@blocknote/core 0.8.2 → 0.8.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +4 -0
  2. package/dist/blocknote.js +1777 -1849
  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 +4 -4
  8. package/src/BlockNoteEditor.ts +89 -39
  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/FormattingToolbar/FormattingToolbarPlugin.ts +101 -114
  17. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +184 -149
  18. package/src/extensions/Placeholder/PlaceholderExtension.ts +2 -2
  19. package/src/extensions/{DraggableBlocks/DraggableBlocksPlugin.ts → SideMenu/SideMenuPlugin.ts} +181 -164
  20. package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -30
  21. package/src/extensions/SlashMenu/SlashMenuPlugin.ts +51 -0
  22. package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +109 -0
  23. package/src/extensions/UniqueID/UniqueID.ts +29 -30
  24. package/src/index.ts +9 -8
  25. package/src/shared/BaseUiElementTypes.ts +8 -0
  26. package/src/shared/EditorElement.ts +0 -16
  27. package/src/shared/EventEmitter.ts +58 -0
  28. package/src/shared/plugins/suggestion/SuggestionItem.ts +3 -6
  29. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +341 -403
  30. package/types/src/BlockNoteEditor.d.ts +18 -11
  31. package/types/src/BlockNoteExtensions.d.ts +0 -19
  32. package/types/src/extensions/Blocks/api/blockTypes.d.ts +3 -2
  33. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +18 -24
  34. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +37 -10
  35. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +79 -0
  36. package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -18
  37. package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +13 -0
  38. package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +1 -69
  39. package/types/src/index.d.ts +9 -8
  40. package/types/src/shared/BaseUiElementTypes.d.ts +7 -0
  41. package/types/src/shared/EditorElement.d.ts +0 -10
  42. package/types/src/shared/EventEmitter.d.ts +11 -0
  43. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +2 -7
  44. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +12 -43
  45. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +0 -29
  46. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +0 -37
  47. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +0 -37
  48. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +0 -18
  49. package/src/extensions/HyperlinkToolbar/HyperlinkMark.ts +0 -28
  50. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +0 -19
  51. package/src/extensions/SlashMenu/SlashMenuExtension.ts +0 -53
  52. package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +0 -195
  53. package/src/extensions/SlashMenu/index.ts +0 -5
  54. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +0 -21
  55. package/types/src/CustomBlock.d.ts +0 -15
  56. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableCol.d.ts +0 -2
  57. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableContent.d.ts +0 -2
  58. package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableRow.d.ts +0 -2
  59. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +0 -17
  60. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +0 -16
  61. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +0 -49
  62. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +0 -11
  63. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +0 -10
  64. package/types/src/extensions/HyperlinkToolbar/HyperlinkMark.d.ts +0 -8
  65. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +0 -12
  66. package/types/src/extensions/Placeholder/localisation/index.d.ts +0 -2
  67. package/types/src/extensions/Placeholder/localisation/translation.d.ts +0 -51
  68. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +0 -13
  69. package/types/src/extensions/SlashMenu/index.d.ts +0 -4
  70. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +0 -12
  71. /package/src/extensions/{DraggableBlocks → SideMenu}/MultipleNodeSelection.ts +0 -0
  72. /package/types/src/extensions/{DraggableBlocks → SideMenu}/MultipleNodeSelection.d.ts +0 -0
package/dist/blocknote.js CHANGED
@@ -1,150 +1,242 @@
1
- var Nt = Object.defineProperty;
2
- var Lt = (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) => (Lt(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { Node as R, InputRule as V, mergeAttributes as x, 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 T, Fragment as P, 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 Vt from "remark-rehype";
14
- import Yt from "remark-stringify";
15
- import { unified as Y } 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
- }, Vo = /* @__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 Yo(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 V({
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
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,16 +314,16 @@ 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() {
254
321
  return [
255
322
  // Creates an unordered list when starting with "-", "+", or "*".
256
- new V({
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
- x(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
  };
@@ -353,10 +420,10 @@ const Et = (o) => {
353
420
  addInputRules() {
354
421
  return [
355
422
  // Creates an ordered list when starting with "1.".
356
- new V({
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
- x(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
- x(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
- }), L = {
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: L,
453
- node: ge
519
+ propSchema: N,
520
+ node: Ce
454
521
  },
455
522
  heading: {
456
523
  propSchema: {
457
- ...L,
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: L,
464
- node: he
530
+ propSchema: N,
531
+ node: ye
465
532
  },
466
533
  numberedListItem: {
467
- propSchema: L,
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
- (B) => l.includes(B.type.name)
548
- ), y = b.map(({ node: B }) => B.attrs[d]).filter((B) => B !== null), U = be(y);
549
- b.forEach(({ node: B, 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
- ...B.attrs,
636
+ l.setNodeMarkup(D, void 0, {
637
+ ...C.attrs,
555
638
  [d]: c()
556
639
  });
557
640
  return;
558
641
  }
559
- const { deleted: At } = p.invert().mapResult(O);
560
- At && U.includes(Z) && a.setNodeMarkup(O, void 0, {
561
- ...B.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
- }), P.from(a);
700
+ l.push(d);
701
+ }), I.from(l);
619
702
  };
620
- return e = !1, new T(
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
- ]), Bt = /* @__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)) : Bt.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 wt(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 wt(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 Mt(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(...wt([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 = Mt(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 (Bt.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 w(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 L) && 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
- w(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 Tt(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 Be(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 xt(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 we(o, e, t) {
889
- Tt(e, o[0], "before", t), xt(o, t);
890
- }
891
- function Me() {
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 Te(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 St(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 Y().use(lt, { fragment: !0 }).use(Te, {
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(w(i.firstChild.child(a), e));
968
- return s;
909
+ return t == null || t.set(n, d), d;
969
910
  }
970
- async function xe(o, e) {
971
- return (await Y().use(lt, { fragment: !0 }).use(Me).use(qt).use(ct).use(Yt).process(await St(o, e))).value;
972
- }
973
- async function Se(o, e, t) {
974
- const n = await Y().use(Wt).use(ct).use(Vt).use(dt).process(o);
975
- return It(n.value, e, t);
976
- }
977
- const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4vj2p_35", Ae = "_dragPreview_4vj2p_68", _ = {
978
- bnEditor: Ie,
979
- bnRoot: Pe,
980
- defaultStyles: _e,
981
- dragPreview: Ae,
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
- }), Le = 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", Pe = "_bnRoot_4vj2p_20", _e = "_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", Pe = "_bnRoot_4vj2p_20", _e = "_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", Pe = "_bnRoot_4vj2p_20", _e = "_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", Pe = "_bnRoot_4vj2p_20", _e = "_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
- x(o, {
1034
+ x(n, {
1167
1035
  class: k.blockOuter,
1168
1036
  "data-node-type": "block-outer"
1169
1037
  }),
1170
1038
  [
1171
1039
  "div",
1172
- x(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", Pe = "_bnRoot_4vj2p_20", _e = "_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 T(P.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 = Mt(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 T(P.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,46 +1120,46 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_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
1141
  return t && (t(
1274
- e.tr.deleteRange(l, l + a.nodeSize).replace(
1275
- u - 1,
1276
- l,
1277
- new T(a.content, 0, 0)
1142
+ e.tr.deleteRange(a, a + l.nodeSize).replace(
1143
+ p - 1,
1144
+ a,
1145
+ new B(l.content, 0, 0)
1278
1146
  ).scrollIntoView()
1279
1147
  ), e.tr.setSelection(
1280
- new tt(e.doc.resolve(u - 1))
1148
+ new et(e.doc.resolve(p - 1))
1281
1149
  )), !0;
1282
1150
  },
1283
1151
  // Splits a block at a given position. Content after the position is moved to a new block below, at the same
1284
1152
  // nesting level.
1285
- BNSplitBlock: (o, e) => ({ state: t, dispatch: n }) => {
1286
- const r = g(t.doc, o);
1153
+ BNSplitBlock: (n, e) => ({ state: t, dispatch: o }) => {
1154
+ const r = g(t.doc, n);
1287
1155
  if (r === void 0)
1288
1156
  return !1;
1289
- 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;
1290
- 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(
1291
1159
  m,
1292
1160
  m + 1,
1293
- u.content.size > 0 ? new T(
1294
- P.from(u),
1161
+ p.content.size > 0 ? new B(
1162
+ I.from(p),
1295
1163
  d + 2,
1296
1164
  d + 2
1297
1165
  ) : void 0
@@ -1301,12 +1169,12 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4v
1301
1169
  t.schema.node(s).type,
1302
1170
  i.attrs
1303
1171
  ), t.tr.setSelection(
1304
- new tt(t.doc.resolve(m))
1172
+ new et(t.doc.resolve(m))
1305
1173
  ), t.tr.replace(
1306
- a + 1,
1307
- l - 1,
1308
- c.content.size > 0 ? new T(
1309
- P.from(c),
1174
+ l + 1,
1175
+ a - 1,
1176
+ c.content.size > 0 ? new B(
1177
+ I.from(c),
1310
1178
  d + 2,
1311
1179
  d + 2
1312
1180
  ) : void 0
@@ -1315,7 +1183,7 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4v
1315
1183
  };
1316
1184
  },
1317
1185
  addProseMirrorPlugins() {
1318
- return [Oe()];
1186
+ return [Ie()];
1319
1187
  },
1320
1188
  addKeyboardShortcuts() {
1321
1189
  return {
@@ -1325,59 +1193,59 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4v
1325
1193
  // Undoes an input rule if one was triggered in the last editor state change.
1326
1194
  () => t.undoInputRule(),
1327
1195
  // Reverts block content type to a paragraph if the selection is at the start of the block.
1328
- () => t.command(({ state: n }) => {
1196
+ () => t.command(({ state: o }) => {
1329
1197
  const { contentType: r } = g(
1330
- n.doc,
1331
- n.selection.from
1332
- ), i = n.selection.$anchor.parentOffset === 0, s = r.name === "paragraph";
1333
- 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, {
1334
1202
  type: "paragraph",
1335
1203
  props: {}
1336
1204
  }) : !1;
1337
1205
  }),
1338
1206
  // Removes a level of nesting if the block is indented if the selection is at the start of the block.
1339
- () => 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),
1340
1208
  // Merges block with the previous one if it isn't indented, isn't the first block in the doc, and the selection
1341
1209
  // is at the start of the block.
1342
- () => t.command(({ state: n }) => {
1210
+ () => t.command(({ state: o }) => {
1343
1211
  const { depth: r, startPos: i } = g(
1344
- n.doc,
1345
- n.selection.from
1346
- ), s = n.selection.$anchor.parentOffset === 0, a = n.selection.anchor === n.selection.head, l = i === 2, d = i - 1;
1347
- 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;
1348
1216
  })
1349
1217
  ]),
1350
1218
  Enter: () => this.editor.commands.first(({ commands: t }) => [
1351
1219
  // Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
1352
1220
  // of the block.
1353
- () => t.command(({ state: n }) => {
1221
+ () => t.command(({ state: o }) => {
1354
1222
  const { node: r, depth: i } = g(
1355
- n.doc,
1356
- n.selection.from
1357
- ), s = n.selection.$anchor.parentOffset === 0, a = n.selection.anchor === n.selection.head, l = r.textContent.length === 0, d = i > 2;
1358
- 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;
1359
1227
  }),
1360
1228
  // Creates a new block and moves the selection to it if the current one is empty, while the selection is also
1361
1229
  // empty & at the start of the block.
1362
- () => t.command(({ state: n, chain: r }) => {
1230
+ () => t.command(({ state: o, chain: r }) => {
1363
1231
  const { node: i, endPos: s } = g(
1364
- n.doc,
1365
- n.selection.from
1366
- ), a = n.selection.$anchor.parentOffset === 0, l = n.selection.anchor === n.selection.head, d = i.textContent.length === 0;
1367
- if (a && l && d) {
1368
- const c = s + 1, u = c + 2;
1369
- 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;
1370
1238
  }
1371
1239
  return !1;
1372
1240
  }),
1373
1241
  // Splits the current block, moving content inside that's after the cursor to a new text block below. Also
1374
1242
  // deletes the selection beforehand, if it's not empty.
1375
- () => t.command(({ state: n, chain: r }) => {
1243
+ () => t.command(({ state: o, chain: r }) => {
1376
1244
  const { node: i } = g(
1377
- n.doc,
1378
- n.selection.from
1245
+ o.doc,
1246
+ o.selection.from
1379
1247
  );
1380
- 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);
1381
1249
  })
1382
1250
  ]),
1383
1251
  // Always returning true for tab key presses ensures they're not captured by the browser. Otherwise, they blur the
@@ -1415,7 +1283,7 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4v
1415
1283
  })
1416
1284
  };
1417
1285
  }
1418
- }), Re = R.create({
1286
+ }), Le = V.create({
1419
1287
  name: "blockGroup",
1420
1288
  group: "blockGroup",
1421
1289
  content: "blockContainer+",
@@ -1428,30 +1296,30 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4v
1428
1296
  return [
1429
1297
  {
1430
1298
  tag: "div",
1431
- 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
1432
1300
  }
1433
1301
  ];
1434
1302
  },
1435
- renderHTML({ HTMLAttributes: o }) {
1303
+ renderHTML({ HTMLAttributes: n }) {
1436
1304
  return [
1437
1305
  "div",
1438
- x(this.options.HTMLAttributes, o, {
1306
+ x(this.options.HTMLAttributes, n, {
1439
1307
  class: k.blockGroup,
1440
1308
  "data-node-type": "blockGroup"
1441
1309
  }),
1442
1310
  0
1443
1311
  ];
1444
1312
  }
1445
- }), ze = [
1446
- Fe,
1447
- Re,
1448
- R.create({
1313
+ }), Ne = [
1314
+ Ae,
1315
+ Le,
1316
+ V.create({
1449
1317
  name: "doc",
1450
1318
  topNode: !0,
1451
1319
  content: "blockGroup"
1452
1320
  })
1453
- ], Ue = (o) => {
1454
- const e = q.fromSchema(o);
1321
+ ], Pe = (n) => {
1322
+ const e = q.fromSchema(n);
1455
1323
  return new q(
1456
1324
  {
1457
1325
  ...e.nodes
@@ -1462,19 +1330,82 @@ const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4v
1462
1330
  },
1463
1331
  e.marks
1464
1332
  );
1465
- }, $e = v.create({
1333
+ }, Oe = T.create({
1466
1334
  addProseMirrorPlugins() {
1467
1335
  return [
1468
- new C({
1336
+ new y({
1469
1337
  props: {
1470
- clipboardSerializer: Ue(this.editor.schema)
1338
+ clipboardSerializer: Pe(this.editor.schema)
1471
1339
  }
1472
1340
  })
1473
1341
  ];
1474
1342
  }
1475
- }), Ge = Ft(
1476
- (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"
1477
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
+ }
1478
1409
  function W() {
1479
1410
  return {
1480
1411
  active: !1,
@@ -1486,264 +1417,861 @@ function W() {
1486
1417
  decorationId: void 0
1487
1418
  };
1488
1419
  }
1489
- class je {
1490
- constructor({
1491
- editor: e,
1492
- pluginKey: t,
1493
- onSelectItem: n = () => {
1494
- },
1495
- suggestionsMenuFactory: r
1496
- }) {
1497
- h(this, "editor");
1498
- h(this, "pluginKey");
1499
- h(this, "suggestionsMenu");
1500
- h(this, "pluginState");
1501
- h(this, "itemCallback");
1502
- h(this, "lastPosition");
1503
- this.editor = e, this.pluginKey = t, this.pluginState = W(), this.itemCallback = (i) => {
1504
- e._tiptapEditor.chain().focus().deleteRange({
1505
- from: this.pluginState.queryStartPos - this.pluginState.triggerCharacter.length,
1506
- to: e._tiptapEditor.state.selection.from
1507
- }).run(), n({
1508
- item: i,
1509
- editor: e
1510
- });
1511
- }, this.suggestionsMenu = r(this.getStaticParams());
1512
- }
1513
- update(e, t) {
1514
- 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;
1515
- !i && !a && !s || (this.pluginState = s ? n : r, (s || !this.editor.isEditable) && (this.suggestionsMenu.hide(), this.suggestionsMenu.element.removeEventListener(
1516
- "mousedown",
1517
- (l) => l.preventDefault()
1518
- )), a && this.suggestionsMenu.render(this.getDynamicParams(), !1), i && this.editor.isEditable && (this.suggestionsMenu.render(this.getDynamicParams(), !0), this.suggestionsMenu.element.addEventListener(
1519
- "mousedown",
1520
- (l) => l.preventDefault()
1521
- )));
1522
- }
1523
- getStaticParams() {
1524
- return {
1525
- itemCallback: (e) => this.itemCallback(e),
1526
- getReferenceRect: () => {
1527
- const e = document.querySelector(
1528
- `[data-decoration-id="${this.pluginState.decorationId}"]`
1529
- );
1530
- if (!e) {
1531
- if (this.lastPosition === void 0)
1532
- throw new Error(
1533
- "Attempted to access trigger character reference rect before rendering suggestions menu."
1534
- );
1535
- return this.lastPosition;
1420
+ const ze = (n, e, t, o, r = () => [], i = () => {
1421
+ }) => {
1422
+ if (o.length !== 1)
1423
+ throw new Error("'char' should be a single character");
1424
+ let s;
1425
+ const l = (a) => {
1426
+ a.dispatch(a.state.tr.setMeta(t, { deactivate: !0 }));
1427
+ };
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() {
1439
+ return W();
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;
1484
+ }
1485
+ },
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
+ ]);
1536
1551
  }
1537
- const t = e.getBoundingClientRect();
1538
- return this.lastPosition = t, t;
1539
1552
  }
1540
- };
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
+ });
1562
+ }
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;
1541
1585
  }
1542
- getDynamicParams() {
1543
- return {
1544
- items: this.pluginState.items,
1545
- keyboardHoveredItemIndex: this.pluginState.keyboardHoveredItemIndex
1546
- };
1586
+ onUpdate(t) {
1587
+ return this.on("update", t);
1547
1588
  }
1548
1589
  }
1549
- function qe({
1550
- pluginKey: o,
1551
- editor: e,
1552
- defaultTriggerCharacter: t,
1553
- suggestionsMenuFactory: n,
1554
- onSelectItem: r = () => {
1590
+ const Ue = new S("blocknote-placeholder"), Fe = T.create({
1591
+ name: "placeholder",
1592
+ addOptions() {
1593
+ return {
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
1602
+ };
1555
1603
  },
1556
- items: i = () => []
1557
- }) {
1558
- if (t.length !== 1)
1559
- throw new Error("'char' should be a single character");
1560
- const s = (a) => {
1561
- a.dispatch(a.state.tr.setMeta(o, { deactivate: !0 }));
1562
- };
1563
- return new C({
1564
- key: o,
1565
- view: (a) => new je({
1566
- editor: e,
1567
- pluginKey: o,
1568
- onSelectItem: (l) => {
1569
- s(a), r(l);
1570
- },
1571
- suggestionsMenuFactory: n
1572
- }),
1573
- state: {
1574
- // Initialize the plugin's internal state.
1575
- init() {
1576
- return W();
1577
- },
1578
- // Apply changes to the plugin state from an editor transaction.
1579
- apply(a, l, d, c) {
1580
- var p, f, m, b;
1581
- if (a.getMeta("orderedListIndexing") !== void 0)
1582
- return l;
1583
- if ((p = a.getMeta(o)) != null && p.activate)
1584
- return {
1585
- active: !0,
1586
- triggerCharacter: ((f = a.getMeta(o)) == null ? void 0 : f.triggerCharacter) || "",
1587
- queryStartPos: c.selection.from,
1588
- items: i(""),
1589
- keyboardHoveredItemIndex: 0,
1590
- // TODO: Maybe should be 1 if the menu has no possible items? Probably redundant since a menu with no items
1591
- // is useless in practice.
1592
- notFoundCount: 0,
1593
- decorationId: `id_${Math.floor(Math.random() * 4294967295)}`
1594
- };
1595
- if (!l.active)
1596
- return l;
1597
- const u = { ...l };
1598
- if (u.items = i(
1599
- c.doc.textBetween(l.queryStartPos, c.selection.from)
1600
- ), u.notFoundCount = 0, u.items.length === 0 && (u.notFoundCount = Math.max(
1601
- 0,
1602
- l.notFoundCount + (c.selection.from - d.selection.from)
1603
- )), // Highlighting text should hide the menu.
1604
- c.selection.from !== c.selection.to || // Transactions with plugin metadata {deactivate: true} should hide the menu.
1605
- (m = a.getMeta(o)) != null && m.deactivate || // Certain mouse events should hide the menu.
1606
- // TODO: Change to global mousedown listener.
1607
- a.getMeta("focus") || a.getMeta("blur") || a.getMeta("pointer") || // Moving the caret before the character which triggered the menu should hide it.
1608
- 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
1609
- // the menu.
1610
- u.notFoundCount > 3)
1611
- return W();
1612
- if (((b = a.getMeta(o)) == null ? void 0 : b.selectedItemIndexChanged) !== void 0) {
1613
- let y = a.getMeta(o).selectedItemIndexChanged;
1614
- y < 0 ? y = l.items.length - 1 : y >= l.items.length && (y = 0), u.keyboardHoveredItemIndex = y;
1604
+ addProseMirrorPlugins() {
1605
+ return [
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
+ }
1625
+ }
1626
+ })
1627
+ ];
1628
+ }
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
+ }
1615
1645
  }
1616
- return u;
1617
1646
  }
1618
- },
1619
- props: {
1620
- handleKeyDown(a, l) {
1621
- const d = this.getState(a.state).active;
1622
- if (l.key === t && !d)
1623
- return a.dispatch(
1624
- a.state.tr.insertText(t).scrollIntoView().setMeta(o, {
1625
- activate: !0,
1626
- triggerCharacter: t
1627
- })
1628
- ), !0;
1629
- if (!d)
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)
1630
1657
  return !1;
1631
- const {
1632
- triggerCharacter: c,
1633
- queryStartPos: u,
1634
- items: p,
1635
- keyboardHoveredItemIndex: f
1636
- } = o.getState(a.state);
1637
- return l.key === "ArrowUp" ? (a.dispatch(
1638
- a.state.tr.setMeta(o, {
1639
- selectedItemIndexChanged: f - 1
1640
- })
1641
- ), !0) : l.key === "ArrowDown" ? (a.dispatch(
1642
- a.state.tr.setMeta(o, {
1643
- selectedItemIndexChanged: f + 1
1644
- })
1645
- ), !0) : l.key === "Enter" ? (s(a), e._tiptapEditor.chain().focus().deleteRange({
1646
- from: u - c.length,
1647
- to: e._tiptapEditor.state.selection.from
1648
- }).run(), r({
1649
- item: p[f],
1650
- editor: e
1651
- }), !0) : l.key === "Escape" ? (s(a), !0) : !1;
1652
- },
1653
- // Hides menu in cases where mouse click does not cause an editor state change.
1654
- handleClick(a) {
1655
- s(a);
1656
- },
1657
- // Setup decorator on the currently active suggestion.
1658
- decorations(a) {
1659
- const { active: l, decorationId: d, queryStartPos: c, triggerCharacter: u } = this.getState(a);
1660
- if (!l)
1661
- return null;
1662
- if (u === "") {
1663
- const p = Ge(a.selection);
1664
- if (p)
1665
- return F.create(a.doc, [
1666
- D.node(
1667
- p.pos,
1668
- p.pos + p.node.nodeSize,
1669
- {
1670
- nodeName: "span",
1671
- class: "suggestion-decorator",
1672
- "data-decoration-id": d
1673
- }
1674
- )
1675
- ]);
1676
- }
1677
- return F.create(a.doc, [
1678
- D.inline(
1679
- c - u.length,
1680
- c,
1681
- {
1682
- nodeName: "span",
1683
- class: "suggestion-decorator",
1684
- "data-decoration-id": d
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
1685
1679
  }
1686
- )
1687
- ]);
1680
+ }
1681
+ }
1688
1682
  }
1689
- }
1690
- });
1691
- }
1692
- const X = new E("suggestions-slash-commands"), We = () => v.create({
1693
- name: "slash-command",
1694
- addOptions() {
1683
+ ];
1684
+ },
1685
+ addCommands() {
1695
1686
  return {
1696
- editor: void 0,
1697
- commands: void 0,
1698
- slashMenuFactory: void 0
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
+ }
1699
1704
  };
1700
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",
1701
1724
  addProseMirrorPlugins() {
1702
- if (!this.options.slashMenuFactory || !this.options.commands)
1703
- throw new Error("required args not defined for SlashMenuExtension");
1704
- const o = this.options.commands;
1725
+ const n = new S(this.name);
1705
1726
  return [
1706
- qe({
1707
- pluginKey: X,
1708
- editor: this.options.editor,
1709
- defaultTriggerCharacter: "/",
1710
- suggestionsMenuFactory: this.options.slashMenuFactory,
1711
- items: (e) => o.filter(
1712
- (t) => t.match(e)
1713
- ),
1714
- onSelectItem: ({ item: e, editor: t }) => {
1715
- e.execute(t);
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
+ }
1716
1750
  }
1717
1751
  })
1718
1752
  ];
1719
1753
  }
1720
- });
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
+ }
1721
2249
  class A extends G {
1722
- constructor(t, n) {
1723
- super(t, n);
1724
- h(this, "nodes");
2250
+ constructor(t, o) {
2251
+ super(t, o);
2252
+ u(this, "nodes");
1725
2253
  const r = t.node();
1726
- this.nodes = [], t.doc.nodesBetween(t.pos, n.pos, (i, s, a) => {
1727
- 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))
1728
2256
  return this.nodes.push(i), !1;
1729
2257
  });
1730
2258
  }
1731
- static create(t, n, r = n) {
1732
- return new A(t.resolve(n), t.resolve(r));
2259
+ static create(t, o, r = o) {
2260
+ return new A(t.resolve(o), t.resolve(r));
1733
2261
  }
1734
2262
  content() {
1735
- return new T(P.from(this.nodes), 0, 0);
2263
+ return new B(I.from(this.nodes), 0, 0);
1736
2264
  }
1737
2265
  eq(t) {
1738
2266
  if (!(t instanceof A) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to)
1739
2267
  return !1;
1740
- for (let n = 0; n < this.nodes.length; n++)
1741
- 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]))
1742
2270
  return !1;
1743
2271
  return !0;
1744
2272
  }
1745
- map(t, n) {
1746
- let r = n.mapResult(this.from), i = n.mapResult(this.to);
2273
+ map(t, o) {
2274
+ let r = o.mapResult(this.from), i = o.mapResult(this.to);
1747
2275
  return i.deleted ? G.near(t.resolve(r.pos)) : r.deleted ? G.near(t.resolve(i.pos)) : new A(
1748
2276
  t.resolve(r.pos),
1749
2277
  t.resolve(i.pos)
@@ -1753,108 +2281,100 @@ class A extends G {
1753
2281
  return { type: "node", anchor: this.anchor, head: this.head };
1754
2282
  }
1755
2283
  }
1756
- const Ve = ae.__serializeForClipboard;
1757
- let M;
1758
- function Pt(o, e) {
2284
+ const so = re.__serializeForClipboard;
2285
+ let E;
2286
+ function It(n, e) {
1759
2287
  var r;
1760
2288
  if (!e.dom.isConnected)
1761
2289
  return;
1762
- let t = e.posAtCoords(o);
2290
+ let t = e.posAtCoords(n);
1763
2291
  if (!t)
1764
2292
  return;
1765
- let n = e.domAtPos(t.pos).node;
1766
- if (n !== e.dom) {
1767
- for (; n && n.parentNode && n.parentNode !== e.dom && !((r = n.hasAttribute) != null && r.call(n, "data-id")); )
1768
- n = n.parentNode;
1769
- if (n)
1770
- 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") };
1771
2299
  }
1772
2300
  }
1773
- function Ye(o, e) {
1774
- let t = Pt(o, e);
2301
+ function ao(n, e) {
2302
+ let t = It(n, e);
1775
2303
  if (t && t.node.nodeType === 1) {
1776
- const n = e.docView;
1777
- let r = n.nearestDesc(t.node, !0);
1778
- 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;
1779
2307
  }
1780
2308
  return null;
1781
2309
  }
1782
- function Ke(o, e) {
1783
- let t, n;
1784
- 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);
1785
2313
  if (r && i) {
1786
- const a = o.$from.start(s - 1), l = o.$to.end(s - 1);
1787
- 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;
1788
2316
  } else
1789
- t = o.from, n = o.to;
1790
- return { from: t, to: n };
2317
+ t = n.from, o = n.to;
2318
+ return { from: t, to: o };
1791
2319
  }
1792
- function it(o, e, t = e) {
1793
- e === t && (t += o.state.doc.resolve(e + 1).node().nodeSize);
1794
- 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(
1795
2323
  r,
1796
2324
  // Expects from position to be just before the first selected block.
1797
- o.domAtPos(e + 1).node.parentElement
1798
- ), a = i(
2325
+ n.domAtPos(e + 1).node.parentElement
2326
+ ), l = i(
1799
2327
  r,
1800
2328
  // Expects to position to be just after the last selected block.
1801
- o.domAtPos(t - 1).node.parentElement
2329
+ n.domAtPos(t - 1).node.parentElement
1802
2330
  );
1803
2331
  for (let c = r.childElementCount - 1; c >= 0; c--)
1804
- (c > a || c < s) && n.removeChild(n.children[c]);
1805
- _t(), M = n;
1806
- 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(
1807
2335
  (c) => !c.includes("bn") && !c.includes("ProseMirror") && !c.includes("editor")
1808
2336
  ).join(" ");
1809
- M.className = M.className + " " + _.dragPreview + " " + d, document.body.appendChild(M);
2337
+ E.className = E.className + " " + H.dragPreview + " " + d, document.body.appendChild(E);
1810
2338
  }
1811
- function _t() {
1812
- M !== void 0 && (document.body.removeChild(M), M = void 0);
2339
+ function Ht() {
2340
+ E !== void 0 && (document.body.removeChild(E), E = void 0);
1813
2341
  }
1814
- function Je(o, e) {
1815
- if (!o.dataTransfer)
2342
+ function co(n, e) {
2343
+ if (!n.dataTransfer)
1816
2344
  return;
1817
2345
  const t = e.dom.getBoundingClientRect();
1818
- let n = {
2346
+ let o = {
1819
2347
  left: t.left + t.width / 2,
1820
2348
  // take middle of editor
1821
- top: o.clientY
1822
- }, r = Ye(n, e);
2349
+ top: n.clientY
2350
+ }, r = ao(o, e);
1823
2351
  if (r != null) {
1824
- 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 A;
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;
1825
2353
  d && c ? (e.dispatch(
1826
- e.state.tr.setSelection(A.create(s, a, l))
1827
- ), it(e, a, l)) : (e.dispatch(
1828
- e.state.tr.setSelection($t.create(e.state.doc, r))
1829
- ), it(e, r));
1830
- let u = e.state.selection.content(), { dom: p, text: f } = Ve(e, u);
1831
- o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", p.innerHTML), o.dataTransfer.setData("text/plain", f), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(M, 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 };
1832
2360
  }
1833
2361
  }
1834
- class Xe {
1835
- constructor({
1836
- tiptapEditor: e,
1837
- editor: t,
1838
- blockMenuFactory: n,
1839
- horizontalPosAnchoredAtRoot: r
1840
- }) {
1841
- h(this, "editor");
1842
- h(this, "ttEditor");
2362
+ class uo {
2363
+ constructor(e, t, o) {
2364
+ u(this, "sideMenuState");
1843
2365
  // When true, the drag handle with be anchored at the same level as root elements
1844
2366
  // When false, the drag handle with be just to the left of the element
1845
- h(this, "horizontalPosAnchoredAtRoot");
1846
- h(this, "horizontalPosAnchor");
1847
- h(this, "blockMenu");
1848
- 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");
1849
2371
  // Used to check if currently dragged content comes from this editor instance.
1850
- h(this, "isDragging", !1);
1851
- h(this, "menuOpen", !1);
1852
- h(this, "menuFrozen", !1);
1853
- h(this, "lastPosition");
2372
+ u(this, "isDragging", !1);
2373
+ u(this, "menuFrozen", !1);
1854
2374
  /**
1855
2375
  * Sets isDragging when dragging text.
1856
2376
  */
1857
- h(this, "onDragStart", () => {
2377
+ u(this, "onDragStart", () => {
1858
2378
  this.isDragging = !0;
1859
2379
  });
1860
2380
  /**
@@ -1862,16 +2382,16 @@ class Xe {
1862
2382
  * we dispatch a fake event, so that we can still drop the content
1863
2383
  * when dragging / dropping to the side of the editor
1864
2384
  */
1865
- h(this, "onDrop", (e) => {
1866
- if (e.synthetic || !this.isDragging)
2385
+ u(this, "onDrop", (e) => {
2386
+ if (this.editor._tiptapEditor.commands.blur(), e.synthetic || !this.isDragging)
1867
2387
  return;
1868
- let t = this.ttEditor.view.posAtCoords({
2388
+ let t = this.pmView.posAtCoords({
1869
2389
  left: e.clientX,
1870
2390
  top: e.clientY
1871
2391
  });
1872
2392
  if (this.isDragging = !1, !t || t.inside === -1) {
1873
- const n = new Event("drop", e), r = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
1874
- 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);
1875
2395
  }
1876
2396
  });
1877
2397
  /**
@@ -1879,854 +2399,225 @@ class Xe {
1879
2399
  * we dispatch a fake event, so that we can still drop the content
1880
2400
  * when dragging / dropping to the side of the editor
1881
2401
  */
1882
- h(this, "onDragOver", (e) => {
2402
+ u(this, "onDragOver", (e) => {
1883
2403
  if (e.synthetic || !this.isDragging)
1884
2404
  return;
1885
- let t = this.ttEditor.view.posAtCoords({
2405
+ let t = this.pmView.posAtCoords({
1886
2406
  left: e.clientX,
1887
2407
  top: e.clientY
1888
2408
  });
1889
2409
  if (!t || t.inside === -1) {
1890
- const n = new Event("dragover", e), r = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
1891
- 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);
1892
2412
  }
1893
2413
  });
1894
- h(this, "onKeyDown", (e) => {
1895
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1;
1896
- });
1897
- h(this, "onMouseDown", (e) => {
2414
+ u(this, "onKeyDown", (e) => {
1898
2415
  var t;
1899
- (t = this.blockMenu.element) != null && t.contains(e.target) || (this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1);
2416
+ (t = this.sideMenuState) != null && t.show && (this.sideMenuState.show = !1, this.updateSideMenu(this.sideMenuState)), this.menuFrozen = !1;
1900
2417
  });
1901
- h(this, "onMouseMove", (e) => {
1902
- var l, d, c;
2418
+ u(this, "onMouseMove", (e) => {
2419
+ var d, c, p, h, f;
1903
2420
  if (this.menuFrozen)
1904
2421
  return;
1905
- const t = this.ttEditor.view.dom.firstChild.getBoundingClientRect(), n = this.ttEditor.view.dom.getBoundingClientRect();
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;
1906
2423
  if (
1907
2424
  // Cursor is within the editor area
1908
- e.clientX >= n.left && e.clientX <= n.right && e.clientY >= n.top && e.clientY <= n.bottom && // An element is hovered
1909
- e && e.target && // Element is outside the editor
1910
- this.ttEditor.view.dom !== e.target && !this.ttEditor.view.dom.contains(e.target) && // Element is outside the side menu
1911
- this.blockMenu.element !== e.target && !((l = this.blockMenu.element) != null && l.contains(e.target))
1912
- ) {
1913
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
1914
- return;
1915
- }
1916
- this.horizontalPosAnchor = t.x;
1917
- const i = {
1918
- left: t.left + t.width / 2,
1919
- // take middle of editor
1920
- top: e.clientY
1921
- }, s = Pt(i, this.ttEditor.view);
1922
- if (!s || !this.editor.isEditable) {
1923
- this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
1924
- return;
1925
- }
1926
- 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)));
1927
- });
1928
- 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.body.addEventListener("mousedown", this.onMouseDown, !0), document.body.addEventListener("keydown", this.onKeyDown, !0);
1929
- }
1930
- destroy() {
1931
- 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.body.removeEventListener("keydown", this.onKeyDown);
1932
- }
1933
- addBlock() {
1934
- this.menuOpen = !1, this.menuFrozen = !0, this.blockMenu.hide();
1935
- const t = this.hoveredBlock.firstChild.getBoundingClientRect(), n = this.ttEditor.view.posAtCoords({
1936
- left: t.left + t.width / 2,
1937
- top: t.top + t.height / 2
1938
- });
1939
- if (!n)
1940
- return;
1941
- const r = g(this.ttEditor.state.doc, n.pos);
1942
- if (r === void 0)
1943
- return;
1944
- const { contentNode: i, endPos: s } = r;
1945
- if (i.textContent.length !== 0) {
1946
- const a = s + 1, l = a + 2;
1947
- this.ttEditor.chain().BNCreateBlock(a).BNUpdateBlock(l, { type: "paragraph", props: {} }).setTextSelection(l).run();
1948
- } else
1949
- this.ttEditor.commands.setTextSelection(s);
1950
- this.ttEditor.view.focus(), this.ttEditor.view.dispatch(
1951
- this.ttEditor.view.state.tr.scrollIntoView().setMeta(X, {
1952
- // TODO import suggestion plugin key
1953
- activate: !0,
1954
- type: "drag"
1955
- })
1956
- );
1957
- }
1958
- getStaticParams() {
1959
- return {
1960
- editor: this.editor,
1961
- addBlock: () => this.addBlock(),
1962
- blockDragStart: (e) => {
1963
- this.isDragging = !0, Je(e, this.ttEditor.view);
1964
- },
1965
- blockDragEnd: () => _t(),
1966
- freezeMenu: () => {
1967
- this.menuFrozen = !0;
1968
- },
1969
- unfreezeMenu: () => {
1970
- this.menuFrozen = !1;
1971
- },
1972
- getReferenceRect: () => {
1973
- if (!this.menuOpen) {
1974
- if (this.lastPosition === void 0)
1975
- throw new Error(
1976
- "Attempted to access block reference rect before rendering block side menu."
1977
- );
1978
- return this.lastPosition;
1979
- }
1980
- const t = this.hoveredBlock.firstChild.getBoundingClientRect();
1981
- return this.horizontalPosAnchoredAtRoot && (t.x = this.horizontalPosAnchor), this.lastPosition = t, t;
1982
- }
1983
- };
1984
- }
1985
- getDynamicParams() {
1986
- return {
1987
- block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))
1988
- };
1989
- }
1990
- }
1991
- const Ze = (o) => new C({
1992
- key: new E("DraggableBlocksPlugin"),
1993
- view: () => new Xe({
1994
- tiptapEditor: o.tiptapEditor,
1995
- editor: o.editor,
1996
- blockMenuFactory: o.blockSideMenuFactory,
1997
- horizontalPosAnchoredAtRoot: !0
1998
- })
1999
- }), Qe = () => v.create({
2000
- name: "DraggableBlocksExtension",
2001
- priority: 1e3,
2002
- // Need to be high, in order to hide menu when typing slash
2003
- addProseMirrorPlugins() {
2004
- if (!this.options.blockSideMenuFactory)
2005
- throw new Error(
2006
- "UI Element factory not defined for DraggableBlocksExtension"
2007
- );
2008
- return [
2009
- Ze({
2010
- tiptapEditor: this.editor,
2011
- editor: this.options.editor,
2012
- blockSideMenuFactory: this.options.blockSideMenuFactory
2013
- })
2014
- ];
2015
- }
2016
- });
2017
- class to {
2018
- constructor({
2019
- editor: e,
2020
- tiptapEditor: t,
2021
- formattingToolbarFactory: n,
2022
- view: r
2023
- }) {
2024
- h(this, "editor");
2025
- h(this, "ttEditor");
2026
- h(this, "view");
2027
- h(this, "formattingToolbar");
2028
- h(this, "preventHide", !1);
2029
- h(this, "preventShow", !1);
2030
- h(this, "toolbarIsOpen", !1);
2031
- h(this, "prevWasEditable", null);
2032
- h(this, "lastPosition");
2033
- h(this, "shouldShow", ({ view: e, state: t, from: n, to: r }) => {
2034
- const { doc: i, selection: s } = t, { empty: a } = s, l = !i.textBetween(n, r).length && Rt(t.selection);
2035
- return !(!e.hasFocus() || a || l);
2036
- });
2037
- h(this, "viewMousedownHandler", () => {
2038
- this.preventShow = !0;
2039
- });
2040
- h(this, "viewMouseupHandler", () => {
2041
- this.preventShow = !1, setTimeout(() => this.update(this.ttEditor.view));
2042
- });
2043
- h(this, "dragstartHandler", () => {
2044
- this.formattingToolbar.hide(), this.toolbarIsOpen = !1;
2045
- });
2046
- h(this, "focusHandler", () => {
2047
- setTimeout(() => this.update(this.ttEditor.view));
2048
- });
2049
- h(this, "blurHandler", ({ event: e }) => {
2050
- var t;
2051
- if (this.preventHide) {
2052
- this.preventHide = !1;
2053
- return;
2054
- }
2055
- // An element is clicked.
2056
- e && e.relatedTarget && // Element is outside the toolbar.
2057
- (this.formattingToolbar.element === e.relatedTarget || (t = this.formattingToolbar.element) != null && t.contains(e.relatedTarget)) || this.toolbarIsOpen && (this.formattingToolbar.hide(), this.toolbarIsOpen = !1);
2058
- });
2059
- 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);
2060
- }
2061
- update(e, t) {
2062
- var p;
2063
- const { state: n, composing: r } = e, { doc: i, selection: s } = n, a = t && t.doc.eq(i) && t.selection.eq(s);
2064
- if ((this.prevWasEditable === null || this.prevWasEditable === this.editor.isEditable) && (r || a))
2065
- return;
2066
- this.prevWasEditable = this.editor.isEditable;
2067
- 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, {
2068
- view: e,
2069
- state: n,
2070
- from: d,
2071
- to: c
2072
- });
2073
- if (this.editor.isEditable && !this.toolbarIsOpen && !this.preventShow && (u || this.preventHide)) {
2074
- this.formattingToolbar.render({}, !0), this.toolbarIsOpen = !0;
2075
- return;
2076
- }
2077
- if (this.toolbarIsOpen && !this.preventShow && (u || this.preventHide)) {
2078
- this.formattingToolbar.render({}, !1);
2079
- return;
2080
- }
2081
- if (this.toolbarIsOpen && !this.preventHide && (!u || this.preventShow || !this.editor.isEditable)) {
2082
- this.formattingToolbar.hide(), this.toolbarIsOpen = !1;
2083
- return;
2084
- }
2085
- }
2086
- destroy() {
2087
- 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);
2088
- }
2089
- getSelectionBoundingBox() {
2090
- 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));
2091
- if (zt(t)) {
2092
- const s = this.ttEditor.view.nodeDOM(r);
2093
- if (s)
2094
- return s.getBoundingClientRect();
2095
- }
2096
- return at(this.ttEditor.view, r, i);
2097
- }
2098
- getStaticParams() {
2099
- return {
2100
- editor: this.editor,
2101
- getReferenceRect: () => {
2102
- if (!this.toolbarIsOpen) {
2103
- if (this.lastPosition === void 0)
2104
- throw new Error(
2105
- "Attempted to access selection reference rect before rendering formatting toolbar."
2106
- );
2107
- return this.lastPosition;
2108
- }
2109
- const e = this.getSelectionBoundingBox();
2110
- return this.lastPosition = e, e;
2111
- }
2112
- };
2113
- }
2114
- }
2115
- const eo = (o) => new C({
2116
- key: new E("FormattingToolbarPlugin"),
2117
- view: (e) => new to({ view: e, ...o })
2118
- }), oo = () => v.create({
2119
- name: "FormattingToolbarExtension",
2120
- addProseMirrorPlugins() {
2121
- if (!this.options.formattingToolbarFactory || !this.options.editor)
2122
- throw new Error(
2123
- "required args not defined for FormattingToolbarExtension"
2124
- );
2125
- return [
2126
- eo({
2127
- tiptapEditor: this.editor,
2128
- editor: this.options.editor,
2129
- formattingToolbarFactory: this.options.formattingToolbarFactory,
2130
- pluginKey: new E("FormattingToolbarPlugin")
2131
- })
2132
- ];
2133
- }
2134
- }), no = new E("HyperlinkToolbarPlugin");
2135
- class ro {
2136
- constructor({ editor: e, hyperlinkToolbarFactory: t }) {
2137
- h(this, "editor");
2138
- h(this, "hyperlinkToolbar");
2139
- h(this, "menuUpdateTimer");
2140
- h(this, "startMenuUpdateTimer");
2141
- h(this, "stopMenuUpdateTimer");
2142
- h(this, "mouseHoveredHyperlinkMark");
2143
- h(this, "mouseHoveredHyperlinkMarkRange");
2144
- h(this, "keyboardHoveredHyperlinkMark");
2145
- h(this, "keyboardHoveredHyperlinkMarkRange");
2146
- h(this, "hyperlinkMark");
2147
- h(this, "hyperlinkMarkRange");
2148
- h(this, "lastPosition");
2149
- h(this, "mouseOverHandler", (e) => {
2150
- if (this.mouseHoveredHyperlinkMark = void 0, this.mouseHoveredHyperlinkMarkRange = void 0, this.stopMenuUpdateTimer(), e.target instanceof HTMLAnchorElement && e.target.nodeName === "A") {
2151
- const t = e.target, n = this.editor.view.posAtDOM(t, 0) + 1, r = this.editor.state.doc.resolve(
2152
- n
2153
- ), i = r.marks();
2154
- for (const s of i)
2155
- if (s.type.name === this.editor.schema.mark("link").type.name) {
2156
- this.mouseHoveredHyperlinkMark = s, this.mouseHoveredHyperlinkMarkRange = Q(
2157
- r,
2158
- s.type,
2159
- s.attrs
2160
- ) || void 0;
2161
- break;
2162
- }
2163
- }
2164
- return this.startMenuUpdateTimer(), !1;
2165
- });
2166
- h(this, "clickHandler", (e) => {
2167
- var t;
2168
- // Toolbar is open.
2169
- this.hyperlinkMark && // An element is clicked.
2170
- e && e.target && // Element is outside the editor.
2171
- this.editor.view.dom !== e.target && !this.editor.view.dom.contains(e.target) && // Element is outside the toolbar.
2172
- this.hyperlinkToolbar.element !== e.target && !((t = this.hyperlinkToolbar.element) != null && t.contains(e.target)) && this.hyperlinkToolbar.hide();
2173
- });
2174
- this.editor = e, this.hyperlinkToolbar = t(this.getStaticParams()), this.startMenuUpdateTimer = () => {
2175
- this.menuUpdateTimer = setTimeout(() => {
2176
- this.update();
2177
- }, 250);
2178
- }, 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);
2179
- }
2180
- update() {
2181
- var t, n, r, i;
2182
- if (!this.editor.view.hasFocus())
2183
- return;
2184
- const e = this.hyperlinkMark;
2185
- if (this.hyperlinkMark = void 0, this.hyperlinkMarkRange = void 0, this.keyboardHoveredHyperlinkMark = void 0, this.keyboardHoveredHyperlinkMarkRange = void 0, this.editor.state.selection.empty) {
2186
- const s = this.editor.state.selection.$from.marks();
2187
- for (const a of s)
2188
- if (a.type.name === this.editor.schema.mark("link").type.name) {
2189
- this.keyboardHoveredHyperlinkMark = a, this.keyboardHoveredHyperlinkMarkRange = Q(
2190
- this.editor.state.selection.$from,
2191
- a.type,
2192
- a.attrs
2193
- ) || void 0;
2194
- break;
2195
- }
2196
- }
2197
- 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) {
2198
- if (this.getDynamicParams(), !e) {
2199
- this.hyperlinkToolbar.render(this.getDynamicParams(), !0), (t = this.hyperlinkToolbar.element) == null || t.addEventListener(
2200
- "mouseleave",
2201
- this.startMenuUpdateTimer
2202
- ), (n = this.hyperlinkToolbar.element) == null || n.addEventListener(
2203
- "mouseenter",
2204
- this.stopMenuUpdateTimer
2205
- );
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));
2206
2430
  return;
2207
2431
  }
2208
- this.hyperlinkToolbar.render(this.getDynamicParams(), !1);
2209
- return;
2210
- }
2211
- if (e && (!this.hyperlinkMark || !this.editor.isEditable)) {
2212
- (r = this.hyperlinkToolbar.element) == null || r.removeEventListener(
2213
- "mouseleave",
2214
- this.startMenuUpdateTimer
2215
- ), (i = this.hyperlinkToolbar.element) == null || i.removeEventListener(
2216
- "mouseenter",
2217
- this.stopMenuUpdateTimer
2218
- ), this.hyperlinkToolbar.hide();
2219
- return;
2220
- }
2221
- }
2222
- destroy() {
2223
- this.editor.view.dom.removeEventListener(
2224
- "mouseover",
2225
- this.mouseOverHandler
2226
- );
2227
- }
2228
- getStaticParams() {
2229
- return {
2230
- editHyperlink: (e, t) => {
2231
- const n = this.editor.view.state.tr.insertText(
2232
- t,
2233
- this.hyperlinkMarkRange.from,
2234
- this.hyperlinkMarkRange.to
2235
- );
2236
- n.addMark(
2237
- this.hyperlinkMarkRange.from,
2238
- this.hyperlinkMarkRange.from + t.length,
2239
- this.editor.schema.mark("link", { href: e })
2240
- ), this.editor.view.dispatch(n), this.editor.view.focus(), this.hyperlinkToolbar.hide();
2241
- },
2242
- deleteHyperlink: () => {
2243
- this.editor.view.dispatch(
2244
- this.editor.view.state.tr.removeMark(
2245
- this.hyperlinkMarkRange.from,
2246
- this.hyperlinkMarkRange.to,
2247
- this.hyperlinkMark.type
2248
- ).setMeta("preventAutolink", !0)
2249
- ), this.editor.view.focus(), this.hyperlinkToolbar.hide();
2250
- },
2251
- getReferenceRect: () => {
2252
- if (!this.hyperlinkMark) {
2253
- if (this.lastPosition === void 0)
2254
- throw new Error(
2255
- "Attempted to access hyperlink reference rect before rendering hyperlink toolbar."
2256
- );
2257
- return this.lastPosition;
2258
- }
2259
- const e = at(
2260
- this.editor.view,
2261
- this.hyperlinkMarkRange.from,
2262
- this.hyperlinkMarkRange.to
2263
- );
2264
- return this.lastPosition = e, e;
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;
2265
2441
  }
2266
- };
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);
2267
2475
  }
