@blocknote/core 0.4.6-alpha.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -34
- package/dist/blocknote.js +331 -308
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +2 -2
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/BlockNoteEditor.ts +76 -14
- package/src/editor.module.css +19 -6
- package/src/extensions/Blocks/nodes/Block.module.css +1 -23
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +25 -1
- package/types/src/BlockNoteEditor.d.ts +38 -4
package/dist/blocknote.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var Ce = Object.defineProperty;
|
|
2
2
|
var Be = (o, e, t) => e in o ? Ce(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
3
|
var h = (o, e, t) => (Be(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { Extension as C, findChildren as
|
|
4
|
+
import { Extension as C, findChildren as $, combineTransactionSteps as Te, getChangedRanges as Me, findChildrenInRange as we, Mark as ne, Node as E, mergeAttributes as x, InputRule as Y, findParentNode as xe, isTextSelection as Ee, isNodeSelection as Ie, posToDOMRect as re, getMarkRange as X, extensions as N, Editor as Se } from "@tiptap/core";
|
|
5
5
|
import { Slice as A, Fragment as P, DOMSerializer as Ae, DOMParser as Pe } from "prosemirror-model";
|
|
6
|
-
import { Plugin as B, PluginKey as v, TextSelection as Q, Selection as
|
|
6
|
+
import { Plugin as B, PluginKey as v, TextSelection as Q, Selection as G, NodeSelection as Ne } from "prosemirror-state";
|
|
7
7
|
import { v4 as Le } from "uuid";
|
|
8
8
|
import ie from "rehype-parse";
|
|
9
9
|
import He from "rehype-remark";
|
|
@@ -12,21 +12,21 @@ import ae from "remark-gfm";
|
|
|
12
12
|
import Oe from "remark-parse";
|
|
13
13
|
import _e from "remark-rehype";
|
|
14
14
|
import De from "remark-stringify";
|
|
15
|
-
import { unified as
|
|
15
|
+
import { unified as W } from "unified";
|
|
16
16
|
import { fromDom as Z } from "hast-util-from-dom";
|
|
17
17
|
import { Bold as Fe } from "@tiptap/extension-bold";
|
|
18
18
|
import { Code as Re } from "@tiptap/extension-code";
|
|
19
19
|
import { Dropcursor as ze } from "@tiptap/extension-dropcursor";
|
|
20
20
|
import { Gapcursor as Ue } from "@tiptap/extension-gapcursor";
|
|
21
|
-
import { HardBreak as
|
|
22
|
-
import { History as
|
|
23
|
-
import { Italic as
|
|
21
|
+
import { HardBreak as Ge } from "@tiptap/extension-hard-break";
|
|
22
|
+
import { History as $e } from "@tiptap/extension-history";
|
|
23
|
+
import { Italic as qe } from "@tiptap/extension-italic";
|
|
24
24
|
import { Link as de } from "@tiptap/extension-link";
|
|
25
|
-
import { Strike as
|
|
26
|
-
import { Text as
|
|
27
|
-
import { Underline as
|
|
25
|
+
import { Strike as Ye } from "@tiptap/extension-strike";
|
|
26
|
+
import { Text as We } from "@tiptap/extension-text";
|
|
27
|
+
import { Underline as je } from "@tiptap/extension-underline";
|
|
28
28
|
import * as Ve from "prosemirror-view";
|
|
29
|
-
import { Decoration as
|
|
29
|
+
import { Decoration as D, DecorationSet as F } from "prosemirror-view";
|
|
30
30
|
const O = [
|
|
31
31
|
"backgroundColor",
|
|
32
32
|
"textColor",
|
|
@@ -54,12 +54,12 @@ function k(o, e) {
|
|
|
54
54
|
break;
|
|
55
55
|
i -= 1, r = t.node(i);
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const a = r.attrs.id, s = r.firstChild, d = s.type, l = r.childCount === 2 ? r.lastChild.childCount : 0, c = t.start(i), u = t.end(i);
|
|
58
58
|
return {
|
|
59
|
-
id:
|
|
59
|
+
id: a,
|
|
60
60
|
node: r,
|
|
61
61
|
contentNode: s,
|
|
62
|
-
contentType:
|
|
62
|
+
contentType: d,
|
|
63
63
|
numChildBlocks: l,
|
|
64
64
|
startPos: c,
|
|
65
65
|
endPos: u,
|
|
@@ -79,7 +79,7 @@ function Je(o) {
|
|
|
79
79
|
);
|
|
80
80
|
return Ke(e);
|
|
81
81
|
}
|
|
82
|
-
const
|
|
82
|
+
const j = C.create({
|
|
83
83
|
name: "uniqueID",
|
|
84
84
|
// we’ll set a very high priority to make sure this runs first
|
|
85
85
|
// and is compatible with `appendTransaction` hooks of other extensions
|
|
@@ -111,14 +111,14 @@ const W = C.create({
|
|
|
111
111
|
// check initial content for missing ids
|
|
112
112
|
onCreate() {
|
|
113
113
|
if (this.editor.extensionManager.extensions.find(
|
|
114
|
-
(
|
|
114
|
+
(d) => d.name === "collaboration"
|
|
115
115
|
))
|
|
116
116
|
return;
|
|
117
|
-
const { view: o, state: e } = this.editor, { tr: t, doc: n } = e, { types: r, attributeName: i, generateID:
|
|
118
|
-
|
|
117
|
+
const { view: o, state: e } = this.editor, { tr: t, doc: n } = e, { types: r, attributeName: i, generateID: a } = this.options;
|
|
118
|
+
$(n, (d) => r.includes(d.type.name) && d.attrs[i] === null).forEach(({ node: d, pos: l }) => {
|
|
119
119
|
t.setNodeMarkup(l, void 0, {
|
|
120
|
-
...
|
|
121
|
-
[i]:
|
|
120
|
+
...d.attrs,
|
|
121
|
+
[i]: a()
|
|
122
122
|
});
|
|
123
123
|
}), t.setMeta("addToHistory", !1), o.dispatch(t);
|
|
124
124
|
},
|
|
@@ -128,25 +128,25 @@ const W = C.create({
|
|
|
128
128
|
new B({
|
|
129
129
|
key: new v("uniqueID"),
|
|
130
130
|
appendTransaction: (t, n, r) => {
|
|
131
|
-
const i = t.some((m) => m.docChanged) && !n.doc.eq(r.doc),
|
|
131
|
+
const i = t.some((m) => m.docChanged) && !n.doc.eq(r.doc), a = this.options.filterTransaction && t.some((m) => {
|
|
132
132
|
var y, g;
|
|
133
133
|
return !(!((g = (y = this.options).filterTransaction) === null || g === void 0) && g.call(y, m));
|
|
134
134
|
});
|
|
135
|
-
if (!i ||
|
|
135
|
+
if (!i || a)
|
|
136
136
|
return;
|
|
137
|
-
const { tr: s } = r, { types:
|
|
137
|
+
const { tr: s } = r, { types: d, attributeName: l, generateID: c } = this.options, u = Te(
|
|
138
138
|
n.doc,
|
|
139
139
|
t
|
|
140
140
|
), { mapping: f } = u;
|
|
141
|
-
if (
|
|
142
|
-
const y =
|
|
141
|
+
if (Me(u).forEach(({ newRange: m }) => {
|
|
142
|
+
const y = we(
|
|
143
143
|
r.doc,
|
|
144
144
|
m,
|
|
145
|
-
(T) =>
|
|
146
|
-
), g = y.map(({ node: T }) => T.attrs[l]).filter((T) => T !== null),
|
|
145
|
+
(T) => d.includes(T.type.name)
|
|
146
|
+
), g = y.map(({ node: T }) => T.attrs[l]).filter((T) => T !== null), z = Je(g);
|
|
147
147
|
y.forEach(({ node: T, pos: H }) => {
|
|
148
|
-
var
|
|
149
|
-
const J = (
|
|
148
|
+
var U;
|
|
149
|
+
const J = (U = s.doc.nodeAt(H)) === null || U === void 0 ? void 0 : U.attrs[l];
|
|
150
150
|
if (J === null) {
|
|
151
151
|
s.setNodeMarkup(H, void 0, {
|
|
152
152
|
...T.attrs,
|
|
@@ -155,7 +155,7 @@ const W = C.create({
|
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
const { deleted: ve } = f.invert().mapResult(H);
|
|
158
|
-
ve &&
|
|
158
|
+
ve && z.includes(J) && s.setNodeMarkup(H, void 0, {
|
|
159
159
|
...T.attrs,
|
|
160
160
|
[l]: c()
|
|
161
161
|
});
|
|
@@ -193,24 +193,24 @@ const W = C.create({
|
|
|
193
193
|
transformPasted: (t) => {
|
|
194
194
|
if (!e)
|
|
195
195
|
return t;
|
|
196
|
-
const { types: n, attributeName: r } = this.options, i = (
|
|
196
|
+
const { types: n, attributeName: r } = this.options, i = (a) => {
|
|
197
197
|
const s = [];
|
|
198
|
-
return
|
|
199
|
-
if (
|
|
200
|
-
s.push(
|
|
198
|
+
return a.forEach((d) => {
|
|
199
|
+
if (d.isText) {
|
|
200
|
+
s.push(d);
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
|
-
if (!n.includes(
|
|
204
|
-
s.push(
|
|
203
|
+
if (!n.includes(d.type.name)) {
|
|
204
|
+
s.push(d.copy(i(d.content)));
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
|
-
const l =
|
|
207
|
+
const l = d.type.create(
|
|
208
208
|
{
|
|
209
|
-
...
|
|
209
|
+
...d.attrs,
|
|
210
210
|
[r]: null
|
|
211
211
|
},
|
|
212
|
-
i(
|
|
213
|
-
|
|
212
|
+
i(d.content),
|
|
213
|
+
d.marks
|
|
214
214
|
);
|
|
215
215
|
s.push(l);
|
|
216
216
|
}), P.from(s);
|
|
@@ -268,9 +268,9 @@ function he(o, e) {
|
|
|
268
268
|
throw new Xe(n);
|
|
269
269
|
return t;
|
|
270
270
|
}
|
|
271
|
-
function
|
|
271
|
+
function R(o, e) {
|
|
272
272
|
let t = o.id;
|
|
273
|
-
t === void 0 && (t =
|
|
273
|
+
t === void 0 && (t = j.options.generateID());
|
|
274
274
|
let n = o.type;
|
|
275
275
|
n === void 0 && (n = "paragraph");
|
|
276
276
|
let r;
|
|
@@ -288,14 +288,14 @@ function F(o, e) {
|
|
|
288
288
|
const i = [];
|
|
289
289
|
if (o.children)
|
|
290
290
|
for (const s of o.children)
|
|
291
|
-
i.push(
|
|
292
|
-
const
|
|
291
|
+
i.push(R(s, e));
|
|
292
|
+
const a = e.nodes.blockGroup.create({}, i);
|
|
293
293
|
return e.nodes.blockContainer.create(
|
|
294
294
|
{
|
|
295
295
|
id: t,
|
|
296
296
|
...o.props
|
|
297
297
|
},
|
|
298
|
-
i.length > 0 ? [r,
|
|
298
|
+
i.length > 0 ? [r, a] : r
|
|
299
299
|
);
|
|
300
300
|
}
|
|
301
301
|
function et(o) {
|
|
@@ -304,15 +304,15 @@ function et(o) {
|
|
|
304
304
|
return o.content.forEach((n) => {
|
|
305
305
|
const r = {};
|
|
306
306
|
let i;
|
|
307
|
-
for (const
|
|
308
|
-
if (
|
|
309
|
-
i =
|
|
310
|
-
else if (le.has(
|
|
311
|
-
r[
|
|
312
|
-
else if (ce.has(
|
|
313
|
-
r[
|
|
307
|
+
for (const a of n.marks)
|
|
308
|
+
if (a.type.name === "link")
|
|
309
|
+
i = a;
|
|
310
|
+
else if (le.has(a.type.name))
|
|
311
|
+
r[a.type.name] = !0;
|
|
312
|
+
else if (ce.has(a.type.name))
|
|
313
|
+
r[a.type.name] = a.attrs.color;
|
|
314
314
|
else
|
|
315
|
-
throw Error("Mark is of an unrecognized type: " +
|
|
315
|
+
throw Error("Mark is of an unrecognized type: " + a.type.name);
|
|
316
316
|
i && t && i.attrs.href === t.href ? t.content.push({
|
|
317
317
|
type: "text",
|
|
318
318
|
text: n.textContent,
|
|
@@ -334,7 +334,7 @@ function et(o) {
|
|
|
334
334
|
}), t = void 0);
|
|
335
335
|
}), e;
|
|
336
336
|
}
|
|
337
|
-
function
|
|
337
|
+
function w(o, e) {
|
|
338
338
|
if (o.type.name !== "blockContainer")
|
|
339
339
|
throw Error(
|
|
340
340
|
"Node must be of type blockContainer, but is of type" + o.type.name + "."
|
|
@@ -344,7 +344,7 @@ function M(o, e) {
|
|
|
344
344
|
return t;
|
|
345
345
|
const n = k(o, 0);
|
|
346
346
|
let r = n.id;
|
|
347
|
-
r === null && (r =
|
|
347
|
+
r === null && (r = j.options.generateID());
|
|
348
348
|
const i = {};
|
|
349
349
|
for (const [l, c] of Object.entries({
|
|
350
350
|
...n.node.attrs,
|
|
@@ -356,17 +356,17 @@ function M(o, e) {
|
|
|
356
356
|
);
|
|
357
357
|
ee[n.contentType.name].has(l) && (i[l] = c);
|
|
358
358
|
}
|
|
359
|
-
const
|
|
359
|
+
const a = et(n.contentNode), s = [];
|
|
360
360
|
for (let l = 0; l < n.numChildBlocks; l++)
|
|
361
|
-
s.push(
|
|
362
|
-
const
|
|
361
|
+
s.push(w(n.node.lastChild.child(l)));
|
|
362
|
+
const d = {
|
|
363
363
|
id: r,
|
|
364
364
|
type: n.contentType.name,
|
|
365
365
|
props: i,
|
|
366
|
-
content:
|
|
366
|
+
content: a,
|
|
367
367
|
children: s
|
|
368
368
|
};
|
|
369
|
-
return e == null || e.set(o,
|
|
369
|
+
return e == null || e.set(o, d), d;
|
|
370
370
|
}
|
|
371
371
|
function V(o, e) {
|
|
372
372
|
let t, n;
|
|
@@ -380,24 +380,24 @@ function V(o, e) {
|
|
|
380
380
|
function pe(o, e, t = "before", n) {
|
|
381
381
|
const r = typeof e == "string" ? e : e.id, i = [];
|
|
382
382
|
for (const l of o)
|
|
383
|
-
i.push(
|
|
384
|
-
let
|
|
385
|
-
const { node: s, posBeforeNode:
|
|
386
|
-
if (t === "before" && (
|
|
383
|
+
i.push(R(l, n.schema));
|
|
384
|
+
let a = -1;
|
|
385
|
+
const { node: s, posBeforeNode: d } = V(r, n.state.doc);
|
|
386
|
+
if (t === "before" && (a = d), t === "after" && (a = d + s.nodeSize), t === "nested") {
|
|
387
387
|
if (s.childCount < 2) {
|
|
388
|
-
|
|
388
|
+
a = d + s.firstChild.nodeSize + 1;
|
|
389
389
|
const l = n.state.schema.nodes.blockGroup.create(
|
|
390
390
|
{},
|
|
391
391
|
i
|
|
392
392
|
);
|
|
393
393
|
n.view.dispatch(
|
|
394
|
-
n.state.tr.insert(
|
|
394
|
+
n.state.tr.insert(a, l)
|
|
395
395
|
);
|
|
396
396
|
return;
|
|
397
397
|
}
|
|
398
|
-
|
|
398
|
+
a = d + s.firstChild.nodeSize + 2;
|
|
399
399
|
}
|
|
400
|
-
n.view.dispatch(n.state.tr.insert(
|
|
400
|
+
n.view.dispatch(n.state.tr.insert(a, i));
|
|
401
401
|
}
|
|
402
402
|
function tt(o, e, t) {
|
|
403
403
|
const n = typeof o == "string" ? o : o.id, { posBeforeNode: r } = V(n, t.state.doc);
|
|
@@ -416,10 +416,10 @@ function fe(o, e) {
|
|
|
416
416
|
if (r.type.name !== "blockContainer" || !t.has(r.attrs.id))
|
|
417
417
|
return !0;
|
|
418
418
|
t.delete(r.attrs.id);
|
|
419
|
-
const
|
|
419
|
+
const a = e.state.doc.nodeSize;
|
|
420
420
|
e.commands.BNDeleteBlock(i - n + 1);
|
|
421
421
|
const s = e.state.doc.nodeSize;
|
|
422
|
-
return n +=
|
|
422
|
+
return n += a - s, !1;
|
|
423
423
|
}), t.size > 0) {
|
|
424
424
|
let r = [...t].join(`
|
|
425
425
|
`);
|
|
@@ -453,20 +453,20 @@ function rt(o) {
|
|
|
453
453
|
...o.unorderedListItemBlockTypes
|
|
454
454
|
]), t = (n) => {
|
|
455
455
|
let r = n.children.length, i;
|
|
456
|
-
for (let
|
|
457
|
-
const
|
|
456
|
+
for (let a = 0; a < r; a++) {
|
|
457
|
+
const d = n.children[a].children[0], l = d.children[0], c = d.children.length === 2 ? d.children[1] : null, u = e.has(
|
|
458
458
|
l.properties.dataContentType
|
|
459
459
|
), f = u ? o.orderedListItemBlockTypes.has(
|
|
460
460
|
l.properties.dataContentType
|
|
461
461
|
) ? "ol" : "ul" : null;
|
|
462
462
|
if (c !== null && t(c), i && i.tagName !== f) {
|
|
463
463
|
n.children.splice(
|
|
464
|
-
|
|
464
|
+
a - i.children.length,
|
|
465
465
|
i.children.length,
|
|
466
466
|
i
|
|
467
467
|
);
|
|
468
468
|
const p = i.children.length - 1;
|
|
469
|
-
|
|
469
|
+
a -= p, r -= p, i = void 0;
|
|
470
470
|
}
|
|
471
471
|
if (u) {
|
|
472
472
|
i || (i = Z(
|
|
@@ -477,11 +477,11 @@ function rt(o) {
|
|
|
477
477
|
);
|
|
478
478
|
p.children.push(l.children[0]), c !== null && p.children.push(...c.children), i.children.push(p);
|
|
479
479
|
} else if (c !== null) {
|
|
480
|
-
n.children.splice(
|
|
480
|
+
n.children.splice(a + 1, 0, ...c.children), n.children[a] = l.children[0];
|
|
481
481
|
const p = c.children.length;
|
|
482
|
-
|
|
482
|
+
a += p, r += p;
|
|
483
483
|
} else
|
|
484
|
-
n.children[
|
|
484
|
+
n.children[a] = l.children[0];
|
|
485
485
|
}
|
|
486
486
|
i && n.children.splice(
|
|
487
487
|
r - i.children.length,
|
|
@@ -494,10 +494,10 @@ function rt(o) {
|
|
|
494
494
|
async function me(o, e) {
|
|
495
495
|
const t = document.createElement("div"), n = Ae.fromSchema(e);
|
|
496
496
|
for (const i of o) {
|
|
497
|
-
const
|
|
497
|
+
const a = R(i, e), s = n.serializeNode(a);
|
|
498
498
|
t.appendChild(s);
|
|
499
499
|
}
|
|
500
|
-
return (await
|
|
500
|
+
return (await W().use(ie, { fragment: !0 }).use(rt, {
|
|
501
501
|
orderedListItemBlockTypes: /* @__PURE__ */ new Set(["numberedListItem"]),
|
|
502
502
|
unorderedListItemBlockTypes: /* @__PURE__ */ new Set(["bulletListItem"])
|
|
503
503
|
}).use(se).process(t.innerHTML)).value;
|
|
@@ -506,15 +506,15 @@ async function ke(o, e) {
|
|
|
506
506
|
const t = document.createElement("div");
|
|
507
507
|
t.innerHTML = o.trim();
|
|
508
508
|
const r = Pe.fromSchema(e).parse(t), i = [];
|
|
509
|
-
for (let
|
|
510
|
-
i.push(
|
|
509
|
+
for (let a = 0; a < r.firstChild.childCount; a++)
|
|
510
|
+
i.push(w(r.firstChild.child(a)));
|
|
511
511
|
return i;
|
|
512
512
|
}
|
|
513
513
|
async function it(o, e) {
|
|
514
|
-
return (await
|
|
514
|
+
return (await W().use(ie, { fragment: !0 }).use(nt).use(He).use(ae).use(De).process(await me(o, e))).value;
|
|
515
515
|
}
|
|
516
516
|
async function st(o, e) {
|
|
517
|
-
const t = await
|
|
517
|
+
const t = await W().use(Oe).use(ae).use(_e).use(se).process(o);
|
|
518
518
|
return ke(t.value, e);
|
|
519
519
|
}
|
|
520
520
|
const at = C.create({
|
|
@@ -618,10 +618,10 @@ const at = C.create({
|
|
|
618
618
|
apply(e, t, n, r) {
|
|
619
619
|
if (t.currentTransactionOldBlockAttrs = {}, t.updatedBlocks.clear(), !e.docChanged || n.doc.eq(r.doc))
|
|
620
620
|
return t;
|
|
621
|
-
const i = {},
|
|
622
|
-
|
|
623
|
-
),
|
|
624
|
-
for (let l of
|
|
621
|
+
const i = {}, a = $(n.doc, (l) => l.attrs.id), s = new Map(
|
|
622
|
+
a.map((l) => [l.node.attrs.id, l])
|
|
623
|
+
), d = $(r.doc, (l) => l.attrs.id);
|
|
624
|
+
for (let l of d) {
|
|
625
625
|
const c = s.get(l.node.attrs.id), u = c == null ? void 0 : c.node.firstChild, f = l.node.firstChild;
|
|
626
626
|
if (c && u && f) {
|
|
627
627
|
const p = {
|
|
@@ -651,22 +651,22 @@ const at = C.create({
|
|
|
651
651
|
return e.doc.descendants((r, i) => {
|
|
652
652
|
if (!r.attrs.id || !t.updatedBlocks.has(r.attrs.id))
|
|
653
653
|
return;
|
|
654
|
-
const
|
|
655
|
-
for (let [l, c] of Object.entries(
|
|
654
|
+
const a = t.currentTransactionOldBlockAttrs[r.attrs.id], s = {};
|
|
655
|
+
for (let [l, c] of Object.entries(a))
|
|
656
656
|
s["data-prev-" + lt[l]] = c || "none";
|
|
657
|
-
const
|
|
657
|
+
const d = D.node(i, i + r.nodeSize, {
|
|
658
658
|
...s
|
|
659
659
|
});
|
|
660
|
-
n.push(
|
|
661
|
-
}),
|
|
660
|
+
n.push(d);
|
|
661
|
+
}), F.create(e.doc, n);
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
664
|
});
|
|
665
|
-
}, ut = "
|
|
665
|
+
}, ut = "_blockOuter_1xym9_5", ht = "_blockContent_1xym9_10", pt = "_blockGroup_1xym9_26", ft = "_block_1xym9_5", mt = "_isEmpty_1xym9_215", kt = "_isFilter_1xym9_216", gt = "_hasAnchor_1xym9_229", b = {
|
|
666
666
|
blockOuter: ut,
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
667
|
+
blockContent: ht,
|
|
668
|
+
blockGroup: pt,
|
|
669
|
+
block: ft,
|
|
670
670
|
isEmpty: mt,
|
|
671
671
|
isFilter: kt,
|
|
672
672
|
hasAnchor: gt
|
|
@@ -742,18 +742,18 @@ const at = C.create({
|
|
|
742
742
|
const r = k(t.doc, o);
|
|
743
743
|
if (r === void 0)
|
|
744
744
|
return !1;
|
|
745
|
-
const { startPos: i, endPos:
|
|
745
|
+
const { startPos: i, endPos: a, node: s, contentNode: d } = r;
|
|
746
746
|
if (n) {
|
|
747
747
|
if (e.children !== void 0) {
|
|
748
748
|
const l = [];
|
|
749
749
|
for (const c of e.children)
|
|
750
|
-
l.push(
|
|
750
|
+
l.push(R(c, t.schema));
|
|
751
751
|
s.childCount === 2 ? t.tr.replace(
|
|
752
|
-
i +
|
|
753
|
-
|
|
752
|
+
i + d.nodeSize + 1,
|
|
753
|
+
a - 1,
|
|
754
754
|
new A(P.from(l), 0, 0)
|
|
755
755
|
) : t.tr.insert(
|
|
756
|
-
i +
|
|
756
|
+
i + d.nodeSize,
|
|
757
757
|
t.schema.nodes.blockGroup.create({}, l)
|
|
758
758
|
);
|
|
759
759
|
}
|
|
@@ -761,7 +761,7 @@ const at = C.create({
|
|
|
761
761
|
let l = [];
|
|
762
762
|
typeof e.content == "string" ? l.push(t.schema.text(e.content)) : l = he(e.content, t.schema), t.tr.replace(
|
|
763
763
|
i + 1,
|
|
764
|
-
i +
|
|
764
|
+
i + d.nodeSize - 1,
|
|
765
765
|
new A(P.from(l), 0, 0)
|
|
766
766
|
);
|
|
767
767
|
}
|
|
@@ -769,7 +769,7 @@ const at = C.create({
|
|
|
769
769
|
i,
|
|
770
770
|
e.type === void 0 ? void 0 : t.schema.nodes[e.type],
|
|
771
771
|
{
|
|
772
|
-
...
|
|
772
|
+
...d.attrs,
|
|
773
773
|
...e.props
|
|
774
774
|
}
|
|
775
775
|
), t.tr.setNodeMarkup(i - 1, void 0, {
|
|
@@ -803,10 +803,10 @@ const at = C.create({
|
|
|
803
803
|
const i = k(
|
|
804
804
|
e.doc,
|
|
805
805
|
o + 1
|
|
806
|
-
), { node:
|
|
807
|
-
if (
|
|
806
|
+
), { node: a, contentNode: s, startPos: d, endPos: l, depth: c } = i;
|
|
807
|
+
if (a.childCount === 2) {
|
|
808
808
|
const p = e.doc.resolve(
|
|
809
|
-
|
|
809
|
+
d + s.nodeSize + 1
|
|
810
810
|
), m = e.doc.resolve(l - 1), y = p.blockRange(m);
|
|
811
811
|
t && e.tr.lift(y, c - 1);
|
|
812
812
|
}
|
|
@@ -814,7 +814,7 @@ const at = C.create({
|
|
|
814
814
|
for (; f.numChildBlocks > 0; )
|
|
815
815
|
if (u--, f = k(e.doc, u), f === void 0)
|
|
816
816
|
return !1;
|
|
817
|
-
return t && (e.tr.deleteRange(
|
|
817
|
+
return t && (e.tr.deleteRange(d, d + s.nodeSize), e.tr.insertText(s.textContent, u - 1), e.tr.setSelection(
|
|
818
818
|
new Q(e.doc.resolve(u - 1))
|
|
819
819
|
)), !0;
|
|
820
820
|
},
|
|
@@ -824,7 +824,7 @@ const at = C.create({
|
|
|
824
824
|
const r = k(t.doc, o);
|
|
825
825
|
if (r === void 0)
|
|
826
826
|
return !1;
|
|
827
|
-
const { contentNode: i, contentType:
|
|
827
|
+
const { contentNode: i, contentType: a, startPos: s, endPos: d, depth: l } = r, c = t.doc.cut(s + 1, o), u = t.doc.cut(o, d - 1), f = t.schema.nodes.blockContainer.createAndFill(), p = d + 1, m = p + 2;
|
|
828
828
|
return n && (t.tr.insert(p, f), t.tr.replace(
|
|
829
829
|
m,
|
|
830
830
|
m + 1,
|
|
@@ -836,13 +836,13 @@ const at = C.create({
|
|
|
836
836
|
), e && t.tr.setBlockType(
|
|
837
837
|
m,
|
|
838
838
|
m,
|
|
839
|
-
t.schema.node(
|
|
839
|
+
t.schema.node(a).type,
|
|
840
840
|
i.attrs
|
|
841
841
|
), t.tr.setSelection(
|
|
842
842
|
new Q(t.doc.resolve(m))
|
|
843
843
|
), t.tr.replace(
|
|
844
844
|
s + 1,
|
|
845
|
-
|
|
845
|
+
d - 1,
|
|
846
846
|
c.content.size > 0 ? new A(
|
|
847
847
|
P.from(c),
|
|
848
848
|
l + 2,
|
|
@@ -867,8 +867,8 @@ const at = C.create({
|
|
|
867
867
|
const { contentType: r } = k(
|
|
868
868
|
n.doc,
|
|
869
869
|
n.selection.from
|
|
870
|
-
), i = n.selection.$anchor.parentOffset === 0,
|
|
871
|
-
return i && !
|
|
870
|
+
), i = n.selection.$anchor.parentOffset === 0, a = r.name === "paragraph";
|
|
871
|
+
return i && !a ? t.BNUpdateBlock(n.selection.from, {
|
|
872
872
|
type: "paragraph",
|
|
873
873
|
props: {}
|
|
874
874
|
}) : !1;
|
|
@@ -881,8 +881,8 @@ const at = C.create({
|
|
|
881
881
|
const { depth: r, startPos: i } = k(
|
|
882
882
|
n.doc,
|
|
883
883
|
n.selection.from
|
|
884
|
-
),
|
|
885
|
-
return !
|
|
884
|
+
), a = n.selection.$anchor.parentOffset === 0, s = n.selection.anchor === n.selection.head, d = i === 2, l = i - 1;
|
|
885
|
+
return !d && a && s && r === 2 ? t.BNMergeBlocks(l) : !1;
|
|
886
886
|
})
|
|
887
887
|
]),
|
|
888
888
|
Enter: () => this.editor.commands.first(({ commands: t }) => [
|
|
@@ -892,18 +892,18 @@ const at = C.create({
|
|
|
892
892
|
const { node: r, depth: i } = k(
|
|
893
893
|
n.doc,
|
|
894
894
|
n.selection.from
|
|
895
|
-
),
|
|
896
|
-
return
|
|
895
|
+
), a = n.selection.$anchor.parentOffset === 0, s = n.selection.anchor === n.selection.head, d = r.textContent.length === 0, l = i > 2;
|
|
896
|
+
return a && s && d && l ? t.liftListItem("blockContainer") : !1;
|
|
897
897
|
}),
|
|
898
898
|
// Creates a new block and moves the selection to it if the current one is empty, while the selection is also
|
|
899
899
|
// empty & at the start of the block.
|
|
900
900
|
() => t.command(({ state: n, chain: r }) => {
|
|
901
|
-
const { node: i, endPos:
|
|
901
|
+
const { node: i, endPos: a } = k(
|
|
902
902
|
n.doc,
|
|
903
903
|
n.selection.from
|
|
904
|
-
), s = n.selection.$anchor.parentOffset === 0,
|
|
905
|
-
if (s &&
|
|
906
|
-
const c =
|
|
904
|
+
), s = n.selection.$anchor.parentOffset === 0, d = n.selection.anchor === n.selection.head, l = i.textContent.length === 0;
|
|
905
|
+
if (s && d && l) {
|
|
906
|
+
const c = a + 1, u = c + 2;
|
|
907
907
|
return r().BNCreateBlock(c).setTextSelection(u).run(), !0;
|
|
908
908
|
}
|
|
909
909
|
return !1;
|
|
@@ -1021,7 +1021,7 @@ const at = C.create({
|
|
|
1021
1021
|
},
|
|
1022
1022
|
addInputRules() {
|
|
1023
1023
|
return [
|
|
1024
|
-
...["1", "2", "3"].map((o) => new
|
|
1024
|
+
...["1", "2", "3"].map((o) => new Y({
|
|
1025
1025
|
find: new RegExp(`^(#{${parseInt(o)}})\\s$`),
|
|
1026
1026
|
handler: ({ state: e, chain: t, range: n }) => {
|
|
1027
1027
|
t().BNUpdateBlock(e.selection.from, {
|
|
@@ -1068,10 +1068,10 @@ const at = C.create({
|
|
|
1068
1068
|
o.state.doc,
|
|
1069
1069
|
o.state.selection.from
|
|
1070
1070
|
), n = o.state.selection.anchor === o.state.selection.head;
|
|
1071
|
-
return !t.name.endsWith("ListItem") || !n ? !1 : o.commands.first(({ state: r, chain: i, commands:
|
|
1071
|
+
return !t.name.endsWith("ListItem") || !n ? !1 : o.commands.first(({ state: r, chain: i, commands: a }) => [
|
|
1072
1072
|
() => (
|
|
1073
1073
|
// Changes list item block to a text block if the content is empty.
|
|
1074
|
-
|
|
1074
|
+
a.command(() => e.textContent.length === 0 ? a.BNUpdateBlock(r.selection.from, {
|
|
1075
1075
|
type: "paragraph",
|
|
1076
1076
|
props: {}
|
|
1077
1077
|
}) : !1)
|
|
@@ -1079,7 +1079,7 @@ const at = C.create({
|
|
|
1079
1079
|
() => (
|
|
1080
1080
|
// Splits the current block, moving content inside that's after the cursor to a new block of the same type
|
|
1081
1081
|
// below.
|
|
1082
|
-
|
|
1082
|
+
a.command(() => e.textContent.length > 0 ? (i().deleteSelection().BNSplitBlock(r.selection.from, !0).run(), !0) : !1)
|
|
1083
1083
|
)
|
|
1084
1084
|
]);
|
|
1085
1085
|
}, Tt = E.create({
|
|
@@ -1089,7 +1089,7 @@ const at = C.create({
|
|
|
1089
1089
|
addInputRules() {
|
|
1090
1090
|
return [
|
|
1091
1091
|
// Creates an unordered list when starting with "-", "+", or "*".
|
|
1092
|
-
new
|
|
1092
|
+
new Y({
|
|
1093
1093
|
find: new RegExp("^[-+*]\\s$"),
|
|
1094
1094
|
handler: ({ state: o, chain: e, range: t }) => {
|
|
1095
1095
|
e().BNUpdateBlock(o.selection.from, {
|
|
@@ -1142,31 +1142,31 @@ const at = C.create({
|
|
|
1142
1142
|
["p", 0]
|
|
1143
1143
|
];
|
|
1144
1144
|
}
|
|
1145
|
-
}),
|
|
1146
|
-
key:
|
|
1145
|
+
}), Mt = new v("numbered-list-indexing"), wt = () => new B({
|
|
1146
|
+
key: Mt,
|
|
1147
1147
|
appendTransaction: (o, e, t) => {
|
|
1148
1148
|
const n = t.tr;
|
|
1149
1149
|
n.setMeta("numberedListIndexing", !0);
|
|
1150
1150
|
let r = !1;
|
|
1151
|
-
return t.doc.descendants((i,
|
|
1151
|
+
return t.doc.descendants((i, a) => {
|
|
1152
1152
|
if (i.type.name === "blockContainer" && i.firstChild.type.name === "numberedListItem") {
|
|
1153
1153
|
let s = "1";
|
|
1154
|
-
const
|
|
1154
|
+
const d = a === 1, l = k(n.doc, a + 1);
|
|
1155
1155
|
if (l === void 0)
|
|
1156
1156
|
return;
|
|
1157
|
-
if (!
|
|
1158
|
-
const f = k(n.doc,
|
|
1157
|
+
if (!d) {
|
|
1158
|
+
const f = k(n.doc, a - 2);
|
|
1159
1159
|
if (f === void 0)
|
|
1160
1160
|
return;
|
|
1161
1161
|
if (!(l.depth !== f.depth)) {
|
|
1162
1162
|
const m = f.contentNode;
|
|
1163
1163
|
if (f.contentType.name === "numberedListItem") {
|
|
1164
|
-
const
|
|
1165
|
-
s = (parseInt(
|
|
1164
|
+
const z = m.attrs.index;
|
|
1165
|
+
s = (parseInt(z) + 1).toString();
|
|
1166
1166
|
}
|
|
1167
1167
|
}
|
|
1168
1168
|
}
|
|
1169
|
-
l.contentNode.attrs.index !== s && (r = !0, n.setNodeMarkup(
|
|
1169
|
+
l.contentNode.attrs.index !== s && (r = !0, n.setNodeMarkup(a + 1, void 0, {
|
|
1170
1170
|
index: s
|
|
1171
1171
|
}));
|
|
1172
1172
|
}
|
|
@@ -1190,7 +1190,7 @@ const at = C.create({
|
|
|
1190
1190
|
addInputRules() {
|
|
1191
1191
|
return [
|
|
1192
1192
|
// Creates an ordered list when starting with "1.".
|
|
1193
|
-
new
|
|
1193
|
+
new Y({
|
|
1194
1194
|
find: new RegExp("^1\\.\\s$"),
|
|
1195
1195
|
handler: ({ state: o, chain: e, range: t }) => {
|
|
1196
1196
|
e().BNUpdateBlock(o.selection.from, {
|
|
@@ -1207,7 +1207,7 @@ const at = C.create({
|
|
|
1207
1207
|
};
|
|
1208
1208
|
},
|
|
1209
1209
|
addProseMirrorPlugins() {
|
|
1210
|
-
return [
|
|
1210
|
+
return [wt()];
|
|
1211
1211
|
},
|
|
1212
1212
|
parseHTML() {
|
|
1213
1213
|
return [
|
|
@@ -1262,14 +1262,15 @@ const at = C.create({
|
|
|
1262
1262
|
topNode: !0,
|
|
1263
1263
|
content: "blockGroup"
|
|
1264
1264
|
})
|
|
1265
|
-
], It = "
|
|
1265
|
+
], It = "_bnEditor_8k3n0_3", St = "_bnRoot_8k3n0_19", At = "_defaultStyles_8k3n0_34", Pt = "_dragPreview_8k3n0_57", _ = {
|
|
1266
1266
|
bnEditor: It,
|
|
1267
1267
|
bnRoot: St,
|
|
1268
|
-
|
|
1269
|
-
|
|
1268
|
+
defaultStyles: At,
|
|
1269
|
+
dragPreview: Pt
|
|
1270
|
+
}, Nt = xe(
|
|
1270
1271
|
(o) => o.type.name === "blockContainer"
|
|
1271
1272
|
);
|
|
1272
|
-
function
|
|
1273
|
+
function q() {
|
|
1273
1274
|
return {
|
|
1274
1275
|
active: !1,
|
|
1275
1276
|
triggerCharacter: void 0,
|
|
@@ -1280,7 +1281,7 @@ function $() {
|
|
|
1280
1281
|
decorationId: void 0
|
|
1281
1282
|
};
|
|
1282
1283
|
}
|
|
1283
|
-
class
|
|
1284
|
+
class Lt {
|
|
1284
1285
|
constructor({
|
|
1285
1286
|
editor: e,
|
|
1286
1287
|
pluginKey: t,
|
|
@@ -1293,7 +1294,7 @@ class Nt {
|
|
|
1293
1294
|
h(this, "suggestionsMenu");
|
|
1294
1295
|
h(this, "pluginState");
|
|
1295
1296
|
h(this, "itemCallback");
|
|
1296
|
-
this.editor = e, this.pluginKey = t, this.pluginState =
|
|
1297
|
+
this.editor = e, this.pluginKey = t, this.pluginState = q(), this.itemCallback = (i) => {
|
|
1297
1298
|
e._tiptapEditor.chain().focus().deleteRange({
|
|
1298
1299
|
from: this.pluginState.queryStartPos - this.pluginState.triggerCharacter.length,
|
|
1299
1300
|
to: e._tiptapEditor.state.selection.from
|
|
@@ -1304,13 +1305,13 @@ class Nt {
|
|
|
1304
1305
|
}, this.suggestionsMenu = r(this.getStaticParams());
|
|
1305
1306
|
}
|
|
1306
1307
|
update(e, t) {
|
|
1307
|
-
const n = this.pluginKey.getState(t), r = this.pluginKey.getState(e.state), i = !n.active && r.active,
|
|
1308
|
-
!i && !s && !
|
|
1308
|
+
const n = this.pluginKey.getState(t), r = this.pluginKey.getState(e.state), i = !n.active && r.active, a = n.active && !r.active, s = n.active && r.active;
|
|
1309
|
+
!i && !s && !a || (this.pluginState = a ? n : r, a && (this.suggestionsMenu.hide(), this.suggestionsMenu.element.removeEventListener(
|
|
1309
1310
|
"mousedown",
|
|
1310
|
-
(
|
|
1311
|
+
(d) => d.preventDefault()
|
|
1311
1312
|
)), s && this.suggestionsMenu.render(this.getDynamicParams(), !1), i && (this.suggestionsMenu.render(this.getDynamicParams(), !0), this.suggestionsMenu.element.addEventListener(
|
|
1312
1313
|
"mousedown",
|
|
1313
|
-
(
|
|
1314
|
+
(d) => d.preventDefault()
|
|
1314
1315
|
)));
|
|
1315
1316
|
}
|
|
1316
1317
|
getStaticParams() {
|
|
@@ -1329,7 +1330,7 @@ class Nt {
|
|
|
1329
1330
|
};
|
|
1330
1331
|
}
|
|
1331
1332
|
}
|
|
1332
|
-
function
|
|
1333
|
+
function Ht({
|
|
1333
1334
|
pluginKey: o,
|
|
1334
1335
|
editor: e,
|
|
1335
1336
|
defaultTriggerCharacter: t,
|
|
@@ -1340,29 +1341,29 @@ function Lt({
|
|
|
1340
1341
|
}) {
|
|
1341
1342
|
if (t.length !== 1)
|
|
1342
1343
|
throw new Error("'char' should be a single character");
|
|
1343
|
-
const
|
|
1344
|
+
const a = (s) => {
|
|
1344
1345
|
s.dispatch(s.state.tr.setMeta(o, { deactivate: !0 }));
|
|
1345
1346
|
};
|
|
1346
1347
|
return new B({
|
|
1347
1348
|
key: o,
|
|
1348
|
-
view: (s) => new
|
|
1349
|
+
view: (s) => new Lt({
|
|
1349
1350
|
editor: e,
|
|
1350
1351
|
pluginKey: o,
|
|
1351
|
-
onSelectItem: (
|
|
1352
|
-
|
|
1352
|
+
onSelectItem: (d) => {
|
|
1353
|
+
a(s), r(d);
|
|
1353
1354
|
},
|
|
1354
1355
|
suggestionsMenuFactory: n
|
|
1355
1356
|
}),
|
|
1356
1357
|
state: {
|
|
1357
1358
|
// Initialize the plugin's internal state.
|
|
1358
1359
|
init() {
|
|
1359
|
-
return
|
|
1360
|
+
return q();
|
|
1360
1361
|
},
|
|
1361
1362
|
// Apply changes to the plugin state from an editor transaction.
|
|
1362
|
-
apply(s,
|
|
1363
|
+
apply(s, d, l, c) {
|
|
1363
1364
|
var f, p, m, y;
|
|
1364
1365
|
if (s.getMeta("orderedListIndexing") !== void 0)
|
|
1365
|
-
return
|
|
1366
|
+
return d;
|
|
1366
1367
|
if ((f = s.getMeta(o)) != null && f.activate)
|
|
1367
1368
|
return {
|
|
1368
1369
|
active: !0,
|
|
@@ -1375,34 +1376,34 @@ function Lt({
|
|
|
1375
1376
|
notFoundCount: 0,
|
|
1376
1377
|
decorationId: `id_${Math.floor(Math.random() * 4294967295)}`
|
|
1377
1378
|
};
|
|
1378
|
-
if (!
|
|
1379
|
-
return
|
|
1380
|
-
const u = { ...
|
|
1379
|
+
if (!d.active)
|
|
1380
|
+
return d;
|
|
1381
|
+
const u = { ...d };
|
|
1381
1382
|
if (u.items = i(
|
|
1382
|
-
c.doc.textBetween(
|
|
1383
|
+
c.doc.textBetween(d.queryStartPos, c.selection.from)
|
|
1383
1384
|
), u.notFoundCount = 0, u.items.length === 0 && (u.notFoundCount = Math.max(
|
|
1384
1385
|
0,
|
|
1385
|
-
|
|
1386
|
+
d.notFoundCount + (c.selection.from - l.selection.from)
|
|
1386
1387
|
)), // Highlighting text should hide the menu.
|
|
1387
1388
|
c.selection.from !== c.selection.to || // Transactions with plugin metadata {deactivate: true} should hide the menu.
|
|
1388
1389
|
(m = s.getMeta(o)) != null && m.deactivate || // Certain mouse events should hide the menu.
|
|
1389
1390
|
// TODO: Change to global mousedown listener.
|
|
1390
1391
|
s.getMeta("focus") || s.getMeta("blur") || s.getMeta("pointer") || // Moving the caret before the character which triggered the menu should hide it.
|
|
1391
|
-
|
|
1392
|
+
d.active && c.selection.from < d.queryStartPos || // Entering more than 3 characters, after the last query that matched with at least 1 menu item, should hide
|
|
1392
1393
|
// the menu.
|
|
1393
1394
|
u.notFoundCount > 3)
|
|
1394
|
-
return
|
|
1395
|
+
return q();
|
|
1395
1396
|
if (((y = s.getMeta(o)) == null ? void 0 : y.selectedItemIndexChanged) !== void 0) {
|
|
1396
1397
|
let g = s.getMeta(o).selectedItemIndexChanged;
|
|
1397
|
-
g < 0 ? g =
|
|
1398
|
+
g < 0 ? g = d.items.length - 1 : g >= d.items.length && (g = 0), u.keyboardHoveredItemIndex = g;
|
|
1398
1399
|
}
|
|
1399
1400
|
return u;
|
|
1400
1401
|
}
|
|
1401
1402
|
},
|
|
1402
1403
|
props: {
|
|
1403
|
-
handleKeyDown(s,
|
|
1404
|
+
handleKeyDown(s, d) {
|
|
1404
1405
|
const l = this.getState(s.state).active;
|
|
1405
|
-
if (
|
|
1406
|
+
if (d.key === t && !l)
|
|
1406
1407
|
return s.dispatch(
|
|
1407
1408
|
s.state.tr.insertText(t).scrollIntoView().setMeta(o, {
|
|
1408
1409
|
activate: !0,
|
|
@@ -1417,36 +1418,36 @@ function Lt({
|
|
|
1417
1418
|
items: f,
|
|
1418
1419
|
keyboardHoveredItemIndex: p
|
|
1419
1420
|
} = o.getState(s.state);
|
|
1420
|
-
return
|
|
1421
|
+
return d.key === "ArrowUp" ? (s.dispatch(
|
|
1421
1422
|
s.state.tr.setMeta(o, {
|
|
1422
1423
|
selectedItemIndexChanged: p - 1
|
|
1423
1424
|
})
|
|
1424
|
-
), !0) :
|
|
1425
|
+
), !0) : d.key === "ArrowDown" ? (s.dispatch(
|
|
1425
1426
|
s.state.tr.setMeta(o, {
|
|
1426
1427
|
selectedItemIndexChanged: p + 1
|
|
1427
1428
|
})
|
|
1428
|
-
), !0) :
|
|
1429
|
+
), !0) : d.key === "Enter" ? (a(s), e._tiptapEditor.chain().focus().deleteRange({
|
|
1429
1430
|
from: u - c.length,
|
|
1430
1431
|
to: e._tiptapEditor.state.selection.from
|
|
1431
1432
|
}).run(), r({
|
|
1432
1433
|
item: f[p],
|
|
1433
1434
|
editor: e
|
|
1434
|
-
}), !0) :
|
|
1435
|
+
}), !0) : d.key === "Escape" ? (a(s), !0) : !1;
|
|
1435
1436
|
},
|
|
1436
1437
|
// Hides menu in cases where mouse click does not cause an editor state change.
|
|
1437
1438
|
handleClick(s) {
|
|
1438
|
-
|
|
1439
|
+
a(s);
|
|
1439
1440
|
},
|
|
1440
1441
|
// Setup decorator on the currently active suggestion.
|
|
1441
1442
|
decorations(s) {
|
|
1442
|
-
const { active:
|
|
1443
|
-
if (!
|
|
1443
|
+
const { active: d, decorationId: l, queryStartPos: c, triggerCharacter: u } = this.getState(s);
|
|
1444
|
+
if (!d)
|
|
1444
1445
|
return null;
|
|
1445
1446
|
if (u === "") {
|
|
1446
|
-
const f =
|
|
1447
|
+
const f = Nt(s.selection);
|
|
1447
1448
|
if (f)
|
|
1448
|
-
return
|
|
1449
|
-
|
|
1449
|
+
return F.create(s.doc, [
|
|
1450
|
+
D.node(
|
|
1450
1451
|
f.pos,
|
|
1451
1452
|
f.pos + f.node.nodeSize,
|
|
1452
1453
|
{
|
|
@@ -1457,8 +1458,8 @@ function Lt({
|
|
|
1457
1458
|
)
|
|
1458
1459
|
]);
|
|
1459
1460
|
}
|
|
1460
|
-
return
|
|
1461
|
-
|
|
1461
|
+
return F.create(s.doc, [
|
|
1462
|
+
D.inline(
|
|
1462
1463
|
c - u.length,
|
|
1463
1464
|
c,
|
|
1464
1465
|
{
|
|
@@ -1472,7 +1473,7 @@ function Lt({
|
|
|
1472
1473
|
}
|
|
1473
1474
|
});
|
|
1474
1475
|
}
|
|
1475
|
-
const K = new v("suggestions-slash-commands"),
|
|
1476
|
+
const K = new v("suggestions-slash-commands"), Ot = C.create({
|
|
1476
1477
|
name: "slash-command",
|
|
1477
1478
|
addOptions() {
|
|
1478
1479
|
return {
|
|
@@ -1486,7 +1487,7 @@ const K = new v("suggestions-slash-commands"), Ht = C.create({
|
|
|
1486
1487
|
throw new Error("required args not defined for SlashMenuExtension");
|
|
1487
1488
|
const o = this.options.commands;
|
|
1488
1489
|
return [
|
|
1489
|
-
|
|
1490
|
+
Ht({
|
|
1490
1491
|
pluginKey: K,
|
|
1491
1492
|
editor: this.options.editor,
|
|
1492
1493
|
defaultTriggerCharacter: "/",
|
|
@@ -1499,12 +1500,12 @@ const K = new v("suggestions-slash-commands"), Ht = C.create({
|
|
|
1499
1500
|
];
|
|
1500
1501
|
}
|
|
1501
1502
|
});
|
|
1502
|
-
class L extends
|
|
1503
|
+
class L extends G {
|
|
1503
1504
|
constructor(t, n) {
|
|
1504
1505
|
super(t, n);
|
|
1505
1506
|
h(this, "nodes");
|
|
1506
1507
|
const r = t.node();
|
|
1507
|
-
this.nodes = [], t.doc.nodesBetween(t.pos, n.pos, (i,
|
|
1508
|
+
this.nodes = [], t.doc.nodesBetween(t.pos, n.pos, (i, a, s) => {
|
|
1508
1509
|
if (s !== null && s.eq(r))
|
|
1509
1510
|
return this.nodes.push(i), !1;
|
|
1510
1511
|
});
|
|
@@ -1525,7 +1526,7 @@ class L extends U {
|
|
|
1525
1526
|
}
|
|
1526
1527
|
map(t, n) {
|
|
1527
1528
|
let r = n.mapResult(this.from), i = n.mapResult(this.to);
|
|
1528
|
-
return i.deleted ?
|
|
1529
|
+
return i.deleted ? G.near(t.resolve(r.pos)) : r.deleted ? G.near(t.resolve(i.pos)) : new L(
|
|
1529
1530
|
t.resolve(r.pos),
|
|
1530
1531
|
t.resolve(i.pos)
|
|
1531
1532
|
);
|
|
@@ -1534,10 +1535,12 @@ class L extends U {
|
|
|
1534
1535
|
return { type: "node", anchor: this.anchor, head: this.head };
|
|
1535
1536
|
}
|
|
1536
1537
|
}
|
|
1537
|
-
const
|
|
1538
|
-
let
|
|
1538
|
+
const _t = Ve.__serializeForClipboard;
|
|
1539
|
+
let M;
|
|
1539
1540
|
function ye(o, e) {
|
|
1540
1541
|
var r;
|
|
1542
|
+
if (!e.dom.isConnected)
|
|
1543
|
+
return;
|
|
1541
1544
|
let t = e.posAtCoords(o);
|
|
1542
1545
|
if (!t)
|
|
1543
1546
|
return;
|
|
@@ -1549,7 +1552,7 @@ function ye(o, e) {
|
|
|
1549
1552
|
return { node: n, id: n.getAttribute("data-id") };
|
|
1550
1553
|
}
|
|
1551
1554
|
}
|
|
1552
|
-
function
|
|
1555
|
+
function Dt(o, e) {
|
|
1553
1556
|
let t = ye(o, e);
|
|
1554
1557
|
if (t && t.node.nodeType === 1) {
|
|
1555
1558
|
const n = e.docView;
|
|
@@ -1558,19 +1561,19 @@ function _t(o, e) {
|
|
|
1558
1561
|
}
|
|
1559
1562
|
return null;
|
|
1560
1563
|
}
|
|
1561
|
-
function
|
|
1564
|
+
function Ft(o, e) {
|
|
1562
1565
|
let t, n;
|
|
1563
|
-
const r = e.resolve(o.from).node().type.spec.group === "blockContent", i = e.resolve(o.to).node().type.spec.group === "blockContent",
|
|
1566
|
+
const r = e.resolve(o.from).node().type.spec.group === "blockContent", i = e.resolve(o.to).node().type.spec.group === "blockContent", a = Math.min(o.$anchor.depth, o.$head.depth);
|
|
1564
1567
|
if (r && i) {
|
|
1565
|
-
const s = o.$from.start(
|
|
1566
|
-
t = e.resolve(s - 1).pos, n = e.resolve(
|
|
1568
|
+
const s = o.$from.start(a - 1), d = o.$to.end(a - 1);
|
|
1569
|
+
t = e.resolve(s - 1).pos, n = e.resolve(d + 1).pos;
|
|
1567
1570
|
} else
|
|
1568
1571
|
t = o.from, n = o.to;
|
|
1569
1572
|
return { from: t, to: n };
|
|
1570
1573
|
}
|
|
1571
1574
|
function oe(o, e, t = e) {
|
|
1572
1575
|
e === t && (t += o.state.doc.resolve(e + 1).node().nodeSize);
|
|
1573
|
-
const n = o.domAtPos(e).node.cloneNode(!0), r = o.domAtPos(e).node, i = (
|
|
1576
|
+
const n = o.domAtPos(e).node.cloneNode(!0), r = o.domAtPos(e).node, i = (c, u) => Array.prototype.indexOf.call(c.children, u), a = i(
|
|
1574
1577
|
r,
|
|
1575
1578
|
// Expects from position to be just before the first selected block.
|
|
1576
1579
|
o.domAtPos(e + 1).node.parentElement
|
|
@@ -1579,14 +1582,18 @@ function oe(o, e, t = e) {
|
|
|
1579
1582
|
// Expects to position to be just after the last selected block.
|
|
1580
1583
|
o.domAtPos(t - 1).node.parentElement
|
|
1581
1584
|
);
|
|
1582
|
-
for (let
|
|
1583
|
-
(
|
|
1584
|
-
be(),
|
|
1585
|
+
for (let c = r.childElementCount - 1; c >= 0; c--)
|
|
1586
|
+
(c > s || c < a) && n.removeChild(n.children[c]);
|
|
1587
|
+
be(), M = n;
|
|
1588
|
+
const l = o.dom.className.split(" ").filter(
|
|
1589
|
+
(c) => !c.includes("bn") && !c.includes("ProseMirror") && !c.includes("editor")
|
|
1590
|
+
).join(" ");
|
|
1591
|
+
M.className = M.className + " " + _.dragPreview + " " + l, document.body.appendChild(M);
|
|
1585
1592
|
}
|
|
1586
1593
|
function be() {
|
|
1587
|
-
|
|
1594
|
+
M !== void 0 && (document.body.removeChild(M), M = void 0);
|
|
1588
1595
|
}
|
|
1589
|
-
function
|
|
1596
|
+
function Rt(o, e) {
|
|
1590
1597
|
if (!o.dataTransfer)
|
|
1591
1598
|
return;
|
|
1592
1599
|
const t = e.dom.getBoundingClientRect();
|
|
@@ -1594,19 +1601,19 @@ function Ft(o, e) {
|
|
|
1594
1601
|
left: t.left + t.width / 2,
|
|
1595
1602
|
// take middle of editor
|
|
1596
1603
|
top: o.clientY
|
|
1597
|
-
}, r =
|
|
1604
|
+
}, r = Dt(n, e);
|
|
1598
1605
|
if (r != null) {
|
|
1599
|
-
const i = e.state.selection,
|
|
1606
|
+
const i = e.state.selection, a = e.state.doc, { from: s, to: d } = Ft(i, a), l = s <= r && r < d, c = !i.$anchor.node().eq(i.$head.node());
|
|
1600
1607
|
l && c ? (e.dispatch(
|
|
1601
|
-
e.state.tr.setSelection(L.create(
|
|
1602
|
-
), oe(e, s,
|
|
1608
|
+
e.state.tr.setSelection(L.create(a, s, d))
|
|
1609
|
+
), oe(e, s, d)) : (e.dispatch(
|
|
1603
1610
|
e.state.tr.setSelection(Ne.create(e.state.doc, r))
|
|
1604
1611
|
), oe(e, r));
|
|
1605
|
-
let u = e.state.selection.content(), { dom: f, text: p } =
|
|
1606
|
-
o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", f.innerHTML), o.dataTransfer.setData("text/plain", p), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(
|
|
1612
|
+
let u = e.state.selection.content(), { dom: f, text: p } = _t(e, u);
|
|
1613
|
+
o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", f.innerHTML), o.dataTransfer.setData("text/plain", p), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(M, 0, 0), e.dragging = { slice: u, move: !0 };
|
|
1607
1614
|
}
|
|
1608
1615
|
}
|
|
1609
|
-
class
|
|
1616
|
+
class zt {
|
|
1610
1617
|
constructor({
|
|
1611
1618
|
editor: e,
|
|
1612
1619
|
blockMenuFactory: t,
|
|
@@ -1663,7 +1670,7 @@ class Rt {
|
|
|
1663
1670
|
(t = this.blockMenu.element) != null && t.contains(e.target) || (this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), this.menuFrozen = !1);
|
|
1664
1671
|
});
|
|
1665
1672
|
h(this, "onMouseMove", (e) => {
|
|
1666
|
-
var
|
|
1673
|
+
var a, s;
|
|
1667
1674
|
if (this.menuFrozen)
|
|
1668
1675
|
return;
|
|
1669
1676
|
const t = this.editor.view.dom.firstChild.getBoundingClientRect();
|
|
@@ -1677,7 +1684,7 @@ class Rt {
|
|
|
1677
1684
|
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
|
|
1678
1685
|
return;
|
|
1679
1686
|
}
|
|
1680
|
-
if (this.menuOpen && ((
|
|
1687
|
+
if (this.menuOpen && ((a = this.hoveredBlockContent) != null && a.hasAttribute("data-id")) && ((s = this.hoveredBlockContent) == null ? void 0 : s.getAttribute("data-id")) === r.id)
|
|
1681
1688
|
return;
|
|
1682
1689
|
const i = r.node.firstChild;
|
|
1683
1690
|
this.hoveredBlockContent = i, i && (this.menuOpen ? this.blockMenu.render(this.getDynamicParams(), !1) : (this.menuOpen = !0, this.blockMenu.render(this.getDynamicParams(), !0)));
|
|
@@ -1700,8 +1707,8 @@ class Rt {
|
|
|
1700
1707
|
return;
|
|
1701
1708
|
const { contentNode: r, endPos: i } = n;
|
|
1702
1709
|
if (r.textContent.length !== 0) {
|
|
1703
|
-
const
|
|
1704
|
-
this.editor.chain().BNCreateBlock(
|
|
1710
|
+
const a = i + 1, s = a + 2;
|
|
1711
|
+
this.editor.chain().BNCreateBlock(a).BNUpdateBlock(s, { type: "paragraph", props: {} }).setTextSelection(s).run();
|
|
1705
1712
|
} else
|
|
1706
1713
|
this.editor.commands.setTextSelection(i);
|
|
1707
1714
|
this.editor.view.focus(), this.editor.view.dispatch(
|
|
@@ -1740,7 +1747,7 @@ class Rt {
|
|
|
1740
1747
|
return {
|
|
1741
1748
|
addBlock: () => this.addBlock(),
|
|
1742
1749
|
deleteBlock: () => this.deleteBlock(),
|
|
1743
|
-
blockDragStart: (e) =>
|
|
1750
|
+
blockDragStart: (e) => Rt(e, this.editor.view),
|
|
1744
1751
|
blockDragEnd: () => be(),
|
|
1745
1752
|
freezeMenu: () => {
|
|
1746
1753
|
this.menuFrozen = !0;
|
|
@@ -1766,14 +1773,14 @@ class Rt {
|
|
|
1766
1773
|
};
|
|
1767
1774
|
}
|
|
1768
1775
|
}
|
|
1769
|
-
const
|
|
1776
|
+
const Ut = (o) => new B({
|
|
1770
1777
|
key: new v("DraggableBlocksPlugin"),
|
|
1771
|
-
view: () => new
|
|
1778
|
+
view: () => new zt({
|
|
1772
1779
|
editor: o.editor,
|
|
1773
1780
|
blockMenuFactory: o.blockSideMenuFactory,
|
|
1774
1781
|
horizontalPosAnchoredAtRoot: !0
|
|
1775
1782
|
})
|
|
1776
|
-
}),
|
|
1783
|
+
}), Gt = C.create({
|
|
1777
1784
|
name: "DraggableBlocksExtension",
|
|
1778
1785
|
priority: 1e3,
|
|
1779
1786
|
// Need to be high, in order to hide menu when typing slash
|
|
@@ -1783,14 +1790,14 @@ const zt = (o) => new B({
|
|
|
1783
1790
|
"UI Element factory not defined for DraggableBlocksExtension"
|
|
1784
1791
|
);
|
|
1785
1792
|
return [
|
|
1786
|
-
|
|
1793
|
+
Ut({
|
|
1787
1794
|
editor: this.editor,
|
|
1788
1795
|
blockSideMenuFactory: this.options.blockSideMenuFactory
|
|
1789
1796
|
})
|
|
1790
1797
|
];
|
|
1791
1798
|
}
|
|
1792
1799
|
});
|
|
1793
|
-
class
|
|
1800
|
+
class $t {
|
|
1794
1801
|
constructor({
|
|
1795
1802
|
editor: e,
|
|
1796
1803
|
formattingToolbarFactory: t,
|
|
@@ -1804,8 +1811,8 @@ class qt {
|
|
|
1804
1811
|
h(this, "preventShow", !1);
|
|
1805
1812
|
h(this, "toolbarIsOpen", !1);
|
|
1806
1813
|
h(this, "shouldShow", ({ view: e, state: t, from: n, to: r }) => {
|
|
1807
|
-
const { doc: i, selection:
|
|
1808
|
-
return !(!e.hasFocus() || s ||
|
|
1814
|
+
const { doc: i, selection: a } = t, { empty: s } = a, d = !i.textBetween(n, r).length && Ee(t.selection);
|
|
1815
|
+
return !(!e.hasFocus() || s || d);
|
|
1809
1816
|
});
|
|
1810
1817
|
h(this, "viewMousedownHandler", () => {
|
|
1811
1818
|
this.preventShow = !0;
|
|
@@ -1833,10 +1840,10 @@ class qt {
|
|
|
1833
1840
|
}
|
|
1834
1841
|
update(e, t) {
|
|
1835
1842
|
var f;
|
|
1836
|
-
const { state: n, composing: r } = e, { doc: i, selection:
|
|
1843
|
+
const { state: n, composing: r } = e, { doc: i, selection: a } = n, s = t && t.doc.eq(i) && t.selection.eq(a);
|
|
1837
1844
|
if (r || s)
|
|
1838
1845
|
return;
|
|
1839
|
-
const { ranges:
|
|
1846
|
+
const { ranges: d } = a, l = Math.min(...d.map((p) => p.$from.pos)), c = Math.max(...d.map((p) => p.$to.pos)), u = (f = this.shouldShow) == null ? void 0 : f.call(this, {
|
|
1840
1847
|
editor: this.editor,
|
|
1841
1848
|
view: e,
|
|
1842
1849
|
state: n,
|
|
@@ -1867,11 +1874,11 @@ class qt {
|
|
|
1867
1874
|
this.view.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.view.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.editor.off("focus", this.focusHandler), this.editor.off("blur", this.blurHandler);
|
|
1868
1875
|
}
|
|
1869
1876
|
getSelectionBoundingBox() {
|
|
1870
|
-
const { state: e } = this.editor.view, { selection: t } = e, { ranges: n } = t, r = Math.min(...n.map((
|
|
1877
|
+
const { state: e } = this.editor.view, { selection: t } = e, { ranges: n } = t, r = Math.min(...n.map((a) => a.$from.pos)), i = Math.max(...n.map((a) => a.$to.pos));
|
|
1871
1878
|
if (Ie(t)) {
|
|
1872
|
-
const
|
|
1873
|
-
if (
|
|
1874
|
-
return
|
|
1879
|
+
const a = this.editor.view.nodeDOM(r);
|
|
1880
|
+
if (a)
|
|
1881
|
+
return a.getBoundingClientRect();
|
|
1875
1882
|
}
|
|
1876
1883
|
return re(this.editor.view, r, i);
|
|
1877
1884
|
}
|
|
@@ -1953,10 +1960,10 @@ class qt {
|
|
|
1953
1960
|
};
|
|
1954
1961
|
}
|
|
1955
1962
|
}
|
|
1956
|
-
const
|
|
1963
|
+
const qt = (o) => new B({
|
|
1957
1964
|
key: new v("FormattingToolbarPlugin"),
|
|
1958
|
-
view: (e) => new
|
|
1959
|
-
}),
|
|
1965
|
+
view: (e) => new $t({ view: e, ...o })
|
|
1966
|
+
}), Yt = C.create({
|
|
1960
1967
|
name: "FormattingToolbarExtension",
|
|
1961
1968
|
addProseMirrorPlugins() {
|
|
1962
1969
|
if (!this.options.formattingToolbarFactory)
|
|
@@ -1964,15 +1971,15 @@ const Gt = (o) => new B({
|
|
|
1964
1971
|
"UI Element factory not defined for FormattingToolbarExtension"
|
|
1965
1972
|
);
|
|
1966
1973
|
return [
|
|
1967
|
-
|
|
1974
|
+
qt({
|
|
1968
1975
|
editor: this.editor,
|
|
1969
1976
|
formattingToolbarFactory: this.options.formattingToolbarFactory,
|
|
1970
1977
|
pluginKey: new v("FormattingToolbarPlugin")
|
|
1971
1978
|
})
|
|
1972
1979
|
];
|
|
1973
1980
|
}
|
|
1974
|
-
}),
|
|
1975
|
-
class
|
|
1981
|
+
}), Wt = new v("HyperlinkToolbarPlugin");
|
|
1982
|
+
class jt {
|
|
1976
1983
|
constructor({ editor: e, hyperlinkToolbarFactory: t }) {
|
|
1977
1984
|
h(this, "editor");
|
|
1978
1985
|
h(this, "hyperlinkToolbar");
|
|
@@ -1991,15 +1998,15 @@ class Yt {
|
|
|
1991
1998
|
}, 250);
|
|
1992
1999
|
}, this.stopMenuUpdateTimer = () => (this.menuUpdateTimer && (clearTimeout(this.menuUpdateTimer), this.menuUpdateTimer = void 0), !1), e.view.dom.addEventListener("mouseover", (n) => {
|
|
1993
2000
|
if (this.mouseHoveredHyperlinkMark = void 0, this.mouseHoveredHyperlinkMarkRange = void 0, this.stopMenuUpdateTimer(), n.target instanceof HTMLAnchorElement && n.target.nodeName === "A") {
|
|
1994
|
-
const r = n.target, i = e.view.posAtDOM(r, 0) + 1,
|
|
2001
|
+
const r = n.target, i = e.view.posAtDOM(r, 0) + 1, a = e.state.doc.resolve(
|
|
1995
2002
|
i
|
|
1996
|
-
), s =
|
|
1997
|
-
for (const
|
|
1998
|
-
if (
|
|
1999
|
-
this.mouseHoveredHyperlinkMark =
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
+
), s = a.marks();
|
|
2004
|
+
for (const d of s)
|
|
2005
|
+
if (d.type.name === e.schema.mark("link").type.name) {
|
|
2006
|
+
this.mouseHoveredHyperlinkMark = d, this.mouseHoveredHyperlinkMarkRange = X(
|
|
2007
|
+
a,
|
|
2008
|
+
d.type,
|
|
2009
|
+
d.attrs
|
|
2003
2010
|
) || void 0;
|
|
2004
2011
|
break;
|
|
2005
2012
|
}
|
|
@@ -2013,8 +2020,8 @@ class Yt {
|
|
|
2013
2020
|
return;
|
|
2014
2021
|
const e = this.hyperlinkMark;
|
|
2015
2022
|
if (this.hyperlinkMark = void 0, this.hyperlinkMarkRange = void 0, this.keyboardHoveredHyperlinkMark = void 0, this.keyboardHoveredHyperlinkMarkRange = void 0, this.editor.state.selection.empty) {
|
|
2016
|
-
const
|
|
2017
|
-
for (const s of
|
|
2023
|
+
const a = this.editor.state.selection.$from.marks();
|
|
2024
|
+
for (const s of a)
|
|
2018
2025
|
if (s.type.name === this.editor.schema.mark("link").type.name) {
|
|
2019
2026
|
this.keyboardHoveredHyperlinkMark = s, this.keyboardHoveredHyperlinkMarkRange = X(
|
|
2020
2027
|
this.editor.state.selection.$from,
|
|
@@ -2089,13 +2096,13 @@ class Yt {
|
|
|
2089
2096
|
};
|
|
2090
2097
|
}
|
|
2091
2098
|
}
|
|
2092
|
-
const
|
|
2093
|
-
key:
|
|
2094
|
-
view: () => new
|
|
2099
|
+
const Vt = (o, e) => new B({
|
|
2100
|
+
key: Wt,
|
|
2101
|
+
view: () => new jt({
|
|
2095
2102
|
editor: o,
|
|
2096
2103
|
hyperlinkToolbarFactory: e.hyperlinkToolbarFactory
|
|
2097
2104
|
})
|
|
2098
|
-
}),
|
|
2105
|
+
}), Kt = de.extend({
|
|
2099
2106
|
priority: 500,
|
|
2100
2107
|
addProseMirrorPlugins() {
|
|
2101
2108
|
var o;
|
|
@@ -2103,12 +2110,12 @@ const Wt = (o, e) => new B({
|
|
|
2103
2110
|
throw new Error("UI Element factory not defined for HyperlinkMark");
|
|
2104
2111
|
return [
|
|
2105
2112
|
...((o = this.parent) == null ? void 0 : o.call(this)) || [],
|
|
2106
|
-
|
|
2113
|
+
Vt(this.editor, {
|
|
2107
2114
|
hyperlinkToolbarFactory: this.options.hyperlinkToolbarFactory
|
|
2108
2115
|
})
|
|
2109
2116
|
];
|
|
2110
2117
|
}
|
|
2111
|
-
}),
|
|
2118
|
+
}), Jt = new v("blocknote-placeholder"), Xt = C.create({
|
|
2112
2119
|
name: "placeholder",
|
|
2113
2120
|
addOptions() {
|
|
2114
2121
|
return {
|
|
@@ -2125,35 +2132,35 @@ const Wt = (o, e) => new B({
|
|
|
2125
2132
|
addProseMirrorPlugins() {
|
|
2126
2133
|
return [
|
|
2127
2134
|
new B({
|
|
2128
|
-
key:
|
|
2135
|
+
key: Jt,
|
|
2129
2136
|
props: {
|
|
2130
2137
|
decorations: (o) => {
|
|
2131
|
-
const { doc: e, selection: t } = o, n = K.getState(o), r = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: i } = t,
|
|
2138
|
+
const { doc: e, selection: t } = o, n = K.getState(o), r = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: i } = t, a = [];
|
|
2132
2139
|
if (r)
|
|
2133
|
-
return e.descendants((s,
|
|
2134
|
-
const l = i >=
|
|
2140
|
+
return e.descendants((s, d) => {
|
|
2141
|
+
const l = i >= d && i <= d + s.nodeSize, c = !s.isLeaf && !s.childCount;
|
|
2135
2142
|
if ((l || !this.options.showOnlyCurrent) && c) {
|
|
2136
2143
|
const u = [this.options.emptyNodeClass];
|
|
2137
2144
|
this.editor.isEmpty && u.push(this.options.emptyEditorClass), l && u.push(this.options.hasAnchorClass), (n == null ? void 0 : n.triggerCharacter) === "" && (n != null && n.active) && u.push(this.options.isFilterClass);
|
|
2138
|
-
const f =
|
|
2145
|
+
const f = D.node(d, d + s.nodeSize, {
|
|
2139
2146
|
class: u.join(" ")
|
|
2140
2147
|
});
|
|
2141
|
-
|
|
2148
|
+
a.push(f);
|
|
2142
2149
|
}
|
|
2143
2150
|
return this.options.includeChildren;
|
|
2144
|
-
}),
|
|
2151
|
+
}), F.create(e, a);
|
|
2145
2152
|
}
|
|
2146
2153
|
}
|
|
2147
2154
|
})
|
|
2148
2155
|
];
|
|
2149
2156
|
}
|
|
2150
2157
|
});
|
|
2151
|
-
class
|
|
2158
|
+
class Qt {
|
|
2152
2159
|
constructor(e, t) {
|
|
2153
2160
|
this.name = e, this.match = t;
|
|
2154
2161
|
}
|
|
2155
2162
|
}
|
|
2156
|
-
class I extends
|
|
2163
|
+
class I extends Qt {
|
|
2157
2164
|
/**
|
|
2158
2165
|
* Constructs a new slash-command.
|
|
2159
2166
|
*
|
|
@@ -2171,7 +2178,7 @@ function S(o, e) {
|
|
|
2171
2178
|
const t = o.getTextCursorPosition().block;
|
|
2172
2179
|
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));
|
|
2173
2180
|
}
|
|
2174
|
-
const
|
|
2181
|
+
const Zt = [
|
|
2175
2182
|
// Command for creating a level 1 heading
|
|
2176
2183
|
new I(
|
|
2177
2184
|
"Heading",
|
|
@@ -2314,7 +2321,7 @@ const Qt = [
|
|
|
2314
2321
|
// TableIcon,
|
|
2315
2322
|
// "Used to create a simple table"
|
|
2316
2323
|
// ),
|
|
2317
|
-
],
|
|
2324
|
+
], eo = C.create({
|
|
2318
2325
|
name: "textAlignment",
|
|
2319
2326
|
addGlobalAttributes() {
|
|
2320
2327
|
return [
|
|
@@ -2352,7 +2359,7 @@ const Qt = [
|
|
|
2352
2359
|
}
|
|
2353
2360
|
};
|
|
2354
2361
|
}
|
|
2355
|
-
}),
|
|
2362
|
+
}), to = C.create({
|
|
2356
2363
|
name: "blockTextColor",
|
|
2357
2364
|
addGlobalAttributes() {
|
|
2358
2365
|
return [
|
|
@@ -2378,7 +2385,7 @@ const Qt = [
|
|
|
2378
2385
|
}
|
|
2379
2386
|
};
|
|
2380
2387
|
}
|
|
2381
|
-
}),
|
|
2388
|
+
}), oo = ne.create({
|
|
2382
2389
|
name: "textColor",
|
|
2383
2390
|
addAttributes() {
|
|
2384
2391
|
return {
|
|
@@ -2407,7 +2414,7 @@ const Qt = [
|
|
|
2407
2414
|
setTextColor: (o) => ({ commands: e }) => o !== "default" ? e.setMark(this.name, { color: o }) : e.unsetMark(this.name)
|
|
2408
2415
|
};
|
|
2409
2416
|
}
|
|
2410
|
-
}),
|
|
2417
|
+
}), no = C.create({
|
|
2411
2418
|
name: "trailingNode",
|
|
2412
2419
|
addProseMirrorPlugins() {
|
|
2413
2420
|
const o = new v(this.name);
|
|
@@ -2415,10 +2422,10 @@ const Qt = [
|
|
|
2415
2422
|
new B({
|
|
2416
2423
|
key: o,
|
|
2417
2424
|
appendTransaction: (e, t, n) => {
|
|
2418
|
-
const { doc: r, tr: i, schema:
|
|
2425
|
+
const { doc: r, tr: i, schema: a } = n, s = o.getState(n), d = r.content.size - 2, l = a.nodes.blockContainer, c = a.nodes.paragraph;
|
|
2419
2426
|
if (s)
|
|
2420
2427
|
return i.insert(
|
|
2421
|
-
|
|
2428
|
+
d,
|
|
2422
2429
|
l.create(void 0, c.create())
|
|
2423
2430
|
);
|
|
2424
2431
|
},
|
|
@@ -2439,7 +2446,7 @@ const Qt = [
|
|
|
2439
2446
|
})
|
|
2440
2447
|
];
|
|
2441
2448
|
}
|
|
2442
|
-
}),
|
|
2449
|
+
}), ro = (o) => {
|
|
2443
2450
|
const e = [
|
|
2444
2451
|
N.ClipboardTextSerializer,
|
|
2445
2452
|
N.Commands,
|
|
@@ -2449,96 +2456,108 @@ const Qt = [
|
|
|
2449
2456
|
// DevTools,
|
|
2450
2457
|
Ue,
|
|
2451
2458
|
// DropCursor,
|
|
2452
|
-
|
|
2459
|
+
Xt.configure({
|
|
2453
2460
|
emptyNodeClass: b.isEmpty,
|
|
2454
2461
|
hasAnchorClass: b.hasAnchor,
|
|
2455
2462
|
isFilterClass: b.isFilter,
|
|
2456
2463
|
includeChildren: !0,
|
|
2457
2464
|
showOnlyCurrent: !1
|
|
2458
2465
|
}),
|
|
2459
|
-
|
|
2466
|
+
j.configure({
|
|
2460
2467
|
types: ["blockContainer"]
|
|
2461
2468
|
}),
|
|
2462
|
-
|
|
2469
|
+
Ge,
|
|
2463
2470
|
// Comments,
|
|
2464
2471
|
// basics:
|
|
2465
|
-
|
|
2472
|
+
We,
|
|
2466
2473
|
// marks:
|
|
2467
2474
|
Fe,
|
|
2468
2475
|
Re,
|
|
2469
|
-
|
|
2476
|
+
qe,
|
|
2477
|
+
Ye,
|
|
2470
2478
|
je,
|
|
2471
|
-
|
|
2479
|
+
oo,
|
|
2472
2480
|
to,
|
|
2473
|
-
eo,
|
|
2474
2481
|
dt,
|
|
2475
2482
|
at,
|
|
2476
|
-
|
|
2483
|
+
eo,
|
|
2477
2484
|
// custom blocks:
|
|
2478
2485
|
...Et,
|
|
2479
2486
|
ze.configure({ width: 5, color: "#ddeeff" }),
|
|
2480
|
-
|
|
2487
|
+
$e,
|
|
2481
2488
|
// This needs to be at the bottom of this list, because Key events (such as enter, when selecting a /command),
|
|
2482
2489
|
// should be handled before Enter handlers in other components like splitListItem
|
|
2483
|
-
|
|
2490
|
+
no
|
|
2484
2491
|
];
|
|
2485
2492
|
return o.uiFactories.blockSideMenuFactory && e.push(
|
|
2486
|
-
|
|
2493
|
+
Gt.configure({
|
|
2487
2494
|
blockSideMenuFactory: o.uiFactories.blockSideMenuFactory
|
|
2488
2495
|
})
|
|
2489
2496
|
), o.uiFactories.formattingToolbarFactory && e.push(
|
|
2490
|
-
|
|
2497
|
+
Yt.configure({
|
|
2491
2498
|
formattingToolbarFactory: o.uiFactories.formattingToolbarFactory
|
|
2492
2499
|
})
|
|
2493
2500
|
), o.uiFactories.hyperlinkToolbarFactory ? e.push(
|
|
2494
|
-
|
|
2501
|
+
Kt.configure({
|
|
2495
2502
|
hyperlinkToolbarFactory: o.uiFactories.hyperlinkToolbarFactory
|
|
2496
2503
|
})
|
|
2497
2504
|
) : e.push(de), o.uiFactories.slashMenuFactory && e.push(
|
|
2498
|
-
|
|
2505
|
+
Ot.configure({
|
|
2499
2506
|
editor: o.editor,
|
|
2500
2507
|
commands: o.slashCommands,
|
|
2501
2508
|
slashMenuFactory: o.uiFactories.slashMenuFactory
|
|
2502
2509
|
})
|
|
2503
2510
|
), e;
|
|
2504
|
-
},
|
|
2511
|
+
}, io = {
|
|
2505
2512
|
enableInputRules: !0,
|
|
2506
2513
|
enablePasteRules: !0,
|
|
2507
2514
|
enableCoreExtensions: !1
|
|
2508
2515
|
};
|
|
2509
|
-
class
|
|
2516
|
+
class Ho {
|
|
2510
2517
|
constructor(e = {}) {
|
|
2511
2518
|
h(this, "_tiptapEditor");
|
|
2512
2519
|
h(this, "blockCache", /* @__PURE__ */ new WeakMap());
|
|
2513
|
-
var i,
|
|
2514
|
-
|
|
2520
|
+
var i, a, s;
|
|
2521
|
+
e = {
|
|
2522
|
+
defaultStyles: !0,
|
|
2523
|
+
...e
|
|
2524
|
+
};
|
|
2525
|
+
const t = ro({
|
|
2515
2526
|
editor: this,
|
|
2516
2527
|
uiFactories: e.uiFactories || {},
|
|
2517
|
-
slashCommands: e.slashCommands ||
|
|
2528
|
+
slashCommands: e.slashCommands || Zt
|
|
2518
2529
|
});
|
|
2519
|
-
let n = e.disableHistoryExtension ? t.filter((
|
|
2530
|
+
let n = e.disableHistoryExtension ? t.filter((d) => d.name !== "history") : t;
|
|
2520
2531
|
const r = {
|
|
2521
|
-
|
|
2532
|
+
// TODO: This approach to setting initial content is "cleaner" but requires the PM editor schema, which is only
|
|
2533
|
+
// created after initializing the TipTap editor. Not sure it's feasible.
|
|
2534
|
+
// content:
|
|
2535
|
+
// options.initialContent &&
|
|
2536
|
+
// options.initialContent.map((block) =>
|
|
2537
|
+
// blockToNode(block, this._tiptapEditor.schema).toJSON()
|
|
2538
|
+
// ),
|
|
2539
|
+
...io,
|
|
2522
2540
|
...e._tiptapOptions,
|
|
2523
2541
|
onCreate: () => {
|
|
2524
|
-
var
|
|
2525
|
-
(
|
|
2542
|
+
var d;
|
|
2543
|
+
(d = e.onEditorReady) == null || d.call(e, this), e.initialContent && this.replaceBlocks(this.topLevelBlocks, e.initialContent);
|
|
2526
2544
|
},
|
|
2527
2545
|
onUpdate: () => {
|
|
2528
|
-
var
|
|
2529
|
-
(
|
|
2546
|
+
var d;
|
|
2547
|
+
(d = e.onEditorContentChange) == null || d.call(e, this);
|
|
2530
2548
|
},
|
|
2531
2549
|
onSelectionUpdate: () => {
|
|
2532
|
-
var
|
|
2533
|
-
(
|
|
2550
|
+
var d;
|
|
2551
|
+
(d = e.onTextCursorPositionChange) == null || d.call(e, this);
|
|
2534
2552
|
},
|
|
2535
|
-
extensions: e.enableBlockNoteExtensions === !1 ? (i = e._tiptapOptions) == null ? void 0 : i.extensions : [...((
|
|
2553
|
+
extensions: e.enableBlockNoteExtensions === !1 ? (i = e._tiptapOptions) == null ? void 0 : i.extensions : [...((a = e._tiptapOptions) == null ? void 0 : a.extensions) || [], ...n],
|
|
2536
2554
|
editorProps: {
|
|
2537
2555
|
attributes: {
|
|
2538
2556
|
...e.editorDOMAttributes || {},
|
|
2539
2557
|
class: [
|
|
2540
|
-
|
|
2541
|
-
|
|
2558
|
+
_.bnEditor,
|
|
2559
|
+
_.bnRoot,
|
|
2560
|
+
e.defaultStyles ? _.defaultStyles : "",
|
|
2542
2561
|
((s = e.editorDOMAttributes) == null ? void 0 : s.class) || ""
|
|
2543
2562
|
].join(" ")
|
|
2544
2563
|
}
|
|
@@ -2555,7 +2574,7 @@ class Lo {
|
|
|
2555
2574
|
*/
|
|
2556
2575
|
get topLevelBlocks() {
|
|
2557
2576
|
const e = [];
|
|
2558
|
-
return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(
|
|
2577
|
+
return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(w(t, this.blockCache)), !1)), e;
|
|
2559
2578
|
}
|
|
2560
2579
|
/**
|
|
2561
2580
|
* Gets a snapshot of an existing block from the editor.
|
|
@@ -2565,7 +2584,7 @@ class Lo {
|
|
|
2565
2584
|
getBlock(e) {
|
|
2566
2585
|
const t = typeof e == "string" ? e : e.id;
|
|
2567
2586
|
let n;
|
|
2568
|
-
return this._tiptapEditor.state.doc.firstChild.descendants((r) => typeof n < "u" ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== t ? !0 : (n =
|
|
2587
|
+
return this._tiptapEditor.state.doc.firstChild.descendants((r) => typeof n < "u" ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== t ? !0 : (n = w(r, this.blockCache), !1)), n;
|
|
2569
2588
|
}
|
|
2570
2589
|
/**
|
|
2571
2590
|
* Traverses all blocks in the editor depth-first, and executes a callback for each.
|
|
@@ -2573,15 +2592,19 @@ class Lo {
|
|
|
2573
2592
|
* @param reverse Whether the blocks should be traversed in reverse order.
|
|
2574
2593
|
*/
|
|
2575
2594
|
forEachBlock(e, t = !1) {
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2595
|
+
const n = this.topLevelBlocks.slice();
|
|
2596
|
+
t && n.reverse();
|
|
2597
|
+
function r(i) {
|
|
2598
|
+
for (const a of i) {
|
|
2599
|
+
if (e(a) === !1)
|
|
2600
|
+
return !1;
|
|
2601
|
+
const s = t ? a.children.slice().reverse() : a.children;
|
|
2602
|
+
if (r(s) === !1)
|
|
2603
|
+
return !1;
|
|
2604
|
+
}
|
|
2605
|
+
return !0;
|
|
2583
2606
|
}
|
|
2584
|
-
n
|
|
2607
|
+
r(n);
|
|
2585
2608
|
}
|
|
2586
2609
|
/**
|
|
2587
2610
|
* Gets a snapshot of the current text cursor position.
|
|
@@ -2591,14 +2614,14 @@ class Lo {
|
|
|
2591
2614
|
const { node: e, depth: t, startPos: n, endPos: r } = k(
|
|
2592
2615
|
this._tiptapEditor.state.doc,
|
|
2593
2616
|
this._tiptapEditor.state.selection.from
|
|
2594
|
-
), i = this._tiptapEditor.state.doc.resolve(r).index(t - 1),
|
|
2617
|
+
), i = this._tiptapEditor.state.doc.resolve(r).index(t - 1), a = this._tiptapEditor.state.doc.resolve(r + 1).node().childCount;
|
|
2595
2618
|
let s;
|
|
2596
2619
|
i > 0 && (s = this._tiptapEditor.state.doc.resolve(n - 2).node());
|
|
2597
|
-
let
|
|
2598
|
-
return i <
|
|
2599
|
-
block:
|
|
2600
|
-
prevBlock: s === void 0 ? void 0 :
|
|
2601
|
-
nextBlock:
|
|
2620
|
+
let d;
|
|
2621
|
+
return i < a - 1 && (d = this._tiptapEditor.state.doc.resolve(r + 2).node()), {
|
|
2622
|
+
block: w(e, this.blockCache),
|
|
2623
|
+
prevBlock: s === void 0 ? void 0 : w(s, this.blockCache),
|
|
2624
|
+
nextBlock: d === void 0 ? void 0 : w(d, this.blockCache)
|
|
2602
2625
|
};
|
|
2603
2626
|
}
|
|
2604
2627
|
/**
|
|
@@ -2608,12 +2631,12 @@ class Lo {
|
|
|
2608
2631
|
* @param placement Whether the text cursor should be placed at the start or end of the block.
|
|
2609
2632
|
*/
|
|
2610
2633
|
setTextCursorPosition(e, t = "start") {
|
|
2611
|
-
const n = typeof e == "string" ? e : e.id, { posBeforeNode: r } = V(n, this._tiptapEditor.state.doc), { startPos: i, contentNode:
|
|
2634
|
+
const n = typeof e == "string" ? e : e.id, { posBeforeNode: r } = V(n, this._tiptapEditor.state.doc), { startPos: i, contentNode: a } = k(
|
|
2612
2635
|
this._tiptapEditor.state.doc,
|
|
2613
2636
|
r + 2
|
|
2614
2637
|
);
|
|
2615
2638
|
t === "start" ? this._tiptapEditor.commands.setTextSelection(i + 1) : this._tiptapEditor.commands.setTextSelection(
|
|
2616
|
-
i +
|
|
2639
|
+
i + a.nodeSize - 1
|
|
2617
2640
|
);
|
|
2618
2641
|
}
|
|
2619
2642
|
/**
|
|
@@ -2695,10 +2718,10 @@ class Lo {
|
|
|
2695
2718
|
}
|
|
2696
2719
|
export {
|
|
2697
2720
|
I as BaseSlashMenuItem,
|
|
2698
|
-
|
|
2721
|
+
Ho as BlockNoteEditor,
|
|
2699
2722
|
ee as blockProps,
|
|
2700
|
-
|
|
2701
|
-
|
|
2723
|
+
Zt as defaultSlashMenuItems,
|
|
2724
|
+
ro as getBlockNoteExtensions,
|
|
2702
2725
|
O as globalProps
|
|
2703
2726
|
};
|
|
2704
2727
|
//# sourceMappingURL=blocknote.js.map
|