@sincpro/web-composer 0.1.0 → 1.0.0

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,8 +1,10 @@
1
1
  import { DOCKS, Zone } from "./enums.js";
2
- import { sameRef } from "./resource.js";
2
+ import { formatRef, rootRef, sameRef, } from "./resource.js";
3
3
  export { DOCKS, Zone };
4
4
  /** The page is not a panel and has no id; it needs one so it can be focused and maximized. */
5
5
  export const PAGE = "page";
6
+ /** Nor is the peek; it needs one to take the focus and publish a selection. */
7
+ export const PEEK = "peek";
6
8
  export const DEFAULT_ZONES = {
7
9
  [Zone.Left]: 0.28,
8
10
  [Zone.Right]: 0.36,
@@ -20,9 +22,11 @@ export const EMPTY = {
20
22
  panels: [],
21
23
  zones: DEFAULT_ZONES,
22
24
  peek: null,
25
+ peekTrail: [],
23
26
  focus: PAGE,
24
27
  maximized: null,
25
28
  selected: null,
29
+ titles: {},
26
30
  };
27
31
  const clampZone = (n) => Math.max(MIN_ZONE, Math.min(MAX_ZONE, n));
28
32
  /** The id comes from the content and not from a global counter, so two identical workspaces
@@ -34,6 +38,14 @@ function nextId(used) {
34
38
  return `p${n}`;
35
39
  }
36
40
  export const findPanel = (w, id) => w.panels.find((p) => p.id === id) ?? null;
41
+ /** What a surface shows now — the page, the peek or a panel — or `null` if it is not there. */
42
+ export function refOn(w, surface) {
43
+ if (surface === PAGE)
44
+ return w.page;
45
+ if (surface === PEEK)
46
+ return w.peek;
47
+ return findPanel(w, surface)?.view ?? null;
48
+ }
37
49
  export const panelsIn = (w, zone) => w.panels.filter((p) => p.placement.zone === zone);
38
50
  function withPanel(w, id, change) {
39
51
  if (!w.panels.some((p) => p.id === id))
@@ -74,6 +86,15 @@ function placementFor(zone, panels) {
74
86
  };
75
87
  }
76
88
  /* ── The page ───────────────────────────────────────────────────────── */
89
+ /**
90
+ * The peek is a drawer over THIS page. When the page becomes another resource the drawer would
91
+ * float over something that is no longer there, so it closes; another face of the same one —
92
+ * only `params` change: a filter, a tab — keeps it.
93
+ */
94
+ function leavePage(w, next) {
95
+ const stays = w.page !== null && next.page !== null && sameRef(rootRef(w.page), rootRef(next.page));
96
+ return stays ? next : closePeek(next);
97
+ }
77
98
  /**
78
99
  * Opens `view` as the page and keeps where I was, so the breadcrumb can take me back. The first
79
100
  * page has nothing behind it. When there is nothing to change it returns THE SAME object —
@@ -85,19 +106,40 @@ export function push(w, view) {
85
106
  return { ...w, page: view };
86
107
  if (sameRef(w.page, view))
87
108
  return w;
88
- return { ...w, page: view, trail: [...w.trail, w.page], selected: dropSelection(w, PAGE) };
109
+ return leavePage(w, {
110
+ ...w,
111
+ page: view,
112
+ trail: [...w.trail, w.page],
113
+ selected: dropSelection(w, PAGE),
114
+ });
115
+ }
116
+ /** Puts `view` where the page is WITHOUT a crumb: a filter that changed, or the record a form
117
+ * just created — the form should not stay in the way back. */
118
+ export function replace(w, view) {
119
+ if (w.page === null)
120
+ return { ...w, page: view };
121
+ if (sameRef(w.page, view))
122
+ return w;
123
+ return leavePage(w, { ...w, page: view, selected: dropSelection(w, PAGE) });
124
+ }
125
+ /** Starting over, from a menu: `view` is the page and the way back starts with it. The panels
126
+ * stay — they are how the person arranged the desk, not where they were. */
127
+ export function start(w, view) {
128
+ if (w.page !== null && sameRef(w.page, view) && w.trail.length === 0 && w.peek === null)
129
+ return w;
130
+ return closePeek({ ...w, page: view, trail: [], selected: dropSelection(w, PAGE) });
89
131
  }
90
132
  /** Back to the page at `index` of the trail; the pages after it are dropped. A crumb is this. */
91
133
  export function goTo(w, index) {
92
134
  const target = w.trail[index];
93
135
  if (target === undefined)
94
136
  return w;
95
- return {
137
+ return leavePage(w, {
96
138
  ...w,
97
139
  page: target,
98
140
  trail: w.trail.slice(0, index),
99
141
  selected: dropSelection(w, PAGE),
100
- };
142
+ });
101
143
  }
102
144
  /** One page back. Nothing to go back to is not an error: it changes nothing. */
103
145
  export const back = (w) => w.trail.length === 0 ? w : goTo(w, w.trail.length - 1);
@@ -196,8 +238,11 @@ export function collapsePanel(w, id) {
196
238
  placement: { ...p.placement, collapsed: p.placement.collapsed !== true },
197
239
  }));
198
240
  }