2268
- getDynamicParams() {
2269
- return {
2270
- url: this.hyperlinkMark.attrs.href,
2271
- text: this.editor.view.state.doc.textBetween(
2272
- this.hyperlinkMarkRange.from,
2273
- this.hyperlinkMarkRange.to
2274
- )
2275
- };
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);
2276
2479
  }
2277
- }
2278
- const io = (o, e) => new C({
2279
- key: no,
2280
- view: () => new ro({
2281
- editor: o,
2282
- hyperlinkToolbarFactory: e.hyperlinkToolbarFactory
2283
- })
2284
- }), so = ut.extend({
2285
- priority: 500,
2286
- addProseMirrorPlugins() {
2287
- var o;
2288
- if (!this.options.hyperlinkToolbarFactory)
2289
- throw new Error("UI Element factory not defined for HyperlinkMark");
2290
- return [
2291
- ...((o = this.parent) == null ? void 0 : o.call(this)) || [],
2292
- io(this.editor, {
2293
- 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"
2294
2506
  })
2295
- ];
2507
+ );
2296
2508
  }
2297
- }), ao = new E("blocknote-placeholder"), lo = v.create({
2298
- name: "placeholder",
2299
- addOptions() {
2300
- return {
2301
- emptyEditorClass: "is-editor-empty",
2302
- emptyNodeClass: "is-empty",
2303
- isFilterClass: "is-filter",
2304
- hasAnchorClass: "has-anchor",
2305
- placeholder: "Write something …",
2306
- showOnlyWhenEditable: !0,
2307
- showOnlyCurrent: !0,
2308
- includeChildren: !1
2309
- };
2310
- },
2311
- addProseMirrorPlugins() {
2312
- return [
2313
- new C({
2314
- key: ao,
2315
- props: {
2316
- decorations: (o) => {
2317
- const { doc: e, selection: t } = o, n = X.getState(o), r = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: i } = t, s = [];
2318
- if (r)
2319
- return e.descendants((a, l) => {
2320
- const d = i >= l && i <= l + a.nodeSize, c = !a.isLeaf && !a.childCount;
2321
- if ((d || !this.options.showOnlyCurrent) && c) {
2322
- const u = [this.options.emptyNodeClass];
2323
- 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);
2324
- const p = D.node(l, l + a.nodeSize, {
2325
- class: u.join(" ")
2326
- });
2327
- s.push(p);
2328
- }
2329
- return this.options.includeChildren;
2330
- }), F.create(e, s);
2331
- }
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);
2332
2550
  }
2333
- })
2334
- ];
2335
- }
2336
- });
2337
- class co {
2338
- constructor(e, t) {
2339
- this.name = e, this.match = t;
2551
+ ), this.sideMenuView)
2552
+ });
2340
2553
  }
