@blocknote/xl-ai 0.31.0 → 0.32.0-hackdays.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,8 @@ var j = (e, t, o) => tt(e, typeof t != "symbol" ? t + "" : t, o);
4
4
  import { getPmSchema as ot, UnreachableCaseError as Pe, getNodeById as rt, updateBlockTr as nt, insertBlocks as st, trackPosition as se, removeAndInsertBlocks as it, getBlock as Oe, defaultProps as Me, isStyledTextInlineContent as at, isLinkInlineContent as ct, BlockNoteExtension as lt, filterSuggestionItems as ut, mergeCSSClasses as dt } from "@blocknote/core";
5
5
  import { applySuggestions as Be, suggestChanges as ft, revertSuggestions as ie } from "@blocknote/prosemirror-suggest-changes";
6
6
  import { jsonSchema as Le, streamObject as pt, generateObject as mt, APICallError as ht, RetryError as yt } from "ai";
7
- import { TextSelection as gt, Plugin as xe, PluginKey as _e } from "prosemirror-state";
8
- import { fixTablesKey as kt } from "prosemirror-tables";
7
+ import { TextSelection as kt, Plugin as xe, PluginKey as _e } from "prosemirror-state";
8
+ import { fixTablesKey as gt } from "prosemirror-tables";
9
9
  import bt from "lodash.isequal";
10
10
  import { Slice as Y, Fragment as ae } from "prosemirror-model";
11
11
  import { Transform as N, Mapping as Ie, ReplaceStep as x, ReplaceAroundStep as St } from "prosemirror-transform";
@@ -611,29 +611,29 @@ function D(e) {
611
611
  );
612
612
  } else
613
613
  throw new Error("Step is not a ReplaceStep or ReplaceAroundStep");
614
- const b = c.map(s.from), g = s.slice.content.firstChild, k = n.doc.resolve(n.mapping.map(b)).nodeAfter;
615
- let w = g.marks || [];
616
- g.type !== k.type && (w = o.create({
614
+ const b = c.map(s.from), k = s.slice.content.firstChild, g = n.doc.resolve(n.mapping.map(b)).nodeAfter;
615
+ let w = k.marks || [];
616
+ k.type !== g.type && (w = o.create({
617
617
  type: "nodeType",
618
- previousValue: k.type.name,
619
- newValue: g.type.name
618
+ previousValue: g.type.name,
619
+ newValue: k.type.name
620
620
  }).addToSet(w));
621
621
  const A = /* @__PURE__ */ new Set([
622
- ...Object.keys(g.attrs),
623
- ...Object.keys(k.attrs)
622
+ ...Object.keys(k.attrs),
623
+ ...Object.keys(g.attrs)
624
624
  ]);
625
625
  for (const P of A)
626
- g.attrs[P] !== k.attrs[P] && (w = o.create({
626
+ k.attrs[P] !== g.attrs[P] && (w = o.create({
627
627
  type: "attr",
628
628
  attrName: P,
629
- previousValue: k.attrs[P],
630
- newValue: g.attrs[P]
629
+ previousValue: g.attrs[P],
630
+ newValue: k.attrs[P]
631
631
  }).addToSet(w));
632
632
  const M = n.steps.length;
633
633
  n.setNodeMarkup(
634
634
  n.mapping.map(b),
635
- g.type,
636
- g.attrs,
635
+ k.type,
636
+ k.attrs,
637
637
  w
638
638
  ), r.push({
639
639
  prosemirrorSteps: n.steps.slice(M),
@@ -673,8 +673,8 @@ function D(e) {
673
673
  const d = n.mapping.map(p);
674
674
  let S = !0;
675
675
  for (let b = f; b <= s.slice.content.size; b++) {
676
- const g = S && u !== p, k = n.steps.length;
677
- if (g) {
676
+ const k = S && u !== p, g = n.steps.length;
677
+ if (k) {
678
678
  const M = n.doc.resolve(n.mapping.map(u));
679
679
  (i = M.nodeAfter) != null && i.isBlock && n.addNodeMark(M.pos, t.mark("deletion", {})), n.addMark(M.pos, h, t.mark("deletion", {})), h = n.mapping.map(p);
680
680
  }
@@ -687,18 +687,18 @@ function D(e) {
687
687
  d,
688
688
  d + w.content.size,
689
689
  (M, P) => P < d || P > d + w.content.size ? !0 : (M.isBlock && n.addNodeMark(P, t.mark("insertion", {})), !1)
690
- ), h = n.mapping.slice(k).map(h);
691
- const A = gt.near(
690
+ ), h = n.mapping.slice(g).map(h);
691
+ const A = kt.near(
692
692
  n.doc.resolve(d + w.content.size),
693
693
  -1
694
694
  );
695
695
  r.push({
696
- prosemirrorSteps: n.steps.slice(k),
696
+ prosemirrorSteps: n.steps.slice(g),
697
697
  selection: {
698
698
  anchor: A.from,
699
699
  head: A.from
700
700
  },
701
- type: g ? "replace" : "insert"
701
+ type: k ? "replace" : "insert"
702
702
  // 3. Insert the replacement character by character
703
703
  }), S = !1;
704
704
  }
@@ -997,10 +997,10 @@ function te(e) {
997
997
  },
998
998
  d.doc,
999
999
  !1
1000
- ).map((g) => g.map(d.invertMap));
1001
- for (const g of b)
1002
- f.step(g.map(f.mapping));
1003
- h = D(f), h = h.filter((g) => g.type !== "select");
1000
+ ).map((k) => k.map(d.invertMap));
1001
+ for (const k of b)
1002
+ f.step(k.map(f.mapping));
1003
+ h = D(f), h = h.filter((k) => k.type !== "select");
1004
1004
  } else {
1005
1005
  const d = u.position === "after" ? a[u.referenceId] : void 0, S = st(
1006
1006
  f,
@@ -1098,10 +1098,10 @@ function oe(e) {
1098
1098
  }
1099
1099
  const p = u.operation;
1100
1100
  if (u.isPossiblyPartial) {
1101
- const k = JSON.stringify(p.block).length;
1102
- if (k < a)
1101
+ const g = JSON.stringify(p.block).length;
1102
+ if (g < a)
1103
1103
  continue;
1104
- a = k + 50;
1104
+ a = g + 50;
1105
1105
  } else
1106
1106
  a = 50;
1107
1107
  const l = await e.rebaseTool(p.id, t), m = s ? l.invertMap.invert().map(s.from()) : void 0, f = s ? l.invertMap.invert().map(s.to()) : void 0, h = await e.toJSONToolCall(t, u);
@@ -1116,13 +1116,13 @@ function oe(e) {
1116
1116
  );
1117
1117
  if (d.length === 1 && u.isPossiblyPartial)
1118
1118
  continue;
1119
- const S = d.map((k) => k.map(l.invertMap)), b = new N(t.prosemirrorState.doc);
1120
- for (const k of S)
1121
- b.step(k.map(b.mapping));
1122
- const g = D(b);
1123
- for (const k of g)
1124
- o.withDelays && await Q(k), t.transact((w) => {
1125
- ee(w, k);
1119
+ const S = d.map((g) => g.map(l.invertMap)), b = new N(t.prosemirrorState.doc);
1120
+ for (const g of S)
1121
+ b.step(g.map(b.mapping));
1122
+ const k = D(b);
1123
+ for (const g of k)
1124
+ o.withDelays && await Q(g), t.transact((w) => {
1125
+ ee(w, g);
1126
1126
  }), (c = o.onBlockUpdate) == null || c.call(o, p.id);
1127
1127
  }
1128
1128
  }
@@ -1412,16 +1412,16 @@ async function Gt(e, t) {
1412
1412
  userPrompt: o,
1413
1413
  excludeBlockIds: h ? [h] : void 0,
1414
1414
  previousMessages: S
1415
- }), g = m(
1415
+ }), k = m(
1416
1416
  e,
1417
1417
  s,
1418
1418
  t.defaultStreamTools,
1419
1419
  d ? { from: d._meta.startPos, to: d._meta.endPos } : void 0,
1420
1420
  t.onBlockUpdate
1421
1421
  );
1422
- let k;
1423
- return i ? k = await $t(
1424
- g,
1422
+ let g;
1423
+ return i ? g = await $t(
1424
+ k,
1425
1425
  {
1426
1426
  messages: b,
1427
1427
  ...p
@@ -1429,10 +1429,10 @@ async function Gt(e, t) {
1429
1429
  () => {
1430
1430
  h && e.removeBlocks([h]), a == null || a();
1431
1431
  }
1432
- ) : (k = await At(g, {
1432
+ ) : (g = await At(k, {
1433
1433
  messages: b,
1434
1434
  ...p
1435
- }), h && e.removeBlocks([h]), a == null || a()), new qt(b, k, g);
1435
+ }), h && e.removeBlocks([h]), a == null || a()), new qt(b, g, k);
1436
1436
  }
1437
1437
  async function Ue(e, t) {
1438
1438
  const o = F(e.document), r = await C(
@@ -1715,7 +1715,7 @@ function so(e) {
1715
1715
  }
1716
1716
  };
1717
1717
  }
1718
- function ge(e) {
1718
+ function ke(e) {
1719
1719
  return e = so(e).removeFileBlocks().removeDefaultProps().get(), {
1720
1720
  $defs: {
1721
1721
  styles: to(e.styleSchema),
@@ -1730,7 +1730,7 @@ function ge(e) {
1730
1730
  function Ve(e, t) {
1731
1731
  return !t.schema.inlineContentSchema[e.type] || at(e) && !("text" in e) ? !1 : ct(e) ? !("content" in e) || !("href" in e) ? !1 : Ve(e.content, t) : !0;
1732
1732
  }
1733
- function ke(e, t, o) {
1733
+ function ge(e, t, o) {
1734
1734
  const r = e.type || o, n = t.schema.blockSchema[r];
1735
1735
  if (!n)
1736
1736
  return {
@@ -1777,9 +1777,9 @@ const Z = {
1777
1777
  block: {
1778
1778
  $ref: "#/$defs/block"
1779
1779
  },
1780
- ...ge(e.schema)
1780
+ ...ke(e.schema)
1781
1781
  }),
1782
- validateBlock: ke,
1782
+ validateBlock: ge,
1783
1783
  rebaseTool: async (e, t) => H(t, R(t)),
1784
1784
  toJSONToolCall: async (e, t) => t.operation
1785
1785
  }),
@@ -1789,9 +1789,9 @@ const Z = {
1789
1789
  block: {
1790
1790
  $ref: "#/$defs/block"
1791
1791
  },
1792
- ...ge(e.schema)
1792
+ ...ke(e.schema)
1793
1793
  }),
1794
- validateBlock: ke,
1794
+ validateBlock: ge,
1795
1795
  rebaseTool: async (e, t) => H(t, R(t)),
1796
1796
  toJSONToolCall: async (e, t) => {
1797
1797
  const o = Object.fromEntries(
@@ -2109,7 +2109,7 @@ const yo = (e) => {
2109
2109
  o.setAttribute("contentedEditable", "false"), o.classList.add("bn-collaboration-cursor__caret"), o.setAttribute("style", `background-color: ${e.color}`);
2110
2110
  const r = document.createElement("span");
2111
2111
  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;
2112
- }, go = new _e("blocknote-ai-plugin");
2112
+ }, ko = new _e("blocknote-ai-plugin");
2113
2113
  class Ye extends lt {
2114
2114
  /**
2115
2115
  * @internal use `createAIExtension` instead
@@ -2132,11 +2132,11 @@ class Ye extends lt {
2132
2132
  ...r
2133
2133
  })), this.addProsemirrorPlugin(
2134
2134
  new xe({
2135
- key: go,
2135
+ key: ko,
2136
2136
  filterTransaction: (n) => {
2137
2137
  var a;
2138
2138
  const i = this.store.getState().aiMenuState;
2139
- return !(i !== "closed" && i.status === "ai-writing" && (a = n.getMeta(kt)) != null && a.fixTables);
2139
+ return !(i !== "closed" && i.status === "ai-writing" && (a = n.getMeta(gt)) != null && a.fixTables);
2140
2140
  }
2141
2141
  })
2142
2142
  ), this.addProsemirrorPlugin(ft()), this.addProsemirrorPlugin(
@@ -2145,7 +2145,7 @@ class Ye extends lt {
2145
2145
  )
2146
2146
  );
2147
2147
  }
2148
- static name() {
2148
+ static key() {
2149
2149
  return "ai";
2150
2150
  }
2151
2151
  /**
@@ -2303,7 +2303,7 @@ function ar(e) {
2303
2303
  function O(e) {
2304
2304
  return e.extension(Ye);
2305
2305
  }
2306
- const ko = (e, t) => async (o, r) => {
2306
+ const go = (e, t) => async (o, r) => {
2307
2307
  const n = new Request(o, r), i = new Request(
2308
2308
  `${e}?provider=${encodeURIComponent(
2309
2309
  t
@@ -2342,7 +2342,7 @@ function cr(e) {
2342
2342
  */
2343
2343
  getProviderSettings: (t) => ({
2344
2344
  apiKey: e.apiKey,
2345
- fetch: ko(e.baseURL, t)
2345
+ fetch: go(e.baseURL, t)
2346
2346
  })
2347
2347
  };
2348
2348
  }