@opentiny/tiny-robot 0.2.13 → 0.3.0-alpha.1

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