atomaric 0.0.74 → 0.0.76
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 +39 -39
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +6 -3
- package/src/do.classes/Array.ts +2 -1
- package/src/do.classes/Boolean.ts +1 -1
- package/src/do.classes/Map.ts +2 -1
- package/src/do.classes/Number.ts +1 -1
- package/src/do.classes/Object.ts +1 -1
- package/src/do.classes/Set.ts +1 -1
- package/src/do.classes/_Basic.ts +1 -1
- package/types/index.d.ts +8 -6
- package/types/paths.ts +1 -0
package/build/atomaric.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
let k = () => {
|
|
2
2
|
throw "call configureAtomaric() before all!";
|
|
3
3
|
};
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
}, ne = (t) => k(t.subscribe, t.get), ie = (t) => t.set, xe = (t) => t.setDeferred, be = (t) => t.get, De = (t) => t.do, $e = (t) => [ne(t), ie(t)],
|
|
7
|
-
class
|
|
4
|
+
const _ = {}, Se = (t) => {
|
|
5
|
+
_.useSyncExternalStore = k = t.useSyncExternalStore, _.keyPathSeparator = t.keyPathSeparator, _.securifyKeyLevel = t.securifyKeyLevel, _.securifyValueLevel = t.securifyValueLevel;
|
|
6
|
+
}, ne = (t) => k(t.subscribe, t.get), ie = (t) => t.set, xe = (t) => t.setDeferred, be = (t) => t.get, De = (t) => t.do, $e = (t) => [ne(t), ie(t)], _e = (t, e) => new pe(t, e);
|
|
7
|
+
class V {
|
|
8
8
|
constructor(e) {
|
|
9
9
|
if (e)
|
|
10
10
|
return new Proxy(this, {
|
|
@@ -26,7 +26,7 @@ const ce = (t, e) => {
|
|
|
26
26
|
});
|
|
27
27
|
return i(t, [], 0);
|
|
28
28
|
};
|
|
29
|
-
class O extends
|
|
29
|
+
class O extends V {
|
|
30
30
|
constructor() {
|
|
31
31
|
super(...arguments), this.updateValue = (e, i) => {
|
|
32
32
|
const s = Array.isArray(e) ? e.slice(0) : { ...e };
|
|
@@ -73,14 +73,14 @@ class oe extends O {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
const ae = (t) => t;
|
|
76
|
-
class ue extends
|
|
76
|
+
class ue extends V {
|
|
77
77
|
constructor(e, i) {
|
|
78
78
|
super(i), this.a = e, this.toggle = () => {
|
|
79
79
|
this.a.set(!this.a.get());
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
class le extends
|
|
83
|
+
class le extends V {
|
|
84
84
|
constructor(e, i) {
|
|
85
85
|
super(i), this.a = e, this.setValue = (s, n) => {
|
|
86
86
|
if (this.a.get().get(s) === n) return;
|
|
@@ -102,7 +102,7 @@ class le extends _ {
|
|
|
102
102
|
}, this.a = e;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
class fe extends
|
|
105
|
+
class fe extends V {
|
|
106
106
|
constructor(e, i) {
|
|
107
107
|
super(i), this.a = e, this.increment = (s) => {
|
|
108
108
|
this.a.set(+this.a.get() + (s ?? 1));
|
|
@@ -117,7 +117,7 @@ class he extends O {
|
|
|
117
117
|
})), this.update = (s) => {
|
|
118
118
|
const n = this.a.get(), c = this.updateValue(n, s);
|
|
119
119
|
c !== n && this.a.set(c);
|
|
120
|
-
}, this.setDeepPartial = (s, n, c, l =
|
|
120
|
+
}, this.setDeepPartial = (s, n, c, l = _.keyPathSeparator || ".") => {
|
|
121
121
|
if (!l) return;
|
|
122
122
|
if (s.includes(l)) {
|
|
123
123
|
let g = s.split(l);
|
|
@@ -146,7 +146,7 @@ class he extends O {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
const v = (t, e) => Array.isArray(t) ? `${+e}` : e;
|
|
149
|
-
class de extends
|
|
149
|
+
class de extends V {
|
|
150
150
|
constructor(e, i) {
|
|
151
151
|
super(i), this.a = e, this.add = (s) => {
|
|
152
152
|
this.a.get().has(s) || this.a.set(new Set(this.a.get()).add(s));
|
|
@@ -169,7 +169,7 @@ const ge = (t, e, i) => {
|
|
|
169
169
|
e,
|
|
170
170
|
(c, l, h) => e.setDeferred(c, l, h)
|
|
171
171
|
) : null, n = {};
|
|
172
|
-
return s && Object.keys(s).forEach((c) => Object.defineProperty(n, c, { get: () => s[c] })), typeof t == "number" ? new fe(e, s) : typeof t == "boolean" ? new ue(e, s) : Array.isArray(t) ? new oe(e, s) : t instanceof Set ? new de(e, s) : t instanceof Map ? new le(e, s) : t instanceof Object ? new he(e, s) : new
|
|
172
|
+
return s && Object.keys(s).forEach((c) => Object.defineProperty(n, c, { get: () => s[c] })), typeof t == "number" ? new fe(e, s) : typeof t == "boolean" ? new ue(e, s) : Array.isArray(t) ? new oe(e, s) : t instanceof Set ? new de(e, s) : t instanceof Map ? new le(e, s) : t instanceof Object ? new he(e, s) : new V(s);
|
|
173
173
|
};
|
|
174
174
|
class pe {
|
|
175
175
|
constructor(e, i) {
|
|
@@ -204,7 +204,7 @@ class pe {
|
|
|
204
204
|
if (this.setDeferred = (r, u = 500, x, b = !0) => {
|
|
205
205
|
b && w === void 0 && S(r, x), clearTimeout(w), w = setTimeout(re, u, r, x);
|
|
206
206
|
}, i == null) return y;
|
|
207
|
-
let A = null, j = null, q = !0, F = !0, N = !1, $ = 0,
|
|
207
|
+
let A = null, j = null, q = !0, F = !0, N = !1, $ = 0, M = 0, K = -1, T = e instanceof Set ? (r) => new Set(r) : e instanceof Map ? (r) => new Map(r) : (r) => r, I = e instanceof Set ? (r) => {
|
|
208
208
|
if (r instanceof Set) return Array.from(r);
|
|
209
209
|
throw console.error(r), "The value is not Set instance";
|
|
210
210
|
} : e instanceof Map ? (r) => {
|
|
@@ -217,35 +217,35 @@ class pe {
|
|
|
217
217
|
if (typeof i == "string")
|
|
218
218
|
A = i;
|
|
219
219
|
else if ("storeKey" in i)
|
|
220
|
-
q = i.warnOnDuplicateStoreKey ?? q, F = i.listenStorageChanges ?? F, A = i.storeKey,
|
|
220
|
+
q = i.warnOnDuplicateStoreKey ?? q, F = i.listenStorageChanges ?? F, A = i.storeKey, T = i.unzipValue ?? T, I = i.zipValue ?? I, N = i.unchangable ?? N, $ = i.securifyKeyLevel ?? _.securifyKeyLevel ?? $, M = i.securifyValueLevel ?? _.securifyValueLevel ?? M, j = i.exp ?? j;
|
|
221
221
|
else return y;
|
|
222
|
-
const B = $ ?
|
|
222
|
+
const B = $ ? L(A, $) : A, a = `${M ? J : C}${B}`;
|
|
223
223
|
if ($) {
|
|
224
|
-
const r = `${
|
|
224
|
+
const r = `${C}${A}`;
|
|
225
225
|
r in o && (o[a] = o[r], delete o[r]);
|
|
226
226
|
} else {
|
|
227
|
-
const r = `${
|
|
227
|
+
const r = `${C}${L(A, $)}`;
|
|
228
228
|
r in o && (o[a] = o[r], delete o[r]);
|
|
229
229
|
}
|
|
230
|
-
const W = j === null || !(j(y, a in o) instanceof Date) ? (r) =>
|
|
231
|
-
if (
|
|
232
|
-
const r = `${
|
|
233
|
-
if (
|
|
230
|
+
const W = j === null || !(j(y, a in o) instanceof Date) ? (r) => L([I(r)], 0) : (r) => (d ?? (d = {}), d.exp = j(y, a in o).getTime(), d.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(K), clearTimeout(ee[a]), K = setTimeout(() => this.reset(), d.exp - Date.now())), d.exp = Math.trunc(d.exp / 1e3), L([I(r), d], 0));
|
|
231
|
+
if (M) {
|
|
232
|
+
const r = `${C}${B}`, u = I, x = T;
|
|
233
|
+
if (I = (b) => {
|
|
234
234
|
try {
|
|
235
|
-
return
|
|
235
|
+
return L([u(b)], M);
|
|
236
236
|
} catch {
|
|
237
237
|
return delete o[a], "";
|
|
238
238
|
}
|
|
239
239
|
}, r in o) {
|
|
240
|
-
const b = `${
|
|
240
|
+
const b = `${C}${L(A, $)}`;
|
|
241
241
|
try {
|
|
242
|
-
o[b] = W(
|
|
242
|
+
o[b] = W(T(z(o[r], 0)[0])), delete o[r];
|
|
243
243
|
} catch {
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
|
|
246
|
+
T = (b) => {
|
|
247
247
|
try {
|
|
248
|
-
return x(z(b,
|
|
248
|
+
return x(z(b, M)[0]);
|
|
249
249
|
} catch {
|
|
250
250
|
return delete o[a], "";
|
|
251
251
|
}
|
|
@@ -253,7 +253,7 @@ class pe {
|
|
|
253
253
|
} else delete o[`${J}${B}`];
|
|
254
254
|
const X = (r) => {
|
|
255
255
|
const u = z(r, 0);
|
|
256
|
-
return d = u[1],
|
|
256
|
+
return d = u[1], T(u[0]);
|
|
257
257
|
};
|
|
258
258
|
let Y = !0;
|
|
259
259
|
if (G[a] = y, o[`atom/${A}`] && (o[a] || (o[a] = `[${o[`atom/${A}`]}]`), delete o[`atom/${A}`]), f = () => {
|
|
@@ -274,14 +274,14 @@ class pe {
|
|
|
274
274
|
o[a] = W(r);
|
|
275
275
|
}, this.reset = () => {
|
|
276
276
|
delete o[a], S(e, !0);
|
|
277
|
-
}, q &&
|
|
277
|
+
}, q && P[a] !== void 0 && console.warn("Duplicate Atom key", A), F)
|
|
278
278
|
if (N) {
|
|
279
279
|
let r = !1, u;
|
|
280
|
-
U[a] = this,
|
|
280
|
+
U[a] = this, P[a] = () => {
|
|
281
281
|
clearTimeout(u), u = setTimeout(() => r = !1, 10), !r && (r = !0, o[a] = W(n()));
|
|
282
282
|
};
|
|
283
283
|
} else
|
|
284
|
-
|
|
284
|
+
P[a] = (r) => {
|
|
285
285
|
if (r.newValue === null) {
|
|
286
286
|
this.reset();
|
|
287
287
|
return;
|
|
@@ -303,12 +303,12 @@ try {
|
|
|
303
303
|
});
|
|
304
304
|
} catch {
|
|
305
305
|
}
|
|
306
|
-
const o = localStorage,
|
|
306
|
+
const o = localStorage, P = {}, U = {}, we = (t, e) => {
|
|
307
307
|
throw `${e} is readonly property`;
|
|
308
308
|
};
|
|
309
309
|
window.addEventListener("storage", (t) => {
|
|
310
310
|
var e;
|
|
311
|
-
t.key === null || t.newValue === t.oldValue || (e =
|
|
311
|
+
t.key === null || t.newValue === t.oldValue || (e = P[t.key]) == null || e.call(P, t);
|
|
312
312
|
});
|
|
313
313
|
const ye = o.setItem.bind(o), Ae = o.removeItem.bind(o);
|
|
314
314
|
o.setItem = (t, e) => {
|
|
@@ -317,13 +317,13 @@ o.setItem = (t, e) => {
|
|
|
317
317
|
o.removeItem = (t) => {
|
|
318
318
|
U[t] === void 0 && Ae.call(o, t);
|
|
319
319
|
};
|
|
320
|
-
const me = /"exp":\s*(\d+)/,
|
|
320
|
+
const me = /"exp":\s*(\d+)/, C = "atom\\", J = "atom`s\\", G = {}, ee = {}, te = /[a-z]/gi, R = 5, Q = {};
|
|
321
321
|
for (let t = 54; t < 80; t++) {
|
|
322
322
|
if (t === 68 || t === 72 || t === 55) continue;
|
|
323
323
|
const e = String.fromCharCode(t + 43).toUpperCase(), i = String.fromCharCode(t + 43).toLowerCase();
|
|
324
324
|
Q[e] = i, Q[i] = e;
|
|
325
325
|
}
|
|
326
|
-
const se = (t) => Q[t] ?? t,
|
|
326
|
+
const se = (t) => Q[t] ?? t, L = /* @__PURE__ */ (() => {
|
|
327
327
|
const t = [
|
|
328
328
|
(e) => JSON.stringify(e),
|
|
329
329
|
(e) => btoa(encodeURI(t[0](e))),
|
|
@@ -362,13 +362,13 @@ const se = (t) => Q[t] ?? t, C = /* @__PURE__ */ (() => {
|
|
|
362
362
|
setTimeout(() => {
|
|
363
363
|
Object.keys(o).forEach((t) => {
|
|
364
364
|
var s;
|
|
365
|
-
if (typeof o[t] != "string" || !t.startsWith(
|
|
366
|
-
const e =
|
|
367
|
-
if (!e || e * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
|
|
365
|
+
if (typeof o[t] != "string" || !t.startsWith(C) && !t.startsWith(J)) return;
|
|
366
|
+
const e = (s = o[t].match(me)) == null ? void 0 : s[1];
|
|
367
|
+
if (!e || +e * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
|
|
368
368
|
const i = z(o[t], 0);
|
|
369
369
|
!Array.isArray(i) || i[1] == null || !("exp" in i[1]) || i[1].exp !== e || (ee[t] = setTimeout(() => {
|
|
370
370
|
G[t] ? G[t].reset() : delete o[t];
|
|
371
|
-
}, e * 1e3 - Date.now()));
|
|
371
|
+
}, +e * 1e3 - Date.now()));
|
|
372
372
|
});
|
|
373
373
|
}, 1e3);
|
|
374
374
|
export {
|
|
@@ -379,9 +379,9 @@ export {
|
|
|
379
379
|
fe as AtomNumberDoActions,
|
|
380
380
|
he as AtomObjectDoActions,
|
|
381
381
|
de as AtomSetDoActions,
|
|
382
|
-
|
|
382
|
+
_e as atom,
|
|
383
383
|
Se as configureAtomaric,
|
|
384
|
-
|
|
384
|
+
_ as configuredOptions,
|
|
385
385
|
$e as useAtom,
|
|
386
386
|
De as useAtomDo,
|
|
387
387
|
be as useAtomGet,
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,
|
|
1
|
+
(function(f,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(f=typeof globalThis<"u"?globalThis:f||self,_(f.atomaric={}))})(this,function(f){"use strict";let _=()=>{throw"call configureAtomaric() before all!"};const $={},de=t=>{$.useSyncExternalStore=_=t.useSyncExternalStore,$.keyPathSeparator=t.keyPathSeparator,$.securifyKeyLevel=t.securifyKeyLevel,$.securifyValueLevel=t.securifyValueLevel},Y=t=>_(t.subscribe,t.get),Z=t=>t.set,ge=t=>t.setDeferred,Ae=t=>t.get,me=t=>t.do,pe=t=>[Y(t),Z(t)],we=(t,e)=>new ie(t,e);class j{constructor(e){if(e)return new Proxy(this,{get:(i,s)=>s in this?i[s]:e[s]})}}const ye=(t,e)=>{const i=(s,r,o)=>new Proxy(s,{get:(l,d,m)=>{const A=o===0&&e.get!=null?e.get(l,d,m):l[d];return typeof A=="object"&&A!==null?i(Array.isArray(A)?A.slice(0):{...A},r.concat(Array.isArray(l)?+d:d),o+1):A},set:(l,d,m)=>(e.onSet(l,r,d,m,l[d])&&(l[d]=m),!0)});return i(t,[],0)};class v extends j{constructor(){super(...arguments),this.updateValue=(e,i)=>{const s=Array.isArray(e)?e.slice(0):{...e};let r=!1;const o=ye(e,{onSet:(l,d,m,A,p)=>{if(A===p)return!0;let S=s;r=!0;for(const h of d){const g=S[h];S=S[h]=Array.isArray(g)?g.slice():{...g}}return S[m]=A,!0}});return i(o),r?s:e}}}class k extends v{constructor(e,i){super(i),this.a=e,this.push=(...s)=>{s.length!==0&&this.a.set(this.a.get().concat(s))},this.unshift=(...s)=>{s.length!==0&&this.a.set(s.concat(this.a.get()))},this.update=s=>{const r=this.a.get(),o=this.updateValue(r,s);o!==r&&this.a.set(o)},this.filter=s=>{const r=this.a.get().filter(s??Se);r.length!==this.a.get().length&&this.a.set(r)},this.add=s=>{this.a.get().includes(s)||this.a.set(this.a.get().concat([s]))},this.removeFirst=s=>{const r=this.a.get().indexOf(s);if(r<0)return;const o=this.a.get().slice(0);o.splice(r,1),this.a.set(o)},this.toggle=(s,r)=>{const o=this.a.get().slice(),l=o.indexOf(s);l<0?r?o.unshift(s):o.push(s):o.splice(l,1),this.a.set(o)}}}const Se=t=>t;class O extends j{constructor(e,i){super(i),this.a=e,this.toggle=()=>{this.a.set(!this.a.get())}}}class ee extends j{constructor(e,i){super(i),this.a=e,this.setValue=(s,r)=>{if(this.a.get().get(s)===r)return;const o=new Map(this.a.get());o.set(s,r),this.a.set(o)},this.setIfNo=(s,r)=>{if(this.a.get().has(s))return;const o=new Map(this.a.get());o.set(s,r),this.a.set(o)},this.delete=s=>{if(!this.a.get().has(s))return;const r=new Map(this.a.get());r.delete(s),this.a.set(r)},this.toggle=(s,r)=>{const o=new Map(this.a.get());o.has(s)?o.delete(s):o.set(s,r),this.a.set(o)},this.clear=()=>{this.a.set(new Map)},this.a=e}}class te extends j{constructor(e,i){super(i),this.a=e,this.increment=s=>{this.a.set(+this.a.get()+(s??1))}}}class se extends v{constructor(e,i){super(i),this.a=e,this.setPartial=s=>this.a.set(r=>({...r,...typeof s=="function"?s(this.a.get()):s})),this.update=s=>{const r=this.a.get(),o=this.updateValue(r,s);o!==r&&this.a.set(o)},this.setDeepPartial=(s,r,o,l=$.keyPathSeparator||".")=>{if(!l)return;if(s.includes(l)){let A=s.split(l);const p=A[A.length-1];A=A.slice(0,-1);const S={...this.a.get()};let h=S,g=o;for(const w of A){g=g==null?void 0:g[Array.isArray(g)?"0":w];const M=h[ne(h,w)]??(Array.isArray(g)?[]:{});if(M==null||typeof M!="object"){if(o==null)throw"Incorrect path for setDeepPartial";const b=typeof r=="function"?r(void 0):r;this.a.get()[s]!==b&&this.setPartial({[s]:b});return}h=h[ne(h,w)]=Array.isArray(M)?[...M]:{...M}}const q=h[p];h[p]=typeof r=="function"?r(h[p]):r,q!==h[p]&&this.a.set(S);return}const d=this.a.get()[s],m=typeof r=="function"?r(d):r;m!==d&&this.setPartial({[s]:m})}}}const ne=(t,e)=>Array.isArray(t)?`${+e}`:e;class re extends j{constructor(e,i){super(i),this.a=e,this.add=s=>{this.a.get().has(s)||this.a.set(new Set(this.a.get()).add(s))},this.delete=s=>{if(!this.a.get().has(s))return;const r=new Set(this.a.get());r.delete(s),this.a.set(r)},this.toggle=s=>{const r=new Set(this.a.get());r.has(s)?r.delete(s):r.add(s),this.a.set(r)},this.clear=()=>{this.a.set(new Set)},this.a=e}}const be=(t,e,i)=>{const s=typeof i=="object"&&i!=null&&"do"in i?i.do((o,l)=>e.set(o,l),()=>e.get(),e,(o,l,d)=>e.setDeferred(o,l,d)):null,r={};return s&&Object.keys(s).forEach(o=>Object.defineProperty(r,o,{get:()=>s[o]})),typeof t=="number"?new te(e,s):typeof t=="boolean"?new O(e,s):Array.isArray(t)?new k(e,s):t instanceof Set?new re(e,s):t instanceof Map?new ee(e,s):t instanceof Object?new se(e,s):new j(s)};class ie{constructor(e,i){e=typeof e=="function"?e():e;const s=n=>A=n,r=()=>A,o=new Set,l=n=>n(h());let d=!0,m=!1,A=e,p,S=()=>{},h=()=>r(),g=null,q=()=>{const n=be(e,w,i);return q=()=>n,n};const w=new Proxy(this,{get:(n,u)=>u==="do"?q():n[u],set:De}),M=()=>{d=!0,m!==!0&&S(h()),m=!1;try{B.postMessage({key:a,value:r()})}catch{}},b=(n,u)=>{const D=typeof n=="function"?n(h()):n;D!==h()&&(s(D),m=u,d&&(d=!1,o.forEach(l),queueMicrotask(M)))};this.set=(n,u)=>b(n,u),this.get=()=>h(),this.initialValue=e,this.isInitialValue=()=>e===r(),this.subscribe=n=>(o.add(n),()=>{o.delete(n)}),this.reset=()=>{b(e,!0)};const Te=(n,u)=>{b(n,u),p=void 0};if(this.setDeferred=(n,u=500,D,x=!0)=>{x&&p===void 0&&b(n,D),clearTimeout(p),p=setTimeout(Te,u,n,D)},i==null)return w;let y=null,z=null,H=!0,J=!0,Q=!1,T=0,C=0,ue=-1,V=e instanceof Set?n=>new Set(n):e instanceof Map?n=>new Map(n):n=>n,E=e instanceof Set?n=>{if(n instanceof Set)return Array.from(n);throw console.error(n),"The value is not Set instance"}:e instanceof Map?n=>{if(n instanceof Map){const u=[];return n.forEach((D,x)=>u.push([x,D])),u}throw console.error(n),"The value is not Set instance"}:n=>n;if(typeof i=="string")y=i;else if("storeKey"in i)H=i.warnOnDuplicateStoreKey??H,J=i.listenStorageChanges??J,y=i.storeKey,V=i.unzipValue??V,E=i.zipValue??E,Q=i.unchangable??Q,T=i.securifyKeyLevel??$.securifyKeyLevel??T,C=i.securifyValueLevel??$.securifyValueLevel??C,z=i.exp??z;else return w;const K=T?P(y,T):y,a=`${C?F:L}${K}`;if(T){const n=`${L}${y}`;n in c&&(c[a]=c[n],delete c[n])}else{const n=`${L}${P(y,T)}`;n in c&&(c[a]=c[n],delete c[n])}const X=z===null||!(z(w,a in c)instanceof Date)?n=>P([E(n)],0):n=>(g??(g={}),g.exp=z(w,a in c).getTime(),g.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ue),clearTimeout(oe[a]),ue=setTimeout(()=>this.reset(),g.exp-Date.now())),g.exp=Math.trunc(g.exp/1e3),P([E(n),g],0));if(C){const n=`${L}${K}`,u=E,D=V;if(E=x=>{try{return P([u(x)],C)}catch{return delete c[a],""}},n in c){const x=`${L}${P(y,T)}`;try{c[x]=X(V(U(c[n],0)[0])),delete c[n]}catch{}}V=x=>{try{return D(U(x,C)[0])}catch{return delete c[a],""}}}else delete c[`${F}${K}`];const fe=n=>{const u=U(n,0);return g=u[1],V(u[0])};let le=!0;if(W[a]=w,c[`atom/${y}`]&&(c[a]||(c[a]=`[${c[`atom/${y}`]}]`),delete c[`atom/${y}`]),h=()=>{if(h=r,le){le=!1;try{s(a in c?fe(c[a]):e)}catch{console.warn("Invalid json value",c[a])}}return r()},S=n=>{if(n===e){this.reset();return}c[a]=X(n)},this.reset=()=>{delete c[a],b(e,!0)},H&&I[a]!==void 0&&console.warn("Duplicate Atom key",y),J)if(Q){let n=!1,u;R[a]=this,I[a]=()=>{clearTimeout(u),u=setTimeout(()=>n=!1,10),!n&&(n=!0,c[a]=X(r()))}}else I[a]=n=>{if(n.newValue===null){this.reset();return}try{b(fe(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return w}}let B;try{B=new BroadcastChannel("updateHere"),B.addEventListener("message",t=>{var e;(e=R[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const c=localStorage,I={},R={},De=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=I[t.key])==null||e.call(I,t)});const xe=c.setItem.bind(c),$e=c.removeItem.bind(c);c.setItem=(t,e)=>{R[t]===void 0&&xe.call(c,t,e)},c.removeItem=t=>{R[t]===void 0&&$e.call(c,t)};const Me=/"exp":\s*(\d+)/,L="atom\\",F="atom`s\\",W={},oe={},ce=/[a-z]/gi,N=5,G={};for(let t=54;t<80;t++){if(t===68||t===72||t===55)continue;const e=String.fromCharCode(t+43).toUpperCase(),i=String.fromCharCode(t+43).toLowerCase();G[e]=i,G[i]=e}const ae=t=>G[t]??t,P=(()=>{const t=[e=>JSON.stringify(e),e=>btoa(encodeURI(t[0](e))),e=>{const i=t[1](e);return`${i.slice(0,N)}${i.slice(N).replace(ce,ae)}`},e=>btoa(t[2](e))];return(e,i)=>{try{return t[i](e)}catch(s){if(i===0)throw s;return t[0](e)}}})(),U=(()=>{const t=[e=>JSON.parse(e),e=>t[0](decodeURI(atob(e))),e=>t[1](`${e.slice(0,N)}${e.slice(N).replace(ce,ae)}`),e=>t[2](atob(e))];return(e,i)=>{try{return t[i](e)}catch(s){if(i===0)throw s;return t[0](e)}}})();setTimeout(()=>{Object.keys(c).forEach(t=>{var s;if(typeof c[t]!="string"||!t.startsWith(L)&&!t.startsWith(F))return;const e=(s=c[t].match(Me))==null?void 0:s[1];if(!e||+e*1e3-Date.now()>24*60*60*1e3)return;const i=U(c[t],0);!Array.isArray(i)||i[1]==null||!("exp"in i[1])||i[1].exp!==e||(oe[t]=setTimeout(()=>{W[t]?W[t].reset():delete c[t]},+e*1e3-Date.now()))})},1e3),f.Atom=ie,f.AtomArrayDoActions=k,f.AtomBooleanDoActions=O,f.AtomMapDoActions=ee,f.AtomNumberDoActions=te,f.AtomObjectDoActions=se,f.AtomSetDoActions=re,f.atom=we,f.configureAtomaric=de,f.configuredOptions=$,f.useAtom=pe,f.useAtomDo=me,f.useAtomGet=Ae,f.useAtomSet=Z,f.useAtomSetDeferred=ge,f.useAtomValue=Y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atomaric",
|
|
3
3
|
"description": "Manage your project state",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.76",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/atomaric.umd.cjs",
|
|
7
7
|
"module": "./build/atomaric.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"build",
|
|
18
18
|
"types",
|
|
19
|
-
"src/do.classes"
|
|
19
|
+
"src/do.classes",
|
|
20
|
+
"src/makeDeepProxyObject"
|
|
20
21
|
],
|
|
21
22
|
"keywords": [
|
|
22
23
|
"react",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"start": "vite --port 8378 --host",
|
|
28
29
|
"build": "tsc && vite build",
|
|
29
30
|
"preview": "vite preview",
|
|
30
|
-
"test": "jest"
|
|
31
|
+
"test": "jest",
|
|
32
|
+
"lint": "tsc --project ./tsconfig.json --noEmit && eslint **/*.{ts,tsx,json} *.*"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -44,6 +46,7 @@
|
|
|
44
46
|
"react": "^19.1.0",
|
|
45
47
|
"react-dom": "^19.1.1",
|
|
46
48
|
"ts-jest": "^29.4.6",
|
|
49
|
+
"typescript-eslint": "^8.52.0",
|
|
47
50
|
"vite": "^6.3.1",
|
|
48
51
|
"vite-plugin-eslint": "^1.8.1"
|
|
49
52
|
},
|
package/src/do.classes/Array.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { Atom } from '../../types';
|
|
2
3
|
import { AtomUpdateDoAction } from './_Update';
|
|
3
4
|
|
|
4
5
|
export class AtomArrayDoActions<Value> extends AtomUpdateDoAction {
|
|
5
|
-
constructor(private a: Atom<Value[]>, actions: Record<string,
|
|
6
|
+
constructor(private a: Atom<Value[]>, actions: Record<string, AnyFunc> | nil) {
|
|
6
7
|
super(actions);
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -2,7 +2,7 @@ import { Atom } from '../../types';
|
|
|
2
2
|
import { AtomDoActionsBasic } from './_Basic';
|
|
3
3
|
|
|
4
4
|
export class AtomBooleanDoActions extends AtomDoActionsBasic {
|
|
5
|
-
constructor(private a: Atom<boolean>, actions: Record<string,
|
|
5
|
+
constructor(private a: Atom<boolean>, actions: Record<string, AnyFunc> | nil) {
|
|
6
6
|
super(actions);
|
|
7
7
|
}
|
|
8
8
|
|
package/src/do.classes/Map.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { Atom } from '../../types';
|
|
2
3
|
import { AtomDoActionsBasic } from './_Basic';
|
|
3
4
|
|
|
@@ -6,7 +7,7 @@ export class AtomMapDoActions<
|
|
|
6
7
|
Key extends MapValue extends Map<infer K, any> ? K : never,
|
|
7
8
|
Value extends MapValue extends Map<any, infer V> ? V : never,
|
|
8
9
|
> extends AtomDoActionsBasic {
|
|
9
|
-
constructor(private a: Atom<MapValue>, actions: Record<string,
|
|
10
|
+
constructor(private a: Atom<MapValue>, actions: Record<string, AnyFunc> | nil) {
|
|
10
11
|
super(actions);
|
|
11
12
|
this.a = a;
|
|
12
13
|
}
|
package/src/do.classes/Number.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Atom } from '../../types';
|
|
|
2
2
|
import { AtomDoActionsBasic } from './_Basic';
|
|
3
3
|
|
|
4
4
|
export class AtomNumberDoActions extends AtomDoActionsBasic {
|
|
5
|
-
constructor(private a: Atom<number>, actions: Record<string,
|
|
5
|
+
constructor(private a: Atom<number>, actions: Record<string, AnyFunc> | nil) {
|
|
6
6
|
super(actions);
|
|
7
7
|
}
|
|
8
8
|
|
package/src/do.classes/Object.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { configuredOptions } from '../lib';
|
|
|
3
3
|
import { AtomUpdateDoAction } from './_Update';
|
|
4
4
|
|
|
5
5
|
export class AtomObjectDoActions<Value extends object> extends AtomUpdateDoAction {
|
|
6
|
-
constructor(private a: Atom<Value>, actions: Record<string,
|
|
6
|
+
constructor(private a: Atom<Value>, actions: Record<string, AnyFunc> | nil) {
|
|
7
7
|
super(actions);
|
|
8
8
|
}
|
|
9
9
|
|
package/src/do.classes/Set.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Atom } from '../../types';
|
|
|
2
2
|
import { AtomDoActionsBasic } from './_Basic';
|
|
3
3
|
|
|
4
4
|
export class AtomSetDoActions<Value> extends AtomDoActionsBasic {
|
|
5
|
-
constructor(private a: Atom<Set<Value>>, actions: Record<string,
|
|
5
|
+
constructor(private a: Atom<Set<Value>>, actions: Record<string, AnyFunc> | nil) {
|
|
6
6
|
super(actions);
|
|
7
7
|
this.a = a;
|
|
8
8
|
}
|
package/src/do.classes/_Basic.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { useSyncExternalStore } from 'react';
|
|
2
3
|
import { AtomArrayDoActions } from '../src/do.classes/Array';
|
|
3
4
|
import { AtomBooleanDoActions } from '../src/do.classes/Boolean';
|
|
@@ -9,6 +10,7 @@ import { Path, PathValue, PathValueDonor } from './paths';
|
|
|
9
10
|
|
|
10
11
|
export type AtomSecureLevel = 0 | 1 | 2 | 3;
|
|
11
12
|
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
12
14
|
export interface Register {}
|
|
13
15
|
|
|
14
16
|
export type ObjectActionsSetDeepPartialSeparator = Register extends {
|
|
@@ -21,7 +23,7 @@ type Sunscriber<Value> = (value: Value) => void;
|
|
|
21
23
|
|
|
22
24
|
export type AtomStoreKey = `${string}${string}:${string}${string}`;
|
|
23
25
|
|
|
24
|
-
export type AtomOptions<Value, Actions extends Record<string,
|
|
26
|
+
export type AtomOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> = {
|
|
25
27
|
/** **default: true** */
|
|
26
28
|
warnOnDuplicateStoreKey?: boolean;
|
|
27
29
|
/** will update value if localStorage value is changed
|
|
@@ -89,9 +91,9 @@ export type DefaultActions<Value> = Value extends Set<infer Val>
|
|
|
89
91
|
? AtomNumberDoActions
|
|
90
92
|
: Value extends object
|
|
91
93
|
? AtomObjectDoActions<Value>
|
|
92
|
-
:
|
|
94
|
+
: object;
|
|
93
95
|
|
|
94
|
-
declare class Atom<Value, Actions extends Record<string,
|
|
96
|
+
declare class Atom<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> {
|
|
95
97
|
constructor(initialValue: Value | (() => Value), storeKeyOrOptions: StoreKeyOrOptions<Value, Actions> | undefined);
|
|
96
98
|
|
|
97
99
|
/** initial value */
|
|
@@ -122,15 +124,15 @@ export function useAtomSetDeferred<Value>(atom: Atom<Value>): AtomSetDeferredMet
|
|
|
122
124
|
export function useAtomGet<Value>(atom: Atom<Value>): () => Value;
|
|
123
125
|
|
|
124
126
|
/** get your custom actions */
|
|
125
|
-
export function useAtomDo<Value, Actions extends Record<string,
|
|
127
|
+
export function useAtomDo<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>>(
|
|
126
128
|
atom: Atom<Value, Actions>,
|
|
127
129
|
): Actions & DefaultActions<Value>;
|
|
128
130
|
|
|
129
|
-
export type StoreKeyOrOptions<Value, Actions extends Record<string,
|
|
131
|
+
export type StoreKeyOrOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> =
|
|
130
132
|
| AtomStoreKey
|
|
131
133
|
| AtomOptions<Value, Actions>;
|
|
132
134
|
|
|
133
|
-
export function atom<Value, Actions extends Record<string,
|
|
135
|
+
export function atom<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>>(
|
|
134
136
|
value: Value | (() => Value),
|
|
135
137
|
storeKeyOrOptions?: StoreKeyOrOptions<Value, Actions>,
|
|
136
138
|
): Atom<Value, Actions>;
|
package/types/paths.ts
CHANGED