@opentiny/tiny-robot 0.2.14 → 0.2.15

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