seitu 0.4.7 → 0.5.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.
- package/dist/core/store.d.ts +5 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/is-online.d.ts +33 -0
- package/dist/web/is-online.test.d.ts +1 -0
- package/dist/web.js +43 -27
- package/package.json +5 -5
package/dist/core/store.d.ts
CHANGED
|
@@ -8,8 +8,13 @@ export interface Store<T> extends Readable<T>, Writable<T, T>, Subscribable<T> {
|
|
|
8
8
|
* - **With schema-store**: use as the state backing for a memory provider.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
+
* ```ts twoslash
|
|
12
|
+
* import { createStore } from 'seitu'
|
|
13
|
+
*
|
|
11
14
|
* const store = createStore({ count: 0 })
|
|
12
15
|
* store.set(prev => ({ ...prev, count: prev.count + 1 }))
|
|
13
16
|
* store.subscribe(state => console.log(state))
|
|
17
|
+
* store.get() // { count: 0 }
|
|
18
|
+
* ```
|
|
14
19
|
*/
|
|
15
20
|
export declare function createStore<T>(initial: T): Store<T>;
|
package/dist/web/index.d.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Destroyable, Readable, Subscribable } from '../core/index';
|
|
2
|
+
export interface IsOnline extends Subscribable<boolean>, Readable<boolean>, Destroyable {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Creates a reactive handle for browser online status.
|
|
6
|
+
*
|
|
7
|
+
* @example Vanilla
|
|
8
|
+
* ```ts twoslash
|
|
9
|
+
* import { createIsOnline } from 'seitu/web'
|
|
10
|
+
*
|
|
11
|
+
* const isOnline = createIsOnline()
|
|
12
|
+
*
|
|
13
|
+
* isOnline.subscribe(value => {
|
|
14
|
+
* console.log(value ? 'online' : 'offline')
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* console.log(isOnline.get())
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example React
|
|
21
|
+
* ```tsx twoslash title="page.tsx"
|
|
22
|
+
* import { createIsOnline } from 'seitu/web'
|
|
23
|
+
* import { useSubscription } from 'seitu/react'
|
|
24
|
+
*
|
|
25
|
+
* const isOnline = createIsOnline()
|
|
26
|
+
*
|
|
27
|
+
* function Status() {
|
|
28
|
+
* const online = useSubscription(isOnline)
|
|
29
|
+
* return online ? 'Connected' : 'Disconnected'
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createIsOnline(): IsOnline;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/web.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { i as e, n as t, o as n } from "./core-3fd1NXIt.js";
|
|
2
|
+
//#region src/web/is-online.ts
|
|
3
|
+
function r() {
|
|
4
|
+
let { subscribe: e, notify: t } = n(), r = () => typeof navigator > "u" ? !0 : navigator.onLine, i = () => t();
|
|
5
|
+
return typeof window < "u" && (window.addEventListener("online", i), window.addEventListener("offline", i)), {
|
|
6
|
+
get: r,
|
|
7
|
+
subscribe: (t) => e(() => t(r())),
|
|
8
|
+
destroy: () => {
|
|
9
|
+
typeof window < "u" && (window.removeEventListener("online", i), window.removeEventListener("offline", i));
|
|
10
|
+
},
|
|
11
|
+
"~": {
|
|
12
|
+
output: null,
|
|
13
|
+
notify: t
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
2
18
|
//#region src/web/web-storage.ts
|
|
3
|
-
function
|
|
19
|
+
function i(n) {
|
|
4
20
|
let { kind: r, keyTransform: i, defaultValues: a, schemas: o } = n, s = !1, c = t({
|
|
5
21
|
defaultValues: a,
|
|
6
22
|
schemas: o,
|
|
@@ -45,15 +61,15 @@ function r(n) {
|
|
|
45
61
|
}
|
|
46
62
|
//#endregion
|
|
47
63
|
//#region src/web/local-storage.ts
|
|
48
|
-
function
|
|
49
|
-
return
|
|
64
|
+
function a(e) {
|
|
65
|
+
return i({
|
|
50
66
|
kind: "localStorage",
|
|
51
67
|
...e
|
|
52
68
|
});
|
|
53
69
|
}
|
|
54
70
|
//#endregion
|
|
55
71
|
//#region src/web/web-storage-value.ts
|
|
56
|
-
function
|
|
72
|
+
function o(t) {
|
|
57
73
|
let r = "storage" in t ? t.storage["~"].kind : t.kind, i = !1, a = `${r}Value`;
|
|
58
74
|
if ("schema" in t && t.defaultValue === void 0) throw Error(`[${a}] Default value is required`);
|
|
59
75
|
if (t.key === void 0) throw Error(`[${a}] Key is required`);
|
|
@@ -97,15 +113,15 @@ function a(t) {
|
|
|
97
113
|
}
|
|
98
114
|
//#endregion
|
|
99
115
|
//#region src/web/local-storage-value.ts
|
|
100
|
-
function
|
|
101
|
-
return "storage" in e ?
|
|
116
|
+
function s(e) {
|
|
117
|
+
return "storage" in e ? o(e) : o({
|
|
102
118
|
...e,
|
|
103
119
|
kind: "localStorage"
|
|
104
120
|
});
|
|
105
121
|
}
|
|
106
122
|
//#endregion
|
|
107
123
|
//#region src/web/media-query.ts
|
|
108
|
-
function
|
|
124
|
+
function c(e) {
|
|
109
125
|
let { subscribe: t, notify: r } = n(), i = typeof window > "u" ? null : window.matchMedia(e.query), a = () => i?.matches ?? e.defaultMatches ?? !1, o = () => r();
|
|
110
126
|
return i?.addEventListener("change", o), {
|
|
111
127
|
get: a,
|
|
@@ -121,11 +137,11 @@ function s(e) {
|
|
|
121
137
|
}
|
|
122
138
|
//#endregion
|
|
123
139
|
//#region src/web/scroll-state.ts
|
|
124
|
-
var
|
|
140
|
+
var l = {
|
|
125
141
|
reached: !1,
|
|
126
142
|
remaining: 0
|
|
127
143
|
};
|
|
128
|
-
function
|
|
144
|
+
function u(e) {
|
|
129
145
|
let { direction: t = "both", threshold: r = 0 } = e, { subscribe: i, notify: a } = n(), o = typeof r == "number" ? {
|
|
130
146
|
top: r,
|
|
131
147
|
bottom: r,
|
|
@@ -136,31 +152,31 @@ function l(e) {
|
|
|
136
152
|
bottom: r.bottom ?? 0,
|
|
137
153
|
left: r.left ?? 0,
|
|
138
154
|
right: r.right ?? 0
|
|
139
|
-
}, s = () => typeof e.element == "function" ? e.element() : e.element,
|
|
155
|
+
}, s = () => typeof e.element == "function" ? e.element() : e.element, c = () => {
|
|
140
156
|
let e = s(), n = (e, t) => ({
|
|
141
157
|
reached: e,
|
|
142
158
|
remaining: Math.max(0, t)
|
|
143
159
|
});
|
|
144
160
|
if (!e) return {
|
|
145
|
-
top:
|
|
146
|
-
bottom:
|
|
147
|
-
left:
|
|
148
|
-
right:
|
|
161
|
+
top: l,
|
|
162
|
+
bottom: l,
|
|
163
|
+
left: l,
|
|
164
|
+
right: l
|
|
149
165
|
};
|
|
150
|
-
let r = e.scrollTop, i = e.scrollHeight - e.scrollTop - e.clientHeight, a = e.scrollLeft,
|
|
166
|
+
let r = e.scrollTop, i = e.scrollHeight - e.scrollTop - e.clientHeight, a = e.scrollLeft, c = e.scrollWidth - e.scrollLeft - e.clientWidth;
|
|
151
167
|
return {
|
|
152
|
-
top: t === "horizontal" ?
|
|
153
|
-
bottom: t === "horizontal" ?
|
|
154
|
-
left: t === "vertical" ?
|
|
155
|
-
right: t === "vertical" ?
|
|
168
|
+
top: t === "horizontal" ? l : n(r <= o.top, r),
|
|
169
|
+
bottom: t === "horizontal" ? l : n(i <= o.bottom, i),
|
|
170
|
+
left: t === "vertical" ? l : n(a <= o.left, a),
|
|
171
|
+
right: t === "vertical" ? l : n(c <= o.right, c)
|
|
156
172
|
};
|
|
157
173
|
};
|
|
158
174
|
return {
|
|
159
|
-
get:
|
|
175
|
+
get: c,
|
|
160
176
|
subscribe: (e) => {
|
|
161
177
|
let t = s();
|
|
162
|
-
if (!t) return e(
|
|
163
|
-
let n = i(() => e(
|
|
178
|
+
if (!t) return e(c()), () => {};
|
|
179
|
+
let n = i(() => e(c())), r = () => e(c());
|
|
164
180
|
return t.addEventListener("scroll", r, { passive: !0 }), () => {
|
|
165
181
|
n(), t.removeEventListener("scroll", r);
|
|
166
182
|
};
|
|
@@ -173,19 +189,19 @@ function l(e) {
|
|
|
173
189
|
}
|
|
174
190
|
//#endregion
|
|
175
191
|
//#region src/web/session-storage.ts
|
|
176
|
-
function
|
|
177
|
-
return
|
|
192
|
+
function d(e) {
|
|
193
|
+
return i({
|
|
178
194
|
kind: "sessionStorage",
|
|
179
195
|
...e
|
|
180
196
|
});
|
|
181
197
|
}
|
|
182
198
|
//#endregion
|
|
183
199
|
//#region src/web/session-storage-value.ts
|
|
184
|
-
function
|
|
185
|
-
return "storage" in e ?
|
|
200
|
+
function f(e) {
|
|
201
|
+
return "storage" in e ? o(e) : o({
|
|
186
202
|
...e,
|
|
187
203
|
kind: "sessionStorage"
|
|
188
204
|
});
|
|
189
205
|
}
|
|
190
206
|
//#endregion
|
|
191
|
-
export {
|
|
207
|
+
export { r as createIsOnline, a as createLocalStorage, s as createLocalStorageValue, c as createMediaQuery, u as createScrollState, d as createSessionStorage, f 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.
|
|
5
|
+
"version": "0.5.0",
|
|
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": "^5.1.4",
|
|
68
|
+
"happy-dom": "^20.8.3",
|
|
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-beta.16",
|
|
73
73
|
"vite-plugin-dts": "^4.5.4",
|
|
74
|
-
"vitest": "^4.
|
|
74
|
+
"vitest": "^4.0.18",
|
|
75
75
|
"zod": "^4.3.6"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|