@blocknote/xl-ai 0.40.0 → 0.41.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.
@@ -1,31 +1,31 @@
1
- var tt = Object.defineProperty;
2
- var ot = (e, t, o) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
- var L = (e, t, o) => ot(e, typeof t != "symbol" ? t + "" : t, o);
4
- import { Chat as rt } from "@ai-sdk/react";
5
- import { getPmSchema as nt, UnreachableCaseError as Be, getNodeById as st, updateBlockTr as it, insertBlocks as at, trackPosition as ae, removeAndInsertBlocks as lt, getBlock as Me, defaultProps as Ee, isStyledTextInlineContent as ct, isLinkInlineContent as ut, BlockNoteExtension as dt, filterSuggestionItems as pt, mergeCSSClasses as mt } from "@blocknote/core";
6
- import { applySuggestions as _e, suggestChanges as ft, revertSuggestions as le } from "@blocknote/prosemirror-suggest-changes";
1
+ var ot = Object.defineProperty;
2
+ var rt = (e, t, o) => t in e ? ot(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var M = (e, t, o) => rt(e, typeof t != "symbol" ? t + "" : t, o);
4
+ import { Chat as nt } from "@ai-sdk/react";
5
+ import { getPmSchema as st, UnreachableCaseError as Be, getNodeById as Me, updateBlockTr as it, insertBlocks as at, trackPosition as ae, removeAndInsertBlocks as lt, getBlock as Ee, defaultProps as _e, isStyledTextInlineContent as ct, isLinkInlineContent as ut, BlockNoteExtension as dt, filterSuggestionItems as pt, mergeCSSClasses as mt } from "@blocknote/core";
6
+ import { applySuggestions as Ne, suggestChanges as ft, revertSuggestions as le } from "@blocknote/prosemirror-suggest-changes";
7
7
  import { Slice as G, Fragment as ce } from "prosemirror-model";
8
- import { TextSelection as ht, Plugin as Ne, PluginKey as Le } from "prosemirror-state";
8
+ import { TextSelection as ht, Plugin as Le, PluginKey as Ae } from "prosemirror-state";
9
9
  import { fixTablesKey as yt } from "prosemirror-tables";
10
10
  import { DecorationSet as ue, Decoration as de } from "prosemirror-view";
11
11
  import { defaultSelectionBuilder as gt } from "y-prosemirror";
12
12
  import bt from "lodash.isequal";
13
13
  import { getErrorMessage as K } from "@ai-sdk/provider-utils";
14
- import { parsePartialJson as Ae, isToolUIPart as kt, tool as St, jsonSchema as pe, generateObject as wt, convertToModelMessages as Y, streamObject as Tt, streamText as xt } from "ai";
15
- import { Transform as D, Mapping as De, ReplaceStep as _, ReplaceAroundStep as vt } from "prosemirror-transform";
14
+ import { parsePartialJson as De, isToolUIPart as kt, tool as St, jsonSchema as pe, generateObject as wt, convertToModelMessages as Y, streamObject as Tt, streamText as xt } from "ai";
15
+ import { Transform as D, Mapping as je, ReplaceStep as N, ReplaceAroundStep as vt } from "prosemirror-transform";
16
16
  import { ChangeSet as me, simplifyChanges as Pt } from "prosemirror-changeset";
17
17
  import { jsxs as Ct, jsx as y } from "react/jsx-runtime";
18
18
  import { useBlockNoteContext as Ot, useComponentsContext as X, useSuggestionMenuKeyboardHandler as It, useBlockNoteEditor as Q, useUIElementPositioning as Bt } from "@blocknote/react";
19
- import M, { useState as je, useCallback as $, useMemo as A, useEffect as $e } from "react";
20
- import { useStore as He } from "zustand";
19
+ import E, { useState as $e, useCallback as $, useMemo as A, useEffect as He } from "react";
20
+ import { useStore as qe } from "zustand";
21
21
  import { offset as Mt, size as Et, autoUpdate as _t } from "@floating-ui/react";
22
22
  const fe = (e) => {
23
23
  let t;
24
- const o = /* @__PURE__ */ new Set(), r = (c, d) => {
25
- const f = typeof c == "function" ? c(t) : c;
26
- if (!Object.is(f, t)) {
27
- const m = t;
28
- t = d ?? (typeof f != "object" || f === null) ? f : Object.assign({}, t, f), o.forEach((u) => u(t, m));
24
+ const o = /* @__PURE__ */ new Set(), r = (c, u) => {
25
+ const m = typeof c == "function" ? c(t) : c;
26
+ if (!Object.is(m, t)) {
27
+ const p = t;
28
+ t = u ?? (typeof m != "object" || m === null) ? m : Object.assign({}, t, m), o.forEach((d) => d(t, p));
29
29
  }
30
30
  }, n = () => t, i = { setState: r, getState: n, getInitialState: () => l, subscribe: (c) => (o.add(c), () => o.delete(c)) }, l = t = e(r, n, i);
31
31
  return i;
@@ -99,7 +99,7 @@ function At(e, t) {
99
99
  }
100
100
  };
101
101
  }
102
- class qe extends Error {
102
+ class ze extends Error {
103
103
  constructor(t, o, r) {
104
104
  super(t, r), this.chunk = o, this.name = "ChunkExecutionError";
105
105
  }
@@ -109,7 +109,7 @@ class Dt {
109
109
  * @param streamTools - The StreamTools to use to apply the StreamToolCalls
110
110
  */
111
111
  constructor(t) {
112
- L(this, "stream");
112
+ M(this, "stream");
113
113
  this.streamTools = t, this.stream = this.createStream();
114
114
  }
115
115
  createStream() {
@@ -147,7 +147,7 @@ class Dt {
147
147
  break;
148
148
  }
149
149
  } catch (i) {
150
- throw new qe(
150
+ throw new ze(
151
151
  `Tool execution failed: ${K(i)}`,
152
152
  o,
153
153
  {
@@ -186,7 +186,7 @@ class Dt {
186
186
  async executeOperationsArray(t) {
187
187
  const o = this.writable.getWriter();
188
188
  for await (const r of t) {
189
- const n = await Ae(r);
189
+ const n = await De(r);
190
190
  if (n.state === "undefined-input" || n.state === "failed-parse" || !n)
191
191
  return;
192
192
  await o.write(r);
@@ -223,7 +223,7 @@ class Dt {
223
223
  }
224
224
  }
225
225
  async function jt(e, t, o) {
226
- const r = await Ae(e);
226
+ const r = await De(e);
227
227
  if (r.state === "undefined-input" || r.state === "failed-parse" || !r)
228
228
  return;
229
229
  const n = o.find((a) => {
@@ -251,7 +251,7 @@ function $t(e) {
251
251
  }
252
252
  });
253
253
  }
254
- function ze(e) {
254
+ function Je(e) {
255
255
  if (e.locked)
256
256
  throw new Error(
257
257
  "Stream (source) is already locked and cannot be iterated."
@@ -270,7 +270,7 @@ function ze(e) {
270
270
  }, t;
271
271
  }
272
272
  function Ht(e) {
273
- return ze($t(e));
273
+ return Je($t(e));
274
274
  }
275
275
  async function* qt(e, t) {
276
276
  var s;
@@ -354,7 +354,7 @@ function Vt(e, t, o) {
354
354
  return Ht(
355
355
  Ut(
356
356
  qt(
357
- ze(e),
357
+ Je(e),
358
358
  o
359
359
  ),
360
360
  t
@@ -367,52 +367,52 @@ async function Ft(e, t, o) {
367
367
  const s = /* @__PURE__ */ new Map();
368
368
  let a = !0;
369
369
  const i = t["~registerMessagesCallback"](() => {
370
- Zt(t, (u) => {
371
- if (!s.has(u.toolCallId)) {
370
+ Zt(t, (d) => {
371
+ if (!s.has(d.toolCallId)) {
372
372
  const h = Wt(
373
373
  e,
374
- u.toolName,
375
- u.toolCallId
374
+ d.toolName,
375
+ d.toolCallId
376
376
  );
377
- n.append(h.operationsStream), s.set(u.toolCallId, h), a && (a = !1, o == null || o());
377
+ n.append(h.operationsStream), s.set(d.toolCallId, h), a && (a = !1, o == null || o());
378
378
  }
379
- return s.get(u.toolCallId);
379
+ return s.get(d.toolCallId);
380
380
  });
381
381
  });
382
- await new Promise((u) => {
382
+ await new Promise((d) => {
383
383
  const h = t["~registerStatusCallback"](() => {
384
- (t.status === "ready" || t.status === "error") && (i(), h(), t.status !== "error" && p(), u());
385
- }), p = t["~registerErrorCallback"](() => {
384
+ (t.status === "ready" || t.status === "error") && (i(), h(), t.status !== "error" && f(), d());
385
+ }), f = t["~registerErrorCallback"](() => {
386
386
  if (t.error) {
387
- p();
387
+ f();
388
388
  for (const k of s.values())
389
389
  k.complete || k.writer.abort(t.error);
390
390
  }
391
391
  });
392
392
  }), await n.finalize();
393
393
  const c = (await Promise.allSettled([r.finish()]))[0];
394
- let d;
394
+ let u;
395
395
  if (c.status === "rejected") {
396
- if (c.reason instanceof qe)
397
- d = c.reason;
396
+ if (c.reason instanceof ze)
397
+ u = c.reason;
398
398
  else if (!t.error)
399
399
  throw new Error(
400
400
  "Unexpected: no ChunkExecutionError but also no chat.error (network error?)"
401
401
  );
402
402
  }
403
- let f = !1;
404
- const m = Array.from(
405
- s.values().filter((u) => u.complete)
403
+ let m = !1;
404
+ const p = Array.from(
405
+ s.values().filter((d) => d.complete)
406
406
  );
407
- if (m.forEach((u, h) => {
408
- const p = u.toolCallId === (d == null ? void 0 : d.chunk.metadata.toolCallId);
409
- p && (f = !0), t.addToolResult({
410
- tool: m[h].toolName,
411
- toolCallId: m[h].toolCallId,
412
- output: f === !1 ? { status: "ok" } : p ? { status: "error", error: K(d) } : { status: "not-executed-previous-tool-errored" }
407
+ if (p.forEach((d, h) => {
408
+ const f = d.toolCallId === (u == null ? void 0 : u.chunk.metadata.toolCallId);
409
+ f && (m = !0), t.addToolResult({
410
+ tool: p[h].toolName,
411
+ toolCallId: p[h].toolCallId,
412
+ output: m === !1 ? { status: "ok" } : f ? { status: "error", error: K(u) } : { status: "not-executed-previous-tool-errored" }
413
413
  });
414
- }), d)
415
- throw d;
414
+ }), u)
415
+ throw u;
416
416
  if (t.error)
417
417
  throw t.error;
418
418
  }
@@ -729,7 +729,7 @@ function T(e) {
729
729
  ...T(t.children)
730
730
  ]);
731
731
  }
732
- function E(e) {
732
+ function _(e) {
733
733
  return e.map((t) => typeof t == "object" && t && "id" in t ? {
734
734
  ...t,
735
735
  id: `${t.id}$`
@@ -737,18 +737,18 @@ function E(e) {
737
737
  }
738
738
  async function oo(e) {
739
739
  return e.selectedBlocks ? {
740
- ...await Ue(e.editor, {
740
+ ...await Ve(e.editor, {
741
741
  selectedBlocks: e.selectedBlocks
742
742
  }),
743
743
  userPrompt: e.userPrompt
744
744
  } : {
745
- ...await Je(e.editor, {
745
+ ...await Ue(e.editor, {
746
746
  excludeBlockIds: e.emptyCursorBlockToDelete ? [e.emptyCursorBlockToDelete] : void 0
747
747
  }),
748
748
  userPrompt: e.userPrompt
749
749
  };
750
750
  }
751
- async function Je(e, t) {
751
+ async function Ue(e, t) {
752
752
  const o = w(e.document).length === 0, r = e.getTextCursorPosition().block.id, n = w(e.document, {
753
753
  cursorBlockId: r
754
754
  }), s = await P(
@@ -759,15 +759,15 @@ async function Je(e, t) {
759
759
  );
760
760
  return {
761
761
  selection: !1,
762
- htmlBlocks: E(i),
762
+ htmlBlocks: _(i),
763
763
  isEmptyDocument: o
764
764
  };
765
765
  }
766
- async function Ue(e, t) {
766
+ async function Ve(e, t) {
767
767
  const o = w(e.document).length === 0, r = await P(
768
768
  T(t.selectedBlocks),
769
769
  async (s) => e.blocksToHTMLLossy([s])
770
- ), n = E(r);
770
+ ), n = _(r);
771
771
  return {
772
772
  isEmptyDocument: o,
773
773
  selection: !0,
@@ -782,11 +782,11 @@ function ro(e) {
782
782
  }
783
783
  function J(e) {
784
784
  var s;
785
- const t = nt(e), { modification: o } = t.marks, r = [], n = new D(e.before);
785
+ const t = st(e), { modification: o } = t.marks, r = [], n = new D(e.before);
786
786
  for (let a = 0; a < e.steps.length; a++) {
787
- const i = e.steps[a], l = new De(e.mapping.maps.slice(0, a)).invert();
787
+ const i = e.steps[a], l = new je(e.mapping.maps.slice(0, a)).invert();
788
788
  if (i.structure) {
789
- if (i instanceof _) {
789
+ if (i instanceof N) {
790
790
  if (i.to !== i.from + 1 || i.slice.openStart !== 0 || i.slice.openEnd !== 1 || i.slice.content.size !== 2)
791
791
  throw new Error(
792
792
  "Structure change is not in expected format (ReplaceStep)"
@@ -829,9 +829,9 @@ function J(e) {
829
829
  });
830
830
  continue;
831
831
  }
832
- if (!(i instanceof _))
832
+ if (!(i instanceof N))
833
833
  throw new Error("Step is not a ReplaceStep");
834
- const c = l.map(i.from), d = l.map(i.to);
834
+ const c = l.map(i.from), u = l.map(i.to);
835
835
  if (i.slice.openStart > 0 || i.slice.openEnd > 0)
836
836
  throw new Error(
837
837
  "Slice has openStart or openEnd > 0, but structure=false"
@@ -840,43 +840,43 @@ function J(e) {
840
840
  prosemirrorSteps: [],
841
841
  selection: {
842
842
  anchor: n.mapping.map(c),
843
- head: n.mapping.map(d)
843
+ head: n.mapping.map(u)
844
844
  },
845
845
  type: "select"
846
846
  });
847
- const f = i.slice.content.textBetween(0, i.slice.size), m = f === n.doc.textBetween(n.mapping.map(c), n.mapping.map(d));
848
- let u;
849
- if (m)
850
- u = i.slice.content.size;
851
- else if (f.length === 0)
852
- u = i.slice.content.size;
847
+ const m = i.slice.content.textBetween(0, i.slice.size), p = m === n.doc.textBetween(n.mapping.map(c), n.mapping.map(u));
848
+ let d;
849
+ if (p)
850
+ d = i.slice.content.size;
851
+ else if (m.length === 0)
852
+ d = i.slice.content.size;
853
853
  else {
854
854
  const b = ro(i.slice.content);
855
855
  if (b === void 0)
856
856
  throw new Error("unexpected: no first character found");
857
- u = b + 1;
857
+ d = b + 1;
858
858
  }
859
- let h = n.mapping.map(d);
860
- const p = n.mapping.map(d);
859
+ let h = n.mapping.map(u);
860
+ const f = n.mapping.map(u);
861
861
  let k = !0;
862
- for (let b = u; b <= i.slice.content.size; b++) {
863
- const g = k && c !== d, v = n.steps.length;
862
+ for (let b = d; b <= i.slice.content.size; b++) {
863
+ const g = k && c !== u, v = n.steps.length;
864
864
  if (g) {
865
865
  const B = n.doc.resolve(n.mapping.map(c));
866
- (s = B.nodeAfter) != null && s.isBlock && n.addNodeMark(B.pos, t.mark("deletion", {})), n.addMark(B.pos, h, t.mark("deletion", {})), h = n.mapping.map(d);
866
+ (s = B.nodeAfter) != null && s.isBlock && n.addNodeMark(B.pos, t.mark("deletion", {})), n.addMark(B.pos, h, t.mark("deletion", {})), h = n.mapping.map(u);
867
867
  }
868
868
  const S = new G(i.slice.content.cut(0, b), 0, 0);
869
- n.replace(p, h, S).addMark(
870
- p,
871
- p + S.content.size,
869
+ n.replace(f, h, S).addMark(
870
+ f,
871
+ f + S.content.size,
872
872
  t.mark("insertion", {})
873
873
  ), n.doc.nodesBetween(
874
- p,
875
- p + S.content.size,
876
- (B, C) => C < p || C > p + S.content.size ? !0 : (B.isBlock && n.addNodeMark(C, t.mark("insertion", {})), !1)
874
+ f,
875
+ f + S.content.size,
876
+ (B, C) => C < f || C > f + S.content.size ? !0 : (B.isBlock && n.addNodeMark(C, t.mark("insertion", {})), !1)
877
877
  ), h = n.mapping.slice(v).map(h);
878
878
  const j = ht.near(
879
- n.doc.resolve(p + S.content.size),
879
+ n.doc.resolve(f + S.content.size),
880
880
  -1
881
881
  );
882
882
  r.push({
@@ -918,7 +918,7 @@ function oe(e, t) {
918
918
  function no(e, t, o) {
919
919
  const r = new D(t);
920
920
  for (const a of e) {
921
- const i = new _(
921
+ const i = new N(
922
922
  r.mapping.map(a.fromA),
923
923
  r.mapping.map(a.toA),
924
924
  o.slice(a.fromB, a.toB)
@@ -931,26 +931,26 @@ function no(e, t, o) {
931
931
  const a = o.resolve(s).nodeAfter, i = r.doc.resolve(s).nodeAfter;
932
932
  if (!a || !i)
933
933
  throw new Error("diffNode not found");
934
- const l = !a.isLeaf && a.content.eq(i.content), c = l ? 1 : Math.min(a.nodeSize, i.nodeSize), d = s + c, f = n.map(s), m = n.map(d);
935
- let u = e.length;
936
- for (let p = 0; p < e.length; p++)
937
- if (e[p].fromA >= m) {
938
- u = p;
934
+ const l = !a.isLeaf && a.content.eq(i.content), c = l ? 1 : Math.min(a.nodeSize, i.nodeSize), u = s + c, m = n.map(s), p = n.map(u);
935
+ let d = e.length;
936
+ for (let f = 0; f < e.length; f++)
937
+ if (e[f].fromA >= p) {
938
+ d = f;
939
939
  break;
940
940
  }
941
- e.splice(u, 0, {
942
- fromA: f,
943
- toA: m,
941
+ e.splice(d, 0, {
942
+ fromA: m,
943
+ toA: p,
944
944
  fromB: s,
945
- toB: d,
945
+ toB: u,
946
946
  deleted: [],
947
947
  inserted: [],
948
948
  type: l ? "node-type-or-attr-update" : "mark-update"
949
949
  }), r.step(
950
- new _(
950
+ new N(
951
951
  s,
952
- d,
953
- o.slice(s, d),
952
+ u,
953
+ o.slice(s, u),
954
954
  l
955
955
  )
956
956
  );
@@ -991,7 +991,7 @@ const ye = (e, t) => {
991
991
  };
992
992
  };
993
993
  function W(e, t, o = !1, r, n) {
994
- const s = st(e.id, t), a = new D(t);
994
+ const s = Me(e.id, t), a = new D(t);
995
995
  it(
996
996
  a,
997
997
  s.posBeforeNode,
@@ -1005,14 +1005,14 @@ function W(e, t, o = !1, r, n) {
1005
1005
  ye(t, i)
1006
1006
  );
1007
1007
  if (l = l.addSteps(i, a.mapping.maps, 0), o && l.changes.length > 0) {
1008
- const f = l.changes[l.changes.length - 1], m = f.toA - f.fromA, u = f.toB - f.fromB;
1009
- if (m > u) {
1008
+ const m = l.changes[l.changes.length - 1], p = m.toA - m.fromA, d = m.toB - m.fromB;
1009
+ if (p > d) {
1010
1010
  const h = t.slice(
1011
- f.fromA + u,
1012
- f.toA
1011
+ m.fromA + d,
1012
+ m.toA
1013
1013
  );
1014
1014
  a.step(
1015
- new _(f.toB, f.toB, h)
1015
+ new N(m.toB, m.toB, h)
1016
1016
  ), i = a.doc, l = me.create(
1017
1017
  l.startDoc,
1018
1018
  void 0,
@@ -1020,45 +1020,45 @@ function W(e, t, o = !1, r, n) {
1020
1020
  ), l = l.addSteps(i, a.mapping.maps, 0);
1021
1021
  }
1022
1022
  }
1023
- const c = [], d = Pt(
1023
+ const c = [], u = Pt(
1024
1024
  l.changes,
1025
1025
  i
1026
1026
  );
1027
- for (let f = 0; f < d.length; f++) {
1028
- const m = d[f], u = i.slice(m.fromB, m.toB);
1029
- if (u.openEnd === 1 && u.openStart === 0 && (m.type = "node-type-or-attr-update", u.size > 2)) {
1027
+ for (let m = 0; m < u.length; m++) {
1028
+ const p = u[m], d = i.slice(p.fromB, p.toB);
1029
+ if (d.openEnd === 1 && d.openStart === 0 && (p.type = "node-type-or-attr-update", d.size > 2)) {
1030
1030
  const h = {
1031
- fromA: m.fromA,
1032
- toA: m.fromA + 1,
1033
- fromB: m.fromB,
1034
- toB: m.fromB + 1,
1031
+ fromA: p.fromA,
1032
+ toA: p.fromA + 1,
1033
+ fromB: p.fromB,
1034
+ toB: p.fromB + 1,
1035
1035
  deleted: [],
1036
1036
  inserted: [],
1037
1037
  type: "node-type-or-attr-update"
1038
- }, p = {
1039
- fromA: m.fromA + 1,
1040
- toA: m.toA,
1041
- fromB: m.fromB + 1,
1042
- toB: m.toB,
1038
+ }, f = {
1039
+ fromA: p.fromA + 1,
1040
+ toA: p.toA,
1041
+ fromB: p.fromB + 1,
1042
+ toB: p.toB,
1043
1043
  deleted: [],
1044
1044
  inserted: []
1045
1045
  };
1046
- d.splice(f, 1, h, p), f++;
1046
+ u.splice(m, 1, h, f), m++;
1047
1047
  }
1048
1048
  }
1049
- no(d, t, i);
1050
- for (let f = 0; f < d.length; f++) {
1051
- const m = d[f], u = i.slice(m.fromB, m.toB);
1052
- if (u.openEnd > 0 && u.size > 1)
1049
+ no(u, t, i);
1050
+ for (let m = 0; m < u.length; m++) {
1051
+ const p = u[m], d = i.slice(p.fromB, p.toB);
1052
+ if (d.openEnd > 0 && d.size > 1)
1053
1053
  throw new Error(
1054
1054
  "unexpected, openEnd > 0 and size > 1, this should have been split into two steps"
1055
1055
  );
1056
- f === d.length - 1 && o && m.type === "mark-update" || c.push(
1057
- new _(
1058
- m.fromA,
1059
- m.toA,
1060
- u,
1061
- m.type === "node-type-or-attr-update"
1056
+ m === u.length - 1 && o && p.type === "mark-update" || c.push(
1057
+ new N(
1058
+ p.fromA,
1059
+ p.toA,
1060
+ d,
1061
+ p.type === "node-type-or-attr-update"
1062
1062
  )
1063
1063
  );
1064
1064
  }
@@ -1173,36 +1173,36 @@ function re(e) {
1173
1173
  l.blocks[l.blocks.length - 1]
1174
1174
  ))
1175
1175
  return !0;
1176
- for (let d = 0; d < l.blocks.length; d++) {
1177
- const f = l.blocks[d], m = t.prosemirrorState.tr;
1178
- let u = [];
1179
- if (d < n.length) {
1180
- const h = await e.rebaseTool(n[d], t), k = W(
1176
+ for (let u = 0; u < l.blocks.length; u++) {
1177
+ const m = l.blocks[u], p = t.prosemirrorState.tr;
1178
+ let d = [];
1179
+ if (u < n.length) {
1180
+ const h = await e.rebaseTool(n[u], t), k = W(
1181
1181
  {
1182
- id: n[d],
1183
- block: f
1182
+ id: n[u],
1183
+ block: m
1184
1184
  },
1185
1185
  h.doc,
1186
1186
  !1
1187
1187
  ).map((b) => b.map(h.invertMap));
1188
1188
  for (const b of k)
1189
- m.step(b.map(m.mapping));
1190
- u = J(m), u = u.filter(
1189
+ p.step(b.map(p.mapping));
1190
+ d = J(p), d = d.filter(
1191
1191
  (b) => b.type !== "select"
1192
1192
  );
1193
1193
  } else {
1194
- const h = i.position === "after" ? s[i.referenceId] : void 0, p = at(
1195
- m,
1196
- [f],
1197
- d > 0 ? n[d - 1] : h || i.referenceId,
1198
- d > 0 ? "after" : i.position
1194
+ const h = i.position === "after" ? s[i.referenceId] : void 0, f = at(
1195
+ p,
1196
+ [m],
1197
+ u > 0 ? n[u - 1] : h || i.referenceId,
1198
+ u > 0 ? "after" : i.position
1199
1199
  );
1200
- n.push(...p.map((k) => k.id)), u = J(m);
1200
+ n.push(...f.map((k) => k.id)), d = J(p);
1201
1201
  }
1202
- for (const h of u)
1203
- o.withDelays && await te(h), t.transact((p) => {
1204
- oe(p, h);
1205
- }), (c = o.onBlockUpdate) == null || c.call(o, n[d]);
1202
+ for (const h of d)
1203
+ o.withDelays && await te(h), t.transact((f) => {
1204
+ oe(f, h);
1205
+ }), (c = o.onBlockUpdate) == null || c.call(o, n[u]);
1206
1206
  }
1207
1207
  return a.isPossiblyPartial || i.position === "after" && (s[i.referenceId] = n[n.length - 1]), !0;
1208
1208
  }
@@ -1291,25 +1291,25 @@ function ne(e) {
1291
1291
  s = g + 50;
1292
1292
  } else
1293
1293
  s = 50;
1294
- const c = await e.rebaseTool(l.id, t), d = a ? c.invertMap.invert().map(a.from()) : void 0, f = a ? c.invertMap.invert().map(a.to()) : void 0, m = await e.toJSONToolCall(t, {
1294
+ const c = await e.rebaseTool(l.id, t), u = a ? c.invertMap.invert().map(a.from()) : void 0, m = a ? c.invertMap.invert().map(a.to()) : void 0, p = await e.toJSONToolCall(t, {
1295
1295
  ...i,
1296
1296
  operation: l
1297
1297
  });
1298
- if (!m)
1298
+ if (!p)
1299
1299
  return !0;
1300
- const u = W(
1301
- m,
1300
+ const d = W(
1301
+ p,
1302
1302
  c.doc,
1303
1303
  i.isPossiblyPartial,
1304
- d,
1305
- f
1304
+ u,
1305
+ m
1306
1306
  );
1307
- if (u.length === 1 && i.isPossiblyPartial)
1307
+ if (d.length === 1 && i.isPossiblyPartial)
1308
1308
  return !0;
1309
- const h = u.map((g) => g.map(c.invertMap)), p = new D(t.prosemirrorState.doc);
1309
+ const h = d.map((g) => g.map(c.invertMap)), f = new D(t.prosemirrorState.doc);
1310
1310
  for (const g of h)
1311
- p.step(g.map(p.mapping));
1312
- const k = J(p);
1311
+ f.step(g.map(f.mapping));
1312
+ const k = J(f);
1313
1313
  for (const g of k)
1314
1314
  o.withDelays && await te(g), t.transact((v) => {
1315
1315
  oe(v, g);
@@ -1401,7 +1401,7 @@ function ge(e) {
1401
1401
  }
1402
1402
  function U(e) {
1403
1403
  let t;
1404
- if (_e(e.prosemirrorState, (o) => {
1404
+ if (Ne(e.prosemirrorState, (o) => {
1405
1405
  t = o;
1406
1406
  }), !t)
1407
1407
  throw new Error("applySuggestionsTr is not set");
@@ -1441,7 +1441,7 @@ function V(e, t) {
1441
1441
  }
1442
1442
  async function be(e, t) {
1443
1443
  var c;
1444
- const o = U(t), r = Me(o.doc, e);
1444
+ const o = U(t), r = Ee(o.doc, e);
1445
1445
  if (!r)
1446
1446
  throw new Error("block not found");
1447
1447
  const n = await t.blocksToHTMLLossy([
@@ -1576,24 +1576,24 @@ const ao = {
1576
1576
  * Helper functions which can be used when implementing a custom PromptBuilder
1577
1577
  */
1578
1578
  promptHelpers: {
1579
- getDataForPromptNoSelection: Je,
1580
- getDataForPromptWithSelection: Ue
1579
+ getDataForPromptNoSelection: Ue,
1580
+ getDataForPromptWithSelection: Ve
1581
1581
  }
1582
1582
  };
1583
1583
  async function lo(e) {
1584
1584
  return e.selectedBlocks ? {
1585
- ...await Fe(e.editor, {
1585
+ ...await Re(e.editor, {
1586
1586
  selectedBlocks: e.selectedBlocks
1587
1587
  }),
1588
1588
  userPrompt: e.userPrompt
1589
1589
  } : {
1590
- ...await Ve(e.editor, {
1590
+ ...await Fe(e.editor, {
1591
1591
  excludeBlockIds: e.emptyCursorBlockToDelete ? [e.emptyCursorBlockToDelete] : void 0
1592
1592
  }),
1593
1593
  userPrompt: e.userPrompt
1594
1594
  };
1595
1595
  }
1596
- async function Ve(e, t) {
1596
+ async function Fe(e, t) {
1597
1597
  const o = w(e.document).length === 0, r = e.getTextCursorPosition().block.id, n = w(e.document, {
1598
1598
  cursorBlockId: r
1599
1599
  }), s = await P(
@@ -1607,15 +1607,15 @@ async function Ve(e, t) {
1607
1607
  );
1608
1608
  return {
1609
1609
  selection: !1,
1610
- jsonBlocks: E(i),
1610
+ jsonBlocks: _(i),
1611
1611
  isEmptyDocument: o
1612
1612
  };
1613
1613
  }
1614
- async function Fe(e, t) {
1614
+ async function Re(e, t) {
1615
1615
  const o = w(e.document).length === 0, r = await P(
1616
1616
  T(t.selectedBlocks),
1617
1617
  async (s) => s
1618
- ), n = E(r);
1618
+ ), n = _(r);
1619
1619
  return {
1620
1620
  isEmptyDocument: o,
1621
1621
  selection: !0,
@@ -1683,7 +1683,7 @@ function po() {
1683
1683
  required: ["type", "text"]
1684
1684
  };
1685
1685
  }
1686
- function Re(e) {
1686
+ function Ze(e) {
1687
1687
  return {
1688
1688
  type: "object",
1689
1689
  properties: Object.fromEntries(
@@ -1736,7 +1736,7 @@ function mo(e) {
1736
1736
  $ref: "#/$defs/styledtext"
1737
1737
  }
1738
1738
  } : void 0,
1739
- props: Re(o.propSchema)
1739
+ props: Ze(o.propSchema)
1740
1740
  },
1741
1741
  additionalProperties: !1,
1742
1742
  required: ["type", ...o.content === "styled" ? ["content"] : []]
@@ -1756,7 +1756,7 @@ function fo(e) {
1756
1756
  },
1757
1757
  content: o.content === "inline" ? { $ref: "#/$defs/inlinecontent" } : o.content === "table" ? { type: "object", properties: {} } : void 0,
1758
1758
  // filter out default props (TODO: make option)
1759
- props: Re(o.propSchema)
1759
+ props: Ze(o.propSchema)
1760
1760
  // Object.fromEntries(
1761
1761
  // Object.entries(val.propSchema).filter(
1762
1762
  // (key) => typeof (defaultProps as any)[key[0]] === "undefined"
@@ -1799,7 +1799,7 @@ function ho(e) {
1799
1799
  ...r,
1800
1800
  propSchema: Object.fromEntries(
1801
1801
  Object.entries(r.propSchema).filter(
1802
- (n) => typeof Ee[n[0]] > "u"
1802
+ (n) => typeof _e[n[0]] > "u"
1803
1803
  )
1804
1804
  )
1805
1805
  }
@@ -1823,8 +1823,8 @@ function Se(e) {
1823
1823
  }
1824
1824
  };
1825
1825
  }
1826
- function Ze(e, t) {
1827
- return !t.schema.inlineContentSchema[e.type] || ct(e) && !("text" in e) ? !1 : ut(e) ? !("content" in e) || !("href" in e) ? !1 : Ze(e.content, t) : !0;
1826
+ function We(e, t) {
1827
+ return !t.schema.inlineContentSchema[e.type] || ct(e) && !("text" in e) ? !1 : ut(e) ? !("content" in e) || !("href" in e) ? !1 : We(e.content, t) : !0;
1828
1828
  }
1829
1829
  function we(e, t, o) {
1830
1830
  const r = e.type || o, n = t.schema.blockSchema[r];
@@ -1855,7 +1855,7 @@ function we(e, t, o) {
1855
1855
  ok: !0,
1856
1856
  value: e
1857
1857
  };
1858
- if (!e.content.every((s) => Ze(s, t)))
1858
+ if (!e.content.every((s) => We(s, t)))
1859
1859
  return {
1860
1860
  ok: !1,
1861
1861
  error: "block content must be an array of inline content"
@@ -1891,7 +1891,7 @@ const q = {
1891
1891
  rebaseTool: async (e, t) => V(t, U(t)),
1892
1892
  toJSONToolCall: async (e, t) => {
1893
1893
  const o = Object.fromEntries(
1894
- Object.entries(Ee).map(([r, n]) => [r, n.default])
1894
+ Object.entries(_e).map(([r, n]) => [r, n.default])
1895
1895
  );
1896
1896
  return {
1897
1897
  ...t.operation,
@@ -2101,24 +2101,24 @@ const So = {
2101
2101
  * Helper functions which can be used when implementing a custom PromptBuilder
2102
2102
  */
2103
2103
  promptHelpers: {
2104
- getDataForPromptNoSelection: Ve,
2105
- getDataForPromptWithSelection: Fe
2104
+ getDataForPromptNoSelection: Fe,
2105
+ getDataForPromptWithSelection: Re
2106
2106
  }
2107
2107
  };
2108
2108
  async function wo(e) {
2109
2109
  return e.selectedBlocks ? {
2110
- ...await Ye(e.editor, {
2110
+ ...await Ge(e.editor, {
2111
2111
  selectedBlocks: e.selectedBlocks
2112
2112
  }),
2113
2113
  userPrompt: e.userPrompt
2114
2114
  } : {
2115
- ...await We(e.editor, {
2115
+ ...await Ye(e.editor, {
2116
2116
  excludeBlockIds: e.emptyCursorBlockToDelete ? [e.emptyCursorBlockToDelete] : void 0
2117
2117
  }),
2118
2118
  userPrompt: e.userPrompt
2119
2119
  };
2120
2120
  }
2121
- async function We(e, t) {
2121
+ async function Ye(e, t) {
2122
2122
  const o = w(e.document).length === 0, r = e.getTextCursorPosition().block.id, n = w(e.document, {
2123
2123
  cursorBlockId: r
2124
2124
  }), s = await P(
@@ -2129,15 +2129,15 @@ async function We(e, t) {
2129
2129
  );
2130
2130
  return {
2131
2131
  selection: !1,
2132
- markdownBlocks: E(i),
2132
+ markdownBlocks: _(i),
2133
2133
  isEmptyDocument: o
2134
2134
  };
2135
2135
  }
2136
- async function Ye(e, t) {
2136
+ async function Ge(e, t) {
2137
2137
  const o = w(e.document).length === 0, r = await P(
2138
2138
  T(t.selectedBlocks),
2139
2139
  async (s) => e.blocksToMarkdownLossy([s])
2140
- ), n = E(r);
2140
+ ), n = _(r);
2141
2141
  return {
2142
2142
  isEmptyDocument: o,
2143
2143
  selection: !0,
@@ -2147,13 +2147,13 @@ async function Ye(e, t) {
2147
2147
  };
2148
2148
  }
2149
2149
  async function Te(e, t) {
2150
- const o = U(t), r = await t.blocksToMarkdownLossy([Me(o.doc, e)]), n = await t.tryParseMarkdownToBlocks(r), s = W(
2150
+ const o = U(t), r = await t.blocksToMarkdownLossy([Ee(o.doc, e)]), n = await t.tryParseMarkdownToBlocks(r), s = W(
2151
2151
  {
2152
2152
  id: e,
2153
2153
  block: n[0]
2154
2154
  },
2155
2155
  o.doc
2156
- ), a = new De();
2156
+ ), a = new je();
2157
2157
  for (const i of s) {
2158
2158
  const l = i.map(a);
2159
2159
  if (!l)
@@ -2413,8 +2413,8 @@ const Co = {
2413
2413
  * Helper functions which can be used when implementing a custom PromptBuilder
2414
2414
  */
2415
2415
  promptHelpers: {
2416
- getDataForPromptNoSelection: We,
2417
- getDataForPromptWithSelection: Ye
2416
+ getDataForPromptNoSelection: Ye,
2417
+ getDataForPromptWithSelection: Ge
2418
2418
  }
2419
2419
  }, O = {
2420
2420
  _experimental_json: So,
@@ -2423,12 +2423,12 @@ const Co = {
2423
2423
  }, xr = {
2424
2424
  addCursorPosition: Z,
2425
2425
  flattenBlocks: T,
2426
- suffixIDs: E,
2426
+ suffixIDs: _,
2427
2427
  trimEmptyBlocks: w,
2428
2428
  convertBlocks: P
2429
- }, ve = new Le("blocknote-agent-cursor");
2429
+ }, ve = new Ae("blocknote-agent-cursor");
2430
2430
  function Oo(e) {
2431
- return new Ne({
2431
+ return new Le({
2432
2432
  key: ve,
2433
2433
  view: (t) => ({}),
2434
2434
  state: {
@@ -2473,27 +2473,29 @@ const Io = (e) => {
2473
2473
  o.setAttribute("contentedEditable", "false"), o.classList.add("bn-collaboration-cursor__caret"), o.setAttribute("style", `background-color: ${e.color}`);
2474
2474
  const r = document.createElement("span");
2475
2475
  return r.classList.add("bn-collaboration-cursor__label"), r.setAttribute("style", `background-color: ${e.color}`), r.insertBefore(document.createTextNode(e.name), null), o.insertBefore(r, null), t.insertBefore(document.createTextNode("⁠"), null), t.insertBefore(o, null), t.insertBefore(document.createTextNode("⁠"), null), t;
2476
- }, Bo = new Le("blocknote-ai-plugin");
2477
- class Ge extends dt {
2476
+ }, Bo = new Ae("blocknote-ai-plugin");
2477
+ class Ke extends dt {
2478
2478
  /**
2479
2479
  * @internal use `createAIExtension` instead
2480
2480
  */
2481
2481
  constructor(o, r) {
2482
2482
  super();
2483
- L(this, "chatSession");
2483
+ M(this, "chatSession");
2484
+ M(this, "scrollInProgress", !1);
2485
+ M(this, "autoScroll", !1);
2484
2486
  // internal store including setters
2485
- L(this, "_store", he()((o) => ({
2487
+ M(this, "_store", he()((o) => ({
2486
2488
  aiMenuState: "closed"
2487
2489
  })));
2488
2490
  /**
2489
2491
  * Returns a zustand store with the global configuration of the AI Extension.
2490
2492
  * These options are used by default across all LLM calls when calling {@link executeLLMRequest}
2491
2493
  */
2492
- L(this, "options");
2494
+ M(this, "options");
2493
2495
  this.editor = o, this.options = he()((n) => ({
2494
2496
  ...r
2495
2497
  })), this.addProsemirrorPlugin(
2496
- new Ne({
2498
+ new Le({
2497
2499
  key: Bo,
2498
2500
  filterTransaction: (n) => {
2499
2501
  var a;
@@ -2505,6 +2507,18 @@ class Ge extends dt {
2505
2507
  Oo(
2506
2508
  r.agentCursor || { name: "AI", color: "#8bc6ff" }
2507
2509
  )
2510
+ ), document.addEventListener(
2511
+ "scroll",
2512
+ () => {
2513
+ this.scrollInProgress && (this.autoScroll = !1), this.scrollInProgress = !0;
2514
+ },
2515
+ !0
2516
+ ), document.addEventListener(
2517
+ "scrollend",
2518
+ () => {
2519
+ this.scrollInProgress = !1;
2520
+ },
2521
+ !0
2508
2522
  );
2509
2523
  }
2510
2524
  static key() {
@@ -2520,12 +2534,17 @@ class Ge extends dt {
2520
2534
  * Open the AI menu at a specific block
2521
2535
  */
2522
2536
  openAIMenuAtBlock(o) {
2537
+ var n;
2523
2538
  this.editor.setForceSelectionVisible(!0), this.editor.isEditable = !1, this._store.setState({
2524
2539
  aiMenuState: {
2525
2540
  blockId: o,
2526
2541
  status: "user-input"
2527
2542
  }
2528
2543
  });
2544
+ const r = (n = this.editor.domElement) == null ? void 0 : n.querySelector(
2545
+ `[data-node-type="blockContainer"][data-id="${o}"]`
2546
+ );
2547
+ r == null || r.scrollIntoView({ block: "center" });
2529
2548
  }
2530
2549
  /**
2531
2550
  * Close the AI menu
@@ -2551,7 +2570,7 @@ class Ge extends dt {
2551
2570
  new G(ce.from(o), 0, 0)
2552
2571
  );
2553
2572
  const i = n.apply(a);
2554
- return _e(i, (l) => {
2573
+ return Ne(i, (l) => {
2555
2574
  s == null || s(
2556
2575
  a.replace(
2557
2576
  0,
@@ -2632,7 +2651,7 @@ class Ge extends dt {
2632
2651
  try {
2633
2652
  this.chatSession ? this.chatSession.previousRequestOptions = o : this.chatSession = {
2634
2653
  previousRequestOptions: o,
2635
- chat: new rt({
2654
+ chat: new nt({
2636
2655
  sendAutomaticallyWhen: () => !1,
2637
2656
  transport: o.transport || this.options.getState().transport
2638
2657
  })
@@ -2653,11 +2672,26 @@ class Ge extends dt {
2653
2672
  deleteEmptyCursorBlock: o.deleteEmptyCursorBlock,
2654
2673
  streamToolsProvider: o.streamToolsProvider,
2655
2674
  onBlockUpdated: (c) => {
2656
- this._store.setState({
2675
+ if (this._store.setState({
2657
2676
  aiMenuState: {
2658
2677
  blockId: c,
2659
2678
  status: "ai-writing"
2660
2679
  }
2680
+ }), !this.autoScroll)
2681
+ return;
2682
+ const u = this._store.getState().aiMenuState, m = u === "closed" ? void 0 : u;
2683
+ if (!m || m.status !== "ai-writing")
2684
+ return;
2685
+ const p = Me(
2686
+ m.blockId,
2687
+ this.editor.prosemirrorState.doc
2688
+ );
2689
+ if (!p)
2690
+ return;
2691
+ this.editor.prosemirrorView.domAtPos(
2692
+ p.posBeforeNode + 1
2693
+ ).node.scrollIntoView({
2694
+ block: "center"
2661
2695
  });
2662
2696
  }
2663
2697
  });
@@ -2666,7 +2700,7 @@ class Ge extends dt {
2666
2700
  sender: i,
2667
2701
  chatRequestOptions: o.chatRequestOptions,
2668
2702
  onStart: () => {
2669
- this.setAIResponseStatus("ai-writing");
2703
+ this.autoScroll = !0, this.setAIResponseStatus("ai-writing");
2670
2704
  }
2671
2705
  }), this.setAIResponseStatus("user-reviewing");
2672
2706
  } catch (s) {
@@ -2678,10 +2712,10 @@ class Ge extends dt {
2678
2712
  }
2679
2713
  }
2680
2714
  function vr(e) {
2681
- return (t) => new Ge(t, e);
2715
+ return (t) => new Ke(t, e);
2682
2716
  }
2683
2717
  function I(e) {
2684
- return e.extension(Ge);
2718
+ return e.extension(Ke);
2685
2719
  }
2686
2720
  const Pr = (e) => async (t, o) => {
2687
2721
  const r = new Request(t, o), n = e(r.url), s = new Request(n, {
@@ -2694,13 +2728,13 @@ const Pr = (e) => async (t, o) => {
2694
2728
  });
2695
2729
  return await fetch(s);
2696
2730
  };
2697
- var Ke = {
2731
+ var Xe = {
2698
2732
  color: void 0,
2699
2733
  size: void 0,
2700
2734
  className: void 0,
2701
2735
  style: void 0,
2702
2736
  attr: void 0
2703
- }, Pe = M.createContext && /* @__PURE__ */ M.createContext(Ke), Mo = ["attr", "size", "title"];
2737
+ }, Pe = E.createContext && /* @__PURE__ */ E.createContext(Xe), Mo = ["attr", "size", "title"];
2704
2738
  function Eo(e, t) {
2705
2739
  if (e == null) return {};
2706
2740
  var o = _o(e, t), r, n;
@@ -2769,15 +2803,15 @@ function Ao(e, t) {
2769
2803
  }
2770
2804
  return (t === "string" ? String : Number)(e);
2771
2805
  }
2772
- function Xe(e) {
2773
- return e && e.map((t, o) => /* @__PURE__ */ M.createElement(t.tag, R({
2806
+ function Qe(e) {
2807
+ return e && e.map((t, o) => /* @__PURE__ */ E.createElement(t.tag, R({
2774
2808
  key: o
2775
- }, t.attr), Xe(t.child)));
2809
+ }, t.attr), Qe(t.child)));
2776
2810
  }
2777
2811
  function x(e) {
2778
- return (t) => /* @__PURE__ */ M.createElement(Do, F({
2812
+ return (t) => /* @__PURE__ */ E.createElement(Do, F({
2779
2813
  attr: R({}, e.attr)
2780
- }, t), Xe(e.child));
2814
+ }, t), Qe(e.child));
2781
2815
  }
2782
2816
  function Do(e) {
2783
2817
  var t = (o) => {
@@ -2786,7 +2820,7 @@ function Do(e) {
2786
2820
  size: n,
2787
2821
  title: s
2788
2822
  } = e, a = Eo(e, Mo), i = n || o.size || "1em", l;
2789
- return o.className && (l = o.className), e.className && (l = (l ? l + " " : "") + e.className), /* @__PURE__ */ M.createElement("svg", F({
2823
+ return o.className && (l = o.className), e.className && (l = (l ? l + " " : "") + e.className), /* @__PURE__ */ E.createElement("svg", F({
2790
2824
  stroke: "currentColor",
2791
2825
  fill: "currentColor",
2792
2826
  strokeWidth: "0"
@@ -2798,11 +2832,11 @@ function Do(e) {
2798
2832
  height: i,
2799
2833
  width: i,
2800
2834
  xmlns: "http://www.w3.org/2000/svg"
2801
- }), s && /* @__PURE__ */ M.createElement("title", null, s), e.children);
2835
+ }), s && /* @__PURE__ */ E.createElement("title", null, s), e.children);
2802
2836
  };
2803
- return Pe !== void 0 ? /* @__PURE__ */ M.createElement(Pe.Consumer, null, (o) => t(o)) : t(Ke);
2837
+ return Pe !== void 0 ? /* @__PURE__ */ E.createElement(Pe.Consumer, null, (o) => t(o)) : t(Xe);
2804
2838
  }
2805
- function Qe(e) {
2839
+ function et(e) {
2806
2840
  return x({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M8 7V11L2 6L8 1V5H13C17.4183 5 21 8.58172 21 13C21 17.4183 17.4183 21 13 21H4V19H13C16.3137 19 19 16.3137 19 13C19 9.68629 16.3137 7 13 7H8Z" }, child: [] }] })(e);
2807
2841
  }
2808
2842
  function Oe(e) {
@@ -2835,36 +2869,36 @@ function Vo(e) {
2835
2869
  function ie(e) {
2836
2870
  return x({ attr: { viewBox: "0 0 24 24", fill: "currentColor" }, child: [{ tag: "path", attr: { d: "M17.0007 1.20825 18.3195 3.68108 20.7923 4.99992 18.3195 6.31876 17.0007 8.79159 15.6818 6.31876 13.209 4.99992 15.6818 3.68108 17.0007 1.20825ZM8.00065 4.33325 10.6673 9.33325 15.6673 11.9999 10.6673 14.6666 8.00065 19.6666 5.33398 14.6666.333984 11.9999 5.33398 9.33325 8.00065 4.33325ZM19.6673 16.3333 18.0007 13.2083 16.334 16.3333 13.209 17.9999 16.334 19.6666 18.0007 22.7916 19.6673 19.6666 22.7923 17.9999 19.6673 16.3333Z" }, child: [] }] })(e);
2837
2871
  }
2838
- function N(e) {
2872
+ function L(e) {
2839
2873
  if (!e.dictionary.ai)
2840
2874
  throw new Error("AI dictionary not found");
2841
2875
  return e.dictionary.ai;
2842
2876
  }
2843
- function et() {
2877
+ function tt() {
2844
2878
  const e = Ot();
2845
- return N(e.editor);
2879
+ return L(e.editor);
2846
2880
  }
2847
2881
  const Fo = (e) => {
2848
- const t = X(), { onManualPromptSubmit: o, promptText: r, onPromptTextChange: n } = e, [s, a] = je(""), i = r || s, l = $(
2849
- async (p) => {
2850
- p.key === "Enter" && o(i);
2882
+ const t = X(), { onManualPromptSubmit: o, promptText: r, onPromptTextChange: n } = e, [s, a] = $e(""), i = r || s, l = $(
2883
+ async (f) => {
2884
+ f.key === "Enter" && o(i);
2851
2885
  },
2852
2886
  [i, o]
2853
2887
  ), c = $(
2854
- (p) => {
2855
- const k = p.currentTarget.value;
2888
+ (f) => {
2889
+ const k = f.currentTarget.value;
2856
2890
  n && n(k), r === void 0 && a(k);
2857
2891
  },
2858
2892
  [n, a, r]
2859
- ), d = A(() => pt(e.items, i), [i, e.items]), { selectedIndex: f, setSelectedIndex: m, handler: u } = It(d, (p) => p.onItemClick()), h = $(
2860
- (p) => {
2861
- p.key === "Enter" ? d.length > 0 ? u(p) : l(p) : u(p);
2893
+ ), u = A(() => pt(e.items, i), [i, e.items]), { selectedIndex: m, setSelectedIndex: p, handler: d } = It(u, (f) => f.onItemClick()), h = $(
2894
+ (f) => {
2895
+ f.key === "Enter" ? u.length > 0 ? d(f) : l(f) : d(f);
2862
2896
  },
2863
- [l, u, d.length]
2897
+ [l, d, u.length]
2864
2898
  );
2865
- return $e(() => {
2866
- m(0);
2867
- }, [i, m]), /* @__PURE__ */ Ct("div", { className: "bn-combobox", children: [
2899
+ return He(() => {
2900
+ p(0);
2901
+ }, [i, p]), /* @__PURE__ */ Ct("div", { className: "bn-combobox", children: [
2868
2902
  /* @__PURE__ */ y(t.Generic.Form.Root, { children: /* @__PURE__ */ y(
2869
2903
  t.Generic.Form.TextInput,
2870
2904
  {
@@ -2888,26 +2922,26 @@ const Fo = (e) => {
2888
2922
  {
2889
2923
  className: "bn-combobox-items",
2890
2924
  id: "ai-suggestion-menu",
2891
- children: d.map((p, k) => /* @__PURE__ */ y(
2925
+ children: u.map((f, k) => /* @__PURE__ */ y(
2892
2926
  t.SuggestionMenu.Item,
2893
2927
  {
2894
2928
  className: mt(
2895
2929
  "bn-suggestion-menu-item",
2896
- p.size === "small" ? "bn-suggestion-menu-item-small" : ""
2930
+ f.size === "small" ? "bn-suggestion-menu-item-small" : ""
2897
2931
  ),
2898
2932
  id: `bn-suggestion-menu-item-${k}`,
2899
- isSelected: k === f,
2900
- onClick: p.onItemClick,
2901
- item: p
2933
+ isSelected: k === m,
2934
+ onClick: f.onItemClick,
2935
+ item: f
2902
2936
  },
2903
- p.title
2937
+ f.title
2904
2938
  ))
2905
2939
  }
2906
2940
  )
2907
2941
  ] });
2908
2942
  };
2909
2943
  function Ro(e) {
2910
- const t = N(e), o = I(e);
2944
+ const t = L(e), o = I(e);
2911
2945
  return [
2912
2946
  {
2913
2947
  key: "continue_writing",
@@ -2982,7 +3016,7 @@ function Ro(e) {
2982
3016
  ];
2983
3017
  }
2984
3018
  function Zo(e) {
2985
- const t = N(e), o = I(e);
3019
+ const t = L(e), o = I(e);
2986
3020
  return [
2987
3021
  {
2988
3022
  key: "improve_writing",
@@ -3060,7 +3094,7 @@ function Zo(e) {
3060
3094
  ];
3061
3095
  }
3062
3096
  function Wo(e) {
3063
- const t = N(e), o = I(e);
3097
+ const t = L(e), o = I(e);
3064
3098
  return [
3065
3099
  {
3066
3100
  key: "accept",
@@ -3076,7 +3110,7 @@ function Wo(e) {
3076
3110
  key: "revert",
3077
3111
  title: t.ai_menu.actions.revert.title,
3078
3112
  aliases: t.ai_menu.actions.revert.aliases,
3079
- icon: /* @__PURE__ */ y(Qe, { size: 18 }),
3113
+ icon: /* @__PURE__ */ y(et, { size: 18 }),
3080
3114
  onItemClick: () => {
3081
3115
  o.rejectChanges();
3082
3116
  },
@@ -3085,7 +3119,7 @@ function Wo(e) {
3085
3119
  ];
3086
3120
  }
3087
3121
  function Yo(e) {
3088
- const t = N(e), o = I(e);
3122
+ const t = L(e), o = I(e);
3089
3123
  return [
3090
3124
  {
3091
3125
  key: "retry",
@@ -3101,7 +3135,7 @@ function Yo(e) {
3101
3135
  key: "cancel",
3102
3136
  title: t.ai_menu.actions.cancel.title,
3103
3137
  aliases: t.ai_menu.actions.cancel.aliases,
3104
- icon: /* @__PURE__ */ y(Qe, { size: 18 }),
3138
+ icon: /* @__PURE__ */ y(et, { size: 18 }),
3105
3139
  onItemClick: () => {
3106
3140
  o.rejectChanges();
3107
3141
  },
@@ -3113,30 +3147,30 @@ function Go(e, t) {
3113
3147
  return t === "user-input" ? e.getSelection() ? Zo(e) : Ro(e) : t === "user-reviewing" ? Wo(e) : t === "error" ? Yo(e) : [];
3114
3148
  }
3115
3149
  const Ko = (e) => {
3116
- const t = Q(), [o, r] = je(""), n = et(), s = X(), a = I(t), i = He(
3150
+ const t = Q(), [o, r] = $e(""), n = tt(), s = X(), a = I(t), i = qe(
3117
3151
  a.store,
3118
- (u) => u.aiMenuState !== "closed" ? u.aiMenuState.status : "closed"
3152
+ (d) => d.aiMenuState !== "closed" ? d.aiMenuState.status : "closed"
3119
3153
  ), { items: l } = e, c = A(() => {
3120
- let u = [];
3121
- return l ? u = l(t, i) : u = Go(t, i), u.map((h) => ({
3154
+ let d = [];
3155
+ return l ? d = l(t, i) : d = Go(t, i), d.map((h) => ({
3122
3156
  ...h,
3123
3157
  onItemClick: () => {
3124
3158
  h.onItemClick(r);
3125
3159
  }
3126
3160
  }));
3127
- }, [l, i, t]), d = $(
3128
- async (u) => {
3161
+ }, [l, i, t]), u = $(
3162
+ async (d) => {
3129
3163
  await a.invokeAI({
3130
- userPrompt: u,
3164
+ userPrompt: d,
3131
3165
  useSelection: t.getSelection() !== void 0
3132
3166
  });
3133
3167
  },
3134
3168
  [a, t]
3135
3169
  );
3136
- $e(() => {
3170
+ He(() => {
3137
3171
  (i === "user-reviewing" || i === "error") && r("");
3138
3172
  }, [i]);
3139
- const f = A(() => i === "thinking" ? n.ai_menu.status.thinking : i === "ai-writing" ? n.ai_menu.status.editing : i === "error" ? n.ai_menu.status.error : n.ai_menu.input_placeholder, [i, n]), m = A(() => {
3173
+ const m = A(() => i === "thinking" ? n.ai_menu.status.thinking : i === "ai-writing" ? n.ai_menu.status.editing : i === "error" ? n.ai_menu.status.error : n.ai_menu.input_placeholder, [i, n]), p = A(() => {
3140
3174
  if (i === "thinking" || i === "ai-writing")
3141
3175
  return /* @__PURE__ */ y(
3142
3176
  s.SuggestionMenu.Loader,
@@ -3160,14 +3194,14 @@ const Ko = (e) => {
3160
3194
  return /* @__PURE__ */ y(
3161
3195
  Fo,
3162
3196
  {
3163
- onManualPromptSubmit: e.onManualPromptSubmit || d,
3197
+ onManualPromptSubmit: e.onManualPromptSubmit || u,
3164
3198
  items: c,
3165
3199
  promptText: o,
3166
3200
  onPromptTextChange: r,
3167
- placeholder: f,
3201
+ placeholder: m,
3168
3202
  disabled: i === "thinking" || i === "ai-writing",
3169
3203
  icon: /* @__PURE__ */ y("div", { className: "bn-combobox-icon", children: /* @__PURE__ */ y(ie, {}) }),
3170
- rightSection: m
3204
+ rightSection: p
3171
3205
  }
3172
3206
  );
3173
3207
  }, Xo = (e) => {
@@ -3193,7 +3227,7 @@ const Ko = (e) => {
3193
3227
  })
3194
3228
  ],
3195
3229
  onOpenChange: e.onOpenChange,
3196
- whileElementsMounted: (l, c, d) => _t(l, c, d, {
3230
+ whileElementsMounted: (l, c, u) => _t(l, c, u, {
3197
3231
  animationFrame: !0
3198
3232
  }),
3199
3233
  ...e.floatingOptions
@@ -3210,7 +3244,7 @@ const Ko = (e) => {
3210
3244
  }
3211
3245
  ) : null;
3212
3246
  }, Cr = (e) => {
3213
- const t = Q(), o = I(t), r = He(o.store, (a) => a.aiMenuState), n = r === "closed" ? void 0 : r.blockId, s = e.aiMenu || Ko;
3247
+ const t = Q(), o = I(t), r = qe(o.store, (a) => a.aiMenuState), n = r === "closed" ? void 0 : r.blockId, s = e.aiMenu || Ko;
3214
3248
  return /* @__PURE__ */ y(
3215
3249
  Xo,
3216
3250
  {
@@ -3223,7 +3257,7 @@ const Ko = (e) => {
3223
3257
  }
3224
3258
  );
3225
3259
  }, Or = () => {
3226
- const e = et(), t = X(), o = Q(), r = I(o), n = () => {
3260
+ const e = tt(), t = X(), o = Q(), r = I(o), n = () => {
3227
3261
  o.formattingToolbar.closeMenu();
3228
3262
  const s = o.getSelection();
3229
3263
  if (!s)
@@ -3254,7 +3288,7 @@ function Ir(e) {
3254
3288
  r.block.content && Array.isArray(r.block.content) && // isarray check not ideal
3255
3289
  r.block.content.length === 0 && r.prevBlock ? t.openAIMenuAtBlock(r.prevBlock.id) : t.openAIMenuAtBlock(r.block.id);
3256
3290
  },
3257
- ...N(e).slash_menu.ai,
3291
+ ...L(e).slash_menu.ai,
3258
3292
  icon: /* @__PURE__ */ y(Qo.AI, {})
3259
3293
  }
3260
3294
  ];
@@ -3436,12 +3470,12 @@ class Br {
3436
3470
  }
3437
3471
  }
3438
3472
  export {
3439
- Ge as AIExtension,
3473
+ Ke as AIExtension,
3440
3474
  Ko as AIMenu,
3441
3475
  Cr as AIMenuController,
3442
3476
  Or as AIToolbarButton,
3443
3477
  Xo as BlockPositioner,
3444
- qe as ChunkExecutionError,
3478
+ ze as ChunkExecutionError,
3445
3479
  Br as ClientSideTransport,
3446
3480
  rr as PROVIDER_OVERRIDES,
3447
3481
  Fo as PromptSuggestionMenu,
@@ -3453,7 +3487,7 @@ export {
3453
3487
  At as defaultAIRequestSender,
3454
3488
  Xt as executeAIRequest,
3455
3489
  Pr as fetchViaProxy,
3456
- N as getAIDictionary,
3490
+ L as getAIDictionary,
3457
3491
  I as getAIExtension,
3458
3492
  Ir as getAISlashMenuItems,
3459
3493
  Go as getDefaultAIMenuItems,