@opentiny/tiny-robot 0.3.0-alpha.15 → 0.3.0-alpha.16

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