@blocknote/core 0.8.1 → 0.8.3

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 (71) hide show
  1. package/README.md +4 -0
  2. package/dist/blocknote.js +1787 -1834
  3. package/dist/blocknote.js.map +1 -1
  4. package/dist/blocknote.umd.cjs +4 -4
  5. package/dist/blocknote.umd.cjs.map +1 -1
  6. package/dist/style.css +1 -1
  7. package/package.json +3 -3
  8. package/src/BlockNoteEditor.ts +102 -38
  9. package/src/BlockNoteExtensions.ts +1 -58
  10. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
  11. package/src/api/formatConversions/formatConversions.test.ts +587 -605
  12. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +15 -15
  13. package/src/api/nodeConversions/nodeConversions.test.ts +90 -94
  14. package/src/extensions/Blocks/api/blockTypes.ts +3 -2
  15. package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +6 -0
  16. package/src/extensions/Blocks/nodes/BlockContainer.ts +12 -3
  17. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +92 -104
  18. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +178 -134
  19. package/src/extensions/Placeholder/PlaceholderExtension.ts +2 -2
  20. package/src/extensions/{DraggableBlocks/DraggableBlocksPlugin.ts → SideMenu/SideMenuPlugin.ts} +173 -163
  21. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -30
  22. package/src/extensions/SlashMenu/SlashMenuPlugin.ts +51 -0
  23. package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +109 -0
  24. package/src/extensions/UniqueID/UniqueID.ts +29 -30
  25. package/src/index.ts +9 -8
  26. package/src/node_modules/.vitest/results.json +1 -0
  27. package/src/shared/BaseUiElementTypes.ts +8 -0
  28. package/src/shared/EditorElement.ts +0 -16
  29. package/src/shared/EventEmitter.ts +58 -0
  30. package/src/shared/plugins/suggestion/SuggestionItem.ts +3 -6
  31. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +333 -389
  32. package/types/src/BlockNoteEditor.d.ts +18 -10
  33. package/types/src/BlockNoteExtensions.d.ts +0 -19
  34. package/types/src/EventEmitter.d.ts +11 -0
  35. package/types/src/extensions/Blocks/api/blockTypes.d.ts +3 -2
  36. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +0 -17
  37. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +25 -19
  38. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -3
  39. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +17 -24
  40. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +0 -12
  41. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +37 -10
  42. package/types/src/extensions/SideMenu/MultipleNodeSelection.d.ts +24 -0
  43. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +79 -0
  44. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -18
  45. package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +13 -0
  46. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +1 -69
  47. package/types/src/extensions/SlashMenu/index.d.ts +2 -3
  48. package/types/src/index.d.ts +9 -8
  49. package/types/src/shared/BaseUiElementTypes.d.ts +7 -0
  50. package/types/src/shared/EditorElement.d.ts +0 -10
  51. package/types/src/shared/EventEmitter.d.ts +11 -0
  52. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +2 -7
  53. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +12 -43
  54. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +1 -1
  55. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +0 -29
  56. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +0 -37
  57. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +0 -37
  58. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +0 -20
  59. package/src/extensions/HyperlinkToolbar/HyperlinkMark.ts +0 -28
  60. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +0 -19
  61. package/src/extensions/SlashMenu/SlashMenuExtension.ts +0 -53
  62. package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +0 -195
  63. package/src/extensions/SlashMenu/index.ts +0 -5
  64. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +0 -21
  65. package/types/src/CustomBlock.d.ts +0 -15
  66. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableCol.d.ts +0 -2
  67. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableContent.d.ts +0 -2
  68. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableRow.d.ts +0 -2
  69. package/types/src/extensions/Placeholder/localisation/index.d.ts +0 -2
  70. package/types/src/extensions/Placeholder/localisation/translation.d.ts +0 -51
  71. /package/src/extensions/{DraggableBlocks → SideMenu}/MultipleNodeSelection.ts +0 -0
