@prokodo/ui 0.0.43 → 0.0.45
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/base-link/BaseLink.view.js +16 -6
- package/dist/components/dynamic-list/DynamicList.client.js +53 -6
- package/dist/components/dynamic-list/DynamicList.view.js +39 -18
- package/dist/components/form/FormField.server.js +1 -1
- package/dist/components/input/Input.view.js +3 -2
- package/dist/components/select/Select.client.js +10 -1
- package/dist/components/select/Select.module.scss.js +1 -0
- package/dist/components/select/Select.view.js +4 -1
- package/dist/constants/project.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/components/dynamic-list/DynamicList.model.d.ts +10 -1
- package/dist/types/components/dynamic-list/DynamicList.view.d.ts +1 -3
- package/dist/types/components/select/Select.model.d.ts +6 -1
- package/dist/types/components/select/Select.view.d.ts +1 -1
- package/dist/ui.css +360 -357
- package/package.json +1 -1
|
@@ -15,16 +15,26 @@ function BaseLinkView({
|
|
|
15
15
|
let finalHref = href ?? "#";
|
|
16
16
|
let kind = "local";
|
|
17
17
|
if (href) {
|
|
18
|
-
|
|
18
|
+
const hasProtocol = href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//");
|
|
19
|
+
const isLocalPath = href.startsWith("/") || href.startsWith("#") || href.startsWith("?");
|
|
20
|
+
const appProto = /^\w+:/.test(href);
|
|
21
|
+
if (hasProtocol || appProto) {
|
|
19
22
|
kind = "url";
|
|
23
|
+
} else if (isLocalPath) {
|
|
24
|
+
kind = "local";
|
|
20
25
|
} else if (emailRE.test(href)) {
|
|
21
26
|
kind = "email";
|
|
22
|
-
finalHref = `mailto:${href
|
|
27
|
+
finalHref = `mailto:${href}`;
|
|
23
28
|
} else {
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const phoneLikeRE = /^\+?\d[\d\s().-]*$/;
|
|
30
|
+
if (phoneLikeRE.test(href)) {
|
|
31
|
+
const digits = href.replace(/[^\d]/g, "");
|
|
32
|
+
if (digits.length >= 6) {
|
|
33
|
+
kind = "tel";
|
|
34
|
+
finalHref = `tel:+${digits}`;
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
kind = "local";
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import { memo, useState, useEffect, useCallback } from "react";
|
|
5
|
+
import { memo, useState, useEffect, useCallback, useMemo } from "react";
|
|
6
6
|
import { isString } from "../../helpers/validations.js";
|
|
7
7
|
import { DynamicListView } from "./DynamicList.view.js";
|
|
8
8
|
function DynamicListClient({
|
|
@@ -38,11 +38,32 @@ function DynamicListClient({
|
|
|
38
38
|
},
|
|
39
39
|
[items, onChange, isSingle]
|
|
40
40
|
);
|
|
41
|
+
const handleSelectChange = useCallback(
|
|
42
|
+
(idx, fieldName, v) => {
|
|
43
|
+
const nextValue = Array.isArray(v) ? String(v[0] ?? "") : v === null ? "" : String(v);
|
|
44
|
+
const next = items.map((it, i) => {
|
|
45
|
+
if (i !== idx) return it;
|
|
46
|
+
if (isSingle) {
|
|
47
|
+
return nextValue === "" ? "" : nextValue;
|
|
48
|
+
}
|
|
49
|
+
const obj = { ...it };
|
|
50
|
+
if (nextValue === "") {
|
|
51
|
+
delete obj[fieldName];
|
|
52
|
+
} else {
|
|
53
|
+
obj[fieldName] = nextValue;
|
|
54
|
+
}
|
|
55
|
+
return obj;
|
|
56
|
+
});
|
|
57
|
+
setItems(next);
|
|
58
|
+
onChange == null ? void 0 : onChange(next);
|
|
59
|
+
},
|
|
60
|
+
[items, onChange, isSingle]
|
|
61
|
+
);
|
|
41
62
|
const handleAdd = useCallback(
|
|
42
63
|
(e) => {
|
|
43
64
|
var _a;
|
|
44
65
|
const empty = isSingle ? "" : fields.reduce((obj, f) => {
|
|
45
|
-
obj[f.name] = "";
|
|
66
|
+
obj[(f == null ? void 0 : f.name) ?? ""] = "";
|
|
46
67
|
return obj;
|
|
47
68
|
}, {});
|
|
48
69
|
const next = [...items, empty];
|
|
@@ -64,11 +85,40 @@ function DynamicListClient({
|
|
|
64
85
|
},
|
|
65
86
|
[items, onChange, buttonDeleteProps]
|
|
66
87
|
);
|
|
88
|
+
const formatedFields = useMemo(
|
|
89
|
+
() => (fields ?? []).map((f) => {
|
|
90
|
+
if (f.fieldType === "select") {
|
|
91
|
+
const { ...rest2 } = f;
|
|
92
|
+
const onChange2 = /* @__PURE__ */ __name((e, v) => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const idx = Number(
|
|
95
|
+
(_b = (_a = e == null ? void 0 : e.target) == null ? void 0 : _a.dataset) == null ? void 0 : _b.index
|
|
96
|
+
);
|
|
97
|
+
if (!Number.isNaN(idx)) {
|
|
98
|
+
handleSelectChange(idx, rest2.name ?? "", v);
|
|
99
|
+
}
|
|
100
|
+
}, "onChange2");
|
|
101
|
+
return {
|
|
102
|
+
fieldType: "select",
|
|
103
|
+
...rest2,
|
|
104
|
+
onChange: onChange2
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const { ...rest } = f;
|
|
108
|
+
return {
|
|
109
|
+
fieldType: "input",
|
|
110
|
+
...rest,
|
|
111
|
+
onChange: handleChange
|
|
112
|
+
// matches InputChangeEventHandler
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
[fields, handleChange, handleSelectChange]
|
|
116
|
+
);
|
|
67
117
|
return /* @__PURE__ */ jsx(
|
|
68
118
|
DynamicListView,
|
|
69
119
|
{
|
|
70
120
|
...props,
|
|
71
|
-
fields,
|
|
121
|
+
fields: formatedFields,
|
|
72
122
|
value: items,
|
|
73
123
|
buttonAddProps: {
|
|
74
124
|
...buttonAddProps,
|
|
@@ -77,9 +127,6 @@ function DynamicListClient({
|
|
|
77
127
|
buttonDeleteProps: {
|
|
78
128
|
...buttonDeleteProps,
|
|
79
129
|
onClick: handleDelete
|
|
80
|
-
},
|
|
81
|
-
fieldProps: {
|
|
82
|
-
onChange: handleChange
|
|
83
130
|
}
|
|
84
131
|
}
|
|
85
132
|
);
|
|
@@ -5,6 +5,7 @@ import { create } from "../../helpers/bem.js";
|
|
|
5
5
|
import { isString } from "../../helpers/validations.js";
|
|
6
6
|
import styles from "./DynamicList.module.scss.js";
|
|
7
7
|
import { Input } from "../input/Input.js";
|
|
8
|
+
import { Select } from "../select/Select.js";
|
|
8
9
|
import { Button } from "../button/Button.js";
|
|
9
10
|
import { Label } from "../label/Label.js";
|
|
10
11
|
const bem = create(styles, "DynamicList");
|
|
@@ -18,7 +19,6 @@ function DynamicListView({
|
|
|
18
19
|
classNameList,
|
|
19
20
|
fields,
|
|
20
21
|
value = [],
|
|
21
|
-
fieldProps,
|
|
22
22
|
buttonAddProps,
|
|
23
23
|
buttonDeleteProps,
|
|
24
24
|
name = "items",
|
|
@@ -57,23 +57,44 @@ function DynamicListView({
|
|
|
57
57
|
"aria-describedby": errorId ?? helperId,
|
|
58
58
|
className: bem("list", mod, classNameList),
|
|
59
59
|
children: [
|
|
60
|
-
/* @__PURE__ */ jsx("li", { className: bem("list__item"), children: fields.map((field) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
60
|
+
/* @__PURE__ */ jsx("li", { className: bem("list__item"), children: fields.map(({ fieldType, ...field }) => {
|
|
61
|
+
switch (fieldType) {
|
|
62
|
+
case "select":
|
|
63
|
+
return /* @__PURE__ */ jsx(
|
|
64
|
+
Select,
|
|
65
|
+
{
|
|
66
|
+
fullWidth: true,
|
|
67
|
+
...field,
|
|
68
|
+
className: bem("field", mod, field == null ? void 0 : field.className),
|
|
69
|
+
"data-field": field == null ? void 0 : field.name,
|
|
70
|
+
"data-index": idx,
|
|
71
|
+
disabled: disabled ?? (field == null ? void 0 : field.disabled),
|
|
72
|
+
id: `${name}-${idx}-${field.name}`,
|
|
73
|
+
name: single ? `${name}[${idx}]` : `${name}[${idx}].${field.name}`,
|
|
74
|
+
required: required ?? (field == null ? void 0 : field.required),
|
|
75
|
+
value: single ? item : item[(field == null ? void 0 : field.name) ?? ""]
|
|
76
|
+
},
|
|
77
|
+
field.name
|
|
78
|
+
);
|
|
79
|
+
default:
|
|
80
|
+
return /* @__PURE__ */ jsx(
|
|
81
|
+
Input,
|
|
82
|
+
{
|
|
83
|
+
fullWidth: true,
|
|
84
|
+
...field,
|
|
85
|
+
className: bem("field", mod, field == null ? void 0 : field.className),
|
|
86
|
+
"data-field": field == null ? void 0 : field.name,
|
|
87
|
+
"data-index": idx,
|
|
88
|
+
disabled: disabled ?? (field == null ? void 0 : field.disabled),
|
|
89
|
+
id: `${name}-${idx}-${field.name}`,
|
|
90
|
+
required: required ?? (field == null ? void 0 : field.required),
|
|
91
|
+
value: single ? item : item[(field == null ? void 0 : field.name) ?? ""],
|
|
92
|
+
name: single ? `${name}[${idx}]` : `${name}[${idx}].${field.name}`
|
|
93
|
+
},
|
|
94
|
+
field.name
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}) }),
|
|
77
98
|
/* @__PURE__ */ jsx(
|
|
78
99
|
Button,
|
|
79
100
|
{
|
|
@@ -4,11 +4,11 @@ import { jsx } from "react/jsx-runtime";
|
|
|
4
4
|
import { create } from "../../helpers/bem.js";
|
|
5
5
|
import styles from "./FormField.module.scss.js";
|
|
6
6
|
import { DatePicker } from "../datePicker/DatePicker.js";
|
|
7
|
-
import { Select } from "../select/Select.js";
|
|
8
7
|
import { Slider } from "../slider/Slider.js";
|
|
9
8
|
import { Switch } from "../switch/Switch.js";
|
|
10
9
|
import { GridRow } from "../grid/GridRow.js";
|
|
11
10
|
import { Input } from "../input/Input.js";
|
|
11
|
+
import { Select } from "../select/Select.js";
|
|
12
12
|
const bem = create(styles, "FormField");
|
|
13
13
|
function FormFieldServer({
|
|
14
14
|
fieldType,
|
|
@@ -32,8 +32,9 @@ function InputView({
|
|
|
32
32
|
type = "text",
|
|
33
33
|
...rest
|
|
34
34
|
}) {
|
|
35
|
-
delete rest.onValidate;
|
|
36
|
-
delete rest.errorTranslations;
|
|
35
|
+
rest == null ? true : delete rest.onValidate;
|
|
36
|
+
rest == null ? true : delete rest.errorTranslations;
|
|
37
|
+
rest == null ? true : delete rest.customRegexPattern;
|
|
37
38
|
const isError = typeof errorText === "string";
|
|
38
39
|
const hasValue = value !== void 0 && value !== "" || Boolean(placeholder);
|
|
39
40
|
const hasHelperText = isString(helperText);
|
|
@@ -8,6 +8,7 @@ function isMulti(v) {
|
|
|
8
8
|
return Array.isArray(v);
|
|
9
9
|
}
|
|
10
10
|
__name(isMulti, "isMulti");
|
|
11
|
+
const toDatasetKey = /* @__PURE__ */ __name((k) => k.replace(/-([a-z])/g, (_, c) => c.toUpperCase()), "toDatasetKey");
|
|
11
12
|
function mergeValue(oldVal, newVal, multiple = false) {
|
|
12
13
|
return multiple ? (() => {
|
|
13
14
|
const s = new Set(isMulti(oldVal) ? oldVal : []);
|
|
@@ -63,10 +64,18 @@ function SelectClient({
|
|
|
63
64
|
setOpen(true);
|
|
64
65
|
}
|
|
65
66
|
}, "handleKey");
|
|
67
|
+
const dataset = (() => {
|
|
68
|
+
const d = {};
|
|
69
|
+
for (const [k, v] of Object.entries(rest)) {
|
|
70
|
+
if (k.startsWith("data-")) d[toDatasetKey(k.slice(5))] = v;
|
|
71
|
+
}
|
|
72
|
+
return d;
|
|
73
|
+
})();
|
|
66
74
|
const clickOption = /* @__PURE__ */ __name((opt) => {
|
|
67
75
|
const newVal = opt === null ? Boolean(multiple) ? [] : "" : mergeValue(val, opt, multiple);
|
|
76
|
+
const syntheticEvt = { target: { dataset } };
|
|
68
77
|
setVal(newVal);
|
|
69
|
-
onChange == null ? void 0 : onChange(
|
|
78
|
+
onChange == null ? void 0 : onChange(syntheticEvt, newVal);
|
|
70
79
|
if (!Boolean(multiple)) close();
|
|
71
80
|
}, "clickOption");
|
|
72
81
|
return /* @__PURE__ */ jsx(
|
|
@@ -3,6 +3,7 @@ const gradientMove = "gradientMove";
|
|
|
3
3
|
const fadeInKeyframe = "fadeInKeyframe";
|
|
4
4
|
const styles = {
|
|
5
5
|
"prokodo-Select": "prokodo-Select",
|
|
6
|
+
"prokodo-Select--fullWidth": "prokodo-Select--fullWidth",
|
|
6
7
|
"prokodo-Select__label": "prokodo-Select__label",
|
|
7
8
|
"prokodo-Select__field": "prokodo-Select__field",
|
|
8
9
|
"prokodo-Select__field--expanded": "prokodo-Select__field--expanded",
|
|
@@ -11,6 +11,7 @@ function SelectView({
|
|
|
11
11
|
disabled,
|
|
12
12
|
name = id,
|
|
13
13
|
label,
|
|
14
|
+
fullWidth = false,
|
|
14
15
|
hideLabel,
|
|
15
16
|
iconVisible,
|
|
16
17
|
placeholder = "-- Please choose --",
|
|
@@ -47,7 +48,9 @@ function SelectView({
|
|
|
47
48
|
idx < selectedItems.length - 1 && ", "
|
|
48
49
|
] }, i == null ? void 0 : i.label);
|
|
49
50
|
}) });
|
|
50
|
-
return /* @__PURE__ */ jsxs("div", { className: bem(void 0,
|
|
51
|
+
return /* @__PURE__ */ jsxs("div", { className: bem(void 0, {
|
|
52
|
+
fullWidth: Boolean(fullWidth)
|
|
53
|
+
}, className), children: [
|
|
51
54
|
!Boolean(hideLabel) && /* @__PURE__ */ jsx(
|
|
52
55
|
Label,
|
|
53
56
|
{
|