@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,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Axis, BoxUnit, formatRef, HandleKind, handles, KEYBOARD_STEP, layout, PAGE, sizeAt, stableOrder, Surface, Zone, } from "../domain/index.js";
2
+ import { Axis, HandleKind, handles, KEYBOARD_STEP, layout, PAGE, sizeAt, stableOrder, Surface, Zone, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
4
  import { PanelFrame } from "./PanelFrame.js";
5
5
  import { ViewHost } from "./ViewHost.js";
@@ -10,10 +10,31 @@ const HANDLE_THICKNESS = 9;
10
10
  const MIN_WINDOW = { w: 280, h: 160 };
11
11
  /** How much of a window must stay inside the host, so it can always be grabbed back. */
12
12
  const KEEP_VISIBLE = 80;
13
+ /** A share of the host plus pixels, as CSS. `calc()` only when both are there. */
14
+ function css({ fr, px }, nudge = 0) {
15
+ const pixels = px + nudge;
16
+ if (pixels === 0)
17
+ return `${fr * 100}%`;
18
+ if (fr === 0)
19
+ return `${pixels}px`;
20
+ return `calc(${fr * 100}% + ${pixels}px)`;
21
+ }
13
22
  function boxStyle(box) {
14
- const u = (n) => (box.unit === BoxUnit.Fraction ? `${n * 100}%` : `${n}px`);
15
- return { left: u(box.left), top: u(box.top), width: u(box.width), height: u(box.height) };
23
+ return {
24
+ left: css(box.left),
25
+ top: css(box.top),
26
+ width: css(box.width),
27
+ height: css(box.height),
28
+ };
16
29
  }
30
+ const WHOLE = {
31
+ left: { fr: 0, px: 0 },
32
+ top: { fr: 0, px: 0 },
33
+ width: { fr: 1, px: 0 },
34
+ height: { fr: 1, px: 0 },
35
+ };
36
+ /** Padding of a docked slot. A strip keeps it only across: along, its 36 px are the header. */
37
+ const slotPadding = (slot) => slot.floating ? undefined : slot.rail ? "y" : slot.collapsed ? "x" : "all";
17
38
  /**
18
39
  * A drag that follows the pointer until it is released, wherever it goes. The listeners live on
19
40
  * `window`, so leaving the header — or the iframe — does not drop the gesture; pointer capture is
@@ -61,30 +82,28 @@ function ResizeHandle({ handle, value, onDrag, onStep, }) {
61
82
  }
62
83
  return (_jsx("div", { role: "separator", tabIndex: 0, "aria-orientation": horizontal ? "vertical" : "horizontal", "aria-label": handleLabel(handle, copy), "aria-valuenow": Math.round(value * 100), "aria-valuemin": 0, "aria-valuemax": 100, onPointerDown: (e) => onDrag(e, handle), onKeyDown: onKeyDown, style: horizontal
63
84
  ? {
64
- left: `calc(${handle.at * 100}% - ${HANDLE_THICKNESS / 2}px)`,
85
+ left: css(handle.at, -HANDLE_THICKNESS / 2),
65
86
  top: 0,
66
87
  width: HANDLE_THICKNESS,
67
88
  height: "100%",
68
- touchAction: "none",
69
89
  }
70
90
  : {
71
- top: `calc(${handle.at * 100}% - ${HANDLE_THICKNESS / 2}px)`,
91
+ top: css(handle.at, -HANDLE_THICKNESS / 2),
72
92
  left: 0,
73
93
  height: HANDLE_THICKNESS,
74
94
  width: "100%",
75
- touchAction: "none",
76
- }, className: `absolute z-10 transition-colors duration-(--duration-instant) hover:bg-primary/25 focus-visible:bg-primary/35 focus-visible:outline-none ${horizontal ? "cursor-col-resize" : "cursor-row-resize"}` }));
95
+ }, className: "sc-handle", "data-axis": handle.axis }));
77
96
  }
78
97
  /** The three grips of a window: right edge, bottom edge, and the corner. */
79
98
  const GRIPS = [
80
- { id: "e", className: "top-0 right-0 h-full w-2 cursor-e-resize", dx: 1, dy: 0 },
81
- { id: "s", className: "bottom-0 left-0 h-2 w-full cursor-s-resize", dx: 0, dy: 1 },
82
- { id: "se", className: "right-0 bottom-0 size-4 cursor-se-resize", dx: 1, dy: 1 },
99
+ { id: "e", dx: 1, dy: 0 },
100
+ { id: "s", dx: 0, dy: 1 },
101
+ { id: "se", dx: 1, dy: 1 },
83
102
  ];
84
103
  function ZoneDropTarget({ zone, style, label, armed, }) {
85
104
  const box = useRef(null);
86
105
  const over = useDropZone(box, zone);
87
- return (_jsx("div", { ref: box, "aria-hidden": true, style: style, className: `absolute z-30 flex items-center justify-center rounded-box border-2 border-dashed transition-colors duration-(--duration-instant) ${armed ? "pointer-events-auto" : "pointer-events-none"} ${over ? "border-primary bg-primary/12" : "border-transparent"}`, children: over ? _jsx("span", { className: "text-micro font-medium text-primary", children: label }) : null }));
106
+ return (_jsx("div", { ref: box, "aria-hidden": true, style: style, className: "sc-drop", "data-armed": armed ? "" : undefined, "data-over": over ? "" : undefined, children: over ? label : null }));
88
107
  }
89
108
  /** Targets cover the container edges, not the live zone boxes — dropping «to the left» has to
90
109
  * work even when that zone has no panel yet. */
@@ -127,9 +146,9 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
127
146
  store.resizePanel(handle.panelId, value);
128
147
  };
129
148
  function moveWindow(e, slot) {
130
- if (slot.box.unit !== BoxUnit.Pixel)
149
+ if (!slot.floating)
131
150
  return;
132
- const { left, top, width } = slot.box;
151
+ const [left, top, width] = [slot.box.left.px, slot.box.top.px, slot.box.width.px];
133
152
  const start = { x: e.clientX, y: e.clientY };
134
153
  store.raisePanel(slot.id);
135
154
  drag(e, (host, ev) => {
@@ -140,9 +159,9 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
140
159
  });
141
160
  }
142
161
  function resizeWindow(e, slot, dx, dy) {
143
- if (slot.box.unit !== BoxUnit.Pixel)
162
+ if (!slot.floating)
144
163
  return;
145
- const { width, height } = slot.box;
164
+ const [width, height] = [slot.box.width.px, slot.box.height.px];
146
165
  const start = { x: e.clientX, y: e.clientY };
147
166
  e.stopPropagation();
148
167
  drag(e, (_host, ev) => {
@@ -154,35 +173,29 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
154
173
  }
155
174
  function moveHandle(e, handle) {
156
175
  drag(e, (host, ev) => {
157
- const p = handle.axis === Axis.X
158
- ? (ev.clientX - host.left) / host.width
159
- : (ev.clientY - host.top) / host.height;
160
- applyHandle(handle, sizeAt(handle, p));
176
+ const [p, size] = handle.axis === Axis.X
177
+ ? [ev.clientX - host.left, host.width]
178
+ : [ev.clientY - host.top, host.height];
179
+ applyHandle(handle, sizeAt(handle, p, size));
161
180
  });
162
181
  }
163
- return (_jsxs("div", { ref: hostRef, className: "relative min-h-0 flex-1 overflow-hidden", children: [stableOrder(slots).map((slot) => {
182
+ return (_jsxs("div", { ref: hostRef, className: "sc-host", children: [stableOrder(slots).map((slot) => {
164
183
  const isPage = slot.id === PAGE;
165
184
  const style = {
166
185
  ...boxStyle(slot.box),
167
186
  ...(slot.floating ? { zIndex: 20 + slot.z } : {}),
168
187
  };
169
188
  if (isPage) {
170
- return (_jsx("div", { hidden: !slot.visible, style: style, onPointerDownCapture: () => store.focusPanel(PAGE), className: "absolute isolate min-h-0 overflow-auto", children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Page }) }) }, slot.id));
189
+ return (_jsx("div", { hidden: !slot.visible, style: style, onPointerDownCapture: () => store.focusPanel(PAGE), className: "sc-slot", "data-page": "", children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Page }) }) }, slot.id));
171
190
  }
172
191
  const zone = slot.panel?.placement.zone ?? Zone.Right;
173
- return (_jsxs("div", { hidden: !slot.visible, style: style, className: `absolute isolate ${slot.floating ? "" : "p-1"}`, children: [_jsx(PanelFrame, { title: registry.resolve(slot.view)?.title(slot.view) ?? formatRef(slot.view), zone: zone, collapsed: slot.collapsed, focused: workspace.focus === slot.id, maximized: workspace.maximized === slot.id, ...(slot.floating ? {} : { dragId: slot.id }), onMaximize: () => store.maximize(slot.id), onFocus: () => store.focusPanel(slot.id), onMoveStart: (e) => moveWindow(e, slot), actions: {
192
+ return (_jsxs("div", { hidden: !slot.visible, style: style, className: "sc-slot", "data-pad": slotPadding(slot), children: [_jsx(PanelFrame, { title: api.titleOf(slot.view), zone: zone, collapsed: slot.collapsed, rail: slot.rail, focused: workspace.focus === slot.id, maximized: workspace.maximized === slot.id, ...(slot.floating ? {} : { dragId: slot.id }), onMaximize: () => store.maximize(slot.id), onFocus: () => store.focusPanel(slot.id), onMoveStart: (e) => moveWindow(e, slot), actions: {
174
193
  onMove: (z) => store.movePanel(slot.id, z),
175
194
  onCollapse: () => store.collapsePanel(slot.id),
176
195
  onExpand: () => store.expandPanel(slot.id),
177
196
  onClose: () => store.closePanel(slot.id),
178
197
  }, children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Panel, panelId: slot.id }) }) }), slot.floating && !slot.collapsed
179
- ? GRIPS.map((grip) => (_jsx("div", { "aria-hidden": true, style: { touchAction: "none" }, onPointerDown: (e) => resizeWindow(e, slot, grip.dx, grip.dy), className: `absolute z-10 ${grip.className}` }, grip.id)))
198
+ ? GRIPS.map((grip) => (_jsx("div", { "aria-hidden": true, onPointerDown: (e) => resizeWindow(e, slot, grip.dx, grip.dy), className: "sc-grip", "data-grip": grip.id }, grip.id)))
180
199
  : null] }, slot.id));
181
- }), overlay === undefined || overlay === null ? null : (_jsx("div", { style: boxStyle(slots.find((slot) => slot.id === PAGE && slot.visible)?.box ?? {
182
- unit: BoxUnit.Fraction,
183
- left: 0,
184
- top: 0,
185
- width: 1,
186
- height: 1,
187
- }), className: "pointer-events-none absolute z-40 [&>*]:pointer-events-auto", children: overlay })), _jsx("div", { className: "pointer-events-none absolute inset-0", children: DROP_ZONES.map((b) => (_jsx(ZoneDropTarget, { zone: b.zone, label: copy[b.label], style: b.style, armed: dropArmed }, b.zone))) }), resizeHandles.map((handle) => (_jsx(ResizeHandle, { handle: handle, value: valueOf(handle), onDrag: moveHandle, onStep: (h, delta) => applyHandle(h, valueOf(h) + delta) }, handle.kind === HandleKind.Zone ? `z:${handle.zone}` : `p:${handle.panelId}`)))] }));
200
+ }), overlay === undefined || overlay === null ? null : (_jsx("div", { style: boxStyle(slots.find((slot) => slot.id === PAGE && slot.visible)?.box ?? WHOLE), className: "sc-overlay", children: overlay })), _jsx("div", { className: "sc-drops", children: DROP_ZONES.map((b) => (_jsx(ZoneDropTarget, { zone: b.zone, label: copy[b.label], style: b.style, armed: dropArmed }, b.zone))) }), resizeHandles.map((handle) => (_jsx(ResizeHandle, { handle: handle, value: valueOf(handle), onDrag: moveHandle, onStep: (h, delta) => applyHandle(h, valueOf(h) + delta) }, handle.kind === HandleKind.Zone ? `z:${handle.zone}` : `p:${handle.panelId}`)))] }));
188
201
  }
@@ -0,0 +1,26 @@
1
+ import type { IconProps } from "./icons.js";
2
+ import { type ConfirmProps, type PeekProps } from "./skin.js";
3
+ import { type ComponentType, type ReactNode } from "react";
4
+ /**
5
+ * The drawer a peek is read in. It does NOT dim or block what is behind it — that is what makes
6
+ * it a peek and not a dialog: the list it came from keeps answering. So it is a landmark
7
+ * (`<aside>`), not a modal:
8
+ *
9
+ * - on open it takes the focus, so a keyboard user does not have to tab through the list;
10
+ * - on close the focus goes back to whatever opened it;
11
+ * - Escape closes it while the focus is inside, and CLAIMS the key (`preventDefault`), so
12
+ * whatever listens further up does not act on it too.
13
+ */
14
+ export declare function ChromeButton({ role, icon: Icon, onClick, children, }: {
15
+ role?: "secondary" | "ghost" | "danger";
16
+ icon?: ComponentType<IconProps>;
17
+ onClick: () => void;
18
+ children: ReactNode;
19
+ }): import("react").JSX.Element;
20
+ export declare function PeekDrawer({ title, onClose, actions, children }: PeekProps): import("react").JSX.Element;
21
+ /**
22
+ * The one question the composer asks: discard what was typed? A native modal `<dialog>` —
23
+ * the browser gives it the top layer, the backdrop, the focus trap and the focus on the first
24
+ * button, which is the safe answer.
25
+ */
26
+ export declare function ConfirmDialog({ open, title, detail, keep, discard, onAnswer, }: ConfirmProps): import("react").JSX.Element;
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { composerCopy } from "./copy.js";
3
+ import { useSkin } from "./skin.js";
4
+ import { useEffect, useId, useRef } from "react";
5
+ /**
6
+ * The drawer a peek is read in. It does NOT dim or block what is behind it — that is what makes
7
+ * it a peek and not a dialog: the list it came from keeps answering. So it is a landmark
8
+ * (`<aside>`), not a modal:
9
+ *
10
+ * - on open it takes the focus, so a keyboard user does not have to tab through the list;
11
+ * - on close the focus goes back to whatever opened it;
12
+ * - Escape closes it while the focus is inside, and CLAIMS the key (`preventDefault`), so
13
+ * whatever listens further up does not act on it too.
14
+ */
15
+ export function ChromeButton({ role = "secondary", icon: Icon, onClick, children, }) {
16
+ return (_jsxs("button", { type: "button", className: "sc-button", "data-role": role, onClick: onClick, children: [Icon === undefined ? null : _jsx(Icon, {}), children] }));
17
+ }
18
+ export function PeekDrawer({ title, onClose, actions, children }) {
19
+ const copy = composerCopy().peek;
20
+ const { close: CloseIcon } = useSkin().icons;
21
+ const box = useRef(null);
22
+ const titleId = useId();
23
+ useEffect(() => {
24
+ const opener = document.activeElement;
25
+ box.current?.focus();
26
+ return () => {
27
+ if (opener instanceof HTMLElement && opener.isConnected)
28
+ opener.focus();
29
+ };
30
+ }, []);
31
+ return (_jsxs("aside", { ref: box, tabIndex: -1, "aria-labelledby": titleId, className: "sc-peek", onKeyDown: (e) => {
32
+ if (e.key !== "Escape" || e.defaultPrevented)
33
+ return;
34
+ e.preventDefault();
35
+ onClose();
36
+ }, children: [_jsxs("header", { className: "sc-peek-head", children: [_jsx("h2", { id: titleId, className: "sc-peek-title", children: title }), _jsx("button", { type: "button", className: "sc-control", "aria-label": copy.close, title: copy.close, onClick: onClose, children: _jsx(CloseIcon, {}) })] }), actions === undefined ? null : _jsx("div", { className: "sc-peek-actions", children: actions }), _jsx("div", { className: "sc-peek-body", children: children })] }));
37
+ }
38
+ /**
39
+ * The one question the composer asks: discard what was typed? A native modal `<dialog>` —
40
+ * the browser gives it the top layer, the backdrop, the focus trap and the focus on the first
41
+ * button, which is the safe answer.
42
+ */
43
+ export function ConfirmDialog({ open, title, detail, keep, discard, onAnswer, }) {
44
+ const dialog = useRef(null);
45
+ const titleId = useId();
46
+ useEffect(() => {
47
+ const d = dialog.current;
48
+ if (d === null)
49
+ return;
50
+ if (open && !d.open)
51
+ d.showModal();
52
+ if (!open && d.open)
53
+ d.close();
54
+ }, [open]);
55
+ return (_jsxs("dialog", { ref: dialog, className: "sc-dialog", "aria-labelledby": titleId, onCancel: (e) => {
56
+ e.preventDefault();
57
+ onAnswer(false);
58
+ }, onKeyDown: (e) => {
59
+ if (e.key !== "Escape")
60
+ return;
61
+ e.preventDefault();
62
+ onAnswer(false);
63
+ }, children: [_jsx("h2", { id: titleId, className: "sc-dialog-title", children: title }), _jsx("p", { className: "sc-dialog-body", children: detail }), _jsxs("div", { className: "sc-dialog-foot", children: [_jsx(ChromeButton, { onClick: () => onAnswer(false), children: keep }), _jsx(ChromeButton, { role: "danger", onClick: () => onAnswer(true), children: discard })] })] }));
64
+ }
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Destination, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
+ import { useSkin } from "./skin.js";
4
5
  import { useDraggableRef } from "../state/drag.js";
