@agent-factory-platform/docs-react 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,111 +1,111 @@
1
1
  var Gt = Object.defineProperty;
2
- var Qt = (n, e, t) => e in n ? Gt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var p = (n, e, t) => Qt(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { jsx as i, jsxs as h, Fragment as Ke } from "react/jsx-runtime";
5
- import { Node as Zt, mergeAttributes as en, getSchema as tn } from "@tiptap/core";
6
- import nn from "@tiptap/extension-collaboration";
7
- import sn from "@tiptap/extension-collaboration-caret";
8
- import rn from "@tiptap/extension-image";
9
- import on from "@tiptap/extension-link";
10
- import an from "@tiptap/extension-placeholder";
11
- import { TableKit as cn, TableCell as ln, TableHeader as dn } from "@tiptap/extension-table";
12
- import un from "@tiptap/extension-text-align";
13
- import { TextStyle as hn, Color as pn, BackgroundColor as fn } from "@tiptap/extension-text-style";
14
- import mn from "@tiptap/extension-task-item";
15
- import gn from "@tiptap/extension-task-list";
16
- import { Markdown as vn } from "@tiptap/markdown";
17
- import { CellSelection as Re } from "@tiptap/pm/tables";
18
- import { Slice as xt } from "@tiptap/pm/model";
19
- import { useEditor as bn, EditorContent as wn } from "@tiptap/react";
20
- import { FloatingMenu as yn, BubbleMenu as Xe } from "@tiptap/react/menus";
21
- import Sn from "@tiptap/starter-kit";
22
- import { Toolbar as De, ToolbarSeparator as j, Input as Ue, IconTip as Te, Pressable as A, MenuChoiceGroup as oe, MenuCommandItem as P, Popover as We, ToolbarButton as ae, Button as U, Modal as kn, StateView as B, CardLabel as _, CardTitle as q, Card as Y, Tag as V, NativeSelect as Dn } 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 nt, SquareCode as st, MessageSquareWarning as rt, Table2 as Ce, Pilcrow as it, Bold as ot, Italic as at, Underline as ct, Strikethrough as lt, Code2 as dt, Link2 as ut, Plus as Cn, Sparkles as ht, ImagePlus as pt, Palette as ft, AlignLeft as mt, AlignCenter as xn, AlignRight as Nn, Minus as In, ChevronDown as An, WandSparkles as En, BetweenHorizontalStart as zn, BetweenHorizontalEnd as Rn, Rows3 as Un, BetweenVerticalStart as Tn, BetweenVerticalEnd as Ln, Columns3 as Pn, TableCellsMerge as Mn, TableCellsSplit as On, Trash2 as Nt, BookOpen as _n, ShieldCheck as qn, RefreshCw as Bn, Languages as Hn } from "lucide-react";
24
- import { useMemo as jn, useState as E, useSyncExternalStore as pe, useRef as xe, useEffect as Ne, useLayoutEffect as Vn } from "react";
2
+ var Qt = (s, e, t) => e in s ? Gt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var f = (s, e, t) => Qt(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { jsx as r, jsxs as h, 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 P, 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 Ns, WandSparkles as Ps, 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
25
  import { docsV1 as G, isRetryableRpcError as Le } from "@agent-factory-platform/client";
26
- import { prosemirrorJSONToYXmlFragment as $n, yXmlFragmentToProsemirrorJSON as Fn } from "@tiptap/y-tiptap";
27
- import * as M from "yjs";
26
+ import { prosemirrorJSONToYXmlFragment as $s, yXmlFragmentToProsemirrorJSON as Fs } from "@tiptap/y-tiptap";
27
+ import * as O from "yjs";
28
28
  const fe = "agentfactory.richtext.v1";
29
- function Jn(n) {
30
- return (n.split(".").at(-1) ?? n).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (t) => t.toUpperCase());
29
+ function Js(s) {
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: "" }, Kn = () => () => {
32
+ const gt = { status: "idle", output: "" }, Ks = () => () => {
33
33
  };
34
- function Xn(n, e, t) {
35
- const s = n.state.doc.content.size, r = e.to - e.from;
36
- return n.commands.insertContentAt(e, t, { contentType: "markdown", updateSelection: !0 }), { from: e.from, to: e.from + n.state.doc.content.size - s + r };
34
+ function Xs(s, e, t) {
35
+ const n = s.state.doc.content.size, i = e.to - e.from;
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 Wn(n, e, t, s) {
38
+ function Ws(s, e, t, n) {
39
39
  try {
40
- return n.state.doc.slice(e.from, e.to).content.eq(s.content) ? (n.view.dispatch(n.state.tr.replaceRange(e.from, e.to, t)), !0) : !1;
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 Yn(n, e, t) {
46
- const s = n.state.doc;
47
- if (!s.slice(e.range.from, e.range.to).content.eq(e.generated.content)) return;
48
- const r = n.state.tr.replaceRange(e.range.from, e.range.to, e.original), l = { schema: fe, doc: r.doc.toJSON() }, d = String(await t(l));
49
- if (n.state.doc.eq(s))
50
- return n.view.dispatch(n.state.tr.replaceRange(e.range.from, e.range.to, e.original)), { value: l, revision: d };
45
+ async function Ys(s, e, t) {
46
+ const n = s.state.doc;
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));
49
+ if (s.state.doc.eq(n))
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 Gn(n, e, t, s) {
53
- if (!It(n, e, t))
52
+ function Gs(s, e, t, n) {
53
+ if (!Nt(s, e, t))
54
54
  try {
55
- const r = xt.fromJSON(n.schema, t.originalSlice), l = Xn(n, t.range, s);
56
- return { range: l, original: r, generated: n.state.doc.slice(l.from, l.to) };
55
+ const i = Ct.fromJSON(s.schema, t.originalSlice), c = Xs(s, t.range, n);
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 It(n, 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
- if (t.range.from < 0 || t.range.to < t.range.from || t.range.to > n.state.doc.content.size) return "range";
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 s = xt.fromJSON(n.schema, t.originalSlice);
68
- if (!n.state.doc.slice(t.range.from, t.range.to).content.eq(s.content)) return "selection";
67
+ const n = Ct.fromJSON(s.schema, t.originalSlice);
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 Qn = Zt.create({
73
+ const Qs = 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
- renderHTML: ({ HTMLAttributes: n }) => ["aside", en(n, { "data-callout": "info" }), 0]
80
- }), Zn = rn.extend({
79
+ renderHTML: ({ HTMLAttributes: s }) => ["aside", es(s, { "data-callout": "info" }), 0]
80
+ }), Zs = is.extend({
81
81
  addAttributes() {
82
- var n;
83
- return { ...(n = this.parent) == null ? void 0 : n.call(this), asset_id: { default: null, parseHTML: (e) => e.getAttribute("data-asset-id"), renderHTML: (e) => e.asset_id ? { "data-asset-id": e.asset_id } : {} } };
82
+ var s;
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
- }), es = ["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)"], At = () => ({
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)"], Pt = () => ({
86
86
  default: null,
87
- parseHTML: (n) => de.includes(n.style.backgroundColor) ? n.style.backgroundColor : null,
88
- renderHTML: ({ backgroundColor: n }) => n && de.includes(n) ? { style: `background-color: ${n}` } : {}
89
- }), ts = ln.extend({ addAttributes() {
90
- var n;
91
- return { ...(n = this.parent) == null ? void 0 : n.call(this), backgroundColor: At() };
92
- } }), ns = dn.extend({ addAttributes() {
93
- var n;
94
- return { ...(n = this.parent) == null ? void 0 : n.call(this), backgroundColor: At() };
87
+ parseHTML: (s) => de.includes(s.style.backgroundColor) ? s.style.backgroundColor : null,
88
+ renderHTML: ({ backgroundColor: s }) => s && de.includes(s) ? { style: `background-color: ${s}` } : {}
89
+ }), tn = cs.extend({ addAttributes() {
90
+ var s;
91
+ return { ...(s = this.parent) == null ? void 0 : s.call(this), backgroundColor: Pt() };
92
+ } }), sn = ls.extend({ addAttributes() {
93
+ var s;
94
+ return { ...(s = this.parent) == null ? void 0 : s.call(this), backgroundColor: Pt() };
95
95
  } }), vt = () => ({ schema: fe, doc: { type: "doc", content: [{ type: "paragraph" }] } });
96
- function Pe(n) {
96
+ function Me(s) {
97
97
  const e = (t) => {
98
- const s = t.type === "image" && t.attrs ? Object.fromEntries(Object.entries(t.attrs).filter(([r]) => r !== "src")) : t.attrs;
98
+ const n = t.type === "image" && t.attrs ? Object.fromEntries(Object.entries(t.attrs).filter(([i]) => i !== "src")) : t.attrs;
99
99
  return {
100
100
  ...t,
101
- ...s ? { attrs: s } : {},
101
+ ...n ? { attrs: n } : {},
102
102
  ...t.content ? { content: t.content.map(e) } : {}
103
103
  };
104
104
  };
105
- return { schema: fe, doc: e(n) };
105
+ return { schema: fe, doc: e(s) };
106
106
  }
107
- function ss(n) {
108
- const e = JSON.parse(n);
107
+ function nn(s) {
108
+ const e = JSON.parse(s);
109
109
  if (!e || typeof e != "object") throw new Error("invalid rich document");
110
110
  const t = e;
111
111
  if (t.doc === void 0)
@@ -114,23 +114,23 @@ function ss(n) {
114
114
  if (!t.doc || typeof t.doc != "object" || t.doc.type !== "doc") throw new Error("invalid rich document");
115
115
  return t;
116
116
  }
117
- const rs = (n) => {
118
- if (n.state.selection instanceof Re) return !0;
119
- const { $from: e } = n.state.selection;
117
+ const rn = (s) => {
118
+ if (s.state.selection instanceof ze) return !0;
119
+ const { $from: e } = s.state.selection;
120
120
  for (let t = e.depth; t > 0; t -= 1) if (e.node(t).type.name === "table") return !0;
121
121
  return !1;
122
- }, is = (n, e) => {
123
- const t = n.state.selection.getBookmark(), s = n.isFocused;
124
- n.commands.setContent(e, { emitUpdate: !1 });
122
+ }, on = (s, e) => {
123
+ const t = s.state.selection.getBookmark(), n = s.isFocused;
124
+ s.commands.setContent(e, { emitUpdate: !1 });
125
125
  try {
126
- n.view.dispatch(n.state.tr.setSelection(t.resolve(n.state.doc)));
126
+ s.view.dispatch(s.state.tr.setSelection(t.resolve(s.state.doc)));
127
127
  } catch {
128
128
  }
129
- s && n.commands.focus();
130
- }, Et = (n, e) => [
131
- Sn.configure({ heading: { levels: [1, 2, 3] }, link: !1, undoRedo: e ? !1 : {} }),
132
- on.configure({ openOnClick: !0, autolink: !0, defaultProtocol: "https", protocols: ["http", "https", "mailto"], HTMLAttributes: { target: "_blank", rel: "noopener noreferrer" } }),
133
- Zn.configure({
129
+ 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({
134
134
  allowBase64: !1,
135
135
  resize: {
136
136
  enabled: !0,
@@ -140,358 +140,359 @@ const rs = (n) => {
140
140
  alwaysPreserveAspectRatio: !0
141
141
  }
142
142
  }),
143
- cn.configure({ table: { resizable: !0, allowTableNodeSelection: !0 }, tableCell: !1, tableHeader: !1 }),
144
- ts,
145
- ns,
146
- un.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
147
- hn,
148
- pn,
149
- fn,
150
- gn,
151
- mn.configure({ nested: !0 }),
152
- Qn,
153
- an.configure({ placeholder: n }),
154
- vn,
155
- ...e ? [nn.configure({ document: e.document, field: e.field ?? "prosemirror" })] : [],
156
- ...e != null && e.awareness ? [sn.configure({ provider: { awareness: e.awareness }, user: e.user ?? {} })] : []
143
+ as.configure({ table: { resizable: !0, allowTableNodeSelection: !0 }, tableCell: !1, tableHeader: !1 }),
144
+ tn,
145
+ sn,
146
+ ds.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
147
+ us,
148
+ hs,
149
+ ps,
150
+ ms,
151
+ fs.configure({ nested: !0 }),
152
+ Qs,
153
+ os.configure({ placeholder: s }),
154
+ 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 ?? {} })] : []
157
157
  ];
158
- function os({ value: n, editable: e, placeholder: t, ariaLabel: s, linkLabel: r = "Link address", saveLabel: l = "Save", surface: d = "panel", source: f, documentId: y = (f == null ? void 0 : f.id) ?? "", nodeId: x = (f == null ? void 0 : f.id) ?? "", baseRevision: b = "", collaboration: C, assistant: S, assistantInstructions: T = {}, onChange: I, onAssistantCommit: F, onImageUpload: z, resolveImage: me, labels: qt = {} }) {
159
- var Fe;
160
- if (S && !F) throw new Error("RichDocument assistant requires onAssistantCommit");
161
- const c = (a) => qt[a] ?? Jn(a), Bt = jn(() => Et(t, C), [C, t]), [Ht, Oe] = E(!1), [_e, ge] = E(!1), [J, O] = E(null), [qe, ve] = E(!1), [jt, ne] = E(!1), [Be, be] = E(""), [se, R] = E(""), [Vt, H] = E(), [K, we] = E(), [He, re] = E(!1), [$t, Ft] = E(0), k = pe((S == null ? void 0 : S.subscribe) ?? Kn, (S == null ? void 0 : S.getSnapshot) ?? (() => gt), (S == null ? void 0 : S.getSnapshot) ?? (() => gt)), ye = xe(null), X = xe(null), W = xe(!1), Se = async (a, u) => {
162
- const m = X.current;
163
- if (!m || !z) return;
164
- let v;
158
+ function an({ value: s, editable: e, placeholder: t, ariaLabel: n, linkLabel: i = "Link address", saveLabel: c = "Save", surface: d = "panel", source: u, documentId: w = (u == null ? void 0 : u.id) ?? "", nodeId: I = (u == null ? void 0 : u.id) ?? "", baseRevision: v = "", collaboration: C, assistant: k, assistantInstructions: A = {}, onChange: m, onAssistantCommit: U, onImageUpload: E, resolveImage: me, labels: qt = {} }) {
159
+ var Je;
160
+ 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, p) => {
162
+ const g = X.current;
163
+ if (!g || !E) return;
164
+ let y;
165
165
  try {
166
- v = await z(a);
166
+ y = await E(a);
167
167
  } catch {
168
168
  return;
169
169
  }
170
- const D = { type: "image", attrs: { src: v.url, asset_id: v.assetId } };
171
- u !== void 0 ? m.chain().focus().insertContentAt(u, D).run() : m.chain().focus().setImage(D.attrs).run();
172
- }, o = bn({
170
+ const D = { type: "image", attrs: { src: y.url, asset_id: y.assetId } };
171
+ p !== void 0 ? g.chain().focus().insertContentAt(p, D).run() : g.chain().focus().setImage(D.attrs).run();
172
+ }, o = vs({
173
173
  extensions: Bt,
174
- content: C ? void 0 : (n ?? vt()).doc,
174
+ content: C ? void 0 : (s ?? vt()).doc,
175
175
  contentType: "json",
176
176
  editable: e,
177
177
  immediatelyRender: !1,
178
178
  editorProps: {
179
- attributes: { class: d === "document" ? "docs-prose min-h-[520px] max-w-none px-0 pb-20 pt-5 outline-none" : "docs-prose min-h-[420px] max-w-none px-5 py-5 outline-none", "aria-label": s, role: e ? "textbox" : "document", "aria-multiline": e ? "true" : "false" },
180
- handlePaste: (a, u) => {
181
- var D, N, w;
182
- const m = [...((D = u.clipboardData) == null ? void 0 : D.files) ?? []].find((L) => L.type.startsWith("image/"));
183
- if (m && z)
184
- return Se(m), !0;
185
- const v = ((N = u.clipboardData) == null ? void 0 : N.getData("text/plain")) ?? "";
186
- return as(v) ? ((w = X.current) == null || w.commands.insertContent(v, { contentType: "markdown" }), !0) : !1;
179
+ attributes: { class: d === "document" ? "docs-prose min-h-[520px] max-w-none px-0 pb-20 pt-5 outline-none" : "docs-prose min-h-[420px] max-w-none px-5 py-5 outline-none", "aria-label": n, role: e ? "textbox" : "document", "aria-multiline": e ? "true" : "false" },
180
+ handlePaste: (a, p) => {
181
+ var D, N, S;
182
+ const g = [...((D = p.clipboardData) == null ? void 0 : D.files) ?? []].find((L) => L.type.startsWith("image/"));
183
+ if (g && E)
184
+ return ke(g), !0;
185
+ const y = ((N = p.clipboardData) == null ? void 0 : N.getData("text/plain")) ?? "";
186
+ return cn(y) ? ((S = X.current) == null || S.commands.insertContent(y, { contentType: "markdown" }), !0) : !1;
187
187
  },
188
- handleDrop: (a, u) => {
188
+ handleDrop: (a, p) => {
189
189
  var D, N;
190
- const m = [...((D = u.dataTransfer) == null ? void 0 : D.files) ?? []].find((w) => w.type.startsWith("image/"));
191
- if (!m || !z) return !1;
192
- const v = (N = a.posAtCoords({ left: u.clientX, top: u.clientY })) == null ? void 0 : N.pos;
193
- return Se(m, v), !0;
190
+ const g = [...((D = p.dataTransfer) == null ? void 0 : D.files) ?? []].find((S) => S.type.startsWith("image/"));
191
+ if (!g || !E) return !1;
192
+ const y = (N = a.posAtCoords({ left: p.clientX, top: p.clientY })) == null ? void 0 : N.pos;
193
+ return ke(g, y), !0;
194
194
  },
195
- handleKeyDown: (a, u) => {
196
- if (!e || !(u.metaKey || u.ctrlKey) || u.key.toLowerCase() !== "k") return !1;
197
- u.preventDefault(), u.stopPropagation();
198
- const m = X.current;
199
- return be(String((m == null ? void 0 : m.getAttributes("link").href) ?? "https://")), ne(!0), !0;
195
+ handleKeyDown: (a, p) => {
196
+ if (!e || !(p.metaKey || p.ctrlKey) || p.key.toLowerCase() !== "k") return !1;
197
+ p.preventDefault(), p.stopPropagation();
198
+ const g = X.current;
199
+ return be(String((g == null ? void 0 : g.getAttributes("link").href) ?? "https://")), se(!0), !0;
200
200
  }
201
201
  },
202
- onUpdate: ({ editor: a, transaction: u }) => {
203
- Oe(a.state.doc.textBetween(Math.max(0, a.state.doc.content.size - 2), a.state.doc.content.size, " ").endsWith("/")), !W.current && !u.getMeta("docsAssetProjection") && (I == null || I(Pe(a.getJSON())));
202
+ onUpdate: ({ editor: a, transaction: p }) => {
203
+ _e(a.state.doc.textBetween(Math.max(0, a.state.doc.content.size - 2), a.state.doc.content.size, " ").endsWith("/")), !W.current && !p.getMeta("docsAssetProjection") && (m == null || m(Me(a.getJSON())));
204
204
  }
205
205
  });
206
- Ne(() => (X.current = o, () => {
206
+ Ie(() => (X.current = o, () => {
207
207
  X.current = null;
208
- }), [o]), Ne(() => {
208
+ }), [o]), Ie(() => {
209
209
  o == null || o.setEditable(e);
210
- }, [e, o]), Vn(() => {
210
+ }, [e, o]), Hs(() => {
211
211
  if (!o || C) return;
212
- const a = (n ?? vt()).doc;
212
+ const a = (s ?? vt()).doc;
213
213
  if (JSON.stringify(o.getJSON()) !== JSON.stringify(a)) {
214
214
  W.current = !0;
215
215
  try {
216
- is(o, a);
216
+ on(o, a);
217
217
  } finally {
218
218
  W.current = !1;
219
219
  }
220
220
  }
221
- }, [C, o, n]), Ne(() => {
221
+ }, [C, o, s]), Ie(() => {
222
222
  if (!o || !me) return;
223
- let a = !1, u;
224
- const m = [];
225
- return o.state.doc.descendants((v, D) => {
226
- const N = v.type.name === "image" ? String(v.attrs.asset_id ?? "") : "";
227
- N && m.push({ assetId: N, position: D });
228
- }), Promise.allSettled(m.map(async (v) => ({ ...v, ...await me(v.assetId) }))).then((v) => {
223
+ let a = !1, p;
224
+ const g = [];
225
+ return o.state.doc.descendants((y, D) => {
226
+ const N = y.type.name === "image" ? String(y.attrs.asset_id ?? "") : "";
227
+ N && g.push({ assetId: N, position: D });
228
+ }), Promise.allSettled(g.map(async (y) => ({ ...y, ...await me(y.assetId) }))).then((y) => {
229
229
  if (a) return;
230
230
  let D = o.state.tr, N = Number.POSITIVE_INFINITY;
231
- for (const w of v) {
232
- if (w.status !== "fulfilled" || !w.value.url) continue;
233
- const L = D.doc.nodeAt(w.value.position);
234
- if (!(!L || String(L.attrs.asset_id ?? "") !== w.value.assetId) && (D = D.setNodeMarkup(w.value.position, void 0, { ...L.attrs, src: w.value.url }), w.value.expiresAt !== void 0)) {
235
- const Je = new Date(w.value.expiresAt).getTime();
236
- Number.isFinite(Je) && (N = Math.min(N, Je));
231
+ for (const S of y) {
232
+ if (S.status !== "fulfilled" || !S.value.url) continue;
233
+ const L = D.doc.nodeAt(S.value.position);
234
+ 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) && (N = Math.min(N, Ke));
237
237
  }
238
238
  }
239
- D.docChanged && o.view.dispatch(D.setMeta("docsAssetProjection", !0).setMeta("addToHistory", !1)), Number.isFinite(N) && (u = setTimeout(() => Ft((w) => w + 1), Math.max(1e3, N - Date.now() - 3e4)));
239
+ D.docChanged && o.view.dispatch(D.setMeta("docsAssetProjection", !0).setMeta("addToHistory", !1)), Number.isFinite(N) && (p = setTimeout(() => Ft((S) => S + 1), Math.max(1e3, N - Date.now() - 3e4)));
240
240
  }), () => {
241
- a = !0, u && clearTimeout(u);
241
+ a = !0, p && clearTimeout(p);
242
242
  };
243
- }, [o, $t, me, n]);
244
- const ie = (a) => {
245
- a(), Oe(!1), o == null || o.commands.focus();
246
- }, je = () => {
247
- o && (be(String(o.getAttributes("link").href ?? "https://")), ne(!0));
243
+ }, [o, $t, me, s]);
244
+ 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));
248
248
  }, Jt = () => {
249
249
  if (!o) return;
250
- const a = Be.trim();
251
- a ? o.chain().focus().extendMarkRange("link").setLink({ href: a }).run() : o.chain().focus().unsetLink().run(), ne(!1);
252
- }, ke = (a) => {
253
- if (!o || !S) return;
254
- const { from: u, to: m } = o.state.selection, v = o.state.doc.textBetween(u, m, `
250
+ const a = je.trim();
251
+ a ? o.chain().focus().extendMarkRange("link").setLink({ href: a }).run() : o.chain().focus().unsetLink().run(), se(!1);
252
+ }, Se = (a) => {
253
+ if (!o || !k) return;
254
+ const { from: p, to: g } = o.state.selection, y = o.state.doc.textBetween(p, g, `
255
255
  `), D = [];
256
- o.state.doc.nodesBetween(u, Math.max(u + 1, m), (w) => {
257
- if (w.type.name !== "image") return;
258
- const L = String(w.attrs.asset_id ?? "");
256
+ o.state.doc.nodesBetween(p, Math.max(p + 1, g), (S) => {
257
+ if (S.type.name !== "image") return;
258
+ const L = String(S.attrs.asset_id ?? "");
259
259
  L && D.push({ assetId: L });
260
260
  });
261
- const N = T[a] ?? `${a === "explain" ? "Explain" : a === "rewrite" ? "Rewrite" : "Continue"} the selected document content.`;
262
- R(""), H(void 0), we(void 0), S.submit({
261
+ const N = A[a] ?? `${a === "explain" ? "Explain" : a === "rewrite" ? "Rewrite" : "Continue"} the selected document content.`;
262
+ R(""), H(void 0), we(void 0), k.submit({
263
263
  version: 2,
264
264
  operation: a,
265
- documentId: y,
266
- nodeId: x,
267
- baseRevision: String(b),
268
- range: { from: u, to: m },
269
- selection: v,
265
+ documentId: w,
266
+ nodeId: I,
267
+ baseRevision: String(v),
268
+ range: { from: p, to: g },
269
+ selection: y,
270
270
  instruction: N,
271
271
  context: `${o.getText({ blockSeparator: `
272
272
  ` }).slice(-12e3)}${D.length ? `
273
273
 
274
- [Selected images: ${D.map((w) => w.assetId).join(", ")}]` : ""}`,
275
- originalSlice: o.state.doc.slice(u, m).toJSON(),
274
+ [Selected images: ${D.map((S) => S.assetId).join(", ")}]` : ""}`,
275
+ originalSlice: o.state.doc.slice(p, g).toJSON(),
276
276
  images: D,
277
- source: f
278
- }).catch((w) => R(w instanceof Error ? w.message : String(w)));
277
+ source: u
278
+ }).catch((S) => R(S instanceof Error ? S.message : String(S)));
279
279
  }, Kt = async () => {
280
- if (!o || !k.operation || !k.output) return;
281
- const a = It(o, { documentId: y, nodeId: x, baseRevision: String(b) }, k.operation);
280
+ if (!o || !x.operation || !x.output) return;
281
+ const a = Nt(o, { documentId: w, nodeId: I, baseRevision: String(v) }, x.operation);
282
282
  if (a) {
283
- H(a), R(c("richDocument.aiConflict"));
283
+ H(a), R(l("richDocument.aiConflict"));
284
284
  return;
285
285
  }
286
286
  W.current = !0;
287
- let u;
287
+ let p;
288
288
  try {
289
- u = Gn(o, { documentId: y, nodeId: x, baseRevision: String(b) }, k.operation, k.output);
289
+ p = Gs(o, { documentId: w, nodeId: I, baseRevision: String(v) }, x.operation, x.output);
290
290
  } finally {
291
291
  W.current = !1;
292
292
  }
293
- if (!u) {
294
- H("invalid_slice"), R(c("richDocument.aiConflict"));
293
+ if (!p) {
294
+ H("invalid_slice"), R(l("richDocument.aiConflict"));
295
295
  return;
296
296
  }
297
- const m = Pe(o.getJSON());
298
- re(!0), o.setEditable(!1);
297
+ const g = Me(o.getJSON());
298
+ ie(!0), o.setEditable(!1);
299
299
  try {
300
- const v = String(await F({ kind: "apply", value: m, nodeId: x, expectedRevision: String(b) }));
301
- R(""), H(void 0), we({ ...u, revision: v }), I == null || I(m, v);
300
+ const y = String(await U({ kind: "apply", value: g, nodeId: I, expectedRevision: String(v) }));
301
+ R(""), H(void 0), we({ ...p, revision: y }), m == null || m(g, y);
302
302
  } catch {
303
- Wn(o, u.range, u.original, u.generated), R(c("richDocument.aiConflict"));
303
+ Ws(o, p.range, p.original, p.generated), R(l("richDocument.aiConflict"));
304
304
  } finally {
305
- o.setEditable(e), re(!1);
305
+ o.setEditable(e), ie(!1);
306
306
  }
307
307
  }, Xt = async () => {
308
308
  if (!(!o || !K)) {
309
- re(!0), o.setEditable(!1);
309
+ ie(!0), o.setEditable(!1);
310
310
  try {
311
- const a = await Yn(o, K, (u) => F({ kind: "rollback", value: u, nodeId: x, expectedRevision: K.revision }));
311
+ const a = await Ys(o, K, (p) => U({ kind: "rollback", value: p, nodeId: I, expectedRevision: K.revision }));
312
312
  if (!a) {
313
- H("selection"), R(c("richDocument.aiConflict"));
313
+ H("selection"), R(l("richDocument.aiConflict"));
314
314
  return;
315
315
  }
316
- R(""), H(void 0), we(void 0), I == null || I(a.value, a.revision);
316
+ R(""), H(void 0), we(void 0), m == null || m(a.value, a.revision);
317
317
  } catch {
318
- R(c("richDocument.aiConflict"));
318
+ R(l("richDocument.aiConflict"));
319
319
  } finally {
320
- o.setEditable(e), re(!1);
320
+ o.setEditable(e), ie(!1);
321
321
  }
322
322
  }
323
- }, g = (a, u, m, v) => /* @__PURE__ */ i(ae, { title: a, "aria-label": a, "aria-pressed": m, className: "aria-pressed:bg-surface-raised aria-pressed:text-ink", onClick: v, children: u }), Ve = (a, u, m) => /* @__PURE__ */ i(ae, { title: u, "aria-label": u, "aria-expanded": J === a, onMouseDown: (v) => v.preventDefault(), onClick: () => O((v) => v === a ? null : a), children: m }), Wt = (a) => {
323
+ }, b = (a, p, 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: p }), $e = (a, p, g) => /* @__PURE__ */ r(ae, { title: p, "aria-label": p, "aria-expanded": J === a, onMouseDown: (y) => y.preventDefault(), onClick: () => _((y) => y === a ? null : a), children: g }), Wt = (a) => {
324
324
  a(), ge(!1), o == null || o.commands.focus();
325
- }, $e = o ? [
326
- [c("richDocument.heading1"), /* @__PURE__ */ i(Ye, { size: 15, "aria-hidden": !0 }, "h1"), () => o.chain().focus().toggleHeading({ level: 1 }).run()],
327
- [c("richDocument.heading2"), /* @__PURE__ */ i(Ge, { size: 15, "aria-hidden": !0 }, "h2"), () => o.chain().focus().toggleHeading({ level: 2 }).run()],
328
- [c("richDocument.heading3"), /* @__PURE__ */ i(Qe, { size: 15, "aria-hidden": !0 }, "h3"), () => o.chain().focus().toggleHeading({ level: 3 }).run()],
329
- [c("richDocument.bulletList"), /* @__PURE__ */ i(Ze, { size: 15, "aria-hidden": !0 }, "bullet"), () => o.chain().focus().toggleBulletList().run()],
330
- [c("richDocument.orderedList"), /* @__PURE__ */ i(et, { size: 15, "aria-hidden": !0 }, "ordered"), () => o.chain().focus().toggleOrderedList().run()],
331
- [c("richDocument.taskList"), /* @__PURE__ */ i(tt, { size: 15, "aria-hidden": !0 }, "task"), () => o.chain().focus().toggleTaskList().run()],
332
- [c("richDocument.quote"), /* @__PURE__ */ i(nt, { size: 15, "aria-hidden": !0 }, "quote"), () => o.chain().focus().toggleBlockquote().run()],
333
- [c("richDocument.codeBlock"), /* @__PURE__ */ i(st, { size: 15, "aria-hidden": !0 }, "code"), () => o.chain().focus().toggleCodeBlock().run()],
334
- [c("richDocument.callout"), /* @__PURE__ */ i(rt, { size: 15, "aria-hidden": !0 }, "callout"), () => o.chain().focus().wrapIn("callout").run()],
335
- [c("richDocument.table"), /* @__PURE__ */ i(Ce, { size: 15, "aria-hidden": !0 }, "table"), () => o.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()]
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()]
336
336
  ] : [], Yt = o ? [
337
- [c("richDocument.paragraph"), /* @__PURE__ */ i(it, { size: 15, "aria-hidden": !0 }, "p"), () => o.chain().focus().setParagraph().run()],
338
- ...$e.slice(0, 8)
337
+ [l("richDocument.paragraph"), /* @__PURE__ */ r(rt, { size: 15, "aria-hidden": !0 }, "p"), () => o.chain().focus().setParagraph().run()],
338
+ ...Fe.slice(0, 8)
339
339
  ] : [];
340
- return /* @__PURE__ */ h("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": y || void 0, "data-node-id": x || void 0, "data-base-revision": String(b) || void 0, "data-editable": e || void 0, "data-surface": d, onDragOver: (a) => z && a.preventDefault(), children: [
341
- e && o && /* @__PURE__ */ h(De, { label: s, 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
- g(c("richDocument.heading1"), /* @__PURE__ */ i(Ye, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 1 }), () => o.chain().focus().toggleHeading({ level: 1 }).run()),
343
- g(c("richDocument.heading2"), /* @__PURE__ */ i(Ge, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 2 }), () => o.chain().focus().toggleHeading({ level: 2 }).run()),
344
- g(c("richDocument.heading3"), /* @__PURE__ */ i(Qe, { size: 15, "aria-hidden": !0 }), o.isActive("heading", { level: 3 }), () => o.chain().focus().toggleHeading({ level: 3 }).run()),
345
- /* @__PURE__ */ i(j, {}),
346
- g(c("richDocument.bold"), /* @__PURE__ */ i(ot, { size: 15, "aria-hidden": !0 }), o.isActive("bold"), () => o.chain().focus().toggleBold().run()),
347
- g(c("richDocument.italic"), /* @__PURE__ */ i(at, { size: 15, "aria-hidden": !0 }), o.isActive("italic"), () => o.chain().focus().toggleItalic().run()),
348
- g(c("richDocument.underline"), /* @__PURE__ */ i(ct, { size: 15, "aria-hidden": !0 }), o.isActive("underline"), () => o.chain().focus().toggleUnderline().run()),
349
- g(c("richDocument.strike"), /* @__PURE__ */ i(lt, { size: 15, "aria-hidden": !0 }), o.isActive("strike"), () => o.chain().focus().toggleStrike().run()),
350
- g(c("richDocument.code"), /* @__PURE__ */ i(dt, { size: 15, "aria-hidden": !0 }), o.isActive("code"), () => o.chain().focus().toggleCode().run()),
351
- g(c("richDocument.link"), /* @__PURE__ */ i(ut, { size: 15, "aria-hidden": !0 }), o.isActive("link"), je),
352
- /* @__PURE__ */ i(j, {}),
353
- g(c("richDocument.bulletList"), /* @__PURE__ */ i(Ze, { size: 15, "aria-hidden": !0 }), o.isActive("bulletList"), () => o.chain().focus().toggleBulletList().run()),
354
- g(c("richDocument.orderedList"), /* @__PURE__ */ i(et, { size: 15, "aria-hidden": !0 }), o.isActive("orderedList"), () => o.chain().focus().toggleOrderedList().run()),
355
- g(c("richDocument.taskList"), /* @__PURE__ */ i(tt, { size: 15, "aria-hidden": !0 }), o.isActive("taskList"), () => o.chain().focus().toggleTaskList().run()),
356
- g(c("richDocument.quote"), /* @__PURE__ */ i(nt, { size: 15, "aria-hidden": !0 }), o.isActive("blockquote"), () => o.chain().focus().toggleBlockquote().run()),
357
- g(c("richDocument.codeBlock"), /* @__PURE__ */ i(st, { size: 15, "aria-hidden": !0 }), o.isActive("codeBlock"), () => o.chain().focus().toggleCodeBlock().run()),
358
- g(c("richDocument.rule"), /* @__PURE__ */ i(In, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().setHorizontalRule().run()),
359
- g(c("richDocument.callout"), /* @__PURE__ */ i(rt, { size: 15, "aria-hidden": !0 }), o.isActive("callout"), () => o.chain().focus().wrapIn("callout").run()),
360
- g(c("richDocument.table"), /* @__PURE__ */ i(Ce, { size: 15, "aria-hidden": !0 }), o.isActive("table"), () => o.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()),
361
- z && g(c("richDocument.image"), /* @__PURE__ */ i(pt, { size: 15, "aria-hidden": !0 }), !1, () => {
340
+ return /* @__PURE__ */ h("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__ */ h(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()),
345
+ /* @__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),
352
+ /* @__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, () => {
362
362
  var a;
363
363
  return (a = ye.current) == null ? void 0 : a.click();
364
364
  })
365
365
  ] }),
366
- z && /* @__PURE__ */ i(Ue, { ref: ye, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", className: "sr-only", tabIndex: -1, onChange: (a) => {
367
- var m;
368
- const u = (m = a.target.files) == null ? void 0 : m[0];
369
- u && Se(u), a.currentTarget.value = "";
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) => {
367
+ var g;
368
+ const p = (g = a.target.files) == null ? void 0 : g[0];
369
+ p && ke(p), a.currentTarget.value = "";
370
370
  } }),
371
- e && o && /* @__PURE__ */ i(yn, { editor: o, options: { placement: "left-start" }, className: "z-40", children: /* @__PURE__ */ h("div", { className: "relative flex items-start gap-1", children: [
372
- /* @__PURE__ */ i(Te, { label: c("richDocument.insertBlock"), children: /* @__PURE__ */ i(A, { type: "button", "aria-label": c("richDocument.insertBlock"), "aria-expanded": _e, 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__ */ i(Cn, { size: 16, "aria-hidden": !0 }) }) }),
373
- S && /* @__PURE__ */ i(Te, { label: c("richDocument.aiContinue"), children: /* @__PURE__ */ i(A, { type: "button", "aria-label": c("richDocument.aiContinue"), onMouseDown: (a) => a.preventDefault(), onClick: () => ke("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__ */ i(ht, { size: 15, "aria-hidden": !0 }) }) }),
374
- _e && /* @__PURE__ */ h(oe, { label: c("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
- $e.map(([a, u, m]) => /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ h(A, { type: "button", onMouseDown: (v) => v.preventDefault(), onClick: () => Wt(m), 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
- u,
377
- /* @__PURE__ */ i("span", { children: a })
371
+ e && o && /* @__PURE__ */ r(ws, { editor: o, options: { placement: "left-start" }, className: "z-40", children: /* @__PURE__ */ h("div", { className: "relative flex items-start gap-1", children: [
372
+ /* @__PURE__ */ r(Ue, { label: l("richDocument.insertBlock"), children: /* @__PURE__ */ r(P, { 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(P, { 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__ */ h(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, p, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ h(P, { 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
+ p,
377
+ /* @__PURE__ */ r("span", { children: a })
378
378
  ] }) }, a)),
379
- z && /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ h(A, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
379
+ E && /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ h(P, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
380
380
  var a;
381
381
  ge(!1), (a = ye.current) == null || a.click();
382
382
  }, 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__ */ i(pt, { size: 15, "aria-hidden": !0 }),
384
- /* @__PURE__ */ i("span", { children: c("richDocument.image") })
383
+ /* @__PURE__ */ r(pt, { size: 15, "aria-hidden": !0 }),
384
+ /* @__PURE__ */ r("span", { children: l("richDocument.image") })
385
385
  ] }) })
386
386
  ] })
387
387
  ] }) }),
388
- e && o && /* @__PURE__ */ i(Xe, { editor: o, pluginKey: "richTextSelectionMenu", shouldShow: ({ editor: a, from: u, to: m }) => u !== m && !(a.state.selection instanceof Re), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ h("div", { className: "relative", children: [
389
- /* @__PURE__ */ h(De, { label: c("richDocument.formatSelection"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
390
- Ve("block", c("richDocument.paragraphStyle"), /* @__PURE__ */ h(Ke, { children: [
391
- /* @__PURE__ */ i(it, { size: 15, "aria-hidden": !0 }),
392
- /* @__PURE__ */ i(An, { size: 11, "aria-hidden": !0 })
388
+ e && o && /* @__PURE__ */ r(Xe, { editor: o, pluginKey: "richTextSelectionMenu", shouldShow: ({ editor: a, from: p, to: g }) => p !== g && !(a.state.selection instanceof ze), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ h("div", { className: "relative", children: [
389
+ /* @__PURE__ */ h(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__ */ h(Ee, { children: [
391
+ /* @__PURE__ */ r(rt, { size: 15, "aria-hidden": !0 }),
392
+ /* @__PURE__ */ r(Ns, { size: 11, "aria-hidden": !0 })
393
393
  ] })),
394
- Ve("align", c("richDocument.alignment"), /* @__PURE__ */ i(mt, { size: 15, "aria-hidden": !0 })),
395
- /* @__PURE__ */ i(j, {}),
396
- g(c("richDocument.bold"), /* @__PURE__ */ i(ot, { size: 15, "aria-hidden": !0 }), o.isActive("bold"), () => o.chain().focus().toggleBold().run()),
397
- g(c("richDocument.italic"), /* @__PURE__ */ i(at, { size: 15, "aria-hidden": !0 }), o.isActive("italic"), () => o.chain().focus().toggleItalic().run()),
398
- g(c("richDocument.underline"), /* @__PURE__ */ i(ct, { size: 15, "aria-hidden": !0 }), o.isActive("underline"), () => o.chain().focus().toggleUnderline().run()),
399
- g(c("richDocument.strike"), /* @__PURE__ */ i(lt, { size: 15, "aria-hidden": !0 }), o.isActive("strike"), () => o.chain().focus().toggleStrike().run()),
400
- g(c("richDocument.code"), /* @__PURE__ */ i(dt, { size: 15, "aria-hidden": !0 }), o.isActive("code"), () => o.chain().focus().toggleCode().run()),
401
- /* @__PURE__ */ h(We, { title: c("richDocument.colors"), open: J === "color", onOpenChange: (a) => O(a ? "color" : null), side: "bottom", align: "end", trigger: /* @__PURE__ */ i(ae, { title: c("richDocument.colors"), "aria-label": c("richDocument.colors"), "aria-expanded": J === "color", onMouseDown: (a) => a.preventDefault(), children: /* @__PURE__ */ i(ft, { size: 15, "aria-hidden": !0 }) }), children: [
402
- /* @__PURE__ */ i(Ie, { label: c("richDocument.textColor"), values: es, onChoose: (a) => {
403
- o.chain().focus().setColor(a).run(), O(null);
394
+ $e("align", l("richDocument.alignment"), /* @__PURE__ */ r(mt, { size: 15, "aria-hidden": !0 })),
395
+ /* @__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__ */ h(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(Ne, { label: l("richDocument.textColor"), values: en, onChoose: (a) => {
403
+ o.chain().focus().setColor(a).run(), _(null);
404
404
  } }),
405
- /* @__PURE__ */ i(Ie, { label: c("richDocument.backgroundColor"), values: de, onChoose: (a) => {
406
- o.chain().focus().setBackgroundColor(a).run(), O(null);
405
+ /* @__PURE__ */ r(Ne, { label: l("richDocument.backgroundColor"), values: de, onChoose: (a) => {
406
+ o.chain().focus().setBackgroundColor(a).run(), _(null);
407
407
  } }),
408
- /* @__PURE__ */ i(A, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
409
- o.chain().focus().unsetColor().unsetBackgroundColor().run(), O(null);
410
- }, className: "mt-2 min-h-9 w-full rounded-control text-caption text-graphite hover:bg-surface-hover hover:text-ink", children: c("richDocument.resetColors") })
408
+ /* @__PURE__ */ r(P, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
409
+ o.chain().focus().unsetColor().unsetBackgroundColor().run(), _(null);
410
+ }, 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
411
  ] }),
412
- g(c("richDocument.link"), /* @__PURE__ */ i(ut, { size: 15, "aria-hidden": !0 }), o.isActive("link"), je),
413
- S && /* @__PURE__ */ h(Ke, { children: [
414
- /* @__PURE__ */ i(j, {}),
415
- g(c("richDocument.aiExplain"), /* @__PURE__ */ i(ht, { size: 15, "aria-hidden": !0 }), !1, () => ke("explain")),
416
- g(c("richDocument.aiRewrite"), /* @__PURE__ */ i(En, { size: 15, "aria-hidden": !0 }), !1, () => ke("rewrite"))
412
+ b(l("richDocument.link"), /* @__PURE__ */ r(ut, { size: 15, "aria-hidden": !0 }), o.isActive("link"), Ve),
413
+ k && /* @__PURE__ */ h(Ee, { children: [
414
+ /* @__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(Ps, { size: 15, "aria-hidden": !0 }), !1, () => Se("rewrite"))
417
417
  ] })
418
418
  ] }),
419
- J === "block" && /* @__PURE__ */ i(oe, { label: c("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, u, m]) => /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ h(A, { type: "button", onMouseDown: (v) => v.preventDefault(), onClick: () => {
420
- m(), O(null);
419
+ 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, p, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ h(P, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => {
420
+ g(), _(null);
421
421
  }, 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: [
422
- u,
423
- /* @__PURE__ */ i("span", { children: a })
422
+ p,
423
+ /* @__PURE__ */ r("span", { children: a })
424
424
  ] }) }, a)) }),
425
- J === "align" && /* @__PURE__ */ i(oe, { label: c("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", c("richDocument.alignLeft"), /* @__PURE__ */ i(mt, { size: 15, "aria-hidden": !0 }, "left")], ["center", c("richDocument.alignCenter"), /* @__PURE__ */ i(xn, { size: 15, "aria-hidden": !0 }, "center")], ["right", c("richDocument.alignRight"), /* @__PURE__ */ i(Nn, { size: 15, "aria-hidden": !0 }, "right")]].map(([a, u, m]) => /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ h(A, { type: "button", onMouseDown: (v) => v.preventDefault(), onClick: () => {
426
- o.chain().focus().setTextAlign(String(a)).run(), O(null);
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, p, g]) => /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ h(P, { type: "button", onMouseDown: (y) => y.preventDefault(), onClick: () => {
426
+ o.chain().focus().setTextAlign(String(a)).run(), _(null);
427
427
  }, 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
- m,
429
- /* @__PURE__ */ i("span", { children: u })
428
+ g,
429
+ /* @__PURE__ */ r("span", { children: p })
430
430
  ] }) }, String(a))) })
431
431
  ] }) }),
432
- e && o && /* @__PURE__ */ i(Xe, { editor: o, pluginKey: "richTableMenu", shouldShow: ({ editor: a, from: u, to: m }) => (u === m || a.state.selection instanceof Re) && rs(a), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ i("div", { className: "relative", children: /* @__PURE__ */ h(De, { label: c("richDocument.tableActions"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
433
- g(c("richDocument.addRowBefore"), /* @__PURE__ */ i(zn, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addRowBefore().run()),
434
- g(c("richDocument.addRowAfter"), /* @__PURE__ */ i(Rn, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addRowAfter().run()),
435
- g(c("richDocument.deleteRow"), /* @__PURE__ */ i(Un, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteRow().run()),
436
- /* @__PURE__ */ i(j, {}),
437
- g(c("richDocument.addColumnBefore"), /* @__PURE__ */ i(Tn, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addColumnBefore().run()),
438
- g(c("richDocument.addColumnAfter"), /* @__PURE__ */ i(Ln, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().addColumnAfter().run()),
439
- g(c("richDocument.deleteColumn"), /* @__PURE__ */ i(Pn, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteColumn().run()),
440
- /* @__PURE__ */ i(j, {}),
441
- g(c("richDocument.mergeCells"), /* @__PURE__ */ i(Mn, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().mergeCells().run()),
442
- g(c("richDocument.splitCell"), /* @__PURE__ */ i(On, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().splitCell().run()),
443
- /* @__PURE__ */ h(We, { title: c("richDocument.cellBackgroundColor"), open: qe, onOpenChange: ve, side: "bottom", align: "end", trigger: /* @__PURE__ */ i(ae, { title: c("richDocument.cellBackgroundColor"), "aria-label": c("richDocument.cellBackgroundColor"), "aria-expanded": qe, onMouseDown: (a) => a.preventDefault(), children: /* @__PURE__ */ i(ft, { size: 15, "aria-hidden": !0 }) }), children: [
444
- /* @__PURE__ */ i(Ie, { label: c("richDocument.cellBackgroundColor"), values: de, onChoose: (a) => {
432
+ e && o && /* @__PURE__ */ r(Xe, { editor: o, pluginKey: "richTableMenu", shouldShow: ({ editor: a, from: p, to: g }) => (p === g || a.state.selection instanceof ze) && rn(a), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ r("div", { className: "relative", children: /* @__PURE__ */ h(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()),
436
+ /* @__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()),
440
+ /* @__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__ */ h(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(Ne, { label: l("richDocument.cellBackgroundColor"), values: de, onChoose: (a) => {
445
445
  o.chain().focus().setCellAttribute("backgroundColor", a).run(), ve(!1);
446
446
  } }),
447
- /* @__PURE__ */ i(A, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
447
+ /* @__PURE__ */ r(P, { type: "button", onMouseDown: (a) => a.preventDefault(), onClick: () => {
448
448
  o.chain().focus().setCellAttribute("backgroundColor", null).run(), ve(!1);
449
- }, className: "mt-2 min-h-9 w-full rounded-control text-caption text-graphite hover:bg-surface-hover hover:text-ink", children: c("richDocument.resetCellBackground") })
449
+ }, 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
450
  ] }),
451
- g(c("richDocument.toggleHeaderRow"), /* @__PURE__ */ i(Ce, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().toggleHeaderRow().run()),
452
- g(c("richDocument.deleteTable"), /* @__PURE__ */ i(Nt, { size: 15, "aria-hidden": !0 }), !1, () => o.chain().focus().deleteTable().run())
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())
453
453
  ] }) }) }),
454
- /* @__PURE__ */ i(wn, { editor: o }),
455
- S && !k.operation && se && /* @__PURE__ */ i("div", { role: "alert", className: "m-4 text-caption text-danger", children: se }),
456
- S && k.operation && /* @__PURE__ */ h("aside", { "data-testid": "document-assistant-operation", "data-run-id": k.runId, "data-status": k.status, "data-document-id": k.operation.documentId, "data-node-id": k.operation.nodeId, "data-base-revision": k.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: [
454
+ /* @__PURE__ */ r(bs, { editor: o }),
455
+ k && !x.operation && ne && /* @__PURE__ */ r("div", { role: "alert", className: "m-4 text-caption text-danger", children: ne }),
456
+ k && x.operation && /* @__PURE__ */ h("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
457
  /* @__PURE__ */ h("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
458
- /* @__PURE__ */ i("strong", { className: "font-sohne text-body-sm text-ink", children: c(`richDocument.ai.${k.operation.operation}`) }),
459
- /* @__PURE__ */ i("span", { className: "text-caption text-graphite", children: k.status })
458
+ /* @__PURE__ */ r("strong", { className: "font-sohne text-body-sm text-ink", children: l(`richDocument.ai.${x.operation.operation}`) }),
459
+ /* @__PURE__ */ r("span", { className: "text-caption text-graphite", children: x.status })
460
460
  ] }),
461
- k.output && /* @__PURE__ */ i("div", { "data-testid": "document-assistant-output", className: "whitespace-pre-wrap text-body-sm text-ink", children: k.output }),
461
+ x.output && /* @__PURE__ */ r("div", { "data-testid": "document-assistant-output", className: "whitespace-pre-wrap text-body-sm text-ink", children: x.output }),
462
462
  /* @__PURE__ */ h("div", { className: "flex flex-wrap gap-2", children: [
463
- k.status === "waiting_for_input" && /* @__PURE__ */ i(U, { size: "compact", onClick: () => void S.resolvePending().catch((a) => R(a instanceof Error ? a.message : String(a))), children: c("richDocument.aiResume") }),
464
- k.status === "completed" && k.operation.operation !== "explain" && k.output && !K && /* @__PURE__ */ i(U, { size: "compact", disabled: He, onClick: () => void Kt(), children: c("richDocument.aiApply") }),
465
- K && /* @__PURE__ */ i(U, { size: "compact", variant: "secondary", disabled: He, onClick: () => void Xt(), children: c("richDocument.aiRollback") })
463
+ 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") })
466
466
  ] }),
467
- (se || k.error) && /* @__PURE__ */ i("div", { role: "alert", className: "text-caption text-danger", children: se || ((Fe = k.error) == null ? void 0 : Fe.message) })
467
+ (ne || x.error) && /* @__PURE__ */ r("div", { role: "alert", className: "text-caption text-danger", children: ne || ((Je = x.error) == null ? void 0 : Je.message) })
468
468
  ] }),
469
- e && Ht && o && /* @__PURE__ */ h(oe, { label: c("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
- /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ i(A, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => ie(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).toggleHeading({ level: 2 }).run()), children: c("richDocument.heading") }) }),
471
- /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ i(A, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => ie(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).toggleTaskList().run()), children: c("richDocument.taskList") }) }),
472
- /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ i(A, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => ie(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).wrapIn("callout").run()), children: c("richDocument.callout") }) }),
473
- /* @__PURE__ */ i(P, { asChild: !0, children: /* @__PURE__ */ i(A, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => ie(() => o.chain().deleteRange({ from: o.state.selection.from - 1, to: o.state.selection.from }).insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()), children: c("richDocument.table") }) })
469
+ e && jt && o && /* @__PURE__ */ h(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
+ /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(P, { 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") }) }),
471
+ /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(P, { 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 }).toggleTaskList().run()), children: l("richDocument.taskList") }) }),
472
+ /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(P, { 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
+ /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ r(P, { 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
474
  ] }),
475
- /* @__PURE__ */ i(kn, { open: jt, onClose: () => ne(!1), title: r, closeLabel: c("common.close"), children: /* @__PURE__ */ h("div", { className: "space-y-4", children: [
476
- /* @__PURE__ */ i(Ue, { autoFocus: !0, type: "url", "aria-label": r, value: Be, onChange: (a) => be(a.target.value), placeholder: "https://" }),
477
- /* @__PURE__ */ i("div", { className: "flex justify-end", children: /* @__PURE__ */ i(A, { type: "button", onClick: Jt, className: "min-h-11 rounded-full bg-ink px-5 font-sohne text-caption text-pure-white", children: l }) })
475
+ /* @__PURE__ */ r(ks, { open: Ht, onClose: () => se(!1), title: i, closeLabel: l("common.close"), children: /* @__PURE__ */ h("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://" }),
477
+ /* @__PURE__ */ r("div", { className: "flex justify-end", children: /* @__PURE__ */ r(P, { type: "button", onClick: Jt, className: "min-h-11 rounded-full bg-ink px-5 font-sohne text-caption text-pure-white", children: c }) })
478
478
  ] }) })
479
479
  ] });
480
480
  }
481
- const as = (n) => /(^|\n)(#{1,3} |[-*+] |\d+\. |> |```|---(?:\n|$)|- \[[ xX]\] )|\|.+\|\n\|(?:\s*:?-+:?\s*\|)+|\*\*[^*]+\*\*|~~[^~]+~~|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)]+\)/m.test(n);
482
- function Ie({ label: n, values: e, onChoose: t }) {
481
+ const cn = (s) => /(^|\n)(#{1,3} |[-*+] |\d+\. |> |```|---(?:\n|$)|- \[[ xX]\] )|\|.+\|\n\|(?:\s*:?-+:?\s*\|)+|\*\*[^*]+\*\*|~~[^~]+~~|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)]+\)/m.test(s);
482
+ function Ne({ label: s, values: e, onChoose: t }) {
483
483
  return /* @__PURE__ */ h("fieldset", { className: "mb-2", children: [
484
- /* @__PURE__ */ i("legend", { className: "mb-1 font-sohne text-caption text-graphite", children: n }),
485
- /* @__PURE__ */ i("div", { className: "flex flex-wrap gap-1", children: e.map((s, r) => {
486
- const l = `${n} ${r + 1}`;
487
- return /* @__PURE__ */ i(Te, { label: l, children: /* @__PURE__ */ i(A, { type: "button", "aria-label": l, onMouseDown: (d) => d.preventDefault(), onClick: () => t(s), className: "size-8 rounded-control border border-border transition-transform hover:-translate-y-px hover:ring-2 hover:ring-rust/35", style: { backgroundColor: s } }) }, s);
484
+ /* @__PURE__ */ r("legend", { className: "mb-1 font-sohne text-caption text-graphite", children: s }),
485
+ /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-1", children: e.map((n, i) => {
486
+ const c = `${s} ${i + 1}`;
487
+ return /* @__PURE__ */ r(Ue, { label: c, children: /* @__PURE__ */ r(P, { 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
488
  }) })
489
489
  ] });
490
490
  }
491
- const bt = (n, e) => {
492
- const t = n == null ? void 0 : n.target;
491
+ const bt = (s, e) => {
492
+ const t = s == null ? void 0 : s.target;
493
493
  return (t == null ? void 0 : t.case) === "nodeId" ? `node:${t.value}` : `space:${(t == null ? void 0 : t.value) || e}`;
494
- }, wt = {
494
+ }, ln = (s) => s instanceof Error ? s : new Error(String(s)), wt = {
495
+ nextPageTokens: {},
495
496
  spaces: [],
496
497
  documents: [],
497
498
  nodes: [],
@@ -501,133 +502,242 @@ const bt = (n, e) => {
501
502
  invites: [],
502
503
  loading: !1
503
504
  };
504
- class vr {
505
+ class wi {
505
506
  constructor(e, t = "") {
506
- p(this, "state");
507
- p(this, "listeners", /* @__PURE__ */ new Set());
508
- p(this, "generation", 0);
509
- p(this, "getSnapshot", () => this.state);
510
- p(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
511
- p(this, "createSpace", (e) => this.run(async () => ({ spaces: [await this.transport.createSpace(e), ...this.state.spaces] })));
512
- p(this, "updateSpace", (e) => this.run(async () => {
507
+ f(this, "state");
508
+ f(this, "listeners", /* @__PURE__ */ new Set());
509
+ f(this, "generation", 0);
510
+ f(this, "getSnapshot", () => this.state);
511
+ f(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
512
+ f(this, "createSpace", (e) => this.run(async () => ({ spaces: [await this.transport.createSpace(e), ...this.state.spaces] })));
513
+ f(this, "updateSpace", (e) => this.run(async () => {
513
514
  const t = await this.transport.updateSpace(e);
514
- return { spaces: this.state.spaces.map((s) => s.id === t.id ? t : s) };
515
+ return { spaces: this.state.spaces.map((n) => n.id === t.id ? t : n) };
515
516
  }));
516
- p(this, "archiveSpace", (e) => this.run(async () => {
517
+ f(this, "archiveSpace", (e) => this.run(async () => {
517
518
  const t = await this.transport.archiveSpace(e);
518
- return { spaces: this.state.spaces.map((s) => s.id === t.id ? t : s) };
519
+ return { spacePermissions: void 0, nodePermissions: void 0, spaces: this.state.spaces.map((n) => n.id === t.id ? t : n) };
519
520
  }));
520
- p(this, "leaveSpace", (e) => this.run(async () => (await this.transport.leaveSpace(e), { spaces: this.state.spaces.filter((t) => t.id !== e.spaceId) })));
521
- p(this, "createNode", (e) => this.run(async () => {
521
+ f(this, "leaveSpace", (e) => this.run(async () => (await this.transport.leaveSpace(e), { spacePermissions: void 0, nodePermissions: void 0, spaces: this.state.spaces.filter((t) => t.id !== e.spaceId) })));
522
+ f(this, "createNode", (e) => this.run(async () => {
522
523
  const t = await this.transport.createNode(e);
523
524
  return { nodes: [...this.state.nodes, t], documents: t.kind === G.NodeKind.DOCUMENT ? [...this.state.documents, t] : this.state.documents };
524
525
  }));
525
- p(this, "updateNode", (e) => this.run(async () => {
526
+ f(this, "updateNode", (e) => this.run(async () => {
526
527
  const t = await this.transport.updateNode(e);
527
528
  return this.replaceNode(t);
528
529
  }));
529
- p(this, "moveNode", (e) => this.run(async () => {
530
+ f(this, "moveNode", (e) => this.run(async () => {
530
531
  const t = await this.transport.moveNode(e);
531
532
  return this.replaceNode(t);
532
533
  }));
533
- p(this, "deleteNode", (e) => this.run(async () => {
534
- const t = this.state.documents.find((s) => s.id === e.nodeId) ?? this.state.nodes.find((s) => s.id === e.nodeId);
535
- return await this.transport.deleteNode(e), { nodes: this.state.nodes.filter((s) => s.id !== e.nodeId), documents: this.state.documents.filter((s) => s.id !== e.nodeId), trash: t ? [...this.state.trash, t] : this.state.trash };
534
+ f(this, "deleteNode", (e) => this.run(async () => {
535
+ const t = this.state.documents.find((n) => n.id === e.nodeId) ?? this.state.nodes.find((n) => n.id === e.nodeId);
536
+ return await this.transport.deleteNode(e), { nodes: this.state.nodes.filter((n) => n.id !== e.nodeId), documents: this.state.documents.filter((n) => n.id !== e.nodeId), trash: t ? [...this.state.trash, t] : this.state.trash };
536
537
  }));
537
- p(this, "restoreNode", (e) => this.run(async () => {
538
+ f(this, "restoreNode", (e) => this.run(async () => {
538
539
  const t = await this.transport.restoreNode(e);
539
- return { nodes: [...this.state.nodes, t], documents: t.kind === G.NodeKind.DOCUMENT ? [...this.state.documents, t] : this.state.documents, trash: this.state.trash.filter((s) => s.id !== t.id) };
540
+ return { nodes: [...this.state.nodes, t], documents: t.kind === G.NodeKind.DOCUMENT ? [...this.state.documents, t] : this.state.documents, trash: this.state.trash.filter((n) => n.id !== t.id) };
540
541
  }));
541
- p(this, "restoreRevision", async (e) => {
542
+ f(this, "restoreRevision", async (e) => {
542
543
  const t = e.nodeId;
543
544
  if (!t) throw new Error("node ID is required");
544
- const s = this.generation, r = await this.transport.restoreRevision(e);
545
- return s === this.generation && await this.openNode(t), r;
545
+ const n = this.generation, i = await this.transport.restoreRevision(e);
546
+ return n === this.generation && await this.openNode(t), i;
546
547
  });
547
- p(this, "setAcl", (e) => this.run(async () => {
548
+ f(this, "setAcl", (e) => this.run(async () => {
548
549
  const t = await this.transport.setAcl(e);
549
- return { acl: [...this.state.acl.filter((s) => s.id !== t.id), t] };
550
+ return { spacePermissions: void 0, nodePermissions: void 0, acl: [...this.state.acl.filter((n) => n.id !== t.id), t] };
550
551
  }));
551
- p(this, "revokeAcl", (e) => this.run(async () => {
552
+ f(this, "revokeAcl", (e) => this.run(async () => {
552
553
  await this.transport.revokeAcl(e);
553
554
  const t = bt(e.resource, e.spaceId ?? "");
554
- return { acl: this.state.acl.filter((s) => s.subjectId !== e.subjectId || bt(s.resource, s.spaceId) !== t) };
555
+ return { spacePermissions: void 0, nodePermissions: void 0, acl: this.state.acl.filter((n) => n.subjectId !== e.subjectId || bt(n.resource, n.spaceId) !== t) };
555
556
  }));
556
- p(this, "createInvite", (e) => this.run(async () => {
557
+ f(this, "createInvite", (e) => this.run(async () => {
557
558
  const t = await this.transport.createInvite(e);
558
559
  return { invites: [...this.state.invites, t] };
559
560
  }));
560
- p(this, "revokeInvite", (e) => this.run(async () => (await this.transport.revokeInvite(e), { invites: this.state.invites.filter((t) => t.id !== e.inviteId) })));
561
+ f(this, "revokeInvite", (e) => this.run(async () => (await this.transport.revokeInvite(e), { invites: this.state.invites.filter((t) => t.id !== e.inviteId) })));
561
562
  this.transport = e, this.state = { ...wt, scope: t };
562
563
  }
563
564
  setScope(e) {
564
565
  e !== this.state.scope && (this.generation += 1, this.state = { ...wt, scope: e }, this.listeners.forEach((t) => t()));
565
566
  }
566
567
  async refresh() {
567
- return this.run(async () => ({ spaces: (await this.transport.listSpaces({})).spaces }));
568
+ this.generation += 1;
569
+ const e = this.state.selectedSpaceId, t = this.generation, n = await this.run(async () => {
570
+ const i = await this.transport.listSpaces({ pageSize: 50 });
571
+ return { spaces: i.spaces, nextPageTokens: { ...this.state.nextPageTokens, spaces: i.nextPageToken } };
572
+ });
573
+ return e && t === this.generation && await this.openSpace(e), n;
568
574
  }
569
575
  async openSpace(e) {
570
- return this.generation += 1, this.run(async () => {
571
- const [t, s, r, l, d] = await Promise.all([
572
- this.transport.listChildren({ spaceId: e }),
573
- this.transport.listDocuments({ spaceId: e }),
574
- this.transport.listTrash({ spaceId: e }),
575
- this.transport.listAcl({ spaceId: e }),
576
- this.transport.listInvites({ spaceId: e })
576
+ var n;
577
+ this.generation += 1;
578
+ const t = this.generation;
579
+ if (this.update({
580
+ selectedSpaceId: e,
581
+ documents: [],
582
+ nodes: [],
583
+ trash: [],
584
+ acl: [],
585
+ invites: [],
586
+ selectedNode: void 0,
587
+ revisions: [],
588
+ index: void 0,
589
+ localDraft: void 0,
590
+ conflict: void 0,
591
+ spacePermissions: void 0,
592
+ nodePermissions: void 0,
593
+ managementError: void 0,
594
+ nextPageTokens: { spaces: this.state.nextPageTokens.spaces }
595
+ }), await this.run(async () => {
596
+ const i = await this.transport.getResourcePermissions({ spaceId: e });
597
+ if (t !== this.generation) return {};
598
+ const [c, d, u] = await Promise.all([
599
+ this.transport.listChildren({ spaceId: e, pageSize: 50 }),
600
+ this.transport.listDocuments({ spaceId: e, pageSize: 50 }),
601
+ this.transport.listTrash({ spaceId: e, pageSize: 50 })
577
602
  ]);
578
- return { selectedSpaceId: e, nodes: t.nodes, documents: s.nodes, trash: r.nodes, acl: l.entries, invites: d.invites, selectedNode: void 0, revisions: [], index: void 0, localDraft: void 0, conflict: void 0 };
579
- });
603
+ return {
604
+ spacePermissions: i,
605
+ nodes: c.nodes,
606
+ documents: d.nodes,
607
+ trash: u.nodes,
608
+ nextPageTokens: { ...this.state.nextPageTokens, nodes: c.nextPageToken, documents: d.nextPageToken, trash: u.nextPageToken }
609
+ };
610
+ }), t === this.generation && ((n = this.state.spacePermissions) != null && n.manage))
611
+ try {
612
+ const [i, c] = await Promise.all([
613
+ this.transport.listAcl({ spaceId: e, pageSize: 50 }),
614
+ this.transport.listInvites({ spaceId: e, pageSize: 50 })
615
+ ]);
616
+ t === this.generation && this.update({
617
+ acl: i.entries,
618
+ invites: c.invites,
619
+ nextPageTokens: { ...this.state.nextPageTokens, acl: i.nextPageToken, invites: c.nextPageToken }
620
+ });
621
+ } catch (i) {
622
+ t === this.generation && this.update({ spacePermissions: void 0, acl: [], invites: [], managementError: ln(i) });
623
+ }
580
624
  }
581
625
  async openNode(e) {
582
- this.generation += 1;
583
- const t = this.state.scope;
626
+ this.generation += 1, this.update({
627
+ selectedNode: void 0,
628
+ nodePermissions: void 0,
629
+ revisions: [],
630
+ index: void 0,
631
+ localDraft: void 0,
632
+ conflict: void 0,
633
+ nextPageTokens: { ...this.state.nextPageTokens, revisions: "" }
634
+ });
635
+ const t = this.generation;
584
636
  return this.run(async () => {
585
- const [s, r] = await Promise.all([
637
+ const [n, i, c] = await Promise.all([
586
638
  this.transport.getNode({ nodeId: e }),
587
- this.transport.listRevisions({ nodeId: e })
588
- ]), l = r.revisions.find((f) => f.number === s.revision), d = l && t === this.state.scope ? await this.transport.getRevisionIndexStatus({ nodeId: e, revisionId: l.id }) : void 0;
589
- return { selectedNode: s, revisions: r.revisions, index: d, localDraft: void 0, conflict: void 0 };
639
+ this.transport.listRevisions({ nodeId: e, pageSize: 50 }),
640
+ this.transport.getResourcePermissions({ resource: { target: { case: "nodeId", value: e } } })
641
+ ]), d = i.revisions.find((w) => w.number === n.revision), u = d && t === this.generation ? await this.transport.getRevisionIndexStatus({ nodeId: e, revisionId: d.id }) : void 0;
642
+ return {
643
+ selectedNode: n,
644
+ nodePermissions: c,
645
+ revisions: i.revisions,
646
+ index: u,
647
+ nextPageTokens: { ...this.state.nextPageTokens, revisions: i.nextPageToken }
648
+ };
590
649
  });
591
650
  }
592
- async save(e, t, s = "") {
593
- const r = this.requireNode(), l = this.generation;
594
- this.update({ localDraft: { schema: e, contentJson: t, name: s }, conflict: void 0 });
651
+ async loadMore(e) {
652
+ var c;
653
+ const t = this.state.nextPageTokens[e];
654
+ if (!t || this.state.loading) return;
655
+ const n = this.state.selectedSpaceId, i = (c = this.state.selectedNode) == null ? void 0 : c.id;
656
+ return this.run(async () => {
657
+ const d = { spaceId: n, nodeId: i, pageToken: t, pageSize: 50 };
658
+ let u, w;
659
+ switch (e) {
660
+ case "spaces": {
661
+ const v = await this.transport.listSpaces(d);
662
+ u = v.spaces, w = v.nextPageToken;
663
+ break;
664
+ }
665
+ case "nodes": {
666
+ const v = await this.transport.listChildren(d);
667
+ u = v.nodes, w = v.nextPageToken;
668
+ break;
669
+ }
670
+ case "documents": {
671
+ const v = await this.transport.listDocuments(d);
672
+ u = v.nodes, w = v.nextPageToken;
673
+ break;
674
+ }
675
+ case "trash": {
676
+ const v = await this.transport.listTrash(d);
677
+ u = v.nodes, w = v.nextPageToken;
678
+ break;
679
+ }
680
+ case "revisions": {
681
+ const v = await this.transport.listRevisions(d);
682
+ u = v.revisions, w = v.nextPageToken;
683
+ break;
684
+ }
685
+ case "acl": {
686
+ const v = await this.transport.listAcl(d);
687
+ u = v.entries, w = v.nextPageToken;
688
+ break;
689
+ }
690
+ case "invites": {
691
+ const v = await this.transport.listInvites(d);
692
+ u = v.invites, w = v.nextPageToken;
693
+ break;
694
+ }
695
+ }
696
+ if (w === t) throw new Error("server repeated a page token");
697
+ const I = new Map(this.state[e].map((v) => [v.id, v]));
698
+ for (const v of u) I.set(v.id, v);
699
+ return { [e]: [...I.values()], nextPageTokens: { ...this.state.nextPageTokens, [e]: w } };
700
+ });
701
+ }
702
+ async save(e, t, n = "") {
703
+ const i = this.requireNode(), c = this.generation;
704
+ this.update({ localDraft: { schema: e, contentJson: t, name: n }, conflict: void 0 });
595
705
  try {
596
- const d = await this.transport.saveRevision({ nodeId: r.id, expectedRevision: r.revision, schema: e, contentJson: t, name: s });
597
- return l === this.generation && await this.openNode(r.id), d;
706
+ const d = await this.transport.saveRevision({ nodeId: i.id, expectedRevision: i.revision, schema: e, contentJson: t, name: n });
707
+ return c === this.generation && await this.openNode(i.id), d;
598
708
  } catch (d) {
599
- const f = d instanceof Error ? d : new Error(String(d));
600
- throw l === this.generation && this.update({ loading: !1, conflict: f, error: void 0 }), f;
709
+ const u = d instanceof Error ? d : new Error(String(d));
710
+ throw c === this.generation && this.update({ loading: !1, conflict: u, error: void 0, spacePermissions: void 0, nodePermissions: void 0 }), u;
601
711
  }
602
712
  }
603
713
  async saveAsCopy(e) {
604
- const t = this.state.selectedSpaceId, s = this.state.localDraft;
605
- if (!t || !s) throw new Error("a selected space and local draft are required");
606
- const r = this.state.selectedNode, l = this.state.scope;
714
+ const t = this.state.selectedSpaceId, n = this.state.localDraft;
715
+ if (!t || !n) throw new Error("a selected space and local draft are required");
716
+ const i = this.state.selectedNode, c = this.state.scope;
607
717
  return this.run(async () => {
608
- var f;
718
+ var u;
609
719
  const d = await this.transport.createNode({
610
- node: { id: crypto.randomUUID(), spaceId: t, parentId: (r == null ? void 0 : r.parentId) ?? "", kind: G.NodeKind.DOCUMENT, title: e, slug: "", locale: (r == null ? void 0 : r.locale) ?? "" },
611
- expectedTreeVersion: ((f = this.state.spaces.find((y) => y.id === t)) == null ? void 0 : f.treeVersion) ?? 0n,
720
+ node: { id: crypto.randomUUID(), spaceId: t, parentId: (i == null ? void 0 : i.parentId) ?? "", kind: G.NodeKind.DOCUMENT, title: e, slug: "", locale: (i == null ? void 0 : i.locale) ?? "" },
721
+ expectedTreeVersion: ((u = this.state.spaces.find((w) => w.id === t)) == null ? void 0 : u.treeVersion) ?? 0n,
612
722
  commandId: crypto.randomUUID()
613
723
  });
614
- if (l !== this.state.scope) throw new Error("account scope changed during save");
615
- return await this.transport.saveRevision({ nodeId: d.id, expectedRevision: d.revision, ...s }), { selectedNode: d, conflict: void 0, localDraft: void 0 };
724
+ if (c !== this.state.scope) throw new Error("account scope changed during save");
725
+ return await this.transport.saveRevision({ nodeId: d.id, expectedRevision: d.revision, ...n }), { selectedNode: d, conflict: void 0, localDraft: void 0 };
616
726
  });
617
727
  }
618
728
  async retryIndex() {
619
- const e = this.requireNode(), t = this.state.revisions.find((s) => s.number === e.revision);
729
+ const e = this.requireNode(), t = this.state.revisions.find((n) => n.number === e.revision);
620
730
  if (!t) throw new Error("current revision is unavailable");
621
731
  return this.run(async () => ({ index: await this.transport.retryRevisionIndex({ nodeId: e.id, revisionId: t.id, force: !0, commandId: crypto.randomUUID() }) }));
622
732
  }
623
733
  async requestTranslation(e, t) {
624
- const s = this.requireNode();
625
- return this.run(async () => (await this.transport.requestTranslation({ sourceNodeId: s.id, targetNodeId: e, targetLocale: t, commandId: crypto.randomUUID() }), {}));
734
+ const n = this.requireNode();
735
+ return this.run(async () => (await this.transport.requestTranslation({ sourceNodeId: n.id, targetNodeId: e, targetLocale: t, commandId: crypto.randomUUID() }), {}));
626
736
  }
627
- async publishBundle(e, t, s) {
628
- const r = this.state.selectedSpaceId;
629
- if (!r) throw new Error("select a space before publishing");
630
- return this.run(async () => (await this.transport.publishReleaseBundle({ spaceId: r, version: e, sourceLocale: t, releases: s.map((l) => ({ locale: l.locale, nodes: [...l.nodes] })), commandId: crypto.randomUUID() }), {}));
737
+ async publishBundle(e, t, n) {
738
+ const i = this.state.selectedSpaceId;
739
+ if (!i) throw new Error("select a space before publishing");
740
+ return this.run(async () => (await this.transport.publishReleaseBundle({ spaceId: i, version: e, sourceLocale: t, releases: n.map((c) => ({ locale: c.locale, nodes: [...c.nodes] })), commandId: crypto.randomUUID() }), {}));
631
741
  }
632
742
  requireNode() {
633
743
  if (!this.state.selectedNode) throw new Error("select a document first");
@@ -635,236 +745,253 @@ class vr {
635
745
  }
636
746
  replaceNode(e) {
637
747
  var t;
638
- return { nodes: this.state.nodes.map((s) => s.id === e.id ? e : s), documents: this.state.documents.map((s) => s.id === e.id ? e : s), selectedNode: ((t = this.state.selectedNode) == null ? void 0 : t.id) === e.id ? e : this.state.selectedNode };
748
+ return { nodes: this.state.nodes.map((n) => n.id === e.id ? e : n), documents: this.state.documents.map((n) => n.id === e.id ? e : n), selectedNode: ((t = this.state.selectedNode) == null ? void 0 : t.id) === e.id ? e : this.state.selectedNode };
639
749
  }
640
750
  async run(e) {
641
751
  const t = this.generation;
642
752
  this.update({ loading: !0, error: void 0 });
643
753
  try {
644
- const s = await e();
645
- return t === this.generation && this.update({ ...s, loading: !1 }), s;
646
- } catch (s) {
647
- const r = s instanceof Error ? s : new Error(String(s));
648
- throw t === this.generation && this.update({ loading: !1, error: r }), r;
754
+ const n = await e();
755
+ return t === this.generation && this.update({ ...n, loading: !1 }), n;
756
+ } catch (n) {
757
+ const i = n instanceof Error ? n : new Error(String(n));
758
+ throw t === this.generation && this.update({ loading: !1, error: i, spacePermissions: void 0, nodePermissions: void 0 }), i;
649
759
  }
650
760
  }
651
761
  update(e) {
652
762
  this.state = { ...this.state, ...e }, this.listeners.forEach((t) => t());
653
763
  }
654
764
  }
655
- const cs = (n) => pe(n.subscribe, n.getSnapshot, n.getSnapshot);
656
- function br({ controller: n }) {
657
- var y, x;
658
- const e = cs(n), [t, s] = E(""), [r, l] = E("1.0.0"), d = e.documents.filter((b) => {
659
- var C;
660
- return b.id !== ((C = e.selectedNode) == null ? void 0 : C.id);
661
- }), f = d.find((b) => b.id === t) ?? d[0];
662
- return e.error && !e.spaces.length ? /* @__PURE__ */ i(B, { title: "Docs unavailable", description: e.error.message, action: { label: "Retry", onClick: () => void n.refresh() } }) : /* @__PURE__ */ h("section", { className: "af-docs-workbench", "aria-label": "Docs workbench", children: [
765
+ const dn = (s) => pe(s.subscribe, s.getSnapshot, s.getSnapshot);
766
+ function yi({ controller: s }) {
767
+ 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) => {
769
+ var U;
770
+ return m.id !== ((U = e.selectedNode) == null ? void 0 : U.id);
771
+ }), u = d.find((m) => m.id === t) ?? d[0];
772
+ return e.error && !e.spaces.length ? /* @__PURE__ */ r(j, { title: "Docs unavailable", description: e.error.message, action: { label: "Retry", onClick: () => void s.refresh() } }) : /* @__PURE__ */ h("section", { className: "af-docs-workbench", "aria-label": "Docs workbench", children: [
663
773
  /* @__PURE__ */ h("header", { children: [
664
774
  /* @__PURE__ */ h("div", { children: [
665
- /* @__PURE__ */ h(_, { children: [
666
- /* @__PURE__ */ i(_n, { size: 14, "aria-hidden": !0 }),
775
+ /* @__PURE__ */ h(q, { children: [
776
+ /* @__PURE__ */ r(Os, { size: 14, "aria-hidden": !0 }),
667
777
  " Docs repository"
668
778
  ] }),
669
- /* @__PURE__ */ h(q, { children: [
779
+ /* @__PURE__ */ h(B, { children: [
670
780
  e.spaces.length,
671
781
  " spaces"
672
782
  ] })
673
783
  ] }),
674
- /* @__PURE__ */ i(U, { size: "compact", variant: "secondary", disabled: e.loading, onClick: () => void n.refresh(), children: e.loading ? "Loading…" : "Refresh" })
784
+ /* @__PURE__ */ r(z, { size: "compact", variant: "secondary", disabled: e.loading, onClick: () => void s.refresh(), children: e.loading ? "Loading…" : "Refresh" })
675
785
  ] }),
676
- e.spaces.length ? /* @__PURE__ */ i("div", { className: "af-docs-workbench__list", children: e.spaces.map((b) => /* @__PURE__ */ h(Y, { as: "article", children: [
786
+ e.spaces.length ? /* @__PURE__ */ r("div", { className: "af-docs-workbench__list", children: e.spaces.map((m) => /* @__PURE__ */ h(Y, { as: "article", children: [
677
787
  /* @__PURE__ */ h("div", { children: [
678
- /* @__PURE__ */ i(_, { children: b.locale || "default locale" }),
679
- /* @__PURE__ */ i(q, { children: b.name }),
680
- /* @__PURE__ */ i("p", { children: b.id })
788
+ /* @__PURE__ */ r(q, { children: m.locale || "default locale" }),
789
+ /* @__PURE__ */ r(B, { children: m.name }),
790
+ /* @__PURE__ */ r("p", { children: m.id })
681
791
  ] }),
682
- /* @__PURE__ */ i(U, { size: "compact", onClick: () => void n.openSpace(b.id), children: "Open" })
683
- ] }, b.id)) }) : /* @__PURE__ */ i(B, { size: "sm", title: "No document spaces", description: "Accessible spaces appear here." }),
792
+ /* @__PURE__ */ r(z, { size: "compact", onClick: () => void s.openSpace(m.id), children: "Open" })
793
+ ] }, m.id)) }) : /* @__PURE__ */ r(j, { size: "sm", title: "No document spaces", description: "Accessible spaces appear here." }),
684
794
  e.selectedSpaceId && /* @__PURE__ */ h("div", { className: "af-docs-workbench__summary", children: [
685
- /* @__PURE__ */ h(V, { tone: "cool", children: [
795
+ /* @__PURE__ */ h($, { tone: "cool", children: [
686
796
  e.nodes.length,
687
797
  " root nodes · ",
688
798
  e.documents.length,
689
799
  " documents"
690
800
  ] }),
691
- /* @__PURE__ */ h(V, { tone: "neutral", children: [
692
- /* @__PURE__ */ i(Nt, { size: 12, "aria-hidden": !0 }),
801
+ /* @__PURE__ */ h($, { tone: "neutral", children: [
802
+ /* @__PURE__ */ r(It, { size: 12, "aria-hidden": !0 }),
693
803
  " ",
694
804
  e.trash.length,
695
805
  " trash"
696
806
  ] }),
697
- /* @__PURE__ */ h(V, { tone: "neutral", children: [
698
- /* @__PURE__ */ i(qn, { size: 12, "aria-hidden": !0 }),
699
- " ",
700
- e.acl.length,
701
- " grants"
702
- ] }),
703
- /* @__PURE__ */ h(V, { tone: "neutral", children: [
704
- e.invites.length,
705
- " invites"
807
+ ((w = e.spacePermissions) == null ? void 0 : w.manage) && /* @__PURE__ */ h(Ee, { children: [
808
+ /* @__PURE__ */ h($, { tone: "neutral", children: [
809
+ /* @__PURE__ */ r(_s, { size: 12, "aria-hidden": !0 }),
810
+ " ",
811
+ e.acl.length,
812
+ " grants"
813
+ ] }),
814
+ /* @__PURE__ */ h($, { tone: "neutral", children: [
815
+ e.invites.length,
816
+ " invites"
817
+ ] })
706
818
  ] })
707
819
  ] }),
708
- e.documents.length > 0 && /* @__PURE__ */ i("div", { className: "af-docs-workbench__list", children: e.documents.map((b) => /* @__PURE__ */ h(Y, { as: "article", children: [
820
+ e.documents.length > 0 && /* @__PURE__ */ r("div", { className: "af-docs-workbench__list", children: e.documents.map((m) => /* @__PURE__ */ h(Y, { as: "article", children: [
709
821
  /* @__PURE__ */ h("div", { children: [
710
- /* @__PURE__ */ h(_, { children: [
822
+ /* @__PURE__ */ h(q, { children: [
711
823
  "Revision ",
712
- b.revision.toString(),
824
+ m.revision.toString(),
713
825
  " · ",
714
- b.locale
826
+ m.locale
715
827
  ] }),
716
- /* @__PURE__ */ i(q, { children: b.title }),
717
- /* @__PURE__ */ i("p", { children: b.id })
828
+ /* @__PURE__ */ r(B, { children: m.title }),
829
+ /* @__PURE__ */ r("p", { children: m.id })
718
830
  ] }),
719
- /* @__PURE__ */ i(U, { size: "compact", variant: "secondary", onClick: () => void n.openNode(b.id), children: "Manage" })
720
- ] }, b.id)) }),
831
+ /* @__PURE__ */ r(z, { size: "compact", variant: "secondary", onClick: () => void s.openNode(m.id), children: "Manage" })
832
+ ] }, m.id)) }),
721
833
  e.selectedNode && /* @__PURE__ */ h(Y, { as: "section", children: [
722
834
  /* @__PURE__ */ h("header", { children: [
723
835
  /* @__PURE__ */ h("div", { children: [
724
- /* @__PURE__ */ i(_, { children: "Selected document" }),
725
- /* @__PURE__ */ i(q, { children: e.selectedNode.title })
836
+ /* @__PURE__ */ r(q, { children: "Selected document" }),
837
+ /* @__PURE__ */ r(B, { children: e.selectedNode.title })
726
838
  ] }),
727
- /* @__PURE__ */ i(V, { tone: ((y = e.index) == null ? void 0 : y.status) === G.RevisionIndexStatus.READY ? "success" : "warning", children: G.RevisionIndexStatus[((x = e.index) == null ? void 0 : x.status) ?? 0] })
839
+ /* @__PURE__ */ r($, { tone: ((I = e.index) == null ? void 0 : I.status) === G.RevisionIndexStatus.READY ? "success" : "warning", children: G.RevisionIndexStatus[((v = e.index) == null ? void 0 : v.status) ?? 0] })
728
840
  ] }),
729
841
  /* @__PURE__ */ h("p", { children: [
730
842
  e.revisions.length,
731
843
  " immutable revisions"
732
844
  ] }),
733
845
  /* @__PURE__ */ h("div", { className: "af-docs-workbench__actions", children: [
734
- /* @__PURE__ */ h(U, { size: "compact", variant: "secondary", onClick: () => void n.retryIndex(), children: [
735
- /* @__PURE__ */ i(Bn, { size: 14, "aria-hidden": !0 }),
846
+ /* @__PURE__ */ h(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 }),
736
848
  " Retry index"
737
849
  ] }),
738
- d.length > 0 && /* @__PURE__ */ i(Dn, { label: "Translation target", value: (f == null ? void 0 : f.id) ?? "", options: d.map((b) => ({ value: b.id, label: `${b.title} · ${b.locale}` })), onChange: s }),
739
- /* @__PURE__ */ h(U, { size: "compact", variant: "ghost", disabled: !f, onClick: () => f && void n.requestTranslation(f.id, f.locale), children: [
740
- /* @__PURE__ */ i(Hn, { size: 14, "aria-hidden": !0 }),
850
+ d.length > 0 && /* @__PURE__ */ r(Ss, { label: "Translation target", value: (u == null ? void 0 : u.id) ?? "", options: d.map((m) => ({ value: m.id, label: `${m.title} · ${m.locale}` })), onChange: n }),
851
+ /* @__PURE__ */ h(z, { size: "compact", variant: "ghost", disabled: !u || !((k = e.nodePermissions) != null && k.write), onClick: () => u && void s.requestTranslation(u.id, u.locale), children: [
852
+ /* @__PURE__ */ r(Bs, { size: 14, "aria-hidden": !0 }),
741
853
  " Translation workflow"
742
854
  ] })
743
855
  ] }),
744
856
  /* @__PURE__ */ h("div", { className: "af-docs-workbench__actions", children: [
745
- /* @__PURE__ */ i(Ue, { "aria-label": "Release version", value: r, onChange: (b) => l(b.target.value) }),
746
- /* @__PURE__ */ i(U, { size: "compact", disabled: !f || !r, onClick: () => f && void n.publishBundle(r, e.selectedNode.locale, [{ locale: f.locale, nodes: [{ sourceNodeId: e.selectedNode.id, targetNodeId: f.id }] }]), children: "Publish locale bundle" })
857
+ /* @__PURE__ */ r(Re, { "aria-label": "Release version", value: i, onChange: (m) => c(m.target.value) }),
858
+ /* @__PURE__ */ r(z, { size: "compact", disabled: !u || !i || !((A = e.spacePermissions) != null && A.writeTree), onClick: () => u && void s.publishBundle(i, e.selectedNode.locale, [{ locale: u.locale, nodes: [{ sourceNodeId: e.selectedNode.id, targetNodeId: u.id }] }]), children: "Publish locale bundle" })
747
859
  ] }),
748
860
  e.conflict && /* @__PURE__ */ h("div", { role: "alert", children: [
749
- /* @__PURE__ */ i("strong", { children: "Concurrent save rejected." }),
861
+ /* @__PURE__ */ r("strong", { children: "Concurrent save rejected." }),
750
862
  " Local draft retained for retry or Save as copy."
751
863
  ] })
752
- ] })
864
+ ] }),
865
+ e.managementError && /* @__PURE__ */ r("p", { role: "status", children: "Management data unavailable. Refresh to check your current access." }),
866
+ e.error && e.spaces.length > 0 && /* @__PURE__ */ r("p", { role: "alert", children: e.error.message }),
867
+ /* @__PURE__ */ r("div", { className: "af-docs-workbench__actions", children: Object.keys(e.nextPageTokens).filter((m) => e.nextPageTokens[m]).map((m) => /* @__PURE__ */ h(z, { size: "compact", variant: "secondary", disabled: e.loading, onClick: () => void s.loadMore(m), children: [
868
+ "Load more ",
869
+ m
870
+ ] }, m)) })
753
871
  ] });
754
872
  }
755
- class wr {
873
+ class ki {
756
874
  constructor(e) {
757
- p(this, "state", { loading: !1 });
758
- p(this, "listeners", /* @__PURE__ */ new Set());
759
- p(this, "generation", 0);
760
- p(this, "target", "");
761
- p(this, "getSnapshot", () => this.state);
762
- p(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
875
+ f(this, "state", { loading: !1 });
876
+ f(this, "listeners", /* @__PURE__ */ new Set());
877
+ f(this, "generation", 0);
878
+ f(this, "target", "");
879
+ f(this, "tenantId", "");
880
+ f(this, "getSnapshot", () => this.state);
881
+ f(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
763
882
  this.transport = e;
764
883
  }
765
- async load(e, t, s) {
766
- const r = ++this.generation, l = JSON.stringify([e, t, s]);
767
- this.target = l, this.update({ loading: !0, error: void 0 });
884
+ async load(e, t, n) {
885
+ const i = ++this.generation, c = JSON.stringify([e, t, n]);
886
+ this.target = c, this.update({ loading: !0, error: void 0 });
768
887
  try {
769
- const d = await this.transport.getLatestPublishedRelease({ tenantId: e, spaceId: t, locale: s });
770
- r === this.generation && l === this.target && this.update({ release: d, loading: !1 });
888
+ const d = await this.transport.getLatestPublishedRelease({ tenantId: e, spaceId: t, locale: n });
889
+ i === this.generation && c === this.target && (this.tenantId = e, this.update({ release: d, loading: !1 }));
771
890
  } catch (d) {
772
- const f = d instanceof Error ? d : new Error(String(d));
773
- throw r === this.generation && l === this.target && this.update({ loading: !1, error: f }), f;
891
+ const u = d instanceof Error ? d : new Error(String(d));
892
+ throw i === this.generation && c === this.target && this.update({ loading: !1, error: u }), u;
774
893
  }
775
894
  }
895
+ async resolveImage(e, t) {
896
+ const n = this.state.release, i = n == null ? void 0 : n.nodes.find((d) => d.nodeId === e);
897
+ if (this.state.loading || this.state.error || !n || !(i != null && i.assets.some((d) => d.assetId === t))) throw new Error("asset is not in the current published revision");
898
+ if (!this.transport.resolvePublishedAsset) throw new Error("published asset transport is unavailable");
899
+ const c = await this.transport.resolvePublishedAsset({ tenantId: this.tenantId, spaceId: n.spaceId, version: n.version, locale: n.locale, nodeId: e, revisionId: i.revisionId, assetId: t });
900
+ return { url: c.readUrl, expiresAt: c.expiresAt ? Number(c.expiresAt.seconds) * 1e3 + c.expiresAt.nanos / 1e6 : void 0 };
901
+ }
776
902
  update(e) {
777
903
  this.state = { ...this.state, ...e }, this.listeners.forEach((t) => t());
778
904
  }
779
905
  }
780
- const ls = (n) => pe(n.subscribe, n.getSnapshot, n.getSnapshot);
781
- function yr({ controller: n }) {
782
- const e = ls(n);
783
- return e.loading ? /* @__PURE__ */ i(B, { title: "Loading published documentation" }) : e.error ? /* @__PURE__ */ i(B, { title: "Published documentation unavailable", description: e.error.message }) : e.release ? /* @__PURE__ */ h("main", { className: "af-docs-workbench", "aria-label": "Published documentation", children: [
784
- /* @__PURE__ */ i("header", { children: /* @__PURE__ */ h("div", { children: [
785
- /* @__PURE__ */ h(_, { children: [
906
+ const un = (s) => pe(s.subscribe, s.getSnapshot, s.getSnapshot);
907
+ function Si({ controller: s }) {
908
+ const e = un(s);
909
+ 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__ */ h("main", { className: "af-docs-workbench", "aria-label": "Published documentation", children: [
910
+ /* @__PURE__ */ r("header", { children: /* @__PURE__ */ h("div", { children: [
911
+ /* @__PURE__ */ h(q, { children: [
786
912
  e.release.locale,
787
913
  " · ",
788
914
  e.release.version
789
915
  ] }),
790
- /* @__PURE__ */ i(q, { children: "Published documentation" })
916
+ /* @__PURE__ */ r(B, { children: "Published documentation" })
791
917
  ] }) }),
792
- e.release.nodes.map((t) => /* @__PURE__ */ i(Y, { as: "article", children: /* @__PURE__ */ h("div", { children: [
793
- /* @__PURE__ */ i(_, { children: t.slug }),
794
- /* @__PURE__ */ i(q, { children: t.title }),
795
- /* @__PURE__ */ i(ds, { node: t })
918
+ e.release.nodes.map((t) => /* @__PURE__ */ r(Y, { as: "article", children: /* @__PURE__ */ h("div", { children: [
919
+ /* @__PURE__ */ r(q, { children: t.slug }),
920
+ /* @__PURE__ */ r(B, { children: t.title }),
921
+ /* @__PURE__ */ r(hn, { node: t, controller: s })
796
922
  ] }) }, t.nodeId))
797
- ] }) : /* @__PURE__ */ i(B, { title: "No published documentation" });
923
+ ] }) : /* @__PURE__ */ r(j, { title: "No published documentation" });
798
924
  }
799
- function ds({ node: n }) {
925
+ function hn({ node: s, controller: e }) {
926
+ const t = Vs((n) => e.resolveImage(s.nodeId, n), [e, s]);
800
927
  try {
801
- return /* @__PURE__ */ i(os, { value: ss(n.contentJson), editable: !1, placeholder: "", ariaLabel: n.title, surface: "document" });
928
+ return /* @__PURE__ */ r(an, { value: nn(s.contentJson), resolveImage: t, editable: !1, placeholder: "", ariaLabel: s.title, surface: "document" });
802
929
  } catch {
803
- return /* @__PURE__ */ i(B, { size: "sm", title: "Published content is incompatible" });
930
+ return /* @__PURE__ */ r(j, { size: "sm", title: "Published content is incompatible" });
804
931
  }
805
932
  }
806
- const zt = Math.floor, us = (n, e) => n < e ? n : e, hs = (n, e) => n > e ? n : e, Rt = 128, ce = 127, ps = Number.MAX_SAFE_INTEGER, fs = () => /* @__PURE__ */ new Set(), ms = Array.from, gs = (n) => {
807
- const e = unescape(encodeURIComponent(n)), t = e.length, s = new Uint8Array(t);
808
- for (let r = 0; r < t; r++)
809
- s[r] = /** @type {number} */
810
- e.codePointAt(r);
811
- return s;
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) => {
934
+ const e = unescape(encodeURIComponent(s)), t = e.length, n = new Uint8Array(t);
935
+ for (let i = 0; i < t; i++)
936
+ n[i] = /** @type {number} */
937
+ e.codePointAt(i);
938
+ return n;
812
939
  }, te = (
813
940
  /** @type {TextEncoder} */
814
941
  typeof TextEncoder < "u" ? new TextEncoder() : null
815
- ), vs = (n) => te.encode(n), bs = te ? vs : gs;
942
+ ), wn = (s) => te.encode(s), yn = te ? wn : bn;
816
943
  let Q = typeof TextDecoder > "u" ? null : new TextDecoder("utf-8", { fatal: !0, ignoreBOM: !0 });
817
944
  Q && Q.decode(new Uint8Array()).length === 1 && (Q = null);
818
- class ws {
945
+ class kn {
819
946
  constructor() {
820
947
  this.cpos = 0, this.cbuf = new Uint8Array(100), this.bufs = [];
821
948
  }
822
949
  }
823
- const ys = () => new ws(), Ss = (n) => {
824
- let e = n.cpos;
825
- for (let t = 0; t < n.bufs.length; t++)
826
- e += n.bufs[t].length;
950
+ const Sn = () => new kn(), xn = (s) => {
951
+ let e = s.cpos;
952
+ for (let t = 0; t < s.bufs.length; t++)
953
+ e += s.bufs[t].length;
827
954
  return e;
828
- }, ks = (n) => {
829
- const e = new Uint8Array(Ss(n));
955
+ }, Dn = (s) => {
956
+ const e = new Uint8Array(xn(s));
830
957
  let t = 0;
831
- for (let s = 0; s < n.bufs.length; s++) {
832
- const r = n.bufs[s];
833
- e.set(r, t), t += r.length;
834
- }
835
- return e.set(new Uint8Array(n.cbuf.buffer, 0, n.cpos), t), e;
836
- }, ue = (n, e) => {
837
- const t = n.cbuf.length;
838
- n.cpos === t && (n.bufs.push(n.cbuf), n.cbuf = new Uint8Array(t * 2), n.cpos = 0), n.cbuf[n.cpos++] = e;
839
- }, $ = (n, e) => {
958
+ for (let n = 0; n < s.bufs.length; n++) {
959
+ const i = s.bufs[n];
960
+ e.set(i, t), t += i.length;
961
+ }
962
+ return e.set(new Uint8Array(s.cbuf.buffer, 0, s.cpos), t), e;
963
+ }, ue = (s, e) => {
964
+ const t = s.cbuf.length;
965
+ s.cpos === t && (s.bufs.push(s.cbuf), s.cbuf = new Uint8Array(t * 2), s.cpos = 0), s.cbuf[s.cpos++] = e;
966
+ }, F = (s, e) => {
840
967
  for (; e > ce; )
841
- ue(n, Rt | ce & e), e = zt(e / 128);
842
- ue(n, ce & e);
843
- }, Me = new Uint8Array(3e4), Ds = Me.length / 3, Cs = (n, e) => {
844
- if (e.length < Ds) {
845
- const t = te.encodeInto(e, Me).written || 0;
846
- $(n, t);
847
- for (let s = 0; s < t; s++)
848
- ue(n, Me[s]);
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) {
972
+ const t = te.encodeInto(e, Oe).written || 0;
973
+ F(s, t);
974
+ for (let n = 0; n < t; n++)
975
+ ue(s, Oe[n]);
849
976
  } else
850
- As(n, bs(e));
851
- }, xs = (n, e) => {
852
- const t = unescape(encodeURIComponent(e)), s = t.length;
853
- $(n, s);
854
- for (let r = 0; r < s; r++)
977
+ An(s, yn(e));
978
+ }, Nn = (s, e) => {
979
+ const t = unescape(encodeURIComponent(e)), n = t.length;
980
+ F(s, n);
981
+ for (let i = 0; i < n; i++)
855
982
  ue(
856
- n,
983
+ s,
857
984
  /** @type {number} */
858
- t.codePointAt(r)
985
+ t.codePointAt(i)
859
986
  );
860
- }, Ns = te && /** @type {any} */
861
- te.encodeInto ? Cs : xs, Is = (n, e) => {
862
- const t = n.cbuf.length, s = n.cpos, r = us(t - s, e.length), l = e.length - r;
863
- n.cbuf.set(e.subarray(0, r), s), n.cpos += r, l > 0 && (n.bufs.push(n.cbuf), n.cbuf = new Uint8Array(hs(t * 2, l)), n.cbuf.set(e.subarray(r)), n.cpos = l);
864
- }, As = (n, e) => {
865
- $(n, e.byteLength), Is(n, e);
866
- }, Ut = (n) => new Error(n), Es = Ut("Unexpected end of array"), zs = Ut("Integer out of Range");
867
- class Rs {
987
+ }, Pn = te && /** @type {any} */
988
+ te.encodeInto ? In : Nn, 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 {
868
995
  /**
869
996
  * @param {Uint8Array<Buf>} uint8Array Binary data to decode
870
997
  */
@@ -872,75 +999,75 @@ class Rs {
872
999
  this.arr = e, this.pos = 0;
873
1000
  }
874
1001
  }
875
- const Us = (n) => new Rs(n), Ts = (n, e) => {
876
- const t = new Uint8Array(n.arr.buffer, n.pos + n.arr.byteOffset, e);
877
- return n.pos += e, t;
878
- }, Ls = (n) => Ts(n, Z(n)), yt = (n) => n.arr[n.pos++], Z = (n) => {
1002
+ const Un = (s) => new Rn(s), Ln = (s, e) => {
1003
+ const t = new Uint8Array(s.arr.buffer, s.pos + s.arr.byteOffset, e);
1004
+ return s.pos += e, t;
1005
+ }, Mn = (s) => Ln(s, Z(s)), yt = (s) => s.arr[s.pos++], Z = (s) => {
879
1006
  let e = 0, t = 1;
880
- const s = n.arr.length;
881
- for (; n.pos < s; ) {
882
- const r = n.arr[n.pos++];
883
- if (e = e + (r & ce) * t, t *= 128, r < Rt)
1007
+ const n = s.arr.length;
1008
+ for (; s.pos < n; ) {
1009
+ const i = s.arr[s.pos++];
1010
+ if (e = e + (i & ce) * t, t *= 128, i < Et)
884
1011
  return e;
885
- if (e > ps)
886
- throw zs;
1012
+ if (e > mn)
1013
+ throw zn;
887
1014
  }
888
- throw Es;
889
- }, Ps = (n) => {
890
- let e = Z(n);
1015
+ throw En;
1016
+ }, On = (s) => {
1017
+ let e = Z(s);
891
1018
  if (e === 0)
892
1019
  return "";
893
1020
  {
894
- let t = String.fromCodePoint(yt(n));
1021
+ let t = String.fromCodePoint(yt(s));
895
1022
  if (--e < 100)
896
1023
  for (; e--; )
897
- t += String.fromCodePoint(yt(n));
1024
+ t += String.fromCodePoint(yt(s));
898
1025
  else
899
1026
  for (; e > 0; ) {
900
- const s = e < 1e4 ? e : 1e4, r = n.arr.subarray(n.pos, n.pos + s);
901
- n.pos += s, t += String.fromCodePoint.apply(
1027
+ const n = e < 1e4 ? e : 1e4, i = s.arr.subarray(s.pos, s.pos + n);
1028
+ s.pos += n, t += String.fromCodePoint.apply(
902
1029
  null,
903
1030
  /** @type {any} */
904
- r
905
- ), e -= s;
1031
+ i
1032
+ ), e -= n;
906
1033
  }
907
1034
  return decodeURIComponent(escape(t));
908
1035
  }
909
- }, Ms = (n) => (
1036
+ }, _n = (s) => (
910
1037
  /** @type any */
911
- Q.decode(Ls(n))
912
- ), Os = Q ? Ms : Ps, he = Date.now, Ae = () => /* @__PURE__ */ new Map(), _s = (n, e, t) => {
913
- let s = n.get(e);
914
- return s === void 0 && n.set(e, s = t()), s;
1038
+ Q.decode(Mn(s))
1039
+ ), qn = Q ? _n : On, he = Date.now, Pe = () => /* @__PURE__ */ new Map(), Bn = (s, e, t) => {
1040
+ let n = s.get(e);
1041
+ return n === void 0 && s.set(e, n = t()), n;
915
1042
  };
916
- class qs {
1043
+ class jn {
917
1044
  constructor() {
918
- this._observers = Ae();
1045
+ this._observers = Pe();
919
1046
  }
920
1047
  /**
921
1048
  * @param {N} name
922
1049
  * @param {function} f
923
1050
  */
924
1051
  on(e, t) {
925
- _s(this._observers, e, fs).add(t);
1052
+ Bn(this._observers, e, gn).add(t);
926
1053
  }
927
1054
  /**
928
1055
  * @param {N} name
929
1056
  * @param {function} f
930
1057
  */
931
1058
  once(e, t) {
932
- const s = (...r) => {
933
- this.off(e, s), t(...r);
1059
+ const n = (...i) => {
1060
+ this.off(e, n), t(...i);
934
1061
  };
935
- this.on(e, s);
1062
+ this.on(e, n);
936
1063
  }
937
1064
  /**
938
1065
  * @param {N} name
939
1066
  * @param {function} f
940
1067
  */
941
1068
  off(e, t) {
942
- const s = this._observers.get(e);
943
- s !== void 0 && (s.delete(t), s.size === 0 && this._observers.delete(e));
1069
+ const n = this._observers.get(e);
1070
+ n !== void 0 && (n.delete(t), n.size === 0 && this._observers.delete(e));
944
1071
  }
945
1072
  /**
946
1073
  * Emit a named event. All registered event listeners that listen to the
@@ -952,68 +1079,68 @@ class qs {
952
1079
  * @param {Array<any>} args The arguments that are applied to the event listener.
953
1080
  */
954
1081
  emit(e, t) {
955
- return ms((this._observers.get(e) || Ae()).values()).forEach((s) => s(...t));
1082
+ return vn((this._observers.get(e) || Pe()).values()).forEach((n) => n(...t));
956
1083
  }
957
1084
  destroy() {
958
- this._observers = Ae();
1085
+ this._observers = Pe();
959
1086
  }
960
1087
  }
961
- const St = Symbol("Equality"), Bs = Object.keys, kt = (n) => Bs(n).length, Hs = (n, e) => Object.prototype.hasOwnProperty.call(n, e), ee = (n, e) => {
962
- if (n === e)
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) => {
1089
+ if (s === e)
963
1090
  return !0;
964
- if (n == null || e == null || n.constructor !== e.constructor && (n.constructor || Object) !== (e.constructor || Object))
1091
+ if (s == null || e == null || s.constructor !== e.constructor && (s.constructor || Object) !== (e.constructor || Object))
965
1092
  return !1;
966
- if (n[St] != null)
967
- return n[St](e);
968
- switch (n.constructor) {
1093
+ if (s[kt] != null)
1094
+ return s[kt](e);
1095
+ switch (s.constructor) {
969
1096
  case ArrayBuffer:
970
- n = new Uint8Array(n), e = new Uint8Array(e);
1097
+ s = new Uint8Array(s), e = new Uint8Array(e);
971
1098
  // eslint-disable-next-line no-fallthrough
972
1099
  case Uint8Array: {
973
- if (n.byteLength !== e.byteLength)
1100
+ if (s.byteLength !== e.byteLength)
974
1101
  return !1;
975
- for (let t = 0; t < n.length; t++)
976
- if (n[t] !== e[t])
1102
+ for (let t = 0; t < s.length; t++)
1103
+ if (s[t] !== e[t])
977
1104
  return !1;
978
1105
  break;
979
1106
  }
980
1107
  case Set: {
981
- if (n.size !== e.size)
1108
+ if (s.size !== e.size)
982
1109
  return !1;
983
- for (const t of n)
1110
+ for (const t of s)
984
1111
  if (!e.has(t))
985
1112
  return !1;
986
1113
  break;
987
1114
  }
988
1115
  case Map: {
989
- if (n.size !== e.size)
1116
+ if (s.size !== e.size)
990
1117
  return !1;
991
- for (const t of n.keys())
992
- if (!e.has(t) || !ee(n.get(t), e.get(t)))
1118
+ for (const t of s.keys())
1119
+ if (!e.has(t) || !ee(s.get(t), e.get(t)))
993
1120
  return !1;
994
1121
  break;
995
1122
  }
996
1123
  case void 0:
997
1124
  case Object:
998
- if (kt(n) !== kt(e))
1125
+ if (St(s) !== St(e))
999
1126
  return !1;
1000
- for (const t in n)
1001
- if (!Hs(n, t) || !ee(n[t], e[t]))
1127
+ for (const t in s)
1128
+ if (!Vn(s, t) || !ee(s[t], e[t]))
1002
1129
  return !1;
1003
1130
  break;
1004
1131
  case Array:
1005
- if (n.length !== e.length)
1132
+ if (s.length !== e.length)
1006
1133
  return !1;
1007
- for (let t = 0; t < n.length; t++)
1008
- if (!ee(n[t], e[t]))
1134
+ for (let t = 0; t < s.length; t++)
1135
+ if (!ee(s[t], e[t]))
1009
1136
  return !1;
1010
1137
  break;
1011
1138
  default:
1012
1139
  return !1;
1013
1140
  }
1014
1141
  return !0;
1015
- }, Ee = 3e4;
1016
- class Tt extends qs {
1142
+ }, Te = 3e4;
1143
+ class Rt extends jn {
1017
1144
  /**
1018
1145
  * @param {Y.Doc} doc
1019
1146
  */
@@ -1021,13 +1148,13 @@ class Tt extends qs {
1021
1148
  super(), this.doc = e, this.clientID = e.clientID, this.states = /* @__PURE__ */ new Map(), this.meta = /* @__PURE__ */ new Map(), this._checkInterval = /** @type {any} */
1022
1149
  setInterval(() => {
1023
1150
  const t = he();
1024
- this.getLocalState() !== null && Ee / 2 <= t - /** @type {{lastUpdated:number}} */
1151
+ this.getLocalState() !== null && Te / 2 <= t - /** @type {{lastUpdated:number}} */
1025
1152
  this.meta.get(this.clientID).lastUpdated && this.setLocalState(this.getLocalState());
1026
- const s = [];
1027
- this.meta.forEach((r, l) => {
1028
- l !== this.clientID && Ee <= t - r.lastUpdated && this.states.has(l) && s.push(l);
1029
- }), s.length > 0 && Lt(this, s, "timeout");
1030
- }, zt(Ee / 10)), e.on("destroy", () => {
1153
+ const n = [];
1154
+ this.meta.forEach((i, c) => {
1155
+ c !== this.clientID && Te <= t - i.lastUpdated && this.states.has(c) && n.push(c);
1156
+ }), n.length > 0 && Ut(this, n, "timeout");
1157
+ }, At(Te / 10)), e.on("destroy", () => {
1031
1158
  this.destroy();
1032
1159
  }), this.setLocalState({});
1033
1160
  }
@@ -1044,22 +1171,22 @@ class Tt extends qs {
1044
1171
  * @param {Object<string,any>|null} state
1045
1172
  */
1046
1173
  setLocalState(e) {
1047
- const t = this.clientID, s = this.meta.get(t), r = s === void 0 ? 0 : s.clock + 1, l = this.states.get(t);
1174
+ const t = this.clientID, n = this.meta.get(t), i = n === void 0 ? 0 : n.clock + 1, c = this.states.get(t);
1048
1175
  e === null ? this.states.delete(t) : this.states.set(t, e), this.meta.set(t, {
1049
- clock: r,
1176
+ clock: i,
1050
1177
  lastUpdated: he()
1051
1178
  });
1052
- const d = [], f = [], y = [], x = [];
1053
- e === null ? x.push(t) : l == null ? e != null && d.push(t) : (f.push(t), ee(l, e) || y.push(t)), (d.length > 0 || y.length > 0 || x.length > 0) && this.emit("change", [{ added: d, updated: y, removed: x }, "local"]), this.emit("update", [{ added: d, updated: f, removed: x }, "local"]);
1179
+ const d = [], u = [], w = [], I = [];
1180
+ e === null ? I.push(t) : c == null ? e != null && d.push(t) : (u.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: u, removed: I }, "local"]);
1054
1181
  }
1055
1182
  /**
1056
1183
  * @param {string} field
1057
1184
  * @param {any} value
1058
1185
  */
1059
1186
  setLocalStateField(e, t) {
1060
- const s = this.getLocalState();
1061
- s !== null && this.setLocalState({
1062
- ...s,
1187
+ const n = this.getLocalState();
1188
+ n !== null && this.setLocalState({
1189
+ ...n,
1063
1190
  [e]: t
1064
1191
  });
1065
1192
  }
@@ -1070,57 +1197,57 @@ class Tt extends qs {
1070
1197
  return this.states;
1071
1198
  }
1072
1199
  }
1073
- const Lt = (n, e, t) => {
1074
- const s = [];
1075
- for (let r = 0; r < e.length; r++) {
1076
- const l = e[r];
1077
- if (n.states.has(l)) {
1078
- if (n.states.delete(l), l === n.clientID) {
1200
+ const Ut = (s, e, t) => {
1201
+ const n = [];
1202
+ for (let i = 0; i < e.length; i++) {
1203
+ const c = e[i];
1204
+ if (s.states.has(c)) {
1205
+ if (s.states.delete(c), c === s.clientID) {
1079
1206
  const d = (
1080
1207
  /** @type {MetaClientState} */
1081
- n.meta.get(l)
1208
+ s.meta.get(c)
1082
1209
  );
1083
- n.meta.set(l, {
1210
+ s.meta.set(c, {
1084
1211
  clock: d.clock + 1,
1085
1212
  lastUpdated: he()
1086
1213
  });
1087
1214
  }
1088
- s.push(l);
1215
+ n.push(c);
1089
1216
  }
1090
1217
  }
1091
- s.length > 0 && (n.emit("change", [{ added: [], updated: [], removed: s }, t]), n.emit("update", [{ added: [], updated: [], removed: s }, t]));
1092
- }, Pt = (n, e, t = n.states) => {
1093
- const s = e.length, r = ys();
1094
- $(r, s);
1095
- for (let l = 0; l < s; l++) {
1096
- const d = e[l], f = t.get(d) || null, y = (
1218
+ n.length > 0 && (s.emit("change", [{ added: [], updated: [], removed: n }, t]), s.emit("update", [{ added: [], updated: [], removed: n }, t]));
1219
+ }, Lt = (s, e, t = s.states) => {
1220
+ const n = e.length, i = Sn();
1221
+ F(i, n);
1222
+ for (let c = 0; c < n; c++) {
1223
+ const d = e[c], u = t.get(d) || null, w = (
1097
1224
  /** @type {MetaClientState} */
1098
- n.meta.get(d).clock
1225
+ s.meta.get(d).clock
1099
1226
  );
1100
- $(r, d), $(r, y), Ns(r, JSON.stringify(f));
1101
- }
1102
- return ks(r);
1103
- }, Mt = (n, e, t) => {
1104
- const s = Us(e), r = he(), l = [], d = [], f = [], y = [], x = Z(s);
1105
- for (let b = 0; b < x; b++) {
1106
- const C = Z(s);
1107
- let S = Z(s);
1108
- const T = JSON.parse(Os(s)), I = n.meta.get(C), F = n.states.get(C), z = I === void 0 ? 0 : I.clock;
1109
- (z < S || z === S && T === null && n.states.has(C)) && (T === null ? C === n.clientID && n.getLocalState() != null ? S++ : n.states.delete(C) : n.states.set(C, T), n.meta.set(C, {
1110
- clock: S,
1111
- lastUpdated: r
1112
- }), I === void 0 && T !== null ? l.push(C) : I !== void 0 && T === null ? y.push(C) : T !== null && (ee(T, F) || f.push(C), d.push(C)));
1113
- }
1114
- (l.length > 0 || f.length > 0 || y.length > 0) && n.emit("change", [{
1115
- added: l,
1116
- updated: f,
1117
- removed: y
1118
- }, t]), (l.length > 0 || d.length > 0 || y.length > 0) && n.emit("update", [{
1119
- added: l,
1227
+ F(i, d), F(i, w), Pn(i, JSON.stringify(u));
1228
+ }
1229
+ return Dn(i);
1230
+ }, Mt = (s, e, t) => {
1231
+ const n = Un(e), i = he(), c = [], d = [], u = [], w = [], I = Z(n);
1232
+ for (let v = 0; v < I; v++) {
1233
+ const C = Z(n);
1234
+ 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;
1236
+ (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
+ clock: k,
1238
+ lastUpdated: i
1239
+ }), m === void 0 && A !== null ? c.push(C) : m !== void 0 && A === null ? w.push(C) : A !== null && (ee(A, U) || u.push(C), d.push(C)));
1240
+ }
1241
+ (c.length > 0 || u.length > 0 || w.length > 0) && s.emit("change", [{
1242
+ added: c,
1243
+ updated: u,
1244
+ removed: w
1245
+ }, t]), (c.length > 0 || d.length > 0 || w.length > 0) && s.emit("update", [{
1246
+ added: c,
1120
1247
  updated: d,
1121
- removed: y
1248
+ removed: w
1122
1249
  }, t]);
1123
- }, Dt = {
1250
+ }, xt = {
1124
1251
  connected: !1,
1125
1252
  connecting: !1,
1126
1253
  serverSequence: 0n,
@@ -1128,34 +1255,34 @@ const Lt = (n, e, t) => {
1128
1255
  updates: [],
1129
1256
  cursors: {}
1130
1257
  };
1131
- class Sr {
1258
+ class xi {
1132
1259
  constructor(e) {
1133
- p(this, "state", Dt);
1134
- p(this, "listeners", /* @__PURE__ */ new Set());
1135
- p(this, "generation", 0);
1136
- p(this, "desired");
1137
- p(this, "pendingUpdates", /* @__PURE__ */ new Map());
1138
- p(this, "reconnecting");
1139
- p(this, "getSnapshot", () => this.state);
1140
- p(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
1260
+ f(this, "state", xt);
1261
+ f(this, "listeners", /* @__PURE__ */ new Set());
1262
+ f(this, "generation", 0);
1263
+ f(this, "desired");
1264
+ f(this, "pendingUpdates", /* @__PURE__ */ new Map());
1265
+ f(this, "reconnecting");
1266
+ f(this, "getSnapshot", () => this.state);
1267
+ f(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
1141
1268
  this.transport = e;
1142
1269
  }
1143
- async connect(e, t, s = 0n) {
1270
+ async connect(e, t, n = 0n) {
1144
1271
  this.disconnect();
1145
- const r = ++this.generation;
1146
- this.desired = { nodeId: e, clientId: t }, this.pendingUpdates.clear(), this.update({ ...Dt, connecting: !0, nodeId: e, serverSequence: s });
1272
+ const i = ++this.generation;
1273
+ this.desired = { nodeId: e, clientId: t }, this.pendingUpdates.clear(), this.update({ ...xt, connecting: !0, nodeId: e, serverSequence: n });
1147
1274
  try {
1148
- await this.open(r, e, t, s);
1149
- } catch (l) {
1150
- throw r === this.generation && this.update({ ...this.state, connecting: !1, error: l instanceof Error ? l : new Error(String(l)) }), l;
1275
+ await this.open(i, e, t, n);
1276
+ } catch (c) {
1277
+ throw i === this.generation && this.update({ ...this.state, connecting: !1, error: c instanceof Error ? c : new Error(String(c)) }), c;
1151
1278
  }
1152
1279
  }
1153
1280
  async push(e, t) {
1154
- const s = this.requireSession();
1281
+ const n = this.requireSession();
1155
1282
  try {
1156
- this.applyUpdate(await this.transport.pushCollaboration({ sessionId: s, clientClock: e, update: t }));
1157
- } catch (r) {
1158
- throw Le(r) && this.connectionLost(this.generation, r), r;
1283
+ this.applyUpdate(await this.transport.pushCollaboration({ sessionId: n, clientClock: e, update: t }));
1284
+ } catch (i) {
1285
+ throw Le(i) && this.connectionLost(this.generation, i), i;
1159
1286
  }
1160
1287
  }
1161
1288
  async updateCursor(e) {
@@ -1164,18 +1291,18 @@ class Sr {
1164
1291
  }
1165
1292
  async sync(e = this.state.serverSequence) {
1166
1293
  const t = this.requireSession();
1167
- let s = e;
1294
+ let n = e;
1168
1295
  for (; ; ) {
1169
- const r = await this.transport.syncCollaboration({ sessionId: t, afterSequence: s });
1170
- if (this.applyReady(r), !r.hasMore) return;
1171
- if (this.state.serverSequence <= s) throw new Error("collaboration sync did not advance");
1172
- s = this.state.serverSequence;
1296
+ const i = await this.transport.syncCollaboration({ sessionId: t, afterSequence: n });
1297
+ if (this.applyReady(i), !i.hasMore) return;
1298
+ if (this.state.serverSequence <= n) throw new Error("collaboration sync did not advance");
1299
+ n = this.state.serverSequence;
1173
1300
  }
1174
1301
  }
1175
1302
  waitForConnection() {
1176
1303
  return this.state.connected ? Promise.resolve() : this.desired ? new Promise((e, t) => {
1177
- const s = this.subscribe(() => {
1178
- this.state.connected ? (s(), e()) : this.desired || (s(), t(this.state.error ?? new Error("collaboration is not connected")));
1304
+ const n = this.subscribe(() => {
1305
+ this.state.connected ? (n(), e()) : this.desired || (n(), t(this.state.error ?? new Error("collaboration is not connected")));
1179
1306
  });
1180
1307
  }) : Promise.reject(new Error("collaboration is not connected"));
1181
1308
  }
@@ -1189,25 +1316,25 @@ class Sr {
1189
1316
  }
1190
1317
  async consume(e, t) {
1191
1318
  try {
1192
- for await (const s of t) {
1319
+ for await (const n of t) {
1193
1320
  if (e !== this.generation) return;
1194
- const r = s.kind;
1195
- if (r.case === "ready")
1196
- this.applyReady(r.value), r.value.hasMore && await this.sync(this.state.serverSequence);
1197
- else if (r.case === "update")
1198
- this.applyUpdate(r.value);
1199
- else if (r.case === "presence") {
1200
- if (r.value.sessionId === this.state.sessionId) continue;
1201
- const l = { ...this.state.cursors };
1202
- r.value.active ? l[r.value.sessionId] = { subjectId: r.value.subjectId, cursor: r.value.cursor } : delete l[r.value.sessionId], this.update({ ...this.state, cursors: l });
1203
- } else if (r.case === "disconnected") {
1204
- r.value.reason === "authorization_revoked" || r.value.reason === "client_closed" ? (this.desired = void 0, this.generation += 1, this.update({ ...this.state, connected: !1, connecting: !1, disconnectedReason: r.value.reason, cursors: {} })) : this.connectionLost(e, new Error(r.value.reason));
1321
+ const i = n.kind;
1322
+ if (i.case === "ready")
1323
+ this.applyReady(i.value), i.value.hasMore && await this.sync(this.state.serverSequence);
1324
+ else if (i.case === "update")
1325
+ this.applyUpdate(i.value);
1326
+ else if (i.case === "presence") {
1327
+ if (i.value.sessionId === this.state.sessionId) continue;
1328
+ const c = { ...this.state.cursors };
1329
+ i.value.active ? c[i.value.sessionId] = { subjectId: i.value.subjectId, cursor: i.value.cursor } : delete c[i.value.sessionId], this.update({ ...this.state, cursors: c });
1330
+ } else if (i.case === "disconnected") {
1331
+ i.value.reason === "authorization_revoked" || i.value.reason === "client_closed" ? (this.desired = void 0, this.generation += 1, this.update({ ...this.state, connected: !1, connecting: !1, disconnectedReason: i.value.reason, cursors: {} })) : this.connectionLost(e, new Error(i.value.reason));
1205
1332
  return;
1206
1333
  }
1207
1334
  }
1208
1335
  e === this.generation && this.connectionLost(e, new Error("stream_closed"));
1209
- } catch (s) {
1210
- this.connectionLost(e, s);
1336
+ } catch (n) {
1337
+ this.connectionLost(e, n);
1211
1338
  }
1212
1339
  }
1213
1340
  requireSession() {
@@ -1215,9 +1342,9 @@ class Sr {
1215
1342
  return this.state.sessionId;
1216
1343
  }
1217
1344
  applyReady(e) {
1218
- const t = this.contiguous(e.updates), s = {};
1219
- for (const r of e.presences ?? [])
1220
- r.active && r.sessionId !== e.sessionId && (s[r.sessionId] = { subjectId: r.subjectId, cursor: r.cursor });
1345
+ const t = this.contiguous(e.updates), n = {};
1346
+ for (const i of e.presences ?? [])
1347
+ i.active && i.sessionId !== e.sessionId && (n[i.sessionId] = { subjectId: i.subjectId, cursor: i.cursor });
1221
1348
  this.update({
1222
1349
  ...this.state,
1223
1350
  connected: !0,
@@ -1226,9 +1353,9 @@ class Sr {
1226
1353
  sessionId: e.sessionId,
1227
1354
  clientId: e.clientId,
1228
1355
  serverSequence: t.serverSequence,
1229
- stateVector: $s(this.state.stateVector, e.stateVector),
1356
+ stateVector: Jn(this.state.stateVector, e.stateVector),
1230
1357
  updates: t.updates,
1231
- cursors: s,
1358
+ cursors: n,
1232
1359
  disconnectedReason: void 0,
1233
1360
  error: void 0
1234
1361
  });
@@ -1242,58 +1369,58 @@ class Sr {
1242
1369
  });
1243
1370
  }
1244
1371
  contiguous(e) {
1245
- for (const r of e)
1246
- if (!(r.serverSequence <= this.state.serverSequence)) {
1247
- if (!this.pendingUpdates.has(r.serverSequence) && this.pendingUpdates.size >= 128)
1372
+ for (const i of e)
1373
+ if (!(i.serverSequence <= this.state.serverSequence)) {
1374
+ if (!this.pendingUpdates.has(i.serverSequence) && this.pendingUpdates.size >= 128)
1248
1375
  throw new Error("collaboration sequence gap exceeds 128 buffered updates");
1249
- this.pendingUpdates.set(r.serverSequence, r);
1376
+ this.pendingUpdates.set(i.serverSequence, i);
1250
1377
  }
1251
1378
  let t = this.state.serverSequence;
1252
- const s = [...this.state.updates];
1379
+ const n = [...this.state.updates];
1253
1380
  for (; ; ) {
1254
- const r = this.pendingUpdates.get(t + 1n);
1255
- if (!r) break;
1256
- this.pendingUpdates.delete(t + 1n), s.push(r), t += 1n;
1381
+ const i = this.pendingUpdates.get(t + 1n);
1382
+ if (!i) break;
1383
+ this.pendingUpdates.delete(t + 1n), n.push(i), t += 1n;
1257
1384
  }
1258
- return { serverSequence: t, updates: s };
1385
+ return { serverSequence: t, updates: n };
1259
1386
  }
1260
- async open(e, t, s, r) {
1261
- const l = await this.transport.openCollaboration({ nodeId: t, clientId: s, afterSequence: r });
1387
+ async open(e, t, n, i) {
1388
+ const c = await this.transport.openCollaboration({ nodeId: t, clientId: n, afterSequence: i });
1262
1389
  if (e !== this.generation) {
1263
- await Promise.resolve(this.transport.closeCollaboration({ sessionId: l.sessionId })).catch(() => {
1390
+ await Promise.resolve(this.transport.closeCollaboration({ sessionId: c.sessionId })).catch(() => {
1264
1391
  });
1265
1392
  return;
1266
1393
  }
1267
- this.applyReady(l), this.consume(e, this.transport.followCollaboration({
1268
- sessionId: l.sessionId,
1394
+ this.applyReady(c), this.consume(e, this.transport.followCollaboration({
1395
+ sessionId: c.sessionId,
1269
1396
  afterSequence: this.state.serverSequence
1270
- })), l.hasMore && await this.sync(this.state.serverSequence);
1397
+ })), c.hasMore && await this.sync(this.state.serverSequence);
1271
1398
  }
1272
1399
  connectionLost(e, t) {
1273
1400
  if (e !== this.generation || !this.desired) return;
1274
- const s = t instanceof Error ? t : new Error(String(t));
1275
- if (this.update({ ...this.state, connected: !1, connecting: !1, disconnectedReason: s.message, cursors: {}, error: s }), !this.reconnecting) {
1276
- const r = this.reconnect().finally(() => {
1277
- this.reconnecting === r && (this.reconnecting = void 0);
1401
+ const n = t instanceof Error ? t : new Error(String(t));
1402
+ if (this.update({ ...this.state, connected: !1, connecting: !1, disconnectedReason: n.message, cursors: {}, error: n }), !this.reconnecting) {
1403
+ const i = this.reconnect().finally(() => {
1404
+ this.reconnecting === i && (this.reconnecting = void 0);
1278
1405
  });
1279
- this.reconnecting = r;
1406
+ this.reconnecting = i;
1280
1407
  }
1281
1408
  }
1282
1409
  async reconnect() {
1283
1410
  const e = this.desired;
1284
1411
  if (!e) return;
1285
- const t = this.state.sessionId, s = ++this.generation;
1412
+ const t = this.state.sessionId, n = ++this.generation;
1286
1413
  t && Promise.resolve(this.transport.closeCollaboration({ sessionId: t })).catch(() => {
1287
1414
  });
1288
- let r = this.state.error ?? new Error("collaboration disconnected");
1289
- for (let l = 0; s === this.generation && this.desired === e; l += 1) {
1290
- if (s !== this.generation || this.desired !== e) return;
1291
- l > 0 && await Fs(Math.min(50 * 2 ** (l - 1), 5e3)), this.update({ ...this.state, connecting: !0, disconnectedReason: void 0 });
1415
+ let i = this.state.error ?? new Error("collaboration disconnected");
1416
+ for (let c = 0; n === this.generation && this.desired === e; c += 1) {
1417
+ 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 });
1292
1419
  try {
1293
- await this.open(s, e.nodeId, e.clientId, this.state.serverSequence);
1420
+ await this.open(n, e.nodeId, e.clientId, this.state.serverSequence);
1294
1421
  return;
1295
1422
  } catch (d) {
1296
- if (r = d instanceof Error ? d : new Error(String(d)), this.update({ ...this.state, connecting: !1, disconnectedReason: r.message, error: r }), !Le(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)) {
1297
1424
  this.desired = void 0;
1298
1425
  return;
1299
1426
  }
@@ -1304,77 +1431,77 @@ class Sr {
1304
1431
  this.state = e, this.listeners.forEach((t) => t());
1305
1432
  }
1306
1433
  }
1307
- const Ct = Symbol("docs-collaboration-remote"), le = Symbol("docs-collaboration-presence"), ze = 64 * 1024;
1308
- class kr {
1309
- constructor(e, t, s, r = "prosemirror") {
1310
- p(this, "document", new M.Doc());
1311
- p(this, "awareness", new Tt(this.document));
1312
- p(this, "user");
1313
- p(this, "editorCollaboration");
1314
- p(this, "unsubscribe");
1315
- p(this, "presenceClients", /* @__PURE__ */ new Map());
1316
- p(this, "appliedPresence", /* @__PURE__ */ new Map());
1317
- p(this, "clockClientId", crypto.randomUUID());
1318
- p(this, "clientClock", 0n);
1319
- p(this, "appliedSequence", 0n);
1320
- p(this, "queuedUpdates", []);
1321
- p(this, "pumping");
1322
- p(this, "presencePending", Promise.resolve());
1323
- p(this, "terminalUpdateError");
1324
- p(this, "oversizedUpdate", !1);
1325
- p(this, "applyRemoteUpdates", () => {
1434
+ const Dt = Symbol("docs-collaboration-remote"), le = Symbol("docs-collaboration-presence"), Ae = 64 * 1024;
1435
+ class Di {
1436
+ constructor(e, t, n, i = "prosemirror") {
1437
+ f(this, "document", new O.Doc());
1438
+ f(this, "awareness", new Rt(this.document));
1439
+ f(this, "user");
1440
+ f(this, "editorCollaboration");
1441
+ f(this, "unsubscribe");
1442
+ f(this, "presenceClients", /* @__PURE__ */ new Map());
1443
+ f(this, "appliedPresence", /* @__PURE__ */ new Map());
1444
+ f(this, "clockClientId", crypto.randomUUID());
1445
+ f(this, "clientClock", 0n);
1446
+ f(this, "appliedSequence", 0n);
1447
+ f(this, "queuedUpdates", []);
1448
+ f(this, "pumping");
1449
+ f(this, "presencePending", Promise.resolve());
1450
+ f(this, "terminalUpdateError");
1451
+ f(this, "oversizedUpdate", !1);
1452
+ f(this, "applyRemoteUpdates", () => {
1326
1453
  for (const t of this.controller.getSnapshot().updates)
1327
- t.serverSequence <= this.appliedSequence || (M.applyUpdate(this.document, t.update, Ct), this.appliedSequence = t.serverSequence);
1454
+ t.serverSequence <= this.appliedSequence || (O.applyUpdate(this.document, t.update, Dt), this.appliedSequence = t.serverSequence);
1328
1455
  const e = this.controller.getSnapshot().cursors;
1329
1456
  for (const t of this.presenceClients.keys())
1330
- e[t] || (Lt(this.awareness, [...this.presenceClients.get(t) ?? []], le), this.presenceClients.delete(t), this.appliedPresence.delete(t));
1331
- for (const [t, s] of Object.entries(e)) {
1332
- if (s.cursor.length === 0 || js(this.appliedPresence.get(t), s.cursor)) continue;
1333
- const r = /* @__PURE__ */ new Set(), l = ({ added: d, updated: f }) => {
1334
- for (const y of [...d, ...f]) r.add(y);
1457
+ e[t] || (Ut(this.awareness, [...this.presenceClients.get(t) ?? []], le), this.presenceClients.delete(t), this.appliedPresence.delete(t));
1458
+ for (const [t, n] of Object.entries(e)) {
1459
+ if (n.cursor.length === 0 || $n(this.appliedPresence.get(t), n.cursor)) continue;
1460
+ const i = /* @__PURE__ */ new Set(), c = ({ added: d, updated: u }) => {
1461
+ for (const w of [...d, ...u]) i.add(w);
1335
1462
  };
1336
- this.awareness.on("update", l);
1463
+ this.awareness.on("update", c);
1337
1464
  try {
1338
- Mt(this.awareness, Vs(s.cursor, s.subjectId), le);
1465
+ Mt(this.awareness, Fn(n.cursor, n.subjectId), le);
1339
1466
  } catch {
1340
1467
  continue;
1341
1468
  } finally {
1342
- this.awareness.off("update", l);
1469
+ this.awareness.off("update", c);
1343
1470
  }
1344
- r.size > 0 && this.presenceClients.set(t, r), this.appliedPresence.set(t, s.cursor);
1471
+ i.size > 0 && this.presenceClients.set(t, i), this.appliedPresence.set(t, n.cursor);
1345
1472
  }
1346
1473
  });
1347
- p(this, "pushLocalUpdate", (e, t) => {
1474
+ f(this, "pushLocalUpdate", (e, t) => {
1348
1475
  var d;
1349
- if (t === Ct) return;
1350
- const s = this.oversizedUpdate ? M.encodeStateAsUpdate(this.document) : e;
1351
- if (s.length > ze) {
1352
- this.oversizedUpdate = !0, this.terminalUpdateError = new Error(`collaboration update exceeds ${ze} bytes`), this.controller.reportError(this.terminalUpdateError);
1476
+ if (t === Dt) return;
1477
+ 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);
1353
1480
  return;
1354
1481
  }
1355
1482
  this.oversizedUpdate = !1, this.terminalUpdateError = void 0;
1356
- const r = this.queuedUpdates.at(-1), l = r && r.clock === void 0 ? M.mergeUpdates([r.bytes, s]) : s;
1357
- r && r.clock === void 0 && l.length <= ze ? r.bytes = l : this.queuedUpdates.push({ bytes: s }), (d = this.ensurePump()) == null || d.catch((f) => this.controller.reportError(f));
1483
+ 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((u) => this.controller.reportError(u));
1358
1485
  });
1359
- p(this, "pushLocalPresence", (e, t) => {
1486
+ f(this, "pushLocalPresence", (e, t) => {
1360
1487
  if (t === le || !this.controller.getSnapshot().connected) return;
1361
- const s = Pt(this.awareness, [this.awareness.clientID]);
1488
+ const n = Lt(this.awareness, [this.awareness.clientID]);
1362
1489
  this.presencePending = this.presencePending.catch(() => {
1363
- }).then(() => this.controller.updateCursor(s)), this.presencePending.catch((r) => this.controller.reportError(r));
1490
+ }).then(() => this.controller.updateCursor(n)), this.presencePending.catch((i) => this.controller.reportError(i));
1364
1491
  });
1365
- this.controller = e, this.clientId = t, this.initialValue = s, this.field = r, this.user = { name: t, color: _t(t) }, this.editorCollaboration = { document: this.document, awareness: this.awareness, user: this.user }, this.awareness.setLocalStateField("user", this.user), this.unsubscribe = e.subscribe(this.applyRemoteUpdates), this.document.on("update", this.pushLocalUpdate), this.awareness.on("update", this.pushLocalPresence);
1492
+ this.controller = e, this.clientId = t, this.initialValue = n, this.field = i, this.user = { name: t, color: _t(t) }, this.editorCollaboration = { document: this.document, awareness: this.awareness, user: this.user }, this.awareness.setLocalStateField("user", this.user), this.unsubscribe = e.subscribe(this.applyRemoteUpdates), this.document.on("update", this.pushLocalUpdate), this.awareness.on("update", this.pushLocalPresence);
1366
1493
  }
1367
1494
  async connect(e, t = 0n) {
1368
1495
  this.oversizedUpdate || (this.terminalUpdateError = void 0), await this.controller.connect(e, this.clockClientId, t), this.applyRemoteUpdates();
1369
- const s = this.controller.getSnapshot(), r = s.stateVector[s.clientId ?? this.clientId] ?? 0n;
1370
- if (r > this.clientClock && (this.clientClock = r), s.serverSequence === 0n && this.document.getXmlFragment(this.field).length === 0 && this.initialValue) {
1371
- const l = tn(Et("")), d = new M.Doc();
1372
- d.clientID = Ot(JSON.stringify(this.initialValue)), $n(l, this.initialValue.doc, d.getXmlFragment(this.field)), M.applyUpdate(this.document, M.encodeStateAsUpdate(d));
1496
+ const n = this.controller.getSnapshot(), i = n.stateVector[n.clientId ?? this.clientId] ?? 0n;
1497
+ 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));
1373
1500
  }
1374
1501
  await this.flush(), this.pushLocalPresence({ added: [this.awareness.clientID], updated: [], removed: [] }, void 0);
1375
1502
  }
1376
1503
  snapshot() {
1377
- return Pe(Fn(this.document.getXmlFragment(this.field)));
1504
+ return Me(Fs(this.document.getXmlFragment(this.field)));
1378
1505
  }
1379
1506
  async checkpoint(e, t) {
1380
1507
  return await this.flush(), await this.controller.sync(), this.applyRemoteUpdates(), await this.flush(), String(await t(this.snapshot(), {
@@ -1410,91 +1537,91 @@ class kr {
1410
1537
  try {
1411
1538
  await this.controller.push(t, e.bytes);
1412
1539
  break;
1413
- } catch (s) {
1414
- if (!Le(s))
1415
- throw this.terminalUpdateError = s instanceof Error ? s : new Error(String(s)), this.terminalUpdateError;
1540
+ } catch (n) {
1541
+ if (!Le(n))
1542
+ throw this.terminalUpdateError = n instanceof Error ? n : new Error(String(n)), this.terminalUpdateError;
1416
1543
  }
1417
1544
  }
1418
- } catch (s) {
1419
- throw this.queuedUpdates.unshift(e), s;
1545
+ } catch (n) {
1546
+ throw this.queuedUpdates.unshift(e), n;
1420
1547
  }
1421
1548
  }
1422
1549
  }
1423
1550
  }
1424
- function Ot(n) {
1551
+ function Ot(s) {
1425
1552
  let e = 2166136261;
1426
- for (let t = 0; t < n.length; t += 1) e = Math.imul(e ^ n.charCodeAt(t), 16777619);
1553
+ for (let t = 0; t < s.length; t += 1) e = Math.imul(e ^ s.charCodeAt(t), 16777619);
1427
1554
  return e >>> 0 || 1;
1428
1555
  }
1429
- function _t(n) {
1430
- return `hsl(${Ot(n) % 360} 62% 42%)`;
1556
+ function _t(s) {
1557
+ return `hsl(${Ot(s) % 360} 62% 42%)`;
1431
1558
  }
1432
- function js(n, e) {
1433
- return (n == null ? void 0 : n.length) === e.length && n.every((t, s) => t === e[s]);
1559
+ function $n(s, e) {
1560
+ return (s == null ? void 0 : s.length) === e.length && s.every((t, n) => t === e[n]);
1434
1561
  }
1435
- function Vs(n, e) {
1436
- const t = new M.Doc(), s = new Tt(t);
1562
+ function Fn(s, e) {
1563
+ const t = new O.Doc(), n = new Rt(t);
1437
1564
  try {
1438
- Mt(s, n, le);
1439
- const r = [...s.getStates().keys()];
1440
- for (const l of r) {
1441
- const d = s.getStates().get(l) ?? {};
1442
- s.states.set(l, { ...d, user: { name: e, color: _t(e) } });
1565
+ Mt(n, s, le);
1566
+ const i = [...n.getStates().keys()];
1567
+ for (const c of i) {
1568
+ const d = n.getStates().get(c) ?? {};
1569
+ n.states.set(c, { ...d, user: { name: e, color: _t(e) } });
1443
1570
  }
1444
- return Pt(s, r);
1571
+ return Lt(n, i);
1445
1572
  } finally {
1446
- s.destroy(), t.destroy();
1573
+ n.destroy(), t.destroy();
1447
1574
  }
1448
1575
  }
1449
- function $s(n, e) {
1450
- const t = { ...n };
1451
- for (const [s, r] of Object.entries(e ?? {})) t[s] = t[s] > r ? t[s] : r;
1576
+ function Jn(s, e) {
1577
+ const t = { ...s };
1578
+ for (const [n, i] of Object.entries(e ?? {})) t[n] = t[n] > i ? t[n] : i;
1452
1579
  return t;
1453
1580
  }
1454
- const Fs = (n) => new Promise((e) => setTimeout(e, n)), Js = (n) => pe(n.subscribe, n.getSnapshot, n.getSnapshot);
1455
- function Dr({ controller: n }) {
1456
- const e = Js(n);
1457
- return e.error ? /* @__PURE__ */ i(B, { size: "sm", title: "Live editing unavailable", description: e.error.message }) : /* @__PURE__ */ h(Y, { as: "section", children: [
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);
1584
+ return e.error ? /* @__PURE__ */ r(j, { size: "sm", title: "Live editing unavailable", description: e.error.message }) : /* @__PURE__ */ h(Y, { as: "section", children: [
1458
1585
  /* @__PURE__ */ h("header", { children: [
1459
1586
  /* @__PURE__ */ h("div", { children: [
1460
- /* @__PURE__ */ i(_, { children: "Live document" }),
1461
- /* @__PURE__ */ i(q, { children: e.nodeId ?? "No document selected" })
1587
+ /* @__PURE__ */ r(q, { children: "Live document" }),
1588
+ /* @__PURE__ */ r(B, { children: e.nodeId ?? "No document selected" })
1462
1589
  ] }),
1463
- /* @__PURE__ */ i(V, { tone: e.connected ? "success" : "neutral", children: e.connecting ? "Connecting" : e.connected ? "Connected" : "Disconnected" })
1590
+ /* @__PURE__ */ r($, { tone: e.connected ? "success" : "neutral", children: e.connecting ? "Connecting" : e.connected ? "Connected" : "Disconnected" })
1464
1591
  ] }),
1465
1592
  /* @__PURE__ */ h("p", { children: [
1466
1593
  Object.keys(e.cursors).length,
1467
1594
  " remote editors · durable sequence ",
1468
1595
  e.serverSequence.toString()
1469
1596
  ] }),
1470
- e.disconnectedReason && /* @__PURE__ */ i("p", { role: "status", children: e.disconnectedReason }),
1471
- (e.connected || e.connecting) && /* @__PURE__ */ i(U, { size: "compact", variant: "secondary", onClick: () => n.disconnect(), children: "Disconnect" })
1597
+ e.disconnectedReason && /* @__PURE__ */ r("p", { role: "status", children: e.disconnectedReason }),
1598
+ (e.connected || e.connecting) && /* @__PURE__ */ r(z, { size: "compact", variant: "secondary", onClick: () => s.disconnect(), children: "Disconnect" })
1472
1599
  ] });
1473
1600
  }
1474
1601
  export {
1475
- Dr as DocsCollaboration,
1476
- Sr as DocsCollaborationController,
1477
- br as DocsWorkbench,
1478
- vr as DocsWorkbenchController,
1479
- yr as PublishedDocs,
1480
- wr as PublishedDocsController,
1602
+ Ci as DocsCollaboration,
1603
+ xi as DocsCollaborationController,
1604
+ yi as DocsWorkbench,
1605
+ wi as DocsWorkbenchController,
1606
+ Si as PublishedDocs,
1607
+ ki as PublishedDocsController,
1481
1608
  fe as RICH_DOCUMENT_SCHEMA,
1482
- os as RichDocument,
1483
- os as RichDocumentEditor,
1484
- kr as YjsDocsCollaborationAdapter,
1485
- Gn as applyDocumentAssistantOutput,
1486
- Yn as commitDocumentAssistantRollback,
1487
- It as documentAssistantConflict,
1488
- Pe as durableRichDocumentContent,
1609
+ an as RichDocument,
1610
+ an as RichDocumentEditor,
1611
+ Di as YjsDocsCollaborationAdapter,
1612
+ Gs as applyDocumentAssistantOutput,
1613
+ Ys as commitDocumentAssistantRollback,
1614
+ Nt as documentAssistantConflict,
1615
+ Me as durableRichDocumentContent,
1489
1616
  vt as emptyRichDocument,
1490
- as as looksLikeMarkdown,
1491
- ss as parseRichDocument,
1492
- Xn as replaceAssistantMarkdown,
1493
- is as replaceDocumentContent,
1494
- Et as richDocumentExtensions,
1495
- Wn as rollbackAssistantRange,
1496
- rs as selectionInsideTable,
1497
- Js as useDocsCollaboration,
1498
- cs as useDocsWorkbench,
1499
- ls as usePublishedDocs
1617
+ cn as looksLikeMarkdown,
1618
+ nn as parseRichDocument,
1619
+ Xs as replaceAssistantMarkdown,
1620
+ on as replaceDocumentContent,
1621
+ Tt as richDocumentExtensions,
1622
+ Ws as rollbackAssistantRange,
1623
+ rn as selectionInsideTable,
1624
+ Xn as useDocsCollaboration,
1625
+ dn as useDocsWorkbench,
1626
+ un as usePublishedDocs
1500
1627
  };