@agent-factory-platform/docs-react 0.16.2 → 0.16.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/index.js CHANGED
@@ -1,99 +1,111 @@
1
1
  var Gt = Object.defineProperty;
2
2
  var Qt = (s, e, t) => e in s ? Gt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
3
  var u = (s, e, t) => Qt(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { jsx as r, jsxs as p, Fragment as Ee } from "react/jsx-runtime";
5
- import { Node as Zt, mergeAttributes as es, getSchema as ts } from "@tiptap/core";
6
- import ss from "@tiptap/extension-collaboration";
7
- import ns from "@tiptap/extension-collaboration-caret";
8
- import is from "@tiptap/extension-image";
9
- import rs from "@tiptap/extension-link";
10
- import os from "@tiptap/extension-placeholder";
11
- import { TableKit as as, TableCell as cs, TableHeader as ls } from "@tiptap/extension-table";
12
- import ds from "@tiptap/extension-text-align";
13
- import { TextStyle as us, Color as hs, BackgroundColor as ps } from "@tiptap/extension-text-style";
14
- import fs from "@tiptap/extension-task-item";
15
- import ms from "@tiptap/extension-task-list";
16
- import { Markdown as gs } from "@tiptap/markdown";
17
- import { CellSelection as ze } from "@tiptap/pm/tables";
18
- import { Slice as Ct } from "@tiptap/pm/model";
19
- import { useEditor as vs, EditorContent as bs } from "@tiptap/react";
20
- import { FloatingMenu as ws, BubbleMenu as Xe } from "@tiptap/react/menus";
21
- import ys from "@tiptap/starter-kit";
22
- import { Toolbar as xe, ToolbarSeparator as V, Input as Re, IconTip as Ue, Pressable as N, MenuChoiceGroup as oe, MenuCommandItem as M, Popover as We, ToolbarButton as ae, Button as z, Modal as ks, StateView as j, CardLabel as q, CardTitle as B, Card as Y, Tag as $, NativeSelect as Ss } from "@agent-factory-platform/ui-kit";
23
- import { Heading1 as Ye, Heading2 as Ge, Heading3 as Qe, List as Ze, ListOrdered as et, ListChecks as tt, Quote as st, SquareCode as nt, MessageSquareWarning as it, Table2 as De, Pilcrow as rt, Bold as ot, Italic as at, Underline as ct, Strikethrough as lt, Code2 as dt, Link2 as ut, Plus as xs, Sparkles as ht, ImagePlus as pt, Palette as ft, AlignLeft as mt, AlignCenter as Ds, AlignRight as Cs, Minus as Is, ChevronDown as Ps, WandSparkles as Ns, BetweenHorizontalStart as Ts, BetweenHorizontalEnd as As, Rows3 as Es, BetweenVerticalStart as zs, BetweenVerticalEnd as Rs, Columns3 as Us, TableCellsMerge as Ls, TableCellsSplit as Ms, Trash2 as It, BookOpen as Os, ShieldCheck as _s, RefreshCw as qs, Languages as Bs } from "lucide-react";
24
- import { useMemo as js, useState as T, useSyncExternalStore as pe, useRef as Ce, useEffect as Ie, useLayoutEffect as Hs, useCallback as Vs } from "react";
25
- import { docsV1 as G, isRetryableRpcError as Le } from "@agent-factory-platform/client";
26
- import { prosemirrorJSONToYXmlFragment as $s, yXmlFragmentToProsemirrorJSON as Fs } from "@tiptap/y-tiptap";
4
+ import { jsx as r, jsxs as p, Fragment as ze } from "react/jsx-runtime";
5
+ import { Node as Zt, mergeAttributes as es, Editor as ts, getSchema as ss } from "@tiptap/core";
6
+ import ns from "@tiptap/extension-collaboration";
7
+ import is from "@tiptap/extension-collaboration-caret";
8
+ import rs from "@tiptap/extension-image";
9
+ import os from "@tiptap/extension-link";
10
+ import as from "@tiptap/extension-placeholder";
11
+ import { TableKit as cs, TableCell as ls, TableHeader as ds } from "@tiptap/extension-table";
12
+ import us from "@tiptap/extension-text-align";
13
+ import { TextStyle as hs, Color as ps, BackgroundColor as fs } from "@tiptap/extension-text-style";
14
+ import ms from "@tiptap/extension-task-item";
15
+ import gs from "@tiptap/extension-task-list";
16
+ import { Markdown as vs } from "@tiptap/markdown";
17
+ import { CellSelection as Re } from "@tiptap/pm/tables";
18
+ import { Slice as It } from "@tiptap/pm/model";
19
+ import { useEditor as bs, EditorContent as ws } from "@tiptap/react";
20
+ import { FloatingMenu as ys, BubbleMenu as We } from "@tiptap/react/menus";
21
+ import ks from "@tiptap/starter-kit";
22
+ import { Toolbar as De, ToolbarSeparator as V, Input as Ue, IconTip as Le, Pressable as N, MenuChoiceGroup as oe, MenuCommandItem as M, Popover as Ye, ToolbarButton as ae, Button as z, Modal as Ss, StateView as j, CardLabel as q, CardTitle as B, Card as Y, Tag as $, NativeSelect as xs } from "@agent-factory-platform/ui-kit";
23
+ import { Heading1 as Ge, Heading2 as Qe, Heading3 as Ze, List as et, ListOrdered as tt, ListChecks as st, Quote as nt, SquareCode as it, MessageSquareWarning as rt, Table2 as Ce, Pilcrow as ot, Bold as at, Italic as ct, Underline as lt, Strikethrough as dt, Code2 as ut, Link2 as ht, Plus as Ds, Sparkles as pt, ImagePlus as ft, Palette as mt, AlignLeft as gt, AlignCenter as Cs, AlignRight as Is, Minus as Ps, ChevronDown as Ns, WandSparkles as Ts, BetweenHorizontalStart as As, BetweenHorizontalEnd as Es, Rows3 as zs, BetweenVerticalStart as Rs, BetweenVerticalEnd as Us, Columns3 as Ls, TableCellsMerge as Ms, TableCellsSplit as Os, Trash2 as Pt, BookOpen as _s, ShieldCheck as qs, RefreshCw as Bs, Languages as js } from "lucide-react";
24
+ import { useMemo as Hs, useState as T, useSyncExternalStore as fe, useRef as Ie, useEffect as Pe, useLayoutEffect as Vs, useCallback as $s } from "react";
25
+ import { docsV1 as G, isRetryableRpcError as Me } from "@agent-factory-platform/client";
26
+ import { prosemirrorJSONToYXmlFragment as Fs, yXmlFragmentToProsemirrorJSON as Js } from "@tiptap/y-tiptap";
27
27
  import * as O from "yjs";
28
- const fe = "agentfactory.richtext.v1";
29
- function Js(s) {
28
+ const me = "agentfactory.richtext.v1";
29
+ function Ks(s) {
30
30
  return (s.split(".").at(-1) ?? s).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (t) => t.toUpperCase());
31
31
  }
32
- const gt = { status: "idle", output: "" }, Ks = () => () => {
32
+ const vt = { status: "idle", output: "" }, Xs = () => () => {
33
33
  };
34
- function Xs(s, e, t) {
34
+ function Ws(s, e, t) {
35
35
  const n = s.state.doc.content.size, i = e.to - e.from;
36
36
  return s.commands.insertContentAt(e, t, { contentType: "markdown", updateSelection: !0 }), { from: e.from, to: e.from + s.state.doc.content.size - n + i };
37
37
  }
38
- function Ws(s, e, t, n) {
38
+ function Ys(s, e, t, n) {
39
39
  try {
40
40
  return s.state.doc.slice(e.from, e.to).content.eq(n.content) ? (s.view.dispatch(s.state.tr.replaceRange(e.from, e.to, t)), !0) : !1;
41
41
  } catch {
42
42
  return !1;
43
43
  }
44
44
  }
45
- async function Ys(s, e, t) {
45
+ async function Gs(s, e, t) {
46
46
  const n = s.state.doc;
47
47
  if (!n.slice(e.range.from, e.range.to).content.eq(e.generated.content)) return;
48
- const i = s.state.tr.replaceRange(e.range.from, e.range.to, e.original), c = { schema: fe, doc: i.doc.toJSON() }, d = String(await t(c));
48
+ const i = s.state.tr.replaceRange(e.range.from, e.range.to, e.original), c = { schema: me, doc: i.doc.toJSON() }, d = String(await t(c));
49
49
  if (s.state.doc.eq(n))
50
50
  return s.view.dispatch(s.state.tr.replaceRange(e.range.from, e.range.to, e.original)), { value: c, revision: d };
51
51
  }
52
- function Gs(s, e, t, n) {
53
- if (!Pt(s, e, t))
52
+ function Qs(s, e, t, n) {
53
+ if (!Nt(s, e, t))
54
54
  try {
55
- const i = Ct.fromJSON(s.schema, t.originalSlice), c = Xs(s, t.range, n);
55
+ const i = It.fromJSON(s.schema, t.originalSlice), c = Ws(s, t.range, n);
56
56
  return { range: c, original: i, generated: s.state.doc.slice(c.from, c.to) };
57
57
  } catch {
58
58
  return;
59
59
  }
60
60
  }
61
- function Pt(s, e, t) {
61
+ function Nt(s, e, t) {
62
62
  if (e.documentId !== t.documentId || e.nodeId !== t.nodeId) return "identity";
63
63
  if (e.baseRevision !== t.baseRevision) return "revision";
64
64
  if (!t.originalSlice) return "missing_original";
65
65
  if (t.range.from < 0 || t.range.to < t.range.from || t.range.to > s.state.doc.content.size) return "range";
66
66
  try {
67
- const n = Ct.fromJSON(s.schema, t.originalSlice);
67
+ const n = It.fromJSON(s.schema, t.originalSlice);
68
68
  if (!s.state.doc.slice(t.range.from, t.range.to).content.eq(n.content)) return "selection";
69
69
  } catch {
70
70
  return "invalid_slice";
71
71
  }
72
72
  }
73
- const Qs = Zt.create({
73
+ const Zs = Zt.create({
74
74
  name: "callout",
75
75
  group: "block",
76
76
  content: "block+",
77
77
  defining: !0,
78
78
  parseHTML: () => [{ tag: "aside[data-callout]" }],
79
79
  renderHTML: ({ HTMLAttributes: s }) => ["aside", es(s, { "data-callout": "info" }), 0]
80
- }), Zs = is.extend({
80
+ }), en = rs.extend({
81
81
  addAttributes() {
82
82
  var s;
83
83
  return { ...(s = this.parent) == null ? void 0 : s.call(this), asset_id: { default: null, parseHTML: (e) => e.getAttribute("data-asset-id"), renderHTML: (e) => e.asset_id ? { "data-asset-id": e.asset_id } : {} } };
84
84
  }
85
- }), en = ["var(--color-ink)", "var(--color-graphite)", "var(--color-rust)", "var(--color-data-blue)", "var(--color-success)", "var(--color-warning)", "var(--color-danger)"], de = ["var(--color-surface-muted)", "var(--color-surface-warm)", "var(--color-surface-cool)", "var(--color-data-4)", "var(--color-data-5)"], Nt = () => ({
85
+ }), tn = ["var(--color-ink)", "var(--color-graphite)", "var(--color-rust)", "var(--color-data-blue)", "var(--color-success)", "var(--color-warning)", "var(--color-danger)"], de = ["var(--color-surface-muted)", "var(--color-surface-warm)", "var(--color-surface-cool)", "var(--color-data-4)", "var(--color-data-5)"], Tt = () => ({
86
86
  default: null,
87
87
  parseHTML: (s) => de.includes(s.style.backgroundColor) ? s.style.backgroundColor : null,
88
88
  renderHTML: ({ backgroundColor: s }) => s && de.includes(s) ? { style: `background-color: ${s}` } : {}
89
- }), tn = cs.extend({ addAttributes() {
89
+ }), sn = ls.extend({ addAttributes() {
90
90
  var s;
91
- return { ...(s = this.parent) == null ? void 0 : s.call(this), backgroundColor: Nt() };
92
- } }), sn = ls.extend({ addAttributes() {
91
+ return { ...(s = this.parent) == null ? void 0 : s.call(this), backgroundColor: Tt() };
92
+ } }), nn = ds.extend({ addAttributes() {
93
93
  var s;
94
- return { ...(s = this.parent) == null ? void 0 : s.call(this), backgroundColor: Nt() };
95
- } }), vt = () => ({ schema: fe, doc: { type: "doc", content: [{ type: "paragraph" }] } });
96
- function Me(s) {
94
+ return { ...(s = this.parent) == null ? void 0 : s.call(this), backgroundColor: Tt() };
95
+ } }), bt = () => ({ schema: me, doc: { type: "doc", content: [{ type: "paragraph" }] } });
96
+ function yi(s) {
97
+ const e = new ts({
98
+ extensions: _e(""),
99
+ content: s,
100
+ contentType: "markdown"
101
+ });
102
+ try {
103
+ return ue(e.getJSON());
104
+ } finally {
105
+ e.destroy();
106
+ }
107
+ }
108
+ function ue(s) {
97
109
  const e = (t) => {
98
110
  const n = t.type === "image" && t.attrs ? Object.fromEntries(Object.entries(t.attrs).filter(([i]) => i !== "src")) : t.attrs;
99
111
  return {
@@ -102,24 +114,24 @@ function Me(s) {
102
114
  ...t.content ? { content: t.content.map(e) } : {}
103
115
  };
104
116
  };
105
- return { schema: fe, doc: e(s) };
117
+ return { schema: me, doc: e(s) };
106
118
  }
107
- function nn(s) {
119
+ function rn(s) {
108
120
  const e = JSON.parse(s);
109
121
  if (!e || typeof e != "object") throw new Error("invalid rich document");
110
122
  const t = e;
111
123
  if (t.doc === void 0)
112
124
  throw e.type === "doc" ? new Error("unsupported rich document schema") : new Error("invalid rich document");
113
- if (t.schema !== fe) throw new Error("unsupported rich document schema");
125
+ if (t.schema !== me) throw new Error("unsupported rich document schema");
114
126
  if (!t.doc || typeof t.doc != "object" || t.doc.type !== "doc") throw new Error("invalid rich document");
115
127
  return t;
116
128
  }
117
- const rn = (s) => {
118
- if (s.state.selection instanceof ze) return !0;
129
+ const on = (s) => {
130
+ if (s.state.selection instanceof Re) return !0;
119
131
  const { $from: e } = s.state.selection;
120
132
  for (let t = e.depth; t > 0; t -= 1) if (e.node(t).type.name === "table") return !0;
121
133
  return !1;
122
- }, on = (s, e) => {
134
+ }, an = (s, e) => {
123
135
  const t = s.state.selection.getBookmark(), n = s.isFocused;
124
136
  s.commands.setContent(e, { emitUpdate: !1 });
125
137
  try {
@@ -127,10 +139,10 @@ const rn = (s) => {
127
139
  } catch {
128
140
  }
129
141
  n && s.commands.focus();
130
- }, Tt = (s, e) => [
131
- ys.configure({ heading: { levels: [1, 2, 3] }, link: !1, undoRedo: e ? !1 : {} }),
132
- rs.configure({ openOnClick: !0, autolink: !0, defaultProtocol: "https", protocols: ["http", "https", "mailto"], HTMLAttributes: { target: "_blank", rel: "noopener noreferrer" } }),
133
- Zs.configure({
142
+ }, _e = (s, e) => [
143
+ ks.configure({ heading: { levels: [1, 2, 3] }, link: !1, undoRedo: e ? !1 : {} }),
144
+ os.configure({ openOnClick: !0, autolink: !0, defaultProtocol: "https", protocols: ["http", "https", "mailto"], HTMLAttributes: { target: "_blank", rel: "noopener noreferrer" } }),
145
+ en.configure({
134
146
  allowBase64: !1,
135
147
  resize: {
136
148
  enabled: !0,
@@ -140,25 +152,25 @@ const rn = (s) => {
140
152
  alwaysPreserveAspectRatio: !0
141
153
  }
142
154
  }),
143
- as.configure({ table: { resizable: !0, allowTableNodeSelection: !0 }, tableCell: !1, tableHeader: !1 }),
144
- tn,
155
+ cs.configure({ table: { resizable: !0, allowTableNodeSelection: !0 }, tableCell: !1, tableHeader: !1 }),
145
156
  sn,
146
- ds.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
147
- us,
157
+ nn,
158
+ us.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
148
159
  hs,
149
160
  ps,
150
- ms,
151
- fs.configure({ nested: !0 }),
152
- Qs,
153
- os.configure({ placeholder: s }),
161
+ fs,
154
162
  gs,
155
- ...e ? [ss.configure({ document: e.document, field: e.field ?? "prosemirror" })] : [],
156
- ...e != null && e.awareness ? [ns.configure({ provider: { awareness: e.awareness }, user: e.user ?? {} })] : []
163
+ ms.configure({ nested: !0 }),
164
+ Zs,
165
+ as.configure({ placeholder: s }),
166
+ vs,
167
+ ...e ? [ns.configure({ document: e.document, field: e.field ?? "prosemirror" })] : [],
168
+ ...e != null && e.awareness ? [is.configure({ provider: { awareness: e.awareness }, user: e.user ?? {} })] : []
157
169
  ];
158
- function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i = "Link address", saveLabel: c = "Save", surface: d = "panel", source: h, documentId: w = (h == null ? void 0 : h.id) ?? "", nodeId: I = (h == null ? void 0 : h.id) ?? "", baseRevision: v = "", collaboration: C, assistant: k, assistantInstructions: A = {}, onChange: m, onAssistantCommit: U, onImageUpload: E, resolveImage: me, labels: qt = {} }) {
159
- var Je;
170
+ function cn({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i = "Link address", saveLabel: c = "Save", surface: d = "panel", source: h, documentId: w = (h == null ? void 0 : h.id) ?? "", nodeId: I = (h == null ? void 0 : h.id) ?? "", baseRevision: v = "", collaboration: C, assistant: k, assistantInstructions: A = {}, onChange: m, onAssistantCommit: U, onImageUpload: E, resolveImage: ge, labels: qt = {} }) {
171
+ var Ke;
160
172
  if (k && !U) throw new Error("RichDocument assistant requires onAssistantCommit");
161
- const l = (a) => qt[a] ?? Js(a), Bt = js(() => Tt(t, C), [C, t]), [jt, _e] = T(!1), [qe, ge] = T(!1), [J, _] = T(null), [Be, ve] = T(!1), [Ht, se] = T(!1), [je, be] = T(""), [ne, R] = T(""), [Vt, H] = T(), [K, we] = T(), [He, ie] = T(!1), [$t, Ft] = T(0), x = pe((k == null ? void 0 : k.subscribe) ?? Ks, (k == null ? void 0 : k.getSnapshot) ?? (() => gt), (k == null ? void 0 : k.getSnapshot) ?? (() => gt)), ye = Ce(null), X = Ce(null), W = Ce(!1), ke = async (a, f) => {
173
+ const l = (a) => qt[a] ?? Ks(a), Bt = Hs(() => _e(t, C), [C, t]), [jt, qe] = T(!1), [Be, ve] = T(!1), [J, _] = T(null), [je, be] = T(!1), [Ht, se] = T(!1), [He, we] = T(""), [ne, R] = T(""), [Vt, H] = T(), [K, ye] = T(), [Ve, ie] = T(!1), [$t, Ft] = T(0), x = fe((k == null ? void 0 : k.subscribe) ?? Xs, (k == null ? void 0 : k.getSnapshot) ?? (() => vt), (k == null ? void 0 : k.getSnapshot) ?? (() => vt)), ke = Ie(null), X = Ie(null), W = Ie(!1), Se = async (a, f) => {
162
174
  const g = X.current;
163
175
  if (!g || !E) return;
164
176
  let y;
@@ -169,9 +181,9 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
169
181
  }
170
182
  const D = { type: "image", attrs: { src: y.url, asset_id: y.assetId } };
171
183
  f !== void 0 ? g.chain().focus().insertContentAt(f, D).run() : g.chain().focus().setImage(D.attrs).run();
172
- }, o = vs({
184
+ }, o = bs({
173
185
  extensions: Bt,
174
- content: C ? void 0 : (s ?? vt()).doc,
186
+ content: C ? void 0 : (s ?? bt()).doc,
175
187
  contentType: "json",
176
188
  editable: e,
177
189
  immediatelyRender: !1,
@@ -181,75 +193,75 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
181
193
  var D, P, S;
182
194
  const g = [...((D = f.clipboardData) == null ? void 0 : D.files) ?? []].find((L) => L.type.startsWith("image/"));
183
195
  if (g && E)
184
- return ke(g), !0;
196
+ return Se(g), !0;
185
197
  const y = ((P = f.clipboardData) == null ? void 0 : P.getData("text/plain")) ?? "";
186
- return cn(y) ? ((S = X.current) == null || S.commands.insertContent(y, { contentType: "markdown" }), !0) : !1;
198
+ return ln(y) ? ((S = X.current) == null || S.commands.insertContent(y, { contentType: "markdown" }), !0) : !1;
187
199
  },
188
200
  handleDrop: (a, f) => {
189
201
  var D, P;
190
202
  const g = [...((D = f.dataTransfer) == null ? void 0 : D.files) ?? []].find((S) => S.type.startsWith("image/"));
191
203
  if (!g || !E) return !1;
192
204
  const y = (P = a.posAtCoords({ left: f.clientX, top: f.clientY })) == null ? void 0 : P.pos;
193
- return ke(g, y), !0;
205
+ return Se(g, y), !0;
194
206
  },
195
207
  handleKeyDown: (a, f) => {
196
208
  if (!e || !(f.metaKey || f.ctrlKey) || f.key.toLowerCase() !== "k") return !1;
197
209
  f.preventDefault(), f.stopPropagation();
198
210
  const g = X.current;
199
- return be(String((g == null ? void 0 : g.getAttributes("link").href) ?? "https://")), se(!0), !0;
211
+ return we(String((g == null ? void 0 : g.getAttributes("link").href) ?? "https://")), se(!0), !0;
200
212
  }
201
213
  },
202
214
  onUpdate: ({ editor: a, transaction: f }) => {
203
- _e(a.state.doc.textBetween(Math.max(0, a.state.doc.content.size - 2), a.state.doc.content.size, " ").endsWith("/")), !W.current && !f.getMeta("docsAssetProjection") && (m == null || m(Me(a.getJSON())));
215
+ qe(a.state.doc.textBetween(Math.max(0, a.state.doc.content.size - 2), a.state.doc.content.size, " ").endsWith("/")), !W.current && !f.getMeta("docsAssetProjection") && (m == null || m(ue(a.getJSON())));
204
216
  }
205
217
  });
206
- Ie(() => (X.current = o, () => {
218
+ Pe(() => (X.current = o, () => {
207
219
  X.current = null;
208
- }), [o]), Ie(() => {
220
+ }), [o]), Pe(() => {
209
221
  o == null || o.setEditable(e);
210
- }, [e, o]), Hs(() => {
222
+ }, [e, o]), Vs(() => {
211
223
  if (!o || C) return;
212
- const a = (s ?? vt()).doc;
224
+ const a = (s ?? bt()).doc;
213
225
  if (JSON.stringify(o.getJSON()) !== JSON.stringify(a)) {
214
226
  W.current = !0;
215
227
  try {
216
- on(o, a);
228
+ an(o, a);
217
229
  } finally {
218
230
  W.current = !1;
219
231
  }
220
232
  }
221
- }, [C, o, s]), Ie(() => {
222
- if (!o || !me) return;
233
+ }, [C, o, s]), Pe(() => {
234
+ if (!o || !ge) return;
223
235
  let a = !1, f;
224
236
  const g = [];
225
237
  return o.state.doc.descendants((y, D) => {
226
238
  const P = y.type.name === "image" ? String(y.attrs.asset_id ?? "") : "";
227
239
  P && g.push({ assetId: P, position: D });
228
- }), Promise.allSettled(g.map(async (y) => ({ ...y, ...await me(y.assetId) }))).then((y) => {
240
+ }), Promise.allSettled(g.map(async (y) => ({ ...y, ...await ge(y.assetId) }))).then((y) => {
229
241
  if (a) return;
230
242
  let D = o.state.tr, P = Number.POSITIVE_INFINITY;
231
243
  for (const S of y) {
232
244
  if (S.status !== "fulfilled" || !S.value.url) continue;
233
245
  const L = D.doc.nodeAt(S.value.position);
234
246
  if (!(!L || String(L.attrs.asset_id ?? "") !== S.value.assetId) && (D = D.setNodeMarkup(S.value.position, void 0, { ...L.attrs, src: S.value.url }), S.value.expiresAt !== void 0)) {
235
- const Ke = new Date(S.value.expiresAt).getTime();
236
- Number.isFinite(Ke) && (P = Math.min(P, Ke));
247
+ const Xe = new Date(S.value.expiresAt).getTime();
248
+ Number.isFinite(Xe) && (P = Math.min(P, Xe));
237
249
  }
238
250
  }
239
251
  D.docChanged && o.view.dispatch(D.setMeta("docsAssetProjection", !0).setMeta("addToHistory", !1)), Number.isFinite(P) && (f = setTimeout(() => Ft((S) => S + 1), Math.max(1e3, P - Date.now() - 3e4)));
240
252
  }), () => {
241
253
  a = !0, f && clearTimeout(f);
242
254
  };
243
- }, [o, $t, me, s]);
255
+ }, [o, $t, ge, s]);
244
256
  const re = (a) => {
245
- a(), _e(!1), o == null || o.commands.focus();
246
- }, Ve = () => {
247
- o && (be(String(o.getAttributes("link").href ?? "https://")), se(!0));
257
+ a(), qe(!1), o == null || o.commands.focus();
258
+ }, $e = () => {
259
+ o && (we(String(o.getAttributes("link").href ?? "https://")), se(!0));
248
260
  }, Jt = () => {
249
261
  if (!o) return;
250
- const a = je.trim();
262
+ const a = He.trim();
251
263
  a ? o.chain().focus().extendMarkRange("link").setLink({ href: a }).run() : o.chain().focus().unsetLink().run(), se(!1);
252
- }, Se = (a) => {
264
+ }, xe = (a) => {
253
265
  if (!o || !k) return;
254
266
  const { from: f, to: g } = o.state.selection, y = o.state.doc.textBetween(f, g, `
255
267
  `), D = [];
@@ -259,7 +271,7 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
259
271
  L && D.push({ assetId: L });
260
272
  });
261
273
  const P = A[a] ?? `${a === "explain" ? "Explain" : a === "rewrite" ? "Rewrite" : "Continue"} the selected document content.`;
262
- R(""), H(void 0), we(void 0), k.submit({
274
+ R(""), H(void 0), ye(void 0), k.submit({
263
275
  version: 2,
264
276
  operation: a,
265
277
  documentId: w,
@@ -278,7 +290,7 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
278
290
  }).catch((S) => R(S instanceof Error ? S.message : String(S)));
279
291
  }, Kt = async () => {
280
292
  if (!o || !x.operation || !x.output) return;
281
- const a = Pt(o, { documentId: w, nodeId: I, baseRevision: String(v) }, x.operation);
293
+ const a = Nt(o, { documentId: w, nodeId: I, baseRevision: String(v) }, x.operation);
282
294
  if (a) {
283
295
  H(a), R(l("richDocument.aiConflict"));
284
296
  return;
@@ -286,7 +298,7 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
286
298
  W.current = !0;
287
299
  let f;
288
300
  try {
289
- f = Gs(o, { documentId: w, nodeId: I, baseRevision: String(v) }, x.operation, x.output);
301
+ f = Qs(o, { documentId: w, nodeId: I, baseRevision: String(v) }, x.operation, x.output);
290
302
  } finally {
291
303
  W.current = !1;
292
304
  }
@@ -294,13 +306,13 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
294
306
  H("invalid_slice"), R(l("richDocument.aiConflict"));
295
307
  return;
296
308
  }
297
- const g = Me(o.getJSON());
309
+ const g = ue(o.getJSON());
298
310
  ie(!0), o.setEditable(!1);
299
311
  try {
300
312
  const y = String(await U({ kind: "apply", value: g, nodeId: I, expectedRevision: String(v) }));
301
- R(""), H(void 0), we({ ...f, revision: y }), m == null || m(g, y);
313
+ R(""), H(void 0), ye({ ...f, revision: y }), m == null || m(g, y);
302
314
  } catch {
303
- Ws(o, f.range, f.original, f.generated), R(l("richDocument.aiConflict"));
315
+ Ys(o, f.range, f.original, f.generated), R(l("richDocument.aiConflict"));
304
316
  } finally {
305
317
  o.setEditable(e), ie(!1);
306
318
  }
@@ -308,112 +320,112 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
308
320
  if (!(!o || !K)) {
309
321
  ie(!0), o.setEditable(!1);
310
322
  try {
311
- const a = await Ys(o, K, (f) => U({ kind: "rollback", value: f, nodeId: I, expectedRevision: K.revision }));
323
+ const a = await Gs(o, K, (f) => U({ kind: "rollback", value: f, nodeId: I, expectedRevision: K.revision }));
312
324
  if (!a) {
313
325
  H("selection"), R(l("richDocument.aiConflict"));
314
326
  return;
315
327
  }
316
- R(""), H(void 0), we(void 0), m == null || m(a.value, a.revision);
328
+ R(""), H(void 0), ye(void 0), m == null || m(a.value, a.revision);
317
329
  } catch {
318
330
  R(l("richDocument.aiConflict"));
319
331
  } finally {
320
332
  o.setEditable(e), ie(!1);
321
333
  }
322
334
  }
323
- }, b = (a, f, g, y) => /* @__PURE__ */ r(ae, { title: a, "aria-label": a, "aria-pressed": g, className: "aria-pressed:bg-surface-raised aria-pressed:text-ink", onClick: y, children: f }), $e = (a, f, g) => /* @__PURE__ */ r(ae, { title: f, "aria-label": f, "aria-expanded": J === a, onMouseDown: (y) => y.preventDefault(), onClick: () => _((y) => y === a ? null : a), children: g }), Wt = (a) => {
324
- a(), ge(!1), o == null || o.commands.focus();
325
- }, Fe = o ? [
326
- [l("richDocument.heading1"), /* @__PURE__ */ r(Ye, { size: 15, "aria-hidden": !0 }, "h1"), () => o.chain().focus().toggleHeading({ level: 1 }).run()],
327
- [l("richDocument.heading2"), /* @__PURE__ */ r(Ge, { size: 15, "aria-hidden": !0 }, "h2"), () => o.chain().focus().toggleHeading({ level: 2 }).run()],
328
- [l("richDocument.heading3"), /* @__PURE__ */ r(Qe, { size: 15, "aria-hidden": !0 }, "h3"), () => o.chain().focus().toggleHeading({ level: 3 }).run()],
329
- [l("richDocument.bulletList"), /* @__PURE__ */ r(Ze, { size: 15, "aria-hidden": !0 }, "bullet"), () => o.chain().focus().toggleBulletList().run()],
330
- [l("richDocument.orderedList"), /* @__PURE__ */ r(et, { size: 15, "aria-hidden": !0 }, "ordered"), () => o.chain().focus().toggleOrderedList().run()],
331
- [l("richDocument.taskList"), /* @__PURE__ */ r(tt, { size: 15, "aria-hidden": !0 }, "task"), () => o.chain().focus().toggleTaskList().run()],
332
- [l("richDocument.quote"), /* @__PURE__ */ r(st, { size: 15, "aria-hidden": !0 }, "quote"), () => o.chain().focus().toggleBlockquote().run()],
333
- [l("richDocument.codeBlock"), /* @__PURE__ */ r(nt, { size: 15, "aria-hidden": !0 }, "code"), () => o.chain().focus().toggleCodeBlock().run()],
334
- [l("richDocument.callout"), /* @__PURE__ */ r(it, { size: 15, "aria-hidden": !0 }, "callout"), () => o.chain().focus().wrapIn("callout").run()],
335
- [l("richDocument.table"), /* @__PURE__ */ r(De, { size: 15, "aria-hidden": !0 }, "table"), () => o.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()]
335
+ }, b = (a, f, g, y) => /* @__PURE__ */ r(ae, { title: a, "aria-label": a, "aria-pressed": g, className: "aria-pressed:bg-surface-raised aria-pressed:text-ink", onClick: y, children: f }), Fe = (a, f, g) => /* @__PURE__ */ r(ae, { title: f, "aria-label": f, "aria-expanded": J === a, onMouseDown: (y) => y.preventDefault(), onClick: () => _((y) => y === a ? null : a), children: g }), Wt = (a) => {
336
+ a(), ve(!1), o == null || o.commands.focus();
337
+ }, Je = o ? [
338
+ [l("richDocument.heading1"), /* @__PURE__ */ r(Ge, { size: 15, "aria-hidden": !0 }, "h1"), () => o.chain().focus().toggleHeading({ level: 1 }).run()],
339
+ [l("richDocument.heading2"), /* @__PURE__ */ r(Qe, { size: 15, "aria-hidden": !0 }, "h2"), () => o.chain().focus().toggleHeading({ level: 2 }).run()],
340
+ [l("richDocument.heading3"), /* @__PURE__ */ r(Ze, { size: 15, "aria-hidden": !0 }, "h3"), () => o.chain().focus().toggleHeading({ level: 3 }).run()],
341
+ [l("richDocument.bulletList"), /* @__PURE__ */ r(et, { size: 15, "aria-hidden": !0 }, "bullet"), () => o.chain().focus().toggleBulletList().run()],
342
+ [l("richDocument.orderedList"), /* @__PURE__ */ r(tt, { size: 15, "aria-hidden": !0 }, "ordered"), () => o.chain().focus().toggleOrderedList().run()],
343
+ [l("richDocument.taskList"), /* @__PURE__ */ r(st, { size: 15, "aria-hidden": !0 }, "task"), () => o.chain().focus().toggleTaskList().run()],
344
+ [l("richDocument.quote"), /* @__PURE__ */ r(nt, { size: 15, "aria-hidden": !0 }, "quote"), () => o.chain().focus().toggleBlockquote().run()],
345
+ [l("richDocument.codeBlock"), /* @__PURE__ */ r(it, { size: 15, "aria-hidden": !0 }, "code"), () => o.chain().focus().toggleCodeBlock().run()],
346
+ [l("richDocument.callout"), /* @__PURE__ */ r(rt, { size: 15, "aria-hidden": !0 }, "callout"), () => o.chain().focus().wrapIn("callout").run()],
347
+ [l("richDocument.table"), /* @__PURE__ */ r(Ce, { size: 15, "aria-hidden": !0 }, "table"), () => o.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()]
336
348
  ] : [], Yt = o ? [
337
- [l("richDocument.paragraph"), /* @__PURE__ */ r(rt, { size: 15, "aria-hidden": !0 }, "p"), () => o.chain().focus().setParagraph().run()],
338
- ...Fe.slice(0, 8)
349
+ [l("richDocument.paragraph"), /* @__PURE__ */ r(ot, { size: 15, "aria-hidden": !0 }, "p"), () => o.chain().focus().setParagraph().run()],
350
+ ...Je.slice(0, 8)
339
351
  ] : [];
340
352
  return /* @__PURE__ */ p("div", { className: d === "document" ? "relative min-w-0" : "relative min-w-0 overflow-hidden rounded-xl border border-border bg-pure-white", "data-rich-document": !0, "data-document-id": w || void 0, "data-node-id": I || void 0, "data-base-revision": String(v) || void 0, "data-editable": e || void 0, "data-surface": d, onDragOver: (a) => E && a.preventDefault(), children: [
341
- e && o && /* @__PURE__ */ p(xe, { label: n, density: "compact", variant: d === "document" ? "bare" : "framed", className: d === "document" ? "sticky top-0 z-20 h-auto min-h-control-compact w-full flex-wrap border-b border-divider bg-pure-white py-1" : "h-auto min-h-control-compact flex-wrap rounded-none border-x-0 border-t-0", children: [
342
- b(l("richDocument.heading1"), /* @__PURE__ */ r(Ye, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 1 }), () => o.chain().focus().toggleHeading({ level: 1 }).run()),
343
- b(l("richDocument.heading2"), /* @__PURE__ */ r(Ge, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 2 }), () => o.chain().focus().toggleHeading({ level: 2 }).run()),
344
- b(l("richDocument.heading3"), /* @__PURE__ */ r(Qe, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 3 }), () => o.chain().focus().toggleHeading({ level: 3 }).run()),
353
+ e && o && /* @__PURE__ */ p(De, { label: n, density: "compact", variant: d === "document" ? "bare" : "framed", className: d === "document" ? "sticky top-0 z-20 h-auto min-h-control-compact w-full flex-wrap border-b border-divider bg-pure-white py-1" : "h-auto min-h-control-compact flex-wrap rounded-none border-x-0 border-t-0", children: [
354
+ b(l("richDocument.heading1"), /* @__PURE__ */ r(Ge, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 1 }), () => o.chain().focus().toggleHeading({ level: 1 }).run()),
355
+ b(l("richDocument.heading2"), /* @__PURE__ */ r(Qe, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 2 }), () => o.chain().focus().toggleHeading({ level: 2 }).run()),
356
+ b(l("richDocument.heading3"), /* @__PURE__ */ r(Ze, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 3 }), () => o.chain().focus().toggleHeading({ level: 3 }).run()),
345
357
  /* @__PURE__ */ r(V, {}),
346
- b(l("richDocument.bold"), /* @__PURE__ */ r(ot, { size: 15, "aria-hidden": !0 }), o.isActive("bold"), () => o.chain().focus().toggleBold().run()),
347
- b(l("richDocument.italic"), /* @__PURE__ */ r(at, { size: 15, "aria-hidden": !0 }), o.isActive("italic"), () => o.chain().focus().toggleItalic().run()),
348
- b(l("richDocument.underline"), /* @__PURE__ */ r(ct, { size: 15, "aria-hidden": !0 }), o.isActive("underline"), () => o.chain().focus().toggleUnderline().run()),
349
- b(l("richDocument.strike"), /* @__PURE__ */ r(lt, { size: 15, "aria-hidden": !0 }), o.isActive("strike"), () => o.chain().focus().toggleStrike().run()),
350
- b(l("richDocument.code"), /* @__PURE__ */ r(dt, { size: 15, "aria-hidden": !0 }), o.isActive("code"), () => o.chain().focus().toggleCode().run()),
351
- b(l("richDocument.link"), /* @__PURE__ */ r(ut, { size: 15, "aria-hidden": !0 }), o.isActive("link"), Ve),
358
+ b(l("richDocument.bold"), /* @__PURE__ */ r(at, { size: 15, "aria-hidden": !0 }), o.isActive("bold"), () => o.chain().focus().toggleBold().run()),
359
+ b(l("richDocument.italic"), /* @__PURE__ */ r(ct, { size: 15, "aria-hidden": !0 }), o.isActive("italic"), () => o.chain().focus().toggleItalic().run()),
360
+ b(l("richDocument.underline"), /* @__PURE__ */ r(lt, { size: 15, "aria-hidden": !0 }), o.isActive("underline"), () => o.chain().focus().toggleUnderline().run()),
361
+ b(l("richDocument.strike"), /* @__PURE__ */ r(dt, { size: 15, "aria-hidden": !0 }), o.isActive("strike"), () => o.chain().focus().toggleStrike().run()),
362
+ b(l("richDocument.code"), /* @__PURE__ */ r(ut, { size: 15, "aria-hidden": !0 }), o.isActive("code"), () => o.chain().focus().toggleCode().run()),
363
+ b(l("richDocument.link"), /* @__PURE__ */ r(ht, { size: 15, "aria-hidden": !0 }), o.isActive("link"), $e),
352
364
  /* @__PURE__ */ r(V, {}),
353
- b(l("richDocument.bulletList"), /* @__PURE__ */ r(Ze, { size: 15, "aria-hidden": !0 }), o.isActive("bulletList"), () => o.chain().focus().toggleBulletList().run()),
354
- b(l("richDocument.orderedList"), /* @__PURE__ */ r(et, { size: 15, "aria-hidden": !0 }), o.isActive("orderedList"), () => o.chain().focus().toggleOrderedList().run()),
355
- b(l("richDocument.taskList"), /* @__PURE__ */ r(tt, { size: 15, "aria-hidden": !0 }), o.isActive("taskList"), () => o.chain().focus().toggleTaskList().run()),
356
- b(l("richDocument.quote"), /* @__PURE__ */ r(st, { size: 15, "aria-hidden": !0 }), o.isActive("blockquote"), () => o.chain().focus().toggleBlockquote().run()),
357
- b(l("richDocument.codeBlock"), /* @__PURE__ */ r(nt, { size: 15, "aria-hidden": !0 }), o.isActive("codeBlock"), () => o.chain().focus().toggleCodeBlock().run()),
358
- b(l("richDocument.rule"), /* @__PURE__ */ r(Is, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().setHorizontalRule().run()),
359
- b(l("richDocument.callout"), /* @__PURE__ */ r(it, { size: 15, "aria-hidden": !0 }), o.isActive("callout"), () => o.chain().focus().wrapIn("callout").run()),
360
- b(l("richDocument.table"), /* @__PURE__ */ r(De, { size: 15, "aria-hidden": !0 }), o.isActive("table"), () => o.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()),
361
- E && b(l("richDocument.image"), /* @__PURE__ */ r(pt, { size: 15, "aria-hidden": !0 }), !1, () => {
365
+ b(l("richDocument.bulletList"), /* @__PURE__ */ r(et, { size: 15, "aria-hidden": !0 }), o.isActive("bulletList"), () => o.chain().focus().toggleBulletList().run()),
366
+ b(l("richDocument.orderedList"), /* @__PURE__ */ r(tt, { size: 15, "aria-hidden": !0 }), o.isActive("orderedList"), () => o.chain().focus().toggleOrderedList().run()),
367
+ b(l("richDocument.taskList"), /* @__PURE__ */ r(st, { size: 15, "aria-hidden": !0 }), o.isActive("taskList"), () => o.chain().focus().toggleTaskList().run()),
368
+ b(l("richDocument.quote"), /* @__PURE__ */ r(nt, { size: 15, "aria-hidden": !0 }), o.isActive("blockquote"), () => o.chain().focus().toggleBlockquote().run()),
369
+ b(l("richDocument.codeBlock"), /* @__PURE__ */ r(it, { size: 15, "aria-hidden": !0 }), o.isActive("codeBlock"), () => o.chain().focus().toggleCodeBlock().run()),
370
+ b(l("richDocument.rule"), /* @__PURE__ */ r(Ps, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().setHorizontalRule().run()),
371
+ b(l("richDocument.callout"), /* @__PURE__ */ r(rt, { size: 15, "aria-hidden": !0 }), o.isActive("callout"), () => o.chain().focus().wrapIn("callout").run()),
372
+ b(l("richDocument.table"), /* @__PURE__ */ r(Ce, { size: 15, "aria-hidden": !0 }), o.isActive("table"), () => o.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()),
373
+ E && b(l("richDocument.image"), /* @__PURE__ */ r(ft, { size: 15, "aria-hidden": !0 }), !1, () => {
362
374
  var a;
363
- return (a = ye.current) == null ? void 0 : a.click();
375
+ return (a = ke.current) == null ? void 0 : a.click();
364
376
  })
365
377
  ] }),
366
- E && /* @__PURE__ */ r(Re, { ref: ye, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", className: "sr-only", tabIndex: -1, onChange: (a) => {
378
+ E && /* @__PURE__ */ r(Ue, { ref: ke, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", className: "sr-only", tabIndex: -1, onChange: (a) => {
367
379
  var g;
368
380
  const f = (g = a.target.files) == null ? void 0 : g[0];
369
- f && ke(f), a.currentTarget.value = "";
381
+ f && Se(f), a.currentTarget.value = "";
370
382
  } }),
371
- e && o && /* @__PURE__ */ r(ws, { editor: o, options: { placement: "left-start" }, className: "z-40", children: /* @__PURE__ */ p("div", { className: "relative flex items-start gap-1", children: [
372
- /* @__PURE__ */ r(Ue, { label: l("richDocument.insertBlock"), children: /* @__PURE__ */ r(N, { type: "button", "aria-label": l("richDocument.insertBlock"), "aria-expanded": qe, onMouseDown: (a) => a.preventDefault(), onClick: () => ge((a) => !a), className: "grid size-8 place-items-center rounded-control border border-border bg-pure-white text-graphite shadow-soft hover:-translate-y-px hover:bg-surface-hover hover:text-ink", children: /* @__PURE__ */ r(xs, { size: 16, "aria-hidden": !0 }) }) }),
373
- k && /* @__PURE__ */ r(Ue, { label: l("richDocument.aiContinue"), children: /* @__PURE__ */ r(N, { type: "button", "aria-label": l("richDocument.aiContinue"), onMouseDown: (a) => a.preventDefault(), onClick: () => Se("continue"), className: "grid size-8 place-items-center rounded-control border border-border bg-pure-white text-rust shadow-soft hover:-translate-y-px hover:bg-surface-hover", children: /* @__PURE__ */ r(ht, { size: 15, "aria-hidden": !0 }) }) }),
374
- qe && /* @__PURE__ */ p(oe, { label: l("richDocument.insertBlock"), className: "absolute left-10 top-0 grid w-52 gap-1 rounded-panel border border-border bg-surface-raised p-1 shadow-pop", children: [
375
- Fe.map(([a, f, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ p(N, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => Wt(g), className: "flex min-h-10 items-center gap-2 rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", children: [
383
+ e && o && /* @__PURE__ */ r(ys, { editor: o, options: { placement: "left-start" }, className: "z-40", children: /* @__PURE__ */ p("div", { className: "relative flex items-start gap-1", children: [
384
+ /* @__PURE__ */ r(Le, { label: l("richDocument.insertBlock"), children: /* @__PURE__ */ r(N, { type: "button", "aria-label": l("richDocument.insertBlock"), "aria-expanded": Be, onMouseDown: (a) => a.preventDefault(), onClick: () => ve((a) => !a), className: "grid size-8 place-items-center rounded-control border border-border bg-pure-white text-graphite shadow-soft hover:-translate-y-px hover:bg-surface-hover hover:text-ink", children: /* @__PURE__ */ r(Ds, { size: 16, "aria-hidden": !0 }) }) }),
385
+ k && /* @__PURE__ */ r(Le, { label: l("richDocument.aiContinue"), children: /* @__PURE__ */ r(N, { type: "button", "aria-label": l("richDocument.aiContinue"), onMouseDown: (a) => a.preventDefault(), onClick: () => xe("continue"), className: "grid size-8 place-items-center rounded-control border border-border bg-pure-white text-rust shadow-soft hover:-translate-y-px hover:bg-surface-hover", children: /* @__PURE__ */ r(pt, { size: 15, "aria-hidden": !0 }) }) }),
386
+ Be && /* @__PURE__ */ p(oe, { label: l("richDocument.insertBlock"), className: "absolute left-10 top-0 grid w-52 gap-1 rounded-panel border border-border bg-surface-raised p-1 shadow-pop", children: [
387
+ Je.map(([a, f, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ p(N, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => Wt(g), className: "flex min-h-10 items-center gap-2 rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", children: [
376
388
  f,
377
389
  /* @__PURE__ */ r("span", { children: a })
378
390
  ] }) }, a)),
379
391
  E && /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ p(N, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
380
392
  var a;
381
- ge(!1), (a = ye.current) == null || a.click();
393
+ ve(!1), (a = ke.current) == null || a.click();
382
394
  }, className: "flex min-h-10 items-center gap-2 rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", children: [
383
- /* @__PURE__ */ r(pt, { size: 15, "aria-hidden": !0 }),
395
+ /* @__PURE__ */ r(ft, { size: 15, "aria-hidden": !0 }),
384
396
  /* @__PURE__ */ r("span", { children: l("richDocument.image") })
385
397
  ] }) })
386
398
  ] })
387
399
  ] }) }),
388
- e && o && /* @__PURE__ */ r(Xe, { editor: o, pluginKey: "richTextSelectionMenu", shouldShow: ({ editor: a, from: f, to: g }) => f !== g && !(a.state.selection instanceof ze), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ p("div", { className: "relative", children: [
389
- /* @__PURE__ */ p(xe, { label: l("richDocument.formatSelection"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
390
- $e("block", l("richDocument.paragraphStyle"), /* @__PURE__ */ p(Ee, { children: [
391
- /* @__PURE__ */ r(rt, { size: 15, "aria-hidden": !0 }),
392
- /* @__PURE__ */ r(Ps, { size: 11, "aria-hidden": !0 })
400
+ e && o && /* @__PURE__ */ r(We, { editor: o, pluginKey: "richTextSelectionMenu", shouldShow: ({ editor: a, from: f, to: g }) => f !== g && !(a.state.selection instanceof Re), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ p("div", { className: "relative", children: [
401
+ /* @__PURE__ */ p(De, { label: l("richDocument.formatSelection"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
402
+ Fe("block", l("richDocument.paragraphStyle"), /* @__PURE__ */ p(ze, { children: [
403
+ /* @__PURE__ */ r(ot, { size: 15, "aria-hidden": !0 }),
404
+ /* @__PURE__ */ r(Ns, { size: 11, "aria-hidden": !0 })
393
405
  ] })),
394
- $e("align", l("richDocument.alignment"), /* @__PURE__ */ r(mt, { size: 15, "aria-hidden": !0 })),
406
+ Fe("align", l("richDocument.alignment"), /* @__PURE__ */ r(gt, { size: 15, "aria-hidden": !0 })),
395
407
  /* @__PURE__ */ r(V, {}),
396
- b(l("richDocument.bold"), /* @__PURE__ */ r(ot, { size: 15, "aria-hidden": !0 }), o.isActive("bold"), () => o.chain().focus().toggleBold().run()),
397
- b(l("richDocument.italic"), /* @__PURE__ */ r(at, { size: 15, "aria-hidden": !0 }), o.isActive("italic"), () => o.chain().focus().toggleItalic().run()),
398
- b(l("richDocument.underline"), /* @__PURE__ */ r(ct, { size: 15, "aria-hidden": !0 }), o.isActive("underline"), () => o.chain().focus().toggleUnderline().run()),
399
- b(l("richDocument.strike"), /* @__PURE__ */ r(lt, { size: 15, "aria-hidden": !0 }), o.isActive("strike"), () => o.chain().focus().toggleStrike().run()),
400
- b(l("richDocument.code"), /* @__PURE__ */ r(dt, { size: 15, "aria-hidden": !0 }), o.isActive("code"), () => o.chain().focus().toggleCode().run()),
401
- /* @__PURE__ */ p(We, { title: l("richDocument.colors"), open: J === "color", onOpenChange: (a) => _(a ? "color" : null), side: "bottom", align: "end", trigger: /* @__PURE__ */ r(ae, { title: l("richDocument.colors"), "aria-label": l("richDocument.colors"), "aria-expanded": J === "color", onMouseDown: (a) => a.preventDefault(), children: /* @__PURE__ */ r(ft, { size: 15, "aria-hidden": !0 }) }), children: [
402
- /* @__PURE__ */ r(Pe, { label: l("richDocument.textColor"), values: en, onChoose: (a) => {
408
+ b(l("richDocument.bold"), /* @__PURE__ */ r(at, { size: 15, "aria-hidden": !0 }), o.isActive("bold"), () => o.chain().focus().toggleBold().run()),
409
+ b(l("richDocument.italic"), /* @__PURE__ */ r(ct, { size: 15, "aria-hidden": !0 }), o.isActive("italic"), () => o.chain().focus().toggleItalic().run()),
410
+ b(l("richDocument.underline"), /* @__PURE__ */ r(lt, { size: 15, "aria-hidden": !0 }), o.isActive("underline"), () => o.chain().focus().toggleUnderline().run()),
411
+ b(l("richDocument.strike"), /* @__PURE__ */ r(dt, { size: 15, "aria-hidden": !0 }), o.isActive("strike"), () => o.chain().focus().toggleStrike().run()),
412
+ b(l("richDocument.code"), /* @__PURE__ */ r(ut, { size: 15, "aria-hidden": !0 }), o.isActive("code"), () => o.chain().focus().toggleCode().run()),
413
+ /* @__PURE__ */ p(Ye, { title: l("richDocument.colors"), open: J === "color", onOpenChange: (a) => _(a ? "color" : null), side: "bottom", align: "end", trigger: /* @__PURE__ */ r(ae, { title: l("richDocument.colors"), "aria-label": l("richDocument.colors"), "aria-expanded": J === "color", onMouseDown: (a) => a.preventDefault(), children: /* @__PURE__ */ r(mt, { size: 15, "aria-hidden": !0 }) }), children: [
414
+ /* @__PURE__ */ r(Ne, { label: l("richDocument.textColor"), values: tn, onChoose: (a) => {
403
415
  o.chain().focus().setColor(a).run(), _(null);
404
416
  } }),
405
- /* @__PURE__ */ r(Pe, { label: l("richDocument.backgroundColor"), values: de, onChoose: (a) => {
417
+ /* @__PURE__ */ r(Ne, { label: l("richDocument.backgroundColor"), values: de, onChoose: (a) => {
406
418
  o.chain().focus().setBackgroundColor(a).run(), _(null);
407
419
  } }),
408
420
  /* @__PURE__ */ r(N, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
409
421
  o.chain().focus().unsetColor().unsetBackgroundColor().run(), _(null);
410
422
  }, className: "mt-2 min-h-9 w-full rounded-control text-caption text-graphite hover:bg-surface-hover hover:text-ink", children: l("richDocument.resetColors") })
411
423
  ] }),
412
- b(l("richDocument.link"), /* @__PURE__ */ r(ut, { size: 15, "aria-hidden": !0 }), o.isActive("link"), Ve),
413
- k && /* @__PURE__ */ p(Ee, { children: [
424
+ b(l("richDocument.link"), /* @__PURE__ */ r(ht, { size: 15, "aria-hidden": !0 }), o.isActive("link"), $e),
425
+ k && /* @__PURE__ */ p(ze, { children: [
414
426
  /* @__PURE__ */ r(V, {}),
415
- b(l("richDocument.aiExplain"), /* @__PURE__ */ r(ht, { size: 15, "aria-hidden": !0 }), !1, () => Se("explain")),
416
- b(l("richDocument.aiRewrite"), /* @__PURE__ */ r(Ns, { size: 15, "aria-hidden": !0 }), !1, () => Se("rewrite"))
427
+ b(l("richDocument.aiExplain"), /* @__PURE__ */ r(pt, { size: 15, "aria-hidden": !0 }), !1, () => xe("explain")),
428
+ b(l("richDocument.aiRewrite"), /* @__PURE__ */ r(Ts, { size: 15, "aria-hidden": !0 }), !1, () => xe("rewrite"))
417
429
  ] })
418
430
  ] }),
419
431
  J === "block" && /* @__PURE__ */ r(oe, { label: l("richDocument.paragraphStyle"), className: "af-layer-overlay absolute left-0 top-full mt-1 grid w-48 gap-1 rounded-panel border border-border bg-surface-raised p-1 shadow-pop", children: Yt.map(([a, f, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ p(N, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => {
@@ -422,36 +434,36 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
422
434
  f,
423
435
  /* @__PURE__ */ r("span", { children: a })
424
436
  ] }) }, a)) }),
425
- J === "align" && /* @__PURE__ */ r(oe, { label: l("richDocument.alignment"), className: "af-layer-overlay absolute left-9 top-full mt-1 grid w-40 gap-1 rounded-panel border border-border bg-surface-raised p-1 shadow-pop", children: [["left", l("richDocument.alignLeft"), /* @__PURE__ */ r(mt, { size: 15, "aria-hidden": !0 }, "left")], ["center", l("richDocument.alignCenter"), /* @__PURE__ */ r(Ds, { size: 15, "aria-hidden": !0 }, "center")], ["right", l("richDocument.alignRight"), /* @__PURE__ */ r(Cs, { size: 15, "aria-hidden": !0 }, "right")]].map(([a, f, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ p(N, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => {
437
+ J === "align" && /* @__PURE__ */ r(oe, { label: l("richDocument.alignment"), className: "af-layer-overlay absolute left-9 top-full mt-1 grid w-40 gap-1 rounded-panel border border-border bg-surface-raised p-1 shadow-pop", children: [["left", l("richDocument.alignLeft"), /* @__PURE__ */ r(gt, { size: 15, "aria-hidden": !0 }, "left")], ["center", l("richDocument.alignCenter"), /* @__PURE__ */ r(Cs, { size: 15, "aria-hidden": !0 }, "center")], ["right", l("richDocument.alignRight"), /* @__PURE__ */ r(Is, { size: 15, "aria-hidden": !0 }, "right")]].map(([a, f, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ p(N, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => {
426
438
  o.chain().focus().setTextAlign(String(a)).run(), _(null);
427
439
  }, className: "flex min-h-10 items-center gap-2 rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", children: [
428
440
  g,
429
441
  /* @__PURE__ */ r("span", { children: f })
430
442
  ] }) }, String(a))) })
431
443
  ] }) }),
432
- e && o && /* @__PURE__ */ r(Xe, { editor: o, pluginKey: "richTableMenu", shouldShow: ({ editor: a, from: f, to: g }) => (f === g || a.state.selection instanceof ze) && rn(a), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ r("div", { className: "relative", children: /* @__PURE__ */ p(xe, { label: l("richDocument.tableActions"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
433
- b(l("richDocument.addRowBefore"), /* @__PURE__ */ r(Ts, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addRowBefore().run()),
434
- b(l("richDocument.addRowAfter"), /* @__PURE__ */ r(As, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addRowAfter().run()),
435
- b(l("richDocument.deleteRow"), /* @__PURE__ */ r(Es, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteRow().run()),
444
+ e && o && /* @__PURE__ */ r(We, { editor: o, pluginKey: "richTableMenu", shouldShow: ({ editor: a, from: f, to: g }) => (f === g || a.state.selection instanceof Re) && on(a), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ r("div", { className: "relative", children: /* @__PURE__ */ p(De, { label: l("richDocument.tableActions"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
445
+ b(l("richDocument.addRowBefore"), /* @__PURE__ */ r(As, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addRowBefore().run()),
446
+ b(l("richDocument.addRowAfter"), /* @__PURE__ */ r(Es, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addRowAfter().run()),
447
+ b(l("richDocument.deleteRow"), /* @__PURE__ */ r(zs, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteRow().run()),
436
448
  /* @__PURE__ */ r(V, {}),
437
- b(l("richDocument.addColumnBefore"), /* @__PURE__ */ r(zs, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addColumnBefore().run()),
438
- b(l("richDocument.addColumnAfter"), /* @__PURE__ */ r(Rs, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addColumnAfter().run()),
439
- b(l("richDocument.deleteColumn"), /* @__PURE__ */ r(Us, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteColumn().run()),
449
+ b(l("richDocument.addColumnBefore"), /* @__PURE__ */ r(Rs, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addColumnBefore().run()),
450
+ b(l("richDocument.addColumnAfter"), /* @__PURE__ */ r(Us, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addColumnAfter().run()),
451
+ b(l("richDocument.deleteColumn"), /* @__PURE__ */ r(Ls, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteColumn().run()),
440
452
  /* @__PURE__ */ r(V, {}),
441
- b(l("richDocument.mergeCells"), /* @__PURE__ */ r(Ls, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().mergeCells().run()),
442
- b(l("richDocument.splitCell"), /* @__PURE__ */ r(Ms, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().splitCell().run()),
443
- /* @__PURE__ */ p(We, { title: l("richDocument.cellBackgroundColor"), open: Be, onOpenChange: ve, side: "bottom", align: "end", trigger: /* @__PURE__ */ r(ae, { title: l("richDocument.cellBackgroundColor"), "aria-label": l("richDocument.cellBackgroundColor"), "aria-expanded": Be, onMouseDown: (a) => a.preventDefault(), children: /* @__PURE__ */ r(ft, { size: 15, "aria-hidden": !0 }) }), children: [
444
- /* @__PURE__ */ r(Pe, { label: l("richDocument.cellBackgroundColor"), values: de, onChoose: (a) => {
445
- o.chain().focus().setCellAttribute("backgroundColor", a).run(), ve(!1);
453
+ b(l("richDocument.mergeCells"), /* @__PURE__ */ r(Ms, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().mergeCells().run()),
454
+ b(l("richDocument.splitCell"), /* @__PURE__ */ r(Os, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().splitCell().run()),
455
+ /* @__PURE__ */ p(Ye, { title: l("richDocument.cellBackgroundColor"), open: je, onOpenChange: be, side: "bottom", align: "end", trigger: /* @__PURE__ */ r(ae, { title: l("richDocument.cellBackgroundColor"), "aria-label": l("richDocument.cellBackgroundColor"), "aria-expanded": je, onMouseDown: (a) => a.preventDefault(), children: /* @__PURE__ */ r(mt, { size: 15, "aria-hidden": !0 }) }), children: [
456
+ /* @__PURE__ */ r(Ne, { label: l("richDocument.cellBackgroundColor"), values: de, onChoose: (a) => {
457
+ o.chain().focus().setCellAttribute("backgroundColor", a).run(), be(!1);
446
458
  } }),
447
459
  /* @__PURE__ */ r(N, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
448
- o.chain().focus().setCellAttribute("backgroundColor", null).run(), ve(!1);
460
+ o.chain().focus().setCellAttribute("backgroundColor", null).run(), be(!1);
449
461
  }, className: "mt-2 min-h-9 w-full rounded-control text-caption text-graphite hover:bg-surface-hover hover:text-ink", children: l("richDocument.resetCellBackground") })
450
462
  ] }),
451
- b(l("richDocument.toggleHeaderRow"), /* @__PURE__ */ r(De, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().toggleHeaderRow().run()),
452
- b(l("richDocument.deleteTable"), /* @__PURE__ */ r(It, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteTable().run())
463
+ b(l("richDocument.toggleHeaderRow"), /* @__PURE__ */ r(Ce, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().toggleHeaderRow().run()),
464
+ b(l("richDocument.deleteTable"), /* @__PURE__ */ r(Pt, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteTable().run())
453
465
  ] }) }) }),
454
- /* @__PURE__ */ r(bs, { editor: o }),
466
+ /* @__PURE__ */ r(ws, { editor: o }),
455
467
  k && !x.operation && ne && /* @__PURE__ */ r("div", { role: "alert", className: "m-4 text-caption text-danger", children: ne }),
456
468
  k && x.operation && /* @__PURE__ */ p("aside", { "data-testid": "document-assistant-operation", "data-run-id": x.runId, "data-status": x.status, "data-document-id": x.operation.documentId, "data-node-id": x.operation.nodeId, "data-base-revision": x.operation.baseRevision, "data-error-code": Vt, className: "m-4 space-y-3 rounded-panel border border-border bg-surface-muted p-4", "aria-live": "polite", children: [
457
469
  /* @__PURE__ */ p("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
@@ -461,10 +473,10 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
461
473
  x.output && /* @__PURE__ */ r("div", { "data-testid": "document-assistant-output", className: "whitespace-pre-wrap text-body-sm text-ink", children: x.output }),
462
474
  /* @__PURE__ */ p("div", { className: "flex flex-wrap gap-2", children: [
463
475
  x.status === "waiting_for_input" && /* @__PURE__ */ r(z, { size: "compact", onClick: () => void k.resolvePending().catch((a) => R(a instanceof Error ? a.message : String(a))), children: l("richDocument.aiResume") }),
464
- x.status === "completed" && x.operation.operation !== "explain" && x.output && !K && /* @__PURE__ */ r(z, { size: "compact", disabled: He, onClick: () => void Kt(), children: l("richDocument.aiApply") }),
465
- K && /* @__PURE__ */ r(z, { size: "compact", variant: "secondary", disabled: He, onClick: () => void Xt(), children: l("richDocument.aiRollback") })
476
+ x.status === "completed" && x.operation.operation !== "explain" && x.output && !K && /* @__PURE__ */ r(z, { size: "compact", disabled: Ve, onClick: () => void Kt(), children: l("richDocument.aiApply") }),
477
+ K && /* @__PURE__ */ r(z, { size: "compact", variant: "secondary", disabled: Ve, onClick: () => void Xt(), children: l("richDocument.aiRollback") })
466
478
  ] }),
467
- (ne || x.error) && /* @__PURE__ */ r("div", { role: "alert", className: "text-caption text-danger", children: ne || ((Je = x.error) == null ? void 0 : Je.message) })
479
+ (ne || x.error) && /* @__PURE__ */ r("div", { role: "alert", className: "text-caption text-danger", children: ne || ((Ke = x.error) == null ? void 0 : Ke.message) })
468
480
  ] }),
469
481
  e && jt && o && /* @__PURE__ */ p(oe, { label: l("richDocument.slashCommands"), className: "absolute left-0 top-12 z-30 grid min-w-44 gap-1 rounded-panel border border-border bg-surface-raised p-1 shadow-pop", children: [
470
482
  /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(N, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => re(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).toggleHeading({ level: 2 }).run()), children: l("richDocument.heading") }) }),
@@ -472,26 +484,26 @@ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i
472
484
  /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(N, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => re(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).wrapIn("callout").run()), children: l("richDocument.callout") }) }),
473
485
  /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(N, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => re(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()), children: l("richDocument.table") }) })
474
486
  ] }),
475
- /* @__PURE__ */ r(ks, { open: Ht, onClose: () => se(!1), title: i, closeLabel: l("common.close"), children: /* @__PURE__ */ p("div", { className: "space-y-4", children: [
476
- /* @__PURE__ */ r(Re, { autoFocus: !0, type: "url", "aria-label": i, value: je, onChange: (a) => be(a.target.value), placeholder: "https://" }),
487
+ /* @__PURE__ */ r(Ss, { open: Ht, onClose: () => se(!1), title: i, closeLabel: l("common.close"), children: /* @__PURE__ */ p("div", { className: "space-y-4", children: [
488
+ /* @__PURE__ */ r(Ue, { autoFocus: !0, type: "url", "aria-label": i, value: He, onChange: (a) => we(a.target.value), placeholder: "https://" }),
477
489
  /* @__PURE__ */ r("div", { className: "flex justify-end", children: /* @__PURE__ */ r(N, { type: "button", onClick: Jt, className: "min-h-11 rounded-full bg-ink px-5 font-sohne text-caption text-pure-white", children: c }) })
478
490
  ] }) })
479
491
  ] });
480
492
  }
481
- const cn = (s) => /(^|\n)(#{1,3} |[-*+] |\d+\. |> |```|---(?:\n|$)|- \[[ xX]\] )|\|.+\|\n\|(?:\s*:?-+:?\s*\|)+|\*\*[^*]+\*\*|~~[^~]+~~|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)]+\)/m.test(s);
482
- function Pe({ label: s, values: e, onChoose: t }) {
493
+ const ln = (s) => /(^|\n)(#{1,3} |[-*+] |\d+\. |> |```|---(?:\n|$)|- \[[ xX]\] )|\|.+\|\n\|(?:\s*:?-+:?\s*\|)+|\*\*[^*]+\*\*|~~[^~]+~~|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)]+\)/m.test(s);
494
+ function Ne({ label: s, values: e, onChoose: t }) {
483
495
  return /* @__PURE__ */ p("fieldset", { className: "mb-2", children: [
484
496
  /* @__PURE__ */ r("legend", { className: "mb-1 font-sohne text-caption text-graphite", children: s }),
485
497
  /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-1", children: e.map((n, i) => {
486
498
  const c = `${s} ${i + 1}`;
487
- return /* @__PURE__ */ r(Ue, { label: c, children: /* @__PURE__ */ r(N, { type: "button", "aria-label": c, onMouseDown: (d) => d.preventDefault(), onClick: () => t(n), className: "size-8 rounded-control border border-border transition-transform hover:-translate-y-px hover:ring-2 hover:ring-rust/35", style: { backgroundColor: n } }) }, n);
499
+ return /* @__PURE__ */ r(Le, { label: c, children: /* @__PURE__ */ r(N, { type: "button", "aria-label": c, onMouseDown: (d) => d.preventDefault(), onClick: () => t(n), className: "size-8 rounded-control border border-border transition-transform hover:-translate-y-px hover:ring-2 hover:ring-rust/35", style: { backgroundColor: n } }) }, n);
488
500
  }) })
489
501
  ] });
490
502
  }
491
- const bt = (s, e) => {
503
+ const wt = (s, e) => {
492
504
  const t = s == null ? void 0 : s.target;
493
505
  return (t == null ? void 0 : t.case) === "nodeId" ? `node:${t.value}` : `space:${(t == null ? void 0 : t.value) || e}`;
494
- }, ln = (s) => s instanceof Error ? s : new Error(String(s)), wt = {
506
+ }, dn = (s) => s instanceof Error ? s : new Error(String(s)), yt = {
495
507
  nextPageTokens: {},
496
508
  spaces: [],
497
509
  documents: [],
@@ -502,7 +514,7 @@ const bt = (s, e) => {
502
514
  invites: [],
503
515
  loading: !1
504
516
  };
505
- class wi {
517
+ class ki {
506
518
  constructor(e, t = "") {
507
519
  u(this, "state");
508
520
  u(this, "listeners", /* @__PURE__ */ new Set());
@@ -551,18 +563,18 @@ class wi {
551
563
  }));
552
564
  u(this, "revokeAcl", (e) => this.run(async () => {
553
565
  await this.transport.revokeAcl(e);
554
- const t = bt(e.resource, e.spaceId ?? "");
555
- return { spacePermissions: void 0, nodePermissions: void 0, acl: this.state.acl.filter((n) => n.subjectId !== e.subjectId || bt(n.resource, n.spaceId) !== t) };
566
+ const t = wt(e.resource, e.spaceId ?? "");
567
+ return { spacePermissions: void 0, nodePermissions: void 0, acl: this.state.acl.filter((n) => n.subjectId !== e.subjectId || wt(n.resource, n.spaceId) !== t) };
556
568
  }));
557
569
  u(this, "createInvite", (e) => this.run(async () => {
558
570
  const t = await this.transport.createInvite(e);
559
571
  return { invites: [...this.state.invites, t] };
560
572
  }));
561
573
  u(this, "revokeInvite", (e) => this.run(async () => (await this.transport.revokeInvite(e), { invites: this.state.invites.filter((t) => t.id !== e.inviteId) })));
562
- this.transport = e, this.state = { ...wt, scope: t };
574
+ this.transport = e, this.state = { ...yt, scope: t };
563
575
  }
564
576
  setScope(e) {
565
- e !== this.state.scope && (this.generation += 1, this.state = { ...wt, scope: e }, this.listeners.forEach((t) => t()));
577
+ e !== this.state.scope && (this.generation += 1, this.state = { ...yt, scope: e }, this.listeners.forEach((t) => t()));
566
578
  }
567
579
  async refresh() {
568
580
  this.generation += 1;
@@ -619,7 +631,7 @@ class wi {
619
631
  nextPageTokens: { ...this.state.nextPageTokens, acl: i.nextPageToken, invites: c.nextPageToken }
620
632
  });
621
633
  } catch (i) {
622
- t === this.generation && this.update({ spacePermissions: void 0, acl: [], invites: [], managementError: ln(i) });
634
+ t === this.generation && this.update({ spacePermissions: void 0, acl: [], invites: [], managementError: dn(i) });
623
635
  }
624
636
  }
625
637
  async openNode(e) {
@@ -762,10 +774,10 @@ class wi {
762
774
  this.state = { ...this.state, ...e }, this.listeners.forEach((t) => t());
763
775
  }
764
776
  }
765
- const dn = (s) => pe(s.subscribe, s.getSnapshot, s.getSnapshot);
766
- function yi({ controller: s }) {
777
+ const un = (s) => fe(s.subscribe, s.getSnapshot, s.getSnapshot);
778
+ function Si({ controller: s }) {
767
779
  var w, I, v, C, k, A;
768
- const e = dn(s), [t, n] = T(""), [i, c] = T("1.0.0"), d = e.documents.filter((m) => {
780
+ const e = un(s), [t, n] = T(""), [i, c] = T("1.0.0"), d = e.documents.filter((m) => {
769
781
  var U;
770
782
  return m.id !== ((U = e.selectedNode) == null ? void 0 : U.id);
771
783
  }), h = d.find((m) => m.id === t) ?? d[0];
@@ -773,7 +785,7 @@ function yi({ controller: s }) {
773
785
  /* @__PURE__ */ p("header", { children: [
774
786
  /* @__PURE__ */ p("div", { children: [
775
787
  /* @__PURE__ */ p(q, { children: [
776
- /* @__PURE__ */ r(Os, { size: 14, "aria-hidden": !0 }),
788
+ /* @__PURE__ */ r(_s, { size: 14, "aria-hidden": !0 }),
777
789
  " Docs repository"
778
790
  ] }),
779
791
  /* @__PURE__ */ p(B, { children: [
@@ -799,14 +811,14 @@ function yi({ controller: s }) {
799
811
  " documents"
800
812
  ] }),
801
813
  /* @__PURE__ */ p($, { tone: "neutral", children: [
802
- /* @__PURE__ */ r(It, { size: 12, "aria-hidden": !0 }),
814
+ /* @__PURE__ */ r(Pt, { size: 12, "aria-hidden": !0 }),
803
815
  " ",
804
816
  e.trash.length,
805
817
  " trash"
806
818
  ] }),
807
- ((w = e.spacePermissions) == null ? void 0 : w.manage) && /* @__PURE__ */ p(Ee, { children: [
819
+ ((w = e.spacePermissions) == null ? void 0 : w.manage) && /* @__PURE__ */ p(ze, { children: [
808
820
  /* @__PURE__ */ p($, { tone: "neutral", children: [
809
- /* @__PURE__ */ r(_s, { size: 12, "aria-hidden": !0 }),
821
+ /* @__PURE__ */ r(qs, { size: 12, "aria-hidden": !0 }),
810
822
  " ",
811
823
  e.acl.length,
812
824
  " grants"
@@ -844,17 +856,17 @@ function yi({ controller: s }) {
844
856
  ] }),
845
857
  /* @__PURE__ */ p("div", { className: "af-docs-workbench__actions", children: [
846
858
  /* @__PURE__ */ p(z, { size: "compact", variant: "secondary", disabled: !((C = e.nodePermissions) != null && C.write), onClick: () => void s.retryIndex(), children: [
847
- /* @__PURE__ */ r(qs, { size: 14, "aria-hidden": !0 }),
859
+ /* @__PURE__ */ r(Bs, { size: 14, "aria-hidden": !0 }),
848
860
  " Retry index"
849
861
  ] }),
850
- d.length > 0 && /* @__PURE__ */ r(Ss, { label: "Translation target", value: (h == null ? void 0 : h.id) ?? "", options: d.map((m) => ({ value: m.id, label: `${m.title} · ${m.locale}` })), onChange: n }),
862
+ d.length > 0 && /* @__PURE__ */ r(xs, { label: "Translation target", value: (h == null ? void 0 : h.id) ?? "", options: d.map((m) => ({ value: m.id, label: `${m.title} · ${m.locale}` })), onChange: n }),
851
863
  /* @__PURE__ */ p(z, { size: "compact", variant: "ghost", disabled: !h || !((k = e.nodePermissions) != null && k.write), onClick: () => h && void s.requestTranslation(h.id, h.locale), children: [
852
- /* @__PURE__ */ r(Bs, { size: 14, "aria-hidden": !0 }),
864
+ /* @__PURE__ */ r(js, { size: 14, "aria-hidden": !0 }),
853
865
  " Translation workflow"
854
866
  ] })
855
867
  ] }),
856
868
  /* @__PURE__ */ p("div", { className: "af-docs-workbench__actions", children: [
857
- /* @__PURE__ */ r(Re, { "aria-label": "Release version", value: i, onChange: (m) => c(m.target.value) }),
869
+ /* @__PURE__ */ r(Ue, { "aria-label": "Release version", value: i, onChange: (m) => c(m.target.value) }),
858
870
  /* @__PURE__ */ r(z, { size: "compact", disabled: !h || !i || !((A = e.spacePermissions) != null && A.writeTree), onClick: () => h && void s.publishBundle(i, e.selectedNode.locale, [{ locale: h.locale, nodes: [{ sourceNodeId: e.selectedNode.id, targetNodeId: h.id }] }]), children: "Publish locale bundle" })
859
871
  ] }),
860
872
  e.conflict && /* @__PURE__ */ p("div", { role: "alert", children: [
@@ -870,7 +882,7 @@ function yi({ controller: s }) {
870
882
  ] }, m)) })
871
883
  ] });
872
884
  }
873
- class ki {
885
+ class xi {
874
886
  constructor(e) {
875
887
  u(this, "state", { loading: !1 });
876
888
  u(this, "listeners", /* @__PURE__ */ new Set());
@@ -903,9 +915,9 @@ class ki {
903
915
  this.state = { ...this.state, ...e }, this.listeners.forEach((t) => t());
904
916
  }
905
917
  }
906
- const un = (s) => pe(s.subscribe, s.getSnapshot, s.getSnapshot);
907
- function Si({ controller: s }) {
908
- const e = un(s);
918
+ const hn = (s) => fe(s.subscribe, s.getSnapshot, s.getSnapshot);
919
+ function Di({ controller: s }) {
920
+ const e = hn(s);
909
921
  return e.loading ? /* @__PURE__ */ r(j, { title: "Loading published documentation" }) : e.error ? /* @__PURE__ */ r(j, { title: "Published documentation unavailable", description: e.error.message }) : e.release ? /* @__PURE__ */ p("main", { className: "af-docs-workbench", "aria-label": "Published documentation", children: [
910
922
  /* @__PURE__ */ r("header", { children: /* @__PURE__ */ p("div", { children: [
911
923
  /* @__PURE__ */ p(q, { children: [
@@ -918,19 +930,19 @@ function Si({ controller: s }) {
918
930
  e.release.nodes.map((t) => /* @__PURE__ */ r(Y, { as: "article", children: /* @__PURE__ */ p("div", { children: [
919
931
  /* @__PURE__ */ r(q, { children: t.slug }),
920
932
  /* @__PURE__ */ r(B, { children: t.title }),
921
- /* @__PURE__ */ r(hn, { node: t, controller: s })
933
+ /* @__PURE__ */ r(pn, { node: t, controller: s })
922
934
  ] }) }, t.nodeId))
923
935
  ] }) : /* @__PURE__ */ r(j, { title: "No published documentation" });
924
936
  }
925
- function hn({ node: s, controller: e }) {
926
- const t = Vs((n) => e.resolveImage(s.nodeId, n), [e, s]);
937
+ function pn({ node: s, controller: e }) {
938
+ const t = $s((n) => e.resolveImage(s.nodeId, n), [e, s]);
927
939
  try {
928
- return /* @__PURE__ */ r(an, { value: nn(s.contentJson), resolveImage: t, editable: !1, placeholder: "", ariaLabel: s.title, surface: "document" });
940
+ return /* @__PURE__ */ r(cn, { value: rn(s.contentJson), resolveImage: t, editable: !1, placeholder: "", ariaLabel: s.title, surface: "document" });
929
941
  } catch {
930
942
  return /* @__PURE__ */ r(j, { size: "sm", title: "Published content is incompatible" });
931
943
  }
932
944
  }
933
- const At = Math.floor, pn = (s, e) => s < e ? s : e, fn = (s, e) => s > e ? s : e, Et = 128, ce = 127, mn = Number.MAX_SAFE_INTEGER, gn = () => /* @__PURE__ */ new Set(), vn = Array.from, bn = (s) => {
945
+ const At = Math.floor, fn = (s, e) => s < e ? s : e, mn = (s, e) => s > e ? s : e, Et = 128, ce = 127, gn = Number.MAX_SAFE_INTEGER, vn = () => /* @__PURE__ */ new Set(), bn = Array.from, wn = (s) => {
934
946
  const e = unescape(encodeURIComponent(s)), t = e.length, n = new Uint8Array(t);
935
947
  for (let i = 0; i < t; i++)
936
948
  n[i] = /** @type {number} */
@@ -939,59 +951,59 @@ const At = Math.floor, pn = (s, e) => s < e ? s : e, fn = (s, e) => s > e ? s :
939
951
  }, te = (
940
952
  /** @type {TextEncoder} */
941
953
  typeof TextEncoder < "u" ? new TextEncoder() : null
942
- ), wn = (s) => te.encode(s), yn = te ? wn : bn;
954
+ ), yn = (s) => te.encode(s), kn = te ? yn : wn;
943
955
  let Q = typeof TextDecoder > "u" ? null : new TextDecoder("utf-8", { fatal: !0, ignoreBOM: !0 });
944
956
  Q && Q.decode(new Uint8Array()).length === 1 && (Q = null);
945
- class kn {
957
+ class Sn {
946
958
  constructor() {
947
959
  this.cpos = 0, this.cbuf = new Uint8Array(100), this.bufs = [];
948
960
  }
949
961
  }
950
- const Sn = () => new kn(), xn = (s) => {
962
+ const xn = () => new Sn(), Dn = (s) => {
951
963
  let e = s.cpos;
952
964
  for (let t = 0; t < s.bufs.length; t++)
953
965
  e += s.bufs[t].length;
954
966
  return e;
955
- }, Dn = (s) => {
956
- const e = new Uint8Array(xn(s));
967
+ }, Cn = (s) => {
968
+ const e = new Uint8Array(Dn(s));
957
969
  let t = 0;
958
970
  for (let n = 0; n < s.bufs.length; n++) {
959
971
  const i = s.bufs[n];
960
972
  e.set(i, t), t += i.length;
961
973
  }
962
974
  return e.set(new Uint8Array(s.cbuf.buffer, 0, s.cpos), t), e;
963
- }, ue = (s, e) => {
975
+ }, he = (s, e) => {
964
976
  const t = s.cbuf.length;
965
977
  s.cpos === t && (s.bufs.push(s.cbuf), s.cbuf = new Uint8Array(t * 2), s.cpos = 0), s.cbuf[s.cpos++] = e;
966
978
  }, F = (s, e) => {
967
979
  for (; e > ce; )
968
- ue(s, Et | ce & e), e = At(e / 128);
969
- ue(s, ce & e);
970
- }, Oe = new Uint8Array(3e4), Cn = Oe.length / 3, In = (s, e) => {
971
- if (e.length < Cn) {
980
+ he(s, Et | ce & e), e = At(e / 128);
981
+ he(s, ce & e);
982
+ }, Oe = new Uint8Array(3e4), In = Oe.length / 3, Pn = (s, e) => {
983
+ if (e.length < In) {
972
984
  const t = te.encodeInto(e, Oe).written || 0;
973
985
  F(s, t);
974
986
  for (let n = 0; n < t; n++)
975
- ue(s, Oe[n]);
987
+ he(s, Oe[n]);
976
988
  } else
977
- An(s, yn(e));
978
- }, Pn = (s, e) => {
989
+ En(s, kn(e));
990
+ }, Nn = (s, e) => {
979
991
  const t = unescape(encodeURIComponent(e)), n = t.length;
980
992
  F(s, n);
981
993
  for (let i = 0; i < n; i++)
982
- ue(
994
+ he(
983
995
  s,
984
996
  /** @type {number} */
985
997
  t.codePointAt(i)
986
998
  );
987
- }, Nn = te && /** @type {any} */
988
- te.encodeInto ? In : Pn, Tn = (s, e) => {
989
- const t = s.cbuf.length, n = s.cpos, i = pn(t - n, e.length), c = e.length - i;
990
- s.cbuf.set(e.subarray(0, i), n), s.cpos += i, c > 0 && (s.bufs.push(s.cbuf), s.cbuf = new Uint8Array(fn(t * 2, c)), s.cbuf.set(e.subarray(i)), s.cpos = c);
991
- }, An = (s, e) => {
992
- F(s, e.byteLength), Tn(s, e);
993
- }, zt = (s) => new Error(s), En = zt("Unexpected end of array"), zn = zt("Integer out of Range");
994
- class Rn {
999
+ }, Tn = te && /** @type {any} */
1000
+ te.encodeInto ? Pn : Nn, An = (s, e) => {
1001
+ const t = s.cbuf.length, n = s.cpos, i = fn(t - n, e.length), c = e.length - i;
1002
+ s.cbuf.set(e.subarray(0, i), n), s.cpos += i, c > 0 && (s.bufs.push(s.cbuf), s.cbuf = new Uint8Array(mn(t * 2, c)), s.cbuf.set(e.subarray(i)), s.cpos = c);
1003
+ }, En = (s, e) => {
1004
+ F(s, e.byteLength), An(s, e);
1005
+ }, zt = (s) => new Error(s), zn = zt("Unexpected end of array"), Rn = zt("Integer out of Range");
1006
+ class Un {
995
1007
  /**
996
1008
  * @param {Uint8Array<Buf>} uint8Array Binary data to decode
997
1009
  */
@@ -999,29 +1011,29 @@ class Rn {
999
1011
  this.arr = e, this.pos = 0;
1000
1012
  }
1001
1013
  }
1002
- const Un = (s) => new Rn(s), Ln = (s, e) => {
1014
+ const Ln = (s) => new Un(s), Mn = (s, e) => {
1003
1015
  const t = new Uint8Array(s.arr.buffer, s.pos + s.arr.byteOffset, e);
1004
1016
  return s.pos += e, t;
1005
- }, Mn = (s) => Ln(s, Z(s)), yt = (s) => s.arr[s.pos++], Z = (s) => {
1017
+ }, On = (s) => Mn(s, Z(s)), kt = (s) => s.arr[s.pos++], Z = (s) => {
1006
1018
  let e = 0, t = 1;
1007
1019
  const n = s.arr.length;
1008
1020
  for (; s.pos < n; ) {
1009
1021
  const i = s.arr[s.pos++];
1010
1022
  if (e = e + (i & ce) * t, t *= 128, i < Et)
1011
1023
  return e;
1012
- if (e > mn)
1013
- throw zn;
1024
+ if (e > gn)
1025
+ throw Rn;
1014
1026
  }
1015
- throw En;
1016
- }, On = (s) => {
1027
+ throw zn;
1028
+ }, _n = (s) => {
1017
1029
  let e = Z(s);
1018
1030
  if (e === 0)
1019
1031
  return "";
1020
1032
  {
1021
- let t = String.fromCodePoint(yt(s));
1033
+ let t = String.fromCodePoint(kt(s));
1022
1034
  if (--e < 100)
1023
1035
  for (; e--; )
1024
- t += String.fromCodePoint(yt(s));
1036
+ t += String.fromCodePoint(kt(s));
1025
1037
  else
1026
1038
  for (; e > 0; ) {
1027
1039
  const n = e < 1e4 ? e : 1e4, i = s.arr.subarray(s.pos, s.pos + n);
@@ -1033,23 +1045,23 @@ const Un = (s) => new Rn(s), Ln = (s, e) => {
1033
1045
  }
1034
1046
  return decodeURIComponent(escape(t));
1035
1047
  }
1036
- }, _n = (s) => (
1048
+ }, qn = (s) => (
1037
1049
  /** @type any */
1038
- Q.decode(Mn(s))
1039
- ), qn = Q ? _n : On, he = Date.now, Ne = () => /* @__PURE__ */ new Map(), Bn = (s, e, t) => {
1050
+ Q.decode(On(s))
1051
+ ), Bn = Q ? qn : _n, pe = Date.now, Te = () => /* @__PURE__ */ new Map(), jn = (s, e, t) => {
1040
1052
  let n = s.get(e);
1041
1053
  return n === void 0 && s.set(e, n = t()), n;
1042
1054
  };
1043
- class jn {
1055
+ class Hn {
1044
1056
  constructor() {
1045
- this._observers = Ne();
1057
+ this._observers = Te();
1046
1058
  }
1047
1059
  /**
1048
1060
  * @param {N} name
1049
1061
  * @param {function} f
1050
1062
  */
1051
1063
  on(e, t) {
1052
- Bn(this._observers, e, gn).add(t);
1064
+ jn(this._observers, e, vn).add(t);
1053
1065
  }
1054
1066
  /**
1055
1067
  * @param {N} name
@@ -1079,19 +1091,19 @@ class jn {
1079
1091
  * @param {Array<any>} args The arguments that are applied to the event listener.
1080
1092
  */
1081
1093
  emit(e, t) {
1082
- return vn((this._observers.get(e) || Ne()).values()).forEach((n) => n(...t));
1094
+ return bn((this._observers.get(e) || Te()).values()).forEach((n) => n(...t));
1083
1095
  }
1084
1096
  destroy() {
1085
- this._observers = Ne();
1097
+ this._observers = Te();
1086
1098
  }
1087
1099
  }
1088
- const kt = Symbol("Equality"), Hn = Object.keys, St = (s) => Hn(s).length, Vn = (s, e) => Object.prototype.hasOwnProperty.call(s, e), ee = (s, e) => {
1100
+ const St = Symbol("Equality"), Vn = Object.keys, xt = (s) => Vn(s).length, $n = (s, e) => Object.prototype.hasOwnProperty.call(s, e), ee = (s, e) => {
1089
1101
  if (s === e)
1090
1102
  return !0;
1091
1103
  if (s == null || e == null || s.constructor !== e.constructor && (s.constructor || Object) !== (e.constructor || Object))
1092
1104
  return !1;
1093
- if (s[kt] != null)
1094
- return s[kt](e);
1105
+ if (s[St] != null)
1106
+ return s[St](e);
1095
1107
  switch (s.constructor) {
1096
1108
  case ArrayBuffer:
1097
1109
  s = new Uint8Array(s), e = new Uint8Array(e);
@@ -1122,10 +1134,10 @@ const kt = Symbol("Equality"), Hn = Object.keys, St = (s) => Hn(s).length, Vn =
1122
1134
  }
1123
1135
  case void 0:
1124
1136
  case Object:
1125
- if (St(s) !== St(e))
1137
+ if (xt(s) !== xt(e))
1126
1138
  return !1;
1127
1139
  for (const t in s)
1128
- if (!Vn(s, t) || !ee(s[t], e[t]))
1140
+ if (!$n(s, t) || !ee(s[t], e[t]))
1129
1141
  return !1;
1130
1142
  break;
1131
1143
  case Array:
@@ -1139,22 +1151,22 @@ const kt = Symbol("Equality"), Hn = Object.keys, St = (s) => Hn(s).length, Vn =
1139
1151
  return !1;
1140
1152
  }
1141
1153
  return !0;
1142
- }, Te = 3e4;
1143
- class Rt extends jn {
1154
+ }, Ae = 3e4;
1155
+ class Rt extends Hn {
1144
1156
  /**
1145
1157
  * @param {Y.Doc} doc
1146
1158
  */
1147
1159
  constructor(e) {
1148
1160
  super(), this.doc = e, this.clientID = e.clientID, this.states = /* @__PURE__ */ new Map(), this.meta = /* @__PURE__ */ new Map(), this._checkInterval = /** @type {any} */
1149
1161
  setInterval(() => {
1150
- const t = he();
1151
- this.getLocalState() !== null && Te / 2 <= t - /** @type {{lastUpdated:number}} */
1162
+ const t = pe();
1163
+ this.getLocalState() !== null && Ae / 2 <= t - /** @type {{lastUpdated:number}} */
1152
1164
  this.meta.get(this.clientID).lastUpdated && this.setLocalState(this.getLocalState());
1153
1165
  const n = [];
1154
1166
  this.meta.forEach((i, c) => {
1155
- c !== this.clientID && Te <= t - i.lastUpdated && this.states.has(c) && n.push(c);
1167
+ c !== this.clientID && Ae <= t - i.lastUpdated && this.states.has(c) && n.push(c);
1156
1168
  }), n.length > 0 && Ut(this, n, "timeout");
1157
- }, At(Te / 10)), e.on("destroy", () => {
1169
+ }, At(Ae / 10)), e.on("destroy", () => {
1158
1170
  this.destroy();
1159
1171
  }), this.setLocalState({});
1160
1172
  }
@@ -1174,7 +1186,7 @@ class Rt extends jn {
1174
1186
  const t = this.clientID, n = this.meta.get(t), i = n === void 0 ? 0 : n.clock + 1, c = this.states.get(t);
1175
1187
  e === null ? this.states.delete(t) : this.states.set(t, e), this.meta.set(t, {
1176
1188
  clock: i,
1177
- lastUpdated: he()
1189
+ lastUpdated: pe()
1178
1190
  });
1179
1191
  const d = [], h = [], w = [], I = [];
1180
1192
  e === null ? I.push(t) : c == null ? e != null && d.push(t) : (h.push(t), ee(c, e) || w.push(t)), (d.length > 0 || w.length > 0 || I.length > 0) && this.emit("change", [{ added: d, updated: w, removed: I }, "local"]), this.emit("update", [{ added: d, updated: h, removed: I }, "local"]);
@@ -1209,7 +1221,7 @@ const Ut = (s, e, t) => {
1209
1221
  );
1210
1222
  s.meta.set(c, {
1211
1223
  clock: d.clock + 1,
1212
- lastUpdated: he()
1224
+ lastUpdated: pe()
1213
1225
  });
1214
1226
  }
1215
1227
  n.push(c);
@@ -1217,22 +1229,22 @@ const Ut = (s, e, t) => {
1217
1229
  }
1218
1230
  n.length > 0 && (s.emit("change", [{ added: [], updated: [], removed: n }, t]), s.emit("update", [{ added: [], updated: [], removed: n }, t]));
1219
1231
  }, Lt = (s, e, t = s.states) => {
1220
- const n = e.length, i = Sn();
1232
+ const n = e.length, i = xn();
1221
1233
  F(i, n);
1222
1234
  for (let c = 0; c < n; c++) {
1223
1235
  const d = e[c], h = t.get(d) || null, w = (
1224
1236
  /** @type {MetaClientState} */
1225
1237
  s.meta.get(d).clock
1226
1238
  );
1227
- F(i, d), F(i, w), Nn(i, JSON.stringify(h));
1239
+ F(i, d), F(i, w), Tn(i, JSON.stringify(h));
1228
1240
  }
1229
- return Dn(i);
1241
+ return Cn(i);
1230
1242
  }, Mt = (s, e, t) => {
1231
- const n = Un(e), i = he(), c = [], d = [], h = [], w = [], I = Z(n);
1243
+ const n = Ln(e), i = pe(), c = [], d = [], h = [], w = [], I = Z(n);
1232
1244
  for (let v = 0; v < I; v++) {
1233
1245
  const C = Z(n);
1234
1246
  let k = Z(n);
1235
- const A = JSON.parse(qn(n)), m = s.meta.get(C), U = s.states.get(C), E = m === void 0 ? 0 : m.clock;
1247
+ const A = JSON.parse(Bn(n)), m = s.meta.get(C), U = s.states.get(C), E = m === void 0 ? 0 : m.clock;
1236
1248
  (E < k || E === k && A === null && s.states.has(C)) && (A === null ? C === s.clientID && s.getLocalState() != null ? k++ : s.states.delete(C) : s.states.set(C, A), s.meta.set(C, {
1237
1249
  clock: k,
1238
1250
  lastUpdated: i
@@ -1247,7 +1259,7 @@ const Ut = (s, e, t) => {
1247
1259
  updated: d,
1248
1260
  removed: w
1249
1261
  }, t]);
1250
- }, xt = {
1262
+ }, Dt = {
1251
1263
  connected: !1,
1252
1264
  connecting: !1,
1253
1265
  serverSequence: 0n,
@@ -1255,9 +1267,9 @@ const Ut = (s, e, t) => {
1255
1267
  updates: [],
1256
1268
  cursors: {}
1257
1269
  };
1258
- class xi {
1270
+ class Ci {
1259
1271
  constructor(e) {
1260
- u(this, "state", xt);
1272
+ u(this, "state", Dt);
1261
1273
  u(this, "listeners", /* @__PURE__ */ new Set());
1262
1274
  u(this, "generation", 0);
1263
1275
  u(this, "desired");
@@ -1270,7 +1282,7 @@ class xi {
1270
1282
  async connect(e, t, n = 0n) {
1271
1283
  this.disconnect();
1272
1284
  const i = ++this.generation;
1273
- this.desired = { nodeId: e, clientId: t }, this.pendingUpdates.clear(), this.update({ ...xt, connecting: !0, nodeId: e, serverSequence: n });
1285
+ this.desired = { nodeId: e, clientId: t }, this.pendingUpdates.clear(), this.update({ ...Dt, connecting: !0, nodeId: e, serverSequence: n });
1274
1286
  try {
1275
1287
  await this.open(i, e, t, n);
1276
1288
  } catch (c) {
@@ -1282,7 +1294,7 @@ class xi {
1282
1294
  try {
1283
1295
  this.applyUpdate(await this.transport.pushCollaboration({ sessionId: n, clientClock: e, update: t }));
1284
1296
  } catch (i) {
1285
- throw Le(i) && this.connectionLost(this.generation, i), i;
1297
+ throw Me(i) && this.connectionLost(this.generation, i), i;
1286
1298
  }
1287
1299
  }
1288
1300
  async updateCursor(e) {
@@ -1353,7 +1365,7 @@ class xi {
1353
1365
  sessionId: e.sessionId,
1354
1366
  clientId: e.clientId,
1355
1367
  serverSequence: t.serverSequence,
1356
- stateVector: Jn(this.state.stateVector, e.stateVector),
1368
+ stateVector: Kn(this.state.stateVector, e.stateVector),
1357
1369
  updates: t.updates,
1358
1370
  cursors: n,
1359
1371
  disconnectedReason: void 0,
@@ -1415,12 +1427,12 @@ class xi {
1415
1427
  let i = this.state.error ?? new Error("collaboration disconnected");
1416
1428
  for (let c = 0; n === this.generation && this.desired === e; c += 1) {
1417
1429
  if (n !== this.generation || this.desired !== e) return;
1418
- c > 0 && await Kn(Math.min(50 * 2 ** (c - 1), 5e3)), this.update({ ...this.state, connecting: !0, disconnectedReason: void 0 });
1430
+ c > 0 && await Xn(Math.min(50 * 2 ** (c - 1), 5e3)), this.update({ ...this.state, connecting: !0, disconnectedReason: void 0 });
1419
1431
  try {
1420
1432
  await this.open(n, e.nodeId, e.clientId, this.state.serverSequence);
1421
1433
  return;
1422
1434
  } catch (d) {
1423
- if (i = d instanceof Error ? d : new Error(String(d)), this.update({ ...this.state, connecting: !1, disconnectedReason: i.message, error: i }), !Le(d)) {
1435
+ if (i = d instanceof Error ? d : new Error(String(d)), this.update({ ...this.state, connecting: !1, disconnectedReason: i.message, error: i }), !Me(d)) {
1424
1436
  this.desired = void 0;
1425
1437
  return;
1426
1438
  }
@@ -1431,8 +1443,8 @@ class xi {
1431
1443
  this.state = e, this.listeners.forEach((t) => t());
1432
1444
  }
1433
1445
  }
1434
- const Dt = Symbol("docs-collaboration-remote"), le = Symbol("docs-collaboration-presence"), Ae = 64 * 1024;
1435
- class Di {
1446
+ const Ct = Symbol("docs-collaboration-remote"), le = Symbol("docs-collaboration-presence"), Ee = 64 * 1024;
1447
+ class Ii {
1436
1448
  constructor(e, t, n, i = "prosemirror") {
1437
1449
  u(this, "document", new O.Doc());
1438
1450
  u(this, "awareness", new Rt(this.document));
@@ -1451,18 +1463,18 @@ class Di {
1451
1463
  u(this, "oversizedUpdate", !1);
1452
1464
  u(this, "applyRemoteUpdates", () => {
1453
1465
  for (const t of this.controller.getSnapshot().updates)
1454
- t.serverSequence <= this.appliedSequence || (O.applyUpdate(this.document, t.update, Dt), this.appliedSequence = t.serverSequence);
1466
+ t.serverSequence <= this.appliedSequence || (O.applyUpdate(this.document, t.update, Ct), this.appliedSequence = t.serverSequence);
1455
1467
  const e = this.controller.getSnapshot().cursors;
1456
1468
  for (const t of this.presenceClients.keys())
1457
1469
  e[t] || (Ut(this.awareness, [...this.presenceClients.get(t) ?? []], le), this.presenceClients.delete(t), this.appliedPresence.delete(t));
1458
1470
  for (const [t, n] of Object.entries(e)) {
1459
- if (n.cursor.length === 0 || $n(this.appliedPresence.get(t), n.cursor)) continue;
1471
+ if (n.cursor.length === 0 || Fn(this.appliedPresence.get(t), n.cursor)) continue;
1460
1472
  const i = /* @__PURE__ */ new Set(), c = ({ added: d, updated: h }) => {
1461
1473
  for (const w of [...d, ...h]) i.add(w);
1462
1474
  };
1463
1475
  this.awareness.on("update", c);
1464
1476
  try {
1465
- Mt(this.awareness, Fn(n.cursor, n.subjectId), le);
1477
+ Mt(this.awareness, Jn(n.cursor, n.subjectId), le);
1466
1478
  } catch {
1467
1479
  continue;
1468
1480
  } finally {
@@ -1473,15 +1485,15 @@ class Di {
1473
1485
  });
1474
1486
  u(this, "pushLocalUpdate", (e, t) => {
1475
1487
  var d;
1476
- if (t === Dt) return;
1488
+ if (t === Ct) return;
1477
1489
  const n = this.oversizedUpdate ? O.encodeStateAsUpdate(this.document) : e;
1478
- if (n.length > Ae) {
1479
- this.oversizedUpdate = !0, this.terminalUpdateError = new Error(`collaboration update exceeds ${Ae} bytes`), this.controller.reportError(this.terminalUpdateError);
1490
+ if (n.length > Ee) {
1491
+ this.oversizedUpdate = !0, this.terminalUpdateError = new Error(`collaboration update exceeds ${Ee} bytes`), this.controller.reportError(this.terminalUpdateError);
1480
1492
  return;
1481
1493
  }
1482
1494
  this.oversizedUpdate = !1, this.terminalUpdateError = void 0;
1483
1495
  const i = this.queuedUpdates.at(-1), c = i && i.clock === void 0 ? O.mergeUpdates([i.bytes, n]) : n;
1484
- i && i.clock === void 0 && c.length <= Ae ? i.bytes = c : this.queuedUpdates.push({ bytes: n }), (d = this.ensurePump()) == null || d.catch((h) => this.controller.reportError(h));
1496
+ i && i.clock === void 0 && c.length <= Ee ? i.bytes = c : this.queuedUpdates.push({ bytes: n }), (d = this.ensurePump()) == null || d.catch((h) => this.controller.reportError(h));
1485
1497
  });
1486
1498
  u(this, "pushLocalPresence", (e, t) => {
1487
1499
  if (t === le || !this.controller.getSnapshot().connected) return;
@@ -1495,13 +1507,13 @@ class Di {
1495
1507
  this.oversizedUpdate || (this.terminalUpdateError = void 0), await this.controller.connect(e, this.clockClientId, t), this.applyRemoteUpdates();
1496
1508
  const n = this.controller.getSnapshot(), i = n.stateVector[n.clientId ?? this.clientId] ?? 0n;
1497
1509
  if (i > this.clientClock && (this.clientClock = i), n.serverSequence === 0n && this.document.getXmlFragment(this.field).length === 0 && this.initialValue) {
1498
- const c = ts(Tt("")), d = new O.Doc();
1499
- d.clientID = Ot(JSON.stringify(this.initialValue)), $s(c, this.initialValue.doc, d.getXmlFragment(this.field)), O.applyUpdate(this.document, O.encodeStateAsUpdate(d));
1510
+ const c = ss(_e("")), d = new O.Doc();
1511
+ d.clientID = Ot(JSON.stringify(this.initialValue)), Fs(c, this.initialValue.doc, d.getXmlFragment(this.field)), O.applyUpdate(this.document, O.encodeStateAsUpdate(d));
1500
1512
  }
1501
1513
  await this.flush(), this.pushLocalPresence({ added: [this.awareness.clientID], updated: [], removed: [] }, void 0);
1502
1514
  }
1503
1515
  snapshot() {
1504
- return Me(Fs(this.document.getXmlFragment(this.field)));
1516
+ return ue(Js(this.document.getXmlFragment(this.field)));
1505
1517
  }
1506
1518
  async checkpoint(e, t) {
1507
1519
  return await this.flush(), await this.controller.sync(), this.applyRemoteUpdates(), await this.flush(), String(await t(this.snapshot(), {
@@ -1538,7 +1550,7 @@ class Di {
1538
1550
  await this.controller.push(t, e.bytes);
1539
1551
  break;
1540
1552
  } catch (n) {
1541
- if (!Le(n))
1553
+ if (!Me(n))
1542
1554
  throw this.terminalUpdateError = n instanceof Error ? n : new Error(String(n)), this.terminalUpdateError;
1543
1555
  }
1544
1556
  }
@@ -1556,10 +1568,10 @@ function Ot(s) {
1556
1568
  function _t(s) {
1557
1569
  return `hsl(${Ot(s) % 360} 62% 42%)`;
1558
1570
  }
1559
- function $n(s, e) {
1571
+ function Fn(s, e) {
1560
1572
  return (s == null ? void 0 : s.length) === e.length && s.every((t, n) => t === e[n]);
1561
1573
  }
1562
- function Fn(s, e) {
1574
+ function Jn(s, e) {
1563
1575
  const t = new O.Doc(), n = new Rt(t);
1564
1576
  try {
1565
1577
  Mt(n, s, le);
@@ -1573,14 +1585,14 @@ function Fn(s, e) {
1573
1585
  n.destroy(), t.destroy();
1574
1586
  }
1575
1587
  }
1576
- function Jn(s, e) {
1588
+ function Kn(s, e) {
1577
1589
  const t = { ...s };
1578
1590
  for (const [n, i] of Object.entries(e ?? {})) t[n] = t[n] > i ? t[n] : i;
1579
1591
  return t;
1580
1592
  }
1581
- const Kn = (s) => new Promise((e) => setTimeout(e, s)), Xn = (s) => pe(s.subscribe, s.getSnapshot, s.getSnapshot);
1582
- function Ci({ controller: s }) {
1583
- const e = Xn(s);
1593
+ const Xn = (s) => new Promise((e) => setTimeout(e, s)), Wn = (s) => fe(s.subscribe, s.getSnapshot, s.getSnapshot);
1594
+ function Pi({ controller: s }) {
1595
+ const e = Wn(s);
1584
1596
  return e.error ? /* @__PURE__ */ r(j, { size: "sm", title: "Live editing unavailable", description: e.error.message }) : /* @__PURE__ */ p(Y, { as: "section", children: [
1585
1597
  /* @__PURE__ */ p("header", { children: [
1586
1598
  /* @__PURE__ */ p("div", { children: [
@@ -1598,7 +1610,7 @@ function Ci({ controller: s }) {
1598
1610
  (e.connected || e.connecting) && /* @__PURE__ */ r(z, { size: "compact", variant: "secondary", onClick: () => s.disconnect(), children: "Disconnect" })
1599
1611
  ] });
1600
1612
  }
1601
- class Ii {
1613
+ class Ni {
1602
1614
  constructor(e, t, n = 800) {
1603
1615
  u(this, "snapshot");
1604
1616
  u(this, "generation", 0);
@@ -1662,30 +1674,31 @@ class Ii {
1662
1674
  }
1663
1675
  }
1664
1676
  export {
1665
- Ii as DocsAutosaveController,
1666
- Ci as DocsCollaboration,
1667
- xi as DocsCollaborationController,
1668
- yi as DocsWorkbench,
1669
- wi as DocsWorkbenchController,
1670
- Si as PublishedDocs,
1671
- ki as PublishedDocsController,
1672
- fe as RICH_DOCUMENT_SCHEMA,
1673
- an as RichDocument,
1674
- an as RichDocumentEditor,
1675
- Di as YjsDocsCollaborationAdapter,
1676
- Gs as applyDocumentAssistantOutput,
1677
- Ys as commitDocumentAssistantRollback,
1678
- Pt as documentAssistantConflict,
1679
- Me as durableRichDocumentContent,
1680
- vt as emptyRichDocument,
1681
- cn as looksLikeMarkdown,
1682
- nn as parseRichDocument,
1683
- Xs as replaceAssistantMarkdown,
1684
- on as replaceDocumentContent,
1685
- Tt as richDocumentExtensions,
1686
- Ws as rollbackAssistantRange,
1687
- rn as selectionInsideTable,
1688
- Xn as useDocsCollaboration,
1689
- dn as useDocsWorkbench,
1690
- un as usePublishedDocs
1677
+ Ni as DocsAutosaveController,
1678
+ Pi as DocsCollaboration,
1679
+ Ci as DocsCollaborationController,
1680
+ Si as DocsWorkbench,
1681
+ ki as DocsWorkbenchController,
1682
+ Di as PublishedDocs,
1683
+ xi as PublishedDocsController,
1684
+ me as RICH_DOCUMENT_SCHEMA,
1685
+ cn as RichDocument,
1686
+ cn as RichDocumentEditor,
1687
+ Ii as YjsDocsCollaborationAdapter,
1688
+ Qs as applyDocumentAssistantOutput,
1689
+ Gs as commitDocumentAssistantRollback,
1690
+ Nt as documentAssistantConflict,
1691
+ ue as durableRichDocumentContent,
1692
+ bt as emptyRichDocument,
1693
+ ln as looksLikeMarkdown,
1694
+ rn as parseRichDocument,
1695
+ Ws as replaceAssistantMarkdown,
1696
+ an as replaceDocumentContent,
1697
+ _e as richDocumentExtensions,
1698
+ yi as richDocumentFromMarkdown,
1699
+ Ys as rollbackAssistantRange,
1700
+ on as selectionInsideTable,
1701
+ Wn as useDocsCollaboration,
1702
+ un as useDocsWorkbench,
1703
+ hn as usePublishedDocs
1691
1704
  };