@sincpro/web-composer 1.1.0 → 1.3.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.
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { Destination, focusedRef, PAGE, PaletteSection, PEEK, selectionOf, Surfa
10
10
  export { Composer } from "./shell/Composer.js";
11
11
  export { composerCopy, ENGLISH_COMPOSER_COPY, installComposerCopy, SPANISH_COMPOSER_COPY, } from "./shell/copy.js";
12
12
  export {} from "./shell/icons.js";
13
+ export { ModalLayer, ModalWindow, } from "./shell/Modal.js";
13
14
  export { WorkspacePalette, } from "./shell/Palette.js";
14
15
  export { PanelFrame, } from "./shell/PanelFrame.js";
15
16
  export { PanelHost } from "./shell/PanelHost.js";
@@ -17,7 +18,7 @@ export { RecordLink } from "./shell/RecordLink.js";
17
18
  export { DEFAULT_ICONS, } from "./shell/skin.js";
18
19
  export { ComposerStyles } from "./shell/styles.js";
19
20
  export { ViewHost } from "./shell/ViewHost.js";
20
- export { createApiFactory, } from "./state/api.js";
21
+ export { createApiFactory, targetOf, } from "./state/api.js";
21
22
  export { createWorkspaceStore, } from "./state/store.js";
22
23
  export { useKeyboard, } from "./state/useKeyboard.js";
23
24
  export { useCrumbs, useWorkspace, useWorkspaceContext, useWorkspaceSlice, useWorkspaceState, } from "./state/useWorkspace.js";
@@ -19,5 +19,8 @@ export type ComposerProps = {
19
19
  /** Your design over the composer: icons, the peek drawer, the confirm dialog, the notice, or
20
20
  * `styles: false` to drop the default sheet. What is not passed keeps the default. */
21
21
  skin?: ComposerSkin;
22
+ /** Below this width (px) of the WORKSPACE it behaves as a phone: one screen, windows and side
23
+ * panels open as the page, choosers as a sheet (`domain/phone.ts`). `0` never does. */
24
+ phoneBelow?: number;
22
25
  };
23
- export declare function Composer({ workspace, registry, empty, keyboard, defaultOpen, palette: paletteProp, onPaletteChange, skin: skinProp, }: ComposerProps): import("react").JSX.Element;
26
+ export declare function Composer({ workspace, registry, empty, keyboard, defaultOpen, palette: paletteProp, onPaletteChange, skin: skinProp, phoneBelow, }: ComposerProps): import("react").JSX.Element;
@@ -1,17 +1,18 @@
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";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Destination, destinationOnPhone, focusedRef, modalOver, PEEK, PHONE_WIDTH, Surface, Zone, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
+ import { ModalLayer } from "./Modal.js";
4
5
  import { WorkspacePalette } from "./Palette.js";
5
6
  import { PanelHost } from "./PanelHost.js";
6
7
  import { ChromeButton, ConfirmDialog, PeekDrawer } from "./Peek.js";
7
8
  import { resolveSkin, SkinProvider, } from "./skin.js";
8
9
  import { ComposerStyles } from "./styles.js";
9
10
  import { ViewHost } from "./ViewHost.js";
10
- import { createApiFactory } from "../state/api.js";
11
+ import { createApiFactory, targetOf } from "../state/api.js";
11
12
  import { useDropMonitor } from "../state/drag.js";
12
13
  import { useKeyboard } from "../state/useKeyboard.js";
13
14
  import { useWorkspaceState } from "../state/useWorkspace.js";
14
- import { useCallback, useEffect, useMemo, useState } from "react";
15
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
15
16
  /**
16
17
  * The question before throwing away what someone typed, drawn with the design system. The store
17
18
  * calls it; a `confirmDiscard` given to the store replaces it.
@@ -30,7 +31,36 @@ function useDiscardDialog(workspace, titleOf) {
30
31
  }, [workspace, titleOf]);
31
32
  return asking;
32
33
  }
33
- export function Composer({ workspace, registry, empty, keyboard = true, defaultOpen = Destination.Page, palette: paletteProp, onPaletteChange, skin: skinProp, }) {
34
+ /**
35
+ * Whether the workspace is a phone, measured BEFORE paint: measuring after it drew the desk for a
36
+ * frame and swapped it, and a click in that frame landed on a panel that was going away. A
37
+ * workspace with no width yet (hidden, or not laid out) is not a phone.
38
+ */
39
+ function usePhone(root, below) {
40
+ const [phone, setPhone] = useState(false);
41
+ useLayoutEffect(() => {
42
+ const el = root.current;
43
+ if (el === null)
44
+ return;
45
+ const measure = (width) => setPhone(width > 0 && width < below);
46
+ measure(el.getBoundingClientRect().width);
47
+ if (typeof ResizeObserver === "undefined")
48
+ return;
49
+ const watch = new ResizeObserver(([entry]) => {
50
+ if (entry !== undefined)
51
+ measure(entry.contentRect.width);
52
+ });
53
+ watch.observe(el);
54
+ return () => watch.disconnect();
55
+ }, [root, below]);
56
+ return phone;
57
+ }
58
+ /** On a phone the panels that were open wait here: one tap brings each to the page. */
59
+ function PhoneDock({ panels, titleOf, onBring, }) {
60
+ const copy = composerCopy().phone;
61
+ return (_jsxs("nav", { "aria-label": copy.alsoOpen, className: "sc-dock", children: [_jsx("span", { className: "sc-dock-label", children: copy.alsoOpen }), panels.map((p) => (_jsx(ChromeButton, { onClick: () => onBring(p.id), children: titleOf(p.view) }, p.id)))] }));
62
+ }
63
+ export function Composer({ workspace, registry, empty, keyboard = true, defaultOpen = Destination.Page, palette: paletteProp, onPaletteChange, skin: skinProp, phoneBelow = PHONE_WIDTH, }) {
34
64
  const skin = useMemo(() => resolveSkin(skinProp), [skinProp]);
35
65
  const Drawer = skin.Peek ?? PeekDrawer;
36
66
  const Confirm = skin.Confirm ?? ConfirmDialog;
@@ -42,7 +72,18 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
42
72
  setPaletteState(open);
43
73
  onPaletteChange?.(open);
44
74
  }, [onPaletteChange]);
