mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🧭 refactor: Move the Code Workspace Menu Into @librechat/chat (#18138)
- refactor: Move the Code Workspace Menu Into the Chat Package - refactor: Share the Composer Chip Classes From the Chat Package - test: Provide the Shared Composer Class Helpers to the Workspace Menu Spec
This commit is contained in:
parent
c44ce3b825
commit
393328f93c
10 changed files with 1328 additions and 1098 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -33,10 +33,20 @@ jest.mock('~/hooks', () => ({
|
|||
}));
|
||||
|
||||
jest.mock('@librechat/client', () => {
|
||||
const { CheckboxGlyph, TooltipAnchor, cn } = jest.requireActual('@librechat/client');
|
||||
const {
|
||||
CheckboxGlyph,
|
||||
TooltipAnchor,
|
||||
cn,
|
||||
mergeComposerClasses,
|
||||
disabledFillClasses,
|
||||
disabledInkClasses,
|
||||
} = jest.requireActual('@librechat/client');
|
||||
return {
|
||||
cn,
|
||||
CheckboxGlyph,
|
||||
mergeComposerClasses,
|
||||
disabledFillClasses,
|
||||
disabledInkClasses,
|
||||
composerControlClasses: () => 'composer-control',
|
||||
useToastContext: () => ({ showToast: mockShowToast }),
|
||||
TooltipAnchor,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const themedControls = [
|
|||
/** The context rail's pills share one recipe built on the composer control classes. */
|
||||
['chip.ts', ['composerControlClasses()']],
|
||||
['CodeApprovalMenu.tsx', ['chipClasses']],
|
||||
['CodeWorkspaceMenu.tsx', ['chipClasses', 'infoChipClasses']],
|
||||
['Workspace.tsx', ['chipClasses', 'infoChipClasses']],
|
||||
/** The dictation mic and its send share the submit slot's corner. */
|
||||
['Composer/Bar.tsx', ['shape="composer"']],
|
||||
] as const;
|
||||
|
|
|
|||
|
|
@ -1,37 +1,17 @@
|
|||
import { cn, composerControlClasses } from '@librechat/client';
|
||||
import { composerChipClasses } from '@librechat/chat/components';
|
||||
|
||||
/** One compact pill for every control in the composer's context rail (project, machine,
|
||||
* workspace, branch, worktree, approval mode), so the rail reads as a single set. */
|
||||
export const chipClasses = cn(
|
||||
composerControlClasses(),
|
||||
'h-8 max-w-full min-w-0 gap-1.5 px-2.5 text-xs',
|
||||
'focus-visible:ring-2 focus-visible:ring-text-primary focus-visible:outline-hidden',
|
||||
);
|
||||
|
||||
/** Read-only facts (branch) drop the border and sit on a quiet fill so they do not look pressable. */
|
||||
export const infoChipClasses = cn(
|
||||
const {
|
||||
chipClasses,
|
||||
'border-transparent bg-surface-tertiary text-text-secondary hover:bg-surface-tertiary',
|
||||
);
|
||||
infoChipClasses,
|
||||
chipMenuClasses,
|
||||
chipMenuHeadingClasses,
|
||||
chipMenuItemClasses,
|
||||
} = composerChipClasses();
|
||||
|
||||
/** The popover the rail's chips open. Menus open above their chip, so they rise a few pixels
|
||||
* from its edge while fading and scaling in, and leave on the faster theme step. */
|
||||
export const chipMenuClasses = cn(
|
||||
'z-50 flex max-w-[min(340px,calc(100vw-2rem))] min-w-[240px] flex-col rounded-theme-popover',
|
||||
'border-border-menu bg-surface-menu max-h-[var(--popover-available-height)] overflow-y-auto border p-1 shadow-lg',
|
||||
'origin-bottom-left translate-y-1 scale-95 opacity-0',
|
||||
'transition duration-theme-normal ease-out motion-reduce:transition-none',
|
||||
'data-[enter]:translate-y-0 data-[enter]:scale-100 data-[enter]:opacity-100',
|
||||
'data-[leave]:duration-theme-fast data-[leave]:ease-in',
|
||||
);
|
||||
|
||||
export const chipMenuHeadingClasses = 'px-2.5 pt-2 pb-1 text-xs font-semibold text-text-secondary';
|
||||
|
||||
export const chipMenuItemClasses = (selected = false) =>
|
||||
cn(
|
||||
'group flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5',
|
||||
'outline-hidden transition-colors duration-theme-fast',
|
||||
'hover:bg-surface-hover data-[active-item]:bg-surface-hover',
|
||||
'aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
|
||||
selected && 'bg-surface-active-alt',
|
||||
);
|
||||
export {
|
||||
chipClasses,
|
||||
infoChipClasses,
|
||||
chipMenuClasses,
|
||||
chipMenuHeadingClasses,
|
||||
chipMenuItemClasses,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,11 +65,6 @@
|
|||
"count": 1
|
||||
}
|
||||
},
|
||||
"client/src/components/Chat/Input/CodeWorkspaceMenu.tsx": {
|
||||
"design/disabled-recipe": {
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"client/src/components/Chat/Input/Composer/Files.tsx": {
|
||||
"design/disabled-recipe": {
|
||||
"count": 1
|
||||
|
|
@ -111,11 +106,6 @@
|
|||
"count": 3
|
||||
}
|
||||
},
|
||||
"client/src/components/Chat/Input/chip.ts": {
|
||||
"design/disabled-recipe": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"client/src/components/Chat/Landing.tsx": {
|
||||
"shadcn/no-restyle": {
|
||||
"count": 14
|
||||
|
|
|
|||
|
|
@ -75,6 +75,15 @@ export { getFileType } from './components/composer/files/kinds';
|
|||
export type { FileKind } from './components/composer/files/kinds';
|
||||
export type { SubtitleAction } from './components/composer/files/FileContainer';
|
||||
export type { PastedTextEdit } from './components/composer/files/PastedTextDialog';
|
||||
export { composerChipClasses } from './components/composer/chip';
|
||||
export type { ComposerChipClasses } from './components/composer/chip';
|
||||
export { default as CodeWorkspaceMenu } from './components/composer/Workspace';
|
||||
export type {
|
||||
WorkspaceLocalize,
|
||||
WorkspaceMachineQuery,
|
||||
CodeWorkspaceMenuProps,
|
||||
CodeWorkspaceMenuWorkspace,
|
||||
} from './components/composer/Workspace';
|
||||
|
||||
/** Message list building blocks: rows, headers, sibling navigation and the streaming timer. */
|
||||
export { default as SubRow } from './components/messages/SubRow';
|
||||
|
|
|
|||
1158
packages/chat/src/components/composer/Workspace.tsx
Normal file
1158
packages/chat/src/components/composer/Workspace.tsx
Normal file
File diff suppressed because it is too large
Load diff
38
packages/chat/src/components/composer/chip.spec.ts
Normal file
38
packages/chat/src/components/composer/chip.spec.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { composerChipClasses } from './chip';
|
||||
|
||||
describe('composerChipClasses', () => {
|
||||
it('replaces the control recipe height, gap, and type on the rail pill', () => {
|
||||
const { chipClasses } = composerChipClasses();
|
||||
|
||||
expect(chipClasses).toContain('h-8');
|
||||
expect(chipClasses).toContain('gap-1.5');
|
||||
expect(chipClasses).toContain('text-xs');
|
||||
expect(chipClasses).not.toContain('h-theme-control');
|
||||
expect(chipClasses).not.toContain('gap-theme-control-gap');
|
||||
expect(chipClasses).not.toContain('text-sm');
|
||||
expect(chipClasses).toContain('rounded-theme-control-round');
|
||||
});
|
||||
|
||||
it('keeps a read-only chip quiet by replacing the pressable border and fill', () => {
|
||||
const { infoChipClasses } = composerChipClasses();
|
||||
|
||||
expect(infoChipClasses).toContain('border-transparent');
|
||||
expect(infoChipClasses).toContain('bg-surface-tertiary');
|
||||
expect(infoChipClasses).toContain('text-text-secondary');
|
||||
expect(infoChipClasses).toContain('hover:bg-surface-tertiary');
|
||||
expect(infoChipClasses).not.toContain('border-border-medium');
|
||||
expect(infoChipClasses).not.toContain('bg-transparent');
|
||||
expect(infoChipClasses).not.toContain('text-text-primary');
|
||||
expect(infoChipClasses).not.toContain('hover:bg-surface-hover');
|
||||
});
|
||||
|
||||
it('dims a disabled menu row with the shared ink recipe', () => {
|
||||
const { chipMenuItemClasses } = composerChipClasses();
|
||||
const classes = chipMenuItemClasses(true);
|
||||
|
||||
expect(classes).toContain('aria-disabled:opacity-50');
|
||||
expect(classes).toContain('theme-disabled:opacity-100');
|
||||
expect(classes).toContain('bg-surface-active-alt');
|
||||
expect(chipMenuItemClasses()).not.toContain('bg-surface-active-alt');
|
||||
});
|
||||
});
|
||||
58
packages/chat/src/components/composer/chip.ts
Normal file
58
packages/chat/src/components/composer/chip.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import {
|
||||
disabledInkClasses,
|
||||
composerControlClasses,
|
||||
mergeComposerClasses,
|
||||
} from '@librechat/client';
|
||||
|
||||
export type ComposerChipClasses = {
|
||||
chipClasses: string;
|
||||
infoChipClasses: string;
|
||||
chipMenuClasses: string;
|
||||
chipMenuHeadingClasses: string;
|
||||
chipMenuItemClasses: (selected?: boolean) => string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pills and menus for the composer's context rail. Built per call: the control recipe
|
||||
* is read then, and the pill's height, gap, and type replace that recipe's own.
|
||||
*/
|
||||
export function composerChipClasses(): ComposerChipClasses {
|
||||
const chipClasses = mergeComposerClasses(
|
||||
composerControlClasses(),
|
||||
'h-8 max-w-full min-w-0 gap-1.5 px-2.5 text-xs',
|
||||
'focus-visible:ring-2 focus-visible:ring-text-primary focus-visible:outline-hidden',
|
||||
);
|
||||
const infoChipClasses = mergeComposerClasses(
|
||||
chipClasses,
|
||||
'border-transparent bg-surface-tertiary text-text-secondary hover:bg-surface-tertiary',
|
||||
);
|
||||
const chipMenuClasses = [
|
||||
'z-50 flex max-w-[min(340px,calc(100vw-2rem))] min-w-[240px] flex-col rounded-theme-popover',
|
||||
'border-border-menu bg-surface-menu max-h-[var(--popover-available-height)] overflow-y-auto border p-1 shadow-lg',
|
||||
'origin-bottom-left translate-y-1 scale-95 opacity-0',
|
||||
'transition duration-theme-normal ease-out motion-reduce:transition-none',
|
||||
'data-[enter]:translate-y-0 data-[enter]:scale-100 data-[enter]:opacity-100',
|
||||
'data-[leave]:duration-theme-fast data-[leave]:ease-in',
|
||||
].join(' ');
|
||||
const chipMenuHeadingClasses = 'px-2.5 pt-2 pb-1 text-xs font-semibold text-text-secondary';
|
||||
const chipMenuItemClasses = (selected = false): string => {
|
||||
const classes = [
|
||||
'group flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5',
|
||||
'outline-hidden transition-colors duration-theme-fast',
|
||||
'hover:bg-surface-hover data-[active-item]:bg-surface-hover',
|
||||
'aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
|
||||
disabledInkClasses,
|
||||
];
|
||||
if (selected) {
|
||||
classes.push('bg-surface-active-alt');
|
||||
}
|
||||
return classes.join(' ');
|
||||
};
|
||||
return {
|
||||
chipClasses,
|
||||
infoChipClasses,
|
||||
chipMenuClasses,
|
||||
chipMenuHeadingClasses,
|
||||
chipMenuItemClasses,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import type { ClassValue } from 'clsx';
|
||||
import { disabledFillClasses } from './theme';
|
||||
import { cn } from './utils';
|
||||
|
||||
|
|
@ -70,3 +71,10 @@ export const composerControlClasses = (): string =>
|
|||
* surface is under 1.2:1 and would leave the control with no visible boundary. */
|
||||
'hover:bg-surface-hover',
|
||||
);
|
||||
|
||||
/**
|
||||
* Merges composer class names so a later utility replaces one from the same theme group
|
||||
* (`h-8` takes the place of `h-theme-control`, `gap-1.5` of `gap-theme-control-gap`).
|
||||
* Chat components call this where they extend `composerControlClasses()`.
|
||||
*/
|
||||
export const mergeComposerClasses = (...inputs: ClassValue[]): string => cn(...inputs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue