@sincpro/web-composer 0.0.0-stage → 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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +269 -2
  3. package/dist/domain/enums.d.ts +55 -0
  4. package/dist/domain/enums.js +48 -0
  5. package/dist/domain/index.d.ts +9 -0
  6. package/dist/domain/index.js +8 -0
  7. package/dist/domain/layout.d.ts +92 -0
  8. package/dist/domain/layout.js +216 -0
  9. package/dist/domain/palette.d.ts +42 -0
  10. package/dist/domain/palette.js +89 -0
  11. package/dist/domain/registry.d.ts +135 -0
  12. package/dist/domain/registry.js +37 -0
  13. package/dist/domain/resource.d.ts +21 -0
  14. package/dist/domain/resource.js +62 -0
  15. package/dist/domain/url.d.ts +16 -0
  16. package/dist/domain/url.js +145 -0
  17. package/dist/domain/workspace.d.ts +174 -0
  18. package/dist/domain/workspace.js +393 -0
  19. package/dist/index.d.ts +24 -0
  20. package/dist/index.js +23 -0
  21. package/dist/shell/Composer.d.ts +23 -0
  22. package/dist/shell/Composer.js +88 -0
  23. package/dist/shell/Palette.d.ts +9 -0
  24. package/dist/shell/Palette.js +124 -0
  25. package/dist/shell/PanelFrame.d.ts +38 -0
  26. package/dist/shell/PanelFrame.js +70 -0
  27. package/dist/shell/PanelHost.d.ts +23 -0
  28. package/dist/shell/PanelHost.js +201 -0
  29. package/dist/shell/Peek.d.ts +26 -0
  30. package/dist/shell/Peek.js +64 -0
  31. package/dist/shell/RecordLink.d.ts +12 -0
  32. package/dist/shell/RecordLink.js +55 -0
  33. package/dist/shell/ViewHost.d.ts +11 -0
  34. package/dist/shell/ViewHost.js +53 -0
  35. package/dist/shell/copy.d.ts +73 -0
  36. package/dist/shell/copy.js +130 -0
  37. package/dist/shell/icons.d.ts +22 -0
  38. package/dist/shell/icons.js +19 -0
  39. package/dist/shell/skin.d.ts +72 -0
  40. package/dist/shell/skin.js +35 -0
  41. package/dist/shell/styles.d.ts +19 -0
  42. package/dist/shell/styles.js +212 -0
  43. package/dist/state/api.d.ts +36 -0
  44. package/dist/state/api.js +170 -0
  45. package/dist/state/drag.d.ts +31 -0
  46. package/dist/state/drag.js +95 -0
  47. package/dist/state/store.d.ts +69 -0
  48. package/dist/state/store.js +200 -0
  49. package/dist/state/useKeyboard.d.ts +16 -0
  50. package/dist/state/useKeyboard.js +63 -0
  51. package/dist/state/useWorkspace.d.ts +23 -0
  52. package/dist/state/useWorkspace.js +34 -0
  53. package/package.json +83 -4
