@code0-tech/pictor 0.0.0-mvp.32 → 0.0.0-mvp.33
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/components/form/Input.js +195 -190
- package/package.json +1 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { jsxs as W, jsx as g } from "react/jsx-runtime";
|
|
2
|
-
import l, { useRef as
|
|
2
|
+
import l, { useRef as C, useState as j, useMemo as D, useEffect as I, useLayoutEffect as _e } from "react";
|
|
3
3
|
import "../../utils/contextStore.js";
|
|
4
|
-
import { mergeCode0Props as
|
|
4
|
+
import { mergeCode0Props as me } from "../../utils/utils.js";
|
|
5
5
|
import '../../assets/components/form/Input.style.css';/* empty css */
|
|
6
|
-
import { InputLabel as
|
|
7
|
-
import { InputDescription as
|
|
8
|
-
import { InputMessage as
|
|
9
|
-
import { Menu as
|
|
10
|
-
import { InputSuggestionMenuContent as
|
|
11
|
-
import { buildDefaultSyntax as
|
|
12
|
-
import { getSelectionMetrics as
|
|
13
|
-
import { Card as
|
|
14
|
-
import { useContentEditableController as
|
|
6
|
+
import { InputLabel as et } from "./InputLabel.js";
|
|
7
|
+
import { InputDescription as tt } from "./InputDescription.js";
|
|
8
|
+
import { InputMessage as nt } from "./InputMessage.js";
|
|
9
|
+
import { Menu as rt, MenuTrigger as ot, MenuPortal as st } from "../menu/Menu.js";
|
|
10
|
+
import { InputSuggestionMenuContent as at, InputSuggestionMenuContentItems as ut } from "./InputSuggestion.js";
|
|
11
|
+
import { buildDefaultSyntax as it } from "./Input.syntax.hook.js";
|
|
12
|
+
import { getSelectionMetrics as lt, setElementKey as ct, setSelectionRangeSafe as ft } from "./Input.utils.js";
|
|
13
|
+
import { Card as dt } from "../card/Card.js";
|
|
14
|
+
import { useContentEditableController as pt, setSelectionOffsetsInValue as gt } from "./InputContentEditable.hook.js";
|
|
15
15
|
const q = (u) => {
|
|
16
16
|
const x = u ?? "";
|
|
17
17
|
return typeof x == "string" ? x : String(x);
|
|
18
|
-
},
|
|
18
|
+
}, ae = (u) => {
|
|
19
19
|
if (u == null) return "";
|
|
20
20
|
if (typeof u == "string") return u;
|
|
21
21
|
try {
|
|
@@ -23,11 +23,11 @@ const q = (u) => {
|
|
|
23
23
|
} catch {
|
|
24
24
|
return String(u ?? "");
|
|
25
25
|
}
|
|
26
|
-
},
|
|
26
|
+
}, ht = (u) => {
|
|
27
27
|
if (u && typeof u == "object") {
|
|
28
28
|
const {
|
|
29
29
|
children: x,
|
|
30
|
-
__contentHtml:
|
|
30
|
+
__contentHtml: Q,
|
|
31
31
|
...U
|
|
32
32
|
} = u;
|
|
33
33
|
return U;
|
|
@@ -35,114 +35,115 @@ const q = (u) => {
|
|
|
35
35
|
return {
|
|
36
36
|
value: u
|
|
37
37
|
};
|
|
38
|
-
},
|
|
38
|
+
}, Ae = (u) => {
|
|
39
39
|
if (!u) return null;
|
|
40
|
-
const x = u.value ?? "",
|
|
40
|
+
const x = u.value ?? "", Q = u.selectionStart ?? x.length, T = x.slice(0, Q).match(/\S+$/);
|
|
41
41
|
if (!T || T.index === void 0) return null;
|
|
42
|
-
const
|
|
42
|
+
const b = T[0], H = T.index, G = H + b.length;
|
|
43
43
|
return {
|
|
44
|
-
token:
|
|
44
|
+
token: b,
|
|
45
45
|
start: H,
|
|
46
|
-
end:
|
|
46
|
+
end: G
|
|
47
47
|
};
|
|
48
|
-
},
|
|
48
|
+
}, mt = l.forwardRef((u, x) => {
|
|
49
49
|
const {
|
|
50
|
-
wrapperComponent:
|
|
50
|
+
wrapperComponent: Q = {},
|
|
51
51
|
title: U,
|
|
52
52
|
description: T,
|
|
53
|
-
disabled:
|
|
53
|
+
disabled: b = !1,
|
|
54
54
|
left: H,
|
|
55
|
-
right:
|
|
56
|
-
leftType:
|
|
57
|
-
rightType:
|
|
58
|
-
formValidation:
|
|
55
|
+
right: G,
|
|
56
|
+
leftType: Ne = "icon",
|
|
57
|
+
rightType: ze = "action",
|
|
58
|
+
formValidation: P = {
|
|
59
59
|
valid: !0,
|
|
60
60
|
notValidMessage: null,
|
|
61
61
|
setValue: null
|
|
62
62
|
},
|
|
63
63
|
suggestions: f,
|
|
64
|
-
suggestionsHeader:
|
|
65
|
-
suggestionsFooter:
|
|
66
|
-
onSuggestionSelect:
|
|
67
|
-
disableOnValue:
|
|
68
|
-
transformSyntax:
|
|
69
|
-
validationUsesSyntax:
|
|
70
|
-
filterSuggestionsByLastToken:
|
|
71
|
-
enforceUniqueSuggestions:
|
|
72
|
-
onLastTokenChange:
|
|
73
|
-
suggestionsEmptyState:
|
|
74
|
-
...
|
|
64
|
+
suggestionsHeader: ye,
|
|
65
|
+
suggestionsFooter: Se,
|
|
66
|
+
onSuggestionSelect: Ce,
|
|
67
|
+
disableOnValue: be = () => !1,
|
|
68
|
+
transformSyntax: X,
|
|
69
|
+
validationUsesSyntax: ue = !1,
|
|
70
|
+
filterSuggestionsByLastToken: k = !1,
|
|
71
|
+
enforceUniqueSuggestions: ke = !1,
|
|
72
|
+
onLastTokenChange: ve,
|
|
73
|
+
suggestionsEmptyState: xe,
|
|
74
|
+
...We
|
|
75
75
|
} = u, {
|
|
76
|
-
onFocus:
|
|
77
|
-
onBlur:
|
|
78
|
-
onKeyDown:
|
|
79
|
-
onKeyDownCapture:
|
|
80
|
-
onChange:
|
|
81
|
-
onInput:
|
|
82
|
-
...
|
|
83
|
-
} =
|
|
84
|
-
B.current = e,
|
|
85
|
-
}, []), [
|
|
86
|
-
l.useImperativeHandle(x, () =>
|
|
87
|
-
const
|
|
88
|
-
...
|
|
89
|
-
|
|
90
|
-
onInput: M
|
|
91
|
-
}), [b, P, M]), Je = D(() => {
|
|
76
|
+
onFocus: we,
|
|
77
|
+
onBlur: Y,
|
|
78
|
+
onKeyDown: Z,
|
|
79
|
+
onKeyDownCapture: ie,
|
|
80
|
+
onChange: R,
|
|
81
|
+
onInput: O,
|
|
82
|
+
...h
|
|
83
|
+
} = We, _ = C(null), S = C(null), $ = C(null), F = C(null), le = C(null), w = C(!1), ce = C(!1), je = C(0), Ve = C(null), fe = h.value ?? u.initialValue ?? u.defaultValue, [Ee, qe] = j(!1), B = C(!1), i = l.useCallback((e) => {
|
|
84
|
+
B.current = e, qe(e);
|
|
85
|
+
}, []), [m, de] = j(fe), [De, Ie] = j([]), [K, pe] = j([]), [Te, Ue] = j(null), [A, He] = j(null), s = !!X, L = D(() => be(m), [be, m]), v = D(() => s ? $ : S, [s]);
|
|
86
|
+
l.useImperativeHandle(x, () => v.current ?? null);
|
|
87
|
+
const Je = D(() => ({
|
|
88
|
+
...h
|
|
89
|
+
}), [h]), Qe = D(() => {
|
|
92
90
|
const {
|
|
93
91
|
value: e,
|
|
94
92
|
defaultValue: t,
|
|
95
93
|
...n
|
|
96
|
-
} =
|
|
97
|
-
return
|
|
98
|
-
}, [
|
|
99
|
-
const e =
|
|
100
|
-
!e ||
|
|
94
|
+
} = h;
|
|
95
|
+
return me("input__control", n);
|
|
96
|
+
}, [h]), ee = l.useCallback(() => {
|
|
97
|
+
const e = v.current;
|
|
98
|
+
!e || b || L || e.focus({
|
|
101
99
|
preventScroll: !0
|
|
102
100
|
});
|
|
103
|
-
}, [
|
|
101
|
+
}, [v, b, L]), N = l.useCallback(() => {
|
|
104
102
|
f && i(!0);
|
|
105
|
-
}, [f, i]),
|
|
106
|
-
|
|
107
|
-
}, [
|
|
108
|
-
if (!
|
|
109
|
-
const n =
|
|
110
|
-
Object.is(
|
|
111
|
-
}, [
|
|
103
|
+
}, [f, i]), ge = l.useCallback((e) => {
|
|
104
|
+
k && (Ue(e), e && i(!0), ve?.(e));
|
|
105
|
+
}, [k, ve, i]), J = l.useCallback((e, t) => {
|
|
106
|
+
if (!P?.setValue) return;
|
|
107
|
+
const n = h.type !== "checkbox" ? q(e) : e, o = ue ? t : n;
|
|
108
|
+
Object.is(Ve.current, o) || (Ve.current = o, P.setValue(o));
|
|
109
|
+
}, [P?.setValue, h.type, ue]), Pe = l.useCallback((e) => {
|
|
110
|
+
const t = e.currentTarget, n = h.type === "checkbox" ? t.checked : t.value;
|
|
111
|
+
de(n), J(n, null);
|
|
112
|
+
}, [h.type, J]), p = pt({
|
|
112
113
|
editorRef: $,
|
|
113
|
-
transformSyntax:
|
|
114
|
-
filterSuggestionsByLastToken:
|
|
115
|
-
onLastTokenChange:
|
|
114
|
+
transformSyntax: X,
|
|
115
|
+
filterSuggestionsByLastToken: k,
|
|
116
|
+
onLastTokenChange: ge,
|
|
116
117
|
onStateChange: ({
|
|
117
118
|
value: e,
|
|
118
119
|
tokens: t,
|
|
119
120
|
segments: n
|
|
120
121
|
}) => {
|
|
121
|
-
|
|
122
|
+
de(e), pe(t), He(n ?? null), J(e, n ?? null);
|
|
122
123
|
}
|
|
123
|
-
}), Le =
|
|
124
|
+
}), Le = C(!1);
|
|
124
125
|
I(() => {
|
|
125
|
-
if (!s || !
|
|
126
|
-
const e = q(
|
|
126
|
+
if (!s || !X || Le.current) return;
|
|
127
|
+
const e = q(fe);
|
|
127
128
|
p.initializeFromExternalValue(e), Le.current = !0;
|
|
128
|
-
}, [s,
|
|
129
|
-
s ||
|
|
130
|
-
}, [
|
|
131
|
-
|
|
132
|
-
}, [
|
|
129
|
+
}, [s, X, fe, ue, p]), I(() => {
|
|
130
|
+
s || h.value !== void 0 && de(h.value);
|
|
131
|
+
}, [h.value, s]), I(() => {
|
|
132
|
+
J(m, A);
|
|
133
|
+
}, [J, A, m]), I(() => {
|
|
133
134
|
if (!f) return;
|
|
134
135
|
const e = (t) => {
|
|
135
|
-
const n = t.target, o = !!$.current?.contains(n), a = !!
|
|
136
|
+
const n = t.target, o = !!$.current?.contains(n), a = !!S.current?.contains(n), r = !!le.current?.contains(n), y = !!_.current?.contains(n), c = o || a || r || y;
|
|
136
137
|
w.current = c, !c && B.current && i(!1);
|
|
137
138
|
};
|
|
138
139
|
return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
|
|
139
140
|
}, [f, i]), I(() => {
|
|
140
|
-
const e =
|
|
141
|
+
const e = _.current;
|
|
141
142
|
if (!e) return;
|
|
142
143
|
const t = () => N();
|
|
143
144
|
return e.addEventListener("focusin", t), () => e.removeEventListener("focusin", t);
|
|
144
145
|
}, [N]);
|
|
145
|
-
const
|
|
146
|
+
const Me = l.useCallback((e, t, n) => {
|
|
146
147
|
if (e.length === 0) return t <= n.length ? t : null;
|
|
147
148
|
let o = n.indexOf(e);
|
|
148
149
|
if (o === -1) return null;
|
|
@@ -150,10 +151,10 @@ const q = (u) => {
|
|
|
150
151
|
for (; a !== -1; )
|
|
151
152
|
Math.abs(a - t) < Math.abs(o - t) && (o = a), a = n.indexOf(e, a + 1);
|
|
152
153
|
return o;
|
|
153
|
-
}, []),
|
|
154
|
+
}, []), te = l.useCallback((e, t) => {
|
|
154
155
|
const n = [];
|
|
155
156
|
return e.forEach((o) => {
|
|
156
|
-
const a =
|
|
157
|
+
const a = Me(o.text, o.start, t);
|
|
157
158
|
if (a === null) return;
|
|
158
159
|
const r = a + o.text.length;
|
|
159
160
|
t.slice(a, r) === o.text && n.push({
|
|
@@ -162,81 +163,81 @@ const q = (u) => {
|
|
|
162
163
|
end: r
|
|
163
164
|
});
|
|
164
165
|
}), n;
|
|
165
|
-
}, [
|
|
166
|
+
}, [Me]);
|
|
166
167
|
I(() => {
|
|
167
168
|
if (s) return;
|
|
168
|
-
const e = q(
|
|
169
|
+
const e = q(S.current?.value ?? m);
|
|
169
170
|
Ie((t) => {
|
|
170
|
-
const n =
|
|
171
|
-
return
|
|
171
|
+
const n = te(t, e);
|
|
172
|
+
return pe(n.map((o) => o.suggestion)), n;
|
|
172
173
|
});
|
|
173
|
-
}, [s,
|
|
174
|
-
if (!
|
|
175
|
-
const e =
|
|
174
|
+
}, [s, te, m]), I(() => {
|
|
175
|
+
if (!k || s) return;
|
|
176
|
+
const e = S.current;
|
|
176
177
|
if (!e) return;
|
|
177
|
-
const t = () =>
|
|
178
|
+
const t = () => ge(Ae(e)?.token ?? null);
|
|
178
179
|
return e.addEventListener("input", t), e.addEventListener("keyup", t), e.addEventListener("mouseup", t), t(), () => {
|
|
179
180
|
e.removeEventListener("input", t), e.removeEventListener("keyup", t), e.removeEventListener("mouseup", t);
|
|
180
181
|
};
|
|
181
|
-
}, [
|
|
182
|
+
}, [k, s, ge]);
|
|
182
183
|
const z = D(() => {
|
|
183
|
-
if (!
|
|
184
|
+
if (!k || !f) return f;
|
|
184
185
|
const e = Te?.trim();
|
|
185
186
|
return e?.length ? f.filter((t) => String(t?.value ?? "").toLowerCase().startsWith(e.toLowerCase())) : f;
|
|
186
|
-
}, [
|
|
187
|
-
if (!
|
|
187
|
+
}, [k, Te, f]), ne = D(() => {
|
|
188
|
+
if (!ke || !z) return z;
|
|
188
189
|
if (s) {
|
|
189
|
-
const t = new Set((K ?? []).map((n) =>
|
|
190
|
-
return z.filter((n) => !t.has(
|
|
190
|
+
const t = new Set((K ?? []).map((n) => ae(n?.value ?? n)));
|
|
191
|
+
return z.filter((n) => !t.has(ae(n?.value ?? n)));
|
|
191
192
|
}
|
|
192
193
|
const e = new Set(De.map((t) => t.suggestion));
|
|
193
194
|
return z.filter((t) => !e.has(t));
|
|
194
|
-
}, [De, K,
|
|
195
|
-
if (!
|
|
196
|
-
const t = typeof
|
|
197
|
-
let r = a,
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
r = `${a.slice(0,
|
|
195
|
+
}, [De, K, ke, z, s]), Re = l.useCallback((e) => {
|
|
196
|
+
if (!S.current) return;
|
|
197
|
+
const t = typeof m == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), o = e.insertMode ?? "replace", a = S.current.value ?? "";
|
|
198
|
+
let r = a, y = null, c = 0;
|
|
199
|
+
const V = k ? Ae(S.current) : null;
|
|
200
|
+
if (k && V)
|
|
201
|
+
r = `${a.slice(0, V.start)}${n}${a.slice(V.end)}`, y = V.start + n.length, c = V.start;
|
|
201
202
|
else
|
|
202
203
|
switch (o) {
|
|
203
204
|
case "append":
|
|
204
|
-
r = `${a}${n}`,
|
|
205
|
+
r = `${a}${n}`, y = r.length, c = a.length;
|
|
205
206
|
break;
|
|
206
207
|
case "prepend":
|
|
207
|
-
r = `${n}${a}`,
|
|
208
|
+
r = `${n}${a}`, y = n.length, c = 0;
|
|
208
209
|
break;
|
|
209
210
|
case "insert": {
|
|
210
211
|
const {
|
|
211
212
|
rawStart: d,
|
|
212
|
-
rawEnd:
|
|
213
|
-
} =
|
|
214
|
-
r = `${a.slice(0, d)}${n}${a.slice(
|
|
213
|
+
rawEnd: M
|
|
214
|
+
} = lt(S.current);
|
|
215
|
+
r = `${a.slice(0, d)}${n}${a.slice(M)}`, y = d + n.length, c = d;
|
|
215
216
|
break;
|
|
216
217
|
}
|
|
217
218
|
case "replace":
|
|
218
219
|
default:
|
|
219
|
-
r = n,
|
|
220
|
+
r = n, y = n.length, c = 0;
|
|
220
221
|
break;
|
|
221
222
|
}
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
id:
|
|
223
|
+
ct(S.current, "value", r, "change"), Ie((d) => {
|
|
224
|
+
const M = q(r), oe = te(d, M), E = n.length ? {
|
|
225
|
+
id: je.current++,
|
|
225
226
|
suggestion: e,
|
|
226
227
|
text: n,
|
|
227
228
|
start: c,
|
|
228
229
|
end: c + n.length
|
|
229
|
-
} : null,
|
|
230
|
-
return
|
|
231
|
-
}),
|
|
232
|
-
const d =
|
|
230
|
+
} : null, se = E ? [...oe, E] : oe;
|
|
231
|
+
return pe(se.map((Ze) => Ze.suggestion)), se;
|
|
232
|
+
}), y !== null && requestAnimationFrame(() => {
|
|
233
|
+
const d = S.current;
|
|
233
234
|
d && (d.focus({
|
|
234
235
|
preventScroll: !0
|
|
235
|
-
}),
|
|
236
|
+
}), ft(d, y, y));
|
|
236
237
|
});
|
|
237
|
-
}, [
|
|
238
|
-
if (s ? p.applySuggestionValueSyntax(e) :
|
|
239
|
-
const t =
|
|
238
|
+
}, [k, te, m]), Oe = l.useCallback((e) => {
|
|
239
|
+
if (s ? p.applySuggestionValueSyntax(e) : Re(e), Ce?.(e), s) {
|
|
240
|
+
const t = v.current;
|
|
240
241
|
requestAnimationFrame(() => {
|
|
241
242
|
if (!t) return;
|
|
242
243
|
const n = {
|
|
@@ -246,31 +247,31 @@ const q = (u) => {
|
|
|
246
247
|
};
|
|
247
248
|
t.dispatchEvent(new Event("input", {
|
|
248
249
|
bubbles: !0
|
|
249
|
-
})),
|
|
250
|
+
})), O?.(n), R?.(n);
|
|
250
251
|
});
|
|
251
252
|
}
|
|
252
253
|
i(!1), w.current = !1, requestAnimationFrame(() => {
|
|
253
|
-
|
|
254
|
+
ee();
|
|
254
255
|
});
|
|
255
|
-
}, [
|
|
256
|
-
N(),
|
|
257
|
-
}, [N,
|
|
258
|
-
if (
|
|
259
|
-
|
|
256
|
+
}, [v, Re, p, ee, s, Ce, i, R, O]), $e = l.useCallback((e) => {
|
|
257
|
+
N(), we?.(e);
|
|
258
|
+
}, [N, we]), re = l.useCallback((e) => {
|
|
259
|
+
if (ce.current) {
|
|
260
|
+
ce.current = !1, Y?.(e);
|
|
260
261
|
return;
|
|
261
262
|
}
|
|
262
263
|
if (w.current) {
|
|
263
|
-
|
|
264
|
+
Y?.(e);
|
|
264
265
|
return;
|
|
265
266
|
}
|
|
266
|
-
i(!1),
|
|
267
|
-
}, [
|
|
267
|
+
i(!1), Y?.(e);
|
|
268
|
+
}, [Y, i]), Fe = l.useCallback((e) => {
|
|
268
269
|
if (s) {
|
|
269
|
-
p.handleKeyDownCapture(e),
|
|
270
|
+
p.handleKeyDownCapture(e), ie?.(e);
|
|
270
271
|
return;
|
|
271
272
|
}
|
|
272
|
-
(e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()),
|
|
273
|
-
}, [p, s,
|
|
273
|
+
(e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()), ie?.(e);
|
|
274
|
+
}, [p, s, ie]), Be = l.useCallback((e) => {
|
|
274
275
|
if (f) {
|
|
275
276
|
if (e.key === "ArrowDown") {
|
|
276
277
|
e.preventDefault(), e.stopPropagation(), B.current ? F.current?.highlightNextItem?.() : (i(!0), setTimeout(() => F.current?.focusFirstItem?.(), 0));
|
|
@@ -291,70 +292,70 @@ const q = (u) => {
|
|
|
291
292
|
}
|
|
292
293
|
if (s && p.handleKeyDown(e)) {
|
|
293
294
|
if (e.key === "Backspace" || e.key === "Delete") {
|
|
294
|
-
const n =
|
|
295
|
+
const n = v.current;
|
|
295
296
|
if (n) {
|
|
296
297
|
const o = {
|
|
297
298
|
type: "change",
|
|
298
299
|
target: n,
|
|
299
300
|
currentTarget: n
|
|
300
301
|
};
|
|
301
|
-
|
|
302
|
+
O?.(o), R?.(o);
|
|
302
303
|
}
|
|
303
304
|
}
|
|
304
|
-
|
|
305
|
+
Z?.(e);
|
|
305
306
|
return;
|
|
306
307
|
}
|
|
307
308
|
if (s && e.key === "Enter") {
|
|
308
|
-
e.preventDefault(),
|
|
309
|
+
e.preventDefault(), Z?.(e);
|
|
309
310
|
return;
|
|
310
311
|
}
|
|
311
|
-
|
|
312
|
-
}, [
|
|
312
|
+
Z?.(e);
|
|
313
|
+
}, [v, p, s, f, i, R, O, Z]), Ke = D(() => {
|
|
313
314
|
if (!s) return null;
|
|
314
|
-
const e = q(
|
|
315
|
-
return n.forEach((r,
|
|
315
|
+
const e = q(m), t = (A ?? []).filter(Boolean).filter((r) => r && (r.type === "text" || r.type === "block") && Number.isFinite(r.start) && Number.isFinite(r.end) && r.start <= r.end), n = t.length ? t : it(e), o = (K ?? []).slice(), a = [];
|
|
316
|
+
return n.forEach((r, y) => {
|
|
316
317
|
const c = r.value ?? e.slice(r.start, r.end);
|
|
317
318
|
if (r.type === "text") {
|
|
318
|
-
const
|
|
319
|
-
|
|
319
|
+
const E = typeof r.content == "string" ? r.content : typeof c == "string" ? c : e.slice(r.start, r.end);
|
|
320
|
+
E?.length && a.push(E);
|
|
320
321
|
return;
|
|
321
322
|
}
|
|
322
|
-
const
|
|
323
|
+
const V = ae(c);
|
|
323
324
|
let d;
|
|
324
325
|
if (o.length) {
|
|
325
|
-
const
|
|
326
|
-
(
|
|
326
|
+
const E = o[0], se = ae(E?.value ?? E);
|
|
327
|
+
(V === "" || se === V) && (d = E, o.shift());
|
|
327
328
|
}
|
|
328
329
|
d || (d = {
|
|
329
330
|
value: c
|
|
330
331
|
});
|
|
331
|
-
const
|
|
332
|
+
const M = ht(d), oe = r.content && typeof r.content != "string" || typeof r.content == "string" ? r.content : M?.label ?? M?.value ?? "";
|
|
332
333
|
a.push(/* @__PURE__ */ W(l.Fragment, { children: [
|
|
333
334
|
"",
|
|
334
|
-
/* @__PURE__ */ g("span", { className: "input__token", contentEditable: !1, "aria-data": JSON.stringify(
|
|
335
|
+
/* @__PURE__ */ g("span", { className: "input__token", contentEditable: !1, "aria-data": JSON.stringify(M), style: {
|
|
335
336
|
display: "inline-flex",
|
|
336
337
|
alignItems: "center",
|
|
337
338
|
verticalAlign: "middle",
|
|
338
339
|
userSelect: "text",
|
|
339
340
|
WebkitUserSelect: "text"
|
|
340
|
-
}, children:
|
|
341
|
+
}, children: oe }),
|
|
341
342
|
""
|
|
342
|
-
] }, `${
|
|
343
|
+
] }, `${y}-${V}`));
|
|
343
344
|
}), a;
|
|
344
|
-
}, [K, s, A,
|
|
345
|
-
|
|
345
|
+
}, [K, s, A, m]);
|
|
346
|
+
_e(() => {
|
|
346
347
|
if (!s) return;
|
|
347
348
|
const e = $.current;
|
|
348
349
|
if (!e) return;
|
|
349
350
|
const t = p.takePendingSelection();
|
|
350
|
-
t &&
|
|
351
|
-
}, [p, s,
|
|
352
|
-
const
|
|
351
|
+
t && gt(e, t.start, t.end);
|
|
352
|
+
}, [p, s, Ke]);
|
|
353
|
+
const Ge = D(() => {
|
|
353
354
|
if (!s) return "plain";
|
|
354
|
-
const e = q(
|
|
355
|
+
const e = q(m), t = K?.length ?? 0, n = A?.length ?? 0;
|
|
355
356
|
return `${e}-${t}-${n}`;
|
|
356
|
-
}, [K, s, A,
|
|
357
|
-
p.updateEditorState($.current), f && (w.current = !0,
|
|
357
|
+
}, [K, s, A, m]), he = s ? /* @__PURE__ */ g("div", { ref: $, ...Qe, contentEditable: !b && !L, suppressContentEditableWarning: !0, "aria-disabled": b || L, onInput: (e) => {
|
|
358
|
+
p.updateEditorState($.current), f && (w.current = !0, ce.current = !0, i(!0), requestAnimationFrame(() => {
|
|
358
359
|
w.current = !1;
|
|
359
360
|
}));
|
|
360
361
|
const t = e.currentTarget, n = {
|
|
@@ -362,67 +363,71 @@ const q = (u) => {
|
|
|
362
363
|
target: t,
|
|
363
364
|
currentTarget: t
|
|
364
365
|
};
|
|
365
|
-
|
|
366
|
+
O?.(n), R?.(n);
|
|
366
367
|
}, onChange: (e) => {
|
|
367
368
|
p.handleChange(e);
|
|
368
|
-
}, onPaste: p.handlePaste, onFocus:
|
|
369
|
-
|
|
369
|
+
}, onPaste: p.handlePaste, onFocus: $e, onBlur: re, onKeyDownCapture: Fe, onKeyDown: Be, spellCheck: !1, children: Ke }, Ge) : /* @__PURE__ */ g("input", { ref: S, ...me("input__control", Je), onFocus: $e, onBlur: re, onKeyDownCapture: Fe, onKeyDown: Be, onInput: (e) => {
|
|
370
|
+
Pe(e), O?.(e);
|
|
371
|
+
}, onChange: (e) => {
|
|
372
|
+
Pe(e), R?.(e);
|
|
373
|
+
}, spellCheck: !1, disabled: b || L }), Xe = l.useCallback((e) => {
|
|
374
|
+
if (b || L) return;
|
|
370
375
|
const t = e.target;
|
|
371
|
-
|
|
372
|
-
}, [
|
|
376
|
+
le.current?.contains(t) || (w.current = !0, ee(), N());
|
|
377
|
+
}, [b, L, ee, N]);
|
|
373
378
|
I(() => {
|
|
374
|
-
const e =
|
|
379
|
+
const e = _.current;
|
|
375
380
|
if (!e) return;
|
|
376
381
|
const t = (n) => {
|
|
377
382
|
const o = n.relatedTarget;
|
|
378
|
-
o && e.contains(o) ||
|
|
383
|
+
o && e.contains(o) || re(n);
|
|
379
384
|
};
|
|
380
385
|
return e.addEventListener("focusout", t), () => e.removeEventListener("focusout", t);
|
|
381
|
-
}, [
|
|
382
|
-
const
|
|
386
|
+
}, [re]);
|
|
387
|
+
const Ye = D(() => /* @__PURE__ */ W(rt, { open: Ee, modal: !1, onOpenChange: (e) => {
|
|
383
388
|
!e && w.current || i(e);
|
|
384
389
|
}, children: [
|
|
385
|
-
/* @__PURE__ */ g(
|
|
390
|
+
/* @__PURE__ */ g(ot, { asChild: !0, children: /* @__PURE__ */ g("button", { type: "button", tabIndex: -1, "aria-hidden": !0, style: {
|
|
386
391
|
position: "absolute",
|
|
387
392
|
inset: 0,
|
|
388
393
|
opacity: 0,
|
|
389
394
|
pointerEvents: "none"
|
|
390
395
|
}, onMouseDown: (e) => e.preventDefault() }) }),
|
|
391
|
-
|
|
392
|
-
/* @__PURE__ */ g(
|
|
396
|
+
he,
|
|
397
|
+
/* @__PURE__ */ g(st, { children: /* @__PURE__ */ g("div", { ref: le, onPointerDownCapture: () => {
|
|
393
398
|
w.current = !0;
|
|
394
399
|
}, onMouseDownCapture: (e) => {
|
|
395
400
|
e.preventDefault(), w.current = !0;
|
|
396
|
-
}, children: /* @__PURE__ */ W(
|
|
397
|
-
|
|
398
|
-
/* @__PURE__ */ W(
|
|
401
|
+
}, children: /* @__PURE__ */ W(at, { color: "secondary", inputRef: v, children: [
|
|
402
|
+
ye,
|
|
403
|
+
/* @__PURE__ */ W(dt, { paddingSize: "xxs", mt: -0.35, mx: -0.35, style: {
|
|
399
404
|
borderWidth: "2px"
|
|
400
405
|
}, children: [
|
|
401
|
-
|
|
402
|
-
!!
|
|
403
|
-
|
|
406
|
+
ne?.length === 0 && xe,
|
|
407
|
+
!!ne?.length && /* @__PURE__ */ g(
|
|
408
|
+
ut,
|
|
404
409
|
{
|
|
405
410
|
ref: F,
|
|
406
|
-
inputRef:
|
|
407
|
-
suggestions:
|
|
408
|
-
onSuggestionSelect:
|
|
411
|
+
inputRef: v,
|
|
412
|
+
suggestions: ne,
|
|
413
|
+
onSuggestionSelect: Oe
|
|
409
414
|
}
|
|
410
415
|
)
|
|
411
416
|
] }),
|
|
412
|
-
|
|
417
|
+
Se
|
|
413
418
|
] }) }) })
|
|
414
|
-
] }), [Ee,
|
|
419
|
+
] }), [Ee, he, s, ne, ye, Se, xe, Oe, v, i]);
|
|
415
420
|
return /* @__PURE__ */ W("div", { children: [
|
|
416
|
-
U && /* @__PURE__ */ g(
|
|
417
|
-
T && /* @__PURE__ */ g(
|
|
418
|
-
/* @__PURE__ */ W("div", { ref:
|
|
419
|
-
H && /* @__PURE__ */ g("div", { className: `input__left input__left--${
|
|
420
|
-
f ?
|
|
421
|
-
|
|
421
|
+
U && /* @__PURE__ */ g(et, { children: U }),
|
|
422
|
+
T && /* @__PURE__ */ g(tt, { children: T }),
|
|
423
|
+
/* @__PURE__ */ W("div", { ref: _, ...me(`input ${P?.valid ? "" : "input--not-valid"}`, Q), onPointerDown: Xe, children: [
|
|
424
|
+
H && /* @__PURE__ */ g("div", { className: `input__left input__left--${Ne}`, children: H }),
|
|
425
|
+
f ? Ye : he,
|
|
426
|
+
G && /* @__PURE__ */ g("div", { className: `input__right input__right--${ze}`, children: G })
|
|
422
427
|
] }),
|
|
423
|
-
!
|
|
428
|
+
!P?.valid && P?.notValidMessage && /* @__PURE__ */ g(nt, { children: P.notValidMessage })
|
|
424
429
|
] });
|
|
425
|
-
}), Lt =
|
|
430
|
+
}), Lt = mt;
|
|
426
431
|
export {
|
|
427
432
|
Lt as Input
|
|
428
433
|
};
|