@opentiny/tiny-robot 0.3.1-alpha.8 → 0.3.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.
@@ -1,3263 +1,1494 @@
1
- import { defineComponent as j, openBlock as M, createBlock as G, unref as L, withCtx as $, createTextVNode as Gt, toDisplayString as fe, ref as V, watch as K, createElementBlock as O, Fragment as De, renderList as Be, withModifiers as Ye, normalizeClass as ee, createCommentVNode as W, createElementVNode as k, nextTick as pe, isRef as _e, Transition as Yt, normalizeStyle as jt, createVNode as oe, toRaw as Zt, computed as B, onMounted as Jt, onUnmounted as Qt, Teleport as en, toRef as Re, onBeforeUnmount as tn, provide as nn, renderSlot as R, normalizeProps as me, guardReactiveProps as he, createSlots as pt } from "vue";
2
- import { a as on, u as Me, W as bt, D as St } from "../index2.js";
3
- import { NodeViewWrapper as Je, VueRenderer as At, VueNodeViewRenderer as Qe, NodeViewContent as sn, useEditor as rn, EditorContent as ln } from "@tiptap/vue-3";
4
- import an from "@tiptap/extension-document";
5
- import cn from "@tiptap/extension-paragraph";
6
- import un from "@tiptap/extension-text";
7
- import dn from "@tiptap/extension-history";
8
- import fn from "@tiptap/extension-placeholder";
9
- import pn from "@tiptap/extension-character-count";
10
- import { j as mn, k as hn, l as gn } from "../index4.js";
11
- import { PluginKey as re, Plugin as ie, TextSelection as P } from "@tiptap/pm/state";
12
- import { DecorationSet as Ce, Decoration as Ct } from "@tiptap/pm/view";
13
- import { _ as Z } from "../_plugin-vue_export-helper.js";
14
- import { IconAssociate as yn, IconArrowDown as xn } from "@opentiny/tiny-robot-svgs";
15
- import { Node as et, mergeAttributes as tt, Extension as _t } from "@tiptap/core";
16
- const Tn = /* @__PURE__ */ j({
17
- __name: "mention-view",
18
- props: {
19
- node: {},
20
- extension: {}
21
- },
22
- setup(e) {
23
- return (t, n) => (M(), G(L(Je), {
24
- as: "span",
25
- class: "mention",
26
- "data-id": e.node.attrs.id,
27
- "data-value": e.node.attrs.value
28
- }, {
29
- default: $(() => [
30
- Gt(fe(e.extension.options.char) + fe(e.node.attrs.label), 1)
31
- ]),
32
- _: 1
33
- }, 8, ["data-id", "data-value"]));
34
- }
35
- }), vn = /* @__PURE__ */ Z(Tn, [["__scopeId", "data-v-b42c4fae"]]), ke = Math.min, de = Math.max, Ie = Math.round, Pe = Math.floor, X = (e) => ({
36
- x: e,
37
- y: e
38
- }), En = {
39
- left: "right",
40
- right: "left",
41
- bottom: "top",
42
- top: "bottom"
43
- }, wn = {
44
- start: "end",
45
- end: "start"
46
- };
47
- function mt(e, t, n) {
48
- return de(e, ke(t, n));
49
- }
50
- function Ke(e, t) {
51
- return typeof e == "function" ? e(t) : e;
52
- }
53
- function ge(e) {
54
- return e.split("-")[0];
55
- }
56
- function He(e) {
57
- return e.split("-")[1];
58
- }
59
- function Lt(e) {
60
- return e === "x" ? "y" : "x";
61
- }
62
- function Mt(e) {
63
- return e === "y" ? "height" : "width";
64
- }
65
- const bn = /* @__PURE__ */ new Set(["top", "bottom"]);
66
- function ne(e) {
67
- return bn.has(ge(e)) ? "y" : "x";
68
- }
69
- function Ot(e) {
70
- return Lt(ne(e));
71
- }
72
- function Sn(e, t, n) {
73
- n === void 0 && (n = !1);
74
- const o = He(e), i = Ot(e), s = Mt(i);
75
- let l = i === "x" ? o === (n ? "end" : "start") ? "right" : "left" : o === "start" ? "bottom" : "top";
76
- return t.reference[s] > t.floating[s] && (l = $e(l)), [l, $e(l)];
77
- }
78
- function An(e) {
79
- const t = $e(e);
80
- return [je(e), t, je(t)];
81
- }
82
- function je(e) {
83
- return e.replace(/start|end/g, (t) => wn[t]);
84
- }
85
- const ht = ["left", "right"], gt = ["right", "left"], Cn = ["top", "bottom"], _n = ["bottom", "top"];
86
- function Ln(e, t, n) {
87
- switch (e) {
88
- case "top":
89
- case "bottom":
90
- return n ? t ? gt : ht : t ? ht : gt;
91
- case "left":
92
- case "right":
93
- return t ? Cn : _n;
94
- default:
95
- return [];
96
- }
97
- }
98
- function Mn(e, t, n, o) {
99
- const i = He(e);
100
- let s = Ln(ge(e), n === "start", o);
101
- return i && (s = s.map((l) => l + "-" + i), t && (s = s.concat(s.map(je)))), s;
102
- }
103
- function $e(e) {
104
- return e.replace(/left|right|bottom|top/g, (t) => En[t]);
105
- }
106
- function On(e) {
107
- return {
108
- top: 0,
109
- right: 0,
110
- bottom: 0,
111
- left: 0,
112
- ...e
113
- };
114
- }
115
- function Pn(e) {
116
- return typeof e != "number" ? On(e) : {
117
- top: e,
118
- right: e,
119
- bottom: e,
120
- left: e
121
- };
122
- }
123
- function Ne(e) {
124
- const {
125
- x: t,
126
- y: n,
127
- width: o,
128
- height: i
129
- } = e;
130
- return {
131
- width: o,
132
- height: i,
133
- top: n,
134
- left: t,
135
- right: t + o,
136
- bottom: n + i,
137
- x: t,
138
- y: n
139
- };
140
- }
141
- function yt(e, t, n) {
142
- let {
143
- reference: o,
144
- floating: i
145
- } = e;
146
- const s = ne(t), l = Ot(t), r = Mt(l), a = ge(t), c = s === "y", f = o.x + o.width / 2 - i.width / 2, u = o.y + o.height / 2 - i.height / 2, T = o[r] / 2 - i[r] / 2;
147
- let y;
148
- switch (a) {
149
- case "top":
150
- y = {
151
- x: f,
152
- y: o.y - i.height
153
- };
154
- break;
155
- case "bottom":
156
- y = {
157
- x: f,
158
- y: o.y + o.height
159
- };
160
- break;
161
- case "right":
162
- y = {
163
- x: o.x + o.width,
164
- y: u
165
- };
166
- break;
167
- case "left":
168
- y = {
169
- x: o.x - i.width,
170
- y: u
171
- };
172
- break;
173
- default:
174
- y = {
175
- x: o.x,
176
- y: o.y
177
- };
178
- }
179
- switch (He(t)) {
180
- case "start":
181
- y[l] -= T * (n && c ? -1 : 1);
182
- break;
183
- case "end":
184
- y[l] += T * (n && c ? -1 : 1);
185
- break;
186
- }
187
- return y;
188
- }
189
- const Rn = async (e, t, n) => {
190
- const {
191
- placement: o = "bottom",
192
- strategy: i = "absolute",
193
- middleware: s = [],
194
- platform: l
195
- } = n, r = s.filter(Boolean), a = await (l.isRTL == null ? void 0 : l.isRTL(t));
196
- let c = await l.getElementRects({
197
- reference: e,
198
- floating: t,
199
- strategy: i
200
- }), {
201
- x: f,
202
- y: u
203
- } = yt(c, o, a), T = o, y = {}, w = 0;
204
- for (let b = 0; b < r.length; b++) {
205
- const {
206
- name: v,
207
- fn: h
208
- } = r[b], {
209
- x: g,
210
- y: m,
211
- data: p,
212
- reset: d
213
- } = await h({
214
- x: f,
215
- y: u,
216
- initialPlacement: o,
217
- placement: T,
218
- strategy: i,
219
- middlewareData: y,
220
- rects: c,
221
- platform: l,
222
- elements: {
223
- reference: e,
224
- floating: t
225
- }
226
- });
227
- f = g ?? f, u = m ?? u, y = {
228
- ...y,
229
- [v]: {
230
- ...y[v],
231
- ...p
232
- }
233
- }, d && w <= 50 && (w++, typeof d == "object" && (d.placement && (T = d.placement), d.rects && (c = d.rects === !0 ? await l.getElementRects({
234
- reference: e,
235
- floating: t,
236
- strategy: i
237
- }) : d.rects), {
238
- x: f,
239
- y: u
240
- } = yt(c, T, a)), b = -1);
241
- }
242
- return {
243
- x: f,
244
- y: u,
245
- placement: T,
246
- strategy: i,
247
- middlewareData: y
248
- };
249
- };
250
- async function Pt(e, t) {
251
- var n;
252
- t === void 0 && (t = {});
253
- const {
254
- x: o,
255
- y: i,
256
- platform: s,
257
- rects: l,
258
- elements: r,
259
- strategy: a
260
- } = e, {
261
- boundary: c = "clippingAncestors",
262
- rootBoundary: f = "viewport",
263
- elementContext: u = "floating",
264
- altBoundary: T = !1,
265
- padding: y = 0
266
- } = Ke(t, e), w = Pn(y), v = r[T ? u === "floating" ? "reference" : "floating" : u], h = Ne(await s.getClippingRect({
267
- element: (n = await (s.isElement == null ? void 0 : s.isElement(v))) == null || n ? v : v.contextElement || await (s.getDocumentElement == null ? void 0 : s.getDocumentElement(r.floating)),
268
- boundary: c,
269
- rootBoundary: f,
270
- strategy: a
271
- })), g = u === "floating" ? {
272
- x: o,
273
- y: i,
274
- width: l.floating.width,
275
- height: l.floating.height
276
- } : l.reference, m = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(r.floating)), p = await (s.isElement == null ? void 0 : s.isElement(m)) ? await (s.getScale == null ? void 0 : s.getScale(m)) || {
277
- x: 1,
278
- y: 1
279
- } : {
280
- x: 1,
281
- y: 1
282
- }, d = Ne(s.convertOffsetParentRelativeRectToViewportRelativeRect ? await s.convertOffsetParentRelativeRectToViewportRelativeRect({
283
- elements: r,
284
- rect: g,
285
- offsetParent: m,
286
- strategy: a
287
- }) : g);
288
- return {
289
- top: (h.top - d.top + w.top) / p.y,
290
- bottom: (d.bottom - h.bottom + w.bottom) / p.y,
291
- left: (h.left - d.left + w.left) / p.x,
292
- right: (d.right - h.right + w.right) / p.x
293
- };
294
- }
295
- const Dn = function(e) {
296
- return e === void 0 && (e = {}), {
297
- name: "flip",
298
- options: e,
299
- async fn(t) {
300
- var n, o;
301
- const {
302
- placement: i,
303
- middlewareData: s,
304
- rects: l,
305
- initialPlacement: r,
306
- platform: a,
307
- elements: c
308
- } = t, {
309
- mainAxis: f = !0,
310
- crossAxis: u = !0,
311
- fallbackPlacements: T,
312
- fallbackStrategy: y = "bestFit",
313
- fallbackAxisSideDirection: w = "none",
314
- flipAlignment: b = !0,
315
- ...v
316
- } = Ke(e, t);
317
- if ((n = s.arrow) != null && n.alignmentOffset)
318
- return {};
319
- const h = ge(i), g = ne(r), m = ge(r) === r, p = await (a.isRTL == null ? void 0 : a.isRTL(c.floating)), d = T || (m || !b ? [$e(r)] : An(r)), x = w !== "none";
320
- !T && x && d.push(...Mn(r, b, w, p));
321
- const E = [r, ...d], _ = await Pt(t, v), C = [];
322
- let I = ((o = s.flip) == null ? void 0 : o.overflows) || [];
323
- if (f && C.push(_[h]), u) {
324
- const ae = Sn(i, l, p);
325
- C.push(_[ae[0]], _[ae[1]]);
326
- }
327
- if (I = [...I, {
328
- placement: i,
329
- overflows: C
330
- }], !C.every((ae) => ae <= 0)) {
331
- var Q, dt;
332
- const ae = (((Q = s.flip) == null ? void 0 : Q.index) || 0) + 1, Ue = E[ae];
333
- if (Ue && (!(u === "alignment" ? g !== ne(Ue) : !1) || // We leave the current main axis only if every placement on that axis
334
- // overflows the main axis.
335
- I.every((H) => ne(H.placement) === g ? H.overflows[0] > 0 : !0)))
336
- return {
337
- data: {
338
- index: ae,
339
- overflows: I
340
- },
341
- reset: {
342
- placement: Ue
343
- }
344
- };
345
- let Ae = (dt = I.filter((ce) => ce.overflows[0] <= 0).sort((ce, H) => ce.overflows[1] - H.overflows[1])[0]) == null ? void 0 : dt.placement;
346
- if (!Ae)
347
- switch (y) {
348
- case "bestFit": {
349
- var ft;
350
- const ce = (ft = I.filter((H) => {
351
- if (x) {
352
- const te = ne(H.placement);
353
- return te === g || // Create a bias to the `y` side axis due to horizontal
354
- // reading directions favoring greater width.
355
- te === "y";
356
- }
357
- return !0;
358
- }).map((H) => [H.placement, H.overflows.filter((te) => te > 0).reduce((te, Xt) => te + Xt, 0)]).sort((H, te) => H[1] - te[1])[0]) == null ? void 0 : ft[0];
359
- ce && (Ae = ce);
360
- break;
361
- }
362
- case "initialPlacement":
363
- Ae = r;
364
- break;
365
- }
366
- if (i !== Ae)
367
- return {
368
- reset: {
369
- placement: Ae
370
- }
371
- };
372
- }
373
- return {};
374
- }
375
- };
376
- }, Bn = /* @__PURE__ */ new Set(["left", "top"]);
377
- async function kn(e, t) {
378
- const {
379
- placement: n,
380
- platform: o,
381
- elements: i
382
- } = e, s = await (o.isRTL == null ? void 0 : o.isRTL(i.floating)), l = ge(n), r = He(n), a = ne(n) === "y", c = Bn.has(l) ? -1 : 1, f = s && a ? -1 : 1, u = Ke(t, e);
383
- let {
384
- mainAxis: T,
385
- crossAxis: y,
386
- alignmentAxis: w
387
- } = typeof u == "number" ? {
388
- mainAxis: u,
389
- crossAxis: 0,
390
- alignmentAxis: null
391
- } : {
392
- mainAxis: u.mainAxis || 0,
393
- crossAxis: u.crossAxis || 0,
394
- alignmentAxis: u.alignmentAxis
395
- };
396
- return r && typeof w == "number" && (y = r === "end" ? w * -1 : w), a ? {
397
- x: y * f,
398
- y: T * c
399
- } : {
400
- x: T * c,
401
- y: y * f
402
- };
403
- }
404
- const In = function(e) {
405
- return e === void 0 && (e = 0), {
406
- name: "offset",
407
- options: e,
408
- async fn(t) {
409
- var n, o;
410
- const {
411
- x: i,
412
- y: s,
413
- placement: l,
414
- middlewareData: r
415
- } = t, a = await kn(t, e);
416
- return l === ((n = r.offset) == null ? void 0 : n.placement) && (o = r.arrow) != null && o.alignmentOffset ? {} : {
417
- x: i + a.x,
418
- y: s + a.y,
419
- data: {
420
- ...a,
421
- placement: l
422
- }
423
- };
1
+ var it = Object.defineProperty;
2
+ var at = (n, a, l) => a in n ? it(n, a, { enumerable: !0, configurable: !0, writable: !0, value: l }) : n[a] = l;
3
+ var Pe = (n, a, l) => at(n, typeof a != "symbol" ? a + "" : a, l);
4
+ import { ref as K, watch as ne, reactive as lt, onUnmounted as tt, computed as E, defineComponent as Ce, isVNode as rt, openBlock as m, createElementBlock as I, normalizeStyle as Ue, createBlock as ee, unref as k, withCtx as ve, createElementVNode as z, createVNode as Y, normalizeClass as oe, createCommentVNode as P, resolveDynamicComponent as ct, toDisplayString as de, useAttrs as ut, resolveComponent as dt, mergeProps as Se, Fragment as ye, renderList as xe, useModel as ft, onMounted as pt, nextTick as q, mergeModels as Ze, Transition as ze, withModifiers as ht, useSlots as vt, toRef as Me, renderSlot as ae, isRef as yt, createTextVNode as Qe } from "vue";
5
+ import { TinyTooltip as We, TinyInput as gt } from "@opentiny/vue";
6
+ import { f as mt } from "../index4.js";
7
+ import { IconVoice as wt, IconUpload as bt, IconRecordingWave as St, IconClear as xt, IconSend as Ct, IconStop as _t, IconAssociate as kt } from "@opentiny/tiny-robot-svgs";
8
+ import { _ as _e } from "../_plugin-vue_export-helper.js";
9
+ import { t as It } from "../utils.js";
10
+ function Rt(n, a) {
11
+ const l = K(n.modelValue || n.defaultValue || ""), r = K(null);
12
+ ne(
13
+ () => n.modelValue,
14
+ (y) => {
15
+ y !== void 0 && y !== l.value && (l.value = y);
424
16
  }
425
- };
426
- }, $n = function(e) {
427
- return e === void 0 && (e = {}), {
428
- name: "shift",
429
- options: e,
430
- async fn(t) {
431
- const {
432
- x: n,
433
- y: o,
434
- placement: i
435
- } = t, {
436
- mainAxis: s = !0,
437
- crossAxis: l = !1,
438
- limiter: r = {
439
- fn: (v) => {
440
- let {
441
- x: h,
442
- y: g
443
- } = v;
444
- return {
445
- x: h,
446
- y: g
447
- };
448
- }
449
- },
450
- ...a
451
- } = Ke(e, t), c = {
452
- x: n,
453
- y: o
454
- }, f = await Pt(t, a), u = ne(ge(i)), T = Lt(u);
455
- let y = c[T], w = c[u];
456
- if (s) {
457
- const v = T === "y" ? "top" : "left", h = T === "y" ? "bottom" : "right", g = y + f[v], m = y - f[h];
458
- y = mt(g, y, m);
459
- }
460
- if (l) {
461
- const v = u === "y" ? "top" : "left", h = u === "y" ? "bottom" : "right", g = w + f[v], m = w - f[h];
462
- w = mt(g, w, m);
463
- }
464
- const b = r.fn({
465
- ...t,
466
- [T]: y,
467
- [u]: w
468
- });
469
- return {
470
- ...b,
471
- data: {
472
- x: b.x - n,
473
- y: b.y - o,
474
- enabled: {
475
- [T]: s,
476
- [u]: l
477
- }
478
- }
479
- };
480
- }
481
- };
482
- };
483
- function Fe() {
484
- return typeof window < "u";
485
- }
486
- function Se(e) {
487
- return Rt(e) ? (e.nodeName || "").toLowerCase() : "#document";
488
- }
489
- function N(e) {
490
- var t;
491
- return (e == null || (t = e.ownerDocument) == null ? void 0 : t.defaultView) || window;
492
- }
493
- function J(e) {
494
- var t;
495
- return (t = (Rt(e) ? e.ownerDocument : e.document) || window.document) == null ? void 0 : t.documentElement;
496
- }
497
- function Rt(e) {
498
- return Fe() ? e instanceof Node || e instanceof N(e).Node : !1;
499
- }
500
- function z(e) {
501
- return Fe() ? e instanceof Element || e instanceof N(e).Element : !1;
502
- }
503
- function Y(e) {
504
- return Fe() ? e instanceof HTMLElement || e instanceof N(e).HTMLElement : !1;
505
- }
506
- function xt(e) {
507
- return !Fe() || typeof ShadowRoot > "u" ? !1 : e instanceof ShadowRoot || e instanceof N(e).ShadowRoot;
508
- }
509
- const Nn = /* @__PURE__ */ new Set(["inline", "contents"]);
510
- function Oe(e) {
511
- const {
512
- overflow: t,
513
- overflowX: n,
514
- overflowY: o,
515
- display: i
516
- } = q(e);
517
- return /auto|scroll|overlay|hidden|clip/.test(t + o + n) && !Nn.has(i);
518
- }
519
- const Wn = /* @__PURE__ */ new Set(["table", "td", "th"]);
520
- function Kn(e) {
521
- return Wn.has(Se(e));
522
- }
523
- const Hn = [":popover-open", ":modal"];
524
- function Ve(e) {
525
- return Hn.some((t) => {
526
- try {
527
- return e.matches(t);
528
- } catch {
529
- return !1;
17
+ ), ne(
18
+ () => l.value,
19
+ (y) => {
20
+ a("update:modelValue", y);
530
21
  }
531
- });
532
- }
533
- const Fn = ["transform", "translate", "scale", "rotate", "perspective"], Vn = ["transform", "translate", "scale", "rotate", "perspective", "filter"], zn = ["paint", "layout", "strict", "content"];
534
- function nt(e) {
535
- const t = ot(), n = z(e) ? q(e) : e;
536
- return Fn.some((o) => n[o] ? n[o] !== "none" : !1) || (n.containerType ? n.containerType !== "normal" : !1) || !t && (n.backdropFilter ? n.backdropFilter !== "none" : !1) || !t && (n.filter ? n.filter !== "none" : !1) || Vn.some((o) => (n.willChange || "").includes(o)) || zn.some((o) => (n.contain || "").includes(o));
537
- }
538
- function qn(e) {
539
- let t = se(e);
540
- for (; Y(t) && !Ee(t); ) {
541
- if (nt(t))
542
- return t;
543
- if (Ve(t))
544
- return null;
545
- t = se(t);
546
- }
547
- return null;
548
- }
549
- function ot() {
550
- return typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("-webkit-backdrop-filter", "none");
551
- }
552
- const Un = /* @__PURE__ */ new Set(["html", "body", "#document"]);
553
- function Ee(e) {
554
- return Un.has(Se(e));
555
- }
556
- function q(e) {
557
- return N(e).getComputedStyle(e);
558
- }
559
- function ze(e) {
560
- return z(e) ? {
561
- scrollLeft: e.scrollLeft,
562
- scrollTop: e.scrollTop
563
- } : {
564
- scrollLeft: e.scrollX,
565
- scrollTop: e.scrollY
566
- };
567
- }
568
- function se(e) {
569
- if (Se(e) === "html")
570
- return e;
571
- const t = (
572
- // Step into the shadow DOM of the parent of a slotted node.
573
- e.assignedSlot || // DOM Element detected.
574
- e.parentNode || // ShadowRoot detected.
575
- xt(e) && e.host || // Fallback.
576
- J(e)
577
22
  );
578
- return xt(t) ? t.host : t;
579
- }
580
- function Dt(e) {
581
- const t = se(e);
582
- return Ee(t) ? e.ownerDocument ? e.ownerDocument.body : e.body : Y(t) && Oe(t) ? t : Dt(t);
583
- }
584
- function Le(e, t, n) {
585
- var o;
586
- t === void 0 && (t = []), n === void 0 && (n = !0);
587
- const i = Dt(e), s = i === ((o = e.ownerDocument) == null ? void 0 : o.body), l = N(i);
588
- if (s) {
589
- const r = Ze(l);
590
- return t.concat(l, l.visualViewport || [], Oe(i) ? i : [], r && n ? Le(r) : []);
591
- }
592
- return t.concat(i, Le(i, [], n));
593
- }
594
- function Ze(e) {
595
- return e.parent && Object.getPrototypeOf(e.parent) ? e.frameElement : null;
596
- }
597
- function Bt(e) {
598
- const t = q(e);
599
- let n = parseFloat(t.width) || 0, o = parseFloat(t.height) || 0;
600
- const i = Y(e), s = i ? e.offsetWidth : n, l = i ? e.offsetHeight : o, r = Ie(n) !== s || Ie(o) !== l;
601
- return r && (n = s, o = l), {
602
- width: n,
603
- height: o,
604
- $: r
605
- };
606
- }
607
- function st(e) {
608
- return z(e) ? e : e.contextElement;
609
- }
610
- function ve(e) {
611
- const t = st(e);
612
- if (!Y(t))
613
- return X(1);
614
- const n = t.getBoundingClientRect(), {
615
- width: o,
616
- height: i,
617
- $: s
618
- } = Bt(t);
619
- let l = (s ? Ie(n.width) : n.width) / o, r = (s ? Ie(n.height) : n.height) / i;
620
- return (!l || !Number.isFinite(l)) && (l = 1), (!r || !Number.isFinite(r)) && (r = 1), {
621
- x: l,
622
- y: r
623
- };
624
- }
625
- const Xn = /* @__PURE__ */ X(0);
626
- function kt(e) {
627
- const t = N(e);
628
- return !ot() || !t.visualViewport ? Xn : {
629
- x: t.visualViewport.offsetLeft,
630
- y: t.visualViewport.offsetTop
631
- };
632
- }
633
- function Gn(e, t, n) {
634
- return t === void 0 && (t = !1), !n || t && n !== N(e) ? !1 : t;
635
- }
636
- function ye(e, t, n, o) {
637
- t === void 0 && (t = !1), n === void 0 && (n = !1);
638
- const i = e.getBoundingClientRect(), s = st(e);
639
- let l = X(1);
640
- t && (o ? z(o) && (l = ve(o)) : l = ve(e));
641
- const r = Gn(s, n, o) ? kt(s) : X(0);
642
- let a = (i.left + r.x) / l.x, c = (i.top + r.y) / l.y, f = i.width / l.x, u = i.height / l.y;
643
- if (s) {
644
- const T = N(s), y = o && z(o) ? N(o) : o;
645
- let w = T, b = Ze(w);
646
- for (; b && o && y !== w; ) {
647
- const v = ve(b), h = b.getBoundingClientRect(), g = q(b), m = h.left + (b.clientLeft + parseFloat(g.paddingLeft)) * v.x, p = h.top + (b.clientTop + parseFloat(g.paddingTop)) * v.y;
648
- a *= v.x, c *= v.y, f *= v.x, u *= v.y, a += m, c += p, w = N(b), b = Ze(w);
649
- }
650
- }
651
- return Ne({
652
- width: f,
653
- height: u,
654
- x: a,
655
- y: c
656
- });
657
- }
658
- function qe(e, t) {
659
- const n = ze(e).scrollLeft;
660
- return t ? t.left + n : ye(J(e)).left + n;
661
- }
662
- function It(e, t) {
663
- const n = e.getBoundingClientRect(), o = n.left + t.scrollLeft - qe(e, n), i = n.top + t.scrollTop;
664
- return {
665
- x: o,
666
- y: i
667
- };
668
- }
669
- function Yn(e) {
670
- let {
671
- elements: t,
672
- rect: n,
673
- offsetParent: o,
674
- strategy: i
675
- } = e;
676
- const s = i === "fixed", l = J(o), r = t ? Ve(t.floating) : !1;
677
- if (o === l || r && s)
678
- return n;
679
- let a = {
680
- scrollLeft: 0,
681
- scrollTop: 0
682
- }, c = X(1);
683
- const f = X(0), u = Y(o);
684
- if ((u || !u && !s) && ((Se(o) !== "body" || Oe(l)) && (a = ze(o)), Y(o))) {
685
- const y = ye(o);
686
- c = ve(o), f.x = y.x + o.clientLeft, f.y = y.y + o.clientTop;
687
- }
688
- const T = l && !u && !s ? It(l, a) : X(0);
689
- return {
690
- width: n.width * c.x,
691
- height: n.height * c.y,
692
- x: n.x * c.x - a.scrollLeft * c.x + f.x + T.x,
693
- y: n.y * c.y - a.scrollTop * c.y + f.y + T.y
694
- };
695
- }
696
- function jn(e) {
697
- return Array.from(e.getClientRects());
698
- }
699
- function Zn(e) {
700
- const t = J(e), n = ze(e), o = e.ownerDocument.body, i = de(t.scrollWidth, t.clientWidth, o.scrollWidth, o.clientWidth), s = de(t.scrollHeight, t.clientHeight, o.scrollHeight, o.clientHeight);
701
- let l = -n.scrollLeft + qe(e);
702
- const r = -n.scrollTop;
703
- return q(o).direction === "rtl" && (l += de(t.clientWidth, o.clientWidth) - i), {
704
- width: i,
705
- height: s,
706
- x: l,
707
- y: r
708
- };
709
- }
710
- const Tt = 25;
711
- function Jn(e, t) {
712
- const n = N(e), o = J(e), i = n.visualViewport;
713
- let s = o.clientWidth, l = o.clientHeight, r = 0, a = 0;
714
- if (i) {
715
- s = i.width, l = i.height;
716
- const f = ot();
717
- (!f || f && t === "fixed") && (r = i.offsetLeft, a = i.offsetTop);
718
- }
719
- const c = qe(o);
720
- if (c <= 0) {
721
- const f = o.ownerDocument, u = f.body, T = getComputedStyle(u), y = f.compatMode === "CSS1Compat" && parseFloat(T.marginLeft) + parseFloat(T.marginRight) || 0, w = Math.abs(o.clientWidth - u.clientWidth - y);
722
- w <= Tt && (s -= w);
723
- } else c <= Tt && (s += c);
724
- return {
725
- width: s,
726
- height: l,
727
- x: r,
728
- y: a
729
- };
730
- }
731
- const Qn = /* @__PURE__ */ new Set(["absolute", "fixed"]);
732
- function eo(e, t) {
733
- const n = ye(e, !0, t === "fixed"), o = n.top + e.clientTop, i = n.left + e.clientLeft, s = Y(e) ? ve(e) : X(1), l = e.clientWidth * s.x, r = e.clientHeight * s.y, a = i * s.x, c = o * s.y;
734
- return {
735
- width: l,
736
- height: r,
737
- x: a,
738
- y: c
739
- };
740
- }
741
- function vt(e, t, n) {
742
- let o;
743
- if (t === "viewport")
744
- o = Jn(e, n);
745
- else if (t === "document")
746
- o = Zn(J(e));
747
- else if (z(t))
748
- o = eo(t, n);
749
- else {
750
- const i = kt(e);
751
- o = {
752
- x: t.x - i.x,
753
- y: t.y - i.y,
754
- width: t.width,
755
- height: t.height
756
- };
757
- }
758
- return Ne(o);
759
- }
760
- function $t(e, t) {
761
- const n = se(e);
762
- return n === t || !z(n) || Ee(n) ? !1 : q(n).position === "fixed" || $t(n, t);
763
- }
764
- function to(e, t) {
765
- const n = t.get(e);
766
- if (n)
767
- return n;
768
- let o = Le(e, [], !1).filter((r) => z(r) && Se(r) !== "body"), i = null;
769
- const s = q(e).position === "fixed";
770
- let l = s ? se(e) : e;
771
- for (; z(l) && !Ee(l); ) {
772
- const r = q(l), a = nt(l);
773
- !a && r.position === "fixed" && (i = null), (s ? !a && !i : !a && r.position === "static" && !!i && Qn.has(i.position) || Oe(l) && !a && $t(e, l)) ? o = o.filter((f) => f !== l) : i = r, l = se(l);
774
- }
775
- return t.set(e, o), o;
776
- }
777
- function no(e) {
778
- let {
779
- element: t,
780
- boundary: n,
781
- rootBoundary: o,
782
- strategy: i
783
- } = e;
784
- const l = [...n === "clippingAncestors" ? Ve(t) ? [] : to(t, this._c) : [].concat(n), o], r = l[0], a = l.reduce((c, f) => {
785
- const u = vt(t, f, i);
786
- return c.top = de(u.top, c.top), c.right = ke(u.right, c.right), c.bottom = ke(u.bottom, c.bottom), c.left = de(u.left, c.left), c;
787
- }, vt(t, r, i));
23
+ const d = (y) => {
24
+ l.value = y, a("update:modelValue", y);
25
+ }, _ = (y) => {
26
+ y == null || y.preventDefault();
27
+ const C = l.value;
28
+ !n.disabled && !n.loading && C.trim() && a("submit", C);
29
+ }, p = () => {
30
+ l.value = "", a("update:modelValue", ""), a("clear");
31
+ }, h = K(!1);
788
32
  return {
789
- width: a.right - a.left,
790
- height: a.bottom - a.top,
791
- x: a.left,
792
- y: a.top
793
- };
794
- }
795
- function oo(e) {
796
- const {
797
- width: t,
798
- height: n
799
- } = Bt(e);
800
- return {
801
- width: t,
802
- height: n
803
- };
804
- }
805
- function so(e, t, n) {
806
- const o = Y(t), i = J(t), s = n === "fixed", l = ye(e, !0, s, t);
807
- let r = {
808
- scrollLeft: 0,
809
- scrollTop: 0
810
- };
811
- const a = X(0);
812
- function c() {
813
- a.x = qe(i);
814
- }
815
- if (o || !o && !s)
816
- if ((Se(t) !== "body" || Oe(i)) && (r = ze(t)), o) {
817
- const y = ye(t, !0, s, t);
818
- a.x = y.x + t.clientLeft, a.y = y.y + t.clientTop;
819
- } else i && c();
820
- s && !o && i && c();
821
- const f = i && !o && !s ? It(i, r) : X(0), u = l.left + r.scrollLeft - a.x - f.x, T = l.top + r.scrollTop - a.y - f.y;
822
- return {
823
- x: u,
824
- y: T,
825
- width: l.width,
826
- height: l.height
827
- };
828
- }
829
- function Xe(e) {
830
- return q(e).position === "static";
831
- }
832
- function Et(e, t) {
833
- if (!Y(e) || q(e).position === "fixed")
834
- return null;
835
- if (t)
836
- return t(e);
837
- let n = e.offsetParent;
838
- return J(e) === n && (n = n.ownerDocument.body), n;
839
- }
840
- function Nt(e, t) {
841
- const n = N(e);
842
- if (Ve(e))
843
- return n;
844
- if (!Y(e)) {
845
- let i = se(e);
846
- for (; i && !Ee(i); ) {
847
- if (z(i) && !Xe(i))
848
- return i;
849
- i = se(i);
850
- }
851
- return n;
852
- }
853
- let o = Et(e, t);
854
- for (; o && Kn(o) && Xe(o); )
855
- o = Et(o, t);
856
- return o && Ee(o) && Xe(o) && !nt(o) ? n : o || qn(e) || n;
857
- }
858
- const ro = async function(e) {
859
- const t = this.getOffsetParent || Nt, n = this.getDimensions, o = await n(e.floating);
860
- return {
861
- reference: so(e.reference, await t(e.floating), e.strategy),
862
- floating: {
863
- x: 0,
864
- y: 0,
865
- width: o.width,
866
- height: o.height
33
+ inputValue: l,
34
+ inputWrapper: r,
35
+ isComposing: h,
36
+ handleChange: d,
37
+ handleSubmit: _,
38
+ handleClear: p,
39
+ clearInput: () => {
40
+ p();
867
41
  }
868
42
  };
869
- };
870
- function io(e) {
871
- return q(e).direction === "rtl";
872
43
  }
873
- const lo = {
874
- convertOffsetParentRelativeRectToViewportRelativeRect: Yn,
875
- getDocumentElement: J,
876
- getClippingRect: no,
877
- getOffsetParent: Nt,
878
- getElementRects: ro,
879
- getClientRects: jn,
880
- getDimensions: oo,
881
- getScale: ve,
882
- isElement: z,
883
- isRTL: io
884
- };
885
- function Wt(e, t) {
886
- return e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height;
887
- }
888
- function ao(e, t) {
889
- let n = null, o;
890
- const i = J(e);
891
- function s() {
892
- var r;
893
- clearTimeout(o), (r = n) == null || r.disconnect(), n = null;
894
- }
895
- function l(r, a) {
896
- r === void 0 && (r = !1), a === void 0 && (a = 1), s();
897
- const c = e.getBoundingClientRect(), {
898
- left: f,
899
- top: u,
900
- width: T,
901
- height: y
902
- } = c;
903
- if (r || t(), !T || !y)
904
- return;
905
- const w = Pe(u), b = Pe(i.clientWidth - (f + T)), v = Pe(i.clientHeight - (u + y)), h = Pe(f), m = {
906
- rootMargin: -w + "px " + -b + "px " + -v + "px " + -h + "px",
907
- threshold: de(0, ke(1, a)) || 1
908
- };
909
- let p = !0;
910
- function d(x) {
911
- const E = x[0].intersectionRatio;
912
- if (E !== a) {
913
- if (!p)
914
- return l();
915
- E ? l(!1, E) : o = setTimeout(() => {
916
- l(!1, 1e-7);
917
- }, 1e3);
918
- }
919
- E === 1 && !Wt(c, e.getBoundingClientRect()) && l(), p = !1;
44
+ function Tt(n, a, l, r, d, _, p, h, v, y, C, g, O, V, A, F) {
45
+ const M = () => {
46
+ g.value && (A != null && A.value && (F == null || F()), a("submit", l.value.trim()));
47
+ }, R = (f, S) => {
48
+ if (!(f.key === "Enter")) return !1;
49
+ switch (S) {
50
+ case "enter":
51
+ return !f.shiftKey && !f.ctrlKey && !f.metaKey;
52
+ case "ctrlEnter":
53
+ return (f.ctrlKey || f.metaKey) && !f.shiftKey;
54
+ case "shiftEnter":
55
+ return f.shiftKey && !f.ctrlKey && !f.metaKey;
56
+ default:
57
+ return !1;
920
58
  }
921
- try {
922
- n = new IntersectionObserver(d, {
923
- ...m,
924
- // Handle <iframe>s
925
- root: i.ownerDocument
926
- });
927
- } catch {
928
- n = new IntersectionObserver(d, m);
59
+ }, W = (f) => {
60
+ const S = f.selectionStart ?? 0, U = f.selectionEnd ?? S, Z = l.value;
61
+ l.value = Z.substring(0, S) + `
62
+ ` + Z.substring(U), setTimeout(() => {
63
+ const B = S + 1;
64
+ f.selectionStart = f.selectionEnd = B, f.scrollTop = f.scrollHeight;
65
+ }, 0);
66
+ }, b = (f) => {
67
+ if (n.submitType !== "enter" || f.key !== "Enter") return !1;
68
+ const S = f.ctrlKey && !f.shiftKey, U = f.shiftKey && !f.ctrlKey;
69
+ if (S || U) {
70
+ f.preventDefault();
71
+ const Z = f.target;
72
+ return (O == null ? void 0 : O.value) === "single" && V && V(), W(Z), !0;
929
73
  }
930
- n.observe(e);
931
- }
932
- return l(!0), s;
933
- }
934
- function rt(e, t, n, o) {
935
- o === void 0 && (o = {});
936
- const {
937
- ancestorScroll: i = !0,
938
- ancestorResize: s = !0,
939
- elementResize: l = typeof ResizeObserver == "function",
940
- layoutShift: r = typeof IntersectionObserver == "function",
941
- animationFrame: a = !1
942
- } = o, c = st(e), f = i || s ? [...c ? Le(c) : [], ...Le(t)] : [];
943
- f.forEach((h) => {
944
- i && h.addEventListener("scroll", n, {
945
- passive: !0
946
- }), s && h.addEventListener("resize", n);
947
- });
948
- const u = c && r ? ao(c, n) : null;
949
- let T = -1, y = null;
950
- l && (y = new ResizeObserver((h) => {
951
- let [g] = h;
952
- g && g.target === c && y && (y.unobserve(t), cancelAnimationFrame(T), T = requestAnimationFrame(() => {
953
- var m;
954
- (m = y) == null || m.observe(t);
955
- })), n();
956
- }), c && !a && y.observe(c), y.observe(t));
957
- let w, b = a ? ye(e) : null;
958
- a && v();
959
- function v() {
960
- const h = ye(e);
961
- b && !Wt(b, h) && n(), b = h, w = requestAnimationFrame(v);
962
- }
963
- return n(), () => {
964
- var h;
965
- f.forEach((g) => {
966
- i && g.removeEventListener("scroll", n), s && g.removeEventListener("resize", n);
967
- }), u == null || u(), (h = y) == null || h.disconnect(), y = null, a && cancelAnimationFrame(w);
74
+ return !1;
968
75
  };
969
- }
970
- const it = In, lt = $n, at = Dn, ct = (e, t, n) => {
971
- const o = /* @__PURE__ */ new Map(), i = {
972
- platform: lo,
973
- ...n
974
- }, s = {
975
- ...i.platform,
976
- _c: o
977
- };
978
- return Rn(e, t, {
979
- ...i,
980
- platform: s
981
- });
982
- };
983
- function Te(e) {
984
- return `${e}_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
985
- }
986
- function co(e, t, n = !1) {
987
- const { $from: o } = e;
988
- if (!e.empty || !o.parent.isTextblock)
989
- return null;
990
- const i = o.parent.textBetween(0, o.parentOffset, void 0, ""), s = i.lastIndexOf(t);
991
- if (s === -1)
992
- return null;
993
- const l = i.slice(s + t.length);
994
- if (!n && l.includes(" "))
995
- return null;
996
- const r = o.start() + s, a = o.pos;
997
76
  return {
998
- range: { from: r, to: a },
999
- query: l
1000
- };
1001
- }
1002
- const xe = {
1003
- /** Template 扩展(包含 TemplateBlock 和 TemplateSelect 子扩展) */
1004
- TEMPLATE: "template",
1005
- /** Mention 扩展 */
1006
- MENTION: "mention",
1007
- /** Suggestion 扩展 */
1008
- SUGGESTION: "suggestion"
1009
- }, A = {
1010
- /** TemplateBlock 节点类型(可编辑块) */
1011
- TEMPLATE_BLOCK: "templateBlock",
1012
- /** TemplateSelect 节点类型(下拉选择) */
1013
- TEMPLATE_SELECT: "templateSelect",
1014
- /** Mention 节点类型 */
1015
- MENTION: "mention",
1016
- /** Paragraph 节点类型(ProseMirror 内置) */
1017
- PARAGRAPH: "paragraph",
1018
- /** Text 节点类型(ProseMirror 内置) */
1019
- TEXT: "text"
1020
- }, le = {
1021
- /** Mention 插件 */
1022
- MENTION: "mention",
1023
- /** Suggestion 插件 */
1024
- SUGGESTION: "suggestion",
1025
- /** Template Select 下拉菜单插件 */
1026
- TEMPLATE_SELECT_DROPDOWN: "templateSelectDropdown",
1027
- /** Template Select 零宽字符插件 */
1028
- TEMPLATE_SELECT_ZERO_WIDTH: "templateSelectZeroWidth",
1029
- /** Template Select 键盘导航插件 */
1030
- TEMPLATE_SELECT_KEYBOARD: "templateSelectKeyboard",
1031
- /** Template Block 零宽字符插件 */
1032
- TEMPLATE_BLOCK_ZERO_WIDTH: "templateBlockZeroWidth",
1033
- /** Template Block 键盘导航插件 */
1034
- TEMPLATE_BLOCK_KEYBOARD: "templateBlockKeyboard",
1035
- /** Template Block 粘贴处理插件 */
1036
- TEMPLATE_BLOCK_PASTE: "templateBlockPaste"
1037
- }, U = {
1038
- /** 文本类型 */
1039
- TEXT: "text",
1040
- /** 模板块类型(对应内部的 TemplateBlock 节点) */
1041
- BLOCK: "block",
1042
- /** 选择器类型(对应内部的 TemplateSelect 节点) */
1043
- SELECT: "select",
1044
- /** Mention 类型 */
1045
- MENTION: "mention"
1046
- }, Kt = {
1047
- /** Enter 键 */
1048
- ENTER: "Enter",
1049
- /** Escape 键 */
1050
- ESCAPE: "Escape",
1051
- /** Tab 键 */
1052
- TAB: "Tab",
1053
- /** Backspace 键 */
1054
- BACKSPACE: "Backspace",
1055
- /** Delete 键 */
1056
- DELETE: "Delete",
1057
- /** 上箭头键 */
1058
- ARROW_UP: "ArrowUp",
1059
- /** 下箭头键 */
1060
- ARROW_DOWN: "ArrowDown",
1061
- /** 左箭头键 */
1062
- ARROW_LEFT: "ArrowLeft",
1063
- /** 右箭头键 */
1064
- ARROW_RIGHT: "ArrowRight",
1065
- /** 空格键 */
1066
- SPACE: " "
1067
- }, D = (e, t) => e.key === Kt[t], we = (e, t) => t.some((n) => e.key === Kt[n]), uo = ["onMousedown", "onMouseenter"], fo = {
1068
- key: 0,
1069
- class: "mention-icon"
1070
- }, po = { class: "mention-label" }, mo = {
1071
- key: 0,
1072
- class: "mention-empty"
1073
- }, ho = /* @__PURE__ */ j({
1074
- __name: "mention-list",
1075
- props: {
1076
- items: {},
1077
- command: { type: Function }
1078
- },
1079
- setup(e, { expose: t }) {
1080
- const n = e, o = V(0), i = V(null);
1081
- K(
1082
- () => n.items,
1083
- () => {
1084
- o.value = 0;
1085
- }
1086
- );
1087
- function s({ event: c }) {
1088
- return D(c, "ARROW_UP") ? (o.value = Math.max(0, o.value - 1), l(), !0) : D(c, "ARROW_DOWN") ? (o.value = Math.min(n.items.length - 1, o.value + 1), l(), !0) : we(c, ["ENTER", "TAB"]) ? (r(o.value), !0) : !1;
1089
- }
1090
- function l() {
1091
- pe(() => {
1092
- var f;
1093
- const c = (f = i.value) == null ? void 0 : f.querySelector(".mention-item.is-selected");
1094
- c && c.scrollIntoView({
1095
- block: "nearest",
1096
- behavior: "smooth"
1097
- });
1098
- });
1099
- }
1100
- function r(c) {
1101
- const f = n.items[c];
1102
- f && n.command({
1103
- id: f.id,
1104
- label: f.label,
1105
- value: f.value
1106
- });
1107
- }
1108
- function a(c) {
1109
- o.value = c;
1110
- }
1111
- return t({
1112
- onKeyDown: s
1113
- }), (c, f) => (M(), O("div", {
1114
- ref_key: "listRef",
1115
- ref: i,
1116
- class: "mention-list"
1117
- }, [
1118
- (M(!0), O(De, null, Be(e.items, (u, T) => (M(), O("button", {
1119
- key: u.id,
1120
- type: "button",
1121
- class: ee(["mention-item", { "is-selected": T === o.value }]),
1122
- onMousedown: Ye((y) => r(T), ["prevent"]),
1123
- onMouseenter: (y) => a(T)
1124
- }, [
1125
- u.icon ? (M(), O("span", fo, fe(u.icon), 1)) : W("", !0),
1126
- k("span", po, fe(u.label), 1)
1127
- ], 42, uo))), 128)),
1128
- e.items.length === 0 ? (M(), O("div", mo, [...f[0] || (f[0] = [
1129
- k("span", null, "未找到匹配的提及项", -1)
1130
- ])])) : W("", !0)
1131
- ], 512));
1132
- }
1133
- }), go = /* @__PURE__ */ Z(ho, [["__scopeId", "data-v-aaa34d1a"]]), ue = new re(le.MENTION);
1134
- function yo(e, t) {
1135
- if (!t)
1136
- return e;
1137
- const n = t.toLowerCase();
1138
- return e.filter((o) => {
1139
- var i;
1140
- return !!(o.label.toLowerCase().includes(n) || (i = o.value) != null && i.toLowerCase().includes(n));
1141
- });
1142
- }
1143
- function xo(e) {
1144
- const { editor: t, char: n, items: o, allowSpaces: i } = e;
1145
- let s = null, l = null, r = null;
1146
- return new ie({
1147
- key: ue,
1148
- state: {
1149
- init() {
1150
- return {
1151
- active: !1,
1152
- range: null,
1153
- query: "",
1154
- filteredItems: []
1155
- };
1156
- },
1157
- apply(a, c) {
1158
- const f = a.getMeta(ue);
1159
- if (f && f.type === "close")
1160
- return {
1161
- active: !1,
1162
- range: null,
1163
- query: "",
1164
- filteredItems: []
1165
- };
1166
- if (!a.docChanged && !a.selectionSet)
1167
- return c;
1168
- const u = co(a.selection, n, i);
1169
- if (!u)
1170
- return {
1171
- active: !1,
1172
- range: null,
1173
- query: "",
1174
- filteredItems: []
1175
- };
1176
- const T = _e(o) ? o.value : o, y = yo(T, u.query);
1177
- return {
1178
- active: y.length > 0,
1179
- range: u.range,
1180
- query: u.query,
1181
- filteredItems: y
1182
- };
1183
- }
1184
- },
1185
- props: {
1186
- // 装饰器:高亮触发区域
1187
- decorations(a) {
1188
- const c = this.getState(a);
1189
- if (!(c != null && c.active) || !c.range)
1190
- return Ce.empty;
1191
- const f = Ct.inline(c.range.from, c.range.to, {
1192
- class: "mention-trigger"
1193
- });
1194
- return Ce.create(a.doc, [f]);
1195
- },
1196
- // 键盘处理
1197
- handleKeyDown(a, c) {
1198
- var u, T, y, w;
1199
- const f = ue.getState(a.state);
1200
- if (D(c, "BACKSPACE")) {
1201
- const { selection: b } = a.state, { $from: v } = b;
1202
- if (v.nodeBefore && v.nodeBefore.type.name === A.MENTION) {
1203
- c.preventDefault();
1204
- const { tr: h } = a.state, g = v.pos - v.nodeBefore.nodeSize;
1205
- return h.delete(g, v.pos), h.insertText(n, g), h.setSelection(P.create(h.doc, g + 1)), a.dispatch(h), a.focus(), !0;
77
+ handleKeyPress: (f) => {
78
+ if (!r.value && !b(f)) {
79
+ if (_.value) {
80
+ if (f.key === "ArrowDown") {
81
+ f.preventDefault(), y("down");
82
+ return;
1206
83
  }
1207
- }
1208
- if (!(f != null && f.active))
1209
- return !1;
1210
- if (D(c, "ESCAPE")) {
1211
- c.preventDefault();
1212
- const b = a.state.tr;
1213
- return b.setMeta(ue, {
1214
- type: "close"
1215
- }), a.dispatch(b), s && (r == null || r(), r = null, s.destroy(), s = null), l && (l.remove(), l = null), !0;
1216
- }
1217
- if (we(c, ["ENTER", "TAB"])) {
1218
- if (c.preventDefault(), (T = (u = s == null ? void 0 : s.ref) == null ? void 0 : u.onKeyDown) == null ? void 0 : T.call(u, { event: c }))
1219
- return !0;
1220
- if (f.filteredItems.length > 0 && f.range) {
1221
- const v = f.filteredItems[0];
1222
- return wt(a, f.range, v), !0;
84
+ if (f.key === "ArrowUp") {
85
+ f.preventDefault(), y("up");
86
+ return;
1223
87
  }
1224
- return !0;
88
+ if (p.value && (n.activeSuggestionKeys || ["Enter", "Tab"]).includes(f.key)) {
89
+ f.preventDefault(), h();
90
+ return;
91
+ }
92
+ }
93
+ if (f.key === "Escape") {
94
+ _.value ? (v(), f.preventDefault()) : d.isRecording && (C(), f.preventDefault()), a("escape-press");
95
+ return;
1225
96
  }
1226
- return we(c, ["ARROW_UP", "ARROW_DOWN"]) && ((w = (y = s == null ? void 0 : s.ref) == null ? void 0 : y.onKeyDown) == null ? void 0 : w.call(y, { event: c })) || !1;
97
+ R(f, n.submitType) && g.value && (f.preventDefault(), M());
1227
98
  }
1228
99
  },
1229
- view() {
1230
- return {
1231
- update(a) {
1232
- const c = ue.getState(a.state);
1233
- if (c != null && c.active && c.filteredItems.length > 0) {
1234
- s ? s.updateProps({
1235
- items: c.filteredItems
1236
- }) : (s = new At(go, {
1237
- props: {
1238
- items: c.filteredItems,
1239
- command: (u) => {
1240
- const T = {
1241
- id: u.id,
1242
- label: u.label,
1243
- value: u.value || ""
1244
- };
1245
- c.range && wt(a, c.range, T);
1246
- }
1247
- },
1248
- editor: t
1249
- }), l = s.element, l.style.position = "absolute", l.style.zIndex = "1000", document.body.appendChild(l));
1250
- const f = a.dom.querySelector(".mention-trigger");
1251
- f && l && (r == null || r(), r = rt(f, l, () => {
1252
- ct(f, l, {
1253
- placement: "bottom-start",
1254
- middleware: [it(8), at(), lt({ padding: 8 })]
1255
- }).then((u) => {
1256
- l && Object.assign(l.style, {
1257
- left: `${u.x}px`,
1258
- top: `${u.y}px`
1259
- });
1260
- });
1261
- }));
1262
- } else
1263
- s && (r == null || r(), r = null, s.destroy(), s = null), l && (l.remove(), l = null);
1264
- },
1265
- destroy() {
1266
- r == null || r(), s == null || s.destroy(), l == null || l.remove();
1267
- }
1268
- };
1269
- }
1270
- });
1271
- }
1272
- function wt(e, t, n) {
1273
- e.focus();
1274
- const { state: o, dispatch: i } = e, { tr: s } = o, l = o.schema.nodes.mention.create({
1275
- id: n.id || Te("mention"),
1276
- label: n.label,
1277
- value: n.value || ""
1278
- }), r = o.schema.text(" ");
1279
- s.delete(t.from, t.to), s.insert(t.from, [l, r]);
1280
- const a = t.from + 2;
1281
- s.setSelection(P.create(s.doc, a)), s.scrollIntoView(), i(s);
100
+ triggerSubmit: M
101
+ };
1282
102
  }
1283
- const To = {
103
+ class Le {
104
+ constructor(a) {
105
+ Pe(this, "recognition");
106
+ Pe(this, "options");
107
+ this.options = a, this.initialize();
108
+ }
1284
109
  /**
1285
- * 插入 mention 节点
110
+ * 初始化语音识别实例
1286
111
  */
1287
- insertMention: (e) => ({ commands: t }) => t.insertContent({
1288
- type: A.MENTION,
1289
- attrs: {
1290
- id: e.id || Te("mention"),
1291
- label: e.label || "",
1292
- value: e.value
1293
- }
1294
- }),
112
+ initialize() {
113
+ this.recognition = new (window.webkitSpeechRecognition || window.SpeechRecognition)(), this.recognition.continuous = this.options.continuous ?? !1, this.recognition.interimResults = this.options.interimResults ?? !0, this.recognition.lang = this.options.lang ?? navigator.language;
114
+ }
1295
115
  /**
1296
- * 删除 mention 节点
116
+ * 检查浏览器是否支持 Web Speech API
1297
117
  */
1298
- deleteMention: (e) => ({ tr: t, state: n }) => {
1299
- let o = !1;
1300
- return n.doc.descendants((i, s) => {
1301
- if (i.type.name === A.MENTION && i.attrs.id === e)
1302
- return t.delete(s, s + i.nodeSize), o = !0, !1;
1303
- }), o;
1304
- }
1305
- }, Ht = et.create({
1306
- name: xe.MENTION,
1307
- // 节点配置
1308
- group: "inline",
1309
- inline: !0,
1310
- atom: !0,
1311
- // 不可编辑,作为整体
1312
- selectable: !0,
1313
- draggable: !1,
1314
- // 节点属性
1315
- addAttributes() {
1316
- return {
1317
- id: {
1318
- default: null,
1319
- parseHTML: (e) => e.getAttribute("data-id"),
1320
- renderHTML: (e) => e.id ? {
1321
- "data-id": e.id
1322
- } : {}
1323
- },
1324
- label: {
1325
- default: null,
1326
- parseHTML: (e) => e.getAttribute("data-label"),
1327
- renderHTML: (e) => e.label ? {
1328
- "data-label": e.label
1329
- } : {}
1330
- },
1331
- value: {
1332
- default: null,
1333
- parseHTML: (e) => e.getAttribute("data-value"),
1334
- renderHTML: (e) => e.value ? {
1335
- "data-value": e.value
1336
- } : {}
1337
- }
1338
- };
1339
- },
1340
- // HTML 解析
1341
- parseHTML() {
1342
- return [
1343
- {
1344
- tag: "span[data-mention]"
1345
- }
1346
- ];
1347
- },
1348
- // HTML 渲染
1349
- renderHTML({ node: e, HTMLAttributes: t }) {
1350
- return [
1351
- "span",
1352
- tt(this.options.HTMLAttributes || {}, t, {
1353
- "data-mention": "",
1354
- "data-id": e.attrs.id,
1355
- "data-label": e.attrs.label,
1356
- "data-value": e.attrs.value
1357
- }),
1358
- `${this.options.char}${e.attrs.label}`
1359
- ];
1360
- },
1361
- // 使用 Vue 组件渲染
1362
- addNodeView() {
1363
- return Qe(vn);
1364
- },
1365
- // 添加 storage 用于存储实例状态
1366
- addStorage() {
1367
- return {
1368
- watchStopHandle: null
1369
- };
1370
- },
1371
- onCreate() {
1372
- const { items: e } = this.options;
1373
- _e(e) && (this.storage.watchStopHandle = K(
1374
- e,
1375
- () => {
1376
- const t = this.editor.state.tr;
1377
- t.setMeta(ue, { type: "mention-update" }), this.editor.view.dispatch(t);
1378
- },
1379
- { deep: !0 }
1380
- ));
1381
- },
1382
- onDestroy() {
1383
- this.storage.watchStopHandle && (this.storage.watchStopHandle(), this.storage.watchStopHandle = null);
1384
- },
1385
- // 添加 Suggestion 插件
1386
- addProseMirrorPlugins() {
1387
- return [
1388
- xo({
1389
- editor: this.editor,
1390
- char: this.options.char,
1391
- items: this.options.items,
1392
- allowSpaces: this.options.allowSpaces || !1
1393
- })
1394
- ];
1395
- },
1396
- // 配置选项
1397
- addOptions() {
1398
- return {
1399
- items: [],
1400
- char: "@"
1401
- };
1402
- },
1403
- // 自定义命令
1404
- addCommands() {
1405
- return To;
1406
- }
1407
- });
1408
- function vo(e) {
1409
- var i;
1410
- const t = e.extensionManager.extensions.find((s) => s.name === xe.MENTION), n = ((i = t == null ? void 0 : t.options) == null ? void 0 : i.char) || "@";
1411
- let o = "";
1412
- return e.state.doc.descendants((s) => {
1413
- s.type.name === A.MENTION ? o += `${n}${s.attrs.label}` : s.type.name === A.TEXT && (o += s.text || "");
1414
- }), o.trim();
1415
- }
1416
- function Eo(e) {
1417
- const t = [];
1418
- return e.state.doc.descendants((n, o, i) => {
1419
- if (i && i.type.name === A.PARAGRAPH) {
1420
- if (n.type.name === A.MENTION)
1421
- t.push({
1422
- type: U.MENTION,
1423
- content: n.attrs.label,
1424
- value: n.attrs.value || ""
1425
- });
1426
- else if (n.type.name === A.TEXT) {
1427
- const s = n.text || "";
1428
- if (s) {
1429
- const l = t[t.length - 1];
1430
- l && l.type === U.TEXT ? l.content = (l.content || "") + s : t.push({
1431
- type: U.TEXT,
1432
- content: s
1433
- });
1434
- }
1435
- }
1436
- }
1437
- }), t;
1438
- }
1439
- function wo(e, t = "@", n) {
1440
- return Ht.configure({
1441
- items: e,
1442
- char: t,
1443
- ...n
1444
- });
1445
- }
1446
- const Ft = (e, t) => {
1447
- if (!t.length)
1448
- return [{ text: e, isMatch: !1 }];
1449
- const n = [];
1450
- for (const l of t) {
1451
- if (!l) continue;
1452
- let r = 0;
1453
- const a = e.toLowerCase(), c = l.toLowerCase();
1454
- for (; ; ) {
1455
- const f = a.indexOf(c, r);
1456
- if (f === -1) break;
1457
- n.push({
1458
- start: f,
1459
- end: f + l.length
1460
- }), r = f + 1;
1461
- }
1462
- }
1463
- if (n.length === 0)
1464
- return [{ text: e, isMatch: !1 }];
1465
- n.sort((l, r) => l.start - r.start);
1466
- const o = [];
1467
- for (const l of n)
1468
- if (o.length === 0)
1469
- o.push(l);
1470
- else {
1471
- const r = o[o.length - 1];
1472
- l.start <= r.end ? r.end = Math.max(r.end, l.end) : o.push(l);
1473
- }
1474
- const i = [];
1475
- let s = 0;
1476
- for (const l of o)
1477
- s < l.start && i.push({
1478
- text: e.substring(s, l.start),
1479
- isMatch: !1
1480
- }), i.push({
1481
- text: e.substring(l.start, l.end),
1482
- isMatch: !0
1483
- }), s = l.end;
1484
- return s < e.length && i.push({
1485
- text: e.substring(s),
1486
- isMatch: !1
1487
- }), i;
1488
- }, bo = (e, t) => !t || !e ? [{ text: e, isMatch: !1 }] : Ft(e, [t]), So = (e, t) => {
1489
- const { content: n, highlights: o } = e;
1490
- return typeof o == "function" ? o(n, t) : Array.isArray(o) ? Ft(n, o) : bo(n, t);
1491
- }, Ao = ["onMouseenter", "onClick"], Co = { class: "suggestion-list__text" }, _o = /* @__PURE__ */ j({
1492
- __name: "suggestion-list",
1493
- props: {
1494
- show: { type: Boolean },
1495
- suggestions: {},
1496
- popupStyle: {},
1497
- activeKeyboardIndex: {},
1498
- activeMouseIndex: {},
1499
- inputValue: {},
1500
- onSelect: { type: Function },
1501
- onMouseEnter: { type: Function },
1502
- onMouseLeave: { type: Function }
1503
- },
1504
- setup(e) {
1505
- const t = e, n = V(null), o = (r) => r === t.activeKeyboardIndex || r === t.activeMouseIndex, i = (r) => {
1506
- var a;
1507
- (a = t.onMouseEnter) == null || a.call(t, r);
1508
- }, s = () => {
1509
- var r;
1510
- (r = t.onMouseLeave) == null || r.call(t);
1511
- }, l = (r) => {
1512
- var c;
1513
- const a = t.suggestions[r];
1514
- a && ((c = t.onSelect) == null || c.call(t, Zt(a)));
1515
- };
1516
- return K(
1517
- () => t.activeKeyboardIndex,
1518
- (r) => {
1519
- if (r !== -1 && n.value) {
1520
- const a = n.value.children[r];
1521
- a && a.scrollIntoView({ block: "nearest" });
1522
- }
1523
- }
1524
- ), (r, a) => (M(), G(Yt, { name: "suggestion-slide-up" }, {
1525
- default: $(() => [
1526
- t.show && t.suggestions.length ? (M(), O("div", {
1527
- key: 0,
1528
- ref_key: "suggestionsListRef",
1529
- ref: n,
1530
- class: "suggestion-list",
1531
- style: jt(t.popupStyle)
1532
- }, [
1533
- (M(!0), O(De, null, Be(t.suggestions, (c, f) => (M(), O("div", {
1534
- key: f,
1535
- class: ee(["suggestion-list__item", { highlighted: o(f) }]),
1536
- onMouseenter: (u) => i(f),
1537
- onMouseleave: s,
1538
- onClick: (u) => l(f)
1539
- }, [
1540
- oe(L(yn), { class: "suggestion-list__icon" }),
1541
- k("span", Co, [
1542
- (M(!0), O(De, null, Be(L(So)(c, t.inputValue), (u, T) => (M(), O("span", {
1543
- key: T,
1544
- class: ee({
1545
- "suggestion-list__text--match": u.isMatch,
1546
- "suggestion-list__text--normal": !u.isMatch
1547
- })
1548
- }, fe(u.text), 3))), 128))
1549
- ])
1550
- ], 42, Ao))), 128))
1551
- ], 4)) : W("", !0)
1552
- ]),
1553
- _: 1
1554
- }));
1555
- }
1556
- }), Lo = /* @__PURE__ */ Z(_o, [["__scopeId", "data-v-76a6f35e"]]), Mo = (e, t) => {
1557
- if (!e || !t)
1558
- return { text: "", show: !1, showTab: !1 };
1559
- const n = e.toLowerCase(), o = t.toLowerCase();
1560
- if (!n.startsWith(o))
1561
- return { text: "", show: !1, showTab: !1 };
1562
- const i = e.substring(t.length), s = i.length > 0;
1563
- return {
1564
- text: i,
1565
- show: s,
1566
- showTab: s
1567
- };
1568
- }, F = new re(le.SUGGESTION);
1569
- function Oo(e) {
1570
- const {
1571
- editor: t,
1572
- activeSuggestionKeys: n = ["Enter"],
1573
- popupWidth: o = 400,
1574
- showAutoComplete: i = !0,
1575
- filterFn: s,
1576
- onSelect: l
1577
- } = e;
1578
- let r = null, a = null, c = null, f = !1;
1579
- function u() {
1580
- const m = t.extensionManager.extensions.find(
1581
- (x) => x.name === xe.SUGGESTION
1582
- ), p = m == null ? void 0 : m.options, d = (p == null ? void 0 : p.items) || (p == null ? void 0 : p.suggestions) || [];
1583
- return d && typeof d == "object" && "value" in d ? d.value : d;
1584
- }
1585
- function T(m) {
1586
- const p = u();
1587
- return s ? s(p, m) : p;
118
+ static isSupported() {
119
+ return typeof window < "u" && ("webkitSpeechRecognition" in window || "SpeechRecognition" in window);
1588
120
  }
1589
- function y(m) {
1590
- return m;
1591
- }
1592
- function w(m, p, d) {
1593
- if (m === -1 || !d[m])
1594
- return { text: "", show: !1, showTab: !1 };
1595
- const x = d[m];
1596
- return Mo(x.content, p);
1597
- }
1598
- function b(m, p, d) {
1599
- if (!p) return;
1600
- (l == null ? void 0 : l(d)) !== !1 && t.commands.setContent(d.content), t.commands.focus();
1601
- }
1602
- function v(m, p) {
1603
- const d = p.filteredSuggestions[p.selectedIndex];
1604
- d && b(m, p.range, d);
1605
- const x = m.state.tr;
1606
- x.setMeta(F, { type: "close" }), m.dispatch(x);
121
+ /**
122
+ * 检查浏览器是否支持 Web Speech API(实例方法)
123
+ */
124
+ isSupported() {
125
+ return Le.isSupported();
1607
126
  }
1608
- function h(m, p) {
1609
- c == null || c();
1610
- const x = m.dom.closest(".tr-sender") || m.dom, E = () => {
1611
- if (typeof o == "number")
1612
- return `${o}px`;
1613
- if (typeof o == "string") {
1614
- if (o.endsWith("%")) {
1615
- const _ = parseFloat(o) / 100;
1616
- return `${x.offsetWidth * _}px`;
1617
- }
1618
- return o;
1619
- }
1620
- return "400px";
1621
- };
1622
- c = rt(x, p, () => {
1623
- ct(x, p, {
1624
- placement: "top-start",
1625
- middleware: [
1626
- it(8),
1627
- at({
1628
- fallbackPlacements: ["bottom-start", "top-start"]
1629
- }),
1630
- lt({ padding: 8 })
1631
- ]
1632
- }).then(({ x: _, y: C }) => {
1633
- p.style.position = "absolute", p.style.left = `${_}px`, p.style.top = `${C}px`, p.style.zIndex = "2000", p.style.width = E();
1634
- });
127
+ /**
128
+ * 设置语音识别事件处理器
129
+ * @param callbacks 语音识别回调函数集合
130
+ */
131
+ setupEventHandlers(a) {
132
+ !this.recognition || !a || (this.recognition.onstart = () => {
133
+ a.onStart();
134
+ }, this.recognition.onend = () => {
135
+ a.onEnd();
136
+ }, this.recognition.onresult = (l) => {
137
+ const r = Array.from(l.results).map((_) => _[0].transcript).join(""), d = l.results[l.resultIndex];
138
+ d != null && d.isFinal ? a.onFinal(r) : a.onInterim(r);
139
+ }, this.recognition.onerror = (l) => {
140
+ a.onError(new Error(l.error)), this.cleanup();
1635
141
  });
1636
142
  }
1637
- function g(m) {
1638
- if (!i || !m.active || !m.autoCompleteText || !m.range)
1639
- return Ce.empty;
1640
- const p = t.state.doc, { selection: d } = t.state, x = d.$head.pos;
1641
- if (!(x >= p.content.size - 1))
1642
- return Ce.empty;
1643
- const _ = Ct.widget(
1644
- x,
1645
- () => {
1646
- const C = document.createElement("span");
1647
- C.className = "suggestion-autocomplete", C.contentEditable = "false";
1648
- const I = document.createElement("span");
1649
- if (I.className = "autocomplete-text", I.textContent = m.autoCompleteText, C.appendChild(I), m.showTabIndicator) {
1650
- const Q = document.createElement("span");
1651
- Q.className = "tab-hint", Q.textContent = "TAB", C.appendChild(Q);
1652
- }
1653
- return C;
1654
- },
1655
- {
1656
- side: 1
1657
- // 显示在光标右侧
1658
- }
1659
- );
1660
- return Ce.create(p, [_]);
1661
- }
1662
- return new ie({
1663
- key: F,
1664
- state: {
1665
- init() {
1666
- return {
1667
- active: !1,
1668
- range: null,
1669
- query: "",
1670
- filteredSuggestions: [],
1671
- selectedIndex: -1,
1672
- autoCompleteText: "",
1673
- showTabIndicator: !1
1674
- };
1675
- },
1676
- apply(m, p) {
1677
- const d = m.getMeta(F);
1678
- if (d) {
1679
- if (d.type === "close")
1680
- return f = !0, setTimeout(() => {
1681
- f = !1;
1682
- }, 0), {
1683
- active: !1,
1684
- range: null,
1685
- query: "",
1686
- filteredSuggestions: [],
1687
- selectedIndex: -1,
1688
- autoCompleteText: "",
1689
- showTabIndicator: !1
1690
- };
1691
- if (d.type === "updateIndex") {
1692
- const I = { ...p, selectedIndex: d.index }, Q = w(d.index, p.query, p.filteredSuggestions);
1693
- return {
1694
- ...I,
1695
- autoCompleteText: Q.text,
1696
- showTabIndicator: Q.showTab
1697
- };
1698
- }
1699
- }
1700
- if (f || !m.docChanged && !m.selectionSet)
1701
- return p;
1702
- const x = m.doc.textContent.trim(), E = x;
1703
- if (!x)
1704
- return {
1705
- active: !1,
1706
- range: null,
1707
- query: "",
1708
- filteredSuggestions: [],
1709
- selectedIndex: -1,
1710
- autoCompleteText: "",
1711
- showTabIndicator: !1
1712
- };
1713
- const _ = T(E);
1714
- if (_.length === 0)
1715
- return {
1716
- active: !1,
1717
- range: null,
1718
- query: "",
1719
- filteredSuggestions: [],
1720
- selectedIndex: -1,
1721
- autoCompleteText: "",
1722
- showTabIndicator: !1
1723
- };
1724
- const C = w(0, E, _);
1725
- return {
1726
- active: !0,
1727
- range: { from: 0, to: m.doc.content.size },
1728
- query: E,
1729
- filteredSuggestions: _,
1730
- selectedIndex: 0,
1731
- autoCompleteText: C.text,
1732
- showTabIndicator: C.showTab
1733
- };
1734
- }
1735
- },
1736
- props: {
1737
- decorations(m) {
1738
- const p = this.getState(m);
1739
- return g(
1740
- p || {
1741
- active: !1,
1742
- range: null,
1743
- autoCompleteText: "",
1744
- showTabIndicator: !1
1745
- }
1746
- );
1747
- },
1748
- handleKeyDown(m, p) {
1749
- const d = F.getState(m.state);
1750
- if (!(d != null && d.active))
1751
- return !1;
1752
- if (D(p, "TAB") && d.autoCompleteText)
1753
- return p.preventDefault(), v(m, d), !0;
1754
- if (we(p, ["ARROW_UP", "ARROW_DOWN"])) {
1755
- p.preventDefault();
1756
- const x = D(p, "ARROW_DOWN") ? 1 : -1, E = d.filteredSuggestions.length;
1757
- let _ = d.selectedIndex + x;
1758
- _ < 0 ? _ = E - 1 : _ >= E && (_ = 0);
1759
- const C = m.state.tr;
1760
- return C.setMeta(F, {
1761
- type: "updateIndex",
1762
- index: _
1763
- }), m.dispatch(C), !0;
1764
- }
1765
- if (n.includes(p.key))
1766
- return p.preventDefault(), v(m, d), !0;
1767
- if (D(p, "ESCAPE")) {
1768
- p.preventDefault();
1769
- const x = m.state.tr;
1770
- return x.setMeta(F, { type: "close" }), m.dispatch(x), !0;
1771
- }
1772
- return !1;
1773
- }
1774
- },
1775
- view() {
1776
- return {
1777
- update(m) {
1778
- const p = F.getState(m.state);
1779
- p != null && p.active && p.filteredSuggestions.length > 0 ? (r ? r.updateProps({
1780
- show: p.active && p.filteredSuggestions.length > 0,
1781
- suggestions: p.filteredSuggestions,
1782
- popupStyle: {
1783
- // 宽度在 computePosition 回调中动态设置,这里只设置 maxWidth
1784
- maxWidth: "100%"
1785
- },
1786
- activeKeyboardIndex: p.selectedIndex,
1787
- inputValue: p.query
1788
- }) : (r = new At(Lo, {
1789
- props: {
1790
- show: p.active && p.filteredSuggestions.length > 0,
1791
- suggestions: p.filteredSuggestions,
1792
- popupStyle: {
1793
- // 宽度在 computePosition 回调中动态设置,这里只设置 maxWidth
1794
- maxWidth: "100%"
1795
- },
1796
- activeKeyboardIndex: p.selectedIndex,
1797
- activeMouseIndex: -1,
1798
- inputValue: p.query,
1799
- onSelect: (d) => {
1800
- b(m, p.range, d);
1801
- const x = m.state.tr;
1802
- x.setMeta(F, { type: "close" }), m.dispatch(x);
1803
- },
1804
- onMouseEnter: (d) => {
1805
- const x = m.state.tr;
1806
- x.setMeta(F, { type: "updateIndex", index: d }), m.dispatch(x);
1807
- }
1808
- },
1809
- editor: t
1810
- }), a = r.element, document.body.appendChild(a)), a && h(m, a)) : (r && (c == null || c(), c = null, r.destroy(), r = null), a && (a.remove(), a = null));
1811
- },
1812
- destroy() {
1813
- c == null || c(), r == null || r.destroy(), a == null || a.remove();
1814
- }
1815
- };
1816
- }
1817
- });
1818
- }
1819
- const Vt = _t.create({
1820
- name: xe.SUGGESTION,
1821
- addOptions() {
1822
- return {
1823
- items: [],
1824
- activeSuggestionKeys: ["Enter"],
1825
- popupWidth: 400,
1826
- showAutoComplete: !0
1827
- };
1828
- },
1829
- // 添加 storage 用于存储实例状态
1830
- addStorage() {
1831
- return {
1832
- watchStopHandle: null
1833
- };
1834
- },
1835
- onCreate() {
1836
- _e(this.options.items) && (this.storage.watchStopHandle = K(
1837
- this.options.items,
1838
- () => {
1839
- const e = this.editor.state.tr;
1840
- e.setMeta(F, { type: "update" }), this.editor.view.dispatch(e);
1841
- },
1842
- { deep: !0 }
1843
- ));
1844
- },
1845
- onDestroy() {
1846
- this.storage.watchStopHandle && (this.storage.watchStopHandle(), this.storage.watchStopHandle = null);
1847
- },
1848
- addProseMirrorPlugins() {
1849
- return [
1850
- Oo({
1851
- editor: this.editor,
1852
- ...this.options
1853
- })
1854
- ];
1855
- }
1856
- });
1857
- function Po(e, t) {
1858
- return Vt.configure({
1859
- items: e,
1860
- ...t
1861
- });
1862
- }
1863
- function Ro(e) {
1864
- const t = [];
1865
- return e.state.doc.descendants((n, o) => {
1866
- n.type.name === A.TEMPLATE_BLOCK && t.push({ node: n, pos: o });
1867
- }), t;
1868
- }
1869
- const Do = {
1870
143
  /**
1871
- * 设置模板数据(批量)
144
+ * 清理事件监听器
1872
145
  */
1873
- setTemplateData: (e) => ({ commands: t }) => {
1874
- t.clearContent();
1875
- const n = [];
1876
- return e.forEach((o) => {
1877
- o.type === U.TEXT ? o.content && n.push({
1878
- type: A.TEXT,
1879
- text: o.content
1880
- }) : o.type === U.BLOCK ? n.push({
1881
- type: A.TEMPLATE_BLOCK,
1882
- attrs: {
1883
- id: o.id || Te("template"),
1884
- content: o.content
1885
- },
1886
- content: o.content ? [
1887
- {
1888
- type: A.TEXT,
1889
- text: o.content
1890
- }
1891
- ] : []
1892
- }) : o.type === U.SELECT && n.push({
1893
- type: A.TEMPLATE_SELECT,
1894
- attrs: {
1895
- id: o.id || Te("select"),
1896
- placeholder: o.placeholder,
1897
- options: o.options,
1898
- value: o.value || null
1899
- }
1900
- });
1901
- }), n.length > 0 && t.insertContent({
1902
- type: A.PARAGRAPH,
1903
- content: n
1904
- }), !0;
1905
- },
146
+ cleanup() {
147
+ this.recognition && (this.recognition.onstart = null, this.recognition.onend = null, this.recognition.onresult = null, this.recognition.onerror = null);
148
+ }
1906
149
  /**
1907
- * 插入模板块
150
+ * 开始语音识别
151
+ * @param callbacks 语音识别回调函数集合
1908
152
  */
1909
- insertTemplate: (e) => ({ commands: t }) => {
1910
- const n = e.content || "";
1911
- return t.insertContent({
1912
- type: A.TEMPLATE_BLOCK,
1913
- attrs: {
1914
- id: e.id || Te("template"),
1915
- content: n
1916
- },
1917
- content: n ? [
1918
- {
1919
- type: A.TEXT,
1920
- text: n
1921
- }
1922
- ] : []
1923
- });
1924
- },
153
+ start(a) {
154
+ if (!this.recognition) {
155
+ a.onError(new Error("浏览器不支持语音识别"));
156
+ return;
157
+ }
158
+ this.setupEventHandlers(a);
159
+ try {
160
+ this.recognition.start();
161
+ } catch (l) {
162
+ a.onError(l instanceof Error ? l : new Error("语音识别启动失败"));
163
+ }
164
+ }
1925
165
  /**
1926
- * 聚焦到第一个模板块
166
+ * 停止语音识别并清理资源
1927
167
  */
1928
- focusFirstTemplate: () => ({ editor: e }) => {
1929
- const t = Ro(e);
1930
- return setTimeout(() => {
1931
- var s;
1932
- const { state: n, view: o } = e, i = n.tr;
168
+ stop() {
169
+ if (this.recognition) {
170
+ this.cleanup();
1933
171
  try {
1934
- let l;
1935
- if (t.length === 0)
1936
- l = n.doc.content.size - 1;
1937
- else {
1938
- const { node: a, pos: c } = t[0], f = ((s = a.textContent) == null ? void 0 : s.length) || 0;
1939
- l = c + 1 + f;
1940
- }
1941
- const r = P.create(n.doc, l);
1942
- i.setSelection(r), o.dispatch(i), o.focus();
1943
- } catch (l) {
1944
- console.error("[focusFirstTemplate] 设置光标失败", l);
172
+ this.recognition.stop();
173
+ } catch (a) {
174
+ console.warn("停止语音识别时发生错误:", a);
1945
175
  }
1946
- }, 0), !0;
1947
- },
1948
- /**
1949
- * 插入选择器
1950
- */
1951
- insertTemplateSelect: (e) => ({ commands: t }) => t.insertContent({
1952
- type: A.TEMPLATE_SELECT,
1953
- attrs: {
1954
- id: e.id || Te("select"),
1955
- placeholder: e.placeholder || "Please select",
1956
- options: e.options || [],
1957
- value: e.value || null
1958
176
  }
1959
- })
1960
- }, S = "​";
1961
- function Ge(e) {
1962
- return zt(e).map((n) => n.content).join("");
177
+ }
1963
178
  }
1964
- function zt(e) {
1965
- const t = [];
1966
- return e.state.doc.descendants((n, o, i) => {
1967
- if (i && i.type.name === A.PARAGRAPH) {
1968
- if (n.type.name === A.TEMPLATE_BLOCK) {
1969
- const s = (n.textContent || "").replace(new RegExp(S, "g"), "");
1970
- t.push({
1971
- type: U.BLOCK,
1972
- content: s
1973
- });
1974
- } else if (n.type.name === A.TEMPLATE_SELECT) {
1975
- const s = n.attrs.options.find((r) => r.value === n.attrs.value), l = (s == null ? void 0 : s.value) || "";
1976
- t.push({
1977
- type: U.SELECT,
1978
- content: l
1979
- });
1980
- } else if (n.type.name === A.TEXT) {
1981
- const s = (n.text || "").replace(new RegExp(S, "g"), "");
1982
- if (s) {
1983
- const l = t[t.length - 1];
1984
- l && l.type === U.TEXT ? l.content += s : t.push({
1985
- type: U.TEXT,
1986
- content: s
1987
- });
1988
- }
1989
- }
179
+ function Et(n) {
180
+ const a = lt({
181
+ isRecording: !1,
182
+ isSupported: !1,
183
+ error: void 0
184
+ }), l = {
185
+ onStart: () => {
186
+ var h;
187
+ a.isRecording = !0, a.error = void 0, (h = n.onStart) == null || h.call(n);
188
+ },
189
+ onInterim: (h) => {
190
+ var v;
191
+ (v = n.onInterim) == null || v.call(n, h);
192
+ },
193
+ onFinal: (h) => {
194
+ var v;
195
+ (v = n.onFinal) == null || v.call(n, h);
196
+ },
197
+ onEnd: (h) => {
198
+ var v;
199
+ a.isRecording && (a.isRecording = !1, (v = n.onEnd) == null || v.call(n, h));
200
+ },
201
+ onError: (h) => {
202
+ var v;
203
+ a.error = h, a.isRecording = !1, (v = n.onError) == null || v.call(n, h);
1990
204
  }
1991
- }), t;
1992
- }
1993
- const Bo = /* @__PURE__ */ j({
1994
- __name: "template-block-view",
1995
- props: {
1996
- node: {}
1997
- },
1998
- setup(e) {
1999
- const t = e, n = B(() => {
2000
- const o = t.node.textContent || "";
2001
- return o.length === 0 || o === S;
2002
- });
2003
- return (o, i) => (M(), G(L(Je), {
2004
- as: "span",
2005
- class: ee(["template-block", { "is-empty": n.value }]),
2006
- "data-id": e.node.attrs.id
2007
- }, {
2008
- default: $(() => [
2009
- i[0] || (i[0] = k("span", {
2010
- contenteditable: "false",
2011
- class: "template-block__prefix"
2012
- }, " ", -1)),
2013
- oe(L(sn), {
2014
- as: "span",
2015
- class: "template-block__content"
2016
- }),
2017
- i[1] || (i[1] = k("span", {
2018
- contenteditable: "false",
2019
- class: "template-block__suffix"
2020
- }, " ", -1))
2021
- ]),
2022
- _: 1
2023
- }, 8, ["class", "data-id"]));
2024
- }
2025
- }), ko = /* @__PURE__ */ Z(Bo, [["__scopeId", "data-v-aa55b9db"]]);
2026
- function Io(e) {
2027
- const t = [];
2028
- let { tr: n } = e;
2029
- return e.doc.descendants((o, i, s) => {
2030
- if (o.type.name === A.PARAGRAPH && o.childCount > 0) {
2031
- const { lastChild: l, firstChild: r } = o;
2032
- if (r && r.type.name === A.TEMPLATE_BLOCK && t.push(i + 1), l && l.type.name === A.TEMPLATE_BLOCK) {
2033
- const a = i + o.nodeSize - 1;
2034
- n.doc.textBetween(a - 1, a, "", "") !== S && t.push(a);
2035
- }
2036
- l === r && l && l.isText && l.text === S && t.push(["remove", i + 1]);
205
+ }, r = Le.isSupported();
206
+ a.isSupported = n.customHandler ? n.customHandler.isSupported() : r;
207
+ const d = n.customHandler ?? (r ? new Le(n) : null), _ = () => {
208
+ var h;
209
+ if (!a.isSupported || !d) {
210
+ const v = new Error("语音识别不受支持");
211
+ a.error = v, (h = n.onError) == null || h.call(n, v);
212
+ return;
2037
213
  }
2038
- if (o.type.name === A.TEMPLATE_BLOCK && o.content.size === 0 && t.push(i + 1), o.type.name === A.TEMPLATE_BLOCK && s) {
2039
- let l = -1;
2040
- if (s.forEach((r, a, c) => {
2041
- r === o && (l = c);
2042
- }), l > -1 && l < s.childCount - 1 && s.child(l + 1).type.name === A.TEMPLATE_BLOCK) {
2043
- const a = i + o.nodeSize;
2044
- n.doc.textBetween(a, a + 1, "", "") !== S && t.push(a);
2045
- }
214
+ if (a.isRecording) {
215
+ d.stop(), a.isRecording = !1, setTimeout(() => {
216
+ d.start(l);
217
+ }, 200);
218
+ return;
2046
219
  }
2047
- }), t.length > 0 ? (t.sort((o, i) => {
2048
- const s = Array.isArray(o) ? o[1] : o;
2049
- return (Array.isArray(i) ? i[1] : i) - s;
2050
- }).forEach((o) => {
2051
- Array.isArray(o) && o[0] === "remove" ? n = n.delete(o[1], o[1] + 1) : typeof o == "number" && (n = n.insertText(S, o, o));
2052
- }), n) : null;
220
+ d.start(l);
221
+ }, p = () => {
222
+ !a.isRecording || !d || (d.stop(), l.onEnd());
223
+ };
224
+ return tt(() => {
225
+ a.isRecording && d && (d.stop(), a.isRecording = !1);
226
+ }), {
227
+ speechState: a,
228
+ start: _,
229
+ stop: p
230
+ };
2053
231
  }
2054
- function $o() {
2055
- return new ie({
2056
- key: new re(le.TEMPLATE_BLOCK_ZERO_WIDTH),
2057
- appendTransaction(e, t, n) {
2058
- return e.some((i) => i.docChanged) ? Io(n) : null;
232
+ function Ot(n, a, l, r, d, _) {
233
+ const p = K(!1), h = K(-1), v = K(-1), y = K(null), C = K(""), g = K(!1), O = E(() => {
234
+ var j, G;
235
+ if (!((j = n.value) != null && j.length)) return "";
236
+ const B = y.value === "mouse" ? v.value : h.value;
237
+ return ((G = n.value[B]) == null ? void 0 : G.content) || "";
238
+ }), V = (B) => {
239
+ C.value = B, g.value = !0;
240
+ }, A = () => {
241
+ C.value = "", g.value = !1;
242
+ }, F = (B) => {
243
+ const j = B || O.value;
244
+ if (!j || !a.value) {
245
+ A();
246
+ return;
2059
247
  }
2060
- });
248
+ const G = j.substring(a.value.length);
249
+ j.toLowerCase().startsWith(a.value.toLowerCase()) && G ? V(G) : A();
250
+ }, M = () => {
251
+ h.value = -1, v.value = -1, y.value = null;
252
+ }, R = () => {
253
+ p.value = !0, F();
254
+ }, W = () => {
255
+ p.value = !1, M(), A();
256
+ }, b = E(() => {
257
+ var B;
258
+ return l.value ? !0 : !!(a.value && ((B = n.value) == null ? void 0 : B.length) > 0 && !r.value);
259
+ }), w = (B) => {
260
+ W(), a.value = B, d(B), _(B);
261
+ }, f = () => {
262
+ O.value && w(O.value);
263
+ }, S = (B) => {
264
+ !p.value || !n.value || (y.value = "keyboard", h.value === -1 ? h.value = B === "down" ? 0 : n.value.length - 1 : B === "down" ? h.value = (h.value + 1) % n.value.length : h.value = (h.value - 1 + n.value.length) % n.value.length, F());
265
+ }, U = (B) => {
266
+ n.value && (y.value = "mouse", v.value = B, F());
267
+ }, Z = () => {
268
+ n.value && (v.value = -1, h.value !== -1 ? y.value = "keyboard" : y.value = null, F());
269
+ };
270
+ return ne(b, (B) => {
271
+ B ? p.value || R() : p.value && W();
272
+ }), {
273
+ // 弹窗控制
274
+ isPopupVisible: p,
275
+ openPopup: R,
276
+ closePopup: W,
277
+ // 自动完成占位符
278
+ autoCompleteText: C,
279
+ showTabIndicator: g,
280
+ syncAutoComplete: F,
281
+ // 选中控制层
282
+ activeSuggestion: O,
283
+ activeKeyboardIndex: h,
284
+ activeMouseIndex: v,
285
+ // 交互处理
286
+ navigateWithKeyboard: S,
287
+ handleMouseEnter: U,
288
+ handleMouseLeave: Z,
289
+ // 业务操作
290
+ applySuggestion: w,
291
+ confirmSelection: f
292
+ };
2061
293
  }
2062
- function No() {
2063
- return new ie({
2064
- key: new re(le.TEMPLATE_BLOCK_KEYBOARD),
2065
- props: {
2066
- handleKeyDown(e, t) {
2067
- var r, a, c, f, u, T, y, w, b;
2068
- const { state: n, dispatch: o } = e, { selection: i } = n, { $from: s } = i;
2069
- if (D(t, "ARROW_LEFT") && s.nodeBefore && s.nodeBefore.isText && s.nodeBefore.text && s.nodeBefore.text === S) {
2070
- const v = s.parent, h = s.index();
2071
- if (h >= 2) {
2072
- if (v.child(h - 2).type.name === A.TEMPLATE_BLOCK) {
2073
- const m = s.pos - 2;
2074
- return o(n.tr.setSelection(P.create(n.doc, m))), t.preventDefault(), !0;
2075
- }
2076
- } else if (h === 1 && s.pos !== 0) {
2077
- const g = s.before() - 1;
2078
- if (g >= 0)
2079
- return o(n.tr.setSelection(P.create(n.doc, g))), t.preventDefault(), !0;
2080
- }
2081
- }
2082
- if (D(t, "ARROW_RIGHT") && s.nodeAfter && s.nodeAfter.isText && s.nodeAfter.text === S) {
2083
- const v = s.parent, h = s.index();
2084
- if (h < v.childCount - 1) {
2085
- if (v.child(h + 1).type.name === A.TEMPLATE_BLOCK) {
2086
- const m = s.pos + 2;
2087
- return o(n.tr.setSelection(P.create(n.doc, m))), t.preventDefault(), !0;
2088
- }
2089
- } else if (h === v.childCount - 1 && n.doc.lastChild !== s.node()) {
2090
- const g = s.after() + 1;
2091
- return o(n.tr.setSelection(P.create(n.doc, g))), t.preventDefault(), !0;
2092
- }
2093
- }
2094
- const l = s.node();
2095
- if (l.type.name === A.TEMPLATE_BLOCK) {
2096
- const v = l.textContent || "";
2097
- if (v === "" || v === S) {
2098
- if (we(t, ["ARROW_LEFT", "ARROW_RIGHT"])) {
2099
- const h = D(t, "ARROW_LEFT") ? s.before() : s.after();
2100
- if (i.from !== h)
2101
- return o(n.tr.setSelection(P.create(n.doc, h))), t.preventDefault(), !0;
2102
- }
2103
- } else {
2104
- if (D(t, "ARROW_LEFT") && s.pos === s.start()) {
2105
- const h = s.before();
2106
- return o(n.tr.setSelection(P.create(n.doc, h))), t.preventDefault(), !0;
2107
- }
2108
- if (D(t, "ARROW_RIGHT") && s.pos === s.end()) {
2109
- const h = s.after();
2110
- return o(n.tr.setSelection(P.create(n.doc, h))), t.preventDefault(), !0;
2111
- }
2112
- }
2113
- }
2114
- if (D(t, "BACKSPACE") && i.empty) {
2115
- const v = s.node(), h = s.nodeBefore;
2116
- if (v.type.name === A.TEMPLATE_BLOCK) {
2117
- const g = v.textContent || "";
2118
- if (s.pos === s.end() && g.length === 1 && g !== S) {
2119
- const m = s.pos - 1;
2120
- return o(n.tr.insertText(S, m, m + 1)), t.preventDefault(), !0;
2121
- }
2122
- if (g === S) {
2123
- const m = s.before(), p = n.tr.setSelection(P.create(n.doc, m));
2124
- return o(p), t.preventDefault(), !0;
2125
- }
2126
- if (g === "") {
2127
- const m = s.before(), p = n.tr.setSelection(P.create(n.doc, m));
2128
- return o(p), t.preventDefault(), !0;
2129
- }
2130
- if (s.pos === s.start() && g.length > 0 && g !== S) {
2131
- const m = s.before();
2132
- return o(n.tr.setSelection(P.create(n.doc, m))), t.preventDefault(), !0;
2133
- }
2134
- return !1;
2135
- }
2136
- if (h && h.isText && ((r = h.text) == null ? void 0 : r.length) === 1 && h.text !== S && s.nodeAfter && s.nodeAfter.type.name === A.TEMPLATE_BLOCK) {
2137
- const g = s.pos - h.nodeSize, m = s.pos;
2138
- let p = n.tr.delete(g, m);
2139
- return p = p.insertText(S, g, g), o(p), t.preventDefault(), !0;
2140
- }
2141
- if (h && h.type.name === A.TEMPLATE_BLOCK) {
2142
- const g = h.textContent || "";
2143
- if (g.length === 0 || g === S) {
2144
- const p = s.parent, d = s.index(), x = s.nodeAfter;
2145
- let E = s.pos - h.nodeSize, _ = s.pos;
2146
- if (d > 1) {
2147
- const C = p.child(d - 2);
2148
- C && C.isText && C.text === S && (E = E - 1);
2149
- }
2150
- return x && x.isText && ((a = x.text) != null && a.startsWith(S)) && (_ = _ + 1), o(n.tr.delete(E, _)), t.preventDefault(), !0;
2151
- } else {
2152
- const p = s.pos - 1;
2153
- return o(n.tr.setSelection(P.create(n.doc, p))), t.preventDefault(), !0;
2154
- }
2155
- }
2156
- if (h && h.isText) {
2157
- const g = s.parent, m = s.index();
2158
- if (h.text === S) {
2159
- if (m > 1) {
2160
- const p = g.child(m - 2);
2161
- if (p.type.name === A.TEMPLATE_BLOCK) {
2162
- const d = p.textContent || "";
2163
- if (d.length === 0 || d === S) {
2164
- const E = s.pos - h.nodeSize - p.nodeSize, _ = s.nodeAfter;
2165
- let C = s.pos;
2166
- return _ && _.isText && _.text === S && (C = C + 1), o(n.tr.delete(E, C)), t.preventDefault(), !0;
2167
- } else {
2168
- const E = s.pos - 2;
2169
- if (E >= 0)
2170
- return o(n.tr.setSelection(P.create(n.doc, E))), t.preventDefault(), !0;
2171
- }
2172
- }
2173
- }
2174
- } else if (m === 1 && s.pos !== 1 && h.text === S) {
2175
- const p = i.from - 1 - 2;
2176
- if (p >= 0)
2177
- return o(n.tr.delete(p, i.to)), t.preventDefault(), !0;
2178
- }
2179
- }
2180
- }
2181
- if (D(t, "BACKSPACE") && !i.empty) {
2182
- let v = i.from, h = i.to;
2183
- const g = s.nodeBefore, m = s.nodeAfter;
2184
- if (g && g.isText && ((c = g.text) != null && c.endsWith(S)) && (v -= 1), m && m.isText && ((f = m.text) != null && f.startsWith(S)) && (h += 1), v !== i.from || h !== i.to) {
2185
- const p = n.tr.delete(v, h);
2186
- return o(p), t.preventDefault(), !0;
2187
- }
2188
- }
2189
- if (D(t, "DELETE") && i.empty) {
2190
- const v = s.node(), h = s.nodeAfter;
2191
- if (v.type.name === A.TEMPLATE_BLOCK) {
2192
- const g = v.textContent || "";
2193
- if (s.pos === s.start() && g.length === 1 && g !== S) {
2194
- const m = s.pos;
2195
- return o(n.tr.insertText(S, m, m + 1)), t.preventDefault(), !0;
2196
- }
2197
- if (g === S) {
2198
- const m = s.after(), p = n.tr.setSelection(P.create(n.doc, m));
2199
- return o(p), t.preventDefault(), !0;
2200
- }
2201
- if (g === "") {
2202
- const m = s.after(), p = n.tr.setSelection(P.create(n.doc, m));
2203
- return o(p), t.preventDefault(), !0;
2204
- }
2205
- if (s.pos === s.end() && g.length > 0 && g !== S) {
2206
- const m = s.after();
2207
- return o(n.tr.setSelection(P.create(n.doc, m))), t.preventDefault(), !0;
2208
- }
2209
- return !1;
2210
- }
2211
- if (h && h.isText && ((u = h.text) == null ? void 0 : u.length) === 1 && h.text !== S && s.nodeBefore && s.nodeBefore.type.name === A.TEMPLATE_BLOCK) {
2212
- const g = s.pos, m = s.pos + h.nodeSize;
2213
- let p = n.tr.delete(g, m);
2214
- return p = p.insertText(S, g, g), o(p), t.preventDefault(), !0;
2215
- }
2216
- if (h && h.type.name === A.TEMPLATE_BLOCK) {
2217
- const g = h.textContent || "";
2218
- if (g.length === 0 || g === S) {
2219
- const p = s.parent, d = s.index(), x = s.nodeBefore;
2220
- let E = s.pos, _ = s.pos + h.nodeSize;
2221
- if (x && x.isText && x.text === S && (E = E - 1), d < p.childCount - 1) {
2222
- const C = p.child(d + 1);
2223
- C && C.isText && C.text === S && (_ = _ + 1);
2224
- }
2225
- return o(n.tr.delete(E, _)), t.preventDefault(), !0;
2226
- } else {
2227
- const p = s.pos + 1;
2228
- return o(n.tr.setSelection(P.create(n.doc, p))), t.preventDefault(), !0;
2229
- }
2230
- }
2231
- if (h && h.isText) {
2232
- const g = s.parent, m = s.index();
2233
- if (m < g.childCount - 1) {
2234
- const p = g.child(m + 1);
2235
- if (p.type.name === A.TEMPLATE_BLOCK) {
2236
- const d = p.textContent || "";
2237
- if (d.length === 0 || d === S) {
2238
- let E = s.pos;
2239
- const _ = s.pos + h.nodeSize + p.nodeSize, C = s.nodeBefore;
2240
- return C && C.isText && ((T = C.text) != null && T.endsWith(S)) && (E = E - 1), o(n.tr.delete(E, _)), t.preventDefault(), !0;
2241
- }
2242
- if (h.text === S || (y = h.text) != null && y.startsWith(S)) {
2243
- const E = s.pos + 2;
2244
- return o(n.tr.setSelection(P.create(n.doc, E))), t.preventDefault(), !0;
2245
- }
2246
- }
2247
- }
2248
- }
2249
- }
2250
- if (D(t, "DELETE") && !i.empty) {
2251
- let v = i.from, h = i.to;
2252
- const g = s.nodeBefore, m = s.nodeAfter;
2253
- if (g && g.isText && ((w = g.text) != null && w.endsWith(S)) && (v -= 1), m && m.isText && ((b = m.text) != null && b.startsWith(S)) && (h += 1), v !== i.from || h !== i.to) {
2254
- const p = n.tr.delete(v, h);
2255
- return o(p), t.preventDefault(), !0;
2256
- }
294
+ const $t = { class: "action-buttons" }, Bt = { class: "action-buttons__submit-content" }, Lt = {
295
+ key: 0,
296
+ class: "action-buttons__cancel-text"
297
+ }, Dt = /* @__PURE__ */ Ce({
298
+ __name: "ActionButtons",
299
+ props: {
300
+ loading: { type: Boolean, default: !1 },
301
+ disabled: { type: Boolean, default: !1 },
302
+ showClear: { type: Boolean, default: !0 },
303
+ hasContent: { type: Boolean, default: !1 },
304
+ buttonGroup: {},
305
+ allowSpeech: { type: Boolean, default: !1 },
306
+ speechStatus: { default: () => ({
307
+ isRecording: !1,
308
+ isSupported: !1
309
+ }) },
310
+ allowFiles: { type: Boolean, default: !1 },
311
+ submitType: { default: "enter" },
312
+ showShortcuts: { type: Boolean },
313
+ isOverLimit: { type: Boolean, default: !1 },
314
+ stopText: { default: void 0 }
315
+ },
316
+ emits: ["clear", "submit", "cancel", "trigger-select", "voice-button-click"],
317
+ setup(n, { emit: a }) {
318
+ const l = n, r = a, d = E(() => {
319
+ var w, f;
320
+ const b = (f = (w = l.buttonGroup) == null ? void 0 : w.file) == null ? void 0 : f.tooltips;
321
+ if (typeof b == "string" && b)
322
+ return () => b;
323
+ if (typeof b == "function")
324
+ return b;
325
+ }), _ = E(() => {
326
+ var w, f;
327
+ const b = (f = (w = l.buttonGroup) == null ? void 0 : w.submit) == null ? void 0 : f.tooltips;
328
+ if (typeof b == "string" && b)
329
+ return () => b;
330
+ if (typeof b == "function")
331
+ return b;
332
+ }), p = E(() => l.allowSpeech), h = E(() => l.speechStatus.isRecording), v = E(() => l.disabled), y = E(() => {
333
+ var b, w;
334
+ return v.value || l.isOverLimit || ((w = (b = l.buttonGroup) == null ? void 0 : b.submit) == null ? void 0 : w.disabled);
335
+ }), C = E(() => l.allowFiles || l.allowSpeech || l.showClear), g = E(() => {
336
+ var w, f;
337
+ const b = (f = (w = l.buttonGroup) == null ? void 0 : w.voice) == null ? void 0 : f.icon;
338
+ return b ? rt(b) ? () => b : b : wt;
339
+ }), O = () => {
340
+ v.value || r("clear");
341
+ }, V = () => {
342
+ v.value || r("voice-button-click");
343
+ }, A = () => {
344
+ y.value || r("submit");
345
+ }, F = () => {
346
+ v.value || r("cancel");
347
+ }, M = E(() => {
348
+ var b, w;
349
+ return v.value || ((w = (b = l.buttonGroup) == null ? void 0 : b.file) == null ? void 0 : w.disabled);
350
+ }), R = () => {
351
+ M.value || r("trigger-select");
352
+ }, W = E(() => {
353
+ var b, w;
354
+ return ((w = (b = l.buttonGroup) == null ? void 0 : b.file) == null ? void 0 : w.tooltipPlacement) || "top";
355
+ });
356
+ return (b, w) => (m(), I("div", $t, [
357
+ C.value ? (m(), I("div", {
358
+ key: 0,
359
+ class: "action-buttons__utility",
360
+ style: Ue({ "padding-right": n.hasContent || n.loading ? "0" : "6px" })
361
+ }, [
362
+ n.allowFiles && !n.loading ? (m(), ee(k(We), {
363
+ key: 0,
364
+ effect: "light",
365
+ placement: W.value,
366
+ "render-content": d.value,
367
+ "visible-arrow": !1,
368
+ "popper-class": "tr-sender-actions-upload-button-popper"
369
+ }, {
370
+ default: ve(() => [
371
+ z("div", {
372
+ class: "action-buttons__button",
373
+ onClick: R,
374
+ onFocusCapture: w[0] || (w[0] = (f) => f.stopPropagation())
375
+ }, [
376
+ Y(k(bt), {
377
+ class: oe(["action-buttons__icon", { "is-disabled": M.value }]),
378
+ alt: "上传文件"
379
+ }, null, 8, ["class"])
380
+ ], 32)
381
+ ]),
382
+ _: 1
383
+ }, 8, ["placement", "render-content"])) : P("", !0),
384
+ p.value && !n.loading ? (m(), I("div", {
385
+ key: 1,
386
+ class: oe(["action-buttons__button", { "is-recording": h.value }]),
387
+ onClick: V
388
+ }, [
389
+ h.value ? (m(), ee(k(St), {
390
+ key: 1,
391
+ class: "action-buttons__icon",
392
+ alt: "语音中"
393
+ })) : (m(), ee(ct(g.value), {
394
+ key: 0,
395
+ class: "action-buttons__icon",
396
+ alt: "录音"
397
+ }))
398
+ ], 2)) : P("", !0),
399
+ n.showClear && n.hasContent ? (m(), ee(k(We), {
400
+ key: 2,
401
+ content: "清空内容",
402
+ placement: "top"
403
+ }, {
404
+ default: ve(() => [
405
+ z("div", {
406
+ class: "action-buttons__button",
407
+ onClick: O
408
+ }, [
409
+ Y(k(xt), { class: "action-buttons__icon" })
410
+ ])
411
+ ]),
412
+ _: 1
413
+ })) : P("", !0)
414
+ ], 4)) : P("", !0),
415
+ n.hasContent || n.loading ? (m(), I("div", {
416
+ key: 1,
417
+ class: "action-buttons__button action-buttons__submit",
418
+ onClick: w[1] || (w[1] = (f) => n.loading ? F() : A())
419
+ }, [
420
+ z("div", Bt, [
421
+ n.loading ? (m(), I("div", {
422
+ key: 1,
423
+ class: oe(["action-buttons__cancel", { "action-buttons__cancel--icon-only": !n.stopText }])
424
+ }, [
425
+ Y(k(_t), {
426
+ class: "action-buttons__icon action-buttons__icon--cancel",
427
+ alt: "停止"
428
+ }),
429
+ n.stopText ? (m(), I("span", Lt, de(n.stopText), 1)) : P("", !0)
430
+ ], 2)) : (m(), ee(k(We), {
431
+ key: 0,
432
+ effect: "light",
433
+ placement: "top",
434
+ "render-content": _.value,
435
+ "visible-arrow": !1
436
+ }, {
437
+ default: ve(() => [
438
+ Y(k(Ct), {
439
+ class: oe(["action-buttons__icon", "action-buttons__icon--send", { "is-disabled": y.value }]),
440
+ alt: "发送"
441
+ }, null, 8, ["class"])
442
+ ]),
443
+ _: 1
444
+ }, 8, ["render-content"]))
445
+ ])
446
+ ])) : P("", !0)
447
+ ]));
448
+ }
449
+ }), et = /* @__PURE__ */ _e(Dt, [["__scopeId", "data-v-f71ebb23"]]);
450
+ function Kt(n, a = {}) {
451
+ let l = [], r = [], d = n;
452
+ return { commit: (C) => {
453
+ var g;
454
+ l.push(d), d = C, r.length && ((g = a.onRemoveHistory) == null || g.call(a, r)), r = [];
455
+ }, undo: () => l.length ? (r.push(d), d = l.pop(), d) : null, redo: () => r.length ? (l.push(d), d = r.pop(), d) : null, clear: () => {
456
+ var C, g;
457
+ l.length && ((C = a.onRemoveHistory) == null || C.call(a, l)), r.length && ((g = a.onRemoveHistory) == null || g.call(a, r)), l = [], r = [];
458
+ }, get: () => d };
459
+ }
460
+ const Ht = ["data-id", "data-type"], At = ["data-id", "data-type"], Vt = /* @__PURE__ */ Ce({
461
+ inheritAttrs: !1,
462
+ __name: "Block",
463
+ props: {
464
+ id: {},
465
+ type: {},
466
+ content: {},
467
+ readonly: { type: Boolean },
468
+ asChild: { type: Boolean }
469
+ },
470
+ setup(n) {
471
+ const a = n, l = ut();
472
+ return (r, d) => {
473
+ const _ = dt("Block", !0);
474
+ return a.type !== "block" ? (m(), I("span", Se({
475
+ key: 0,
476
+ "data-id": a.id,
477
+ "data-type": a.type
478
+ }, k(l)), de(a.content), 17, Ht)) : (m(), I(ye, { key: 1 }, [
479
+ a.asChild ? (m(!0), I(ye, { key: 0 }, xe(a.content, (p) => (m(), ee(_, Se({
480
+ key: `${p.id}-${p.type}`
481
+ }, { ref_for: !0 }, p), null, 16))), 128)) : (m(), I("span", Se({
482
+ key: 1,
483
+ "data-id": a.id,
484
+ "data-type": a.type
485
+ }, k(l)), [
486
+ (m(!0), I(ye, null, xe(a.content, (p) => (m(), ee(_, Se({
487
+ key: `${p.id}-${p.type}`
488
+ }, { ref_for: !0 }, p), null, 16))), 128))
489
+ ], 16, At))
490
+ ], 64));
491
+ };
492
+ }
493
+ }), Ft = /* @__PURE__ */ _e(Vt, [["__scopeId", "data-v-13862606"]]), Pt = { class: "editor-container" }, Ne = "​", Mt = 40, Wt = /* @__PURE__ */ Ce({
494
+ __name: "TemplateEditor",
495
+ props: /* @__PURE__ */ Ze({
496
+ autoSize: { type: [Boolean, Object] }
497
+ }, {
498
+ modelValue: { default: () => [] },
499
+ modelModifiers: {}
500
+ }),
501
+ emits: /* @__PURE__ */ Ze(["submit"], ["update:modelValue"]),
502
+ setup(n, { expose: a, emit: l }) {
503
+ const r = typeof window.ShadowRoot.prototype.getSelection == "function", d = typeof window.Selection.prototype.getComposedRanges == "function";
504
+ function _() {
505
+ const e = navigator.userAgent;
506
+ return e.includes("Safari") && !e.includes("Chrome") && !e.includes("Chromium") && !e.includes("CriOS");
507
+ }
508
+ const p = _(), h = () => Math.random().toString(36).substring(2, 15), v = Ne, y = Ne, C = Ne, g = n, O = ft(n, "modelValue"), V = l, A = K(0), F = (e) => e.map((o) => ({
509
+ id: o.id || h(),
510
+ ...o.type === "template" ? { ...o, prefix: y, suffix: C } : o
511
+ })), M = (e) => e.map((o) => ({ id: o.id, type: o.type, content: o.content })), R = K(F(O.value || [])), W = (e) => {
512
+ R.value = e;
513
+ }, b = E(() => {
514
+ const e = [], o = [], s = R.value;
515
+ if (s.length >= 2) {
516
+ const t = s[0], i = s[1];
517
+ t.type === "text" && t.content.length === 0 && i.type === "template" && e.push({ ...t, content: v });
518
+ const u = s[s.length - 1], x = s[s.length - 2];
519
+ u.type === "text" && u.content.length === 0 && x.type === "template" && o.push({ ...u, content: v });
520
+ }
521
+ s.length > 0 && s[0].type === "template" && e.push({ type: "text", content: v, id: h() }), s.length > 0 && s[s.length - 1].type === "template" && o.push({ type: "text", content: v, id: h() });
522
+ const c = new RegExp(v, "g");
523
+ return s.length > 0 && (s[0].content !== v && (s[0].content = s[0].content.replace(c, "")), s[s.length - 1].content !== v && (s[s.length - 1].content = s[s.length - 1].content.replace(c, ""))), e.concat(s).concat(o);
524
+ }), w = E(() => R.value.map((e) => e.type === "template" ? [
525
+ { id: e.id, type: "prefix", content: e.prefix },
526
+ { id: e.id, type: "template", content: e.content },
527
+ { id: e.id, type: "suffix", content: e.suffix }
528
+ ] : [e]).flat()), f = E(() => b.value.map((e) => e.type === "text" ? e : p ? {
529
+ id: e.id,
530
+ type: "block",
531
+ asChild: !0,
532
+ content: [
533
+ { id: e.id, type: "prefix", content: e.prefix },
534
+ {
535
+ id: e.id,
536
+ type: "block",
537
+ content: [
538
+ { id: e.id, type: "template", content: e.content },
539
+ { id: e.id, type: "suffix", content: e.suffix }
540
+ ]
2257
541
  }
2258
- return !1;
542
+ ]
543
+ } : {
544
+ id: e.id,
545
+ type: "block",
546
+ asChild: !0,
547
+ content: [
548
+ {
549
+ id: e.id,
550
+ type: "block",
551
+ content: [
552
+ { id: e.id, type: "prefix", content: e.prefix },
553
+ { id: e.id, type: "template", content: e.content }
554
+ ]
555
+ },
556
+ { id: e.id, type: "suffix", content: e.suffix }
557
+ ]
558
+ })), S = K(null), U = K(Mt), Z = () => {
559
+ if (!S.value) return;
560
+ const e = window.getComputedStyle(S.value), o = parseFloat(e.fontSize), s = parseFloat(e.lineHeight);
561
+ U.value = isNaN(s) ? o * 2.5 : s;
562
+ }, B = E(() => {
563
+ if (!g.autoSize)
564
+ return {};
565
+ const e = typeof g.autoSize == "boolean" ? { minRows: 1, maxRows: 3 } : g.autoSize, o = e.minRows * U.value, s = e.maxRows * U.value;
566
+ return {
567
+ minHeight: `${o}px`,
568
+ maxHeight: `${s}px`,
569
+ overflowY: "auto",
570
+ overflowX: "hidden"
571
+ };
572
+ }), j = () => {
573
+ if (!S.value) return;
574
+ const e = window.getSelection();
575
+ if (!e || e.rangeCount === 0) return;
576
+ const s = e.getRangeAt(0).getBoundingClientRect(), c = S.value.getBoundingClientRect(), t = s.top - c.top, i = s.bottom - c.top, u = S.value.scrollTop, x = S.value.clientHeight;
577
+ i > x ? S.value.scrollTop = u + (i - x) + 10 : t < 0 && (S.value.scrollTop = u + t - 10);
578
+ }, G = (e) => {
579
+ const o = Date.now(), s = JSON.stringify(e);
580
+ return `${o}:${s}`;
581
+ }, ke = (e) => {
582
+ const o = parseInt(e.slice(0, 13)), s = JSON.parse(e.slice(14));
583
+ return {
584
+ timestamp: o,
585
+ data: s
586
+ };
587
+ }, L = /* @__PURE__ */ new Map(), H = Kt(G(R.value), {
588
+ onRemoveHistory: (e) => {
589
+ for (const o of e)
590
+ L.delete(o);
2259
591
  }
2260
- }
2261
- });
2262
- }
2263
- function Wo() {
2264
- return new ie({
2265
- key: new re(le.TEMPLATE_BLOCK_PASTE),
2266
- props: {
2267
- handlePaste(e, t) {
2268
- var s, l, r;
2269
- const n = ((s = t.clipboardData) == null ? void 0 : s.types) || [], o = (l = t.clipboardData) == null ? void 0 : l.getData("text/html");
2270
- if (n.includes("text/html") && (o != null && o.includes("data-template")) || n.includes("application/x-prosemirror-slice"))
2271
- return !1;
2272
- const i = (r = t.clipboardData) == null ? void 0 : r.getData("text/plain");
2273
- if (i) {
2274
- const { state: a, dispatch: c } = e, f = a.selection.$from;
2275
- let u = a.tr;
2276
- f.nodeBefore && f.nodeBefore.isText && f.nodeBefore.text === S && (u = u.delete(f.pos - f.nodeBefore.nodeSize, f.pos)), f.nodeAfter && f.nodeAfter.isText && f.nodeAfter.text === S && (u = u.delete(f.pos, f.pos + f.nodeAfter.nodeSize));
2277
- const T = i.split(`
2278
- `);
2279
- let y;
2280
- if (T.length === 1)
2281
- u = u.insertText(T[0], u.selection.from, u.selection.to), y = u.selection.$to.pos;
2282
- else {
2283
- u = u.insertText(T[0], u.selection.from, u.selection.to);
2284
- let w = u.selection.$to.pos;
2285
- for (let b = 1; b < T.length; b++) {
2286
- const v = a.schema.nodes.paragraph.create({}, T[b] ? a.schema.text(T[b]) : null);
2287
- u = u.insert(w, v), w += v.nodeSize;
2288
- }
2289
- y = w;
592
+ });
593
+ ne(
594
+ () => O.value,
595
+ (e) => {
596
+ const o = F(e || []);
597
+ if (JSON.stringify(o) !== JSON.stringify(R.value)) {
598
+ if (S.value) {
599
+ const c = le(S.value);
600
+ c && L.set(H.get(), J(c));
2290
601
  }
2291
- return u = u.setSelection(P.create(u.doc, y)), u = u.scrollIntoView(), c(u), t.preventDefault(), !0;
602
+ W(o), H.commit(G(R.value));
2292
603
  }
2293
- return !1;
2294
- }
2295
- }
2296
- });
2297
- }
2298
- const Ko = et.create({
2299
- name: A.TEMPLATE_BLOCK,
2300
- // 节点配置
2301
- group: "inline",
2302
- inline: !0,
2303
- content: "text*",
2304
- // 允许内部有文本内容
2305
- atom: !1,
2306
- // 不是 atom 节点,允许光标进入
2307
- selectable: !0,
2308
- draggable: !1,
2309
- onCreate() {
2310
- const { items: e } = this.options;
2311
- e && _e(e) && K(
2312
- e,
2313
- () => {
2314
- const t = _e(e) ? e.value : e;
2315
- t != null && (this.editor.commands.setTemplateData(t), this.editor.commands.focusFirstTemplate());
2316
604
  },
2317
- { deep: !0, immediate: !0 }
605
+ { deep: !0 }
2318
606
  );
2319
- },
2320
- // 节点属性
2321
- addAttributes() {
2322
- return {
2323
- id: {
2324
- default: null,
2325
- parseHTML: (e) => e.getAttribute("data-id"),
2326
- renderHTML: (e) => e.id ? {
2327
- "data-id": e.id
2328
- } : {}
2329
- },
2330
- content: {
2331
- default: "",
2332
- parseHTML: (e) => e.getAttribute("data-content") || e.textContent,
2333
- renderHTML: (e) => ({
2334
- "data-content": e.content
2335
- })
607
+ const ge = (e, o = document.body) => o.contains(e) ? e instanceof HTMLElement && e.dataset.id ? e : e.parentElement ? ge(e.parentElement, o) : null : null, fe = (e) => e === S.value, le = (e) => {
608
+ const o = window.getSelection();
609
+ if (!o)
610
+ return null;
611
+ const s = o.rangeCount > 0 ? o.getRangeAt(0) : null, c = e.getRootNode();
612
+ if (!(c instanceof ShadowRoot))
613
+ return s;
614
+ if (d) {
615
+ const t = o.getComposedRanges(p ? c : { shadowRoots: [c] });
616
+ return (t == null ? void 0 : t[0]) ?? null;
2336
617
  }
2337
- };
2338
- },
2339
- // HTML 解析
2340
- parseHTML() {
2341
- return [
2342
- {
2343
- tag: "span[data-template]"
618
+ if (r) {
619
+ const t = c.getSelection();
620
+ return t.rangeCount > 0 ? t.getRangeAt(0) : null;
2344
621
  }
2345
- ];
2346
- },
2347
- // HTML 渲染
2348
- renderHTML({ node: e, HTMLAttributes: t }) {
2349
- const n = e.textContent || "";
2350
- return [
2351
- "span",
2352
- tt(this.options.HTMLAttributes || {}, t, {
2353
- "data-template": "",
2354
- "data-id": e.attrs.id,
2355
- "data-content": n
2356
- }),
2357
- n
2358
- ];
2359
- },
2360
- // 使用 Vue 组件渲染
2361
- addNodeView() {
2362
- return Qe(ko);
2363
- },
2364
- // 添加插件
2365
- addProseMirrorPlugins() {
2366
- return [$o(), No(), Wo()];
2367
- }
2368
- }), be = new re(
2369
- le.TEMPLATE_SELECT_DROPDOWN
2370
- );
2371
- function Ho() {
2372
- return new ie({
2373
- key: be,
2374
- state: {
2375
- init() {
2376
- return {
2377
- isOpen: !1,
2378
- selectId: null
2379
- };
2380
- },
2381
- apply(e, t) {
2382
- const n = e.getMeta(be);
2383
- if (n) {
2384
- if (n.type === "open")
2385
- return {
2386
- isOpen: !0,
2387
- selectId: n.selectId
2388
- };
2389
- if (n.type === "close")
2390
- return {
2391
- isOpen: !1,
2392
- selectId: null
2393
- };
622
+ return s;
623
+ }, me = (e, o) => {
624
+ var c;
625
+ if (!e.firstChild || e.firstChild.nodeType !== Node.TEXT_NODE)
626
+ return { node: e, offset: 0 };
627
+ const s = ((c = e.firstChild.textContent) == null ? void 0 : c.length) ?? 0;
628
+ return { node: e.firstChild, offset: Math.min(o, s) };
629
+ }, te = (e, o, s, c) => {
630
+ const t = window.getSelection();
631
+ if (!t)
632
+ return;
633
+ const { node: i, offset: u } = me(e, o);
634
+ if (!s)
635
+ t.setBaseAndExtent(i, u, i, u);
636
+ else {
637
+ const { node: x, offset: N } = me(s, c ?? 0);
638
+ t.setBaseAndExtent(i, u, x, N);
639
+ }
640
+ q(() => {
641
+ j();
642
+ });
643
+ }, re = (e, o) => {
644
+ const s = h(), c = { id: s, type: "text", content: e };
645
+ if (o) {
646
+ const t = R.value.findIndex((i) => i.id === o);
647
+ t !== -1 ? (W(
648
+ R.value.slice(0, t + 1).concat(c).concat(R.value.slice(t + 1))
649
+ ), H.commit(G(R.value))) : console.warn(`can not find item with id: ${o}`);
650
+ } else
651
+ W([c].concat(R.value)), H.commit(G(R.value));
652
+ q(() => {
653
+ var i;
654
+ const t = (i = S.value) == null ? void 0 : i.querySelector(`[data-id="${s}"][data-type="text"]`);
655
+ t && te(t, e.length);
656
+ }), O.value = M(R.value);
657
+ }, Q = K({
658
+ hasStarted: !1,
659
+ range: null
660
+ }), Ke = (e) => {
661
+ var x;
662
+ const o = e;
663
+ e.preventDefault();
664
+ const { inputType: s } = o, c = (o.data || ((x = o.dataTransfer) == null ? void 0 : x.getData("text/plain")) || "").replace(y, "").replace(C, ""), t = o.getTargetRanges()[0];
665
+ if (!t) {
666
+ console.warn("range is null", t);
667
+ return;
668
+ }
669
+ const i = [
670
+ "insertText",
671
+ "insertFromPaste",
672
+ "insertReplacementText",
673
+ "deleteContentBackward",
674
+ "deleteContentForward",
675
+ "deleteWordBackward",
676
+ "deleteWordForward",
677
+ "deleteSoftLineBackward",
678
+ "deleteSoftLineForward",
679
+ "deleteByCut"
680
+ ], u = le(S.value);
681
+ if (i.includes(s)) {
682
+ if (c && fe(t.startContainer) && fe(t.endContainer)) {
683
+ u && L.set(H.get(), J(u)), re(c);
684
+ return;
2394
685
  }
2395
- return t;
686
+ const N = J(t);
687
+ N.startId && N.endId ? (u && L.set(H.get(), J(u)), we(N, s, c)) : console.warn("range is not valid, range:", N);
688
+ } else s === "insertCompositionText" && Q.value.hasStarted && (Q.value = { hasStarted: !1, range: J(t) });
689
+ }, J = (e) => {
690
+ const o = ge(e.startContainer, S.value), s = ge(e.endContainer, S.value);
691
+ return {
692
+ collapsed: e.collapsed,
693
+ endContainer: e.endContainer,
694
+ endId: s == null ? void 0 : s.dataset.id,
695
+ endEl: s,
696
+ endOffset: e.endOffset,
697
+ endType: s == null ? void 0 : s.dataset.type,
698
+ startContainer: e.startContainer,
699
+ startId: o == null ? void 0 : o.dataset.id,
700
+ startEl: o,
701
+ startOffset: e.startOffset,
702
+ startType: o == null ? void 0 : o.dataset.type
703
+ };
704
+ }, se = (e, o, s, c) => e.slice(0, s) + o + e.slice(c), we = (e, o, s) => {
705
+ const c = Re(e);
706
+ if (!Array.isArray(c) || c.length === 0)
707
+ return;
708
+ const t = Te(c, e, o, s);
709
+ if (t.some((T) => T.tag === "new")) {
710
+ const { afterId: T, content: $ } = t[0];
711
+ re($, T);
712
+ return;
2396
713
  }
2397
- }
2398
- });
2399
- }
2400
- function Fo() {
2401
- return new ie({
2402
- key: new re(le.TEMPLATE_SELECT_ZERO_WIDTH),
2403
- appendTransaction(e, t, n) {
2404
- if (!e.some((l) => l.docChanged)) return null;
2405
- const i = [];
2406
- let { tr: s } = n;
2407
- return n.doc.descendants((l, r) => {
2408
- if (l.type.name === A.PARAGRAPH && l.childCount > 0) {
2409
- const { lastChild: a, firstChild: c } = l;
2410
- a === c && a && a.isText && a.text === S && i.push(["remove", r + 1]);
714
+ const i = t, u = [];
715
+ for (const [T, $] of i.entries()) {
716
+ const D = R.value.find((ue) => ue.id === $.id), X = T === 0 ? s : "";
717
+ D ? D.type === "text" ? D.content = se(D.content, X, $.startOffset, $.endOffset) : D.type === "template" ? $.type === "prefix" || $.type === "suffix" ? $.startOffset === 0 && $.endOffset === 1 && X.length === 0 ? D[$.type] = "" : console.warn(`${$.type} can not be inserted text. it only can be deleted`, $) : $.startOffset < 0 || $.endOffset > D.content.length ? u.push(D.id) : D.content = se(D.content, X, $.startOffset, $.endOffset) : console.warn("dataItem.type is not text or template", D) : console.warn("can not find dataItem", $);
718
+ }
719
+ let x = R.value.filter((T) => !u.includes(T.id));
720
+ x = x.filter((T) => !(T.type === "template" && [T.prefix, T.suffix, T.content].join("").length === 0));
721
+ const N = /* @__PURE__ */ new Set();
722
+ x.forEach((T, $, D) => {
723
+ if (D.length >= 2) {
724
+ if ($ === 0 || $ === 1) {
725
+ const X = D[0], ue = D[1];
726
+ if (X.type === "text" && X.content.length === 0 && ue.type === "template")
727
+ return;
728
+ }
729
+ if ($ === D.length - 2 || $ === D.length - 1) {
730
+ const X = D[D.length - 1], ue = D[D.length - 2];
731
+ if (X.type === "text" && X.content.length === 0 && ue.type === "template")
732
+ return;
733
+ }
2411
734
  }
2412
- }), i.length > 0 ? (i.forEach(([, l]) => {
2413
- s = s.delete(l, l + 1);
2414
- }), s) : null;
2415
- }
2416
- });
2417
- }
2418
- function Vo() {
2419
- return new ie({
2420
- key: new re(le.TEMPLATE_SELECT_KEYBOARD),
2421
- props: {
2422
- handleKeyDown(e, t) {
2423
- const { state: n, dispatch: o } = e, { selection: i } = n, { $from: s } = i, l = be.getState(e.state);
2424
- if (l != null && l.isOpen && we(t, ["ENTER", "ARROW_UP", "ARROW_DOWN", "ESCAPE"]))
2425
- return !0;
2426
- if (D(t, "BACKSPACE") && i.empty) {
2427
- const r = s.nodeBefore, a = s.nodeAfter;
2428
- if ((r == null ? void 0 : r.type.name) === A.TEMPLATE_SELECT)
2429
- return o(n.tr.delete(s.pos - r.nodeSize, s.pos)), t.preventDefault(), !0;
2430
- if (r != null && r.isText && r.text === S) {
2431
- const c = s.pos - 1, u = n.doc.resolve(c).nodeBefore;
2432
- if ((u == null ? void 0 : u.type.name) === A.TEMPLATE_SELECT) {
2433
- const T = c - u.nodeSize, y = s.pos;
2434
- return o(n.tr.delete(T, y)), t.preventDefault(), !0;
735
+ T.type === "text" && T.content.length === 0 && N.add(T.id);
736
+ }), x = x.filter((T) => !N.has(T.id));
737
+ for (const T of x.filter(($) => $.type === "template"))
738
+ T.prefix.length === 0 && (T.prefix = y), T.suffix.length === 0 && (T.suffix = C);
739
+ W(x), H.commit(G(R.value)), i.length > 0 && Ie(i, s), O.value = M(R.value), q(() => {
740
+ j();
741
+ });
742
+ }, Ie = (e, o) => {
743
+ const s = e[0], c = `[data-id="${s.id}"][data-type="${s.type}"]`, t = e.slice(1).map((i) => `[data-id="${i.id}"][data-type="${i.type}"]`);
744
+ q(() => {
745
+ var u, x;
746
+ const i = (u = S.value) == null ? void 0 : u.querySelector(c);
747
+ if (i)
748
+ te(i, s.startOffset + o.length);
749
+ else if (o.length === 0)
750
+ for (const N of t) {
751
+ const T = (x = S.value) == null ? void 0 : x.querySelector(N);
752
+ if (T) {
753
+ te(T, 0);
754
+ break;
2435
755
  }
2436
756
  }
2437
- if ((a == null ? void 0 : a.type.name) === A.TEMPLATE_SELECT) {
2438
- if (r != null && r.isText && r.text !== S)
2439
- return o(n.tr.delete(s.pos - 1, s.pos)), t.preventDefault(), !0;
2440
- if ((r == null ? void 0 : r.type.name) === A.TEMPLATE_BLOCK)
2441
- return !1;
757
+ else
758
+ console.warn(`can not find el with selector: ${c}`);
759
+ });
760
+ }, Re = (e) => {
761
+ const o = w.value.findIndex((u) => u.id === e.startId && u.type === e.startType), s = w.value.findIndex((u) => u.id === e.endId && u.type === e.endType);
762
+ if (o === -1 || s === -1 || o > s)
763
+ return console.warn("startIndex or endIndex is -1, or startIndex > endIndex. ", { range: e }), null;
764
+ const c = w.value[o], t = w.value[s];
765
+ if (o === s)
766
+ return [
767
+ {
768
+ id: c.id,
769
+ type: c.type,
770
+ startOffset: e.startOffset,
771
+ endOffset: e.endOffset
2442
772
  }
2443
- if (!a && (r != null && r.isText) && r.text !== S)
2444
- return o(n.tr.delete(s.pos - 1, s.pos)), t.preventDefault(), !0;
773
+ ];
774
+ const i = [
775
+ {
776
+ id: c.id,
777
+ type: c.type,
778
+ startOffset: e.startOffset,
779
+ endOffset: c.content.length
2445
780
  }
2446
- if (D(t, "DELETE") && i.empty) {
2447
- const r = s.nodeAfter, a = s.nodeBefore;
2448
- if ((r == null ? void 0 : r.type.name) === A.TEMPLATE_SELECT)
2449
- return o(n.tr.delete(s.pos, s.pos + r.nodeSize)), t.preventDefault(), !0;
2450
- if (r != null && r.isText && r.text === S) {
2451
- const c = s.pos + 1, u = n.doc.resolve(c).nodeAfter;
2452
- if ((u == null ? void 0 : u.type.name) === A.TEMPLATE_SELECT) {
2453
- const T = c + u.nodeSize;
2454
- return o(n.tr.delete(s.pos, T)), t.preventDefault(), !0;
2455
- }
781
+ ];
782
+ for (let u = o + 1; u < s; u++) {
783
+ const x = w.value[u];
784
+ i.push({
785
+ id: x.id,
786
+ type: x.type,
787
+ startOffset: 0,
788
+ endOffset: x.content.length
789
+ });
790
+ }
791
+ return i.push({
792
+ id: t.id,
793
+ type: t.type,
794
+ startOffset: 0,
795
+ endOffset: e.endOffset
796
+ }), i;
797
+ }, Te = (e, o, s, c) => {
798
+ const t = e[0];
799
+ if (t.type !== "prefix" && t.type !== "suffix")
800
+ return e;
801
+ if (e.length === 1) {
802
+ if (o.collapsed)
803
+ if (o.startOffset === 0) {
804
+ const i = ie(t, c);
805
+ return i ? [i] : [];
806
+ } else {
807
+ const i = be(t, c);
808
+ return i ? [i] : [];
2456
809
  }
2457
- if ((a == null ? void 0 : a.type.name) === A.TEMPLATE_SELECT) {
2458
- if (r != null && r.isText && r.text !== S)
2459
- return o(n.tr.delete(s.pos, s.pos + 1)), t.preventDefault(), !0;
2460
- if ((r == null ? void 0 : r.type.name) === A.TEMPLATE_BLOCK)
2461
- return !1;
810
+ if (s.startsWith("insert"))
811
+ if (p) {
812
+ const i = ie(t, c);
813
+ return i ? [i] : [];
814
+ } else {
815
+ const i = be(t, c);
816
+ return i ? [i] : [];
817
+ }
818
+ if (s.startsWith("delete")) {
819
+ if (s.includes("Backward")) {
820
+ const i = ie(t, c, 1);
821
+ return i ? [i] : [];
822
+ } else if (s.includes("Forward")) {
823
+ const i = be(t, c, 1);
824
+ return i ? [i] : [];
2462
825
  }
2463
- if (!a && (r != null && r.isText) && r.text !== S)
2464
- return o(n.tr.delete(s.pos, s.pos + 1)), t.preventDefault(), !0;
2465
826
  }
2466
- return !1;
2467
827
  }
2468
- }
2469
- });
2470
- }
2471
- function zo(e, t, n) {
2472
- const o = (i) => {
2473
- const s = i.target;
2474
- !e.contains(s) && !t.contains(s) && (n(), document.removeEventListener("click", o));
2475
- };
2476
- return setTimeout(() => {
2477
- document.addEventListener("click", o);
2478
- }, 0), () => {
2479
- document.removeEventListener("click", o);
2480
- };
2481
- }
2482
- const qo = { class: "template-select__icon" }, Uo = ["onMousedown", "onMouseenter"], Xo = /* @__PURE__ */ j({
2483
- __name: "template-select-view",
2484
- props: {
2485
- node: {},
2486
- updateAttributes: { type: Function },
2487
- editor: {}
2488
- },
2489
- setup(e) {
2490
- const t = e, n = V(!1), o = V(-1), i = V(), s = V();
2491
- let l = null, r = null;
2492
- const a = B(() => t.node.attrs.options.find((d) => d.value === t.node.attrs.value)), c = B(() => {
2493
- var d;
2494
- return ((d = a.value) == null ? void 0 : d.label) || t.node.attrs.placeholder;
2495
- }), f = B(() => !t.node.attrs.value), u = () => {
2496
- n.value ? y() : T();
2497
- }, T = async () => {
2498
- var d;
2499
- if (n.value = !0, (d = t.editor) != null && d.view) {
2500
- const x = t.editor.view, E = x.state.tr;
2501
- E.setMeta(be, {
2502
- type: "open",
2503
- selectId: t.node.attrs.id
2504
- }), x.dispatch(E);
828
+ return c.length > 0 ? e.slice(1) : e;
829
+ }, ie = (e, o, s = 0) => {
830
+ const c = w.value.findIndex((t) => t.id === e.id && t.type === e.type);
831
+ if (c > 0) {
832
+ const t = w.value[c - 1], { id: i, type: u, content: x } = t;
833
+ if (u === "text" || u === "template")
834
+ return {
835
+ id: i,
836
+ type: u,
837
+ startOffset: x.length - s,
838
+ endOffset: x.length
839
+ };
840
+ if (o.length > 0)
841
+ return { tag: "new", afterId: i, type: "text", content: o };
842
+ if (console.warn("the previous item is not text or template", { current: e, previous: t }), s === 1)
843
+ return { ...e, endOffset: e.startOffset };
844
+ } else return o.length > 0 ? { tag: "new", type: "text", content: o } : (console.warn("the previous item of current is not found", { current: e }), null);
845
+ return e;
846
+ }, be = (e, o, s = 0) => {
847
+ const c = w.value.findIndex((t) => t.id === e.id && t.type === e.type);
848
+ if (c < w.value.length - 1) {
849
+ const t = w.value[c + 1], { id: i, type: u } = t;
850
+ if (u === "text" || u === "template")
851
+ return {
852
+ id: i,
853
+ type: u,
854
+ startOffset: 0,
855
+ endOffset: 0 + s
856
+ };
857
+ if (o.length > 0)
858
+ return { tag: "new", afterId: e.id, type: "text", content: o };
859
+ if (console.warn("the next item is not text or template", { current: e, next: t }), s === 1)
860
+ return { ...e, startOffset: e.endOffset };
861
+ } else return o.length > 0 ? { tag: "new", afterId: e.id, type: "text", content: o } : (console.warn("the next item of current is not found", { current: e }), null);
862
+ return e;
863
+ }, pe = () => {
864
+ Q.value = { hasStarted: !0, range: null };
865
+ }, He = (e) => {
866
+ const o = Q.value.range;
867
+ o ? (e.data && fe(o.startContainer) && fe(o.endContainer) ? (L.set(H.get(), J(o)), re(e.data)) : o.startId && o.endId ? (L.set(H.get(), J(o)), we(o, "insertCompositionText", e.data)) : console.warn("range is not valid, range:", o), A.value++, q(() => {
868
+ j();
869
+ })) : console.warn("range is null, compositionEnd:", e), Q.value = { hasStarted: !1, range: null };
870
+ }, he = (() => {
871
+ const e = navigator.userAgent.toLowerCase();
872
+ return /macintosh|mac os x|iphone|ipad|ipod/.test(e);
873
+ })(), Ae = (e) => {
874
+ const o = he && e.metaKey && !e.shiftKey && e.key.toLowerCase() === "z" || // Cmd+Z
875
+ !he && e.ctrlKey && !e.shiftKey && e.key.toLowerCase() === "z", s = he && e.metaKey && e.shiftKey && e.key.toLowerCase() === "z" || // Cmd+Shift+z
876
+ !he && e.ctrlKey && (e.key.toLowerCase() === "y" || e.shiftKey && e.key.toLowerCase() === "z"), c = e.key.toLowerCase() === "enter";
877
+ if (o) {
878
+ e.preventDefault();
879
+ const t = le(S.value);
880
+ t && L.set(H.get(), J(t));
881
+ const i = H.undo();
882
+ i && Ee(i);
2505
883
  }
2506
- t.node.attrs.value ? o.value = t.node.attrs.options.findIndex((x) => x.value === t.node.attrs.value) : o.value = -1, await pe(), b(), i.value && s.value && (l = zo(i.value, s.value, y));
2507
- }, y = async () => {
2508
- var d;
2509
- if (n.value = !1, o.value = -1, (d = t.editor) != null && d.view) {
2510
- const x = t.editor.view, E = x.state.tr;
2511
- E.setMeta(be, {
2512
- type: "close"
2513
- }), x.dispatch(E);
884
+ if (s) {
885
+ e.preventDefault();
886
+ const t = H.redo();
887
+ t && Ee(t);
2514
888
  }
2515
- l && (l(), l = null), r && (r(), r = null);
2516
- }, w = (d) => {
2517
- t.updateAttributes({ value: d.value }), y();
2518
- }, b = () => {
2519
- !i.value || !s.value || (r && (r(), r = null), r = rt(i.value, s.value, () => {
2520
- !i.value || !s.value || ct(i.value, s.value, {
2521
- placement: "bottom-start",
2522
- strategy: "fixed",
2523
- // 使用 fixed 定位策略,相对于视口
2524
- middleware: [it(4), at(), lt({ padding: 8 })]
2525
- }).then(({ x: d, y: x }) => {
2526
- s.value && Object.assign(s.value.style, {
2527
- left: `${d}px`,
2528
- top: `${x}px`
2529
- });
2530
- });
2531
- }));
2532
- }, v = (d) => {
2533
- if (n.value)
2534
- switch (d.key) {
2535
- case "ArrowUp":
2536
- d.preventDefault(), h();
2537
- break;
2538
- case "ArrowDown":
2539
- d.preventDefault(), g();
2540
- break;
2541
- case "Enter":
2542
- d.preventDefault(), p();
2543
- break;
2544
- case "Escape":
2545
- d.preventDefault(), y();
2546
- break;
2547
- }
2548
- }, h = () => {
2549
- o.value === -1 || o.value <= 0 ? o.value = t.node.attrs.options.length - 1 : o.value -= 1, m();
2550
- }, g = () => {
2551
- o.value === -1 || o.value >= t.node.attrs.options.length - 1 ? o.value = 0 : o.value += 1, m();
2552
- }, m = () => {
2553
- pe(() => {
2554
- if (!s.value) return;
2555
- const d = s.value.querySelector(".template-select__option.is-highlighted");
2556
- d && d.scrollIntoView({
2557
- block: "nearest",
2558
- behavior: "smooth"
889
+ c && (e.preventDefault(), V("submit"));
890
+ }, Ee = (e) => {
891
+ const { data: o } = ke(e);
892
+ if (W(o), L.has(e)) {
893
+ const s = L.get(e);
894
+ q(() => {
895
+ const c = S.value.querySelector(`[data-id="${s.startId}"][data-type="${s.startType}"]`), t = S.value.querySelector(`[data-id="${s.endId}"][data-type="${s.endType}"]`);
896
+ c && te(c, s.startOffset, t, s.endOffset);
2559
897
  });
898
+ }
899
+ O.value = M(R.value);
900
+ }, ce = (e, o) => {
901
+ var t, i;
902
+ const s = (t = S.value) == null ? void 0 : t.querySelector(`[data-id="${e}"][data-type="${o}"]`);
903
+ if (!s) return;
904
+ const c = ((i = s.textContent) == null ? void 0 : i.length) || 0;
905
+ te(s, c);
906
+ }, Ve = () => {
907
+ S.value && q(() => {
908
+ const e = R.value, o = e.find((c) => c.type === "template");
909
+ o && ce(o.id, "template"), e.every((c) => c.type === "text") && e.length === 1 && ce(e[0].id, "text");
2560
910
  });
2561
- }, p = () => {
2562
- o.value >= 0 && o.value < t.node.attrs.options.length ? w(t.node.attrs.options[o.value]) : y();
2563
- };
2564
- return Jt(() => {
2565
- document.addEventListener("keydown", v);
2566
- }), Qt(() => {
2567
- document.removeEventListener("keydown", v), l && l(), r && r();
2568
- }), (d, x) => (M(), G(L(Je), {
2569
- as: "span",
2570
- class: "template-select"
2571
- }, {
2572
- default: $(() => [
2573
- x[0] || (x[0] = k("span", {
2574
- contenteditable: "false",
2575
- class: "template-select__prefix"
2576
- }, "​", -1)),
2577
- k("span", {
2578
- ref_key: "triggerRef",
2579
- ref: i,
2580
- class: ee(["template-select__trigger", { "is-open": n.value }]),
2581
- onMousedown: Ye(u, ["prevent"])
2582
- }, [
2583
- k("span", {
2584
- class: ee(["template-select__text", { "is-placeholder": f.value }])
2585
- }, fe(c.value), 3),
2586
- k("span", qo, [
2587
- oe(L(xn))
2588
- ])
2589
- ], 34),
2590
- x[1] || (x[1] = k("span", {
2591
- contenteditable: "false",
2592
- class: "template-select__suffix"
2593
- }, "​", -1)),
2594
- (M(), G(en, { to: "body" }, [
2595
- n.value ? (M(), O("div", {
2596
- key: 0,
2597
- ref_key: "dropdownRef",
2598
- ref: s,
2599
- class: "template-select__dropdown"
2600
- }, [
2601
- (M(!0), O(De, null, Be(e.node.attrs.options, (E, _) => (M(), O("div", {
2602
- key: E.value,
2603
- class: ee(["template-select__option", {
2604
- "is-highlighted": _ === o.value,
2605
- "is-selected": E.value === e.node.attrs.value
2606
- }]),
2607
- onMousedown: Ye((C) => w(E), ["prevent"]),
2608
- onMouseenter: (C) => o.value = _
2609
- }, fe(E.label), 43, Uo))), 128))
2610
- ], 512)) : W("", !0)
2611
- ]))
2612
- ]),
2613
- _: 1
2614
- }));
2615
- }
2616
- }), Go = /* @__PURE__ */ Z(Xo, [["__scopeId", "data-v-dbb18436"]]), Yo = et.create({
2617
- name: A.TEMPLATE_SELECT,
2618
- // 节点配置
2619
- group: "inline",
2620
- inline: !0,
2621
- atom: !0,
2622
- // 原子节点,光标不能进入
2623
- selectable: !1,
2624
- draggable: !1,
2625
- // 节点属性
2626
- addAttributes() {
2627
- return {
2628
- id: {
2629
- default: null,
2630
- parseHTML: (e) => e.getAttribute("data-id"),
2631
- renderHTML: (e) => e.id ? { "data-id": e.id } : {}
2632
- },
2633
- placeholder: {
2634
- default: "Please select",
2635
- parseHTML: (e) => e.getAttribute("data-placeholder"),
2636
- renderHTML: (e) => ({ "data-placeholder": e.placeholder })
2637
- },
2638
- options: {
2639
- default: [],
2640
- parseHTML: (e) => {
2641
- const t = e.getAttribute("data-options");
2642
- if (!t) return [];
2643
- try {
2644
- return JSON.parse(t);
2645
- } catch (n) {
2646
- return console.warn("Failed to parse template select options:", n), [];
2647
- }
2648
- },
2649
- renderHTML: (e) => {
2650
- try {
2651
- return { "data-options": JSON.stringify(e.options) };
2652
- } catch (t) {
2653
- return console.error("Failed to stringify template select options:", t), { "data-options": "[]" };
2654
- }
911
+ }, Fe = () => {
912
+ H.clear(), L.clear();
913
+ }, Oe = () => {
914
+ if (!S.value || Q.value.range)
915
+ return;
916
+ const e = le(S.value);
917
+ if (e != null && e.collapsed && b.value.length > 0) {
918
+ const o = J(e), s = b.value[0];
919
+ if (o.startEl && o.startId === s.id && o.startOffset === 0 && s.content === v && s.type === "text") {
920
+ te(o.startEl, 1);
921
+ return;
922
+ }
923
+ const c = b.value[b.value.length - 1];
924
+ if (o.endEl && o.endId === c.id && o.endOffset === 1 && c.content === v && c.type === "text") {
925
+ te(o.endEl, 0);
926
+ return;
2655
927
  }
2656
- },
2657
- value: {
2658
- default: null,
2659
- parseHTML: (e) => e.getAttribute("data-value") || null,
2660
- renderHTML: (e) => e.value ? { "data-value": e.value } : {}
2661
928
  }
2662
929
  };
2663
- },
2664
- // HTML 解析
2665
- parseHTML() {
2666
- return [
2667
- {
2668
- tag: "span[data-template-select]"
2669
- }
2670
- ];
2671
- },
2672
- // HTML 渲染
2673
- renderHTML({ node: e, HTMLAttributes: t }) {
2674
- const n = e.attrs.options.find(
2675
- (s) => s.value === e.attrs.value
2676
- ), o = (n == null ? void 0 : n.label) || e.attrs.placeholder;
2677
- let i = "[]";
2678
- try {
2679
- i = JSON.stringify(e.attrs.options);
2680
- } catch (s) {
2681
- console.error("Failed to stringify template select options in renderHTML:", s);
2682
- }
2683
- return [
2684
- "span",
2685
- tt(t, {
2686
- "data-template-select": "",
2687
- "data-id": e.attrs.id,
2688
- "data-placeholder": e.attrs.placeholder,
2689
- "data-options": i,
2690
- "data-value": e.attrs.value || ""
2691
- }),
2692
- o
2693
- ];
2694
- },
2695
- // 使用 Vue 组件渲染
2696
- addNodeView() {
2697
- return Qe(Go);
2698
- },
2699
- // 添加插件
2700
- addProseMirrorPlugins() {
2701
- return [Ho(), Fo(), Vo()];
2702
- }
2703
- }), qt = _t.create({
2704
- name: xe.TEMPLATE,
2705
- addExtensions() {
2706
- return [Ko.configure(this.options), Yo];
2707
- },
2708
- // 添加命令(统一命令入口)
2709
- addCommands() {
2710
- return Do;
930
+ return pt(() => {
931
+ document.addEventListener("selectionchange", Oe), q(() => {
932
+ Z();
933
+ });
934
+ }), tt(() => {
935
+ document.removeEventListener("selectionchange", Oe);
936
+ }), a({
937
+ clearHistory: Fe,
938
+ activateFirstField: Ve
939
+ }), (e, o) => (m(), I("div", Pt, [
940
+ (m(), I("div", {
941
+ contenteditable: "true",
942
+ ref_key: "editorRef",
943
+ ref: S,
944
+ key: A.value,
945
+ class: "editor",
946
+ style: Ue(B.value),
947
+ onBeforeinput: Ke,
948
+ onCompositionstart: pe,
949
+ onCompositionend: He,
950
+ onKeydown: Ae
951
+ }, [
952
+ (m(!0), I(ye, null, xe(f.value, (s) => (m(), ee(Ft, Se({
953
+ key: `${s.id}-${s.type}`
954
+ }, { ref_for: !0 }, s), null, 16))), 128))
955
+ ], 36))
956
+ ]));
2711
957
  }
2712
- });
2713
- function jo(e, t) {
2714
- return qt.configure({
2715
- items: e,
2716
- ...t
2717
- });
2718
- }
2719
- function Zo(e, t) {
2720
- const n = V(null), o = Re(e, "placeholder"), i = () => {
2721
- var r;
2722
- const l = [
2723
- an,
2724
- cn,
2725
- un,
2726
- dn,
2727
- // 提供 undo/redo 功能
2728
- fn.configure({
2729
- placeholder: () => o.value || "请输入内容..."
2730
- }),
2731
- pn.configure({
2732
- mode: "textSize"
2733
- })
2734
- ];
2735
- return (r = e.extensions) != null && r.length && l.push(...e.extensions), l;
2736
- }, s = rn({
2737
- content: e.modelValue ?? e.defaultValue ?? "",
2738
- extensions: i(),
2739
- autofocus: e.autofocus ? "end" : !1,
2740
- editorProps: {
2741
- attributes: {
2742
- class: "tr-sender-editor"
2743
- },
2744
- // 处理粘贴事件 - 只粘贴纯文本
2745
- handlePaste(l, r) {
2746
- var T;
2747
- const a = (T = r.clipboardData) == null ? void 0 : T.getData("text/plain");
2748
- if (!a) return !1;
2749
- const c = e.mode === "single" ? a.replace(/\r?\n/g, " ") : a, { state: f } = l, { tr: u } = f;
2750
- return u.insertText(c), l.dispatch(u), pe(() => {
2751
- var y;
2752
- (y = s.value) == null || y.commands.scrollIntoView();
2753
- }), !0;
2754
- }
2755
- },
2756
- onUpdate: (l) => {
2757
- const r = l.editor.getText();
2758
- t("update:modelValue", r), t("input", r);
2759
- },
2760
- onFocus: (l) => {
2761
- t("focus", l.event);
2762
- },
2763
- onBlur: (l) => {
2764
- t("blur", l.event);
2765
- }
2766
- });
2767
- return K(
2768
- () => e.modelValue,
2769
- (l) => {
2770
- s.value && l !== s.value.getText() && s.value.commands.setContent(l ?? "", { emitUpdate: !1 });
2771
- }
2772
- ), K(
2773
- () => e.placeholder,
2774
- () => {
2775
- if (s.value) {
2776
- const { state: l } = s.value, r = l.tr;
2777
- s.value.view.dispatch(r);
2778
- }
2779
- }
2780
- ), tn(() => {
2781
- var l;
2782
- (l = s.value) == null || l.destroy();
2783
- }), {
2784
- editor: s,
2785
- editorRef: n
2786
- };
2787
- }
2788
- function Jo(e) {
2789
- const { submitType: t } = e;
2790
- return {
2791
- checkSubmitShortcut: (i) => {
2792
- if (!D(i, "ENTER")) return !1;
2793
- switch (t.value) {
2794
- case "enter":
2795
- return !i.shiftKey && !i.ctrlKey && !i.metaKey;
2796
- case "ctrlEnter":
2797
- return (i.ctrlKey || i.metaKey) && !i.shiftKey;
2798
- case "shiftEnter":
2799
- return i.shiftKey && !i.ctrlKey && !i.metaKey;
2800
- default:
2801
- return !1;
2802
- }
2803
- },
2804
- checkNewlineShortcut: (i) => {
2805
- if (!D(i, "ENTER")) return !1;
2806
- switch (t.value) {
2807
- case "enter":
2808
- return i.shiftKey || i.ctrlKey || i.metaKey;
2809
- case "ctrlEnter":
2810
- case "shiftEnter":
2811
- return !i.shiftKey && !i.ctrlKey && !i.metaKey;
2812
- default:
2813
- return !1;
2814
- }
2815
- }
2816
- };
2817
- }
2818
- function Qo(e, t, n) {
2819
- const o = V(e.mode || "single"), i = V(!1), s = V(e.mode || "single"), { start: l, stop: r } = mn(
2820
- () => {
2821
- i.value = !1;
2822
- },
2823
- 300,
2824
- { immediate: !1 }
2825
- ), a = B(() => {
2826
- var u;
2827
- return (u = n.value) == null ? void 0 : u.closest(".tr-sender-main");
2828
- }), c = () => {
2829
- if (s.value !== "single" || i.value || !t.value || !n.value) return;
2830
- const u = n.value.querySelector(".ProseMirror");
2831
- if (!u) return;
2832
- const T = t.value.getText();
2833
- o.value === "single" ? u.scrollWidth > u.clientWidth && f("multiple") : T.length || f("single");
2834
- }, f = (u) => {
2835
- o.value !== u && (i.value = !0, o.value = u, pe(() => {
2836
- t.value && t.value.commands.focus("end"), r(), l();
2837
- }));
2838
- };
2839
- return hn(a, () => {
2840
- requestAnimationFrame(() => {
2841
- c();
2842
- });
2843
- }), K(
2844
- () => e.mode,
2845
- (u) => {
2846
- u && u !== o.value && (s.value = u, f(u));
2847
- }
2848
- ), {
2849
- currentMode: o,
2850
- isAutoSwitching: i,
2851
- setMode: f,
2852
- checkOverflow: c
2853
- };
2854
- }
2855
- function es(e, t, n) {
2856
- const o = gn("--tr-sender-line-height", t), i = B(() => {
2857
- const r = o.value;
2858
- if (r) {
2859
- const a = parseFloat(r);
2860
- return isNaN(a) ? 26 : a;
2861
- }
2862
- return 26;
2863
- }), s = B(() => n === !1 || n === void 0 ? null : n === !0 ? {
2864
- minRows: 1,
2865
- maxRows: 5
2866
- } : typeof n == "object" ? {
2867
- minRows: n.minRows,
2868
- maxRows: n.maxRows
2869
- } : null), l = () => {
2870
- if (!t.value) return;
2871
- const r = t.value.querySelector(".tr-sender-editor-scroll");
2872
- if (!r) {
2873
- console.warn("⚠️ 找不到滚动容器 .tr-sender-editor-scroll");
2874
- return;
958
+ }), Nt = /* @__PURE__ */ _e(Wt, [["__scopeId", "data-v-b5c1a845"]]), nt = (n, a) => {
959
+ if (!a.length)
960
+ return [{ text: n, isMatch: !1 }];
961
+ const l = [];
962
+ for (const p of a) {
963
+ if (!p) continue;
964
+ let h = 0;
965
+ const v = n.toLowerCase(), y = p.toLowerCase();
966
+ for (; ; ) {
967
+ const C = v.indexOf(y, h);
968
+ if (C === -1) break;
969
+ l.push({
970
+ start: C,
971
+ end: C + p.length
972
+ }), h = C + 1;
2875
973
  }
2876
- const a = s.value;
2877
- if (e.value === "multiple" && a) {
2878
- const c = i.value * a.minRows, f = i.value * a.maxRows;
2879
- r.style.minHeight = `${c}px`, r.style.maxHeight = `${f}px`, r.style.overflowY = "auto";
2880
- } else
2881
- r.style.minHeight = "", r.style.maxHeight = "", r.style.overflowY = e.value === "single" ? "hidden" : "auto";
2882
- };
2883
- return K(
2884
- e,
2885
- () => {
2886
- pe(() => {
2887
- l();
2888
- });
2889
- },
2890
- { immediate: !0 }
2891
- ), K(
2892
- s,
2893
- () => {
2894
- pe(() => {
2895
- l();
2896
- });
2897
- },
2898
- { immediate: !0 }
2899
- ), {
2900
- updateHeight: l
2901
- };
2902
- }
2903
- function ts(e, t) {
2904
- const { editor: n, editorRef: o } = Zo(e, t), i = B(() => n.value ? Ge(n.value).trim().length > 0 : !1), s = B(() => n.value ? Ge(n.value).length : 0), l = B(() => e.maxLength ? s.value > e.maxLength : !1), r = B(() => {
2905
- var d, x;
2906
- return !e.disabled && !e.loading && i.value && !l.value && !((x = (d = e.defaultActions) == null ? void 0 : d.submit) != null && x.disabled);
2907
- }), a = () => {
2908
- if (!r.value || !n.value) return;
2909
- let d, x = "";
2910
- if (n.value.extensionManager.extensions.some((E) => E.name === xe.TEMPLATE)) {
2911
- const E = zt(n.value);
2912
- E.length > 0 && (d = E), x = Ge(n.value);
2913
- } else if (n.value.extensionManager.extensions.some((E) => E.name === xe.MENTION)) {
2914
- const E = Eo(n.value);
2915
- E.length > 0 && (d = E), x = vo(n.value);
974
+ }
975
+ if (l.length === 0)
976
+ return [{ text: n, isMatch: !1 }];
977
+ l.sort((p, h) => p.start - h.start);
978
+ const r = [];
979
+ for (const p of l)
980
+ if (r.length === 0)
981
+ r.push(p);
982
+ else {
983
+ const h = r[r.length - 1];
984
+ p.start <= h.end ? h.end = Math.max(h.end, p.end) : r.push(p);
2916
985
  }
2917
- x || (x = n.value.getText()), t("submit", x, d);
2918
- }, { currentMode: c, isAutoSwitching: f, setMode: u, checkOverflow: T } = Qo(e, n, o), y = Jo({
2919
- submitType: B(() => e.submitType ?? "enter")
2920
- });
2921
- K(
2922
- n,
2923
- (d) => {
2924
- d && d.setOptions({
2925
- editorProps: {
2926
- ...d.options.editorProps,
2927
- handleKeyDown: (x, E) => {
2928
- const _ = ue.getState(x.state), C = F.getState(x.state), I = be.getState(x.state);
2929
- return _ && _.active || C && C.active || I && I.isOpen ? !1 : y.checkSubmitShortcut(E) ? (E.preventDefault(), a(), !0) : y.checkNewlineShortcut(E) ? (E.preventDefault(), c.value === "single" ? (u("multiple"), setTimeout(() => {
2930
- d.commands.splitBlock(), d.commands.focus();
2931
- }, 0)) : d.commands.splitBlock(), !0) : !1;
2932
- }
986
+ const d = [];
987
+ let _ = 0;
988
+ for (const p of r)
989
+ _ < p.start && d.push({
990
+ text: n.substring(_, p.start),
991
+ isMatch: !1
992
+ }), d.push({
993
+ text: n.substring(p.start, p.end),
994
+ isMatch: !0
995
+ }), _ = p.end;
996
+ return _ < n.length && d.push({
997
+ text: n.substring(_),
998
+ isMatch: !1
999
+ }), d;
1000
+ }, zt = (n, a) => !a || !n ? [{ text: n, isMatch: !1 }] : nt(n, [a]), Ut = (n, a) => {
1001
+ const { content: l, highlights: r } = n;
1002
+ return typeof r == "function" ? r(l, a) : Array.isArray(r) ? nt(l, r) : zt(l, a);
1003
+ }, Gt = ["onMouseenter", "onMousedown"], qt = { class: "suggestion-list__text" }, jt = /* @__PURE__ */ Ce({
1004
+ __name: "SuggestionList",
1005
+ props: {
1006
+ show: { type: Boolean },
1007
+ suggestions: {},
1008
+ popupStyle: {},
1009
+ activeKeyboardIndex: {},
1010
+ activeMouseIndex: {},
1011
+ inputValue: {}
1012
+ },
1013
+ emits: ["select", "mouse-enter", "mouse-leave"],
1014
+ setup(n, { emit: a }) {
1015
+ const l = n, r = a, d = K(null), _ = (y) => y === l.activeKeyboardIndex || y === l.activeMouseIndex, p = (y) => {
1016
+ r("mouse-enter", y);
1017
+ }, h = () => {
1018
+ r("mouse-leave");
1019
+ }, v = (y) => {
1020
+ r("select", y);
1021
+ };
1022
+ return ne(
1023
+ () => l.activeKeyboardIndex,
1024
+ (y) => {
1025
+ if (y !== -1 && d.value) {
1026
+ const C = d.value.children[y];
1027
+ C && C.scrollIntoView({ block: "nearest" });
2933
1028
  }
2934
- });
2935
- },
2936
- { immediate: !0 }
2937
- ), es(c, o, e.autoSize), K(
2938
- () => {
2939
- var d;
2940
- return (d = n.value) == null ? void 0 : d.state.doc.content;
2941
- },
2942
- () => {
2943
- setTimeout(() => {
2944
- T();
2945
- }, 0);
2946
- },
2947
- { deep: !0 }
2948
- );
2949
- const w = () => {
2950
- var d;
2951
- (d = n.value) == null || d.commands.focus();
2952
- }, b = () => {
2953
- var d, x;
2954
- (d = n.value) == null || d.commands.clearContent(), (x = n.value) == null || x.commands.focus(), t("clear");
2955
- }, v = () => {
2956
- t("cancel");
2957
- }, h = () => {
2958
- var d;
2959
- (d = n.value) == null || d.commands.blur();
2960
- }, g = (d) => {
2961
- var x;
2962
- (x = n.value) == null || x.commands.setContent(d);
2963
- }, m = () => {
2964
- var d;
2965
- return ((d = n.value) == null ? void 0 : d.getText()) || "";
2966
- }, p = {
2967
- editor: n,
2968
- editorRef: o,
2969
- mode: c,
2970
- isAutoSwitching: f,
2971
- loading: B(() => e.loading ?? !1),
2972
- disabled: B(() => e.disabled ?? !1),
2973
- hasContent: i,
2974
- canSubmit: r,
2975
- isOverLimit: l,
2976
- characterCount: s,
2977
- maxLength: Re(e, "maxLength"),
2978
- size: B(() => e.size ?? "normal"),
2979
- showWordLimit: B(() => e.showWordLimit ?? !1),
2980
- clearable: B(() => e.clearable ?? !1),
2981
- defaultActions: Re(e, "defaultActions"),
2982
- submitType: B(() => e.submitType ?? "enter"),
2983
- stopText: Re(e, "stopText"),
2984
- submit: a,
2985
- clear: b,
2986
- cancel: v,
2987
- focus: w,
2988
- blur: h,
2989
- setContent: g,
2990
- getContent: m
2991
- };
2992
- return nn(on, p), {
2993
- context: p,
2994
- expose: {
2995
- submit: a,
2996
- clear: b,
2997
- cancel: v,
2998
- focus: w,
2999
- blur: h,
3000
- setContent: g,
3001
- getContent: m,
3002
- editor: n
3003
- }
3004
- };
3005
- }
3006
- function ut() {
3007
- const e = Me();
3008
- return B(() => ({
3009
- // 编辑器实例
3010
- editor: e.editor.value,
3011
- // 基础操作
3012
- focus: e.focus,
3013
- blur: e.blur,
3014
- // 内容操作(为增强按钮设计)
3015
- insert: (t) => {
3016
- var n;
3017
- (n = e.editor.value) == null || n.commands.insertContent(t + " "), e.focus();
3018
- },
3019
- append: (t) => {
3020
- const n = e.editor.value;
3021
- if (n) {
3022
- const o = n.state.doc.content.size;
3023
- n.chain().focus().insertContentAt(o, t).run();
3024
1029
  }
3025
- },
3026
- replace: (t) => {
3027
- e.setContent(t), e.focus();
3028
- },
3029
- // 常用状态
3030
- disabled: e.disabled.value,
3031
- loading: e.loading.value,
3032
- hasContent: e.hasContent.value
3033
- }));
3034
- }
3035
- const ns = { class: "tr-sender-editor-scroll" }, os = /* @__PURE__ */ j({
3036
- __name: "index",
3037
- setup(e) {
3038
- const { editor: t, editorRef: n } = Me();
3039
- return (o, i) => (M(), O("div", {
3040
- ref_key: "editorRef",
3041
- ref: n,
3042
- class: "tr-sender-editor-wrapper"
3043
- }, [
3044
- k("div", ns, [
3045
- L(t) ? (M(), G(L(ln), {
1030
+ ), (y, C) => (m(), ee(ze, { name: "tiny-sender-slide-up" }, {
1031
+ default: ve(() => [
1032
+ l.show && l.suggestions.length ? (m(), I("div", {
3046
1033
  key: 0,
3047
- editor: L(t),
3048
- class: "tr-sender-editor-content"
3049
- }, null, 8, ["editor"])) : W("", !0)
3050
- ])
3051
- ], 512));
1034
+ ref_key: "suggestionsListRef",
1035
+ ref: d,
1036
+ class: "suggestion-list",
1037
+ style: Ue(l.popupStyle)
1038
+ }, [
1039
+ (m(!0), I(ye, null, xe(l.suggestions, (g, O) => (m(), I("div", {
1040
+ key: O,
1041
+ class: oe(["suggestion-list__item", { highlighted: _(O) }]),
1042
+ onMouseenter: (V) => p(O),
1043
+ onMouseleave: h,
1044
+ onMousedown: ht((V) => v(g.content), ["prevent"])
1045
+ }, [
1046
+ Y(k(kt), { class: "suggestion-list__icon" }),
1047
+ z("span", qt, [
1048
+ (m(!0), I(ye, null, xe(k(Ut)(g, l.inputValue), (V, A) => (m(), I("span", {
1049
+ key: A,
1050
+ class: oe({
1051
+ "suggestion-list__text--match": V.isMatch,
1052
+ "suggestion-list__text--normal": !V.isMatch
1053
+ })
1054
+ }, de(V.text), 3))), 128))
1055
+ ])
1056
+ ], 42, Gt))), 128))
1057
+ ], 4)) : P("", !0)
1058
+ ]),
1059
+ _: 1
1060
+ }));
3052
1061
  }
3053
- }), Ut = /* @__PURE__ */ Z(os, [["__scopeId", "data-v-7f5b51aa"]]), ss = { class: "tr-sender-single-layout" }, rs = {
1062
+ }), Jt = /* @__PURE__ */ _e(jt, [["__scopeId", "data-v-e0ec9fe3"]]), Xt = ["data-theme"], Yt = { class: "tiny-sender__container" }, Zt = {
3054
1063
  key: 0,
3055
- class: "tr-sender-header"
3056
- }, is = { class: "tr-sender-container" }, ls = { class: "tr-sender-main" }, as = {
1064
+ class: "tiny-sender__header-slot"
1065
+ }, Qt = {
3057
1066
  key: 0,
3058
- class: "tr-sender-prefix"
3059
- }, cs = { class: "tr-sender-content" }, us = /* @__PURE__ */ j({
3060
- __name: "SingleLineLayout",
3061
- setup(e) {
3062
- const { editor: t, hasContent: n, loading: o, showWordLimit: i, maxLength: s } = Me(), l = ut();
3063
- return (r, a) => (M(), O("div", ss, [
3064
- r.$slots.header ? (M(), O("div", rs, [
3065
- R(r.$slots, "header", {}, void 0, !0)
3066
- ])) : W("", !0),
3067
- k("div", is, [
3068
- k("div", ls, [
3069
- r.$slots.prefix ? (M(), O("div", as, [
3070
- R(r.$slots, "prefix", {}, void 0, !0)
3071
- ])) : W("", !0),
3072
- k("div", cs, [
3073
- R(r.$slots, "content", { editor: L(t) }, () => [
3074
- oe(Ut)
3075
- ], !0)
3076
- ])
3077
- ]),
3078
- k("div", {
3079
- class: ee(["tr-sender-actions-inline", { "has-content": L(n) || L(o) }])
3080
- }, [
3081
- L(i) && L(s) ? (M(), G(L(bt), { key: 0 })) : W("", !0),
3082
- R(r.$slots, "actions-inline", me(he(L(l))), void 0, !0),
3083
- oe(L(St))
3084
- ], 2)
3085
- ])
3086
- ]));
3087
- }
3088
- }), ds = /* @__PURE__ */ Z(us, [["__scopeId", "data-v-87bc03b2"]]), fs = {
1067
+ class: "tiny-sender__prefix-slot"
1068
+ }, en = { class: "tiny-sender__content-area" }, tn = {
3089
1069
  key: 0,
3090
- class: "tr-sender-footer"
3091
- }, ps = { class: "tr-sender-footer-left" }, ms = { class: "tr-sender-footer-right" }, hs = /* @__PURE__ */ j({
3092
- __name: "index",
3093
- setup(e) {
3094
- const { mode: t, showWordLimit: n, maxLength: o } = Me(), i = ut();
3095
- return (s, l) => L(t) === "multiple" ? (M(), O("div", fs, [
3096
- k("div", ps, [
3097
- R(s.$slots, "footer", me(he(L(i))), void 0, !0)
3098
- ]),
3099
- k("div", ms, [
3100
- L(n) && L(o) ? (M(), G(L(bt), { key: 0 })) : W("", !0),
3101
- R(s.$slots, "footer-right", me(he(L(i))), void 0, !0),
3102
- oe(L(St))
3103
- ])
3104
- ])) : W("", !0);
3105
- }
3106
- }), gs = /* @__PURE__ */ Z(hs, [["__scopeId", "data-v-3a92a161"]]), ys = { class: "tr-sender-multi-layout" }, xs = {
1070
+ class: "tiny-sender__decorative-content"
1071
+ }, nn = {
1072
+ key: 2,
1073
+ class: "tiny-sender__input-field-wrapper"
1074
+ }, on = {
3107
1075
  key: 0,
3108
- class: "tr-sender-header"
3109
- }, Ts = { class: "tr-sender-main" }, vs = {
1076
+ class: "tiny-sender__completion-placeholder"
1077
+ }, sn = { class: "user-input-mirror" }, an = {
3110
1078
  key: 0,
3111
- class: "tr-sender-prefix"
3112
- }, Es = { class: "tr-sender-content" }, ws = /* @__PURE__ */ j({
3113
- __name: "MultiLineLayout",
3114
- setup(e) {
3115
- const t = Me(), n = ut();
3116
- return (o, i) => (M(), O("div", ys, [
3117
- o.$slots.header ? (M(), O("div", xs, [
3118
- R(o.$slots, "header", {}, void 0, !0)
3119
- ])) : W("", !0),
3120
- k("div", Ts, [
3121
- o.$slots.prefix ? (M(), O("div", vs, [
3122
- R(o.$slots, "prefix", {}, void 0, !0)
3123
- ])) : W("", !0),
3124
- k("div", Es, [
3125
- R(o.$slots, "content", {
3126
- editor: L(t).editor
3127
- }, () => [
3128
- oe(Ut)
3129
- ], !0)
3130
- ])
3131
- ]),
3132
- oe(gs, null, {
3133
- footer: $(() => [
3134
- R(o.$slots, "footer", me(he(L(n))), void 0, !0)
3135
- ]),
3136
- "footer-right": $(() => [
3137
- R(o.$slots, "footer-right", me(he(L(n))), void 0, !0)
3138
- ]),
3139
- _: 3
3140
- })
3141
- ]));
3142
- }
3143
- }), bs = /* @__PURE__ */ Z(ws, [["__scopeId", "data-v-0b507198"]]), Ss = /* @__PURE__ */ j({
1079
+ class: "tiny-sender__tab-hint"
1080
+ }, ln = {
1081
+ key: 1,
1082
+ class: "tiny-sender__actions-slot"
1083
+ }, rn = {
1084
+ key: 0,
1085
+ class: "tiny-sender__footer-slot tiny-sender__bottom-row"
1086
+ }, cn = { class: "tiny-sender__footer-left" }, un = { class: "tiny-sender__footer-right" }, dn = { class: "real-word-length" }, fn = {
1087
+ key: 1,
1088
+ class: "tiny-sender__toolbar"
1089
+ }, pn = { class: "tiny-sender__buttons-container" }, hn = {
1090
+ key: 1,
1091
+ class: "tiny-sender__footer-slot"
1092
+ }, vn = /* @__PURE__ */ Ce({
3144
1093
  __name: "index",
3145
1094
  props: {
3146
- modelValue: {},
1095
+ autofocus: { type: Boolean, default: !1 },
1096
+ autoSize: { type: [Boolean, Object], default: () => ({ minRows: 1, maxRows: 3 }) },
1097
+ allowSpeech: { type: Boolean, default: !0 },
1098
+ allowFiles: { type: Boolean, default: !1 },
1099
+ clearable: { type: Boolean, default: !1 },
1100
+ disabled: { type: Boolean, default: !1 },
3147
1101
  defaultValue: {},
3148
- placeholder: { default: "请输入内容..." },
3149
- disabled: { type: Boolean },
3150
- loading: { type: Boolean },
3151
- autofocus: { type: Boolean },
1102
+ loading: { type: Boolean, default: !1 },
1103
+ modelValue: { default: "" },
3152
1104
  mode: { default: "single" },
3153
- autoSize: { type: [Boolean, Object], default: () => ({ minRows: 1, maxRows: 5 }) },
3154
- maxLength: {},
3155
- showWordLimit: { type: Boolean },
3156
- clearable: { type: Boolean },
3157
- extensions: { default: () => [] },
3158
- size: { default: "normal" },
3159
- stopText: {},
3160
- defaultActions: {},
3161
- submitType: { default: "enter" }
1105
+ maxLength: { default: 1 / 0 },
1106
+ buttonGroup: {},
1107
+ submitType: { default: "enter" },
1108
+ speech: { type: [Boolean, Object] },
1109
+ placeholder: { default: "请输入内容..." },
1110
+ showWordLimit: { type: Boolean, default: !1 },
1111
+ suggestions: { default: () => [] },
1112
+ suggestionPopupWidth: { default: 400 },
1113
+ activeSuggestionKeys: {},
1114
+ theme: { default: "light" },
1115
+ templateData: { default: () => [] },
1116
+ stopText: { default: "" }
3162
1117
  },
3163
- emits: ["update:modelValue", "submit", "focus", "blur", "clear", "cancel", "input"],
3164
- setup(e, { expose: t, emit: n }) {
3165
- const o = e, i = n, { context: s, expose: l } = ts(o, i);
3166
- return t(l), (r, a) => (M(), O("div", {
3167
- class: ee([
3168
- "tr-sender",
3169
- `tr-sender--${L(s).mode.value}`,
3170
- `tr-sender--${L(s).size.value}`,
3171
- {
3172
- "is-auto-switching": L(s).isAutoSwitching.value,
3173
- "is-disabled": L(s).disabled.value
1118
+ emits: ["update:modelValue", "update:templateData", "submit", "clear", "speech-start", "speech-end", "speech-interim", "speech-error", "suggestion-select", "focus", "blur", "escape-press", "cancel", "reset-template", "files-selected"],
1119
+ setup(n, { expose: a, emit: l }) {
1120
+ const r = n, d = l, _ = K(null), p = K(null), h = K(null), v = K(null), y = K(null), C = E(() => r.templateData && r.templateData.length > 0), { inputValue: g, isComposing: O, clearInput: V } = Rt(r, d), A = E(() => !!g.value.trim()), F = E(() => {
1121
+ var t, i;
1122
+ return !(r.disabled || r.loading || !A.value || ie.value || (i = (t = r.buttonGroup) == null ? void 0 : t.submit) != null && i.disabled);
1123
+ }), {
1124
+ isPopupVisible: M,
1125
+ activeSuggestion: R,
1126
+ activeKeyboardIndex: W,
1127
+ activeMouseIndex: b,
1128
+ autoCompleteText: w,
1129
+ showTabIndicator: f,
1130
+ syncAutoComplete: S,
1131
+ closePopup: U,
1132
+ applySuggestion: Z,
1133
+ confirmSelection: B,
1134
+ navigateWithKeyboard: j,
1135
+ handleMouseEnter: G,
1136
+ handleMouseLeave: ke
1137
+ } = Ot(
1138
+ E(() => r.suggestions),
1139
+ g,
1140
+ O,
1141
+ C,
1142
+ (t) => d("update:modelValue", t),
1143
+ (t) => d("suggestion-select", t)
1144
+ ), L = K(r.mode), H = K(!1), ge = () => {
1145
+ L.value === "single" && (L.value = "multiple", q(() => {
1146
+ setTimeout(() => {
1147
+ const t = document.querySelector(".tiny-textarea__inner");
1148
+ if (t) {
1149
+ t.style.whiteSpace = "pre-wrap";
1150
+ const i = g.value.length;
1151
+ t.focus(), t.setSelectionRange(i, i);
1152
+ }
1153
+ }, 50);
1154
+ }));
1155
+ }, fe = (t, i) => {
1156
+ const u = document.createElement("span");
1157
+ u.style.visibility = "hidden", u.style.position = "absolute", u.style.whiteSpace = "nowrap", u.style.font = i, u.textContent = t, document.body.appendChild(u);
1158
+ const x = u.offsetWidth;
1159
+ return document.body.removeChild(u), x;
1160
+ }, le = () => {
1161
+ var $e, je, Je;
1162
+ if (r.mode !== "single" || !_.value || H.value || !p.value || !v.value) return;
1163
+ const t = p.value.querySelector(".tiny-sender__content-area");
1164
+ if (!t) return;
1165
+ const i = ((je = ($e = _.value) == null ? void 0 : $e.querySelector) == null ? void 0 : je.call($e, ".tiny-input__inner")) || t.querySelector(".tiny-input__inner"), u = y.value || p.value.querySelector(".tiny-sender__buttons-container");
1166
+ if (!i) {
1167
+ console.warn("Cannot find input element for overflow check");
1168
+ return;
1169
+ }
1170
+ const x = i.getBoundingClientRect(), N = u == null ? void 0 : u.getBoundingClientRect();
1171
+ if (x.width === 0) {
1172
+ setTimeout(() => le(), 50);
1173
+ return;
1174
+ }
1175
+ const T = window.getComputedStyle(i).font, $ = fe(g.value, T), D = (Je = p.value) == null ? void 0 : Je.classList.contains("tr-sender-compact"), X = D ? 12 : 20, ue = x.width, ot = (N == null ? void 0 : N.width) || 0, qe = ue - ot - X, st = D ? 50 : 80;
1176
+ $ > qe && qe > st && L.value === "single" && (H.value = !0, L.value = "multiple", q(() => {
1177
+ _.value ? setTimeout(() => {
1178
+ var Xe;
1179
+ const Be = (Xe = p.value) == null ? void 0 : Xe.querySelector(".tiny-textarea__inner");
1180
+ if (Be) {
1181
+ Be.style.whiteSpace = "pre-wrap";
1182
+ const Ye = g.value.length;
1183
+ Be.focus(), Be.setSelectionRange(Ye, Ye);
1184
+ }
1185
+ H.value = !1;
1186
+ }, 300) : H.value = !1;
1187
+ }));
1188
+ }, me = () => {
1189
+ if (C.value && h.value)
1190
+ o();
1191
+ else if (_.value)
1192
+ _.value.focus();
1193
+ else {
1194
+ const t = document.querySelector(".tiny-input__inner");
1195
+ t == null || t.focus();
1196
+ }
1197
+ }, te = () => {
1198
+ if (_.value)
1199
+ _.value.blur();
1200
+ else {
1201
+ const t = document.querySelector(".tiny-input__inner");
1202
+ t == null || t.blur();
1203
+ }
1204
+ }, re = () => {
1205
+ var t;
1206
+ d("update:templateData", []), (t = h.value) == null || t.clearHistory(), q(() => {
1207
+ g.value === "" && (L.value = r.mode || "single"), setTimeout(() => {
1208
+ me();
1209
+ }, 50);
1210
+ });
1211
+ }, Q = () => {
1212
+ var t;
1213
+ V(), C.value ? re() : (t = p.value) == null || t.focus(), q(() => {
1214
+ g.value === "" && (L.value = r.mode || "single");
1215
+ });
1216
+ }, Ke = (t) => {
1217
+ const i = (x) => x.type === "text" && x.content === "​";
1218
+ if (t.length === 0 || t.every(i)) {
1219
+ re();
1220
+ return;
1221
+ }
1222
+ d("update:templateData", t);
1223
+ };
1224
+ ne(
1225
+ () => r.templateData,
1226
+ () => {
1227
+ g.value = r.templateData.map((t) => t.content).join("");
1228
+ },
1229
+ { deep: !0 }
1230
+ );
1231
+ const J = E(() => {
1232
+ const t = typeof r.speech == "object" ? r.speech : {};
1233
+ return {
1234
+ ...t,
1235
+ onStart: () => d("speech-start"),
1236
+ onEnd: (i) => d("speech-end", i),
1237
+ onInterim: (i) => d("speech-interim", i),
1238
+ onFinal: (i) => {
1239
+ if (t.autoReplace)
1240
+ g.value = i;
1241
+ else {
1242
+ const u = g.value;
1243
+ u && i && !u.endsWith(" ") && !i.startsWith(" ") && u.length > 0 ? g.value = u + " " + i : g.value = u + i;
1244
+ }
1245
+ d("speech-end", i);
1246
+ },
1247
+ onError: (i) => {
1248
+ d("speech-error", i);
1249
+ }
1250
+ };
1251
+ }), { speechState: se, start: we, stop: Ie } = Et(J.value), Re = () => {
1252
+ se.isRecording ? Ie() : we();
1253
+ }, Te = async () => {
1254
+ const t = typeof r.speech == "object" ? r.speech : {}, i = se.isRecording;
1255
+ if (t.onVoiceButtonClick) {
1256
+ let u = !1;
1257
+ try {
1258
+ await t.onVoiceButtonClick(i, () => {
1259
+ u = !0;
1260
+ });
1261
+ } catch (x) {
1262
+ console.error("语音按钮点击拦截器执行失败:", x);
3174
1263
  }
3175
- ])
1264
+ if (u)
1265
+ return;
1266
+ }
1267
+ Re();
1268
+ }, ie = E(() => r.maxLength !== 1 / 0 && g.value.length > r.maxLength), { handleKeyPress: be, triggerSubmit: pe } = Tt(
1269
+ r,
1270
+ d,
1271
+ g,
1272
+ O,
1273
+ se,
1274
+ M,
1275
+ R,
1276
+ B,
1277
+ U,
1278
+ j,
1279
+ Re,
1280
+ F,
1281
+ L,
1282
+ ge,
1283
+ C,
1284
+ re
1285
+ ), He = (t) => {
1286
+ d("focus", t), g.value && !C.value && (M.value = !0);
1287
+ }, Ge = (t) => {
1288
+ d("blur", t), U();
1289
+ }, he = E(() => L.value === "multiple" ? "textarea" : "text"), Ae = vt(), Ee = E(() => !!Ae.decorativeContent), ce = E(() => r.disabled || Ee.value), Ve = E(() => r.loading), Fe = E(() => ({
1290
+ "is-disabled": ce.value,
1291
+ "is-loading": Ve.value,
1292
+ "is-auto-switching": H.value
1293
+ })), Oe = E(() => ({
1294
+ width: It(r.suggestionPopupWidth),
1295
+ maxWidth: "100%"
1296
+ // 确保不超出父容器宽度
1297
+ })), e = () => {
1298
+ O.value = !1;
1299
+ };
1300
+ ne(g, () => {
1301
+ q(le), g.value === "" && r.mode === "single" && (L.value = "single"), S();
1302
+ }), ne(
1303
+ () => C.value,
1304
+ (t) => {
1305
+ t && (L.value = "multiple");
1306
+ }
1307
+ );
1308
+ const o = () => {
1309
+ h.value && h.value.activateFirstField();
1310
+ }, { open: s, files: c } = mt({
1311
+ accept: Me(() => {
1312
+ var t, i;
1313
+ return ((i = (t = r.buttonGroup) == null ? void 0 : t.file) == null ? void 0 : i.accept) ?? "*";
1314
+ }),
1315
+ multiple: Me(() => {
1316
+ var t, i;
1317
+ return ((i = (t = r.buttonGroup) == null ? void 0 : t.file) == null ? void 0 : i.multiple) ?? !0;
1318
+ }),
1319
+ reset: Me(() => {
1320
+ var t, i;
1321
+ return ((i = (t = r.buttonGroup) == null ? void 0 : t.file) == null ? void 0 : i.reset) ?? !0;
1322
+ })
1323
+ });
1324
+ return ne(c, (t) => {
1325
+ t && t.length > 0 && d("files-selected", Array.from(t));
1326
+ }), a({
1327
+ focus: me,
1328
+ blur: te,
1329
+ clear: Q,
1330
+ submit: pe,
1331
+ startSpeech: we,
1332
+ stopSpeech: Ie,
1333
+ activateTemplateFirstField: o
1334
+ }), (t, i) => (m(), I("div", {
1335
+ ref_key: "senderRef",
1336
+ ref: p,
1337
+ class: oe(["tiny-sender", [Fe.value, `theme-${n.theme}`, `mode-${L.value}`]]),
1338
+ "data-theme": n.theme
3176
1339
  }, [
3177
- L(s).mode.value === "single" ? (M(), G(ds, { key: 0 }, pt({ _: 2 }, [
3178
- r.$slots.header ? {
3179
- name: "header",
3180
- fn: $(() => [
3181
- R(r.$slots, "header", {}, void 0, !0)
3182
- ]),
3183
- key: "0"
3184
- } : void 0,
3185
- r.$slots.prefix ? {
3186
- name: "prefix",
3187
- fn: $(() => [
3188
- R(r.$slots, "prefix", {}, void 0, !0)
3189
- ]),
3190
- key: "1"
3191
- } : void 0,
3192
- r.$slots.content ? {
3193
- name: "content",
3194
- fn: $((c) => [
3195
- R(r.$slots, "content", me(he(c)), void 0, !0)
3196
- ]),
3197
- key: "2"
3198
- } : void 0,
3199
- r.$slots["actions-inline"] ? {
3200
- name: "actions-inline",
3201
- fn: $(() => [
3202
- R(r.$slots, "actions-inline", {}, void 0, !0)
3203
- ]),
3204
- key: "3"
3205
- } : void 0
3206
- ]), 1024)) : (M(), G(bs, { key: 1 }, pt({ _: 2 }, [
3207
- r.$slots.header ? {
3208
- name: "header",
3209
- fn: $(() => [
3210
- R(r.$slots, "header", {}, void 0, !0)
3211
- ]),
3212
- key: "0"
3213
- } : void 0,
3214
- r.$slots.prefix ? {
3215
- name: "prefix",
3216
- fn: $(() => [
3217
- R(r.$slots, "prefix", {}, void 0, !0)
3218
- ]),
3219
- key: "1"
3220
- } : void 0,
3221
- r.$slots.content ? {
3222
- name: "content",
3223
- fn: $((c) => [
3224
- R(r.$slots, "content", me(he(c)), void 0, !0)
3225
- ]),
3226
- key: "2"
3227
- } : void 0,
3228
- r.$slots.footer ? {
3229
- name: "footer",
3230
- fn: $(() => [
3231
- R(r.$slots, "footer", {}, void 0, !0)
3232
- ]),
3233
- key: "3"
3234
- } : void 0,
3235
- r.$slots["footer-right"] ? {
3236
- name: "footer-right",
3237
- fn: $(() => [
3238
- R(r.$slots, "footer-right", {}, void 0, !0)
3239
- ]),
3240
- key: "4"
3241
- } : void 0
3242
- ]), 1024))
3243
- ], 2));
1340
+ z("div", Yt, [
1341
+ z("div", {
1342
+ class: "tiny-sender__input-wrapper",
1343
+ ref_key: "inputWrapperRef",
1344
+ ref: v
1345
+ }, [
1346
+ Y(ze, { name: "tiny-sender-slide-down" }, {
1347
+ default: ve(() => [
1348
+ t.$slots.header ? (m(), I("div", Zt, [
1349
+ ae(t.$slots, "header", {}, void 0, !0)
1350
+ ])) : P("", !0)
1351
+ ]),
1352
+ _: 3
1353
+ }),
1354
+ z("div", {
1355
+ class: oe(["tiny-sender__input-row", { "has-prefix": t.$slots.prefix, "has-header": t.$slots.header }])
1356
+ }, [
1357
+ t.$slots.prefix ? (m(), I("div", Qt, [
1358
+ ae(t.$slots, "prefix", {}, void 0, !0)
1359
+ ])) : P("", !0),
1360
+ z("div", en, [
1361
+ ae(t.$slots, "content", {}, () => [
1362
+ t.$slots.decorativeContent ? (m(), I("div", tn, [
1363
+ ae(t.$slots, "decorativeContent", {}, void 0, !0)
1364
+ ])) : P("", !0),
1365
+ C.value ? (m(), ee(Nt, {
1366
+ key: 1,
1367
+ ref_key: "templateEditorRef",
1368
+ ref: h,
1369
+ "model-value": r.templateData,
1370
+ "auto-size": n.autoSize,
1371
+ "onUpdate:modelValue": Ke,
1372
+ onSubmit: k(pe)
1373
+ }, null, 8, ["model-value", "auto-size", "onSubmit"])) : (m(), I("div", nn, [
1374
+ Y(k(gt), {
1375
+ ref_key: "inputRef",
1376
+ ref: _,
1377
+ autosize: n.autoSize,
1378
+ type: he.value,
1379
+ resize: "none",
1380
+ modelValue: k(g),
1381
+ "onUpdate:modelValue": i[0] || (i[0] = (u) => yt(g) ? g.value = u : null),
1382
+ disabled: ce.value,
1383
+ placeholder: n.placeholder,
1384
+ autofocus: n.autofocus,
1385
+ onKeydown: k(be),
1386
+ onCompositionstart: i[1] || (i[1] = (u) => O.value = !0),
1387
+ onCompositionend: e,
1388
+ onFocus: He,
1389
+ onBlur: Ge
1390
+ }, null, 8, ["autosize", "type", "modelValue", "disabled", "placeholder", "autofocus", "onKeydown"]),
1391
+ k(w) && !k(O) ? (m(), I("div", on, [
1392
+ z("span", sn, de(k(g)), 1),
1393
+ Qe(" " + de(k(w)) + " ", 1),
1394
+ k(f) ? (m(), I("div", an, "TAB")) : P("", !0)
1395
+ ])) : P("", !0)
1396
+ ]))
1397
+ ], !0)
1398
+ ]),
1399
+ L.value === "single" ? (m(), I("div", ln, [
1400
+ z("div", {
1401
+ class: "tiny-sender__buttons-container",
1402
+ ref_key: "buttonsContainerRef",
1403
+ ref: y
1404
+ }, [
1405
+ ae(t.$slots, "actions", {}, void 0, !0),
1406
+ Y(et, {
1407
+ "allow-speech": n.allowSpeech,
1408
+ "allow-files": n.allowFiles,
1409
+ loading: n.loading,
1410
+ disabled: ce.value,
1411
+ "show-clear": n.clearable,
1412
+ "has-content": A.value,
1413
+ "speech-status": k(se),
1414
+ "button-group": n.buttonGroup,
1415
+ "submit-type": n.submitType,
1416
+ "is-over-limit": ie.value,
1417
+ "stop-text": n.stopText,
1418
+ onClear: Q,
1419
+ onVoiceButtonClick: Te,
1420
+ onSubmit: k(pe),
1421
+ onCancel: i[2] || (i[2] = (u) => t.$emit("cancel")),
1422
+ onTriggerSelect: k(s)
1423
+ }, null, 8, ["allow-speech", "allow-files", "loading", "disabled", "show-clear", "has-content", "speech-status", "button-group", "submit-type", "is-over-limit", "stop-text", "onSubmit", "onTriggerSelect"])
1424
+ ], 512)
1425
+ ])) : P("", !0)
1426
+ ], 2),
1427
+ Y(ze, { name: "tiny-sender-slide-up" }, {
1428
+ default: ve(() => [
1429
+ L.value === "multiple" ? (m(), I("div", rn, [
1430
+ z("div", cn, [
1431
+ ae(t.$slots, "footer-left", {}, void 0, !0)
1432
+ ]),
1433
+ z("div", un, [
1434
+ ae(t.$slots, "footer-right", {}, void 0, !0),
1435
+ n.showWordLimit && n.maxLength !== 1 / 0 ? (m(), I("div", {
1436
+ key: 0,
1437
+ class: oe(["tiny-sender__word-limit", { "is-over-limit": ie.value }])
1438
+ }, [
1439
+ z("span", dn, de(k(g).length), 1),
1440
+ Qe("/" + de(n.maxLength), 1)
1441
+ ], 2)) : P("", !0),
1442
+ L.value === "multiple" ? (m(), I("div", fn, [
1443
+ z("div", pn, [
1444
+ Y(et, {
1445
+ "allow-speech": n.allowSpeech,
1446
+ "allow-files": n.allowFiles,
1447
+ loading: n.loading,
1448
+ disabled: ce.value,
1449
+ "show-clear": n.clearable,
1450
+ "has-content": A.value,
1451
+ "speech-status": k(se),
1452
+ "button-group": n.buttonGroup,
1453
+ "submit-type": n.submitType,
1454
+ "is-over-limit": ie.value,
1455
+ "stop-text": n.stopText,
1456
+ onClear: Q,
1457
+ onVoiceButtonClick: Te,
1458
+ onSubmit: k(pe),
1459
+ onCancel: i[3] || (i[3] = (u) => t.$emit("cancel")),
1460
+ onTriggerSelect: k(s)
1461
+ }, null, 8, ["allow-speech", "allow-files", "loading", "disabled", "show-clear", "has-content", "speech-status", "button-group", "submit-type", "is-over-limit", "stop-text", "onSubmit", "onTriggerSelect"])
1462
+ ])
1463
+ ])) : P("", !0)
1464
+ ])
1465
+ ])) : t.$slots.footer ? (m(), I("div", hn, [
1466
+ ae(t.$slots, "footer", {}, void 0, !0)
1467
+ ])) : P("", !0)
1468
+ ]),
1469
+ _: 3
1470
+ })
1471
+ ], 512)
1472
+ ]),
1473
+ Y(Jt, {
1474
+ show: k(M),
1475
+ suggestions: n.suggestions,
1476
+ "popup-style": Oe.value,
1477
+ "active-keyboard-index": k(W),
1478
+ "active-mouse-index": k(b),
1479
+ "input-value": k(g),
1480
+ onSelect: k(Z),
1481
+ onMouseEnter: k(G),
1482
+ onMouseLeave: k(ke)
1483
+ }, null, 8, ["show", "suggestions", "popup-style", "active-keyboard-index", "active-mouse-index", "input-value", "onSelect", "onMouseEnter", "onMouseLeave"])
1484
+ ], 10, Xt));
3244
1485
  }
3245
- }), We = /* @__PURE__ */ Z(Ss, [["__scopeId", "data-v-283d5f77"]]);
3246
- We.name = "TrSender";
3247
- const As = function(e) {
3248
- e.component(We.name, We);
3249
- }, Hs = Object.assign(We, {
3250
- install: As,
3251
- // 扩展类(用于继承)
3252
- Mention: Ht,
3253
- Suggestion: Vt,
3254
- Template: qt,
3255
- // 便捷函数(用于简单场景)
3256
- mention: wo,
3257
- suggestion: Po,
3258
- template: jo
3259
- });
1486
+ }), De = /* @__PURE__ */ _e(vn, [["__scopeId", "data-v-dcefe1f1"]]);
1487
+ De.name = "TrSender";
1488
+ const yn = function(n) {
1489
+ n.component(De.name, De);
1490
+ };
1491
+ De.install = yn;
3260
1492
  export {
3261
- Hs as default,
3262
- Me as useSenderContext
1493
+ De as default
3263
1494
  };