atomaric 0.0.61 → 0.0.63

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
@@ -1,290 +1,366 @@
1
- let B = () => {
1
+ var u = /* @__PURE__ */ ((e) => (e[e.None = 0] = "None", e[e.Simple = 1] = "Simple", e[e.Middle = 2] = "Middle", e[e.Strong = 3] = "Strong", e))(u || {});
2
+ let te = () => {
2
3
  throw "call configureAtomaric() before all!";
3
4
  };
4
- const J = {}, ne = (e) => {
5
- J.useSyncExternalStore = B = e.useSyncExternalStore, J.keyPathSeparator = e.keyPathSeparator;
6
- }, k = (e) => B(e.subscribe, e.get), X = (e) => e.set, se = (e) => e.setDeferred, ce = (e) => e.get, oe = (e) => e.do, ie = (e) => [k(e), X(e)], le = (e, s) => new O(e, s), Y = (e, s) => {
7
- const i = (u, p, y) => new Proxy(u, {
8
- get: (r, t, c) => {
9
- const o = y === 0 && s.get != null ? s.get(r, t, c) : r[t];
10
- return typeof o == "object" && o !== null ? i(
11
- Array.isArray(o) ? o.slice(0) : { ...o },
12
- p.concat(Array.isArray(r) ? +t : t),
13
- y + 1
14
- ) : o;
5
+ const I = {}, pe = (e) => {
6
+ I.useSyncExternalStore = te = e.useSyncExternalStore, I.keyPathSeparator = e.keyPathSeparator, I.securifyKeyLevel = e.securifyKeyLevel, I.securifyValueLevel = e.securifyValueLevel;
7
+ }, ce = (e) => te(e.subscribe, e.get), oe = (e) => e.set, he = (e) => e.setDeferred, we = (e) => e.get, Se = (e) => e.do, Ae = (e) => [ce(e), oe(e)], be = (e, t) => new fe(e, t), ie = (e, t) => {
8
+ const c = (f, p, A) => new Proxy(f, {
9
+ get: (s, n, o) => {
10
+ const l = A === 0 && t.get != null ? t.get(s, n, o) : s[n];
11
+ return typeof l == "object" && l !== null ? c(
12
+ Array.isArray(l) ? l.slice(0) : { ...l },
13
+ p.concat(Array.isArray(s) ? +n : n),
14
+ A + 1
15
+ ) : l;
15
16
  },
16
- set: (r, t, c) => (s.onSet(r, p, t, c, r[t]) && (r[t] = c), !0)
17
+ set: (s, n, o) => (t.onSet(s, p, n, o, s[n]) && (s[n] = o), !0)
17
18
  });
18
- return i(e, [], 0);
19
- }, Z = (e, s, i) => {
20
- let u = null;
19
+ return c(e, [], 0);
20
+ }, le = (e, t, c) => {
21
+ let f = null;
21
22
  if (typeof e == "number")
22
- u = V(
23
- s,
24
- (r) => ({
25
- increment: (t) => {
26
- r.set(+r.get() + (t ?? 0));
23
+ f = R(
24
+ t,
25
+ (s) => ({
26
+ increment: (n) => {
27
+ s.set(+s.get() + (n ?? 0));
27
28
  }
28
29
  })
29
30
  );
30
31
  else if (typeof e == "boolean")
31
- u = V(
32
- s,
33
- (r) => ({
32
+ f = R(
33
+ t,
34
+ (s) => ({
34
35
  toggle: () => {
35
- r.set(!r.get());
36
+ s.set(!s.get());
36
37
  }
37
38
  })
38
39
  );
39
40
  else if (Array.isArray(e))
40
- u = V(
41
- s,
42
- (r) => ({
43
- push: (...t) => {
44
- r.set(r.get().concat(t));
41
+ f = R(
42
+ t,
43
+ (s) => ({
44
+ push: (...n) => {
45
+ s.set(s.get().concat(n));
45
46
  },
46
- unshift: (...t) => {
47
- r.set(t.concat(r.get()));
47
+ unshift: (...n) => {
48
+ s.set(n.concat(s.get()));
48
49
  },
49
- update: (t) => {
50
- const c = r.get(), o = W(c, t);
51
- o !== c && r.set(o);
50
+ update: (n) => {
51
+ const o = s.get(), l = O(o, n);
52
+ l !== o && s.set(l);
52
53
  },
53
- filter: (t) => {
54
- r.set(r.get().filter(t ?? v));
54
+ filter: (n) => {
55
+ s.set(s.get().filter(n ?? ue));
55
56
  },
56
- add: (t) => {
57
- r.get().includes(t) || r.set(r.get().concat([t]));
57
+ add: (n) => {
58
+ s.get().includes(n) || s.set(s.get().concat([n]));
58
59
  },
59
- remove: (t) => {
60
- const c = r.get().indexOf(t);
61
- if (c < 0) return;
62
- const o = r.get().slice(0);
63
- o.splice(c, 1), r.set(o);
60
+ remove: (n) => {
61
+ const o = s.get().indexOf(n);
62
+ if (o < 0) return;
63
+ const l = s.get().slice(0);
64
+ l.splice(o, 1), s.set(l);
64
65
  },
65
- toggle: (t, c) => {
66
- const o = r.get().slice(), f = o.indexOf(t);
67
- f < 0 ? c ? o.unshift(t) : o.push(t) : o.splice(f, 1), r.set(o);
66
+ toggle: (n, o) => {
67
+ const l = s.get().slice(), g = l.indexOf(n);
68
+ g < 0 ? o ? l.unshift(n) : l.push(n) : l.splice(g, 1), s.set(l);
68
69
  }
69
70
  })
70
71
  );
71
72
  else if (e instanceof Set)
72
- u = V(
73
- s,
74
- (r) => ({
75
- add: (t) => {
76
- r.set(new Set(r.get()).add(t));
73
+ f = R(
74
+ t,
75
+ (s) => ({
76
+ add: (n) => {
77
+ s.set(new Set(s.get()).add(n));
77
78
  },
78
- delete: (t) => {
79
- const c = new Set(r.get());
80
- c.delete(t), r.set(c);
79
+ delete: (n) => {
80
+ const o = new Set(s.get());
81
+ o.delete(n), s.set(o);
81
82
  },
82
- toggle: (t) => {
83
- const c = new Set(r.get());
84
- c.has(t) ? c.delete(t) : c.add(t), r.set(c);
83
+ toggle: (n) => {
84
+ const o = new Set(s.get());
85
+ o.has(n) ? o.delete(n) : o.add(n), s.set(o);
85
86
  },
86
87
  clear: () => {
87
- r.set(/* @__PURE__ */ new Set());
88
+ s.set(/* @__PURE__ */ new Set());
88
89
  }
89
90
  })
90
91
  );
91
92
  else if (e instanceof Object) {
92
- const r = J.keyPathSeparator || ".";
93
- u = V(
94
- s,
95
- (t) => ({
96
- setPartial: (c) => t.set((o) => ({
97
- ...o,
98
- ...typeof c == "function" ? c(t.get()) : c
93
+ const s = I.keyPathSeparator || ".";
94
+ f = R(
95
+ t,
96
+ (n) => ({
97
+ setPartial: (o) => n.set((l) => ({
98
+ ...l,
99
+ ...typeof o == "function" ? o(n.get()) : o
99
100
  })),
100
- update: (c) => {
101
- const o = t.get(), f = W(o, c);
102
- f !== o && t.set(f);
101
+ update: (o) => {
102
+ const l = n.get(), g = O(l, o);
103
+ g !== l && n.set(g);
103
104
  },
104
- setDeepPartial: (c, o, f, S = r) => {
105
- if (!S) return;
106
- if (c.includes(S)) {
107
- let T = c.split(S);
108
- const w = T[T.length - 1];
109
- T = T.slice(0, -1);
110
- const m = { ...t.get() };
111
- let g = m, _ = f;
112
- for (const b of T) {
113
- _ = _ == null ? void 0 : _[Array.isArray(_) ? "0" : b];
114
- const D = g[q(g, b)] ?? (Array.isArray(_) ? [] : {});
105
+ setDeepPartial: (o, l, g, x = s) => {
106
+ if (!x) return;
107
+ if (o.includes(x)) {
108
+ let N = o.split(x);
109
+ const S = N[N.length - 1];
110
+ N = N.slice(0, -1);
111
+ const q = { ...n.get() };
112
+ let y = q, V = g;
113
+ for (const $ of N) {
114
+ V = V == null ? void 0 : V[Array.isArray(V) ? "0" : $];
115
+ const D = y[ee(y, $)] ?? (Array.isArray(V) ? [] : {});
115
116
  if (D == null || typeof D != "object") {
116
- if (f == null) throw "Incorrect path for setDeepPartial";
117
- const j = typeof o == "function" ? o(void 0) : o;
118
- t.get()[c] !== j && t.do.setPartial({ [c]: j });
117
+ if (g == null) throw "Incorrect path for setDeepPartial";
118
+ const _ = typeof l == "function" ? l(void 0) : l;
119
+ n.get()[o] !== _ && n.do.setPartial({ [o]: _ });
119
120
  return;
120
121
  }
121
- g = g[q(g, b)] = Array.isArray(D) ? [...D] : { ...D };
122
+ y = y[ee(y, $)] = Array.isArray(D) ? [...D] : { ...D };
122
123
  }
123
- const x = g[w];
124
- g[w] = typeof o == "function" ? o(g[w]) : o, x !== g[w] && t.set(m);
124
+ const w = y[S];
125
+ y[S] = typeof l == "function" ? l(y[S]) : l, w !== y[S] && n.set(q);
125
126
  return;
126
127
  }
127
- const h = t.get()[c], A = typeof o == "function" ? o(h) : o;
128
- A !== h && t.do.setPartial({ [c]: A });
128
+ const h = n.get()[o], b = typeof l == "function" ? l(h) : l;
129
+ b !== h && n.do.setPartial({ [o]: b });
129
130
  }
130
131
  })
131
132
  );
132
133
  }
133
- const p = typeof i == "object" && i != null && "do" in i ? i.do(
134
- (r, t) => s.set(r, t),
135
- () => s.get(),
136
- s,
137
- (r, t, c) => s.setDeferred(r, t, c)
138
- ) : null, y = {};
139
- return p && Object.keys(p).forEach((r) => Object.defineProperty(y, r, { get: () => p[r] })), u && Object.keys(u).forEach(
140
- (r) => Object.defineProperty(y, r, { get: () => u[r] })
141
- ), y;
142
- }, v = (e) => e, V = (e, s, i) => s(e), W = (e, s) => {
143
- const i = Array.isArray(e) ? e.slice(0) : { ...e };
144
- let u = !1;
145
- const p = Y(e, {
146
- onSet: (y, r, t, c, o) => {
147
- if (c === o) return !0;
148
- let f = i;
149
- u = !0;
150
- for (const S of r) {
151
- const h = f[S];
152
- f = f[S] = Array.isArray(h) ? h.slice(0) : { ...h };
134
+ const p = typeof c == "object" && c != null && "do" in c ? c.do(
135
+ (s, n) => t.set(s, n),
136
+ () => t.get(),
137
+ t,
138
+ (s, n, o) => t.setDeferred(s, n, o)
139
+ ) : null, A = {};
140
+ return p && Object.keys(p).forEach((s) => Object.defineProperty(A, s, { get: () => p[s] })), f && Object.keys(f).forEach(
141
+ (s) => Object.defineProperty(A, s, { get: () => f[s] })
142
+ ), A;
143
+ }, ue = (e) => e, R = (e, t, c) => t(e), O = (e, t) => {
144
+ const c = Array.isArray(e) ? e.slice(0) : { ...e };
145
+ let f = !1;
146
+ const p = ie(e, {
147
+ onSet: (A, s, n, o, l) => {
148
+ if (o === l) return !0;
149
+ let g = c;
150
+ f = !0;
151
+ for (const x of s) {
152
+ const h = g[x];
153
+ g = g[x] = Array.isArray(h) ? h.slice(0) : { ...h };
153
154
  }
154
- return f[t] = c, !0;
155
+ return g[n] = o, !0;
155
156
  }
156
157
  });
157
- return s(p), u ? i : e;
158
- }, q = (e, s) => Array.isArray(e) ? `${+s}` : s;
159
- class O {
160
- constructor(s, i) {
161
- const u = (n) => o = n, p = () => o, y = /* @__PURE__ */ new Set(), r = (n) => n(h());
162
- let t = !0, c = !1, o = s, f, S = () => {
163
- }, h = () => p(), A = null, T = () => {
164
- const n = Z(s, w, i);
165
- return T = () => n, n;
158
+ return t(p), f ? c : e;
159
+ }, ee = (e, t) => Array.isArray(e) ? `${+t}` : t;
160
+ class fe {
161
+ constructor(t, c) {
162
+ const f = (r) => l = r, p = () => l, A = /* @__PURE__ */ new Set(), s = (r) => r(h());
163
+ let n = !0, o = !1, l = t, g, x = () => {
164
+ }, h = () => p(), b = null, N = () => {
165
+ const r = le(t, S, c);
166
+ return N = () => r, r;
166
167
  };
167
- const w = new Proxy(this, {
168
- get: (n, d) => d === "do" ? T() : n[d],
169
- set: K
170
- }), m = () => {
171
- t = !0, c !== !0 && S(h()), c = !1;
168
+ const S = new Proxy(this, {
169
+ get: (r, d) => d === "do" ? N() : r[d],
170
+ set: ae
171
+ }), q = () => {
172
+ n = !0, o !== !0 && x(h()), o = !1;
172
173
  try {
173
- M.postMessage({ key: a, value: p() });
174
+ G.postMessage({ key: a, value: p() });
174
175
  } catch {
175
176
  }
176
- }, g = (n, d) => {
177
- const I = typeof n == "function" ? n(h()) : n;
178
- I !== h() && (u(I), c = d, t && (t = !1, y.forEach(r), queueMicrotask(m)));
177
+ }, y = (r, d) => {
178
+ const T = typeof r == "function" ? r(h()) : r;
179
+ T !== h() && (f(T), o = d, n && (n = !1, A.forEach(s), queueMicrotask(q)));
179
180
  };
180
- this.set = (n, d) => g(n, d), this.get = () => h(), this.initialValue = s, this.isInitialValue = () => s === p(), this.subscribe = (n) => (y.add(n), () => {
181
- y.delete(n);
181
+ this.set = (r, d) => y(r, d), this.get = () => h(), this.initialValue = t, this.isInitialValue = () => t === p(), this.subscribe = (r) => (A.add(r), () => {
182
+ A.delete(r);
182
183
  }), this.reset = () => {
183
- g(s, !0);
184
+ y(t, !0);
184
185
  };
185
- const _ = (n, d) => {
186
- g(n, d), f = void 0;
186
+ const V = (r, d) => {
187
+ y(r, d), g = void 0;
187
188
  };
188
- if (this.setDeferred = (n, d = 500, I, U = !0) => {
189
- U && f === void 0 && g(n, I), clearTimeout(f), f = setTimeout(_, d, n, I);
190
- }, i == null) return w;
191
- let x = null, b = null, D = !0, j = !0, C = !1, F = -1, z = s instanceof Set ? (n) => new Set(n) : (n) => n, E = s instanceof Set ? (n) => {
192
- if (n instanceof Set) return Array.from(n);
193
- throw console.error(n), "The value is not Set instance";
194
- } : (n) => n;
195
- if (typeof i == "string")
196
- x = i;
197
- else if ("storeKey" in i)
198
- D = i.warnOnDuplicateStoreKey ?? D, j = i.listenStorageChanges ?? j, x = i.storeKey, z = i.unzipValue ?? z, E = i.zipValue ?? E, C = i.unchangable ?? C, b = i.exp ?? b;
199
- else return w;
200
- const a = `${G}${x}`, R = b === null || !(b(w, a in l) instanceof Date) ? (n) => JSON.stringify([E(n)]) : (n) => (A ?? (A = {}), A.exp = b(w, a in l).getTime(), A.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(F), clearTimeout(Q[a]), F = setTimeout(() => this.reset(), A.exp - Date.now())), A.exp = Math.trunc(A.exp / 1e3), JSON.stringify([E(n), A])), H = (n) => {
201
- const d = JSON.parse(n);
202
- return A = d[1], z(d[0]);
189
+ if (this.setDeferred = (r, d = 500, T, C = !0) => {
190
+ C && g === void 0 && y(r, T), clearTimeout(g), g = setTimeout(V, d, r, T);
191
+ }, c == null) return S;
192
+ let w = null, $ = null, D = !0, _ = !0, H = !1, P = u.None, j = u.None, X = -1, m = t instanceof Set ? (r) => new Set(r) : (r) => r, M = t instanceof Set ? (r) => {
193
+ if (r instanceof Set) return Array.from(r);
194
+ throw console.error(r), "The value is not Set instance";
195
+ } : (r) => r;
196
+ if (typeof c == "string")
197
+ w = c;
198
+ else if ("storeKey" in c)
199
+ D = c.warnOnDuplicateStoreKey ?? D, _ = c.listenStorageChanges ?? _, w = c.storeKey, m = c.unzipValue ?? m, M = c.zipValue ?? M, H = c.unchangable ?? H, P = c.securifyKeyLevel ?? I.securifyKeyLevel ?? P, j = c.securifyValueLevel ?? I.securifyValueLevel ?? j, $ = c.exp ?? $;
200
+ else return S;
201
+ const J = P ? E(w, P) : w, a = `${j ? Q : L}${J}`;
202
+ if (P) {
203
+ const r = `${L}${w}`;
204
+ r in i && (i[a] = i[r], delete i[r]);
205
+ } else {
206
+ const r = `${L}${E(w, P)}`;
207
+ r in i && (i[a] = i[r], delete i[r]);
208
+ }
209
+ const B = $ === null || !($(S, a in i) instanceof Date) ? (r) => E([M(r)], u.None) : (r) => (b ?? (b = {}), b.exp = $(S, a in i).getTime(), b.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(X), clearTimeout(re[a]), X = setTimeout(() => this.reset(), b.exp - Date.now())), b.exp = Math.trunc(b.exp / 1e3), E([M(r), b], u.None));
210
+ if (j) {
211
+ const r = `${L}${J}`, d = M, T = m;
212
+ if (M = (C) => {
213
+ try {
214
+ return E([d(C)], j);
215
+ } catch {
216
+ return delete i[a], "";
217
+ }
218
+ }, r in i) {
219
+ const C = `${L}${E(w, P)}`;
220
+ try {
221
+ i[C] = B(
222
+ m(U(i[r], u.None)[0])
223
+ ), delete i[r];
224
+ } catch {
225
+ }
226
+ }
227
+ m = (C) => {
228
+ try {
229
+ return T(U(C, j)[0]);
230
+ } catch {
231
+ return delete i[a], "";
232
+ }
233
+ };
234
+ } else delete i[`${Q}${J}`];
235
+ const Y = (r) => {
236
+ const d = U(r, u.None);
237
+ return b = d[1], m(d[0]);
203
238
  };
204
- let L = !0;
205
- if (N[a] = w, l[`atom/${x}`] && (l[a] || (l[a] = `[${l[`atom/${x}`]}]`), delete l[`atom/${x}`]), h = () => {
206
- if (h = p, L) {
207
- L = !1;
239
+ let Z = !0;
240
+ if (k[a] = S, i[`atom/${w}`] && (i[a] || (i[a] = `[${i[`atom/${w}`]}]`), delete i[`atom/${w}`]), h = () => {
241
+ if (h = p, Z) {
242
+ Z = !1;
208
243
  try {
209
- u(a in l ? H(l[a]) : s);
244
+ f(a in i ? Y(i[a]) : t);
210
245
  } catch {
211
- console.warn("Invalid json value", l[a]);
246
+ console.warn("Invalid json value", i[a]);
212
247
  }
213
248
  }
214
249
  return p();
215
- }, S = (n) => {
216
- if (n === s) {
250
+ }, x = (r) => {
251
+ if (r === t) {
217
252
  this.reset();
218
253
  return;
219
254
  }
220
- l[a] = R(n);
255
+ i[a] = B(r);
221
256
  }, this.reset = () => {
222
- delete l[a], g(s, !0);
223
- }, D && P[a] !== void 0 && console.warn("Duplicate Atom key", x), j)
224
- if (C) {
225
- let n = !1, d;
226
- $[a] = this, P[a] = () => {
227
- clearTimeout(d), d = setTimeout(() => n = !1, 10), !n && (n = !0, l[a] = R(p()));
257
+ delete i[a], y(t, !0);
258
+ }, D && z[a] !== void 0 && console.warn("Duplicate Atom key", w), _)
259
+ if (H) {
260
+ let r = !1, d;
261
+ W[a] = this, z[a] = () => {
262
+ clearTimeout(d), d = setTimeout(() => r = !1, 10), !r && (r = !0, i[a] = B(p()));
228
263
  };
229
264
  } else
230
- P[a] = (n) => {
231
- if (n.newValue === null) {
265
+ z[a] = (r) => {
266
+ if (r.newValue === null) {
232
267
  this.reset();
233
268
  return;
234
269
  }
235
270
  try {
236
- g(H(n.newValue));
271
+ y(Y(r.newValue));
237
272
  } catch {
238
- console.warn("Invalid json value", n.newValue);
273
+ console.warn("Invalid json value", r.newValue);
239
274
  }
240
275
  };
241
- return w;
276
+ return S;
242
277
  }
243
278
  }
244
- let M;
279
+ let G;
245
280
  try {
246
- M = new BroadcastChannel("updateHere"), M.addEventListener("message", (e) => {
247
- var s;
248
- (s = $[e.data.key]) == null || s.set(e.data.value, !0);
281
+ G = new BroadcastChannel("updateHere"), G.addEventListener("message", (e) => {
282
+ var t;
283
+ (t = W[e.data.key]) == null || t.set(e.data.value, !0);
249
284
  });
250
285
  } catch {
251
286
  }
252
- const l = window.localStorage, P = {}, $ = {}, K = (e, s) => {
253
- throw `${s} is readonly property`;
287
+ const i = localStorage, z = {}, W = {}, ae = (e, t) => {
288
+ throw `${t} is readonly property`;
254
289
  };
255
290
  window.addEventListener("storage", (e) => {
256
- var s;
257
- e.key === null || e.newValue === e.oldValue || (s = P[e.key]) == null || s.call(P, e);
291
+ var t;
292
+ e.key === null || e.newValue === e.oldValue || (t = z[e.key]) == null || t.call(z, e);
258
293
  });
259
- const ee = l.setItem.bind(l), te = l.removeItem.bind(l);
260
- l.setItem = (e, s) => {
261
- $[e] === void 0 && ee.call(l, e, s);
294
+ const de = i.setItem.bind(i), ge = i.removeItem.bind(i);
295
+ i.setItem = (e, t) => {
296
+ W[e] === void 0 && de.call(i, e, t);
262
297
  };
263
- l.removeItem = (e) => {
264
- $[e] === void 0 && te.call(l, e);
298
+ i.removeItem = (e) => {
299
+ W[e] === void 0 && ge.call(i, e);
265
300
  };
266
- const re = /"exp":\s*(\d+)/, G = "atom\\", N = {}, Q = {};
301
+ const ye = /"exp":\s*(\d+)/, L = "atom\\", Q = "atom`s\\", k = {}, re = {}, ne = /[a-z]/gi, F = 5, K = {};
302
+ for (let e = 54; e < 80; e++) {
303
+ if (e === 68 || e === 72 || e === 55) continue;
304
+ const t = String.fromCharCode(e + 43).toUpperCase(), c = String.fromCharCode(e + 43).toLowerCase();
305
+ K[t] = c, K[c] = t;
306
+ }
307
+ const se = (e) => K[e] ?? e, E = (() => {
308
+ const e = {
309
+ [u.None]: (t) => JSON.stringify(t),
310
+ [u.Simple]: (t) => btoa(encodeURI(e[u.None](t))),
311
+ [u.Middle]: (t) => {
312
+ const c = e[u.Simple](t);
313
+ return `${c.slice(0, F)}${c.slice(F).replace(ne, se)}`;
314
+ },
315
+ [u.Strong]: (t) => btoa(e[u.Middle](t))
316
+ };
317
+ return (t, c) => {
318
+ try {
319
+ return e[c](t);
320
+ } catch (f) {
321
+ if (c === u.None) throw f;
322
+ return e[u.None](t);
323
+ }
324
+ };
325
+ })(), U = (() => {
326
+ const e = {
327
+ [u.None]: (t) => JSON.parse(t),
328
+ [u.Simple]: (t) => e[u.None](decodeURI(atob(t))),
329
+ [u.Middle]: (t) => e[u.Simple](
330
+ `${t.slice(0, F)}${t.slice(F).replace(ne, se)}`
331
+ ),
332
+ [u.Strong]: (t) => e[u.Middle](atob(t))
333
+ };
334
+ return (t, c) => {
335
+ try {
336
+ return e[c](t);
337
+ } catch (f) {
338
+ if (c === u.None) throw f;
339
+ return e[u.None](t);
340
+ }
341
+ };
342
+ })();
267
343
  setTimeout(() => {
268
- Object.keys(l).forEach((e) => {
269
- var u;
270
- if (!e.startsWith(G) || typeof l[e] != "string") return;
271
- const s = +((u = l[e].match(re)) == null ? void 0 : u[1]);
272
- if (!s || s * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
273
- const i = JSON.parse(l[e]);
274
- !Array.isArray(i) || i[1] == null || !("exp" in i[1]) || i[1].exp !== s || (Q[e] = setTimeout(() => {
275
- N[e] ? N[e].reset() : delete l[e];
276
- }, s * 1e3 - Date.now()));
344
+ Object.keys(i).forEach((e) => {
345
+ var f;
346
+ if (typeof i[e] != "string" || !e.startsWith(L) && !e.startsWith(Q)) return;
347
+ const t = +((f = i[e].match(ye)) == null ? void 0 : f[1]);
348
+ if (!t || t * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
349
+ const c = U(i[e], u.None);
350
+ !Array.isArray(c) || c[1] == null || !("exp" in c[1]) || c[1].exp !== t || (re[e] = setTimeout(() => {
351
+ k[e] ? k[e].reset() : delete i[e];
352
+ }, t * 1e3 - Date.now()));
277
353
  });
278
354
  }, 1e3);
279
355
  export {
280
- O as Atom,
281
- le as atom,
282
- ne as configureAtomaric,
283
- J as configuredOptions,
284
- ie as useAtom,
285
- oe as useAtomDo,
286
- ce as useAtomGet,
287
- X as useAtomSet,
288
- se as useAtomSetDeferred,
289
- k as useAtomValue
356
+ fe as Atom,
357
+ be as atom,
358
+ pe as configureAtomaric,
359
+ I as configuredOptions,
360
+ Ae as useAtom,
361
+ Se as useAtomDo,
362
+ we as useAtomGet,
363
+ oe as useAtomSet,
364
+ he as useAtomSetDeferred,
365
+ ce as useAtomValue
290
366
  };
@@ -1 +1 @@
1
- (function(A,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(A=typeof globalThis<"u"?globalThis:A||self,_(A.atomaric={}))})(this,function(A){"use strict";let _=()=>{throw"call configureAtomaric() before all!"};const $={},Y=e=>{$.useSyncExternalStore=_=e.useSyncExternalStore,$.keyPathSeparator=e.keyPathSeparator},G=e=>_(e.subscribe,e.get),H=e=>e.set,Z=e=>e.setDeferred,O=e=>e.get,K=e=>e.do,ee=e=>[G(e),H(e)],te=(e,s)=>new q(e,s),ne=(e,s)=>{const i=(l,h,p)=>new Proxy(l,{get:(n,t,c)=>{const o=p===0&&s.get!=null?s.get(n,t,c):n[t];return typeof o=="object"&&o!==null?i(Array.isArray(o)?o.slice(0):{...o},h.concat(Array.isArray(n)?+t:t),p+1):o},set:(n,t,c)=>(s.onSet(n,h,t,c,n[t])&&(n[t]=c),!0)});return i(e,[],0)},re=(e,s,i)=>{let l=null;if(typeof e=="number")l=V(s,n=>({increment:t=>{n.set(+n.get()+(t??0))}}));else if(typeof e=="boolean")l=V(s,n=>({toggle:()=>{n.set(!n.get())}}));else if(Array.isArray(e))l=V(s,n=>({push:(...t)=>{n.set(n.get().concat(t))},unshift:(...t)=>{n.set(t.concat(n.get()))},update:t=>{const c=n.get(),o=L(c,t);o!==c&&n.set(o)},filter:t=>{n.set(n.get().filter(t??se))},add:t=>{n.get().includes(t)||n.set(n.get().concat([t]))},remove:t=>{const c=n.get().indexOf(t);if(c<0)return;const o=n.get().slice(0);o.splice(c,1),n.set(o)},toggle:(t,c)=>{const o=n.get().slice(),f=o.indexOf(t);f<0?c?o.unshift(t):o.push(t):o.splice(f,1),n.set(o)}}));else if(e instanceof Set)l=V(s,n=>({add:t=>{n.set(new Set(n.get()).add(t))},delete:t=>{const c=new Set(n.get());c.delete(t),n.set(c)},toggle:t=>{const c=new Set(n.get());c.has(t)?c.delete(t):c.add(t),n.set(c)},clear:()=>{n.set(new Set)}}));else if(e instanceof Object){const n=$.keyPathSeparator||".";l=V(s,t=>({setPartial:c=>t.set(o=>({...o,...typeof c=="function"?c(t.get()):c})),update:c=>{const o=t.get(),f=L(o,c);f!==o&&t.set(f)},setDeepPartial:(c,o,f,b=n)=>{if(!b)return;if(c.includes(b)){let D=c.split(b);const S=D[D.length-1];D=D.slice(0,-1);const M={...t.get()};let g=M,j=f;for(const x of D){j=j==null?void 0:j[Array.isArray(j)?"0":x];const T=g[W(g,x)]??(Array.isArray(j)?[]:{});if(T==null||typeof T!="object"){if(f==null)throw"Incorrect path for setDeepPartial";const I=typeof o=="function"?o(void 0):o;t.get()[c]!==I&&t.do.setPartial({[c]:I});return}g=g[W(g,x)]=Array.isArray(T)?[...T]:{...T}}const m=g[S];g[S]=typeof o=="function"?o(g[S]):o,m!==g[S]&&t.set(M);return}const y=t.get()[c],w=typeof o=="function"?o(y):o;w!==y&&t.do.setPartial({[c]:w})}}))}const h=typeof i=="object"&&i!=null&&"do"in i?i.do((n,t)=>s.set(n,t),()=>s.get(),s,(n,t,c)=>s.setDeferred(n,t,c)):null,p={};return h&&Object.keys(h).forEach(n=>Object.defineProperty(p,n,{get:()=>h[n]})),l&&Object.keys(l).forEach(n=>Object.defineProperty(p,n,{get:()=>l[n]})),p},se=e=>e,V=(e,s,i)=>s(e),L=(e,s)=>{const i=Array.isArray(e)?e.slice(0):{...e};let l=!1;const h=ne(e,{onSet:(p,n,t,c,o)=>{if(c===o)return!0;let f=i;l=!0;for(const b of n){const y=f[b];f=f[b]=Array.isArray(y)?y.slice(0):{...y}}return f[t]=c,!0}});return s(h),l?i:e},W=(e,s)=>Array.isArray(e)?`${+s}`:s;class q{constructor(s,i){const l=r=>o=r,h=()=>o,p=new Set,n=r=>r(y());let t=!0,c=!1,o=s,f,b=()=>{},y=()=>h(),w=null,D=()=>{const r=re(s,S,i);return D=()=>r,r};const S=new Proxy(this,{get:(r,d)=>d==="do"?D():r[d],set:ce}),M=()=>{t=!0,c!==!0&&b(y()),c=!1;try{J.postMessage({key:a,value:h()})}catch{}},g=(r,d)=>{const E=typeof r=="function"?r(y()):r;E!==y()&&(l(E),c=d,t&&(t=!1,p.forEach(n),queueMicrotask(M)))};this.set=(r,d)=>g(r,d),this.get=()=>y(),this.initialValue=s,this.isInitialValue=()=>s===h(),this.subscribe=r=>(p.add(r),()=>{p.delete(r)}),this.reset=()=>{g(s,!0)};const j=(r,d)=>{g(r,d),f=void 0};if(this.setDeferred=(r,d=500,E,le=!0)=>{le&&f===void 0&&g(r,E),clearTimeout(f),f=setTimeout(j,d,r,E)},i==null)return S;let m=null,x=null,T=!0,I=!0,F=!1,U=-1,R=s instanceof Set?r=>new Set(r):r=>r,z=s instanceof Set?r=>{if(r instanceof Set)return Array.from(r);throw console.error(r),"The value is not Set instance"}:r=>r;if(typeof i=="string")m=i;else if("storeKey"in i)T=i.warnOnDuplicateStoreKey??T,I=i.listenStorageChanges??I,m=i.storeKey,R=i.unzipValue??R,z=i.zipValue??z,F=i.unchangable??F,x=i.exp??x;else return S;const a=`${B}${m}`,k=x===null||!(x(S,a in u)instanceof Date)?r=>JSON.stringify([z(r)]):r=>(w??(w={}),w.exp=x(S,a in u).getTime(),w.exp-Date.now()<24*60*60*1e3&&(clearTimeout(U),clearTimeout(Q[a]),U=setTimeout(()=>this.reset(),w.exp-Date.now())),w.exp=Math.trunc(w.exp/1e3),JSON.stringify([z(r),w])),v=r=>{const d=JSON.parse(r);return w=d[1],R(d[0])};let X=!0;if(N[a]=S,u[`atom/${m}`]&&(u[a]||(u[a]=`[${u[`atom/${m}`]}]`),delete u[`atom/${m}`]),y=()=>{if(y=h,X){X=!1;try{l(a in u?v(u[a]):s)}catch{console.warn("Invalid json value",u[a])}}return h()},b=r=>{if(r===s){this.reset();return}u[a]=k(r)},this.reset=()=>{delete u[a],g(s,!0)},T&&P[a]!==void 0&&console.warn("Duplicate Atom key",m),I)if(F){let r=!1,d;C[a]=this,P[a]=()=>{clearTimeout(d),d=setTimeout(()=>r=!1,10),!r&&(r=!0,u[a]=k(h()))}}else P[a]=r=>{if(r.newValue===null){this.reset();return}try{g(v(r.newValue))}catch{console.warn("Invalid json value",r.newValue)}};return S}}let J;try{J=new BroadcastChannel("updateHere"),J.addEventListener("message",e=>{var s;(s=C[e.data.key])==null||s.set(e.data.value,!0)})}catch{}const u=window.localStorage,P={},C={},ce=(e,s)=>{throw`${s} is readonly property`};window.addEventListener("storage",e=>{var s;e.key===null||e.newValue===e.oldValue||(s=P[e.key])==null||s.call(P,e)});const oe=u.setItem.bind(u),ie=u.removeItem.bind(u);u.setItem=(e,s)=>{C[e]===void 0&&oe.call(u,e,s)},u.removeItem=e=>{C[e]===void 0&&ie.call(u,e)};const ue=/"exp":\s*(\d+)/,B="atom\\",N={},Q={};setTimeout(()=>{Object.keys(u).forEach(e=>{var l;if(!e.startsWith(B)||typeof u[e]!="string")return;const s=+((l=u[e].match(ue))==null?void 0:l[1]);if(!s||s*1e3-Date.now()>24*60*60*1e3)return;const i=JSON.parse(u[e]);!Array.isArray(i)||i[1]==null||!("exp"in i[1])||i[1].exp!==s||(Q[e]=setTimeout(()=>{N[e]?N[e].reset():delete u[e]},s*1e3-Date.now()))})},1e3),A.Atom=q,A.atom=te,A.configureAtomaric=Y,A.configuredOptions=$,A.useAtom=ee,A.useAtomDo=K,A.useAtomGet=O,A.useAtomSet=H,A.useAtomSetDeferred=Z,A.useAtomValue=G,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.atomaric={}))})(this,function(h){"use strict";var l=(e=>(e[e.None=0]="None",e[e.Simple=1]="Simple",e[e.Middle=2]="Middle",e[e.Strong=3]="Strong",e))(l||{});let Y=()=>{throw"call configureAtomaric() before all!"};const N={},le=e=>{N.useSyncExternalStore=Y=e.useSyncExternalStore,N.keyPathSeparator=e.keyPathSeparator,N.securifyKeyLevel=e.securifyKeyLevel,N.securifyValueLevel=e.securifyValueLevel},Z=e=>Y(e.subscribe,e.get),v=e=>e.set,fe=e=>e.setDeferred,ae=e=>e.get,de=e=>e.do,ge=e=>[Z(e),v(e)],ye=(e,t)=>new te(e,t),he=(e,t)=>{const c=(f,p,b)=>new Proxy(f,{get:(s,r,o)=>{const u=b===0&&t.get!=null?t.get(s,r,o):s[r];return typeof u=="object"&&u!==null?c(Array.isArray(u)?u.slice(0):{...u},p.concat(Array.isArray(s)?+r:r),b+1):u},set:(s,r,o)=>(t.onSet(s,p,r,o,s[r])&&(s[r]=o),!0)});return c(e,[],0)},pe=(e,t,c)=>{let f=null;if(typeof e=="number")f=q(t,s=>({increment:r=>{s.set(+s.get()+(r??0))}}));else if(typeof e=="boolean")f=q(t,s=>({toggle:()=>{s.set(!s.get())}}));else if(Array.isArray(e))f=q(t,s=>({push:(...r)=>{s.set(s.get().concat(r))},unshift:(...r)=>{s.set(r.concat(s.get()))},update:r=>{const o=s.get(),u=O(o,r);u!==o&&s.set(u)},filter:r=>{s.set(s.get().filter(r??Se))},add:r=>{s.get().includes(r)||s.set(s.get().concat([r]))},remove:r=>{const o=s.get().indexOf(r);if(o<0)return;const u=s.get().slice(0);u.splice(o,1),s.set(u)},toggle:(r,o)=>{const u=s.get().slice(),g=u.indexOf(r);g<0?o?u.unshift(r):u.push(r):u.splice(g,1),s.set(u)}}));else if(e instanceof Set)f=q(t,s=>({add:r=>{s.set(new Set(s.get()).add(r))},delete:r=>{const o=new Set(s.get());o.delete(r),s.set(o)},toggle:r=>{const o=new Set(s.get());o.has(r)?o.delete(r):o.add(r),s.set(o)},clear:()=>{s.set(new Set)}}));else if(e instanceof Object){const s=N.keyPathSeparator||".";f=q(t,r=>({setPartial:o=>r.set(u=>({...u,...typeof o=="function"?o(r.get()):o})),update:o=>{const u=r.get(),g=O(u,o);g!==u&&r.set(g)},setDeepPartial:(o,u,g,x=s)=>{if(!x)return;if(o.includes(x)){let T=o.split(x);const A=T[T.length-1];T=T.slice(0,-1);const G={...r.get()};let y=G,V=g;for(const $ of T){V=V==null?void 0:V[Array.isArray(V)?"0":$];const D=y[ee(y,$)]??(Array.isArray(V)?[]:{});if(D==null||typeof D!="object"){if(g==null)throw"Incorrect path for setDeepPartial";const E=typeof u=="function"?u(void 0):u;r.get()[o]!==E&&r.do.setPartial({[o]:E});return}y=y[ee(y,$)]=Array.isArray(D)?[...D]:{...D}}const w=y[A];y[A]=typeof u=="function"?u(y[A]):u,w!==y[A]&&r.set(G);return}const S=r.get()[o],m=typeof u=="function"?u(S):u;m!==S&&r.do.setPartial({[o]:m})}}))}const p=typeof c=="object"&&c!=null&&"do"in c?c.do((s,r)=>t.set(s,r),()=>t.get(),t,(s,r,o)=>t.setDeferred(s,r,o)):null,b={};return p&&Object.keys(p).forEach(s=>Object.defineProperty(b,s,{get:()=>p[s]})),f&&Object.keys(f).forEach(s=>Object.defineProperty(b,s,{get:()=>f[s]})),b},Se=e=>e,q=(e,t,c)=>t(e),O=(e,t)=>{const c=Array.isArray(e)?e.slice(0):{...e};let f=!1;const p=he(e,{onSet:(b,s,r,o,u)=>{if(o===u)return!0;let g=c;f=!0;for(const x of s){const S=g[x];g=g[x]=Array.isArray(S)?S.slice(0):{...S}}return g[r]=o,!0}});return t(p),f?c:e},ee=(e,t)=>Array.isArray(e)?`${+t}`:t;class te{constructor(t,c){const f=n=>u=n,p=()=>u,b=new Set,s=n=>n(S());let r=!0,o=!1,u=t,g,x=()=>{},S=()=>p(),m=null,T=()=>{const n=pe(t,A,c);return T=()=>n,n};const A=new Proxy(this,{get:(n,d)=>d==="do"?T():n[d],set:we}),G=()=>{r=!0,o!==!0&&x(S()),o=!1;try{H.postMessage({key:a,value:p()})}catch{}},y=(n,d)=>{const j=typeof n=="function"?n(S()):n;j!==S()&&(f(j),o=d,r&&(r=!1,b.forEach(s),queueMicrotask(G)))};this.set=(n,d)=>y(n,d),this.get=()=>S(),this.initialValue=t,this.isInitialValue=()=>t===p(),this.subscribe=n=>(b.add(n),()=>{b.delete(n)}),this.reset=()=>{y(t,!0)};const V=(n,d)=>{y(n,d),g=void 0};if(this.setDeferred=(n,d=500,j,C=!0)=>{C&&g===void 0&&y(n,j),clearTimeout(g),g=setTimeout(V,d,n,j)},c==null)return A;let w=null,$=null,D=!0,E=!0,k=!1,P=l.None,L=l.None,ce=-1,z=t instanceof Set?n=>new Set(n):n=>n,R=t instanceof Set?n=>{if(n instanceof Set)return Array.from(n);throw console.error(n),"The value is not Set instance"}:n=>n;if(typeof c=="string")w=c;else if("storeKey"in c)D=c.warnOnDuplicateStoreKey??D,E=c.listenStorageChanges??E,w=c.storeKey,z=c.unzipValue??z,R=c.zipValue??R,k=c.unchangable??k,P=c.securifyKeyLevel??N.securifyKeyLevel??P,L=c.securifyValueLevel??N.securifyValueLevel??L,$=c.exp??$;else return A;const K=P?M(w,P):w,a=`${L?J:_}${K}`;if(P){const n=`${_}${w}`;n in i&&(i[a]=i[n],delete i[n])}else{const n=`${_}${M(w,P)}`;n in i&&(i[a]=i[n],delete i[n])}const X=$===null||!($(A,a in i)instanceof Date)?n=>M([R(n)],l.None):n=>(m??(m={}),m.exp=$(A,a in i).getTime(),m.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ce),clearTimeout(ne[a]),ce=setTimeout(()=>this.reset(),m.exp-Date.now())),m.exp=Math.trunc(m.exp/1e3),M([R(n),m],l.None));if(L){const n=`${_}${K}`,d=R,j=z;if(R=C=>{try{return M([d(C)],L)}catch{return delete i[a],""}},n in i){const C=`${_}${M(w,P)}`;try{i[C]=X(z(W(i[n],l.None)[0])),delete i[n]}catch{}}z=C=>{try{return j(W(C,L)[0])}catch{return delete i[a],""}}}else delete i[`${J}${K}`];const ie=n=>{const d=W(n,l.None);return m=d[1],z(d[0])};let oe=!0;if(B[a]=A,i[`atom/${w}`]&&(i[a]||(i[a]=`[${i[`atom/${w}`]}]`),delete i[`atom/${w}`]),S=()=>{if(S=p,oe){oe=!1;try{f(a in i?ie(i[a]):t)}catch{console.warn("Invalid json value",i[a])}}return p()},x=n=>{if(n===t){this.reset();return}i[a]=X(n)},this.reset=()=>{delete i[a],y(t,!0)},D&&I[a]!==void 0&&console.warn("Duplicate Atom key",w),E)if(k){let n=!1,d;U[a]=this,I[a]=()=>{clearTimeout(d),d=setTimeout(()=>n=!1,10),!n&&(n=!0,i[a]=X(p()))}}else I[a]=n=>{if(n.newValue===null){this.reset();return}try{y(ie(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return A}}let H;try{H=new BroadcastChannel("updateHere"),H.addEventListener("message",e=>{var t;(t=U[e.data.key])==null||t.set(e.data.value,!0)})}catch{}const i=localStorage,I={},U={},we=(e,t)=>{throw`${t} is readonly property`};window.addEventListener("storage",e=>{var t;e.key===null||e.newValue===e.oldValue||(t=I[e.key])==null||t.call(I,e)});const Ae=i.setItem.bind(i),be=i.removeItem.bind(i);i.setItem=(e,t)=>{U[e]===void 0&&Ae.call(i,e,t)},i.removeItem=e=>{U[e]===void 0&&be.call(i,e)};const me=/"exp":\s*(\d+)/,_="atom\\",J="atom`s\\",B={},ne={},re=/[a-z]/gi,F=5,Q={};for(let e=54;e<80;e++){if(e===68||e===72||e===55)continue;const t=String.fromCharCode(e+43).toUpperCase(),c=String.fromCharCode(e+43).toLowerCase();Q[t]=c,Q[c]=t}const se=e=>Q[e]??e,M=(()=>{const e={[l.None]:t=>JSON.stringify(t),[l.Simple]:t=>btoa(encodeURI(e[l.None](t))),[l.Middle]:t=>{const c=e[l.Simple](t);return`${c.slice(0,F)}${c.slice(F).replace(re,se)}`},[l.Strong]:t=>btoa(e[l.Middle](t))};return(t,c)=>{try{return e[c](t)}catch(f){if(c===l.None)throw f;return e[l.None](t)}}})(),W=(()=>{const e={[l.None]:t=>JSON.parse(t),[l.Simple]:t=>e[l.None](decodeURI(atob(t))),[l.Middle]:t=>e[l.Simple](`${t.slice(0,F)}${t.slice(F).replace(re,se)}`),[l.Strong]:t=>e[l.Middle](atob(t))};return(t,c)=>{try{return e[c](t)}catch(f){if(c===l.None)throw f;return e[l.None](t)}}})();setTimeout(()=>{Object.keys(i).forEach(e=>{var f;if(typeof i[e]!="string"||!e.startsWith(_)&&!e.startsWith(J))return;const t=+((f=i[e].match(me))==null?void 0:f[1]);if(!t||t*1e3-Date.now()>24*60*60*1e3)return;const c=W(i[e],l.None);!Array.isArray(c)||c[1]==null||!("exp"in c[1])||c[1].exp!==t||(ne[e]=setTimeout(()=>{B[e]?B[e].reset():delete i[e]},t*1e3-Date.now()))})},1e3),h.Atom=te,h.atom=ye,h.configureAtomaric=le,h.configuredOptions=N,h.useAtom=ge,h.useAtomDo=de,h.useAtomGet=ae,h.useAtomSet=v,h.useAtomSetDeferred=fe,h.useAtomValue=Z,Object.defineProperty(h,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.61",
4
+ "version": "0.0.63",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
@@ -25,16 +25,24 @@
25
25
  "scripts": {
26
26
  "start": "vite --port 8378 --host",
27
27
  "build": "tsc && vite build",
28
- "preview": "vite preview"
28
+ "preview": "vite preview",
29
+ "test": "jest"
29
30
  },
30
31
  "devDependencies": {
32
+ "@testing-library/jest-dom": "^6.9.1",
33
+ "@testing-library/react": "^16.3.1",
34
+ "@testing-library/user-event": "^14.6.1",
35
+ "@types/jest": "^30.0.0",
31
36
  "@types/md5": "^2.3.5",
32
37
  "@types/node": "^22.15.1",
33
38
  "@types/react": "^19.1.2",
34
39
  "@types/react-dom": "^19.1.8",
35
40
  "@vitejs/plugin-react": "^4.7.0",
41
+ "jest": "^30.2.0",
42
+ "jest-environment-jsdom": "^30.2.0",
36
43
  "react": "^19.1.0",
37
44
  "react-dom": "^19.1.1",
45
+ "ts-jest": "^29.4.6",
38
46
  "vite": "^6.3.1",
39
47
  "vite-plugin-eslint": "^1.8.1"
40
48
  },
package/types/enums.ts ADDED
@@ -0,0 +1,6 @@
1
+ export const enum AtomSecureLevel {
2
+ None,
3
+ Simple,
4
+ Middle,
5
+ Strong,
6
+ }
package/types/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useSyncExternalStore } from 'react';
2
+ import { AtomSecureLevel } from './enums';
2
3
  import { Path, PathValue, PathValueDonor } from './paths';
3
4
 
4
5
  export interface Register {}
@@ -34,14 +35,16 @@ export type AtomOptions<Value, Actions extends Record<string, Function> = {}> =
34
35
  | {
35
36
  /** save in localStorage by this key */
36
37
  storeKey: AtomStoreKey;
38
+ securifyKeyLevel?: AtomSecureLevel;
39
+ securifyValueLevel?: AtomSecureLevel;
37
40
  }
38
41
  | {
39
42
  /** declare your custom actions */
40
43
  do: (
41
- set: (value: Value | ((value: Value) => Value), isPreventSave?: boolean) => void,
44
+ set: AtomSetMethod<Value>,
42
45
  get: () => Value,
43
46
  self: Atom<Value>,
44
- setDeferred: (value: Value | ((value: Value) => Value), debounceMs?: number, isPreventSave?: boolean) => void,
47
+ setDeferred: AtomSetDeferredMethod<Value>,
45
48
  ) => Actions;
46
49
  }
47
50
  );
@@ -175,4 +178,6 @@ export function atom<Value, Actions extends Record<string, Function> = {}>(
175
178
  export function configureAtomaric(options: {
176
179
  useSyncExternalStore: typeof useSyncExternalStore;
177
180
  keyPathSeparator: ObjectActionsSetDeepPartial;
181
+ securifyKeyLevel?: AtomSecureLevel;
182
+ securifyValueLevel?: AtomSecureLevel;
178
183
  }): void;