@whity/ui 0.0.0-stage → 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.
Files changed (205) hide show
  1. package/README.md +106 -2
  2. package/package.json +219 -4
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +338 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +604 -0
  16. package/src/approval-queue.tsx +109 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar-pattern.ts +138 -0
  22. package/src/avatar.tsx +125 -0
  23. package/src/badge.stories.tsx +105 -0
  24. package/src/badge.tsx +68 -0
  25. package/src/beta-warning.stories.tsx +79 -0
  26. package/src/beta-warning.tsx +189 -0
  27. package/src/bilingual-input.stories.tsx +82 -0
  28. package/src/bilingual-input.tsx +188 -0
  29. package/src/board.tsx +216 -0
  30. package/src/breadcrumb.stories.tsx +51 -0
  31. package/src/breadcrumb.tsx +90 -0
  32. package/src/built-on-whity.tsx +52 -0
  33. package/src/button.stories.tsx +87 -0
  34. package/src/button.tsx +123 -0
  35. package/src/card.stories.tsx +423 -0
  36. package/src/card.tsx +180 -0
  37. package/src/chart.stories.tsx +66 -0
  38. package/src/chart.tsx +228 -0
  39. package/src/checkbox.stories.tsx +62 -0
  40. package/src/checkbox.tsx +54 -0
  41. package/src/collapsible.stories.tsx +48 -0
  42. package/src/collapsible.tsx +34 -0
  43. package/src/color-card.stories.tsx +61 -0
  44. package/src/color-card.tsx +270 -0
  45. package/src/color-picker.stories.tsx +65 -0
  46. package/src/color-picker.tsx +425 -0
  47. package/src/column-matcher.tsx +84 -0
  48. package/src/command-palette.tsx +398 -0
  49. package/src/confirm-action.tsx +98 -0
  50. package/src/copy-block.stories.tsx +38 -0
  51. package/src/copy-block.tsx +85 -0
  52. package/src/data-table.stories.tsx +200 -0
  53. package/src/data-table.tsx +1686 -0
  54. package/src/date-picker.stories.tsx +61 -0
  55. package/src/date-picker.tsx +456 -0
  56. package/src/design-cards.stories.tsx +551 -0
  57. package/src/dialog.stories.tsx +48 -0
  58. package/src/dialog.tsx +179 -0
  59. package/src/display-preferences.tsx +50 -0
  60. package/src/documents/barcode-svg.stories.tsx +72 -0
  61. package/src/documents/barcode-svg.tsx +79 -0
  62. package/src/dropdown-menu.stories.tsx +77 -0
  63. package/src/dropdown-menu.tsx +271 -0
  64. package/src/editor/agent-panel.tsx +222 -0
  65. package/src/editor/agents.stories.tsx +81 -0
  66. package/src/editor/agents.ts +55 -0
  67. package/src/editor/behaviour.ts +279 -0
  68. package/src/editor/block-ids.ts +44 -0
  69. package/src/editor/block-list.tsx +104 -0
  70. package/src/editor/block-toolbar.tsx +490 -0
  71. package/src/editor/bubble.tsx +119 -0
  72. package/src/editor/catalogue.ts +169 -0
  73. package/src/editor/collab-rail.tsx +746 -0
  74. package/src/editor/collab.stories.tsx +207 -0
  75. package/src/editor/collab.ts +87 -0
  76. package/src/editor/contract.ts +476 -0
  77. package/src/editor/convert.ts +414 -0
  78. package/src/editor/doc-editor.stories.tsx +98 -0
  79. package/src/editor/doc-editor.tsx +1492 -0
  80. package/src/editor/editor.css +636 -0
  81. package/src/editor/extensions.ts +86 -0
  82. package/src/editor/field-bar.tsx +154 -0
  83. package/src/editor/field-picker.tsx +109 -0
  84. package/src/editor/fields.ts +100 -0
  85. package/src/editor/gutter.tsx +443 -0
  86. package/src/editor/index.ts +23 -0
  87. package/src/editor/label-sheet.tsx +289 -0
  88. package/src/editor/labels.ts +394 -0
  89. package/src/editor/link-tools.tsx +141 -0
  90. package/src/editor/node-views.tsx +461 -0
  91. package/src/editor/page-view.tsx +372 -0
  92. package/src/editor/phone.tsx +310 -0
  93. package/src/editor/plugin-block-view.tsx +230 -0
  94. package/src/editor/plugin-blocks.stories.tsx +96 -0
  95. package/src/editor/plugin-blocks.ts +52 -0
  96. package/src/editor/publish-check.tsx +201 -0
  97. package/src/editor/rich-blocks.stories.tsx +146 -0
  98. package/src/editor/sample.ts +40 -0
  99. package/src/editor/save-block-dialog.tsx +141 -0
  100. package/src/editor/saved-block-view.tsx +205 -0
  101. package/src/editor/saved-blocks.stories.tsx +105 -0
  102. package/src/editor/saved-parts.ts +192 -0
  103. package/src/editor/schema-rich.ts +156 -0
  104. package/src/editor/schema.ts +368 -0
  105. package/src/editor/services.tsx +205 -0
  106. package/src/editor/slash.ts +64 -0
  107. package/src/editor/suggesting.ts +372 -0
  108. package/src/editor/suggestions.ts +763 -0
  109. package/src/editor/table-keys.ts +66 -0
  110. package/src/editor/templates.stories.tsx +324 -0
  111. package/src/editor/toolbar.tsx +364 -0
  112. package/src/empty-state.stories.tsx +51 -0
  113. package/src/empty-state.tsx +126 -0
  114. package/src/empty-state.usage-notes.md +30 -0
  115. package/src/form.stories.tsx +112 -0
  116. package/src/form.tsx +176 -0
  117. package/src/globals.css +20 -0
  118. package/src/icon-button.tsx +85 -0
  119. package/src/icon-map.ts +335 -0
  120. package/src/icon.tsx +41 -0
  121. package/src/index.ts +90 -0
  122. package/src/input.stories.tsx +157 -0
  123. package/src/input.tsx +768 -0
  124. package/src/kpi-strip.tsx +47 -0
  125. package/src/localized-text.ts +76 -0
  126. package/src/locked-screen.stories.tsx +29 -0
  127. package/src/locked-screen.tsx +75 -0
  128. package/src/lockup.tsx +42 -0
  129. package/src/lottie.tsx +441 -0
  130. package/src/mark.tsx +62 -0
  131. package/src/math-text.stories.tsx +33 -0
  132. package/src/math-text.tsx +43 -0
  133. package/src/menu-bar.stories.tsx +198 -0
  134. package/src/menu-bar.tsx +373 -0
  135. package/src/message-thread.tsx +181 -0
  136. package/src/money/currency.ts +244 -0
  137. package/src/money/money-input.tsx +131 -0
  138. package/src/money/money.tsx +33 -0
  139. package/src/open-on-computer.tsx +150 -0
  140. package/src/otp-input.tsx +161 -0
  141. package/src/page-header.stories.tsx +95 -0
  142. package/src/page-header.tsx +122 -0
  143. package/src/page-shell.stories.tsx +42 -0
  144. package/src/page-shell.tsx +32 -0
  145. package/src/page-states.tsx +277 -0
  146. package/src/pagination.stories.tsx +45 -0
  147. package/src/pagination.tsx +98 -0
  148. package/src/paper-sheet.stories.tsx +88 -0
  149. package/src/paper-sheet.tsx +85 -0
  150. package/src/phone-tab-bar.tsx +152 -0
  151. package/src/plugin-card.stories.tsx +208 -0
  152. package/src/plugin-card.tsx +931 -0
  153. package/src/popover.stories.tsx +48 -0
  154. package/src/popover.tsx +55 -0
  155. package/src/radio-group.stories.tsx +26 -0
  156. package/src/radio-group.tsx +44 -0
  157. package/src/route-flow/editor.tsx +1087 -0
  158. package/src/route-flow/model.ts +771 -0
  159. package/src/save-bar.tsx +94 -0
  160. package/src/scope-grant.tsx +139 -0
  161. package/src/screen-too-small.stories.tsx +61 -0
  162. package/src/screen-too-small.tsx +104 -0
  163. package/src/search-field.tsx +65 -0
  164. package/src/select.stories.tsx +44 -0
  165. package/src/select.tsx +197 -0
  166. package/src/separator.stories.tsx +34 -0
  167. package/src/separator.tsx +34 -0
  168. package/src/sheet.stories.tsx +49 -0
  169. package/src/sheet.tsx +168 -0
  170. package/src/skeleton.stories.tsx +28 -0
  171. package/src/skeleton.tsx +19 -0
  172. package/src/slider.stories.tsx +78 -0
  173. package/src/slider.tsx +300 -0
  174. package/src/spinner.stories.tsx +33 -0
  175. package/src/spinner.tsx +55 -0
  176. package/src/stepper.tsx +85 -0
  177. package/src/switch.stories.tsx +42 -0
  178. package/src/switch.tsx +41 -0
  179. package/src/switcher.stories.tsx +111 -0
  180. package/src/switcher.tsx +131 -0
  181. package/src/system-state.tsx +55 -0
  182. package/src/table.stories.tsx +48 -0
  183. package/src/table.tsx +121 -0
  184. package/src/tabs.stories.tsx +74 -0
  185. package/src/tabs.tsx +90 -0
  186. package/src/tag-input.stories.tsx +67 -0
  187. package/src/tag-input.tsx +117 -0
  188. package/src/tenant-logo.tsx +63 -0
  189. package/src/tenant-switcher.stories.tsx +38 -0
  190. package/src/tenant-switcher.tsx +164 -0
  191. package/src/textarea.stories.tsx +27 -0
  192. package/src/textarea.tsx +18 -0
  193. package/src/theme-mode.ts +52 -0
  194. package/src/time-grid.tsx +163 -0
  195. package/src/time-picker.stories.tsx +62 -0
  196. package/src/time-picker.tsx +615 -0
  197. package/src/toggle-group.tsx +138 -0
  198. package/src/tooltip.stories.tsx +43 -0
  199. package/src/tooltip.tsx +73 -0
  200. package/src/top-nav.stories.tsx +58 -0
  201. package/src/top-nav.tsx +324 -0
  202. package/src/undo-bar.tsx +107 -0
  203. package/src/utils.ts +45 -0
  204. package/src/view-toggle.stories.tsx +84 -0
  205. package/src/view-toggle.tsx +110 -0
