@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.
- package/README.md +106 -2
- package/package.json +219 -4
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +338 -0
- package/src/actor-chip.tsx +71 -0
- package/src/agent-activity.tsx +163 -0
- package/src/agent-collaboration.stories.tsx +156 -0
- package/src/agent-run-status.tsx +196 -0
- package/src/alert-dialog.stories.tsx +45 -0
- package/src/alert-dialog.tsx +147 -0
- package/src/alert.stories.tsx +91 -0
- package/src/alert.tsx +89 -0
- package/src/app-sidebar.stories.tsx +195 -0
- package/src/app-sidebar.tsx +604 -0
- package/src/approval-queue.tsx +109 -0
- package/src/audience-group-picker.stories.tsx +198 -0
- package/src/audience-group-picker.tsx +362 -0
- package/src/audience-people-picker.stories.tsx +102 -0
- package/src/audience-people-picker.tsx +279 -0
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -0
- package/src/badge.stories.tsx +105 -0
- package/src/badge.tsx +68 -0
- package/src/beta-warning.stories.tsx +79 -0
- package/src/beta-warning.tsx +189 -0
- package/src/bilingual-input.stories.tsx +82 -0
- package/src/bilingual-input.tsx +188 -0
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +123 -0
- package/src/card.stories.tsx +423 -0
- package/src/card.tsx +180 -0
- package/src/chart.stories.tsx +66 -0
- package/src/chart.tsx +228 -0
- package/src/checkbox.stories.tsx +62 -0
- package/src/checkbox.tsx +54 -0
- package/src/collapsible.stories.tsx +48 -0
- package/src/collapsible.tsx +34 -0
- package/src/color-card.stories.tsx +61 -0
- package/src/color-card.tsx +270 -0
- package/src/color-picker.stories.tsx +65 -0
- package/src/color-picker.tsx +425 -0
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -0
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -0
- package/src/copy-block.tsx +85 -0
- package/src/data-table.stories.tsx +200 -0
- package/src/data-table.tsx +1686 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +456 -0
- package/src/design-cards.stories.tsx +551 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +179 -0
- package/src/display-preferences.tsx +50 -0
- package/src/documents/barcode-svg.stories.tsx +72 -0
- package/src/documents/barcode-svg.tsx +79 -0
- package/src/dropdown-menu.stories.tsx +77 -0
- package/src/dropdown-menu.tsx +271 -0
- 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 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +104 -0
- package/src/editor/block-toolbar.tsx +490 -0
- package/src/editor/bubble.tsx +119 -0
- package/src/editor/catalogue.ts +169 -0
- package/src/editor/collab-rail.tsx +746 -0
- package/src/editor/collab.stories.tsx +207 -0
- package/src/editor/collab.ts +87 -0
- package/src/editor/contract.ts +476 -0
- package/src/editor/convert.ts +414 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1492 -0
- package/src/editor/editor.css +636 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +443 -0
- package/src/editor/index.ts +23 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +394 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +461 -0
- package/src/editor/page-view.tsx +372 -0
- 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 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- 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 -0
- package/src/editor/schema.ts +368 -0
- package/src/editor/services.tsx +205 -0
- package/src/editor/slash.ts +64 -0
- package/src/editor/suggesting.ts +372 -0
- package/src/editor/suggestions.ts +763 -0
- package/src/editor/table-keys.ts +66 -0
- package/src/editor/templates.stories.tsx +324 -0
- package/src/editor/toolbar.tsx +364 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +126 -0
- package/src/empty-state.usage-notes.md +30 -0
- package/src/form.stories.tsx +112 -0
- package/src/form.tsx +176 -0
- package/src/globals.css +20 -0
- package/src/icon-button.tsx +85 -0
- package/src/icon-map.ts +335 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +90 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +768 -0
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +75 -0
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -0
- package/src/math-text.stories.tsx +33 -0
- package/src/math-text.tsx +43 -0
- package/src/menu-bar.stories.tsx +198 -0
- package/src/menu-bar.tsx +373 -0
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -0
- 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 -0
- package/src/page-header.tsx +122 -0
- package/src/page-shell.stories.tsx +42 -0
- package/src/page-shell.tsx +32 -0
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- 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 -0
- package/src/plugin-card.tsx +931 -0
- package/src/popover.stories.tsx +48 -0
- package/src/popover.tsx +55 -0
- package/src/radio-group.stories.tsx +26 -0
- package/src/radio-group.tsx +44 -0
- package/src/route-flow/editor.tsx +1087 -0
- package/src/route-flow/model.ts +771 -0
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -0
- package/src/screen-too-small.stories.tsx +61 -0
- package/src/screen-too-small.tsx +104 -0
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -0
- package/src/select.tsx +197 -0
- package/src/separator.stories.tsx +34 -0
- package/src/separator.tsx +34 -0
- package/src/sheet.stories.tsx +49 -0
- package/src/sheet.tsx +168 -0
- package/src/skeleton.stories.tsx +28 -0
- package/src/skeleton.tsx +19 -0
- package/src/slider.stories.tsx +78 -0
- package/src/slider.tsx +300 -0
- package/src/spinner.stories.tsx +33 -0
- package/src/spinner.tsx +55 -0
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -0
- package/src/switch.tsx +41 -0
- package/src/switcher.stories.tsx +111 -0
- package/src/switcher.tsx +131 -0
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -0
- package/src/table.tsx +121 -0
- package/src/tabs.stories.tsx +74 -0
- package/src/tabs.tsx +90 -0
- package/src/tag-input.stories.tsx +67 -0
- package/src/tag-input.tsx +117 -0
- package/src/tenant-logo.tsx +63 -0
- package/src/tenant-switcher.stories.tsx +38 -0
- package/src/tenant-switcher.tsx +164 -0
- package/src/textarea.stories.tsx +27 -0
- package/src/textarea.tsx +18 -0
- package/src/theme-mode.ts +52 -0
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -0
- package/src/time-picker.tsx +615 -0
- package/src/toggle-group.tsx +138 -0
- package/src/tooltip.stories.tsx +43 -0
- package/src/tooltip.tsx +73 -0
- package/src/top-nav.stories.tsx +58 -0
- package/src/top-nav.tsx +324 -0
- package/src/undo-bar.tsx +107 -0
- package/src/utils.ts +45 -0
- package/src/view-toggle.stories.tsx +84 -0
- 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
|
+
]
|