@slotform/react-ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/density.d.ts +4 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +8 -0
- package/dist/density.js.map +1 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/node/canvas.d.ts +3 -0
- package/dist/node/canvas.d.ts.map +1 -0
- package/dist/node/canvas.js +13 -0
- package/dist/node/canvas.js.map +1 -0
- package/dist/node/codegen.d.ts +6 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +70 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/css-escape.d.ts +8 -0
- package/dist/node/css-escape.d.ts.map +1 -0
- package/dist/node/css-escape.js +12 -0
- package/dist/node/css-escape.js.map +1 -0
- package/dist/node/fonts.d.ts +6 -0
- package/dist/node/fonts.d.ts.map +1 -0
- package/dist/node/fonts.js +219 -0
- package/dist/node/fonts.js.map +1 -0
- package/dist/node/lint.d.ts +3 -0
- package/dist/node/lint.d.ts.map +1 -0
- package/dist/node/lint.js +23 -0
- package/dist/node/lint.js.map +1 -0
- package/dist/node/mode.d.ts +9 -0
- package/dist/node/mode.d.ts.map +1 -0
- package/dist/node/mode.js +38 -0
- package/dist/node/mode.js.map +1 -0
- package/dist/node/theme.d.ts +13 -0
- package/dist/node/theme.d.ts.map +1 -0
- package/dist/node/theme.js +160 -0
- package/dist/node/theme.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/guide/acts.md +61 -0
- package/guide/audio.md +77 -0
- package/guide/blocks.md +82 -0
- package/guide/canvas-choosing.md +34 -0
- package/guide/canvas-editing.md +36 -0
- package/guide/canvas-layout.md +46 -0
- package/guide/canvas-opening.md +47 -0
- package/guide/canvas-overview.md +24 -0
- package/guide/canvas-states.md +37 -0
- package/guide/canvas-view.md +46 -0
- package/guide/canvas.md +94 -0
- package/guide/containers.md +60 -0
- package/guide/content.md +40 -0
- package/guide/controls.md +89 -0
- package/guide/density.md +48 -0
- package/guide/dock.md +42 -0
- package/guide/drag.md +38 -0
- package/guide/figures.md +25 -0
- package/guide/forms.md +82 -0
- package/guide/pane-bar.md +11 -0
- package/guide/pane.md +50 -0
- package/guide/reference.md +74 -0
- package/guide/rules.md +109 -0
- package/guide/section.md +29 -0
- package/guide/shell.md +26 -0
- package/guide/shots.md +37 -0
- package/guide/sidebar.md +30 -0
- package/guide/table.md +119 -0
- package/lint/no-arbitrary-value.grit +9 -0
- package/lint/no-class-on-component.grit +12 -0
- package/lint/no-density.grit +8 -0
- package/lint/no-host-look.grit +38 -0
- package/lint/no-img.grit +10 -0
- package/lint/no-navigate-act.grit +22 -0
- package/lint/no-raw-style.grit +8 -0
- package/package.json +150 -3
- package/src/density.ts +9 -0
- package/src/index.ts +503 -0
- package/src/node/canvas.ts +14 -0
- package/src/node/codegen.ts +100 -0
- package/src/node/css-escape.ts +27 -0
- package/src/node/fonts.ts +260 -0
- package/src/node/lint.ts +25 -0
- package/src/node/mode.ts +64 -0
- package/src/node/theme.ts +232 -0
- package/src/types.ts +120 -0
- package/src/ui/atoms/avatar/base.tsx +42 -0
- package/src/ui/atoms/button/glyph.tsx +244 -0
- package/src/ui/atoms/button/link.tsx +81 -0
- package/src/ui/atoms/button/look.ts +32 -0
- package/src/ui/atoms/button/reason.tsx +69 -0
- package/src/ui/atoms/chip/base.tsx +85 -0
- package/src/ui/atoms/count/base.tsx +27 -0
- package/src/ui/atoms/icon/index.tsx +51 -0
- package/src/ui/atoms/message/waiting.tsx +19 -0
- package/src/ui/atoms/prose/painted.tsx +35 -0
- package/src/ui/atoms/row/badges.tsx +226 -0
- package/src/ui/atoms/row/leading.tsx +166 -0
- package/src/ui/atoms/row/lock.tsx +17 -0
- package/src/ui/atoms/row/marks.tsx +79 -0
- package/src/ui/atoms/section/card.tsx +27 -0
- package/src/ui/atoms/spinner/index.tsx +42 -0
- package/src/ui/atoms/status/base.tsx +51 -0
- package/src/ui/atoms/status/change.tsx +29 -0
- package/src/ui/atoms/status/dot.tsx +45 -0
- package/src/ui/atoms/switch/checkbox.tsx +121 -0
- package/src/ui/atoms/turn.tsx +28 -0
- package/src/ui/components/action-bar/base.tsx +276 -0
- package/src/ui/components/action-bar/index.tsx +20 -0
- package/src/ui/components/avatar/index.tsx +21 -0
- package/src/ui/components/banner/index.tsx +207 -0
- package/src/ui/components/banner/pending.tsx +109 -0
- package/src/ui/components/bar-chart/index.tsx +701 -0
- package/src/ui/components/button/base.tsx +214 -0
- package/src/ui/components/button/face.tsx +84 -0
- package/src/ui/components/button/index.tsx +206 -0
- package/src/ui/components/canvas/connection.tsx +26 -0
- package/src/ui/components/canvas/edges.tsx +116 -0
- package/src/ui/components/canvas/elk.ts +260 -0
- package/src/ui/components/canvas/floor.ts +173 -0
- package/src/ui/components/canvas/geometry.ts +772 -0
- package/src/ui/components/canvas/ground.tsx +97 -0
- package/src/ui/components/canvas/group.tsx +156 -0
- package/src/ui/components/canvas/hit.ts +40 -0
- package/src/ui/components/canvas/index.tsx +497 -0
- package/src/ui/components/canvas/label.tsx +53 -0
- package/src/ui/components/canvas/layout.ts +543 -0
- package/src/ui/components/canvas/lift.ts +272 -0
- package/src/ui/components/canvas/look.ts +129 -0
- package/src/ui/components/canvas/node.tsx +689 -0
- package/src/ui/components/canvas/open.ts +243 -0
- package/src/ui/components/canvas/opening.ts +240 -0
- package/src/ui/components/canvas/view.ts +621 -0
- package/src/ui/components/canvas/viewport.ts +417 -0
- package/src/ui/components/canvas/zoom.tsx +113 -0
- package/src/ui/components/card/index.tsx +20 -0
- package/src/ui/components/chip/index.tsx +24 -0
- package/src/ui/components/code/frame.ts +2 -0
- package/src/ui/components/code/index.tsx +234 -0
- package/src/ui/components/columns/index.tsx +51 -0
- package/src/ui/components/count/index.tsx +17 -0
- package/src/ui/components/diff/index.tsx +249 -0
- package/src/ui/components/diff/word.tsx +104 -0
- package/src/ui/components/dock/index.tsx +262 -0
- package/src/ui/components/file-row/index.tsx +213 -0
- package/src/ui/components/form/base.tsx +280 -0
- package/src/ui/components/form/derive.tsx +269 -0
- package/src/ui/components/form/index.tsx +49 -0
- package/src/ui/components/form/saved.tsx +39 -0
- package/src/ui/components/form-field/index.tsx +658 -0
- package/src/ui/components/gallery/index.tsx +83 -0
- package/src/ui/components/gate/index.tsx +183 -0
- package/src/ui/components/image/base.tsx +245 -0
- package/src/ui/components/image/index.tsx +58 -0
- package/src/ui/components/input/base.tsx +246 -0
- package/src/ui/components/input/code.tsx +108 -0
- package/src/ui/components/input/drop.ts +37 -0
- package/src/ui/components/input/file.tsx +154 -0
- package/src/ui/components/input/index.tsx +132 -0
- package/src/ui/components/input/prose.tsx +107 -0
- package/src/ui/components/input/refusal.tsx +30 -0
- package/src/ui/components/item-header/base.tsx +410 -0
- package/src/ui/components/menu/base.tsx +319 -0
- package/src/ui/components/message/attachments.tsx +101 -0
- package/src/ui/components/message/base.tsx +266 -0
- package/src/ui/components/message-input/index.tsx +377 -0
- package/src/ui/components/missing/base.tsx +45 -0
- package/src/ui/components/pane/head.tsx +399 -0
- package/src/ui/components/pane/index.tsx +325 -0
- package/src/ui/components/picker/base.tsx +1551 -0
- package/src/ui/components/picker/index.tsx +224 -0
- package/src/ui/components/picker/list.tsx +423 -0
- package/src/ui/components/picker/segments.tsx +183 -0
- package/src/ui/components/prose/index.tsx +259 -0
- package/src/ui/components/qr-code/index.tsx +65 -0
- package/src/ui/components/row/acts.tsx +126 -0
- package/src/ui/components/row/fact.tsx +54 -0
- package/src/ui/components/row/index.tsx +1370 -0
- package/src/ui/components/row/progress.tsx +38 -0
- package/src/ui/components/row/status.tsx +54 -0
- package/src/ui/components/row/title.ts +7 -0
- package/src/ui/components/rules/index.tsx +290 -0
- package/src/ui/components/section/band.tsx +39 -0
- package/src/ui/components/section/head.tsx +267 -0
- package/src/ui/components/section/index.tsx +409 -0
- package/src/ui/components/section/rows.tsx +356 -0
- package/src/ui/components/sheet/base.tsx +272 -0
- package/src/ui/components/sheet/confirm.tsx +79 -0
- package/src/ui/components/sheet/docked.tsx +218 -0
- package/src/ui/components/sheet/form.tsx +76 -0
- package/src/ui/components/sheet/head.tsx +120 -0
- package/src/ui/components/sheet/index.tsx +45 -0
- package/src/ui/components/sheet/layer.tsx +168 -0
- package/src/ui/components/sheet/outlet.tsx +58 -0
- package/src/ui/components/sheet/task.tsx +41 -0
- package/src/ui/components/shell/cut.tsx +116 -0
- package/src/ui/components/shell/drag.tsx +45 -0
- package/src/ui/components/shell/host.tsx +71 -0
- package/src/ui/components/shell/index.tsx +737 -0
- package/src/ui/components/shell/panes.tsx +76 -0
- package/src/ui/components/shell/preview.ts +230 -0
- package/src/ui/components/shell/rail.tsx +163 -0
- package/src/ui/components/shell/row.ts +11 -0
- package/src/ui/components/shell/switcher.tsx +143 -0
- package/src/ui/components/shell/tree.tsx +252 -0
- package/src/ui/components/slider/base.tsx +139 -0
- package/src/ui/components/slider/index.tsx +57 -0
- package/src/ui/components/stages/index.tsx +198 -0
- package/src/ui/components/stats/count-links.tsx +47 -0
- package/src/ui/components/stats/index.tsx +203 -0
- package/src/ui/components/stats/meter.tsx +213 -0
- package/src/ui/components/stats/parts.ts +10 -0
- package/src/ui/components/step-count/index.tsx +45 -0
- package/src/ui/components/switch/base.tsx +86 -0
- package/src/ui/components/switch/index.tsx +38 -0
- package/src/ui/components/table/columns.tsx +131 -0
- package/src/ui/components/table/index.tsx +2215 -0
- package/src/ui/components/text/index.tsx +37 -0
- package/src/ui/components/thread/index.tsx +503 -0
- package/src/ui/components/thread/latest.tsx +59 -0
- package/src/ui/components/toast/index.tsx +113 -0
- package/src/ui/components/toast/layer.tsx +26 -0
- package/src/ui/components/toolbar/filters.tsx +161 -0
- package/src/ui/components/toolbar/index.tsx +125 -0
- package/src/ui/components/waveform/index.tsx +205 -0
- package/src/ui/globals.css +427 -0
- package/src/ui/lib/act.ts +60 -0
- package/src/ui/lib/age.ts +49 -0
- package/src/ui/lib/bound.ts +16 -0
- package/src/ui/lib/canvas-layout.ts +11 -0
- package/src/ui/lib/caret.ts +9 -0
- package/src/ui/lib/chip-lines.ts +3 -0
- package/src/ui/lib/closed.ts +8 -0
- package/src/ui/lib/code.tsx +184 -0
- package/src/ui/lib/columns.ts +39 -0
- package/src/ui/lib/commit.ts +24 -0
- package/src/ui/lib/container.ts +112 -0
- package/src/ui/lib/copy.ts +29 -0
- package/src/ui/lib/drag.ts +575 -0
- package/src/ui/lib/empty.tsx +85 -0
- package/src/ui/lib/field.ts +39 -0
- package/src/ui/lib/focus.ts +175 -0
- package/src/ui/lib/folds.ts +67 -0
- package/src/ui/lib/follow.ts +220 -0
- package/src/ui/lib/form.ts +19 -0
- package/src/ui/lib/guards.ts +38 -0
- package/src/ui/lib/heading.ts +14 -0
- package/src/ui/lib/ink.ts +26 -0
- package/src/ui/lib/lang.ts +7 -0
- package/src/ui/lib/leave.ts +14 -0
- package/src/ui/lib/lockup.tsx +145 -0
- package/src/ui/lib/measure.ts +22 -0
- package/src/ui/lib/media.ts +63 -0
- package/src/ui/lib/modality.ts +69 -0
- package/src/ui/lib/moment.ts +13 -0
- package/src/ui/lib/more.tsx +76 -0
- package/src/ui/lib/navigate.ts +210 -0
- package/src/ui/lib/noop.ts +3 -0
- package/src/ui/lib/not-found.tsx +40 -0
- package/src/ui/lib/paint.tsx +55 -0
- package/src/ui/lib/parts-line.tsx +54 -0
- package/src/ui/lib/picked.ts +18 -0
- package/src/ui/lib/player-store.ts +38 -0
- package/src/ui/lib/player.ts +139 -0
- package/src/ui/lib/portal.ts +12 -0
- package/src/ui/lib/read.tsx +269 -0
- package/src/ui/lib/region.tsx +49 -0
- package/src/ui/lib/reorder.ts +154 -0
- package/src/ui/lib/rest.ts +16 -0
- package/src/ui/lib/saved.ts +29 -0
- package/src/ui/lib/scramble.tsx +147 -0
- package/src/ui/lib/scrolls.ts +70 -0
- package/src/ui/lib/style.ts +6 -0
- package/src/ui/lib/swap.tsx +107 -0
- package/src/ui/lib/toast.ts +39 -0
- package/src/ui/lib/walk-classes.ts +16 -0
- package/src/ui/lib/window.tsx +376 -0
- package/src/ui/worker.d.ts +4 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type {
|
|
3
|
+
Attachment,
|
|
4
|
+
Notice,
|
|
5
|
+
PickedFile,
|
|
6
|
+
} from "@slotform/ui-core/descriptors";
|
|
7
|
+
import { FieldDisabled } from "@slotform/ui-core/react/field";
|
|
8
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
9
|
+
import {
|
|
10
|
+
FLOW_IN,
|
|
11
|
+
field,
|
|
12
|
+
fieldValue,
|
|
13
|
+
MESSAGE_ATTACH_REGION,
|
|
14
|
+
MESSAGE_INPUT,
|
|
15
|
+
MESSAGE_INPUT_BOX,
|
|
16
|
+
MESSAGE_INPUT_CHIPS,
|
|
17
|
+
MESSAGE_INPUT_FIELD_CHIPS,
|
|
18
|
+
MESSAGE_INPUT_FIELD_VALUE,
|
|
19
|
+
MESSAGE_INPUT_FOOT,
|
|
20
|
+
MESSAGE_INPUT_ROW,
|
|
21
|
+
MESSAGE_INPUT_TEXT,
|
|
22
|
+
MESSAGE_INPUT_VALUE,
|
|
23
|
+
MESSAGE_NOTICE,
|
|
24
|
+
MESSAGE_NOTICE_TEXT,
|
|
25
|
+
THREAD_COLUMN,
|
|
26
|
+
text,
|
|
27
|
+
YIELDS_FIRST,
|
|
28
|
+
} from "@slotform/ui-core/variants";
|
|
29
|
+
import {
|
|
30
|
+
type ChangeEvent,
|
|
31
|
+
type ClipboardEvent,
|
|
32
|
+
type KeyboardEvent,
|
|
33
|
+
type MouseEvent,
|
|
34
|
+
type ReactNode,
|
|
35
|
+
useRef,
|
|
36
|
+
useState,
|
|
37
|
+
} from "react";
|
|
38
|
+
import { IconButtonBase } from "../../atoms/button/glyph.tsx";
|
|
39
|
+
import { ButtonLink } from "../../atoms/button/link.tsx";
|
|
40
|
+
import { useAct, wiringOf } from "../../lib/act.ts";
|
|
41
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
42
|
+
import { ActInert } from "../../lib/form.ts";
|
|
43
|
+
import { useTouch } from "../../lib/media.ts";
|
|
44
|
+
import { BOX_FOCUS, useModality } from "../../lib/modality.ts";
|
|
45
|
+
import { attachedFrom } from "../../lib/picked.ts";
|
|
46
|
+
import { ButtonBase } from "../button/base.tsx";
|
|
47
|
+
import { Button } from "../button/index.tsx";
|
|
48
|
+
import { BOX_HOVER_VALUE } from "../input/base.tsx";
|
|
49
|
+
import { chosenFiles, fileDrop } from "../input/drop.ts";
|
|
50
|
+
import { Attachments } from "../message/attachments.tsx";
|
|
51
|
+
|
|
52
|
+
const ROOT = "flex flex-col w-full";
|
|
53
|
+
const STACK = "flex flex-col";
|
|
54
|
+
// The box draws the field's states, as `Input`'s does: the acts inside it
|
|
55
|
+
// answer their own pointer and ring on their own focus.
|
|
56
|
+
const BOX_DISABLED = "bg-fill-disabled";
|
|
57
|
+
const FIELD_BOX = "flex flex-col justify-center grow min-w-0";
|
|
58
|
+
const VALUE =
|
|
59
|
+
"block w-full resize-none field-sizing-content overflow-y-auto outline-none placeholder:text-ink-meta disabled:text-ink-disabled disabled:placeholder:text-ink-disabled";
|
|
60
|
+
const ROW = "flex items-end";
|
|
61
|
+
// A file dragged over the input lights its boundary as the pointer does.
|
|
62
|
+
const OVER = "border-edge-hover";
|
|
63
|
+
const FOOT = "flex items-center";
|
|
64
|
+
const SPACER = "grow";
|
|
65
|
+
// Stop, while an answer comes, and Send: the spacer holds no width to give, so
|
|
66
|
+
// only a label wider than the row narrows them. On touch they are icon acts the
|
|
67
|
+
// field gives way to.
|
|
68
|
+
const ACTS = "flex items-center min-w-0 max-w-full";
|
|
69
|
+
const ACTS_ICON = "flex items-center shrink-0";
|
|
70
|
+
const NOTICE = "flex items-center";
|
|
71
|
+
const NOTICE_TEXT = `grow ${YIELDS_FIRST} min-w-0`;
|
|
72
|
+
const ATTACH_REGION = "shrink-0";
|
|
73
|
+
|
|
74
|
+
/** Where a message is written and sent. */
|
|
75
|
+
export interface MessageInputProps extends Closed {
|
|
76
|
+
/** The text being written (text; wraps). */
|
|
77
|
+
value: string;
|
|
78
|
+
/** Hears every keystroke's value. */
|
|
79
|
+
onChange: (value: string) => void;
|
|
80
|
+
/** The files going with the message: an attachment with `src` a thumbnail, one without a chip of its name. */
|
|
81
|
+
attachments?: readonly Attachment[];
|
|
82
|
+
/** Hears the files the viewer brings: the attach act opens the system's file dialog before the text, and a file pasted into the text or dropped on the input comes the same way. Turn each into an `Attachment` and pass it back. */
|
|
83
|
+
onAttach?: (files: readonly PickedFile[]) => void;
|
|
84
|
+
/** Removes an attachment by its id: each carries its remove act. */
|
|
85
|
+
onDetach?: (id: string) => void;
|
|
86
|
+
/** The hint drawn while the text is empty; never the field's name (a short phrase; wraps). */
|
|
87
|
+
placeholder?: string;
|
|
88
|
+
/** A sentence under the input, with its one act. */
|
|
89
|
+
notice?: Notice;
|
|
90
|
+
/** An answer is coming: Stop stands before Send, and Send still sends. */
|
|
91
|
+
working?: boolean;
|
|
92
|
+
/** Sends the text; inert while it is empty. Enter sends on the desktop, Shift+Enter breaks the line. */
|
|
93
|
+
onSend: () => unknown;
|
|
94
|
+
/** Stops the answer; without it Stop is drawn inert. */
|
|
95
|
+
onStop?: () => unknown;
|
|
96
|
+
/** Nothing can be written or sent: the disabled fill and ink, the attach act inert in its place. */
|
|
97
|
+
disabled?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** On the desktop one box (its attachments, the text growing to eight lines and scrolling past them, then the attach act, Stop while an answer comes, and Send), the notice under it at the text's x; on touch one row (attach, the field growing upward, Stop's icon act while an answer comes, Send's icon act), the notice under it in the same columns. A press anywhere in the box or field that is no act focuses the text, the caret at its end. A Thread's `composer`; outside the package's exports. */
|
|
101
|
+
export function MessageInput({
|
|
102
|
+
value,
|
|
103
|
+
onChange,
|
|
104
|
+
attachments,
|
|
105
|
+
onAttach,
|
|
106
|
+
onDetach,
|
|
107
|
+
placeholder,
|
|
108
|
+
notice,
|
|
109
|
+
working,
|
|
110
|
+
onSend,
|
|
111
|
+
onStop,
|
|
112
|
+
disabled,
|
|
113
|
+
}: MessageInputProps) {
|
|
114
|
+
useModality();
|
|
115
|
+
const words = useWords();
|
|
116
|
+
const touch = useTouch();
|
|
117
|
+
// A docked foot spans the page body, so the field keeps its own measure
|
|
118
|
+
// column on the desktop.
|
|
119
|
+
const column = !touch && THREAD_COLUMN;
|
|
120
|
+
const empty = value.trim() === "";
|
|
121
|
+
const sendable = !empty && !disabled;
|
|
122
|
+
const textField = useRef<HTMLTextAreaElement>(null);
|
|
123
|
+
const chooser = useRef<HTMLInputElement>(null);
|
|
124
|
+
const [over, setOver] = useState(false);
|
|
125
|
+
// Focus never drops to the page: Send and Stop hand it to the text, a
|
|
126
|
+
// removed chip to the next chip's remove, else the previous one's.
|
|
127
|
+
// Send and Stop hold their handler's promise: the pressed one pends, and a
|
|
128
|
+
// rejection toasts with Retry.
|
|
129
|
+
const acting = useAct<"send" | "stop">("toast");
|
|
130
|
+
const sending = acting.pending === "send";
|
|
131
|
+
const stopping = acting.pending === "stop";
|
|
132
|
+
const send = () => {
|
|
133
|
+
acting.attempt("send", { onAct: onSend });
|
|
134
|
+
textField.current?.focus();
|
|
135
|
+
};
|
|
136
|
+
const stop = () => {
|
|
137
|
+
acting.attempt("stop", { onAct: () => onStop?.() });
|
|
138
|
+
textField.current?.focus();
|
|
139
|
+
};
|
|
140
|
+
// Every way a file arrives (the dialog, a paste, a drop) ends here.
|
|
141
|
+
const take = (files: ArrayLike<File>) => {
|
|
142
|
+
if (files.length > 0) onAttach?.(Array.from(files, attachedFrom));
|
|
143
|
+
};
|
|
144
|
+
const choose = (event: ChangeEvent<HTMLInputElement>) =>
|
|
145
|
+
take(chosenFiles(event));
|
|
146
|
+
// A pasted screenshot is a file; pasted text stays the text area's, even
|
|
147
|
+
// when the clipboard carries an image beside it (copied from an office
|
|
148
|
+
// document).
|
|
149
|
+
const paste = (event: ClipboardEvent<HTMLTextAreaElement>) => {
|
|
150
|
+
if (
|
|
151
|
+
event.clipboardData.files.length === 0 ||
|
|
152
|
+
event.clipboardData.getData("text/plain") !== ""
|
|
153
|
+
)
|
|
154
|
+
return;
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
take(event.clipboardData.files);
|
|
157
|
+
};
|
|
158
|
+
const dropping = onAttach && !disabled ? fileDrop(setOver, take) : undefined;
|
|
159
|
+
// A press on the box that lands on no act or chip puts the focus in the text,
|
|
160
|
+
// the caret at its end: the box is the field, not its one line. The text
|
|
161
|
+
// area itself is the textarea (it fills the box's text and the touch field's
|
|
162
|
+
// height), so this is for what is left: the box's inset and rhythm, the
|
|
163
|
+
// foot's spacer and the field's sides.
|
|
164
|
+
const focusText = (event: MouseEvent<HTMLDivElement>) => {
|
|
165
|
+
const area = textField.current;
|
|
166
|
+
if (!area || event.target === area) return;
|
|
167
|
+
if (event.target instanceof Element && event.target.closest("button, a"))
|
|
168
|
+
return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
area.focus();
|
|
171
|
+
area.setSelectionRange(area.value.length, area.value.length);
|
|
172
|
+
};
|
|
173
|
+
// A phone's return key breaks the line; the desktop's sends.
|
|
174
|
+
const keyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
175
|
+
if (touch || event.key !== "Enter" || event.shiftKey) return;
|
|
176
|
+
if (event.nativeEvent.isComposing) return;
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
if (sendable && !sending) send();
|
|
179
|
+
};
|
|
180
|
+
const box = cn(
|
|
181
|
+
BOX_FOCUS,
|
|
182
|
+
disabled ? BOX_DISABLED : BOX_HOVER_VALUE,
|
|
183
|
+
over && OVER,
|
|
184
|
+
);
|
|
185
|
+
// A disabled input keeps its attach act, inert, so the field stands at one
|
|
186
|
+
// x and width in both forms.
|
|
187
|
+
const attach = onAttach ? (
|
|
188
|
+
<FieldDisabled value={disabled === true}>
|
|
189
|
+
<Button
|
|
190
|
+
glyph
|
|
191
|
+
icon="Paperclip"
|
|
192
|
+
label={words.attach}
|
|
193
|
+
onAct={() => chooser.current?.click()}
|
|
194
|
+
/>
|
|
195
|
+
</FieldDisabled>
|
|
196
|
+
) : null;
|
|
197
|
+
const chips =
|
|
198
|
+
attachments && attachments.length > 0 ? (
|
|
199
|
+
<Attachments
|
|
200
|
+
attachments={attachments}
|
|
201
|
+
onRemove={onDetach}
|
|
202
|
+
fallback={textField}
|
|
203
|
+
/>
|
|
204
|
+
) : null;
|
|
205
|
+
const textarea = (
|
|
206
|
+
<textarea
|
|
207
|
+
ref={textField}
|
|
208
|
+
value={value}
|
|
209
|
+
onChange={(event) => onChange(event.target.value)}
|
|
210
|
+
onKeyDown={keyDown}
|
|
211
|
+
onPaste={onAttach && paste}
|
|
212
|
+
aria-label={words.message}
|
|
213
|
+
placeholder={placeholder}
|
|
214
|
+
disabled={disabled}
|
|
215
|
+
className={cn(
|
|
216
|
+
fieldValue({ kind: "text" }),
|
|
217
|
+
MESSAGE_INPUT_VALUE,
|
|
218
|
+
VALUE,
|
|
219
|
+
touch ? [MESSAGE_INPUT_FIELD_VALUE, "grow"] : MESSAGE_INPUT_TEXT,
|
|
220
|
+
)}
|
|
221
|
+
/>
|
|
222
|
+
);
|
|
223
|
+
// On touch Stop and Send are icon acts, so the field keeps its width; Stop's
|
|
224
|
+
// glyph is the stop square in a ring, never a bare square a checkbox would
|
|
225
|
+
// read as.
|
|
226
|
+
let stopAct: ReactNode = null;
|
|
227
|
+
if (working && touch)
|
|
228
|
+
stopAct = (
|
|
229
|
+
<IconButtonBase
|
|
230
|
+
icon="CircleStop"
|
|
231
|
+
label={words.stop}
|
|
232
|
+
onClick={stop}
|
|
233
|
+
pending={stopping}
|
|
234
|
+
disabled={!onStop}
|
|
235
|
+
/>
|
|
236
|
+
);
|
|
237
|
+
else if (working)
|
|
238
|
+
stopAct = (
|
|
239
|
+
<ActInert value={!onStop}>
|
|
240
|
+
<ButtonBase
|
|
241
|
+
act="secondary"
|
|
242
|
+
label={words.stop}
|
|
243
|
+
onAct={stop}
|
|
244
|
+
pending={stopping}
|
|
245
|
+
/>
|
|
246
|
+
</ActInert>
|
|
247
|
+
);
|
|
248
|
+
const acts = (
|
|
249
|
+
<div
|
|
250
|
+
className={cn(
|
|
251
|
+
touch ? MESSAGE_INPUT_ROW : MESSAGE_INPUT_FOOT,
|
|
252
|
+
touch ? ACTS_ICON : ACTS,
|
|
253
|
+
)}
|
|
254
|
+
>
|
|
255
|
+
{stopAct}
|
|
256
|
+
{touch ? (
|
|
257
|
+
<IconButtonBase
|
|
258
|
+
icon="Send"
|
|
259
|
+
label={words.send}
|
|
260
|
+
onClick={send}
|
|
261
|
+
pending={sending}
|
|
262
|
+
disabled={!sendable}
|
|
263
|
+
/>
|
|
264
|
+
) : (
|
|
265
|
+
<ActInert value={!sendable}>
|
|
266
|
+
<ButtonBase
|
|
267
|
+
act="primary"
|
|
268
|
+
label={words.send}
|
|
269
|
+
onAct={send}
|
|
270
|
+
pending={sending}
|
|
271
|
+
/>
|
|
272
|
+
</ActInert>
|
|
273
|
+
)}
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
const noticed = notice?.act;
|
|
277
|
+
let act: ReactNode = null;
|
|
278
|
+
if (noticed && "href" in noticed)
|
|
279
|
+
act = (
|
|
280
|
+
<ButtonLink act="secondary" label={noticed.label} href={noticed.href} />
|
|
281
|
+
);
|
|
282
|
+
else if (noticed)
|
|
283
|
+
act = (
|
|
284
|
+
<ButtonBase
|
|
285
|
+
act="secondary"
|
|
286
|
+
label={noticed.label}
|
|
287
|
+
onAct={noticed.onAct}
|
|
288
|
+
blocked={noticed.blocked}
|
|
289
|
+
{...wiringOf(noticed)}
|
|
290
|
+
/>
|
|
291
|
+
);
|
|
292
|
+
let input: ReactNode;
|
|
293
|
+
let under: ReactNode = null;
|
|
294
|
+
if (touch) {
|
|
295
|
+
input = (
|
|
296
|
+
<div className={cn(MESSAGE_INPUT_ROW, ROW)}>
|
|
297
|
+
{attach}
|
|
298
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: a pointer shortcut to the text; the keyboard reaches the text itself */}
|
|
299
|
+
<div
|
|
300
|
+
onDragOver={dropping?.onDragOver}
|
|
301
|
+
onDragLeave={dropping?.onDragLeave}
|
|
302
|
+
onDrop={dropping?.onDrop}
|
|
303
|
+
onMouseDown={focusText}
|
|
304
|
+
className={cn(
|
|
305
|
+
field({ trailing: "none", state: "rest" }),
|
|
306
|
+
FIELD_BOX,
|
|
307
|
+
box,
|
|
308
|
+
)}
|
|
309
|
+
>
|
|
310
|
+
{chips ? (
|
|
311
|
+
<div className={MESSAGE_INPUT_FIELD_CHIPS}>{chips}</div>
|
|
312
|
+
) : null}
|
|
313
|
+
{textarea}
|
|
314
|
+
</div>
|
|
315
|
+
{acts}
|
|
316
|
+
</div>
|
|
317
|
+
);
|
|
318
|
+
if (notice)
|
|
319
|
+
under = (
|
|
320
|
+
<div className={cn(MESSAGE_INPUT_ROW, NOTICE, FLOW_IN)}>
|
|
321
|
+
{attach ? (
|
|
322
|
+
<span
|
|
323
|
+
aria-hidden
|
|
324
|
+
className={cn(MESSAGE_ATTACH_REGION, ATTACH_REGION)}
|
|
325
|
+
/>
|
|
326
|
+
) : null}
|
|
327
|
+
<p
|
|
328
|
+
className={cn(
|
|
329
|
+
text({ role: "meta" }),
|
|
330
|
+
MESSAGE_NOTICE_TEXT,
|
|
331
|
+
NOTICE_TEXT,
|
|
332
|
+
)}
|
|
333
|
+
>
|
|
334
|
+
{notice.sentence}
|
|
335
|
+
</p>
|
|
336
|
+
{act}
|
|
337
|
+
</div>
|
|
338
|
+
);
|
|
339
|
+
} else {
|
|
340
|
+
input = (
|
|
341
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: a pointer shortcut to the text; the keyboard reaches the text itself
|
|
342
|
+
<div
|
|
343
|
+
onDragOver={dropping?.onDragOver}
|
|
344
|
+
onDragLeave={dropping?.onDragLeave}
|
|
345
|
+
onDrop={dropping?.onDrop}
|
|
346
|
+
onMouseDown={focusText}
|
|
347
|
+
className={cn(MESSAGE_INPUT_BOX, STACK, box)}
|
|
348
|
+
>
|
|
349
|
+
{chips ? <div className={MESSAGE_INPUT_CHIPS}>{chips}</div> : null}
|
|
350
|
+
{textarea}
|
|
351
|
+
<div className={cn(MESSAGE_INPUT_FOOT, FOOT)}>
|
|
352
|
+
{attach}
|
|
353
|
+
<span className={SPACER} />
|
|
354
|
+
{acts}
|
|
355
|
+
</div>
|
|
356
|
+
</div>
|
|
357
|
+
);
|
|
358
|
+
if (notice)
|
|
359
|
+
under = (
|
|
360
|
+
<div className={cn(MESSAGE_NOTICE, NOTICE, FLOW_IN)}>
|
|
361
|
+
<p className={cn(text({ role: "meta" }), NOTICE_TEXT)}>
|
|
362
|
+
{notice.sentence}
|
|
363
|
+
</p>
|
|
364
|
+
{act}
|
|
365
|
+
</div>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
return (
|
|
369
|
+
<div className={cn(MESSAGE_INPUT, ROOT, column)}>
|
|
370
|
+
{onAttach ? (
|
|
371
|
+
<input ref={chooser} type="file" multiple hidden onChange={choose} />
|
|
372
|
+
) : null}
|
|
373
|
+
{input}
|
|
374
|
+
{under}
|
|
375
|
+
</div>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LinkAct } from "@slotform/ui-core/descriptors";
|
|
2
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
3
|
+
import { trailEnds } from "@slotform/ui-core/route";
|
|
4
|
+
import { filled } from "@slotform/ui-core/tokens";
|
|
5
|
+
import { use } from "react";
|
|
6
|
+
import { BackRoute, PlaceTrail } from "../../lib/container.ts";
|
|
7
|
+
import { EmptyBase, type EmptyFit } from "../../lib/empty.tsx";
|
|
8
|
+
|
|
9
|
+
// The Back link of a Pane's read that answers not found: to the route its
|
|
10
|
+
// Pane gives (`BackRoute`), else the current place's route; none with neither.
|
|
11
|
+
function useBackAct(): LinkAct | undefined {
|
|
12
|
+
const words = useWords();
|
|
13
|
+
const screen = use(BackRoute);
|
|
14
|
+
const place = trailEnds(use(PlaceTrail)).here?.route;
|
|
15
|
+
const href = screen ?? place;
|
|
16
|
+
if (href === undefined) return undefined;
|
|
17
|
+
return { label: words.back, href };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The missing shape every read that answers not found draws, and the page for an address nothing serves. Outside the package's exports: `fit` and `fill` are the reads' alone, where its form stands and whether its line fills the box it stands in; `noun` words the sentence for the kind of record (the Pane's), `sentence` replaces it. The way back is the Pane's: a Pane's own frame (`headed`) offers it, any other frame says the sentence alone. */
|
|
21
|
+
export function MissingBase(props: {
|
|
22
|
+
fit?: EmptyFit;
|
|
23
|
+
headed?: boolean;
|
|
24
|
+
noun?: string;
|
|
25
|
+
sentence?: string;
|
|
26
|
+
act?: LinkAct;
|
|
27
|
+
fill?: boolean;
|
|
28
|
+
}) {
|
|
29
|
+
const words = useWords();
|
|
30
|
+
const back = useBackAct();
|
|
31
|
+
return (
|
|
32
|
+
<EmptyBase
|
|
33
|
+
fit={props.fit ?? "frame"}
|
|
34
|
+
tone="missing"
|
|
35
|
+
sentence={
|
|
36
|
+
props.sentence ??
|
|
37
|
+
(props.noun === undefined
|
|
38
|
+
? words.missing
|
|
39
|
+
: filled(words.missingNoun, { noun: props.noun }))
|
|
40
|
+
}
|
|
41
|
+
act={props.act ?? (props.headed ? back : undefined)}
|
|
42
|
+
fill={props.fill}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|