@freecallai/pro 0.0.12 → 0.0.14

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.
Files changed (55) hide show
  1. package/README.md +23 -2
  2. package/dist/{FkpRichText.vue_vue_type_script_setup_true_lang-DiS7CZdc.js → FkpRichText.vue_vue_type_script_setup_true_lang-D-SOdFra.js} +1364 -1349
  3. package/dist/{KnowledgeArea-FGgCcubh.js → KnowledgeArea-ClZoLiaZ.js} +1 -1
  4. package/dist/KnowledgeArea.vue_vue_type_script_setup_true_lang-CoFF-WCe.js +1830 -0
  5. package/dist/{ToolForm-CHmdyhjh.js → ToolForm-BK9epxdr.js} +1 -1
  6. package/dist/agent-prompt-editor/index.js +510 -495
  7. package/dist/agent-prompt-editor/legacy-converter/index.js +2 -2
  8. package/dist/{choice-CUCsR2dN.js → choice-UgePgrSl.js} +1 -1
  9. package/dist/{guard-DgExtfXo.js → guard-DPwe4mCm.js} +1 -0
  10. package/dist/{index-DqJvaPTD.js → index-BIi3k45j.js} +1 -1
  11. package/dist/index-BMHUPL5x.js +5 -0
  12. package/dist/{index-pdr6mUf0.js → index-CaA13lC9.js} +1 -1
  13. package/dist/{index-C54ce9Tn.js → index-ChuzFuNm.js} +1 -1
  14. package/dist/index-DJLfgC4v.js +5 -0
  15. package/dist/{index-dnsGFj0F.js → index-DfKH-RZq.js} +2 -2
  16. package/dist/{index-DaGfiqBX.js → index-DiLMgNEe.js} +1 -1
  17. package/dist/{index-BwZXmefJ.js → index-RHu4JIw7.js} +1 -1
  18. package/dist/{index-DIMONp3g.js → index-v1UD08i6.js} +1 -1
  19. package/dist/index.js +3 -3
  20. package/dist/{inline-BpwAryXp.js → inline-CVF1zEsG.js} +1 -1
  21. package/dist/{knowledge-DIzYk2iM.js → knowledge-DWM6tWnP.js} +1 -1
  22. package/dist/{media-migration-Bnfn27i9.js → media-migration-BctCLEuT.js} +1 -1
  23. package/dist/{media-policy-tG5OHWSj.js → media-policy-B1UuSN2e.js} +1 -1
  24. package/dist/{media-upload-_xeZtn3i.js → media-upload-DtH-oCtw.js} +1 -1
  25. package/dist/{model-DlAjlPai.js → model-VLLhEQfn.js} +1 -1
  26. package/dist/rich-text/index.js +6 -6
  27. package/dist/rich-text/legacy-converter/index.js +2 -2
  28. package/dist/style.css +1 -1
  29. package/dist/types/agent-prompt-editor/FkpAgentPromptEditor.vue.d.ts +33 -2
  30. package/dist/types/agent-prompt-editor/index.d.ts +1 -0
  31. package/dist/types/agent-prompt-editor/types.d.ts +4 -0
  32. package/dist/types/filters/FkpFilter.vue.d.ts +2 -2
  33. package/dist/types/filters/FkpFilterDateRange.vue.d.ts +2 -2
  34. package/dist/types/filters/FkpFilterPeriod.vue.d.ts +2 -2
  35. package/dist/types/filters/FkpSearchableMultiSelect.vue.d.ts +2 -2
  36. package/dist/types/index.d.ts +1 -0
  37. package/dist/types/rich-text/FkpRichText.vue.d.ts +18 -2
  38. package/dist/types/rich-text/index.d.ts +1 -0
  39. package/dist/types/rich-text/plugins/attribute/token.d.ts +1 -0
  40. package/dist/types/rich-text/plugins/tableKnowledge/token.d.ts +1 -0
  41. package/dist/types/rich-text/plugins/ticket/token.d.ts +2 -1
  42. package/dist/types/rich-text/plugins/token-catalog.d.ts +4 -1
  43. package/dist/types/rich-text/plugins/token-definition.d.ts +2 -0
  44. package/dist/types/rich-text/public/types.d.ts +5 -0
  45. package/dist/types/rich-text/runtime/document-adapter.d.ts +3 -0
  46. package/dist/types/rich-text/runtime/tag-validity.d.ts +46 -0
  47. package/dist/types/rich-text/ui/FkpKnowledgeTypePicker.vue.d.ts +2 -2
  48. package/dist/types/rich-text/ui/KnowledgeArea.vue.d.ts +9 -0
  49. package/dist/types/rich-text/ui/MediaSourceControls.vue.d.ts +10 -10
  50. package/dist/types/rich-text/ui/ToolForm.vue.d.ts +2 -2
  51. package/dist/types/switcher/FkpSwitcher.vue.d.ts +2 -2
  52. package/package.json +5 -4
  53. package/dist/KnowledgeArea.vue_vue_type_script_setup_true_lang-JH_F4CFe.js +0 -1663
  54. package/dist/index-CMl5mgFR.js +0 -5
  55. package/dist/index-Cs38tTe4.js +0 -5
