seitu 0.4.5 → 0.4.6
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/dist/react.js +10 -13
- package/dist/web.js +20 -19
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -265,23 +265,20 @@ function I(e = {}) {
|
|
|
265
265
|
//#endregion
|
|
266
266
|
//#region src/react/hooks.ts
|
|
267
267
|
function L(t, n) {
|
|
268
|
-
let { selector: r, deps: i = [] } = n ?? {}, a = typeof t == "function", o = e.useRef(
|
|
269
|
-
|
|
270
|
-
o.current
|
|
271
|
-
|
|
272
|
-
c.
|
|
273
|
-
let l = e.useMemo(() => c.current(), i);
|
|
274
|
-
if (!l.get || !l.subscribe) throw Error("Subscription is not valid. It must have a get and subscribe method.");
|
|
275
|
-
let [u, d] = e.useState(() => r ? r(l.get()) : l.get()), f = e.useEffectEvent(() => u);
|
|
268
|
+
let { selector: r, deps: i = [] } = n ?? {}, a = typeof t == "function" ? t : () => t, o = e.useRef(a);
|
|
269
|
+
o.current = a;
|
|
270
|
+
let s = e.useMemo(() => o.current(), i);
|
|
271
|
+
if (!s.get || !s.subscribe) throw Error("Subscription is not valid. It must have a get and subscribe method.");
|
|
272
|
+
let [c, l] = e.useState(() => r ? r(s.get()) : s.get()), u = e.useEffectEvent(() => c);
|
|
276
273
|
return e.useEffect(() => {
|
|
277
274
|
let e = (e) => {
|
|
278
275
|
let t = r ? r(e) : e;
|
|
279
|
-
F(t,
|
|
280
|
-
}, t =
|
|
281
|
-
return e(
|
|
282
|
-
t(),
|
|
276
|
+
F(t, u()) || l(t);
|
|
277
|
+
}, t = s.subscribe(e);
|
|
278
|
+
return e(s.get()), () => {
|
|
279
|
+
t(), s.destroy?.();
|
|
283
280
|
};
|
|
284
|
-
}, [
|
|
281
|
+
}, [s, r]), c;
|
|
285
282
|
}
|
|
286
283
|
//#endregion
|
|
287
284
|
//#region src/react/components.tsx
|
package/dist/web.js
CHANGED
|
@@ -24,7 +24,8 @@ function r(n) {
|
|
|
24
24
|
if (typeof window > "u") return;
|
|
25
25
|
let t = window[r];
|
|
26
26
|
s = !0, Object.entries(e).forEach(([e, n]) => {
|
|
27
|
-
|
|
27
|
+
let r = typeof n == "string" ? n : JSON.stringify(n);
|
|
28
|
+
t.setItem(i ? i(e) : e, r);
|
|
28
29
|
}), window.dispatchEvent(new Event("storage")), s = !1;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -53,41 +54,41 @@ function i(e) {
|
|
|
53
54
|
//#endregion
|
|
54
55
|
//#region src/web/web-storage-value.ts
|
|
55
56
|
function a(t) {
|
|
56
|
-
let r = "storage" in t ? t.storage["~"].kind : t.kind, i = `${r}Value`;
|
|
57
|
-
if ("schema" in t && t.defaultValue === void 0) throw Error(`[${
|
|
58
|
-
if (t.key === void 0) throw Error(`[${
|
|
59
|
-
if (!("schema" in t || "storage" in t)) throw Error(`[${
|
|
60
|
-
let
|
|
61
|
-
if (typeof window > "u") return
|
|
57
|
+
let r = "storage" in t ? t.storage["~"].kind : t.kind, i = !1, a = `${r}Value`;
|
|
58
|
+
if ("schema" in t && t.defaultValue === void 0) throw Error(`[${a}] Default value is required`);
|
|
59
|
+
if (t.key === void 0) throw Error(`[${a}] Key is required`);
|
|
60
|
+
if (!("schema" in t || "storage" in t)) throw Error(`[${a}] Either schema or storage must be provided`);
|
|
61
|
+
let o = ("schema" in t ? t.defaultValue : t.storage.getDefaultValue(t.key)) ?? null, { subscribe: s, notify: c } = n(), l = () => {
|
|
62
|
+
if (typeof window > "u") return o;
|
|
62
63
|
let n = window[r].getItem(t.key);
|
|
63
|
-
if (n === null) return
|
|
64
|
+
if (n === null) return o;
|
|
64
65
|
let i = e(n);
|
|
65
66
|
try {
|
|
66
67
|
if ("schema" in t) {
|
|
67
68
|
let e = t.schema["~standard"].validate(i);
|
|
68
69
|
if (e instanceof Promise) throw TypeError("Validation schema should not return a Promise.");
|
|
69
|
-
return e.issues ? (console.error(JSON.stringify(e.issues, null, 2), { cause: e.issues }),
|
|
70
|
+
return e.issues ? (console.error(JSON.stringify(e.issues, null, 2), { cause: e.issues }), o) : e.value;
|
|
70
71
|
} else return i;
|
|
71
72
|
} catch {
|
|
72
|
-
return
|
|
73
|
+
return o !== void 0 && typeof o != "string" ? o : i;
|
|
73
74
|
}
|
|
74
|
-
},
|
|
75
|
-
e.key === t.key &&
|
|
75
|
+
}, u = (e) => {
|
|
76
|
+
i || e.key === t.key && c();
|
|
76
77
|
};
|
|
77
|
-
return typeof window < "u" && window.addEventListener("storage",
|
|
78
|
-
get:
|
|
78
|
+
return typeof window < "u" && window.addEventListener("storage", u), {
|
|
79
|
+
get: l,
|
|
79
80
|
set: (e) => {
|
|
80
81
|
if (typeof window > "u") return;
|
|
81
|
-
let n = window[r],
|
|
82
|
-
n.setItem(t.key, typeof
|
|
82
|
+
let n = window[r], a = typeof e == "function" ? e(l()) : e;
|
|
83
|
+
i = !0, n.setItem(t.key, typeof a == "string" ? a : JSON.stringify(a)), window.dispatchEvent(new Event("storage")), i = !1, c();
|
|
83
84
|
},
|
|
84
|
-
subscribe: (e) =>
|
|
85
|
+
subscribe: (e) => s(() => e(l())),
|
|
85
86
|
destroy: () => {
|
|
86
|
-
typeof window < "u" && window.removeEventListener("storage",
|
|
87
|
+
typeof window < "u" && window.removeEventListener("storage", u);
|
|
87
88
|
},
|
|
88
89
|
"~": {
|
|
89
90
|
output: null,
|
|
90
|
-
notify:
|
|
91
|
+
notify: c
|
|
91
92
|
}
|
|
92
93
|
};
|
|
93
94
|
}
|