@blocknote/core 0.8.1 → 0.8.2
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 +199 -174
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +3 -3
- package/dist/blocknote.umd.cjs.map +1 -1
- package/package.json +3 -3
- package/src/BlockNoteEditor.ts +14 -0
- package/src/extensions/Blocks/nodes/BlockContainer.ts +12 -3
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +2 -2
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +22 -29
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +4 -6
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +20 -19
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +2 -2
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +22 -13
- package/src/shared/EditorElement.ts +3 -3
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +23 -17
- package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +2 -2
- package/types/src/BlockNoteEditor.d.ts +1 -0
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +1 -1
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +1 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -3
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +2 -3
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +1 -1
- package/types/src/shared/EditorElement.d.ts +3 -3
- package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +1 -1
package/dist/blocknote.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
var Nt = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var h = (o, e, t) => (
|
|
4
|
-
import { Node as R, InputRule as
|
|
2
|
+
var Lt = (o, e, t) => e in o ? Nt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var h = (o, e, t) => (Lt(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { Node as R, InputRule as V, mergeAttributes as x, Extension as v, findChildren as j, combineTransactionSteps as Ht, getChangedRanges as Ot, findChildrenInRange as Dt, Mark as st, findParentNode as Ft, isTextSelection as Rt, isNodeSelection as zt, posToDOMRect as at, getMarkRange as Q, extensions as N, Editor as Ut } from "@tiptap/core";
|
|
5
5
|
import { PluginKey as E, Plugin as C, TextSelection as tt, Selection as G, NodeSelection as $t } from "prosemirror-state";
|
|
6
|
-
import { Slice as
|
|
6
|
+
import { Slice as T, Fragment as P, DOMSerializer as q, DOMParser as Gt } from "prosemirror-model";
|
|
7
7
|
import { v4 as jt } from "uuid";
|
|
8
8
|
import lt from "rehype-parse";
|
|
9
9
|
import qt from "rehype-remark";
|
|
10
10
|
import dt from "rehype-stringify";
|
|
11
11
|
import ct from "remark-gfm";
|
|
12
12
|
import Wt from "remark-parse";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { unified as
|
|
13
|
+
import Vt from "remark-rehype";
|
|
14
|
+
import Yt from "remark-stringify";
|
|
15
|
+
import { unified as Y } from "unified";
|
|
16
16
|
import { fromDom as et } from "hast-util-from-dom";
|
|
17
17
|
import { Bold as Kt } from "@tiptap/extension-bold";
|
|
18
18
|
import { Code as Jt } from "@tiptap/extension-code";
|
|
@@ -39,7 +39,7 @@ const ht = "_blockOuter_xgzwr_5", pt = "_block_xgzwr_5", ft = "_reactNodeViewRen
|
|
|
39
39
|
inlineContent: yt,
|
|
40
40
|
isFilter: bt,
|
|
41
41
|
hasAnchor: vt
|
|
42
|
-
},
|
|
42
|
+
}, Vo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
43
43
|
__proto__: null,
|
|
44
44
|
block: pt,
|
|
45
45
|
blockContent: mt,
|
|
@@ -91,7 +91,7 @@ function ce(o, e) {
|
|
|
91
91
|
dom: t
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function Yo(o) {
|
|
95
95
|
return {
|
|
96
96
|
node: H({
|
|
97
97
|
name: o.type,
|
|
@@ -161,7 +161,7 @@ const ue = H({
|
|
|
161
161
|
},
|
|
162
162
|
addInputRules() {
|
|
163
163
|
return [
|
|
164
|
-
...["1", "2", "3"].map((o) => new
|
|
164
|
+
...["1", "2", "3"].map((o) => new V({
|
|
165
165
|
find: new RegExp(`^(#{${parseInt(o)}})\\s$`),
|
|
166
166
|
handler: ({ state: e, chain: t, range: n }) => {
|
|
167
167
|
t().BNUpdateBlock(e.selection.from, {
|
|
@@ -196,7 +196,7 @@ const ue = H({
|
|
|
196
196
|
renderHTML({ node: o, HTMLAttributes: e }) {
|
|
197
197
|
return [
|
|
198
198
|
"div",
|
|
199
|
-
|
|
199
|
+
x(e, {
|
|
200
200
|
class: k.blockContent,
|
|
201
201
|
"data-content-type": this.name
|
|
202
202
|
}),
|
|
@@ -253,7 +253,7 @@ const Et = (o) => {
|
|
|
253
253
|
addInputRules() {
|
|
254
254
|
return [
|
|
255
255
|
// Creates an unordered list when starting with "-", "+", or "*".
|
|
256
|
-
new
|
|
256
|
+
new V({
|
|
257
257
|
find: new RegExp("^[-+*]\\s$"),
|
|
258
258
|
handler: ({ state: o, chain: e, range: t }) => {
|
|
259
259
|
e().BNUpdateBlock(o.selection.from, {
|
|
@@ -299,7 +299,7 @@ const Et = (o) => {
|
|
|
299
299
|
renderHTML({ HTMLAttributes: o }) {
|
|
300
300
|
return [
|
|
301
301
|
"div",
|
|
302
|
-
|
|
302
|
+
x(o, {
|
|
303
303
|
class: k.blockContent,
|
|
304
304
|
"data-content-type": this.name
|
|
305
305
|
}),
|
|
@@ -353,7 +353,7 @@ const Et = (o) => {
|
|
|
353
353
|
addInputRules() {
|
|
354
354
|
return [
|
|
355
355
|
// Creates an ordered list when starting with "1.".
|
|
356
|
-
new
|
|
356
|
+
new V({
|
|
357
357
|
find: new RegExp("^1\\.\\s$"),
|
|
358
358
|
handler: ({ state: o, chain: e, range: t }) => {
|
|
359
359
|
e().BNUpdateBlock(o.selection.from, {
|
|
@@ -404,7 +404,7 @@ const Et = (o) => {
|
|
|
404
404
|
renderHTML({ HTMLAttributes: o }) {
|
|
405
405
|
return [
|
|
406
406
|
"div",
|
|
407
|
-
|
|
407
|
+
x(o, {
|
|
408
408
|
class: k.blockContent,
|
|
409
409
|
"data-content-type": this.name
|
|
410
410
|
}),
|
|
@@ -428,14 +428,14 @@ const Et = (o) => {
|
|
|
428
428
|
renderHTML({ HTMLAttributes: o }) {
|
|
429
429
|
return [
|
|
430
430
|
"div",
|
|
431
|
-
|
|
431
|
+
x(o, {
|
|
432
432
|
class: k.blockContent,
|
|
433
433
|
"data-content-type": this.name
|
|
434
434
|
}),
|
|
435
435
|
["p", { class: k.inlineContent }, 0]
|
|
436
436
|
];
|
|
437
437
|
}
|
|
438
|
-
}),
|
|
438
|
+
}), L = {
|
|
439
439
|
backgroundColor: {
|
|
440
440
|
default: "transparent"
|
|
441
441
|
},
|
|
@@ -449,22 +449,22 @@ const Et = (o) => {
|
|
|
449
449
|
}
|
|
450
450
|
}, ke = {
|
|
451
451
|
paragraph: {
|
|
452
|
-
propSchema:
|
|
452
|
+
propSchema: L,
|
|
453
453
|
node: ge
|
|
454
454
|
},
|
|
455
455
|
heading: {
|
|
456
456
|
propSchema: {
|
|
457
|
-
...
|
|
457
|
+
...L,
|
|
458
458
|
level: { default: "1", values: ["1", "2", "3"] }
|
|
459
459
|
},
|
|
460
460
|
node: ue
|
|
461
461
|
},
|
|
462
462
|
bulletListItem: {
|
|
463
|
-
propSchema:
|
|
463
|
+
propSchema: L,
|
|
464
464
|
node: he
|
|
465
465
|
},
|
|
466
466
|
numberedListItem: {
|
|
467
|
-
propSchema:
|
|
467
|
+
propSchema: L,
|
|
468
468
|
node: me
|
|
469
469
|
}
|
|
470
470
|
};
|
|
@@ -544,21 +544,21 @@ const K = v.create({
|
|
|
544
544
|
const b = Dt(
|
|
545
545
|
r.doc,
|
|
546
546
|
m,
|
|
547
|
-
(
|
|
548
|
-
), y = b.map(({ node:
|
|
549
|
-
b.forEach(({ node:
|
|
547
|
+
(B) => l.includes(B.type.name)
|
|
548
|
+
), y = b.map(({ node: B }) => B.attrs[d]).filter((B) => B !== null), U = be(y);
|
|
549
|
+
b.forEach(({ node: B, pos: O }) => {
|
|
550
550
|
var $;
|
|
551
551
|
const Z = ($ = a.doc.nodeAt(O)) === null || $ === void 0 ? void 0 : $.attrs[d];
|
|
552
552
|
if (Z === null) {
|
|
553
553
|
a.setNodeMarkup(O, void 0, {
|
|
554
|
-
...
|
|
554
|
+
...B.attrs,
|
|
555
555
|
[d]: c()
|
|
556
556
|
});
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
|
-
const { deleted:
|
|
560
|
-
|
|
561
|
-
...
|
|
559
|
+
const { deleted: At } = p.invert().mapResult(O);
|
|
560
|
+
At && U.includes(Z) && a.setNodeMarkup(O, void 0, {
|
|
561
|
+
...B.attrs,
|
|
562
562
|
[d]: c()
|
|
563
563
|
});
|
|
564
564
|
});
|
|
@@ -615,9 +615,9 @@ const K = v.create({
|
|
|
615
615
|
l.marks
|
|
616
616
|
);
|
|
617
617
|
a.push(d);
|
|
618
|
-
}),
|
|
618
|
+
}), P.from(a);
|
|
619
619
|
};
|
|
620
|
-
return e = !1, new
|
|
620
|
+
return e = !1, new T(
|
|
621
621
|
i(t.content),
|
|
622
622
|
t.openStart,
|
|
623
623
|
t.openEnd
|
|
@@ -639,11 +639,11 @@ const Ct = /* @__PURE__ */ new Set([
|
|
|
639
639
|
"underline",
|
|
640
640
|
"strike",
|
|
641
641
|
"code"
|
|
642
|
-
]),
|
|
642
|
+
]), Bt = /* @__PURE__ */ new Set(["textColor", "backgroundColor"]);
|
|
643
643
|
function nt(o, e) {
|
|
644
644
|
const t = [];
|
|
645
645
|
for (const [n, r] of Object.entries(o.styles))
|
|
646
|
-
Ct.has(n) ? t.push(e.mark(n)) :
|
|
646
|
+
Ct.has(n) ? t.push(e.mark(n)) : Bt.has(n) && t.push(e.mark(n, { color: r }));
|
|
647
647
|
return o.text.split(/(\n)/g).filter((n) => n.length > 0).map((n) => n === `
|
|
648
648
|
` ? e.nodes.hardBreak.create() : e.text(n, t));
|
|
649
649
|
}
|
|
@@ -651,7 +651,7 @@ function Ee(o, e) {
|
|
|
651
651
|
const t = e.marks.link.create({
|
|
652
652
|
href: o.href
|
|
653
653
|
});
|
|
654
|
-
return
|
|
654
|
+
return wt(o.content, e).map((n) => {
|
|
655
655
|
if (n.type.name === "text")
|
|
656
656
|
return n.mark([...n.marks, t]);
|
|
657
657
|
if (n.type.name === "hardBreak")
|
|
@@ -659,7 +659,7 @@ function Ee(o, e) {
|
|
|
659
659
|
throw new Error("unexpected node type");
|
|
660
660
|
});
|
|
661
661
|
}
|
|
662
|
-
function
|
|
662
|
+
function wt(o, e) {
|
|
663
663
|
let t = [];
|
|
664
664
|
if (typeof o == "string")
|
|
665
665
|
return t.push(
|
|
@@ -669,13 +669,13 @@ function Bt(o, e) {
|
|
|
669
669
|
t.push(...nt(n, e));
|
|
670
670
|
return t;
|
|
671
671
|
}
|
|
672
|
-
function
|
|
672
|
+
function Mt(o, e) {
|
|
673
673
|
let t = [];
|
|
674
674
|
for (const n of o)
|
|
675
675
|
if (n.type === "link")
|
|
676
676
|
t.push(...Ee(n, e));
|
|
677
677
|
else if (n.type === "text")
|
|
678
|
-
t.push(...
|
|
678
|
+
t.push(...wt([n], e));
|
|
679
679
|
else
|
|
680
680
|
throw new ve(n);
|
|
681
681
|
return t;
|
|
@@ -694,7 +694,7 @@ function z(o, e) {
|
|
|
694
694
|
e.text(o.content)
|
|
695
695
|
);
|
|
696
696
|
else {
|
|
697
|
-
const a =
|
|
697
|
+
const a = Mt(o.content, e);
|
|
698
698
|
r = e.nodes[n].create(o.props, a);
|
|
699
699
|
}
|
|
700
700
|
const i = [];
|
|
@@ -732,7 +732,7 @@ function Ce(o) {
|
|
|
732
732
|
i = s;
|
|
733
733
|
else if (Ct.has(s.type.name))
|
|
734
734
|
r[s.type.name] = !0;
|
|
735
|
-
else if (
|
|
735
|
+
else if (Bt.has(s.type.name))
|
|
736
736
|
r[s.type.name] = s.attrs.color;
|
|
737
737
|
else
|
|
738
738
|
throw Error("Mark is of an unrecognized type: " + s.type.name);
|
|
@@ -787,7 +787,7 @@ function Ce(o) {
|
|
|
787
787
|
};
|
|
788
788
|
}), t && e.push(t), e;
|
|
789
789
|
}
|
|
790
|
-
function
|
|
790
|
+
function w(o, e, t) {
|
|
791
791
|
if (o.type.name !== "blockContainer")
|
|
792
792
|
throw Error(
|
|
793
793
|
"Node must be of type blockContainer, but is of type" + o.type.name + "."
|
|
@@ -809,12 +809,12 @@ function B(o, e, t) {
|
|
|
809
809
|
"Block is of an unrecognized type: " + r.contentType.name
|
|
810
810
|
);
|
|
811
811
|
const f = p.propSchema;
|
|
812
|
-
c in f ? s[c] = u : c !== "id" && !(c in
|
|
812
|
+
c in f ? s[c] = u : c !== "id" && !(c in L) && console.warn("Block has an unrecognized attribute: " + c);
|
|
813
813
|
}
|
|
814
814
|
const a = Ce(r.contentNode), l = [];
|
|
815
815
|
for (let c = 0; c < r.numChildBlocks; c++)
|
|
816
816
|
l.push(
|
|
817
|
-
|
|
817
|
+
w(r.node.lastChild.child(c), e, t)
|
|
818
818
|
);
|
|
819
819
|
const d = {
|
|
820
820
|
id: i,
|
|
@@ -834,7 +834,7 @@ function J(o, e) {
|
|
|
834
834
|
posBeforeNode: n
|
|
835
835
|
};
|
|
836
836
|
}
|
|
837
|
-
function
|
|
837
|
+
function Tt(o, e, t = "before", n) {
|
|
838
838
|
const r = typeof e == "string" ? e : e.id, i = [];
|
|
839
839
|
for (const d of o)
|
|
840
840
|
i.push(z(d, n.schema));
|
|
@@ -856,11 +856,11 @@ function wt(o, e, t = "before", n) {
|
|
|
856
856
|
}
|
|
857
857
|
n.view.dispatch(n.state.tr.insert(s, i));
|
|
858
858
|
}
|
|
859
|
-
function
|
|
859
|
+
function Be(o, e, t) {
|
|
860
860
|
const n = typeof o == "string" ? o : o.id, { posBeforeNode: r } = J(n, t.state.doc);
|
|
861
861
|
t.commands.BNUpdateBlock(r + 1, e);
|
|
862
862
|
}
|
|
863
|
-
function
|
|
863
|
+
function xt(o, e) {
|
|
864
864
|
const t = new Set(
|
|
865
865
|
o.map(
|
|
866
866
|
(r) => typeof r == "string" ? r : r.id
|
|
@@ -885,10 +885,10 @@ function St(o, e) {
|
|
|
885
885
|
);
|
|
886
886
|
}
|
|
887
887
|
}
|
|
888
|
-
function
|
|
889
|
-
|
|
888
|
+
function we(o, e, t) {
|
|
889
|
+
Tt(e, o[0], "before", t), xt(o, t);
|
|
890
890
|
}
|
|
891
|
-
function
|
|
891
|
+
function Me() {
|
|
892
892
|
const o = (e) => {
|
|
893
893
|
let t = e.children.length;
|
|
894
894
|
for (let n = 0; n < t; n++) {
|
|
@@ -904,7 +904,7 @@ function Te() {
|
|
|
904
904
|
};
|
|
905
905
|
return o;
|
|
906
906
|
}
|
|
907
|
-
function
|
|
907
|
+
function Te(o) {
|
|
908
908
|
const e = /* @__PURE__ */ new Set([
|
|
909
909
|
...o.orderedListItemBlockTypes,
|
|
910
910
|
...o.unorderedListItemBlockTypes
|
|
@@ -948,13 +948,13 @@ function we(o) {
|
|
|
948
948
|
};
|
|
949
949
|
return t;
|
|
950
950
|
}
|
|
951
|
-
async function
|
|
951
|
+
async function St(o, e) {
|
|
952
952
|
const t = document.createElement("div"), n = q.fromSchema(e);
|
|
953
953
|
for (const i of o) {
|
|
954
954
|
const s = z(i, e), a = n.serializeNode(s);
|
|
955
955
|
t.appendChild(a);
|
|
956
956
|
}
|
|
957
|
-
return (await
|
|
957
|
+
return (await Y().use(lt, { fragment: !0 }).use(Te, {
|
|
958
958
|
orderedListItemBlockTypes: /* @__PURE__ */ new Set(["numberedListItem"]),
|
|
959
959
|
unorderedListItemBlockTypes: /* @__PURE__ */ new Set(["bulletListItem"])
|
|
960
960
|
}).use(dt).process(t.innerHTML)).value;
|
|
@@ -964,21 +964,21 @@ async function It(o, e, t) {
|
|
|
964
964
|
n.innerHTML = o.trim();
|
|
965
965
|
const i = Gt.fromSchema(t).parse(n), s = [];
|
|
966
966
|
for (let a = 0; a < i.firstChild.childCount; a++)
|
|
967
|
-
s.push(
|
|
967
|
+
s.push(w(i.firstChild.child(a), e));
|
|
968
968
|
return s;
|
|
969
969
|
}
|
|
970
|
-
async function
|
|
971
|
-
return (await
|
|
970
|
+
async function xe(o, e) {
|
|
971
|
+
return (await Y().use(lt, { fragment: !0 }).use(Me).use(qt).use(ct).use(Yt).process(await St(o, e))).value;
|
|
972
972
|
}
|
|
973
|
-
async function
|
|
974
|
-
const n = await
|
|
973
|
+
async function Se(o, e, t) {
|
|
974
|
+
const n = await Y().use(Wt).use(ct).use(Vt).use(dt).process(o);
|
|
975
975
|
return It(n.value, e, t);
|
|
976
976
|
}
|
|
977
|
-
const Ie = "_bnEditor_4vj2p_3",
|
|
977
|
+
const Ie = "_bnEditor_4vj2p_3", Pe = "_bnRoot_4vj2p_20", _e = "_defaultStyles_4vj2p_35", Ae = "_dragPreview_4vj2p_68", _ = {
|
|
978
978
|
bnEditor: Ie,
|
|
979
|
-
bnRoot:
|
|
980
|
-
defaultStyles:
|
|
981
|
-
dragPreview:
|
|
979
|
+
bnRoot: Pe,
|
|
980
|
+
defaultStyles: _e,
|
|
981
|
+
dragPreview: Ae,
|
|
982
982
|
"collaboration-cursor__caret": "_collaboration-cursor__caret_4vj2p_74",
|
|
983
983
|
"collaboration-cursor__label": "_collaboration-cursor__label_4vj2p_85"
|
|
984
984
|
}, Ne = v.create({
|
|
@@ -1011,7 +1011,7 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1011
1011
|
}
|
|
1012
1012
|
};
|
|
1013
1013
|
}
|
|
1014
|
-
}),
|
|
1014
|
+
}), Le = st.create({
|
|
1015
1015
|
name: "backgroundColor",
|
|
1016
1016
|
addAttributes() {
|
|
1017
1017
|
return {
|
|
@@ -1163,13 +1163,13 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1163
1163
|
renderHTML({ HTMLAttributes: o }) {
|
|
1164
1164
|
return [
|
|
1165
1165
|
"div",
|
|
1166
|
-
|
|
1166
|
+
x(o, {
|
|
1167
1167
|
class: k.blockOuter,
|
|
1168
1168
|
"data-node-type": "block-outer"
|
|
1169
1169
|
}),
|
|
1170
1170
|
[
|
|
1171
1171
|
"div",
|
|
1172
|
-
|
|
1172
|
+
x(o, {
|
|
1173
1173
|
// TODO: maybe remove html attributes from inner block
|
|
1174
1174
|
class: k.block,
|
|
1175
1175
|
"data-node-type": this.name
|
|
@@ -1207,7 +1207,7 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1207
1207
|
a.childCount === 2 ? t.tr.replace(
|
|
1208
1208
|
i + l.nodeSize + 1,
|
|
1209
1209
|
s - 1,
|
|
1210
|
-
new
|
|
1210
|
+
new T(P.from(d), 0, 0)
|
|
1211
1211
|
) : t.tr.insert(
|
|
1212
1212
|
i + l.nodeSize,
|
|
1213
1213
|
t.schema.nodes.blockGroup.create({}, d)
|
|
@@ -1215,10 +1215,10 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1215
1215
|
}
|
|
1216
1216
|
if (e.content !== void 0) {
|
|
1217
1217
|
let d = [];
|
|
1218
|
-
typeof e.content == "string" ? d.push(t.schema.text(e.content)) : d =
|
|
1218
|
+
typeof e.content == "string" ? d.push(t.schema.text(e.content)) : d = Mt(e.content, t.schema), t.tr.replace(
|
|
1219
1219
|
i + 1,
|
|
1220
1220
|
i + l.nodeSize - 1,
|
|
1221
|
-
new
|
|
1221
|
+
new T(P.from(d), 0, 0)
|
|
1222
1222
|
);
|
|
1223
1223
|
}
|
|
1224
1224
|
t.tr.setNodeMarkup(
|
|
@@ -1270,7 +1270,13 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1270
1270
|
for (; p.numChildBlocks > 0; )
|
|
1271
1271
|
if (u--, p = g(e.doc, u), p === void 0)
|
|
1272
1272
|
return !1;
|
|
1273
|
-
return t && (
|
|
1273
|
+
return t && (t(
|
|
1274
|
+
e.tr.deleteRange(l, l + a.nodeSize).replace(
|
|
1275
|
+
u - 1,
|
|
1276
|
+
l,
|
|
1277
|
+
new T(a.content, 0, 0)
|
|
1278
|
+
).scrollIntoView()
|
|
1279
|
+
), e.tr.setSelection(
|
|
1274
1280
|
new tt(e.doc.resolve(u - 1))
|
|
1275
1281
|
)), !0;
|
|
1276
1282
|
},
|
|
@@ -1284,8 +1290,8 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1284
1290
|
return n && (t.tr.insert(f, p), t.tr.replace(
|
|
1285
1291
|
m,
|
|
1286
1292
|
m + 1,
|
|
1287
|
-
u.content.size > 0 ? new
|
|
1288
|
-
|
|
1293
|
+
u.content.size > 0 ? new T(
|
|
1294
|
+
P.from(u),
|
|
1289
1295
|
d + 2,
|
|
1290
1296
|
d + 2
|
|
1291
1297
|
) : void 0
|
|
@@ -1299,8 +1305,8 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1299
1305
|
), t.tr.replace(
|
|
1300
1306
|
a + 1,
|
|
1301
1307
|
l - 1,
|
|
1302
|
-
c.content.size > 0 ? new
|
|
1303
|
-
|
|
1308
|
+
c.content.size > 0 ? new T(
|
|
1309
|
+
P.from(c),
|
|
1304
1310
|
d + 2,
|
|
1305
1311
|
d + 2
|
|
1306
1312
|
) : void 0
|
|
@@ -1429,7 +1435,7 @@ const Ie = "_bnEditor_4vj2p_3", _e = "_bnRoot_4vj2p_20", Pe = "_defaultStyles_4v
|
|
|
1429
1435
|
renderHTML({ HTMLAttributes: o }) {
|
|
1430
1436
|
return [
|
|
1431
1437
|
"div",
|
|
1432
|
-
|
|
1438
|
+
x(this.options.HTMLAttributes, o, {
|
|
1433
1439
|
class: k.blockGroup,
|
|
1434
1440
|
"data-node-type": "blockGroup"
|
|
1435
1441
|
}),
|
|
@@ -1493,9 +1499,7 @@ class je {
|
|
|
1493
1499
|
h(this, "suggestionsMenu");
|
|
1494
1500
|
h(this, "pluginState");
|
|
1495
1501
|
h(this, "itemCallback");
|
|
1496
|
-
h(this, "
|
|
1497
|
-
this.pluginKey.getState(this.editor._tiptapEditor.state).active && this.suggestionsMenu.render(this.getDynamicParams(), !1);
|
|
1498
|
-
});
|
|
1502
|
+
h(this, "lastPosition");
|
|
1499
1503
|
this.editor = e, this.pluginKey = t, this.pluginState = W(), this.itemCallback = (i) => {
|
|
1500
1504
|
e._tiptapEditor.chain().focus().deleteRange({
|
|
1501
1505
|
from: this.pluginState.queryStartPos - this.pluginState.triggerCharacter.length,
|
|
@@ -1504,7 +1508,7 @@ class je {
|
|
|
1504
1508
|
item: i,
|
|
1505
1509
|
editor: e
|
|
1506
1510
|
});
|
|
1507
|
-
}, this.suggestionsMenu = r(this.getStaticParams())
|
|
1511
|
+
}, this.suggestionsMenu = r(this.getStaticParams());
|
|
1508
1512
|
}
|
|
1509
1513
|
update(e, t) {
|
|
1510
1514
|
const n = this.pluginKey.getState(t), r = this.pluginKey.getState(e.state), i = !n.active && r.active, s = n.active && !r.active, a = n.active && r.active;
|
|
@@ -1516,22 +1520,29 @@ class je {
|
|
|
1516
1520
|
(l) => l.preventDefault()
|
|
1517
1521
|
)));
|
|
1518
1522
|
}
|
|
1519
|
-
destroy() {
|
|
1520
|
-
document.removeEventListener("scroll", this.handleScroll);
|
|
1521
|
-
}
|
|
1522
1523
|
getStaticParams() {
|
|
1523
1524
|
return {
|
|
1524
|
-
itemCallback: (e) => this.itemCallback(e)
|
|
1525
|
+
itemCallback: (e) => this.itemCallback(e),
|
|
1526
|
+
getReferenceRect: () => {
|
|
1527
|
+
const e = document.querySelector(
|
|
1528
|
+
`[data-decoration-id="${this.pluginState.decorationId}"]`
|
|
1529
|
+
);
|
|
1530
|
+
if (!e) {
|
|
1531
|
+
if (this.lastPosition === void 0)
|
|
1532
|
+
throw new Error(
|
|
1533
|
+
"Attempted to access trigger character reference rect before rendering suggestions menu."
|
|
1534
|
+
);
|
|
1535
|
+
return this.lastPosition;
|
|
1536
|
+
}
|
|
1537
|
+
const t = e.getBoundingClientRect();
|
|
1538
|
+
return this.lastPosition = t, t;
|
|
1539
|
+
}
|
|
1525
1540
|
};
|
|
1526
1541
|
}
|
|
1527
1542
|
getDynamicParams() {
|
|
1528
|
-
const e = document.querySelector(
|
|
1529
|
-
`[data-decoration-id="${this.pluginState.decorationId}"]`
|
|
1530
|
-
);
|
|
1531
1543
|
return {
|
|
1532
1544
|
items: this.pluginState.items,
|
|
1533
|
-
keyboardHoveredItemIndex: this.pluginState.keyboardHoveredItemIndex
|
|
1534
|
-
referenceRect: e.getBoundingClientRect()
|
|
1545
|
+
keyboardHoveredItemIndex: this.pluginState.keyboardHoveredItemIndex
|
|
1535
1546
|
};
|
|
1536
1547
|
}
|
|
1537
1548
|
}
|
|
@@ -1707,7 +1718,7 @@ const X = new E("suggestions-slash-commands"), We = () => v.create({
|
|
|
1707
1718
|
];
|
|
1708
1719
|
}
|
|
1709
1720
|
});
|
|
1710
|
-
class
|
|
1721
|
+
class A extends G {
|
|
1711
1722
|
constructor(t, n) {
|
|
1712
1723
|
super(t, n);
|
|
1713
1724
|
h(this, "nodes");
|
|
@@ -1718,13 +1729,13 @@ class L extends G {
|
|
|
1718
1729
|
});
|
|
1719
1730
|
}
|
|
1720
1731
|
static create(t, n, r = n) {
|
|
1721
|
-
return new
|
|
1732
|
+
return new A(t.resolve(n), t.resolve(r));
|
|
1722
1733
|
}
|
|
1723
1734
|
content() {
|
|
1724
|
-
return new
|
|
1735
|
+
return new T(P.from(this.nodes), 0, 0);
|
|
1725
1736
|
}
|
|
1726
1737
|
eq(t) {
|
|
1727
|
-
if (!(t instanceof
|
|
1738
|
+
if (!(t instanceof A) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to)
|
|
1728
1739
|
return !1;
|
|
1729
1740
|
for (let n = 0; n < this.nodes.length; n++)
|
|
1730
1741
|
if (!this.nodes[n].eq(t.nodes[n]))
|
|
@@ -1733,7 +1744,7 @@ class L extends G {
|
|
|
1733
1744
|
}
|
|
1734
1745
|
map(t, n) {
|
|
1735
1746
|
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
|
|
1747
|
+
return i.deleted ? G.near(t.resolve(r.pos)) : r.deleted ? G.near(t.resolve(i.pos)) : new A(
|
|
1737
1748
|
t.resolve(r.pos),
|
|
1738
1749
|
t.resolve(i.pos)
|
|
1739
1750
|
);
|
|
@@ -1742,9 +1753,9 @@ class L extends G {
|
|
|
1742
1753
|
return { type: "node", anchor: this.anchor, head: this.head };
|
|
1743
1754
|
}
|
|
1744
1755
|
}
|
|
1745
|
-
const
|
|
1746
|
-
let
|
|
1747
|
-
function
|
|
1756
|
+
const Ve = ae.__serializeForClipboard;
|
|
1757
|
+
let M;
|
|
1758
|
+
function Pt(o, e) {
|
|
1748
1759
|
var r;
|
|
1749
1760
|
if (!e.dom.isConnected)
|
|
1750
1761
|
return;
|
|
@@ -1759,8 +1770,8 @@ function _t(o, e) {
|
|
|
1759
1770
|
return { node: n, id: n.getAttribute("data-id") };
|
|
1760
1771
|
}
|
|
1761
1772
|
}
|
|
1762
|
-
function
|
|
1763
|
-
let t =
|
|
1773
|
+
function Ye(o, e) {
|
|
1774
|
+
let t = Pt(o, e);
|
|
1764
1775
|
if (t && t.node.nodeType === 1) {
|
|
1765
1776
|
const n = e.docView;
|
|
1766
1777
|
let r = n.nearestDesc(t.node, !0);
|
|
@@ -1791,14 +1802,14 @@ function it(o, e, t = e) {
|
|
|
1791
1802
|
);
|
|
1792
1803
|
for (let c = r.childElementCount - 1; c >= 0; c--)
|
|
1793
1804
|
(c > a || c < s) && n.removeChild(n.children[c]);
|
|
1794
|
-
|
|
1805
|
+
_t(), M = n;
|
|
1795
1806
|
const d = o.dom.className.split(" ").filter(
|
|
1796
1807
|
(c) => !c.includes("bn") && !c.includes("ProseMirror") && !c.includes("editor")
|
|
1797
1808
|
).join(" ");
|
|
1798
|
-
|
|
1809
|
+
M.className = M.className + " " + _.dragPreview + " " + d, document.body.appendChild(M);
|
|
1799
1810
|
}
|
|
1800
|
-
function
|
|
1801
|
-
|
|
1811
|
+
function _t() {
|
|
1812
|
+
M !== void 0 && (document.body.removeChild(M), M = void 0);
|
|
1802
1813
|
}
|
|
1803
1814
|
function Je(o, e) {
|
|
1804
1815
|
if (!o.dataTransfer)
|
|
@@ -1808,16 +1819,16 @@ function Je(o, e) {
|
|
|
1808
1819
|
left: t.left + t.width / 2,
|
|
1809
1820
|
// take middle of editor
|
|
1810
1821
|
top: o.clientY
|
|
1811
|
-
}, r =
|
|
1822
|
+
}, r = Ye(n, e);
|
|
1812
1823
|
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
|
|
1824
|
+
const i = e.state.selection, s = e.state.doc, { from: a, to: l } = Ke(i, s), d = a <= r && r < l, c = i.$anchor.node() !== i.$head.node() || i instanceof A;
|
|
1814
1825
|
d && c ? (e.dispatch(
|
|
1815
|
-
e.state.tr.setSelection(
|
|
1826
|
+
e.state.tr.setSelection(A.create(s, a, l))
|
|
1816
1827
|
), it(e, a, l)) : (e.dispatch(
|
|
1817
1828
|
e.state.tr.setSelection($t.create(e.state.doc, r))
|
|
1818
1829
|
), it(e, r));
|
|
1819
|
-
let u = e.state.selection.content(), { dom: p, text: f } =
|
|
1820
|
-
o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", p.innerHTML), o.dataTransfer.setData("text/plain", f), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(
|
|
1830
|
+
let u = e.state.selection.content(), { dom: p, text: f } = Ve(e, u);
|
|
1831
|
+
o.dataTransfer.clearData(), o.dataTransfer.setData("text/html", p.innerHTML), o.dataTransfer.setData("text/plain", f), o.dataTransfer.effectAllowed = "move", o.dataTransfer.setDragImage(M, 0, 0), e.dragging = { slice: u, move: !0 };
|
|
1821
1832
|
}
|
|
1822
1833
|
}
|
|
1823
1834
|
class Xe {
|
|
@@ -1839,6 +1850,7 @@ class Xe {
|
|
|
1839
1850
|
h(this, "isDragging", !1);
|
|
1840
1851
|
h(this, "menuOpen", !1);
|
|
1841
1852
|
h(this, "menuFrozen", !1);
|
|
1853
|
+
h(this, "lastPosition");
|
|
1842
1854
|
/**
|
|
1843
1855
|
* Sets isDragging when dragging text.
|
|
1844
1856
|
*/
|
|
@@ -1906,21 +1918,17 @@ class Xe {
|
|
|
1906
1918
|
left: t.left + t.width / 2,
|
|
1907
1919
|
// take middle of editor
|
|
1908
1920
|
top: e.clientY
|
|
1909
|
-
}, s =
|
|
1921
|
+
}, s = Pt(i, this.ttEditor.view);
|
|
1910
1922
|
if (!s || !this.editor.isEditable) {
|
|
1911
1923
|
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide());
|
|
1912
1924
|
return;
|
|
1913
1925
|
}
|
|
1914
1926
|
this.menuOpen && ((d = this.hoveredBlock) != null && d.hasAttribute("data-id")) && ((c = this.hoveredBlock) == null ? void 0 : c.getAttribute("data-id")) === s.id || (this.hoveredBlock = s.node, !s.node.firstChild) || this.editor.isEditable && (this.menuOpen ? this.blockMenu.render(this.getDynamicParams(), !1) : (this.menuOpen = !0, this.blockMenu.render(this.getDynamicParams(), !0)));
|
|
1915
1927
|
});
|
|
1916
|
-
|
|
1917
|
-
const e = this.ttEditor.view.dom.firstChild.getBoundingClientRect();
|
|
1918
|
-
this.horizontalPosAnchor = e.x, this.menuOpen && this.blockMenu.render(this.getDynamicParams(), !1);
|
|
1919
|
-
});
|
|
1920
|
-
this.editor = t, this.ttEditor = e, this.horizontalPosAnchoredAtRoot = r, this.horizontalPosAnchor = this.ttEditor.view.dom.firstChild.getBoundingClientRect().x, this.blockMenu = n(this.getStaticParams()), document.body.addEventListener("drop", this.onDrop, !0), document.body.addEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.addEventListener("dragstart", this.onDragStart), document.body.addEventListener("mousemove", this.onMouseMove, !0), document.addEventListener("scroll", this.onScroll), document.body.addEventListener("mousedown", this.onMouseDown, !0), document.body.addEventListener("keydown", this.onKeyDown, !0);
|
|
1928
|
+
this.editor = t, this.ttEditor = e, this.horizontalPosAnchoredAtRoot = r, this.horizontalPosAnchor = this.ttEditor.view.dom.firstChild.getBoundingClientRect().x, this.blockMenu = n(this.getStaticParams()), document.body.addEventListener("drop", this.onDrop, !0), document.body.addEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.addEventListener("dragstart", this.onDragStart), document.body.addEventListener("mousemove", this.onMouseMove, !0), document.body.addEventListener("mousedown", this.onMouseDown, !0), document.body.addEventListener("keydown", this.onKeyDown, !0);
|
|
1921
1929
|
}
|
|
1922
1930
|
destroy() {
|
|
1923
|
-
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), document.body.removeEventListener("mousemove", this.onMouseMove), document.body.removeEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.removeEventListener("dragstart", this.onDragStart), document.body.removeEventListener("drop", this.onDrop), document.body.removeEventListener("mousedown", this.onMouseDown), document.
|
|
1931
|
+
this.menuOpen && (this.menuOpen = !1, this.blockMenu.hide()), document.body.removeEventListener("mousemove", this.onMouseMove), document.body.removeEventListener("dragover", this.onDragOver), this.ttEditor.view.dom.removeEventListener("dragstart", this.onDragStart), document.body.removeEventListener("drop", this.onDrop), document.body.removeEventListener("mousedown", this.onMouseDown), document.body.removeEventListener("keydown", this.onKeyDown);
|
|
1924
1932
|
}
|
|
1925
1933
|
addBlock() {
|
|
1926
1934
|
this.menuOpen = !1, this.menuFrozen = !0, this.blockMenu.hide();
|
|
@@ -1954,25 +1962,29 @@ class Xe {
|
|
|
1954
1962
|
blockDragStart: (e) => {
|
|
1955
1963
|
this.isDragging = !0, Je(e, this.ttEditor.view);
|
|
1956
1964
|
},
|
|
1957
|
-
blockDragEnd: () =>
|
|
1965
|
+
blockDragEnd: () => _t(),
|
|
1958
1966
|
freezeMenu: () => {
|
|
1959
1967
|
this.menuFrozen = !0;
|
|
1960
1968
|
},
|
|
1961
1969
|
unfreezeMenu: () => {
|
|
1962
1970
|
this.menuFrozen = !1;
|
|
1971
|
+
},
|
|
1972
|
+
getReferenceRect: () => {
|
|
1973
|
+
if (!this.menuOpen) {
|
|
1974
|
+
if (this.lastPosition === void 0)
|
|
1975
|
+
throw new Error(
|
|
1976
|
+
"Attempted to access block reference rect before rendering block side menu."
|
|
1977
|
+
);
|
|
1978
|
+
return this.lastPosition;
|
|
1979
|
+
}
|
|
1980
|
+
const t = this.hoveredBlock.firstChild.getBoundingClientRect();
|
|
1981
|
+
return this.horizontalPosAnchoredAtRoot && (t.x = this.horizontalPosAnchor), this.lastPosition = t, t;
|
|
1963
1982
|
}
|
|
1964
1983
|
};
|
|
1965
1984
|
}
|
|
1966
1985
|
getDynamicParams() {
|
|
1967
|
-
const t = this.hoveredBlock.firstChild.getBoundingClientRect();
|
|
1968
1986
|
return {
|
|
1969
|
-
block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))
|
|
1970
|
-
referenceRect: new DOMRect(
|
|
1971
|
-
this.horizontalPosAnchoredAtRoot ? this.horizontalPosAnchor : t.x,
|
|
1972
|
-
t.y,
|
|
1973
|
-
t.width,
|
|
1974
|
-
t.height
|
|
1975
|
-
)
|
|
1987
|
+
block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))
|
|
1976
1988
|
};
|
|
1977
1989
|
}
|
|
1978
1990
|
}
|
|
@@ -2017,6 +2029,7 @@ class to {
|
|
|
2017
2029
|
h(this, "preventShow", !1);
|
|
2018
2030
|
h(this, "toolbarIsOpen", !1);
|
|
2019
2031
|
h(this, "prevWasEditable", null);
|
|
2032
|
+
h(this, "lastPosition");
|
|
2020
2033
|
h(this, "shouldShow", ({ view: e, state: t, from: n, to: r }) => {
|
|
2021
2034
|
const { doc: i, selection: s } = t, { empty: a } = s, l = !i.textBetween(n, r).length && Rt(t.selection);
|
|
2022
2035
|
return !(!e.hasFocus() || a || l);
|
|
@@ -2043,10 +2056,7 @@ class to {
|
|
|
2043
2056
|
e && e.relatedTarget && // Element is outside the toolbar.
|
|
2044
2057
|
(this.formattingToolbar.element === e.relatedTarget || (t = this.formattingToolbar.element) != null && t.contains(e.relatedTarget)) || this.toolbarIsOpen && (this.formattingToolbar.hide(), this.toolbarIsOpen = !1);
|
|
2045
2058
|
});
|
|
2046
|
-
|
|
2047
|
-
this.toolbarIsOpen && this.formattingToolbar.render(this.getDynamicParams(), !1);
|
|
2048
|
-
});
|
|
2049
|
-
this.editor = e, this.ttEditor = t, this.view = r, this.formattingToolbar = n(this.getStaticParams()), this.view.dom.addEventListener("mousedown", this.viewMousedownHandler), this.view.dom.addEventListener("mouseup", this.viewMouseupHandler), this.view.dom.addEventListener("dragstart", this.dragstartHandler), this.ttEditor.on("focus", this.focusHandler), this.ttEditor.on("blur", this.blurHandler), document.addEventListener("scroll", this.scrollHandler);
|
|
2059
|
+
this.editor = e, this.ttEditor = t, this.view = r, this.formattingToolbar = n(this.getStaticParams()), this.view.dom.addEventListener("mousedown", this.viewMousedownHandler), this.view.dom.addEventListener("mouseup", this.viewMouseupHandler), this.view.dom.addEventListener("dragstart", this.dragstartHandler), this.ttEditor.on("focus", this.focusHandler), this.ttEditor.on("blur", this.blurHandler);
|
|
2050
2060
|
}
|
|
2051
2061
|
update(e, t) {
|
|
2052
2062
|
var p;
|
|
@@ -2061,11 +2071,11 @@ class to {
|
|
|
2061
2071
|
to: c
|
|
2062
2072
|
});
|
|
2063
2073
|
if (this.editor.isEditable && !this.toolbarIsOpen && !this.preventShow && (u || this.preventHide)) {
|
|
2064
|
-
this.formattingToolbar.render(
|
|
2074
|
+
this.formattingToolbar.render({}, !0), this.toolbarIsOpen = !0;
|
|
2065
2075
|
return;
|
|
2066
2076
|
}
|
|
2067
2077
|
if (this.toolbarIsOpen && !this.preventShow && (u || this.preventHide)) {
|
|
2068
|
-
this.formattingToolbar.render(
|
|
2078
|
+
this.formattingToolbar.render({}, !1);
|
|
2069
2079
|
return;
|
|
2070
2080
|
}
|
|
2071
2081
|
if (this.toolbarIsOpen && !this.preventHide && (!u || this.preventShow || !this.editor.isEditable)) {
|
|
@@ -2074,7 +2084,7 @@ class to {
|
|
|
2074
2084
|
}
|
|
2075
2085
|
}
|
|
2076
2086
|
destroy() {
|
|
2077
|
-
this.view.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.view.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.ttEditor.off("focus", this.focusHandler), this.ttEditor.off("blur", this.blurHandler)
|
|
2087
|
+
this.view.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.view.dom.removeEventListener("mouseup", this.viewMouseupHandler), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.ttEditor.off("focus", this.focusHandler), this.ttEditor.off("blur", this.blurHandler);
|
|
2078
2088
|
}
|
|
2079
2089
|
getSelectionBoundingBox() {
|
|
2080
2090
|
const { state: e } = this.ttEditor.view, { selection: t } = e, { ranges: n } = t, r = Math.min(...n.map((s) => s.$from.pos)), i = Math.max(...n.map((s) => s.$to.pos));
|
|
@@ -2087,12 +2097,18 @@ class to {
|
|
|
2087
2097
|
}
|
|
2088
2098
|
getStaticParams() {
|
|
2089
2099
|
return {
|
|
2090
|
-
editor: this.editor
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2100
|
+
editor: this.editor,
|
|
2101
|
+
getReferenceRect: () => {
|
|
2102
|
+
if (!this.toolbarIsOpen) {
|
|
2103
|
+
if (this.lastPosition === void 0)
|
|
2104
|
+
throw new Error(
|
|
2105
|
+
"Attempted to access selection reference rect before rendering formatting toolbar."
|
|
2106
|
+
);
|
|
2107
|
+
return this.lastPosition;
|
|
2108
|
+
}
|
|
2109
|
+
const e = this.getSelectionBoundingBox();
|
|
2110
|
+
return this.lastPosition = e, e;
|
|
2111
|
+
}
|
|
2096
2112
|
};
|
|
2097
2113
|
}
|
|
2098
2114
|
}
|
|
@@ -2129,6 +2145,7 @@ class ro {
|
|
|
2129
2145
|
h(this, "keyboardHoveredHyperlinkMarkRange");
|
|
2130
2146
|
h(this, "hyperlinkMark");
|
|
2131
2147
|
h(this, "hyperlinkMarkRange");
|
|
2148
|
+
h(this, "lastPosition");
|
|
2132
2149
|
h(this, "mouseOverHandler", (e) => {
|
|
2133
2150
|
if (this.mouseHoveredHyperlinkMark = void 0, this.mouseHoveredHyperlinkMarkRange = void 0, this.stopMenuUpdateTimer(), e.target instanceof HTMLAnchorElement && e.target.nodeName === "A") {
|
|
2134
2151
|
const t = e.target, n = this.editor.view.posAtDOM(t, 0) + 1, r = this.editor.state.doc.resolve(
|
|
@@ -2154,14 +2171,11 @@ class ro {
|
|
|
2154
2171
|
this.editor.view.dom !== e.target && !this.editor.view.dom.contains(e.target) && // Element is outside the toolbar.
|
|
2155
2172
|
this.hyperlinkToolbar.element !== e.target && !((t = this.hyperlinkToolbar.element) != null && t.contains(e.target)) && this.hyperlinkToolbar.hide();
|
|
2156
2173
|
});
|
|
2157
|
-
h(this, "scrollHandler", () => {
|
|
2158
|
-
this.hyperlinkMark !== void 0 && this.hyperlinkToolbar.render(this.getDynamicParams(), !1);
|
|
2159
|
-
});
|
|
2160
2174
|
this.editor = e, this.hyperlinkToolbar = t(this.getStaticParams()), this.startMenuUpdateTimer = () => {
|
|
2161
2175
|
this.menuUpdateTimer = setTimeout(() => {
|
|
2162
2176
|
this.update();
|
|
2163
2177
|
}, 250);
|
|
2164
|
-
}, this.stopMenuUpdateTimer = () => (this.menuUpdateTimer && (clearTimeout(this.menuUpdateTimer), this.menuUpdateTimer = void 0), !1), this.editor.view.dom.addEventListener("mouseover", this.mouseOverHandler), document.addEventListener("click", this.clickHandler, !0)
|
|
2178
|
+
}, this.stopMenuUpdateTimer = () => (this.menuUpdateTimer && (clearTimeout(this.menuUpdateTimer), this.menuUpdateTimer = void 0), !1), this.editor.view.dom.addEventListener("mouseover", this.mouseOverHandler), document.addEventListener("click", this.clickHandler, !0);
|
|
2165
2179
|
}
|
|
2166
2180
|
update() {
|
|
2167
2181
|
var t, n, r, i;
|
|
@@ -2209,7 +2223,7 @@ class ro {
|
|
|
2209
2223
|
this.editor.view.dom.removeEventListener(
|
|
2210
2224
|
"mouseover",
|
|
2211
2225
|
this.mouseOverHandler
|
|
2212
|
-
)
|
|
2226
|
+
);
|
|
2213
2227
|
}
|
|
2214
2228
|
getStaticParams() {
|
|
2215
2229
|
return {
|
|
@@ -2233,6 +2247,21 @@ class ro {
|
|
|
2233
2247
|
this.hyperlinkMark.type
|
|
2234
2248
|
).setMeta("preventAutolink", !0)
|
|
2235
2249
|
), this.editor.view.focus(), this.hyperlinkToolbar.hide();
|
|
2250
|
+
},
|
|
2251
|
+
getReferenceRect: () => {
|
|
2252
|
+
if (!this.hyperlinkMark) {
|
|
2253
|
+
if (this.lastPosition === void 0)
|
|
2254
|
+
throw new Error(
|
|
2255
|
+
"Attempted to access hyperlink reference rect before rendering hyperlink toolbar."
|
|
2256
|
+
);
|
|
2257
|
+
return this.lastPosition;
|
|
2258
|
+
}
|
|
2259
|
+
const e = at(
|
|
2260
|
+
this.editor.view,
|
|
2261
|
+
this.hyperlinkMarkRange.from,
|
|
2262
|
+
this.hyperlinkMarkRange.to
|
|
2263
|
+
);
|
|
2264
|
+
return this.lastPosition = e, e;
|
|
2236
2265
|
}
|
|
2237
2266
|
};
|
|
2238
2267
|
}
|
|
@@ -2242,11 +2271,6 @@ class ro {
|
|
|
2242
2271
|
text: this.editor.view.state.doc.textBetween(
|
|
2243
2272
|
this.hyperlinkMarkRange.from,
|
|
2244
2273
|
this.hyperlinkMarkRange.to
|
|
2245
|
-
),
|
|
2246
|
-
referenceRect: at(
|
|
2247
|
-
this.editor.view,
|
|
2248
|
-
this.hyperlinkMarkRange.from,
|
|
2249
|
-
this.hyperlinkMarkRange.to
|
|
2250
2274
|
)
|
|
2251
2275
|
};
|
|
2252
2276
|
}
|
|
@@ -2329,7 +2353,7 @@ class S extends co {
|
|
|
2329
2353
|
).length !== 0), this.name = e, this.execute = t, this.aliases = n;
|
|
2330
2354
|
}
|
|
2331
2355
|
}
|
|
2332
|
-
function
|
|
2356
|
+
function I(o, e) {
|
|
2333
2357
|
const t = o.getTextCursorPosition().block;
|
|
2334
2358
|
t.content.length === 1 && t.content[0].type === "text" && t.content[0].text === "/" || t.content.length === 0 ? o.updateBlock(t, e) : (o.insertBlocks([e], t, "after"), o.setTextCursorPosition(o.getTextCursorPosition().nextBlock));
|
|
2335
2359
|
}
|
|
@@ -2337,7 +2361,7 @@ const uo = [
|
|
|
2337
2361
|
// Command for creating a level 1 heading
|
|
2338
2362
|
new S(
|
|
2339
2363
|
"Heading",
|
|
2340
|
-
(o) =>
|
|
2364
|
+
(o) => I(o, {
|
|
2341
2365
|
type: "heading",
|
|
2342
2366
|
props: { level: "1" }
|
|
2343
2367
|
}),
|
|
@@ -2346,7 +2370,7 @@ const uo = [
|
|
|
2346
2370
|
// Command for creating a level 2 heading
|
|
2347
2371
|
new S(
|
|
2348
2372
|
"Heading 2",
|
|
2349
|
-
(o) =>
|
|
2373
|
+
(o) => I(o, {
|
|
2350
2374
|
type: "heading",
|
|
2351
2375
|
props: { level: "2" }
|
|
2352
2376
|
}),
|
|
@@ -2355,7 +2379,7 @@ const uo = [
|
|
|
2355
2379
|
// Command for creating a level 3 heading
|
|
2356
2380
|
new S(
|
|
2357
2381
|
"Heading 3",
|
|
2358
|
-
(o) =>
|
|
2382
|
+
(o) => I(o, {
|
|
2359
2383
|
type: "heading",
|
|
2360
2384
|
props: { level: "3" }
|
|
2361
2385
|
}),
|
|
@@ -2364,7 +2388,7 @@ const uo = [
|
|
|
2364
2388
|
// Command for creating an ordered list
|
|
2365
2389
|
new S(
|
|
2366
2390
|
"Numbered List",
|
|
2367
|
-
(o) =>
|
|
2391
|
+
(o) => I(o, {
|
|
2368
2392
|
type: "numberedListItem"
|
|
2369
2393
|
}),
|
|
2370
2394
|
["li", "list", "numberedlist", "numbered list"]
|
|
@@ -2372,7 +2396,7 @@ const uo = [
|
|
|
2372
2396
|
// Command for creating a bullet list
|
|
2373
2397
|
new S(
|
|
2374
2398
|
"Bullet List",
|
|
2375
|
-
(o) =>
|
|
2399
|
+
(o) => I(o, {
|
|
2376
2400
|
type: "bulletListItem"
|
|
2377
2401
|
}),
|
|
2378
2402
|
["ul", "list", "bulletlist", "bullet list"]
|
|
@@ -2380,7 +2404,7 @@ const uo = [
|
|
|
2380
2404
|
// Command for creating a paragraph (pretty useless)
|
|
2381
2405
|
new S(
|
|
2382
2406
|
"Paragraph",
|
|
2383
|
-
(o) =>
|
|
2407
|
+
(o) => I(o, {
|
|
2384
2408
|
type: "paragraph"
|
|
2385
2409
|
}),
|
|
2386
2410
|
["p"]
|
|
@@ -2633,7 +2657,7 @@ const uo = [
|
|
|
2633
2657
|
se,
|
|
2634
2658
|
fo,
|
|
2635
2659
|
po,
|
|
2636
|
-
|
|
2660
|
+
Le,
|
|
2637
2661
|
Ne,
|
|
2638
2662
|
ho,
|
|
2639
2663
|
// custom blocks:
|
|
@@ -2655,9 +2679,9 @@ const uo = [
|
|
|
2655
2679
|
);
|
|
2656
2680
|
const t = (n) => {
|
|
2657
2681
|
const r = document.createElement("span");
|
|
2658
|
-
r.classList.add(
|
|
2682
|
+
r.classList.add(_["collaboration-cursor__caret"]), r.setAttribute("style", `border-color: ${n.color}`);
|
|
2659
2683
|
const i = document.createElement("span");
|
|
2660
|
-
i.classList.add(
|
|
2684
|
+
i.classList.add(_["collaboration-cursor__label"]), i.setAttribute("style", `background-color: ${n.color}`), i.insertBefore(document.createTextNode(n.name), null);
|
|
2661
2685
|
const s = document.createTextNode(""), a = document.createTextNode("");
|
|
2662
2686
|
return r.insertBefore(s, null), r.insertBefore(i, null), r.insertBefore(a, null), r;
|
|
2663
2687
|
};
|
|
@@ -2701,6 +2725,7 @@ class Ko {
|
|
|
2701
2725
|
h(this, "_tiptapEditor");
|
|
2702
2726
|
h(this, "blockCache", /* @__PURE__ */ new WeakMap());
|
|
2703
2727
|
h(this, "schema");
|
|
2728
|
+
h(this, "ready", !1);
|
|
2704
2729
|
var i, s, a;
|
|
2705
2730
|
this.options = e;
|
|
2706
2731
|
const t = {
|
|
@@ -2732,15 +2757,15 @@ class Ko {
|
|
|
2732
2757
|
...t._tiptapOptions,
|
|
2733
2758
|
onCreate: () => {
|
|
2734
2759
|
var l;
|
|
2735
|
-
(l = t.onEditorReady) == null || l.call(t, this), t.initialContent && this.replaceBlocks(this.topLevelBlocks, t.initialContent);
|
|
2760
|
+
(l = t.onEditorReady) == null || l.call(t, this), t.initialContent && this.replaceBlocks(this.topLevelBlocks, t.initialContent), this.ready = !0;
|
|
2736
2761
|
},
|
|
2737
2762
|
onUpdate: () => {
|
|
2738
2763
|
var l;
|
|
2739
|
-
(l = t.onEditorContentChange) == null || l.call(t, this);
|
|
2764
|
+
this.ready && ((l = t.onEditorContentChange) == null || l.call(t, this));
|
|
2740
2765
|
},
|
|
2741
2766
|
onSelectionUpdate: () => {
|
|
2742
2767
|
var l;
|
|
2743
|
-
(l = t.onTextCursorPositionChange) == null || l.call(t, this);
|
|
2768
|
+
this.ready && ((l = t.onTextCursorPositionChange) == null || l.call(t, this));
|
|
2744
2769
|
},
|
|
2745
2770
|
editable: e.editable === void 0 ? !0 : e.editable,
|
|
2746
2771
|
extensions: t.enableBlockNoteExtensions === !1 ? (i = t._tiptapOptions) == null ? void 0 : i.extensions : [...((s = t._tiptapOptions) == null ? void 0 : s.extensions) || [], ...n],
|
|
@@ -2749,9 +2774,9 @@ class Ko {
|
|
|
2749
2774
|
"data-theme": e.theme || "light",
|
|
2750
2775
|
...t.editorDOMAttributes || {},
|
|
2751
2776
|
class: [
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
t.defaultStyles ?
|
|
2777
|
+
_.bnEditor,
|
|
2778
|
+
_.bnRoot,
|
|
2779
|
+
t.defaultStyles ? _.defaultStyles : "",
|
|
2755
2780
|
((a = t.editorDOMAttributes) == null ? void 0 : a.class) || ""
|
|
2756
2781
|
].join(" ")
|
|
2757
2782
|
}
|
|
@@ -2774,7 +2799,7 @@ class Ko {
|
|
|
2774
2799
|
*/
|
|
2775
2800
|
get topLevelBlocks() {
|
|
2776
2801
|
const e = [];
|
|
2777
|
-
return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(
|
|
2802
|
+
return this._tiptapEditor.state.doc.firstChild.descendants((t) => (e.push(w(t, this.schema, this.blockCache)), !1)), e;
|
|
2778
2803
|
}
|
|
2779
2804
|
/**
|
|
2780
2805
|
* Gets a snapshot of an existing block from the editor.
|
|
@@ -2784,7 +2809,7 @@ class Ko {
|
|
|
2784
2809
|
getBlock(e) {
|
|
2785
2810
|
const t = typeof e == "string" ? e : e.id;
|
|
2786
2811
|
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 =
|
|
2812
|
+
return this._tiptapEditor.state.doc.firstChild.descendants((r) => typeof n < "u" ? !1 : r.type.name !== "blockContainer" || r.attrs.id !== t ? !0 : (n = w(r, this.schema, this.blockCache), !1)), n;
|
|
2788
2813
|
}
|
|
2789
2814
|
/**
|
|
2790
2815
|
* Traverses all blocks in the editor depth-first, and executes a callback for each.
|
|
@@ -2826,9 +2851,9 @@ class Ko {
|
|
|
2826
2851
|
i > 0 && (a = this._tiptapEditor.state.doc.resolve(n - 2).node());
|
|
2827
2852
|
let l;
|
|
2828
2853
|
return i < s - 1 && (l = this._tiptapEditor.state.doc.resolve(r + 2).node()), {
|
|
2829
|
-
block:
|
|
2830
|
-
prevBlock: a === void 0 ? void 0 :
|
|
2831
|
-
nextBlock: l === void 0 ? void 0 :
|
|
2854
|
+
block: w(e, this.schema, this.blockCache),
|
|
2855
|
+
prevBlock: a === void 0 ? void 0 : w(a, this.schema, this.blockCache),
|
|
2856
|
+
nextBlock: l === void 0 ? void 0 : w(l, this.schema, this.blockCache)
|
|
2832
2857
|
};
|
|
2833
2858
|
}
|
|
2834
2859
|
/**
|
|
@@ -2854,7 +2879,7 @@ class Ko {
|
|
|
2854
2879
|
return;
|
|
2855
2880
|
const e = [];
|
|
2856
2881
|
return this._tiptapEditor.state.doc.descendants((t, n) => t.type.spec.group !== "blockContent" || n + t.nodeSize < this._tiptapEditor.state.selection.from || n > this._tiptapEditor.state.selection.to ? !0 : (e.push(
|
|
2857
|
-
|
|
2882
|
+
w(
|
|
2858
2883
|
this._tiptapEditor.state.doc.resolve(n).node(),
|
|
2859
2884
|
this.schema,
|
|
2860
2885
|
this.blockCache
|
|
@@ -2884,7 +2909,7 @@ class Ko {
|
|
|
2884
2909
|
* `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
|
|
2885
2910
|
*/
|
|
2886
2911
|
insertBlocks(e, t, n = "before") {
|
|
2887
|
-
|
|
2912
|
+
Tt(e, t, n, this._tiptapEditor);
|
|
2888
2913
|
}
|
|
2889
2914
|
/**
|
|
2890
2915
|
* Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
|
|
@@ -2894,14 +2919,14 @@ class Ko {
|
|
|
2894
2919
|
* @param update A partial block which defines how the existing block should be changed.
|
|
2895
2920
|
*/
|
|
2896
2921
|
updateBlock(e, t) {
|
|
2897
|
-
|
|
2922
|
+
Be(e, t, this._tiptapEditor);
|
|
2898
2923
|
}
|
|
2899
2924
|
/**
|
|
2900
2925
|
* Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
|
|
2901
2926
|
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
2902
2927
|
*/
|
|
2903
2928
|
removeBlocks(e) {
|
|
2904
|
-
|
|
2929
|
+
xt(e, this._tiptapEditor);
|
|
2905
2930
|
}
|
|
2906
2931
|
/**
|
|
2907
2932
|
* Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
|
|
@@ -2911,7 +2936,7 @@ class Ko {
|
|
|
2911
2936
|
* @param blocksToInsert An array of partial blocks to replace the old ones with.
|
|
2912
2937
|
*/
|
|
2913
2938
|
replaceBlocks(e, t) {
|
|
2914
|
-
|
|
2939
|
+
we(e, t, this._tiptapEditor);
|
|
2915
2940
|
}
|
|
2916
2941
|
/**
|
|
2917
2942
|
* Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
|
|
@@ -3038,7 +3063,7 @@ class Ko {
|
|
|
3038
3063
|
* @returns The blocks, serialized as an HTML string.
|
|
3039
3064
|
*/
|
|
3040
3065
|
async blocksToHTML(e) {
|
|
3041
|
-
return
|
|
3066
|
+
return St(e, this._tiptapEditor.schema);
|
|
3042
3067
|
}
|
|
3043
3068
|
/**
|
|
3044
3069
|
* Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
|
|
@@ -3057,7 +3082,7 @@ class Ko {
|
|
|
3057
3082
|
* @returns The blocks, serialized as a Markdown string.
|
|
3058
3083
|
*/
|
|
3059
3084
|
async blocksToMarkdown(e) {
|
|
3060
|
-
return
|
|
3085
|
+
return xe(e, this._tiptapEditor.schema);
|
|
3061
3086
|
}
|
|
3062
3087
|
/**
|
|
3063
3088
|
* Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
|
|
@@ -3067,7 +3092,7 @@ class Ko {
|
|
|
3067
3092
|
* @returns The blocks parsed from the Markdown string.
|
|
3068
3093
|
*/
|
|
3069
3094
|
async markdownToBlocks(e) {
|
|
3070
|
-
return
|
|
3095
|
+
return Se(e, this.schema, this._tiptapEditor.schema);
|
|
3071
3096
|
}
|
|
3072
3097
|
/**
|
|
3073
3098
|
* Updates the user info for the current user that's shown to other collaborators.
|
|
@@ -3084,12 +3109,12 @@ export {
|
|
|
3084
3109
|
S as BaseSlashMenuItem,
|
|
3085
3110
|
Ko as BlockNoteEditor,
|
|
3086
3111
|
$e as CustomBlockSerializerExtension,
|
|
3087
|
-
|
|
3112
|
+
Vo as blockStyles,
|
|
3088
3113
|
ot as camelToDataKebab,
|
|
3089
|
-
|
|
3114
|
+
Yo as createBlockSpec,
|
|
3090
3115
|
H as createTipTapBlock,
|
|
3091
3116
|
ke as defaultBlockSchema,
|
|
3092
|
-
|
|
3117
|
+
L as defaultProps,
|
|
3093
3118
|
uo as defaultSlashMenuItems,
|
|
3094
3119
|
go as getBlockNoteExtensions,
|
|
3095
3120
|
de as parse,
|