@norio-office/rich-text 0.7.0 → 0.8.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 +895 -816
- package/dist/ai/bridge.d.ts +335 -0
- package/dist/ai/consume-stream.d.ts +8 -0
- package/dist/ai/executor.d.ts +19 -0
- package/dist/ai/index.d.ts +8 -0
- package/dist/ai/index.js +4106 -0
- package/dist/ai/tools.d.ts +158 -0
- package/dist/ai-protocol/index.d.ts +12 -0
- package/dist/ai-protocol/index.js +2372 -0
- package/dist/ai-protocol/json-schema.d.ts +5 -0
- package/dist/ai-protocol/patch.d.ts +77 -0
- package/dist/ai-protocol/references.d.ts +11 -0
- package/dist/ai-protocol/stream.d.ts +94 -0
- package/dist/ai-protocol/tools.d.ts +8 -0
- package/dist/ai-protocol/validation.d.ts +20 -0
- package/dist/components/RichTextEditor.vue.d.ts +11 -8
- package/dist/components/TextSelectionMenu.vue.d.ts +29 -1
- package/dist/document/ai-identity.d.ts +4 -0
- package/dist/document/nodes/columns-block.d.ts +2 -0
- package/dist/document/nodes/countdown-block.d.ts +2 -0
- package/dist/document/nodes/formula-block.d.ts +2 -0
- package/dist/document/nodes/highlight-block.d.ts +2 -0
- package/dist/document/nodes/image-block.d.ts +8 -0
- package/dist/document/nodes/link-block.d.ts +2 -0
- package/dist/document/nodes/local-file-block.d.ts +2 -0
- package/dist/document/nodes/mention.d.ts +2 -0
- package/dist/document/nodes/office-code-block.d.ts +1 -0
- package/dist/document/nodes/table-cells.d.ts +2 -0
- package/dist/document/nodes/themed-table.d.ts +1 -0
- package/dist/document/nodes/video-block.d.ts +8 -0
- package/dist/document/schema.d.ts +17 -0
- package/dist/extensions/ai-identity.d.ts +1 -0
- package/dist/extensions/columns-block.d.ts +1 -2
- package/dist/extensions/countdown-block.d.ts +1 -2
- package/dist/extensions/formula-block.d.ts +1 -2
- package/dist/extensions/highlight-block.d.ts +1 -2
- package/dist/extensions/image-block.d.ts +4 -8
- package/dist/extensions/link-block.d.ts +1 -2
- package/dist/extensions/local-file-block.d.ts +1 -2
- package/dist/extensions/mention.d.ts +1 -2
- package/dist/extensions/video-block.d.ts +4 -8
- package/dist/{html2canvas-4hiP1s1t.js → html2canvas-BnDzIoab.js} +112 -126
- package/dist/index.js +8272 -7604
- package/dist/index.umd.cjs +2189 -1990
- package/dist/nordox/index.d.ts +95 -0
- package/dist/nordox/index.js +2094 -0
- package/dist/{chunk-C_CI6nMA.js → rolldown-runtime-VHNaYcLd.js} +3 -3
- package/dist/style.css +1 -1
- package/dist/types.d.ts +9 -1
- package/docs/ai/README.md +108 -0
- package/docs/ai/acceptance-report.md +88 -0
- package/docs/ai/capability-matrix.md +43 -0
- package/docs/ai/compatibility.md +9 -0
- package/docs/icons.md +21 -0
- package/examples/ai/browser/App.vue +151 -0
- package/examples/ai/browser/index.html +12 -0
- package/examples/ai/browser/main.ts +5 -0
- package/examples/ai/browser/tsconfig.json +7 -0
- package/examples/ai/browser/vite.config.ts +14 -0
- package/examples/ai/node.mjs +28 -0
- package/package.json +15 -1
|
@@ -0,0 +1,2372 @@
|
|
|
1
|
+
import { Extension as e, Mark as t, Node as n, getSchema as r, mergeAttributes as i } from "@tiptap/core";
|
|
2
|
+
import a from "@tiptap/extension-text-style/background-color";
|
|
3
|
+
import o from "@tiptap/extension-text-style/color";
|
|
4
|
+
import s from "@tiptap/extension-text-style/font-size";
|
|
5
|
+
import c from "@tiptap/extension-font-family";
|
|
6
|
+
import l from "@tiptap/extension-subscript";
|
|
7
|
+
import u from "@tiptap/extension-superscript";
|
|
8
|
+
import d from "@tiptap/extension-table-row";
|
|
9
|
+
import f from "@tiptap/extension-task-item";
|
|
10
|
+
import p from "@tiptap/extension-task-list";
|
|
11
|
+
import { TextStyle as m } from "@tiptap/extension-text-style/text-style";
|
|
12
|
+
import h from "@tiptap/extension-underline";
|
|
13
|
+
import ee from "@tiptap/starter-kit";
|
|
14
|
+
import te from "@tiptap/extension-code-block-lowlight";
|
|
15
|
+
import { common as ne, createLowlight as re } from "lowlight";
|
|
16
|
+
import ie from "@tiptap/extension-table-cell";
|
|
17
|
+
import ae from "@tiptap/extension-table-header";
|
|
18
|
+
import { Table as oe } from "@tiptap/extension-table";
|
|
19
|
+
import { TextSelection as g } from "@tiptap/pm/state";
|
|
20
|
+
import se from "@tiptap/extension-horizontal-rule";
|
|
21
|
+
//#region src/document/ai-identity.ts
|
|
22
|
+
var _ = [
|
|
23
|
+
"paragraph",
|
|
24
|
+
"heading",
|
|
25
|
+
"blockquote",
|
|
26
|
+
"bulletList",
|
|
27
|
+
"orderedList",
|
|
28
|
+
"listItem",
|
|
29
|
+
"taskList",
|
|
30
|
+
"taskItem",
|
|
31
|
+
"codeBlock",
|
|
32
|
+
"horizontalRule",
|
|
33
|
+
"table",
|
|
34
|
+
"tableRow",
|
|
35
|
+
"tableCell",
|
|
36
|
+
"tableHeader",
|
|
37
|
+
"columnsBlock",
|
|
38
|
+
"columnsColumn",
|
|
39
|
+
"highlightBlock",
|
|
40
|
+
"imageBlock",
|
|
41
|
+
"videoBlock",
|
|
42
|
+
"localFileBlock",
|
|
43
|
+
"linkBlock",
|
|
44
|
+
"formulaBlock",
|
|
45
|
+
"countdownBlock"
|
|
46
|
+
], ce = e.create({
|
|
47
|
+
name: "aiIdentity",
|
|
48
|
+
addGlobalAttributes() {
|
|
49
|
+
return [{
|
|
50
|
+
types: [..._],
|
|
51
|
+
attributes: { aiId: {
|
|
52
|
+
default: null,
|
|
53
|
+
parseHTML: (e) => e.getAttribute("data-ai-id"),
|
|
54
|
+
renderHTML: (e) => e.aiId ? { "data-ai-id": e.aiId } : {}
|
|
55
|
+
} }
|
|
56
|
+
}];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
function le(e) {
|
|
60
|
+
let t = JSON.parse(JSON.stringify(e)), n = /* @__PURE__ */ new Set(), r = new Set(_);
|
|
61
|
+
function i(e) {
|
|
62
|
+
if (e.type && r.has(e.type)) {
|
|
63
|
+
let t = e.attrs?.aiId;
|
|
64
|
+
(typeof t != "string" || !t || n.has(t)) && (e.attrs = {
|
|
65
|
+
...e.attrs,
|
|
66
|
+
aiId: crypto.randomUUID()
|
|
67
|
+
}), n.add(e.attrs?.aiId);
|
|
68
|
+
}
|
|
69
|
+
e.content?.forEach(i);
|
|
70
|
+
}
|
|
71
|
+
return i(t), t;
|
|
72
|
+
}
|
|
73
|
+
function v(e) {
|
|
74
|
+
return Math.round(e * 1e3) / 1e3;
|
|
75
|
+
}
|
|
76
|
+
function y(e) {
|
|
77
|
+
if (e <= 0) return [];
|
|
78
|
+
let t = 100 / e, n = Array.from({ length: e }, () => v(t)), r = n.reduce((e, t) => e + t, 0);
|
|
79
|
+
return n[e - 1] = v(n[e - 1] + (100 - r)), n;
|
|
80
|
+
}
|
|
81
|
+
function ue(e, t) {
|
|
82
|
+
if (t <= 0) return [];
|
|
83
|
+
if (!Array.isArray(e) || e.length !== t) return y(t);
|
|
84
|
+
let n = e.map((e) => Number(e)).filter((e) => Number.isFinite(e) && e > 0);
|
|
85
|
+
if (n.length !== t) return y(t);
|
|
86
|
+
let r = n.reduce((e, t) => e + t, 0);
|
|
87
|
+
if (r <= 0) return y(t);
|
|
88
|
+
let i = n.map((e) => e / r * 100);
|
|
89
|
+
if (10 * t > 100) return y(t);
|
|
90
|
+
let a = i.map((e) => e).map((e) => e < 10 ? 10 : e), o = a.reduce((e, t) => e + t, 0) - 100;
|
|
91
|
+
for (; o > .001;) {
|
|
92
|
+
let e = a.map((e, t) => ({
|
|
93
|
+
width: e,
|
|
94
|
+
index: t
|
|
95
|
+
})).filter(({ width: e }) => e > 10.001);
|
|
96
|
+
if (!e.length) return y(t);
|
|
97
|
+
let n = o / e.length, r = 0;
|
|
98
|
+
if (e.forEach(({ index: e }) => {
|
|
99
|
+
let t = a[e] - 10, i = Math.min(t, n);
|
|
100
|
+
a[e] -= i, r += i;
|
|
101
|
+
}), r <= .001) return y(t);
|
|
102
|
+
o -= r;
|
|
103
|
+
}
|
|
104
|
+
return a = a.map((e) => v(e)), r = a.reduce((e, t) => e + t, 0), a[t - 1] = v(a[t - 1] + (100 - r)), a;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/document/nodes/columns-block.ts
|
|
108
|
+
var de = n.create({
|
|
109
|
+
name: "columnsBlock",
|
|
110
|
+
group: "block",
|
|
111
|
+
content: "columnsColumn+",
|
|
112
|
+
defining: !0,
|
|
113
|
+
isolating: !0,
|
|
114
|
+
addAttributes() {
|
|
115
|
+
return { widths: {
|
|
116
|
+
default: y(2),
|
|
117
|
+
parseHTML: (e) => {
|
|
118
|
+
let t = e.getAttribute("data-widths");
|
|
119
|
+
if (!t) return y(e.childElementCount || 2);
|
|
120
|
+
try {
|
|
121
|
+
return ue(JSON.parse(decodeURIComponent(t)), e.childElementCount || 2);
|
|
122
|
+
} catch {
|
|
123
|
+
return y(e.childElementCount || 2);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
renderHTML: (e) => ({ "data-widths": encodeURIComponent(JSON.stringify(e.widths ?? y(2))) })
|
|
127
|
+
} };
|
|
128
|
+
},
|
|
129
|
+
parseHTML() {
|
|
130
|
+
return [{ tag: "div[data-type=\"columns-block\"]" }];
|
|
131
|
+
},
|
|
132
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
133
|
+
return [
|
|
134
|
+
"div",
|
|
135
|
+
i(e, { "data-type": "columns-block" }),
|
|
136
|
+
0
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
}), fe = n.create({
|
|
140
|
+
name: "countdownBlock",
|
|
141
|
+
group: "block",
|
|
142
|
+
atom: !0,
|
|
143
|
+
selectable: !0,
|
|
144
|
+
draggable: !0,
|
|
145
|
+
addAttributes() {
|
|
146
|
+
return {
|
|
147
|
+
targetTimestamp: {
|
|
148
|
+
default: 0,
|
|
149
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-target-timestamp") ?? "0", 10) || 0,
|
|
150
|
+
renderHTML: (e) => ({ "data-target-timestamp": String(e.targetTimestamp ?? 0) })
|
|
151
|
+
},
|
|
152
|
+
mode: {
|
|
153
|
+
default: "duration",
|
|
154
|
+
parseHTML: (e) => e.getAttribute("data-mode") || "duration",
|
|
155
|
+
renderHTML: (e) => ({ "data-mode": String(e.mode ?? "duration") })
|
|
156
|
+
},
|
|
157
|
+
color: {
|
|
158
|
+
default: "#ff8b00",
|
|
159
|
+
parseHTML: (e) => e.getAttribute("data-color") || "#ff8b00",
|
|
160
|
+
renderHTML: (e) => ({ "data-color": String(e.color ?? "#ff8b00") })
|
|
161
|
+
},
|
|
162
|
+
reminderEnabled: {
|
|
163
|
+
default: !0,
|
|
164
|
+
parseHTML: (e) => e.getAttribute("data-reminder-enabled") !== "false",
|
|
165
|
+
renderHTML: (e) => ({ "data-reminder-enabled": e.reminderEnabled === !1 ? "false" : "true" })
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
parseHTML() {
|
|
170
|
+
return [{ tag: "div[data-type=\"countdown-block\"]" }];
|
|
171
|
+
},
|
|
172
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
173
|
+
return ["div", {
|
|
174
|
+
...e,
|
|
175
|
+
"data-type": "countdown-block"
|
|
176
|
+
}];
|
|
177
|
+
}
|
|
178
|
+
}), pe = n.create({
|
|
179
|
+
name: "formulaBlock",
|
|
180
|
+
group: "block",
|
|
181
|
+
atom: !0,
|
|
182
|
+
selectable: !0,
|
|
183
|
+
draggable: !0,
|
|
184
|
+
addAttributes() {
|
|
185
|
+
return { latex: {
|
|
186
|
+
default: "",
|
|
187
|
+
parseHTML: (e) => e.getAttribute("data-latex") || "",
|
|
188
|
+
renderHTML: (e) => ({ "data-latex": String(e.latex ?? "") })
|
|
189
|
+
} };
|
|
190
|
+
},
|
|
191
|
+
parseHTML() {
|
|
192
|
+
return [{ tag: "div[data-type=\"formula-block\"]" }];
|
|
193
|
+
},
|
|
194
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
195
|
+
return ["div", {
|
|
196
|
+
...e,
|
|
197
|
+
"data-type": "formula-block"
|
|
198
|
+
}];
|
|
199
|
+
}
|
|
200
|
+
}), b = "高亮块", x = "✍️", S = "#f3c389", C = "#fff8ef", me = n.create({
|
|
201
|
+
name: "highlightBlock",
|
|
202
|
+
group: "block",
|
|
203
|
+
content: "block+",
|
|
204
|
+
defining: !0,
|
|
205
|
+
isolating: !0,
|
|
206
|
+
addAttributes() {
|
|
207
|
+
return {
|
|
208
|
+
titleEnabled: {
|
|
209
|
+
default: !0,
|
|
210
|
+
parseHTML: (e) => e.getAttribute("data-title-enabled") !== "false",
|
|
211
|
+
renderHTML: (e) => ({ "data-title-enabled": e.titleEnabled ? "true" : "false" })
|
|
212
|
+
},
|
|
213
|
+
emojiEnabled: {
|
|
214
|
+
default: !0,
|
|
215
|
+
parseHTML: (e) => e.getAttribute("data-emoji-enabled") !== "false",
|
|
216
|
+
renderHTML: (e) => ({ "data-emoji-enabled": e.emojiEnabled ? "true" : "false" })
|
|
217
|
+
},
|
|
218
|
+
title: {
|
|
219
|
+
default: b,
|
|
220
|
+
parseHTML: (e) => e.getAttribute("data-title") || b,
|
|
221
|
+
renderHTML: (e) => ({ "data-title": e.title || b })
|
|
222
|
+
},
|
|
223
|
+
emoji: {
|
|
224
|
+
default: x,
|
|
225
|
+
parseHTML: (e) => e.getAttribute("data-emoji") || x,
|
|
226
|
+
renderHTML: (e) => ({ "data-emoji": e.emoji || x })
|
|
227
|
+
},
|
|
228
|
+
borderColor: {
|
|
229
|
+
default: S,
|
|
230
|
+
parseHTML: (e) => e.getAttribute("data-border-color") || S,
|
|
231
|
+
renderHTML: (e) => ({ "data-border-color": e.borderColor || S })
|
|
232
|
+
},
|
|
233
|
+
backgroundColor: {
|
|
234
|
+
default: C,
|
|
235
|
+
parseHTML: (e) => e.getAttribute("data-background-color") || C,
|
|
236
|
+
renderHTML: (e) => ({ "data-background-color": e.backgroundColor || C })
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
},
|
|
240
|
+
parseHTML() {
|
|
241
|
+
return [{ tag: "div[data-type=\"highlight-block\"]" }];
|
|
242
|
+
},
|
|
243
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
244
|
+
return [
|
|
245
|
+
"div",
|
|
246
|
+
i(e, { "data-type": "highlight-block" }),
|
|
247
|
+
0
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
}), he = n.create({
|
|
251
|
+
name: "imageBlock",
|
|
252
|
+
group: "block",
|
|
253
|
+
atom: !0,
|
|
254
|
+
selectable: !0,
|
|
255
|
+
draggable: !0,
|
|
256
|
+
addOptions() {
|
|
257
|
+
return {
|
|
258
|
+
uploadImage: null,
|
|
259
|
+
onUploadError: null
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
addAttributes() {
|
|
263
|
+
return {
|
|
264
|
+
images: {
|
|
265
|
+
default: [],
|
|
266
|
+
parseHTML: (e) => {
|
|
267
|
+
let t = e.getAttribute("data-images");
|
|
268
|
+
if (!t) return [];
|
|
269
|
+
try {
|
|
270
|
+
return JSON.parse(decodeURIComponent(t));
|
|
271
|
+
} catch {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
renderHTML: (e) => ({ "data-images": encodeURIComponent(JSON.stringify(e.images ?? [])) })
|
|
276
|
+
},
|
|
277
|
+
widthPercent: {
|
|
278
|
+
default: 100,
|
|
279
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-width-percent") ?? "100", 10) || 100,
|
|
280
|
+
renderHTML: (e) => ({ "data-width-percent": String(e.widthPercent ?? 100) })
|
|
281
|
+
},
|
|
282
|
+
align: {
|
|
283
|
+
default: "left",
|
|
284
|
+
parseHTML: (e) => e.getAttribute("data-align") || "left",
|
|
285
|
+
renderHTML: (e) => ({ "data-align": String(e.align ?? "left") })
|
|
286
|
+
},
|
|
287
|
+
height: {
|
|
288
|
+
default: 146,
|
|
289
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-height") ?? "146", 10) || 146,
|
|
290
|
+
renderHTML: (e) => ({ "data-height": String(e.height ?? 146) })
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
parseHTML() {
|
|
295
|
+
return [{ tag: "div[data-type=\"image-block\"]" }];
|
|
296
|
+
},
|
|
297
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
298
|
+
return ["div", {
|
|
299
|
+
...e,
|
|
300
|
+
"data-type": "image-block"
|
|
301
|
+
}];
|
|
302
|
+
}
|
|
303
|
+
}), ge = n.create({
|
|
304
|
+
name: "linkBlock",
|
|
305
|
+
group: "block",
|
|
306
|
+
atom: !0,
|
|
307
|
+
selectable: !0,
|
|
308
|
+
draggable: !0,
|
|
309
|
+
addAttributes() {
|
|
310
|
+
return {
|
|
311
|
+
title: {
|
|
312
|
+
default: "",
|
|
313
|
+
parseHTML: (e) => e.getAttribute("data-title") || "",
|
|
314
|
+
renderHTML: (e) => ({ "data-title": String(e.title ?? "") })
|
|
315
|
+
},
|
|
316
|
+
url: {
|
|
317
|
+
default: "",
|
|
318
|
+
parseHTML: (e) => e.getAttribute("data-url") || "",
|
|
319
|
+
renderHTML: (e) => ({ "data-url": String(e.url ?? "") })
|
|
320
|
+
},
|
|
321
|
+
displayMode: {
|
|
322
|
+
default: "preview",
|
|
323
|
+
parseHTML: (e) => e.getAttribute("data-display-mode") || "preview",
|
|
324
|
+
renderHTML: (e) => ({ "data-display-mode": String(e.displayMode ?? "preview") })
|
|
325
|
+
},
|
|
326
|
+
align: {
|
|
327
|
+
default: "left",
|
|
328
|
+
parseHTML: (e) => e.getAttribute("data-align") || "left",
|
|
329
|
+
renderHTML: (e) => ({ "data-align": String(e.align ?? "left") })
|
|
330
|
+
},
|
|
331
|
+
widthPercent: {
|
|
332
|
+
default: 100,
|
|
333
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-width-percent") ?? "100", 10) || 100,
|
|
334
|
+
renderHTML: (e) => ({ "data-width-percent": String(e.widthPercent ?? 100) })
|
|
335
|
+
},
|
|
336
|
+
height: {
|
|
337
|
+
default: 420,
|
|
338
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-height") ?? "420", 10) || 420,
|
|
339
|
+
renderHTML: (e) => ({ "data-height": String(e.height ?? 420) })
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
parseHTML() {
|
|
344
|
+
return [{ tag: "div[data-type=\"link-block\"]" }];
|
|
345
|
+
},
|
|
346
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
347
|
+
return ["div", {
|
|
348
|
+
...e,
|
|
349
|
+
"data-type": "link-block"
|
|
350
|
+
}];
|
|
351
|
+
}
|
|
352
|
+
}), _e = n.create({
|
|
353
|
+
name: "localFileBlock",
|
|
354
|
+
group: "block",
|
|
355
|
+
atom: !0,
|
|
356
|
+
selectable: !0,
|
|
357
|
+
draggable: !0,
|
|
358
|
+
addOptions() {
|
|
359
|
+
return {
|
|
360
|
+
onClick: null,
|
|
361
|
+
onDownload: null
|
|
362
|
+
};
|
|
363
|
+
},
|
|
364
|
+
addAttributes() {
|
|
365
|
+
return {
|
|
366
|
+
assetId: {
|
|
367
|
+
default: "",
|
|
368
|
+
parseHTML: (e) => e.getAttribute("data-asset-id") || "",
|
|
369
|
+
renderHTML: (e) => ({ "data-asset-id": String(e.assetId ?? "") })
|
|
370
|
+
},
|
|
371
|
+
url: {
|
|
372
|
+
default: "",
|
|
373
|
+
parseHTML: (e) => e.getAttribute("data-url") || "",
|
|
374
|
+
renderHTML: (e) => ({ "data-url": String(e.url ?? "") })
|
|
375
|
+
},
|
|
376
|
+
name: {
|
|
377
|
+
default: "",
|
|
378
|
+
parseHTML: (e) => e.getAttribute("data-name") || "",
|
|
379
|
+
renderHTML: (e) => ({ "data-name": String(e.name ?? "") })
|
|
380
|
+
},
|
|
381
|
+
size: {
|
|
382
|
+
default: 0,
|
|
383
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-size") ?? "0", 10) || 0,
|
|
384
|
+
renderHTML: (e) => ({ "data-size": String(e.size ?? 0) })
|
|
385
|
+
},
|
|
386
|
+
mimeType: {
|
|
387
|
+
default: "",
|
|
388
|
+
parseHTML: (e) => e.getAttribute("data-mime-type") || "",
|
|
389
|
+
renderHTML: (e) => ({ "data-mime-type": String(e.mimeType ?? "") })
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
},
|
|
393
|
+
parseHTML() {
|
|
394
|
+
return [{ tag: "div[data-type=\"local-file-block\"]" }];
|
|
395
|
+
},
|
|
396
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
397
|
+
return ["div", {
|
|
398
|
+
...e,
|
|
399
|
+
"data-type": "local-file-block"
|
|
400
|
+
}];
|
|
401
|
+
}
|
|
402
|
+
}), ve = n.create({
|
|
403
|
+
name: "mention",
|
|
404
|
+
group: "inline",
|
|
405
|
+
inline: !0,
|
|
406
|
+
atom: !0,
|
|
407
|
+
selectable: !0,
|
|
408
|
+
addOptions() {
|
|
409
|
+
return { onClick: null };
|
|
410
|
+
},
|
|
411
|
+
addAttributes() {
|
|
412
|
+
return {
|
|
413
|
+
id: {
|
|
414
|
+
default: "",
|
|
415
|
+
parseHTML: (e) => e.getAttribute("data-mention-id") || "",
|
|
416
|
+
renderHTML: (e) => ({ "data-mention-id": String(e.id ?? "") })
|
|
417
|
+
},
|
|
418
|
+
name: {
|
|
419
|
+
default: "",
|
|
420
|
+
parseHTML: (e) => e.getAttribute("data-mention-name") || "",
|
|
421
|
+
renderHTML: (e) => ({ "data-mention-name": String(e.name ?? "") })
|
|
422
|
+
},
|
|
423
|
+
type: {
|
|
424
|
+
default: 1,
|
|
425
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-mention-type") ?? "1", 10) === 2 ? 2 : 1,
|
|
426
|
+
renderHTML: (e) => ({ "data-mention-type": String(Number(e.type ?? 1) === 2 ? 2 : 1) })
|
|
427
|
+
},
|
|
428
|
+
avatar: {
|
|
429
|
+
default: "",
|
|
430
|
+
parseHTML: (e) => e.getAttribute("data-mention-avatar") || "",
|
|
431
|
+
renderHTML: (e) => ({ "data-mention-avatar": String(e.avatar ?? "") })
|
|
432
|
+
},
|
|
433
|
+
icon: {
|
|
434
|
+
default: "",
|
|
435
|
+
parseHTML: (e) => e.getAttribute("data-mention-icon") || "",
|
|
436
|
+
renderHTML: (e) => ({ "data-mention-icon": String(e.icon ?? "") })
|
|
437
|
+
},
|
|
438
|
+
tag: {
|
|
439
|
+
default: "",
|
|
440
|
+
parseHTML: (e) => e.getAttribute("data-mention-tag") || "",
|
|
441
|
+
renderHTML: (e) => ({ "data-mention-tag": String(e.tag ?? "") })
|
|
442
|
+
},
|
|
443
|
+
updatedAt: {
|
|
444
|
+
default: "",
|
|
445
|
+
parseHTML: (e) => e.getAttribute("data-mention-updated-at") || "",
|
|
446
|
+
renderHTML: (e) => ({ "data-mention-updated-at": String(e.updatedAt ?? "") })
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
},
|
|
450
|
+
parseHTML() {
|
|
451
|
+
return [{ tag: "span[data-type=\"mention\"]" }];
|
|
452
|
+
},
|
|
453
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
454
|
+
let t = String(e["data-mention-name"] ?? e.name ?? "");
|
|
455
|
+
return [
|
|
456
|
+
"span",
|
|
457
|
+
{
|
|
458
|
+
...e,
|
|
459
|
+
"data-type": "mention",
|
|
460
|
+
class: "norio-office-rich-mention-inline"
|
|
461
|
+
},
|
|
462
|
+
`@${t}`
|
|
463
|
+
];
|
|
464
|
+
},
|
|
465
|
+
renderText({ node: e }) {
|
|
466
|
+
return `@${String(e.attrs.name ?? "")}`;
|
|
467
|
+
}
|
|
468
|
+
}), ye = re(ne), be = te.configure({ lowlight: ye }).extend({ addAttributes() {
|
|
469
|
+
return {
|
|
470
|
+
...this.parent?.(),
|
|
471
|
+
language: {
|
|
472
|
+
default: "plain_text",
|
|
473
|
+
parseHTML: (e) => e.getAttribute("data-language") || "plain_text",
|
|
474
|
+
renderHTML: (e) => {
|
|
475
|
+
let t = e.language || "plain_text";
|
|
476
|
+
return t === "plain_text" ? { "data-language": t } : {
|
|
477
|
+
"data-language": t,
|
|
478
|
+
class: `language-${t}`
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
wrapLines: {
|
|
483
|
+
default: !1,
|
|
484
|
+
parseHTML: (e) => e.getAttribute("data-wrap-lines") === "true",
|
|
485
|
+
renderHTML: (e) => ({ "data-wrap-lines": e.wrapLines ? "true" : "false" })
|
|
486
|
+
},
|
|
487
|
+
darkTheme: {
|
|
488
|
+
default: !1,
|
|
489
|
+
parseHTML: (e) => e.getAttribute("data-dark-theme") === "true",
|
|
490
|
+
renderHTML: (e) => ({ "data-dark-theme": e.darkTheme ? "true" : "false" })
|
|
491
|
+
},
|
|
492
|
+
fixedHeight: {
|
|
493
|
+
default: !1,
|
|
494
|
+
parseHTML: (e) => e.getAttribute("data-fixed-height") === "true",
|
|
495
|
+
renderHTML: (e) => ({ "data-fixed-height": e.fixedHeight ? "true" : "false" })
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
} }), xe = {
|
|
499
|
+
default: null,
|
|
500
|
+
parseHTML: (e) => e.getAttribute("data-cell-background") || e.style.backgroundColor || null,
|
|
501
|
+
renderHTML: (e) => e.backgroundColor ? {
|
|
502
|
+
"data-cell-background": e.backgroundColor,
|
|
503
|
+
style: `background-color: ${e.backgroundColor};`
|
|
504
|
+
} : {}
|
|
505
|
+
}, Se = ie.extend({ addAttributes() {
|
|
506
|
+
return {
|
|
507
|
+
...this.parent?.(),
|
|
508
|
+
backgroundColor: xe
|
|
509
|
+
};
|
|
510
|
+
} }), Ce = ae.extend({ addAttributes() {
|
|
511
|
+
return {
|
|
512
|
+
...this.parent?.(),
|
|
513
|
+
backgroundColor: xe
|
|
514
|
+
};
|
|
515
|
+
} });
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/utils/table-theme.ts
|
|
518
|
+
function w(e) {
|
|
519
|
+
if (!e || typeof e != "object") return null;
|
|
520
|
+
let t = e;
|
|
521
|
+
return [
|
|
522
|
+
t.header,
|
|
523
|
+
t.odd,
|
|
524
|
+
t.even
|
|
525
|
+
].every((e) => typeof e == "string" && /^#[\da-f]{6}$/i.test(e)) ? {
|
|
526
|
+
header: t.header.toLowerCase(),
|
|
527
|
+
odd: t.odd.toLowerCase(),
|
|
528
|
+
even: t.even.toLowerCase()
|
|
529
|
+
} : null;
|
|
530
|
+
}
|
|
531
|
+
function we(e) {
|
|
532
|
+
let t = [
|
|
533
|
+
1,
|
|
534
|
+
3,
|
|
535
|
+
5
|
|
536
|
+
].map((t) => {
|
|
537
|
+
let n = Number.parseInt(e.slice(t, t + 2), 16) / 255;
|
|
538
|
+
return n <= .04045 ? n / 12.92 : ((n + .055) / 1.055) ** 2.4;
|
|
539
|
+
});
|
|
540
|
+
return t[0] * .2126 + t[1] * .7152 + t[2] * .0722 > .179 ? "#16213a" : "#ffffff";
|
|
541
|
+
}
|
|
542
|
+
function Te(e) {
|
|
543
|
+
let t = w(e);
|
|
544
|
+
return t ? {
|
|
545
|
+
"data-table-theme": "true",
|
|
546
|
+
"data-table-theme-header": t.header,
|
|
547
|
+
"data-table-theme-odd": t.odd,
|
|
548
|
+
"data-table-theme-even": t.even,
|
|
549
|
+
style: `--norio-office-rich-table-header:${t.header};--norio-office-rich-table-header-text:${we(t.header)};--norio-office-rich-table-odd:${t.odd};--norio-office-rich-table-even:${t.even};`
|
|
550
|
+
} : {};
|
|
551
|
+
}
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region src/document/nodes/themed-table.ts
|
|
554
|
+
var Ee = oe.extend({ addAttributes() {
|
|
555
|
+
return {
|
|
556
|
+
...this.parent?.(),
|
|
557
|
+
tableTheme: {
|
|
558
|
+
default: null,
|
|
559
|
+
parseHTML: (e) => w({
|
|
560
|
+
header: e.getAttribute("data-table-theme-header"),
|
|
561
|
+
odd: e.getAttribute("data-table-theme-odd"),
|
|
562
|
+
even: e.getAttribute("data-table-theme-even")
|
|
563
|
+
}),
|
|
564
|
+
renderHTML: (e) => Te(e.tableTheme)
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
} }), De = n.create({
|
|
568
|
+
name: "videoBlock",
|
|
569
|
+
group: "block",
|
|
570
|
+
atom: !0,
|
|
571
|
+
selectable: !0,
|
|
572
|
+
draggable: !0,
|
|
573
|
+
addOptions() {
|
|
574
|
+
return {
|
|
575
|
+
uploadVideo: null,
|
|
576
|
+
onUploadError: null
|
|
577
|
+
};
|
|
578
|
+
},
|
|
579
|
+
addAttributes() {
|
|
580
|
+
return {
|
|
581
|
+
assetId: {
|
|
582
|
+
default: "",
|
|
583
|
+
parseHTML: (e) => e.getAttribute("data-asset-id") || "",
|
|
584
|
+
renderHTML: (e) => ({ "data-asset-id": String(e.assetId ?? "") })
|
|
585
|
+
},
|
|
586
|
+
src: {
|
|
587
|
+
default: "",
|
|
588
|
+
parseHTML: (e) => e.getAttribute("data-src") || "",
|
|
589
|
+
renderHTML: (e) => ({ "data-src": String(e.src ?? "") })
|
|
590
|
+
},
|
|
591
|
+
name: {
|
|
592
|
+
default: "",
|
|
593
|
+
parseHTML: (e) => e.getAttribute("data-name") || "",
|
|
594
|
+
renderHTML: (e) => ({ "data-name": String(e.name ?? "") })
|
|
595
|
+
},
|
|
596
|
+
description: {
|
|
597
|
+
default: "",
|
|
598
|
+
parseHTML: (e) => e.getAttribute("data-description") || "",
|
|
599
|
+
renderHTML: (e) => ({ "data-description": String(e.description ?? "") })
|
|
600
|
+
},
|
|
601
|
+
mimeType: {
|
|
602
|
+
default: "video/mp4",
|
|
603
|
+
parseHTML: (e) => e.getAttribute("data-mime-type") || "video/mp4",
|
|
604
|
+
renderHTML: (e) => ({ "data-mime-type": String(e.mimeType ?? "video/mp4") })
|
|
605
|
+
},
|
|
606
|
+
align: {
|
|
607
|
+
default: "left",
|
|
608
|
+
parseHTML: (e) => e.getAttribute("data-align") || "left",
|
|
609
|
+
renderHTML: (e) => ({ "data-align": String(e.align ?? "left") })
|
|
610
|
+
},
|
|
611
|
+
widthPercent: {
|
|
612
|
+
default: 100,
|
|
613
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-width-percent") ?? "100", 10) || 100,
|
|
614
|
+
renderHTML: (e) => ({ "data-width-percent": String(e.widthPercent ?? 100) })
|
|
615
|
+
},
|
|
616
|
+
height: {
|
|
617
|
+
default: 220,
|
|
618
|
+
parseHTML: (e) => Number.parseInt(e.getAttribute("data-height") ?? "220", 10) || 220,
|
|
619
|
+
renderHTML: (e) => ({ "data-height": String(e.height ?? 220) })
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
},
|
|
623
|
+
parseHTML() {
|
|
624
|
+
return [{ tag: "div[data-type=\"video-block\"]" }];
|
|
625
|
+
},
|
|
626
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
627
|
+
return ["div", {
|
|
628
|
+
...e,
|
|
629
|
+
"data-type": "video-block"
|
|
630
|
+
}];
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region src/extensions/columns-column.ts
|
|
635
|
+
function Oe(e) {
|
|
636
|
+
return e.textContent.trim().length === 0;
|
|
637
|
+
}
|
|
638
|
+
var ke = n.create({
|
|
639
|
+
name: "columnsColumn",
|
|
640
|
+
content: "block+",
|
|
641
|
+
defining: !0,
|
|
642
|
+
isolating: !0,
|
|
643
|
+
parseHTML() {
|
|
644
|
+
return [{ tag: "div[data-type=\"columns-column\"]" }];
|
|
645
|
+
},
|
|
646
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
647
|
+
return [
|
|
648
|
+
"div",
|
|
649
|
+
i(e, {
|
|
650
|
+
"data-type": "columns-column",
|
|
651
|
+
class: "norio-office-rich-columns__column"
|
|
652
|
+
}),
|
|
653
|
+
0
|
|
654
|
+
];
|
|
655
|
+
},
|
|
656
|
+
addKeyboardShortcuts() {
|
|
657
|
+
return { Backspace: () => {
|
|
658
|
+
let { state: e, view: t } = this.editor, { selection: n, schema: r } = e;
|
|
659
|
+
if (!n.empty || n.$from.parentOffset !== 0) return !1;
|
|
660
|
+
let i = -1, a = -1;
|
|
661
|
+
for (let e = n.$from.depth; e > 0; --e) {
|
|
662
|
+
let t = n.$from.node(e).type.name;
|
|
663
|
+
if (t === "columnsColumn" && a < 0 && (a = e), t === "columnsBlock") {
|
|
664
|
+
i = e;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (i < 0 || a < 0) return !1;
|
|
669
|
+
let o = n.$from.node(i), s = n.$from.node(a);
|
|
670
|
+
if (!Oe(s)) return !1;
|
|
671
|
+
let c = n.$from.before(i), l = n.$from.before(a), u = n.$from.index(i), d = e.tr;
|
|
672
|
+
if (o.childCount <= 1) {
|
|
673
|
+
let e = r.nodes.paragraph?.create();
|
|
674
|
+
return e ? (d.replaceWith(c, c + o.nodeSize, e), d.setSelection(g.near(d.doc.resolve(Math.min(c + 1, d.doc.content.size)), 1)), t.dispatch(d.scrollIntoView()), !0) : !1;
|
|
675
|
+
}
|
|
676
|
+
d.delete(l, l + s.nodeSize), d.setNodeMarkup(c, void 0, {
|
|
677
|
+
...o.attrs,
|
|
678
|
+
widths: y(o.childCount - 1)
|
|
679
|
+
});
|
|
680
|
+
let f = d.doc.nodeAt(c);
|
|
681
|
+
if (f) {
|
|
682
|
+
let e = Math.max(0, u - 1), t = c + 1;
|
|
683
|
+
for (let n = 0; n < e; n += 1) t += f.child(n).nodeSize;
|
|
684
|
+
d.setSelection(g.near(d.doc.resolve(Math.min(t + 1, d.doc.content.size)), 1));
|
|
685
|
+
}
|
|
686
|
+
return t.dispatch(d.scrollIntoView()), !0;
|
|
687
|
+
} };
|
|
688
|
+
}
|
|
689
|
+
}), Ae = t.create({
|
|
690
|
+
name: "commentMark",
|
|
691
|
+
inclusive: !1,
|
|
692
|
+
addAttributes() {
|
|
693
|
+
return { threadId: {
|
|
694
|
+
default: "",
|
|
695
|
+
parseHTML: (e) => e.getAttribute("data-comment-thread-id") || "",
|
|
696
|
+
renderHTML: (e) => ({ "data-comment-thread-id": String(e.threadId ?? "") })
|
|
697
|
+
} };
|
|
698
|
+
},
|
|
699
|
+
parseHTML() {
|
|
700
|
+
return [{ tag: "span[data-comment-thread-id]" }];
|
|
701
|
+
},
|
|
702
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
703
|
+
return [
|
|
704
|
+
"span",
|
|
705
|
+
{
|
|
706
|
+
...e,
|
|
707
|
+
class: "norio-office-rich-comment-mark"
|
|
708
|
+
},
|
|
709
|
+
0
|
|
710
|
+
];
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/extensions/indent.ts
|
|
715
|
+
function je(e, t, n) {
|
|
716
|
+
return Math.max(t, Math.min(n, e));
|
|
717
|
+
}
|
|
718
|
+
var Me = e.create({
|
|
719
|
+
name: "indent",
|
|
720
|
+
addOptions() {
|
|
721
|
+
return {
|
|
722
|
+
types: ["paragraph", "heading"],
|
|
723
|
+
minLevel: 0,
|
|
724
|
+
maxLevel: 8,
|
|
725
|
+
stepEm: 2
|
|
726
|
+
};
|
|
727
|
+
},
|
|
728
|
+
addGlobalAttributes() {
|
|
729
|
+
return [{
|
|
730
|
+
types: this.options.types,
|
|
731
|
+
attributes: { indent: {
|
|
732
|
+
default: 0,
|
|
733
|
+
parseHTML: (e) => {
|
|
734
|
+
let t = e.getAttribute("data-indent"), n = Number.parseInt(t ?? "0", 10);
|
|
735
|
+
return Number.isNaN(n) ? this.options.minLevel : je(n, this.options.minLevel, this.options.maxLevel);
|
|
736
|
+
},
|
|
737
|
+
renderHTML: (e) => {
|
|
738
|
+
let t = Number(e.indent ?? 0);
|
|
739
|
+
return t ? {
|
|
740
|
+
"data-indent": String(t),
|
|
741
|
+
style: `margin-left: ${t * this.options.stepEm}em;`
|
|
742
|
+
} : {};
|
|
743
|
+
}
|
|
744
|
+
} }
|
|
745
|
+
}];
|
|
746
|
+
},
|
|
747
|
+
addCommands() {
|
|
748
|
+
let e = (e) => ({ state: t, dispatch: n }) => {
|
|
749
|
+
let r = t.tr, i = !1, a = /* @__PURE__ */ new Set();
|
|
750
|
+
for (let { $from: n, $to: o } of t.selection.ranges) t.doc.nodesBetween(n.pos, o.pos, (t, n) => {
|
|
751
|
+
if (!this.options.types.includes(t.type.name) || a.has(n)) return;
|
|
752
|
+
a.add(n);
|
|
753
|
+
let o = Number(t.attrs.indent ?? 0), s = je(o + e, this.options.minLevel, this.options.maxLevel);
|
|
754
|
+
s !== o && (r.setNodeMarkup(n, void 0, {
|
|
755
|
+
...t.attrs,
|
|
756
|
+
indent: s
|
|
757
|
+
}), i = !0);
|
|
758
|
+
});
|
|
759
|
+
return i ? (n && n(r), !0) : !1;
|
|
760
|
+
};
|
|
761
|
+
return {
|
|
762
|
+
increaseIndent: () => e(1),
|
|
763
|
+
decreaseIndent: () => e(-1)
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
}), Ne = e.create({
|
|
767
|
+
name: "quoteStyle",
|
|
768
|
+
addOptions() {
|
|
769
|
+
return {
|
|
770
|
+
defaultBorderColor: "#c084fc",
|
|
771
|
+
defaultBackgroundColor: "#fcf5ff"
|
|
772
|
+
};
|
|
773
|
+
},
|
|
774
|
+
addGlobalAttributes() {
|
|
775
|
+
return [{
|
|
776
|
+
types: ["blockquote"],
|
|
777
|
+
attributes: {
|
|
778
|
+
quoteBorderColor: {
|
|
779
|
+
default: this.options.defaultBorderColor,
|
|
780
|
+
parseHTML: (e) => e.getAttribute("data-quote-border-color") || this.options.defaultBorderColor,
|
|
781
|
+
renderHTML: (e) => {
|
|
782
|
+
let t = e.quoteBorderColor || this.options.defaultBorderColor, n = e.quoteBackgroundColor || this.options.defaultBackgroundColor;
|
|
783
|
+
return {
|
|
784
|
+
"data-quote-border-color": t,
|
|
785
|
+
"data-quote-background-color": n,
|
|
786
|
+
style: `--norio-office-rich-quote-border-color:${t};--norio-office-rich-quote-background-color:${n};`
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
quoteBackgroundColor: {
|
|
791
|
+
default: this.options.defaultBackgroundColor,
|
|
792
|
+
parseHTML: (e) => e.getAttribute("data-quote-background-color") || this.options.defaultBackgroundColor
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}];
|
|
796
|
+
},
|
|
797
|
+
addCommands() {
|
|
798
|
+
return {
|
|
799
|
+
setQuoteStyle: (e) => ({ commands: t }) => t.updateAttributes("blockquote", {
|
|
800
|
+
quoteBorderColor: e.quoteBorderColor ?? this.options.defaultBorderColor,
|
|
801
|
+
quoteBackgroundColor: e.quoteBackgroundColor ?? this.options.defaultBackgroundColor
|
|
802
|
+
}),
|
|
803
|
+
resetQuoteStyle: () => ({ commands: e }) => e.updateAttributes("blockquote", {
|
|
804
|
+
quoteBorderColor: this.options.defaultBorderColor,
|
|
805
|
+
quoteBackgroundColor: this.options.defaultBackgroundColor
|
|
806
|
+
})
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}), Pe = [
|
|
810
|
+
{
|
|
811
|
+
value: "solid",
|
|
812
|
+
label: "实线"
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
value: "dashed",
|
|
816
|
+
label: "虚线"
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
value: "dotted",
|
|
820
|
+
label: "点状线"
|
|
821
|
+
}
|
|
822
|
+
];
|
|
823
|
+
function Fe(e) {
|
|
824
|
+
return Pe.find((t) => t.value === e)?.value ?? "solid";
|
|
825
|
+
}
|
|
826
|
+
function Ie(e) {
|
|
827
|
+
return typeof e == "string" && /^#[\da-f]{6}$/i.test(e) ? e.toLowerCase() : null;
|
|
828
|
+
}
|
|
829
|
+
//#endregion
|
|
830
|
+
//#region src/extensions/styled-horizontal-rule.ts
|
|
831
|
+
var Le = se.extend({ addAttributes() {
|
|
832
|
+
return {
|
|
833
|
+
...this.parent?.(),
|
|
834
|
+
lineStyle: {
|
|
835
|
+
default: "solid",
|
|
836
|
+
parseHTML: (e) => Fe(e.getAttribute("data-line-style") || e.style.borderTopStyle),
|
|
837
|
+
renderHTML: (e) => {
|
|
838
|
+
let t = Fe(e.lineStyle);
|
|
839
|
+
return {
|
|
840
|
+
"data-line-style": t,
|
|
841
|
+
style: `border-top-style: ${t}; border-top-width: ${t === "solid" ? 1 : 2}px;`
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
lineColor: {
|
|
846
|
+
default: null,
|
|
847
|
+
parseHTML: (e) => Ie(e.getAttribute("data-line-color")),
|
|
848
|
+
renderHTML: (e) => {
|
|
849
|
+
let t = Ie(e.lineColor);
|
|
850
|
+
return t ? {
|
|
851
|
+
"data-line-color": t,
|
|
852
|
+
style: `border-top-color: ${t};`
|
|
853
|
+
} : {};
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
} }), Re = e.create({
|
|
858
|
+
name: "textAlign",
|
|
859
|
+
addOptions() {
|
|
860
|
+
return {
|
|
861
|
+
types: ["paragraph", "heading"],
|
|
862
|
+
alignments: [
|
|
863
|
+
"left",
|
|
864
|
+
"center",
|
|
865
|
+
"right"
|
|
866
|
+
]
|
|
867
|
+
};
|
|
868
|
+
},
|
|
869
|
+
addGlobalAttributes() {
|
|
870
|
+
return [{
|
|
871
|
+
types: this.options.types,
|
|
872
|
+
attributes: { textAlign: {
|
|
873
|
+
default: null,
|
|
874
|
+
parseHTML: (e) => {
|
|
875
|
+
let t = e.style.textAlign || e.getAttribute("data-text-align");
|
|
876
|
+
return this.options.alignments.includes(t) ? t : null;
|
|
877
|
+
},
|
|
878
|
+
renderHTML: (e) => !e.textAlign || e.textAlign === "left" ? {} : {
|
|
879
|
+
"data-text-align": e.textAlign,
|
|
880
|
+
style: `text-align: ${e.textAlign};`
|
|
881
|
+
}
|
|
882
|
+
} }
|
|
883
|
+
}];
|
|
884
|
+
},
|
|
885
|
+
addCommands() {
|
|
886
|
+
let e = (e) => ({ state: t, dispatch: n }) => {
|
|
887
|
+
let { selection: r, doc: i } = t, a = t.tr, o = !1;
|
|
888
|
+
for (let { $from: t, $to: n } of r.ranges) i.nodesBetween(t.pos, n.pos, (t, n) => {
|
|
889
|
+
if (!this.options.types.includes(t.type.name)) return;
|
|
890
|
+
let r = e === "left" ? null : e;
|
|
891
|
+
return t.attrs.textAlign === r || (a = a.setNodeMarkup(n, void 0, {
|
|
892
|
+
...t.attrs,
|
|
893
|
+
textAlign: r
|
|
894
|
+
}), o = !0), !1;
|
|
895
|
+
});
|
|
896
|
+
if (!o) {
|
|
897
|
+
let { $from: t } = r;
|
|
898
|
+
for (let n = t.depth; n > 0; --n) {
|
|
899
|
+
let r = t.node(n);
|
|
900
|
+
if (this.options.types.includes(r.type.name)) {
|
|
901
|
+
a = a.setNodeMarkup(t.before(n), void 0, {
|
|
902
|
+
...r.attrs,
|
|
903
|
+
textAlign: e === "left" ? null : e
|
|
904
|
+
}), o = !0;
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return o ? (n && n(a), !0) : !1;
|
|
910
|
+
};
|
|
911
|
+
return {
|
|
912
|
+
setTextAlign: (t) => (n) => e(t)(n),
|
|
913
|
+
unsetTextAlign: () => (t) => e(null)(t)
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
}), ze = "1";
|
|
917
|
+
function Be() {
|
|
918
|
+
return [
|
|
919
|
+
ee.configure({
|
|
920
|
+
codeBlock: !1,
|
|
921
|
+
horizontalRule: !1,
|
|
922
|
+
underline: !1
|
|
923
|
+
}),
|
|
924
|
+
ce,
|
|
925
|
+
Ee,
|
|
926
|
+
d,
|
|
927
|
+
Ce,
|
|
928
|
+
Se,
|
|
929
|
+
Le,
|
|
930
|
+
Ae,
|
|
931
|
+
Me,
|
|
932
|
+
de,
|
|
933
|
+
ke,
|
|
934
|
+
fe,
|
|
935
|
+
pe,
|
|
936
|
+
he,
|
|
937
|
+
ge,
|
|
938
|
+
_e,
|
|
939
|
+
ve,
|
|
940
|
+
De,
|
|
941
|
+
be,
|
|
942
|
+
me,
|
|
943
|
+
m,
|
|
944
|
+
c,
|
|
945
|
+
s,
|
|
946
|
+
a,
|
|
947
|
+
o,
|
|
948
|
+
u,
|
|
949
|
+
l,
|
|
950
|
+
p,
|
|
951
|
+
f.configure({ nested: !1 }),
|
|
952
|
+
h,
|
|
953
|
+
Ne,
|
|
954
|
+
Re
|
|
955
|
+
];
|
|
956
|
+
}
|
|
957
|
+
var T;
|
|
958
|
+
function E() {
|
|
959
|
+
return T ??= r(Be()), T;
|
|
960
|
+
}
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region src/ai-protocol/validation.ts
|
|
963
|
+
function D(e) {
|
|
964
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
965
|
+
}
|
|
966
|
+
function O(e, t, n, r) {
|
|
967
|
+
e.push({
|
|
968
|
+
path: t,
|
|
969
|
+
code: n,
|
|
970
|
+
message: r
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
function Ve(e) {
|
|
974
|
+
if (e.length > 80 || /[;{}<>\\]/.test(e)) return !1;
|
|
975
|
+
if (/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e) || /^[a-z]+$/i.test(e)) return !0;
|
|
976
|
+
let t = /^(rgba?)\((.*)\)$/i.exec(e);
|
|
977
|
+
if (!t) return !1;
|
|
978
|
+
let n = t[2].trim(), r = n.includes(",") ? n.split(",").map((e) => e.trim()) : null, i = r ? null : n.replace(/\s*\/\s*/, " / ").split(/\s+/), a = r ?? i ?? [], o, s;
|
|
979
|
+
if (a.includes("/")) {
|
|
980
|
+
if (a.indexOf("/") !== 3 || a.length !== 5) return !1;
|
|
981
|
+
o = a.slice(0, 3), s = a[4];
|
|
982
|
+
} else if (o = a.slice(0, 3), s = a[3], a.length !== (s === void 0 ? 3 : 4) || s !== void 0 && (!r || t[1].toLowerCase() !== "rgba")) return !1;
|
|
983
|
+
if (t[1].toLowerCase() === "rgba" && s === void 0) return !1;
|
|
984
|
+
let c = (e, t) => {
|
|
985
|
+
if (!/^(?:\d+(?:\.\d*)?|\.\d+)%?$/.test(e)) return !1;
|
|
986
|
+
let n = e.endsWith("%"), r = Number.parseFloat(e);
|
|
987
|
+
return Number.isFinite(r) && r >= 0 && r <= (n ? 100 : t);
|
|
988
|
+
};
|
|
989
|
+
return o.length === 3 && o.every((e) => c(e, 255)) && (s === void 0 || c(s, 1));
|
|
990
|
+
}
|
|
991
|
+
function k(e, t, n) {
|
|
992
|
+
if (t === "aiId") return n === null || typeof n == "string" && !!n.trim();
|
|
993
|
+
let r = E(), i = r.nodes[e]?.spec.attrs?.[t] ?? r.marks[e]?.spec.attrs?.[t];
|
|
994
|
+
if (n === null) return i?.default === null;
|
|
995
|
+
if (t === "images" && e === "imageBlock") {
|
|
996
|
+
let e = /* @__PURE__ */ new Set([
|
|
997
|
+
"id",
|
|
998
|
+
"assetId",
|
|
999
|
+
"src",
|
|
1000
|
+
"alt",
|
|
1001
|
+
"name",
|
|
1002
|
+
"description",
|
|
1003
|
+
"descriptionVisible",
|
|
1004
|
+
"link",
|
|
1005
|
+
"linkTarget",
|
|
1006
|
+
"rotation"
|
|
1007
|
+
]);
|
|
1008
|
+
return Array.isArray(n) && n.length <= 4 && n.every((t) => !D(t) || Object.keys(t).some((t) => !e.has(t)) ? !1 : Object.entries(t).every(([e, t]) => e === "descriptionVisible" ? typeof t == "boolean" : e === "rotation" ? typeof t == "number" && Number.isFinite(t) : e === "linkTarget" ? t === "_blank" || t === "_self" : e === "src" || e === "link" ? k("link", "href", t) : typeof t == "string" && (e !== "id" && e !== "assetId" || !!t.trim())));
|
|
1009
|
+
}
|
|
1010
|
+
if (t === "indent") return Number.isInteger(n) && n >= 0 && n <= 8;
|
|
1011
|
+
if (t === "level") return Number.isInteger(n) && n >= 1 && n <= 6;
|
|
1012
|
+
if (t === "textAlign" || t === "align") return [
|
|
1013
|
+
"left",
|
|
1014
|
+
"center",
|
|
1015
|
+
"right"
|
|
1016
|
+
].includes(String(n));
|
|
1017
|
+
if (t === "colwidth") return Array.isArray(n) && n.length > 0 && n.every((e) => Number.isSafeInteger(e) && e > 0);
|
|
1018
|
+
if (t === "type" && e === "orderedList") return [
|
|
1019
|
+
"1",
|
|
1020
|
+
"a",
|
|
1021
|
+
"A",
|
|
1022
|
+
"i",
|
|
1023
|
+
"I"
|
|
1024
|
+
].includes(String(n));
|
|
1025
|
+
if (t === "displayMode" && e === "linkBlock") return [
|
|
1026
|
+
"text",
|
|
1027
|
+
"card",
|
|
1028
|
+
"preview"
|
|
1029
|
+
].includes(String(n));
|
|
1030
|
+
if (t === "lineStyle" && e === "horizontalRule") return [
|
|
1031
|
+
"solid",
|
|
1032
|
+
"dashed",
|
|
1033
|
+
"dotted"
|
|
1034
|
+
].includes(String(n));
|
|
1035
|
+
if (t === "widthPercent") return typeof n == "number" && Number.isFinite(n) && n > 0 && n <= 100;
|
|
1036
|
+
if (t === "height" || t === "size" || t === "targetTimestamp") return Number.isSafeInteger(n) && n >= 0;
|
|
1037
|
+
if (t === "mode" && e === "countdownBlock") return ["duration", "deadline"].includes(String(n));
|
|
1038
|
+
if (t === "tableTheme") return D(n) && Object.keys(n).length === 3 && w(n) !== null;
|
|
1039
|
+
if (t === "widths") return Array.isArray(n) && n.every((e) => typeof e == "number" && Number.isFinite(e) && e > 0);
|
|
1040
|
+
if (t === "colspan" || t === "rowspan" || t === "start") return Number.isSafeInteger(n) && n >= 1;
|
|
1041
|
+
if (t === "fontSize") return typeof n == "string" && /^\d{1,3}px$/.test(n) && Number.parseInt(n, 10) > 0;
|
|
1042
|
+
if (t === "fontFamily") return typeof n == "string" && n.length <= 120 && !/[;{}<>\\]/.test(n);
|
|
1043
|
+
if (/color$/i.test(t) || t === "backgroundColor") return typeof n == "string" && Ve(n);
|
|
1044
|
+
if (t === "href" || t === "url" || t === "src") return typeof n == "string" && !/^\s*(?:javascript|vbscript):/i.test(n) && !/[<>]/.test(n);
|
|
1045
|
+
let a = i?.default;
|
|
1046
|
+
return a === null ? typeof n == "string" : Array.isArray(a) ? Array.isArray(n) : a !== void 0 && typeof n == typeof a && (typeof n != "number" || Number.isFinite(n));
|
|
1047
|
+
}
|
|
1048
|
+
function A(e, t, n, r, i) {
|
|
1049
|
+
if (e !== void 0) {
|
|
1050
|
+
if (!D(e)) O(i, r, "INVALID_ATTRIBUTES", "Attributes must be an object.");
|
|
1051
|
+
else for (let [a, o] of Object.entries(e)) {
|
|
1052
|
+
let e = t?.[a], s = `${r}.${a}`;
|
|
1053
|
+
if (!e) {
|
|
1054
|
+
O(i, s, "UNKNOWN_ATTRIBUTE", `Unknown attribute: ${a}.`);
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
let c = e.default;
|
|
1058
|
+
k(n, a, o) ? c != null && o !== null && (Array.isArray(c) ? !Array.isArray(o) : typeof o != typeof c) && O(i, s, "INVALID_ATTRIBUTE_VALUE", `Invalid value for ${a}.`) : O(i, s, "INVALID_ATTRIBUTE_VALUE", `Invalid value for ${a}.`);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
function He(e, t, n, r) {
|
|
1063
|
+
if (!D(e) || typeof e.type != "string") {
|
|
1064
|
+
O(r, n, "INVALID_MARK", "Mark must have a type.");
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
let i = t.marks[e.type];
|
|
1068
|
+
if (!i) O(r, `${n}.type`, "UNKNOWN_MARK", `Unknown mark: ${e.type}.`);
|
|
1069
|
+
else {
|
|
1070
|
+
for (let t of Object.keys(e)) t !== "type" && t !== "attrs" && O(r, `${n}.${t}`, "UNKNOWN_FIELD", `Unknown mark field: ${t}.`);
|
|
1071
|
+
A(e.attrs, i.spec.attrs, e.type, `${n}.attrs`, r);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
function j(e, t = "$") {
|
|
1075
|
+
let n = [];
|
|
1076
|
+
if (M(e, E(), t, n), n.length) return n;
|
|
1077
|
+
try {
|
|
1078
|
+
E().nodeFromJSON(e).check();
|
|
1079
|
+
} catch (e) {
|
|
1080
|
+
O(n, t, "INVALID_NODE", e instanceof Error ? e.message : "Invalid node structure.");
|
|
1081
|
+
}
|
|
1082
|
+
return n;
|
|
1083
|
+
}
|
|
1084
|
+
function M(e, t, n, r) {
|
|
1085
|
+
if (!D(e) || typeof e.type != "string") {
|
|
1086
|
+
O(r, n, "INVALID_NODE", "Node must have a type.");
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
let i = t.nodes[e.type];
|
|
1090
|
+
if (!i) O(r, `${n}.type`, "UNKNOWN_NODE", `Unknown node: ${e.type}.`);
|
|
1091
|
+
else {
|
|
1092
|
+
for (let t of Object.keys(e)) t !== "type" && t !== "attrs" && t !== "content" && t !== "text" && t !== "marks" && O(r, `${n}.${t}`, "UNKNOWN_FIELD", `Unknown node field: ${t}.`);
|
|
1093
|
+
if (A(e.attrs, i.spec.attrs, e.type, `${n}.attrs`, r), e.type === "text" ? (typeof e.text != "string" || !e.text.length) && O(r, `${n}.text`, "INVALID_TEXT", "Text must be a nonempty string.") : e.text !== void 0 && O(r, `${n}.text`, "INVALID_TEXT", "Only text nodes may contain text."), e.content !== void 0 && (i.isLeaf ? O(r, `${n}.content`, "INVALID_CONTENT", "Leaf nodes cannot contain child nodes.") : Array.isArray(e.content) ? e.content.forEach((e, i) => M(e, t, `${n}.content[${i}]`, r)) : O(r, `${n}.content`, "INVALID_CONTENT", "Content must be an array.")), e.marks !== void 0 && (i.isInline ? Array.isArray(e.marks) ? e.marks.forEach((e, i) => He(e, t, `${n}.marks[${i}]`, r)) : O(r, `${n}.marks`, "INVALID_MARKS", "Marks must be an array.") : O(r, `${n}.marks`, "INVALID_MARKS", "Only inline nodes can have marks.")), e.type === "columnsBlock" && Array.isArray(e.content) && D(e.attrs)) {
|
|
1094
|
+
let t = e.attrs.widths;
|
|
1095
|
+
t !== void 0 && (!Array.isArray(t) || t.length !== e.content.length || t.some((e) => typeof e != "number" || !Number.isFinite(e) || e <= 0)) && O(r, `${n}.attrs.widths`, "INVALID_COLUMNS_WIDTHS", "Column widths must match the number of columns and be positive numbers.");
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
function N(e) {
|
|
1100
|
+
let t = [], n = E();
|
|
1101
|
+
if (M(e, n, "$", t), D(e) && e.type !== "doc" && O(t, "$.type", "INVALID_ROOT", "Document root must be doc."), t.length) return {
|
|
1102
|
+
valid: !1,
|
|
1103
|
+
errors: t,
|
|
1104
|
+
schemaVersion: "1"
|
|
1105
|
+
};
|
|
1106
|
+
try {
|
|
1107
|
+
let r = n.nodeFromJSON(e);
|
|
1108
|
+
r.check();
|
|
1109
|
+
let i = /* @__PURE__ */ new Set();
|
|
1110
|
+
return r.descendants((e, n) => {
|
|
1111
|
+
let r = e.attrs.aiId;
|
|
1112
|
+
r != null && (typeof r != "string" || !r.trim() || i.has(r) ? O(t, `$.pos[${n}].attrs.aiId`, "INVALID_AI_ID", "Block aiId must be unique and nonempty.") : i.add(r));
|
|
1113
|
+
}), t.length ? {
|
|
1114
|
+
valid: !1,
|
|
1115
|
+
errors: t,
|
|
1116
|
+
schemaVersion: "1"
|
|
1117
|
+
} : {
|
|
1118
|
+
valid: !0,
|
|
1119
|
+
document: r.toJSON(),
|
|
1120
|
+
schemaVersion: "1",
|
|
1121
|
+
errors: []
|
|
1122
|
+
};
|
|
1123
|
+
} catch (e) {
|
|
1124
|
+
return O(t, "$", "INVALID_DOCUMENT", e instanceof Error ? e.message : "Invalid document structure."), {
|
|
1125
|
+
valid: !1,
|
|
1126
|
+
errors: t,
|
|
1127
|
+
schemaVersion: "1"
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
function Ue(e, t = "legacy-json") {
|
|
1132
|
+
if (t !== "legacy-json" && t !== "1") return {
|
|
1133
|
+
valid: !1,
|
|
1134
|
+
schemaVersion: "1",
|
|
1135
|
+
errors: [{
|
|
1136
|
+
path: "$",
|
|
1137
|
+
code: "SCHEMA_VERSION_UNSUPPORTED",
|
|
1138
|
+
message: `Unsupported document schema version: ${t}.`
|
|
1139
|
+
}]
|
|
1140
|
+
};
|
|
1141
|
+
let n = N(e);
|
|
1142
|
+
return !n.valid && !n.errors.every((e) => e.code === "INVALID_AI_ID") ? n : N(le(n.valid ? n.document : e));
|
|
1143
|
+
}
|
|
1144
|
+
//#endregion
|
|
1145
|
+
//#region src/ai-protocol/patch.ts
|
|
1146
|
+
var P = {
|
|
1147
|
+
insertContent: [
|
|
1148
|
+
"type",
|
|
1149
|
+
"targetRef",
|
|
1150
|
+
"position",
|
|
1151
|
+
"content"
|
|
1152
|
+
],
|
|
1153
|
+
replaceText: [
|
|
1154
|
+
"type",
|
|
1155
|
+
"targetRef",
|
|
1156
|
+
"text"
|
|
1157
|
+
],
|
|
1158
|
+
replaceFragment: [
|
|
1159
|
+
"type",
|
|
1160
|
+
"targetRef",
|
|
1161
|
+
"content"
|
|
1162
|
+
],
|
|
1163
|
+
setMarks: [
|
|
1164
|
+
"type",
|
|
1165
|
+
"targetRef",
|
|
1166
|
+
"marks"
|
|
1167
|
+
],
|
|
1168
|
+
unsetMarks: [
|
|
1169
|
+
"type",
|
|
1170
|
+
"targetRef",
|
|
1171
|
+
"markTypes"
|
|
1172
|
+
],
|
|
1173
|
+
setNodeAttributes: [
|
|
1174
|
+
"type",
|
|
1175
|
+
"targetRef",
|
|
1176
|
+
"nodeType",
|
|
1177
|
+
"attrs"
|
|
1178
|
+
],
|
|
1179
|
+
unsetNodeAttributes: [
|
|
1180
|
+
"type",
|
|
1181
|
+
"targetRef",
|
|
1182
|
+
"nodeType",
|
|
1183
|
+
"attributes"
|
|
1184
|
+
],
|
|
1185
|
+
deleteContent: ["type", "targetRef"],
|
|
1186
|
+
moveBlocks: [
|
|
1187
|
+
"type",
|
|
1188
|
+
"targetRef",
|
|
1189
|
+
"destinationRef",
|
|
1190
|
+
"position"
|
|
1191
|
+
],
|
|
1192
|
+
transformBlocks: [
|
|
1193
|
+
"type",
|
|
1194
|
+
"targetRef",
|
|
1195
|
+
"nodeType",
|
|
1196
|
+
"attrs"
|
|
1197
|
+
],
|
|
1198
|
+
tableOperation: [
|
|
1199
|
+
"type",
|
|
1200
|
+
"targetRef",
|
|
1201
|
+
"action",
|
|
1202
|
+
"content",
|
|
1203
|
+
"value"
|
|
1204
|
+
]
|
|
1205
|
+
}, We = /* @__PURE__ */ new Set([
|
|
1206
|
+
"insertRowBefore",
|
|
1207
|
+
"insertRowAfter",
|
|
1208
|
+
"deleteRow",
|
|
1209
|
+
"insertColumnBefore",
|
|
1210
|
+
"insertColumnAfter",
|
|
1211
|
+
"deleteColumn",
|
|
1212
|
+
"mergeCells",
|
|
1213
|
+
"splitCell",
|
|
1214
|
+
"setCellContent",
|
|
1215
|
+
"setCellBackground",
|
|
1216
|
+
"setTableTheme"
|
|
1217
|
+
]);
|
|
1218
|
+
function F(e) {
|
|
1219
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1220
|
+
}
|
|
1221
|
+
function I(e, t, n, r) {
|
|
1222
|
+
e.push({
|
|
1223
|
+
path: t,
|
|
1224
|
+
code: n,
|
|
1225
|
+
message: r
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
function L(e, t, n, r, i) {
|
|
1229
|
+
if (!F(e)) I(i, r, "INVALID_ATTRIBUTES", "Attributes must be an object.");
|
|
1230
|
+
else for (let a of Object.keys(e)) t?.[a] ? k(n, a, e[a]) || I(i, `${r}.${a}`, "INVALID_ATTRIBUTE_VALUE", `Invalid value for ${a}.`) : I(i, `${r}.${a}`, "UNKNOWN_ATTRIBUTE", `Unknown attribute: ${a}.`);
|
|
1231
|
+
}
|
|
1232
|
+
function R(e, t, n) {
|
|
1233
|
+
if (!Array.isArray(e) || !e.length) {
|
|
1234
|
+
I(n, t, "INVALID_FRAGMENT", "Fragment must contain at least one node.");
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
let r = E();
|
|
1238
|
+
function i(e, t) {
|
|
1239
|
+
F(e.attrs) && Object.prototype.hasOwnProperty.call(e.attrs, "aiId") && I(n, `${t}.attrs.aiId`, "OUT_OF_SCOPE", "AI cannot supply node identity."), Array.isArray(e.content) && e.content.forEach((e, n) => {
|
|
1240
|
+
F(e) && i(e, `${t}.content[${n}]`);
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
for (let [a, o] of e.entries()) !F(o) || typeof o.type != "string" || !r.nodes[o.type] ? I(n, `${t}[${a}]`, "UNKNOWN_NODE", "Fragment contains an unknown node.") : (i(o, `${t}[${a}]`), n.push(...j(o, `${t}[${a}]`)));
|
|
1244
|
+
}
|
|
1245
|
+
function Ge(e) {
|
|
1246
|
+
let t = [];
|
|
1247
|
+
if (!F(e)) return {
|
|
1248
|
+
valid: !1,
|
|
1249
|
+
errors: [{
|
|
1250
|
+
path: "$",
|
|
1251
|
+
code: "INVALID_PATCH",
|
|
1252
|
+
message: "Patch must be an object."
|
|
1253
|
+
}]
|
|
1254
|
+
};
|
|
1255
|
+
let n = /* @__PURE__ */ new Set([
|
|
1256
|
+
"protocolVersion",
|
|
1257
|
+
"documentId",
|
|
1258
|
+
"requestId",
|
|
1259
|
+
"contextId",
|
|
1260
|
+
"baseRevision",
|
|
1261
|
+
"operations"
|
|
1262
|
+
]);
|
|
1263
|
+
for (let r of Object.keys(e)) n.has(r) || I(t, `$.${r}`, "UNKNOWN_FIELD", `Unknown patch field: ${r}.`);
|
|
1264
|
+
e.protocolVersion !== 1 && I(t, "$.protocolVersion", "SCHEMA_VERSION_UNSUPPORTED", "Only protocol version 1 is supported.");
|
|
1265
|
+
for (let n of [
|
|
1266
|
+
"documentId",
|
|
1267
|
+
"requestId",
|
|
1268
|
+
"contextId"
|
|
1269
|
+
]) (typeof e[n] != "string" || !e[n].trim()) && I(t, `$.${n}`, "INVALID_FIELD", `${n} must be nonempty.`);
|
|
1270
|
+
if ((!Number.isSafeInteger(e.baseRevision) || e.baseRevision < 0) && I(t, "$.baseRevision", "INVALID_REVISION", "baseRevision must be a nonnegative integer."), !Array.isArray(e.operations) || !e.operations.length || e.operations.length > 500) I(t, "$.operations", "INVALID_OPERATIONS", "Patch must contain 1 to 500 operations.");
|
|
1271
|
+
else {
|
|
1272
|
+
let n = E();
|
|
1273
|
+
e.operations.forEach((e, r) => {
|
|
1274
|
+
let i = `$.operations[${r}]`;
|
|
1275
|
+
if (!F(e) || typeof e.type != "string" || !(e.type in P)) {
|
|
1276
|
+
I(t, i, "UNKNOWN_OPERATION", "Unknown patch operation.");
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
let a = e.type;
|
|
1280
|
+
for (let n of Object.keys(e)) P[a].includes(n) || I(t, `${i}.${n}`, "UNKNOWN_FIELD", `Unknown operation field: ${n}.`);
|
|
1281
|
+
switch ((typeof e.targetRef != "string" || !e.targetRef) && I(t, `${i}.targetRef`, "INVALID_TARGET", "Missing targetRef."), a) {
|
|
1282
|
+
case "insertContent":
|
|
1283
|
+
[
|
|
1284
|
+
"at",
|
|
1285
|
+
"before",
|
|
1286
|
+
"after"
|
|
1287
|
+
].includes(String(e.position)) || I(t, `${i}.position`, "INVALID_POSITION", "Invalid insertion position."), R(e.content, `${i}.content`, t);
|
|
1288
|
+
break;
|
|
1289
|
+
case "replaceText":
|
|
1290
|
+
typeof e.text != "string" && I(t, `${i}.text`, "INVALID_TEXT", "Replacement must be text.");
|
|
1291
|
+
break;
|
|
1292
|
+
case "replaceFragment":
|
|
1293
|
+
R(e.content, `${i}.content`, t);
|
|
1294
|
+
break;
|
|
1295
|
+
case "setMarks":
|
|
1296
|
+
!Array.isArray(e.marks) || !e.marks.length ? I(t, `${i}.marks`, "INVALID_MARKS", "Marks are required.") : e.marks.forEach((e, r) => {
|
|
1297
|
+
let a = `${i}.marks[${r}]`;
|
|
1298
|
+
if (!F(e) || typeof e.type != "string" || !n.marks[e.type]) I(t, a, "UNKNOWN_MARK", "Unknown mark.");
|
|
1299
|
+
else {
|
|
1300
|
+
for (let n of Object.keys(e)) n !== "type" && n !== "attrs" && I(t, `${a}.${n}`, "UNKNOWN_FIELD", `Unknown mark field: ${n}.`);
|
|
1301
|
+
e.attrs !== void 0 && L(e.attrs, n.marks[e.type].spec.attrs, e.type, `${a}.attrs`, t);
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
break;
|
|
1305
|
+
case "unsetMarks":
|
|
1306
|
+
(!Array.isArray(e.markTypes) || !e.markTypes.length || e.markTypes.some((e) => typeof e != "string" || !n.marks[e])) && I(t, `${i}.markTypes`, "UNKNOWN_MARK", "Unknown or missing mark type.");
|
|
1307
|
+
break;
|
|
1308
|
+
case "setNodeAttributes":
|
|
1309
|
+
case "unsetNodeAttributes":
|
|
1310
|
+
case "transformBlocks": {
|
|
1311
|
+
let r = typeof e.nodeType == "string" ? n.nodes[e.nodeType] : void 0;
|
|
1312
|
+
r || I(t, `${i}.nodeType`, "UNKNOWN_NODE", "Unknown node type."), a === "unsetNodeAttributes" ? ((!Array.isArray(e.attributes) || !e.attributes.length || e.attributes.some((e) => typeof e != "string" || !r?.spec.attrs?.[e])) && I(t, `${i}.attributes`, "UNKNOWN_ATTRIBUTE", "Unknown or missing attribute name."), Array.isArray(e.attributes) && e.attributes.includes("aiId") && I(t, `${i}.attributes`, "OUT_OF_SCOPE", "AI cannot remove node identity.")) : (e.attrs !== void 0 || a === "setNodeAttributes") && (L(e.attrs, r?.spec.attrs, String(e.nodeType), `${i}.attrs`, t), F(e.attrs) && Object.prototype.hasOwnProperty.call(e.attrs, "aiId") && I(t, `${i}.attrs.aiId`, "OUT_OF_SCOPE", "AI cannot set node identity."));
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
case "moveBlocks":
|
|
1316
|
+
(typeof e.destinationRef != "string" || !e.destinationRef || !["before", "after"].includes(String(e.position))) && I(t, i, "INVALID_MOVE", "Move requires a destination and position.");
|
|
1317
|
+
break;
|
|
1318
|
+
case "tableOperation": We.has(String(e.action)) || I(t, `${i}.action`, "UNKNOWN_OPERATION", "Unknown table action."), e.action === "setCellContent" ? R(e.content, `${i}.content`, t) : e.content !== void 0 && I(t, `${i}.content`, "UNKNOWN_FIELD", "This table action does not accept content."), !["setCellBackground", "setTableTheme"].includes(String(e.action)) && e.value !== void 0 && I(t, `${i}.value`, "UNKNOWN_FIELD", "This table action does not accept a value."), e.action === "setCellBackground" && !k("tableCell", "backgroundColor", e.value) && I(t, `${i}.value`, "INVALID_ATTRIBUTE_VALUE", "Invalid cell background color."), e.action === "setTableTheme" && !k("table", "tableTheme", e.value) && I(t, `${i}.value`, "INVALID_ATTRIBUTE_VALUE", "Invalid table theme.");
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
return t.length ? {
|
|
1323
|
+
valid: !1,
|
|
1324
|
+
errors: t
|
|
1325
|
+
} : {
|
|
1326
|
+
valid: !0,
|
|
1327
|
+
patch: e,
|
|
1328
|
+
errors: []
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
//#endregion
|
|
1332
|
+
//#region src/ai-protocol/stream.ts
|
|
1333
|
+
var Ke = 1, z = class extends Error {
|
|
1334
|
+
code;
|
|
1335
|
+
constructor(e, t) {
|
|
1336
|
+
super(t), this.code = e, this.name = "RichTextStreamError";
|
|
1337
|
+
}
|
|
1338
|
+
}, B = {
|
|
1339
|
+
maxEventBytes: 262144,
|
|
1340
|
+
maxTotalBytes: 16777216,
|
|
1341
|
+
maxTextLength: 2e6,
|
|
1342
|
+
maxNodes: 2e4,
|
|
1343
|
+
maxDepth: 32,
|
|
1344
|
+
maxOperations: 500,
|
|
1345
|
+
maxEvents: 1e5
|
|
1346
|
+
};
|
|
1347
|
+
function V(e) {
|
|
1348
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1349
|
+
}
|
|
1350
|
+
function H(e) {
|
|
1351
|
+
throw new z("INVALID_STREAM_EVENT", e);
|
|
1352
|
+
}
|
|
1353
|
+
function U(e) {
|
|
1354
|
+
if (!V(e) || e.protocolVersion !== 1 || typeof e.streamId != "string" || !e.streamId || !Number.isSafeInteger(e.seq) || e.seq < 1 || !V(e.payload)) return H("Invalid stream envelope.");
|
|
1355
|
+
if (typeof e.type != "string" || ![
|
|
1356
|
+
"node.open",
|
|
1357
|
+
"text.delta",
|
|
1358
|
+
"node.attrs",
|
|
1359
|
+
"node.close",
|
|
1360
|
+
"operation",
|
|
1361
|
+
"stream.end"
|
|
1362
|
+
].includes(e.type)) return H("Unknown stream event type.");
|
|
1363
|
+
let t = e.payload;
|
|
1364
|
+
if (Object.keys(e).some((e) => ![
|
|
1365
|
+
"protocolVersion",
|
|
1366
|
+
"streamId",
|
|
1367
|
+
"seq",
|
|
1368
|
+
"type",
|
|
1369
|
+
"payload"
|
|
1370
|
+
].includes(e))) return H("Unknown stream envelope field.");
|
|
1371
|
+
let n = {
|
|
1372
|
+
"node.open": [
|
|
1373
|
+
"nodeRef",
|
|
1374
|
+
"nodeType",
|
|
1375
|
+
"attrs"
|
|
1376
|
+
],
|
|
1377
|
+
"text.delta": [
|
|
1378
|
+
"nodeRef",
|
|
1379
|
+
"text",
|
|
1380
|
+
"marks"
|
|
1381
|
+
],
|
|
1382
|
+
"node.attrs": ["nodeRef", "attrs"],
|
|
1383
|
+
"node.close": ["nodeRef"],
|
|
1384
|
+
operation: ["operation"],
|
|
1385
|
+
"stream.end": []
|
|
1386
|
+
};
|
|
1387
|
+
if (Object.keys(t).some((t) => !n[e.type].includes(t))) return H("Unknown stream payload field.");
|
|
1388
|
+
switch (e.type) {
|
|
1389
|
+
case "node.open":
|
|
1390
|
+
if (typeof t.nodeRef != "string" || !t.nodeRef || typeof t.nodeType != "string" || !t.nodeType || t.attrs !== void 0 && !V(t.attrs)) return H("Invalid node.open payload.");
|
|
1391
|
+
if (!E().nodes[t.nodeType]) return H("Unknown node type.");
|
|
1392
|
+
if (V(t.attrs)) {
|
|
1393
|
+
if (Object.prototype.hasOwnProperty.call(t.attrs, "aiId")) return H("AI cannot supply node identity.");
|
|
1394
|
+
let e = E().nodes[t.nodeType].spec.attrs ?? {};
|
|
1395
|
+
if (Object.entries(t.attrs).some(([n, r]) => !Object.prototype.hasOwnProperty.call(e, n) || !k(t.nodeType, n, r))) return H("Invalid node.open attributes.");
|
|
1396
|
+
}
|
|
1397
|
+
break;
|
|
1398
|
+
case "text.delta":
|
|
1399
|
+
if (typeof t.text != "string" || !t.text || t.nodeRef !== void 0 && typeof t.nodeRef != "string" || t.marks !== void 0 && !Array.isArray(t.marks)) return H("Invalid text.delta payload.");
|
|
1400
|
+
if (t.marks && j({
|
|
1401
|
+
type: "text",
|
|
1402
|
+
text: "x",
|
|
1403
|
+
marks: t.marks
|
|
1404
|
+
}).length) return H("Invalid text.delta marks.");
|
|
1405
|
+
break;
|
|
1406
|
+
case "node.attrs":
|
|
1407
|
+
if (typeof t.nodeRef != "string" || !V(t.attrs)) return H("Invalid node.attrs payload.");
|
|
1408
|
+
if (Object.prototype.hasOwnProperty.call(t.attrs, "aiId")) return H("AI cannot supply node identity.");
|
|
1409
|
+
break;
|
|
1410
|
+
case "node.close":
|
|
1411
|
+
if (typeof t.nodeRef != "string") return H("Invalid node.close payload.");
|
|
1412
|
+
break;
|
|
1413
|
+
case "operation":
|
|
1414
|
+
if (!V(t.operation)) return H("Invalid operation payload.");
|
|
1415
|
+
{
|
|
1416
|
+
let e = Ge({
|
|
1417
|
+
protocolVersion: 1,
|
|
1418
|
+
documentId: "stream",
|
|
1419
|
+
requestId: "stream",
|
|
1420
|
+
contextId: "stream",
|
|
1421
|
+
baseRevision: 0,
|
|
1422
|
+
operations: [t.operation]
|
|
1423
|
+
});
|
|
1424
|
+
if (!e.valid) return H(`Invalid streamed operation: ${e.errors[0]?.code ?? "INVALID_OPERATION"} at ${e.errors[0]?.path ?? "operation"}.`);
|
|
1425
|
+
}
|
|
1426
|
+
break;
|
|
1427
|
+
case "stream.end": if (Object.keys(t).length) return H("stream.end payload must be empty.");
|
|
1428
|
+
}
|
|
1429
|
+
return e;
|
|
1430
|
+
}
|
|
1431
|
+
function qe(e = {}) {
|
|
1432
|
+
let t = {
|
|
1433
|
+
...B,
|
|
1434
|
+
...e
|
|
1435
|
+
}, n = new TextDecoder("utf-8", { fatal: !0 }), r = new TextEncoder(), i = "", a = 0, o = !1;
|
|
1436
|
+
function s(e) {
|
|
1437
|
+
if (e.endsWith("\r") && (e = e.slice(0, -1)), !e) return null;
|
|
1438
|
+
if (r.encode(e).byteLength > t.maxEventBytes) throw new z("STREAM_LIMIT_EXCEEDED", "Stream event exceeds byte limit.");
|
|
1439
|
+
try {
|
|
1440
|
+
return U(JSON.parse(e));
|
|
1441
|
+
} catch (e) {
|
|
1442
|
+
if (e instanceof z) throw e;
|
|
1443
|
+
return H("Invalid stream JSON line.");
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
function c(e) {
|
|
1447
|
+
if (o) throw new z("STREAM_CLOSED", "Stream decoder is closed.");
|
|
1448
|
+
let c = typeof e == "string" ? r.encode(e) : e;
|
|
1449
|
+
if (a += c.byteLength, a > t.maxTotalBytes) throw new z("STREAM_LIMIT_EXCEEDED", "Stream exceeds total byte limit.");
|
|
1450
|
+
try {
|
|
1451
|
+
i += n.decode(c, { stream: !0 });
|
|
1452
|
+
} catch {
|
|
1453
|
+
return H("Invalid UTF-8 stream chunk.");
|
|
1454
|
+
}
|
|
1455
|
+
let l = [], u = 0, d = i.indexOf("\n", u);
|
|
1456
|
+
for (; d >= 0;) {
|
|
1457
|
+
let e = s(i.slice(u, d));
|
|
1458
|
+
e && l.push(e), u = d + 1, d = i.indexOf("\n", u);
|
|
1459
|
+
}
|
|
1460
|
+
if (i = i.slice(u), r.encode(i).byteLength > t.maxEventBytes) throw new z("STREAM_LIMIT_EXCEEDED", "Incomplete stream event exceeds byte limit.");
|
|
1461
|
+
return l;
|
|
1462
|
+
}
|
|
1463
|
+
function l() {
|
|
1464
|
+
if (o) throw new z("STREAM_CLOSED", "Stream decoder is closed.");
|
|
1465
|
+
o = !0;
|
|
1466
|
+
try {
|
|
1467
|
+
i += n.decode();
|
|
1468
|
+
} catch {
|
|
1469
|
+
return H("Incomplete UTF-8 sequence.");
|
|
1470
|
+
}
|
|
1471
|
+
if (i.trim()) throw new z("STREAM_INCOMPLETE", "Stream ends with an incomplete event line.");
|
|
1472
|
+
return [];
|
|
1473
|
+
}
|
|
1474
|
+
return {
|
|
1475
|
+
push: c,
|
|
1476
|
+
finish: l
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
function Je(e) {
|
|
1480
|
+
let t = {
|
|
1481
|
+
...B,
|
|
1482
|
+
...e.limits
|
|
1483
|
+
}, n = E(), r = [], i = [], a = [], o = /* @__PURE__ */ new Map(), s = "", c = 0, l = 0, u = 0, d = !1;
|
|
1484
|
+
function f(f) {
|
|
1485
|
+
let p = U(f);
|
|
1486
|
+
if (p.streamId !== e.streamId) return H("Event belongs to a different stream.");
|
|
1487
|
+
let m = JSON.stringify(p);
|
|
1488
|
+
if (p.seq <= c) {
|
|
1489
|
+
if (o.get(p.seq) === m) return;
|
|
1490
|
+
throw new z("STREAM_SEQUENCE_ERROR", "Conflicting retransmitted event.");
|
|
1491
|
+
}
|
|
1492
|
+
if (d) throw new z("STREAM_CLOSED", "Stream already ended.");
|
|
1493
|
+
if (p.seq !== c + 1) throw new z("STREAM_SEQUENCE_ERROR", "Stream sequence has a gap.");
|
|
1494
|
+
if (p.seq > t.maxEvents) throw new z("STREAM_LIMIT_EXCEEDED", "Stream event count exceeded.");
|
|
1495
|
+
switch (p.type) {
|
|
1496
|
+
case "node.open": {
|
|
1497
|
+
let r = p.payload;
|
|
1498
|
+
if (e.mode === "replaceText" || e.mode === "operations") return H("Nodes are not allowed in this stream mode.");
|
|
1499
|
+
if (++l > t.maxNodes || i.length >= t.maxDepth) throw new z("STREAM_LIMIT_EXCEEDED", "Stream node or depth limit exceeded.");
|
|
1500
|
+
let a = r.nodeType;
|
|
1501
|
+
if (!n.nodes[a] || a === "doc" || a === "text") return H(`Unknown or unsupported node type: ${a}.`);
|
|
1502
|
+
let o = r.nodeRef;
|
|
1503
|
+
if (i.some((e) => e.ref === o)) return H("Duplicate open nodeRef.");
|
|
1504
|
+
i.push({
|
|
1505
|
+
ref: o,
|
|
1506
|
+
node: {
|
|
1507
|
+
type: a,
|
|
1508
|
+
...r.attrs ? { attrs: r.attrs } : {},
|
|
1509
|
+
content: []
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
break;
|
|
1513
|
+
}
|
|
1514
|
+
case "text.delta": {
|
|
1515
|
+
let n = p.payload, r = n.text;
|
|
1516
|
+
if (u += r.length, u > t.maxTextLength) throw new z("STREAM_LIMIT_EXCEEDED", "Stream text limit exceeded.");
|
|
1517
|
+
if (e.mode === "replaceText") {
|
|
1518
|
+
if (n.nodeRef && n.nodeRef !== "replacement") return H("replaceText accepts only the replacement slot.");
|
|
1519
|
+
s += r;
|
|
1520
|
+
break;
|
|
1521
|
+
}
|
|
1522
|
+
let a = i[i.length - 1];
|
|
1523
|
+
if (!a || n.nodeRef && n.nodeRef !== a.ref) return H("Text target is not the current open node.");
|
|
1524
|
+
let o = n.marks, c = a.node.content?.[a.node.content.length - 1];
|
|
1525
|
+
c?.type === "text" && JSON.stringify(c.marks ?? []) === JSON.stringify(o ?? []) ? c.text = (c.text ?? "") + r : a.node.content?.push({
|
|
1526
|
+
type: "text",
|
|
1527
|
+
text: r,
|
|
1528
|
+
...o ? { marks: o } : {}
|
|
1529
|
+
});
|
|
1530
|
+
break;
|
|
1531
|
+
}
|
|
1532
|
+
case "node.attrs": {
|
|
1533
|
+
let e = p.payload, t = i[i.length - 1];
|
|
1534
|
+
if (!t || t.ref !== e.nodeRef) return H("Attribute target is not the current open node.");
|
|
1535
|
+
let r = n.nodes[t.node.type].spec.attrs ?? {};
|
|
1536
|
+
if (Object.entries(e.attrs).some(([e, n]) => !Object.prototype.hasOwnProperty.call(r, e) || !k(t.node.type, e, n))) return H("Invalid node attributes.");
|
|
1537
|
+
t.node.attrs = {
|
|
1538
|
+
...t.node.attrs,
|
|
1539
|
+
...e.attrs
|
|
1540
|
+
};
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
case "node.close": {
|
|
1544
|
+
let e = p.payload, t = i[i.length - 1];
|
|
1545
|
+
if (!t || t.ref !== e.nodeRef) return H("Nodes must close in stack order.");
|
|
1546
|
+
let a = t.node.content?.length ? t.node : {
|
|
1547
|
+
...t.node,
|
|
1548
|
+
content: void 0
|
|
1549
|
+
};
|
|
1550
|
+
try {
|
|
1551
|
+
n.nodeFromJSON(a).check();
|
|
1552
|
+
} catch {
|
|
1553
|
+
return H("Closed node is not valid under the editor schema.");
|
|
1554
|
+
}
|
|
1555
|
+
i.pop();
|
|
1556
|
+
let o = i[i.length - 1];
|
|
1557
|
+
o ? o.node.content?.push(a) : r.push(a);
|
|
1558
|
+
break;
|
|
1559
|
+
}
|
|
1560
|
+
case "operation": {
|
|
1561
|
+
let n = p.payload;
|
|
1562
|
+
if (e.mode !== "operations") return H("Operation event is not allowed in this stream mode.");
|
|
1563
|
+
if (a.length >= t.maxOperations) throw new z("STREAM_LIMIT_EXCEEDED", "Stream operation limit exceeded.");
|
|
1564
|
+
a.push(n.operation);
|
|
1565
|
+
break;
|
|
1566
|
+
}
|
|
1567
|
+
case "stream.end":
|
|
1568
|
+
if (i.length) throw new z("STREAM_INCOMPLETE", "Nodes remain open at stream.end.");
|
|
1569
|
+
if (e.mode === "createDocument") {
|
|
1570
|
+
let e = N({
|
|
1571
|
+
type: "doc",
|
|
1572
|
+
content: r
|
|
1573
|
+
});
|
|
1574
|
+
if (!e.valid) return H(e.errors[0]?.message ?? "Invalid generated document.");
|
|
1575
|
+
}
|
|
1576
|
+
d = !0;
|
|
1577
|
+
}
|
|
1578
|
+
c = p.seq, o.set(c, m);
|
|
1579
|
+
}
|
|
1580
|
+
function p(e) {
|
|
1581
|
+
return f(e), h();
|
|
1582
|
+
}
|
|
1583
|
+
function m(e) {
|
|
1584
|
+
return f(e), {
|
|
1585
|
+
seq: c,
|
|
1586
|
+
ended: d
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
function h() {
|
|
1590
|
+
return {
|
|
1591
|
+
committed: !1,
|
|
1592
|
+
streamId: e.streamId,
|
|
1593
|
+
mode: e.mode,
|
|
1594
|
+
seq: c,
|
|
1595
|
+
ended: d,
|
|
1596
|
+
nodes: structuredClone(r),
|
|
1597
|
+
openNodes: structuredClone(i.map((e) => e.node)),
|
|
1598
|
+
replacementText: s,
|
|
1599
|
+
operations: structuredClone(a)
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
function ee() {
|
|
1603
|
+
if (!d) throw new z("STREAM_INCOMPLETE", "Stream has not ended.");
|
|
1604
|
+
return h();
|
|
1605
|
+
}
|
|
1606
|
+
return {
|
|
1607
|
+
append: p,
|
|
1608
|
+
appendFast: m,
|
|
1609
|
+
snapshot: h,
|
|
1610
|
+
result: ee,
|
|
1611
|
+
currentNodeType: () => i[i.length - 1]?.node.type
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
//#endregion
|
|
1615
|
+
//#region src/ai-protocol/json-schema.ts
|
|
1616
|
+
function Ye(e, t, n) {
|
|
1617
|
+
let r = e === null, i = (e) => r ? [e, "null"] : e;
|
|
1618
|
+
return t === "images" && n === "imageBlock" ? {
|
|
1619
|
+
type: "array",
|
|
1620
|
+
maxItems: 4,
|
|
1621
|
+
items: {
|
|
1622
|
+
type: "object",
|
|
1623
|
+
additionalProperties: !1,
|
|
1624
|
+
properties: {
|
|
1625
|
+
id: {
|
|
1626
|
+
type: "string",
|
|
1627
|
+
minLength: 1
|
|
1628
|
+
},
|
|
1629
|
+
assetId: {
|
|
1630
|
+
type: "string",
|
|
1631
|
+
minLength: 1
|
|
1632
|
+
},
|
|
1633
|
+
src: { type: "string" },
|
|
1634
|
+
alt: { type: "string" },
|
|
1635
|
+
name: { type: "string" },
|
|
1636
|
+
description: { type: "string" },
|
|
1637
|
+
descriptionVisible: { type: "boolean" },
|
|
1638
|
+
link: { type: "string" },
|
|
1639
|
+
linkTarget: { enum: ["_blank", "_self"] },
|
|
1640
|
+
rotation: { type: "number" }
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
} : t === "indent" ? {
|
|
1644
|
+
type: i("integer"),
|
|
1645
|
+
minimum: 0,
|
|
1646
|
+
maximum: 8
|
|
1647
|
+
} : t === "level" ? {
|
|
1648
|
+
type: i("integer"),
|
|
1649
|
+
minimum: 1,
|
|
1650
|
+
maximum: 6
|
|
1651
|
+
} : t === "align" || t === "textAlign" ? { enum: [
|
|
1652
|
+
"left",
|
|
1653
|
+
"center",
|
|
1654
|
+
"right",
|
|
1655
|
+
...r ? [null] : []
|
|
1656
|
+
] } : t === "colwidth" ? {
|
|
1657
|
+
type: ["array", "null"],
|
|
1658
|
+
items: {
|
|
1659
|
+
type: "integer",
|
|
1660
|
+
minimum: 1
|
|
1661
|
+
},
|
|
1662
|
+
minItems: 1
|
|
1663
|
+
} : t === "type" && n === "orderedList" ? { enum: [
|
|
1664
|
+
"1",
|
|
1665
|
+
"a",
|
|
1666
|
+
"A",
|
|
1667
|
+
"i",
|
|
1668
|
+
"I",
|
|
1669
|
+
null
|
|
1670
|
+
] } : t === "displayMode" && n === "linkBlock" ? { enum: [
|
|
1671
|
+
"text",
|
|
1672
|
+
"card",
|
|
1673
|
+
"preview"
|
|
1674
|
+
] } : t === "lineStyle" && n === "horizontalRule" ? { enum: [
|
|
1675
|
+
"solid",
|
|
1676
|
+
"dashed",
|
|
1677
|
+
"dotted"
|
|
1678
|
+
] } : t === "widthPercent" ? {
|
|
1679
|
+
type: i("number"),
|
|
1680
|
+
exclusiveMinimum: 0,
|
|
1681
|
+
maximum: 100
|
|
1682
|
+
} : [
|
|
1683
|
+
"height",
|
|
1684
|
+
"size",
|
|
1685
|
+
"targetTimestamp"
|
|
1686
|
+
].includes(t) ? {
|
|
1687
|
+
type: i("integer"),
|
|
1688
|
+
minimum: 0
|
|
1689
|
+
} : [
|
|
1690
|
+
"colspan",
|
|
1691
|
+
"rowspan",
|
|
1692
|
+
"start"
|
|
1693
|
+
].includes(t) ? {
|
|
1694
|
+
type: i("integer"),
|
|
1695
|
+
minimum: 1
|
|
1696
|
+
} : t === "fontSize" ? {
|
|
1697
|
+
type: i("string"),
|
|
1698
|
+
pattern: "^\\d{1,3}px$"
|
|
1699
|
+
} : /color$/i.test(t) || t === "backgroundColor" ? {
|
|
1700
|
+
type: i("string"),
|
|
1701
|
+
maxLength: 80,
|
|
1702
|
+
pattern: "^(?:#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgba?\\([\\d.%\\s,/]+\\)|[a-zA-Z]+)$"
|
|
1703
|
+
} : t === "widths" ? {
|
|
1704
|
+
type: i("array"),
|
|
1705
|
+
items: {
|
|
1706
|
+
type: "number",
|
|
1707
|
+
exclusiveMinimum: 0
|
|
1708
|
+
}
|
|
1709
|
+
} : t === "tableTheme" ? { anyOf: [{ type: "null" }, {
|
|
1710
|
+
type: "object",
|
|
1711
|
+
required: [
|
|
1712
|
+
"header",
|
|
1713
|
+
"odd",
|
|
1714
|
+
"even"
|
|
1715
|
+
],
|
|
1716
|
+
additionalProperties: !1,
|
|
1717
|
+
properties: Object.fromEntries([
|
|
1718
|
+
"header",
|
|
1719
|
+
"odd",
|
|
1720
|
+
"even"
|
|
1721
|
+
].map((e) => [e, {
|
|
1722
|
+
type: "string",
|
|
1723
|
+
pattern: "^#[0-9a-fA-F]{6}$"
|
|
1724
|
+
}]))
|
|
1725
|
+
}] } : Array.isArray(e) ? { type: "array" } : e === null ? { type: ["string", "null"] } : e === void 0 ? {} : typeof e == "object" ? { type: "object" } : typeof e == "number" ? { type: "number" } : { type: typeof e };
|
|
1726
|
+
}
|
|
1727
|
+
function Xe(e, t) {
|
|
1728
|
+
if (!e || !Object.keys(e).length) return;
|
|
1729
|
+
let n = {}, r = [];
|
|
1730
|
+
for (let [i, a] of Object.entries(e)) n[i] = Ye(a.default, i, t), a.default === void 0 && r.push(i);
|
|
1731
|
+
return {
|
|
1732
|
+
type: "object",
|
|
1733
|
+
properties: n,
|
|
1734
|
+
additionalProperties: !1,
|
|
1735
|
+
...r.length ? { required: r } : {}
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
function W() {
|
|
1739
|
+
let e = E(), t = {}, n = [], r = [];
|
|
1740
|
+
return e.spec.marks.forEach((e, n) => {
|
|
1741
|
+
let i = Xe(n.attrs, e);
|
|
1742
|
+
t[`mark_${e}`] = {
|
|
1743
|
+
type: "object",
|
|
1744
|
+
properties: {
|
|
1745
|
+
type: { const: e },
|
|
1746
|
+
...i ? { attrs: i } : {}
|
|
1747
|
+
},
|
|
1748
|
+
required: ["type"],
|
|
1749
|
+
additionalProperties: !1
|
|
1750
|
+
}, r.push({ $ref: `#/$defs/mark_${e}` });
|
|
1751
|
+
}), e.spec.nodes.forEach((e, r) => {
|
|
1752
|
+
let i = Xe(r.attrs, e), a = { type: { const: e } };
|
|
1753
|
+
i && (a.attrs = i), e === "text" ? a.text = {
|
|
1754
|
+
type: "string",
|
|
1755
|
+
minLength: 1
|
|
1756
|
+
} : r.content && (a.content = {
|
|
1757
|
+
type: "array",
|
|
1758
|
+
items: { $ref: "#/$defs/node" }
|
|
1759
|
+
}), e !== "doc" && (a.marks = {
|
|
1760
|
+
type: "array",
|
|
1761
|
+
items: { $ref: "#/$defs/mark" }
|
|
1762
|
+
}), t[`node_${e}`] = {
|
|
1763
|
+
type: "object",
|
|
1764
|
+
properties: a,
|
|
1765
|
+
required: e === "text" ? ["type", "text"] : ["type"],
|
|
1766
|
+
additionalProperties: !1
|
|
1767
|
+
}, n.push({ $ref: `#/$defs/node_${e}` });
|
|
1768
|
+
}), t.node = { oneOf: n }, t.mark = { oneOf: r }, {
|
|
1769
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1770
|
+
$id: "https://norio-office.github.io/rich-text/document.schema.json",
|
|
1771
|
+
title: "Norio rich text document",
|
|
1772
|
+
$ref: "#/$defs/node_doc",
|
|
1773
|
+
$defs: t
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1776
|
+
function Ze(e) {
|
|
1777
|
+
let t = {}, n = [];
|
|
1778
|
+
for (let [r, i] of Object.entries(e)) {
|
|
1779
|
+
if (!r.startsWith("node_") || r === "node") continue;
|
|
1780
|
+
let e = { ...i.properties };
|
|
1781
|
+
if (e.attrs) {
|
|
1782
|
+
let t = e.attrs, n = { ...t.properties };
|
|
1783
|
+
delete n.aiId, e.attrs = {
|
|
1784
|
+
...t,
|
|
1785
|
+
properties: n
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
e.content &&= {
|
|
1789
|
+
...e.content,
|
|
1790
|
+
items: { $ref: "#/$defs/new_node" }
|
|
1791
|
+
}, t[`new_${r}`] = {
|
|
1792
|
+
...i,
|
|
1793
|
+
properties: e
|
|
1794
|
+
}, n.push({ $ref: `#/$defs/new_${r}` });
|
|
1795
|
+
}
|
|
1796
|
+
return t.new_node = { oneOf: n }, t;
|
|
1797
|
+
}
|
|
1798
|
+
function Qe() {
|
|
1799
|
+
let e = W(), t = e.$defs;
|
|
1800
|
+
return {
|
|
1801
|
+
...e,
|
|
1802
|
+
$id: "https://norio-office.github.io/rich-text/ai-created-document.schema.json",
|
|
1803
|
+
title: "Norio AI-created rich text document",
|
|
1804
|
+
$ref: "#/$defs/new_node_doc",
|
|
1805
|
+
$defs: {
|
|
1806
|
+
...t,
|
|
1807
|
+
...Ze(t)
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
function G() {
|
|
1812
|
+
let e = W().$defs, t = Ze(e), n = {
|
|
1813
|
+
type: "string",
|
|
1814
|
+
minLength: 1
|
|
1815
|
+
}, r = {
|
|
1816
|
+
type: "array",
|
|
1817
|
+
minItems: 1,
|
|
1818
|
+
items: { $ref: "#/$defs/new_node" }
|
|
1819
|
+
}, i = {
|
|
1820
|
+
type: "array",
|
|
1821
|
+
minItems: 1,
|
|
1822
|
+
items: {
|
|
1823
|
+
type: "string",
|
|
1824
|
+
minLength: 1
|
|
1825
|
+
}
|
|
1826
|
+
}, a = {
|
|
1827
|
+
type: "object",
|
|
1828
|
+
not: { required: ["aiId"] }
|
|
1829
|
+
}, o = {
|
|
1830
|
+
insertContent: {
|
|
1831
|
+
properties: {
|
|
1832
|
+
position: { enum: [
|
|
1833
|
+
"at",
|
|
1834
|
+
"before",
|
|
1835
|
+
"after"
|
|
1836
|
+
] },
|
|
1837
|
+
content: r
|
|
1838
|
+
},
|
|
1839
|
+
required: ["position", "content"]
|
|
1840
|
+
},
|
|
1841
|
+
replaceText: {
|
|
1842
|
+
properties: { text: { type: "string" } },
|
|
1843
|
+
required: ["text"]
|
|
1844
|
+
},
|
|
1845
|
+
replaceFragment: {
|
|
1846
|
+
properties: { content: r },
|
|
1847
|
+
required: ["content"]
|
|
1848
|
+
},
|
|
1849
|
+
setMarks: {
|
|
1850
|
+
properties: { marks: {
|
|
1851
|
+
type: "array",
|
|
1852
|
+
minItems: 1,
|
|
1853
|
+
items: { $ref: "#/$defs/mark" }
|
|
1854
|
+
} },
|
|
1855
|
+
required: ["marks"]
|
|
1856
|
+
},
|
|
1857
|
+
unsetMarks: {
|
|
1858
|
+
properties: { markTypes: i },
|
|
1859
|
+
required: ["markTypes"]
|
|
1860
|
+
},
|
|
1861
|
+
setNodeAttributes: {
|
|
1862
|
+
properties: {
|
|
1863
|
+
nodeType: { type: "string" },
|
|
1864
|
+
attrs: a
|
|
1865
|
+
},
|
|
1866
|
+
required: ["nodeType", "attrs"]
|
|
1867
|
+
},
|
|
1868
|
+
unsetNodeAttributes: {
|
|
1869
|
+
properties: {
|
|
1870
|
+
nodeType: { type: "string" },
|
|
1871
|
+
attributes: {
|
|
1872
|
+
type: "array",
|
|
1873
|
+
minItems: 1,
|
|
1874
|
+
items: {
|
|
1875
|
+
type: "string",
|
|
1876
|
+
minLength: 1,
|
|
1877
|
+
not: { const: "aiId" }
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
},
|
|
1881
|
+
required: ["nodeType", "attributes"]
|
|
1882
|
+
},
|
|
1883
|
+
deleteContent: { properties: {} },
|
|
1884
|
+
moveBlocks: {
|
|
1885
|
+
properties: {
|
|
1886
|
+
destinationRef: n,
|
|
1887
|
+
position: { enum: ["before", "after"] }
|
|
1888
|
+
},
|
|
1889
|
+
required: ["destinationRef", "position"]
|
|
1890
|
+
},
|
|
1891
|
+
transformBlocks: {
|
|
1892
|
+
properties: {
|
|
1893
|
+
nodeType: { type: "string" },
|
|
1894
|
+
attrs: a
|
|
1895
|
+
},
|
|
1896
|
+
required: ["nodeType"]
|
|
1897
|
+
},
|
|
1898
|
+
tableOperation: {
|
|
1899
|
+
properties: {
|
|
1900
|
+
action: { enum: [
|
|
1901
|
+
"insertRowBefore",
|
|
1902
|
+
"insertRowAfter",
|
|
1903
|
+
"deleteRow",
|
|
1904
|
+
"insertColumnBefore",
|
|
1905
|
+
"insertColumnAfter",
|
|
1906
|
+
"deleteColumn",
|
|
1907
|
+
"mergeCells",
|
|
1908
|
+
"splitCell",
|
|
1909
|
+
"setCellContent",
|
|
1910
|
+
"setCellBackground",
|
|
1911
|
+
"setTableTheme"
|
|
1912
|
+
] },
|
|
1913
|
+
content: r,
|
|
1914
|
+
value: {}
|
|
1915
|
+
},
|
|
1916
|
+
required: ["action"]
|
|
1917
|
+
}
|
|
1918
|
+
}, s = Object.fromEntries(Object.entries(o).map(([e, t]) => [`operation_${e}`, {
|
|
1919
|
+
type: "object",
|
|
1920
|
+
additionalProperties: !1,
|
|
1921
|
+
required: [
|
|
1922
|
+
"type",
|
|
1923
|
+
"targetRef",
|
|
1924
|
+
...t.required ?? []
|
|
1925
|
+
],
|
|
1926
|
+
properties: {
|
|
1927
|
+
type: { const: e },
|
|
1928
|
+
targetRef: n,
|
|
1929
|
+
...t.properties
|
|
1930
|
+
}
|
|
1931
|
+
}]));
|
|
1932
|
+
return {
|
|
1933
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1934
|
+
$id: "https://norio-office.github.io/rich-text/patch.schema.json",
|
|
1935
|
+
type: "object",
|
|
1936
|
+
required: [
|
|
1937
|
+
"protocolVersion",
|
|
1938
|
+
"documentId",
|
|
1939
|
+
"requestId",
|
|
1940
|
+
"contextId",
|
|
1941
|
+
"baseRevision",
|
|
1942
|
+
"operations"
|
|
1943
|
+
],
|
|
1944
|
+
additionalProperties: !1,
|
|
1945
|
+
properties: {
|
|
1946
|
+
protocolVersion: { const: 1 },
|
|
1947
|
+
documentId: {
|
|
1948
|
+
type: "string",
|
|
1949
|
+
minLength: 1
|
|
1950
|
+
},
|
|
1951
|
+
requestId: {
|
|
1952
|
+
type: "string",
|
|
1953
|
+
minLength: 1
|
|
1954
|
+
},
|
|
1955
|
+
contextId: {
|
|
1956
|
+
type: "string",
|
|
1957
|
+
minLength: 1
|
|
1958
|
+
},
|
|
1959
|
+
baseRevision: {
|
|
1960
|
+
type: "integer",
|
|
1961
|
+
minimum: 0
|
|
1962
|
+
},
|
|
1963
|
+
operations: {
|
|
1964
|
+
type: "array",
|
|
1965
|
+
minItems: 1,
|
|
1966
|
+
maxItems: 500,
|
|
1967
|
+
items: { $ref: "#/$defs/operation" }
|
|
1968
|
+
}
|
|
1969
|
+
},
|
|
1970
|
+
$defs: {
|
|
1971
|
+
...e,
|
|
1972
|
+
...t,
|
|
1973
|
+
...s,
|
|
1974
|
+
operation: { oneOf: Object.keys(o).map((e) => ({ $ref: `#/$defs/operation_${e}` })) }
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
function $e() {
|
|
1979
|
+
let e = G().$defs, t = {
|
|
1980
|
+
type: "string",
|
|
1981
|
+
minLength: 1
|
|
1982
|
+
}, n = {
|
|
1983
|
+
type: "object",
|
|
1984
|
+
not: { required: ["aiId"] }
|
|
1985
|
+
}, r = {
|
|
1986
|
+
"node.open": {
|
|
1987
|
+
properties: {
|
|
1988
|
+
nodeRef: t,
|
|
1989
|
+
nodeType: t,
|
|
1990
|
+
attrs: n
|
|
1991
|
+
},
|
|
1992
|
+
required: ["nodeRef", "nodeType"]
|
|
1993
|
+
},
|
|
1994
|
+
"text.delta": {
|
|
1995
|
+
properties: {
|
|
1996
|
+
nodeRef: t,
|
|
1997
|
+
text: t,
|
|
1998
|
+
marks: {
|
|
1999
|
+
type: "array",
|
|
2000
|
+
items: { $ref: "#/$defs/mark" }
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
required: ["text"]
|
|
2004
|
+
},
|
|
2005
|
+
"node.attrs": {
|
|
2006
|
+
properties: {
|
|
2007
|
+
nodeRef: t,
|
|
2008
|
+
attrs: n
|
|
2009
|
+
},
|
|
2010
|
+
required: ["nodeRef", "attrs"]
|
|
2011
|
+
},
|
|
2012
|
+
"node.close": {
|
|
2013
|
+
properties: { nodeRef: t },
|
|
2014
|
+
required: ["nodeRef"]
|
|
2015
|
+
},
|
|
2016
|
+
operation: {
|
|
2017
|
+
properties: { operation: { $ref: "#/$defs/operation" } },
|
|
2018
|
+
required: ["operation"]
|
|
2019
|
+
},
|
|
2020
|
+
"stream.end": { properties: {} }
|
|
2021
|
+
}, i = Object.fromEntries(Object.entries(r).map(([e, n]) => [`event_${e.replace(".", "_")}`, {
|
|
2022
|
+
type: "object",
|
|
2023
|
+
additionalProperties: !1,
|
|
2024
|
+
required: [
|
|
2025
|
+
"protocolVersion",
|
|
2026
|
+
"streamId",
|
|
2027
|
+
"seq",
|
|
2028
|
+
"type",
|
|
2029
|
+
"payload"
|
|
2030
|
+
],
|
|
2031
|
+
properties: {
|
|
2032
|
+
protocolVersion: { const: 1 },
|
|
2033
|
+
streamId: t,
|
|
2034
|
+
seq: {
|
|
2035
|
+
type: "integer",
|
|
2036
|
+
minimum: 1
|
|
2037
|
+
},
|
|
2038
|
+
type: { const: e },
|
|
2039
|
+
payload: {
|
|
2040
|
+
type: "object",
|
|
2041
|
+
additionalProperties: !1,
|
|
2042
|
+
required: n.required ?? [],
|
|
2043
|
+
properties: n.properties
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}]));
|
|
2047
|
+
return {
|
|
2048
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
2049
|
+
$id: "https://norio-office.github.io/rich-text/stream-event.schema.json",
|
|
2050
|
+
oneOf: Object.keys(r).map((e) => ({ $ref: `#/$defs/event_${e.replace(".", "_")}` })),
|
|
2051
|
+
$defs: {
|
|
2052
|
+
...e,
|
|
2053
|
+
...i
|
|
2054
|
+
}
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
//#endregion
|
|
2058
|
+
//#region src/ai-protocol/tools.ts
|
|
2059
|
+
function K(e, t = []) {
|
|
2060
|
+
return {
|
|
2061
|
+
type: "object",
|
|
2062
|
+
properties: e,
|
|
2063
|
+
required: t,
|
|
2064
|
+
additionalProperties: !1
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
var q = { type: "string" }, J = { type: "integer" }, Y = { type: "boolean" }, X = { type: ["string", "null"] }, Z = {
|
|
2068
|
+
type: "array",
|
|
2069
|
+
items: q
|
|
2070
|
+
}, et = { $ref: "#/$defs/node" }, tt = { $ref: "#/$defs/mark" }, nt = K({
|
|
2071
|
+
code: q,
|
|
2072
|
+
message: q,
|
|
2073
|
+
retryable: Y,
|
|
2074
|
+
requiresContextRefresh: Y
|
|
2075
|
+
}, [
|
|
2076
|
+
"code",
|
|
2077
|
+
"message",
|
|
2078
|
+
"retryable",
|
|
2079
|
+
"requiresContextRefresh"
|
|
2080
|
+
]);
|
|
2081
|
+
function Q(e, t = !1) {
|
|
2082
|
+
return {
|
|
2083
|
+
oneOf: [K({
|
|
2084
|
+
ok: { const: !0 },
|
|
2085
|
+
data: e
|
|
2086
|
+
}, ["ok", "data"]), K({
|
|
2087
|
+
ok: { const: !1 },
|
|
2088
|
+
error: nt
|
|
2089
|
+
}, ["ok", "error"])],
|
|
2090
|
+
...t ? { $defs: W().$defs } : {}
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
var rt = K({
|
|
2094
|
+
kind: { enum: [
|
|
2095
|
+
"cursor",
|
|
2096
|
+
"textRange",
|
|
2097
|
+
"node",
|
|
2098
|
+
"blockSet",
|
|
2099
|
+
"tableCells",
|
|
2100
|
+
"none"
|
|
2101
|
+
] },
|
|
2102
|
+
from: J,
|
|
2103
|
+
to: J,
|
|
2104
|
+
text: q,
|
|
2105
|
+
direction: { enum: ["forward", "backward"] },
|
|
2106
|
+
markRanges: {
|
|
2107
|
+
type: "array",
|
|
2108
|
+
items: K({
|
|
2109
|
+
from: J,
|
|
2110
|
+
to: J,
|
|
2111
|
+
marks: {
|
|
2112
|
+
type: "array",
|
|
2113
|
+
items: tt
|
|
2114
|
+
}
|
|
2115
|
+
}, ["from", "to"])
|
|
2116
|
+
},
|
|
2117
|
+
node: et,
|
|
2118
|
+
blocks: {
|
|
2119
|
+
type: "array",
|
|
2120
|
+
items: K({
|
|
2121
|
+
from: J,
|
|
2122
|
+
to: J,
|
|
2123
|
+
nodeId: X
|
|
2124
|
+
}, ["from", "to"])
|
|
2125
|
+
},
|
|
2126
|
+
cells: {
|
|
2127
|
+
type: "array",
|
|
2128
|
+
items: K({
|
|
2129
|
+
from: J,
|
|
2130
|
+
to: J,
|
|
2131
|
+
nodeId: X,
|
|
2132
|
+
row: J,
|
|
2133
|
+
column: J
|
|
2134
|
+
}, ["from", "to"])
|
|
2135
|
+
},
|
|
2136
|
+
tableId: X,
|
|
2137
|
+
anchorCell: J,
|
|
2138
|
+
headCell: J,
|
|
2139
|
+
revision: J
|
|
2140
|
+
}, ["kind", "revision"]), $ = K({
|
|
2141
|
+
documentId: q,
|
|
2142
|
+
revision: J,
|
|
2143
|
+
results: {
|
|
2144
|
+
type: "array",
|
|
2145
|
+
items: K({
|
|
2146
|
+
targetRef: q,
|
|
2147
|
+
kind: q,
|
|
2148
|
+
text: q,
|
|
2149
|
+
truncated: Y,
|
|
2150
|
+
nodeType: q,
|
|
2151
|
+
parentRef: q,
|
|
2152
|
+
tableRow: J,
|
|
2153
|
+
tableColumn: J,
|
|
2154
|
+
isHeader: Y,
|
|
2155
|
+
operations: Z,
|
|
2156
|
+
tableActions: Z,
|
|
2157
|
+
content: { anyOf: [{ type: "null" }, K({
|
|
2158
|
+
content: {
|
|
2159
|
+
type: "array",
|
|
2160
|
+
items: et
|
|
2161
|
+
},
|
|
2162
|
+
openStart: J,
|
|
2163
|
+
openEnd: J
|
|
2164
|
+
}, ["content"])] },
|
|
2165
|
+
nextCursor: X,
|
|
2166
|
+
neighbors: K({
|
|
2167
|
+
before: X,
|
|
2168
|
+
after: X
|
|
2169
|
+
}, ["before", "after"])
|
|
2170
|
+
}, [
|
|
2171
|
+
"targetRef",
|
|
2172
|
+
"kind",
|
|
2173
|
+
"text",
|
|
2174
|
+
"truncated",
|
|
2175
|
+
"content",
|
|
2176
|
+
"nextCursor"
|
|
2177
|
+
])
|
|
2178
|
+
},
|
|
2179
|
+
truncated: Y
|
|
2180
|
+
}, [
|
|
2181
|
+
"documentId",
|
|
2182
|
+
"revision",
|
|
2183
|
+
"results",
|
|
2184
|
+
"truncated"
|
|
2185
|
+
]), it = K({
|
|
2186
|
+
schemaVersion: q,
|
|
2187
|
+
protocolVersion: J,
|
|
2188
|
+
streamProtocolVersion: J,
|
|
2189
|
+
documentId: q,
|
|
2190
|
+
mode: { enum: ["edit", "preview"] },
|
|
2191
|
+
collaboration: Y,
|
|
2192
|
+
nodes: Z,
|
|
2193
|
+
marks: Z,
|
|
2194
|
+
nodeAttributes: { type: "object" },
|
|
2195
|
+
markAttributes: { type: "object" },
|
|
2196
|
+
nodeAttributeConstraints: { type: "object" },
|
|
2197
|
+
markAttributeConstraints: { type: "object" },
|
|
2198
|
+
nodeContentRules: { type: "object" },
|
|
2199
|
+
targetKinds: Z,
|
|
2200
|
+
externalDependencies: K({
|
|
2201
|
+
authorizationConfigured: Y,
|
|
2202
|
+
byteResolverConfigured: Y,
|
|
2203
|
+
media: q,
|
|
2204
|
+
mentions: q,
|
|
2205
|
+
comments: q,
|
|
2206
|
+
embedding: q
|
|
2207
|
+
}, [
|
|
2208
|
+
"authorizationConfigured",
|
|
2209
|
+
"byteResolverConfigured",
|
|
2210
|
+
"media",
|
|
2211
|
+
"mentions",
|
|
2212
|
+
"comments",
|
|
2213
|
+
"embedding"
|
|
2214
|
+
]),
|
|
2215
|
+
resourcePackaging: K({
|
|
2216
|
+
images: Z,
|
|
2217
|
+
videos: Z,
|
|
2218
|
+
files: Z
|
|
2219
|
+
}, [
|
|
2220
|
+
"images",
|
|
2221
|
+
"videos",
|
|
2222
|
+
"files"
|
|
2223
|
+
]),
|
|
2224
|
+
operations: Z,
|
|
2225
|
+
streamModes: Z,
|
|
2226
|
+
streamEvents: Z,
|
|
2227
|
+
streamLimits: { type: "object" },
|
|
2228
|
+
streamPreview: K({
|
|
2229
|
+
localOnly: Y,
|
|
2230
|
+
committedDocumentUnchangedUntilCommit: Y
|
|
2231
|
+
}, ["localOnly", "committedDocumentUnchangedUntilCommit"]),
|
|
2232
|
+
commitSemantics: q
|
|
2233
|
+
}, [
|
|
2234
|
+
"schemaVersion",
|
|
2235
|
+
"protocolVersion",
|
|
2236
|
+
"streamProtocolVersion",
|
|
2237
|
+
"documentId",
|
|
2238
|
+
"mode",
|
|
2239
|
+
"collaboration",
|
|
2240
|
+
"nodes",
|
|
2241
|
+
"marks",
|
|
2242
|
+
"nodeAttributes",
|
|
2243
|
+
"markAttributes",
|
|
2244
|
+
"nodeAttributeConstraints",
|
|
2245
|
+
"markAttributeConstraints",
|
|
2246
|
+
"nodeContentRules",
|
|
2247
|
+
"targetKinds",
|
|
2248
|
+
"externalDependencies",
|
|
2249
|
+
"resourcePackaging",
|
|
2250
|
+
"operations",
|
|
2251
|
+
"streamModes",
|
|
2252
|
+
"streamEvents",
|
|
2253
|
+
"streamLimits",
|
|
2254
|
+
"streamPreview",
|
|
2255
|
+
"commitSemantics"
|
|
2256
|
+
]);
|
|
2257
|
+
function at() {
|
|
2258
|
+
return [
|
|
2259
|
+
{
|
|
2260
|
+
name: "richtext_get_capabilities",
|
|
2261
|
+
description: "Get the editor schema, supported operations, modes, and limits.",
|
|
2262
|
+
inputSchema: K({}),
|
|
2263
|
+
outputSchema: Q(it)
|
|
2264
|
+
},
|
|
2265
|
+
{
|
|
2266
|
+
name: "richtext_create_document",
|
|
2267
|
+
description: "Validate native rich text and ask the host to save a new Nordox document.",
|
|
2268
|
+
inputSchema: K({
|
|
2269
|
+
title: { type: "string" },
|
|
2270
|
+
document: Qe()
|
|
2271
|
+
}, ["document"]),
|
|
2272
|
+
outputSchema: Q(K({
|
|
2273
|
+
documentId: q,
|
|
2274
|
+
name: q,
|
|
2275
|
+
byteLength: J,
|
|
2276
|
+
format: { const: "nordox" }
|
|
2277
|
+
}, [
|
|
2278
|
+
"documentId",
|
|
2279
|
+
"byteLength",
|
|
2280
|
+
"format"
|
|
2281
|
+
]))
|
|
2282
|
+
},
|
|
2283
|
+
{
|
|
2284
|
+
name: "richtext_read_document",
|
|
2285
|
+
description: "Read an authorized document within a character budget.",
|
|
2286
|
+
inputSchema: K({
|
|
2287
|
+
contextId: { type: "string" },
|
|
2288
|
+
budget: {
|
|
2289
|
+
type: "integer",
|
|
2290
|
+
minimum: 1,
|
|
2291
|
+
maximum: 12e3
|
|
2292
|
+
},
|
|
2293
|
+
cursor: { type: "string" }
|
|
2294
|
+
}, ["contextId"]),
|
|
2295
|
+
outputSchema: Q({
|
|
2296
|
+
...$,
|
|
2297
|
+
properties: {
|
|
2298
|
+
...$.properties,
|
|
2299
|
+
outline: K({
|
|
2300
|
+
documentId: q,
|
|
2301
|
+
revision: J,
|
|
2302
|
+
blocks: {
|
|
2303
|
+
type: "array",
|
|
2304
|
+
items: K({
|
|
2305
|
+
aiId: X,
|
|
2306
|
+
nodeType: q,
|
|
2307
|
+
level: { type: ["integer", "null"] },
|
|
2308
|
+
text: q
|
|
2309
|
+
}, [
|
|
2310
|
+
"aiId",
|
|
2311
|
+
"nodeType",
|
|
2312
|
+
"level",
|
|
2313
|
+
"text"
|
|
2314
|
+
])
|
|
2315
|
+
},
|
|
2316
|
+
truncated: Y
|
|
2317
|
+
}, [
|
|
2318
|
+
"documentId",
|
|
2319
|
+
"revision",
|
|
2320
|
+
"blocks",
|
|
2321
|
+
"truncated"
|
|
2322
|
+
])
|
|
2323
|
+
},
|
|
2324
|
+
required: [...$.required, "outline"]
|
|
2325
|
+
}, !0)
|
|
2326
|
+
},
|
|
2327
|
+
{
|
|
2328
|
+
name: "richtext_get_selection",
|
|
2329
|
+
description: "Read the selection captured for an authorized edit context.",
|
|
2330
|
+
inputSchema: K({ contextId: { type: "string" } }, ["contextId"]),
|
|
2331
|
+
outputSchema: Q(rt, !0)
|
|
2332
|
+
},
|
|
2333
|
+
{
|
|
2334
|
+
name: "richtext_read_target",
|
|
2335
|
+
description: "Read authorized targets and nearby context.",
|
|
2336
|
+
inputSchema: K({
|
|
2337
|
+
contextId: { type: "string" },
|
|
2338
|
+
targetRefs: {
|
|
2339
|
+
type: "array",
|
|
2340
|
+
items: { type: "string" }
|
|
2341
|
+
},
|
|
2342
|
+
budget: {
|
|
2343
|
+
type: "integer",
|
|
2344
|
+
minimum: 1,
|
|
2345
|
+
maximum: 12e3
|
|
2346
|
+
},
|
|
2347
|
+
cursor: { type: "string" }
|
|
2348
|
+
}, ["contextId", "targetRefs"]),
|
|
2349
|
+
outputSchema: Q($, !0)
|
|
2350
|
+
},
|
|
2351
|
+
{
|
|
2352
|
+
name: "richtext_apply_patch",
|
|
2353
|
+
description: "Validate and atomically apply a local patch to the bound editor session.",
|
|
2354
|
+
inputSchema: G(),
|
|
2355
|
+
outputSchema: Q(K({
|
|
2356
|
+
requestId: q,
|
|
2357
|
+
previousRevision: J,
|
|
2358
|
+
revision: J,
|
|
2359
|
+
changed: Y,
|
|
2360
|
+
targetRefs: Z
|
|
2361
|
+
}, [
|
|
2362
|
+
"requestId",
|
|
2363
|
+
"previousRevision",
|
|
2364
|
+
"revision",
|
|
2365
|
+
"changed",
|
|
2366
|
+
"targetRefs"
|
|
2367
|
+
]))
|
|
2368
|
+
}
|
|
2369
|
+
];
|
|
2370
|
+
}
|
|
2371
|
+
//#endregion
|
|
2372
|
+
export { B as DEFAULT_RICH_TEXT_STREAM_LIMITS, ze as RICH_TEXT_SCHEMA_VERSION, Ke as RICH_TEXT_STREAM_PROTOCOL_VERSION, z as RichTextStreamError, Je as createRichTextStreamBuilder, qe as createRichTextStreamDecoder, Qe as getRichTextAiCreatedDocumentJsonSchema, W as getRichTextDocumentJsonSchema, E as getRichTextDocumentSchema, G as getRichTextPatchJsonSchema, $e as getRichTextStreamEventJsonSchema, at as getRichTextToolDefinitions, Ue as migrateRichTextDocument, N as validateRichTextDocument, Ge as validateRichTextPatch, U as validateRichTextStreamEvent };
|