@@ -0,0 +1,124 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Destination, localEntries, matches, MIN_QUERY, PaletteSection, searchEntries, } from "../domain/index.js";
3
+ import { composerCopy } from "./copy.js";
4
+ import { useSkin } from "./skin.js";
5
+ import { useEffect, useId, useMemo, useRef, useState, } from "react";
6
+ /**
7
+ * ⌘K over the workspace. The list is the model's (`localEntries`,
8
+ * `searchEntries`); this only draws it and decides WHERE a resource opens,
9
+ * which is the one thing a generic palette cannot know:
10
+ *
11
+ * Enter the page — what a click on a record does
12
+ * ⌥Enter a peek — look without losing the place
13
+ * ⇧Enter a panel beside what I am on
14
+ * ⌘Enter a window
15
+ *
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
+ */
20
+ const SECTION_KEY = {
21
+ [PaletteSection.Actions]: "actions",
22
+ [PaletteSection.Goto]: "goto",
23
+ [PaletteSection.Found]: "found",
24
+ };
25
+ /** Long enough to not ask every domain per keystroke, short enough to feel live. */
26
+ const SEARCH_DELAY_MS = 180;
27
+ function destinationOf(e) {
28
+ if (e.metaKey || e.ctrlKey)
29
+ return Destination.Window;
30
+ if (e.shiftKey)
31
+ return Destination.Side;
32
+ if (e.altKey)
33
+ return Destination.Peek;
34
+ return Destination.Page;
35
+ }
36
+ /** The remote search, debounced, with the stale answers dropped: typing «fac»
37
+ * then «fact» must not let the slower «fac» land last. */
38
+ function useFound(registry, query) {
39
+ const [found, setFound] = useState([]);
40
+ const [loading, setLoading] = useState(false);
41
+ useEffect(() => {
42
+ if (query.trim().length < MIN_QUERY) {
43
+ setFound([]);
44
+ setLoading(false);
45
+ return;
46
+ }
47
+ let current = true;
48
+ setLoading(true);
49
+ const timer = setTimeout(() => {
50
+ void searchEntries(registry, query).then((entries) => {
51
+ if (!current)
52
+ return;
53
+ setFound(entries);
54
+ setLoading(false);
55
+ });
56
+ }, SEARCH_DELAY_MS);
57
+ return () => {
58
+ current = false;
59
+ clearTimeout(timer);
60
+ };
61
+ }, [registry, query]);
62
+ return { found, loading };
63
+ }
64
+ export function WorkspacePalette({ registry, focused, onOpen, onAction, onClose, }) {
65
+ const copy = composerCopy().palette;
66
+ const SearchIcon = useSkin().icons.search;
67
+ const listId = useId();
68
+ const [query, setQuery] = useState("");
69
+ const [cursor, setCursor] = useState(0);
70
+ const { found, loading } = useFound(registry, query);
71
+ const local = useMemo(() => localEntries(registry, focused), [registry, focused]);
72
+ const entries = useMemo(() => [...local.filter((e) => matches(e, query)), ...found], [local, found, query]);
73
+ const active = entries[Math.min(cursor, entries.length - 1)];
74
+ /* The focus goes back where it was: the palette is a path, not a place. */
75
+ const returnTo = useRef(null);
76
+ useEffect(() => {
77
+ returnTo.current = document.activeElement;
78
+ return () => {
79
+ if (returnTo.current instanceof HTMLElement)
80
+ returnTo.current.focus();
81
+ };
82
+ }, []);
83
+ function run(entry, destination) {
84
+ onClose();
85
+ if (entry.section === PaletteSection.Actions)
86
+ onAction(entry.action);
87
+ else
88
+ onOpen(entry.ref, destination);
89
+ }
90
+ function onKeyDown(e) {
91
+ const step = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
92
+ if (step !== 0 && entries.length > 0) {
93
+ setCursor((c) => (Math.min(c, entries.length - 1) + step + entries.length) % entries.length);
94
+ e.preventDefault();
95
+ }
96
+ else if (e.key === "Enter" && active !== undefined) {
97
+ run(active, destinationOf(e));
98
+ e.preventDefault();
99
+ }
100
+ else if (e.key === "Escape") {
101
+ onClose();
102
+ e.preventDefault();
103
+ }
104
+ else if (e.key === "Tab") {
105
+ /* The search box is the palette's only stop: Tab would walk out of the
106
+ dialog into the page behind it. */
107
+ e.preventDefault();
108
+ }
109
+ }
110
+ return (_jsx("div", { className: "sc-scrim", onPointerDown: (e) => {
111
+ if (e.target === e.currentTarget)
112
+ onClose();
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
114
+ ? {}
115
+ : { "aria-activedescendant": `${listId}-${active.id}` }), value: query, placeholder: copy.placeholder, onChange: (e) => {
116
+ setQuery(e.target.value);
117
+ setCursor(0);
118
+ }, onKeyDown: onKeyDown })] }), _jsxs("ul", { id: listId, role: "listbox", className: "sc-palette-list", children: [entries.map((entry, i) => {
119
+ const Icon = entry.icon;
120
+ const heading = entries[i - 1]?.section !== entry.section;
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 })] }) }));
124
+ }
@@ -0,0 +1,38 @@
1
+ import { Zone } from "../domain/index.js";
2
+ import { type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
3
+ /**
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.
11
+ */
12
+ export type PanelActions = {
13
+ onMove: (zone: Zone) => void;
14
+ onCollapse: () => void;
15
+ /** Grow into the page, keeping where it came from. */
16
+ onExpand: () => void;
17
+ onClose: () => void;
18
+ };
19
+ export type PanelFrameProps = {
20
+ title: string;
21
+ actions: PanelActions;
22
+ zone: Zone;
23
+ maximized: boolean;
24
+ collapsed: boolean;
25
+ /** Minimized into a narrow strip: the title is drawn vertically. */
26
+ rail?: boolean;
27
+ focused: boolean;
28
+ /** The id a docked panel is dragged by. A window has none: it moves with the pointer. */
29
+ dragId?: string;
30
+ onMaximize: () => void;
31
+ onFocus: () => void;
32
+ /** Pointer down on the title of a window: the host moves it. */
33
+ onMoveStart?: (e: ReactPointerEvent) => void;
34
+ children: ReactNode;
35
+ };
36
+ declare function Frame({ title, actions, zone, maximized, collapsed, rail, focused, dragId, onMaximize, onFocus, onMoveStart, children, }: PanelFrameProps): import("react").JSX.Element;
37
+ export declare const PanelFrame: import("react").MemoExoticComponent<typeof Frame>;
38
+ export {};
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Zone } from "../domain/index.js";
3
+ import { composerCopy } from "./copy.js";
4
+ import { useSkin } from "./skin.js";
5
+ import { useDraggablePanel } from "../state/drag.js";
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 },
12
+ ];
13
+ /* `onPointerDown` stops here: a control sits on the header, and the header drags. */
14
+ function Control({ icon: Icon, label, active = false, danger = false, onClick, }) {
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, {}) }));
16
+ }
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 }) {
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;
64
+ const header = useRef(null);
65
+ const floating = zone === Zone.Floating;
66
+ const dragging = useDraggablePanel(header, dragId ?? "", dragId !== undefined && !floating);
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 })] }));
69
+ }
70
+ export const PanelFrame = memo(Frame);
@@ -0,0 +1,23 @@
1
+ import { type Registry, type Workspace } from "../domain/index.js";
2
+ import type { ApiFactory } from "../state/api.js";
3
+ import type { WorkspaceStore } from "../state/store.js";
4
+ import { type ReactNode } from "react";
5
+ /**
6
+ * Every surface is a sibling on one layer, ordered by id, positioned with CSS. Changing zone
7
+ * only changes its box: React keeps the node, and with it its scroll, filter, and typed input.
8
+ * Nesting containers per zone would unmount it on every move.
9
+ *
10
+ * Each surface is its own stacking context (`isolate`): a list's sticky bar carries a z-index,
11
+ * and without the boundary it painted OVER the windows — covering their title, so they could
12
+ * not be grabbed.
13
+ */
14
+ export type PanelHostProps = {
15
+ workspace: Workspace;
16
+ /** Drawn over the PAGE only — the peek. Anchored to the page's box, it reads beside the list
17
+ * it came from and never covers the panels docked around it. */
18
+ overlay?: ReactNode;
19
+ registry: Registry;
20
+ store: WorkspaceStore;
21
+ api: ApiFactory;
22
+ };
23
+ export declare function PanelHost({ workspace, overlay, registry, store, api }: PanelHostProps): import("react").JSX.Element;
@@ -0,0 +1,201 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Axis, HandleKind, handles, KEYBOARD_STEP, layout, PAGE, sizeAt, stableOrder, Surface, Zone, } from "../domain/index.js";
3
+ import { composerCopy } from "./copy.js";
4
+ import { PanelFrame } from "./PanelFrame.js";
5
+ import { ViewHost } from "./ViewHost.js";
6
+ import { useDropZone, usePanelDragArmed } from "../state/drag.js";
7
+ import { useCallback, useRef, } from "react";
8
+ const HANDLE_THICKNESS = 9;
9
+ /** A window never gets smaller than this: below it the controls overlap. */
10
+ const MIN_WINDOW = { w: 280, h: 160 };
11
+ /** How much of a window must stay inside the host, so it can always be grabbed back. */
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
+ }
22
+ function boxStyle(box) {
23
+ return {
24
+ left: css(box.left),
25
+ top: css(box.top),
26
+ width: css(box.width),
27
+ height: css(box.height),
28
+ };
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";
38
+ /**
39
+ * A drag that follows the pointer until it is released, wherever it goes. The listeners live on
40
+ * `window`, so leaving the header — or the iframe — does not drop the gesture; pointer capture is
41
+ * only a bonus, because Chrome refuses it for a pointer it no longer tracks («No active pointer
42
+ * with the given id») and a refusal must not cancel the move — that was the window that would
43
+ * not budge.
44
+ */
45
+ function useDrag(hostRef) {
46
+ return useCallback((e, move) => {
47
+ const host = hostRef.current?.getBoundingClientRect();
48
+ if (host === undefined || e.button !== 0)
49
+ return;
50
+ e.preventDefault();
51
+ const target = e.currentTarget;
52
+ try {
53
+ target.setPointerCapture(e.pointerId);
54
+ }
55
+ catch {
56
+ /* Not captured: the window listeners below still follow the pointer. */
57
+ }
58
+ const onMove = (ev) => move(host, ev);
59
+ const stop = () => {
60
+ window.removeEventListener("pointermove", onMove);
61
+ window.removeEventListener("pointerup", stop);
62
+ window.removeEventListener("pointercancel", stop);
63
+ window.removeEventListener("blur", stop);
64
+ };
65
+ window.addEventListener("pointermove", onMove);
66
+ window.addEventListener("pointerup", stop);
67
+ window.addEventListener("pointercancel", stop);
68
+ window.addEventListener("blur", stop);
69
+ }, [hostRef]);
70
+ }
71
+ const handleLabel = (handle, copy) => handle.kind === HandleKind.Zone ? copy.resizeZone(handle.zone) : copy.resizeBetween;
72
+ function ResizeHandle({ handle, value, onDrag, onStep, }) {
73
+ const horizontal = handle.axis === Axis.X;
74
+ const copy = composerCopy().panel;
75
+ function onKeyDown(e) {
76
+ const minus = horizontal ? "ArrowLeft" : "ArrowUp";
77
+ const plus = horizontal ? "ArrowRight" : "ArrowDown";
78
+ if (e.key !== minus && e.key !== plus)
79
+ return;
80
+ e.preventDefault();
81
+ onStep(handle, (e.key === plus ? 1 : -1) * (handle.invert ? -1 : 1) * KEYBOARD_STEP);
82
+ }
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
84
+ ? {
85
+ left: css(handle.at, -HANDLE_THICKNESS / 2),
86
+ top: 0,
87
+ width: HANDLE_THICKNESS,
88
+ height: "100%",
89
+ }
90
+ : {
91
+ top: css(handle.at, -HANDLE_THICKNESS / 2),
92
+ left: 0,
93
+ height: HANDLE_THICKNESS,
94
+ width: "100%",
95
+ }, className: "sc-handle", "data-axis": handle.axis }));
96
+ }
97
+ /** The three grips of a window: right edge, bottom edge, and the corner. */
98
+ const GRIPS = [
99
+ { id: "e", dx: 1, dy: 0 },
100
+ { id: "s", dx: 0, dy: 1 },
101
+ { id: "se", dx: 1, dy: 1 },
102
+ ];
103
+ function ZoneDropTarget({ zone, style, label, armed, }) {
104
+ const box = useRef(null);
105
+ const over = useDropZone(box, zone);
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 }));
107
+ }
108
+ /** Targets cover the container edges, not the live zone boxes — dropping «to the left» has to
109
+ * work even when that zone has no panel yet. */
110
+ const DROP_ZONES = [
111
+ {
112
+ zone: Zone.Left,
113
+ label: "dropLeft",
114
+ style: { left: 0, top: 0, width: "24%", height: "100%" },
115
+ },
116
+ {
117
+ zone: Zone.Right,
118
+ label: "dropRight",
119
+ style: { right: 0, top: 0, width: "24%", height: "100%" },
120
+ },
121
+ {
122
+ zone: Zone.Bottom,
123
+ label: "dropBottom",
124
+ style: { left: "24%", right: "24%", bottom: 0, height: "30%" },
125
+ },
126
+ ];
127
+ export function PanelHost({ workspace, overlay, registry, store, api }) {
128
+ const hostRef = useRef(null);
129
+ const drag = useDrag(hostRef);
130
+ const dropArmed = usePanelDragArmed();
131
+ const copy = composerCopy().panel;
132
+ const slots = layout(workspace);
133
+ const resizeHandles = handles(workspace);
134
+ const valueOf = (handle) => {
135
+ if (handle.kind === HandleKind.Zone)
136
+ return workspace.zones[handle.zone];
137
+ const panel = workspace.panels.find((p) => p.id === handle.panelId);
138
+ return panel !== undefined && panel.placement.zone !== Zone.Floating
139
+ ? panel.placement.share
140
+ : 0;
141
+ };
142
+ const applyHandle = (handle, value) => {
143
+ if (handle.kind === HandleKind.Zone)
144
+ store.resizeZone(handle.zone, value);
145
+ else
146
+ store.resizePanel(handle.panelId, value);
147
+ };
148
+ function moveWindow(e, slot) {
149
+ if (!slot.floating)
150
+ return;
151
+ const [left, top, width] = [slot.box.left.px, slot.box.top.px, slot.box.width.px];
152
+ const start = { x: e.clientX, y: e.clientY };
153
+ store.raisePanel(slot.id);
154
+ drag(e, (host, ev) => {
155
+ store.floatPanel(slot.id, {
156
+ x: Math.max(KEEP_VISIBLE - width, Math.min(left + ev.clientX - start.x, host.width - KEEP_VISIBLE)),
157
+ y: Math.max(0, Math.min(top + ev.clientY - start.y, host.height - KEEP_VISIBLE / 2)),
158
+ });
159
+ });
160
+ }
161
+ function resizeWindow(e, slot, dx, dy) {
162
+ if (!slot.floating)
163
+ return;
164
+ const [width, height] = [slot.box.width.px, slot.box.height.px];
165
+ const start = { x: e.clientX, y: e.clientY };
166
+ e.stopPropagation();
167
+ drag(e, (_host, ev) => {
168
+ store.floatPanel(slot.id, {
169
+ ...(dx === 0 ? {} : { w: Math.max(MIN_WINDOW.w, width + ev.clientX - start.x) }),
170
+ ...(dy === 0 ? {} : { h: Math.max(MIN_WINDOW.h, height + ev.clientY - start.y) }),
171
+ });
172
+ });
173
+ }
174
+ function moveHandle(e, handle) {
175
+ drag(e, (host, ev) => {
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));
180
+ });
181
+ }
182
+ return (_jsxs("div", { ref: hostRef, className: "sc-host", children: [stableOrder(slots).map((slot) => {
183
+ const isPage = slot.id === PAGE;
184
+ const style = {
185
+ ...boxStyle(slot.box),
186
+ ...(slot.floating ? { zIndex: 20 + slot.z } : {}),
187
+ };
188
+ if (isPage) {
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));
190
+ }
191
+ const zone = slot.panel?.placement.zone ?? Zone.Right;
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: {
193
+ onMove: (z) => store.movePanel(slot.id, z),
194
+ onCollapse: () => store.collapsePanel(slot.id),
195
+ onExpand: () => store.expandPanel(slot.id),
196
+ onClose: () => store.closePanel(slot.id),
197
+ }, children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Panel, panelId: slot.id }) }) }), slot.floating && !slot.collapsed
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)))
199
+ : null] }, slot.id));
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}`)))] }));
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
+ }
@@ -0,0 +1,12 @@
1
+ import { Destination, type ResourceRef, type WorkspaceApi } from "../domain/index.js";
2
+ import { type ReactNode } from "react";
3
+ export type RecordLinkProps = {
4
+ api: WorkspaceApi;
5
+ resource: ResourceRef;
6
+ /** What a plain click does. Without it, the workspace's default. */
7
+ to?: Destination;
8
+ /** Hide the icons — for a dense table where only the keys are wanted. */
9
+ compact?: boolean;
10
+ children: ReactNode;
11
+ };
12
+ export declare function RecordLink({ api, resource, to, compact, children, }: RecordLinkProps): import("react").JSX.Element;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Destination, } from "../domain/index.js";
3
+ import { composerCopy } from "./copy.js";
4
+ import { useSkin } from "./skin.js";
5
+ import { useDraggableRef } from "../state/drag.js";
6
+ import { useRef } from "react";
7
+ /**
8
+ * The name of a record, wherever it appears — a row, a chip of a many2one, a search result. It
9
+ * is the same control everywhere so people learn it once:
10
+ *
11
+ * click the default (the page, unless the caller says `to`)
12
+ * Space a peek, without leaving the place
13
+ * ⇧ click a panel beside
14
+ * ⌘ / Ctrl click a window
15
+ * the icons every destination by name, for who does not know the keys
16
+ * drag to an edge of the workspace: a panel
17
+ *
18
+ * The icons appear on hover and on focus, never taking room from the name.
19
+ */
20
+ const ICONS = [
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
+ ];
25
+ export function RecordLink({ api, resource, to, compact = false, children, }) {
26
+ const copy = composerCopy().link;
27
+ const icons = useSkin().icons;
28
+ const box = useRef(null);
29
+ const dragging = useDraggableRef(box, resource);
30
+ /* The name sits inside a row that has its own click (open, peek). Whatever this control
31
+ does, the row must not do it too. */
32
+ function onClick(e) {
33
+ e.stopPropagation();
34
+ if (e.metaKey || e.ctrlKey)
35
+ api.open(resource, { to: Destination.Window });
36
+ else if (e.shiftKey)
37
+ api.open(resource, { to: Destination.Side });
38
+ else
39
+ api.open(resource, to === undefined ? {} : { to });
40
+ }
41
+ function onKeyDown(e) {
42
+ if (e.key !== " ")
43
+ return;
44
+ api.open(resource, { to: Destination.Peek });
45
+ e.preventDefault();
46
+ e.stopPropagation();
47
+ }
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
+ }) }))] }));
55
+ }
@@ -0,0 +1,11 @@
1
+ import { type Registry, type ResourceRef, type WorkspaceApi } from "../domain/index.js";
2
+ import { type ReactNode } from "react";
3
+ export type ViewHostProps = {
4
+ resource: ResourceRef;
5
+ registry: Registry;
6
+ api: WorkspaceApi;
7
+ fallback?: ReactNode;
8
+ };
9
+ declare function Host({ resource, registry, api, fallback }: ViewHostProps): import("react").JSX.Element;
10
+ export declare const ViewHost: import("react").MemoExoticComponent<typeof Host>;
11
+ export {};