@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,37 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { Run, Runs } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { isRun } from "@slotform/ui-core/runs";
|
|
4
|
+
import { type TextRole, text } from "@slotform/ui-core/variants";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
7
|
+
import { RunText } from "../../lib/code.tsx";
|
|
8
|
+
|
|
9
|
+
const MEASURE = "max-w-measure";
|
|
10
|
+
|
|
11
|
+
/** A paragraph of text in a type role. */
|
|
12
|
+
export interface TextProps extends Closed {
|
|
13
|
+
/** The type role: a primary line (`body`, the default) or a secondary one (`meta`). Not named `role`, which is the ARIA attribute: lint and tooling read that name as one. */
|
|
14
|
+
kind?: TextRole;
|
|
15
|
+
/** The text (text; wraps): words, links and inline acts (a `Button` at `fit: "inline"`, after the caption that asks for it), or runs, where a `{ strong }` run is words at weight 500 and a `{ code }` run a span of code. */
|
|
16
|
+
children?: ReactNode | Run | Runs;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function runsIn(children: TextProps["children"]): Runs | undefined {
|
|
20
|
+
if (Array.isArray(children) && children.every(isRun)) return children;
|
|
21
|
+
return typeof children === "object" && isRun(children)
|
|
22
|
+
? [children]
|
|
23
|
+
: undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A paragraph in the body or meta role; ink and family ride with the role. A run of emphasis inside it is a `{ strong }` run, at weight 500 and never a size change. */
|
|
27
|
+
export function Text({ kind, children }: TextProps) {
|
|
28
|
+
const runs = runsIn(children);
|
|
29
|
+
// A paragraph, never a span: a line inside a row is drawn by the row's own
|
|
30
|
+
// cells, so a Text stands on its own and holds the measure.
|
|
31
|
+
return (
|
|
32
|
+
<p className={cn(text({ role: kind ?? "body" }), MEASURE)}>
|
|
33
|
+
{/* Children `runsIn` leaves hold no run; its array check narrows nothing. */}
|
|
34
|
+
{runs ? <RunText runs={runs} /> : (children as ReactNode)}
|
|
35
|
+
</p>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import { stampsTime } from "@slotform/ui-core/clock";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type {
|
|
4
|
+
Attachment,
|
|
5
|
+
MessageDetail,
|
|
6
|
+
Runs,
|
|
7
|
+
} from "@slotform/ui-core/descriptors";
|
|
8
|
+
import type { ProcedureCall } from "@slotform/ui-core/form";
|
|
9
|
+
import { PAINT_TURNS } from "@slotform/ui-core/paint";
|
|
10
|
+
import { useArrivals } from "@slotform/ui-core/react/arrive";
|
|
11
|
+
import {
|
|
12
|
+
type Frame,
|
|
13
|
+
FrameHolds,
|
|
14
|
+
useCollection,
|
|
15
|
+
useFrameRead,
|
|
16
|
+
} from "@slotform/ui-core/react/read";
|
|
17
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
18
|
+
import {
|
|
19
|
+
type Datum,
|
|
20
|
+
type Drawn,
|
|
21
|
+
isEnded,
|
|
22
|
+
NO_HOLDS,
|
|
23
|
+
type Selection,
|
|
24
|
+
turnOf,
|
|
25
|
+
} from "@slotform/ui-core/read";
|
|
26
|
+
import { sameBy } from "@slotform/ui-core/same-by";
|
|
27
|
+
import { THREAD, THREAD_COLUMN } from "@slotform/ui-core/variants";
|
|
28
|
+
import {
|
|
29
|
+
memo,
|
|
30
|
+
type ReactElement,
|
|
31
|
+
type ReactNode,
|
|
32
|
+
type RefObject,
|
|
33
|
+
use,
|
|
34
|
+
useEffect,
|
|
35
|
+
useLayoutEffect,
|
|
36
|
+
useRef,
|
|
37
|
+
useState,
|
|
38
|
+
} from "react";
|
|
39
|
+
import { WaitingReply } from "../../atoms/message/waiting.tsx";
|
|
40
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
41
|
+
import { PageTitle, useFootRegion } from "../../lib/container.ts";
|
|
42
|
+
import type { Empty } from "../../lib/empty.tsx";
|
|
43
|
+
import { useFootFocus } from "../../lib/focus.ts";
|
|
44
|
+
import { useTouch } from "../../lib/media.ts";
|
|
45
|
+
import { FrameBody, FrameLine, StateLine, stillOf } from "../../lib/read.tsx";
|
|
46
|
+
import { useScrolls } from "../../lib/scrolls.ts";
|
|
47
|
+
import { Scroller, useScroller, Window } from "../../lib/window.tsx";
|
|
48
|
+
import { MessageBase } from "../message/base.tsx";
|
|
49
|
+
import {
|
|
50
|
+
MessageInput,
|
|
51
|
+
type MessageInputProps,
|
|
52
|
+
} from "../message-input/index.tsx";
|
|
53
|
+
import { SheetDocked } from "../sheet/docked.tsx";
|
|
54
|
+
import type { SheetProps } from "../sheet/index.tsx";
|
|
55
|
+
import { Latest } from "./latest.tsx";
|
|
56
|
+
|
|
57
|
+
/** The input under the messages. */
|
|
58
|
+
export type ComposerProps = MessageInputProps;
|
|
59
|
+
|
|
60
|
+
/** The input of a `Thread` drawn on its own, to give a `Pane`'s `foot` (a short run of text in a field, its attachments, the notice under it, Send and Stop; the props are the Thread's `composer`). A `Thread` standing among a Pane's sections gives its input to the Pane's foot this way where the field should stay in reach however long the page (on touch, above the tab bar), and draws none under its log (give it no `composer`); its `sheet` is then the Pane's. */
|
|
61
|
+
export function Composer(props: ComposerProps) {
|
|
62
|
+
return <MessageInput {...props} />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const STACK = "flex flex-col";
|
|
66
|
+
// The thread fills what it stands in by plain flex: in a Pane's body, whose
|
|
67
|
+
// height is definite, it takes the free height and its log scrolls; among
|
|
68
|
+
// sections it stands at its content's height. The input stands a sections
|
|
69
|
+
// gap under the log. With a foot its measurement bounds a docked sheet's body.
|
|
70
|
+
const FILL = "flex flex-col grow min-h-0";
|
|
71
|
+
// The region over the foot: the log, and the Latest act floating at its foot.
|
|
72
|
+
// It clips its height, so where the foot leaves it no room nothing it holds
|
|
73
|
+
// paints over the foot or the head.
|
|
74
|
+
const REGION = "relative flex flex-col grow min-h-0 overflow-y-clip";
|
|
75
|
+
// The log rings inset; it takes a tab stop only while it scrolls.
|
|
76
|
+
const SCROLLS =
|
|
77
|
+
"flex flex-col grow min-h-0 overflow-y-auto focus-visible:-outline-offset-2";
|
|
78
|
+
// What the foot holds shrinks to its bound, so a docked form scrolls inside it.
|
|
79
|
+
const FOOT = "flex flex-col shrink-0 min-h-0";
|
|
80
|
+
// The log is at its end while its last pixel shows; a reader who scrolled
|
|
81
|
+
// up keeps their place as a message arrives.
|
|
82
|
+
const AT_END = 1;
|
|
83
|
+
// The empty log's sentence stands centred in the room the messages would fill.
|
|
84
|
+
const EMPTY = "grow justify-center";
|
|
85
|
+
|
|
86
|
+
/** One function per `Message` region, each called with a loaded item and reading only it: a message draws again only when its item changes. */
|
|
87
|
+
export interface MessageRegions<T> {
|
|
88
|
+
/** The item's React key, unique in the thread. */
|
|
89
|
+
key: (item: T) => string;
|
|
90
|
+
/** Who said it: `you`, `other` or `system`. */
|
|
91
|
+
author: (item: T) => "you" | "other" | "system";
|
|
92
|
+
/** Who said it, by name: drawn over `other`'s reply, yours draws none; a system line takes none (a short phrase; wraps). */
|
|
93
|
+
name?: (item: T) => string | undefined;
|
|
94
|
+
/** What was said (text; wraps): plain text for `you` and `system`, markdown for `other`. */
|
|
95
|
+
body: (item: T) => string;
|
|
96
|
+
/** When it was said, an ISO moment: stamped on a turn whose turn before is another author's or in another minute, so a run of one author's turns in one minute reads its time once, on its first. */
|
|
97
|
+
at?: (item: T) => string | undefined;
|
|
98
|
+
/** What came with a turn: its attachments, one row over its bubble or reply; a system line takes none. */
|
|
99
|
+
attachments?: (item: T) => readonly Attachment[] | undefined;
|
|
100
|
+
/** Where a turn came from ("via email", "Front desk"), before its time; a system line takes none (each a short phrase; the line breaks between a part's words). */
|
|
101
|
+
from?: (item: T) => Runs | undefined;
|
|
102
|
+
/** The reply is still arriving: an `other` turn whose open Markdown marker at its end draws in its own form (see `Message`); a turn of yours or a system line takes none. */
|
|
103
|
+
streaming?: (item: T) => boolean | undefined;
|
|
104
|
+
/** What a system line opens: the line becomes the act; a turn takes none. */
|
|
105
|
+
onOpen?: (item: T) => (() => void) | undefined;
|
|
106
|
+
/** What stands under a system line (a row, a free act's code, a fold); a turn takes none. */
|
|
107
|
+
detail?: (item: T) => MessageDetail | undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A conversation: its messages from items, over the input that adds to it. */
|
|
111
|
+
export type ThreadProps<
|
|
112
|
+
T = unknown,
|
|
113
|
+
P extends ProcedureCall = ProcedureCall,
|
|
114
|
+
> = Closed & {
|
|
115
|
+
/** The items the messages draw, oldest first: constants, or a selection, which paints two turns until its read lands, an ask of yours over the other author's reply (`PAINT_TURNS`). A selection stands in a frame (a Pane, Section, Sheet or Form given the read), which draws the thread's failed, missing and empty shapes. */
|
|
116
|
+
items: Datum<readonly T[]>;
|
|
117
|
+
/** The `Message` regions. */
|
|
118
|
+
message: MessageRegions<T>;
|
|
119
|
+
/** The input under the messages, where a message is written and sent: what is written, its attachments, the notice under it, and the sending and stopping of an answer. A thread among a Pane's sections that should keep its field in reach gives none and the Pane's `foot` a `Composer`. */
|
|
120
|
+
composer?: ComposerProps;
|
|
121
|
+
/** A task over the input: while it is `open` it docks in the foot in the input's place, the log keeping two rows above it, and closing hands focus back to the input. Where the input is the Pane's foot, the sheet is the Pane's too. */
|
|
122
|
+
sheet?: SheetProps<P>;
|
|
123
|
+
/** A reply from the other author is on its way: the loaded log ends on one waiting message of theirs, until it is cleared. */
|
|
124
|
+
replying?: boolean;
|
|
125
|
+
/** The turn being written, a read the app declares (a stream: `streamRead` or `read(options, { kind: "stream" })`, whose `stop()` ends it and resolves with the partial value, or a slice of a channel read): it draws after the items from its own subscription, so a chunk renders only it. Waiting for the first chunk it is one waiting message of the other author; writing, the message with `streaming` set; written, the message. Held as a root read, a stream that failed after some text draws the partial message, then "The reply stopped." with Retry; one that failed before any text draws "This didn't load." with Retry. Retry runs the stream again. It hides once the last item has its key, so a history that catches up shows no second turn. `null` or `undefined` is no turn. */
|
|
126
|
+
reply?: Selection<T | null | undefined>;
|
|
127
|
+
/** What the log says when the `items` read is empty: the sentence and the act that makes the first message, centred where the messages would stand with the composer kept. Without one the log says the generic sentence. */
|
|
128
|
+
empty?: Empty;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// One message from its item, its Message by its author: a system line takes
|
|
132
|
+
// `onOpen` and `detail`, a turn takes `name`. It renders again only when its
|
|
133
|
+
// item does: every region reads the item, and a system line's acts call the
|
|
134
|
+
// thread's latest regions when pressed, so a thread's re-render (a keystroke in
|
|
135
|
+
// its input, a message arriving) skips every message already drawn.
|
|
136
|
+
function ThreadItemBase<T>({
|
|
137
|
+
item,
|
|
138
|
+
regions,
|
|
139
|
+
streaming,
|
|
140
|
+
arrives,
|
|
141
|
+
unstamped,
|
|
142
|
+
}: {
|
|
143
|
+
item: T;
|
|
144
|
+
regions: RefObject<MessageRegions<T>>;
|
|
145
|
+
// The reply turn's own, which overrides the region.
|
|
146
|
+
streaming?: boolean;
|
|
147
|
+
// It came to the end of the log on its own: it rises in as it mounts.
|
|
148
|
+
arrives?: boolean;
|
|
149
|
+
// The turn before it is its author's in the same minute: its time is not
|
|
150
|
+
// stamped again (`stampsTime`).
|
|
151
|
+
unstamped?: boolean;
|
|
152
|
+
}) {
|
|
153
|
+
// Held from the first render, so a later commit does not cut the rise short.
|
|
154
|
+
const [rises] = useState(arrives);
|
|
155
|
+
const read = regions.current;
|
|
156
|
+
const author = read.author(item);
|
|
157
|
+
const body = read.body(item);
|
|
158
|
+
const at = unstamped ? undefined : read.at?.(item);
|
|
159
|
+
if (author !== "system")
|
|
160
|
+
return (
|
|
161
|
+
<MessageBase
|
|
162
|
+
author={author}
|
|
163
|
+
arrives={rises}
|
|
164
|
+
name={read.name?.(item)}
|
|
165
|
+
body={body}
|
|
166
|
+
at={at}
|
|
167
|
+
attachments={read.attachments?.(item)}
|
|
168
|
+
from={read.from?.(item)}
|
|
169
|
+
streaming={
|
|
170
|
+
author === "other" ? (streaming ?? read.streaming?.(item)) : undefined
|
|
171
|
+
}
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
const opens = read.onOpen?.(item) !== undefined;
|
|
175
|
+
let detail = read.detail?.(item);
|
|
176
|
+
const row = detail?.row;
|
|
177
|
+
if (row?.onOpen)
|
|
178
|
+
detail = {
|
|
179
|
+
row: {
|
|
180
|
+
...row,
|
|
181
|
+
onOpen: () => regions.current.detail?.(item)?.row?.onOpen?.(),
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
return (
|
|
185
|
+
<MessageBase
|
|
186
|
+
author="system"
|
|
187
|
+
arrives={rises}
|
|
188
|
+
body={body}
|
|
189
|
+
at={at}
|
|
190
|
+
onOpen={opens ? () => regions.current.onOpen?.(item)?.() : undefined}
|
|
191
|
+
detail={detail}
|
|
192
|
+
/>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// `memo` erases the generic its component takes, so the memoised item keeps
|
|
197
|
+
// the base's own type.
|
|
198
|
+
const ThreadItem = memo(
|
|
199
|
+
ThreadItemBase,
|
|
200
|
+
sameBy("item"),
|
|
201
|
+
) as typeof ThreadItemBase;
|
|
202
|
+
|
|
203
|
+
// The key the waiting message is known by among the log's arrivals.
|
|
204
|
+
const WAITING = "replying";
|
|
205
|
+
|
|
206
|
+
// The turn being written, from its own subscription to the reply: a chunk
|
|
207
|
+
// renders this and nothing else in the thread. A stream that failed keeps its
|
|
208
|
+
// partial message and says it stopped, one that failed before any text says the
|
|
209
|
+
// read failed, each with the frame's retry, which runs the stream again. It
|
|
210
|
+
// stays mounted whenever there is a reply, so the items' fetch cycle never
|
|
211
|
+
// subscribes it or lets it go: a reply read that shares the items' failed read
|
|
212
|
+
// would otherwise refetch on each mount and loop.
|
|
213
|
+
function ReplyTurn<T>(props: {
|
|
214
|
+
reply: Selection<T | null | undefined>;
|
|
215
|
+
regions: RefObject<MessageRegions<T>>;
|
|
216
|
+
after: string | undefined;
|
|
217
|
+
// The items are painted, not here: no turn stands among painted messages.
|
|
218
|
+
painted: boolean;
|
|
219
|
+
}) {
|
|
220
|
+
const { reply, regions, after, painted } = props;
|
|
221
|
+
const words = useWords();
|
|
222
|
+
const {
|
|
223
|
+
state: { form, value },
|
|
224
|
+
retry,
|
|
225
|
+
} = useFrameRead(reply, turnOf);
|
|
226
|
+
// The waiting message rises in when the turn begins once the log is drawn;
|
|
227
|
+
// the text that replaces it lands with the read's first answer, so the
|
|
228
|
+
// turn's own message never rises.
|
|
229
|
+
const begun = useArrivals(form === "waiting" ? [WAITING] : [], !painted);
|
|
230
|
+
if (painted || form === "none") return null;
|
|
231
|
+
if (form === "waiting") return <WaitingReply arrives={begun.has(WAITING)} />;
|
|
232
|
+
// `useFrameRead` reads the turn untyped (`turnOf` over the held read): its
|
|
233
|
+
// value is the `reply`'s.
|
|
234
|
+
const item = value as T | null | undefined;
|
|
235
|
+
// History holds the turn already: it draws it, so this one steps aside.
|
|
236
|
+
if (item != null && regions.current.key(item) === after) return null;
|
|
237
|
+
return (
|
|
238
|
+
<>
|
|
239
|
+
{item == null ? null : (
|
|
240
|
+
<ThreadItem
|
|
241
|
+
item={item}
|
|
242
|
+
regions={regions}
|
|
243
|
+
streaming={form === "writing"}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
{form === "stopped" || form === "failed" ? (
|
|
247
|
+
<StateLine
|
|
248
|
+
sentence={form === "failed" ? words.readFailed : words.replyStopped}
|
|
249
|
+
act={{ label: words.retry, onAct: retry }}
|
|
250
|
+
/>
|
|
251
|
+
) : null}
|
|
252
|
+
</>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// The message at an index of the log's window, oldest first: a painted turn
|
|
257
|
+
// while the items are not here (`PAINT_TURNS`: an ask of yours, then the other
|
|
258
|
+
// author's reply), else one Message per item.
|
|
259
|
+
function messageAt<T>(
|
|
260
|
+
props: Omit<ThreadProps<T>, "sheet">,
|
|
261
|
+
drawn: Drawn<readonly T[]>,
|
|
262
|
+
regions: RefObject<MessageRegions<T>>,
|
|
263
|
+
arrived: ReadonlySet<string>,
|
|
264
|
+
awaits: boolean,
|
|
265
|
+
index: number,
|
|
266
|
+
): ReactElement {
|
|
267
|
+
if (drawn.painted)
|
|
268
|
+
return (
|
|
269
|
+
<MessageBase
|
|
270
|
+
key={index}
|
|
271
|
+
painted
|
|
272
|
+
author={PAINT_TURNS[index] ?? "other"}
|
|
273
|
+
name={props.message.name !== undefined}
|
|
274
|
+
at={index}
|
|
275
|
+
/>
|
|
276
|
+
);
|
|
277
|
+
// The window hands out indices under the items' count, so this one and the
|
|
278
|
+
// one before it are in range: the `T` casts are what
|
|
279
|
+
// `noUncheckedIndexedAccess` cannot see.
|
|
280
|
+
const item = drawn.value[index] as T;
|
|
281
|
+
const key = props.message.key(item);
|
|
282
|
+
// The other author's turn in a thread that waits on a reply is that reply:
|
|
283
|
+
// it takes the place of the waiting message, which the reply's own text
|
|
284
|
+
// arrives by, and does not rise again.
|
|
285
|
+
const reply = awaits && props.message.author(item) === "other";
|
|
286
|
+
const before = index > 0 ? (drawn.value[index - 1] as T) : undefined;
|
|
287
|
+
const turn = (of: T) => ({
|
|
288
|
+
author: props.message.author(of),
|
|
289
|
+
at: props.message.at?.(of),
|
|
290
|
+
});
|
|
291
|
+
return (
|
|
292
|
+
<ThreadItem
|
|
293
|
+
key={key}
|
|
294
|
+
item={item}
|
|
295
|
+
regions={regions}
|
|
296
|
+
arrives={arrived.has(key) && !reply}
|
|
297
|
+
unstamped={!stampsTime(turn(item), before && turn(before))}
|
|
298
|
+
/>
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// What follows the window: the waiting message and the turn being written,
|
|
303
|
+
// which grow outside it, so a chunk never reaches the rows. They stand through
|
|
304
|
+
// the items' failed shape, which says nothing of a turn being written, and
|
|
305
|
+
// hold back while the items are painted.
|
|
306
|
+
function tailOf<T>(
|
|
307
|
+
props: Omit<ThreadProps<T>, "sheet">,
|
|
308
|
+
drawn: Drawn<readonly T[]>,
|
|
309
|
+
regions: RefObject<MessageRegions<T>>,
|
|
310
|
+
ended: boolean,
|
|
311
|
+
arrived: ReadonlySet<string>,
|
|
312
|
+
): ReactNode {
|
|
313
|
+
const painted = drawn.painted && !ended;
|
|
314
|
+
const last = drawn.painted ? undefined : drawn.value.at(-1);
|
|
315
|
+
return (
|
|
316
|
+
<>
|
|
317
|
+
{props.replying && !painted ? (
|
|
318
|
+
<WaitingReply arrives={arrived.has(WAITING)} />
|
|
319
|
+
) : null}
|
|
320
|
+
{props.reply ? (
|
|
321
|
+
<ReplyTurn
|
|
322
|
+
reply={props.reply}
|
|
323
|
+
regions={regions}
|
|
324
|
+
painted={painted}
|
|
325
|
+
after={last === undefined ? undefined : props.message.key(last)}
|
|
326
|
+
/>
|
|
327
|
+
) : null}
|
|
328
|
+
</>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** The messages, a log region so an arriving one is announced, a sections gap apart, one rung above a reply's block gap, and the input a sections gap under them. It fills what it stands in by plain flex: in a Pane's body it takes the free height and the log scrolls, opening at the newest message and following each that arrives while the reader is at the end, the input under it, which a docked `sheet` takes the place of, its body scrolling past two fifths of the region and keeping three rows, the log keeping two rows of its own while the body can give and the foot's head and submit never giving; while the reader is scrolled up, a Latest act floats centred above the input and returns to the newest message. Among sections it stands at its content's height, its input under its log; to keep the field in reach however long the page (on touch, above the tab bar) the route gives the Pane's `foot` a `Composer` and its `sheet`, and the Thread no `composer`, so the log stays among the sections. It draws one Message per item, and with `replying` set one waiting Message of the other author after them, followed and pinned to as any message is, replaced in place when the reply's item arrives and `replying` clears; the `reply` read draws its turn after them the same way, from its own subscription. While the `items` selection's read waits, an ask of yours and the other author's reply stand in the log (`PAINT_TURNS`), painted and inert. The thread is a frame of its items: the failed shape with Retry and the missing shape stand in the log's place, in its box with the generic sentence, and the empty shape is one sentence in the meta ink (`empty`, else the generic one) centred in the log over its act, if any; the foot and the reply stand through each of them, so a thread whose items failed still sends. The stale and paused line stands over the log while it holds its read. */
|
|
333
|
+
export function Thread<T, P extends ProcedureCall = ProcedureCall>(
|
|
334
|
+
props: ThreadProps<T, P>,
|
|
335
|
+
) {
|
|
336
|
+
const { sheet } = props;
|
|
337
|
+
const { drawn, frame } = useCollection(props.items);
|
|
338
|
+
// The latest regions, which each drawn message reads when its item changes
|
|
339
|
+
// and its acts call when pressed.
|
|
340
|
+
const regions = useRef(props.message);
|
|
341
|
+
regions.current = props.message;
|
|
342
|
+
const dock = useRef<HTMLDivElement>(null);
|
|
343
|
+
useFootFocus(dock);
|
|
344
|
+
const region = useFootRegion(sheet?.open === true, dock);
|
|
345
|
+
const foot = sheet?.open ? (
|
|
346
|
+
<SheetDocked {...sheet} region={region.value} />
|
|
347
|
+
) : props.composer ? (
|
|
348
|
+
<MessageInput {...props.composer} />
|
|
349
|
+
) : undefined;
|
|
350
|
+
return (
|
|
351
|
+
<div
|
|
352
|
+
ref={foot ? region.ref : undefined}
|
|
353
|
+
data-still={stillOf(frame)}
|
|
354
|
+
className={cn(FILL, THREAD)}
|
|
355
|
+
>
|
|
356
|
+
<div className={REGION}>
|
|
357
|
+
<FrameHolds holds={frame.held}>
|
|
358
|
+
<FrameLine frame={frame} />
|
|
359
|
+
<Log thread={props} drawn={drawn} frame={frame} regions={regions} />
|
|
360
|
+
</FrameHolds>
|
|
361
|
+
</div>
|
|
362
|
+
{foot ? (
|
|
363
|
+
<div ref={dock} className={FOOT}>
|
|
364
|
+
<FrameHolds holds={NO_HOLDS}>{foot}</FrameHolds>
|
|
365
|
+
</div>
|
|
366
|
+
) : null}
|
|
367
|
+
</div>
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// The log and the Latest act floating at its foot. The items' failed and
|
|
372
|
+
// missing shapes stand in the messages' place, the reply and the waiting
|
|
373
|
+
// message after them as after any messages.
|
|
374
|
+
function Log<T>(props: {
|
|
375
|
+
thread: Omit<ThreadProps<T>, "sheet">;
|
|
376
|
+
drawn: Drawn<readonly T[]>;
|
|
377
|
+
frame: Frame;
|
|
378
|
+
regions: RefObject<MessageRegions<T>>;
|
|
379
|
+
}) {
|
|
380
|
+
const { thread, drawn, frame, regions } = props;
|
|
381
|
+
const ended = isEnded(frame.shape);
|
|
382
|
+
// The empty shape stands in the messages' place as the ended ones do, but says
|
|
383
|
+
// its own sentence, centred in the log.
|
|
384
|
+
const empty = frame.shape === "empty";
|
|
385
|
+
// On the desktop the log keeps the composer's measure column, so a message,
|
|
386
|
+
// your message's end and the failed or empty shape stand on the field's edges.
|
|
387
|
+
const column = !useTouch() && THREAD_COLUMN;
|
|
388
|
+
const count = ended
|
|
389
|
+
? 0
|
|
390
|
+
: drawn.painted
|
|
391
|
+
? PAINT_TURNS.length
|
|
392
|
+
: drawn.value.length;
|
|
393
|
+
// The messages that came to the end of the log on their own once it was
|
|
394
|
+
// drawn rise in as they mount; what it held when first drawn does not. The
|
|
395
|
+
// waiting message is one of them.
|
|
396
|
+
const awaiting = useRef(false);
|
|
397
|
+
const awaits =
|
|
398
|
+
thread.replying === true || thread.reply !== undefined || awaiting.current;
|
|
399
|
+
// Held a commit on, so the reply that arrives as `replying` clears is read as
|
|
400
|
+
// the one the waiting message was for.
|
|
401
|
+
useEffect(() => {
|
|
402
|
+
awaiting.current = thread.replying === true;
|
|
403
|
+
});
|
|
404
|
+
const arrived = useArrivals(
|
|
405
|
+
drawn.painted || ended
|
|
406
|
+
? []
|
|
407
|
+
: [
|
|
408
|
+
...drawn.value.map(thread.message.key),
|
|
409
|
+
...(thread.replying ? [WAITING] : []),
|
|
410
|
+
],
|
|
411
|
+
!drawn.painted && !ended,
|
|
412
|
+
);
|
|
413
|
+
const tail = tailOf(thread, drawn, regions, ended, arrived);
|
|
414
|
+
const title = use(PageTitle);
|
|
415
|
+
const log = useRef<HTMLDivElement>(null);
|
|
416
|
+
const scroll = useScroller(log);
|
|
417
|
+
useScrolls(scroll.node);
|
|
418
|
+
const content = useRef<HTMLDivElement>(null);
|
|
419
|
+
const atEnd = useRef(true);
|
|
420
|
+
// The log's box and content heights as the follow last saw them. A scroll
|
|
421
|
+
// event that reads other heights came with a resize (the foot changed, a
|
|
422
|
+
// message grew): the browser keeping its place, not the reader scrolling,
|
|
423
|
+
// and the follow, which runs next, settles the log at its end.
|
|
424
|
+
const laid = useRef<[number, number]>([0, 0]);
|
|
425
|
+
// The reader is scrolled up: the Latest act stands over the foot.
|
|
426
|
+
const [away, setAway] = useState(false);
|
|
427
|
+
// The log opens at its end and stays there while the reader is, as a
|
|
428
|
+
// message arrives, a reply grows, or the input grows under it.
|
|
429
|
+
useLayoutEffect(() => {
|
|
430
|
+
const scroller = log.current;
|
|
431
|
+
const inner = content.current;
|
|
432
|
+
if (!scroller || !inner) return;
|
|
433
|
+
const follow = () => {
|
|
434
|
+
if (atEnd.current) scroller.scrollTop = scroller.scrollHeight;
|
|
435
|
+
laid.current = [scroller.clientHeight, scroller.scrollHeight];
|
|
436
|
+
};
|
|
437
|
+
follow();
|
|
438
|
+
const observer = new ResizeObserver(follow);
|
|
439
|
+
observer.observe(scroller);
|
|
440
|
+
observer.observe(inner);
|
|
441
|
+
return () => observer.disconnect();
|
|
442
|
+
}, []);
|
|
443
|
+
// Back to the newest message, following again from there; the log takes
|
|
444
|
+
// the focus the act held, since the act leaves with the press.
|
|
445
|
+
const toLatest = () => {
|
|
446
|
+
const scroller = log.current;
|
|
447
|
+
if (!scroller) return;
|
|
448
|
+
atEnd.current = true;
|
|
449
|
+
setAway(false);
|
|
450
|
+
scroller.scrollTop = scroller.scrollHeight;
|
|
451
|
+
scroller.focus({ preventScroll: true });
|
|
452
|
+
};
|
|
453
|
+
return (
|
|
454
|
+
<>
|
|
455
|
+
<div
|
|
456
|
+
ref={scroll.ref}
|
|
457
|
+
role="log"
|
|
458
|
+
aria-labelledby={title}
|
|
459
|
+
onScroll={(event) => {
|
|
460
|
+
const { scrollHeight, scrollTop, clientHeight } = event.currentTarget;
|
|
461
|
+
const [height, content] = laid.current;
|
|
462
|
+
if (clientHeight !== height || scrollHeight !== content) return;
|
|
463
|
+
const end = scrollHeight - scrollTop - clientHeight <= AT_END;
|
|
464
|
+
atEnd.current = end;
|
|
465
|
+
setAway(!end);
|
|
466
|
+
}}
|
|
467
|
+
className={SCROLLS}
|
|
468
|
+
>
|
|
469
|
+
<Scroller value={scroll}>
|
|
470
|
+
<div
|
|
471
|
+
ref={content}
|
|
472
|
+
className={cn(THREAD, STACK, column, empty && EMPTY)}
|
|
473
|
+
>
|
|
474
|
+
{ended || empty ? (
|
|
475
|
+
<FrameBody
|
|
476
|
+
frame={frame}
|
|
477
|
+
fit={empty ? "part" : "frame"}
|
|
478
|
+
empty={thread.empty}
|
|
479
|
+
/>
|
|
480
|
+
) : (
|
|
481
|
+
<Window
|
|
482
|
+
count={count}
|
|
483
|
+
keyOf={(index) =>
|
|
484
|
+
drawn.painted
|
|
485
|
+
? index
|
|
486
|
+
: // An index under `count` is in range (`messageAt`).
|
|
487
|
+
thread.message.key(drawn.value[index] as T)
|
|
488
|
+
}
|
|
489
|
+
row={(index) =>
|
|
490
|
+
messageAt(thread, drawn, regions, arrived, awaits, index)
|
|
491
|
+
}
|
|
492
|
+
box={content}
|
|
493
|
+
end
|
|
494
|
+
/>
|
|
495
|
+
)}
|
|
496
|
+
{tail}
|
|
497
|
+
</div>
|
|
498
|
+
</Scroller>
|
|
499
|
+
</div>
|
|
500
|
+
<Latest shown={away} onBack={toLatest} />
|
|
501
|
+
</>
|
|
502
|
+
);
|
|
503
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
3
|
+
import { STREAM_LATEST, THREAD_LATEST } from "@slotform/ui-core/variants";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { Button } from "../button/index.tsx";
|
|
6
|
+
|
|
7
|
+
// The layer covers the region over the docked foot, so the act centres on it
|
|
8
|
+
// and the log under it keeps the pointer everywhere else. It is the size
|
|
9
|
+
// container the act's reach is decided by: absolute, so its height is the
|
|
10
|
+
// region's whatever the content, and its font size is that reach (the act's
|
|
11
|
+
// height, a pair above the foot, and the focus ring around it), so the query
|
|
12
|
+
// below reads it as `1em`.
|
|
13
|
+
const LAYER =
|
|
14
|
+
"absolute inset-0 flex flex-col items-center justify-end pointer-events-none [container-type:size] [font-size:calc(var(--spacing-control)+var(--spacing-gap)+var(--focus-ring)+var(--focus-ring-offset))]";
|
|
15
|
+
// The act is reachable only while its whole box (and the focus ring around
|
|
16
|
+
// it) stands inside the region the log shows: a region shorter than that
|
|
17
|
+
// clips it, so it keeps its place but leaves the tab order and the tree.
|
|
18
|
+
const HIT = "flex pointer-events-auto [@container_(height_<_1em)]:invisible";
|
|
19
|
+
|
|
20
|
+
/** The act back to the newest message, centred at the foot of the region it stands in while the reader is away from the end (`shown`). It fades in rising on `fast` and leaves the same way back, staying mounted, `inert`, until it has gone. */
|
|
21
|
+
export function Latest(props: { shown: boolean; onBack: () => void }) {
|
|
22
|
+
const { shown, onBack } = props;
|
|
23
|
+
const words = useWords();
|
|
24
|
+
const [mounted, setMounted] = useState(shown);
|
|
25
|
+
if (shown && !mounted) setMounted(true);
|
|
26
|
+
const box = useRef<HTMLSpanElement>(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (shown || !mounted) return;
|
|
29
|
+
let live = true;
|
|
30
|
+
const going = (box.current?.getAnimations() ?? []).map(
|
|
31
|
+
(one) => one.finished,
|
|
32
|
+
);
|
|
33
|
+
// A cancelled leave rejects `finished`: the act is gone either way.
|
|
34
|
+
Promise.allSettled(going).then(() => live && setMounted(false));
|
|
35
|
+
return () => {
|
|
36
|
+
live = false;
|
|
37
|
+
};
|
|
38
|
+
}, [shown, mounted]);
|
|
39
|
+
if (!mounted) return null;
|
|
40
|
+
return (
|
|
41
|
+
<div className={LAYER}>
|
|
42
|
+
<span
|
|
43
|
+
ref={box}
|
|
44
|
+
data-leaving={shown ? undefined : ""}
|
|
45
|
+
inert={!shown}
|
|
46
|
+
className={cn("flex", STREAM_LATEST)}
|
|
47
|
+
>
|
|
48
|
+
<span className={cn(THREAD_LATEST, HIT)}>
|
|
49
|
+
<Button
|
|
50
|
+
act="secondary"
|
|
51
|
+
icon="ArrowDown"
|
|
52
|
+
label={words.latest}
|
|
53
|
+
onAct={onBack}
|
|
54
|
+
/>
|
|
55
|
+
</span>
|
|
56
|
+
</span>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|