@freecallai/pro 0.0.0-stage → 0.0.2

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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -2
  3. package/dist/FkpRichText.vue_vue_type_script_setup_true_lang-BuMz8Tyy.js +4416 -0
  4. package/dist/KnowledgeArea-BkRVWFrg.js +1224 -0
  5. package/dist/ToolForm-BSJxTJ7U.js +185 -0
  6. package/dist/choice-DDg5gNtS.js +29 -0
  7. package/dist/index-BVHYCLDv.js +5 -0
  8. package/dist/index-BnFTr8u9.js +49 -0
  9. package/dist/index-CG2j9Znw.js +41 -0
  10. package/dist/index-CJlAseSN.js +15 -0
  11. package/dist/index-CzpY61Qj.js +6 -0
  12. package/dist/index-D8bcFtWR.js +6 -0
  13. package/dist/index-DSgEWJGP.js +6 -0
  14. package/dist/index-DxxX09iY.js +6 -0
  15. package/dist/index-kOPLn4DD.js +5 -0
  16. package/dist/index-nnvfy5q0.js +31 -0
  17. package/dist/index-urNonkMH.js +6 -0
  18. package/dist/index.js +16 -0
  19. package/dist/inline-TT_dl8Y3.js +17 -0
  20. package/dist/knowledge-BZCmalF_.js +6 -0
  21. package/dist/knowledge-DnYGicjn.js +13 -0
  22. package/dist/media-extensions-ZoxmhIhH.js +276 -0
  23. package/dist/media-migration-Cj-3xrxd.js +59 -0
  24. package/dist/media-upload-D7DpMJYx.js +69 -0
  25. package/dist/operations-JgnjGx3H.js +19 -0
  26. package/dist/question-D1--acV8.js +10 -0
  27. package/dist/question-DGC6JHy5.js +6 -0
  28. package/dist/rich-text/index.js +224 -0
  29. package/dist/rich-text/legacy-converter/index.js +930 -0
  30. package/dist/rules-CC6NoltX.js +811 -0
  31. package/dist/selection-state-D47jhx0U.js +20 -0
  32. package/dist/state-KfOqha3d.js +16 -0
  33. package/dist/style.css +1 -0
  34. package/dist/types/index.d.ts +10 -0
  35. package/dist/types/rich-text/FkpRichText.vue.d.ts +253 -0
  36. package/dist/types/rich-text/MediaView.vue.d.ts +92 -0
  37. package/dist/types/rich-text/__demo__/conversion-fixtures.d.ts +35 -0
  38. package/dist/types/rich-text/__demo__/reasoning-template-examples.d.ts +12 -0
  39. package/dist/types/rich-text/config/catalog.d.ts +3 -0
  40. package/dist/types/rich-text/config/descriptor.d.ts +58 -0
  41. package/dist/types/rich-text/config/media-options.d.ts +6 -0
  42. package/dist/types/rich-text/config/resolve.d.ts +17 -0
  43. package/dist/types/rich-text/config/selection-options.d.ts +6 -0
  44. package/dist/types/rich-text/extensions.d.ts +6 -0
  45. package/dist/types/rich-text/index.d.ts +17 -0
  46. package/dist/types/rich-text/legacy-converter/business-attribute.d.ts +32 -0
  47. package/dist/types/rich-text/legacy-converter/index.d.ts +46 -0
  48. package/dist/types/rich-text/legacy-converter/tool-contract.d.ts +5 -0
  49. package/dist/types/rich-text/media-extensions.d.ts +4 -0
  50. package/dist/types/rich-text/media-id.d.ts +2 -0
  51. package/dist/types/rich-text/model/agent-context.d.ts +7 -0
  52. package/dist/types/rich-text/model/capability-diff.d.ts +14 -0
  53. package/dist/types/rich-text/model/condition-contract.d.ts +10 -0
  54. package/dist/types/rich-text/model/convert.d.ts +6 -0
  55. package/dist/types/rich-text/model/guard.d.ts +7 -0
  56. package/dist/types/rich-text/model/json-value.d.ts +2 -0
  57. package/dist/types/rich-text/model/media-migration.d.ts +8 -0
  58. package/dist/types/rich-text/model/node-contract.d.ts +10 -0
  59. package/dist/types/rich-text/model/node-identity.d.ts +8 -0
  60. package/dist/types/rich-text/model/persistence-contract.d.ts +25 -0
  61. package/dist/types/rich-text/model/preview.d.ts +2 -0
  62. package/dist/types/rich-text/model/question-text.d.ts +15 -0
  63. package/dist/types/rich-text/model/reasoning-context.d.ts +24 -0
  64. package/dist/types/rich-text/model/scene-snapshot.d.ts +4 -0
  65. package/dist/types/rich-text/model/validate.d.ts +19 -0
  66. package/dist/types/rich-text/model/web-url.d.ts +2 -0
  67. package/dist/types/rich-text/plugins/agentSelect/descriptor.d.ts +2 -0
  68. package/dist/types/rich-text/plugins/attribute/descriptor.d.ts +2 -0
  69. package/dist/types/rich-text/plugins/attribute/index.d.ts +2 -0
  70. package/dist/types/rich-text/plugins/block.d.ts +3 -0
  71. package/dist/types/rich-text/plugins/choice.d.ts +4 -0
  72. package/dist/types/rich-text/plugins/image/descriptor.d.ts +2 -0
  73. package/dist/types/rich-text/plugins/image/index.d.ts +2 -0
  74. package/dist/types/rich-text/plugins/inline.d.ts +3 -0
  75. package/dist/types/rich-text/plugins/media-upload.d.ts +3 -0
  76. package/dist/types/rich-text/plugins/memory/descriptor.d.ts +2 -0
  77. package/dist/types/rich-text/plugins/memory/index.d.ts +2 -0
  78. package/dist/types/rich-text/plugins/operations.d.ts +86 -0
  79. package/dist/types/rich-text/plugins/originalReply/descriptor.d.ts +2 -0
  80. package/dist/types/rich-text/plugins/originalReply/knowledge.d.ts +2 -0
  81. package/dist/types/rich-text/plugins/originalReply/question.d.ts +2 -0
  82. package/dist/types/rich-text/plugins/reasoningPolish/descriptor.d.ts +2 -0
  83. package/dist/types/rich-text/plugins/reasoningPolish/index.d.ts +3 -0
  84. package/dist/types/rich-text/plugins/reasoningTemplate/descriptor.d.ts +2 -0
  85. package/dist/types/rich-text/plugins/reasoningTemplate/index.d.ts +3 -0
  86. package/dist/types/rich-text/plugins/registry.d.ts +14 -0
  87. package/dist/types/rich-text/plugins/selection-state.d.ts +4 -0
  88. package/dist/types/rich-text/plugins/separator/descriptor.d.ts +2 -0
  89. package/dist/types/rich-text/plugins/separator/index.d.ts +2 -0
  90. package/dist/types/rich-text/plugins/state.d.ts +3 -0
  91. package/dist/types/rich-text/plugins/tagged/descriptor.d.ts +2 -0
  92. package/dist/types/rich-text/plugins/tagged/index.d.ts +2 -0
  93. package/dist/types/rich-text/plugins/ticket/descriptor.d.ts +2 -0
  94. package/dist/types/rich-text/plugins/ticket/index.d.ts +2 -0
  95. package/dist/types/rich-text/plugins/todo/descriptor.d.ts +2 -0
  96. package/dist/types/rich-text/plugins/todo/knowledge.d.ts +2 -0
  97. package/dist/types/rich-text/plugins/todo/question.d.ts +2 -0
  98. package/dist/types/rich-text/plugins/tool/descriptor.d.ts +2 -0
  99. package/dist/types/rich-text/plugins/tool/index.d.ts +2 -0
  100. package/dist/types/rich-text/plugins/tool/operations.d.ts +4 -0
  101. package/dist/types/rich-text/plugins/tool/presentation.d.ts +7 -0
  102. package/dist/types/rich-text/plugins/tool/rules.d.ts +34 -0
  103. package/dist/types/rich-text/plugins/variable/descriptor.d.ts +2 -0
  104. package/dist/types/rich-text/plugins/variable/index.d.ts +2 -0
  105. package/dist/types/rich-text/plugins/video/descriptor.d.ts +2 -0
  106. package/dist/types/rich-text/plugins/video/index.d.ts +2 -0
  107. package/dist/types/rich-text/public/types.d.ts +598 -0
  108. package/dist/types/rich-text/runtime/action-ports.d.ts +15 -0
  109. package/dist/types/rich-text/runtime/file-drop-guard.d.ts +2 -0
  110. package/dist/types/rich-text/runtime/media-policy.d.ts +15 -0
  111. package/dist/types/rich-text/runtime/media-state.d.ts +6 -0
  112. package/dist/types/rich-text/runtime/media-target.d.ts +9 -0
  113. package/dist/types/rich-text/runtime/media-upload-session.d.ts +63 -0
  114. package/dist/types/rich-text/runtime/media-upload-slots.d.ts +4 -0
  115. package/dist/types/rich-text/runtime/operations.d.ts +48 -0
  116. package/dist/types/rich-text/runtime/option-menu-session.d.ts +28 -0
  117. package/dist/types/rich-text/runtime/option-source.d.ts +10 -0
  118. package/dist/types/rich-text/runtime/port-result.d.ts +21 -0
  119. package/dist/types/rich-text/runtime/schema-plan.d.ts +17 -0
  120. package/dist/types/rich-text/runtime/tool-form-session.d.ts +39 -0
  121. package/dist/types/rich-text/runtime/tool-params.d.ts +5 -0
  122. package/dist/types/rich-text/types.d.ts +40 -0
  123. package/dist/types/rich-text/ui/CapabilityHelp.vue.d.ts +9 -0
  124. package/dist/types/rich-text/ui/KnowledgeArea.vue.d.ts +124 -0
  125. package/dist/types/rich-text/ui/ToolForm.vue.d.ts +14 -0
  126. package/dist/types/rich-text/ui/VariableOptionList.vue.d.ts +15 -0
  127. package/package.json +70 -3
