atomaric 0.0.77 → 0.0.78

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 CHANGED
@@ -14,15 +14,15 @@ class V {
14
14
  }
15
15
  const ce = (t, e) => {
16
16
  const i = (s, n, c) => new Proxy(s, {
17
- get: (l, h, p) => {
18
- const g = c === 0 && e.get != null ? e.get(l, h, p) : l[h];
19
- return typeof g == "object" && g !== null ? i(
20
- Array.isArray(g) ? g.slice(0) : { ...g },
21
- n.concat(Array.isArray(l) ? +h : h),
17
+ get: (a, d, p) => {
18
+ const w = c === 0 && e.get != null ? e.get(a, d, p) : a[d], f = w ?? (Array.isArray(a) ? [] : {});
19
+ return typeof f == "object" && f !== null ? i(
20
+ Array.isArray(f) ? f.slice(0) : { ...f },
21
+ n.concat(Array.isArray(a) ? +d : d),
22
22
  c + 1
23
- ) : g;
23
+ ) : f;
24
24
  },
25
- set: (l, h, p) => (e.onSet(l, n, h, p, l[h]) && (l[h] = p), !0)
25
+ set: (a, d, p) => (e.onSet(a, n, d, p, a[d]) && (a[d] = p), !0)
26
26
  });
27
27
  return i(t, [], 0);
28
28
  };
@@ -31,19 +31,20 @@ class O extends V {
31
31
  super(...arguments), this.updateValue = (e, i) => {
32
32
  const s = Array.isArray(e) ? e.slice(0) : { ...e };
33
33
  let n = !1;
34
- const c = ce(e, {
35
- onSet: (l, h, p, g, w) => {
36
- if (g === w) return !0;
37
- let m = s;
38
- n = !0;
39
- for (const f of h) {
40
- const d = m[f];
41
- m = m[f] = Array.isArray(d) ? d.slice() : { ...d };
34
+ return i(
35
+ ce(s, {
36
+ onSet: (c, a, d, p, w) => {
37
+ if (p === w) return !0;
38
+ let f = s;
39
+ n = !0;
40
+ for (const b of a) {
41
+ const h = f[b];
42
+ f = f[b] = Array.isArray(h) ? h.slice() : { ...h };
43
+ }
44
+ return f[d] = p, !0;
42
45
  }
43
- return m[p] = g, !0;
44
- }
45
- });
46
- return i(c), n ? s : e;
46
+ })
47
+ ), n ? s : e;
47
48
  };
48
49
  }
49
50
  }
@@ -67,8 +68,8 @@ class oe extends O {
67
68
  const c = this.a.get().slice(0);
68
69
  c.splice(n, 1), this.a.set(c);
69
70
  }, this.toggle = (s, n) => {
70
- const c = this.a.get().slice(), l = c.indexOf(s);
71
- l < 0 ? n ? c.unshift(s) : c.push(s) : c.splice(l, 1), this.a.set(c);
71
+ const c = this.a.get().slice(), a = c.indexOf(s);
72
+ a < 0 ? n ? c.unshift(s) : c.push(s) : c.splice(a, 1), this.a.set(c);
72
73
  };
73
74
  }
74
75
  }