45
- const api = useMemo(() => createApiFactory(workspace, { registry, defaultOpen }), [workspace, registry, defaultOpen]);
75
+ const root = useRef(null);
76
+ const phone = usePhone(root, phoneBelow);
77
+ /* The API reads it at call time: a view's API is not rebuilt when the window is resized. */
78
+ const phoneNow = useRef(phone);
79
+ useLayoutEffect(() => {
80
+ phoneNow.current = phone;
81
+ }, [phone]);
82
+ const api = useMemo(() => createApiFactory(workspace, {
83
+ registry,
84
+ defaultOpen,
85
+ isPhone: () => phoneNow.current,
86
+ }), [workspace, registry, defaultOpen]);
46
87
  useEffect(() => api.dispose, [api]);
47
88
  useKeyboard({
48
89
  workspace,
@@ -56,7 +97,8 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
56
97
  const asking = useDiscardDialog(workspace, api.titleOf);
57
98
  /** Where a chosen search result opens. Without a page yet, the first one becomes it —
58
99
  * whatever was asked: a peek or a window over nothing would be invisible. */
59
- function open(ref, destination) {
100
+ function open(ref, asked) {
101
+ const destination = phone ? destinationOnPhone(asked) : asked;
60
102
  if (workspace.get().page === null)
61
103
  workspace.push(ref);
62
104
  else if (destination === Destination.Peek)
@@ -69,20 +111,17 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
69
111
  workspace.push(ref);
70
112
  }
71
113
  /** 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. */
114
+ * reading, a panel or a modal — so «audit» can open beside it or navigate it. */
73
115
  function run(action) {
74
116
  const w = workspace.get();
75
117
  const ref = focusedRef(w);
76
118
  if (ref === null)
77
119
  return;
78
- action.run(api.for(ref, w.focus === PAGE
79
- ? { surface: Surface.Page }
80
- : w.focus === PEEK
81
- ? { surface: Surface.Peek }
82
- : { surface: Surface.Panel, panelId: w.focus }));
120
+ action.run(api.for(ref, targetOf(w.focus)));
83
121
  }
84
122
  const peeked = state.peek;
123
+ const peekModal = modalOver(state, PEEK);
85
124
  const peekSpec = peeked === null ? null : registry.resolve(peeked);
86
125
  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] }) }));
