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