@@ -117,31 +118,31 @@ class he extends O {
117
118
  })), this.update = (s) => {
118
119
  const n = this.a.get(), c = this.updateValue(n, s);
119
120
  c !== n && this.a.set(c);
120
- }, this.setDeepPartial = (s, n, c, l = _.keyPathSeparator || ".") => {
121
- if (!l) return;
122
- if (s.includes(l)) {
123
- let g = s.split(l);
124
- const w = g[g.length - 1];
125
- g = g.slice(0, -1);
126
- const m = { ...this.a.get() };
127
- let f = m, d = c;
128
- for (const y of g) {
129
- d = d == null ? void 0 : d[Array.isArray(d) ? "0" : y];
130
- const D = f[v(f, y)] ?? (Array.isArray(d) ? [] : {});
121
+ }, this.setDeepPartial = (s, n, c, a = _.keyPathSeparator || ".") => {
122
+ if (!a) return;
123
+ if (s.includes(a)) {
124
+ let w = s.split(a);
125
+ const f = w[w.length - 1];
126
+ w = w.slice(0, -1);
127
+ const b = { ...this.a.get() };
128
+ let h = b, g = c;
129
+ for (const y of w) {
130
+ g = g == null ? void 0 : g[Array.isArray(g) ? "0" : y];
131
+ const D = h[v(h, y)] ?? (Array.isArray(g) ? [] : {});
131
132
  if (D == null || typeof D != "object") {
132
133
  if (c == null) throw "Incorrect path for setDeepPartial";
133
- const S = typeof n == "function" ? n(void 0) : n;
134
- this.a.get()[s] !== S && this.setPartial({ [s]: S });
134
+ const m = typeof n == "function" ? n(void 0) : n;
135
+ this.a.get()[s] !== m && this.setPartial({ [s]: m });
135
136
  return;
136
137
  }
137
- f = f[v(f, y)] = Array.isArray(D) ? [...D] : { ...D };
138
+ h = h[v(h, y)] = Array.isArray(D) ? [...D] : { ...D };
138
139
  }
139
- const E = f[w];
140
- f[w] = typeof n == "function" ? n(f[w]) : n, E !== f[w] && this.a.set(m);
140
+ const E = h[f];
141
+ h[f] = typeof n == "function" ? n(h[f]) : n, E !== h[f] && this.a.set(b);
141
142
  return;
142
143
  }
143
- const h = this.a.get()[s], p = typeof n == "function" ? n(h) : n;
144
- p !== h && this.setPartial({ [s]: p });
144
+ const d = this.a.get()[s], p = typeof n == "function" ? n(d) : n;
145
+ p !== d && this.setPartial({ [s]: p });
145
146
  };
146
147
  }
147
148
  }
@@ -164,53 +165,53 @@ class de extends V {
164
165
  }
165
166
  const ge = (t, e, i) => {
166
167
  const s = typeof i == "object" && i != null && "do" in i ? i.do(
167
- (c, l) => e.set(c, l),
168
+ (c, a) => e.set(c, a),
168
169
  () => e.get(),
169
170
  e,
170
- (c, l, h) => e.setDeferred(c, l, h)
171
+ (c, a, d) => e.setDeferred(c, a, d)
171
172
  ) : null, n = {};
172
173
  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
174
  };
