@ultraviolet/form 2.13.4 → 2.13.6
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/CheckboxField/index.cjs +53 -0
- package/dist/components/CheckboxGroupField/index.cjs +75 -0
- package/dist/components/DateField/index.cjs +74 -0
- package/dist/components/Form/defaultErrors.cjs +22 -0
- package/dist/components/Form/index.cjs +72 -0
- package/dist/components/KeyValueField/index.cjs +51 -0
- package/dist/components/NumberInputField/index.cjs +56 -0
- package/dist/components/NumberInputFieldV2/index.cjs +63 -0
- package/dist/components/RadioField/index.cjs +49 -0
- package/dist/components/RadioGroupField/index.cjs +45 -0
- package/dist/components/SelectInputField/index.cjs +102 -0
- package/dist/components/SelectInputFieldV2/index.cjs +70 -0
- package/dist/components/SelectableCardField/index.cjs +58 -0
- package/dist/components/SelectableCardGroupField/index.cjs +56 -0
- package/dist/components/Submit/index.cjs +26 -0
- package/dist/components/SubmitErrorAlert/index.cjs +14 -0
- package/dist/components/TagInputField/index.cjs +50 -0
- package/dist/components/TextAreaField/index.cjs +70 -0
- package/dist/components/TextInputField/index.cjs +114 -0
- package/dist/components/TextInputFieldV2/index.cjs +79 -0
- package/dist/components/TimeField/index.cjs +66 -0
- package/dist/components/ToggleField/index.cjs +47 -0
- package/dist/constants.cjs +4 -0
- package/dist/hooks/useField.cjs +30 -0
- package/dist/hooks/useFieldArray.cjs +32 -0
- package/dist/hooks/useForm.cjs +24 -0
- package/dist/hooks/useFormState.cjs +22 -0
- package/dist/hooks/useOnFieldChange.cjs +21 -0
- package/dist/index.cjs +84 -0
- package/dist/providers/ErrorContext/index.cjs +33 -0
- package/dist/validators/maxDate.cjs +4 -0
- package/dist/validators/minDate.cjs +4 -0
- package/package.json +23 -5
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactHookForm = require("react-hook-form");
|
|
4
|
+
const useFieldArrayDeprecated = (name, options) => {
|
|
5
|
+
const {
|
|
6
|
+
fields,
|
|
7
|
+
append,
|
|
8
|
+
remove,
|
|
9
|
+
update,
|
|
10
|
+
move
|
|
11
|
+
} = reactHookForm.useFieldArray({
|
|
12
|
+
name,
|
|
13
|
+
rules: {
|
|
14
|
+
validate: options?.validate
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const value = reactHookForm.useWatch({
|
|
18
|
+
name
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
fields: {
|
|
22
|
+
push: append,
|
|
23
|
+
value,
|
|
24
|
+
remove,
|
|
25
|
+
update,
|
|
26
|
+
map: (callback) => fields.map((_, index) => callback(`${name}.${index}`, index)),
|
|
27
|
+
move,
|
|
28
|
+
length: fields.length
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.useFieldArrayDeprecated = useFieldArrayDeprecated;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const reactHookForm = require("react-hook-form");
|
|
5
|
+
const index = require("../components/Form/index.cjs");
|
|
6
|
+
const useFormDeprecated = () => {
|
|
7
|
+
const {
|
|
8
|
+
setValue,
|
|
9
|
+
resetField,
|
|
10
|
+
getFieldState,
|
|
11
|
+
reset
|
|
12
|
+
} = reactHookForm.useFormContext();
|
|
13
|
+
const formSubmitContext = React.useContext(index.FormSubmitContext);
|
|
14
|
+
return {
|
|
15
|
+
change: setValue,
|
|
16
|
+
resetFieldState: resetField,
|
|
17
|
+
getFieldState,
|
|
18
|
+
batch: (callback) => callback(),
|
|
19
|
+
restart: reset,
|
|
20
|
+
reset,
|
|
21
|
+
submit: formSubmitContext.handleSubmit
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.useFormDeprecated = useFormDeprecated;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactHookForm = require("react-hook-form");
|
|
4
|
+
const useFormStateDeprecated = (_params) => {
|
|
5
|
+
const {
|
|
6
|
+
formState
|
|
7
|
+
} = reactHookForm.useFormContext();
|
|
8
|
+
return {
|
|
9
|
+
dirtySinceLastSubmit: formState.isDirty,
|
|
10
|
+
submitErrors: formState.errors.root,
|
|
11
|
+
values: reactHookForm.useWatch(),
|
|
12
|
+
hasValidationErrors: !formState.isValid,
|
|
13
|
+
pristine: !formState.isDirty,
|
|
14
|
+
errors: formState.errors,
|
|
15
|
+
initialValues: formState.defaultValues,
|
|
16
|
+
touched: formState.touchedFields,
|
|
17
|
+
submitting: formState.isSubmitting,
|
|
18
|
+
invalid: !formState.isValid,
|
|
19
|
+
valid: formState.isValid
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.useFormStateDeprecated = useFormStateDeprecated;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const reactHookForm = require("react-hook-form");
|
|
5
|
+
const useOnFieldChange = (fieldName, callback, enabled = true) => {
|
|
6
|
+
const {
|
|
7
|
+
watch,
|
|
8
|
+
getValues
|
|
9
|
+
} = reactHookForm.useFormContext();
|
|
10
|
+
const previousValues = React.useRef(getValues(fieldName));
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const subscription = watch((value) => {
|
|
13
|
+
if (previousValues.current !== value[fieldName] && enabled) {
|
|
14
|
+
previousValues.current = value[fieldName];
|
|
15
|
+
callback(value[fieldName], value)?.catch(() => null);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return () => subscription.unsubscribe();
|
|
19
|
+
}, [callback, enabled, watch, getValues, fieldName]);
|
|
20
|
+
};
|
|
21
|
+
exports.useOnFieldChange = useOnFieldChange;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const constants = require("./constants.cjs");
|
|
4
|
+
const index = require("./providers/ErrorContext/index.cjs");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const useFormState = require("./hooks/useFormState.cjs");
|
|
7
|
+
const useField = require("./hooks/useField.cjs");
|
|
8
|
+
const useForm = require("./hooks/useForm.cjs");
|
|
9
|
+
const useFieldArray = require("./hooks/useFieldArray.cjs");
|
|
10
|
+
const useOnFieldChange = require("./hooks/useOnFieldChange.cjs");
|
|
11
|
+
const index$1 = require("./components/CheckboxField/index.cjs");
|
|
12
|
+
const index$2 = require("./components/CheckboxGroupField/index.cjs");
|
|
13
|
+
const index$3 = require("./components/DateField/index.cjs");
|
|
14
|
+
const index$4 = require("./components/Form/index.cjs");
|
|
15
|
+
const index$5 = require("./components/RadioField/index.cjs");
|
|
16
|
+
const index$6 = require("./components/SelectInputField/index.cjs");
|
|
17
|
+
const index$7 = require("./components/SelectableCardField/index.cjs");
|
|
18
|
+
const index$8 = require("./components/NumberInputField/index.cjs");
|
|
19
|
+
const index$9 = require("./components/NumberInputFieldV2/index.cjs");
|
|
20
|
+
const index$a = require("./components/SubmitErrorAlert/index.cjs");
|
|
21
|
+
const index$b = require("./components/TagInputField/index.cjs");
|
|
22
|
+
const index$c = require("./components/TextAreaField/index.cjs");
|
|
23
|
+
const index$d = require("./components/TextInputField/index.cjs");
|
|
24
|
+
const index$e = require("./components/TextInputFieldV2/index.cjs");
|
|
25
|
+
const index$f = require("./components/TimeField/index.cjs");
|
|
26
|
+
const index$g = require("./components/ToggleField/index.cjs");
|
|
27
|
+
const index$h = require("./components/Submit/index.cjs");
|
|
28
|
+
const index$i = require("./components/RadioGroupField/index.cjs");
|
|
29
|
+
const index$j = require("./components/KeyValueField/index.cjs");
|
|
30
|
+
const index$k = require("./components/SelectableCardGroupField/index.cjs");
|
|
31
|
+
const index$l = require("./components/SelectInputFieldV2/index.cjs");
|
|
32
|
+
exports.FORM_ERROR = constants.FORM_ERROR;
|
|
33
|
+
exports.ErrorProvider = index.ErrorProvider;
|
|
34
|
+
exports.useErrors = index.useErrors;
|
|
35
|
+
Object.defineProperty(exports, "useController", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: () => reactHookForm.useController
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "useFieldArray", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: () => reactHookForm.useFieldArray
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "useForm", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: () => reactHookForm.useForm
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "useFormContext", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: () => reactHookForm.useFormContext
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "useFormState", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: () => reactHookForm.useFormState
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "useWatch", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: () => reactHookForm.useWatch
|
|
58
|
+
});
|
|
59
|
+
exports.useFormStateDeprecated = useFormState.useFormStateDeprecated;
|
|
60
|
+
exports.useFieldDeprecated = useField.useFieldDeprecated;
|
|
61
|
+
exports.useFormDeprecated = useForm.useFormDeprecated;
|
|
62
|
+
exports.useFieldArrayDeprecated = useFieldArray.useFieldArrayDeprecated;
|
|
63
|
+
exports.useOnFieldChange = useOnFieldChange.useOnFieldChange;
|
|
64
|
+
exports.CheckboxField = index$1.CheckboxField;
|
|
65
|
+
exports.CheckboxGroupField = index$2.CheckboxGroupField;
|
|
66
|
+
exports.DateField = index$3.DateField;
|
|
67
|
+
exports.Form = index$4.Form;
|
|
68
|
+
exports.RadioField = index$5.RadioField;
|
|
69
|
+
exports.SelectInputField = index$6.SelectInputField;
|
|
70
|
+
exports.SelectableCardField = index$7.SelectableCardField;
|
|
71
|
+
exports.NumberInputField = index$8.NumberInputField;
|
|
72
|
+
exports.NumberInputFieldV2 = index$9.NumberInputFieldV2;
|
|
73
|
+
exports.SubmitErrorAlert = index$a.SubmitErrorAlert;
|
|
74
|
+
exports.TagInputField = index$b.TagInputField;
|
|
75
|
+
exports.TextAreaField = index$c.TextAreaField;
|
|
76
|
+
exports.TextInputField = index$d.TextInputField;
|
|
77
|
+
exports.TextInputFieldV2 = index$e.TextInputField;
|
|
78
|
+
exports.TimeField = index$f.TimeField;
|
|
79
|
+
exports.ToggleField = index$g.ToggleField;
|
|
80
|
+
exports.Submit = index$h.Submit;
|
|
81
|
+
exports.RadioGroupField = index$i.RadioGroupField;
|
|
82
|
+
exports.KeyValueField = index$j.KeyValueField;
|
|
83
|
+
exports.SelectableCardGroupField = index$k.SelectableCardGroupField;
|
|
84
|
+
exports.SelectInputFieldV2 = index$l.SelectInputFieldV2;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const ErrorContext = React.createContext(void 0);
|
|
6
|
+
const ErrorProvider = ({
|
|
7
|
+
children,
|
|
8
|
+
errors
|
|
9
|
+
}) => {
|
|
10
|
+
const getError = React.useCallback((meta, error) => {
|
|
11
|
+
if (!error) {
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
if (error.message) {
|
|
15
|
+
return error.message;
|
|
16
|
+
}
|
|
17
|
+
return errors?.[error.type]?.(meta);
|
|
18
|
+
}, [errors]);
|
|
19
|
+
const value = React.useMemo(() => ({
|
|
20
|
+
errors,
|
|
21
|
+
getError
|
|
22
|
+
}), [errors, getError]);
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ErrorContext.Provider, { value, children });
|
|
24
|
+
};
|
|
25
|
+
const useErrors = () => {
|
|
26
|
+
const context = React.useContext(ErrorContext);
|
|
27
|
+
if (context === void 0) {
|
|
28
|
+
throw new Error("useErrors must be used within an ErrorProvider ");
|
|
29
|
+
}
|
|
30
|
+
return context;
|
|
31
|
+
};
|
|
32
|
+
exports.ErrorProvider = ErrorProvider;
|
|
33
|
+
exports.useErrors = useErrors;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.6",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -29,18 +29,33 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"module": "./dist/index.js",
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
34
35
|
"types": "./dist/index.d.ts",
|
|
36
|
+
"require": "./dist/index.cjs",
|
|
35
37
|
"default": "./dist/index.js"
|
|
36
38
|
}
|
|
37
39
|
},
|
|
40
|
+
"size-limit": [
|
|
41
|
+
{
|
|
42
|
+
"path": [
|
|
43
|
+
"dist/**/*.js",
|
|
44
|
+
"!*.d.ts",
|
|
45
|
+
"!*.cjs"
|
|
46
|
+
],
|
|
47
|
+
"limit": "50 kB",
|
|
48
|
+
"webpack": false,
|
|
49
|
+
"brotli": true,
|
|
50
|
+
"running": false
|
|
51
|
+
}
|
|
52
|
+
],
|
|
38
53
|
"peerDependencies": {
|
|
39
54
|
"@emotion/react": "11.11.4",
|
|
40
55
|
"@emotion/styled": "11.11.5",
|
|
41
56
|
"react": "18.x",
|
|
42
57
|
"react-dom": "18.x",
|
|
43
|
-
"react-hook-form": "7.51.
|
|
58
|
+
"react-hook-form": "7.51.4"
|
|
44
59
|
},
|
|
45
60
|
"devDependencies": {
|
|
46
61
|
"@babel/core": "7.24.5",
|
|
@@ -55,14 +70,17 @@
|
|
|
55
70
|
"@emotion/react": "11.11.4",
|
|
56
71
|
"@emotion/styled": "11.11.5",
|
|
57
72
|
"react-select": "5.8.0",
|
|
58
|
-
"react-hook-form": "7.51.
|
|
59
|
-
"@ultraviolet/ui": "1.51.
|
|
73
|
+
"react-hook-form": "7.51.4",
|
|
74
|
+
"@ultraviolet/ui": "1.51.5"
|
|
60
75
|
},
|
|
61
76
|
"scripts": {
|
|
62
77
|
"prebuild": "shx rm -rf dist",
|
|
63
78
|
"type:generate": "tsc --declaration -p tsconfig.build.json",
|
|
79
|
+
"watch": "pnpm run '/^watch:.*/'",
|
|
80
|
+
"watch:build": "vite build --config vite.config.ts --watch",
|
|
64
81
|
"build": "vite build --config vite.config.ts && pnpm run type:generate",
|
|
65
82
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|
|
66
|
-
"typecheck": "tsc --noEmit"
|
|
83
|
+
"typecheck": "tsc --noEmit",
|
|
84
|
+
"size": "pnpm run build && size-limit"
|
|
67
85
|
}
|
|
68
86
|
}
|