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