@blocknote/core 0.42.3 → 0.43.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 (200) hide show
  1. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +2 -0
  2. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +1 -0
  3. package/dist/BlockNoteExtension-C2X7LW-V.js +25 -0
  4. package/dist/BlockNoteExtension-C2X7LW-V.js.map +1 -0
  5. package/dist/BlockNoteSchema-CbSavEwr.js +270 -0
  6. package/dist/BlockNoteSchema-CbSavEwr.js.map +1 -0
  7. package/dist/BlockNoteSchema-D8TyvlfU.cjs +2 -0
  8. package/dist/BlockNoteSchema-D8TyvlfU.cjs.map +1 -0
  9. package/dist/EventEmitter-CLwfmbqG.cjs +2 -0
  10. package/dist/EventEmitter-CLwfmbqG.cjs.map +1 -0
  11. package/dist/EventEmitter-CjSwpTbz.js +27 -0
  12. package/dist/EventEmitter-CjSwpTbz.js.map +1 -0
  13. package/dist/ShowSelection-BW37oJ6h.cjs +2 -0
  14. package/dist/ShowSelection-BW37oJ6h.cjs.map +1 -0
  15. package/dist/ShowSelection-Dz-NEase.js +43 -0
  16. package/dist/ShowSelection-Dz-NEase.js.map +1 -0
  17. package/dist/TrailingNode-BUhuMJrB.js +2096 -0
  18. package/dist/TrailingNode-BUhuMJrB.js.map +1 -0
  19. package/dist/TrailingNode-CaT_wbho.cjs +2 -0
  20. package/dist/TrailingNode-CaT_wbho.cjs.map +1 -0
  21. package/dist/{blockToNode-DIfPWLH8.js → blockToNode-DBNbhwwC.js} +33 -33
  22. package/dist/blockToNode-DBNbhwwC.js.map +1 -0
  23. package/dist/blockToNode-w7H99R6p.cjs.map +1 -1
  24. package/dist/blocknote.cjs +4 -4
  25. package/dist/blocknote.cjs.map +1 -1
  26. package/dist/blocknote.js +2402 -5594
  27. package/dist/blocknote.js.map +1 -1
  28. package/dist/blocks.cjs +1 -1
  29. package/dist/blocks.js +71 -70
  30. package/dist/blocks.js.map +1 -1
  31. package/dist/comments.cjs +1 -1
  32. package/dist/comments.cjs.map +1 -1
  33. package/dist/comments.js +451 -137
  34. package/dist/comments.js.map +1 -1
  35. package/dist/{BlockNoteSchema-Bi-eeHal.js → defaultBlocks-BJtxTOM2.js} +991 -1047
  36. package/dist/defaultBlocks-BJtxTOM2.js.map +1 -0
  37. package/dist/defaultBlocks-BxFclIGP.cjs +6 -0
  38. package/dist/defaultBlocks-BxFclIGP.cjs.map +1 -0
  39. package/dist/extensions.cjs +2 -0
  40. package/dist/extensions.cjs.map +1 -0
  41. package/dist/extensions.js +57 -0
  42. package/dist/extensions.js.map +1 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.js +1 -1
  46. package/package.json +9 -3
  47. package/src/api/nodeConversions/blockToNode.ts +1 -1
  48. package/src/api/nodeConversions/nodeToBlock.ts +1 -1
  49. package/src/blocks/Code/block.ts +4 -4
  50. package/src/blocks/Divider/block.ts +2 -2
  51. package/src/blocks/File/helpers/render/createAddFileButton.ts +7 -5
  52. package/src/blocks/Heading/block.ts +23 -20
  53. package/src/blocks/ListItem/BulletListItem/block.ts +2 -2
  54. package/src/blocks/ListItem/CheckListItem/block.ts +2 -2
  55. package/src/blocks/ListItem/NumberedListItem/block.ts +3 -3
  56. package/src/blocks/ListItem/ToggleListItem/block.ts +2 -2
  57. package/src/blocks/PageBreak/getPageBreakSlashMenuItems.ts +2 -2
  58. package/src/blocks/Paragraph/block.ts +2 -2
  59. package/src/blocks/Quote/block.ts +2 -2
  60. package/src/blocks/Table/block.ts +4 -3
  61. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +2 -1
  62. package/src/comments/extension.ts +353 -0
  63. package/src/comments/index.ts +2 -1
  64. package/src/comments/types.ts +8 -0
  65. package/src/{extensions/Comments → comments}/userstore/UserStore.ts +2 -2
  66. package/src/editor/BlockNoteEditor.test.ts +2 -23
  67. package/src/editor/BlockNoteEditor.ts +60 -453
  68. package/src/editor/BlockNoteExtension.test.ts +103 -0
  69. package/src/editor/BlockNoteExtension.ts +174 -56
  70. package/src/editor/managers/EventManager.ts +64 -35
  71. package/src/editor/managers/ExtensionManager/extensions.ts +214 -0
  72. package/src/editor/managers/ExtensionManager/index.ts +514 -0
  73. package/src/editor/managers/ExtensionManager/symbol.ts +6 -0
  74. package/src/editor/managers/SelectionManager.ts +5 -1
  75. package/src/editor/managers/StateManager.ts +29 -17
  76. package/src/editor/managers/index.ts +1 -5
  77. package/src/extensions/BlockChange/{BlockChangePlugin.ts → BlockChange.ts} +27 -29
  78. package/src/extensions/Collaboration/{ForkYDocPlugin.test.ts → ForkYDoc.test.ts} +6 -5
  79. package/src/extensions/Collaboration/ForkYDoc.ts +158 -0
  80. package/src/extensions/Collaboration/YCursorPlugin.ts +183 -0
  81. package/src/extensions/Collaboration/YSync.ts +16 -0
  82. package/src/extensions/Collaboration/YUndo.ts +12 -0
  83. package/src/extensions/Collaboration/schemaMigration/SchemaMigration.ts +59 -0
  84. package/src/extensions/DropCursor/DropCursor.ts +26 -0
  85. package/src/extensions/FilePanel/FilePanel.ts +41 -0
  86. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +119 -0
  87. package/src/extensions/History/History.ts +11 -0
  88. package/src/extensions/LinkToolbar/LinkToolbar.ts +121 -0
  89. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +74 -0
  90. package/src/extensions/Placeholder/Placeholder.ts +148 -0
  91. package/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.ts → PreviousBlockType.ts} +9 -13
  92. package/src/extensions/ShowSelection/{ShowSelectionPlugin.ts → ShowSelection.ts} +27 -33
  93. package/src/extensions/SideMenu/{SideMenuPlugin.ts → SideMenu.ts} +63 -83
  94. package/src/extensions/SuggestionMenu/{SuggestionPlugin.ts → SuggestionMenu.ts} +71 -77
  95. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +29 -44
  96. package/src/extensions/TableHandles/{TableHandlesPlugin.ts → TableHandles.ts} +416 -437
  97. package/src/extensions/TrailingNode/{TrailingNodeExtension.ts → TrailingNode.ts} +8 -17
  98. package/src/extensions/index.ts +24 -0
  99. package/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.ts +1 -1
  100. package/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.ts +21 -16
  101. package/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.ts +1 -1
  102. package/src/extensions/tiptap-extensions/index.ts +31 -0
  103. package/src/index.ts +1 -13
  104. package/src/schema/blocks/createSpec.ts +14 -11
  105. package/src/schema/blocks/internal.ts +2 -2
  106. package/src/schema/blocks/types.ts +8 -5
  107. package/src/schema/schema.ts +11 -36
  108. package/src/util/topo-sort.ts +46 -0
  109. package/types/src/comments/extension.d.ts +70 -0
  110. package/types/src/comments/index.d.ts +2 -1
  111. package/types/src/comments/types.d.ts +8 -0
  112. package/types/src/{extensions/Comments → comments}/userstore/UserStore.d.ts +2 -2
  113. package/types/src/editor/BlockNoteEditor.d.ts +34 -105
  114. package/types/src/editor/BlockNoteExtension.d.ts +87 -22
  115. package/types/src/editor/managers/EventManager.d.ts +25 -16
  116. package/types/src/editor/managers/ExtensionManager/extensions.d.ts +8 -0
  117. package/types/src/editor/managers/ExtensionManager/index.d.ts +83 -0
  118. package/types/src/editor/managers/ExtensionManager/symbol.d.ts +5 -0
  119. package/types/src/editor/managers/StateManager.d.ts +1 -12
  120. package/types/src/editor/managers/index.d.ts +1 -2
  121. package/types/src/extensions/BlockChange/BlockChange.d.ts +16 -0
  122. package/types/src/extensions/Collaboration/ForkYDoc.d.ts +34 -0
  123. package/types/src/extensions/Collaboration/ForkYDoc.test.d.ts +1 -0
  124. package/types/src/extensions/Collaboration/YCursorPlugin.d.ts +24 -0
  125. package/types/src/extensions/Collaboration/YSync.d.ts +8 -0
  126. package/types/src/extensions/Collaboration/YUndo.d.ts +12 -0
  127. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigration.d.ts +8 -0
  128. package/types/src/extensions/DropCursor/DropCursor.d.ts +5 -0
  129. package/types/src/extensions/FilePanel/FilePanel.d.ts +11 -0
  130. package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +9 -0
  131. package/types/src/extensions/History/History.d.ts +6 -0
  132. package/types/src/extensions/LinkToolbar/LinkToolbar.d.ts +24 -0
  133. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +5 -0
  134. package/types/src/extensions/Placeholder/Placeholder.d.ts +6 -0
  135. package/types/src/extensions/PreviousBlockType/{PreviousBlockTypePlugin.d.ts → PreviousBlockType.d.ts} +9 -5
  136. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +21 -0
  137. package/types/src/extensions/SideMenu/{SideMenuPlugin.d.ts → SideMenu.d.ts} +11 -15
  138. package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +54 -0
  139. package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +1 -1
  140. package/types/src/extensions/TableHandles/{TableHandlesPlugin.d.ts → TableHandles.d.ts} +28 -31
  141. package/types/src/extensions/TrailingNode/TrailingNode.d.ts +8 -0
  142. package/types/src/extensions/index.d.ts +24 -0
  143. package/types/src/extensions/{KeyboardShortcuts → tiptap-extensions/KeyboardShortcuts}/KeyboardShortcutsExtension.d.ts +1 -1
  144. package/types/src/extensions/tiptap-extensions/index.d.ts +11 -0
  145. package/types/src/index.d.ts +1 -13
  146. package/types/src/schema/blocks/createSpec.d.ts +4 -4
  147. package/types/src/schema/blocks/internal.d.ts +2 -2
  148. package/types/src/schema/blocks/types.d.ts +5 -5
  149. package/types/src/util/topo-sort.d.ts +8 -0
  150. package/dist/BlockNoteSchema-Bi-eeHal.js.map +0 -1
  151. package/dist/BlockNoteSchema-DjDaA2C3.cjs +0 -6
  152. package/dist/BlockNoteSchema-DjDaA2C3.cjs.map +0 -1
  153. package/dist/blockToNode-DIfPWLH8.js.map +0 -1
  154. package/src/comments/models/User.ts +0 -8
  155. package/src/editor/BlockNoteExtensions.ts +0 -325
  156. package/src/editor/managers/CollaborationManager.ts +0 -212
  157. package/src/editor/managers/ExtensionManager.ts +0 -130
  158. package/src/extensions/Collaboration/CursorPlugin.ts +0 -189
  159. package/src/extensions/Collaboration/ForkYDocPlugin.ts +0 -192
  160. package/src/extensions/Collaboration/SyncPlugin.ts +0 -18
  161. package/src/extensions/Collaboration/UndoPlugin.ts +0 -18
  162. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +0 -59
  163. package/src/extensions/Comments/CommentsPlugin.ts +0 -392
  164. package/src/extensions/FilePanel/FilePanelPlugin.ts +0 -206
  165. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +0 -363
  166. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +0 -380
  167. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +0 -75
  168. package/src/extensions/Placeholder/PlaceholderPlugin.ts +0 -147
  169. package/types/src/comments/models/User.d.ts +0 -8
  170. package/types/src/editor/BlockNoteExtensions.d.ts +0 -43
  171. package/types/src/editor/managers/CollaborationManager.d.ts +0 -115
  172. package/types/src/editor/managers/ExtensionManager.d.ts +0 -68
  173. package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +0 -15
  174. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +0 -37
  175. package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +0 -41
  176. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +0 -7
  177. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +0 -9
  178. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +0 -7
  179. package/types/src/extensions/Comments/CommentsPlugin.d.ts +0 -66
  180. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +0 -31
  181. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +0 -41
  182. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +0 -42
  183. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +0 -5
  184. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +0 -6
  185. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +0 -15
  186. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +0 -31
  187. package/types/src/extensions/TrailingNode/TrailingNodeExtension.d.ts +0 -13
  188. /package/src/{extensions/Comments/CommentMark.ts → comments/mark.ts} +0 -0
  189. /package/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.ts +0 -0
  190. /package/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.ts +0 -0
  191. /package/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.ts +0 -0
  192. /package/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.ts +0 -0
  193. /package/types/src/{extensions/Comments/CommentMark.d.ts → comments/mark.d.ts} +0 -0
  194. /package/types/src/{extensions/Collaboration/ForkYDocPlugin.test.d.ts → editor/BlockNoteExtension.test.d.ts} +0 -0
  195. /package/types/src/extensions/{BackgroundColor → tiptap-extensions/BackgroundColor}/BackgroundColorExtension.d.ts +0 -0
  196. /package/types/src/extensions/{HardBreak → tiptap-extensions/HardBreak}/HardBreak.d.ts +0 -0
  197. /package/types/src/extensions/{Suggestions → tiptap-extensions/Suggestions}/SuggestionMarks.d.ts +0 -0
  198. /package/types/src/extensions/{TextAlignment → tiptap-extensions/TextAlignment}/TextAlignmentExtension.d.ts +0 -0
  199. /package/types/src/extensions/{TextColor → tiptap-extensions/TextColor}/TextColorExtension.d.ts +0 -0
  200. /package/types/src/extensions/{UniqueID → tiptap-extensions/UniqueID}/UniqueID.d.ts +0 -0