199
- /** Take the whole workspace. Calling it on what is already maximized gives it back. */
241
+ /** Take the whole workspace. Calling it on what is already maximized gives it back. The peek is
242
+ * a drawer: it grows into the page instead (`peekToPage`). */
200
243
  export function maximize(w, target) {
244
+ if (target === PEEK)
245
+ return w;
201
246
  if (target !== null && target !== PAGE && findPanel(w, target) === null)
202
247
  return w;
203
248
  return { ...w, maximized: w.maximized === target ? null : target };
@@ -206,13 +251,13 @@ export function maximize(w, target) {
206
251
  export function focusPanel(w, target) {
207
252
  if (w.focus === target)
208
253
  return w;
209
- if (target !== PAGE && findPanel(w, target) === null)
254
+ if (refOn(w, target) === null)
210
255
  return w;
211
256
  return { ...w, focus: target };
212
257
  }
213
- /** The next one in reading order: the page, then each panel. */
258
+ /** The next one in reading order: the page, the peek over it, then each panel. */
214
259
  export function cycleFocus(w, delta) {
215
- const order = [PAGE, ...w.panels.map((p) => p.id)];
260
+ const order = [PAGE, ...(w.peek === null ? [] : [PEEK]), ...w.panels.map((p) => p.id)];
216
261
  const current = Math.max(0, order.indexOf(w.focus));
217
262
  const next = order[(current + delta + order.length) % order.length];
218
263
  return next === undefined ? w : focusPanel(w, next);
@@ -228,12 +273,63 @@ export function expandPanel(w, id) {
228
273
  return push(closePanel(w, id), panel.view);
229
274
  }
230
275
  /* ── Peek ───────────────────────────────────────────────────────────── */
276
+ /**
277
+ * Opened from outside — a row, ⌘K — the drawer starts fresh: its trail is only of what was
278
+ * drilled INSIDE it. It takes the focus, so ⌘K acts on what I am reading. Without a page there
279
+ * is nothing to read beside, so it becomes the page.
280
+ */
231
281
  export function peek(w, view) {
232
- if (w.peek !== null && sameRef(w.peek, view))
282
+ if (w.page === null)
283
+ return push(w, view);
284
+ if (w.peek !== null && sameRef(w.peek, view) && w.peekTrail.length === 0)
233
285
  return w;
234
- return { ...w, peek: view };
286
+ return { ...w, peek: view, peekTrail: [], focus: PEEK, selected: dropSelection(w, PEEK) };
287
+ }
288
+ /** From inside the drawer: what it shows now goes to its trail, so ← comes back to it. */
289
+ export function drillPeek(w, view) {
290
+ if (w.peek === null)
291
+ return peek(w, view);
292
+ if (sameRef(w.peek, view))
293
+ return w;
294
+ return {
295
+ ...w,
296
+ peek: view,
297
+ peekTrail: [...w.peekTrail, w.peek],
298
+ selected: dropSelection(w, PEEK),
299
+ };
300
+ }
301
+ /** Another face, or the record a form in the drawer just created: no step in its trail. */
302
+ export function replacePeek(w, view) {
303
+ if (w.peek === null)
304
+ return peek(w, view);
305
+ if (sameRef(w.peek, view))
306
+ return w;
307
+ return { ...w, peek: view, selected: dropSelection(w, PEEK) };
308
+ }
309
+ /** Back to the step at `index` of the drawer's trail. */
310
+ export function peekGoTo(w, index) {
311
+ const target = w.peekTrail[index];
312
+ if (target === undefined)
313
+ return w;
314
+ return {
315
+ ...w,
316
+ peek: target,
317
+ peekTrail: w.peekTrail.slice(0, index),
318
+ selected: dropSelection(w, PEEK),
319
+ };
320
+ }
321
+ export const peekBack = (w) => w.peekTrail.length === 0 ? w : peekGoTo(w, w.peekTrail.length - 1);
322
+ export function closePeek(w) {
323
+ if (w.peek === null)
324
+ return w;
325
+ return {
326
+ ...w,
327
+ peek: null,
328
+ peekTrail: [],
329
+ focus: w.focus === PEEK ? PAGE : w.focus,
330
+ selected: dropSelection(w, PEEK),
331
+ };
235
332
  }
236
- export const closePeek = (w) => w.peek === null ? w : { ...w, peek: null };
237
333
  /** The peek becomes the page. */
238
334
  export function peekToPage(w) {
239
335
  return w.peek === null ? w : closePeek(push(w, w.peek));
@@ -263,10 +359,35 @@ export function select(w, by, refs) {
263
359
  return w;
264
360
  return { ...w, selected: { by, refs } };
265
361
  }
266
- /** What the user is working on: the page, or the panel that has the focus. */
362
+ /** What the user is working on: the page, the peek or the panel that has the focus. */
267
363
  export function focusedRef(w) {
268
- if (w.focus === PAGE)
269
- return w.page;
270
- return findPanel(w, w.focus)?.view ?? w.page;
364
+ return refOn(w, w.focus) ?? w.page;
365
+ }
366
+ /** Every resource the workspace shows or can go back to. */
367
+ const reachable = (w) => [
368
+ ...w.trail,
369
+ ...(w.page === null ? [] : [w.page]),
370
+ ...w.peekTrail,
371
+ ...(w.peek === null ? [] : [w.peek]),
372
+ ...w.panels.map((p) => p.view),
373
+ ];
374
+ /**
375
+ * The name a view gives its resource once it has loaded it — «Acme S.R.L.» instead of
376
+ * `acme`. `null` gives the `ViewSpec` title back. Names of what is no longer reachable are
377
+ * forgotten on the way, so the map does not grow with the session.
378
+ */
379
+ export function nameRef(w, ref, title) {
380
+ const key = formatRef(ref);
381
+ if ((w.titles[key] ?? null) === title)
382
+ return w;
383
+ const alive = new Set(reachable(w).map(formatRef));
384
+ const titles = {};
385
+ for (const [k, v] of Object.entries(w.titles))
386
+ if (k !== key && alive.has(k))
387
+ titles[k] = v;
388
+ if (title !== null)
389
+ titles[key] = title;
390
+ return { ...w, titles };
271
391
  }
392
+ export const nameOf = (w, ref) => w.titles[formatRef(ref)] ?? null;
272
393
  export const selectionOf = (w) => w.selected?.refs ?? NO_REFS;
package/dist/index.d.ts CHANGED
@@ -1,20 +1,24 @@
1
1
  /**
2
- * The shell — React and the design system. The model comes in through the other door,
3
- * `@sincpro/web-composer/domain`, which depends on nothing.
2
+ * The shell — React and nothing else: the composer draws its windows with its own skin
3
+ * (`sc-*` classes, `--sc-*` variables) and depends on no design system. The model comes in
4
+ * through the other door, `@sincpro/web-composer/domain`, which depends on nothing.
4
5
  *
5
6
  * Only the model TYPES that appear in these signatures are re-exported, so declaring a domain
6
7
  * does not force a two-place import.
7
8
  */
8
9
  export type { Action, Crumb, OpenOptions, PaletteEntry, PickOptions, Registry, ResourceRef, SearchHit, ViewProps, ViewSpec, Workspace, WorkspaceApi, } from "./domain/index.js";
9
- export { Destination, focusedRef, PAGE, PaletteSection, selectionOf, Surface, Zone, } from "./domain/index.js";
10
+ export { Destination, focusedRef, PAGE, PaletteSection, PEEK, selectionOf, Surface, Zone, } from "./domain/index.js";
10
11
  export { Composer, type ComposerProps } from "./shell/Composer.js";
11
12
  export { type ComposerCopy, composerCopy, ENGLISH_COMPOSER_COPY, installComposerCopy, SPANISH_COMPOSER_COPY, } from "./shell/copy.js";
13
+ export { type IconProps } from "./shell/icons.js";
12
14
  export { WorkspacePalette, type WorkspacePaletteProps, } from "./shell/Palette.js";
13
15
  export { type PanelActions, PanelFrame, type PanelFrameProps, } from "./shell/PanelFrame.js";
14
16
  export { PanelHost, type PanelHostProps } from "./shell/PanelHost.js";
15
17
  export { RecordLink, type RecordLinkProps } from "./shell/RecordLink.js";
18
+ export { type ComposerSkin, type ConfirmProps, DEFAULT_ICONS, type NoticeProps, type PeekProps, type SkinIcons, } from "./shell/skin.js";
19
+ export { ComposerStyles } from "./shell/styles.js";
16
20
  export { ViewHost, type ViewHostProps } from "./shell/ViewHost.js";
17
21
  export { type ApiFactory, createApiFactory, type Target, } from "./state/api.js";
18
- export { createWorkspaceStore, type StoreOptions, type WorkspaceStore, } from "./state/store.js";
22
+ export { type ConfirmDiscard, createWorkspaceStore, type StoreOptions, type WorkspaceStore, } from "./state/store.js";
19
23
  export { useKeyboard, type UseKeyboardOptions, } from "./state/useKeyboard.js";
20
24
  export { useWorkspace, useWorkspaceContext, useWorkspaceSlice, useWorkspaceState, } from "./state/useWorkspace.js";
package/dist/index.js CHANGED
@@ -1,17 +1,21 @@
1
1
  /**
2
- * The shell — React and the design system. The model comes in through the other door,
3
- * `@sincpro/web-composer/domain`, which depends on nothing.
2
+ * The shell — React and nothing else: the composer draws its windows with its own skin
3
+ * (`sc-*` classes, `--sc-*` variables) and depends on no design system. The model comes in
4
+ * through the other door, `@sincpro/web-composer/domain`, which depends on nothing.
4
5
  *
5
6
  * Only the model TYPES that appear in these signatures are re-exported, so declaring a domain
6
7
  * does not force a two-place import.
7
8
  */
8
- export { Destination, focusedRef, PAGE, PaletteSection, selectionOf, Surface, Zone, } from "./domain/index.js";
9
+ export { Destination, focusedRef, PAGE, PaletteSection, PEEK, selectionOf, Surface, Zone, } from "./domain/index.js";
9
10
  export { Composer } from "./shell/Composer.js";
10
11
  export { composerCopy, ENGLISH_COMPOSER_COPY, installComposerCopy, SPANISH_COMPOSER_COPY, } from "./shell/copy.js";
12
+ export {} from "./shell/icons.js";
11
13
  export { WorkspacePalette, } from "./shell/Palette.js";
12
14
  export { PanelFrame, } from "./shell/PanelFrame.js";
13
15
  export { PanelHost } from "./shell/PanelHost.js";
14
16
  export { RecordLink } from "./shell/RecordLink.js";
17
+ export { DEFAULT_ICONS, } from "./shell/skin.js";
18
+ export { ComposerStyles } from "./shell/styles.js";
15
19
  export { ViewHost } from "./shell/ViewHost.js";
16
20
  export { createApiFactory, } from "./state/api.js";
17
21
  export { createWorkspaceStore, } from "./state/store.js";
@@ -1,11 +1,7 @@
1
1
  import { Destination, type Registry } from "../domain/index.js";
2
+ import { type ComposerSkin } from "./skin.js";
2
3
  import type { WorkspaceStore } from "../state/store.js";
3
4
  import { type ReactNode } from "react";
4
- /**
5
- * The workspace — the page, the panels around it, the peek and ⌘K — wired against the
6
- * registry. Adding a domain does not touch any file in this package: register its `ViewSpec`
7
- * and it appears.
8
- */
9
5
  export type ComposerProps = {
10
6
  workspace: WorkspaceStore;
11
7
  registry: Registry;
@@ -20,5 +16,8 @@ export type ComposerProps = {
20
16
  * the state and only the shortcut opens it. */
21
17
  palette?: boolean;
22
18
  onPaletteChange?: (open: boolean) => void;
19
+ /** Your design over the composer: icons, the peek drawer, the confirm dialog, the notice, or
20
+ * `styles: false` to drop the default sheet. What is not passed keeps the default. */
21
+ skin?: ComposerSkin;
23
22
  };
24
- export declare function Composer({ workspace, registry, empty, keyboard, defaultOpen, palette: paletteProp, onPaletteChange, }: ComposerProps): import("react").JSX.Element;
23
+ export declare function Composer({ workspace, registry, empty, keyboard, defaultOpen, palette: paletteProp, onPaletteChange, skin: skinProp, }: ComposerProps): import("react").JSX.Element;
@@ -1,16 +1,39 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Destination, focusedRef, formatRef, Surface, Zone, } from "../domain/index.js";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Destination, focusedRef, PAGE, PEEK, Surface, Zone, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
4
  import { WorkspacePalette } from "./Palette.js";
5
5
  import { PanelHost } from "./PanelHost.js";
6
+ import { ChromeButton, ConfirmDialog, PeekDrawer } from "./Peek.js";
7
+ import { resolveSkin, SkinProvider, } from "./skin.js";
8
+ import { ComposerStyles } from "./styles.js";
6
9
  import { ViewHost } from "./ViewHost.js";
7
10
  import { createApiFactory } from "../state/api.js";
8
11
  import { useDropMonitor } from "../state/drag.js";
9
12
  import { useKeyboard } from "../state/useKeyboard.js";
10
13
  import { useWorkspaceState } from "../state/useWorkspace.js";
11
- import { Button, Peek } from "@sincpro/web-ui";
12
14
  import { useCallback, useEffect, useMemo, useState } from "react";
13
- export function Composer({ workspace, registry, empty, keyboard = true, defaultOpen = Destination.Page, palette: paletteProp, onPaletteChange, }) {
15
+ /**
16
+ * The question before throwing away what someone typed, drawn with the design system. The store
17
+ * calls it; a `confirmDiscard` given to the store replaces it.
18
+ */
19
+ function useDiscardDialog(workspace, titleOf) {
20
+ const [asking, setAsking] = useState(null);
21
+ useEffect(() => {
22
+ workspace.setConfirmDiscard((lost) => new Promise((resolve) => setAsking({
23
+ names: lost.map(titleOf),
24
+ answer: (ok) => {
25
+ setAsking(null);
26
+ resolve(ok);
27
+ },
28
+ })));
29
+ return () => workspace.setConfirmDiscard(null);
30
+ }, [workspace, titleOf]);
31
+ return asking;
32
+ }
33
+ export function Composer({ workspace, registry, empty, keyboard = true, defaultOpen = Destination.Page, palette: paletteProp, onPaletteChange, skin: skinProp, }) {
34
+ const skin = useMemo(() => resolveSkin(skinProp), [skinProp]);
35
+ const Drawer = skin.Peek ?? PeekDrawer;
36
+ const Confirm = skin.Confirm ?? ConfirmDialog;
14
37
  const state = useWorkspaceState(workspace);
15
38
  const copy = composerCopy();
16
39
  const [paletteState, setPaletteState] = useState(false);
@@ -30,30 +53,36 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
30
53
  onPanelToZone: workspace.movePanel,
31
54
  onRefToZone: (ref, zone) => workspace.openPanel(ref, zone),
32
55
  }), [workspace]));
33
- /** Where a chosen search result opens. Without a page yet, the first one becomes it. */
56
+ const asking = useDiscardDialog(workspace, api.titleOf);
57
+ /** Where a chosen search result opens. Without a page yet, the first one becomes it —
58
+ * whatever was asked: a peek or a window over nothing would be invisible. */
34
59
  function open(ref, destination) {
35
- const here = workspace.get();
36
- if (destination === Destination.Peek)
60
+ if (workspace.get().page === null)
61
+ workspace.push(ref);
62
+ else if (destination === Destination.Peek)
37
63
  workspace.peek(ref);
38
64
  else if (destination === Destination.Window)
39
65
  workspace.openPanel(ref, Zone.Floating);
40
- else if (destination === Destination.Side && here.page !== null)
66
+ else if (destination === Destination.Side)
41
67
  workspace.openPanel(ref, api.zoneFor(registry.resolve(ref)));
42
68
  else
43
69
  workspace.push(ref);
44
70
  }
45
- /** An action runs with the API of the surface its resource is on, so «audit» can open beside
46
- * it or navigate it. */
71
+ /** An action runs with the API of the surface its resource is on — the page, the peek I am
72
+ * reading or a panel — so «audit» can open beside it or navigate it. */
47
73
  function run(action) {
48
74
  const w = workspace.get();
49
75
  const ref = focusedRef(w);
50
76
  if (ref === null)
51
77
  return;
52
- action.run(api.for(ref, w.focus === "page"
78
+ action.run(api.for(ref, w.focus === PAGE
53
79
  ? { surface: Surface.Page }
54
- : { surface: Surface.Panel, panelId: w.focus }));
80
+ : w.focus === PEEK
81
+ ? { surface: Surface.Peek }
82
+ : { surface: Surface.Panel, panelId: w.focus }));
55
83
  }
56
84
  const peeked = state.peek;
57
85
  const peekSpec = peeked === null ? null : registry.resolve(peeked);
58
- return (_jsxs("div", { className: "relative flex min-h-0 flex-1 flex-col bg-ground", children: [state.page === null ? (_jsx("div", { className: "flex min-h-0 flex-1 items-center justify-center p-8", children: empty })) : (_jsx(PanelHost, { workspace: state, registry: registry, store: workspace, api: api, overlay: peeked === null ? null : (_jsx(Peek, { open: true, title: peekSpec?.title(peeked) ?? formatRef(peeked), onClose: workspace.closePeek, onPromote: () => workspace.peekToSide(peekSpec?.preferredZone ?? Zone.Right), actions: _jsx(Button, { size: "sm", role: "ghost", onClick: workspace.peekToPage, children: copy.peek.openAsPage }), children: _jsx(ViewHost, { resource: peeked, registry: registry, api: api.for(peeked, { surface: Surface.Peek }) }) })) })), palette ? (_jsx(WorkspacePalette, { registry: registry, focused: focusedRef(state), onOpen: open, onAction: run, onClose: () => setPalette(false) })) : null] }));
86
+ const cameFrom = state.peekTrail.at(-1);
87
+ return (_jsx(SkinProvider, { value: skin, children: _jsxs("div", { className: "sc-root", children: [skin.styles ? _jsx(ComposerStyles, {}) : null, state.page === null ? (_jsx("div", { className: "sc-empty", children: empty })) : (_jsx(PanelHost, { workspace: state, registry: registry, store: workspace, api: api, overlay: peeked === null ? null : (_jsx("div", { style: { display: "contents" }, onPointerDownCapture: () => workspace.focusPanel(PEEK), children: _jsx(Drawer, { title: api.titleOf(peeked), onClose: workspace.closePeek, actions: _jsxs(_Fragment, { children: [_jsx(ChromeButton, { onClick: () => workspace.peekToSide(peekSpec?.preferredZone ?? Zone.Right), children: copy.peek.openAsPanel }), cameFrom === undefined ? null : (_jsx(ChromeButton, { role: "ghost", icon: skin.icons.back, onClick: workspace.peekBack, children: copy.peek.back(api.titleOf(cameFrom)) })), _jsx(ChromeButton, { role: "ghost", onClick: workspace.peekToPage, children: copy.peek.openAsPage })] }), children: _jsx(ViewHost, { resource: peeked, registry: registry, api: api.for(peeked, { surface: Surface.Peek }) }) }) })) })), _jsx(Confirm, { open: asking !== null, title: copy.discard.title, detail: asking === null ? "" : copy.discard.detail(asking.names), keep: copy.discard.keep, discard: copy.discard.discard, onAnswer: (ok) => asking?.answer(ok) }), palette ? (_jsx(WorkspacePalette, { registry: registry, focused: focusedRef(state), onOpen: open, onAction: run, onClose: () => setPalette(false) })) : null] }) }));
59
88
  }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Destination, localEntries, matches, MIN_QUERY, PaletteSection, searchEntries, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
- import { Search } from "lucide-react";
4
+ import { useSkin } from "./skin.js";
5
5
  import { useEffect, useId, useMemo, useRef, useState, } from "react";
6
6
  /**
7
7
  * ⌘K over the workspace. The list is the model's (`localEntries`,
@@ -13,9 +13,9 @@ import { useEffect, useId, useMemo, useRef, useState, } from "react";
13
13
  * ⇧Enter a panel beside what I am on
14
14
  * ⌘Enter a window
15
15
  *
16
- * Built by hand because synthesis-ui has no palette. When this moves onto
17
- * `@sincpro/web-ui`, the drawing is its `CommandPalette` and only the
18
- * destinations stay here.
16
+ * Drawn here, with the composer's own skin: the composer depends on no design
17
+ * system. An application with its own palette keeps the destinations and the
18
+ * entries (`localEntries`, `searchEntries`) and draws them however it likes.
19
19
  */
20
20
  const SECTION_KEY = {
21
21
  [PaletteSection.Actions]: "actions",
@@ -63,6 +63,7 @@ function useFound(registry, query) {
63
63
  }
64
64
  export function WorkspacePalette({ registry, focused, onOpen, onAction, onClose, }) {
65
65
  const copy = composerCopy().palette;
66
+ const SearchIcon = useSkin().icons.search;
66
67
  const listId = useId();
67
68
  const [query, setQuery] = useState("");
68
69
  const [cursor, setCursor] = useState(0);
@@ -106,18 +107,18 @@ export function WorkspacePalette({ registry, focused, onOpen, onAction, onClose,
106
107
  e.preventDefault();
107
108
  }
108
109
  }
109
- return (_jsx("div", { className: "fixed inset-0 z-50 flex items-start justify-center bg-ink/30 px-4 pt-24", onPointerDown: (e) => {
110
+ return (_jsx("div", { className: "sc-scrim", onPointerDown: (e) => {
110
111
  if (e.target === e.currentTarget)
111
112
  onClose();
112
- }, children: _jsxs("div", { role: "dialog", "aria-label": copy.label, className: "w-full max-w-xl overflow-hidden rounded-box border border-line-strong bg-surface shadow-window", children: [_jsxs("div", { className: "flex items-center gap-2 border-b border-line px-3", children: [_jsx(Search, { className: "size-(--size-icon-md) shrink-0 text-muted", strokeWidth: 2, "aria-hidden": true }), _jsx("input", { autoFocus: true, role: "combobox", "aria-expanded": true, "aria-controls": listId, "aria-autocomplete": "list", ...(active === undefined
113
+ }, children: _jsxs("div", { role: "dialog", "aria-label": copy.label, className: "sc-palette", children: [_jsxs("div", { className: "sc-palette-search", children: [_jsx(SearchIcon, {}), _jsx("input", { autoFocus: true, role: "combobox", "aria-expanded": true, "aria-controls": listId, "aria-autocomplete": "list", ...(active === undefined
113
114
  ? {}
114
115
  : { "aria-activedescendant": `${listId}-${active.id}` }), value: query, placeholder: copy.placeholder, onChange: (e) => {
115
116
  setQuery(e.target.value);
116
117
  setCursor(0);
117
- }, onKeyDown: onKeyDown, className: "h-(--size-control-lg) min-w-0 flex-1 bg-transparent text-body text-ink outline-0 placeholder:text-muted" })] }), _jsxs("ul", { id: listId, role: "listbox", className: "max-h-96 overflow-y-auto p-1", children: [entries.map((entry, i) => {
118
+ }, onKeyDown: onKeyDown })] }), _jsxs("ul", { id: listId, role: "listbox", className: "sc-palette-list", children: [entries.map((entry, i) => {
118
119
  const Icon = entry.icon;
119
120
  const heading = entries[i - 1]?.section !== entry.section;
120
- return (_jsxs("li", { role: "presentation", children: [heading ? (_jsx("p", { className: "px-2 pt-2 pb-1 text-micro font-medium text-muted", children: copy.sections[SECTION_KEY[entry.section]] })) : null, _jsxs("div", { id: `${listId}-${entry.id}`, role: "option", "aria-selected": entry === active, onPointerMove: () => setCursor(i), onClick: (e) => run(entry, destinationOf(e)), className: `flex cursor-default items-center gap-2 rounded-control px-2 py-1.5 text-meta text-ink ${entry === active ? "bg-primary/8" : ""}`, children: [_jsx("span", { className: "flex size-(--size-icon-md) shrink-0 items-center justify-center text-muted", children: Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2 })) }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: entry.label }), entry.section !== PaletteSection.Actions && entry.detail !== undefined ? (_jsx("span", { className: "shrink-0 truncate text-micro text-muted", children: entry.detail })) : null, entry.section === PaletteSection.Actions &&
121
- entry.shortcut !== undefined ? (_jsx("kbd", { className: "shrink-0 rounded-control border border-line px-1.5 text-micro text-muted", children: entry.shortcut })) : null] })] }, entry.id));
122
- }), entries.length === 0 && !loading ? (_jsx("li", { className: "px-3 py-6 text-center text-meta text-muted italic", children: copy.empty })) : null, loading ? (_jsx("li", { className: "px-3 py-2 text-micro text-muted", children: copy.searching })) : null] }), _jsx("p", { className: "border-t border-line px-3 py-1.5 text-micro text-muted", children: copy.hint })] }) }));
121
+ return (_jsxs("li", { role: "presentation", children: [heading ? (_jsx("p", { className: "sc-palette-section", children: copy.sections[SECTION_KEY[entry.section]] })) : null, _jsxs("div", { id: `${listId}-${entry.id}`, role: "option", "aria-selected": entry === active, onPointerMove: () => setCursor(i), onClick: (e) => run(entry, destinationOf(e)), className: "sc-option", children: [_jsx("span", { className: "sc-option-icon", children: Icon === undefined ? null : _jsx(Icon, { strokeWidth: 2 }) }), _jsx("span", { className: "sc-option-label", children: entry.label }), entry.section !== PaletteSection.Actions && entry.detail !== undefined ? (_jsx("span", { className: "sc-option-detail", children: entry.detail })) : null, entry.section === PaletteSection.Actions &&
122
+ entry.shortcut !== undefined ? (_jsx("kbd", { className: "sc-kbd", children: entry.shortcut })) : null] })] }, entry.id));
123
+ }), entries.length === 0 && !loading ? (_jsx("li", { className: "sc-palette-empty", children: copy.empty })) : null, loading ? _jsx("li", { className: "sc-palette-empty", children: copy.searching }) : null] }), _jsx("p", { className: "sc-palette-hint", children: copy.hint })] }) }));
123
124
  }
