seitu 0.4.2 → 0.4.4
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/core/schema-store.d.ts +3 -2
- package/dist/core/subscription.d.ts +3 -0
- package/dist/{core-iY5ySiQY.js → core-3fd1NXIt.js} +14 -1
- package/dist/core.js +1 -1
- package/dist/react/hooks.d.ts +2 -2
- package/dist/react.js +11 -3
- package/dist/web/web-storage-value.d.ts +2 -2
- package/dist/web/web-storage.d.ts +1 -0
- package/dist/web.js +53 -42
- package/package.json +5 -5
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { Simplify } from '../utils';
|
|
3
|
-
import type { Readable, Subscribable, Writable } from './index';
|
|
3
|
+
import type { Destroyable, Readable, Subscribable, Writable } from './index';
|
|
4
4
|
export type SchemaStoreSchema = Record<string, StandardSchemaV1<unknown, unknown>>;
|
|
5
5
|
export type SchemaStoreOutput<S extends SchemaStoreSchema> = Simplify<{
|
|
6
6
|
[K in keyof S]: StandardSchemaV1.InferOutput<S[K]>;
|
|
7
7
|
}>;
|
|
8
|
-
export interface SchemaStore<O extends Record<string, unknown>> extends Subscribable<O>, Readable<O>, Writable<Partial<O>, O
|
|
8
|
+
export interface SchemaStore<O extends Record<string, unknown>> extends Subscribable<O>, Readable<O>, Writable<Partial<O>, O>, Destroyable {
|
|
9
9
|
getDefaultValue: <K extends keyof O>(key: K) => O[K];
|
|
10
10
|
}
|
|
11
11
|
export interface SchemaStoreOptions<S extends Record<string, StandardSchemaV1>> {
|
|
@@ -39,6 +39,7 @@ export declare function createSchemaStore<S extends Record<string, StandardSchem
|
|
|
39
39
|
export interface SchemaStoreProvider<S extends SchemaStoreSchema> {
|
|
40
40
|
get: () => SchemaStoreOutput<S>;
|
|
41
41
|
set: (value: Partial<SchemaStoreOutput<S>>) => void;
|
|
42
|
+
destroy?: () => void;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* Creates an in-memory provider for a schema store. Use as the state backing when you don't
|
|
@@ -17,6 +17,9 @@ export interface Readable<T> {
|
|
|
17
17
|
export interface Writable<T, P = T> {
|
|
18
18
|
set: (value: T | ((prev: P) => T)) => any;
|
|
19
19
|
}
|
|
20
|
+
export interface Destroyable {
|
|
21
|
+
destroy: () => void;
|
|
22
|
+
}
|
|
20
23
|
export declare function createSubscription<T = void>(): {
|
|
21
24
|
subscribe: (callback: (payload: T) => any) => () => void;
|
|
22
25
|
notify: (payload: T) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
//#region src/core/subscription.ts
|
|
1
2
|
function e() {
|
|
2
|
-
let e = new Set();
|
|
3
|
+
let e = /* @__PURE__ */ new Set();
|
|
3
4
|
return {
|
|
4
5
|
subscribe(t) {
|
|
5
6
|
return e.add(t), () => {
|
|
@@ -11,6 +12,8 @@ function e() {
|
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/core/computed.ts
|
|
14
17
|
function t(t, n) {
|
|
15
18
|
let { subscribe: r, notify: i } = e(), a = Array.isArray(t) ? t : [t], o = !Array.isArray(t), s = () => n(o ? a[0].get() : a.map((e) => e.get()));
|
|
16
19
|
for (let e of a) e.subscribe(() => i());
|
|
@@ -25,6 +28,8 @@ function t(t, n) {
|
|
|
25
28
|
}
|
|
26
29
|
};
|
|
27
30
|
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/utils.ts
|
|
28
33
|
function n(e) {
|
|
29
34
|
if (typeof e != "string") return e;
|
|
30
35
|
try {
|
|
@@ -33,6 +38,8 @@ function n(e) {
|
|
|
33
38
|
return e;
|
|
34
39
|
}
|
|
35
40
|
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/core/schema-store.ts
|
|
36
43
|
function r(t) {
|
|
37
44
|
let { subscribe: r, notify: a } = e(), o = { ...t.defaultValues }, s = t.provider ?? i(), c = () => {
|
|
38
45
|
let e = { ...o };
|
|
@@ -53,6 +60,9 @@ function r(t) {
|
|
|
53
60
|
subscribe: (e) => r(() => {
|
|
54
61
|
e(c());
|
|
55
62
|
}),
|
|
63
|
+
destroy: () => {
|
|
64
|
+
s.destroy?.();
|
|
65
|
+
},
|
|
56
66
|
"~": {
|
|
57
67
|
output: null,
|
|
58
68
|
notify: a
|
|
@@ -68,6 +78,8 @@ function i() {
|
|
|
68
78
|
}
|
|
69
79
|
};
|
|
70
80
|
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core/store.ts
|
|
71
83
|
function a(t) {
|
|
72
84
|
let n = t, { subscribe: r, notify: i } = e(), a = () => n;
|
|
73
85
|
return {
|
|
@@ -85,4 +97,5 @@ function a(t) {
|
|
|
85
97
|
}
|
|
86
98
|
};
|
|
87
99
|
}
|
|
100
|
+
//#endregion
|
|
88
101
|
export { t as a, n as i, r as n, e as o, i as r, a as t };
|
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e, n as t, o as n, r, t as i } from "./core-
|
|
1
|
+
import { a as e, n as t, o as n, r, t as i } from "./core-3fd1NXIt.js";
|
|
2
2
|
export { e as createComputed, t as createSchemaStore, r as createSchemaStoreMemoryProvider, i as createStore, n as createSubscription };
|
package/dist/react/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Readable, Subscribable } from '../core/index';
|
|
1
|
+
import type { Destroyable, Readable, Subscribable } from '../core/index';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
export interface UseSubscriptionOptions<S extends Subscribable<any> & Readable<any>, R = S['~']['output']> {
|
|
4
4
|
selector?: (value: S['~']['output']) => R;
|
|
@@ -91,4 +91,4 @@ export interface UseSubscriptionOptions<S extends Subscribable<any> & Readable<a
|
|
|
91
91
|
* }
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
|
-
export declare function useSubscription<S extends Subscribable<any> & Readable<any>, R = S['~']['output']>(source: S | (() => S), options?: UseSubscriptionOptions<S, R>): R;
|
|
94
|
+
export declare function useSubscription<S extends Subscribable<any> & Readable<any> & Partial<Destroyable>, R = S['~']['output']>(source: S | (() => S), options?: UseSubscriptionOptions<S, R>): R;
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
|
+
//#region ../node_modules/.pnpm/fast-equals@6.0.0/node_modules/fast-equals/dist/es/index.mjs
|
|
2
3
|
var { getOwnPropertyNames: t, getOwnPropertySymbols: n } = Object, { hasOwnProperty: r } = Object.prototype;
|
|
3
4
|
function i(e, t) {
|
|
4
5
|
return function(n, r, i) {
|
|
@@ -176,7 +177,7 @@ function M(e) {
|
|
|
176
177
|
}
|
|
177
178
|
function N({ circular: e, comparator: t, createState: n, equals: r, strict: i }) {
|
|
178
179
|
if (n) return function(a, o) {
|
|
179
|
-
let { cache: s = e ? new WeakMap() : void 0, meta: c } = n();
|
|
180
|
+
let { cache: s = e ? /* @__PURE__ */ new WeakMap() : void 0, meta: c } = n();
|
|
180
181
|
return t(a, o, {
|
|
181
182
|
cache: s,
|
|
182
183
|
equals: r,
|
|
@@ -186,7 +187,7 @@ function N({ circular: e, comparator: t, createState: n, equals: r, strict: i })
|
|
|
186
187
|
};
|
|
187
188
|
if (e) return function(e, n) {
|
|
188
189
|
return t(e, n, {
|
|
189
|
-
cache: new WeakMap(),
|
|
190
|
+
cache: /* @__PURE__ */ new WeakMap(),
|
|
190
191
|
equals: r,
|
|
191
192
|
meta: void 0,
|
|
192
193
|
strict: i
|
|
@@ -261,6 +262,8 @@ function I(e = {}) {
|
|
|
261
262
|
strict: i
|
|
262
263
|
});
|
|
263
264
|
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/react/hooks.ts
|
|
264
267
|
function L(t, n) {
|
|
265
268
|
let { selector: r, deps: i = [] } = n ?? {}, a = typeof t == "function", o = e.useRef(t);
|
|
266
269
|
if (!a && t !== o.current) throw Error("useSubscription detected a new object on re-render. Either create the subscription outside the component or wrap it in a factory: useSubscription(() => yourSubscription(...))");
|
|
@@ -275,10 +278,15 @@ function L(t, n) {
|
|
|
275
278
|
let t = r ? r(e) : e;
|
|
276
279
|
F(t, f()) || d(t);
|
|
277
280
|
}, t = l.subscribe(e);
|
|
278
|
-
return e(l.get()),
|
|
281
|
+
return e(l.get()), () => {
|
|
282
|
+
t(), l.destroy?.();
|
|
283
|
+
};
|
|
279
284
|
}, [l, r]), u;
|
|
280
285
|
}
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/react/components.tsx
|
|
281
288
|
function R({ value: e, selector: t, children: n }) {
|
|
282
289
|
return n(L(e, { selector: t }));
|
|
283
290
|
}
|
|
291
|
+
//#endregion
|
|
284
292
|
export { R as Subscription, L as useSubscription };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type { Readable, Subscribable, Writable } from '../core/index';
|
|
2
|
+
import type { Destroyable, Readable, Subscribable, Writable } from '../core/index';
|
|
3
3
|
import type { WebStorage } from './web-storage';
|
|
4
|
-
export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V
|
|
4
|
+
export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V>, Destroyable {
|
|
5
5
|
}
|
|
6
6
|
export interface WebStorageValueOptionsWithStorage<Storage extends WebStorage<any>, K extends keyof Storage['~']['output']> {
|
|
7
7
|
storage: Storage;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SchemaStore, SchemaStoreOptions, SchemaStoreOutput, SchemaStoreSchema } from '../core/index';
|
|
2
2
|
export interface WebStorageOptions<S extends SchemaStoreSchema> extends Omit<SchemaStoreOptions<S>, 'provider'> {
|
|
3
|
+
keyTransform?: (key: keyof S) => string;
|
|
3
4
|
}
|
|
4
5
|
export interface WebStorage<O extends Record<string, unknown>> extends SchemaStore<O> {
|
|
5
6
|
'~': {
|
package/dist/web.js
CHANGED
|
@@ -1,48 +1,57 @@
|
|
|
1
|
-
import { i as e, n as t, o as n } from "./core-
|
|
1
|
+
import { i as e, n as t, o as n } from "./core-3fd1NXIt.js";
|
|
2
|
+
//#region src/web/web-storage.ts
|
|
2
3
|
function r(n) {
|
|
3
|
-
let { kind: r,
|
|
4
|
-
|
|
4
|
+
let { kind: r, keyTransform: i, defaultValues: a, schemas: o } = n, s = !1, c = t({
|
|
5
|
+
defaultValues: a,
|
|
6
|
+
schemas: o,
|
|
5
7
|
provider: {
|
|
6
8
|
get: () => {
|
|
7
|
-
if (typeof window > "u") return
|
|
8
|
-
let t = window[r], n = { ...
|
|
9
|
+
if (typeof window > "u") return a;
|
|
10
|
+
let t = window[r], n = { ...a };
|
|
9
11
|
for (let r in n) {
|
|
10
|
-
let
|
|
11
|
-
if (
|
|
12
|
-
n[r] =
|
|
12
|
+
let s = t.getItem(i ? i(r) : r);
|
|
13
|
+
if (s === null) {
|
|
14
|
+
n[r] = a[r];
|
|
13
15
|
continue;
|
|
14
16
|
}
|
|
15
|
-
let
|
|
16
|
-
if (
|
|
17
|
-
|
|
17
|
+
let c = e(s), l = o[r]["~standard"].validate(c);
|
|
18
|
+
if (l instanceof Promise) throw TypeError("[createWebSchemaStore] Validation schema should not return a Promise.");
|
|
19
|
+
l.issues && console.warn(JSON.stringify(l.issues, null, 2), { cause: l.issues }), n[r] = l.issues ? a[r] : l.value;
|
|
18
20
|
}
|
|
19
21
|
return n;
|
|
20
22
|
},
|
|
21
23
|
set: (e) => {
|
|
22
24
|
if (typeof window > "u") return;
|
|
23
25
|
let t = window[r];
|
|
24
|
-
Object.entries(e).forEach(([e, n]) => {
|
|
25
|
-
t.setItem(e, typeof n == "string" ? n : JSON.stringify(n));
|
|
26
|
-
});
|
|
26
|
+
s = !0, Object.entries(e).forEach(([e, n]) => {
|
|
27
|
+
t.setItem(i ? i(e) : e, typeof n == "string" ? n : JSON.stringify(n));
|
|
28
|
+
}), window.dispatchEvent(new Event("storage")), s = !1;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...
|
|
31
|
+
}), l = () => {
|
|
32
|
+
s || c["~"].notify();
|
|
33
|
+
};
|
|
34
|
+
return typeof window < "u" && window.addEventListener("storage", l), {
|
|
35
|
+
...c,
|
|
36
|
+
destroy: () => {
|
|
37
|
+
c.destroy?.(), typeof window < "u" && window.removeEventListener("storage", l);
|
|
38
|
+
},
|
|
34
39
|
"~": {
|
|
35
40
|
kind: r,
|
|
36
|
-
...
|
|
41
|
+
...c["~"]
|
|
37
42
|
}
|
|
38
43
|
};
|
|
39
44
|
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/web/local-storage.ts
|
|
40
47
|
function i(e) {
|
|
41
48
|
return r({
|
|
42
49
|
kind: "localStorage",
|
|
43
50
|
...e
|
|
44
51
|
});
|
|
45
52
|
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/web/web-storage-value.ts
|
|
46
55
|
function a(t) {
|
|
47
56
|
let r = "storage" in t ? t.storage["~"].kind : t.kind, i = `${r}Value`;
|
|
48
57
|
if ("schema" in t && t.defaultValue === void 0) throw Error(`[${i}] Default value is required`);
|
|
@@ -62,21 +71,19 @@ function a(t) {
|
|
|
62
71
|
} catch {
|
|
63
72
|
return a !== void 0 && typeof a != "string" ? a : i;
|
|
64
73
|
}
|
|
74
|
+
}, l = (e) => {
|
|
75
|
+
e.key === t.key && s();
|
|
65
76
|
};
|
|
66
|
-
return {
|
|
77
|
+
return typeof window < "u" && window.addEventListener("storage", l), {
|
|
67
78
|
get: c,
|
|
68
79
|
set: (e) => {
|
|
69
80
|
if (typeof window > "u") return;
|
|
70
81
|
let n = window[r], i = typeof e == "function" ? e(c()) : e;
|
|
71
82
|
n.setItem(t.key, typeof i == "string" ? i : JSON.stringify(i)), window.dispatchEvent(new Event("storage")), s();
|
|
72
83
|
},
|
|
73
|
-
subscribe: (e) =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
return typeof window < "u" && window.addEventListener("storage", r), () => {
|
|
78
|
-
n(), typeof window < "u" && window.removeEventListener("storage", r);
|
|
79
|
-
};
|
|
84
|
+
subscribe: (e) => o(() => e(c())),
|
|
85
|
+
destroy: () => {
|
|
86
|
+
typeof window < "u" && window.removeEventListener("storage", l);
|
|
80
87
|
},
|
|
81
88
|
"~": {
|
|
82
89
|
output: null,
|
|
@@ -84,28 +91,25 @@ function a(t) {
|
|
|
84
91
|
}
|
|
85
92
|
};
|
|
86
93
|
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/web/local-storage-value.ts
|
|
87
96
|
function o(e) {
|
|
88
97
|
return "storage" in e ? a(e) : a({
|
|
89
98
|
...e,
|
|
90
99
|
kind: "localStorage"
|
|
91
100
|
});
|
|
92
101
|
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/web/media-query.ts
|
|
93
104
|
function s(e) {
|
|
94
|
-
let { subscribe: t, notify: r } = n(), i = () =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return window.matchMedia(e.query).matches;
|
|
98
|
-
} catch {
|
|
99
|
-
return e.defaultMatches ?? !1;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
get: i,
|
|
105
|
+
let { subscribe: t, notify: r } = n(), i = typeof window > "u" ? null : window.matchMedia(e.query), a = () => i?.matches ?? e.defaultMatches ?? !1;
|
|
106
|
+
return i?.addEventListener("change", () => r()), {
|
|
107
|
+
get: a,
|
|
104
108
|
subscribe: (n) => {
|
|
105
|
-
if (typeof window > "u") return n(
|
|
106
|
-
let r = t(() => n(
|
|
107
|
-
return
|
|
108
|
-
r(),
|
|
109
|
+
if (typeof window > "u") return n(a()), () => {};
|
|
110
|
+
let r = t(() => n(a())), i = window.matchMedia(e.query), o = () => n(a());
|
|
111
|
+
return i.addEventListener("change", o), () => {
|
|
112
|
+
r(), i.removeEventListener("change", o);
|
|
109
113
|
};
|
|
110
114
|
},
|
|
111
115
|
"~": {
|
|
@@ -114,6 +118,8 @@ function s(e) {
|
|
|
114
118
|
}
|
|
115
119
|
};
|
|
116
120
|
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/web/scroll-state.ts
|
|
117
123
|
var c = {
|
|
118
124
|
reached: !1,
|
|
119
125
|
remaining: 0
|
|
@@ -164,16 +170,21 @@ function l(e) {
|
|
|
164
170
|
}
|
|
165
171
|
};
|
|
166
172
|
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/web/session-storage.ts
|
|
167
175
|
function u(e) {
|
|
168
176
|
return r({
|
|
169
177
|
kind: "sessionStorage",
|
|
170
178
|
...e
|
|
171
179
|
});
|
|
172
180
|
}
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/web/session-storage-value.ts
|
|
173
183
|
function d(e) {
|
|
174
184
|
return "storage" in e ? a(e) : a({
|
|
175
185
|
...e,
|
|
176
186
|
kind: "sessionStorage"
|
|
177
187
|
});
|
|
178
188
|
}
|
|
189
|
+
//#endregion
|
|
179
190
|
export { i as createLocalStorage, o as createLocalStorageValue, s as createMediaQuery, l as createScrollState, u as createSessionStorage, d as createSessionStorageValue };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "seitu",
|
|
3
3
|
"displayName": "Seitu",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.4",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Valerii Strilets",
|
|
8
8
|
"license": "MIT",
|
|
@@ -64,14 +64,14 @@
|
|
|
64
64
|
"@testing-library/jest-dom": "^6.9.1",
|
|
65
65
|
"@testing-library/react": "^16.3.2",
|
|
66
66
|
"@types/react": "^19.2.14",
|
|
67
|
-
"@vitejs/plugin-react": "^
|
|
68
|
-
"happy-dom": "^20.8.
|
|
67
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
68
|
+
"happy-dom": "^20.8.4",
|
|
69
69
|
"react-dom": "^19.2.4",
|
|
70
70
|
"type-fest": "^5.4.4",
|
|
71
71
|
"typescript": "^5.9.3",
|
|
72
|
-
"vite": "^8.0.0
|
|
72
|
+
"vite": "^8.0.0",
|
|
73
73
|
"vite-plugin-dts": "^4.5.4",
|
|
74
|
-
"vitest": "^4.0
|
|
74
|
+
"vitest": "^4.1.0",
|
|
75
75
|
"zod": "^4.3.6"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|