react-wire-persisted 2.1.0 → 3.1.0

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.
@@ -1,346 +1,245 @@
1
- import { useRef as A, useEffect as T } from "react";
2
- import { createWire as k } from "@forminator/react-wire";
1
+ import { useEffect as e, useRef as t } from "react";
2
+ import { createWire as n } from "@forminator/react-wire";
3
+ //#region \0rolldown/runtime.js
4
+ var r = Object.defineProperty, i = (e, t) => {
5
+ let n = {};
6
+ for (var i in e) r(n, i, {
7
+ get: e[i],
8
+ enumerable: !0
9
+ });
10
+ return t || r(n, Symbol.toStringTag, { value: "Module" }), n;
11
+ };
12
+ //#endregion
13
+ //#region \0rollup-plugin-inject-process-env
3
14
  (function() {
4
- const e = {};
5
- try {
6
- if (process) {
7
- process.env = Object.assign({}, process.env), Object.assign(process.env, e);
8
- return;
9
- }
10
- } catch {
11
- }
12
- globalThis.process = { env: e };
15
+ let e = {};
16
+ try {
17
+ if (process) {
18
+ process.env = Object.assign({}, process.env), Object.assign(process.env, e);
19
+ return;
20
+ }
21
+ } catch {}
22
+ globalThis.process = { env: e };
13
23
  })();
