@opentiny/tiny-robot 0.3.0-alpha.0 → 0.3.0-alpha.10

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