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