@opentiny/tiny-robot 0.3.2 → 0.3.4-beta.1

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