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