@whity/ui 0.5.0 → 1.0.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/README.md +107 -107
- package/package.json +221 -192
- package/src/access-denied.stories.tsx +179 -179
- package/src/access-denied.tsx +305 -305
- package/src/action-proposal.tsx +338 -302
- package/src/actor-chip.tsx +71 -71
- package/src/agent-activity.tsx +163 -163
- package/src/agent-collaboration.stories.tsx +156 -156
- package/src/agent-run-status.tsx +196 -196
- package/src/alert-dialog.stories.tsx +45 -45
- package/src/alert-dialog.tsx +147 -147
- package/src/alert.stories.tsx +91 -91
- package/src/alert.tsx +89 -89
- package/src/app-sidebar.stories.tsx +195 -195
- package/src/app-sidebar.tsx +604 -500
- package/src/approval-queue.tsx +109 -108
- package/src/audience-group-picker.stories.tsx +198 -198
- package/src/audience-group-picker.tsx +362 -362
- package/src/audience-people-picker.stories.tsx +102 -102
- package/src/audience-people-picker.tsx +279 -279
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -83
- package/src/badge.stories.tsx +105 -105
- package/src/badge.tsx +68 -68
- package/src/beta-warning.stories.tsx +79 -79
- package/src/beta-warning.tsx +189 -189
- package/src/bilingual-input.stories.tsx +82 -82
- package/src/bilingual-input.tsx +188 -183
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -51
- package/src/breadcrumb.tsx +90 -90
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -87
- package/src/button.tsx +123 -118
- package/src/card.stories.tsx +423 -423
- package/src/card.tsx +180 -180
- package/src/chart.stories.tsx +66 -66
- package/src/chart.tsx +228 -228
- package/src/checkbox.stories.tsx +62 -62
- package/src/checkbox.tsx +54 -54
- package/src/collapsible.stories.tsx +48 -48
- package/src/collapsible.tsx +34 -34
- package/src/color-card.stories.tsx +61 -61
- package/src/color-card.tsx +270 -270
- package/src/color-picker.stories.tsx +65 -65
- package/src/color-picker.tsx +425 -425
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -306
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -38
- package/src/copy-block.tsx +85 -85
- package/src/data-table.stories.tsx +200 -200
- package/src/data-table.tsx +1686 -1106
- package/src/date-picker.stories.tsx +61 -61
- package/src/date-picker.tsx +456 -422
- package/src/design-cards.stories.tsx +551 -458
- package/src/dialog.stories.tsx +48 -48
- package/src/dialog.tsx +179 -166
- package/src/display-preferences.tsx +50 -0
- package/src/documents/barcode-svg.stories.tsx +72 -72
- package/src/documents/barcode-svg.tsx +79 -79
- package/src/dropdown-menu.stories.tsx +77 -77
- package/src/dropdown-menu.tsx +271 -271
- package/src/editor/agent-panel.tsx +222 -0
- package/src/editor/agents.stories.tsx +81 -0
- package/src/editor/agents.ts +55 -0
- package/src/editor/behaviour.ts +279 -279
- package/src/editor/block-ids.ts +44 -44
- package/src/editor/block-list.tsx +104 -101
- package/src/editor/block-toolbar.tsx +490 -477
- package/src/editor/bubble.tsx +119 -93
- package/src/editor/catalogue.ts +169 -103
- package/src/editor/collab-rail.tsx +746 -746
- package/src/editor/collab.stories.tsx +207 -207
- package/src/editor/collab.ts +87 -87
- package/src/editor/contract.ts +476 -408
- package/src/editor/convert.ts +414 -362
- package/src/editor/doc-editor.stories.tsx +98 -98
- package/src/editor/doc-editor.tsx +1492 -1287
- package/src/editor/editor.css +636 -536
- package/src/editor/extensions.ts +86 -86
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -107
- package/src/editor/fields.ts +100 -100
- package/src/editor/gutter.tsx +443 -367
- package/src/editor/index.ts +23 -22
- package/src/editor/label-sheet.tsx +289 -289
- package/src/editor/labels.ts +394 -310
- package/src/editor/link-tools.tsx +141 -141
- package/src/editor/node-views.tsx +461 -450
- package/src/editor/page-view.tsx +372 -353
- package/src/editor/phone.tsx +310 -0
- package/src/editor/plugin-block-view.tsx +230 -0
- package/src/editor/plugin-blocks.stories.tsx +96 -0
- package/src/editor/plugin-blocks.ts +52 -0
- package/src/editor/publish-check.tsx +201 -182
- package/src/editor/rich-blocks.stories.tsx +146 -146
- package/src/editor/sample.ts +40 -40
- package/src/editor/save-block-dialog.tsx +141 -0
- package/src/editor/saved-block-view.tsx +205 -0
- package/src/editor/saved-blocks.stories.tsx +105 -0
- package/src/editor/saved-parts.ts +192 -0
- package/src/editor/schema-rich.ts +156 -150
- package/src/editor/schema.ts +368 -315
- package/src/editor/services.tsx +205 -127
- package/src/editor/slash.ts +64 -64
- package/src/editor/suggesting.ts +372 -372
- package/src/editor/suggestions.ts +763 -763
- package/src/editor/table-keys.ts +66 -66
- package/src/editor/templates.stories.tsx +324 -324
- package/src/editor/toolbar.tsx +364 -358
- package/src/empty-state.stories.tsx +51 -51
- package/src/empty-state.tsx +126 -100
- package/src/empty-state.usage-notes.md +30 -30
- package/src/form.stories.tsx +112 -112
- package/src/form.tsx +176 -176
- package/src/globals.css +20 -20
- package/src/icon-button.tsx +85 -85
- package/src/icon-map.ts +335 -244
- package/src/icon.tsx +41 -41
- package/src/index.ts +90 -67
- package/src/input.stories.tsx +157 -157
- package/src/input.tsx +768 -759
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -29
- package/src/locked-screen.tsx +75 -61
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -62
- package/src/math-text.stories.tsx +33 -33
- package/src/math-text.tsx +43 -43
- package/src/menu-bar.stories.tsx +198 -198
- package/src/menu-bar.tsx +373 -373
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -230
- package/src/money/money-input.tsx +131 -0
- package/src/money/money.tsx +33 -0
- package/src/open-on-computer.tsx +150 -0
- package/src/otp-input.tsx +161 -0
- package/src/page-header.stories.tsx +95 -95
- package/src/page-header.tsx +122 -122
- package/src/page-shell.stories.tsx +42 -42
- package/src/page-shell.tsx +32 -32
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -45
- package/src/pagination.tsx +98 -98
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -180
- package/src/plugin-card.tsx +931 -848
- package/src/popover.stories.tsx +48 -48
- package/src/popover.tsx +55 -55
- package/src/radio-group.stories.tsx +26 -26
- package/src/radio-group.tsx +44 -44
- package/src/route-flow/editor.tsx +1087 -1014
- package/src/route-flow/model.ts +771 -716
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -139
- package/src/screen-too-small.stories.tsx +61 -61
- package/src/screen-too-small.tsx +104 -104
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -44
- package/src/select.tsx +197 -197
- package/src/separator.stories.tsx +34 -34
- package/src/separator.tsx +34 -34
- package/src/sheet.stories.tsx +49 -49
- package/src/sheet.tsx +168 -168
- package/src/skeleton.stories.tsx +28 -28
- package/src/skeleton.tsx +19 -19
- package/src/slider.stories.tsx +78 -78
- package/src/slider.tsx +300 -300
- package/src/spinner.stories.tsx +33 -33
- package/src/spinner.tsx +55 -55
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -42
- package/src/switch.tsx +41 -41
- package/src/switcher.stories.tsx +111 -111
- package/src/switcher.tsx +131 -131
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -48
- package/src/table.tsx +121 -121
- package/src/tabs.stories.tsx +74 -74
- package/src/tabs.tsx +90 -90
- package/src/tag-input.stories.tsx +67 -67
- package/src/tag-input.tsx +117 -117
- package/src/tenant-logo.tsx +63 -63
- package/src/tenant-switcher.stories.tsx +38 -38
- package/src/tenant-switcher.tsx +164 -164
- package/src/textarea.stories.tsx +27 -27
- package/src/textarea.tsx +18 -18
- package/src/theme-mode.ts +52 -52
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -62
- package/src/time-picker.tsx +615 -615
- package/src/toggle-group.tsx +138 -138
- package/src/tooltip.stories.tsx +43 -43
- package/src/tooltip.tsx +73 -73
- package/src/top-nav.stories.tsx +58 -58
- package/src/top-nav.tsx +324 -324
- package/src/undo-bar.tsx +107 -107
- package/src/utils.ts +45 -45
- package/src/view-toggle.stories.tsx +84 -84
- package/src/view-toggle.tsx +110 -110
|
@@ -1,477 +1,490 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import * as React from "react"
|
|
4
|
-
import type { Editor } from "@tiptap/core"
|
|
5
|
-
import type { Node as PmNode } from "@tiptap/pm/model"
|
|
6
|
-
import { NodeSelection, TextSelection } from "@tiptap/pm/state"
|
|
7
|
-
import { useEditorState } from "@tiptap/react"
|
|
8
|
-
|
|
9
|
-
import { Button } from "../button"
|
|
10
|
-
import { IconButton } from "../icon-button"
|
|
11
|
-
import { ToggleGroup } from "../toggle-group"
|
|
12
|
-
import { cn } from "../utils"
|
|
13
|
-
import type { Inline } from "./contract"
|
|
14
|
-
import { deleteBlock } from "./behaviour"
|
|
15
|
-
import { fill, type EditorLabels } from "./labels"
|
|
16
|
-
import { inlineText, textToInline, useEditorServices } from "./services"
|
|
17
|
-
|
|
18
|
-
const RICH = new Set(["callout", "table", "image", "file", "record", "chart", "signature", "barcode", "qr", "math"])
|
|
19
|
-
|
|
20
|
-
/** The rich block the selection is on or in: its node and position. */
|
|
21
|
-
function selectedRich(editor: Editor): { node: PmNode; pos: number } | null {
|
|
22
|
-
const sel = editor.state.selection
|
|
23
|
-
if (sel instanceof NodeSelection && RICH.has(sel.node.type.name)) return { node: sel.node, pos: sel.from }
|
|
24
|
-
const { $from } = sel
|
|
25
|
-
for (let d = $from.depth; d > 0; d--) {
|
|
26
|
-
const node = $from.node(d)
|
|
27
|
-
if (node.type.name === "table" || node.type.name === "callout") return { node, pos: $from.before(d) }
|
|
28
|
-
}
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function Sep() {
|
|
33
|
-
return <span aria-hidden="true" className="mx-[3px] h-[18px] w-px bg-border" />
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** A labelled text field the toolbar opens for one attribute; Enter keeps it, Esc leaves it. */
|
|
37
|
-
function FieldRow({ label, value, onDone, onCancel, mono }: { label: string; value: string; onDone: (v: string) => void; onCancel: () => void; mono?: boolean }) {
|
|
38
|
-
const [text, setText] = React.useState(value)
|
|
39
|
-
const ref = React.useRef<HTMLInputElement>(null)
|
|
40
|
-
React.useEffect(() => ref.current?.focus(), [])
|
|
41
|
-
const { labels } = useEditorServices()
|
|
42
|
-
return (
|
|
43
|
-
<div className="flex items-center gap-1.5 border-t border-border pt-1">
|
|
44
|
-
<label className="flex flex-1 items-center gap-2 text-[0.8125rem] text-muted-foreground">
|
|
45
|
-
{label}
|
|
46
|
-
<input
|
|
47
|
-
ref={ref}
|
|
48
|
-
value={text}
|
|
49
|
-
dir="auto"
|
|
50
|
-
onChange={(e) => setText(e.target.value)}
|
|
51
|
-
onKeyDown={(e) => {
|
|
52
|
-
if (e.key === "Enter") {
|
|
53
|
-
e.preventDefault()
|
|
54
|
-
onDone(text)
|
|
55
|
-
} else if (e.key === "Escape") {
|
|
56
|
-
e.preventDefault()
|
|
57
|
-
onCancel()
|
|
58
|
-
}
|
|
59
|
-
}}
|
|
60
|
-
className={cn(
|
|
61
|
-
"h-7 min-w-0 flex-1 rounded-control-sm border border-input bg-card px-2 text-[0.8125rem] text-foreground outline-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",
|
|
62
|
-
mono && "font-mono"
|
|
63
|
-
)}
|
|
64
|
-
/>
|
|
65
|
-
</label>
|
|
66
|
-
<Button size="sm" variant="outline" onClick={() => onDone(text)}>
|
|
67
|
-
{labels.done}
|
|
68
|
-
</Button>
|
|
69
|
-
</div>
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type Editing = { key: string; label: string; value: string; apply: (v: string) => void; mono?: boolean } | null
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* A selected rich block's own toolbar, above it (E.8, EditorBlockChrome):
|
|
77
|
-
* image width, caption, alt text, replace; table header row, rows and columns;
|
|
78
|
-
* callout kind; record and chart source; signature signers and stamp; barcode
|
|
79
|
-
* and QR value; the maths formula. Agents never use it (E.4).
|
|
80
|
-
*/
|
|
81
|
-
function BlockToolbar({ editor, labels, container }: { editor: Editor; labels: EditorLabels; container: React.RefObject<HTMLDivElement | null> }) {
|
|
82
|
-
const { services } = useEditorServices()
|
|
83
|
-
const target = useEditorState({ editor, selector: ({ editor: e }) => (e.isEditable ? selectedRich(e) : null) })
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
>
|
|
245
|
-
{labels.
|
|
246
|
-
</Button>
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
{
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
{
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import type { Editor } from "@tiptap/core"
|
|
5
|
+
import type { Node as PmNode } from "@tiptap/pm/model"
|
|
6
|
+
import { NodeSelection, TextSelection } from "@tiptap/pm/state"
|
|
7
|
+
import { useEditorState } from "@tiptap/react"
|
|
8
|
+
|
|
9
|
+
import { Button } from "../button"
|
|
10
|
+
import { IconButton } from "../icon-button"
|
|
11
|
+
import { ToggleGroup } from "../toggle-group"
|
|
12
|
+
import { cn } from "../utils"
|
|
13
|
+
import type { Inline } from "./contract"
|
|
14
|
+
import { deleteBlock } from "./behaviour"
|
|
15
|
+
import { fill, type EditorLabels } from "./labels"
|
|
16
|
+
import { inlineText, textToInline, useEditorServices } from "./services"
|
|
17
|
+
|
|
18
|
+
const RICH = new Set(["callout", "table", "image", "file", "record", "chart", "signature", "barcode", "qr", "math"])
|
|
19
|
+
|
|
20
|
+
/** The rich block the selection is on or in: its node and position. */
|
|
21
|
+
function selectedRich(editor: Editor): { node: PmNode; pos: number } | null {
|
|
22
|
+
const sel = editor.state.selection
|
|
23
|
+
if (sel instanceof NodeSelection && RICH.has(sel.node.type.name)) return { node: sel.node, pos: sel.from }
|
|
24
|
+
const { $from } = sel
|
|
25
|
+
for (let d = $from.depth; d > 0; d--) {
|
|
26
|
+
const node = $from.node(d)
|
|
27
|
+
if (node.type.name === "table" || node.type.name === "callout") return { node, pos: $from.before(d) }
|
|
28
|
+
}
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function Sep() {
|
|
33
|
+
return <span aria-hidden="true" className="mx-[3px] h-[18px] w-px bg-border" />
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A labelled text field the toolbar opens for one attribute; Enter keeps it, Esc leaves it. */
|
|
37
|
+
function FieldRow({ label, value, onDone, onCancel, mono }: { label: string; value: string; onDone: (v: string) => void; onCancel: () => void; mono?: boolean }) {
|
|
38
|
+
const [text, setText] = React.useState(value)
|
|
39
|
+
const ref = React.useRef<HTMLInputElement>(null)
|
|
40
|
+
React.useEffect(() => ref.current?.focus(), [])
|
|
41
|
+
const { labels } = useEditorServices()
|
|
42
|
+
return (
|
|
43
|
+
<div className="flex items-center gap-1.5 border-t border-border pt-1">
|
|
44
|
+
<label className="flex flex-1 items-center gap-2 text-[0.8125rem] text-muted-foreground">
|
|
45
|
+
{label}
|
|
46
|
+
<input
|
|
47
|
+
ref={ref}
|
|
48
|
+
value={text}
|
|
49
|
+
dir="auto"
|
|
50
|
+
onChange={(e) => setText(e.target.value)}
|
|
51
|
+
onKeyDown={(e) => {
|
|
52
|
+
if (e.key === "Enter") {
|
|
53
|
+
e.preventDefault()
|
|
54
|
+
onDone(text)
|
|
55
|
+
} else if (e.key === "Escape") {
|
|
56
|
+
e.preventDefault()
|
|
57
|
+
onCancel()
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
className={cn(
|
|
61
|
+
"h-7 min-w-0 flex-1 rounded-control-sm border border-input bg-card px-2 text-[0.8125rem] text-foreground outline-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",
|
|
62
|
+
mono && "font-mono"
|
|
63
|
+
)}
|
|
64
|
+
/>
|
|
65
|
+
</label>
|
|
66
|
+
<Button size="sm" variant="outline" onClick={() => onDone(text)}>
|
|
67
|
+
{labels.done}
|
|
68
|
+
</Button>
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type Editing = { key: string; label: string; value: string; apply: (v: string) => void; mono?: boolean } | null
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A selected rich block's own toolbar, above it (E.8, EditorBlockChrome):
|
|
77
|
+
* image width, caption, alt text, replace; table header row, rows and columns;
|
|
78
|
+
* callout kind; record and chart source; signature signers and stamp; barcode
|
|
79
|
+
* and QR value; the maths formula. Agents never use it (E.4).
|
|
80
|
+
*/
|
|
81
|
+
function BlockToolbar({ editor, labels, container }: { editor: Editor; labels: EditorLabels; container: React.RefObject<HTMLDivElement | null> }) {
|
|
82
|
+
const { services } = useEditorServices()
|
|
83
|
+
const target = useEditorState({ editor, selector: ({ editor: e }) => (e.isEditable ? selectedRich(e) : null) })
|
|
84
|
+
// A document opens with its caret at the start, which in most starters is
|
|
85
|
+
// inside the first table: shown then, the bar sat over the letterhead before
|
|
86
|
+
// the author had touched anything. It waits for the first focus and stays
|
|
87
|
+
// after it, so typing in its own fields (which blurs the editor) keeps it.
|
|
88
|
+
const [engaged, setEngaged] = React.useState(() => editor.isFocused)
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
if (engaged) return
|
|
91
|
+
const onFocus = () => setEngaged(true)
|
|
92
|
+
editor.on("focus", onFocus)
|
|
93
|
+
return () => {
|
|
94
|
+
editor.off("focus", onFocus)
|
|
95
|
+
}
|
|
96
|
+
}, [editor, engaged])
|
|
97
|
+
const [editing, setEditing] = React.useState<Editing>(null)
|
|
98
|
+
const [busy, setBusy] = React.useState(false)
|
|
99
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
100
|
+
const fileInput = React.useRef<HTMLInputElement>(null)
|
|
101
|
+
const [top, setTop] = React.useState<number | null>(null)
|
|
102
|
+
// On a label sheet (E.43) the label is small and its neighbours repeat it, so
|
|
103
|
+
// the bar opens below the block, where it covers nothing the author needs.
|
|
104
|
+
const [below, setBelow] = React.useState(false)
|
|
105
|
+
|
|
106
|
+
const pos = target?.pos
|
|
107
|
+
React.useEffect(() => setEditing(null), [pos])
|
|
108
|
+
React.useLayoutEffect(() => {
|
|
109
|
+
if (pos === undefined || !container.current) {
|
|
110
|
+
setTop(null)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
const dom = editor.view.nodeDOM(pos) as HTMLElement | null
|
|
114
|
+
if (!dom) return
|
|
115
|
+
const box = container.current.getBoundingClientRect()
|
|
116
|
+
const rect = dom.getBoundingClientRect()
|
|
117
|
+
const inLabel = !!dom.closest(".wy-ls__label")
|
|
118
|
+
setBelow(inLabel)
|
|
119
|
+
setTop((inLabel ? rect.bottom + 10 : rect.top) - box.top)
|
|
120
|
+
}, [editor, pos, container, target?.node])
|
|
121
|
+
|
|
122
|
+
if (!engaged || !target || top === null) return null
|
|
123
|
+
const { node } = target
|
|
124
|
+
const type = node.type.name
|
|
125
|
+
const attrs = node.attrs as Record<string, unknown>
|
|
126
|
+
const set = (next: Record<string, unknown>) => {
|
|
127
|
+
const current = editor.state.doc.nodeAt(target.pos)
|
|
128
|
+
if (!current) return
|
|
129
|
+
const tr = editor.state.tr.setNodeMarkup(target.pos, undefined, { ...current.attrs, ...next })
|
|
130
|
+
if (editor.state.selection instanceof NodeSelection) tr.setSelection(NodeSelection.create(tr.doc, target.pos))
|
|
131
|
+
editor.view.dispatch(tr)
|
|
132
|
+
}
|
|
133
|
+
const edit = (key: string, label: string, value: string, apply: (v: string) => void, mono?: boolean) => setEditing({ key, label, value, apply, mono })
|
|
134
|
+
const remove = () => deleteBlock(editor, target.pos)
|
|
135
|
+
const del = <IconButton icon="delete" label={labels.deleteBlock} size="sm" onClick={remove} />
|
|
136
|
+
|
|
137
|
+
const upload = async (file: File) => {
|
|
138
|
+
if (!services.uploadFile) return
|
|
139
|
+
setBusy(true)
|
|
140
|
+
setError(null)
|
|
141
|
+
try {
|
|
142
|
+
const up = await services.uploadFile(file)
|
|
143
|
+
if (type === "image") set({ src: up.url, alt: (attrs.alt as string) || file.name.replace(/\.[^.]+$/, "") })
|
|
144
|
+
else set({ fileId: up.fileId, name: up.name, size: up.size, mime: up.mime })
|
|
145
|
+
} catch {
|
|
146
|
+
setError(labels.uploadFailed)
|
|
147
|
+
} finally {
|
|
148
|
+
setBusy(false)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let controls: React.ReactNode = null
|
|
153
|
+
if (type === "callout") {
|
|
154
|
+
controls = (
|
|
155
|
+
<ToggleGroup
|
|
156
|
+
size="sm"
|
|
157
|
+
label={labels.blockCallout}
|
|
158
|
+
required
|
|
159
|
+
value={attrs.kind === "important" ? "important" : "note"}
|
|
160
|
+
onChange={(v) => set({ kind: v })}
|
|
161
|
+
options={[
|
|
162
|
+
{ value: "note", label: labels.calloutNote, icon: "info" },
|
|
163
|
+
{ value: "important", label: labels.calloutImportant, icon: "alert" },
|
|
164
|
+
]}
|
|
165
|
+
/>
|
|
166
|
+
)
|
|
167
|
+
} else if (type === "image" || type === "file") {
|
|
168
|
+
controls = (
|
|
169
|
+
<>
|
|
170
|
+
{type === "image" && (
|
|
171
|
+
<>
|
|
172
|
+
<ToggleGroup
|
|
173
|
+
size="sm"
|
|
174
|
+
label={labels.blockImage}
|
|
175
|
+
required
|
|
176
|
+
value={String(attrs.width ?? "full")}
|
|
177
|
+
onChange={(v) => set({ width: v })}
|
|
178
|
+
options={[
|
|
179
|
+
{ value: "half", label: labels.widthHalf, icon: "columns", iconOnly: true },
|
|
180
|
+
{ value: "wide", label: labels.widthWide, icon: "continuous", iconOnly: true },
|
|
181
|
+
{ value: "full", label: labels.widthFull, icon: "page", iconOnly: true },
|
|
182
|
+
]}
|
|
183
|
+
/>
|
|
184
|
+
<Sep />
|
|
185
|
+
<Button variant="ghost" size="sm" onClick={() => edit("caption", labels.caption, inlineText(attrs.caption as Inline[] | null), (v) => set({ caption: v.trim() ? textToInline(v, attrs.caption as Inline[] | null) : null }))}>
|
|
186
|
+
{labels.caption}
|
|
187
|
+
</Button>
|
|
188
|
+
<Button variant="ghost" size="sm" onClick={() => edit("alt", labels.altText, String(attrs.alt ?? ""), (v) => set({ alt: v.trim() }))}>
|
|
189
|
+
{labels.altText}
|
|
190
|
+
</Button>
|
|
191
|
+
</>
|
|
192
|
+
)}
|
|
193
|
+
{services.uploadFile && (
|
|
194
|
+
<Button variant="ghost" size="sm" loading={busy} onClick={() => fileInput.current?.click()}>
|
|
195
|
+
{busy ? labels.uploading : (type === "image" ? attrs.src : attrs.fileId) ? labels.replace : labels.upload}
|
|
196
|
+
</Button>
|
|
197
|
+
)}
|
|
198
|
+
<input
|
|
199
|
+
ref={fileInput}
|
|
200
|
+
type="file"
|
|
201
|
+
hidden
|
|
202
|
+
/* What the server stores (FormUploadPolicy): PNG and JPEG images, and PDF for files. */
|
|
203
|
+
accept={type === "image" ? "image/png,image/jpeg" : "application/pdf,image/png,image/jpeg"}
|
|
204
|
+
onChange={(e) => {
|
|
205
|
+
const file = e.target.files?.[0]
|
|
206
|
+
e.target.value = ""
|
|
207
|
+
if (file) void upload(file)
|
|
208
|
+
}}
|
|
209
|
+
/>
|
|
210
|
+
<Sep />
|
|
211
|
+
{del}
|
|
212
|
+
</>
|
|
213
|
+
)
|
|
214
|
+
} else if (type === "table") {
|
|
215
|
+
const sel = editor.state.selection
|
|
216
|
+
const cellPos = (() => {
|
|
217
|
+
const { $from } = sel
|
|
218
|
+
for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === "tableCell") return { row: $from.index(d - 2), col: $from.index(d - 1) }
|
|
219
|
+
return null
|
|
220
|
+
})()
|
|
221
|
+
const columns = ((attrs.columns as { align: string; widthPct?: number }[]) ?? []).slice()
|
|
222
|
+
const width = Math.max(columns.length, ...Array.from({ length: node.childCount }, (_, i) => node.child(i).childCount))
|
|
223
|
+
const setRows = (mutate: (rows: Inline[][][]) => Inline[][][], nextColumns = columns) => {
|
|
224
|
+
// Rebuild through the contract so cells keep their content and marks.
|
|
225
|
+
const json = node.toJSON() as { content?: { content?: { content?: unknown[] }[] }[] }
|
|
226
|
+
const rows: Inline[][][] = (json.content ?? []).map((r) => (r.content ?? []).map((c) => (c.content ?? []) as Inline[]))
|
|
227
|
+
const next = mutate(rows)
|
|
228
|
+
const table = editor.schema.nodeFromJSON({
|
|
229
|
+
type: "table",
|
|
230
|
+
attrs: { ...node.attrs, columns: nextColumns },
|
|
231
|
+
content: next.map((r) => ({ type: "tableRow", content: r.map((c) => ({ type: "tableCell", ...(c.length ? { content: c } : {}) })) })),
|
|
232
|
+
})
|
|
233
|
+
const tr = editor.state.tr.replaceWith(target.pos, target.pos + node.nodeSize, table)
|
|
234
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.min(target.pos + 3, tr.doc.content.size))))
|
|
235
|
+
editor.view.dispatch(tr)
|
|
236
|
+
}
|
|
237
|
+
const blankRow = () => Array.from({ length: width }, () => [] as Inline[])
|
|
238
|
+
controls = (
|
|
239
|
+
<>
|
|
240
|
+
<Button variant="ghost" size="sm" icon={attrs.headerRow ? "check" : undefined} active={Boolean(attrs.headerRow)} onClick={() => set({ headerRow: !attrs.headerRow })}>
|
|
241
|
+
{labels.headerRow}
|
|
242
|
+
</Button>
|
|
243
|
+
<Sep />
|
|
244
|
+
<Button variant="ghost" size="sm" icon="plus" onClick={() => setRows((rows) => { const r = rows.slice(); r.splice(cellPos ? cellPos.row + 1 : r.length, 0, blankRow()); return r })}>
|
|
245
|
+
{labels.addRow}
|
|
246
|
+
</Button>
|
|
247
|
+
<Button
|
|
248
|
+
variant="ghost"
|
|
249
|
+
size="sm"
|
|
250
|
+
icon="plus"
|
|
251
|
+
onClick={() => {
|
|
252
|
+
const at = cellPos ? cellPos.col + 1 : width
|
|
253
|
+
const nextColumns = Array.from({ length: width }, (_, i) => columns[i] ?? { align: "start" as const })
|
|
254
|
+
nextColumns.splice(at, 0, { align: "start" })
|
|
255
|
+
setRows((rows) => rows.map((r) => { const c = r.slice(); while (c.length < width) c.push([]); c.splice(at, 0, []); return c }), nextColumns)
|
|
256
|
+
}}
|
|
257
|
+
>
|
|
258
|
+
{labels.addColumn}
|
|
259
|
+
</Button>
|
|
260
|
+
{cellPos && (
|
|
261
|
+
<>
|
|
262
|
+
<Sep />
|
|
263
|
+
<ToggleGroup
|
|
264
|
+
size="sm"
|
|
265
|
+
label={labels.columnAlign}
|
|
266
|
+
required
|
|
267
|
+
value={columns[cellPos.col]?.align === "end" ? "end" : "start"}
|
|
268
|
+
onChange={(v) => {
|
|
269
|
+
const next = Array.from({ length: width }, (_, i) => columns[i] ?? { align: "start" as const })
|
|
270
|
+
next[cellPos.col] = { ...next[cellPos.col], align: v === "end" ? "end" : "start" }
|
|
271
|
+
set({ columns: next })
|
|
272
|
+
}}
|
|
273
|
+
options={[
|
|
274
|
+
{ value: "start", label: labels.alignStart },
|
|
275
|
+
{ value: "end", label: labels.alignEnd },
|
|
276
|
+
]}
|
|
277
|
+
/>
|
|
278
|
+
<IconButton icon="minus" label={labels.deleteRow} size="sm" disabled={node.childCount <= 1} onClick={() => setRows((rows) => rows.filter((_, i) => i !== cellPos.row))} />
|
|
279
|
+
<IconButton
|
|
280
|
+
icon="close"
|
|
281
|
+
label={labels.deleteColumn}
|
|
282
|
+
size="sm"
|
|
283
|
+
disabled={width <= 1}
|
|
284
|
+
onClick={() => setRows((rows) => rows.map((r) => r.filter((_, i) => i !== cellPos.col)), columns.filter((_, i) => i !== cellPos.col))}
|
|
285
|
+
/>
|
|
286
|
+
</>
|
|
287
|
+
)}
|
|
288
|
+
<Sep />
|
|
289
|
+
{del}
|
|
290
|
+
</>
|
|
291
|
+
)
|
|
292
|
+
} else if (type === "record") {
|
|
293
|
+
const ref = attrs.ref as { type: string; id: string } | null
|
|
294
|
+
controls = (
|
|
295
|
+
<>
|
|
296
|
+
{services.recordTypes && services.recordTypes.length > 0 && (
|
|
297
|
+
<select
|
|
298
|
+
aria-label={labels.recordType}
|
|
299
|
+
value={ref?.type ?? ""}
|
|
300
|
+
onChange={(e) => set({ ref: e.target.value ? { type: e.target.value, id: ref?.id ?? "" } : null })}
|
|
301
|
+
className="h-7 rounded-control-sm border border-input bg-card px-1.5 text-[0.8125rem]"
|
|
302
|
+
>
|
|
303
|
+
<option value="">{labels.recordType}</option>
|
|
304
|
+
{services.recordTypes.map((t) => (
|
|
305
|
+
<option key={t.key} value={t.key}>
|
|
306
|
+
{t.label}
|
|
307
|
+
</option>
|
|
308
|
+
))}
|
|
309
|
+
</select>
|
|
310
|
+
)}
|
|
311
|
+
<Button variant="ghost" size="sm" disabled={!ref?.type} onClick={() => edit("record", labels.recordId, ref?.id ?? "", (v) => set({ ref: { type: ref!.type, id: v.trim() } }), true)}>
|
|
312
|
+
{labels.recordChoose}
|
|
313
|
+
</Button>
|
|
314
|
+
<Sep />
|
|
315
|
+
<ToggleGroup
|
|
316
|
+
size="sm"
|
|
317
|
+
label={labels.blockRecord}
|
|
318
|
+
required
|
|
319
|
+
value={attrs.view === "summary" ? "summary" : "card"}
|
|
320
|
+
onChange={(v) => set({ view: v })}
|
|
321
|
+
options={[
|
|
322
|
+
{ value: "card", label: labels.viewCard },
|
|
323
|
+
{ value: "summary", label: labels.viewSummary },
|
|
324
|
+
]}
|
|
325
|
+
/>
|
|
326
|
+
<Sep />
|
|
327
|
+
{del}
|
|
328
|
+
</>
|
|
329
|
+
)
|
|
330
|
+
} else if (type === "chart") {
|
|
331
|
+
const source = attrs.source as { query: string; params?: Record<string, string> } | null
|
|
332
|
+
controls = (
|
|
333
|
+
<>
|
|
334
|
+
<ToggleGroup
|
|
335
|
+
size="sm"
|
|
336
|
+
label={labels.blockChart}
|
|
337
|
+
required
|
|
338
|
+
value={String(attrs.chart ?? "bar")}
|
|
339
|
+
onChange={(v) => set({ chart: v })}
|
|
340
|
+
options={[
|
|
341
|
+
{ value: "bar", label: labels.chartBar },
|
|
342
|
+
{ value: "line", label: labels.chartLine },
|
|
343
|
+
{ value: "donut", label: labels.chartDonut },
|
|
344
|
+
]}
|
|
345
|
+
/>
|
|
346
|
+
{services.chartSources && services.chartSources.length > 0 && (
|
|
347
|
+
<>
|
|
348
|
+
<Sep />
|
|
349
|
+
<select
|
|
350
|
+
aria-label={labels.chartSource}
|
|
351
|
+
value={source?.query ?? ""}
|
|
352
|
+
onChange={(e) => set({ source: e.target.value ? { query: e.target.value } : null })}
|
|
353
|
+
className="h-7 rounded-control-sm border border-input bg-card px-1.5 text-[0.8125rem]"
|
|
354
|
+
>
|
|
355
|
+
<option value="">{labels.chartSource}</option>
|
|
356
|
+
{services.chartSources.map((s) => (
|
|
357
|
+
<option key={s.key} value={s.key}>
|
|
358
|
+
{s.label}
|
|
359
|
+
</option>
|
|
360
|
+
))}
|
|
361
|
+
</select>
|
|
362
|
+
</>
|
|
363
|
+
)}
|
|
364
|
+
<Button variant="ghost" size="sm" onClick={() => edit("title", labels.chartTitle, String(attrs.title ?? ""), (v) => set({ title: v.trim() || null }))}>
|
|
365
|
+
{labels.chartTitle}
|
|
366
|
+
</Button>
|
|
367
|
+
<Sep />
|
|
368
|
+
{del}
|
|
369
|
+
</>
|
|
370
|
+
)
|
|
371
|
+
} else if (type === "signature") {
|
|
372
|
+
const signers = (attrs.signers as { name: Inline[]; role: Inline[] }[]) ?? []
|
|
373
|
+
controls = (
|
|
374
|
+
<>
|
|
375
|
+
{signers.map((s, i) => (
|
|
376
|
+
<Button
|
|
377
|
+
key={i}
|
|
378
|
+
variant="ghost"
|
|
379
|
+
size="sm"
|
|
380
|
+
onClick={() =>
|
|
381
|
+
edit(`signer-${i}`, fill(labels.signatureName, {}), `${inlineText(s.name)} | ${inlineText(s.role)}`, (v) => {
|
|
382
|
+
const [name, role = ""] = v.split("|").map((x) => x.trim())
|
|
383
|
+
const next = signers.slice()
|
|
384
|
+
next[i] = { name: textToInline(name, s.name), role: textToInline(role, s.role) }
|
|
385
|
+
set({ signers: next })
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
>
|
|
389
|
+
{inlineText(s.name) || labels.signatureName}
|
|
390
|
+
</Button>
|
|
391
|
+
))}
|
|
392
|
+
<Button variant="ghost" size="sm" icon="plus" disabled={signers.length >= 3} onClick={() => set({ signers: [...signers, { name: [], role: [] }] })}>
|
|
393
|
+
{labels.addSigner}
|
|
394
|
+
</Button>
|
|
395
|
+
<Button variant="ghost" size="sm" onClick={() => edit("date", labels.signatureDate, inlineText(attrs.date as Inline[]), (v) => set({ date: textToInline(v, attrs.date as Inline[]) }))}>
|
|
396
|
+
{/* @date-display-ignore: the signature date is text the author typed or a merge field (Inline[]), not a record timestamp; this is its label. */}
|
|
397
|
+
{labels.signatureDate}
|
|
398
|
+
</Button>
|
|
399
|
+
<Button variant="ghost" size="sm" active={Boolean(attrs.stamp)} onClick={() => set({ stamp: !attrs.stamp })}>
|
|
400
|
+
{labels.stamp}
|
|
401
|
+
</Button>
|
|
402
|
+
<Sep />
|
|
403
|
+
{del}
|
|
404
|
+
</>
|
|
405
|
+
)
|
|
406
|
+
} else if (type === "barcode" || type === "qr") {
|
|
407
|
+
controls = (
|
|
408
|
+
<>
|
|
409
|
+
{type === "barcode" && (
|
|
410
|
+
<select
|
|
411
|
+
aria-label={labels.symbology}
|
|
412
|
+
value={String(attrs.symbology ?? "code128")}
|
|
413
|
+
onChange={(e) => set({ symbology: e.target.value })}
|
|
414
|
+
className="h-7 rounded-control-sm border border-input bg-card px-1.5 text-[0.8125rem]"
|
|
415
|
+
>
|
|
416
|
+
<option value="code128">Code 128</option>
|
|
417
|
+
<option value="ean13">EAN-13</option>
|
|
418
|
+
<option value="code39">Code 39</option>
|
|
419
|
+
</select>
|
|
420
|
+
)}
|
|
421
|
+
<Button variant="ghost" size="sm" onClick={() => edit("value", labels.value, inlineText(attrs.value as Inline[]), (v) => set({ value: textToInline(v, attrs.value as Inline[]) }), true)}>
|
|
422
|
+
{labels.value}
|
|
423
|
+
</Button>
|
|
424
|
+
{type === "barcode" ? (
|
|
425
|
+
<Button variant="ghost" size="sm" active={Boolean(attrs.showText)} onClick={() => set({ showText: !attrs.showText })}>
|
|
426
|
+
{labels.showText}
|
|
427
|
+
</Button>
|
|
428
|
+
) : (
|
|
429
|
+
<Button variant="ghost" size="sm" onClick={() => edit("caption", labels.caption, inlineText(attrs.caption as Inline[] | null), (v) => set({ caption: v.trim() ? textToInline(v, attrs.caption as Inline[] | null) : null }))}>
|
|
430
|
+
{labels.caption}
|
|
431
|
+
</Button>
|
|
432
|
+
)}
|
|
433
|
+
<Sep />
|
|
434
|
+
{del}
|
|
435
|
+
</>
|
|
436
|
+
)
|
|
437
|
+
} else if (type === "math") {
|
|
438
|
+
controls = (
|
|
439
|
+
<>
|
|
440
|
+
<Button variant="ghost" size="sm" onClick={() => edit("tex", labels.formula, String(attrs.tex ?? ""), (v) => set({ tex: v }), true)}>
|
|
441
|
+
{labels.formula}
|
|
442
|
+
</Button>
|
|
443
|
+
<Sep />
|
|
444
|
+
{del}
|
|
445
|
+
</>
|
|
446
|
+
)
|
|
447
|
+
}
|
|
448
|
+
if (!controls) return null
|
|
449
|
+
|
|
450
|
+
return (
|
|
451
|
+
<div
|
|
452
|
+
role="toolbar"
|
|
453
|
+
aria-label={labels.blockToolbar}
|
|
454
|
+
data-slot="block-toolbar"
|
|
455
|
+
className={cn(
|
|
456
|
+
"absolute start-0 z-20 grid gap-1 rounded-control border border-border bg-popover p-[3px] shadow-float",
|
|
457
|
+
below ? "w-max max-w-[420px]" : "max-w-full"
|
|
458
|
+
)}
|
|
459
|
+
style={below ? { top } : { top, transform: "translateY(calc(-100% - 10px))" }}
|
|
460
|
+
onMouseDown={(e) => {
|
|
461
|
+
if ((e.target as HTMLElement).tagName !== "INPUT" && (e.target as HTMLElement).tagName !== "SELECT") e.preventDefault()
|
|
462
|
+
}}
|
|
463
|
+
>
|
|
464
|
+
<div className="flex flex-wrap items-center gap-0.5">{controls}</div>
|
|
465
|
+
{error && (
|
|
466
|
+
<div role="alert" className="px-1.5 pb-0.5 text-xs text-error-text">
|
|
467
|
+
{error}
|
|
468
|
+
</div>
|
|
469
|
+
)}
|
|
470
|
+
{editing && (
|
|
471
|
+
<FieldRow
|
|
472
|
+
key={editing.key}
|
|
473
|
+
label={editing.label}
|
|
474
|
+
value={editing.value}
|
|
475
|
+
mono={editing.mono}
|
|
476
|
+
onCancel={() => {
|
|
477
|
+
setEditing(null)
|
|
478
|
+
editor.commands.focus()
|
|
479
|
+
}}
|
|
480
|
+
onDone={(v) => {
|
|
481
|
+
editing.apply(v)
|
|
482
|
+
setEditing(null)
|
|
483
|
+
}}
|
|
484
|
+
/>
|
|
485
|
+
)}
|
|
486
|
+
</div>
|
|
487
|
+
)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export { BlockToolbar }
|