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