@ultraviolet/form 2.13.3 → 2.13.5
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/CheckboxField/index.js +15 -32
- package/dist/components/CheckboxGroupField/index.cjs +75 -0
- package/dist/components/CheckboxGroupField/index.js +31 -48
- package/dist/components/DateField/index.cjs +74 -0
- package/dist/components/DateField/index.js +27 -42
- package/dist/components/Form/defaultErrors.cjs +22 -0
- package/dist/components/Form/index.cjs +72 -0
- package/dist/components/Form/index.js +25 -33
- package/dist/components/KeyValueField/index.cjs +51 -0
- package/dist/components/KeyValueField/index.js +14 -48
- package/dist/components/NumberInputField/index.cjs +56 -0
- package/dist/components/NumberInputField/index.js +17 -32
- package/dist/components/NumberInputFieldV2/index.cjs +63 -0
- package/dist/components/NumberInputFieldV2/index.js +17 -37
- package/dist/components/RadioField/index.cjs +49 -0
- package/dist/components/RadioField/index.js +15 -27
- package/dist/components/RadioGroupField/index.cjs +45 -0
- package/dist/components/RadioGroupField/index.js +12 -22
- package/dist/components/SelectInputField/index.cjs +102 -0
- package/dist/components/SelectInputField/index.js +41 -78
- package/dist/components/SelectInputFieldV2/index.cjs +70 -0
- package/dist/components/SelectInputFieldV2/index.js +16 -50
- package/dist/components/SelectableCardField/index.cjs +58 -0
- package/dist/components/SelectableCardField/index.js +20 -42
- package/dist/components/SelectableCardGroupField/index.cjs +56 -0
- package/dist/components/SelectableCardGroupField/index.js +20 -34
- package/dist/components/Submit/index.cjs +26 -0
- package/dist/components/Submit/index.js +5 -19
- package/dist/components/SubmitErrorAlert/index.cjs +14 -0
- package/dist/components/SubmitErrorAlert/index.js +6 -2
- package/dist/components/TagInputField/index.cjs +50 -0
- package/dist/components/TagInputField/index.js +12 -27
- package/dist/components/TextAreaField/index.cjs +70 -0
- package/dist/components/TextAreaField/index.js +22 -50
- package/dist/components/TextInputField/index.cjs +114 -0
- package/dist/components/TextInputField/index.js +31 -71
- package/dist/components/TextInputFieldV2/index.cjs +79 -0
- package/dist/components/TextInputFieldV2/index.js +22 -59
- package/dist/components/TimeField/index.cjs +66 -0
- package/dist/components/TimeField/index.js +17 -42
- package/dist/components/ToggleField/index.cjs +47 -0
- package/dist/components/ToggleField/index.js +10 -24
- package/dist/constants.cjs +4 -0
- package/dist/hooks/useField.cjs +30 -0
- package/dist/hooks/useField.js +10 -3
- package/dist/hooks/useFieldArray.cjs +32 -0
- package/dist/hooks/useFieldArray.js +13 -3
- package/dist/hooks/useForm.cjs +24 -0
- package/dist/hooks/useForm.js +6 -1
- package/dist/hooks/useFormState.cjs +22 -0
- package/dist/hooks/useFormState.js +3 -1
- package/dist/hooks/useOnFieldChange.cjs +21 -0
- package/dist/hooks/useOnFieldChange.js +5 -4
- package/dist/index.cjs +84 -0
- package/dist/providers/ErrorContext/index.cjs +33 -0
- package/dist/providers/ErrorContext/index.js +17 -20
- package/dist/validators/maxDate.cjs +4 -0
- package/dist/validators/minDate.cjs +4 -0
- package/package.json +20 -4
|
@@ -35,7 +35,9 @@ const TimeField = ({
|
|
|
35
35
|
}) => {
|
|
36
36
|
const {
|
|
37
37
|
field,
|
|
38
|
-
fieldState: {
|
|
38
|
+
fieldState: {
|
|
39
|
+
error
|
|
40
|
+
}
|
|
39
41
|
} = useController({
|
|
40
42
|
name,
|
|
41
43
|
shouldUnregister,
|
|
@@ -44,47 +46,20 @@ const TimeField = ({
|
|
|
44
46
|
...rules
|
|
45
47
|
}
|
|
46
48
|
});
|
|
47
|
-
return /* @__PURE__ */ jsx(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
date.setHours(Number(hours), Number(minutes), 0);
|
|
62
|
-
field.onChange(date);
|
|
63
|
-
},
|
|
64
|
-
onBlur: (event) => {
|
|
65
|
-
field.onBlur();
|
|
66
|
-
onBlur?.(event);
|
|
67
|
-
},
|
|
68
|
-
onFocus: (event) => {
|
|
69
|
-
onFocus?.(event);
|
|
70
|
-
},
|
|
71
|
-
error: error?.message,
|
|
72
|
-
disabled,
|
|
73
|
-
readOnly,
|
|
74
|
-
animation,
|
|
75
|
-
animationDuration,
|
|
76
|
-
animationOnChange,
|
|
77
|
-
className,
|
|
78
|
-
isLoading,
|
|
79
|
-
isClearable,
|
|
80
|
-
isSearchable,
|
|
81
|
-
inputId,
|
|
82
|
-
id,
|
|
83
|
-
options,
|
|
84
|
-
"data-testid": dataTestId,
|
|
85
|
-
noTopLabel
|
|
86
|
-
}
|
|
87
|
-
);
|
|
49
|
+
return /* @__PURE__ */ jsx(TimeInput, { name: field.name, placeholder, schedule, required, value: parseTime(field.value), onChange: (val) => {
|
|
50
|
+
if (!val)
|
|
51
|
+
return;
|
|
52
|
+
onChange?.(val);
|
|
53
|
+
const [hours, minutes] = val.value.split(":");
|
|
54
|
+
const date = field.value ? new Date(field.value) : /* @__PURE__ */ new Date();
|
|
55
|
+
date.setHours(Number(hours), Number(minutes), 0);
|
|
56
|
+
field.onChange(date);
|
|
57
|
+
}, onBlur: (event) => {
|
|
58
|
+
field.onBlur();
|
|
59
|
+
onBlur?.(event);
|
|
60
|
+
}, onFocus: (event) => {
|
|
61
|
+
onFocus?.(event);
|
|
62
|
+
}, error: error?.message, disabled, readOnly, animation, animationDuration, animationOnChange, className, isLoading, isClearable, isSearchable, inputId, id, options, "data-testid": dataTestId, noTopLabel });
|
|
88
63
|
};
|
|
89
64
|
export {
|
|
90
65
|
TimeField
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const ToggleField = ({
|
|
7
|
+
className,
|
|
8
|
+
disabled,
|
|
9
|
+
label,
|
|
10
|
+
name,
|
|
11
|
+
onChange,
|
|
12
|
+
required,
|
|
13
|
+
size,
|
|
14
|
+
tooltip,
|
|
15
|
+
rules,
|
|
16
|
+
labelPosition,
|
|
17
|
+
parse,
|
|
18
|
+
format,
|
|
19
|
+
"data-testid": dataTestId,
|
|
20
|
+
shouldUnregister = false
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
field
|
|
24
|
+
} = reactHookForm.useController({
|
|
25
|
+
name,
|
|
26
|
+
shouldUnregister,
|
|
27
|
+
rules: {
|
|
28
|
+
required,
|
|
29
|
+
...rules
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const transformedValue = () => {
|
|
33
|
+
if (format) {
|
|
34
|
+
return format(field.value);
|
|
35
|
+
}
|
|
36
|
+
return field.value;
|
|
37
|
+
};
|
|
38
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Toggle, { name: field.name, ref: field.ref, checked: transformedValue(), tooltip, onChange: (event) => {
|
|
39
|
+
if (parse) {
|
|
40
|
+
field.onChange(parse(event.target.checked));
|
|
41
|
+
} else {
|
|
42
|
+
field.onChange(event);
|
|
43
|
+
}
|
|
44
|
+
onChange?.(event);
|
|
45
|
+
}, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId });
|
|
46
|
+
};
|
|
47
|
+
exports.ToggleField = ToggleField;
|
|
@@ -17,7 +17,9 @@ const ToggleField = ({
|
|
|
17
17
|
"data-testid": dataTestId,
|
|
18
18
|
shouldUnregister = false
|
|
19
19
|
}) => {
|
|
20
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
field
|
|
22
|
+
} = useController({
|
|
21
23
|
name,
|
|
22
24
|
shouldUnregister,
|
|
23
25
|
rules: {
|
|
@@ -31,30 +33,14 @@ const ToggleField = ({
|
|
|
31
33
|
}
|
|
32
34
|
return field.value;
|
|
33
35
|
};
|
|
34
|
-
return /* @__PURE__ */ jsx(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
checked: transformedValue(),
|
|
40
|
-
tooltip,
|
|
41
|
-
onChange: (event) => {
|
|
42
|
-
if (parse) {
|
|
43
|
-
field.onChange(parse(event.target.checked));
|
|
44
|
-
} else {
|
|
45
|
-
field.onChange(event);
|
|
46
|
-
}
|
|
47
|
-
onChange?.(event);
|
|
48
|
-
},
|
|
49
|
-
label,
|
|
50
|
-
size,
|
|
51
|
-
disabled,
|
|
52
|
-
labelPosition,
|
|
53
|
-
className,
|
|
54
|
-
required,
|
|
55
|
-
"data-testid": dataTestId
|
|
36
|
+
return /* @__PURE__ */ jsx(Toggle, { name: field.name, ref: field.ref, checked: transformedValue(), tooltip, onChange: (event) => {
|
|
37
|
+
if (parse) {
|
|
38
|
+
field.onChange(parse(event.target.checked));
|
|
39
|
+
} else {
|
|
40
|
+
field.onChange(event);
|
|
56
41
|
}
|
|
57
|
-
|
|
42
|
+
onChange?.(event);
|
|
43
|
+
}, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId });
|
|
58
44
|
};
|
|
59
45
|
export {
|
|
60
46
|
ToggleField
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactHookForm = require("react-hook-form");
|
|
4
|
+
const useFieldDeprecated = (name, options) => {
|
|
5
|
+
const {
|
|
6
|
+
getValues
|
|
7
|
+
} = reactHookForm.useFormContext();
|
|
8
|
+
const {
|
|
9
|
+
field,
|
|
10
|
+
fieldState
|
|
11
|
+
} = reactHookForm.useController({
|
|
12
|
+
name,
|
|
13
|
+
rules: {
|
|
14
|
+
validate: options?.validate
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
input: {
|
|
19
|
+
value: getValues(name),
|
|
20
|
+
onChange: field.onChange
|
|
21
|
+
},
|
|
22
|
+
meta: {
|
|
23
|
+
error: fieldState.error?.message,
|
|
24
|
+
touched: fieldState.isTouched,
|
|
25
|
+
invalid: fieldState.invalid,
|
|
26
|
+
dirty: fieldState.isDirty
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.useFieldDeprecated = useFieldDeprecated;
|
package/dist/hooks/useField.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { useFormContext, useController } from "react-hook-form";
|
|
2
2
|
const useFieldDeprecated = (name, options) => {
|
|
3
|
-
const {
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
getValues
|
|
5
|
+
} = useFormContext();
|
|
6
|
+
const {
|
|
7
|
+
field,
|
|
8
|
+
fieldState
|
|
9
|
+
} = useController({
|
|
5
10
|
name,
|
|
6
|
-
rules: {
|
|
11
|
+
rules: {
|
|
12
|
+
validate: options?.validate
|
|
13
|
+
}
|
|
7
14
|
});
|
|
8
15
|
return {
|
|
9
16
|
input: {
|
|
@@ -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;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { useFieldArray, useWatch } from "react-hook-form";
|
|
2
2
|
const useFieldArrayDeprecated = (name, options) => {
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
fields,
|
|
5
|
+
append,
|
|
6
|
+
remove,
|
|
7
|
+
update,
|
|
8
|
+
move
|
|
9
|
+
} = useFieldArray({
|
|
4
10
|
name,
|
|
5
|
-
rules: {
|
|
11
|
+
rules: {
|
|
12
|
+
validate: options?.validate
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const value = useWatch({
|
|
16
|
+
name
|
|
6
17
|
});
|
|
7
|
-
const value = useWatch({ name });
|
|
8
18
|
return {
|
|
9
19
|
fields: {
|
|
10
20
|
push: append,
|
|
@@ -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;
|
package/dist/hooks/useForm.js
CHANGED
|
@@ -2,7 +2,12 @@ import { useContext } from "react";
|
|
|
2
2
|
import { useFormContext } from "react-hook-form";
|
|
3
3
|
import { FormSubmitContext } from "../components/Form/index.js";
|
|
4
4
|
const useFormDeprecated = () => {
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
setValue,
|
|
7
|
+
resetField,
|
|
8
|
+
getFieldState,
|
|
9
|
+
reset
|
|
10
|
+
} = useFormContext();
|
|
6
11
|
const formSubmitContext = useContext(FormSubmitContext);
|
|
7
12
|
return {
|
|
8
13
|
change: setValue,
|
|
@@ -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;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useFormContext, useWatch } from "react-hook-form";
|
|
2
2
|
const useFormStateDeprecated = (_params) => {
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
formState
|
|
5
|
+
} = useFormContext();
|
|
4
6
|
return {
|
|
5
7
|
dirtySinceLastSubmit: formState.isDirty,
|
|
6
8
|
submitErrors: formState.errors.root,
|
|
@@ -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;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
2
|
import { useFormContext } from "react-hook-form";
|
|
3
3
|
const useOnFieldChange = (fieldName, callback, enabled = true) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
getValues
|
|
7
|
-
);
|
|
4
|
+
const {
|
|
5
|
+
watch,
|
|
6
|
+
getValues
|
|
7
|
+
} = useFormContext();
|
|
8
|
+
const previousValues = useRef(getValues(fieldName));
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
const subscription = watch((value) => {
|
|
10
11
|
if (previousValues.current !== value[fieldName] && enabled) {
|
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;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { createContext, useCallback, useMemo, useContext } from "react";
|
|
3
3
|
const ErrorContext = createContext(void 0);
|
|
4
|
-
const ErrorProvider = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
[
|
|
16
|
-
);
|
|
17
|
-
const value = useMemo(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}),
|
|
22
|
-
[errors, getError]
|
|
23
|
-
);
|
|
4
|
+
const ErrorProvider = ({
|
|
5
|
+
children,
|
|
6
|
+
errors
|
|
7
|
+
}) => {
|
|
8
|
+
const getError = useCallback((meta, error) => {
|
|
9
|
+
if (!error) {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
if (error.message) {
|
|
13
|
+
return error.message;
|
|
14
|
+
}
|
|
15
|
+
return errors?.[error.type]?.(meta);
|
|
16
|
+
}, [errors]);
|
|
17
|
+
const value = useMemo(() => ({
|
|
18
|
+
errors,
|
|
19
|
+
getError
|
|
20
|
+
}), [errors, getError]);
|
|
24
21
|
return /* @__PURE__ */ jsx(ErrorContext.Provider, { value, children });
|
|
25
22
|
};
|
|
26
23
|
const useErrors = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.5",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -29,12 +29,27 @@
|
|
|
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",
|
|
@@ -52,17 +67,18 @@
|
|
|
52
67
|
},
|
|
53
68
|
"dependencies": {
|
|
54
69
|
"@babel/runtime": "7.24.5",
|
|
55
|
-
"@emotion/babel-plugin": "11.11.0",
|
|
56
70
|
"@emotion/react": "11.11.4",
|
|
57
71
|
"@emotion/styled": "11.11.5",
|
|
58
72
|
"react-select": "5.8.0",
|
|
59
73
|
"react-hook-form": "7.51.3",
|
|
60
|
-
"@ultraviolet/ui": "1.51.
|
|
74
|
+
"@ultraviolet/ui": "1.51.4"
|
|
61
75
|
},
|
|
62
76
|
"scripts": {
|
|
77
|
+
"prebuild": "shx rm -rf dist",
|
|
63
78
|
"type:generate": "tsc --declaration -p tsconfig.build.json",
|
|
64
79
|
"build": "vite build --config vite.config.ts && pnpm run type:generate",
|
|
65
80
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|
|
66
|
-
"typecheck": "tsc --noEmit"
|
|
81
|
+
"typecheck": "tsc --noEmit",
|
|
82
|
+
"size": "pnpm run build && size-limit"
|
|
67
83
|
}
|
|
68
84
|
}
|