@opentiny/tiny-robot 0.3.0-alpha.2 → 0.3.0-alpha.4

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