@adea-ai/ui 0.145.1 → 0.145.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
+ import { WorkspaceSwitcher } from "./workspace-switcher.js";
1
2
  import { moveTarget, moveWorkspace } from "./workspace-order.js";
2
3
  import { WorkspaceReorderDialog } from "./workspace-reorder-dialog.js";
3
- import { WorkspaceSwitcher } from "./workspace-switcher.js";
4
4
  export { WorkspaceReorderDialog, WorkspaceSwitcher, moveTarget, moveWorkspace };
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-reorder-dialog.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/workspace-switcher/workspace-reorder-dialog.tsx"],"names":[],"mappings":"AACA,OAAO,EAAwD,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAe9F,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;IACjC,UAAU,EAAE,SAAS,oBAAoB,EAAE,CAAA;IAC3C,2FAA2F;IAC3F,SAAS,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0FAA0F;IAC1F,eAAe,CAAC,EAAE,QAAQ,CAAC,WAAW,GAAG,SAAS,CAAC,CAAA;CACpD,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,kCA6JxE"}
1
+ {"version":3,"file":"workspace-reorder-dialog.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/workspace-switcher/workspace-reorder-dialog.tsx"],"names":[],"mappings":"AACA,OAAO,EAAwD,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAe9F,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;IACjC,UAAU,EAAE,SAAS,oBAAoB,EAAE,CAAA;IAC3C,2FAA2F;IAC3F,SAAS,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0FAA0F;IAC1F,eAAe,CAAC,EAAE,QAAQ,CAAC,WAAW,GAAG,SAAS,CAAC,CAAA;CACpD,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,kCAmKxE"}
@@ -50,13 +50,18 @@ function WorkspaceReorderDialog(props) {
50
50
  });
