@freecallai/pro 0.0.4 → 0.0.6

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