@@ -0,0 +1,192 @@
1
+ import type { Block, Inline, PerDocumentKey, PerDocumentPart } from "./contract"
2
+
3
+ /**
4
+ * Per-document parts of a synced saved block (E.23, E.23a). In the original,
5
+ * text carries the `perDocument` mark and a merge field sets `perDocument`.
6
+ * Since design 3.4 each part has a stable key, `pd_` + 8 characters, minted
7
+ * once when the creator marks it and kept through edits, moves and
8
+ * translation; adjacent runs with the same key are one part, and a
9
+ * document's `overrides` fill parts by key.
10
+ *
11
+ * Rows from before 3.4 carry no key: each run of consecutive marked text and
12
+ * fields in a block's line is one part, named by where it sits,
13
+ * `<block id>#<n>`. That name (`legacy`) is still worked out for every part,
14
+ * so a value stored under it keeps filling the same part. Migration 270
15
+ * gave stored rows their keys; Whity's printer (SavedBlockExpander,
16
+ * PerDocumentParts) finds parts the same way.
17
+ */
18
+
19
+ export type Segment = { part: null; runs: Inline[] } | { part: PerDocumentKey; legacy: string; runs: Inline[] }
20
+
21
+ /** The blocks whose `content` holds a line of text (and so can hold a part). */
22
+ const TEXT_TYPES = new Set(["paragraph", "heading", "quote", "bullet", "number", "checklist", "callout"])
23
+
24
+ const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"
25
+
26
+ /** A fresh part key: `pd_` + 8 characters of a nanoid alphabet (E.23a). */
27
+ export function mintPartKey(): PerDocumentKey {
28
+ const bytes = new Uint8Array(8)
29
+ crypto.getRandomValues(bytes)
30
+ return "pd_" + Array.from(bytes, (b) => ALPHABET[b & 63]).join("")
31
+ }
32
+
33
+ /** The part a run belongs to: null when it isn't one, "" for a part with no key yet, else its key. */
34
+ export function partKeyOf(run: Inline): string | null {
35
+ // Rows from before 3.4 have the mark without a key.
36
+ const mark = (run.type === "text" || run.type === "field" ? run.marks?.find((m) => m.type === "perDocument") : undefined) as { key?: unknown } | undefined
37
+ const markKey = mark ? (typeof mark.key === "string" && mark.key ? mark.key : "") : null
38
+ if (run.type === "text") return markKey
39
+ if (run.type === "field") {
40
+ const own = run.perDocument as unknown
41
+ if (typeof own === "string" && own) return own
42
+ if (own === true) return markKey ?? ""
43
+ return markKey
44
+ }
45
+ return null
46
+ }
47
+
48
+ export function isPerDocument(run: Inline): boolean {
49
+ return partKeyOf(run) !== null
50
+ }
51
+
52
+ /** A block's line split into plain runs and parts, in order. */
53
+ export function segments(blockId: string, content: Inline[]): Segment[] {
54
+ const out: Segment[] = []
55
+ let n = 0
56
+ let current: string | null = null
57
+ for (const run of content) {
58
+ const key = partKeyOf(run)
59
+ const last = out[out.length - 1]
60
+ if (last && key === current && (key !== null || last.part === null)) {
61
+ last.runs.push(run)
62
+ } else if (key === null) {
63
+ out.push({ part: null, runs: [run] })
64
+ } else {
65
+ const legacy = `${blockId}#${n++}`
66
+ out.push({ part: key || legacy, legacy, runs: [run] })
67
+ }
68
+ current = key
69
+ }
70
+ return out
71
+ }
72
+
73
+ /** What a document holds for a part: by its key, then by its pre-3.4 name. Undefined when nothing. */
74
+ export function lookupPart(overrides: Partial<Record<string, Inline[]>>, segment: Segment): Inline[] | undefined {
75
+ if (segment.part === null) return undefined
76
+ for (const name of [segment.part, segment.legacy]) {
77
+ const value = overrides[name]
78
+ if (value && value.length) return value
79
+ }
80
+ return undefined
81
+ }
82
+
83
+ function textContent(block: Block): Inline[] | null {
84
+ return TEXT_TYPES.has(block.type) && "content" in block && Array.isArray(block.content) ? (block.content as Inline[]) : null
85
+ }
86
+
87
+ function collect(blocks: Block[], found: Map<string, Inline[]>): void {
88
+ for (const block of blocks) {
89
+ const content = textContent(block)
90
+ if (content) for (const s of segments(block.id, content)) if (s.part !== null) found.set(s.part, [...(found.get(s.part) ?? []), ...s.runs])
91
+ if (block.type === "toggle") collect(block.children, found)
92
+ if (block.type === "columns") {
93
+ collect(block.columns[0], found)
94
+ collect(block.columns[1], found)
95
+ }
96
+ }
97
+ }
98
+
99
+ /** Every part's key in a saved block's blocks, in reading order, nested toggles and columns included. */
100
+ export function perDocumentKeys(blocks: Block[]): PerDocumentKey[] {
101
+ const found = new Map<string, Inline[]>()
102
+ collect(blocks, found)
103
+ return [...found.keys()]
104
+ }
105
+
106
+ /**
107
+ * The parts in reading order, each once, keeping what `previous` gave each key
108
+ * (label, required, placeholder). A new part is labelled with its own text.
109
+ */
110
+ export function perDocumentParts(blocks: Block[], previous: PerDocumentPart[] = []): PerDocumentPart[] {
111
+ const found = new Map<string, Inline[]>()
112
+ collect(blocks, found)
113
+ const before = new Map(previous.map((p) => [p.key, p]))
114
+ return [...found].map(([key, runs]) => {
115
+ const kind: PerDocumentPart["kind"] = runs.every((r) => r.type === "field") ? "field" : "text"
116
+ const old = before.get(key)
117
+ const text = partText(runs).replace(/\s+/g, " ").trim().slice(0, 120)
118
+ return { ...old, key, kind, label: old?.label?.en ? old.label : { en: text || key } }
119
+ })
120
+ }
121
+
122
+ /** The run with its part's key written on its mark (and on a field's `perDocument`). */
123
+ function withKey(run: Inline, key: PerDocumentKey): Inline {
124
+ if (run.type !== "text" && run.type !== "field") return run
125
+ const out = { ...run } as typeof run
126
+ if (run.marks) out.marks = run.marks.map((m) => (m.type === "perDocument" ? { type: "perDocument", key } : m)) as typeof run.marks
127
+ if (out.type === "field" && out.perDocument !== undefined) out.perDocument = key
128
+ return out
129
+ }
130
+
131
+ /**
132
+ * Gives every part that has no key one (E.23a). `map` takes each part's
133
+ * pre-3.4 name to its key, reused when present and filled in for every part.
134
+ */
135
+ export function assignPartKeys(blocks: Block[], map: Map<string, PerDocumentKey> = new Map()): Block[] {
136
+ return blocks.map((block) => {
137
+ const content = textContent(block)
138
+ let next: Block = block
139
+ if (content) {
140
+ const runs = segments(block.id, content).flatMap((s) => {
141
+ if (s.part === null) return s.runs
142
+ if (s.part !== s.legacy) {
143
+ if (!map.has(s.legacy)) map.set(s.legacy, s.part)
144
+ return s.runs
145
+ }
146
+ const key = map.get(s.legacy) ?? mintPartKey()
147
+ map.set(s.legacy, key)
148
+ return s.runs.map((r) => withKey(r, key))
149
+ })
150
+ next = { ...block, content: runs } as Block
151
+ }
152
+ if (next.type === "toggle") next = { ...next, children: assignPartKeys(next.children, map) }
153
+ if (next.type === "columns") next = { ...next, columns: [assignPartKeys(next.columns[0], map), assignPartKeys(next.columns[1], map)] }
154
+ return next
155
+ })
156
+ }
157
+
158
+ /**
159
+ * The blocks with each filled part replaced by the document's own text (and
160
+ * the per-document mark dropped): what Detach leaves in the document.
161
+ */
162
+ export function applyOverrides(blocks: Block[], overrides: Partial<Record<string, Inline[]>>): Block[] {
163
+ return blocks.map((block) => {
164
+ const content = textContent(block)
165
+ let next: Block = block
166
+ if (content) {
167
+ const runs = segments(block.id, content).flatMap((s) => {
168
+ if (s.part === null) return s.runs
169
+ const own = lookupPart(overrides, s) ?? s.runs
170
+ return own.map((r) => (r.type === "text" || r.type === "field" ? unmark(r) : r))
171
+ })
172
+ next = { ...block, content: runs } as Block
173
+ }
174
+ if (next.type === "toggle") next = { ...next, children: applyOverrides(next.children, overrides) }
175
+ if (next.type === "columns") next = { ...next, columns: [applyOverrides(next.columns[0], overrides), applyOverrides(next.columns[1], overrides)] }
176
+ return next
177
+ })
178
+ }
179
+
180
+ function unmark<T extends Inline & { marks?: { type: string }[] }>(run: T): T {
181
+ const marks = run.marks?.filter((m) => m.type !== "perDocument")
182
+ const out = { ...run } as T & { perDocument?: unknown }
183
+ if (marks && marks.length) out.marks = marks as T["marks"]
184
+ else delete out.marks
185
+ if (out.type === "field") delete out.perDocument
186
+ return out
187
+ }
188
+
189
+ /** The plain text a part shows when the document hasn't filled it: the original's. */
190
+ export function partText(runs: Inline[]): string {
191
+ return runs.map((r) => (r.type === "text" ? r.text : r.type === "field" ? r.label || r.path : r.type === "math" ? r.tex : "\n")).join("")
192
+ }
@@ -0,0 +1,156 @@
1
+ import { Node, mergeAttributes } from "@tiptap/core"
2
+
3
+ /**
4
+ * The rich blocks of editor milestone M3 (E.13–E.16, E.40–E.42), on top of
5
+ * schema.ts. Containers (toggle, columns, table) hold editable content; the
6
+ * rest are atoms whose contract fields live in attributes and are edited
7
+ * through their block toolbar (E.8). Every block keeps its `id` and optional
8
+ * `suggestion`, like the text blocks.
9
+ */
10
+
11
+ const blockAttributes = {
12
+ id: { default: null, keepOnSplit: false },
13
+ suggestion: { default: null, rendered: false },
14
+ }
15
+
16
+ const dataAttrs = (attrs: Record<string, unknown>, type: string, extra: Record<string, unknown> = {}) =>
17
+ mergeAttributes({ "data-block-id": attrs.id ?? undefined, "data-type": type, ...extra })
18
+
19
+ /** An attribute that holds contract JSON (objects, arrays) and is never rendered to the DOM. */
20
+ const json = (fallback: unknown = null) => ({ default: fallback, rendered: false })
21
+
22
+ /** E.14: two kinds only, Note (grey) and Important (warning tint). */
23
+ export const Callout = Node.create({
24
+ name: "callout",
25
+ group: "block",
26
+ content: "inline*",
27
+ defining: true,
28
+ addAttributes: () => ({ ...blockAttributes, kind: { default: "note" } }),
29
+ parseHTML: () => [{ tag: "div[data-type=callout]" }],
30
+ renderHTML: ({ node }) => ["div", dataAttrs(node.attrs, "callout", { "data-kind": node.attrs.kind }), 0],
31
+ })
32
+
33
+ /** A toggle: a summary line and the blocks it hides. */
34
+ export const Toggle = Node.create({
35
+ name: "toggle",
36
+ group: "block",
37
+ content: "toggleSummary block*",
38
+ defining: true,
39
+ addAttributes: () => ({ ...blockAttributes, open: { default: true } }),
40
+ parseHTML: () => [{ tag: "div[data-type=toggle]" }],
41
+ renderHTML: ({ node }) => ["div", dataAttrs(node.attrs, "toggle", { "data-open": node.attrs.open ? "true" : "false" }), 0],
42
+ })
43
+
44
+ export const ToggleSummary = Node.create({
45
+ name: "toggleSummary",
46
+ content: "inline*",
47
+ defining: true,
48
+ parseHTML: () => [{ tag: "div[data-type=toggle-summary]" }],
49
+ renderHTML: () => ["div", { "data-type": "toggle-summary" }, 0],
50
+ })
51
+
52
+ /** E.13: two columns. A column may be empty, so the editor never invents content. */
53
+ export const Columns = Node.create({
54
+ name: "columns",
55
+ group: "block",
56
+ content: "column column",
57
+ defining: true,
58
+ addAttributes: () => blockAttributes,
59
+ parseHTML: () => [{ tag: "div[data-type=columns]" }],
60
+ renderHTML: ({ node }) => ["div", dataAttrs(node.attrs, "columns"), 0],
61
+ })
62
+
63
+ export const Column = Node.create({
64
+ name: "column",
65
+ content: "block*",
66
+ isolating: true,
67
+ parseHTML: () => [{ tag: "div[data-type=column]" }],
68
+ renderHTML: () => ["div", { "data-type": "column" }, 0],
69
+ })
70
+
71
+ /** E.15: a document table — rows, columns, an optional header row, end-aligned numbers. Not a database. */
72
+ export const Table = Node.create({
73
+ name: "table",
74
+ group: "block",
75
+ content: "tableRow*",
76
+ isolating: true,
77
+ addAttributes: () => ({ ...blockAttributes, headerRow: { default: true }, columns: json([]) }),
78
+ parseHTML: () => [{ tag: "table" }],
79
+ renderHTML: ({ node }) => ["table", dataAttrs(node.attrs, "table", { "data-header-row": node.attrs.headerRow ? "true" : "false" }), ["tbody", 0]],
80
+ })
81
+
82
+ export const TableRow = Node.create({
83
+ name: "tableRow",
84
+ content: "tableCell*",
85
+ parseHTML: () => [{ tag: "tr" }],
86
+ renderHTML: () => ["tr", 0],
87
+ })
88
+
89
+ export const TableCell = Node.create({
90
+ name: "tableCell",
91
+ content: "inline*",
92
+ isolating: true,
93
+ parseHTML: () => [{ tag: "td" }, { tag: "th" }],
94
+ renderHTML: () => ["td", 0],
95
+ })
96
+
97
+ function atom(name: string, attrs: Record<string, unknown>) {
98
+ return Node.create({
99
+ name,
100
+ group: "block",
101
+ atom: true,
102
+ selectable: true,
103
+ draggable: false,
104
+ addAttributes: () => ({ ...blockAttributes, ...attrs }),
105
+ parseHTML: () => [{ tag: `div[data-type=${name}]` }],
106
+ renderHTML: ({ node }) => ["div", dataAttrs(node.attrs, name)],
107
+ })
108
+ }
109
+
110
+ export const PageBreak = atom("pageBreak", {})
111
+ /** Image: half, wide or full width, alt text, an optional caption (E.13). */
112
+ export const Image = atom("image", { src: { default: "" }, alt: { default: "" }, width: { default: "full" }, caption: json(null) })
113
+ export const FileBlock = atom("file", { fileId: { default: "" }, name: { default: "" }, size: { default: 0 }, mime: { default: "" } })
114
+ /** E.16: live in the editor; each PDF freezes the values. */
115
+ export const RecordBlock = atom("record", { ref: json(null), view: { default: "card" } })
116
+ export const ChartBlock = atom("chart", { chart: { default: "bar" }, source: json(null), title: { default: null } })
117
+ /** Stage 6: signers, a date, an optional stamp. */
118
+ export const SignatureBlock = atom("signature", { signers: json([]), date: json([]), stamp: { default: true } })
119
+ /** E.40 */
120
+ export const BarcodeBlock = atom("barcode", {
121
+ symbology: { default: "code128" },
122
+ value: json([]),
123
+ showText: { default: true },
124
+ widthMm: { default: null },
125
+ heightMm: { default: null },
126
+ })
127
+ /** E.41 */
128
+ export const QrBlock = atom("qr", { value: json([]), caption: json(null), sizeMm: { default: null } })
129
+ /** E.42 */
130
+ export const MathBlock = atom("math", { tex: { default: "" } })
131
+ /** E.21: a synced saved block, drawn from the library; copies are ordinary blocks. */
132
+ export const SavedBlockNode = atom("savedBlock", { savedBlockId: { default: "" }, version: { default: 1 }, overrides: json({}) })
133
+ /** E.17: a plugin's block; its data is the plugin's own, drawn from the plugin's declaration. */
134
+ export const PluginBlockNode = atom("plugin", { plugin: { default: "" }, blockType: { default: "" }, schemaVersion: { default: 1 }, data: json({}) })
135
+
136
+ export const richSchemaExtensions = [
137
+ Callout,
138
+ Toggle,
139
+ ToggleSummary,
140
+ Columns,
141
+ Column,
142
+ Table,
143
+ TableRow,
144
+ TableCell,
145
+ PageBreak,
146
+ Image,
147
+ FileBlock,
148
+ RecordBlock,
149
+ ChartBlock,
150
+ SignatureBlock,
151
+ BarcodeBlock,
152
+ QrBlock,
153
+ MathBlock,
154
+ SavedBlockNode,
155
+ PluginBlockNode,
156
+ ]