@cyclone-ui/state 0.0.11 → 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 +20 -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 +1,48 @@
|
|
|
1
|
-
let
|
|
1
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
2
|
+
let _stryke_type_checks_is_plain_object = require("@stryke/type-checks/is-plain-object");
|
|
3
|
+
|
|
4
|
+
//#region src/base/utilities/is-atom.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the value is a [Jotai](https://jotai.org) `Atom` object
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to check
|
|
9
|
+
* @returns A boolean indicating whether the value is an `Atom` object
|
|
10
|
+
*/
|
|
11
|
+
const isAtom = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
return (0, _stryke_type_checks_is_plain_object.isPlainObject)(value) && "read" in value && (0, _stryke_type_checks_is_function.isFunction)(value.read);
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Check if the value is a [Jotai](https://jotai.org) `WritableAtom` object
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to check
|
|
22
|
+
* @returns A boolean indicating whether the value is a `WritableAtom` object
|
|
23
|
+
*/
|
|
24
|
+
const isWritableAtom = (value) => {
|
|
25
|
+
try {
|
|
26
|
+
return isAtom(value) && "write" in value && (0, _stryke_type_checks_is_function.isFunction)(value.write);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Check if the value is a [Jotai](https://jotai.org) `Atom` object with the ability to reset to it's initial value
|
|
33
|
+
*
|
|
34
|
+
* @param value - The value to check
|
|
35
|
+
* @returns A boolean indicating whether the value is a `Atom` object with the ability to reset to it's initial value
|
|
36
|
+
*/
|
|
37
|
+
const isResetAtom = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
return isWritableAtom(value) && "init" in value;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.isAtom = isAtom;
|
|
47
|
+
exports.isResetAtom = isResetAtom;
|
|
48
|
+
exports.isWritableAtom = isWritableAtom;
|
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
import{isFunction
|
|
1
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
2
|
+
import { isPlainObject } from "@stryke/type-checks/is-plain-object";
|
|
3
|
+
|
|
4
|
+
//#region src/base/utilities/is-atom.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the value is a [Jotai](https://jotai.org) `Atom` object
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to check
|
|
9
|
+
* @returns A boolean indicating whether the value is an `Atom` object
|
|
10
|
+
*/
|
|
11
|
+
const isAtom = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
return isPlainObject(value) && "read" in value && isFunction(value.read);
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Check if the value is a [Jotai](https://jotai.org) `WritableAtom` object
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to check
|
|
22
|
+
* @returns A boolean indicating whether the value is a `WritableAtom` object
|
|
23
|
+
*/
|
|
24
|
+
const isWritableAtom = (value) => {
|
|
25
|
+
try {
|
|
26
|
+
return isAtom(value) && "write" in value && isFunction(value.write);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Check if the value is a [Jotai](https://jotai.org) `Atom` object with the ability to reset to it's initial value
|
|
33
|
+
*
|
|
34
|
+
* @param value - The value to check
|
|
35
|
+
* @returns A boolean indicating whether the value is a `Atom` object with the ability to reset to it's initial value
|
|
36
|
+
*/
|
|
37
|
+
const isResetAtom = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
return isWritableAtom(value) && "init" in value;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { isAtom, isResetAtom, isWritableAtom };
|
|
2
47
|
//# sourceMappingURL=is-atom.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-atom.mjs","names":[
|
|
1
|
+
{"version":3,"file":"is-atom.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
let
|
|
1
|
+
let _stryke_env_environment_checks = require("@stryke/env/environment-checks");
|
|
2
|
+
|
|
3
|
+
//#region src/base/utilities/set-atom-debug.ts
|
|
4
|
+
/**
|
|
5
|
+
* Add a debug label to the Jotai Atom
|
|
6
|
+
*
|
|
7
|
+
* @param atom - The atom to apply the debug label to
|
|
8
|
+
* @param label - The label to apply to the atom
|
|
9
|
+
*/
|
|
10
|
+
const setAtomDebugLabel = (atom, label) => {
|
|
11
|
+
if (_stryke_env_environment_checks.isDevelopment) atom.debugLabel = label;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Mark the atom as a *private* or internal
|
|
15
|
+
*
|
|
16
|
+
* @param atom - The atom to mark as private
|
|
17
|
+
*/
|
|
18
|
+
const setAtomDebugPrivate = (atom) => {
|
|
19
|
+
if (_stryke_env_environment_checks.isDevelopment) atom.debugPrivate = true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.setAtomDebugLabel = setAtomDebugLabel;
|
|
24
|
+
exports.setAtomDebugPrivate = setAtomDebugPrivate;
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import{isDevelopment
|
|
1
|
+
import { isDevelopment } from "@stryke/env/environment-checks";
|
|
2
|
+
|
|
3
|
+
//#region src/base/utilities/set-atom-debug.ts
|
|
4
|
+
/**
|
|
5
|
+
* Add a debug label to the Jotai Atom
|
|
6
|
+
*
|
|
7
|
+
* @param atom - The atom to apply the debug label to
|
|
8
|
+
* @param label - The label to apply to the atom
|
|
9
|
+
*/
|
|
10
|
+
const setAtomDebugLabel = (atom, label) => {
|
|
11
|
+
if (isDevelopment) atom.debugLabel = label;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Mark the atom as a *private* or internal
|
|
15
|
+
*
|
|
16
|
+
* @param atom - The atom to mark as private
|
|
17
|
+
*/
|
|
18
|
+
const setAtomDebugPrivate = (atom) => {
|
|
19
|
+
if (isDevelopment) atom.debugPrivate = true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { setAtomDebugLabel, setAtomDebugPrivate };
|
|
2
24
|
//# sourceMappingURL=set-atom-debug.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-atom-debug.mjs","names":[
|
|
1
|
+
{"version":3,"file":"set-atom-debug.mjs","names":[],"sources":[],"mappings":""}
|
package/dist/client/index.cjs
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_theme_molecule = require("../theme/molecules/theme-molecule.cjs");
|
|
3
|
+
const require_use_theme_actions = require("../theme/hooks/use-theme-actions.cjs");
|
|
4
|
+
const require_theme_helpers = require("../theme/utilities/theme-helpers.cjs");
|
|
5
|
+
const require_use_theme_store = require("../theme/hooks/use-theme-store.cjs");
|
|
6
|
+
const require_ThemeProvider = require("../theme/providers/ThemeProvider.cjs");
|
|
7
|
+
require("../theme/index.cjs");
|
|
8
|
+
|
|
9
|
+
exports.ThemeApi = require_theme_molecule.ThemeApi;
|
|
10
|
+
exports.ThemeProvider = require_ThemeProvider.ThemeProvider;
|
|
11
|
+
exports.getThemeColorThemeName = require_theme_helpers.getThemeColorThemeName;
|
|
12
|
+
exports.themeColorThemeNameExists = require_theme_helpers.themeColorThemeNameExists;
|
|
13
|
+
exports.useColorThemeName = require_use_theme_store.useColorThemeName;
|
|
14
|
+
exports.useColorThemeNameExists = require_use_theme_store.useColorThemeNameExists;
|
|
15
|
+
exports.useThemeActions = require_use_theme_actions.useThemeActions;
|
|
16
|
+
exports.useThemeMode = require_use_theme_store.useThemeMode;
|
package/dist/client/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ThemeApi } from "../theme/molecules/theme-molecule.mjs";
|
|
2
|
+
import { useThemeActions } from "../theme/hooks/use-theme-actions.mjs";
|
|
3
|
+
import { getThemeColorThemeName, themeColorThemeNameExists } from "../theme/utilities/theme-helpers.mjs";
|
|
4
|
+
import { useColorThemeName, useColorThemeNameExists, useThemeMode } from "../theme/hooks/use-theme-store.mjs";
|
|
5
|
+
import { ThemeProvider } from "../theme/providers/ThemeProvider.mjs";
|
|
6
|
+
import "../theme/index.mjs";
|
|
7
|
+
|
|
8
|
+
export { ThemeApi, ThemeProvider, getThemeColorThemeName, themeColorThemeNameExists, useColorThemeName, useColorThemeNameExists, useThemeActions, useThemeMode };
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
let
|
|
1
|
+
let jotai_utils = require("jotai/utils");
|
|
2
|
+
let jotai = require("jotai");
|
|
3
|
+
|
|
4
|
+
//#region src/form/atoms/atom-with-field.ts
|
|
5
|
+
const atomWithFieldItems = (optionsAtom, valueAtom, disabledAtom) => {
|
|
6
|
+
return (0, jotai_utils.atomWithDefault)((get) => {
|
|
7
|
+
const options = get(optionsAtom);
|
|
8
|
+
const value = get(valueAtom);
|
|
9
|
+
const disabled = get(disabledAtom);
|
|
10
|
+
return (options.items ?? []).reduce((ret, item, index) => {
|
|
11
|
+
if (!ret.some((existing) => existing.value === item.value)) ret.push({
|
|
12
|
+
index,
|
|
13
|
+
...item,
|
|
14
|
+
selected: item.value === value,
|
|
15
|
+
disabled: Boolean(item.disabled) || Boolean(disabled)
|
|
16
|
+
});
|
|
17
|
+
return ret;
|
|
18
|
+
}, []);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.atomWithFieldItems = atomWithFieldItems;
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import{atomWithDefault
|
|
1
|
+
import { atomWithDefault } from "jotai/utils";
|
|
2
|
+
import { atom } from "jotai";
|
|
3
|
+
|
|
4
|
+
//#region src/form/atoms/atom-with-field.ts
|
|
5
|
+
const atomWithFieldItems = (optionsAtom, valueAtom, disabledAtom) => {
|
|
6
|
+
return atomWithDefault((get) => {
|
|
7
|
+
const options = get(optionsAtom);
|
|
8
|
+
const value = get(valueAtom);
|
|
9
|
+
const disabled = get(disabledAtom);
|
|
10
|
+
return (options.items ?? []).reduce((ret, item, index) => {
|
|
11
|
+
if (!ret.some((existing) => existing.value === item.value)) ret.push({
|
|
12
|
+
index,
|
|
13
|
+
...item,
|
|
14
|
+
selected: item.value === value,
|
|
15
|
+
disabled: Boolean(item.disabled) || Boolean(disabled)
|
|
16
|
+
});
|
|
17
|
+
return ret;
|
|
18
|
+
}, []);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { atomWithFieldItems };
|
|
2
24
|
//# sourceMappingURL=atom-with-field.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-field.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-field.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,85 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_is_validation_results = require("../utilities/is-validation-results.cjs");
|
|
2
|
+
let jotai = require("jotai");
|
|
3
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
4
|
+
|
|
5
|
+
//#region src/form/atoms/atom-with-messages.ts
|
|
6
|
+
const getMessageType = (validationResults, type) => {
|
|
7
|
+
const messages = [];
|
|
8
|
+
if (validationResults.initialize) messages.push(...validationResults.initialize.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
9
|
+
if (validationResults.change) messages.push(...validationResults.change.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
10
|
+
if (validationResults.blur) messages.push(...validationResults.blur.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
11
|
+
if (validationResults.server) messages.push(...validationResults.server.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
12
|
+
if (validationResults.submit) messages.push(...validationResults.submit.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
13
|
+
return messages;
|
|
14
|
+
};
|
|
15
|
+
const getFieldsMessageTypes = (messageMap, type) => {
|
|
16
|
+
if (require_is_validation_results.isValidationResults(messageMap)) return getMessageType(messageMap, type);
|
|
17
|
+
return Object.entries(messageMap).reduce((ret, [field, messages]) => {
|
|
18
|
+
if (!require_is_validation_results.isValidationResults(messages)) ret[field] = getFieldsMessageTypes(messages, type);
|
|
19
|
+
else ret[field] = getMessageType(messages, type);
|
|
20
|
+
return ret;
|
|
21
|
+
}, {});
|
|
22
|
+
};
|
|
23
|
+
const atomWithFieldsMessageTypes = (validationResultsAtom, type) => {
|
|
24
|
+
return (0, jotai.atom)((get) => {
|
|
25
|
+
return getFieldsMessageTypes(get(validationResultsAtom), type);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const getFieldsMessageList = (messageMap, type) => {
|
|
29
|
+
if (require_is_validation_results.isValidationResults(messageMap)) return getMessageType(messageMap, type);
|
|
30
|
+
return Object.entries(messageMap ?? {}).reduce((ret, [_, messages]) => {
|
|
31
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(messages)) {
|
|
32
|
+
if (!require_is_validation_results.isValidationResults(messages)) ret.push(...getFieldsMessageList(messages, type));
|
|
33
|
+
else ret.push(...getMessageType(messages, type));
|
|
34
|
+
}
|
|
35
|
+
return ret;
|
|
36
|
+
}, []);
|
|
37
|
+
};
|
|
38
|
+
const atomWithFieldsMessageList = (validationResultsAtom, type) => {
|
|
39
|
+
return (0, jotai.atom)((get) => {
|
|
40
|
+
return getFieldsMessageList(get(validationResultsAtom), type);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const atomWithMessageTypes = (validationResultsAtom, type) => {
|
|
44
|
+
return (0, jotai.atom)((get) => {
|
|
45
|
+
return getMessageType(get(validationResultsAtom), type);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const atomWithMessages = (dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => (0, jotai.atom)((get) => {
|
|
49
|
+
const dangerMessages = get(dangerMessagesAtom);
|
|
50
|
+
if (dangerMessages.length > 0) return dangerMessages;
|
|
51
|
+
const warningMessages = get(warningMessagesAtom);
|
|
52
|
+
if (warningMessages.length > 0) return warningMessages;
|
|
53
|
+
const infoMessages = get(infoMessagesAtom);
|
|
54
|
+
if (infoMessages.length > 0) return infoMessages;
|
|
55
|
+
const discoveryMessages = get(discoveryMessagesAtom);
|
|
56
|
+
if (discoveryMessages.length > 0) return discoveryMessages;
|
|
57
|
+
const successMessages = get(successMessagesAtom);
|
|
58
|
+
if (successMessages.length > 0) return successMessages;
|
|
59
|
+
const positiveMessages = get(positiveMessagesAtom);
|
|
60
|
+
if (positiveMessages.length > 0) return positiveMessages;
|
|
61
|
+
const negativeMessages = get(negativeMessagesAtom);
|
|
62
|
+
if (negativeMessages.length > 0) return negativeMessages;
|
|
63
|
+
return [];
|
|
64
|
+
});
|
|
65
|
+
const atomWithTheme = (optionsAtom, dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => (0, jotai.atom)((get) => {
|
|
66
|
+
const options = get(optionsAtom);
|
|
67
|
+
if (get(dangerMessagesAtom).length > 0 || options.theme?.includes("danger")) return "danger";
|
|
68
|
+
else if (get(warningMessagesAtom).length > 0 || options.theme?.includes("warning")) return "warning";
|
|
69
|
+
else if (get(successMessagesAtom).length > 0 || options.theme?.includes("success")) return "success";
|
|
70
|
+
else if (get(infoMessagesAtom).length > 0 || options.theme?.includes("info")) return "info";
|
|
71
|
+
else if (get(discoveryMessagesAtom).length > 0 || options.theme?.includes("discovery")) return "discovery";
|
|
72
|
+
else if (get(positiveMessagesAtom).length > 0 || options.theme?.includes("positive")) return "positive";
|
|
73
|
+
else if (get(negativeMessagesAtom).length > 0 || options.theme?.includes("negative")) return "negative";
|
|
74
|
+
return "base";
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.atomWithFieldsMessageList = atomWithFieldsMessageList;
|
|
79
|
+
exports.atomWithFieldsMessageTypes = atomWithFieldsMessageTypes;
|
|
80
|
+
exports.atomWithMessageTypes = atomWithMessageTypes;
|
|
81
|
+
exports.atomWithMessages = atomWithMessages;
|
|
82
|
+
exports.atomWithTheme = atomWithTheme;
|
|
83
|
+
exports.getFieldsMessageList = getFieldsMessageList;
|
|
84
|
+
exports.getFieldsMessageTypes = getFieldsMessageTypes;
|
|
85
|
+
exports.getMessageType = getMessageType;
|
|
@@ -1,2 +1,79 @@
|
|
|
1
|
-
import{isValidationResults
|
|
1
|
+
import { isValidationResults } from "../utilities/is-validation-results.mjs";
|
|
2
|
+
import { atom } from "jotai";
|
|
3
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
4
|
+
|
|
5
|
+
//#region src/form/atoms/atom-with-messages.ts
|
|
6
|
+
const getMessageType = (validationResults, type) => {
|
|
7
|
+
const messages = [];
|
|
8
|
+
if (validationResults.initialize) messages.push(...validationResults.initialize.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
9
|
+
if (validationResults.change) messages.push(...validationResults.change.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
10
|
+
if (validationResults.blur) messages.push(...validationResults.blur.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
11
|
+
if (validationResults.server) messages.push(...validationResults.server.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
12
|
+
if (validationResults.submit) messages.push(...validationResults.submit.filter((message) => type === message.type && (message.message || message.code) && !messages.some((existing) => existing.message === message.message || existing.code === message.code)));
|
|
13
|
+
return messages;
|
|
14
|
+
};
|
|
15
|
+
const getFieldsMessageTypes = (messageMap, type) => {
|
|
16
|
+
if (isValidationResults(messageMap)) return getMessageType(messageMap, type);
|
|
17
|
+
return Object.entries(messageMap).reduce((ret, [field, messages]) => {
|
|
18
|
+
if (!isValidationResults(messages)) ret[field] = getFieldsMessageTypes(messages, type);
|
|
19
|
+
else ret[field] = getMessageType(messages, type);
|
|
20
|
+
return ret;
|
|
21
|
+
}, {});
|
|
22
|
+
};
|
|
23
|
+
const atomWithFieldsMessageTypes = (validationResultsAtom, type) => {
|
|
24
|
+
return atom((get) => {
|
|
25
|
+
return getFieldsMessageTypes(get(validationResultsAtom), type);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const getFieldsMessageList = (messageMap, type) => {
|
|
29
|
+
if (isValidationResults(messageMap)) return getMessageType(messageMap, type);
|
|
30
|
+
return Object.entries(messageMap ?? {}).reduce((ret, [_, messages]) => {
|
|
31
|
+
if (isSetObject(messages)) {
|
|
32
|
+
if (!isValidationResults(messages)) ret.push(...getFieldsMessageList(messages, type));
|
|
33
|
+
else ret.push(...getMessageType(messages, type));
|
|
34
|
+
}
|
|
35
|
+
return ret;
|
|
36
|
+
}, []);
|
|
37
|
+
};
|
|
38
|
+
const atomWithFieldsMessageList = (validationResultsAtom, type) => {
|
|
39
|
+
return atom((get) => {
|
|
40
|
+
return getFieldsMessageList(get(validationResultsAtom), type);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const atomWithMessageTypes = (validationResultsAtom, type) => {
|
|
44
|
+
return atom((get) => {
|
|
45
|
+
return getMessageType(get(validationResultsAtom), type);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const atomWithMessages = (dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => atom((get) => {
|
|
49
|
+
const dangerMessages = get(dangerMessagesAtom);
|
|
50
|
+
if (dangerMessages.length > 0) return dangerMessages;
|
|
51
|
+
const warningMessages = get(warningMessagesAtom);
|
|
52
|
+
if (warningMessages.length > 0) return warningMessages;
|
|
53
|
+
const infoMessages = get(infoMessagesAtom);
|
|
54
|
+
if (infoMessages.length > 0) return infoMessages;
|
|
55
|
+
const discoveryMessages = get(discoveryMessagesAtom);
|
|
56
|
+
if (discoveryMessages.length > 0) return discoveryMessages;
|
|
57
|
+
const successMessages = get(successMessagesAtom);
|
|
58
|
+
if (successMessages.length > 0) return successMessages;
|
|
59
|
+
const positiveMessages = get(positiveMessagesAtom);
|
|
60
|
+
if (positiveMessages.length > 0) return positiveMessages;
|
|
61
|
+
const negativeMessages = get(negativeMessagesAtom);
|
|
62
|
+
if (negativeMessages.length > 0) return negativeMessages;
|
|
63
|
+
return [];
|
|
64
|
+
});
|
|
65
|
+
const atomWithTheme = (optionsAtom, dangerMessagesAtom, warningMessagesAtom, infoMessagesAtom, discoveryMessagesAtom, successMessagesAtom, positiveMessagesAtom, negativeMessagesAtom) => atom((get) => {
|
|
66
|
+
const options = get(optionsAtom);
|
|
67
|
+
if (get(dangerMessagesAtom).length > 0 || options.theme?.includes("danger")) return "danger";
|
|
68
|
+
else if (get(warningMessagesAtom).length > 0 || options.theme?.includes("warning")) return "warning";
|
|
69
|
+
else if (get(successMessagesAtom).length > 0 || options.theme?.includes("success")) return "success";
|
|
70
|
+
else if (get(infoMessagesAtom).length > 0 || options.theme?.includes("info")) return "info";
|
|
71
|
+
else if (get(discoveryMessagesAtom).length > 0 || options.theme?.includes("discovery")) return "discovery";
|
|
72
|
+
else if (get(positiveMessagesAtom).length > 0 || options.theme?.includes("positive")) return "positive";
|
|
73
|
+
else if (get(negativeMessagesAtom).length > 0 || options.theme?.includes("negative")) return "negative";
|
|
74
|
+
return "base";
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { atomWithFieldsMessageList, atomWithFieldsMessageTypes, atomWithMessageTypes, atomWithMessages, atomWithTheme, getFieldsMessageList, getFieldsMessageTypes, getMessageType };
|
|
2
79
|
//# sourceMappingURL=atom-with-messages.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-messages.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-messages.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_use_field_actions = require("./use-field-actions.cjs");
|
|
2
|
+
const require_use_field_ref = require("./use-field-ref.cjs");
|
|
3
|
+
const require_use_form_actions = require("./use-form-actions.cjs");
|
|
4
|
+
|
|
5
|
+
exports.useFieldActions = require_use_field_actions.useFieldActions;
|
|
6
|
+
exports.useFieldRef = require_use_field_ref.useFieldRef;
|
|
7
|
+
exports.useFormActions = require_use_form_actions.useFormActions;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{useFieldActions
|
|
1
|
+
import { useFieldActions } from "./use-field-actions.mjs";
|
|
2
|
+
import { useFieldRef } from "./use-field-ref.mjs";
|
|
3
|
+
import { useFormActions } from "./use-form-actions.mjs";
|
|
4
|
+
|
|
5
|
+
export { useFieldActions, useFieldRef, useFormActions };
|
|
@@ -1 +1,92 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_field_molecule = require("../molecules/field-molecule.cjs");
|
|
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
|
+
//#region src/form/hooks/use-field-actions.ts
|
|
9
|
+
const useFieldActions = () => {
|
|
10
|
+
const field = require_field_molecule.FieldApi.useMolecule();
|
|
11
|
+
const validate = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValue, cause) => {
|
|
12
|
+
const options = get(field.options);
|
|
13
|
+
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) {
|
|
14
|
+
const previousValue = get(field.previousValue);
|
|
15
|
+
const results = [];
|
|
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) results.push(...options.validate[`on${(0, _stryke_string_format_upper_case_first.upperCaseFirst)(cause)}`].map((validator) => validator(nextValue, previousValue, cause, get, set)));
|
|
17
|
+
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(nextValue, previousValue, cause, get, set)));
|
|
18
|
+
const messages = [];
|
|
19
|
+
const promises = [];
|
|
20
|
+
for (const result of results) if (result) {
|
|
21
|
+
if ((0, _stryke_type_checks_is_promise.isPromise)(result)) promises.push(result);
|
|
22
|
+
else messages.push(...result);
|
|
23
|
+
}
|
|
24
|
+
if (promises.length > 0) {
|
|
25
|
+
set(field.validating, true);
|
|
26
|
+
for (const result of await Promise.all(promises)) if (result && result.length > 0) messages.push(...result);
|
|
27
|
+
set(field.validating, false);
|
|
28
|
+
}
|
|
29
|
+
set(field.validationResults, (prev) => ({
|
|
30
|
+
...prev,
|
|
31
|
+
[cause]: messages
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}, []));
|
|
35
|
+
const reset = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set) => {
|
|
36
|
+
set(field.value, get(field.initialValue));
|
|
37
|
+
set(field.options, jotai_utils.RESET);
|
|
38
|
+
}, []));
|
|
39
|
+
const initialize = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, initialValue, skipIfDirty = true) => {
|
|
40
|
+
if (skipIfDirty && get(field.dirty)) return;
|
|
41
|
+
if (initialValue !== get(field.initialValue)) set(field.initialValue, initialValue);
|
|
42
|
+
}, []));
|
|
43
|
+
const change = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, nextValue, touch = false) => {
|
|
44
|
+
if (!get(field.disabled)) {
|
|
45
|
+
if (!get(field.touched) && touch) set(field.touched, touch);
|
|
46
|
+
const options = get(field.options);
|
|
47
|
+
const value = get(field.value);
|
|
48
|
+
let nextParsed = nextValue;
|
|
49
|
+
if (options.parse) nextParsed = options.parse(nextValue);
|
|
50
|
+
if (!options.isEqual(nextParsed, value)) set(field.value, nextParsed);
|
|
51
|
+
}
|
|
52
|
+
}, []));
|
|
53
|
+
const focus = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set) => {
|
|
54
|
+
if (!get(field.disabled)) {
|
|
55
|
+
if (!get(field.touched)) set(field.touched, true);
|
|
56
|
+
set(field.focused, true);
|
|
57
|
+
}
|
|
58
|
+
}, []));
|
|
59
|
+
const blur = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set) => {
|
|
60
|
+
if (!get(field.disabled)) {
|
|
61
|
+
if (!get(field.touched)) set(field.touched, true);
|
|
62
|
+
set(field.focused, false);
|
|
63
|
+
set(field.blurred, true);
|
|
64
|
+
}
|
|
65
|
+
}, []));
|
|
66
|
+
const setFocused = (0, react.useCallback)(async (focused) => {
|
|
67
|
+
if (focused) return focus();
|
|
68
|
+
return blur();
|
|
69
|
+
}, [focus, blur]);
|
|
70
|
+
const toggleFocused = (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get) => setFocused(!get(field.focused)), [setFocused]));
|
|
71
|
+
return {
|
|
72
|
+
mount: (0, jotai_utils.useAtomCallback)((0, react.useCallback)(async (get, set, ref, tabIndex) => {
|
|
73
|
+
set(field.ref, ref);
|
|
74
|
+
set(field.tabIndex, tabIndex ?? 0);
|
|
75
|
+
if (!get(field.initialValue)) {
|
|
76
|
+
const options = get(field.options);
|
|
77
|
+
set(field.initialValue, options.defaultValue ?? null);
|
|
78
|
+
}
|
|
79
|
+
}, [])),
|
|
80
|
+
initialize,
|
|
81
|
+
change,
|
|
82
|
+
focus,
|
|
83
|
+
blur,
|
|
84
|
+
setFocused,
|
|
85
|
+
toggleFocused,
|
|
86
|
+
validate,
|
|
87
|
+
reset
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
exports.useFieldActions = useFieldActions;
|