14
- const p = {
15
- __IS_FAKE_LOCAL_STORAGE__: !0
16
- }, S = {
17
- getItem: (e) => p[e],
18
- setItem: (e, t) => {
19
- p[e] = t;
20
- },
21
- removeItem: (e) => {
22
- delete p[e];
23
- },
24
- // Make Object.keys() work properly for _resetAll method
25
- ...p
26
- };
27
- let w = !1, R = !1, O = !1;
28
- typeof window < "u" && (w = !0, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
29
- R = !0;
30
- }) : R = !0);
31
- const u = () => w, I = () => R, b = () => O, U = () => {
32
- O = !0;
33
- }, y = () => {
34
- if (!w) return !1;
35
- try {
36
- const e = "__rwp_test__";
37
- return window.localStorage.setItem(e, "test"), window.localStorage.removeItem(e), !0;
38
- } catch {
39
- return !1;
40
- }
41
- }, P = {}, N = (e) => {
42
- P[e] = e;
43
- }, F = (e) => N(e), x = () => P, K = (e, t = null) => {
44
- const s = t || P;
45
- return e ? Object.keys(s).reduce((r, n) => (r[n] = `${e}.${s[n]}`, r), {}) : s;
46
- }, G = (e) => {
47
- const t = typeof e;
48
- return e === null ? !0 : Array.isArray(e) || t === "object" ? !1 : t !== "function";
49
- }, z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
50
- __proto__: null,
51
- addKey: N,
52
- fakeLocalStorage: S,
53
- getHasHydrated: I,
54
- getHasHydratedStorage: b,
55
- getIsClient: u,
56
- getKeys: x,
57
- getPrefixedKeys: K,
58
- isLocalStorageAvailable: y,
59
- isPrimitive: G,
60
- key: F,
61
- markStorageAsHydrated: U
62
- }, Symbol.toStringTag, { value: "Module" }));
63
- class E {
64
- /**
65
- * Initializes the class
66
- * @param {String} namespace Namespace to prefix all keys with. Mostly used for the logging & reset functions
67
- * @param {Object} registry (Optional) Initialize the storage provider with an existing registry
68
- */
69
- constructor(t, s) {
70
- if (new.target === E)
71
- throw TypeError("StorageProvider is abstract. Extend this class to implement it");
72
- this.namespace = t || null, this.registry = s || /* istanbul ignore next */
73
- {};
74
- }
75
- /**
76
- * Sets the namespace for this storage provider, and migrates
77
- * all stored values to the new namespace
78
- * @param {String} namespace New namespace for this storage provider
79
- */
80
- /* istanbul ignore next */
81
- setNamespace(t) {
82
- }
83
- /**
84
- * Registers an item with it's initial value. This is used for logging, resetting, etc.
85
- * @param {String} key Storage item's key
86
- * @param {*} initialValue Storage item's initial value
87
- */
88
- register(t, s) {
89
- this.registry[t] = s;
90
- }
91
- /**
92
- * Reads an item from storage
93
- * @param {String} key Key for the item to retrieve
94
- */
95
- /* istanbul ignore next */
96
- getItem(t) {
97
- }
98
- /**
99
- * Stores a value
100
- * @param {String} key Item's storage key
101
- * @param {String} value Item's value to store
102
- */
103
- /* istanbul ignore next */
104
- setItem(t, s) {
105
- }
106
- /**
107
- * Removes an item from storage
108
- * @param {String} key Item's storage key
109
- * @param {Boolean} fromRegistry (Optional) If the item should also be removed from the registry
110
- */
111
- /* istanbul ignore next */
112
- removeItem(t, s = !1) {
113
- }
114
- /**
115
- * Gets all stored keys & values
116
- * If a `namespace` was set, only keys prefixed with the namespace will be returned
117
- */
118
- /* istanbul ignore next */
119
- getAll() {
120
- }
121
- /**
122
- *
123
- * @param {Boolean} useInitialValues If values should be replaced with their initial values. If false, keys are removed
124
- * @param {String[]} excludedKeys (Optional) List of keys to exclude
125
- * @param {Boolean} clearRegistry (Optional) If the registry should also be cleared
126
- */
127
- /* istanbul ignore next */
128
- _resetAll(t = !0, s = [], r = !1) {
129
- }
130
- /**
131
- * Resets all values to their initial values
132
- * If a `namespace` is set, only keys prefixed with the namespace will be reset
133
- * @param {String[]} excludedKeys (Optional) List of keys to exclude
134
- */
135
- /* istanbul ignore next */
136
- resetAll(t = []) {
137
- }
138
- /**
139
- * Removes all items from local storage.
140
- * If a `namespace` is set, only keys prefixed with the namespace will be removed
141
- * @param {String[]} excludedKeys (Optional) List of keys to exclude
142
- */
143
- /* istanbul ignore next */
144
- removeAll(t = []) {
145
- }
146
- }
147
- class V extends E {
148
- constructor(t = null, s = {}) {
149
- super(t, s), this.storage = S, this._isUsingFakeStorage = !0;
150
- }
151
- getStorage() {
152
- return y() ? window.localStorage : S;
153
- }
154
- setNamespace(t) {
155
- if (!this.namespace) {
156
- this.namespace = t;
157
- return;
158
- }
159
- if (this.namespace === t) return;
160
- const s = JSON.parse(JSON.stringify(this.getAll()));
161
- this.removeAll();
162
- for (const [r, n] of Object.entries(s)) {
163
- const a = r.replace(this.namespace, t);
164
- this.setItem(a, n);
165
- }
166
- this.namespace = t;
167
- }
168
- getItem(t) {
169
- const s = this.storage.getItem(t);
170
- if (s == null) return null;
171
- try {
172
- return JSON.parse(s);
173
- } catch {
174
- return s;
175
- }
176
- }
177
- setItem(t, s) {
178
- let r = s;
179
- return r != null && (r = G(s) ? s : JSON.stringify(s)), this.storage.setItem(t, r);
180
- }
181
- removeItem(t, s = !1) {
182
- return s && delete this.registry[t], this.storage.removeItem(t);
183
- }
184
- getAll() {
185
- const t = `${this.namespace}.`;
186
- return Object.keys(this.storage).reduce((s, r) => ((!this.namespace || r.startsWith(t)) && (s[r] = this.storage.getItem(r)), s), {});
187
- }
188
- _resetAll(t = !0, s = [], r = !1) {
189
- const n = `${this.namespace}.`;
190
- Object.keys(this.storage).forEach((a) => {
191
- const c = this.namespace ? a.startsWith(n) : !0, _ = s?.includes(a) || !1;
192
- !c || _ || (t ? Object.hasOwn(this.registry, a) ? this.storage.setItem(a, this.registry[a]) : this.storage.removeItem(a) : (this.storage.removeItem(a), r && delete this.registry[a]));
193
- });
194
- }
195
- resetAll(t = [], s = !1) {
196
- this._resetAll(!0, t || [], s);
197
- }
198
- removeAll(t = [], s = !1) {
199
- this._resetAll(!1, t || [], s);
200
- }
201
- /**
202
- * Attempt to upgrade from fake storage to real localStorage
203
- * This is useful for hydration scenarios
204
- */
205
- upgradeToRealStorage() {
206
- return !this._isUsingFakeStorage || !y() ? !1 : (this.storage = window.localStorage, this._isUsingFakeStorage = !1, !0);
207
- }
208
- /**
209
- * Check if currently using fake storage
210
- */
211
- isUsingFakeStorage() {
212
- return this._isUsingFakeStorage;
213
- }
214
- }
215
- const l = Math.random().toString(36).substring(7), i = (...e) => {
216
- typeof globalThis < "u" && globalThis.__RWP_LOGGING_ENABLED__ !== !1 && console.log(...e);
217
- }, v = {
218
- logging: {
219
- enabled: !1
220
- }
221
- };
222
- typeof globalThis < "u" && globalThis.__RWP_LOGGING_ENABLED__ === void 0 && (globalThis.__RWP_LOGGING_ENABLED__ = v.logging.enabled);
223
- i("[RWP] Module initialized, instance ID:", l);
224
- const W = V;
225
- i("[RWP] About to check global storage, instanceId:", l);
226
- let o;
24
+ //#endregion
25
+ //#region src/utils/fakeLocalStorage.ts
26
+ var a = { __IS_FAKE_LOCAL_STORAGE__: "true" }, o = {
27
+ getItem: (e) => a[e],
28
+ setItem: (e, t) => {
29
+ a[e] = t;
30
+ },
31
+ removeItem: (e) => {
32
+ delete a[e];
33
+ },
34
+ ...a
35
+ }, s = !1, c = !1, l = !1;
36
+ typeof window < "u" && (s = !0, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
37
+ c = !0;
38
+ }) : c = !0);
39
+ var u = () => s, d = () => c, f = () => l, p = () => {
40
+ l = !0;
41
+ }, m = () => {
42
+ if (!s) return !1;
43
+ try {
44
+ let e = "__rwp_test__";
45
+ return window.localStorage.setItem(e, "test"), window.localStorage.removeItem(e), !0;
46
+ } catch {
47
+ return !1;
48
+ }
49
+ }, h = {}, g = (e) => {
50
+ h[e] = e;
51
+ }, _ = (e) => g(e), v = () => h, y = (e, t = null) => {
52
+ let n = t || h;
53
+ return e ? Object.keys(n).reduce((t, r) => (t[r] = `${e}.${n[r]}`, t), {}) : n;
54
+ }, b = /* @__PURE__ */ i({
55
+ addKey: () => g,
56
+ fakeLocalStorage: () => o,
57
+ getHasHydrated: () => d,
58
+ getHasHydratedStorage: () => f,
59
+ getIsClient: () => u,
60
+ getKeys: () => v,
61
+ getPrefixedKeys: () => y,
62
+ isLocalStorageAvailable: () => m,
63
+ isPrimitive: () => x,
64
+ key: () => _,
65
+ markStorageAsHydrated: () => p
66
+ }), x = (e) => {
67
+ let t = typeof e;
68
+ return e === null ? !0 : Array.isArray(e) || t === "object" ? !1 : t !== "function";
69
+ }, S = class e {
70
+ constructor(t, n) {
71
+ if (new.target === e) throw TypeError("StorageProvider is abstract. Extend this class to implement it");
72
+ this.namespace = t || null, this.registry = n || ( /* istanbul ignore next */ {});
73
+ }
74
+ register(e, t) {
75
+ this.registry[e] = t;
76
+ }
77
+ upgradeToRealStorage() {
78
+ return !1;
79
+ }
80
+ isUsingFakeStorage() {
81
+ return !1;
82
+ }
83
+ }, C = class extends S {
84
+ constructor(e, t = {}) {
85
+ super(e, t), this.storage = o, this._isUsingFakeStorage = !0;
86
+ }
87
+ getStorage() {
88
+ return m() ? window.localStorage : o;
89
+ }
90
+ setNamespace(e) {
91
+ if (!this.namespace) {
92
+ this.namespace = e;
93
+ return;
94
+ }
95
+ if (this.namespace === e) return;
96
+ let t = JSON.parse(JSON.stringify(this.getAll()));
97
+ this.removeAll();
98
+ for (let [n, r] of Object.entries(t)) {
99
+ let t = n.replace(this.namespace, e);
100
+ this.setItem(t, r);
101
+ }
102
+ this.namespace = e;
103
+ }
104
+ getItem(e) {
105
+ let t = this.storage.getItem(e);
106
+ if (t == null) return null;
107
+ try {
108
+ return JSON.parse(t);
109
+ } catch {
110
+ return t;
111
+ }
112
+ }
113
+ setItem(e, t) {
114
+ return t == null ? this.removeItem(e) : this.storage.setItem(e, JSON.stringify(t));
115
+ }
116
+ removeItem(e, t = !1) {
117
+ return t && delete this.registry[e], this.storage.removeItem(e);
118
+ }
119
+ getAll() {
120
+ let e = `${this.namespace}.`;
121
+ return Object.keys(this.storage).reduce((t, n) => ((!this.namespace || n.startsWith(e)) && (t[n] = this.storage.getItem(n)), t), {});
122
+ }
123
+ _resetAll(e = !0, t = [], n = !1) {
124
+ let r = `${this.namespace}.`;
125
+ Object.keys(this.storage).forEach((i) => {
126
+ let a = this.namespace ? i.startsWith(r) : !0, o = t?.includes(i) || !1;
127
+ !a || o || (e ? Object.hasOwn(this.registry, i) ? this.registry[i] === void 0 || this.registry[i] === null ? this.storage.removeItem(i) : this.storage.setItem(i, JSON.stringify(this.registry[i])) : this.storage.removeItem(i) : (this.storage.removeItem(i), n && delete this.registry[i]));
128
+ });
129
+ }
130
+ resetAll(e = [], t = !1) {
131
+ this._resetAll(!0, e || [], t);
132
+ }
133
+ removeAll(e = [], t = !1) {
134
+ this._resetAll(!1, e || [], t);
135
+ }
136
+ upgradeToRealStorage() {
137
+ return !this._isUsingFakeStorage || !m() ? !1 : (this.storage = window.localStorage, this._isUsingFakeStorage = !1, !0);
138
+ }
139
+ isUsingFakeStorage() {
140
+ return this._isUsingFakeStorage;
141
+ }
142
+ }, w = Math.random().toString(36).substring(7), T = (...e) => {
143
+ typeof globalThis < "u" && globalThis.__RWP_LOGGING_ENABLED__ !== !1 && console.log(...e);
144
+ }, E = {
145
+ logging: { enabled: !1 },
146
+ storageProvider: C
147
+ }, D = { ...E }, O, k = [];
148
+ typeof globalThis < "u" && globalThis.__RWP_LOGGING_ENABLED__ === void 0 && (globalThis.__RWP_LOGGING_ENABLED__ = E.logging.enabled), T("[RWP] Module initialized, instance ID:", w), T("[RWP] About to check global storage, instanceId:", w);
227
149
  try {
228
- globalThis.__RWP_STORAGE__ ? i("[RWP] Using existing global storage in instance:", l) : (i("[RWP] Creating global storage in instance:", l), globalThis.__RWP_STORAGE__ = new W()), o = globalThis.__RWP_STORAGE__, i("[RWP] Storage assigned successfully");
150
+ globalThis.__RWP_STORAGE__ ? T("[RWP] Using existing global storage in instance:", w) : (T("[RWP] Creating global storage in instance:", w), globalThis.__RWP_STORAGE__ = new C("__internal_rwp_storage__")), O = globalThis.__RWP_STORAGE__, T("[RWP] InternalStorage assigned successfully");
229
151
  } catch (e) {
230
- globalThis.__RWP_LOGGING_ENABLED__ && console.error("[RWP] Error setting up global storage:", e), o = new W();
152
+ globalThis.__RWP_LOGGING_ENABLED__ && console.error("[RWP] Error setting up global storage:", e), O = new C("__internal_rwp_storage__");
231
153
  }
