cosmic-ai-input 1.0.11 → 1.0.13

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.
package/dist/index.es.js CHANGED
@@ -1,586 +1,695 @@
1
- // Generated at: 2026-01-19T02:33:31.529Z
2
- import { jsx as f, jsxs as _ } from "react/jsx-runtime";
3
- import { forwardRef as j, useState as C, useRef as H, useEffect as P, useCallback as ve, useImperativeHandle as Ge } from "react";
4
- import Ce from "classnames";
5
- import { createPortal as Je } from "react-dom";
6
- const ke = j(
7
- ({ value: s, position: r, id: c, onChange: d }, k) => {
8
- const [x, w] = C(!0), D = H(null), A = H(null);
9
- P(() => {
10
- typeof k == "function" ? k(D.current) : k && (k.current = D.current);
1
+ // Generated at: 2026-03-10T07:58:48.343Z
2
+ import { jsx as u, jsxs as Y } from "react/jsx-runtime";
3
+ import { forwardRef as j, useState as L, useRef as F, useEffect as M, useCallback as Pe, useImperativeHandle as lt } from "react";
4
+ import Se from "classnames";
5
+ import { createPortal as ot } from "react-dom";
6
+ var h = /* @__PURE__ */ ((r) => (r.INPUT = "input", r.SELECT = "select", r.MULTIPLE_SELECT = "multiple-select", r.DATE_PICKER = "date-picker", r.LABEL = "label", r))(h || {});
7
+ const $e = j(
8
+ ({ value: r, position: s, id: o, onChange: f }, k) => {
9
+ const [w, g] = L(!0), $ = F(null), D = F(null);
10
+ M(() => {
11
+ typeof k == "function" ? k($.current) : k && (k.current = $.current);
11
12
  }, [k]);
12
- const m = (a) => {
13
- console.log("DatePicker handleChange", a);
14
- const g = a.target.value;
15
- d == null || d(g, "date-picker");
13
+ const T = (p) => {
14
+ const y = p.target.value;
15
+ f == null || f(y, h.DATE_PICKER);
16
16
  };
17
- P(() => {
18
- if (A.current)
17
+ M(() => {
18
+ if (D.current)
19
19
  try {
20
20
  setTimeout(() => {
21
- S();
21
+ N();
22
22
  }, 100);
23
- } catch (a) {
24
- console.log("无法自动打开日期选择器,浏览器安全策略限制", a);
23
+ } catch {
25
24
  }
26
25
  }, []);
27
- const S = () => {
28
- if (A.current)
26
+ const N = () => {
27
+ if (D.current)
29
28
  try {
30
- A.current.showPicker();
31
- } catch (a) {
32
- console.log("点击后无法打开日期选择器", a);
29
+ D.current.showPicker();
30
+ } catch {
33
31
  }
34
- }, h = (a) => {
35
- a.stopPropagation(), console.log("DatePicker handleClick", a);
32
+ }, A = (p) => {
33
+ p.stopPropagation();
36
34
  };
37
- return x ? /* @__PURE__ */ f(
35
+ return w ? /* @__PURE__ */ u(
38
36
  "div",
39
37
  {
40
- ref: D,
41
- id: c,
38
+ ref: $,
39
+ id: o,
42
40
  style: {
43
- top: (r == null ? void 0 : r.top) || 0,
44
- left: (r == null ? void 0 : r.left) || 0
41
+ top: (s == null ? void 0 : s.top) || 0,
42
+ left: (s == null ? void 0 : s.left) || 0
45
43
  },
46
44
  className: "cosmic-ai-input-datePicker",
47
45
  suppressHydrationWarning: !0,
48
- children: /* @__PURE__ */ f(
46
+ children: /* @__PURE__ */ u(
49
47
  "input",
50
48
  {
51
- ref: A,
49
+ ref: D,
52
50
  type: "date",
53
- value: s || "",
54
- onChange: m,
55
- onClick: h
51
+ value: r || "",
52
+ onChange: T,
53
+ onClick: A
56
54
  }
57
55
  )
58
56
  }
59
57
  ) : null;
60
58
  }
61
59
  );
62
- ke.displayName = "DatePicker";
63
- function te(s) {
64
- const r = s.textContent || "", c = s.nextSibling;
65
- r.length ? (c == null || c.setAttribute("style", "display: none"), s.style.padding = "2px 4px", s.style.borderTopLeftRadius = "2px", s.style.borderBottomLeftRadius = "2px", s.style.borderTopRightRadius = "2px", s.style.borderBottomRightRadius = "2px") : (c == null || c.setAttribute("style", "display: inline"), s.style.padding = "2px 0 2px 4px", s.style.borderTopLeftRadius = "2px", s.style.borderBottomLeftRadius = "2px", s.style.borderTopRightRadius = "0", s.style.borderBottomRightRadius = "0");
60
+ $e.displayName = "DatePicker";
61
+ function fe(r) {
62
+ const s = r.textContent || "", o = r.nextSibling;
63
+ s.length ? (o == null || o.setAttribute("style", "display: none"), r.style.padding = "2px 4px", r.style.borderTopLeftRadius = "2px", r.style.borderBottomLeftRadius = "2px", r.style.borderTopRightRadius = "2px", r.style.borderBottomRightRadius = "2px") : (o == null || o.setAttribute("style", "display: inline"), r.style.padding = "2px 0 2px 4px", r.style.borderTopLeftRadius = "2px", r.style.borderBottomLeftRadius = "2px", r.style.borderTopRightRadius = "0", r.style.borderBottomRightRadius = "0");
66
64
  }
67
- function M(s) {
68
- if (s && s.getAttribute("data-set-type") === "input") {
69
- const r = s.children[0];
70
- r.setAttribute("contenteditable", "true"), requestAnimationFrame(() => {
71
- r.focus();
65
+ function V(r) {
66
+ if (r && r.getAttribute("data-set-type") === "input") {
67
+ const s = r.children[0];
68
+ s.setAttribute("contenteditable", "true"), requestAnimationFrame(() => {
69
+ s.focus();
72
70
  });
73
71
  }
74
72
  }
75
- function me(s) {
76
- s && s.getAttribute("data-set-type") === "input" && s.children[0].setAttribute("contenteditable", "false");
73
+ function Ne(r) {
74
+ r && r.getAttribute("data-set-type") === "input" && r.children[0].setAttribute("contenteditable", "false");
77
75
  }
78
- function O(s) {
79
- return s && s.getAttribute("data-set-type") === "input";
76
+ function _(r) {
77
+ return r && (r != null && r.getAttribute) ? r.getAttribute("data-set-type") === "input" : !1;
80
78
  }
81
- const Re = j(({
82
- options: s,
83
- value: r,
84
- position: c,
85
- id: d,
79
+ const Be = j(({
80
+ options: r,
81
+ value: s,
82
+ position: o,
83
+ id: f,
86
84
  height: k = 37,
87
- onChange: x
88
- }, w) => {
89
- const [D, A] = C(r || ""), m = H(null);
90
- P(() => {
91
- typeof w == "function" ? w(m.current) : w && (w.current = m.current);
92
- }, [w]);
93
- const S = (a) => {
94
- const g = D.split(",").filter((N) => N) || [];
95
- let B = "";
96
- g.includes(a) ? B = g.filter((N) => N !== a).join(",") : (console.log("handleOptionClick", g), g.length ? B = `${g.join(",")},${a}` : B = a), A(B), x == null || x(B, "multiple-select");
97
- }, h = D.split(",") || [];
98
- return /* @__PURE__ */ f(
85
+ onChange: w
86
+ }, g) => {
87
+ const [$, D] = L(s || ""), T = F(null);
88
+ M(() => {
89
+ typeof g == "function" ? g(T.current) : g && (g.current = T.current);
90
+ }, [g]);
91
+ const N = (p) => {
92
+ const y = $.split(",").filter((E) => E) || [];
93
+ let b = "";
94
+ y.includes(p) ? b = y.filter((E) => E !== p).join(",") : y.length ? b = `${y.join(",")},${p}` : b = p, D(b), w == null || w(b, h.MULTIPLE_SELECT);
95
+ }, A = $.split(",") || [];
96
+ return /* @__PURE__ */ u(
99
97
  "div",
100
98
  {
101
- ref: m,
99
+ ref: T,
102
100
  className: "cosmic-ai-input-selectFloatElement",
103
- id: d,
101
+ id: f,
104
102
  style: {
105
103
  position: "absolute",
106
- top: (c == null ? void 0 : c.top) || 0,
107
- left: (c == null ? void 0 : c.left) || 0,
104
+ top: (o == null ? void 0 : o.top) || 0,
105
+ left: (o == null ? void 0 : o.left) || 0,
108
106
  zIndex: 5e3,
109
107
  maxHeight: `${k}px`
110
108
  },
111
- children: s.map((a, g) => /* @__PURE__ */ f(
109
+ children: r.map((p, y) => /* @__PURE__ */ u(
112
110
  "div",
113
111
  {
114
- className: `selectOption ${h.includes(a) ? "selected" : ""}`,
115
- onClick: () => S(a),
116
- children: a
112
+ className: `selectOption ${A.includes(p) ? "selected" : ""}`,
113
+ onClick: () => N(p),
114
+ children: p
117
115
  },
118
- g
116
+ y
119
117
  ))
120
118
  }
121
119
  );
122
120
  });
123
- Re.displayName = "MultipleSelect";
124
- const De = j(({
125
- options: s,
126
- value: r,
127
- position: c,
128
- id: d,
121
+ Be.displayName = "MultipleSelect";
122
+ const Me = j(({
123
+ options: r,
124
+ value: s,
125
+ position: o,
126
+ id: f,
129
127
  height: k = 120,
130
- onChange: x
131
- }, w) => {
132
- const [D, A] = C(r || ""), m = H(null);
133
- P(() => {
134
- typeof w == "function" ? w(m.current) : w && (w.current = m.current);
135
- }, [w]);
136
- const S = (h) => {
137
- A(h), x == null || x(h, "select");
128
+ onChange: w
129
+ }, g) => {
130
+ const [$, D] = L(s || ""), T = F(null);
131
+ M(() => {
132
+ typeof g == "function" ? g(T.current) : g && (g.current = T.current);
133
+ }, [g]);
134
+ const N = (A) => {
135
+ D(A), w == null || w(A, h.SELECT);
138
136
  };
139
- return /* @__PURE__ */ f(
137
+ return /* @__PURE__ */ u(
140
138
  "div",
141
139
  {
142
- ref: m,
140
+ ref: T,
143
141
  className: "cosmic-ai-input-selectFloatElement",
144
- id: d,
142
+ id: f,
145
143
  style: {
146
144
  position: "absolute",
147
- top: (c == null ? void 0 : c.top) || 0,
148
- left: (c == null ? void 0 : c.left) || 0,
145
+ top: (o == null ? void 0 : o.top) || 0,
146
+ left: (o == null ? void 0 : o.left) || 0,
149
147
  zIndex: 5e3,
150
148
  maxHeight: `${k}px`
151
149
  },
152
- children: s.length > 0 && s.map((h, a) => /* @__PURE__ */ f(
150
+ children: r.length > 0 && r.map((A, p) => /* @__PURE__ */ u(
153
151
  "div",
154
152
  {
155
- className: `selectOption ${D === h ? "selected" : ""}`,
156
- onClick: () => S(h),
157
- children: h
153
+ className: `selectOption ${$ === A ? "selected" : ""}`,
154
+ onClick: () => N(A),
155
+ children: A
158
156
  },
159
- a
157
+ p
160
158
  ))
161
159
  }
162
160
  );
163
161
  });
164
- De.displayName = "Select";
165
- function Ae(s) {
166
- const r = s instanceof Element ? s : document.getElementById(s);
167
- return r && r.children[0].textContent || "";
162
+ Me.displayName = "Select";
163
+ function De(r) {
164
+ const s = r instanceof Element ? r : document.getElementById(r);
165
+ return s && s.children[0].textContent || "";
168
166
  }
169
- function Qe(s, r) {
170
- const c = s instanceof Element ? s : document.getElementById(s);
171
- c && (c.children[0].textContent = r);
167
+ function st(r, s) {
168
+ const o = r instanceof Element ? r : document.getElementById(r);
169
+ o && (o.children[0].textContent = s);
172
170
  }
173
- function z(s) {
174
- const r = document.createRange(), c = window.getSelection();
175
- if (!c) {
176
- console.error("无法获取selection对象");
177
- return;
178
- }
179
- if (!s || !(s instanceof Node)) {
180
- console.error("element 不是有效的 DOM 节点");
181
- return;
182
- }
183
- r.selectNodeContents(s), r.collapse(!0), c.removeAllRanges(), c.addRange(r);
171
+ function ee(r) {
172
+ const s = document.createRange(), o = window.getSelection();
173
+ o && (!r || !(r instanceof Node) || (s.selectNodeContents(r), s.collapse(!0), o.removeAllRanges(), o.addRange(s)));
184
174
  }
185
- function F(s) {
186
- const r = document.createRange(), c = window.getSelection();
187
- if (!c) {
188
- console.error("无法获取selection对象");
189
- return;
190
- }
191
- if (!s || !(s instanceof Node)) {
192
- console.error("element 不是有效的 DOM 节点");
193
- return;
194
- }
195
- r.selectNodeContents(s), r.collapse(!1), c.removeAllRanges(), c.addRange(r);
175
+ function q(r) {
176
+ const s = document.createRange(), o = window.getSelection();
177
+ o && (!r || !(r instanceof Node) || (s.selectNodeContents(r), s.collapse(!1), o.removeAllRanges(), o.addRange(s)));
196
178
  }
197
- function ne(s) {
198
- const r = window.getSelection();
199
- if (!r || r.rangeCount === 0)
179
+ function pe(r) {
180
+ const s = window.getSelection();
181
+ if (!s || s.rangeCount === 0)
200
182
  return 0;
201
- if (!s || !(s instanceof Node)) {
202
- console.error("element 不是有效的 DOM 节点");
183
+ if (!r || !(r instanceof Node))
203
184
  return;
204
- }
205
- const c = r.getRangeAt(0), d = c.cloneRange();
206
- return d.selectNodeContents(s), d.setEnd(c.startContainer, c.startOffset), d.toString().length;
185
+ const o = s.getRangeAt(0), f = o.cloneRange();
186
+ return f.selectNodeContents(r), f.setEnd(o.startContainer, o.startOffset), f.toString().length;
207
187
  }
208
- function Ye() {
209
- const s = window.getSelection();
210
- if (!s || s.rangeCount === 0)
188
+ function ct() {
189
+ const r = window.getSelection();
190
+ if (!r || r.rangeCount === 0)
211
191
  return null;
212
- const c = s.getRangeAt(0).startContainer;
213
- return c.nodeType === Node.TEXT_NODE ? c.parentElement : c.nodeType === Node.ELEMENT_NODE ? c : null;
192
+ const o = r.getRangeAt(0).startContainer;
193
+ return o.nodeType === Node.TEXT_NODE ? o.parentElement : o.nodeType === Node.ELEMENT_NODE ? o : null;
214
194
  }
215
- function Ze() {
216
- const s = window.getSelection();
217
- if (!s || s.rangeCount === 0) return null;
218
- const r = s.getRangeAt(0), c = r.startContainer, d = r.startOffset;
219
- return c.nodeType === Node.TEXT_NODE ? d > 0 ? c : c.previousSibling : c.nodeType === Node.ELEMENT_NODE ? d > 0 ? c.childNodes[d - 1] : c.previousSibling : null;
195
+ function at() {
196
+ const r = window.getSelection();
197
+ return !r || r.rangeCount === 0 ? null : r.getRangeAt(0).getBoundingClientRect();
220
198
  }
221
- function Ie() {
222
- const s = window.getSelection();
223
- if (!s || s.rangeCount === 0) return null;
224
- const r = s.getRangeAt(0), c = r.startContainer, d = r.startOffset;
225
- return c.nodeType === Node.TEXT_NODE ? d < c.length ? c : c.nextSibling : c.nodeType === Node.ELEMENT_NODE ? d < c.childNodes.length ? c.childNodes[d] : c.nextSibling : null;
199
+ function dt() {
200
+ return new Promise((r) => {
201
+ requestAnimationFrame(() => {
202
+ r(at());
203
+ });
204
+ });
205
+ }
206
+ function ut() {
207
+ const r = window.getSelection();
208
+ if (!r || r.rangeCount === 0) return null;
209
+ const s = r.getRangeAt(0), o = s.startContainer, f = s.startOffset;
210
+ return o.nodeType === Node.TEXT_NODE ? f > 0 ? o : o.previousSibling : o.nodeType === Node.ELEMENT_NODE ? f > 0 ? o.childNodes[f - 1] : o.previousSibling : null;
211
+ }
212
+ function ft() {
213
+ const r = window.getSelection();
214
+ if (!r || r.rangeCount === 0) return null;
215
+ const s = r.getRangeAt(0), o = s.startContainer, f = s.startOffset;
216
+ return o.nodeType === Node.TEXT_NODE ? f < o.length ? o : o.nextSibling : o.nodeType === Node.ELEMENT_NODE ? f < o.childNodes.length ? o.childNodes[f] : o.nextSibling : null;
217
+ }
218
+ function pt(r) {
219
+ return r && !r.getAttribute("data-set-type");
226
220
  }
227
- function et(s) {
228
- return s && !s.getAttribute("data-set-type");
221
+ function ke() {
222
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
229
223
  }
230
- const tt = j((s, r) => {
224
+ const He = j(({
225
+ options: r,
226
+ value: s,
227
+ position: o,
228
+ id: f,
229
+ height: k = 120,
230
+ onChange: w
231
+ }, g) => {
232
+ const [$, D] = L(s || ""), [T, N] = L(0), A = F(null), p = F(T), y = Pe((b) => {
233
+ D(b), w == null || w(b, h.LABEL);
234
+ }, [w]);
235
+ return M(() => {
236
+ typeof g == "function" ? g(A.current) : g && (g.current = A.current);
237
+ }, [g]), M(() => {
238
+ p.current = T;
239
+ }, [T]), M(() => {
240
+ N(0);
241
+ }, [r]), M(() => {
242
+ const b = (E) => {
243
+ r.length !== 0 && (E.key === "ArrowDown" ? (E.preventDefault(), N((x) => x < r.length - 1 ? x + 1 : x)) : E.key === "ArrowUp" ? (E.preventDefault(), N((x) => x > 0 ? x - 1 : x)) : E.key === "Enter" && (E.preventDefault(), setTimeout(() => {
244
+ const x = p.current;
245
+ x >= 0 && r[x] && y(r[x]);
246
+ }, 0)));
247
+ };
248
+ return document.addEventListener("keydown", b), () => {
249
+ document.removeEventListener("keydown", b);
250
+ };
251
+ }, [r, y]), /* @__PURE__ */ u(
252
+ "div",
253
+ {
254
+ ref: A,
255
+ className: "cosmic-ai-input-selectFloatElement",
256
+ id: f,
257
+ style: {
258
+ position: "absolute",
259
+ top: (o == null ? void 0 : o.top) || 0,
260
+ left: (o == null ? void 0 : o.left) || 0,
261
+ zIndex: 5e3,
262
+ maxHeight: `${k}px`
263
+ },
264
+ children: r.length > 0 && r.map((b, E) => /* @__PURE__ */ u(
265
+ "div",
266
+ {
267
+ className: `selectOption ${$ === b ? "selected" : ""} ${T === E ? "highlighted" : ""}`,
268
+ onClick: () => y(b),
269
+ onMouseEnter: () => N(E),
270
+ children: b
271
+ },
272
+ E
273
+ ))
274
+ }
275
+ );
276
+ });
277
+ He.displayName = "Mention";
278
+ const ht = j((r, s) => {
231
279
  const {
232
- value: c = "",
233
- varList: d,
280
+ value: o = "",
281
+ varList: f,
234
282
  placeholder: k = "",
235
- maxLength: x,
236
- defaultRows: w = 3,
237
- disabled: D = !1,
238
- defaultFocus: A = !1,
239
- onFocus: m,
240
- onBlur: S,
241
- onChange: h,
242
- onClick: a,
243
- onSend: g,
244
- onParse: B,
245
- onKeyDown: N,
246
- onKeyUp: V,
247
- onMaxLengthExceeded: U
248
- } = s, [nt, ot] = C(c || ""), [X, v] = C(""), [lt, oe] = C(""), [G, q] = C(!1), [J, Q] = C({ top: 0, left: 0 }), [le, ce] = C([]), [Y, se] = C(""), [L, re] = C(null), [ie, ae] = C(120), [de, ue] = C(A), Ne = 240, Te = 240, pe = 240, fe = 276, y = H(null), E = H(null), T = H(null), K = () => {
249
- var o, n;
250
- let e = ((n = (o = y.current) == null ? void 0 : o.innerText) == null ? void 0 : n.replace(/\u200B/g, "")) || "";
251
- return e === `
252
- ` && (e = ""), e;
253
- }, he = () => {
254
- var o;
255
- let e = ((o = y.current) == null ? void 0 : o.innerHTML) || "";
256
- return e === "<br>" && (e = ""), e;
257
- }, Se = (e) => {
258
- const o = [];
259
- let n = 0;
283
+ maxLength: w,
284
+ defaultRows: g = 3,
285
+ disabled: $ = !1,
286
+ defaultFocus: D = !1,
287
+ textIndex: T = 0,
288
+ mentions: N = [],
289
+ onFocus: A,
290
+ onBlur: p,
291
+ onChange: y,
292
+ onClick: b,
293
+ onSend: E,
294
+ onKeyDown: x,
295
+ onKeyUp: K,
296
+ onMaxLengthExceeded: te
297
+ } = r, [gt, Et] = L(o || ""), [ne, ie] = L(""), [yt, he] = L(""), [U, O] = L(!1), [X, W] = L({ top: 0, left: 0 }), [re, le] = L([]), [G, ge] = L(""), [C, oe] = L(null), [se, J] = L(120), [Ee, ye] = L(D), be = 240, Ce = 240, we = 240, Ae = 276, m = F(null), R = F(null), B = F(null), ce = F(!1), v = () => {
298
+ var i, e;
299
+ let n = ((e = (i = m.current) == null ? void 0 : i.innerText) == null ? void 0 : e.replace(/\u200B/g, "")) || "";
300
+ return n === `
301
+ ` && (n = ""), n;
302
+ }, xe = () => {
303
+ var i;
304
+ let n = ((i = m.current) == null ? void 0 : i.innerHTML) || "";
305
+ return n === "<br>" && (n = ""), n;
306
+ }, Fe = (n) => {
307
+ const i = [];
308
+ let e = 0;
260
309
  const l = /\[([^\]]+)\]/g;
261
- let i;
262
- const u = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
263
- let p = 0;
264
- if (e === "" || !e || e === `
310
+ let c;
311
+ const a = ke();
312
+ let d = 0;
313
+ if (n === "" || !n || n === `
265
314
  `)
266
315
  return [
267
316
  {
268
317
  type: "text",
269
318
  content: "​",
270
- id: `text-${p++}-${u}`
319
+ id: `text-${d++}-${a}`
271
320
  }
272
321
  ];
273
- const $ = new Set((d || []).map((b) => b.name));
274
- for (; (i = l.exec(e)) !== null; ) {
275
- if (i.index > n) {
276
- const R = e.substring(n, i.index).split(`
322
+ const P = new Set((f || []).map((S) => S.name));
323
+ for (; (c = l.exec(n)) !== null; ) {
324
+ if (c.index > e) {
325
+ const H = n.substring(e, c.index).split(`
277
326
  `);
278
- R.forEach((W, Xe) => {
279
- W && o.push({
327
+ H.forEach((I, rt) => {
328
+ I && i.push({
280
329
  type: "text",
281
- content: W,
282
- id: `text-${p++}-${u}`
283
- }), Xe < R.length - 1 && o.push({
330
+ content: I,
331
+ id: `text-${d++}-${a}`
332
+ }), rt < H.length - 1 && i.push({
284
333
  type: "newline",
285
- id: `newline-${p++}-${u}`
334
+ id: `newline-${d++}-${a}`
286
335
  });
287
336
  });
288
337
  }
289
- const b = i[1];
290
- if ($.has(b)) {
291
- const t = d.find((R) => R.name === b);
292
- (t == null ? void 0 : t.type) === "input" ? o.push({
338
+ const S = c[1];
339
+ if (P.has(S)) {
340
+ const t = f.find((H) => H.name === S);
341
+ (t == null ? void 0 : t.type) === "input" ? i.push({
293
342
  type: "input",
294
343
  name: t == null ? void 0 : t.name,
295
344
  content: (t == null ? void 0 : t.content) || "",
296
- placeholder: (t == null ? void 0 : t.placeholder) || b,
297
- id: `input-${p++}-${u}`
298
- }) : (t == null ? void 0 : t.type) === "select" ? o.push({
345
+ placeholder: (t == null ? void 0 : t.placeholder) || S,
346
+ id: `input-${d++}-${a}`
347
+ }) : (t == null ? void 0 : t.type) === "label" ? i.push({
348
+ type: "label",
349
+ name: t == null ? void 0 : t.name,
350
+ content: (t == null ? void 0 : t.content) || "",
351
+ id: `label-${d++}-${a}`
352
+ }) : (t == null ? void 0 : t.type) === "select" ? i.push({
299
353
  type: "select",
300
354
  name: t == null ? void 0 : t.name,
301
355
  content: (t == null ? void 0 : t.content) || "",
302
- placeholder: (t == null ? void 0 : t.placeholder) || b,
356
+ placeholder: (t == null ? void 0 : t.placeholder) || S,
303
357
  options: (t == null ? void 0 : t.options) || [],
304
- id: `select-${p++}-${u}`
305
- }) : (t == null ? void 0 : t.type) === "multiple-select" ? o.push({
358
+ id: `select-${d++}-${a}`
359
+ }) : (t == null ? void 0 : t.type) === "multiple-select" ? i.push({
306
360
  type: "multiple-select",
307
361
  name: t == null ? void 0 : t.name,
308
362
  content: (t == null ? void 0 : t.content) || "",
309
- placeholder: (t == null ? void 0 : t.placeholder) || b,
363
+ placeholder: (t == null ? void 0 : t.placeholder) || S,
310
364
  options: (t == null ? void 0 : t.options) || [],
311
- id: `multiple-select-${p++}-${u}`
312
- }) : (t == null ? void 0 : t.type) === "date-picker" && o.push({
365
+ id: `multiple-select-${d++}-${a}`
366
+ }) : (t == null ? void 0 : t.type) === "date-picker" && i.push({
313
367
  type: "date-picker",
314
368
  name: t == null ? void 0 : t.name,
315
369
  content: (t == null ? void 0 : t.content) || "",
316
- placeholder: (t == null ? void 0 : t.placeholder) || b,
317
- id: `date-picker-${p++}-${u}`
370
+ placeholder: (t == null ? void 0 : t.placeholder) || S,
371
+ id: `date-picker-${d++}-${a}`
318
372
  });
319
373
  } else
320
- o.push({
374
+ i.push({
321
375
  type: "text",
322
- content: `[${b}]`,
323
- id: `text-${p++}-${u}`
376
+ content: `[${S}]`,
377
+ id: `text-${d++}-${a}`
324
378
  });
325
- n = l.lastIndex;
379
+ e = l.lastIndex;
326
380
  }
327
- if (n < e.length) {
328
- const t = e.substring(n).split(`
381
+ if (e < n.length) {
382
+ const t = n.substring(e).split(`
329
383
  `);
330
- t.forEach((R, W) => {
331
- R && o.push({
384
+ t.forEach((H, I) => {
385
+ H && i.push({
332
386
  type: "text",
333
- content: R,
334
- id: `text-${p++}`
335
- }), W < t.length - 1 && o.push({
387
+ content: H,
388
+ id: `text-${d++}`
389
+ }), I < t.length - 1 && i.push({
336
390
  type: "newline",
337
- id: `newline-${p++}`
391
+ id: `newline-${d++}`
338
392
  });
339
393
  });
340
394
  }
341
- return o;
342
- }, Z = () => {
343
- var e;
344
- (e = y.current) == null || e.setAttribute("contenteditable", "true"), E.current && (O(E.current) && E.current.children[0].setAttribute(
395
+ return i;
396
+ }, ae = () => {
397
+ var n;
398
+ (n = m.current) == null || n.setAttribute("contenteditable", "true"), R.current && (_(R.current) && R.current.children[0].setAttribute(
345
399
  "contenteditable",
346
400
  "false"
347
- ), E.current = null), F(y.current);
348
- }, Le = (e) => {
349
- console.log("handleEditorClick", e), a == null || a(e);
350
- }, $e = (e) => {
351
- console.log("handleEditorMouseDown", e), Z();
352
- }, ge = (e) => {
353
- console.log("handleEditorInput", e), v(K()), oe(he()), h == null || h(K());
354
- }, Me = (e) => {
355
- var o, n;
356
- if (e.code === "Enter" && !e.shiftKey) {
357
- e.preventDefault();
358
- const l = K();
359
- if (console.log(
360
- "onSend",
361
- l,
362
- "maxLength:",
363
- x,
364
- "length:",
365
- l.length
366
- ), l.length === 0 || (console.log(
367
- "containerRef.current?.innerHTML",
368
- (o = y.current) == null ? void 0 : o.innerHTML
369
- ), (n = y.current) != null && n.innerHTML.match(
401
+ ), R.current = null), q(m.current);
402
+ }, Oe = (n) => {
403
+ b == null || b(n);
404
+ }, Ve = (n) => {
405
+ ae();
406
+ }, z = (n) => {
407
+ ie(v()), he(xe()), y == null || y(v()), et(n);
408
+ }, qe = (n) => {
409
+ var i;
410
+ if (!ce.current && n.code === "Enter" && !n.shiftKey) {
411
+ n.preventDefault();
412
+ const e = v();
413
+ if (e.length === 0 || (i = m.current) != null && i.innerHTML.match(
370
414
  /^<span>[\s\u200B]*(<br\s*\/?>[\s\u200B]*)+<\/span>$/
371
- )))
415
+ ))
372
416
  return;
373
- x ? l.length <= x ? g == null || g(l) : (console.log("maxLength exceeded", l, x), U == null || U(l, x)) : g == null || g(l);
417
+ w ? e.length <= w ? E == null || E(e) : te == null || te(e, w) : E == null || E(e);
374
418
  }
375
- }, Fe = (e) => {
376
- var n;
377
- console.log("handleEditorKeyDown", e), N == null || N(e);
378
- const o = Ye();
379
- if (o && et(o)) {
380
- if (e.code === "ArrowLeft") {
381
- const l = o == null ? void 0 : o.previousElementSibling, i = ne(o);
382
- l && i === 0 && O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
383
- F(l.children[0]);
419
+ }, _e = (n) => {
420
+ var e;
421
+ if (U && (C == null ? void 0 : C.type) === h.LABEL && (n.code === "ArrowUp" || n.code === "ArrowDown" || n.code === "Enter")) {
422
+ n.preventDefault();
423
+ return;
424
+ }
425
+ O(!1), x == null || x(n);
426
+ const i = ct();
427
+ if (i && pt(i)) {
428
+ if (n.code === "ArrowLeft") {
429
+ const l = i == null ? void 0 : i.previousElementSibling, c = pe(i);
430
+ l && c === 0 && _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
431
+ q(l.children[0]);
384
432
  }));
385
433
  }
386
- if (e.code === "ArrowRight") {
387
- const l = o == null ? void 0 : o.nextElementSibling, i = ne(o);
388
- l && i === ((n = o.textContent) == null ? void 0 : n.length) && O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
389
- z(l.children[0]);
434
+ if (n.code === "ArrowRight") {
435
+ const l = i == null ? void 0 : i.nextElementSibling, c = pe(i);
436
+ l && c === ((e = i.textContent) == null ? void 0 : e.length) && _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
437
+ ee(l.children[0]);
390
438
  }));
391
439
  }
392
- e.code === "Backspace" && (o.innerHTML === "​" && e.preventDefault(), o.innerHTML === "<br>" && (e.preventDefault(), o.innerHTML = "​"));
440
+ n.code === "Backspace" && (i.innerHTML === "​" && n.preventDefault(), i.innerHTML === "<br>" && (n.preventDefault(), i.innerHTML = "​"));
393
441
  }
394
- if (o && o.getAttribute("data-set-type") === "container") {
395
- if (e.code === "ArrowLeft") {
396
- const l = Ze();
397
- O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
398
- F(l.children[0]);
442
+ if (i && i.getAttribute("data-set-type") === "container") {
443
+ if (n.code === "ArrowLeft") {
444
+ const l = ut();
445
+ _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
446
+ q(l.children[0]);
399
447
  }));
400
448
  }
401
- if (e.code === "ArrowRight") {
402
- const l = Ie();
403
- O(l) && l.children[0] && (E.current = l, M(l), requestAnimationFrame(() => {
404
- z(l.children[0]);
449
+ if (n.code === "ArrowRight") {
450
+ const l = ft();
451
+ _(l) && l.children[0] && (R.current = l, V(l), requestAnimationFrame(() => {
452
+ ee(l.children[0]);
405
453
  }));
406
454
  }
407
455
  }
408
- Me(e);
409
- }, Pe = (e) => {
410
- console.log("handleEditorKeyUp", e), V == null || V(e);
411
- }, Oe = (e) => {
412
- e.preventDefault();
413
- const n = window.getSelection().toString();
414
- if (!n) return;
415
- const l = n, i = n;
416
- e.clipboardData.setData("text/plain", l), e.clipboardData.setData("text/html", i);
417
- }, He = (e) => {
418
- m == null || m(e);
419
- }, Be = (e, o) => {
420
- o.stopPropagation(), console.log("handleInputClick", e);
421
- }, Ve = (e, o) => {
456
+ qe(n);
457
+ }, Ke = (n) => {
458
+ if (U && (C == null ? void 0 : C.type) === h.LABEL && (n.code === "ArrowUp" || n.code === "ArrowDown" || n.code === "Enter")) {
459
+ n.preventDefault();
460
+ return;
461
+ }
462
+ K == null || K(n);
463
+ }, ve = (n) => {
464
+ n.preventDefault();
465
+ const e = window.getSelection().toString();
466
+ if (!e) return;
467
+ const l = e, c = e;
468
+ n.clipboardData.setData("text/plain", l), n.clipboardData.setData("text/html", c);
469
+ }, Ue = (n) => {
470
+ A == null || A(n);
471
+ }, We = () => {
472
+ ce.current = !0;
473
+ }, ze = () => {
474
+ ce.current = !1;
475
+ }, je = (n, i) => {
476
+ i.stopPropagation();
477
+ }, Xe = (n, i) => {
422
478
  var l;
423
- o.stopPropagation(), console.log("handleInputMouseDown", e, o), E.current && me(E.current), (l = y.current) == null || l.setAttribute("contenteditable", "false");
424
- const n = document.getElementById(e.id);
425
- E.current = n, requestAnimationFrame(() => {
426
- M(n);
479
+ i.stopPropagation(), R.current && Ne(R.current), (l = m.current) == null || l.setAttribute("contenteditable", "false");
480
+ const e = document.getElementById(n.id);
481
+ R.current = e, requestAnimationFrame(() => {
482
+ V(e);
427
483
  });
428
- }, qe = (e, o) => {
429
- var i, u, p, $, b;
430
- console.log("handleInputKeyDown", e, o), N == null || N(o), o.stopPropagation();
431
- const n = o.target, l = ne(n);
432
- if (o.code === "Backspace" && l === 0) {
433
- const t = (i = n.parentElement) == null ? void 0 : i.previousElementSibling;
434
- console.log("previousElement", t), t && (O(t) && t.children[0] && ((u = t.children[0].textContent) != null && u.length) ? (E.current = t, M(t), F(t.children[0]), requestAnimationFrame(() => {
435
- te(t.children[0]);
436
- })) : (Z(), F(t)));
484
+ }, Ge = (n, i) => {
485
+ var c, a, d, P, S;
486
+ x == null || x(i), i.stopPropagation();
487
+ const e = i.target, l = pe(e);
488
+ if (i.code === "Backspace" && l === 0) {
489
+ const t = (c = e.parentElement) == null ? void 0 : c.previousElementSibling;
490
+ t && (_(t) && t.children[0] && ((a = t.children[0].textContent) != null && a.length) ? (R.current = t, V(t), q(t.children[0]), requestAnimationFrame(() => {
491
+ fe(t.children[0]);
492
+ })) : (ae(), q(t)));
437
493
  }
438
- if (o.code === "ArrowRight" && l === ((p = n.textContent) == null ? void 0 : p.length)) {
439
- const t = ($ = n.parentElement) == null ? void 0 : $.nextElementSibling;
440
- console.log("nextElement", t), t && (O(t) && t.children[0] && ((b = t.children[0].textContent) != null && b.length) ? (E.current = t, M(t), z(t.children[0]), requestAnimationFrame(() => {
441
- te(t.children[0]);
442
- })) : (Z(), z(t)));
494
+ if (i.code === "ArrowRight" && l === ((d = e.textContent) == null ? void 0 : d.length)) {
495
+ const t = (P = e.parentElement) == null ? void 0 : P.nextElementSibling;
496
+ t && (_(t) && t.children[0] && ((S = t.children[0].textContent) != null && S.length) ? (R.current = t, V(t), ee(t.children[0]), requestAnimationFrame(() => {
497
+ fe(t.children[0]);
498
+ })) : (ae(), ee(t)));
443
499
  }
444
- }, Ke = (e, o) => {
445
- console.log("handleInputKeyUp", e, o), V == null || V(o);
446
- const n = o.target;
447
- te(n);
448
- }, We = (e, o) => {
500
+ i.code === "Enter" && i.shiftKey && i.preventDefault();
501
+ }, Je = (n, i) => {
502
+ K == null || K(i);
503
+ const e = i.target;
504
+ fe(e);
505
+ }, Qe = (n, i) => {
449
506
  var l;
450
- o.stopPropagation(), console.log("handlePlaceholderMouseDown", e), E.current && me(E.current), (l = y.current) == null || l.setAttribute("contenteditable", "false");
451
- const n = document.getElementById(e.id);
452
- E.current = n, requestAnimationFrame(() => {
453
- M(n);
507
+ i.stopPropagation(), R.current && Ne(R.current), (l = m.current) == null || l.setAttribute("contenteditable", "false");
508
+ const e = document.getElementById(n.id);
509
+ R.current = e, requestAnimationFrame(() => {
510
+ V(e);
454
511
  });
455
- }, _e = (e, o) => {
456
- console.log("handleInputChange", e, o), v(K()), oe(he()), h == null || h(K());
457
- }, ze = (e, o) => {
458
- console.log("handleTextSpanKeyDown 不生效", e, o);
512
+ }, Ze = (n, i) => {
513
+ ie(v()), he(xe()), y == null || y(v());
514
+ }, Ie = (n, i) => {
459
515
  };
460
- P(() => {
461
- if (!G) return;
462
- const e = (l) => {
463
- T.current && !T.current.contains(l.target) && q(!1);
464
- }, o = (l) => {
465
- T.current && !T.current.contains(l.target) && q(!1);
466
- }, n = () => {
467
- q(!1);
516
+ M(() => {
517
+ if (!U) return;
518
+ const n = (l) => {
519
+ B.current && !B.current.contains(l.target) && O(!1);
520
+ }, i = (l) => {
521
+ B.current && !B.current.contains(l.target) && O(!1);
522
+ }, e = () => {
523
+ O(!1);
468
524
  };
469
- return document.addEventListener("mousedown", e), document.addEventListener("scroll", o, !0), window.addEventListener("resize", n), () => {
470
- document.removeEventListener("mousedown", e), document.removeEventListener("scroll", o, !0), window.removeEventListener("resize", n);
525
+ return document.addEventListener("mousedown", n), document.addEventListener("scroll", i, !0), window.addEventListener("resize", e), () => {
526
+ document.removeEventListener("mousedown", n), document.removeEventListener("scroll", i, !0), window.removeEventListener("resize", e);
471
527
  };
472
- }, [G]);
473
- const I = (e, o) => {
474
- if (console.log("handleFloatChange", e, o), L && Qe(L.id, e), o === "select" && q(!1), o === "multiple-select" || o === "date-picker") {
475
- const n = document.getElementById(
476
- L.id
528
+ }, [U]);
529
+ const Q = (n, i) => {
530
+ if (C && i !== h.LABEL && st(C.id, n), i === h.SELECT && (O(!1), z({})), i === h.LABEL && (ue(), O(!1), requestAnimationFrame(() => {
531
+ const e = window.getSelection();
532
+ e && Z.current && (e.removeAllRanges(), e.addRange(Z.current), setTimeout(() => {
533
+ var d;
534
+ const l = document.createElement("span");
535
+ l.contentEditable = "false", l.setAttribute("data-set-type", "label"), l.id = C.id;
536
+ const c = document.createElement("span");
537
+ c.contentEditable = "false", c.textContent = n, l.appendChild(c);
538
+ const a = (d = m.current) == null ? void 0 : d.children;
539
+ if ((a == null ? void 0 : a.length) === 1 && a[0].tagName === "SPAN" && a[0].innerHTML === "​[")
540
+ m.current.innerHTML = "", m.current.appendChild(l), setTimeout(() => {
541
+ z({}), ue();
542
+ }, 0);
543
+ else {
544
+ document.execCommand("delete", !1, void 0);
545
+ const P = Z.current;
546
+ P.insertNode(l), P.setStartAfter(l), P.setEndAfter(l), e.removeAllRanges(), e.addRange(P), setTimeout(() => {
547
+ z({});
548
+ }, 0);
549
+ }
550
+ }, 0));
551
+ })), i === h.MULTIPLE_SELECT || i === h.DATE_PICKER) {
552
+ const e = document.getElementById(
553
+ C.id
477
554
  );
478
- n && n.children[0] && n.children[1] && (e.length > 0 ? (n.children[0].setAttribute("style", "display: inline"), n.children[0].setAttribute("contenteditable", "false"), n.children[1].setAttribute("style", "display: none"), n.children[1].setAttribute("contenteditable", "true")) : (n.children[0].setAttribute("style", "display: none"), n.children[0].setAttribute("contenteditable", "true"), n.children[1].setAttribute("style", "display: inline"), n.children[1].setAttribute("contenteditable", "true")));
555
+ e && e.children[0] && e.children[1] && (n.length > 0 ? (e.children[0].setAttribute("style", "display: inline"), e.children[0].setAttribute("contenteditable", "false"), e.children[1].setAttribute("style", "display: none"), e.children[1].setAttribute("contenteditable", "true")) : (e.children[0].setAttribute("style", "display: none"), e.children[0].setAttribute("contenteditable", "true"), e.children[1].setAttribute("style", "display: inline"), e.children[1].setAttribute("contenteditable", "true"))), z({});
479
556
  }
480
- ge({});
481
- }, ye = (e, o) => {
482
- console.log("handleSelectClick", e, o);
483
- const l = o.target.getBoundingClientRect();
484
- ce(e.options), se(e.value || Ae(e.id)), Q({ top: -999999, left: -999999999 }), re(e), ae(Te), q(!0), requestAnimationFrame(() => {
485
- if (T.current) {
486
- console.log(
487
- "currentFloatElementRef.current",
488
- T.current
489
- );
490
- const i = T.current.getBoundingClientRect();
491
- let u = l.left, p = l.top + l.height;
492
- window.innerWidth - l.right < Ne && l.width < i.width && (u = l.right - i.width), l.top < i.height && (p = l.top + l.height), Q({ top: p, left: u }), ae(i.height);
557
+ }, Z = F(null), Ye = (N == null ? void 0 : N.map((n) => n.prefix)) || [], et = (n) => {
558
+ const i = n == null ? void 0 : n.nativeEvent, e = i == null ? void 0 : i.data;
559
+ Ye.includes(e) && dt().then((l) => {
560
+ var a;
561
+ const c = window.getSelection();
562
+ c && c.rangeCount > 0 && (Z.current = c.getRangeAt(0)), tt({
563
+ options: ((a = N.find((d) => d.prefix === e)) == null ? void 0 : a.options) || [],
564
+ value: "",
565
+ type: h.LABEL,
566
+ id: "label-" + ke()
567
+ }, l);
568
+ });
569
+ }, tt = (n, i) => {
570
+ le(n.options), W({ top: -999999, left: -999999999 }), oe(n), J(Ce), O(!0), requestAnimationFrame(() => {
571
+ if (B.current) {
572
+ const e = B.current.getBoundingClientRect();
573
+ let l = i.left, c = i.top + i.height;
574
+ window.innerWidth - i.right < be && i.width < e.width && (l = i.right - e.width), i.top < e.height && (c = i.top + i.height), W({ top: c, left: l }), J(e.height);
575
+ }
576
+ });
577
+ }, me = (n, i) => {
578
+ const l = i.target.getBoundingClientRect();
579
+ le(n.options), ge(n.value || De(n.id)), W({ top: -999999, left: -999999999 }), oe(n), J(Ce), O(!0), requestAnimationFrame(() => {
580
+ if (B.current) {
581
+ const c = B.current.getBoundingClientRect();
582
+ let a = l.left, d = l.top + l.height;
583
+ window.innerWidth - l.right < be && l.width < c.width && (a = l.right - c.width), l.top < c.height && (d = l.top + l.height), W({ top: d, left: a }), J(c.height);
493
584
  }
494
585
  });
495
- }, je = (e, o) => {
496
- console.log("handleDatePickerClick", e, o);
497
- const l = o.target.getBoundingClientRect();
498
- let i = l.left, u = l.top - fe;
499
- window.innerWidth - l.right < pe && (i = i - pe + l.width), l.top < fe && (u = l.top + l.height), ce(e.options), se(e.value || Ae(e.id)), Q({ top: u, left: i }), re(e), q(!0);
500
- }, [Ee, be] = C([]), [ee, xe] = C(!0), we = ve(() => {
501
- xe(!1);
502
- const e = Se(c), o = [];
503
- return e.forEach((n) => {
504
- var l, i, u, p, $, b;
505
- if (n.type === "text")
506
- o.push(
507
- /* @__PURE__ */ f("span", { onKeyDown: (t) => ze(n, t), children: n.content }, n.id)
586
+ }, nt = (n, i) => {
587
+ const l = i.target.getBoundingClientRect();
588
+ let c = l.left, a = l.top - Ae;
589
+ window.innerWidth - l.right < we && (c = c - we + l.width), l.top < Ae && (a = l.top + l.height), le(n.options), ge(n.value || De(n.id)), W({ top: a, left: c }), oe(n), O(!0);
590
+ }, [it, Le] = L([]), [de, Te] = L(!0), Re = Pe(() => {
591
+ Te(!1);
592
+ const n = Fe(o), i = [];
593
+ return n.forEach((e) => {
594
+ var l, c, a, d, P, S;
595
+ if (e.type === "text")
596
+ i.push(
597
+ /* @__PURE__ */ u("span", { onKeyDown: (t) => Ie(), children: e.content }, e.id)
598
+ );
599
+ else if (e.type === "newline")
600
+ i.push(/* @__PURE__ */ u("br", {}, e.id));
601
+ else if (e.type === "label")
602
+ i.push(
603
+ /* @__PURE__ */ u(
604
+ "span",
605
+ {
606
+ id: e.id,
607
+ "data-set-type": "label",
608
+ contentEditable: !1,
609
+ children: /* @__PURE__ */ u(
610
+ "span",
611
+ {
612
+ contentEditable: !1,
613
+ children: e.name
614
+ }
615
+ )
616
+ },
617
+ e.id
618
+ )
508
619
  );
509
- else if (n.type === "newline")
510
- o.push(/* @__PURE__ */ f("br", {}, n.id));
511
- else if (n.type === "input")
512
- o.push(
513
- /* @__PURE__ */ _(
620
+ else if (e.type === "input")
621
+ i.push(
622
+ /* @__PURE__ */ Y(
514
623
  "span",
515
624
  {
516
- id: n.id,
625
+ id: e.id,
517
626
  "data-set-type": "input",
518
627
  contentEditable: !1,
519
628
  suppressContentEditableWarning: !0,
520
- onInput: (t) => _e(n, t),
521
- onClick: (t) => Be(n, t),
522
- onMouseDown: (t) => Ve(n, t),
523
- "data-cosmic-ai-input-placeholder": n.placeholder,
629
+ onInput: (t) => Ze(),
630
+ onClick: (t) => je(e, t),
631
+ onMouseDown: (t) => Xe(e, t),
632
+ "data-cosmic-ai-input-placeholder": e.placeholder,
524
633
  children: [
525
- /* @__PURE__ */ f(
634
+ /* @__PURE__ */ u(
526
635
  "span",
527
636
  {
528
637
  className: "cosmic-ai-input-inputContent",
529
638
  style: {
530
- padding: (l = n.content) != null && l.length ? "2px 4px" : "2px 0 2px 4px"
639
+ padding: (l = e.content) != null && l.length ? "2px 4px" : "2px 0 2px 4px"
531
640
  },
532
641
  contentEditable: !1,
533
- onKeyDown: (t) => qe(n, t),
534
- onKeyUp: (t) => Ke(n, t),
535
- children: n.content
642
+ onKeyDown: (t) => Ge(e, t),
643
+ onKeyUp: (t) => Je(e, t),
644
+ children: e.content
536
645
  }
537
646
  ),
538
- /* @__PURE__ */ f(
647
+ /* @__PURE__ */ u(
539
648
  "span",
540
649
  {
541
650
  contentEditable: !1,
542
- style: { display: (i = n.content) != null && i.length ? "none" : "inline" },
651
+ style: { display: (c = e.content) != null && c.length ? "none" : "inline" },
543
652
  className: "cosmic-ai-input-placeholder",
544
- onMouseDown: (t) => We(n, t),
545
- children: n.placeholder
653
+ onMouseDown: (t) => Qe(e, t),
654
+ children: e.placeholder
546
655
  }
547
656
  )
548
657
  ]
549
658
  },
550
- n.id
659
+ e.id
551
660
  )
552
661
  );
553
- else if (n.type === "select") {
554
- const t = n.content || ((u = n.options) == null ? void 0 : u[0]) || n.placeholder;
555
- o.push(
556
- /* @__PURE__ */ f(
662
+ else if (e.type === h.SELECT) {
663
+ const t = e.content || ((a = e.options) == null ? void 0 : a[0]) || e.placeholder;
664
+ i.push(
665
+ /* @__PURE__ */ u(
557
666
  "span",
558
667
  {
559
- id: n.id,
668
+ id: e.id,
560
669
  "data-set-type": "select",
561
670
  contentEditable: !1,
562
671
  suppressContentEditableWarning: !0,
563
- onClick: (R) => ye(n, R),
564
- "data-cosmic-ai-input-placeholder": n.placeholder,
565
- children: /* @__PURE__ */ f("span", { contentEditable: !1, children: t })
672
+ onClick: (H) => me(e, H),
673
+ "data-cosmic-ai-input-placeholder": e.placeholder,
674
+ children: /* @__PURE__ */ u("span", { contentEditable: !1, children: t })
566
675
  },
567
- n.id
676
+ e.id
568
677
  )
569
678
  );
570
- } else if (n.type === "multiple-select") {
571
- const t = n.content || ((p = n.options) == null ? void 0 : p[0]);
572
- o.push(
573
- /* @__PURE__ */ _(
679
+ } else if (e.type === h.MULTIPLE_SELECT) {
680
+ const t = e.content || ((d = e.options) == null ? void 0 : d[0]);
681
+ i.push(
682
+ /* @__PURE__ */ Y(
574
683
  "span",
575
684
  {
576
- id: n.id,
685
+ id: e.id,
577
686
  "data-set-type": "multiple-select",
578
687
  contentEditable: !1,
579
688
  suppressContentEditableWarning: !0,
580
- onClick: (R) => ye(n, R),
581
- "data-cosmic-ai-input-placeholder": n.placeholder,
689
+ onClick: (H) => me(e, H),
690
+ "data-cosmic-ai-input-placeholder": e.placeholder,
582
691
  children: [
583
- /* @__PURE__ */ f(
692
+ /* @__PURE__ */ u(
584
693
  "span",
585
694
  {
586
695
  style: { display: t != null && t.length ? "inline" : "none" },
@@ -588,156 +697,162 @@ const tt = j((s, r) => {
588
697
  children: t
589
698
  }
590
699
  ),
591
- /* @__PURE__ */ f(
700
+ /* @__PURE__ */ u(
592
701
  "span",
593
702
  {
594
703
  style: { display: t != null && t.length ? "none" : "inline" },
595
704
  className: "cosmic-ai-input-selectPlaceholder",
596
705
  contentEditable: !1,
597
- children: n.placeholder
706
+ children: e.placeholder
598
707
  }
599
708
  )
600
709
  ]
601
710
  },
602
- n.id
711
+ e.id
603
712
  )
604
713
  );
605
- } else n.type === "date-picker" && o.push(
606
- /* @__PURE__ */ _(
714
+ } else e.type === h.DATE_PICKER && i.push(
715
+ /* @__PURE__ */ Y(
607
716
  "span",
608
717
  {
609
- id: n.id,
718
+ id: e.id,
610
719
  "data-set-type": "date-picker",
611
720
  contentEditable: !1,
612
721
  suppressContentEditableWarning: !0,
613
- onClick: (t) => je(n, t),
614
- "data-cosmic-ai-input-placeholder": n.placeholder,
722
+ onClick: (t) => nt(e, t),
723
+ "data-cosmic-ai-input-placeholder": e.placeholder,
615
724
  children: [
616
- /* @__PURE__ */ f(
725
+ /* @__PURE__ */ u(
617
726
  "span",
618
727
  {
619
- style: { display: ($ = n.content) != null && $.length ? "inline" : "none" },
728
+ style: { display: (P = e.content) != null && P.length ? "inline" : "none" },
620
729
  contentEditable: !1,
621
- children: n.content
730
+ children: e.content
622
731
  }
623
732
  ),
624
- /* @__PURE__ */ f(
733
+ /* @__PURE__ */ u(
625
734
  "span",
626
735
  {
627
- style: { display: (b = n.content) != null && b.length ? "none" : "inline" },
736
+ style: { display: (S = e.content) != null && S.length ? "none" : "inline" },
628
737
  className: "cosmic-ai-input-datePickerPlaceholder",
629
738
  contentEditable: !1,
630
- children: n.placeholder
739
+ children: e.placeholder
631
740
  }
632
741
  )
633
742
  ]
634
743
  },
635
- n.id
744
+ e.id
636
745
  )
637
746
  );
638
747
  }), setTimeout(() => {
639
- xe(!0);
640
- }, 0), console.log(
641
- "重新渲染 ============================>",
642
- "elements",
643
- o,
644
- "parsed",
645
- e,
646
- c
647
- ), o;
648
- }, [c]);
649
- P(() => {
650
- ee && setTimeout(() => {
651
- F(y.current);
748
+ Te(!0);
749
+ }, 0), i;
750
+ }, [o]);
751
+ M(() => {
752
+ de && setTimeout(() => {
753
+ q(m.current);
652
754
  }, 0);
653
- }, [ee]), P(() => {
654
- c !== X ? (be(we()), v(c), ue(!0)) : (c === "" || !c) && be(we());
655
- }, [c, X]), P(() => {
656
- if (!A && !de) return;
657
- const e = new MutationObserver(() => {
658
- y.current && document.contains(y.current) && (requestAnimationFrame(() => {
659
- F(y.current), ue(!1);
660
- }), e.disconnect());
755
+ }, [de]), M(() => {
756
+ o !== ne ? (Le(Re()), ie(o), ye(!0)) : (o === "" || !o) && Le(Re());
757
+ }, [o, ne]), M(() => {
758
+ if (!D && !Ee) return;
759
+ const n = new MutationObserver(() => {
760
+ m.current && document.contains(m.current) && (requestAnimationFrame(() => {
761
+ q(m.current), ye(!1);
762
+ }), n.disconnect());
661
763
  });
662
- return y.current && e.observe(document.body, { childList: !0, subtree: !0 }), () => e.disconnect();
663
- }, [A, de]);
664
- const Ue = () => {
665
- y.current && requestAnimationFrame(() => {
666
- F(y.current);
764
+ return m.current && n.observe(document.body, { childList: !0, subtree: !0 }), () => n.disconnect();
765
+ }, [D, Ee]);
766
+ const ue = () => {
767
+ m.current && requestAnimationFrame(() => {
768
+ q(m.current);
667
769
  });
668
770
  };
669
- return Ge(r, () => ({
670
- getCurrentValue: K,
671
- focus: Ue
672
- })), console.log("renderElements", Ee), // 最外层的防止renderContainer为false的时候样式坍塌
673
- /* @__PURE__ */ _("div", { className: Ce(`cosmic-ai-input-rows${w}`), children: [
674
- ee && /* @__PURE__ */ f(
771
+ return lt(s, () => ({
772
+ getCurrentValue: v,
773
+ focus: ue
774
+ })), // 最外层的防止renderContainer为false的时候样式坍塌
775
+ /* @__PURE__ */ Y("div", { className: Se(`cosmic-ai-input-rows${g}`), style: { textIndent: T + "px" }, children: [
776
+ de && /* @__PURE__ */ u(
675
777
  "div",
676
778
  {
677
779
  "data-set-type": "container",
678
780
  "data-cosmic-ai-input-placeholder": k,
679
- className: Ce(
781
+ className: Se(
680
782
  "cosmic-ai-input",
681
- `cosmic-ai-input-rows${w}`,
682
- { "is-disabled": D },
683
- { "is-empty": X.length === 0 }
783
+ `cosmic-ai-input-rows${g}`,
784
+ { "is-disabled": $ },
785
+ { "is-empty": ne.length === 0 }
684
786
  ),
685
- ref: y,
787
+ ref: m,
686
788
  contentEditable: !0,
687
789
  suppressContentEditableWarning: !0,
688
- onClick: (e) => Le(e),
689
- onFocus: (e) => {
690
- He(e);
790
+ onClick: (n) => Oe(n),
791
+ onFocus: (n) => {
792
+ Ue(n);
691
793
  },
692
- onBlur: (e) => {
693
- S == null || S(e);
794
+ onBlur: (n) => {
795
+ p == null || p(n);
694
796
  },
695
- onMouseDown: (e) => $e(e),
696
- onKeyDown: (e) => Fe(e),
697
- onKeyUp: (e) => Pe(e),
698
- onInput: (e) => ge(e),
699
- onCopy: (e) => Oe(e),
700
- children: Ee
797
+ onMouseDown: (n) => Ve(),
798
+ onKeyDown: (n) => _e(n),
799
+ onKeyUp: (n) => Ke(n),
800
+ onInput: (n) => z(n),
801
+ onCopy: (n) => ve(n),
802
+ onCompositionStart: We,
803
+ onCompositionEnd: ze,
804
+ children: it
701
805
  }
702
806
  ),
703
- G && Je(
704
- (L == null ? void 0 : L.type) === "multiple-select" ? /* @__PURE__ */ f(
705
- Re,
807
+ U && ot(
808
+ (C == null ? void 0 : C.type) === h.MULTIPLE_SELECT ? /* @__PURE__ */ u(
809
+ Be,
810
+ {
811
+ ref: B,
812
+ options: re,
813
+ value: G,
814
+ position: X,
815
+ height: se,
816
+ onChange: Q
817
+ },
818
+ h.MULTIPLE_SELECT
819
+ ) : (C == null ? void 0 : C.type) === h.DATE_PICKER ? /* @__PURE__ */ u(
820
+ $e,
706
821
  {
707
- ref: T,
708
- options: le,
709
- value: Y,
710
- position: J,
711
- height: ie,
712
- onChange: I
822
+ ref: B,
823
+ value: G,
824
+ position: X,
825
+ onChange: Q
713
826
  },
714
- "multiple-select"
715
- ) : (L == null ? void 0 : L.type) === "date-picker" ? /* @__PURE__ */ f(
716
- ke,
827
+ h.DATE_PICKER
828
+ ) : (C == null ? void 0 : C.type) === h.LABEL ? /* @__PURE__ */ u(
829
+ He,
717
830
  {
718
- ref: T,
719
- value: Y,
720
- position: J,
721
- onChange: I
831
+ ref: B,
832
+ options: re,
833
+ value: G,
834
+ position: X,
835
+ height: se,
836
+ onChange: Q
722
837
  },
723
- "date-picker"
724
- ) : /* @__PURE__ */ f(
725
- De,
838
+ h.LABEL
839
+ ) : /* @__PURE__ */ u(
840
+ Me,
726
841
  {
727
- ref: T,
728
- options: le,
729
- value: Y,
730
- position: J,
731
- height: ie,
732
- onChange: I
842
+ ref: B,
843
+ options: re,
844
+ value: G,
845
+ position: X,
846
+ height: se,
847
+ onChange: Q
733
848
  },
734
- "select"
849
+ h.SELECT
735
850
  ),
736
851
  document.body
737
852
  )
738
853
  ] });
739
854
  });
740
- tt.displayName = "AiInput";
855
+ ht.displayName = "AiInput";
741
856
  export {
742
- tt as default
857
+ ht as default
743
858
  };