@@ -1,8 +1,13 @@
1
1
  import { Zone } from "../domain/index.js";
2
2
  import { type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
3
3
  /**
4
- * The frame of a side panel or a window. Four icons, always the same, in OS order: more,
5
- * minimize, enlarge, close. The page has no frame: a list or a record draws its own header.
4
+ * The frame of a side panel or a window. Five controls, always the same: more, open as page,
5
+ * then in OS order minimize, enlarge, close. «Open as page» is out of the menu because it is
6
+ * what a record in a panel is asked for most — every view was drawing its own button for it.
7
+ * The page has no frame: a list or a record draws its own header.
8
+ *
9
+ * Minimized into a narrow strip (`rail`) the title reads vertically and only restore and close
10
+ * remain: there is no room for the rest, and nothing else makes sense until it is restored.
6
11
  */
7
12
  export type PanelActions = {
8
13
  onMove: (zone: Zone) => void;
@@ -17,6 +22,8 @@ export type PanelFrameProps = {
17
22
  zone: Zone;
18
23
  maximized: boolean;
19
24
  collapsed: boolean;
25
+ /** Minimized into a narrow strip: the title is drawn vertically. */
26
+ rail?: boolean;
20
27
  focused: boolean;
21
28
  /** The id a docked panel is dragged by. A window has none: it moves with the pointer. */
22
29
  dragId?: string;
@@ -26,6 +33,6 @@ export type PanelFrameProps = {
26
33
  onMoveStart?: (e: ReactPointerEvent) => void;
27
34
  children: ReactNode;
28
35
  };
29
- declare function Frame({ title, actions, zone, maximized, collapsed, focused, dragId, onMaximize, onFocus, onMoveStart, children, }: PanelFrameProps): import("react").JSX.Element;
36
+ declare function Frame({ title, actions, zone, maximized, collapsed, rail, focused, dragId, onMaximize, onFocus, onMoveStart, children, }: PanelFrameProps): import("react").JSX.Element;
30
37
  export declare const PanelFrame: import("react").MemoExoticComponent<typeof Frame>;
31
38
  export {};
@@ -1,44 +1,70 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Zone } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
+ import { useSkin } from "./skin.js";
4
5
  import { useDraggablePanel } from "../state/drag.js";
5
- import { Menu } from "@sincpro/web-ui";
6
- import { ArrowUpRight, Copy, Ellipsis, Minus, PanelBottom, PanelLeft, PanelRight, PictureInPicture2, Square, X, } from "lucide-react";
7
- import { memo, useRef } from "react";
8
- const DESTINATIONS = (c) => [
9
- { zone: Zone.Left, icon: PanelLeft, label: c.left, hint: c.leftHint },
10
- { zone: Zone.Right, icon: PanelRight, label: c.right, hint: c.rightHint },
11
- { zone: Zone.Bottom, icon: PanelBottom, label: c.bottom, hint: c.bottomHint },
12
- { zone: Zone.Floating, icon: PictureInPicture2, label: c.window, hint: c.windowHint },
6
+ import { memo, useEffect, useId, useRef, useState, } from "react";
7
+ const DESTINATIONS = (c, icons) => [
8
+ { zone: Zone.Left, icon: icons.left, label: c.left, hint: c.leftHint },
9
+ { zone: Zone.Right, icon: icons.right, label: c.right, hint: c.rightHint },
10
+ { zone: Zone.Bottom, icon: icons.bottom, label: c.bottom, hint: c.bottomHint },
11
+ { zone: Zone.Floating, icon: icons.window, label: c.window, hint: c.windowHint },
13
12
  ];
13
+ /* `onPointerDown` stops here: a control sits on the header, and the header drags. */
14
14
  function Control({ icon: Icon, label, active = false, danger = false, onClick, }) {
15
- const paint = active
16
- ? "bg-primary/12 text-primary"
17
- : danger
18
- ? "text-muted hover:bg-bad/10 hover:text-bad"
19
- : "text-muted hover:bg-ink/6 hover:text-ink";
20
- return (_jsx("button", { type: "button", title: label, "aria-label": label, "aria-pressed": active, onClick: onClick, onPointerDown: (e) => e.stopPropagation(), className: `inline-flex size-(--size-control-sm) shrink-0 items-center justify-center rounded-control transition-colors duration-(--duration-instant) focus-visible:outline-1 focus-visible:outline-offset-1 focus-visible:outline-primary ${paint}`, children: _jsx(Icon, { className: "size-(--size-icon-sm)", strokeWidth: 2 }) }));
15
+ return (_jsx("button", { type: "button", title: label, "aria-label": label, "aria-pressed": active, onClick: onClick, onPointerDown: (e) => e.stopPropagation(), className: "sc-control", ...(danger ? { "data-danger": "" } : {}), children: _jsx(Icon, {}) }));
21
16
  }
22
- const MenuAction = { Expand: "expand" };
23
- function Frame({ title, actions, zone, maximized, collapsed, focused, dragId, onMaximize, onFocus, onMoveStart, children, }) {
17
+ /**
18
+ * «Move to»: a menu button. Closes on a choice, on a press outside and on Escape — which it
19
+ * CLAIMS, so the workspace does not also close the peek or restore a maximized view.
20
+ */
21
+ function MoveMenu({ zone, onMove }) {
24
22
  const copy = composerCopy().panel;
23
+ const icons = useSkin().icons;
24
+ const MoreIcon = icons.more;
25
+ const [open, setOpen] = useState(false);
26
+ const box = useRef(null);
27
+ const menuId = useId();
28
+ useEffect(() => {
29
+ if (!open)
30
+ return;
31
+ box.current?.querySelector('[role="menuitemradio"]')?.focus();
32
+ const outside = (e) => {
33
+ if (!box.current?.contains(e.target))
34
+ setOpen(false);
35
+ };
36
+ window.addEventListener("pointerdown", outside, true);
37
+ return () => window.removeEventListener("pointerdown", outside, true);
38
+ }, [open]);
39
+ function onKeyDown(e) {
40
+ if (e.key === "Escape") {
41
+ e.preventDefault();
42
+ setOpen(false);
43
+ box.current?.querySelector("button")?.focus();
44
+ return;
45
+ }
46
+ const step = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
47
+ if (step === 0)
48
+ return;
49
+ e.preventDefault();
50
+ const items = [
51
+ ...(box.current?.querySelectorAll('[role="menuitemradio"]') ?? []),
52
+ ];
53
+ const at = items.indexOf(document.activeElement);
54
+ items[(at + step + items.length) % items.length]?.focus();
55
+ }
56
+ return (_jsxs("div", { ref: box, onPointerDown: (e) => e.stopPropagation(), onKeyDown: onKeyDown, children: [_jsx("button", { type: "button", className: "sc-control", "aria-label": copy.more, title: copy.more, "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": open ? menuId : undefined, onClick: () => setOpen((o) => !o), children: _jsx(MoreIcon, {}) }), open ? (_jsxs("div", { id: menuId, role: "menu", "aria-label": copy.moveTo, className: "sc-menu", children: [_jsx("div", { className: "sc-menu-label", children: copy.moveTo }), DESTINATIONS(copy, icons).map(({ zone: z, icon: Icon, label, hint }) => (_jsxs("button", { type: "button", role: "menuitemradio", "aria-checked": zone === z, className: "sc-menu-item", onClick: () => {
57
+ setOpen(false);
58
+ onMove(z);
59
+ }, children: [_jsx(Icon, {}), label, _jsx("span", { className: "sc-menu-hint", children: hint })] }, z)))] })) : null] }));
60
+ }
61
+ function Frame({ title, actions, zone, maximized, collapsed, rail = false, focused, dragId, onMaximize, onFocus, onMoveStart, children, }) {
62
+ const copy = composerCopy().panel;
63
+ const icons = useSkin().icons;
25
64
  const header = useRef(null);
26
65
  const floating = zone === Zone.Floating;
27
66
  const dragging = useDraggablePanel(header, dragId ?? "", dragId !== undefined && !floating);
28
- return (_jsxs("section", { role: "region", "aria-label": title, onPointerDownCapture: onFocus, className: `flex h-full min-h-0 min-w-0 flex-col overflow-hidden rounded-box border bg-surface transition-[border-color,box-shadow,opacity] duration-(--duration-instant) ${focused ? "border-primary/55 ring-1 ring-primary/25" : "border-line-strong"} ${floating ? "shadow-window" : ""} ${dragging ? "opacity-40" : ""}`, children: [_jsxs("header", { ref: header, onPointerDown: floating ? onMoveStart : undefined, style: floating ? { touchAction: "none" } : undefined, className: `flex shrink-0 items-center gap-0.5 border-b border-line bg-ground py-1 pr-1 pl-2.5 select-none ${floating ? "cursor-move" : "cursor-grab active:cursor-grabbing"}`, children: [_jsx("span", { className: "min-w-0 flex-1 truncate pr-1 text-micro font-medium text-ink", children: title }), _jsx("div", { onPointerDown: (e) => e.stopPropagation(), children: _jsx(Menu, { label: copy.more, icon: Ellipsis, iconOnly: true, chevron: false, align: "end", variant: "text", groups: [
29
- {
30
- label: copy.moveTo,
31
- options: DESTINATIONS(copy).map((d) => ({
32
- id: d.zone,
33
- label: d.label,
34
- hint: d.hint,
35
- icon: d.icon,
36
- checked: zone === d.zone,
37
- })),
38
- },
39
- {
40
- options: [{ id: MenuAction.Expand, label: copy.expand, icon: ArrowUpRight }],
41
- },
42
- ], onSelect: (id) => id === MenuAction.Expand ? actions.onExpand() : actions.onMove(id) }) }), _jsx(Control, { icon: Minus, label: collapsed ? copy.restore : copy.minimize, active: collapsed, onClick: actions.onCollapse }), _jsx(Control, { icon: maximized ? Copy : Square, label: maximized ? copy.restore : copy.enlarge, active: maximized, onClick: onMaximize }), _jsx(Control, { icon: X, label: copy.close, danger: true, onClick: actions.onClose })] }), _jsx("div", { hidden: collapsed, className: "@container min-h-0 flex-1 overflow-auto", children: children })] }));
67
+ const flag = (on) => (on ? "" : undefined);
68
+ return (_jsxs("section", { role: "region", "aria-label": title, onPointerDownCapture: onFocus, className: "sc-frame", "data-focused": flag(focused), "data-floating": flag(floating), "data-dragging": flag(dragging), children: [rail ? (_jsxs("header", { ref: header, className: "sc-header", "data-rail": "", children: [_jsx(Control, { icon: icons.minimize, label: copy.restore, active: true, onClick: actions.onCollapse }), _jsx("span", { className: "sc-title", children: title }), _jsx(Control, { icon: icons.close, label: copy.close, danger: true, onClick: actions.onClose })] })) : (_jsxs("header", { ref: header, className: "sc-header", "data-floating": flag(floating), onPointerDown: floating ? onMoveStart : undefined, children: [_jsx("span", { className: "sc-title", children: title }), _jsx(MoveMenu, { zone: zone, onMove: actions.onMove }), _jsx(Control, { icon: icons.expand, label: copy.expand, onClick: actions.onExpand }), _jsx(Control, { icon: icons.minimize, label: collapsed ? copy.restore : copy.minimize, active: collapsed, onClick: actions.onCollapse }), _jsx(Control, { icon: maximized ? icons.restore : icons.maximize, label: maximized ? copy.restore : copy.enlarge, active: maximized, onClick: onMaximize }), _jsx(Control, { icon: icons.close, label: copy.close, danger: true, onClick: actions.onClose })] })), _jsx("div", { hidden: collapsed, className: "sc-body", children: children })] }));
43
69
  }
44
70
  export const PanelFrame = memo(Frame);