package/dist/blocknote.js CHANGED
@@ -1,150 +1,242 @@
1
- var Nt = Object.defineProperty;
2
- var At = (o, e, t) => e in o ? Nt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var h = (o, e, t) => (At(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { Node as R, InputRule as Y, mergeAttributes as w, Extension as v, findChildren as j, combineTransactionSteps as Ht, getChangedRanges as Ot, findChildrenInRange as Dt, Mark as st, findParentNode as Ft, isTextSelection as Rt, isNodeSelection as zt, posToDOMRect as at, getMarkRange as Q, extensions as N, Editor as Ut } from "@tiptap/core";
5
- import { PluginKey as E, Plugin as C, TextSelection as tt, Selection as G, NodeSelection as $t } from "prosemirror-state";
6
- import { Slice as I, Fragment as _, DOMSerializer as q, DOMParser as Gt } from "prosemirror-model";
7
- import { v4 as jt } from "uuid";
1
+ var Lt = Object.defineProperty;
2
+ var Nt = (n, e, t) => e in n ? Lt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var u = (n, e, t) => (Nt(n, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { Extension as T, Mark as at, Node as V, InputRule as Y, mergeAttributes as x, combineTransactionSteps as Pt, getChangedRanges as Ot, findChildrenInRange as Dt, findChildren as Q, findParentNode as Rt, extensions as L, isTextSelection as zt, isNodeSelection as Vt, posToDOMRect as j, getMarkRange as tt, Editor as Ut } from "@tiptap/core";
5
+ import { Bold as Ft } from "@tiptap/extension-bold";
6
+ import { Code as $t } from "@tiptap/extension-code";
7
+ import Gt from "@tiptap/extension-collaboration";
8
+ import jt from "@tiptap/extension-collaboration-cursor";
9
+ import { Dropcursor as qt } from "@tiptap/extension-dropcursor";
10
+ import { Gapcursor as Wt } from "@tiptap/extension-gapcursor";
11
+ import { HardBreak as Yt } from "@tiptap/extension-hard-break";
12
+ import { History as Jt } from "@tiptap/extension-history";
13
+ import { Italic as Kt } from "@tiptap/extension-italic";
14
+ import { Link as Xt } from "@tiptap/extension-link";
15
+ import { Strike as Zt } from "@tiptap/extension-strike";
16
+ import { Text as Qt } from "@tiptap/extension-text";
17
+ import { Underline as te } from "@tiptap/extension-underline";
18
+ import { Slice as B, Fragment as I, DOMSerializer as q, DOMParser as ee } from "prosemirror-model";
19
+ import { PluginKey as S, Plugin as y, TextSelection as et, Selection as G, NodeSelection as oe } from "prosemirror-state";
20
+ import { v4 as ne } from "uuid";
21
+ import * as re from "prosemirror-view";
22
+ import { Decoration as R, DecorationSet as z } from "prosemirror-view";
8
23
  import lt from "rehype-parse";
9
- import qt from "rehype-remark";
24
+ import ie from "rehype-remark";
10
25
  import dt from "rehype-stringify";
11
26
  import ct from "remark-gfm";
12
- import Wt from "remark-parse";
13
- import Yt from "remark-rehype";
14
- import Vt from "remark-stringify";
15
- import { unified as V } from "unified";
16
- import { fromDom as et } from "hast-util-from-dom";
17
- import { Bold as Kt } from "@tiptap/extension-bold";
18
- import { Code as Jt } from "@tiptap/extension-code";
19
- import Xt from "@tiptap/extension-collaboration";
20
- import Zt from "@tiptap/extension-collaboration-cursor";
21
- import { Dropcursor as Qt } from "@tiptap/extension-dropcursor";
22
- import { Gapcursor as te } from "@tiptap/extension-gapcursor";
23
- import { HardBreak as ee } from "@tiptap/extension-hard-break";
24
- import { History as oe } from "@tiptap/extension-history";
25
- import { Italic as ne } from "@tiptap/extension-italic";
26
- import { Link as ut } from "@tiptap/extension-link";
27
- import { Strike as re } from "@tiptap/extension-strike";
28
- import { Text as ie } from "@tiptap/extension-text";
29
- import { Underline as se } from "@tiptap/extension-underline";
30
- import * as ae from "prosemirror-view";
31
- import { Decoration as D, DecorationSet as F } from "prosemirror-view";
32
- const ht = "_blockOuter_xgzwr_5", pt = "_block_xgzwr_5", ft = "_reactNodeViewRenderer_xgzwr_17", mt = "_blockContent_xgzwr_22", gt = "_blockGroup_xgzwr_42", kt = "_isEmpty_xgzwr_240", yt = "_inlineContent_xgzwr_240", bt = "_isFilter_xgzwr_241", vt = "_hasAnchor_xgzwr_263", k = {
33
- blockOuter: ht,
27
+ import se from "remark-parse";
28
+ import ae from "remark-rehype";
29
+ import le from "remark-stringify";
30
+ import { unified as J } from "unified";
31
+ import { fromDom as ot } from "hast-util-from-dom";
32
+ const de = "_bnEditor_4vj2p_3", ce = "_bnRoot_4vj2p_20", ue = "_defaultStyles_4vj2p_35", pe = "_dragPreview_4vj2p_68", H = {
33
+ bnEditor: de,
34
+ bnRoot: ce,
35
+ defaultStyles: ue,
36
+ dragPreview: pe,
37
+ "collaboration-cursor__caret": "_collaboration-cursor__caret_4vj2p_74",
38
+ "collaboration-cursor__label": "_collaboration-cursor__label_4vj2p_85"
39
+ };
40
+ function g(n, e) {
41
+ if (e < 0 || e > n.nodeSize)
42
+ return;
43
+ n.resolve(e).parent.type.name === "blockGroup" && e++;
44
+ const t = n.resolve(e), o = t.depth;
45
+ let r = t.node(o), i = o;
46
+ for (; ; ) {
47
+ if (i < 0)
48
+ return;
49
+ if (r.type.name === "blockContainer")
50
+ break;
51
+ i -= 1, r = t.node(i);
52
+ }
53
+ const s = r.attrs.id, l = r.firstChild, a = l.type, d = r.childCount === 2 ? r.lastChild.childCount : 0, c = t.start(i), p = t.end(i);
54
+ return {
55
+ id: s,
56
+ node: r,
57
+ contentNode: l,
58
+ contentType: a,
59
+ numChildBlocks: d,
60
+ startPos: c,
61
+ endPos: p,
62
+ depth: i
63
+ };
64
+ }
65
+ const he = T.create({
66
+ name: "blockBackgroundColor",
67
+ addGlobalAttributes() {
68
+ return [
69
+ {
70
+ types: ["blockContainer"],
71
+ attributes: {
72
+ backgroundColor: {
73
+ default: "default",
74
+ parseHTML: (n) => n.hasAttribute("data-background-color") ? n.getAttribute("data-background-color") : "default",
75
+ renderHTML: (n) => n.backgroundColor !== "default" && {
76
+ "data-background-color": n.backgroundColor
77
+ }
78
+ }
79
+ }
80
+ }
81
+ ];
82
+ },
83
+ addCommands() {
84
+ return {
85
+ setBlockBackgroundColor: (n, e) => ({ state: t, view: o }) => {
86
+ const r = g(t.doc, n);
87
+ return r === void 0 ? !1 : (t.tr.setNodeAttribute(
88
+ r.startPos - 1,
89
+ "backgroundColor",
90
+ e
91
+ ), o.focus(), !0);
92
+ }
93
+ };
94
+ }
95
+ }), fe = at.create({
96
+ name: "backgroundColor",
97
+ addAttributes() {
98
+ return {
99
+ color: {
100
+ default: void 0,
101
+ parseHTML: (n) => n.getAttribute("data-background-color"),
102
+ renderHTML: (n) => ({
103
+ "data-background-color": n.color
104
+ })
105
+ }
106
+ };
107
+ },
108
+ parseHTML() {
109
+ return [
110
+ {
111
+ tag: "span",
112
+ getAttrs: (n) => typeof n == "string" ? !1 : n.hasAttribute("data-background-color") ? { color: n.getAttribute("data-background-color") } : !1
113
+ }
114
+ ];
115
+ },
116
+ renderHTML({ HTMLAttributes: n }) {
117
+ return ["span", n, 0];
118
+ },
119
+ addCommands() {
120
+ return {
121
+ setBackgroundColor: (n) => ({ commands: e }) => n !== "default" ? e.setMark(this.name, { color: n }) : e.unsetMark(this.name)
122
+ };
123
+ }
124
+ }), ut = "_blockOuter_xgzwr_5", pt = "_block_xgzwr_5", ht = "_reactNodeViewRenderer_xgzwr_17", ft = "_blockContent_xgzwr_22", mt = "_blockGroup_xgzwr_42", gt = "_isEmpty_xgzwr_240", kt = "_inlineContent_xgzwr_240", bt = "_isFilter_xgzwr_241", yt = "_hasAnchor_xgzwr_263", k = {
125
+ blockOuter: ut,
34
126
  block: pt,
35
- reactNodeViewRenderer: ft,
36
- blockContent: mt,
37
- blockGroup: gt,
38
- isEmpty: kt,
39
- inlineContent: yt,
127
+ reactNodeViewRenderer: ht,
128
+ blockContent: ft,
129
+ blockGroup: mt,
130
+ isEmpty: gt,
131
+ inlineContent: kt,
40
132
  isFilter: bt,
41
- hasAnchor: vt
42
- }, Yo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
133
+ hasAnchor: yt
134
+ }, jo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
43
135
  __proto__: null,
44
136
  block: pt,
45
- blockContent: mt,
46
- blockGroup: gt,
47
- blockOuter: ht,
137
+ blockContent: ft,
138
+ blockGroup: mt,
139
+ blockOuter: ut,
48
140
  default: k,
49
- hasAnchor: vt,
50
- inlineContent: yt,
51
- isEmpty: kt,
141
+ hasAnchor: yt,
142
+ inlineContent: kt,
143
+ isEmpty: gt,
52
144
  isFilter: bt,
53
- reactNodeViewRenderer: ft
145
+ reactNodeViewRenderer: ht
54
146
  }, Symbol.toStringTag, { value: "Module" }));
55
- function ot(o) {
56
- return "data-" + o.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
147
+ function nt(n) {
148
+ return "data-" + n.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
57
149
  }
58
- function le(o) {
150
+ function me(n) {
59
151
  const e = {};
60
- return Object.entries(o.propSchema).forEach(([t, n]) => {
152
+ return Object.entries(n.propSchema).forEach(([t, o]) => {
61
153
  e[t] = {
62
- default: n.default,
154
+ default: o.default,
63
155
  keepOnSplit: !0,
64
156
  // Props are displayed in kebab-case as HTML attributes. If a prop's
65
157
  // value is the same as its default, we don't display an HTML
66
158
  // attribute for it.
67
- parseHTML: (r) => r.getAttribute(ot(t)),
68
- renderHTML: (r) => r[t] !== n.default ? {
69
- [ot(t)]: r[t]
159
+ parseHTML: (r) => r.getAttribute(nt(t)),
160
+ renderHTML: (r) => r[t] !== o.default ? {
161
+ [nt(t)]: r[t]
70
162
  } : {}
71
163
  };
72
164
  }), e;
73
165
  }
74
- function de(o) {
166
+ function ge(n) {
75
167
  return [
76
168
  {
77
- tag: "div[data-content-type=" + o.type + "]"
169
+ tag: "div[data-content-type=" + n.type + "]"
78
170
  }
79
171
  ];
80
172
  }
81
- function ce(o, e) {
173
+ function ke(n, e) {
82
174
  const t = document.createElement("div");
83
- t.setAttribute("data-content-type", o.type);
175
+ t.setAttribute("data-content-type", n.type);
84
176
  for (const [r, i] of Object.entries(e))
85
177
  t.setAttribute(r, i);
86
- let n;
87
- return o.containsInlineContent ? (n = document.createElement("div"), t.appendChild(n)) : n = void 0, n !== void 0 ? {
178
+ let o;
179
+ return n.containsInlineContent ? (o = document.createElement("div"), t.appendChild(o)) : o = void 0, o !== void 0 ? {
88
180
  dom: t,
89
- contentDOM: n
181
+ contentDOM: o
90
182
  } : {
91
183
  dom: t
92
184
  };
93
185
  }
94
- function Vo(o) {
186
+ function qo(n) {
95
187
  return {
96
- node: H({
97
- name: o.type,
98
- content: o.containsInlineContent ? "inline*" : "",
99
- selectable: o.containsInlineContent,
188
+ node: P({
189
+ name: n.type,
190
+ content: n.containsInlineContent ? "inline*" : "",
191
+ selectable: n.containsInlineContent,
100
192
  addOptions() {
101
193
  return {
102
194
  editor: void 0
103
195
  };
104
196
  },
105
197
  addAttributes() {
106
- return le(o);
198
+ return me(n);
107
199
  },
108
200
  parseHTML() {
109
- return de(o);
201
+ return ge(n);
110
202
  },
111
203
  renderHTML({ HTMLAttributes: t }) {
112
- return ce(o, t);
204
+ return ke(n, t);
113
205
  },
114
206
  addNodeView() {
115
- return ({ HTMLAttributes: t, getPos: n }) => {
207
+ return ({ HTMLAttributes: t, getPos: o }) => {
116
208
  const r = document.createElement("div");
117
- r.className = k.blockContent, r.setAttribute("data-content-type", o.type);
118
- for (const [p, f] of Object.entries(t))
119
- r.setAttribute(p, f);
209
+ r.className = k.blockContent, r.setAttribute("data-content-type", n.type);
210
+ for (const [h, f] of Object.entries(t))
211
+ r.setAttribute(h, f);
120
212
  const i = this.options.editor;
121
- if (typeof n == "boolean")
213
+ if (typeof o == "boolean")
122
214
  throw new Error(
123
215
  "Cannot find node position as getPos is a boolean, not a function."
124
216
  );
125
- const s = n(), d = i._tiptapEditor.state.doc.resolve(s).node().attrs.id, c = i.getBlock(d);
126
- if (c.type !== o.type)
217
+ const s = o(), d = i._tiptapEditor.state.doc.resolve(s).node().attrs.id, c = i.getBlock(d);
218
+ if (c.type !== n.type)
127
219
  throw new Error("Block type does not match");
128
- const u = o.render(c, i);
129
- return "contentDOM" in u && (u.contentDOM.className = `${u.contentDOM.className ? u.contentDOM.className + " " : ""}${k.inlineContent}`), r.appendChild(u.dom), "contentDOM" in u ? {
220
+ const p = n.render(c, i);
221
+ return "contentDOM" in p && (p.contentDOM.className = `${p.contentDOM.className ? p.contentDOM.className + " " : ""}${k.inlineContent}`), r.appendChild(p.dom), "contentDOM" in p ? {
130
222
  dom: r,
131
- contentDOM: u.contentDOM
223
+ contentDOM: p.contentDOM
132
224
  } : {
133
225
  dom: r
134
226
  };
135
227
  };
136
228
  }
137
229
  }),
138
- propSchema: o.propSchema
230
+ propSchema: n.propSchema
139
231
  };
140
232
  }
141
- function H(o) {
142
- return R.create({
143
- ...o,
233
+ function P(n) {
234
+ return V.create({
235
+ ...n,
144
236
  group: "blockContent"
145
237
  });
146
238
  }
147
- const ue = H({
239
+ const be = P({
148
240
  name: "heading",
149
241
  content: "inline*",
150
242
  addAttributes() {
@@ -152,24 +244,24 @@ const ue = H({
152
244
  level: {
153
245
  default: "1",
154
246
  // instead of "level" attributes, use "data-level"
155
- parseHTML: (o) => o.getAttribute("data-level"),
156
- renderHTML: (o) => ({
157
- "data-level": o.level
247
+ parseHTML: (n) => n.getAttribute("data-level"),
248
+ renderHTML: (n) => ({
249
+ "data-level": n.level
158
250
  })
159
251
  }
160
252
  };
161
253
  },
162
254
  addInputRules() {
163
255
  return [
164
- ...["1", "2", "3"].map((o) => new Y({
165
- find: new RegExp(`^(#{${parseInt(o)}})\\s$`),
166
- handler: ({ state: e, chain: t, range: n }) => {
256
+ ...["1", "2", "3"].map((n) => new Y({
257
+ find: new RegExp(`^(#{${parseInt(n)}})\\s$`),
258
+ handler: ({ state: e, chain: t, range: o }) => {
167
259
  t().BNUpdateBlock(e.selection.from, {
168
260
  type: "heading",
169
261
  props: {
170
- level: o
262
+ level: n
171
263
  }
172
- }).deleteRange({ from: n.from, to: n.to });
264
+ }).deleteRange({ from: o.from, to: o.to });
173
265
  }
174
266
  }))
175
267
  ];
@@ -193,47 +285,22 @@ const ue = H({
193
285
  }
194
286
  ];
195
287
  },
196
- renderHTML({ node: o, HTMLAttributes: e }) {
288
+ renderHTML({ node: n, HTMLAttributes: e }) {
197
289
  return [
198
290
  "div",
199
- w(e, {
291
+ x(e, {
200
292
  class: k.blockContent,
201
293
  "data-content-type": this.name
202
294
  }),
203
- ["h" + o.attrs.level, { class: k.inlineContent }, 0]
295
+ ["h" + n.attrs.level, { class: k.inlineContent }, 0]
204
296
  ];
205
297
  }
206
- });
207
- function g(o, e) {
208
- if (e < 0 || e > o.nodeSize)
209
- return;
210
- const t = o.resolve(e), n = t.depth;
211
- let r = t.node(n), i = n;
212
- for (; ; ) {
213
- if (i < 0)
214
- return;
215
- if (r.type.name === "blockContainer")
216
- break;
217
- i -= 1, r = t.node(i);
218
- }
219
- const s = r.attrs.id, a = r.firstChild, l = a.type, d = r.childCount === 2 ? r.lastChild.childCount : 0, c = t.start(i), u = t.end(i);
220
- return {
221
- id: s,
222
- node: r,
223
- contentNode: a,
224
- contentType: l,
225
- numChildBlocks: d,
226
- startPos: c,
227
- endPos: u,
228
- depth: i
229
- };
230
- }
231
- const Et = (o) => {
298
+ }), vt = (n) => {
232
299
  const { node: e, contentType: t } = g(
233
- o.state.doc,
234
- o.state.selection.from
235
- ), n = o.state.selection.anchor === o.state.selection.head;
236
- return !t.name.endsWith("ListItem") || !n ? !1 : o.commands.first(({ state: r, chain: i, commands: s }) => [
300
+ n.state.doc,
301
+ n.state.selection.from
302
+ ), o = n.state.selection.anchor === n.state.selection.head;
303
+ return !t.name.endsWith("ListItem") || !o ? !1 : n.commands.first(({ state: r, chain: i, commands: s }) => [
237
304
  () => (
238
305
  // Changes list item block to a text block if the content is empty.
239
306
  s.command(() => e.textContent.length === 0 ? s.BNUpdateBlock(r.selection.from, {
@@ -247,7 +314,7 @@ const Et = (o) => {
247
314
  s.command(() => e.textContent.length > 0 ? (i().deleteSelection().BNSplitBlock(r.selection.from, !0).run(), !0) : !1)
248
315
  )
249
316
  ]);
250
- }, he = H({
317
+ }, ye = P({
251
318
  name: "bulletListItem",
252
319
  content: "inline*",
253
320
  addInputRules() {
@@ -255,8 +322,8 @@ const Et = (o) => {
255
322
  // Creates an unordered list when starting with "-", "+", or "*".
256
323
  new Y({
257
324
  find: new RegExp("^[-+*]\\s$"),
258
- handler: ({ state: o, chain: e, range: t }) => {
259
- e().BNUpdateBlock(o.selection.from, {
325
+ handler: ({ state: n, chain: e, range: t }) => {
326
+ e().BNUpdateBlock(n.selection.from, {
260
327
  type: "bulletListItem",
261
328
  props: {}
262
329
  }).deleteRange({ from: t.from, to: t.to });
@@ -266,7 +333,7 @@ const Et = (o) => {
266
333
  },
267
334
  addKeyboardShortcuts() {
268
335
  return {
269
- Enter: () => Et(this.editor)
336
+ Enter: () => vt(this.editor)
270
337
  };
271
338
  },
272
339
  parseHTML() {
@@ -274,10 +341,10 @@ const Et = (o) => {
274
341
  // Case for regular HTML list structure.
275
342
  {
276
343
  tag: "li",
277
- getAttrs: (o) => {
278
- if (typeof o == "string")
344
+ getAttrs: (n) => {
345
+ if (typeof n == "string")
279
346
  return !1;
280
- const e = o.parentElement;
347
+ const e = n.parentElement;
281
348
  return e === null ? !1 : e.tagName === "UL" ? {} : !1;
282
349
  },
283
350
  node: "bulletListItem"
@@ -285,10 +352,10 @@ const Et = (o) => {
285
352
  // Case for BlockNote list structure.
286
353
  {
287
354
  tag: "p",
288
- getAttrs: (o) => {
289
- if (typeof o == "string")
355
+ getAttrs: (n) => {
356
+ if (typeof n == "string")
290
357
  return !1;
291
- const e = o.parentElement;
358
+ const e = n.parentElement;
292
359
  return e === null ? !1 : e.getAttribute("data-content-type") === "bulletListItem" ? {} : !1;
293
360
  },
294
361
  priority: 300,
@@ -296,56 +363,56 @@ const Et = (o) => {
296
363
  }
297
364
  ];
298
365
  },
299
- renderHTML({ HTMLAttributes: o }) {
366
+ renderHTML({ HTMLAttributes: n }) {
300
367
  return [
301
368
  "div",
302
- w(o, {
369
+ x(n, {
303
370
  class: k.blockContent,
304
371
  "data-content-type": this.name
305
372
  }),
306
373
  ["p", { class: k.inlineContent }, 0]
307
374
  ];
308
375
  }
309
- }), pe = new E("numbered-list-indexing"), fe = () => new C({
310
- key: pe,
311
- appendTransaction: (o, e, t) => {
312
- const n = t.tr;
313
- n.setMeta("numberedListIndexing", !0);
376
+ }), ve = new S("numbered-list-indexing"), we = () => new y({
377
+ key: ve,
378
+ appendTransaction: (n, e, t) => {
379
+ const o = t.tr;
380
+ o.setMeta("numberedListIndexing", !0);
314
381
  let r = !1;
315
382
  return t.doc.descendants((i, s) => {
316
383
  if (i.type.name === "blockContainer" && i.firstChild.type.name === "numberedListItem") {
317
- let a = "1";
318
- const l = s === 1, d = g(n.doc, s + 1);
384
+ let l = "1";
385
+ const a = s === 1, d = g(o.doc, s + 1);
319
386
  if (d === void 0)
320
387
  return;
321
- if (!l) {
322
- const p = g(n.doc, s - 2);
323
- if (p === void 0)
388
+ if (!a) {
389
+ const h = g(o.doc, s - 2);
390
+ if (h === void 0)
324
391
  return;
325
- if (!(d.depth !== p.depth)) {
326
- const m = p.contentNode;
327
- if (p.contentType.name === "numberedListItem") {
328
- const U = m.attrs.index;
329
- a = (parseInt(U) + 1).toString();
392
+ if (!(d.depth !== h.depth)) {
393
+ const m = h.contentNode;
394
+ if (h.contentType.name === "numberedListItem") {
395
+ const w = m.attrs.index;
396
+ l = (parseInt(w) + 1).toString();
330
397
  }
331
398
  }
332
399
  }
333
- d.contentNode.attrs.index !== a && (r = !0, n.setNodeMarkup(s + 1, void 0, {
334
- index: a
400
+ d.contentNode.attrs.index !== l && (r = !0, o.setNodeMarkup(s + 1, void 0, {
401
+ index: l
335
402
  }));
336
403
  }
337
- }), r ? n : null;
404
+ }), r ? o : null;
338
405
  }
339
- }), me = H({
406
+ }), Se = P({
340
407
  name: "numberedListItem",
341
408
  content: "inline*",
342
409
  addAttributes() {
343
410
  return {
344
411
  index: {
345
412
  default: null,
346
- parseHTML: (o) => o.getAttribute("data-index"),
347
- renderHTML: (o) => ({
348
- "data-index": o.index
413
+ parseHTML: (n) => n.getAttribute("data-index"),
414
+ renderHTML: (n) => ({
415
+ "data-index": n.index
349
416
  })
350
417
  }
351
418
  };
@@ -355,8 +422,8 @@ const Et = (o) => {
355
422
  // Creates an ordered list when starting with "1.".
356
423
  new Y({
357
424
  find: new RegExp("^1\\.\\s$"),
358
- handler: ({ state: o, chain: e, range: t }) => {
359
- e().BNUpdateBlock(o.selection.from, {
425
+ handler: ({ state: n, chain: e, range: t }) => {
426
+ e().BNUpdateBlock(n.selection.from, {
360
427
  type: "numberedListItem",
361
428
  props: {}
362
429
  }).deleteRange({ from: t.from, to: t.to });
@@ -366,11 +433,11 @@ const Et = (o) => {
366
433
  },
367
434
  addKeyboardShortcuts() {
368
435
  return {
369
- Enter: () => Et(this.editor)
436
+ Enter: () => vt(this.editor)
370
437
  };
371
438
  },
372
439
  addProseMirrorPlugins() {
373
- return [fe()];
440
+ return [we()];
374
441
  },
375
442
  parseHTML() {
376
443
  return [
@@ -378,10 +445,10 @@ const Et = (o) => {
378
445
  // (e.g.: when pasting from other apps)
379
446
  {
380
447
  tag: "li",
381
- getAttrs: (o) => {
382
- if (typeof o == "string")
448
+ getAttrs: (n) => {
449
+ if (typeof n == "string")
383
450
  return !1;
384
- const e = o.parentElement;
451
+ const e = n.parentElement;
385
452
  return e === null ? !1 : e.tagName === "OL" ? {} : !1;
386
453
  },
387
454
  node: "numberedListItem"
@@ -390,10 +457,10 @@ const Et = (o) => {
390
457
  // (e.g.: when pasting from blocknote)
391
458
  {
392
459
  tag: "p",
393
- getAttrs: (o) => {
394
- if (typeof o == "string")
460
+ getAttrs: (n) => {
461
+ if (typeof n == "string")
395
462
  return !1;
396
- const e = o.parentElement;
463
+ const e = n.parentElement;
397
464
  return e === null ? !1 : e.getAttribute("data-content-type") === "numberedListItem" ? {} : !1;
398
465
  },
399
466
  priority: 300,
@@ -401,10 +468,10 @@ const Et = (o) => {
401
468
  }
402
469
  ];
403
470
  },
404
- renderHTML({ HTMLAttributes: o }) {
471
+ renderHTML({ HTMLAttributes: n }) {
405
472
  return [
406
473
  "div",
407
- w(o, {
474
+ x(n, {
408
475
  class: k.blockContent,
409
476
  "data-content-type": this.name
410
477
  }),
@@ -413,7 +480,7 @@ const Et = (o) => {
413
480
  ["p", { class: k.inlineContent }, 0]
414
481
  ];
415
482
  }
416
- }), ge = H({
483
+ }), Ce = P({
417
484
  name: "paragraph",
418
485
  content: "inline*",
419
486
  parseHTML() {
@@ -425,17 +492,17 @@ const Et = (o) => {
425
492
  }
426
493
  ];
427
494
  },
428
- renderHTML({ HTMLAttributes: o }) {
495
+ renderHTML({ HTMLAttributes: n }) {
429
496
  return [
430
497
  "div",
431
- w(o, {
498
+ x(n, {
432
499
  class: k.blockContent,
433
500
  "data-content-type": this.name
434
501
  }),
435
502
  ["p", { class: k.inlineContent }, 0]
436
503
  ];
437
504
  }
438
- }), A = {
505
+ }), N = {
439
506
  backgroundColor: {
440
507
  default: "transparent"
441
508
  },
@@ -447,41 +514,41 @@ const Et = (o) => {
447
514
  default: "left",
448
515
  values: ["left", "center", "right", "justify"]
449
516
  }
450
- }, ke = {
517
+ }, wt = {
451
518
  paragraph: {
452
- propSchema: A,
453
- node: ge
519
+ propSchema: N,
520
+ node: Ce
454
521
  },
455
522
  heading: {
456
523
  propSchema: {
457
- ...A,
524
+ ...N,
458
525
  level: { default: "1", values: ["1", "2", "3"] }
459
526
  },
460
- node: ue
527
+ node: be
461
528
  },
462
529
  bulletListItem: {
463
- propSchema: A,
464
- node: he
530
+ propSchema: N,
531
+ node: ye
465
532
  },
466
533
  numberedListItem: {
467
- propSchema: A,
468
- node: me
534
+ propSchema: N,
535
+ node: Se
469
536
  }
470
537
  };
471
- function ye(o, e = JSON.stringify) {
538
+ function Me(n, e = JSON.stringify) {
472
539
  const t = {};
473
- return o.filter((n) => {
474
- const r = e(n);
540
+ return n.filter((o) => {
541
+ const r = e(o);
475
542
  return Object.prototype.hasOwnProperty.call(t, r) ? !1 : t[r] = !0;
476
543
  });
477
544
  }
478
- function be(o) {
479
- const e = o.filter(
480
- (n, r) => o.indexOf(n) !== r
545
+ function Ee(n) {
546
+ const e = n.filter(
547
+ (o, r) => n.indexOf(o) !== r
481
548
  );
482
- return ye(e);
549
+ return Me(e);
483
550
  }
484
- const K = v.create({
551
+ const U = T.create({
485
552
  name: "uniqueID",
486
553
  // we’ll set a very high priority to make sure this runs first
487
554
  // and is compatible with `appendTransaction` hooks of other extensions
@@ -490,7 +557,7 @@ const K = v.create({
490
557
  return {
491
558
  attributeName: "id",
492
559
  types: [],
493
- generateID: () => window.__TEST_OPTIONS ? (window.__TEST_OPTIONS.mockID === void 0 ? window.__TEST_OPTIONS.mockID = 0 : window.__TEST_OPTIONS.mockID++, window.__TEST_OPTIONS.mockID.toString()) : jt(),
560
+ generateID: () => window.__TEST_OPTIONS ? (window.__TEST_OPTIONS.mockID === void 0 ? window.__TEST_OPTIONS.mockID = 0 : window.__TEST_OPTIONS.mockID++, window.__TEST_OPTIONS.mockID.toString()) : ne(),
494
561
  filterTransaction: null
495
562
  };
496
563
  },
@@ -501,9 +568,9 @@ const K = v.create({
501
568
  attributes: {
502
569
  [this.options.attributeName]: {
503
570
  default: null,
504
- parseHTML: (o) => o.getAttribute(`data-${this.options.attributeName}`),
505
- renderHTML: (o) => ({
506
- [`data-${this.options.attributeName}`]: o[this.options.attributeName]
571
+ parseHTML: (n) => n.getAttribute(`data-${this.options.attributeName}`),
572
+ renderHTML: (n) => ({
573
+ [`data-${this.options.attributeName}`]: n[this.options.attributeName]
507
574
  })
508
575
  }
509
576
  }
@@ -511,69 +578,85 @@ const K = v.create({
511
578
  ];
512
579
  },
513
580
  // check initial content for missing ids
514
- onCreate() {
515
- if (this.editor.extensionManager.extensions.find(
516
- (l) => l.name === "collaboration"
517
- ))
518
- return;
519
- const { view: o, state: e } = this.editor, { tr: t, doc: n } = e, { types: r, attributeName: i, generateID: s } = this.options;
520
- j(n, (l) => r.includes(l.type.name) && l.attrs[i] === null).forEach(({ node: l, pos: d }) => {
521
- t.setNodeMarkup(d, void 0, {
522
- ...l.attrs,
523
- [i]: s()
524
- });
525
- }), t.setMeta("addToHistory", !1), o.dispatch(t);
526
- },
581
+ // onCreate() {
582
+ // // Don’t do this when the collaboration extension is active
583
+ // // because this may update the content, so Y.js tries to merge these changes.
584
+ // // This leads to empty block nodes.
585
+ // // See: https://github.com/ueberdosis/tiptap/issues/2400
586
+ // if (
587
+ // this.editor.extensionManager.extensions.find(
588
+ // (extension) => extension.name === "collaboration"
589
+ // )
590
+ // ) {
591
+ // return;
592
+ // }
593
+ // const { view, state } = this.editor;
594
+ // const { tr, doc } = state;
595
+ // const { types, attributeName, generateID } = this.options;
596
+ // const nodesWithoutId = findChildren(doc, (node) => {
597
+ // return (
598
+ // types.includes(node.type.name) && node.attrs[attributeName] === null
599
+ // );
600
+ // });
601
+ // nodesWithoutId.forEach(({ node, pos }) => {
602
+ // tr.setNodeMarkup(pos, undefined, {
603
+ // ...node.attrs,
604
+ // [attributeName]: generateID(),
605
+ // });
606
+ // });
607
+ // tr.setMeta("addToHistory", false);
608
+ // view.dispatch(tr);
609
+ // },
527
610
  addProseMirrorPlugins() {
528
- let o = null, e = !1;
611
+ let n = null, e = !1;
529
612
  return [
530
- new C({
531
- key: new E("uniqueID"),
532
- appendTransaction: (t, n, r) => {
533
- const i = t.some((m) => m.docChanged) && !n.doc.eq(r.doc), s = this.options.filterTransaction && t.some((m) => {
534
- var b, y;
535
- return !(!((y = (b = this.options).filterTransaction) === null || y === void 0) && y.call(b, m));
613
+ new y({
614
+ key: new S("uniqueID"),
615
+ appendTransaction: (t, o, r) => {
616
+ const i = t.some((m) => m.docChanged) && !o.doc.eq(r.doc), s = this.options.filterTransaction && t.some((m) => {
617
+ var b, v;
618
+ return !(!((v = (b = this.options).filterTransaction) === null || v === void 0) && v.call(b, m));
536
619
  });
537
620
  if (!i || s)
538
621
  return;
539
- const { tr: a } = r, { types: l, attributeName: d, generateID: c } = this.options, u = Ht(
540
- n.doc,
622
+ const { tr: l } = r, { types: a, attributeName: d, generateID: c } = this.options, p = Pt(
623
+ o.doc,
541
624
  t
542
- ), { mapping: p } = u;
543
- if (Ot(u).forEach(({ newRange: m }) => {
625
+ ), { mapping: h } = p;
626
+ if (Ot(p).forEach(({ newRange: m }) => {
544
627
  const b = Dt(
545
628
  r.doc,
546
629
  m,
547
- (M) => l.includes(M.type.name)
548
- ), y = b.map(({ node: M }) => M.attrs[d]).filter((M) => M !== null), U = be(y);
549
- b.forEach(({ node: M, pos: O }) => {
630
+ (C) => a.includes(C.type.name)
631
+ ), v = b.map(({ node: C }) => C.attrs[d]).filter((C) => C !== null), w = Ee(v);
632
+ b.forEach(({ node: C, pos: D }) => {
550
633
  var $;
551
- const Z = ($ = a.doc.nodeAt(O)) === null || $ === void 0 ? void 0 : $.attrs[d];
634
+ const Z = ($ = l.doc.nodeAt(D)) === null || $ === void 0 ? void 0 : $.attrs[d];
552
635
  if (Z === null) {
553
- a.setNodeMarkup(O, void 0, {
554
- ...M.attrs,
636
+ l.setNodeMarkup(D, void 0, {
637
+ ...C.attrs,
555
638
  [d]: c()
556
639
  });
557
640
  return;
558
641
  }
559
- const { deleted: Lt } = p.invert().mapResult(O);
560
- Lt && U.includes(Z) && a.setNodeMarkup(O, void 0, {
561
- ...M.attrs,
642
+ const { deleted: At } = h.invert().mapResult(D);
643
+ At && w.includes(Z) && l.setNodeMarkup(D, void 0, {
644
+ ...C.attrs,
562
645
  [d]: c()
563
646
  });
564
647
  });
565
- }), !!a.steps.length)
566
- return a;
648
+ }), !!l.steps.length)
649
+ return l;
567
650
  },
568
651
  // we register a global drag handler to track the current drag source element
569
652
  view(t) {
570
- const n = (r) => {
653
+ const o = (r) => {
571
654
  var i;
572
- o = !((i = t.dom.parentElement) === null || i === void 0) && i.contains(r.target) ? t.dom.parentElement : null;
655
+ n = !((i = t.dom.parentElement) === null || i === void 0) && i.contains(r.target) ? t.dom.parentElement : null;
573
656
  };
574
- return window.addEventListener("dragstart", n), {
657
+ return window.addEventListener("dragstart", o), {
575
658
  destroy() {
576
- window.removeEventListener("dragstart", n);
659
+ window.removeEventListener("dragstart", o);
577
660
  }
578
661
  };
579
662
  },
@@ -583,9 +666,9 @@ const K = v.create({
583
666
  handleDOMEvents: {
584
667
  // only create new ids for dropped content while holding `alt`
585
668
  // or content is dragged from another editor
586
- drop: (t, n) => {
669
+ drop: (t, o) => {
587
670
  var r;
588
- return (o !== t.dom.parentElement || ((r = n.dataTransfer) === null || r === void 0 ? void 0 : r.effectAllowed) === "copy") && (o = null, e = !0), !1;
671
+ return (n !== t.dom.parentElement || ((r = o.dataTransfer) === null || r === void 0 ? void 0 : r.effectAllowed) === "copy") && (n = null, e = !0), !1;
589
672
  },
590
673
  // always create new ids on pasted content
591
674
  paste: () => (e = !0, !1)
@@ -595,29 +678,29 @@ const K = v.create({
595
678
  transformPasted: (t) => {
596
679
  if (!e)
597
680
  return t;
598
- const { types: n, attributeName: r } = this.options, i = (s) => {
599
- const a = [];
600
- return s.forEach((l) => {
601
- if (l.isText) {
602
- a.push(l);
681
+ const { types: o, attributeName: r } = this.options, i = (s) => {
682
+ const l = [];
683
+ return s.forEach((a) => {
684
+ if (a.isText) {
685
+ l.push(a);
603
686
  return;
604
687
  }
605
- if (!n.includes(l.type.name)) {
606
- a.push(l.copy(i(l.content)));
688
+ if (!o.includes(a.type.name)) {
689
+ l.push(a.copy(i(a.content)));
607
690
  return;
608
691
  }
609
- const d = l.type.create(
692
+ const d = a.type.create(
610
693
  {
611
- ...l.attrs,
694
+ ...a.attrs,
612
695
  [r]: null
613
696
  },
614
- i(l.content),
615
- l.marks
697
+ i(a.content),
698
+ a.marks
616
699
  );
617
- a.push(d);
618
- }), _.from(a);
700
+ l.push(d);
701
+ }), I.from(l);
619
702
  };
620
- return e = !1, new I(
703
+ return e = !1, new B(
621
704
  i(t.content),
622
705
  t.openStart,
623
706
  t.openEnd
@@ -628,93 +711,93 @@ const K = v.create({
628
711
  ];
629
712
  }
630
713
  });
631
- class ve extends Error {
714
+ class Te extends Error {
632
715
  constructor(e) {
633
716
  super(`Unreachable case: ${e}`);
634
717
  }
635
718
  }
636
- const Ct = /* @__PURE__ */ new Set([
719
+ const St = /* @__PURE__ */ new Set([
637
720
  "bold",
638
721
  "italic",
639
722
  "underline",
640
723
  "strike",
641
724
  "code"
642
- ]), Mt = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
643
- function nt(o, e) {
725
+ ]), Ct = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
726
+ function rt(n, e) {
644
727
  const t = [];
645
- for (const [n, r] of Object.entries(o.styles))
646
- Ct.has(n) ? t.push(e.mark(n)) : Mt.has(n) && t.push(e.mark(n, { color: r }));
647
- return o.text.split(/(\n)/g).filter((n) => n.length > 0).map((n) => n === `
648
- ` ? e.nodes.hardBreak.create() : e.text(n, t));
728
+ for (const [o, r] of Object.entries(n.styles))
729
+ St.has(o) ? t.push(e.mark(o)) : Ct.has(o) && t.push(e.mark(o, { color: r }));
730
+ return n.text.split(/(\n)/g).filter((o) => o.length > 0).map((o) => o === `
731
+ ` ? e.nodes.hardBreak.create() : e.text(o, t));
649
732
  }
650
- function Ee(o, e) {
733
+ function Be(n, e) {
651
734
  const t = e.marks.link.create({
652
- href: o.href
735
+ href: n.href
653
736
  });
654
- return Bt(o.content, e).map((n) => {
655
- if (n.type.name === "text")
656
- return n.mark([...n.marks, t]);
657
- if (n.type.name === "hardBreak")
658
- return n;
737
+ return Mt(n.content, e).map((o) => {
738
+ if (o.type.name === "text")
739
+ return o.mark([...o.marks, t]);
740
+ if (o.type.name === "hardBreak")
741
+ return o;
659
742
  throw new Error("unexpected node type");
660
743
  });
661
744
  }
662
- function Bt(o, e) {
745
+ function Mt(n, e) {
663
746
  let t = [];
664
- if (typeof o == "string")
747
+ if (typeof n == "string")
665
748
  return t.push(
666
- ...nt({ type: "text", text: o, styles: {} }, e)
749
+ ...rt({ type: "text", text: n, styles: {} }, e)
667
750
  ), t;
668
- for (const n of o)
669
- t.push(...nt(n, e));
751
+ for (const o of n)
752
+ t.push(...rt(o, e));
670
753
  return t;
671
754
  }
672
- function Tt(o, e) {
755
+ function Et(n, e) {
673
756
  let t = [];
674
- for (const n of o)
675
- if (n.type === "link")
676
- t.push(...Ee(n, e));
677
- else if (n.type === "text")
678
- t.push(...Bt([n], e));
757
+ for (const o of n)
758
+ if (o.type === "link")
759
+ t.push(...Be(o, e));
760
+ else if (o.type === "text")
761
+ t.push(...Mt([o], e));
679
762
  else
680
- throw new ve(n);
763
+ throw new Te(o);
681
764
  return t;
682
765
  }
683
- function z(o, e) {
684
- let t = o.id;
685
- t === void 0 && (t = K.options.generateID());
686
- let n = o.type;
687
- n === void 0 && (n = "paragraph");
766
+ function O(n, e) {
767
+ let t = n.id;
768
+ t === void 0 && (t = U.options.generateID());
769
+ let o = n.type;
770
+ o === void 0 && (o = "paragraph");
688
771
  let r;
689
- if (!o.content)
690
- r = e.nodes[n].create(o.props);
691
- else if (typeof o.content == "string")
692
- r = e.nodes[n].create(
693
- o.props,
694
- e.text(o.content)
772
+ if (!n.content)
773
+ r = e.nodes[o].create(n.props);
774
+ else if (typeof n.content == "string")
775
+ r = e.nodes[o].create(
776
+ n.props,
777
+ e.text(n.content)
695
778
  );
696
779
  else {
697
- const a = Tt(o.content, e);
698
- r = e.nodes[n].create(o.props, a);
780
+ const l = Et(n.content, e);
781
+ r = e.nodes[o].create(n.props, l);
699
782
  }
700
783
  const i = [];
701
- if (o.children)
702
- for (const a of o.children)
703
- i.push(z(a, e));
784
+ if (n.children)
785
+ for (const l of n.children)
786
+ i.push(O(l, e));
704
787
  const s = e.nodes.blockGroup.create({}, i);
705
788
  return e.nodes.blockContainer.create(
706
789
  {
707
790
  id: t,
708
- ...o.props
791
+ ...n.props
709
792
  },
710
793
  i.length > 0 ? [r, s] : r
711
794
  );
712
795
  }
713
- function Ce(o) {
796
+ function xe(n) {
714
797
  const e = [];
715
798
  let t;
716
- return o.content.forEach((n) => {
717
- if (n.type.name === "hardBreak") {
799
+ return n.content.forEach((o) => {
800
+ if (o.type.name === "hardBreak") {
718
801
  t ? t.type === "text" ? t.text += `
719
802
  ` : t.type === "link" && (t.content[t.content.length - 1].text += `
720
803
  `) : t = {
@@ -727,12 +810,12 @@ function Ce(o) {
727
810
  }
728
811
  const r = {};
729
812
  let i;
730
- for (const s of n.marks)
813
+ for (const s of o.marks)
731
814
  if (s.type.name === "link")
732
815
  i = s;
733
- else if (Ct.has(s.type.name))
816
+ else if (St.has(s.type.name))
734
817
  r[s.type.name] = !0;
735
- else if (Mt.has(s.type.name))
818
+ else if (Ct.has(s.type.name))
736
819
  r[s.type.name] = s.attrs.color;
737
820
  else
738
821
  throw Error("Mark is of an unrecognized type: " + s.type.name);
@@ -742,19 +825,19 @@ function Ce(o) {
742
825
  content: [
743
826
  {
744
827
  type: "text",
745
- text: n.textContent,
828
+ text: o.textContent,
746
829
  styles: r
747
830
  }
748
831
  ]
749
- }) : JSON.stringify(t.styles) === JSON.stringify(r) ? t.text += n.textContent : (e.push(t), t = {
832
+ }) : JSON.stringify(t.styles) === JSON.stringify(r) ? t.text += o.textContent : (e.push(t), t = {
750
833
  type: "text",
751
- text: n.textContent,
834
+ text: o.textContent,
752
835
  styles: r
753
836
  }) : t.type === "link" && (i ? t.href === i.attrs.href ? JSON.stringify(
754
837
  t.content[t.content.length - 1].styles
755
- ) === JSON.stringify(r) ? t.content[t.content.length - 1].text += n.textContent : t.content.push({
838
+ ) === JSON.stringify(r) ? t.content[t.content.length - 1].text += o.textContent : t.content.push({
756
839
  type: "text",
757
- text: n.textContent,
840
+ text: o.textContent,
758
841
  styles: r
759
842
  }) : (e.push(t), t = {
760
843
  type: "link",
@@ -762,13 +845,13 @@ function Ce(o) {
762
845
  content: [
763
846
  {
764
847
  type: "text",
765
- text: n.textContent,
848
+ text: o.textContent,
766
849
  styles: r
767
850
  }
768
851
  ]
769
852
  }) : (e.push(t), t = {
770
853
  type: "text",
771
- text: n.textContent,
854
+ text: o.textContent,
772
855
  styles: r
773
856
  })) : i ? t = {
774
857
  type: "link",
@@ -776,271 +859,56 @@ function Ce(o) {
776
859
  content: [
777
860
  {
778
861
  type: "text",
779
- text: n.textContent,
862
+ text: o.textContent,
780
863
  styles: r
781
864
  }
782
865
  ]
783
866
  } : t = {
784
867
  type: "text",
785
- text: n.textContent,
868
+ text: o.textContent,
786
869
  styles: r
787
870
  };
788
871
  }), t && e.push(t), e;
789
872
  }
790
- function B(o, e, t) {
791
- if (o.type.name !== "blockContainer")
873
+ function M(n, e, t) {
874
+ if (n.type.name !== "blockContainer")
792
875
  throw Error(
793
- "Node must be of type blockContainer, but is of type" + o.type.name + "."
876
+ "Node must be of type blockContainer, but is of type" + n.type.name + "."
794
877
  );
795
- const n = t == null ? void 0 : t.get(o);
796
- if (n)
797
- return n;
798
- const r = g(o, 0);
878
+ const o = t == null ? void 0 : t.get(n);
879
+ if (o)
880
+ return o;
881
+ const r = g(n, 0);
799
882
  let i = r.id;
800
- i === null && (i = K.options.generateID());
883
+ i === null && (i = U.options.generateID());
801
884
  const s = {};
802
- for (const [c, u] of Object.entries({
885
+ for (const [c, p] of Object.entries({
803
886
  ...r.node.attrs,
804
887
  ...r.contentNode.attrs
805
888
  })) {
806
- const p = e[r.contentType.name];
807
- if (!p)
889
+ const h = e[r.contentType.name];
890
+ if (!h)
808
891
  throw Error(
809
892
  "Block is of an unrecognized type: " + r.contentType.name
810
893
  );
811
- const f = p.propSchema;
812
- c in f ? s[c] = u : c !== "id" && !(c in A) && console.warn("Block has an unrecognized attribute: " + c);
894
+ const f = h.propSchema;
895
+ c in f ? s[c] = p : c !== "id" && !(c in N) && console.warn("Block has an unrecognized attribute: " + c);
813
896
  }
814
- const a = Ce(r.contentNode), l = [];
897
+ const l = xe(r.contentNode), a = [];
815
898
  for (let c = 0; c < r.numChildBlocks; c++)
816
- l.push(
817
- B(r.node.lastChild.child(c), e, t)
899
+ a.push(
900
+ M(r.node.lastChild.child(c), e, t)
818
901
  );
819
902
  const d = {
820
903
  id: i,
821
904
  type: r.contentType.name,
822
905
  props: s,
823
- content: a,
824
- children: l
825
- };
826
- return t == null || t.set(o, d), d;
827
- }
828
- function J(o, e) {
829
- let t, n;
830
- if (e.firstChild.descendants((r, i) => t ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== o ? !0 : (t = r, n = i + 1, !1)), t === void 0 || n === void 0)
831
- throw Error("Could not find block in the editor with matching ID.");
832
- return {
833
- node: t,
834
- posBeforeNode: n
835
- };
836
- }
837
- function wt(o, e, t = "before", n) {
838
- const r = typeof e == "string" ? e : e.id, i = [];
839
- for (const d of o)
840
- i.push(z(d, n.schema));
841
- let s = -1;
842
- const { node: a, posBeforeNode: l } = J(r, n.state.doc);
843
- if (t === "before" && (s = l), t === "after" && (s = l + a.nodeSize), t === "nested") {
844
- if (a.childCount < 2) {
845
- s = l + a.firstChild.nodeSize + 1;
846
- const d = n.state.schema.nodes.blockGroup.create(
847
- {},
848
- i
849
- );
850
- n.view.dispatch(
851
- n.state.tr.insert(s, d)
852
- );
853
- return;
854
- }
855
- s = l + a.firstChild.nodeSize + 2;
856
- }
857
- n.view.dispatch(n.state.tr.insert(s, i));
858
- }
859
- function Me(o, e, t) {
860
- const n = typeof o == "string" ? o : o.id, { posBeforeNode: r } = J(n, t.state.doc);
861
- t.commands.BNUpdateBlock(r + 1, e);
862
- }
863
- function St(o, e) {
864
- const t = new Set(
865
- o.map(
866
- (r) => typeof r == "string" ? r : r.id
867
- )
868
- );
869
- let n = 0;
870
- if (e.state.doc.descendants((r, i) => {
871
- if (t.size === 0)
872
- return !1;
873
- if (r.type.name !== "blockContainer" || !t.has(r.attrs.id))
874
- return !0;
875
- t.delete(r.attrs.id);
876
- const s = e.state.doc.nodeSize;
877
- e.commands.BNDeleteBlock(i - n + 1);
878
- const a = e.state.doc.nodeSize;
879
- return n += s - a, !1;
880
- }), t.size > 0) {
881
- let r = [...t].join(`
882
- `);
883
- throw Error(
884
- "Blocks with the following IDs could not be found in the editor: " + r
885
- );
886
- }
887
- }
888
- function Be(o, e, t) {
889
- wt(e, o[0], "before", t), St(o, t);
890
- }
891
- function Te() {
892
- const o = (e) => {
893
- let t = e.children.length;
894
- for (let n = 0; n < t; n++) {
895
- const r = e.children[n];
896
- if (r.type === "element" && (o(r), r.tagName === "u"))
897
- if (r.children.length > 0) {
898
- e.children.splice(n, 1, ...r.children);
899
- const i = r.children.length - 1;
900
- t += i, n += i;
901
- } else
902
- e.children.splice(n, 1), t--, n--;
903
- }
904
- };
905
- return o;
906
- }
907
- function we(o) {
908
- const e = /* @__PURE__ */ new Set([
909
- ...o.orderedListItemBlockTypes,
910
- ...o.unorderedListItemBlockTypes
911
- ]), t = (n) => {
912
- let r = n.children.length, i;
913
- for (let s = 0; s < r; s++) {
914
- const l = n.children[s].children[0], d = l.children[0], c = l.children.length === 2 ? l.children[1] : null, u = e.has(
915
- d.properties.dataContentType
916
- ), p = u ? o.orderedListItemBlockTypes.has(
917
- d.properties.dataContentType
918
- ) ? "ol" : "ul" : null;
919
- if (c !== null && t(c), i && i.tagName !== p) {
920
- n.children.splice(
921
- s - i.children.length,
922
- i.children.length,
923
- i
924
- );
925
- const f = i.children.length - 1;
926
- s -= f, r -= f, i = void 0;
927
- }
928
- if (u) {
929
- i || (i = et(
930
- document.createElement(p)
931
- ));
932
- const f = et(
933
- document.createElement("li")
934
- );
935
- f.children.push(d.children[0]), c !== null && f.children.push(...c.children), i.children.push(f);
936
- } else if (c !== null) {
937
- n.children.splice(s + 1, 0, ...c.children), n.children[s] = d.children[0];
938
- const f = c.children.length;
939
- s += f, r += f;
940
- } else
941
- n.children[s] = d.children[0];
942
- }
943
- i && n.children.splice(
944
- r - i.children.length,
945
- i.children.length,
946
- i
947
- );
906
+ content: l,
907
+ children: a
948
908
  };
949
- return t;
950
- }
951
- async function xt(o, e) {
952
- const t = document.createElement("div"), n = q.fromSchema(e);
953
- for (const i of o) {
954
- const s = z(i, e), a = n.serializeNode(s);
955
- t.appendChild(a);
956
- }
957
- return (await V().use(lt, { fragment: !0 }).use(we, {
958
- orderedListItemBlockTypes: /* @__PURE__ */ new Set(["numberedListItem"]),
959
- unorderedListItemBlockTypes: /* @__PURE__ */ new Set(["bulletListItem"])
960
- }).use(dt).process(t.innerHTML)).value;
961
- }
962
- async function It(o, e, t) {
963
- const n = document.createElement("div");
964
- n.innerHTML = o.trim();
965
- const i = Gt.fromSchema(t).parse(n), s = [];
966
- for (let a = 0; a < i.firstChild.childCount; a++)
967
- s.push(B(i.firstChild.child(a), e));
968
- return s;
909
+ return t == null || t.set(n, d), d;
969
910
  }
970
- async function Se(o, e) {
971
- return (await V().use(lt, { fragment: !0 }).use(Te).use(qt).use(ct).use(Vt).process(await xt(o, e))).value;
972
- }
973
- async function xe(o, e, t) {
974
- const n = await V().use(Wt).use(ct).use(Yt).use(dt).process(o);
975
- return It(n.value, e, t);
976
- }
977
- const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4vj2p_35", Le = "_dragPreview_4vj2p_68", P = {
978
- bnEditor: Ie,
979
- bnRoot: _e,
980
- defaultStyles: Pe,
981
- dragPreview: Le,
982
- "collaboration-cursor__caret": "_collaboration-cursor__caret_4vj2p_74",
983
- "collaboration-cursor__label": "_collaboration-cursor__label_4vj2p_85"
984
- }, Ne = v.create({
985
- name: "blockBackgroundColor",
986
- addGlobalAttributes() {
987
- return [
988
- {
989
- types: ["blockContainer"],
990
- attributes: {
991
- backgroundColor: {
992
- default: "default",
993
- parseHTML: (o) => o.hasAttribute("data-background-color") ? o.getAttribute("data-background-color") : "default",
994
- renderHTML: (o) => o.backgroundColor !== "default" && {
995
- "data-background-color": o.backgroundColor
996
- }
997
- }
998
- }
999
- }
1000
- ];
1001
- },
1002
- addCommands() {
1003
- return {
1004
- setBlockBackgroundColor: (o, e) => ({ state: t, view: n }) => {
1005
- const r = g(t.doc, o);
1006
- return r === void 0 ? !1 : (t.tr.setNodeAttribute(
1007
- r.startPos - 1,
1008
- "backgroundColor",
1009
- e
1010
- ), n.focus(), !0);
1011
- }
1012
- };
1013
- }
1014
- }), Ae = st.create({
1015
- name: "backgroundColor",
1016
- addAttributes() {
1017
- return {
1018
- color: {
1019
- default: void 0,
1020
- parseHTML: (o) => o.getAttribute("data-background-color"),
1021
- renderHTML: (o) => ({
1022
- "data-background-color": o.color
1023
- })
1024
- }
1025
- };
1026
- },
1027
- parseHTML() {
1028
- return [
1029
- {
1030
- tag: "span",
1031
- getAttrs: (o) => typeof o == "string" ? !1 : o.hasAttribute("data-background-color") ? { color: o.getAttribute("data-background-color") } : !1
1032
- }
1033
- ];
1034
- },
1035
- renderHTML({ HTMLAttributes: o }) {
1036
- return ["span", o, 0];
1037
- },
1038
- addCommands() {
1039
- return {
1040
- setBackgroundColor: (o) => ({ commands: e }) => o !== "default" ? e.setMark(this.name, { color: o }) : e.unsetMark(this.name)
1041
- };
1042
- }
1043
- }), rt = new E("previous-blocks"), He = {
911
+ const it = new S("previous-blocks"), _e = {
1044
912
  // Numbered List Items
1045
913
  index: "index",
1046
914
  // Headings
@@ -1049,22 +917,22 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1049
917
  type: "type",
1050
918
  depth: "depth",
1051
919
  "depth-change": "depth-change"
1052
- }, Oe = () => {
1053
- let o;
1054
- return new C({
1055
- key: rt,
920
+ }, Ie = () => {
921
+ let n;
922
+ return new y({
923
+ key: it,
1056
924
  view(e) {
1057
925
  return {
1058
- update: async (t, n) => {
926
+ update: async (t, o) => {
1059
927
  var r;
1060
- ((r = this.key) == null ? void 0 : r.getState(t.state).updatedBlocks.size) > 0 && (o = setTimeout(() => {
928
+ ((r = this.key) == null ? void 0 : r.getState(t.state).updatedBlocks.size) > 0 && (n = setTimeout(() => {
1061
929
  t.dispatch(
1062
- t.state.tr.setMeta(rt, { clearUpdate: !0 })
930
+ t.state.tr.setMeta(it, { clearUpdate: !0 })
1063
931
  );
1064
932
  }, 0));
1065
933
  },
1066
934
  destroy: () => {
1067
- o && clearTimeout(o);
935
+ n && clearTimeout(n);
1068
936
  }
1069
937
  };
1070
938
  },
@@ -1079,26 +947,26 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1079
947
  updatedBlocks: /* @__PURE__ */ new Set()
1080
948
  };
1081
949
  },
1082
- apply(e, t, n, r) {
1083
- if (t.currentTransactionOldBlockAttrs = {}, t.updatedBlocks.clear(), !e.docChanged || n.doc.eq(r.doc))
950
+ apply(e, t, o, r) {
951
+ if (t.currentTransactionOldBlockAttrs = {}, t.updatedBlocks.clear(), !e.docChanged || o.doc.eq(r.doc))
1084
952
  return t;
1085
- const i = {}, s = j(n.doc, (d) => d.attrs.id), a = new Map(
953
+ const i = {}, s = Q(o.doc, (d) => d.attrs.id), l = new Map(
1086
954
  s.map((d) => [d.node.attrs.id, d])
1087
- ), l = j(r.doc, (d) => d.attrs.id);
1088
- for (let d of l) {
1089
- const c = a.get(d.node.attrs.id), u = c == null ? void 0 : c.node.firstChild, p = d.node.firstChild;
1090
- if (c && u && p) {
955
+ ), a = Q(r.doc, (d) => d.attrs.id);
956
+ for (let d of a) {
957
+ const c = l.get(d.node.attrs.id), p = c == null ? void 0 : c.node.firstChild, h = d.node.firstChild;
958
+ if (c && p && h) {
1091
959
  const f = {
1092
- index: p.attrs.index,
1093
- level: p.attrs.level,
1094
- type: p.type.name,
960
+ index: h.attrs.index,
961
+ level: h.attrs.level,
962
+ type: h.type.name,
1095
963
  depth: r.doc.resolve(d.pos).depth
1096
964
  };
1097
965
  let m = {
1098
- index: u.attrs.index,
1099
- level: u.attrs.level,
1100
- type: u.type.name,
1101
- depth: n.doc.resolve(c.pos).depth
966
+ index: p.attrs.index,
967
+ level: p.attrs.level,
968
+ type: p.type.name,
969
+ depth: o.doc.resolve(c.pos).depth
1102
970
  };
1103
971
  i[d.node.attrs.id] = m, e.getMeta("numberedListIndexing") && (d.node.attrs.id in t.prevTransactionOldBlockAttrs && (m = t.prevTransactionOldBlockAttrs[d.node.attrs.id]), f.type === "numberedListItem" && (m.index = f.index)), t.currentTransactionOldBlockAttrs[d.node.attrs.id] = m, JSON.stringify(m) !== JSON.stringify(f) && (m["depth-change"] = m.depth - f.depth, t.updatedBlocks.add(d.node.attrs.id));
1104
972
  }
@@ -1111,28 +979,28 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1111
979
  const t = this.getState(e);
1112
980
  if (t.updatedBlocks.size === 0)
1113
981
  return;
1114
- const n = [];
982
+ const o = [];
1115
983
  return e.doc.descendants((r, i) => {
1116
984
  if (!r.attrs.id || !t.updatedBlocks.has(r.attrs.id))
1117
985
  return;
1118
- const s = t.currentTransactionOldBlockAttrs[r.attrs.id], a = {};
986
+ const s = t.currentTransactionOldBlockAttrs[r.attrs.id], l = {};
1119
987
  for (let [d, c] of Object.entries(s))
1120
- a["data-prev-" + He[d]] = c || "none";
1121
- const l = D.node(i, i + r.nodeSize, {
1122
- ...a
988
+ l["data-prev-" + _e[d]] = c || "none";
989
+ const a = R.node(i, i + r.nodeSize, {
990
+ ...l
1123
991
  });
1124
- n.push(l);
1125
- }), F.create(e.doc, n);
992
+ o.push(a);
993
+ }), z.create(e.doc, o);
1126
994
  }
1127
995
  }
1128
996
  });
1129
- }, De = {
997
+ }, He = {
1130
998
  blockColor: "data-block-color",
1131
999
  blockStyle: "data-block-style",
1132
1000
  id: "data-id",
1133
1001
  depth: "data-depth",
1134
1002
  depthChange: "data-depth-change"
1135
- }, Fe = R.create({
1003
+ }, Ae = V.create({
1136
1004
  name: "blockContainer",
1137
1005
  group: "blockContainer",
1138
1006
  // A block always contains content, and optionally a blockGroup which contains nested blocks
@@ -1149,27 +1017,27 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1149
1017
  return [
1150
1018
  {
1151
1019
  tag: "div",
1152
- getAttrs: (o) => {
1153
- if (typeof o == "string")
1020
+ getAttrs: (n) => {
1021
+ if (typeof n == "string")
1154
1022
  return !1;
1155
1023
  const e = {};
1156
- for (let [t, n] of Object.entries(De))
1157
- o.getAttribute(n) && (e[t] = o.getAttribute(n));
1158
- return o.getAttribute("data-node-type") === "blockContainer" ? e : !1;
1024
+ for (let [t, o] of Object.entries(He))
1025
+ n.getAttribute(o) && (e[t] = n.getAttribute(o));
1026
+ return n.getAttribute("data-node-type") === "blockContainer" ? e : !1;
1159
1027
  }
1160
1028
  }
1161
1029
  ];
1162
1030
  },
1163
- renderHTML({ HTMLAttributes: o }) {
1031
+ renderHTML({ HTMLAttributes: n }) {
1164
1032
  return [
1165
1033
  "div",
1166
- w(o, {
1034
+ x(n, {
1167
1035
  class: k.blockOuter,
1168
1036
  "data-node-type": "block-outer"
1169
1037
  }),
1170
1038
  [
1171
1039
  "div",
1172
- w(o, {
1040
+ x(n, {
1173
1041
  // TODO: maybe remove html attributes from inner block
1174
1042
  class: k.block,
1175
1043
  "data-node-type": this.name
@@ -1181,55 +1049,55 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1181
1049
  addCommands() {
1182
1050
  return {
1183
1051
  // Creates a new text block at a given position.
1184
- BNCreateBlock: (o) => ({ state: e, dispatch: t }) => {
1185
- const n = e.schema.nodes.blockContainer.createAndFill();
1186
- return t && e.tr.insert(o, n), !0;
1052
+ BNCreateBlock: (n) => ({ state: e, dispatch: t }) => {
1053
+ const o = e.schema.nodes.blockContainer.createAndFill();
1054
+ return t && e.tr.insert(n, o), !0;
1187
1055
  },
1188
1056
  // Deletes a block at a given position.
1189
- BNDeleteBlock: (o) => ({ state: e, dispatch: t }) => {
1190
- const n = g(e.doc, o);
1191
- if (n === void 0)
1057
+ BNDeleteBlock: (n) => ({ state: e, dispatch: t }) => {
1058
+ const o = g(e.doc, n);
1059
+ if (o === void 0)
1192
1060
  return !1;
1193
- const { startPos: r, endPos: i } = n;
1061
+ const { startPos: r, endPos: i } = o;
1194
1062
  return t && e.tr.deleteRange(r, i), !0;
1195
1063
  },
1196
1064
  // Updates a block at a given position.
1197
- BNUpdateBlock: (o, e) => ({ state: t, dispatch: n }) => {
1198
- const r = g(t.doc, o);
1065
+ BNUpdateBlock: (n, e) => ({ state: t, dispatch: o }) => {
1066
+ const r = g(t.doc, n);
1199
1067
  if (r === void 0)
1200
1068
  return !1;
1201
- const { startPos: i, endPos: s, node: a, contentNode: l } = r;
1202
- if (n) {
1069
+ const { startPos: i, endPos: s, node: l, contentNode: a } = r;
1070
+ if (o) {
1203
1071
  if (e.children !== void 0) {
1204
1072
  const d = [];
1205
1073
  for (const c of e.children)
1206
- d.push(z(c, t.schema));
1207
- a.childCount === 2 ? t.tr.replace(
1208
- i + l.nodeSize + 1,
1074
+ d.push(O(c, t.schema));
1075
+ l.childCount === 2 ? t.tr.replace(
1076
+ i + a.nodeSize + 1,
1209
1077
  s - 1,
1210
- new I(_.from(d), 0, 0)
1078
+ new B(I.from(d), 0, 0)
1211
1079
  ) : t.tr.insert(
1212
- i + l.nodeSize,
1080
+ i + a.nodeSize,
1213
1081
  t.schema.nodes.blockGroup.create({}, d)
1214
1082
  );
1215
1083
  }
1216
1084
  if (e.content !== void 0) {
1217
1085
  let d = [];
1218
- typeof e.content == "string" ? d.push(t.schema.text(e.content)) : d = Tt(e.content, t.schema), t.tr.replace(
1086
+ typeof e.content == "string" ? d.push(t.schema.text(e.content)) : d = Et(e.content, t.schema), t.tr.replace(
1219
1087
  i + 1,
1220
- i + l.nodeSize - 1,
1221
- new I(_.from(d), 0, 0)
1088
+ i + a.nodeSize - 1,
1089
+ new B(I.from(d), 0, 0)
1222
1090
  );
1223
1091
  }
1224
1092
  t.tr.setNodeMarkup(
1225
1093
  i,
1226
1094
  e.type === void 0 ? void 0 : t.schema.nodes[e.type],
1227
1095
  {
1228
- ...l.attrs,
1096
+ ...a.attrs,
1229
1097
  ...e.props
1230
1098
  }
1231
1099
  ), t.tr.setNodeMarkup(i - 1, void 0, {
1232
- ...a.attrs,
1100
+ ...l.attrs,
1233
1101
  ...e.props
1234
1102
  });
1235
1103
  }
@@ -1252,40 +1120,46 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1252
1120
  // Block2Block3
1253
1121
  // Block4
1254
1122
  // Block5
1255
- BNMergeBlocks: (o) => ({ state: e, dispatch: t }) => {
1256
- const n = e.doc.resolve(o + 1).node().type.name === "blockContainer", r = e.doc.resolve(o - 1).node().type.name === "blockContainer";
1257
- if (!n || !r)
1123
+ BNMergeBlocks: (n) => ({ state: e, dispatch: t }) => {
1124
+ const o = e.doc.resolve(n + 1).node().type.name === "blockContainer", r = e.doc.resolve(n - 1).node().type.name === "blockContainer";
1125
+ if (!o || !r)
1258
1126
  return !1;
1259
1127
  const i = g(
1260
1128
  e.doc,
1261
- o + 1
1262
- ), { node: s, contentNode: a, startPos: l, endPos: d, depth: c } = i;
1129
+ n + 1
1130
+ ), { node: s, contentNode: l, startPos: a, endPos: d, depth: c } = i;
1263
1131
  if (s.childCount === 2) {
1264
1132
  const f = e.doc.resolve(
1265
- l + a.nodeSize + 1
1133
+ a + l.nodeSize + 1
1266
1134
  ), m = e.doc.resolve(d - 1), b = f.blockRange(m);
1267
1135
  t && e.tr.lift(b, c - 1);
1268
1136
  }
1269
- let u = o - 1, p = g(e.doc, u);
1270
- for (; p.numChildBlocks > 0; )
1271
- if (u--, p = g(e.doc, u), p === void 0)
1137
+ let p = n - 1, h = g(e.doc, p);
1138
+ for (; h.numChildBlocks > 0; )
1139
+ if (p--, h = g(e.doc, p), h === void 0)
1272
1140
  return !1;
1273
- return t && (e.tr.deleteRange(l, l + a.nodeSize), e.tr.insertText(a.textContent, u - 1), e.tr.setSelection(
1274
- new tt(e.doc.resolve(u - 1))
1141
+ return t && (t(
1142
+ e.tr.deleteRange(a, a + l.nodeSize).replace(
1143
+ p - 1,
1144
+ a,
1145
+ new B(l.content, 0, 0)
1146
+ ).scrollIntoView()
1147
+ ), e.tr.setSelection(
1148
+ new et(e.doc.resolve(p - 1))
1275
1149
  )), !0;
1276
1150
  },
1277
1151
  // Splits a block at a given position. Content after the position is moved to a new block below, at the same
1278
1152
  // nesting level.
1279
- BNSplitBlock: (o, e) => ({ state: t, dispatch: n }) => {
1280
- const r = g(t.doc, o);
1153
+ BNSplitBlock: (n, e) => ({ state: t, dispatch: o }) => {
1154
+ const r = g(t.doc, n);
1281
1155
  if (r === void 0)
1282
1156
  return !1;
1283
- const { contentNode: i, contentType: s, startPos: a, endPos: l, depth: d } = r, c = t.doc.cut(a + 1, o), u = t.doc.cut(o, l - 1), p = t.schema.nodes.blockContainer.createAndFill(), f = l + 1, m = f + 2;
1284
- return n && (t.tr.insert(f, p), t.tr.replace(
1157
+ const { contentNode: i, contentType: s, startPos: l, endPos: a, depth: d } = r, c = t.doc.cut(l + 1, n), p = t.doc.cut(n, a - 1), h = t.schema.nodes.blockContainer.createAndFill(), f = a + 1, m = f + 2;
1158
+ return o && (t.tr.insert(f, h), t.tr.replace(
1285
1159
  m,
1286
1160
  m + 1,
1287
- u.content.size > 0 ? new I(
1288
- _.from(u),
1161
+ p.content.size > 0 ? new B(
1162
+ I.from(p),
1289
1163
  d + 2,
1290
1164
  d + 2
1291
1165
  ) : void 0
@@ -1295,12 +1169,12 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1295
1169
  t.schema.node(s).type,
1296
1170
  i.attrs
1297
1171
  ), t.tr.setSelection(
1298
- new tt(t.doc.resolve(m))
1172
+ new et(t.doc.resolve(m))
1299
1173
  ), t.tr.replace(
1300
- a + 1,
1301
- l - 1,
1302
- c.content.size > 0 ? new I(
1303
- _.from(c),
1174
+ l + 1,
1175
+ a - 1,
1176
+ c.content.size > 0 ? new B(
1177
+ I.from(c),
1304
1178
  d + 2,
1305
1179
  d + 2
1306
1180
  ) : void 0
@@ -1309,7 +1183,7 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1309
1183
  };
1310
1184
  },
1311
1185
  addProseMirrorPlugins() {
1312
- return [Oe()];
1186
+ return [Ie()];
1313
1187
  },
1314
1188
  addKeyboardShortcuts() {
1315
1189
  return {
@@ -1319,59 +1193,59 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1319
1193
  // Undoes an input rule if one was triggered in the last editor state change.
1320
1194
  () => t.undoInputRule(),
1321
1195
  // Reverts block content type to a paragraph if the selection is at the start of the block.
1322
- () => t.command(({ state: n }) => {
1196
+ () => t.command(({ state: o }) => {
1323
1197
  const { contentType: r } = g(
1324
- n.doc,
1325
- n.selection.from
1326
- ), i = n.selection.$anchor.parentOffset === 0, s = r.name === "paragraph";
1327
- return i && !s ? t.BNUpdateBlock(n.selection.from, {
1198
+ o.doc,
1199
+ o.selection.from
1200
+ ), i = o.selection.$anchor.parentOffset === 0, s = r.name === "paragraph";
1201
+ return i && !s ? t.BNUpdateBlock(o.selection.from, {
1328
1202
  type: "paragraph",
1329
1203
  props: {}
1330
1204
  }) : !1;
1331
1205
  }),
1332
1206
  // Removes a level of nesting if the block is indented if the selection is at the start of the block.
1333
- () => t.command(({ state: n }) => n.selection.$anchor.parentOffset === 0 ? t.liftListItem("blockContainer") : !1),
1207
+ () => t.command(({ state: o }) => o.selection.$anchor.parentOffset === 0 ? t.liftListItem("blockContainer") : !1),
1334
1208
  // Merges block with the previous one if it isn't indented, isn't the first block in the doc, and the selection
1335
1209
  // is at the start of the block.
1336
- () => t.command(({ state: n }) => {
1210
+ () => t.command(({ state: o }) => {
1337
1211
  const { depth: r, startPos: i } = g(
1338
- n.doc,
1339
- n.selection.from
1340
- ), s = n.selection.$anchor.parentOffset === 0, a = n.selection.anchor === n.selection.head, l = i === 2, d = i - 1;
1341
- return !l && s && a && r === 2 ? t.BNMergeBlocks(d) : !1;
1212
+ o.doc,
1213
+ o.selection.from
1214
+ ), s = o.selection.$anchor.parentOffset === 0, l = o.selection.anchor === o.selection.head, a = i === 2, d = i - 1;
1215
+ return !a && s && l && r === 2 ? t.BNMergeBlocks(d) : !1;
1342
1216
  })
1343
1217
  ]),
1344
1218
  Enter: () => this.editor.commands.first(({ commands: t }) => [
1345
1219
  // Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
1346
1220
  // of the block.
1347
- () => t.command(({ state: n }) => {
1221
+ () => t.command(({ state: o }) => {
1348
1222
  const { node: r, depth: i } = g(
1349
- n.doc,
1350
- n.selection.from
1351
- ), s = n.selection.$anchor.parentOffset === 0, a = n.selection.anchor === n.selection.head, l = r.textContent.length === 0, d = i > 2;
1352
- return s && a && l && d ? t.liftListItem("blockContainer") : !1;
1223
+ o.doc,
1224
+ o.selection.from
1225
+ ), s = o.selection.$anchor.parentOffset === 0, l = o.selection.anchor === o.selection.head, a = r.textContent.length === 0, d = i > 2;
1226
+ return s && l && a && d ? t.liftListItem("blockContainer") : !1;
1353
1227
  }),
1354
1228
  // Creates a new block and moves the selection to it if the current one is empty, while the selection is also
1355
1229
  // empty & at the start of the block.
1356
- () => t.command(({ state: n, chain: r }) => {
1230
+ () => t.command(({ state: o, chain: r }) => {
1357
1231
  const { node: i, endPos: s } = g(
1358
- n.doc,
1359
- n.selection.from
1360
- ), a = n.selection.$anchor.parentOffset === 0, l = n.selection.anchor === n.selection.head, d = i.textContent.length === 0;
1361
- if (a && l && d) {
1362
- const c = s + 1, u = c + 2;
1363
- return r().BNCreateBlock(c).setTextSelection(u).run(), !0;
1232
+ o.doc,
1233
+ o.selection.from
1234
+ ), l = o.selection.$anchor.parentOffset === 0, a = o.selection.anchor === o.selection.head, d = i.textContent.length === 0;
1235
+ if (l && a && d) {
1236
+ const c = s + 1, p = c + 2;
1237
+ return r().BNCreateBlock(c).setTextSelection(p).run(), !0;
1364
1238
  }
1365
1239
  return !1;
1366
1240
  }),
1367
1241
  // Splits the current block, moving content inside that's after the cursor to a new text block below. Also
1368
1242
  // deletes the selection beforehand, if it's not empty.
1369
- () => t.command(({ state: n, chain: r }) => {
1243
+ () => t.command(({ state: o, chain: r }) => {
1370
1244
  const { node: i } = g(
1371
- n.doc,
1372
- n.selection.from
1245
+ o.doc,
1246
+ o.selection.from
1373
1247
  );
1374
- return i.textContent.length === 0 ? !1 : (r().deleteSelection().BNSplitBlock(n.selection.from, !1).run(), !0);
1248
+ return i.textContent.length === 0 ? !1 : (r().deleteSelection().BNSplitBlock(o.selection.from, !1).run(), !0);
1375
1249
  })
1376
1250
  ]),
1377
1251
  // Always returning true for tab key presses ensures they're not captured by the browser. Otherwise, they blur the
@@ -1409,7 +1283,7 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1409
1283
  })
1410
1284
  };
1411
1285
  }
1412
- }), Re = R.create({
1286
+ }), Le = V.create({
1413
1287
  name: "blockGroup",
1414
1288
  group: "blockGroup",
1415
1289
  content: "blockContainer+",
@@ -1422,30 +1296,30 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1422
1296
  return [
1423
1297
  {
1424
1298
  tag: "div",
1425
- getAttrs: (o) => typeof o == "string" ? !1 : o.getAttribute("data-node-type") === "blockGroup" ? null : !1
1299
+ getAttrs: (n) => typeof n == "string" ? !1 : n.getAttribute("data-node-type") === "blockGroup" ? null : !1
1426
1300
  }
1427
1301
  ];
1428
1302
  },
1429
- renderHTML({ HTMLAttributes: o }) {
1303
+ renderHTML({ HTMLAttributes: n }) {
1430
1304
  return [
1431
1305
  "div",
1432
- w(this.options.HTMLAttributes, o, {
1306
+ x(this.options.HTMLAttributes, n, {
1433
1307
  class: k.blockGroup,
1434
1308
  "data-node-type": "blockGroup"
1435
1309
  }),
1436
1310
  0
1437
1311
  ];
1438
1312
  }
1439
- }), ze = [
1440
- Fe,
1441
- Re,
1442
- R.create({
1313
+ }), Ne = [
1314
+ Ae,
1315
+ Le,
1316
+ V.create({
1443
1317
  name: "doc",
1444
1318
  topNode: !0,
1445
1319
  content: "blockGroup"
1446
1320
  })
1447
- ], Ue = (o) => {
1448
- const e = q.fromSchema(o);
1321
+ ], Pe = (n) => {
1322
+ const e = q.fromSchema(n);
1449
1323
  return new q(
1450
1324
  {
1451
1325
  ...e.nodes
@@ -1456,19 +1330,82 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
1456
1330
  },
1457
1331
  e.marks
1458
1332
  );
1459
- }, $e = v.create({
1333
+ }, Oe = T.create({
1460
1334
  addProseMirrorPlugins() {
1461
1335
  return [
1462
- new C({
1336
+ new y({
1463
1337
  props: {
1464
- clipboardSerializer: Ue(this.editor.schema)
1338
+ clipboardSerializer: Pe(this.editor.schema)
1465
1339
  }
1466
1340
  })
1467
1341
  ];
1468
1342
  }
1469
- }), Ge = Ft(
1470
- (o) => o.type.name === "blockContainer"
1343
+ });
1344
+ class F {
1345
+ constructor() {
1346
+ u(this, "callbacks", {});
1347
+ }
1348
+ on(e, t) {
1349
+ return this.callbacks[e] || (this.callbacks[e] = []), this.callbacks[e].push(t), () => this.off(e, t);
1350
+ }
1351
+ emit(e, ...t) {
1352
+ const o = this.callbacks[e];
1353
+ o && o.forEach((r) => r.apply(this, t));
1354
+ }
1355
+ off(e, t) {
1356
+ const o = this.callbacks[e];
1357
+ o && (t ? this.callbacks[e] = o.filter((r) => r !== t) : delete this.callbacks[e]);
1358
+ }
1359
+ removeAllListeners() {
1360
+ this.callbacks = {};
1361
+ }
1362
+ }
1363
+ const De = Rt(
1364
+ (n) => n.type.name === "blockContainer"
1471
1365
  );
1366
+ class Re {
1367
+ constructor(e, t, o = () => {
1368
+ }) {
1369
+ u(this, "suggestionsMenuState");
1370
+ u(this, "updateSuggestionsMenu");
1371
+ u(this, "pluginState");
1372
+ u(this, "handleScroll", () => {
1373
+ var e;
1374
+ if ((e = this.suggestionsMenuState) != null && e.show) {
1375
+ const t = document.querySelector(
1376
+ `[data-decoration-id="${this.pluginState.decorationId}"]`
1377
+ );
1378
+ this.suggestionsMenuState.referencePos = t.getBoundingClientRect(), this.updateSuggestionsMenu();
1379
+ }
1380
+ });
1381
+ this.editor = e, this.pluginKey = t, this.pluginState = W(), this.updateSuggestionsMenu = () => {
1382
+ if (!this.suggestionsMenuState)
1383
+ throw new Error("Attempting to update uninitialized suggestions menu");
1384
+ o(this.suggestionsMenuState);
1385
+ }, document.addEventListener("scroll", this.handleScroll);
1386
+ }
1387
+ update(e, t) {
1388
+ const o = this.pluginKey.getState(t), r = this.pluginKey.getState(e.state), i = !o.active && r.active, s = o.active && !r.active, l = o.active && r.active;
1389
+ if (!i && !l && !s)
1390
+ return;
1391
+ if (this.pluginState = s ? o : r, s || !this.editor.isEditable) {
1392
+ this.suggestionsMenuState.show = !1, this.updateSuggestionsMenu();
1393
+ return;
1394
+ }
1395
+ const a = document.querySelector(
1396
+ `[data-decoration-id="${this.pluginState.decorationId}"]`
1397
+ );
1398
+ this.editor.isEditable && (this.suggestionsMenuState = {
1399
+ show: !0,
1400
+ referencePos: a.getBoundingClientRect(),
1401
+ filteredItems: this.pluginState.items,
1402
+ keyboardHoveredItemIndex: this.pluginState.keyboardHoveredItemIndex
1403
+ }, this.updateSuggestionsMenu());
1404
+ }
1405
+ destroy() {
1406
+ document.removeEventListener("scroll", this.handleScroll);
1407
+ }
1408
+ }
1472
1409
  function W() {
1473
1410
  return {
1474
1411
  active: !1,
@@ -1480,260 +1417,862 @@ function W() {
1480
1417
  decorationId: void 0
1481
1418
  };
1482
1419
  }
1483
- class je {
1484
- constructor({
1485
- editor: e,
1486
- pluginKey: t,
1487
- onSelectItem: n = () => {
1488
- },
1489
- suggestionsMenuFactory: r
1490
- }) {
1491
- h(this, "editor");
1492
- h(this, "pluginKey");
1493
- h(this, "suggestionsMenu");
1494
- h(this, "pluginState");
1495
- h(this, "itemCallback");
1496
- h(this, "handleScroll", () => {
1497
- this.pluginKey.getState(this.editor._tiptapEditor.state).active && this.suggestionsMenu.render(this.getDynamicParams(), !1);
1498
- });
1499
- this.editor = e, this.pluginKey = t, this.pluginState = W(), this.itemCallback = (i) => {
1500
- e._tiptapEditor.chain().focus().deleteRange({
1501
- from: this.pluginState.queryStartPos - this.pluginState.triggerCharacter.length,
1502
- to: e._tiptapEditor.state.selection.from
1503
- }).run(), n({
1504
- item: i,
1505
- editor: e
1506
- });
1507
- }, this.suggestionsMenu = r(this.getStaticParams()), document.addEventListener("scroll", this.handleScroll);
1508
- }
1509
- update(e, t) {
1510
- const n = this.pluginKey.getState(t), r = this.pluginKey.getState(e.state), i = !n.active && r.active, s = n.active && !r.active, a = n.active && r.active;
1511
- !i && !a && !s || (this.pluginState = s ? n : r, (s || !this.editor.isEditable) && (this.suggestionsMenu.hide(), this.suggestionsMenu.element.removeEventListener(
1512
- "mousedown",
1513
- (l) => l.preventDefault()
1514
- )), a && this.suggestionsMenu.render(this.getDynamicParams(), !1), i && this.editor.isEditable && (this.suggestionsMenu.render(this.getDynamicParams(), !0), this.suggestionsMenu.element.addEventListener(
1515
- "mousedown",
1516
- (l) => l.preventDefault()
1517
- )));
1518
- }
1519
- destroy() {
1520
- document.removeEventListener("scroll", this.handleScroll);
1521
- }
1522
- getStaticParams() {
1523
- return {
1524
- itemCallback: (e) => this.itemCallback(e)
1525
- };
1526
- }
1527
- getDynamicParams() {
1528
- const e = document.querySelector(
1529
- `[data-decoration-id="${this.pluginState.decorationId}"]`
1530
- );
1531
- return {
1532
- items: this.pluginState.items,
1533
- keyboardHoveredItemIndex: this.pluginState.keyboardHoveredItemIndex,
1534
- referenceRect: e.getBoundingClientRect()
1535
- };
1536
- }
1537
- }
1538
- function qe({
1539
- pluginKey: o,
1540
- editor: e,
1541
- defaultTriggerCharacter: t,
1542
- suggestionsMenuFactory: n,
1543
- onSelectItem: r = () => {
1544
- },
1545
- items: i = () => []
1546
- }) {
1547
- if (t.length !== 1)
1420
+ const ze = (n, e, t, o, r = () => [], i = () => {
1421
+ }) => {
1422
+ if (o.length !== 1)
1548
1423
  throw new Error("'char' should be a single character");
1549
- const s = (a) => {
1550
- a.dispatch(a.state.tr.setMeta(o, { deactivate: !0 }));
1424
+ let s;
1425
+ const l = (a) => {
1426
+ a.dispatch(a.state.tr.setMeta(t, { deactivate: !0 }));
1551
1427
  };
1552
- return new C({
1553
- key: o,
1554
- view: (a) => new je({
1555
- editor: e,
1556
- pluginKey: o,
1557
- onSelectItem: (l) => {
1558
- s(a), r(l);
1559
- },
1560
- suggestionsMenuFactory: n
1561
- }),
1562
- state: {
1563
- // Initialize the plugin's internal state.
1564
- init() {
1565
- return W();
1566
- },
1567
- // Apply changes to the plugin state from an editor transaction.
1568
- apply(a, l, d, c) {
1569
- var p, f, m, b;
1570
- if (a.getMeta("orderedListIndexing") !== void 0)
1571
- return l;
1572
- if ((p = a.getMeta(o)) != null && p.activate)
1573
- return {
1574
- active: !0,
1575
- triggerCharacter: ((f = a.getMeta(o)) == null ? void 0 : f.triggerCharacter) || "",
1576
- queryStartPos: c.selection.from,
1577
- items: i(""),
1578
- keyboardHoveredItemIndex: 0,
1579
- // TODO: Maybe should be 1 if the menu has no possible items? Probably redundant since a menu with no items
1580
- // is useless in practice.
1581
- notFoundCount: 0,
1582
- decorationId: `id_${Math.floor(Math.random() * 4294967295)}`
1583
- };
1584
- if (!l.active)
1585
- return l;
1586
- const u = { ...l };
1587
- if (u.items = i(
1588
- c.doc.textBetween(l.queryStartPos, c.selection.from)
1589
- ), u.notFoundCount = 0, u.items.length === 0 && (u.notFoundCount = Math.max(
1590
- 0,
1591
- l.notFoundCount + (c.selection.from - d.selection.from)
1592
- )), // Highlighting text should hide the menu.
1593
- c.selection.from !== c.selection.to || // Transactions with plugin metadata {deactivate: true} should hide the menu.
1594
- (m = a.getMeta(o)) != null && m.deactivate || // Certain mouse events should hide the menu.
1595
- // TODO: Change to global mousedown listener.
1596
- a.getMeta("focus") || a.getMeta("blur") || a.getMeta("pointer") || // Moving the caret before the character which triggered the menu should hide it.
1597
- l.active && c.selection.from < l.queryStartPos || // Entering more than 3 characters, after the last query that matched with at least 1 menu item, should hide
1598
- // the menu.
1599
- u.notFoundCount > 3)
1428
+ return {
1429
+ plugin: new y({
1430
+ key: t,
1431
+ view: () => (s = new Re(
1432
+ n,
1433
+ t,
1434
+ e
1435
+ ), s),
1436
+ state: {
1437
+ // Initialize the plugin's internal state.
1438
+ init() {
1600
1439
  return W();
1601
- if (((b = a.getMeta(o)) == null ? void 0 : b.selectedItemIndexChanged) !== void 0) {
1602
- let y = a.getMeta(o).selectedItemIndexChanged;
1603
- y < 0 ? y = l.items.length - 1 : y >= l.items.length && (y = 0), u.keyboardHoveredItemIndex = y;
1440
+ },
1441
+ // Apply changes to the plugin state from an editor transaction.
1442
+ apply(a, d, c, p) {
1443
+ var f, m, b, v;
1444
+ if (a.getMeta("orderedListIndexing") !== void 0)
1445
+ return d;
1446
+ if ((f = a.getMeta(t)) != null && f.activate)
1447
+ return {
1448
+ active: !0,
1449
+ triggerCharacter: ((m = a.getMeta(t)) == null ? void 0 : m.triggerCharacter) || "",
1450
+ queryStartPos: p.selection.from,
1451
+ items: r(""),
1452
+ keyboardHoveredItemIndex: 0,
1453
+ // TODO: Maybe should be 1 if the menu has no possible items? Probably redundant since a menu with no items
1454
+ // is useless in practice.
1455
+ notFoundCount: 0,
1456
+ decorationId: `id_${Math.floor(Math.random() * 4294967295)}`
1457
+ };
1458
+ if (!d.active)
1459
+ return d;
1460
+ const h = { ...d };
1461
+ if (h.items = r(
1462
+ p.doc.textBetween(
1463
+ d.queryStartPos,
1464
+ p.selection.from
1465
+ )
1466
+ ), h.notFoundCount = 0, h.items.length === 0 && (h.notFoundCount = Math.max(
1467
+ 0,
1468
+ d.notFoundCount + (p.selection.from - c.selection.from)
1469
+ )), // Highlighting text should hide the menu.
1470
+ p.selection.from !== p.selection.to || // Transactions with plugin metadata {deactivate: true} should hide the menu.
1471
+ (b = a.getMeta(t)) != null && b.deactivate || // Certain mouse events should hide the menu.
1472
+ // TODO: Change to global mousedown listener.
1473
+ a.getMeta("focus") || a.getMeta("blur") || a.getMeta("pointer") || // Moving the caret before the character which triggered the menu should hide it.
1474
+ d.active && p.selection.from < d.queryStartPos || // Entering more than 3 characters, after the last query that matched with at least 1 menu item, should hide
1475
+ // the menu.
1476
+ h.notFoundCount > 3)
1477
+ return W();
1478
+ if (((v = a.getMeta(t)) == null ? void 0 : v.selectedItemIndexChanged) !== void 0) {
1479
+ let w = a.getMeta(t).selectedItemIndexChanged;
1480
+ w < 0 ? w = d.items.length - 1 : w >= d.items.length && (w = 0), h.keyboardHoveredItemIndex = w;
1481
+ } else
1482
+ c.selection.from !== p.selection.from && (h.keyboardHoveredItemIndex = 0);
1483
+ return h;
1604
1484
  }
1605
- return u;
1606
- }
1607
- },
1608
- props: {
1609
- handleKeyDown(a, l) {
1610
- const d = this.getState(a.state).active;
1611
- if (l.key === t && !d)
1612
- return a.dispatch(
1613
- a.state.tr.insertText(t).scrollIntoView().setMeta(o, {
1614
- activate: !0,
1615
- triggerCharacter: t
1616
- })
1617
- ), !0;
1618
- if (!d)
1619
- return !1;
1620
- const {
1621
- triggerCharacter: c,
1622
- queryStartPos: u,
1623
- items: p,
1624
- keyboardHoveredItemIndex: f
1625
- } = o.getState(a.state);
1626
- return l.key === "ArrowUp" ? (a.dispatch(
1627
- a.state.tr.setMeta(o, {
1628
- selectedItemIndexChanged: f - 1
1629
- })
1630
- ), !0) : l.key === "ArrowDown" ? (a.dispatch(
1631
- a.state.tr.setMeta(o, {
1632
- selectedItemIndexChanged: f + 1
1633
- })
1634
- ), !0) : l.key === "Enter" ? (s(a), e._tiptapEditor.chain().focus().deleteRange({
1635
- from: u - c.length,
1636
- to: e._tiptapEditor.state.selection.from
1637
- }).run(), r({
1638
- item: p[f],
1639
- editor: e
1640
- }), !0) : l.key === "Escape" ? (s(a), !0) : !1;
1641
- },
1642
- // Hides menu in cases where mouse click does not cause an editor state change.
1643
- handleClick(a) {
1644
- s(a);
1645
1485
  },
1646
- // Setup decorator on the currently active suggestion.
1647
- decorations(a) {
1648
- const { active: l, decorationId: d, queryStartPos: c, triggerCharacter: u } = this.getState(a);
1649
- if (!l)
1650
- return null;
1651
- if (u === "") {
1652
- const p = Ge(a.selection);
1653
- if (p)
1654
- return F.create(a.doc, [
1655
- D.node(
1656
- p.pos,
1657
- p.pos + p.node.nodeSize,
1658
- {
1659
- nodeName: "span",
1660
- class: "suggestion-decorator",
1661
- "data-decoration-id": d
1662
- }
1663
- )
1664
- ]);
1486
+ props: {
1487
+ handleKeyDown(a, d) {
1488
+ const c = this.getState(a.state).active;
1489
+ if (d.key === o && !c)
1490
+ return a.dispatch(
1491
+ a.state.tr.insertText(o).scrollIntoView().setMeta(t, {
1492
+ activate: !0,
1493
+ triggerCharacter: o
1494
+ })
1495
+ ), !0;
1496
+ if (!c)
1497
+ return !1;
1498
+ const {
1499
+ triggerCharacter: p,
1500
+ queryStartPos: h,
1501
+ items: f,
1502
+ keyboardHoveredItemIndex: m
1503
+ } = t.getState(a.state);
1504
+ return d.key === "ArrowUp" ? (a.dispatch(
1505
+ a.state.tr.setMeta(t, {
1506
+ selectedItemIndexChanged: m - 1
1507
+ })
1508
+ ), !0) : d.key === "ArrowDown" ? (a.dispatch(
1509
+ a.state.tr.setMeta(t, {
1510
+ selectedItemIndexChanged: m + 1
1511
+ })
1512
+ ), !0) : d.key === "Enter" ? (l(a), n._tiptapEditor.chain().focus().deleteRange({
1513
+ from: h - p.length,
1514
+ to: n._tiptapEditor.state.selection.from
1515
+ }).run(), i({
1516
+ item: f[m],
1517
+ editor: n
1518
+ }), !0) : d.key === "Escape" ? (l(a), !0) : !1;
1519
+ },
1520
+ // Setup decorator on the currently active suggestion.
1521
+ decorations(a) {
1522
+ const { active: d, decorationId: c, queryStartPos: p, triggerCharacter: h } = this.getState(a);
1523
+ if (!d)
1524
+ return null;
1525
+ if (h === "") {
1526
+ const f = De(a.selection);
1527
+ if (f)
1528
+ return z.create(a.doc, [
1529
+ R.node(
1530
+ f.pos,
1531
+ f.pos + f.node.nodeSize,
1532
+ {
1533
+ nodeName: "span",
1534
+ class: "suggestion-decorator",
1535
+ "data-decoration-id": c
1536
+ }
1537
+ )
1538
+ ]);
1539
+ }
1540
+ return z.create(a.doc, [
1541
+ R.inline(
1542
+ p - h.length,
1543
+ p,
1544
+ {
1545
+ nodeName: "span",
1546
+ class: "suggestion-decorator",
1547
+ "data-decoration-id": c
1548
+ }
1549
+ )
1550
+ ]);
1665
1551
  }
1666
- return F.create(a.doc, [
1667
- D.inline(
1668
- c - u.length,
1669
- c,
1670
- {
1671
- nodeName: "span",
1672
- class: "suggestion-decorator",
1673
- "data-decoration-id": d
1674
- }
1675
- )
1676
- ]);
1677
1552
  }
1553
+ }),
1554
+ itemCallback: (a) => {
1555
+ l(n._tiptapEditor.view), n._tiptapEditor.chain().focus().deleteRange({
1556
+ from: s.pluginState.queryStartPos - s.pluginState.triggerCharacter.length,
1557
+ to: n._tiptapEditor.state.selection.from
1558
+ }).run(), i({
1559
+ item: a,
1560
+ editor: n
1561
+ });
1678
1562
  }
1679
- });
1563
+ };
1564
+ }, K = new S("SlashMenuPlugin");
1565
+ class Ve extends F {
1566
+ constructor(t, o) {
1567
+ super();
1568
+ u(this, "plugin");
1569
+ u(this, "itemCallback");
1570
+ const r = ze(
1571
+ t,
1572
+ (i) => {
1573
+ this.emit("update", i);
1574
+ },
1575
+ K,
1576
+ "/",
1577
+ (i) => o.filter(
1578
+ ({ name: s, aliases: l }) => s.toLowerCase().startsWith(i.toLowerCase()) || l && l.filter(
1579
+ (a) => a.toLowerCase().startsWith(i.toLowerCase())
1580
+ ).length !== 0
1581
+ ),
1582
+ ({ item: i, editor: s }) => i.execute(s)
1583
+ );
1584
+ this.plugin = r.plugin, this.itemCallback = r.itemCallback;
1585
+ }
1586
+ onUpdate(t) {
1587
+ return this.on("update", t);
1588
+ }
1680
1589
  }
1681
- const X = new E("suggestions-slash-commands"), We = () => v.create({
1682
- name: "slash-command",
1590
+ const Ue = new S("blocknote-placeholder"), Fe = T.create({
1591
+ name: "placeholder",
1683
1592
  addOptions() {
1684
1593
  return {
1685
- editor: void 0,
1686
- commands: void 0,
1687
- slashMenuFactory: void 0
1594
+ emptyEditorClass: "is-editor-empty",
1595
+ emptyNodeClass: "is-empty",
1596
+ isFilterClass: "is-filter",
1597
+ hasAnchorClass: "has-anchor",
1598
+ placeholder: "Write something …",
1599
+ showOnlyWhenEditable: !0,
1600
+ showOnlyCurrent: !0,
1601
+ includeChildren: !1
1688
1602
  };
1689
1603
  },
1690
1604
  addProseMirrorPlugins() {
1691
- if (!this.options.slashMenuFactory || !this.options.commands)
1692
- throw new Error("required args not defined for SlashMenuExtension");
1693
- const o = this.options.commands;
1694
1605
  return [
1695
- qe({
1696
- pluginKey: X,
1697
- editor: this.options.editor,
1698
- defaultTriggerCharacter: "/",
1699
- suggestionsMenuFactory: this.options.slashMenuFactory,
1700
- items: (e) => o.filter(
1701
- (t) => t.match(e)
1702
- ),
1703
- onSelectItem: ({ item: e, editor: t }) => {
1704
- e.execute(t);
1606
+ new y({
1607
+ key: Ue,
1608
+ props: {
1609
+ decorations: (n) => {
1610
+ const { doc: e, selection: t } = n, o = K.getState(n), r = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: i } = t, s = [];
1611
+ if (r)
1612
+ return e.descendants((l, a) => {
1613
+ const d = i >= a && i <= a + l.nodeSize, c = !l.isLeaf && !l.childCount;
1614
+ if ((d || !this.options.showOnlyCurrent) && c) {
1615
+ const p = [this.options.emptyNodeClass];
1616
+ this.editor.isEmpty && p.push(this.options.emptyEditorClass), d && p.push(this.options.hasAnchorClass), (o == null ? void 0 : o.triggerCharacter) === "" && (o != null && o.active) && p.push(this.options.isFilterClass);
1617
+ const h = R.node(a, a + l.nodeSize, {
1618
+ class: p.join(" ")
1619
+ });
1620
+ s.push(h);
1621
+ }
1622
+ return this.options.includeChildren;
1623
+ }), z.create(e, s);
1624
+ }
1705
1625
  }
1706
1626
  })
1707
1627
  ];
1708
1628
  }
1709
- });
1710
- class L extends G {
1711
- constructor(t, n) {
1712
- super(t, n);
1713
- h(this, "nodes");
1629
+ }), $e = T.create({
1630
+ name: "textAlignment",
1631
+ addGlobalAttributes() {
1632
+ return [
1633
+ {
1634
+ // Attribute is applied to block content instead of container so that child blocks don't inherit the text
1635
+ // alignment styling.
1636
+ types: ["paragraph", "heading", "bulletListItem", "numberedListItem"],
1637
+ attributes: {
1638
+ textAlignment: {
1639
+ default: "left",
1640
+ parseHTML: (n) => n.getAttribute("data-text-alignment"),
1641
+ renderHTML: (n) => n.textAlignment !== "left" && {
1642
+ "data-text-alignment": n.textAlignment
1643
+ }
1644
+ }
1645
+ }
1646
+ }
1647
+ ];
1648
+ },
1649
+ addCommands() {
1650
+ return {
1651
+ setTextAlignment: (n) => ({ state: e }) => {
1652
+ const t = [], o = g(
1653
+ e.doc,
1654
+ e.selection.from
1655
+ );
1656
+ if (o === void 0)
1657
+ return !1;
1658
+ let r = o.startPos;
1659
+ for (; r < e.selection.to; )
1660
+ e.doc.resolve(r).node().type.spec.group === "blockContent" ? (t.push(r - 1), r += e.doc.resolve(r).node().nodeSize - 1) : r += 1;
1661
+ for (const i of t)
1662
+ e.tr.setNodeAttribute(i, "textAlignment", n);
1663
+ return !0;
1664
+ }
1665
+ };
1666
+ }
1667
+ }), Ge = T.create({
1668
+ name: "blockTextColor",
1669
+ addGlobalAttributes() {
1670
+ return [
1671
+ {
1672
+ types: ["blockContainer"],
1673
+ attributes: {
1674
+ textColor: {
1675
+ default: "default",
1676
+ parseHTML: (n) => n.hasAttribute("data-text-color") ? n.getAttribute("data-text-color") : "default",
1677
+ renderHTML: (n) => n.textColor !== "default" && {
1678
+ "data-text-color": n.textColor
1679
+ }
1680
+ }
1681
+ }
1682
+ }
1683
+ ];
1684
+ },
1685
+ addCommands() {
1686
+ return {
1687
+ setBlockTextColor: (n, e) => ({ state: t, view: o }) => {
1688
+ const r = g(t.doc, n);
1689
+ return r === void 0 ? !1 : (t.tr.setNodeAttribute(r.startPos - 1, "textColor", e), o.focus(), !0);
1690
+ }
1691
+ };
1692
+ }
1693
+ }), je = at.create({
1694
+ name: "textColor",
1695
+ addAttributes() {
1696
+ return {
1697
+ color: {
1698
+ default: void 0,
1699
+ parseHTML: (n) => n.getAttribute("data-text-color"),
1700
+ renderHTML: (n) => ({
1701
+ "data-text-color": n.color
1702
+ })
1703
+ }
1704
+ };
1705
+ },
1706
+ parseHTML() {
1707
+ return [
1708
+ {
1709
+ tag: "span",
1710
+ getAttrs: (n) => typeof n == "string" ? !1 : n.hasAttribute("data-text-color") ? { color: n.getAttribute("data-text-color") } : !1
1711
+ }
1712
+ ];
1713
+ },
1714
+ renderHTML({ HTMLAttributes: n }) {
1715
+ return ["span", n, 0];
1716
+ },
1717
+ addCommands() {
1718
+ return {
1719
+ setTextColor: (n) => ({ commands: e }) => n !== "default" ? e.setMark(this.name, { color: n }) : e.unsetMark(this.name)
1720
+ };
1721
+ }
1722
+ }), qe = T.create({
1723
+ name: "trailingNode",
1724
+ addProseMirrorPlugins() {
1725
+ const n = new S(this.name);
1726
+ return [
1727
+ new y({
1728
+ key: n,
1729
+ appendTransaction: (e, t, o) => {
1730
+ const { doc: r, tr: i, schema: s } = o, l = n.getState(o), a = r.content.size - 2, d = s.nodes.blockContainer, c = s.nodes.paragraph;
1731
+ if (l)
1732
+ return i.insert(
1733
+ a,
1734
+ d.create(void 0, c.create())
1735
+ );
1736
+ },
1737
+ state: {
1738
+ init: (e, t) => {
1739
+ },
1740
+ apply: (e, t) => {
1741
+ if (!e.docChanged)
1742
+ return t;
1743
+ let o = e.doc.lastChild;
1744
+ if (!o || o.type.name !== "blockGroup")
1745
+ throw new Error("Expected blockGroup");
1746
+ if (o = o.lastChild, !o || o.type.name !== "blockContainer")
1747
+ throw new Error("Expected blockContainer");
1748
+ return o.nodeSize > 4;
1749
+ }
1750
+ }
1751
+ })
1752
+ ];
1753
+ }
1754
+ }), We = (n) => {
1755
+ const e = [
1756
+ L.ClipboardTextSerializer,
1757
+ L.Commands,
1758
+ L.Editable,
1759
+ L.FocusEvents,
1760
+ L.Tabindex,
1761
+ // DevTools,
1762
+ Wt,
1763
+ // DropCursor,
1764
+ Fe.configure({
1765
+ emptyNodeClass: k.isEmpty,
1766
+ hasAnchorClass: k.hasAnchor,
1767
+ isFilterClass: k.isFilter,
1768
+ includeChildren: !0,
1769
+ showOnlyCurrent: !1
1770
+ }),
1771
+ U.configure({
1772
+ types: ["blockContainer"]
1773
+ }),
1774
+ Yt,
1775
+ // Comments,
1776
+ // basics:
1777
+ Qt,
1778
+ // marks:
1779
+ Ft,
1780
+ $t,
1781
+ Kt,
1782
+ Zt,
1783
+ te,
1784
+ Xt,
1785
+ je,
1786
+ Ge,
1787
+ fe,
1788
+ he,
1789
+ $e,
1790
+ // custom blocks:
1791
+ ...Ne,
1792
+ ...Object.values(n.blockSchema).map(
1793
+ (t) => t.node.configure({ editor: n.editor })
1794
+ ),
1795
+ Oe,
1796
+ qt.configure({ width: 5, color: "#ddeeff" }),
1797
+ // This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
1798
+ // should be handled before Enter handlers in other components like splitListItem
1799
+ qe
1800
+ ];
1801
+ if (n.collaboration) {
1802
+ e.push(
1803
+ Gt.configure({
1804
+ fragment: n.collaboration.fragment
1805
+ })
1806
+ );
1807
+ const t = (o) => {
1808
+ const r = document.createElement("span");
1809
+ r.classList.add(H["collaboration-cursor__caret"]), r.setAttribute("style", `border-color: ${o.color}`);
1810
+ const i = document.createElement("span");
1811
+ i.classList.add(H["collaboration-cursor__label"]), i.setAttribute("style", `background-color: ${o.color}`), i.insertBefore(document.createTextNode(o.name), null);
1812
+ const s = document.createTextNode("⁠"), l = document.createTextNode("⁠");
1813
+ return r.insertBefore(s, null), r.insertBefore(i, null), r.insertBefore(l, null), r;
1814
+ };
1815
+ e.push(
1816
+ jt.configure({
1817
+ user: n.collaboration.user,
1818
+ render: n.collaboration.renderCursor || t,
1819
+ provider: n.collaboration.provider
1820
+ })
1821
+ );
1822
+ } else
1823
+ e.push(Jt);
1824
+ return e;
1825
+ };
1826
+ function X(n, e) {
1827
+ let t, o;
1828
+ if (e.firstChild.descendants((r, i) => t ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== n ? !0 : (t = r, o = i + 1, !1)), t === void 0 || o === void 0)
1829
+ throw Error("Could not find block in the editor with matching ID.");
1830
+ return {
1831
+ node: t,
1832
+ posBeforeNode: o
1833
+ };
1834
+ }
1835
+ function Tt(n, e, t = "before", o) {
1836
+ const r = typeof e == "string" ? e : e.id, i = [];
1837
+ for (const d of n)
1838
+ i.push(O(d, o.schema));
1839
+ let s = -1;
1840
+ const { node: l, posBeforeNode: a } = X(r, o.state.doc);
1841
+ if (t === "before" && (s = a), t === "after" && (s = a + l.nodeSize), t === "nested") {
1842
+ if (l.childCount < 2) {
1843
+ s = a + l.firstChild.nodeSize + 1;
1844
+ const d = o.state.schema.nodes.blockGroup.create(
1845
+ {},
1846
+ i
1847
+ );
1848
+ o.view.dispatch(
1849
+ o.state.tr.insert(s, d)
1850
+ );
1851
+ return;
1852
+ }
1853
+ s = a + l.firstChild.nodeSize + 2;
1854
+ }
1855
+ o.view.dispatch(o.state.tr.insert(s, i));
1856
+ }
1857
+ function Ye(n, e, t) {
1858
+ const o = typeof n == "string" ? n : n.id, { posBeforeNode: r } = X(o, t.state.doc);
1859
+ t.commands.BNUpdateBlock(r + 1, e);
1860
+ }
1861
+ function Bt(n, e) {
1862
+ const t = new Set(
1863
+ n.map(
1864
+ (r) => typeof r == "string" ? r : r.id
1865
+ )
1866
+ );
1867
+ let o = 0;
1868
+ if (e.state.doc.descendants((r, i) => {
1869
+ if (t.size === 0)
1870
+ return !1;
1871
+ if (r.type.name !== "blockContainer" || !t.has(r.attrs.id))
1872
+ return !0;
1873
+ t.delete(r.attrs.id);
1874
+ const s = e.state.doc.nodeSize;
1875
+ e.commands.BNDeleteBlock(i - o + 1);
1876
+ const l = e.state.doc.nodeSize;
1877
+ return o += s - l, !1;
1878
+ }), t.size > 0) {
1879
+ let r = [...t].join(`
1880
+ `);
1881
+ throw Error(
1882
+ "Blocks with the following IDs could not be found in the editor: " + r
1883
+ );
1884
+ }
1885
+ }
1886
+ function Je(n, e, t) {
1887
+ Tt(e, n[0], "before", t), Bt(n, t);
1888
+ }
1889
+ function Ke() {
1890
+ const n = (e) => {
1891
+ let t = e.children.length;
1892
+ for (let o = 0; o < t; o++) {
1893
+ const r = e.children[o];
1894
+ if (r.type === "element" && (n(r), r.tagName === "u"))
1895
+ if (r.children.length > 0) {
1896
+ e.children.splice(o, 1, ...r.children);
1897
+ const i = r.children.length - 1;
1898
+ t += i, o += i;
1899
+ } else
1900
+ e.children.splice(o, 1), t--, o--;
1901
+ }
1902
+ };
1903
+ return n;
1904
+ }
1905
+ function Xe(n) {
1906
+ const e = /* @__PURE__ */ new Set([
1907
+ ...n.orderedListItemBlockTypes,
1908
+ ...n.unorderedListItemBlockTypes
1909
+ ]), t = (o) => {
1910
+ let r = o.children.length, i;
1911
+ for (let s = 0; s < r; s++) {
1912
+ const a = o.children[s].children[0], d = a.children[0], c = a.children.length === 2 ? a.children[1] : null, p = e.has(
1913
+ d.properties.dataContentType
1914
+ ), h = p ? n.orderedListItemBlockTypes.has(
1915
+ d.properties.dataContentType
1916
+ ) ? "ol" : "ul" : null;
1917
+ if (c !== null && t(c), i && i.tagName !== h) {
1918
+ o.children.splice(
1919
+ s - i.children.length,
1920
+ i.children.length,
1921
+ i
1922
+ );
1923
+ const f = i.children.length - 1;
1924
+ s -= f, r -= f, i = void 0;
1925
+ }
1926
+ if (p) {
1927
+ i || (i = ot(
1928
+ document.createElement(h)
1929
+ ));
1930
+ const f = ot(
1931
+ document.createElement("li")
1932
+ );
1933
+ f.children.push(d.children[0]), c !== null && f.children.push(...c.children), i.children.push(f);
1934
+ } else if (c !== null) {
1935
+ o.children.splice(s + 1, 0, ...c.children), o.children[s] = d.children[0];
1936
+ const f = c.children.length;
1937
+ s += f, r += f;
1938
+ } else
1939
+ o.children[s] = d.children[0];
1940
+ }
1941
+ i && o.children.splice(
1942
+ r - i.children.length,
1943
+ i.children.length,
1944
+ i
1945
+ );
1946
+ };
1947
+ return t;
1948
+ }
1949
+ async function xt(n, e) {
1950
+ const t = document.createElement("div"), o = q.fromSchema(e);
1951
+ for (const i of n) {
1952
+ const s = O(i, e), l = o.serializeNode(s);
1953
+ t.appendChild(l);
1954
+ }
1955
+ return (await J().use(lt, { fragment: !0 }).use(Xe, {
1956
+ orderedListItemBlockTypes: /* @__PURE__ */ new Set(["numberedListItem"]),
1957
+ unorderedListItemBlockTypes: /* @__PURE__ */ new Set(["bulletListItem"])
1958
+ }).use(dt).process(t.innerHTML)).value;
1959
+ }
1960
+ async function _t(n, e, t) {
1961
+ const o = document.createElement("div");
1962
+ o.innerHTML = n.trim();
1963
+ const i = ee.fromSchema(t).parse(o), s = [];
1964
+ for (let l = 0; l < i.firstChild.childCount; l++)
1965
+ s.push(M(i.firstChild.child(l), e));
1966
+ return s;
1967
+ }
1968
+ async function Ze(n, e) {
1969
+ return (await J().use(lt, { fragment: !0 }).use(Ke).use(ie).use(ct).use(le).process(await xt(n, e))).value;
1970
+ }
1971
+ async function Qe(n, e, t) {
1972
+ const o = await J().use(se).use(ct).use(ae).use(dt).process(n);
1973
+ return _t(o.value, e, t);
1974
+ }
1975
+ class to {
1976
+ constructor(e, t, o) {
1977
+ u(this, "formattingToolbarState");
1978
+ u(this, "updateFormattingToolbar");
1979
+ u(this, "preventHide", !1);
1980
+ u(this, "preventShow", !1);
1981
+ u(this, "prevWasEditable", null);
1982
+ u(this, "shouldShow", ({ view: e, state: t, from: o, to: r }) => {
1983
+ const { doc: i, selection: s } = t, { empty: l } = s, a = !i.textBetween(o, r).length && zt(t.selection);
1984
+ return !(!e.hasFocus() || l || a);
1985
+ });
1986
+ u(this, "viewMousedownHandler", () => {
1987
+ this.preventShow = !0;
1988
+ });
1989
+ u(this, "viewMouseupHandler", () => {
1990
+ this.preventShow = !1, setTimeout(() => this.update(this.pmView));
1991
+ });
1992
+ // For dragging the whole editor.
1993
+ u(this, "dragstartHandler", () => {
1994
+ var e;
1995
+ (e = this.formattingToolbarState) != null && e.show && (this.formattingToolbarState.show = !1, this.updateFormattingToolbar());
1996
+ });
1997
+ u(this, "focusHandler", () => {
1998
+ setTimeout(() => this.update(this.pmView));
1999
+ });
2000
+ u(this, "blurHandler", (e) => {
2001
+ var o;
2002
+ if (this.preventHide) {
2003
+ this.preventHide = !1;
2004
+ return;
2005
+ }
2006
+ const t = this.pmView.dom.parentElement;
2007
+ // An element is clicked.
2008
+ e && e.relatedTarget && // Element is inside the editor.
2009
+ (t === e.relatedTarget || t.contains(e.relatedTarget)) || (o = this.formattingToolbarState) != null && o.show && (this.formattingToolbarState.show = !1, this.updateFormattingToolbar());
2010
+ });
2011
+ u(this, "scrollHandler", () => {
2012
+ var e;
2013
+ (e = this.formattingToolbarState) != null && e.show && (this.formattingToolbarState.referencePos = this.getSelectionBoundingBox(), this.updateFormattingToolbar());
2014
+ });
2015
+ this.editor = e, this.pmView = t, this.updateFormattingToolbar = () => {
2016
+ if (!this.formattingToolbarState)
2017
+ throw new Error(
2018
+ "Attempting to update uninitialized formatting toolbar"
2019
+ );
2020
+ o(this.formattingToolbarState);
2021
+ }, t.dom.addEventListener("mousedown", this.viewMousedownHandler), t.dom.addEventListener("mouseup", this.viewMouseupHandler), t.dom.addEventListener("dragstart", this.dragstartHandler), t.dom.addEventListener("focus", this.focusHandler), t.dom.addEventListener("blur", this.blurHandler), document.addEventListener("scroll", this.scrollHandler);
2022
+ }
2023
+ update(e, t) {
2024
+ var h, f;
2025
+ const { state: o, composing: r } = e, { doc: i, selection: s } = o, l = t && t.doc.eq(i) && t.selection.eq(s);
2026
+ if ((this.prevWasEditable === null || this.prevWasEditable === this.editor.isEditable) && (r || l))
2027
+ return;
2028
+ this.prevWasEditable = this.editor.isEditable;
2029
+ const { ranges: a } = s, d = Math.min(...a.map((m) => m.$from.pos)), c = Math.max(...a.map((m) => m.$to.pos)), p = (h = this.shouldShow) == null ? void 0 : h.call(this, {
2030
+ view: e,
2031
+ state: o,
2032
+ from: d,
2033
+ to: c
2034
+ });
2035
+ if (this.editor.isEditable && !this.preventShow && (p || this.preventHide)) {
2036
+ this.formattingToolbarState = {
2037
+ show: !0,
2038
+ referencePos: this.getSelectionBoundingBox()
2039
+ }, this.updateFormattingToolbar();
2040
+ return;
2041
+ }
2042
+ if ((f = this.formattingToolbarState) != null && f.show && !this.preventHide && (!p || this.preventShow || !this.editor.isEditable)) {
2043
+ this.formattingToolbarState.show = !1, this.updateFormattingToolbar();
2044
+ return;
2045
+ }
2046
+ }
2047
+ destroy() {
2048
+ this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.pmView.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.pmView.dom.removeEventListener("dragstart", this.dragstartHandler), this.pmView.dom.removeEventListener("focus", this.focusHandler), this.pmView.dom.removeEventListener("blur", this.blurHandler), document.removeEventListener("scroll", this.scrollHandler);
2049
+ }
2050
+ getSelectionBoundingBox() {
2051
+ const { state: e } = this.pmView, { selection: t } = e, { ranges: o } = t, r = Math.min(...o.map((s) => s.$from.pos)), i = Math.max(...o.map((s) => s.$to.pos));
2052
+ if (Vt(t)) {
2053
+ const s = this.pmView.nodeDOM(r);
2054
+ if (s)
2055
+ return s.getBoundingClientRect();
2056
+ }
2057
+ return j(this.pmView, r, i);
2058
+ }
2059
+ }
2060
+ const eo = new S(
2061
+ "FormattingToolbarPlugin"
2062
+ );
2063
+ class oo extends F {
2064
+ constructor(t) {
2065
+ super();
2066
+ u(this, "view");
2067
+ u(this, "plugin");
2068
+ this.plugin = new y({
2069
+ key: eo,
2070
+ view: (o) => (this.view = new to(t, o, (r) => {
2071
+ this.emit("update", r);
2072
+ }), this.view)
2073
+ });
2074
+ }
2075
+ onUpdate(t) {
2076
+ return this.on("update", t);
2077
+ }
2078
+ }
2079
+ class no {
2080
+ constructor(e, t, o) {
2081
+ u(this, "hyperlinkToolbarState");
2082
+ u(this, "updateHyperlinkToolbar");
2083
+ u(this, "menuUpdateTimer");
2084
+ u(this, "startMenuUpdateTimer");
2085
+ u(this, "stopMenuUpdateTimer");
2086
+ u(this, "mouseHoveredHyperlinkMark");
2087
+ u(this, "mouseHoveredHyperlinkMarkRange");
2088
+ u(this, "keyboardHoveredHyperlinkMark");
2089
+ u(this, "keyboardHoveredHyperlinkMarkRange");
2090
+ u(this, "hyperlinkMark");
2091
+ u(this, "hyperlinkMarkRange");
2092
+ u(this, "mouseOverHandler", (e) => {
2093
+ if (this.mouseHoveredHyperlinkMark = void 0, this.mouseHoveredHyperlinkMarkRange = void 0, this.stopMenuUpdateTimer(), e.target instanceof HTMLAnchorElement && e.target.nodeName === "A") {
2094
+ const t = e.target, o = this.pmView.posAtDOM(t, 0) + 1, r = this.pmView.state.doc.resolve(
2095
+ o
2096
+ ), i = r.marks();
2097
+ for (const s of i)
2098
+ if (s.type.name === this.pmView.state.schema.mark("link").type.name) {
2099
+ this.mouseHoveredHyperlinkMark = s, this.mouseHoveredHyperlinkMarkRange = tt(
2100
+ r,
2101
+ s.type,
2102
+ s.attrs
2103
+ ) || void 0;
2104
+ break;
2105
+ }
2106
+ }
2107
+ return this.startMenuUpdateTimer(), !1;
2108
+ });
2109
+ u(this, "clickHandler", (e) => {
2110
+ var o;
2111
+ const t = this.pmView.dom.parentElement;
2112
+ // Toolbar is open.
2113
+ this.hyperlinkMark && // An element is clicked.
2114
+ e && e.target && // The clicked element is not the editor.
2115
+ !(t === e.target || t.contains(e.target)) && (o = this.hyperlinkToolbarState) != null && o.show && (this.hyperlinkToolbarState.show = !1, this.updateHyperlinkToolbar());
2116
+ });
2117
+ u(this, "scrollHandler", () => {
2118
+ var e;
2119
+ this.hyperlinkMark !== void 0 && (e = this.hyperlinkToolbarState) != null && e.show && (this.hyperlinkToolbarState.referencePos = j(
2120
+ this.pmView,
2121
+ this.hyperlinkMarkRange.from,
2122
+ this.hyperlinkMarkRange.to
2123
+ ), this.updateHyperlinkToolbar());
2124
+ });
2125
+ this.editor = e, this.pmView = t, this.updateHyperlinkToolbar = () => {
2126
+ if (!this.hyperlinkToolbarState)
2127
+ throw new Error("Attempting to update uninitialized hyperlink toolbar");
2128
+ o(this.hyperlinkToolbarState);
2129
+ }, this.startMenuUpdateTimer = () => {
2130
+ this.menuUpdateTimer = setTimeout(() => {
2131
+ this.update();
2132
+ }, 250);
2133
+ }, this.stopMenuUpdateTimer = () => (this.menuUpdateTimer && (clearTimeout(this.menuUpdateTimer), this.menuUpdateTimer = void 0), !1), this.pmView.dom.addEventListener("mouseover", this.mouseOverHandler), document.addEventListener("click", this.clickHandler, !0), document.addEventListener("scroll", this.scrollHandler);
2134
+ }
2135
+ editHyperlink(e, t) {
2136
+ var r;
2137
+ const o = this.pmView.state.tr.insertText(
2138
+ t,
2139
+ this.hyperlinkMarkRange.from,
2140
+ this.hyperlinkMarkRange.to
2141
+ );
2142
+ o.addMark(
2143
+ this.hyperlinkMarkRange.from,
2144
+ this.hyperlinkMarkRange.from + t.length,
2145
+ this.pmView.state.schema.mark("link", { href: e })
2146
+ ), this.pmView.dispatch(o), this.pmView.focus(), (r = this.hyperlinkToolbarState) != null && r.show && (this.hyperlinkToolbarState.show = !1, this.updateHyperlinkToolbar());
2147
+ }
2148
+ deleteHyperlink() {
2149
+ var e;
2150
+ this.pmView.dispatch(
2151
+ this.pmView.state.tr.removeMark(
2152
+ this.hyperlinkMarkRange.from,
2153
+ this.hyperlinkMarkRange.to,
2154
+ this.hyperlinkMark.type
2155
+ ).setMeta("preventAutolink", !0)
2156
+ ), this.pmView.focus(), (e = this.hyperlinkToolbarState) != null && e.show && (this.hyperlinkToolbarState.show = !1, this.updateHyperlinkToolbar());
2157
+ }
2158
+ update() {
2159
+ var t;
2160
+ if (!this.pmView.hasFocus())
2161
+ return;
2162
+ const e = this.hyperlinkMark;
2163
+ if (this.hyperlinkMark = void 0, this.hyperlinkMarkRange = void 0, this.keyboardHoveredHyperlinkMark = void 0, this.keyboardHoveredHyperlinkMarkRange = void 0, this.pmView.state.selection.empty) {
2164
+ const o = this.pmView.state.selection.$from.marks();
2165
+ for (const r of o)
2166
+ if (r.type.name === this.pmView.state.schema.mark("link").type.name) {
2167
+ this.keyboardHoveredHyperlinkMark = r, this.keyboardHoveredHyperlinkMarkRange = tt(
2168
+ this.pmView.state.selection.$from,
2169
+ r.type,
2170
+ r.attrs
2171
+ ) || void 0;
2172
+ break;
2173
+ }
2174
+ }
2175
+ if (this.mouseHoveredHyperlinkMark && (this.hyperlinkMark = this.mouseHoveredHyperlinkMark, this.hyperlinkMarkRange = this.mouseHoveredHyperlinkMarkRange), this.keyboardHoveredHyperlinkMark && (this.hyperlinkMark = this.keyboardHoveredHyperlinkMark, this.hyperlinkMarkRange = this.keyboardHoveredHyperlinkMarkRange), this.hyperlinkMark && this.editor.isEditable) {
2176
+ this.hyperlinkToolbarState = {
2177
+ show: !0,
2178
+ referencePos: j(
2179
+ this.pmView,
2180
+ this.hyperlinkMarkRange.from,
2181
+ this.hyperlinkMarkRange.to
2182
+ ),
2183
+ url: this.hyperlinkMark.attrs.href,
2184
+ text: this.pmView.state.doc.textBetween(
2185
+ this.hyperlinkMarkRange.from,
2186
+ this.hyperlinkMarkRange.to
2187
+ )
2188
+ }, this.updateHyperlinkToolbar();
2189
+ return;
2190
+ }
2191
+ if ((t = this.hyperlinkToolbarState) != null && t.show && e && (!this.hyperlinkMark || !this.editor.isEditable)) {
2192
+ this.hyperlinkToolbarState.show = !1, this.updateHyperlinkToolbar();
2193
+ return;
2194
+ }
2195
+ }
2196
+ destroy() {
2197
+ this.pmView.dom.removeEventListener("mouseover", this.mouseOverHandler), document.removeEventListener("scroll", this.scrollHandler), document.removeEventListener("click", this.clickHandler, !0);
2198
+ }
2199
+ }
2200
+ const ro = new S(
2201
+ "HyperlinkToolbarPlugin"
2202
+ );
2203
+ class io extends F {
2204
+ constructor(t) {
2205
+ super();
2206
+ u(this, "view");
2207
+ u(this, "plugin");
2208
+ /**
2209
+ * Edit the currently hovered hyperlink.
2210
+ */
2211
+ u(this, "editHyperlink", (t, o) => {
2212
+ this.view.editHyperlink(t, o);
2213
+ });
2214
+ /**
2215
+ * Delete the currently hovered hyperlink.
2216
+ */
2217
+ u(this, "deleteHyperlink", () => {
2218
+ this.view.deleteHyperlink();
2219
+ });
2220
+ /**
2221
+ * When hovering on/off hyperlinks using the mouse cursor, the hyperlink
2222
+ * toolbar will open & close with a delay.
2223
+ *
2224
+ * This function starts the delay timer, and should be used for when the mouse cursor enters the hyperlink toolbar.
2225
+ */
2226
+ u(this, "startHideTimer", () => {
2227
+ this.view.startMenuUpdateTimer();
2228
+ });
2229
+ /**
2230
+ * When hovering on/off hyperlinks using the mouse cursor, the hyperlink
2231
+ * toolbar will open & close with a delay.
2232
+ *
2233
+ * This function stops the delay timer, and should be used for when the mouse cursor exits the hyperlink toolbar.
2234
+ */
2235
+ u(this, "stopHideTimer", () => {
2236
+ this.view.stopMenuUpdateTimer();
2237
+ });
2238
+ this.plugin = new y({
2239
+ key: ro,
2240
+ view: (o) => (this.view = new no(t, o, (r) => {
2241
+ this.emit("update", r);
2242
+ }), this.view)
2243
+ });
2244
+ }
2245
+ onUpdate(t) {
2246
+ return this.on("update", t);
2247
+ }
2248
+ }
2249
+ class A extends G {
2250
+ constructor(t, o) {
2251
+ super(t, o);
2252
+ u(this, "nodes");
1714
2253
  const r = t.node();
1715
- this.nodes = [], t.doc.nodesBetween(t.pos, n.pos, (i, s, a) => {
1716
- if (a !== null && a.eq(r))
2254
+ this.nodes = [], t.doc.nodesBetween(t.pos, o.pos, (i, s, l) => {
2255
+ if (l !== null && l.eq(r))
1717
2256
  return this.nodes.push(i), !1;
1718
2257
  });
1719
2258
  }
1720
- static create(t, n, r = n) {
1721
- return new L(t.resolve(n), t.resolve(r));
2259
+ static create(t, o, r = o) {
2260
+ return new A(t.resolve(o), t.resolve(r));
1722
2261
  }
1723
2262
  content() {
1724
- return new I(_.from(this.nodes), 0, 0);
2263
+ return new B(I.from(this.nodes), 0, 0);
1725
2264
  }
1726
2265
  eq(t) {
1727
- if (!(t instanceof L) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to)
2266
+ if (!(t instanceof A) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to)
1728
2267
  return !1;
1729
- for (let n = 0; n < this.nodes.length; n++)
1730
- if (!this.nodes[n].eq(t.nodes[n]))
2268
+ for (let o = 0; o < this.nodes.length; o++)
2269
+ if (!this.nodes[o].eq(t.nodes[o]))
1731
2270
  return !1;
1732
2271
  return !0;
1733
2272
  }
1734
- map(t, n) {
1735
- let r = n.mapResult(this.from), i = n.mapResult(this.to);
1736
- return i.deleted ? G.near(t.resolve(r.pos)) : r.deleted ? G.near(t.resolve(i.pos)) : new L(
2273
+ map(t, o) {
2274
+ let r = o.mapResult(this.from), i = o.mapResult(this.to);
2275
+ return i.deleted ? G.near(t.resolve(r.pos)) : r.deleted ? G.near(t.resolve(i.pos)) : new A(
1737
2276
  t.resolve(r.pos),
1738
2277
  t.resolve(i.pos)
1739
2278
  );
@@ -1742,107 +2281,100 @@ class L extends G {
1742
2281
  return { type: "node", anchor: this.anchor, head: this.head };
1743
2282
  }
1744
2283
  }
1745
- const Ye = ae.__serializeForClipboard;
1746
- let T;
1747
- function _t(o, e) {
2284
+ const so = re.__serializeForClipboard;
2285
+ let E;
2286
+ function It(n, e) {
1748
2287
  var r;
1749
2288
  if (!e.dom.isConnected)
1750
2289
  return;
1751
- let t = e.posAtCoords(o);
2290
+ let t = e.posAtCoords(n);
1752
2291
  if (!t)
1753
2292
  return;
1754
- let n = e.domAtPos(t.pos).node;
1755
- if (n !== e.dom) {
1756
- for (; n && n.parentNode && n.parentNode !== e.dom && !((r = n.hasAttribute) != null && r.call(n, "data-id")); )
1757
- n = n.parentNode;
1758
- if (n)
1759
- return { node: n, id: n.getAttribute("data-id") };
2293
+ let o = e.domAtPos(t.pos).node;
2294
+ if (o !== e.dom) {
2295
+ for (; o && o.parentNode && o.parentNode !== e.dom && !((r = o.hasAttribute) != null && r.call(o, "data-id")); )
2296
+ o = o.parentNode;
2297
+ if (o)
2298
+ return { node: o, id: o.getAttribute("data-id") };
1760
2299
  }
1761
2300
  }
1762
- function Ve(o, e) {
1763
- let t = _t(o, e);
2301
+ function ao(n, e) {
2302
+ let t = It(n, e);
1764
2303
  if (t && t.node.nodeType === 1) {
1765
- const n = e.docView;
1766
- let r = n.nearestDesc(t.node, !0);
1767
- return !r || r === n ? null : r.posBefore;
2304
+ const o = e.docView;
2305
+ let r = o.nearestDesc(t.node, !0);
2306
+ return !r || r === o ? null : r.posBefore;
1768
2307
  }
1769
2308
  return null;
1770
2309
  }
1771
- function Ke(o, e) {
1772
- let t, n;
1773
- const r = e.resolve(o.from).node().type.spec.group === "blockContent", i = e.resolve(o.to).node().type.spec.group === "blockContent", s = Math.min(o.$anchor.depth, o.$head.depth);
2310
+ function lo(n, e) {
2311
+ let t, o;
2312
+ const r = e.resolve(n.from).node().type.spec.group === "blockContent", i = e.resolve(n.to).node().type.spec.group === "blockContent", s = Math.min(n.$anchor.depth, n.$head.depth);
1774
2313
  if (r && i) {
1775
- const a = o.$from.start(s - 1), l = o.$to.end(s - 1);
1776
- t = e.resolve(a - 1).pos, n = e.resolve(l + 1).pos;
2314
+ const l = n.$from.start(s - 1), a = n.$to.end(s - 1);
2315
+ t = e.resolve(l - 1).pos, o = e.resolve(a + 1).pos;
1777
2316
  } else
1778
- t = o.from, n = o.to;
1779
- return { from: t, to: n };
2317
+ t = n.from, o = n.to;
2318
+ return { from: t, to: o };
1780
2319
  }
1781
- function it(o, e, t = e) {
1782
- e === t && (t += o.state.doc.resolve(e + 1).node().nodeSize);
1783
- const n = o.domAtPos(e).node.cloneNode(!0), r = o.domAtPos(e).node, i = (c, u) => Array.prototype.indexOf.call(c.children, u), s = i(
2320
+ function st(n, e, t = e) {
2321
+ e === t && (t += n.state.doc.resolve(e + 1).node().nodeSize);
2322
+ const o = n.domAtPos(e).node.cloneNode(!0), r = n.domAtPos(e).node, i = (c, p) => Array.prototype.indexOf.call(c.children, p), s = i(
1784
2323
  r,
1785
2324
  // Expects from position to be just before the first selected block.
1786
- o.domAtPos(e + 1).node.parentElement
1787
- ), a = i(
2325
+ n.domAtPos(e + 1).node.parentElement
2326
+ ), l = i(
1788
2327
  r,
1789
2328
  // Expects to position to be just after the last selected block.
1790
- o.domAtPos(t - 1).node.parentElement
2329
+ n.domAtPos(t - 1).node.parentElement
1791
2330
  );
1792
2331
  for (let c = r.childElementCount - 1; c >= 0; c--)
1793
- (c > a || c < s) && n.removeChild(n.children[c]);
1794
- Pt(), T = n;
1795
- const d = o.dom.className.split(" ").filter(
2332
+ (c > l || c < s) && o.removeChild(o.children[c]);
2333
+ Ht(), E = o;
2334
+ const d = n.dom.className.split(" ").filter(
1796
2335
  (c) => !c.includes("bn") && !c.includes("ProseMirror") && !c.includes("editor")
1797
2336
  ).join(" ");
1798
- T.className = T.className + " " + P.dragPreview + " " + d, document.body.appendChild(T);
2337
+ E.className = E.className + " " + H.dragPreview + " " + d, document.body.appendChild(E);
1799
2338
  }
1800
- function Pt() {
1801
- T !== void 0 && (document.body.removeChild(T), T = void 0);
2339
+ function Ht() {
2340
+ E !== void 0 && (document.body.removeChild(E), E = void 0);
1802
2341
  }
1803
- function Je(o, e) {
1804
- if (!o.dataTransfer)
2342
+ function co(n, e) {
2343
+ if (!n.dataTransfer)
1805
2344
  return;
1806
2345
  const t = e.dom.getBoundingClientRect();
1807
- let n = {
2346
+ let o = {
1808
2347
  left: t.left + t.width / 2,
1809
2348
  // take middle of editor
1810
- top: o.clientY
1811
- }, r = Ve(n, e);
2349
+ top: n.clientY
2350
+ }, r = ao(o, e);
1812
2351
  if (r != null) {
1813
- const i = e.state.selection, s = e.state.doc, { from: a, to: l } = Ke(i, s), d = a <= r && r < l, c = i.$anchor.node() !== i.$head.node() || i instanceof L;
2352
+ const i = e.state.selection, s = e.state.doc, { from: l, to: a } = lo(i, s), d = l <= r && r < a, c = i.$anchor.node() !== i.$head.node() || i instanceof A;
1814
2353
  d && c ? (e.dispatch(
1815
- e.state.tr.setSelection(L.create(s, a, l))
1816
- ), it(e, a, l)) : (e.dispatch(
1817
- e.state.tr.setSelection($t.create(e.state.doc, r))
1818
- ), it(e, r));
1819
- let u = e.state.selection.content(), { dom: p, text: f } = Ye(e, u);
1820
- o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", p.innerHTML), o.dataTransfer.setData("text/plain", f), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(T, 0, 0), e.dragging = { slice: u, move: !0 };
2354
+ e.state.tr.setSelection(A.create(s, l, a))
2355
+ ), st(e, l, a)) : (e.dispatch(
2356
+ e.state.tr.setSelection(oe.create(e.state.doc, r))
2357
+ ), st(e, r));
2358
+ let p = e.state.selection.content(), { dom: h, text: f } = so(e, p);
2359
+ n.dataTransfer.clearData(), n.dataTransfer.setData("text/html", h.innerHTML), n.dataTransfer.setData("text/plain", f), n.dataTransfer.effectAllowed = "move", n.dataTransfer.setDragImage(E, 0, 0), e.dragging = { slice: p, move: !0 };
1821
2360
  }
1822
2361
  }
1823
- class Xe {
1824
- constructor({
1825
- tiptapEditor: e,
1826
- editor: t,
1827
- blockMenuFactory: n,
1828
- horizontalPosAnchoredAtRoot: r
1829
- }) {
1830
- h(this, "editor");
1831
- h(this, "ttEditor");
2362
+ class uo {
2363
+ constructor(e, t, o) {
2364
+ u(this, "sideMenuState");
1832
2365
  // When true, the drag handle with be anchored at the same level as root elements
1833
2366
  // When false, the drag handle with be just to the left of the element
1834
- h(this, "horizontalPosAnchoredAtRoot");
1835
- h(this, "horizontalPosAnchor");
1836
- h(this, "blockMenu");
1837
- h(this, "hoveredBlock");
2367
+ // TODO: Is there any case where we want this to be false?
2368
+ u(this, "horizontalPosAnchoredAtRoot");
2369
+ u(this, "horizontalPosAnchor");
2370
+ u(this, "hoveredBlock");
1838
2371
  // Used to check if currently dragged content comes from this editor instance.
1839
- h(this, "isDragging", !1);
1840
- h(this, "menuOpen", !1);
1841
- h(this, "menuFrozen", !1);
2372
+ u(this, "isDragging", !1);
2373
+ u(this, "menuFrozen", !1);
1842
2374
  /**
1843
2375
  * Sets isDragging when dragging text.
1844
2376
  */
1845
- h(this, "onDragStart", () => {
2377
+ u(this, "onDragStart", () => {
1846
2378
  this.isDragging = !0;
1847
2379
  });
1848
2380
  /**
@@ -1850,16 +2382,16 @@ class Xe {
1850
2382
  * we dispatch a fake event, so that we can still drop the content
1851
2383
  * when dragging / dropping to the side of the editor
1852
2384
  */
1853
- h(this, "onDrop", (e) => {
1854
- if (e.synthetic || !this.isDragging)
2385
+ u(this, "onDrop", (e) => {
2386
+ if (this.editor._tiptapEditor.commands.blur(), e.synthetic || !this.isDragging)
1855
2387
  return;
1856
- let t = this.ttEditor.view.posAtCoords({
2388
+ let t = this.pmView.posAtCoords({
1857
2389
  left: e.clientX,
1858
2390
  top: e.clientY
1859
2391
  });
1860
2392
  if (this.isDragging = !1, !t || t.inside === -1) {
1861
- const n = new Event("drop", e), r = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
1862
- n.clientX = r.left + r.width / 2, n.clientY = e.clientY, n.dataTransfer = e.dataTransfer, n.preventDefault = () => e.preventDefault(), n.synthetic = !0, this.ttEditor.view.dom.dispatchEvent(n);
2393
+ const o = new Event("drop", e), r = this.pmView.dom.firstChild.getBoundingClientRect();
2394
+ o.clientX = r.left + r.width / 2, o.clientY = e.clientY, o.dataTransfer = e.dataTransfer, o.preventDefault = () => e.preventDefault(), o.synthetic = !0, this.pmView.dom.dispatchEvent(o);
1863
2395
  }
1864
2396
  });
1865
2397
  /**
@@ -1867,841 +2399,225 @@ class Xe {
1867
2399
  * we dispatch a fake event, so that we can still drop the content
1868
2400
  * when dragging / dropping to the side of the editor
1869
2401
  */
1870
- h(this, "onDragOver", (e) => {
2402
+ u(this, "onDragOver", (e) => {
1871
2403
  if (e.synthetic || !this.isDragging)
1872
2404
  return;
1873
- let t = this.ttEditor.view.posAtCoords({
2405
+ let t = this.pmView.posAtCoords({
1874
2406
  left: e.clientX,
1875
2407
  top: e.clientY
1876
2408
  });
1877
2409
  if (!t || t.inside === -1) {
1878
- const n = new Event("dragover", e), r = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
1879
- n.clientX = r.left + r.width / 2, n.clientY = e.clientY, n.dataTransfer = e.dataTransfer, n.preventDefault = () => e.preventDefault(), n.synthetic = !0, this.ttEditor.view.dom.dispatchEvent(n);
2410
+ const o = new Event("dragover", e), r = this.pmView.dom.firstChild.getBoundingClientRect();
2411
+ o.clientX = r.left + r.width / 2, o.clientY = e.clientY, o.dataTransfer = e.dataTransfer, o.preventDefault = () => e.preventDefault(), o.synthetic = !0, this.pmView.dom.dispatchEvent(o);
1880
2412
  }
1881
2413
  });
1882
- h(this, "onKeyDown", (e) => {
1883
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1;
1884
- });
1885
- h(this, "onMouseDown", (e) => {
2414
+ u(this, "onKeyDown", (e) => {
1886
2415
  var t;
1887
- (t = this.blockMenu.element) != null && t.contains(e.target) || (this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1);
1888
- });
1889
- h(this, "onMouseMove", (e) => {
1890
- var l, d, c;
1891
- if (this.menuFrozen)
1892
- return;
1893
- const t = this.ttEditor.view.dom.firstChild.getBoundingClientRect(), n = this.ttEditor.view.dom.getBoundingClientRect();
1894
- if (
1895
- // Cursor is within the editor area
1896
- e.clientX >= n.left && e.clientX <= n.right && e.clientY >= n.top && e.clientY <= n.bottom && // An element is hovered
1897
- e && e.target && // Element is outside the editor
1898
- this.ttEditor.view.dom !== e.target && !this.ttEditor.view.dom.contains(e.target) && // Element is outside the side menu
1899
- this.blockMenu.element !== e.target && !((l = this.blockMenu.element) != null && l.contains(e.target))
1900
- ) {
1901
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
1902
- return;
1903
- }
1904
- this.horizontalPosAnchor = t.x;
1905
- const i = {
1906
- left: t.left + t.width / 2,
1907
- // take middle of editor
1908
- top: e.clientY
1909
- }, s = _t(i, this.ttEditor.view);
1910
- if (!s || !this.editor.isEditable) {
1911
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
1912
- return;
1913
- }
1914
- this.menuOpen && ((d = this.hoveredBlock) != null && d.hasAttribute("data-id")) && ((c = this.hoveredBlock) == null ? void 0 : c.getAttribute("data-id")) === s.id || (this.hoveredBlock = s.node, !s.node.firstChild) || this.editor.isEditable && (this.menuOpen ? this.blockMenu.render(this.getDynamicParams(), !1) : (this.menuOpen = !0, this.blockMenu.render(this.getDynamicParams(), !0)));
1915
- });
1916
- h(this, "onScroll", () => {
1917
- const e = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
1918
- this.horizontalPosAnchor = e.x, this.menuOpen && this.blockMenu.render(this.getDynamicParams(), !1);
1919
- });
1920
- this.editor = t, this.ttEditor = e, this.horizontalPosAnchoredAtRoot = r, this.horizontalPosAnchor = this.ttEditor.view.dom.firstChild.getBoundingClientRect().x, this.blockMenu = n(this.getStaticParams()), document.body.addEventListener("drop", this.onDrop, !0), document.body.addEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.addEventListener("dragstart", this.onDragStart), document.body.addEventListener("mousemove", this.onMouseMove, !0), document.addEventListener("scroll", this.onScroll), document.body.addEventListener("mousedown", this.onMouseDown, !0), document.body.addEventListener("keydown", this.onKeyDown, !0);
1921
- }
1922
- destroy() {
1923
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), document.body.removeEventListener("mousemove", this.onMouseMove), document.body.removeEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.removeEventListener("dragstart", this.onDragStart), document.body.removeEventListener("drop", this.onDrop), document.body.removeEventListener("mousedown", this.onMouseDown), document.removeEventListener("scroll", this.onScroll), document.body.removeEventListener("keydown", this.onKeyDown);
1924
- }
1925
- addBlock() {
1926
- this.menuOpen = !1, this.menuFrozen = !0, this.blockMenu.hide();
1927
- const t = this.hoveredBlock.firstChild.getBoundingClientRect(), n = this.ttEditor.view.posAtCoords({
1928
- left: t.left + t.width / 2,
1929
- top: t.top + t.height / 2
1930
- });
1931
- if (!n)
1932
- return;
1933
- const r = g(this.ttEditor.state.doc, n.pos);
1934
- if (r === void 0)
1935
- return;
1936
- const { contentNode: i, endPos: s } = r;
1937
- if (i.textContent.length !== 0) {
1938
- const a = s + 1, l = a + 2;
1939
- this.ttEditor.chain().BNCreateBlock(a).BNUpdateBlock(l, { type: "paragraph", props: {} }).setTextSelection(l).run();
1940
- } else
1941
- this.ttEditor.commands.setTextSelection(s);
1942
- this.ttEditor.view.focus(), this.ttEditor.view.dispatch(
1943
- this.ttEditor.view.state.tr.scrollIntoView().setMeta(X, {
1944
- // TODO import suggestion plugin key
1945
- activate: !0,
1946
- type: "drag"
1947
- })
1948
- );
1949
- }
1950
- getStaticParams() {
1951
- return {
1952
- editor: this.editor,
1953
- addBlock: () => this.addBlock(),
1954
- blockDragStart: (e) => {
1955
- this.isDragging = !0, Je(e, this.ttEditor.view);
1956
- },
1957
- blockDragEnd: () => Pt(),
1958
- freezeMenu: () => {
1959
- this.menuFrozen = !0;
1960
- },
1961
- unfreezeMenu: () => {
1962
- this.menuFrozen = !1;
1963
- }
1964
- };
1965
- }
1966
- getDynamicParams() {
1967
- const t = this.hoveredBlock.firstChild.getBoundingClientRect();
1968
- return {
1969
- block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id")),
1970
- referenceRect: new DOMRect(
1971
- this.horizontalPosAnchoredAtRoot ? this.horizontalPosAnchor : t.x,
1972
- t.y,
1973
- t.width,
1974
- t.height
1975
- )
1976
- };
1977
- }
1978
- }
1979
- const Ze = (o) => new C({
1980
- key: new E("DraggableBlocksPlugin"),
1981
- view: () => new Xe({
1982
- tiptapEditor: o.tiptapEditor,
1983
- editor: o.editor,
1984
- blockMenuFactory: o.blockSideMenuFactory,
1985
- horizontalPosAnchoredAtRoot: !0
1986
- })
1987
- }), Qe = () => v.create({
1988
- name: "DraggableBlocksExtension",
1989
- priority: 1e3,
1990
- // Need to be high, in order to hide menu when typing slash
1991
- addProseMirrorPlugins() {
1992
- if (!this.options.blockSideMenuFactory)
1993
- throw new Error(
1994
- "UI Element factory not defined for DraggableBlocksExtension"
1995
- );
1996
- return [
1997
- Ze({
1998
- tiptapEditor: this.editor,
1999
- editor: this.options.editor,
2000
- blockSideMenuFactory: this.options.blockSideMenuFactory
2001
- })
2002
- ];
2003
- }
2004
- });
2005
- class to {
2006
- constructor({
2007
- editor: e,
2008
- tiptapEditor: t,
2009
- formattingToolbarFactory: n,
2010
- view: r
2011
- }) {
2012
- h(this, "editor");
2013
- h(this, "ttEditor");
2014
- h(this, "view");
2015
- h(this, "formattingToolbar");
2016
- h(this, "preventHide", !1);
2017
- h(this, "preventShow", !1);
2018
- h(this, "toolbarIsOpen", !1);
2019
- h(this, "prevWasEditable", null);
2020
- h(this, "shouldShow", ({ view: e, state: t, from: n, to: r }) => {
2021
- const { doc: i, selection: s } = t, { empty: a } = s, l = !i.textBetween(n, r).length && Rt(t.selection);
2022
- return !(!e.hasFocus() || a || l);
2023
- });
2024
- h(this, "viewMousedownHandler", () => {
2025
- this.preventShow = !0;
2026
- });
2027
- h(this, "viewMouseupHandler", () => {
2028
- this.preventShow = !1, setTimeout(() => this.update(this.ttEditor.view));
2029
- });
2030
- h(this, "dragstartHandler", () => {
2031
- this.formattingToolbar.hide(), this.toolbarIsOpen = !1;
2032
- });
2033
- h(this, "focusHandler", () => {
2034
- setTimeout(() => this.update(this.ttEditor.view));
2035
- });
2036
- h(this, "blurHandler", ({ event: e }) => {
2037
- var t;
2038
- if (this.preventHide) {
2039
- this.preventHide = !1;
2040
- return;
2041
- }
2042
- // An element is clicked.
2043
- e && e.relatedTarget && // Element is outside the toolbar.
2044
- (this.formattingToolbar.element === e.relatedTarget || (t = this.formattingToolbar.element) != null && t.contains(e.relatedTarget)) || this.toolbarIsOpen && (this.formattingToolbar.hide(), this.toolbarIsOpen = !1);
2045
- });
2046
- h(this, "scrollHandler", () => {
2047
- this.toolbarIsOpen && this.formattingToolbar.render(this.getDynamicParams(), !1);
2048
- });
2049
- this.editor = e, this.ttEditor = t, this.view = r, this.formattingToolbar = n(this.getStaticParams()), this.view.dom.addEventListener("mousedown", this.viewMousedownHandler), this.view.dom.addEventListener("mouseup", this.viewMouseupHandler), this.view.dom.addEventListener("dragstart", this.dragstartHandler), this.ttEditor.on("focus", this.focusHandler), this.ttEditor.on("blur", this.blurHandler), document.addEventListener("scroll", this.scrollHandler);
2050
- }
2051
- update(e, t) {
2052
- var p;
2053
- const { state: n, composing: r } = e, { doc: i, selection: s } = n, a = t && t.doc.eq(i) && t.selection.eq(s);
2054
- if ((this.prevWasEditable === null || this.prevWasEditable === this.editor.isEditable) && (r || a))
2055
- return;
2056
- this.prevWasEditable = this.editor.isEditable;
2057
- const { ranges: l } = s, d = Math.min(...l.map((f) => f.$from.pos)), c = Math.max(...l.map((f) => f.$to.pos)), u = (p = this.shouldShow) == null ? void 0 : p.call(this, {
2058
- view: e,
2059
- state: n,
2060
- from: d,
2061
- to: c
2062
- });
2063
- if (this.editor.isEditable && !this.toolbarIsOpen && !this.preventShow && (u || this.preventHide)) {
2064
- this.formattingToolbar.render(this.getDynamicParams(), !0), this.toolbarIsOpen = !0;
2065
- return;
2066
- }
2067
- if (this.toolbarIsOpen && !this.preventShow && (u || this.preventHide)) {
2068
- this.formattingToolbar.render(this.getDynamicParams(), !1);
2069
- return;
2070
- }
2071
- if (this.toolbarIsOpen && !this.preventHide && (!u || this.preventShow || !this.editor.isEditable)) {
2072
- this.formattingToolbar.hide(), this.toolbarIsOpen = !1;
2073
- return;
2074
- }
2075
- }
2076
- destroy() {
2077
- this.view.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.view.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.ttEditor.off("focus", this.focusHandler), this.ttEditor.off("blur", this.blurHandler), document.removeEventListener("scroll", this.scrollHandler);
2078
- }
2079
- getSelectionBoundingBox() {
2080
- const { state: e } = this.ttEditor.view, { selection: t } = e, { ranges: n } = t, r = Math.min(...n.map((s) => s.$from.pos)), i = Math.max(...n.map((s) => s.$to.pos));
2081
- if (zt(t)) {
2082
- const s = this.ttEditor.view.nodeDOM(r);
2083
- if (s)
2084
- return s.getBoundingClientRect();
2085
- }
2086
- return at(this.ttEditor.view, r, i);
2087
- }
2088
- getStaticParams() {
2089
- return {
2090
- editor: this.editor
2091
- };
2092
- }
2093
- getDynamicParams() {
2094
- return {
2095
- referenceRect: this.getSelectionBoundingBox()
2096
- };
2097
- }
2098
- }
2099
- const eo = (o) => new C({
2100
- key: new E("FormattingToolbarPlugin"),
2101
- view: (e) => new to({ view: e, ...o })
2102
- }), oo = () => v.create({
2103
- name: "FormattingToolbarExtension",
2104
- addProseMirrorPlugins() {
2105
- if (!this.options.formattingToolbarFactory || !this.options.editor)
2106
- throw new Error(
2107
- "required args not defined for FormattingToolbarExtension"
2108
- );
2109
- return [
2110
- eo({
2111
- tiptapEditor: this.editor,
2112
- editor: this.options.editor,
2113
- formattingToolbarFactory: this.options.formattingToolbarFactory,
2114
- pluginKey: new E("FormattingToolbarPlugin")
2115
- })
2116
- ];
2117
- }
2118
- }), no = new E("HyperlinkToolbarPlugin");
2119
- class ro {
2120
- constructor({ editor: e, hyperlinkToolbarFactory: t }) {
2121
- h(this, "editor");
2122
- h(this, "hyperlinkToolbar");
2123
- h(this, "menuUpdateTimer");
2124
- h(this, "startMenuUpdateTimer");
2125
- h(this, "stopMenuUpdateTimer");
2126
- h(this, "mouseHoveredHyperlinkMark");
2127
- h(this, "mouseHoveredHyperlinkMarkRange");
2128
- h(this, "keyboardHoveredHyperlinkMark");
2129
- h(this, "keyboardHoveredHyperlinkMarkRange");
2130
- h(this, "hyperlinkMark");
2131
- h(this, "hyperlinkMarkRange");
2132
- h(this, "mouseOverHandler", (e) => {
2133
- if (this.mouseHoveredHyperlinkMark = void 0, this.mouseHoveredHyperlinkMarkRange = void 0, this.stopMenuUpdateTimer(), e.target instanceof HTMLAnchorElement && e.target.nodeName === "A") {
2134
- const t = e.target, n = this.editor.view.posAtDOM(t, 0) + 1, r = this.editor.state.doc.resolve(
2135
- n
2136
- ), i = r.marks();
2137
- for (const s of i)
2138
- if (s.type.name === this.editor.schema.mark("link").type.name) {
2139
- this.mouseHoveredHyperlinkMark = s, this.mouseHoveredHyperlinkMarkRange = Q(
2140
- r,
2141
- s.type,
2142
- s.attrs
2143
- ) || void 0;
2144
- break;
2145
- }
2146
- }
2147
- return this.startMenuUpdateTimer(), !1;
2148
- });
2149
- h(this, "clickHandler", (e) => {
2150
- var t;
2151
- // Toolbar is open.
2152
- this.hyperlinkMark && // An element is clicked.
2153
- e && e.target && // Element is outside the editor.
2154
- this.editor.view.dom !== e.target && !this.editor.view.dom.contains(e.target) && // Element is outside the toolbar.
2155
- this.hyperlinkToolbar.element !== e.target && !((t = this.hyperlinkToolbar.element) != null && t.contains(e.target)) && this.hyperlinkToolbar.hide();
2156
- });
2157
- h(this, "scrollHandler", () => {
2158
- this.hyperlinkMark !== void 0 && this.hyperlinkToolbar.render(this.getDynamicParams(), !1);
2159
- });
2160
- this.editor = e, this.hyperlinkToolbar = t(this.getStaticParams()), this.startMenuUpdateTimer = () => {
2161
- this.menuUpdateTimer = setTimeout(() => {
2162
- this.update();
2163
- }, 250);
2164
- }, this.stopMenuUpdateTimer = () => (this.menuUpdateTimer && (clearTimeout(this.menuUpdateTimer), this.menuUpdateTimer = void 0), !1), this.editor.view.dom.addEventListener("mouseover", this.mouseOverHandler), document.addEventListener("click", this.clickHandler, !0), document.addEventListener("scroll", this.scrollHandler);
2165
- }
2166
- update() {
2167
- var t, n, r, i;
2168
- if (!this.editor.view.hasFocus())
2169
- return;
2170
- const e = this.hyperlinkMark;
2171
- if (this.hyperlinkMark = void 0, this.hyperlinkMarkRange = void 0, this.keyboardHoveredHyperlinkMark = void 0, this.keyboardHoveredHyperlinkMarkRange = void 0, this.editor.state.selection.empty) {
2172
- const s = this.editor.state.selection.$from.marks();
2173
- for (const a of s)
2174
- if (a.type.name === this.editor.schema.mark("link").type.name) {
2175
- this.keyboardHoveredHyperlinkMark = a, this.keyboardHoveredHyperlinkMarkRange = Q(
2176
- this.editor.state.selection.$from,
2177
- a.type,
2178
- a.attrs
2179
- ) || void 0;
2180
- break;
2181
- }
2182
- }
2183
- if (this.mouseHoveredHyperlinkMark && (this.hyperlinkMark = this.mouseHoveredHyperlinkMark, this.hyperlinkMarkRange = this.mouseHoveredHyperlinkMarkRange), this.keyboardHoveredHyperlinkMark && (this.hyperlinkMark = this.keyboardHoveredHyperlinkMark, this.hyperlinkMarkRange = this.keyboardHoveredHyperlinkMarkRange), this.hyperlinkMark && this.editor.isEditable) {
2184
- if (this.getDynamicParams(), !e) {
2185
- this.hyperlinkToolbar.render(this.getDynamicParams(), !0), (t = this.hyperlinkToolbar.element) == null || t.addEventListener(
2186
- "mouseleave",
2187
- this.startMenuUpdateTimer
2188
- ), (n = this.hyperlinkToolbar.element) == null || n.addEventListener(
2189
- "mouseenter",
2190
- this.stopMenuUpdateTimer
2191
- );
2416
+ (t = this.sideMenuState) != null && t.show && (this.sideMenuState.show = !1, this.updateSideMenu(this.sideMenuState)), this.menuFrozen = !1;
2417
+ });
2418
+ u(this, "onMouseMove", (e) => {
2419
+ var d, c, p, h, f;
2420
+ if (this.menuFrozen)
2421
+ return;
2422
+ const t = this.pmView.dom.firstChild.getBoundingClientRect(), o = this.pmView.dom.getBoundingClientRect(), r = e.clientX >= o.left && e.clientX <= o.right && e.clientY >= o.top && e.clientY <= o.bottom, i = this.pmView.dom.parentElement;
2423
+ if (
2424
+ // Cursor is within the editor area
2425
+ r && // An element is hovered
2426
+ e && e.target && // Element is outside the editor
2427
+ !(i === e.target || i.contains(e.target))
2428
+ ) {
2429
+ (d = this.sideMenuState) != null && d.show && (this.sideMenuState.show = !1, this.updateSideMenu(this.sideMenuState));
2192
2430
  return;
2193
2431
  }
2194
- this.hyperlinkToolbar.render(this.getDynamicParams(), !1);
2195
- return;
2196
- }
2197
- if (e && (!this.hyperlinkMark || !this.editor.isEditable)) {
2198
- (r = this.hyperlinkToolbar.element) == null || r.removeEventListener(
2199
- "mouseleave",
2200
- this.startMenuUpdateTimer
2201
- ), (i = this.hyperlinkToolbar.element) == null || i.removeEventListener(
2202
- "mouseenter",
2203
- this.stopMenuUpdateTimer
2204
- ), this.hyperlinkToolbar.hide();
2205
- return;
2206
- }
2207
- }
2208
- destroy() {
2209
- this.editor.view.dom.removeEventListener(
2210
- "mouseover",
2211
- this.mouseOverHandler
2212
- ), document.removeEventListener("scroll", this.scrollHandler);
2213
- }
2214
- getStaticParams() {
2215
- return {
2216
- editHyperlink: (e, t) => {
2217
- const n = this.editor.view.state.tr.insertText(
2218
- t,
2219
- this.hyperlinkMarkRange.from,
2220
- this.hyperlinkMarkRange.to
2221
- );
2222
- n.addMark(
2223
- this.hyperlinkMarkRange.from,
2224
- this.hyperlinkMarkRange.from + t.length,
2225
- this.editor.schema.mark("link", { href: e })
2226
- ), this.editor.view.dispatch(n), this.editor.view.focus(), this.hyperlinkToolbar.hide();
2227
- },
2228
- deleteHyperlink: () => {
2229
- this.editor.view.dispatch(
2230
- this.editor.view.state.tr.removeMark(
2231
- this.hyperlinkMarkRange.from,
2232
- this.hyperlinkMarkRange.to,
2233
- this.hyperlinkMark.type
2234
- ).setMeta("preventAutolink", !0)
2235
- ), this.editor.view.focus(), this.hyperlinkToolbar.hide();
2432
+ this.horizontalPosAnchor = t.x;
2433
+ const s = {
2434
+ left: t.left + t.width / 2,
2435
+ // take middle of editor
2436
+ top: e.clientY
2437
+ }, l = It(s, this.pmView);
2438
+ if (!l || !this.editor.isEditable) {
2439
+ (c = this.sideMenuState) != null && c.show && (this.sideMenuState.show = !1, this.updateSideMenu(this.sideMenuState));
2440
+ return;
2236
2441
  }
2237
- };
2442
+ if ((p = this.sideMenuState) != null && p.show && ((h = this.hoveredBlock) != null && h.hasAttribute("data-id")) && ((f = this.hoveredBlock) == null ? void 0 : f.getAttribute("data-id")) === l.id)
2443
+ return;
2444
+ this.hoveredBlock = l.node;
2445
+ const a = l.node.firstChild;
2446
+ if (a && this.editor.isEditable) {
2447
+ const m = a.getBoundingClientRect();
2448
+ this.sideMenuState = {
2449
+ show: !0,
2450
+ referencePos: new DOMRect(
2451
+ this.horizontalPosAnchoredAtRoot ? this.horizontalPosAnchor : m.x,
2452
+ m.y,
2453
+ m.width,
2454
+ m.height
2455
+ ),
2456
+ block: this.editor.getBlock(
2457
+ this.hoveredBlock.getAttribute("data-id")
2458
+ )
2459
+ }, this.updateSideMenu(this.sideMenuState);
2460
+ }
2461
+ });
2462
+ u(this, "onScroll", () => {
2463
+ var e;
2464
+ if ((e = this.sideMenuState) != null && e.show) {
2465
+ const o = this.hoveredBlock.firstChild.getBoundingClientRect();
2466
+ this.sideMenuState.referencePos = new DOMRect(
2467
+ this.horizontalPosAnchoredAtRoot ? this.horizontalPosAnchor : o.x,
2468
+ o.y,
2469
+ o.width,
2470
+ o.height
2471
+ ), this.updateSideMenu(this.sideMenuState);
2472
+ }
2473
+ });
2474
+ this.editor = e, this.pmView = t, this.updateSideMenu = o, this.horizontalPosAnchoredAtRoot = !0, this.horizontalPosAnchor = this.pmView.dom.firstChild.getBoundingClientRect().x, document.body.addEventListener("drop", this.onDrop, !0), document.body.addEventListener("dragover", this.onDragOver), this.pmView.dom.addEventListener("dragstart", this.onDragStart), document.body.addEventListener("mousemove", this.onMouseMove, !0), document.addEventListener("scroll", this.onScroll), document.body.addEventListener("keydown", this.onKeyDown, !0);
2238
2475
  }
2239
- getDynamicParams() {
2240
- return {
2241
- url: this.hyperlinkMark.attrs.href,
2242
- text: this.editor.view.state.doc.textBetween(
2243
- this.hyperlinkMarkRange.from,
2244
- this.hyperlinkMarkRange.to
2245
- ),
2246
- referenceRect: at(
2247
- this.editor.view,
2248
- this.hyperlinkMarkRange.from,
2249
- this.hyperlinkMarkRange.to
2250
- )
2251
- };
2476
+ destroy() {
2477
+ var e;
2478
+ (e = this.sideMenuState) != null && e.show && (this.sideMenuState.show = !1, this.updateSideMenu(this.sideMenuState)), document.body.removeEventListener("mousemove", this.onMouseMove), document.body.removeEventListener("dragover", this.onDragOver), this.pmView.dom.removeEventListener("dragstart", this.onDragStart), document.body.removeEventListener("drop", this.onDrop, !0), document.removeEventListener("scroll", this.onScroll), document.body.removeEventListener("keydown", this.onKeyDown, !0);
2252
2479
  }
2253
- }
2254
- const io = (o, e) => new C({
2255
- key: no,
2256
- view: () => new ro({
2257
- editor: o,
2258
- hyperlinkToolbarFactory: e.hyperlinkToolbarFactory
2259
- })
2260
- }), so = ut.extend({
2261
- priority: 500,
2262
- addProseMirrorPlugins() {
2263
- var o;
2264
- if (!this.options.hyperlinkToolbarFactory)
2265
- throw new Error("UI Element factory not defined for HyperlinkMark");
2266
- return [
2267
- ...((o = this.parent) == null ? void 0 : o.call(this)) || [],
2268
- io(this.editor, {
2269
- hyperlinkToolbarFactory: this.options.hyperlinkToolbarFactory
2480
+ addBlock() {
2481
+ var l;
2482
+ (l = this.sideMenuState) != null && l.show && (this.sideMenuState.show = !1, this.updateSideMenu(this.sideMenuState)), this.menuFrozen = !0;
2483
+ const t = this.hoveredBlock.firstChild.getBoundingClientRect(), o = this.pmView.posAtCoords({
2484
+ left: t.left + t.width / 2,
2485
+ top: t.top + t.height / 2
2486
+ });
2487
+ if (!o)
2488
+ return;
2489
+ const r = g(
2490
+ this.editor._tiptapEditor.state.doc,
2491
+ o.pos
2492
+ );
2493
+ if (r === void 0)
2494
+ return;
2495
+ const { contentNode: i, endPos: s } = r;
2496
+ if (i.textContent.length !== 0) {
2497
+ const a = s + 1, d = a + 2;
2498
+ this.editor._tiptapEditor.chain().BNCreateBlock(a).BNUpdateBlock(d, { type: "paragraph", props: {} }).setTextSelection(d).run();
2499
+ } else
2500
+ this.editor._tiptapEditor.commands.setTextSelection(s);
2501
+ this.pmView.focus(), this.pmView.dispatch(
2502
+ this.pmView.state.tr.scrollIntoView().setMeta(K, {
2503
+ // TODO import suggestion plugin key
2504
+ activate: !0,
2505
+ type: "drag"
2270
2506
  })
2271
- ];
2507
+ );
2272
2508
  }
2273
- }), ao = new E("blocknote-placeholder"), lo = v.create({
2274
- name: "placeholder",
2275
- addOptions() {
2276
- return {
2277
- emptyEditorClass: "is-editor-empty",
2278
- emptyNodeClass: "is-empty",
2279
- isFilterClass: "is-filter",
2280
- hasAnchorClass: "has-anchor",
2281
- placeholder: "Write something …",
2282
- showOnlyWhenEditable: !0,
2283
- showOnlyCurrent: !0,
2284
- includeChildren: !1
2285
- };
2286
- },
2287
- addProseMirrorPlugins() {
2288
- return [
2289
- new C({
2290
- key: ao,
2291
- props: {
2292
- decorations: (o) => {
2293
- const { doc: e, selection: t } = o, n = X.getState(o), r = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: i } = t, s = [];
2294
- if (r)
2295
- return e.descendants((a, l) => {
2296
- const d = i >= l && i <= l + a.nodeSize, c = !a.isLeaf && !a.childCount;
2297
- if ((d || !this.options.showOnlyCurrent) && c) {
2298
- const u = [this.options.emptyNodeClass];
2299
- this.editor.isEmpty && u.push(this.options.emptyEditorClass), d && u.push(this.options.hasAnchorClass), (n == null ? void 0 : n.triggerCharacter) === "" && (n != null && n.active) && u.push(this.options.isFilterClass);
2300
- const p = D.node(l, l + a.nodeSize, {
2301
- class: u.join(" ")
2302
- });
2303
- s.push(p);
2304
- }
2305
- return this.options.includeChildren;
2306
- }), F.create(e, s);
2307
- }
2509
+ }
2510
+ const po = new S("SideMenuPlugin");
2511
+ class ho extends F {
2512
+ constructor(t) {
2513
+ super();
2514
+ u(this, "sideMenuView");
2515
+ u(this, "plugin");
2516
+ /**
2517
+ * If the block is empty, opens the slash menu. If the block has content,
2518
+ * creates a new block below and opens the slash menu in it.
2519
+ */
2520
+ u(this, "addBlock", () => this.sideMenuView.addBlock());
2521
+ /**
2522
+ * Handles drag & drop events for blocks.
2523
+ */
2524
+ u(this, "blockDragStart", (t) => {
2525
+ this.sideMenuView.isDragging = !0, co(t, this.editor.prosemirrorView);
2526
+ });
2527
+ /**
2528
+ * Handles drag & drop events for blocks.
2529
+ */
2530
+ u(this, "blockDragEnd", () => Ht());
2531
+ /**
2532
+ * Freezes the side menu. When frozen, the side menu will stay
2533
+ * attached to the same block regardless of which block is hovered by the
2534
+ * mouse cursor.
2535
+ */
2536
+ u(this, "freezeMenu", () => this.sideMenuView.menuFrozen = !0);
2537
+ /**
2538
+ * Unfreezes the side menu. When frozen, the side menu will stay
2539
+ * attached to the same block regardless of which block is hovered by the
2540
+ * mouse cursor.
2541
+ */
2542
+ u(this, "unfreezeMenu", () => this.sideMenuView.menuFrozen = !1);
2543
+ this.editor = t, this.plugin = new y({
2544
+ key: po,
2545
+ view: (o) => (this.sideMenuView = new uo(
2546
+ t,
2547
+ o,
2548
+ (r) => {
2549
+ this.emit("update", r);
2308
2550
  }
2309
- })
2310
- ];
2311
- }
2312
- });
2313
- class co {
2314
- constructor(e, t) {
2315
- this.name = e, this.match = t;
2551
+ ), this.sideMenuView)
2552
+ });
2316
2553
  }
2317
- }
2318
- class S extends co {
2319
- /**
2320
- * Constructs a new slash-command.
2321
- *
2322
- * @param name The name of the command
2323
- * @param execute The callback for creating a new node
2324
- * @param aliases Aliases for this command
2325
- */
2326
- constructor(e, t, n = []) {
2327
- super(e, (r) => this.name.toLowerCase().startsWith(r.toLowerCase()) || this.aliases.filter(
2328
- (i) => i.toLowerCase().startsWith(r.toLowerCase())
2329
- ).length !== 0), this.name = e, this.execute = t, this.aliases = n;
2554
+ onUpdate(t) {
2555
+ return this.on("update", t);
2330
2556
  }
2331
2557
  }
2332
- function x(o, e) {
2333
- const t = o.getTextCursorPosition().block;
2334
- t.content.length === 1 && t.content[0].type === "text" && t.content[0].text === "/" || t.content.length === 0 ? o.updateBlock(t, e) : (o.insertBlocks([e], t, "after"), o.setTextCursorPosition(o.getTextCursorPosition().nextBlock));
2558
+ function _(n, e) {
2559
+ const t = n.getTextCursorPosition().block;
2560
+ t.content.length === 1 && t.content[0].type === "text" && t.content[0].text === "/" || t.content.length === 0 ? n.updateBlock(t, e) : (n.insertBlocks([e], t, "after"), n.setTextCursorPosition(n.getTextCursorPosition().nextBlock));
2335
2561
  }
2336
- const uo = [
2337
- // Command for creating a level 1 heading
2338
- new S(
2339
- "Heading",
2340
- (o) => x(o, {
2562
+ const fo = (n = wt) => {
2563
+ var t, o, r;
2564
+ const e = [];
2565
+ return "heading" in n && "level" in n.heading.propSchema && ((t = n.heading.propSchema.level.values) != null && t.includes("1") && e.push({
2566
+ name: "Heading",
2567
+ aliases: ["h", "heading1", "h1"],
2568
+ execute: (i) => _(i, {
2341
2569
  type: "heading",
2342
2570
  props: { level: "1" }
2343
- }),
2344
- ["h", "heading1", "h1"]
2345
- ),
2346
- // Command for creating a level 2 heading
2347
- new S(
2348
- "Heading 2",
2349
- (o) => x(o, {
2571
+ })
2572
+ }), (o = n.heading.propSchema.level.values) != null && o.includes("2") && e.push({
2573
+ name: "Heading 2",
2574
+ aliases: ["h2", "heading2", "subheading"],
2575
+ execute: (i) => _(i, {
2350
2576
  type: "heading",
2351
2577
  props: { level: "2" }
2352
- }),
2353
- ["h2", "heading2", "subheading"]
2354
- ),
2355
- // Command for creating a level 3 heading
2356
- new S(
2357
- "Heading 3",
2358
- (o) => x(o, {
2578
+ })
2579
+ }), (r = n.heading.propSchema.level.values) != null && r.includes("3") && e.push({
2580
+ name: "Heading 3",
2581
+ aliases: ["h3", "heading3", "subheading"],
2582
+ execute: (i) => _(i, {
2359
2583
  type: "heading",
2360
2584
  props: { level: "3" }
2361
- }),
2362
- ["h3", "heading3", "subheading"]
2363
- ),
2364
- // Command for creating an ordered list
2365
- new S(
2366
- "Numbered List",
2367
- (o) => x(o, {
2368
- type: "numberedListItem"
2369
- }),
2370
- ["li", "list", "numberedlist", "numbered list"]
2371
- ),
2372
- // Command for creating a bullet list
2373
- new S(
2374
- "Bullet List",
2375
- (o) => x(o, {
2376
- type: "bulletListItem"
2377
- }),
2378
- ["ul", "list", "bulletlist", "bullet list"]
2379
- ),
2380
- // Command for creating a paragraph (pretty useless)
2381
- new S(
2382
- "Paragraph",
2383
- (o) => x(o, {
2384
- type: "paragraph"
2385
- }),
2386
- ["p"]
2387
- )
2388
- // replaceRangeWithNode(editor, range, node);
2389
- // return true;
2390
- // },
2391
- // ["ol", "orderedlist"],
2392
- // OrderedListIcon,
2393
- // "Used to display an ordered (enumerated) list item"
2394
- // ),
2395
- // Command for creating a blockquote
2396
- // blockquote: new SlashCommand(
2397
- // "Block Quote",
2398
- // CommandGroup.BASIC_BLOCKS,
2399
- // (editor, range) => {
2400
- // const paragraph = editor.schema.node("paragraph");
2401
- // const node = editor.schema.node(
2402
- // "blockquote",
2403
- // { "block-id": uniqueId.generate() },
2404
- // paragraph
2405
- // );
2406
- // replaceRangeWithNode(editor, range, node);
2407
- // return true;
2408
- // },
2409
- // ["quote", "blockquote"],
2410
- // QuoteIcon,
2411
- // "Used to make a quote stand out",
2412
- // "Ctrl+Shift+B"
2413
- // ),
2414
- // Command for creating a horizontal rule
2415
- // horizontalRule: new SlashCommand(
2416
- // "Horizontal Rule",
2417
- // CommandGroup.BASIC_BLOCKS,
2418
- // (editor, range) => {
2419
- // const node = editor.schema.node("horizontalRule", {
2420
- // "block-id": uniqueId.generate(),
2421
- // });
2422
- // // insert horizontal rule, create a new block after the horizontal rule if applicable
2423
- // // and put the cursor in the block after the horizontal rule.
2424
- // editor
2425
- // .chain()
2426
- // .focus()
2427
- // .replaceRangeAndUpdateSelection(range, node)
2428
- // .command(({ tr, dispatch }) => {
2429
- // if (dispatch) {
2430
- // // the node immediately after the cursor
2431
- // const nodeAfter = tr.selection.$to.nodeAfter;
2432
- // // the position of the cursor
2433
- // const cursorPos = tr.selection.$to.pos;
2434
- // // check if there is no node after the cursor (end of document)
2435
- // if (!nodeAfter) {
2436
- // // create a new block of the default type (probably paragraph) after the cursor
2437
- // const { parent } = tr.selection.$to;
2438
- // const node = parent.type.contentMatch.defaultType?.create();
2439
- // if (node) {
2440
- // tr.insert(cursorPos, node);
2441
- // }
2442
- // }
2443
- // // try to put the cursor at the start of the node directly after the inserted horizontal rule
2444
- // tr.doc.nodesBetween(cursorPos, cursorPos + 1, (node, pos) => {
2445
- // if (node.type.name !== "horizontalRule") {
2446
- // tr.setSelection(TextSelection.create(tr.doc, pos));
2447
- // }
2448
- // });
2449
- // }
2450
- // return true;
2451
- // })
2452
- // .scrollIntoView()
2453
- // .run();
2454
- // return true;
2455
- // },
2456
- // ["hr", "horizontalrule"],
2457
- // SeparatorIcon,
2458
- // "Used to separate sections with a horizontal line"
2459
- // ),
2460
- // Command for creating a table
2461
- // table: new SlashCommand(
2462
- // "Table",
2463
- // CommandGroup.BASIC_BLOCKS,
2464
- // (editor, range) => {
2465
- // editor.chain().focus().deleteRange(range).run();
2466
- // // TODO: add blockid, pending https://github.com/ueberdosis/tiptap/pull/1469
2467
- // editor
2468
- // .chain()
2469
- // .focus()
2470
- // .insertTable({ rows: 1, cols: 2, withHeaderRow: false })
2471
- // .scrollIntoView()
2472
- // .run();
2473
- // return true;
2474
- // },
2475
- // ["table", "database"],
2476
- // TableIcon,
2477
- // "Used to create a simple table"
2478
- // ),
2479
- ], ho = v.create({
2480
- name: "textAlignment",
2481
- addGlobalAttributes() {
2482
- return [
2483
- {
2484
- // Attribute is applied to block content instead of container so that child blocks don't inherit the text
2485
- // alignment styling.
2486
- types: ["paragraph", "heading", "bulletListItem", "numberedListItem"],
2487
- attributes: {
2488
- textAlignment: {
2489
- default: "left",
2490
- parseHTML: (o) => o.getAttribute("data-text-alignment"),
2491
- renderHTML: (o) => o.textAlignment !== "left" && {
2492
- "data-text-alignment": o.textAlignment
2493
- }
2494
- }
2495
- }
2496
- }
2497
- ];
2498
- },
2499
- addCommands() {
2500
- return {
2501
- setTextAlignment: (o) => ({ state: e }) => {
2502
- const t = [], n = g(
2503
- e.doc,
2504
- e.selection.from
2505
- );
2506
- if (n === void 0)
2507
- return !1;
2508
- let r = n.startPos;
2509
- for (; r < e.selection.to; )
2510
- e.doc.resolve(r).node().type.spec.group === "blockContent" ? (t.push(r - 1), r += e.doc.resolve(r).node().nodeSize - 1) : r += 1;
2511
- for (const i of t)
2512
- e.tr.setNodeAttribute(i, "textAlignment", o);
2513
- return !0;
2514
- }
2515
- };
2516
- }
2517
- }), po = v.create({
2518
- name: "blockTextColor",
2519
- addGlobalAttributes() {
2520
- return [
2521
- {
2522
- types: ["blockContainer"],
2523
- attributes: {
2524
- textColor: {
2525
- default: "default",
2526
- parseHTML: (o) => o.hasAttribute("data-text-color") ? o.getAttribute("data-text-color") : "default",
2527
- renderHTML: (o) => o.textColor !== "default" && {
2528
- "data-text-color": o.textColor
2529
- }
2530
- }
2531
- }
2532
- }
2533
- ];
2534
- },
2535
- addCommands() {
2536
- return {
2537
- setBlockTextColor: (o, e) => ({ state: t, view: n }) => {
2538
- const r = g(t.doc, o);
2539
- return r === void 0 ? !1 : (t.tr.setNodeAttribute(r.startPos - 1, "textColor", e), n.focus(), !0);
2540
- }
2541
- };
2542
- }
2543
- }), fo = st.create({
2544
- name: "textColor",
2545
- addAttributes() {
2546
- return {
2547
- color: {
2548
- default: void 0,
2549
- parseHTML: (o) => o.getAttribute("data-text-color"),
2550
- renderHTML: (o) => ({
2551
- "data-text-color": o.color
2552
- })
2553
- }
2554
- };
2555
- },
2556
- parseHTML() {
2557
- return [
2558
- {
2559
- tag: "span",
2560
- getAttrs: (o) => typeof o == "string" ? !1 : o.hasAttribute("data-text-color") ? { color: o.getAttribute("data-text-color") } : !1
2561
- }
2562
- ];
2563
- },
2564
- renderHTML({ HTMLAttributes: o }) {
2565
- return ["span", o, 0];
2566
- },
2567
- addCommands() {
2568
- return {
2569
- setTextColor: (o) => ({ commands: e }) => o !== "default" ? e.setMark(this.name, { color: o }) : e.unsetMark(this.name)
2570
- };
2571
- }
2572
- }), mo = v.create({
2573
- name: "trailingNode",
2574
- addProseMirrorPlugins() {
2575
- const o = new E(this.name);
2576
- return [
2577
- new C({
2578
- key: o,
2579
- appendTransaction: (e, t, n) => {
2580
- const { doc: r, tr: i, schema: s } = n, a = o.getState(n), l = r.content.size - 2, d = s.nodes.blockContainer, c = s.nodes.paragraph;
2581
- if (a)
2582
- return i.insert(
2583
- l,
2584
- d.create(void 0, c.create())
2585
- );
2586
- },
2587
- state: {
2588
- init: (e, t) => {
2589
- },
2590
- apply: (e, t) => {
2591
- if (!e.docChanged)
2592
- return t;
2593
- let n = e.doc.lastChild;
2594
- if (!n || n.type.name !== "blockGroup")
2595
- throw new Error("Expected blockGroup");
2596
- if (n = n.lastChild, !n || n.type.name !== "blockContainer")
2597
- throw new Error("Expected blockContainer");
2598
- return n.nodeSize > 4;
2599
- }
2600
- }
2601
- })
2602
- ];
2603
- }
2604
- }), go = (o) => {
2605
- const e = [
2606
- N.ClipboardTextSerializer,
2607
- N.Commands,
2608
- N.Editable,
2609
- N.FocusEvents,
2610
- N.Tabindex,
2611
- // DevTools,
2612
- te,
2613
- // DropCursor,
2614
- lo.configure({
2615
- emptyNodeClass: k.isEmpty,
2616
- hasAnchorClass: k.hasAnchor,
2617
- isFilterClass: k.isFilter,
2618
- includeChildren: !0,
2619
- showOnlyCurrent: !1
2620
- }),
2621
- K.configure({
2622
- types: ["blockContainer"]
2623
- }),
2624
- ee,
2625
- // Comments,
2626
- // basics:
2627
- ie,
2628
- // marks:
2629
- Kt,
2630
- Jt,
2631
- ne,
2632
- re,
2633
- se,
2634
- fo,
2635
- po,
2636
- Ae,
2637
- Ne,
2638
- ho,
2639
- // custom blocks:
2640
- ...ze,
2641
- ...Object.values(o.blockSchema).map(
2642
- (t) => t.node.configure({ editor: o.editor })
2643
- ),
2644
- $e,
2645
- Qt.configure({ width: 5, color: "#ddeeff" }),
2646
- // This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
2647
- // should be handled before Enter handlers in other components like splitListItem
2648
- mo
2649
- ];
2650
- if (o.collaboration) {
2651
- e.push(
2652
- Xt.configure({
2653
- fragment: o.collaboration.fragment
2654
- })
2655
- );
2656
- const t = (n) => {
2657
- const r = document.createElement("span");
2658
- r.classList.add(P["collaboration-cursor__caret"]), r.setAttribute("style", `border-color: ${n.color}`);
2659
- const i = document.createElement("span");
2660
- i.classList.add(P["collaboration-cursor__label"]), i.setAttribute("style", `background-color: ${n.color}`), i.insertBefore(document.createTextNode(n.name), null);
2661
- const s = document.createTextNode("⁠"), a = document.createTextNode("⁠");
2662
- return r.insertBefore(s, null), r.insertBefore(i, null), r.insertBefore(a, null), r;
2663
- };
2664
- e.push(
2665
- Zt.configure({
2666
- user: o.collaboration.user,
2667
- render: o.collaboration.renderCursor || t,
2668
- provider: o.collaboration.provider
2669
- })
2670
- );
2671
- } else
2672
- e.push(oe);
2673
- return o.uiFactories.blockSideMenuFactory && e.push(
2674
- Qe().configure({
2675
- editor: o.editor,
2676
- blockSideMenuFactory: o.uiFactories.blockSideMenuFactory
2677
2585
  })
2678
- ), o.uiFactories.formattingToolbarFactory && e.push(
2679
- oo().configure({
2680
- editor: o.editor,
2681
- formattingToolbarFactory: o.uiFactories.formattingToolbarFactory
2586
+ })), "bulletListItem" in n && e.push({
2587
+ name: "Bullet List",
2588
+ aliases: ["ul", "list", "bulletlist", "bullet list"],
2589
+ execute: (i) => _(i, {
2590
+ type: "bulletListItem"
2682
2591
  })
2683
- ), o.uiFactories.hyperlinkToolbarFactory ? e.push(
2684
- so.configure({
2685
- hyperlinkToolbarFactory: o.uiFactories.hyperlinkToolbarFactory
2592
+ }), "numberedListItem" in n && e.push({
2593
+ name: "Numbered List",
2594
+ aliases: ["li", "list", "numberedlist", "numbered list"],
2595
+ execute: (i) => _(i, {
2596
+ type: "numberedListItem"
2686
2597
  })
2687
- ) : e.push(ut), o.uiFactories.slashMenuFactory && e.push(
2688
- We().configure({
2689
- editor: o.editor,
2690
- commands: o.slashCommands,
2691
- slashMenuFactory: o.uiFactories.slashMenuFactory
2598
+ }), "paragraph" in n && e.push({
2599
+ name: "Paragraph",
2600
+ aliases: ["p"],
2601
+ execute: (i) => _(i, {
2602
+ type: "paragraph"
2692
2603
  })
2693
- ), e;
2694
- }, ko = {
2604
+ }), e;
2605
+ }, mo = {
2695
2606
  enableInputRules: !0,
2696
2607
  enablePasteRules: !0,
2697
2608
  enableCoreExtensions: !1
2698
2609
  };
2699
- class Ko {
2610
+ class Wo {
2700
2611
  constructor(e = {}) {
2701
- h(this, "_tiptapEditor");
2702
- h(this, "blockCache", /* @__PURE__ */ new WeakMap());
2703
- h(this, "schema");
2704
- var i, s, a;
2612
+ u(this, "_tiptapEditor");
2613
+ u(this, "blockCache", /* @__PURE__ */ new WeakMap());
2614
+ u(this, "schema");
2615
+ u(this, "ready", !1);
2616
+ u(this, "sideMenu");
2617
+ u(this, "formattingToolbar");
2618
+ u(this, "slashMenu");
2619
+ u(this, "hyperlinkToolbar");
2620
+ var l, a, d;
2705
2621
  this.options = e;
2706
2622
  const t = {
2707
2623
  defaultStyles: !0,
@@ -2710,54 +2626,74 @@ class Ko {
2710
2626
  // If BSchema is not specified, then options.blockSchema should also not
2711
2627
  // be defined. Unfortunately, trying to implement these constraints seems
2712
2628
  // to be a huge pain, hence the `as any` casts.
2713
- blockSchema: e.blockSchema || ke,
2629
+ blockSchema: e.blockSchema || wt,
2714
2630
  ...e
2715
- }, n = go({
2631
+ };
2632
+ this.sideMenu = new ho(this), this.formattingToolbar = new oo(this), this.slashMenu = new Ve(
2633
+ this,
2634
+ t.slashMenuItems || fo(t.blockSchema)
2635
+ ), this.hyperlinkToolbar = new io(this);
2636
+ const o = We({
2716
2637
  editor: this,
2717
- uiFactories: t.uiFactories || {},
2718
- slashCommands: t.slashCommands || uo,
2719
2638
  blockSchema: t.blockSchema,
2720
2639
  collaboration: t.collaboration
2640
+ }), r = T.create({
2641
+ name: "BlockNoteUIExtension",
2642
+ addProseMirrorPlugins: () => [
2643
+ this.sideMenu.plugin,
2644
+ this.formattingToolbar.plugin,
2645
+ this.slashMenu.plugin,
2646
+ this.hyperlinkToolbar.plugin
2647
+ ]
2721
2648
  });
2722
- this.schema = t.blockSchema;
2723
- const r = {
2724
- // TODO: This approach to setting initial content is "cleaner" but requires the PM editor schema, which is only
2725
- // created after initializing the TipTap editor. Not sure it's feasible.
2726
- // content:
2727
- // options.initialContent &&
2728
- // options.initialContent.map((block) =>
2729
- // blockToNode(block, this._tiptapEditor.schema).toJSON()
2730
- // ),
2731
- ...ko,
2649
+ o.push(r), this.schema = t.blockSchema;
2650
+ const i = t.initialContent || [
2651
+ {
2652
+ type: "paragraph",
2653
+ id: U.options.generateID()
2654
+ }
2655
+ ], s = {
2656
+ ...mo,
2732
2657
  ...t._tiptapOptions,
2733
2658
  onCreate: () => {
2734
- var l;
2735
- (l = t.onEditorReady) == null || l.call(t, this), t.initialContent && this.replaceBlocks(this.topLevelBlocks, t.initialContent);
2659
+ var c;
2660
+ (c = t.onEditorReady) == null || c.call(t, this), this.ready = !0;
2661
+ },
2662
+ onBeforeCreate(c) {
2663
+ const p = c.editor.schema, h = i.map((m) => O(m, p)), f = p.node(
2664
+ "doc",
2665
+ void 0,
2666
+ p.node("blockGroup", void 0, h)
2667
+ );
2668
+ c.editor.options.content = f.toJSON();
2736
2669
  },
2737
2670
  onUpdate: () => {
2738
- var l;
2739
- (l = t.onEditorContentChange) == null || l.call(t, this);
2671
+ var c;
2672
+ this.ready && ((c = t.onEditorContentChange) == null || c.call(t, this));
2740
2673
  },
2741
2674
  onSelectionUpdate: () => {
2742
- var l;
2743
- (l = t.onTextCursorPositionChange) == null || l.call(t, this);
2675
+ var c;
2676
+ this.ready && ((c = t.onTextCursorPositionChange) == null || c.call(t, this));
2744
2677
  },
2745
2678
  editable: e.editable === void 0 ? !0 : e.editable,
2746
- extensions: t.enableBlockNoteExtensions === !1 ? (i = t._tiptapOptions) == null ? void 0 : i.extensions : [...((s = t._tiptapOptions) == null ? void 0 : s.extensions) || [], ...n],
2679
+ extensions: t.enableBlockNoteExtensions === !1 ? (l = t._tiptapOptions) == null ? void 0 : l.extensions : [...((a = t._tiptapOptions) == null ? void 0 : a.extensions) || [], ...o],
2747
2680
  editorProps: {
2748
2681
  attributes: {
2749
2682
  "data-theme": e.theme || "light",
2750
2683
  ...t.editorDOMAttributes || {},
2751
2684
  class: [
2752
- P.bnEditor,
2753
- P.bnRoot,
2754
- t.defaultStyles ? P.defaultStyles : "",
2755
- ((a = t.editorDOMAttributes) == null ? void 0 : a.class) || ""
2685
+ H.bnEditor,
2686
+ H.bnRoot,
2687
+ t.defaultStyles ? H.defaultStyles : "",
2688
+ ((d = t.editorDOMAttributes) == null ? void 0 : d.class) || ""
2756
2689
  ].join(" ")
2757
2690
  }
2758
2691
  }
2759
2692
  };
2760
- t.parentElement && (r.element = t.parentElement), this._tiptapEditor = new Ut(r);
2693
+ t.parentElement && (s.element = t.parentElement), this._tiptapEditor = new Ut(s);
2694
+ }
2695
+ get prosemirrorView() {
2696
+ return this._tiptapEditor.view;
2761
2697
  }
2762
2698
  get domElement() {
2763
2699
  return this._tiptapEditor.view.dom;
@@ -2774,7 +2710,7 @@ class Ko {
2774
2710
  */
2775
2711
  get topLevelBlocks() {
2776
2712
  const e = [];
2777
- return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(B(t, this.schema, this.blockCache)), !1)), e;
2713
+ return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(M(t, this.schema, this.blockCache)), !1)), e;
2778
2714
  }
2779
2715
  /**
2780
2716
  * Gets a snapshot of an existing block from the editor.
@@ -2783,8 +2719,8 @@ class Ko {
2783
2719
  */
2784
2720
  getBlock(e) {
2785
2721
  const t = typeof e == "string" ? e : e.id;
2786
- let n;
2787
- return this._tiptapEditor.state.doc.firstChild.descendants((r) => typeof n < "u" ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== t ? !0 : (n = B(r, this.schema, this.blockCache), !1)), n;
2722
+ let o;
2723
+ return this._tiptapEditor.state.doc.firstChild.descendants((r) => typeof o < "u" ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== t ? !0 : (o = M(r, this.schema, this.blockCache), !1)), o;
2788
2724
  }
2789
2725
  /**
2790
2726
  * Traverses all blocks in the editor depth-first, and executes a callback for each.
@@ -2792,19 +2728,19 @@ class Ko {
2792
2728
  * @param reverse Whether the blocks should be traversed in reverse order.
2793
2729
  */
2794
2730
  forEachBlock(e, t = !1) {
2795
- const n = this.topLevelBlocks.slice();
2796
- t && n.reverse();
2731
+ const o = this.topLevelBlocks.slice();
2732
+ t && o.reverse();
2797
2733
  function r(i) {
2798
2734
  for (const s of i) {
2799
2735
  if (!e(s))
2800
2736
  return !1;
2801
- const a = t ? s.children.slice().reverse() : s.children;
2802
- if (!r(a))
2737
+ const l = t ? s.children.slice().reverse() : s.children;
2738
+ if (!r(l))
2803
2739
  return !1;
2804
2740
  }
2805
2741
  return !0;
2806
2742
  }
2807
- r(n);
2743
+ r(o);
2808
2744
  }
2809
2745
  /**
2810
2746
  * Executes a callback whenever the editor's contents change.
@@ -2813,22 +2749,29 @@ class Ko {
2813
2749
  onEditorContentChange(e) {
2814
2750
  this._tiptapEditor.on("update", e);
2815
2751
  }
2752
+ /**
2753
+ * Executes a callback whenever the editor's selection changes.
2754
+ * @param callback The callback to execute.
2755
+ */
2756
+ onEditorSelectionChange(e) {
2757
+ this._tiptapEditor.on("selectionUpdate", e);
2758
+ }
2816
2759
  /**
2817
2760
  * Gets a snapshot of the current text cursor position.
2818
2761
  * @returns A snapshot of the current text cursor position.
2819
2762
  */
2820
2763
  getTextCursorPosition() {
2821
- const { node: e, depth: t, startPos: n, endPos: r } = g(
2764
+ const { node: e, depth: t, startPos: o, endPos: r } = g(
2822
2765
  this._tiptapEditor.state.doc,
2823
2766
  this._tiptapEditor.state.selection.from
2824
2767
  ), i = this._tiptapEditor.state.doc.resolve(r).index(t - 1), s = this._tiptapEditor.state.doc.resolve(r + 1).node().childCount;
2825
- let a;
2826
- i > 0 && (a = this._tiptapEditor.state.doc.resolve(n - 2).node());
2827
2768
  let l;
2828
- return i < s - 1 && (l = this._tiptapEditor.state.doc.resolve(r + 2).node()), {
2829
- block: B(e, this.schema, this.blockCache),
2830
- prevBlock: a === void 0 ? void 0 : B(a, this.schema, this.blockCache),
2831
- nextBlock: l === void 0 ? void 0 : B(l, this.schema, this.blockCache)
2769
+ i > 0 && (l = this._tiptapEditor.state.doc.resolve(o - 2).node());
2770
+ let a;
2771
+ return i < s - 1 && (a = this._tiptapEditor.state.doc.resolve(r + 2).node()), {
2772
+ block: M(e, this.schema, this.blockCache),
2773
+ prevBlock: l === void 0 ? void 0 : M(l, this.schema, this.blockCache),
2774
+ nextBlock: a === void 0 ? void 0 : M(a, this.schema, this.blockCache)
2832
2775
  };
2833
2776
  }
2834
2777
  /**
@@ -2838,7 +2781,7 @@ class Ko {
2838
2781
  * @param placement Whether the text cursor should be placed at the start or end of the block.
2839
2782
  */
2840
2783
  setTextCursorPosition(e, t = "start") {
2841
- const n = typeof e == "string" ? e : e.id, { posBeforeNode: r } = J(n, this._tiptapEditor.state.doc), { startPos: i, contentNode: s } = g(
2784
+ const o = typeof e == "string" ? e : e.id, { posBeforeNode: r } = X(o, this._tiptapEditor.state.doc), { startPos: i, contentNode: s } = g(
2842
2785
  this._tiptapEditor.state.doc,
2843
2786
  r + 2
2844
2787
  );
@@ -2853,9 +2796,9 @@ class Ko {
2853
2796
  if (this._tiptapEditor.state.selection.from === this._tiptapEditor.state.selection.to)
2854
2797
  return;
2855
2798
  const e = [];
2856
- return this._tiptapEditor.state.doc.descendants((t, n) => t.type.spec.group !== "blockContent" || n + t.nodeSize < this._tiptapEditor.state.selection.from || n > this._tiptapEditor.state.selection.to ? !0 : (e.push(
2857
- B(
2858
- this._tiptapEditor.state.doc.resolve(n).node(),
2799
+ return this._tiptapEditor.state.doc.descendants((t, o) => t.type.spec.group !== "blockContent" || o + t.nodeSize < this._tiptapEditor.state.selection.from || o > this._tiptapEditor.state.selection.to ? !0 : (e.push(
2800
+ M(
2801
+ this._tiptapEditor.state.doc.resolve(o).node(),
2859
2802
  this.schema,
2860
2803
  this.blockCache
2861
2804
  )
@@ -2883,8 +2826,8 @@ class Ko {
2883
2826
  * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
2884
2827
  * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
2885
2828
  */
2886
- insertBlocks(e, t, n = "before") {
2887
- wt(e, t, n, this._tiptapEditor);
2829
+ insertBlocks(e, t, o = "before") {
2830
+ Tt(e, t, o, this._tiptapEditor);
2888
2831
  }
2889
2832
  /**
2890
2833
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
@@ -2894,14 +2837,14 @@ class Ko {
2894
2837
  * @param update A partial block which defines how the existing block should be changed.
2895
2838
  */
2896
2839
  updateBlock(e, t) {
2897
- Me(e, t, this._tiptapEditor);
2840
+ Ye(e, t, this._tiptapEditor);
2898
2841
  }
2899
2842
  /**
2900
2843
  * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
2901
2844
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
2902
2845
  */
2903
2846
  removeBlocks(e) {
2904
- St(e, this._tiptapEditor);
2847
+ Bt(e, this._tiptapEditor);
2905
2848
  }
2906
2849
  /**
2907
2850
  * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
@@ -2911,13 +2854,13 @@ class Ko {
2911
2854
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
2912
2855
  */
2913
2856
  replaceBlocks(e, t) {
2914
- Be(e, t, this._tiptapEditor);
2857
+ Je(e, t, this._tiptapEditor);
2915
2858
  }
2916
2859
  /**
2917
2860
  * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
2918
2861
  */
2919
2862
  getActiveStyles() {
2920
- const e = {}, t = this._tiptapEditor.state.selection.$to.marks(), n = /* @__PURE__ */ new Set([
2863
+ const e = {}, t = this._tiptapEditor.state.selection.$to.marks(), o = /* @__PURE__ */ new Set([
2921
2864
  "bold",
2922
2865
  "italic",
2923
2866
  "underline",
@@ -2925,7 +2868,7 @@ class Ko {
2925
2868
  "code"
2926
2869
  ]), r = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2927
2870
  for (const i of t)
2928
- n.has(i.type.name) ? e[i.type.name] = !0 : r.has(i.type.name) && (e[i.type.name] = i.attrs.color);
2871
+ o.has(i.type.name) ? e[i.type.name] = !0 : r.has(i.type.name) && (e[i.type.name] = i.attrs.color);
2929
2872
  return e;
2930
2873
  }
2931
2874
  /**
@@ -2939,10 +2882,10 @@ class Ko {
2939
2882
  "underline",
2940
2883
  "strike",
2941
2884
  "code"
2942
- ]), n = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2885
+ ]), o = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2943
2886
  this._tiptapEditor.view.focus();
2944
2887
  for (const [r, i] of Object.entries(e))
2945
- t.has(r) ? this._tiptapEditor.commands.setMark(r) : n.has(r) && this._tiptapEditor.commands.setMark(r, { color: i });
2888
+ t.has(r) ? this._tiptapEditor.commands.setMark(r) : o.has(r) && this._tiptapEditor.commands.setMark(r, { color: i });
2946
2889
  }
2947
2890
  /**
2948
2891
  * Removes styles from the currently selected content.
@@ -2964,10 +2907,10 @@ class Ko {
2964
2907
  "underline",
2965
2908
  "strike",
2966
2909
  "code"
2967
- ]), n = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2910
+ ]), o = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2968
2911
  this._tiptapEditor.view.focus();
2969
2912
  for (const [r, i] of Object.entries(e))
2970
- t.has(r) ? this._tiptapEditor.commands.toggleMark(r) : n.has(r) && this._tiptapEditor.commands.toggleMark(r, { color: i });
2913
+ t.has(r) ? this._tiptapEditor.commands.toggleMark(r) : o.has(r) && this._tiptapEditor.commands.toggleMark(r, { color: i });
2971
2914
  }
2972
2915
  /**
2973
2916
  * Gets the currently selected text.
@@ -2992,11 +2935,11 @@ class Ko {
2992
2935
  createLink(e, t) {
2993
2936
  if (e === "")
2994
2937
  return;
2995
- let { from: n, to: r } = this._tiptapEditor.state.selection;
2996
- t || (t = this._tiptapEditor.state.doc.textBetween(n, r));
2938
+ let { from: o, to: r } = this._tiptapEditor.state.selection;
2939
+ t || (t = this._tiptapEditor.state.doc.textBetween(o, r));
2997
2940
  const i = this._tiptapEditor.schema.mark("link", { href: e });
2998
2941
  this._tiptapEditor.view.dispatch(
2999
- this._tiptapEditor.view.state.tr.insertText(t, n, r).addMark(n, n + t.length, i)
2942
+ this._tiptapEditor.view.state.tr.insertText(t, o, r).addMark(o, o + t.length, i)
3000
2943
  );
3001
2944
  }
3002
2945
  /**
@@ -3048,7 +2991,7 @@ class Ko {
3048
2991
  * @returns The blocks parsed from the HTML string.
3049
2992
  */
3050
2993
  async HTMLToBlocks(e) {
3051
- return It(e, this.schema, this._tiptapEditor.schema);
2994
+ return _t(e, this.schema, this._tiptapEditor.schema);
3052
2995
  }
3053
2996
  /**
3054
2997
  * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
@@ -3057,7 +3000,7 @@ class Ko {
3057
3000
  * @returns The blocks, serialized as a Markdown string.
3058
3001
  */
3059
3002
  async blocksToMarkdown(e) {
3060
- return Se(e, this._tiptapEditor.schema);
3003
+ return Ze(e, this._tiptapEditor.schema);
3061
3004
  }
3062
3005
  /**
3063
3006
  * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
@@ -3067,7 +3010,7 @@ class Ko {
3067
3010
  * @returns The blocks parsed from the Markdown string.
3068
3011
  */
3069
3012
  async markdownToBlocks(e) {
3070
- return xe(e, this.schema, this._tiptapEditor.schema);
3013
+ return Qe(e, this.schema, this._tiptapEditor.schema);
3071
3014
  }
3072
3015
  /**
3073
3016
  * Updates the user info for the current user that's shown to other collaborators.
@@ -3081,19 +3024,29 @@ class Ko {
3081
3024
  }
3082
3025
  }
3083
3026
  export {
3084
- S as BaseSlashMenuItem,
3085
- Ko as BlockNoteEditor,
3086
- $e as CustomBlockSerializerExtension,
3087
- Yo as blockStyles,
3088
- ot as camelToDataKebab,
3089
- Vo as createBlockSpec,
3090
- H as createTipTapBlock,
3091
- ke as defaultBlockSchema,
3092
- A as defaultProps,
3093
- uo as defaultSlashMenuItems,
3094
- go as getBlockNoteExtensions,
3095
- de as parse,
3096
- le as propsToAttributes,
3097
- ce as render
3027
+ Wo as BlockNoteEditor,
3028
+ Oe as CustomBlockSerializerExtension,
3029
+ oo as FormattingToolbarProsemirrorPlugin,
3030
+ to as FormattingToolbarView,
3031
+ io as HyperlinkToolbarProsemirrorPlugin,
3032
+ ho as SideMenuProsemirrorPlugin,
3033
+ uo as SideMenuView,
3034
+ Ve as SlashMenuProsemirrorPlugin,
3035
+ jo as blockStyles,
3036
+ nt as camelToDataKebab,
3037
+ qo as createBlockSpec,
3038
+ P as createTipTapBlock,
3039
+ wt as defaultBlockSchema,
3040
+ N as defaultProps,
3041
+ eo as formattingToolbarPluginKey,
3042
+ We as getBlockNoteExtensions,
3043
+ fo as getDefaultSlashMenuItems,
3044
+ ro as hyperlinkToolbarPluginKey,
3045
+ ge as parse,
3046
+ me as propsToAttributes,
3047
+ ke as render,
3048
+ ze as setupSuggestionsMenu,
3049
+ po as sideMenuPluginKey,
3050
+ K as slashMenuPluginKey
3098
3051
  };
3099
3052
  //# sourceMappingURL=blocknote.js.map