126
+ return (_jsx(SkinProvider, { value: skin, children: _jsxs("div", { ref: root, className: "sc-root", ...(phone ? { "data-phone": "" } : {}), 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, phone: phone, overlay: peeked === null ? null : (_jsxs(_Fragment, { children: [_jsx("div", { style: { display: "contents" }, inert: peekModal !== null, onPointerDownCapture: () => workspace.focusPanel(PEEK), children: _jsx(Drawer, { title: api.titleOf(peeked), onClose: workspace.closePeek, actions: _jsxs(_Fragment, { children: [phone ? null : (_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 }) }) }) }), peekModal === null ? null : (_jsx(ModalLayer, { modal: peekModal, registry: registry, store: workspace, api: api, phone: phone }))] })) })), phone && state.page !== null && state.panels.length > 0 ? (_jsx(PhoneDock, { panels: state.panels, titleOf: api.titleOf, onBring: workspace.expandPanel })) : null, _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] }) }));
88
127
  }
@@ -0,0 +1,18 @@
1
+ import { type Modal, type Registry } from "../domain/index.js";
2
+ import { type ModalProps } from "./skin.js";
3
+ import type { ApiFactory } from "../state/api.js";
4
+ import type { WorkspaceStore } from "../state/store.js";
5
+ import { type CSSProperties } from "react";
6
+ export declare function ModalWindow({ title, blur, size, phone, onClose, children }: ModalProps): import("react").JSX.Element;
7
+ export type ModalLayerProps = {
8
+ modal: Modal;
9
+ registry: Registry;
10
+ store: WorkspaceStore;
11
+ api: ApiFactory;
12
+ /** Geometry only: where the host is, when the layer is not already inside it. */
13
+ style?: CSSProperties;
14
+ phone?: boolean;
15
+ };
16
+ /** Where a modal stands: over its host's box, taking the workspace focus when touched. The skin
17
+ * draws what is inside it. */
18
+ export declare function ModalLayer({ modal, registry, store, api, style, phone, }: ModalLayerProps): import("react").JSX.Element;
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { modalId, Surface, } from "../domain/index.js";
3
+ import { composerCopy } from "./copy.js";
4
+ import { useSkin } from "./skin.js";
5
+ import { ViewHost } from "./ViewHost.js";
6
+ import { useEffect, useId, useRef, useState, } from "react";
7
+ /**
8
+ * The composer's own modal: a small window centred over the surface that asked for it — on a
9
+ * phone, a sheet from the bottom. It moves
10
+ * by its title — what is underneath may be what the person needs to read to answer — but never
11
+ * further than its surface: it belongs to it, and leaving it would cover a neighbour that is
12
+ * not blocked. It does not dim the rest of the workspace; that is the point of it.
13
+ */
14
+ /** How much of the window must stay inside its surface, so it can always be grabbed back. */
15
+ const KEEP_VISIBLE = 48;
16
+ /** Follows the pointer until it is released, on `window`: leaving the title does not drop the
17
+ * gesture. */
18
+ function useMoveByTitle(box) {
19
+ const [offset, setOffset] = useState({ x: 0, y: 0 });
20
+ function start(e) {
21
+ const el = box.current;
22
+ const layer = el?.parentElement?.getBoundingClientRect();
23
+ if (el === null || layer === undefined || e.button !== 0)
24
+ return;
25
+ e.preventDefault();
26
+ const from = { x: e.clientX, y: e.clientY };
27
+ const origin = offset;
28
+ const rect = el.getBoundingClientRect();
29
+ /* Where the window is with no offset, so the limits are absolute and not cumulative. */
30
+ const base = { left: rect.left - origin.x, top: rect.top - origin.y };
31
+ const onMove = (ev) => {
32
+ const left = base.left + origin.x + ev.clientX - from.x;
33
+ const top = base.top + origin.y + ev.clientY - from.y;
34
+ const x = Math.max(layer.left - rect.width + KEEP_VISIBLE, Math.min(left, layer.right - KEEP_VISIBLE));
35
+ const y = Math.max(layer.top, Math.min(top, layer.bottom - KEEP_VISIBLE));
36
+ setOffset({ x: x - base.left, y: y - base.top });
37
+ };
38
+ const stop = () => {
39
+ window.removeEventListener("pointermove", onMove);
40
+ window.removeEventListener("pointerup", stop);
41
+ window.removeEventListener("pointercancel", stop);
42
+ };
43
+ window.addEventListener("pointermove", onMove);
44
+ window.addEventListener("pointerup", stop);
45
+ window.addEventListener("pointercancel", stop);
46
+ }
47
+ return { offset, start };
48
+ }
49
+ export function ModalWindow({ title, blur, size, phone, onClose, children }) {
50
+ const copy = composerCopy().modal;
51
+ const { close: CloseIcon } = useSkin().icons;
52
+ const box = useRef(null);
53
+ const titleId = useId();
54
+ const { offset, start } = useMoveByTitle(box);
55
+ useEffect(() => {
56
+ const opener = document.activeElement;
57
+ box.current?.focus();
58
+ return () => {
59
+ if (opener instanceof HTMLElement && opener.isConnected)
60
+ opener.focus();
61
+ };
62
+ }, []);
63
+ return (_jsx("div", { className: "sc-modal-scrim", ...(blur ? { "data-blur": "" } : {}), ...(phone ? { "data-phone": "" } : {}), children: _jsxs("section", { ref: box, role: "dialog", tabIndex: -1, "aria-labelledby": titleId, className: "sc-modal", style: phone
64
+ ? undefined
65
+ : {
66
+ transform: `translate(${offset.x}px, ${offset.y}px)`,
67
+ ...(size === undefined ? {} : { width: size.w, height: size.h }),
68
+ }, onKeyDown: (e) => {
69
+ if (e.key !== "Escape" || e.defaultPrevented)
70
+ return;
71
+ e.preventDefault();
72
+ onClose();
73
+ }, children: [_jsxs("header", { className: "sc-modal-head", onPointerDown: phone ? undefined : start, children: [_jsx("h2", { id: titleId, className: "sc-modal-title", children: title }), _jsx("button", { type: "button", className: "sc-control", "aria-label": copy.close, title: copy.close, onPointerDown: (e) => e.stopPropagation(), onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: "sc-modal-body", children: children })] }) }));
74
+ }
75
+ /** Where a modal stands: over its host's box, taking the workspace focus when touched. The skin
76
+ * draws what is inside it. */
77
+ export function ModalLayer({ modal, registry, store, api, style, phone = false, }) {
78
+ const Window = useSkin().Modal ?? ModalWindow;
79
+ const { host, view } = modal;
80
+ return (_jsx("div", { className: "sc-modal-layer", ...(style === undefined ? {} : { style }), onPointerDownCapture: () => store.focusPanel(modalId(host)), children: _jsx(Window, { title: api.titleOf(view), blur: modal.blur, ...(modal.size === undefined ? {} : { size: modal.size }), phone: phone, onClose: () => store.closeModal(host), children: _jsx(ViewHost, { resource: view, registry: registry, api: api.for(view, { surface: Surface.Modal, host }) }) }) }));
81
+ }
@@ -31,8 +31,11 @@ export type PanelFrameProps = {
31
31
  onFocus: () => void;
32
32
  /** Pointer down on the title of a window: the host moves it. */
33
33
  onMoveStart?: (e: ReactPointerEvent) => void;
34
+ /** A modal over this panel's view. It blocks the view only: the header still moves, minimizes
35
+ * and closes the panel. */
36
+ modal?: ReactNode;
34
37
  children: ReactNode;
35
38
  };
36
- declare function Frame({ title, actions, zone, maximized, collapsed, rail, focused, dragId, onMaximize, onFocus, onMoveStart, children, }: PanelFrameProps): import("react").JSX.Element;
39
+ declare function Frame({ title, actions, zone, maximized, collapsed, rail, focused, dragId, onMaximize, onFocus, onMoveStart, modal, children, }: PanelFrameProps): import("react").JSX.Element;
37
40
  export declare const PanelFrame: import("react").MemoExoticComponent<typeof Frame>;
38
41
  export {};
@@ -58,13 +58,13 @@ function MoveMenu({ zone, onMove }) {
58
58
  onMove(z);
59
59
  }, children: [_jsx(Icon, {}), label, _jsx("span", { className: "sc-menu-hint", children: hint })] }, z)))] })) : null] }));