232
- let h = { ...v };
233
- const m = [];
234
- typeof globalThis < "u" && (globalThis.__RWP_REGISTERED_WIRES__ ? i("[RWP] Using existing global registeredWires in instance:", l) : (i("[RWP] Creating global registeredWires in instance:", l), globalThis.__RWP_REGISTERED_WIRES__ = /* @__PURE__ */ new Map()));
235
- const g = globalThis.__RWP_REGISTERED_WIRES__ || /* @__PURE__ */ new Map();
236
- i("[RWP] registeredWires Map reference in instance:", l, "size:", g.size);
237
- const j = () => o.namespace, M = () => o, $ = () => h, B = (e) => {
238
- i("[RWP] setNamespace() called with:", e, "registered wires before:", g.size), o.setNamespace(e), o = new W(e || j()), i("[RWP] setNamespace() done, registered wires after:", g.size);
239
- }, J = (e) => {
240
- if (h = {
241
- ...h,
242
- ...e
243
- }, typeof globalThis < "u" && (globalThis.__RWP_LOGGING_ENABLED__ = h.logging.enabled), h.logging.enabled)
244
- for (console.info("Flushing", m.length, "pending logs"); m.length; )
245
- console.log(...m.shift());
246
- }, C = () => {
247
- i("[RWP] refreshAllWires() called in instance:", l, "registered wires:", g.size), f("react-wire-persisted: refreshAllWires() called, registered wires:", g.size), g.forEach((e, t) => {
248
- const s = o.getItem(t), r = e.getValue();
249
- i("[RWP] Checking wire", t, {
250
- storedValue: s,
251
- currentValue: r,
252
- willUpdate: s !== null && s !== r
253
- }), f("react-wire-persisted: Checking wire", t, {
254
- storedValue: s,
255
- currentValue: r,
256
- willUpdate: s !== null && s !== r
257
- }), s !== null && s !== r && (i("[RWP] Refreshing wire", t, "with stored value", s), f("react-wire-persisted: Refreshing wire", t, "with stored value", s), e.setValue(s));
258
- });
154
+ typeof globalThis < "u" && (globalThis.__RWP_REGISTERED_WIRES__ ? T("[RWP] Using existing global registeredWires in instance:", w) : (T("[RWP] Creating global registeredWires in instance:", w), globalThis.__RWP_REGISTERED_WIRES__ = /* @__PURE__ */ new Map()));
155
+ var A = globalThis.__RWP_REGISTERED_WIRES__ || /* @__PURE__ */ new Map();
156
+ T("[RWP] registeredWires Map reference in instance:", w, "size:", A.size);
157
+ var j = () => O.namespace, M = () => O, N = (e) => {
158
+ T("[RWP] setNamespace() called with:", e, "registered wires before:", A.size);
159
+ let t = e || j();
160
+ if (!t) throw Error("react-wire-persisted: Cannot set namespace to null or undefined");
161
+ O.setNamespace(e), O = new C(t), T("[RWP] setNamespace() done, registered wires after:", A.size);
162
+ }, P = () => D, F = (e) => {
163
+ /* istanbul ignore next */
164
+ if (D = {
165
+ ...D,
166
+ ...e
167
+ }, typeof globalThis < "u" && (globalThis.__RWP_LOGGING_ENABLED__ = D.logging.enabled), D.logging.enabled) for (console.info("Flushing", k.length, "pending logs"); k.length;)
168
+ /* istanbul ignore next */
169
+ console.log(...k.shift() || []);
170
+ }, I = () => {
171
+ T("[RWP] refreshAllWires() called in instance:", w, "registered wires:", A.size), R("react-wire-persisted: refreshAllWires() called, registered wires:", A.size), A.forEach((e, t) => {
172
+ let n = O.getItem(t), r = e.getValue();
173
+ T("[RWP] Checking wire", t, {
174
+ storedValue: n,
175
+ currentValue: r,
176
+ willUpdate: n !== null && n !== r
177
+ }), R("react-wire-persisted: Checking wire", t, {
178
+ storedValue: n,
179
+ currentValue: r,
180
+ willUpdate: n !== null && n !== r
181
+ }), n !== null && n !== r && (T("[RWP] Refreshing wire", t, "with stored value", n), R("react-wire-persisted: Refreshing wire", t, "with stored value", n), e.setValue(n));
182
+ });
259
183
  }, L = () => {
260
- if (i("[RWP] upgradeStorage() called in instance:", l, {
261
- isClient: u(),
262
- isUsingFakeStorage: o.isUsingFakeStorage()
263
- }), f("react-wire-persisted: upgradeStorage() called", {
264
- isClient: u(),
265
- isUsingFakeStorage: o.isUsingFakeStorage()
266
- }), !u()) return !1;
267
- const e = o.upgradeToRealStorage();
268
- return i("[RWP] upgradeToRealStorage() returned", e), f("react-wire-persisted: upgradeToRealStorage() returned", e), e && (U(), i("[RWP] Upgraded to real localStorage, calling refreshAllWires()"), f("react-wire-persisted: Upgraded to real localStorage after hydration"), C()), e;
269
- }, f = (...e) => {
270
- h.logging.enabled ? console.log(...e) : m.push(e);
271
- }, q = (e, t = null) => {
272
- if (i("[RWP] createPersistedWire() called in instance:", l, "key:", e, "value:", t), !e && typeof e != "number") throw new Error(`createPersistedWire: Key cannot be a falsey value (${e}}`);
273
- o.register(e, t);
274
- const s = k(t), r = () => s.getValue(), n = (d) => (i(
275
- "[RWP] setValue called in instance:",
276
- l,
277
- "key:",
278
- e,
279
- "isUsingFakeStorage:",
280
- o.isUsingFakeStorage()
281
- ), o.setItem(e, d), s.setValue(d)), a = (d) => {
282
- s.subscribe(d);
283
- };
284
- let c = t;
285
- const _ = b() || !o.isUsingFakeStorage();
286
- if (_ && u()) {
287
- const d = o.getItem(e);
288
- d !== null && (c = d);
289
- }
290
- return f("react-wire-persisted: create", e, {
291
- value: t,
292
- initialValue: c,
293
- hasHydratedStorage: b(),
294
- isUsingFakeStorage: o.isUsingFakeStorage(),
295
- canReadStorage: _
296
- }), c !== t && n(c), g.set(e, {
297
- getValue: r,
298
- setValue: n,
299
- subscribe: a
300
- }), i("[RWP] Wire registered, total wires:", g.size, "keys:", Array.from(g.keys())), {
301
- ...s,
302
- getValue: r,
303
- setValue: n,
304
- subscribe: a
305
- };
306
- };
307
- function Q({ children: e, onUpgrade: t, autoUpgrade: s = !0 }) {
308
- const r = A(!1);
309
- return T(() => {
310
- if (!s || r.current || !u())
311
- return;
312
- const n = () => {
313
- I() && !r.current && L() && (r.current = !0, t?.());
314
- };
315
- n();
316
- const a = setTimeout(n, 0);
317
- return () => clearTimeout(a);
318
- }, [s, t]), e;
319
- }
320
- const X = (e = {}) => {
321
- const { autoUpgrade: t = !0, onUpgrade: s } = e, r = A(!1);
322
- return T(() => {
323
- if (!t || r.current || !u()) return;
324
- const n = () => {
325
- I() && !r.current && L() && (r.current = !0, s?.());
326
- };
327
- n();
328
- const a = setTimeout(n, 0);
329
- return () => clearTimeout(a);
330
- }, [t, s]), {
331
- hasUpgraded: r.current
332
- };
333
- };
334
- export {
335
- Q as HydrationProvider,
336
- q as createPersistedWire,
337
- v as defaultOptions,
338
- j as getNamespace,
339
- $ as getOptions,
340
- M as getStorage,
341
- B as setNamespace,
342
- J as setOptions,
343
- L as upgradeStorage,
344
- X as useHydration,
345
- z as utils
184
+ if (T("[RWP] upgradeStorage() called in instance:", w, {
185
+ isClient: u(),
186
+ isUsingFakeStorage: O.isUsingFakeStorage()
187
+ }), R("react-wire-persisted: upgradeStorage() called", {
188
+ isClient: u(),
189
+ isUsingFakeStorage: O.isUsingFakeStorage()
190
+ }), !u()) return !1;
191
+ let e = O.upgradeToRealStorage();
192
+ return T("[RWP] upgradeToRealStorage() returned", e), R("react-wire-persisted: upgradeToRealStorage() returned", e), e && (p(), T("[RWP] Upgraded to real localStorage, calling refreshAllWires()"), R("react-wire-persisted: Upgraded to real localStorage after hydration"), I()), e;
193
+ }, R = (...e) => {
194
+ /* istanbul ignore next */
195
+ D.logging.enabled ? console.log(...e) : k.push(e);
196
+ }, z = (e, t = null) => {
197
+ if (T("[RWP] createPersistedWire() called in instance:", w, "key:", e, "value:", t), !e) throw Error(`createPersistedWire: Key cannot be a falsey value (${e}}`);
198
+ O.register(e, t);
199
+ let r = n(t), i = () => r.getValue(), a = (t) => (T("[RWP] setValue called in instance:", w, "key:", e, "isUsingFakeStorage:", O.isUsingFakeStorage()), O.setItem(e, t), r.setValue(t)), o = (e) => r.subscribe(e), s = t, c = f() || !O.isUsingFakeStorage();
200
+ if (c && u()) {
201
+ let t = O.getItem(e);
202
+ t !== null && (s = t);
203
+ }
204
+ return R("react-wire-persisted: create", e, {
205
+ value: t,
206
+ initialValue: s,
207
+ hasHydratedStorage: f(),
208
+ isUsingFakeStorage: O.isUsingFakeStorage(),
209
+ canReadStorage: c
210
+ }), s !== t && s !== void 0 && a(s), A.set(e, {
211
+ getValue: i,
212
+ setValue: a,
213
+ subscribe: o
214
+ }), T("[RWP] Wire registered, total wires:", A.size, "keys:", Array.from(A.keys())), {
215
+ ...r,
216
+ getValue: i,
217
+ setValue: a,
218
+ subscribe: o
219
+ };
220
+ }, B = (n = {}) => {
221
+ let { autoUpgrade: r = !0, onUpgrade: i } = n, a = t(!1);
222
+ return e(() => {
223
+ if (!r || a.current || !u()) return;
224
+ let e = () => {
225
+ d() && !a.current && L() && (a.current = !0, i?.());
226
+ };
227
+ e();
228
+ let t = setTimeout(e, 0);
229
+ return () => clearTimeout(t);
230
+ }, [r, i]), { hasUpgraded: a.current };
231
+ }, V = ({ children: e, onUpgrade: t, autoUpgrade: n = !0 }) => (B({
232
+ onUpgrade: t,
233
+ autoUpgrade: n
234
+ }), e), H = class extends C {
235
+ constructor(e, t = {}) {
236
+ super(e, t);
237
+ }
238
+ getStorage() {
239
+ return o;
240
+ }
346
241
  };
242
+ //#endregion
243
+ export { V as HydrationProvider, C as LocalStorageProvider, H as MemoryStorageProvider, S as RWPStorageProvider, z as createPersistedWire, E as defaultOptions, j as getNamespace, P as getOptions, M as getStorage, N as setNamespace, F as setOptions, L as upgradeStorage, B as useHydration, b as utils };
244
+
245
+ //# sourceMappingURL=react-wire-persisted.js.map