@cyclone-ui/state 0.0.12 → 0.0.13
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/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/base/atoms/atom-with-broadcast.cjs +45 -1
- package/dist/base/atoms/atom-with-broadcast.mjs +45 -1
- package/dist/base/atoms/atom-with-broadcast.mjs.map +1 -1
- package/dist/base/atoms/atom-with-compare.cjs +12 -1
- package/dist/base/atoms/atom-with-compare.mjs +12 -1
- package/dist/base/atoms/atom-with-compare.mjs.map +1 -1
- package/dist/base/atoms/atom-with-debounce.cjs +52 -1
- package/dist/base/atoms/atom-with-debounce.mjs +52 -1
- package/dist/base/atoms/atom-with-debounce.mjs.map +1 -1
- package/dist/base/atoms/atom-with-effect.cjs +123 -1
- package/dist/base/atoms/atom-with-effect.mjs +120 -1
- package/dist/base/atoms/atom-with-effect.mjs.map +1 -1
- package/dist/base/atoms/atom-with-listeners.cjs +36 -1
- package/dist/base/atoms/atom-with-listeners.mjs +36 -1
- package/dist/base/atoms/atom-with-listeners.mjs.map +1 -1
- package/dist/base/atoms/atom-with-pending.cjs +14 -1
- package/dist/base/atoms/atom-with-pending.mjs +14 -1
- package/dist/base/atoms/atom-with-pending.mjs.map +1 -1
- package/dist/base/atoms/atom-with-refresh-and-default.cjs +19 -1
- package/dist/base/atoms/atom-with-refresh-and-default.mjs +19 -1
- package/dist/base/atoms/atom-with-refresh-and-default.mjs.map +1 -1
- package/dist/base/atoms/atom-with-refresh.cjs +13 -1
- package/dist/base/atoms/atom-with-refresh.mjs +13 -1
- package/dist/base/atoms/atom-with-refresh.mjs.map +1 -1
- package/dist/base/atoms/atom-with-toggle.cjs +13 -1
- package/dist/base/atoms/atom-with-toggle.mjs +13 -1
- package/dist/base/atoms/atom-with-toggle.mjs.map +1 -1
- package/dist/base/atoms/atom-with-web-storage.cjs +48 -1
- package/dist/base/atoms/atom-with-web-storage.mjs +47 -1
- package/dist/base/atoms/atom-with-web-storage.mjs.map +1 -1
- package/dist/base/atoms/atom-with-wrapper.cjs +25 -1
- package/dist/base/atoms/atom-with-wrapper.mjs +25 -1
- package/dist/base/atoms/atom-with-wrapper.mjs.map +1 -1
- package/dist/base/atoms/base-atom.cjs +25 -1
- package/dist/base/atoms/base-atom.mjs +25 -1
- package/dist/base/atoms/base-atom.mjs.map +1 -1
- package/dist/base/atoms/index.cjs +24 -1
- package/dist/base/atoms/index.mjs +13 -1
- package/dist/base/hooks/index.cjs +9 -1
- package/dist/base/hooks/index.mjs +6 -1
- package/dist/base/hooks/use-atom-effect.cjs +17 -1
- package/dist/base/hooks/use-atom-effect.mjs +17 -1
- package/dist/base/hooks/use-atom-effect.mjs.map +1 -1
- package/dist/base/hooks/use-hydrate-molecule.cjs +17 -1
- package/dist/base/hooks/use-hydrate-molecule.mjs +17 -1
- package/dist/base/hooks/use-hydrate-molecule.mjs.map +1 -1
- package/dist/base/hooks/use-prepare-atoms.cjs +20 -1
- package/dist/base/hooks/use-prepare-atoms.mjs +20 -1
- package/dist/base/hooks/use-prepare-atoms.mjs.map +1 -1
- package/dist/base/hooks/use-sync-molecule.cjs +37 -1
- package/dist/base/hooks/use-sync-molecule.mjs +37 -1
- package/dist/base/hooks/use-sync-molecule.mjs.map +1 -1
- package/dist/base/index.cjs +47 -1
- package/dist/base/index.mjs +24 -1
- package/dist/base/utilities/create-molecule.cjs +105 -4
- package/dist/base/utilities/create-molecule.d.cts.map +1 -1
- package/dist/base/utilities/create-molecule.mjs +102 -4
- package/dist/base/utilities/create-molecule.mjs.map +1 -1
- package/dist/base/utilities/create-web-storage.cjs +55 -1
- package/dist/base/utilities/create-web-storage.mjs +55 -1
- package/dist/base/utilities/create-web-storage.mjs.map +1 -1
- package/dist/base/utilities/debounce.cjs +52 -1
- package/dist/base/utilities/debounce.mjs +52 -1
- package/dist/base/utilities/debounce.mjs.map +1 -1
- package/dist/base/utilities/index.cjs +13 -1
- package/dist/base/utilities/index.mjs +6 -1
- package/dist/base/utilities/is-atom.cjs +48 -1
- package/dist/base/utilities/is-atom.mjs +46 -1
- package/dist/base/utilities/is-atom.mjs.map +1 -1
- package/dist/base/utilities/set-atom-debug.cjs +24 -1
- package/dist/base/utilities/set-atom-debug.mjs +23 -1
- package/dist/base/utilities/set-atom-debug.mjs.map +1 -1
- package/dist/client/index.cjs +16 -1
- package/dist/client/index.mjs +8 -1
- package/dist/form/atoms/atom-with-field.cjs +23 -1
- package/dist/form/atoms/atom-with-field.mjs +23 -1
- package/dist/form/atoms/atom-with-field.mjs.map +1 -1
- package/dist/form/atoms/atom-with-messages.cjs +85 -1
- package/dist/form/atoms/atom-with-messages.mjs +78 -1
- package/dist/form/atoms/atom-with-messages.mjs.map +1 -1
- package/dist/form/hooks/index.cjs +7 -1
- package/dist/form/hooks/index.mjs +5 -1
- package/dist/form/hooks/use-field-actions.cjs +92 -1
- package/dist/form/hooks/use-field-actions.mjs +92 -1
- package/dist/form/hooks/use-field-actions.mjs.map +1 -1
- package/dist/form/hooks/use-field-ref.cjs +16 -1
- package/dist/form/hooks/use-field-ref.mjs +16 -1
- package/dist/form/hooks/use-field-ref.mjs.map +1 -1
- package/dist/form/hooks/use-form-actions.cjs +69 -1
- package/dist/form/hooks/use-form-actions.mjs +69 -1
- package/dist/form/hooks/use-form-actions.mjs.map +1 -1
- package/dist/form/index.cjs +30 -1
- package/dist/form/index.mjs +17 -1
- package/dist/form/molecules/field-molecule.cjs +154 -1
- package/dist/form/molecules/field-molecule.mjs +153 -1
- package/dist/form/molecules/field-molecule.mjs.map +1 -1
- package/dist/form/molecules/form-molecule.cjs +180 -1
- package/dist/form/molecules/form-molecule.mjs +179 -1
- package/dist/form/molecules/form-molecule.mjs.map +1 -1
- package/dist/form/molecules/index.cjs +7 -1
- package/dist/form/molecules/index.mjs +4 -1
- package/dist/form/providers/FieldProvider.cjs +103 -4
- package/dist/form/providers/FieldProvider.mjs +103 -4
- package/dist/form/providers/FieldProvider.mjs.map +1 -1
- package/dist/form/providers/FormProvider.cjs +66 -4
- package/dist/form/providers/FormProvider.d.cts.map +1 -1
- package/dist/form/providers/FormProvider.mjs +66 -4
- package/dist/form/providers/FormProvider.mjs.map +1 -1
- package/dist/form/providers/index.cjs +5 -1
- package/dist/form/providers/index.mjs +4 -1
- package/dist/form/types.cjs +13 -1
- package/dist/form/types.mjs +13 -1
- package/dist/form/types.mjs.map +1 -1
- package/dist/form/utilities/abort-error.cjs +15 -1
- package/dist/form/utilities/abort-error.mjs +15 -1
- package/dist/form/utilities/abort-error.mjs.map +1 -1
- package/dist/form/utilities/index.cjs +7 -1
- package/dist/form/utilities/index.mjs +5 -1
- package/dist/form/utilities/is-validation-results.cjs +9 -1
- package/dist/form/utilities/is-validation-results.mjs +9 -1
- package/dist/form/utilities/is-validation-results.mjs.map +1 -1
- package/dist/form/utilities/validators.cjs +8 -1
- package/dist/form/utilities/validators.mjs +8 -1
- package/dist/form/utilities/validators.mjs.map +1 -1
- package/dist/index.cjs +71 -1
- package/dist/index.mjs +34 -1
- package/dist/message/components/MessageViewport.cjs +21 -6
- package/dist/message/components/MessageViewport.mjs +21 -6
- package/dist/message/components/MessageViewport.mjs.map +1 -1
- package/dist/message/components/index.cjs +3 -1
- package/dist/message/components/index.mjs +3 -1
- package/dist/message/hooks/index.cjs +3 -1
- package/dist/message/hooks/index.mjs +3 -1
- package/dist/message/hooks/use-message-actions.cjs +63 -1
- package/dist/message/hooks/use-message-actions.mjs +63 -1
- package/dist/message/hooks/use-message-actions.mjs.map +1 -1
- package/dist/message/index.cjs +23 -1
- package/dist/message/index.mjs +8 -1
- package/dist/message/providers/MessageProvider.cjs +16 -1
- package/dist/message/providers/MessageProvider.mjs +16 -1
- package/dist/message/providers/MessageProvider.mjs.map +1 -1
- package/dist/theme/hooks/index.cjs +7 -1
- package/dist/theme/hooks/index.mjs +4 -1
- package/dist/theme/hooks/use-theme-actions.cjs +21 -1
- package/dist/theme/hooks/use-theme-actions.mjs +21 -1
- package/dist/theme/hooks/use-theme-actions.mjs.map +1 -1
- package/dist/theme/hooks/use-theme-store.cjs +61 -1
- package/dist/theme/hooks/use-theme-store.d.cts +2 -2
- package/dist/theme/hooks/use-theme-store.d.mts +2 -2
- package/dist/theme/hooks/use-theme-store.mjs +59 -1
- package/dist/theme/hooks/use-theme-store.mjs.map +1 -1
- package/dist/theme/index.cjs +17 -1
- package/dist/theme/index.mjs +9 -1
- package/dist/theme/molecules/index.cjs +3 -1
- package/dist/theme/molecules/index.mjs +3 -1
- package/dist/theme/molecules/theme-molecule.cjs +14 -1
- package/dist/theme/molecules/theme-molecule.mjs +14 -1
- package/dist/theme/molecules/theme-molecule.mjs.map +1 -1
- package/dist/theme/providers/ThemeProvider.cjs +30 -5
- package/dist/theme/providers/ThemeProvider.mjs +30 -5
- package/dist/theme/providers/ThemeProvider.mjs.map +1 -1
- package/dist/theme/utilities/theme-helpers.cjs +71 -1
- package/dist/theme/utilities/theme-helpers.mjs +70 -1
- package/dist/theme/utilities/theme-helpers.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1,4 +1,103 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const require_use_atom_effect = require("../../base/hooks/use-atom-effect.cjs");
|
|
2
|
+
const require_form_molecule = require("../molecules/form-molecule.cjs");
|
|
3
|
+
const require_field_molecule = require("../molecules/field-molecule.cjs");
|
|
4
|
+
const require_types = require("../types.cjs");
|
|
5
|
+
const require_use_field_actions = require("../hooks/use-field-actions.cjs");
|
|
6
|
+
const require_abort_error = require("../utilities/abort-error.cjs");
|
|
7
|
+
let _tamagui_core = require("@tamagui/core");
|
|
8
|
+
let _stryke_async = require("@stryke/async");
|
|
9
|
+
let _stryke_type_checks_is_boolean = require("@stryke/type-checks/is-boolean");
|
|
10
|
+
|
|
11
|
+
//#region src/form/providers/FieldProvider.tsx
|
|
12
|
+
function FieldStateManager(_props) {
|
|
13
|
+
const { validate } = require_use_field_actions.useFieldActions();
|
|
14
|
+
const form = require_form_molecule.FormApi.useMolecule();
|
|
15
|
+
const field = require_field_molecule.FieldApi.useMolecule();
|
|
16
|
+
require_use_atom_effect.useAtomEffect((get, set) => {
|
|
17
|
+
const value = get(field.value);
|
|
18
|
+
const abortController = new AbortController();
|
|
19
|
+
(async () => {
|
|
20
|
+
try {
|
|
21
|
+
const options = get(field.options);
|
|
22
|
+
await (0, _stryke_async.delay)(options.debounceMs);
|
|
23
|
+
abortController.signal.throwIfAborted();
|
|
24
|
+
if (options.onChange) {
|
|
25
|
+
await Promise.resolve(options.onChange({
|
|
26
|
+
get,
|
|
27
|
+
set,
|
|
28
|
+
atoms: field
|
|
29
|
+
}));
|
|
30
|
+
abortController.signal.throwIfAborted();
|
|
31
|
+
}
|
|
32
|
+
const promises = [];
|
|
33
|
+
promises.push(validate(value, require_types.ValidationCause.CHANGE));
|
|
34
|
+
if (get(field.blurred)) promises.push(validate(value, require_types.ValidationCause.BLUR));
|
|
35
|
+
if (get(form.submitAttempts) > 0) promises.push(validate(value, require_types.ValidationCause.SUBMIT));
|
|
36
|
+
await Promise.all(promises);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
if (e instanceof require_abort_error.AbortError) {}
|
|
39
|
+
}
|
|
40
|
+
})();
|
|
41
|
+
return () => {
|
|
42
|
+
abortController.abort(new require_abort_error.AbortError());
|
|
43
|
+
};
|
|
44
|
+
}, [validate]);
|
|
45
|
+
require_use_atom_effect.useAtomEffect((get, set) => {
|
|
46
|
+
const focused = get(field.focused);
|
|
47
|
+
const abortController = new AbortController();
|
|
48
|
+
(async () => {
|
|
49
|
+
try {
|
|
50
|
+
const options = get(field.options);
|
|
51
|
+
await (0, _stryke_async.delay)(options.debounceMs);
|
|
52
|
+
abortController.signal.throwIfAborted();
|
|
53
|
+
if ((0, _stryke_type_checks_is_boolean.isBoolean)(focused)) {
|
|
54
|
+
if (!get(field.touched)) set(field.touched, true);
|
|
55
|
+
if (focused) {
|
|
56
|
+
if (options.onFocus) {
|
|
57
|
+
await Promise.resolve(options.onFocus({
|
|
58
|
+
get,
|
|
59
|
+
set,
|
|
60
|
+
atoms: field
|
|
61
|
+
}));
|
|
62
|
+
abortController.signal.throwIfAborted();
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (options.onBlur) {
|
|
66
|
+
await Promise.resolve(options.onBlur({
|
|
67
|
+
get,
|
|
68
|
+
set,
|
|
69
|
+
atoms: field
|
|
70
|
+
}));
|
|
71
|
+
abortController.signal.throwIfAborted();
|
|
72
|
+
}
|
|
73
|
+
const value = get(field.value);
|
|
74
|
+
const promises = [];
|
|
75
|
+
promises.push(validate(value, require_types.ValidationCause.BLUR));
|
|
76
|
+
if (get(form.submitAttempts) > 0) promises.push(validate(value, require_types.ValidationCause.SUBMIT));
|
|
77
|
+
await Promise.all(promises);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if (e instanceof require_abort_error.AbortError) {}
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
return () => {
|
|
85
|
+
abortController.abort(new require_abort_error.AbortError());
|
|
86
|
+
};
|
|
87
|
+
}, [validate]);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function FieldProvider({ children, name, ...props }) {
|
|
91
|
+
const formName = require_form_molecule.FormApi.use().name.get();
|
|
92
|
+
const theme = (0, _tamagui_core.useThemeName)();
|
|
93
|
+
return <require_field_molecule.FieldApi.Provider scope={`${formName}-${name}`} initialState={{ options: {
|
|
94
|
+
theme,
|
|
95
|
+
...props
|
|
96
|
+
} }}>
|
|
97
|
+
<FieldStateManager {...props} />
|
|
98
|
+
{children}
|
|
99
|
+
</require_field_molecule.FieldApi.Provider>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
exports.FieldProvider = FieldProvider;
|
|
@@ -1,5 +1,104 @@
|
|
|
1
|
-
import{useAtomEffect
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useAtomEffect } from "../../base/hooks/use-atom-effect.mjs";
|
|
2
|
+
import { FormApi } from "../molecules/form-molecule.mjs";
|
|
3
|
+
import { FieldApi } from "../molecules/field-molecule.mjs";
|
|
4
|
+
import { ValidationCause } from "../types.mjs";
|
|
5
|
+
import { useFieldActions } from "../hooks/use-field-actions.mjs";
|
|
6
|
+
import { AbortError } from "../utilities/abort-error.mjs";
|
|
7
|
+
import { useThemeName } from "@tamagui/core";
|
|
8
|
+
import { delay } from "@stryke/async";
|
|
9
|
+
import { isBoolean } from "@stryke/type-checks/is-boolean";
|
|
10
|
+
|
|
11
|
+
//#region src/form/providers/FieldProvider.tsx
|
|
12
|
+
function FieldStateManager(_props) {
|
|
13
|
+
const { validate } = useFieldActions();
|
|
14
|
+
const form = FormApi.useMolecule();
|
|
15
|
+
const field = FieldApi.useMolecule();
|
|
16
|
+
useAtomEffect((get, set) => {
|
|
17
|
+
const value = get(field.value);
|
|
18
|
+
const abortController = new AbortController();
|
|
19
|
+
(async () => {
|
|
20
|
+
try {
|
|
21
|
+
const options = get(field.options);
|
|
22
|
+
await delay(options.debounceMs);
|
|
23
|
+
abortController.signal.throwIfAborted();
|
|
24
|
+
if (options.onChange) {
|
|
25
|
+
await Promise.resolve(options.onChange({
|
|
26
|
+
get,
|
|
27
|
+
set,
|
|
28
|
+
atoms: field
|
|
29
|
+
}));
|
|
30
|
+
abortController.signal.throwIfAborted();
|
|
31
|
+
}
|
|
32
|
+
const promises = [];
|
|
33
|
+
promises.push(validate(value, ValidationCause.CHANGE));
|
|
34
|
+
if (get(field.blurred)) promises.push(validate(value, ValidationCause.BLUR));
|
|
35
|
+
if (get(form.submitAttempts) > 0) promises.push(validate(value, ValidationCause.SUBMIT));
|
|
36
|
+
await Promise.all(promises);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
if (e instanceof AbortError) {}
|
|
39
|
+
}
|
|
40
|
+
})();
|
|
41
|
+
return () => {
|
|
42
|
+
abortController.abort(new AbortError());
|
|
43
|
+
};
|
|
44
|
+
}, [validate]);
|
|
45
|
+
useAtomEffect((get, set) => {
|
|
46
|
+
const focused = get(field.focused);
|
|
47
|
+
const abortController = new AbortController();
|
|
48
|
+
(async () => {
|
|
49
|
+
try {
|
|
50
|
+
const options = get(field.options);
|
|
51
|
+
await delay(options.debounceMs);
|
|
52
|
+
abortController.signal.throwIfAborted();
|
|
53
|
+
if (isBoolean(focused)) {
|
|
54
|
+
if (!get(field.touched)) set(field.touched, true);
|
|
55
|
+
if (focused) {
|
|
56
|
+
if (options.onFocus) {
|
|
57
|
+
await Promise.resolve(options.onFocus({
|
|
58
|
+
get,
|
|
59
|
+
set,
|
|
60
|
+
atoms: field
|
|
61
|
+
}));
|
|
62
|
+
abortController.signal.throwIfAborted();
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (options.onBlur) {
|
|
66
|
+
await Promise.resolve(options.onBlur({
|
|
67
|
+
get,
|
|
68
|
+
set,
|
|
69
|
+
atoms: field
|
|
70
|
+
}));
|
|
71
|
+
abortController.signal.throwIfAborted();
|
|
72
|
+
}
|
|
73
|
+
const value = get(field.value);
|
|
74
|
+
const promises = [];
|
|
75
|
+
promises.push(validate(value, ValidationCause.BLUR));
|
|
76
|
+
if (get(form.submitAttempts) > 0) promises.push(validate(value, ValidationCause.SUBMIT));
|
|
77
|
+
await Promise.all(promises);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if (e instanceof AbortError) {}
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
return () => {
|
|
85
|
+
abortController.abort(new AbortError());
|
|
86
|
+
};
|
|
87
|
+
}, [validate]);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function FieldProvider({ children, name, ...props }) {
|
|
91
|
+
const formName = FormApi.use().name.get();
|
|
92
|
+
const theme = useThemeName();
|
|
93
|
+
return <FieldApi.Provider scope={`${formName}-${name}`} initialState={{ options: {
|
|
94
|
+
theme,
|
|
95
|
+
...props
|
|
96
|
+
} }}>
|
|
97
|
+
<FieldStateManager {...props} />
|
|
98
|
+
{children}
|
|
99
|
+
</FieldApi.Provider>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { FieldProvider };
|
|
5
104
|
//# sourceMappingURL=FieldProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldProvider.mjs","names":[
|
|
1
|
+
{"version":3,"file":"FieldProvider.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1,4 +1,66 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const require_use_atom_effect = require("../../base/hooks/use-atom-effect.cjs");
|
|
2
|
+
const require_form_molecule = require("../molecules/form-molecule.cjs");
|
|
3
|
+
const require_types = require("../types.cjs");
|
|
4
|
+
const require_use_form_actions = require("../hooks/use-form-actions.cjs");
|
|
5
|
+
const require_abort_error = require("../utilities/abort-error.cjs");
|
|
6
|
+
let jotai_utils = require("jotai/utils");
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _tamagui_core = require("@tamagui/core");
|
|
9
|
+
let _stryke_async = require("@stryke/async");
|
|
10
|
+
|
|
11
|
+
//#region src/form/providers/FormProvider.tsx
|
|
12
|
+
function FormStateManager(props) {
|
|
13
|
+
const { validate } = require_use_form_actions.useFormActions();
|
|
14
|
+
const molecule = require_form_molecule.FormApi.useMolecule();
|
|
15
|
+
const theme = (0, _tamagui_core.useThemeName)();
|
|
16
|
+
const setOptions = require_form_molecule.FormApi.use().options.set();
|
|
17
|
+
(0, jotai_utils.useHydrateAtoms)([[molecule.options, {
|
|
18
|
+
theme,
|
|
19
|
+
...props
|
|
20
|
+
}]]);
|
|
21
|
+
(0, react.useEffect)(() => {
|
|
22
|
+
setOptions({
|
|
23
|
+
theme,
|
|
24
|
+
...props
|
|
25
|
+
});
|
|
26
|
+
}, [setOptions]);
|
|
27
|
+
require_use_atom_effect.useAtomEffect((get, set) => {
|
|
28
|
+
const values = get(molecule.values);
|
|
29
|
+
const options = get(molecule.options);
|
|
30
|
+
const abortController = new AbortController();
|
|
31
|
+
(async () => {
|
|
32
|
+
try {
|
|
33
|
+
await (0, _stryke_async.delay)(options.debounceMs);
|
|
34
|
+
abortController.signal.throwIfAborted();
|
|
35
|
+
if (options.onChange) {
|
|
36
|
+
await Promise.resolve(options.onChange({
|
|
37
|
+
get,
|
|
38
|
+
set,
|
|
39
|
+
atoms: molecule
|
|
40
|
+
}));
|
|
41
|
+
abortController.signal.throwIfAborted();
|
|
42
|
+
}
|
|
43
|
+
const promises = [];
|
|
44
|
+
promises.push(validate(values, require_types.ValidationCause.CHANGE));
|
|
45
|
+
if (get(molecule.blurred)) promises.push(validate(values, require_types.ValidationCause.BLUR));
|
|
46
|
+
if (get(molecule.submitAttempts) > 0) promises.push(validate(values, require_types.ValidationCause.SUBMIT));
|
|
47
|
+
await Promise.all(promises);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (e instanceof require_abort_error.AbortError) {}
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
return () => {
|
|
53
|
+
abortController.abort(new require_abort_error.AbortError());
|
|
54
|
+
};
|
|
55
|
+
}, [validate]);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const FormProvider = ({ children, name, ...props }) => {
|
|
59
|
+
return <require_form_molecule.FormApi.Provider scope={name}>
|
|
60
|
+
<FormStateManager {...props} />
|
|
61
|
+
{children}
|
|
62
|
+
</require_form_molecule.FormApi.Provider>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.FormProvider = FormProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormProvider.d.cts","names":[],"sources":["../../../src/form/providers/FormProvider.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"FormProvider.d.cts","names":[],"sources":["../../../src/form/providers/FormProvider.tsx"],"mappings":";;;KA6GY,oBACV,oBAAoB,sBAAsB,uBACxC,kBAAkB,YAAY;EAAiB;;cAEtC,eACX,oBAAoB,sBAAsB,uBAC1C,UAAA,SAAA,SAIC,oBAAoB,iCAAY,IAAA"}
|
|
@@ -1,5 +1,67 @@
|
|
|
1
|
-
import{useAtomEffect
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useAtomEffect } from "../../base/hooks/use-atom-effect.mjs";
|
|
2
|
+
import { FormApi } from "../molecules/form-molecule.mjs";
|
|
3
|
+
import { ValidationCause } from "../types.mjs";
|
|
4
|
+
import { useFormActions } from "../hooks/use-form-actions.mjs";
|
|
5
|
+
import { AbortError } from "../utilities/abort-error.mjs";
|
|
6
|
+
import { useHydrateAtoms } from "jotai/utils";
|
|
7
|
+
import { useEffect } from "react";
|
|
8
|
+
import { useThemeName } from "@tamagui/core";
|
|
9
|
+
import { delay } from "@stryke/async";
|
|
10
|
+
|
|
11
|
+
//#region src/form/providers/FormProvider.tsx
|
|
12
|
+
function FormStateManager(props) {
|
|
13
|
+
const { validate } = useFormActions();
|
|
14
|
+
const molecule = FormApi.useMolecule();
|
|
15
|
+
const theme = useThemeName();
|
|
16
|
+
const setOptions = FormApi.use().options.set();
|
|
17
|
+
useHydrateAtoms([[molecule.options, {
|
|
18
|
+
theme,
|
|
19
|
+
...props
|
|
20
|
+
}]]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setOptions({
|
|
23
|
+
theme,
|
|
24
|
+
...props
|
|
25
|
+
});
|
|
26
|
+
}, [setOptions]);
|
|
27
|
+
useAtomEffect((get, set) => {
|
|
28
|
+
const values = get(molecule.values);
|
|
29
|
+
const options = get(molecule.options);
|
|
30
|
+
const abortController = new AbortController();
|
|
31
|
+
(async () => {
|
|
32
|
+
try {
|
|
33
|
+
await delay(options.debounceMs);
|
|
34
|
+
abortController.signal.throwIfAborted();
|
|
35
|
+
if (options.onChange) {
|
|
36
|
+
await Promise.resolve(options.onChange({
|
|
37
|
+
get,
|
|
38
|
+
set,
|
|
39
|
+
atoms: molecule
|
|
40
|
+
}));
|
|
41
|
+
abortController.signal.throwIfAborted();
|
|
42
|
+
}
|
|
43
|
+
const promises = [];
|
|
44
|
+
promises.push(validate(values, ValidationCause.CHANGE));
|
|
45
|
+
if (get(molecule.blurred)) promises.push(validate(values, ValidationCause.BLUR));
|
|
46
|
+
if (get(molecule.submitAttempts) > 0) promises.push(validate(values, ValidationCause.SUBMIT));
|
|
47
|
+
await Promise.all(promises);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (e instanceof AbortError) {}
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
return () => {
|
|
53
|
+
abortController.abort(new AbortError());
|
|
54
|
+
};
|
|
55
|
+
}, [validate]);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const FormProvider = ({ children, name, ...props }) => {
|
|
59
|
+
return <FormApi.Provider scope={name}>
|
|
60
|
+
<FormStateManager {...props} />
|
|
61
|
+
{children}
|
|
62
|
+
</FormApi.Provider>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { FormProvider };
|
|
5
67
|
//# sourceMappingURL=FormProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormProvider.mjs","names":[
|
|
1
|
+
{"version":3,"file":"FormProvider.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_FieldProvider = require("./FieldProvider.cjs");
|
|
2
|
+
const require_FormProvider = require("./FormProvider.cjs");
|
|
3
|
+
|
|
4
|
+
exports.FieldProvider = require_FieldProvider.FieldProvider;
|
|
5
|
+
exports.FormProvider = require_FormProvider.FormProvider;
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import{FieldProvider
|
|
1
|
+
import { FieldProvider } from "./FieldProvider.mjs";
|
|
2
|
+
import { FormProvider } from "./FormProvider.mjs";
|
|
3
|
+
|
|
4
|
+
export { FieldProvider, FormProvider };
|
package/dist/form/types.cjs
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
require("@cyclone-ui/helpers");
|
|
1
|
+
require("@cyclone-ui/helpers");
|
|
2
|
+
|
|
3
|
+
//#region src/form/types.ts
|
|
4
|
+
const ValidationCause = {
|
|
5
|
+
INITIALIZE: "initialize",
|
|
6
|
+
CHANGE: "change",
|
|
7
|
+
BLUR: "blur",
|
|
8
|
+
SUBMIT: "submit",
|
|
9
|
+
SERVER: "server"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.ValidationCause = ValidationCause;
|
package/dist/form/types.mjs
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import"@cyclone-ui/helpers";
|
|
1
|
+
import "@cyclone-ui/helpers";
|
|
2
|
+
|
|
3
|
+
//#region src/form/types.ts
|
|
4
|
+
const ValidationCause = {
|
|
5
|
+
INITIALIZE: "initialize",
|
|
6
|
+
CHANGE: "change",
|
|
7
|
+
BLUR: "blur",
|
|
8
|
+
SUBMIT: "submit",
|
|
9
|
+
SERVER: "server"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ValidationCause };
|
|
2
14
|
//# sourceMappingURL=types.mjs.map
|
package/dist/form/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/form/utilities/abort-error.ts
|
|
2
|
+
/**
|
|
3
|
+
* Error used to cancel in-flight form validation when a provider unmounts.
|
|
4
|
+
*
|
|
5
|
+
* `@stryke/async` no longer exports `AbortError`.
|
|
6
|
+
*/
|
|
7
|
+
var AbortError = class extends Error {
|
|
8
|
+
name = "AbortError";
|
|
9
|
+
constructor(message = "Aborted") {
|
|
10
|
+
super(message);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.AbortError = AbortError;
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/form/utilities/abort-error.ts
|
|
2
|
+
/**
|
|
3
|
+
* Error used to cancel in-flight form validation when a provider unmounts.
|
|
4
|
+
*
|
|
5
|
+
* `@stryke/async` no longer exports `AbortError`.
|
|
6
|
+
*/
|
|
7
|
+
var AbortError = class extends Error {
|
|
8
|
+
name = "AbortError";
|
|
9
|
+
constructor(message = "Aborted") {
|
|
10
|
+
super(message);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { AbortError };
|
|
2
16
|
//# sourceMappingURL=abort-error.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abort-error.mjs","names":[
|
|
1
|
+
{"version":3,"file":"abort-error.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_is_validation_results = require("./is-validation-results.cjs");
|
|
2
|
+
const require_validators = require("./validators.cjs");
|
|
3
|
+
const require_abort_error = require("./abort-error.cjs");
|
|
4
|
+
|
|
5
|
+
exports.AbortError = require_abort_error.AbortError;
|
|
6
|
+
exports.isValidationResults = require_is_validation_results.isValidationResults;
|
|
7
|
+
exports.requiredValidator = require_validators.requiredValidator;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{isValidationResults
|
|
1
|
+
import { isValidationResults } from "./is-validation-results.mjs";
|
|
2
|
+
import { requiredValidator } from "./validators.mjs";
|
|
3
|
+
import { AbortError } from "./abort-error.mjs";
|
|
4
|
+
|
|
5
|
+
export { AbortError, isValidationResults, requiredValidator };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
let
|
|
1
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
2
|
+
|
|
3
|
+
//#region src/form/utilities/is-validation-results.ts
|
|
4
|
+
const isValidationResults = (value) => {
|
|
5
|
+
return (0, _stryke_type_checks_is_set_object.isSetObject)(value) && (Array.isArray(value.initialize) || Array.isArray(value.change) || Array.isArray(value.blur) || Array.isArray(value.submit) || Array.isArray(value.server));
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.isValidationResults = isValidationResults;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import{isSetObject
|
|
1
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
2
|
+
|
|
3
|
+
//#region src/form/utilities/is-validation-results.ts
|
|
4
|
+
const isValidationResults = (value) => {
|
|
5
|
+
return isSetObject(value) && (Array.isArray(value.initialize) || Array.isArray(value.change) || Array.isArray(value.blur) || Array.isArray(value.submit) || Array.isArray(value.server));
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isValidationResults };
|
|
2
10
|
//# sourceMappingURL=is-validation-results.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-validation-results.mjs","names":[
|
|
1
|
+
{"version":3,"file":"is-validation-results.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/form/utilities/validators.ts
|
|
2
|
+
const requiredValidator = (value) => value && !(Array.isArray(value) && value.length === 0) ? [] : [{
|
|
3
|
+
message: "This field is required",
|
|
4
|
+
type: "error"
|
|
5
|
+
}];
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.requiredValidator = requiredValidator;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/form/utilities/validators.ts
|
|
2
|
+
const requiredValidator = (value) => value && !(Array.isArray(value) && value.length === 0) ? [] : [{
|
|
3
|
+
message: "This field is required",
|
|
4
|
+
type: "error"
|
|
5
|
+
}];
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { requiredValidator };
|
|
2
9
|
//# sourceMappingURL=validators.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.mjs","names":[
|
|
1
|
+
{"version":3,"file":"validators.mjs","names":[],"sources":[],"mappings":""}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_set_atom_debug = require("./base/utilities/set-atom-debug.cjs");
|
|
3
|
+
const require_atom_with_broadcast = require("./base/atoms/atom-with-broadcast.cjs");
|
|
4
|
+
const require_atom_with_compare = require("./base/atoms/atom-with-compare.cjs");
|
|
5
|
+
const require_atom_with_wrapper = require("./base/atoms/atom-with-wrapper.cjs");
|
|
6
|
+
const require_atom_with_debounce = require("./base/atoms/atom-with-debounce.cjs");
|
|
7
|
+
const require_atom_with_effect = require("./base/atoms/atom-with-effect.cjs");
|
|
8
|
+
const require_atom_with_listeners = require("./base/atoms/atom-with-listeners.cjs");
|
|
9
|
+
const require_atom_with_pending = require("./base/atoms/atom-with-pending.cjs");
|
|
10
|
+
const require_atom_with_refresh = require("./base/atoms/atom-with-refresh.cjs");
|
|
11
|
+
const require_atom_with_refresh_and_default = require("./base/atoms/atom-with-refresh-and-default.cjs");
|
|
12
|
+
const require_atom_with_toggle = require("./base/atoms/atom-with-toggle.cjs");
|
|
13
|
+
const require_create_web_storage = require("./base/utilities/create-web-storage.cjs");
|
|
14
|
+
const require_atom_with_web_storage = require("./base/atoms/atom-with-web-storage.cjs");
|
|
15
|
+
const require_use_atom_effect = require("./base/hooks/use-atom-effect.cjs");
|
|
16
|
+
const require_use_hydrate_molecule = require("./base/hooks/use-hydrate-molecule.cjs");
|
|
17
|
+
const require_use_prepare_atoms = require("./base/hooks/use-prepare-atoms.cjs");
|
|
18
|
+
const require_use_sync_molecule = require("./base/hooks/use-sync-molecule.cjs");
|
|
19
|
+
const require_create_molecule = require("./base/utilities/create-molecule.cjs");
|
|
20
|
+
const require_debounce = require("./base/utilities/debounce.cjs");
|
|
21
|
+
require("./base/index.cjs");
|
|
22
|
+
const require_is_validation_results = require("./form/utilities/is-validation-results.cjs");
|
|
23
|
+
const require_validators = require("./form/utilities/validators.cjs");
|
|
24
|
+
const require_form_molecule = require("./form/molecules/form-molecule.cjs");
|
|
25
|
+
const require_field_molecule = require("./form/molecules/field-molecule.cjs");
|
|
26
|
+
const require_types = require("./form/types.cjs");
|
|
27
|
+
const require_use_field_actions = require("./form/hooks/use-field-actions.cjs");
|
|
28
|
+
const require_use_field_ref = require("./form/hooks/use-field-ref.cjs");
|
|
29
|
+
const require_use_form_actions = require("./form/hooks/use-form-actions.cjs");
|
|
30
|
+
const require_abort_error = require("./form/utilities/abort-error.cjs");
|
|
31
|
+
const require_FieldProvider = require("./form/providers/FieldProvider.cjs");
|
|
32
|
+
const require_FormProvider = require("./form/providers/FormProvider.cjs");
|
|
33
|
+
require("./form/index.cjs");
|
|
34
|
+
|
|
35
|
+
exports.AbortError = require_abort_error.AbortError;
|
|
36
|
+
exports.DEFAULT_FIELD_OPTIONS = require_field_molecule.DEFAULT_FIELD_OPTIONS;
|
|
37
|
+
exports.DEFAULT_FORM_OPTIONS = require_form_molecule.DEFAULT_FORM_OPTIONS;
|
|
38
|
+
exports.DEFAULT_SCOPE = require_create_molecule.DEFAULT_SCOPE;
|
|
39
|
+
exports.FieldApi = require_field_molecule.FieldApi;
|
|
40
|
+
exports.FieldProvider = require_FieldProvider.FieldProvider;
|
|
41
|
+
exports.FormApi = require_form_molecule.FormApi;
|
|
42
|
+
exports.FormProvider = require_FormProvider.FormProvider;
|
|
43
|
+
exports.ValidationCause = require_types.ValidationCause;
|
|
44
|
+
exports.atomWithBroadcast = require_atom_with_broadcast.atomWithBroadcast;
|
|
45
|
+
exports.atomWithCompare = require_atom_with_compare.atomWithCompare;
|
|
46
|
+
exports.atomWithDebounce = require_atom_with_debounce.atomWithDebounce;
|
|
47
|
+
exports.atomWithEffect = require_atom_with_effect.atomWithEffect;
|
|
48
|
+
exports.atomWithListeners = require_atom_with_listeners.atomWithListeners;
|
|
49
|
+
exports.atomWithPending = require_atom_with_pending.atomWithPending;
|
|
50
|
+
exports.atomWithRefresh = require_atom_with_refresh.atomWithRefresh;
|
|
51
|
+
exports.atomWithRefreshAndDefault = require_atom_with_refresh_and_default.atomWithRefreshAndDefault;
|
|
52
|
+
exports.atomWithToggle = require_atom_with_toggle.atomWithToggle;
|
|
53
|
+
exports.atomWithWebStorage = require_atom_with_web_storage.atomWithWebStorage;
|
|
54
|
+
exports.atomWithWrapper = require_atom_with_wrapper.atomWithWrapper;
|
|
55
|
+
exports.createMoleculeApi = require_create_molecule.createMoleculeApi;
|
|
56
|
+
exports.createScope = require_create_molecule.createScope;
|
|
57
|
+
exports.createWebStorage = require_create_web_storage.createWebStorage;
|
|
58
|
+
exports.debounce = require_debounce.debounce;
|
|
59
|
+
exports.getWebStorage = require_atom_with_web_storage.getWebStorage;
|
|
60
|
+
exports.isValidationResults = require_is_validation_results.isValidationResults;
|
|
61
|
+
exports.requiredValidator = require_validators.requiredValidator;
|
|
62
|
+
exports.setAtomDebugLabel = require_set_atom_debug.setAtomDebugLabel;
|
|
63
|
+
exports.setAtomDebugPrivate = require_set_atom_debug.setAtomDebugPrivate;
|
|
64
|
+
exports.use = require_create_molecule.use;
|
|
65
|
+
exports.useAtomEffect = require_use_atom_effect.useAtomEffect;
|
|
66
|
+
exports.useFieldActions = require_use_field_actions.useFieldActions;
|
|
67
|
+
exports.useFieldRef = require_use_field_ref.useFieldRef;
|
|
68
|
+
exports.useFormActions = require_use_form_actions.useFormActions;
|
|
69
|
+
exports.useHydrateMolecule = require_use_hydrate_molecule.useHydrateMolecule;
|
|
70
|
+
exports.usePrepareAtoms = require_use_prepare_atoms.usePrepareAtoms;
|
|
71
|
+
exports.useSyncMolecule = require_use_sync_molecule.useSyncMolecule;
|