@pathscale/ui 1.1.50 → 1.1.52
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/field-error/FieldError.d.ts +3 -3
- package/dist/components/field-error/FieldError.js +11 -11
- package/dist/components/floating-dock/FloatingDock.css +1 -1
- package/dist/components/form/Form.d.ts +0 -6
- package/dist/hooks/form/index.d.ts +0 -6
- package/dist/hooks/form/index.js +1 -12
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -6
- package/dist/purge-manifest.json +2281 -2281
- package/dist/styles/icons/generated-icons.css +63 -1
- package/package.json +2 -12
- package/dist/hooks/form/useField.d.ts +0 -11
- package/dist/hooks/form/useField.js +0 -20
- package/dist/hooks/form/useFieldError.d.ts +0 -3
- package/dist/hooks/form/useFieldError.js +0 -3
- package/dist/hooks/form/useFieldMeta.d.ts +0 -20
- package/dist/hooks/form/useFieldMeta.js +0 -49
- package/dist/hooks/form/useFieldProps.d.ts +0 -10
- package/dist/hooks/form/useFieldProps.js +0 -51
- package/dist/hooks/form/useForm.d.ts +0 -27
- package/dist/hooks/form/useForm.js +0 -59
- package/dist/hooks/form/utils.d.ts +0 -4
- package/dist/hooks/form/utils.js +0 -30
|
@@ -1 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
.iconify {
|
|
3
|
+
display: inline-block;
|
|
4
|
+
width: 1em;
|
|
5
|
+
height: 1em;
|
|
6
|
+
background-color: currentColor;
|
|
7
|
+
-webkit-mask-repeat: no-repeat;
|
|
8
|
+
mask-repeat: no-repeat;
|
|
9
|
+
-webkit-mask-size: 100% 100%;
|
|
10
|
+
mask-size: 100% 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.iconify-color {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
width: 1em;
|
|
16
|
+
height: 1em;
|
|
17
|
+
background-repeat: no-repeat;
|
|
18
|
+
background-size: 100% 100%;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.icon-[mdi--close] {
|
|
22
|
+
--svg: url("data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M19%206.41%2017.59%205%2012%2010.59%206.41%205%205%206.41%2010.59%2012%205%2017.59%206.41%2019%2012%2013.41%2017.59%2019%2019%2017.59%2013.41%2012z%22%2F%3E%3C%2Fsvg%3E");
|
|
23
|
+
}
|
|
24
|
+
.icon-[mdi--close].iconify {
|
|
25
|
+
-webkit-mask-image: var(--svg);
|
|
26
|
+
mask-image: var(--svg);
|
|
27
|
+
}
|
|
28
|
+
.icon-[mdi--close].iconify-color {
|
|
29
|
+
background-image: var(--svg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.icon-[mdi--firefox] {
|
|
33
|
+
--svg: url("data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M6.85%206.74q.015%200%200%200M21.28%208.6c-.43-1.05-1.32-2.18-2.01-2.54.56%201.11.89%202.22%201.02%203.04v.02c-1.13-2.82-3.05-3.96-4.62-6.44-.08-.12-.17-.25-.24-.38-.04-.07-.07-.14-.11-.21-.06-.13-.12-.26-.15-.4%200-.01-.01-.02-.02-.02h-.03c-2.22%201.3-3.15%203.59-3.38%205.04-.69.04-1.37.21-1.99.51-.12.05-.17.19-.13.31.05.14.21.21.34.15.54-.26%201.14-.41%201.74-.45h.05c.08-.01.17-.01.25-.01.5-.01.97.06%201.44.2l.06.02c.1.02.17.06.25.06.05.04.11.06.16.08l.14.06c.07.03.14.06.2.09.03.02.06.03.09.05.07.04.16.07.2.11.04.02.08.05.12.07.73.45%201.34%201.07%201.75%201.81-.53-.37-1.49-.74-2.41-.58%203.6%201.81%202.63%208-2.36%207.76-.44-.01-.88-.1-1.3-.25-.1-.03-.2-.07-.29-.12-.05-.02-.12-.05-.17-.08-1.23-.63-2.24-1.82-2.38-3.27%200%200%20.5-1.73%203.33-1.73.31%200%201.17-.86%201.2-1.1%200-.09-1.74-.78-2.42-1.45-.37-.36-.54-.53-.69-.66-.08-.07-.17-.13-.26-.19a4.63%204.63%200%200%201-.03-2.45C7.6%206.12%206.8%206.86%206.22%207.5c-.4-.5-.37-2.15-.35-2.5-.01%200-.3.16-.33.18-.35.25-.68.53-.98.82-.35.37-.66.74-.94%201.14-.62.91-1.12%201.95-1.34%203.04%200%20.01-.1.41-.17.92l-.03.23c-.02.17-.04.32-.08.58v.41c0%205.53%204.5%2010.01%2010%2010.01%204.97%200%209.08-3.59%209.88-8.33.02-.11.03-.24.05-.37.2-1.72-.02-3.52-.65-5.03%22%2F%3E%3C%2Fsvg%3E");
|
|
34
|
+
}
|
|
35
|
+
.icon-[mdi--firefox].iconify {
|
|
36
|
+
-webkit-mask-image: var(--svg);
|
|
37
|
+
mask-image: var(--svg);
|
|
38
|
+
}
|
|
39
|
+
.icon-[mdi--firefox].iconify-color {
|
|
40
|
+
background-image: var(--svg);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.icon-[mdi--loading] {
|
|
44
|
+
--svg: url("data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M12%204V2A10%2010%200%200%200%202%2012h2a8%208%200%200%201%208-8%22%2F%3E%3C%2Fsvg%3E");
|
|
45
|
+
}
|
|
46
|
+
.icon-[mdi--loading].iconify {
|
|
47
|
+
-webkit-mask-image: var(--svg);
|
|
48
|
+
mask-image: var(--svg);
|
|
49
|
+
}
|
|
50
|
+
.icon-[mdi--loading].iconify-color {
|
|
51
|
+
background-image: var(--svg);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.icon-[mdi--palette] {
|
|
55
|
+
--svg: url("data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M17.5%2012a1.5%201.5%200%200%201-1.5-1.5A1.5%201.5%200%200%201%2017.5%209a1.5%201.5%200%200%201%201.5%201.5%201.5%201.5%200%200%201-1.5%201.5m-3-4A1.5%201.5%200%200%201%2013%206.5%201.5%201.5%200%200%201%2014.5%205%201.5%201.5%200%200%201%2016%206.5%201.5%201.5%200%200%201%2014.5%208m-5%200A1.5%201.5%200%200%201%208%206.5%201.5%201.5%200%200%201%209.5%205%201.5%201.5%200%200%201%2011%206.5%201.5%201.5%200%200%201%209.5%208m-3%204A1.5%201.5%200%200%201%205%2010.5%201.5%201.5%200%200%201%206.5%209%201.5%201.5%200%200%201%208%2010.5%201.5%201.5%200%200%201%206.5%2012M12%203a9%209%200%200%200-9%209%209%209%200%200%200%209%209%201.5%201.5%200%200%200%201.5-1.5c0-.39-.15-.74-.39-1-.23-.27-.38-.62-.38-1a1.5%201.5%200%200%201%201.5-1.5H16a5%205%200%200%200%205-5c0-4.42-4.03-8-9-8%22%2F%3E%3C%2Fsvg%3E");
|
|
56
|
+
}
|
|
57
|
+
.icon-[mdi--palette].iconify {
|
|
58
|
+
-webkit-mask-image: var(--svg);
|
|
59
|
+
mask-image: var(--svg);
|
|
60
|
+
}
|
|
61
|
+
.icon-[mdi--palette].iconify-color {
|
|
62
|
+
background-image: var(--svg);
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pathscale/ui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.52",
|
|
4
4
|
"author": "pathscale",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@biomejs/biome": "1.9.4",
|
|
56
|
-
"@felte/solid": "^1.2.11",
|
|
57
56
|
"@iconify/json": "^2.2.342",
|
|
58
57
|
"@iconify/utils": "^2.3.0",
|
|
59
58
|
"@rsbuild/core": "^1.3.20",
|
|
@@ -89,11 +88,9 @@
|
|
|
89
88
|
"@iconify/tailwind4": "^1.2.1",
|
|
90
89
|
"@pathscale/ui": "^1.1.11",
|
|
91
90
|
"@tanstack/solid-virtual": "^3.13.23",
|
|
92
|
-
"valibot": "^1.0.0",
|
|
93
91
|
"rsbuild-plugin-iconify": "^1.0.3"
|
|
94
92
|
},
|
|
95
93
|
"peerDependencies": {
|
|
96
|
-
"@felte/solid": "^1.2.0",
|
|
97
94
|
"@solid-primitives/event-listener": "^2.3.0",
|
|
98
95
|
"@solid-primitives/intersection-observer": "^2.1.3",
|
|
99
96
|
"@solid-primitives/keyboard": "^1.2.5",
|
|
@@ -108,21 +105,14 @@
|
|
|
108
105
|
"@tanstack/solid-form": "^1.29.0",
|
|
109
106
|
"@tanstack/solid-table": "^8.0.0",
|
|
110
107
|
"popmotion": "^11.0.5",
|
|
111
|
-
"solid-js": "^1.9"
|
|
112
|
-
"valibot": "^1.0.0"
|
|
108
|
+
"solid-js": "^1.9"
|
|
113
109
|
},
|
|
114
110
|
"peerDependenciesMeta": {
|
|
115
|
-
"@felte/solid": {
|
|
116
|
-
"optional": true
|
|
117
|
-
},
|
|
118
111
|
"@standard-schema/spec": {
|
|
119
112
|
"optional": true
|
|
120
113
|
},
|
|
121
114
|
"popmotion": {
|
|
122
115
|
"optional": true
|
|
123
|
-
},
|
|
124
|
-
"valibot": {
|
|
125
|
-
"optional": true
|
|
126
116
|
}
|
|
127
117
|
},
|
|
128
118
|
"scripts": {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type Accessor } from "solid-js";
|
|
2
|
-
import { type FieldName, type UseFieldOptions } from "./useFieldMeta";
|
|
3
|
-
export type UseFieldResult = {
|
|
4
|
-
name: Accessor<string | undefined>;
|
|
5
|
-
value: Accessor<unknown>;
|
|
6
|
-
error: Accessor<string | undefined>;
|
|
7
|
-
touched: Accessor<boolean>;
|
|
8
|
-
invalid: Accessor<boolean>;
|
|
9
|
-
setValue: (value: unknown) => void;
|
|
10
|
-
};
|
|
11
|
-
export declare const useField: (name: FieldName, options?: UseFieldOptions) => UseFieldResult;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__ from "solid-js";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE__useFieldMeta_js_65e8362d__ from "./useFieldMeta.js";
|
|
3
|
-
const useField = (name, options = {})=>{
|
|
4
|
-
const meta = (0, __WEBPACK_EXTERNAL_MODULE__useFieldMeta_js_65e8362d__.useFieldMeta)(name, options);
|
|
5
|
-
const setValue = (value)=>{
|
|
6
|
-
const form = meta.controller();
|
|
7
|
-
const fieldName = meta.name();
|
|
8
|
-
if (!form || !fieldName) return;
|
|
9
|
-
form.setFieldValue(fieldName, value);
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
name: meta.name,
|
|
13
|
-
value: meta.value,
|
|
14
|
-
error: meta.error,
|
|
15
|
-
touched: meta.touched,
|
|
16
|
-
invalid: (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>meta.invalid()),
|
|
17
|
-
setValue
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export { useField };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type Accessor } from "solid-js";
|
|
2
|
-
import { type FormController } from "./useForm";
|
|
3
|
-
type AnyFormController = FormController<Record<string, unknown>>;
|
|
4
|
-
export type FieldName = string | Accessor<string | undefined>;
|
|
5
|
-
export type UseFieldOptions = {
|
|
6
|
-
form?: AnyFormController | Accessor<AnyFormController | undefined>;
|
|
7
|
-
element?: Accessor<Element | undefined>;
|
|
8
|
-
showWhenTouched?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type UseFieldMetaResult = {
|
|
11
|
-
controller: Accessor<AnyFormController | undefined>;
|
|
12
|
-
name: Accessor<string | undefined>;
|
|
13
|
-
value: Accessor<unknown>;
|
|
14
|
-
rawError: Accessor<string | undefined>;
|
|
15
|
-
error: Accessor<string | undefined>;
|
|
16
|
-
touched: Accessor<boolean>;
|
|
17
|
-
invalid: Accessor<boolean>;
|
|
18
|
-
};
|
|
19
|
-
export declare const useFieldMeta: (name: FieldName, options?: UseFieldOptions) => UseFieldMetaResult;
|
|
20
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__ from "solid-js";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_e31b00cd__ from "./useForm.js";
|
|
3
|
-
import * as __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__ from "./utils.js";
|
|
4
|
-
const isFormController = (value)=>{
|
|
5
|
-
if ("function" != typeof value) return false;
|
|
6
|
-
const candidate = value;
|
|
7
|
-
return "function" == typeof candidate.errors && "function" == typeof candidate.touched && "function" == typeof candidate.data && "function" == typeof candidate.setFieldValue;
|
|
8
|
-
};
|
|
9
|
-
const resolveFieldName = (name)=>{
|
|
10
|
-
if ("function" == typeof name) return name;
|
|
11
|
-
return ()=>name;
|
|
12
|
-
};
|
|
13
|
-
const readFieldState = (form, name, reader)=>{
|
|
14
|
-
if (!form || !name) return;
|
|
15
|
-
return reader(name);
|
|
16
|
-
};
|
|
17
|
-
const useFieldMeta = (name, options = {})=>{
|
|
18
|
-
const nameAccessor = resolveFieldName(name);
|
|
19
|
-
const showWhenTouched = options.showWhenTouched ?? true;
|
|
20
|
-
const controller = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>{
|
|
21
|
-
if (options.form) {
|
|
22
|
-
if (isFormController(options.form)) return options.form;
|
|
23
|
-
return options.form();
|
|
24
|
-
}
|
|
25
|
-
const currentElement = options.element?.();
|
|
26
|
-
if (!currentElement) return;
|
|
27
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_e31b00cd__.getFormControllerFromElement)(currentElement);
|
|
28
|
-
});
|
|
29
|
-
const value = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>readFieldState(controller(), nameAccessor(), (path)=>controller()?.data(path)));
|
|
30
|
-
const touched = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>Boolean(readFieldState(controller(), nameAccessor(), (path)=>controller()?.touched(path))));
|
|
31
|
-
const rawError = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.normalizeFieldError)(readFieldState(controller(), nameAccessor(), (path)=>controller()?.errors(path))));
|
|
32
|
-
const error = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>{
|
|
33
|
-
const message = rawError();
|
|
34
|
-
if (!message) return;
|
|
35
|
-
if (!showWhenTouched) return message;
|
|
36
|
-
return touched() ? message : void 0;
|
|
37
|
-
});
|
|
38
|
-
const invalid = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>Boolean(error()));
|
|
39
|
-
return {
|
|
40
|
-
controller,
|
|
41
|
-
name: nameAccessor,
|
|
42
|
-
value,
|
|
43
|
-
rawError,
|
|
44
|
-
error,
|
|
45
|
-
touched,
|
|
46
|
-
invalid
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export { useFieldMeta };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { JSX } from "solid-js";
|
|
2
|
-
import { type FieldName, type UseFieldOptions } from "./useFieldMeta";
|
|
3
|
-
export type UseFieldPropsResult = {
|
|
4
|
-
name: () => string | undefined;
|
|
5
|
-
value: () => unknown;
|
|
6
|
-
onInput: JSX.EventHandlerUnion<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, InputEvent>;
|
|
7
|
-
onChange: (valueOrEvent: unknown) => void;
|
|
8
|
-
onBlur: JSX.EventHandlerUnion<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, FocusEvent>;
|
|
9
|
-
};
|
|
10
|
-
export declare const useFieldProps: (name: FieldName, options?: UseFieldOptions) => UseFieldPropsResult;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE__useFieldMeta_js_65e8362d__ from "./useFieldMeta.js";
|
|
2
|
-
const isEventLike = (value)=>value instanceof Event;
|
|
3
|
-
const getValueFromInputLikeEvent = (event)=>{
|
|
4
|
-
const currentTarget = event.currentTarget;
|
|
5
|
-
const target = event.target;
|
|
6
|
-
const element = currentTarget instanceof Element ? currentTarget : target instanceof Element ? target : void 0;
|
|
7
|
-
if (!element) return;
|
|
8
|
-
if (element instanceof HTMLInputElement) {
|
|
9
|
-
if ("checkbox" === element.type || "radio" === element.type) return element.checked;
|
|
10
|
-
return element.value;
|
|
11
|
-
}
|
|
12
|
-
if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) return element.value;
|
|
13
|
-
};
|
|
14
|
-
const useFieldProps = (name, options = {})=>{
|
|
15
|
-
const meta = (0, __WEBPACK_EXTERNAL_MODULE__useFieldMeta_js_65e8362d__.useFieldMeta)(name, options);
|
|
16
|
-
const setValue = (nextValue)=>{
|
|
17
|
-
const form = meta.controller();
|
|
18
|
-
const fieldName = meta.name();
|
|
19
|
-
if (!form || !fieldName) return;
|
|
20
|
-
form.setFieldValue(fieldName, nextValue);
|
|
21
|
-
};
|
|
22
|
-
const markTouched = ()=>{
|
|
23
|
-
const form = meta.controller();
|
|
24
|
-
const fieldName = meta.name();
|
|
25
|
-
if (!form || !fieldName) return;
|
|
26
|
-
form.setTouched(fieldName, true);
|
|
27
|
-
};
|
|
28
|
-
const onInput = (event)=>{
|
|
29
|
-
const nextValue = getValueFromInputLikeEvent(event) ?? event.currentTarget.value;
|
|
30
|
-
setValue(nextValue);
|
|
31
|
-
};
|
|
32
|
-
const onChange = (valueOrEvent)=>{
|
|
33
|
-
if (isEventLike(valueOrEvent)) {
|
|
34
|
-
const extractedValue = getValueFromInputLikeEvent(valueOrEvent);
|
|
35
|
-
setValue(extractedValue);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
setValue(valueOrEvent);
|
|
39
|
-
};
|
|
40
|
-
const onBlur = ()=>{
|
|
41
|
-
markTouched();
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
name: meta.name,
|
|
45
|
-
value: meta.value,
|
|
46
|
-
onInput,
|
|
47
|
-
onChange,
|
|
48
|
-
onBlur
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
export { useFieldProps };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type GenericSchema } from "valibot";
|
|
2
|
-
import type { ObjectSetter, Paths } from "@felte/common";
|
|
3
|
-
import type { Accessor } from "solid-js";
|
|
4
|
-
type AnyValues = Record<string, unknown>;
|
|
5
|
-
export type FormPathQuery<TValues extends AnyValues = AnyValues> = string | ((data: TValues) => unknown);
|
|
6
|
-
export type FormDirective = (element: HTMLFormElement, accessor?: Accessor<unknown>) => void | (() => void);
|
|
7
|
-
export type UseFormOptions<TValues extends AnyValues = AnyValues> = {
|
|
8
|
-
schema?: GenericSchema;
|
|
9
|
-
initialValues?: TValues;
|
|
10
|
-
onSubmit?: (values: TValues) => void | Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
export type FormController<TValues extends AnyValues = AnyValues> = FormDirective & {
|
|
13
|
-
errors: (path?: FormPathQuery<TValues>) => unknown;
|
|
14
|
-
touched: (path?: FormPathQuery<TValues>) => unknown;
|
|
15
|
-
data: (path?: FormPathQuery<TValues>) => unknown;
|
|
16
|
-
isValid: () => boolean;
|
|
17
|
-
isSubmitting: () => boolean;
|
|
18
|
-
setData: ObjectSetter<TValues, Paths<TValues>>;
|
|
19
|
-
setErrors: (...args: unknown[]) => unknown;
|
|
20
|
-
setWarnings: (...args: unknown[]) => unknown;
|
|
21
|
-
setTouched: (...args: unknown[]) => unknown;
|
|
22
|
-
reset: () => void;
|
|
23
|
-
setFieldValue: (name: string, value: unknown) => void;
|
|
24
|
-
};
|
|
25
|
-
export declare const getFormControllerFromElement: (element?: Element | null) => FormController<AnyValues> | undefined;
|
|
26
|
-
export declare const useForm: <TValues extends AnyValues = AnyValues>(options?: UseFormOptions<TValues>) => FormController<TValues>;
|
|
27
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE__felte_solid_6a709b1d__ from "@felte/solid";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE_valibot__ from "valibot";
|
|
3
|
-
const FORM_CONTROLLER_REGISTRY = new WeakMap();
|
|
4
|
-
const getClosestFormElement = (element)=>{
|
|
5
|
-
if (!element) return;
|
|
6
|
-
if (element instanceof HTMLFormElement) return element;
|
|
7
|
-
const closest = element.closest("form");
|
|
8
|
-
if (closest instanceof HTMLFormElement) return closest;
|
|
9
|
-
};
|
|
10
|
-
const getFormControllerFromElement = (element)=>{
|
|
11
|
-
const formElement = getClosestFormElement(element);
|
|
12
|
-
if (!formElement) return;
|
|
13
|
-
return FORM_CONTROLLER_REGISTRY.get(formElement);
|
|
14
|
-
};
|
|
15
|
-
const useForm = (options = {})=>{
|
|
16
|
-
const formConfig = {
|
|
17
|
-
initialValues: options.initialValues,
|
|
18
|
-
onSubmit: async (values)=>{
|
|
19
|
-
await options.onSubmit?.(values);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
if (options.schema) formConfig.validate = (values)=>{
|
|
23
|
-
const result = (0, __WEBPACK_EXTERNAL_MODULE_valibot__.safeParse)(options.schema, values);
|
|
24
|
-
if (result.success) return;
|
|
25
|
-
const errors = {};
|
|
26
|
-
for (const issue of result.issues)if (issue.path) {
|
|
27
|
-
const path = issue.path.map((p)=>p.key).join(".");
|
|
28
|
-
if (!errors[path]) errors[path] = issue.message;
|
|
29
|
-
}
|
|
30
|
-
return errors;
|
|
31
|
-
};
|
|
32
|
-
const { form: felteForm, errors, touched, data, isValid, isSubmitting, setData, setErrors, setWarnings, setTouched, reset } = (0, __WEBPACK_EXTERNAL_MODULE__felte_solid_6a709b1d__.createForm)(formConfig);
|
|
33
|
-
let controller;
|
|
34
|
-
const directive = (element, accessor)=>{
|
|
35
|
-
FORM_CONTROLLER_REGISTRY.set(element, controller);
|
|
36
|
-
const cleanup = felteForm(element, accessor);
|
|
37
|
-
return ()=>{
|
|
38
|
-
FORM_CONTROLLER_REGISTRY.delete(element);
|
|
39
|
-
if ("function" == typeof cleanup) cleanup();
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
controller = Object.assign(directive, {
|
|
43
|
-
errors,
|
|
44
|
-
touched,
|
|
45
|
-
data,
|
|
46
|
-
isValid,
|
|
47
|
-
isSubmitting,
|
|
48
|
-
setData,
|
|
49
|
-
setErrors,
|
|
50
|
-
setWarnings,
|
|
51
|
-
setTouched,
|
|
52
|
-
reset,
|
|
53
|
-
setFieldValue: (name, value)=>{
|
|
54
|
-
setData(name, value);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return controller;
|
|
58
|
-
};
|
|
59
|
-
export { getFormControllerFromElement, useForm };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Accessor } from "solid-js";
|
|
2
|
-
export declare const isAccessor: <T>(value: unknown) => value is Accessor<T>;
|
|
3
|
-
export declare const toAccessor: <T>(value: T | Accessor<T>) => Accessor<T>;
|
|
4
|
-
export declare const normalizeFieldError: (value: unknown) => string | undefined;
|
package/dist/hooks/form/utils.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const isAccessor = (value)=>"function" == typeof value;
|
|
2
|
-
const toAccessor = (value)=>{
|
|
3
|
-
if (isAccessor(value)) return value;
|
|
4
|
-
return ()=>value;
|
|
5
|
-
};
|
|
6
|
-
const normalizeFieldError = (value)=>{
|
|
7
|
-
if ("string" == typeof value) {
|
|
8
|
-
const trimmed = value.trim();
|
|
9
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(value)) {
|
|
12
|
-
for (const item of value){
|
|
13
|
-
const normalized = normalizeFieldError(item);
|
|
14
|
-
if (normalized) return normalized;
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (value && "object" == typeof value) {
|
|
19
|
-
const maybeMessage = value.message;
|
|
20
|
-
if ("string" == typeof maybeMessage) {
|
|
21
|
-
const trimmed = maybeMessage.trim();
|
|
22
|
-
if (trimmed.length > 0) return trimmed;
|
|
23
|
-
}
|
|
24
|
-
for (const nested of Object.values(value)){
|
|
25
|
-
const normalized = normalizeFieldError(nested);
|
|
26
|
-
if (normalized) return normalized;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export { isAccessor, normalizeFieldError, toAccessor };
|