@@ -0,0 +1,2096 @@
1
+ var xe = Object.defineProperty;
2
+ var Ee = (n, e, o) => e in n ? xe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[e] = o;
3
+ var b = (n, e, o) => Ee(n, typeof e != "symbol" ? e + "" : e, o);
4
+ import { Plugin as B, PluginKey as T, NodeSelection as le, TextSelection as _, Selection as L } from "prosemirror-state";
5
+ import { combineTransactionSteps as Ie, getMarkRange as Be, posToDOMRect as Te, findChildren as j } from "@tiptap/core";
6
+ import Pe from "fast-deep-equal";
7
+ import { i as q, t as Oe, U as De, n as Ae, g as N, a as R, c as ce, m as Me, e as de, f as Le, h as Ne, j as Re, k as Ve, l as He, o as W, p as G } from "./blockToNode-DBNbhwwC.js";
8
+ import { ai as ue, a2 as J, aj as he, $ as Fe, a1 as Q } from "./defaultBlocks-BJtxTOM2.js";
9
+ import { c as k, a as H } from "./BlockNoteExtension-C2X7LW-V.js";
10
+ import { yCursorPlugin as Ue, defaultSelectionBuilder as $e, ySyncPlugin as _e, redoCommand as ze, undoCommand as Ye, yUndoPlugin as Ke, yUndoPluginKey as Z } from "y-prosemirror";
11
+ import * as I from "yjs";
12
+ import { dropCursor as Xe } from "prosemirror-dropcursor";
13
+ import { redo as je, undo as qe, history as We } from "prosemirror-history";
14
+ import { Decoration as A, DecorationSet as V } from "prosemirror-view";
15
+ import { v4 as Ge } from "uuid";
16
+ import { DOMSerializer as me, Fragment as pe, Slice as fe, DOMParser as Je } from "prosemirror-model";
17
+ import Qe from "rehype-parse";
18
+ import Ze from "rehype-remark";
19
+ import et from "remark-gfm";
20
+ import tt from "remark-stringify";
21
+ import { unified as ot } from "unified";
22
+ import { fromDom as nt } from "hast-util-from-dom";
23
+ import { visit as rt } from "unist-util-visit";
24
+ import { splitCell as st, mergeCells as it, deleteRow as at, deleteColumn as lt, addRowBefore as ct, addRowAfter as dt, addColumnBefore as ut, addColumnAfter as ht, CellSelection as mt } from "prosemirror-tables";
25
+ function ge(n) {
26
+ const e = Array.from(n.classList).filter(
27
+ (o) => !o.startsWith("bn-")
28
+ ) || [];
29
+ e.length > 0 ? n.className = e.join(" ") : n.removeAttribute("class");
30
+ }
31
+ function we(n, e, o, t) {
32
+ var a;
33
+ let r;
34
+ if (e)
35
+ if (typeof e == "string")
36
+ r = q([e], n.pmSchema);
37
+ else if (Array.isArray(e))
38
+ r = q(e, n.pmSchema);
39
+ else if (e.type === "tableContent")
40
+ r = Oe(e, n.pmSchema);
41
+ else
42
+ throw new De(e.type);
43
+ else throw new Error("blockContent is required");
44
+ const i = ((t == null ? void 0 : t.document) ?? document).createDocumentFragment();
45
+ for (const c of r)
46
+ if (c.type.name !== "text" && n.schema.inlineContentSchema[c.type.name]) {
47
+ const l = n.schema.inlineContentSpecs[c.type.name].implementation;
48
+ if (l) {
49
+ const m = Ae(
50
+ c,
51
+ n.schema.inlineContentSchema,
52
+ n.schema.styleSchema
53
+ ), h = l.toExternalHTML ? l.toExternalHTML(
54
+ m,
55
+ n
56
+ ) : l.render.call(
57
+ {
58
+ renderType: "dom",
59
+ props: void 0
60
+ },
61
+ m,
62
+ () => {
63
+ },
64
+ n
65
+ );
66
+ if (h) {
67
+ if (i.appendChild(h.dom), h.contentDOM) {
68
+ const f = o.serializeFragment(
69
+ c.content,
70
+ t
71
+ );
72
+ h.contentDOM.dataset.editable = "", h.contentDOM.appendChild(f);
73
+ }
74
+ continue;
75
+ }
76
+ }
77
+ } else if (c.type.name === "text") {
78
+ let l = document.createTextNode(
79
+ c.textContent
80
+ );
81
+ for (const m of c.marks.toReversed())
82
+ if (m.type.name in n.schema.styleSpecs) {
83
+ const h = (n.schema.styleSpecs[m.type.name].implementation.toExternalHTML ?? n.schema.styleSpecs[m.type.name].implementation.render)(m.attrs.stringValue, n);
84
+ h.contentDOM.appendChild(l), l = h.dom;
85
+ } else {
86
+ const h = m.type.spec.toDOM(m, !0), f = me.renderSpec(document, h);
87
+ f.contentDOM.appendChild(l), l = f.dom;
88
+ }
89
+ i.appendChild(l);
90
+ } else {
91
+ const l = o.serializeFragment(
92
+ pe.from([c]),
93
+ t
94
+ );
95
+ i.appendChild(l);
96
+ }
97
+ return i.childNodes.length === 1 && ((a = i.firstChild) == null ? void 0 : a.nodeType) === 1 && ge(i.firstChild), i;
98
+ }
99
+ function pt(n, e, o, t, r, s, i) {
100
+ var p, w, y, E, O, z, Y, K, X;
101
+ const a = (i == null ? void 0 : i.document) ?? document, c = e.pmSchema.nodes.blockContainer, l = o.props || {};
102
+ for (const [v, S] of Object.entries(
103
+ e.schema.blockSchema[o.type].propSchema
104
+ ))
105
+ !(v in l) && S.default !== void 0 && (l[v] = S.default);
106
+ const m = (w = (p = c.spec) == null ? void 0 : p.toDOM) == null ? void 0 : w.call(
107
+ p,
108
+ c.create({
109
+ id: o.id,
110
+ ...l
111
+ })
112
+ ), h = Array.from(m.dom.attributes), f = e.blockImplementations[o.type].implementation, u = ((y = f.toExternalHTML) == null ? void 0 : y.call(
113
+ {},
114
+ { ...o, props: l },
115
+ e
116
+ )) || f.render.call(
117
+ {},
118
+ { ...o, props: l },
119
+ e
120
+ ), g = a.createDocumentFragment();
121
+ if (u.dom.classList.contains("bn-block-content")) {
122
+ const v = [
123
+ ...h,
124
+ ...Array.from(u.dom.attributes)
125
+ ].filter(
126
+ (S) => S.name.startsWith("data") && S.name !== "data-content-type" && S.name !== "data-file-block" && S.name !== "data-node-view-wrapper" && S.name !== "data-node-type" && S.name !== "data-id" && S.name !== "data-editable"
127
+ );
128
+ for (const S of v)
129
+ u.dom.firstChild.setAttribute(S.name, S.value);
130
+ ge(u.dom.firstChild), g.append(...Array.from(u.dom.childNodes));
131
+ } else
132
+ g.append(u.dom);
133
+ if (u.contentDOM && o.content) {
134
+ const v = we(
135
+ e,
136
+ o.content,
137
+ // TODO
138
+ t,
139
+ i
140
+ );
141
+ u.contentDOM.appendChild(v);
142
+ }
143
+ let d;
144
+ if (r.has(o.type) ? d = "OL" : s.has(o.type) && (d = "UL"), d) {
145
+ if (((E = n.lastChild) == null ? void 0 : E.nodeName) !== d) {
146
+ const v = a.createElement(d);
147
+ d === "OL" && "start" in l && l.start && (l == null ? void 0 : l.start) !== 1 && v.setAttribute("start", l.start + ""), n.append(v);
148
+ }
149
+ n.lastChild.appendChild(g);
150
+ } else
151
+ n.append(g);
152
+ if (o.children && o.children.length > 0) {
153
+ const v = a.createDocumentFragment();
154
+ if (ye(
155
+ v,
156
+ e,
157
+ o.children,
158
+ t,
159
+ r,
160
+ s,
161
+ i
162
+ ), ((O = n.lastChild) == null ? void 0 : O.nodeName) === "UL" || ((z = n.lastChild) == null ? void 0 : z.nodeName) === "OL")
163
+ for (; ((Y = v.firstChild) == null ? void 0 : Y.nodeName) === "UL" || ((K = v.firstChild) == null ? void 0 : K.nodeName) === "OL"; )
164
+ n.lastChild.lastChild.appendChild(v.firstChild);
165
+ e.pmSchema.nodes[o.type].isInGroup("blockContent") ? n.append(v) : (X = u.contentDOM) == null || X.append(v);
166
+ }
167
+ }
168
+ const ye = (n, e, o, t, r, s, i) => {
169
+ for (const a of o)
170
+ pt(
171
+ n,
172
+ e,
173
+ a,
174
+ t,
175
+ r,
176
+ s,
177
+ i
178
+ );
179
+ }, ft = (n, e, o, t, r, s) => {
180
+ const a = ((s == null ? void 0 : s.document) ?? document).createDocumentFragment();
181
+ return ye(
182
+ a,
183
+ n,
184
+ e,
185
+ o,
186
+ t,
187
+ r,
188
+ s
189
+ ), a;
190
+ }, be = (n, e) => {
191
+ const o = me.fromSchema(n);
192
+ return {
193
+ exportBlocks: (t, r) => {
194
+ const s = ft(
195
+ e,
196
+ t,
197
+ o,
198
+ /* @__PURE__ */ new Set(["numberedListItem"]),
199
+ /* @__PURE__ */ new Set(["bulletListItem", "checkListItem", "toggleListItem"]),
200
+ r
201
+ ), i = document.createElement("div");
202
+ return i.append(s), i.innerHTML;
203
+ },
204
+ exportInlineContent: (t, r) => {
205
+ const s = we(
206
+ e,
207
+ t,
208
+ o,
209
+ r
210
+ ), i = document.createElement("div");
211
+ return i.append(s.cloneNode(!0)), i.innerHTML;
212
+ }
213
+ };
214
+ };
215
+ function gt(n, e) {
216
+ if (e === 0)
217
+ return;
218
+ const o = n.resolve(e);
219
+ for (let t = o.depth; t > 0; t--) {
220
+ const r = o.node(t);
221
+ if (ue(r))
222
+ return r.attrs.id;
223
+ }
224
+ }
225
+ function wt(n) {
226
+ return n.getMeta("paste") ? { type: "paste" } : n.getMeta("uiEvent") === "drop" ? { type: "drop" } : n.getMeta("history$") ? {
227
+ type: n.getMeta("history$").redo ? "redo" : "undo"
228
+ } : n.getMeta("y-sync$") ? n.getMeta("y-sync$").isUndoRedoOperation ? { type: "undo-redo" } : { type: "yjs-remote" } : { type: "local" };
229
+ }
230
+ function ee(n) {
231
+ const e = "__root__", o = {}, t = {}, r = N(n);
232
+ return n.descendants((s, i) => {
233
+ if (!ue(s))
234
+ return !0;
235
+ const a = gt(n, i), c = a ?? e;
236
+ t[c] || (t[c] = []);
237
+ const l = R(s, r);
238
+ return o[s.attrs.id] = { block: l, parentId: a }, t[c].push(s.attrs.id), !0;
239
+ }), { byId: o, childrenByParent: t };
240
+ }
241
+ function yt(n, e) {
242
+ const o = /* @__PURE__ */ new Set();
243
+ if (!n || !e)
244
+ return o;
245
+ const t = new Set(n), r = e.filter((d) => t.has(d)), s = n.filter(
246
+ (d) => r.includes(d)
247
+ );
248
+ if (s.length <= 1 || r.length <= 1)
249
+ return o;
250
+ const i = {};
251
+ for (let d = 0; d < s.length; d++)
252
+ i[s[d]] = d;
253
+ const a = r.map((d) => i[d]), c = a.length, l = [], m = [], h = new Array(c).fill(-1), f = (d, p) => {
254
+ let w = 0, y = d.length;
255
+ for (; w < y; ) {
256
+ const E = w + y >>> 1;
257
+ d[E] < p ? w = E + 1 : y = E;
258
+ }
259
+ return w;
260
+ };
261
+ for (let d = 0; d < c; d++) {
262
+ const p = a[d], w = f(l, p);
263
+ w > 0 && (h[d] = m[w - 1]), w === l.length ? (l.push(p), m.push(d)) : (l[w] = p, m[w] = d);
264
+ }
265
+ const u = /* @__PURE__ */ new Set();
266
+ let g = m[m.length - 1] ?? -1;
267
+ for (; g !== -1; )
268
+ u.add(g), g = h[g];
269
+ for (let d = 0; d < r.length; d++)
270
+ u.has(d) || o.add(r[d]);
271
+ return o;
272
+ }
273
+ function bt(n, e = []) {
274
+ const o = wt(n), t = Ie(n.before, [
275
+ n,
276
+ ...e
277
+ ]), r = ee(
278
+ t.before
279
+ ), s = ee(
280
+ t.doc
281
+ ), i = [], a = /* @__PURE__ */ new Set();
282
+ Object.keys(s.byId).filter((u) => !(u in r.byId)).forEach((u) => {
283
+ i.push({
284
+ type: "insert",
285
+ block: s.byId[u].block,
286
+ source: o,
287
+ prevBlock: void 0
288
+ }), a.add(u);
289
+ }), Object.keys(r.byId).filter((u) => !(u in s.byId)).forEach((u) => {
290
+ i.push({
291
+ type: "delete",
292
+ block: r.byId[u].block,
293
+ source: o,
294
+ prevBlock: void 0
295
+ }), a.add(u);
296
+ }), Object.keys(s.byId).filter((u) => u in r.byId).forEach((u) => {
297
+ var w, y;
298
+ const g = r.byId[u], d = s.byId[u];
299
+ g.parentId !== d.parentId ? (i.push({
300
+ type: "move",
301
+ block: d.block,
302
+ prevBlock: g.block,
303
+ source: o,
304
+ prevParent: g.parentId ? (w = r.byId[g.parentId]) == null ? void 0 : w.block : void 0,
305
+ currentParent: d.parentId ? (y = s.byId[d.parentId]) == null ? void 0 : y.block : void 0
306
+ }), a.add(u)) : Pe(
307
+ { ...g.block, children: void 0 },
308
+ { ...d.block, children: void 0 }
309
+ ) || (i.push({
310
+ type: "update",
311
+ block: d.block,
312
+ prevBlock: g.block,
313
+ source: o
314
+ }), a.add(u));
315
+ });
316
+ const c = r.childrenByParent, l = s.childrenByParent, m = "__root__", h = /* @__PURE__ */ new Set([
317
+ ...Object.keys(c),
318
+ ...Object.keys(l)
319
+ ]), f = /* @__PURE__ */ new Set();
320
+ return h.forEach((u) => {
321
+ const g = yt(
322
+ c[u],
323
+ l[u]
324
+ );
325
+ g.size !== 0 && g.forEach((d) => {
326
+ var E, O;
327
+ const p = r.byId[d], w = s.byId[d];
328
+ !p || !w || p.parentId !== w.parentId || a.has(d) || (p.parentId ?? m) !== u || f.has(d) || (f.add(d), i.push({
329
+ type: "move",
330
+ block: w.block,
331
+ prevBlock: p.block,
332
+ source: o,
333
+ prevParent: p.parentId ? (E = r.byId[p.parentId]) == null ? void 0 : E.block : void 0,
334
+ currentParent: w.parentId ? (O = s.byId[w.parentId]) == null ? void 0 : O.block : void 0
335
+ }), a.add(d));
336
+ });
337
+ }), i;
338
+ }
339
+ function vt() {
340
+ const n = (e) => {
341
+ let o = e.children.length;
342
+ for (let t = 0; t < o; t++) {
343
+ const r = e.children[t];
344
+ if (r.type === "element" && (n(r), r.tagName === "u"))
345
+ if (r.children.length > 0) {
346
+ e.children.splice(t, 1, ...r.children);
347
+ const s = r.children.length - 1;
348
+ o += s, t += s;
349
+ } else
350
+ e.children.splice(t, 1), o--, t--;
351
+ }
352
+ };
353
+ return n;
354
+ }
355
+ function kt() {
356
+ const n = (e) => {
357
+ var o;
358
+ if (e.children && "length" in e.children && e.children.length)
359
+ for (let t = e.children.length - 1; t >= 0; t--) {
360
+ const r = e.children[t], s = t + 1 < e.children.length ? e.children[t + 1] : void 0;
361
+ r.type === "element" && r.tagName === "input" && ((o = r.properties) == null ? void 0 : o.type) === "checkbox" && (s == null ? void 0 : s.type) === "element" && s.tagName === "p" ? (s.tagName = "span", s.children.splice(
362
+ 0,
363
+ 0,
364
+ nt(document.createTextNode(" "))
365
+ )) : n(r);
366
+ }
367
+ };
368
+ return n;
369
+ }
370
+ function Ct() {
371
+ return (n) => {
372
+ rt(n, "element", (e, o, t) => {
373
+ var r, s, i, a;
374
+ if (t && e.tagName === "video") {
375
+ const c = ((r = e.properties) == null ? void 0 : r.src) || ((s = e.properties) == null ? void 0 : s["data-url"]) || "", l = ((i = e.properties) == null ? void 0 : i.title) || ((a = e.properties) == null ? void 0 : a["data-name"]) || "";
376
+ t.children[o] = {
377
+ type: "text",
378
+ value: `![${l}](${c})`
379
+ };
380
+ }
381
+ });
382
+ };
383
+ }
384
+ function ve(n) {
385
+ return ot().use(Qe, { fragment: !0 }).use(Ct).use(vt).use(kt).use(Ze).use(et).use(tt, {
386
+ handlers: { text: (o) => o.value }
387
+ }).processSync(n).value;
388
+ }
389
+ function ao(n, e, o, t) {
390
+ const s = be(e, o).exportBlocks(n, t);
391
+ return ve(s);
392
+ }
393
+ function St(n) {
394
+ const e = [];
395
+ return n.descendants((o) => {
396
+ var r, s;
397
+ const t = N(o);
398
+ return o.type.name === "blockContainer" && ((r = o.firstChild) == null ? void 0 : r.type.name) === "blockGroup" ? !0 : o.type.name === "columnList" && o.childCount === 1 ? ((s = o.firstChild) == null || s.forEach((i) => {
399
+ e.push(R(i, t));
400
+ }), !1) : o.type.isInGroup("bnBlock") ? (e.push(R(o, t)), !1) : !0;
401
+ }), e;
402
+ }
403
+ const lo = k(() => {
404
+ const n = [];
405
+ return {
406
+ key: "blockChange",
407
+ prosemirrorPlugins: [
408
+ new B({
409
+ key: new T("blockChange"),
410
+ filterTransaction: (e) => {
411
+ let o;
412
+ return n.reduce((t, r) => t === !1 ? t : r({
413
+ getChanges() {
414
+ return o || (o = bt(e), o);
415
+ },
416
+ tr: e
417
+ }) !== !1, !0);
418
+ }
419
+ })
420
+ ],
421
+ /**
422
+ * Subscribe to the block change events.
423
+ */
424
+ subscribe(e) {
425
+ return n.push(e), () => {
426
+ n.splice(
427
+ n.indexOf(e),
428
+ 1
429
+ );
430
+ };
431
+ }
432
+ };
433
+ });
434
+ function te(n) {
435
+ const e = n.charAt(0) === "#" ? n.substring(1, 7) : n, o = parseInt(e.substring(0, 2), 16), t = parseInt(e.substring(2, 4), 16), r = parseInt(e.substring(4, 6), 16), i = [o / 255, t / 255, r / 255].map((c) => c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
436
+ return 0.2126 * i[0] + 0.7152 * i[1] + 0.0722 * i[2] <= 0.179;
437
+ }
438
+ function xt(n) {
439
+ const e = document.createElement("span");
440
+ e.classList.add("bn-collaboration-cursor__base");
441
+ const o = document.createElement("span");
442
+ o.setAttribute("contentedEditable", "false"), o.classList.add("bn-collaboration-cursor__caret"), o.setAttribute(
443
+ "style",
444
+ `background-color: ${n.color}; color: ${te(n.color) ? "white" : "black"}`
445
+ );
446
+ const t = document.createElement("span");
447
+ return t.classList.add("bn-collaboration-cursor__label"), t.setAttribute(
448
+ "style",
449
+ `background-color: ${n.color}; color: ${te(n.color) ? "white" : "black"}`
450
+ ), t.insertBefore(document.createTextNode(n.name), null), o.insertBefore(t, null), e.insertBefore(document.createTextNode("⁠"), null), e.insertBefore(o, null), e.insertBefore(document.createTextNode("⁠"), null), e;
451
+ }
452
+ const oe = k(
453
+ ({
454
+ options: n
455
+ }) => {
456
+ const e = /* @__PURE__ */ new Map();
457
+ return n.provider && "awareness" in n.provider && typeof n.provider.awareness == "object" && ("setLocalStateField" in n.provider.awareness && typeof n.provider.awareness.setLocalStateField == "function" && n.provider.awareness.setLocalStateField("user", n.user), "on" in n.provider.awareness && typeof n.provider.awareness.on == "function" && n.showCursorLabels !== "always" && n.provider.awareness.on(
458
+ "change",
459
+ ({
460
+ updated: o
461
+ }) => {
462
+ for (const t of o) {
463
+ const r = e.get(t);
464
+ r && (r.element.setAttribute("data-active", ""), r.hideTimeout && clearTimeout(r.hideTimeout), e.set(t, {
465
+ element: r.element,
466
+ hideTimeout: setTimeout(() => {
467
+ r.element.removeAttribute("data-active");
468
+ }, 2e3)
469
+ }));
470
+ }
471
+ }
472
+ )), {
473
+ key: "yCursor",
474
+ prosemirrorPlugins: [
475
+ Ue(n.provider.awareness, {
476
+ selectionBuilder: $e,
477
+ cursorBuilder(o, t) {
478
+ let r = e.get(t);
479
+ if (!r) {
480
+ const s = (n.renderCursor ?? xt)(o);
481
+ n.showCursorLabels !== "always" && (s.addEventListener("mouseenter", () => {
482
+ const i = e.get(t);
483
+ i.element.setAttribute("data-active", ""), i.hideTimeout && (clearTimeout(i.hideTimeout), e.set(t, {
484
+ element: i.element,
485
+ hideTimeout: void 0
486
+ }));
487
+ }), s.addEventListener("mouseleave", () => {
488
+ const i = e.get(t);
489
+ e.set(t, {
490
+ element: i.element,
491
+ hideTimeout: setTimeout(() => {
492
+ i.element.removeAttribute("data-active");
493
+ }, 2e3)
494
+ });
495
+ })), r = {
496
+ element: s,
497
+ hideTimeout: void 0
498
+ }, e.set(t, r);
499
+ }
500
+ return r.element;
501
+ }
502
+ })
503
+ ],
504
+ dependsOn: ["ySync"],
505
+ updateUser(o) {
506
+ n.provider.awareness.setLocalStateField("user", o);
507
+ }
508
+ };
509
+ }
510
+ ), F = k(
511
+ ({ options: n }) => ({
512
+ key: "ySync",
513
+ prosemirrorPlugins: [_e(n.fragment)],
514
+ runsBefore: ["default"]
515
+ })
516
+ ), U = k(({ editor: n }) => ({
517
+ key: "yUndo",
518
+ prosemirrorPlugins: [Ke({ trackedOrigins: [n] })],
519
+ dependsOn: ["yCursor", "ySync"],
520
+ undoCommand: Ye,
521
+ redoCommand: ze
522
+ }));
523
+ function Et(n, e) {
524
+ const o = n.doc;
525
+ if (n._item === null) {
526
+ const t = Array.from(o.share.keys()).find(
527
+ (r) => o.share.get(r) === n
528
+ );
529
+ if (t == null)
530
+ throw new Error("type does not exist in other ydoc");
531
+ return e.get(t, n.constructor);
532
+ } else {
533
+ const t = n._item, r = e.store.clients.get(t.id.client) ?? [], s = I.findIndexSS(r, t.id.clock);
534
+ return r[s].content.type;
535
+ }
536
+ }
537
+ const co = k(
538
+ ({
539
+ editor: n,
540
+ options: e
541
+ }) => {
542
+ let o;
543
+ const t = H({ isForked: !1 });
544
+ return {
545
+ key: "yForkDoc",
546
+ store: t,
547
+ /**
548
+ * Fork the Y.js document from syncing to the remote,
549
+ * allowing modifications to the document without affecting the remote.
550
+ * These changes can later be rolled back or applied to the remote.
551
+ */
552
+ fork() {
553
+ if (o)
554
+ return;
555
+ const r = e.fragment;
556
+ if (!r)
557
+ throw new Error("No fragment to fork from");
558
+ const s = new I.Doc();
559
+ I.applyUpdate(s, I.encodeStateAsUpdate(r.doc));
560
+ const i = Et(r, s);
561
+ o = {
562
+ undoStack: Z.getState(n.prosemirrorState).undoManager.undoStack,
563
+ originalFragment: r,
564
+ forkedFragment: i
565
+ }, n.unregisterExtension([
566
+ U,
567
+ oe,
568
+ F
569
+ ]);
570
+ const a = {
571
+ ...e,
572
+ fragment: i
573
+ };
574
+ n.registerExtension([
575
+ F(a),
576
+ // No need to register the cursor plugin again, it's a local fork
577
+ U({})
578
+ ]), t.setState({ isForked: !0 });
579
+ },
580
+ /**
581
+ * Resume syncing the Y.js document to the remote
582
+ * If `keepChanges` is true, any changes that have been made to the forked document will be applied to the original document.
583
+ * Otherwise, the original document will be restored and the changes will be discarded.
584
+ */
585
+ merge({ keepChanges: r }) {
586
+ if (!o)
587
+ return;
588
+ n.unregisterExtension(["ySync", "yCursor", "yUndo"]);
589
+ const { originalFragment: s, forkedFragment: i, undoStack: a } = o;
590
+ if (n.registerExtension([
591
+ F(e),
592
+ oe(e),
593
+ U({})
594
+ ]), Z.getState(
595
+ n.prosemirrorState
596
+ ).undoManager.undoStack = a, r) {
597
+ const c = I.encodeStateAsUpdate(
598
+ i.doc,
599
+ I.encodeStateVector(s.doc)
600
+ );
601
+ I.applyUpdate(s.doc, c, n);
602
+ }
603
+ o = void 0, t.setState({ isForked: !1 });
604
+ }
605
+ };
606
+ }
607
+ ), ke = (n, e) => {
608
+ e(n), n.forEach((o) => {
609
+ o instanceof I.XmlElement && ke(o, e);
610
+ });
611
+ }, It = (n, e) => {
612
+ const o = /* @__PURE__ */ new Map();
613
+ return n.forEach((t) => {
614
+ t instanceof I.XmlElement && ke(t, (r) => {
615
+ if (r.nodeName === "blockContainer" && r.hasAttribute("id")) {
616
+ const s = r.getAttribute("textColor"), i = r.getAttribute("backgroundColor"), a = {
617
+ textColor: s === J.textColor.default ? void 0 : s,
618
+ backgroundColor: i === J.backgroundColor.default ? void 0 : i
619
+ };
620
+ (a.textColor || a.backgroundColor) && o.set(r.getAttribute("id"), a);
621
+ }
622
+ });
623
+ }), o.size === 0 ? !1 : (e.doc.descendants((t, r) => {
624
+ if (t.type.name === "blockContainer" && o.has(t.attrs.id)) {
625
+ const s = e.doc.nodeAt(r + 1);
626
+ if (!s)
627
+ throw new Error("No element found");
628
+ e.setNodeMarkup(r + 1, void 0, {
629
+ // preserve existing attributes
630
+ ...s.attrs,
631
+ // add the textColor and backgroundColor attributes
632
+ ...o.get(t.attrs.id)
633
+ });
634
+ }
635
+ }), !0);
636
+ }, Bt = [It], uo = k(
637
+ ({ options: n }) => {
638
+ let e = !1;
639
+ const o = new T("schemaMigration");
640
+ return {
641
+ key: "schemaMigration",
642
+ prosemirrorPlugins: [
643
+ new B({
644
+ key: o,
645
+ appendTransaction: (t, r, s) => {
646
+ if (e || // If any of the transactions are not due to a yjs sync, we don't need to run the migration
647
+ !t.some((a) => a.getMeta("y-sync$")) || // If none of the transactions result in a document change, we don't need to run the migration
648
+ t.every((a) => !a.docChanged) || // If the fragment is still empty, we can't run the migration (since it has not yet been applied to the Y.Doc)
649
+ !n.fragment.firstChild)
650
+ return;
651
+ const i = s.tr;
652
+ for (const a of Bt)
653
+ a(n.fragment, i);
654
+ if (e = !0, !!i.docChanged)
655
+ return i;
656
+ }
657
+ })
658
+ ]
659
+ };
660
+ }
661
+ ), ho = k(
662
+ ({
663
+ editor: n,
664
+ options: e
665
+ }) => ({
666
+ key: "dropCursor",
667
+ prosemirrorPlugins: [
668
+ (e.dropCursor ?? Xe)({
669
+ width: 5,
670
+ color: "#ddeeff",
671
+ editor: n
672
+ })
673
+ ]
674
+ })
675
+ ), mo = k(({ editor: n }) => {
676
+ const e = H(!1), o = () => n.transact((t) => {
677
+ var s;
678
+ if (t.selection.empty || t.selection instanceof le && (t.selection.node.type.spec.content === "inline*" || ((s = t.selection.node.firstChild) == null ? void 0 : s.type.spec.content) === "inline*") || t.selection instanceof _ && t.doc.textBetween(t.selection.from, t.selection.to).length === 0)
679
+ return !1;
680
+ let r = !1;
681
+ return t.selection.content().content.descendants((i) => (i.type.spec.code && (r = !0), !r)), !r;
682
+ });
683
+ return {
684
+ key: "formattingToolbar",
685
+ store: e,
686
+ mount({ dom: t, signal: r }) {
687
+ let s = !1;
688
+ const i = n.onChange(() => {
689
+ s || e.setState(o());
690
+ }), a = n.onSelectionChange(() => {
691
+ s || e.setState(o());
692
+ });
693
+ t.addEventListener(
694
+ "pointerdown",
695
+ () => {
696
+ s = !0, e.setState(!1);
697
+ },
698
+ { signal: r }
699
+ ), n.prosemirrorView.root.addEventListener(
700
+ "pointerup",
701
+ () => {
702
+ s = !1, n.isFocused() && e.setState(o());
703
+ },
704
+ { signal: r, capture: !0 }
705
+ ), t.addEventListener(
706
+ "pointercancel",
707
+ () => {
708
+ s = !1;
709
+ },
710
+ {
711
+ signal: r,
712
+ capture: !0
713
+ }
714
+ ), r.addEventListener("abort", () => {
715
+ i(), a();
716
+ });
717
+ }
718
+ };
719
+ }), po = k(() => ({
720
+ key: "history",
721
+ prosemirrorPlugins: [We()],
722
+ undoCommand: qe,
723
+ redoCommand: je
724
+ })), fo = k(({ editor: n }) => {
725
+ function e(r) {
726
+ let s = n.prosemirrorView.nodeDOM(r);
727
+ for (; s && s.parentElement; ) {
728
+ if (s.nodeName === "A")
729
+ return s;
730
+ s = s.parentElement;
731
+ }
732
+ return null;
733
+ }
734
+ function o(r, s) {
735
+ return n.transact((i) => {
736
+ const a = i.doc.resolve(r), c = a.marks().find((m) => m.type.name === s);
737
+ if (!c)
738
+ return;
739
+ const l = Be(a, c.type);
740
+ if (l)
741
+ return {
742
+ range: l,
743
+ mark: c,
744
+ get text() {
745
+ return i.doc.textBetween(l.from, l.to);
746
+ },
747
+ get position() {
748
+ return Te(
749
+ n.prosemirrorView,
750
+ l.from,
751
+ l.to
752
+ ).toJSON();
753
+ }
754
+ };
755
+ });
756
+ }
757
+ function t() {
758
+ return n.transact((r) => {
759
+ const s = r.selection;
760
+ if (s.empty)
761
+ return o(s.anchor, "link");
762
+ });
763
+ }
764
+ return {
765
+ key: "linkToolbar",
766
+ getLinkAtSelection: t,
767
+ getLinkElementAtPos: e,
768
+ getMarkAtPos: o,
769
+ getLinkAtElement(r) {
770
+ return n.transact(() => {
771
+ const s = n.prosemirrorView.posAtDOM(r, 0) + 1;
772
+ return o(s, "link");
773
+ });
774
+ },
775
+ editLink(r, s, i = n.transact((a) => a.selection.anchor)) {
776
+ n.transact((a) => {
777
+ const c = N(a), { range: l } = o(i + 1, "link") || {
778
+ range: {
779
+ from: a.selection.from,
780
+ to: a.selection.to
781
+ }
782
+ };
783
+ l && (a.insertText(s, l.from, l.to), a.addMark(
784
+ l.from,
785
+ l.from + s.length,
786
+ c.mark("link", { href: r })
787
+ ));
788
+ }), n.prosemirrorView.focus();
789
+ },
790
+ deleteLink(r = n.transact((s) => s.selection.anchor)) {
791
+ n.transact((s) => {
792
+ const i = N(s), { range: a } = o(r + 1, "link") || {
793
+ range: {
794
+ from: s.selection.from,
795
+ to: s.selection.to
796
+ }
797
+ };
798
+ a && s.removeMark(a.from, a.to, i.marks.link).setMeta(
799
+ "preventAutolink",
800
+ !0
801
+ );
802
+ }), n.prosemirrorView.focus();
803
+ }
804
+ };
805
+ }), go = [
806
+ "http",
807
+ "https",
808
+ "ftp",
809
+ "ftps",
810
+ "mailto",
811
+ "tel",
812
+ "callto",
813
+ "sms",
814
+ "cid",
815
+ "xmpp"
816
+ ], wo = "https", Tt = new T("node-selection-keyboard"), yo = k(
817
+ () => ({
818
+ key: "nodeSelectionKeyboard",
819
+ prosemirrorPlugins: [
820
+ new B({
821
+ key: Tt,
822
+ props: {
823
+ handleKeyDown: (n, e) => {
824
+ if ("node" in n.state.selection) {
825
+ if (e.ctrlKey || e.metaKey)
826
+ return !1;
827
+ if (e.key.length === 1)
828
+ return e.preventDefault(), !0;
829
+ if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) {
830
+ const o = n.state.tr;
831
+ return n.dispatch(
832
+ o.insert(
833
+ n.state.tr.selection.$to.after(),
834
+ n.state.schema.nodes.paragraph.createChecked()
835
+ ).setSelection(
836
+ new _(
837
+ o.doc.resolve(
838
+ n.state.tr.selection.$to.after() + 1
839
+ )
840
+ )
841
+ )
842
+ ), !0;
843
+ }
844
+ }
845
+ return !1;
846
+ }
847
+ }
848
+ })
849
+ ]
850
+ })
851
+ ), Pt = new T("blocknote-placeholder"), bo = k(
852
+ ({
853
+ editor: n,
854
+ options: e
855
+ }) => {
856
+ const o = e.placeholders;
857
+ return {
858
+ key: "placeholder",
859
+ prosemirrorPlugins: [
860
+ new B({
861
+ key: Pt,
862
+ view: (t) => {
863
+ const r = `placeholder-selector-${Ge()}`;
864
+ t.dom.classList.add(r);
865
+ const s = document.createElement("style"), i = n._tiptapEditor.options.injectNonce;
866
+ i && s.setAttribute("nonce", i), t.root instanceof window.ShadowRoot ? t.root.append(s) : t.root.head.appendChild(s);
867
+ const a = s.sheet, c = (l = "") => `.${r} .bn-block-content${l} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;
868
+ try {
869
+ const {
870
+ default: l,
871
+ emptyDocument: m,
872
+ ...h
873
+ } = o || {};
874
+ for (const [g, d] of Object.entries(h)) {
875
+ const p = `[data-content-type="${g}"]`;
876
+ a.insertRule(
877
+ `${c(p)} { content: ${JSON.stringify(
878
+ d
879
+ )}; }`
880
+ );
881
+ }
882
+ const f = "[data-is-only-empty-block]", u = "[data-is-empty-and-focused]";
883
+ a.insertRule(
884
+ `${c(f)} { content: ${JSON.stringify(
885
+ m
886
+ )}; }`
887
+ ), a.insertRule(
888
+ `${c(u)} { content: ${JSON.stringify(
889
+ l
890
+ )}; }`
891
+ );
892
+ } catch (l) {
893
+ console.warn(
894
+ "Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)",
895
+ l
896
+ );
897
+ }
898
+ return {
899
+ destroy: () => {
900
+ t.root instanceof window.ShadowRoot ? t.root.removeChild(s) : t.root.head.removeChild(s);
901
+ }
902
+ };
903
+ },
904
+ props: {
905
+ decorations: (t) => {
906
+ const { doc: r, selection: s } = t;
907
+ if (!n.isEditable || !s.empty || s.$from.parent.type.spec.code)
908
+ return;
909
+ const i = [];
910
+ t.doc.content.size === 6 && i.push(
911
+ A.node(2, 4, {
912
+ "data-is-only-empty-block": "true"
913
+ })
914
+ );
915
+ const a = s.$anchor, c = a.parent;
916
+ if (c.content.size === 0) {
917
+ const l = a.before();
918
+ i.push(
919
+ A.node(l, l + c.nodeSize, {
920
+ "data-is-empty-and-focused": "true"
921
+ })
922
+ );
923
+ }
924
+ return V.create(r, i);
925
+ }
926
+ }
927
+ })
928
+ ]
929
+ };
930
+ }
931
+ ), ne = new T("previous-blocks"), Ot = {
932
+ // Numbered List Items
933
+ index: "index",
934
+ // Headings
935
+ level: "level",
936
+ // All Blocks
937
+ type: "type",
938
+ depth: "depth",
939
+ "depth-change": "depth-change"
940
+ }, vo = k(() => {
941
+ let n;
942
+ return {
943
+ key: "previousBlockType",
944
+ prosemirrorPlugins: [
945
+ new B({
946
+ key: ne,
947
+ view(e) {
948
+ return {
949
+ update: async (o, t) => {
950
+ var r;
951
+ ((r = this.key) == null ? void 0 : r.getState(o.state).updatedBlocks.size) > 0 && (n = setTimeout(() => {
952
+ o.dispatch(
953
+ o.state.tr.setMeta(ne, { clearUpdate: !0 })
954
+ );
955
+ }, 0));
956
+ },
957
+ destroy: () => {
958
+ n && clearTimeout(n);
959
+ }
960
+ };
961
+ },
962
+ state: {
963
+ init() {
964
+ return {
965
+ // Block attributes, by block ID, from just before the previous transaction.
966
+ prevTransactionOldBlockAttrs: {},
967
+ // Block attributes, by block ID, from just before the current transaction.
968
+ currentTransactionOldBlockAttrs: {},
969
+ // Set of IDs of blocks whose attributes changed from the current transaction.
970
+ updatedBlocks: /* @__PURE__ */ new Set()
971
+ };
972
+ },
973
+ apply(e, o, t, r) {
974
+ if (o.currentTransactionOldBlockAttrs = {}, o.updatedBlocks.clear(), !e.docChanged || t.doc.eq(r.doc))
975
+ return o;
976
+ const s = {}, i = j(
977
+ t.doc,
978
+ (l) => l.attrs.id
979
+ ), a = new Map(
980
+ i.map((l) => [l.node.attrs.id, l])
981
+ ), c = j(
982
+ r.doc,
983
+ (l) => l.attrs.id
984
+ );
985
+ for (const l of c) {
986
+ const m = a.get(l.node.attrs.id), h = m == null ? void 0 : m.node.firstChild, f = l.node.firstChild;
987
+ if (m && h && f) {
988
+ const u = {
989
+ index: f.attrs.index,
990
+ level: f.attrs.level,
991
+ type: f.type.name,
992
+ depth: r.doc.resolve(l.pos).depth
993
+ }, g = {
994
+ index: h.attrs.index,
995
+ level: h.attrs.level,
996
+ type: h.type.name,
997
+ depth: t.doc.resolve(m.pos).depth
998
+ };
999
+ s[l.node.attrs.id] = g, o.currentTransactionOldBlockAttrs[l.node.attrs.id] = g, JSON.stringify(g) !== JSON.stringify(u) && (g["depth-change"] = g.depth - u.depth, o.updatedBlocks.add(l.node.attrs.id));
1000
+ }
1001
+ }
1002
+ return o.prevTransactionOldBlockAttrs = s, o;
1003
+ }
1004
+ },
1005
+ props: {
1006
+ decorations(e) {
1007
+ const o = this.getState(e);
1008
+ if (o.updatedBlocks.size === 0)
1009
+ return;
1010
+ const t = [];
1011
+ return e.doc.descendants((r, s) => {
1012
+ if (!r.attrs.id || !o.updatedBlocks.has(r.attrs.id))
1013
+ return;
1014
+ const i = o.currentTransactionOldBlockAttrs[r.attrs.id], a = {};
1015
+ for (const [l, m] of Object.entries(i))
1016
+ a["data-prev-" + Ot[l]] = m || "none";
1017
+ const c = A.node(s, s + r.nodeSize, {
1018
+ ...a
1019
+ });
1020
+ t.push(c);
1021
+ }), V.create(e.doc, t);
1022
+ }
1023
+ }
1024
+ })
1025
+ ]
1026
+ };
1027
+ });
1028
+ function Ce(n, e) {
1029
+ var o, t;
1030
+ for (; n && n.parentElement && n.parentElement !== e.dom && ((o = n.getAttribute) == null ? void 0 : o.call(n, "data-node-type")) !== "blockContainer"; )
1031
+ n = n.parentElement;
1032
+ if (((t = n.getAttribute) == null ? void 0 : t.call(n, "data-node-type")) === "blockContainer")
1033
+ return { node: n, id: n.getAttribute("data-id") };
1034
+ }
1035
+ class P extends L {
1036
+ constructor(o, t) {
1037
+ super(o, t);
1038
+ b(this, "nodes");
1039
+ const r = o.node();
1040
+ this.nodes = [], o.doc.nodesBetween(o.pos, t.pos, (s, i, a) => {
1041
+ if (a !== null && a.eq(r))
1042
+ return this.nodes.push(s), !1;
1043
+ });
1044
+ }
1045
+ static create(o, t, r = t) {
1046
+ return new P(o.resolve(t), o.resolve(r));
1047
+ }
1048
+ content() {
1049
+ return new fe(pe.from(this.nodes), 0, 0);
1050
+ }
1051
+ eq(o) {
1052
+ if (!(o instanceof P) || this.nodes.length !== o.nodes.length || this.from !== o.from || this.to !== o.to)
1053
+ return !1;
1054
+ for (let t = 0; t < this.nodes.length; t++)
1055
+ if (!this.nodes[t].eq(o.nodes[t]))
1056
+ return !1;
1057
+ return !0;
1058
+ }
1059
+ map(o, t) {
1060
+ const r = t.mapResult(this.from), s = t.mapResult(this.to);
1061
+ return s.deleted ? L.near(o.resolve(r.pos)) : r.deleted ? L.near(o.resolve(s.pos)) : new P(
1062
+ o.resolve(r.pos),
1063
+ o.resolve(s.pos)
1064
+ );
1065
+ }
1066
+ toJSON() {
1067
+ return { type: "multiple-node", anchor: this.anchor, head: this.head };
1068
+ }
1069
+ }
1070
+ L.jsonID("multiple-node", P);
1071
+ let x;
1072
+ function Dt(n, e) {
1073
+ let o, t;
1074
+ const r = e.resolve(n.from).node().type.spec.group === "blockContent", s = e.resolve(n.to).node().type.spec.group === "blockContent", i = Math.min(n.$anchor.depth, n.$head.depth);
1075
+ if (r && s) {
1076
+ const a = n.$from.start(i - 1), c = n.$to.end(i - 1);
1077
+ o = e.resolve(a - 1).pos, t = e.resolve(c + 1).pos;
1078
+ } else
1079
+ o = n.from, t = n.to;
1080
+ return { from: o, to: t };
1081
+ }
1082
+ function re(n, e, o = e) {
1083
+ e === o && (o += n.state.doc.resolve(e + 1).node().nodeSize);
1084
+ const t = n.domAtPos(e).node.cloneNode(!0), r = n.domAtPos(e).node, s = (h, f) => Array.prototype.indexOf.call(h.children, f), i = s(
1085
+ r,
1086
+ // Expects from position to be just before the first selected block.
1087
+ n.domAtPos(e + 1).node.parentElement
1088
+ ), a = s(
1089
+ r,
1090
+ // Expects to position to be just after the last selected block.
1091
+ n.domAtPos(o - 1).node.parentElement
1092
+ );
1093
+ for (let h = r.childElementCount - 1; h >= 0; h--)
1094
+ (h > a || h < i) && t.removeChild(t.children[h]);
1095
+ Se(n.root), x = t;
1096
+ const c = x.getElementsByTagName("iframe");
1097
+ for (let h = 0; h < c.length; h++) {
1098
+ const f = c[h], u = f.parentElement;
1099
+ u && u.removeChild(f);
1100
+ }
1101
+ const m = n.dom.className.split(" ").filter(
1102
+ (h) => h !== "ProseMirror" && h !== "bn-root" && h !== "bn-editor"
1103
+ ).join(" ");
1104
+ x.className = x.className + " bn-drag-preview " + m, n.root instanceof ShadowRoot ? n.root.appendChild(x) : n.root.body.appendChild(x);
1105
+ }
1106
+ function Se(n) {
1107
+ x !== void 0 && (n instanceof ShadowRoot ? n.removeChild(x) : n.body.removeChild(x), x = void 0);
1108
+ }
1109
+ function At(n, e, o) {
1110
+ if (!n.dataTransfer || o.headless)
1111
+ return;
1112
+ const t = o.prosemirrorView, r = he(e.id, t.state.doc);
1113
+ if (!r)
1114
+ throw new Error(`Block with ID ${e.id} not found`);
1115
+ const s = r.posBeforeNode;
1116
+ if (s != null) {
1117
+ const i = t.state.selection, a = t.state.doc, { from: c, to: l } = Dt(i, a), m = c <= s && s < l, h = i.$anchor.node() !== i.$head.node() || i instanceof P;
1118
+ m && h ? (t.dispatch(
1119
+ t.state.tr.setSelection(P.create(a, c, l))
1120
+ ), re(t, c, l)) : (t.dispatch(
1121
+ t.state.tr.setSelection(le.create(t.state.doc, s))
1122
+ ), re(t, s));
1123
+ const f = t.state.selection.content(), u = o.pmSchema, g = t.serializeForClipboard(f).dom.innerHTML, d = be(u, o), p = St(f.content), w = d.exportBlocks(p, {}), y = ve(w);
1124
+ n.dataTransfer.clearData(), n.dataTransfer.setData("blocknote/html", g), n.dataTransfer.setData("text/html", w), n.dataTransfer.setData("text/plain", y), n.dataTransfer.effectAllowed = "move", n.dataTransfer.setDragImage(x, 0, 0);
1125
+ }
1126
+ }
1127
+ const se = 250;
1128
+ function $(n, e, o = !0) {
1129
+ const t = n.root.elementsFromPoint(e.left, e.top);
1130
+ for (const r of t)
1131
+ if (n.dom.contains(r))
1132
+ return o && r.closest("[data-node-type=columnList]") ? $(
1133
+ n,
1134
+ {
1135
+ // TODO can we do better than this?
1136
+ left: e.left + 50,
1137
+ // bit hacky, but if we're inside a column, offset x position to right to account for the width of sidemenu itself
1138
+ top: e.top
1139
+ },
1140
+ !1
1141
+ ) : Ce(r, n);
1142
+ }
1143
+ function Mt(n, e) {
1144
+ if (!e.dom.firstChild)
1145
+ return;
1146
+ const o = e.dom.firstChild.getBoundingClientRect(), t = {
1147
+ // Clamps the x position to the editor's bounding box.
1148
+ left: Math.min(
1149
+ Math.max(o.left + 10, n.x),
1150
+ o.right - 10
1151
+ ),
1152
+ top: n.y
1153
+ }, r = $(e, t);
1154
+ if (!r)
1155
+ return;
1156
+ const s = r.node.getBoundingClientRect();
1157
+ return $(
1158
+ e,
1159
+ {
1160
+ left: s.right - 10,
1161
+ top: n.y
1162
+ },
1163
+ !1
1164
+ );
1165
+ }
1166
+ class Lt {
1167
+ constructor(e, o, t) {
1168
+ b(this, "state");
1169
+ b(this, "emitUpdate");
1170
+ b(this, "mousePos");
1171
+ b(this, "hoveredBlock");
1172
+ b(this, "menuFrozen", !1);
1173
+ b(this, "isDragOrigin", !1);
1174
+ b(this, "updateState", (e) => {
1175
+ this.state = e, this.emitUpdate(this.state);
1176
+ });
1177
+ b(this, "updateStateFromMousePos", () => {
1178
+ var t, r, s, i, a;
1179
+ if (this.menuFrozen || !this.mousePos)
1180
+ return;
1181
+ const e = this.findClosestEditorElement({
1182
+ clientX: this.mousePos.x,
1183
+ clientY: this.mousePos.y
1184
+ });
1185
+ if ((e == null ? void 0 : e.element) !== this.pmView.dom || e.distance > se) {
1186
+ (t = this.state) != null && t.show && (this.state.show = !1, this.updateState(this.state));
1187
+ return;
1188
+ }
1189
+ const o = Mt(this.mousePos, this.pmView);
1190
+ if (!o || !this.editor.isEditable) {
1191
+ (r = this.state) != null && r.show && (this.state.show = !1, this.updateState(this.state));
1192
+ return;
1193
+ }
1194
+ if (!((s = this.state) != null && s.show && ((i = this.hoveredBlock) != null && i.hasAttribute("data-id")) && ((a = this.hoveredBlock) == null ? void 0 : a.getAttribute("data-id")) === o.id) && (this.hoveredBlock = o.node, this.editor.isEditable)) {
1195
+ const c = o.node.getBoundingClientRect(), l = o.node.closest("[data-node-type=column]");
1196
+ this.state = {
1197
+ show: !0,
1198
+ referencePos: new DOMRect(
1199
+ l ? (
1200
+ // We take the first child as column elements have some default
1201
+ // padding. This is a little weird since this child element will
1202
+ // be the first block, but since it's always non-nested and we
1203
+ // only take the x coordinate, it's ok.
1204
+ l.firstElementChild.getBoundingClientRect().x
1205
+ ) : this.pmView.dom.firstChild.getBoundingClientRect().x,
1206
+ c.y,
1207
+ c.width,
1208
+ c.height
1209
+ ),
1210
+ block: this.editor.getBlock(
1211
+ this.hoveredBlock.getAttribute("data-id")
1212
+ )
1213
+ }, this.updateState(this.state);
1214
+ }
1215
+ });
1216
+ /**
1217
+ * If a block is being dragged, ProseMirror usually gets the context of what's
1218
+ * being dragged from `view.dragging`, which is automatically set when a
1219
+ * `dragstart` event fires in the editor. However, if the user tries to drag
1220
+ * and drop blocks between multiple editors, only the one in which the drag
1221
+ * began has that context, so we need to set it on the others manually. This
1222
+ * ensures that PM always drops the blocks in between other blocks, and not
1223
+ * inside them.
1224
+ *
1225
+ * After the `dragstart` event fires on the drag handle, it sets
1226
+ * `blocknote/html` data on the clipboard. This handler fires right after,
1227
+ * parsing the `blocknote/html` data into nodes and setting them on
1228
+ * `view.dragging`.
1229
+ *
1230
+ * Note: Setting `view.dragging` on `dragover` would be better as the user
1231
+ * could then drag between editors in different windows, but you can only
1232
+ * access `dataTransfer` contents on `dragstart` and `drop` events.
1233
+ */
1234
+ b(this, "onDragStart", (e) => {
1235
+ var i;
1236
+ const o = (i = e.dataTransfer) == null ? void 0 : i.getData("blocknote/html");
1237
+ if (!o || this.pmView.dragging)
1238
+ return;
1239
+ const t = document.createElement("div");
1240
+ t.innerHTML = o;
1241
+ const s = Je.fromSchema(this.pmView.state.schema).parse(t, {
1242
+ topNode: this.pmView.state.schema.nodes.blockGroup.create()
1243
+ });
1244
+ this.pmView.dragging = {
1245
+ slice: new fe(s.content, 0, 0),
1246
+ move: !0
1247
+ };
1248
+ });
1249
+ /**
1250
+ * Finds the closest editor visually to the given coordinates
1251
+ */
1252
+ b(this, "findClosestEditorElement", (e) => {
1253
+ const o = Array.from(this.pmView.root.querySelectorAll(".bn-editor"));
1254
+ if (o.length === 0)
1255
+ return null;
1256
+ let t = o[0], r = Number.MAX_VALUE;
1257
+ return o.forEach((s) => {
1258
+ const i = s.querySelector(".bn-block-group").getBoundingClientRect(), a = e.clientX < i.left ? i.left - e.clientX : e.clientX > i.right ? e.clientX - i.right : 0, c = e.clientY < i.top ? i.top - e.clientY : e.clientY > i.bottom ? e.clientY - i.bottom : 0, l = Math.sqrt(
1259
+ Math.pow(a, 2) + Math.pow(c, 2)
1260
+ );
1261
+ l < r && (r = l, t = s);
1262
+ }), {
1263
+ element: t,
1264
+ distance: r
1265
+ };
1266
+ });
1267
+ /**
1268
+ * This dragover event handler listens at the document level,
1269
+ * and is trying to handle dragover events for all editors.
1270
+ *
1271
+ * It specifically is trying to handle the following cases:
1272
+ * - If the dragover event is within the bounds of any editor, then it does nothing
1273
+ * - If the dragover event is outside the bounds of any editor, but close enough (within DISTANCE_TO_CONSIDER_EDITOR_BOUNDS) to the closest editor,
1274
+ * then it dispatches a synthetic dragover event to the closest editor (which will trigger the drop-cursor to be shown on that editor)
1275
+ * - If the dragover event is outside the bounds of the current editor, then it will dispatch a synthetic dragleave event to the current editor
1276
+ * (which will trigger the drop-cursor to be removed from the current editor)
1277
+ *
1278
+ * The synthetic event is a necessary evil because we do not control prosemirror-dropcursor to be able to show the drop-cursor within the range we want
1279
+ */
1280
+ b(this, "onDragOver", (e) => {
1281
+ if (e.synthetic)
1282
+ return;
1283
+ const o = this.getDragEventContext(e);
1284
+ if (!o || !o.isDropPoint) {
1285
+ this.closeDropCursor();
1286
+ return;
1287
+ }
1288
+ o.isDropPoint && !o.isDropWithinEditorBounds && this.dispatchSyntheticEvent(e);
1289
+ });
1290
+ /**
1291
+ * Closes the drop-cursor for the current editor
1292
+ */
1293
+ b(this, "closeDropCursor", () => {
1294
+ const e = new Event("dragleave", { bubbles: !1 });
1295
+ e.synthetic = !0, this.pmView.dom.dispatchEvent(e);
1296
+ });
1297
+ /**
1298
+ * It is surprisingly difficult to determine the information we need to know about a drag event
1299
+ *
1300
+ * This function is trying to determine the following:
1301
+ * - Whether the current editor instance is the drop point
1302
+ * - Whether the current editor instance is the drag origin
1303
+ * - Whether the drop event is within the bounds of the current editor instance
1304
+ */
1305
+ b(this, "getDragEventContext", (e) => {
1306
+ var c;
1307
+ const o = !((c = e.dataTransfer) != null && c.types.includes("blocknote/html")) && !!this.pmView.dragging, t = !!this.isDragOrigin, r = o || t, s = this.findClosestEditorElement(e);
1308
+ if (!s || s.distance > se)
1309
+ return;
1310
+ const i = s.element === this.pmView.dom, a = i && s.distance === 0;
1311
+ if (!(!i && !r))
1312
+ return {
1313
+ isDropPoint: i,
1314
+ isDropWithinEditorBounds: a,
1315
+ isDragOrigin: r
1316
+ };
1317
+ });
1318
+ /**
1319
+ * The drop event handler listens at the document level,
1320
+ * and handles drop events for all editors.
1321
+ *
1322
+ * It specifically handles the following cases:
1323
+ * - If we are both the drag origin and drop point:
1324
+ * - Let normal drop handling take over
1325
+ * - If we are the drop point but not the drag origin:
1326
+ * - Collapse selection to prevent PM from deleting unrelated content
1327
+ * - If drop event is outside our editor bounds, dispatch synthetic drop event to our editor
1328
+ * - If we are the drag origin but not the drop point:
1329
+ * - Delete the dragged content from our editor after a delay
1330
+ */
1331
+ b(this, "onDrop", (e) => {
1332
+ if (e.synthetic)
1333
+ return;
1334
+ const o = this.getDragEventContext(e);
1335
+ if (!o) {
1336
+ this.closeDropCursor();
1337
+ return;
1338
+ }
1339
+ const { isDropPoint: t, isDropWithinEditorBounds: r, isDragOrigin: s } = o;
1340
+ if (!r && t && this.dispatchSyntheticEvent(e), t) {
1341
+ if (this.pmView.dragging)
1342
+ return;
1343
+ this.pmView.dispatch(
1344
+ this.pmView.state.tr.setSelection(
1345
+ _.create(
1346
+ this.pmView.state.tr.doc,
1347
+ this.pmView.state.tr.selection.anchor
1348
+ )
1349
+ )
1350
+ );
1351
+ return;
1352
+ } else if (s) {
1353
+ setTimeout(
1354
+ () => this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),
1355
+ 0
1356
+ );
1357
+ return;
1358
+ }
1359
+ });
1360
+ b(this, "onDragEnd", (e) => {
1361
+ e.synthetic || (this.pmView.dragging = null);
1362
+ });
1363
+ b(this, "onKeyDown", (e) => {
1364
+ var o;
1365
+ (o = this.state) != null && o.show && this.editor.isFocused() && (this.state.show = !1, this.emitUpdate(this.state));
1366
+ });
1367
+ b(this, "onMouseMove", (e) => {
1368
+ var s;
1369
+ if (this.menuFrozen)
1370
+ return;
1371
+ this.mousePos = { x: e.clientX, y: e.clientY };
1372
+ const o = this.pmView.dom.getBoundingClientRect(), t = this.mousePos.x > o.left && this.mousePos.x < o.right && this.mousePos.y > o.top && this.mousePos.y < o.bottom, r = this.pmView.dom.parentElement;
1373
+ if (
1374
+ // Cursor is within the editor area
1375
+ t && // An element is hovered
1376
+ e && e.target && // Element is outside the editor
1377
+ !(r === e.target || r.contains(e.target))
1378
+ ) {
1379
+ (s = this.state) != null && s.show && (this.state.show = !1, this.emitUpdate(this.state));
1380
+ return;
1381
+ }
1382
+ this.updateStateFromMousePos();
1383
+ });
1384
+ this.editor = e, this.pmView = o, this.emitUpdate = () => {
1385
+ if (!this.state)
1386
+ throw new Error("Attempting to update uninitialized side menu");
1387
+ t(this.state);
1388
+ }, this.pmView.root.addEventListener(
1389
+ "dragstart",
1390
+ this.onDragStart
1391
+ ), this.pmView.root.addEventListener(
1392
+ "dragover",
1393
+ this.onDragOver
1394
+ ), this.pmView.root.addEventListener(
1395
+ "drop",
1396
+ this.onDrop,
1397
+ !0
1398
+ ), this.pmView.root.addEventListener(
1399
+ "dragend",
1400
+ this.onDragEnd,
1401
+ !0
1402
+ ), this.pmView.root.addEventListener(
1403
+ "mousemove",
1404
+ this.onMouseMove,
1405
+ !0
1406
+ ), this.pmView.root.addEventListener(
1407
+ "keydown",
1408
+ this.onKeyDown,
1409
+ !0
1410
+ );
1411
+ }
1412
+ dispatchSyntheticEvent(e) {
1413
+ const o = new Event(e.type, e), t = this.pmView.dom.firstChild.getBoundingClientRect();
1414
+ o.clientX = e.clientX, o.clientY = e.clientY, o.clientX = Math.min(
1415
+ Math.max(e.clientX, t.left),
1416
+ t.left + t.width
1417
+ ), o.clientY = Math.min(
1418
+ Math.max(e.clientY, t.top),
1419
+ t.top + t.height
1420
+ ), o.dataTransfer = e.dataTransfer, o.preventDefault = () => e.preventDefault(), o.synthetic = !0, this.pmView.dom.dispatchEvent(o);
1421
+ }
1422
+ // Needed in cases where the editor state updates without the mouse cursor
1423
+ // moving, as some state updates can require a side menu update. For example,
1424
+ // adding a button to the side menu which removes the block can cause the
1425
+ // block below to jump up into the place of the removed block when clicked,
1426
+ // allowing the user to click the button again without moving the cursor. This
1427
+ // would otherwise not update the side menu, and so clicking the button again
1428
+ // would attempt to remove the same block again, causing an error.
1429
+ update(e, o) {
1430
+ var r;
1431
+ !o.doc.eq(this.pmView.state.doc) && ((r = this.state) != null && r.show) && this.updateStateFromMousePos();
1432
+ }
1433
+ destroy() {
1434
+ var e;
1435
+ (e = this.state) != null && e.show && (this.state.show = !1, this.emitUpdate(this.state)), this.pmView.root.removeEventListener(
1436
+ "mousemove",
1437
+ this.onMouseMove,
1438
+ !0
1439
+ ), this.pmView.root.removeEventListener(
1440
+ "dragstart",
1441
+ this.onDragStart
1442
+ ), this.pmView.root.removeEventListener(
1443
+ "dragover",
1444
+ this.onDragOver
1445
+ ), this.pmView.root.removeEventListener(
1446
+ "drop",
1447
+ this.onDrop,
1448
+ !0
1449
+ ), this.pmView.root.removeEventListener(
1450
+ "dragend",
1451
+ this.onDragEnd,
1452
+ !0
1453
+ ), this.pmView.root.removeEventListener(
1454
+ "keydown",
1455
+ this.onKeyDown,
1456
+ !0
1457
+ );
1458
+ }
1459
+ }
1460
+ const Nt = new T("SideMenuPlugin"), ko = k(({ editor: n }) => {
1461
+ let e;
1462
+ const o = H(
1463
+ void 0
1464
+ );
1465
+ return {
1466
+ key: "sideMenu",
1467
+ store: o,
1468
+ prosemirrorPlugins: [
1469
+ new B({
1470
+ key: Nt,
1471
+ view: (t) => (e = new Lt(n, t, (r) => {
1472
+ o.setState({ ...r });
1473
+ }), e)
1474
+ })
1475
+ ],
1476
+ /**
1477
+ * Handles drag & drop events for blocks.
1478
+ */
1479
+ blockDragStart(t, r) {
1480
+ e && (e.isDragOrigin = !0), At(t, r, n);
1481
+ },
1482
+ /**
1483
+ * Handles drag & drop events for blocks.
1484
+ */
1485
+ blockDragEnd() {
1486
+ Se(n.prosemirrorView.root), e && (e.isDragOrigin = !1), n.blur();
1487
+ },
1488
+ /**
1489
+ * Freezes the side menu. When frozen, the side menu will stay
1490
+ * attached to the same block regardless of which block is hovered by the
1491
+ * mouse cursor.
1492
+ */
1493
+ freezeMenu() {
1494
+ e.menuFrozen = !0, e.state.show = !0, e.emitUpdate(e.state);
1495
+ },
1496
+ /**
1497
+ * Unfreezes the side menu. When frozen, the side menu will stay
1498
+ * attached to the same block regardless of which block is hovered by the
1499
+ * mouse cursor.
1500
+ */
1501
+ unfreezeMenu() {
1502
+ e.menuFrozen = !1, e.state.show = !1, e.emitUpdate(e.state);
1503
+ }
1504
+ };
1505
+ });
1506
+ let C;
1507
+ function ie(n) {
1508
+ C || (C = document.createElement("div"), C.innerHTML = "_", C.style.opacity = "0", C.style.height = "1px", C.style.width = "1px", n instanceof Document ? n.body.appendChild(C) : n.appendChild(C));
1509
+ }
1510
+ function Rt(n) {
1511
+ C && (n instanceof Document ? n.body.removeChild(C) : n.removeChild(C), C = void 0);
1512
+ }
1513
+ function M(n) {
1514
+ return Array.prototype.indexOf.call(n.parentElement.childNodes, n);
1515
+ }
1516
+ function Vt(n) {
1517
+ let e = n;
1518
+ for (; e && e.nodeName !== "TD" && e.nodeName !== "TH" && !e.classList.contains("tableWrapper"); ) {
1519
+ if (e.classList.contains("ProseMirror"))
1520
+ return;
1521
+ const o = e.parentNode;
1522
+ if (!o || !(o instanceof Element))
1523
+ return;
1524
+ e = o;
1525
+ }
1526
+ return e.nodeName === "TD" || e.nodeName === "TH" ? {
1527
+ type: "cell",
1528
+ domNode: e,
1529
+ tbodyNode: e.closest("tbody")
1530
+ } : {
1531
+ type: "wrapper",
1532
+ domNode: e,
1533
+ tbodyNode: e.querySelector("tbody")
1534
+ };
1535
+ }
1536
+ function Ht(n, e) {
1537
+ const o = e.querySelectorAll(n);
1538
+ for (let t = 0; t < o.length; t++)
1539
+ o[t].style.visibility = "hidden";
1540
+ }
1541
+ class Ft {
1542
+ constructor(e, o, t) {
1543
+ b(this, "state");
1544
+ b(this, "emitUpdate");
1545
+ b(this, "tableId");
1546
+ b(this, "tablePos");
1547
+ b(this, "tableElement");
1548
+ b(this, "menuFrozen", !1);
1549
+ b(this, "mouseState", "up");
1550
+ b(this, "prevWasEditable", null);
1551
+ b(this, "viewMousedownHandler", () => {
1552
+ this.mouseState = "down";
1553
+ });
1554
+ b(this, "mouseUpHandler", (e) => {
1555
+ this.mouseState = "up", this.mouseMoveHandler(e);
1556
+ });
1557
+ b(this, "mouseMoveHandler", (e) => {
1558
+ var l, m, h, f, u, g, d;
1559
+ if (this.menuFrozen || this.mouseState === "selecting" || !(e.target instanceof Element) || !this.pmView.dom.contains(e.target))
1560
+ return;
1561
+ const o = Vt(e.target);
1562
+ if ((o == null ? void 0 : o.type) === "cell" && this.mouseState === "down" && !((l = this.state) != null && l.draggingState)) {
1563
+ this.mouseState = "selecting", (m = this.state) != null && m.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate());
1564
+ return;
1565
+ }
1566
+ if (!o || !this.editor.isEditable) {
1567
+ (h = this.state) != null && h.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate());
1568
+ return;
1569
+ }
1570
+ if (!o.tbodyNode)
1571
+ return;
1572
+ const t = o.tbodyNode.getBoundingClientRect(), r = Ce(o.domNode, this.pmView);
1573
+ if (!r)
1574
+ return;
1575
+ this.tableElement = r.node;
1576
+ let s;
1577
+ const i = this.editor.transact(
1578
+ (p) => he(r.id, p.doc)
1579
+ );
1580
+ if (!i)
1581
+ throw new Error(`Block with ID ${r.id} not found`);
1582
+ const a = R(
1583
+ i.node,
1584
+ this.editor.pmSchema,
1585
+ this.editor.schema.blockSchema,
1586
+ this.editor.schema.inlineContentSchema,
1587
+ this.editor.schema.styleSchema
1588
+ );
1589
+ if (Fe(this.editor, "table") && (this.tablePos = i.posBeforeNode + 1, s = a), !s)
1590
+ return;
1591
+ this.tableId = r.id;
1592
+ const c = (f = o.domNode.closest(".tableWrapper")) == null ? void 0 : f.querySelector(".table-widgets-container");
1593
+ if ((o == null ? void 0 : o.type) === "wrapper") {
1594
+ const p = e.clientY >= t.bottom - 1 && // -1 to account for fractions of pixels in "bottom"
1595
+ e.clientY < t.bottom + 20, w = e.clientX >= t.right - 1 && e.clientX < t.right + 20, y = e.clientX > t.right || e.clientY > t.bottom;
1596
+ this.state = {
1597
+ ...this.state,
1598
+ show: !0,
1599
+ showAddOrRemoveRowsButton: p,
1600
+ showAddOrRemoveColumnsButton: w,
1601
+ referencePosTable: t,
1602
+ block: s,
1603
+ widgetContainer: c,
1604
+ colIndex: y || (u = this.state) == null ? void 0 : u.colIndex,
1605
+ rowIndex: y || (g = this.state) == null ? void 0 : g.rowIndex,
1606
+ referencePosCell: y || (d = this.state) == null ? void 0 : d.referencePosCell
1607
+ };
1608
+ } else {
1609
+ const p = M(o.domNode), w = M(o.domNode.parentElement), y = o.domNode.getBoundingClientRect();
1610
+ if (this.state !== void 0 && this.state.show && this.tableId === r.id && this.state.rowIndex === w && this.state.colIndex === p)
1611
+ return;
1612
+ this.state = {
1613
+ show: !0,
1614
+ showAddOrRemoveColumnsButton: p === s.content.rows[0].cells.length - 1,
1615
+ showAddOrRemoveRowsButton: w === s.content.rows.length - 1,
1616
+ referencePosTable: t,
1617
+ block: s,
1618
+ draggingState: void 0,
1619
+ referencePosCell: y,
1620
+ colIndex: p,
1621
+ rowIndex: w,
1622
+ widgetContainer: c
1623
+ };
1624
+ }
1625
+ return this.emitUpdate(), !1;
1626
+ });
1627
+ b(this, "dragOverHandler", (e) => {
1628
+ var f;
1629
+ if (((f = this.state) == null ? void 0 : f.draggingState) === void 0)
1630
+ return;
1631
+ e.preventDefault(), e.dataTransfer.dropEffect = "move", Ht(
1632
+ ".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",
1633
+ this.pmView.root
1634
+ );
1635
+ const o = {
1636
+ left: Math.min(
1637
+ Math.max(e.clientX, this.state.referencePosTable.left + 1),
1638
+ this.state.referencePosTable.right - 1
1639
+ ),
1640
+ top: Math.min(
1641
+ Math.max(e.clientY, this.state.referencePosTable.top + 1),
1642
+ this.state.referencePosTable.bottom - 1
1643
+ )
1644
+ }, t = this.pmView.root.elementsFromPoint(o.left, o.top).filter(
1645
+ (u) => u.tagName === "TD" || u.tagName === "TH"
1646
+ );
1647
+ if (t.length === 0)
1648
+ return;
1649
+ const r = t[0];
1650
+ let s = !1;
1651
+ const i = M(r.parentElement), a = M(r), c = this.state.draggingState.draggedCellOrientation === "row" ? this.state.rowIndex : this.state.colIndex, m = (this.state.draggingState.draggedCellOrientation === "row" ? i : a) !== c;
1652
+ (this.state.rowIndex !== i || this.state.colIndex !== a) && (this.state.rowIndex = i, this.state.colIndex = a, this.state.referencePosCell = r.getBoundingClientRect(), s = !0);
1653
+ const h = this.state.draggingState.draggedCellOrientation === "row" ? o.top : o.left;
1654
+ this.state.draggingState.mousePos !== h && (this.state.draggingState.mousePos = h, s = !0), s && this.emitUpdate(), m && this.editor.transact((u) => u.setMeta(D, !0));
1655
+ });
1656
+ b(this, "dropHandler", (e) => {
1657
+ if (this.mouseState = "up", this.state === void 0 || this.state.draggingState === void 0)
1658
+ return !1;
1659
+ if (this.state.rowIndex === void 0 || this.state.colIndex === void 0)
1660
+ throw new Error(
1661
+ "Attempted to drop table row or column, but no table block was hovered prior."
1662
+ );
1663
+ e.preventDefault();
1664
+ const { draggingState: o, colIndex: t, rowIndex: r } = this.state, s = this.state.block.content.columnWidths;
1665
+ if (o.draggedCellOrientation === "row") {
1666
+ if (!ce(
1667
+ this.state.block,
1668
+ o.originalIndex,
1669
+ r
1670
+ ))
1671
+ return !1;
1672
+ const i = Me(
1673
+ this.state.block,
1674
+ o.originalIndex,
1675
+ r
1676
+ );
1677
+ this.editor.updateBlock(this.state.block, {
1678
+ type: "table",
1679
+ content: {
1680
+ ...this.state.block.content,
1681
+ rows: i
1682
+ }
1683
+ });
1684
+ } else {
1685
+ if (!de(
1686
+ this.state.block,
1687
+ o.originalIndex,
1688
+ t
1689
+ ))
1690
+ return !1;
1691
+ const i = Le(
1692
+ this.state.block,
1693
+ o.originalIndex,
1694
+ t
1695
+ ), [a] = s.splice(o.originalIndex, 1);
1696
+ s.splice(t, 0, a), this.editor.updateBlock(this.state.block, {
1697
+ type: "table",
1698
+ content: {
1699
+ ...this.state.block.content,
1700
+ columnWidths: s,
1701
+ rows: i
1702
+ }
1703
+ });
1704
+ }
1705
+ return this.editor.setTextCursorPosition(this.state.block.id), !0;
1706
+ });
1707
+ this.editor = e, this.pmView = o, this.emitUpdate = () => {
1708
+ if (!this.state)
1709
+ throw new Error("Attempting to update uninitialized image toolbar");
1710
+ t(this.state);
1711
+ }, o.dom.addEventListener("mousemove", this.mouseMoveHandler), o.dom.addEventListener("mousedown", this.viewMousedownHandler), window.addEventListener("mouseup", this.mouseUpHandler), o.root.addEventListener(
1712
+ "dragover",
1713
+ this.dragOverHandler
1714
+ ), o.root.addEventListener(
1715
+ "drop",
1716
+ this.dropHandler
1717
+ );
1718
+ }
1719
+ // Updates drag handles when the table is modified or removed.
1720
+ update() {
1721
+ var r;
1722
+ if (!this.state || !this.state.show)
1723
+ return;
1724
+ if (this.state.block = this.editor.getBlock(this.state.block.id), !this.state.block || this.state.block.type !== "table" || // when collaborating, the table element might be replaced and out of date
1725
+ // because yjs replaces the element when for example you change the color via the side menu
1726
+ !((r = this.tableElement) != null && r.isConnected)) {
1727
+ this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate();
1728
+ return;
1729
+ }
1730
+ const { height: e, width: o } = Ne(
1731
+ this.state.block
1732
+ );
1733
+ this.state.rowIndex !== void 0 && this.state.colIndex !== void 0 && (this.state.rowIndex >= e && (this.state.rowIndex = e - 1), this.state.colIndex >= o && (this.state.colIndex = o - 1));
1734
+ const t = this.tableElement.querySelector("tbody");
1735
+ if (!t)
1736
+ throw new Error(
1737
+ "Table block does not contain a 'tbody' HTML element. This should never happen."
1738
+ );
1739
+ if (this.state.rowIndex !== void 0 && this.state.colIndex !== void 0) {
1740
+ const i = t.children[this.state.rowIndex].children[this.state.colIndex];
1741
+ i ? this.state.referencePosCell = i.getBoundingClientRect() : (this.state.rowIndex = void 0, this.state.colIndex = void 0);
1742
+ }
1743
+ this.state.referencePosTable = t.getBoundingClientRect(), this.emitUpdate();
1744
+ }
1745
+ destroy() {
1746
+ this.pmView.dom.removeEventListener("mousemove", this.mouseMoveHandler), window.removeEventListener("mouseup", this.mouseUpHandler), this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.pmView.root.removeEventListener(
1747
+ "dragover",
1748
+ this.dragOverHandler
1749
+ ), this.pmView.root.removeEventListener(
1750
+ "drop",
1751
+ this.dropHandler
1752
+ );
1753
+ }
1754
+ }
1755
+ const D = new T("TableHandlesPlugin"), Co = k(({ editor: n }) => {
1756
+ let e;
1757
+ const o = H(void 0);
1758
+ return {
1759
+ key: "tableHandles",
1760
+ store: o,
1761
+ prosemirrorPlugins: [
1762
+ new B({
1763
+ key: D,
1764
+ view: (t) => (e = new Ft(n, t, (r) => {
1765
+ o.setState({
1766
+ ...r,
1767
+ draggingState: r.draggingState ? { ...r.draggingState } : void 0
1768
+ });
1769
+ }), e),
1770
+ // We use decorations to render the drop cursor when dragging a table row
1771
+ // or column. The decorations are updated in the `dragOverHandler` method.
1772
+ props: {
1773
+ decorations: (t) => {
1774
+ if (e === void 0 || e.state === void 0 || e.state.draggingState === void 0 || e.tablePos === void 0)
1775
+ return;
1776
+ const r = e.state.draggingState.draggedCellOrientation === "row" ? e.state.rowIndex : e.state.colIndex;
1777
+ if (r === void 0)
1778
+ return;
1779
+ const s = [], { block: i, draggingState: a } = e.state, { originalIndex: c, draggedCellOrientation: l } = a;
1780
+ if (r === c || !i || l === "row" && !ce(i, c, r) || l === "col" && !de(i, c, r))
1781
+ return V.create(t.doc, s);
1782
+ const m = t.doc.resolve(e.tablePos + 1);
1783
+ return e.state.draggingState.draggedCellOrientation === "row" ? G(
1784
+ e.state.block,
1785
+ r
1786
+ ).forEach(({ row: f, col: u }) => {
1787
+ const g = t.doc.resolve(
1788
+ m.posAtIndex(f) + 1
1789
+ ), d = t.doc.resolve(
1790
+ g.posAtIndex(u) + 1
1791
+ ), p = d.node(), w = d.pos + (r > c ? p.nodeSize - 2 : 0);
1792
+ s.push(
1793
+ // The widget is a small bar which spans the width of the cell.
1794
+ A.widget(w, () => {
1795
+ const y = document.createElement("div");
1796
+ return y.className = "bn-table-drop-cursor", y.style.left = "0", y.style.right = "0", r > c ? y.style.bottom = "-2px" : y.style.top = "-3px", y.style.height = "4px", y;
1797
+ })
1798
+ );
1799
+ }) : W(
1800
+ e.state.block,
1801
+ r
1802
+ ).forEach(({ row: f, col: u }) => {
1803
+ const g = t.doc.resolve(
1804
+ m.posAtIndex(f) + 1
1805
+ ), d = t.doc.resolve(
1806
+ g.posAtIndex(u) + 1
1807
+ ), p = d.node(), w = d.pos + (r > c ? p.nodeSize - 2 : 0);
1808
+ s.push(
1809
+ // The widget is a small bar which spans the height of the cell.
1810
+ A.widget(w, () => {
1811
+ const y = document.createElement("div");
1812
+ return y.className = "bn-table-drop-cursor", y.style.top = "0", y.style.bottom = "0", r > c ? y.style.right = "-2px" : y.style.left = "-3px", y.style.width = "4px", y;
1813
+ })
1814
+ );
1815
+ }), V.create(t.doc, s);
1816
+ }
1817
+ }
1818
+ })
1819
+ ],
1820
+ /**
1821
+ * Callback that should be set on the `dragStart` event for whichever element
1822
+ * is used as the column drag handle.
1823
+ */
1824
+ colDragStart(t) {
1825
+ if (e === void 0 || e.state === void 0 || e.state.colIndex === void 0)
1826
+ throw new Error(
1827
+ "Attempted to drag table column, but no table block was hovered prior."
1828
+ );
1829
+ e.state.draggingState = {
1830
+ draggedCellOrientation: "col",
1831
+ originalIndex: e.state.colIndex,
1832
+ mousePos: t.clientX
1833
+ }, e.emitUpdate(), n.transact(
1834
+ (r) => r.setMeta(D, {
1835
+ draggedCellOrientation: e.state.draggingState.draggedCellOrientation,
1836
+ originalIndex: e.state.colIndex,
1837
+ newIndex: e.state.colIndex,
1838
+ tablePos: e.tablePos
1839
+ })
1840
+ ), !n.headless && (ie(n.prosemirrorView.root), t.dataTransfer.setDragImage(C, 0, 0), t.dataTransfer.effectAllowed = "move");
1841
+ },
1842
+ /**
1843
+ * Callback that should be set on the `dragStart` event for whichever element
1844
+ * is used as the row drag handle.
1845
+ */
1846
+ rowDragStart(t) {
1847
+ if (e.state === void 0 || e.state.rowIndex === void 0)
1848
+ throw new Error(
1849
+ "Attempted to drag table row, but no table block was hovered prior."
1850
+ );
1851
+ e.state.draggingState = {
1852
+ draggedCellOrientation: "row",
1853
+ originalIndex: e.state.rowIndex,
1854
+ mousePos: t.clientY
1855
+ }, e.emitUpdate(), n.transact(
1856
+ (r) => r.setMeta(D, {
1857
+ draggedCellOrientation: e.state.draggingState.draggedCellOrientation,
1858
+ originalIndex: e.state.rowIndex,
1859
+ newIndex: e.state.rowIndex,
1860
+ tablePos: e.tablePos
1861
+ })
1862
+ ), !n.headless && (ie(n.prosemirrorView.root), t.dataTransfer.setDragImage(C, 0, 0), t.dataTransfer.effectAllowed = "copyMove");
1863
+ },
1864
+ /**
1865
+ * Callback that should be set on the `dragEnd` event for both the element
1866
+ * used as the row drag handle, and the one used as the column drag handle.
1867
+ */
1868
+ dragEnd() {
1869
+ if (e.state === void 0)
1870
+ throw new Error(
1871
+ "Attempted to drag table row, but no table block was hovered prior."
1872
+ );
1873
+ e.state.draggingState = void 0, e.emitUpdate(), n.transact((t) => t.setMeta(D, null)), !n.headless && Rt(n.prosemirrorView.root);
1874
+ },
1875
+ /**
1876
+ * Freezes the drag handles. When frozen, they will stay attached to the same
1877
+ * cell regardless of which cell is hovered by the mouse cursor.
1878
+ */
1879
+ freezeHandles() {
1880
+ e.menuFrozen = !0;
1881
+ },
1882
+ /**
1883
+ * Unfreezes the drag handles. When frozen, they will stay attached to the
1884
+ * same cell regardless of which cell is hovered by the mouse cursor.
1885
+ */
1886
+ unfreezeHandles() {
1887
+ e.menuFrozen = !1;
1888
+ },
1889
+ getCellsAtRowHandle(t, r) {
1890
+ return G(t, r);
1891
+ },
1892
+ /**
1893
+ * Get all the cells in a column of the table block.
1894
+ */
1895
+ getCellsAtColumnHandle(t, r) {
1896
+ return W(t, r);
1897
+ },
1898
+ /**
1899
+ * Sets the selection to the given cell or a range of cells.
1900
+ * @returns The new state after the selection has been set.
1901
+ */
1902
+ setCellSelection(t, r, s = r) {
1903
+ if (!e)
1904
+ throw new Error("Table handles view not initialized");
1905
+ const i = t.doc.resolve(e.tablePos + 1), a = t.doc.resolve(
1906
+ i.posAtIndex(r.row) + 1
1907
+ ), c = t.doc.resolve(
1908
+ // No need for +1, since CellSelection expects the position before the cell
1909
+ a.posAtIndex(r.col)
1910
+ ), l = t.doc.resolve(
1911
+ i.posAtIndex(s.row) + 1
1912
+ ), m = t.doc.resolve(
1913
+ // No need for +1, since CellSelection expects the position before the cell
1914
+ l.posAtIndex(s.col)
1915
+ ), h = t.tr;
1916
+ return h.setSelection(
1917
+ new mt(c, m)
1918
+ ), t.apply(h);
1919
+ },
1920
+ /**
1921
+ * Adds a row or column to the table using prosemirror-table commands
1922
+ */
1923
+ addRowOrColumn(t, r) {
1924
+ n.exec((s, i) => {
1925
+ const a = this.setCellSelection(
1926
+ s,
1927
+ r.orientation === "row" ? { row: t, col: 0 } : { row: 0, col: t }
1928
+ );
1929
+ return r.orientation === "row" ? r.side === "above" ? ct(a, i) : dt(a, i) : r.side === "left" ? ut(a, i) : ht(a, i);
1930
+ });
1931
+ },
1932
+ /**
1933
+ * Removes a row or column from the table using prosemirror-table commands
1934
+ */
1935
+ removeRowOrColumn(t, r) {
1936
+ return r === "row" ? n.exec((s, i) => {
1937
+ const a = this.setCellSelection(s, {
1938
+ row: t,
1939
+ col: 0
1940
+ });
1941
+ return at(a, i);
1942
+ }) : n.exec((s, i) => {
1943
+ const a = this.setCellSelection(s, {
1944
+ row: 0,
1945
+ col: t
1946
+ });
1947
+ return lt(a, i);
1948
+ });
1949
+ },
1950
+ /**
1951
+ * Merges the cells in the table block.
1952
+ */
1953
+ mergeCells(t) {
1954
+ return n.exec((r, s) => {
1955
+ const i = t ? this.setCellSelection(
1956
+ r,
1957
+ t.relativeStartCell,
1958
+ t.relativeEndCell
1959
+ ) : r;
1960
+ return it(i, s);
1961
+ });
1962
+ },
1963
+ /**
1964
+ * Splits the cell in the table block.
1965
+ * If no cell is provided, the current cell selected will be split.
1966
+ */
1967
+ splitCell(t) {
1968
+ return n.exec((r, s) => {
1969
+ const i = t ? this.setCellSelection(r, t) : r;
1970
+ return st(i, s);
1971
+ });
1972
+ },
1973
+ /**
1974
+ * Gets the start and end cells of the current cell selection.
1975
+ * @returns The start and end cells of the current cell selection.
1976
+ */
1977
+ getCellSelection() {
1978
+ return n.transact((t) => {
1979
+ const r = t.selection;
1980
+ let s = r.$from, i = r.$to;
1981
+ if (Q(r)) {
1982
+ const { ranges: d } = r;
1983
+ d.forEach((p) => {
1984
+ s = p.$from.min(s ?? p.$from), i = p.$to.max(i ?? p.$to);
1985
+ });
1986
+ } else if (s = t.doc.resolve(
1987
+ r.$from.pos - r.$from.parentOffset - 1
1988
+ ), i = t.doc.resolve(
1989
+ r.$to.pos - r.$to.parentOffset - 1
1990
+ ), s.pos === 0 || i.pos === 0)
1991
+ return;
1992
+ const a = t.doc.resolve(
1993
+ s.pos - s.parentOffset - 1
1994
+ ), c = t.doc.resolve(i.pos - i.parentOffset - 1), l = t.doc.resolve(a.pos - a.parentOffset - 1), m = s.index(a.depth), h = a.index(l.depth), f = i.index(c.depth), u = c.index(l.depth), g = [];
1995
+ for (let d = h; d <= u; d++)
1996
+ for (let p = m; p <= f; p++)
1997
+ g.push({ row: d, col: p });
1998
+ return {
1999
+ from: {
2000
+ row: h,
2001
+ col: m
2002
+ },
2003
+ to: {
2004
+ row: u,
2005
+ col: f
2006
+ },
2007
+ cells: g
2008
+ };
2009
+ });
2010
+ },
2011
+ /**
2012
+ * Gets the direction of the merge based on the current cell selection.
2013
+ *
2014
+ * Returns undefined when there is no cell selection, or the selection is not within a table.
2015
+ */
2016
+ getMergeDirection(t) {
2017
+ return n.transact((r) => {
2018
+ const s = Q(r.selection) ? r.selection : void 0;
2019
+ if (!s || !t || // Only offer the merge button if there is more than one cell selected.
2020
+ s.ranges.length <= 1)
2021
+ return;
2022
+ const i = this.getCellSelection();
2023
+ if (i)
2024
+ return He(i.from, i.to, t) ? "vertical" : "horizontal";
2025
+ });
2026
+ },
2027
+ cropEmptyRowsOrColumns(t, r) {
2028
+ return Ve(t, r);
2029
+ },
2030
+ addRowsOrColumns(t, r, s) {
2031
+ return Re(t, r, s);
2032
+ }
2033
+ };
2034
+ }), ae = new T("trailingNode"), So = k(() => ({
2035
+ key: "trailingNode",
2036
+ prosemirrorPlugins: [
2037
+ new B({
2038
+ key: ae,
2039
+ appendTransaction: (n, e, o) => {
2040
+ const { doc: t, tr: r, schema: s } = o, i = ae.getState(o), a = t.content.size - 2, c = s.nodes.blockContainer, l = s.nodes.paragraph;
2041
+ if (i)
2042
+ return r.insert(
2043
+ a,
2044
+ c.create(void 0, l.create())
2045
+ );
2046
+ },
2047
+ state: {
2048
+ init: (n, e) => {
2049
+ },
2050
+ apply: (n, e) => {
2051
+ if (!n.docChanged)
2052
+ return e;
2053
+ let o = n.doc.lastChild;
2054
+ if (!o || o.type.name !== "blockGroup")
2055
+ throw new Error("Expected blockGroup");
2056
+ if (o = o.lastChild, !o || o.type.name !== "blockContainer")
2057
+ return !0;
2058
+ const t = o.firstChild;
2059
+ if (!t)
2060
+ throw new Error("Expected blockContent");
2061
+ return o.nodeSize > 4 || t.type.spec.content !== "inline*";
2062
+ }
2063
+ }
2064
+ })
2065
+ ]
2066
+ }));
2067
+ export {
2068
+ lo as B,
2069
+ ho as D,
2070
+ co as F,
2071
+ po as H,
2072
+ fo as L,
2073
+ yo as N,
2074
+ bo as P,
2075
+ uo as S,
2076
+ Ft as T,
2077
+ go as V,
2078
+ oe as Y,
2079
+ F as a,
2080
+ U as b,
2081
+ mo as c,
2082
+ wo as d,
2083
+ vo as e,
2084
+ Lt as f,
2085
+ ko as g,
2086
+ Co as h,
2087
+ So as i,
2088
+ bt as j,
2089
+ be as k,
2090
+ ao as l,
2091
+ ve as m,
2092
+ St as n,
2093
+ Nt as s,
2094
+ D as t
2095
+ };
2096
+ //# sourceMappingURL=TrailingNode-BUhuMJrB.js.map