@slotform/react-ui 0.0.0-stage → 0.1.1
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,97 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { CANVAS_GROUND, canvasNode } from "@slotform/ui-core/variants";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { IconBase } from "../../atoms/icon/index.tsx";
|
|
5
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
6
|
+
import { PITCH } from "./view.ts";
|
|
7
|
+
import { DOT } from "./viewport.ts";
|
|
8
|
+
|
|
9
|
+
// Under `tablet` the region keeps half of the column it stands in, so the
|
|
10
|
+
// column scrolls past it and the head and banners above it scroll away. In a
|
|
11
|
+
// Pane it runs over the body's inset: to the Pane's sides and foot, and to its
|
|
12
|
+
// top when it is the body's first child; under content it draws a hairline
|
|
13
|
+
// where it meets it. It clips what the layer draws past it and is no scroll
|
|
14
|
+
// box: a focus on a node out of view scrolls nothing (the view pans to it), so
|
|
15
|
+
// the zoom stack and the act keep the region's foot. `--canvas-zoom-space` is
|
|
16
|
+
// the width the zoom stack takes past the page inset, named once for what
|
|
17
|
+
// stands beside it.
|
|
18
|
+
const REGION =
|
|
19
|
+
"[--canvas-zoom-space:calc(var(--spacing-control)+2*var(--spacing-hairline)+var(--spacing-gap))] @container/canvas relative flex flex-col grow min-h-0 page-max-tablet:min-h-1/2 min-w-0 overflow-clip touch-none in-[[data-page]]:-mx-page in-[[data-page]]:-mb-page in-[[data-page]]:first:-mt-page in-[[data-page]]:not-first:border-t in-[[data-page]]:not-first:border-edge";
|
|
20
|
+
const GRID = "absolute inset-0 size-full text-grid";
|
|
21
|
+
|
|
22
|
+
// The waiting graph: a column of node cards in the middle of the ground, each
|
|
23
|
+
// a loaded step node's card (`canvasNode`: the node width, its inset, border and
|
|
24
|
+
// radius) holding the node's parts painted, in the node's own text roles: the
|
|
25
|
+
// icon's box, then the overline, the title and the first line as filler, a layer
|
|
26
|
+
// gap apart. The graph's real nodes and where they stand are not known, so the
|
|
27
|
+
// stand-ins are the nodes' measure alone, laid by flex: nothing reads a box.
|
|
28
|
+
// The cards stand in the room the zoom stack leaves (`--canvas-zoom-space`, set
|
|
29
|
+
// on the region: the stack's buttons' width, their border and a gap of air),
|
|
30
|
+
// as the loaded graph's first view does: past the stack's column and inside
|
|
31
|
+
// the page inset on the other side, so at a phone's width no card stands under
|
|
32
|
+
// the stack.
|
|
33
|
+
const WAITING =
|
|
34
|
+
"absolute inset-0 flex flex-col items-center justify-center ps-[calc(var(--spacing-page)+var(--canvas-zoom-space))] pe-page";
|
|
35
|
+
const WAITING_NODE = "flex shrink-0 items-center max-w-full";
|
|
36
|
+
const WAITING_TEXT = "flex flex-col flex-auto min-w-0";
|
|
37
|
+
const WAITING_OVERLINE = "truncate text-caption leading-caption";
|
|
38
|
+
const WAITING_TITLE = "truncate text-body leading-body font-medium";
|
|
39
|
+
const WAITING_LINE = "truncate text-meta leading-meta";
|
|
40
|
+
const WAITING_NODES = 3;
|
|
41
|
+
|
|
42
|
+
/** The region a canvas stands in, loaded or waiting. */
|
|
43
|
+
export const GROUND = cn(CANVAS_GROUND, REGION);
|
|
44
|
+
|
|
45
|
+
// The dot grid at scale 1, which is how a waiting canvas draws it. A loaded
|
|
46
|
+
// canvas's viewport rewrites the pattern's attributes with each pan and zoom.
|
|
47
|
+
export function Grid() {
|
|
48
|
+
const id = useId();
|
|
49
|
+
return (
|
|
50
|
+
<svg aria-hidden="true" data-ground className={GRID}>
|
|
51
|
+
<defs>
|
|
52
|
+
<pattern
|
|
53
|
+
id={id}
|
|
54
|
+
data-grid
|
|
55
|
+
patternUnits="userSpaceOnUse"
|
|
56
|
+
width={PITCH}
|
|
57
|
+
height={PITCH}
|
|
58
|
+
>
|
|
59
|
+
<circle
|
|
60
|
+
fill="currentColor"
|
|
61
|
+
cx={PITCH / 2 + 0.5}
|
|
62
|
+
cy={PITCH / 2 + 0.5}
|
|
63
|
+
r={DOT}
|
|
64
|
+
/>
|
|
65
|
+
</pattern>
|
|
66
|
+
</defs>
|
|
67
|
+
<rect width="100%" height="100%" fill={`url(#${id})`} />
|
|
68
|
+
</svg>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The nodes a waiting canvas stands: the loaded card's parts painted, at the node's measure. */
|
|
73
|
+
export function PaintedNodes() {
|
|
74
|
+
return (
|
|
75
|
+
<div aria-hidden="true" className={cn(WAITING, "gap-section")}>
|
|
76
|
+
{Array.from({ length: WAITING_NODES }, (_, at) => (
|
|
77
|
+
<div
|
|
78
|
+
key={at}
|
|
79
|
+
className={cn(canvasNode({ role: "step" }), WAITING_NODE)}
|
|
80
|
+
>
|
|
81
|
+
<IconBase name="Circle" fit="meta" stroke="line" painted />
|
|
82
|
+
<span className={WAITING_TEXT}>
|
|
83
|
+
<span className={WAITING_OVERLINE}>
|
|
84
|
+
<Painted role="word" at={at} />
|
|
85
|
+
</span>
|
|
86
|
+
<span className={WAITING_TITLE}>
|
|
87
|
+
<Painted role="name" at={at} />
|
|
88
|
+
</span>
|
|
89
|
+
<span className={WAITING_LINE}>
|
|
90
|
+
<Painted role="phrase" at={at} />
|
|
91
|
+
</span>
|
|
92
|
+
</span>
|
|
93
|
+
</div>
|
|
94
|
+
))}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { CANVAS_GROUP_HEAD, canvasGroup } from "@slotform/ui-core/variants";
|
|
3
|
+
import { spacing } from "../../lib/measure.ts";
|
|
4
|
+
import { GROUP_HEAD } from "../../lib/walk-classes.ts";
|
|
5
|
+
import { UNZOOM, UNZOOM_VAR } from "./floor.ts";
|
|
6
|
+
import type { Box } from "./geometry.ts";
|
|
7
|
+
import { keyboardFocus } from "./hit.ts";
|
|
8
|
+
import { FOCUSED, HOVERED } from "./look.ts";
|
|
9
|
+
import { inStackRows, type Transform } from "./view.ts";
|
|
10
|
+
import { useViewportValue, type Viewport } from "./viewport.ts";
|
|
11
|
+
|
|
12
|
+
const BOX = "absolute flex flex-col pointer-events-none";
|
|
13
|
+
const HEAD_TEXT = "min-w-0 truncate";
|
|
14
|
+
// Under the text floor the head keeps its size on screen: the layer's scale is
|
|
15
|
+
// taken back (`UNZOOM`) about the frame's top left, and its width is the
|
|
16
|
+
// frame's on screen, so a long head truncates inside the frame.
|
|
17
|
+
const UNZOOMED = "origin-top-left";
|
|
18
|
+
const UNZOOMED_STYLE = {
|
|
19
|
+
...UNZOOM,
|
|
20
|
+
width: `calc(100% / var(${UNZOOM_VAR}))`,
|
|
21
|
+
};
|
|
22
|
+
const CONTROL = "pointer-events-auto text-start";
|
|
23
|
+
|
|
24
|
+
// How far the head's words stand in from its frame's start, in the head's own
|
|
25
|
+
// pixels: as far as the zoom stack's column (`clear.left`, from the pane's
|
|
26
|
+
// start) stands past the frame's start where the head stands in the stack's
|
|
27
|
+
// rows (`clear.stack`, up from the pane's foot), else as far as the pane's start,
|
|
28
|
+
// so a frame that runs under the stack or off the pane's start keeps its head's
|
|
29
|
+
// words in view and clear of the stack (its band stays across the frame), up to
|
|
30
|
+
// the frame's end less a head's padding and a little room for the words. A head
|
|
31
|
+
// above the stack's rows has no stack to clear: a frame of a few glyphs gives it
|
|
32
|
+
// its whole width. Under the text floor the head draws at its own size on
|
|
33
|
+
// screen, so the flow's distance is taken at the scale.
|
|
34
|
+
function headShift(
|
|
35
|
+
box: Box,
|
|
36
|
+
view: Transform,
|
|
37
|
+
below: boolean,
|
|
38
|
+
clear: Clear,
|
|
39
|
+
pane: { width: number; height: number },
|
|
40
|
+
): number {
|
|
41
|
+
const pad = spacing("pad");
|
|
42
|
+
const top = box.y * view.k + view.y;
|
|
43
|
+
const band = spacing("control") * (below ? 1 : view.k);
|
|
44
|
+
const stood = inStackRows(top, top + band, pane, clear.stack);
|
|
45
|
+
const past = ((stood ? clear.left : 0) - view.x) / view.k - box.x;
|
|
46
|
+
const most = box.width - (4 * pad) / (below ? view.k : 1);
|
|
47
|
+
const flow = Math.max(0, Math.min(past, most));
|
|
48
|
+
return Math.round(below ? flow * view.k : flow);
|
|
49
|
+
}
|
|
50
|
+
// How far the frame's end runs past the pane's end, less the page inset, in the
|
|
51
|
+
// head's own pixels (as `headShift`): the head's words stop that far short of
|
|
52
|
+
// the frame's end, so a frame that runs off the pane's end keeps them in view.
|
|
53
|
+
// What the words keep is what `headShift` leaves of the frame, never less than
|
|
54
|
+
// the room it keeps for them.
|
|
55
|
+
function headEnd(
|
|
56
|
+
box: Box,
|
|
57
|
+
view: Transform,
|
|
58
|
+
below: boolean,
|
|
59
|
+
pane: number,
|
|
60
|
+
shift: number,
|
|
61
|
+
): number {
|
|
62
|
+
const pad = spacing("pad");
|
|
63
|
+
const over =
|
|
64
|
+
((box.x + box.width) * view.k + view.x - pane + spacing("page")) /
|
|
65
|
+
(below ? 1 : view.k);
|
|
66
|
+
const most = (below ? box.width * view.k : box.width) - 4 * pad - shift;
|
|
67
|
+
const flow = Math.max(0, Math.min(over, most));
|
|
68
|
+
return Math.round(flow);
|
|
69
|
+
}
|
|
70
|
+
// What the zoom stack takes from the pane: the columns it reaches across and the
|
|
71
|
+
// rows it reaches up.
|
|
72
|
+
interface Clear {
|
|
73
|
+
left: number;
|
|
74
|
+
stack: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// A group's dashed frame and its head, standing in flow coordinates around
|
|
78
|
+
// the nodes it holds. The frame takes no pointer, so a drag that starts on it
|
|
79
|
+
// pans; with `onSelect` the head alone is a button that chooses the group's
|
|
80
|
+
// id. Under the text floor the head stays, at its own size on screen. Its
|
|
81
|
+
// words stay in view, past the zoom stack, while the frame runs under the stack
|
|
82
|
+
// or off the pane's start (`headShift`).
|
|
83
|
+
export function GroupBox({
|
|
84
|
+
id,
|
|
85
|
+
head,
|
|
86
|
+
box,
|
|
87
|
+
below,
|
|
88
|
+
clear,
|
|
89
|
+
viewport,
|
|
90
|
+
selected,
|
|
91
|
+
onSelect,
|
|
92
|
+
onFocusVisible,
|
|
93
|
+
}: {
|
|
94
|
+
id: string;
|
|
95
|
+
head: string;
|
|
96
|
+
box: Box;
|
|
97
|
+
below: boolean;
|
|
98
|
+
// The zoom stack's column, from the pane's start, and its rows, up from the
|
|
99
|
+
// pane's foot (`headShift`).
|
|
100
|
+
clear: Clear;
|
|
101
|
+
viewport: Viewport;
|
|
102
|
+
selected: boolean;
|
|
103
|
+
onSelect?: (id: string | null) => void;
|
|
104
|
+
onFocusVisible: (id: string) => void;
|
|
105
|
+
}) {
|
|
106
|
+
const shift = useViewportValue(viewport, (view) =>
|
|
107
|
+
headShift(box, view, below, clear, viewport.size()),
|
|
108
|
+
);
|
|
109
|
+
const stop = useViewportValue(viewport, (view) =>
|
|
110
|
+
headEnd(box, view, below, viewport.size().width, shift),
|
|
111
|
+
);
|
|
112
|
+
const text = <span className={HEAD_TEXT}>{head}</span>;
|
|
113
|
+
// The head's start and end padding and the shifts, distances known at run time.
|
|
114
|
+
const style = {
|
|
115
|
+
...(below ? UNZOOMED_STYLE : undefined),
|
|
116
|
+
...(shift > 0
|
|
117
|
+
? { paddingInlineStart: `calc(var(--spacing-pad) + ${shift}px)` }
|
|
118
|
+
: undefined),
|
|
119
|
+
...(stop > 0
|
|
120
|
+
? { paddingInlineEnd: `calc(var(--spacing-pad) + ${stop}px)` }
|
|
121
|
+
: undefined),
|
|
122
|
+
};
|
|
123
|
+
const classes = cn(CANVAS_GROUP_HEAD, GROUP_HEAD, below && UNZOOMED);
|
|
124
|
+
return (
|
|
125
|
+
// The frame's rectangle is a coordinate of the flow, known at run time.
|
|
126
|
+
<div
|
|
127
|
+
data-group={id}
|
|
128
|
+
className={cn(
|
|
129
|
+
canvasGroup({ state: selected ? "selected" : "rest" }),
|
|
130
|
+
BOX,
|
|
131
|
+
)}
|
|
132
|
+
style={{
|
|
133
|
+
left: box.x,
|
|
134
|
+
top: box.y,
|
|
135
|
+
width: box.width,
|
|
136
|
+
height: box.height,
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
{onSelect && head ? (
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
onClick={() => onSelect(id)}
|
|
143
|
+
onFocus={keyboardFocus(id, onFocusVisible)}
|
|
144
|
+
style={style}
|
|
145
|
+
className={cn(classes, CONTROL, HOVERED, FOCUSED)}
|
|
146
|
+
>
|
|
147
|
+
{text}
|
|
148
|
+
</button>
|
|
149
|
+
) : (
|
|
150
|
+
<div style={style} className={classes}>
|
|
151
|
+
{text}
|
|
152
|
+
</div>
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CanvasPoint } from "@slotform/ui-core/descriptors";
|
|
2
|
+
import type { FocusEvent } from "react";
|
|
3
|
+
|
|
4
|
+
// The region's ground and its parts: docs/architecture/plugins/react-ui.md, "Canvas".
|
|
5
|
+
export function isGround(element: Element, region: Element): boolean {
|
|
6
|
+
return (
|
|
7
|
+
region.contains(element) &&
|
|
8
|
+
(element === region ||
|
|
9
|
+
element.matches("[data-layer], [data-ground], [data-ground] *"))
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// What lies under a client point: the node whose in port is there, and whether
|
|
14
|
+
// the topmost element is ground. `elementsFromPoint` lists every element at the
|
|
15
|
+
// point, so an in port is found where a later node's box overlaps its hit, and
|
|
16
|
+
// what a pointer capture redirects does not matter: this reads what is there.
|
|
17
|
+
export function hit(
|
|
18
|
+
point: CanvasPoint,
|
|
19
|
+
region: Element,
|
|
20
|
+
): { node: string | null; ground: boolean } {
|
|
21
|
+
const stack = document.elementsFromPoint(point.x, point.y);
|
|
22
|
+
const port = stack.find(
|
|
23
|
+
(element) =>
|
|
24
|
+
region.contains(element) && element.matches('[data-port="in"]'),
|
|
25
|
+
);
|
|
26
|
+
const top = stack[0];
|
|
27
|
+
return {
|
|
28
|
+
node: port instanceof HTMLElement ? (port.dataset.node ?? null) : null,
|
|
29
|
+
ground: top !== undefined && isGround(top, region),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A focus handler that pans to the part only on a keyboard focus: a press
|
|
34
|
+
// focuses the button too, and panning then would move the part out from under
|
|
35
|
+
// the pointer.
|
|
36
|
+
export const keyboardFocus =
|
|
37
|
+
(id: string, pan: (id: string) => void) =>
|
|
38
|
+
(event: FocusEvent<HTMLElement>): void => {
|
|
39
|
+
if (event.currentTarget.matches(":focus-visible")) pan(id);
|
|
40
|
+
};
|