5
- import { AppWindow, Eye, PanelRight } from "lucide-react";
6
6
  import { useRef } from "react";
7
7
  /**
8
8
  * The name of a record, wherever it appears — a row, a chip of a many2one, a search result. It
@@ -18,12 +18,13 @@ import { useRef } from "react";
18
18
  * The icons appear on hover and on focus, never taking room from the name.
19
19
  */
20
20
  const ICONS = [
21
- { to: Destination.Peek, icon: Eye, label: "peek" },
22
- { to: Destination.Side, icon: PanelRight, label: "side" },
23
- { to: Destination.Window, icon: AppWindow, label: "window" },
21
+ { to: Destination.Peek, icon: "peek", label: "peek" },
22
+ { to: Destination.Side, icon: "right", label: "side" },
23
+ { to: Destination.Window, icon: "window", label: "window" },
24
24
  ];
25
25
  export function RecordLink({ api, resource, to, compact = false, children, }) {
26
26
  const copy = composerCopy().link;
27
+ const icons = useSkin().icons;
27
28
  const box = useRef(null);
28
29
  const dragging = useDraggableRef(box, resource);
29
30
  /* The name sits inside a row that has its own click (open, peek). Whatever this control
@@ -44,8 +45,11 @@ export function RecordLink({ api, resource, to, compact = false, children, }) {
44
45
  e.preventDefault();
45
46
  e.stopPropagation();
46
47
  }
47
- return (_jsxs("span", { ref: box, className: `group/link inline-flex min-w-0 items-center gap-1 ${dragging ? "opacity-40" : ""}`, children: [_jsx("button", { type: "button", onClick: onClick, onKeyDown: onKeyDown, className: "min-w-0 cursor-pointer truncate rounded-mark text-left text-primary hover:underline hover:underline-offset-4 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary", children: children }), compact ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center opacity-0 transition-opacity duration-(--duration-instant) group-focus-within/link:opacity-100 group-hover/link:opacity-100", children: ICONS.map(({ to: destination, icon: Icon, label }) => (_jsx("button", { type: "button", "aria-label": copy[label], title: copy[label], onClick: (e) => {
48
- e.stopPropagation();
49
- api.open(resource, { to: destination });
50
- }, className: "inline-flex size-6 cursor-pointer items-center justify-center rounded-control text-muted hover:bg-ink/8 hover:text-ink focus-visible:outline-2 focus-visible:outline-primary", children: _jsx(Icon, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }) }, destination))) }))] }));
48
+ return (_jsxs("span", { ref: box, className: "sc-link", "data-dragging": dragging ? "" : undefined, children: [_jsx("button", { type: "button", onClick: onClick, onKeyDown: onKeyDown, className: "sc-link-name", children: children }), compact ? null : (_jsx("span", { className: "sc-link-icons", children: ICONS.map(({ to: destination, icon, label }) => {
49
+ const Icon = icons[icon];
50
+ return (_jsx("button", { type: "button", "aria-label": copy[label], title: copy[label], onClick: (e) => {
51
+ e.stopPropagation();
52
+ api.open(resource, { to: destination });
53
+ }, className: "sc-control", children: _jsx(Icon, {}) }, destination));
54
+ }) }))] }));
51
55
  }
@@ -1,7 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { formatRef, loadView, } from "../domain/index.js";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { formatRef, loadView, rootRef, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
- import { ICONO_ROTO, Missing } from "@sincpro/web-ui";
4
+ import { useSkin } from "./skin.js";
5
5
  import { Component, lazy, memo, Suspense, useMemo, } from "react";
6
6
  /**
7
7
  * The only thing that turns a reference into pixels. Resolves against the
@@ -10,7 +10,16 @@ import { Component, lazy, memo, Suspense, useMemo, } from "react";
10
10
  *
11
11
  * Three distinct states because each one is someone else's job: unregistered
12
12
  * is wiring, loading is normal, broken is a domain bug.
13
+ *
14
+ * The view is keyed by the resource WITHOUT its params: another record is another view, but
15
+ * another face of the same one — a filter, a tab, `api.setParams` — is the same view receiving
16
+ * a new `resource`. Remounting there threw away the search typed, the scroll and the selection.
13
17
  */
18
+ /** What stands where a view could not be drawn. Plain text: it must work even when nothing
19
+ * else does. */
20
+ function DefaultNotice({ heading, detail, bad = false }) {
21
+ return (_jsxs("div", { role: "status", className: "sc-notice", ...(bad ? { "data-tone": "bad" } : {}), children: [_jsx("strong", { children: heading }), _jsx("code", { children: detail })] }));
22
+ }
14
23
  class ErrorBoundary extends Component {
15
24
  state = { error: null };
16
25
  static getDerivedStateFromError(error) {
@@ -27,16 +36,18 @@ class ErrorBoundary extends Component {
27
36
  render() {
28
37
  if (this.state.error === null)
29
38
  return this.props.children;
30
- return (_jsx(Missing, { icon: ICONO_ROTO, tone: "bad", heading: composerCopy().view.failed, detail: `${this.props.name} — ${this.state.error.message}` }));
39
+ const { Notice } = this.props;
40
+ return (_jsx(Notice, { bad: true, heading: composerCopy().view.failed, detail: `${this.props.name} — ${this.state.error.message}` }));
31
41
  }
32
42
  }
33
43
  function Host({ resource, registry, api, fallback }) {
34
44
  const key = formatRef(resource);
35
45
  const spec = registry.resolve(resource);
46
+ const Notice = useSkin().Notice ?? DefaultNotice;
36
47
  const View = useMemo(() => (spec === null ? null : lazy(async () => ({ default: await loadView(spec) }))), [spec]);
37
48
  if (spec === null || View === null) {
38
- return (_jsx(Missing, { heading: composerCopy().view.unresolved, detail: `${key} — is the «${resource.domain}» domain missing from the registry?` }));
49
+ return (_jsx(Notice, { heading: composerCopy().view.unresolved, detail: `${key} — is the «${resource.domain}» domain missing from the registry?` }));
39
50
  }
40
- return (_jsx(ErrorBoundary, { name: key, children: _jsx(Suspense, { fallback: fallback ?? (_jsx("p", { className: "p-4 text-micro text-muted", children: composerCopy().view.loading(spec.domain) })), children: _jsx(View, { resource: resource, api: api }, key) }) }));
51
+ return (_jsx(ErrorBoundary, { name: key, Notice: Notice, children: _jsx(Suspense, { fallback: fallback ?? _jsx("p", { className: "sc-loading", children: composerCopy().view.loading(spec.domain) }), children: _jsx(View, { resource: resource, api: api }, formatRef(rootRef(resource))) }) }));
41
52
  }
42
53
  export const ViewHost = memo(Host);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Every word the composer draws, in one table — the way `@sincpro/web-ui` does it. English by
2
+ * Every word the composer draws, in one table. English by
3
3
  * default; an application installs its language ONCE with `installComposerCopy`, next to the
4
4
  * design system's `installCopy`, and no component carries a hard-coded string.
5
5
  */
@@ -28,6 +28,15 @@ export type ComposerCopy = {
28
28
  };
29
29
  peek: {
30
30
  openAsPage: string;
31
+ openAsPanel: string;
32
+ close: string;
33
+ back: (to: string) => string;
34
+ };
35
+ discard: {
36
+ title: string;
37
+ detail: (names: readonly string[]) => string;
38
+ keep: string;
39
+ discard: string;
31
40
  };
32
41
  link: {
33
42
  peek: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Every word the composer draws, in one table — the way `@sincpro/web-ui` does it. English by
2
+ * Every word the composer draws, in one table. English by
3
3
  * default; an application installs its language ONCE with `installComposerCopy`, next to the
4
4
  * design system's `installCopy`, and no component carries a hard-coded string.
5
5
  */
@@ -26,7 +26,18 @@ export const ENGLISH_COMPOSER_COPY = {
26
26
  dropRight: "to the right",
27
27
  dropBottom: "to the bottom",
28
28
  },
29
- peek: { openAsPage: "Open as page" },
29
+ peek: {
30
+ openAsPage: "Open as page",
31
+ openAsPanel: "Open as panel",
32
+ close: "Close the preview",
33
+ back: (to) => `Back to ${to}`,
34
+ },
35
+ discard: {
36
+ title: "Discard the changes?",
37
+ detail: (names) => `What was typed in ${names.join(", ")} has not been saved.`,
38
+ keep: "Keep editing",
39
+ discard: "Discard",
40
+ },
30
41
  link: { peek: "Peek", side: "Open beside", window: "Open in a window" },
31
42
  view: {
32
43
  failed: "This view failed to render",
@@ -43,10 +54,10 @@ export const ENGLISH_COMPOSER_COPY = {
43
54
  },
44
55
  shortcuts: [
45
56
  { keys: "⌘K", action: "go to, search, or act on what you are on" },
46
- { keys: "⌥←", action: "one page back" },
57
+ { keys: "⌥←", action: "one page back, or one step back in the peek" },
47
58
  { keys: "⌘⌥[ / ⌘⌥]", action: "move focus between the page and the panels" },
48
59
  { keys: "⌘⇧⏎", action: "maximize the focused surface, or restore it" },
49
- { keys: "⌘⇧⌫", action: "close the focused panel" },
60
+ { keys: "⌘⇧⌫", action: "close the focused panel or the peek" },
50
61
  { keys: "Esc", action: "close the peek, or restore the maximized view" },
51
62
  { keys: "← → on a handle", action: "resize without the mouse" },
52
63
  ],
@@ -74,7 +85,18 @@ export const SPANISH_COMPOSER_COPY = {
74
85
  dropRight: "a la derecha",
75
86
  dropBottom: "abajo",
76
87
  },
77
- peek: { openAsPage: "Abrir como página" },
88
+ peek: {
89
+ openAsPage: "Abrir como página",
90
+ openAsPanel: "Abrir como panel",
91
+ close: "Cerrar la vista previa",
92
+ back: (to) => `Volver a ${to}`,
93
+ },
94
+ discard: {
95
+ title: "¿Descartar los cambios?",
96
+ detail: (names) => `Lo escrito en ${names.join(", ")} no se guardó.`,
97
+ keep: "Seguir editando",
98
+ discard: "Descartar",
99
+ },
78
100
  link: { peek: "Vistazo", side: "Abrir al lado", window: "Abrir en una ventana" },
79
101
  view: {
80
102
  failed: "Esta vista no se pudo dibujar",
@@ -91,10 +113,10 @@ export const SPANISH_COMPOSER_COPY = {
91
113
  },
92
114
  shortcuts: [
93
115
  { keys: "⌘K", action: "ir a, buscar o actuar sobre lo que miras" },
94
- { keys: "⌥←", action: "una página atrás" },
116
+ { keys: "⌥←", action: "una página atrás, o un paso atrás en el vistazo" },
95
117
  { keys: "⌘⌥[ / ⌘⌥]", action: "mover el foco entre la página y los paneles" },
96
118
  { keys: "⌘⇧⏎", action: "maximizar la superficie con foco, o restaurarla" },
97
- { keys: "⌘⇧⌫", action: "cerrar el panel con foco" },
119
+ { keys: "⌘⇧⌫", action: "cerrar el panel con foco o el vistazo" },
98
120
  { keys: "Esc", action: "cerrar el vistazo, o restaurar la vista maximizada" },
99
121
  { keys: "← → en un divisor", action: "redimensionar sin el mouse" },
100
122
  ],
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The few glyphs the frames need, drawn here so the composer depends on no icon library. Same
3
+ * shape as any icon component (`className`, `strokeWidth`), so an application can pass its own
4
+ * wherever the composer takes an icon.
5
+ */
6
+ export type IconProps = {
7
+ className?: string;
8
+ strokeWidth?: number;
9
+ };
10
+ export declare const MoreIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
11
+ export declare const ExpandIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
12
+ export declare const MinimizeIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
13
+ export declare const MaximizeIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
14
+ export declare const RestoreIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
15
+ export declare const CloseIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
16
+ export declare const LeftIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
17
+ export declare const RightIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
18
+ export declare const BottomIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
19
+ export declare const WindowIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
20
+ export declare const BackIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
21
+ export declare const SearchIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
22
+ export declare const PeekIcon: ({ className, strokeWidth }: IconProps) => import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ function glyph(paths) {
3
+ return function Icon({ className, strokeWidth = 2 }) {
4
+ return (_jsx("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: strokeWidth, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, ...(className === undefined ? {} : { className }), children: paths }));
5
+ };
6
+ }
7
+ export const MoreIcon = glyph(_jsxs(_Fragment, { children: [_jsx("circle", { cx: "5", cy: "12", r: "1" }), _jsx("circle", { cx: "12", cy: "12", r: "1" }), _jsx("circle", { cx: "19", cy: "12", r: "1" })] }));
8
+ export const ExpandIcon = glyph(_jsx("path", { d: "M7 17 17 7M8 7h9v9" }));
9
+ export const MinimizeIcon = glyph(_jsx("path", { d: "M5 12h14" }));
10
+ export const MaximizeIcon = glyph(_jsx("rect", { x: "5", y: "5", width: "14", height: "14", rx: "2" }));
11
+ export const RestoreIcon = glyph(_jsxs(_Fragment, { children: [_jsx("rect", { x: "8", y: "8", width: "12", height: "12", rx: "2" }), _jsx("path", { d: "M4 16V6a2 2 0 0 1 2-2h10" })] }));
12
+ export const CloseIcon = glyph(_jsx("path", { d: "M18 6 6 18M6 6l12 12" }));
13
+ export const LeftIcon = glyph(_jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }), _jsx("path", { d: "M9 3v18" })] }));
14
+ export const RightIcon = glyph(_jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }), _jsx("path", { d: "M15 3v18" })] }));
15
+ export const BottomIcon = glyph(_jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }), _jsx("path", { d: "M3 15h18" })] }));
16
+ export const WindowIcon = glyph(_jsxs(_Fragment, { children: [_jsx("rect", { x: "3", y: "5", width: "18", height: "14", rx: "2" }), _jsx("rect", { x: "12", y: "11", width: "6", height: "5", rx: "1" })] }));
17
+ export const BackIcon = glyph(_jsx("path", { d: "M19 12H5M12 19l-7-7 7-7" }));
18
+ export const SearchIcon = glyph(_jsxs(_Fragment, { children: [_jsx("circle", { cx: "11", cy: "11", r: "7" }), _jsx("path", { d: "m20 20-3.5-3.5" })] }));
19
+ export const PeekIcon = glyph(_jsxs(_Fragment, { children: [_jsx("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }), _jsx("circle", { cx: "12", cy: "12", r: "3" })] }));
@@ -0,0 +1,72 @@
1
+ import { type IconProps } from "./icons.js";
2
+ import type { ComponentType, ReactNode } from "react";
3
+ /**
4
+ * What the composer draws, open to be replaced. The composer owns the BEHAVIOUR — where a thing
5
+ * opens, how it moves, what is remembered — and ships a minimal look so it works out of the box.
6
+ * The look is the application's: every piece here can be swapped, one at a time, and what is
7
+ * not passed keeps the default.
8
+ *
9
+ * <Composer skin={{ icons: { close: X, more: Ellipsis }, Peek: MyDrawer }} … />
10
+ *
11
+ * Three levels, from least to most work: the `--sc-*` variables (colors, radius), these pieces,
12
+ * and `styles: false` to drop the default sheet and style the `sc-*` classes from scratch.
13
+ */
14
+ export type Icon = ComponentType<IconProps>;
15
+ export type SkinIcons = {
16
+ more: Icon;
17
+ expand: Icon;
18
+ minimize: Icon;
19
+ maximize: Icon;
20
+ restore: Icon;
21
+ close: Icon;
22
+ left: Icon;
23
+ right: Icon;
24
+ bottom: Icon;
25
+ window: Icon;
26
+ back: Icon;
27
+ search: Icon;
28
+ peek: Icon;
29
+ };
30
+ /** The drawer a peek is read in. It must not block what is behind it, take the focus on open,
31
+ * and close on Escape while the focus is inside — claiming the key with `preventDefault`. */
32
+ export type PeekProps = {
33
+ title: string;
34
+ onClose: () => void;
35
+ /** «Open as panel», «Back to …», «Open as page»: already wired, only to be placed. */
36
+ actions?: ReactNode;
37
+ children: ReactNode;
38
+ };
39
+ /** The question before throwing away what was typed. `onAnswer(false)` is the safe answer and
40
+ * what Escape gives. */
41
+ export type ConfirmProps = {
42
+ open: boolean;
43
+ title: string;
44
+ detail: string;
45
+ keep: string;
46
+ discard: string;
47
+ onAnswer: (ok: boolean) => void;
48
+ };
49
+ /** What stands where a view could not be drawn: a reference nobody resolves, or a view that
50
+ * threw. */
51
+ export type NoticeProps = {
52
+ heading: string;
53
+ detail: string;
54
+ bad?: boolean;
55
+ };
56
+ export type Skin = {
57
+ icons: SkinIcons;
58
+ Peek: ComponentType<PeekProps> | null;
59
+ Confirm: ComponentType<ConfirmProps> | null;
60
+ Notice: ComponentType<NoticeProps> | null;
61
+ /** `false` drops the default sheet: the `sc-*` classes are then yours to style. */
62
+ styles: boolean;
63
+ };
64
+ /** What `<Composer skin>` takes: any part, the rest stays default. */
65
+ export type ComposerSkin = Partial<Omit<Skin, "icons">> & {
66
+ icons?: Partial<SkinIcons>;
67
+ };
68
+ export declare const DEFAULT_ICONS: SkinIcons;
69
+ export declare function resolveSkin(skin: ComposerSkin | undefined): Skin;
70
+ export declare const SkinProvider: import("react").Provider<Skin>;
71
+ /** The skin in use. Outside a `<Composer>` — a `RecordLink` in a test — the default. */
72
+ export declare const useSkin: () => Skin;
@@ -0,0 +1,35 @@
1
+ import { BackIcon, BottomIcon, CloseIcon, ExpandIcon, LeftIcon, MaximizeIcon, MinimizeIcon, MoreIcon, PeekIcon, RestoreIcon, RightIcon, SearchIcon, WindowIcon, } from "./icons.js";
2
+ import { createContext, useContext } from "react";
3
+ export const DEFAULT_ICONS = {
4
+ more: MoreIcon,
5
+ expand: ExpandIcon,
6
+ minimize: MinimizeIcon,
7
+ maximize: MaximizeIcon,
8
+ restore: RestoreIcon,
9
+ close: CloseIcon,
10
+ left: LeftIcon,
11
+ right: RightIcon,
12
+ bottom: BottomIcon,
13
+ window: WindowIcon,
14
+ back: BackIcon,
15
+ search: SearchIcon,
16
+ peek: PeekIcon,
17
+ };
18
+ /** `null` components mean «the composer's own»; they are resolved where they are drawn, so this
19
+ * file does not import the shell. */
20
+ const DEFAULT_SKIN = {
21
+ icons: DEFAULT_ICONS,
22
+ Peek: null,
23
+ Confirm: null,
24
+ Notice: null,
25
+ styles: true,
26
+ };
27
+ export function resolveSkin(skin) {
28
+ if (skin === undefined)
29
+ return DEFAULT_SKIN;
30
+ return { ...DEFAULT_SKIN, ...skin, icons: { ...DEFAULT_ICONS, ...skin.icons } };
31
+ }
32
+ const SkinContext = createContext(DEFAULT_SKIN);
33
+ export const SkinProvider = SkinContext.Provider;
34
+ /** The skin in use. Outside a `<Composer>` — a `RecordLink` in a test — the default. */
35
+ export const useSkin = () => useContext(SkinContext);
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The composer's own skin: the frames, the drawer, the rail, the dialog and ⌘K, with no design
3
+ * system behind it. It is the minimum that makes the windows usable — the views inside them are
4
+ * the application's, drawn with whatever it uses.
5
+ *
6
+ * Every color, radius and shadow is a CSS variable with a default, so an application themes it
7
+ * from anywhere above the workspace (`:root` included) without a stylesheet of its own:
8
+ *
9
+ * :root {
10
+ * --sc-surface: var(--my-surface);
11
+ * --sc-accent: var(--my-brand);
12
+ * }
13
+ *
14
+ * The classes (`sc-*`) are stable: they are how a skin is overridden. The sheet is a React 19
15
+ * `<style href precedence>`: hoisted to <head> and drawn once however many workspaces there are,
16
+ * so nothing has to be imported.
17
+ */
18
+ /** Drawn by `<Composer>`. Exported for an application that draws the parts on their own. */
19
+ export declare function ComposerStyles(): import("react").JSX.Element;