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