@depup/jotai 2.18.0-depup.0
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/LICENSE +21 -0
- package/README.md +25 -0
- package/babel/plugin-debug-label.d.ts +5 -0
- package/babel/plugin-debug-label.js +54 -0
- package/babel/plugin-react-refresh.d.ts +5 -0
- package/babel/plugin-react-refresh.js +72 -0
- package/babel/preset.d.ts +6 -0
- package/babel/preset.js +110 -0
- package/babel/utils.d.ts +5 -0
- package/benchmarks/simple-read.d.ts +2 -0
- package/benchmarks/simple-write.d.ts +2 -0
- package/benchmarks/subscribe-write.d.ts +2 -0
- package/changes.json +5 -0
- package/esm/babel/plugin-debug-label.d.mts +5 -0
- package/esm/babel/plugin-debug-label.mjs +103 -0
- package/esm/babel/plugin-react-refresh.d.mts +5 -0
- package/esm/babel/plugin-react-refresh.mjs +121 -0
- package/esm/babel/preset.d.mts +6 -0
- package/esm/babel/preset.mjs +179 -0
- package/esm/babel/utils.d.mts +5 -0
- package/esm/index.d.mts +2 -0
- package/esm/index.mjs +2 -0
- package/esm/react/Provider.d.mts +16 -0
- package/esm/react/useAtom.d.mts +13 -0
- package/esm/react/useAtomValue.d.mts +9 -0
- package/esm/react/useSetAtom.d.mts +7 -0
- package/esm/react/utils/useAtomCallback.d.mts +5 -0
- package/esm/react/utils/useHydrateAtoms.d.mts +14 -0
- package/esm/react/utils/useReducerAtom.d.mts +14 -0
- package/esm/react/utils/useResetAtom.d.mts +6 -0
- package/esm/react/utils.d.mts +4 -0
- package/esm/react/utils.mjs +57 -0
- package/esm/react.d.mts +4 -0
- package/esm/react.mjs +182 -0
- package/esm/utils.d.mts +2 -0
- package/esm/utils.mjs +2 -0
- package/esm/vanilla/atom.d.mts +47 -0
- package/esm/vanilla/internals.d.mts +164 -0
- package/esm/vanilla/internals.mjs +715 -0
- package/esm/vanilla/store.d.mts +5 -0
- package/esm/vanilla/typeUtils.d.mts +7 -0
- package/esm/vanilla/utils/atomFamily.d.mts +55 -0
- package/esm/vanilla/utils/atomWithDefault.d.mts +6 -0
- package/esm/vanilla/utils/atomWithLazy.d.mts +2 -0
- package/esm/vanilla/utils/atomWithObservable.d.mts +32 -0
- package/esm/vanilla/utils/atomWithReducer.d.mts +3 -0
- package/esm/vanilla/utils/atomWithRefresh.d.mts +6 -0
- package/esm/vanilla/utils/atomWithReset.d.mts +8 -0
- package/esm/vanilla/utils/atomWithStorage.d.mts +50 -0
- package/esm/vanilla/utils/constants.d.mts +1 -0
- package/esm/vanilla/utils/freezeAtom.d.mts +6 -0
- package/esm/vanilla/utils/loadable.d.mts +33 -0
- package/esm/vanilla/utils/selectAtom.d.mts +2 -0
- package/esm/vanilla/utils/splitAtom.d.mts +16 -0
- package/esm/vanilla/utils/unwrap.d.mts +5 -0
- package/esm/vanilla/utils.d.mts +14 -0
- package/esm/vanilla/utils.mjs +736 -0
- package/esm/vanilla.d.mts +4 -0
- package/esm/vanilla.mjs +59 -0
- package/index.d.ts +2 -0
- package/index.js +19 -0
- package/package.json +125 -0
- package/react/Provider.d.ts +16 -0
- package/react/useAtom.d.ts +13 -0
- package/react/useAtomValue.d.ts +9 -0
- package/react/useSetAtom.d.ts +7 -0
- package/react/utils/useAtomCallback.d.ts +5 -0
- package/react/utils/useHydrateAtoms.d.ts +14 -0
- package/react/utils/useReducerAtom.d.ts +14 -0
- package/react/utils/useResetAtom.d.ts +6 -0
- package/react/utils.d.ts +4 -0
- package/react/utils.js +100 -0
- package/react.d.ts +4 -0
- package/react.js +182 -0
- package/system/babel/plugin-debug-label.development.js +113 -0
- package/system/babel/plugin-debug-label.production.js +4 -0
- package/system/babel/plugin-react-refresh.development.js +131 -0
- package/system/babel/plugin-react-refresh.production.js +11 -0
- package/system/babel/preset.development.js +189 -0
- package/system/babel/preset.production.js +14 -0
- package/system/index.development.js +27 -0
- package/system/index.production.js +1 -0
- package/system/react/utils.development.js +79 -0
- package/system/react/utils.production.js +2 -0
- package/system/react.development.js +210 -0
- package/system/react.production.js +2 -0
- package/system/utils.development.js +27 -0
- package/system/utils.production.js +1 -0
- package/system/vanilla/internals.development.js +735 -0
- package/system/vanilla/internals.production.js +1 -0
- package/system/vanilla/utils.development.js +764 -0
- package/system/vanilla/utils.production.js +1 -0
- package/system/vanilla.development.js +75 -0
- package/system/vanilla.production.js +1 -0
- package/ts3.8/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/babel/preset.d.ts +7 -0
- package/ts3.8/babel/utils.d.ts +6 -0
- package/ts3.8/benchmarks/simple-read.d.ts +3 -0
- package/ts3.8/benchmarks/simple-write.d.ts +3 -0
- package/ts3.8/benchmarks/subscribe-write.d.ts +3 -0
- package/ts3.8/esm/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/esm/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/esm/babel/preset.d.ts +7 -0
- package/ts3.8/esm/babel/utils.d.ts +6 -0
- package/ts3.8/esm/index.d.ts +3 -0
- package/ts3.8/esm/react/Provider.d.ts +17 -0
- package/ts3.8/esm/react/useAtom.d.ts +28 -0
- package/ts3.8/esm/react/useAtomValue.d.ts +10 -0
- package/ts3.8/esm/react/useSetAtom.d.ts +8 -0
- package/ts3.8/esm/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/esm/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/esm/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/esm/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/esm/react/utils.d.ts +5 -0
- package/ts3.8/esm/react.d.ts +5 -0
- package/ts3.8/esm/utils.d.ts +3 -0
- package/ts3.8/esm/vanilla/atom.d.ts +48 -0
- package/ts3.8/esm/vanilla/internals.d.ts +165 -0
- package/ts3.8/esm/vanilla/store.d.ts +6 -0
- package/ts3.8/esm/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/esm/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/esm/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/esm/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/esm/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/esm/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/esm/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/esm/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/esm/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/esm/vanilla/utils.d.ts +15 -0
- package/ts3.8/esm/vanilla.d.ts +5 -0
- package/ts3.8/index.d.ts +3 -0
- package/ts3.8/react/Provider.d.ts +17 -0
- package/ts3.8/react/useAtom.d.ts +28 -0
- package/ts3.8/react/useAtomValue.d.ts +10 -0
- package/ts3.8/react/useSetAtom.d.ts +8 -0
- package/ts3.8/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/react/utils.d.ts +5 -0
- package/ts3.8/react.d.ts +5 -0
- package/ts3.8/utils.d.ts +3 -0
- package/ts3.8/vanilla/atom.d.ts +48 -0
- package/ts3.8/vanilla/internals.d.ts +165 -0
- package/ts3.8/vanilla/store.d.ts +6 -0
- package/ts3.8/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/vanilla/utils.d.ts +15 -0
- package/ts3.8/vanilla.d.ts +5 -0
- package/ts_version_3.8_and_above_is_required.d.ts +0 -0
- package/umd/babel/plugin-debug-label.development.js +58 -0
- package/umd/babel/plugin-debug-label.production.js +1 -0
- package/umd/babel/plugin-react-refresh.development.js +76 -0
- package/umd/babel/plugin-react-refresh.production.js +1 -0
- package/umd/babel/preset.development.js +114 -0
- package/umd/babel/preset.production.js +1 -0
- package/umd/index.development.js +20 -0
- package/umd/index.production.js +1 -0
- package/umd/react/utils.development.js +101 -0
- package/umd/react/utils.production.js +1 -0
- package/umd/react.development.js +184 -0
- package/umd/react.production.js +1 -0
- package/umd/utils.development.js +20 -0
- package/umd/utils.production.js +1 -0
- package/umd/vanilla/internals.development.js +785 -0
- package/umd/vanilla/internals.production.js +1 -0
- package/umd/vanilla/utils.development.js +858 -0
- package/umd/vanilla/utils.production.js +1 -0
- package/umd/vanilla.development.js +64 -0
- package/umd/vanilla.production.js +1 -0
- package/utils.d.ts +2 -0
- package/utils.js +19 -0
- package/vanilla/atom.d.ts +47 -0
- package/vanilla/internals.d.ts +164 -0
- package/vanilla/internals.js +779 -0
- package/vanilla/store.d.ts +5 -0
- package/vanilla/typeUtils.d.ts +7 -0
- package/vanilla/utils/atomFamily.d.ts +55 -0
- package/vanilla/utils/atomWithDefault.d.ts +6 -0
- package/vanilla/utils/atomWithLazy.d.ts +2 -0
- package/vanilla/utils/atomWithObservable.d.ts +32 -0
- package/vanilla/utils/atomWithReducer.d.ts +3 -0
- package/vanilla/utils/atomWithRefresh.d.ts +6 -0
- package/vanilla/utils/atomWithReset.d.ts +8 -0
- package/vanilla/utils/atomWithStorage.d.ts +50 -0
- package/vanilla/utils/constants.d.ts +1 -0
- package/vanilla/utils/freezeAtom.d.ts +6 -0
- package/vanilla/utils/loadable.d.ts +33 -0
- package/vanilla/utils/selectAtom.d.ts +2 -0
- package/vanilla/utils/splitAtom.d.ts +16 -0
- package/vanilla/utils/unwrap.d.ts +5 -0
- package/vanilla/utils.d.ts +14 -0
- package/vanilla/utils.js +854 -0
- package/vanilla.d.ts +4 -0
- package/vanilla.js +60 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
System.register(['@babel/core', '@babel/template'], (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
var _templateBuilder;
|
|
4
|
+
return {
|
|
5
|
+
setters: [null, function (module) {
|
|
6
|
+
_templateBuilder = module.default;
|
|
7
|
+
}],
|
|
8
|
+
execute: (function () {
|
|
9
|
+
|
|
10
|
+
exports("default", debugLabelPlugin);
|
|
11
|
+
|
|
12
|
+
function isAtom(t, callee, customAtomNames = []) {
|
|
13
|
+
const atomNames = [...atomFunctionNames, ...customAtomNames];
|
|
14
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (t.isMemberExpression(callee)) {
|
|
18
|
+
const { property } = callee;
|
|
19
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const atomFunctionNames = [
|
|
26
|
+
// Core
|
|
27
|
+
"atom",
|
|
28
|
+
"atomFamily",
|
|
29
|
+
"atomWithDefault",
|
|
30
|
+
"atomWithObservable",
|
|
31
|
+
"atomWithReducer",
|
|
32
|
+
"atomWithReset",
|
|
33
|
+
"atomWithStorage",
|
|
34
|
+
"freezeAtom",
|
|
35
|
+
"loadable",
|
|
36
|
+
"selectAtom",
|
|
37
|
+
"splitAtom",
|
|
38
|
+
"unwrap",
|
|
39
|
+
// jotai-xstate
|
|
40
|
+
"atomWithMachine",
|
|
41
|
+
// jotai-immer
|
|
42
|
+
"atomWithImmer",
|
|
43
|
+
// jotai-valtio
|
|
44
|
+
"atomWithProxy",
|
|
45
|
+
// jotai-trpc + jotai-relay
|
|
46
|
+
"atomWithQuery",
|
|
47
|
+
"atomWithMutation",
|
|
48
|
+
"atomWithSubscription",
|
|
49
|
+
// jotai-redux + jotai-zustand
|
|
50
|
+
"atomWithStore",
|
|
51
|
+
// jotai-location
|
|
52
|
+
"atomWithHash",
|
|
53
|
+
"atomWithLocation",
|
|
54
|
+
// jotai-optics
|
|
55
|
+
"focusAtom",
|
|
56
|
+
// jotai-form
|
|
57
|
+
"atomWithValidate",
|
|
58
|
+
"validateAtoms",
|
|
59
|
+
// jotai-cache
|
|
60
|
+
"atomWithCache",
|
|
61
|
+
// jotai-recoil
|
|
62
|
+
"atomWithRecoilValue"
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
66
|
+
function debugLabelPlugin({ types: t }, options) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
visitor: {
|
|
72
|
+
ExportDefaultDeclaration(nodePath, state) {
|
|
73
|
+
const { node } = nodePath;
|
|
74
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
75
|
+
const filename = (state.filename || "unknown").replace(/\.\w+$/, "");
|
|
76
|
+
let displayName = filename.split("/").pop();
|
|
77
|
+
if (displayName === "index") {
|
|
78
|
+
displayName = filename.slice(0, -"/index".length).split("/").pop() || "unknown";
|
|
79
|
+
}
|
|
80
|
+
const buildExport = templateBuilder(`
|
|
81
|
+
const %%atomIdentifier%% = %%atom%%;
|
|
82
|
+
export default %%atomIdentifier%%
|
|
83
|
+
`);
|
|
84
|
+
const ast = buildExport({
|
|
85
|
+
atomIdentifier: t.identifier(displayName),
|
|
86
|
+
atom: node.declaration
|
|
87
|
+
});
|
|
88
|
+
nodePath.replaceWithMultiple(ast);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
VariableDeclarator(path) {
|
|
92
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
93
|
+
path.parentPath.insertAfter(
|
|
94
|
+
t.expressionStatement(
|
|
95
|
+
t.assignmentExpression(
|
|
96
|
+
"=",
|
|
97
|
+
t.memberExpression(
|
|
98
|
+
t.identifier(path.node.id.name),
|
|
99
|
+
t.identifier("debugLabel")
|
|
100
|
+
),
|
|
101
|
+
t.stringLiteral(path.node.id.name)
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
}));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
System.register(["@babel/core","@babel/template"],(function(m){"use strict";var r;return{setters:[null,function(o){r=o.default}],execute:(function(){m("default",u);function o(t,i,e=[]){const n=[...c,...e];if(t.isIdentifier(i)&&n.includes(i.name))return!0;if(t.isMemberExpression(i)){const{property:a}=i;if(t.isIdentifier(a)&&n.includes(a.name))return!0}return!1}const c=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],d=r.default||r;function u({types:t},i){return console.warn("[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{visitor:{ExportDefaultDeclaration(e,n){const{node:a}=e;if(t.isCallExpression(a.declaration)&&o(t,a.declaration.callee,i==null?void 0:i.customAtomNames)){const s=(n.filename||"unknown").replace(/\.\w+$/,"");let l=s.split("/").pop();l==="index"&&(l=s.slice(0,-6).split("/").pop()||"unknown");const f=d(`
|
|
2
|
+
const %%atomIdentifier%% = %%atom%%;
|
|
3
|
+
export default %%atomIdentifier%%
|
|
4
|
+
`)({atomIdentifier:t.identifier(l),atom:a.declaration});e.replaceWithMultiple(f)}},VariableDeclarator(e){t.isIdentifier(e.node.id)&&t.isCallExpression(e.node.init)&&o(t,e.node.init.callee,i==null?void 0:i.customAtomNames)&&e.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(e.node.id.name),t.identifier("debugLabel")),t.stringLiteral(e.node.id.name))))}}}}})}}));
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
System.register(['@babel/core', '@babel/template'], (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
var _templateBuilder;
|
|
4
|
+
return {
|
|
5
|
+
setters: [null, function (module) {
|
|
6
|
+
_templateBuilder = module.default;
|
|
7
|
+
}],
|
|
8
|
+
execute: (function () {
|
|
9
|
+
|
|
10
|
+
exports("default", reactRefreshPlugin);
|
|
11
|
+
|
|
12
|
+
function isAtom(t, callee, customAtomNames = []) {
|
|
13
|
+
const atomNames = [...atomFunctionNames, ...customAtomNames];
|
|
14
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (t.isMemberExpression(callee)) {
|
|
18
|
+
const { property } = callee;
|
|
19
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const atomFunctionNames = [
|
|
26
|
+
// Core
|
|
27
|
+
"atom",
|
|
28
|
+
"atomFamily",
|
|
29
|
+
"atomWithDefault",
|
|
30
|
+
"atomWithObservable",
|
|
31
|
+
"atomWithReducer",
|
|
32
|
+
"atomWithReset",
|
|
33
|
+
"atomWithStorage",
|
|
34
|
+
"freezeAtom",
|
|
35
|
+
"loadable",
|
|
36
|
+
"selectAtom",
|
|
37
|
+
"splitAtom",
|
|
38
|
+
"unwrap",
|
|
39
|
+
// jotai-xstate
|
|
40
|
+
"atomWithMachine",
|
|
41
|
+
// jotai-immer
|
|
42
|
+
"atomWithImmer",
|
|
43
|
+
// jotai-valtio
|
|
44
|
+
"atomWithProxy",
|
|
45
|
+
// jotai-trpc + jotai-relay
|
|
46
|
+
"atomWithQuery",
|
|
47
|
+
"atomWithMutation",
|
|
48
|
+
"atomWithSubscription",
|
|
49
|
+
// jotai-redux + jotai-zustand
|
|
50
|
+
"atomWithStore",
|
|
51
|
+
// jotai-location
|
|
52
|
+
"atomWithHash",
|
|
53
|
+
"atomWithLocation",
|
|
54
|
+
// jotai-optics
|
|
55
|
+
"focusAtom",
|
|
56
|
+
// jotai-form
|
|
57
|
+
"atomWithValidate",
|
|
58
|
+
"validateAtoms",
|
|
59
|
+
// jotai-cache
|
|
60
|
+
"atomWithCache",
|
|
61
|
+
// jotai-recoil
|
|
62
|
+
"atomWithRecoilValue"
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
66
|
+
function reactRefreshPlugin({ types: t }, options) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
pre({ opts }) {
|
|
72
|
+
if (!opts.filename) {
|
|
73
|
+
throw new Error("Filename must be available");
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
visitor: {
|
|
77
|
+
Program: {
|
|
78
|
+
exit(path) {
|
|
79
|
+
const jotaiAtomCache = templateBuilder(`
|
|
80
|
+
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
|
|
81
|
+
cache: new Map(),
|
|
82
|
+
get(name, inst) {
|
|
83
|
+
if (this.cache.has(name)) {
|
|
84
|
+
return this.cache.get(name)
|
|
85
|
+
}
|
|
86
|
+
this.cache.set(name, inst)
|
|
87
|
+
return inst
|
|
88
|
+
},
|
|
89
|
+
}`)();
|
|
90
|
+
path.unshiftContainer("body", jotaiAtomCache);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
ExportDefaultDeclaration(nodePath, state) {
|
|
94
|
+
const { node } = nodePath;
|
|
95
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
96
|
+
const filename = state.filename || "unknown";
|
|
97
|
+
const atomKey = `${filename}/defaultExport`;
|
|
98
|
+
const buildExport = templateBuilder(
|
|
99
|
+
`export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
|
|
100
|
+
);
|
|
101
|
+
const ast = buildExport({
|
|
102
|
+
atomKey: t.stringLiteral(atomKey),
|
|
103
|
+
atom: node.declaration
|
|
104
|
+
});
|
|
105
|
+
nodePath.replaceWith(ast);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
VariableDeclarator(nodePath, state) {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && // Make sure atom declaration is in module scope
|
|
111
|
+
(((_a = nodePath.parentPath.parentPath) == null ? void 0 : _a.isProgram()) || ((_b = nodePath.parentPath.parentPath) == null ? void 0 : _b.isExportNamedDeclaration()))) {
|
|
112
|
+
const filename = state.filename || "unknown";
|
|
113
|
+
const atomKey = `${filename}/${nodePath.node.id.name}`;
|
|
114
|
+
const buildAtomDeclaration = templateBuilder(
|
|
115
|
+
`const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
|
|
116
|
+
);
|
|
117
|
+
const ast = buildAtomDeclaration({
|
|
118
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
119
|
+
atomKey: t.stringLiteral(atomKey),
|
|
120
|
+
atom: nodePath.node.init
|
|
121
|
+
});
|
|
122
|
+
nodePath.parentPath.replaceWith(ast);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
})
|
|
130
|
+
};
|
|
131
|
+
}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
System.register(["@babel/core","@babel/template"],(function(c){"use strict";var l;return{setters:[null,function(n){l=n.default}],execute:(function(){c("default",u);function n(e,a,t=[]){const o=[...h,...t];if(e.isIdentifier(a)&&o.includes(a.name))return!0;if(e.isMemberExpression(a)){const{property:i}=a;if(e.isIdentifier(i)&&o.includes(i.name))return!0}return!1}const h=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],s=l.default||l;function u({types:e},a){return console.warn("[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{pre({opts:t}){if(!t.filename)throw new Error("Filename must be available")},visitor:{Program:{exit(t){const o=s(`
|
|
2
|
+
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
|
|
3
|
+
cache: new Map(),
|
|
4
|
+
get(name, inst) {
|
|
5
|
+
if (this.cache.has(name)) {
|
|
6
|
+
return this.cache.get(name)
|
|
7
|
+
}
|
|
8
|
+
this.cache.set(name, inst)
|
|
9
|
+
return inst
|
|
10
|
+
},
|
|
11
|
+
}`)();t.unshiftContainer("body",o)}},ExportDefaultDeclaration(t,o){const{node:i}=t;if(e.isCallExpression(i.declaration)&&n(e,i.declaration.callee,a==null?void 0:a.customAtomNames)){const r=`${o.filename||"unknown"}/defaultExport`,m=s("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomKey:e.stringLiteral(r),atom:i.declaration});t.replaceWith(m)}},VariableDeclarator(t,o){var i,r;if(e.isIdentifier(t.node.id)&&e.isCallExpression(t.node.init)&&n(e,t.node.init.callee,a==null?void 0:a.customAtomNames)&&((i=t.parentPath.parentPath)!=null&&i.isProgram()||(r=t.parentPath.parentPath)!=null&&r.isExportNamedDeclaration())){const m=`${o.filename||"unknown"}/${t.node.id.name}`,d=s("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomIdentifier:e.identifier(t.node.id.name),atomKey:e.stringLiteral(m),atom:t.node.init});t.parentPath.replaceWith(d)}}}}}})}}));
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
System.register(['@babel/core', '@babel/template'], (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
var _templateBuilder;
|
|
4
|
+
return {
|
|
5
|
+
setters: [null, function (module) {
|
|
6
|
+
_templateBuilder = module.default;
|
|
7
|
+
}],
|
|
8
|
+
execute: (function () {
|
|
9
|
+
|
|
10
|
+
exports("default", jotaiPreset);
|
|
11
|
+
|
|
12
|
+
function isAtom(t, callee, customAtomNames = []) {
|
|
13
|
+
const atomNames = [...atomFunctionNames, ...customAtomNames];
|
|
14
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (t.isMemberExpression(callee)) {
|
|
18
|
+
const { property } = callee;
|
|
19
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const atomFunctionNames = [
|
|
26
|
+
// Core
|
|
27
|
+
"atom",
|
|
28
|
+
"atomFamily",
|
|
29
|
+
"atomWithDefault",
|
|
30
|
+
"atomWithObservable",
|
|
31
|
+
"atomWithReducer",
|
|
32
|
+
"atomWithReset",
|
|
33
|
+
"atomWithStorage",
|
|
34
|
+
"freezeAtom",
|
|
35
|
+
"loadable",
|
|
36
|
+
"selectAtom",
|
|
37
|
+
"splitAtom",
|
|
38
|
+
"unwrap",
|
|
39
|
+
// jotai-xstate
|
|
40
|
+
"atomWithMachine",
|
|
41
|
+
// jotai-immer
|
|
42
|
+
"atomWithImmer",
|
|
43
|
+
// jotai-valtio
|
|
44
|
+
"atomWithProxy",
|
|
45
|
+
// jotai-trpc + jotai-relay
|
|
46
|
+
"atomWithQuery",
|
|
47
|
+
"atomWithMutation",
|
|
48
|
+
"atomWithSubscription",
|
|
49
|
+
// jotai-redux + jotai-zustand
|
|
50
|
+
"atomWithStore",
|
|
51
|
+
// jotai-location
|
|
52
|
+
"atomWithHash",
|
|
53
|
+
"atomWithLocation",
|
|
54
|
+
// jotai-optics
|
|
55
|
+
"focusAtom",
|
|
56
|
+
// jotai-form
|
|
57
|
+
"atomWithValidate",
|
|
58
|
+
"validateAtoms",
|
|
59
|
+
// jotai-cache
|
|
60
|
+
"atomWithCache",
|
|
61
|
+
// jotai-recoil
|
|
62
|
+
"atomWithRecoilValue"
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const templateBuilder$1 = _templateBuilder.default || _templateBuilder;
|
|
66
|
+
function debugLabelPlugin({ types: t }, options) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
visitor: {
|
|
72
|
+
ExportDefaultDeclaration(nodePath, state) {
|
|
73
|
+
const { node } = nodePath;
|
|
74
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
75
|
+
const filename = (state.filename || "unknown").replace(/\.\w+$/, "");
|
|
76
|
+
let displayName = filename.split("/").pop();
|
|
77
|
+
if (displayName === "index") {
|
|
78
|
+
displayName = filename.slice(0, -"/index".length).split("/").pop() || "unknown";
|
|
79
|
+
}
|
|
80
|
+
const buildExport = templateBuilder$1(`
|
|
81
|
+
const %%atomIdentifier%% = %%atom%%;
|
|
82
|
+
export default %%atomIdentifier%%
|
|
83
|
+
`);
|
|
84
|
+
const ast = buildExport({
|
|
85
|
+
atomIdentifier: t.identifier(displayName),
|
|
86
|
+
atom: node.declaration
|
|
87
|
+
});
|
|
88
|
+
nodePath.replaceWithMultiple(ast);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
VariableDeclarator(path) {
|
|
92
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
93
|
+
path.parentPath.insertAfter(
|
|
94
|
+
t.expressionStatement(
|
|
95
|
+
t.assignmentExpression(
|
|
96
|
+
"=",
|
|
97
|
+
t.memberExpression(
|
|
98
|
+
t.identifier(path.node.id.name),
|
|
99
|
+
t.identifier("debugLabel")
|
|
100
|
+
),
|
|
101
|
+
t.stringLiteral(path.node.id.name)
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
112
|
+
function reactRefreshPlugin({ types: t }, options) {
|
|
113
|
+
console.warn(
|
|
114
|
+
"[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
115
|
+
);
|
|
116
|
+
return {
|
|
117
|
+
pre({ opts }) {
|
|
118
|
+
if (!opts.filename) {
|
|
119
|
+
throw new Error("Filename must be available");
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
visitor: {
|
|
123
|
+
Program: {
|
|
124
|
+
exit(path) {
|
|
125
|
+
const jotaiAtomCache = templateBuilder(`
|
|
126
|
+
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
|
|
127
|
+
cache: new Map(),
|
|
128
|
+
get(name, inst) {
|
|
129
|
+
if (this.cache.has(name)) {
|
|
130
|
+
return this.cache.get(name)
|
|
131
|
+
}
|
|
132
|
+
this.cache.set(name, inst)
|
|
133
|
+
return inst
|
|
134
|
+
},
|
|
135
|
+
}`)();
|
|
136
|
+
path.unshiftContainer("body", jotaiAtomCache);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
ExportDefaultDeclaration(nodePath, state) {
|
|
140
|
+
const { node } = nodePath;
|
|
141
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
142
|
+
const filename = state.filename || "unknown";
|
|
143
|
+
const atomKey = `${filename}/defaultExport`;
|
|
144
|
+
const buildExport = templateBuilder(
|
|
145
|
+
`export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
|
|
146
|
+
);
|
|
147
|
+
const ast = buildExport({
|
|
148
|
+
atomKey: t.stringLiteral(atomKey),
|
|
149
|
+
atom: node.declaration
|
|
150
|
+
});
|
|
151
|
+
nodePath.replaceWith(ast);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
VariableDeclarator(nodePath, state) {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && // Make sure atom declaration is in module scope
|
|
157
|
+
(((_a = nodePath.parentPath.parentPath) == null ? void 0 : _a.isProgram()) || ((_b = nodePath.parentPath.parentPath) == null ? void 0 : _b.isExportNamedDeclaration()))) {
|
|
158
|
+
const filename = state.filename || "unknown";
|
|
159
|
+
const atomKey = `${filename}/${nodePath.node.id.name}`;
|
|
160
|
+
const buildAtomDeclaration = templateBuilder(
|
|
161
|
+
`const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
|
|
162
|
+
);
|
|
163
|
+
const ast = buildAtomDeclaration({
|
|
164
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
165
|
+
atomKey: t.stringLiteral(atomKey),
|
|
166
|
+
atom: nodePath.node.init
|
|
167
|
+
});
|
|
168
|
+
nodePath.parentPath.replaceWith(ast);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function jotaiPreset(_, options) {
|
|
176
|
+
console.warn(
|
|
177
|
+
"[DEPRECATED] jotai/babel/preset is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"
|
|
178
|
+
);
|
|
179
|
+
return {
|
|
180
|
+
plugins: [
|
|
181
|
+
[debugLabelPlugin, options],
|
|
182
|
+
[reactRefreshPlugin, options]
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
})
|
|
188
|
+
};
|
|
189
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
System.register(["@babel/core","@babel/template"],(function(d){"use strict";var s;return{setters:[null,function(l){s=l.default}],execute:(function(){d("default",b);function l(t,a,e=[]){const o=[...u,...e];if(t.isIdentifier(a)&&o.includes(a.name))return!0;if(t.isMemberExpression(a)){const{property:i}=a;if(t.isIdentifier(i)&&o.includes(i.name))return!0}return!1}const u=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],h=s.default||s;function p({types:t},a){return console.warn("[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{visitor:{ExportDefaultDeclaration(e,o){const{node:i}=e;if(t.isCallExpression(i.declaration)&&l(t,i.declaration.callee,a==null?void 0:a.customAtomNames)){const n=(o.filename||"unknown").replace(/\.\w+$/,"");let r=n.split("/").pop();r==="index"&&(r=n.slice(0,-6).split("/").pop()||"unknown");const c=h(`
|
|
2
|
+
const %%atomIdentifier%% = %%atom%%;
|
|
3
|
+
export default %%atomIdentifier%%
|
|
4
|
+
`)({atomIdentifier:t.identifier(r),atom:i.declaration});e.replaceWithMultiple(c)}},VariableDeclarator(e){t.isIdentifier(e.node.id)&&t.isCallExpression(e.node.init)&&l(t,e.node.init.callee,a==null?void 0:a.customAtomNames)&&e.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(e.node.id.name),t.identifier("debugLabel")),t.stringLiteral(e.node.id.name))))}}}}const m=s.default||s;function f({types:t},a){return console.warn("[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{pre({opts:e}){if(!e.filename)throw new Error("Filename must be available")},visitor:{Program:{exit(e){const o=m(`
|
|
5
|
+
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
|
|
6
|
+
cache: new Map(),
|
|
7
|
+
get(name, inst) {
|
|
8
|
+
if (this.cache.has(name)) {
|
|
9
|
+
return this.cache.get(name)
|
|
10
|
+
}
|
|
11
|
+
this.cache.set(name, inst)
|
|
12
|
+
return inst
|
|
13
|
+
},
|
|
14
|
+
}`)();e.unshiftContainer("body",o)}},ExportDefaultDeclaration(e,o){const{node:i}=e;if(t.isCallExpression(i.declaration)&&l(t,i.declaration.callee,a==null?void 0:a.customAtomNames)){const n=`${o.filename||"unknown"}/defaultExport`,r=m("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomKey:t.stringLiteral(n),atom:i.declaration});e.replaceWith(r)}},VariableDeclarator(e,o){var i,n;if(t.isIdentifier(e.node.id)&&t.isCallExpression(e.node.init)&&l(t,e.node.init.callee,a==null?void 0:a.customAtomNames)&&((i=e.parentPath.parentPath)!=null&&i.isProgram()||(n=e.parentPath.parentPath)!=null&&n.isExportNamedDeclaration())){const r=`${o.filename||"unknown"}/${e.node.id.name}`,c=m("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomIdentifier:t.identifier(e.node.id.name),atomKey:t.stringLiteral(r),atom:e.node.init});e.parentPath.replaceWith(c)}}}}}function b(t,a){return console.warn("[DEPRECATED] jotai/babel/preset is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{plugins:[[p,a],[f,a]]}}})}}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
System.register(['jotai/vanilla', 'jotai/react'], (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
var _starExcludes = {
|
|
4
|
+
__proto__: null,
|
|
5
|
+
default: 1
|
|
6
|
+
};
|
|
7
|
+
return {
|
|
8
|
+
setters: [function (module) {
|
|
9
|
+
var setter = { __proto__: null };
|
|
10
|
+
for (var name in module) {
|
|
11
|
+
if (!_starExcludes[name]) setter[name] = module[name];
|
|
12
|
+
}
|
|
13
|
+
exports(setter);
|
|
14
|
+
}, function (module) {
|
|
15
|
+
var setter = { __proto__: null };
|
|
16
|
+
for (var name in module) {
|
|
17
|
+
if (!_starExcludes[name]) setter[name] = module[name];
|
|
18
|
+
}
|
|
19
|
+
exports(setter);
|
|
20
|
+
}],
|
|
21
|
+
execute: (function () {
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
})
|
|
26
|
+
};
|
|
27
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
System.register(["jotai/vanilla","jotai/react"],(function(_){"use strict";var n={__proto__:null,default:1};return{setters:[function(r){var i={__proto__:null};for(var t in r)n[t]||(i[t]=r[t]);_(i)},function(r){var i={__proto__:null};for(var t in r)n[t]||(i[t]=r[t]);_(i)}],execute:(function(){})}}));
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
System.register(['react', 'jotai/react', 'jotai/vanilla/utils', 'jotai/vanilla'], (function (exports) {
|
|
3
|
+
'use strict';
|
|
4
|
+
var useCallback, useMemo, useSetAtom, useAtom, useStore, RESET, atom;
|
|
5
|
+
return {
|
|
6
|
+
setters: [function (module) {
|
|
7
|
+
useCallback = module.useCallback;
|
|
8
|
+
useMemo = module.useMemo;
|
|
9
|
+
}, function (module) {
|
|
10
|
+
useSetAtom = module.useSetAtom;
|
|
11
|
+
useAtom = module.useAtom;
|
|
12
|
+
useStore = module.useStore;
|
|
13
|
+
}, function (module) {
|
|
14
|
+
RESET = module.RESET;
|
|
15
|
+
}, function (module) {
|
|
16
|
+
atom = module.atom;
|
|
17
|
+
}],
|
|
18
|
+
execute: (function () {
|
|
19
|
+
|
|
20
|
+
exports({
|
|
21
|
+
useAtomCallback: useAtomCallback,
|
|
22
|
+
useHydrateAtoms: useHydrateAtoms,
|
|
23
|
+
useReducerAtom: useReducerAtom,
|
|
24
|
+
useResetAtom: useResetAtom
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function useResetAtom(anAtom, options) {
|
|
28
|
+
const setAtom = useSetAtom(anAtom, options);
|
|
29
|
+
const resetAtom = useCallback(() => setAtom(RESET), [setAtom]);
|
|
30
|
+
return resetAtom;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useReducerAtom(anAtom, reducer, options) {
|
|
34
|
+
{
|
|
35
|
+
console.warn(
|
|
36
|
+
"[DEPRECATED] useReducerAtom is deprecated and will be removed in the future. Please create your own version using the recipe. https://github.com/pmndrs/jotai/pull/2467"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const [state, setState] = useAtom(anAtom, options);
|
|
40
|
+
const dispatch = useCallback(
|
|
41
|
+
(action) => {
|
|
42
|
+
setState((prev) => reducer(prev, action));
|
|
43
|
+
},
|
|
44
|
+
[setState, reducer]
|
|
45
|
+
);
|
|
46
|
+
return [state, dispatch];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function useAtomCallback(callback, options) {
|
|
50
|
+
const anAtom = useMemo(
|
|
51
|
+
() => atom(null, (get, set, ...args) => callback(get, set, ...args)),
|
|
52
|
+
[callback]
|
|
53
|
+
);
|
|
54
|
+
return useSetAtom(anAtom, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const hydratedMap = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
function useHydrateAtoms(values, options) {
|
|
59
|
+
const store = useStore(options);
|
|
60
|
+
const hydratedSet = getHydratedSet(store);
|
|
61
|
+
for (const [atom, ...args] of values) {
|
|
62
|
+
if (!hydratedSet.has(atom) || (options == null ? void 0 : options.dangerouslyForceHydrate)) {
|
|
63
|
+
hydratedSet.add(atom);
|
|
64
|
+
store.set(atom, ...args);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const getHydratedSet = (store) => {
|
|
69
|
+
let hydratedSet = hydratedMap.get(store);
|
|
70
|
+
if (!hydratedSet) {
|
|
71
|
+
hydratedSet = /* @__PURE__ */ new WeakSet();
|
|
72
|
+
hydratedMap.set(store, hydratedSet);
|
|
73
|
+
}
|
|
74
|
+
return hydratedSet;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
}));
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
System.register(["react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],(function(d){"use strict";var r,i,c,l,m,f,A;return{setters:[function(e){r=e.useCallback,i=e.useMemo},function(e){c=e.useSetAtom,l=e.useAtom,m=e.useStore},function(e){f=e.RESET},function(e){A=e.atom}],execute:(function(){d({useAtomCallback:R,useHydrateAtoms:y,useReducerAtom:k,useResetAtom:e});function e(n,t){const s=c(n,t);return r(()=>s(f),[s])}function k(n,t,s){const[u,o]=l(n,s),a=r(C=>{o(E=>t(E,C))},[o,t]);return[u,a]}function R(n,t){const s=i(()=>A(null,(u,o,...a)=>n(u,o,...a)),[n]);return c(s,t)}const S=new WeakMap;function y(n,t){const s=m(t),u=b(s);for(const[o,...a]of n)(!u.has(o)||t!=null&&t.dangerouslyForceHydrate)&&(u.add(o),s.set(o,...a))}const b=n=>{let t=S.get(n);return t||(t=new WeakSet,S.set(n,t)),t}})}}));
|