@slotform/react-ui 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 +44 -2
- package/dist/density.d.ts +4 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +8 -0
- package/dist/density.js.map +1 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/node/canvas.d.ts +3 -0
- package/dist/node/canvas.d.ts.map +1 -0
- package/dist/node/canvas.js +13 -0
- package/dist/node/canvas.js.map +1 -0
- package/dist/node/codegen.d.ts +6 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +70 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/css-escape.d.ts +8 -0
- package/dist/node/css-escape.d.ts.map +1 -0
- package/dist/node/css-escape.js +12 -0
- package/dist/node/css-escape.js.map +1 -0
- package/dist/node/fonts.d.ts +6 -0
- package/dist/node/fonts.d.ts.map +1 -0
- package/dist/node/fonts.js +219 -0
- package/dist/node/fonts.js.map +1 -0
- package/dist/node/lint.d.ts +3 -0
- package/dist/node/lint.d.ts.map +1 -0
- package/dist/node/lint.js +23 -0
- package/dist/node/lint.js.map +1 -0
- package/dist/node/mode.d.ts +9 -0
- package/dist/node/mode.d.ts.map +1 -0
- package/dist/node/mode.js +38 -0
- package/dist/node/mode.js.map +1 -0
- package/dist/node/theme.d.ts +13 -0
- package/dist/node/theme.d.ts.map +1 -0
- package/dist/node/theme.js +160 -0
- package/dist/node/theme.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/guide/acts.md +61 -0
- package/guide/audio.md +77 -0
- package/guide/blocks.md +82 -0
- package/guide/canvas-choosing.md +34 -0
- package/guide/canvas-editing.md +36 -0
- package/guide/canvas-layout.md +46 -0
- package/guide/canvas-opening.md +47 -0
- package/guide/canvas-overview.md +24 -0
- package/guide/canvas-states.md +37 -0
- package/guide/canvas-view.md +46 -0
- package/guide/canvas.md +94 -0
- package/guide/containers.md +60 -0
- package/guide/content.md +40 -0
- package/guide/controls.md +89 -0
- package/guide/density.md +48 -0
- package/guide/dock.md +42 -0
- package/guide/drag.md +38 -0
- package/guide/figures.md +25 -0
- package/guide/forms.md +82 -0
- package/guide/pane-bar.md +11 -0
- package/guide/pane.md +50 -0
- package/guide/reference.md +74 -0
- package/guide/rules.md +109 -0
- package/guide/section.md +29 -0
- package/guide/shell.md +26 -0
- package/guide/shots.md +37 -0
- package/guide/sidebar.md +30 -0
- package/guide/table.md +119 -0
- package/lint/no-arbitrary-value.grit +9 -0
- package/lint/no-class-on-component.grit +12 -0
- package/lint/no-density.grit +8 -0
- package/lint/no-host-look.grit +38 -0
- package/lint/no-img.grit +10 -0
- package/lint/no-navigate-act.grit +22 -0
- package/lint/no-raw-style.grit +8 -0
- package/package.json +150 -3
- package/src/density.ts +9 -0
- package/src/index.ts +503 -0
- package/src/node/canvas.ts +14 -0
- package/src/node/codegen.ts +100 -0
- package/src/node/css-escape.ts +27 -0
- package/src/node/fonts.ts +260 -0
- package/src/node/lint.ts +25 -0
- package/src/node/mode.ts +64 -0
- package/src/node/theme.ts +232 -0
- package/src/types.ts +120 -0
- package/src/ui/atoms/avatar/base.tsx +42 -0
- package/src/ui/atoms/button/glyph.tsx +244 -0
- package/src/ui/atoms/button/link.tsx +81 -0
- package/src/ui/atoms/button/look.ts +32 -0
- package/src/ui/atoms/button/reason.tsx +69 -0
- package/src/ui/atoms/chip/base.tsx +85 -0
- package/src/ui/atoms/count/base.tsx +27 -0
- package/src/ui/atoms/icon/index.tsx +51 -0
- package/src/ui/atoms/message/waiting.tsx +19 -0
- package/src/ui/atoms/prose/painted.tsx +35 -0
- package/src/ui/atoms/row/badges.tsx +226 -0
- package/src/ui/atoms/row/leading.tsx +166 -0
- package/src/ui/atoms/row/lock.tsx +17 -0
- package/src/ui/atoms/row/marks.tsx +79 -0
- package/src/ui/atoms/section/card.tsx +27 -0
- package/src/ui/atoms/spinner/index.tsx +42 -0
- package/src/ui/atoms/status/base.tsx +51 -0
- package/src/ui/atoms/status/change.tsx +29 -0
- package/src/ui/atoms/status/dot.tsx +45 -0
- package/src/ui/atoms/switch/checkbox.tsx +121 -0
- package/src/ui/atoms/turn.tsx +28 -0
- package/src/ui/components/action-bar/base.tsx +276 -0
- package/src/ui/components/action-bar/index.tsx +20 -0
- package/src/ui/components/avatar/index.tsx +21 -0
- package/src/ui/components/banner/index.tsx +207 -0
- package/src/ui/components/banner/pending.tsx +109 -0
- package/src/ui/components/bar-chart/index.tsx +701 -0
- package/src/ui/components/button/base.tsx +214 -0
- package/src/ui/components/button/face.tsx +84 -0
- package/src/ui/components/button/index.tsx +206 -0
- package/src/ui/components/canvas/connection.tsx +26 -0
- package/src/ui/components/canvas/edges.tsx +116 -0
- package/src/ui/components/canvas/elk.ts +260 -0
- package/src/ui/components/canvas/floor.ts +173 -0
- package/src/ui/components/canvas/geometry.ts +772 -0
- package/src/ui/components/canvas/ground.tsx +97 -0
- package/src/ui/components/canvas/group.tsx +156 -0
- package/src/ui/components/canvas/hit.ts +40 -0
- package/src/ui/components/canvas/index.tsx +497 -0
- package/src/ui/components/canvas/label.tsx +53 -0
- package/src/ui/components/canvas/layout.ts +543 -0
- package/src/ui/components/canvas/lift.ts +272 -0
- package/src/ui/components/canvas/look.ts +129 -0
- package/src/ui/components/canvas/node.tsx +689 -0
- package/src/ui/components/canvas/open.ts +243 -0
- package/src/ui/components/canvas/opening.ts +240 -0
- package/src/ui/components/canvas/view.ts +621 -0
- package/src/ui/components/canvas/viewport.ts +417 -0
- package/src/ui/components/canvas/zoom.tsx +113 -0
- package/src/ui/components/card/index.tsx +20 -0
- package/src/ui/components/chip/index.tsx +24 -0
- package/src/ui/components/code/frame.ts +2 -0
- package/src/ui/components/code/index.tsx +234 -0
- package/src/ui/components/columns/index.tsx +51 -0
- package/src/ui/components/count/index.tsx +17 -0
- package/src/ui/components/diff/index.tsx +249 -0
- package/src/ui/components/diff/word.tsx +104 -0
- package/src/ui/components/dock/index.tsx +262 -0
- package/src/ui/components/file-row/index.tsx +213 -0
- package/src/ui/components/form/base.tsx +280 -0
- package/src/ui/components/form/derive.tsx +269 -0
- package/src/ui/components/form/index.tsx +49 -0
- package/src/ui/components/form/saved.tsx +39 -0
- package/src/ui/components/form-field/index.tsx +658 -0
- package/src/ui/components/gallery/index.tsx +83 -0
- package/src/ui/components/gate/index.tsx +183 -0
- package/src/ui/components/image/base.tsx +245 -0
- package/src/ui/components/image/index.tsx +58 -0
- package/src/ui/components/input/base.tsx +246 -0
- package/src/ui/components/input/code.tsx +108 -0
- package/src/ui/components/input/drop.ts +37 -0
- package/src/ui/components/input/file.tsx +154 -0
- package/src/ui/components/input/index.tsx +132 -0
- package/src/ui/components/input/prose.tsx +107 -0
- package/src/ui/components/input/refusal.tsx +30 -0
- package/src/ui/components/item-header/base.tsx +410 -0
- package/src/ui/components/menu/base.tsx +319 -0
- package/src/ui/components/message/attachments.tsx +101 -0
- package/src/ui/components/message/base.tsx +266 -0
- package/src/ui/components/message-input/index.tsx +377 -0
- package/src/ui/components/missing/base.tsx +45 -0
- package/src/ui/components/pane/head.tsx +399 -0
- package/src/ui/components/pane/index.tsx +325 -0
- package/src/ui/components/picker/base.tsx +1551 -0
- package/src/ui/components/picker/index.tsx +224 -0
- package/src/ui/components/picker/list.tsx +423 -0
- package/src/ui/components/picker/segments.tsx +183 -0
- package/src/ui/components/prose/index.tsx +259 -0
- package/src/ui/components/qr-code/index.tsx +65 -0
- package/src/ui/components/row/acts.tsx +126 -0
- package/src/ui/components/row/fact.tsx +54 -0
- package/src/ui/components/row/index.tsx +1370 -0
- package/src/ui/components/row/progress.tsx +38 -0
- package/src/ui/components/row/status.tsx +54 -0
- package/src/ui/components/row/title.ts +7 -0
- package/src/ui/components/rules/index.tsx +290 -0
- package/src/ui/components/section/band.tsx +39 -0
- package/src/ui/components/section/head.tsx +267 -0
- package/src/ui/components/section/index.tsx +409 -0
- package/src/ui/components/section/rows.tsx +356 -0
- package/src/ui/components/sheet/base.tsx +272 -0
- package/src/ui/components/sheet/confirm.tsx +79 -0
- package/src/ui/components/sheet/docked.tsx +218 -0
- package/src/ui/components/sheet/form.tsx +76 -0
- package/src/ui/components/sheet/head.tsx +120 -0
- package/src/ui/components/sheet/index.tsx +45 -0
- package/src/ui/components/sheet/layer.tsx +168 -0
- package/src/ui/components/sheet/outlet.tsx +58 -0
- package/src/ui/components/sheet/task.tsx +41 -0
- package/src/ui/components/shell/cut.tsx +116 -0
- package/src/ui/components/shell/drag.tsx +45 -0
- package/src/ui/components/shell/host.tsx +71 -0
- package/src/ui/components/shell/index.tsx +737 -0
- package/src/ui/components/shell/panes.tsx +76 -0
- package/src/ui/components/shell/preview.ts +230 -0
- package/src/ui/components/shell/rail.tsx +163 -0
- package/src/ui/components/shell/row.ts +11 -0
- package/src/ui/components/shell/switcher.tsx +143 -0
- package/src/ui/components/shell/tree.tsx +252 -0
- package/src/ui/components/slider/base.tsx +139 -0
- package/src/ui/components/slider/index.tsx +57 -0
- package/src/ui/components/stages/index.tsx +198 -0
- package/src/ui/components/stats/count-links.tsx +47 -0
- package/src/ui/components/stats/index.tsx +203 -0
- package/src/ui/components/stats/meter.tsx +213 -0
- package/src/ui/components/stats/parts.ts +10 -0
- package/src/ui/components/step-count/index.tsx +45 -0
- package/src/ui/components/switch/base.tsx +86 -0
- package/src/ui/components/switch/index.tsx +38 -0
- package/src/ui/components/table/columns.tsx +131 -0
- package/src/ui/components/table/index.tsx +2215 -0
- package/src/ui/components/text/index.tsx +37 -0
- package/src/ui/components/thread/index.tsx +503 -0
- package/src/ui/components/thread/latest.tsx +59 -0
- package/src/ui/components/toast/index.tsx +113 -0
- package/src/ui/components/toast/layer.tsx +26 -0
- package/src/ui/components/toolbar/filters.tsx +161 -0
- package/src/ui/components/toolbar/index.tsx +125 -0
- package/src/ui/components/waveform/index.tsx +205 -0
- package/src/ui/globals.css +427 -0
- package/src/ui/lib/act.ts +60 -0
- package/src/ui/lib/age.ts +49 -0
- package/src/ui/lib/bound.ts +16 -0
- package/src/ui/lib/canvas-layout.ts +11 -0
- package/src/ui/lib/caret.ts +9 -0
- package/src/ui/lib/chip-lines.ts +3 -0
- package/src/ui/lib/closed.ts +8 -0
- package/src/ui/lib/code.tsx +184 -0
- package/src/ui/lib/columns.ts +39 -0
- package/src/ui/lib/commit.ts +24 -0
- package/src/ui/lib/container.ts +112 -0
- package/src/ui/lib/copy.ts +29 -0
- package/src/ui/lib/drag.ts +575 -0
- package/src/ui/lib/empty.tsx +85 -0
- package/src/ui/lib/field.ts +39 -0
- package/src/ui/lib/focus.ts +175 -0
- package/src/ui/lib/folds.ts +67 -0
- package/src/ui/lib/follow.ts +220 -0
- package/src/ui/lib/form.ts +19 -0
- package/src/ui/lib/guards.ts +38 -0
- package/src/ui/lib/heading.ts +14 -0
- package/src/ui/lib/ink.ts +26 -0
- package/src/ui/lib/lang.ts +7 -0
- package/src/ui/lib/leave.ts +14 -0
- package/src/ui/lib/lockup.tsx +145 -0
- package/src/ui/lib/measure.ts +22 -0
- package/src/ui/lib/media.ts +63 -0
- package/src/ui/lib/modality.ts +69 -0
- package/src/ui/lib/moment.ts +13 -0
- package/src/ui/lib/more.tsx +76 -0
- package/src/ui/lib/navigate.ts +210 -0
- package/src/ui/lib/noop.ts +3 -0
- package/src/ui/lib/not-found.tsx +40 -0
- package/src/ui/lib/paint.tsx +55 -0
- package/src/ui/lib/parts-line.tsx +54 -0
- package/src/ui/lib/picked.ts +18 -0
- package/src/ui/lib/player-store.ts +38 -0
- package/src/ui/lib/player.ts +139 -0
- package/src/ui/lib/portal.ts +12 -0
- package/src/ui/lib/read.tsx +269 -0
- package/src/ui/lib/region.tsx +49 -0
- package/src/ui/lib/reorder.ts +154 -0
- package/src/ui/lib/rest.ts +16 -0
- package/src/ui/lib/saved.ts +29 -0
- package/src/ui/lib/scramble.tsx +147 -0
- package/src/ui/lib/scrolls.ts +70 -0
- package/src/ui/lib/style.ts +6 -0
- package/src/ui/lib/swap.tsx +107 -0
- package/src/ui/lib/toast.ts +39 -0
- package/src/ui/lib/walk-classes.ts +16 -0
- package/src/ui/lib/window.tsx +376 -0
- package/src/ui/worker.d.ts +4 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type glyphTier,
|
|
3
|
+
minZoomFor,
|
|
4
|
+
OVERVIEW_FLOOR,
|
|
5
|
+
overviewFloorFor,
|
|
6
|
+
routeSide,
|
|
7
|
+
} from "./floor.ts";
|
|
8
|
+
import { type Box, type Routes, type Size, union } from "./geometry.ts";
|
|
9
|
+
import {
|
|
10
|
+
type Clearance,
|
|
11
|
+
centreOf,
|
|
12
|
+
FIT_FLOOR,
|
|
13
|
+
fitTransform,
|
|
14
|
+
inStackRows,
|
|
15
|
+
overviewTransform,
|
|
16
|
+
solveScale,
|
|
17
|
+
space,
|
|
18
|
+
type Transform,
|
|
19
|
+
withNames,
|
|
20
|
+
} from "./view.ts";
|
|
21
|
+
|
|
22
|
+
// The opening view: pure, so node tests run it. The layout reads the pane, the
|
|
23
|
+
// chrome and the density off the page and hands them here with the two ways it
|
|
24
|
+
// has to draw the graph at a routing side (`glyphTier`, `routeEdges`).
|
|
25
|
+
export interface Opening {
|
|
26
|
+
pane: Size;
|
|
27
|
+
inset: number;
|
|
28
|
+
clear: Clearance;
|
|
29
|
+
// A node's icon stands past its inline padding, in a box no wider than a
|
|
30
|
+
// control: the part of a node the stack must leave clear where no offset
|
|
31
|
+
// clears whole nodes.
|
|
32
|
+
icon: { start: number; end: number };
|
|
33
|
+
// A glyph's size on screen, the `pair` after it, and the widest a name stands
|
|
34
|
+
// beside it.
|
|
35
|
+
glyph: number;
|
|
36
|
+
pair: number;
|
|
37
|
+
names: number;
|
|
38
|
+
// The nodes' boxes as placed.
|
|
39
|
+
boxes: ReadonlyMap<string, Box>;
|
|
40
|
+
// The node the view stands on: the running or failed one, else the first.
|
|
41
|
+
anchor?: string;
|
|
42
|
+
tierAt: (side: number) => ReturnType<typeof glyphTier>;
|
|
43
|
+
routeTier: (side: number, tier: ReturnType<typeof glyphTier>) => Routes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The centres' span of the cards, across and down.
|
|
47
|
+
function spreadOf(cards: readonly Box[]): { across: number; down: number } {
|
|
48
|
+
const centres = cards.map((box) => ({
|
|
49
|
+
...centreOf(box),
|
|
50
|
+
width: 0,
|
|
51
|
+
height: 0,
|
|
52
|
+
}));
|
|
53
|
+
const span = union(centres);
|
|
54
|
+
return { across: span.width, down: span.height };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The view Fit goes to: the whole graph in the room, down to `floor`, the lowest
|
|
58
|
+
// scale the boxes allow; the opening view takes it at `FIT_FLOOR`, `bounds` the
|
|
59
|
+
// drawing it frames where that is not the routed bounds. Under the text floor the
|
|
60
|
+
// frames and the routes follow the zoom (a head and a padding keep their size on
|
|
61
|
+
// screen), so the bounds depend on the scale they are fitted to: the fit is taken
|
|
62
|
+
// again at the scale it gave, down until the bounds at that scale fit it.
|
|
63
|
+
export function fitView(
|
|
64
|
+
o: Opening,
|
|
65
|
+
floor: number,
|
|
66
|
+
bounds?: (routed: Routes) => Box,
|
|
67
|
+
): Transform {
|
|
68
|
+
const { pane, inset, clear, glyph, pair } = o;
|
|
69
|
+
const view = (at: number) => {
|
|
70
|
+
const tier = o.tierAt(at);
|
|
71
|
+
const routed = o.routeTier(at, tier);
|
|
72
|
+
return fitTransform(
|
|
73
|
+
bounds ? bounds(routed) : routed.bounds,
|
|
74
|
+
pane,
|
|
75
|
+
inset,
|
|
76
|
+
clear,
|
|
77
|
+
o.anchor === undefined ? undefined : tier.cards.get(o.anchor),
|
|
78
|
+
{ nodes: [...tier.cards.values()], icon: o.icon },
|
|
79
|
+
floor,
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
let at = view(0);
|
|
83
|
+
for (let step = 0; step < 6; step++) {
|
|
84
|
+
const next = view(routeSide(at.k, glyph, pair));
|
|
85
|
+
if (next.k >= at.k - 1e-3) return next;
|
|
86
|
+
at = next;
|
|
87
|
+
}
|
|
88
|
+
return at;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The view a graph opens at: the graph at its own size (the text floor,
|
|
92
|
+
// `FIT_FLOOR`), where its words stand, when that shows every node whole across
|
|
93
|
+
// the pane and clear of the zoom stack: centred where its drawing (cards, routes
|
|
94
|
+
// and chips) fits the room, else framed at its anchor, the viewer panning down.
|
|
95
|
+
// Where its nodes and frames would be cut at the pane's side, or a node would
|
|
96
|
+
// stand under the stack, it opens as its overview instead (`overview`). An edge
|
|
97
|
+
// chip that stands past the pane's side is the one thing that may be cut.
|
|
98
|
+
export function openingView(o: Opening): Transform {
|
|
99
|
+
const { pane, inset, clear, glyph, pair } = o;
|
|
100
|
+
const all = [...o.boxes.values()];
|
|
101
|
+
const tier0 = o.tierAt(0);
|
|
102
|
+
const cards = [...tier0.cards.values()];
|
|
103
|
+
// The lowest scale the graph may open at: the overview's floor, or the lowest
|
|
104
|
+
// the graph allows above it.
|
|
105
|
+
const lowest = Math.max(OVERVIEW_FLOOR, minZoomFor(all, glyph, pair));
|
|
106
|
+
|
|
107
|
+
if (lowest >= FIT_FLOOR) return fitView(o, FIT_FLOOR);
|
|
108
|
+
|
|
109
|
+
// What the graph's nodes and frames take at the text floor, and the box its
|
|
110
|
+
// drawing takes with the routes and chips.
|
|
111
|
+
const routed0 = o.routeTier(0, tier0);
|
|
112
|
+
const frames = [...routed0.frames.values()];
|
|
113
|
+
const bodies = union([
|
|
114
|
+
...cards,
|
|
115
|
+
...frames,
|
|
116
|
+
...[...routed0.routes.values()].flatMap((route) =>
|
|
117
|
+
route.points.map((at) => ({ ...at, width: 0, height: 0 })),
|
|
118
|
+
),
|
|
119
|
+
]);
|
|
120
|
+
const chipped = union([
|
|
121
|
+
...cards,
|
|
122
|
+
...[...routed0.routes.values()].flatMap((route) => [
|
|
123
|
+
...route.points.map((at) => ({ ...at, width: 0, height: 0 })),
|
|
124
|
+
...(route.label ? [route.label] : []),
|
|
125
|
+
]),
|
|
126
|
+
]);
|
|
127
|
+
// A drawing the pane holds with its chips is framed with them; one it holds
|
|
128
|
+
// only without them is framed without, and its chips may be cut.
|
|
129
|
+
const framed = fitView(
|
|
130
|
+
o,
|
|
131
|
+
FIT_FLOOR,
|
|
132
|
+
chipped.width <= pane.width - 2 * inset ? undefined : () => bodies,
|
|
133
|
+
);
|
|
134
|
+
// The words show the graph whole across the pane and clear of the stack. A
|
|
135
|
+
// graph the pane holds is moved to stand in it, a `pair` from either side.
|
|
136
|
+
const edge = pair;
|
|
137
|
+
const body = union([...cards, ...frames]);
|
|
138
|
+
const left = body.x * framed.k + framed.x;
|
|
139
|
+
const holds = body.width * framed.k <= pane.width - 2 * edge;
|
|
140
|
+
const over = holds
|
|
141
|
+
? Math.max(edge - left, 0) -
|
|
142
|
+
Math.max(left + body.width * framed.k - (pane.width - edge), 0)
|
|
143
|
+
: 0;
|
|
144
|
+
// The stack itself, without the `pair` of air the clearance keeps round it.
|
|
145
|
+
const stackTop = pane.height - clear.stack + pair;
|
|
146
|
+
const stacked = (box: Box, view: Transform) =>
|
|
147
|
+
box.x * view.k + view.x < clear.left - pair &&
|
|
148
|
+
inStackRows(
|
|
149
|
+
box.y * view.k + view.y,
|
|
150
|
+
(box.y + box.height) * view.k + view.y,
|
|
151
|
+
pane,
|
|
152
|
+
clear.stack - pair,
|
|
153
|
+
);
|
|
154
|
+
// A graph the pane holds from top to foot moves up out of the stack's rows
|
|
155
|
+
// where a node under the stack's column would stand in them.
|
|
156
|
+
const area = space(pane, inset, clear);
|
|
157
|
+
const raised = (view: Transform): Transform => {
|
|
158
|
+
const hit = cards.filter((box) => stacked(box, view));
|
|
159
|
+
const up = Math.max(
|
|
160
|
+
0,
|
|
161
|
+
...hit.map((box) => (box.y + box.height) * view.k + view.y - stackTop),
|
|
162
|
+
);
|
|
163
|
+
return hit.length > 0 &&
|
|
164
|
+
body.height * view.k <= area.height &&
|
|
165
|
+
body.y * view.k + view.y - up >= area.y - 0.5
|
|
166
|
+
? { ...view, y: view.y - up }
|
|
167
|
+
: view;
|
|
168
|
+
};
|
|
169
|
+
// A graph the pane holds, but not the room past the stack's column, stands
|
|
170
|
+
// centred across the pane (what it draws, the same margin on both sides)
|
|
171
|
+
// where none of its nodes stands in the stack's rows and its nodes and frames
|
|
172
|
+
// stand whole a `pair` in; else it stands as far over as it must.
|
|
173
|
+
const drawing =
|
|
174
|
+
chipped.width <= pane.width - 2 * inset ? routed0.bounds : bodies;
|
|
175
|
+
const middle = raised({
|
|
176
|
+
...framed,
|
|
177
|
+
x: (pane.width - drawing.width * framed.k) / 2 - drawing.x * framed.k,
|
|
178
|
+
});
|
|
179
|
+
const kept =
|
|
180
|
+
body.x * middle.k + middle.x >= edge - 0.5 &&
|
|
181
|
+
(body.x + body.width) * middle.k + middle.x <= pane.width - edge + 0.5 &&
|
|
182
|
+
!cards.some((box) => stacked(box, middle));
|
|
183
|
+
const words = kept ? middle : raised({ ...framed, x: framed.x + over });
|
|
184
|
+
const whole = [...cards, ...frames].every(
|
|
185
|
+
(box) =>
|
|
186
|
+
box.x * words.k + words.x >= edge - 0.5 &&
|
|
187
|
+
(box.x + box.width) * words.k + words.x <= pane.width - edge + 0.5,
|
|
188
|
+
);
|
|
189
|
+
if (whole && !cards.some((box) => stacked(box, words))) return words;
|
|
190
|
+
return overview(o, lowest);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// A graph wider than its pane at the text floor opens as its overview: its
|
|
194
|
+
// glyphs, its frames (the loops' bands, their heads and the corridors up their
|
|
195
|
+
// sides) and the last glyph's name at the scale that holds them across the room
|
|
196
|
+
// the zoom stack leaves, no lower than `lowest` and just under the text floor at
|
|
197
|
+
// most, so no node opens cut at the pane's edge. Where it is also taller than
|
|
198
|
+
// the pane it opens lower, down to where its names still clear each other (or,
|
|
199
|
+
// with no named overview, to `lowest`). A graph that holds at `lowest` neither
|
|
200
|
+
// across nor down opens there anyway, against the room's start (see
|
|
201
|
+
// `overviewTransform`).
|
|
202
|
+
function overview(o: Opening, lowest: number): Transform {
|
|
203
|
+
const { pane, inset, clear, glyph, pair, names } = o;
|
|
204
|
+
const all = [...o.boxes.values()];
|
|
205
|
+
const area = space(pane, inset, clear);
|
|
206
|
+
const spread = spreadOf([...o.tierAt(0).cards.values()]);
|
|
207
|
+
const named = overviewFloorFor(all, glyph, glyph + pair + names, 2 * pair);
|
|
208
|
+
const heightFloor = named < FIT_FLOOR ? Math.max(lowest, named) : lowest;
|
|
209
|
+
// The glyphs and the frames at a scale: the tier its routing side draws.
|
|
210
|
+
const at = (k: number) => {
|
|
211
|
+
const side = routeSide(k, glyph, pair);
|
|
212
|
+
const tier = o.tierAt(side);
|
|
213
|
+
const squares = [...tier.cards.keys()].flatMap(
|
|
214
|
+
(id) => tier.boxes.get(id) ?? [],
|
|
215
|
+
);
|
|
216
|
+
const frames = [...o.routeTier(side, tier).frames.values()];
|
|
217
|
+
return { tier, box: union([...squares, ...frames]) };
|
|
218
|
+
};
|
|
219
|
+
const across = solveScale(
|
|
220
|
+
(k) => at(k).box.width * k + pair + names,
|
|
221
|
+
spread.across,
|
|
222
|
+
area.width,
|
|
223
|
+
lowest,
|
|
224
|
+
);
|
|
225
|
+
const down = solveScale(
|
|
226
|
+
(k) => at(k).box.height * k,
|
|
227
|
+
spread.down,
|
|
228
|
+
area.height,
|
|
229
|
+
lowest,
|
|
230
|
+
across,
|
|
231
|
+
);
|
|
232
|
+
const k = Math.max(Math.min(across, heightFloor), down);
|
|
233
|
+
const { tier, box } = at(k);
|
|
234
|
+
return overviewTransform(
|
|
235
|
+
withNames(box, pair + names, k),
|
|
236
|
+
k,
|
|
237
|
+
pane,
|
|
238
|
+
inset,
|
|
239
|
+
clear,
|
|
240
|
+
o.anchor === undefined ? undefined : tier.boxes.get(o.anchor),
|
|
241
|
+
[...tier.cards.values()],
|
|
242
|
+
);
|
|
243
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { CanvasNode } from "@slotform/ui-core/descriptors";
|
|
2
|
+
import {
|
|
3
|
+
type RefObject,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { spacing } from "../../lib/measure.ts";
|
|
12
|
+
import { minZoomFor } from "./floor.ts";
|
|
13
|
+
import type { Box, Size } from "./geometry.ts";
|
|
14
|
+
import type { GraphRun, Laid } from "./layout.ts";
|
|
15
|
+
import { fitView, type Opening, openingView } from "./open.ts";
|
|
16
|
+
import { standIn, standsIn } from "./view.ts";
|
|
17
|
+
import type { Viewport } from "./viewport.ts";
|
|
18
|
+
|
|
19
|
+
interface OpeningArgs {
|
|
20
|
+
region: RefObject<HTMLElement | null>;
|
|
21
|
+
nodes: readonly CanvasNode[];
|
|
22
|
+
// `pathOrder` of the nodes and the empty groups.
|
|
23
|
+
order: readonly string[];
|
|
24
|
+
sizes: ReadonlyMap<string, Size>;
|
|
25
|
+
// A glyph's size on screen at the density.
|
|
26
|
+
glyph: number;
|
|
27
|
+
// The widest a node's name stands beside its glyph on screen (`nameCap`).
|
|
28
|
+
names: number;
|
|
29
|
+
// The node the viewer chose: a resized pane keeps it in view.
|
|
30
|
+
selected?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface OpeningView {
|
|
34
|
+
// The lowest scale the pan and zoom allow (`minZoomFor`).
|
|
35
|
+
minZoom: number;
|
|
36
|
+
// The graph is placed and the first view set, so it may show.
|
|
37
|
+
ready: boolean;
|
|
38
|
+
// The Fit act's view: the whole graph in the room the pane leaves, at the
|
|
39
|
+
// scale that holds it down to the lowest the boxes allow. The graph opens
|
|
40
|
+
// (and opens again when its pane resizes) at the same view floored at
|
|
41
|
+
// `FIT_FLOOR`, framed at its first node where it holds only under it.
|
|
42
|
+
fit: () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Sets the view on what the run placed: the first view, the Fit act's, the one
|
|
46
|
+
// an Arrange lands at, and the view again when the room, the parts or the node
|
|
47
|
+
// set move under it.
|
|
48
|
+
export function useOpeningView(
|
|
49
|
+
run: GraphRun,
|
|
50
|
+
viewport: Viewport,
|
|
51
|
+
{ region, nodes, order, sizes, glyph, names, selected }: OpeningArgs,
|
|
52
|
+
): OpeningView {
|
|
53
|
+
const {
|
|
54
|
+
boxes,
|
|
55
|
+
standing,
|
|
56
|
+
tierAt,
|
|
57
|
+
routeTier,
|
|
58
|
+
laid,
|
|
59
|
+
set,
|
|
60
|
+
placing,
|
|
61
|
+
measured,
|
|
62
|
+
placed,
|
|
63
|
+
room,
|
|
64
|
+
} = run;
|
|
65
|
+
const { pair } = run.space;
|
|
66
|
+
const [ready, setReady] = useState(false);
|
|
67
|
+
|
|
68
|
+
// The node the opening view stands on: the first one that is running or has
|
|
69
|
+
// failed (where the run is), else the graph's first.
|
|
70
|
+
const anchor = useMemo(
|
|
71
|
+
() =>
|
|
72
|
+
order.find((id) => {
|
|
73
|
+
const tone = nodes.find((node) => node.id === id)?.status?.tone;
|
|
74
|
+
return tone === "running" || tone === "failed";
|
|
75
|
+
}) ?? order[0],
|
|
76
|
+
[nodes, order],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// What the views that hold the whole graph (`openingView`, `fitView`) take:
|
|
80
|
+
// the pane, the chrome and the density are read here, off the page.
|
|
81
|
+
const opening = useCallback((): Opening | null => {
|
|
82
|
+
if (!region.current) return null;
|
|
83
|
+
// A node's icon stands past its inline padding, in a box no wider than a
|
|
84
|
+
// control (a decision's diamond).
|
|
85
|
+
const inline = spacing("pad");
|
|
86
|
+
return {
|
|
87
|
+
pane: viewport.size(),
|
|
88
|
+
inset: spacing("page"),
|
|
89
|
+
clear: viewport.clearance(),
|
|
90
|
+
icon: { start: inline, end: inline + spacing("control") },
|
|
91
|
+
glyph,
|
|
92
|
+
pair,
|
|
93
|
+
names,
|
|
94
|
+
boxes,
|
|
95
|
+
anchor,
|
|
96
|
+
tierAt,
|
|
97
|
+
routeTier,
|
|
98
|
+
};
|
|
99
|
+
}, [region, viewport, tierAt, routeTier, glyph, names, pair, boxes, anchor]);
|
|
100
|
+
// The lowest zoom at which no two glyphs stand closer than the gap the edges
|
|
101
|
+
// between them need: the lowest scale the pan and zoom allow, set as the boxes
|
|
102
|
+
// move, and by a fit before its view, which must not meet the last graph's.
|
|
103
|
+
const minZoom = useMemo(
|
|
104
|
+
() => minZoomFor([...boxes.values()], glyph, pair),
|
|
105
|
+
[boxes, glyph, pair],
|
|
106
|
+
);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
viewport.limit(minZoom);
|
|
109
|
+
}, [viewport, minZoom]);
|
|
110
|
+
const fitTo = useCallback(
|
|
111
|
+
(whole: boolean) => {
|
|
112
|
+
const o = opening();
|
|
113
|
+
if (!o) return;
|
|
114
|
+
const view = whole ? fitView(o, minZoom) : openingView(o);
|
|
115
|
+
viewport.limit(minZoom);
|
|
116
|
+
viewport[whole ? "go" : "set"](view);
|
|
117
|
+
// The view is the canvas's own again, until the viewer moves it.
|
|
118
|
+
viewport.settle();
|
|
119
|
+
},
|
|
120
|
+
[opening, viewport, minZoom],
|
|
121
|
+
);
|
|
122
|
+
// The opening view and the one an Arrange fits to land at once, as the nodes
|
|
123
|
+
// they follow do; the Fit act is the viewer's, fits the whole graph and travels.
|
|
124
|
+
const open = useCallback(() => fitTo(false), [fitTo]);
|
|
125
|
+
const fit = useCallback(() => fitTo(true), [fitTo]);
|
|
126
|
+
// The latest opening, so Arrange fits the bounds the consumer's positions
|
|
127
|
+
// produced and not the ones the run was asked from.
|
|
128
|
+
const latest = useRef(open);
|
|
129
|
+
useLayoutEffect(() => {
|
|
130
|
+
latest.current = open;
|
|
131
|
+
}, [open]);
|
|
132
|
+
// The run reports an arranged layout's positions in an effect before this
|
|
133
|
+
// one; they commit before the frame, and no event marks that commit.
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (laid?.arranged) requestAnimationFrame(() => latest.current());
|
|
136
|
+
}, [laid]);
|
|
137
|
+
|
|
138
|
+
// The node set the view was last opened on.
|
|
139
|
+
const opened = useRef(set);
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
const element = region.current;
|
|
142
|
+
if (ready || !element || !placed) return;
|
|
143
|
+
// The graph opens as Fit shows it: whole in the room the pane leaves.
|
|
144
|
+
open();
|
|
145
|
+
// A node or frame chosen as the canvas mounts is where the view stands:
|
|
146
|
+
// the opening view fits the graph, and the view is then set, at once and at
|
|
147
|
+
// the scale it opened at, to stand the chosen box in the pane.
|
|
148
|
+
const box = standing(selected);
|
|
149
|
+
const view = viewport.get();
|
|
150
|
+
const size = viewport.size();
|
|
151
|
+
const clear = viewport.clearance();
|
|
152
|
+
const inset = spacing("page");
|
|
153
|
+
if (box && !standsIn(box, view, size, inset, clear)) {
|
|
154
|
+
viewport.set(standIn(box, view.k, size, inset, clear));
|
|
155
|
+
viewport.settle();
|
|
156
|
+
}
|
|
157
|
+
opened.current = set;
|
|
158
|
+
setReady(true);
|
|
159
|
+
}, [ready, placed, region, open, set, selected, standing, viewport]);
|
|
160
|
+
// The opening view stands for the room it was set in. When the pane's size
|
|
161
|
+
// changes (a Pane beside it opens or closes, the window resizes) the graph
|
|
162
|
+
// opens again in the new room, at once; with a node chosen the view keeps
|
|
163
|
+
// its scale and pans only as far as the chosen node needs to stand in the new
|
|
164
|
+
// room (`centreOn`), so a sheet docked beside it leaves it in sight. The view
|
|
165
|
+
// is a transform the script sets, so CSS cannot follow the room: the
|
|
166
|
+
// region's size is read here.
|
|
167
|
+
const chosen = useRef<Box | undefined>(undefined);
|
|
168
|
+
useLayoutEffect(() => {
|
|
169
|
+
chosen.current = standing(selected);
|
|
170
|
+
}, [selected, standing]);
|
|
171
|
+
// The view opens again in the room it now has, or pans to the chosen box.
|
|
172
|
+
const refit = useCallback(() => {
|
|
173
|
+
const box = chosen.current;
|
|
174
|
+
if (box) viewport.centreOn(box);
|
|
175
|
+
else latest.current();
|
|
176
|
+
}, [viewport]);
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
const element = region.current;
|
|
179
|
+
if (!ready || !element) return;
|
|
180
|
+
let last = viewport.size();
|
|
181
|
+
const watch = new ResizeObserver(() => {
|
|
182
|
+
const size = viewport.size();
|
|
183
|
+
if (size.width === last.width && size.height === last.height) return;
|
|
184
|
+
last = size;
|
|
185
|
+
refit();
|
|
186
|
+
});
|
|
187
|
+
watch.observe(element);
|
|
188
|
+
return () => watch.disconnect();
|
|
189
|
+
}, [ready, region, viewport, refit]);
|
|
190
|
+
// Parts wrapped again for a resized room stand elsewhere: the graph opens
|
|
191
|
+
// again on their boxes once they are drawn, or pans to the chosen node's new
|
|
192
|
+
// place. A new layout is not this: its first view is the opening one, or
|
|
193
|
+
// Arrange's fit. A new set of edges over the layout it was not run on is not
|
|
194
|
+
// a new room, and the view the viewer left stays (a new set opens again once
|
|
195
|
+
// its own layout lands, below).
|
|
196
|
+
const wrappedFor = useRef<{ laid: Laid | null; room: string } | null>(null);
|
|
197
|
+
useLayoutEffect(() => {
|
|
198
|
+
if (!ready || !laid) return;
|
|
199
|
+
const was = wrappedFor.current;
|
|
200
|
+
if (was && was.laid === laid && was.room !== room) refit();
|
|
201
|
+
wrappedFor.current = { laid, room };
|
|
202
|
+
}, [ready, laid, room, refit]);
|
|
203
|
+
|
|
204
|
+
// A new set of nodes is a new graph: once the layout has placed it, the view
|
|
205
|
+
// opens on it again (or pans to the chosen node, as a resize does), unless the
|
|
206
|
+
// viewer has panned or zoomed since the view was last the canvas's own. A graph
|
|
207
|
+
// the consumer placed is not laid out, and a node it adds lands where the
|
|
208
|
+
// viewer looks, so it never opens again.
|
|
209
|
+
useLayoutEffect(() => {
|
|
210
|
+
if (!ready || opened.current === set) return;
|
|
211
|
+
if (!placing) {
|
|
212
|
+
opened.current = set;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!measured || laid?.set !== set) return;
|
|
216
|
+
opened.current = set;
|
|
217
|
+
if (viewport.moved()) return;
|
|
218
|
+
refit();
|
|
219
|
+
}, [ready, set, placing, measured, laid, viewport, refit]);
|
|
220
|
+
|
|
221
|
+
// What the view was opened on: the layout and the nodes' sizes. A late font
|
|
222
|
+
// or a node that grows after the first view moves the boxes the view was set
|
|
223
|
+
// for, and a layout that lands again for the same nodes (the probe read a
|
|
224
|
+
// second time) moves them too, so the view opens again on them, or pans to the
|
|
225
|
+
// chosen node, unless the viewer has since moved it. Without this the first view
|
|
226
|
+
// stands whenever the second layout lands, and which it is is a race.
|
|
227
|
+
const basis = useRef<{ laid: Laid | null; sizes: typeof sizes } | null>(null);
|
|
228
|
+
useLayoutEffect(() => {
|
|
229
|
+
if (!ready) return;
|
|
230
|
+
const was = basis.current;
|
|
231
|
+
basis.current = { laid, sizes };
|
|
232
|
+
if (!was || (was.laid === laid && was.sizes === sizes)) return;
|
|
233
|
+
// An Arrange fits the view itself, once it lands.
|
|
234
|
+
if (laid?.arranged && was.laid !== laid) return;
|
|
235
|
+
if (!measured || viewport.moved()) return;
|
|
236
|
+
refit();
|
|
237
|
+
}, [ready, laid, sizes, measured, viewport, refit]);
|
|
238
|
+
|
|
239
|
+
return { minZoom, ready, fit };
|
|
240
|
+
}
|