atomaric 0.0.79 → 0.0.82
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 +304 -301
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +27 -20
package/build/atomaric.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
let
|
|
1
|
+
let Ye = () => {
|
|
2
2
|
throw "call configureAtomaric() before all!";
|
|
3
3
|
};
|
|
4
4
|
const T = {}, Ot = (e) => {
|
|
5
|
-
T.useSyncExternalStore =
|
|
6
|
-
},
|
|
5
|
+
T.useSyncExternalStore = Ye = e.useSyncExternalStore, T.keyPathSeparator = e.keyPathSeparator, T.securifyKeyLevel = e.securifyKeyLevel, T.securifyValueLevel = e.securifyValueLevel;
|
|
6
|
+
}, lt = (e) => Ye(e.subscribe, e.get), dt = (e) => e.set, Bt = (e) => e.setDeferred, Wt = (e) => e.get, qt = (e) => e.do, Gt = (e) => [lt(e), dt(e)], Ht = (e, t) => new kt(e, t);
|
|
7
7
|
class F {
|
|
8
8
|
constructor(t) {
|
|
9
9
|
if (t)
|
|
@@ -12,7 +12,7 @@ class F {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
var
|
|
15
|
+
var Qe = Symbol.for("immer-nothing"), Ue = Symbol.for("immer-draftable"), p = Symbol.for("immer-state"), ht = process.env.NODE_ENV !== "production" ? [
|
|
16
16
|
// All error codes, starting by 0:
|
|
17
17
|
function(e) {
|
|
18
18
|
return `The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`;
|
|
@@ -45,117 +45,117 @@ var Ye = Symbol.for("immer-nothing"), Ve = Symbol.for("immer-draftable"), m = Sy
|
|
|
45
45
|
] : [];
|
|
46
46
|
function g(e, ...t) {
|
|
47
47
|
if (process.env.NODE_ENV !== "production") {
|
|
48
|
-
const r =
|
|
48
|
+
const r = ht[e], n = v(r) ? r.apply(null, t) : r;
|
|
49
49
|
throw new Error(`[Immer] ${n}`);
|
|
50
50
|
}
|
|
51
51
|
throw new Error(
|
|
52
52
|
`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
var w = Object,
|
|
55
|
+
var w = Object, O = w.getPrototypeOf, Z = "constructor", oe = "prototype", Pe = "configurable", ee = "enumerable", Y = "writable", W = "value", M = (e) => !!e && !!e[p];
|
|
56
56
|
function C(e) {
|
|
57
57
|
var t;
|
|
58
|
-
return e ?
|
|
58
|
+
return e ? Xe(e) || ae(e) || !!e[Ue] || !!((t = e[Z]) != null && t[Ue]) || ue(e) || fe(e) : !1;
|
|
59
59
|
}
|
|
60
|
-
var
|
|
61
|
-
function
|
|
62
|
-
if (!e || !
|
|
60
|
+
var _t = w[oe][Z].toString(), je = /* @__PURE__ */ new WeakMap();
|
|
61
|
+
function Xe(e) {
|
|
62
|
+
if (!e || !Fe(e))
|
|
63
63
|
return !1;
|
|
64
|
-
const t =
|
|
65
|
-
if (t === null || t === w[
|
|
64
|
+
const t = O(e);
|
|
65
|
+
if (t === null || t === w[oe])
|
|
66
66
|
return !0;
|
|
67
|
-
const r = w.hasOwnProperty.call(t,
|
|
67
|
+
const r = w.hasOwnProperty.call(t, Z) && t[Z];
|
|
68
68
|
if (r === Object)
|
|
69
69
|
return !0;
|
|
70
70
|
if (!v(r))
|
|
71
71
|
return !1;
|
|
72
|
-
let n =
|
|
73
|
-
return n === void 0 && (n = Function.toString.call(r),
|
|
72
|
+
let n = je.get(r);
|
|
73
|
+
return n === void 0 && (n = Function.toString.call(r), je.set(r, n)), n === _t;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
75
|
+
function ce(e, t, r = !0) {
|
|
76
|
+
H(e) === 0 ? (r ? Reflect.ownKeys(e) : w.keys(e)).forEach((s) => {
|
|
77
77
|
t(s, e[s], e);
|
|
78
78
|
}) : e.forEach((n, s) => t(s, n, e));
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
const t = e[
|
|
82
|
-
return t ? t.type_ :
|
|
80
|
+
function H(e) {
|
|
81
|
+
const t = e[p];
|
|
82
|
+
return t ? t.type_ : ae(e) ? 1 : ue(e) ? 2 : fe(e) ? 3 : 0;
|
|
83
83
|
}
|
|
84
|
-
var Oe = (e, t, r =
|
|
84
|
+
var Oe = (e, t, r = H(e)) => r === 2 ? e.has(t) : w[oe].hasOwnProperty.call(e, t), Ae = (e, t, r = H(e)) => (
|
|
85
85
|
// @ts-ignore
|
|
86
86
|
r === 2 ? e.get(t) : e[t]
|
|
87
|
-
),
|
|
87
|
+
), te = (e, t, r, n = H(e)) => {
|
|
88
88
|
n === 2 ? e.set(t, r) : n === 3 ? e.add(r) : e[t] = r;
|
|
89
89
|
};
|
|
90
|
-
function
|
|
90
|
+
function yt(e, t) {
|
|
91
91
|
return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
|
|
92
92
|
}
|
|
93
|
-
var
|
|
94
|
-
function
|
|
93
|
+
var ae = Array.isArray, ue = (e) => e instanceof Map, fe = (e) => e instanceof Set, Fe = (e) => typeof e == "object", v = (e) => typeof e == "function", we = (e) => typeof e == "boolean";
|
|
94
|
+
function pt(e) {
|
|
95
95
|
const t = +e;
|
|
96
96
|
return Number.isInteger(t) && String(t) === e;
|
|
97
97
|
}
|
|
98
|
-
var I = (e) => e.copy_ || e.base_,
|
|
99
|
-
function
|
|
100
|
-
if (ae(e))
|
|
101
|
-
return new Map(e);
|
|
98
|
+
var I = (e) => e.copy_ || e.base_, Ne = (e) => e.modified_ ? e.copy_ : e.base_;
|
|
99
|
+
function be(e, t) {
|
|
102
100
|
if (ue(e))
|
|
101
|
+
return new Map(e);
|
|
102
|
+
if (fe(e))
|
|
103
103
|
return new Set(e);
|
|
104
|
-
if (
|
|
105
|
-
return Array[
|
|
106
|
-
const r =
|
|
104
|
+
if (ae(e))
|
|
105
|
+
return Array[oe].slice.call(e);
|
|
106
|
+
const r = Xe(e);
|
|
107
107
|
if (t === !0 || t === "class_only" && !r) {
|
|
108
108
|
const n = w.getOwnPropertyDescriptors(e);
|
|
109
|
-
delete n[
|
|
109
|
+
delete n[p];
|
|
110
110
|
let s = Reflect.ownKeys(n);
|
|
111
111
|
for (let i = 0; i < s.length; i++) {
|
|
112
112
|
const c = s[i], u = n[c];
|
|
113
|
-
u[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
113
|
+
u[Y] === !1 && (u[Y] = !0, u[Pe] = !0), (u.get || u.set) && (n[c] = {
|
|
114
|
+
[Pe]: !0,
|
|
115
|
+
[Y]: !0,
|
|
116
116
|
// could live with !!desc.set as well here...
|
|
117
|
-
[
|
|
118
|
-
[
|
|
117
|
+
[ee]: u[ee],
|
|
118
|
+
[W]: e[c]
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
return w.create(
|
|
121
|
+
return w.create(O(e), n);
|
|
122
122
|
} else {
|
|
123
|
-
const n =
|
|
123
|
+
const n = O(e);
|
|
124
124
|
if (n !== null && r)
|
|
125
125
|
return { ...e };
|
|
126
126
|
const s = w.create(n);
|
|
127
127
|
return w.assign(s, e);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
function
|
|
131
|
-
return
|
|
130
|
+
function $e(e, t = !1) {
|
|
131
|
+
return le(e) || M(e) || !C(e) || (H(e) > 1 && w.defineProperties(e, {
|
|
132
132
|
set: K,
|
|
133
133
|
add: K,
|
|
134
134
|
clear: K,
|
|
135
135
|
delete: K
|
|
136
|
-
}), w.freeze(e), t &&
|
|
136
|
+
}), w.freeze(e), t && ce(
|
|
137
137
|
e,
|
|
138
138
|
(r, n) => {
|
|
139
|
-
|
|
139
|
+
$e(n, !0);
|
|
140
140
|
},
|
|
141
141
|
!1
|
|
142
142
|
)), e;
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function mt() {
|
|
145
145
|
g(2);
|
|
146
146
|
}
|
|
147
147
|
var K = {
|
|
148
|
-
[
|
|
148
|
+
[W]: mt
|
|
149
149
|
};
|
|
150
|
-
function
|
|
151
|
-
return e === null || !
|
|
150
|
+
function le(e) {
|
|
151
|
+
return e === null || !Fe(e) ? !0 : w.isFrozen(e);
|
|
152
152
|
}
|
|
153
|
-
var
|
|
153
|
+
var re = "MapSet", De = "Patches", Be = "ArrayMethods", Ze = {};
|
|
154
154
|
function E(e) {
|
|
155
|
-
const t =
|
|
155
|
+
const t = Ze[e];
|
|
156
156
|
return t || g(0, e), t;
|
|
157
157
|
}
|
|
158
|
-
var
|
|
158
|
+
var We = (e) => !!Ze[e], q, et = () => q, gt = (e, t) => ({
|
|
159
159
|
drafts_: [],
|
|
160
160
|
parent_: e,
|
|
161
161
|
immer_: t,
|
|
@@ -165,45 +165,45 @@ var Be = (e) => !!Xe[e], W, Ze = () => W, mt = (e, t) => ({
|
|
|
165
165
|
unfinalizedDrafts_: 0,
|
|
166
166
|
handledSet_: /* @__PURE__ */ new Set(),
|
|
167
167
|
processedForPatches_: /* @__PURE__ */ new Set(),
|
|
168
|
-
mapSetPlugin_:
|
|
169
|
-
arrayMethodsPlugin_: Be
|
|
168
|
+
mapSetPlugin_: We(re) ? E(re) : void 0,
|
|
169
|
+
arrayMethodsPlugin_: We(Be) ? E(Be) : void 0
|
|
170
170
|
});
|
|
171
|
-
function
|
|
172
|
-
t && (e.patchPlugin_ = E(
|
|
173
|
-
}
|
|
174
|
-
function De(e) {
|
|
175
|
-
Ie(e), e.drafts_.forEach(gt), e.drafts_ = null;
|
|
171
|
+
function qe(e, t) {
|
|
172
|
+
t && (e.patchPlugin_ = E(De), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
|
|
176
173
|
}
|
|
177
174
|
function Ie(e) {
|
|
178
|
-
e
|
|
175
|
+
Ce(e), e.drafts_.forEach(wt), e.drafts_ = null;
|
|
179
176
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
function Ce(e) {
|
|
178
|
+
e === q && (q = e.parent_);
|
|
179
|
+
}
|
|
180
|
+
var Ge = (e) => q = gt(q, e);
|
|
181
|
+
function wt(e) {
|
|
182
|
+
const t = e[p];
|
|
183
183
|
t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function He(e, t) {
|
|
186
186
|
t.unfinalizedDrafts_ = t.drafts_.length;
|
|
187
187
|
const r = t.drafts_[0];
|
|
188
188
|
if (e !== void 0 && e !== r) {
|
|
189
|
-
r[
|
|
189
|
+
r[p].modified_ && (Ie(t), g(4)), C(e) && (e = Je(t, e));
|
|
190
190
|
const { patchPlugin_: s } = t;
|
|
191
191
|
s && s.generateReplacementPatches_(
|
|
192
|
-
r[
|
|
192
|
+
r[p].base_,
|
|
193
193
|
e,
|
|
194
194
|
t
|
|
195
195
|
);
|
|
196
196
|
} else
|
|
197
|
-
e =
|
|
198
|
-
return
|
|
197
|
+
e = Je(t, r);
|
|
198
|
+
return St(t, e, !0), Ie(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== Qe ? e : void 0;
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
if (
|
|
200
|
+
function Je(e, t) {
|
|
201
|
+
if (le(t))
|
|
202
202
|
return t;
|
|
203
|
-
const r = t[
|
|
203
|
+
const r = t[p];
|
|
204
204
|
if (!r)
|
|
205
|
-
return
|
|
206
|
-
if (!
|
|
205
|
+
return ne(t, e.handledSet_, e);
|
|
206
|
+
if (!de(r, e))
|
|
207
207
|
return t;
|
|
208
208
|
if (!r.modified_)
|
|
209
209
|
return r.base_;
|
|
@@ -212,48 +212,48 @@ function He(e, t) {
|
|
|
212
212
|
if (n)
|
|
213
213
|
for (; n.length > 0; )
|
|
214
214
|
n.pop()(e);
|
|
215
|
-
|
|
215
|
+
nt(r, e);
|
|
216
216
|
}
|
|
217
217
|
return r.copy_;
|
|
218
218
|
}
|
|
219
|
-
function
|
|
220
|
-
!e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ &&
|
|
219
|
+
function St(e, t, r = !1) {
|
|
220
|
+
!e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && $e(t, r);
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function tt(e) {
|
|
223
223
|
e.finalized_ = !0, e.scope_.unfinalizedDrafts_--;
|
|
224
224
|
}
|
|
225
|
-
var
|
|
226
|
-
function
|
|
225
|
+
var de = (e, t) => e.scope_ === t, Pt = [];
|
|
226
|
+
function rt(e, t, r, n) {
|
|
227
227
|
const s = I(e), i = e.type_;
|
|
228
|
-
if (n !== void 0 &&
|
|
229
|
-
|
|
228
|
+
if (n !== void 0 && Ae(s, n, i) === t) {
|
|
229
|
+
te(s, n, r, i);
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
if (!e.draftLocations_) {
|
|
233
233
|
const u = e.draftLocations_ = /* @__PURE__ */ new Map();
|
|
234
|
-
|
|
234
|
+
ce(s, (h, d) => {
|
|
235
235
|
if (M(d)) {
|
|
236
|
-
const
|
|
237
|
-
|
|
236
|
+
const _ = u.get(d) || [];
|
|
237
|
+
_.push(h), u.set(d, _);
|
|
238
238
|
}
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
|
-
const c = e.draftLocations_.get(t) ??
|
|
241
|
+
const c = e.draftLocations_.get(t) ?? Pt;
|
|
242
242
|
for (const u of c)
|
|
243
|
-
|
|
243
|
+
te(s, u, r, i);
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function At(e, t, r) {
|
|
246
246
|
e.callbacks_.push(function(s) {
|
|
247
247
|
var u;
|
|
248
248
|
const i = t;
|
|
249
|
-
if (!i || !
|
|
249
|
+
if (!i || !de(i, s))
|
|
250
250
|
return;
|
|
251
251
|
(u = s.mapSetPlugin_) == null || u.fixSetContents(i);
|
|
252
|
-
const c =
|
|
253
|
-
|
|
252
|
+
const c = Ne(i);
|
|
253
|
+
rt(e, i.draft_ ?? i, c, r), nt(i, s);
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
|
-
function
|
|
256
|
+
function nt(e, t) {
|
|
257
257
|
var n;
|
|
258
258
|
if (e.modified_ && !e.finalized_ && (e.type_ === 3 || e.type_ === 1 && e.allIndicesReassigned_ || (((n = e.assigned_) == null ? void 0 : n.size) ?? 0) > 0)) {
|
|
259
259
|
const { patchPlugin_: s } = t;
|
|
@@ -261,43 +261,43 @@ function rt(e, t) {
|
|
|
261
261
|
const i = s.getPath(e);
|
|
262
262
|
i && s.generatePatches_(e, i, t);
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
tt(e);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
-
function
|
|
267
|
+
function bt(e, t, r) {
|
|
268
268
|
const { scope_: n } = e;
|
|
269
269
|
if (M(r)) {
|
|
270
|
-
const s = r[
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const c =
|
|
274
|
-
|
|
270
|
+
const s = r[p];
|
|
271
|
+
de(s, n) && s.callbacks_.push(function() {
|
|
272
|
+
Q(e);
|
|
273
|
+
const c = Ne(s);
|
|
274
|
+
rt(e, r, c, t);
|
|
275
275
|
});
|
|
276
276
|
} else C(r) && e.callbacks_.push(function() {
|
|
277
277
|
const i = I(e);
|
|
278
|
-
e.type_ === 3 ? i.has(r) &&
|
|
279
|
-
|
|
278
|
+
e.type_ === 3 ? i.has(r) && ne(r, n.handledSet_, n) : Ae(i, t, e.type_) === r && n.drafts_.length > 1 && (e.assigned_.get(t) ?? !1) === !0 && e.copy_ && ne(
|
|
279
|
+
Ae(e.copy_, t, e.type_),
|
|
280
280
|
n.handledSet_,
|
|
281
281
|
n
|
|
282
282
|
);
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
|
-
function
|
|
286
|
-
return !r.immer_.autoFreeze_ && r.unfinalizedDrafts_ < 1 || M(e) || t.has(e) || !C(e) ||
|
|
285
|
+
function ne(e, t, r) {
|
|
286
|
+
return !r.immer_.autoFreeze_ && r.unfinalizedDrafts_ < 1 || M(e) || t.has(e) || !C(e) || le(e) || (t.add(e), ce(e, (n, s) => {
|
|
287
287
|
if (M(s)) {
|
|
288
|
-
const i = s[
|
|
289
|
-
if (
|
|
290
|
-
const c =
|
|
291
|
-
|
|
288
|
+
const i = s[p];
|
|
289
|
+
if (de(i, r)) {
|
|
290
|
+
const c = Ne(i);
|
|
291
|
+
te(e, n, c, e.type_), tt(i);
|
|
292
292
|
}
|
|
293
|
-
} else C(s) &&
|
|
293
|
+
} else C(s) && ne(s, t, r);
|
|
294
294
|
})), e;
|
|
295
295
|
}
|
|
296
|
-
function
|
|
297
|
-
const r =
|
|
296
|
+
function Dt(e, t) {
|
|
297
|
+
const r = ae(e), n = {
|
|
298
298
|
type_: r ? 1 : 0,
|
|
299
299
|
// Track which produce call this is associated with.
|
|
300
|
-
scope_: t ? t.scope_ :
|
|
300
|
+
scope_: t ? t.scope_ : et(),
|
|
301
301
|
// True for both shallow and deep changes.
|
|
302
302
|
modified_: !1,
|
|
303
303
|
// Used during finalization.
|
|
@@ -320,14 +320,14 @@ function bt(e, t) {
|
|
|
320
320
|
// `callbacks` actually gets assigned in `createProxy`
|
|
321
321
|
callbacks_: void 0
|
|
322
322
|
};
|
|
323
|
-
let s = n, i =
|
|
324
|
-
r && (s = [n], i =
|
|
323
|
+
let s = n, i = se;
|
|
324
|
+
r && (s = [n], i = G);
|
|
325
325
|
const { revoke: c, proxy: u } = Proxy.revocable(s, i);
|
|
326
326
|
return n.draft_ = u, n.revoke_ = c, [u, n];
|
|
327
327
|
}
|
|
328
|
-
var
|
|
328
|
+
var se = {
|
|
329
329
|
get(e, t) {
|
|
330
|
-
if (t ===
|
|
330
|
+
if (t === p)
|
|
331
331
|
return e;
|
|
332
332
|
let r = e.scope_.arrayMethodsPlugin_;
|
|
333
333
|
const n = e.type_ === 1 && typeof t == "string";
|
|
@@ -335,15 +335,15 @@ var ne = {
|
|
|
335
335
|
return r.createMethodInterceptor(e, t);
|
|
336
336
|
const s = I(e);
|
|
337
337
|
if (!Oe(s, t, e.type_))
|
|
338
|
-
return
|
|
338
|
+
return It(e, s, t);
|
|
339
339
|
const i = s[t];
|
|
340
340
|
if (e.finalized_ || !C(i) || n && e.operationMethod && (r != null && r.isMutatingArrayMethod(
|
|
341
341
|
e.operationMethod
|
|
342
|
-
)) &&
|
|
342
|
+
)) && pt(t))
|
|
343
343
|
return i;
|
|
344
|
-
if (i ===
|
|
345
|
-
|
|
346
|
-
const c = e.type_ === 1 ? +t : t, u =
|
|
344
|
+
if (i === Se(e.base_, t)) {
|
|
345
|
+
Q(e);
|
|
346
|
+
const c = e.type_ === 1 ? +t : t, u = ze(e.scope_, i, e, c);
|
|
347
347
|
return e.copy_[c] = u;
|
|
348
348
|
}
|
|
349
349
|
return i;
|
|
@@ -355,117 +355,117 @@ var ne = {
|
|
|
355
355
|
return Reflect.ownKeys(I(e));
|
|
356
356
|
},
|
|
357
357
|
set(e, t, r) {
|
|
358
|
-
const n =
|
|
358
|
+
const n = st(I(e), t);
|
|
359
359
|
if (n != null && n.set)
|
|
360
360
|
return n.set.call(e.draft_, r), !0;
|
|
361
361
|
if (!e.modified_) {
|
|
362
|
-
const s =
|
|
362
|
+
const s = Se(I(e), t), i = s == null ? void 0 : s[p];
|
|
363
363
|
if (i && i.base_ === r)
|
|
364
364
|
return e.copy_[t] = r, e.assigned_.set(t, !1), !0;
|
|
365
|
-
if (
|
|
365
|
+
if (yt(r, s) && (r !== void 0 || Oe(e.base_, t, e.type_)))
|
|
366
366
|
return !0;
|
|
367
|
-
|
|
367
|
+
Q(e), Me(e);
|
|
368
368
|
}
|
|
369
369
|
return e.copy_[t] === r && // special case: handle new props with value 'undefined'
|
|
370
370
|
(r !== void 0 || t in e.copy_) || // special case: NaN
|
|
371
|
-
Number.isNaN(r) && Number.isNaN(e.copy_[t]) || (e.copy_[t] = r, e.assigned_.set(t, !0),
|
|
371
|
+
Number.isNaN(r) && Number.isNaN(e.copy_[t]) || (e.copy_[t] = r, e.assigned_.set(t, !0), bt(e, t, r)), !0;
|
|
372
372
|
},
|
|
373
373
|
deleteProperty(e, t) {
|
|
374
|
-
return
|
|
374
|
+
return Q(e), Se(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_.set(t, !1), Me(e)) : e.assigned_.delete(t), e.copy_ && delete e.copy_[t], !0;
|
|
375
375
|
},
|
|
376
376
|
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
377
377
|
// the same guarantee in ES5 mode.
|
|
378
378
|
getOwnPropertyDescriptor(e, t) {
|
|
379
379
|
const r = I(e), n = Reflect.getOwnPropertyDescriptor(r, t);
|
|
380
380
|
return n && {
|
|
381
|
-
[
|
|
382
|
-
[
|
|
383
|
-
[
|
|
384
|
-
[
|
|
381
|
+
[Y]: !0,
|
|
382
|
+
[Pe]: e.type_ !== 1 || t !== "length",
|
|
383
|
+
[ee]: n[ee],
|
|
384
|
+
[W]: r[t]
|
|
385
385
|
};
|
|
386
386
|
},
|
|
387
387
|
defineProperty() {
|
|
388
388
|
g(11);
|
|
389
389
|
},
|
|
390
390
|
getPrototypeOf(e) {
|
|
391
|
-
return
|
|
391
|
+
return O(e.base_);
|
|
392
392
|
},
|
|
393
393
|
setPrototypeOf() {
|
|
394
394
|
g(12);
|
|
395
395
|
}
|
|
396
|
-
},
|
|
397
|
-
for (let e in
|
|
398
|
-
let t =
|
|
399
|
-
|
|
396
|
+
}, G = {};
|
|
397
|
+
for (let e in se) {
|
|
398
|
+
let t = se[e];
|
|
399
|
+
G[e] = function() {
|
|
400
400
|
const r = arguments;
|
|
401
401
|
return r[0] = r[0][0], t.apply(this, r);
|
|
402
402
|
};
|
|
403
403
|
}
|
|
404
|
-
|
|
405
|
-
return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && g(13),
|
|
404
|
+
G.deleteProperty = function(e, t) {
|
|
405
|
+
return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && g(13), G.set.call(this, e, t, void 0);
|
|
406
406
|
};
|
|
407
|
-
|
|
408
|
-
return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && g(14),
|
|
407
|
+
G.set = function(e, t, r) {
|
|
408
|
+
return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && g(14), se.set.call(this, e[0], t, r, e[0]);
|
|
409
409
|
};
|
|
410
|
-
function
|
|
411
|
-
const r = e[
|
|
410
|
+
function Se(e, t) {
|
|
411
|
+
const r = e[p];
|
|
412
412
|
return (r ? I(r) : e)[t];
|
|
413
413
|
}
|
|
414
|
-
function
|
|
414
|
+
function It(e, t, r) {
|
|
415
415
|
var s;
|
|
416
|
-
const n =
|
|
417
|
-
return n ?
|
|
416
|
+
const n = st(t, r);
|
|
417
|
+
return n ? W in n ? n[W] : (
|
|
418
418
|
// This is a very special case, if the prop is a getter defined by the
|
|
419
419
|
// prototype, we should invoke it with the draft as context!
|
|
420
420
|
(s = n.get) == null ? void 0 : s.call(e.draft_)
|
|
421
421
|
) : void 0;
|
|
422
422
|
}
|
|
423
|
-
function
|
|
423
|
+
function st(e, t) {
|
|
424
424
|
if (!(t in e))
|
|
425
425
|
return;
|
|
426
|
-
let r =
|
|
426
|
+
let r = O(e);
|
|
427
427
|
for (; r; ) {
|
|
428
428
|
const n = Object.getOwnPropertyDescriptor(r, t);
|
|
429
429
|
if (n)
|
|
430
430
|
return n;
|
|
431
|
-
r =
|
|
431
|
+
r = O(r);
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
|
-
function
|
|
435
|
-
e.modified_ || (e.modified_ = !0, e.parent_ &&
|
|
434
|
+
function Me(e) {
|
|
435
|
+
e.modified_ || (e.modified_ = !0, e.parent_ && Me(e.parent_));
|
|
436
436
|
}
|
|
437
|
-
function
|
|
438
|
-
e.copy_ || (e.assigned_ = /* @__PURE__ */ new Map(), e.copy_ =
|
|
437
|
+
function Q(e) {
|
|
438
|
+
e.copy_ || (e.assigned_ = /* @__PURE__ */ new Map(), e.copy_ = be(
|
|
439
439
|
e.base_,
|
|
440
440
|
e.scope_.immer_.useStrictShallowCopy_
|
|
441
441
|
));
|
|
442
442
|
}
|
|
443
|
-
var
|
|
443
|
+
var Ct = class {
|
|
444
444
|
constructor(e) {
|
|
445
445
|
this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !1, this.produce = (t, r, n) => {
|
|
446
446
|
if (v(t) && !v(r)) {
|
|
447
447
|
const i = r;
|
|
448
448
|
r = t;
|
|
449
449
|
const c = this;
|
|
450
|
-
return function(
|
|
451
|
-
return c.produce(
|
|
450
|
+
return function(h = i, ...d) {
|
|
451
|
+
return c.produce(h, (_) => r.call(this, _, ...d));
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
454
|
v(r) || g(6), n !== void 0 && !v(n) && g(7);
|
|
455
455
|
let s;
|
|
456
456
|
if (C(t)) {
|
|
457
|
-
const i =
|
|
457
|
+
const i = Ge(this), c = ze(i, t, void 0);
|
|
458
458
|
let u = !0;
|
|
459
459
|
try {
|
|
460
460
|
s = r(c), u = !1;
|
|
461
461
|
} finally {
|
|
462
|
-
u ?
|
|
462
|
+
u ? Ie(i) : Ce(i);
|
|
463
463
|
}
|
|
464
|
-
return
|
|
465
|
-
} else if (!t || !
|
|
466
|
-
if (s = r(t), s === void 0 && (s = t), s ===
|
|
464
|
+
return qe(i, n), He(s, i);
|
|
465
|
+
} else if (!t || !Fe(t)) {
|
|
466
|
+
if (s = r(t), s === void 0 && (s = t), s === Qe && (s = void 0), this.autoFreeze_ && $e(s, !0), n) {
|
|
467
467
|
const i = [], c = [];
|
|
468
|
-
E(
|
|
468
|
+
E(De).generateReplacementPatches_(t, s, {
|
|
469
469
|
patches_: i,
|
|
470
470
|
inversePatches_: c
|
|
471
471
|
}), n(i, c);
|
|
@@ -475,23 +475,23 @@ var It = class {
|
|
|
475
475
|
g(1, t);
|
|
476
476
|
}, this.produceWithPatches = (t, r) => {
|
|
477
477
|
if (v(t))
|
|
478
|
-
return (c, ...u) => this.produceWithPatches(c, (
|
|
478
|
+
return (c, ...u) => this.produceWithPatches(c, (h) => t(h, ...u));
|
|
479
479
|
let n, s;
|
|
480
480
|
return [this.produce(t, r, (c, u) => {
|
|
481
481
|
n = c, s = u;
|
|
482
482
|
}), n, s];
|
|
483
|
-
},
|
|
483
|
+
}, we(e == null ? void 0 : e.autoFreeze) && this.setAutoFreeze(e.autoFreeze), we(e == null ? void 0 : e.useStrictShallowCopy) && this.setUseStrictShallowCopy(e.useStrictShallowCopy), we(e == null ? void 0 : e.useStrictIteration) && this.setUseStrictIteration(e.useStrictIteration);
|
|
484
484
|
}
|
|
485
485
|
createDraft(e) {
|
|
486
|
-
C(e) || g(8), M(e) && (e =
|
|
487
|
-
const t =
|
|
488
|
-
return r[
|
|
486
|
+
C(e) || g(8), M(e) && (e = Mt(e));
|
|
487
|
+
const t = Ge(this), r = ze(t, e, void 0);
|
|
488
|
+
return r[p].isManual_ = !0, Ce(t), r;
|
|
489
489
|
}
|
|
490
490
|
finishDraft(e, t) {
|
|
491
|
-
const r = e && e[
|
|
491
|
+
const r = e && e[p];
|
|
492
492
|
(!r || !r.isManual_) && g(9);
|
|
493
493
|
const { scope_: n } = r;
|
|
494
|
-
return
|
|
494
|
+
return qe(n, t), He(void 0, n);
|
|
495
495
|
}
|
|
496
496
|
/**
|
|
497
497
|
* Pass true to automatically freeze all copies created by Immer.
|
|
@@ -531,56 +531,56 @@ var It = class {
|
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
r > -1 && (t = t.slice(r + 1));
|
|
534
|
-
const n = E(
|
|
534
|
+
const n = E(De).applyPatches_;
|
|
535
535
|
return M(e) ? n(e, t) : this.produce(
|
|
536
536
|
e,
|
|
537
537
|
(s) => n(s, t)
|
|
538
538
|
);
|
|
539
539
|
}
|
|
540
540
|
};
|
|
541
|
-
function
|
|
542
|
-
const [s, i] =
|
|
543
|
-
return ((r == null ? void 0 : r.scope_) ??
|
|
544
|
-
var
|
|
545
|
-
(
|
|
546
|
-
const { patchPlugin_: d } =
|
|
547
|
-
i.modified_ && d && d.generatePatches_(i, [],
|
|
541
|
+
function ze(e, t, r, n) {
|
|
542
|
+
const [s, i] = ue(t) ? E(re).proxyMap_(t, r) : fe(t) ? E(re).proxySet_(t, r) : Dt(t, r);
|
|
543
|
+
return ((r == null ? void 0 : r.scope_) ?? et()).drafts_.push(s), i.callbacks_ = (r == null ? void 0 : r.callbacks_) ?? [], i.key_ = n, r && n !== void 0 ? At(r, i, n) : i.callbacks_.push(function(h) {
|
|
544
|
+
var _;
|
|
545
|
+
(_ = h.mapSetPlugin_) == null || _.fixSetContents(i);
|
|
546
|
+
const { patchPlugin_: d } = h;
|
|
547
|
+
i.modified_ && d && d.generatePatches_(i, [], h);
|
|
548
548
|
}), s;
|
|
549
549
|
}
|
|
550
|
-
function
|
|
551
|
-
return M(e) || g(10, e),
|
|
550
|
+
function Mt(e) {
|
|
551
|
+
return M(e) || g(10, e), it(e);
|
|
552
552
|
}
|
|
553
|
-
function
|
|
554
|
-
if (!C(e) ||
|
|
553
|
+
function it(e) {
|
|
554
|
+
if (!C(e) || le(e))
|
|
555
555
|
return e;
|
|
556
|
-
const t = e[
|
|
556
|
+
const t = e[p];
|
|
557
557
|
let r, n = !0;
|
|
558
558
|
if (t) {
|
|
559
559
|
if (!t.modified_)
|
|
560
560
|
return t.base_;
|
|
561
|
-
t.finalized_ = !0, r =
|
|
561
|
+
t.finalized_ = !0, r = be(e, t.scope_.immer_.useStrictShallowCopy_), n = t.scope_.immer_.shouldUseStrictIteration();
|
|
562
562
|
} else
|
|
563
|
-
r =
|
|
564
|
-
return
|
|
563
|
+
r = be(e, !0);
|
|
564
|
+
return ce(
|
|
565
565
|
r,
|
|
566
566
|
(s, i) => {
|
|
567
|
-
|
|
567
|
+
te(r, s, it(i));
|
|
568
568
|
},
|
|
569
569
|
n
|
|
570
570
|
), t && (t.finalized_ = !1), r;
|
|
571
571
|
}
|
|
572
|
-
var
|
|
573
|
-
class
|
|
572
|
+
var zt = new Ct(), ot = zt.produce;
|
|
573
|
+
class xt extends F {
|
|
574
574
|
constructor(t, r) {
|
|
575
575
|
super(r), this.a = t, this.push = (...n) => {
|
|
576
576
|
n.length !== 0 && this.a.set(this.a.get().concat(n));
|
|
577
577
|
}, this.unshift = (...n) => {
|
|
578
578
|
n.length !== 0 && this.a.set(n.concat(this.a.get()));
|
|
579
579
|
}, this.update = (n) => {
|
|
580
|
-
const s = this.a.get(), i =
|
|
580
|
+
const s = this.a.get(), i = ot(s, (c) => void n(c));
|
|
581
581
|
i !== s && this.a.set(i);
|
|
582
582
|
}, this.filter = (n) => {
|
|
583
|
-
const s = this.a.get().filter(n ??
|
|
583
|
+
const s = this.a.get().filter(n ?? vt);
|
|
584
584
|
s.length !== this.a.get().length && this.a.set(s);
|
|
585
585
|
}, this.add = (n) => {
|
|
586
586
|
this.a.get().includes(n) || this.a.set(this.a.get().concat([n]));
|
|
@@ -595,15 +595,15 @@ class zt extends F {
|
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
|
-
const
|
|
599
|
-
class
|
|
598
|
+
const vt = (e) => e;
|
|
599
|
+
class Tt extends F {
|
|
600
600
|
constructor(t, r) {
|
|
601
601
|
super(r), this.a = t, this.toggle = () => {
|
|
602
602
|
this.a.set(!this.a.get());
|
|
603
603
|
};
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
|
-
class
|
|
606
|
+
class Et extends F {
|
|
607
607
|
constructor(t, r) {
|
|
608
608
|
super(r), this.a = t, this.setValue = (n, s) => {
|
|
609
609
|
if (this.a.get().get(n) === s) return;
|
|
@@ -625,51 +625,51 @@ class Tt extends F {
|
|
|
625
625
|
}, this.a = t;
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
|
-
class
|
|
628
|
+
class Ft extends F {
|
|
629
629
|
constructor(t, r) {
|
|
630
630
|
super(r), this.a = t, this.increment = (n) => {
|
|
631
631
|
this.a.set(+this.a.get() + (n ?? 1));
|
|
632
632
|
};
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
-
class
|
|
635
|
+
class Nt extends F {
|
|
636
636
|
constructor(t, r) {
|
|
637
637
|
super(r), this.a = t, this.setPartial = (n) => this.a.set((s) => ({
|
|
638
638
|
...s,
|
|
639
639
|
...typeof n == "function" ? n(this.a.get()) : n
|
|
640
640
|
})), this.update = (n) => {
|
|
641
|
-
const s = this.a.get(), i =
|
|
641
|
+
const s = this.a.get(), i = ot(s, (c) => void n(c));
|
|
642
642
|
i !== s && this.a.set(i);
|
|
643
643
|
}, this.setDeepPartial = (n, s, i, c = T.keyPathSeparator || ".") => {
|
|
644
644
|
if (!c) return;
|
|
645
645
|
if (n.includes(c)) {
|
|
646
646
|
let d = n.split(c);
|
|
647
|
-
const
|
|
647
|
+
const _ = d[d.length - 1];
|
|
648
648
|
d = d.slice(0, -1);
|
|
649
|
-
const
|
|
650
|
-
let
|
|
651
|
-
for (const
|
|
652
|
-
|
|
653
|
-
const
|
|
654
|
-
if (
|
|
649
|
+
const z = { ...this.a.get() };
|
|
650
|
+
let S = z, y = i;
|
|
651
|
+
for (const N of d) {
|
|
652
|
+
y = y == null ? void 0 : y[Array.isArray(y) ? "0" : N];
|
|
653
|
+
const m = S[Ke(S, N)] ?? (Array.isArray(y) ? [] : {});
|
|
654
|
+
if (m == null || typeof m != "object") {
|
|
655
655
|
if (i == null) throw "Incorrect path for setDeepPartial";
|
|
656
|
-
const
|
|
657
|
-
this.a.get()[n] !==
|
|
656
|
+
const J = typeof s == "function" ? s(void 0) : s;
|
|
657
|
+
this.a.get()[n] !== J && this.setPartial({ [n]: J });
|
|
658
658
|
return;
|
|
659
659
|
}
|
|
660
|
-
|
|
660
|
+
S = S[Ke(S, N)] = Array.isArray(m) ? [...m] : { ...m };
|
|
661
661
|
}
|
|
662
|
-
const
|
|
663
|
-
_
|
|
662
|
+
const b = S[_];
|
|
663
|
+
S[_] = typeof s == "function" ? s(S[_]) : s, b !== S[_] && this.a.set(z);
|
|
664
664
|
return;
|
|
665
665
|
}
|
|
666
|
-
const u = this.a.get()[n],
|
|
667
|
-
|
|
666
|
+
const u = this.a.get()[n], h = typeof s == "function" ? s(u) : s;
|
|
667
|
+
h !== u && this.setPartial({ [n]: h });
|
|
668
668
|
};
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
671
|
const Ke = (e, t) => Array.isArray(e) ? `${+t}` : t;
|
|
672
|
-
class
|
|
672
|
+
class $t extends F {
|
|
673
673
|
constructor(t, r) {
|
|
674
674
|
super(r), this.a = t, this.add = (n) => {
|
|
675
675
|
this.a.get().has(n) || this.a.set(new Set(this.a.get()).add(n));
|
|
@@ -685,174 +685,174 @@ class Nt extends F {
|
|
|
685
685
|
}, this.a = t;
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
const
|
|
688
|
+
const Rt = (e, t, r) => {
|
|
689
689
|
const n = typeof r == "object" && r != null && "do" in r ? r.do(
|
|
690
690
|
(i, c) => t.set(i, c),
|
|
691
691
|
() => t.get(),
|
|
692
692
|
t,
|
|
693
693
|
(i, c, u) => t.setDeferred(i, c, u)
|
|
694
694
|
) : null, s = {};
|
|
695
|
-
return n && Object.keys(n).forEach((i) => Object.defineProperty(s, i, { get: () => n[i] })), typeof e == "number" ? new
|
|
695
|
+
return n && Object.keys(n).forEach((i) => Object.defineProperty(s, i, { get: () => n[i] })), typeof e == "number" ? new Ft(t, n) : typeof e == "boolean" ? new Tt(t, n) : Array.isArray(e) ? new xt(t, n) : e instanceof Set ? new $t(t, n) : e instanceof Map ? new Et(t, n) : e instanceof Object ? new Nt(t, n) : new F(n);
|
|
696
696
|
};
|
|
697
|
-
class
|
|
697
|
+
class kt {
|
|
698
698
|
constructor(t, r) {
|
|
699
699
|
t = typeof t == "function" ? t() : t;
|
|
700
|
-
const n = (o) =>
|
|
701
|
-
let u = !0,
|
|
702
|
-
},
|
|
703
|
-
const o =
|
|
704
|
-
return
|
|
700
|
+
const n = (o) => _ = o, s = () => _, i = /* @__PURE__ */ new Set(), c = (o) => o(y());
|
|
701
|
+
let u = !0, h = !1, d = (o) => o, _ = t, z, S = () => {
|
|
702
|
+
}, y = () => s(), b = null, N = () => {
|
|
703
|
+
const o = Rt(t, m, r);
|
|
704
|
+
return N = () => o, o;
|
|
705
705
|
};
|
|
706
|
-
const
|
|
707
|
-
get: (o, l) => l === "do" ?
|
|
708
|
-
set:
|
|
709
|
-
}),
|
|
710
|
-
u = !0,
|
|
706
|
+
const m = new Proxy(this, {
|
|
707
|
+
get: (o, l) => l === "do" ? N() : o[l],
|
|
708
|
+
set: Lt
|
|
709
|
+
}), J = () => {
|
|
710
|
+
u = !0, h !== !0 && S(y()), h = !1;
|
|
711
711
|
try {
|
|
712
|
-
|
|
712
|
+
xe.postMessage({ key: f, value: s() });
|
|
713
713
|
} catch {
|
|
714
714
|
}
|
|
715
|
-
},
|
|
716
|
-
|
|
717
|
-
|
|
715
|
+
}, $ = (o, l) => {
|
|
716
|
+
let A = typeof o == "function" ? o(y()) : o;
|
|
717
|
+
A = d(A, y()), A !== y() && (n(A), h = l, u && (u = !1, i.forEach(c), queueMicrotask(J)));
|
|
718
718
|
};
|
|
719
|
-
this.set = (o, l) =>
|
|
719
|
+
this.set = (o, l) => $(o, l), this.get = () => y(), this.initialValue = t, this.isInitialValue = () => t === s(), this.subscribe = (o) => (i.add(o), () => {
|
|
720
720
|
i.delete(o);
|
|
721
721
|
}), this.reset = () => {
|
|
722
|
-
|
|
722
|
+
$(t, !0);
|
|
723
723
|
};
|
|
724
|
-
const
|
|
725
|
-
|
|
724
|
+
const ft = (o, l) => {
|
|
725
|
+
$(o, l), z = void 0;
|
|
726
726
|
};
|
|
727
|
-
if (this.setDeferred = (o, l = 500,
|
|
728
|
-
D &&
|
|
729
|
-
}, r == null) return
|
|
730
|
-
let P = null,
|
|
727
|
+
if (this.setDeferred = (o, l = 500, A, D = !0) => {
|
|
728
|
+
D && z === void 0 && $(o, A), clearTimeout(z), z = setTimeout(ft, l, o, A);
|
|
729
|
+
}, r == null) return m;
|
|
730
|
+
let P = null, B = null, _e = !0, ye = !0, pe = !1, x = 0, R = 0, Re = -1, k = t instanceof Set ? (o) => new Set(o) : t instanceof Map ? (o) => new Map(o) : (o) => o, L = t instanceof Set ? (o) => {
|
|
731
731
|
if (o instanceof Set) return Array.from(o);
|
|
732
732
|
throw console.error(o), "The value is not Set instance";
|
|
733
733
|
} : t instanceof Map ? (o) => {
|
|
734
734
|
if (o instanceof Map) {
|
|
735
735
|
const l = [];
|
|
736
|
-
return o.forEach((
|
|
736
|
+
return o.forEach((A, D) => l.push([D, A])), l;
|
|
737
737
|
}
|
|
738
738
|
throw console.error(o), "The value is not Set instance";
|
|
739
739
|
} : (o) => o;
|
|
740
740
|
if (typeof r == "string")
|
|
741
741
|
P = r;
|
|
742
|
-
else if ("
|
|
743
|
-
|
|
744
|
-
else return
|
|
745
|
-
const
|
|
742
|
+
else if (d = r.map ?? d, "storageKey" in r)
|
|
743
|
+
_e = r.warnOnDuplicateStorageKey ?? _e, ye = r.listenStorageChanges ?? ye, P = r.storageKey, k = r.unzipValue ?? k, L = r.zipValue ?? L, pe = r.unchangable ?? pe, x = r.securifyKeyLevel ?? T.securifyKeyLevel ?? x, R = r.securifyValueLevel ?? T.securifyValueLevel ?? R, B = r.exp ?? B;
|
|
744
|
+
else return m;
|
|
745
|
+
const me = x ? V(P, x) : P, f = `${R ? ve : U}${me}`;
|
|
746
746
|
if (x) {
|
|
747
|
-
const o = `${
|
|
747
|
+
const o = `${U}${P}`;
|
|
748
748
|
o in a && (a[f] = a[o], delete a[o]);
|
|
749
749
|
} else {
|
|
750
|
-
const o = `${
|
|
750
|
+
const o = `${U}${V(P, x)}`;
|
|
751
751
|
o in a && (a[f] = a[o], delete a[o]);
|
|
752
752
|
}
|
|
753
|
-
const
|
|
754
|
-
if (
|
|
755
|
-
const o = `${
|
|
756
|
-
if (
|
|
753
|
+
const ge = B === null || !(B(m, f in a) instanceof Date) ? (o) => V([L(o)], 0) : (o) => (b ?? (b = {}), b.exp = B(m, f in a).getTime(), b.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(Re), clearTimeout(ct[f]), Re = setTimeout(() => this.reset(), b.exp - Date.now())), b.exp = Math.trunc(b.exp / 1e3), V([L(o), b], 0));
|
|
754
|
+
if (R) {
|
|
755
|
+
const o = `${U}${me}`, l = L, A = k;
|
|
756
|
+
if (L = (D) => {
|
|
757
757
|
try {
|
|
758
|
-
return
|
|
758
|
+
return V([l(D)], R);
|
|
759
759
|
} catch {
|
|
760
760
|
return delete a[f], "";
|
|
761
761
|
}
|
|
762
762
|
}, o in a) {
|
|
763
|
-
const D = `${
|
|
763
|
+
const D = `${U}${V(P, x)}`;
|
|
764
764
|
try {
|
|
765
|
-
a[D] =
|
|
765
|
+
a[D] = ge(k(X(a[o], 0)[0])), delete a[o];
|
|
766
766
|
} catch {
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
|
-
|
|
769
|
+
k = (D) => {
|
|
770
770
|
try {
|
|
771
|
-
return
|
|
771
|
+
return A(X(D, R)[0]);
|
|
772
772
|
} catch {
|
|
773
773
|
return delete a[f], "";
|
|
774
774
|
}
|
|
775
775
|
};
|
|
776
|
-
} else delete a[`${
|
|
777
|
-
const
|
|
778
|
-
const l =
|
|
779
|
-
return
|
|
776
|
+
} else delete a[`${ve}${me}`];
|
|
777
|
+
const ke = (o) => {
|
|
778
|
+
const l = X(o, 0);
|
|
779
|
+
return b = l[1], k(l[0]);
|
|
780
780
|
};
|
|
781
|
-
let
|
|
782
|
-
if (
|
|
783
|
-
if (
|
|
784
|
-
|
|
781
|
+
let Le = !0;
|
|
782
|
+
if (Te[f] = m, a[`atom/${P}`] && (a[f] || (a[f] = `[${a[`atom/${P}`]}]`), delete a[`atom/${P}`]), y = () => {
|
|
783
|
+
if (y = s, Le) {
|
|
784
|
+
Le = !1;
|
|
785
785
|
try {
|
|
786
|
-
n(f in a ?
|
|
786
|
+
n(f in a ? ke(a[f]) : t);
|
|
787
787
|
} catch {
|
|
788
788
|
console.warn("Invalid json value", a[f]);
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
return s();
|
|
792
|
-
},
|
|
792
|
+
}, S = (o) => {
|
|
793
793
|
if (o === t) {
|
|
794
794
|
this.reset();
|
|
795
795
|
return;
|
|
796
796
|
}
|
|
797
|
-
a[f] =
|
|
797
|
+
a[f] = ge(o);
|
|
798
798
|
}, this.reset = () => {
|
|
799
|
-
delete a[f],
|
|
800
|
-
},
|
|
801
|
-
if (
|
|
799
|
+
delete a[f], $(t, !0);
|
|
800
|
+
}, _e && j[f] !== void 0 && console.warn("Duplicate Atom key", P), ye)
|
|
801
|
+
if (pe) {
|
|
802
802
|
let o = !1, l;
|
|
803
|
-
|
|
804
|
-
clearTimeout(l), l = setTimeout(() => o = !1, 10), !o && (o = !0, a[f] =
|
|
803
|
+
he[f] = this, j[f] = () => {
|
|
804
|
+
clearTimeout(l), l = setTimeout(() => o = !1, 10), !o && (o = !0, a[f] = ge(s()));
|
|
805
805
|
};
|
|
806
806
|
} else
|
|
807
|
-
|
|
807
|
+
j[f] = (o) => {
|
|
808
808
|
if (o.newValue === null) {
|
|
809
809
|
this.reset();
|
|
810
810
|
return;
|
|
811
811
|
}
|
|
812
812
|
try {
|
|
813
|
-
|
|
813
|
+
$(ke(o.newValue));
|
|
814
814
|
} catch {
|
|
815
815
|
console.warn("Invalid json value", o.newValue);
|
|
816
816
|
}
|
|
817
817
|
};
|
|
818
|
-
return
|
|
818
|
+
return m;
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
|
-
let
|
|
821
|
+
let xe;
|
|
822
822
|
try {
|
|
823
|
-
|
|
823
|
+
xe = new BroadcastChannel("updateHere"), xe.addEventListener("message", (e) => {
|
|
824
824
|
var t;
|
|
825
|
-
(t =
|
|
825
|
+
(t = he[e.data.key]) == null || t.set(e.data.value, !0);
|
|
826
826
|
});
|
|
827
827
|
} catch {
|
|
828
828
|
}
|
|
829
|
-
const a = localStorage,
|
|
829
|
+
const a = localStorage, j = {}, he = {}, Lt = (e, t) => {
|
|
830
830
|
throw `${t} is readonly property`;
|
|
831
831
|
};
|
|
832
832
|
window.addEventListener("storage", (e) => {
|
|
833
833
|
var t;
|
|
834
|
-
e.key === null || e.newValue === e.oldValue || (t =
|
|
834
|
+
e.key === null || e.newValue === e.oldValue || (t = j[e.key]) == null || t.call(j, e);
|
|
835
835
|
});
|
|
836
|
-
const
|
|
836
|
+
const Vt = a.setItem.bind(a), Ut = a.removeItem.bind(a);
|
|
837
837
|
a.setItem = (e, t) => {
|
|
838
|
-
|
|
838
|
+
he[e] === void 0 && Vt.call(a, e, t);
|
|
839
839
|
};
|
|
840
840
|
a.removeItem = (e) => {
|
|
841
|
-
|
|
841
|
+
he[e] === void 0 && Ut.call(a, e);
|
|
842
842
|
};
|
|
843
|
-
const
|
|
843
|
+
const jt = /"exp":\s*(\d+)/, U = "atom\\", ve = "atom`s\\", Te = {}, ct = {}, at = /[a-z]/gi, ie = 5, Ee = {};
|
|
844
844
|
for (let e = 54; e < 80; e++) {
|
|
845
845
|
if (e === 68 || e === 72 || e === 55) continue;
|
|
846
846
|
const t = String.fromCharCode(e + 43).toUpperCase(), r = String.fromCharCode(e + 43).toLowerCase();
|
|
847
|
-
|
|
847
|
+
Ee[t] = r, Ee[r] = t;
|
|
848
848
|
}
|
|
849
|
-
const
|
|
849
|
+
const ut = (e) => Ee[e] ?? e, V = /* @__PURE__ */ (() => {
|
|
850
850
|
const e = [
|
|
851
851
|
(t) => JSON.stringify(t),
|
|
852
852
|
(t) => btoa(encodeURI(e[0](t))),
|
|
853
853
|
(t) => {
|
|
854
854
|
const r = e[1](t);
|
|
855
|
-
return `${r.slice(0,
|
|
855
|
+
return `${r.slice(0, ie)}${r.slice(ie).replace(at, ut)}`;
|
|
856
856
|
},
|
|
857
857
|
(t) => btoa(e[2](t))
|
|
858
858
|
];
|
|
@@ -864,12 +864,12 @@ const at = (e) => Te[e] ?? e, k = /* @__PURE__ */ (() => {
|
|
|
864
864
|
return e[0](t);
|
|
865
865
|
}
|
|
866
866
|
};
|
|
867
|
-
})(),
|
|
867
|
+
})(), X = /* @__PURE__ */ (() => {
|
|
868
868
|
const e = [
|
|
869
869
|
(t) => JSON.parse(t),
|
|
870
870
|
(t) => e[0](decodeURI(atob(t))),
|
|
871
871
|
(t) => e[1](
|
|
872
|
-
`${t.slice(0,
|
|
872
|
+
`${t.slice(0, ie)}${t.slice(ie).replace(at, ut)}`
|
|
873
873
|
),
|
|
874
874
|
(t) => e[2](atob(t))
|
|
875
875
|
];
|
|
@@ -885,30 +885,33 @@ const at = (e) => Te[e] ?? e, k = /* @__PURE__ */ (() => {
|
|
|
885
885
|
setTimeout(() => {
|
|
886
886
|
Object.keys(a).forEach((e) => {
|
|
887
887
|
var n;
|
|
888
|
-
if (typeof a[e] != "string" || !e.startsWith(
|
|
889
|
-
const t = (n = a[e].match(
|
|
888
|
+
if (typeof a[e] != "string" || !e.startsWith(U) && !e.startsWith(ve)) return;
|
|
889
|
+
const t = (n = a[e].match(jt)) == null ? void 0 : n[1];
|
|
890
890
|
if (!t || +t * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
|
|
891
|
-
const r =
|
|
892
|
-
!Array.isArray(r) || r[1] == null || !("exp" in r[1]) || r[1].exp !== t || (
|
|
893
|
-
|
|
894
|
-
|
|
891
|
+
const r = X(a[e], 0);
|
|
892
|
+
!Array.isArray(r) || r[1] == null || !("exp" in r[1]) || r[1].exp !== t || (ct[e] = setTimeout(
|
|
893
|
+
() => {
|
|
894
|
+
Te[e] ? Te[e].reset() : delete a[e];
|
|
895
|
+
},
|
|
896
|
+
+t * 1e3 - Date.now()
|
|
897
|
+
));
|
|
895
898
|
});
|
|
896
899
|
}, 1e3);
|
|
897
900
|
export {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
901
|
+
kt as Atom,
|
|
902
|
+
xt as AtomArrayDoActions,
|
|
903
|
+
Tt as AtomBooleanDoActions,
|
|
904
|
+
Et as AtomMapDoActions,
|
|
905
|
+
Ft as AtomNumberDoActions,
|
|
906
|
+
Nt as AtomObjectDoActions,
|
|
907
|
+
$t as AtomSetDoActions,
|
|
908
|
+
Ht as atom,
|
|
906
909
|
Ot as configureAtomaric,
|
|
907
910
|
T as configuredOptions,
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
911
|
+
Gt as useAtom,
|
|
912
|
+
qt as useAtomDo,
|
|
913
|
+
Wt as useAtomGet,
|
|
914
|
+
dt as useAtomSet,
|
|
915
|
+
Bt as useAtomSetDeferred,
|
|
916
|
+
lt as useAtomValue
|
|
914
917
|
};
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(d=typeof globalThis<"u"?globalThis:d||self,$(d.atomaric={}))})(this,function(d){"use strict";let $=()=>{throw"call configureAtomaric() before all!"};const z={},wt=e=>{z.useSyncExternalStore=$=e.useSyncExternalStore,z.keyPathSeparator=e.keyPathSeparator,z.securifyKeyLevel=e.securifyKeyLevel,z.securifyValueLevel=e.securifyValueLevel},ke=e=>$(e.subscribe,e.get),Le=e=>e.set,St=e=>e.setDeferred,At=e=>e.get,Pt=e=>e.do,bt=e=>[ke(e),Le(e)],Dt=(e,t)=>new lt(e,t);class T{constructor(t){if(t)return new Proxy(this,{get:(r,n)=>n in this?r[n]:t[n]})}}var Ve=Symbol.for("immer-nothing"),Oe=Symbol.for("immer-draftable"),p=Symbol.for("immer-state"),It=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function w(e,...t){if(process.env.NODE_ENV!=="production"){const r=It[e],n=E(r)?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var S=Object,R=S.getPrototypeOf,J="constructor",Y="prototype",ye="configurable",Q="enumerable",X="writable",B="value",v=e=>!!e&&!!e[p];function b(e){var t;return e?Ue(e)||te(e)||!!e[Oe]||!!((t=e[J])!=null&&t[Oe])||re(e)||ne(e):!1}var Mt=S[Y][J].toString(),je=new WeakMap;function Ue(e){if(!e||!pe(e))return!1;const t=R(e);if(t===null||t===S[Y])return!0;const r=S.hasOwnProperty.call(t,J)&&t[J];if(r===Object)return!0;if(!E(r))return!1;let n=je.get(r);return n===void 0&&(n=Function.toString.call(r),je.set(r,n)),n===Mt}function Z(e,t,r=!0){W(e)===0?(r?Reflect.ownKeys(e):S.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((n,s)=>t(s,n,e))}function W(e){const t=e[p];return t?t.type_:te(e)?1:re(e)?2:ne(e)?3:0}var Be=(e,t,r=W(e))=>r===2?e.has(t):S[Y].hasOwnProperty.call(e,t),me=(e,t,r=W(e))=>r===2?e.get(t):e[t],ee=(e,t,r,n=W(e))=>{n===2?e.set(t,r):n===3?e.add(r):e[t]=r};function Ct(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var te=Array.isArray,re=e=>e instanceof Map,ne=e=>e instanceof Set,pe=e=>typeof e=="object",E=e=>typeof e=="function",ge=e=>typeof e=="boolean";function zt(e){const t=+e;return Number.isInteger(t)&&String(t)===e}var D=e=>e.copy_||e.base_,we=e=>e.modified_?e.copy_:e.base_;function Se(e,t){if(re(e))return new Map(e);if(ne(e))return new Set(e);if(te(e))return Array[Y].slice.call(e);const r=Ue(e);if(t===!0||t==="class_only"&&!r){const n=S.getOwnPropertyDescriptors(e);delete n[p];let s=Reflect.ownKeys(n);for(let i=0;i<s.length;i++){const c=s[i],u=n[c];u[X]===!1&&(u[X]=!0,u[ye]=!0),(u.get||u.set)&&(n[c]={[ye]:!0,[X]:!0,[Q]:u[Q],[B]:e[c]})}return S.create(R(e),n)}else{const n=R(e);if(n!==null&&r)return{...e};const s=S.create(n);return S.assign(s,e)}}function Ae(e,t=!1){return ie(e)||v(e)||!b(e)||(W(e)>1&&S.defineProperties(e,{set:se,add:se,clear:se,delete:se}),S.freeze(e),t&&Z(e,(r,n)=>{Ae(n,!0)},!1)),e}function vt(){w(2)}var se={[B]:vt};function ie(e){return e===null||!pe(e)?!0:S.isFrozen(e)}var oe="MapSet",Pe="Patches",We="ArrayMethods",Ge={};function F(e){const t=Ge[e];return t||w(0,e),t}var qe=e=>!!Ge[e],G,He=()=>G,Tt=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:qe(oe)?F(oe):void 0,arrayMethodsPlugin_:qe(We)?F(We):void 0});function Ke(e,t){t&&(e.patchPlugin_=F(Pe),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function be(e){De(e),e.drafts_.forEach(Et),e.drafts_=null}function De(e){e===G&&(G=e.parent_)}var Je=e=>G=Tt(G,e);function Et(e){const t=e[p];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Ye(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];if(e!==void 0&&e!==r){r[p].modified_&&(be(t),w(4)),b(e)&&(e=Qe(t,e));const{patchPlugin_:s}=t;s&&s.generateReplacementPatches_(r[p].base_,e,t)}else e=Qe(t,r);return Ft(t,e,!0),be(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Ve?e:void 0}function Qe(e,t){if(ie(t))return t;const r=t[p];if(!r)return ae(t,e.handledSet_,e);if(!ce(r,e))return t;if(!r.modified_)return r.base_;if(!r.finalized_){const{callbacks_:n}=r;if(n)for(;n.length>0;)n.pop()(e);et(r,e)}return r.copy_}function Ft(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Ae(t,r)}function Xe(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var ce=(e,t)=>e.scope_===t,xt=[];function Ze(e,t,r,n){const s=D(e),i=e.type_;if(n!==void 0&&me(s,n,i)===t){ee(s,n,r,i);return}if(!e.draftLocations_){const u=e.draftLocations_=new Map;Z(s,(m,h)=>{if(v(h)){const _=u.get(h)||[];_.push(m),u.set(h,_)}})}const c=e.draftLocations_.get(t)??xt;for(const u of c)ee(s,u,r,i)}function Nt(e,t,r){e.callbacks_.push(function(s){var u;const i=t;if(!i||!ce(i,s))return;(u=s.mapSetPlugin_)==null||u.fixSetContents(i);const c=we(i);Ze(e,i.draft_??i,c,r),et(i,s)})}function et(e,t){var n;if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(((n=e.assigned_)==null?void 0:n.size)??0)>0)){const{patchPlugin_:s}=t;if(s){const i=s.getPath(e);i&&s.generatePatches_(e,i,t)}Xe(e)}}function $t(e,t,r){const{scope_:n}=e;if(v(r)){const s=r[p];ce(s,n)&&s.callbacks_.push(function(){fe(e);const c=we(s);Ze(e,r,c,t)})}else b(r)&&e.callbacks_.push(function(){const i=D(e);e.type_===3?i.has(r)&&ae(r,n.handledSet_,n):me(i,t,e.type_)===r&&n.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&ae(me(e.copy_,t,e.type_),n.handledSet_,n)})}function ae(e,t,r){return!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||v(e)||t.has(e)||!b(e)||ie(e)||(t.add(e),Z(e,(n,s)=>{if(v(s)){const i=s[p];if(ce(i,r)){const c=we(i);ee(e,n,c,e.type_),Xe(i)}}else b(s)&&ae(s,t,r)})),e}function Rt(e,t){const r=te(e),n={type_:r?1:0,scope_:t?t.scope_:He(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let s=n,i=ue;r&&(s=[n],i=q);const{revoke:c,proxy:u}=Proxy.revocable(s,i);return n.draft_=u,n.revoke_=c,[u,n]}var ue={get(e,t){if(t===p)return e;let r=e.scope_.arrayMethodsPlugin_;const n=e.type_===1&&typeof t=="string";if(n&&r!=null&&r.isArrayOperationMethod(t))return r.createMethodInterceptor(e,t);const s=D(e);if(!Be(s,t,e.type_))return kt(e,s,t);const i=s[t];if(e.finalized_||!b(i)||n&&e.operationMethod&&(r!=null&&r.isMutatingArrayMethod(e.operationMethod))&&zt(t))return i;if(i===Ie(e.base_,t)){fe(e);const c=e.type_===1?+t:t,u=Ce(e.scope_,i,e,c);return e.copy_[c]=u}return i},has(e,t){return t in D(e)},ownKeys(e){return Reflect.ownKeys(D(e))},set(e,t,r){const n=tt(D(e),t);if(n!=null&&n.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const s=Ie(D(e),t),i=s==null?void 0:s[p];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_.set(t,!1),!0;if(Ct(r,s)&&(r!==void 0||Be(e.base_,t,e.type_)))return!0;fe(e),Me(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_.set(t,!0),$t(e,t,r)),!0},deleteProperty(e,t){return fe(e),Ie(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),Me(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const r=D(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{[X]:!0,[ye]:e.type_!==1||t!=="length",[Q]:n[Q],[B]:r[t]}},defineProperty(){w(11)},getPrototypeOf(e){return R(e.base_)},setPrototypeOf(){w(12)}},q={};for(let e in ue){let t=ue[e];q[e]=function(){const r=arguments;return r[0]=r[0][0],t.apply(this,r)}}q.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&w(13),q.set.call(this,e,t,void 0)},q.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&w(14),ue.set.call(this,e[0],t,r,e[0])};function Ie(e,t){const r=e[p];return(r?D(r):e)[t]}function kt(e,t,r){var s;const n=tt(t,r);return n?B in n?n[B]:(s=n.get)==null?void 0:s.call(e.draft_):void 0}function tt(e,t){if(!(t in e))return;let r=R(e);for(;r;){const n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=R(r)}}function Me(e){e.modified_||(e.modified_=!0,e.parent_&&Me(e.parent_))}function fe(e){e.copy_||(e.assigned_=new Map,e.copy_=Se(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Lt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(t,r,n)=>{if(E(t)&&!E(r)){const i=r;r=t;const c=this;return function(m=i,...h){return c.produce(m,_=>r.call(this,_,...h))}}E(r)||w(6),n!==void 0&&!E(n)&&w(7);let s;if(b(t)){const i=Je(this),c=Ce(i,t,void 0);let u=!0;try{s=r(c),u=!1}finally{u?be(i):De(i)}return Ke(i,n),Ye(s,i)}else if(!t||!pe(t)){if(s=r(t),s===void 0&&(s=t),s===Ve&&(s=void 0),this.autoFreeze_&&Ae(s,!0),n){const i=[],c=[];F(Pe).generateReplacementPatches_(t,s,{patches_:i,inversePatches_:c}),n(i,c)}return s}else w(1,t)},this.produceWithPatches=(t,r)=>{if(E(t))return(c,...u)=>this.produceWithPatches(c,m=>t(m,...u));let n,s;return[this.produce(t,r,(c,u)=>{n=c,s=u}),n,s]},ge(e==null?void 0:e.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),ge(e==null?void 0:e.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),ge(e==null?void 0:e.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){b(e)||w(8),v(e)&&(e=Vt(e));const t=Je(this),r=Ce(t,e,void 0);return r[p].isManual_=!0,De(t),r}finishDraft(e,t){const r=e&&e[p];(!r||!r.isManual_)&&w(9);const{scope_:n}=r;return Ke(n,t),Ye(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const s=t[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(t=t.slice(r+1));const n=F(Pe).applyPatches_;return v(e)?n(e,t):this.produce(e,s=>n(s,t))}};function Ce(e,t,r,n){const[s,i]=re(t)?F(oe).proxyMap_(t,r):ne(t)?F(oe).proxySet_(t,r):Rt(t,r);return((r==null?void 0:r.scope_)??He()).drafts_.push(s),i.callbacks_=(r==null?void 0:r.callbacks_)??[],i.key_=n,r&&n!==void 0?Nt(r,i,n):i.callbacks_.push(function(m){var _;(_=m.mapSetPlugin_)==null||_.fixSetContents(i);const{patchPlugin_:h}=m;i.modified_&&h&&h.generatePatches_(i,[],m)}),s}function Vt(e){return v(e)||w(10,e),rt(e)}function rt(e){if(!b(e)||ie(e))return e;const t=e[p];let r,n=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=Se(e,t.scope_.immer_.useStrictShallowCopy_),n=t.scope_.immer_.shouldUseStrictIteration()}else r=Se(e,!0);return Z(r,(s,i)=>{ee(r,s,rt(i))},n),t&&(t.finalized_=!1),r}var Ot=new Lt,nt=Ot.produce;class st extends T{constructor(t,r){super(r),this.a=t,this.push=(...n)=>{n.length!==0&&this.a.set(this.a.get().concat(n))},this.unshift=(...n)=>{n.length!==0&&this.a.set(n.concat(this.a.get()))},this.update=n=>{const s=this.a.get(),i=nt(s,c=>void n(c));i!==s&&this.a.set(i)},this.filter=n=>{const s=this.a.get().filter(n??jt);s.length!==this.a.get().length&&this.a.set(s)},this.add=n=>{this.a.get().includes(n)||this.a.set(this.a.get().concat([n]))},this.removeFirst=n=>{const s=this.a.get().indexOf(n);if(s<0)return;const i=this.a.get().slice(0);i.splice(s,1),this.a.set(i)},this.toggle=(n,s)=>{const i=this.a.get().slice(),c=i.indexOf(n);c<0?s?i.unshift(n):i.push(n):i.splice(c,1),this.a.set(i)}}}const jt=e=>e;class it extends T{constructor(t,r){super(r),this.a=t,this.toggle=()=>{this.a.set(!this.a.get())}}}class ot extends T{constructor(t,r){super(r),this.a=t,this.setValue=(n,s)=>{if(this.a.get().get(n)===s)return;const i=new Map(this.a.get());i.set(n,s),this.a.set(i)},this.setIfNo=(n,s)=>{if(this.a.get().has(n))return;const i=new Map(this.a.get());i.set(n,s),this.a.set(i)},this.delete=n=>{if(!this.a.get().has(n))return;const s=new Map(this.a.get());s.delete(n),this.a.set(s)},this.toggle=(n,s)=>{const i=new Map(this.a.get());i.has(n)?i.delete(n):i.set(n,s),this.a.set(i)},this.clear=()=>{this.a.set(new Map)},this.a=t}}class ct extends T{constructor(t,r){super(r),this.a=t,this.increment=n=>{this.a.set(+this.a.get()+(n??1))}}}class at extends T{constructor(t,r){super(r),this.a=t,this.setPartial=n=>this.a.set(s=>({...s,...typeof n=="function"?n(this.a.get()):n})),this.update=n=>{const s=this.a.get(),i=nt(s,c=>void n(c));i!==s&&this.a.set(i)},this.setDeepPartial=(n,s,i,c=z.keyPathSeparator||".")=>{if(!c)return;if(n.includes(c)){let h=n.split(c);const _=h[h.length-1];h=h.slice(0,-1);const H={...this.a.get()};let y=H,g=i;for(const A of h){g=g==null?void 0:g[Array.isArray(g)?"0":A];const x=y[ut(y,A)]??(Array.isArray(g)?[]:{});if(x==null||typeof x!="object"){if(i==null)throw"Incorrect path for setDeepPartial";const I=typeof s=="function"?s(void 0):s;this.a.get()[n]!==I&&this.setPartial({[n]:I});return}y=y[ut(y,A)]=Array.isArray(x)?[...x]:{...x}}const _e=y[_];y[_]=typeof s=="function"?s(y[_]):s,_e!==y[_]&&this.a.set(H);return}const u=this.a.get()[n],m=typeof s=="function"?s(u):s;m!==u&&this.setPartial({[n]:m})}}}const ut=(e,t)=>Array.isArray(e)?`${+t}`:t;class ft extends T{constructor(t,r){super(r),this.a=t,this.add=n=>{this.a.get().has(n)||this.a.set(new Set(this.a.get()).add(n))},this.delete=n=>{if(!this.a.get().has(n))return;const s=new Set(this.a.get());s.delete(n),this.a.set(s)},this.toggle=n=>{const s=new Set(this.a.get());s.has(n)?s.delete(n):s.add(n),this.a.set(s)},this.clear=()=>{this.a.set(new Set)},this.a=t}}const Ut=(e,t,r)=>{const n=typeof r=="object"&&r!=null&&"do"in r?r.do((i,c)=>t.set(i,c),()=>t.get(),t,(i,c,u)=>t.setDeferred(i,c,u)):null,s={};return n&&Object.keys(n).forEach(i=>Object.defineProperty(s,i,{get:()=>n[i]})),typeof e=="number"?new ct(t,n):typeof e=="boolean"?new it(t,n):Array.isArray(e)?new st(t,n):e instanceof Set?new ft(t,n):e instanceof Map?new ot(t,n):e instanceof Object?new at(t,n):new T(n)};class lt{constructor(t,r){t=typeof t=="function"?t():t;const n=o=>h=o,s=()=>h,i=new Set,c=o=>o(y());let u=!0,m=!1,h=t,_,H=()=>{},y=()=>s(),g=null,_e=()=>{const o=Ut(t,A,r);return _e=()=>o,o};const A=new Proxy(this,{get:(o,l)=>l==="do"?_e():o[l],set:Bt}),x=()=>{u=!0,m!==!0&&H(y()),m=!1;try{ze.postMessage({key:f,value:s()})}catch{}},I=(o,l)=>{const M=typeof o=="function"?o(y()):o;M!==y()&&(n(M),m=l,u&&(u=!1,i.forEach(c),queueMicrotask(x)))};this.set=(o,l)=>I(o,l),this.get=()=>y(),this.initialValue=t,this.isInitialValue=()=>t===s(),this.subscribe=o=>(i.add(o),()=>{i.delete(o)}),this.reset=()=>{I(t,!0)};const Ht=(o,l)=>{I(o,l),_=void 0};if(this.setDeferred=(o,l=500,M,C=!0)=>{C&&_===void 0&&I(o,M),clearTimeout(_),_=setTimeout(Ht,l,o,M)},r==null)return A;let P=null,K=null,Fe=!0,xe=!0,Ne=!1,N=0,O=0,yt=-1,j=t instanceof Set?o=>new Set(o):t instanceof Map?o=>new Map(o):o=>o,U=t instanceof Set?o=>{if(o instanceof Set)return Array.from(o);throw console.error(o),"The value is not Set instance"}:t instanceof Map?o=>{if(o instanceof Map){const l=[];return o.forEach((M,C)=>l.push([C,M])),l}throw console.error(o),"The value is not Set instance"}:o=>o;if(typeof r=="string")P=r;else if("storeKey"in r)Fe=r.warnOnDuplicateStoreKey??Fe,xe=r.listenStorageChanges??xe,P=r.storeKey,j=r.unzipValue??j,U=r.zipValue??U,Ne=r.unchangable??Ne,N=r.securifyKeyLevel??z.securifyKeyLevel??N,O=r.securifyValueLevel??z.securifyValueLevel??O,K=r.exp??K;else return A;const $e=N?V(P,N):P,f=`${O?ve:L}${$e}`;if(N){const o=`${L}${P}`;o in a&&(a[f]=a[o],delete a[o])}else{const o=`${L}${V(P,N)}`;o in a&&(a[f]=a[o],delete a[o])}const Re=K===null||!(K(A,f in a)instanceof Date)?o=>V([U(o)],0):o=>(g??(g={}),g.exp=K(A,f in a).getTime(),g.exp-Date.now()<24*60*60*1e3&&(clearTimeout(yt),clearTimeout(dt[f]),yt=setTimeout(()=>this.reset(),g.exp-Date.now())),g.exp=Math.trunc(g.exp/1e3),V([U(o),g],0));if(O){const o=`${L}${$e}`,l=U,M=j;if(U=C=>{try{return V([l(C)],O)}catch{return delete a[f],""}},o in a){const C=`${L}${V(P,N)}`;try{a[C]=Re(j(he(a[o],0)[0])),delete a[o]}catch{}}j=C=>{try{return M(he(C,O)[0])}catch{return delete a[f],""}}}else delete a[`${ve}${$e}`];const mt=o=>{const l=he(o,0);return g=l[1],j(l[0])};let pt=!0;if(Te[f]=A,a[`atom/${P}`]&&(a[f]||(a[f]=`[${a[`atom/${P}`]}]`),delete a[`atom/${P}`]),y=()=>{if(y=s,pt){pt=!1;try{n(f in a?mt(a[f]):t)}catch{console.warn("Invalid json value",a[f])}}return s()},H=o=>{if(o===t){this.reset();return}a[f]=Re(o)},this.reset=()=>{delete a[f],I(t,!0)},Fe&&k[f]!==void 0&&console.warn("Duplicate Atom key",P),xe)if(Ne){let o=!1,l;le[f]=this,k[f]=()=>{clearTimeout(l),l=setTimeout(()=>o=!1,10),!o&&(o=!0,a[f]=Re(s()))}}else k[f]=o=>{if(o.newValue===null){this.reset();return}try{I(mt(o.newValue))}catch{console.warn("Invalid json value",o.newValue)}};return A}}let ze;try{ze=new BroadcastChannel("updateHere"),ze.addEventListener("message",e=>{var t;(t=le[e.data.key])==null||t.set(e.data.value,!0)})}catch{}const a=localStorage,k={},le={},Bt=(e,t)=>{throw`${t} is readonly property`};window.addEventListener("storage",e=>{var t;e.key===null||e.newValue===e.oldValue||(t=k[e.key])==null||t.call(k,e)});const Wt=a.setItem.bind(a),Gt=a.removeItem.bind(a);a.setItem=(e,t)=>{le[e]===void 0&&Wt.call(a,e,t)},a.removeItem=e=>{le[e]===void 0&&Gt.call(a,e)};const qt=/"exp":\s*(\d+)/,L="atom\\",ve="atom`s\\",Te={},dt={},ht=/[a-z]/gi,de=5,Ee={};for(let e=54;e<80;e++){if(e===68||e===72||e===55)continue;const t=String.fromCharCode(e+43).toUpperCase(),r=String.fromCharCode(e+43).toLowerCase();Ee[t]=r,Ee[r]=t}const _t=e=>Ee[e]??e,V=(()=>{const e=[t=>JSON.stringify(t),t=>btoa(encodeURI(e[0](t))),t=>{const r=e[1](t);return`${r.slice(0,de)}${r.slice(de).replace(ht,_t)}`},t=>btoa(e[2](t))];return(t,r)=>{try{return e[r](t)}catch(n){if(r===0)throw n;return e[0](t)}}})(),he=(()=>{const e=[t=>JSON.parse(t),t=>e[0](decodeURI(atob(t))),t=>e[1](`${t.slice(0,de)}${t.slice(de).replace(ht,_t)}`),t=>e[2](atob(t))];return(t,r)=>{try{return e[r](t)}catch(n){if(r===0)throw n;return e[0](t)}}})();setTimeout(()=>{Object.keys(a).forEach(e=>{var n;if(typeof a[e]!="string"||!e.startsWith(L)&&!e.startsWith(ve))return;const t=(n=a[e].match(qt))==null?void 0:n[1];if(!t||+t*1e3-Date.now()>24*60*60*1e3)return;const r=he(a[e],0);!Array.isArray(r)||r[1]==null||!("exp"in r[1])||r[1].exp!==t||(dt[e]=setTimeout(()=>{Te[e]?Te[e].reset():delete a[e]},+t*1e3-Date.now()))})},1e3),d.Atom=lt,d.AtomArrayDoActions=st,d.AtomBooleanDoActions=it,d.AtomMapDoActions=ot,d.AtomNumberDoActions=ct,d.AtomObjectDoActions=at,d.AtomSetDoActions=ft,d.atom=Dt,d.configureAtomaric=wt,d.configuredOptions=z,d.useAtom=bt,d.useAtomDo=Pt,d.useAtomGet=At,d.useAtomSet=Le,d.useAtomSetDeferred=St,d.useAtomValue=ke,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(d,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(d=typeof globalThis<"u"?globalThis:d||self,$(d.atomaric={}))})(this,function(d){"use strict";let $=()=>{throw"call configureAtomaric() before all!"};const z={},St=e=>{z.useSyncExternalStore=$=e.useSyncExternalStore,z.keyPathSeparator=e.keyPathSeparator,z.securifyKeyLevel=e.securifyKeyLevel,z.securifyValueLevel=e.securifyValueLevel},Le=e=>$(e.subscribe,e.get),Ve=e=>e.set,At=e=>e.setDeferred,Pt=e=>e.get,bt=e=>e.do,Dt=e=>[Le(e),Ve(e)],It=(e,t)=>new dt(e,t);class T{constructor(t){if(t)return new Proxy(this,{get:(r,n)=>n in this?r[n]:t[n]})}}var je=Symbol.for("immer-nothing"),Oe=Symbol.for("immer-draftable"),y=Symbol.for("immer-state"),Mt=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function g(e,...t){if(process.env.NODE_ENV!=="production"){const r=Mt[e],n=E(r)?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var w=Object,R=w.getPrototypeOf,Y="constructor",Q="prototype",me="configurable",X="enumerable",Z="writable",G="value",v=e=>!!e&&!!e[y];function I(e){var t;return e?Be(e)||re(e)||!!e[Oe]||!!((t=e[Y])!=null&&t[Oe])||ne(e)||se(e):!1}var Ct=w[Q][Y].toString(),Ue=new WeakMap;function Be(e){if(!e||!ge(e))return!1;const t=R(e);if(t===null||t===w[Q])return!0;const r=w.hasOwnProperty.call(t,Y)&&t[Y];if(r===Object)return!0;if(!E(r))return!1;let n=Ue.get(r);return n===void 0&&(n=Function.toString.call(r),Ue.set(r,n)),n===Ct}function ee(e,t,r=!0){q(e)===0?(r?Reflect.ownKeys(e):w.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((n,s)=>t(s,n,e))}function q(e){const t=e[y];return t?t.type_:re(e)?1:ne(e)?2:se(e)?3:0}var We=(e,t,r=q(e))=>r===2?e.has(t):w[Q].hasOwnProperty.call(e,t),pe=(e,t,r=q(e))=>r===2?e.get(t):e[t],te=(e,t,r,n=q(e))=>{n===2?e.set(t,r):n===3?e.add(r):e[t]=r};function zt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var re=Array.isArray,ne=e=>e instanceof Map,se=e=>e instanceof Set,ge=e=>typeof e=="object",E=e=>typeof e=="function",we=e=>typeof e=="boolean";function vt(e){const t=+e;return Number.isInteger(t)&&String(t)===e}var M=e=>e.copy_||e.base_,Se=e=>e.modified_?e.copy_:e.base_;function Ae(e,t){if(ne(e))return new Map(e);if(se(e))return new Set(e);if(re(e))return Array[Q].slice.call(e);const r=Be(e);if(t===!0||t==="class_only"&&!r){const n=w.getOwnPropertyDescriptors(e);delete n[y];let s=Reflect.ownKeys(n);for(let i=0;i<s.length;i++){const c=s[i],u=n[c];u[Z]===!1&&(u[Z]=!0,u[me]=!0),(u.get||u.set)&&(n[c]={[me]:!0,[Z]:!0,[X]:u[X],[G]:e[c]})}return w.create(R(e),n)}else{const n=R(e);if(n!==null&&r)return{...e};const s=w.create(n);return w.assign(s,e)}}function Pe(e,t=!1){return oe(e)||v(e)||!I(e)||(q(e)>1&&w.defineProperties(e,{set:ie,add:ie,clear:ie,delete:ie}),w.freeze(e),t&&ee(e,(r,n)=>{Pe(n,!0)},!1)),e}function Tt(){g(2)}var ie={[G]:Tt};function oe(e){return e===null||!ge(e)?!0:w.isFrozen(e)}var ce="MapSet",be="Patches",Ge="ArrayMethods",qe={};function F(e){const t=qe[e];return t||g(0,e),t}var He=e=>!!qe[e],H,Je=()=>H,Et=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:He(ce)?F(ce):void 0,arrayMethodsPlugin_:He(Ge)?F(Ge):void 0});function Ke(e,t){t&&(e.patchPlugin_=F(be),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function De(e){Ie(e),e.drafts_.forEach(Ft),e.drafts_=null}function Ie(e){e===H&&(H=e.parent_)}var Ye=e=>H=Et(H,e);function Ft(e){const t=e[y];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Qe(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];if(e!==void 0&&e!==r){r[y].modified_&&(De(t),g(4)),I(e)&&(e=Xe(t,e));const{patchPlugin_:s}=t;s&&s.generateReplacementPatches_(r[y].base_,e,t)}else e=Xe(t,r);return xt(t,e,!0),De(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==je?e:void 0}function Xe(e,t){if(oe(t))return t;const r=t[y];if(!r)return ue(t,e.handledSet_,e);if(!ae(r,e))return t;if(!r.modified_)return r.base_;if(!r.finalized_){const{callbacks_:n}=r;if(n)for(;n.length>0;)n.pop()(e);tt(r,e)}return r.copy_}function xt(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Pe(t,r)}function Ze(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var ae=(e,t)=>e.scope_===t,Nt=[];function et(e,t,r,n){const s=M(e),i=e.type_;if(n!==void 0&&pe(s,n,i)===t){te(s,n,r,i);return}if(!e.draftLocations_){const u=e.draftLocations_=new Map;ee(s,(_,h)=>{if(v(h)){const m=u.get(h)||[];m.push(_),u.set(h,m)}})}const c=e.draftLocations_.get(t)??Nt;for(const u of c)te(s,u,r,i)}function $t(e,t,r){e.callbacks_.push(function(s){var u;const i=t;if(!i||!ae(i,s))return;(u=s.mapSetPlugin_)==null||u.fixSetContents(i);const c=Se(i);et(e,i.draft_??i,c,r),tt(i,s)})}function tt(e,t){var n;if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(((n=e.assigned_)==null?void 0:n.size)??0)>0)){const{patchPlugin_:s}=t;if(s){const i=s.getPath(e);i&&s.generatePatches_(e,i,t)}Ze(e)}}function Rt(e,t,r){const{scope_:n}=e;if(v(r)){const s=r[y];ae(s,n)&&s.callbacks_.push(function(){le(e);const c=Se(s);et(e,r,c,t)})}else I(r)&&e.callbacks_.push(function(){const i=M(e);e.type_===3?i.has(r)&&ue(r,n.handledSet_,n):pe(i,t,e.type_)===r&&n.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&ue(pe(e.copy_,t,e.type_),n.handledSet_,n)})}function ue(e,t,r){return!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||v(e)||t.has(e)||!I(e)||oe(e)||(t.add(e),ee(e,(n,s)=>{if(v(s)){const i=s[y];if(ae(i,r)){const c=Se(i);te(e,n,c,e.type_),Ze(i)}}else I(s)&&ue(s,t,r)})),e}function kt(e,t){const r=re(e),n={type_:r?1:0,scope_:t?t.scope_:Je(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let s=n,i=fe;r&&(s=[n],i=J);const{revoke:c,proxy:u}=Proxy.revocable(s,i);return n.draft_=u,n.revoke_=c,[u,n]}var fe={get(e,t){if(t===y)return e;let r=e.scope_.arrayMethodsPlugin_;const n=e.type_===1&&typeof t=="string";if(n&&r!=null&&r.isArrayOperationMethod(t))return r.createMethodInterceptor(e,t);const s=M(e);if(!We(s,t,e.type_))return Lt(e,s,t);const i=s[t];if(e.finalized_||!I(i)||n&&e.operationMethod&&(r!=null&&r.isMutatingArrayMethod(e.operationMethod))&&vt(t))return i;if(i===Me(e.base_,t)){le(e);const c=e.type_===1?+t:t,u=ze(e.scope_,i,e,c);return e.copy_[c]=u}return i},has(e,t){return t in M(e)},ownKeys(e){return Reflect.ownKeys(M(e))},set(e,t,r){const n=rt(M(e),t);if(n!=null&&n.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const s=Me(M(e),t),i=s==null?void 0:s[y];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_.set(t,!1),!0;if(zt(r,s)&&(r!==void 0||We(e.base_,t,e.type_)))return!0;le(e),Ce(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_.set(t,!0),Rt(e,t,r)),!0},deleteProperty(e,t){return le(e),Me(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),Ce(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const r=M(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{[Z]:!0,[me]:e.type_!==1||t!=="length",[X]:n[X],[G]:r[t]}},defineProperty(){g(11)},getPrototypeOf(e){return R(e.base_)},setPrototypeOf(){g(12)}},J={};for(let e in fe){let t=fe[e];J[e]=function(){const r=arguments;return r[0]=r[0][0],t.apply(this,r)}}J.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&g(13),J.set.call(this,e,t,void 0)},J.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&g(14),fe.set.call(this,e[0],t,r,e[0])};function Me(e,t){const r=e[y];return(r?M(r):e)[t]}function Lt(e,t,r){var s;const n=rt(t,r);return n?G in n?n[G]:(s=n.get)==null?void 0:s.call(e.draft_):void 0}function rt(e,t){if(!(t in e))return;let r=R(e);for(;r;){const n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=R(r)}}function Ce(e){e.modified_||(e.modified_=!0,e.parent_&&Ce(e.parent_))}function le(e){e.copy_||(e.assigned_=new Map,e.copy_=Ae(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Vt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(t,r,n)=>{if(E(t)&&!E(r)){const i=r;r=t;const c=this;return function(_=i,...h){return c.produce(_,m=>r.call(this,m,...h))}}E(r)||g(6),n!==void 0&&!E(n)&&g(7);let s;if(I(t)){const i=Ye(this),c=ze(i,t,void 0);let u=!0;try{s=r(c),u=!1}finally{u?De(i):Ie(i)}return Ke(i,n),Qe(s,i)}else if(!t||!ge(t)){if(s=r(t),s===void 0&&(s=t),s===je&&(s=void 0),this.autoFreeze_&&Pe(s,!0),n){const i=[],c=[];F(be).generateReplacementPatches_(t,s,{patches_:i,inversePatches_:c}),n(i,c)}return s}else g(1,t)},this.produceWithPatches=(t,r)=>{if(E(t))return(c,...u)=>this.produceWithPatches(c,_=>t(_,...u));let n,s;return[this.produce(t,r,(c,u)=>{n=c,s=u}),n,s]},we(e==null?void 0:e.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),we(e==null?void 0:e.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),we(e==null?void 0:e.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){I(e)||g(8),v(e)&&(e=jt(e));const t=Ye(this),r=ze(t,e,void 0);return r[y].isManual_=!0,Ie(t),r}finishDraft(e,t){const r=e&&e[y];(!r||!r.isManual_)&&g(9);const{scope_:n}=r;return Ke(n,t),Qe(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const s=t[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(t=t.slice(r+1));const n=F(be).applyPatches_;return v(e)?n(e,t):this.produce(e,s=>n(s,t))}};function ze(e,t,r,n){const[s,i]=ne(t)?F(ce).proxyMap_(t,r):se(t)?F(ce).proxySet_(t,r):kt(t,r);return((r==null?void 0:r.scope_)??Je()).drafts_.push(s),i.callbacks_=(r==null?void 0:r.callbacks_)??[],i.key_=n,r&&n!==void 0?$t(r,i,n):i.callbacks_.push(function(_){var m;(m=_.mapSetPlugin_)==null||m.fixSetContents(i);const{patchPlugin_:h}=_;i.modified_&&h&&h.generatePatches_(i,[],_)}),s}function jt(e){return v(e)||g(10,e),nt(e)}function nt(e){if(!I(e)||oe(e))return e;const t=e[y];let r,n=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=Ae(e,t.scope_.immer_.useStrictShallowCopy_),n=t.scope_.immer_.shouldUseStrictIteration()}else r=Ae(e,!0);return ee(r,(s,i)=>{te(r,s,nt(i))},n),t&&(t.finalized_=!1),r}var Ot=new Vt,st=Ot.produce;class it extends T{constructor(t,r){super(r),this.a=t,this.push=(...n)=>{n.length!==0&&this.a.set(this.a.get().concat(n))},this.unshift=(...n)=>{n.length!==0&&this.a.set(n.concat(this.a.get()))},this.update=n=>{const s=this.a.get(),i=st(s,c=>void n(c));i!==s&&this.a.set(i)},this.filter=n=>{const s=this.a.get().filter(n??Ut);s.length!==this.a.get().length&&this.a.set(s)},this.add=n=>{this.a.get().includes(n)||this.a.set(this.a.get().concat([n]))},this.removeFirst=n=>{const s=this.a.get().indexOf(n);if(s<0)return;const i=this.a.get().slice(0);i.splice(s,1),this.a.set(i)},this.toggle=(n,s)=>{const i=this.a.get().slice(),c=i.indexOf(n);c<0?s?i.unshift(n):i.push(n):i.splice(c,1),this.a.set(i)}}}const Ut=e=>e;class ot extends T{constructor(t,r){super(r),this.a=t,this.toggle=()=>{this.a.set(!this.a.get())}}}class ct extends T{constructor(t,r){super(r),this.a=t,this.setValue=(n,s)=>{if(this.a.get().get(n)===s)return;const i=new Map(this.a.get());i.set(n,s),this.a.set(i)},this.setIfNo=(n,s)=>{if(this.a.get().has(n))return;const i=new Map(this.a.get());i.set(n,s),this.a.set(i)},this.delete=n=>{if(!this.a.get().has(n))return;const s=new Map(this.a.get());s.delete(n),this.a.set(s)},this.toggle=(n,s)=>{const i=new Map(this.a.get());i.has(n)?i.delete(n):i.set(n,s),this.a.set(i)},this.clear=()=>{this.a.set(new Map)},this.a=t}}class at extends T{constructor(t,r){super(r),this.a=t,this.increment=n=>{this.a.set(+this.a.get()+(n??1))}}}class ut extends T{constructor(t,r){super(r),this.a=t,this.setPartial=n=>this.a.set(s=>({...s,...typeof n=="function"?n(this.a.get()):n})),this.update=n=>{const s=this.a.get(),i=st(s,c=>void n(c));i!==s&&this.a.set(i)},this.setDeepPartial=(n,s,i,c=z.keyPathSeparator||".")=>{if(!c)return;if(n.includes(c)){let h=n.split(c);const m=h[h.length-1];h=h.slice(0,-1);const x={...this.a.get()};let A=x,p=i;for(const j of h){p=p==null?void 0:p[Array.isArray(p)?"0":j];const S=A[ft(A,j)]??(Array.isArray(p)?[]:{});if(S==null||typeof S!="object"){if(i==null)throw"Incorrect path for setDeepPartial";const ye=typeof s=="function"?s(void 0):s;this.a.get()[n]!==ye&&this.setPartial({[n]:ye});return}A=A[ft(A,j)]=Array.isArray(S)?[...S]:{...S}}const D=A[m];A[m]=typeof s=="function"?s(A[m]):s,D!==A[m]&&this.a.set(x);return}const u=this.a.get()[n],_=typeof s=="function"?s(u):s;_!==u&&this.setPartial({[n]:_})}}}const ft=(e,t)=>Array.isArray(e)?`${+t}`:t;class lt extends T{constructor(t,r){super(r),this.a=t,this.add=n=>{this.a.get().has(n)||this.a.set(new Set(this.a.get()).add(n))},this.delete=n=>{if(!this.a.get().has(n))return;const s=new Set(this.a.get());s.delete(n),this.a.set(s)},this.toggle=n=>{const s=new Set(this.a.get());s.has(n)?s.delete(n):s.add(n),this.a.set(s)},this.clear=()=>{this.a.set(new Set)},this.a=t}}const Bt=(e,t,r)=>{const n=typeof r=="object"&&r!=null&&"do"in r?r.do((i,c)=>t.set(i,c),()=>t.get(),t,(i,c,u)=>t.setDeferred(i,c,u)):null,s={};return n&&Object.keys(n).forEach(i=>Object.defineProperty(s,i,{get:()=>n[i]})),typeof e=="number"?new at(t,n):typeof e=="boolean"?new ot(t,n):Array.isArray(e)?new it(t,n):e instanceof Set?new lt(t,n):e instanceof Map?new ct(t,n):e instanceof Object?new ut(t,n):new T(n)};class dt{constructor(t,r){t=typeof t=="function"?t():t;const n=o=>m=o,s=()=>m,i=new Set,c=o=>o(p());let u=!0,_=!1,h=o=>o,m=t,x,A=()=>{},p=()=>s(),D=null,j=()=>{const o=Bt(t,S,r);return j=()=>o,o};const S=new Proxy(this,{get:(o,l)=>l==="do"?j():o[l],set:Wt}),ye=()=>{u=!0,_!==!0&&A(p()),_=!1;try{ve.postMessage({key:f,value:s()})}catch{}},O=(o,l)=>{let b=typeof o=="function"?o(p()):o;b=h(b,p()),b!==p()&&(n(b),_=l,u&&(u=!1,i.forEach(c),queueMicrotask(ye)))};this.set=(o,l)=>O(o,l),this.get=()=>p(),this.initialValue=t,this.isInitialValue=()=>t===s(),this.subscribe=o=>(i.add(o),()=>{i.delete(o)}),this.reset=()=>{O(t,!0)};const Jt=(o,l)=>{O(o,l),x=void 0};if(this.setDeferred=(o,l=500,b,C=!0)=>{C&&x===void 0&&O(o,b),clearTimeout(x),x=setTimeout(Jt,l,o,b)},r==null)return S;let P=null,K=null,xe=!0,Ne=!0,$e=!1,N=0,U=0,mt=-1,B=t instanceof Set?o=>new Set(o):t instanceof Map?o=>new Map(o):o=>o,W=t instanceof Set?o=>{if(o instanceof Set)return Array.from(o);throw console.error(o),"The value is not Set instance"}:t instanceof Map?o=>{if(o instanceof Map){const l=[];return o.forEach((b,C)=>l.push([C,b])),l}throw console.error(o),"The value is not Set instance"}:o=>o;if(typeof r=="string")P=r;else if(h=r.map??h,"storageKey"in r)xe=r.warnOnDuplicateStorageKey??xe,Ne=r.listenStorageChanges??Ne,P=r.storageKey,B=r.unzipValue??B,W=r.zipValue??W,$e=r.unchangable??$e,N=r.securifyKeyLevel??z.securifyKeyLevel??N,U=r.securifyValueLevel??z.securifyValueLevel??U,K=r.exp??K;else return S;const Re=N?V(P,N):P,f=`${U?Te:L}${Re}`;if(N){const o=`${L}${P}`;o in a&&(a[f]=a[o],delete a[o])}else{const o=`${L}${V(P,N)}`;o in a&&(a[f]=a[o],delete a[o])}const ke=K===null||!(K(S,f in a)instanceof Date)?o=>V([W(o)],0):o=>(D??(D={}),D.exp=K(S,f in a).getTime(),D.exp-Date.now()<24*60*60*1e3&&(clearTimeout(mt),clearTimeout(ht[f]),mt=setTimeout(()=>this.reset(),D.exp-Date.now())),D.exp=Math.trunc(D.exp/1e3),V([W(o),D],0));if(U){const o=`${L}${Re}`,l=W,b=B;if(W=C=>{try{return V([l(C)],U)}catch{return delete a[f],""}},o in a){const C=`${L}${V(P,N)}`;try{a[C]=ke(B(_e(a[o],0)[0])),delete a[o]}catch{}}B=C=>{try{return b(_e(C,U)[0])}catch{return delete a[f],""}}}else delete a[`${Te}${Re}`];const pt=o=>{const l=_e(o,0);return D=l[1],B(l[0])};let gt=!0;if(Ee[f]=S,a[`atom/${P}`]&&(a[f]||(a[f]=`[${a[`atom/${P}`]}]`),delete a[`atom/${P}`]),p=()=>{if(p=s,gt){gt=!1;try{n(f in a?pt(a[f]):t)}catch{console.warn("Invalid json value",a[f])}}return s()},A=o=>{if(o===t){this.reset();return}a[f]=ke(o)},this.reset=()=>{delete a[f],O(t,!0)},xe&&k[f]!==void 0&&console.warn("Duplicate Atom key",P),Ne)if($e){let o=!1,l;de[f]=this,k[f]=()=>{clearTimeout(l),l=setTimeout(()=>o=!1,10),!o&&(o=!0,a[f]=ke(s()))}}else k[f]=o=>{if(o.newValue===null){this.reset();return}try{O(pt(o.newValue))}catch{console.warn("Invalid json value",o.newValue)}};return S}}let ve;try{ve=new BroadcastChannel("updateHere"),ve.addEventListener("message",e=>{var t;(t=de[e.data.key])==null||t.set(e.data.value,!0)})}catch{}const a=localStorage,k={},de={},Wt=(e,t)=>{throw`${t} is readonly property`};window.addEventListener("storage",e=>{var t;e.key===null||e.newValue===e.oldValue||(t=k[e.key])==null||t.call(k,e)});const Gt=a.setItem.bind(a),qt=a.removeItem.bind(a);a.setItem=(e,t)=>{de[e]===void 0&&Gt.call(a,e,t)},a.removeItem=e=>{de[e]===void 0&&qt.call(a,e)};const Ht=/"exp":\s*(\d+)/,L="atom\\",Te="atom`s\\",Ee={},ht={},_t=/[a-z]/gi,he=5,Fe={};for(let e=54;e<80;e++){if(e===68||e===72||e===55)continue;const t=String.fromCharCode(e+43).toUpperCase(),r=String.fromCharCode(e+43).toLowerCase();Fe[t]=r,Fe[r]=t}const yt=e=>Fe[e]??e,V=(()=>{const e=[t=>JSON.stringify(t),t=>btoa(encodeURI(e[0](t))),t=>{const r=e[1](t);return`${r.slice(0,he)}${r.slice(he).replace(_t,yt)}`},t=>btoa(e[2](t))];return(t,r)=>{try{return e[r](t)}catch(n){if(r===0)throw n;return e[0](t)}}})(),_e=(()=>{const e=[t=>JSON.parse(t),t=>e[0](decodeURI(atob(t))),t=>e[1](`${t.slice(0,he)}${t.slice(he).replace(_t,yt)}`),t=>e[2](atob(t))];return(t,r)=>{try{return e[r](t)}catch(n){if(r===0)throw n;return e[0](t)}}})();setTimeout(()=>{Object.keys(a).forEach(e=>{var n;if(typeof a[e]!="string"||!e.startsWith(L)&&!e.startsWith(Te))return;const t=(n=a[e].match(Ht))==null?void 0:n[1];if(!t||+t*1e3-Date.now()>24*60*60*1e3)return;const r=_e(a[e],0);!Array.isArray(r)||r[1]==null||!("exp"in r[1])||r[1].exp!==t||(ht[e]=setTimeout(()=>{Ee[e]?Ee[e].reset():delete a[e]},+t*1e3-Date.now()))})},1e3),d.Atom=dt,d.AtomArrayDoActions=it,d.AtomBooleanDoActions=ot,d.AtomMapDoActions=ct,d.AtomNumberDoActions=at,d.AtomObjectDoActions=ut,d.AtomSetDoActions=lt,d.atom=It,d.configureAtomaric=St,d.configuredOptions=z,d.useAtom=Dt,d.useAtomDo=bt,d.useAtomGet=Pt,d.useAtomSet=Ve,d.useAtomSetDeferred=At,d.useAtomValue=Le,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -21,11 +21,11 @@ export type ObjectActionsSetDeepPartialSeparator = Register extends {
|
|
|
21
21
|
|
|
22
22
|
type Sunscriber<Value> = (value: Value) => void;
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type AtomStorageKey = `${string}${string}:${string}${string}`;
|
|
25
25
|
|
|
26
26
|
export type AtomOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> = {
|
|
27
27
|
/** **default: true** */
|
|
28
|
-
|
|
28
|
+
warnOnDuplicateStorageKey?: boolean;
|
|
29
29
|
/** will update value if localStorage value is changed
|
|
30
30
|
* **default: true**
|
|
31
31
|
*/
|
|
@@ -40,10 +40,13 @@ export type AtomOptions<Value, Actions extends Record<string, AnyFunc> = Record<
|
|
|
40
40
|
unchangable?: true;
|
|
41
41
|
/** return value expire Date */
|
|
42
42
|
exp?: (self: Atom<Value>, isValueWasStoraged: boolean) => Date;
|
|
43
|
+
|
|
44
|
+
/** map setted value */
|
|
45
|
+
map?: (newValue: Value, prevValue: Value) => Value;
|
|
43
46
|
} & (
|
|
44
47
|
| {
|
|
45
48
|
/** save in localStorage by this key */
|
|
46
|
-
|
|
49
|
+
storageKey: AtomStorageKey;
|
|
47
50
|
securifyKeyLevel?: AtomSecureLevel;
|
|
48
51
|
securifyValueLevel?: AtomSecureLevel;
|
|
49
52
|
}
|
|
@@ -79,22 +82,26 @@ export type ObjectActionsSetDeepPartialDoAction<Value> = <
|
|
|
79
82
|
separator?: Sep,
|
|
80
83
|
) => void;
|
|
81
84
|
|
|
82
|
-
export type DefaultActions<Value> =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
export type DefaultActions<Value> =
|
|
86
|
+
Value extends Set<infer Val>
|
|
87
|
+
? IAtomSetDoActions<Val>
|
|
88
|
+
: Value extends Map<infer Key, infer Val>
|
|
89
|
+
? IAtomMapDoActions<Value, Key, Val>
|
|
90
|
+
: Value extends boolean
|
|
91
|
+
? IAtomBooleanDoActions
|
|
92
|
+
: Value extends (infer Val)[]
|
|
93
|
+
? IAtomArrayDoActions<Val>
|
|
94
|
+
: Value extends number
|
|
95
|
+
? IAtomNumberDoActions
|
|
96
|
+
: Value extends object
|
|
97
|
+
? IAtomObjectDoActions<Value>
|
|
98
|
+
: object;
|
|
95
99
|
|
|
96
100
|
declare class Atom<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> {
|
|
97
|
-
constructor(
|
|
101
|
+
constructor(
|
|
102
|
+
initialValue: Value | (() => Value),
|
|
103
|
+
storageKeyOrOptions: StorageKeyOrOptions<Value, Actions> | undefined,
|
|
104
|
+
);
|
|
98
105
|
|
|
99
106
|
/** initial value */
|
|
100
107
|
readonly initialValue: Value;
|
|
@@ -128,13 +135,13 @@ export function useAtomDo<Value, Actions extends Record<string, AnyFunc> = Recor
|
|
|
128
135
|
atom: Atom<Value, Actions>,
|
|
129
136
|
): Actions & DefaultActions<Value>;
|
|
130
137
|
|
|
131
|
-
export type
|
|
132
|
-
|
|
|
138
|
+
export type StorageKeyOrOptions<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>> =
|
|
139
|
+
| AtomStorageKey
|
|
133
140
|
| AtomOptions<Value, Actions>;
|
|
134
141
|
|
|
135
142
|
export function atom<Value, Actions extends Record<string, AnyFunc> = Record<string, AnyFunc>>(
|
|
136
143
|
value: Value | (() => Value),
|
|
137
|
-
|
|
144
|
+
storageKeyOrOptions?: StorageKeyOrOptions<Value, Actions>,
|
|
138
145
|
): Atom<Value, Actions>;
|
|
139
146
|
|
|
140
147
|
/** invoke this function before all atom usages */
|