60
60
  }
61
- function Frame({ title, actions, zone, maximized, collapsed, rail = false, focused, dragId, onMaximize, onFocus, onMoveStart, children, }) {
61
+ function Frame({ title, actions, zone, maximized, collapsed, rail = false, focused, dragId, onMaximize, onFocus, onMoveStart, modal, children, }) {
62
62
  const copy = composerCopy().panel;
63
63
  const icons = useSkin().icons;
64
64
  const header = useRef(null);
65
65
  const floating = zone === Zone.Floating;
66
66
  const dragging = useDraggablePanel(header, dragId ?? "", dragId !== undefined && !floating);
67
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 })] }));
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 })] })), _jsxs("div", { hidden: collapsed, className: "sc-body-wrap", children: [_jsx("div", { inert: modal !== undefined && modal !== null, className: "sc-body", children: children }), modal] })] }));
69
69
  }
70
70
  export const PanelFrame = memo(Frame);
@@ -19,5 +19,7 @@ export type PanelHostProps = {
19
19
  registry: Registry;
20
20
  store: WorkspaceStore;
21
21
  api: ApiFactory;
22
+ /** One screen: the page takes it all, the panels wait hidden, nothing resizes or docks. */
23
+ phone?: boolean;
22
24
  };
23
- export declare function PanelHost({ workspace, overlay, registry, store, api }: PanelHostProps): import("react").JSX.Element;
25
+ export declare function PanelHost({ workspace, overlay, registry, store, api, phone, }: PanelHostProps): import("react").JSX.Element;
@@ -1,13 +1,12 @@
1
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";
2
+ import { Axis, HandleKind, handles, KEYBOARD_STEP, layout, MIN_WINDOW, modalOver, PAGE, phoneLayout, sizeAt, stableOrder, Surface, Zone, } from "../domain/index.js";
3
3
  import { composerCopy } from "./copy.js";
