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

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