@@ -0,0 +1,1224 @@
1
+ import { defineComponent as ft, shallowRef as pt, ref as _, onBeforeUnmount as Ie, watch as G, nextTick as Ne, onMounted as mt, openBlock as B, createElementBlock as z, createVNode as Ae, unref as q, createBlock as kt, withCtx as ae, createElementVNode as I, normalizeStyle as re, createCommentVNode as W, toDisplayString as De, createTextVNode as gt } from "vue";
2
+ import { EditorContent as yt, Editor as ht } from "@tiptap/vue-3";
3
+ import { Popover as vt, Tag as bt } from "@freecallai/ui";
4
+ import { Plugin as Ve, PluginKey as Tt, Selection as Mt, TextSelection as St } from "@tiptap/pm/state";
5
+ import wt from "@tiptap/starter-kit";
6
+ import Ct from "@tiptap/extension-placeholder";
7
+ import { Extension as Et, Node as ie } from "@tiptap/core";
8
+ import { DecorationSet as xt, Decoration as It } from "@tiptap/pm/view";
9
+ import { glyphs as A } from "@freecallai/icons";
10
+ import { e as j, u as H, v as oe, w as Oe, x as Q, y as Nt, t as At, r as Dt, j as Pt, C as Rt, l as Pe, m as Bt } from "./rules-CC6NoltX.js";
11
+ import { b as Re } from "./FkpRichText.vue_vue_type_script_setup_true_lang-BuMz8Tyy.js";
12
+ function se() {
13
+ const r = globalThis.crypto.getRandomValues(new Uint8Array(16));
14
+ r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128;
15
+ const u = Array.from(
16
+ r,
17
+ (y) => y.toString(16).padStart(2, "0")
18
+ ).join("");
19
+ return `${u.slice(0, 8)}-${u.slice(8, 12)}-${u.slice(
20
+ 12,
21
+ 16
22
+ )}-${u.slice(16, 20)}-${u.slice(20)}`;
23
+ }
24
+ function $t(r, u) {
25
+ if (r !== "order_note" && r !== "small_payment") return null;
26
+ const y = u && typeof u == "object" && !Array.isArray(u) ? u : {};
27
+ if (r === "small_payment") {
28
+ const m = typeof y.amount == "string" ? y.amount : "", M = /^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/.test(m), [h = "", i = ""] = m.split(".");
29
+ return {
30
+ label: "小额打款",
31
+ iconGlyph: A.tool,
32
+ summary: M ? `¥${h}.${i.padEnd(2, "0")}` : ""
33
+ };
34
+ }
35
+ const d = y.contentMode === "smart" ? "智能提取" : typeof y.content == "string" ? y.content.replace(/\s+/g, " ").trim() : "";
36
+ return { label: "备注", iconGlyph: A["msg-tag"], summary: d };
37
+ }
38
+ const Vt = Et.create({
39
+ name: "uniqueExtensionNodeIds",
40
+ addProseMirrorPlugins() {
41
+ return [
42
+ new Ve({
43
+ appendTransaction(r, u, y) {
44
+ if (!r.some((g) => g.docChanged))
45
+ return null;
46
+ const d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
47
+ u.doc.descendants((g, v) => {
48
+ if (!j(g.type.name) || !g.attrs.id) return;
49
+ m.set(String(g.attrs.id), g);
50
+ let b = v;
51
+ for (const $ of r)
52
+ b = $.mapping.mapResult(b, 1).pos;
53
+ const x = y.doc.nodeAt(b);
54
+ (x == null ? void 0 : x.type.name) === g.type.name && x.attrs.id === g.attrs.id && d.set(String(g.attrs.id), b);
55
+ });
56
+ const M = /* @__PURE__ */ new Set();
57
+ for (const g of r) {
58
+ const v = g.getMeta(H);
59
+ Array.isArray(v) && v.forEach((b) => {
60
+ typeof b == "string" && b && M.add(b);
61
+ });
62
+ }
63
+ const h = /* @__PURE__ */ new Set();
64
+ y.doc.descendants((g) => {
65
+ j(g.type.name) && g.attrs.id && h.add(String(g.attrs.id));
66
+ });
67
+ const i = /* @__PURE__ */ new Set(), { tr: C } = y, S = r.some(
68
+ (g) => g.getMeta("uiEvent") === "drop"
69
+ );
70
+ return y.doc.descendants((g, v) => {
71
+ var V;
72
+ if (!j(g.type.name)) return;
73
+ let b = String(g.attrs.id || "");
74
+ const x = d.get(b);
75
+ !!b && !i.has(b) && (x === v || S && x === void 0 && ((V = m.get(b)) == null ? void 0 : V.eq(g)) || x === void 0 && M.has(b)) || (b = oe(h, se), C.setNodeMarkup(v, void 0, {
76
+ ...g.attrs,
77
+ id: b,
78
+ nodeVersion: 0
79
+ }), h.add(b)), i.add(b);
80
+ }), C.docChanged ? C.setMeta("addToHistory", !1) : null;
81
+ }
82
+ })
83
+ ];
84
+ }
85
+ }), Ot = ie.create({
86
+ name: "businessToken",
87
+ group: "inline",
88
+ inline: !0,
89
+ atom: !0,
90
+ selectable: !0,
91
+ addAttributes() {
92
+ return {
93
+ id: { default: "" },
94
+ nodeVersion: { default: 0 },
95
+ kind: { default: "variable" },
96
+ key: { default: "" },
97
+ label: { default: "" },
98
+ token: { default: null },
99
+ params: { default: null }
100
+ };
101
+ },
102
+ parseHTML() {
103
+ return [
104
+ {
105
+ tag: "span[data-business-token]",
106
+ getAttrs: (r) => ({
107
+ kind: r.getAttribute("data-kind"),
108
+ key: r.getAttribute("data-key"),
109
+ label: r.getAttribute("data-label") || r.textContent,
110
+ token: r.getAttribute("data-token"),
111
+ params: null
112
+ })
113
+ }
114
+ ];
115
+ },
116
+ renderHTML({ node: r }) {
117
+ const u = Oe(r.attrs.kind) ? r.attrs.kind : null, y = u === "todo" ? A.Followup : u === "attribute" ? A.data : A["AI-ticket"], d = r.attrs.kind === "variable" ? A.variate : r.attrs.kind === "separator" ? A.sep : null, m = r.attrs.kind === "tool" ? $t(r.attrs.key, r.attrs.params) : null, M = m ? r.attrs.key === "order_note" ? " fkp-tool-note fkp-tool-note--order-note" : " fkp-tool-note fkp-tool-note--small-payment" : "", h = r.attrs.kind === "tool" && !m, i = String(r.attrs.label || r.attrs.key || ""), C = i.startsWith("#") && i.endsWith("#") ? i : `#${i}#`, { summary: S } = m || { summary: "" };
118
+ return [
119
+ "span",
120
+ {
121
+ "data-business-token": "",
122
+ "data-kind": r.attrs.kind,
123
+ "data-key": r.attrs.key,
124
+ "data-node-id": r.attrs.id,
125
+ "data-token": r.attrs.token,
126
+ ...m || u || d || h ? {
127
+ "data-label": r.attrs.label,
128
+ "aria-label": m ? S ? `${m.label}:${S}` : m.label : d ? String(r.attrs.label) : `${u === "todo" ? "待办" : u === "attribute" ? "属性" : "工单"}:${r.attrs.label}`
129
+ } : {},
130
+ class: `fk-token fk-token--${r.attrs.kind} fkp-knowledge-tag fkp-knowledge-tag--${r.attrs.kind}${M}`,
131
+ contenteditable: "false"
132
+ },
133
+ ...m ? [
134
+ [
135
+ "span",
136
+ { class: "fkp-icon fkp-tool-note-icon", "aria-hidden": "true" },
137
+ m.iconGlyph
138
+ ],
139
+ ["span", { class: "fkp-tool-note-label" }, m.label],
140
+ ...S ? [
141
+ [
142
+ "span",
143
+ { class: "fkp-tool-note-divider", "aria-hidden": "true" }
144
+ ],
145
+ ["span", { class: "fkp-tool-note-summary" }, S]
146
+ ] : []
147
+ ] : u ? [
148
+ [
149
+ "span",
150
+ {
151
+ class: `fkp-icon fkp-${u}-token-icon`,
152
+ "aria-hidden": "true"
153
+ },
154
+ y
155
+ ],
156
+ [
157
+ "span",
158
+ { class: `fkp-${u}-token-label` },
159
+ r.attrs.label
160
+ ],
161
+ [
162
+ "span",
163
+ {
164
+ class: `fkp-icon fkp-${u}-token-arrow`,
165
+ "aria-hidden": "true"
166
+ },
167
+ A["arrow-down"]
168
+ ]
169
+ ] : h ? [
170
+ [
171
+ "span",
172
+ {
173
+ class: "fkp-icon fkp-tool-token-icon",
174
+ "aria-hidden": "true"
175
+ },
176
+ A.tool
177
+ ],
178
+ ["span", { class: "fkp-tool-token-label" }, r.attrs.label]
179
+ ] : d ? [
180
+ [
181
+ "span",
182
+ {
183
+ class: "fkp-icon fkp-inline-token-icon",
184
+ "aria-hidden": "true"
185
+ },
186
+ d
187
+ ],
188
+ [
189
+ "span",
190
+ { class: "fkp-inline-token-label" },
191
+ r.attrs.kind === "variable" ? C : r.attrs.label
192
+ ]
193
+ ] : [r.attrs.label]
194
+ ];
195
+ },
196
+ renderText({ node: r }) {
197
+ const u = r.attrs.kind;
198
+ return u === "variable" ? String(r.attrs.token || `#${r.attrs.key}#`) : u === "todo" ? `{待办@${r.attrs.key}}` : u === "attribute" ? `{属性@${r.attrs.key}}` : u === "tool" ? `{工具@${r.attrs.key}}` : u === "separator" ? "{分隔符}" : String(r.attrs.label || r.attrs.key || "");
199
+ }
200
+ }), Be = new Tt(
201
+ "inlineReplyNeighbors"
202
+ );
203
+ function $e(r) {
204
+ const u = [];
205
+ r.forEach((d, m) => {
206
+ u.push({ node: d, position: m });
207
+ });
208
+ const y = /* @__PURE__ */ new Set();
209
+ return u.forEach(({ node: d }, m) => {
210
+ var M;
211
+ if (!(d.type.name !== "originalReply" || d.childCount !== 1 || ((M = d.firstChild) == null ? void 0 : M.type.name) !== "paragraph"))
212
+ for (const h of [u[m - 1], u[m + 1]])
213
+ (h == null ? void 0 : h.node.type.name) === "paragraph" && y.add(h.position);
214
+ }), xt.create(
215
+ r,
216
+ [...y].map((d) => {
217
+ const m = r.nodeAt(d);
218
+ return It.node(d, d + m.nodeSize, {
219
+ class: "fk-inline-reply-neighbor"
220
+ });
221
+ })
222
+ );
223
+ }
224
+ const Lt = ie.create({
225
+ name: "originalReply",
226
+ group: "block",
227
+ content: "(paragraph | mediaBlock | messageSeparator)+",
228
+ defining: !0,
229
+ isolating: !0,
230
+ addAttributes() {
231
+ return { id: { default: "" }, nodeVersion: { default: 0 } };
232
+ },
233
+ parseHTML() {
234
+ return [{ tag: "section[data-original-reply]" }];
235
+ },
236
+ renderHTML() {
237
+ return [
238
+ "section",
239
+ { "data-original-reply": "", class: "fk-original-reply" },
240
+ 0
241
+ ];
242
+ },
243
+ addProseMirrorPlugins() {
244
+ return [
245
+ new Ve({
246
+ key: Be,
247
+ state: {
248
+ init: (r, u) => $e(u.doc),
249
+ apply: (r, u, y) => r.docChanged ? $e(y.doc) : u
250
+ },
251
+ props: {
252
+ decorations(r) {
253
+ return Be.getState(r);
254
+ }
255
+ }
256
+ })
257
+ ];
258
+ }
259
+ }), zt = ie.create({
260
+ name: "messageSeparator",
261
+ group: "block",
262
+ atom: !0,
263
+ selectable: !0,
264
+ addAttributes() {
265
+ return { id: { default: "" }, nodeVersion: { default: 0 } };
266
+ },
267
+ parseHTML() {
268
+ return [{ tag: "div[data-message-separator]" }];
269
+ },
270
+ renderHTML() {
271
+ return [
272
+ "div",
273
+ { "data-message-separator": "", class: "fk-message-separator" },
274
+ [
275
+ "span",
276
+ {
277
+ class: "fk-separator-tag fkp-knowledge-tag fkp-knowledge-tag--primary"
278
+ },
279
+ "分隔符"
280
+ ]
281
+ ];
282
+ },
283
+ renderText() {
284
+ return `
285
+ {分隔符}
286
+ `;
287
+ }
288
+ });
289
+ function Ht(r) {
290
+ return Le(r, r.state.selection.getBookmark());
291
+ }
292
+ function Ft(r, u) {
293
+ if (r.isDestroyed || !Number.isInteger(u) || u < 0 || u > r.state.doc.content.size)
294
+ return null;
295
+ try {
296
+ const y = Mt.near(
297
+ r.state.doc.resolve(u)
298
+ ).getBookmark();
299
+ return Le(r, y);
300
+ } catch {
301
+ return null;
302
+ }
303
+ }
304
+ function Le(r, u) {
305
+ let y = u, d = !0, m = !0, M = !1, { from: h, to: i } = u.resolve(r.state.doc);
306
+ const C = ({ transaction: S }) => {
307
+ const g = S.mapping.mapResult(h, 1), v = S.mapping.mapResult(i, -1);
308
+ !M && (g.deletedAcross || v.deletedAcross) && (m = !1), h = g.pos, i = v.pos, y = y.map(S.mapping);
309
+ };
310
+ return r.on("transaction", C), {
311
+ status() {
312
+ return !d || r.isDestroyed ? "disposed" : m ? "ready" : "lost";
313
+ },
314
+ insert(S) {
315
+ if (!d || !m || r.isDestroyed) return !1;
316
+ try {
317
+ const g = y.resolve(r.state.doc);
318
+ M = !0;
319
+ try {
320
+ return r.chain().setMeta(H, Q(S)).insertContentAt(
321
+ { from: g.from, to: g.to },
322
+ S
323
+ ).run();
324
+ } finally {
325
+ M = !1;
326
+ }
327
+ } catch {
328
+ return !1;
329
+ }
330
+ },
331
+ dispose() {
332
+ d && (d = !1, r.off("transaction", C));
333
+ }
334
+ };
335
+ }
336
+ const _t = {
337
+ key: 0,
338
+ class: "fkp-knowledge-area",
339
+ role: "alert"
340
+ }, Ut = { class: "fkp-order-remark-detail-title" }, qt = {
341
+ key: 0,
342
+ class: "fkp-order-remark-extract"
343
+ }, jt = { class: "fkp-order-remark-detail-content" }, Jt = { class: "fkp-order-remark-detail-row" }, Kt = { key: 0 }, Yt = ["aria-label"], Xt = { class: "fkp-order-remark-detail-row" }, Gt = {
344
+ key: 2,
345
+ class: "fkp-reference-placeholder",
346
+ "aria-hidden": "true"
347
+ }, dn = /* @__PURE__ */ ft({
348
+ __name: "KnowledgeArea",
349
+ props: {
350
+ modelValue: {},
351
+ editable: { type: Boolean },
352
+ placeholder: {},
353
+ referencePlaceholder: { type: Boolean },
354
+ schemaPlan: {},
355
+ activeChoiceId: {}
356
+ },
357
+ emits: ["update:modelValue", "retry-media", "load-error", "edit-tool", "choice-menu", "leave-choice"],
358
+ setup(r, { expose: u, emit: y }) {
359
+ const d = r;
360
+ let m = !1;
361
+ const M = y, h = /* @__PURE__ */ new Map(), i = pt(), C = _(), S = _(!0), g = _(!1), v = _(null), b = _({});
362
+ let x = null;
363
+ function $() {
364
+ x && clearTimeout(x), x = null;
365
+ }
366
+ function V() {
367
+ $(), x = setTimeout(() => {
368
+ v.value = null;
369
+ }, 150);
370
+ }
371
+ function le(e) {
372
+ const { target: t } = e;
373
+ if (!(t instanceof Element) || !i.value) return;
374
+ const n = t.closest(
375
+ '[data-business-token][data-key="order_note"]'
376
+ );
377
+ n != null && n.dataset.nodeId && ($(), i.value.state.doc.descendants((a) => {
378
+ if (a.type.name !== "businessToken" || a.attrs.id !== n.dataset.nodeId)
379
+ return !0;
380
+ v.value = Dt(a.attrs.params) ? a.attrs.params : null;
381
+ const o = n.getBoundingClientRect();
382
+ return b.value = {
383
+ left: `${o.left}px`,
384
+ top: `${o.top}px`,
385
+ width: `${o.width}px`,
386
+ height: `${o.height}px`
387
+ }, !1;
388
+ }));
389
+ }
390
+ function ze(e) {
391
+ const { target: t } = e;
392
+ if (!(t instanceof Element)) return;
393
+ const n = t.closest('[data-business-token][data-key="order_note"]');
394
+ n && (!(e.relatedTarget instanceof Node) || !n.contains(e.relatedTarget)) && V();
395
+ }
396
+ Ie($);
397
+ let J = !1, O = null;
398
+ const E = _(null);
399
+ let D = null, L = null;
400
+ function K() {
401
+ D = null, L !== null && cancelAnimationFrame(L), L = null;
402
+ }
403
+ function P() {
404
+ K(), O = null, E.value = null;
405
+ }
406
+ function de(e) {
407
+ e.key === "Escape" && P();
408
+ }
409
+ function Z() {
410
+ if (!D) return;
411
+ const e = ke({
412
+ clientX: D.x,
413
+ clientY: D.y
414
+ }), t = e === null ? null : me(e, "file"), n = E.value;
415
+ (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) || (E.value = t);
416
+ }
417
+ G(
418
+ () => d.editable,
419
+ (e) => {
420
+ e || P();
421
+ }
422
+ );
423
+ function ce() {
424
+ L = null;
425
+ const e = C.value, t = D;
426
+ if (!e || !t || !d.editable) return;
427
+ const n = e.getBoundingClientRect(), a = Math.min(40, n.height / 3);
428
+ if (a <= 0) return;
429
+ const o = t.y < n.top + a ? -Math.ceil(12 * Math.min(1, (n.top + a - t.y) / a)) : t.y > n.bottom - a ? Math.ceil(12 * Math.min(1, (t.y - n.bottom + a) / a)) : 0, s = e.scrollHeight - e.clientHeight;
430
+ if (!o || s <= 0) return;
431
+ const c = Math.max(0, Math.min(s, e.scrollTop + o));
432
+ c !== e.scrollTop && (e.scrollTop = c, L = requestAnimationFrame(ce));
433
+ }
434
+ function He() {
435
+ v.value = null, D ? Z() : E.value = null;
436
+ }
437
+ let Y = null, ee = !1;
438
+ const ue = `[data-business-token]:is(${Rt.map(
439
+ (e) => `[data-kind="${e}"]`
440
+ ).join(", ")})`;
441
+ function X(e) {
442
+ const t = h.get(e);
443
+ t && (URL.revokeObjectURL(t), h.delete(e));
444
+ }
445
+ function te(e) {
446
+ return !d.editable || !(e.target instanceof Element) ? null : e.target.closest(ue);
447
+ }
448
+ function Fe(e) {
449
+ const t = te(e);
450
+ !t || e.relatedTarget instanceof Node && t.contains(e.relatedTarget) || fe(t);
451
+ }
452
+ function _e(e) {
453
+ const t = te(e);
454
+ t && (!(e.relatedTarget instanceof Node) || !t.contains(e.relatedTarget)) && M("leave-choice");
455
+ }
456
+ function fe(e) {
457
+ const { nodeId: t } = e.dataset;
458
+ !t || !i.value || i.value.state.doc.descendants((n) => n.type.name !== "businessToken" || n.attrs.id !== t ? !0 : (Oe(n.attrs.kind) && M("choice-menu", {
459
+ nodeId: t,
460
+ nodeVersion: Number(n.attrs.nodeVersion) || 0,
461
+ key: String(n.attrs.key),
462
+ kind: n.attrs.kind,
463
+ anchor: e
464
+ }), !1));
465
+ }
466
+ function Ue(e) {
467
+ if (!d.editable || !i.value) return;
468
+ const { target: t } = e;
469
+ if (!(t instanceof Element)) return;
470
+ const n = te(e);
471
+ if (n) {
472
+ fe(n);
473
+ return;
474
+ }
475
+ const a = t.closest(
476
+ '[data-business-token][data-kind="tool"]'
477
+ );
478
+ a && (v.value = null);
479
+ const o = a == null ? void 0 : a.dataset.nodeId;
480
+ o && i.value.state.doc.descendants((s) => {
481
+ if (s.type.name !== "businessToken" || s.attrs.id !== o)
482
+ return !0;
483
+ const { params: c } = s.attrs;
484
+ return M("edit-tool", {
485
+ nodeId: o,
486
+ nodeVersion: Number(s.attrs.nodeVersion) || 0,
487
+ key: String(s.attrs.key),
488
+ label: String(s.attrs.label || s.attrs.key),
489
+ params: c && typeof c == "object" && !Array.isArray(c) ? c : null
490
+ }), !1;
491
+ });
492
+ }
493
+ function qe(e) {
494
+ if (!d.editable || !i.value) return;
495
+ const { target: t } = e;
496
+ if (t === C.value || t === i.value.view.dom.parentElement) {
497
+ i.value.commands.focus("end");
498
+ return;
499
+ }
500
+ Ue(e);
501
+ }
502
+ function pe() {
503
+ var e;
504
+ (e = C.value) == null || e.querySelectorAll(ue).forEach(
505
+ (t) => t.classList.toggle(
506
+ "is-menu-open",
507
+ !!d.activeChoiceId && t.dataset.nodeId === d.activeChoiceId
508
+ )
509
+ );
510
+ }
511
+ G(
512
+ [() => d.activeChoiceId, () => d.modelValue],
513
+ () => void Ne(pe)
514
+ );
515
+ function je(e) {
516
+ var n;
517
+ const t = e.target instanceof Element ? e.target.closest(".fk-media[data-drag-handle]") : null;
518
+ !d.editable || !(t != null && t.dataset.mediaId) || (O = t.dataset.mediaId, E.value = null, (n = e.dataTransfer) == null || n.setData("application/x-fkp-media-id", O), e.dataTransfer && (e.dataTransfer.effectAllowed = "move"), e.stopPropagation());
519
+ }
520
+ function me(e, t) {
521
+ const n = i.value, a = C.value;
522
+ if (!n || !a) return null;
523
+ const { doc: o } = n.state, s = e === o.content.size, c = o.lastChild, l = s && c ? e - c.nodeSize : e, f = n.view.nodeDOM(l);
524
+ if (!(f instanceof HTMLElement)) return null;
525
+ const p = f.getBoundingClientRect(), k = a.getBoundingClientRect();
526
+ return {
527
+ top: (s ? p.bottom : p.top) - k.top + a.scrollTop,
528
+ left: a.scrollLeft,
529
+ width: a.clientWidth || k.right - k.left,
530
+ pos: e,
531
+ kind: t
532
+ };
533
+ }
534
+ function ke(e) {
535
+ const t = i.value;
536
+ if (!t) return null;
537
+ const { view: n } = t, a = n.posAtCoords({ left: e.clientX, top: e.clientY });
538
+ if (!a) {
539
+ const k = n.dom.children;
540
+ let T = 0, w = k.length;
541
+ for (; T < w; ) {
542
+ const R = Math.floor((T + w) / 2), N = k[R].getBoundingClientRect();
543
+ e.clientY > N.top + N.height / 2 ? T = R + 1 : w = R;
544
+ }
545
+ if (T === k.length) return n.state.doc.content.size;
546
+ const F = n.state.doc.resolve(n.posAtDOM(k[T], 0));
547
+ return F.depth ? F.before(1) : F.pos;
548
+ }
549
+ const { doc: o } = n.state, s = o.resolve(a.pos);
550
+ let c = s.depth ? s.before(1) : a.pos;
551
+ c === o.content.size && o.lastChild && (c -= o.lastChild.nodeSize);
552
+ const l = o.nodeAt(c), f = n.nodeDOM(c);
553
+ if (!l || !(f instanceof HTMLElement)) return null;
554
+ const p = f.getBoundingClientRect();
555
+ return e.clientY > p.top + p.height / 2 ? c + l.nodeSize : c;
556
+ }
557
+ function ge(e, t) {
558
+ const n = i.value;
559
+ if (!n) return null;
560
+ const a = /* @__PURE__ */ new Map();
561
+ n.state.doc.descendants((p, k) => {
562
+ p.type.name === "mediaBlock" && typeof p.attrs.id == "string" && a.set(p.attrs.id, { pos: k, size: p.nodeSize });
563
+ });
564
+ const o = a.get(t);
565
+ if (!o) return null;
566
+ const s = e.target instanceof Element ? e.target.closest(".fk-media[data-media-id]") : null, c = s == null ? void 0 : s.dataset.mediaId;
567
+ if (c === t) return null;
568
+ const l = c ? a.get(c) : void 0;
569
+ let f;
570
+ if (l && s) {
571
+ const p = o.pos < l.pos;
572
+ f = l.pos + (p ? l.size : 0);
573
+ } else {
574
+ const p = n.view.posAtCoords({
575
+ left: e.clientX,
576
+ top: e.clientY
577
+ });
578
+ if (!p) return null;
579
+ const k = [0];
580
+ n.state.doc.forEach((T, w) => {
581
+ k.push(w + T.nodeSize);
582
+ }), f = k.reduce(
583
+ (T, w) => Math.abs(w - p.pos) < Math.abs(T - p.pos) ? w : T
584
+ );
585
+ }
586
+ return f === o.pos || f === o.pos + o.size ? null : { source: o, insertion: f };
587
+ }
588
+ function Je(e) {
589
+ var t;
590
+ if (d.editable) {
591
+ if (O) {
592
+ e.preventDefault(), e.stopPropagation(), e.dataTransfer && (e.dataTransfer.dropEffect = "move");
593
+ const n = ge(e, O);
594
+ E.value = n ? me(n.insertion, "media") : null;
595
+ return;
596
+ }
597
+ !d.schemaPlan.mediaBlock || !Array.from(((t = e.dataTransfer) == null ? void 0 : t.types) || []).includes("Files") || (e.preventDefault(), e.stopPropagation(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"), D = { x: e.clientX, y: e.clientY }, Z(), L === null && (L = requestAnimationFrame(ce)));
598
+ }
599
+ }
600
+ function Ke(e) {
601
+ var l;
602
+ K();
603
+ const t = O;
604
+ if (!t) {
605
+ (l = e.dataTransfer) != null && l.files.length || (E.value = null);
606
+ return;
607
+ }
608
+ O = null, E.value = null, e.preventDefault(), e.stopPropagation();
609
+ const n = i.value;
610
+ if (!d.editable || !n || n.isDestroyed) return;
611
+ const a = ge(e, t);
612
+ if (!a) return;
613
+ const { source: o, insertion: s } = a, c = n.state.doc.nodeAt(o.pos);
614
+ if (!(!c || c.type.name !== "mediaBlock"))
615
+ try {
616
+ const f = n.state.tr.delete(
617
+ o.pos,
618
+ o.pos + o.size
619
+ );
620
+ f.insert(f.mapping.map(s), c), f.setMeta("uiEvent", "drop"), f.setMeta(H, [t]), n.view.dispatch(f);
621
+ } catch {
622
+ }
623
+ }
624
+ function Ye(e) {
625
+ const t = C.value;
626
+ if (!t || !E.value || e.relatedTarget instanceof Node && t.contains(e.relatedTarget))
627
+ return;
628
+ const n = t.getBoundingClientRect();
629
+ e.clientX >= n.left && e.clientX <= n.right && e.clientY >= n.top && e.clientY <= n.bottom || (K(), E.value = null);
630
+ }
631
+ function Xe() {
632
+ P();
633
+ }
634
+ function ne(e) {
635
+ const t = /* @__PURE__ */ new Set(), n = (a) => {
636
+ var o, s;
637
+ a.type === "mediaBlock" && typeof ((o = a.attrs) == null ? void 0 : o.id) == "string" && t.add(a.attrs.id), (s = a.content) == null || s.forEach(n);
638
+ };
639
+ n(e);
640
+ for (const a of h.keys()) t.has(a) || X(a);
641
+ }
642
+ function ye(e) {
643
+ i.value = new ht({
644
+ content: d.modelValue,
645
+ editable: d.editable,
646
+ extensions: [
647
+ wt.configure({
648
+ heading: !1,
649
+ dropcursor: { color: "#5278ff", width: 2 },
650
+ link: { openOnClick: !1, isAllowedUri: (t) => Pt(t) }
651
+ }),
652
+ Ct.configure({
653
+ placeholder: () => d.referencePlaceholder ? "" : d.placeholder || "填写知识内容"
654
+ }),
655
+ Vt,
656
+ ...d.schemaPlan.businessToken ? [Ot] : [],
657
+ ...d.schemaPlan.originalReply ? [Lt] : [],
658
+ ...d.schemaPlan.separator ? [zt] : [],
659
+ ...e
660
+ ],
661
+ editorProps: {
662
+ attributes: {
663
+ class: "fkp-knowledge-document",
664
+ role: "textbox",
665
+ "aria-label": "知识内容",
666
+ "aria-multiline": "true"
667
+ }
668
+ },
669
+ onUpdate: ({ editor: t }) => {
670
+ S.value = t.isEmpty;
671
+ const n = t.getJSON();
672
+ ne(n), m || M("update:modelValue", n);
673
+ }
674
+ }), S.value = i.value.isEmpty, pe(), xe();
675
+ }
676
+ mt(() => {
677
+ if (document.addEventListener("keydown", de), document.addEventListener("dragend", P), document.addEventListener("drop", P), !d.schemaPlan.mediaBlock) {
678
+ ye([]);
679
+ return;
680
+ }
681
+ import("./media-extensions-ZoxmhIhH.js").then(({ MediaBlock: e }) => {
682
+ J || ye([e.configure({ sceneStyle: !0 })]);
683
+ }).catch(() => {
684
+ J || (g.value = !0, M("load-error", "媒体编辑器加载失败,请刷新页面重试"));
685
+ });
686
+ }), G(
687
+ () => d.editable,
688
+ (e) => {
689
+ var t;
690
+ return (t = i.value) == null ? void 0 : t.setEditable(e);
691
+ }
692
+ ), G(
693
+ () => d.modelValue,
694
+ (e) => {
695
+ if (i.value && Re(e) !== Re(i.value.getJSON())) {
696
+ const t = Ce();
697
+ i.value.chain().setMeta(H, Q(e)).setContent(e, { emitUpdate: !1 }).run(), S.value = i.value.isEmpty, ne(e), D && Z(), t && Ee(i.value, t);
698
+ }
699
+ },
700
+ { deep: !0 }
701
+ ), Ie(() => {
702
+ var e;
703
+ J = !0, document.removeEventListener("keydown", de), document.removeEventListener("dragend", P), document.removeEventListener("drop", P), P();
704
+ for (const t of h.keys()) X(t);
705
+ (e = i.value) == null || e.destroy();
706
+ });
707
+ function he(e, t, n, a) {
708
+ var o;
709
+ !d.editable || !d.schemaPlan.businessToken || (o = i.value) == null || o.chain().focus().insertContent([
710
+ { type: "businessToken", attrs: { kind: e, key: t, label: n, token: a } },
711
+ { type: "text", text: " " }
712
+ ]).run();
713
+ }
714
+ function Ge() {
715
+ if (!d.editable || !d.schemaPlan.originalReply) return;
716
+ const e = i.value;
717
+ if (!e) return;
718
+ e.commands.focus();
719
+ const { from: t, to: n } = e.state.selection;
720
+ e.commands.insertContentAt(
721
+ { from: t, to: n },
722
+ { type: "originalReply", content: [{ type: "paragraph" }] }
723
+ ) && ve();
724
+ }
725
+ function We() {
726
+ he("separator", "separator", "分隔符", "{分隔符}");
727
+ }
728
+ function ve() {
729
+ const e = i.value;
730
+ if (!e) return;
731
+ const t = e.state.selection.from;
732
+ let n = null;
733
+ e.state.doc.descendants((a, o) => {
734
+ a.type.name === "originalReply" && o < t && (n = o);
735
+ }), n !== null && e.commands.setTextSelection(n + 2);
736
+ }
737
+ function Qe(e, t, n) {
738
+ if (!d.editable || !i.value || !e.length) return null;
739
+ m = !0;
740
+ try {
741
+ const a = t.insert(e);
742
+ return a && e.some((o) => o.type === "originalReply") && ve(), a && n && i.value.commands.focus(), a ? i.value.getJSON() : null;
743
+ } finally {
744
+ m = !1;
745
+ }
746
+ }
747
+ function Ze(e) {
748
+ if (!(!i.value || i.value.isDestroyed)) {
749
+ m = !0;
750
+ try {
751
+ i.value.chain().setMeta("addToHistory", !1).setMeta(H, Q(e)).setContent(e, { emitUpdate: !1 }).run(), S.value = i.value.isEmpty, ne(e);
752
+ } finally {
753
+ m = !1;
754
+ }
755
+ }
756
+ }
757
+ function et() {
758
+ var t;
759
+ const e = new Set(h.keys());
760
+ return (t = i.value) == null || t.state.doc.descendants((n) => {
761
+ n.attrs.id && e.add(String(n.attrs.id));
762
+ }), oe(e, se);
763
+ }
764
+ function tt(e, t, n) {
765
+ var o;
766
+ if (!d.editable || !d.schemaPlan.mediaBlock) return !1;
767
+ const a = [
768
+ {
769
+ type: "mediaBlock",
770
+ attrs: {
771
+ id: et(),
772
+ nodeVersion: 0,
773
+ assetId: e.id || null,
774
+ src: e.url,
775
+ kind: e.kind,
776
+ name: t,
777
+ poster: e.posterUrl || null,
778
+ status: "ready"
779
+ }
780
+ },
781
+ { type: "paragraph" }
782
+ ];
783
+ return n ? n.insert(a) : ((o = i.value) == null ? void 0 : o.chain().setMeta(H, Q(a)).focus().insertContent(a).run()) || !1;
784
+ }
785
+ function nt(e, t, n) {
786
+ var a;
787
+ return ((a = be([{ file: e, kind: t }], n)) == null ? void 0 : a[0]) || null;
788
+ }
789
+ function be(e, t) {
790
+ if (!d.editable || !d.schemaPlan.mediaBlock || !i.value || !e.length)
791
+ return null;
792
+ const n = new Set(h.keys());
793
+ i.value.state.doc.descendants((s) => {
794
+ s.attrs.id && n.add(String(s.attrs.id));
795
+ });
796
+ const a = [], o = [];
797
+ try {
798
+ for (const { file: s, kind: c } of e) {
799
+ const l = oe(n, se);
800
+ n.add(l);
801
+ const f = URL.createObjectURL(s);
802
+ h.set(l, f), a.push(l), o.push({
803
+ type: "mediaBlock",
804
+ attrs: {
805
+ id: l,
806
+ nodeVersion: 0,
807
+ assetId: null,
808
+ src: f,
809
+ kind: c,
810
+ name: s.name,
811
+ poster: null,
812
+ status: "uploading",
813
+ error: ""
814
+ }
815
+ });
816
+ }
817
+ if (o.push({ type: "paragraph" }), t.insert(o)) return a;
818
+ } catch {
819
+ }
820
+ return a.forEach(X), null;
821
+ }
822
+ function Te(e) {
823
+ const t = i.value;
824
+ if (!t || t.isDestroyed) return null;
825
+ let n = null;
826
+ return t.state.doc.descendants((a) => {
827
+ a.type.name === "mediaBlock" && a.attrs.id === e && Number.isSafeInteger(a.attrs.nodeVersion) && a.attrs.nodeVersion >= 0 && (n = {
828
+ kind: a.attrs.kind,
829
+ status: a.attrs.status,
830
+ nodeVersion: a.attrs.nodeVersion
831
+ });
832
+ }), n;
833
+ }
834
+ function Me(e, t, n, a) {
835
+ const o = i.value;
836
+ if (!o || o.isDestroyed || !Number.isSafeInteger(t) || t < 0 || t >= Number.MAX_SAFE_INTEGER)
837
+ return !1;
838
+ let s = null;
839
+ if (o.state.doc.descendants((l, f) => {
840
+ l.type.name === "mediaBlock" && l.attrs.id === e && (s = f);
841
+ }), s === null) return !1;
842
+ const c = o.state.doc.nodeAt(s);
843
+ return !c || c.attrs.nodeVersion !== t || c.attrs.status !== n ? !1 : (o.view.dispatch(
844
+ o.state.tr.setNodeMarkup(s, void 0, {
845
+ ...c.attrs,
846
+ ...a,
847
+ nodeVersion: t + 1
848
+ }).setMeta("addToHistory", !1)
849
+ ), !0);
850
+ }
851
+ function at(e, t) {
852
+ var c, l, f, p;
853
+ const n = i.value;
854
+ if (!d.editable || !n || n.isDestroyed) return !1;
855
+ let a = null, o = 0;
856
+ if (n.state.doc.descendants((k, T) => {
857
+ k.type.name === "mediaBlock" && k.attrs.id === e.nodeId && (a = T, o++);
858
+ }), o !== 1 || a === null) return !1;
859
+ const s = n.state.doc.nodeAt(a);
860
+ if (!s || s.attrs.kind !== t || s.attrs.status !== "uploading" || s.attrs.nodeVersion !== e.expectedNodeVersion || e.node.type !== "mediaBlock" || ((c = e.node.attrs) == null ? void 0 : c.id) !== e.nodeId || ((l = e.node.attrs) == null ? void 0 : l.kind) !== t || ((f = e.node.attrs) == null ? void 0 : f.nodeVersion) !== e.expectedNodeVersion + 1)
861
+ return !1;
862
+ try {
863
+ n.view.dispatch(
864
+ n.state.tr.setNodeMarkup(a, void 0, e.node.attrs).setMeta("addToHistory", !1)
865
+ );
866
+ } catch {
867
+ return !1;
868
+ }
869
+ return ((p = Te(e.nodeId)) == null ? void 0 : p.status) !== "ready" ? !1 : (X(e.nodeId), !0);
870
+ }
871
+ function Se(e, t) {
872
+ var s, c;
873
+ const n = i.value;
874
+ if (!d.editable || !n || n.isDestroyed || !e.length)
875
+ return null;
876
+ const a = /* @__PURE__ */ new Set(), o = [];
877
+ for (const l of e) {
878
+ if (a.has(l.nodeId)) return null;
879
+ a.add(l.nodeId);
880
+ let f = null, p = 0;
881
+ if (n.state.doc.descendants((T, w) => {
882
+ j(T.type.name) && T.attrs.id === l.nodeId && (f = w, p++);
883
+ }), p !== 1 || f === null) return null;
884
+ const k = n.state.doc.nodeAt(f);
885
+ if (!k || Pe(k.type.name, k.attrs) !== t || k.attrs.nodeVersion !== l.expectedNodeVersion || k.type.name === "originalReply" && Bt(k.toJSON()) || l.kind === "updateNode" && (k.type.name === "mediaBlock" || l.node.type !== k.type.name || ((s = l.node.attrs) == null ? void 0 : s.id) !== l.nodeId || ((c = l.node.attrs) == null ? void 0 : c.nodeVersion) !== l.expectedNodeVersion + 1 || Pe(l.node.type, l.node.attrs) !== t))
886
+ return null;
887
+ o.push({ plan: l, position: f, size: k.nodeSize });
888
+ }
889
+ try {
890
+ let l = n.state.tr;
891
+ for (const { plan: f, position: p, size: k } of o.sort(
892
+ (T, w) => w.position - T.position
893
+ ))
894
+ f.kind === "removeNode" ? l = l.delete(p, p + k) : l = l.replaceWith(
895
+ p,
896
+ p + k,
897
+ n.schema.nodeFromJSON(f.node)
898
+ );
899
+ return l.doc.check(), l.setMeta(
900
+ H,
901
+ e.filter((f) => f.kind === "updateNode").map((f) => f.nodeId)
902
+ ), { transaction: l, requestedIds: a };
903
+ } catch {
904
+ return null;
905
+ }
906
+ }
907
+ function rt(e, t) {
908
+ var n;
909
+ return ((n = Se(e, t)) == null ? void 0 : n.transaction.doc.toJSON()) || null;
910
+ }
911
+ function we(e, t) {
912
+ const n = Se(e, t), a = i.value;
913
+ if (!n || !a || a.isDestroyed) return !1;
914
+ const { transaction: o, requestedIds: s } = n;
915
+ try {
916
+ a.view.dispatch(o);
917
+ } catch {
918
+ return !1;
919
+ }
920
+ const c = /* @__PURE__ */ new Map();
921
+ return a.state.doc.descendants((l) => {
922
+ j(l.type.name) && s.has(l.attrs.id) && c.set(l.attrs.id, l.attrs.nodeVersion);
923
+ }), e.every(
924
+ (l) => l.kind === "removeNode" ? !c.has(l.nodeId) : c.get(l.nodeId) === l.expectedNodeVersion + 1
925
+ );
926
+ }
927
+ function ot(e, t) {
928
+ return we([e], t);
929
+ }
930
+ function st(e, t, n) {
931
+ return Me(e, n, "uploading", {
932
+ status: "error",
933
+ error: t
934
+ });
935
+ }
936
+ function it(e, t) {
937
+ return Me(e, t, "error", {
938
+ status: "uploading",
939
+ error: ""
940
+ });
941
+ }
942
+ function lt(e, t, n) {
943
+ const a = i.value;
944
+ if (!a || a.isDestroyed || !Number.isFinite(n))
945
+ return !1;
946
+ let o = !1;
947
+ return a.state.doc.descendants((s) => {
948
+ s.type.name === "mediaBlock" && s.attrs.id === e && s.attrs.status === "uploading" && s.attrs.nodeVersion === t && (o = !0);
949
+ }), o ? (a.view.dom.dispatchEvent(
950
+ new CustomEvent("fkp-media-progress", {
951
+ detail: { id: e, percent: Math.round(Math.max(0, Math.min(100, n))) }
952
+ })
953
+ ), !0) : !1;
954
+ }
955
+ function dt(e) {
956
+ var n;
957
+ const t = (n = e.detail) == null ? void 0 : n.id;
958
+ typeof t == "string" && M("retry-media", t);
959
+ }
960
+ function Ce() {
961
+ const e = i.value;
962
+ if (!e || e.isDestroyed) return null;
963
+ const { selection: t } = e.state;
964
+ let n;
965
+ if (t instanceof St && t.empty) {
966
+ const { $from: a } = t, o = a.start();
967
+ if (a.parent.forEach((s, c) => {
968
+ if (s.type.name !== "businessToken" || !s.attrs.id) return;
969
+ const l = t.from - (o + c + s.nodeSize);
970
+ l >= 0 && l <= 1 && (n = {
971
+ id: String(s.attrs.id),
972
+ kind: "inlineAfter",
973
+ offset: l
974
+ });
975
+ }), !n && a.depth >= 1 && a.parent.isTextblock && a.parentOffset <= 1) {
976
+ const s = a.depth - 1, c = a.index(s), l = a.node(s);
977
+ for (let f = c - 1; f >= 0; f--) {
978
+ const p = l.child(f);
979
+ if (p.type.name === "mediaBlock" && p.attrs.id) {
980
+ n = {
981
+ id: String(p.attrs.id),
982
+ kind: "blockAfter",
983
+ offset: a.parentOffset,
984
+ siblingOffset: c - f
985
+ };
986
+ break;
987
+ }
988
+ if (!p.isTextblock || p.content.size > 0) break;
989
+ }
990
+ }
991
+ }
992
+ return {
993
+ from: t.from,
994
+ to: t.to,
995
+ focused: e.isFocused,
996
+ ...n ? { nodeCaret: n } : {}
997
+ };
998
+ }
999
+ function Ee(e, t) {
1000
+ const n = e.state.doc.content.size;
1001
+ let a;
1002
+ const { nodeCaret: o } = t;
1003
+ o && t.from === t.to && e.state.doc.descendants((f, p) => {
1004
+ if (f.attrs.id !== o.id) return;
1005
+ if (o.kind === "inlineAfter") {
1006
+ if (f.type.name !== "businessToken") return;
1007
+ const N = e.state.doc.resolve(p).end();
1008
+ a = Math.min(
1009
+ p + f.nodeSize + o.offset,
1010
+ N
1011
+ );
1012
+ return;
1013
+ }
1014
+ if (f.type.name !== "mediaBlock") return;
1015
+ const k = e.state.doc.resolve(p), { parent: T } = k, w = k.index(), F = w + o.siblingOffset, R = T.maybeChild(F);
1016
+ if (R != null && R.isTextblock && Array.from(
1017
+ { length: o.siblingOffset - 1 },
1018
+ (N, U) => T.child(w + U + 1)
1019
+ ).every((N) => N.isTextblock && N.content.size === 0)) {
1020
+ let N = p;
1021
+ for (let U = w; U < F; U++)
1022
+ N += T.child(U).nodeSize;
1023
+ a = Math.min(
1024
+ N + 1 + o.offset,
1025
+ N + R.nodeSize - 1
1026
+ );
1027
+ }
1028
+ });
1029
+ const s = {
1030
+ from: a ?? Math.min(t.from, n),
1031
+ to: a ?? Math.min(t.to, n)
1032
+ }, c = document.activeElement;
1033
+ t.focused && (!c || c === document.body || c === e.view.dom || !c.isConnected) ? e.chain().setTextSelection(s).focus().run() : e.commands.setTextSelection(s);
1034
+ }
1035
+ async function xe() {
1036
+ if (!(ee || !Y)) {
1037
+ ee = !0;
1038
+ try {
1039
+ for (let e = 0; e < 5 && !J; e++) {
1040
+ await Ne();
1041
+ const t = i.value;
1042
+ if (!t || t.isDestroyed || !t.view.dom.isConnected)
1043
+ continue;
1044
+ const n = Y;
1045
+ if (Y = null, !n) return;
1046
+ Ee(t, n);
1047
+ return;
1048
+ }
1049
+ } finally {
1050
+ ee = !1;
1051
+ }
1052
+ }
1053
+ }
1054
+ function ct(e) {
1055
+ e && (Y = e, xe());
1056
+ }
1057
+ function ut(e) {
1058
+ const t = e.clipboardData, n = i.value;
1059
+ if (!d.editable || !n || !t) return;
1060
+ const a = t.getData("text/html");
1061
+ if (a) {
1062
+ const s = document.createElement("div");
1063
+ if (s.innerHTML = a, s.querySelectorAll(
1064
+ "figure[data-media-block],img,video,audio,source,object,iframe"
1065
+ ).forEach((c) => c.remove()), s.textContent) {
1066
+ n.view.pasteHTML(s.innerHTML, e);
1067
+ return;
1068
+ }
1069
+ }
1070
+ const o = t.getData("text/plain");
1071
+ o && n.view.pasteText(o, e);
1072
+ }
1073
+ return u({
1074
+ pasteFileText: ut,
1075
+ isSelectionInsideOriginalReply: () => {
1076
+ const e = i.value;
1077
+ if (!e) return !1;
1078
+ const { selection: t } = e.state;
1079
+ for (let { depth: n } = t.$from; n > 0; n--)
1080
+ if (t.$from.node(n).type.name === "originalReply")
1081
+ return !0;
1082
+ return !1;
1083
+ },
1084
+ insertToken: he,
1085
+ insertOriginal: Ge,
1086
+ insertSeparator: We,
1087
+ insertBatch: Qe,
1088
+ restoreDoc: Ze,
1089
+ insertMedia: tt,
1090
+ insertPendingMedia: nt,
1091
+ insertPendingMediaBatch: be,
1092
+ applyNodeUpdate: at,
1093
+ applyPluginNodeOperation: ot,
1094
+ applyPluginNodeOperations: we,
1095
+ previewPluginNodeOperations: rt,
1096
+ failMedia: st,
1097
+ retryMedia: it,
1098
+ getMediaState: Te,
1099
+ reportMediaProgress: lt,
1100
+ captureSelection: Ce,
1101
+ restoreSelection: ct,
1102
+ captureMediaTarget: () => i.value ? Ht(i.value) : null,
1103
+ captureMediaTargetAt: (e, t) => {
1104
+ const n = i.value, a = n ? ke({ clientX: e, clientY: t }) : null;
1105
+ return K(), E.value = null, n && a !== null ? Ft(n, a) : null;
1106
+ },
1107
+ focus: () => {
1108
+ var e;
1109
+ return (e = i.value) == null ? void 0 : e.commands.focus();
1110
+ },
1111
+ getJSON: () => {
1112
+ var e;
1113
+ return (e = i.value) == null ? void 0 : e.getJSON();
1114
+ }
1115
+ }), (e, t) => g.value ? (B(), z("div", _t, "媒体编辑器加载失败,请刷新页面重试")) : (B(), z("div", {
1116
+ key: 1,
1117
+ ref_key: "areaRoot",
1118
+ ref: C,
1119
+ class: "fkp-knowledge-area",
1120
+ onFkpMediaRetry: dt,
1121
+ onClick: qe,
1122
+ onMouseover: t[0] || (t[0] = (n) => {
1123
+ Fe(n), le(n);
1124
+ }),
1125
+ onMouseout: t[1] || (t[1] = (n) => {
1126
+ _e(n), ze(n);
1127
+ }),
1128
+ onFocusin: le,
1129
+ onFocusout: V,
1130
+ onDragstartCapture: je,
1131
+ onDragoverCapture: Je,
1132
+ onDragleaveCapture: Ye,
1133
+ onDropCapture: Ke,
1134
+ onDragendCapture: Xe,
1135
+ onScrollCapture: He
1136
+ }, [
1137
+ Ae(q(yt), {
1138
+ class: "fkp-knowledge-editor",
1139
+ editor: i.value
1140
+ }, null, 8, ["editor"]),
1141
+ v.value ? (B(), kt(q(vt), {
1142
+ key: 0,
1143
+ "popup-visible": !0,
1144
+ trigger: [],
1145
+ position: "tl",
1146
+ "content-class": "fkp-order-remark-popover",
1147
+ "content-style": {
1148
+ width: "326px",
1149
+ maxWidth: "calc(100vw - 32px)",
1150
+ padding: "16px",
1151
+ border: "none",
1152
+ boxSizing: "border-box",
1153
+ maxHeight: "420px",
1154
+ overflowY: "auto"
1155
+ }
1156
+ }, {
1157
+ content: ae(() => [
1158
+ I("div", {
1159
+ class: "fkp-order-remark-detail",
1160
+ onMouseenter: $,
1161
+ onMouseleave: V
1162
+ }, [
1163
+ I("div", Ut, [
1164
+ t[2] || (t[2] = I("strong", null, "订单备注", -1)),
1165
+ v.value.contentMode === "smart" ? (B(), z("span", qt, "智能提取")) : W("", !0)
1166
+ ]),
1167
+ I("div", jt, De(v.value.content), 1),
1168
+ I("div", Jt, [
1169
+ t[3] || (t[3] = I("span", null, "备注插旗", -1)),
1170
+ v.value.flag === "none" ? (B(), z("span", Kt, "不标记")) : (B(), z("span", {
1171
+ key: 1,
1172
+ class: "fkp-order-remark-detail-flag",
1173
+ role: "img",
1174
+ "aria-label": q(At)[v.value.flag],
1175
+ style: re({
1176
+ backgroundColor: q(Nt)[v.value.flag]
1177
+ })
1178
+ }, null, 12, Yt))
1179
+ ]),
1180
+ I("div", Xt, [
1181
+ t[4] || (t[4] = I("span", null, "备注位置", -1)),
1182
+ I("span", null, De(v.value.position === "first" ? "最前" : "最后"), 1)
1183
+ ])
1184
+ ], 32)
1185
+ ]),
1186
+ default: ae(() => [
1187
+ I("span", {
1188
+ class: "fkp-order-remark-anchor",
1189
+ style: re(b.value)
1190
+ }, null, 4)
1191
+ ]),
1192
+ _: 1
1193
+ })) : W("", !0),
1194
+ E.value ? (B(), z("div", {
1195
+ key: 1,
1196
+ class: "fkp-media-drop-line",
1197
+ style: re({
1198
+ top: `${E.value.top}px`,
1199
+ left: `${E.value.left}px`,
1200
+ width: `${E.value.width}px`
1201
+ }),
1202
+ "aria-hidden": "true"
1203
+ }, null, 4)) : W("", !0),
1204
+ e.referencePlaceholder && S.value ? (B(), z("div", Gt, [
1205
+ t[6] || (t[6] = I("span", { class: "fkp-reference-bracket" }, "<", -1)),
1206
+ Ae(q(bt), {
1207
+ color: "arcoblue",
1208
+ size: "small",
1209
+ bordered: ""
1210
+ }, {
1211
+ default: ae(() => t[5] || (t[5] = [
1212
+ gt("参考话术")
1213
+ ])),
1214
+ _: 1
1215
+ }),
1216
+ t[7] || (t[7] = I("span", null, "请填写参考话术", -1)),
1217
+ t[8] || (t[8] = I("span", { class: "fkp-reference-bracket" }, ">", -1))
1218
+ ])) : W("", !0)
1219
+ ], 544));
1220
+ }
1221
+ });
1222
+ export {
1223
+ dn as default
1224
+ };