@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
package/src/editor/extensions.ts
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import type { AnyExtension } from "@tiptap/core"
|
|
2
|
-
import { Gapcursor, Placeholder, UndoRedo } from "@tiptap/extensions"
|
|
3
|
-
|
|
4
|
-
import { BlockIds } from "./block-ids"
|
|
5
|
-
import { DocumentBehaviour } from "./behaviour"
|
|
6
|
-
import { richNodeViews } from "./node-views"
|
|
7
|
-
import { CheckItem, schemaExtensions } from "./schema"
|
|
8
|
-
import { Suggesting } from "./suggesting"
|
|
9
|
-
import { TableKeys } from "./table-keys"
|
|
10
|
-
|
|
11
|
-
/** The checklist box: a real checkbox button, outside the editable text. */
|
|
12
|
-
const CheckItemWithBox = CheckItem.extend({
|
|
13
|
-
addNodeView() {
|
|
14
|
-
return ({ node: initial, getPos, editor }) => {
|
|
15
|
-
let node = initial
|
|
16
|
-
const dom = document.createElement("div")
|
|
17
|
-
const box = document.createElement("button")
|
|
18
|
-
const contentDOM = document.createElement("div")
|
|
19
|
-
box.type = "button"
|
|
20
|
-
box.contentEditable = "false"
|
|
21
|
-
box.setAttribute("role", "checkbox")
|
|
22
|
-
box.className = "wy-check"
|
|
23
|
-
contentDOM.className = "wy-check-text"
|
|
24
|
-
dom.append(box, contentDOM)
|
|
25
|
-
|
|
26
|
-
const paint = () => {
|
|
27
|
-
dom.dataset.type = "check-item"
|
|
28
|
-
dom.dataset.level = String(node.attrs.level)
|
|
29
|
-
dom.dataset.checked = node.attrs.checked ? "true" : "false"
|
|
30
|
-
if (node.attrs.id) dom.dataset.blockId = node.attrs.id
|
|
31
|
-
box.setAttribute("aria-checked", node.attrs.checked ? "true" : "false")
|
|
32
|
-
box.setAttribute("aria-label", node.textContent || "Checklist item")
|
|
33
|
-
}
|
|
34
|
-
paint()
|
|
35
|
-
|
|
36
|
-
box.addEventListener("mousedown", (e) => e.preventDefault())
|
|
37
|
-
box.addEventListener("click", () => {
|
|
38
|
-
if (!editor.isEditable) return
|
|
39
|
-
const pos = typeof getPos === "function" ? getPos() : undefined
|
|
40
|
-
if (pos === undefined) return
|
|
41
|
-
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, checked: !node.attrs.checked }))
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
dom,
|
|
46
|
-
contentDOM,
|
|
47
|
-
update(next) {
|
|
48
|
-
if (next.type !== node.type) return false
|
|
49
|
-
node = next
|
|
50
|
-
paint()
|
|
51
|
-
return true
|
|
52
|
-
},
|
|
53
|
-
ignoreMutation: (m) => m.target === box || box.contains(m.target as globalThis.Node),
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
export interface DocumentExtensionOptions {
|
|
60
|
-
/** The focused empty line's hint (EditorInsert card). */
|
|
61
|
-
placeholder?: string
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Everything the document editor runs on, in one list. */
|
|
65
|
-
export function documentExtensions({ placeholder }: DocumentExtensionOptions = {}): AnyExtension[] {
|
|
66
|
-
return [
|
|
67
|
-
...schemaExtensions.map((ext) => {
|
|
68
|
-
if (ext.name === "checkItem") return CheckItemWithBox
|
|
69
|
-
// M3 blocks get their editor views (node-views.tsx).
|
|
70
|
-
return richNodeViews.find((view) => view.name === ext.name) ?? ext
|
|
71
|
-
}),
|
|
72
|
-
Gapcursor,
|
|
73
|
-
TableKeys,
|
|
74
|
-
BlockIds,
|
|
75
|
-
DocumentBehaviour,
|
|
76
|
-
// Off until the editor turns Suggesting mode on (M5); also draws comment highlights.
|
|
77
|
-
Suggesting,
|
|
78
|
-
UndoRedo.configure({ depth: 200 }),
|
|
79
|
-
Placeholder.configure({
|
|
80
|
-
placeholder: placeholder ?? "Type / for blocks, {{ for fields, or just write",
|
|
81
|
-
showOnlyCurrent: true,
|
|
82
|
-
includeChildren: false,
|
|
83
|
-
emptyNodeClass: "is-empty",
|
|
84
|
-
}),
|
|
85
|
-
]
|
|
86
|
-
}
|
|
1
|
+
import type { AnyExtension } from "@tiptap/core"
|
|
2
|
+
import { Gapcursor, Placeholder, UndoRedo } from "@tiptap/extensions"
|
|
3
|
+
|
|
4
|
+
import { BlockIds } from "./block-ids"
|
|
5
|
+
import { DocumentBehaviour } from "./behaviour"
|
|
6
|
+
import { richNodeViews } from "./node-views"
|
|
7
|
+
import { CheckItem, schemaExtensions } from "./schema"
|
|
8
|
+
import { Suggesting } from "./suggesting"
|
|
9
|
+
import { TableKeys } from "./table-keys"
|
|
10
|
+
|
|
11
|
+
/** The checklist box: a real checkbox button, outside the editable text. */
|
|
12
|
+
const CheckItemWithBox = CheckItem.extend({
|
|
13
|
+
addNodeView() {
|
|
14
|
+
return ({ node: initial, getPos, editor }) => {
|
|
15
|
+
let node = initial
|
|
16
|
+
const dom = document.createElement("div")
|
|
17
|
+
const box = document.createElement("button")
|
|
18
|
+
const contentDOM = document.createElement("div")
|
|
19
|
+
box.type = "button"
|
|
20
|
+
box.contentEditable = "false"
|
|
21
|
+
box.setAttribute("role", "checkbox")
|
|
22
|
+
box.className = "wy-check"
|
|
23
|
+
contentDOM.className = "wy-check-text"
|
|
24
|
+
dom.append(box, contentDOM)
|
|
25
|
+
|
|
26
|
+
const paint = () => {
|
|
27
|
+
dom.dataset.type = "check-item"
|
|
28
|
+
dom.dataset.level = String(node.attrs.level)
|
|
29
|
+
dom.dataset.checked = node.attrs.checked ? "true" : "false"
|
|
30
|
+
if (node.attrs.id) dom.dataset.blockId = node.attrs.id
|
|
31
|
+
box.setAttribute("aria-checked", node.attrs.checked ? "true" : "false")
|
|
32
|
+
box.setAttribute("aria-label", node.textContent || "Checklist item")
|
|
33
|
+
}
|
|
34
|
+
paint()
|
|
35
|
+
|
|
36
|
+
box.addEventListener("mousedown", (e) => e.preventDefault())
|
|
37
|
+
box.addEventListener("click", () => {
|
|
38
|
+
if (!editor.isEditable) return
|
|
39
|
+
const pos = typeof getPos === "function" ? getPos() : undefined
|
|
40
|
+
if (pos === undefined) return
|
|
41
|
+
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, checked: !node.attrs.checked }))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
dom,
|
|
46
|
+
contentDOM,
|
|
47
|
+
update(next) {
|
|
48
|
+
if (next.type !== node.type) return false
|
|
49
|
+
node = next
|
|
50
|
+
paint()
|
|
51
|
+
return true
|
|
52
|
+
},
|
|
53
|
+
ignoreMutation: (m) => m.target === box || box.contains(m.target as globalThis.Node),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export interface DocumentExtensionOptions {
|
|
60
|
+
/** The focused empty line's hint (EditorInsert card). */
|
|
61
|
+
placeholder?: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Everything the document editor runs on, in one list. */
|
|
65
|
+
export function documentExtensions({ placeholder }: DocumentExtensionOptions = {}): AnyExtension[] {
|
|
66
|
+
return [
|
|
67
|
+
...schemaExtensions.map((ext) => {
|
|
68
|
+
if (ext.name === "checkItem") return CheckItemWithBox
|
|
69
|
+
// M3 blocks get their editor views (node-views.tsx).
|
|
70
|
+
return richNodeViews.find((view) => view.name === ext.name) ?? ext
|
|
71
|
+
}),
|
|
72
|
+
Gapcursor,
|
|
73
|
+
TableKeys,
|
|
74
|
+
BlockIds,
|
|
75
|
+
DocumentBehaviour,
|
|
76
|
+
// Off until the editor turns Suggesting mode on (M5); also draws comment highlights.
|
|
77
|
+
Suggesting,
|
|
78
|
+
UndoRedo.configure({ depth: 200 }),
|
|
79
|
+
Placeholder.configure({
|
|
80
|
+
placeholder: placeholder ?? "Type / for blocks, {{ for fields, or just write",
|
|
81
|
+
showOnlyCurrent: true,
|
|
82
|
+
includeChildren: false,
|
|
83
|
+
emptyNodeClass: "is-empty",
|
|
84
|
+
}),
|
|
85
|
+
]
|
|
86
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import type { Editor } from "@tiptap/core"
|
|
5
|
+
import { NodeSelection } from "@tiptap/pm/state"
|
|
6
|
+
import { useEditorState } from "@tiptap/react"
|
|
7
|
+
|
|
8
|
+
import { Button } from "../button"
|
|
9
|
+
import { IconButton } from "../icon-button"
|
|
10
|
+
import { FieldPicker, flatFields } from "./field-picker"
|
|
11
|
+
import { filterFields, type FieldDef, type FieldGroup } from "./fields"
|
|
12
|
+
import type { EditorLabels } from "./labels"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A selected merge field's own bar (E.26): what fills it (its group, its
|
|
16
|
+
* sample) and the two things an author does to one: change it for another
|
|
17
|
+
* field, or remove it. Before this, clicking a chip only selected it, so the
|
|
18
|
+
* only way to swap "Bill to" for "Customer name" was to delete it and find the
|
|
19
|
+
* new one in Field ▾.
|
|
20
|
+
*/
|
|
21
|
+
function FieldBar({
|
|
22
|
+
editor,
|
|
23
|
+
labels,
|
|
24
|
+
groups,
|
|
25
|
+
container,
|
|
26
|
+
}: {
|
|
27
|
+
editor: Editor
|
|
28
|
+
labels: EditorLabels
|
|
29
|
+
groups: FieldGroup[] | undefined
|
|
30
|
+
container: React.RefObject<HTMLDivElement | null>
|
|
31
|
+
}) {
|
|
32
|
+
const target = useEditorState({
|
|
33
|
+
editor,
|
|
34
|
+
selector: ({ editor: e }) => {
|
|
35
|
+
const sel = e.state.selection
|
|
36
|
+
return e.isEditable && sel instanceof NodeSelection && sel.node.type.name === "field" ? { node: sel.node, pos: sel.from } : null
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
const [changing, setChanging] = React.useState(false)
|
|
40
|
+
const [query, setQuery] = React.useState("")
|
|
41
|
+
const [active, setActive] = React.useState(0)
|
|
42
|
+
const [place, setPlace] = React.useState<{ top: number; start: number } | null>(null)
|
|
43
|
+
|
|
44
|
+
const pos = target?.pos
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
setChanging(false)
|
|
47
|
+
setQuery("")
|
|
48
|
+
}, [pos])
|
|
49
|
+
React.useLayoutEffect(() => {
|
|
50
|
+
if (pos === undefined || !container.current) {
|
|
51
|
+
setPlace(null)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
const dom = editor.view.nodeDOM(pos) as HTMLElement | null
|
|
55
|
+
if (!dom) return
|
|
56
|
+
const box = container.current.getBoundingClientRect()
|
|
57
|
+
const rect = dom.getBoundingClientRect()
|
|
58
|
+
const rtl = getComputedStyle(container.current).direction === "rtl"
|
|
59
|
+
setPlace({ top: rect.bottom - box.top + 6, start: rtl ? box.right - rect.right : rect.left - box.left })
|
|
60
|
+
}, [editor, pos, container, target?.node])
|
|
61
|
+
|
|
62
|
+
const all = React.useMemo(() => flatFields(groups ?? []), [groups])
|
|
63
|
+
const shown = React.useMemo(() => filterFields(groups ?? [], query), [groups, query])
|
|
64
|
+
const flat = flatFields(shown)
|
|
65
|
+
React.useEffect(() => setActive(0), [query, changing])
|
|
66
|
+
|
|
67
|
+
if (!target || !place) return null
|
|
68
|
+
const path = String(target.node.attrs.path ?? "")
|
|
69
|
+
const def: FieldDef | undefined = all.find((f) => f.path === path)
|
|
70
|
+
const group = (groups ?? []).find((g) => g.items.some((f) => f.path === path))?.group
|
|
71
|
+
const label = String(target.node.attrs.label || def?.label || path)
|
|
72
|
+
|
|
73
|
+
const replace = (field: FieldDef) => {
|
|
74
|
+
editor
|
|
75
|
+
.chain()
|
|
76
|
+
.focus()
|
|
77
|
+
.command(({ tr }) => {
|
|
78
|
+
tr.setNodeMarkup(target.pos, undefined, { ...target.node.attrs, path: field.path, label: field.label, required: field.required ? true : null })
|
|
79
|
+
tr.setSelection(NodeSelection.create(tr.doc, target.pos))
|
|
80
|
+
return true
|
|
81
|
+
})
|
|
82
|
+
.run()
|
|
83
|
+
setChanging(false)
|
|
84
|
+
}
|
|
85
|
+
const remove = () => editor.chain().focus().deleteRange({ from: target.pos, to: target.pos + target.node.nodeSize }).run()
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div
|
|
89
|
+
role="toolbar"
|
|
90
|
+
aria-label={labels.fieldBar}
|
|
91
|
+
data-slot="field-bar"
|
|
92
|
+
className="absolute z-20 grid w-max max-w-[360px] gap-1 rounded-control border border-border bg-popover p-1.5 text-sm text-popover-foreground shadow-float"
|
|
93
|
+
style={{ top: place.top, insetInlineStart: Math.max(0, place.start) }}
|
|
94
|
+
onMouseDown={(e) => {
|
|
95
|
+
if ((e.target as HTMLElement).tagName !== "INPUT") e.preventDefault()
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<div className="flex items-center gap-2 px-1">
|
|
99
|
+
<span className="min-w-0">
|
|
100
|
+
<span className="block truncate font-medium" dir="auto">
|
|
101
|
+
{label}
|
|
102
|
+
</span>
|
|
103
|
+
<span className="block truncate text-xs text-muted-foreground" dir="auto">
|
|
104
|
+
{[group, def?.sample ? `${labels.fieldExample} ${def.sample}` : null].filter(Boolean).join(" · ")}
|
|
105
|
+
</span>
|
|
106
|
+
</span>
|
|
107
|
+
<span className="ms-auto flex shrink-0 items-center gap-0.5">
|
|
108
|
+
{all.length > 0 && (
|
|
109
|
+
<Button variant="outline" size="sm" onClick={() => setChanging((v) => !v)} aria-expanded={changing}>
|
|
110
|
+
{labels.fieldChange}
|
|
111
|
+
</Button>
|
|
112
|
+
)}
|
|
113
|
+
<IconButton icon="delete" label={labels.fieldRemove} size="sm" onClick={remove} />
|
|
114
|
+
</span>
|
|
115
|
+
</div>
|
|
116
|
+
{changing && (
|
|
117
|
+
<FieldPicker
|
|
118
|
+
id="wy-fieldbar"
|
|
119
|
+
groups={shown}
|
|
120
|
+
active={Math.min(active, Math.max(0, flat.length - 1))}
|
|
121
|
+
onActive={setActive}
|
|
122
|
+
onPick={replace}
|
|
123
|
+
labels={labels}
|
|
124
|
+
search={
|
|
125
|
+
<input
|
|
126
|
+
autoFocus
|
|
127
|
+
aria-label={labels.fieldSearch}
|
|
128
|
+
placeholder={labels.fieldSearch}
|
|
129
|
+
value={query}
|
|
130
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
131
|
+
onKeyDown={(e) => {
|
|
132
|
+
const n = flat.length || 1
|
|
133
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
134
|
+
e.preventDefault()
|
|
135
|
+
setActive((i) => (i + (e.key === "ArrowDown" ? 1 : n - 1)) % n)
|
|
136
|
+
} else if (e.key === "Enter" && flat[active]) {
|
|
137
|
+
e.preventDefault()
|
|
138
|
+
replace(flat[active])
|
|
139
|
+
} else if (e.key === "Escape") {
|
|
140
|
+
e.preventDefault()
|
|
141
|
+
setChanging(false)
|
|
142
|
+
editor.commands.focus()
|
|
143
|
+
}
|
|
144
|
+
}}
|
|
145
|
+
className="mx-1 mb-1 h-8 rounded-control-sm border border-input bg-card px-2 text-sm outline-none focus-visible:border-ring"
|
|
146
|
+
/>
|
|
147
|
+
}
|
|
148
|
+
/>
|
|
149
|
+
)}
|
|
150
|
+
</div>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { FieldBar }
|
|
@@ -1,107 +1,109 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import * as React from "react"
|
|
4
|
-
|
|
5
|
-
import { Icon } from "../icon"
|
|
6
|
-
import { cn } from "../utils"
|
|
7
|
-
import type { FieldDef, FieldGroup } from "./fields"
|
|
8
|
-
import type { EditorLabels } from "./labels"
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The field picker (EditorInline): a searchable list grouped by record, each
|
|
12
|
-
* field as its chip with a sample value. Typing {{ fills the query from the
|
|
13
|
-
* text; Field ▾ in the toolbar gives it a search box instead.
|
|
14
|
-
*/
|
|
15
|
-
function FieldPicker({
|
|
16
|
-
groups,
|
|
17
|
-
query,
|
|
18
|
-
active,
|
|
19
|
-
onActive,
|
|
20
|
-
onPick,
|
|
21
|
-
labels,
|
|
22
|
-
search,
|
|
23
|
-
footer,
|
|
24
|
-
id,
|
|
25
|
-
}: {
|
|
26
|
-
/** Already filtered by the query. */
|
|
27
|
-
groups: FieldGroup[]
|
|
28
|
-
/** What was typed after {{, shown at the top. */
|
|
29
|
-
query?: string
|
|
30
|
-
active: number
|
|
31
|
-
onActive: (index: number) => void
|
|
32
|
-
onPick: (field: FieldDef) => void
|
|
33
|
-
labels: EditorLabels
|
|
34
|
-
/** Field ▾'s own search box, in place of the query line. */
|
|
35
|
-
search?: React.ReactNode
|
|
36
|
-
/** Below the list: Field ▾'s "New field". */
|
|
37
|
-
footer?: React.ReactNode
|
|
38
|
-
id: string
|
|
39
|
-
}) {
|
|
40
|
-
const listRef = React.useRef<HTMLDivElement>(null)
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
listRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" })
|
|
43
|
-
}, [active])
|
|
44
|
-
|
|
45
|
-
let index = -1
|
|
46
|
-
return (
|
|
47
|
-
<div
|
|
48
|
-
data-slot="field-picker"
|
|
49
|
-
className="wy-fpick grid w-[
|
|
50
|
-
>
|
|
51
|
-
{search ??
|
|
52
|
-
(query !== undefined && (
|
|
53
|
-
<div className="flex items-center gap-1.5 px-2 pt-1 pb-1.5 text-xs text-muted-foreground">
|
|
54
|
-
<Icon name="search" size={14} />
|
|
55
|
-
{query ? <b className="font-medium text-foreground">{query}</b> : labels.fieldSearch}
|
|
56
|
-
</div>
|
|
57
|
-
))}
|
|
58
|
-
<div ref={listRef} id={id} role="listbox" aria-label={labels.fieldPicker} className="grid max-h-[320px] gap-0.5 overflow-y-auto">
|
|
59
|
-
{groups.length === 0 && <div className="px-2 py-3 text-muted-foreground">{labels.noFields}</div>}
|
|
60
|
-
{groups.map((group) => (
|
|
61
|
-
<div key={group.group} role="group" aria-label={group.group} className="grid gap-0.5">
|
|
62
|
-
<div role="presentation" className="px-2 pt-1.5 pb-0.5 text-xs font-medium text-muted-foreground">
|
|
63
|
-
{group.group}
|
|
64
|
-
</div>
|
|
65
|
-
{group.items.map((field) => {
|
|
66
|
-
index += 1
|
|
67
|
-
const i = index
|
|
68
|
-
const on = i === active
|
|
69
|
-
return (
|
|
70
|
-
<div
|
|
71
|
-
key={field.path}
|
|
72
|
-
role="option"
|
|
73
|
-
id={`${id}-${i}`}
|
|
74
|
-
aria-selected={on}
|
|
75
|
-
data-index={i}
|
|
76
|
-
title={field.path}
|
|
77
|
-
onMouseDown={(e) => e.preventDefault()}
|
|
78
|
-
onMouseMove={() => onActive(i)}
|
|
79
|
-
onClick={() => onPick(field)}
|
|
80
|
-
className={cn(
|
|
81
|
-
"wy-fpick__it flex cursor-pointer items-center gap-2 rounded-control px-2 py-1.5",
|
|
82
|
-
on && "bg-primary-tint text-primary-tint-foreground"
|
|
83
|
-
)}
|
|
84
|
-
>
|
|
85
|
-
<span className="wy-mf">{field.label}</span>
|
|
86
|
-
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { Icon } from "../icon"
|
|
6
|
+
import { cn } from "../utils"
|
|
7
|
+
import type { FieldDef, FieldGroup } from "./fields"
|
|
8
|
+
import type { EditorLabels } from "./labels"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The field picker (EditorInline): a searchable list grouped by record, each
|
|
12
|
+
* field as its chip with a sample value. Typing {{ fills the query from the
|
|
13
|
+
* text; Field ▾ in the toolbar gives it a search box instead.
|
|
14
|
+
*/
|
|
15
|
+
function FieldPicker({
|
|
16
|
+
groups,
|
|
17
|
+
query,
|
|
18
|
+
active,
|
|
19
|
+
onActive,
|
|
20
|
+
onPick,
|
|
21
|
+
labels,
|
|
22
|
+
search,
|
|
23
|
+
footer,
|
|
24
|
+
id,
|
|
25
|
+
}: {
|
|
26
|
+
/** Already filtered by the query. */
|
|
27
|
+
groups: FieldGroup[]
|
|
28
|
+
/** What was typed after {{, shown at the top. */
|
|
29
|
+
query?: string
|
|
30
|
+
active: number
|
|
31
|
+
onActive: (index: number) => void
|
|
32
|
+
onPick: (field: FieldDef) => void
|
|
33
|
+
labels: EditorLabels
|
|
34
|
+
/** Field ▾'s own search box, in place of the query line. */
|
|
35
|
+
search?: React.ReactNode
|
|
36
|
+
/** Below the list: Field ▾'s "New field". */
|
|
37
|
+
footer?: React.ReactNode
|
|
38
|
+
id: string
|
|
39
|
+
}) {
|
|
40
|
+
const listRef = React.useRef<HTMLDivElement>(null)
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
listRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" })
|
|
43
|
+
}, [active])
|
|
44
|
+
|
|
45
|
+
let index = -1
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
data-slot="field-picker"
|
|
49
|
+
className="wy-fpick grid w-[340px] max-w-[calc(100vw-2rem)] gap-0.5 rounded-lg border border-border bg-popover p-1 text-sm text-popover-foreground shadow-float"
|
|
50
|
+
>
|
|
51
|
+
{search ??
|
|
52
|
+
(query !== undefined && (
|
|
53
|
+
<div className="flex items-center gap-1.5 px-2 pt-1 pb-1.5 text-xs text-muted-foreground">
|
|
54
|
+
<Icon name="search" size={14} />
|
|
55
|
+
{query ? <b className="font-medium text-foreground">{query}</b> : labels.fieldSearch}
|
|
56
|
+
</div>
|
|
57
|
+
))}
|
|
58
|
+
<div ref={listRef} id={id} role="listbox" aria-label={labels.fieldPicker} className="grid max-h-[320px] gap-0.5 overflow-y-auto">
|
|
59
|
+
{groups.length === 0 && <div className="px-2 py-3 text-muted-foreground">{labels.noFields}</div>}
|
|
60
|
+
{groups.map((group) => (
|
|
61
|
+
<div key={group.group} role="group" aria-label={group.group} className="grid gap-0.5">
|
|
62
|
+
<div role="presentation" className="px-2 pt-1.5 pb-0.5 text-xs font-medium text-muted-foreground">
|
|
63
|
+
{group.group}
|
|
64
|
+
</div>
|
|
65
|
+
{group.items.map((field) => {
|
|
66
|
+
index += 1
|
|
67
|
+
const i = index
|
|
68
|
+
const on = i === active
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
key={field.path}
|
|
72
|
+
role="option"
|
|
73
|
+
id={`${id}-${i}`}
|
|
74
|
+
aria-selected={on}
|
|
75
|
+
data-index={i}
|
|
76
|
+
title={field.path}
|
|
77
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
78
|
+
onMouseMove={() => onActive(i)}
|
|
79
|
+
onClick={() => onPick(field)}
|
|
80
|
+
className={cn(
|
|
81
|
+
"wy-fpick__it flex cursor-pointer items-center gap-2 rounded-control px-2 py-1.5",
|
|
82
|
+
on && "bg-primary-tint text-primary-tint-foreground"
|
|
83
|
+
)}
|
|
84
|
+
>
|
|
85
|
+
<span className="wy-mf shrink-0">{field.label}</span>
|
|
86
|
+
{/* min-w-0 lets the sample give way: without it a long chip
|
|
87
|
+
pushed "7 November 2026" past the picker's edge. */}
|
|
88
|
+
{field.sample && (
|
|
89
|
+
<span dir="auto" title={field.sample} className="ms-auto min-w-0 truncate text-xs text-muted-foreground">
|
|
90
|
+
{field.sample}
|
|
91
|
+
</span>
|
|
92
|
+
)}
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
})}
|
|
96
|
+
</div>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
{footer}
|
|
100
|
+
</div>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The fields in picker order, so the active index maps back to one. */
|
|
105
|
+
function flatFields(groups: FieldGroup[]): FieldDef[] {
|
|
106
|
+
return groups.flatMap((g) => g.items)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { FieldPicker, flatFields }
|