zustand-iten 0.4.2 → 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/README.md +4 -9
- package/dist/create-router.cjs +2 -0
- package/dist/create-router.d.cts +5 -1
- package/dist/create-router.d.ts +5 -1
- package/dist/create-router.mjs +2 -0
- package/dist/types.d.cts +3 -2
- package/dist/types.d.ts +3 -2
- package/dist/url.cjs +1 -0
- package/dist/url.mjs +1 -0
- package/package.json +2 -2
- package/src/create-router.ts +17 -1
- package/src/types.ts +3 -0
- package/src/url.ts +1 -0
package/README.md
CHANGED
|
@@ -16,10 +16,8 @@ npm install zustand-iten zustand
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import {
|
|
19
|
-
createRoute,
|
|
20
19
|
createRouter,
|
|
21
20
|
defineRoutes,
|
|
22
|
-
type InferRoutes,
|
|
23
21
|
route,
|
|
24
22
|
} from 'zustand-iten'
|
|
25
23
|
|
|
@@ -29,15 +27,12 @@ const routes = defineRoutes({
|
|
|
29
27
|
settings: route(),
|
|
30
28
|
})
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const router = createRouter<Routes>({
|
|
37
|
-
initial: toRoute({ name: 'home' }),
|
|
30
|
+
const router = createRouter({
|
|
31
|
+
routes,
|
|
32
|
+
initial: { name: 'home' },
|
|
38
33
|
})
|
|
39
34
|
|
|
40
|
-
await router.navigate({ target:
|
|
35
|
+
await router.navigate({ target: router.to({ name: 'project', params: { id: 'alpha' } }) })
|
|
41
36
|
|
|
42
37
|
router.store.getState().route
|
|
43
38
|
router.store.getState().canGoBack
|
package/dist/create-router.cjs
CHANGED
|
@@ -8,6 +8,7 @@ function createRouter(config) {
|
|
|
8
8
|
};
|
|
9
9
|
const core = (0, iten_core.createItenCore)({
|
|
10
10
|
initial: config.initial,
|
|
11
|
+
routes: config.routes,
|
|
11
12
|
routeConfig: config.routeConfig,
|
|
12
13
|
maxHistoryLength: config.maxHistoryLength,
|
|
13
14
|
queryClient: config.queryClient,
|
|
@@ -54,6 +55,7 @@ function createRouter(config) {
|
|
|
54
55
|
return {
|
|
55
56
|
store,
|
|
56
57
|
core,
|
|
58
|
+
to: core.to,
|
|
57
59
|
navigate: actions.navigate,
|
|
58
60
|
goBack: actions.goBack,
|
|
59
61
|
dispose: actions.dispose
|
package/dist/create-router.d.cts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ZustandRouterActions, ZustandRouterConfig, ZustandRouterStore } from "./types.cjs";
|
|
2
|
-
import { ItenCore, RouteMapDef } from "iten-core";
|
|
2
|
+
import { InferRoutes, ItenCore, RouteDefinitions, RouteFactory, RouteMapDef } from "iten-core";
|
|
3
3
|
|
|
4
4
|
//#region src/create-router.d.ts
|
|
5
5
|
type ZustandRouter<M extends RouteMapDef, _Ctx = unknown> = {
|
|
6
6
|
store: ZustandRouterStore<M>;
|
|
7
7
|
core: ItenCore<M>;
|
|
8
|
+
to: RouteFactory<M>;
|
|
8
9
|
navigate: ZustandRouterActions<M>["navigate"];
|
|
9
10
|
goBack: ZustandRouterActions<M>["goBack"];
|
|
10
11
|
dispose: ZustandRouterActions<M>["dispose"];
|
|
11
12
|
};
|
|
13
|
+
declare function createRouter<const Defs extends RouteDefinitions, Ctx = unknown>(config: ZustandRouterConfig<InferRoutes<Defs>, Ctx> & {
|
|
14
|
+
routes: Defs;
|
|
15
|
+
}): ZustandRouter<InferRoutes<Defs>, Ctx>;
|
|
12
16
|
declare function createRouter<M extends RouteMapDef, Ctx = unknown>(config: ZustandRouterConfig<M, Ctx>): ZustandRouter<M, Ctx>;
|
|
13
17
|
//#endregion
|
|
14
18
|
export { ZustandRouter, createRouter };
|
package/dist/create-router.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ZustandRouterActions, ZustandRouterConfig, ZustandRouterStore } from "./types.js";
|
|
2
|
-
import { ItenCore, RouteMapDef } from "iten-core";
|
|
2
|
+
import { InferRoutes, ItenCore, RouteDefinitions, RouteFactory, RouteMapDef } from "iten-core";
|
|
3
3
|
|
|
4
4
|
//#region src/create-router.d.ts
|
|
5
5
|
type ZustandRouter<M extends RouteMapDef, _Ctx = unknown> = {
|
|
6
6
|
store: ZustandRouterStore<M>;
|
|
7
7
|
core: ItenCore<M>;
|
|
8
|
+
to: RouteFactory<M>;
|
|
8
9
|
navigate: ZustandRouterActions<M>["navigate"];
|
|
9
10
|
goBack: ZustandRouterActions<M>["goBack"];
|
|
10
11
|
dispose: ZustandRouterActions<M>["dispose"];
|
|
11
12
|
};
|
|
13
|
+
declare function createRouter<const Defs extends RouteDefinitions, Ctx = unknown>(config: ZustandRouterConfig<InferRoutes<Defs>, Ctx> & {
|
|
14
|
+
routes: Defs;
|
|
15
|
+
}): ZustandRouter<InferRoutes<Defs>, Ctx>;
|
|
12
16
|
declare function createRouter<M extends RouteMapDef, Ctx = unknown>(config: ZustandRouterConfig<M, Ctx>): ZustandRouter<M, Ctx>;
|
|
13
17
|
//#endregion
|
|
14
18
|
export { ZustandRouter, createRouter };
|
package/dist/create-router.mjs
CHANGED
|
@@ -8,6 +8,7 @@ function createRouter(config) {
|
|
|
8
8
|
};
|
|
9
9
|
const core = createItenCore({
|
|
10
10
|
initial: config.initial,
|
|
11
|
+
routes: config.routes,
|
|
11
12
|
routeConfig: config.routeConfig,
|
|
12
13
|
maxHistoryLength: config.maxHistoryLength,
|
|
13
14
|
queryClient: config.queryClient,
|
|
@@ -54,6 +55,7 @@ function createRouter(config) {
|
|
|
54
55
|
return {
|
|
55
56
|
store,
|
|
56
57
|
core,
|
|
58
|
+
to: core.to,
|
|
57
59
|
navigate: actions.navigate,
|
|
58
60
|
goBack: actions.goBack,
|
|
59
61
|
dispose: actions.dispose
|
package/dist/types.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { InferRoutes, NavigateInput, NoParams, QueryClientLike, RouteConfigMap, RouteDefinition, RouteDefinitions, RouteMap, RouteMapDef as RouteMapDef$1, RouteMatcher, RouteName, RouteOf, RouteParams, RouteUnion, RouterError, RouterState } from "iten-core";
|
|
1
|
+
import { InferRoutes as InferRoutes$1, NavigateInput, NoParams, QueryClientLike, RouteConfigMap, RouteDefinition, RouteDefinitions as RouteDefinitions$1, RouteMap, RouteMapDef as RouteMapDef$1, RouteMatcher, RouteName, RouteOf, RouteParams, RouteUnion, RouterError, RouterState } from "iten-core";
|
|
2
2
|
import { StoreApi } from "zustand/vanilla";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
type ZustandRouterConfig<M extends RouteMapDef$1, Ctx = unknown> = {
|
|
6
6
|
initial: RouteUnion<M> | null;
|
|
7
|
+
routes?: RouteDefinitions$1 | undefined;
|
|
7
8
|
routeConfig?: RouteConfigMap<M, Ctx> | undefined;
|
|
8
9
|
maxHistoryLength?: number | undefined;
|
|
9
10
|
context?: Ctx | (() => Ctx) | undefined;
|
|
@@ -17,4 +18,4 @@ type ZustandRouterActions<M extends RouteMapDef$1> = {
|
|
|
17
18
|
type ZustandRouterState<M extends RouteMapDef$1> = RouterState<M> & ZustandRouterActions<M>;
|
|
18
19
|
type ZustandRouterStore<M extends RouteMapDef$1> = StoreApi<ZustandRouterState<M>>;
|
|
19
20
|
//#endregion
|
|
20
|
-
export { type InferRoutes, type NoParams, type QueryClientLike, type RouteConfigMap, type RouteDefinition, type RouteDefinitions, type RouteMap, type RouteMapDef$1 as RouteMapDef, type RouteMatcher, type RouteName, type RouteOf, type RouteParams, type RouteUnion, type RouterError, type RouterState, ZustandRouterActions, ZustandRouterConfig, ZustandRouterState, ZustandRouterStore };
|
|
21
|
+
export { type InferRoutes$1 as InferRoutes, type NoParams, type QueryClientLike, type RouteConfigMap, type RouteDefinition, type RouteDefinitions$1 as RouteDefinitions, type RouteMap, type RouteMapDef$1 as RouteMapDef, type RouteMatcher, type RouteName, type RouteOf, type RouteParams, type RouteUnion, type RouterError, type RouterState, ZustandRouterActions, ZustandRouterConfig, ZustandRouterState, ZustandRouterStore };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { InferRoutes, NavigateInput, NoParams, QueryClientLike, RouteConfigMap, RouteDefinition, RouteDefinitions, RouteMap, RouteMapDef as RouteMapDef$1, RouteMatcher, RouteName, RouteOf, RouteParams, RouteUnion, RouterError, RouterState } from "iten-core";
|
|
1
|
+
import { InferRoutes as InferRoutes$1, NavigateInput, NoParams, QueryClientLike, RouteConfigMap, RouteDefinition, RouteDefinitions as RouteDefinitions$1, RouteMap, RouteMapDef as RouteMapDef$1, RouteMatcher, RouteName, RouteOf, RouteParams, RouteUnion, RouterError, RouterState } from "iten-core";
|
|
2
2
|
import { StoreApi } from "zustand/vanilla";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
type ZustandRouterConfig<M extends RouteMapDef$1, Ctx = unknown> = {
|
|
6
6
|
initial: RouteUnion<M> | null;
|
|
7
|
+
routes?: RouteDefinitions$1 | undefined;
|
|
7
8
|
routeConfig?: RouteConfigMap<M, Ctx> | undefined;
|
|
8
9
|
maxHistoryLength?: number | undefined;
|
|
9
10
|
context?: Ctx | (() => Ctx) | undefined;
|
|
@@ -17,4 +18,4 @@ type ZustandRouterActions<M extends RouteMapDef$1> = {
|
|
|
17
18
|
type ZustandRouterState<M extends RouteMapDef$1> = RouterState<M> & ZustandRouterActions<M>;
|
|
18
19
|
type ZustandRouterStore<M extends RouteMapDef$1> = StoreApi<ZustandRouterState<M>>;
|
|
19
20
|
//#endregion
|
|
20
|
-
export { type InferRoutes, type NoParams, type QueryClientLike, type RouteConfigMap, type RouteDefinition, type RouteDefinitions, type RouteMap, type RouteMapDef$1 as RouteMapDef, type RouteMatcher, type RouteName, type RouteOf, type RouteParams, type RouteUnion, type RouterError, type RouterState, ZustandRouterActions, ZustandRouterConfig, ZustandRouterState, ZustandRouterStore };
|
|
21
|
+
export { type InferRoutes$1 as InferRoutes, type NoParams, type QueryClientLike, type RouteConfigMap, type RouteDefinition, type RouteDefinitions$1 as RouteDefinitions, type RouteMap, type RouteMapDef$1 as RouteMapDef, type RouteMatcher, type RouteName, type RouteOf, type RouteParams, type RouteUnion, type RouterError, type RouterState, ZustandRouterActions, ZustandRouterConfig, ZustandRouterState, ZustandRouterStore };
|
package/dist/url.cjs
CHANGED
|
@@ -4,6 +4,7 @@ let iten_core_url = require("iten-core/url");
|
|
|
4
4
|
function createUrlSync({ router, ...input }) {
|
|
5
5
|
const coreLike = {
|
|
6
6
|
getState: () => router.store.getState(),
|
|
7
|
+
to: router.to,
|
|
7
8
|
navigate: (navigateInput) => router.navigate(navigateInput),
|
|
8
9
|
goBack: () => router.goBack(),
|
|
9
10
|
subscribe: ({ listener }) => router.store.subscribe((state) => {
|
package/dist/url.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { createUrlSync as createUrlSync$1 } from "iten-core/url";
|
|
|
3
3
|
function createUrlSync({ router, ...input }) {
|
|
4
4
|
const coreLike = {
|
|
5
5
|
getState: () => router.store.getState(),
|
|
6
|
+
to: router.to,
|
|
6
7
|
navigate: (navigateInput) => router.navigate(navigateInput),
|
|
7
8
|
goBack: () => router.goBack(),
|
|
8
9
|
subscribe: ({ listener }) => router.store.subscribe((state) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zustand-iten",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Zustand adapter for iten — ultralight in-memory router for embedded JS apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zustand",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"zustand": "^5.0.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"iten-core": "^0.
|
|
75
|
+
"iten-core": "^0.5.0"
|
|
76
76
|
},
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public",
|
package/src/create-router.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
InferRoutes,
|
|
3
|
+
ItenCore,
|
|
4
|
+
RouteDefinitions,
|
|
5
|
+
RouteFactory,
|
|
6
|
+
RouteMapDef,
|
|
7
|
+
RouterState,
|
|
8
|
+
} from 'iten-core'
|
|
2
9
|
import { createItenCore } from 'iten-core'
|
|
3
10
|
import { createStore } from 'zustand/vanilla'
|
|
4
11
|
import type {
|
|
@@ -11,11 +18,18 @@ import type {
|
|
|
11
18
|
export type ZustandRouter<M extends RouteMapDef, _Ctx = unknown> = {
|
|
12
19
|
store: ZustandRouterStore<M>
|
|
13
20
|
core: ItenCore<M>
|
|
21
|
+
to: RouteFactory<M>
|
|
14
22
|
navigate: ZustandRouterActions<M>['navigate']
|
|
15
23
|
goBack: ZustandRouterActions<M>['goBack']
|
|
16
24
|
dispose: ZustandRouterActions<M>['dispose']
|
|
17
25
|
}
|
|
18
26
|
|
|
27
|
+
export function createRouter<const Defs extends RouteDefinitions, Ctx = unknown>(
|
|
28
|
+
config: ZustandRouterConfig<InferRoutes<Defs>, Ctx> & { routes: Defs },
|
|
29
|
+
): ZustandRouter<InferRoutes<Defs>, Ctx>
|
|
30
|
+
export function createRouter<M extends RouteMapDef, Ctx = unknown>(
|
|
31
|
+
config: ZustandRouterConfig<M, Ctx>,
|
|
32
|
+
): ZustandRouter<M, Ctx>
|
|
19
33
|
export function createRouter<M extends RouteMapDef, Ctx = unknown>(
|
|
20
34
|
config: ZustandRouterConfig<M, Ctx>,
|
|
21
35
|
): ZustandRouter<M, Ctx> {
|
|
@@ -28,6 +42,7 @@ export function createRouter<M extends RouteMapDef, Ctx = unknown>(
|
|
|
28
42
|
|
|
29
43
|
const core = createItenCore<M, Ctx>({
|
|
30
44
|
initial: config.initial,
|
|
45
|
+
routes: config.routes,
|
|
31
46
|
routeConfig: config.routeConfig,
|
|
32
47
|
maxHistoryLength: config.maxHistoryLength,
|
|
33
48
|
queryClient: config.queryClient,
|
|
@@ -78,6 +93,7 @@ export function createRouter<M extends RouteMapDef, Ctx = unknown>(
|
|
|
78
93
|
return {
|
|
79
94
|
store,
|
|
80
95
|
core,
|
|
96
|
+
to: core.to,
|
|
81
97
|
navigate: actions.navigate,
|
|
82
98
|
goBack: actions.goBack,
|
|
83
99
|
dispose: actions.dispose,
|
package/src/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
RouteConfigMap,
|
|
7
7
|
RouteDefinition,
|
|
8
8
|
RouteDefinitions,
|
|
9
|
+
RouteFactory,
|
|
9
10
|
RouteMap,
|
|
10
11
|
RouteMapDef,
|
|
11
12
|
RouteMatcher,
|
|
@@ -25,6 +26,7 @@ export type {
|
|
|
25
26
|
RouteConfigMap,
|
|
26
27
|
RouteDefinition,
|
|
27
28
|
RouteDefinitions,
|
|
29
|
+
RouteFactory,
|
|
28
30
|
RouteMap,
|
|
29
31
|
RouteMapDef,
|
|
30
32
|
RouteMatcher,
|
|
@@ -38,6 +40,7 @@ export type {
|
|
|
38
40
|
|
|
39
41
|
export type ZustandRouterConfig<M extends RouteMapDef, Ctx = unknown> = {
|
|
40
42
|
initial: RouteUnion<M> | null
|
|
43
|
+
routes?: RouteDefinitions | undefined
|
|
41
44
|
routeConfig?: RouteConfigMap<M, Ctx> | undefined
|
|
42
45
|
maxHistoryLength?: number | undefined
|
|
43
46
|
context?: Ctx | (() => Ctx) | undefined
|
package/src/url.ts
CHANGED
|
@@ -31,6 +31,7 @@ export function createUrlSync<M extends RouteMapDef>({
|
|
|
31
31
|
}: CreateUrlSyncInput<M>): UrlSync<M> {
|
|
32
32
|
const coreLike: ItenCore<M> = {
|
|
33
33
|
getState: () => router.store.getState() as RouterState<M>,
|
|
34
|
+
to: router.to,
|
|
34
35
|
navigate: (navigateInput: NavigateInput<M>) => router.navigate(navigateInput),
|
|
35
36
|
goBack: () => router.goBack(),
|
|
36
37
|
subscribe: ({ listener }) =>
|