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