4
+ import { ModalLayer } from "./Modal.js";
4
5
  import { PanelFrame } from "./PanelFrame.js";
5
6
  import { ViewHost } from "./ViewHost.js";
6
7
  import { useDropZone, usePanelDragArmed } from "../state/drag.js";
7
- import { useCallback, useRef, } from "react";
8
+ import { Fragment, useCallback, useRef, } from "react";
8
9
  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
10
  /** How much of a window must stay inside the host, so it can always be grabbed back. */
12
11
  const KEEP_VISIBLE = 80;
13
12
  /** A share of the host plus pixels, as CSS. `calc()` only when both are there. */
@@ -124,13 +123,13 @@ const DROP_ZONES = [
124
123
  style: { left: "24%", right: "24%", bottom: 0, height: "30%" },
125
124
  },
126
125
  ];
127
- export function PanelHost({ workspace, overlay, registry, store, api }) {
126
+ export function PanelHost({ workspace, overlay, registry, store, api, phone = false, }) {
128
127
  const hostRef = useRef(null);
129
128
  const drag = useDrag(hostRef);
130
129
  const dropArmed = usePanelDragArmed();
131
130
  const copy = composerCopy().panel;
132
- const slots = layout(workspace);
133
- const resizeHandles = handles(workspace);
131
+ const slots = phone ? phoneLayout(layout(workspace)) : layout(workspace);
132
+ const resizeHandles = phone ? [] : handles(workspace);
134
133
  const valueOf = (handle) => {
135
134
  if (handle.kind === HandleKind.Zone)
136
135
  return workspace.zones[handle.zone];
@@ -185,11 +184,14 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
185
184
  ...boxStyle(slot.box),
186
185
  ...(slot.floating ? { zIndex: 20 + slot.z } : {}),
187
186
  };
187
+ const modal = modalOver(workspace, slot.id);
188
+ /* The page has no frame to hold its modal: it stands beside it, over the same box, and
189
+ the page underneath is inert. */
188
190
  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));
191
+ return (_jsxs(Fragment, { children: [_jsx("div", { hidden: !slot.visible, inert: modal !== null, 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 }) }) }), modal === null || !slot.visible ? null : (_jsx(ModalLayer, { modal: modal, registry: registry, store: store, api: api, phone: phone, style: boxStyle(slot.box) }))] }, slot.id));
190
192
  }
191
193
  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: {
194
+ 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), modal: modal === null ? null : (_jsx(ModalLayer, { modal: modal, registry: registry, store: store, api: api })), actions: {
193
195
  onMove: (z) => store.movePanel(slot.id, z),
194
196
  onCollapse: () => store.collapsePanel(slot.id),
195
197
  onExpand: () => store.expandPanel(slot.id),
@@ -197,5 +199,5 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
197
199
  }, children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Panel, panelId: slot.id }) }) }), slot.floating && !slot.collapsed
198
200
  ? 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
