@agent-factory-platform/docs-react 0.3.0 → 0.5.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,117 +1,128 @@
1
- import { jsx as t, jsxs as h, Fragment as ve } from "react/jsx-runtime";
2
- import { Node as it, mergeAttributes as at } from "@tiptap/core";
3
- import ct from "@tiptap/extension-image";
4
- import st from "@tiptap/extension-link";
5
- import lt from "@tiptap/extension-placeholder";
6
- import { TableKit as ut, TableCell as dt, TableHeader as ht } from "@tiptap/extension-table";
7
- import mt from "@tiptap/extension-text-align";
8
- import { TextStyle as ft, Color as pt, BackgroundColor as gt } from "@tiptap/extension-text-style";
9
- import bt from "@tiptap/extension-task-item";
10
- import vt from "@tiptap/extension-task-list";
11
- import { Markdown as kt } from "@tiptap/markdown";
12
- import { CellSelection as ae } from "@tiptap/pm/tables";
13
- import { Slice as We } from "@tiptap/pm/model";
14
- import { useEditor as Dt, EditorContent as wt } from "@tiptap/react";
15
- import { FloatingMenu as xt, BubbleMenu as ke } from "@tiptap/react/menus";
16
- import Ct from "@tiptap/starter-kit";
17
- import { Toolbar as te, ToolbarSeparator as L, Input as De, IconTip as ce, Pressable as g, MenuChoiceGroup as K, MenuCommandItem as z, Popover as we, ToolbarButton as W, Button as re, Modal as yt } from "@agent-factory-platform/ui-kit";
18
- import { Heading1 as xe, Heading2 as Ce, Heading3 as ye, List as ze, ListOrdered as Se, ListChecks as Ae, Quote as Ne, SquareCode as Te, MessageSquareWarning as Re, Table2 as ne, Pilcrow as Le, Bold as Be, Italic as Me, Underline as Oe, Strikethrough as Ee, Code2 as He, Link2 as _e, Plus as zt, Sparkles as Ie, ImagePlus as Pe, Palette as qe, AlignLeft as $e, AlignCenter as St, AlignRight as At, Minus as Nt, ChevronDown as Tt, WandSparkles as Rt, BetweenHorizontalStart as Lt, BetweenHorizontalEnd as Bt, Rows3 as Mt, BetweenVerticalStart as Ot, BetweenVerticalEnd as Et, Columns3 as Ht, TableCellsMerge as _t, TableCellsSplit as It, Trash2 as Pt } from "lucide-react";
19
- import { useMemo as qt, useState as w, useSyncExternalStore as $t, useRef as oe, useEffect as Je, useLayoutEffect as Jt } from "react";
20
- const _ = "agentfactory.richtext.v1";
21
- function jt(o) {
1
+ import { jsx as t, jsxs as p, Fragment as De } from "react/jsx-runtime";
2
+ import { Node as lt, mergeAttributes as ut } from "@tiptap/core";
3
+ import dt from "@tiptap/extension-image";
4
+ import ht from "@tiptap/extension-link";
5
+ import mt from "@tiptap/extension-placeholder";
6
+ import { TableKit as ft, TableCell as pt, TableHeader as gt } from "@tiptap/extension-table";
7
+ import bt from "@tiptap/extension-text-align";
8
+ import { TextStyle as vt, Color as kt, BackgroundColor as Dt } from "@tiptap/extension-text-style";
9
+ import xt from "@tiptap/extension-task-item";
10
+ import wt from "@tiptap/extension-task-list";
11
+ import { Markdown as Ct } from "@tiptap/markdown";
12
+ import { CellSelection as se } from "@tiptap/pm/tables";
13
+ import { Slice as Ve } from "@tiptap/pm/model";
14
+ import { useEditor as yt, EditorContent as zt } from "@tiptap/react";
15
+ import { FloatingMenu as At, BubbleMenu as xe } from "@tiptap/react/menus";
16
+ import St from "@tiptap/starter-kit";
17
+ import { Toolbar as re, ToolbarSeparator as M, Input as we, IconTip as le, Pressable as v, MenuChoiceGroup as J, MenuCommandItem as S, Popover as Ce, ToolbarButton as F, Button as ne, Modal as Nt } from "@agent-factory-platform/ui-kit";
18
+ import { Heading1 as ye, Heading2 as ze, Heading3 as Ae, List as Se, ListOrdered as Ne, ListChecks as Te, Quote as Re, SquareCode as Le, MessageSquareWarning as Me, Table2 as oe, Pilcrow as Be, Bold as Oe, Italic as Ee, Underline as He, Strikethrough as Ie, Code2 as Pe, Link2 as _e, Plus as Tt, Sparkles as je, ImagePlus as qe, Palette as $e, AlignLeft as Je, AlignCenter as Rt, AlignRight as Lt, Minus as Mt, ChevronDown as Bt, WandSparkles as Ot, BetweenHorizontalStart as Et, BetweenHorizontalEnd as Ht, Rows3 as It, BetweenVerticalStart as Pt, BetweenVerticalEnd as _t, Columns3 as jt, TableCellsMerge as qt, TableCellsSplit as $t, Trash2 as Jt } from "lucide-react";
19
+ import { useMemo as Ft, useState as x, useSyncExternalStore as Kt, useRef as ie, useEffect as ae, useLayoutEffect as Wt } from "react";
20
+ const W = "agentfactory.richtext.v1";
21
+ function Vt(o) {
22
22
  return (o.split(".").at(-1) ?? o).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (c) => c.toUpperCase());
23
23
  }
