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