@sincpro/web-composer 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +198 -2
- package/dist/domain/enums.d.ts +65 -0
- package/dist/domain/enums.js +56 -0
- package/dist/domain/index.d.ts +9 -0
- package/dist/domain/index.js +8 -0
- package/dist/domain/layout.d.ts +75 -0
- package/dist/domain/layout.js +180 -0
- package/dist/domain/palette.d.ts +42 -0
- package/dist/domain/palette.js +89 -0
- package/dist/domain/registry.d.ts +112 -0
- package/dist/domain/registry.js +37 -0
- package/dist/domain/resource.d.ts +21 -0
- package/dist/domain/resource.js +62 -0
- package/dist/domain/url.d.ts +3 -0
- package/dist/domain/url.js +107 -0
- package/dist/domain/workspace.d.ts +138 -0
- package/dist/domain/workspace.js +272 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +19 -0
- package/dist/shell/Composer.d.ts +24 -0
- package/dist/shell/Composer.js +59 -0
- package/dist/shell/Palette.d.ts +9 -0
- package/dist/shell/Palette.js +123 -0
- package/dist/shell/PanelFrame.d.ts +31 -0
- package/dist/shell/PanelFrame.js +44 -0
- package/dist/shell/PanelHost.d.ts +23 -0
- package/dist/shell/PanelHost.js +188 -0
- package/dist/shell/RecordLink.d.ts +12 -0
- package/dist/shell/RecordLink.js +51 -0
- package/dist/shell/ViewHost.d.ts +11 -0
- package/dist/shell/ViewHost.js +42 -0
- package/dist/shell/copy.d.ts +64 -0
- package/dist/shell/copy.js +108 -0
- package/dist/state/api.d.ts +32 -0
- package/dist/state/api.js +140 -0
- package/dist/state/drag.d.ts +31 -0
- package/dist/state/drag.js +95 -0
- package/dist/state/store.d.ts +45 -0
- package/dist/state/store.js +76 -0
- package/dist/state/useKeyboard.d.ts +12 -0
- package/dist/state/useKeyboard.js +55 -0
- package/dist/state/useWorkspace.d.ts +23 -0
- package/dist/state/useWorkspace.js +34 -0
- package/package.json +82 -4
|
@@ -0,0 +1,188 @@
|
|
|
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";
|
|
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
|
+
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) };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A drag that follows the pointer until it is released, wherever it goes. The listeners live on
|
|
19
|
+
* `window`, so leaving the header — or the iframe — does not drop the gesture; pointer capture is
|
|
20
|
+
* only a bonus, because Chrome refuses it for a pointer it no longer tracks («No active pointer
|
|
21
|
+
* with the given id») and a refusal must not cancel the move — that was the window that would
|
|
22
|
+
* not budge.
|
|
23
|
+
*/
|
|
24
|
+
function useDrag(hostRef) {
|
|
25
|
+
return useCallback((e, move) => {
|
|
26
|
+
const host = hostRef.current?.getBoundingClientRect();
|
|
27
|
+
if (host === undefined || e.button !== 0)
|
|
28
|
+
return;
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
const target = e.currentTarget;
|
|
31
|
+
try {
|
|
32
|
+
target.setPointerCapture(e.pointerId);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* Not captured: the window listeners below still follow the pointer. */
|
|
36
|
+
}
|
|
37
|
+
const onMove = (ev) => move(host, ev);
|
|
38
|
+
const stop = () => {
|
|
39
|
+
window.removeEventListener("pointermove", onMove);
|
|
40
|
+
window.removeEventListener("pointerup", stop);
|
|
41
|
+
window.removeEventListener("pointercancel", stop);
|
|
42
|
+
window.removeEventListener("blur", stop);
|
|
43
|
+
};
|
|
44
|
+
window.addEventListener("pointermove", onMove);
|
|
45
|
+
window.addEventListener("pointerup", stop);
|
|
46
|
+
window.addEventListener("pointercancel", stop);
|
|
47
|
+
window.addEventListener("blur", stop);
|
|
48
|
+
}, [hostRef]);
|
|
49
|
+
}
|
|
50
|
+
const handleLabel = (handle, copy) => handle.kind === HandleKind.Zone ? copy.resizeZone(handle.zone) : copy.resizeBetween;
|
|
51
|
+
function ResizeHandle({ handle, value, onDrag, onStep, }) {
|
|
52
|
+
const horizontal = handle.axis === Axis.X;
|
|
53
|
+
const copy = composerCopy().panel;
|
|
54
|
+
function onKeyDown(e) {
|
|
55
|
+
const minus = horizontal ? "ArrowLeft" : "ArrowUp";
|
|
56
|
+
const plus = horizontal ? "ArrowRight" : "ArrowDown";
|
|
57
|
+
if (e.key !== minus && e.key !== plus)
|
|
58
|
+
return;
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
onStep(handle, (e.key === plus ? 1 : -1) * (handle.invert ? -1 : 1) * KEYBOARD_STEP);
|
|
61
|
+
}
|
|
62
|
+
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
|
+
? {
|
|
64
|
+
left: `calc(${handle.at * 100}% - ${HANDLE_THICKNESS / 2}px)`,
|
|
65
|
+
top: 0,
|
|
66
|
+
width: HANDLE_THICKNESS,
|
|
67
|
+
height: "100%",
|
|
68
|
+
touchAction: "none",
|
|
69
|
+
}
|
|
70
|
+
: {
|
|
71
|
+
top: `calc(${handle.at * 100}% - ${HANDLE_THICKNESS / 2}px)`,
|
|
72
|
+
left: 0,
|
|
73
|
+
height: HANDLE_THICKNESS,
|
|
74
|
+
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"}` }));
|
|
77
|
+
}
|
|
78
|
+
/** The three grips of a window: right edge, bottom edge, and the corner. */
|
|
79
|
+
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 },
|
|
83
|
+
];
|
|
84
|
+
function ZoneDropTarget({ zone, style, label, armed, }) {
|
|
85
|
+
const box = useRef(null);
|
|
86
|
+
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 }));
|
|
88
|
+
}
|
|
89
|
+
/** Targets cover the container edges, not the live zone boxes — dropping «to the left» has to
|
|
90
|
+
* work even when that zone has no panel yet. */
|
|
91
|
+
const DROP_ZONES = [
|
|
92
|
+
{
|
|
93
|
+
zone: Zone.Left,
|
|
94
|
+
label: "dropLeft",
|
|
95
|
+
style: { left: 0, top: 0, width: "24%", height: "100%" },
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
zone: Zone.Right,
|
|
99
|
+
label: "dropRight",
|
|
100
|
+
style: { right: 0, top: 0, width: "24%", height: "100%" },
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
zone: Zone.Bottom,
|
|
104
|
+
label: "dropBottom",
|
|
105
|
+
style: { left: "24%", right: "24%", bottom: 0, height: "30%" },
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
export function PanelHost({ workspace, overlay, registry, store, api }) {
|
|
109
|
+
const hostRef = useRef(null);
|
|
110
|
+
const drag = useDrag(hostRef);
|
|
111
|
+
const dropArmed = usePanelDragArmed();
|
|
112
|
+
const copy = composerCopy().panel;
|
|
113
|
+
const slots = layout(workspace);
|
|
114
|
+
const resizeHandles = handles(workspace);
|
|
115
|
+
const valueOf = (handle) => {
|
|
116
|
+
if (handle.kind === HandleKind.Zone)
|
|
117
|
+
return workspace.zones[handle.zone];
|
|
118
|
+
const panel = workspace.panels.find((p) => p.id === handle.panelId);
|
|
119
|
+
return panel !== undefined && panel.placement.zone !== Zone.Floating
|
|
120
|
+
? panel.placement.share
|
|
121
|
+
: 0;
|
|
122
|
+
};
|
|
123
|
+
const applyHandle = (handle, value) => {
|
|
124
|
+
if (handle.kind === HandleKind.Zone)
|
|
125
|
+
store.resizeZone(handle.zone, value);
|
|
126
|
+
else
|
|
127
|
+
store.resizePanel(handle.panelId, value);
|
|
128
|
+
};
|
|
129
|
+
function moveWindow(e, slot) {
|
|
130
|
+
if (slot.box.unit !== BoxUnit.Pixel)
|
|
131
|
+
return;
|
|
132
|
+
const { left, top, width } = slot.box;
|
|
133
|
+
const start = { x: e.clientX, y: e.clientY };
|
|
134
|
+
store.raisePanel(slot.id);
|
|
135
|
+
drag(e, (host, ev) => {
|
|
136
|
+
store.floatPanel(slot.id, {
|
|
137
|
+
x: Math.max(KEEP_VISIBLE - width, Math.min(left + ev.clientX - start.x, host.width - KEEP_VISIBLE)),
|
|
138
|
+
y: Math.max(0, Math.min(top + ev.clientY - start.y, host.height - KEEP_VISIBLE / 2)),
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function resizeWindow(e, slot, dx, dy) {
|
|
143
|
+
if (slot.box.unit !== BoxUnit.Pixel)
|
|
144
|
+
return;
|
|
145
|
+
const { width, height } = slot.box;
|
|
146
|
+
const start = { x: e.clientX, y: e.clientY };
|
|
147
|
+
e.stopPropagation();
|
|
148
|
+
drag(e, (_host, ev) => {
|
|
149
|
+
store.floatPanel(slot.id, {
|
|
150
|
+
...(dx === 0 ? {} : { w: Math.max(MIN_WINDOW.w, width + ev.clientX - start.x) }),
|
|
151
|
+
...(dy === 0 ? {} : { h: Math.max(MIN_WINDOW.h, height + ev.clientY - start.y) }),
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function moveHandle(e, handle) {
|
|
156
|
+
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));
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return (_jsxs("div", { ref: hostRef, className: "relative min-h-0 flex-1 overflow-hidden", children: [stableOrder(slots).map((slot) => {
|
|
164
|
+
const isPage = slot.id === PAGE;
|
|
165
|
+
const style = {
|
|
166
|
+
...boxStyle(slot.box),
|
|
167
|
+
...(slot.floating ? { zIndex: 20 + slot.z } : {}),
|
|
168
|
+
};
|
|
169
|
+
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));
|
|
171
|
+
}
|
|
172
|
+
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: {
|
|
174
|
+
onMove: (z) => store.movePanel(slot.id, z),
|
|
175
|
+
onCollapse: () => store.collapsePanel(slot.id),
|
|
176
|
+
onExpand: () => store.expandPanel(slot.id),
|
|
177
|
+
onClose: () => store.closePanel(slot.id),
|
|
178
|
+
}, 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)))
|
|
180
|
+
: 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}`)))] }));
|
|
188
|
+
}
|
|
@@ -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,51 @@
|
|
|
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 { useDraggableRef } from "../state/drag.js";
|
|
5
|
+
import { AppWindow, Eye, PanelRight } from "lucide-react";
|
|
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: Eye, label: "peek" },
|
|
22
|
+
{ to: Destination.Side, icon: PanelRight, label: "side" },
|
|
23
|
+
{ to: Destination.Window, icon: AppWindow, label: "window" },
|
|
24
|
+
];
|
|
25
|
+
export function RecordLink({ api, resource, to, compact = false, children, }) {
|
|
26
|
+
const copy = composerCopy().link;
|
|
27
|
+
const box = useRef(null);
|
|
28
|
+
const dragging = useDraggableRef(box, resource);
|
|
29
|
+
/* The name sits inside a row that has its own click (open, peek). Whatever this control
|
|
30
|
+
does, the row must not do it too. */
|
|
31
|
+
function onClick(e) {
|
|
32
|
+
e.stopPropagation();
|
|
33
|
+
if (e.metaKey || e.ctrlKey)
|
|
34
|
+
api.open(resource, { to: Destination.Window });
|
|
35
|
+
else if (e.shiftKey)
|
|
36
|
+
api.open(resource, { to: Destination.Side });
|
|
37
|
+
else
|
|
38
|
+
api.open(resource, to === undefined ? {} : { to });
|
|
39
|
+
}
|
|
40
|
+
function onKeyDown(e) {
|
|
41
|
+
if (e.key !== " ")
|
|
42
|
+
return;
|
|
43
|
+
api.open(resource, { to: Destination.Peek });
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
}
|
|
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))) }))] }));
|
|
51
|
+
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { formatRef, loadView, } from "../domain/index.js";
|
|
3
|
+
import { composerCopy } from "./copy.js";
|
|
4
|
+
import { ICONO_ROTO, Missing } from "@sincpro/web-ui";
|
|
5
|
+
import { Component, lazy, memo, Suspense, useMemo, } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* The only thing that turns a reference into pixels. Resolves against the
|
|
8
|
+
* registry, isolates failure, and lends the navigation API — the view never
|
|
9
|
+
* receives workspace state, or two domains would couple through it.
|
|
10
|
+
*
|
|
11
|
+
* Three distinct states because each one is someone else's job: unregistered
|
|
12
|
+
* is wiring, loading is normal, broken is a domain bug.
|
|
13
|
+
*/
|
|
14
|
+
class ErrorBoundary extends Component {
|
|
15
|
+
state = { error: null };
|
|
16
|
+
static getDerivedStateFromError(error) {
|
|
17
|
+
return { error };
|
|
18
|
+
}
|
|
19
|
+
componentDidCatch(error, info) {
|
|
20
|
+
console.error(`[view ${this.props.name}] failed to render`, error, info.componentStack);
|
|
21
|
+
}
|
|
22
|
+
componentDidUpdate(prev) {
|
|
23
|
+
if (prev.name !== this.props.name && this.state.error !== null) {
|
|
24
|
+
this.setState({ error: null });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
render() {
|
|
28
|
+
if (this.state.error === null)
|
|
29
|
+
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}` }));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function Host({ resource, registry, api, fallback }) {
|
|
34
|
+
const key = formatRef(resource);
|
|
35
|
+
const spec = registry.resolve(resource);
|
|
36
|
+
const View = useMemo(() => (spec === null ? null : lazy(async () => ({ default: await loadView(spec) }))), [spec]);
|
|
37
|
+
if (spec === null || View === null) {
|
|
38
|
+
return (_jsx(Missing, { heading: composerCopy().view.unresolved, detail: `${key} — is the «${resource.domain}» domain missing from the registry?` }));
|
|
39
|
+
}
|
|
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) }) }));
|
|
41
|
+
}
|
|
42
|
+
export const ViewHost = memo(Host);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every word the composer draws, in one table — the way `@sincpro/web-ui` does it. English by
|
|
3
|
+
* default; an application installs its language ONCE with `installComposerCopy`, next to the
|
|
4
|
+
* design system's `installCopy`, and no component carries a hard-coded string.
|
|
5
|
+
*/
|
|
6
|
+
export type ComposerCopy = {
|
|
7
|
+
panel: {
|
|
8
|
+
more: string;
|
|
9
|
+
moveTo: string;
|
|
10
|
+
left: string;
|
|
11
|
+
leftHint: string;
|
|
12
|
+
right: string;
|
|
13
|
+
rightHint: string;
|
|
14
|
+
bottom: string;
|
|
15
|
+
bottomHint: string;
|
|
16
|
+
window: string;
|
|
17
|
+
windowHint: string;
|
|
18
|
+
expand: string;
|
|
19
|
+
minimize: string;
|
|
20
|
+
restore: string;
|
|
21
|
+
enlarge: string;
|
|
22
|
+
close: string;
|
|
23
|
+
resizeZone: (zone: string) => string;
|
|
24
|
+
resizeBetween: string;
|
|
25
|
+
dropLeft: string;
|
|
26
|
+
dropRight: string;
|
|
27
|
+
dropBottom: string;
|
|
28
|
+
};
|
|
29
|
+
peek: {
|
|
30
|
+
openAsPage: string;
|
|
31
|
+
};
|
|
32
|
+
link: {
|
|
33
|
+
peek: string;
|
|
34
|
+
side: string;
|
|
35
|
+
window: string;
|
|
36
|
+
};
|
|
37
|
+
view: {
|
|
38
|
+
failed: string;
|
|
39
|
+
unresolved: string;
|
|
40
|
+
loading: (domain: string) => string;
|
|
41
|
+
};
|
|
42
|
+
palette: {
|
|
43
|
+
label: string;
|
|
44
|
+
placeholder: string;
|
|
45
|
+
sections: {
|
|
46
|
+
actions: string;
|
|
47
|
+
goto: string;
|
|
48
|
+
found: string;
|
|
49
|
+
};
|
|
50
|
+
empty: string;
|
|
51
|
+
searching: string;
|
|
52
|
+
hint: string;
|
|
53
|
+
};
|
|
54
|
+
shortcuts: readonly {
|
|
55
|
+
keys: string;
|
|
56
|
+
action: string;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
export declare const ENGLISH_COMPOSER_COPY: ComposerCopy;
|
|
60
|
+
export declare const SPANISH_COMPOSER_COPY: ComposerCopy;
|
|
61
|
+
/** Install the composer's words once, where the application starts. */
|
|
62
|
+
export declare function installComposerCopy(copy: ComposerCopy): void;
|
|
63
|
+
/** The words in use. A plain read: they are installed before anything draws. */
|
|
64
|
+
export declare const composerCopy: () => ComposerCopy;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every word the composer draws, in one table — the way `@sincpro/web-ui` does it. English by
|
|
3
|
+
* default; an application installs its language ONCE with `installComposerCopy`, next to the
|
|
4
|
+
* design system's `installCopy`, and no component carries a hard-coded string.
|
|
5
|
+
*/
|
|
6
|
+
export const ENGLISH_COMPOSER_COPY = {
|
|
7
|
+
panel: {
|
|
8
|
+
more: "More",
|
|
9
|
+
moveTo: "move to",
|
|
10
|
+
left: "To the left",
|
|
11
|
+
leftHint: "docked to the left edge",
|
|
12
|
+
right: "To the right",
|
|
13
|
+
rightHint: "docked to the right edge",
|
|
14
|
+
bottom: "To the bottom",
|
|
15
|
+
bottomHint: "docked to the foot",
|
|
16
|
+
window: "Window",
|
|
17
|
+
windowHint: "floating; drag it by the title",
|
|
18
|
+
expand: "Expand to a page",
|
|
19
|
+
minimize: "Minimize",
|
|
20
|
+
restore: "Restore",
|
|
21
|
+
enlarge: "Enlarge",
|
|
22
|
+
close: "Close",
|
|
23
|
+
resizeZone: (zone) => `Resize the ${zone} zone`,
|
|
24
|
+
resizeBetween: "Resize between two panels",
|
|
25
|
+
dropLeft: "to the left",
|
|
26
|
+
dropRight: "to the right",
|
|
27
|
+
dropBottom: "to the bottom",
|
|
28
|
+
},
|
|
29
|
+
peek: { openAsPage: "Open as page" },
|
|
30
|
+
link: { peek: "Peek", side: "Open beside", window: "Open in a window" },
|
|
31
|
+
view: {
|
|
32
|
+
failed: "This view failed to render",
|
|
33
|
+
unresolved: "Nobody can resolve this reference",
|
|
34
|
+
loading: (domain) => `loading ${domain}…`,
|
|
35
|
+
},
|
|
36
|
+
palette: {
|
|
37
|
+
label: "Command palette",
|
|
38
|
+
placeholder: "Go to, search, or act on what you are on…",
|
|
39
|
+
sections: { actions: "Do", goto: "Go to", found: "Found" },
|
|
40
|
+
empty: "Nothing matches",
|
|
41
|
+
searching: "searching…",
|
|
42
|
+
hint: "↵ page · ⌥↵ peek · ⇧↵ beside · ⌘↵ window · esc close",
|
|
43
|
+
},
|
|
44
|
+
shortcuts: [
|
|
45
|
+
{ keys: "⌘K", action: "go to, search, or act on what you are on" },
|
|
46
|
+
{ keys: "⌥←", action: "one page back" },
|
|
47
|
+
{ keys: "⌘⌥[ / ⌘⌥]", action: "move focus between the page and the panels" },
|
|
48
|
+
{ keys: "⌘⇧⏎", action: "maximize the focused surface, or restore it" },
|
|
49
|
+
{ keys: "⌘⇧⌫", action: "close the focused panel" },
|
|
50
|
+
{ keys: "Esc", action: "close the peek, or restore the maximized view" },
|
|
51
|
+
{ keys: "← → on a handle", action: "resize without the mouse" },
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
export const SPANISH_COMPOSER_COPY = {
|
|
55
|
+
panel: {
|
|
56
|
+
more: "Más",
|
|
57
|
+
moveTo: "mover a",
|
|
58
|
+
left: "A la izquierda",
|
|
59
|
+
leftHint: "acoplado al borde izquierdo",
|
|
60
|
+
right: "A la derecha",
|
|
61
|
+
rightHint: "acoplado al borde derecho",
|
|
62
|
+
bottom: "Abajo",
|
|
63
|
+
bottomHint: "acoplado al pie",
|
|
64
|
+
window: "Ventana",
|
|
65
|
+
windowHint: "flotante; se arrastra por el título",
|
|
66
|
+
expand: "Agrandar a página",
|
|
67
|
+
minimize: "Minimizar",
|
|
68
|
+
restore: "Restaurar",
|
|
69
|
+
enlarge: "Maximizar",
|
|
70
|
+
close: "Cerrar",
|
|
71
|
+
resizeZone: (zone) => `Redimensionar la zona ${{ left: "izquierda", right: "derecha", bottom: "inferior" }[zone] ?? zone}`,
|
|
72
|
+
resizeBetween: "Redimensionar entre dos paneles",
|
|
73
|
+
dropLeft: "a la izquierda",
|
|
74
|
+
dropRight: "a la derecha",
|
|
75
|
+
dropBottom: "abajo",
|
|
76
|
+
},
|
|
77
|
+
peek: { openAsPage: "Abrir como página" },
|
|
78
|
+
link: { peek: "Vistazo", side: "Abrir al lado", window: "Abrir en una ventana" },
|
|
79
|
+
view: {
|
|
80
|
+
failed: "Esta vista no se pudo dibujar",
|
|
81
|
+
unresolved: "Nadie sabe resolver esta referencia",
|
|
82
|
+
loading: (domain) => `cargando ${domain}…`,
|
|
83
|
+
},
|
|
84
|
+
palette: {
|
|
85
|
+
label: "Paleta de comandos",
|
|
86
|
+
placeholder: "Ir a, buscar o actuar sobre lo que miras…",
|
|
87
|
+
sections: { actions: "Hacer", goto: "Ir a", found: "Encontrado" },
|
|
88
|
+
empty: "Nada coincide",
|
|
89
|
+
searching: "buscando…",
|
|
90
|
+
hint: "↵ página · ⌥↵ vistazo · ⇧↵ al lado · ⌘↵ ventana · esc cerrar",
|
|
91
|
+
},
|
|
92
|
+
shortcuts: [
|
|
93
|
+
{ keys: "⌘K", action: "ir a, buscar o actuar sobre lo que miras" },
|
|
94
|
+
{ keys: "⌥←", action: "una página atrás" },
|
|
95
|
+
{ keys: "⌘⌥[ / ⌘⌥]", action: "mover el foco entre la página y los paneles" },
|
|
96
|
+
{ keys: "⌘⇧⏎", action: "maximizar la superficie con foco, o restaurarla" },
|
|
97
|
+
{ keys: "⌘⇧⌫", action: "cerrar el panel con foco" },
|
|
98
|
+
{ keys: "Esc", action: "cerrar el vistazo, o restaurar la vista maximizada" },
|
|
99
|
+
{ keys: "← → en un divisor", action: "redimensionar sin el mouse" },
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
let installed = ENGLISH_COMPOSER_COPY;
|
|
103
|
+
/** Install the composer's words once, where the application starts. */
|
|
104
|
+
export function installComposerCopy(copy) {
|
|
105
|
+
installed = copy;
|
|
106
|
+
}
|
|
107
|
+
/** The words in use. A plain read: they are installed before anything draws. */
|
|
108
|
+
export const composerCopy = () => installed;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Destination, type Registry, type ResourceRef, Surface, type ViewSpec, type WorkspaceApi, Zone } from "../domain/index.js";
|
|
2
|
+
import type { WorkspaceStore } from "./store.js";
|
|
3
|
+
/**
|
|
4
|
+
* The API each view receives is built once per surface and kept. Recreating it on every
|
|
5
|
+
* workspace change swapped the prop on every mounted view, so moving one panel redrew the
|
|
6
|
+
* other five.
|
|
7
|
+
*
|
|
8
|
+
* Anything that needs current state reads it with `store.get()` at call time, never captured —
|
|
9
|
+
* that is what lets the object stay stable without going stale.
|
|
10
|
+
*/
|
|
11
|
+
export type Target = {
|
|
12
|
+
surface: typeof Surface.Page;
|
|
13
|
+
} | {
|
|
14
|
+
surface: typeof Surface.Panel;
|
|
15
|
+
panelId: string;
|
|
16
|
+
} | {
|
|
17
|
+
surface: typeof Surface.Peek;
|
|
18
|
+
};
|
|
19
|
+
export type ApiFactory = {
|
|
20
|
+
for: (resource: ResourceRef, target: Target) => WorkspaceApi;
|
|
21
|
+
/** Zone to open into when nobody asks: the one the domain prefers. */
|
|
22
|
+
zoneFor: (spec: ViewSpec | null) => Zone;
|
|
23
|
+
/** Stops listening to the store. Call it when the workspace goes away. */
|
|
24
|
+
dispose: () => void;
|
|
25
|
+
};
|
|
26
|
+
export type ApiFactoryOptions = {
|
|
27
|
+
/** Gives the breadcrumb its titles and `open(ref, { to: "side" })` the zone a domain prefers. */
|
|
28
|
+
registry?: Registry;
|
|
29
|
+
/** Where `open(ref)` goes without a `to`. The page: what people expect of a click. */
|
|
30
|
+
defaultOpen?: Destination;
|
|
31
|
+
};
|
|
32
|
+
export declare function createApiFactory(store: WorkspaceStore, { registry, defaultOpen }?: ApiFactoryOptions): ApiFactory;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as model from "../domain/index.js";
|
|
2
|
+
import { Destination, formatRef, PAGE, Surface, Zone, } from "../domain/index.js";
|
|
3
|
+
const cacheKey = (target) => target.surface === Surface.Panel ? `${Surface.Panel}:${target.panelId}` : target.surface;
|
|
4
|
+
export function createApiFactory(store, { registry, defaultOpen = Destination.Page } = {}) {
|
|
5
|
+
const cache = new Map();
|
|
6
|
+
const choosers = new Map();
|
|
7
|
+
const zoneFor = (spec) => spec?.preferredZone ?? Zone.Right;
|
|
8
|
+
const titleOf = (ref) => registry?.resolve(ref)?.title(ref) ?? formatRef(ref);
|
|
9
|
+
/* A chooser whose panel is gone is forgotten, and so is a cached API of a surface that no
|
|
10
|
+
longer exists — or every panel ever opened would stay in memory. */
|
|
11
|
+
const stop = store.subscribe(() => {
|
|
12
|
+
const w = store.get();
|
|
13
|
+
for (const id of choosers.keys()) {
|
|
14
|
+
if (id !== `${PAGE}:peek` && model.findPanel(w, id) === null)
|
|
15
|
+
choosers.delete(id);
|
|
16
|
+
}
|
|
17
|
+
for (const key of cache.keys()) {
|
|
18
|
+
const id = key.startsWith(`${Surface.Panel}:`)
|
|
19
|
+
? key.slice(Surface.Panel.length + 1)
|
|
20
|
+
: null;
|
|
21
|
+
if (id !== null && model.findPanel(w, id) === null)
|
|
22
|
+
cache.delete(key);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const context = {
|
|
26
|
+
focused: () => model.focusedRef(store.get()),
|
|
27
|
+
selection: () => model.selectionOf(store.get()),
|
|
28
|
+
subscribe: store.subscribe,
|
|
29
|
+
};
|
|
30
|
+
function build(resource, target) {
|
|
31
|
+
const me = target.surface === Surface.Panel ? target.panelId : PAGE;
|
|
32
|
+
function openSide(ref, zone) {
|
|
33
|
+
store.openPanel(ref, zone);
|
|
34
|
+
}
|
|
35
|
+
function open(ref, to) {
|
|
36
|
+
if (to === Destination.Peek)
|
|
37
|
+
store.peek(ref);
|
|
38
|
+
else if (to === Destination.Window)
|
|
39
|
+
openSide(ref, Zone.Floating);
|
|
40
|
+
else if (to === Destination.Side)
|
|
41
|
+
openSide(ref, zoneFor(registry?.resolve(ref) ?? null));
|
|
42
|
+
else if (target.surface === Surface.Peek) {
|
|
43
|
+
store.closePeek();
|
|
44
|
+
store.push(ref);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
store.push(ref);
|
|
48
|
+
}
|
|
49
|
+
const api = {
|
|
50
|
+
self: resource,
|
|
51
|
+
surface: target.surface,
|
|
52
|
+
context,
|
|
53
|
+
open: (ref, options) => open(ref, options?.to ?? defaultOpen),
|
|
54
|
+
navigate: (to) => {
|
|
55
|
+
if (target.surface === Surface.Panel)
|
|
56
|
+
store.navigatePanel(target.panelId, to);
|
|
57
|
+
else if (target.surface === Surface.Peek)
|
|
58
|
+
store.peek(to);
|
|
59
|
+
else
|
|
60
|
+
store.apply((w) => model.push(w, to));
|
|
61
|
+
},
|
|
62
|
+
back: () => {
|
|
63
|
+
if (target.surface === Surface.Page)
|
|
64
|
+
store.back();
|
|
65
|
+
},
|
|
66
|
+
expand: () => {
|
|
67
|
+
if (target.surface === Surface.Panel)
|
|
68
|
+
store.expandPanel(target.panelId);
|
|
69
|
+
else if (target.surface === Surface.Peek)
|
|
70
|
+
store.peekToPage();
|
|
71
|
+
},
|
|
72
|
+
close: () => {
|
|
73
|
+
if (target.surface === Surface.Panel)
|
|
74
|
+
store.closePanel(target.panelId);
|
|
75
|
+
else if (target.surface === Surface.Peek)
|
|
76
|
+
store.closePeek();
|
|
77
|
+
},
|
|
78
|
+
focus: () => store.focusPanel(me),
|
|
79
|
+
crumbs: () => {
|
|
80
|
+
/* A panel, a window or the peek already carry the record's name in their frame: a
|
|
81
|
+
breadcrumb of one would only repeat it. The way back belongs to the page. */
|
|
82
|
+
if (target.surface !== Surface.Page)
|
|
83
|
+
return [];
|
|
84
|
+
const w = store.get();
|
|
85
|
+
return [
|
|
86
|
+
...w.trail.map((past, i) => ({
|
|
87
|
+
label: titleOf(past),
|
|
88
|
+
onClick: () => store.goTo(i),
|
|
89
|
+
})),
|
|
90
|
+
{ label: titleOf(w.page ?? api.self) },
|
|
91
|
+
];
|
|
92
|
+
},
|
|
93
|
+
select: (refs) => store.apply((w) => model.select(w, me, refs)),
|
|
94
|
+
pick: (ref, onPick, options) => {
|
|
95
|
+
const to = options?.to ?? Destination.Window;
|
|
96
|
+
if (to === Destination.Peek) {
|
|
97
|
+
store.peek(ref);
|
|
98
|
+
choosers.set(PAGE + ":peek", onPick);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
open(ref, to);
|
|
102
|
+
const id = store.get().focus;
|
|
103
|
+
if (id !== PAGE)
|
|
104
|
+
choosers.set(id, onPick);
|
|
105
|
+
},
|
|
106
|
+
answer: (value) => {
|
|
107
|
+
const key = target.surface === Surface.Peek ? `${PAGE}:peek` : me;
|
|
108
|
+
const onPick = choosers.get(key);
|
|
109
|
+
if (onPick === undefined)
|
|
110
|
+
return;
|
|
111
|
+
/* Forget it BEFORE closing, so closing is not mistaken for anything else. */
|
|
112
|
+
choosers.delete(key);
|
|
113
|
+
onPick(value);
|
|
114
|
+
if (target.surface === Surface.Peek)
|
|
115
|
+
store.closePeek();
|
|
116
|
+
else if (target.surface === Surface.Panel)
|
|
117
|
+
store.closePanel(target.panelId);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
return api;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
for: (resource, target) => {
|
|
124
|
+
const key = cacheKey(target);
|
|
125
|
+
const cached = cache.get(key);
|
|
126
|
+
if (cached === undefined) {
|
|
127
|
+
const api = build(resource, target);
|
|
128
|
+
cache.set(key, { resource, api });
|
|
129
|
+
return api;
|
|
130
|
+
}
|
|
131
|
+
if (cached.resource !== resource) {
|
|
132
|
+
cached.api.self = resource;
|
|
133
|
+
cached.resource = resource;
|
|
134
|
+
}
|
|
135
|
+
return cached.api;
|
|
136
|
+
},
|
|
137
|
+
zoneFor,
|
|
138
|
+
dispose: stop,
|
|
139
|
+
};
|
|
140
|
+
}
|