24
- const je = { status: "idle", output: "" }, Kt = () => () => {
24
+ const Fe = { status: "idle", output: "" }, Xt = () => () => {
25
25
  };
26
- function Wt(o, i, c) {
27
- const m = o.state.doc.content.size, k = i.to - i.from;
28
- return o.commands.insertContentAt(i, c, { contentType: "markdown", updateSelection: !0 }), { from: i.from, to: i.from + o.state.doc.content.size - m + k };
26
+ function Gt(o, i, c) {
27
+ const h = o.state.doc.content.size, k = i.to - i.from;
28
+ return o.commands.insertContentAt(i, c, { contentType: "markdown", updateSelection: !0 }), { from: i.from, to: i.from + o.state.doc.content.size - h + k };
29
29
  }
30
- function Ft(o, i, c, m) {
30
+ function Yt(o, i, c, h) {
31
31
  try {
32
- return o.state.doc.slice(i.from, i.to).content.eq(m.content) ? (o.view.dispatch(o.state.tr.replaceRange(i.from, i.to, c)), !0) : !1;
32
+ return o.state.doc.slice(i.from, i.to).content.eq(h.content) ? (o.view.dispatch(o.state.tr.replaceRange(i.from, i.to, c)), !0) : !1;
33
33
  } catch {
34
34
  return !1;
35
35
  }
36
36
  }
37
- async function Vt(o, i, c) {
38
- const m = o.state.doc;
39
- if (!m.slice(i.range.from, i.range.to).content.eq(i.generated.content)) return;
40
- const k = o.state.tr.replaceRange(i.range.from, i.range.to, i.original), v = { schema: _, doc: k.doc.toJSON() }, x = String(await c(v));
41
- if (o.state.doc.eq(m))
42
- return o.view.dispatch(o.state.tr.replaceRange(i.range.from, i.range.to, i.original)), { value: v, revision: x };
37
+ async function Qt(o, i, c) {
38
+ const h = o.state.doc;
39
+ if (!h.slice(i.range.from, i.range.to).content.eq(i.generated.content)) return;
40
+ const k = o.state.tr.replaceRange(i.range.from, i.range.to, i.original), D = { schema: W, doc: k.doc.toJSON() }, C = String(await c(D));
41
+ if (o.state.doc.eq(h))
42
+ return o.view.dispatch(o.state.tr.replaceRange(i.range.from, i.range.to, i.original)), { value: D, revision: C };
43
43
  }
44
- function Xt(o, i, c, m) {
45
- if (!Fe(o, i, c))
44
+ function Ut(o, i, c, h) {
45
+ if (!Xe(o, i, c))
46
46
  try {
47
- const k = We.fromJSON(o.schema, c.originalSlice), v = Wt(o, c.range, m);
48
- return { range: v, original: k, generated: o.state.doc.slice(v.from, v.to) };
47
+ const k = Ve.fromJSON(o.schema, c.originalSlice), D = Gt(o, c.range, h);
48
+ return { range: D, original: k, generated: o.state.doc.slice(D.from, D.to) };
49
49
  } catch {
50
50
  return;
51
51
  }
52
52
  }
53
- function Fe(o, i, c) {
53
+ function Xe(o, i, c) {
54
54
  if (i.documentId !== c.documentId || i.nodeId !== c.nodeId) return "identity";
55
55
  if (i.baseRevision !== c.baseRevision) return "revision";
56
56
  if (!c.originalSlice) return "missing_original";
57
57
  if (c.range.from < 0 || c.range.to < c.range.from || c.range.to > o.state.doc.content.size) return "range";
58
58
  try {
59
- const m = We.fromJSON(o.schema, c.originalSlice);
60
- if (!o.state.doc.slice(c.range.from, c.range.to).content.eq(m.content)) return "selection";
59
+ const h = Ve.fromJSON(o.schema, c.originalSlice);
60
+ if (!o.state.doc.slice(c.range.from, c.range.to).content.eq(h.content)) return "selection";
61
61
  } catch {
62
62
  return "invalid_slice";
63
63
  }
64
64
  }
65
- const Gt = it.create({
65
+ const Zt = lt.create({
66
66
  name: "callout",
67
67
  group: "block",
68
68
  content: "block+",
69
69
  defining: !0,
70
70
  parseHTML: () => [{ tag: "aside[data-callout]" }],
71
- renderHTML: ({ HTMLAttributes: o }) => ["aside", at(o, { "data-callout": "info" }), 0]
72
- }), Qt = ct.extend({
71
+ renderHTML: ({ HTMLAttributes: o }) => ["aside", ut(o, { "data-callout": "info" }), 0]
72
+ }), er = dt.extend({
73
73
  addAttributes() {
74
74
  var o;
75
75
  return { ...(o = this.parent) == null ? void 0 : o.call(this), asset_id: { default: null, parseHTML: (i) => i.getAttribute("data-asset-id"), renderHTML: (i) => i.asset_id ? { "data-asset-id": i.asset_id } : {} } };
76
76
  }
77
- }), Ut = ["var(--color-ink)", "var(--color-graphite)", "var(--color-rust)", "var(--color-data-blue)", "var(--color-success)", "var(--color-warning)", "var(--color-danger)"], F = ["var(--color-surface-muted)", "var(--color-surface-warm)", "var(--color-surface-cool)", "var(--color-data-4)", "var(--color-data-5)"], Ve = () => ({
77
+ }), tr = ["var(--color-ink)", "var(--color-graphite)", "var(--color-rust)", "var(--color-data-blue)", "var(--color-success)", "var(--color-warning)", "var(--color-danger)"], K = ["var(--color-surface-muted)", "var(--color-surface-warm)", "var(--color-surface-cool)", "var(--color-data-4)", "var(--color-data-5)"], Ge = () => ({
78
78
  default: null,
79
- parseHTML: (o) => F.includes(o.style.backgroundColor) ? o.style.backgroundColor : null,
80
- renderHTML: ({ backgroundColor: o }) => o && F.includes(o) ? { style: `background-color: ${o}` } : {}
81
- }), Yt = dt.extend({ addAttributes() {
79
+ parseHTML: (o) => K.includes(o.style.backgroundColor) ? o.style.backgroundColor : null,
80
+ renderHTML: ({ backgroundColor: o }) => o && K.includes(o) ? { style: `background-color: ${o}` } : {}
81
+ }), rr = pt.extend({ addAttributes() {
82
82
  var o;
83
- return { ...(o = this.parent) == null ? void 0 : o.call(this), backgroundColor: Ve() };
84
- } }), Zt = ht.extend({ addAttributes() {
83
+ return { ...(o = this.parent) == null ? void 0 : o.call(this), backgroundColor: Ge() };
84
+ } }), nr = gt.extend({ addAttributes() {
85
85
  var o;
86
- return { ...(o = this.parent) == null ? void 0 : o.call(this), backgroundColor: Ve() };
87
- } }), Ke = () => ({ schema: _, doc: { type: "doc", content: [{ type: "paragraph" }] } });
88
- function Cr(o) {
86
+ return { ...(o = this.parent) == null ? void 0 : o.call(this), backgroundColor: Ge() };
87
+ } }), Ke = () => ({ schema: W, doc: { type: "doc", content: [{ type: "paragraph" }] } });
88
+ function We(o) {
89
+ const i = (c) => {
90
+ const h = c.type === "image" && c.attrs ? Object.fromEntries(Object.entries(c.attrs).filter(([k]) => k !== "src")) : c.attrs;
91
+ return {
92
+ ...c,
93
+ ...h ? { attrs: h } : {},
94
+ ...c.content ? { content: c.content.map(i) } : {}
95
+ };
96
+ };
97
+ return { schema: W, doc: i(o) };
98
+ }
99
+ function Sr(o) {
89
100
  const i = JSON.parse(o);
90
101
  if (!i || typeof i != "object") throw new Error("invalid rich document");
91
102
  const c = i;
92
103
  if (c.doc === void 0)
93
104
  throw i.type === "doc" ? new Error("unsupported rich document schema") : new Error("invalid rich document");
94
- if (c.schema !== _) throw new Error("unsupported rich document schema");
105
+ if (c.schema !== W) throw new Error("unsupported rich document schema");
95
106
  if (!c.doc || typeof c.doc != "object" || c.doc.type !== "doc") throw new Error("invalid rich document");
96
107
  return c;
97
108
  }
98
- const er = (o) => {
99
- if (o.state.selection instanceof ae) return !0;
109
+ const or = (o) => {
110
+ if (o.state.selection instanceof se) return !0;
100
111
  const { $from: i } = o.state.selection;
101
112
  for (let c = i.depth; c > 0; c -= 1) if (i.node(c).type.name === "table") return !0;
102
113
  return !1;
103
- }, tr = (o, i) => {
104
- const c = o.state.selection.getBookmark(), m = o.isFocused;
114
+ }, ir = (o, i) => {
115
+ const c = o.state.selection.getBookmark(), h = o.isFocused;
105
116
  o.commands.setContent(i, { emitUpdate: !1 });
106
117
  try {
107
118
  o.view.dispatch(o.state.tr.setSelection(c.resolve(o.state.doc)));
108
119
  } catch {
109
120
  }
110
- m && o.commands.focus();
111
- }, rr = (o) => [
112
- Ct.configure({ heading: { levels: [1, 2, 3] }, link: !1 }),
113
- st.configure({ openOnClick: !0, autolink: !0, defaultProtocol: "https", HTMLAttributes: { target: "_blank", rel: "noopener noreferrer" } }),
114
- Qt.configure({
121
+ h && o.commands.focus();
122
+ }, ar = (o) => [
123
+ St.configure({ heading: { levels: [1, 2, 3] }, link: !1 }),
124
+ ht.configure({ openOnClick: !0, autolink: !0, defaultProtocol: "https", protocols: ["http", "https", "mailto"], HTMLAttributes: { target: "_blank", rel: "noopener noreferrer" } }),
125
+ er.configure({
115
126
  allowBase64: !1,
116
127
  resize: {
117
128
  enabled: !0,
@@ -121,343 +132,366 @@ const er = (o) => {
121
132
  alwaysPreserveAspectRatio: !0
122
133
  }
123
134
  }),
124
- ut.configure({ table: { resizable: !0, allowTableNodeSelection: !0 }, tableCell: !1, tableHeader: !1 }),
125
- Yt,
126
- Zt,
127
- mt.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
128
- ft,
129
- pt,
130
- gt,
135
+ ft.configure({ table: { resizable: !0, allowTableNodeSelection: !0 }, tableCell: !1, tableHeader: !1 }),
136
+ rr,
137
+ nr,
138
+ bt.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right"] }),
131
139
  vt,
132
- bt.configure({ nested: !0 }),
133
- Gt,
134
- lt.configure({ placeholder: o }),
135
- kt
140
+ kt,
141
+ Dt,
142
+ wt,
143
+ xt.configure({ nested: !0 }),
144
+ Zt,
145
+ mt.configure({ placeholder: o }),
146
+ Ct
136
147
  ];
137
- function yr({ value: o, editable: i, placeholder: c, ariaLabel: m, linkLabel: k = "Link address", saveLabel: v = "Save", surface: x = "panel", source: S, documentId: I = (S == null ? void 0 : S.id) ?? "", nodeId: T = (S == null ? void 0 : S.id) ?? "", baseRevision: B = "", assistant: f, assistantInstructions: Xe = {}, onChange: C, onAssistantCommit: V, onImageUpload: y, labels: Ge = {} }) {
138
- var ge;
139
- if (f && !V) throw new Error("RichDocument assistant requires onAssistantCommit");
140
- const n = (r) => Ge[r] ?? jt(r), Qe = qt(() => rr(c), [c]), [Ue, se] = w(!1), [le, X] = w(!1), [M, A] = w(null), [ue, G] = w(!1), [Ye, P] = w(!1), [de, Q] = w(""), [q, D] = w(""), [Ze, R] = w(), [O, U] = w(), [he, $] = w(!1), d = $t((f == null ? void 0 : f.subscribe) ?? Kt, (f == null ? void 0 : f.getSnapshot) ?? (() => je), (f == null ? void 0 : f.getSnapshot) ?? (() => je)), Y = oe(null), E = oe(null), H = oe(!1), Z = async (r, a) => {
141
- const s = E.current;
142
- if (!s || !y) return;
148
+ function Nr({ value: o, editable: i, placeholder: c, ariaLabel: h, linkLabel: k = "Link address", saveLabel: D = "Save", surface: C = "panel", source: N, documentId: P = (N == null ? void 0 : N.id) ?? "", nodeId: R = (N == null ? void 0 : N.id) ?? "", baseRevision: B = "", assistant: g, assistantInstructions: Ye = {}, onChange: y, onAssistantCommit: V, onImageUpload: z, resolveImage: X, labels: Qe = {} }) {
149
+ var ve;
150
+ if (g && !V) throw new Error("RichDocument assistant requires onAssistantCommit");
151
+ const n = (r) => Qe[r] ?? Vt(r), Ue = Ft(() => ar(c), [c]), [Ze, ue] = x(!1), [de, G] = x(!1), [O, T] = x(null), [he, Y] = x(!1), [et, _] = x(!1), [me, Q] = x(""), [j, w] = x(""), [tt, L] = x(), [E, U] = x(), [fe, q] = x(!1), [rt, nt] = x(0), m = Kt((g == null ? void 0 : g.subscribe) ?? Xt, (g == null ? void 0 : g.getSnapshot) ?? (() => Fe), (g == null ? void 0 : g.getSnapshot) ?? (() => Fe)), Z = ie(null), H = ie(null), I = ie(!1), ee = async (r, a) => {
152
+ const s = H.current;
153
+ if (!s || !z) return;
143
154
  let u;
144
155
  try {
145
- u = await y(r);
156
+ u = await z(r);
146
157
  } catch {
147
158
  return;
148
159
  }
149
- const b = { type: "image", attrs: { src: u.url, asset_id: u.assetId } };
150
- a !== void 0 ? s.chain().focus().insertContentAt(a, b).run() : s.chain().focus().setImage(b.attrs).run();
151
- }, e = Dt({
152
- extensions: Qe,
160
+ const f = { type: "image", attrs: { src: u.url, asset_id: u.assetId } };
161
+ a !== void 0 ? s.chain().focus().insertContentAt(a, f).run() : s.chain().focus().setImage(f.attrs).run();
162
+ }, e = yt({
163
+ extensions: Ue,
153
164
  content: (o ?? Ke()).doc,
154
165
  contentType: "json",
155
166
  editable: i,
156
167
  immediatelyRender: !1,
157
168
  editorProps: {
158
- attributes: { class: x === "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": m, role: i ? "textbox" : "document", "aria-multiline": i ? "true" : "false" },
169
+ attributes: { class: C === "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": h, role: i ? "textbox" : "document", "aria-multiline": i ? "true" : "false" },
159
170
  handlePaste: (r, a) => {
160
- var b, N, p;
161
- const s = [...((b = a.clipboardData) == null ? void 0 : b.files) ?? []].find((j) => j.type.startsWith("image/"));
162
- if (s && y)
163
- return Z(s), !0;
164
- const u = ((N = a.clipboardData) == null ? void 0 : N.getData("text/plain")) ?? "";
165
- return nr(u) ? ((p = E.current) == null || p.commands.insertContent(u, { contentType: "markdown" }), !0) : !1;
171
+ var f, b, d;
172
+ const s = [...((f = a.clipboardData) == null ? void 0 : f.files) ?? []].find((A) => A.type.startsWith("image/"));
173
+ if (s && z)
174
+ return ee(s), !0;
175
+ const u = ((b = a.clipboardData) == null ? void 0 : b.getData("text/plain")) ?? "";
176
+ return cr(u) ? ((d = H.current) == null || d.commands.insertContent(u, { contentType: "markdown" }), !0) : !1;
166
177
  },
167
178
  handleDrop: (r, a) => {
168
- var b, N;
169
- const s = [...((b = a.dataTransfer) == null ? void 0 : b.files) ?? []].find((p) => p.type.startsWith("image/"));
170
- if (!s || !y) return !1;
171
- const u = (N = r.posAtCoords({ left: a.clientX, top: a.clientY })) == null ? void 0 : N.pos;
172
- return Z(s, u), !0;
179
+ var f, b;
180
+ const s = [...((f = a.dataTransfer) == null ? void 0 : f.files) ?? []].find((d) => d.type.startsWith("image/"));
181
+ if (!s || !z) return !1;
182
+ const u = (b = r.posAtCoords({ left: a.clientX, top: a.clientY })) == null ? void 0 : b.pos;
183
+ return ee(s, u), !0;
173
184
  },
174
185
  handleKeyDown: (r, a) => {
175
186
  if (!i || !(a.metaKey || a.ctrlKey) || a.key.toLowerCase() !== "k") return !1;
176
187
  a.preventDefault(), a.stopPropagation();
177
- const s = E.current;
178
- return Q(String((s == null ? void 0 : s.getAttributes("link").href) ?? "https://")), P(!0), !0;
188
+ const s = H.current;
189
+ return Q(String((s == null ? void 0 : s.getAttributes("link").href) ?? "https://")), _(!0), !0;
179
190
  }
180
191
  },
181
- onUpdate: ({ editor: r }) => {
182
- se(r.state.doc.textBetween(Math.max(0, r.state.doc.content.size - 2), r.state.doc.content.size, " ").endsWith("/")), H.current || C == null || C({ schema: _, doc: r.getJSON() });
192
+ onUpdate: ({ editor: r, transaction: a }) => {
193
+ ue(r.state.doc.textBetween(Math.max(0, r.state.doc.content.size - 2), r.state.doc.content.size, " ").endsWith("/")), !I.current && !a.getMeta("docsAssetProjection") && (y == null || y(We(r.getJSON())));
183
194
  }
184
195
  });
185
- Je(() => (E.current = e, () => {
186
- E.current = null;
187
- }), [e]), Je(() => {
196
+ ae(() => (H.current = e, () => {
197
+ H.current = null;
198
+ }), [e]), ae(() => {
188
199
  e == null || e.setEditable(i);
189
- }, [i, e]), Jt(() => {
200
+ }, [i, e]), Wt(() => {
190
201
  if (!e) return;
191
202
  const r = (o ?? Ke()).doc;
192
203
  if (JSON.stringify(e.getJSON()) !== JSON.stringify(r)) {
193
- H.current = !0;
204
+ I.current = !0;
194
205
  try {
195
- tr(e, r);
206
+ ir(e, r);
196
207
  } finally {
197
- H.current = !1;
208
+ I.current = !1;
198
209
  }
199
210
  }
200
- }, [e, o]);
201
- const J = (r) => {
202
- r(), se(!1), e == null || e.commands.focus();
203
- }, me = () => {
204
- e && (Q(String(e.getAttributes("link").href ?? "https://")), P(!0));
205
- }, et = () => {
211
+ }, [e, o]), ae(() => {
212
+ if (!e || !X) return;
213
+ let r = !1, a;
214
+ const s = [];
215
+ return e.state.doc.descendants((u, f) => {
216
+ const b = u.type.name === "image" ? String(u.attrs.asset_id ?? "") : "";
217
+ b && s.push({ assetId: b, position: f });
218
+ }), Promise.allSettled(s.map(async (u) => ({ ...u, ...await X(u.assetId) }))).then((u) => {
219
+ if (r) return;
220
+ let f = e.state.tr, b = Number.POSITIVE_INFINITY;
221
+ for (const d of u) {
222
+ if (d.status !== "fulfilled" || !d.value.url) continue;
223
+ const A = f.doc.nodeAt(d.value.position);
224
+ if (!(!A || String(A.attrs.asset_id ?? "") !== d.value.assetId) && (f = f.setNodeMarkup(d.value.position, void 0, { ...A.attrs, src: d.value.url }), d.value.expiresAt !== void 0)) {
225
+ const ke = new Date(d.value.expiresAt).getTime();
226
+ Number.isFinite(ke) && (b = Math.min(b, ke));
227
+ }
228
+ }
229
+ f.docChanged && e.view.dispatch(f.setMeta("docsAssetProjection", !0).setMeta("addToHistory", !1)), Number.isFinite(b) && (a = setTimeout(() => nt((d) => d + 1), Math.max(1e3, b - Date.now() - 3e4)));
230
+ }), () => {
231
+ r = !0, a && clearTimeout(a);
232
+ };
233
+ }, [e, rt, X, o]);
234
+ const $ = (r) => {
235
+ r(), ue(!1), e == null || e.commands.focus();
236
+ }, pe = () => {
237
+ e && (Q(String(e.getAttributes("link").href ?? "https://")), _(!0));
238
+ }, ot = () => {
206
239
  if (!e) return;
207
- const r = de.trim();
208
- r ? e.chain().focus().extendMarkRange("link").setLink({ href: r }).run() : e.chain().focus().unsetLink().run(), P(!1);
209
- }, ee = (r) => {
210
- if (!e || !f) return;
240
+ const r = me.trim();
241
+ r ? e.chain().focus().extendMarkRange("link").setLink({ href: r }).run() : e.chain().focus().unsetLink().run(), _(!1);
242
+ }, te = (r) => {
243
+ if (!e || !g) return;
211
244
  const { from: a, to: s } = e.state.selection, u = e.state.doc.textBetween(a, s, `
212
- `), b = [];
213
- e.state.doc.nodesBetween(a, Math.max(a + 1, s), (p) => {
214
- if (p.type.name !== "image") return;
215
- const j = String(p.attrs.asset_id ?? ""), be = String(p.attrs.src ?? "");
216
- j && be && b.push({ assetId: j, url: be });
245
+ `), f = [];
246
+ e.state.doc.nodesBetween(a, Math.max(a + 1, s), (d) => {
247
+ if (d.type.name !== "image") return;
248
+ const A = String(d.attrs.asset_id ?? "");
249
+ A && f.push({ assetId: A });
217
250
  });
218
- const N = Xe[r] ?? `${r === "explain" ? "Explain" : r === "rewrite" ? "Rewrite" : "Continue"} the selected document content.`;
219
- D(""), R(void 0), U(void 0), f.submit({
220
- version: 1,
251
+ const b = Ye[r] ?? `${r === "explain" ? "Explain" : r === "rewrite" ? "Rewrite" : "Continue"} the selected document content.`;
252
+ w(""), L(void 0), U(void 0), g.submit({
253
+ version: 2,
221
254
  operation: r,
222
- documentId: I,
223
- nodeId: T,
255
+ documentId: P,
256
+ nodeId: R,
224
257
  baseRevision: String(B),
225
258
  range: { from: a, to: s },
226
259
  selection: u,
227
- instruction: N,
260
+ instruction: b,
228
261
  context: `${e.getText({ blockSeparator: `
229
- ` }).slice(-12e3)}${b.length ? `
262
+ ` }).slice(-12e3)}${f.length ? `
230
263
 
231
- [Selected images: ${b.map((p) => p.assetId).join(", ")}]` : ""}`,
264
+ [Selected images: ${f.map((d) => d.assetId).join(", ")}]` : ""}`,
232
265
  originalSlice: e.state.doc.slice(a, s).toJSON(),
233
- images: b,
234
- source: S
235
- }).catch((p) => D(p instanceof Error ? p.message : String(p)));
236
- }, tt = async () => {
237
- if (!e || !d.operation || !d.output) return;
238
- const r = Fe(e, { documentId: I, nodeId: T, baseRevision: String(B) }, d.operation);
266
+ images: f,
267
+ source: N
268
+ }).catch((d) => w(d instanceof Error ? d.message : String(d)));
269
+ }, it = async () => {
270
+ if (!e || !m.operation || !m.output) return;
271
+ const r = Xe(e, { documentId: P, nodeId: R, baseRevision: String(B) }, m.operation);
239
272
  if (r) {
240
- R(r), D(n("richDocument.aiConflict"));
273
+ L(r), w(n("richDocument.aiConflict"));
241
274
  return;
242
275
  }
243
- H.current = !0;
276
+ I.current = !0;
244
277
  let a;
245
278
  try {
246
- a = Xt(e, { documentId: I, nodeId: T, baseRevision: String(B) }, d.operation, d.output);
279
+ a = Ut(e, { documentId: P, nodeId: R, baseRevision: String(B) }, m.operation, m.output);
247
280
  } finally {
248
- H.current = !1;
281
+ I.current = !1;
249
282
  }
250
283
  if (!a) {
251
- R("invalid_slice"), D(n("richDocument.aiConflict"));
284
+ L("invalid_slice"), w(n("richDocument.aiConflict"));
252
285
  return;
253
286
  }
254
- const s = { schema: _, doc: e.getJSON() };
255
- $(!0), e.setEditable(!1);
287
+ const s = We(e.getJSON());
288
+ q(!0), e.setEditable(!1);
256
289
  try {
257
- const u = String(await V({ kind: "apply", value: s, nodeId: T, expectedRevision: String(B) }));
258
- D(""), R(void 0), U({ ...a, revision: u }), C == null || C(s, u);
290
+ const u = String(await V({ kind: "apply", value: s, nodeId: R, expectedRevision: String(B) }));
291
+ w(""), L(void 0), U({ ...a, revision: u }), y == null || y(s, u);
259
292
  } catch {
260
- Ft(e, a.range, a.original, a.generated), D(n("richDocument.aiConflict"));
293
+ Yt(e, a.range, a.original, a.generated), w(n("richDocument.aiConflict"));
261
294
  } finally {
262
- e.setEditable(i), $(!1);
295
+ e.setEditable(i), q(!1);
263
296
  }
264
- }, rt = async () => {
265
- if (!(!e || !O)) {
266
- $(!0), e.setEditable(!1);
297
+ }, at = async () => {
298
+ if (!(!e || !E)) {
299
+ q(!0), e.setEditable(!1);
267
300
  try {
268
- const r = await Vt(e, O, (a) => V({ kind: "rollback", value: a, nodeId: T, expectedRevision: O.revision }));
301
+ const r = await Qt(e, E, (a) => V({ kind: "rollback", value: a, nodeId: R, expectedRevision: E.revision }));
269
302
  if (!r) {
270
- R("selection"), D(n("richDocument.aiConflict"));
303
+ L("selection"), w(n("richDocument.aiConflict"));
271
304
  return;
272
305
  }
273
- D(""), R(void 0), U(void 0), C == null || C(r.value, r.revision);
306
+ w(""), L(void 0), U(void 0), y == null || y(r.value, r.revision);
274
307
  } catch {
275
- D(n("richDocument.aiConflict"));
308
+ w(n("richDocument.aiConflict"));
276
309
  } finally {
277
- e.setEditable(i), $(!1);
310
+ e.setEditable(i), q(!1);
278
311
  }
279
312
  }
280
- }, l = (r, a, s, u) => /* @__PURE__ */ t(W, { title: r, "aria-label": r, "aria-pressed": s, className: "aria-pressed:bg-surface-raised aria-pressed:text-ink", onClick: u, children: a }), fe = (r, a, s) => /* @__PURE__ */ t(W, { title: a, "aria-label": a, "aria-expanded": M === r, onMouseDown: (u) => u.preventDefault(), onClick: () => A((u) => u === r ? null : r), children: s }), nt = (r) => {
281
- r(), X(!1), e == null || e.commands.focus();
282
- }, pe = e ? [
283
- [n("richDocument.heading1"), /* @__PURE__ */ t(xe, { size: 15, "aria-hidden": !0 }, "h1"), () => e.chain().focus().toggleHeading({ level: 1 }).run()],
284
- [n("richDocument.heading2"), /* @__PURE__ */ t(Ce, { size: 15, "aria-hidden": !0 }, "h2"), () => e.chain().focus().toggleHeading({ level: 2 }).run()],
285
- [n("richDocument.heading3"), /* @__PURE__ */ t(ye, { size: 15, "aria-hidden": !0 }, "h3"), () => e.chain().focus().toggleHeading({ level: 3 }).run()],
286
- [n("richDocument.bulletList"), /* @__PURE__ */ t(ze, { size: 15, "aria-hidden": !0 }, "bullet"), () => e.chain().focus().toggleBulletList().run()],
287
- [n("richDocument.orderedList"), /* @__PURE__ */ t(Se, { size: 15, "aria-hidden": !0 }, "ordered"), () => e.chain().focus().toggleOrderedList().run()],
288
- [n("richDocument.taskList"), /* @__PURE__ */ t(Ae, { size: 15, "aria-hidden": !0 }, "task"), () => e.chain().focus().toggleTaskList().run()],
289
- [n("richDocument.quote"), /* @__PURE__ */ t(Ne, { size: 15, "aria-hidden": !0 }, "quote"), () => e.chain().focus().toggleBlockquote().run()],
290
- [n("richDocument.codeBlock"), /* @__PURE__ */ t(Te, { size: 15, "aria-hidden": !0 }, "code"), () => e.chain().focus().toggleCodeBlock().run()],
291
- [n("richDocument.callout"), /* @__PURE__ */ t(Re, { size: 15, "aria-hidden": !0 }, "callout"), () => e.chain().focus().wrapIn("callout").run()],
292
- [n("richDocument.table"), /* @__PURE__ */ t(ne, { size: 15, "aria-hidden": !0 }, "table"), () => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()]
293
- ] : [], ot = e ? [
294
- [n("richDocument.paragraph"), /* @__PURE__ */ t(Le, { size: 15, "aria-hidden": !0 }, "p"), () => e.chain().focus().setParagraph().run()],
295
- ...pe.slice(0, 8)
313
+ }, l = (r, a, s, u) => /* @__PURE__ */ t(F, { title: r, "aria-label": r, "aria-pressed": s, className: "aria-pressed:bg-surface-raised aria-pressed:text-ink", onClick: u, children: a }), ge = (r, a, s) => /* @__PURE__ */ t(F, { title: a, "aria-label": a, "aria-expanded": O === r, onMouseDown: (u) => u.preventDefault(), onClick: () => T((u) => u === r ? null : r), children: s }), ct = (r) => {
314
+ r(), G(!1), e == null || e.commands.focus();
315
+ }, be = e ? [
316
+ [n("richDocument.heading1"), /* @__PURE__ */ t(ye, { size: 15, "aria-hidden": !0 }, "h1"), () => e.chain().focus().toggleHeading({ level: 1 }).run()],
317
+ [n("richDocument.heading2"), /* @__PURE__ */ t(ze, { size: 15, "aria-hidden": !0 }, "h2"), () => e.chain().focus().toggleHeading({ level: 2 }).run()],
318
+ [n("richDocument.heading3"), /* @__PURE__ */ t(Ae, { size: 15, "aria-hidden": !0 }, "h3"), () => e.chain().focus().toggleHeading({ level: 3 }).run()],
319
+ [n("richDocument.bulletList"), /* @__PURE__ */ t(Se, { size: 15, "aria-hidden": !0 }, "bullet"), () => e.chain().focus().toggleBulletList().run()],
320
+ [n("richDocument.orderedList"), /* @__PURE__ */ t(Ne, { size: 15, "aria-hidden": !0 }, "ordered"), () => e.chain().focus().toggleOrderedList().run()],
321
+ [n("richDocument.taskList"), /* @__PURE__ */ t(Te, { size: 15, "aria-hidden": !0 }, "task"), () => e.chain().focus().toggleTaskList().run()],
322
+ [n("richDocument.quote"), /* @__PURE__ */ t(Re, { size: 15, "aria-hidden": !0 }, "quote"), () => e.chain().focus().toggleBlockquote().run()],
323
+ [n("richDocument.codeBlock"), /* @__PURE__ */ t(Le, { size: 15, "aria-hidden": !0 }, "code"), () => e.chain().focus().toggleCodeBlock().run()],
324
+ [n("richDocument.callout"), /* @__PURE__ */ t(Me, { size: 15, "aria-hidden": !0 }, "callout"), () => e.chain().focus().wrapIn("callout").run()],
325
+ [n("richDocument.table"), /* @__PURE__ */ t(oe, { size: 15, "aria-hidden": !0 }, "table"), () => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()]
326
+ ] : [], st = e ? [
327
+ [n("richDocument.paragraph"), /* @__PURE__ */ t(Be, { size: 15, "aria-hidden": !0 }, "p"), () => e.chain().focus().setParagraph().run()],
328
+ ...be.slice(0, 8)
296
329
  ] : [];
297
- return /* @__PURE__ */ h("div", { className: x === "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": I || void 0, "data-node-id": T || void 0, "data-base-revision": String(B) || void 0, "data-editable": i || void 0, "data-surface": x, onDragOver: (r) => y && r.preventDefault(), children: [
298
- i && e && /* @__PURE__ */ h(te, { label: m, density: "compact", variant: x === "document" ? "bare" : "framed", className: x === "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: [
299
- l(n("richDocument.heading1"), /* @__PURE__ */ t(xe, { size: 15, "aria-hidden": !0 }), e.isActive("heading", { level: 1 }), () => e.chain().focus().toggleHeading({ level: 1 }).run()),
300
- l(n("richDocument.heading2"), /* @__PURE__ */ t(Ce, { size: 15, "aria-hidden": !0 }), e.isActive("heading", { level: 2 }), () => e.chain().focus().toggleHeading({ level: 2 }).run()),
301
- l(n("richDocument.heading3"), /* @__PURE__ */ t(ye, { size: 15, "aria-hidden": !0 }), e.isActive("heading", { level: 3 }), () => e.chain().focus().toggleHeading({ level: 3 }).run()),
302
- /* @__PURE__ */ t(L, {}),
303
- l(n("richDocument.bold"), /* @__PURE__ */ t(Be, { size: 15, "aria-hidden": !0 }), e.isActive("bold"), () => e.chain().focus().toggleBold().run()),
304
- l(n("richDocument.italic"), /* @__PURE__ */ t(Me, { size: 15, "aria-hidden": !0 }), e.isActive("italic"), () => e.chain().focus().toggleItalic().run()),
305
- l(n("richDocument.underline"), /* @__PURE__ */ t(Oe, { size: 15, "aria-hidden": !0 }), e.isActive("underline"), () => e.chain().focus().toggleUnderline().run()),
306
- l(n("richDocument.strike"), /* @__PURE__ */ t(Ee, { size: 15, "aria-hidden": !0 }), e.isActive("strike"), () => e.chain().focus().toggleStrike().run()),
307
- l(n("richDocument.code"), /* @__PURE__ */ t(He, { size: 15, "aria-hidden": !0 }), e.isActive("code"), () => e.chain().focus().toggleCode().run()),
308
- l(n("richDocument.link"), /* @__PURE__ */ t(_e, { size: 15, "aria-hidden": !0 }), e.isActive("link"), me),
309
- /* @__PURE__ */ t(L, {}),
310
- l(n("richDocument.bulletList"), /* @__PURE__ */ t(ze, { size: 15, "aria-hidden": !0 }), e.isActive("bulletList"), () => e.chain().focus().toggleBulletList().run()),
311
- l(n("richDocument.orderedList"), /* @__PURE__ */ t(Se, { size: 15, "aria-hidden": !0 }), e.isActive("orderedList"), () => e.chain().focus().toggleOrderedList().run()),
312
- l(n("richDocument.taskList"), /* @__PURE__ */ t(Ae, { size: 15, "aria-hidden": !0 }), e.isActive("taskList"), () => e.chain().focus().toggleTaskList().run()),
313
- l(n("richDocument.quote"), /* @__PURE__ */ t(Ne, { size: 15, "aria-hidden": !0 }), e.isActive("blockquote"), () => e.chain().focus().toggleBlockquote().run()),
314
- l(n("richDocument.codeBlock"), /* @__PURE__ */ t(Te, { size: 15, "aria-hidden": !0 }), e.isActive("codeBlock"), () => e.chain().focus().toggleCodeBlock().run()),
315
- l(n("richDocument.rule"), /* @__PURE__ */ t(Nt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().setHorizontalRule().run()),
316
- l(n("richDocument.callout"), /* @__PURE__ */ t(Re, { size: 15, "aria-hidden": !0 }), e.isActive("callout"), () => e.chain().focus().wrapIn("callout").run()),
317
- l(n("richDocument.table"), /* @__PURE__ */ t(ne, { size: 15, "aria-hidden": !0 }), e.isActive("table"), () => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()),
318
- y && l(n("richDocument.image"), /* @__PURE__ */ t(Pe, { size: 15, "aria-hidden": !0 }), !1, () => {
330
+ return /* @__PURE__ */ p("div", { className: C === "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": P || void 0, "data-node-id": R || void 0, "data-base-revision": String(B) || void 0, "data-editable": i || void 0, "data-surface": C, onDragOver: (r) => z && r.preventDefault(), children: [
331
+ i && e && /* @__PURE__ */ p(re, { label: h, density: "compact", variant: C === "document" ? "bare" : "framed", className: C === "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: [
332
+ l(n("richDocument.heading1"), /* @__PURE__ */ t(ye, { size: 15, "aria-hidden": !0 }), e.isActive("heading", { level: 1 }), () => e.chain().focus().toggleHeading({ level: 1 }).run()),
333
+ l(n("richDocument.heading2"), /* @__PURE__ */ t(ze, { size: 15, "aria-hidden": !0 }), e.isActive("heading", { level: 2 }), () => e.chain().focus().toggleHeading({ level: 2 }).run()),
334
+ l(n("richDocument.heading3"), /* @__PURE__ */ t(Ae, { size: 15, "aria-hidden": !0 }), e.isActive("heading", { level: 3 }), () => e.chain().focus().toggleHeading({ level: 3 }).run()),
335
+ /* @__PURE__ */ t(M, {}),
336
+ l(n("richDocument.bold"), /* @__PURE__ */ t(Oe, { size: 15, "aria-hidden": !0 }), e.isActive("bold"), () => e.chain().focus().toggleBold().run()),
337
+ l(n("richDocument.italic"), /* @__PURE__ */ t(Ee, { size: 15, "aria-hidden": !0 }), e.isActive("italic"), () => e.chain().focus().toggleItalic().run()),
338
+ l(n("richDocument.underline"), /* @__PURE__ */ t(He, { size: 15, "aria-hidden": !0 }), e.isActive("underline"), () => e.chain().focus().toggleUnderline().run()),
339
+ l(n("richDocument.strike"), /* @__PURE__ */ t(Ie, { size: 15, "aria-hidden": !0 }), e.isActive("strike"), () => e.chain().focus().toggleStrike().run()),
340
+ l(n("richDocument.code"), /* @__PURE__ */ t(Pe, { size: 15, "aria-hidden": !0 }), e.isActive("code"), () => e.chain().focus().toggleCode().run()),
341
+ l(n("richDocument.link"), /* @__PURE__ */ t(_e, { size: 15, "aria-hidden": !0 }), e.isActive("link"), pe),
342
+ /* @__PURE__ */ t(M, {}),
343
+ l(n("richDocument.bulletList"), /* @__PURE__ */ t(Se, { size: 15, "aria-hidden": !0 }), e.isActive("bulletList"), () => e.chain().focus().toggleBulletList().run()),
344
+ l(n("richDocument.orderedList"), /* @__PURE__ */ t(Ne, { size: 15, "aria-hidden": !0 }), e.isActive("orderedList"), () => e.chain().focus().toggleOrderedList().run()),
345
+ l(n("richDocument.taskList"), /* @__PURE__ */ t(Te, { size: 15, "aria-hidden": !0 }), e.isActive("taskList"), () => e.chain().focus().toggleTaskList().run()),
346
+ l(n("richDocument.quote"), /* @__PURE__ */ t(Re, { size: 15, "aria-hidden": !0 }), e.isActive("blockquote"), () => e.chain().focus().toggleBlockquote().run()),
347
+ l(n("richDocument.codeBlock"), /* @__PURE__ */ t(Le, { size: 15, "aria-hidden": !0 }), e.isActive("codeBlock"), () => e.chain().focus().toggleCodeBlock().run()),
348
+ l(n("richDocument.rule"), /* @__PURE__ */ t(Mt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().setHorizontalRule().run()),
349
+ l(n("richDocument.callout"), /* @__PURE__ */ t(Me, { size: 15, "aria-hidden": !0 }), e.isActive("callout"), () => e.chain().focus().wrapIn("callout").run()),
350
+ l(n("richDocument.table"), /* @__PURE__ */ t(oe, { size: 15, "aria-hidden": !0 }), e.isActive("table"), () => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()),
351
+ z && l(n("richDocument.image"), /* @__PURE__ */ t(qe, { size: 15, "aria-hidden": !0 }), !1, () => {
319
352
  var r;
320
- return (r = Y.current) == null ? void 0 : r.click();
353
+ return (r = Z.current) == null ? void 0 : r.click();
321
354
  })
322
355
  ] }),
323
- y && /* @__PURE__ */ t(De, { ref: Y, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", className: "sr-only", tabIndex: -1, onChange: (r) => {
356
+ z && /* @__PURE__ */ t(we, { ref: Z, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", className: "sr-only", tabIndex: -1, onChange: (r) => {
324
357
  var s;
325
358
  const a = (s = r.target.files) == null ? void 0 : s[0];
326
- a && Z(a), r.currentTarget.value = "";
359
+ a && ee(a), r.currentTarget.value = "";
327
360
  } }),
328
- i && e && /* @__PURE__ */ t(xt, { editor: e, options: { placement: "left-start" }, className: "z-40", children: /* @__PURE__ */ h("div", { className: "relative flex items-start gap-1", children: [
329
- /* @__PURE__ */ t(ce, { label: n("richDocument.insertBlock"), children: /* @__PURE__ */ t(g, { type: "button", "aria-label": n("richDocument.insertBlock"), "aria-expanded": le, onMouseDown: (r) => r.preventDefault(), onClick: () => X((r) => !r), 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__ */ t(zt, { size: 16, "aria-hidden": !0 }) }) }),
330
- f && /* @__PURE__ */ t(ce, { label: n("richDocument.aiContinue"), children: /* @__PURE__ */ t(g, { type: "button", "aria-label": n("richDocument.aiContinue"), onMouseDown: (r) => r.preventDefault(), onClick: () => ee("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__ */ t(Ie, { size: 15, "aria-hidden": !0 }) }) }),
331
- le && /* @__PURE__ */ h(K, { label: n("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: [
332
- pe.map(([r, a, s]) => /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ h(g, { type: "button", onMouseDown: (u) => u.preventDefault(), onClick: () => nt(s), 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: [
361
+ i && e && /* @__PURE__ */ t(At, { editor: e, options: { placement: "left-start" }, className: "z-40", children: /* @__PURE__ */ p("div", { className: "relative flex items-start gap-1", children: [
362
+ /* @__PURE__ */ t(le, { label: n("richDocument.insertBlock"), children: /* @__PURE__ */ t(v, { type: "button", "aria-label": n("richDocument.insertBlock"), "aria-expanded": de, onMouseDown: (r) => r.preventDefault(), onClick: () => G((r) => !r), 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__ */ t(Tt, { size: 16, "aria-hidden": !0 }) }) }),
363
+ g && /* @__PURE__ */ t(le, { label: n("richDocument.aiContinue"), children: /* @__PURE__ */ t(v, { type: "button", "aria-label": n("richDocument.aiContinue"), onMouseDown: (r) => r.preventDefault(), onClick: () => te("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__ */ t(je, { size: 15, "aria-hidden": !0 }) }) }),
364
+ de && /* @__PURE__ */ p(J, { label: n("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: [
365
+ be.map(([r, a, s]) => /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ p(v, { type: "button", onMouseDown: (u) => u.preventDefault(), onClick: () => ct(s), 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: [
333
366
  a,
334
367
  /* @__PURE__ */ t("span", { children: r })
335
368
  ] }) }, r)),
336
- y && /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ h(g, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
369
+ z && /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ p(v, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
337
370
  var r;
338
- X(!1), (r = Y.current) == null || r.click();
371
+ G(!1), (r = Z.current) == null || r.click();
339
372
  }, 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: [
340
- /* @__PURE__ */ t(Pe, { size: 15, "aria-hidden": !0 }),
373
+ /* @__PURE__ */ t(qe, { size: 15, "aria-hidden": !0 }),
341
374
  /* @__PURE__ */ t("span", { children: n("richDocument.image") })
342
375
  ] }) })
343
376
  ] })
344
377
  ] }) }),
345
- i && e && /* @__PURE__ */ t(ke, { editor: e, pluginKey: "richTextSelectionMenu", shouldShow: ({ editor: r, from: a, to: s }) => a !== s && !(r.state.selection instanceof ae), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ h("div", { className: "relative", children: [
346
- /* @__PURE__ */ h(te, { label: n("richDocument.formatSelection"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
347
- fe("block", n("richDocument.paragraphStyle"), /* @__PURE__ */ h(ve, { children: [
348
- /* @__PURE__ */ t(Le, { size: 15, "aria-hidden": !0 }),
349
- /* @__PURE__ */ t(Tt, { size: 11, "aria-hidden": !0 })
378
+ i && e && /* @__PURE__ */ t(xe, { editor: e, pluginKey: "richTextSelectionMenu", shouldShow: ({ editor: r, from: a, to: s }) => a !== s && !(r.state.selection instanceof se), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ p("div", { className: "relative", children: [
379
+ /* @__PURE__ */ p(re, { label: n("richDocument.formatSelection"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
380
+ ge("block", n("richDocument.paragraphStyle"), /* @__PURE__ */ p(De, { children: [
381
+ /* @__PURE__ */ t(Be, { size: 15, "aria-hidden": !0 }),
382
+ /* @__PURE__ */ t(Bt, { size: 11, "aria-hidden": !0 })
350
383
  ] })),
351
- fe("align", n("richDocument.alignment"), /* @__PURE__ */ t($e, { size: 15, "aria-hidden": !0 })),
352
- /* @__PURE__ */ t(L, {}),
353
- l(n("richDocument.bold"), /* @__PURE__ */ t(Be, { size: 15, "aria-hidden": !0 }), e.isActive("bold"), () => e.chain().focus().toggleBold().run()),
354
- l(n("richDocument.italic"), /* @__PURE__ */ t(Me, { size: 15, "aria-hidden": !0 }), e.isActive("italic"), () => e.chain().focus().toggleItalic().run()),
355
- l(n("richDocument.underline"), /* @__PURE__ */ t(Oe, { size: 15, "aria-hidden": !0 }), e.isActive("underline"), () => e.chain().focus().toggleUnderline().run()),
356
- l(n("richDocument.strike"), /* @__PURE__ */ t(Ee, { size: 15, "aria-hidden": !0 }), e.isActive("strike"), () => e.chain().focus().toggleStrike().run()),
357
- l(n("richDocument.code"), /* @__PURE__ */ t(He, { size: 15, "aria-hidden": !0 }), e.isActive("code"), () => e.chain().focus().toggleCode().run()),
358
- /* @__PURE__ */ h(we, { title: n("richDocument.colors"), open: M === "color", onOpenChange: (r) => A(r ? "color" : null), side: "bottom", align: "end", trigger: /* @__PURE__ */ t(W, { title: n("richDocument.colors"), "aria-label": n("richDocument.colors"), "aria-expanded": M === "color", onMouseDown: (r) => r.preventDefault(), children: /* @__PURE__ */ t(qe, { size: 15, "aria-hidden": !0 }) }), children: [
359
- /* @__PURE__ */ t(ie, { label: n("richDocument.textColor"), values: Ut, onChoose: (r) => {
360
- e.chain().focus().setColor(r).run(), A(null);
384
+ ge("align", n("richDocument.alignment"), /* @__PURE__ */ t(Je, { size: 15, "aria-hidden": !0 })),
385
+ /* @__PURE__ */ t(M, {}),
386
+ l(n("richDocument.bold"), /* @__PURE__ */ t(Oe, { size: 15, "aria-hidden": !0 }), e.isActive("bold"), () => e.chain().focus().toggleBold().run()),
387
+ l(n("richDocument.italic"), /* @__PURE__ */ t(Ee, { size: 15, "aria-hidden": !0 }), e.isActive("italic"), () => e.chain().focus().toggleItalic().run()),
388
+ l(n("richDocument.underline"), /* @__PURE__ */ t(He, { size: 15, "aria-hidden": !0 }), e.isActive("underline"), () => e.chain().focus().toggleUnderline().run()),
389
+ l(n("richDocument.strike"), /* @__PURE__ */ t(Ie, { size: 15, "aria-hidden": !0 }), e.isActive("strike"), () => e.chain().focus().toggleStrike().run()),
390
+ l(n("richDocument.code"), /* @__PURE__ */ t(Pe, { size: 15, "aria-hidden": !0 }), e.isActive("code"), () => e.chain().focus().toggleCode().run()),
391
+ /* @__PURE__ */ p(Ce, { title: n("richDocument.colors"), open: O === "color", onOpenChange: (r) => T(r ? "color" : null), side: "bottom", align: "end", trigger: /* @__PURE__ */ t(F, { title: n("richDocument.colors"), "aria-label": n("richDocument.colors"), "aria-expanded": O === "color", onMouseDown: (r) => r.preventDefault(), children: /* @__PURE__ */ t($e, { size: 15, "aria-hidden": !0 }) }), children: [
392
+ /* @__PURE__ */ t(ce, { label: n("richDocument.textColor"), values: tr, onChoose: (r) => {
393
+ e.chain().focus().setColor(r).run(), T(null);
361
394
  } }),
362
- /* @__PURE__ */ t(ie, { label: n("richDocument.backgroundColor"), values: F, onChoose: (r) => {
363
- e.chain().focus().setBackgroundColor(r).run(), A(null);
395
+ /* @__PURE__ */ t(ce, { label: n("richDocument.backgroundColor"), values: K, onChoose: (r) => {
396
+ e.chain().focus().setBackgroundColor(r).run(), T(null);
364
397
  } }),
365
- /* @__PURE__ */ t(g, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
366
- e.chain().focus().unsetColor().unsetBackgroundColor().run(), A(null);
398
+ /* @__PURE__ */ t(v, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
399
+ e.chain().focus().unsetColor().unsetBackgroundColor().run(), T(null);
367
400
  }, className: "mt-2 min-h-9 w-full rounded-control text-caption text-graphite hover:bg-surface-hover hover:text-ink", children: n("richDocument.resetColors") })
368
401
  ] }),
369
- l(n("richDocument.link"), /* @__PURE__ */ t(_e, { size: 15, "aria-hidden": !0 }), e.isActive("link"), me),
370
- f && /* @__PURE__ */ h(ve, { children: [
371
- /* @__PURE__ */ t(L, {}),
372
- l(n("richDocument.aiExplain"), /* @__PURE__ */ t(Ie, { size: 15, "aria-hidden": !0 }), !1, () => ee("explain")),
373
- l(n("richDocument.aiRewrite"), /* @__PURE__ */ t(Rt, { size: 15, "aria-hidden": !0 }), !1, () => ee("rewrite"))
402
+ l(n("richDocument.link"), /* @__PURE__ */ t(_e, { size: 15, "aria-hidden": !0 }), e.isActive("link"), pe),
403
+ g && /* @__PURE__ */ p(De, { children: [
404
+ /* @__PURE__ */ t(M, {}),
405
+ l(n("richDocument.aiExplain"), /* @__PURE__ */ t(je, { size: 15, "aria-hidden": !0 }), !1, () => te("explain")),
406
+ l(n("richDocument.aiRewrite"), /* @__PURE__ */ t(Ot, { size: 15, "aria-hidden": !0 }), !1, () => te("rewrite"))
374
407
  ] })
375
408
  ] }),
376
- M === "block" && /* @__PURE__ */ t(K, { label: n("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: ot.map(([r, a, s]) => /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ h(g, { type: "button", onMouseDown: (u) => u.preventDefault(), onClick: () => {
377
- s(), A(null);
409
+ O === "block" && /* @__PURE__ */ t(J, { label: n("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: st.map(([r, a, s]) => /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ p(v, { type: "button", onMouseDown: (u) => u.preventDefault(), onClick: () => {
410
+ s(), T(null);
378
411
  }, 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: [
379
412
  a,
380
413
  /* @__PURE__ */ t("span", { children: r })
381
414
  ] }) }, r)) }),
382
- M === "align" && /* @__PURE__ */ t(K, { label: n("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", n("richDocument.alignLeft"), /* @__PURE__ */ t($e, { size: 15, "aria-hidden": !0 }, "left")], ["center", n("richDocument.alignCenter"), /* @__PURE__ */ t(St, { size: 15, "aria-hidden": !0 }, "center")], ["right", n("richDocument.alignRight"), /* @__PURE__ */ t(At, { size: 15, "aria-hidden": !0 }, "right")]].map(([r, a, s]) => /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ h(g, { type: "button", onMouseDown: (u) => u.preventDefault(), onClick: () => {
383
- e.chain().focus().setTextAlign(String(r)).run(), A(null);
415
+ O === "align" && /* @__PURE__ */ t(J, { label: n("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", n("richDocument.alignLeft"), /* @__PURE__ */ t(Je, { size: 15, "aria-hidden": !0 }, "left")], ["center", n("richDocument.alignCenter"), /* @__PURE__ */ t(Rt, { size: 15, "aria-hidden": !0 }, "center")], ["right", n("richDocument.alignRight"), /* @__PURE__ */ t(Lt, { size: 15, "aria-hidden": !0 }, "right")]].map(([r, a, s]) => /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ p(v, { type: "button", onMouseDown: (u) => u.preventDefault(), onClick: () => {
416
+ e.chain().focus().setTextAlign(String(r)).run(), T(null);
384
417
  }, 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: [
385
418
  s,
386
419
  /* @__PURE__ */ t("span", { children: a })
387
420
  ] }) }, String(r))) })
388
421
  ] }) }),
389
- i && e && /* @__PURE__ */ t(ke, { editor: e, pluginKey: "richTableMenu", shouldShow: ({ editor: r, from: a, to: s }) => (a === s || r.state.selection instanceof ae) && er(r), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ t("div", { className: "relative", children: /* @__PURE__ */ h(te, { label: n("richDocument.tableActions"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
390
- l(n("richDocument.addRowBefore"), /* @__PURE__ */ t(Lt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addRowBefore().run()),
391
- l(n("richDocument.addRowAfter"), /* @__PURE__ */ t(Bt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addRowAfter().run()),
392
- l(n("richDocument.deleteRow"), /* @__PURE__ */ t(Mt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().deleteRow().run()),
393
- /* @__PURE__ */ t(L, {}),
394
- l(n("richDocument.addColumnBefore"), /* @__PURE__ */ t(Ot, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addColumnBefore().run()),
395
- l(n("richDocument.addColumnAfter"), /* @__PURE__ */ t(Et, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addColumnAfter().run()),
396
- l(n("richDocument.deleteColumn"), /* @__PURE__ */ t(Ht, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().deleteColumn().run()),
397
- /* @__PURE__ */ t(L, {}),
398
- l(n("richDocument.mergeCells"), /* @__PURE__ */ t(_t, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().mergeCells().run()),
399
- l(n("richDocument.splitCell"), /* @__PURE__ */ t(It, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().splitCell().run()),
400
- /* @__PURE__ */ h(we, { title: n("richDocument.cellBackgroundColor"), open: ue, onOpenChange: G, side: "bottom", align: "end", trigger: /* @__PURE__ */ t(W, { title: n("richDocument.cellBackgroundColor"), "aria-label": n("richDocument.cellBackgroundColor"), "aria-expanded": ue, onMouseDown: (r) => r.preventDefault(), children: /* @__PURE__ */ t(qe, { size: 15, "aria-hidden": !0 }) }), children: [
401
- /* @__PURE__ */ t(ie, { label: n("richDocument.cellBackgroundColor"), values: F, onChoose: (r) => {
402
- e.chain().focus().setCellAttribute("backgroundColor", r).run(), G(!1);
422
+ i && e && /* @__PURE__ */ t(xe, { editor: e, pluginKey: "richTableMenu", shouldShow: ({ editor: r, from: a, to: s }) => (a === s || r.state.selection instanceof se) && or(r), options: { placement: "top" }, className: "z-40 shadow-pop", children: /* @__PURE__ */ t("div", { className: "relative", children: /* @__PURE__ */ p(re, { label: n("richDocument.tableActions"), density: "compact", className: "max-w-[calc(100vw-2rem)] overflow-x-auto bg-surface-raised", children: [
423
+ l(n("richDocument.addRowBefore"), /* @__PURE__ */ t(Et, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addRowBefore().run()),
424
+ l(n("richDocument.addRowAfter"), /* @__PURE__ */ t(Ht, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addRowAfter().run()),
425
+ l(n("richDocument.deleteRow"), /* @__PURE__ */ t(It, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().deleteRow().run()),
426
+ /* @__PURE__ */ t(M, {}),
427
+ l(n("richDocument.addColumnBefore"), /* @__PURE__ */ t(Pt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addColumnBefore().run()),
428
+ l(n("richDocument.addColumnAfter"), /* @__PURE__ */ t(_t, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().addColumnAfter().run()),
429
+ l(n("richDocument.deleteColumn"), /* @__PURE__ */ t(jt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().deleteColumn().run()),
430
+ /* @__PURE__ */ t(M, {}),
431
+ l(n("richDocument.mergeCells"), /* @__PURE__ */ t(qt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().mergeCells().run()),
432
+ l(n("richDocument.splitCell"), /* @__PURE__ */ t($t, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().splitCell().run()),
433
+ /* @__PURE__ */ p(Ce, { title: n("richDocument.cellBackgroundColor"), open: he, onOpenChange: Y, side: "bottom", align: "end", trigger: /* @__PURE__ */ t(F, { title: n("richDocument.cellBackgroundColor"), "aria-label": n("richDocument.cellBackgroundColor"), "aria-expanded": he, onMouseDown: (r) => r.preventDefault(), children: /* @__PURE__ */ t($e, { size: 15, "aria-hidden": !0 }) }), children: [
434
+ /* @__PURE__ */ t(ce, { label: n("richDocument.cellBackgroundColor"), values: K, onChoose: (r) => {
435
+ e.chain().focus().setCellAttribute("backgroundColor", r).run(), Y(!1);
403
436
  } }),
404
- /* @__PURE__ */ t(g, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
405
- e.chain().focus().setCellAttribute("backgroundColor", null).run(), G(!1);
437
+ /* @__PURE__ */ t(v, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
438
+ e.chain().focus().setCellAttribute("backgroundColor", null).run(), Y(!1);
406
439
  }, className: "mt-2 min-h-9 w-full rounded-control text-caption text-graphite hover:bg-surface-hover hover:text-ink", children: n("richDocument.resetCellBackground") })
407
440
  ] }),
408
- l(n("richDocument.toggleHeaderRow"), /* @__PURE__ */ t(ne, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().toggleHeaderRow().run()),
409
- l(n("richDocument.deleteTable"), /* @__PURE__ */ t(Pt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().deleteTable().run())
441
+ l(n("richDocument.toggleHeaderRow"), /* @__PURE__ */ t(oe, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().toggleHeaderRow().run()),
442
+ l(n("richDocument.deleteTable"), /* @__PURE__ */ t(Jt, { size: 15, "aria-hidden": !0 }), !1, () => e.chain().focus().deleteTable().run())
410
443
  ] }) }) }),
411
- /* @__PURE__ */ t(wt, { editor: e }),
412
- f && !d.operation && q && /* @__PURE__ */ t("div", { role: "alert", className: "m-4 text-caption text-danger", children: q }),
413
- f && d.operation && /* @__PURE__ */ h("aside", { "data-testid": "document-assistant-operation", "data-run-id": d.runId, "data-status": d.status, "data-document-id": d.operation.documentId, "data-node-id": d.operation.nodeId, "data-base-revision": d.operation.baseRevision, "data-error-code": Ze, className: "m-4 space-y-3 rounded-panel border border-border bg-surface-muted p-4", "aria-live": "polite", children: [
414
- /* @__PURE__ */ h("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
415
- /* @__PURE__ */ t("strong", { className: "font-sohne text-body-sm text-ink", children: n(`richDocument.ai.${d.operation.operation}`) }),
416
- /* @__PURE__ */ t("span", { className: "text-caption text-graphite", children: d.status })
444
+ /* @__PURE__ */ t(zt, { editor: e }),
445
+ g && !m.operation && j && /* @__PURE__ */ t("div", { role: "alert", className: "m-4 text-caption text-danger", children: j }),
446
+ g && m.operation && /* @__PURE__ */ p("aside", { "data-testid": "document-assistant-operation", "data-run-id": m.runId, "data-status": m.status, "data-document-id": m.operation.documentId, "data-node-id": m.operation.nodeId, "data-base-revision": m.operation.baseRevision, "data-error-code": tt, className: "m-4 space-y-3 rounded-panel border border-border bg-surface-muted p-4", "aria-live": "polite", children: [
447
+ /* @__PURE__ */ p("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
448
+ /* @__PURE__ */ t("strong", { className: "font-sohne text-body-sm text-ink", children: n(`richDocument.ai.${m.operation.operation}`) }),
449
+ /* @__PURE__ */ t("span", { className: "text-caption text-graphite", children: m.status })
417
450
  ] }),
418
- d.output && /* @__PURE__ */ t("div", { "data-testid": "document-assistant-output", className: "whitespace-pre-wrap text-body-sm text-ink", children: d.output }),
419
- /* @__PURE__ */ h("div", { className: "flex flex-wrap gap-2", children: [
420
- d.status === "waiting_for_input" && /* @__PURE__ */ t(re, { size: "compact", onClick: () => void f.resolvePending().catch((r) => D(r instanceof Error ? r.message : String(r))), children: n("richDocument.aiResume") }),
421
- d.status === "completed" && d.operation.operation !== "explain" && d.output && !O && /* @__PURE__ */ t(re, { size: "compact", disabled: he, onClick: () => void tt(), children: n("richDocument.aiApply") }),
422
- O && /* @__PURE__ */ t(re, { size: "compact", variant: "secondary", disabled: he, onClick: () => void rt(), children: n("richDocument.aiRollback") })
451
+ m.output && /* @__PURE__ */ t("div", { "data-testid": "document-assistant-output", className: "whitespace-pre-wrap text-body-sm text-ink", children: m.output }),
452
+ /* @__PURE__ */ p("div", { className: "flex flex-wrap gap-2", children: [
453
+ m.status === "waiting_for_input" && /* @__PURE__ */ t(ne, { size: "compact", onClick: () => void g.resolvePending().catch((r) => w(r instanceof Error ? r.message : String(r))), children: n("richDocument.aiResume") }),
454
+ m.status === "completed" && m.operation.operation !== "explain" && m.output && !E && /* @__PURE__ */ t(ne, { size: "compact", disabled: fe, onClick: () => void it(), children: n("richDocument.aiApply") }),
455
+ E && /* @__PURE__ */ t(ne, { size: "compact", variant: "secondary", disabled: fe, onClick: () => void at(), children: n("richDocument.aiRollback") })
423
456
  ] }),
424
- (q || d.error) && /* @__PURE__ */ t("div", { role: "alert", className: "text-caption text-danger", children: q || ((ge = d.error) == null ? void 0 : ge.message) })
457
+ (j || m.error) && /* @__PURE__ */ t("div", { role: "alert", className: "text-caption text-danger", children: j || ((ve = m.error) == null ? void 0 : ve.message) })
425
458
  ] }),
426
- i && Ue && e && /* @__PURE__ */ h(K, { label: n("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: [
427
- /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ t(g, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => J(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).toggleHeading({ level: 2 }).run()), children: n("richDocument.heading") }) }),
428
- /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ t(g, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => J(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).toggleTaskList().run()), children: n("richDocument.taskList") }) }),
429
- /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ t(g, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => J(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).wrapIn("callout").run()), children: n("richDocument.callout") }) }),
430
- /* @__PURE__ */ t(z, { asChild: !0, children: /* @__PURE__ */ t(g, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => J(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()), children: n("richDocument.table") }) })
459
+ i && Ze && e && /* @__PURE__ */ p(J, { label: n("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: [
460
+ /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ t(v, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => $(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).toggleHeading({ level: 2 }).run()), children: n("richDocument.heading") }) }),
461
+ /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ t(v, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => $(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).toggleTaskList().run()), children: n("richDocument.taskList") }) }),
462
+ /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ t(v, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => $(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).wrapIn("callout").run()), children: n("richDocument.callout") }) }),
463
+ /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ t(v, { className: "h-row-default rounded-control px-3 text-left font-sohne text-body-sm text-ink hover:bg-surface-hover", onClick: () => $(() => e.chain().deleteRange({ from: e.state.selection.from - 1, to: e.state.selection.from }).insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run()), children: n("richDocument.table") }) })
431
464
  ] }),
432
- /* @__PURE__ */ t(yt, { open: Ye, onClose: () => P(!1), title: k, closeLabel: n("common.close"), children: /* @__PURE__ */ h("div", { className: "space-y-4", children: [
433
- /* @__PURE__ */ t(De, { autoFocus: !0, type: "url", "aria-label": k, value: de, onChange: (r) => Q(r.target.value), placeholder: "https://" }),
434
- /* @__PURE__ */ t("div", { className: "flex justify-end", children: /* @__PURE__ */ t(g, { type: "button", onClick: et, className: "min-h-11 rounded-full bg-ink px-5 font-sohne text-caption text-pure-white", children: v }) })
465
+ /* @__PURE__ */ t(Nt, { open: et, onClose: () => _(!1), title: k, closeLabel: n("common.close"), children: /* @__PURE__ */ p("div", { className: "space-y-4", children: [
466
+ /* @__PURE__ */ t(we, { autoFocus: !0, type: "url", "aria-label": k, value: me, onChange: (r) => Q(r.target.value), placeholder: "https://" }),
467
+ /* @__PURE__ */ t("div", { className: "flex justify-end", children: /* @__PURE__ */ t(v, { type: "button", onClick: ot, className: "min-h-11 rounded-full bg-ink px-5 font-sohne text-caption text-pure-white", children: D }) })
435
468
  ] }) })
436
469
  ] });
437
470
  }
438
- const nr = (o) => /(^|\n)(#{1,3} |[-*+] |\d+\. |> |```|---(?:\n|$)|- \[[ xX]\] )|\|.+\|\n\|(?:\s*:?-+:?\s*\|)+|\*\*[^*]+\*\*|~~[^~]+~~|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)]+\)/m.test(o);
439
- function ie({ label: o, values: i, onChoose: c }) {
440
- return /* @__PURE__ */ h("fieldset", { className: "mb-2", children: [
471
+ const cr = (o) => /(^|\n)(#{1,3} |[-*+] |\d+\. |> |```|---(?:\n|$)|- \[[ xX]\] )|\|.+\|\n\|(?:\s*:?-+:?\s*\|)+|\*\*[^*]+\*\*|~~[^~]+~~|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^)]+\)/m.test(o);
472
+ function ce({ label: o, values: i, onChoose: c }) {
473
+ return /* @__PURE__ */ p("fieldset", { className: "mb-2", children: [
441
474
  /* @__PURE__ */ t("legend", { className: "mb-1 font-sohne text-caption text-graphite", children: o }),
442
- /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-1", children: i.map((m, k) => {
443
- const v = `${o} ${k + 1}`;
444
- return /* @__PURE__ */ t(ce, { label: v, children: /* @__PURE__ */ t(g, { type: "button", "aria-label": v, onMouseDown: (x) => x.preventDefault(), onClick: () => c(m), className: "size-8 rounded-control border border-border transition-transform hover:-translate-y-px hover:ring-2 hover:ring-rust/35", style: { backgroundColor: m } }) }, m);
475
+ /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-1", children: i.map((h, k) => {
476
+ const D = `${o} ${k + 1}`;
477
+ return /* @__PURE__ */ t(le, { label: D, children: /* @__PURE__ */ t(v, { type: "button", "aria-label": D, onMouseDown: (C) => C.preventDefault(), onClick: () => c(h), className: "size-8 rounded-control border border-border transition-transform hover:-translate-y-px hover:ring-2 hover:ring-rust/35", style: { backgroundColor: h } }) }, h);
445
478
  }) })
446
479
  ] });
447
480
  }
448
481
  export {
449
- _ as RICH_DOCUMENT_SCHEMA,
450
- yr as RichDocument,
451
- yr as RichDocumentEditor,
452
- Xt as applyDocumentAssistantOutput,
453
- Vt as commitDocumentAssistantRollback,
454
- Fe as documentAssistantConflict,
482
+ W as RICH_DOCUMENT_SCHEMA,
483
+ Nr as RichDocument,
484
+ Nr as RichDocumentEditor,
485
+ Ut as applyDocumentAssistantOutput,
486
+ Qt as commitDocumentAssistantRollback,
487
+ Xe as documentAssistantConflict,
488
+ We as durableRichDocumentContent,
455
489
  Ke as emptyRichDocument,
456
- nr as looksLikeMarkdown,
457
- Cr as parseRichDocument,
458
- Wt as replaceAssistantMarkdown,
459
- tr as replaceDocumentContent,
460
- rr as richDocumentExtensions,
461
- Ft as rollbackAssistantRange,
462
- er as selectionInsideTable
490
+ cr as looksLikeMarkdown,
491
+ Sr as parseRichDocument,
492
+ Gt as replaceAssistantMarkdown,
493
+ ir as replaceDocumentContent,
494
+ ar as richDocumentExtensions,
495
+ Yt as rollbackAssistantRange,
496
+ or as selectionInsideTable
463
497
  };