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