201
  : 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}`)))] }));
202
+ }), 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", { hidden: phone, 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
203
  }
@@ -32,6 +32,12 @@ export type ComposerCopy = {
32
32
  close: string;
33
33
  back: (to: string) => string;
34
34
  };
35
+ modal: {
36
+ close: string;
37
+ };
38
+ phone: {
39
+ alsoOpen: string;
40
+ };
35
41
  discard: {
36
42
  title: string;
37
43
  detail: (names: readonly string[]) => string;
@@ -32,6 +32,8 @@ export const ENGLISH_COMPOSER_COPY = {
32
32
  close: "Close the preview",
33
33
  back: (to) => `Back to ${to}`,
34
34
  },
35
+ modal: { close: "Close" },
36
+ phone: { alsoOpen: "Also open" },
35
37
  discard: {
36
38
  title: "Discard the changes?",
37
39
  detail: (names) => `What was typed in ${names.join(", ")} has not been saved.`,
@@ -57,8 +59,8 @@ export const ENGLISH_COMPOSER_COPY = {
57
59
  { keys: "⌥←", action: "one page back, or one step back in the peek" },
58
60
  { keys: "⌘⌥[ / ⌘⌥]", action: "move focus between the page and the panels" },
59
61
  { keys: "⌘⇧⏎", action: "maximize the focused surface, or restore it" },
60
- { keys: "⌘⇧⌫", action: "close the focused panel or the peek" },
61
- { keys: "Esc", action: "close the peek, or restore the maximized view" },
62
+ { keys: "⌘⇧⌫", action: "close the focused panel, modal or the peek" },
63
+ { keys: "Esc", action: "close the modal or the peek, or restore the maximized view" },
62
64
  { keys: "← → on a handle", action: "resize without the mouse" },
63
65
  ],
64
66
  };
@@ -91,6 +93,8 @@ export const SPANISH_COMPOSER_COPY = {
91
93
  close: "Cerrar la vista previa",
92
94
  back: (to) => `Volver a ${to}`,
93
95
  },
96
+ modal: { close: "Cerrar" },
97
+ phone: { alsoOpen: "También abiertos" },
94
98
  discard: {
95
99
  title: "¿Descartar los cambios?",
96
100
  detail: (names) => `Lo escrito en ${names.join(", ")} no se guardó.`,
@@ -116,8 +120,8 @@ export const SPANISH_COMPOSER_COPY = {
116
120
  { keys: "⌥←", action: "una página atrás, o un paso atrás en el vistazo" },
117
121
  { keys: "⌘⌥[ / ⌘⌥]", action: "mover el foco entre la página y los paneles" },
118
122
  { keys: "⌘⇧⏎", action: "maximizar la superficie con foco, o restaurarla" },
119
- { keys: "⌘⇧⌫", action: "cerrar el panel con foco o el vistazo" },
120
- { keys: "Esc", action: "cerrar el vistazo, o restaurar la vista maximizada" },
123
+ { keys: "⌘⇧⌫", action: "cerrar el panel o el modal con foco, o el vistazo" },
124
+ { keys: "Esc", action: "cerrar el modal o el vistazo, o restaurar la vista maximizada" },
121
125
  { keys: "← → en un divisor", action: "redimensionar sin el mouse" },
122
126
  ],
123
127
  };
@@ -1,3 +1,4 @@
1
+ import type { Size } from "../domain/index.js";
1
2
  import { type IconProps } from "./icons.js";
2
3
  import type { ComponentType, ReactNode } from "react";
3
4
  /**
@@ -8,6 +9,9 @@ import type { ComponentType, ReactNode } from "react";
8
9
  *
9
10
  * <Composer skin={{ icons: { close: X, more: Ellipsis }, Peek: MyDrawer }} … />
10
11
  *
12
+ * An icon passed here is drawn at the composer's size (`--sc-icon`, 14px), whatever size it
13
+ * draws itself at: a 24px icon library does not inflate the controls.
14
+ *
11
15
  * Three levels, from least to most work: the `--sc-*` variables (colors, radius), these pieces,
12
16
  * and `styles: false` to drop the default sheet and style the `sc-*` classes from scratch.
13
17
  */
@@ -36,6 +40,24 @@ export type PeekProps = {
36
40
  actions?: ReactNode;
37
41
  children: ReactNode;
38
42
  };
43
+ /**
44
+ * A modal over ONE surface: it covers that surface — the page, a window, a side panel or the
45
+ * peek — and nothing else, so the rest of the workspace keeps answering. The composer places it
46
+ * and blocks what is underneath; this draws the scrim and the window. It must take the focus on
47
+ * open, give it back on close, and close on Escape while the focus is inside — claiming the key
48
+ * with `preventDefault`. The default one moves by its title.
49
+ */
50
+ export type ModalProps = {
51
+ title: string;
52
+ /** Blur what it covers. Off unless the view that opened it asked. */
53
+ blur: boolean;
54
+ /** The size the view asked for, in pixels; what does not fit shrinks. */
55
+ size?: Size;
56
+ /** The workspace is a phone: draw it as a sheet from the bottom, not a window. */
57
+ phone: boolean;
58
+ onClose: () => void;
59
+ children: ReactNode;
60
+ };
39
61
  /** The question before throwing away what was typed. `onAnswer(false)` is the safe answer and
40
62
  * what Escape gives. */
41
63
  export type ConfirmProps = {
@@ -56,6 +78,7 @@ export type NoticeProps = {
56
78
  export type Skin = {
57
79
  icons: SkinIcons;
58
80
  Peek: ComponentType<PeekProps> | null;
81
+ Modal: ComponentType<ModalProps> | null;
59
82
  Confirm: ComponentType<ConfirmProps> | null;
60
83
  Notice: ComponentType<NoticeProps> | null;
61
84
  /** `false` drops the default sheet: the `sc-*` classes are then yours to style. */
@@ -20,6 +20,7 @@ export const DEFAULT_ICONS = {
20
20
  const DEFAULT_SKIN = {
21
21
  icons: DEFAULT_ICONS,
22
22
  Peek: null,
23
+ Modal: null,
23
24
  Confirm: null,
24
25
  Notice: null,
25
26
  styles: true,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The composer's own skin: the frames, the drawer, the rail, the dialog and ⌘K, with no design
2
+ * The composer's own skin: the frames, the drawer, the modal, the rail, the dialog and ⌘K, with no design
3
3
  * system behind it. It is the minimum that makes the windows usable — the views inside them are
4
4
  * the application's, drawn with whatever it uses.
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /**
3
- * The composer's own skin: the frames, the drawer, the rail, the dialog and ⌘K, with no design
3
+ * The composer's own skin: the frames, the drawer, the modal, the rail, the dialog and ⌘K, with no design
4
4
  * system behind it. It is the minimum that makes the windows usable — the views inside them are
5
5
  * the application's, drawn with whatever it uses.
6
6
  *
@@ -33,6 +33,10 @@ const CSS = `
33
33
  --_radius-control: var(--sc-radius-control, 6px);