@@ -0,0 +1,1830 @@
1
+ import { defineComponent as Ot, shallowRef as Pt, watch as ie, onBeforeUnmount as ve, ref as re, nextTick as He, onMounted as zt, openBlock as G, createElementBlock as W, createVNode as Ke, unref as le, createBlock as Lt, withCtx as Te, createElementVNode as K, normalizeStyle as Se, createCommentVNode as fe, toDisplayString as Ue, createTextVNode as $t } from "vue";
2
+ import { EditorContent as qt, Editor as Ft } from "@tiptap/vue-3";
3
+ import { Popover as Ht, Tag as Kt } from "@freecallai/ui";
4
+ import { PluginKey as Qe, Plugin as Ce, TextSelection as j, NodeSelection as Ut, Selection as _t } from "@tiptap/pm/state";
5
+ import Jt from "@tiptap/starter-kit";
6
+ import Yt from "@tiptap/extension-placeholder";
7
+ import { Extension as Ze, Node as Ee } from "@tiptap/core";
8
+ import { Decoration as pe, DecorationSet as et } from "@tiptap/pm/view";
9
+ import { g as de, d as ce, t as Q, q as Me, r as Xt, c as Gt, u as tt, b as nt, i as ue, v as me, C as jt, w as Wt, x as Qt, y as Zt, z as _e, A as en } from "./guard-DPwe4mCm.js";
10
+ import { DOMSerializer as rt, DOMParser as tn } from "@tiptap/pm/model";
11
+ import { c as ge } from "./media-id-b2dgniSy.js";
12
+ import { icons as nn } from "@freecallai/icons";
13
+ import { a as rn, c as Je } from "./media-policy-B1UuSN2e.js";
14
+ function an(r) {
15
+ const o = new Qe("fkpTagValidity"), c = /* @__PURE__ */ new Map();
16
+ let a, l = 0, f = 0, y = !1, i = !1, T, S = /* @__PURE__ */ new Set();
17
+ function p(D = ((F) => (F = r.editor()) == null ? void 0 : F.state.doc)()) {
18
+ const C = [];
19
+ return D == null || D.descendants((w, P) => {
20
+ var H, x, V;
21
+ const { attrs: R } = w, $ = (H = r.describeExtra) == null ? void 0 : H.call(r, w);
22
+ if (w.type.name !== "businessToken" && !$) return;
23
+ const N = w.type.name === "businessToken" ? String(R.kind || "") : $.kind;
24
+ if (!N || w.type.name === "businessToken" && ((x = de(N)) == null ? void 0 : x.validateValidity) === !1)
25
+ return;
26
+ const q = w.type.name === "businessToken" ? `token:${R.id || P}` : `extra:${P}`, z = $ || {
27
+ kind: N,
28
+ key: String(R.key || ""),
29
+ label: String(R.label || ""),
30
+ ...typeof R.token == "string" ? { token: R.token } : {},
31
+ ...R.params && typeof R.params == "object" ? { params: R.params } : {}
32
+ }, _ = JSON.stringify([q, z]);
33
+ C.push({
34
+ fingerprint: _,
35
+ input: { requestItemId: _, ...z },
36
+ pos: P,
37
+ size: w.nodeSize,
38
+ ariaLabel: w.type.name === "businessToken" && ((V = de(N)) == null ? void 0 : V.present(R).ariaLabel) || z.label
39
+ });
40
+ }), C;
41
+ }
42
+ function k() {
43
+ const D = r.editor();
44
+ D && !D.isDestroyed && D.view.dispatch(
45
+ D.state.tr.setMeta(o, !0).setMeta("addToHistory", !1)
46
+ );
47
+ }
48
+ const v = Ze.create({
49
+ name: "fkpTagValidity",
50
+ addProseMirrorPlugins() {
51
+ return [
52
+ new Ce({
53
+ key: o,
54
+ props: {
55
+ decorations(D) {
56
+ const F = p(D.doc).flatMap((C) => {
57
+ const w = c.get(C.fingerprint);
58
+ return (w == null ? void 0 : w.status) !== "invalid" ? [] : [
59
+ pe.node(C.pos, C.pos + C.size, {
60
+ class: "fkp-tag-validity-invalid",
61
+ "aria-label": `${C.ariaLabel}(已失效)`,
62
+ ...w.reason ? { title: w.reason } : {}
63
+ })
64
+ ];
65
+ });
66
+ return et.create(D.doc, F);
67
+ }
68
+ }
69
+ })
70
+ ];
71
+ }
72
+ });
73
+ function m() {
74
+ y || i || (y = !0, queueMicrotask(() => {
75
+ y = !1, i || A(!1);
76
+ }));
77
+ }
78
+ async function A(D) {
79
+ var H;
80
+ const F = r.port(), C = p(), w = new Set(C.map((x) => x.fingerprint));
81
+ for (const x of c.keys()) w.has(x) || c.delete(x);
82
+ if (!F)
83
+ return a == null || a.abort(), l++, T = void 0, S.clear(), c.clear(), k(), { status: "unavailable", items: [] };
84
+ const P = D ? C : C.filter((x) => !c.has(x.fingerprint));
85
+ if (!P.length && D)
86
+ return a == null || a.abort(), l++, T = void 0, S.clear(), { status: "complete", items: [] };
87
+ if (!P.length)
88
+ return T || {
89
+ status: "complete",
90
+ items: C.flatMap((x) => {
91
+ const V = c.get(x.fingerprint);
92
+ return V ? [{ ...x.input, ...V }] : [];
93
+ })
94
+ };
95
+ if (!D && T && P.every((x) => S.has(x.fingerprint)))
96
+ return T;
97
+ a == null || a.abort(), a = new AbortController(), S = new Set(P.map((x) => x.fingerprint));
98
+ const { signal: R } = a, $ = ++l, N = r.editorKey(), q = JSON.parse(
99
+ JSON.stringify(
100
+ P.map((x, V) => ({
101
+ ...x.input,
102
+ requestItemId: `${$}:${V}`
103
+ }))
104
+ )
105
+ ), z = (async () => {
106
+ var x;
107
+ try {
108
+ const V = await F(
109
+ { tags: q },
110
+ { editorKey: N, requestId: `${N}:${++f}`, signal: R }
111
+ );
112
+ if (i || R.aborted || $ !== l || N !== r.editorKey())
113
+ return { status: "cancelled", items: [] };
114
+ const Y = V != null && V.ok && Array.isArray((x = V.data) == null ? void 0 : x.items) ? V.data.items : null, se = new Set(q.map((I) => I.requestItemId));
115
+ if (!Y || Y.length !== se.size || new Set(Y.map((I) => I == null ? void 0 : I.requestItemId)).size !== se.size || Y.some(
116
+ (I) => !I || !se.has(I.requestItemId) || !["valid", "invalid", "unknown"].includes(I.status) || I.reason !== void 0 && typeof I.reason != "string"
117
+ ))
118
+ return {
119
+ status: "error",
120
+ items: [],
121
+ message: V && !V.ok ? V.error.message : "标签状态返回不完整或格式错误"
122
+ };
123
+ const Z = new Set(p().map((I) => I.fingerprint));
124
+ if (P.some((I) => !Z.has(I.fingerprint)))
125
+ return m(), { status: "cancelled", items: [] };
126
+ const ee = new Map(
127
+ Y.map((I) => [I.requestItemId, I])
128
+ );
129
+ return P.forEach((I, J) => {
130
+ const te = ee.get(q[J].requestItemId);
131
+ te.status === "unknown" && c.has(I.fingerprint) || c.set(I.fingerprint, te);
132
+ }), k(), {
133
+ status: "complete",
134
+ items: P.map((I, J) => ({
135
+ ...I.input,
136
+ ...ee.get(q[J].requestItemId)
137
+ }))
138
+ };
139
+ } catch (V) {
140
+ return R.aborted || $ !== l || i ? { status: "cancelled", items: [] } : {
141
+ status: "error",
142
+ items: [],
143
+ message: V instanceof Error ? V.message : "标签状态查询失败"
144
+ };
145
+ }
146
+ })();
147
+ T = z;
148
+ const _ = await z;
149
+ return _.status === "error" && ((H = r.onError) == null || H.call(r, _.message || "标签状态查询失败")), T === z && (T = void 0, S.clear()), _;
150
+ }
151
+ function O() {
152
+ a == null || a.abort(), l++, T = void 0, S.clear(), c.clear(), k(), m();
153
+ }
154
+ return {
155
+ extension: v,
156
+ schedule: m,
157
+ refresh: () => A(!0),
158
+ reset: O,
159
+ dispose() {
160
+ i = !0, a == null || a.abort(), l++, c.clear();
161
+ }
162
+ };
163
+ }
164
+ function ae(r, o) {
165
+ const c = (l) => [
166
+ `http://www.w3.org/2000/svg ${l.tag}`,
167
+ l.attrs,
168
+ ...l.children.map(c)
169
+ ], a = nn[r];
170
+ return [
171
+ "http://www.w3.org/2000/svg svg",
172
+ {
173
+ ...a.attrs,
174
+ class: `fkp-icon ${o}`,
175
+ "aria-hidden": "true",
176
+ focusable: "false"
177
+ },
178
+ ...a.children.map(c)
179
+ ];
180
+ }
181
+ function sn(r) {
182
+ var y;
183
+ const o = (y = de(r.kind)) == null ? void 0 : y.present(r), c = String(r.kind || ""), a = (o == null ? void 0 : o.label) || String(r.label || r.key || ""), l = (i) => [
184
+ "span",
185
+ { class: i },
186
+ a
187
+ ];
188
+ let f = [a];
189
+ return (o == null ? void 0 : o.layout) === "choice" && (f = [
190
+ ae(o.icon, `fkp-choice-token-icon fkp-${c}-token-icon`),
191
+ l(`fkp-choice-token-label fkp-${c}-token-label`),
192
+ ae(
193
+ "arrow-down",
194
+ `fkp-choice-token-arrow fkp-${c}-token-arrow`
195
+ )
196
+ ]), (o == null ? void 0 : o.layout) === "inline" && (f = [
197
+ ae(o.icon, "fkp-inline-token-icon"),
198
+ l("fkp-inline-token-label")
199
+ ]), (o == null ? void 0 : o.layout) === "tool" && (f = [
200
+ ae(o.icon, "fkp-tool-token-icon"),
201
+ l("fkp-tool-token-label")
202
+ ]), (o == null ? void 0 : o.layout) === "toolNote" && (f = [
203
+ ae(o.icon, "fkp-tool-note-icon"),
204
+ l("fkp-tool-note-label"),
205
+ ...o.summary ? [
206
+ [
207
+ "span",
208
+ { class: "fkp-tool-note-divider", "aria-hidden": "true" }
209
+ ],
210
+ [
211
+ "span",
212
+ { class: "fkp-tool-note-summary" },
213
+ o.summary
214
+ ]
215
+ ] : []
216
+ ]), [
217
+ "span",
218
+ {
219
+ "data-business-token": "",
220
+ "data-fkp-node": "business-token",
221
+ "data-kind": r.kind,
222
+ "data-key": r.key,
223
+ "data-node-id": r.id,
224
+ "data-token": r.token,
225
+ ...r.params ? { "data-fkp-params": JSON.stringify(r.params) } : {},
226
+ ...o ? { "data-label": r.label, "aria-label": o.ariaLabel } : {},
227
+ class: `fk-token fk-token--${c} fkp-knowledge-tag fkp-knowledge-tag--${c}${(o == null ? void 0 : o.layout) === "choice" ? " fkp-choice-token" : ""}${o != null && o.className ? ` ${o.className}` : ""}`,
228
+ contenteditable: "false"
229
+ },
230
+ ...f
231
+ ];
232
+ }
233
+ function at(r) {
234
+ var o;
235
+ return ((o = de(r.kind)) == null ? void 0 : o.serialize(r)) || String(r.label || r.key || "");
236
+ }
237
+ const on = Ze.create({
238
+ name: "uniqueExtensionNodeIds",
239
+ addProseMirrorPlugins() {
240
+ return [
241
+ new Ce({
242
+ appendTransaction(r, o, c) {
243
+ if (!r.some((p) => p.docChanged))
244
+ return null;
245
+ const a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
246
+ o.doc.descendants((p, k) => {
247
+ if (!ce(p.type.name) || !p.attrs.id) return;
248
+ l.set(String(p.attrs.id), p);
249
+ let v = k;
250
+ for (const A of r)
251
+ v = A.mapping.mapResult(v, 1).pos;
252
+ const m = c.doc.nodeAt(v);
253
+ (m == null ? void 0 : m.type.name) === p.type.name && m.attrs.id === p.attrs.id && a.set(String(p.attrs.id), v);
254
+ });
255
+ const f = /* @__PURE__ */ new Set();
256
+ for (const p of r) {
257
+ const k = p.getMeta(Q);
258
+ Array.isArray(k) && k.forEach((v) => {
259
+ typeof v == "string" && v && f.add(v);
260
+ });
261
+ }
262
+ const y = /* @__PURE__ */ new Set();
263
+ c.doc.descendants((p) => {
264
+ ce(p.type.name) && p.attrs.id && y.add(String(p.attrs.id));
265
+ });
266
+ const i = /* @__PURE__ */ new Set(), { tr: T } = c, S = r.some(
267
+ (p) => p.getMeta("uiEvent") === "drop"
268
+ );
269
+ return c.doc.descendants((p, k) => {
270
+ var O;
271
+ if (!ce(p.type.name)) return;
272
+ let v = String(p.attrs.id || "");
273
+ const m = a.get(v);
274
+ !!v && !i.has(v) && (m === k || S && m === void 0 && ((O = l.get(v)) == null ? void 0 : O.eq(p)) || m === void 0 && f.has(v)) || (v = Me(y, ge), T.setNodeMarkup(k, void 0, {
275
+ ...p.attrs,
276
+ id: v,
277
+ nodeVersion: 0
278
+ }), y.add(v)), i.add(v);
279
+ }), T.docChanged ? T.setMeta("addToHistory", !1) : null;
280
+ }
281
+ })
282
+ ];
283
+ }
284
+ }), ln = Ee.create({
285
+ name: "businessToken",
286
+ group: "inline",
287
+ inline: !0,
288
+ atom: !0,
289
+ selectable: !0,
290
+ addAttributes() {
291
+ return {
292
+ id: { default: "" },
293
+ nodeVersion: { default: 0 },
294
+ kind: { default: "variable" },
295
+ key: { default: "" },
296
+ label: { default: "" },
297
+ token: { default: null },
298
+ params: { default: null }
299
+ };
300
+ },
301
+ parseHTML() {
302
+ return [
303
+ {
304
+ tag: "span[data-business-token]",
305
+ getAttrs: (r) => ({
306
+ kind: r.getAttribute("data-kind"),
307
+ key: r.getAttribute("data-key"),
308
+ label: r.getAttribute("data-label") || r.textContent,
309
+ token: r.getAttribute("data-token"),
310
+ params: (() => {
311
+ const o = r.getAttribute("data-fkp-params");
312
+ if (!o || o.length > 8192) return null;
313
+ try {
314
+ return JSON.parse(o);
315
+ } catch {
316
+ return null;
317
+ }
318
+ })()
319
+ })
320
+ }
321
+ ];
322
+ },
323
+ renderHTML: ({ node: r }) => sn(r.attrs),
324
+ renderText: ({ node: r }) => at(r.attrs)
325
+ }), Ye = new Qe(
326
+ "inlineReplyNeighbors"
327
+ );
328
+ function Xe(r) {
329
+ const o = [];
330
+ r.forEach((a, l) => {
331
+ o.push({ node: a, position: l });
332
+ });
333
+ const c = /* @__PURE__ */ new Set();
334
+ return o.forEach(({ node: a }, l) => {
335
+ var f;
336
+ if (!(a.type.name !== "originalReply" || a.childCount !== 1 || ((f = a.firstChild) == null ? void 0 : f.type.name) !== "paragraph"))
337
+ for (const y of [o[l - 1], o[l + 1]])
338
+ (y == null ? void 0 : y.node.type.name) === "paragraph" && c.add(y.position);
339
+ }), et.create(r, [
340
+ ...o.filter(({ node: a }) => a.type.name === "originalReply").map(
341
+ ({ position: a }) => pe.widget(
342
+ a + 1,
343
+ () => {
344
+ const l = document.createElement("span");
345
+ return l.className = "fkp-original-reply-label", l.setAttribute("aria-hidden", "true"), l.append(
346
+ rt.renderSpec(document, ae("quote", "")).dom
347
+ ), l;
348
+ },
349
+ { side: -1, ignoreSelection: !0 }
350
+ )
351
+ ),
352
+ ...[...c].flatMap((a) => {
353
+ const l = r.nodeAt(a), f = pe.node(
354
+ a,
355
+ a + l.nodeSize,
356
+ {
357
+ class: l.content.size ? "fk-inline-reply-neighbor" : "fk-inline-reply-neighbor fk-inline-reply-neighbor--empty"
358
+ }
359
+ );
360
+ return l.content.size ? [f] : [
361
+ f,
362
+ pe.widget(
363
+ a + 1,
364
+ () => {
365
+ const y = document.createElement("span");
366
+ return y.className = "fkp-reply-caret-anchor", y.setAttribute("aria-hidden", "true"), y.textContent = "​", y;
367
+ },
368
+ { side: -1, ignoreSelection: !0 }
369
+ )
370
+ ];
371
+ })
372
+ ]);
373
+ }
374
+ function Ge(r) {
375
+ var o;
376
+ return r.type.name === "originalReply" && r.childCount === 1 && ((o = r.firstChild) == null ? void 0 : o.type.name) === "paragraph" && r.firstChild.content.size === 0;
377
+ }
378
+ function Ae(r, o) {
379
+ var k;
380
+ const { state: c } = r, { empty: a, $from: l } = c.selection;
381
+ if (!r.editable || r.composing || !a || !(c.selection instanceof j) || l.parent.type.name !== "paragraph")
382
+ return !1;
383
+ const f = (v, m) => {
384
+ const A = c.tr.delete(v, v + m.nodeSize);
385
+ return A.setSelection(
386
+ j.near(
387
+ A.doc.resolve(Math.min(v, A.doc.content.size)),
388
+ o ? -1 : 1
389
+ )
390
+ ), r.dispatch(A.scrollIntoView()), !0;
391
+ }, y = l.depth - 1;
392
+ if (y < 1 || l.node(y).type.name !== "originalReply") {
393
+ if (l.parentOffset !== (o ? 0 : l.parent.content.size))
394
+ return !1;
395
+ const v = o ? l.before() : l.after(), m = c.doc.resolve(v), A = o ? m.nodeBefore : m.nodeAfter;
396
+ if ((A == null ? void 0 : A.type.name) !== "originalReply") return !1;
397
+ const O = o ? v - A.nodeSize : v;
398
+ return Ge(A) ? f(O, A) : (r.dispatch(
399
+ c.tr.setSelection(Ut.create(c.doc, O)).scrollIntoView()
400
+ ), !0);
401
+ }
402
+ const i = l.node(y);
403
+ if (Ge(i)) return f(l.before(y), i);
404
+ if (l.parent.childCount !== 1 || !((k = l.parent.firstChild) != null && k.isText) || l.parentOffset !== (o ? l.parent.content.size : 0))
405
+ return !1;
406
+ const T = l.parent.textContent;
407
+ if ((typeof Intl.Segmenter == "function" ? [
408
+ ...new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(
409
+ T
410
+ )
411
+ ] : Array.from(T)).length !== 1) return !1;
412
+ const p = c.tr.delete(l.start(), l.end());
413
+ return p.setSelection(j.create(p.doc, l.start())), r.dispatch(p.scrollIntoView()), !0;
414
+ }
415
+ const cn = Ee.create({
416
+ name: "originalReply",
417
+ group: "block",
418
+ content: "(paragraph | mediaBlock | messageSeparator)+",
419
+ defining: !0,
420
+ isolating: !0,
421
+ addAttributes() {
422
+ return { id: { default: "" }, nodeVersion: { default: 0 } };
423
+ },
424
+ parseHTML() {
425
+ return [{ tag: "section[data-original-reply]" }];
426
+ },
427
+ renderHTML() {
428
+ return [
429
+ "section",
430
+ {
431
+ "data-original-reply": "",
432
+ "data-fkp-node": "original-reply",
433
+ class: "fk-original-reply"
434
+ },
435
+ 0
436
+ ];
437
+ },
438
+ addKeyboardShortcuts() {
439
+ const r = (o) => {
440
+ const { state: c, view: a } = this.editor, { empty: l, $from: f } = c.selection, { paragraph: y } = c.schema.nodes;
441
+ if (!this.editor.isEditable || a.composing || !l || !(c.selection instanceof j) || f.parent.type !== y || f.parentOffset !== (o === 1 ? f.parent.content.size : 0))
442
+ return !1;
443
+ const { tr: i } = c, T = f.depth - 1;
444
+ if (T > 0 && f.node(T).type === this.type) {
445
+ const S = o === 1 ? f.end(T) - 1 : f.start(T) + 1;
446
+ if (f.pos !== S) return !1;
447
+ const p = o === 1 ? f.after(T) : f.before(T), k = c.doc.resolve(p), v = o === 1 ? k.nodeAfter : k.nodeBefore;
448
+ let m;
449
+ if ((v == null ? void 0 : v.type) === y)
450
+ m = o === 1 ? p + 1 : p - 1;
451
+ else {
452
+ const A = k.index();
453
+ if (!k.parent.canReplaceWith(A, A, y))
454
+ return !1;
455
+ i.insert(p, y.create()), m = p + 1;
456
+ }
457
+ i.setSelection(j.create(i.doc, m));
458
+ } else {
459
+ const S = o === 1 ? f.after() : f.before(), p = c.doc.resolve(S), k = o === 1 ? p.nodeAfter : p.nodeBefore;
460
+ if ((k == null ? void 0 : k.type) !== this.type) return !1;
461
+ const v = o === 1 ? k.firstChild : k.lastChild;
462
+ if ((v == null ? void 0 : v.type) !== y) return !1;
463
+ const m = o === 1 ? S + 2 : S - 2;
464
+ i.setSelection(j.create(i.doc, m));
465
+ }
466
+ return a.dispatch(i.scrollIntoView()), !0;
467
+ };
468
+ return {
469
+ Backspace: () => Ae(this.editor.view, !0),
470
+ Delete: () => Ae(this.editor.view, !1),
471
+ ArrowLeft: () => r(-1),
472
+ ArrowRight: () => r(1)
473
+ };
474
+ },
475
+ addProseMirrorPlugins() {
476
+ return [
477
+ new Ce({
478
+ key: Ye,
479
+ state: {
480
+ init: (r, o) => Xe(o.doc),
481
+ apply: (r, o) => r.docChanged ? Xe(r.doc) : o
482
+ },
483
+ props: {
484
+ handleDOMEvents: {
485
+ beforeinput: (r, o) => {
486
+ if (!o.cancelable || o.isComposing) return !1;
487
+ const c = o.inputType === "deleteContentBackward";
488
+ return !c && o.inputType !== "deleteContentForward" || !Ae(r, c) ? !1 : (o.preventDefault(), !0);
489
+ },
490
+ mousedown: (r, o) => {
491
+ var f;
492
+ if (!r.editable || r.composing || o.button !== 0 || o.shiftKey || o.ctrlKey || o.metaKey || o.altKey || o.detail > 1 || !(o.target instanceof Element))
493
+ return !1;
494
+ const c = o.target.closest("p");
495
+ if (!c || !r.dom.contains(c) || !((f = c.parentElement) != null && f.matches(
496
+ "section[data-original-reply]"
497
+ )))
498
+ return !1;
499
+ const a = r.posAtDOM(c, 0), l = r.state.doc.resolve(a);
500
+ return l.parent.type !== r.state.schema.nodes.paragraph || l.parent.content.size !== 0 || l.node(l.depth - 1).type !== this.type ? !1 : (o.preventDefault(), r.dispatch(
501
+ r.state.tr.setSelection(
502
+ j.create(r.state.doc, a)
503
+ )
504
+ ), r.focus(), !0);
505
+ }
506
+ },
507
+ decorations(r) {
508
+ return Ye.getState(r);
509
+ }
510
+ }
511
+ })
512
+ ];
513
+ }
514
+ }), dn = Ee.create({
515
+ name: "messageSeparator",
516
+ group: "block",
517
+ atom: !0,
518
+ selectable: !0,
519
+ addAttributes() {
520
+ return { id: { default: "" }, nodeVersion: { default: 0 } };
521
+ },
522
+ parseHTML() {
523
+ return [{ tag: "div[data-message-separator]" }];
524
+ },
525
+ renderHTML() {
526
+ return [
527
+ "div",
528
+ {
529
+ "data-message-separator": "",
530
+ "data-fkp-node": "message-separator",
531
+ class: "fk-message-separator"
532
+ },
533
+ [
534
+ "span",
535
+ {
536
+ class: "fk-separator-tag fkp-knowledge-tag fkp-knowledge-tag--primary"
537
+ },
538
+ "分隔符"
539
+ ]
540
+ ];
541
+ },
542
+ renderText() {
543
+ return `
544
+ {分隔符}
545
+ `;
546
+ }
547
+ }), un = 1024 * 1024, fn = 1e4, pn = /* @__PURE__ */ new Set([
548
+ "SCRIPT",
549
+ "STYLE",
550
+ "SVG",
551
+ "IFRAME",
552
+ "OBJECT",
553
+ "TEMPLATE"
554
+ ]), mn = /* @__PURE__ */ new Set([
555
+ "P",
556
+ "DIV",
557
+ "BLOCKQUOTE",
558
+ "UL",
559
+ "OL",
560
+ "LI"
561
+ ]);
562
+ function gn(r, o, c, a) {
563
+ if (!o.content.size) return !1;
564
+ const l = document.createElement("div");
565
+ l.appendChild(
566
+ rt.fromSchema(c).serializeFragment(o.content)
567
+ );
568
+ const f = o.content.textBetween(
569
+ 0,
570
+ o.content.size,
571
+ `
572
+ `,
573
+ (y) => {
574
+ var T;
575
+ if (y.type.name === "mediaBlock")
576
+ return y.attrs.sourceType === "qianniuVideo" ? y.attrs.src : `[${y.attrs.kind === "video" ? "视频" : "图片"}:${y.attrs.name || ""}]`;
577
+ if (y.type.name === "businessToken")
578
+ return at(y.attrs);
579
+ const i = (T = a == null ? void 0 : a.serializeNode) == null ? void 0 : T.call(a, y);
580
+ return i !== void 0 ? i : y.type.name === "messageSeparator" ? "{分隔符}" : "";
581
+ }
582
+ );
583
+ try {
584
+ return r.setData("text/plain", f), r.setData("text/html", l.innerHTML), !0;
585
+ } catch {
586
+ return !1;
587
+ }
588
+ }
589
+ function yn(r, o, c, a) {
590
+ var v;
591
+ const l = r.getAttribute("data-kind"), f = r.getAttribute("data-key"), y = r.getAttribute("data-label"), i = r.getAttribute("data-token");
592
+ if (!Xt(l) || !f || !y || a != null && a.allowBusinessToken && !a.allowBusinessToken(l, f) || c && ((v = de(l)) == null ? void 0 : v.allowInOriginalReply) === !1 || !o.has(`${l}:knowledgeInline`))
593
+ return null;
594
+ const T = r.getAttribute("data-fkp-params");
595
+ let S = null;
596
+ if (T != null) {
597
+ if (T.length > 8192) return null;
598
+ try {
599
+ const m = JSON.parse(T);
600
+ if (!m || typeof m != "object" || Array.isArray(m))
601
+ return null;
602
+ S = m;
603
+ } catch {
604
+ return null;
605
+ }
606
+ }
607
+ if (l === "tool" && (!S || f === "small_payment" && !Gt(S.amount) || f === "order_note" && !tt(S)) || nt({
608
+ type: "doc",
609
+ content: [
610
+ { type: "paragraph", content: [{ type: "businessToken", attrs: { kind: l, key: f, label: y, token: i, params: S } }] }
611
+ ]
612
+ }))
613
+ return null;
614
+ const k = document.createElement("span");
615
+ return k.setAttribute("data-business-token", ""), k.setAttribute("data-fkp-node", "business-token"), k.setAttribute("data-kind", l), k.setAttribute("data-key", f), k.setAttribute("data-label", y), i && k.setAttribute("data-token", i), S && k.setAttribute("data-fkp-params", JSON.stringify(S)), k.textContent = r.textContent, k;
616
+ }
617
+ function kn(r, o, c) {
618
+ var S, p;
619
+ const a = r.tagName === "IMG" || r.tagName === "VIDEO" ? r : r.querySelector("img,video");
620
+ if (!a) return !1;
621
+ const l = a.tagName === "VIDEO" ? "video" : "image", f = a.getAttribute("src") || (l === "video" ? (S = a.querySelector("source[src]")) == null ? void 0 : S.getAttribute("src") : null);
622
+ let y = "";
623
+ if (ue(f))
624
+ try {
625
+ y = decodeURIComponent(
626
+ new URL(f).pathname.split("/").pop() || ""
627
+ );
628
+ } catch {
629
+ y = "";
630
+ }
631
+ const i = [
632
+ r.getAttribute("data-name"),
633
+ (p = r.querySelector("figcaption")) == null ? void 0 : p.textContent,
634
+ a.getAttribute("alt"),
635
+ y
636
+ ].filter((k) => !!(k != null && k.trim())).map((k) => k.trim().toLowerCase());
637
+ if (!i.length) return !1;
638
+ const T = o.findIndex(
639
+ (k, v) => {
640
+ var m;
641
+ return !c.has(v) && ((m = rn(k)) == null ? void 0 : m.kind) === l && i.includes(k.name.toLowerCase());
642
+ }
643
+ );
644
+ return T < 0 ? !1 : (c.add(T), !0);
645
+ }
646
+ function hn(r, o) {
647
+ var m, A;
648
+ const c = r.tagName === "IMG" || r.tagName === "VIDEO" ? r : r.querySelector("img,video") || (r.getAttribute("data-source-type") === "qianniuVideo" ? r.querySelector("a[href]") : null), a = r.getAttribute("data-kind") || ((c == null ? void 0 : c.tagName) === "VIDEO" ? "video" : "image"), l = (c == null ? void 0 : c.getAttribute("src")) || (c == null ? void 0 : c.getAttribute("href")) || ((c == null ? void 0 : c.tagName) === "VIDEO" ? (m = c.querySelector("source[src]")) == null ? void 0 : m.getAttribute("src") : null), f = c == null ? void 0 : c.getAttribute("poster");
649
+ if (r.getAttribute("data-fkp-node") === "media-block" && r.hasAttribute("status") && r.getAttribute("status") !== "ready" || c && (a === "image" && c.tagName !== "IMG" || a === "video" && c.tagName !== "VIDEO" && !(r.getAttribute("data-source-type") === "qianniuVideo" && c.tagName === "A")) || !["image", "video"].includes(a) || !o.has(`${a}:knowledgeBlock`) || !ue(l) || f && !ue(f))
650
+ return null;
651
+ const y = r.getAttribute("data-name") || ((A = r.querySelector("figcaption")) == null ? void 0 : A.textContent) || (c == null ? void 0 : c.getAttribute("alt")) || "", i = r.getAttribute("data-asset-id"), T = r.getAttribute("data-source-type"), S = {
652
+ id: ge(),
653
+ kind: a,
654
+ src: l,
655
+ name: y,
656
+ status: "ready",
657
+ ...f ? { poster: f } : {},
658
+ ...i ? { assetId: i } : {},
659
+ ...T ? { sourceType: T } : {}
660
+ };
661
+ if (nt({
662
+ type: "doc",
663
+ content: [{ type: "mediaBlock", attrs: S }]
664
+ }))
665
+ return null;
666
+ const p = document.createElement("figure");
667
+ p.setAttribute("data-media-block", ""), p.setAttribute("data-fkp-node", "media-block"), p.setAttribute("data-id", S.id), p.setAttribute("data-kind", a), i && p.setAttribute("data-asset-id", i), S.sourceType && p.setAttribute("data-source-type", S.sourceType);
668
+ const k = document.createElement(
669
+ S.sourceType === "qianniuVideo" ? "a" : a === "video" ? "video" : "img"
670
+ );
671
+ k.setAttribute(S.sourceType === "qianniuVideo" ? "href" : "src", l), S.sourceType === "qianniuVideo" && (k.textContent = l), f && k.setAttribute("poster", f), p.appendChild(k);
672
+ const v = document.createElement("figcaption");
673
+ return v.textContent = y, p.appendChild(v), p;
674
+ }
675
+ function bn(r, o, c, a = [], l) {
676
+ var v;
677
+ if (!r || r.length > un)
678
+ return { slice: null, handled: !1 };
679
+ const f = new Set(
680
+ c.map((m) => `${m.id}:${m.slot}`)
681
+ ), y = new DOMParser().parseFromString(
682
+ r.replace(
683
+ /<video\b((?:[^"'<>]|"[^"]*"|'[^']*')*)\/>/giu,
684
+ "<video$1></video>"
685
+ ),
686
+ "text/html"
687
+ ), i = document.createElement("div"), T = /* @__PURE__ */ new Set();
688
+ let S = 0, p = !1;
689
+ const k = (m, A = !1) => {
690
+ var F;
691
+ if (++S > fn)
692
+ throw new Error("Clipboard HTML is too large");
693
+ if (m.nodeType === Node.TEXT_NODE)
694
+ return document.createTextNode(m.textContent || "");
695
+ if (!(m instanceof Element) || pn.has(m.tagName))
696
+ return null;
697
+ const O = (F = l == null ? void 0 : l.sanitizeInlineNode) == null ? void 0 : F.call(l, m);
698
+ if (O !== void 0)
699
+ return O || (p = !0), O;
700
+ if (m.hasAttribute("data-agent-size-chart"))
701
+ return p = !0, null;
702
+ if (m.getAttribute("data-fkp-node") === "business-token") {
703
+ const C = yn(m, f, A, l);
704
+ return C || (p = !0), C;
705
+ }
706
+ if (m.getAttribute("data-fkp-node") === "media-block" || m.tagName === "IMG" || m.tagName === "VIDEO" || m.tagName === "FIGURE" && m.querySelector("img,video")) {
707
+ if (kn(m, a, T))
708
+ return p = !0, null;
709
+ const C = hn(m, f);
710
+ return C || (p = !0), C;
711
+ }
712
+ if (m.getAttribute("data-fkp-node") === "message-separator") {
713
+ if (!f.has("separator:knowledgeInline"))
714
+ return p = !0, null;
715
+ const C = document.createElement("div");
716
+ return C.setAttribute("data-message-separator", ""), C;
717
+ }
718
+ if (m.getAttribute("data-fkp-node") === "original-reply") {
719
+ const C = f.has("originalReply:knowledgeBlock");
720
+ C || (p = !0);
721
+ const w = C ? document.createElement("section") : document.createDocumentFragment();
722
+ return w instanceof HTMLElement && w.setAttribute("data-original-reply", ""), m.childNodes.forEach((P) => {
723
+ const R = k(P, C);
724
+ R && w.appendChild(R);
725
+ }), w;
726
+ }
727
+ if (m.hasAttribute("data-fkp-node") || m.hasAttribute("data-business-token") || m.hasAttribute("data-message-separator") || m.getAttribute("data-tag") === "true" || m.getAttribute("data-variable") === "true" || m.getAttribute("data-divider") === "true")
728
+ return p = !0, null;
729
+ const D = mn.has(m.tagName) ? document.createElement(m.tagName.toLowerCase()) : m.tagName === "BR" ? document.createElement("br") : document.createDocumentFragment();
730
+ return m.childNodes.forEach((C) => {
731
+ const w = k(C, A);
732
+ w && D.appendChild(w);
733
+ }), D;
734
+ };
735
+ try {
736
+ if (y.body.childNodes.forEach((A) => {
737
+ const O = k(A);
738
+ O && i.appendChild(O);
739
+ }), !((v = i.textContent) != null && v.trim()) && !i.querySelector(
740
+ "figure, [data-message-separator], [data-original-reply]"
741
+ ))
742
+ return { slice: null, handled: p };
743
+ const m = tn.fromSchema(o).parseSlice(i, {
744
+ preserveWhitespace: !0
745
+ });
746
+ return m.content.size ? { slice: m, handled: !0 } : { slice: null, handled: p };
747
+ } catch {
748
+ return { slice: null, handled: !1 };
749
+ }
750
+ }
751
+ function vn(r) {
752
+ return st(r, r.state.selection.getBookmark());
753
+ }
754
+ function je(r, o) {
755
+ if (r.isDestroyed || !Number.isInteger(o) || o < 0 || o > r.state.doc.content.size)
756
+ return null;
757
+ let c = o, a = !0, l = !0;
758
+ const f = ({ transaction: y }) => {
759
+ const i = y.mapping.mapResult(c, 1);
760
+ i.deletedAcross && (l = !1), c = i.pos;
761
+ };
762
+ return r.on("transaction", f), {
763
+ status() {
764
+ return !a || r.isDestroyed ? "disposed" : l ? "ready" : "lost";
765
+ },
766
+ insert(y) {
767
+ if (!a || !l || r.isDestroyed) return !1;
768
+ try {
769
+ return r.chain().setMeta(Q, me(y)).insertContentAt(c, y).run();
770
+ } catch {
771
+ return !1;
772
+ }
773
+ },
774
+ dispose() {
775
+ a && (a = !1, r.off("transaction", f));
776
+ }
777
+ };
778
+ }
779
+ function We(r, o) {
780
+ if (r.isDestroyed || !Number.isInteger(o) || o < 0 || o > r.state.doc.content.size)
781
+ return null;
782
+ try {
783
+ const c = _t.near(
784
+ r.state.doc.resolve(o)
785
+ ).getBookmark();
786
+ return st(r, c);
787
+ } catch {
788
+ return null;
789
+ }
790
+ }
791
+ function st(r, o) {
792
+ let c = o, a = !0, l = !0, f = !1, { from: y, to: i } = o.resolve(r.state.doc);
793
+ const T = ({ transaction: S }) => {
794
+ const p = S.mapping.mapResult(y, 1), k = S.mapping.mapResult(i, -1);
795
+ !f && (p.deletedAcross || k.deletedAcross) && (l = !1), y = p.pos, i = k.pos, c = c.map(S.mapping);
796
+ };
797
+ return r.on("transaction", T), {
798
+ status() {
799
+ return !a || r.isDestroyed ? "disposed" : l ? "ready" : "lost";
800
+ },
801
+ insert(S) {
802
+ if (!a || !l || r.isDestroyed) return !1;
803
+ try {
804
+ const p = c.resolve(r.state.doc);
805
+ f = !0;
806
+ try {
807
+ return r.chain().setMeta(Q, me(S)).insertContentAt(
808
+ { from: p.from, to: p.to },
809
+ S
810
+ ).run();
811
+ } finally {
812
+ f = !1;
813
+ }
814
+ } catch {
815
+ return !1;
816
+ }
817
+ },
818
+ dispose() {
819
+ a && (a = !1, r.off("transaction", T));
820
+ }
821
+ };
822
+ }
823
+ const Tn = {
824
+ key: 0,
825
+ class: "fkp-knowledge-area",
826
+ role: "alert"
827
+ }, Sn = { class: "fkp-order-remark-detail-title" }, An = {
828
+ key: 0,
829
+ class: "fkp-order-remark-extract"
830
+ }, Mn = { class: "fkp-order-remark-detail-content" }, Cn = { class: "fkp-order-remark-detail-row" }, En = { key: 0 }, wn = ["aria-label"], In = { class: "fkp-order-remark-detail-row" }, Nn = {
831
+ key: 2,
832
+ class: "fkp-reference-placeholder",
833
+ "aria-hidden": "true"
834
+ }, Kn = /* @__PURE__ */ Ot({
835
+ __name: "KnowledgeArea",
836
+ props: {
837
+ modelValue: {},
838
+ tagValidityPort: { type: Function },
839
+ tagValidityKey: {},
840
+ editable: { type: Boolean },
841
+ placeholder: {},
842
+ referencePlaceholder: { type: Boolean },
843
+ schemaPlan: {},
844
+ pasteCapabilities: {},
845
+ activeChoiceId: {},
846
+ documentAdapter: {}
847
+ },
848
+ emits: ["update:modelValue", "retry-media", "load-error", "tag-validity-error", "edit-tool", "choice-menu", "leave-choice"],
849
+ setup(r, { expose: o, emit: c }) {
850
+ const a = r;
851
+ let l = !1;
852
+ const f = c, y = /* @__PURE__ */ new Map(), i = Pt(), T = an({
853
+ editor: () => i.value,
854
+ port: () => a.tagValidityPort,
855
+ editorKey: () => a.tagValidityKey || "",
856
+ onError: (e) => f("tag-validity-error", e),
857
+ describeExtra: (e) => {
858
+ var t, n;
859
+ return (n = (t = a.documentAdapter).describeTagValidity) == null ? void 0 : n.call(t, e);
860
+ }
861
+ });
862
+ ie(
863
+ () => [a.tagValidityPort, a.tagValidityKey],
864
+ () => T.reset()
865
+ ), ve(() => T.dispose());
866
+ let S = () => {
867
+ };
868
+ const p = new Promise((e) => {
869
+ S = e;
870
+ }), k = re(), v = re(!0), m = re(!1), A = re(null), O = re({});
871
+ let D = null;
872
+ function F() {
873
+ D && clearTimeout(D), D = null;
874
+ }
875
+ function C() {
876
+ F(), D = setTimeout(() => {
877
+ A.value = null;
878
+ }, 150);
879
+ }
880
+ function w(e) {
881
+ const { target: t } = e;
882
+ if (!(t instanceof Element) || !i.value) return;
883
+ const n = t.closest(
884
+ '[data-business-token][data-key="order_note"]'
885
+ );
886
+ n != null && n.dataset.nodeId && (F(), i.value.state.doc.descendants((s) => {
887
+ if (s.type.name !== "businessToken" || s.attrs.id !== n.dataset.nodeId)
888
+ return !0;
889
+ A.value = tt(s.attrs.params) ? s.attrs.params : null;
890
+ const d = n.getBoundingClientRect();
891
+ return O.value = {
892
+ left: `${d.left}px`,
893
+ top: `${d.top}px`,
894
+ width: `${d.width}px`,
895
+ height: `${d.height}px`
896
+ }, !1;
897
+ }));
898
+ }
899
+ function P(e) {
900
+ const { target: t } = e;
901
+ if (!(t instanceof Element)) return;
902
+ const n = t.closest('[data-business-token][data-key="order_note"]');
903
+ n && (!(e.relatedTarget instanceof Node) || !n.contains(e.relatedTarget)) && C();
904
+ }
905
+ ve(F);
906
+ let R = !1, $ = null;
907
+ const N = re(null);
908
+ let q = null, z = null;
909
+ function _() {
910
+ q = null, z !== null && cancelAnimationFrame(z), z = null;
911
+ }
912
+ function H() {
913
+ _(), $ = null, N.value = null;
914
+ }
915
+ function x(e) {
916
+ e.key === "Escape" && H();
917
+ }
918
+ function V() {
919
+ if (!q) return;
920
+ const e = xe({
921
+ clientX: q.x,
922
+ clientY: q.y
923
+ }), t = e === null ? null : Ne(e, "file"), n = N.value;
924
+ (t == null ? void 0 : t.pos) === (n == null ? void 0 : n.pos) && (t == null ? void 0 : t.top) === (n == null ? void 0 : n.top) && (t == null ? void 0 : t.left) === (n == null ? void 0 : n.left) && (t == null ? void 0 : t.width) === (n == null ? void 0 : n.width) && (t == null ? void 0 : t.kind) === (n == null ? void 0 : n.kind) || (N.value = t);
925
+ }
926
+ ie(
927
+ () => a.editable,
928
+ (e) => {
929
+ e || H();
930
+ }
931
+ );
932
+ function Y() {
933
+ z = null;
934
+ const e = k.value, t = q;
935
+ if (!e || !t || !a.editable) return;
936
+ const n = e.getBoundingClientRect(), s = Math.min(40, n.height / 3);
937
+ if (s <= 0) return;
938
+ const d = t.y < n.top + s ? -Math.ceil(12 * Math.min(1, (n.top + s - t.y) / s)) : t.y > n.bottom - s ? Math.ceil(12 * Math.min(1, (t.y - n.bottom + s) / s)) : 0, u = e.scrollHeight - e.clientHeight;
939
+ if (!d || u <= 0) return;
940
+ const h = Math.max(0, Math.min(u, e.scrollTop + d));
941
+ h !== e.scrollTop && (e.scrollTop = h, z = requestAnimationFrame(Y));
942
+ }
943
+ function se() {
944
+ A.value = null, q ? V() : N.value = null;
945
+ }
946
+ let Z = null, ee = !1;
947
+ const I = `[data-business-token]:is(${jt.map(
948
+ (e) => `[data-kind="${e}"]`
949
+ ).join(", ")})`;
950
+ function J(e) {
951
+ const t = y.get(e);
952
+ t && (URL.revokeObjectURL(t), y.delete(e));
953
+ }
954
+ function te(e) {
955
+ return !a.editable || !(e.target instanceof Element) ? null : e.target.closest(I);
956
+ }
957
+ function ot(e) {
958
+ const t = te(e);
959
+ !t || e.relatedTarget instanceof Node && t.contains(e.relatedTarget) || we(t);
960
+ }
961
+ function it(e) {
962
+ const t = te(e);
963
+ t && (!(e.relatedTarget instanceof Node) || !t.contains(e.relatedTarget)) && f("leave-choice");
964
+ }
965
+ function we(e) {
966
+ const { nodeId: t } = e.dataset;
967
+ !t || !i.value || i.value.state.doc.descendants((n) => n.type.name !== "businessToken" || n.attrs.id !== t ? !0 : (Zt(n.attrs.kind) && f("choice-menu", {
968
+ nodeId: t,
969
+ nodeVersion: Number(n.attrs.nodeVersion) || 0,
970
+ key: String(n.attrs.key),
971
+ kind: n.attrs.kind,
972
+ anchor: e
973
+ }), !1));
974
+ }
975
+ function lt(e) {
976
+ if (!a.editable || !i.value) return;
977
+ const { target: t } = e;
978
+ if (!(t instanceof Element)) return;
979
+ const n = te(e);
980
+ if (n) {
981
+ we(n);
982
+ return;
983
+ }
984
+ const s = t.closest(
985
+ '[data-business-token][data-kind="tool"]'
986
+ );
987
+ s && (A.value = null);
988
+ const d = s == null ? void 0 : s.dataset.nodeId;
989
+ d && i.value.state.doc.descendants((u) => {
990
+ if (u.type.name !== "businessToken" || u.attrs.id !== d)
991
+ return !0;
992
+ const { params: h } = u.attrs;
993
+ return f("edit-tool", {
994
+ nodeId: d,
995
+ nodeVersion: Number(u.attrs.nodeVersion) || 0,
996
+ key: String(u.attrs.key),
997
+ label: String(u.attrs.label || u.attrs.key),
998
+ params: h && typeof h == "object" && !Array.isArray(h) ? h : null
999
+ }), !1;
1000
+ });
1001
+ }
1002
+ function ct(e) {
1003
+ if (!a.editable || !i.value) return;
1004
+ const { target: t } = e;
1005
+ if (t === k.value || t === i.value.view.dom.parentElement) {
1006
+ i.value.commands.focus("end");
1007
+ return;
1008
+ }
1009
+ lt(e);
1010
+ }
1011
+ function Ie() {
1012
+ var e;
1013
+ (e = k.value) == null || e.querySelectorAll(I).forEach(
1014
+ (t) => t.classList.toggle(
1015
+ "is-menu-open",
1016
+ !!a.activeChoiceId && t.dataset.nodeId === a.activeChoiceId
1017
+ )
1018
+ );
1019
+ }
1020
+ ie(
1021
+ [() => a.activeChoiceId, () => a.modelValue],
1022
+ () => void He(Ie)
1023
+ );
1024
+ function dt(e) {
1025
+ var n;
1026
+ const t = e.target instanceof Element ? e.target.closest(".fk-media[data-drag-handle]") : null;
1027
+ !a.editable || !(t != null && t.dataset.mediaId) || ($ = t.dataset.mediaId, N.value = null, (n = e.dataTransfer) == null || n.setData("application/x-fkp-media-id", $), e.dataTransfer && (e.dataTransfer.effectAllowed = "move"), e.stopPropagation());
1028
+ }
1029
+ function Ne(e, t) {
1030
+ const n = i.value, s = k.value;
1031
+ if (!n || !s) return null;
1032
+ const { doc: d } = n.state, u = e === d.content.size, h = d.lastChild, g = u && h ? e - h.nodeSize : e, b = n.view.nodeDOM(g);
1033
+ if (!(b instanceof HTMLElement)) return null;
1034
+ const M = b.getBoundingClientRect(), E = s.getBoundingClientRect();
1035
+ return {
1036
+ top: (u ? M.bottom : M.top) - E.top + s.scrollTop,
1037
+ left: s.scrollLeft,
1038
+ width: s.clientWidth || E.right - E.left,
1039
+ pos: e,
1040
+ kind: t
1041
+ };
1042
+ }
1043
+ function xe(e) {
1044
+ const t = i.value;
1045
+ if (!t) return null;
1046
+ const { view: n } = t, s = n.posAtCoords({ left: e.clientX, top: e.clientY });
1047
+ if (!s) {
1048
+ const E = n.dom.children;
1049
+ let B = 0, L = E.length;
1050
+ for (; B < L; ) {
1051
+ const X = Math.floor((B + L) / 2), U = E[X].getBoundingClientRect();
1052
+ e.clientY > U.top + U.height / 2 ? B = X + 1 : L = X;
1053
+ }
1054
+ if (B === E.length) return n.state.doc.content.size;
1055
+ const ne = n.state.doc.resolve(n.posAtDOM(E[B], 0));
1056
+ return ne.depth ? ne.before(1) : ne.pos;
1057
+ }
1058
+ const { doc: d } = n.state, u = d.resolve(s.pos);
1059
+ let h = u.depth ? u.before(1) : s.pos;
1060
+ h === d.content.size && d.lastChild && (h -= d.lastChild.nodeSize);
1061
+ const g = d.nodeAt(h), b = n.nodeDOM(h);
1062
+ if (!g || !(b instanceof HTMLElement)) return null;
1063
+ const M = b.getBoundingClientRect();
1064
+ return e.clientY > M.top + M.height / 2 ? h + g.nodeSize : h;
1065
+ }
1066
+ function De(e, t) {
1067
+ const n = i.value;
1068
+ if (!n) return null;
1069
+ const s = /* @__PURE__ */ new Map();
1070
+ n.state.doc.descendants((M, E) => {
1071
+ M.type.name === "mediaBlock" && typeof M.attrs.id == "string" && s.set(M.attrs.id, { pos: E, size: M.nodeSize });
1072
+ });
1073
+ const d = s.get(t);
1074
+ if (!d) return null;
1075
+ const u = e.target instanceof Element ? e.target.closest(".fk-media[data-media-id]") : null, h = u == null ? void 0 : u.dataset.mediaId;
1076
+ if (h === t) return null;
1077
+ const g = h ? s.get(h) : void 0;
1078
+ let b;
1079
+ if (g && u) {
1080
+ const M = d.pos < g.pos;
1081
+ b = g.pos + (M ? g.size : 0);
1082
+ } else {
1083
+ const M = n.view.posAtCoords({
1084
+ left: e.clientX,
1085
+ top: e.clientY
1086
+ });
1087
+ if (!M) return null;
1088
+ const E = [0];
1089
+ n.state.doc.forEach((B, L) => {
1090
+ E.push(L + B.nodeSize);
1091
+ }), b = E.reduce(
1092
+ (B, L) => Math.abs(L - M.pos) < Math.abs(B - M.pos) ? L : B
1093
+ );
1094
+ }
1095
+ return b === d.pos || b === d.pos + d.size ? null : { source: d, insertion: b };
1096
+ }
1097
+ function ut(e) {
1098
+ var t;
1099
+ if (a.editable) {
1100
+ if ($) {
1101
+ e.preventDefault(), e.stopPropagation(), e.dataTransfer && (e.dataTransfer.dropEffect = "move");
1102
+ const n = De(e, $);
1103
+ N.value = n ? Ne(n.insertion, "media") : null;
1104
+ return;
1105
+ }
1106
+ !a.schemaPlan.mediaBlock || !Array.from(((t = e.dataTransfer) == null ? void 0 : t.types) || []).includes("Files") || (e.preventDefault(), e.stopPropagation(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"), q = { x: e.clientX, y: e.clientY }, V(), z === null && (z = requestAnimationFrame(Y)));
1107
+ }
1108
+ }
1109
+ function ft(e) {
1110
+ var g;
1111
+ _();
1112
+ const t = $;
1113
+ if (!t) {
1114
+ (g = e.dataTransfer) != null && g.files.length || (N.value = null);
1115
+ return;
1116
+ }
1117
+ $ = null, N.value = null, e.preventDefault(), e.stopPropagation();
1118
+ const n = i.value;
1119
+ if (!a.editable || !n || n.isDestroyed) return;
1120
+ const s = De(e, t);
1121
+ if (!s) return;
1122
+ const { source: d, insertion: u } = s, h = n.state.doc.nodeAt(d.pos);
1123
+ if (!(!h || h.type.name !== "mediaBlock"))
1124
+ try {
1125
+ const b = n.state.tr.delete(
1126
+ d.pos,
1127
+ d.pos + d.size
1128
+ );
1129
+ b.insert(b.mapping.map(u), h), b.setMeta("uiEvent", "drop"), b.setMeta(Q, [t]), n.view.dispatch(b);
1130
+ } catch {
1131
+ }
1132
+ }
1133
+ function pt(e) {
1134
+ const t = k.value;
1135
+ if (!t || !N.value || e.relatedTarget instanceof Node && t.contains(e.relatedTarget))
1136
+ return;
1137
+ const n = t.getBoundingClientRect();
1138
+ e.clientX >= n.left && e.clientX <= n.right && e.clientY >= n.top && e.clientY <= n.bottom || (_(), N.value = null);
1139
+ }
1140
+ function mt() {
1141
+ H();
1142
+ }
1143
+ function ye(e) {
1144
+ const t = /* @__PURE__ */ new Set(), n = (s) => {
1145
+ var d, u;
1146
+ s.type === "mediaBlock" && typeof ((d = s.attrs) == null ? void 0 : d.id) == "string" && t.add(s.attrs.id), (u = s.content) == null || u.forEach(n);
1147
+ };
1148
+ n(e);
1149
+ for (const s of y.keys()) t.has(s) || J(s);
1150
+ }
1151
+ function Ve(e) {
1152
+ i.value = new Ft({
1153
+ content: a.modelValue,
1154
+ editable: a.editable,
1155
+ extensions: [
1156
+ Jt.configure({
1157
+ heading: !1,
1158
+ dropcursor: { color: "#4884e4", width: 2 },
1159
+ link: { openOnClick: !1, isAllowedUri: (t) => ue(t) }
1160
+ }),
1161
+ Yt.configure({
1162
+ placeholder: () => a.referencePlaceholder ? "" : a.placeholder || a.documentAdapter.placeholder
1163
+ }),
1164
+ on,
1165
+ T.extension,
1166
+ ...a.schemaPlan.businessToken ? [ln] : [],
1167
+ ...a.schemaPlan.originalReply ? [cn] : [],
1168
+ ...a.schemaPlan.separator ? [dn] : [],
1169
+ ...a.documentAdapter.extensions || [],
1170
+ ...e
1171
+ ],
1172
+ editorProps: {
1173
+ attributes: {
1174
+ class: "fkp-knowledge-document",
1175
+ role: "textbox",
1176
+ "aria-label": a.documentAdapter.ariaLabel,
1177
+ "aria-multiline": "true"
1178
+ }
1179
+ },
1180
+ onUpdate: ({ editor: t }) => {
1181
+ v.value = t.isEmpty;
1182
+ const n = t.getJSON();
1183
+ T.schedule(), ye(n), l || f("update:modelValue", n);
1184
+ }
1185
+ }), v.value = i.value.isEmpty, T.schedule(), S(!0), Ie(), qe();
1186
+ }
1187
+ zt(() => {
1188
+ if (document.addEventListener("keydown", x), document.addEventListener("dragend", H), document.addEventListener("drop", H), !a.schemaPlan.mediaBlock) {
1189
+ Ve([]);
1190
+ return;
1191
+ }
1192
+ import("./media-extensions-YYbGuUQa.js").then(({ MediaBlock: e }) => {
1193
+ R || Ve([e.configure({ sceneStyle: !0 })]);
1194
+ }).catch(() => {
1195
+ R || (m.value = !0, S(!1), f("load-error", "媒体编辑器加载失败,请刷新页面重试"));
1196
+ });
1197
+ }), ie(
1198
+ () => a.editable,
1199
+ (e) => {
1200
+ var t;
1201
+ return (t = i.value) == null ? void 0 : t.setEditable(e);
1202
+ }
1203
+ ), ie(
1204
+ () => a.modelValue,
1205
+ (e) => {
1206
+ if (i.value && Je(e) !== Je(i.value.getJSON())) {
1207
+ const t = Le();
1208
+ i.value.chain().setMeta(Q, me(e)).setContent(e, { emitUpdate: !1 }).run(), v.value = i.value.isEmpty, ye(e), T.schedule(), q && V(), t && $e(i.value, t);
1209
+ }
1210
+ },
1211
+ { deep: !0 }
1212
+ ), ve(() => {
1213
+ var e;
1214
+ R = !0, S(!1), document.removeEventListener("keydown", x), document.removeEventListener("dragend", H), document.removeEventListener("drop", H), H();
1215
+ for (const t of y.keys()) J(t);
1216
+ (e = i.value) == null || e.destroy();
1217
+ });
1218
+ function ke(e, t, n, s, d) {
1219
+ var u;
1220
+ return !a.editable || !a.schemaPlan.businessToken ? !1 : !!((u = i.value) != null && u.chain().focus().insertContent([
1221
+ { type: "businessToken", attrs: { kind: e, key: t, label: n, token: s, params: d } },
1222
+ { type: "text", text: " " }
1223
+ ]).run());
1224
+ }
1225
+ function gt(e, t, n, s) {
1226
+ const d = i.value;
1227
+ if (!a.editable || !a.schemaPlan.businessToken || !d)
1228
+ return !1;
1229
+ const u = [];
1230
+ if (d.state.doc.descendants((b, M) => {
1231
+ b.type.name === "businessToken" && b.attrs.kind === e && b.attrs.key === t && u.push(M);
1232
+ }), u.length > 1) return !1;
1233
+ if (!u.length) return ke(e, t, n, void 0, s);
1234
+ const h = u[0], g = d.state.doc.nodeAt(h);
1235
+ return g ? (d.view.dispatch(
1236
+ d.state.tr.setNodeMarkup(h, void 0, {
1237
+ ...g.attrs,
1238
+ params: s,
1239
+ nodeVersion: Number(g.attrs.nodeVersion || 0) + 1
1240
+ })
1241
+ ), !0) : !1;
1242
+ }
1243
+ function yt() {
1244
+ if (!a.editable || !a.schemaPlan.originalReply) return !1;
1245
+ const e = i.value;
1246
+ if (!e) return !1;
1247
+ e.commands.focus();
1248
+ const { from: t, to: n } = e.state.selection, s = e.commands.insertContentAt(
1249
+ { from: t, to: n },
1250
+ { type: "originalReply", content: [{ type: "paragraph" }] }
1251
+ );
1252
+ return s && Re(), s;
1253
+ }
1254
+ function kt() {
1255
+ return ke("separator", "separator", "分隔符", "{分隔符}");
1256
+ }
1257
+ function ht(e, t) {
1258
+ var s;
1259
+ const n = i.value;
1260
+ return !a.editable || !n || !((s = a.documentAdapter.extensions) != null && s.some(
1261
+ (d) => d.name === e
1262
+ )) ? !1 : n.chain().focus().insertContent([
1263
+ { type: e, attrs: t },
1264
+ { type: "text", text: " " }
1265
+ ]).run() || !1;
1266
+ }
1267
+ function bt(e, t = "lastCaret", n = !1) {
1268
+ var d;
1269
+ const s = i.value;
1270
+ if (!a.editable || !s || !e) return !1;
1271
+ if (t === "end") {
1272
+ const u = s.state.doc.childCount === 1 && ((d = s.state.doc.firstChild) == null ? void 0 : d.isTextblock) && s.state.doc.firstChild.content.size === 0, h = u ? 0 : s.state.doc.content.size, g = e.split(/\r\n?|\n/u).map((b) => ({
1273
+ type: "paragraph",
1274
+ ...b ? { content: [{ type: "text", text: b }] } : {}
1275
+ }));
1276
+ if (!s.commands.insertContentAt(
1277
+ u ? { from: 0, to: s.state.doc.content.size } : h,
1278
+ g
1279
+ ))
1280
+ return !1;
1281
+ if (n) {
1282
+ const b = s.state.doc.content.size;
1283
+ s.commands.setTextSelection({
1284
+ from: Math.min(h + 1, b),
1285
+ to: Math.max(h + 1, b - 1)
1286
+ });
1287
+ }
1288
+ return s.commands.focus(), !0;
1289
+ }
1290
+ return s.chain().focus().insertContent(e).run();
1291
+ }
1292
+ function Re() {
1293
+ const e = i.value;
1294
+ if (!e) return;
1295
+ const t = e.state.selection.from;
1296
+ let n = null;
1297
+ e.state.doc.descendants((s, d) => {
1298
+ s.type.name === "originalReply" && d < t && (n = d);
1299
+ }), n !== null && e.commands.setTextSelection(n + 2);
1300
+ }
1301
+ function Be(e, t, n) {
1302
+ if (!a.editable || !i.value || !e.length) return null;
1303
+ l = !0;
1304
+ try {
1305
+ const s = t.insert(e);
1306
+ return s && e.some((d) => d.type === "originalReply") && Re(), s && n && i.value.commands.focus(), s ? i.value.getJSON() : null;
1307
+ } finally {
1308
+ l = !1;
1309
+ }
1310
+ }
1311
+ function vt(e) {
1312
+ if (!(!i.value || i.value.isDestroyed)) {
1313
+ l = !0;
1314
+ try {
1315
+ i.value.chain().setMeta("addToHistory", !1).setMeta(Q, me(e)).setContent(e, { emitUpdate: !1 }).run(), v.value = i.value.isEmpty, ye(e);
1316
+ } finally {
1317
+ l = !1;
1318
+ }
1319
+ }
1320
+ }
1321
+ function Tt() {
1322
+ var t;
1323
+ const e = new Set(y.keys());
1324
+ return (t = i.value) == null || t.state.doc.descendants((n) => {
1325
+ n.attrs.id && e.add(String(n.attrs.id));
1326
+ }), Me(e, ge);
1327
+ }
1328
+ function St(e, t, n, s) {
1329
+ if (!a.editable || !a.schemaPlan.mediaBlock) return null;
1330
+ const d = [
1331
+ {
1332
+ type: "mediaBlock",
1333
+ attrs: {
1334
+ id: Tt(),
1335
+ nodeVersion: 0,
1336
+ assetId: e.id || null,
1337
+ sourceType: e.sourceType || null,
1338
+ src: e.url,
1339
+ kind: e.kind,
1340
+ name: t,
1341
+ poster: e.posterUrl || null,
1342
+ status: "ready"
1343
+ }
1344
+ },
1345
+ { type: "paragraph" }
1346
+ ];
1347
+ return Be(d, n, s);
1348
+ }
1349
+ function At(e, t, n) {
1350
+ var s;
1351
+ return ((s = Oe([{ file: e, kind: t }], n)) == null ? void 0 : s[0]) || null;
1352
+ }
1353
+ function Oe(e, t) {
1354
+ if (!a.editable || !a.schemaPlan.mediaBlock || !i.value || !e.length)
1355
+ return null;
1356
+ const n = new Set(y.keys());
1357
+ i.value.state.doc.descendants((u) => {
1358
+ u.attrs.id && n.add(String(u.attrs.id));
1359
+ });
1360
+ const s = [], d = [];
1361
+ try {
1362
+ for (const { file: u, kind: h } of e) {
1363
+ const g = Me(n, ge);
1364
+ n.add(g);
1365
+ const b = URL.createObjectURL(u);
1366
+ y.set(g, b), s.push(g), d.push({
1367
+ type: "mediaBlock",
1368
+ attrs: {
1369
+ id: g,
1370
+ nodeVersion: 0,
1371
+ assetId: null,
1372
+ src: b,
1373
+ kind: h,
1374
+ name: u.name,
1375
+ poster: null,
1376
+ status: "uploading",
1377
+ error: ""
1378
+ }
1379
+ });
1380
+ }
1381
+ if (d.push({ type: "paragraph" }), t.insert(d)) return s;
1382
+ } catch {
1383
+ }
1384
+ return s.forEach(J), null;
1385
+ }
1386
+ function he(e) {
1387
+ const t = i.value;
1388
+ if (!t || t.isDestroyed) return null;
1389
+ let n = null;
1390
+ return t.state.doc.descendants((s) => {
1391
+ s.type.name === "mediaBlock" && s.attrs.id === e && Number.isSafeInteger(s.attrs.nodeVersion) && s.attrs.nodeVersion >= 0 && (n = {
1392
+ kind: s.attrs.kind,
1393
+ status: s.attrs.status,
1394
+ nodeVersion: s.attrs.nodeVersion
1395
+ });
1396
+ }), n;
1397
+ }
1398
+ function be(e, t, n, s) {
1399
+ const d = i.value;
1400
+ if (!d || d.isDestroyed || !Number.isSafeInteger(t) || t < 0 || t >= Number.MAX_SAFE_INTEGER)
1401
+ return !1;
1402
+ let u = null;
1403
+ if (d.state.doc.descendants((g, b) => {
1404
+ g.type.name === "mediaBlock" && g.attrs.id === e && (u = b);
1405
+ }), u === null) return !1;
1406
+ const h = d.state.doc.nodeAt(u);
1407
+ return !h || h.attrs.nodeVersion !== t || h.attrs.status !== n ? !1 : (d.view.dispatch(
1408
+ d.state.tr.setNodeMarkup(u, void 0, {
1409
+ ...h.attrs,
1410
+ ...s,
1411
+ nodeVersion: t + 1
1412
+ }).setMeta("addToHistory", !1)
1413
+ ), !0);
1414
+ }
1415
+ function Mt(e, t) {
1416
+ var h, g, b, M;
1417
+ const n = i.value;
1418
+ if (!a.editable || !n || n.isDestroyed) return !1;
1419
+ let s = null, d = 0;
1420
+ if (n.state.doc.descendants((E, B) => {
1421
+ E.type.name === "mediaBlock" && E.attrs.id === e.nodeId && (s = B, d++);
1422
+ }), d !== 1 || s === null) return !1;
1423
+ const u = n.state.doc.nodeAt(s);
1424
+ if (!u || u.attrs.kind !== t || u.attrs.status !== "uploading" || u.attrs.nodeVersion !== e.expectedNodeVersion || e.node.type !== "mediaBlock" || ((h = e.node.attrs) == null ? void 0 : h.id) !== e.nodeId || ((g = e.node.attrs) == null ? void 0 : g.kind) !== t || ((b = e.node.attrs) == null ? void 0 : b.nodeVersion) !== e.expectedNodeVersion + 1)
1425
+ return !1;
1426
+ try {
1427
+ n.view.dispatch(
1428
+ n.state.tr.setNodeMarkup(s, void 0, e.node.attrs).setMeta("addToHistory", !1)
1429
+ );
1430
+ } catch {
1431
+ return !1;
1432
+ }
1433
+ return ((M = he(e.nodeId)) == null ? void 0 : M.status) !== "ready" ? !1 : (J(e.nodeId), !0);
1434
+ }
1435
+ function Pe(e, t) {
1436
+ var u, h;
1437
+ const n = i.value;
1438
+ if (!a.editable || !n || n.isDestroyed || !e.length)
1439
+ return null;
1440
+ const s = /* @__PURE__ */ new Set(), d = [];
1441
+ for (const g of e) {
1442
+ if (s.has(g.nodeId)) return null;
1443
+ s.add(g.nodeId);
1444
+ let b = null, M = 0;
1445
+ if (n.state.doc.descendants((B, L) => {
1446
+ ce(B.type.name) && B.attrs.id === g.nodeId && (b = L, M++);
1447
+ }), M !== 1 || b === null) return null;
1448
+ const E = n.state.doc.nodeAt(b);
1449
+ if (!E || _e(E.type.name, E.attrs) !== t || E.attrs.nodeVersion !== g.expectedNodeVersion || E.type.name === "originalReply" && en(E.toJSON()) || g.kind === "updateNode" && (E.type.name === "mediaBlock" || g.node.type !== E.type.name || ((u = g.node.attrs) == null ? void 0 : u.id) !== g.nodeId || ((h = g.node.attrs) == null ? void 0 : h.nodeVersion) !== g.expectedNodeVersion + 1 || _e(g.node.type, g.node.attrs) !== t))
1450
+ return null;
1451
+ d.push({ plan: g, position: b, size: E.nodeSize });
1452
+ }
1453
+ try {
1454
+ let g = n.state.tr;
1455
+ for (const { plan: b, position: M, size: E } of d.sort(
1456
+ (B, L) => L.position - B.position
1457
+ ))
1458
+ b.kind === "removeNode" ? g = g.delete(M, M + E) : g = g.replaceWith(
1459
+ M,
1460
+ M + E,
1461
+ n.schema.nodeFromJSON(b.node)
1462
+ );
1463
+ return g.doc.check(), g.setMeta(
1464
+ Q,
1465
+ e.filter((b) => b.kind === "updateNode").map((b) => b.nodeId)
1466
+ ), { transaction: g, requestedIds: s };
1467
+ } catch {
1468
+ return null;
1469
+ }
1470
+ }
1471
+ function Ct(e, t) {
1472
+ var n;
1473
+ return ((n = Pe(e, t)) == null ? void 0 : n.transaction.doc.toJSON()) || null;
1474
+ }
1475
+ function ze(e, t) {
1476
+ const n = Pe(e, t), s = i.value;
1477
+ if (!n || !s || s.isDestroyed) return !1;
1478
+ const { transaction: d, requestedIds: u } = n;
1479
+ try {
1480
+ s.view.dispatch(d);
1481
+ } catch {
1482
+ return !1;
1483
+ }
1484
+ const h = /* @__PURE__ */ new Map();
1485
+ return s.state.doc.descendants((g) => {
1486
+ ce(g.type.name) && u.has(g.attrs.id) && h.set(g.attrs.id, g.attrs.nodeVersion);
1487
+ }), e.every(
1488
+ (g) => g.kind === "removeNode" ? !h.has(g.nodeId) : h.get(g.nodeId) === g.expectedNodeVersion + 1
1489
+ );
1490
+ }
1491
+ function Et(e, t) {
1492
+ return ze([e], t);
1493
+ }
1494
+ function wt(e, t, n) {
1495
+ return be(e, n, "uploading", {
1496
+ status: "error",
1497
+ error: t
1498
+ });
1499
+ }
1500
+ function It(e, t, n) {
1501
+ const s = he(e);
1502
+ if ((s == null ? void 0 : s.kind) !== n.kind || !ue(n.url)) return !1;
1503
+ const d = be(e, t, "uploading", {
1504
+ status: "ready",
1505
+ src: n.url,
1506
+ assetId: n.id || null,
1507
+ poster: n.posterUrl || null,
1508
+ error: ""
1509
+ });
1510
+ return d && J(e), d;
1511
+ }
1512
+ function Nt(e, t) {
1513
+ return be(e, t, "error", {
1514
+ status: "uploading",
1515
+ error: ""
1516
+ });
1517
+ }
1518
+ function xt(e, t, n) {
1519
+ const s = i.value;
1520
+ if (!s || s.isDestroyed || !Number.isFinite(n))
1521
+ return !1;
1522
+ let d = !1;
1523
+ return s.state.doc.descendants((u) => {
1524
+ u.type.name === "mediaBlock" && u.attrs.id === e && u.attrs.status === "uploading" && u.attrs.nodeVersion === t && (d = !0);
1525
+ }), d ? (s.view.dom.dispatchEvent(
1526
+ new CustomEvent("fkp-media-progress", {
1527
+ detail: { id: e, percent: Math.round(Math.max(0, Math.min(100, n))) }
1528
+ })
1529
+ ), !0) : !1;
1530
+ }
1531
+ function Dt(e) {
1532
+ var n;
1533
+ const t = (n = e.detail) == null ? void 0 : n.id;
1534
+ typeof t == "string" && f("retry-media", t);
1535
+ }
1536
+ function Le() {
1537
+ const e = i.value;
1538
+ if (!e || e.isDestroyed) return null;
1539
+ const { selection: t } = e.state;
1540
+ let n;
1541
+ if (t instanceof j && t.empty) {
1542
+ const { $from: s } = t, d = s.start();
1543
+ if (s.parent.forEach((u, h) => {
1544
+ if (u.type.name !== "businessToken" || !u.attrs.id) return;
1545
+ const g = t.from - (d + h + u.nodeSize);
1546
+ g >= 0 && g <= 1 && (n = {
1547
+ id: String(u.attrs.id),
1548
+ kind: "inlineAfter",
1549
+ offset: g
1550
+ });
1551
+ }), !n && s.depth >= 1 && s.parent.isTextblock && s.parentOffset <= 1) {
1552
+ const u = s.depth - 1, h = s.index(u), g = s.node(u);
1553
+ for (let b = h - 1; b >= 0; b--) {
1554
+ const M = g.child(b);
1555
+ if (M.type.name === "mediaBlock" && M.attrs.id) {
1556
+ n = {
1557
+ id: String(M.attrs.id),
1558
+ kind: "blockAfter",
1559
+ offset: s.parentOffset,
1560
+ siblingOffset: h - b
1561
+ };
1562
+ break;
1563
+ }
1564
+ if (!M.isTextblock || M.content.size > 0) break;
1565
+ }
1566
+ }
1567
+ }
1568
+ return {
1569
+ from: t.from,
1570
+ to: t.to,
1571
+ focused: e.isFocused,
1572
+ ...n ? { nodeCaret: n } : {}
1573
+ };
1574
+ }
1575
+ function $e(e, t) {
1576
+ const n = e.state.doc.content.size;
1577
+ let s;
1578
+ const { nodeCaret: d } = t;
1579
+ d && t.from === t.to && e.state.doc.descendants((b, M) => {
1580
+ if (b.attrs.id !== d.id) return;
1581
+ if (d.kind === "inlineAfter") {
1582
+ if (b.type.name !== "businessToken") return;
1583
+ const U = e.state.doc.resolve(M).end();
1584
+ s = Math.min(
1585
+ M + b.nodeSize + d.offset,
1586
+ U
1587
+ );
1588
+ return;
1589
+ }
1590
+ if (b.type.name !== "mediaBlock") return;
1591
+ const E = e.state.doc.resolve(M), { parent: B } = E, L = E.index(), ne = L + d.siblingOffset, X = B.maybeChild(ne);
1592
+ if (X != null && X.isTextblock && Array.from(
1593
+ { length: d.siblingOffset - 1 },
1594
+ (U, oe) => B.child(L + oe + 1)
1595
+ ).every((U) => U.isTextblock && U.content.size === 0)) {
1596
+ let U = M;
1597
+ for (let oe = L; oe < ne; oe++)
1598
+ U += B.child(oe).nodeSize;
1599
+ s = Math.min(
1600
+ U + 1 + d.offset,
1601
+ U + X.nodeSize - 1
1602
+ );
1603
+ }
1604
+ });
1605
+ const u = {
1606
+ from: s ?? Math.min(t.from, n),
1607
+ to: s ?? Math.min(t.to, n)
1608
+ }, h = document.activeElement;
1609
+ t.focused && (!h || h === document.body || h === e.view.dom || !h.isConnected) ? e.chain().setTextSelection(u).focus().run() : e.commands.setTextSelection(u);
1610
+ }
1611
+ async function qe() {
1612
+ if (!(ee || !Z)) {
1613
+ ee = !0;
1614
+ try {
1615
+ for (let e = 0; e < 5 && !R; e++) {
1616
+ await He();
1617
+ const t = i.value;
1618
+ if (!t || t.isDestroyed || !t.view.dom.isConnected)
1619
+ continue;
1620
+ const n = Z;
1621
+ if (Z = null, !n) return;
1622
+ $e(t, n);
1623
+ return;
1624
+ }
1625
+ } finally {
1626
+ ee = !1;
1627
+ }
1628
+ }
1629
+ }
1630
+ function Vt(e) {
1631
+ e && (Z = e, qe());
1632
+ }
1633
+ function Fe(e) {
1634
+ const t = e.clipboardData, n = i.value;
1635
+ if (!a.editable || !n || !t) return null;
1636
+ const s = () => t.files.length ? je(n, n.state.selection.to) : null, d = t.getData("text/html"), { slice: u, handled: h } = bn(
1637
+ d,
1638
+ n.state.schema,
1639
+ a.pasteCapabilities || [],
1640
+ Array.from(t.files),
1641
+ a.documentAdapter.clipboard
1642
+ );
1643
+ if (u)
1644
+ return n.view.dispatch(
1645
+ n.state.tr.replaceSelection(u).setMeta("uiEvent", "paste")
1646
+ ), s();
1647
+ if (h) return null;
1648
+ const g = t.getData("text/plain");
1649
+ return g && n.view.pasteText(g, new Event("paste")), g ? s() : null;
1650
+ }
1651
+ function Rt(e) {
1652
+ const t = i.value;
1653
+ !t || !e.clipboardData || !(e.target instanceof Element) || !e.target.closest(".fkp-knowledge-document") || gn(
1654
+ e.clipboardData,
1655
+ t.state.selection.content(),
1656
+ t.state.schema,
1657
+ a.documentAdapter.clipboard
1658
+ ) && (e.preventDefault(), e.stopPropagation());
1659
+ }
1660
+ function Bt(e) {
1661
+ var t;
1662
+ e.defaultPrevented || (t = e.clipboardData) != null && t.files.length || !(e.target instanceof Element) || !e.target.closest(".fkp-knowledge-document") || (e.preventDefault(), e.stopPropagation(), Fe(e));
1663
+ }
1664
+ return o({
1665
+ validateTagValidity: async () => await p ? T.refresh() : { status: "unavailable", items: [] },
1666
+ pasteClipboardContent: Fe,
1667
+ isSelectionInsideOriginalReply: () => {
1668
+ const e = i.value;
1669
+ if (!e) return !1;
1670
+ const { selection: t } = e.state;
1671
+ for (let { depth: n } = t.$from; n > 0; n--)
1672
+ if (t.$from.node(n).type.name === "originalReply")
1673
+ return !0;
1674
+ return !1;
1675
+ },
1676
+ insertToken: ke,
1677
+ upsertToken: gt,
1678
+ insertInlineNode: ht,
1679
+ insertText: bt,
1680
+ insertOriginal: yt,
1681
+ insertSeparator: kt,
1682
+ insertBatch: Be,
1683
+ restoreDoc: vt,
1684
+ insertMedia: St,
1685
+ insertPendingMedia: At,
1686
+ insertPendingMediaBatch: Oe,
1687
+ applyNodeUpdate: Mt,
1688
+ applyPluginNodeOperation: Et,
1689
+ applyPluginNodeOperations: ze,
1690
+ previewPluginNodeOperations: Ct,
1691
+ failMedia: wt,
1692
+ completeMedia: It,
1693
+ retryMedia: Nt,
1694
+ getMediaState: he,
1695
+ reportMediaProgress: xt,
1696
+ captureSelection: Le,
1697
+ restoreSelection: Vt,
1698
+ captureMediaTarget: () => i.value ? vn(i.value) : null,
1699
+ whenReady: () => p,
1700
+ captureEndTarget: () => {
1701
+ var n;
1702
+ const e = i.value;
1703
+ if (!e) return null;
1704
+ const { doc: t } = e.state;
1705
+ return (n = t.lastChild) != null && n.isTextblock ? We(e, t.content.size - 1) : je(e, t.content.size);
1706
+ },
1707
+ captureMediaTargetAt: (e, t) => {
1708
+ const n = i.value, s = n ? xe({ clientX: e, clientY: t }) : null;
1709
+ return _(), N.value = null, n && s !== null ? We(n, s) : null;
1710
+ },
1711
+ focus: () => {
1712
+ var e;
1713
+ return (e = i.value) == null ? void 0 : e.commands.focus();
1714
+ },
1715
+ getJSON: () => {
1716
+ var e;
1717
+ return (e = i.value) == null ? void 0 : e.getJSON();
1718
+ }
1719
+ }), (e, t) => m.value ? (G(), W("div", Tn, "媒体编辑器加载失败,请刷新页面重试")) : (G(), W("div", {
1720
+ key: 1,
1721
+ ref_key: "areaRoot",
1722
+ ref: k,
1723
+ class: "fkp-knowledge-area",
1724
+ onFkpMediaRetry: Dt,
1725
+ onClick: ct,
1726
+ onMouseover: t[0] || (t[0] = (n) => {
1727
+ ot(n), w(n);
1728
+ }),
1729
+ onMouseout: t[1] || (t[1] = (n) => {
1730
+ it(n), P(n);
1731
+ }),
1732
+ onFocusin: w,
1733
+ onFocusout: C,
1734
+ onDragstartCapture: dt,
1735
+ onDragoverCapture: ut,
1736
+ onDragleaveCapture: pt,
1737
+ onDropCapture: ft,
1738
+ onDragendCapture: mt,
1739
+ onCopyCapture: Rt,
1740
+ onPasteCapture: Bt,
1741
+ onScrollCapture: se
1742
+ }, [
1743
+ Ke(le(qt), {
1744
+ class: "fkp-knowledge-editor",
1745
+ editor: i.value
1746
+ }, null, 8, ["editor"]),
1747
+ A.value ? (G(), Lt(le(Ht), {
1748
+ key: 0,
1749
+ "popup-visible": !0,
1750
+ trigger: [],
1751
+ position: "tl",
1752
+ "content-class": "fkp-order-remark-popover",
1753
+ "content-style": {
1754
+ width: "326px",
1755
+ maxWidth: "calc(100vw - 32px)",
1756
+ padding: "16px",
1757
+ border: "none",
1758
+ boxSizing: "border-box",
1759
+ maxHeight: "420px",
1760
+ overflowY: "auto"
1761
+ }
1762
+ }, {
1763
+ content: Te(() => [
1764
+ K("div", {
1765
+ class: "fkp-order-remark-detail",
1766
+ onMouseenter: F,
1767
+ onMouseleave: C
1768
+ }, [
1769
+ K("div", Sn, [
1770
+ t[2] || (t[2] = K("strong", null, "订单备注", -1)),
1771
+ A.value.contentMode === "smart" ? (G(), W("span", An, "智能提取")) : fe("", !0)
1772
+ ]),
1773
+ K("div", Mn, Ue(A.value.content), 1),
1774
+ K("div", Cn, [
1775
+ t[3] || (t[3] = K("span", null, "备注插旗", -1)),
1776
+ A.value.flag === "none" ? (G(), W("span", En, "不标记")) : (G(), W("span", {
1777
+ key: 1,
1778
+ class: "fkp-order-remark-detail-flag",
1779
+ role: "img",
1780
+ "aria-label": le(Qt)[A.value.flag],
1781
+ style: Se({
1782
+ backgroundColor: le(Wt)[A.value.flag]
1783
+ })
1784
+ }, null, 12, wn))
1785
+ ]),
1786
+ K("div", In, [
1787
+ t[4] || (t[4] = K("span", null, "备注位置", -1)),
1788
+ K("span", null, Ue(A.value.position === "first" ? "最前" : "最后"), 1)
1789
+ ])
1790
+ ], 32)
1791
+ ]),
1792
+ default: Te(() => [
1793
+ K("span", {
1794
+ class: "fkp-order-remark-anchor",
1795
+ style: Se(O.value)
1796
+ }, null, 4)
1797
+ ]),
1798
+ _: 1
1799
+ })) : fe("", !0),
1800
+ N.value ? (G(), W("div", {
1801
+ key: 1,
1802
+ class: "fkp-media-drop-line",
1803
+ style: Se({
1804
+ top: `${N.value.top}px`,
1805
+ left: `${N.value.left}px`,
1806
+ width: `${N.value.width}px`
1807
+ }),
1808
+ "aria-hidden": "true"
1809
+ }, null, 4)) : fe("", !0),
1810
+ e.referencePlaceholder && v.value ? (G(), W("div", Nn, [
1811
+ t[6] || (t[6] = K("span", { class: "fkp-reference-bracket" }, "<", -1)),
1812
+ Ke(le(Kt), {
1813
+ color: "arcoblue",
1814
+ size: "small",
1815
+ bordered: ""
1816
+ }, {
1817
+ default: Te(() => t[5] || (t[5] = [
1818
+ $t("参考话术")
1819
+ ])),
1820
+ _: 1
1821
+ }),
1822
+ t[7] || (t[7] = K("span", null, "请填写参考话术", -1)),
1823
+ t[8] || (t[8] = K("span", { class: "fkp-reference-bracket" }, ">", -1))
1824
+ ])) : fe("", !0)
1825
+ ], 544));
1826
+ }
1827
+ });
1828
+ export {
1829
+ Kn as _
1830
+ };