@cyclone-ui/state 0.0.31 → 0.0.33
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 +16 -0
- package/dist/base/atoms/atom-with-broadcast.cjs +1 -44
- package/dist/base/atoms/atom-with-broadcast.mjs +1 -44
- package/dist/base/atoms/atom-with-broadcast.mjs.map +1 -1
- package/dist/base/atoms/atom-with-compare.cjs +1 -11
- package/dist/base/atoms/atom-with-compare.mjs +1 -11
- package/dist/base/atoms/atom-with-compare.mjs.map +1 -1
- package/dist/base/atoms/atom-with-debounce.cjs +1 -51
- package/dist/base/atoms/atom-with-debounce.mjs +1 -51
- package/dist/base/atoms/atom-with-debounce.mjs.map +1 -1
- package/dist/base/atoms/atom-with-effect.cjs +1 -122
- package/dist/base/atoms/atom-with-effect.mjs +1 -119
- package/dist/base/atoms/atom-with-effect.mjs.map +1 -1
- package/dist/base/atoms/atom-with-listeners.cjs +1 -35
- package/dist/base/atoms/atom-with-listeners.mjs +1 -35
- package/dist/base/atoms/atom-with-listeners.mjs.map +1 -1
- package/dist/base/atoms/atom-with-pending.cjs +1 -13
- package/dist/base/atoms/atom-with-pending.mjs +1 -13
- package/dist/base/atoms/atom-with-pending.mjs.map +1 -1
- package/dist/base/atoms/atom-with-refresh-and-default.cjs +1 -18
- package/dist/base/atoms/atom-with-refresh-and-default.mjs +1 -18
- package/dist/base/atoms/atom-with-refresh-and-default.mjs.map +1 -1
- package/dist/base/atoms/atom-with-refresh.cjs +1 -12
- package/dist/base/atoms/atom-with-refresh.mjs +1 -12
- package/dist/base/atoms/atom-with-refresh.mjs.map +1 -1
- package/dist/base/atoms/atom-with-toggle.cjs +1 -12
- package/dist/base/atoms/atom-with-toggle.mjs +1 -12
- package/dist/base/atoms/atom-with-toggle.mjs.map +1 -1
- package/dist/base/atoms/atom-with-web-storage.cjs +1 -47
- package/dist/base/atoms/atom-with-web-storage.mjs +1 -46
- package/dist/base/atoms/atom-with-web-storage.mjs.map +1 -1
- package/dist/base/atoms/atom-with-wrapper.cjs +1 -24
- package/dist/base/atoms/atom-with-wrapper.mjs +1 -24
- package/dist/base/atoms/atom-with-wrapper.mjs.map +1 -1
- package/dist/base/atoms/base-atom.cjs +1 -24
- package/dist/base/atoms/base-atom.mjs +1 -24
- package/dist/base/atoms/base-atom.mjs.map +1 -1
- package/dist/base/atoms/index.cjs +1 -24
- package/dist/base/atoms/index.mjs +1 -13
- package/dist/base/hooks/index.cjs +1 -9
- package/dist/base/hooks/index.mjs +1 -6
- package/dist/base/hooks/use-atom-effect.cjs +1 -16
- package/dist/base/hooks/use-atom-effect.mjs +1 -16
- package/dist/base/hooks/use-atom-effect.mjs.map +1 -1
- package/dist/base/hooks/use-hydrate-molecule.cjs +1 -16
- package/dist/base/hooks/use-hydrate-molecule.mjs +1 -16
- package/dist/base/hooks/use-hydrate-molecule.mjs.map +1 -1
- package/dist/base/hooks/use-prepare-atoms.cjs +1 -19
- package/dist/base/hooks/use-prepare-atoms.mjs +1 -19
- package/dist/base/hooks/use-prepare-atoms.mjs.map +1 -1
- package/dist/base/hooks/use-sync-molecule.cjs +1 -36
- package/dist/base/hooks/use-sync-molecule.mjs +1 -36
- package/dist/base/hooks/use-sync-molecule.mjs.map +1 -1
- package/dist/base/index.cjs +1 -47
- package/dist/base/index.mjs +1 -24
- package/dist/base/utilities/create-molecule.cjs +1 -104
- package/dist/base/utilities/create-molecule.mjs +1 -101
- package/dist/base/utilities/create-molecule.mjs.map +1 -1
- package/dist/base/utilities/create-web-storage.cjs +1 -54
- package/dist/base/utilities/create-web-storage.mjs +1 -54
- package/dist/base/utilities/create-web-storage.mjs.map +1 -1
- package/dist/base/utilities/debounce.cjs +1 -51
- package/dist/base/utilities/debounce.mjs +1 -51
- package/dist/base/utilities/debounce.mjs.map +1 -1
- package/dist/base/utilities/index.cjs +1 -13
- package/dist/base/utilities/index.mjs +1 -6
- package/dist/base/utilities/is-atom.cjs +1 -47
- package/dist/base/utilities/is-atom.mjs +1 -45
- package/dist/base/utilities/is-atom.mjs.map +1 -1
- package/dist/base/utilities/set-atom-debug.cjs +1 -23
- package/dist/base/utilities/set-atom-debug.mjs +1 -22
- package/dist/base/utilities/set-atom-debug.mjs.map +1 -1
- package/dist/form/atoms/atom-with-field.cjs +1 -22
- package/dist/form/atoms/atom-with-field.mjs +1 -22
- package/dist/form/atoms/atom-with-field.mjs.map +1 -1
- package/dist/form/atoms/atom-with-messages.cjs +1 -84
- package/dist/form/atoms/atom-with-messages.mjs +1 -77
- package/dist/form/atoms/atom-with-messages.mjs.map +1 -1
- package/dist/form/hooks/index.cjs +1 -7
- package/dist/form/hooks/index.mjs +1 -5
- package/dist/form/hooks/use-field-actions.cjs +1 -91
- package/dist/form/hooks/use-field-actions.mjs +1 -91
- package/dist/form/hooks/use-field-actions.mjs.map +1 -1
- package/dist/form/hooks/use-field-ref.cjs +1 -15
- package/dist/form/hooks/use-field-ref.mjs +1 -15
- package/dist/form/hooks/use-field-ref.mjs.map +1 -1
- package/dist/form/hooks/use-form-actions.cjs +1 -68
- package/dist/form/hooks/use-form-actions.mjs +1 -68
- package/dist/form/hooks/use-form-actions.mjs.map +1 -1
- package/dist/form/index.cjs +1 -30
- package/dist/form/index.mjs +1 -17
- package/dist/form/molecules/field-molecule.cjs +1 -156
- package/dist/form/molecules/field-molecule.mjs +1 -155
- package/dist/form/molecules/field-molecule.mjs.map +1 -1
- package/dist/form/molecules/form-molecule.cjs +1 -179
- package/dist/form/molecules/form-molecule.mjs +1 -178
- package/dist/form/molecules/form-molecule.mjs.map +1 -1
- package/dist/form/molecules/index.cjs +1 -7
- package/dist/form/molecules/index.mjs +1 -4
- package/dist/form/providers/FieldProvider.cjs +1 -102
- package/dist/form/providers/FieldProvider.mjs +1 -102
- package/dist/form/providers/FieldProvider.mjs.map +1 -1
- package/dist/form/providers/FormProvider.cjs +1 -65
- package/dist/form/providers/FormProvider.mjs +1 -65
- package/dist/form/providers/FormProvider.mjs.map +1 -1
- package/dist/form/providers/index.cjs +1 -5
- package/dist/form/providers/index.mjs +1 -4
- package/dist/form/types.cjs +1 -12
- package/dist/form/types.mjs +1 -12
- package/dist/form/types.mjs.map +1 -1
- package/dist/form/utilities/abort-error.cjs +1 -14
- package/dist/form/utilities/abort-error.mjs +1 -14
- package/dist/form/utilities/abort-error.mjs.map +1 -1
- package/dist/form/utilities/index.cjs +1 -7
- package/dist/form/utilities/index.mjs +1 -5
- package/dist/form/utilities/is-validation-results.cjs +1 -8
- package/dist/form/utilities/is-validation-results.mjs +1 -8
- package/dist/form/utilities/is-validation-results.mjs.map +1 -1
- package/dist/form/utilities/validators.cjs +1 -7
- package/dist/form/utilities/validators.mjs +1 -7
- package/dist/form/utilities/validators.mjs.map +1 -1
- package/dist/index.cjs +1 -46
- package/dist/index.mjs +1 -22
- package/dist/message/components/MessageViewport.cjs +1 -20
- package/dist/message/components/MessageViewport.mjs +1 -20
- package/dist/message/components/MessageViewport.mjs.map +1 -1
- package/dist/message/components/index.cjs +1 -3
- package/dist/message/components/index.mjs +1 -3
- package/dist/message/hooks/index.cjs +1 -3
- package/dist/message/hooks/index.mjs +1 -3
- package/dist/message/hooks/use-message-actions.cjs +1 -63
- package/dist/message/hooks/use-message-actions.mjs +1 -63
- package/dist/message/hooks/use-message-actions.mjs.map +1 -1
- package/dist/message/index.cjs +1 -23
- package/dist/message/index.mjs +1 -8
- package/dist/message/providers/MessageProvider.cjs +1 -15
- package/dist/message/providers/MessageProvider.mjs +1 -15
- package/dist/message/providers/MessageProvider.mjs.map +1 -1
- package/dist/theme/hooks/index.cjs +1 -7
- package/dist/theme/hooks/index.mjs +1 -4
- package/dist/theme/hooks/use-theme-actions.cjs +1 -20
- package/dist/theme/hooks/use-theme-actions.mjs +1 -20
- package/dist/theme/hooks/use-theme-actions.mjs.map +1 -1
- package/dist/theme/hooks/use-theme-store.cjs +1 -60
- package/dist/theme/hooks/use-theme-store.mjs +1 -58
- package/dist/theme/hooks/use-theme-store.mjs.map +1 -1
- package/dist/theme/index.cjs +1 -17
- package/dist/theme/index.mjs +1 -9
- package/dist/theme/molecules/index.cjs +1 -3
- package/dist/theme/molecules/index.mjs +1 -3
- package/dist/theme/molecules/theme-molecule.cjs +1 -13
- package/dist/theme/molecules/theme-molecule.mjs +1 -13
- package/dist/theme/molecules/theme-molecule.mjs.map +1 -1
- package/dist/theme/providers/ThemeProvider.cjs +1 -29
- package/dist/theme/providers/ThemeProvider.mjs +1 -29
- package/dist/theme/providers/ThemeProvider.mjs.map +1 -1
- package/dist/theme/utilities/theme-helpers.cjs +1 -70
- package/dist/theme/utilities/theme-helpers.mjs +1 -69
- package/dist/theme/utilities/theme-helpers.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,68 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_types = require("../types.cjs");
|
|
3
|
-
let jotai_utils = require("jotai/utils");
|
|
4
|
-
let react = require("react");
|
|
5
|
-
let _stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
|
|
6
|
-
let _stryke_string_format_upper_case_first = require("@stryke/string-format/upper-case-first");
|
|
7
|
-
|
|
8
|
-
// src/form/hooks/use-form-actions.ts
|
|
9
|
-
const useFormActions = () => {
|
|
10
|
-
const form = require_form_molecule.FormApi.useMolecule();
|
|
11
|
-
return {
|
|
12
|
-
initializeField: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (_get, _set, _name) => {}, [])),
|
|
13
|
-
uninitializeField: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (_get, _set, _name) => {}, [])),
|
|
14
|
-
validate: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValues, cause) => {
|
|
15
|
-
const options = get(form.options);
|
|
16
|
-
if (options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].length > 0 || options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`].length > 0) {
|
|
17
|
-
const previousValues = get(form.previousValues);
|
|
18
|
-
const results = [];
|
|
19
|
-
if (options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].length > 0) results.push(...options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
|
|
20
|
-
if (cause !== require_types.ValidationCause.INITIALIZE && options.validate?.[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`] && options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`].length > 0) results.push(...options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(require_types.ValidationCause.INITIALIZE)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
|
|
21
|
-
const messages = [];
|
|
22
|
-
const promises = [];
|
|
23
|
-
for (const result of results) if (result) {
|
|
24
|
-
if ((0, _stryke_type_checks_is_promise.isPromise)(result)) promises.push(result);
|
|
25
|
-
else messages.push(...result);
|
|
26
|
-
}
|
|
27
|
-
if (promises.length > 0) {
|
|
28
|
-
set(form.formValidating, true);
|
|
29
|
-
for (const result of await Promise.all(promises)) if (result && result.length > 0) messages.push(...result);
|
|
30
|
-
set(form.formValidating, false);
|
|
31
|
-
}
|
|
32
|
-
set(form.validationResults, (prev) => ({
|
|
33
|
-
...prev,
|
|
34
|
-
[cause]: messages
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
}, [])),
|
|
38
|
-
change: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValues) => {
|
|
39
|
-
const options = get(form.options);
|
|
40
|
-
const values = get(form.values);
|
|
41
|
-
if (!options.isEqual(nextValues, values)) set(form.values, nextValues);
|
|
42
|
-
}, [])),
|
|
43
|
-
submit: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set) => {
|
|
44
|
-
if (get(form.canSubmit)) {
|
|
45
|
-
if (!get(form.submitting)) set(form.submitting, true);
|
|
46
|
-
set(form.submitAttempts, (prev) => prev + 1);
|
|
47
|
-
const options = get(form.options);
|
|
48
|
-
try {
|
|
49
|
-
if (get(form.valid)) {
|
|
50
|
-
await options.onSubmit?.({
|
|
51
|
-
get,
|
|
52
|
-
set,
|
|
53
|
-
atoms: form
|
|
54
|
-
});
|
|
55
|
-
set(form.submitted, true);
|
|
56
|
-
}
|
|
57
|
-
} finally {
|
|
58
|
-
set(form.submitting, false);
|
|
59
|
-
}
|
|
60
|
-
} else if (get(form.invalid)) {
|
|
61
|
-
if (get(form.invalid)) {}
|
|
62
|
-
}
|
|
63
|
-
}, [])),
|
|
64
|
-
reset: (0, react.useCallback)(() => {}, [])
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
exports.useFormActions = useFormActions;
|
|
1
|
+
const e=require("../molecules/form-molecule.cjs"),t=require("../types.cjs");let n=require("jotai/utils"),r=require("react"),i=require("@stryke/type-checks/is-promise"),a=require("@stryke/string-format/upper-case-first");const o=()=>{let o=e.FormApi.useMolecule();return{initializeField:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n)=>{},[])),uninitializeField:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n)=>{},[])),validate:(0,n.useAtomCallback)((0,r.useCallback)(async(e,n,r,s)=>{let c=e(o.options);if(c.validate?.[`on${(0,a.upperCaseFirst)(s)}`]&&c.validate[`on${(0,a.upperCaseFirst)(s)}`].length>0||c.validate?.[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`]&&c.validate[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`].length>0){let l=e(o.previousValues),u=[];c.validate?.[`on${(0,a.upperCaseFirst)(s)}`]&&c.validate[`on${(0,a.upperCaseFirst)(s)}`].length>0&&u.push(...c.validate[`on${(0,a.upperCaseFirst)(s)}`].map(t=>t(r,l,s,e,n))),s!==t.ValidationCause.INITIALIZE&&c.validate?.[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`]&&c.validate[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`].length>0&&u.push(...c.validate[`on${(0,a.upperCaseFirst)(t.ValidationCause.INITIALIZE)}`].map(t=>t(r,l,s,e,n)));let d=[],f=[];for(let e of u)e&&((0,i.isPromise)(e)?f.push(e):d.push(...e));if(f.length>0){n(o.formValidating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(o.formValidating,!1)}n(o.validationResults,e=>({...e,[s]:d}))}},[])),change:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t,n)=>{let r=e(o.options),i=e(o.values);r.isEqual(n,i)||t(o.values,n)},[])),submit:(0,n.useAtomCallback)((0,r.useCallback)(async(e,t)=>{if(e(o.canSubmit)){e(o.submitting)||t(o.submitting,!0),t(o.submitAttempts,e=>e+1);let n=e(o.options);try{e(o.valid)&&(await n.onSubmit?.({get:e,set:t,atoms:o}),t(o.submitted,!0))}finally{t(o.submitting,!1)}}else e(o.invalid)&&e(o.invalid)},[])),reset:(0,r.useCallback)(()=>{},[])}};exports.useFormActions=o;
|
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ValidationCause } from "../types.mjs";
|
|
3
|
-
import { useAtomCallback } from "jotai/utils";
|
|
4
|
-
import { useCallback } from "react";
|
|
5
|
-
import { isPromise } from "@stryke/type-checks/is-promise";
|
|
6
|
-
import { upperCaseFirst } from "@stryke/string-format/upper-case-first";
|
|
7
|
-
|
|
8
|
-
// src/form/hooks/use-form-actions.ts
|
|
9
|
-
const useFormActions = () => {
|
|
10
|
-
const form = FormApi.useMolecule();
|
|
11
|
-
return {
|
|
12
|
-
initializeField: useAtomCallback(useCallback(async (_get, _set, _name) => {}, [])),
|
|
13
|
-
uninitializeField: useAtomCallback(useCallback(async (_get, _set, _name) => {}, [])),
|
|
14
|
-
validate: useAtomCallback(useCallback(async (get, set, nextValues, cause) => {
|
|
15
|
-
const options = get(form.options);
|
|
16
|
-
if (options.validate?.[`on${upperCaseFirst(cause)}`] && options.validate[`on${upperCaseFirst(cause)}`].length > 0 || options.validate?.[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`] && options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].length > 0) {
|
|
17
|
-
const previousValues = get(form.previousValues);
|
|
18
|
-
const results = [];
|
|
19
|
-
if (options.validate?.[`on${upperCaseFirst(cause)}`] && options.validate[`on${upperCaseFirst(cause)}`].length > 0) results.push(...options.validate[`on${upperCaseFirst(cause)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
|
|
20
|
-
if (cause !== ValidationCause.INITIALIZE && options.validate?.[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`] && options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].length > 0) results.push(...options.validate[`on${upperCaseFirst(ValidationCause.INITIALIZE)}`].map((validator) => validator(nextValues, previousValues, cause, get, set)));
|
|
21
|
-
const messages = [];
|
|
22
|
-
const promises = [];
|
|
23
|
-
for (const result of results) if (result) {
|
|
24
|
-
if (isPromise(result)) promises.push(result);
|
|
25
|
-
else messages.push(...result);
|
|
26
|
-
}
|
|
27
|
-
if (promises.length > 0) {
|
|
28
|
-
set(form.formValidating, true);
|
|
29
|
-
for (const result of await Promise.all(promises)) if (result && result.length > 0) messages.push(...result);
|
|
30
|
-
set(form.formValidating, false);
|
|
31
|
-
}
|
|
32
|
-
set(form.validationResults, (prev) => ({
|
|
33
|
-
...prev,
|
|
34
|
-
[cause]: messages
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
}, [])),
|
|
38
|
-
change: useAtomCallback(useCallback(async (get, set, nextValues) => {
|
|
39
|
-
const options = get(form.options);
|
|
40
|
-
const values = get(form.values);
|
|
41
|
-
if (!options.isEqual(nextValues, values)) set(form.values, nextValues);
|
|
42
|
-
}, [])),
|
|
43
|
-
submit: useAtomCallback(useCallback(async (get, set) => {
|
|
44
|
-
if (get(form.canSubmit)) {
|
|
45
|
-
if (!get(form.submitting)) set(form.submitting, true);
|
|
46
|
-
set(form.submitAttempts, (prev) => prev + 1);
|
|
47
|
-
const options = get(form.options);
|
|
48
|
-
try {
|
|
49
|
-
if (get(form.valid)) {
|
|
50
|
-
await options.onSubmit?.({
|
|
51
|
-
get,
|
|
52
|
-
set,
|
|
53
|
-
atoms: form
|
|
54
|
-
});
|
|
55
|
-
set(form.submitted, true);
|
|
56
|
-
}
|
|
57
|
-
} finally {
|
|
58
|
-
set(form.submitting, false);
|
|
59
|
-
}
|
|
60
|
-
} else if (get(form.invalid)) {
|
|
61
|
-
if (get(form.invalid)) {}
|
|
62
|
-
}
|
|
63
|
-
}, [])),
|
|
64
|
-
reset: useCallback(() => {}, [])
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { useFormActions };
|
|
1
|
+
import{FormApi as e}from"../molecules/form-molecule.mjs";import{ValidationCause as t}from"../types.mjs";import{useAtomCallback as n}from"jotai/utils";import{useCallback as r}from"react";import{isPromise as i}from"@stryke/type-checks/is-promise";import{upperCaseFirst as a}from"@stryke/string-format/upper-case-first";const o=()=>{let o=e.useMolecule();return{initializeField:n(r(async(e,t,n)=>{},[])),uninitializeField:n(r(async(e,t,n)=>{},[])),validate:n(r(async(e,n,r,s)=>{let c=e(o.options);if(c.validate?.[`on${a(s)}`]&&c.validate[`on${a(s)}`].length>0||c.validate?.[`on${a(t.INITIALIZE)}`]&&c.validate[`on${a(t.INITIALIZE)}`].length>0){let l=e(o.previousValues),u=[];c.validate?.[`on${a(s)}`]&&c.validate[`on${a(s)}`].length>0&&u.push(...c.validate[`on${a(s)}`].map(t=>t(r,l,s,e,n))),s!==t.INITIALIZE&&c.validate?.[`on${a(t.INITIALIZE)}`]&&c.validate[`on${a(t.INITIALIZE)}`].length>0&&u.push(...c.validate[`on${a(t.INITIALIZE)}`].map(t=>t(r,l,s,e,n)));let d=[],f=[];for(let e of u)e&&(i(e)?f.push(e):d.push(...e));if(f.length>0){n(o.formValidating,!0);for(let e of await Promise.all(f))e&&e.length>0&&d.push(...e);n(o.formValidating,!1)}n(o.validationResults,e=>({...e,[s]:d}))}},[])),change:n(r(async(e,t,n)=>{let r=e(o.options),i=e(o.values);r.isEqual(n,i)||t(o.values,n)},[])),submit:n(r(async(e,t)=>{if(e(o.canSubmit)){e(o.submitting)||t(o.submitting,!0),t(o.submitAttempts,e=>e+1);let n=e(o.options);try{e(o.valid)&&(await n.onSubmit?.({get:e,set:t,atoms:o}),t(o.submitted,!0))}finally{t(o.submitting,!1)}}else e(o.invalid)&&e(o.invalid)},[])),reset:r(()=>{},[])}};export{o as useFormActions};
|
|
69
2
|
//# sourceMappingURL=use-form-actions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-form-actions.mjs","names":[],"sources":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"use-form-actions.mjs","names":["useFormActions","form","FormApi","useAtomCallback","useCallback","options","get","upperCaseFirst","cause","ValidationCause","previousValues","results","validator","nextValues","set","messages","promises","result","isPromise","prev","values"],"sources":[],"mappings":""}
|
package/dist/form/index.cjs
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_is_validation_results = require("./utilities/is-validation-results.cjs");
|
|
3
|
-
const require_validators = require("./utilities/validators.cjs");
|
|
4
|
-
const require_form_molecule = require("./molecules/form-molecule.cjs");
|
|
5
|
-
const require_field_molecule = require("./molecules/field-molecule.cjs");
|
|
6
|
-
const require_types = require("./types.cjs");
|
|
7
|
-
const require_use_field_actions = require("./hooks/use-field-actions.cjs");
|
|
8
|
-
const require_use_field_ref = require("./hooks/use-field-ref.cjs");
|
|
9
|
-
const require_use_form_actions = require("./hooks/use-form-actions.cjs");
|
|
10
|
-
require("./hooks/index.cjs");
|
|
11
|
-
require("./molecules/index.cjs");
|
|
12
|
-
const require_abort_error = require("./utilities/abort-error.cjs");
|
|
13
|
-
const require_FieldProvider = require("./providers/FieldProvider.cjs");
|
|
14
|
-
const require_FormProvider = require("./providers/FormProvider.cjs");
|
|
15
|
-
require("./providers/index.cjs");
|
|
16
|
-
require("./utilities/index.cjs");
|
|
17
|
-
|
|
18
|
-
exports.AbortError = require_abort_error.AbortError;
|
|
19
|
-
exports.DEFAULT_FIELD_OPTIONS = require_field_molecule.DEFAULT_FIELD_OPTIONS;
|
|
20
|
-
exports.DEFAULT_FORM_OPTIONS = require_form_molecule.DEFAULT_FORM_OPTIONS;
|
|
21
|
-
exports.FieldApi = require_field_molecule.FieldApi;
|
|
22
|
-
exports.FieldProvider = require_FieldProvider.FieldProvider;
|
|
23
|
-
exports.FormApi = require_form_molecule.FormApi;
|
|
24
|
-
exports.FormProvider = require_FormProvider.FormProvider;
|
|
25
|
-
exports.ValidationCause = require_types.ValidationCause;
|
|
26
|
-
exports.isValidationResults = require_is_validation_results.isValidationResults;
|
|
27
|
-
exports.requiredValidator = require_validators.requiredValidator;
|
|
28
|
-
exports.useFieldActions = require_use_field_actions.useFieldActions;
|
|
29
|
-
exports.useFieldRef = require_use_field_ref.useFieldRef;
|
|
30
|
-
exports.useFormActions = require_use_form_actions.useFormActions;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utilities/is-validation-results.cjs"),t=require("./utilities/validators.cjs"),n=require("./molecules/form-molecule.cjs"),r=require("./molecules/field-molecule.cjs"),i=require("./types.cjs"),a=require("./hooks/use-field-actions.cjs"),o=require("./hooks/use-field-ref.cjs"),s=require("./hooks/use-form-actions.cjs");require("./hooks/index.cjs"),require("./molecules/index.cjs");const c=require("./utilities/abort-error.cjs"),l=require("./providers/FieldProvider.cjs"),u=require("./providers/FormProvider.cjs");require("./providers/index.cjs"),require("./utilities/index.cjs"),exports.AbortError=c.AbortError,exports.DEFAULT_FIELD_OPTIONS=r.DEFAULT_FIELD_OPTIONS,exports.DEFAULT_FORM_OPTIONS=n.DEFAULT_FORM_OPTIONS,exports.FieldApi=r.FieldApi,exports.FieldProvider=l.FieldProvider,exports.FormApi=n.FormApi,exports.FormProvider=u.FormProvider,exports.ValidationCause=i.ValidationCause,exports.isValidationResults=e.isValidationResults,exports.requiredValidator=t.requiredValidator,exports.useFieldActions=a.useFieldActions,exports.useFieldRef=o.useFieldRef,exports.useFormActions=s.useFormActions;
|
package/dist/form/index.mjs
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { requiredValidator } from "./utilities/validators.mjs";
|
|
3
|
-
import { DEFAULT_FORM_OPTIONS, FormApi } from "./molecules/form-molecule.mjs";
|
|
4
|
-
import { DEFAULT_FIELD_OPTIONS, FieldApi } from "./molecules/field-molecule.mjs";
|
|
5
|
-
import { ValidationCause } from "./types.mjs";
|
|
6
|
-
import { useFieldActions } from "./hooks/use-field-actions.mjs";
|
|
7
|
-
import { useFieldRef } from "./hooks/use-field-ref.mjs";
|
|
8
|
-
import { useFormActions } from "./hooks/use-form-actions.mjs";
|
|
9
|
-
import "./hooks/index.mjs";
|
|
10
|
-
import "./molecules/index.mjs";
|
|
11
|
-
import { AbortError } from "./utilities/abort-error.mjs";
|
|
12
|
-
import { FieldProvider } from "./providers/FieldProvider.mjs";
|
|
13
|
-
import { FormProvider } from "./providers/FormProvider.mjs";
|
|
14
|
-
import "./providers/index.mjs";
|
|
15
|
-
import "./utilities/index.mjs";
|
|
16
|
-
|
|
17
|
-
export { AbortError, DEFAULT_FIELD_OPTIONS, DEFAULT_FORM_OPTIONS, FieldApi, FieldProvider, FormApi, FormProvider, ValidationCause, isValidationResults, requiredValidator, useFieldActions, useFieldRef, useFormActions };
|
|
1
|
+
import{isValidationResults as e}from"./utilities/is-validation-results.mjs";import{requiredValidator as t}from"./utilities/validators.mjs";import{DEFAULT_FORM_OPTIONS as n,FormApi as r}from"./molecules/form-molecule.mjs";import{DEFAULT_FIELD_OPTIONS as i,FieldApi as a}from"./molecules/field-molecule.mjs";import{ValidationCause as o}from"./types.mjs";import{useFieldActions as s}from"./hooks/use-field-actions.mjs";import{useFieldRef as c}from"./hooks/use-field-ref.mjs";import{useFormActions as l}from"./hooks/use-form-actions.mjs";import"./hooks/index.mjs";import"./molecules/index.mjs";import{AbortError as u}from"./utilities/abort-error.mjs";import{FieldProvider as d}from"./providers/FieldProvider.mjs";import{FormProvider as f}from"./providers/FormProvider.mjs";import"./providers/index.mjs";import"./utilities/index.mjs";export{u as AbortError,i as DEFAULT_FIELD_OPTIONS,n as DEFAULT_FORM_OPTIONS,a as FieldApi,d as FieldProvider,r as FormApi,f as FormProvider,o as ValidationCause,e as isValidationResults,t as requiredValidator,s as useFieldActions,c as useFieldRef,l as useFormActions};
|
|
@@ -1,156 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
require("../../base/index.cjs");
|
|
3
|
-
const require_atom_with_field = require("../atoms/atom-with-field.cjs");
|
|
4
|
-
const require_atom_with_messages = require("../atoms/atom-with-messages.cjs");
|
|
5
|
-
const require_validators = require("../utilities/validators.cjs");
|
|
6
|
-
const require_form_molecule = require("./form-molecule.cjs");
|
|
7
|
-
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
8
|
-
let jotai_utils = require("jotai/utils");
|
|
9
|
-
let _stryke_helpers_is_equal = require("@stryke/helpers/is-equal");
|
|
10
|
-
let jotai = require("jotai");
|
|
11
|
-
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
12
|
-
let _stryke_helpers_deep_merge = require("@stryke/helpers/deep-merge");
|
|
13
|
-
let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
|
|
14
|
-
let _stryke_helpers_to_path = require("@stryke/helpers/to-path");
|
|
15
|
-
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
16
|
-
let jotai_optics = require("jotai-optics");
|
|
17
|
-
|
|
18
|
-
// src/form/molecules/field-molecule.ts
|
|
19
|
-
const DEFAULT_FIELD_OPTIONS = {
|
|
20
|
-
theme: "base",
|
|
21
|
-
size: "md",
|
|
22
|
-
debounceMs: 100,
|
|
23
|
-
isEqual: _stryke_helpers_is_equal.isEqual,
|
|
24
|
-
required: false,
|
|
25
|
-
disabled: false,
|
|
26
|
-
clearable: false,
|
|
27
|
-
initialValue: null
|
|
28
|
-
};
|
|
29
|
-
const FieldApi = require_create_molecule.createMoleculeApi((scope) => {
|
|
30
|
-
const formScope = require_create_molecule.use(require_form_molecule.FormApi.Scope);
|
|
31
|
-
const formScopeAtom = (0, jotai.atom)(() => formScope);
|
|
32
|
-
const form = require_create_molecule.use(require_form_molecule.FormApi.Molecule);
|
|
33
|
-
const optionsBaseAtom = (0, jotai.atom)(DEFAULT_FIELD_OPTIONS);
|
|
34
|
-
const optionsAtom = (0, jotai.atom)((get) => {
|
|
35
|
-
const formOptions = get(form.options);
|
|
36
|
-
const options = get(optionsBaseAtom);
|
|
37
|
-
const result = (0, _stryke_helpers_deep_merge.deepMerge)(formOptions.defaultFieldOptions, options);
|
|
38
|
-
return (0, _stryke_helpers_deep_merge.deepMerge)({ validate: { onBlur: result.required ? [require_validators.requiredValidator] : [] } }, result);
|
|
39
|
-
}, (get, set, update) => {
|
|
40
|
-
let nextValue = {};
|
|
41
|
-
if ((0, _stryke_type_checks_is_function.isFunction)(update)) nextValue = update(get(optionsBaseAtom));
|
|
42
|
-
else if (update === jotai_utils.RESET) nextValue = {};
|
|
43
|
-
else nextValue = update;
|
|
44
|
-
set(optionsBaseAtom, (0, _stryke_helpers_deep_merge.deepMerge)(DEFAULT_FIELD_OPTIONS, nextValue));
|
|
45
|
-
});
|
|
46
|
-
const formPrefix = `${formScope}-`;
|
|
47
|
-
const path = (0, _stryke_helpers_to_path.toPath)(scope.startsWith(formPrefix) ? scope.slice(formPrefix.length) : scope.includes("-") ? scope.slice(scope.indexOf("-") + 1) : scope);
|
|
48
|
-
const pathAtom = (0, jotai.atom)(() => path);
|
|
49
|
-
const nameAtom = (0, jotai.atom)((get) => get(pathAtom).slice(-1)[0]);
|
|
50
|
-
const focusedAtom = (0, jotai_optics.focusAtom)(form.focusedFields, (optic) => optic.path(...path));
|
|
51
|
-
const requiredStateAtom = (0, jotai_optics.focusAtom)(form.requiredFields, (optic) => optic.path(...path));
|
|
52
|
-
const disabledStateAtom = (0, jotai_optics.focusAtom)(form.disabledFields, (optic) => optic.path(...path));
|
|
53
|
-
const requiredAtom = (0, jotai.atom)((get) => get(requiredStateAtom) ?? get(optionsAtom).required, (_get, set, update) => {
|
|
54
|
-
set(requiredStateAtom, update);
|
|
55
|
-
});
|
|
56
|
-
const disabledAtom = (0, jotai.atom)((get) => get(disabledStateAtom) ?? get(optionsAtom).disabled, (_get, set, update) => {
|
|
57
|
-
set(disabledStateAtom, update);
|
|
58
|
-
});
|
|
59
|
-
const clearableAtom = (0, jotai.atom)((get) => get(optionsAtom).clearable);
|
|
60
|
-
const touchedAtom = (0, jotai_optics.focusAtom)(form.touchedFields, (optic) => optic.path(...path));
|
|
61
|
-
const blurredAtom = (0, jotai_optics.focusAtom)(form.blurredFields, (optic) => optic.path(...path));
|
|
62
|
-
const validatingAtom = (0, jotai_optics.focusAtom)(form.validatingFields, (optic) => optic.path(...path));
|
|
63
|
-
const validationResultsAtom = (0, jotai_optics.focusAtom)(form.validationResultsFields, (optic) => optic.path(...path));
|
|
64
|
-
const tabIndexAtom = (0, jotai_optics.focusAtom)(form.tabIndexes, (optic) => optic.path(...path));
|
|
65
|
-
const refAtom = (0, jotai_optics.focusAtom)(form.refs, (optic) => optic.path(...path));
|
|
66
|
-
const initialValueAtom = (0, jotai_optics.focusAtom)(form.initialValues, (optic) => optic.path(...path));
|
|
67
|
-
const valueAtom = (0, jotai_optics.focusAtom)(form.values, (optic) => optic.path(...path));
|
|
68
|
-
const dirtyAtom = (0, jotai.atom)((get) => {
|
|
69
|
-
return get(optionsAtom).isEqual(get(valueAtom), get(initialValueAtom));
|
|
70
|
-
});
|
|
71
|
-
const showErrorsAtom = (0, jotai.atom)((get) => Boolean(get(optionsAtom).showErrorsBeforeBlur) || Boolean(get(blurredAtom)) || get(form.submitAttempts) > 0);
|
|
72
|
-
const allErrorsAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "danger");
|
|
73
|
-
const errorsAtom = (0, jotai.atom)((get) => get(showErrorsAtom) ? get(allErrorsAtom) : []);
|
|
74
|
-
const warningsAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "warning");
|
|
75
|
-
const infoAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "info");
|
|
76
|
-
const discoveryAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "discovery");
|
|
77
|
-
const successesAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "success");
|
|
78
|
-
const positivesAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "positive");
|
|
79
|
-
const negativesAtom = require_atom_with_messages.atomWithFieldsMessageTypes(validationResultsAtom, "negative");
|
|
80
|
-
const allErrorMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "danger");
|
|
81
|
-
const errorMessagesAtom = (0, jotai.atom)((get) => get(showErrorsAtom) ? get(allErrorMessagesAtom) : []);
|
|
82
|
-
const warningMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "warning");
|
|
83
|
-
const infoMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "info");
|
|
84
|
-
const discoveryMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "discovery");
|
|
85
|
-
const successMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "success");
|
|
86
|
-
const positiveMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "positive");
|
|
87
|
-
const negativeMessagesAtom = require_atom_with_messages.atomWithFieldsMessageList(validationResultsAtom, "negative");
|
|
88
|
-
const invalidAtom = (0, jotai.atom)((get) => {
|
|
89
|
-
return get(errorMessagesAtom).length > 0;
|
|
90
|
-
});
|
|
91
|
-
const validAtom = (0, jotai.atom)((get) => !get(invalidAtom));
|
|
92
|
-
const formattedValueAtom = (0, jotai.atom)((get) => {
|
|
93
|
-
const options = get(optionsAtom);
|
|
94
|
-
const value = get(valueAtom);
|
|
95
|
-
let formattedValue;
|
|
96
|
-
if (options?.format) formattedValue = options.format(value);
|
|
97
|
-
else formattedValue = value;
|
|
98
|
-
if (!(0, _stryke_type_checks_is_set.isSet)(formattedValue)) return "";
|
|
99
|
-
else if ((0, _stryke_type_checks_is_string.isString)(formattedValue)) return formattedValue;
|
|
100
|
-
return String(formattedValue);
|
|
101
|
-
});
|
|
102
|
-
const itemsAtom = require_atom_with_field.atomWithFieldItems(optionsAtom, valueAtom, disabledAtom);
|
|
103
|
-
const itemsAtomsAtom = (0, jotai_utils.splitAtom)(itemsAtom);
|
|
104
|
-
const sizeAtom = (0, jotai_utils.atomWithDefault)((get) => {
|
|
105
|
-
return get(optionsAtom).size ?? "md";
|
|
106
|
-
});
|
|
107
|
-
return {
|
|
108
|
-
options: optionsAtom,
|
|
109
|
-
form: formScopeAtom,
|
|
110
|
-
name: nameAtom,
|
|
111
|
-
path: pathAtom,
|
|
112
|
-
initialValue: initialValueAtom,
|
|
113
|
-
previousValue: (0, jotai.atom)((get) => {
|
|
114
|
-
const previousValues = get(form.previousValues);
|
|
115
|
-
return (0, _stryke_helpers_get_field.getField)(previousValues, get(pathAtom).join(".")) ?? null;
|
|
116
|
-
}),
|
|
117
|
-
value: valueAtom,
|
|
118
|
-
formattedValue: formattedValueAtom,
|
|
119
|
-
focused: focusedAtom,
|
|
120
|
-
required: requiredAtom,
|
|
121
|
-
disabled: disabledAtom,
|
|
122
|
-
clearable: clearableAtom,
|
|
123
|
-
touched: touchedAtom,
|
|
124
|
-
blurred: blurredAtom,
|
|
125
|
-
validating: validatingAtom,
|
|
126
|
-
validationResults: validationResultsAtom,
|
|
127
|
-
tabIndex: tabIndexAtom,
|
|
128
|
-
ref: refAtom,
|
|
129
|
-
pristine: (0, jotai.atom)((get) => !get(dirtyAtom)),
|
|
130
|
-
dirty: dirtyAtom,
|
|
131
|
-
items: itemsAtom,
|
|
132
|
-
itemsAtoms: itemsAtomsAtom,
|
|
133
|
-
size: sizeAtom,
|
|
134
|
-
errors: errorsAtom,
|
|
135
|
-
warnings: warningsAtom,
|
|
136
|
-
info: infoAtom,
|
|
137
|
-
discovery: discoveryAtom,
|
|
138
|
-
success: successesAtom,
|
|
139
|
-
positive: positivesAtom,
|
|
140
|
-
negative: negativesAtom,
|
|
141
|
-
dangerMessages: errorMessagesAtom,
|
|
142
|
-
warningMessages: warningMessagesAtom,
|
|
143
|
-
infoMessages: infoMessagesAtom,
|
|
144
|
-
discoveryMessages: discoveryMessagesAtom,
|
|
145
|
-
successMessages: successMessagesAtom,
|
|
146
|
-
positiveMessages: positiveMessagesAtom,
|
|
147
|
-
negativeMessages: negativeMessagesAtom,
|
|
148
|
-
theme: require_atom_with_messages.atomWithTheme(optionsAtom, errorMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom),
|
|
149
|
-
messages: require_atom_with_messages.atomWithMessages(errorMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom),
|
|
150
|
-
invalid: invalidAtom,
|
|
151
|
-
valid: validAtom
|
|
152
|
-
};
|
|
153
|
-
}, { type: "field" });
|
|
154
|
-
|
|
155
|
-
exports.DEFAULT_FIELD_OPTIONS = DEFAULT_FIELD_OPTIONS;
|
|
156
|
-
exports.FieldApi = FieldApi;
|
|
1
|
+
const e=require("../../base/utilities/create-molecule.cjs");require("../../base/index.cjs");const t=require("../atoms/atom-with-field.cjs"),n=require("../atoms/atom-with-messages.cjs"),r=require("../utilities/validators.cjs"),i=require("./form-molecule.cjs");let ee=require("@stryke/type-checks/is-function"),a=require("jotai/utils"),o=require("@stryke/helpers/is-equal"),s=require("jotai"),c=require("@stryke/type-checks/is-string"),l=require("@stryke/helpers/deep-merge"),te=require("@stryke/helpers/get-field"),u=require("@stryke/helpers/to-path"),d=require("@stryke/type-checks/is-set"),f=require("jotai-optics");const p={theme:`base`,size:`md`,debounceMs:100,isEqual:o.isEqual,required:!1,disabled:!1,clearable:!1,initialValue:null},m=e.createMoleculeApi(o=>{let m=e.use(i.FormApi.Scope),h=(0,s.atom)(()=>m),g=e.use(i.FormApi.Molecule),_=(0,s.atom)(p),v=(0,s.atom)(e=>{let t=e(g.options),n=e(_),i=(0,l.deepMerge)(t.defaultFieldOptions,n);return(0,l.deepMerge)({validate:{onBlur:i.required?[r.requiredValidator]:[]}},i)},(e,t,n)=>{let r={};r=(0,ee.isFunction)(n)?n(e(_)):n===a.RESET?{}:n,t(_,(0,l.deepMerge)(p,r))}),y=`${m}-`,b=(0,u.toPath)(o.startsWith(y)?o.slice(y.length):o.includes(`-`)?o.slice(o.indexOf(`-`)+1):o),x=(0,s.atom)(()=>b),S=(0,s.atom)(e=>e(x).slice(-1)[0]),C=(0,f.focusAtom)(g.focusedFields,e=>e.path(...b)),w=(0,f.focusAtom)(g.requiredFields,e=>e.path(...b)),T=(0,f.focusAtom)(g.disabledFields,e=>e.path(...b)),E=(0,s.atom)(e=>e(w)??e(v).required,(e,t,n)=>{t(w,n)}),D=(0,s.atom)(e=>e(T)??e(v).disabled,(e,t,n)=>{t(T,n)}),O=(0,s.atom)(e=>e(v).clearable),k=(0,f.focusAtom)(g.touchedFields,e=>e.path(...b)),A=(0,f.focusAtom)(g.blurredFields,e=>e.path(...b)),ne=(0,f.focusAtom)(g.validatingFields,e=>e.path(...b)),j=(0,f.focusAtom)(g.validationResultsFields,e=>e.path(...b)),re=(0,f.focusAtom)(g.tabIndexes,e=>e.path(...b)),ie=(0,f.focusAtom)(g.refs,e=>e.path(...b)),M=(0,f.focusAtom)(g.initialValues,e=>e.path(...b)),N=(0,f.focusAtom)(g.values,e=>e.path(...b)),P=(0,s.atom)(e=>e(v).isEqual(e(N),e(M))),F=(0,s.atom)(e=>!!e(v).showErrorsBeforeBlur||!!e(A)||e(g.submitAttempts)>0),I=n.atomWithFieldsMessageTypes(j,`danger`),L=(0,s.atom)(e=>e(F)?e(I):[]),R=n.atomWithFieldsMessageTypes(j,`warning`),z=n.atomWithFieldsMessageTypes(j,`info`),B=n.atomWithFieldsMessageTypes(j,`discovery`),V=n.atomWithFieldsMessageTypes(j,`success`),H=n.atomWithFieldsMessageTypes(j,`positive`),U=n.atomWithFieldsMessageTypes(j,`negative`),W=n.atomWithFieldsMessageList(j,`danger`),G=(0,s.atom)(e=>e(F)?e(W):[]),K=n.atomWithFieldsMessageList(j,`warning`),q=n.atomWithFieldsMessageList(j,`info`),J=n.atomWithFieldsMessageList(j,`discovery`),Y=n.atomWithFieldsMessageList(j,`success`),X=n.atomWithFieldsMessageList(j,`positive`),Z=n.atomWithFieldsMessageList(j,`negative`),Q=(0,s.atom)(e=>e(G).length>0),ae=(0,s.atom)(e=>!e(Q)),oe=(0,s.atom)(e=>{let t=e(v),n=e(N),r;return r=t?.format?t.format(n):n,(0,d.isSet)(r)?(0,c.isString)(r)?r:String(r):``}),$=t.atomWithFieldItems(v,N,D),se=(0,a.splitAtom)($),ce=(0,a.atomWithDefault)(e=>e(v).size??`md`);return{options:v,form:h,name:S,path:x,initialValue:M,previousValue:(0,s.atom)(e=>{let t=e(g.previousValues);return(0,te.getField)(t,e(x).join(`.`))??null}),value:N,formattedValue:oe,focused:C,required:E,disabled:D,clearable:O,touched:k,blurred:A,validating:ne,validationResults:j,tabIndex:re,ref:ie,pristine:(0,s.atom)(e=>!e(P)),dirty:P,items:$,itemsAtoms:se,size:ce,errors:L,warnings:R,info:z,discovery:B,success:V,positive:H,negative:U,dangerMessages:G,warningMessages:K,infoMessages:q,discoveryMessages:J,successMessages:Y,positiveMessages:X,negativeMessages:Z,theme:n.atomWithTheme(v,G,K,q,J,Y,X,Z),messages:n.atomWithMessages(G,K,q,J,Y,X,Z),invalid:Q,valid:ae}},{type:`field`});exports.DEFAULT_FIELD_OPTIONS=p,exports.FieldApi=m;
|
|
@@ -1,156 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../../base/index.mjs";
|
|
3
|
-
import { atomWithFieldItems } from "../atoms/atom-with-field.mjs";
|
|
4
|
-
import { atomWithFieldsMessageList, atomWithFieldsMessageTypes, atomWithMessages, atomWithTheme } from "../atoms/atom-with-messages.mjs";
|
|
5
|
-
import { requiredValidator } from "../utilities/validators.mjs";
|
|
6
|
-
import { FormApi } from "./form-molecule.mjs";
|
|
7
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
8
|
-
import { RESET, atomWithDefault, splitAtom } from "jotai/utils";
|
|
9
|
-
import { isEqual } from "@stryke/helpers/is-equal";
|
|
10
|
-
import { atom } from "jotai";
|
|
11
|
-
import { isString } from "@stryke/type-checks/is-string";
|
|
12
|
-
import { deepMerge } from "@stryke/helpers/deep-merge";
|
|
13
|
-
import { getField } from "@stryke/helpers/get-field";
|
|
14
|
-
import { toPath } from "@stryke/helpers/to-path";
|
|
15
|
-
import { isSet } from "@stryke/type-checks/is-set";
|
|
16
|
-
import { focusAtom } from "jotai-optics";
|
|
17
|
-
|
|
18
|
-
// src/form/molecules/field-molecule.ts
|
|
19
|
-
const DEFAULT_FIELD_OPTIONS = {
|
|
20
|
-
theme: "base",
|
|
21
|
-
size: "md",
|
|
22
|
-
debounceMs: 100,
|
|
23
|
-
isEqual,
|
|
24
|
-
required: false,
|
|
25
|
-
disabled: false,
|
|
26
|
-
clearable: false,
|
|
27
|
-
initialValue: null
|
|
28
|
-
};
|
|
29
|
-
const FieldApi = createMoleculeApi((scope) => {
|
|
30
|
-
const formScope = use(FormApi.Scope);
|
|
31
|
-
const formScopeAtom = atom(() => formScope);
|
|
32
|
-
const form = use(FormApi.Molecule);
|
|
33
|
-
const optionsBaseAtom = atom(DEFAULT_FIELD_OPTIONS);
|
|
34
|
-
const optionsAtom = atom((get) => {
|
|
35
|
-
const formOptions = get(form.options);
|
|
36
|
-
const options = get(optionsBaseAtom);
|
|
37
|
-
const result = deepMerge(formOptions.defaultFieldOptions, options);
|
|
38
|
-
return deepMerge({ validate: { onBlur: result.required ? [requiredValidator] : [] } }, result);
|
|
39
|
-
}, (get, set, update) => {
|
|
40
|
-
let nextValue = {};
|
|
41
|
-
if (isFunction(update)) nextValue = update(get(optionsBaseAtom));
|
|
42
|
-
else if (update === RESET) nextValue = {};
|
|
43
|
-
else nextValue = update;
|
|
44
|
-
set(optionsBaseAtom, deepMerge(DEFAULT_FIELD_OPTIONS, nextValue));
|
|
45
|
-
});
|
|
46
|
-
const formPrefix = `${formScope}-`;
|
|
47
|
-
const path = toPath(scope.startsWith(formPrefix) ? scope.slice(formPrefix.length) : scope.includes("-") ? scope.slice(scope.indexOf("-") + 1) : scope);
|
|
48
|
-
const pathAtom = atom(() => path);
|
|
49
|
-
const nameAtom = atom((get) => get(pathAtom).slice(-1)[0]);
|
|
50
|
-
const focusedAtom = focusAtom(form.focusedFields, (optic) => optic.path(...path));
|
|
51
|
-
const requiredStateAtom = focusAtom(form.requiredFields, (optic) => optic.path(...path));
|
|
52
|
-
const disabledStateAtom = focusAtom(form.disabledFields, (optic) => optic.path(...path));
|
|
53
|
-
const requiredAtom = atom((get) => get(requiredStateAtom) ?? get(optionsAtom).required, (_get, set, update) => {
|
|
54
|
-
set(requiredStateAtom, update);
|
|
55
|
-
});
|
|
56
|
-
const disabledAtom = atom((get) => get(disabledStateAtom) ?? get(optionsAtom).disabled, (_get, set, update) => {
|
|
57
|
-
set(disabledStateAtom, update);
|
|
58
|
-
});
|
|
59
|
-
const clearableAtom = atom((get) => get(optionsAtom).clearable);
|
|
60
|
-
const touchedAtom = focusAtom(form.touchedFields, (optic) => optic.path(...path));
|
|
61
|
-
const blurredAtom = focusAtom(form.blurredFields, (optic) => optic.path(...path));
|
|
62
|
-
const validatingAtom = focusAtom(form.validatingFields, (optic) => optic.path(...path));
|
|
63
|
-
const validationResultsAtom = focusAtom(form.validationResultsFields, (optic) => optic.path(...path));
|
|
64
|
-
const tabIndexAtom = focusAtom(form.tabIndexes, (optic) => optic.path(...path));
|
|
65
|
-
const refAtom = focusAtom(form.refs, (optic) => optic.path(...path));
|
|
66
|
-
const initialValueAtom = focusAtom(form.initialValues, (optic) => optic.path(...path));
|
|
67
|
-
const valueAtom = focusAtom(form.values, (optic) => optic.path(...path));
|
|
68
|
-
const dirtyAtom = atom((get) => {
|
|
69
|
-
return get(optionsAtom).isEqual(get(valueAtom), get(initialValueAtom));
|
|
70
|
-
});
|
|
71
|
-
const showErrorsAtom = atom((get) => Boolean(get(optionsAtom).showErrorsBeforeBlur) || Boolean(get(blurredAtom)) || get(form.submitAttempts) > 0);
|
|
72
|
-
const allErrorsAtom = atomWithFieldsMessageTypes(validationResultsAtom, "danger");
|
|
73
|
-
const errorsAtom = atom((get) => get(showErrorsAtom) ? get(allErrorsAtom) : []);
|
|
74
|
-
const warningsAtom = atomWithFieldsMessageTypes(validationResultsAtom, "warning");
|
|
75
|
-
const infoAtom = atomWithFieldsMessageTypes(validationResultsAtom, "info");
|
|
76
|
-
const discoveryAtom = atomWithFieldsMessageTypes(validationResultsAtom, "discovery");
|
|
77
|
-
const successesAtom = atomWithFieldsMessageTypes(validationResultsAtom, "success");
|
|
78
|
-
const positivesAtom = atomWithFieldsMessageTypes(validationResultsAtom, "positive");
|
|
79
|
-
const negativesAtom = atomWithFieldsMessageTypes(validationResultsAtom, "negative");
|
|
80
|
-
const allErrorMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "danger");
|
|
81
|
-
const errorMessagesAtom = atom((get) => get(showErrorsAtom) ? get(allErrorMessagesAtom) : []);
|
|
82
|
-
const warningMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "warning");
|
|
83
|
-
const infoMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "info");
|
|
84
|
-
const discoveryMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "discovery");
|
|
85
|
-
const successMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "success");
|
|
86
|
-
const positiveMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "positive");
|
|
87
|
-
const negativeMessagesAtom = atomWithFieldsMessageList(validationResultsAtom, "negative");
|
|
88
|
-
const invalidAtom = atom((get) => {
|
|
89
|
-
return get(errorMessagesAtom).length > 0;
|
|
90
|
-
});
|
|
91
|
-
const validAtom = atom((get) => !get(invalidAtom));
|
|
92
|
-
const formattedValueAtom = atom((get) => {
|
|
93
|
-
const options = get(optionsAtom);
|
|
94
|
-
const value = get(valueAtom);
|
|
95
|
-
let formattedValue;
|
|
96
|
-
if (options?.format) formattedValue = options.format(value);
|
|
97
|
-
else formattedValue = value;
|
|
98
|
-
if (!isSet(formattedValue)) return "";
|
|
99
|
-
else if (isString(formattedValue)) return formattedValue;
|
|
100
|
-
return String(formattedValue);
|
|
101
|
-
});
|
|
102
|
-
const itemsAtom = atomWithFieldItems(optionsAtom, valueAtom, disabledAtom);
|
|
103
|
-
const itemsAtomsAtom = splitAtom(itemsAtom);
|
|
104
|
-
const sizeAtom = atomWithDefault((get) => {
|
|
105
|
-
return get(optionsAtom).size ?? "md";
|
|
106
|
-
});
|
|
107
|
-
return {
|
|
108
|
-
options: optionsAtom,
|
|
109
|
-
form: formScopeAtom,
|
|
110
|
-
name: nameAtom,
|
|
111
|
-
path: pathAtom,
|
|
112
|
-
initialValue: initialValueAtom,
|
|
113
|
-
previousValue: atom((get) => {
|
|
114
|
-
const previousValues = get(form.previousValues);
|
|
115
|
-
return getField(previousValues, get(pathAtom).join(".")) ?? null;
|
|
116
|
-
}),
|
|
117
|
-
value: valueAtom,
|
|
118
|
-
formattedValue: formattedValueAtom,
|
|
119
|
-
focused: focusedAtom,
|
|
120
|
-
required: requiredAtom,
|
|
121
|
-
disabled: disabledAtom,
|
|
122
|
-
clearable: clearableAtom,
|
|
123
|
-
touched: touchedAtom,
|
|
124
|
-
blurred: blurredAtom,
|
|
125
|
-
validating: validatingAtom,
|
|
126
|
-
validationResults: validationResultsAtom,
|
|
127
|
-
tabIndex: tabIndexAtom,
|
|
128
|
-
ref: refAtom,
|
|
129
|
-
pristine: atom((get) => !get(dirtyAtom)),
|
|
130
|
-
dirty: dirtyAtom,
|
|
131
|
-
items: itemsAtom,
|
|
132
|
-
itemsAtoms: itemsAtomsAtom,
|
|
133
|
-
size: sizeAtom,
|
|
134
|
-
errors: errorsAtom,
|
|
135
|
-
warnings: warningsAtom,
|
|
136
|
-
info: infoAtom,
|
|
137
|
-
discovery: discoveryAtom,
|
|
138
|
-
success: successesAtom,
|
|
139
|
-
positive: positivesAtom,
|
|
140
|
-
negative: negativesAtom,
|
|
141
|
-
dangerMessages: errorMessagesAtom,
|
|
142
|
-
warningMessages: warningMessagesAtom,
|
|
143
|
-
infoMessages: infoMessagesAtom,
|
|
144
|
-
discoveryMessages: discoveryMessagesAtom,
|
|
145
|
-
successMessages: successMessagesAtom,
|
|
146
|
-
positiveMessages: positiveMessagesAtom,
|
|
147
|
-
negativeMessages: negativeMessagesAtom,
|
|
148
|
-
theme: atomWithTheme(optionsAtom, errorMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom),
|
|
149
|
-
messages: atomWithMessages(errorMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom),
|
|
150
|
-
invalid: invalidAtom,
|
|
151
|
-
valid: validAtom
|
|
152
|
-
};
|
|
153
|
-
}, { type: "field" });
|
|
154
|
-
|
|
155
|
-
export { DEFAULT_FIELD_OPTIONS, FieldApi };
|
|
1
|
+
import{createMoleculeApi as e,use as t}from"../../base/utilities/create-molecule.mjs";import"../../base/index.mjs";import{atomWithFieldItems as n}from"../atoms/atom-with-field.mjs";import{atomWithFieldsMessageList as r,atomWithFieldsMessageTypes as i,atomWithMessages as a,atomWithTheme as ee}from"../atoms/atom-with-messages.mjs";import{requiredValidator as te}from"../utilities/validators.mjs";import{FormApi as o}from"./form-molecule.mjs";import{isFunction as s}from"@stryke/type-checks/is-function";import{RESET as c,atomWithDefault as l,splitAtom as ne}from"jotai/utils";import{isEqual as u}from"@stryke/helpers/is-equal";import{atom as d}from"jotai";import{isString as f}from"@stryke/type-checks/is-string";import{deepMerge as p}from"@stryke/helpers/deep-merge";import{getField as re}from"@stryke/helpers/get-field";import{toPath as m}from"@stryke/helpers/to-path";import{isSet as ie}from"@stryke/type-checks/is-set";import{focusAtom as h}from"jotai-optics";const g={theme:`base`,size:`md`,debounceMs:100,isEqual:u,required:!1,disabled:!1,clearable:!1,initialValue:null},_=e(e=>{let u=t(o.Scope),_=d(()=>u),v=t(o.Molecule),y=d(g),b=d(e=>{let t=e(v.options),n=e(y),r=p(t.defaultFieldOptions,n);return p({validate:{onBlur:r.required?[te]:[]}},r)},(e,t,n)=>{let r={};r=s(n)?n(e(y)):n===c?{}:n,t(y,p(g,r))}),x=`${u}-`,S=m(e.startsWith(x)?e.slice(x.length):e.includes(`-`)?e.slice(e.indexOf(`-`)+1):e),C=d(()=>S),w=d(e=>e(C).slice(-1)[0]),ae=h(v.focusedFields,e=>e.path(...S)),T=h(v.requiredFields,e=>e.path(...S)),E=h(v.disabledFields,e=>e.path(...S)),oe=d(e=>e(T)??e(b).required,(e,t,n)=>{t(T,n)}),D=d(e=>e(E)??e(b).disabled,(e,t,n)=>{t(E,n)}),se=d(e=>e(b).clearable),ce=h(v.touchedFields,e=>e.path(...S)),O=h(v.blurredFields,e=>e.path(...S)),k=h(v.validatingFields,e=>e.path(...S)),A=h(v.validationResultsFields,e=>e.path(...S)),j=h(v.tabIndexes,e=>e.path(...S)),M=h(v.refs,e=>e.path(...S)),N=h(v.initialValues,e=>e.path(...S)),P=h(v.values,e=>e.path(...S)),F=d(e=>e(b).isEqual(e(P),e(N))),I=d(e=>!!e(b).showErrorsBeforeBlur||!!e(O)||e(v.submitAttempts)>0),L=i(A,`danger`),R=d(e=>e(I)?e(L):[]),z=i(A,`warning`),B=i(A,`info`),V=i(A,`discovery`),H=i(A,`success`),U=i(A,`positive`),W=i(A,`negative`),le=r(A,`danger`),G=d(e=>e(I)?e(le):[]),K=r(A,`warning`),q=r(A,`info`),J=r(A,`discovery`),Y=r(A,`success`),X=r(A,`positive`),Z=r(A,`negative`),Q=d(e=>e(G).length>0),ue=d(e=>!e(Q)),de=d(e=>{let t=e(b),n=e(P),r;return r=t?.format?t.format(n):n,ie(r)?f(r)?r:String(r):``}),$=n(b,P,D),fe=ne($),pe=l(e=>e(b).size??`md`);return{options:b,form:_,name:w,path:C,initialValue:N,previousValue:d(e=>{let t=e(v.previousValues);return re(t,e(C).join(`.`))??null}),value:P,formattedValue:de,focused:ae,required:oe,disabled:D,clearable:se,touched:ce,blurred:O,validating:k,validationResults:A,tabIndex:j,ref:M,pristine:d(e=>!e(F)),dirty:F,items:$,itemsAtoms:fe,size:pe,errors:R,warnings:z,info:B,discovery:V,success:H,positive:U,negative:W,dangerMessages:G,warningMessages:K,infoMessages:q,discoveryMessages:J,successMessages:Y,positiveMessages:X,negativeMessages:Z,theme:ee(b,G,K,q,J,Y,X,Z),messages:a(G,K,q,J,Y,X,Z),invalid:Q,valid:ue}},{type:`field`});export{g as DEFAULT_FIELD_OPTIONS,_ as FieldApi};
|
|
156
2
|
//# sourceMappingURL=field-molecule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-molecule.mjs","names":[],"sources":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"field-molecule.mjs","names":["DEFAULT_FIELD_OPTIONS","FieldApi","createMoleculeApi","formScope","use","FormApi","formScopeAtom","atom","form","optionsBaseAtom","optionsAtom","formOptions","get","options","result","deepMerge","requiredValidator","nextValue","isFunction","update","RESET","set","formPrefix","path","toPath","scope","pathAtom","nameAtom","focusedAtom","focusAtom","optic","requiredStateAtom","disabledStateAtom","requiredAtom","disabledAtom","clearableAtom","touchedAtom","blurredAtom","validatingAtom","validationResultsAtom","tabIndexAtom","refAtom","initialValueAtom","valueAtom","dirtyAtom","showErrorsAtom","allErrorsAtom","atomWithFieldsMessageTypes","errorsAtom","warningsAtom","infoAtom","discoveryAtom","successesAtom","positivesAtom","negativesAtom","allErrorMessagesAtom","atomWithFieldsMessageList","errorMessagesAtom","warningMessagesAtom","infoMessagesAtom","discoveryMessagesAtom","successMessagesAtom","positiveMessagesAtom","negativeMessagesAtom","invalidAtom","validAtom","formattedValueAtom","value","formattedValue","isSet","isString","itemsAtom","atomWithFieldItems","itemsAtomsAtom","splitAtom","sizeAtom","atomWithDefault","previousValues","getField","atomWithTheme","atomWithMessages"],"sources":[],"mappings":""}
|