@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,38 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { levelOf } from "@slotform/ui-core/list-state";
|
|
3
|
+
import {
|
|
4
|
+
METER_TRACK,
|
|
5
|
+
meterFill,
|
|
6
|
+
ROW_PROGRESS,
|
|
7
|
+
} from "@slotform/ui-core/variants";
|
|
8
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
9
|
+
|
|
10
|
+
/** A row's progress: a running task's `value` of its `max` as the meter's bar along the row's foot, at the text column's start, a badge gap under the facts. It fills in the meta ink and turns the good tone once it reaches `max`, never amber. Outside the package's exports. */
|
|
11
|
+
export function RowProgress(props: {
|
|
12
|
+
value: number;
|
|
13
|
+
max: number;
|
|
14
|
+
name: string;
|
|
15
|
+
}) {
|
|
16
|
+
const { value, max, name } = props;
|
|
17
|
+
if (!(max > 0)) return null;
|
|
18
|
+
const share = Math.min(Math.max(value / max, 0), 1);
|
|
19
|
+
// The fill is the whole track scaled to the task's share.
|
|
20
|
+
const fill: VarStyle = { "--fill": share };
|
|
21
|
+
return (
|
|
22
|
+
<div className={ROW_PROGRESS}>
|
|
23
|
+
<div
|
|
24
|
+
role="progressbar"
|
|
25
|
+
aria-label={name}
|
|
26
|
+
aria-valuemin={0}
|
|
27
|
+
aria-valuemax={max}
|
|
28
|
+
aria-valuenow={Math.min(Math.max(value, 0), max)}
|
|
29
|
+
className={cn(METER_TRACK, "pointer-events-none")}
|
|
30
|
+
>
|
|
31
|
+
<div
|
|
32
|
+
className={meterFill({ level: levelOf(share, undefined, true) })}
|
|
33
|
+
style={fill}
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { StatusMark } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
4
|
+
import { lineBox, STATUS, STATUS_LABEL } from "@slotform/ui-core/variants";
|
|
5
|
+
import { StatusDot } from "../../atoms/status/dot.tsx";
|
|
6
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
7
|
+
|
|
8
|
+
// The dot's lane: one facts line tall, the dot centred on it.
|
|
9
|
+
const LANE = "flex shrink-0 items-center h-[1lh]";
|
|
10
|
+
const WORD = "min-w-0 break-words";
|
|
11
|
+
|
|
12
|
+
/** The status dot (the spinner while `running`) of a room row whose only fact is its status: it stands at the start of the end group, before its word (`RowStatusWord`), which is no badge; a row's status among its facts is a badge (`StatusBadge`). `painted` is the dot's box while the status is not here. Outside the package's exports. */
|
|
13
|
+
export function RowStatusDot(props: { status: StatusMark; painted?: boolean }) {
|
|
14
|
+
const { status, painted } = props;
|
|
15
|
+
return (
|
|
16
|
+
<span className={cn(lineBox({ role: "meta" }), LANE)}>
|
|
17
|
+
{/* Painted before anything reads the status: over a placeholder every key is there. */}
|
|
18
|
+
{painted ? (
|
|
19
|
+
<StatusDot tone="done" painted />
|
|
20
|
+
) : (
|
|
21
|
+
<StatusDot tone={status.tone} />
|
|
22
|
+
)}
|
|
23
|
+
</span>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The status word of a room row whose only fact is its status, in the end group after its dot (`RowStatusDot`), a given word too, or a word's filler while the status is not here. Outside the package's exports. */
|
|
28
|
+
export function RowStatusWord(props: {
|
|
29
|
+
status: StatusMark;
|
|
30
|
+
painted?: boolean;
|
|
31
|
+
}) {
|
|
32
|
+
const { status, painted } = props;
|
|
33
|
+
const words = useWords();
|
|
34
|
+
return (
|
|
35
|
+
<span className={cn(STATUS_LABEL, WORD)}>
|
|
36
|
+
{painted ? <Painted role="word" /> : (status.label ?? words[status.tone])}
|
|
37
|
+
</span>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const VALUE = "inline-flex items-center min-w-0 max-w-full";
|
|
42
|
+
|
|
43
|
+
/** A status as a row's title (a value in a fact row): its tone's mark and its word, plain, as a status is wherever it is no fact of a facts line; the state pill's tint and outline are a control's (a pick of states), never a value's, so colour stays on the glyph. Outside the package's exports. */
|
|
44
|
+
export function StatusValue({ status }: { status: StatusMark }) {
|
|
45
|
+
const words = useWords();
|
|
46
|
+
return (
|
|
47
|
+
<span className={cn(STATUS, VALUE)}>
|
|
48
|
+
<StatusDot tone={status.tone} />
|
|
49
|
+
<span className={cn(STATUS_LABEL, WORD)}>
|
|
50
|
+
{status.label ?? words[status.tone]}
|
|
51
|
+
</span>
|
|
52
|
+
</span>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// A title wraps to `ROW_TITLE_LINES` lines and keeps its longest word whole:
|
|
2
|
+
// docs/architecture/ui-core/layout.md, "Title and facts". Tailwind reads the
|
|
3
|
+
// class as written, so the count is spelled here and `title.test.ts` holds it
|
|
4
|
+
// to the constant.
|
|
5
|
+
export const TITLE_COMPACT = "line-clamp-3 whitespace-normal break-words";
|
|
6
|
+
export const TITLE_ADAPTS =
|
|
7
|
+
"row-two-line:line-clamp-3 row-two-line:whitespace-normal row-two-line:break-words";
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type {
|
|
3
|
+
EitherPick,
|
|
4
|
+
Rule,
|
|
5
|
+
RuleValue,
|
|
6
|
+
} from "@slotform/ui-core/descriptors";
|
|
7
|
+
import { useArrivals } from "@slotform/ui-core/react/arrive";
|
|
8
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
9
|
+
import { isTyped, marked, pairSet, ruleName } from "@slotform/ui-core/rules";
|
|
10
|
+
import {
|
|
11
|
+
BLOCK_IN,
|
|
12
|
+
RULE_CARD,
|
|
13
|
+
RULE_ROW,
|
|
14
|
+
RULES,
|
|
15
|
+
ruleArrow,
|
|
16
|
+
} from "@slotform/ui-core/variants";
|
|
17
|
+
import { Fragment, useMemo, useRef, useState } from "react";
|
|
18
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
19
|
+
import { SheetCard } from "../../atoms/section/card.tsx";
|
|
20
|
+
import { type Act, wiringOf } from "../../lib/act.ts";
|
|
21
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
22
|
+
import { useTouch } from "../../lib/media.ts";
|
|
23
|
+
import { ButtonBase } from "../button/base.tsx";
|
|
24
|
+
import { Button } from "../button/index.tsx";
|
|
25
|
+
import { HeldInput } from "../input/base.tsx";
|
|
26
|
+
import { HeldPicker } from "../picker/base.tsx";
|
|
27
|
+
import { Text } from "../text/index.tsx";
|
|
28
|
+
|
|
29
|
+
// From `tablet` each rule is one flex row: its two terms share the row's
|
|
30
|
+
// width equally (the same basis, so their columns align across rows), the
|
|
31
|
+
// arrow or operator between them at a floor of the remove act's width, so
|
|
32
|
+
// the short words and the arrow line up. A rule that cannot go keeps the
|
|
33
|
+
// remove act's room as the row's end padding, so the terms stay aligned.
|
|
34
|
+
// A term's control yields to its column (`*:min-w-0`): a typed term's box
|
|
35
|
+
// would otherwise hold the input's own width, run past its column and draw
|
|
36
|
+
// its act over the next term; its value truncates before its act instead.
|
|
37
|
+
// A list narrower than its one-row width (`rulesOneRow`, the `rules`
|
|
38
|
+
// container: two terms at their floor of characters, the arrow and the remove
|
|
39
|
+
// act) stacks each rule's terms rather than cut them (`rules-stacked:`), the
|
|
40
|
+
// arrow turned down between them and the remove act beside the last term on
|
|
41
|
+
// its line, a hairline between the rules. On touch each rule is a card of
|
|
42
|
+
// stacked terms in a sheet, its remove act beside the last term on that
|
|
43
|
+
// term's line.
|
|
44
|
+
const LIST = "@container/rules flex flex-col";
|
|
45
|
+
const ROW =
|
|
46
|
+
"flex items-center rules-stacked:flex-col rules-stacked:items-stretch rules-stacked:not-first:border-t rules-stacked:not-first:border-edge rules-stacked:not-first:pt-gap";
|
|
47
|
+
const KEPT =
|
|
48
|
+
"pe-[calc(var(--spacing-control)+var(--spacing-gap))] rules-stacked:pe-0";
|
|
49
|
+
const TERM =
|
|
50
|
+
"flex min-w-0 grow basis-0 *:grow *:min-w-0 rules-stacked:basis-auto";
|
|
51
|
+
const MIDDLE = "min-w-control";
|
|
52
|
+
// The arrow points down where the terms stack.
|
|
53
|
+
const TURN = "flex rules-stacked:rotate-90";
|
|
54
|
+
// The last term and the remove act: items of the row where it is one, one
|
|
55
|
+
// line of their own where the terms stack.
|
|
56
|
+
const TAIL =
|
|
57
|
+
"contents rules-stacked:flex rules-stacked:items-center rules-stacked:gap-gap";
|
|
58
|
+
const ADD = "flex";
|
|
59
|
+
const STACKED = "flex flex-col items-stretch";
|
|
60
|
+
const STACK = "flex flex-col items-start gap-gap";
|
|
61
|
+
const GROUP_REGION = "self-stretch";
|
|
62
|
+
const ADD_WRAP = "max-w-full";
|
|
63
|
+
const MARK = "flex shrink-0 items-center justify-center";
|
|
64
|
+
// On touch the last term and the remove act share one line of the card.
|
|
65
|
+
const LAST = "flex items-center";
|
|
66
|
+
const LAST_TERM = "flex min-w-0 grow *:grow *:min-w-0";
|
|
67
|
+
|
|
68
|
+
/** The rules, each one row of terms. */
|
|
69
|
+
export interface RulesProps<V extends string | null = string> extends Closed {
|
|
70
|
+
/** The rules in order, each a pair (`from`, `to`) or a condition (`field`, `operator`, `value`), with its own `onRemove` and an `id` unique in the list. */
|
|
71
|
+
rules: readonly Rule<V>[];
|
|
72
|
+
/** The act that adds a rule, ending the list. */
|
|
73
|
+
add?: Act;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// A picked option or a typed value: the pick (its list ends with the act that
|
|
77
|
+
// types), or the typed `Input` (its act picks again). An act the viewer ran
|
|
78
|
+
// types into a field that takes focus; a typed value that arrives so does not.
|
|
79
|
+
function Either<V extends string | null>(props: EitherPick<V>) {
|
|
80
|
+
const { label, options, value, onChange, placeholder } = props;
|
|
81
|
+
const words = useWords();
|
|
82
|
+
const [typing, setTyping] = useState(false);
|
|
83
|
+
const marks = useMemo(() => marked(options), [options]);
|
|
84
|
+
const rule = { label, focus: typing };
|
|
85
|
+
if (isTyped(value))
|
|
86
|
+
return (
|
|
87
|
+
<HeldInput
|
|
88
|
+
inline={rule}
|
|
89
|
+
value={value.typed}
|
|
90
|
+
onChange={(typed) => onChange({ typed })}
|
|
91
|
+
placeholder={placeholder}
|
|
92
|
+
act={{
|
|
93
|
+
icon: "ListFilter",
|
|
94
|
+
label: words.pickValue,
|
|
95
|
+
onAct: () => {
|
|
96
|
+
setTyping(false);
|
|
97
|
+
onChange({});
|
|
98
|
+
},
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
return (
|
|
103
|
+
<HeldPicker
|
|
104
|
+
term
|
|
105
|
+
label={label}
|
|
106
|
+
fit="bar"
|
|
107
|
+
options={marks}
|
|
108
|
+
value={value.picked}
|
|
109
|
+
onChange={(picked) => onChange({ picked })}
|
|
110
|
+
act={{
|
|
111
|
+
icon: "TextCursorInput",
|
|
112
|
+
label: words.typeValue,
|
|
113
|
+
onAct: () => {
|
|
114
|
+
setTyping(true);
|
|
115
|
+
onChange({ typed: "" });
|
|
116
|
+
},
|
|
117
|
+
}}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function Term<V extends string | null>({ value }: { value: RuleValue<V> }) {
|
|
123
|
+
if (value.pick) return <HeldPicker term {...value.pick} fit="bar" />;
|
|
124
|
+
if (value.picks) return <HeldPicker term fold {...value.picks} fit="bar" />;
|
|
125
|
+
return <Either {...value.either} />;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// A rule is a block of the list: named for the page's block move (the viewer's
|
|
129
|
+
// remove runs in it), and fading in if it came on its own once the list was
|
|
130
|
+
// drawn, held from the first render.
|
|
131
|
+
function RuleRow<V extends string | null>({
|
|
132
|
+
rule,
|
|
133
|
+
onRemove,
|
|
134
|
+
touch,
|
|
135
|
+
arrived,
|
|
136
|
+
}: {
|
|
137
|
+
rule: Rule<V>;
|
|
138
|
+
onRemove: (() => void) | undefined;
|
|
139
|
+
touch: boolean;
|
|
140
|
+
arrived: boolean;
|
|
141
|
+
}) {
|
|
142
|
+
const words = useWords();
|
|
143
|
+
const [fades] = useState(arrived);
|
|
144
|
+
const { terms } = rule;
|
|
145
|
+
const middle = terms.from ? (
|
|
146
|
+
<span
|
|
147
|
+
className={cn(
|
|
148
|
+
ruleArrow({ state: pairSet(terms) ? "set" : "unset" }),
|
|
149
|
+
MARK,
|
|
150
|
+
!touch && MIDDLE,
|
|
151
|
+
)}
|
|
152
|
+
>
|
|
153
|
+
{touch ? (
|
|
154
|
+
<Icon name="ArrowDown" fit="meta" />
|
|
155
|
+
) : (
|
|
156
|
+
<span className={TURN}>
|
|
157
|
+
<Icon name="ArrowRight" fit="meta" />
|
|
158
|
+
</span>
|
|
159
|
+
)}
|
|
160
|
+
</span>
|
|
161
|
+
) : (
|
|
162
|
+
<span className={cn(MARK, !touch && MIDDLE)}>
|
|
163
|
+
<Text kind="meta">{terms.operator}</Text>
|
|
164
|
+
</span>
|
|
165
|
+
);
|
|
166
|
+
const remove = onRemove ? (
|
|
167
|
+
<span data-rule-remove="" className={MARK}>
|
|
168
|
+
<Button
|
|
169
|
+
glyph
|
|
170
|
+
icon="X"
|
|
171
|
+
label={`${words.remove} ${ruleName(terms)}`}
|
|
172
|
+
onAct={onRemove}
|
|
173
|
+
/>
|
|
174
|
+
</span>
|
|
175
|
+
) : null;
|
|
176
|
+
const last = <Term value={terms.from ? terms.to : terms.value} />;
|
|
177
|
+
const Row = touch ? "div" : "li";
|
|
178
|
+
return (
|
|
179
|
+
<Row
|
|
180
|
+
role={touch ? "listitem" : undefined}
|
|
181
|
+
className={cn(
|
|
182
|
+
RULE_ROW,
|
|
183
|
+
touch ? cn(RULE_CARD, STACKED) : cn(ROW, !onRemove && KEPT),
|
|
184
|
+
fades && BLOCK_IN,
|
|
185
|
+
)}
|
|
186
|
+
>
|
|
187
|
+
<span className={touch ? undefined : TERM}>
|
|
188
|
+
{terms.from ? (
|
|
189
|
+
<Term value={terms.from} />
|
|
190
|
+
) : (
|
|
191
|
+
<HeldPicker term {...terms.field} fit="bar" />
|
|
192
|
+
)}
|
|
193
|
+
</span>
|
|
194
|
+
{middle}
|
|
195
|
+
{!touch ? (
|
|
196
|
+
<span className={TAIL}>
|
|
197
|
+
<span className={TERM}>{last}</span>
|
|
198
|
+
{remove}
|
|
199
|
+
</span>
|
|
200
|
+
) : remove ? (
|
|
201
|
+
<div className={cn(RULE_ROW, LAST)}>
|
|
202
|
+
<span className={LAST_TERM}>{last}</span>
|
|
203
|
+
{remove}
|
|
204
|
+
</div>
|
|
205
|
+
) : (
|
|
206
|
+
<span>{last}</span>
|
|
207
|
+
)}
|
|
208
|
+
</Row>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** A list of rules, each one row of terms aligned in columns: a pair maps a source to a target, a condition is a field, fixed operator words and a value. In a list narrower than its one-row width each rule stacks its terms, so no term is cut under its floor of characters. */
|
|
213
|
+
export function Rules<V extends string | null = string>({
|
|
214
|
+
rules,
|
|
215
|
+
add,
|
|
216
|
+
}: RulesProps<V>) {
|
|
217
|
+
const touch = useTouch();
|
|
218
|
+
const list = useRef<HTMLElement | null>(null);
|
|
219
|
+
// One ref for the list element of either density, a `ul` or a `div`.
|
|
220
|
+
const hold = (element: HTMLElement | null) => {
|
|
221
|
+
list.current = element;
|
|
222
|
+
};
|
|
223
|
+
const removable = rules.filter((rule) => rule.onRemove);
|
|
224
|
+
// A removed rule hands focus to the next row's remove act, else the
|
|
225
|
+
// previous one's, else the add act, so a keyboard viewer keeps their place.
|
|
226
|
+
const removeRule = (rule: Rule<V>) => () => {
|
|
227
|
+
const acts = list.current?.querySelectorAll("[data-rule-remove] button");
|
|
228
|
+
const at = removable.indexOf(rule);
|
|
229
|
+
const next =
|
|
230
|
+
acts?.[at + 1] ??
|
|
231
|
+
acts?.[at - 1] ??
|
|
232
|
+
list.current?.querySelector("[data-rule-add] button");
|
|
233
|
+
rule.onRemove?.();
|
|
234
|
+
if (next instanceof HTMLElement) next.focus();
|
|
235
|
+
};
|
|
236
|
+
const arrived = useArrivals(
|
|
237
|
+
rules.map((rule) => rule.id),
|
|
238
|
+
true,
|
|
239
|
+
);
|
|
240
|
+
const rowOf = (rule: Rule<V>) => (
|
|
241
|
+
<RuleRow
|
|
242
|
+
rule={rule}
|
|
243
|
+
onRemove={rule.onRemove && removeRule(rule)}
|
|
244
|
+
touch={touch}
|
|
245
|
+
arrived={arrived.has(rule.id)}
|
|
246
|
+
/>
|
|
247
|
+
);
|
|
248
|
+
const act = add ? (
|
|
249
|
+
<ButtonBase
|
|
250
|
+
act="secondary"
|
|
251
|
+
icon="Plus"
|
|
252
|
+
label={add.label}
|
|
253
|
+
onAct={add.onAct}
|
|
254
|
+
blocked={add.blocked}
|
|
255
|
+
{...wiringOf(add)}
|
|
256
|
+
/>
|
|
257
|
+
) : null;
|
|
258
|
+
if (touch)
|
|
259
|
+
return (
|
|
260
|
+
<div ref={hold} className={STACK}>
|
|
261
|
+
{rules.length > 0 ? (
|
|
262
|
+
// biome-ignore lint/a11y/useSemanticElements: the sheet's card sits between the list and its cards, and a `ul` over it cannot hold its `div`
|
|
263
|
+
<div role="list" className={GROUP_REGION}>
|
|
264
|
+
<SheetCard>
|
|
265
|
+
{rules.map((rule) => (
|
|
266
|
+
<Fragment key={rule.id}>{rowOf(rule)}</Fragment>
|
|
267
|
+
))}
|
|
268
|
+
</SheetCard>
|
|
269
|
+
</div>
|
|
270
|
+
) : null}
|
|
271
|
+
{act ? (
|
|
272
|
+
<div data-rule-add="" className={ADD_WRAP}>
|
|
273
|
+
{act}
|
|
274
|
+
</div>
|
|
275
|
+
) : null}
|
|
276
|
+
</div>
|
|
277
|
+
);
|
|
278
|
+
return (
|
|
279
|
+
<ul ref={hold} className={cn(RULES, LIST)}>
|
|
280
|
+
{rules.map((rule) => (
|
|
281
|
+
<Fragment key={rule.id}>{rowOf(rule)}</Fragment>
|
|
282
|
+
))}
|
|
283
|
+
{act ? (
|
|
284
|
+
<li data-rule-add="" className={ADD}>
|
|
285
|
+
{act}
|
|
286
|
+
</li>
|
|
287
|
+
) : null}
|
|
288
|
+
</ul>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { IconLinkAct } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { LIST_BAND, text, textStrong } from "@slotform/ui-core/variants";
|
|
4
|
+
import { CountBase } from "../../atoms/count/base.tsx";
|
|
5
|
+
import type { IconAct } from "../../lib/act.ts";
|
|
6
|
+
import { IconActFace } from "../button/face.tsx";
|
|
7
|
+
|
|
8
|
+
// The row hairline the sheet draws under its children (`DIVIDER`) is not the
|
|
9
|
+
// band's: the band closes with its own rule.
|
|
10
|
+
const BAND = "flex items-center after:hidden";
|
|
11
|
+
// The label and its count stand together, the act at the end.
|
|
12
|
+
const NAME = "flex items-center min-w-0 grow gap-gap";
|
|
13
|
+
const LABEL = "truncate min-w-0";
|
|
14
|
+
|
|
15
|
+
/** A band: its label, the count of its rows (none when it has none) and its act. Outside the package's exports; the Section draws it. */
|
|
16
|
+
export function BandHead(props: {
|
|
17
|
+
label: string;
|
|
18
|
+
count: number;
|
|
19
|
+
act?: IconAct | IconLinkAct;
|
|
20
|
+
}) {
|
|
21
|
+
const { act } = props;
|
|
22
|
+
return (
|
|
23
|
+
<div className={cn(LIST_BAND, BAND)}>
|
|
24
|
+
<span className={NAME}>
|
|
25
|
+
<span
|
|
26
|
+
className={cn(
|
|
27
|
+
text({ role: "body" }),
|
|
28
|
+
textStrong({ role: "body" }),
|
|
29
|
+
LABEL,
|
|
30
|
+
)}
|
|
31
|
+
>
|
|
32
|
+
{props.label}
|
|
33
|
+
</span>
|
|
34
|
+
{props.count > 0 ? <CountBase value={props.count} /> : null}
|
|
35
|
+
</span>
|
|
36
|
+
{act ? <IconActFace act={act} /> : null}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|