@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/README.md +29 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +323 -289
- package/dist/rich-document.d.ts +7 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,117 +1,128 @@
|
|
|
1
|
-
import { jsx as t, jsxs as
|
|
2
|
-
import { Node as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { TableKit as
|
|
7
|
-
import
|
|
8
|
-
import { TextStyle as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { Markdown as
|
|
12
|
-
import { CellSelection as
|
|
13
|
-
import { Slice as
|
|
14
|
-
import { useEditor as
|
|
15
|
-
import { FloatingMenu as
|
|
16
|
-
import
|
|
17
|
-
import { Toolbar as
|
|
18
|
-
import { Heading1 as
|
|
19
|
-
import { useMemo as
|
|
20
|
-
const
|
|
21
|
-
function
|
|
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
|
|
24
|
+
const Fe = { status: "idle", output: "" }, Xt = () => () => {
|
|
25
25
|
};
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
return o.commands.insertContentAt(i, c, { contentType: "markdown", updateSelection: !0 }), { from: i.from, to: i.from + o.state.doc.content.size -
|
|
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
|
|
30
|
+
function Yt(o, i, c, h) {
|
|
31
31
|
try {
|
|
32
|
-
return o.state.doc.slice(i.from, i.to).content.eq(
|
|
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
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const k = o.state.tr.replaceRange(i.range.from, i.range.to, i.original),
|
|
41
|
-
if (o.state.doc.eq(
|
|
42
|
-
return o.view.dispatch(o.state.tr.replaceRange(i.range.from, i.range.to, i.original)), { value:
|
|
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
|
|
45
|
-
if (!
|
|
44
|
+
function Ut(o, i, c, h) {
|
|
45
|
+
if (!Xe(o, i, c))
|
|
46
46
|
try {
|
|
47
|
-
const k =
|
|
48
|
-
return { range:
|
|
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
|
|
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
|
|
60
|
-
if (!o.state.doc.slice(c.range.from, c.range.to).content.eq(
|
|
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
|
|
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",
|
|
72
|
-
}),
|
|
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
|
-
}),
|
|
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) =>
|
|
80
|
-
renderHTML: ({ backgroundColor: o }) => o &&
|
|
81
|
-
}),
|
|
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:
|
|
84
|
-
} }),
|
|
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:
|
|
87
|
-
} }), Ke = () => ({ schema:
|
|
88
|
-
function
|
|
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 !==
|
|
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
|
|
99
|
-
if (o.state.selection instanceof
|
|
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
|
-
},
|
|
104
|
-
const c = o.state.selection.getBookmark(),
|
|
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
|
-
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
kt,
|
|
141
|
+
Dt,
|
|
142
|
+
wt,
|
|
143
|
+
xt.configure({ nested: !0 }),
|
|
144
|
+
Zt,
|
|
145
|
+
mt.configure({ placeholder: o }),
|
|
146
|
+
Ct
|
|
136
147
|
];
|
|
137
|
-
function
|
|
138
|
-
var
|
|
139
|
-
if (
|
|
140
|
-
const n = (r) =>
|
|
141
|
-
const s =
|
|
142
|
-
if (!s || !
|
|
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
|
|
156
|
+
u = await z(r);
|
|
146
157
|
} catch {
|
|
147
158
|
return;
|
|
148
159
|
}
|
|
149
|
-
const
|
|
150
|
-
a !== void 0 ? s.chain().focus().insertContentAt(a,
|
|
151
|
-
}, e =
|
|
152
|
-
extensions:
|
|
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:
|
|
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
|
|
161
|
-
const s = [...((
|
|
162
|
-
if (s &&
|
|
163
|
-
return
|
|
164
|
-
const u = ((
|
|
165
|
-
return
|
|
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
|
|
169
|
-
const s = [...((
|
|
170
|
-
if (!s || !
|
|
171
|
-
const u = (
|
|
172
|
-
return
|
|
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 =
|
|
178
|
-
return Q(String((s == null ? void 0 : s.getAttributes("link").href) ?? "https://")),
|
|
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
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
}), [e]),
|
|
196
|
+
ae(() => (H.current = e, () => {
|
|
197
|
+
H.current = null;
|
|
198
|
+
}), [e]), ae(() => {
|
|
188
199
|
e == null || e.setEditable(i);
|
|
189
|
-
}, [i, e]),
|
|
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
|
-
|
|
204
|
+
I.current = !0;
|
|
194
205
|
try {
|
|
195
|
-
|
|
206
|
+
ir(e, r);
|
|
196
207
|
} finally {
|
|
197
|
-
|
|
208
|
+
I.current = !1;
|
|
198
209
|
}
|
|
199
210
|
}
|
|
200
|
-
}, [e, o])
|
|
201
|
-
|
|
202
|
-
r
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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 =
|
|
208
|
-
r ? e.chain().focus().extendMarkRange("link").setLink({ href: r }).run() : e.chain().focus().unsetLink().run(),
|
|
209
|
-
},
|
|
210
|
-
if (!e || !
|
|
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
|
-
`),
|
|
213
|
-
e.state.doc.nodesBetween(a, Math.max(a + 1, s), (
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
|
|
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
|
|
219
|
-
|
|
220
|
-
version:
|
|
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:
|
|
223
|
-
nodeId:
|
|
255
|
+
documentId: P,
|
|
256
|
+
nodeId: R,
|
|
224
257
|
baseRevision: String(B),
|
|
225
258
|
range: { from: a, to: s },
|
|
226
259
|
selection: u,
|
|
227
|
-
instruction:
|
|
260
|
+
instruction: b,
|
|
228
261
|
context: `${e.getText({ blockSeparator: `
|
|
229
|
-
` }).slice(-12e3)}${
|
|
262
|
+
` }).slice(-12e3)}${f.length ? `
|
|
230
263
|
|
|
231
|
-
[Selected images: ${
|
|
264
|
+
[Selected images: ${f.map((d) => d.assetId).join(", ")}]` : ""}`,
|
|
232
265
|
originalSlice: e.state.doc.slice(a, s).toJSON(),
|
|
233
|
-
images:
|
|
234
|
-
source:
|
|
235
|
-
}).catch((
|
|
236
|
-
},
|
|
237
|
-
if (!e || !
|
|
238
|
-
const r =
|
|
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
|
-
|
|
273
|
+
L(r), w(n("richDocument.aiConflict"));
|
|
241
274
|
return;
|
|
242
275
|
}
|
|
243
|
-
|
|
276
|
+
I.current = !0;
|
|
244
277
|
let a;
|
|
245
278
|
try {
|
|
246
|
-
a =
|
|
279
|
+
a = Ut(e, { documentId: P, nodeId: R, baseRevision: String(B) }, m.operation, m.output);
|
|
247
280
|
} finally {
|
|
248
|
-
|
|
281
|
+
I.current = !1;
|
|
249
282
|
}
|
|
250
283
|
if (!a) {
|
|
251
|
-
|
|
284
|
+
L("invalid_slice"), w(n("richDocument.aiConflict"));
|
|
252
285
|
return;
|
|
253
286
|
}
|
|
254
|
-
const s =
|
|
255
|
-
|
|
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:
|
|
258
|
-
|
|
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
|
-
|
|
293
|
+
Yt(e, a.range, a.original, a.generated), w(n("richDocument.aiConflict"));
|
|
261
294
|
} finally {
|
|
262
|
-
e.setEditable(i),
|
|
295
|
+
e.setEditable(i), q(!1);
|
|
263
296
|
}
|
|
264
|
-
},
|
|
265
|
-
if (!(!e || !
|
|
266
|
-
|
|
297
|
+
}, at = async () => {
|
|
298
|
+
if (!(!e || !E)) {
|
|
299
|
+
q(!0), e.setEditable(!1);
|
|
267
300
|
try {
|
|
268
|
-
const r = await
|
|
301
|
+
const r = await Qt(e, E, (a) => V({ kind: "rollback", value: a, nodeId: R, expectedRevision: E.revision }));
|
|
269
302
|
if (!r) {
|
|
270
|
-
|
|
303
|
+
L("selection"), w(n("richDocument.aiConflict"));
|
|
271
304
|
return;
|
|
272
305
|
}
|
|
273
|
-
|
|
306
|
+
w(""), L(void 0), U(void 0), y == null || y(r.value, r.revision);
|
|
274
307
|
} catch {
|
|
275
|
-
|
|
308
|
+
w(n("richDocument.aiConflict"));
|
|
276
309
|
} finally {
|
|
277
|
-
e.setEditable(i),
|
|
310
|
+
e.setEditable(i), q(!1);
|
|
278
311
|
}
|
|
279
312
|
}
|
|
280
|
-
}, l = (r, a, s, u) => /* @__PURE__ */ t(
|
|
281
|
-
r(),
|
|
282
|
-
},
|
|
283
|
-
[n("richDocument.heading1"), /* @__PURE__ */ t(
|
|
284
|
-
[n("richDocument.heading2"), /* @__PURE__ */ t(
|
|
285
|
-
[n("richDocument.heading3"), /* @__PURE__ */ t(
|
|
286
|
-
[n("richDocument.bulletList"), /* @__PURE__ */ t(
|
|
287
|
-
[n("richDocument.orderedList"), /* @__PURE__ */ t(
|
|
288
|
-
[n("richDocument.taskList"), /* @__PURE__ */ t(
|
|
289
|
-
[n("richDocument.quote"), /* @__PURE__ */ t(
|
|
290
|
-
[n("richDocument.codeBlock"), /* @__PURE__ */ t(
|
|
291
|
-
[n("richDocument.callout"), /* @__PURE__ */ t(
|
|
292
|
-
[n("richDocument.table"), /* @__PURE__ */ t(
|
|
293
|
-
] : [],
|
|
294
|
-
[n("richDocument.paragraph"), /* @__PURE__ */ t(
|
|
295
|
-
...
|
|
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__ */
|
|
298
|
-
i && e && /* @__PURE__ */
|
|
299
|
-
l(n("richDocument.heading1"), /* @__PURE__ */ t(
|
|
300
|
-
l(n("richDocument.heading2"), /* @__PURE__ */ t(
|
|
301
|
-
l(n("richDocument.heading3"), /* @__PURE__ */ t(
|
|
302
|
-
/* @__PURE__ */ t(
|
|
303
|
-
l(n("richDocument.bold"), /* @__PURE__ */ t(
|
|
304
|
-
l(n("richDocument.italic"), /* @__PURE__ */ t(
|
|
305
|
-
l(n("richDocument.underline"), /* @__PURE__ */ t(
|
|
306
|
-
l(n("richDocument.strike"), /* @__PURE__ */ t(
|
|
307
|
-
l(n("richDocument.code"), /* @__PURE__ */ t(
|
|
308
|
-
l(n("richDocument.link"), /* @__PURE__ */ t(_e, { size: 15, "aria-hidden": !0 }), e.isActive("link"),
|
|
309
|
-
/* @__PURE__ */ t(
|
|
310
|
-
l(n("richDocument.bulletList"), /* @__PURE__ */ t(
|
|
311
|
-
l(n("richDocument.orderedList"), /* @__PURE__ */ t(
|
|
312
|
-
l(n("richDocument.taskList"), /* @__PURE__ */ t(
|
|
313
|
-
l(n("richDocument.quote"), /* @__PURE__ */ t(
|
|
314
|
-
l(n("richDocument.codeBlock"), /* @__PURE__ */ t(
|
|
315
|
-
l(n("richDocument.rule"), /* @__PURE__ */ t(
|
|
316
|
-
l(n("richDocument.callout"), /* @__PURE__ */ t(
|
|
317
|
-
l(n("richDocument.table"), /* @__PURE__ */ t(
|
|
318
|
-
|
|
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 =
|
|
353
|
+
return (r = Z.current) == null ? void 0 : r.click();
|
|
321
354
|
})
|
|
322
355
|
] }),
|
|
323
|
-
|
|
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 &&
|
|
359
|
+
a && ee(a), r.currentTarget.value = "";
|
|
327
360
|
} }),
|
|
328
|
-
i && e && /* @__PURE__ */ t(
|
|
329
|
-
/* @__PURE__ */ t(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
369
|
+
z && /* @__PURE__ */ t(S, { asChild: !0, children: /* @__PURE__ */ p(v, { type: "button", onMouseDown: (r) => r.preventDefault(), onClick: () => {
|
|
337
370
|
var r;
|
|
338
|
-
|
|
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(
|
|
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(
|
|
346
|
-
/* @__PURE__ */
|
|
347
|
-
|
|
348
|
-
/* @__PURE__ */ t(
|
|
349
|
-
/* @__PURE__ */ t(
|
|
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
|
-
|
|
352
|
-
/* @__PURE__ */ t(
|
|
353
|
-
l(n("richDocument.bold"), /* @__PURE__ */ t(
|
|
354
|
-
l(n("richDocument.italic"), /* @__PURE__ */ t(
|
|
355
|
-
l(n("richDocument.underline"), /* @__PURE__ */ t(
|
|
356
|
-
l(n("richDocument.strike"), /* @__PURE__ */ t(
|
|
357
|
-
l(n("richDocument.code"), /* @__PURE__ */ t(
|
|
358
|
-
/* @__PURE__ */
|
|
359
|
-
/* @__PURE__ */ t(
|
|
360
|
-
e.chain().focus().setColor(r).run(),
|
|
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(
|
|
363
|
-
e.chain().focus().setBackgroundColor(r).run(),
|
|
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(
|
|
366
|
-
e.chain().focus().unsetColor().unsetBackgroundColor().run(),
|
|
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"),
|
|
370
|
-
|
|
371
|
-
/* @__PURE__ */ t(
|
|
372
|
-
l(n("richDocument.aiExplain"), /* @__PURE__ */ t(
|
|
373
|
-
l(n("richDocument.aiRewrite"), /* @__PURE__ */ t(
|
|
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
|
-
|
|
377
|
-
s(),
|
|
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
|
-
|
|
383
|
-
e.chain().focus().setTextAlign(String(r)).run(),
|
|
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(
|
|
390
|
-
l(n("richDocument.addRowBefore"), /* @__PURE__ */ t(
|
|
391
|
-
l(n("richDocument.addRowAfter"), /* @__PURE__ */ t(
|
|
392
|
-
l(n("richDocument.deleteRow"), /* @__PURE__ */ t(
|
|
393
|
-
/* @__PURE__ */ t(
|
|
394
|
-
l(n("richDocument.addColumnBefore"), /* @__PURE__ */ t(
|
|
395
|
-
l(n("richDocument.addColumnAfter"), /* @__PURE__ */ t(
|
|
396
|
-
l(n("richDocument.deleteColumn"), /* @__PURE__ */ t(
|
|
397
|
-
/* @__PURE__ */ t(
|
|
398
|
-
l(n("richDocument.mergeCells"), /* @__PURE__ */ t(
|
|
399
|
-
l(n("richDocument.splitCell"), /* @__PURE__ */ t(
|
|
400
|
-
/* @__PURE__ */
|
|
401
|
-
/* @__PURE__ */ t(
|
|
402
|
-
e.chain().focus().setCellAttribute("backgroundColor", r).run(),
|
|
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(
|
|
405
|
-
e.chain().focus().setCellAttribute("backgroundColor", null).run(),
|
|
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(
|
|
409
|
-
l(n("richDocument.deleteTable"), /* @__PURE__ */ t(
|
|
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(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
/* @__PURE__ */
|
|
415
|
-
/* @__PURE__ */ t("strong", { className: "font-sohne text-body-sm text-ink", children: n(`richDocument.ai.${
|
|
416
|
-
/* @__PURE__ */ t("span", { className: "text-caption text-graphite", children:
|
|
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
|
-
|
|
419
|
-
/* @__PURE__ */
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
(
|
|
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 &&
|
|
427
|
-
/* @__PURE__ */ t(
|
|
428
|
-
/* @__PURE__ */ t(
|
|
429
|
-
/* @__PURE__ */ t(
|
|
430
|
-
/* @__PURE__ */ t(
|
|
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(
|
|
433
|
-
/* @__PURE__ */ t(
|
|
434
|
-
/* @__PURE__ */ t("div", { className: "flex justify-end", children: /* @__PURE__ */ t(
|
|
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
|
|
439
|
-
function
|
|
440
|
-
return /* @__PURE__ */
|
|
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((
|
|
443
|
-
const
|
|
444
|
-
return /* @__PURE__ */ t(
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
};
|