@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,184 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { Runs } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { valueCut } from "@slotform/ui-core/list-state";
|
|
4
|
+
import {
|
|
5
|
+
CODE_NAME,
|
|
6
|
+
PROSE_CODESPAN,
|
|
7
|
+
textStrong,
|
|
8
|
+
} from "@slotform/ui-core/variants";
|
|
9
|
+
import { Fragment, type ReactNode } from "react";
|
|
10
|
+
import { boundPieces } from "./bound.ts";
|
|
11
|
+
|
|
12
|
+
// A whole value of code in the room its box leaves: the stem truncates to it
|
|
13
|
+
// and the tail stands whole (`valueCut`).
|
|
14
|
+
const CUT = "flex min-w-0";
|
|
15
|
+
const STEM = "min-w-0 truncate";
|
|
16
|
+
const TAIL = "shrink-0";
|
|
17
|
+
// A code run in a line of text: docs/architecture/plugins/react-ui.md, "Text".
|
|
18
|
+
const SPAN = "inline-block max-w-full align-bottom truncate";
|
|
19
|
+
const SPAN_WHOLE = "wrap-anywhere box-decoration-clone";
|
|
20
|
+
// Where a whole value of code may break before it breaks anywhere: after a run
|
|
21
|
+
// of a path's or a URL's separators (a slash, the query signs `?`, `&`, `=`
|
|
22
|
+
// and the fragment's `#`), which only a long path or URL carries, never inside
|
|
23
|
+
// a run of them (`../`, `://`) nor before a space, which breaks already. A
|
|
24
|
+
// name's dot, colon, underscore, hyphen, comma or semicolon offers none, so a
|
|
25
|
+
// short machine name in a sentence (`connection_timeout`) moves whole to the next
|
|
26
|
+
// line, as a word does, and breaks inside only where it alone is wider than
|
|
27
|
+
// the line.
|
|
28
|
+
const SEPARATED = /(?<=[/?&=#])(?=[^/?&=#\s])/;
|
|
29
|
+
// A hyphen that leads a word binds to the word after it: a flag (`--bg`) is one
|
|
30
|
+
// unbreakable piece, no wider than that word, and a line still breaks before
|
|
31
|
+
// it. A hyphen inside a word is the browser's own break, after the hyphen and
|
|
32
|
+
// never before it (`boundPieces`).
|
|
33
|
+
const PIECE = "whitespace-nowrap";
|
|
34
|
+
|
|
35
|
+
// An address (a word holding an `@`) breaks after its `@` and after each of its
|
|
36
|
+
// dots, so a name that wraps in a narrow row breaks between its parts
|
|
37
|
+
// (`reader.one@` / `example.com`), never inside one where its last letter would
|
|
38
|
+
// stand alone. A dot between digits or in a sentence's stop is no address's.
|
|
39
|
+
const ADDRESS = /\S*@\S*/g;
|
|
40
|
+
const PARTS = /(?<=[@.])(?=[^@.])/;
|
|
41
|
+
|
|
42
|
+
/** Text whose addresses carry a break opportunity after each `@` and dot (`<wbr>`, which adds no character to a copy or a selection); text with no address is returned as it is. Outside the package's exports. */
|
|
43
|
+
export function Soft({ text }: { text: string }): ReactNode {
|
|
44
|
+
if (!text.includes("@")) return text;
|
|
45
|
+
const out: ReactNode[] = [];
|
|
46
|
+
let at = 0;
|
|
47
|
+
for (const found of text.matchAll(ADDRESS)) {
|
|
48
|
+
out.push(text.slice(at, found.index));
|
|
49
|
+
found[0].split(PARTS).forEach((part, n) => {
|
|
50
|
+
if (n > 0) out.push(<wbr key={`${found.index}-${n}`} />);
|
|
51
|
+
out.push(part);
|
|
52
|
+
});
|
|
53
|
+
at = found.index + found[0].length;
|
|
54
|
+
}
|
|
55
|
+
out.push(text.slice(at));
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A text whose leading hyphens bind to the word after them (`--bg` never breaks after its hyphens); a hyphen inside a word breaks after it, as a browser's does, and a line never starts on one. Adds no character to a copy or a selection. Outside the package's exports. */
|
|
60
|
+
function CodeBound(props: { code: string; wraps?: boolean }) {
|
|
61
|
+
return boundPieces(props.code).map((part, at) =>
|
|
62
|
+
at % 2 === 1 ? (
|
|
63
|
+
<span key={at} className={PIECE}>
|
|
64
|
+
{part}
|
|
65
|
+
</span>
|
|
66
|
+
) : props.wraps ? (
|
|
67
|
+
<Soft key={at} text={part} />
|
|
68
|
+
) : (
|
|
69
|
+
part
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A whole value of code with a break opportunity after each run of its path and URL separators (`<wbr>`, which adds no character to a copy or a selection), so a path or a URL wider than its line breaks between segments and a short name moves whole; its box's `wrap-anywhere` breaks inside a segment only where that segment alone is wider than the line, never before a hyphen (`CodeBound`). Outside the package's exports. */
|
|
75
|
+
export function CodeWhole(props: { code: string }) {
|
|
76
|
+
return props.code.split(SEPARATED).map((part, at) => (
|
|
77
|
+
<Fragment key={at}>
|
|
78
|
+
{at > 0 ? <wbr /> : null}
|
|
79
|
+
<CodeBound code={part} />
|
|
80
|
+
</Fragment>
|
|
81
|
+
));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A span of code that is a whole title or meta part of a row: one value in the mono, bare (a machine name in a row is never boxed), cut in its middle to keep its start and its end (`valueCut`: a value with a space is words, cut at its end). Outside the package's exports. */
|
|
85
|
+
export function CodeCut(props: { code: string }) {
|
|
86
|
+
const { stem, tail } = valueCut(props.code);
|
|
87
|
+
return (
|
|
88
|
+
<code className={cn(CODE_NAME, CUT)}>
|
|
89
|
+
<span className={STEM}>{stem}</span>
|
|
90
|
+
{tail ? <span className={TAIL}>{tail}</span> : null}
|
|
91
|
+
</code>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A boxed code run in a sentence is one box, never two: it stands as an atom
|
|
96
|
+
// on its line (`inline-block`), moving whole to the next line while it fits and
|
|
97
|
+
// wrapping inside its own box only where it alone is wider than the line, at
|
|
98
|
+
// its path's or URL's separators (`CodeWhole`). Prose's inline code stands the
|
|
99
|
+
// same way.
|
|
100
|
+
const ATOM = "inline-block max-w-full";
|
|
101
|
+
const ATOM_WHOLE = "wrap-anywhere";
|
|
102
|
+
// Punctuation that opens or closes around a run (`(`, `)`, `.`) stays with it:
|
|
103
|
+
// the run and its marks are one atom whose marks take their own width, the
|
|
104
|
+
// opening one at the run's first line, the closing one at its last, so a long
|
|
105
|
+
// run never leaves a bracket alone on the line above or below. Only marks that
|
|
106
|
+
// touch the run: a space parts them.
|
|
107
|
+
const OPENS = /[([{“‘«]$/;
|
|
108
|
+
const CLOSES = /^[)\]}”’».,;:!?]+(?=\s|$)/;
|
|
109
|
+
const MARK = "shrink-0";
|
|
110
|
+
const MARK_LAST = "shrink-0 self-baseline-last";
|
|
111
|
+
const GLUED = "inline-flex max-w-full items-baseline";
|
|
112
|
+
const FLEX_CODE = "min-w-0";
|
|
113
|
+
|
|
114
|
+
/** Runs as one text: words, a `{ quoted }` run in typographic quotes, a `{ strong }` run at strong weight in the meta role, a `{ code }` run in the mono, which never cuts in its middle: boxed in the inline code style inside a sentence (`fit` `span`, the default), bare where the runs are a name, a crumb or a row's line (`fit` `name`); `whole` (a text read whole) wraps a code run inside its one box at its separators (`CodeWhole`) instead of cutting it at its end, and the brackets and the stop that touch a boxed run stay on its line with it. Outside the package's exports. */
|
|
115
|
+
export function RunText(props: {
|
|
116
|
+
runs: Runs;
|
|
117
|
+
whole?: boolean;
|
|
118
|
+
fit?: "span" | "name";
|
|
119
|
+
/** A flag in the words keeps its leading hyphens bound (`CodeBound`), and a hyphenated word breaks after a hyphen, never before one, so a title that wraps never starts a line on a hyphen. */
|
|
120
|
+
bound?: boolean;
|
|
121
|
+
/** A string in the words carries a break opportunity after each `@` and dot of an address (`Soft`): for a text that wraps (a title, a name); a text a bar or a badge truncates passes none, so its own cut takes it at its end. */
|
|
122
|
+
wraps?: boolean;
|
|
123
|
+
}) {
|
|
124
|
+
const { runs, whole, bound, wraps } = props;
|
|
125
|
+
const boxed = props.fit !== "name";
|
|
126
|
+
const look = boxed ? PROSE_CODESPAN : CODE_NAME;
|
|
127
|
+
// A boxed run is an atom of its line; a bare one flows as text.
|
|
128
|
+
const span = boxed
|
|
129
|
+
? whole
|
|
130
|
+
? cn(ATOM, ATOM_WHOLE)
|
|
131
|
+
: SPAN
|
|
132
|
+
: whole
|
|
133
|
+
? SPAN_WHOLE
|
|
134
|
+
: SPAN;
|
|
135
|
+
// The marks a boxed run takes from the strings around it.
|
|
136
|
+
const marks = runs.map((run, at) => {
|
|
137
|
+
const before = runs[at - 1];
|
|
138
|
+
const after = runs[at + 1];
|
|
139
|
+
if (!boxed || typeof run === "string" || !("code" in run))
|
|
140
|
+
return { open: "", close: "" };
|
|
141
|
+
return {
|
|
142
|
+
open: (typeof before === "string" && OPENS.exec(before)?.[0]) || "",
|
|
143
|
+
close: (typeof after === "string" && CLOSES.exec(after)?.[0]) || "",
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
return runs.map((run, at) => {
|
|
147
|
+
if (typeof run === "string") {
|
|
148
|
+
// The marks the code run before it and after it took are theirs.
|
|
149
|
+
const cut = marks[at - 1]?.close.length ?? 0;
|
|
150
|
+
const end = run.length - (marks[at + 1]?.open.length ?? 0);
|
|
151
|
+
const kept = run.slice(cut, end);
|
|
152
|
+
if (bound)
|
|
153
|
+
return (
|
|
154
|
+
<Fragment key={at}>
|
|
155
|
+
<CodeBound code={kept} wraps={wraps} />
|
|
156
|
+
</Fragment>
|
|
157
|
+
);
|
|
158
|
+
return wraps ? <Soft key={at} text={kept} /> : kept;
|
|
159
|
+
}
|
|
160
|
+
if ("quoted" in run) return `“${run.quoted}”`;
|
|
161
|
+
if ("code" in run) {
|
|
162
|
+
const { open, close } = marks[at] ?? { open: "", close: "" };
|
|
163
|
+
const text = whole ? <CodeWhole code={run.code} /> : run.code;
|
|
164
|
+
if (!open && !close)
|
|
165
|
+
return (
|
|
166
|
+
<code key={at} className={cn(look, span)}>
|
|
167
|
+
{text}
|
|
168
|
+
</code>
|
|
169
|
+
);
|
|
170
|
+
return (
|
|
171
|
+
<span key={at} className={GLUED}>
|
|
172
|
+
{open ? <span className={MARK}>{open}</span> : null}
|
|
173
|
+
<code className={cn(look, span, FLEX_CODE)}>{text}</code>
|
|
174
|
+
{close ? <span className={MARK_LAST}>{close}</span> : null}
|
|
175
|
+
</span>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return (
|
|
179
|
+
<span key={at} className={textStrong({ role: "meta" })}>
|
|
180
|
+
{run.strong}
|
|
181
|
+
</span>
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TableColumn } from "@slotform/ui-core/descriptors";
|
|
2
|
+
import {
|
|
3
|
+
type ColumnChoice,
|
|
4
|
+
columnsKey,
|
|
5
|
+
parseColumnChoice,
|
|
6
|
+
visibleColumns,
|
|
7
|
+
} from "@slotform/ui-core/list-state";
|
|
8
|
+
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
9
|
+
import { saveChoice, savedChoice, subscribeSaved } from "./saved.ts";
|
|
10
|
+
|
|
11
|
+
/** The columns a table stands with: what its consumer declared (`hidden`) under what the viewer chose, which `toggle` changes, `reset` clears and the browser keeps (the table's `label` names the choice, else its columns' keys do). Outside the package's exports. */
|
|
12
|
+
export function useColumns<C extends TableColumn>(
|
|
13
|
+
columns: readonly C[],
|
|
14
|
+
label: string | undefined,
|
|
15
|
+
): {
|
|
16
|
+
shown: readonly C[];
|
|
17
|
+
choice: ColumnChoice;
|
|
18
|
+
toggle: (key: string, on: boolean) => void;
|
|
19
|
+
reset: () => void;
|
|
20
|
+
} {
|
|
21
|
+
const key = columnsKey(columns, label);
|
|
22
|
+
const raw = useSyncExternalStore(
|
|
23
|
+
subscribeSaved,
|
|
24
|
+
() => savedChoice(key),
|
|
25
|
+
() => null,
|
|
26
|
+
);
|
|
27
|
+
const choice = useMemo(() => parseColumnChoice(raw), [raw]);
|
|
28
|
+
const shown = useMemo(
|
|
29
|
+
() => visibleColumns(columns, choice),
|
|
30
|
+
[columns, choice],
|
|
31
|
+
);
|
|
32
|
+
const toggle = useCallback(
|
|
33
|
+
(column: string, on: boolean) =>
|
|
34
|
+
saveChoice(key, JSON.stringify({ ...choice, [column]: on })),
|
|
35
|
+
[key, choice],
|
|
36
|
+
);
|
|
37
|
+
const reset = useCallback(() => saveChoice(key, "{}"), [key]);
|
|
38
|
+
return { shown, choice, toggle, reset };
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { commitMoment } from "@slotform/ui-core/commit";
|
|
2
|
+
import { type KeyboardEvent, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// A typing control's commit moments: docs/architecture/ui-core/acts.md, "Commit".
|
|
5
|
+
export function useCommit(
|
|
6
|
+
value: string,
|
|
7
|
+
onChange: (value: string) => void,
|
|
8
|
+
onCommit: ((value: string) => void) | undefined,
|
|
9
|
+
enter: boolean,
|
|
10
|
+
) {
|
|
11
|
+
const [moment] = useState(() => commitMoment<string>());
|
|
12
|
+
const commit = (next: string) => onCommit?.(next);
|
|
13
|
+
return {
|
|
14
|
+
onFocus: () => moment.focus(value),
|
|
15
|
+
onBlur: () => moment.leave(value, commit),
|
|
16
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
|
|
17
|
+
if (enter && event.key === "Enter") moment.commit(value, commit);
|
|
18
|
+
if (onCommit && event.key === "Escape") {
|
|
19
|
+
moment.cancel(value, onChange);
|
|
20
|
+
event.currentTarget.blur();
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { TrailPart } from "@slotform/ui-core/route";
|
|
2
|
+
import { DOCKED_LOG_FLOOR_ROWS } from "@slotform/ui-core/variants";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
type RefObject,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react";
|
|
9
|
+
import type { IconAct } from "./act.ts";
|
|
10
|
+
|
|
11
|
+
// The Shell's places-layer act, handed to the Pane: docs/architecture/ui-core/layout.md, "Container context".
|
|
12
|
+
export const ShellMenu = createContext<IconAct | undefined>(undefined);
|
|
13
|
+
|
|
14
|
+
// The Shell's trail (`placeTrail`), the current place last: a Pane draws the
|
|
15
|
+
// places above it, and a read with no Pane's `back` around it leads back to
|
|
16
|
+
// the last.
|
|
17
|
+
export const PlaceTrail = createContext<readonly TrailPart[]>([]);
|
|
18
|
+
|
|
19
|
+
// The route a Pane's back act returns to: docs/architecture/ui-core/layout.md, "Body".
|
|
20
|
+
export const BackRoute = createContext<string | undefined>(undefined);
|
|
21
|
+
|
|
22
|
+
// The two kinds of Pane a Panes holds, one of each at most: the place's own,
|
|
23
|
+
// and a record's after it.
|
|
24
|
+
export type PaneKind = "place" | "record";
|
|
25
|
+
|
|
26
|
+
// What a Panes hands its Panes: docs/architecture/ui-core/layout.md, "Panes".
|
|
27
|
+
export const PanesContainer = createContext<
|
|
28
|
+
| { name: string | undefined; stand: (kind: PaneKind) => () => void }
|
|
29
|
+
| undefined
|
|
30
|
+
>(undefined);
|
|
31
|
+
|
|
32
|
+
// Whether what draws stands in a Pane's body: the page for an unknown
|
|
33
|
+
// address under a record's Pane is that Pane's body, not a Pane of its own.
|
|
34
|
+
export const InPane = createContext(false);
|
|
35
|
+
|
|
36
|
+
// The id of the title that names what stands in a Pane or a Gate (the labelling
|
|
37
|
+
// a Thread's log and a Table's grid take).
|
|
38
|
+
export const PageTitle = createContext<string | undefined>(undefined);
|
|
39
|
+
|
|
40
|
+
// What a docked foot's region hands the docked `Sheet`: docs/architecture/ui-core/layout.md, "Container context".
|
|
41
|
+
export interface FootRegionValue {
|
|
42
|
+
height: number;
|
|
43
|
+
chrome: number;
|
|
44
|
+
logFloor: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const BLOCK_PADDING = ["paddingTop", "paddingBottom"] as const;
|
|
48
|
+
const BLOCK_SIDES = [
|
|
49
|
+
...BLOCK_PADDING,
|
|
50
|
+
"borderTopWidth",
|
|
51
|
+
"borderBottomWidth",
|
|
52
|
+
] as const;
|
|
53
|
+
|
|
54
|
+
function sum(
|
|
55
|
+
style: CSSStyleDeclaration,
|
|
56
|
+
sides: readonly (typeof BLOCK_SIDES)[number][],
|
|
57
|
+
): number {
|
|
58
|
+
return sides.reduce(
|
|
59
|
+
(total, side) => total + Number.parseFloat(style[side]),
|
|
60
|
+
0,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The block padding of the body over the foot: the foot is bounded by the
|
|
65
|
+
// region less it, so the body's insets stand even where the foot takes the
|
|
66
|
+
// rest.
|
|
67
|
+
function overPadding(node: HTMLElement | null | undefined): number {
|
|
68
|
+
return node ? sum(getComputedStyle(node), BLOCK_PADDING) : 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The region's measured value and the ref to put on it. `docked` is whether a docked sheet stands in the foot, the one reader of the value: the region is measured only while it does, so a region that grows with its content (a Thread among sections, a message landing) does not commit its owner a second time per update. `dock` is the foot's own node, which shares the region with a log; `over` is the body standing over the foot, whose block padding never gives way to it. */
|
|
72
|
+
export function useFootRegion(
|
|
73
|
+
docked: boolean,
|
|
74
|
+
dock: RefObject<HTMLElement | null>,
|
|
75
|
+
over?: RefObject<HTMLElement | null>,
|
|
76
|
+
) {
|
|
77
|
+
const [node, ref] = useState<HTMLElement | null>(null);
|
|
78
|
+
const [value, setValue] = useState<FootRegionValue>({
|
|
79
|
+
height: 0,
|
|
80
|
+
chrome: 0,
|
|
81
|
+
logFloor: 0,
|
|
82
|
+
});
|
|
83
|
+
// A sheet that docks is measured in the commit that draws it, before the
|
|
84
|
+
// paint, and the value it was last measured at stands until then.
|
|
85
|
+
useLayoutEffect(() => {
|
|
86
|
+
if (!node || !docked) return;
|
|
87
|
+
const measure = () => {
|
|
88
|
+
const style = dock.current ? getComputedStyle(dock.current) : null;
|
|
89
|
+
const next = {
|
|
90
|
+
height: Math.round(node.getBoundingClientRect().height),
|
|
91
|
+
chrome:
|
|
92
|
+
(style ? sum(style, BLOCK_SIDES) : 0) + overPadding(over?.current),
|
|
93
|
+
logFloor: style
|
|
94
|
+
? DOCKED_LOG_FLOOR_ROWS *
|
|
95
|
+
Number.parseFloat(style.getPropertyValue("--spacing-row"))
|
|
96
|
+
: 0,
|
|
97
|
+
};
|
|
98
|
+
setValue((last) =>
|
|
99
|
+
last.height === next.height &&
|
|
100
|
+
last.chrome === next.chrome &&
|
|
101
|
+
last.logFloor === next.logFloor
|
|
102
|
+
? last
|
|
103
|
+
: next,
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
measure();
|
|
107
|
+
const resize = new ResizeObserver(measure);
|
|
108
|
+
resize.observe(node);
|
|
109
|
+
return () => resize.disconnect();
|
|
110
|
+
}, [node, docked, dock, over]);
|
|
111
|
+
return { value, ref };
|
|
112
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { toast } from "./toast.ts";
|
|
4
|
+
|
|
5
|
+
const COPIED_MS = 2000;
|
|
6
|
+
|
|
7
|
+
// A copy act's write and its state: `copy(text)` writes to the clipboard and
|
|
8
|
+
// sets `done` for two seconds from the last copy (the act's check and the
|
|
9
|
+
// word Copied). A missing clipboard throws inside the chain and a refused one
|
|
10
|
+
// rejects; either raises a failed Toast and leaves the act at rest.
|
|
11
|
+
export function useCopy(): [done: boolean, copy: (text: string) => void] {
|
|
12
|
+
const words = useWords();
|
|
13
|
+
// Each copy is its own moment, counted, so the reset restarts on every one.
|
|
14
|
+
const [copied, setCopied] = useState(0);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (copied === 0) return;
|
|
17
|
+
const timer = setTimeout(() => setCopied(0), COPIED_MS);
|
|
18
|
+
return () => clearTimeout(timer);
|
|
19
|
+
}, [copied]);
|
|
20
|
+
const copy = (text: string) => {
|
|
21
|
+
Promise.resolve()
|
|
22
|
+
.then(() => navigator.clipboard.writeText(text))
|
|
23
|
+
.then(
|
|
24
|
+
() => setCopied((count) => count + 1),
|
|
25
|
+
() => toast(words.copyFailed, { tone: "failed" }),
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
return [copied > 0, copy];
|
|
29
|
+
}
|