@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,168 @@
|
|
|
1
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import {
|
|
4
|
+
LAYER_CARD,
|
|
5
|
+
LAYER_SCRIM,
|
|
6
|
+
LAYER_SHEET_BOTTOM,
|
|
7
|
+
SCRIM,
|
|
8
|
+
SHEET,
|
|
9
|
+
SHEET_CENTERED,
|
|
10
|
+
SHEET_DESKTOP,
|
|
11
|
+
} from "@slotform/ui-core/variants";
|
|
12
|
+
import {
|
|
13
|
+
createContext,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
type RefObject,
|
|
16
|
+
use,
|
|
17
|
+
useId,
|
|
18
|
+
useRef,
|
|
19
|
+
} from "react";
|
|
20
|
+
import { PageTitle } from "../../lib/container.ts";
|
|
21
|
+
import { useReturnFocus } from "../../lib/focus.ts";
|
|
22
|
+
import { HeadingContext } from "../../lib/heading.ts";
|
|
23
|
+
import { useTouch } from "../../lib/media.ts";
|
|
24
|
+
import { PortalContainer } from "../../lib/portal.ts";
|
|
25
|
+
import { SHEET_BACKDROP } from "../../lib/walk-classes.ts";
|
|
26
|
+
|
|
27
|
+
// The layer the sheet stands on over the scrim (`SHEET_BACKDROP`): from the
|
|
28
|
+
// bottom edge on touch, centred on the desktop. The page inset above a bottom
|
|
29
|
+
// sheet keeps a strip of scrim over the tallest one, so a press above it still
|
|
30
|
+
// dismisses.
|
|
31
|
+
const LAYER_BOTTOM = `${SHEET_BACKDROP} flex flex-col justify-end pt-page`;
|
|
32
|
+
// A decision is centred over the page with no cap of its own.
|
|
33
|
+
const LAYER_CENTRED = `${SHEET_BACKDROP} flex items-center justify-center`;
|
|
34
|
+
// Any other card on the desktop opens one static top inset under the viewport's
|
|
35
|
+
// top and grows downward from it, the page inset below it, and gives way to what
|
|
36
|
+
// they leave, its body scrolling. A flex centre would move its top by half of
|
|
37
|
+
// every change under the member's hands (a textarea a line at a time, a
|
|
38
|
+
// wizard's next page).
|
|
39
|
+
const LAYER_DESKTOP = `${SHEET_BACKDROP} flex flex-col items-center pt-[12dvh] pb-page`;
|
|
40
|
+
const BOX_CARD = "max-h-full min-h-0";
|
|
41
|
+
// The popup takes focus only where nothing in it can (its body still painted
|
|
42
|
+
// while its read waits): it is no control, so it draws no ring, which would
|
|
43
|
+
// read as the whole sheet chosen.
|
|
44
|
+
const BOX = "relative flex flex-col focus-visible:outline-none";
|
|
45
|
+
// A view stands over the whole layer, rising and fading as a centred sheet
|
|
46
|
+
// does (it does not travel from its thumbnail). It takes no
|
|
47
|
+
// press, so the layer around its content hears one as a press on the scrim
|
|
48
|
+
// and dismisses; its content takes its own.
|
|
49
|
+
const BOX_VIEW = "relative size-full pointer-events-none";
|
|
50
|
+
// A bottom sheet is the toasts' anchor: docs/architecture/plugins/react-ui.md, "Toast anchor and stacking".
|
|
51
|
+
const BOX_BOTTOM = "max-h-full pb-safe [anchor-name:--docked-foot]";
|
|
52
|
+
// A menu that searches grows to the layer's height, which `max-h-full` caps at
|
|
53
|
+
// the page inset under the viewport's top.
|
|
54
|
+
const BOX_TALL = "grow";
|
|
55
|
+
const BOX_FLOAT = "max-w-full";
|
|
56
|
+
|
|
57
|
+
/** The layer's popup and the id of the title that names it, which its `SheetHead` draws. Outside the package's exports. */
|
|
58
|
+
export const SheetLayerContext = createContext<{
|
|
59
|
+
popup: RefObject<HTMLDivElement | null>;
|
|
60
|
+
titleId: string;
|
|
61
|
+
}>({ popup: { current: null }, titleId: "" });
|
|
62
|
+
|
|
63
|
+
/** A modal layer over the scrim: on touch a box raised from the bottom edge, on the desktop a card under a static top inset, a decision's card centred, a view over the whole layer. Base UI's dialog traps focus and closes on Escape and on a press outside; focus returns to where it was when it closes. Outside the package's exports. */
|
|
64
|
+
export function SheetLayer({
|
|
65
|
+
open,
|
|
66
|
+
onOpen,
|
|
67
|
+
onClose,
|
|
68
|
+
handle,
|
|
69
|
+
place,
|
|
70
|
+
tall,
|
|
71
|
+
label,
|
|
72
|
+
focus,
|
|
73
|
+
onChange,
|
|
74
|
+
nested,
|
|
75
|
+
children,
|
|
76
|
+
}: {
|
|
77
|
+
open: boolean;
|
|
78
|
+
/** Hears a trigger tied by `handle` opening the layer. */
|
|
79
|
+
onOpen?: () => void;
|
|
80
|
+
/** Hears Escape and a press outside. */
|
|
81
|
+
onClose: () => void;
|
|
82
|
+
/** Ties a trigger elsewhere (a `Dialog.Trigger`) to the layer. */
|
|
83
|
+
handle?: Dialog.Handle<unknown>;
|
|
84
|
+
/** A decision is an alert, centred on the desktop; a view (an image's full size) is its children over the whole layer. */
|
|
85
|
+
place?: "centred" | "view";
|
|
86
|
+
/** A menu that searches stands the whole viewport height from its first frame, so its list does not jump as the filter narrows. */
|
|
87
|
+
tall?: boolean;
|
|
88
|
+
/** The layer's name where no `SheetHead` titles it (a view). */
|
|
89
|
+
label?: string;
|
|
90
|
+
/** What the layer opens focused on: the element a ref holds, or the one a function finds in the popup. */
|
|
91
|
+
focus?:
|
|
92
|
+
| RefObject<HTMLElement | null>
|
|
93
|
+
| ((popup: HTMLDivElement | null) => HTMLElement | true);
|
|
94
|
+
/** Hears a field inside taking input. */
|
|
95
|
+
onChange?: () => void;
|
|
96
|
+
/** A sheet opened over this one, drawn in this dialog's tree and outside its popup, so it takes none of the popup's contexts. */
|
|
97
|
+
nested?: ReactNode;
|
|
98
|
+
children?: ReactNode;
|
|
99
|
+
}) {
|
|
100
|
+
const touch = useTouch();
|
|
101
|
+
const container = use(PortalContainer);
|
|
102
|
+
const titleId = useId();
|
|
103
|
+
const popup = useRef<HTMLDivElement | null>(null);
|
|
104
|
+
useReturnFocus(open, popup);
|
|
105
|
+
const centred = place === "centred" && !touch;
|
|
106
|
+
const view = place === "view";
|
|
107
|
+
// The head's title names the layer unless a label does (a view).
|
|
108
|
+
const named = label === undefined ? titleId : undefined;
|
|
109
|
+
const box = view
|
|
110
|
+
? cn(BOX_VIEW, LAYER_CARD)
|
|
111
|
+
: touch
|
|
112
|
+
? cn(SHEET, BOX, BOX_BOTTOM, tall && BOX_TALL, LAYER_SHEET_BOTTOM)
|
|
113
|
+
: centred
|
|
114
|
+
? cn(SHEET_CENTERED, BOX, BOX_FLOAT, LAYER_CARD)
|
|
115
|
+
: cn(SHEET_DESKTOP, BOX, BOX_FLOAT, BOX_CARD, LAYER_CARD);
|
|
116
|
+
const layer =
|
|
117
|
+
view || centred ? LAYER_CENTRED : touch ? LAYER_BOTTOM : LAYER_DESKTOP;
|
|
118
|
+
return (
|
|
119
|
+
<Dialog.Root
|
|
120
|
+
handle={handle}
|
|
121
|
+
open={open}
|
|
122
|
+
onOpenChange={(next) => {
|
|
123
|
+
if (next) onOpen?.();
|
|
124
|
+
else onClose();
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
<Dialog.Portal container={container}>
|
|
128
|
+
<Dialog.Backdrop className={cn(SCRIM, SHEET_BACKDROP, LAYER_SCRIM)} />
|
|
129
|
+
<Dialog.Viewport
|
|
130
|
+
// A press on the scrim (the layer around the sheet) keeps focus
|
|
131
|
+
// inside the sheet.
|
|
132
|
+
onMouseDown={(event) => {
|
|
133
|
+
if (event.target === event.currentTarget) event.preventDefault();
|
|
134
|
+
}}
|
|
135
|
+
className={layer}
|
|
136
|
+
>
|
|
137
|
+
<Dialog.Popup
|
|
138
|
+
ref={popup}
|
|
139
|
+
initialFocus={
|
|
140
|
+
typeof focus === "function" ? () => focus(popup.current) : focus
|
|
141
|
+
}
|
|
142
|
+
role={place === "centred" ? "alertdialog" : "dialog"}
|
|
143
|
+
// Base UI hides the page behind a modal and traps focus but
|
|
144
|
+
// leaves the popup unmarked; the role promises it.
|
|
145
|
+
aria-modal
|
|
146
|
+
aria-label={label}
|
|
147
|
+
aria-labelledby={named}
|
|
148
|
+
onChange={onChange}
|
|
149
|
+
className={box}
|
|
150
|
+
>
|
|
151
|
+
<SheetLayerContext value={{ popup, titleId }}>
|
|
152
|
+
{/* The head's title is the layer's h2: what the layer holds heads under it, and its title names the parts a page title names. */}
|
|
153
|
+
<PageTitle value={named}>
|
|
154
|
+
<HeadingContext value={3}>{children}</HeadingContext>
|
|
155
|
+
</PageTitle>
|
|
156
|
+
</SheetLayerContext>
|
|
157
|
+
</Dialog.Popup>
|
|
158
|
+
</Dialog.Viewport>
|
|
159
|
+
</Dialog.Portal>
|
|
160
|
+
{
|
|
161
|
+
// Base UI dismisses a modal on a press in a sibling modal; a dialog
|
|
162
|
+
// under this one's root is its nested dialog, and only the topmost
|
|
163
|
+
// hears Escape and a press outside.
|
|
164
|
+
nested
|
|
165
|
+
}
|
|
166
|
+
</Dialog.Root>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DrawnSheet,
|
|
3
|
+
useDrawnSheets,
|
|
4
|
+
} from "@slotform/ui-core/react/sheets";
|
|
5
|
+
import { closeOnResolve, closeSheet } from "@slotform/ui-core/sheets";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
import type { ActSheetProps } from "./index.tsx";
|
|
8
|
+
import { TaskSheet } from "./task.tsx";
|
|
9
|
+
|
|
10
|
+
// One sheet an act opened, with the props the act held at the press.
|
|
11
|
+
function OpenedSheet(props: { drawn: DrawnSheet; nested: ReactNode }) {
|
|
12
|
+
const { drawn, nested } = props;
|
|
13
|
+
// Only `useAct` opens a sheet here, with an act's `sheet` of this platform.
|
|
14
|
+
const sheet = drawn.sheet as ActSheetProps;
|
|
15
|
+
const { submit, form } = sheet;
|
|
16
|
+
return (
|
|
17
|
+
<TaskSheet
|
|
18
|
+
{...sheet}
|
|
19
|
+
open={drawn.open}
|
|
20
|
+
onClose={() => closeSheet(drawn.id)}
|
|
21
|
+
nested={nested}
|
|
22
|
+
form={
|
|
23
|
+
form && {
|
|
24
|
+
...form,
|
|
25
|
+
onDone: (output: unknown, input: unknown) =>
|
|
26
|
+
closeOnResolve(
|
|
27
|
+
drawn.id,
|
|
28
|
+
// The procedure is forgotten here, so its input types as `never`.
|
|
29
|
+
(
|
|
30
|
+
form.onDone as
|
|
31
|
+
| ((output: unknown, input: unknown) => unknown)
|
|
32
|
+
| undefined
|
|
33
|
+
)?.(output, input),
|
|
34
|
+
),
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
submit={
|
|
38
|
+
submit?.onAct
|
|
39
|
+
? {
|
|
40
|
+
...submit,
|
|
41
|
+
// The submit's confirm, done and to stand as given.
|
|
42
|
+
onAct: () => closeOnResolve(drawn.id, submit.onAct?.()),
|
|
43
|
+
}
|
|
44
|
+
: submit
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The sheets acts open (`openSheet`, `@slotform/ui-core/sheets`), each later one drawn inside the one before it, as Base UI nests dialogs. Outside the package's exports: a root container's host draws it. */
|
|
51
|
+
export function SheetOutlet() {
|
|
52
|
+
return useDrawnSheets().reduceRight<ReactNode>(
|
|
53
|
+
(nested, drawn) => (
|
|
54
|
+
<OpenedSheet key={drawn.id} drawn={drawn} nested={nested} />
|
|
55
|
+
),
|
|
56
|
+
null,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ProcedureCall } from "@slotform/ui-core/form";
|
|
2
|
+
import { FrameHolds } from "@slotform/ui-core/react/read";
|
|
3
|
+
import { NO_HOLDS } from "@slotform/ui-core/read";
|
|
4
|
+
import { type ReactNode, useState } from "react";
|
|
5
|
+
import { SheetBase } from "./base.tsx";
|
|
6
|
+
import { useSheetForm } from "./form.tsx";
|
|
7
|
+
import type { SheetProps } from "./index.tsx";
|
|
8
|
+
|
|
9
|
+
/** The public `Sheet`, with what the sheet outlet hands it: `nested`, the sheet opened after this one, drawn inside this one's dialog. Outside the package's exports. */
|
|
10
|
+
export function TaskSheet<P extends ProcedureCall>(
|
|
11
|
+
given: SheetProps<P> & { nested?: ReactNode },
|
|
12
|
+
) {
|
|
13
|
+
// The props of the last open render. A set during render re-runs this
|
|
14
|
+
// component with the same props object, so it settles at once.
|
|
15
|
+
const [shown, setShown] = useState(given);
|
|
16
|
+
if (given.open && shown !== given) setShown(given);
|
|
17
|
+
const { open, onClose } = given;
|
|
18
|
+
const { title, description, back, submit, read, empty, form, children } = open
|
|
19
|
+
? given
|
|
20
|
+
: shown;
|
|
21
|
+
const { acting, fields } = useSheetForm(form, open, [read]);
|
|
22
|
+
return (
|
|
23
|
+
<FrameHolds holds={NO_HOLDS}>
|
|
24
|
+
<SheetBase
|
|
25
|
+
acting={acting}
|
|
26
|
+
open={open}
|
|
27
|
+
onClose={onClose}
|
|
28
|
+
title={title}
|
|
29
|
+
description={description}
|
|
30
|
+
back={back}
|
|
31
|
+
submit={submit}
|
|
32
|
+
read={read}
|
|
33
|
+
empty={empty}
|
|
34
|
+
fields={fields}
|
|
35
|
+
nested={given.nested}
|
|
36
|
+
>
|
|
37
|
+
{children}
|
|
38
|
+
</SheetBase>
|
|
39
|
+
</FrameHolds>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Tooltip } from "@base-ui/react/tooltip";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { NamePopup, SHOW_AFTER } from "../../atoms/button/glyph.tsx";
|
|
4
|
+
import { useTouch } from "../../lib/media.ts";
|
|
5
|
+
import { hid, recently } from "../../lib/rest.ts";
|
|
6
|
+
|
|
7
|
+
// A truncating element: one line cut with an ellipsis (`truncate`), or a line
|
|
8
|
+
// clamp. Cut only when its text runs past its box.
|
|
9
|
+
function cutOf(element: Element): boolean | null {
|
|
10
|
+
const style = getComputedStyle(element);
|
|
11
|
+
if (style.textOverflow === "ellipsis")
|
|
12
|
+
return element.scrollWidth > element.clientWidth;
|
|
13
|
+
if (style.webkitLineClamp !== "none")
|
|
14
|
+
return element.scrollHeight > element.clientHeight;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The nearest truncating ancestor of what the pointer is on, if its text is cut.
|
|
19
|
+
function cutAbove(target: Element): Element | null {
|
|
20
|
+
for (let up: Element | null = target; up; up = up.parentElement) {
|
|
21
|
+
const cut = cutOf(up);
|
|
22
|
+
if (cut !== null) return cut ? up : null;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Keyboard focus lands on a row or a link whose text is a descendant.
|
|
28
|
+
function cutWithin(target: Element): Element | null {
|
|
29
|
+
return (
|
|
30
|
+
cutAbove(target) ??
|
|
31
|
+
[...target.querySelectorAll("*")].find((e) => cutOf(e) === true) ??
|
|
32
|
+
null
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// An element that already names itself (a native `title`) keeps its own.
|
|
37
|
+
function named(element: Element): boolean {
|
|
38
|
+
return element.closest("[title]") !== null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The one tooltip for text that is cut: a pointer resting on it or the keyboard reaching it shows the whole text; Escape, a press, a scroll or leaving hides it; touch draws none. Outside the package's exports; the frame host mounts it once. */
|
|
42
|
+
export function CutText() {
|
|
43
|
+
const touch = useTouch();
|
|
44
|
+
// `instant` is a tooltip that opened with no rest (the keyboard's focus, or
|
|
45
|
+
// a pointer within `RECENT` of the last one going): it shows with no fade.
|
|
46
|
+
const [shown, setShown] = useState<{
|
|
47
|
+
element: Element;
|
|
48
|
+
instant: boolean;
|
|
49
|
+
} | null>(null);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (touch) return;
|
|
53
|
+
let timer: number | undefined;
|
|
54
|
+
let open: Element | null = null;
|
|
55
|
+
const show = (element: Element | null, instant: boolean) => {
|
|
56
|
+
open = element && !named(element) ? element : null;
|
|
57
|
+
setShown(open && { element: open, instant });
|
|
58
|
+
};
|
|
59
|
+
const hide = () => {
|
|
60
|
+
window.clearTimeout(timer);
|
|
61
|
+
if (!open) return;
|
|
62
|
+
show(null, false);
|
|
63
|
+
hid();
|
|
64
|
+
};
|
|
65
|
+
const onMove = (event: Event) => {
|
|
66
|
+
if (!(event instanceof PointerEvent) || event.pointerType === "touch")
|
|
67
|
+
return;
|
|
68
|
+
const target = event.target;
|
|
69
|
+
if (!(target instanceof Element)) return;
|
|
70
|
+
if (open?.contains(target)) return;
|
|
71
|
+
hide();
|
|
72
|
+
const rest = recently() ? 0 : SHOW_AFTER;
|
|
73
|
+
timer = window.setTimeout(
|
|
74
|
+
() => show(target.isConnected ? cutAbove(target) : null, rest === 0),
|
|
75
|
+
rest,
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
const onFocus = (event: Event) => {
|
|
79
|
+
hide();
|
|
80
|
+
const target = event.target;
|
|
81
|
+
if (target instanceof Element && target.matches(":focus-visible"))
|
|
82
|
+
show(cutWithin(target), true);
|
|
83
|
+
};
|
|
84
|
+
const onKey = (event: Event) => {
|
|
85
|
+
if (event instanceof KeyboardEvent && event.key === "Escape") hide();
|
|
86
|
+
};
|
|
87
|
+
const options = { capture: true, passive: true };
|
|
88
|
+
const on: [string, EventListener][] = [
|
|
89
|
+
["pointermove", onMove],
|
|
90
|
+
["pointerdown", hide],
|
|
91
|
+
["pointerleave", hide],
|
|
92
|
+
["scroll", hide],
|
|
93
|
+
["wheel", hide],
|
|
94
|
+
["focusin", onFocus],
|
|
95
|
+
["focusout", hide],
|
|
96
|
+
["keydown", onKey],
|
|
97
|
+
];
|
|
98
|
+
for (const [type, fn] of on) document.addEventListener(type, fn, options);
|
|
99
|
+
document.documentElement.addEventListener("pointerleave", hide);
|
|
100
|
+
return () => {
|
|
101
|
+
hide();
|
|
102
|
+
for (const [type, fn] of on)
|
|
103
|
+
document.removeEventListener(type, fn, options);
|
|
104
|
+
document.documentElement.removeEventListener("pointerleave", hide);
|
|
105
|
+
};
|
|
106
|
+
}, [touch]);
|
|
107
|
+
|
|
108
|
+
if (!shown) return null;
|
|
109
|
+
return (
|
|
110
|
+
<Tooltip.Root open>
|
|
111
|
+
<NamePopup cut anchor={shown.element} instant={shown.instant}>
|
|
112
|
+
{shown.element.textContent}
|
|
113
|
+
</NamePopup>
|
|
114
|
+
</Tooltip.Root>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { DRAG_GHOST, DROP_LINE } from "@slotform/ui-core/variants";
|
|
3
|
+
import { use } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { useDrag } from "../../lib/drag.ts";
|
|
6
|
+
import { PortalContainer } from "../../lib/portal.ts";
|
|
7
|
+
|
|
8
|
+
// The label follows the pointer a step off it, so the drop under the pointer
|
|
9
|
+
// stays in view; both stand in the frame's popup container, a point at the
|
|
10
|
+
// viewport's origin, and take no pointer, so the drag's hit test sees through
|
|
11
|
+
// them.
|
|
12
|
+
const GHOST = "absolute top-0 left-0 pointer-events-none";
|
|
13
|
+
const LINE = "absolute -translate-y-1/2 pointer-events-none";
|
|
14
|
+
|
|
15
|
+
/** The label that follows a drag's pointer and the line a reordered row lands at. Mounted by the container host; draws nothing while no drag stands. Outside the package's exports. */
|
|
16
|
+
export function DragLayer() {
|
|
17
|
+
const drag = useDrag();
|
|
18
|
+
const container = use(PortalContainer);
|
|
19
|
+
if (!drag || !container) return null;
|
|
20
|
+
return createPortal(
|
|
21
|
+
<>
|
|
22
|
+
<div
|
|
23
|
+
aria-hidden
|
|
24
|
+
style={{
|
|
25
|
+
transform: `translate(calc(${drag.x}px + var(--spacing-pad)), calc(${drag.y}px + var(--spacing-pad)))`,
|
|
26
|
+
}}
|
|
27
|
+
className={cn(DRAG_GHOST, GHOST)}
|
|
28
|
+
>
|
|
29
|
+
{drag.label}
|
|
30
|
+
</div>
|
|
31
|
+
{drag.line ? (
|
|
32
|
+
<div
|
|
33
|
+
aria-hidden
|
|
34
|
+
style={{
|
|
35
|
+
left: drag.line.left,
|
|
36
|
+
top: drag.line.top,
|
|
37
|
+
width: drag.line.width,
|
|
38
|
+
}}
|
|
39
|
+
className={cn(DROP_LINE, LINE)}
|
|
40
|
+
/>
|
|
41
|
+
) : null}
|
|
42
|
+
</>,
|
|
43
|
+
container,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Toast as ToastControl } from "@base-ui/react/toast";
|
|
2
|
+
import { Tooltip } from "@base-ui/react/tooltip";
|
|
3
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
4
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
5
|
+
import { TOASTS } from "@slotform/ui-core/variants";
|
|
6
|
+
import { type ReactNode, use, useState } from "react";
|
|
7
|
+
import { useModality } from "../../lib/modality.ts";
|
|
8
|
+
import { PortalContainer, PortalRegion } from "../../lib/portal.ts";
|
|
9
|
+
import { RECENT } from "../../lib/rest.ts";
|
|
10
|
+
import { toasts } from "../../lib/toast.ts";
|
|
11
|
+
import { Confirmations } from "../sheet/confirm.tsx";
|
|
12
|
+
import { SheetOutlet } from "../sheet/outlet.tsx";
|
|
13
|
+
import { ToastList } from "../toast/layer.tsx";
|
|
14
|
+
import { CutText } from "./cut.tsx";
|
|
15
|
+
import { DragLayer } from "./drag.tsx";
|
|
16
|
+
|
|
17
|
+
// The frame's `main` landmark: it holds the toasts' layer over the page.
|
|
18
|
+
const MAIN = "relative flex flex-col grow min-h-0";
|
|
19
|
+
// The popups' mount: docs/architecture/plugins/react-ui.md, "Popups".
|
|
20
|
+
const PORTAL = "fixed top-0 left-0 size-0 z-(--layer-popover)";
|
|
21
|
+
// The toasts' layer stands over the sheets: docs/architecture/plugins/react-ui.md, "Toast anchor and stacking".
|
|
22
|
+
// A sheet as tall as the viewport leaves the layer no room above it, so the
|
|
23
|
+
// layer keeps its frontmost toast's height and the page inset round it (Base UI's
|
|
24
|
+
// `--toast-frontmost-height` on the viewport) and the toast then stands at the
|
|
25
|
+
// top of the viewport, over the sheet's head, never off the screen.
|
|
26
|
+
const TOASTS_LAYER =
|
|
27
|
+
"fixed inset-0 bottom-[anchor(--docked-foot_top,0px)] min-h-[calc(var(--toast-frontmost-height,0px)+2*var(--spacing-page))] z-(--layer-toasts) flex flex-col items-end justify-end pointer-events-none touch:items-center";
|
|
28
|
+
|
|
29
|
+
/** What a root container (the Shell, the Gate) mounts around itself: the `toast()` queue, the sheets acts open, the `confirm()` decisions, the tooltips' shared window, the one tooltip for cut text, the layer a drag draws on and the modality its rings read. Outside the package's exports. */
|
|
30
|
+
export function ContainerHost({ children }: { children: ReactNode }) {
|
|
31
|
+
useModality();
|
|
32
|
+
// The popups' container is an element of `main`, so it is state until the
|
|
33
|
+
// frame's `main` mounts it.
|
|
34
|
+
const [portal, setPortal] = useState<HTMLElement | null>(null);
|
|
35
|
+
return (
|
|
36
|
+
<ToastControl.Provider toastManager={toasts}>
|
|
37
|
+
<Tooltip.Provider timeout={RECENT}>
|
|
38
|
+
<PortalContainer value={portal}>
|
|
39
|
+
<PortalRegion value={setPortal}>
|
|
40
|
+
{children}
|
|
41
|
+
<SheetOutlet />
|
|
42
|
+
<Confirmations />
|
|
43
|
+
<CutText />
|
|
44
|
+
<DragLayer />
|
|
45
|
+
</PortalRegion>
|
|
46
|
+
</PortalContainer>
|
|
47
|
+
</Tooltip.Provider>
|
|
48
|
+
</ToastControl.Provider>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The frame's `main`: its page and the toasts' layer over it. It stands inside a `ContainerHost`, whose popups' container it mounts. */
|
|
53
|
+
export function ContainerMain(props: {
|
|
54
|
+
children: ReactNode;
|
|
55
|
+
className?: string;
|
|
56
|
+
}) {
|
|
57
|
+
const words = useWords();
|
|
58
|
+
const region = use(PortalRegion);
|
|
59
|
+
return (
|
|
60
|
+
<main className={cn(MAIN, props.className)}>
|
|
61
|
+
{props.children}
|
|
62
|
+
<div ref={region} className={PORTAL} />
|
|
63
|
+
<ToastControl.Viewport
|
|
64
|
+
aria-label={words.notifications}
|
|
65
|
+
className={cn(TOASTS, TOASTS_LAYER)}
|
|
66
|
+
>
|
|
67
|
+
<ToastList />
|
|
68
|
+
</ToastControl.Viewport>
|
|
69
|
+
</main>
|
|
70
|
+
);
|
|
71
|
+
}
|