2341
- }
2342
- class S extends co {
2343
- /**
2344
- * Constructs a new slash-command.
2345
- *
2346
- * @param name The name of the command
2347
- * @param execute The callback for creating a new node
2348
- * @param aliases Aliases for this command
2349
- */
2350
- constructor(e, t, n = []) {
2351
- super(e, (r) => this.name.toLowerCase().startsWith(r.toLowerCase()) || this.aliases.filter(
2352
- (i) => i.toLowerCase().startsWith(r.toLowerCase())
2353
- ).length !== 0), this.name = e, this.execute = t, this.aliases = n;
2554
+ onUpdate(t) {
2555
+ return this.on("update", t);
2354
2556
  }
2355
2557
  }
2356
- function I(o, e) {
2357
- const t = o.getTextCursorPosition().block;
2358
- 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));
2359
2561
  }
2360
- const uo = [
2361
- // Command for creating a level 1 heading
2362
- new S(
2363
- "Heading",
2364
- (o) => I(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, {
2365
2569
  type: "heading",
2366
2570
  props: { level: "1" }
2367
- }),
2368
- ["h", "heading1", "h1"]
2369
- ),
2370
- // Command for creating a level 2 heading
2371
- new S(
2372
- "Heading 2",
2373
- (o) => I(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, {
2374
2576
  type: "heading",
2375
2577
  props: { level: "2" }
2376
- }),
2377
- ["h2", "heading2", "subheading"]
2378
- ),
2379
- // Command for creating a level 3 heading
2380
- new S(
2381
- "Heading 3",
2382
- (o) => I(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, {
2383
2583
  type: "heading",
2384
2584
  props: { level: "3" }
2385
- }),
2386
- ["h3", "heading3", "subheading"]
2387
- ),
2388
- // Command for creating an ordered list
2389
- new S(
2390
- "Numbered List",
2391
- (o) => I(o, {
2392
- type: "numberedListItem"
2393
- }),
2394
- ["li", "list", "numberedlist", "numbered list"]
2395
- ),
2396
- // Command for creating a bullet list
2397
- new S(
2398
- "Bullet List",
2399
- (o) => I(o, {
2400
- type: "bulletListItem"
2401
- }),
2402
- ["ul", "list", "bulletlist", "bullet list"]
2403
- ),
2404
- // Command for creating a paragraph (pretty useless)
2405
- new S(
2406
- "Paragraph",
2407
- (o) => I(o, {
2408
- type: "paragraph"
2409
- }),
2410
- ["p"]
2411
- )
2412
- // replaceRangeWithNode(editor, range, node);
2413
- // return true;
2414
- // },
2415
- // ["ol", "orderedlist"],
2416
- // OrderedListIcon,
2417
- // "Used to display an ordered (enumerated) list item"
2418
- // ),
2419
- // Command for creating a blockquote
2420
- // blockquote: new SlashCommand(
2421
- // "Block Quote",
2422
- // CommandGroup.BASIC_BLOCKS,
2423
- // (editor, range) => {
2424
- // const paragraph = editor.schema.node("paragraph");
2425
- // const node = editor.schema.node(
2426
- // "blockquote",
2427
- // { "block-id": uniqueId.generate() },
2428
- // paragraph
2429
- // );
2430
- // replaceRangeWithNode(editor, range, node);
2431
- // return true;
2432
- // },
2433
- // ["quote", "blockquote"],
2434
- // QuoteIcon,
2435
- // "Used to make a quote stand out",
2436
- // "Ctrl+Shift+B"
2437
- // ),
2438
- // Command for creating a horizontal rule
2439
- // horizontalRule: new SlashCommand(
2440
- // "Horizontal Rule",
2441
- // CommandGroup.BASIC_BLOCKS,
2442
- // (editor, range) => {
2443
- // const node = editor.schema.node("horizontalRule", {
2444
- // "block-id": uniqueId.generate(),
2445
- // });
2446
- // // insert horizontal rule, create a new block after the horizontal rule if applicable
2447
- // // and put the cursor in the block after the horizontal rule.
2448
- // editor
2449
- // .chain()
2450
- // .focus()
2451
- // .replaceRangeAndUpdateSelection(range, node)
2452
- // .command(({ tr, dispatch }) => {
2453
- // if (dispatch) {
2454
- // // the node immediately after the cursor
2455
- // const nodeAfter = tr.selection.$to.nodeAfter;
2456
- // // the position of the cursor
2457
- // const cursorPos = tr.selection.$to.pos;
2458
- // // check if there is no node after the cursor (end of document)
2459
- // if (!nodeAfter) {
2460
- // // create a new block of the default type (probably paragraph) after the cursor
2461
- // const { parent } = tr.selection.$to;
2462
- // const node = parent.type.contentMatch.defaultType?.create();
2463
- // if (node) {
2464
- // tr.insert(cursorPos, node);
2465
- // }
2466
- // }
2467
- // // try to put the cursor at the start of the node directly after the inserted horizontal rule
2468
- // tr.doc.nodesBetween(cursorPos, cursorPos + 1, (node, pos) => {
2469
- // if (node.type.name !== "horizontalRule") {
2470
- // tr.setSelection(TextSelection.create(tr.doc, pos));
2471
- // }
2472
- // });
2473
- // }
2474
- // return true;
2475
- // })
2476
- // .scrollIntoView()
2477
- // .run();
2478
- // return true;
2479
- // },
2480
- // ["hr", "horizontalrule"],
2481
- // SeparatorIcon,
2482
- // "Used to separate sections with a horizontal line"
2483
- // ),
2484
- // Command for creating a table
2485
- // table: new SlashCommand(
2486
- // "Table",
2487
- // CommandGroup.BASIC_BLOCKS,
2488
- // (editor, range) => {
2489
- // editor.chain().focus().deleteRange(range).run();
2490
- // // TODO: add blockid, pending https://github.com/ueberdosis/tiptap/pull/1469
2491
- // editor
2492
- // .chain()
2493
- // .focus()
2494
- // .insertTable({ rows: 1, cols: 2, withHeaderRow: false })
2495
- // .scrollIntoView()
2496
- // .run();
2497
- // return true;
2498
- // },
2499
- // ["table", "database"],
2500
- // TableIcon,
2501
- // "Used to create a simple table"
2502
- // ),
2503
- ], ho = v.create({
2504
- name: "textAlignment",
2505
- addGlobalAttributes() {
2506
- return [
2507
- {
2508
- // Attribute is applied to block content instead of container so that child blocks don't inherit the text
2509
- // alignment styling.
2510
- types: ["paragraph", "heading", "bulletListItem", "numberedListItem"],
2511
- attributes: {
2512
- textAlignment: {
2513
- default: "left",
2514
- parseHTML: (o) => o.getAttribute("data-text-alignment"),
2515
- renderHTML: (o) => o.textAlignment !== "left" && {
2516
- "data-text-alignment": o.textAlignment
2517
- }
2518
- }
2519
- }
2520
- }
2521
- ];
2522
- },
2523
- addCommands() {
2524
- return {
2525
- setTextAlignment: (o) => ({ state: e }) => {
2526
- const t = [], n = g(
2527
- e.doc,
2528
- e.selection.from
2529
- );
2530
- if (n === void 0)
2531
- return !1;
2532
- let r = n.startPos;
2533
- for (; r < e.selection.to; )
2534
- e.doc.resolve(r).node().type.spec.group === "blockContent" ? (t.push(r - 1), r += e.doc.resolve(r).node().nodeSize - 1) : r += 1;
2535
- for (const i of t)
2536
- e.tr.setNodeAttribute(i, "textAlignment", o);
2537
- return !0;
2538
- }
2539
- };
2540
- }
2541
- }), po = v.create({
2542
- name: "blockTextColor",
2543
- addGlobalAttributes() {
2544
- return [
2545
- {
2546
- types: ["blockContainer"],
2547
- attributes: {
2548
- textColor: {
2549
- default: "default",
2550
- parseHTML: (o) => o.hasAttribute("data-text-color") ? o.getAttribute("data-text-color") : "default",
2551
- renderHTML: (o) => o.textColor !== "default" && {
2552
- "data-text-color": o.textColor
2553
- }
2554
- }
2555
- }
2556
- }
2557
- ];
2558
- },
2559
- addCommands() {
2560
- return {
2561
- setBlockTextColor: (o, e) => ({ state: t, view: n }) => {
2562
- const r = g(t.doc, o);
2563
- return r === void 0 ? !1 : (t.tr.setNodeAttribute(r.startPos - 1, "textColor", e), n.focus(), !0);
2564
- }
2565
- };
2566
- }
2567
- }), fo = st.create({
2568
- name: "textColor",
2569
- addAttributes() {
2570
- return {
2571
- color: {
2572
- default: void 0,
2573
- parseHTML: (o) => o.getAttribute("data-text-color"),
2574
- renderHTML: (o) => ({
2575
- "data-text-color": o.color
2576
- })
2577
- }
2578
- };
2579
- },
2580
- parseHTML() {
2581
- return [
2582
- {
2583
- tag: "span",
2584
- getAttrs: (o) => typeof o == "string" ? !1 : o.hasAttribute("data-text-color") ? { color: o.getAttribute("data-text-color") } : !1
2585
- }
2586
- ];
2587
- },
2588
- renderHTML({ HTMLAttributes: o }) {
2589
- return ["span", o, 0];
2590
- },
2591
- addCommands() {
2592
- return {
2593
- setTextColor: (o) => ({ commands: e }) => o !== "default" ? e.setMark(this.name, { color: o }) : e.unsetMark(this.name)
2594
- };
2595
- }
2596
- }), mo = v.create({
2597
- name: "trailingNode",
2598
- addProseMirrorPlugins() {
2599
- const o = new E(this.name);
2600
- return [
2601
- new C({
2602
- key: o,
2603
- appendTransaction: (e, t, n) => {
2604
- 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;
2605
- if (a)
2606
- return i.insert(
2607
- l,
2608
- d.create(void 0, c.create())
2609
- );
2610
- },
2611
- state: {
2612
- init: (e, t) => {
2613
- },
2614
- apply: (e, t) => {
2615
- if (!e.docChanged)
2616
- return t;
2617
- let n = e.doc.lastChild;
2618
- if (!n || n.type.name !== "blockGroup")
2619
- throw new Error("Expected blockGroup");
2620
- if (n = n.lastChild, !n || n.type.name !== "blockContainer")
2621
- throw new Error("Expected blockContainer");
2622
- return n.nodeSize > 4;
2623
- }
2624
- }
2625
- })
2626
- ];
2627
- }
2628
- }), go = (o) => {
2629
- const e = [
2630
- N.ClipboardTextSerializer,
2631
- N.Commands,
2632
- N.Editable,
2633
- N.FocusEvents,
2634
- N.Tabindex,
2635
- // DevTools,
2636
- te,
2637
- // DropCursor,
2638
- lo.configure({
2639
- emptyNodeClass: k.isEmpty,
2640
- hasAnchorClass: k.hasAnchor,
2641
- isFilterClass: k.isFilter,
2642
- includeChildren: !0,
2643
- showOnlyCurrent: !1
2644
- }),
2645
- K.configure({
2646
- types: ["blockContainer"]
2647
- }),
2648
- ee,
2649
- // Comments,
2650
- // basics:
2651
- ie,
2652
- // marks:
2653
- Kt,
2654
- Jt,
2655
- ne,
2656
- re,
2657
- se,
2658
- fo,
2659
- po,
2660
- Le,
2661
- Ne,
2662
- ho,
2663
- // custom blocks:
2664
- ...ze,
2665
- ...Object.values(o.blockSchema).map(
2666
- (t) => t.node.configure({ editor: o.editor })
2667
- ),
2668
- $e,
2669
- Qt.configure({ width: 5, color: "#ddeeff" }),
2670
- // This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
2671
- // should be handled before Enter handlers in other components like splitListItem
2672
- mo
2673
- ];
2674
- if (o.collaboration) {
2675
- e.push(
2676
- Xt.configure({
2677
- fragment: o.collaboration.fragment
2678
- })
2679
- );
2680
- const t = (n) => {
2681
- const r = document.createElement("span");
2682
- r.classList.add(_["collaboration-cursor__caret"]), r.setAttribute("style", `border-color: ${n.color}`);
2683
- const i = document.createElement("span");
2684
- i.classList.add(_["collaboration-cursor__label"]), i.setAttribute("style", `background-color: ${n.color}`), i.insertBefore(document.createTextNode(n.name), null);
2685
- const s = document.createTextNode("⁠"), a = document.createTextNode("⁠");
2686
- return r.insertBefore(s, null), r.insertBefore(i, null), r.insertBefore(a, null), r;
2687
- };
2688
- e.push(
2689
- Zt.configure({
2690
- user: o.collaboration.user,
2691
- render: o.collaboration.renderCursor || t,
2692
- provider: o.collaboration.provider
2693
- })
2694
- );
2695
- } else
2696
- e.push(oe);
2697
- return o.uiFactories.blockSideMenuFactory && e.push(
2698
- Qe().configure({
2699
- editor: o.editor,
2700
- blockSideMenuFactory: o.uiFactories.blockSideMenuFactory
2701
2585
  })
2702
- ), o.uiFactories.formattingToolbarFactory && e.push(
2703
- oo().configure({
2704
- editor: o.editor,
2705
- 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"
2706
2591
  })
2707
- ), o.uiFactories.hyperlinkToolbarFactory ? e.push(
2708
- so.configure({
2709
- 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"
2710
2597
  })
2711
- ) : e.push(ut), o.uiFactories.slashMenuFactory && e.push(
2712
- We().configure({
2713
- editor: o.editor,
2714
- commands: o.slashCommands,
2715
- slashMenuFactory: o.uiFactories.slashMenuFactory
2598
+ }), "paragraph" in n && e.push({
2599
+ name: "Paragraph",
2600
+ aliases: ["p"],
2601
+ execute: (i) => _(i, {
2602
+ type: "paragraph"
2716
2603
  })
2717
- ), e;
2718
- }, ko = {
2604
+ }), e;
2605
+ }, mo = {
2719
2606
  enableInputRules: !0,
2720
2607
  enablePasteRules: !0,
2721
2608
  enableCoreExtensions: !1
2722
2609
  };
