@cyclone-ui/state 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/base/atoms/atom-with-broadcast.cjs +45 -1
- package/dist/base/atoms/atom-with-broadcast.mjs +45 -1
- package/dist/base/atoms/atom-with-broadcast.mjs.map +1 -1
- package/dist/base/atoms/atom-with-compare.cjs +12 -1
- package/dist/base/atoms/atom-with-compare.mjs +12 -1
- package/dist/base/atoms/atom-with-compare.mjs.map +1 -1
- package/dist/base/atoms/atom-with-debounce.cjs +52 -1
- package/dist/base/atoms/atom-with-debounce.mjs +52 -1
- package/dist/base/atoms/atom-with-debounce.mjs.map +1 -1
- package/dist/base/atoms/atom-with-effect.cjs +123 -1
- package/dist/base/atoms/atom-with-effect.mjs +120 -1
- package/dist/base/atoms/atom-with-effect.mjs.map +1 -1
- package/dist/base/atoms/atom-with-listeners.cjs +36 -1
- package/dist/base/atoms/atom-with-listeners.mjs +36 -1
- package/dist/base/atoms/atom-with-listeners.mjs.map +1 -1
- package/dist/base/atoms/atom-with-pending.cjs +14 -1
- package/dist/base/atoms/atom-with-pending.mjs +14 -1
- package/dist/base/atoms/atom-with-pending.mjs.map +1 -1
- package/dist/base/atoms/atom-with-refresh-and-default.cjs +19 -1
- package/dist/base/atoms/atom-with-refresh-and-default.mjs +19 -1
- package/dist/base/atoms/atom-with-refresh-and-default.mjs.map +1 -1
- package/dist/base/atoms/atom-with-refresh.cjs +13 -1
- package/dist/base/atoms/atom-with-refresh.mjs +13 -1
- package/dist/base/atoms/atom-with-refresh.mjs.map +1 -1
- package/dist/base/atoms/atom-with-toggle.cjs +13 -1
- package/dist/base/atoms/atom-with-toggle.mjs +13 -1
- package/dist/base/atoms/atom-with-toggle.mjs.map +1 -1
- package/dist/base/atoms/atom-with-web-storage.cjs +48 -1
- package/dist/base/atoms/atom-with-web-storage.mjs +47 -1
- package/dist/base/atoms/atom-with-web-storage.mjs.map +1 -1
- package/dist/base/atoms/atom-with-wrapper.cjs +25 -1
- package/dist/base/atoms/atom-with-wrapper.mjs +25 -1
- package/dist/base/atoms/atom-with-wrapper.mjs.map +1 -1
- package/dist/base/atoms/base-atom.cjs +25 -1
- package/dist/base/atoms/base-atom.mjs +25 -1
- package/dist/base/atoms/base-atom.mjs.map +1 -1
- package/dist/base/atoms/index.cjs +24 -1
- package/dist/base/atoms/index.mjs +13 -1
- package/dist/base/hooks/index.cjs +9 -1
- package/dist/base/hooks/index.mjs +6 -1
- package/dist/base/hooks/use-atom-effect.cjs +17 -1
- package/dist/base/hooks/use-atom-effect.mjs +17 -1
- package/dist/base/hooks/use-atom-effect.mjs.map +1 -1
- package/dist/base/hooks/use-hydrate-molecule.cjs +17 -1
- package/dist/base/hooks/use-hydrate-molecule.mjs +17 -1
- package/dist/base/hooks/use-hydrate-molecule.mjs.map +1 -1
- package/dist/base/hooks/use-prepare-atoms.cjs +20 -1
- package/dist/base/hooks/use-prepare-atoms.mjs +20 -1
- package/dist/base/hooks/use-prepare-atoms.mjs.map +1 -1
- package/dist/base/hooks/use-sync-molecule.cjs +37 -1
- package/dist/base/hooks/use-sync-molecule.mjs +37 -1
- package/dist/base/hooks/use-sync-molecule.mjs.map +1 -1
- package/dist/base/index.cjs +47 -1
- package/dist/base/index.mjs +24 -1
- package/dist/base/utilities/create-molecule.cjs +105 -4
- package/dist/base/utilities/create-molecule.d.cts.map +1 -1
- package/dist/base/utilities/create-molecule.mjs +102 -4
- package/dist/base/utilities/create-molecule.mjs.map +1 -1
- package/dist/base/utilities/create-web-storage.cjs +55 -1
- package/dist/base/utilities/create-web-storage.mjs +55 -1
- package/dist/base/utilities/create-web-storage.mjs.map +1 -1
- package/dist/base/utilities/debounce.cjs +52 -1
- package/dist/base/utilities/debounce.mjs +52 -1
- package/dist/base/utilities/debounce.mjs.map +1 -1
- package/dist/base/utilities/index.cjs +13 -1
- package/dist/base/utilities/index.mjs +6 -1
- package/dist/base/utilities/is-atom.cjs +48 -1
- package/dist/base/utilities/is-atom.mjs +46 -1
- package/dist/base/utilities/is-atom.mjs.map +1 -1
- package/dist/base/utilities/set-atom-debug.cjs +24 -1
- package/dist/base/utilities/set-atom-debug.mjs +23 -1
- package/dist/base/utilities/set-atom-debug.mjs.map +1 -1
- package/dist/client/index.cjs +16 -1
- package/dist/client/index.mjs +8 -1
- package/dist/form/atoms/atom-with-field.cjs +23 -1
- package/dist/form/atoms/atom-with-field.mjs +23 -1
- package/dist/form/atoms/atom-with-field.mjs.map +1 -1
- package/dist/form/atoms/atom-with-messages.cjs +85 -1
- package/dist/form/atoms/atom-with-messages.mjs +78 -1
- package/dist/form/atoms/atom-with-messages.mjs.map +1 -1
- package/dist/form/hooks/index.cjs +7 -1
- package/dist/form/hooks/index.mjs +5 -1
- package/dist/form/hooks/use-field-actions.cjs +92 -1
- package/dist/form/hooks/use-field-actions.mjs +92 -1
- package/dist/form/hooks/use-field-actions.mjs.map +1 -1
- package/dist/form/hooks/use-field-ref.cjs +16 -1
- package/dist/form/hooks/use-field-ref.mjs +16 -1
- package/dist/form/hooks/use-field-ref.mjs.map +1 -1
- package/dist/form/hooks/use-form-actions.cjs +69 -1
- package/dist/form/hooks/use-form-actions.mjs +69 -1
- package/dist/form/hooks/use-form-actions.mjs.map +1 -1
- package/dist/form/index.cjs +30 -1
- package/dist/form/index.mjs +17 -1
- package/dist/form/molecules/field-molecule.cjs +154 -1
- package/dist/form/molecules/field-molecule.mjs +153 -1
- package/dist/form/molecules/field-molecule.mjs.map +1 -1
- package/dist/form/molecules/form-molecule.cjs +180 -1
- package/dist/form/molecules/form-molecule.mjs +179 -1
- package/dist/form/molecules/form-molecule.mjs.map +1 -1
- package/dist/form/molecules/index.cjs +7 -1
- package/dist/form/molecules/index.mjs +4 -1
- package/dist/form/providers/FieldProvider.cjs +103 -4
- package/dist/form/providers/FieldProvider.mjs +103 -4
- package/dist/form/providers/FieldProvider.mjs.map +1 -1
- package/dist/form/providers/FormProvider.cjs +66 -4
- package/dist/form/providers/FormProvider.d.cts.map +1 -1
- package/dist/form/providers/FormProvider.mjs +66 -4
- package/dist/form/providers/FormProvider.mjs.map +1 -1
- package/dist/form/providers/index.cjs +5 -1
- package/dist/form/providers/index.mjs +4 -1
- package/dist/form/types.cjs +13 -1
- package/dist/form/types.mjs +13 -1
- package/dist/form/types.mjs.map +1 -1
- package/dist/form/utilities/abort-error.cjs +15 -1
- package/dist/form/utilities/abort-error.mjs +15 -1
- package/dist/form/utilities/abort-error.mjs.map +1 -1
- package/dist/form/utilities/index.cjs +7 -1
- package/dist/form/utilities/index.mjs +5 -1
- package/dist/form/utilities/is-validation-results.cjs +9 -1
- package/dist/form/utilities/is-validation-results.mjs +9 -1
- package/dist/form/utilities/is-validation-results.mjs.map +1 -1
- package/dist/form/utilities/validators.cjs +8 -1
- package/dist/form/utilities/validators.mjs +8 -1
- package/dist/form/utilities/validators.mjs.map +1 -1
- package/dist/index.cjs +71 -1
- package/dist/index.mjs +34 -1
- package/dist/message/components/MessageViewport.cjs +21 -6
- package/dist/message/components/MessageViewport.mjs +21 -6
- package/dist/message/components/MessageViewport.mjs.map +1 -1
- package/dist/message/components/index.cjs +3 -1
- package/dist/message/components/index.mjs +3 -1
- package/dist/message/hooks/index.cjs +3 -1
- package/dist/message/hooks/index.mjs +3 -1
- package/dist/message/hooks/use-message-actions.cjs +63 -1
- package/dist/message/hooks/use-message-actions.mjs +63 -1
- package/dist/message/hooks/use-message-actions.mjs.map +1 -1
- package/dist/message/index.cjs +23 -1
- package/dist/message/index.mjs +8 -1
- package/dist/message/providers/MessageProvider.cjs +16 -1
- package/dist/message/providers/MessageProvider.mjs +16 -1
- package/dist/message/providers/MessageProvider.mjs.map +1 -1
- package/dist/theme/hooks/index.cjs +7 -1
- package/dist/theme/hooks/index.mjs +4 -1
- package/dist/theme/hooks/use-theme-actions.cjs +21 -1
- package/dist/theme/hooks/use-theme-actions.mjs +21 -1
- package/dist/theme/hooks/use-theme-actions.mjs.map +1 -1
- package/dist/theme/hooks/use-theme-store.cjs +61 -1
- package/dist/theme/hooks/use-theme-store.d.cts +2 -2
- package/dist/theme/hooks/use-theme-store.d.mts +2 -2
- package/dist/theme/hooks/use-theme-store.mjs +59 -1
- package/dist/theme/hooks/use-theme-store.mjs.map +1 -1
- package/dist/theme/index.cjs +17 -1
- package/dist/theme/index.mjs +9 -1
- package/dist/theme/molecules/index.cjs +3 -1
- package/dist/theme/molecules/index.mjs +3 -1
- package/dist/theme/molecules/theme-molecule.cjs +14 -1
- package/dist/theme/molecules/theme-molecule.mjs +14 -1
- package/dist/theme/molecules/theme-molecule.mjs.map +1 -1
- package/dist/theme/providers/ThemeProvider.cjs +30 -5
- package/dist/theme/providers/ThemeProvider.mjs +30 -5
- package/dist/theme/providers/ThemeProvider.mjs.map +1 -1
- package/dist/theme/utilities/theme-helpers.cjs +71 -1
- package/dist/theme/utilities/theme-helpers.mjs +70 -1
- package/dist/theme/utilities/theme-helpers.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1,19 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_base_atom = require("./base-atom.cjs");
|
|
2
|
+
|
|
3
|
+
//#region src/base/atoms/atom-with-refresh-and-default.ts
|
|
4
|
+
const atomWithRefreshAndDefault = (refreshAtom, getDefault) => {
|
|
5
|
+
const overwrittenAtom = require_base_atom.baseAtom(null);
|
|
6
|
+
return require_base_atom.baseAtom((get) => {
|
|
7
|
+
const lastState = get(overwrittenAtom);
|
|
8
|
+
if (lastState && lastState.refresh === get(refreshAtom)) return lastState.value;
|
|
9
|
+
return getDefault(get);
|
|
10
|
+
}, (get, set, update) => {
|
|
11
|
+
set(overwrittenAtom, {
|
|
12
|
+
refresh: get(refreshAtom),
|
|
13
|
+
value: update
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.atomWithRefreshAndDefault = atomWithRefreshAndDefault;
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import{baseAtom
|
|
1
|
+
import { baseAtom } from "./base-atom.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/base/atoms/atom-with-refresh-and-default.ts
|
|
4
|
+
const atomWithRefreshAndDefault = (refreshAtom, getDefault) => {
|
|
5
|
+
const overwrittenAtom = baseAtom(null);
|
|
6
|
+
return baseAtom((get) => {
|
|
7
|
+
const lastState = get(overwrittenAtom);
|
|
8
|
+
if (lastState && lastState.refresh === get(refreshAtom)) return lastState.value;
|
|
9
|
+
return getDefault(get);
|
|
10
|
+
}, (get, set, update) => {
|
|
11
|
+
set(overwrittenAtom, {
|
|
12
|
+
refresh: get(refreshAtom),
|
|
13
|
+
value: update
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { atomWithRefreshAndDefault };
|
|
2
20
|
//# sourceMappingURL=atom-with-refresh-and-default.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-refresh-and-default.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-refresh-and-default.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_base_atom = require("./base-atom.cjs");
|
|
2
|
+
|
|
3
|
+
//#region src/base/atoms/atom-with-refresh.ts
|
|
4
|
+
function atomWithRefresh(fn) {
|
|
5
|
+
const refreshCounter = require_base_atom.baseAtom(0);
|
|
6
|
+
return require_base_atom.baseAtom((get) => {
|
|
7
|
+
get(refreshCounter);
|
|
8
|
+
return fn(get);
|
|
9
|
+
}, (_, set) => set(refreshCounter, (i) => i + 1));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.atomWithRefresh = atomWithRefresh;
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import{baseAtom
|
|
1
|
+
import { baseAtom } from "./base-atom.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/base/atoms/atom-with-refresh.ts
|
|
4
|
+
function atomWithRefresh(fn) {
|
|
5
|
+
const refreshCounter = baseAtom(0);
|
|
6
|
+
return baseAtom((get) => {
|
|
7
|
+
get(refreshCounter);
|
|
8
|
+
return fn(get);
|
|
9
|
+
}, (_, set) => set(refreshCounter, (i) => i + 1));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { atomWithRefresh };
|
|
2
14
|
//# sourceMappingURL=atom-with-refresh.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-refresh.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-refresh.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_base_atom = require("./base-atom.cjs");
|
|
2
|
+
|
|
3
|
+
//#region src/base/atoms/atom-with-toggle.ts
|
|
4
|
+
function atomWithToggle(initialValue) {
|
|
5
|
+
const anAtom = require_base_atom.baseAtom(initialValue, (get, set, nextValue) => {
|
|
6
|
+
const update = nextValue ?? !get(anAtom);
|
|
7
|
+
set(anAtom, update);
|
|
8
|
+
});
|
|
9
|
+
return anAtom;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.atomWithToggle = atomWithToggle;
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import{baseAtom
|
|
1
|
+
import { baseAtom } from "./base-atom.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/base/atoms/atom-with-toggle.ts
|
|
4
|
+
function atomWithToggle(initialValue) {
|
|
5
|
+
const anAtom = baseAtom(initialValue, (get, set, nextValue) => {
|
|
6
|
+
const update = nextValue ?? !get(anAtom);
|
|
7
|
+
set(anAtom, update);
|
|
8
|
+
});
|
|
9
|
+
return anAtom;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { atomWithToggle };
|
|
2
14
|
//# sourceMappingURL=atom-with-toggle.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-toggle.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-toggle.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,48 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_is_atom = require("../utilities/is-atom.cjs");
|
|
2
|
+
const require_base_atom = require("./base-atom.cjs");
|
|
3
|
+
const require_atom_with_broadcast = require("./atom-with-broadcast.cjs");
|
|
4
|
+
const require_atom_with_debounce = require("./atom-with-debounce.cjs");
|
|
5
|
+
const require_atom_with_effect = require("./atom-with-effect.cjs");
|
|
6
|
+
const require_create_web_storage = require("../utilities/create-web-storage.cjs");
|
|
7
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
8
|
+
let jotai_utils = require("jotai/utils");
|
|
9
|
+
|
|
10
|
+
//#region src/base/atoms/atom-with-web-storage.ts
|
|
11
|
+
const getWebStorage = () => require_create_web_storage.createWebStorage(() => localStorage);
|
|
12
|
+
/**
|
|
13
|
+
* Creates an atom that persists its state in external storage and sends a broadcast message to other tabs/windows when the state changes.
|
|
14
|
+
*
|
|
15
|
+
* @param key - The key to use for the storage
|
|
16
|
+
* @param initialValue - The initial value of the atom
|
|
17
|
+
* @param webStorage - The storage to use
|
|
18
|
+
* @returns An atom that persists its state in external storage and sends a broadcast message to other tabs/windows when the state changes.
|
|
19
|
+
*/
|
|
20
|
+
function atomWithWebStorage(key, initialValueOrAtom, webStorage = getWebStorage(), options) {
|
|
21
|
+
const debounceMs = options?.debounceMs ?? 500;
|
|
22
|
+
const getOnInit = options?.getOnInit ?? true;
|
|
23
|
+
const valueAtom = require_is_atom.isAtom(initialValueOrAtom) ? initialValueOrAtom : require_base_atom.baseAtom(initialValueOrAtom);
|
|
24
|
+
const debouncedStorageAtom = require_atom_with_debounce.atomWithDebounce((0, jotai_utils.atomWithStorage)(key, require_is_atom.isAtom(initialValueOrAtom) ? void 0 : initialValueOrAtom, webStorage, { getOnInit }), debounceMs);
|
|
25
|
+
const debouncedBroadcastAtom = require_atom_with_debounce.atomWithDebounce(require_atom_with_broadcast.atomWithBroadcast(key, require_is_atom.isAtom(initialValueOrAtom) ? void 0 : initialValueOrAtom), debounceMs);
|
|
26
|
+
const wrapperAtom = require_base_atom.baseAtom((get) => {
|
|
27
|
+
return get(valueAtom);
|
|
28
|
+
}, (get, set, update) => {
|
|
29
|
+
const nextValue = (0, _stryke_type_checks_is_function.isFunction)(update) ? update(get(valueAtom)) : update;
|
|
30
|
+
set(valueAtom, nextValue);
|
|
31
|
+
set(debouncedStorageAtom.debouncedValueAtom, nextValue);
|
|
32
|
+
set(debouncedBroadcastAtom.debouncedValueAtom, nextValue);
|
|
33
|
+
});
|
|
34
|
+
const effectAtom = require_atom_with_effect.atomWithEffect((get, set) => {
|
|
35
|
+
const next = get(debouncedBroadcastAtom.debouncedValueAtom);
|
|
36
|
+
if (next !== get(wrapperAtom)) set(wrapperAtom, next);
|
|
37
|
+
});
|
|
38
|
+
return require_base_atom.baseAtom((get) => {
|
|
39
|
+
get(effectAtom);
|
|
40
|
+
return get(wrapperAtom);
|
|
41
|
+
}, (get, set, update) => {
|
|
42
|
+
set(wrapperAtom, update);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.atomWithWebStorage = atomWithWebStorage;
|
|
48
|
+
exports.getWebStorage = getWebStorage;
|
|
@@ -1,2 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isAtom } from "../utilities/is-atom.mjs";
|
|
2
|
+
import { baseAtom } from "./base-atom.mjs";
|
|
3
|
+
import { atomWithBroadcast } from "./atom-with-broadcast.mjs";
|
|
4
|
+
import { atomWithDebounce } from "./atom-with-debounce.mjs";
|
|
5
|
+
import { atomWithEffect } from "./atom-with-effect.mjs";
|
|
6
|
+
import { createWebStorage } from "../utilities/create-web-storage.mjs";
|
|
7
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
8
|
+
import { atomWithStorage } from "jotai/utils";
|
|
9
|
+
|
|
10
|
+
//#region src/base/atoms/atom-with-web-storage.ts
|
|
11
|
+
const getWebStorage = () => createWebStorage(() => localStorage);
|
|
12
|
+
/**
|
|
13
|
+
* Creates an atom that persists its state in external storage and sends a broadcast message to other tabs/windows when the state changes.
|
|
14
|
+
*
|
|
15
|
+
* @param key - The key to use for the storage
|
|
16
|
+
* @param initialValue - The initial value of the atom
|
|
17
|
+
* @param webStorage - The storage to use
|
|
18
|
+
* @returns An atom that persists its state in external storage and sends a broadcast message to other tabs/windows when the state changes.
|
|
19
|
+
*/
|
|
20
|
+
function atomWithWebStorage(key, initialValueOrAtom, webStorage = getWebStorage(), options) {
|
|
21
|
+
const debounceMs = options?.debounceMs ?? 500;
|
|
22
|
+
const getOnInit = options?.getOnInit ?? true;
|
|
23
|
+
const valueAtom = isAtom(initialValueOrAtom) ? initialValueOrAtom : baseAtom(initialValueOrAtom);
|
|
24
|
+
const debouncedStorageAtom = atomWithDebounce(atomWithStorage(key, isAtom(initialValueOrAtom) ? void 0 : initialValueOrAtom, webStorage, { getOnInit }), debounceMs);
|
|
25
|
+
const debouncedBroadcastAtom = atomWithDebounce(atomWithBroadcast(key, isAtom(initialValueOrAtom) ? void 0 : initialValueOrAtom), debounceMs);
|
|
26
|
+
const wrapperAtom = baseAtom((get) => {
|
|
27
|
+
return get(valueAtom);
|
|
28
|
+
}, (get, set, update) => {
|
|
29
|
+
const nextValue = isFunction(update) ? update(get(valueAtom)) : update;
|
|
30
|
+
set(valueAtom, nextValue);
|
|
31
|
+
set(debouncedStorageAtom.debouncedValueAtom, nextValue);
|
|
32
|
+
set(debouncedBroadcastAtom.debouncedValueAtom, nextValue);
|
|
33
|
+
});
|
|
34
|
+
const effectAtom = atomWithEffect((get, set) => {
|
|
35
|
+
const next = get(debouncedBroadcastAtom.debouncedValueAtom);
|
|
36
|
+
if (next !== get(wrapperAtom)) set(wrapperAtom, next);
|
|
37
|
+
});
|
|
38
|
+
return baseAtom((get) => {
|
|
39
|
+
get(effectAtom);
|
|
40
|
+
return get(wrapperAtom);
|
|
41
|
+
}, (get, set, update) => {
|
|
42
|
+
set(wrapperAtom, update);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { atomWithWebStorage, getWebStorage };
|
|
2
48
|
//# sourceMappingURL=atom-with-web-storage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-web-storage.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-web-storage.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_base_atom = require("./base-atom.cjs");
|
|
2
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
3
|
+
|
|
4
|
+
//#region src/base/atoms/atom-with-wrapper.ts
|
|
5
|
+
const wrapFn = (fnOrValue) => (0, _stryke_type_checks_is_function.isFunction)(fnOrValue) ? { __fn: fnOrValue } : fnOrValue;
|
|
6
|
+
const unwrapFn = (wrappedFnOrValue) => wrappedFnOrValue && typeof wrappedFnOrValue === "object" && "__fn" in wrappedFnOrValue ? wrappedFnOrValue.__fn : wrappedFnOrValue;
|
|
7
|
+
/**
|
|
8
|
+
* Create an atom with a wrapper that allows functions as values.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Jotai atoms don't allow functions as values by default. This function is a
|
|
12
|
+
* drop-in replacement for `atom` that wraps functions in an object while
|
|
13
|
+
* leaving non-functions unchanged. The wrapper object should be completely
|
|
14
|
+
* invisible to consumers of the atom.
|
|
15
|
+
*
|
|
16
|
+
* @param initialValue - The initial value of the atom
|
|
17
|
+
* @returns An atom with a wrapper that allows functions as values.
|
|
18
|
+
*/
|
|
19
|
+
const atomWithWrapper = (initialValue) => {
|
|
20
|
+
const rootAtom = require_base_atom.baseAtom(wrapFn(initialValue));
|
|
21
|
+
return require_base_atom.baseAtom((get) => unwrapFn(get(rootAtom)), (_get, set, value) => set(rootAtom, wrapFn(value)));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.atomWithWrapper = atomWithWrapper;
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import{baseAtom
|
|
1
|
+
import { baseAtom } from "./base-atom.mjs";
|
|
2
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
3
|
+
|
|
4
|
+
//#region src/base/atoms/atom-with-wrapper.ts
|
|
5
|
+
const wrapFn = (fnOrValue) => isFunction(fnOrValue) ? { __fn: fnOrValue } : fnOrValue;
|
|
6
|
+
const unwrapFn = (wrappedFnOrValue) => wrappedFnOrValue && typeof wrappedFnOrValue === "object" && "__fn" in wrappedFnOrValue ? wrappedFnOrValue.__fn : wrappedFnOrValue;
|
|
7
|
+
/**
|
|
8
|
+
* Create an atom with a wrapper that allows functions as values.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Jotai atoms don't allow functions as values by default. This function is a
|
|
12
|
+
* drop-in replacement for `atom` that wraps functions in an object while
|
|
13
|
+
* leaving non-functions unchanged. The wrapper object should be completely
|
|
14
|
+
* invisible to consumers of the atom.
|
|
15
|
+
*
|
|
16
|
+
* @param initialValue - The initial value of the atom
|
|
17
|
+
* @returns An atom with a wrapper that allows functions as values.
|
|
18
|
+
*/
|
|
19
|
+
const atomWithWrapper = (initialValue) => {
|
|
20
|
+
const rootAtom = baseAtom(wrapFn(initialValue));
|
|
21
|
+
return baseAtom((get) => unwrapFn(get(rootAtom)), (_get, set, value) => set(rootAtom, wrapFn(value)));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { atomWithWrapper };
|
|
2
26
|
//# sourceMappingURL=atom-with-wrapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom-with-wrapper.mjs","names":[
|
|
1
|
+
{"version":3,"file":"atom-with-wrapper.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_set_atom_debug = require("../utilities/set-atom-debug.cjs");
|
|
2
|
+
let jotai_vanilla = require("jotai/vanilla");
|
|
3
|
+
|
|
4
|
+
//#region src/base/atoms/base-atom.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a "base" atom that can be used to create derived atoms.
|
|
7
|
+
* The base atom is a writable atom that can be used to create derived atoms.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function serves as a wrapper around the `atom` function from the Jotai library that adds debugging helpers.
|
|
11
|
+
*
|
|
12
|
+
* @param readOrInitialValue - The initial value of the atom or a read function
|
|
13
|
+
* @param write - The write function for the atom
|
|
14
|
+
* @returns The base atom
|
|
15
|
+
*/
|
|
16
|
+
function baseAtom(readOrInitialValue, write) {
|
|
17
|
+
const result = (0, jotai_vanilla.atom)(readOrInitialValue, write);
|
|
18
|
+
result.setDebugLabel = (label) => {
|
|
19
|
+
require_set_atom_debug.setAtomDebugLabel(result, label);
|
|
20
|
+
};
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.baseAtom = baseAtom;
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import{setAtomDebugLabel
|
|
1
|
+
import { setAtomDebugLabel } from "../utilities/set-atom-debug.mjs";
|
|
2
|
+
import { atom } from "jotai/vanilla";
|
|
3
|
+
|
|
4
|
+
//#region src/base/atoms/base-atom.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a "base" atom that can be used to create derived atoms.
|
|
7
|
+
* The base atom is a writable atom that can be used to create derived atoms.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function serves as a wrapper around the `atom` function from the Jotai library that adds debugging helpers.
|
|
11
|
+
*
|
|
12
|
+
* @param readOrInitialValue - The initial value of the atom or a read function
|
|
13
|
+
* @param write - The write function for the atom
|
|
14
|
+
* @returns The base atom
|
|
15
|
+
*/
|
|
16
|
+
function baseAtom(readOrInitialValue, write) {
|
|
17
|
+
const result = atom(readOrInitialValue, write);
|
|
18
|
+
result.setDebugLabel = (label) => {
|
|
19
|
+
setAtomDebugLabel(result, label);
|
|
20
|
+
};
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { baseAtom };
|
|
2
26
|
//# sourceMappingURL=base-atom.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-atom.mjs","names":["jotaiAtom"
|
|
1
|
+
{"version":3,"file":"base-atom.mjs","names":["jotaiAtom"],"sources":[],"mappings":""}
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_atom_with_broadcast = require("./atom-with-broadcast.cjs");
|
|
2
|
+
const require_atom_with_compare = require("./atom-with-compare.cjs");
|
|
3
|
+
const require_atom_with_wrapper = require("./atom-with-wrapper.cjs");
|
|
4
|
+
const require_atom_with_debounce = require("./atom-with-debounce.cjs");
|
|
5
|
+
const require_atom_with_effect = require("./atom-with-effect.cjs");
|
|
6
|
+
const require_atom_with_listeners = require("./atom-with-listeners.cjs");
|
|
7
|
+
const require_atom_with_pending = require("./atom-with-pending.cjs");
|
|
8
|
+
const require_atom_with_refresh = require("./atom-with-refresh.cjs");
|
|
9
|
+
const require_atom_with_refresh_and_default = require("./atom-with-refresh-and-default.cjs");
|
|
10
|
+
const require_atom_with_toggle = require("./atom-with-toggle.cjs");
|
|
11
|
+
const require_atom_with_web_storage = require("./atom-with-web-storage.cjs");
|
|
12
|
+
|
|
13
|
+
exports.atomWithBroadcast = require_atom_with_broadcast.atomWithBroadcast;
|
|
14
|
+
exports.atomWithCompare = require_atom_with_compare.atomWithCompare;
|
|
15
|
+
exports.atomWithDebounce = require_atom_with_debounce.atomWithDebounce;
|
|
16
|
+
exports.atomWithEffect = require_atom_with_effect.atomWithEffect;
|
|
17
|
+
exports.atomWithListeners = require_atom_with_listeners.atomWithListeners;
|
|
18
|
+
exports.atomWithPending = require_atom_with_pending.atomWithPending;
|
|
19
|
+
exports.atomWithRefresh = require_atom_with_refresh.atomWithRefresh;
|
|
20
|
+
exports.atomWithRefreshAndDefault = require_atom_with_refresh_and_default.atomWithRefreshAndDefault;
|
|
21
|
+
exports.atomWithToggle = require_atom_with_toggle.atomWithToggle;
|
|
22
|
+
exports.atomWithWebStorage = require_atom_with_web_storage.atomWithWebStorage;
|
|
23
|
+
exports.atomWithWrapper = require_atom_with_wrapper.atomWithWrapper;
|
|
24
|
+
exports.getWebStorage = require_atom_with_web_storage.getWebStorage;
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { atomWithBroadcast } from "./atom-with-broadcast.mjs";
|
|
2
|
+
import { atomWithCompare } from "./atom-with-compare.mjs";
|
|
3
|
+
import { atomWithWrapper } from "./atom-with-wrapper.mjs";
|
|
4
|
+
import { atomWithDebounce } from "./atom-with-debounce.mjs";
|
|
5
|
+
import { atomWithEffect } from "./atom-with-effect.mjs";
|
|
6
|
+
import { atomWithListeners } from "./atom-with-listeners.mjs";
|
|
7
|
+
import { atomWithPending } from "./atom-with-pending.mjs";
|
|
8
|
+
import { atomWithRefresh } from "./atom-with-refresh.mjs";
|
|
9
|
+
import { atomWithRefreshAndDefault } from "./atom-with-refresh-and-default.mjs";
|
|
10
|
+
import { atomWithToggle } from "./atom-with-toggle.mjs";
|
|
11
|
+
import { atomWithWebStorage, getWebStorage } from "./atom-with-web-storage.mjs";
|
|
12
|
+
|
|
13
|
+
export { atomWithBroadcast, atomWithCompare, atomWithDebounce, atomWithEffect, atomWithListeners, atomWithPending, atomWithRefresh, atomWithRefreshAndDefault, atomWithToggle, atomWithWebStorage, atomWithWrapper, getWebStorage };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_use_atom_effect = require("./use-atom-effect.cjs");
|
|
2
|
+
const require_use_hydrate_molecule = require("./use-hydrate-molecule.cjs");
|
|
3
|
+
const require_use_prepare_atoms = require("./use-prepare-atoms.cjs");
|
|
4
|
+
const require_use_sync_molecule = require("./use-sync-molecule.cjs");
|
|
5
|
+
|
|
6
|
+
exports.useAtomEffect = require_use_atom_effect.useAtomEffect;
|
|
7
|
+
exports.useHydrateMolecule = require_use_hydrate_molecule.useHydrateMolecule;
|
|
8
|
+
exports.usePrepareAtoms = require_use_prepare_atoms.usePrepareAtoms;
|
|
9
|
+
exports.useSyncMolecule = require_use_sync_molecule.useSyncMolecule;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useAtomEffect } from "./use-atom-effect.mjs";
|
|
2
|
+
import { useHydrateMolecule } from "./use-hydrate-molecule.mjs";
|
|
3
|
+
import { usePrepareAtoms } from "./use-prepare-atoms.mjs";
|
|
4
|
+
import { useSyncMolecule } from "./use-sync-molecule.mjs";
|
|
5
|
+
|
|
6
|
+
export { useAtomEffect, useHydrateMolecule, usePrepareAtoms, useSyncMolecule };
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_atom_with_effect = require("../atoms/atom-with-effect.cjs");
|
|
2
|
+
let jotai_utils = require("jotai/utils");
|
|
3
|
+
let _stryke_hooks_use_memo_stable = require("@stryke/hooks/use-memo-stable");
|
|
4
|
+
let jotai_react = require("jotai/react");
|
|
5
|
+
|
|
6
|
+
//#region src/base/hooks/use-atom-effect.ts
|
|
7
|
+
/**
|
|
8
|
+
* A hook that runs a side effect when the component mounts.
|
|
9
|
+
*
|
|
10
|
+
* @param effectFn - The side effect function.
|
|
11
|
+
*/
|
|
12
|
+
function useAtomEffect(effectFn, deps = []) {
|
|
13
|
+
(0, jotai_react.useAtomValue)((0, jotai_utils.loadable)((0, _stryke_hooks_use_memo_stable.useMemoStable)(() => require_atom_with_effect.atomWithEffect(effectFn), deps)));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.useAtomEffect = useAtomEffect;
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
import{atomWithEffect
|
|
1
|
+
import { atomWithEffect } from "../atoms/atom-with-effect.mjs";
|
|
2
|
+
import { loadable } from "jotai/utils";
|
|
3
|
+
import { useMemoStable } from "@stryke/hooks/use-memo-stable";
|
|
4
|
+
import { useAtomValue } from "jotai/react";
|
|
5
|
+
|
|
6
|
+
//#region src/base/hooks/use-atom-effect.ts
|
|
7
|
+
/**
|
|
8
|
+
* A hook that runs a side effect when the component mounts.
|
|
9
|
+
*
|
|
10
|
+
* @param effectFn - The side effect function.
|
|
11
|
+
*/
|
|
12
|
+
function useAtomEffect(effectFn, deps = []) {
|
|
13
|
+
useAtomValue(loadable(useMemoStable(() => atomWithEffect(effectFn), deps)));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { useAtomEffect };
|
|
2
18
|
//# sourceMappingURL=use-atom-effect.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-atom-effect.mjs","names":[
|
|
1
|
+
{"version":3,"file":"use-atom-effect.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
let
|
|
1
|
+
let jotai_utils = require("jotai/utils");
|
|
2
|
+
|
|
3
|
+
//#region src/base/hooks/use-hydrate-molecule.ts
|
|
4
|
+
/**
|
|
5
|
+
* Hydrate atoms with initial values for SSR.
|
|
6
|
+
*/
|
|
7
|
+
const useHydrateMolecule = (atoms, initialValues, store) => {
|
|
8
|
+
const values = [];
|
|
9
|
+
for (const key of Object.keys(atoms)) {
|
|
10
|
+
const initialValue = initialValues[key];
|
|
11
|
+
if (initialValue !== void 0) values.push([atoms[key], initialValue]);
|
|
12
|
+
}
|
|
13
|
+
(0, jotai_utils.useHydrateAtoms)(values, { store });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.useHydrateMolecule = useHydrateMolecule;
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
import{useHydrateAtoms
|
|
1
|
+
import { useHydrateAtoms } from "jotai/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/base/hooks/use-hydrate-molecule.ts
|
|
4
|
+
/**
|
|
5
|
+
* Hydrate atoms with initial values for SSR.
|
|
6
|
+
*/
|
|
7
|
+
const useHydrateMolecule = (atoms, initialValues, store) => {
|
|
8
|
+
const values = [];
|
|
9
|
+
for (const key of Object.keys(atoms)) {
|
|
10
|
+
const initialValue = initialValues[key];
|
|
11
|
+
if (initialValue !== void 0) values.push([atoms[key], initialValue]);
|
|
12
|
+
}
|
|
13
|
+
useHydrateAtoms(values, { store });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { useHydrateMolecule };
|
|
2
18
|
//# sourceMappingURL=use-hydrate-molecule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hydrate-molecule.mjs","names":[
|
|
1
|
+
{"version":3,"file":"use-hydrate-molecule.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
let
|
|
1
|
+
let jotai_vanilla = require("jotai/vanilla");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let jotai_react = require("jotai/react");
|
|
4
|
+
|
|
5
|
+
//#region src/base/hooks/use-prepare-atoms.ts
|
|
6
|
+
function useMemoList(list, compareFn = (a, b) => a === b) {
|
|
7
|
+
const [state, setState] = (0, react.useState)(list);
|
|
8
|
+
const listChanged = list.length !== state.length || list.some((arg, index) => !compareFn(arg, state[index]));
|
|
9
|
+
if (listChanged) setState(list);
|
|
10
|
+
return listChanged ? list : state;
|
|
11
|
+
}
|
|
12
|
+
function usePrepareAtoms(atoms, options) {
|
|
13
|
+
const stableAtoms = useMemoList(atoms);
|
|
14
|
+
(0, jotai_react.useAtomValue)((0, react.useMemo)(() => (0, jotai_vanilla.atom)((get) => {
|
|
15
|
+
stableAtoms.map((stableAtom) => get(stableAtom));
|
|
16
|
+
}), [stableAtoms]), options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.usePrepareAtoms = usePrepareAtoms;
|
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
import{atom
|
|
1
|
+
import { atom } from "jotai/vanilla";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { useAtomValue } from "jotai/react";
|
|
4
|
+
|
|
5
|
+
//#region src/base/hooks/use-prepare-atoms.ts
|
|
6
|
+
function useMemoList(list, compareFn = (a, b) => a === b) {
|
|
7
|
+
const [state, setState] = useState(list);
|
|
8
|
+
const listChanged = list.length !== state.length || list.some((arg, index) => !compareFn(arg, state[index]));
|
|
9
|
+
if (listChanged) setState(list);
|
|
10
|
+
return listChanged ? list : state;
|
|
11
|
+
}
|
|
12
|
+
function usePrepareAtoms(atoms, options) {
|
|
13
|
+
const stableAtoms = useMemoList(atoms);
|
|
14
|
+
useAtomValue(useMemo(() => atom((get) => {
|
|
15
|
+
stableAtoms.map((stableAtom) => get(stableAtom));
|
|
16
|
+
}), [stableAtoms]), options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { usePrepareAtoms };
|
|
2
21
|
//# sourceMappingURL=use-prepare-atoms.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-prepare-atoms.mjs","names":[
|
|
1
|
+
{"version":3,"file":"use-prepare-atoms.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_is_atom = require("../utilities/is-atom.cjs");
|
|
2
|
+
let _stryke_helpers_is_equal = require("@stryke/helpers/is-equal");
|
|
3
|
+
let jotai = require("jotai");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
|
|
6
|
+
//#region src/base/hooks/use-sync-molecule.ts
|
|
7
|
+
/**
|
|
8
|
+
* Keep the previous reference while `value` is deeply equal to it, so callers
|
|
9
|
+
* passing a fresh object literal each render do not re-trigger effects.
|
|
10
|
+
*/
|
|
11
|
+
const useDeepStable = (value) => {
|
|
12
|
+
const ref = (0, react.useRef)(value);
|
|
13
|
+
if (!(0, _stryke_helpers_is_equal.isEqual)(ref.current, value)) ref.current = value;
|
|
14
|
+
return ref.current;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Update atoms with new values on changes.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Values are compared deeply, so a provider that re-renders with equivalent
|
|
21
|
+
* `initialState` does not write to its atoms again. Without this, two
|
|
22
|
+
* providers sharing a molecule scope overwrite each other on every render.
|
|
23
|
+
*/
|
|
24
|
+
const useSyncMolecule = (atoms, values, store) => {
|
|
25
|
+
for (const key of Object.keys(atoms)) {
|
|
26
|
+
let value = values[key];
|
|
27
|
+
if (require_is_atom.isAtom(value)) value = (0, jotai.useAtomValue)(value);
|
|
28
|
+
value = useDeepStable(value);
|
|
29
|
+
const setAtom = (0, jotai.useSetAtom)(atoms[key], { store });
|
|
30
|
+
(0, react.useEffect)(() => {
|
|
31
|
+
if (value !== void 0) setAtom(value);
|
|
32
|
+
}, [setAtom, value]);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.useSyncMolecule = useSyncMolecule;
|