174
175
  class pe {
175
176
  constructor(e, i) {
176
177
  e = typeof e == "function" ? e() : e;
177
- const s = (r) => g = r, n = () => g, c = /* @__PURE__ */ new Set(), l = (r) => r(f());
178
- let h = !0, p = !1, g = e, w, m = () => {
179
- }, f = () => n(), d = null, E = () => {
178
+ const s = (r) => w = r, n = () => w, c = /* @__PURE__ */ new Set(), a = (r) => r(h());
179
+ let d = !0, p = !1, w = e, f, b = () => {
180
+ }, h = () => n(), g = null, E = () => {
180
181
  const r = ge(e, y, i);
181
182
  return E = () => r, r;
182
183
  };
183
184
  const y = new Proxy(this, {
184
- get: (r, u) => u === "do" ? E() : r[u],
185
+ get: (r, l) => l === "do" ? E() : r[l],
185
186
  set: we
186
187
  }), D = () => {
187
- h = !0, p !== !0 && m(f()), p = !1;
188
+ d = !0, p !== !0 && b(h()), p = !1;
188
189
  try {
189
- H.postMessage({ key: a, value: n() });
190
+ H.postMessage({ key: u, value: n() });
190
191
  } catch {
191
192
  }
192
- }, S = (r, u) => {
193
- const x = typeof r == "function" ? r(f()) : r;
194
- x !== f() && (s(x), p = u, h && (h = !1, c.forEach(l), queueMicrotask(D)));
193
+ }, m = (r, l) => {
194
+ const S = typeof r == "function" ? r(h()) : r;
195
+ S !== h() && (s(S), p = l, d && (d = !1, c.forEach(a), queueMicrotask(D)));
195
196
  };
196
- this.set = (r, u) => S(r, u), this.get = () => f(), this.initialValue = e, this.isInitialValue = () => e === n(), this.subscribe = (r) => (c.add(r), () => {
197
+ this.set = (r, l) => m(r, l), this.get = () => h(), this.initialValue = e, this.isInitialValue = () => e === n(), this.subscribe = (r) => (c.add(r), () => {
197
198
  c.delete(r);
198
199
  }), this.reset = () => {
199
- S(e, !0);
200
+ m(e, !0);
200
201
  };
201
- const re = (r, u) => {
202
- S(r, u), w = void 0;
202
+ const re = (r, l) => {
203
+ m(r, l), f = void 0;
203
204
  };
204
- if (this.setDeferred = (r, u = 500, x, b = !0) => {
205
- b && w === void 0 && S(r, x), clearTimeout(w), w = setTimeout(re, u, r, x);
205
+ if (this.setDeferred = (r, l = 500, S, x = !0) => {
206
+ x && f === void 0 && m(r, S), clearTimeout(f), f = setTimeout(re, l, r, S);
206
207
  }, i == null) return y;
207
208
  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
209
  if (r instanceof Set) return Array.from(r);
209
210
  throw console.error(r), "The value is not Set instance";
210
211
  } : e instanceof Map ? (r) => {
211
212
  if (r instanceof Map) {
212
- const u = [];
213
- return r.forEach((x, b) => u.push([b, x])), u;
213
+ const l = [];
214
+ return r.forEach((S, x) => l.push([x, S])), l;
214
215
  }
215
216
  throw console.error(r), "The value is not Set instance";
216
217
  } : (r) => r;
@@ -219,75 +220,75 @@ class pe {
219
220
  else if ("storeKey" in i)
220
221
  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
222
  else return y;
222
- const B = $ ? L(A, $) : A, a = `${M ? J : C}${B}`;
223
+ const B = $ ? L(A, $) : A, u = `${M ? J : C}${B}`;
223
224
  if ($) {
224
225
  const r = `${C}${A}`;
225
- r in o && (o[a] = o[r], delete o[r]);
226
+ r in o && (o[u] = o[r], delete o[r]);
226
227
  } else {
227
228
  const r = `${C}${L(A, $)}`;
228
- r in o && (o[a] = o[r], delete o[r]);
229
+ r in o && (o[u] = o[r], delete o[r]);
229
230
  }
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
+ const W = j === null || !(j(y, u in o) instanceof Date) ? (r) => L([I(r)], 0) : (r) => (g ?? (g = {}), g.exp = j(y, u in o).getTime(), g.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(K), clearTimeout(ee[u]), K = setTimeout(() => this.reset(), g.exp - Date.now())), g.exp = Math.trunc(g.exp / 1e3), L([I(r), g], 0));
231
232
  if (M) {
232
- const r = `${C}${B}`, u = I, x = T;
233
- if (I = (b) => {
233
+ const r = `${C}${B}`, l = I, S = T;
234
+ if (I = (x) => {
234
235
  try {
235
- return L([u(b)], M);
236
+ return L([l(x)], M);
236
237
  } catch {
237
- return delete o[a], "";
238
+ return delete o[u], "";
238
239
  }
239
240
  }, r in o) {
240
- const b = `${C}${L(A, $)}`;
241
+ const x = `${C}${L(A, $)}`;
241
242
  try {
242
- o[b] = W(T(z(o[r], 0)[0])), delete o[r];
243
+ o[x] = W(T(z(o[r], 0)[0])), delete o[r];
243
244
  } catch {
244
245
  }
245
246
  }
246
- T = (b) => {
247
+ T = (x) => {
247
248
  try {
248
- return x(z(b, M)[0]);
249
+ return S(z(x, M)[0]);
249
250
  } catch {
250
- return delete o[a], "";
251
+ return delete o[u], "";
251
252
  }
252
253
  };
253
254
  } else delete o[`${J}${B}`];
254
255
  const X = (r) => {
255
- const u = z(r, 0);
256
- return d = u[1], T(u[0]);
256
+ const l = z(r, 0);
257
+ return g = l[1], T(l[0]);
257
258
  };
258
259
  let Y = !0;
259
- if (G[a] = y, o[`atom/${A}`] && (o[a] || (o[a] = `[${o[`atom/${A}`]}]`), delete o[`atom/${A}`]), f = () => {
260
- if (f = n, Y) {
260
+ if (G[u] = y, o[`atom/${A}`] && (o[u] || (o[u] = `[${o[`atom/${A}`]}]`), delete o[`atom/${A}`]), h = () => {
261
+ if (h = n, Y) {
261
262
  Y = !1;
262
263
  try {
263
- s(a in o ? X(o[a]) : e);
264
+ s(u in o ? X(o[u]) : e);
264
265
  } catch {
265
- console.warn("Invalid json value", o[a]);
266
+ console.warn("Invalid json value", o[u]);
266
267
  }
267
268
  }
268
269
  return n();
269
- }, m = (r) => {
270
+ }, b = (r) => {
270
271
  if (r === e) {
271
272
  this.reset();
272
273
  return;
273
274
  }
274
- o[a] = W(r);
275
+ o[u] = W(r);
275
276
  }, this.reset = () => {
276
- delete o[a], S(e, !0);
277
- }, q && P[a] !== void 0 && console.warn("Duplicate Atom key", A), F)
277
+ delete o[u], m(e, !0);
278
+ }, q && P[u] !== void 0 && console.warn("Duplicate Atom key", A), F)
278
279
  if (N) {
279
- let r = !1, u;
280
- U[a] = this, P[a] = () => {
281
- clearTimeout(u), u = setTimeout(() => r = !1, 10), !r && (r = !0, o[a] = W(n()));
280
+ let r = !1, l;
281
+ U[u] = this, P[u] = () => {
282
+ clearTimeout(l), l = setTimeout(() => r = !1, 10), !r && (r = !0, o[u] = W(n()));
282
283
  };
283
284
  } else
284
- P[a] = (r) => {
285
+ P[u] = (r) => {
285
286
  if (r.newValue === null) {
286
287
  this.reset();
287
288
  return;
288
289
  }
289
290
  try {
290
- S(X(r.newValue));
291
+ m(X(r.newValue));
291
292
  } catch {
292
293
  console.warn("Invalid json value", r.newValue);
293
294
  }
@@ -1 +1 @@
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"})});
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 x={},de=t=>{x.useSyncExternalStore=_=t.useSyncExternalStore,x.keyPathSeparator=t.keyPathSeparator,x.securifyKeyLevel=t.securifyKeyLevel,x.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,ye=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 pe=(t,e)=>{const i=(s,r,o)=>new Proxy(s,{get:(a,g,m)=>{const y=o===0&&e.get!=null?e.get(a,g,m):a[g],h=y??(Array.isArray(a)?[]:{});return typeof h=="object"&&h!==null?i(Array.isArray(h)?h.slice(0):{...h},r.concat(Array.isArray(a)?+g:g),o+1):h},set:(a,g,m)=>(e.onSet(a,r,g,m,a[g])&&(a[g]=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;return i(pe(s,{onSet:(o,a,g,m,y)=>{if(m===y)return!0;let h=s;r=!0;for(const $ of a){const d=h[$];h=h[$]=Array.isArray(d)?d.slice():{...d}}return h[g]=m,!0}})),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(),a=o.indexOf(s);a<0?r?o.unshift(s):o.push(s):o.splice(a,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,a=x.keyPathSeparator||".")=>{if(!a)return;if(s.includes(a)){let y=s.split(a);const h=y[y.length-1];y=y.slice(0,-1);const $={...this.a.get()};let d=$,A=o;for(const w of y){A=A==null?void 0:A[Array.isArray(A)?"0":w];const M=d[ne(d,w)]??(Array.isArray(A)?[]:{});if(M==null||typeof M!="object"){if(o==null)throw"Incorrect path for setDeepPartial";const S=typeof r=="function"?r(void 0):r;this.a.get()[s]!==S&&this.setPartial({[s]:S});return}d=d[ne(d,w)]=Array.isArray(M)?[...M]:{...M}}const q=d[h];d[h]=typeof r=="function"?r(d[h]):r,q!==d[h]&&this.a.set($);return}const g=this.a.get()[s],m=typeof r=="function"?r(g):r;m!==g&&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,a)=>e.set(o,a),()=>e.get(),e,(o,a,g)=>e.setDeferred(o,a,g)):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=>y=n,r=()=>y,o=new Set,a=n=>n(d());let g=!0,m=!1,y=e,h,$=()=>{},d=()=>r(),A=null,q=()=>{const n=be(e,w,i);return q=()=>n,n};const w=new Proxy(this,{get:(n,l)=>l==="do"?q():n[l],set:De}),M=()=>{g=!0,m!==!0&&$(d()),m=!1;try{B.postMessage({key:u,value:r()})}catch{}},S=(n,l)=>{const b=typeof n=="function"?n(d()):n;b!==d()&&(s(b),m=l,g&&(g=!1,o.forEach(a),queueMicrotask(M)))};this.set=(n,l)=>S(n,l),this.get=()=>d(),this.initialValue=e,this.isInitialValue=()=>e===r(),this.subscribe=n=>(o.add(n),()=>{o.delete(n)}),this.reset=()=>{S(e,!0)};const Te=(n,l)=>{S(n,l),h=void 0};if(this.setDeferred=(n,l=500,b,D=!0)=>{D&&h===void 0&&S(n,b),clearTimeout(h),h=setTimeout(Te,l,n,b)},i==null)return w;let p=null,z=null,H=!0,J=!0,Q=!1,T=0,V=0,ue=-1,C=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 l=[];return n.forEach((b,D)=>l.push([D,b])),l}throw console.error(n),"The value is not Set instance"}:n=>n;if(typeof i=="string")p=i;else if("storeKey"in i)H=i.warnOnDuplicateStoreKey??H,J=i.listenStorageChanges??J,p=i.storeKey,C=i.unzipValue??C,E=i.zipValue??E,Q=i.unchangable??Q,T=i.securifyKeyLevel??x.securifyKeyLevel??T,V=i.securifyValueLevel??x.securifyValueLevel??V,z=i.exp??z;else return w;const K=T?P(p,T):p,u=`${V?F:L}${K}`;if(T){const n=`${L}${p}`;n in c&&(c[u]=c[n],delete c[n])}else{const n=`${L}${P(p,T)}`;n in c&&(c[u]=c[n],delete c[n])}const X=z===null||!(z(w,u in c)instanceof Date)?n=>P([E(n)],0):n=>(A??(A={}),A.exp=z(w,u in c).getTime(),A.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ue),clearTimeout(oe[u]),ue=setTimeout(()=>this.reset(),A.exp-Date.now())),A.exp=Math.trunc(A.exp/1e3),P([E(n),A],0));if(V){const n=`${L}${K}`,l=E,b=C;if(E=D=>{try{return P([l(D)],V)}catch{return delete c[u],""}},n in c){const D=`${L}${P(p,T)}`;try{c[D]=X(C(U(c[n],0)[0])),delete c[n]}catch{}}C=D=>{try{return b(U(D,V)[0])}catch{return delete c[u],""}}}else delete c[`${F}${K}`];const le=n=>{const l=U(n,0);return A=l[1],C(l[0])};let fe=!0;if(W[u]=w,c[`atom/${p}`]&&(c[u]||(c[u]=`[${c[`atom/${p}`]}]`),delete c[`atom/${p}`]),d=()=>{if(d=r,fe){fe=!1;try{s(u in c?le(c[u]):e)}catch{console.warn("Invalid json value",c[u])}}return r()},$=n=>{if(n===e){this.reset();return}c[u]=X(n)},this.reset=()=>{delete c[u],S(e,!0)},H&&I[u]!==void 0&&console.warn("Duplicate Atom key",p),J)if(Q){let n=!1,l;R[u]=this,I[u]=()=>{clearTimeout(l),l=setTimeout(()=>n=!1,10),!n&&(n=!0,c[u]=X(r()))}}else I[u]=n=>{if(n.newValue===null){this.reset();return}try{S(le(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=x,f.useAtom=ye,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.77",
4
+ "version": "0.0.78",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
@@ -16,7 +16,7 @@ export interface IAtomArrayDoActions<Value> {
16
16
  /** will add value if not exists */
17
17
  add: (value: Value) => void;
18
18
 
19
- /** will delete value from array */
19
+ /** will delete first found value from array */
20
20
  removeFirst: (value: Value) => void;
21
21
 
22
22
  /** will add value if it doesn't exist, otherwise delete */
package/types/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { useSyncExternalStore } from 'react';
3
- import { IAtomArrayDoActions } from './do.classes.model/Array';
4
- import { IAtomBooleanDoActions } from './do.classes.model/Boolean';
5
- import { IAtomMapDoActions } from './do.classes.model/Map';
6
- import { IAtomNumberDoActions } from './do.classes.model/Number';
7
- import { IAtomObjectDoActions } from './do.classes.model/Object';
8
- import { IAtomSetDoActions } from './do.classes.model/Set';
3
+ import { IAtomArrayDoActions } from './do.classes.model/IArray';
4
+ import { IAtomBooleanDoActions } from './do.classes.model/IBoolean';
5
+ import { IAtomMapDoActions } from './do.classes.model/IMap';
6
+ import { IAtomNumberDoActions } from './do.classes.model/INumber';
7
+ import { IAtomObjectDoActions } from './do.classes.model/IObject';
8
+ import { IAtomSetDoActions } from './do.classes.model/ISet';
9
9
  import { Path, PathValue, PathValueDonor } from './paths';
10
10
 
11
11
  export type AtomSecureLevel = 0 | 1 | 2 | 3;
File without changes
File without changes