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