34
34
  --_text: var(--sc-text, 13px);
35
35
  --_text-small: var(--sc-text-small, 12px);
36
+ /* Every glyph the composer places — its own or the application's — is drawn at this size. */
37
+ --_icon: var(--sc-icon, 14px);
38
+ --_modal-scrim: var(--sc-modal-scrim, rgb(0 0 0 / 0.14));
39
+ --_modal-blur: var(--sc-modal-blur, 3px);
36
40
  --_tint: color-mix(in srgb, var(--_accent) 10%, transparent);
37
41
  --_hover: color-mix(in srgb, var(--_ink) 7%, transparent);
38
42
 
@@ -47,6 +51,10 @@ const CSS = `
47
51
  }
48
52
  .sc-root *, .sc-root *::before, .sc-root *::after { box-sizing: border-box; }
49
53
  .sc-root :focus-visible { outline: 2px solid var(--_accent); outline-offset: 1px; }
54
+ .sc-root :is(.sc-control, .sc-button, .sc-menu-item, .sc-palette-search, .sc-option-icon) svg {
55
+ flex-shrink: 0; width: var(--_icon); height: var(--_icon);
56
+ }
57
+ .sc-root .sc-link-icons .sc-control svg { width: calc(var(--_icon) - 2px); height: calc(var(--_icon) - 2px); }
50
58
 
51
59
  .sc-empty { display: flex; flex: 1; min-height: 0; align-items: center; justify-content: center; padding: 32px; }
52
60
  .sc-host { position: relative; flex: 1; min-height: 0; overflow: hidden; }
@@ -79,6 +87,7 @@ const CSS = `
79
87
  font-size: var(--_text-small); font-weight: 500;
80
88
  }
81
89
  .sc-header[data-rail] .sc-title { min-height: 0; padding: 4px 0; writing-mode: vertical-rl; }
