@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,183 @@
|
|
|
1
|
+
import { Radio } from "@base-ui/react/radio";
|
|
2
|
+
import { RadioGroup } from "@base-ui/react/radio-group";
|
|
3
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
4
|
+
import type { LinkSegment } from "@slotform/ui-core/descriptors";
|
|
5
|
+
import { linkAt } from "@slotform/ui-core/pick";
|
|
6
|
+
import type { Draft } from "@slotform/ui-core/react/acts";
|
|
7
|
+
import {
|
|
8
|
+
SEGMENT_CHOSEN,
|
|
9
|
+
SEGMENT_IDLE,
|
|
10
|
+
SEGMENT_TRACK,
|
|
11
|
+
segment,
|
|
12
|
+
segmentLabel,
|
|
13
|
+
} from "@slotform/ui-core/variants";
|
|
14
|
+
import { use, useLayoutEffect, useRef } from "react";
|
|
15
|
+
import { useHeldDraft } from "../../lib/act.ts";
|
|
16
|
+
import { GroupName } from "../../lib/field.ts";
|
|
17
|
+
import { follow, useRoute } from "../../lib/navigate.ts";
|
|
18
|
+
import { PAINT_CONTROL_HIDDEN } from "../../lib/paint.tsx";
|
|
19
|
+
import type { PickerSegmentsProps } from "./index.tsx";
|
|
20
|
+
|
|
21
|
+
// The track keeps natural widths and scrolls: docs/architecture/plugins/react-ui.md, "Picker segments".
|
|
22
|
+
const TRACK =
|
|
23
|
+
"relative inline-flex shrink-0 min-w-0 max-w-full! items-center w-fit overflow-x-auto scrollbar-none scroll-fade-x";
|
|
24
|
+
// A segment rings inset, so the ring clears its neighbours; an idle one
|
|
25
|
+
// washes under the pointer and the press and takes the body ink, the chosen
|
|
26
|
+
// one carries a 2 px ink underline.
|
|
27
|
+
const SEGMENT =
|
|
28
|
+
"group relative inline-flex shrink-0 items-center justify-center focus-visible:-outline-offset-2";
|
|
29
|
+
const IDLE_LABEL = "group-hover:text-ink-body";
|
|
30
|
+
const LABEL = "truncate max-w-measure-short";
|
|
31
|
+
|
|
32
|
+
// The chosen segment is revealed as it mounts, as the choice changes and as
|
|
33
|
+
// the track's size changes (the phone's width, a late font, a Pane's body
|
|
34
|
+
// settling), by the track's own scroll and only when the segment is not
|
|
35
|
+
// already whole in view (a pixel of subpixel rounding is whole); CSS cannot
|
|
36
|
+
// scroll a track to a child. It looks the chosen segment up in the track,
|
|
37
|
+
// since a ref on a child runs before its parent's is set. A key's focus
|
|
38
|
+
// scrolls its own segment natively.
|
|
39
|
+
const CHOSEN = '[role="radio"][aria-checked="true"], [aria-current="page"]';
|
|
40
|
+
const SLACK = 1;
|
|
41
|
+
function useReveal<E extends HTMLElement>(chosen: string) {
|
|
42
|
+
const track = useRef<E>(null);
|
|
43
|
+
useLayoutEffect(() => {
|
|
44
|
+
const box = track.current;
|
|
45
|
+
if (!box) return;
|
|
46
|
+
const reveal = () => {
|
|
47
|
+
const segment = box.querySelector<HTMLElement>(CHOSEN);
|
|
48
|
+
if (!segment) return;
|
|
49
|
+
// Physical offsets from the track's edges, so the scroll is the same in a
|
|
50
|
+
// right-to-left page.
|
|
51
|
+
const space = box.getBoundingClientRect();
|
|
52
|
+
const at = segment.getBoundingClientRect();
|
|
53
|
+
if (at.left < space.left - SLACK)
|
|
54
|
+
box.scrollBy({ left: at.left - space.left });
|
|
55
|
+
else if (at.right > space.right + SLACK)
|
|
56
|
+
box.scrollBy({ left: at.right - space.right });
|
|
57
|
+
};
|
|
58
|
+
reveal();
|
|
59
|
+
const watch = new ResizeObserver(reveal);
|
|
60
|
+
watch.observe(box);
|
|
61
|
+
return () => watch.disconnect();
|
|
62
|
+
}, [chosen]);
|
|
63
|
+
return track;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The group every Picker in `fit: segments` over choices renders, on the `draft` its host holds: a field hosts the draft of its segments and draws a rejection in its own line. While the draft paints, the track is one filled box at its loaded size, the segments not drawn, inert. Outside the package's exports. */
|
|
67
|
+
export function SegmentsBase<V extends string = string>({
|
|
68
|
+
label,
|
|
69
|
+
options,
|
|
70
|
+
draft,
|
|
71
|
+
onChange,
|
|
72
|
+
}: Pick<PickerSegmentsProps<V>, "label" | "options" | "onChange"> & {
|
|
73
|
+
draft: Draft<V>;
|
|
74
|
+
}) {
|
|
75
|
+
// A read that ended leaves the track with no segment chosen, blocked.
|
|
76
|
+
const ended = draft.ended;
|
|
77
|
+
const painted = draft.painted && !ended;
|
|
78
|
+
const chosenValue = painted || ended ? "" : draft.value;
|
|
79
|
+
// A FormField around it names it with its visible label.
|
|
80
|
+
const named = use(GroupName);
|
|
81
|
+
const track = useReveal<HTMLDivElement>(chosenValue);
|
|
82
|
+
return (
|
|
83
|
+
<RadioGroup
|
|
84
|
+
ref={track}
|
|
85
|
+
aria-label={named ? undefined : label}
|
|
86
|
+
aria-labelledby={named?.labelledBy}
|
|
87
|
+
value={chosenValue}
|
|
88
|
+
onValueChange={(next) => {
|
|
89
|
+
// The track's `""` is no choice, never a segment's value: the viewer
|
|
90
|
+
// picks only a segment.
|
|
91
|
+
const picked = next as V;
|
|
92
|
+
draft.change(picked, () => onChange(picked));
|
|
93
|
+
}}
|
|
94
|
+
inert={painted || undefined}
|
|
95
|
+
aria-disabled={ended || undefined}
|
|
96
|
+
className={cn(SEGMENT_TRACK, TRACK, painted && PAINT_CONTROL_HIDDEN)}
|
|
97
|
+
>
|
|
98
|
+
{options.map((option) => {
|
|
99
|
+
const chosen = option.value === chosenValue;
|
|
100
|
+
const state = chosen ? "selected" : "idle";
|
|
101
|
+
return (
|
|
102
|
+
<Radio.Root
|
|
103
|
+
key={String(option.value)}
|
|
104
|
+
value={option.value}
|
|
105
|
+
nativeButton
|
|
106
|
+
render={<button type="button" />}
|
|
107
|
+
className={cn(
|
|
108
|
+
segment({ state }),
|
|
109
|
+
SEGMENT,
|
|
110
|
+
chosen ? SEGMENT_CHOSEN : SEGMENT_IDLE,
|
|
111
|
+
)}
|
|
112
|
+
>
|
|
113
|
+
<span
|
|
114
|
+
className={cn(
|
|
115
|
+
segmentLabel({ state }),
|
|
116
|
+
LABEL,
|
|
117
|
+
!chosen && IDLE_LABEL,
|
|
118
|
+
)}
|
|
119
|
+
>
|
|
120
|
+
{option.label}
|
|
121
|
+
</span>
|
|
122
|
+
</Radio.Root>
|
|
123
|
+
);
|
|
124
|
+
})}
|
|
125
|
+
</RadioGroup>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Segments over choices that hold their own draft, as a bare one does; a rejection toasts. Outside the package's exports. */
|
|
130
|
+
export function HeldSegments<V extends string = string>({
|
|
131
|
+
label,
|
|
132
|
+
options,
|
|
133
|
+
value,
|
|
134
|
+
onChange,
|
|
135
|
+
}: Omit<PickerSegmentsProps<V>, "fit"> & {
|
|
136
|
+
fit?: "segments";
|
|
137
|
+
}) {
|
|
138
|
+
return (
|
|
139
|
+
<SegmentsBase<V>
|
|
140
|
+
label={label}
|
|
141
|
+
options={options}
|
|
142
|
+
draft={useHeldDraft<V>(value)}
|
|
143
|
+
onChange={onChange}
|
|
144
|
+
/>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Segments over links, the tabs of a place: anchors, the one the location selects marked as the current page, a plain press opening its href in place and any other press the browser's. Outside the package's exports. */
|
|
149
|
+
export function LinkSegments({ options }: { options: readonly LinkSegment[] }) {
|
|
150
|
+
const chosen = linkAt(options, useRoute());
|
|
151
|
+
const track = useReveal<HTMLDivElement>(chosen?.href ?? "");
|
|
152
|
+
return (
|
|
153
|
+
<div ref={track} className={cn(SEGMENT_TRACK, TRACK)}>
|
|
154
|
+
{options.map((option) => {
|
|
155
|
+
const current = option === chosen;
|
|
156
|
+
const state = current ? "selected" : "idle";
|
|
157
|
+
return (
|
|
158
|
+
<a
|
|
159
|
+
key={option.href}
|
|
160
|
+
href={option.href}
|
|
161
|
+
onClick={follow}
|
|
162
|
+
aria-current={current ? "page" : undefined}
|
|
163
|
+
className={cn(
|
|
164
|
+
segment({ state }),
|
|
165
|
+
SEGMENT,
|
|
166
|
+
current ? SEGMENT_CHOSEN : SEGMENT_IDLE,
|
|
167
|
+
)}
|
|
168
|
+
>
|
|
169
|
+
<span
|
|
170
|
+
className={cn(
|
|
171
|
+
segmentLabel({ state }),
|
|
172
|
+
LABEL,
|
|
173
|
+
!current && IDLE_LABEL,
|
|
174
|
+
)}
|
|
175
|
+
>
|
|
176
|
+
{option.label}
|
|
177
|
+
</span>
|
|
178
|
+
</a>
|
|
179
|
+
);
|
|
180
|
+
})}
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { PAINT_ROWS } from "@slotform/ui-core/paint";
|
|
3
|
+
import {
|
|
4
|
+
decodeHTML,
|
|
5
|
+
keyed,
|
|
6
|
+
type Part,
|
|
7
|
+
parts,
|
|
8
|
+
safeHref,
|
|
9
|
+
} from "@slotform/ui-core/prose";
|
|
10
|
+
import { useSelections } from "@slotform/ui-core/react/read";
|
|
11
|
+
import { type Datum, paints } from "@slotform/ui-core/read";
|
|
12
|
+
import {
|
|
13
|
+
PROSE,
|
|
14
|
+
PROSE_BLOCKS,
|
|
15
|
+
PROSE_CODESPAN,
|
|
16
|
+
PROSE_EMPHASIS,
|
|
17
|
+
PROSE_ITEM,
|
|
18
|
+
PROSE_LIST,
|
|
19
|
+
PROSE_PART,
|
|
20
|
+
PROSE_QUOTE,
|
|
21
|
+
PROSE_RULE,
|
|
22
|
+
PROSE_STRIKE,
|
|
23
|
+
proseMarker,
|
|
24
|
+
text,
|
|
25
|
+
textStrong,
|
|
26
|
+
} from "@slotform/ui-core/variants";
|
|
27
|
+
import { lexer, type Token, type Tokens } from "marked";
|
|
28
|
+
import { type ReactNode, use, useMemo } from "react";
|
|
29
|
+
import { ButtonLink } from "../../atoms/button/link.tsx";
|
|
30
|
+
import { PaintedProse } from "../../atoms/prose/painted.tsx";
|
|
31
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
32
|
+
import { HeadingContext } from "../../lib/heading.ts";
|
|
33
|
+
import { Code } from "../code/index.tsx";
|
|
34
|
+
|
|
35
|
+
// An unbroken token too long for the column (a URL) wraps anywhere; every
|
|
36
|
+
// paragraph, item and quote inherits it.
|
|
37
|
+
const COLUMN = "flex flex-col min-w-0";
|
|
38
|
+
const STACK = "flex flex-col";
|
|
39
|
+
const ITEM = "flex";
|
|
40
|
+
const BULLET = "shrink-0 text-center";
|
|
41
|
+
const ORDINAL = "shrink-0 text-end";
|
|
42
|
+
const ITEM_BODY = "flex flex-col grow min-w-0";
|
|
43
|
+
// An inline code span is one atom on its line: it moves whole while it fits,
|
|
44
|
+
// and only a span wider than the column wraps, inside itself.
|
|
45
|
+
const CODESPAN = "inline-block max-w-full";
|
|
46
|
+
// A quote's text reads in the meta ink.
|
|
47
|
+
const QUOTED = "text-ink-meta";
|
|
48
|
+
/** Markdown read at the measure. */
|
|
49
|
+
export interface ProseProps extends Closed {
|
|
50
|
+
/** The text, in markdown: headings, paragraphs, lists, quotes, rules, inline code, links and fenced code (text; wraps). A selection paints one paragraph of `PAINT_ROWS` clipped lines until its read lands. */
|
|
51
|
+
markdown: Datum<string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function inline(tokens: readonly Token[] | undefined, parent: string) {
|
|
55
|
+
return keyed(tokens ?? [], parent).map(([token, key]) => run(token, key));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function run(token: Token, key: string): ReactNode {
|
|
59
|
+
// marked's `Token` holds `Tokens.Generic`, whose `type` is any string, so a
|
|
60
|
+
// case narrows nothing and each case names its token's shape.
|
|
61
|
+
switch (token.type) {
|
|
62
|
+
case "strong":
|
|
63
|
+
return (
|
|
64
|
+
<strong key={key} className={textStrong({ role: "body" })}>
|
|
65
|
+
{inline((token as Tokens.Strong).tokens, key)}
|
|
66
|
+
</strong>
|
|
67
|
+
);
|
|
68
|
+
case "em":
|
|
69
|
+
return (
|
|
70
|
+
<em key={key} className={PROSE_EMPHASIS}>
|
|
71
|
+
{inline((token as Tokens.Em).tokens, key)}
|
|
72
|
+
</em>
|
|
73
|
+
);
|
|
74
|
+
case "del":
|
|
75
|
+
return (
|
|
76
|
+
<del key={key} className={PROSE_STRIKE}>
|
|
77
|
+
{inline((token as Tokens.Del).tokens, key)}
|
|
78
|
+
</del>
|
|
79
|
+
);
|
|
80
|
+
case "codespan":
|
|
81
|
+
return (
|
|
82
|
+
<code key={key} className={cn(PROSE_CODESPAN, CODESPAN)}>
|
|
83
|
+
{(token as Tokens.Codespan).text}
|
|
84
|
+
</code>
|
|
85
|
+
);
|
|
86
|
+
case "link": {
|
|
87
|
+
const link = token as Tokens.Link;
|
|
88
|
+
const href = safeHref(link.href);
|
|
89
|
+
const words = inline(link.tokens, key);
|
|
90
|
+
return href ? (
|
|
91
|
+
<ButtonLink key={key} href={href} fit="inline">
|
|
92
|
+
{words}
|
|
93
|
+
</ButtonLink>
|
|
94
|
+
) : (
|
|
95
|
+
words
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
case "br":
|
|
99
|
+
return <br key={key} />;
|
|
100
|
+
case "image":
|
|
101
|
+
return (token as Tokens.Image).text;
|
|
102
|
+
case "text": {
|
|
103
|
+
const words = token as Tokens.Text;
|
|
104
|
+
return words.tokens ? inline(words.tokens, key) : decodeHTML(words.text);
|
|
105
|
+
}
|
|
106
|
+
case "escape":
|
|
107
|
+
return (token as Tokens.Escape).text;
|
|
108
|
+
// Raw HTML is never interpreted: it reads as its own text.
|
|
109
|
+
default:
|
|
110
|
+
return token.raw;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function Paragraph(props: { tokens?: Token[]; quoted: boolean; id: string }) {
|
|
115
|
+
return (
|
|
116
|
+
<p className={cn(text({ role: "body" }), props.quoted && QUOTED)}>
|
|
117
|
+
{inline(props.tokens, props.id)}
|
|
118
|
+
</p>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function List(props: { list: Tokens.List; quoted: boolean; id: string }) {
|
|
123
|
+
const { list, quoted, id } = props;
|
|
124
|
+
const kind = list.ordered ? "ordered" : "bullet";
|
|
125
|
+
const first = typeof list.start === "number" ? list.start : 1;
|
|
126
|
+
const items = keyed(list.items, id).map(([item, key], index) => (
|
|
127
|
+
<li key={key} className={cn(PROSE_ITEM, ITEM)}>
|
|
128
|
+
<span
|
|
129
|
+
aria-hidden
|
|
130
|
+
className={cn(
|
|
131
|
+
proseMarker({ list: kind }),
|
|
132
|
+
list.ordered ? ORDINAL : BULLET,
|
|
133
|
+
)}
|
|
134
|
+
>
|
|
135
|
+
{list.ordered ? `${first + index}.` : "•"}
|
|
136
|
+
</span>
|
|
137
|
+
<div className={cn(PROSE_LIST, ITEM_BODY)}>
|
|
138
|
+
{blocks(item.tokens, quoted, key)}
|
|
139
|
+
</div>
|
|
140
|
+
</li>
|
|
141
|
+
));
|
|
142
|
+
const box = cn(PROSE_LIST, STACK);
|
|
143
|
+
return list.ordered ? (
|
|
144
|
+
<ol className={box} start={first}>
|
|
145
|
+
{items}
|
|
146
|
+
</ol>
|
|
147
|
+
) : (
|
|
148
|
+
<ul className={box}>{items}</ul>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function blocks(tokens: readonly Token[], quoted: boolean, parent: string) {
|
|
153
|
+
return keyed(tokens, parent).map(([token, key]) => {
|
|
154
|
+
// As in `run`: a case of marked's `Token` narrows nothing.
|
|
155
|
+
switch (token.type) {
|
|
156
|
+
case "space":
|
|
157
|
+
return null;
|
|
158
|
+
case "paragraph":
|
|
159
|
+
case "text":
|
|
160
|
+
return (
|
|
161
|
+
<Paragraph
|
|
162
|
+
key={key}
|
|
163
|
+
tokens={(token as Tokens.Paragraph).tokens ?? [token]}
|
|
164
|
+
quoted={quoted}
|
|
165
|
+
id={key}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
case "code":
|
|
169
|
+
return <Code key={key} text={(token as Tokens.Code).text} copy />;
|
|
170
|
+
case "blockquote":
|
|
171
|
+
return (
|
|
172
|
+
<blockquote key={key} className={cn(PROSE_QUOTE, STACK)}>
|
|
173
|
+
{blocks((token as Tokens.Blockquote).tokens, true, key)}
|
|
174
|
+
</blockquote>
|
|
175
|
+
);
|
|
176
|
+
case "list":
|
|
177
|
+
return (
|
|
178
|
+
<List
|
|
179
|
+
key={key}
|
|
180
|
+
list={token as Tokens.List}
|
|
181
|
+
quoted={quoted}
|
|
182
|
+
id={key}
|
|
183
|
+
/>
|
|
184
|
+
);
|
|
185
|
+
case "hr":
|
|
186
|
+
return <hr key={key} className={PROSE_RULE} />;
|
|
187
|
+
default:
|
|
188
|
+
return (
|
|
189
|
+
<Paragraph
|
|
190
|
+
key={key}
|
|
191
|
+
tokens={[{ type: "text", raw: token.raw, text: token.raw }]}
|
|
192
|
+
quoted={quoted}
|
|
193
|
+
id={key}
|
|
194
|
+
/>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function Blocks(props: { part: Part; level: number }) {
|
|
201
|
+
const { part } = props;
|
|
202
|
+
const nested = new Map(part.parts.map((each) => [each.key, each]));
|
|
203
|
+
const shown = keyed(part.blocks, part.key).map(([token, key]) => {
|
|
204
|
+
const held = token.type === "part" ? nested.get(token.raw) : undefined;
|
|
205
|
+
return held ? (
|
|
206
|
+
<Headed key={key} part={held} level={props.level} />
|
|
207
|
+
) : (
|
|
208
|
+
blocks([token], false, key)
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
return <div className={cn(PROSE_BLOCKS, STACK)}>{shown}</div>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function Headed(props: { part: Part; level: number }) {
|
|
215
|
+
const { part, level } = props;
|
|
216
|
+
const heading = part.heading;
|
|
217
|
+
const top = (heading?.depth ?? 1) <= 2;
|
|
218
|
+
// HTML stops at `h6`. A template literal is no intrinsic element name to the
|
|
219
|
+
// compiler; every heading takes the props `h2` takes.
|
|
220
|
+
const Tag = `h${Math.min(level, 6)}` as "h2";
|
|
221
|
+
return (
|
|
222
|
+
<div className={cn(PROSE_PART, STACK)}>
|
|
223
|
+
<Tag
|
|
224
|
+
className={
|
|
225
|
+
top
|
|
226
|
+
? text({ role: "heading" })
|
|
227
|
+
: cn(text({ role: "body" }), textStrong({ role: "body" }))
|
|
228
|
+
}
|
|
229
|
+
>
|
|
230
|
+
{inline(heading?.tokens, part.key)}
|
|
231
|
+
</Tag>
|
|
232
|
+
<Blocks part={part} level={level + 1} />
|
|
233
|
+
</div>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Markdown at the body role, its column at the measure: `#` and `##` head its parts a sections gap apart at the heading role, `###` and deeper head a part inside them at body 500; paragraphs, lists (the marker hung in its own region), quotes and rules a fields gap apart; inline code on the neutral fill; a fenced block is a `Code` with its copy act. Raw HTML reads as its own text; tables, task lists and images draw as text. While the `markdown` selection's read waits, one paragraph of `PAINT_ROWS` clipped lines of filler stands in its column, inert. */
|
|
238
|
+
export function Prose({ markdown }: ProseProps) {
|
|
239
|
+
const level = use(HeadingContext);
|
|
240
|
+
const [drawn] = useSelections([markdown] as const);
|
|
241
|
+
const source = drawn.painted ? undefined : drawn.value;
|
|
242
|
+
// The markdown lexes and folds once per text, and not while the prose paints.
|
|
243
|
+
const root = useMemo(
|
|
244
|
+
() => (source === undefined ? undefined : parts(lexer(source))),
|
|
245
|
+
[source],
|
|
246
|
+
);
|
|
247
|
+
// An ended read draws no text; the frame that holds it says why.
|
|
248
|
+
if (!root) return paints(drawn) ? <PaintedProse lines={PAINT_ROWS} /> : null;
|
|
249
|
+
return (
|
|
250
|
+
<div className={cn(PROSE, COLUMN)}>
|
|
251
|
+
{root.blocks.length > 0 ? <Blocks part={root} level={level} /> : null}
|
|
252
|
+
{root.parts
|
|
253
|
+
.filter((part) => (part.heading?.depth ?? 1) <= 2)
|
|
254
|
+
.map((part) => (
|
|
255
|
+
<Headed key={part.key} part={part} level={level} />
|
|
256
|
+
))}
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { qrModules, qrTooLong } from "@slotform/ui-core/qr";
|
|
3
|
+
import { useSelections } from "@slotform/ui-core/react/read";
|
|
4
|
+
import { type Datum, dev, paints } from "@slotform/ui-core/read";
|
|
5
|
+
import {
|
|
6
|
+
IMAGE_FAILED_INK,
|
|
7
|
+
QR_CODE,
|
|
8
|
+
QR_CODE_FAILED,
|
|
9
|
+
QR_CODE_FAILED_GLYPH,
|
|
10
|
+
QR_CODE_INK,
|
|
11
|
+
} from "@slotform/ui-core/variants";
|
|
12
|
+
import { useEffect, useMemo } from "react";
|
|
13
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
14
|
+
import { PAINT_BOX } from "../../lib/paint.tsx";
|
|
15
|
+
|
|
16
|
+
// The drawing fills the tile edge to edge, the quiet zone inside its view box.
|
|
17
|
+
const DRAWING = "block size-full";
|
|
18
|
+
|
|
19
|
+
/** A code a camera reads. */
|
|
20
|
+
export interface QrCodeProps {
|
|
21
|
+
/** The text the code carries (an address). A selection paints the tile, inert, until its read lands. Never drawn as words nor read aloud: the label names the code, and the link beside it carries the text. */
|
|
22
|
+
value: Datum<string>;
|
|
23
|
+
/** What the code is for, its accessible name ("Code that adds a device"): a phrase. */
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The code's modules, crisp-edged in the dark ink on a light tile in both modes, inside a four-module quiet zone. The tile is a square at its container's width down to the image's height cap, centred where the cap narrows it, so the code is never cropped. While its text is a selection still to land the tile is painted at that square. It takes no press: an act beside it (a copy of the link) carries the text. */
|
|
28
|
+
export function QrCode({ value: given, label }: QrCodeProps) {
|
|
29
|
+
const [named] = useSelections([given]);
|
|
30
|
+
const text = named.painted ? undefined : named.value;
|
|
31
|
+
const code = useMemo(
|
|
32
|
+
() => (text === undefined ? undefined : qrModules(text)),
|
|
33
|
+
[text],
|
|
34
|
+
);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (text !== undefined && code === undefined && dev())
|
|
37
|
+
console.error(qrTooLong(text));
|
|
38
|
+
}, [text, code]);
|
|
39
|
+
// An ended read draws no code; the region that holds it says why.
|
|
40
|
+
if (named.painted && !paints(named)) return null;
|
|
41
|
+
if (text === undefined)
|
|
42
|
+
return <div aria-hidden inert className={cn(QR_CODE, PAINT_BOX)} />;
|
|
43
|
+
if (code === undefined)
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
role="img"
|
|
47
|
+
aria-label={label}
|
|
48
|
+
className={cn(QR_CODE, QR_CODE_FAILED, IMAGE_FAILED_INK)}
|
|
49
|
+
>
|
|
50
|
+
<Icon name={QR_CODE_FAILED_GLYPH} />
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
return (
|
|
54
|
+
<div role="img" aria-label={label} className={cn(QR_CODE, QR_CODE_INK)}>
|
|
55
|
+
<svg
|
|
56
|
+
aria-hidden="true"
|
|
57
|
+
viewBox={`0 0 ${code.side} ${code.side}`}
|
|
58
|
+
shapeRendering="crispEdges"
|
|
59
|
+
className={DRAWING}
|
|
60
|
+
>
|
|
61
|
+
<path d={code.path} fill="currentColor" />
|
|
62
|
+
</svg>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { moreMenu } from "@slotform/ui-core/acts";
|
|
2
|
+
import type { IconLinkAct } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { paintText } from "@slotform/ui-core/paint";
|
|
4
|
+
import { useOffer } from "@slotform/ui-core/react/acts";
|
|
5
|
+
import { useDrawsFailure, useSelections } from "@slotform/ui-core/react/read";
|
|
6
|
+
import { ReasonHostContext } from "@slotform/ui-core/react/reason";
|
|
7
|
+
import { useTouched } from "@slotform/ui-core/react/touched";
|
|
8
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
9
|
+
import { type Datum, isSelection } from "@slotform/ui-core/read";
|
|
10
|
+
import { pressStands } from "@slotform/ui-core/reason";
|
|
11
|
+
import { useMemo } from "react";
|
|
12
|
+
import { IconButtonBase } from "../../atoms/button/glyph.tsx";
|
|
13
|
+
import { Reason, type useReasonLine } from "../../atoms/button/reason.tsx";
|
|
14
|
+
import {
|
|
15
|
+
type Act,
|
|
16
|
+
type IconAct,
|
|
17
|
+
type MenuEntry,
|
|
18
|
+
wiringOf,
|
|
19
|
+
} from "../../lib/act.ts";
|
|
20
|
+
import { ButtonBase } from "../button/base.tsx";
|
|
21
|
+
import { IconActFace } from "../button/face.tsx";
|
|
22
|
+
import { MenuBase } from "../menu/base.tsx";
|
|
23
|
+
|
|
24
|
+
/** Whether the row has a more act to draw: a selection may still answer none, the box standing meanwhile. */
|
|
25
|
+
export function hasMore(more: Datum<readonly MenuEntry[] | undefined>) {
|
|
26
|
+
return isSelection(more) || Boolean(more?.length);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function PaintedAct({
|
|
30
|
+
at,
|
|
31
|
+
icon = false,
|
|
32
|
+
}: {
|
|
33
|
+
at: number;
|
|
34
|
+
icon?: boolean;
|
|
35
|
+
}) {
|
|
36
|
+
if (icon) return <IconButtonBase icon="Ellipsis" label="" painted />;
|
|
37
|
+
return <ButtonBase act="secondary" label={paintText("word", at)} painted />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The row's act at its end, its icon; a press on it while blocked tells the
|
|
41
|
+
// row whose line draws the reason.
|
|
42
|
+
export function RowAct(props: {
|
|
43
|
+
act: Datum<IconAct | IconLinkAct | undefined>;
|
|
44
|
+
stand: (reason: string) => void;
|
|
45
|
+
at: number;
|
|
46
|
+
}) {
|
|
47
|
+
const { act, stand, at } = props;
|
|
48
|
+
useDrawsFailure([act]);
|
|
49
|
+
const { waits, given, blocked } = useOffer(act);
|
|
50
|
+
const host = useMemo(
|
|
51
|
+
() => (blocked === undefined ? undefined : () => stand(blocked)),
|
|
52
|
+
[blocked, stand],
|
|
53
|
+
);
|
|
54
|
+
if (waits) return <PaintedAct at={at} icon />;
|
|
55
|
+
if (!given) return null;
|
|
56
|
+
return (
|
|
57
|
+
<ReasonHostContext value={host}>
|
|
58
|
+
<IconActFace act={given} />
|
|
59
|
+
</ReasonHostContext>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The reason the row's act is blocked under, on the row's own line: shown once
|
|
64
|
+
// the act was pressed while blocked, or its form is touched.
|
|
65
|
+
export function ActLine(props: {
|
|
66
|
+
act: Datum<IconAct | IconLinkAct | undefined>;
|
|
67
|
+
stood: string | undefined;
|
|
68
|
+
}) {
|
|
69
|
+
const { blocked } = useOffer(props.act);
|
|
70
|
+
const { touched } = useTouched();
|
|
71
|
+
if (blocked === undefined) return null;
|
|
72
|
+
return (
|
|
73
|
+
<Reason shown={pressStands(blocked, props.stood) || touched}>
|
|
74
|
+
{blocked}
|
|
75
|
+
</Reason>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The row's more act: painted while its read lands, the one blocked item with
|
|
80
|
+
// the sentence once it ended, nothing when it answers none. `extra` are the
|
|
81
|
+
// entries the platform adds after the row's own (a drag's, a reorder's).
|
|
82
|
+
export function RowMore(props: {
|
|
83
|
+
more: Datum<readonly MenuEntry[] | undefined> | undefined;
|
|
84
|
+
extra?: readonly MenuEntry[];
|
|
85
|
+
named: string;
|
|
86
|
+
tabIndex?: -1;
|
|
87
|
+
}) {
|
|
88
|
+
useDrawsFailure([props.more]);
|
|
89
|
+
const [offer] = useSelections([props.more]);
|
|
90
|
+
const words = useWords();
|
|
91
|
+
const { painted, items } = moreMenu(words, offer);
|
|
92
|
+
const label = `${words.more} ${props.named}`;
|
|
93
|
+
if (painted)
|
|
94
|
+
return <MenuBase label={label} title={props.named} items={[]} painted />;
|
|
95
|
+
const all = props.extra?.length ? [...items, ...props.extra] : items;
|
|
96
|
+
if (!all.length) return null;
|
|
97
|
+
return (
|
|
98
|
+
<MenuBase
|
|
99
|
+
label={label}
|
|
100
|
+
title={props.named}
|
|
101
|
+
items={all}
|
|
102
|
+
tabIndex={props.tabIndex}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function ActButton(props: {
|
|
108
|
+
act: Act;
|
|
109
|
+
host: ReturnType<typeof useReasonLine>["host"];
|
|
110
|
+
painted: boolean;
|
|
111
|
+
at: number;
|
|
112
|
+
}) {
|
|
113
|
+
const { act, host, painted, at } = props;
|
|
114
|
+
if (painted) return <PaintedAct at={at} />;
|
|
115
|
+
return (
|
|
116
|
+
<ReasonHostContext value={host}>
|
|
117
|
+
<ButtonBase
|
|
118
|
+
act={act.destructive ? "destructive" : "secondary"}
|
|
119
|
+
label={act.label}
|
|
120
|
+
onAct={act.onAct}
|
|
121
|
+
blocked={act.blocked}
|
|
122
|
+
{...wiringOf(act)}
|
|
123
|
+
/>
|
|
124
|
+
</ReasonHostContext>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
3
|
+
import { CODE_NAME, FIGURES } from "@slotform/ui-core/variants";
|
|
4
|
+
import { useCopy } from "../../lib/copy.ts";
|
|
5
|
+
import { Decoded } from "../../lib/region.tsx";
|
|
6
|
+
import { Button } from "../button/index.tsx";
|
|
7
|
+
|
|
8
|
+
// An identifier (`copyable`) is the mono, carrying the body ink as the value
|
|
9
|
+
// beside it; too long for its room it cuts in its middle, its stem truncating
|
|
10
|
+
// to the room and its tail standing whole (`valueCut`). In a row that wraps it
|
|
11
|
+
// stands whole, at a path's or URL's separators first, then anywhere: a
|
|
12
|
+
// fingerprint or a key has no spaces.
|
|
13
|
+
const ID = "flex min-w-0 text-ink-body";
|
|
14
|
+
const STEM = "min-w-0 truncate";
|
|
15
|
+
const WHOLE = "min-w-0 wrap-anywhere";
|
|
16
|
+
const TAIL = "shrink-0";
|
|
17
|
+
|
|
18
|
+
/** A copyable id bare in the mono, cut as the row cuts it, or `whole` (the row's `wrap`) on as many lines as it takes, its `stem` the whole value: its stem is one region across the waiting shape and the loaded one, so it decodes if it waited. Outside the package's exports. */
|
|
19
|
+
export function IdValue(props: {
|
|
20
|
+
painted?: boolean;
|
|
21
|
+
at?: number;
|
|
22
|
+
stem?: string;
|
|
23
|
+
tail?: string;
|
|
24
|
+
whole?: boolean;
|
|
25
|
+
}) {
|
|
26
|
+
return (
|
|
27
|
+
<span className={cn(CODE_NAME, ID, FIGURES)}>
|
|
28
|
+
<span className={props.whole ? WHOLE : STEM}>
|
|
29
|
+
<Decoded
|
|
30
|
+
role="id"
|
|
31
|
+
painted={props.painted}
|
|
32
|
+
at={props.at}
|
|
33
|
+
text={props.stem}
|
|
34
|
+
broken={props.whole}
|
|
35
|
+
/>
|
|
36
|
+
</span>
|
|
37
|
+
{props.tail ? <span className={TAIL}>{props.tail}</span> : null}
|
|
38
|
+
</span>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The copy act: a check and the word Copied for two seconds once copied. Outside the package's exports. */
|
|
43
|
+
export function CopyAct({ label, value }: { label: string; value: string }) {
|
|
44
|
+
const words = useWords();
|
|
45
|
+
const [done, copy] = useCopy();
|
|
46
|
+
return (
|
|
47
|
+
<Button
|
|
48
|
+
glyph
|
|
49
|
+
icon={done ? "Check" : "Copy"}
|
|
50
|
+
label={done ? words.copied : `${words.copy} ${label}`}
|
|
51
|
+
onAct={() => copy(value)}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|