@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,443 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import type { Editor, JSONContent } from "@tiptap/core"
|
|
5
|
+
import { NodeSelection } from "@tiptap/pm/state"
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuContent,
|
|
10
|
+
DropdownMenuItem,
|
|
11
|
+
DropdownMenuSeparator,
|
|
12
|
+
DropdownMenuShortcut,
|
|
13
|
+
DropdownMenuSub,
|
|
14
|
+
DropdownMenuSubContent,
|
|
15
|
+
DropdownMenuSubTrigger,
|
|
16
|
+
DropdownMenuTrigger,
|
|
17
|
+
} from "../dropdown-menu"
|
|
18
|
+
import { Icon } from "../icon"
|
|
19
|
+
import { cn } from "../utils"
|
|
20
|
+
import { deleteBlock, duplicateBlock, moveBlockTo, turnInto } from "./behaviour"
|
|
21
|
+
import { BlockList } from "./block-list"
|
|
22
|
+
import { CATALOGUE, applyItem, filterCatalogue, type CatalogueItem } from "./catalogue"
|
|
23
|
+
import type { SavedBlock } from "./contract"
|
|
24
|
+
import { fromEditorContent } from "./convert"
|
|
25
|
+
import { EDITOR_LABELS, type EditorLabels } from "./labels"
|
|
26
|
+
import { SaveBlockDialog, type SaveBlockChoice } from "./save-block-dialog"
|
|
27
|
+
import type { NewSavedBlock } from "./services"
|
|
28
|
+
|
|
29
|
+
/** Top padding of a block before its first line, so the gutter sits on that line. */
|
|
30
|
+
function firstLineOffset(el: HTMLElement): number {
|
|
31
|
+
return parseFloat(getComputedStyle(el).paddingTop) || 0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface Hovered {
|
|
35
|
+
pos: number
|
|
36
|
+
index: number
|
|
37
|
+
top: number
|
|
38
|
+
height: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The block gutter (E.8, EditorBlockChrome): hovering a block, or putting the
|
|
43
|
+
* caret in it, shows + and the drag handle in the margin at its first line.
|
|
44
|
+
* + opens the inserter for a new block below; the handle drags the block or,
|
|
45
|
+
* clicked, opens its menu. Agents never use it: they only suggest (E.4).
|
|
46
|
+
*/
|
|
47
|
+
function BlockGutter({
|
|
48
|
+
editor,
|
|
49
|
+
labels,
|
|
50
|
+
container,
|
|
51
|
+
menuAt,
|
|
52
|
+
onMenuAtChange,
|
|
53
|
+
blockUrl,
|
|
54
|
+
savedItems = [],
|
|
55
|
+
saveBlock,
|
|
56
|
+
canShareSavedBlocks = false,
|
|
57
|
+
}: {
|
|
58
|
+
editor: Editor
|
|
59
|
+
labels: EditorLabels
|
|
60
|
+
/** The positioned element around the editable content. */
|
|
61
|
+
container: React.RefObject<HTMLDivElement | null>
|
|
62
|
+
/** A block position whose menu should open (Esc then Enter). */
|
|
63
|
+
menuAt: number | null
|
|
64
|
+
onMenuAtChange: (pos: number | null) => void
|
|
65
|
+
/** The address "Copy link to block" copies. */
|
|
66
|
+
blockUrl: (blockId: string) => string
|
|
67
|
+
/** The Saved blocks group for the + inserter (E.21). */
|
|
68
|
+
savedItems?: CatalogueItem[]
|
|
69
|
+
/** Save as block; without it the block menu doesn't offer it. */
|
|
70
|
+
saveBlock?: (block: NewSavedBlock) => Promise<SavedBlock>
|
|
71
|
+
canShareSavedBlocks?: boolean
|
|
72
|
+
}) {
|
|
73
|
+
const [hovered, setHovered] = React.useState<Hovered | null>(null)
|
|
74
|
+
// Save as block: the first and last top-level block ids, found again by id when saving.
|
|
75
|
+
const [saving, setSaving] = React.useState<{ first: string; last: string; count: number } | null>(null)
|
|
76
|
+
const [inserter, setInserter] = React.useState<{ pos: number; query: string; active: number } | null>(null)
|
|
77
|
+
const [drag, setDrag] = React.useState<{ from: number; x: number; y: number; dropIndex: number; dropTop: number; text: string } | null>(null)
|
|
78
|
+
const pointerDown = React.useRef<{ x: number; y: number; pos: number } | null>(null)
|
|
79
|
+
|
|
80
|
+
const measure = React.useCallback(
|
|
81
|
+
(index: number): Hovered | null => {
|
|
82
|
+
const wrap = container.current
|
|
83
|
+
const el = editor.view.dom.children[index] as HTMLElement | undefined
|
|
84
|
+
if (!wrap || !el) return null
|
|
85
|
+
let pos = 0
|
|
86
|
+
for (let i = 0; i < index; i++) pos += editor.state.doc.child(i).nodeSize
|
|
87
|
+
const box = wrap.getBoundingClientRect()
|
|
88
|
+
const r = el.getBoundingClientRect()
|
|
89
|
+
return { pos, index, top: r.top - box.top + firstLineOffset(el), height: r.height }
|
|
90
|
+
},
|
|
91
|
+
[editor, container]
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
// Hovering a block shows its gutter.
|
|
95
|
+
React.useEffect(() => {
|
|
96
|
+
const wrap = container.current
|
|
97
|
+
if (!wrap) return
|
|
98
|
+
const onMove = (e: PointerEvent) => {
|
|
99
|
+
if (drag) return
|
|
100
|
+
const children = Array.from(editor.view.dom.children) as HTMLElement[]
|
|
101
|
+
const index = children.findIndex((el) => {
|
|
102
|
+
const r = el.getBoundingClientRect()
|
|
103
|
+
return e.clientY >= r.top - 2 && e.clientY <= r.bottom + 2
|
|
104
|
+
})
|
|
105
|
+
if (index >= 0) setHovered(measure(index))
|
|
106
|
+
}
|
|
107
|
+
wrap.addEventListener("pointermove", onMove)
|
|
108
|
+
return () => wrap.removeEventListener("pointermove", onMove)
|
|
109
|
+
}, [editor, container, measure, drag])
|
|
110
|
+
|
|
111
|
+
// So does putting the caret in it.
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
const onSelection = () => {
|
|
114
|
+
if (!editor.isFocused) return
|
|
115
|
+
const { $from } = editor.state.selection
|
|
116
|
+
setHovered(measure($from.depth === 0 ? $from.index(0) : $from.index(0)))
|
|
117
|
+
}
|
|
118
|
+
editor.on("selectionUpdate", onSelection)
|
|
119
|
+
editor.on("update", onSelection)
|
|
120
|
+
return () => {
|
|
121
|
+
editor.off("selectionUpdate", onSelection)
|
|
122
|
+
editor.off("update", onSelection)
|
|
123
|
+
}
|
|
124
|
+
}, [editor, measure])
|
|
125
|
+
|
|
126
|
+
// Esc then Enter on a block opens its menu.
|
|
127
|
+
React.useEffect(() => {
|
|
128
|
+
if (menuAt === null) return
|
|
129
|
+
const index = editor.state.doc.resolve(menuAt).index(0)
|
|
130
|
+
setHovered(measure(index))
|
|
131
|
+
}, [menuAt, editor, measure])
|
|
132
|
+
|
|
133
|
+
if (!editor.isEditable) return null
|
|
134
|
+
|
|
135
|
+
const dropIndexAt = (clientY: number) => {
|
|
136
|
+
const wrap = container.current!
|
|
137
|
+
const box = wrap.getBoundingClientRect()
|
|
138
|
+
const children = Array.from(editor.view.dom.children) as HTMLElement[]
|
|
139
|
+
let index = children.length
|
|
140
|
+
let top = children.length ? children[children.length - 1].getBoundingClientRect().bottom - box.top : 0
|
|
141
|
+
for (let i = 0; i < children.length; i++) {
|
|
142
|
+
const r = children[i].getBoundingClientRect()
|
|
143
|
+
if (clientY < r.top + r.height / 2) {
|
|
144
|
+
index = i
|
|
145
|
+
top = r.top - box.top
|
|
146
|
+
break
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { index, top }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const startPointer = (e: React.PointerEvent) => {
|
|
153
|
+
if (!hovered || e.button !== 0) return
|
|
154
|
+
pointerDown.current = { x: e.clientX, y: e.clientY, pos: hovered.pos }
|
|
155
|
+
;(e.target as HTMLElement).setPointerCapture(e.pointerId)
|
|
156
|
+
}
|
|
157
|
+
const movePointer = (e: React.PointerEvent) => {
|
|
158
|
+
const down = pointerDown.current
|
|
159
|
+
if (!down) return
|
|
160
|
+
if (!drag && Math.hypot(e.clientX - down.x, e.clientY - down.y) < 4) return
|
|
161
|
+
const node = editor.state.doc.nodeAt(down.pos)
|
|
162
|
+
const box = container.current!.getBoundingClientRect()
|
|
163
|
+
const { index, top } = dropIndexAt(e.clientY)
|
|
164
|
+
const el = editor.view.nodeDOM(down.pos) as HTMLElement | null
|
|
165
|
+
el?.classList.add("is-dragging")
|
|
166
|
+
setDrag({ from: down.pos, x: e.clientX - box.left, y: e.clientY - box.top, dropIndex: index, dropTop: top, text: node?.textContent.slice(0, 80) ?? "" })
|
|
167
|
+
}
|
|
168
|
+
const endPointer = () => {
|
|
169
|
+
const down = pointerDown.current
|
|
170
|
+
pointerDown.current = null
|
|
171
|
+
if (!down) return
|
|
172
|
+
if (!drag) {
|
|
173
|
+
onMenuAtChange(down.pos)
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
;(editor.view.nodeDOM(down.pos) as HTMLElement | null)?.classList.remove("is-dragging")
|
|
177
|
+
const fromIndex = editor.state.doc.resolve(down.pos).index(0)
|
|
178
|
+
// Dropping below its own place: the block isn't counted once it's lifted out.
|
|
179
|
+
const target = drag.dropIndex > fromIndex ? drag.dropIndex - 1 : drag.dropIndex
|
|
180
|
+
setDrag(null)
|
|
181
|
+
if (target !== fromIndex) moveBlockTo(editor, down.pos, target)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const blockAt = (pos: number) => editor.state.doc.nodeAt(pos)
|
|
185
|
+
const select = (pos: number) => editor.chain().focus().command(({ tr }) => {
|
|
186
|
+
tr.setSelection(NodeSelection.create(tr.doc, pos))
|
|
187
|
+
return true
|
|
188
|
+
}).run()
|
|
189
|
+
const inside = (pos: number) => editor.chain().focus().setTextSelection(pos + 1).run()
|
|
190
|
+
|
|
191
|
+
const menuOpen = menuAt !== null
|
|
192
|
+
const menuBlock = menuOpen ? blockAt(menuAt) : null
|
|
193
|
+
const inserterItems: CatalogueItem[] = inserter ? filterCatalogue(inserter.query, labels, EDITOR_LABELS, savedItems) : []
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The top-level blocks Save as block takes: those the selection spans when
|
|
197
|
+
* it covers this block and others (E.21: select several, then save), else
|
|
198
|
+
* this block alone.
|
|
199
|
+
*/
|
|
200
|
+
const blocksToSave = (pos: number) => {
|
|
201
|
+
const { doc, selection } = editor.state
|
|
202
|
+
const at = doc.resolve(pos).index(0)
|
|
203
|
+
const from = doc.resolve(selection.from).index(0)
|
|
204
|
+
const to = doc.resolve(Math.max(selection.from, selection.to - 1)).index(0)
|
|
205
|
+
const [a, b] = to > from && at >= from && at <= to ? [from, to] : [at, at]
|
|
206
|
+
return { first: String(doc.child(a).attrs.id ?? ""), last: String(doc.child(b).attrs.id ?? ""), count: b - a + 1 }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Where the blocks being saved are now, by their ids: the document may have changed meanwhile. */
|
|
210
|
+
const savingRange = () => {
|
|
211
|
+
if (!saving) return null
|
|
212
|
+
let from = -1
|
|
213
|
+
let to = -1
|
|
214
|
+
editor.state.doc.forEach((node, offset) => {
|
|
215
|
+
if (node.attrs.id === saving.first) from = offset
|
|
216
|
+
if (node.attrs.id === saving.last) to = offset + node.nodeSize
|
|
217
|
+
})
|
|
218
|
+
return from >= 0 && to > from ? { from, to } : null
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const saveSelection = async (choice: SaveBlockChoice) => {
|
|
222
|
+
const range = savingRange()
|
|
223
|
+
if (!range || !saveBlock) throw new Error("The blocks have changed")
|
|
224
|
+
const nodes: JSONContent[] = []
|
|
225
|
+
editor.state.doc.nodesBetween(range.from, range.to, (node, pos) => {
|
|
226
|
+
if (pos >= range.from && pos < range.to) nodes.push(node.toJSON() as JSONContent)
|
|
227
|
+
return false
|
|
228
|
+
})
|
|
229
|
+
const saved = await saveBlock({ ...choice, blocks: fromEditorContent({ type: "doc", content: nodes }), perDocumentParts: [] })
|
|
230
|
+
if (choice.mode !== "synced") return
|
|
231
|
+
// Synced: the blocks become the saved block, drawn from the library from now on.
|
|
232
|
+
const now = savingRange()
|
|
233
|
+
if (!now) return
|
|
234
|
+
editor
|
|
235
|
+
.chain()
|
|
236
|
+
.focus()
|
|
237
|
+
.insertContentAt(now, { type: "savedBlock", attrs: { savedBlockId: saved.id, version: saved.version, overrides: {} } })
|
|
238
|
+
.run()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<>
|
|
243
|
+
{hovered && !drag && (
|
|
244
|
+
<div
|
|
245
|
+
data-slot="block-gutter"
|
|
246
|
+
className="absolute end-full z-10 flex pe-1.5"
|
|
247
|
+
style={{ top: hovered.top }}
|
|
248
|
+
onPointerDown={(e) => e.stopPropagation()}
|
|
249
|
+
>
|
|
250
|
+
<button
|
|
251
|
+
type="button"
|
|
252
|
+
aria-label={labels.addBelow}
|
|
253
|
+
className={cn(
|
|
254
|
+
"grid size-6 place-items-center rounded-[6px] text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring",
|
|
255
|
+
inserter && "bg-muted text-foreground"
|
|
256
|
+
)}
|
|
257
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
258
|
+
onClick={() => setInserter({ pos: hovered.pos, query: "", active: 0 })}
|
|
259
|
+
>
|
|
260
|
+
<Icon name="plus" />
|
|
261
|
+
</button>
|
|
262
|
+
<DropdownMenu
|
|
263
|
+
modal={false}
|
|
264
|
+
open={menuOpen && menuAt === hovered.pos}
|
|
265
|
+
onOpenChange={(open) => onMenuAtChange(open ? hovered.pos : null)}
|
|
266
|
+
>
|
|
267
|
+
<DropdownMenuTrigger asChild>
|
|
268
|
+
<button
|
|
269
|
+
type="button"
|
|
270
|
+
aria-label={labels.dragHandle}
|
|
271
|
+
className="grid h-6 w-[18px] cursor-grab touch-none place-items-center rounded-[6px] text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
|
|
272
|
+
onPointerDown={(e) => {
|
|
273
|
+
e.preventDefault()
|
|
274
|
+
startPointer(e)
|
|
275
|
+
}}
|
|
276
|
+
onPointerMove={movePointer}
|
|
277
|
+
onPointerUp={endPointer}
|
|
278
|
+
onKeyDown={(e) => {
|
|
279
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
280
|
+
e.preventDefault()
|
|
281
|
+
onMenuAtChange(hovered.pos)
|
|
282
|
+
}
|
|
283
|
+
}}
|
|
284
|
+
>
|
|
285
|
+
<Icon name="drag" />
|
|
286
|
+
</button>
|
|
287
|
+
</DropdownMenuTrigger>
|
|
288
|
+
{menuBlock && menuAt !== null && (
|
|
289
|
+
<DropdownMenuContent
|
|
290
|
+
align="start"
|
|
291
|
+
aria-label={labels.blockMenu}
|
|
292
|
+
onCloseAutoFocus={(e) => {
|
|
293
|
+
e.preventDefault()
|
|
294
|
+
editor.commands.focus()
|
|
295
|
+
}}
|
|
296
|
+
>
|
|
297
|
+
{menuBlock.isTextblock && (
|
|
298
|
+
<DropdownMenuSub>
|
|
299
|
+
<DropdownMenuSubTrigger>
|
|
300
|
+
<Icon name="sync" /> {labels.turnInto}
|
|
301
|
+
</DropdownMenuSubTrigger>
|
|
302
|
+
<DropdownMenuSubContent>
|
|
303
|
+
{CATALOGUE.filter((i) => i.textBlock).map((item) => (
|
|
304
|
+
<DropdownMenuItem
|
|
305
|
+
key={item.id}
|
|
306
|
+
onSelect={() => {
|
|
307
|
+
inside(menuAt)
|
|
308
|
+
turnInto(editor, item.node.type, item.node.attrs)
|
|
309
|
+
}}
|
|
310
|
+
>
|
|
311
|
+
<Icon name={item.icon} /> {labels[item.label]}
|
|
312
|
+
</DropdownMenuItem>
|
|
313
|
+
))}
|
|
314
|
+
</DropdownMenuSubContent>
|
|
315
|
+
</DropdownMenuSub>
|
|
316
|
+
)}
|
|
317
|
+
<DropdownMenuItem onSelect={() => duplicateBlock(editor, menuAt)}>
|
|
318
|
+
<Icon name="copy" /> {labels.duplicate}
|
|
319
|
+
<DropdownMenuShortcut>⌘D</DropdownMenuShortcut>
|
|
320
|
+
</DropdownMenuItem>
|
|
321
|
+
<DropdownMenuItem
|
|
322
|
+
onSelect={() => {
|
|
323
|
+
const id = menuBlock.attrs.id as string | null
|
|
324
|
+
if (id) void navigator.clipboard?.writeText(blockUrl(id))
|
|
325
|
+
}}
|
|
326
|
+
>
|
|
327
|
+
<Icon name="link" /> {labels.copyLinkToBlock}
|
|
328
|
+
</DropdownMenuItem>
|
|
329
|
+
{saveBlock && menuBlock.type.name !== "savedBlock" && (
|
|
330
|
+
<DropdownMenuItem onSelect={() => setSaving(blocksToSave(menuAt))}>
|
|
331
|
+
<Icon name="template" /> {labels.saveAsBlock}
|
|
332
|
+
</DropdownMenuItem>
|
|
333
|
+
)}
|
|
334
|
+
<DropdownMenuSeparator />
|
|
335
|
+
<DropdownMenuItem
|
|
336
|
+
disabled={editor.state.doc.resolve(menuAt).index(0) === 0}
|
|
337
|
+
onSelect={() => moveBlockTo(editor, menuAt, editor.state.doc.resolve(menuAt).index(0) - 1)}
|
|
338
|
+
>
|
|
339
|
+
<Icon name="arrow-up" /> {labels.moveUp}
|
|
340
|
+
<DropdownMenuShortcut>⌥⇧↑</DropdownMenuShortcut>
|
|
341
|
+
</DropdownMenuItem>
|
|
342
|
+
<DropdownMenuItem
|
|
343
|
+
disabled={editor.state.doc.resolve(menuAt).index(0) >= editor.state.doc.childCount - 1}
|
|
344
|
+
onSelect={() => moveBlockTo(editor, menuAt, editor.state.doc.resolve(menuAt).index(0) + 1)}
|
|
345
|
+
>
|
|
346
|
+
<Icon name="arrow-down" /> {labels.moveDown}
|
|
347
|
+
<DropdownMenuShortcut>⌥⇧↓</DropdownMenuShortcut>
|
|
348
|
+
</DropdownMenuItem>
|
|
349
|
+
<DropdownMenuSeparator />
|
|
350
|
+
<DropdownMenuItem variant="destructive" onSelect={() => deleteBlock(editor, menuAt)}>
|
|
351
|
+
<Icon name="delete" /> {labels.delete}
|
|
352
|
+
<DropdownMenuShortcut>Del</DropdownMenuShortcut>
|
|
353
|
+
</DropdownMenuItem>
|
|
354
|
+
</DropdownMenuContent>
|
|
355
|
+
)}
|
|
356
|
+
</DropdownMenu>
|
|
357
|
+
</div>
|
|
358
|
+
)}
|
|
359
|
+
|
|
360
|
+
{inserter && hovered && (
|
|
361
|
+
<div className="absolute start-0 z-30" style={{ top: hovered.top + 28 }}>
|
|
362
|
+
<BlockList
|
|
363
|
+
id="wy-inserter"
|
|
364
|
+
items={inserterItems}
|
|
365
|
+
active={Math.min(inserter.active, Math.max(0, inserterItems.length - 1))}
|
|
366
|
+
onActive={(active) => setInserter({ ...inserter, active })}
|
|
367
|
+
onPick={(item) => {
|
|
368
|
+
const node = blockAt(inserter.pos)
|
|
369
|
+
setInserter(null)
|
|
370
|
+
if (node) applyItem(editor, item, { after: inserter.pos + node.nodeSize })
|
|
371
|
+
}}
|
|
372
|
+
labels={labels}
|
|
373
|
+
footer={
|
|
374
|
+
<>
|
|
375
|
+
<span>{labels.slashMove}</span>
|
|
376
|
+
<span>{labels.slashInsert}</span>
|
|
377
|
+
<span>{labels.slashClose}</span>
|
|
378
|
+
</>
|
|
379
|
+
}
|
|
380
|
+
search={
|
|
381
|
+
<div className="-mx-1 -mt-1 mb-1 flex h-9 items-center gap-2 border-b border-border px-2.5 text-muted-foreground">
|
|
382
|
+
<Icon name="search" size={14} />
|
|
383
|
+
<input
|
|
384
|
+
autoFocus
|
|
385
|
+
aria-label={labels.searchBlocks}
|
|
386
|
+
aria-controls="wy-inserter"
|
|
387
|
+
placeholder={labels.searchBlocks}
|
|
388
|
+
value={inserter.query}
|
|
389
|
+
onChange={(e) => setInserter({ ...inserter, query: e.target.value, active: 0 })}
|
|
390
|
+
onBlur={() => setInserter(null)}
|
|
391
|
+
onKeyDown={(e) => {
|
|
392
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
393
|
+
e.preventDefault()
|
|
394
|
+
const n = inserterItems.length || 1
|
|
395
|
+
setInserter({ ...inserter, active: (inserter.active + (e.key === "ArrowDown" ? 1 : n - 1)) % n })
|
|
396
|
+
} else if (e.key === "Enter") {
|
|
397
|
+
e.preventDefault()
|
|
398
|
+
const item = inserterItems[inserter.active]
|
|
399
|
+
const node = blockAt(inserter.pos)
|
|
400
|
+
setInserter(null)
|
|
401
|
+
if (item && node) applyItem(editor, item, { after: inserter.pos + node.nodeSize })
|
|
402
|
+
} else if (e.key === "Escape") {
|
|
403
|
+
e.preventDefault()
|
|
404
|
+
setInserter(null)
|
|
405
|
+
select(inserter.pos)
|
|
406
|
+
}
|
|
407
|
+
}}
|
|
408
|
+
className="h-full min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground"
|
|
409
|
+
/>
|
|
410
|
+
</div>
|
|
411
|
+
}
|
|
412
|
+
/>
|
|
413
|
+
</div>
|
|
414
|
+
)}
|
|
415
|
+
|
|
416
|
+
{saveBlock && (
|
|
417
|
+
<SaveBlockDialog
|
|
418
|
+
open={saving !== null}
|
|
419
|
+
onOpenChange={(open) => !open && setSaving(null)}
|
|
420
|
+
blockCount={saving?.count ?? 1}
|
|
421
|
+
canShare={canShareSavedBlocks}
|
|
422
|
+
onSave={saveSelection}
|
|
423
|
+
labels={labels}
|
|
424
|
+
/>
|
|
425
|
+
)}
|
|
426
|
+
|
|
427
|
+
{drag && (
|
|
428
|
+
<>
|
|
429
|
+
<div aria-hidden="true" className="pointer-events-none absolute inset-x-0 z-20 h-0.5 rounded-[1px] bg-primary" style={{ top: drag.dropTop - 1 }} />
|
|
430
|
+
<div
|
|
431
|
+
aria-hidden="true"
|
|
432
|
+
className="pointer-events-none absolute z-30 max-w-[420px] -rotate-1 truncate rounded-control border border-border bg-card px-2.5 py-1.5 text-base shadow-float"
|
|
433
|
+
style={{ top: drag.y + 8, left: drag.x + 12 }}
|
|
434
|
+
>
|
|
435
|
+
{drag.text || "…"}
|
|
436
|
+
</div>
|
|
437
|
+
</>
|
|
438
|
+
)}
|
|
439
|
+
</>
|
|
440
|
+
)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export { BlockGutter }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "./contract"
|
|
2
|
+
export { DocEditor, type DocEditorProps, type SaveState } from "./doc-editor"
|
|
3
|
+
export { EDITOR_LABELS, type EditorLabels } from "./labels"
|
|
4
|
+
export { fromEditorContent, normalizeBlocks, toEditorContent } from "./convert"
|
|
5
|
+
export { documentExtensions } from "./extensions"
|
|
6
|
+
export { EditorServicesProvider, type EditorServices, type RecordView, type ChartData, type UploadedFile } from "./services"
|
|
7
|
+
export { type FieldDef, type FieldGroup } from "./fields"
|
|
8
|
+
export { type Letterhead } from "./page-view"
|
|
9
|
+
export { type FieldPreview } from "./services"
|
|
10
|
+
export * from "./collab"
|
|
11
|
+
export * from "./agents"
|
|
12
|
+
export {
|
|
13
|
+
collectPatches,
|
|
14
|
+
renderSuggestions,
|
|
15
|
+
stripSuggestions,
|
|
16
|
+
suggestEdit,
|
|
17
|
+
summarize,
|
|
18
|
+
type FormatEdit,
|
|
19
|
+
type LocalChange,
|
|
20
|
+
type PatchedSuggestion,
|
|
21
|
+
type SuggestionKind,
|
|
22
|
+
type SuggestionPatch,
|
|
23
|
+
} from "./suggestions"
|