@opentiny/tiny-robot 0.3.1-alpha.5 → 0.3.1-alpha.7

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