@opentiny/tiny-robot 0.3.0-alpha.3 → 0.3.0-alpha.31

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,438 +1,230 @@
1
- import { ref as O, watch as te, reactive as $e, computed as P, nextTick as W, defineComponent as be, createElementBlock as A, openBlock as D, createCommentVNode as H, createBlock as Q, unref as E, withCtx as Y, createVNode as G, normalizeClass as ae, resolveDynamicComponent as it, createElementVNode as U, mergeModels as Fe, useModel as rt, onMounted as ut, useSlots as ct, Transition as ve, renderSlot as se, isRef as Le, createTextVNode as Oe, toDisplayString as le, normalizeStyle as Ie, Fragment as Ae, renderList as Me, withModifiers as dt } from "vue";
2
- import { I as ft } from "../index5.js";
3
- import { g as z, i as pt, t as mt } from "../utils.js";
4
- import { B as fe } from "../index3.js";
5
- import { T as Ve } from "../index4.js";
6
- import { i as ht } from "../close.js";
7
- import { o as gt, H as vt, g as yt, F as bt, X as Ct, s as St } from "../tiny-robot-svgs.js";
8
- function wt(t, y) {
9
- const h = O(t.modelValue || t.defaultValue || ""), o = O(null);
10
- te(
11
- () => t.modelValue,
12
- (f) => {
13
- f !== void 0 && f !== h.value && (h.value = f);
1
+ import { ref as A, watch as ne, reactive as ot, computed as B, defineComponent as Se, createElementBlock as I, openBlock as b, createCommentVNode as N, normalizeStyle as Je, createBlock as Y, unref as C, withCtx as he, createElementVNode as q, createVNode as Q, normalizeClass as oe, toDisplayString as ue, useAttrs as st, resolveComponent as at, mergeProps as we, Fragment as ve, renderList as _e, mergeModels as lt, useModel as rt, onMounted as it, onUnmounted as ut, nextTick as te, Transition as Ve, withModifiers as ct, useSlots as dt, renderSlot as ie, isRef as ft, createTextVNode as Ge } from "vue";
2
+ import { TinyTooltip as Fe, TinyInput as pt } from "@opentiny/vue";
3
+ import { e as ht } from "../index3.js";
4
+ import { IconUpload as vt, IconVoice as yt, IconLoadingSpeech as gt, IconClear as mt, IconSend as bt, IconStop as wt, IconAssociate as _t } from "@opentiny/tiny-robot-svgs";
5
+ import { _ as Ce } from "../_plugin-vue_export-helper.js";
6
+ import { t as St } from "../utils.js";
7
+ function Ct(a, c) {
8
+ const s = A(a.modelValue || a.defaultValue || ""), u = A(null);
9
+ ne(
10
+ () => a.modelValue,
11
+ (h) => {
12
+ h !== void 0 && h !== s.value && (s.value = h);
14
13
  }
15
- ), te(
16
- () => h.value,
17
- (f) => {
18
- y("update:modelValue", f);
14
+ ), ne(
15
+ () => s.value,
16
+ (h) => {
17
+ c("update:modelValue", h);
19
18
  }
20
19
  );
21
- const x = (f) => {
22
- h.value = f, y("update:modelValue", f);
23
- }, u = (f) => {
24
- f == null || f.preventDefault();
25
- const p = h.value;
26
- !t.disabled && !t.loading && p.trim() && y("submit", p);
27
- }, i = () => {
28
- h.value = "", y("update:modelValue", ""), y("clear");
29
- }, r = O(!1);
20
+ const g = (h) => {
21
+ s.value = h, c("update:modelValue", h);
22
+ }, S = (h) => {
23
+ h == null || h.preventDefault();
24
+ const w = s.value;
25
+ !a.disabled && !a.loading && w.trim() && c("submit", w);
26
+ }, l = () => {
27
+ s.value = "", c("update:modelValue", ""), c("clear");
28
+ }, f = A(!1);
30
29
  return {
31
- inputValue: h,
32
- inputWrapper: o,
33
- isComposing: r,
34
- handleChange: x,
35
- handleSubmit: u,
36
- handleClear: i,
30
+ inputValue: s,
31
+ inputWrapper: u,
32
+ isComposing: f,
33
+ handleChange: g,
34
+ handleSubmit: S,
35
+ handleClear: l,
37
36
  clearInput: () => {
38
- i();
37
+ l();
39
38
  }
40
39
  };
41
40
  }
42
- const Pe = "​", ee = (t) => t.split("").every((y) => y === Pe), J = (t) => t.replace(/\u200B/g, ""), ye = () => document.createTextNode(Pe), Et = (t) => {
43
- const y = t.textContent || "", h = J(y);
44
- return !h || h.trim() === "";
45
- }, Be = (t) => {
46
- const y = t.nextSibling;
47
- if (y && y.nodeType === Node.TEXT_NODE && ee(y.textContent || ""))
48
- return;
49
- const h = ye();
50
- t.parentNode && t.parentNode.insertBefore(h, t.nextSibling);
51
- }, _t = (t) => {
52
- Array.from(t.childNodes).forEach((h) => {
53
- if (h.nodeType === Node.TEXT_NODE && ee(h.textContent || "")) {
54
- const o = h.previousSibling;
55
- o && o.nodeType === Node.ELEMENT_NODE && o.classList.contains("template-field") || h.parentNode && h.parentNode.removeChild(h);
56
- }
57
- });
58
- };
59
- function Tt(t, y, h, o, x, u, i, r, c, f, p, a, b, L) {
60
- const _ = (m) => !(t.disabled || t.loading || m.trim().length === 0 || a.value), v = () => {
61
- _(h.value) && y("submit", h.value.trim());
62
- }, R = (m, $) => {
63
- if (!(m.key === "Enter")) return !1;
64
- switch ($) {
41
+ function xt(a, c, s, u, g, S, l, f, x, h, w, y, K, V, F, M) {
42
+ const T = () => {
43
+ y.value && (F != null && F.value && (M == null || M()), c("submit", s.value.trim()));
44
+ }, H = (d, P) => {
45
+ if (!(d.key === "Enter")) return !1;
46
+ switch (P) {
65
47
  case "enter":
66
- return !m.shiftKey && !m.ctrlKey && !m.metaKey;
48
+ return !d.shiftKey && !d.ctrlKey && !d.metaKey;
67
49
  case "ctrlEnter":
68
- return (m.ctrlKey || m.metaKey) && !m.shiftKey;
50
+ return (d.ctrlKey || d.metaKey) && !d.shiftKey;
69
51
  case "shiftEnter":
70
- return m.shiftKey && !m.ctrlKey && !m.metaKey;
52
+ return d.shiftKey && !d.ctrlKey && !d.metaKey;
71
53
  default:
72
54
  return !1;
73
55
  }
74
56
  };
75
57
  return {
76
- handleKeyPress: (m) => {
77
- if (o.value) return;
78
- if (m.key === "Enter" && m.shiftKey && (b == null ? void 0 : b.value) === "single" && L) {
79
- m.preventDefault(), L();
80
- const V = m.target, K = V.selectionStart, C = h.value;
81
- h.value = C.substring(0, K) + `
82
- ` + C.substring(K), setTimeout(() => {
83
- V.selectionStart = V.selectionEnd = K + 1;
58
+ handleKeyPress: (d) => {
59
+ if (u.value) return;
60
+ if (d.key === "Enter" && d.shiftKey && (K == null ? void 0 : K.value) === "single" && V) {
61
+ d.preventDefault(), V();
62
+ const O = d.target, z = O.selectionStart, ee = s.value;
63
+ s.value = ee.substring(0, z) + `
64
+ ` + ee.substring(z), setTimeout(() => {
65
+ O.selectionStart = O.selectionEnd = z + 1;
84
66
  }, 0);
85
67
  return;
86
68
  }
87
- if (m.key === "Tab" && u.value && i.value) {
88
- m.preventDefault(), r();
89
- return;
90
- }
91
- if (u.value) {
92
- if (m.key === "ArrowDown") {
93
- m.preventDefault(), f("down");
69
+ if (S.value) {
70
+ if (d.key === "ArrowDown") {
71
+ d.preventDefault(), h("down");
94
72
  return;
95
73
  }
96
- if (m.key === "ArrowUp") {
97
- m.preventDefault(), f("up");
74
+ if (d.key === "ArrowUp") {
75
+ d.preventDefault(), h("up");
98
76
  return;
99
77
  }
100
- if (m.key === "Enter" && i.value) {
101
- m.preventDefault(), r();
78
+ if (l.value && (a.activeSuggestionKeys || ["Enter", "Tab"]).includes(d.key)) {
79
+ d.preventDefault(), f();
102
80
  return;
103
81
  }
104
82
  }
105
- if (m.key === "Escape") {
106
- u.value ? (c(), m.preventDefault()) : x.isRecording && (p(), m.preventDefault()), y("escape-press");
83
+ if (d.key === "Escape") {
84
+ S.value ? (x(), d.preventDefault()) : g.isRecording && (w(), d.preventDefault()), c("escape-press");
107
85
  return;
108
86
  }
109
- R(m, t.submitType) && _(h.value) && (m.preventDefault(), v());
87
+ H(d, a.submitType) && (d.preventDefault(), y.value && T());
110
88
  },
111
- triggerSubmit: v
112
- };
113
- }
114
- function Nt(t) {
115
- const y = (u, i, r) => {
116
- var L, _;
117
- const { startOffset: c, collapsed: f } = i;
118
- let p = i.startContainer;
119
- if ((L = p.parentElement) != null && L.classList.contains("template-field") && (p = p.parentElement), !f) return !1;
120
- const a = p.nodeType === Node.TEXT_NODE && c === 0 && u.key === "ArrowLeft", b = p.nodeType === Node.TEXT_NODE && c === (((_ = p.textContent) == null ? void 0 : _.length) || 0) && u.key === "ArrowRight";
121
- if (a || b) {
122
- let v = null, R = "inside";
123
- if (a)
124
- if (p.parentNode && p.parentNode.classList.contains("template-field"))
125
- v = p.parentNode, R = "before";
126
- else {
127
- let w = p.previousSibling;
128
- !w && p.parentNode && p.parentNode !== r && (w = p.parentNode.previousSibling), w && w.nodeType === Node.ELEMENT_NODE && w.classList.contains("template-field") && (v = w, R = "inside");
129
- }
130
- else if (b)
131
- if (p.parentNode && p.parentNode.classList.contains("template-field"))
132
- v = p.parentNode, R = "after";
133
- else {
134
- let w = p.nextSibling;
135
- !w && p.parentNode && p.parentNode !== r && (w = p.parentNode.nextSibling), w && w.nodeType === Node.ELEMENT_NODE && w.classList.contains("template-field") && (v = w, R = "inside");
136
- }
137
- if (v) {
138
- u.preventDefault();
139
- const w = document.createRange(), m = z(r);
140
- return m && (R === "before" ? w.setStartBefore(v) : R === "after" ? w.setStartAfter(v) : (w.selectNodeContents(v), w.collapse(u.key === "ArrowLeft")), m.removeAllRanges(), m.addRange(w)), !0;
141
- }
142
- }
143
- if (p.nodeType === Node.ELEMENT_NODE && p.classList.contains("template-field")) {
144
- const R = p.textContent || "", w = J(R);
145
- if (!w || w.trim() === "") {
146
- u.preventDefault();
147
- const m = document.createRange(), $ = z(r);
148
- if (!$) return !0;
149
- if (u.key === "ArrowLeft")
150
- m.setStartBefore(p);
151
- else {
152
- const V = p.nextSibling;
153
- V && V.nodeType === Node.TEXT_NODE && ee(V.textContent || "") ? (m.setStart(V, 0), m.setEnd(V, 0)) : m.setStartAfter(p);
154
- }
155
- return m.collapse(!0), $.removeAllRanges(), $.addRange(m), !0;
156
- }
157
- }
158
- if (p.nodeType === Node.TEXT_NODE && ee(p.textContent || "")) {
159
- const v = p.previousSibling, R = p.nextSibling;
160
- u.preventDefault();
161
- const w = document.createRange(), m = z(r);
162
- return m && (u.key === "ArrowLeft" ? v && v.nodeType === Node.ELEMENT_NODE && v.classList.contains("template-field") ? (w.selectNodeContents(v), w.collapse(!1)) : w.setStartBefore(p) : R ? R.nodeType === Node.ELEMENT_NODE && R.classList.contains("template-field") ? (w.selectNodeContents(R), w.collapse(!0)) : pt(r) ? (w.setStart(R, 1), w.collapse(!0)) : w.setStartAfter(p) : w.setStartAfter(p), m.removeAllRanges(), m.addRange(w)), !0;
163
- }
164
- return !1;
165
- }, h = (u, i, r) => {
166
- if (!i.collapsed) return !1;
167
- const { startContainer: c, startOffset: f } = i;
168
- if (c.nodeType === Node.TEXT_NODE && ee(c.textContent || "")) {
169
- const a = c.previousSibling;
170
- if (a && a.nodeType === Node.ELEMENT_NODE && a.classList.contains("template-field")) {
171
- const b = a, L = b.textContent || "", _ = J(L);
172
- if (!_ || _.trim() === "") {
173
- u.preventDefault();
174
- const v = b.previousSibling, R = c.nextSibling;
175
- b.parentNode && b.parentNode.removeChild(b), c.parentNode && c.parentNode.removeChild(c);
176
- const w = z(r);
177
- if (w) {
178
- const m = document.createRange();
179
- v ? v.nodeType === Node.ELEMENT_NODE && v.classList.contains("template-field") ? (m.selectNodeContents(v), m.collapse(!1)) : v.nodeType === Node.TEXT_NODE && ee(v.textContent || "") ? (m.setStart(v, 0), m.setEnd(v, 0)) : m.setStartAfter(v) : R ? m.setStartBefore(R) : m.setStart(r, 0), m.collapse(!0), w.removeAllRanges(), w.addRange(m);
180
- }
181
- return t.handleInput(), !0;
182
- } else {
183
- u.preventDefault();
184
- const v = z(r);
185
- if (v) {
186
- const R = document.createRange();
187
- R.selectNodeContents(b), R.collapse(!1), v.removeAllRanges(), v.addRange(R);
188
- }
189
- return !0;
190
- }
191
- }
192
- }
193
- if (c.nodeType === Node.TEXT_NODE && c.parentNode && c.parentNode.classList.contains("template-field") && c.textContent) {
194
- const a = c.textContent;
195
- if (J(a).length === 1 && f === a.length) {
196
- u.preventDefault(), c.textContent = "";
197
- const L = c.parentNode, _ = z(r);
198
- if (_) {
199
- const v = document.createRange();
200
- v.selectNodeContents(L), v.collapse(!0), _.removeAllRanges(), _.addRange(v);
201
- }
202
- return t.handleInput(), !0;
203
- }
204
- }
205
- if (f === 0) {
206
- let a = null;
207
- if (c.nodeType === Node.ELEMENT_NODE && c.classList.contains("template-field") ? a = c : c.nodeType === Node.TEXT_NODE && c.parentNode && c.parentNode.classList.contains("template-field") && (a = c.parentNode), a) {
208
- u.preventDefault();
209
- const b = z(r);
210
- return b && (i.setStartBefore(a), i.collapse(!0), b.removeAllRanges(), b.addRange(i)), !0;
211
- }
212
- }
213
- return !1;
214
- }, o = (u, i, r) => {
215
- if (!i.collapsed) return !1;
216
- const { startContainer: c, startOffset: f } = i;
217
- if (c.nodeType === Node.TEXT_NODE && c.parentNode && c.parentNode.classList.contains("template-field") && c.textContent) {
218
- const a = c.textContent, b = J(a);
219
- if (f === a.length && b.length === 1) {
220
- u.preventDefault(), c.textContent = "";
221
- const L = c.parentNode, _ = z(r);
222
- if (_) {
223
- const v = document.createRange();
224
- v.selectNodeContents(L), v.collapse(!0), _.removeAllRanges(), _.addRange(v);
225
- }
226
- return t.handleInput(), !0;
227
- }
228
- }
229
- return !1;
230
- };
231
- return {
232
- handleTemplateKeyDown: (u) => {
233
- if (t.isComposing.value) return;
234
- const i = t.editor.value;
235
- if (!i) return;
236
- const r = z(i);
237
- if (!r || r.rangeCount === 0) return;
238
- const c = r.getRangeAt(0);
239
- if (u.key === "Enter") {
240
- u.preventDefault(), t.onSubmit(t.getValueFromDOM());
241
- return;
242
- }
243
- (u.key === "ArrowLeft" || u.key === "ArrowRight") && !u.shiftKey && y(u, c, i) || u.key === "Backspace" && h(u, c, i) || u.key === "Delete" && o(u, c, i);
244
- }
89
+ triggerSubmit: T
245
90
  };
246
91
  }
247
- function xt(t) {
248
- const y = $e({
92
+ function kt(a) {
93
+ const c = ot({
249
94
  isRecording: !1,
250
95
  isSupported: typeof window < "u" && "webkitSpeechRecognition" in window || "SpeechRecognition" in window,
251
96
  error: void 0
252
- }), h = y.isSupported ? new (window.webkitSpeechRecognition || window.SpeechRecognition)() : void 0;
253
- h !== void 0 && (h.continuous = t.continuous ?? !1, h.interimResults = t.interimResults ?? !0, h.lang = t.lang ?? navigator.language, h.onstart = () => {
254
- var i;
255
- y.isRecording = !0, y.error = void 0, (i = t.onStart) == null || i.call(t);
256
- }, h.onend = () => {
257
- var i;
258
- y.isRecording = !1, (i = t.onEnd) == null || i.call(t);
259
- }, h.onresult = (i) => {
260
- var c, f;
261
- const r = Array.from(i.results).map((p) => p[0].transcript).join("");
262
- i.results[0].isFinal ? (c = t.onFinal) == null || c.call(t, r) : (f = t.onInterim) == null || f.call(t, r);
263
- }, h.onerror = (i) => {
264
- var r;
265
- y.error = new Error(i.error), y.isRecording = !1, (r = t.onError) == null || r.call(t, y.error);
97
+ }), s = c.isSupported ? new (window.webkitSpeechRecognition || window.SpeechRecognition)() : void 0;
98
+ s !== void 0 && (s.continuous = a.continuous ?? !1, s.interimResults = a.interimResults ?? !0, s.lang = a.lang ?? navigator.language, s.onstart = () => {
99
+ var l;
100
+ c.isRecording = !0, c.error = void 0, (l = a.onStart) == null || l.call(a);
101
+ }, s.onend = () => {
102
+ var l;
103
+ c.isRecording = !1, (l = a.onEnd) == null || l.call(a);
104
+ }, s.onresult = (l) => {
105
+ var x, h;
106
+ const f = Array.from(l.results).map((w) => w[0].transcript).join("");
107
+ l.results[0].isFinal ? (x = a.onFinal) == null || x.call(a, f) : (h = a.onInterim) == null || h.call(a, f);
108
+ }, s.onerror = (l) => {
109
+ var f;
110
+ c.error = new Error(l.error), c.isRecording = !1, (f = a.onError) == null || f.call(a, c.error);
266
111
  });
267
- const o = () => {
268
- var i;
269
- if (!h) {
270
- const r = new Error("浏览器不支持语音识别");
271
- y.error = r, (i = t.onError) == null || i.call(t, r);
112
+ const u = () => {
113
+ var l;
114
+ if (!s) {
115
+ const f = new Error("浏览器不支持语音识别");
116
+ c.error = f, (l = a.onError) == null || l.call(a, f);
272
117
  return;
273
118
  }
274
- if (y.isRecording) {
119
+ if (c.isRecording) {
275
120
  try {
276
- h.stop(), setTimeout(() => {
121
+ s.stop(), setTimeout(() => {
277
122
  try {
278
- h.start();
279
- } catch (r) {
280
- u(r);
123
+ s.start();
124
+ } catch (f) {
125
+ S(f);
281
126
  }
282
127
  }, 100);
283
- } catch (r) {
284
- u(r);
128
+ } catch (f) {
129
+ S(f);
285
130
  }
286
131
  return;
287
132
  }
288
133
  try {
289
- h.start();
290
- } catch (r) {
291
- u(r);
134
+ s.start();
135
+ } catch (f) {
136
+ S(f);
292
137
  }
293
- }, x = () => {
294
- if (h && y.isRecording)
138
+ }, g = () => {
139
+ if (s && c.isRecording)
295
140
  try {
296
- h.stop();
297
- } catch (i) {
298
- u(i);
141
+ s.stop();
142
+ } catch (l) {
143
+ S(l);
299
144
  }
300
- }, u = (i) => {
301
- var r;
302
- y.error = i instanceof Error ? i : new Error("语音识别操作失败"), y.isRecording = !1, (r = t.onError) == null || r.call(t, y.error);
145
+ }, S = (l) => {
146
+ var f;
147
+ c.error = l instanceof Error ? l : new Error("语音识别操作失败"), c.isRecording = !1, (f = a.onError) == null || f.call(a, c.error);
303
148
  };
304
149
  return {
305
- speechState: y,
306
- start: o,
307
- stop: x
150
+ speechState: c,
151
+ start: u,
152
+ stop: g
308
153
  };
309
154
  }
310
- const kt = (t, y) => {
311
- if (!y || !t)
312
- return [{ text: t, isMatch: !1 }];
313
- const h = t.toLowerCase(), o = y.toLowerCase(), x = [];
314
- let u = 0;
315
- for (; u < h.length; ) {
316
- const f = h.indexOf(o, u);
317
- if (f === -1) break;
318
- x.push({
319
- start: f,
320
- end: f + y.length
321
- }), u = f + 1;
322
- }
323
- if (x.length === 0)
324
- return [{ text: t, isMatch: !1 }];
325
- const i = [];
326
- for (const f of x)
327
- if (i.length === 0)
328
- i.push(f);
329
- else {
330
- const p = i[i.length - 1];
331
- f.start <= p.end ? p.end = Math.max(p.end, f.end) : i.push(f);
332
- }
333
- const r = [];
334
- let c = 0;
335
- for (const f of i)
336
- c < f.start && r.push({
337
- text: t.substring(c, f.start),
338
- isMatch: !1
339
- }), r.push({
340
- text: t.substring(f.start, f.end),
341
- isMatch: !0
342
- }), c = f.end;
343
- return c < t.length && r.push({
344
- text: t.substring(c),
345
- isMatch: !1
346
- }), r;
347
- };
348
- function Rt(t, y, h, o) {
349
- const x = O(!1), u = O(-1), i = O(-1), r = O(""), c = O(!1), f = O(null), p = O(!1), a = O(null), b = P(() => {
350
- if (!t.suggestions || !h.value || t.template) return [];
351
- const e = h.value.toLowerCase();
352
- return t.suggestions.filter((l) => l.toLowerCase().includes(e));
353
- }), L = P(() => {
354
- let e = -1;
355
- return a.value === "mouse" && i.value !== -1 ? e = i.value : a.value === "keyboard" && u.value !== -1 && (e = u.value), b.value[e] || null;
356
- }), _ = (e) => e === u.value || e === i.value, v = (e) => {
357
- if (a.value === null) {
358
- r.value = "", c.value = !1;
155
+ function It(a, c, s, u, g, S) {
156
+ const l = A(!1), f = A(-1), x = A(-1), h = A(null), w = A(""), y = A(!1), K = B(() => {
157
+ var J, X;
158
+ if (!((J = a.value) != null && J.length)) return "";
159
+ const k = h.value === "mouse" ? x.value : f.value;
160
+ return ((X = a.value[k]) == null ? void 0 : X.content) || "";
161
+ }), V = (k) => {
162
+ w.value = k, y.value = !0;
163
+ }, F = () => {
164
+ w.value = "", y.value = !1;
165
+ }, M = (k) => {
166
+ const J = k || K.value;
167
+ if (!J || !c.value) {
168
+ F();
359
169
  return;
360
170
  }
361
- const l = e || L.value;
362
- l && h.value && l.toLowerCase().startsWith(h.value.toLowerCase()) ? (r.value = l.substring(h.value.length), c.value = !0) : (r.value = "", c.value = !1);
363
- }, R = () => {
364
- x.value = !1, u.value = -1, i.value = -1, a.value = null, r.value = "", c.value = !1;
365
- }, w = () => {
366
- x.value = !0, u.value = -1, i.value = -1, a.value = null, v();
367
- }, m = () => {
368
- o.value || p.value || W(() => {
369
- h.value && t.suggestions && t.suggestions.length > 0 && !t.template && b.value.length > 0 ? w() : R();
370
- });
171
+ const X = J.substring(c.value.length);
172
+ J.toLowerCase().startsWith(c.value.toLowerCase()) && X ? V(X) : F();
173
+ }, T = () => {
174
+ f.value = -1, x.value = -1, h.value = null;
175
+ }, H = () => {
176
+ l.value = !0, M();
177
+ }, v = () => {
178
+ l.value = !1, T(), F();
179
+ }, d = B(() => {
180
+ var k;
181
+ return s.value ? !0 : !!(c.value && ((k = a.value) == null ? void 0 : k.length) > 0 && !u.value);
182
+ }), P = (k) => {
183
+ v(), c.value = k, g(k), S(k);
184
+ }, O = () => {
185
+ K.value && P(K.value);
186
+ }, z = (k) => {
187
+ !l.value || !a.value || (h.value = "keyboard", f.value === -1 ? f.value = k === "down" ? 0 : a.value.length - 1 : k === "down" ? f.value = (f.value + 1) % a.value.length : f.value = (f.value - 1 + a.value.length) % a.value.length, M());
188
+ }, ee = (k) => {
189
+ a.value && (h.value = "mouse", x.value = k, M());
190
+ }, U = () => {
191
+ a.value && (x.value = -1, f.value !== -1 ? h.value = "keyboard" : h.value = null, M());
371
192
  };
372
- te(h, m), te(() => t.suggestions, m);
373
- const $ = (e) => {
374
- p.value = !0, h.value = e, y("update:modelValue", e), y("suggestion-select", e), K(), W(() => {
375
- p.value = !1;
376
- });
377
- }, V = () => {
378
- L.value && $(L.value);
379
- }, K = () => {
380
- R();
381
- };
382
- return {
383
- showSuggestionsPopup: x,
384
- completionPlaceholder: r,
385
- showTabHint: c,
386
- suggestionsListRef: f,
387
- filteredSuggestions: b,
388
- activeSuggestion: L,
389
- isItemHighlighted: _,
390
- updateCompletionPlaceholder: v,
391
- updateSuggestionsState: m,
392
- selectSuggestion: $,
393
- acceptCurrentSuggestion: V,
394
- closeSuggestionsPopup: K,
395
- navigateSuggestions: (e) => {
396
- if (!x.value || b.value.length === 0) return;
397
- a.value = "keyboard", u.value === -1 ? u.value = e === "down" ? 0 : b.value.length - 1 : e === "down" ? u.value = (u.value + 1) % b.value.length : u.value = (u.value - 1 + b.value.length) % b.value.length;
398
- const l = b.value[u.value];
399
- l && v(l);
400
- const n = f.value;
401
- if (n) {
402
- const s = n.children[u.value];
403
- s && s.scrollIntoView({ block: "nearest" });
404
- }
405
- },
406
- handleSuggestionItemHover: (e) => {
407
- a.value = "mouse", i.value = e, v(b.value[e]);
408
- },
409
- handleSuggestionItemLeave: () => {
410
- if (i.value = -1, u.value !== -1) {
411
- a.value = "keyboard";
412
- const e = b.value[u.value];
413
- e && v(e);
414
- } else
415
- a.value = null, v();
416
- },
417
- handleClickOutside: () => {
418
- K();
419
- },
420
- highlightSuggestionText: kt
193
+ return ne(d, (k) => {
194
+ k ? l.value || H() : l.value && v();
195
+ }), {
196
+ // 弹窗控制
197
+ isPopupVisible: l,
198
+ openPopup: H,
199
+ closePopup: v,
200
+ // 自动完成占位符
201
+ autoCompleteText: w,
202
+ showTabIndicator: y,
203
+ syncAutoComplete: M,
204
+ // 选中控制层
205
+ activeSuggestion: K,
206
+ activeKeyboardIndex: f,
207
+ activeMouseIndex: x,
208
+ // 交互处理
209
+ navigateWithKeyboard: z,
210
+ handleMouseEnter: ee,
211
+ handleMouseLeave: U,
212
+ // 业务操作
213
+ applySuggestion: P,
214
+ confirmSelection: O
421
215
  };
422
216
  }
423
- const Dt = { class: "action-buttons" }, Ft = {
217
+ const Tt = { class: "action-buttons" }, Rt = { class: "action-buttons__submit-content" }, Ot = {
424
218
  key: 0,
425
- class: "action-buttons__utility"
426
- }, Lt = { class: "action-buttons__submit-content" }, Ot = {
427
- key: 1,
428
- class: "action-buttons__cancel"
429
- }, We = /* @__PURE__ */ be({
219
+ class: "action-buttons__cancel-text"
220
+ }, Et = /* @__PURE__ */ Se({
430
221
  __name: "ActionButtons",
431
222
  props: {
432
223
  loading: { type: Boolean, default: !1 },
433
224
  disabled: { type: Boolean, default: !1 },
434
225
  showClear: { type: Boolean, default: !0 },
435
226
  hasContent: { type: Boolean, default: !1 },
227
+ buttonGroup: {},
436
228
  allowSpeech: { type: Boolean, default: !1 },
437
229
  speechStatus: { default: () => ({
438
230
  isRecording: !1,
@@ -441,617 +233,753 @@ const Dt = { class: "action-buttons" }, Ft = {
441
233
  allowFiles: { type: Boolean, default: !1 },
442
234
  submitType: { default: "enter" },
443
235
  showShortcuts: { type: Boolean },
444
- isOverLimit: { type: Boolean, default: !1 }
236
+ isOverLimit: { type: Boolean, default: !1 },
237
+ stopText: { default: void 0 }
445
238
  },
446
- emits: ["clear", "toggle-speech", "submit", "cancel"],
447
- setup(t, { emit: y }) {
448
- const h = ht(), o = t, x = y, u = P(() => o.allowSpeech), i = P(() => o.speechStatus.isRecording), r = P(() => o.disabled), c = P(() => r.value || o.isOverLimit), f = P(() => o.allowFiles || o.allowSpeech || o.showClear), p = () => {
449
- r.value || x("clear");
450
- }, a = () => {
451
- if (!r.value) {
452
- const _ = !o.speechStatus.isRecording;
453
- x("toggle-speech", _);
239
+ emits: ["clear", "toggle-speech", "submit", "cancel", "trigger-select"],
240
+ setup(a, { emit: c }) {
241
+ const s = a, u = c, g = B(() => {
242
+ var d, P;
243
+ const v = (P = (d = s.buttonGroup) == null ? void 0 : d.file) == null ? void 0 : P.tooltips;
244
+ if (typeof v == "string" && v)
245
+ return () => v;
246
+ if (typeof v == "function")
247
+ return v;
248
+ }), S = B(() => {
249
+ var d, P;
250
+ const v = (P = (d = s.buttonGroup) == null ? void 0 : d.submit) == null ? void 0 : P.tooltips;
251
+ if (typeof v == "string" && v)
252
+ return () => v;
253
+ if (typeof v == "function")
254
+ return v;
255
+ }), l = B(() => s.allowSpeech), f = B(() => s.speechStatus.isRecording), x = B(() => s.disabled), h = B(() => {
256
+ var v, d;
257
+ return x.value || s.isOverLimit || ((d = (v = s.buttonGroup) == null ? void 0 : v.submit) == null ? void 0 : d.disabled);
258
+ }), w = B(() => s.allowFiles || s.allowSpeech || s.showClear), y = () => {
259
+ x.value || u("clear");
260
+ }, K = () => {
261
+ if (!x.value) {
262
+ const v = !s.speechStatus.isRecording;
263
+ u("toggle-speech", v);
454
264
  }
455
- }, b = () => {
456
- c.value || x("submit");
457
- }, L = () => {
458
- r.value || x("cancel");
459
- };
460
- return (_, v) => (D(), A("div", Dt, [
461
- f.value ? (D(), A("div", Ft, [
462
- _.allowFiles && !_.loading ? (D(), Q(E(Ve), {
265
+ }, V = () => {
266
+ h.value || u("submit");
267
+ }, F = () => {
268
+ x.value || u("cancel");
269
+ }, M = B(() => {
270
+ var v, d;
271
+ return x.value || ((d = (v = s.buttonGroup) == null ? void 0 : v.file) == null ? void 0 : d.disabled);
272
+ }), T = () => {
273
+ M.value || u("trigger-select");
274
+ }, H = B(() => {
275
+ var v, d;
276
+ return ((d = (v = s.buttonGroup) == null ? void 0 : v.file) == null ? void 0 : d.tooltipPlacement) || "top";
277
+ });
278
+ return (v, d) => (b(), I("div", Tt, [
279
+ w.value ? (b(), I("div", {
280
+ key: 0,
281
+ class: "action-buttons__utility",
282
+ style: Je({ "padding-right": v.hasContent || v.loading ? "0" : "6px" })
283
+ }, [
284
+ v.allowFiles && !v.loading ? (b(), Y(C(Fe), {
463
285
  key: 0,
464
- content: "上传文件",
465
- placement: "top"
286
+ effect: "light",
287
+ placement: H.value,
288
+ "render-content": g.value,
289
+ "visible-arrow": !1,
290
+ "popper-class": "tr-sender-actions-upload-button-popper"
466
291
  }, {
467
- default: Y(() => [
468
- G(E(fe), {
469
- class: "action-buttons__button action-buttons__file-button",
470
- type: "text",
471
- disabled: r.value
472
- }, {
473
- default: Y(() => [
474
- G(E(gt), {
475
- class: "action-buttons__icon",
476
- alt: "上传文件"
477
- })
478
- ]),
479
- _: 1
480
- }, 8, ["disabled"])
292
+ default: he(() => [
293
+ q("div", {
294
+ class: "action-buttons__button",
295
+ onClick: T,
296
+ onFocusCapture: d[0] || (d[0] = (P) => P.stopPropagation())
297
+ }, [
298
+ Q(C(vt), {
299
+ class: oe(["action-buttons__icon", { "is-disabled": M.value }]),
300
+ alt: "上传文件"
301
+ }, null, 8, ["class"])
302
+ ], 32)
481
303
  ]),
482
304
  _: 1
483
- })) : H("", !0),
484
- u.value && !_.loading ? (D(), Q(E(fe), {
305
+ }, 8, ["placement", "render-content"])) : N("", !0),
306
+ l.value && !v.loading ? (b(), I("div", {
485
307
  key: 1,
486
- class: ae(["action-buttons__button action-buttons__speech-button", { "is-recording": i.value }]),
487
- type: "text",
488
- disabled: r.value,
489
- onClick: a
490
- }, {
491
- default: Y(() => [
492
- i.value ? (D(), Q(E(yt), {
493
- key: 1,
494
- class: "action-buttons__icon action-buttons__icon--recording",
495
- alt: "语音中"
496
- })) : (D(), Q(E(vt), {
497
- key: 0,
498
- class: "action-buttons__icon",
499
- alt: "录音"
500
- }))
501
- ]),
502
- _: 1
503
- }, 8, ["disabled", "class"])) : H("", !0),
504
- _.showClear ? (D(), Q(E(Ve), {
308
+ class: oe(["action-buttons__button", { "is-recording": f.value }]),
309
+ onClick: K
310
+ }, [
311
+ f.value ? (b(), Y(C(gt), {
312
+ key: 1,
313
+ class: "action-buttons__icon action-buttons__icon--recording",
314
+ alt: "语音中"
315
+ })) : (b(), Y(C(yt), {
316
+ key: 0,
317
+ class: "action-buttons__icon",
318
+ alt: "录音"
319
+ }))
320
+ ], 2)) : N("", !0),
321
+ v.showClear ? (b(), Y(C(Fe), {
505
322
  key: 2,
506
323
  content: "清空内容",
507
324
  placement: "top"
508
325
  }, {
509
- default: Y(() => [
510
- G(E(fe), {
511
- class: "action-buttons__button action-buttons__clear-button",
512
- type: "text",
513
- disabled: r.value || !_.hasContent,
514
- onClick: p
515
- }, {
516
- default: Y(() => [
517
- (D(), Q(it(E(h)), { class: "action-buttons__icon action-buttons__icon--close" }))
518
- ]),
519
- _: 1
520
- }, 8, ["disabled"])
326
+ default: he(() => [
327
+ q("div", {
328
+ class: "action-buttons__button",
329
+ onClick: y
330
+ }, [
331
+ Q(C(mt), { class: "action-buttons__icon" })
332
+ ])
521
333
  ]),
522
334
  _: 1
523
- })) : H("", !0)
524
- ])) : H("", !0),
525
- _.hasContent || _.loading ? (D(), Q(E(fe), {
335
+ })) : N("", !0)
336
+ ], 4)) : N("", !0),
337
+ v.hasContent || v.loading ? (b(), I("div", {
526
338
  key: 1,
527
- type: "text",
528
339
  class: "action-buttons__button action-buttons__submit",
529
- disabled: _.loading ? r.value : c.value,
530
- onClick: v[0] || (v[0] = (R) => _.loading ? L() : b())
531
- }, {
532
- default: Y(() => [
533
- U("div", Lt, [
534
- _.loading ? (D(), A("div", Ot, [
535
- G(E(Ct), {
536
- class: "action-buttons__icon action-buttons__icon--stop",
537
- alt: "加载中"
538
- }),
539
- v[1] || (v[1] = U("span", { class: "action-buttons__cancel-text" }, "停止回答", -1))
540
- ])) : (D(), Q(E(bt), {
541
- key: 0,
542
- class: "action-buttons__icon action-buttons__icon--send",
543
- alt: "发送"
544
- }))
545
- ])
546
- ]),
547
- _: 1
548
- }, 8, ["disabled"])) : H("", !0)
340
+ onClick: d[1] || (d[1] = (P) => v.loading ? F() : V())
341
+ }, [
342
+ q("div", Rt, [
343
+ v.loading ? (b(), I("div", {
344
+ key: 1,
345
+ class: oe(["action-buttons__cancel", { "action-buttons__cancel--icon-only": !v.stopText }])
346
+ }, [
347
+ Q(C(wt), {
348
+ class: "action-buttons__icon action-buttons__icon--cancel",
349
+ alt: "停止"
350
+ }),
351
+ v.stopText ? (b(), I("span", Ot, ue(v.stopText), 1)) : N("", !0)
352
+ ], 2)) : (b(), Y(C(Fe), {
353
+ key: 0,
354
+ effect: "light",
355
+ placement: "top",
356
+ "render-content": S.value,
357
+ "visible-arrow": !1
358
+ }, {
359
+ default: he(() => [
360
+ Q(C(bt), {
361
+ class: oe(["action-buttons__icon", "action-buttons__icon--send", { "is-disabled": h.value }]),
362
+ alt: "发送"
363
+ }, null, 8, ["class"])
364
+ ]),
365
+ _: 1
366
+ }, 8, ["render-content"]))
367
+ ])
368
+ ])) : N("", !0)
549
369
  ]));
550
370
  }
551
- });
552
- function It(t, y) {
553
- const h = O(!1), o = $e({ ...y }), x = (e) => {
554
- Object.assign(o, e);
555
- }, u = (e) => {
556
- const l = [];
557
- let n = 0;
558
- const s = /\[(.*?)\]/g;
559
- let g;
560
- for (; (g = s.exec(e)) !== null; )
561
- g.index > n && l.push({ type: "text", content: e.substring(n, g.index) }), l.push({ type: "field", content: g[1] }), n = g.index + g[0].length;
562
- return n < e.length && l.push({ type: "text", content: e.substring(n) }), l;
563
- }, i = () => {
564
- if (!t.value) return "";
565
- let e = "";
566
- const l = (n) => {
567
- let s = "";
568
- if (n.nodeType === Node.TEXT_NODE) {
569
- const g = n.textContent || "";
570
- s += J(g);
571
- } else if (n.nodeType === Node.ELEMENT_NODE) {
572
- const g = n;
573
- if (g.classList.contains("template-field")) {
574
- const T = g.textContent || "";
575
- s += J(T);
576
- } else if (g.tagName.toLowerCase() === "span") {
577
- const T = g.textContent || "";
578
- s += J(T);
579
- } else if (g.tagName.toLowerCase() === "br")
580
- s += `
581
- `;
582
- else
583
- for (const T of Array.from(g.childNodes))
584
- s += l(T);
585
- }
586
- return s;
371
+ }), je = /* @__PURE__ */ Ce(Et, [["__scopeId", "data-v-687a8616"]]);
372
+ function $t(a, c = {}) {
373
+ let s = [], u = [], g = a;
374
+ return { commit: (w) => {
375
+ var y;
376
+ s.push(g), g = w, u.length && ((y = c.onRemoveHistory) == null || y.call(c, u)), u = [];
377
+ }, undo: () => s.length ? (u.push(g), g = s.pop(), g) : null, redo: () => u.length ? (s.push(g), g = u.pop(), g) : null, clear: () => {
378
+ var w, y;
379
+ s.length && ((w = c.onRemoveHistory) == null || w.call(c, s)), u.length && ((y = c.onRemoveHistory) == null || y.call(c, u)), s = [], u = [];
380
+ }, get: () => g };
381
+ }
382
+ const Bt = ["data-id", "data-type"], Lt = ["data-id", "data-type"], Dt = /* @__PURE__ */ Se({
383
+ inheritAttrs: !1,
384
+ __name: "Block",
385
+ props: {
386
+ id: {},
387
+ type: {},
388
+ content: {},
389
+ readonly: { type: Boolean },
390
+ asChild: { type: Boolean }
391
+ },
392
+ setup(a) {
393
+ const c = a, s = st();
394
+ return (u, g) => {
395
+ const S = at("Block", !0);
396
+ return c.type !== "block" ? (b(), I("span", we({
397
+ key: 0,
398
+ "data-id": c.id,
399
+ "data-type": c.type
400
+ }, C(s)), ue(c.content), 17, Bt)) : (b(), I(ve, { key: 1 }, [
401
+ c.asChild ? (b(!0), I(ve, { key: 0 }, _e(c.content, (l) => (b(), Y(S, we({
402
+ key: `${l.id}-${l.type}`
403
+ }, { ref_for: !0 }, l), null, 16))), 128)) : (b(), I("span", we({
404
+ key: 1,
405
+ "data-id": c.id,
406
+ "data-type": c.type
407
+ }, C(s)), [
408
+ (b(!0), I(ve, null, _e(c.content, (l) => (b(), Y(S, we({
409
+ key: `${l.id}-${l.type}`
410
+ }, { ref_for: !0 }, l), null, 16))), 128))
411
+ ], 16, Lt))
412
+ ], 64));
587
413
  };
588
- return t.value.childNodes.forEach((n) => {
589
- e += l(n);
590
- }), e;
591
- }, r = (e) => o.initialValues && typeof o.initialValues[e] == "string" ? o.initialValues[e] : "", c = (e, l) => {
592
- const n = document.createElement("span");
593
- return n.className = "template-field", n.setAttribute("data-placeholder", e), l && (n.textContent = l), W(() => {
594
- f(n, l || "");
595
- }), n;
596
- }, f = (e, l) => {
597
- const n = J(l);
598
- if (!n || n.trim() === "") {
599
- const s = e.getAttribute("data-placeholder") || "";
600
- s ? p(e, s, !0) : (e.style.minWidth = "", e.style.width = "");
601
- } else
602
- p(e, n, !1);
603
- Be(e);
604
- }, p = (e, l, n) => {
605
- const s = document.createElement("span");
606
- s.className = "template-field", s.style.visibility = "hidden", s.style.position = "absolute", s.style.top = "-9999px", s.style.left = "-9999px", s.style.whiteSpace = "nowrap", s.style.padding = "3px 8px", s.style.margin = "0 2px", s.style.boxSizing = "border-box", s.textContent = l, document.body.appendChild(s);
607
- const g = getComputedStyle(s), T = s.offsetWidth, I = parseFloat(g.fontSize);
608
- document.body.removeChild(s);
609
- const M = n ? 1.5 : 2, j = T / I, B = Math.max(M, Math.ceil(j));
610
- e.style.setProperty("min-width", `${B}em`, "important");
611
- const q = 20;
612
- B > q ? (e.style.setProperty("max-width", `${q}em`, "important"), e.style.setProperty("white-space", "normal", "important"), e.style.setProperty("word-break", "break-word", "important")) : e.style.removeProperty("max-width");
613
- }, a = (e) => {
614
- const n = (e === void 0 ? i() : e).trim().length > 0;
615
- h.value !== n && (h.value = n, o.onContentStatusChange(n));
616
- }, b = (e, l = "inside", n = !1) => {
617
- W(() => {
618
- const s = z(t.value);
619
- if (!s) return;
620
- const g = document.createRange();
621
- switch (l) {
622
- case "before":
623
- g.setStartBefore(e);
624
- break;
625
- case "after":
626
- g.setStartAfter(e);
627
- break;
628
- case "inside":
629
- default:
630
- g.selectNodeContents(e), g.collapse(n);
631
- break;
414
+ }
415
+ }), Kt = /* @__PURE__ */ Ce(Dt, [["__scopeId", "data-v-13862606"]]), At = { class: "editor-container" }, Me = "​", Pt = /* @__PURE__ */ Se({
416
+ __name: "TemplateEditor",
417
+ props: {
418
+ modelValue: { default: () => [] },
419
+ modelModifiers: {}
420
+ },
421
+ emits: /* @__PURE__ */ lt(["submit"], ["update:modelValue"]),
422
+ setup(a, { expose: c, emit: s }) {
423
+ const u = typeof window.ShadowRoot.prototype.getSelection == "function", g = typeof window.Selection.prototype.getComposedRanges == "function";
424
+ function S() {
425
+ const e = navigator.userAgent;
426
+ return e.includes("Safari") && !e.includes("Chrome") && !e.includes("Chromium") && !e.includes("CriOS");
427
+ }
428
+ const l = S(), f = () => Math.random().toString(36).substring(2, 15), x = Me, h = Me, w = Me, y = rt(a, "modelValue"), K = s, V = A(0), F = (e) => e.map((t) => ({
429
+ id: t.id || f(),
430
+ ...t.type === "template" ? { ...t, prefix: h, suffix: w } : t
431
+ })), M = (e) => e.map((t) => ({ id: t.id, type: t.type, content: t.content })), T = A(F(y.value || [])), H = (e) => {
432
+ T.value = e;
433
+ }, v = B(() => {
434
+ const e = [], t = [], n = T.value;
435
+ if (n.length >= 2) {
436
+ const r = n[0], p = n[1];
437
+ r.type === "text" && r.content.length === 0 && p.type === "template" && e.push({ ...r, content: x });
438
+ const _ = n[n.length - 1], E = n[n.length - 2];
439
+ _.type === "text" && _.content.length === 0 && E.type === "template" && t.push({ ..._, content: x });
632
440
  }
633
- s.removeAllRanges(), s.addRange(g), e.focus && e.focus();
634
- });
635
- }, L = () => {
636
- W(() => {
637
- const e = t.value;
638
- if (e) {
639
- const l = document.createRange(), n = z(e);
640
- l.selectNodeContents(e), l.collapse(!1), n && (n.removeAllRanges(), n.addRange(l)), e.focus();
441
+ n.length > 0 && n[0].type === "template" && e.push({ type: "text", content: x, id: f() }), n.length > 0 && n[n.length - 1].type === "template" && t.push({ type: "text", content: x, id: f() });
442
+ const i = new RegExp(x, "g");
443
+ return n.length > 0 && (n[0].content !== x && (n[0].content = n[0].content.replace(i, "")), n[n.length - 1].content !== x && (n[n.length - 1].content = n[n.length - 1].content.replace(i, ""))), e.concat(n).concat(t);
444
+ }), d = B(() => T.value.map((e) => e.type === "template" ? [
445
+ { id: e.id, type: "prefix", content: e.prefix },
446
+ { id: e.id, type: "template", content: e.content },
447
+ { id: e.id, type: "suffix", content: e.suffix }
448
+ ] : [e]).flat()), P = B(() => v.value.map((e) => e.type === "text" ? e : l ? {
449
+ id: e.id,
450
+ type: "block",
451
+ asChild: !0,
452
+ content: [
453
+ { id: e.id, type: "prefix", content: e.prefix },
454
+ {
455
+ id: e.id,
456
+ type: "block",
457
+ content: [
458
+ { id: e.id, type: "template", content: e.content },
459
+ { id: e.id, type: "suffix", content: e.suffix }
460
+ ]
461
+ }
462
+ ]
463
+ } : {
464
+ id: e.id,
465
+ type: "block",
466
+ asChild: !0,
467
+ content: [
468
+ {
469
+ id: e.id,
470
+ type: "block",
471
+ content: [
472
+ { id: e.id, type: "prefix", content: e.prefix },
473
+ { id: e.id, type: "template", content: e.content }
474
+ ]
475
+ },
476
+ { id: e.id, type: "suffix", content: e.suffix }
477
+ ]
478
+ })), O = A(null), z = (e) => {
479
+ const t = Date.now(), n = JSON.stringify(e);
480
+ return `${t}:${n}`;
481
+ }, ee = (e) => {
482
+ const t = parseInt(e.slice(0, 13)), n = JSON.parse(e.slice(14));
483
+ return {
484
+ timestamp: t,
485
+ data: n
486
+ };
487
+ }, U = /* @__PURE__ */ new Map(), k = $t(z(T.value), {
488
+ onRemoveHistory: (e) => {
489
+ for (const t of e)
490
+ U.delete(t);
641
491
  }
642
492
  });
643
- }, _ = (e, l) => {
644
- const n = t.value;
645
- if (!n) return null;
646
- n.innerHTML = "";
647
- let s = null;
648
- if (!l || l === o.template)
649
- e.forEach((g) => {
650
- if (g.type === "field") {
651
- const T = r(g.content), I = c(g.content, T);
652
- n.appendChild(I);
653
- const M = ye();
654
- n.appendChild(M), s || (s = I);
655
- } else
656
- n.appendChild(document.createTextNode(g.content));
657
- }), o.initialValues && Object.keys(o.initialValues).length > 0 && W(() => {
658
- const g = i();
659
- g !== o.value && (o.onValueChange(g), o.onInput(g));
660
- });
661
- else {
662
- const g = v(e, l);
663
- g.success ? g.elements.forEach((T) => {
664
- if (n.appendChild(T.node), T.isField) {
665
- const I = ye();
666
- n.appendChild(I);
667
- }
668
- T.isField && !s && (s = T.node);
669
- }) : (n.appendChild(document.createTextNode(l)), s = null);
670
- }
671
- return s;
672
- }, v = (e, l) => {
673
- const n = [];
674
- let s = 0, g = 0, T = !0;
675
- for (; g < e.length && s <= l.length && T; ) {
676
- const I = e[g];
677
- if (I.type === "text")
678
- l.substring(s).startsWith(I.content) ? (n.push({
679
- node: document.createTextNode(I.content),
680
- isField: !1
681
- }), s += I.content.length, g++) : T = !1;
682
- else {
683
- let M = "";
684
- const j = e.find((B, q) => q > g && B.type === "text");
685
- if (j) {
686
- const B = l.substring(s), q = B.indexOf(j.content);
687
- q !== -1 ? (M = B.substring(0, q), s += M.length) : T = !1;
688
- } else
689
- M = l.substring(s), s = l.length;
690
- if (T) {
691
- const B = c(I.content, M);
692
- n.push({ node: B, isField: !0 }), g++;
493
+ ne(
494
+ () => y.value,
495
+ (e) => {
496
+ const t = F(e || []);
497
+ if (JSON.stringify(t) !== JSON.stringify(T.value)) {
498
+ if (O.value) {
499
+ const i = le(O.value);
500
+ i && U.set(k.get(), Z(i));
501
+ }
502
+ H(t), k.commit(z(T.value));
693
503
  }
504
+ },
505
+ { deep: !0 }
506
+ );
507
+ const J = (e, t = document.body) => t.contains(e) ? e instanceof HTMLElement && e.dataset.id ? e : e.parentElement ? J(e.parentElement, t) : null : null, X = (e) => e === O.value, le = (e) => {
508
+ const t = window.getSelection();
509
+ if (!t)
510
+ return null;
511
+ const n = t.rangeCount > 0 ? t.getRangeAt(0) : null, i = e.getRootNode();
512
+ if (!(i instanceof ShadowRoot))
513
+ return n;
514
+ if (g) {
515
+ const r = t.getComposedRanges(l ? i : { shadowRoots: [i] });
516
+ return (r == null ? void 0 : r[0]) ?? null;
694
517
  }
695
- }
696
- if (T && g < e.length)
697
- for (let I = g; I < e.length; I++) {
698
- const M = e[I];
699
- if (M.type === "field") {
700
- const j = !o.value || o.value === "" ? r(M.content) : "", B = c(M.content, j);
701
- n.push({ node: B, isField: !0 });
702
- } else
703
- n.push({
704
- node: document.createTextNode(M.content),
705
- isField: !1
706
- });
518
+ if (u) {
519
+ const r = i.getSelection();
520
+ return r.rangeCount > 0 ? r.getRangeAt(0) : null;
707
521
  }
708
- return { success: T, elements: n };
709
- }, R = () => {
710
- if (!t.value) return;
711
- o.isInternalUpdate = !0;
712
- const e = u(o.template), l = _(e, o.value);
713
- a(), W(() => {
714
- if (S(), l) {
715
- const n = l.textContent || "", s = J(n);
716
- s && s.trim() !== "" ? b(l, "inside", !1) : b(l, "inside", !0);
717
- } else
718
- L();
719
- o.isInternalUpdate = !1;
720
- });
721
- }, w = () => {
722
- if (o.isComposing) return;
723
- $(), C(), m(), S();
724
- const e = i();
725
- e !== o.value && (o.onValueChange(e), o.onInput(e)), a(e), e === "" && t.value && Array.from(t.value.childNodes).every((n) => n.nodeType === Node.ELEMENT_NODE && n.classList.contains("template-field") ? Et(n) : !!(n.nodeType === Node.TEXT_NODE && ee(n.textContent || ""))) && $();
726
- }, m = () => {
727
- if (!t.value) return;
728
- _t(t.value), t.value.querySelectorAll(".template-field").forEach((l) => {
729
- Be(l);
730
- });
731
- }, $ = () => {
732
- if (!t.value) return;
733
- const e = [];
734
- t.value.childNodes.forEach((l) => {
735
- if (l.nodeType === Node.TEXT_NODE) {
736
- const n = l.textContent || "";
737
- if (ee(n)) {
738
- const s = l.previousSibling;
739
- if (s && s.nodeType === Node.ELEMENT_NODE && s.classList.contains("template-field"))
740
- return;
741
- }
742
- (n.trim() === "" || ee(n)) && e.push(l);
743
- } else l.nodeType === Node.ELEMENT_NODE && l.tagName.toLowerCase() === "br" && e.push(l);
744
- }), e.forEach((l) => {
745
- l.parentNode && l.parentNode.removeChild(l);
746
- });
747
- }, V = (e) => {
748
- if (!o.template || !o.initialValues)
749
- return "字段";
750
- for (const [l, n] of Object.entries(o.initialValues))
751
- if (n === e)
752
- return l;
753
- return e.length <= 2 || /^[[\]{}()]+$/.test(e) || e.includes("[") && e.includes("]") ? e : "字段";
754
- }, K = (e) => {
755
- const l = e.getAttribute("data-placeholder");
756
- if (l)
757
- return l;
758
- const n = e.getAttribute("title") || e.getAttribute("data-field") || e.getAttribute("data-key") || e.getAttribute("placeholder") || "";
759
- if (n)
760
522
  return n;
761
- const s = e.textContent || "";
762
- return V(s);
763
- }, C = () => {
764
- if (!t.value) return;
765
- t.value.querySelectorAll("span").forEach((l) => {
766
- const n = l, s = n.style, g = n.classList.contains("template-field"), T = n.hasAttribute("data-placeholder");
767
- if (g && T)
523
+ }, W = (e, t) => {
524
+ var i;
525
+ if (!e.firstChild || e.firstChild.nodeType !== Node.TEXT_NODE)
526
+ return { node: e, offset: 0 };
527
+ const n = ((i = e.firstChild.textContent) == null ? void 0 : i.length) ?? 0;
528
+ return { node: e.firstChild, offset: Math.min(t, n) };
529
+ }, G = (e, t, n, i) => {
530
+ const r = window.getSelection();
531
+ if (!r)
532
+ return;
533
+ const { node: p, offset: _ } = W(e, t);
534
+ if (!n) {
535
+ r.setBaseAndExtent(p, _, p, _);
768
536
  return;
769
- const I = s.backgroundColor && // 标准格式
770
- (s.backgroundColor === "rgba(0, 0, 0, 0.05)" || s.backgroundColor === "rgba(0, 0, 0, 0.08)" || // 可能的变体格式
771
- s.backgroundColor.includes("rgba(0, 0, 0, 0.05)") || s.backgroundColor.includes("rgba(0, 0, 0, 0.08)") || // 十六进制或其他可能的格式
772
- s.backgroundColor.toLowerCase().includes("0.05") || s.backgroundColor.toLowerCase().includes("0.08")), M = s.borderRadius === "4px" || s.padding === "3px 8px" || s.margin === "0px 2px" || s.whiteSpace === "nowrap" && s.padding && s.margin;
773
- if (I || M || T) {
774
- if (n.className = "template-field", !n.getAttribute("data-placeholder")) {
775
- const B = K(n);
776
- B && n.setAttribute("data-placeholder", B);
537
+ }
538
+ const { node: E, offset: j } = W(n, i ?? 0);
539
+ r.setBaseAndExtent(p, _, E, j);
540
+ }, ye = (e, t) => {
541
+ const n = f(), i = { id: n, type: "text", content: e };
542
+ if (t) {
543
+ const r = T.value.findIndex((p) => p.id === t);
544
+ r !== -1 ? (H(
545
+ T.value.slice(0, r + 1).concat(i).concat(T.value.slice(r + 1))
546
+ ), k.commit(z(T.value))) : console.warn(`can not find item with id: ${t}`);
547
+ } else
548
+ H([i].concat(T.value)), k.commit(z(T.value));
549
+ te(() => {
550
+ var p;
551
+ const r = (p = O.value) == null ? void 0 : p.querySelector(`[data-id="${n}"][data-type="text"]`);
552
+ r && G(r, e.length);
553
+ }), y.value = M(T.value);
554
+ }, se = A({
555
+ hasStarted: !1,
556
+ range: null
557
+ }), xe = (e) => {
558
+ var E;
559
+ const t = e;
560
+ e.preventDefault();
561
+ const { inputType: n } = t, i = (t.data || ((E = t.dataTransfer) == null ? void 0 : E.getData("text/plain")) || "").replace(h, "").replace(w, ""), r = t.getTargetRanges()[0];
562
+ if (!r) {
563
+ console.warn("range is null", r);
564
+ return;
565
+ }
566
+ const p = [
567
+ "insertText",
568
+ "insertFromPaste",
569
+ "insertReplacementText",
570
+ "deleteContentBackward",
571
+ "deleteContentForward",
572
+ "deleteWordBackward",
573
+ "deleteWordForward",
574
+ "deleteSoftLineBackward",
575
+ "deleteSoftLineForward",
576
+ "deleteByCut"
577
+ ], _ = le(O.value);
578
+ if (p.includes(n)) {
579
+ if (i && X(r.startContainer) && X(r.endContainer)) {
580
+ _ && U.set(k.get(), Z(_)), ye(i);
581
+ return;
777
582
  }
778
- n.removeAttribute("style");
779
- const j = n.textContent || "";
780
- f(n, j);
583
+ const j = Z(r);
584
+ j.startId && j.endId ? (_ && U.set(k.get(), Z(_)), ce(j, n, i)) : console.warn("range is not valid, range:", j);
585
+ } else n === "insertCompositionText" && se.value.hasStarted && (se.value = { hasStarted: !1, range: Z(r) });
586
+ }, Z = (e) => {
587
+ const t = J(e.startContainer, O.value), n = J(e.endContainer, O.value);
588
+ return {
589
+ collapsed: e.collapsed,
590
+ endContainer: e.endContainer,
591
+ endId: n == null ? void 0 : n.dataset.id,
592
+ endEl: n,
593
+ endOffset: e.endOffset,
594
+ endType: n == null ? void 0 : n.dataset.type,
595
+ startContainer: e.startContainer,
596
+ startId: t == null ? void 0 : t.dataset.id,
597
+ startEl: t,
598
+ startOffset: e.startOffset,
599
+ startType: t == null ? void 0 : t.dataset.type
600
+ };
601
+ }, ke = (e, t, n, i) => e.slice(0, n) + t + e.slice(i), ce = (e, t, n) => {
602
+ const i = Le(e);
603
+ if (!Array.isArray(i) || i.length === 0)
604
+ return;
605
+ const r = De(i, e, t, n);
606
+ if (r.some((R) => R.tag === "new")) {
607
+ const { afterId: R, content: $ } = r[0];
608
+ ye($, R);
609
+ return;
781
610
  }
782
- });
783
- }, S = () => {
784
- if (!t.value) return;
785
- t.value.querySelectorAll(".template-field").forEach((l) => {
786
- const n = l.textContent || "";
787
- f(l, n);
788
- });
789
- };
790
- return {
791
- // 状态
792
- hasContent: h,
793
- // 解析和DOM操作
794
- parseTemplateToParts: u,
795
- getValueFromDOM: i,
796
- getInitialContentForField: r,
797
- createFieldElement: c,
798
- // 光标操作
799
- setCursorTo: b,
800
- setCursorToEnd: L,
801
- // DOM更新
802
- updateEditorDOM: R,
803
- renderTemplateToDOM: _,
804
- // 事件处理
805
- handleInput: w,
806
- checkHasContent: a,
807
- cleanupEmptyTextNodes: $,
808
- // 推断 placeholder
809
- inferPlaceholderForContent: V,
810
- extractPlaceholderFromElement: K,
811
- // 方法
812
- resetFields: () => {
813
- if (!t.value) return;
814
- o.isInternalUpdate = !0;
815
- const e = t.value;
816
- e.innerHTML = "";
817
- const l = u(o.template);
818
- let n = "";
819
- l.forEach((s) => {
820
- if (s.type === "field") {
821
- const g = r(s.content), T = c(s.content, g);
822
- g && (n += g), e.appendChild(T);
823
- } else
824
- e.appendChild(document.createTextNode(s.content)), n += s.content;
825
- }), o.onValueChange(n), L(), a(n), W(() => {
826
- o.isInternalUpdate = !1;
827
- });
828
- },
829
- activateFirstField: () => {
830
- var l;
831
- const e = (l = t.value) == null ? void 0 : l.querySelector(".template-field");
832
- e ? b(e, "inside", !1) : L();
833
- },
834
- // 选项更新
835
- updateOptions: x
836
- };
837
- }
838
- const At = /* @__PURE__ */ be({
839
- __name: "TemplateEditor",
840
- props: /* @__PURE__ */ Fe({
841
- value: {},
842
- autofocus: { type: Boolean }
843
- }, {
844
- value: { default: "" },
845
- valueModifiers: {}
846
- }),
847
- emits: /* @__PURE__ */ Fe(["input", "content-status", "submit", "focus", "blur", "empty-content"], ["update:value"]),
848
- setup(t, { expose: y, emit: h }) {
849
- const o = rt(t, "value"), x = t, u = h, i = O(null), r = O(""), c = O({}), f = O(!1), p = O(!1), a = It(i, {
850
- template: r.value,
851
- value: o.value,
852
- initialValues: c.value,
853
- isInternalUpdate: f,
854
- isComposing: p,
855
- onValueChange: (C) => {
856
- if (o.value !== C) {
857
- const S = f.value;
858
- f.value = !0, o.value = C, W(() => {
859
- f.value = S;
860
- });
611
+ const p = r, _ = [];
612
+ for (const [R, $] of p.entries()) {
613
+ const L = T.value.find((m) => m.id === $.id), o = R === 0 ? n : "";
614
+ L ? L.type === "text" ? L.content = ke(L.content, o, $.startOffset, $.endOffset) : L.type === "template" ? $.type === "prefix" || $.type === "suffix" ? $.startOffset === 0 && $.endOffset === 1 && o.length === 0 ? L[$.type] = "" : console.warn(`${$.type} can not be inserted text. it only can be deleted`, $) : $.startOffset < 0 || $.endOffset > L.content.length ? _.push(L.id) : L.content = ke(L.content, o, $.startOffset, $.endOffset) : console.warn("dataItem.type is not text or template", L) : console.warn("can not find dataItem", $);
615
+ }
616
+ let E = T.value.filter((R) => !_.includes(R.id));
617
+ E = E.filter((R) => !(R.type === "template" && [R.prefix, R.suffix, R.content].join("").length === 0));
618
+ const j = /* @__PURE__ */ new Set();
619
+ E.forEach((R, $, L) => {
620
+ if (L.length >= 2) {
621
+ if ($ === 0 || $ === 1) {
622
+ const o = L[0], m = L[1];
623
+ if (o.type === "text" && o.content.length === 0 && m.type === "template")
624
+ return;
625
+ }
626
+ if ($ === L.length - 2 || $ === L.length - 1) {
627
+ const o = L[L.length - 1], m = L[L.length - 2];
628
+ if (o.type === "text" && o.content.length === 0 && m.type === "template")
629
+ return;
630
+ }
861
631
  }
862
- },
863
- onInput: (C) => {
864
- u("input", C);
865
- },
866
- onContentStatusChange: (C) => u("content-status", C),
867
- onSubmit: (C) => u("submit", C)
868
- }), b = Nt({
869
- editor: i,
870
- isComposing: p,
871
- getValueFromDOM: a.getValueFromDOM,
872
- handleInput: a.handleInput,
873
- onSubmit: (C) => u("submit", C)
874
- }), L = (C, S) => {
875
- let N = C;
876
- return Object.entries(S).forEach(([X, e]) => {
877
- const l = `[${X}]`;
878
- N = N.replace(new RegExp(l.replace(/[[\]]/g, "\\$&"), "g"), e);
879
- }), N;
880
- }, _ = (C) => {
881
- f.value = !0, r.value = C.template, c.value = C.initialValues || {};
882
- const S = L(r.value, c.value);
883
- a.updateOptions({
884
- template: r.value,
885
- value: S,
886
- // 使用新生成的内容而不是旧的inputValue
887
- initialValues: c.value
888
- }), a.updateEditorDOM(), o.value = S, W(() => {
889
- f.value = !1;
632
+ R.type === "text" && R.content.length === 0 && j.add(R.id);
633
+ }), E = E.filter((R) => !j.has(R.id));
634
+ for (const R of E.filter(($) => $.type === "template"))
635
+ R.prefix.length === 0 && (R.prefix = h), R.suffix.length === 0 && (R.suffix = w);
636
+ H(E), k.commit(z(T.value)), p.length > 0 && ge(p, n), y.value = M(T.value);
637
+ }, ge = (e, t) => {
638
+ const n = e[0], i = `[data-id="${n.id}"][data-type="${n.type}"]`, r = e.slice(1).map((p) => `[data-id="${p.id}"][data-type="${p.type}"]`);
639
+ te(() => {
640
+ var _, E;
641
+ const p = (_ = O.value) == null ? void 0 : _.querySelector(i);
642
+ if (p)
643
+ G(p, n.startOffset + t.length);
644
+ else if (t.length === 0)
645
+ for (const j of r) {
646
+ const R = (E = O.value) == null ? void 0 : E.querySelector(j);
647
+ if (R) {
648
+ G(R, 0);
649
+ break;
650
+ }
651
+ }
652
+ else
653
+ console.warn(`can not find el with selector: ${i}`);
890
654
  });
891
- }, v = () => {
892
- p.value = !0;
893
- }, R = () => {
894
- p.value = !1, a.handleInput();
895
- }, w = (C) => {
896
- var X;
897
- if (!i.value) return;
898
- const S = C.target;
899
- let N = null;
900
- if (S.classList.contains("template-field") ? N = S : (X = S.parentElement) != null && X.classList.contains("template-field") && (N = S.parentElement), N && (!N.textContent || N.textContent.trim() === "")) {
901
- const e = z(i.value), l = document.createRange();
902
- e && (l.selectNodeContents(N), l.collapse(!0), e.removeAllRanges(), e.addRange(l), N.focus(), C.preventDefault(), C.stopPropagation());
655
+ }, Le = (e) => {
656
+ const t = d.value.findIndex((_) => _.id === e.startId && _.type === e.startType), n = d.value.findIndex((_) => _.id === e.endId && _.type === e.endType);
657
+ if (t === -1 || n === -1 || t > n)
658
+ return console.warn("startIndex or endIndex is -1, or startIndex > endIndex. ", { range: e }), null;
659
+ const i = d.value[t], r = d.value[n];
660
+ if (t === n)
661
+ return [
662
+ {
663
+ id: i.id,
664
+ type: i.type,
665
+ startOffset: e.startOffset,
666
+ endOffset: e.endOffset
667
+ }
668
+ ];
669
+ const p = [
670
+ {
671
+ id: i.id,
672
+ type: i.type,
673
+ startOffset: e.startOffset,
674
+ endOffset: i.content.length
675
+ }
676
+ ];
677
+ for (let _ = t + 1; _ < n; _++) {
678
+ const E = d.value[_];
679
+ p.push({
680
+ id: E.id,
681
+ type: E.type,
682
+ startOffset: 0,
683
+ endOffset: E.content.length
684
+ });
903
685
  }
904
- }, m = (C) => {
905
- if (typeof ShadowRoot.prototype.getSelection != "function")
906
- return;
907
- C.preventDefault();
908
- const S = C.clipboardData;
909
- if (!S) return;
910
- const N = S.getData("text/html"), X = S.getData("text/plain");
911
- if (N) {
912
- const e = document.createElement("div");
913
- e.innerHTML = N;
914
- const l = e.querySelectorAll("span");
915
- let n = !1;
916
- if (l.forEach((s) => {
917
- const g = s, T = g.style, I = g.classList.contains("template-field"), M = g.hasAttribute("data-placeholder"), j = T.backgroundColor && // 标准格式
918
- (T.backgroundColor === "rgba(0, 0, 0, 0.05)" || T.backgroundColor === "rgba(0, 0, 0, 0.08)" || // 可能的变体格式
919
- T.backgroundColor.includes("rgba(0, 0, 0, 0.05)") || T.backgroundColor.includes("rgba(0, 0, 0, 0.08)") || // 十六进制或其他可能的格式
920
- T.backgroundColor.toLowerCase().includes("0.05") || T.backgroundColor.toLowerCase().includes("0.08")), B = T.borderRadius === "4px" || T.padding === "3px 8px" || T.margin === "0px 2px" || T.whiteSpace === "nowrap";
921
- if (I || M || j || B) {
922
- if (n = !0, g.className = "template-field", !g.getAttribute("data-placeholder")) {
923
- const q = a.extractPlaceholderFromElement(g);
924
- q && g.setAttribute("data-placeholder", q);
925
- }
926
- g.removeAttribute("style");
686
+ return p.push({
687
+ id: r.id,
688
+ type: r.type,
689
+ startOffset: 0,
690
+ endOffset: e.endOffset
691
+ }), p;
692
+ }, De = (e, t, n, i) => {
693
+ const r = e[0];
694
+ if (r.type !== "prefix" && r.type !== "suffix")
695
+ return e;
696
+ if (e.length === 1) {
697
+ if (t.collapsed)
698
+ if (t.startOffset === 0) {
699
+ const p = ae(r, i);
700
+ return p ? [p] : [];
701
+ } else {
702
+ const p = de(r, i);
703
+ return p ? [p] : [];
704
+ }
705
+ if (n.startsWith("insert"))
706
+ if (l) {
707
+ const p = ae(r, i);
708
+ return p ? [p] : [];
709
+ } else {
710
+ const p = de(r, i);
711
+ return p ? [p] : [];
712
+ }
713
+ if (n.startsWith("delete")) {
714
+ if (n.includes("Backward")) {
715
+ const p = ae(r, i, 1);
716
+ return p ? [p] : [];
717
+ } else if (n.includes("Forward")) {
718
+ const p = de(r, i, 1);
719
+ return p ? [p] : [];
927
720
  }
928
- }), n) {
929
- $(e);
930
- return;
931
721
  }
932
722
  }
933
- X && V(X);
934
- }, $ = (C) => {
935
- const S = z(i.value);
936
- if (S && S.rangeCount > 0) {
937
- const N = S.getRangeAt(0);
938
- N.deleteContents();
939
- const X = document.createDocumentFragment();
940
- for (; C.firstChild; )
941
- X.appendChild(C.firstChild);
942
- N.insertNode(X), N.collapse(!1), S.removeAllRanges(), S.addRange(N), K();
723
+ return i.length > 0 ? e.slice(1) : e;
724
+ }, ae = (e, t, n = 0) => {
725
+ const i = d.value.findIndex((r) => r.id === e.id && r.type === e.type);
726
+ if (i > 0) {
727
+ const r = d.value[i - 1], { id: p, type: _, content: E } = r;
728
+ if (_ === "text" || _ === "template")
729
+ return {
730
+ id: p,
731
+ type: _,
732
+ startOffset: E.length - n,
733
+ endOffset: E.length
734
+ };
735
+ if (t.length > 0)
736
+ return { tag: "new", afterId: p, type: "text", content: t };
737
+ if (console.warn("the previous item is not text or template", { current: e, previous: r }), n === 1)
738
+ return { ...e, endOffset: e.startOffset };
739
+ } else return t.length > 0 ? { tag: "new", type: "text", content: t } : (console.warn("the previous item of current is not found", { current: e }), null);
740
+ return e;
741
+ }, de = (e, t, n = 0) => {
742
+ const i = d.value.findIndex((r) => r.id === e.id && r.type === e.type);
743
+ if (i < d.value.length - 1) {
744
+ const r = d.value[i + 1], { id: p, type: _ } = r;
745
+ if (_ === "text" || _ === "template")
746
+ return {
747
+ id: p,
748
+ type: _,
749
+ startOffset: 0,
750
+ endOffset: 0 + n
751
+ };
752
+ if (t.length > 0)
753
+ return { tag: "new", afterId: e.id, type: "text", content: t };
754
+ if (console.warn("the next item is not text or template", { current: e, next: r }), n === 1)
755
+ return { ...e, startOffset: e.endOffset };
756
+ } else return t.length > 0 ? { tag: "new", afterId: e.id, type: "text", content: t } : (console.warn("the next item of current is not found", { current: e }), null);
757
+ return e;
758
+ }, Ie = () => {
759
+ se.value = { hasStarted: !0, range: null };
760
+ }, me = (e) => {
761
+ const t = se.value.range;
762
+ t ? (e.data && X(t.startContainer) && X(t.endContainer) ? (U.set(k.get(), Z(t)), ye(e.data)) : t.startId && t.endId ? (U.set(k.get(), Z(t)), ce(t, "insertCompositionText", e.data)) : console.warn("range is not valid, range:", t), V.value++) : console.warn("range is null, compositionEnd:", e), se.value = { hasStarted: !1, range: null };
763
+ }, fe = (() => {
764
+ const e = navigator.userAgent.toLowerCase();
765
+ return /macintosh|mac os x|iphone|ipad|ipod/.test(e);
766
+ })(), pe = (e) => {
767
+ const t = fe && e.metaKey && !e.shiftKey && e.key.toLowerCase() === "z" || // Cmd+Z
768
+ !fe && e.ctrlKey && !e.shiftKey && e.key.toLowerCase() === "z", n = fe && e.metaKey && e.shiftKey && e.key.toLowerCase() === "z" || // Cmd+Shift+z
769
+ !fe && e.ctrlKey && (e.key.toLowerCase() === "y" || e.shiftKey && e.key.toLowerCase() === "z"), i = e.key.toLowerCase() === "enter";
770
+ if (t) {
771
+ e.preventDefault();
772
+ const r = le(O.value);
773
+ r && U.set(k.get(), Z(r));
774
+ const p = k.undo();
775
+ p && Te(p);
943
776
  }
944
- }, V = (C) => {
945
- const S = z(i.value);
946
- if (S && S.rangeCount > 0) {
947
- const N = S.getRangeAt(0);
948
- N.deleteContents(), N.insertNode(document.createTextNode(C)), N.collapse(!1), S.removeAllRanges(), S.addRange(N), K();
777
+ if (n) {
778
+ e.preventDefault();
779
+ const r = k.redo();
780
+ r && Te(r);
949
781
  }
950
- }, K = () => {
951
- p.value = !1, W(() => {
952
- a.handleInput();
953
- const C = a.getValueFromDOM();
954
- if (C !== o.value) {
955
- const S = f.value;
956
- f.value = !0, o.value = C, u("input", C), W(() => {
957
- f.value = S;
958
- });
959
- }
960
- setTimeout(() => {
961
- const S = a.getValueFromDOM();
962
- S !== o.value && (f.value = !0, o.value = S, u("input", S), W(() => {
963
- f.value = !1;
964
- }));
965
- }, 50);
782
+ i && (e.preventDefault(), K("submit"));
783
+ }, Te = (e) => {
784
+ const { data: t } = ee(e);
785
+ if (H(t), U.has(e)) {
786
+ const n = U.get(e);
787
+ te(() => {
788
+ const i = O.value.querySelector(`[data-id="${n.startId}"][data-type="${n.startType}"]`), r = O.value.querySelector(`[data-id="${n.endId}"][data-type="${n.endType}"]`);
789
+ i && G(i, n.startOffset, r, n.endOffset);
790
+ });
791
+ }
792
+ y.value = M(T.value);
793
+ }, Re = (e, t) => {
794
+ var r, p;
795
+ const n = (r = O.value) == null ? void 0 : r.querySelector(`[data-id="${e}"][data-type="${t}"]`);
796
+ if (!n) return;
797
+ const i = ((p = n.textContent) == null ? void 0 : p.length) || 0;
798
+ G(n, i);
799
+ }, Ke = () => {
800
+ O.value && te(() => {
801
+ const e = T.value, t = e.find((i) => i.type === "template");
802
+ t && Re(t.id, "template"), e.every((i) => i.type === "text") && e.length === 1 && Re(e[0].id, "text");
966
803
  });
967
- };
968
- return ut(() => {
969
- r.value && a.updateEditorDOM(), x.autofocus && i.value && a.setCursorToEnd();
970
- }), te(
971
- () => r.value,
972
- () => {
973
- f.value || (a.updateOptions({
974
- template: r.value,
975
- value: o.value,
976
- initialValues: c.value
977
- }), a.updateEditorDOM());
804
+ }, Ae = () => {
805
+ k.clear(), U.clear();
806
+ }, Oe = () => {
807
+ if (!O.value || se.value.range)
808
+ return;
809
+ const e = le(O.value);
810
+ if (e != null && e.collapsed && v.value.length > 0) {
811
+ const t = Z(e), n = v.value[0];
812
+ if (t.startEl && t.startId === n.id && t.startOffset === 0 && n.content === x && n.type === "text") {
813
+ G(t.startEl, 1);
814
+ return;
815
+ }
816
+ const i = v.value[v.value.length - 1];
817
+ if (t.endEl && t.endId === i.id && t.endOffset === 1 && i.content === x && i.type === "text") {
818
+ G(t.endEl, 0);
819
+ return;
820
+ }
978
821
  }
979
- ), te(
980
- () => c.value,
981
- () => {
982
- f.value || (a.updateOptions({
983
- template: r.value,
984
- value: o.value,
985
- initialValues: c.value
986
- }), a.updateEditorDOM());
987
- },
988
- { deep: !0 }
989
- ), te(
990
- () => o.value,
991
- (C) => {
992
- f.value || (a.updateOptions({
993
- template: r.value,
994
- value: C,
995
- initialValues: c.value
996
- }), a.updateEditorDOM()), (!C || C.trim() === "") && u("empty-content");
822
+ };
823
+ return it(() => {
824
+ document.addEventListener("selectionchange", Oe);
825
+ }), ut(() => {
826
+ document.removeEventListener("selectionchange", Oe);
827
+ }), c({
828
+ clearHistory: Ae,
829
+ activateFirstField: Ke
830
+ }), (e, t) => (b(), I("div", At, [
831
+ (b(), I("div", {
832
+ contenteditable: "true",
833
+ ref_key: "editorRef",
834
+ ref: O,
835
+ key: V.value,
836
+ class: "editor",
837
+ onBeforeinput: xe,
838
+ onCompositionstart: Ie,
839
+ onCompositionend: me,
840
+ onKeydown: pe
841
+ }, [
842
+ (b(!0), I(ve, null, _e(P.value, (n) => (b(), Y(Kt, we({
843
+ key: `${n.id}-${n.type}`
844
+ }, { ref_for: !0 }, n), null, 16))), 128))
845
+ ], 32))
846
+ ]));
847
+ }
848
+ }), Ft = /* @__PURE__ */ Ce(Pt, [["__scopeId", "data-v-5fda773e"]]), Xe = (a, c) => {
849
+ if (!c.length)
850
+ return [{ text: a, isMatch: !1 }];
851
+ const s = [];
852
+ for (const l of c) {
853
+ if (!l) continue;
854
+ let f = 0;
855
+ const x = a.toLowerCase(), h = l.toLowerCase();
856
+ for (; ; ) {
857
+ const w = x.indexOf(h, f);
858
+ if (w === -1) break;
859
+ s.push({
860
+ start: w,
861
+ end: w + l.length
862
+ }), f = w + 1;
863
+ }
864
+ }
865
+ if (s.length === 0)
866
+ return [{ text: a, isMatch: !1 }];
867
+ s.sort((l, f) => l.start - f.start);
868
+ const u = [];
869
+ for (const l of s)
870
+ if (u.length === 0)
871
+ u.push(l);
872
+ else {
873
+ const f = u[u.length - 1];
874
+ l.start <= f.end ? f.end = Math.max(f.end, l.end) : u.push(l);
875
+ }
876
+ const g = [];
877
+ let S = 0;
878
+ for (const l of u)
879
+ S < l.start && g.push({
880
+ text: a.substring(S, l.start),
881
+ isMatch: !1
882
+ }), g.push({
883
+ text: a.substring(l.start, l.end),
884
+ isMatch: !0
885
+ }), S = l.end;
886
+ return S < a.length && g.push({
887
+ text: a.substring(S),
888
+ isMatch: !1
889
+ }), g;
890
+ }, Mt = (a, c) => !c || !a ? [{ text: a, isMatch: !1 }] : Xe(a, [c]), Vt = (a, c) => {
891
+ const { content: s, highlights: u } = a;
892
+ return typeof u == "function" ? u(s, c) : Array.isArray(u) ? Xe(s, u) : Mt(s, c);
893
+ }, Wt = ["onMouseenter", "onMousedown"], Nt = { class: "suggestion-list__text" }, Ht = /* @__PURE__ */ Se({
894
+ __name: "SuggestionList",
895
+ props: {
896
+ show: { type: Boolean },
897
+ suggestions: {},
898
+ popupStyle: {},
899
+ activeKeyboardIndex: {},
900
+ activeMouseIndex: {},
901
+ inputValue: {}
902
+ },
903
+ emits: ["select", "mouse-enter", "mouse-leave"],
904
+ setup(a, { emit: c }) {
905
+ const s = a, u = c, g = A(null), S = (h) => h === s.activeKeyboardIndex || h === s.activeMouseIndex, l = (h) => {
906
+ u("mouse-enter", h);
907
+ }, f = () => {
908
+ u("mouse-leave");
909
+ }, x = (h) => {
910
+ u("select", h);
911
+ };
912
+ return ne(
913
+ () => s.activeKeyboardIndex,
914
+ (h) => {
915
+ if (h !== -1 && g.value) {
916
+ const w = g.value.children[h];
917
+ w && w.scrollIntoView({ block: "nearest" });
918
+ }
997
919
  }
998
- ), y({
999
- focus: () => {
1000
- var C;
1001
- (C = i.value) == null || C.focus(), a.setCursorToEnd();
1002
- },
1003
- resetFields: a.resetFields,
1004
- activateFirstField: a.activateFirstField,
1005
- getValueFromDOM: a.getValueFromDOM,
1006
- setTemplate: _
1007
- }), (C, S) => (D(), A("div", {
1008
- class: "template-editor",
1009
- ref_key: "contentEditableRef",
1010
- ref: i,
1011
- contenteditable: "true",
1012
- onInput: S[0] || (S[0] = //@ts-ignore
1013
- (...N) => E(a).handleInput && E(a).handleInput(...N)),
1014
- onKeydown: S[1] || (S[1] = //@ts-ignore
1015
- (...N) => E(b).handleTemplateKeyDown && E(b).handleTemplateKeyDown(...N)),
1016
- onClick: w,
1017
- onCompositionstart: v,
1018
- onCompositionend: R,
1019
- onFocus: S[2] || (S[2] = (N) => C.$emit("focus", N)),
1020
- onBlur: S[3] || (S[3] = (N) => C.$emit("blur", N)),
1021
- onPaste: m
1022
- }, null, 544));
920
+ ), (h, w) => (b(), Y(Ve, { name: "tiny-sender-slide-up" }, {
921
+ default: he(() => [
922
+ s.show && s.suggestions.length ? (b(), I("div", {
923
+ key: 0,
924
+ ref_key: "suggestionsListRef",
925
+ ref: g,
926
+ class: "suggestion-list",
927
+ style: Je(s.popupStyle)
928
+ }, [
929
+ (b(!0), I(ve, null, _e(s.suggestions, (y, K) => (b(), I("div", {
930
+ key: K,
931
+ class: oe(["suggestion-list__item", { highlighted: S(K) }]),
932
+ onMouseenter: (V) => l(K),
933
+ onMouseleave: f,
934
+ onMousedown: ct((V) => x(y.content), ["prevent"])
935
+ }, [
936
+ Q(C(_t), { class: "suggestion-list__icon" }),
937
+ q("span", Nt, [
938
+ (b(!0), I(ve, null, _e(C(Vt)(y, s.inputValue), (V, F) => (b(), I("span", {
939
+ key: F,
940
+ class: oe({
941
+ "suggestion-list__text--match": V.isMatch,
942
+ "suggestion-list__text--normal": !V.isMatch
943
+ })
944
+ }, ue(V.text), 3))), 128))
945
+ ])
946
+ ], 42, Wt))), 128))
947
+ ], 4)) : N("", !0)
948
+ ]),
949
+ _: 1
950
+ }));
1023
951
  }
1024
- }), Mt = ["data-theme"], Vt = { class: "tiny-sender__container" }, Bt = {
952
+ }), Ut = /* @__PURE__ */ Ce(Ht, [["__scopeId", "data-v-e0ec9fe3"]]), qt = ["data-theme"], zt = { class: "tiny-sender__container" }, Gt = {
1025
953
  key: 0,
1026
954
  class: "tiny-sender__header-slot"
1027
- }, Wt = {
955
+ }, jt = {
1028
956
  key: 0,
1029
957
  class: "tiny-sender__prefix-slot"
1030
- }, $t = { class: "tiny-sender__content-area" }, Pt = {
958
+ }, Jt = { class: "tiny-sender__content-area" }, Xt = {
1031
959
  key: 0,
1032
960
  class: "tiny-sender__decorative-content"
1033
- }, Ht = {
961
+ }, Zt = {
1034
962
  key: 2,
1035
963
  class: "tiny-sender__input-field-wrapper"
1036
- }, Kt = {
964
+ }, Qt = {
1037
965
  key: 0,
1038
966
  class: "tiny-sender__completion-placeholder"
1039
- }, Xt = { class: "user-input-mirror" }, qt = {
967
+ }, Yt = { class: "user-input-mirror" }, en = {
1040
968
  key: 0,
1041
969
  class: "tiny-sender__tab-hint"
1042
- }, zt = {
970
+ }, tn = {
1043
971
  key: 1,
1044
972
  class: "tiny-sender__actions-slot"
1045
- }, jt = { class: "tiny-sender__footer-left" }, Ut = { class: "tiny-sender__footer-right" }, Zt = { class: "real-word-length" }, Gt = {
973
+ }, nn = {
974
+ key: 0,
975
+ class: "tiny-sender__footer-slot tiny-sender__bottom-row"
976
+ }, on = { class: "tiny-sender__footer-left" }, sn = { class: "tiny-sender__footer-right" }, an = { class: "real-word-length" }, ln = {
1046
977
  key: 1,
1047
978
  class: "tiny-sender__toolbar"
1048
- }, Jt = { class: "tiny-sender__buttons-container" }, Qt = {
979
+ }, rn = { class: "tiny-sender__buttons-container" }, un = {
1049
980
  key: 1,
1050
981
  class: "tiny-sender__footer-slot"
1051
- }, Yt = ["onMouseenter", "onMousedown"], en = { class: "suggestion-item__text" }, tn = {
1052
- key: 0,
1053
- class: "tiny-sender__error"
1054
- }, pe = /* @__PURE__ */ be({
982
+ }, cn = /* @__PURE__ */ Se({
1055
983
  __name: "index",
1056
984
  props: {
1057
985
  autofocus: { type: Boolean, default: !1 },
@@ -1065,367 +993,362 @@ const At = /* @__PURE__ */ be({
1065
993
  modelValue: { default: "" },
1066
994
  mode: { default: "single" },
1067
995
  maxLength: { default: 1 / 0 },
996
+ buttonGroup: {},
1068
997
  submitType: { default: "enter" },
1069
998
  speech: { type: [Boolean, Object] },
1070
999
  placeholder: { default: "请输入内容..." },
1071
1000
  showWordLimit: { type: Boolean, default: !1 },
1072
1001
  suggestions: { default: () => [] },
1073
1002
  suggestionPopupWidth: { default: 400 },
1003
+ activeSuggestionKeys: {},
1074
1004
  theme: { default: "light" },
1075
- template: { default: "" },
1076
- hasContent: { type: Boolean, default: void 0 },
1077
- templateInitialValues: { default: () => ({}) }
1005
+ templateData: { default: () => [] },
1006
+ stopText: { default: "" }
1078
1007
  },
1079
- emits: ["update:modelValue", "submit", "clear", "speech-start", "speech-end", "speech-interim", "speech-error", "suggestion-select", "focus", "blur", "escape-press", "cancel", "reset-template"],
1080
- setup(t, { expose: y, emit: h }) {
1081
- const o = t, x = h, u = O(null), i = O(null), r = O(null), c = O(null), f = O(null), p = O(!1), { inputValue: a, isComposing: b, clearInput: L } = wt(o, x), {
1082
- showSuggestionsPopup: _,
1083
- completionPlaceholder: v,
1084
- showTabHint: R,
1085
- suggestionsListRef: w,
1086
- filteredSuggestions: m,
1087
- activeSuggestion: $,
1088
- isItemHighlighted: V,
1089
- updateSuggestionsState: K,
1090
- selectSuggestion: C,
1091
- acceptCurrentSuggestion: S,
1092
- closeSuggestionsPopup: N,
1093
- navigateSuggestions: X,
1094
- handleSuggestionItemHover: e,
1095
- handleSuggestionItemLeave: l,
1096
- highlightSuggestionText: n
1097
- } = Rt(o, x, a, b), s = O(o.mode), g = O(!1), T = () => {
1098
- s.value === "single" && (s.value = "multiple", W(() => {
1008
+ emits: ["update:modelValue", "update:templateData", "submit", "clear", "speech-start", "speech-end", "speech-interim", "speech-error", "suggestion-select", "focus", "blur", "escape-press", "cancel", "reset-template", "files-selected"],
1009
+ setup(a, { expose: c, emit: s }) {
1010
+ var L;
1011
+ const u = a, g = s, S = A(null), l = A(null), f = A(null), x = A(null), h = A(null), w = B(() => u.templateData && u.templateData.length > 0), { inputValue: y, isComposing: K, clearInput: V } = Ct(u, g), F = B(() => !!y.value.trim()), M = B(() => {
1012
+ var o, m;
1013
+ return !(u.disabled || u.loading || !F.value || be.value || (m = (o = u.buttonGroup) == null ? void 0 : o.submit) != null && m.disabled);
1014
+ }), {
1015
+ isPopupVisible: T,
1016
+ activeSuggestion: H,
1017
+ activeKeyboardIndex: v,
1018
+ activeMouseIndex: d,
1019
+ autoCompleteText: P,
1020
+ showTabIndicator: O,
1021
+ syncAutoComplete: z,
1022
+ closePopup: ee,
1023
+ applySuggestion: U,
1024
+ confirmSelection: k,
1025
+ navigateWithKeyboard: J,
1026
+ handleMouseEnter: X,
1027
+ handleMouseLeave: le
1028
+ } = It(
1029
+ B(() => u.suggestions),
1030
+ y,
1031
+ K,
1032
+ w,
1033
+ (o) => g("update:modelValue", o),
1034
+ (o) => g("suggestion-select", o)
1035
+ ), W = A(u.mode), G = A(!1), ye = () => {
1036
+ W.value === "single" && (W.value = "multiple", te(() => {
1099
1037
  setTimeout(() => {
1100
- const d = document.querySelector(".tiny-textarea__inner");
1101
- if (d) {
1102
- d.style.whiteSpace = "pre-wrap";
1103
- const k = a.value.length;
1104
- d.focus(), d.setSelectionRange(k, k);
1038
+ const o = document.querySelector(".tiny-textarea__inner");
1039
+ if (o) {
1040
+ o.style.whiteSpace = "pre-wrap";
1041
+ const m = y.value.length;
1042
+ o.focus(), o.setSelectionRange(m, m);
1105
1043
  }
1106
1044
  }, 50);
1107
1045
  }));
1108
- }, I = (d, k) => {
1109
- const F = document.createElement("span");
1110
- F.style.visibility = "hidden", F.style.position = "absolute", F.style.whiteSpace = "nowrap", F.style.font = k, F.textContent = d, document.body.appendChild(F);
1111
- const ne = F.offsetWidth;
1112
- return document.body.removeChild(F), ne;
1113
- }, M = () => {
1114
- var ce, xe, ke;
1115
- if (o.mode !== "single" || !u.value || g.value || !i.value || !c.value) return;
1116
- const d = i.value.querySelector(".tiny-sender__content-area");
1117
- if (!d) return;
1118
- const k = ((xe = (ce = u.value) == null ? void 0 : ce.querySelector) == null ? void 0 : xe.call(ce, ".tiny-input__inner")) || d.querySelector(".tiny-input__inner"), F = f.value || i.value.querySelector(".tiny-sender__buttons-container");
1119
- if (!k) {
1046
+ }, se = (o, m) => {
1047
+ const D = document.createElement("span");
1048
+ D.style.visibility = "hidden", D.style.position = "absolute", D.style.whiteSpace = "nowrap", D.style.font = m, D.textContent = o, document.body.appendChild(D);
1049
+ const re = D.offsetWidth;
1050
+ return document.body.removeChild(D), re;
1051
+ }, xe = () => {
1052
+ var Ee, He, Ue;
1053
+ if (u.mode !== "single" || !S.value || G.value || !l.value || !x.value) return;
1054
+ const o = l.value.querySelector(".tiny-sender__content-area");
1055
+ if (!o) return;
1056
+ const m = ((He = (Ee = S.value) == null ? void 0 : Ee.querySelector) == null ? void 0 : He.call(Ee, ".tiny-input__inner")) || o.querySelector(".tiny-input__inner"), D = h.value || l.value.querySelector(".tiny-sender__buttons-container");
1057
+ if (!m) {
1120
1058
  console.warn("Cannot find input element for overflow check");
1121
1059
  return;
1122
1060
  }
1123
- const ne = k.getBoundingClientRect(), Z = F == null ? void 0 : F.getBoundingClientRect();
1124
- if (ne.width === 0) {
1125
- setTimeout(() => M(), 50);
1061
+ const re = m.getBoundingClientRect(), Pe = D == null ? void 0 : D.getBoundingClientRect();
1062
+ if (re.width === 0) {
1063
+ setTimeout(() => xe(), 50);
1126
1064
  return;
1127
1065
  }
1128
- const ge = window.getComputedStyle(k).font, nt = I(a.value, ge), Te = (ke = i.value) == null ? void 0 : ke.classList.contains("tr-sender-compact"), st = Te ? 12 : 20, lt = ne.width, at = (Z == null ? void 0 : Z.width) || 0, Ne = lt - at - st, ot = Te ? 50 : 80;
1129
- nt > Ne && Ne > ot && s.value === "single" && (g.value = !0, s.value = "multiple", W(() => {
1130
- u.value ? setTimeout(() => {
1131
- var Re;
1132
- const de = (Re = i.value) == null ? void 0 : Re.querySelector(".tiny-textarea__inner");
1133
- if (de) {
1134
- de.style.whiteSpace = "pre-wrap";
1135
- const De = a.value.length;
1136
- de.focus(), de.setSelectionRange(De, De);
1066
+ const Ze = window.getComputedStyle(m).font, Qe = se(y.value, Ze), We = (Ue = l.value) == null ? void 0 : Ue.classList.contains("tr-sender-compact"), Ye = We ? 12 : 20, et = re.width, tt = (Pe == null ? void 0 : Pe.width) || 0, Ne = et - tt - Ye, nt = We ? 50 : 80;
1067
+ Qe > Ne && Ne > nt && W.value === "single" && (G.value = !0, W.value = "multiple", te(() => {
1068
+ S.value ? setTimeout(() => {
1069
+ var qe;
1070
+ const $e = (qe = l.value) == null ? void 0 : qe.querySelector(".tiny-textarea__inner");
1071
+ if ($e) {
1072
+ $e.style.whiteSpace = "pre-wrap";
1073
+ const ze = y.value.length;
1074
+ $e.focus(), $e.setSelectionRange(ze, ze);
1137
1075
  }
1138
- g.value = !1;
1139
- }, 300) : g.value = !1;
1076
+ G.value = !1;
1077
+ }, 300) : G.value = !1;
1140
1078
  }));
1141
- }, j = () => {
1142
- if (p.value && r.value)
1143
- Ce();
1144
- else if (u.value)
1145
- u.value.focus();
1079
+ }, Z = () => {
1080
+ if (w.value && f.value)
1081
+ p();
1082
+ else if (S.value)
1083
+ S.value.focus();
1146
1084
  else {
1147
- const d = document.querySelector(".tiny-input__inner");
1148
- d == null || d.focus();
1085
+ const o = document.querySelector(".tiny-input__inner");
1086
+ o == null || o.focus();
1149
1087
  }
1150
- }, B = () => {
1151
- p.value = !1, x("reset-template"), W(() => {
1152
- a.value === "" && (s.value = o.mode || "single"), setTimeout(() => {
1153
- j();
1088
+ }, ke = () => {
1089
+ if (S.value)
1090
+ S.value.blur();
1091
+ else {
1092
+ const o = document.querySelector(".tiny-input__inner");
1093
+ o == null || o.blur();
1094
+ }
1095
+ }, ce = () => {
1096
+ var o;
1097
+ g("update:templateData", []), (o = f.value) == null || o.clearHistory(), te(() => {
1098
+ y.value === "" && (W.value = u.mode || "single"), setTimeout(() => {
1099
+ Z();
1154
1100
  }, 50);
1155
1101
  });
1156
- }, q = () => {
1157
- var d;
1158
- L(), p.value ? B() : (d = i.value) == null || d.focus(), W(() => {
1159
- a.value === "" && (s.value = o.mode || "single");
1160
- }), N();
1161
- }, He = (d) => {
1162
- x("update:modelValue", d);
1163
- }, Ce = () => {
1164
- r.value && r.value.activateFirstField();
1165
- }, Ke = (d, k) => {
1166
- p.value = !0, W(() => {
1167
- r.value && r.value.setTemplate({ template: d, initialValues: k });
1102
+ }, ge = () => {
1103
+ var o;
1104
+ V(), w.value ? ce() : (o = l.value) == null || o.focus(), te(() => {
1105
+ y.value === "" && (W.value = u.mode || "single");
1168
1106
  });
1169
- }, Xe = P(() => {
1170
- const d = typeof o.speech == "object" ? o.speech : {};
1107
+ }, Le = (o) => {
1108
+ const m = (re) => re.type === "text" && re.content === "​";
1109
+ if (o.length === 0 || o.every(m)) {
1110
+ ce();
1111
+ return;
1112
+ }
1113
+ g("update:templateData", o);
1114
+ };
1115
+ ne(
1116
+ () => u.templateData,
1117
+ () => {
1118
+ y.value = u.templateData.map((o) => o.content).join("");
1119
+ },
1120
+ { deep: !0 }
1121
+ );
1122
+ const De = B(() => {
1123
+ const o = typeof u.speech == "object" ? u.speech : {};
1171
1124
  return {
1172
- ...d,
1173
- onStart: () => x("speech-start"),
1174
- onEnd: (k) => x("speech-end", k),
1175
- onInterim: (k) => x("speech-interim", k),
1176
- onFinal: (k) => {
1177
- if (d.autoReplace)
1178
- a.value = k;
1125
+ ...o,
1126
+ onStart: () => g("speech-start"),
1127
+ onEnd: (m) => g("speech-end", m),
1128
+ onInterim: (m) => g("speech-interim", m),
1129
+ onFinal: (m) => {
1130
+ if (o.autoReplace)
1131
+ y.value = m;
1179
1132
  else {
1180
- const F = a.value;
1181
- F && k && !F.endsWith(" ") && !k.startsWith(" ") && F.length > 0 ? a.value = F + " " + k : a.value = F + k;
1133
+ const D = y.value;
1134
+ D && m && !D.endsWith(" ") && !m.startsWith(" ") && D.length > 0 ? y.value = D + " " + m : y.value = D + m;
1182
1135
  }
1183
- x("speech-end", k);
1136
+ g("speech-end", m);
1184
1137
  },
1185
- onError: (k) => {
1186
- et(k.message), x("speech-error", k);
1138
+ onError: (m) => {
1139
+ g("speech-error", m);
1187
1140
  }
1188
1141
  };
1189
- }), { speechState: ie, start: Se, stop: we } = xt(Xe.value), me = () => {
1190
- ie.isRecording ? we() : Se();
1191
- }, re = P(() => o.maxLength !== 1 / 0 && a.value.length > o.maxLength), { handleKeyPress: qe, triggerSubmit: he } = Tt(
1192
- o,
1193
- x,
1194
- a,
1195
- b,
1196
- ie,
1197
- _,
1198
- $,
1199
- S,
1200
- N,
1201
- X,
1142
+ }), { speechState: ae, start: de, stop: Ie } = kt(De.value), me = () => {
1143
+ ae.isRecording ? Ie() : de();
1144
+ }, be = B(() => u.maxLength !== 1 / 0 && y.value.length > u.maxLength), { handleKeyPress: fe, triggerSubmit: pe } = xt(
1145
+ u,
1146
+ g,
1147
+ y,
1148
+ K,
1149
+ ae,
1150
+ T,
1151
+ H,
1152
+ k,
1153
+ ee,
1154
+ J,
1202
1155
  me,
1203
- re,
1204
- s,
1205
- T
1206
- ), ze = (d) => {
1207
- x("focus", d), a.value && m.value.length > 0 && !o.template && (_.value = !0, R.value = !0);
1208
- }, je = (d) => {
1209
- x("blur", d), N();
1210
- }, Ue = P(() => s.value === "multiple" ? "textarea" : "text"), Ze = P(
1211
- () => ({
1212
- display: "flex",
1213
- justifyContent: o.showWordLimit && o.maxLength !== 1 / 0 ? "space-between" : "flex-end",
1214
- alignItems: "center"
1215
- })
1216
- ), Ge = ct(), Je = P(() => !!Ge.decorativeContent), ue = P(() => o.disabled || Je.value), Ee = P(() => o.loading), _e = P(() => o.hasContent !== void 0 ? o.hasContent : !!a.value), Qe = P(() => ({
1217
- "is-disabled": ue.value,
1218
- "is-loading": Ee.value,
1219
- "has-error": !!oe.value,
1220
- "is-auto-switching": g.value
1221
- })), Ye = P(() => ({
1222
- width: mt(o.suggestionPopupWidth),
1156
+ M,
1157
+ W,
1158
+ ye,
1159
+ w,
1160
+ ce
1161
+ ), Te = (o) => {
1162
+ g("focus", o), y.value && !w.value && (T.value = !0);
1163
+ }, Re = (o) => {
1164
+ g("blur", o), ee();
1165
+ }, Ke = B(() => W.value === "multiple" ? "textarea" : "text"), Ae = dt(), Oe = B(() => !!Ae.decorativeContent), e = B(() => u.disabled || Oe.value), t = B(() => u.loading), n = B(() => ({
1166
+ "is-disabled": e.value,
1167
+ "is-loading": t.value,
1168
+ "is-auto-switching": G.value
1169
+ })), i = B(() => ({
1170
+ width: St(u.suggestionPopupWidth),
1223
1171
  maxWidth: "100%"
1224
1172
  // 确保不超出父容器宽度
1225
- })), oe = O(""), et = (d) => {
1226
- oe.value = d, setTimeout(() => oe.value = "", 5e3);
1227
- }, tt = () => {
1228
- b.value = !1, setTimeout(() => {
1229
- b.value = !1, K();
1230
- }, 50);
1173
+ })), r = () => {
1174
+ K.value = !1;
1231
1175
  };
1232
- return te(a, () => {
1233
- W(M), a.value === "" && o.mode === "single" && (s.value = "single");
1234
- }), te(
1235
- () => p.value,
1236
- (d) => {
1237
- d && (s.value = "multiple");
1176
+ ne(y, () => {
1177
+ te(xe), y.value === "" && u.mode === "single" && (W.value = "single"), z();
1178
+ }), ne(
1179
+ () => w.value,
1180
+ (o) => {
1181
+ o && (W.value = "multiple");
1238
1182
  }
1239
- ), y({
1240
- focus: j,
1241
- blur: () => {
1242
- if (u.value)
1243
- u.value.blur();
1244
- else {
1245
- const d = document.querySelector(".tiny-input__inner");
1246
- d == null || d.blur();
1247
- }
1248
- },
1249
- clear: q,
1250
- submit: he,
1251
- startSpeech: Se,
1252
- stopSpeech: we,
1253
- activateTemplateFirstField: Ce,
1254
- setTemplate: Ke
1255
- }), (d, k) => (D(), A("div", {
1183
+ );
1184
+ const p = () => {
1185
+ f.value && f.value.activateFirstField();
1186
+ }, { accept: _ = "*", multiple: E = !0, reset: j = !0 } = ((L = u.buttonGroup) == null ? void 0 : L.file) || {}, { open: R, files: $ } = ht({ accept: _, multiple: E, reset: j });
1187
+ return ne($, (o) => {
1188
+ o && o.length > 0 && g("files-selected", Array.from(o));
1189
+ }), c({
1190
+ focus: Z,
1191
+ blur: ke,
1192
+ clear: ge,
1193
+ submit: pe,
1194
+ startSpeech: de,
1195
+ stopSpeech: Ie,
1196
+ activateTemplateFirstField: p
1197
+ }), (o, m) => (b(), I("div", {
1256
1198
  ref_key: "senderRef",
1257
- ref: i,
1258
- class: ae(["tiny-sender", [Qe.value, `theme-${d.theme}`, `mode-${s.value}`]]),
1259
- "data-theme": d.theme
1199
+ ref: l,
1200
+ class: oe(["tiny-sender", [n.value, `theme-${o.theme}`, `mode-${W.value}`]]),
1201
+ "data-theme": o.theme
1260
1202
  }, [
1261
- U("div", Vt, [
1262
- U("div", {
1203
+ q("div", zt, [
1204
+ q("div", {
1263
1205
  class: "tiny-sender__input-wrapper",
1264
1206
  ref_key: "inputWrapperRef",
1265
- ref: c
1207
+ ref: x
1266
1208
  }, [
1267
- G(ve, { name: "tiny-sender-slide-down" }, {
1268
- default: Y(() => [
1269
- d.$slots.header ? (D(), A("div", Bt, [
1270
- se(d.$slots, "header")
1271
- ])) : H("", !0)
1209
+ Q(Ve, { name: "tiny-sender-slide-down" }, {
1210
+ default: he(() => [
1211
+ o.$slots.header ? (b(), I("div", Gt, [
1212
+ ie(o.$slots, "header", {}, void 0, !0)
1213
+ ])) : N("", !0)
1272
1214
  ]),
1273
1215
  _: 3
1274
1216
  }),
1275
- U("div", {
1276
- class: ae(["tiny-sender__input-row", { "has-prefix": d.$slots.prefix, "has-header": d.$slots.header }])
1217
+ q("div", {
1218
+ class: oe(["tiny-sender__input-row", { "has-prefix": o.$slots.prefix, "has-header": o.$slots.header }])
1277
1219
  }, [
1278
- d.$slots.prefix ? (D(), A("div", Wt, [
1279
- se(d.$slots, "prefix")
1280
- ])) : H("", !0),
1281
- U("div", $t, [
1282
- d.$slots.decorativeContent ? (D(), A("div", Pt, [
1283
- se(d.$slots, "decorativeContent")
1284
- ])) : H("", !0),
1285
- p.value ? (D(), Q(At, {
1220
+ o.$slots.prefix ? (b(), I("div", jt, [
1221
+ ie(o.$slots, "prefix", {}, void 0, !0)
1222
+ ])) : N("", !0),
1223
+ q("div", Jt, [
1224
+ o.$slots.decorativeContent ? (b(), I("div", Xt, [
1225
+ ie(o.$slots, "decorativeContent", {}, void 0, !0)
1226
+ ])) : N("", !0),
1227
+ w.value ? (b(), Y(Ft, {
1286
1228
  key: 1,
1287
1229
  ref_key: "templateEditorRef",
1288
- ref: r,
1289
- value: E(a),
1290
- "onUpdate:value": k[0] || (k[0] = (F) => Le(a) ? a.value = F : null),
1291
- onInput: He,
1292
- onEmptyContent: B
1293
- }, null, 8, ["value"])) : (D(), A("div", Ht, [
1294
- G(E(ft), {
1230
+ ref: f,
1231
+ "model-value": u.templateData,
1232
+ "onUpdate:modelValue": Le,
1233
+ onSubmit: C(pe)
1234
+ }, null, 8, ["model-value", "onSubmit"])) : (b(), I("div", Zt, [
1235
+ Q(C(pt), {
1295
1236
  ref_key: "inputRef",
1296
- ref: u,
1297
- autosize: d.autoSize,
1298
- type: Ue.value,
1299
- readonly: Ee.value,
1237
+ ref: S,
1238
+ autosize: o.autoSize,
1239
+ type: Ke.value,
1300
1240
  resize: "none",
1301
- modelValue: E(a),
1302
- "onUpdate:modelValue": k[1] || (k[1] = (F) => Le(a) ? a.value = F : null),
1303
- disabled: ue.value,
1304
- placeholder: d.placeholder,
1305
- autofocus: d.autofocus,
1306
- onKeydown: E(qe),
1307
- onCompositionstart: k[2] || (k[2] = (F) => b.value = !0),
1308
- onCompositionend: tt,
1309
- onFocus: ze,
1310
- onBlur: je
1311
- }, null, 8, ["autosize", "type", "readonly", "modelValue", "disabled", "placeholder", "autofocus", "onKeydown"]),
1312
- E(v) && !E(b) ? (D(), A("div", Kt, [
1313
- U("span", Xt, le(E(a)), 1),
1314
- Oe(le(E(v)) + " ", 1),
1315
- E(R) ? (D(), A("div", qt, "TAB")) : H("", !0)
1316
- ])) : H("", !0)
1241
+ modelValue: C(y),
1242
+ "onUpdate:modelValue": m[0] || (m[0] = (D) => ft(y) ? y.value = D : null),
1243
+ disabled: e.value,
1244
+ placeholder: o.placeholder,
1245
+ autofocus: o.autofocus,
1246
+ onKeydown: C(fe),
1247
+ onCompositionstart: m[1] || (m[1] = (D) => K.value = !0),
1248
+ onCompositionend: r,
1249
+ onFocus: Te,
1250
+ onBlur: Re
1251
+ }, null, 8, ["autosize", "type", "modelValue", "disabled", "placeholder", "autofocus", "onKeydown"]),
1252
+ C(P) && !C(K) ? (b(), I("div", Qt, [
1253
+ q("span", Yt, ue(C(y)), 1),
1254
+ Ge(ue(C(P)) + " ", 1),
1255
+ C(O) ? (b(), I("div", en, "TAB")) : N("", !0)
1256
+ ])) : N("", !0)
1317
1257
  ]))
1318
1258
  ]),
1319
- s.value === "single" ? (D(), A("div", zt, [
1320
- U("div", {
1259
+ W.value === "single" ? (b(), I("div", tn, [
1260
+ q("div", {
1321
1261
  class: "tiny-sender__buttons-container",
1322
1262
  ref_key: "buttonsContainerRef",
1323
- ref: f
1263
+ ref: h
1324
1264
  }, [
1325
- se(d.$slots, "actions"),
1326
- G(We, {
1327
- "allow-speech": d.allowSpeech,
1328
- "allow-files": d.allowFiles,
1329
- loading: d.loading,
1330
- disabled: ue.value,
1331
- "show-clear": d.clearable,
1332
- "has-content": _e.value,
1333
- "speech-status": E(ie),
1334
- "submit-type": d.submitType,
1335
- "is-over-limit": re.value,
1336
- onClear: q,
1265
+ ie(o.$slots, "actions", {}, void 0, !0),
1266
+ Q(je, {
1267
+ "allow-speech": o.allowSpeech,
1268
+ "allow-files": o.allowFiles,
1269
+ loading: o.loading,
1270
+ disabled: e.value,
1271
+ "show-clear": o.clearable,
1272
+ "has-content": F.value,
1273
+ "speech-status": C(ae),
1274
+ "button-group": o.buttonGroup,
1275
+ "submit-type": o.submitType,
1276
+ "is-over-limit": be.value,
1277
+ "stop-text": o.stopText,
1278
+ onClear: ge,
1337
1279
  onToggleSpeech: me,
1338
- onSubmit: E(he),
1339
- onCancel: k[3] || (k[3] = (F) => d.$emit("cancel"))
1340
- }, null, 8, ["allow-speech", "allow-files", "loading", "disabled", "show-clear", "has-content", "speech-status", "submit-type", "is-over-limit", "onSubmit"])
1280
+ onSubmit: C(pe),
1281
+ onCancel: m[2] || (m[2] = (D) => o.$emit("cancel")),
1282
+ onTriggerSelect: C(R)
1283
+ }, null, 8, ["allow-speech", "allow-files", "loading", "disabled", "show-clear", "has-content", "speech-status", "button-group", "submit-type", "is-over-limit", "stop-text", "onSubmit", "onTriggerSelect"])
1341
1284
  ], 512)
1342
- ])) : H("", !0)
1285
+ ])) : N("", !0)
1343
1286
  ], 2),
1344
- G(ve, { name: "tiny-sender-slide-up" }, {
1345
- default: Y(() => [
1346
- s.value === "multiple" ? (D(), A("div", {
1347
- key: 0,
1348
- style: Ie(Ze.value),
1349
- class: "tiny-sender__footer-slot tiny-sender__bottom-row"
1350
- }, [
1351
- U("div", jt, [
1352
- se(d.$slots, "footer-left")
1287
+ Q(Ve, { name: "tiny-sender-slide-up" }, {
1288
+ default: he(() => [
1289
+ W.value === "multiple" ? (b(), I("div", nn, [
1290
+ q("div", on, [
1291
+ ie(o.$slots, "footer-left", {}, void 0, !0)
1353
1292
  ]),
1354
- U("div", Ut, [
1355
- se(d.$slots, "footer-right"),
1356
- d.showWordLimit && d.maxLength !== 1 / 0 ? (D(), A("div", {
1293
+ q("div", sn, [
1294
+ ie(o.$slots, "footer-right", {}, void 0, !0),
1295
+ o.showWordLimit && o.maxLength !== 1 / 0 ? (b(), I("div", {
1357
1296
  key: 0,
1358
- class: ae(["tiny-sender__word-limit", { "is-over-limit": re.value }])
1297
+ class: oe(["tiny-sender__word-limit", { "is-over-limit": be.value }])
1359
1298
  }, [
1360
- U("span", Zt, le(E(a).length), 1),
1361
- Oe("/" + le(d.maxLength), 1)
1362
- ], 2)) : H("", !0),
1363
- s.value === "multiple" ? (D(), A("div", Gt, [
1364
- U("div", Jt, [
1365
- G(We, {
1366
- "allow-speech": d.allowSpeech,
1367
- "allow-files": d.allowFiles,
1368
- loading: d.loading,
1369
- disabled: ue.value,
1370
- "show-clear": d.clearable,
1371
- "has-content": _e.value,
1372
- "speech-status": E(ie),
1373
- "submit-type": d.submitType,
1374
- "is-over-limit": re.value,
1375
- onClear: q,
1299
+ q("span", an, ue(C(y).length), 1),
1300
+ Ge("/" + ue(o.maxLength), 1)
1301
+ ], 2)) : N("", !0),
1302
+ W.value === "multiple" ? (b(), I("div", ln, [
1303
+ q("div", rn, [
1304
+ Q(je, {
1305
+ "allow-speech": o.allowSpeech,
1306
+ "allow-files": o.allowFiles,
1307
+ loading: o.loading,
1308
+ disabled: e.value,
1309
+ "show-clear": o.clearable,
1310
+ "has-content": F.value,
1311
+ "speech-status": C(ae),
1312
+ "button-group": o.buttonGroup,
1313
+ "submit-type": o.submitType,
1314
+ "is-over-limit": be.value,
1315
+ "stop-text": o.stopText,
1316
+ onClear: ge,
1376
1317
  onToggleSpeech: me,
1377
- onSubmit: E(he),
1378
- onCancel: k[4] || (k[4] = (F) => d.$emit("cancel"))
1379
- }, null, 8, ["allow-speech", "allow-files", "loading", "disabled", "show-clear", "has-content", "speech-status", "submit-type", "is-over-limit", "onSubmit"])
1318
+ onSubmit: C(pe),
1319
+ onCancel: m[3] || (m[3] = (D) => o.$emit("cancel")),
1320
+ onTriggerSelect: C(R)
1321
+ }, null, 8, ["allow-speech", "allow-files", "loading", "disabled", "show-clear", "has-content", "speech-status", "button-group", "submit-type", "is-over-limit", "stop-text", "onSubmit", "onTriggerSelect"])
1380
1322
  ])
1381
- ])) : H("", !0)
1323
+ ])) : N("", !0)
1382
1324
  ])
1383
- ], 4)) : d.$slots.footer ? (D(), A("div", Qt, [
1384
- se(d.$slots, "footer")
1385
- ])) : H("", !0)
1325
+ ])) : o.$slots.footer ? (b(), I("div", un, [
1326
+ ie(o.$slots, "footer", {}, void 0, !0)
1327
+ ])) : N("", !0)
1386
1328
  ]),
1387
1329
  _: 3
1388
1330
  })
1389
1331
  ], 512)
1390
1332
  ]),
1391
- G(ve, { name: "tiny-sender-slide-up" }, {
1392
- default: Y(() => [
1393
- E(_) && E(m).length ? (D(), A("div", {
1394
- key: 0,
1395
- ref_key: "suggestionsListRef",
1396
- ref: w,
1397
- class: "tiny-sender__suggestions",
1398
- style: Ie(Ye.value)
1399
- }, [
1400
- (D(!0), A(Ae, null, Me(E(m), (F, ne) => (D(), A("div", {
1401
- key: ne,
1402
- class: ae(["suggestion-item", { highlighted: E(V)(ne) }]),
1403
- onMouseenter: (Z) => E(e)(ne),
1404
- onMouseleave: k[5] || (k[5] = //@ts-ignore
1405
- (...Z) => E(l) && E(l)(...Z)),
1406
- onMousedown: dt((Z) => E(C)(F), ["prevent"])
1407
- }, [
1408
- G(E(St), { class: "suggestion-item__icon" }),
1409
- U("span", en, [
1410
- (D(!0), A(Ae, null, Me(E(n)(F, E(a)), (Z, ge) => (D(), A("span", {
1411
- key: ge,
1412
- class: ae({ "suggestion-item__text--match": Z.isMatch, "suggestion-item__text--normal": !Z.isMatch })
1413
- }, le(Z.text), 3))), 128))
1414
- ])
1415
- ], 42, Yt))), 128))
1416
- ], 4)) : H("", !0)
1417
- ]),
1418
- _: 1
1419
- }),
1420
- oe.value ? (D(), A("div", tn, le(oe.value), 1)) : H("", !0)
1421
- ], 10, Mt));
1333
+ Q(Ut, {
1334
+ show: C(T),
1335
+ suggestions: o.suggestions,
1336
+ "popup-style": i.value,
1337
+ "active-keyboard-index": C(v),
1338
+ "active-mouse-index": C(d),
1339
+ "input-value": C(y),
1340
+ onSelect: C(U),
1341
+ onMouseEnter: C(X),
1342
+ onMouseLeave: C(le)
1343
+ }, null, 8, ["show", "suggestions", "popup-style", "active-keyboard-index", "active-mouse-index", "input-value", "onSelect", "onMouseEnter", "onMouseLeave"])
1344
+ ], 10, qt));
1422
1345
  }
1423
- });
1424
- pe.name = "TrSender";
1425
- const nn = function(t) {
1426
- t.component(pe.name, pe);
1346
+ }), Be = /* @__PURE__ */ Ce(cn, [["__scopeId", "data-v-ed19a136"]]);
1347
+ Be.name = "TrSender";
1348
+ const dn = function(a) {
1349
+ a.component(Be.name, Be);
1427
1350
  };
1428
- pe.install = nn;
1351
+ Be.install = dn;
1429
1352
  export {
1430
- pe as default
1353
+ Be as default
1431
1354
  };