2723
- class Ko {
2610
+ class Wo {
2724
2611
  constructor(e = {}) {
2725
- h(this, "_tiptapEditor");
2726
- h(this, "blockCache", /* @__PURE__ */ new WeakMap());
2727
- h(this, "schema");
2728
- h(this, "ready", !1);
2729
- 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;
2730
2621
  this.options = e;
2731
2622
  const t = {
2732
2623
  defaultStyles: !0,
@@ -2735,54 +2626,74 @@ class Ko {
2735
2626
  // If BSchema is not specified, then options.blockSchema should also not
2736
2627
  // be defined. Unfortunately, trying to implement these constraints seems
2737
2628
  // to be a huge pain, hence the `as any` casts.
2738
- blockSchema: e.blockSchema || ke,
2629
+ blockSchema: e.blockSchema || wt,
2739
2630
  ...e
2740
- }, 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({
2741
2637
  editor: this,
2742
- uiFactories: t.uiFactories || {},
2743
- slashCommands: t.slashCommands || uo,
2744
2638
  blockSchema: t.blockSchema,
2745
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
+ ]
2746
2648
  });
2747
- this.schema = t.blockSchema;
2748
- const r = {
2749
- // TODO: This approach to setting initial content is "cleaner" but requires the PM editor schema, which is only
2750
- // created after initializing the TipTap editor. Not sure it's feasible.
2751
- // content:
2752
- // options.initialContent &&
2753
- // options.initialContent.map((block) =>
2754
- // blockToNode(block, this._tiptapEditor.schema).toJSON()
2755
- // ),
2756
- ...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,
2757
2657
  ...t._tiptapOptions,
2758
2658
  onCreate: () => {
2759
- var l;
2760
- (l = t.onEditorReady) == null || l.call(t, this), t.initialContent && this.replaceBlocks(this.topLevelBlocks, t.initialContent), this.ready = !0;
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();
2761
2669
  },
2762
2670
  onUpdate: () => {
2763
- var l;
2764
- this.ready && ((l = t.onEditorContentChange) == null || l.call(t, this));
2671
+ var c;
2672
+ this.ready && ((c = t.onEditorContentChange) == null || c.call(t, this));
2765
2673
  },
2766
2674
  onSelectionUpdate: () => {
2767
- var l;
2768
- this.ready && ((l = t.onTextCursorPositionChange) == null || l.call(t, this));
2675
+ var c;
2676
+ this.ready && ((c = t.onTextCursorPositionChange) == null || c.call(t, this));
2769
2677
  },
2770
2678
  editable: e.editable === void 0 ? !0 : e.editable,
2771
- 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],
2772
2680
  editorProps: {
2773
2681
  attributes: {
2774
2682
  "data-theme": e.theme || "light",
2775
2683
  ...t.editorDOMAttributes || {},
2776
2684
  class: [
2777
- _.bnEditor,
2778
- _.bnRoot,
2779
- t.defaultStyles ? _.defaultStyles : "",
2780
- ((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) || ""
2781
2689
  ].join(" ")
2782
2690
  }
2783
2691
  }
2784
2692
  };
2785
- 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;
2786
2697
  }
2787
2698
  get domElement() {
2788
2699
  return this._tiptapEditor.view.dom;
@@ -2799,7 +2710,7 @@ class Ko {
2799
2710
  */
2800
2711
  get topLevelBlocks() {
2801
2712
  const e = [];
2802
- return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(w(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;
2803
2714
  }
2804
2715
  /**
2805
2716
  * Gets a snapshot of an existing block from the editor.
@@ -2808,8 +2719,8 @@ class Ko {
2808
2719
  */
2809
2720
  getBlock(e) {
2810
2721
  const t = typeof e == "string" ? e : e.id;
2811
- let n;
2812
- return this._tiptapEditor.state.doc.firstChild.descendants((r) => typeof n < "u" ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== t ? !0 : (n = w(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;
2813
2724
  }
2814
2725
  /**
2815
2726
  * Traverses all blocks in the editor depth-first, and executes a callback for each.
@@ -2817,19 +2728,19 @@ class Ko {
2817
2728
  * @param reverse Whether the blocks should be traversed in reverse order.
2818
2729
  */
2819
2730
  forEachBlock(e, t = !1) {
2820
- const n = this.topLevelBlocks.slice();
2821
- t && n.reverse();
2731
+ const o = this.topLevelBlocks.slice();
2732
+ t && o.reverse();
2822
2733
  function r(i) {
2823
2734
  for (const s of i) {
2824
2735
  if (!e(s))
2825
2736
  return !1;
2826
- const a = t ? s.children.slice().reverse() : s.children;
2827
- if (!r(a))
2737
+ const l = t ? s.children.slice().reverse() : s.children;
2738
+ if (!r(l))
2828
2739
  return !1;
2829
2740
  }
2830
2741
  return !0;
2831
2742
  }
2832
- r(n);
2743
+ r(o);
2833
2744
  }
2834
2745
  /**
2835
2746
  * Executes a callback whenever the editor's contents change.
@@ -2838,22 +2749,29 @@ class Ko {
2838
2749
  onEditorContentChange(e) {
2839
2750
  this._tiptapEditor.on("update", e);
2840
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
+ }
2841
2759
  /**
2842
2760
  * Gets a snapshot of the current text cursor position.
2843
2761
  * @returns A snapshot of the current text cursor position.
2844
2762
  */
2845
2763
  getTextCursorPosition() {
2846
- const { node: e, depth: t, startPos: n, endPos: r } = g(
2764
+ const { node: e, depth: t, startPos: o, endPos: r } = g(
2847
2765
  this._tiptapEditor.state.doc,
2848
2766
  this._tiptapEditor.state.selection.from
2849
2767
  ), i = this._tiptapEditor.state.doc.resolve(r).index(t - 1), s = this._tiptapEditor.state.doc.resolve(r + 1).node().childCount;
2850
- let a;
2851
- i > 0 && (a = this._tiptapEditor.state.doc.resolve(n - 2).node());
2852
2768
  let l;
2853
- return i < s - 1 && (l = this._tiptapEditor.state.doc.resolve(r + 2).node()), {
2854
- block: w(e, this.schema, this.blockCache),
2855
- prevBlock: a === void 0 ? void 0 : w(a, this.schema, this.blockCache),
2856
- nextBlock: l === void 0 ? void 0 : w(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)
2857
2775
  };
2858
2776
  }
2859
2777
  /**
@@ -2863,7 +2781,7 @@ class Ko {
2863
2781
  * @param placement Whether the text cursor should be placed at the start or end of the block.
2864
2782
  */
2865
2783
  setTextCursorPosition(e, t = "start") {
2866
- 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(
2867
2785
  this._tiptapEditor.state.doc,
2868
2786
  r + 2
2869
2787
  );
@@ -2878,9 +2796,9 @@ class Ko {
2878
2796
  if (this._tiptapEditor.state.selection.from === this._tiptapEditor.state.selection.to)
2879
2797
  return;
2880
2798
  const e = [];
2881
- 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(
2882
- w(
2883
- 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(),
2884
2802
  this.schema,
2885
2803
  this.blockCache
2886
2804
  )
@@ -2908,8 +2826,8 @@ class Ko {
2908
2826
  * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
2909
2827
  * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
2910
2828
  */
2911
- insertBlocks(e, t, n = "before") {
2912
- Tt(e, t, n, this._tiptapEditor);
2829
+ insertBlocks(e, t, o = "before") {
2830
+ Tt(e, t, o, this._tiptapEditor);
2913
2831
  }
2914
2832
  /**
2915
2833
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
@@ -2919,14 +2837,14 @@ class Ko {
2919
2837
  * @param update A partial block which defines how the existing block should be changed.
2920
2838
  */
2921
2839
  updateBlock(e, t) {
2922
- Be(e, t, this._tiptapEditor);
2840
+ Ye(e, t, this._tiptapEditor);
2923
2841
  }
2924
2842
  /**
2925
2843
  * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
2926
2844
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
2927
2845
  */
2928
2846
  removeBlocks(e) {
2929
- xt(e, this._tiptapEditor);
2847
+ Bt(e, this._tiptapEditor);
2930
2848
  }
2931
2849
  /**
2932
2850
  * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
@@ -2936,13 +2854,13 @@ class Ko {
2936
2854
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
2937
2855
  */
2938
2856
  replaceBlocks(e, t) {
2939
- we(e, t, this._tiptapEditor);
2857
+ Je(e, t, this._tiptapEditor);
2940
2858
  }
2941
2859
  /**
2942
2860
  * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
2943
2861
  */
2944
2862
  getActiveStyles() {
2945
- 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([
2946
2864
  "bold",
2947
2865
  "italic",
2948
2866
  "underline",
@@ -2950,7 +2868,7 @@ class Ko {
2950
2868
  "code"
2951
2869
  ]), r = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2952
2870
  for (const i of t)
2953
- 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);
2954
2872
  return e;
2955
2873
  }
2956
2874
  /**
@@ -2964,10 +2882,10 @@ class Ko {
2964
2882
  "underline",
2965
2883
  "strike",
2966
2884
  "code"
2967
- ]), n = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2885
+ ]), o = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2968
2886
  this._tiptapEditor.view.focus();
2969
2887
  for (const [r, i] of Object.entries(e))
2970
- 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 });
2971
2889
  }
2972
2890
  /**
2973
2891
  * Removes styles from the currently selected content.
@@ -2989,10 +2907,10 @@ class Ko {
2989
2907
  "underline",
2990
2908
  "strike",
2991
2909
  "code"
2992
- ]), n = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2910
+ ]), o = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
2993
2911
  this._tiptapEditor.view.focus();
2994
2912
  for (const [r, i] of Object.entries(e))
2995
- 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 });
2996
2914
  }
2997
2915
  /**
2998
2916
  * Gets the currently selected text.
@@ -3017,11 +2935,11 @@ class Ko {
3017
2935
  createLink(e, t) {
3018
2936
  if (e === "")
3019
2937
  return;
3020
- let { from: n, to: r } = this._tiptapEditor.state.selection;
3021
- 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));
3022
2940
  const i = this._tiptapEditor.schema.mark("link", { href: e });
3023
2941
  this._tiptapEditor.view.dispatch(
3024
- 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)
3025
2943
  );
3026
2944
  }
3027
2945
  /**
@@ -3063,7 +2981,7 @@ class Ko {
3063
2981
  * @returns The blocks, serialized as an HTML string.
3064
2982
  */
3065
2983
  async blocksToHTML(e) {
3066
- return St(e, this._tiptapEditor.schema);
2984
+ return xt(e, this._tiptapEditor.schema);
3067
2985
  }
3068
2986
  /**
3069
2987
  * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
@@ -3073,7 +2991,7 @@ class Ko {
3073
2991
  * @returns The blocks parsed from the HTML string.
3074
2992
  */
3075
2993
  async HTMLToBlocks(e) {
3076
- return It(e, this.schema, this._tiptapEditor.schema);
2994
+ return _t(e, this.schema, this._tiptapEditor.schema);
3077
2995
  }
3078
2996
  /**
3079
2997
  * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
@@ -3082,7 +3000,7 @@ class Ko {
3082
3000
  * @returns The blocks, serialized as a Markdown string.
3083
3001
  */
3084
3002
  async blocksToMarkdown(e) {
3085
- return xe(e, this._tiptapEditor.schema);
3003
+ return Ze(e, this._tiptapEditor.schema);
3086
3004
  }
3087
3005
  /**
3088
3006
  * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
@@ -3092,7 +3010,7 @@ class Ko {
3092
3010
  * @returns The blocks parsed from the Markdown string.
3093
3011
  */
3094
3012
  async markdownToBlocks(e) {
3095
- return Se(e, this.schema, this._tiptapEditor.schema);
3013
+ return Qe(e, this.schema, this._tiptapEditor.schema);
3096
3014
  }
3097
3015
  /**
3098
3016
  * Updates the user info for the current user that's shown to other collaborators.
@@ -3106,19 +3024,29 @@ class Ko {
3106
3024
  }
3107
3025
  }
3108
3026
  export {
3109
- S as BaseSlashMenuItem,
3110
- Ko as BlockNoteEditor,
3111
- $e as CustomBlockSerializerExtension,
3112
- Vo as blockStyles,
3113
- ot as camelToDataKebab,
3114
- Yo as createBlockSpec,
3115
- H as createTipTapBlock,
3116
- ke as defaultBlockSchema,
3117
- L as defaultProps,
3118
- uo as defaultSlashMenuItems,
3119
- go as getBlockNoteExtensions,
3120
- de as parse,
3121
- le as propsToAttributes,
3122
- 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
3123
3051
  };
3124
3052
  //# sourceMappingURL=blocknote.js.map