atomaric 0.0.35 → 0.0.37
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/build/atomaric.js +102 -99
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +4 -3
- package/types/paths.ts +67 -12
package/build/atomaric.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
let M = () => {
|
|
2
|
+
throw "call configureAtomaric() before all!";
|
|
3
|
+
};
|
|
4
|
+
const $ = {}, v = (e) => {
|
|
5
|
+
$.useSyncExternalStore = M = e.useSyncExternalStore, $.keyPathSeparator = e.keyPathSeparator;
|
|
6
|
+
}, B = (e) => M(e.subscribe, e.get), G = (e) => e.set, K = (e) => e.setDeferred, O = (e) => e.get, ee = (e) => e.do, te = (e) => [B(e), G(e)], se = (e, r) => new q(e, r), U = (e, r, i) => {
|
|
7
|
+
let h = null;
|
|
8
|
+
typeof e == "number" ? h = j(
|
|
4
9
|
r,
|
|
5
10
|
(s) => ({
|
|
6
11
|
increment: (n) => {
|
|
7
12
|
s.set(+s.get() + (n ?? 0));
|
|
8
13
|
}
|
|
9
14
|
})
|
|
10
|
-
) : typeof e == "boolean" ?
|
|
15
|
+
) : typeof e == "boolean" ? h = j(
|
|
11
16
|
r,
|
|
12
17
|
(s) => ({
|
|
13
18
|
toggle: () => {
|
|
14
19
|
s.set(!s.get());
|
|
15
20
|
}
|
|
16
21
|
})
|
|
17
|
-
) : Array.isArray(e) ?
|
|
22
|
+
) : Array.isArray(e) ? h = j(
|
|
18
23
|
r,
|
|
19
24
|
(s) => ({
|
|
20
25
|
push: (...n) => {
|
|
@@ -28,14 +33,14 @@ const B = (e, r, i) => {
|
|
|
28
33
|
n(c), s.set(c);
|
|
29
34
|
},
|
|
30
35
|
filter: (n) => {
|
|
31
|
-
s.set(s.get().filter(n ??
|
|
36
|
+
s.set(s.get().filter(n ?? W));
|
|
32
37
|
},
|
|
33
38
|
toggle: (n, c) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
39
|
+
const p = s.get().slice(), a = p.indexOf(n);
|
|
40
|
+
a < 0 ? c ? p.unshift(n) : p.push(n) : p.splice(a, 1), s.set(p);
|
|
36
41
|
}
|
|
37
42
|
})
|
|
38
|
-
) : e instanceof Set ?
|
|
43
|
+
) : e instanceof Set ? h = j(
|
|
39
44
|
r,
|
|
40
45
|
(s) => ({
|
|
41
46
|
add: (n) => {
|
|
@@ -57,7 +62,7 @@ const B = (e, r, i) => {
|
|
|
57
62
|
n(c), s.set(c);
|
|
58
63
|
}
|
|
59
64
|
})
|
|
60
|
-
) : e instanceof Object && (
|
|
65
|
+
) : e instanceof Object && (h = j(
|
|
61
66
|
r,
|
|
62
67
|
(s) => ({
|
|
63
68
|
setPartial: (n) => s.set((c) => ({
|
|
@@ -68,167 +73,165 @@ const B = (e, r, i) => {
|
|
|
68
73
|
const c = { ...s.get() };
|
|
69
74
|
n(c), s.set(c);
|
|
70
75
|
},
|
|
71
|
-
setDeepPartial: (n, c,
|
|
72
|
-
if (n.includes(
|
|
73
|
-
let
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
let
|
|
78
|
-
for (const
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
setDeepPartial: (n, c, p, a = $.keyPathSeparator ?? ".") => {
|
|
77
|
+
if (n.includes(a)) {
|
|
78
|
+
let d = n.split(a);
|
|
79
|
+
const T = d[d.length - 1];
|
|
80
|
+
d = d.slice(0, -1);
|
|
81
|
+
const b = { ...s.get() };
|
|
82
|
+
let g = b, x = p;
|
|
83
|
+
for (const w of d) {
|
|
84
|
+
let f = g[w];
|
|
85
|
+
const _ = x = x == null ? void 0 : x[Array.isArray(x) ? "0" : w];
|
|
86
|
+
if (f == null && (f = Array.isArray(_) ? [] : {}), f == null || typeof f != "object") {
|
|
81
87
|
s.do.setPartial({ [n]: typeof c == "function" ? c(void 0) : c });
|
|
82
88
|
return;
|
|
83
89
|
}
|
|
84
|
-
|
|
90
|
+
g = g[w] = Array.isArray(f) ? [...f] : { ...f };
|
|
85
91
|
}
|
|
86
|
-
|
|
92
|
+
g[T] = typeof c == "function" ? c(g[T]) : c, s.set(b);
|
|
87
93
|
} else s.do.setPartial({ [n]: c });
|
|
88
94
|
}
|
|
89
95
|
})
|
|
90
96
|
));
|
|
91
|
-
const
|
|
97
|
+
const S = typeof i == "object" && i != null && "do" in i ? i.do(
|
|
92
98
|
(s, n) => r.set(s, n),
|
|
93
99
|
() => r.get(),
|
|
94
100
|
r,
|
|
95
101
|
(s, n, c) => r.setDeferred(s, n, c)
|
|
96
|
-
) : null,
|
|
97
|
-
return
|
|
98
|
-
(s) => Object.defineProperty(
|
|
99
|
-
),
|
|
100
|
-
},
|
|
101
|
-
class
|
|
102
|
+
) : null, A = {};
|
|
103
|
+
return S && Object.keys(S).forEach((s) => Object.defineProperty(A, s, { get: () => S[s] })), h && Object.keys(h).forEach(
|
|
104
|
+
(s) => Object.defineProperty(A, s, { get: () => h[s] })
|
|
105
|
+
), A;
|
|
106
|
+
}, W = (e) => e, j = (e, r, i) => r(e);
|
|
107
|
+
class q {
|
|
102
108
|
constructor(r, i) {
|
|
103
|
-
const
|
|
104
|
-
let n = r, c,
|
|
105
|
-
},
|
|
106
|
-
const t =
|
|
107
|
-
return
|
|
109
|
+
const h = (t) => n = t, S = () => n, A = /* @__PURE__ */ new Set(), s = (t) => t(a());
|
|
110
|
+
let n = r, c, p = () => {
|
|
111
|
+
}, a = () => S(), d = null, T = () => {
|
|
112
|
+
const t = U(r, b, i);
|
|
113
|
+
return T = () => t, t;
|
|
108
114
|
};
|
|
109
|
-
const
|
|
110
|
-
get: (t, u) => u === "do" ?
|
|
111
|
-
set:
|
|
112
|
-
}),
|
|
113
|
-
const
|
|
114
|
-
if (!(
|
|
115
|
-
|
|
115
|
+
const b = new Proxy(this, {
|
|
116
|
+
get: (t, u) => u === "do" ? T() : t[u],
|
|
117
|
+
set: Q
|
|
118
|
+
}), g = (t, u) => {
|
|
119
|
+
const y = typeof t == "function" ? t(a()) : t;
|
|
120
|
+
if (!(y === a() || y === void 0 || typeof y == "number" && isNaN(y))) {
|
|
121
|
+
h(y), A.forEach(s, this);
|
|
116
122
|
try {
|
|
117
|
-
|
|
123
|
+
N.postMessage({ key: l, value: S() });
|
|
118
124
|
} catch {
|
|
119
125
|
}
|
|
120
|
-
u !== !0 &&
|
|
126
|
+
u !== !0 && p(y);
|
|
121
127
|
}
|
|
122
128
|
};
|
|
123
|
-
this.set = (t, u) =>
|
|
124
|
-
|
|
129
|
+
this.set = (t, u) => g(t, u), this.get = () => a(), this.initialValue = r, this.isInitialValue = () => r === S(), this.subscribe = (t) => (A.add(t), () => {
|
|
130
|
+
A.delete(t);
|
|
125
131
|
}), this.reset = () => {
|
|
126
|
-
|
|
132
|
+
g(r, !0), A.forEach(s, this);
|
|
127
133
|
};
|
|
128
|
-
const
|
|
129
|
-
|
|
134
|
+
const x = (t, u) => {
|
|
135
|
+
g(t, u), c = void 0;
|
|
130
136
|
};
|
|
131
|
-
if (this.setDeferred = (t, u = 500,
|
|
132
|
-
|
|
133
|
-
}, i == null) return
|
|
134
|
-
let
|
|
137
|
+
if (this.setDeferred = (t, u = 500, y, L = !0) => {
|
|
138
|
+
L && c === void 0 && g(t, y), clearTimeout(c), c = setTimeout(x, u, t, y);
|
|
139
|
+
}, i == null) return b;
|
|
140
|
+
let w = null, f = null, _ = !0, E = !0, P = !1, V = -1, C = r instanceof Set ? (t) => new Set(t) : (t) => t, m = r instanceof Set ? (t) => {
|
|
135
141
|
if (t instanceof Set) return Array.from(t);
|
|
136
142
|
throw console.error(t), "The value is not Set instance";
|
|
137
143
|
} : (t) => t;
|
|
138
144
|
if (typeof i == "string")
|
|
139
|
-
|
|
145
|
+
w = i;
|
|
140
146
|
else if ("storeKey" in i)
|
|
141
|
-
|
|
142
|
-
else return
|
|
143
|
-
const l = `${
|
|
147
|
+
_ = i.warnOnDuplicateStoreKey ?? _, E = i.listenStorageChanges ?? E, w = i.storeKey, C = i.unzipValue ?? C, m = i.zipValue ?? m, P = i.unchangable ?? P, f = i.exp ?? f;
|
|
148
|
+
else return b;
|
|
149
|
+
const l = `${R}${w}`, F = f === null || !(f(b, l in o) instanceof Date) ? (t) => JSON.stringify([m(t)]) : (t) => (d ?? (d = {}), d.exp = f(b, l in o).getTime() + 0.2866, d.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(V), clearTimeout(k[l]), V = setTimeout(() => this.reset(), d.exp - Date.now())), JSON.stringify([m(t), d])), J = (t) => {
|
|
144
150
|
const u = JSON.parse(t);
|
|
145
|
-
return
|
|
151
|
+
return d = u[1], C(u[0]);
|
|
146
152
|
};
|
|
147
|
-
let
|
|
148
|
-
if (
|
|
149
|
-
if (
|
|
150
|
-
|
|
153
|
+
let H = !0;
|
|
154
|
+
if (z[l] = b, o[`atom/${w}`] && (o[l] || (o[l] = `[${o[`atom/${w}`]}]`), delete o[`atom/${w}`]), a = () => {
|
|
155
|
+
if (a = S, H) {
|
|
156
|
+
H = !1;
|
|
151
157
|
try {
|
|
152
|
-
|
|
158
|
+
h(l in o ? J(o[l]) : r);
|
|
153
159
|
} catch {
|
|
154
160
|
console.warn("Invalid json value", o[l]);
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
|
-
return
|
|
158
|
-
},
|
|
163
|
+
return S();
|
|
164
|
+
}, p = (t) => {
|
|
159
165
|
if (t === r) {
|
|
160
166
|
this.reset();
|
|
161
167
|
return;
|
|
162
168
|
}
|
|
163
|
-
o[l] =
|
|
169
|
+
o[l] = F(t);
|
|
164
170
|
}, this.reset = () => {
|
|
165
|
-
delete o[l],
|
|
166
|
-
},
|
|
167
|
-
if (
|
|
171
|
+
delete o[l], g(r, !0);
|
|
172
|
+
}, _ && D[l] !== void 0 && console.warn("Duplicate Atom key", w), E)
|
|
173
|
+
if (P) {
|
|
168
174
|
let t = !1, u;
|
|
169
|
-
|
|
170
|
-
clearTimeout(u), u = setTimeout(() => t = !1, 10), !t && (t = !0, o[l] =
|
|
175
|
+
I[l] = this, D[l] = () => {
|
|
176
|
+
clearTimeout(u), u = setTimeout(() => t = !1, 10), !t && (t = !0, o[l] = F(S()));
|
|
171
177
|
};
|
|
172
178
|
} else
|
|
173
|
-
|
|
179
|
+
D[l] = (t) => {
|
|
174
180
|
if (t.newValue === null) {
|
|
175
181
|
this.reset();
|
|
176
182
|
return;
|
|
177
183
|
}
|
|
178
184
|
try {
|
|
179
|
-
|
|
185
|
+
g(J(t.newValue));
|
|
180
186
|
} catch {
|
|
181
187
|
console.warn("Invalid json value", t.newValue);
|
|
182
188
|
}
|
|
183
189
|
};
|
|
184
|
-
return
|
|
190
|
+
return b;
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
|
-
let
|
|
193
|
+
let N;
|
|
188
194
|
try {
|
|
189
|
-
|
|
195
|
+
N = new BroadcastChannel("updateHere"), N.addEventListener("message", (e) => {
|
|
190
196
|
var r;
|
|
191
|
-
(r =
|
|
197
|
+
(r = I[e.data.key]) == null || r.set(e.data.value, !0);
|
|
192
198
|
});
|
|
193
199
|
} catch {
|
|
194
200
|
}
|
|
195
|
-
const o = window.localStorage,
|
|
201
|
+
const o = window.localStorage, D = {}, I = {}, Q = (e, r) => {
|
|
196
202
|
throw `${r} is readonly property`;
|
|
197
203
|
};
|
|
198
204
|
window.addEventListener("storage", (e) => {
|
|
199
205
|
var r;
|
|
200
|
-
e.key === null || e.newValue === e.oldValue || (r =
|
|
206
|
+
e.key === null || e.newValue === e.oldValue || (r = D[e.key]) == null || r.call(D, e);
|
|
201
207
|
});
|
|
202
|
-
const
|
|
208
|
+
const X = o.setItem.bind(o), Y = o.removeItem.bind(o);
|
|
203
209
|
o.setItem = (e, r) => {
|
|
204
|
-
|
|
210
|
+
I[e] === void 0 && X.call(o, e, r);
|
|
205
211
|
};
|
|
206
212
|
o.removeItem = (e) => {
|
|
207
|
-
|
|
213
|
+
I[e] === void 0 && Y.call(o, e);
|
|
208
214
|
};
|
|
209
|
-
const
|
|
215
|
+
const Z = /"exp":(\d+)\.2866/, R = "atom\\", z = {}, k = {};
|
|
210
216
|
setTimeout(() => {
|
|
211
217
|
Object.keys(o).forEach((e) => {
|
|
212
218
|
var i;
|
|
213
|
-
if (!e.startsWith(
|
|
214
|
-
const r = +((i = o[e].match(
|
|
215
|
-
r && r - Date.now() < 24 * 60 * 60 * 1e3 && (
|
|
216
|
-
|
|
219
|
+
if (!e.startsWith(R) || typeof o[e] != "string") return;
|
|
220
|
+
const r = +((i = o[e].match(Z)) == null ? void 0 : i[1]);
|
|
221
|
+
r && r - Date.now() < 24 * 60 * 60 * 1e3 && (k[e] = setTimeout(() => {
|
|
222
|
+
z[e] ? z[e].reset() : delete o[e];
|
|
217
223
|
}, r - Date.now()));
|
|
218
224
|
});
|
|
219
225
|
}, 1e3);
|
|
220
|
-
let R = () => {
|
|
221
|
-
throw "call configureAtomaric() before all!";
|
|
222
|
-
};
|
|
223
|
-
const k = (e) => R = e.useSyncExternalStore, Y = (e) => R(e.subscribe, e.get), Z = (e) => e.set, v = (e) => e.setDeferred, K = (e) => e.get, O = (e) => e.do, ee = (e) => [Y(e), Z(e)], te = (e, r) => new U(e, r);
|
|
224
226
|
export {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
227
|
+
q as Atom,
|
|
228
|
+
se as atom,
|
|
229
|
+
v as configureAtomaric,
|
|
230
|
+
$ as configuredOptions,
|
|
231
|
+
te as useAtom,
|
|
232
|
+
ee as useAtomDo,
|
|
233
|
+
O as useAtomGet,
|
|
234
|
+
G as useAtomSet,
|
|
235
|
+
K as useAtomSetDeferred,
|
|
236
|
+
B as useAtomValue
|
|
234
237
|
};
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(f,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(f=typeof globalThis<"u"?globalThis:f||self,D(f.atomaric={}))})(this,function(f){"use strict";let D=()=>{throw"call configureAtomaric() before all!"};const P={},q=e=>{P.useSyncExternalStore=D=e.useSyncExternalStore,P.keyPathSeparator=e.keyPathSeparator},J=e=>D(e.subscribe,e.get),M=e=>e.set,Q=e=>e.setDeferred,X=e=>e.get,Y=e=>e.do,Z=e=>[J(e),M(e)],v=(e,r)=>new G(e,r),K=(e,r,i)=>{let S=null;typeof e=="number"?S=_(r,n=>({increment:s=>{n.set(+n.get()+(s??0))}})):typeof e=="boolean"?S=_(r,n=>({toggle:()=>{n.set(!n.get())}})):Array.isArray(e)?S=_(r,n=>({push:(...s)=>{n.set(n.get().concat(s))},unshift:(...s)=>{n.set(s.concat(n.get()))},update:s=>{const c=n.get().slice();s(c),n.set(c)},filter:s=>{n.set(n.get().filter(s??O))},toggle:(s,c)=>{const y=n.get().slice(),d=y.indexOf(s);d<0?c?y.unshift(s):y.push(s):y.splice(d,1),n.set(y)}})):e instanceof Set?S=_(r,n=>({add:s=>{n.set(new Set(n.get()).add(s))},delete:s=>{const c=new Set(n.get());c.delete(s),n.set(c)},toggle:s=>{const c=new Set(n.get());c.has(s)?c.delete(s):c.add(s),n.set(c)},clear:()=>{n.set(new Set)},update:s=>{const c=new Set(n.get());s(c),n.set(c)}})):e instanceof Object&&(S=_(r,n=>({setPartial:s=>n.set(c=>({...c,...typeof s=="function"?s(n.get()):s})),update:s=>{const c={...n.get()};s(c),n.set(c)},setDeepPartial:(s,c,y,d=P.keyPathSeparator??".")=>{if(s.includes(d)){let g=s.split(d);const I=g[g.length-1];g=g.slice(0,-1);const b={...n.get()};let h=b,T=y;for(const w of g){let a=h[w];const E=T=T==null?void 0:T[Array.isArray(T)?"0":w];if(a==null&&(a=Array.isArray(E)?[]:{}),a==null||typeof a!="object"){n.do.setPartial({[s]:typeof c=="function"?c(void 0):c});return}h=h[w]=Array.isArray(a)?[...a]:{...a}}h[I]=typeof c=="function"?c(h[I]):c,n.set(b)}else n.do.setPartial({[s]:c})}})));const A=typeof i=="object"&&i!=null&&"do"in i?i.do((n,s)=>r.set(n,s),()=>r.get(),r,(n,s,c)=>r.setDeferred(n,s,c)):null,m={};return A&&Object.keys(A).forEach(n=>Object.defineProperty(m,n,{get:()=>A[n]})),S&&Object.keys(S).forEach(n=>Object.defineProperty(m,n,{get:()=>S[n]})),m},O=e=>e,_=(e,r,i)=>r(e);class G{constructor(r,i){const S=t=>s=t,A=()=>s,m=new Set,n=t=>t(d());let s=r,c,y=()=>{},d=()=>A(),g=null,I=()=>{const t=K(r,b,i);return I=()=>t,t};const b=new Proxy(this,{get:(t,u)=>u==="do"?I():t[u],set:ee}),h=(t,u)=>{const p=typeof t=="function"?t(d()):t;if(!(p===d()||p===void 0||typeof p=="number"&&isNaN(p))){S(p),m.forEach(n,this);try{$.postMessage({key:l,value:A()})}catch{}u!==!0&&y(p)}};this.set=(t,u)=>h(t,u),this.get=()=>d(),this.initialValue=r,this.isInitialValue=()=>r===A(),this.subscribe=t=>(m.add(t),()=>{m.delete(t)}),this.reset=()=>{h(r,!0),m.forEach(n,this)};const T=(t,u)=>{h(t,u),c=void 0};if(this.setDeferred=(t,u=500,p,W=!0)=>{W&&c===void 0&&h(t,p),clearTimeout(c),c=setTimeout(T,u,t,p)},i==null)return b;let w=null,a=null,E=!0,V=!0,z=!1,R=-1,F=r instanceof Set?t=>new Set(t):t=>t,C=r instanceof Set?t=>{if(t instanceof Set)return Array.from(t);throw console.error(t),"The value is not Set instance"}:t=>t;if(typeof i=="string")w=i;else if("storeKey"in i)E=i.warnOnDuplicateStoreKey??E,V=i.listenStorageChanges??V,w=i.storeKey,F=i.unzipValue??F,C=i.zipValue??C,z=i.unchangable??z,a=i.exp??a;else return b;const l=`${H}${w}`,k=a===null||!(a(b,l in o)instanceof Date)?t=>JSON.stringify([C(t)]):t=>(g??(g={}),g.exp=a(b,l in o).getTime()+.2866,g.exp-Date.now()<24*60*60*1e3&&(clearTimeout(R),clearTimeout(L[l]),R=setTimeout(()=>this.reset(),g.exp-Date.now())),JSON.stringify([C(t),g])),B=t=>{const u=JSON.parse(t);return g=u[1],F(u[0])};let U=!0;if(N[l]=b,o[`atom/${w}`]&&(o[l]||(o[l]=`[${o[`atom/${w}`]}]`),delete o[`atom/${w}`]),d=()=>{if(d=A,U){U=!1;try{S(l in o?B(o[l]):r)}catch{console.warn("Invalid json value",o[l])}}return A()},y=t=>{if(t===r){this.reset();return}o[l]=k(t)},this.reset=()=>{delete o[l],h(r,!0)},E&&j[l]!==void 0&&console.warn("Duplicate Atom key",w),V)if(z){let t=!1,u;x[l]=this,j[l]=()=>{clearTimeout(u),u=setTimeout(()=>t=!1,10),!t&&(t=!0,o[l]=k(A()))}}else j[l]=t=>{if(t.newValue===null){this.reset();return}try{h(B(t.newValue))}catch{console.warn("Invalid json value",t.newValue)}};return b}}let $;try{$=new BroadcastChannel("updateHere"),$.addEventListener("message",e=>{var r;(r=x[e.data.key])==null||r.set(e.data.value,!0)})}catch{}const o=window.localStorage,j={},x={},ee=(e,r)=>{throw`${r} is readonly property`};window.addEventListener("storage",e=>{var r;e.key===null||e.newValue===e.oldValue||(r=j[e.key])==null||r.call(j,e)});const te=o.setItem.bind(o),ne=o.removeItem.bind(o);o.setItem=(e,r)=>{x[e]===void 0&&te.call(o,e,r)},o.removeItem=e=>{x[e]===void 0&&ne.call(o,e)};const se=/"exp":(\d+)\.2866/,H="atom\\",N={},L={};setTimeout(()=>{Object.keys(o).forEach(e=>{var i;if(!e.startsWith(H)||typeof o[e]!="string")return;const r=+((i=o[e].match(se))==null?void 0:i[1]);r&&r-Date.now()<24*60*60*1e3&&(L[e]=setTimeout(()=>{N[e]?N[e].reset():delete o[e]},r-Date.now()))})},1e3),f.Atom=G,f.atom=v,f.configureAtomaric=q,f.configuredOptions=P,f.useAtom=Z,f.useAtomDo=Y,f.useAtomGet=X,f.useAtomSet=M,f.useAtomSetDeferred=Q,f.useAtomValue=J,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
|
-
import { Path,
|
|
2
|
+
import { Path, PathValue, PathValueDonor } from './paths';
|
|
3
3
|
|
|
4
4
|
export interface Register {}
|
|
5
5
|
|
|
@@ -68,11 +68,12 @@ export type ObjectActions<Value> = UpdateAction<Value> & {
|
|
|
68
68
|
/** pass partial value to update some deep values by flat path */
|
|
69
69
|
setDeepPartial: <
|
|
70
70
|
ValuePath extends Path<Value, Sep>,
|
|
71
|
-
Val extends
|
|
71
|
+
Val extends PathValue<Value, Sep, ValuePath>,
|
|
72
72
|
Sep extends string = ObjectActionsSetDeepPartial,
|
|
73
73
|
>(
|
|
74
74
|
path: ValuePath,
|
|
75
|
-
value:
|
|
75
|
+
value: Val | ((value: Val) => Val),
|
|
76
|
+
donor: PathValueDonor<Value, Sep, ValuePath> | null,
|
|
76
77
|
separator?: Sep,
|
|
77
78
|
) => void;
|
|
78
79
|
};
|
package/types/paths.ts
CHANGED
|
@@ -30,18 +30,6 @@ type PathImpl<K extends string | number, Sep extends string, V, TraversedTypes>
|
|
|
30
30
|
? `${K}`
|
|
31
31
|
: `${K}` | `${K}${Sep}${PathInternal<V, Sep, TraversedTypes | V>}`;
|
|
32
32
|
|
|
33
|
-
type ArrayKey = number;
|
|
34
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
35
|
-
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
36
|
-
type BrowserNativeObject = Date | FileList | File;
|
|
37
|
-
|
|
38
|
-
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
39
|
-
type IsEqual<T1, T2> = T1 extends T2
|
|
40
|
-
? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2
|
|
41
|
-
? true
|
|
42
|
-
: false
|
|
43
|
-
: false;
|
|
44
|
-
|
|
45
33
|
////////////////////////////////////////////////////////////////////////////
|
|
46
34
|
////////////////////////////////////////////////////////////////////////////
|
|
47
35
|
////////////////////////////////////////////////////////////////////////////
|
|
@@ -76,6 +64,73 @@ type TPathValue<T, Sep extends string, P extends Path<T, Sep> | ArrayPath<T, Sep
|
|
|
76
64
|
: never
|
|
77
65
|
: never;
|
|
78
66
|
|
|
67
|
+
////////////////////////////////////////////////////////////////////////////
|
|
68
|
+
////////////////////////////////////////////////////////////////////////////
|
|
69
|
+
////////////////////////////////////////////////////////////////////////////
|
|
70
|
+
////////////////////////////////////////////////////////////////////////////
|
|
71
|
+
////////////////////////////////////////////////////////////////////////////
|
|
72
|
+
////////////////////////////////////////////////////////////////////////////
|
|
73
|
+
////////////////////////////////////////////////////////////////////////////
|
|
74
|
+
////////////////////////////////////////////////////////////////////////////
|
|
75
|
+
////////////////////////////////////////////////////////////////////////////
|
|
76
|
+
////////////////////////////////////////////////////////////////////////////
|
|
77
|
+
////////////////////////////////////////////////////////////////////////////
|
|
78
|
+
////////////////////////////////////////////////////////////////////////////
|
|
79
|
+
////////////////////////////////////////////////////////////////////////////
|
|
80
|
+
|
|
81
|
+
export type PathValueDonor<
|
|
82
|
+
Value,
|
|
83
|
+
Sep extends string,
|
|
84
|
+
FullPath extends Path<Value, Sep> | ArrayPath<Value, Sep>,
|
|
85
|
+
> = Value extends any
|
|
86
|
+
? FullPath extends `${infer Key}${Sep}${infer KeyRest}`
|
|
87
|
+
? Key extends keyof Value
|
|
88
|
+
? KeyRest extends Path<Value[Key], Sep>
|
|
89
|
+
? Required<Record<Key, PathValueDonor<Value[Key], Sep, KeyRest>>>
|
|
90
|
+
: never
|
|
91
|
+
: Key extends `${ArrayKey}`
|
|
92
|
+
? Value extends ReadonlyArray<infer V>
|
|
93
|
+
? [PathValueDonor<V, Sep, KeyRest & Path<V, Sep>>]
|
|
94
|
+
: never
|
|
95
|
+
: never
|
|
96
|
+
: FullPath extends keyof Value
|
|
97
|
+
? FullPath extends `${string}${Sep}${string}${string}`
|
|
98
|
+
? Required<Record<FullPath, Value[FullPath]>>
|
|
99
|
+
: Partial<Record<string, unknown>>
|
|
100
|
+
: FullPath extends `${ArrayKey}`
|
|
101
|
+
? Value extends ReadonlyArray<infer V>
|
|
102
|
+
? FullPath extends `${string}${Sep}${string}${string}`
|
|
103
|
+
? [V]
|
|
104
|
+
: []
|
|
105
|
+
: never
|
|
106
|
+
: never
|
|
107
|
+
: never;
|
|
108
|
+
|
|
109
|
+
/////////////////////////////////////////////////////////
|
|
110
|
+
/////////////////////////////////////////////////////////
|
|
111
|
+
/////////////////////////////////////////////////////////
|
|
112
|
+
/////////////////////////////////////////////////////////
|
|
113
|
+
/////////////////////////////////////////////////////////
|
|
114
|
+
/////////////////////////////////////////////////////////
|
|
115
|
+
/////////////////////////////////////////////////////////
|
|
116
|
+
/////////////////////////////////////////////////////////
|
|
117
|
+
/////////////////////////////////////////////////////////
|
|
118
|
+
/////////////////////////////////////////////////////////
|
|
119
|
+
/////////////////////////////////////////////////////////
|
|
120
|
+
/////////////////////////////////////////////////////////
|
|
121
|
+
|
|
122
|
+
type ArrayKey = number;
|
|
123
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
124
|
+
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
125
|
+
type BrowserNativeObject = Date | FileList | File;
|
|
126
|
+
|
|
127
|
+
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
128
|
+
type IsEqual<T1, T2> = T1 extends T2
|
|
129
|
+
? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2
|
|
130
|
+
? true
|
|
131
|
+
: false
|
|
132
|
+
: false;
|
|
133
|
+
|
|
79
134
|
type ArrayPath<T, Sep extends string> = T extends any ? ArrayPathInternal<T, Sep> : never;
|
|
80
135
|
|
|
81
136
|
type ArrayPathInternal<T, Sep extends string, TraversedTypes = T> = T extends ReadonlyArray<infer V>
|