@blocknote/core 0.8.3 → 0.8.4
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 +64 -55
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +3 -3
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +10 -11
- package/src/BlockNoteEditor.ts +13 -6
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +34 -14
- package/types/src/extensions/Blocks/helpers/getBlockInfoFromPos.d.ts +5 -5
package/dist/blocknote.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var Lt = Object.defineProperty;
|
|
2
2
|
var Nt = (n, e, t) => e in n ? Lt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
3
|
var u = (n, e, t) => (Nt(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { Extension as
|
|
4
|
+
import { Extension as B, Mark as at, Node as V, InputRule as Y, mergeAttributes as x, combineTransactionSteps as Pt, getChangedRanges as Ot, findChildrenInRange as Dt, findChildren as Q, findParentNode as Rt, extensions as L, isTextSelection as zt, isNodeSelection as Vt, posToDOMRect as j, getMarkRange as tt, Editor as Ut } from "@tiptap/core";
|
|
5
5
|
import { Bold as Ft } from "@tiptap/extension-bold";
|
|
6
|
-
import { Code as
|
|
7
|
-
import
|
|
6
|
+
import { Code as Gt } from "@tiptap/extension-code";
|
|
7
|
+
import $t from "@tiptap/extension-collaboration";
|
|
8
8
|
import jt from "@tiptap/extension-collaboration-cursor";
|
|
9
9
|
import { Dropcursor as qt } from "@tiptap/extension-dropcursor";
|
|
10
10
|
import { Gapcursor as Wt } from "@tiptap/extension-gapcursor";
|
|
@@ -15,8 +15,8 @@ import { Link as Xt } from "@tiptap/extension-link";
|
|
|
15
15
|
import { Strike as Zt } from "@tiptap/extension-strike";
|
|
16
16
|
import { Text as Qt } from "@tiptap/extension-text";
|
|
17
17
|
import { Underline as te } from "@tiptap/extension-underline";
|
|
18
|
-
import { Slice as
|
|
19
|
-
import { PluginKey as S, Plugin as y, TextSelection as et, Selection as
|
|
18
|
+
import { Slice as T, Fragment as I, DOMSerializer as q, DOMParser as ee } from "prosemirror-model";
|
|
19
|
+
import { PluginKey as S, Plugin as y, TextSelection as et, Selection as $, NodeSelection as oe } from "prosemirror-state";
|
|
20
20
|
import { v4 as ne } from "uuid";
|
|
21
21
|
import * as re from "prosemirror-view";
|
|
22
22
|
import { Decoration as R, DecorationSet as z } from "prosemirror-view";
|
|
@@ -38,31 +38,38 @@ const de = "_bnEditor_4vj2p_3", ce = "_bnRoot_4vj2p_20", ue = "_defaultStyles_4v
|
|
|
38
38
|
"collaboration-cursor__label": "_collaboration-cursor__label_4vj2p_85"
|
|
39
39
|
};
|
|
40
40
|
function g(n, e) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const o = n.nodeSize - 2;
|
|
42
|
+
if (e <= 1)
|
|
43
|
+
for (e = 1 + 1; n.resolve(e).parent.type.name !== "blockContainer" && e < o; )
|
|
44
|
+
e++;
|
|
45
|
+
else if (e >= o)
|
|
46
|
+
for (e = o - 1; n.resolve(e).parent.type.name !== "blockContainer" && e > 1; )
|
|
47
|
+
e--;
|
|
43
48
|
n.resolve(e).parent.type.name === "blockGroup" && e++;
|
|
44
|
-
const
|
|
45
|
-
let
|
|
49
|
+
const r = n.resolve(e), i = r.depth;
|
|
50
|
+
let s = r.node(i), l = i;
|
|
46
51
|
for (; ; ) {
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
if (l < 0)
|
|
53
|
+
throw new Error(
|
|
54
|
+
"Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited."
|
|
55
|
+
);
|
|
56
|
+
if (s.type.name === "blockContainer")
|
|
50
57
|
break;
|
|
51
|
-
|
|
58
|
+
l -= 1, s = r.node(l);
|
|
52
59
|
}
|
|
53
|
-
const
|
|
60
|
+
const a = s.attrs.id, d = s.firstChild, c = d.type, p = s.childCount === 2 ? s.lastChild.childCount : 0, h = r.start(l), f = r.end(l);
|
|
54
61
|
return {
|
|
55
|
-
id:
|
|
56
|
-
node:
|
|
57
|
-
contentNode:
|
|
58
|
-
contentType:
|
|
59
|
-
numChildBlocks:
|
|
60
|
-
startPos:
|
|
61
|
-
endPos:
|
|
62
|
-
depth:
|
|
62
|
+
id: a,
|
|
63
|
+
node: s,
|
|
64
|
+
contentNode: d,
|
|
65
|
+
contentType: c,
|
|
66
|
+
numChildBlocks: p,
|
|
67
|
+
startPos: h,
|
|
68
|
+
endPos: f,
|
|
69
|
+
depth: l
|
|
63
70
|
};
|
|
64
71
|
}
|
|
65
|
-
const he =
|
|
72
|
+
const he = B.create({
|
|
66
73
|
name: "blockBackgroundColor",
|
|
67
74
|
addGlobalAttributes() {
|
|
68
75
|
return [
|
|
@@ -548,7 +555,7 @@ function Ee(n) {
|
|
|
548
555
|
);
|
|
549
556
|
return Me(e);
|
|
550
557
|
}
|
|
551
|
-
const U =
|
|
558
|
+
const U = B.create({
|
|
552
559
|
name: "uniqueID",
|
|
553
560
|
// we’ll set a very high priority to make sure this runs first
|
|
554
561
|
// and is compatible with `appendTransaction` hooks of other extensions
|
|
@@ -630,8 +637,8 @@ const U = T.create({
|
|
|
630
637
|
(C) => a.includes(C.type.name)
|
|
631
638
|
), v = b.map(({ node: C }) => C.attrs[d]).filter((C) => C !== null), w = Ee(v);
|
|
632
639
|
b.forEach(({ node: C, pos: D }) => {
|
|
633
|
-
var
|
|
634
|
-
const Z = (
|
|
640
|
+
var G;
|
|
641
|
+
const Z = (G = l.doc.nodeAt(D)) === null || G === void 0 ? void 0 : G.attrs[d];
|
|
635
642
|
if (Z === null) {
|
|
636
643
|
l.setNodeMarkup(D, void 0, {
|
|
637
644
|
...C.attrs,
|
|
@@ -700,7 +707,7 @@ const U = T.create({
|
|
|
700
707
|
l.push(d);
|
|
701
708
|
}), I.from(l);
|
|
702
709
|
};
|
|
703
|
-
return e = !1, new
|
|
710
|
+
return e = !1, new T(
|
|
704
711
|
i(t.content),
|
|
705
712
|
t.openStart,
|
|
706
713
|
t.openEnd
|
|
@@ -711,7 +718,7 @@ const U = T.create({
|
|
|
711
718
|
];
|
|
712
719
|
}
|
|
713
720
|
});
|
|
714
|
-
class
|
|
721
|
+
class Be extends Error {
|
|
715
722
|
constructor(e) {
|
|
716
723
|
super(`Unreachable case: ${e}`);
|
|
717
724
|
}
|
|
@@ -730,7 +737,7 @@ function rt(n, e) {
|
|
|
730
737
|
return n.text.split(/(\n)/g).filter((o) => o.length > 0).map((o) => o === `
|
|
731
738
|
` ? e.nodes.hardBreak.create() : e.text(o, t));
|
|
732
739
|
}
|
|
733
|
-
function
|
|
740
|
+
function Te(n, e) {
|
|
734
741
|
const t = e.marks.link.create({
|
|
735
742
|
href: n.href
|
|
736
743
|
});
|
|
@@ -756,11 +763,11 @@ function Et(n, e) {
|
|
|
756
763
|
let t = [];
|
|
757
764
|
for (const o of n)
|
|
758
765
|
if (o.type === "link")
|
|
759
|
-
t.push(...
|
|
766
|
+
t.push(...Te(o, e));
|
|
760
767
|
else if (o.type === "text")
|
|
761
768
|
t.push(...Mt([o], e));
|
|
762
769
|
else
|
|
763
|
-
throw new
|
|
770
|
+
throw new Be(o);
|
|
764
771
|
return t;
|
|
765
772
|
}
|
|
766
773
|
function O(n, e) {
|
|
@@ -1075,7 +1082,7 @@ const it = new S("previous-blocks"), _e = {
|
|
|
1075
1082
|
l.childCount === 2 ? t.tr.replace(
|
|
1076
1083
|
i + a.nodeSize + 1,
|
|
1077
1084
|
s - 1,
|
|
1078
|
-
new
|
|
1085
|
+
new T(I.from(d), 0, 0)
|
|
1079
1086
|
) : t.tr.insert(
|
|
1080
1087
|
i + a.nodeSize,
|
|
1081
1088
|
t.schema.nodes.blockGroup.create({}, d)
|
|
@@ -1086,7 +1093,7 @@ const it = new S("previous-blocks"), _e = {
|
|
|
1086
1093
|
typeof e.content == "string" ? d.push(t.schema.text(e.content)) : d = Et(e.content, t.schema), t.tr.replace(
|
|
1087
1094
|
i + 1,
|
|
1088
1095
|
i + a.nodeSize - 1,
|
|
1089
|
-
new
|
|
1096
|
+
new T(I.from(d), 0, 0)
|
|
1090
1097
|
);
|
|
1091
1098
|
}
|
|
1092
1099
|
t.tr.setNodeMarkup(
|
|
@@ -1142,7 +1149,7 @@ const it = new S("previous-blocks"), _e = {
|
|
|
1142
1149
|
e.tr.deleteRange(a, a + l.nodeSize).replace(
|
|
1143
1150
|
p - 1,
|
|
1144
1151
|
a,
|
|
1145
|
-
new
|
|
1152
|
+
new T(l.content, 0, 0)
|
|
1146
1153
|
).scrollIntoView()
|
|
1147
1154
|
), e.tr.setSelection(
|
|
1148
1155
|
new et(e.doc.resolve(p - 1))
|
|
@@ -1158,7 +1165,7 @@ const it = new S("previous-blocks"), _e = {
|
|
|
1158
1165
|
return o && (t.tr.insert(f, h), t.tr.replace(
|
|
1159
1166
|
m,
|
|
1160
1167
|
m + 1,
|
|
1161
|
-
p.content.size > 0 ? new
|
|
1168
|
+
p.content.size > 0 ? new T(
|
|
1162
1169
|
I.from(p),
|
|
1163
1170
|
d + 2,
|
|
1164
1171
|
d + 2
|
|
@@ -1173,7 +1180,7 @@ const it = new S("previous-blocks"), _e = {
|
|
|
1173
1180
|
), t.tr.replace(
|
|
1174
1181
|
l + 1,
|
|
1175
1182
|
a - 1,
|
|
1176
|
-
c.content.size > 0 ? new
|
|
1183
|
+
c.content.size > 0 ? new T(
|
|
1177
1184
|
I.from(c),
|
|
1178
1185
|
d + 2,
|
|
1179
1186
|
d + 2
|
|
@@ -1330,7 +1337,7 @@ const it = new S("previous-blocks"), _e = {
|
|
|
1330
1337
|
},
|
|
1331
1338
|
e.marks
|
|
1332
1339
|
);
|
|
1333
|
-
}, Oe =
|
|
1340
|
+
}, Oe = B.create({
|
|
1334
1341
|
addProseMirrorPlugins() {
|
|
1335
1342
|
return [
|
|
1336
1343
|
new y({
|
|
@@ -1587,7 +1594,7 @@ class Ve extends F {
|
|
|
1587
1594
|
return this.on("update", t);
|
|
1588
1595
|
}
|
|
1589
1596
|
}
|
|
1590
|
-
const Ue = new S("blocknote-placeholder"), Fe =
|
|
1597
|
+
const Ue = new S("blocknote-placeholder"), Fe = B.create({
|
|
1591
1598
|
name: "placeholder",
|
|
1592
1599
|
addOptions() {
|
|
1593
1600
|
return {
|
|
@@ -1626,7 +1633,7 @@ const Ue = new S("blocknote-placeholder"), Fe = T.create({
|
|
|
1626
1633
|
})
|
|
1627
1634
|
];
|
|
1628
1635
|
}
|
|
1629
|
-
}),
|
|
1636
|
+
}), Ge = B.create({
|
|
1630
1637
|
name: "textAlignment",
|
|
1631
1638
|
addGlobalAttributes() {
|
|
1632
1639
|
return [
|
|
@@ -1664,7 +1671,7 @@ const Ue = new S("blocknote-placeholder"), Fe = T.create({
|
|
|
1664
1671
|
}
|
|
1665
1672
|
};
|
|
1666
1673
|
}
|
|
1667
|
-
}),
|
|
1674
|
+
}), $e = B.create({
|
|
1668
1675
|
name: "blockTextColor",
|
|
1669
1676
|
addGlobalAttributes() {
|
|
1670
1677
|
return [
|
|
@@ -1719,7 +1726,7 @@ const Ue = new S("blocknote-placeholder"), Fe = T.create({
|
|
|
1719
1726
|
setTextColor: (n) => ({ commands: e }) => n !== "default" ? e.setMark(this.name, { color: n }) : e.unsetMark(this.name)
|
|
1720
1727
|
};
|
|
1721
1728
|
}
|
|
1722
|
-
}), qe =
|
|
1729
|
+
}), qe = B.create({
|
|
1723
1730
|
name: "trailingNode",
|
|
1724
1731
|
addProseMirrorPlugins() {
|
|
1725
1732
|
const n = new S(this.name);
|
|
@@ -1777,16 +1784,16 @@ const Ue = new S("blocknote-placeholder"), Fe = T.create({
|
|
|
1777
1784
|
Qt,
|
|
1778
1785
|
// marks:
|
|
1779
1786
|
Ft,
|
|
1780
|
-
|
|
1787
|
+
Gt,
|
|
1781
1788
|
Kt,
|
|
1782
1789
|
Zt,
|
|
1783
1790
|
te,
|
|
1784
1791
|
Xt,
|
|
1785
1792
|
je,
|
|
1786
|
-
|
|
1793
|
+
$e,
|
|
1787
1794
|
fe,
|
|
1788
1795
|
he,
|
|
1789
|
-
|
|
1796
|
+
Ge,
|
|
1790
1797
|
// custom blocks:
|
|
1791
1798
|
...Ne,
|
|
1792
1799
|
...Object.values(n.blockSchema).map(
|
|
@@ -1800,7 +1807,7 @@ const Ue = new S("blocknote-placeholder"), Fe = T.create({
|
|
|
1800
1807
|
];
|
|
1801
1808
|
if (n.collaboration) {
|
|
1802
1809
|
e.push(
|
|
1803
|
-
|
|
1810
|
+
$t.configure({
|
|
1804
1811
|
fragment: n.collaboration.fragment
|
|
1805
1812
|
})
|
|
1806
1813
|
);
|
|
@@ -1832,7 +1839,7 @@ function X(n, e) {
|
|
|
1832
1839
|
posBeforeNode: o
|
|
1833
1840
|
};
|
|
1834
1841
|
}
|
|
1835
|
-
function
|
|
1842
|
+
function Bt(n, e, t = "before", o) {
|
|
1836
1843
|
const r = typeof e == "string" ? e : e.id, i = [];
|
|
1837
1844
|
for (const d of n)
|
|
1838
1845
|
i.push(O(d, o.schema));
|
|
@@ -1858,7 +1865,7 @@ function Ye(n, e, t) {
|
|
|
1858
1865
|
const o = typeof n == "string" ? n : n.id, { posBeforeNode: r } = X(o, t.state.doc);
|
|
1859
1866
|
t.commands.BNUpdateBlock(r + 1, e);
|
|
1860
1867
|
}
|
|
1861
|
-
function
|
|
1868
|
+
function Tt(n, e) {
|
|
1862
1869
|
const t = new Set(
|
|
1863
1870
|
n.map(
|
|
1864
1871
|
(r) => typeof r == "string" ? r : r.id
|
|
@@ -1884,7 +1891,7 @@ function Bt(n, e) {
|
|
|
1884
1891
|
}
|
|
1885
1892
|
}
|
|
1886
1893
|
function Je(n, e, t) {
|
|
1887
|
-
|
|
1894
|
+
Bt(e, n[0], "before", t), Tt(n, t);
|
|
1888
1895
|
}
|
|
1889
1896
|
function Ke() {
|
|
1890
1897
|
const n = (e) => {
|
|
@@ -2246,7 +2253,7 @@ class io extends F {
|
|
|
2246
2253
|
return this.on("update", t);
|
|
2247
2254
|
}
|
|
2248
2255
|
}
|
|
2249
|
-
class A extends
|
|
2256
|
+
class A extends $ {
|
|
2250
2257
|
constructor(t, o) {
|
|
2251
2258
|
super(t, o);
|
|
2252
2259
|
u(this, "nodes");
|
|
@@ -2260,7 +2267,7 @@ class A extends G {
|
|
|
2260
2267
|
return new A(t.resolve(o), t.resolve(r));
|
|
2261
2268
|
}
|
|
2262
2269
|
content() {
|
|
2263
|
-
return new
|
|
2270
|
+
return new T(I.from(this.nodes), 0, 0);
|
|
2264
2271
|
}
|
|
2265
2272
|
eq(t) {
|
|
2266
2273
|
if (!(t instanceof A) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to)
|
|
@@ -2272,7 +2279,7 @@ class A extends G {
|
|
|
2272
2279
|
}
|
|
2273
2280
|
map(t, o) {
|
|
2274
2281
|
let r = o.mapResult(this.from), i = o.mapResult(this.to);
|
|
2275
|
-
return i.deleted ?
|
|
2282
|
+
return i.deleted ? $.near(t.resolve(r.pos)) : r.deleted ? $.near(t.resolve(i.pos)) : new A(
|
|
2276
2283
|
t.resolve(r.pos),
|
|
2277
2284
|
t.resolve(i.pos)
|
|
2278
2285
|
);
|
|
@@ -2637,7 +2644,7 @@ class Wo {
|
|
|
2637
2644
|
editor: this,
|
|
2638
2645
|
blockSchema: t.blockSchema,
|
|
2639
2646
|
collaboration: t.collaboration
|
|
2640
|
-
}), r =
|
|
2647
|
+
}), r = B.create({
|
|
2641
2648
|
name: "BlockNoteUIExtension",
|
|
2642
2649
|
addProseMirrorPlugins: () => [
|
|
2643
2650
|
this.sideMenu.plugin,
|
|
@@ -2647,7 +2654,7 @@ class Wo {
|
|
|
2647
2654
|
]
|
|
2648
2655
|
});
|
|
2649
2656
|
o.push(r), this.schema = t.blockSchema;
|
|
2650
|
-
const i = t.initialContent || [
|
|
2657
|
+
const i = t.initialContent || e.collaboration ? void 0 : [
|
|
2651
2658
|
{
|
|
2652
2659
|
type: "paragraph",
|
|
2653
2660
|
id: U.options.generateID()
|
|
@@ -2660,6 +2667,8 @@ class Wo {
|
|
|
2660
2667
|
(c = t.onEditorReady) == null || c.call(t, this), this.ready = !0;
|
|
2661
2668
|
},
|
|
2662
2669
|
onBeforeCreate(c) {
|
|
2670
|
+
if (!i)
|
|
2671
|
+
return;
|
|
2663
2672
|
const p = c.editor.schema, h = i.map((m) => O(m, p)), f = p.node(
|
|
2664
2673
|
"doc",
|
|
2665
2674
|
void 0,
|
|
@@ -2827,7 +2836,7 @@ class Wo {
|
|
|
2827
2836
|
* `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
|
|
2828
2837
|
*/
|
|
2829
2838
|
insertBlocks(e, t, o = "before") {
|
|
2830
|
-
|
|
2839
|
+
Bt(e, t, o, this._tiptapEditor);
|
|
2831
2840
|
}
|
|
2832
2841
|
/**
|
|
2833
2842
|
* Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
|
|
@@ -2844,7 +2853,7 @@ class Wo {
|
|
|
2844
2853
|
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
2845
2854
|
*/
|
|
2846
2855
|
removeBlocks(e) {
|
|
2847
|
-
|
|
2856
|
+
Tt(e, this._tiptapEditor);
|
|
2848
2857
|
}
|
|
2849
2858
|
/**
|
|
2850
2859
|
* Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
|