@blocknote/core 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/blocknote.js CHANGED
@@ -8568,66 +8568,7 @@ const ys = async (e) => {
8568
8568
  "tmpfiles.org/dl/"
8569
8569
  );
8570
8570
  };
8571
- function Jn(e, t) {
8572
- const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8573
- if (i)
8574
- return v(
8575
- i.node,
8576
- e.schema.blockSchema,
8577
- e.schema.inlineContentSchema,
8578
- e.schema.styleSchema,
8579
- e.blockCache
8580
- );
8581
- }
8582
- function Yn(e, t) {
8583
- const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8584
- if (!i)
8585
- return;
8586
- const r = e._tiptapEditor.state.doc.resolve(
8587
- i.posBeforeNode
8588
- ).nodeBefore;
8589
- if (r)
8590
- return v(
8591
- r,
8592
- e.schema.blockSchema,
8593
- e.schema.inlineContentSchema,
8594
- e.schema.styleSchema,
8595
- e.blockCache
8596
- );
8597
- }
8598
- function Qn(e, t) {
8599
- const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8600
- if (!i)
8601
- return;
8602
- const r = e._tiptapEditor.state.doc.resolve(
8603
- i.posBeforeNode + i.node.nodeSize
8604
- ).nodeAfter;
8605
- if (r)
8606
- return v(
8607
- r,
8608
- e.schema.blockSchema,
8609
- e.schema.inlineContentSchema,
8610
- e.schema.styleSchema,
8611
- e.blockCache
8612
- );
8613
- }
8614
- function er(e, t) {
8615
- const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8616
- if (!i)
8617
- return;
8618
- const n = e._tiptapEditor.state.doc.resolve(
8619
- i.posBeforeNode
8620
- ), r = n.node(), a = n.node(-1), s = a.type.name !== "doc" ? r.type.name === "blockGroup" ? a : r : void 0;
8621
- if (s)
8622
- return v(
8623
- s,
8624
- e.schema.blockSchema,
8625
- e.schema.inlineContentSchema,
8626
- e.schema.styleSchema,
8627
- e.blockCache
8628
- );
8629
- }
8630
- function tr(e, t, o, i = "before") {
8571
+ function Jn(e, t, o, i = "before") {
8631
8572
  const n = typeof o == "string" ? o : o.id, r = [];
8632
8573
  for (const l of t)
8633
8574
  r.push(
@@ -8657,7 +8598,7 @@ function tr(e, t, o, i = "before") {
8657
8598
  );
8658
8599
  return s;
8659
8600
  }
8660
- function or(e) {
8601
+ function Yn(e) {
8661
8602
  const t = e._tiptapEditor.state, o = t.selection, i = z(t.doc, o.anchor);
8662
8603
  if (o instanceof Fe)
8663
8604
  return {
@@ -8682,7 +8623,7 @@ function or(e) {
8682
8623
  };
8683
8624
  }
8684
8625
  }
8685
- function ir(e, t) {
8626
+ function Qn(e, t) {
8686
8627
  var n, r;
8687
8628
  const o = (n = A(
8688
8629
  t.anchorBlockId,
@@ -8731,8 +8672,8 @@ function Yt(e, t, o) {
8731
8672
  var r;
8732
8673
  const i = ((r = e.getSelection()) == null ? void 0 : r.blocks) || [
8733
8674
  e.getTextCursorPosition().block
8734
- ], n = or(e);
8735
- e.removeBlocks(i), e.insertBlocks(Re(i), t, o), ir(e, n);
8675
+ ], n = Yn(e);
8676
+ e.removeBlocks(i), e.insertBlocks(Re(i), t, o), Qn(e, n);
8736
8677
  }
8737
8678
  function Qt(e) {
8738
8679
  return !e || e.type !== "columnList";
@@ -8759,7 +8700,7 @@ function to(e, t, o) {
8759
8700
  r
8760
8701
  );
8761
8702
  }
8762
- function nr(e) {
8703
+ function er(e) {
8763
8704
  const t = e.getSelection(), o = (t == null ? void 0 : t.blocks[0]) || e.getTextCursorPosition().block, i = eo(
8764
8705
  e,
8765
8706
  e.getPrevBlock(o),
@@ -8771,7 +8712,7 @@ function nr(e) {
8771
8712
  i.placement
8772
8713
  );
8773
8714
  }
8774
- function rr(e) {
8715
+ function tr(e) {
8775
8716
  const t = e.getSelection(), o = (t == null ? void 0 : t.blocks[(t == null ? void 0 : t.blocks.length) - 1]) || e.getTextCursorPosition().block, i = to(
8776
8717
  e,
8777
8718
  e.getNextBlock(o),
@@ -8783,7 +8724,7 @@ function rr(e) {
8783
8724
  i.placement
8784
8725
  );
8785
8726
  }
8786
- function ar(e, t) {
8727
+ function or(e, t) {
8787
8728
  return function({ state: o, dispatch: i }) {
8788
8729
  const { $from: n, $to: r } = o.selection, a = n.blockRange(
8789
8730
  r,
@@ -8826,22 +8767,22 @@ function ar(e, t) {
8826
8767
  }
8827
8768
  function oo(e) {
8828
8769
  return e._tiptapEditor.commands.command(
8829
- ar(
8770
+ or(
8830
8771
  e._tiptapEditor.schema.nodes.blockContainer,
8831
8772
  e._tiptapEditor.schema.nodes.blockGroup
8832
8773
  )
8833
8774
  );
8834
8775
  }
8835
- function sr(e) {
8776
+ function ir(e) {
8836
8777
  e._tiptapEditor.commands.liftListItem("blockContainer");
8837
8778
  }
8838
- function lr(e) {
8779
+ function nr(e) {
8839
8780
  const { bnBlock: t } = _(
8840
8781
  e._tiptapEditor.state
8841
8782
  );
8842
8783
  return e._tiptapEditor.state.doc.resolve(t.beforePos).nodeBefore !== null;
8843
8784
  }
8844
- function dr(e) {
8785
+ function rr(e) {
8845
8786
  const { bnBlock: t } = _(
8846
8787
  e._tiptapEditor.state
8847
8788
  );
@@ -8905,90 +8846,83 @@ function io(e, t, o) {
8905
8846
  );
8906
8847
  return { insertedBlocks: d, removedBlocks: s };
8907
8848
  }
8908
- function cr(e, t, o) {
8849
+ function ar(e, t, o) {
8909
8850
  return io(e, t, o);
8910
8851
  }
8911
- function ur(e, t) {
8852
+ function sr(e, t) {
8912
8853
  return io(e, t, []).removedBlocks;
8913
8854
  }
8914
- function pr(e, t, o, i = { updateSelection: !0 }) {
8915
- const n = o._tiptapEditor.state.tr;
8916
- let { from: r, to: a } = typeof e == "number" ? { from: e, to: e } : { from: e.from, to: e.to }, s = !0, l = !0, c = "";
8917
- if (t.forEach((d) => {
8918
- d.check(), s && d.isText && d.marks.length === 0 ? c += d.text : s = !1, l = l ? d.isBlock : !1;
8919
- }), r === a && l) {
8920
- const { parent: d } = n.doc.resolve(r);
8921
- d.isTextblock && !d.type.spec.code && !d.childCount && (r -= 1, a += 1);
8922
- }
8923
- return s ? n.insertText(c, r, a) : n.replaceWith(r, a, t), i.updateSelection && Co(n, n.steps.length - 1, -1), o.dispatch(n), !0;
8924
- }
8925
- function hr(e) {
8926
- const { bnBlock: t } = _(e._tiptapEditor.state), o = e._tiptapEditor.state.doc.resolve(t.beforePos), i = o.nodeBefore, n = e._tiptapEditor.state.doc.resolve(
8927
- t.afterPos
8928
- ).nodeAfter;
8929
- let r;
8930
- return o.depth > 1 && (r = o.node(), r.type.isInGroup("bnBlock") || (r = o.node(o.depth - 1))), {
8931
- block: v(
8932
- t.node,
8855
+ function lr(e, t) {
8856
+ const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8857
+ if (i)
8858
+ return v(
8859
+ i.node,
8933
8860
  e.schema.blockSchema,
8934
8861
  e.schema.inlineContentSchema,
8935
8862
  e.schema.styleSchema,
8936
8863
  e.blockCache
8937
- ),
8938
- prevBlock: i === null ? void 0 : v(
8939
- i,
8864
+ );
8865
+ }
8866
+ function dr(e, t) {
8867
+ const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8868
+ if (!i)
8869
+ return;
8870
+ const r = e._tiptapEditor.state.doc.resolve(
8871
+ i.posBeforeNode
8872
+ ).nodeBefore;
8873
+ if (r)
8874
+ return v(
8875
+ r,
8940
8876
  e.schema.blockSchema,
8941
8877
  e.schema.inlineContentSchema,
8942
8878
  e.schema.styleSchema,
8943
8879
  e.blockCache
8944
- ),
8945
- nextBlock: n === null ? void 0 : v(
8946
- n,
8880
+ );
8881
+ }
8882
+ function cr(e, t) {
8883
+ const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8884
+ if (!i)
8885
+ return;
8886
+ const r = e._tiptapEditor.state.doc.resolve(
8887
+ i.posBeforeNode + i.node.nodeSize
8888
+ ).nodeAfter;
8889
+ if (r)
8890
+ return v(
8891
+ r,
8947
8892
  e.schema.blockSchema,
8948
8893
  e.schema.inlineContentSchema,
8949
8894
  e.schema.styleSchema,
8950
8895
  e.blockCache
8951
- ),
8952
- parentBlock: r === void 0 ? void 0 : v(
8953
- r,
8896
+ );
8897
+ }
8898
+ function ur(e, t) {
8899
+ const o = typeof t == "string" ? t : t.id, i = A(o, e._tiptapEditor.state.doc);
8900
+ if (!i)
8901
+ return;
8902
+ const n = e._tiptapEditor.state.doc.resolve(
8903
+ i.posBeforeNode
8904
+ ), r = n.node(), a = n.node(-1), s = a.type.name !== "doc" ? r.type.name === "blockGroup" ? a : r : void 0;
8905
+ if (s)
8906
+ return v(
8907
+ s,
8954
8908
  e.schema.blockSchema,
8955
8909
  e.schema.inlineContentSchema,
8956
8910
  e.schema.styleSchema,
8957
8911
  e.blockCache
8958
- )
8959
- };
8912
+ );
8960
8913
  }
8961
- function no(e, t, o = "start") {
8962
- const i = typeof t == "string" ? t : t.id, n = A(i, e._tiptapEditor.state.doc);
8963
- if (!n)
8964
- throw new Error(`Block with ID ${i} not found`);
8965
- const r = F(n), a = e.schema.blockSchema[r.blockNoteType].content;
8966
- if (r.isBlockContainer) {
8967
- const s = r.blockContent;
8968
- if (a === "none") {
8969
- e._tiptapEditor.commands.setNodeSelection(s.beforePos);
8970
- return;
8971
- }
8972
- if (a === "inline")
8973
- o === "start" ? e._tiptapEditor.commands.setTextSelection(
8974
- s.beforePos + 1
8975
- ) : e._tiptapEditor.commands.setTextSelection(
8976
- s.afterPos - 1
8977
- );
8978
- else if (a === "table")
8979
- o === "start" ? e._tiptapEditor.commands.setTextSelection(
8980
- s.beforePos + 4
8981
- ) : e._tiptapEditor.commands.setTextSelection(
8982
- s.afterPos - 4
8983
- );
8984
- else
8985
- throw new D(a);
8986
- } else {
8987
- const s = o === "start" ? r.childContainer.node.firstChild : r.childContainer.node.lastChild;
8988
- no(e, s.attrs.id, o);
8914
+ function pr(e, t, o, i = { updateSelection: !0 }) {
8915
+ const n = o._tiptapEditor.state.tr;
8916
+ let { from: r, to: a } = typeof e == "number" ? { from: e, to: e } : { from: e.from, to: e.to }, s = !0, l = !0, c = "";
8917
+ if (t.forEach((d) => {
8918
+ d.check(), s && d.isText && d.marks.length === 0 ? c += d.text : s = !1, l = l ? d.isBlock : !1;
8919
+ }), r === a && l) {
8920
+ const { parent: d } = n.doc.resolve(r);
8921
+ d.isTextblock && !d.type.spec.code && !d.childCount && (r -= 1, a += 1);
8989
8922
  }
8923
+ return s ? n.insertText(c, r, a) : n.replaceWith(r, a, t), i.updateSelection && Co(n, n.steps.length - 1, -1), o.dispatch(n), !0;
8990
8924
  }
8991
- function mr(e) {
8925
+ function hr(e) {
8992
8926
  const t = e._tiptapEditor.state;
8993
8927
  if (t.selection.empty || "node" in t.selection)
8994
8928
  return;
@@ -9038,7 +8972,7 @@ function mr(e) {
9038
8972
  blocks: r
9039
8973
  };
9040
8974
  }
9041
- function fr(e, t, o) {
8975
+ function mr(e, t, o) {
9042
8976
  const i = typeof t == "string" ? t : t.id, n = typeof o == "string" ? o : o.id;
9043
8977
  if (i === n)
9044
8978
  throw new Error(
@@ -9080,6 +9014,72 @@ function fr(e, t, o) {
9080
9014
  )
9081
9015
  );
9082
9016
  }
9017
+ function fr(e) {
9018
+ const { bnBlock: t } = _(e._tiptapEditor.state), o = e._tiptapEditor.state.doc.resolve(t.beforePos), i = o.nodeBefore, n = e._tiptapEditor.state.doc.resolve(
9019
+ t.afterPos
9020
+ ).nodeAfter;
9021
+ let r;
9022
+ return o.depth > 1 && (r = o.node(), r.type.isInGroup("bnBlock") || (r = o.node(o.depth - 1))), {
9023
+ block: v(
9024
+ t.node,
9025
+ e.schema.blockSchema,
9026
+ e.schema.inlineContentSchema,
9027
+ e.schema.styleSchema,
9028
+ e.blockCache
9029
+ ),
9030
+ prevBlock: i === null ? void 0 : v(
9031
+ i,
9032
+ e.schema.blockSchema,
9033
+ e.schema.inlineContentSchema,
9034
+ e.schema.styleSchema,
9035
+ e.blockCache
9036
+ ),
9037
+ nextBlock: n === null ? void 0 : v(
9038
+ n,
9039
+ e.schema.blockSchema,
9040
+ e.schema.inlineContentSchema,
9041
+ e.schema.styleSchema,
9042
+ e.blockCache
9043
+ ),
9044
+ parentBlock: r === void 0 ? void 0 : v(
9045
+ r,
9046
+ e.schema.blockSchema,
9047
+ e.schema.inlineContentSchema,
9048
+ e.schema.styleSchema,
9049
+ e.blockCache
9050
+ )
9051
+ };
9052
+ }
9053
+ function no(e, t, o = "start") {
9054
+ const i = typeof t == "string" ? t : t.id, n = A(i, e._tiptapEditor.state.doc);
9055
+ if (!n)
9056
+ throw new Error(`Block with ID ${i} not found`);
9057
+ const r = F(n), a = e.schema.blockSchema[r.blockNoteType].content;
9058
+ if (r.isBlockContainer) {
9059
+ const s = r.blockContent;
9060
+ if (a === "none") {
9061
+ e._tiptapEditor.commands.setNodeSelection(s.beforePos);
9062
+ return;
9063
+ }
9064
+ if (a === "inline")
9065
+ o === "start" ? e._tiptapEditor.commands.setTextSelection(
9066
+ s.beforePos + 1
9067
+ ) : e._tiptapEditor.commands.setTextSelection(
9068
+ s.afterPos - 1
9069
+ );
9070
+ else if (a === "table")
9071
+ o === "start" ? e._tiptapEditor.commands.setTextSelection(
9072
+ s.beforePos + 4
9073
+ ) : e._tiptapEditor.commands.setTextSelection(
9074
+ s.afterPos - 4
9075
+ );
9076
+ else
9077
+ throw new D(a);
9078
+ } else {
9079
+ const s = o === "start" ? r.childContainer.node.firstChild : r.childContainer.node.lastChild;
9080
+ no(e, s.attrs.id, o);
9081
+ }
9082
+ }
9083
9083
  let Y;
9084
9084
  async function qe() {
9085
9085
  if (Y)
@@ -10787,6 +10787,10 @@ class oa {
10787
10787
  }
10788
10788
  this.updateStateFromMousePos();
10789
10789
  });
10790
+ p(this, "onScroll", () => {
10791
+ var t;
10792
+ (t = this.state) != null && t.show && (this.state.referencePos = this.hoveredBlock.getBoundingClientRect(), this.emitUpdate(this.state));
10793
+ });
10790
10794
  this.editor = t, this.sideMenuDetection = o, this.pmView = i, this.emitUpdate = () => {
10791
10795
  if (!this.state)
10792
10796
  throw new Error("Attempting to update uninitialized side menu");
@@ -10809,7 +10813,7 @@ class oa {
10809
10813
  "keydown",
10810
10814
  this.onKeyDown,
10811
10815
  !0
10812
- );
10816
+ ), i.root.addEventListener("scroll", this.onScroll, !0);
10813
10817
  }
10814
10818
  createSyntheticEvent(t) {
10815
10819
  const o = new Event(t.type, t), i = this.pmView.dom.firstChild.getBoundingClientRect();
@@ -10849,7 +10853,7 @@ class oa {
10849
10853
  "keydown",
10850
10854
  this.onKeyDown,
10851
10855
  !0
10852
- );
10856
+ ), this.pmView.root.removeEventListener("scroll", this.onScroll, !0);
10853
10857
  }
10854
10858
  }
10855
10859
  const ia = new N("SideMenuPlugin");
@@ -12049,7 +12053,7 @@ class mo {
12049
12053
  }), (((s = i._tiptapOptions) == null ? void 0 : s.extensions) || []).forEach((m) => {
12050
12054
  this.extensions[m.name] = m;
12051
12055
  }), Object.entries(i._extensions || {}).forEach(([m, g]) => {
12052
- this.extensions[m] = g;
12056
+ typeof g == "function" && (g = g(this)), this.extensions[m] = g;
12053
12057
  }), this.formattingToolbar = this.extensions.formattingToolbar, this.linkToolbar = this.extensions.linkToolbar, this.sideMenu = this.extensions.sideMenu, this.suggestionMenus = this.extensions.suggestionMenus, this.filePanel = this.extensions.filePanel, this.tableHandles = this.extensions.tableHandles, i.uploadFile) {
12054
12058
  const m = i.uploadFile;
12055
12059
  this.uploadFile = async (g, b) => {
@@ -12190,7 +12194,7 @@ class mo {
12190
12194
  * matching block was found.
12191
12195
  */
12192
12196
  getBlock(t) {
12193
- return Jn(this, t);
12197
+ return lr(this, t);
12194
12198
  }
12195
12199
  /**
12196
12200
  * Gets a snapshot of the previous sibling of an existing block from the
@@ -12202,7 +12206,7 @@ class mo {
12202
12206
  * in the document.
12203
12207
  */
12204
12208
  getPrevBlock(t) {
12205
- return Yn(this, t);
12209
+ return dr(this, t);
12206
12210
  }
12207
12211
  /**
12208
12212
  * Gets a snapshot of the next sibling of an existing block from the editor.
@@ -12213,7 +12217,7 @@ class mo {
12213
12217
  * the document.
12214
12218
  */
12215
12219
  getNextBlock(t) {
12216
- return Qn(this, t);
12220
+ return cr(this, t);
12217
12221
  }
12218
12222
  /**
12219
12223
  * Gets a snapshot of the parent of an existing block from the editor.
@@ -12223,7 +12227,7 @@ class mo {
12223
12227
  * if no matching block was found, or the block isn't nested.
12224
12228
  */
12225
12229
  getParentBlock(t) {
12226
- return er(this, t);
12230
+ return ur(this, t);
12227
12231
  }
12228
12232
  /**
12229
12233
  * Traverses all blocks in the editor depth-first, and executes a callback for each.
@@ -12264,7 +12268,7 @@ class mo {
12264
12268
  * @returns A snapshot of the current text cursor position.
12265
12269
  */
12266
12270
  getTextCursorPosition() {
12267
- return hr(this);
12271
+ return fr(this);
12268
12272
  }
12269
12273
  /**
12270
12274
  * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
@@ -12279,10 +12283,10 @@ class mo {
12279
12283
  * Gets a snapshot of the current selection.
12280
12284
  */
12281
12285
  getSelection() {
12282
- return mr(this);
12286
+ return hr(this);
12283
12287
  }
12284
12288
  setSelection(t, o) {
12285
- fr(this, t, o);
12289
+ mr(this, t, o);
12286
12290
  }
12287
12291
  /**
12288
12292
  * Checks if the editor is currently editable, or if it's locked.
@@ -12317,7 +12321,7 @@ class mo {
12317
12321
  * `referenceBlock`.
12318
12322
  */
12319
12323
  insertBlocks(t, o, i = "before") {
12320
- return tr(this, t, o, i);
12324
+ return Jn(this, t, o, i);
12321
12325
  }
12322
12326
  /**
12323
12327
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
@@ -12334,7 +12338,7 @@ class mo {
12334
12338
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
12335
12339
  */
12336
12340
  removeBlocks(t) {
12337
- return ur(this, t);
12341
+ return sr(this, t);
12338
12342
  }
12339
12343
  /**
12340
12344
  * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
@@ -12344,7 +12348,7 @@ class mo {
12344
12348
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
12345
12349
  */
12346
12350
  replaceBlocks(t, o) {
12347
- return cr(this, t, o);
12351
+ return ar(this, t, o);
12348
12352
  }
12349
12353
  /**
12350
12354
  * Insert a piece of content at the current cursor position.
@@ -12457,7 +12461,7 @@ class mo {
12457
12461
  * Checks if the block containing the text cursor can be nested.
12458
12462
  */
12459
12463
  canNestBlock() {
12460
- return lr(this);
12464
+ return nr(this);
12461
12465
  }
12462
12466
  /**
12463
12467
  * Nests the block containing the text cursor into the block above it.
@@ -12469,13 +12473,13 @@ class mo {
12469
12473
  * Checks if the block containing the text cursor is nested.
12470
12474
  */
12471
12475
  canUnnestBlock() {
12472
- return dr(this);
12476
+ return rr(this);
12473
12477
  }
12474
12478
  /**
12475
12479
  * Lifts the block containing the text cursor out of its parent.
12476
12480
  */
12477
12481
  unnestBlock() {
12478
- sr(this);
12482
+ ir(this);
12479
12483
  }
12480
12484
  /**
12481
12485
  * Moves the selected blocks up. If the previous block has children, moves
@@ -12483,7 +12487,7 @@ class mo {
12483
12487
  * current blocks share a common parent, moves them out of & before it.
12484
12488
  */
12485
12489
  moveBlocksUp() {
12486
- nr(this);
12490
+ er(this);
12487
12491
  }
12488
12492
  /**
12489
12493
  * Moves the selected blocks down. If the next block has children, moves
@@ -12491,7 +12495,7 @@ class mo {
12491
12495
  * current blocks share a common parent, moves them out of & after it.
12492
12496
  */
12493
12497
  moveBlocksDown() {
12494
- rr(this);
12498
+ tr(this);
12495
12499
  }
12496
12500
  /**
12497
12501
  * Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list