@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,319 @@
|
|
|
1
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
2
|
+
import { Menu as Control } from "@base-ui/react/menu";
|
|
3
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
4
|
+
import {
|
|
5
|
+
LAYER_POPOVER,
|
|
6
|
+
menu,
|
|
7
|
+
menuGroup,
|
|
8
|
+
menuLabel,
|
|
9
|
+
OPTION_ROW,
|
|
10
|
+
POPOVER,
|
|
11
|
+
row,
|
|
12
|
+
text,
|
|
13
|
+
} from "@slotform/ui-core/variants";
|
|
14
|
+
import { type KeyboardEvent, type ReactNode, use, useState } from "react";
|
|
15
|
+
import { IconButtonBase } from "../../atoms/button/glyph.tsx";
|
|
16
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
17
|
+
import type { MenuEntry } from "../../lib/act.ts";
|
|
18
|
+
import { useAct } from "../../lib/act.ts";
|
|
19
|
+
import { expandedTrigger, rememberOpener } from "../../lib/focus.ts";
|
|
20
|
+
import { useQuietGuards } from "../../lib/guards.ts";
|
|
21
|
+
import { spacing } from "../../lib/measure.ts";
|
|
22
|
+
import { useTouch } from "../../lib/media.ts";
|
|
23
|
+
import { follow } from "../../lib/navigate.ts";
|
|
24
|
+
import { PortalContainer } from "../../lib/portal.ts";
|
|
25
|
+
import { SheetHead } from "../sheet/head.tsx";
|
|
26
|
+
import { SheetLayer } from "../sheet/layer.tsx";
|
|
27
|
+
|
|
28
|
+
// Base UI focuses the popup itself after a pointer open; its rows carry the ring.
|
|
29
|
+
const POPUP = "flex flex-col outline-none";
|
|
30
|
+
const POSITIONER = "z-(--layer-popover)";
|
|
31
|
+
const GROUP = "flex flex-col";
|
|
32
|
+
// A row the keyboard reaches rings inset over its wash, which alone sits
|
|
33
|
+
// under the 3:1 a state needs; the pointer's highlight is the wash alone.
|
|
34
|
+
const ITEM = "flex items-center focus-visible:-outline-offset-2";
|
|
35
|
+
const PRESS = "active:bg-wash-press";
|
|
36
|
+
// A touch row is a button: the start of its line, and its focus the
|
|
37
|
+
// keyboard's highlight.
|
|
38
|
+
const BUTTON = "text-start focus-visible:bg-wash-hover";
|
|
39
|
+
const GLYPH = "flex shrink-0";
|
|
40
|
+
const GLYPH_INK = {
|
|
41
|
+
act: "text-ink-meta",
|
|
42
|
+
destructive: "text-danger",
|
|
43
|
+
blocked: "text-ink-disabled",
|
|
44
|
+
} as const;
|
|
45
|
+
const LABEL = "min-w-0 grow truncate";
|
|
46
|
+
const LABEL_BLOCKED = "truncate text-ink-disabled";
|
|
47
|
+
const TEXT = "flex flex-col min-w-0 grow";
|
|
48
|
+
|
|
49
|
+
// A link entry goes to a route: it is never blocked and removes nothing.
|
|
50
|
+
const blockedOf = (item: MenuEntry) =>
|
|
51
|
+
"blocked" in item ? item.blocked : undefined;
|
|
52
|
+
const destructiveOf = (item: MenuEntry) =>
|
|
53
|
+
"destructive" in item && item.destructive === true;
|
|
54
|
+
|
|
55
|
+
// Each item keeps its place in the list, which keys it: two items may share
|
|
56
|
+
// a label.
|
|
57
|
+
function groupsOf(items: readonly MenuEntry[]) {
|
|
58
|
+
const placed = items.map((item, at) => ({ item, at }));
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
kind: "acts" as const,
|
|
62
|
+
items: placed.filter(({ item }) => !destructiveOf(item)),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
kind: "destructive" as const,
|
|
66
|
+
items: placed.filter(({ item }) => destructiveOf(item)),
|
|
67
|
+
},
|
|
68
|
+
].filter((group) => group.items.length > 0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// An item's glyph, its label and, blocked, its reason under the label.
|
|
72
|
+
function ItemLine(props: { item: MenuEntry }) {
|
|
73
|
+
const { item } = props;
|
|
74
|
+
const blocked = blockedOf(item) !== undefined;
|
|
75
|
+
const kind = destructiveOf(item) ? "destructive" : "act";
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{item.icon ? (
|
|
79
|
+
<span className={cn(GLYPH, GLYPH_INK[blocked ? "blocked" : kind])}>
|
|
80
|
+
<Icon name={item.icon} />
|
|
81
|
+
</span>
|
|
82
|
+
) : null}
|
|
83
|
+
{blocked ? (
|
|
84
|
+
<span className={TEXT}>
|
|
85
|
+
<span
|
|
86
|
+
className={cn(
|
|
87
|
+
text({ role: "body" }),
|
|
88
|
+
menuLabel({ kind }),
|
|
89
|
+
LABEL_BLOCKED,
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
{item.label}
|
|
93
|
+
</span>
|
|
94
|
+
<span className={text({ role: "meta" })}>{blockedOf(item)}</span>
|
|
95
|
+
</span>
|
|
96
|
+
) : (
|
|
97
|
+
<span
|
|
98
|
+
className={cn(text({ role: "body" }), menuLabel({ kind }), LABEL)}
|
|
99
|
+
>
|
|
100
|
+
{item.label}
|
|
101
|
+
</span>
|
|
102
|
+
)}
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function rowOf(item: MenuEntry, highlighted: boolean): string {
|
|
108
|
+
const blocked = blockedOf(item) !== undefined;
|
|
109
|
+
return cn(
|
|
110
|
+
row({ state: highlighted && !blocked ? "highlighted" : "rest" }),
|
|
111
|
+
OPTION_ROW,
|
|
112
|
+
ITEM,
|
|
113
|
+
!blocked && PRESS,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The row each key moves the focus to, from the row at `at` of `count`.
|
|
118
|
+
const MOVES: Record<string, (at: number, count: number) => number> = {
|
|
119
|
+
ArrowDown: (at, count) => (at + 1) % count,
|
|
120
|
+
// From the first row or from none, ArrowUp lands on the last.
|
|
121
|
+
ArrowUp: (at, count) => (at <= 0 ? count : at) - 1,
|
|
122
|
+
Home: () => 0,
|
|
123
|
+
End: (_, count) => count - 1,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// The touch sheet's rows are buttons the arrow keys, Home and End move
|
|
127
|
+
// through, the way a popover's rows move under Base UI.
|
|
128
|
+
function moveFocus(event: KeyboardEvent<HTMLElement>): void {
|
|
129
|
+
const move = MOVES[event.key];
|
|
130
|
+
if (!move) return;
|
|
131
|
+
const rows = [
|
|
132
|
+
...event.currentTarget.querySelectorAll<HTMLElement>('[role="menuitem"]'),
|
|
133
|
+
];
|
|
134
|
+
const focused = document.activeElement;
|
|
135
|
+
const at = focused instanceof HTMLElement ? rows.indexOf(focused) : -1;
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
rows[move(at, rows.length)]?.focus();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function Groups(props: {
|
|
141
|
+
items: readonly MenuEntry[];
|
|
142
|
+
item: (item: MenuEntry, at: number) => ReactNode;
|
|
143
|
+
}) {
|
|
144
|
+
return groupsOf(props.items).map((group, index) => (
|
|
145
|
+
<div
|
|
146
|
+
key={group.kind}
|
|
147
|
+
className={cn(
|
|
148
|
+
menuGroup({ place: index === 0 ? "first" : "after" }),
|
|
149
|
+
GROUP,
|
|
150
|
+
)}
|
|
151
|
+
>
|
|
152
|
+
{group.items.map(({ item, at }) => props.item(item, at))}
|
|
153
|
+
</div>
|
|
154
|
+
));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// The more act named `label` and its acts, the touch sheet titled `title`:
|
|
158
|
+
// a row's menu is titled with the row's name. It holds its items' run, the
|
|
159
|
+
// trigger drawn pending while one runs. `painted` is the trigger while
|
|
160
|
+
// its data is not here: its box filled, inert, so nothing opens. Outside the
|
|
161
|
+
// package's exports.
|
|
162
|
+
export function MenuBase({
|
|
163
|
+
label,
|
|
164
|
+
title,
|
|
165
|
+
items,
|
|
166
|
+
painted,
|
|
167
|
+
tabIndex,
|
|
168
|
+
}: {
|
|
169
|
+
label: string;
|
|
170
|
+
title: string;
|
|
171
|
+
items: readonly MenuEntry[];
|
|
172
|
+
painted?: boolean;
|
|
173
|
+
/** `-1` where the trigger's host holds the tab stop (a tree's row); absent, the trigger keeps its own. */
|
|
174
|
+
tabIndex?: -1;
|
|
175
|
+
}) {
|
|
176
|
+
const touch = useTouch();
|
|
177
|
+
const container = use(PortalContainer);
|
|
178
|
+
useQuietGuards();
|
|
179
|
+
const acting = useAct<number>("toast");
|
|
180
|
+
const pending = acting.pending !== undefined;
|
|
181
|
+
const [open, setOpen] = useState(false);
|
|
182
|
+
const [sheet] = useState(() => Dialog.createHandle<unknown>());
|
|
183
|
+
if (touch) {
|
|
184
|
+
return (
|
|
185
|
+
<>
|
|
186
|
+
<Dialog.Trigger
|
|
187
|
+
handle={sheet}
|
|
188
|
+
render={
|
|
189
|
+
<IconButtonBase
|
|
190
|
+
icon="Ellipsis"
|
|
191
|
+
label={label}
|
|
192
|
+
painted={painted}
|
|
193
|
+
pending={pending}
|
|
194
|
+
tabIndex={tabIndex}
|
|
195
|
+
/>
|
|
196
|
+
}
|
|
197
|
+
/>
|
|
198
|
+
<SheetLayer
|
|
199
|
+
handle={sheet}
|
|
200
|
+
open={open}
|
|
201
|
+
onOpen={() => setOpen(true)}
|
|
202
|
+
onClose={() => setOpen(false)}
|
|
203
|
+
>
|
|
204
|
+
<SheetHead title={title} onClose={() => setOpen(false)} />
|
|
205
|
+
<div
|
|
206
|
+
role="menu"
|
|
207
|
+
aria-label={label}
|
|
208
|
+
onKeyDown={moveFocus}
|
|
209
|
+
className={cn(menu({ lines: "sheet" }), POPUP)}
|
|
210
|
+
>
|
|
211
|
+
<Groups
|
|
212
|
+
items={items}
|
|
213
|
+
item={(item, at) =>
|
|
214
|
+
"href" in item ? (
|
|
215
|
+
<a
|
|
216
|
+
key={at}
|
|
217
|
+
href={item.href}
|
|
218
|
+
role="menuitem"
|
|
219
|
+
onClick={(event) => {
|
|
220
|
+
rememberOpener(expandedTrigger());
|
|
221
|
+
setOpen(false);
|
|
222
|
+
follow(event);
|
|
223
|
+
}}
|
|
224
|
+
className={cn(rowOf(item, false), BUTTON)}
|
|
225
|
+
>
|
|
226
|
+
<ItemLine item={item} />
|
|
227
|
+
</a>
|
|
228
|
+
) : (
|
|
229
|
+
<button
|
|
230
|
+
key={at}
|
|
231
|
+
type="button"
|
|
232
|
+
role="menuitem"
|
|
233
|
+
aria-disabled={item.blocked !== undefined || undefined}
|
|
234
|
+
onClick={() => {
|
|
235
|
+
if (item.blocked !== undefined) return;
|
|
236
|
+
rememberOpener(expandedTrigger());
|
|
237
|
+
setOpen(false);
|
|
238
|
+
acting.attempt(at, item);
|
|
239
|
+
}}
|
|
240
|
+
className={cn(rowOf(item, false), BUTTON)}
|
|
241
|
+
>
|
|
242
|
+
<ItemLine item={item} />
|
|
243
|
+
</button>
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
/>
|
|
247
|
+
</div>
|
|
248
|
+
</SheetLayer>
|
|
249
|
+
</>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return (
|
|
253
|
+
<Control.Root modal={false}>
|
|
254
|
+
<Control.Trigger
|
|
255
|
+
render={
|
|
256
|
+
<IconButtonBase
|
|
257
|
+
icon="Ellipsis"
|
|
258
|
+
label={label}
|
|
259
|
+
painted={painted}
|
|
260
|
+
pending={pending}
|
|
261
|
+
tabIndex={tabIndex}
|
|
262
|
+
/>
|
|
263
|
+
}
|
|
264
|
+
/>
|
|
265
|
+
<Control.Portal container={container}>
|
|
266
|
+
<Control.Positioner
|
|
267
|
+
className={POSITIONER}
|
|
268
|
+
align="end"
|
|
269
|
+
sideOffset={() => spacing("gap")}
|
|
270
|
+
>
|
|
271
|
+
<Control.Popup
|
|
272
|
+
className={cn(
|
|
273
|
+
POPOVER,
|
|
274
|
+
menu({ lines: "popover" }),
|
|
275
|
+
POPUP,
|
|
276
|
+
LAYER_POPOVER,
|
|
277
|
+
)}
|
|
278
|
+
>
|
|
279
|
+
<Groups
|
|
280
|
+
items={items}
|
|
281
|
+
item={(item, at) =>
|
|
282
|
+
"href" in item ? (
|
|
283
|
+
<Control.LinkItem
|
|
284
|
+
key={at}
|
|
285
|
+
label={item.label}
|
|
286
|
+
href={item.href}
|
|
287
|
+
// A link entry closes its menu as the touch sheet's does: the
|
|
288
|
+
// route it opens may keep the menu's Pane mounted.
|
|
289
|
+
closeOnClick
|
|
290
|
+
onClick={(event) => {
|
|
291
|
+
rememberOpener(expandedTrigger());
|
|
292
|
+
follow(event);
|
|
293
|
+
}}
|
|
294
|
+
className={(state) => rowOf(item, state.highlighted)}
|
|
295
|
+
>
|
|
296
|
+
<ItemLine item={item} />
|
|
297
|
+
</Control.LinkItem>
|
|
298
|
+
) : (
|
|
299
|
+
<Control.Item
|
|
300
|
+
key={at}
|
|
301
|
+
label={item.label}
|
|
302
|
+
onClick={() => {
|
|
303
|
+
rememberOpener(expandedTrigger());
|
|
304
|
+
acting.attempt(at, item);
|
|
305
|
+
}}
|
|
306
|
+
disabled={item.blocked !== undefined}
|
|
307
|
+
className={(state) => rowOf(item, state.highlighted)}
|
|
308
|
+
>
|
|
309
|
+
<ItemLine item={item} />
|
|
310
|
+
</Control.Item>
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
/>
|
|
314
|
+
</Control.Popup>
|
|
315
|
+
</Control.Positioner>
|
|
316
|
+
</Control.Portal>
|
|
317
|
+
</Control.Root>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { Attachment } from "@slotform/ui-core/descriptors";
|
|
4
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
5
|
+
import {
|
|
6
|
+
ANSWER,
|
|
7
|
+
BLOCK_IN,
|
|
8
|
+
IMAGE_REMOVE,
|
|
9
|
+
IMAGE_REMOVE_DISC,
|
|
10
|
+
MESSAGE_ATTACHMENTS,
|
|
11
|
+
REMOVE_HIT,
|
|
12
|
+
} from "@slotform/ui-core/variants";
|
|
13
|
+
import type { ReactNode, RefObject } from "react";
|
|
14
|
+
import { useRef } from "react";
|
|
15
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
16
|
+
import { CHIP_LINES } from "../../lib/chip-lines.ts";
|
|
17
|
+
import { Chip } from "../chip/index.tsx";
|
|
18
|
+
import { Image } from "../image/index.tsx";
|
|
19
|
+
|
|
20
|
+
// Items align to the start, so a chip keeps its own height beside a thumbnail.
|
|
21
|
+
const ROW = "flex flex-wrap items-start max-w-full";
|
|
22
|
+
const END = "justify-end";
|
|
23
|
+
const ITEM = "relative flex min-w-0";
|
|
24
|
+
// The remove act stands at the thumbnail's corner: its hit box centres the
|
|
25
|
+
// disc, and the washes of the pointer fill the disc.
|
|
26
|
+
const HIT =
|
|
27
|
+
"group absolute top-0 end-0 flex items-center justify-center focus-visible:-outline-offset-2";
|
|
28
|
+
const DISC = "flex overflow-hidden";
|
|
29
|
+
const WASH = `flex grow items-center justify-center text-ink-meta ${ANSWER} group-hover:bg-wash-hover group-active:bg-wash-press`;
|
|
30
|
+
|
|
31
|
+
// One attachment: a block of the row. A removable one (a message input's) is
|
|
32
|
+
// named for the page's block move and fades in as it mounts, and the viewer's
|
|
33
|
+
// remove runs in that move.
|
|
34
|
+
function Item(props: { removable: boolean; children: ReactNode }) {
|
|
35
|
+
return (
|
|
36
|
+
<div className={cn(ITEM, props.removable && BLOCK_IN)}>
|
|
37
|
+
{props.children}
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A message's attachments and a message input's, in one wrapping row. An
|
|
43
|
+
// attachment with `src` is an `Image` thumbnail, one without a chip of its
|
|
44
|
+
// name; each carries a remove act only when `onRemove` is given, and a removed
|
|
45
|
+
// one hands focus to the next attachment's remove act, else the previous
|
|
46
|
+
// one's, else `fallback`. Outside the package's exports.
|
|
47
|
+
export function Attachments(props: {
|
|
48
|
+
attachments: readonly Attachment[];
|
|
49
|
+
// The row stands at the end of its line, under your own message.
|
|
50
|
+
end?: boolean;
|
|
51
|
+
onRemove?: (id: string) => void;
|
|
52
|
+
fallback?: RefObject<HTMLElement | null>;
|
|
53
|
+
}) {
|
|
54
|
+
const { attachments, end, onRemove, fallback } = props;
|
|
55
|
+
const words = useWords();
|
|
56
|
+
const row = useRef<HTMLDivElement>(null);
|
|
57
|
+
// Each attachment's last button is its remove act: the open act of a
|
|
58
|
+
// thumbnail comes first.
|
|
59
|
+
const remove = (id: string, index: number) => {
|
|
60
|
+
const items = row.current?.children;
|
|
61
|
+
const near = items?.[index + 1] ?? items?.[index - 1];
|
|
62
|
+
const next = [...(near?.querySelectorAll("button") ?? [])].at(-1);
|
|
63
|
+
onRemove?.(id);
|
|
64
|
+
(next ?? fallback?.current)?.focus();
|
|
65
|
+
};
|
|
66
|
+
return (
|
|
67
|
+
<div
|
|
68
|
+
ref={row}
|
|
69
|
+
className={cn(MESSAGE_ATTACHMENTS, ROW, CHIP_LINES, end && END)}
|
|
70
|
+
>
|
|
71
|
+
{attachments.map((attachment, index) => (
|
|
72
|
+
<Item key={attachment.id} removable={onRemove !== undefined}>
|
|
73
|
+
{attachment.src ? (
|
|
74
|
+
<>
|
|
75
|
+
<Image src={attachment.src} alt={attachment.name} fit="thumb" />
|
|
76
|
+
{onRemove ? (
|
|
77
|
+
<BaseButton
|
|
78
|
+
aria-label={`${words.remove} ${attachment.name}`}
|
|
79
|
+
onClick={() => remove(attachment.id, index)}
|
|
80
|
+
className={cn(IMAGE_REMOVE, HIT)}
|
|
81
|
+
>
|
|
82
|
+
<span className={cn(REMOVE_HIT, IMAGE_REMOVE_DISC, DISC)}>
|
|
83
|
+
<span className={WASH}>
|
|
84
|
+
<Icon name="X" fit="meta" />
|
|
85
|
+
</span>
|
|
86
|
+
</span>
|
|
87
|
+
</BaseButton>
|
|
88
|
+
) : null}
|
|
89
|
+
</>
|
|
90
|
+
) : (
|
|
91
|
+
<Chip
|
|
92
|
+
family="neutral"
|
|
93
|
+
label={attachment.name}
|
|
94
|
+
onRemove={onRemove && (() => remove(attachment.id, index))}
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
</Item>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { Message, MessageDetail } from "@slotform/ui-core/descriptors";
|
|
4
|
+
import { factParts, filled } from "@slotform/ui-core/runs";
|
|
5
|
+
import { closeOpenRuns } from "@slotform/ui-core/streaming";
|
|
6
|
+
import {
|
|
7
|
+
CARD,
|
|
8
|
+
FIGURES,
|
|
9
|
+
MESSAGE_BUBBLE,
|
|
10
|
+
MESSAGE_CODE,
|
|
11
|
+
MESSAGE_ENTRY,
|
|
12
|
+
MESSAGE_FOLD,
|
|
13
|
+
MESSAGE_HEAD,
|
|
14
|
+
MESSAGE_LINE,
|
|
15
|
+
MESSAGE_OPEN,
|
|
16
|
+
message,
|
|
17
|
+
PRESS_WASH,
|
|
18
|
+
STREAM_IN,
|
|
19
|
+
text,
|
|
20
|
+
textStrong,
|
|
21
|
+
} from "@slotform/ui-core/variants";
|
|
22
|
+
import { memo, type ReactNode, useId, useState } from "react";
|
|
23
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
24
|
+
import { PaintedProse } from "../../atoms/prose/painted.tsx";
|
|
25
|
+
import { Turn } from "../../atoms/turn.tsx";
|
|
26
|
+
import { RunText } from "../../lib/code.tsx";
|
|
27
|
+
import { moment } from "../../lib/moment.ts";
|
|
28
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
29
|
+
import { PartsLine } from "../../lib/parts-line.tsx";
|
|
30
|
+
import { Prose } from "../prose/index.tsx";
|
|
31
|
+
import { RowBase } from "../row/index.tsx";
|
|
32
|
+
import { Attachments } from "./attachments.tsx";
|
|
33
|
+
|
|
34
|
+
const STACK = "flex flex-col";
|
|
35
|
+
const YOURS = "flex flex-col items-end";
|
|
36
|
+
// The line centred; a free act's code or an open fold's lines under it
|
|
37
|
+
// start-aligned across the column.
|
|
38
|
+
const SYSTEM = "flex flex-col items-center justify-center text-center";
|
|
39
|
+
// Each wraps at its spaces, breaking a token only when it outruns the line.
|
|
40
|
+
const DETAIL = "self-stretch text-start whitespace-pre-wrap";
|
|
41
|
+
const FRAMED = "flex flex-col overflow-hidden";
|
|
42
|
+
const LINE_TEXT = "inline-flex flex-wrap justify-center min-w-0";
|
|
43
|
+
const OPEN = cn("inline-flex items-center min-w-0", PRESS_WASH);
|
|
44
|
+
const HEAD = "flex items-baseline";
|
|
45
|
+
const BUBBLE = "max-w-4/5";
|
|
46
|
+
// A token too long for the line (a link, a hash) breaks anywhere.
|
|
47
|
+
const BODY = "whitespace-pre-wrap";
|
|
48
|
+
const WORDS = "min-w-0";
|
|
49
|
+
const TRAIL_END = "max-w-4/5 text-end";
|
|
50
|
+
// A time reads as one unit: it never shrinks or breaks beside a long line.
|
|
51
|
+
const TIME = "shrink-0 whitespace-nowrap";
|
|
52
|
+
|
|
53
|
+
// A system line and its detail: the fold's toggle over its lines, or the line
|
|
54
|
+
// (an act with `onOpen`) over the code, the line centred and the detail
|
|
55
|
+
// start-aligned across the column; a row's hairline card stands under them.
|
|
56
|
+
function SystemMessage(props: {
|
|
57
|
+
body: string;
|
|
58
|
+
time: ReactNode;
|
|
59
|
+
onOpen?: () => void;
|
|
60
|
+
detail?: MessageDetail;
|
|
61
|
+
arrives?: boolean;
|
|
62
|
+
}) {
|
|
63
|
+
const { body, time, onOpen, detail, arrives } = props;
|
|
64
|
+
const [open, setOpen] = useState(false);
|
|
65
|
+
const linesId = useId();
|
|
66
|
+
// The fold opens and closes as a block: the lines come in or go and what
|
|
67
|
+
// follows moves with them.
|
|
68
|
+
const words = (
|
|
69
|
+
<span className={cn(text({ role: "meta" }), WORDS)}>{body}</span>
|
|
70
|
+
);
|
|
71
|
+
let line = (
|
|
72
|
+
<p className={cn(MESSAGE_LINE, LINE_TEXT)}>
|
|
73
|
+
{words}
|
|
74
|
+
{time}
|
|
75
|
+
</p>
|
|
76
|
+
);
|
|
77
|
+
if (detail?.fold !== undefined)
|
|
78
|
+
line = (
|
|
79
|
+
<BaseButton
|
|
80
|
+
aria-expanded={open}
|
|
81
|
+
aria-controls={linesId}
|
|
82
|
+
onClick={() => setOpen(!open)}
|
|
83
|
+
className={cn(MESSAGE_OPEN, OPEN)}
|
|
84
|
+
>
|
|
85
|
+
{words}
|
|
86
|
+
{time}
|
|
87
|
+
<Turn name="ChevronDown" fit="meta" turned={!open} by="quarter" />
|
|
88
|
+
</BaseButton>
|
|
89
|
+
);
|
|
90
|
+
else if (onOpen)
|
|
91
|
+
line = (
|
|
92
|
+
<BaseButton onClick={onOpen} className={cn(MESSAGE_OPEN, OPEN)}>
|
|
93
|
+
{words}
|
|
94
|
+
{time}
|
|
95
|
+
<Icon name="ChevronRight" fit="meta" />
|
|
96
|
+
</BaseButton>
|
|
97
|
+
);
|
|
98
|
+
const centred = (
|
|
99
|
+
<div
|
|
100
|
+
className={cn(
|
|
101
|
+
message({ author: "system" }),
|
|
102
|
+
SYSTEM,
|
|
103
|
+
arrives && !detail?.row && STREAM_IN,
|
|
104
|
+
)}
|
|
105
|
+
>
|
|
106
|
+
{line}
|
|
107
|
+
{detail?.code === undefined ? null : (
|
|
108
|
+
<code className={cn(text({ role: "code" }), MESSAGE_CODE, DETAIL)}>
|
|
109
|
+
{detail.code}
|
|
110
|
+
</code>
|
|
111
|
+
)}
|
|
112
|
+
{detail?.fold === undefined ? null : (
|
|
113
|
+
<p
|
|
114
|
+
id={linesId}
|
|
115
|
+
hidden={!open}
|
|
116
|
+
className={cn(text({ role: "meta" }), MESSAGE_FOLD, DETAIL)}
|
|
117
|
+
>
|
|
118
|
+
{detail.fold}
|
|
119
|
+
</p>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
if (detail?.row === undefined) return centred;
|
|
124
|
+
return (
|
|
125
|
+
<div className={cn(MESSAGE_ENTRY, STACK, arrives && STREAM_IN)}>
|
|
126
|
+
{centred}
|
|
127
|
+
<div className={cn(CARD, FRAMED)}>
|
|
128
|
+
<RowBase {...detail.row} />
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** One turn as every Message draws it: a thread's `Message`, or `painted` (a turn while a thread's items are not here, inert: yours a bubble of one phrase's filler over the time's; the other author's its head, the name's filler and the time's, over one clipped line of filler where `name` is set, else that line over the time's filler). A named turn's time stands in its head beside the name; another's unnamed turn stands its time under it, as yours does. `arrives` is a turn that came to the end of a log on its own, which rises in (`STREAM_IN`). Memoised on its props, each compared by reference: a thread's re-render skips each message whose props are the same values as before. Outside the package's exports. */
|
|
135
|
+
export const MessageBase = memo(function MessageBase(
|
|
136
|
+
props:
|
|
137
|
+
| (Message & { arrives?: boolean })
|
|
138
|
+
| {
|
|
139
|
+
painted: true;
|
|
140
|
+
author: "you" | "other";
|
|
141
|
+
name?: boolean;
|
|
142
|
+
at?: number;
|
|
143
|
+
},
|
|
144
|
+
) {
|
|
145
|
+
// Painted, a turn stands as a short loaded one does: yours a bubble of one
|
|
146
|
+
// line over the time's filler; a reply its head (the name's filler and the
|
|
147
|
+
// time's) over one clipped line where the thread names its authors, else the
|
|
148
|
+
// line over the time's filler, so a log of short turns paints at its loaded
|
|
149
|
+
// height.
|
|
150
|
+
if ("painted" in props) {
|
|
151
|
+
const stamp = (
|
|
152
|
+
<span className={cn(text({ role: "meta" }), FIGURES, TIME)}>
|
|
153
|
+
<Painted role="figure" at={props.at} />
|
|
154
|
+
</span>
|
|
155
|
+
);
|
|
156
|
+
if (props.author === "you")
|
|
157
|
+
return (
|
|
158
|
+
<article inert className={cn(message({ author: "you" }), YOURS)}>
|
|
159
|
+
<div className={cn(MESSAGE_BUBBLE, BUBBLE)}>
|
|
160
|
+
<p className={text({ role: "body" })}>
|
|
161
|
+
<Painted role="phrase" at={props.at} />
|
|
162
|
+
</p>
|
|
163
|
+
</div>
|
|
164
|
+
{stamp}
|
|
165
|
+
</article>
|
|
166
|
+
);
|
|
167
|
+
return (
|
|
168
|
+
<article inert className={cn(message({ author: "other" }), STACK)}>
|
|
169
|
+
{props.name ? (
|
|
170
|
+
<p className={cn(MESSAGE_HEAD, HEAD)}>
|
|
171
|
+
<span
|
|
172
|
+
className={cn(
|
|
173
|
+
text({ role: "body" }),
|
|
174
|
+
textStrong({ role: "body" }),
|
|
175
|
+
)}
|
|
176
|
+
>
|
|
177
|
+
<Painted role="name" at={props.at} />
|
|
178
|
+
</span>
|
|
179
|
+
{stamp}
|
|
180
|
+
</p>
|
|
181
|
+
) : null}
|
|
182
|
+
<PaintedProse lines={1} at={props.at} />
|
|
183
|
+
{props.name ? null : <p className={HEAD}>{stamp}</p>}
|
|
184
|
+
</article>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const { author, body, at } = props;
|
|
188
|
+
const time = at ? (
|
|
189
|
+
<time dateTime={at} className={cn(text({ role: "meta" }), FIGURES, TIME)}>
|
|
190
|
+
{moment(at)}
|
|
191
|
+
</time>
|
|
192
|
+
) : null;
|
|
193
|
+
if (author === "system")
|
|
194
|
+
return (
|
|
195
|
+
<SystemMessage
|
|
196
|
+
body={body}
|
|
197
|
+
time={time}
|
|
198
|
+
onOpen={props.onOpen}
|
|
199
|
+
detail={props.detail}
|
|
200
|
+
arrives={props.arrives}
|
|
201
|
+
/>
|
|
202
|
+
);
|
|
203
|
+
const { name, attachments, from } = props;
|
|
204
|
+
const attached = attachments?.length ? (
|
|
205
|
+
<Attachments attachments={attachments} end={author === "you"} />
|
|
206
|
+
) : null;
|
|
207
|
+
// The provenance (`from`) is a text line, never badges: a sentence is text.
|
|
208
|
+
// It leads the time, one text a middle dot apart that breaks only between a
|
|
209
|
+
// part's words, never at a dot (`flow`): a line set to its end marks no
|
|
210
|
+
// line's start for a dot to be clipped at.
|
|
211
|
+
const line = from?.some(filled) ? (
|
|
212
|
+
<span
|
|
213
|
+
className={cn(
|
|
214
|
+
text({ role: "meta" }),
|
|
215
|
+
WORDS,
|
|
216
|
+
author === "you" && TRAIL_END,
|
|
217
|
+
)}
|
|
218
|
+
>
|
|
219
|
+
<PartsLine
|
|
220
|
+
parts={[
|
|
221
|
+
...factParts(from).map((runs, at) => (
|
|
222
|
+
<RunText key={at} runs={runs} whole fit="name" />
|
|
223
|
+
)),
|
|
224
|
+
...(time ? [time] : []),
|
|
225
|
+
]}
|
|
226
|
+
/>
|
|
227
|
+
</span>
|
|
228
|
+
) : (
|
|
229
|
+
time
|
|
230
|
+
);
|
|
231
|
+
if (author === "you")
|
|
232
|
+
return (
|
|
233
|
+
<article
|
|
234
|
+
className={cn(message({ author }), YOURS, props.arrives && STREAM_IN)}
|
|
235
|
+
>
|
|
236
|
+
{attached}
|
|
237
|
+
{body ? (
|
|
238
|
+
<div className={cn(MESSAGE_BUBBLE, BUBBLE)}>
|
|
239
|
+
<p className={cn(text({ role: "body" }), BODY)}>{body}</p>
|
|
240
|
+
</div>
|
|
241
|
+
) : null}
|
|
242
|
+
{line}
|
|
243
|
+
</article>
|
|
244
|
+
);
|
|
245
|
+
return (
|
|
246
|
+
<article
|
|
247
|
+
className={cn(message({ author }), STACK, props.arrives && STREAM_IN)}
|
|
248
|
+
>
|
|
249
|
+
{name ? (
|
|
250
|
+
<p className={cn(MESSAGE_HEAD, HEAD)}>
|
|
251
|
+
<span
|
|
252
|
+
className={cn(text({ role: "body" }), textStrong({ role: "body" }))}
|
|
253
|
+
>
|
|
254
|
+
{name}
|
|
255
|
+
</span>
|
|
256
|
+
{line}
|
|
257
|
+
</p>
|
|
258
|
+
) : null}
|
|
259
|
+
{attached}
|
|
260
|
+
{body ? (
|
|
261
|
+
<Prose markdown={props.streaming ? closeOpenRuns(body) : body} />
|
|
262
|
+
) : null}
|
|
263
|
+
{name || !line ? null : <p className={HEAD}>{line}</p>}
|
|
264
|
+
</article>
|
|
265
|
+
);
|
|
266
|
+
});
|