90
+ .sc-body-wrap { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; }
82
91
  .sc-body { flex: 1; min-height: 0; overflow: auto; container-type: inline-size; }
83
92
 
84
93
  .sc-control {
@@ -143,6 +152,43 @@ const CSS = `
143
152
  .sc-peek-actions { display: flex; flex-shrink: 0; flex-wrap: wrap; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--_line); }
144
153
  .sc-peek-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; container-type: inline-size; }
145
154
 
155
+ .sc-modal-layer { position: absolute; inset: 0; z-index: 1; }
156
+ .sc-overlay > .sc-modal-layer { z-index: 31; }
157
+ .sc-modal-scrim {
158
+ position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
159
+ padding: 12px; overflow: hidden; background: var(--_modal-scrim);
160
+ }
161
+ .sc-modal-scrim[data-blur] { backdrop-filter: blur(var(--_modal-blur)); }
162
+ .sc-modal {
163
+ display: flex; flex-direction: column; width: min(28rem, 100%); max-width: 100%; max-height: 100%;
164
+ overflow: hidden; background: var(--_surface); border: 1px solid var(--_line-strong);
165
+ border-radius: var(--_radius); box-shadow: var(--_shadow); outline: 0;
166
+ }
167
+ .sc-modal-head {
168
+ display: flex; flex-shrink: 0; align-items: center; gap: 8px; height: 34px; padding: 0 3px 0 12px;
169
+ background: var(--_ground); border-bottom: 1px solid var(--_line);
170
+ cursor: move; user-select: none; touch-action: none;
171
+ }
172
+ .sc-modal-title {
173
+ flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
174
+ font-size: var(--_text-small); font-weight: 600;
175
+ }
176
+ .sc-modal-body { flex: 1; min-height: 0; overflow: auto; container-type: inline-size; }
177
+
178
+ /* A phone: one screen. The drawer is the screen's width, the modal a sheet from the bottom. */
179
+ .sc-root[data-phone] .sc-peek { width: 100%; border-left: 0; border-radius: 0; }
180
+ .sc-modal-scrim[data-phone] { align-items: flex-end; padding: 0; }
181
+ .sc-modal-scrim[data-phone] .sc-modal {
182
+ width: 100%; max-height: 90%; border-bottom: 0;
183
+ border-radius: var(--_radius) var(--_radius) 0 0;
184
+ }
185
+ .sc-modal-scrim[data-phone] .sc-modal-head { cursor: default; }
186
+ .sc-dock {
187
+ display: flex; flex-shrink: 0; align-items: center; gap: 6px; padding: 6px 8px;
188
+ overflow-x: auto; background: var(--_ground); border-top: 1px solid var(--_line);
189
+ }
190
+ .sc-dock-label { flex-shrink: 0; color: var(--_muted); font-size: var(--_text-small); }
191
+
146
192
  .sc-button {
147
193
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
148
194
  border: 1px solid var(--_line-strong); border-radius: var(--_radius-control);
@@ -17,7 +17,12 @@ export type Target = {
17
17
  panelId: string;
18
18
  } | {
19
19
  surface: typeof Surface.Peek;
20
+ } | {
21
+ surface: typeof Surface.Modal;
22
+ host: string;
20
23
  };
24
+ /** The other way: the target of a surface the workspace knows by `id` — the focus, say. */
25
+ export declare function targetOf(id: string): Target;
21
26
  export type ApiFactory = {
22
27
  for: (resource: ResourceRef, target: Target) => WorkspaceApi;
23
28
  /** Zone to open into when nobody asks: the one the domain prefers. */
@@ -32,5 +37,8 @@ export type ApiFactoryOptions = {
32
37
  registry?: Registry;
33
38
  /** Where `open(ref)` goes without a `to`. The page: what people expect of a click. */
34
39
  defaultOpen?: Destination;
40
+ /** Whether the workspace is a phone right now — read at call time. On a phone a window or a
41
+ * side panel opens as the page, and a chooser as a modal (`domain/phone.ts`). */
42
+ isPhone?: () => boolean;
35
43
  };
36
- export declare function createApiFactory(store: WorkspaceStore, { registry, defaultOpen }?: ApiFactoryOptions): ApiFactory;
44
+ export declare function createApiFactory(store: WorkspaceStore, { registry, defaultOpen, isPhone }?: ApiFactoryOptions): ApiFactory;