51
51
  const focusMove = (owner, id, direction) => {
52
52
  if (frame !== void 0) cancelAnimationFrame(frame);
53
- frame = requestAnimationFrame(() => {
54
- frame = void 0;
53
+ const restore = () => {
55
54
  if (disposed || owner !== session || !props.open) return;
56
55
  const row = list?.querySelector(`[data-reorder-id="${CSS.escape(id)}"]`);
57
56
  const wanted = row?.querySelector(`[data-move="${direction}"]`);
58
57
  const other = row?.querySelector(`[data-move="${direction === "up" ? "down" : "up"}"]`);
59
- (wanted?.getAttribute("aria-disabled") === "true" ? other : wanted)?.focus({ preventScroll: true });
58
+ const target = wanted?.getAttribute("aria-disabled") === "true" ? other : wanted;
59
+ if (target && document.activeElement !== target) target.focus({ preventScroll: true });
60
+ };
61
+ restore();
62
+ frame = requestAnimationFrame(() => {
63
+ frame = void 0;
64
+ restore();
60
65
  });
61
66
  };
62
67
  const move = async (item, direction) => {
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-reorder-dialog.js","names":["ArrowDown","ArrowUp","For","Show","createEffect","createSignal","on","onCleanup","Accessor","Button","Dialog","DialogClose","DialogContent","DialogDescription","DialogFooter","DialogHeader","DialogTitle","createDialogFocusRestoration","ActionButton","moveTarget","moveWorkspace","WorkspaceMoveDirection","WorkspaceReorderItem","id","name","fixed","WorkspaceReorderDialogProps","open","onOpenChange","workspaces","onReorder","ids","Promise","title","restoreFocusRef","HTMLElement","WorkspaceReorderDialog","props","status","setStatus","error","setError","pending","setPending","list","HTMLOListElement","session","disposed","frame","undefined","cancelAnimationFrame","defer","focus","focusMove","owner","direction","requestAnimationFrame","row","querySelector","CSS","escape","wanted","other","target","getAttribute","preventScroll","move","item","next","current","indexOf","length","_$createComponent","children","onKeyDown","event","KeyboardEvent","key","defaultPrevented","preventDefault","onOpenAutoFocus","onCloseAutoFocus","_el$","_tmpl$","_$use","el","_$insert","each","_el$4","_tmpl$4","_el$5","firstChild","when","fallback","_tmpl$5","const","variant","size","aria-label","tooltip","disabled","onClick","_$effect","_$setAttribute","_el$2","_tmpl$2","_el$3","_tmpl$3","as","_$createComponent","_$setAttribute"],"sources":["../../../../src/components/composites/workspace-switcher/workspace-reorder-dialog.tsx"],"sourcesContent":["import { ArrowDown, ArrowUp } from 'lucide-solid'\nimport { For, Show, createEffect, createSignal, on, onCleanup, type Accessor } from 'solid-js'\nimport { Button } from '../../ui/button'\nimport {\n Dialog,\n DialogClose,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '../../ui/dialog'\nimport { createDialogFocusRestoration } from '../../ui/dialog/dialog'\nimport { ActionButton } from '../action-button'\nimport { moveTarget, moveWorkspace, type WorkspaceMoveDirection } from './workspace-order'\n\nexport type WorkspaceReorderItem = {\n id: string\n name: string\n fixed?: boolean\n}\n\nexport type WorkspaceReorderDialogProps = {\n open: boolean\n onOpenChange(open: boolean): void\n workspaces: readonly WorkspaceReorderItem[]\n /** Receives the full id order after one move. May be async; a rejection shows an error. */\n onReorder(ids: readonly string[]): void | Promise<void>\n title?: string\n /** Where focus returns on close; the menu item that opened the dialog is gone by then. */\n restoreFocusRef?: Accessor<HTMLElement | undefined>\n}\n\n/**\n * WorkspaceReorderDialog.\n *\n * Ordering by buttons, not by dragging, so it works from the keyboard and with\n * a screen reader: every row has a labelled Move up and Move down. Each move is\n * reported to the host straight away (there is no Save), the moved row keeps\n * focus on the control that was used, and the new position is announced.\n *\n * One save runs at a time, even across a close and reopen: the moves stay\n * disabled until the host's promise settles. A save that finishes after the\n * dialog has closed reports nothing here (the host owns any failure it wants\n * to surface) and never moves focus.\n */\nexport function WorkspaceReorderDialog(props: WorkspaceReorderDialogProps) {\n const [status, setStatus] = createSignal('')\n const [error, setError] = createSignal('')\n const [pending, setPending] = createSignal(false)\n let list: HTMLOListElement | undefined\n // Each open and each close starts a new session. A save belongs to the session\n // it began in; once the dialog has closed (or closed and reopened) its result\n // no longer speaks for what is on screen, so it must not touch the status\n // line or focus. `pending` is deliberately not reset with the session: the\n // host's save is still running, so the next move waits for it instead of\n // running a second save beside it.\n let session = 0\n let disposed = false\n let frame: number | undefined\n\n createEffect(\n on(\n () => props.open,\n () => {\n session += 1\n if (frame !== undefined) cancelAnimationFrame(frame)\n frame = undefined\n setStatus('')\n setError('')\n },\n { defer: true }\n )\n )\n onCleanup(() => {\n disposed = true\n session += 1\n if (frame !== undefined) cancelAnimationFrame(frame)\n })\n\n const focus = createDialogFocusRestoration({\n open: () => props.open,\n restoreFocusRef: props.restoreFocusRef,\n })\n\n const focusMove = (owner: number, id: string, direction: WorkspaceMoveDirection) => {\n // The host re-renders the rows with the new order; focus the same control\n // once it exists, or its sibling when the move reached an edge.\n if (frame !== undefined) cancelAnimationFrame(frame)\n frame = requestAnimationFrame(() => {\n frame = undefined\n if (disposed || owner !== session || !props.open) return\n const row = list?.querySelector<HTMLElement>(`[data-reorder-id=\"${CSS.escape(id)}\"]`)\n const wanted = row?.querySelector<HTMLElement>(`[data-move=\"${direction}\"]`)\n const other = row?.querySelector<HTMLElement>(\n `[data-move=\"${direction === 'up' ? 'down' : 'up'}\"]`\n )\n const target = wanted?.getAttribute('aria-disabled') === 'true' ? other : wanted\n target?.focus({ preventScroll: true })\n })\n }\n\n const move = async (item: WorkspaceReorderItem, direction: WorkspaceMoveDirection) => {\n if (pending()) return\n const next = moveWorkspace(props.workspaces, item.id, direction)\n if (!next) return\n const owner = session\n const current = () => !disposed && owner === session && props.open\n setError('')\n setPending(true)\n try {\n await props.onReorder(next)\n if (current())\n setStatus(`Moved ${item.name} to position ${next.indexOf(item.id) + 1} of ${next.length}.`)\n } catch {\n if (current()) {\n setStatus('')\n setError('Could not save the order. Try again.')\n }\n } finally {\n if (!disposed) setPending(false)\n if (current()) focusMove(owner, item.id, direction)\n }\n }\n\n return (\n <Dialog open={props.open} onOpenChange={props.onOpenChange}>\n <DialogContent\n class=\"w-full max-w-sm\"\n onKeyDown={(event: KeyboardEvent) => {\n // Tooltip help on a focused move control would otherwise take the first Escape.\n if (event.key === 'Escape' && !event.defaultPrevented) {\n event.preventDefault()\n props.onOpenChange(false)\n }\n }}\n onOpenAutoFocus={focus.onOpenAutoFocus}\n onCloseAutoFocus={focus.onCloseAutoFocus}\n >\n <DialogHeader>\n <DialogTitle>{props.title ?? 'Reorder workspaces'}</DialogTitle>\n <DialogDescription>\n Move a workspace up or down. The order is saved as you go.\n </DialogDescription>\n </DialogHeader>\n <ol\n ref={(el) => (list = el)}\n class=\"flex flex-col gap-1\"\n aria-label=\"Workspace order\"\n aria-busy={pending()}\n >\n <For each={props.workspaces}>\n {(item) => (\n <li\n data-reorder-id={item.id}\n class=\"flex items-center gap-2 rounded-md border border-border px-3 py-1.5\"\n >\n <span class=\"min-w-0 flex-1 truncate text-sm\">{item.name}</span>\n <Show\n when={!item.fixed}\n fallback={<span class=\"text-xs text-muted-foreground\">Always first</span>}\n >\n <For each={['up', 'down'] as const}>\n {(direction) => (\n <ActionButton\n variant=\"ghost\"\n size=\"icon-sm\"\n data-move={direction}\n aria-label={`Move ${item.name} ${direction}`}\n tooltip={`Move ${direction}`}\n disabled={\n pending() ||\n moveTarget(props.workspaces, item.id, direction) === undefined\n }\n onClick={() => void move(item, direction)}\n >\n <Show when={direction === 'up'} fallback={<ArrowDown aria-hidden=\"true\" />}>\n <ArrowUp aria-hidden=\"true\" />\n </Show>\n </ActionButton>\n )}\n </For>\n </Show>\n </li>\n )}\n </For>\n </ol>\n <p role=\"status\" aria-live=\"polite\" class=\"min-h-5 text-xs text-muted-foreground\">\n {status()}\n </p>\n <Show when={error()}>\n <p role=\"alert\" class=\"text-xs text-destructive\">\n {error()}\n </p>\n </Show>\n <DialogFooter>\n <DialogClose as={Button} variant=\"outline\" size=\"sm\">\n Done\n </DialogClose>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAgBoC,uBAAuBC,OAAoC;CACzE,MAAM,CAACC,QAAQC,aAAalC,aAAa,EAAE;CAC3C,MAAM,CAACmC,OAAOC,YAAYpC,aAAa,EAAE;CACzC,MAAM,CAACqC,SAASC,cAActC,aAAa,KAAK;CAChD,IAAIuC;CAOJ,IAAIE,UAAU;CACd,IAAIC,WAAW;CACf,IAAIC;CAEJ5C,aACEE,SACQ+B,MAAMV,YACN;EACJmB,WAAW;EACX,IAAIE,UAAUC,KAAAA,GAAWC,qBAAqBF,KAAK;EACnDA,QAAQC,KAAAA;EACRV,UAAU,EAAE;EACZE,SAAS,EAAE;CACb,GACA,EAAEU,OAAO,KAAK,CAChB,CACF;CACA5C,gBAAgB;EACdwC,WAAW;EACXD,WAAW;EACX,IAAIE,UAAUC,KAAAA,GAAWC,qBAAqBF,KAAK;CACrD,CAAC;CAED,MAAMI,QAAQnC,6BAA6B;EACzCU,YAAYU,MAAMV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EAAA;CAAA,CAAA;AAOzD"}
1
+ {"version":3,"file":"workspace-reorder-dialog.js","names":["ArrowDown","ArrowUp","For","Show","createEffect","createSignal","on","onCleanup","Accessor","Button","Dialog","DialogClose","DialogContent","DialogDescription","DialogFooter","DialogHeader","DialogTitle","createDialogFocusRestoration","ActionButton","moveTarget","moveWorkspace","WorkspaceMoveDirection","WorkspaceReorderItem","id","name","fixed","WorkspaceReorderDialogProps","open","onOpenChange","workspaces","onReorder","ids","Promise","title","restoreFocusRef","HTMLElement","WorkspaceReorderDialog","props","status","setStatus","error","setError","pending","setPending","list","HTMLOListElement","session","disposed","frame","undefined","cancelAnimationFrame","defer","focus","focusMove","owner","direction","restore","row","querySelector","CSS","escape","wanted","other","target","getAttribute","document","activeElement","preventScroll","requestAnimationFrame","move","item","next","current","indexOf","length","_$createComponent","children","onKeyDown","event","KeyboardEvent","key","defaultPrevented","preventDefault","onOpenAutoFocus","onCloseAutoFocus","_el$","_tmpl$","_$use","el","_$insert","each","_el$4","_tmpl$4","_el$5","firstChild","when","fallback","_tmpl$5","const","variant","size","aria-label","tooltip","disabled","onClick","_$effect","_$setAttribute","_el$2","_tmpl$2","_el$3","_tmpl$3","as","_$createComponent","_$setAttribute"],"sources":["../../../../src/components/composites/workspace-switcher/workspace-reorder-dialog.tsx"],"sourcesContent":["import { ArrowDown, ArrowUp } from 'lucide-solid'\nimport { For, Show, createEffect, createSignal, on, onCleanup, type Accessor } from 'solid-js'\nimport { Button } from '../../ui/button'\nimport {\n Dialog,\n DialogClose,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '../../ui/dialog'\nimport { createDialogFocusRestoration } from '../../ui/dialog/dialog'\nimport { ActionButton } from '../action-button'\nimport { moveTarget, moveWorkspace, type WorkspaceMoveDirection } from './workspace-order'\n\nexport type WorkspaceReorderItem = {\n id: string\n name: string\n fixed?: boolean\n}\n\nexport type WorkspaceReorderDialogProps = {\n open: boolean\n onOpenChange(open: boolean): void\n workspaces: readonly WorkspaceReorderItem[]\n /** Receives the full id order after one move. May be async; a rejection shows an error. */\n onReorder(ids: readonly string[]): void | Promise<void>\n title?: string\n /** Where focus returns on close; the menu item that opened the dialog is gone by then. */\n restoreFocusRef?: Accessor<HTMLElement | undefined>\n}\n\n/**\n * WorkspaceReorderDialog.\n *\n * Ordering by buttons, not by dragging, so it works from the keyboard and with\n * a screen reader: every row has a labelled Move up and Move down. Each move is\n * reported to the host straight away (there is no Save), the moved row keeps\n * focus on the control that was used, and the new position is announced.\n *\n * One save runs at a time, even across a close and reopen: the moves stay\n * disabled until the host's promise settles. A save that finishes after the\n * dialog has closed reports nothing here (the host owns any failure it wants\n * to surface) and never moves focus.\n */\nexport function WorkspaceReorderDialog(props: WorkspaceReorderDialogProps) {\n const [status, setStatus] = createSignal('')\n const [error, setError] = createSignal('')\n const [pending, setPending] = createSignal(false)\n let list: HTMLOListElement | undefined\n // Each open and each close starts a new session. A save belongs to the session\n // it began in; once the dialog has closed (or closed and reopened) its result\n // no longer speaks for what is on screen, so it must not touch the status\n // line or focus. `pending` is deliberately not reset with the session: the\n // host's save is still running, so the next move waits for it instead of\n // running a second save beside it.\n let session = 0\n let disposed = false\n let frame: number | undefined\n\n createEffect(\n on(\n () => props.open,\n () => {\n session += 1\n if (frame !== undefined) cancelAnimationFrame(frame)\n frame = undefined\n setStatus('')\n setError('')\n },\n { defer: true }\n )\n )\n onCleanup(() => {\n disposed = true\n session += 1\n if (frame !== undefined) cancelAnimationFrame(frame)\n })\n\n const focus = createDialogFocusRestoration({\n open: () => props.open,\n restoreFocusRef: props.restoreFocusRef,\n })\n\n const focusMove = (owner: number, id: string, direction: WorkspaceMoveDirection) => {\n // The host re-renders the rows with the new order, which replaces the control\n // that had focus; focus the same control once it exists, or its sibling when\n // the move reached an edge. Try at once so keys pressed right after a save\n // still reach the dialog, and again next frame for a host that renders later.\n if (frame !== undefined) cancelAnimationFrame(frame)\n const restore = () => {\n if (disposed || owner !== session || !props.open) return\n const row = list?.querySelector<HTMLElement>(`[data-reorder-id=\"${CSS.escape(id)}\"]`)\n const wanted = row?.querySelector<HTMLElement>(`[data-move=\"${direction}\"]`)\n const other = row?.querySelector<HTMLElement>(\n `[data-move=\"${direction === 'up' ? 'down' : 'up'}\"]`\n )\n const target = wanted?.getAttribute('aria-disabled') === 'true' ? other : wanted\n if (target && document.activeElement !== target) target.focus({ preventScroll: true })\n }\n restore()\n frame = requestAnimationFrame(() => {\n frame = undefined\n restore()\n })\n }\n\n const move = async (item: WorkspaceReorderItem, direction: WorkspaceMoveDirection) => {\n if (pending()) return\n const next = moveWorkspace(props.workspaces, item.id, direction)\n if (!next) return\n const owner = session\n const current = () => !disposed && owner === session && props.open\n setError('')\n setPending(true)\n try {\n await props.onReorder(next)\n if (current())\n setStatus(`Moved ${item.name} to position ${next.indexOf(item.id) + 1} of ${next.length}.`)\n } catch {\n if (current()) {\n setStatus('')\n setError('Could not save the order. Try again.')\n }\n } finally {\n if (!disposed) setPending(false)\n if (current()) focusMove(owner, item.id, direction)\n }\n }\n\n return (\n <Dialog open={props.open} onOpenChange={props.onOpenChange}>\n <DialogContent\n class=\"w-full max-w-sm\"\n onKeyDown={(event: KeyboardEvent) => {\n // Tooltip help on a focused move control would otherwise take the first Escape.\n if (event.key === 'Escape' && !event.defaultPrevented) {\n event.preventDefault()\n props.onOpenChange(false)\n }\n }}\n onOpenAutoFocus={focus.onOpenAutoFocus}\n onCloseAutoFocus={focus.onCloseAutoFocus}\n >\n <DialogHeader>\n <DialogTitle>{props.title ?? 'Reorder workspaces'}</DialogTitle>\n <DialogDescription>\n Move a workspace up or down. The order is saved as you go.\n </DialogDescription>\n </DialogHeader>\n <ol\n ref={(el) => (list = el)}\n class=\"flex flex-col gap-1\"\n aria-label=\"Workspace order\"\n aria-busy={pending()}\n >\n <For each={props.workspaces}>\n {(item) => (\n <li\n data-reorder-id={item.id}\n class=\"flex items-center gap-2 rounded-md border border-border px-3 py-1.5\"\n >\n <span class=\"min-w-0 flex-1 truncate text-sm\">{item.name}</span>\n <Show\n when={!item.fixed}\n fallback={<span class=\"text-xs text-muted-foreground\">Always first</span>}\n >\n <For each={['up', 'down'] as const}>\n {(direction) => (\n <ActionButton\n variant=\"ghost\"\n size=\"icon-sm\"\n data-move={direction}\n aria-label={`Move ${item.name} ${direction}`}\n tooltip={`Move ${direction}`}\n disabled={\n pending() ||\n moveTarget(props.workspaces, item.id, direction) === undefined\n }\n onClick={() => void move(item, direction)}\n >\n <Show when={direction === 'up'} fallback={<ArrowDown aria-hidden=\"true\" />}>\n <ArrowUp aria-hidden=\"true\" />\n </Show>\n </ActionButton>\n )}\n </For>\n </Show>\n </li>\n )}\n </For>\n </ol>\n <p role=\"status\" aria-live=\"polite\" class=\"min-h-5 text-xs text-muted-foreground\">\n {status()}\n </p>\n <Show when={error()}>\n <p role=\"alert\" class=\"text-xs text-destructive\">\n {error()}\n </p>\n </Show>\n <DialogFooter>\n <DialogClose as={Button} variant=\"outline\" size=\"sm\">\n Done\n </DialogClose>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAgBoC,uBAAuBC,OAAoC;CACzE,MAAM,CAACC,QAAQC,aAAalC,aAAa,EAAE;CAC3C,MAAM,CAACmC,OAAOC,YAAYpC,aAAa,EAAE;CACzC,MAAM,CAACqC,SAASC,cAActC,aAAa,KAAK;CAChD,IAAIuC;CAOJ,IAAIE,UAAU;CACd,IAAIC,WAAW;CACf,IAAIC;CAEJ5C,aACEE,SACQ+B,MAAMV,YACN;EACJmB,WAAW;EACX,IAAIE,UAAUC,KAAAA,GAAWC,qBAAqBF,KAAK;EACnDA,QAAQC,KAAAA;EACRV,UAAU,EAAE;EACZE,SAAS,EAAE;CACb,GACA,EAAEU,OAAO,KAAK,CAChB,CACF;CACA5C,gBAAgB;EACdwC,WAAW;EACXD,WAAW;EACX,IAAIE,UAAUC,KAAAA,GAAWC,qBAAqBF,KAAK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D,cAAY,EAAA,IAAA8D,WAAA;OAAA,OAAAD,gBACVhE,aAAW;QAACoG,IAAItG;QAAQ0F,SAAO;QAAWC,MAAI;QAAAxB,UAAA;OAAA,CAAA;MAAA,EAAA,CAAA;KAAA;IAAA;GAAA,CAAA;EAAA;CAAA,CAAA;AAOzD"}
@@ -50,6 +50,8 @@ export type WorkspaceSwitcherProps = {
50
50
  */
51
51
  onReorder?(ids: readonly string[]): void | Promise<void>;
52
52
  reorderLabel?: string;
53
+ /** Replaces the "Reorder workspaces…" item when the dialog could not be loaded. */
54
+ reorderErrorLabel?: string;
53
55
  /** The menu's heading; also the trigger's accessible-name prefix. */
54
56
  label?: string;
55
57
  /** Shown while no workspace is current. */
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-switcher.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/workspace-switcher/workspace-switcher.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAiBnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;;;;OAQG;IACH,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAA;IACvC,2EAA2E;IAC3E,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACpB,gGAAgG;IAChG,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAA;IAC5C,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,oDAAoD;IACpD,QAAQ,CAAC,IAAI,IAAI,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,IAAI,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,SAAS,CAAC,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAWD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA2F9D"}
1
+ {"version":3,"file":"workspace-switcher.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/workspace-switcher/workspace-switcher.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAsBnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;;;;OAQG;IACH,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAA;IACvC,2EAA2E;IAC3E,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACpB,gGAAgG;IAChG,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAA;IAC5C,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,oDAAoD;IACpD,QAAQ,CAAC,IAAI,IAAI,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,IAAI,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,SAAS,CAAC,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAWD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAkJ9D"}
@@ -1,14 +1,14 @@
1
1
  import { cn } from "../../../lib/utils.js";
2
2
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger } from "../../ui/dropdown-menu/dropdown-menu.js";
3
3
  import { ActionButton } from "../action-button/action-button.js";
4
- import { WorkspaceReorderDialog } from "./workspace-reorder-dialog.js";
5
- import { createComponent, insert, memo, template } from "solid-js/web";
4
+ import { Dynamic, createComponent, insert, memo, template } from "solid-js/web";
6
5
  import { ArrowDownUp, ChevronDown, Plus, Settings } from "lucide-solid";
7
- import { For, Show, createSignal } from "solid-js";
6
+ import { For, Show, createSignal, onCleanup } from "solid-js";
8
7
  //#region src/components/composites/workspace-switcher/workspace-switcher.tsx
9
8
  var _tmpl$ = /*#__PURE__*/ template(`<span aria-hidden=true class="flex shrink-0">`);
10
9
  var _tmpl$2 = /*#__PURE__*/ template(`<span class="min-w-0 max-w-40 truncate">`);
11
10
  var _tmpl$3 = /*#__PURE__*/ template(`<span class="min-w-0 flex-1 truncate">`);
11
+ var loadReorderDialog = () => import("./workspace-reorder-dialog.js");
12
12
  /**
13
13
  * Draws one placement of a mark. A function draws anew each time; a node that is
14
14
  * already placed elsewhere is copied so the original stays where it is.
@@ -20,16 +20,56 @@ function drawMark(mark, copy) {
20
20
  function WorkspaceSwitcher(props) {
21
21
  const [open, setOpen] = createSignal(false);
22
22
  const [reordering, setReordering] = createSignal(false);
23
+ const [reorderDialog, setReorderDialog] = createSignal();
24
+ const [reorderFailed, setReorderFailed] = createSignal(false);
25
+ let cancelPending;
23
26
  let trigger;
24
27
  const current = () => props.workspaces.find((item) => item.id === props.value);
25
28
  const label = () => props.label ?? "Workspaces";
26
29
  const canReorder = () => props.onReorder !== void 0 && props.workspaces.filter((item) => !item.fixed).length > 1;
30
+ const loadDialog = () => loadReorderDialog().then((module) => {
31
+ setReorderDialog(() => module.WorkspaceReorderDialog);
32
+ return true;
33
+ }, () => {
34
+ setReorderFailed(true);
35
+ return false;
36
+ });
37
+ const warm = (next) => {
38
+ setOpen(next);
39
+ if (next && canReorder() && !reorderDialog()) loadDialog();
40
+ };
41
+ const requestReorder = () => {
42
+ cancelPending?.();
43
+ if (reorderDialog()) {
44
+ setReordering(true);
45
+ return;
46
+ }
47
+ let waiting = true;
48
+ const stop = () => {
49
+ waiting = false;
50
+ document.removeEventListener("keydown", onKey, true);
51
+ document.removeEventListener("pointerdown", stop, true);
52
+ if (cancelPending === stop) cancelPending = void 0;
53
+ };
54
+ const onKey = (event) => {
55
+ if (event.key === "Escape") stop();
56
+ };
57
+ document.addEventListener("keydown", onKey, true);
58
+ document.addEventListener("pointerdown", stop, true);
59
+ cancelPending = stop;
60
+ loadDialog().then((loaded) => {
61
+ const stillWanted = waiting;
62
+ stop();
63
+ if (loaded && stillWanted) setReordering(true);
64
+ });
65
+ };
66
+ onCleanup(() => cancelPending?.());
27
67
  return [createComponent(DropdownMenu, {
28
68
  modal: false,
29
69
  get open() {
30
70
  return open();
31
71
  },
32
- onOpenChange: setOpen,
72
+ onOpenChange: warm,
33
73
  get children() {
34
74
  return [createComponent(DropdownMenuTrigger, {
35
75
  as: ActionButton,
@@ -152,9 +192,12 @@ function WorkspaceSwitcher(props) {
152
192
  },
153
193
  get children() {
154
194
  return createComponent(DropdownMenuItem, {
155
- onSelect: () => setReordering(true),
195
+ get disabled() {
196
+ return reorderFailed();
197
+ },
198
+ onSelect: requestReorder,
156
199
  get children() {
157
- return [createComponent(ArrowDownUp, { "aria-hidden": "true" }), memo(() => props.reorderLabel ?? "Reorder workspaces…")];
200
+ return [createComponent(ArrowDownUp, { "aria-hidden": "true" }), memo(() => memo(() => !!reorderFailed())() ? props.reorderErrorLabel ?? "Couldn’t load reordering. Reload to try again." : props.reorderLabel ?? "Reorder workspaces…")];
158
201
  }
159
202
  });
160
203
  }
@@ -180,9 +223,12 @@ function WorkspaceSwitcher(props) {
180
223
  }
181
224
  }), createComponent(Show, {
182
225
  get when() {
183
- return props.onReorder;
226
+ return memo(() => !!reorderDialog())() && props.onReorder;
184
227
  },
185
- children: (onReorder) => createComponent(WorkspaceReorderDialog, {
228
+ children: (onReorder) => createComponent(Dynamic, {
229
+ get component() {
230
+ return reorderDialog();
231
+ },
186
232
  get open() {
187
233
  return reordering();
188
234
  },
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-switcher.js","names":["ArrowDownUp","ChevronDown","Plus","Settings","JSX","For","Show","createSignal","cn","DropdownMenu","DropdownMenuContent","DropdownMenuGroup","DropdownMenuItem","DropdownMenuLabel","DropdownMenuRadioGroup","DropdownMenuRadioItem","DropdownMenuSeparator","DropdownMenuTrigger","ActionButton","WorkspaceReorderDialog","WorkspaceSwitcherItem","id","name","mark","Element","detail","fixed","WorkspaceSwitcherProps","workspaces","value","onValueChange","onCreate","createLabel","onManage","manageLabel","onReorder","ids","Promise","reorderLabel","label","placeholder","disabled","class","drawMark","copy","Node","cloneNode","WorkspaceSwitcher","props","open","setOpen","reordering","setReordering","trigger","HTMLElement","current","find","item","canReorder","undefined","filter","length","_$createComponent","modal","onOpenChange","children","as","variant","size","ref","el","tooltip","aria-label","_el$","_tmpl$","_$insert","_c$","_$memo","_el$2","_tmpl$2","align","sideOffset","onChange","String","each","closeOnSelect","data-workspace-id","_el$3","_el$4","_tmpl$3","when","onSelect","restoreFocusRef","_$createComponent","_$memo"],"sources":["../../../../src/components/composites/workspace-switcher/workspace-switcher.tsx"],"sourcesContent":["import { ArrowDownUp, ChevronDown, Plus, Settings } from 'lucide-solid'\nimport type { JSX } from 'solid-js'\nimport { For, Show, createSignal } from 'solid-js'\nimport { cn } from '#lib/utils'\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from '../../ui/dropdown-menu'\nimport { ActionButton } from '../action-button'\nimport { WorkspaceReorderDialog } from './workspace-reorder-dialog'\n\n/**\n * WorkspaceSwitcher.\n *\n * The workspace picker that sits in the top bar beside the sidebar toggle. One\n * ghost button shows the current workspace's mark and name; pressing it opens a\n * radio list of the others. Choosing one only changes what the window is\n * looking at: the switcher reports the id and the host decides what that means,\n * which is why it carries no status of its own and never closes, restarts or\n * moves anything.\n *\n * It is deliberately the simple interaction (a single menu, not a nested\n * accordion): the sidebar below it already shows what is inside the chosen\n * workspace, so the switcher's only job is to name the workspace and let the\n * user change it.\n */\nexport type WorkspaceSwitcherItem = {\n id: string\n name: string\n /**\n * The workspace's mark, drawn in the trigger and in its row. Decorative.\n *\n * A DOM node can sit in one place, so the current workspace's mark would have\n * to be in the trigger and its menu row at once. Pass a function to draw a\n * fresh mark in each place (the preferred form). A node built once is also\n * safe: the trigger keeps it and the current row gets a copy, which carries\n * no event handlers or reactive bindings, so keep marks static.\n */\n mark: JSX.Element | (() => JSX.Element)\n /** A quiet trailing readout in the row, e.g. an unread count. Optional. */\n detail?: JSX.Element\n /** Pinned to the top of the order, e.g. Home: it cannot be moved and nothing moves above it. */\n fixed?: boolean\n}\n\nexport type WorkspaceSwitcherProps = {\n workspaces: readonly WorkspaceSwitcherItem[]\n /** The current workspace's id. */\n value: string | undefined\n onValueChange(id: string): void\n /** Offered at the foot of the menu when present. */\n onCreate?(): void\n createLabel?: string\n /** Offered beside the create action when present: open the current workspace's settings. */\n onManage?(): void\n manageLabel?: string\n /**\n * Offered when present and at least two workspaces can move: opens a dialog\n * with Move up and Move down on each row. Receives the full id order after\n * each move; the host saves it and passes the workspaces back in that order.\n */\n onReorder?(ids: readonly string[]): void | Promise<void>\n reorderLabel?: string\n /** The menu's heading; also the trigger's accessible-name prefix. */\n label?: string\n /** Shown while no workspace is current. */\n placeholder?: string\n disabled?: boolean\n class?: string\n}\n\n/**\n * Draws one placement of a mark. A function draws anew each time; a node that is\n * already placed elsewhere is copied so the original stays where it is.\n */\nfunction drawMark(mark: WorkspaceSwitcherItem['mark'], copy: boolean): JSX.Element {\n if (typeof mark === 'function') return mark()\n return copy && mark instanceof Node ? mark.cloneNode(true) : mark\n}\n\nexport function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {\n const [open, setOpen] = createSignal(false)\n const [reordering, setReordering] = createSignal(false)\n let trigger: HTMLElement | undefined\n const current = () => props.workspaces.find((item) => item.id === props.value)\n const label = () => props.label ?? 'Workspaces'\n const canReorder = () =>\n props.onReorder !== undefined && props.workspaces.filter((item) => !item.fixed).length > 1\n\n return (\n <>\n <DropdownMenu modal={false} open={open()} onOpenChange={setOpen}>\n <DropdownMenuTrigger\n as={ActionButton}\n variant=\"ghost\"\n size=\"sm\"\n disabled={props.disabled}\n ref={(el: HTMLElement) => (trigger = el)}\n data-slot=\"workspace-switcher\"\n tooltip={`Workspace: ${current()?.name ?? props.placeholder ?? 'Choose workspace'}`}\n aria-label={`Switch workspace, current: ${current()?.name ?? 'none'}`}\n class={cn('max-w-full min-w-0 shrink', props.class)}\n >\n <span aria-hidden=\"true\" class=\"flex shrink-0\">\n {current() && drawMark(current()!.mark, false)}\n </span>\n <span class=\"min-w-0 max-w-40 truncate\">\n {current()?.name ?? props.placeholder ?? 'Choose workspace'}\n </span>\n <ChevronDown aria-hidden=\"true\" class=\"size-3.5 shrink-0 text-muted-foreground\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"start\" sideOffset={6} class=\"min-w-56\">\n <DropdownMenuGroup>\n <DropdownMenuLabel>{label()}</DropdownMenuLabel>\n <DropdownMenuRadioGroup\n value={props.value}\n onChange={(value) => {\n setOpen(false)\n const id = String(value)\n if (id !== props.value) props.onValueChange(id)\n }}\n >\n <For each={props.workspaces}>\n {(item) => (\n <DropdownMenuRadioItem value={item.id} closeOnSelect data-workspace-id={item.id}>\n <span aria-hidden=\"true\" class=\"flex shrink-0\">\n {drawMark(item.mark, item.id === props.value)}\n </span>\n <span class=\"min-w-0 flex-1 truncate\">{item.name}</span>\n <Show when={item.detail}>{item.detail}</Show>\n </DropdownMenuRadioItem>\n )}\n </For>\n </DropdownMenuRadioGroup>\n </DropdownMenuGroup>\n <Show when={props.onCreate || props.onManage || canReorder()}>\n <DropdownMenuSeparator />\n <Show when={props.onCreate}>\n <DropdownMenuItem onSelect={() => props.onCreate?.()}>\n <Plus aria-hidden=\"true\" />\n {props.createLabel ?? 'New workspace'}\n </DropdownMenuItem>\n </Show>\n <Show when={canReorder()}>\n <DropdownMenuItem onSelect={() => setReordering(true)}>\n <ArrowDownUp aria-hidden=\"true\" />\n {props.reorderLabel ?? 'Reorder workspaces…'}\n </DropdownMenuItem>\n </Show>\n <Show when={props.onManage}>\n <DropdownMenuItem onSelect={() => props.onManage?.()}>\n <Settings aria-hidden=\"true\" />\n {props.manageLabel ?? 'Workspace settings…'}\n </DropdownMenuItem>\n </Show>\n </Show>\n </DropdownMenuContent>\n </DropdownMenu>\n <Show when={props.onReorder}>\n {(onReorder) => (\n <WorkspaceReorderDialog\n open={reordering()}\n onOpenChange={setReordering}\n workspaces={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AwB,gBAG/CxD,MAAI;SAAA,IAACoF,OAAI;UAAA,OAAE1C,MAAMf;SAAQ;SAAA,IAAAgC,WAAA;UAAA,OAAAH,gBACvBlD,kBAAgB;WAAC+E,gBAAgB3C,MAAMf,WAAW;WAAC,IAAAgC,WAAA;YAAA,OAAA,CAAAH,gBACjD3D,UAAQ,EAAA,eAAA,OAAA,CAAA,GAAA0E,WACR7B,MAAMd,eAAe,qBAAqB,CAAA;WAAA;UAAA,CAAA;SAAA;QAAA,CAAA;OAAA;MAAA;KAAA,CAAA,CAAA;IAAA;GAAA,CAAA,CAAA;EAAA;CAAA,CAAA,GAAA4B,gBAMpDxD,MAAI;EAAA,IAACoF,OAAI;GAAA,OAAE1C,MAAMb;EAAS;EAAA8B,WACvB9B,cAAS2B,gBACR3C,wBAAsB;GAAA,IACrB8B,OAAI;IAAA,OAAEE,WAAW;GAAC;GAClBa,cAAcZ;GAAa,IAC3BxB,aAAU;IAAA,OAAEoB,MAAMpB;GAAU;GAAA,IAC5BO,YAAS;IAAA,OAAEA,UAAU;GAAC;GACtByD,uBAAuBvC;EAAO,CAAA;CAEjC,CAAA,CAAA;AAIT"}
1
+ {"version":3,"file":"workspace-switcher.js","names":["ArrowDownUp","ChevronDown","Plus","Settings","JSX","Dynamic","For","Show","createSignal","onCleanup","cn","DropdownMenu","DropdownMenuContent","DropdownMenuGroup","DropdownMenuItem","DropdownMenuLabel","DropdownMenuRadioGroup","DropdownMenuRadioItem","DropdownMenuSeparator","DropdownMenuTrigger","ActionButton","loadReorderDialog","ReorderDialog","Awaited","ReturnType","WorkspaceSwitcherItem","id","name","mark","Element","detail","fixed","WorkspaceSwitcherProps","workspaces","value","onValueChange","onCreate","createLabel","onManage","manageLabel","onReorder","ids","Promise","reorderLabel","reorderErrorLabel","label","placeholder","disabled","class","drawMark","copy","Node","cloneNode","WorkspaceSwitcher","props","open","setOpen","reordering","setReordering","reorderDialog","setReorderDialog","reorderFailed","setReorderFailed","cancelPending","trigger","HTMLElement","current","find","item","canReorder","undefined","filter","length","loadDialog","then","module","WorkspaceReorderDialog","warm","next","requestReorder","waiting","stop","document","removeEventListener","onKey","event","KeyboardEvent","key","addEventListener","loaded","stillWanted","_$createComponent","modal","onOpenChange","children","as","variant","size","ref","el","tooltip","aria-label","_el$","_tmpl$","_$insert","_c$","_$memo","_el$2","_tmpl$2","align","sideOffset","onChange","String","each","closeOnSelect","data-workspace-id","_el$3","_el$4","_tmpl$3","when","onSelect","component","restoreFocusRef","_$createComponent","_$memo"],"sources":["../../../../src/components/composites/workspace-switcher/workspace-switcher.tsx"],"sourcesContent":["import { ArrowDownUp, ChevronDown, Plus, Settings } from 'lucide-solid'\nimport type { JSX } from 'solid-js'\nimport { Dynamic } from 'solid-js/web'\nimport { For, Show, createSignal, onCleanup } from 'solid-js'\nimport { cn } from '#lib/utils'\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from '../../ui/dropdown-menu'\nimport { ActionButton } from '../action-button'\n\n// The dialog is only reachable from a menu item, so it stays out of the code\n// that ships with the switcher and loads on demand.\nconst loadReorderDialog = () => import('./workspace-reorder-dialog')\ntype ReorderDialog = Awaited<ReturnType<typeof loadReorderDialog>>['WorkspaceReorderDialog']\n\n/**\n * WorkspaceSwitcher.\n *\n * The workspace picker that sits in the top bar beside the sidebar toggle. One\n * ghost button shows the current workspace's mark and name; pressing it opens a\n * radio list of the others. Choosing one only changes what the window is\n * looking at: the switcher reports the id and the host decides what that means,\n * which is why it carries no status of its own and never closes, restarts or\n * moves anything.\n *\n * It is deliberately the simple interaction (a single menu, not a nested\n * accordion): the sidebar below it already shows what is inside the chosen\n * workspace, so the switcher's only job is to name the workspace and let the\n * user change it.\n */\nexport type WorkspaceSwitcherItem = {\n id: string\n name: string\n /**\n * The workspace's mark, drawn in the trigger and in its row. Decorative.\n *\n * A DOM node can sit in one place, so the current workspace's mark would have\n * to be in the trigger and its menu row at once. Pass a function to draw a\n * fresh mark in each place (the preferred form). A node built once is also\n * safe: the trigger keeps it and the current row gets a copy, which carries\n * no event handlers or reactive bindings, so keep marks static.\n */\n mark: JSX.Element | (() => JSX.Element)\n /** A quiet trailing readout in the row, e.g. an unread count. Optional. */\n detail?: JSX.Element\n /** Pinned to the top of the order, e.g. Home: it cannot be moved and nothing moves above it. */\n fixed?: boolean\n}\n\nexport type WorkspaceSwitcherProps = {\n workspaces: readonly WorkspaceSwitcherItem[]\n /** The current workspace's id. */\n value: string | undefined\n onValueChange(id: string): void\n /** Offered at the foot of the menu when present. */\n onCreate?(): void\n createLabel?: string\n /** Offered beside the create action when present: open the current workspace's settings. */\n onManage?(): void\n manageLabel?: string\n /**\n * Offered when present and at least two workspaces can move: opens a dialog\n * with Move up and Move down on each row. Receives the full id order after\n * each move; the host saves it and passes the workspaces back in that order.\n */\n onReorder?(ids: readonly string[]): void | Promise<void>\n reorderLabel?: string\n /** Replaces the \"Reorder workspaces…\" item when the dialog could not be loaded. */\n reorderErrorLabel?: string\n /** The menu's heading; also the trigger's accessible-name prefix. */\n label?: string\n /** Shown while no workspace is current. */\n placeholder?: string\n disabled?: boolean\n class?: string\n}\n\n/**\n * Draws one placement of a mark. A function draws anew each time; a node that is\n * already placed elsewhere is copied so the original stays where it is.\n */\nfunction drawMark(mark: WorkspaceSwitcherItem['mark'], copy: boolean): JSX.Element {\n if (typeof mark === 'function') return mark()\n return copy && mark instanceof Node ? mark.cloneNode(true) : mark\n}\n\nexport function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {\n const [open, setOpen] = createSignal(false)\n const [reordering, setReordering] = createSignal(false)\n const [reorderDialog, setReorderDialog] = createSignal<ReorderDialog>()\n const [reorderFailed, setReorderFailed] = createSignal(false)\n let cancelPending: (() => void) | undefined\n let trigger: HTMLElement | undefined\n const current = () => props.workspaces.find((item) => item.id === props.value)\n const label = () => props.label ?? 'Workspaces'\n const canReorder = () =>\n props.onReorder !== undefined && props.workspaces.filter((item) => !item.fixed).length > 1\n\n // Fetch the dialog's code. Safe to call early and often: the browser keeps one\n // copy, and a failure is remembered here instead of surfacing as an unhandled\n // rejection, so the switcher keeps working without reordering.\n const loadDialog = () =>\n loadReorderDialog().then(\n (module) => {\n setReorderDialog(() => module.WorkspaceReorderDialog)\n return true\n },\n () => {\n setReorderFailed(true)\n return false\n }\n )\n // Warm the chunk while the menu is open, so choosing the item rarely waits.\n const warm = (next: boolean) => {\n setOpen(next)\n if (next && canReorder() && !reorderDialog()) void loadDialog()\n }\n // Choosing the item while the code is still arriving must not open the dialog\n // late: nothing on screen can take Escape or an outside click yet, so either\n // of them withdraws the request, and the dialog opens only if the user waits.\n const requestReorder = () => {\n cancelPending?.()\n if (reorderDialog()) {\n setReordering(true)\n return\n }\n let waiting = true\n const stop = () => {\n waiting = false\n document.removeEventListener('keydown', onKey, true)\n document.removeEventListener('pointerdown', stop, true)\n if (cancelPending === stop) cancelPending = undefined\n }\n const onKey = (event: KeyboardEvent) => {\n if (event.key === 'Escape') stop()\n }\n document.addEventListener('keydown', onKey, true)\n document.addEventListener('pointerdown', stop, true)\n cancelPending = stop\n void loadDialog().then((loaded) => {\n const stillWanted = waiting\n stop()\n if (loaded && stillWanted) setReordering(true)\n })\n }\n onCleanup(() => cancelPending?.())\n\n return (\n <>\n <DropdownMenu modal={false} open={open()} onOpenChange={warm}>\n <DropdownMenuTrigger\n as={ActionButton}\n variant=\"ghost\"\n size=\"sm\"\n disabled={props.disabled}\n ref={(el: HTMLElement) => (trigger = el)}\n data-slot=\"workspace-switcher\"\n tooltip={`Workspace: ${current()?.name ?? props.placeholder ?? 'Choose workspace'}`}\n aria-label={`Switch workspace, current: ${current()?.name ?? 'none'}`}\n class={cn('max-w-full min-w-0 shrink', props.class)}\n >\n <span aria-hidden=\"true\" class=\"flex shrink-0\">\n {current() && drawMark(current()!.mark, false)}\n </span>\n <span class=\"min-w-0 max-w-40 truncate\">\n {current()?.name ?? props.placeholder ?? 'Choose workspace'}\n </span>\n <ChevronDown aria-hidden=\"true\" class=\"size-3.5 shrink-0 text-muted-foreground\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"start\" sideOffset={6} class=\"min-w-56\">\n <DropdownMenuGroup>\n <DropdownMenuLabel>{label()}</DropdownMenuLabel>\n <DropdownMenuRadioGroup\n value={props.value}\n onChange={(value) => {\n setOpen(false)\n const id = String(value)\n if (id !== props.value) props.onValueChange(id)\n }}\n >\n <For each={props.workspaces}>\n {(item) => (\n <DropdownMenuRadioItem value={item.id} closeOnSelect data-workspace-id={item.id}>\n <span aria-hidden=\"true\" class=\"flex shrink-0\">\n {drawMark(item.mark, item.id === props.value)}\n </span>\n <span class=\"min-w-0 flex-1 truncate\">{item.name}</span>\n <Show when={item.detail}>{item.detail}</Show>\n </DropdownMenuRadioItem>\n )}\n </For>\n </DropdownMenuRadioGroup>\n </DropdownMenuGroup>\n <Show when={props.onCreate || props.onManage || canReorder()}>\n <DropdownMenuSeparator />\n <Show when={props.onCreate}>\n <DropdownMenuItem onSelect={() => props.onCreate?.()}>\n <Plus aria-hidden=\"true\" />\n {props.createLabel ?? 'New workspace'}\n </DropdownMenuItem>\n </Show>\n <Show when={canReorder()}>\n <DropdownMenuItem disabled={reorderFailed()} onSelect={requestReorder}>\n <ArrowDownUp aria-hidden=\"true\" />\n {reorderFailed()\n ? (props.reorderErrorLabel ?? 'Couldn’t load reordering. Reload to try again.')\n : (props.reorderLabel ?? 'Reorder workspaces…')}\n </DropdownMenuItem>\n </Show>\n <Show when={props.onManage}>\n <DropdownMenuItem onSelect={() => props.onManage?.()}>\n <Settings aria-hidden=\"true\" />\n {props.manageLabel ?? 'Workspace settings…'}\n </DropdownMenuItem>\n </Show>\n </Show>\n </DropdownMenuContent>\n </DropdownMenu>\n <Show when={reorderDialog() && props.onReorder}>\n {(onReorder) => (\n <Dynamic\n component={reorderDialog()}\n open={reordering()}\n onOpenChange={setReordering}\n workspaces={props.workspaces}\n onReorder={onReorder()}\n restoreFocusRef={() => trigger}\n />\n )}\n </Show>\n </>\n )\n}\n"],"mappings":";;;;;;;;;;AAoBA,IAAMqB,0BAA0B,OAAO;;;;;AAqEvC,SAAS4B,SAASrB,MAAqCsB,MAA4B;CACjF,IAAI,OAAOtB,SAAS,YAAY,OAAOA,KAAK;CAC5C,OAAOsB,QAAQtB,gBAAgBuB,OAAOvB,KAAKwB,UAAU,IAAI,IAAIxB;AAC/D;AAEA,SAAgByB,kBAAkBC,OAA+B;CAC/D,MAAM,CAACC,MAAMC,WAAWhD,aAAa,KAAK;CAC1C,MAAM,CAACiD,YAAYC,iBAAiBlD,aAAa,KAAK;CACtD,MAAM,CAACmD,eAAeC,oBAAoBpD,aAA4B;CACtE,MAAM,CAACqD,eAAeC,oBAAoBtD,aAAa,KAAK;CAC5D,IAAIuD;CACJ,IAAIC;CACJ,MAAME,gBAAgBZ,MAAMrB,WAAWkC,MAAMC,SAASA,KAAK1C,OAAO4B,MAAMpB,KAAK;CAC7E,MAAMW,cAAcS,MAAMT,SAAS;CACnC,MAAMwB,mBACJf,MAAMd,cAAc8B,KAAAA,KAAahB,MAAMrB,WAAWsC,QAAQH,SAAS,CAACA,KAAKrC,KAAK,CAAC,CAACyC,SAAS;CAK3F,MAAMC,mBACJpD,kBAAkB,CAAC,CAACqD,MACjBC,WAAW;EACVf,uBAAuBe,OAAOC,sBAAsB;EACpD,OAAO;CACT,SACM;EACJd,iBAAiB,IAAI;EACrB,OAAO;CACT,CACF;CAEF,MAAMe,QAAQC,SAAkB;EAC9BtB,QAAQsB,IAAI;EACZ,IAAIA,QAAQT,WAAW,KAAK,CAACV,cAAc,GAAG,WAAgB;CAChE;CAIA,MAAMoB,uBAAuB;EAC3BhB,gBAAgB;EAChB,IAAIJ,cAAc,GAAG;GACnBD,cAAc,IAAI;GAClB;EACF;EACA,IAAIsB,UAAU;EACd,MAAMC,aAAa;GACjBD,UAAU;GACVE,SAASC,o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AAA,IAAAwD,WAAA;UAAA,OAAAH,gBACvB7E,kBAAgB;WAAC0G,gBAAgBlE,MAAMhB,WAAW;WAAC,IAAAwD,WAAA;YAAA,OAAA,CAAAH,gBACjDxF,UAAQ,EAAA,eAAA,OAAA,CAAA,GAAAuG,WACRpD,MAAMf,eAAe,qBAAqB,CAAA;WAAA;UAAA,CAAA;SAAA;QAAA,CAAA;OAAA;MAAA;KAAA,CAAA,CAAA;IAAA;GAAA,CAAA,CAAA;EAAA;CAAA,CAAA,GAAAoD,gBAMpDpF,MAAI;EAAA,IAACgH,OAAI;GAAA,OAAEb,WAAA,CAAA,CAAA/C,cAAc,CAAC,CAAA,CAAA,KAAIL,MAAMd;EAAS;EAAAsD,WAC1CtD,cAASmD,gBACRtF,SAAO;GAAA,IACNoH,YAAS;IAAA,OAAE9D,cAAc;GAAC;GAAA,IAC1BJ,OAAI;IAAA,OAAEE,WAAW;GAAC;GAClBoC,cAAcnC;GAAa,IAC3BzB,aAAU;IAAA,OAAEqB,MAAMrB;GAAU;GAAA,IAC5BO,YAAS;IAAA,OAAEA,UAAU;GAAC;GACtBkF,uBAAuB1D;EAAO,CAAA;CAEjC,CAAA,CAAA;AAIT"}
package/dist/index.js CHANGED
@@ -189,9 +189,9 @@ import { UpdateChannelControl } from "./components/composites/update-dialog/chan
189
189
  import { AboutDialog } from "./components/composites/about-dialog/about-dialog.js";
190
190
  import { HelpCenter } from "./components/composites/help-center/help-center.js";
191
191
  import { WorkspaceMark } from "./components/composites/workspace-mark/workspace-mark.js";
192
+ import { WorkspaceSwitcher } from "./components/composites/workspace-switcher/workspace-switcher.js";
192
193
  import { moveTarget, moveWorkspace } from "./components/composites/workspace-switcher/workspace-order.js";
193
194
  import { WorkspaceReorderDialog } from "./components/composites/workspace-switcher/workspace-reorder-dialog.js";
194
- import { WorkspaceSwitcher } from "./components/composites/workspace-switcher/workspace-switcher.js";
195
195
  import { MARK_IMAGE_MAX_DATA_URL_LENGTH, MARK_IMAGE_MAX_SOURCE_BYTES, MARK_IMAGE_SIZE, MarkImageError, centredSquare, checkMarkImageFile, isMarkImageDataUrl, markImageFromFile, markImageProblemCopy } from "./components/composites/icon-picker/image-data-url.js";
196
196
  import { isShellIconKey, resolveShellIcon, shellIconEntries, shellIconLabel } from "./components/composites/icon-picker/shell-icons.js";
197
197
  import { IconPicker, IconPickerDropdown } from "./components/composites/icon-picker/icon-picker.js";
@@ -84,11 +84,12 @@ export function WorkspaceReorderDialog(props: WorkspaceReorderDialogProps) {
84
84
  })
85
85
 
86
86
  const focusMove = (owner: number, id: string, direction: WorkspaceMoveDirection) => {
87
- // The host re-renders the rows with the new order; focus the same control
88
- // once it exists, or its sibling when the move reached an edge.
87
+ // The host re-renders the rows with the new order, which replaces the control
88
+ // that had focus; focus the same control once it exists, or its sibling when
89
+ // the move reached an edge. Try at once so keys pressed right after a save
90
+ // still reach the dialog, and again next frame for a host that renders later.
89
91
  if (frame !== undefined) cancelAnimationFrame(frame)
90
- frame = requestAnimationFrame(() => {
91
- frame = undefined
92
+ const restore = () => {
92
93
  if (disposed || owner !== session || !props.open) return
93
94
  const row = list?.querySelector<HTMLElement>(`[data-reorder-id="${CSS.escape(id)}"]`)
94
95
  const wanted = row?.querySelector<HTMLElement>(`[data-move="${direction}"]`)
@@ -96,7 +97,12 @@ export function WorkspaceReorderDialog(props: WorkspaceReorderDialogProps) {
96
97
  `[data-move="${direction === 'up' ? 'down' : 'up'}"]`
97
98
  )
98
99
  const target = wanted?.getAttribute('aria-disabled') === 'true' ? other : wanted
99
- target?.focus({ preventScroll: true })
100
+ if (target && document.activeElement !== target) target.focus({ preventScroll: true })
101
+ }
102
+ restore()
103
+ frame = requestAnimationFrame(() => {
104
+ frame = undefined
105
+ restore()
100
106
  })
101
107
  }
102
108
 
@@ -1,6 +1,7 @@
1
1
  import { ArrowDownUp, ChevronDown, Plus, Settings } from 'lucide-solid'
2
2
  import type { JSX } from 'solid-js'
3
- import { For, Show, createSignal } from 'solid-js'
3
+ import { Dynamic } from 'solid-js/web'
4
+ import { For, Show, createSignal, onCleanup } from 'solid-js'
4
5
  import { cn } from '../../../lib/utils'
5
6
  import {
6
7
  DropdownMenu,
@@ -14,7 +15,11 @@ import {
14
15
  DropdownMenuTrigger,
15
16
  } from '../../ui/dropdown-menu'
16
17
  import { ActionButton } from '../action-button'
17
- import { WorkspaceReorderDialog } from './workspace-reorder-dialog'
18
+
19
+ // The dialog is only reachable from a menu item, so it stays out of the code
20
+ // that ships with the switcher and loads on demand.
21
+ const loadReorderDialog = () => import('./workspace-reorder-dialog')
22
+ type ReorderDialog = Awaited<ReturnType<typeof loadReorderDialog>>['WorkspaceReorderDialog']
18
23
 
19
24
  /**
20
25
  * WorkspaceSwitcher.
@@ -68,6 +73,8 @@ export type WorkspaceSwitcherProps = {
68
73
  */
69
74
  onReorder?(ids: readonly string[]): void | Promise<void>
70
75
  reorderLabel?: string
76
+ /** Replaces the "Reorder workspaces…" item when the dialog could not be loaded. */
77
+ reorderErrorLabel?: string
71
78
  /** The menu's heading; also the trigger's accessible-name prefix. */
72
79
  label?: string
73
80
  /** Shown while no workspace is current. */
@@ -88,15 +95,67 @@ function drawMark(mark: WorkspaceSwitcherItem['mark'], copy: boolean): JSX.Eleme
88
95
  export function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {
89
96
  const [open, setOpen] = createSignal(false)
90
97
  const [reordering, setReordering] = createSignal(false)
98
+ const [reorderDialog, setReorderDialog] = createSignal<ReorderDialog>()
99
+ const [reorderFailed, setReorderFailed] = createSignal(false)
100
+ let cancelPending: (() => void) | undefined
91
101
  let trigger: HTMLElement | undefined
92
102
  const current = () => props.workspaces.find((item) => item.id === props.value)
93
103
  const label = () => props.label ?? 'Workspaces'
94
104
  const canReorder = () =>
95
105
  props.onReorder !== undefined && props.workspaces.filter((item) => !item.fixed).length > 1
96
106
 
107
+ // Fetch the dialog's code. Safe to call early and often: the browser keeps one
108
+ // copy, and a failure is remembered here instead of surfacing as an unhandled
109
+ // rejection, so the switcher keeps working without reordering.
110
+ const loadDialog = () =>
111
+ loadReorderDialog().then(
112
+ (module) => {
113
+ setReorderDialog(() => module.WorkspaceReorderDialog)
114
+ return true
115
+ },
116
+ () => {
117
+ setReorderFailed(true)
118
+ return false
119
+ }
120
+ )
121
+ // Warm the chunk while the menu is open, so choosing the item rarely waits.
122
+ const warm = (next: boolean) => {
123
+ setOpen(next)
124
+ if (next && canReorder() && !reorderDialog()) void loadDialog()
125
+ }
126
+ // Choosing the item while the code is still arriving must not open the dialog
127
+ // late: nothing on screen can take Escape or an outside click yet, so either
128
+ // of them withdraws the request, and the dialog opens only if the user waits.
129
+ const requestReorder = () => {
130
+ cancelPending?.()
131
+ if (reorderDialog()) {
132
+ setReordering(true)
133
+ return
134
+ }
135
+ let waiting = true
136
+ const stop = () => {
137
+ waiting = false
138
+ document.removeEventListener('keydown', onKey, true)
139
+ document.removeEventListener('pointerdown', stop, true)
140
+ if (cancelPending === stop) cancelPending = undefined
141
+ }
142
+ const onKey = (event: KeyboardEvent) => {
143
+ if (event.key === 'Escape') stop()
144
+ }
145
+ document.addEventListener('keydown', onKey, true)
146
+ document.addEventListener('pointerdown', stop, true)
147
+ cancelPending = stop
148
+ void loadDialog().then((loaded) => {
149
+ const stillWanted = waiting
150
+ stop()
151
+ if (loaded && stillWanted) setReordering(true)
152
+ })
153
+ }
154
+ onCleanup(() => cancelPending?.())
155
+
97
156
  return (
98
157
  <>
99
- <DropdownMenu modal={false} open={open()} onOpenChange={setOpen}>
158
+ <DropdownMenu modal={false} open={open()} onOpenChange={warm}>
100
159
  <DropdownMenuTrigger
101
160
  as={ActionButton}
102
161
  variant="ghost"
@@ -149,9 +208,11 @@ export function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {
149
208
  </DropdownMenuItem>
150
209
  </Show>
151
210
  <Show when={canReorder()}>
152
- <DropdownMenuItem onSelect={() => setReordering(true)}>
211
+ <DropdownMenuItem disabled={reorderFailed()} onSelect={requestReorder}>
153
212
  <ArrowDownUp aria-hidden="true" />
154
- {props.reorderLabel ?? 'Reorder workspaces…'}
213
+ {reorderFailed()
214
+ ? (props.reorderErrorLabel ?? 'Couldn’t load reordering. Reload to try again.')
215
+ : (props.reorderLabel ?? 'Reorder workspaces…')}
155
216
  </DropdownMenuItem>
156
217
  </Show>
157
218
  <Show when={props.onManage}>
@@ -163,9 +224,10 @@ export function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {
163
224
  </Show>
164
225
  </DropdownMenuContent>
165
226
  </DropdownMenu>
166
- <Show when={props.onReorder}>
227
+ <Show when={reorderDialog() && props.onReorder}>
167
228
  {(onReorder) => (
168
- <WorkspaceReorderDialog
229
+ <Dynamic
230
+ component={reorderDialog()}
169
231
  open={reordering()}
170
232
  onOpenChange={setReordering}
171
233
  workspaces={props.workspaces}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/ui",
3
- "version": "0.145.1",
3
+ "version": "0.145.2",
4
4
  "description": "The Adea design system: Kobalte-backed Solid components, semantic OKLCH tokens, and the app-shell layout primitives shared by Adea and Cortana.",
5
5
  "keywords": [
6
6
  "adea",
@@ -84,11 +84,12 @@ export function WorkspaceReorderDialog(props: WorkspaceReorderDialogProps) {
84
84
  })
85
85
 
86
86
  const focusMove = (owner: number, id: string, direction: WorkspaceMoveDirection) => {
87
- // The host re-renders the rows with the new order; focus the same control
88
- // once it exists, or its sibling when the move reached an edge.
87
+ // The host re-renders the rows with the new order, which replaces the control
88
+ // that had focus; focus the same control once it exists, or its sibling when
89
+ // the move reached an edge. Try at once so keys pressed right after a save
90
+ // still reach the dialog, and again next frame for a host that renders later.
89
91
  if (frame !== undefined) cancelAnimationFrame(frame)
90
- frame = requestAnimationFrame(() => {
91
- frame = undefined
92
+ const restore = () => {
92
93
  if (disposed || owner !== session || !props.open) return
93
94
  const row = list?.querySelector<HTMLElement>(`[data-reorder-id="${CSS.escape(id)}"]`)
94
95
  const wanted = row?.querySelector<HTMLElement>(`[data-move="${direction}"]`)
@@ -96,7 +97,12 @@ export function WorkspaceReorderDialog(props: WorkspaceReorderDialogProps) {
96
97
  `[data-move="${direction === 'up' ? 'down' : 'up'}"]`
97
98
  )
98
99
  const target = wanted?.getAttribute('aria-disabled') === 'true' ? other : wanted
99
- target?.focus({ preventScroll: true })
100
+ if (target && document.activeElement !== target) target.focus({ preventScroll: true })
101
+ }
102
+ restore()
103
+ frame = requestAnimationFrame(() => {
104
+ frame = undefined
105
+ restore()
100
106
  })
101
107
  }
102
108
 
@@ -1,6 +1,7 @@
1
1
  import { ArrowDownUp, ChevronDown, Plus, Settings } from 'lucide-solid'
2
2
  import type { JSX } from 'solid-js'
3
- import { For, Show, createSignal } from 'solid-js'
3
+ import { Dynamic } from 'solid-js/web'
4
+ import { For, Show, createSignal, onCleanup } from 'solid-js'
4
5
  import { cn } from '#lib/utils'
5
6
  import {
6
7
  DropdownMenu,
@@ -14,7 +15,11 @@ import {
14
15
  DropdownMenuTrigger,
15
16
  } from '../../ui/dropdown-menu'
16
17
  import { ActionButton } from '../action-button'
17
- import { WorkspaceReorderDialog } from './workspace-reorder-dialog'
18
+
19
+ // The dialog is only reachable from a menu item, so it stays out of the code
20
+ // that ships with the switcher and loads on demand.
21
+ const loadReorderDialog = () => import('./workspace-reorder-dialog')
22
+ type ReorderDialog = Awaited<ReturnType<typeof loadReorderDialog>>['WorkspaceReorderDialog']
18
23
 
19
24
  /**
20
25
  * WorkspaceSwitcher.
@@ -68,6 +73,8 @@ export type WorkspaceSwitcherProps = {
68
73
  */
69
74
  onReorder?(ids: readonly string[]): void | Promise<void>
70
75
  reorderLabel?: string
76
+ /** Replaces the "Reorder workspaces…" item when the dialog could not be loaded. */
77
+ reorderErrorLabel?: string
71
78
  /** The menu's heading; also the trigger's accessible-name prefix. */
72
79
  label?: string
73
80
  /** Shown while no workspace is current. */
@@ -88,15 +95,67 @@ function drawMark(mark: WorkspaceSwitcherItem['mark'], copy: boolean): JSX.Eleme
88
95
  export function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {
89
96
  const [open, setOpen] = createSignal(false)
90
97
  const [reordering, setReordering] = createSignal(false)
98
+ const [reorderDialog, setReorderDialog] = createSignal<ReorderDialog>()
99
+ const [reorderFailed, setReorderFailed] = createSignal(false)
100
+ let cancelPending: (() => void) | undefined
91
101
  let trigger: HTMLElement | undefined
92
102
  const current = () => props.workspaces.find((item) => item.id === props.value)
93
103
  const label = () => props.label ?? 'Workspaces'
94
104
  const canReorder = () =>
95
105
  props.onReorder !== undefined && props.workspaces.filter((item) => !item.fixed).length > 1
96
106
 
107
+ // Fetch the dialog's code. Safe to call early and often: the browser keeps one
108
+ // copy, and a failure is remembered here instead of surfacing as an unhandled
109
+ // rejection, so the switcher keeps working without reordering.
110
+ const loadDialog = () =>
111
+ loadReorderDialog().then(
112
+ (module) => {
113
+ setReorderDialog(() => module.WorkspaceReorderDialog)
114
+ return true
115
+ },
116
+ () => {
117
+ setReorderFailed(true)
118
+ return false
119
+ }
120
+ )
121
+ // Warm the chunk while the menu is open, so choosing the item rarely waits.
122
+ const warm = (next: boolean) => {
123
+ setOpen(next)
124
+ if (next && canReorder() && !reorderDialog()) void loadDialog()
125
+ }
126
+ // Choosing the item while the code is still arriving must not open the dialog
127
+ // late: nothing on screen can take Escape or an outside click yet, so either
128
+ // of them withdraws the request, and the dialog opens only if the user waits.
129
+ const requestReorder = () => {
130
+ cancelPending?.()
131
+ if (reorderDialog()) {
132
+ setReordering(true)
133
+ return
134
+ }
135
+ let waiting = true
136
+ const stop = () => {
137
+ waiting = false
138
+ document.removeEventListener('keydown', onKey, true)
139
+ document.removeEventListener('pointerdown', stop, true)
140
+ if (cancelPending === stop) cancelPending = undefined
141
+ }
142
+ const onKey = (event: KeyboardEvent) => {
143
+ if (event.key === 'Escape') stop()
144
+ }
145
+ document.addEventListener('keydown', onKey, true)
146
+ document.addEventListener('pointerdown', stop, true)
147
+ cancelPending = stop
148
+ void loadDialog().then((loaded) => {
149
+ const stillWanted = waiting
150
+ stop()
151
+ if (loaded && stillWanted) setReordering(true)
152
+ })
153
+ }
154
+ onCleanup(() => cancelPending?.())
155
+
97
156
  return (
98
157
  <>
99
- <DropdownMenu modal={false} open={open()} onOpenChange={setOpen}>
158
+ <DropdownMenu modal={false} open={open()} onOpenChange={warm}>
100
159
  <DropdownMenuTrigger
101
160
  as={ActionButton}
102
161
  variant="ghost"
@@ -149,9 +208,11 @@ export function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {
149
208
  </DropdownMenuItem>
150
209
  </Show>
151
210
  <Show when={canReorder()}>
152
- <DropdownMenuItem onSelect={() => setReordering(true)}>
211
+ <DropdownMenuItem disabled={reorderFailed()} onSelect={requestReorder}>
153
212
  <ArrowDownUp aria-hidden="true" />
154
- {props.reorderLabel ?? 'Reorder workspaces…'}
213
+ {reorderFailed()
214
+ ? (props.reorderErrorLabel ?? 'Couldn’t load reordering. Reload to try again.')
215
+ : (props.reorderLabel ?? 'Reorder workspaces…')}
155
216
  </DropdownMenuItem>
156
217
  </Show>
157
218
  <Show when={props.onManage}>
@@ -163,9 +224,10 @@ export function WorkspaceSwitcher(props: WorkspaceSwitcherProps) {
163
224
  </Show>
164
225
  </DropdownMenuContent>
165
226
  </DropdownMenu>
166
- <Show when={props.onReorder}>
227
+ <Show when={reorderDialog() && props.onReorder}>
167
228
  {(onReorder) => (
168
- <WorkspaceReorderDialog
229
+ <Dynamic
230
+ component={reorderDialog()}
169
231
  open={reordering()}
170
232
  onOpenChange={setReordering}
171
233
  workspaces={props.workspaces}