atomaric 0.0.37 → 0.0.39

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,237 +1,268 @@
1
- let M = () => {
1
+ let R = () => {
2
2
  throw "call configureAtomaric() before all!";
3
3
  };
4
- const $ = {}, v = (e) => {
5
- $.useSyncExternalStore = M = e.useSyncExternalStore, $.keyPathSeparator = e.keyPathSeparator;
6
- }, B = (e) => M(e.subscribe, e.get), G = (e) => e.set, K = (e) => e.setDeferred, O = (e) => e.get, ee = (e) => e.do, te = (e) => [B(e), G(e)], se = (e, r) => new q(e, r), U = (e, r, i) => {
7
- let h = null;
8
- typeof e == "number" ? h = j(
9
- r,
10
- (s) => ({
11
- increment: (n) => {
12
- s.set(+s.get() + (n ?? 0));
4
+ const V = {}, K = (e) => {
5
+ V.useSyncExternalStore = R = e.useSyncExternalStore, V.keyPathSeparator = e.keyPathSeparator;
6
+ }, U = (e) => R(e.subscribe, e.get), W = (e) => e.set, ee = (e) => e.setDeferred, te = (e) => e.get, re = (e) => e.do, ne = (e) => [U(e), W(e)], se = (e, s) => new Y(e, s), q = (e, s) => {
7
+ const i = (d, g, w) => new Proxy(d, {
8
+ get: (t, r, c) => {
9
+ const o = w === 0 && s.get != null ? s.get(t, r, c) : t[r];
10
+ return typeof o == "object" && o !== null ? i(
11
+ Array.isArray(o) ? o.slice(0) : { ...o },
12
+ g.concat(Array.isArray(t) ? +r : r),
13
+ w + 1
14
+ ) : o;
15
+ },
16
+ set: (t, r, c) => (s.onSet(t, g, r, c, t[r]) && (t[r] = c), !0)
17
+ });
18
+ return i(e, [], 0);
19
+ }, Q = (e, s, i) => {
20
+ let d = null;
21
+ typeof e == "number" ? d = j(
22
+ s,
23
+ (t) => ({
24
+ increment: (r) => {
25
+ t.set(+t.get() + (r ?? 0));
13
26
  }
14
27
  })
15
- ) : typeof e == "boolean" ? h = j(
16
- r,
17
- (s) => ({
28
+ ) : typeof e == "boolean" ? d = j(
29
+ s,
30
+ (t) => ({
18
31
  toggle: () => {
19
- s.set(!s.get());
32
+ t.set(!t.get());
20
33
  }
21
34
  })
22
- ) : Array.isArray(e) ? h = j(
23
- r,
24
- (s) => ({
25
- push: (...n) => {
26
- s.set(s.get().concat(n));
35
+ ) : Array.isArray(e) ? d = j(
36
+ s,
37
+ (t) => ({
38
+ push: (...r) => {
39
+ t.set(t.get().concat(r));
40
+ },
41
+ unshift: (...r) => {
42
+ t.set(r.concat(t.get()));
27
43
  },
28
- unshift: (...n) => {
29
- s.set(n.concat(s.get()));
44
+ update: (r) => {
45
+ const c = t.get(), o = M(c, r);
46
+ o !== c && t.set(o);
30
47
  },
31
- update: (n) => {
32
- const c = s.get().slice();
33
- n(c), s.set(c);
48
+ filter: (r) => {
49
+ t.set(t.get().filter(r ?? X));
34
50
  },
35
- filter: (n) => {
36
- s.set(s.get().filter(n ?? W));
51
+ remove: (r) => {
52
+ const c = t.get().indexOf(r);
53
+ if (c < 0) return;
54
+ const o = t.get().slice(0);
55
+ o.splice(c, 1), t.set(o);
37
56
  },
38
- toggle: (n, c) => {
39
- const p = s.get().slice(), a = p.indexOf(n);
40
- a < 0 ? c ? p.unshift(n) : p.push(n) : p.splice(a, 1), s.set(p);
57
+ toggle: (r, c) => {
58
+ const o = t.get().slice(), f = o.indexOf(r);
59
+ f < 0 ? c ? o.unshift(r) : o.push(r) : o.splice(f, 1), t.set(o);
41
60
  }
42
61
  })
43
- ) : e instanceof Set ? h = j(
44
- r,
45
- (s) => ({
46
- add: (n) => {
47
- s.set(new Set(s.get()).add(n));
62
+ ) : e instanceof Set ? d = j(
63
+ s,
64
+ (t) => ({
65
+ add: (r) => {
66
+ t.set(new Set(t.get()).add(r));
48
67
  },
49
- delete: (n) => {
50
- const c = new Set(s.get());
51
- c.delete(n), s.set(c);
68
+ delete: (r) => {
69
+ const c = new Set(t.get());
70
+ c.delete(r), t.set(c);
52
71
  },
53
- toggle: (n) => {
54
- const c = new Set(s.get());
55
- c.has(n) ? c.delete(n) : c.add(n), s.set(c);
72
+ toggle: (r) => {
73
+ const c = new Set(t.get());
74
+ c.has(r) ? c.delete(r) : c.add(r), t.set(c);
56
75
  },
57
76
  clear: () => {
58
- s.set(/* @__PURE__ */ new Set());
59
- },
60
- update: (n) => {
61
- const c = new Set(s.get());
62
- n(c), s.set(c);
77
+ t.set(/* @__PURE__ */ new Set());
63
78
  }
64
79
  })
65
- ) : e instanceof Object && (h = j(
66
- r,
67
- (s) => ({
68
- setPartial: (n) => s.set((c) => ({
80
+ ) : e instanceof Object && (d = j(
81
+ s,
82
+ (t) => ({
83
+ setPartial: (r) => t.set((c) => ({
69
84
  ...c,
70
- ...typeof n == "function" ? n(s.get()) : n
85
+ ...typeof r == "function" ? r(t.get()) : r
71
86
  })),
72
- update: (n) => {
73
- const c = { ...s.get() };
74
- n(c), s.set(c);
87
+ update: (r) => {
88
+ const c = t.get(), o = M(c, r);
89
+ o !== c && t.set(o);
75
90
  },
76
- setDeepPartial: (n, c, p, a = $.keyPathSeparator ?? ".") => {
77
- if (n.includes(a)) {
78
- let d = n.split(a);
79
- const T = d[d.length - 1];
80
- d = d.slice(0, -1);
81
- const b = { ...s.get() };
82
- let g = b, x = p;
83
- for (const w of d) {
84
- let f = g[w];
85
- const _ = x = x == null ? void 0 : x[Array.isArray(x) ? "0" : w];
86
- if (f == null && (f = Array.isArray(_) ? [] : {}), f == null || typeof f != "object") {
87
- s.do.setPartial({ [n]: typeof c == "function" ? c(void 0) : c });
91
+ setDeepPartial: (r, c, o, f = V.keyPathSeparator ?? ".") => {
92
+ if (r.includes(f)) {
93
+ let h = r.split(f);
94
+ const b = h[h.length - 1];
95
+ h = h.slice(0, -1);
96
+ const y = { ...t.get() };
97
+ let A = y, D = o;
98
+ for (const S of h) {
99
+ let p = A[S];
100
+ const T = D = D == null ? void 0 : D[Array.isArray(D) ? "0" : S];
101
+ if (p == null && (p = Array.isArray(T) ? [] : {}), p == null || typeof p != "object") {
102
+ t.do.setPartial({ [r]: typeof c == "function" ? c(void 0) : c });
88
103
  return;
89
104
  }
90
- g = g[w] = Array.isArray(f) ? [...f] : { ...f };
105
+ A = A[S] = Array.isArray(p) ? [...p] : { ...p };
91
106
  }
92
- g[T] = typeof c == "function" ? c(g[T]) : c, s.set(b);
93
- } else s.do.setPartial({ [n]: c });
107
+ A[b] = typeof c == "function" ? c(A[b]) : c, t.set(y);
108
+ } else t.do.setPartial({ [r]: c });
94
109
  }
95
110
  })
96
111
  ));
97
- const S = typeof i == "object" && i != null && "do" in i ? i.do(
98
- (s, n) => r.set(s, n),
99
- () => r.get(),
100
- r,
101
- (s, n, c) => r.setDeferred(s, n, c)
102
- ) : null, A = {};
103
- return S && Object.keys(S).forEach((s) => Object.defineProperty(A, s, { get: () => S[s] })), h && Object.keys(h).forEach(
104
- (s) => Object.defineProperty(A, s, { get: () => h[s] })
105
- ), A;
106
- }, W = (e) => e, j = (e, r, i) => r(e);
107
- class q {
108
- constructor(r, i) {
109
- const h = (t) => n = t, S = () => n, A = /* @__PURE__ */ new Set(), s = (t) => t(a());
110
- let n = r, c, p = () => {
111
- }, a = () => S(), d = null, T = () => {
112
- const t = U(r, b, i);
113
- return T = () => t, t;
112
+ const g = typeof i == "object" && i != null && "do" in i ? i.do(
113
+ (t, r) => s.set(t, r),
114
+ () => s.get(),
115
+ s,
116
+ (t, r, c) => s.setDeferred(t, r, c)
117
+ ) : null, w = {};
118
+ return g && Object.keys(g).forEach((t) => Object.defineProperty(w, t, { get: () => g[t] })), d && Object.keys(d).forEach(
119
+ (t) => Object.defineProperty(w, t, { get: () => d[t] })
120
+ ), w;
121
+ }, X = (e) => e, j = (e, s, i) => s(e), M = (e, s) => {
122
+ const i = Array.isArray(e) ? e.slice(0) : { ...e };
123
+ let d = !1;
124
+ const g = q(e, {
125
+ onSet: (w, t, r, c, o) => {
126
+ if (c === o) return !0;
127
+ let f = i;
128
+ d = !0;
129
+ for (const h of t) {
130
+ const b = f[h];
131
+ f = f[h] = Array.isArray(b) ? b.slice(0) : { ...b };
132
+ }
133
+ return f[r] = c, !0;
134
+ }
135
+ });
136
+ return s(g), d ? i : e;
137
+ };
138
+ class Y {
139
+ constructor(s, i) {
140
+ const d = (n) => r = n, g = () => r, w = /* @__PURE__ */ new Set(), t = (n) => n(f());
141
+ let r = s, c, o = () => {
142
+ }, f = () => g(), h = null, b = () => {
143
+ const n = Q(s, y, i);
144
+ return b = () => n, n;
114
145
  };
115
- const b = new Proxy(this, {
116
- get: (t, u) => u === "do" ? T() : t[u],
117
- set: Q
118
- }), g = (t, u) => {
119
- const y = typeof t == "function" ? t(a()) : t;
120
- if (!(y === a() || y === void 0 || typeof y == "number" && isNaN(y))) {
121
- h(y), A.forEach(s, this);
146
+ const y = new Proxy(this, {
147
+ get: (n, a) => a === "do" ? b() : n[a],
148
+ set: Z
149
+ }), A = (n, a) => {
150
+ const x = typeof n == "function" ? n(f()) : n;
151
+ if (!(x === f() || x === void 0 || typeof x == "number" && isNaN(x))) {
152
+ d(x), w.forEach(t, this);
122
153
  try {
123
- N.postMessage({ key: l, value: S() });
154
+ $.postMessage({ key: u, value: g() });
124
155
  } catch {
125
156
  }
126
- u !== !0 && p(y);
157
+ a !== !0 && o(x);
127
158
  }
128
159
  };
129
- this.set = (t, u) => g(t, u), this.get = () => a(), this.initialValue = r, this.isInitialValue = () => r === S(), this.subscribe = (t) => (A.add(t), () => {
130
- A.delete(t);
160
+ this.set = (n, a) => A(n, a), this.get = () => f(), this.initialValue = s, this.isInitialValue = () => s === g(), this.subscribe = (n) => (w.add(n), () => {
161
+ w.delete(n);
131
162
  }), this.reset = () => {
132
- g(r, !0), A.forEach(s, this);
163
+ A(s, !0), w.forEach(t, this);
133
164
  };
134
- const x = (t, u) => {
135
- g(t, u), c = void 0;
165
+ const D = (n, a) => {
166
+ A(n, a), c = void 0;
136
167
  };
137
- if (this.setDeferred = (t, u = 500, y, L = !0) => {
138
- L && c === void 0 && g(t, y), clearTimeout(c), c = setTimeout(x, u, t, y);
139
- }, i == null) return b;
140
- let w = null, f = null, _ = !0, E = !0, P = !1, V = -1, C = r instanceof Set ? (t) => new Set(t) : (t) => t, m = r instanceof Set ? (t) => {
141
- if (t instanceof Set) return Array.from(t);
142
- throw console.error(t), "The value is not Set instance";
143
- } : (t) => t;
168
+ if (this.setDeferred = (n, a = 500, x, L = !0) => {
169
+ L && c === void 0 && A(n, x), clearTimeout(c), c = setTimeout(D, a, n, x);
170
+ }, i == null) return y;
171
+ let S = null, p = null, T = !0, P = !0, E = !1, z = -1, C = s instanceof Set ? (n) => new Set(n) : (n) => n, m = s instanceof Set ? (n) => {
172
+ if (n instanceof Set) return Array.from(n);
173
+ throw console.error(n), "The value is not Set instance";
174
+ } : (n) => n;
144
175
  if (typeof i == "string")
145
- w = i;
176
+ S = i;
146
177
  else if ("storeKey" in i)
147
- _ = i.warnOnDuplicateStoreKey ?? _, E = i.listenStorageChanges ?? E, w = i.storeKey, C = i.unzipValue ?? C, m = i.zipValue ?? m, P = i.unchangable ?? P, f = i.exp ?? f;
148
- else return b;
149
- const l = `${R}${w}`, F = f === null || !(f(b, l in o) instanceof Date) ? (t) => JSON.stringify([m(t)]) : (t) => (d ?? (d = {}), d.exp = f(b, l in o).getTime() + 0.2866, d.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(V), clearTimeout(k[l]), V = setTimeout(() => this.reset(), d.exp - Date.now())), JSON.stringify([m(t), d])), J = (t) => {
150
- const u = JSON.parse(t);
151
- return d = u[1], C(u[0]);
178
+ T = i.warnOnDuplicateStoreKey ?? T, P = i.listenStorageChanges ?? P, S = i.storeKey, C = i.unzipValue ?? C, m = i.zipValue ?? m, E = i.unchangable ?? E, p = i.exp ?? p;
179
+ else return y;
180
+ const u = `${B}${S}`, F = p === null || !(p(y, u in l) instanceof Date) ? (n) => JSON.stringify([m(n)]) : (n) => (h ?? (h = {}), h.exp = p(y, u in l).getTime() + 0.2866, h.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(z), clearTimeout(G[u]), z = setTimeout(() => this.reset(), h.exp - Date.now())), JSON.stringify([m(n), h])), J = (n) => {
181
+ const a = JSON.parse(n);
182
+ return h = a[1], C(a[0]);
152
183
  };
153
184
  let H = !0;
154
- if (z[l] = b, o[`atom/${w}`] && (o[l] || (o[l] = `[${o[`atom/${w}`]}]`), delete o[`atom/${w}`]), a = () => {
155
- if (a = S, H) {
185
+ if (N[u] = y, l[`atom/${S}`] && (l[u] || (l[u] = `[${l[`atom/${S}`]}]`), delete l[`atom/${S}`]), f = () => {
186
+ if (f = g, H) {
156
187
  H = !1;
157
188
  try {
158
- h(l in o ? J(o[l]) : r);
189
+ d(u in l ? J(l[u]) : s);
159
190
  } catch {
160
- console.warn("Invalid json value", o[l]);
191
+ console.warn("Invalid json value", l[u]);
161
192
  }
162
193
  }
163
- return S();
164
- }, p = (t) => {
165
- if (t === r) {
194
+ return g();
195
+ }, o = (n) => {
196
+ if (n === s) {
166
197
  this.reset();
167
198
  return;
168
199
  }
169
- o[l] = F(t);
200
+ l[u] = F(n);
170
201
  }, this.reset = () => {
171
- delete o[l], g(r, !0);
172
- }, _ && D[l] !== void 0 && console.warn("Duplicate Atom key", w), E)
173
- if (P) {
174
- let t = !1, u;
175
- I[l] = this, D[l] = () => {
176
- clearTimeout(u), u = setTimeout(() => t = !1, 10), !t && (t = !0, o[l] = F(S()));
202
+ delete l[u], A(s, !0);
203
+ }, T && _[u] !== void 0 && console.warn("Duplicate Atom key", S), P)
204
+ if (E) {
205
+ let n = !1, a;
206
+ I[u] = this, _[u] = () => {
207
+ clearTimeout(a), a = setTimeout(() => n = !1, 10), !n && (n = !0, l[u] = F(g()));
177
208
  };
178
209
  } else
179
- D[l] = (t) => {
180
- if (t.newValue === null) {
210
+ _[u] = (n) => {
211
+ if (n.newValue === null) {
181
212
  this.reset();
182
213
  return;
183
214
  }
184
215
  try {
185
- g(J(t.newValue));
216
+ A(J(n.newValue));
186
217
  } catch {
187
- console.warn("Invalid json value", t.newValue);
218
+ console.warn("Invalid json value", n.newValue);
188
219
  }
189
220
  };
190
- return b;
221
+ return y;
191
222
  }
192
223
  }
193
- let N;
224
+ let $;
194
225
  try {
195
- N = new BroadcastChannel("updateHere"), N.addEventListener("message", (e) => {
196
- var r;
197
- (r = I[e.data.key]) == null || r.set(e.data.value, !0);
226
+ $ = new BroadcastChannel("updateHere"), $.addEventListener("message", (e) => {
227
+ var s;
228
+ (s = I[e.data.key]) == null || s.set(e.data.value, !0);
198
229
  });
199
230
  } catch {
200
231
  }
201
- const o = window.localStorage, D = {}, I = {}, Q = (e, r) => {
202
- throw `${r} is readonly property`;
232
+ const l = window.localStorage, _ = {}, I = {}, Z = (e, s) => {
233
+ throw `${s} is readonly property`;
203
234
  };
204
235
  window.addEventListener("storage", (e) => {
205
- var r;
206
- e.key === null || e.newValue === e.oldValue || (r = D[e.key]) == null || r.call(D, e);
236
+ var s;
237
+ e.key === null || e.newValue === e.oldValue || (s = _[e.key]) == null || s.call(_, e);
207
238
  });
208
- const X = o.setItem.bind(o), Y = o.removeItem.bind(o);
209
- o.setItem = (e, r) => {
210
- I[e] === void 0 && X.call(o, e, r);
239
+ const v = l.setItem.bind(l), k = l.removeItem.bind(l);
240
+ l.setItem = (e, s) => {
241
+ I[e] === void 0 && v.call(l, e, s);
211
242
  };
212
- o.removeItem = (e) => {
213
- I[e] === void 0 && Y.call(o, e);
243
+ l.removeItem = (e) => {
244
+ I[e] === void 0 && k.call(l, e);
214
245
  };
215
- const Z = /"exp":(\d+)\.2866/, R = "atom\\", z = {}, k = {};
246
+ const O = /"exp":(\d+)\.2866/, B = "atom\\", N = {}, G = {};
216
247
  setTimeout(() => {
217
- Object.keys(o).forEach((e) => {
248
+ Object.keys(l).forEach((e) => {
218
249
  var i;
219
- if (!e.startsWith(R) || typeof o[e] != "string") return;
220
- const r = +((i = o[e].match(Z)) == null ? void 0 : i[1]);
221
- r && r - Date.now() < 24 * 60 * 60 * 1e3 && (k[e] = setTimeout(() => {
222
- z[e] ? z[e].reset() : delete o[e];
223
- }, r - Date.now()));
250
+ if (!e.startsWith(B) || typeof l[e] != "string") return;
251
+ const s = +((i = l[e].match(O)) == null ? void 0 : i[1]);
252
+ s && s - Date.now() < 24 * 60 * 60 * 1e3 && (G[e] = setTimeout(() => {
253
+ N[e] ? N[e].reset() : delete l[e];
254
+ }, s - Date.now()));
224
255
  });
225
256
  }, 1e3);
226
257
  export {
227
- q as Atom,
258
+ Y as Atom,
228
259
  se as atom,
229
- v as configureAtomaric,
230
- $ as configuredOptions,
231
- te as useAtom,
232
- ee as useAtomDo,
233
- O as useAtomGet,
234
- G as useAtomSet,
235
- K as useAtomSetDeferred,
236
- B as useAtomValue
260
+ K as configureAtomaric,
261
+ V as configuredOptions,
262
+ ne as useAtom,
263
+ re as useAtomDo,
264
+ te as useAtomGet,
265
+ W as useAtomSet,
266
+ ee as useAtomSetDeferred,
267
+ U as useAtomValue
237
268
  };
@@ -1 +1 @@
1
- (function(f,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(f=typeof globalThis<"u"?globalThis:f||self,D(f.atomaric={}))})(this,function(f){"use strict";let D=()=>{throw"call configureAtomaric() before all!"};const P={},q=e=>{P.useSyncExternalStore=D=e.useSyncExternalStore,P.keyPathSeparator=e.keyPathSeparator},J=e=>D(e.subscribe,e.get),M=e=>e.set,Q=e=>e.setDeferred,X=e=>e.get,Y=e=>e.do,Z=e=>[J(e),M(e)],v=(e,r)=>new G(e,r),K=(e,r,i)=>{let S=null;typeof e=="number"?S=_(r,n=>({increment:s=>{n.set(+n.get()+(s??0))}})):typeof e=="boolean"?S=_(r,n=>({toggle:()=>{n.set(!n.get())}})):Array.isArray(e)?S=_(r,n=>({push:(...s)=>{n.set(n.get().concat(s))},unshift:(...s)=>{n.set(s.concat(n.get()))},update:s=>{const c=n.get().slice();s(c),n.set(c)},filter:s=>{n.set(n.get().filter(s??O))},toggle:(s,c)=>{const y=n.get().slice(),d=y.indexOf(s);d<0?c?y.unshift(s):y.push(s):y.splice(d,1),n.set(y)}})):e instanceof Set?S=_(r,n=>({add:s=>{n.set(new Set(n.get()).add(s))},delete:s=>{const c=new Set(n.get());c.delete(s),n.set(c)},toggle:s=>{const c=new Set(n.get());c.has(s)?c.delete(s):c.add(s),n.set(c)},clear:()=>{n.set(new Set)},update:s=>{const c=new Set(n.get());s(c),n.set(c)}})):e instanceof Object&&(S=_(r,n=>({setPartial:s=>n.set(c=>({...c,...typeof s=="function"?s(n.get()):s})),update:s=>{const c={...n.get()};s(c),n.set(c)},setDeepPartial:(s,c,y,d=P.keyPathSeparator??".")=>{if(s.includes(d)){let g=s.split(d);const I=g[g.length-1];g=g.slice(0,-1);const b={...n.get()};let h=b,T=y;for(const w of g){let a=h[w];const E=T=T==null?void 0:T[Array.isArray(T)?"0":w];if(a==null&&(a=Array.isArray(E)?[]:{}),a==null||typeof a!="object"){n.do.setPartial({[s]:typeof c=="function"?c(void 0):c});return}h=h[w]=Array.isArray(a)?[...a]:{...a}}h[I]=typeof c=="function"?c(h[I]):c,n.set(b)}else n.do.setPartial({[s]:c})}})));const A=typeof i=="object"&&i!=null&&"do"in i?i.do((n,s)=>r.set(n,s),()=>r.get(),r,(n,s,c)=>r.setDeferred(n,s,c)):null,m={};return A&&Object.keys(A).forEach(n=>Object.defineProperty(m,n,{get:()=>A[n]})),S&&Object.keys(S).forEach(n=>Object.defineProperty(m,n,{get:()=>S[n]})),m},O=e=>e,_=(e,r,i)=>r(e);class G{constructor(r,i){const S=t=>s=t,A=()=>s,m=new Set,n=t=>t(d());let s=r,c,y=()=>{},d=()=>A(),g=null,I=()=>{const t=K(r,b,i);return I=()=>t,t};const b=new Proxy(this,{get:(t,u)=>u==="do"?I():t[u],set:ee}),h=(t,u)=>{const p=typeof t=="function"?t(d()):t;if(!(p===d()||p===void 0||typeof p=="number"&&isNaN(p))){S(p),m.forEach(n,this);try{$.postMessage({key:l,value:A()})}catch{}u!==!0&&y(p)}};this.set=(t,u)=>h(t,u),this.get=()=>d(),this.initialValue=r,this.isInitialValue=()=>r===A(),this.subscribe=t=>(m.add(t),()=>{m.delete(t)}),this.reset=()=>{h(r,!0),m.forEach(n,this)};const T=(t,u)=>{h(t,u),c=void 0};if(this.setDeferred=(t,u=500,p,W=!0)=>{W&&c===void 0&&h(t,p),clearTimeout(c),c=setTimeout(T,u,t,p)},i==null)return b;let w=null,a=null,E=!0,V=!0,z=!1,R=-1,F=r instanceof Set?t=>new Set(t):t=>t,C=r instanceof Set?t=>{if(t instanceof Set)return Array.from(t);throw console.error(t),"The value is not Set instance"}:t=>t;if(typeof i=="string")w=i;else if("storeKey"in i)E=i.warnOnDuplicateStoreKey??E,V=i.listenStorageChanges??V,w=i.storeKey,F=i.unzipValue??F,C=i.zipValue??C,z=i.unchangable??z,a=i.exp??a;else return b;const l=`${H}${w}`,k=a===null||!(a(b,l in o)instanceof Date)?t=>JSON.stringify([C(t)]):t=>(g??(g={}),g.exp=a(b,l in o).getTime()+.2866,g.exp-Date.now()<24*60*60*1e3&&(clearTimeout(R),clearTimeout(L[l]),R=setTimeout(()=>this.reset(),g.exp-Date.now())),JSON.stringify([C(t),g])),B=t=>{const u=JSON.parse(t);return g=u[1],F(u[0])};let U=!0;if(N[l]=b,o[`atom/${w}`]&&(o[l]||(o[l]=`[${o[`atom/${w}`]}]`),delete o[`atom/${w}`]),d=()=>{if(d=A,U){U=!1;try{S(l in o?B(o[l]):r)}catch{console.warn("Invalid json value",o[l])}}return A()},y=t=>{if(t===r){this.reset();return}o[l]=k(t)},this.reset=()=>{delete o[l],h(r,!0)},E&&j[l]!==void 0&&console.warn("Duplicate Atom key",w),V)if(z){let t=!1,u;x[l]=this,j[l]=()=>{clearTimeout(u),u=setTimeout(()=>t=!1,10),!t&&(t=!0,o[l]=k(A()))}}else j[l]=t=>{if(t.newValue===null){this.reset();return}try{h(B(t.newValue))}catch{console.warn("Invalid json value",t.newValue)}};return b}}let $;try{$=new BroadcastChannel("updateHere"),$.addEventListener("message",e=>{var r;(r=x[e.data.key])==null||r.set(e.data.value,!0)})}catch{}const o=window.localStorage,j={},x={},ee=(e,r)=>{throw`${r} is readonly property`};window.addEventListener("storage",e=>{var r;e.key===null||e.newValue===e.oldValue||(r=j[e.key])==null||r.call(j,e)});const te=o.setItem.bind(o),ne=o.removeItem.bind(o);o.setItem=(e,r)=>{x[e]===void 0&&te.call(o,e,r)},o.removeItem=e=>{x[e]===void 0&&ne.call(o,e)};const se=/"exp":(\d+)\.2866/,H="atom\\",N={},L={};setTimeout(()=>{Object.keys(o).forEach(e=>{var i;if(!e.startsWith(H)||typeof o[e]!="string")return;const r=+((i=o[e].match(se))==null?void 0:i[1]);r&&r-Date.now()<24*60*60*1e3&&(L[e]=setTimeout(()=>{N[e]?N[e].reset():delete o[e]},r-Date.now()))})},1e3),f.Atom=G,f.atom=v,f.configureAtomaric=q,f.configuredOptions=P,f.useAtom=Z,f.useAtomDo=Y,f.useAtomGet=X,f.useAtomSet=M,f.useAtomSetDeferred=Q,f.useAtomValue=J,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(g,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(g=typeof globalThis<"u"?globalThis:g||self,j(g.atomaric={}))})(this,function(g){"use strict";let j=()=>{throw"call configureAtomaric() before all!"};const I={},Q=e=>{I.useSyncExternalStore=j=e.useSyncExternalStore,I.keyPathSeparator=e.keyPathSeparator},J=e=>j(e.subscribe,e.get),M=e=>e.set,X=e=>e.setDeferred,Y=e=>e.get,Z=e=>e.do,k=e=>[J(e),M(e)],O=(e,r)=>new H(e,r),K=(e,r)=>{const i=(d,h,w)=>new Proxy(d,{get:(t,n,c)=>{const o=w===0&&r.get!=null?r.get(t,n,c):t[n];return typeof o=="object"&&o!==null?i(Array.isArray(o)?o.slice(0):{...o},h.concat(Array.isArray(t)?+n:n),w+1):o},set:(t,n,c)=>(r.onSet(t,h,n,c,t[n])&&(t[n]=c),!0)});return i(e,[],0)},ee=(e,r,i)=>{let d=null;typeof e=="number"?d=x(r,t=>({increment:n=>{t.set(+t.get()+(n??0))}})):typeof e=="boolean"?d=x(r,t=>({toggle:()=>{t.set(!t.get())}})):Array.isArray(e)?d=x(r,t=>({push:(...n)=>{t.set(t.get().concat(n))},unshift:(...n)=>{t.set(n.concat(t.get()))},update:n=>{const c=t.get(),o=G(c,n);o!==c&&t.set(o)},filter:n=>{t.set(t.get().filter(n??te))},remove:n=>{const c=t.get().indexOf(n);if(c<0)return;const o=t.get().slice(0);o.splice(c,1),t.set(o)},toggle:(n,c)=>{const o=t.get().slice(),f=o.indexOf(n);f<0?c?o.unshift(n):o.push(n):o.splice(f,1),t.set(o)}})):e instanceof Set?d=x(r,t=>({add:n=>{t.set(new Set(t.get()).add(n))},delete:n=>{const c=new Set(t.get());c.delete(n),t.set(c)},toggle:n=>{const c=new Set(t.get());c.has(n)?c.delete(n):c.add(n),t.set(c)},clear:()=>{t.set(new Set)}})):e instanceof Object&&(d=x(r,t=>({setPartial:n=>t.set(c=>({...c,...typeof n=="function"?n(t.get()):n})),update:n=>{const c=t.get(),o=G(c,n);o!==c&&t.set(o)},setDeepPartial:(n,c,o,f=I.keyPathSeparator??".")=>{if(n.includes(f)){let A=n.split(f);const m=A[A.length-1];A=A.slice(0,-1);const b={...t.get()};let y=b,T=o;for(const p of A){let S=y[p];const P=T=T==null?void 0:T[Array.isArray(T)?"0":p];if(S==null&&(S=Array.isArray(P)?[]:{}),S==null||typeof S!="object"){t.do.setPartial({[n]:typeof c=="function"?c(void 0):c});return}y=y[p]=Array.isArray(S)?[...S]:{...S}}y[m]=typeof c=="function"?c(y[m]):c,t.set(b)}else t.do.setPartial({[n]:c})}})));const h=typeof i=="object"&&i!=null&&"do"in i?i.do((t,n)=>r.set(t,n),()=>r.get(),r,(t,n,c)=>r.setDeferred(t,n,c)):null,w={};return h&&Object.keys(h).forEach(t=>Object.defineProperty(w,t,{get:()=>h[t]})),d&&Object.keys(d).forEach(t=>Object.defineProperty(w,t,{get:()=>d[t]})),w},te=e=>e,x=(e,r,i)=>r(e),G=(e,r)=>{const i=Array.isArray(e)?e.slice(0):{...e};let d=!1;const h=K(e,{onSet:(w,t,n,c,o)=>{if(c===o)return!0;let f=i;d=!0;for(const A of t){const m=f[A];f=f[A]=Array.isArray(m)?m.slice(0):{...m}}return f[n]=c,!0}});return r(h),d?i:e};class H{constructor(r,i){const d=s=>n=s,h=()=>n,w=new Set,t=s=>s(f());let n=r,c,o=()=>{},f=()=>h(),A=null,m=()=>{const s=ee(r,b,i);return m=()=>s,s};const b=new Proxy(this,{get:(s,a)=>a==="do"?m():s[a],set:ne}),y=(s,a)=>{const D=typeof s=="function"?s(f()):s;if(!(D===f()||D===void 0||typeof D=="number"&&isNaN(D))){d(D),w.forEach(t,this);try{C.postMessage({key:l,value:h()})}catch{}a!==!0&&o(D)}};this.set=(s,a)=>y(s,a),this.get=()=>f(),this.initialValue=r,this.isInitialValue=()=>r===h(),this.subscribe=s=>(w.add(s),()=>{w.delete(s)}),this.reset=()=>{y(r,!0),w.forEach(t,this)};const T=(s,a)=>{y(s,a),c=void 0};if(this.setDeferred=(s,a=500,D,v=!0)=>{v&&c===void 0&&y(s,D),clearTimeout(c),c=setTimeout(T,a,s,D)},i==null)return b;let p=null,S=null,P=!0,N=!0,z=!1,B=-1,F=r instanceof Set?s=>new Set(s):s=>s,V=r instanceof Set?s=>{if(s instanceof Set)return Array.from(s);throw console.error(s),"The value is not Set instance"}:s=>s;if(typeof i=="string")p=i;else if("storeKey"in i)P=i.warnOnDuplicateStoreKey??P,N=i.listenStorageChanges??N,p=i.storeKey,F=i.unzipValue??F,V=i.zipValue??V,z=i.unchangable??z,S=i.exp??S;else return b;const l=`${L}${p}`,U=S===null||!(S(b,l in u)instanceof Date)?s=>JSON.stringify([V(s)]):s=>(A??(A={}),A.exp=S(b,l in u).getTime()+.2866,A.exp-Date.now()<24*60*60*1e3&&(clearTimeout(B),clearTimeout(R[l]),B=setTimeout(()=>this.reset(),A.exp-Date.now())),JSON.stringify([V(s),A])),W=s=>{const a=JSON.parse(s);return A=a[1],F(a[0])};let q=!0;if($[l]=b,u[`atom/${p}`]&&(u[l]||(u[l]=`[${u[`atom/${p}`]}]`),delete u[`atom/${p}`]),f=()=>{if(f=h,q){q=!1;try{d(l in u?W(u[l]):r)}catch{console.warn("Invalid json value",u[l])}}return h()},o=s=>{if(s===r){this.reset();return}u[l]=U(s)},this.reset=()=>{delete u[l],y(r,!0)},P&&_[l]!==void 0&&console.warn("Duplicate Atom key",p),N)if(z){let s=!1,a;E[l]=this,_[l]=()=>{clearTimeout(a),a=setTimeout(()=>s=!1,10),!s&&(s=!0,u[l]=U(h()))}}else _[l]=s=>{if(s.newValue===null){this.reset();return}try{y(W(s.newValue))}catch{console.warn("Invalid json value",s.newValue)}};return b}}let C;try{C=new BroadcastChannel("updateHere"),C.addEventListener("message",e=>{var r;(r=E[e.data.key])==null||r.set(e.data.value,!0)})}catch{}const u=window.localStorage,_={},E={},ne=(e,r)=>{throw`${r} is readonly property`};window.addEventListener("storage",e=>{var r;e.key===null||e.newValue===e.oldValue||(r=_[e.key])==null||r.call(_,e)});const se=u.setItem.bind(u),re=u.removeItem.bind(u);u.setItem=(e,r)=>{E[e]===void 0&&se.call(u,e,r)},u.removeItem=e=>{E[e]===void 0&&re.call(u,e)};const ce=/"exp":(\d+)\.2866/,L="atom\\",$={},R={};setTimeout(()=>{Object.keys(u).forEach(e=>{var i;if(!e.startsWith(L)||typeof u[e]!="string")return;const r=+((i=u[e].match(ce))==null?void 0:i[1]);r&&r-Date.now()<24*60*60*1e3&&(R[e]=setTimeout(()=>{$[e]?$[e].reset():delete u[e]},r-Date.now()))})},1e3),g.Atom=H,g.atom=O,g.configureAtomaric=Q,g.configuredOptions=I,g.useAtom=k,g.useAtomDo=Z,g.useAtomGet=Y,g.useAtomSet=M,g.useAtomSetDeferred=X,g.useAtomValue=J,Object.defineProperty(g,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.37",
4
+ "version": "0.0.39",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
package/types/index.d.ts CHANGED
@@ -89,7 +89,7 @@ export type BooleanActions = {
89
89
  toggle: () => void;
90
90
  };
91
91
 
92
- export type SetActions<Value> = UpdateAction<Value> & {
92
+ export type SetActions<Value> = {
93
93
  /** like the Set.prototype.add() method */
94
94
  add: (value: Value) => void;
95
95
  /** like the Set.prototype.delete() method */
@@ -109,6 +109,8 @@ export type ArrayActions<Value> = UpdateAction<Value[]> & {
109
109
  filter: (filter?: (value: Value, index: number, array: Value[]) => any) => void;
110
110
  /** will add value if it doesn't exist, otherwise delete */
111
111
  toggle: (value: Value, isAddInStart?: boolean) => void;
112
+ /** will delete item from array */
113
+ remove: (value: Value) => void;
112
114
  };
113
115
 
114
116
  export type DefaultActions<Value> = Value extends Set<infer Val>