ui-router-effect 0.0.0-stage → 0.1.0-rc.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/LICENSE +9 -0
- package/README.md +27 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/route-ref.d.ts +13 -0
- package/dist/route-ref.d.ts.map +1 -0
- package/dist/route-ref.js +14 -0
- package/dist/route-ref.js.map +1 -0
- package/dist/shared/route-snapshot.d.ts +25 -0
- package/dist/shared/route-snapshot.d.ts.map +1 -0
- package/dist/shared/route-snapshot.js +27 -0
- package/dist/shared/route-snapshot.js.map +1 -0
- package/package.json +43 -3
- package/src/index.ts +3 -0
- package/src/route-ref.ts +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Lit UI-Router Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ui-router-effect
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Effect](https://effect.website) bindings for [UI-Router](https://ui-router.github.io): a framework-agnostic `SubscriptionRef` of the router's current state. It imports only `effect` and `@uirouter/core`.
|
|
4
|
+
|
|
5
|
+
[`lit-ui-router-effect`](../lit-ui-router-effect/) holds the Lit controllers.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **`routeRef(router)`**: a `SubscriptionRef<RouteSnapshot>` of the current state, params and transition. There is one ref, and one `onSuccess` hook, per router, attached lazily on first use. Every value it holds is a settled route.
|
|
10
|
+
- **`RouteSnapshot`** and **`snapshotRoute(router, transition?)`**: the value the ref holds. Its `includes()` evaluates `StateService.includes` against the snapshot, not the live router.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { Effect, Stream } from 'effect';
|
|
16
|
+
import { routeRef } from 'ui-router-effect';
|
|
17
|
+
|
|
18
|
+
const names = routeRef(router).changes.pipe(
|
|
19
|
+
Stream.map((route) => route.current?.name),
|
|
20
|
+
Stream.changes,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
Effect.runFork(Stream.runForEach(names, (name) => Effect.log(name)));
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Dependencies
|
|
27
|
+
|
|
28
|
+
`@uirouter/core` and `effect` are peer dependencies. `lit` and `lit-ui-router` are not, and the `bundleProbe` claim in `package.json` holds the entry free of them.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","mappings":"AAAA,SAAS,gBAAgB;AAEzB,cAAc,eAAe,qBAAqB","names":[],"ignoreList":[],"sources":["../src/index.ts"]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAAA,SAAS,gBAAgB;AAEzB,SAA6B,qBAAqB","names":[],"ignoreList":[],"sources":["../src/index.ts"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SubscriptionRef } from "effect";
|
|
2
|
+
import { UIRouter } from "@uirouter/core";
|
|
3
|
+
import { RouteSnapshot } from "./shared/route-snapshot.js";
|
|
4
|
+
/**
|
|
5
|
+
* The route ref for a router — one per router instance, attached lazily.
|
|
6
|
+
*
|
|
7
|
+
* No plugin and no router-configuration wiring: the first caller creates the
|
|
8
|
+
* ref and registers the single `onSuccess` hook that feeds it, and both live
|
|
9
|
+
* as long as the router does. `onSuccess` is the only hook a later transition
|
|
10
|
+
* cannot supersede, so every value the ref ever holds is a settled route.
|
|
11
|
+
*/
|
|
12
|
+
export declare function routeRef(router: UIRouter): SubscriptionRef.SubscriptionRef<RouteSnapshot>;
|
|
13
|
+
//# sourceMappingURL=route-ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-ref.d.ts","mappings":"AAAA,SAAiB,uBAAuB;AACxC,SAAS,gBAAgB;AAEzB,SAAS,qBAAoC;;;;;;;;;AAe7C,OAAO,iBAAS,SACd,QAAQ,WACP,gBAAgB,gBAAgB","names":[],"ignoreList":[],"sources":["../src/route-ref.ts"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect, SubscriptionRef } from "effect";
|
|
2
|
+
import { snapshotRoute } from "./shared/route-snapshot.js";
|
|
3
|
+
const routeRefs = new WeakMap();
|
|
4
|
+
export function routeRef(router) {
|
|
5
|
+
const existing = routeRefs.get(router);
|
|
6
|
+
if (existing) return existing;
|
|
7
|
+
const ref = Effect.runSync(SubscriptionRef.make(snapshotRoute(router)));
|
|
8
|
+
routeRefs.set(router, ref);
|
|
9
|
+
router.transitionService.onSuccess({}, (transition) => {
|
|
10
|
+
Effect.runSync(SubscriptionRef.set(ref, snapshotRoute(router, transition)));
|
|
11
|
+
});
|
|
12
|
+
return ref;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=route-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-ref.js","mappings":"AAAA,SAAS,QAAQ,uBAAuB;AAGxC,SAAwB,qBAAqB;AAE7C,MAAM,YAAY,IAAI,QAGpB;AAUF,OAAO,SAAS,SACd,QACgD;CAChD,MAAM,WAAW,UAAU,IAAI,MAAM;CAErC,IAAI,UAAU,OAAO;CACrB,MAAM,MAAM,OAAO,QAAQ,gBAAgB,KAAK,cAAc,MAAM,CAAC,CAAC;CACtE,UAAU,IAAI,QAAQ,GAAG;CACzB,OAAO,kBAAkB,UAAU,CAAC,IAAI,eAAe;EACrD,OAAO,QAAQ,gBAAgB,IAAI,KAAK,cAAc,QAAQ,UAAU,CAAC,CAAC;CAC5E,CAAC;CAED,OAAO;AACT","names":[],"ignoreList":[],"sources":["../src/route-ref.ts"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RawParams, StateDeclaration, StateOrName, Transition, UIRouter } from "@uirouter/core";
|
|
2
|
+
/**
|
|
3
|
+
* The router's current state as one immutable value, for a reactive cell to hold.
|
|
4
|
+
*
|
|
5
|
+
* Taken once per successful transition; every field, `includes()` included,
|
|
6
|
+
* answers for that moment. A selector asking during a later transition gets
|
|
7
|
+
* the settled answer, not the in-flight one.
|
|
8
|
+
*/
|
|
9
|
+
export interface RouteSnapshot {
|
|
10
|
+
/** The current state declaration (`globals.current`). */
|
|
11
|
+
readonly current: StateDeclaration | undefined;
|
|
12
|
+
/** The current parameter values (`globals.params`), replaced per transition. */
|
|
13
|
+
readonly params: RawParams;
|
|
14
|
+
/** The transition that produced this snapshot; `undefined` before the first. */
|
|
15
|
+
readonly transition: Transition | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* `StateService.includes` evaluated against this snapshot: is the state (or
|
|
18
|
+
* glob pattern, e.g. `'admin.**'`) included in the snapshot's active state,
|
|
19
|
+
* with these parameter values?
|
|
20
|
+
*/
|
|
21
|
+
includes(stateOrName: StateOrName, params?: RawParams): boolean;
|
|
22
|
+
}
|
|
23
|
+
/** The snapshot of a router right now; `StateService.includes` minus the live reads. */
|
|
24
|
+
export declare function snapshotRoute(router: UIRouter, transition?: Transition | undefined): RouteSnapshot;
|
|
25
|
+
//# sourceMappingURL=route-snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-snapshot.d.ts","mappings":"AAAA,SAIE,WACA,kBACA,aACA,YACA,gBACK;;;;;;;;AASP,iBAAiB,cAAc;;UAEpB,SAAS;;UAGT,QAAQ;;UAGR,YAAY;;;;;;CAOrB,SAAS,aAAa,aAAa,SAAS;AAC9C;;AAGA,OAAO,iBAAS,cACd,QAAQ,UACR,aACI,yBAEH","names":[],"ignoreList":[],"sources":["../../../shared/route-snapshot/src/route-snapshot.ts"],"sourcesContent":["import {\n Glob,\n isString,\n Param,\n RawParams,\n StateDeclaration,\n StateOrName,\n Transition,\n UIRouter,\n} from '@uirouter/core';\n\n/**\n * The router's current state as one immutable value, for a reactive cell to hold.\n *\n * Taken once per successful transition; every field, `includes()` included,\n * answers for that moment. A selector asking during a later transition gets\n * the settled answer, not the in-flight one.\n */\nexport interface RouteSnapshot {\n /** The current state declaration (`globals.current`). */\n readonly current: StateDeclaration | undefined;\n\n /** The current parameter values (`globals.params`), replaced per transition. */\n readonly params: RawParams;\n\n /** The transition that produced this snapshot; `undefined` before the first. */\n readonly transition: Transition | undefined;\n\n /**\n * `StateService.includes` evaluated against this snapshot: is the state (or\n * glob pattern, e.g. `'admin.**'`) included in the snapshot's active state,\n * with these parameter values?\n */\n includes(stateOrName: StateOrName, params?: RawParams): boolean;\n}\n\n/** The snapshot of a router right now; `StateService.includes` minus the live reads. */\nexport function snapshotRoute(\n router: UIRouter,\n transition:\n | Transition\n | undefined = router.globals.successfulTransitions.peekTail(),\n): RouteSnapshot {\n const { $current, current } = router.globals;\n // eslint-disable-next-line typescript/no-misused-spread -- snapshot StateParams' own props as a fresh plain object per transition\n const params: RawParams = { ...router.globals.params };\n const { matcher } = router.stateRegistry;\n\n return {\n current,\n params,\n transition,\n includes(stateOrName, values) {\n let target = stateOrName;\n\n if (isString(stateOrName) && Glob.is(stateOrName)) {\n if (!Glob.fromString(stateOrName).matches($current.name)) return false;\n target = $current.name;\n }\n\n // SAFETY: `find` returns undefined for an unregistered state, which its signature omits.\n const state = matcher.find(target, $current) as\n | ReturnType<typeof matcher.find>\n | undefined;\n\n if (!state || !$current.includes[state.name]) return false;\n\n if (!values) return true;\n const schema = state.parameters({ inherit: true, matchingKeys: values });\n\n return Param.equals(schema, Param.values(schema, params), values);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Glob, isString, Param } from "@uirouter/core";
|
|
2
|
+
export function snapshotRoute(router, transition = router.globals.successfulTransitions.peekTail()) {
|
|
3
|
+
const { $current, current } = router.globals;
|
|
4
|
+
const params = { ...router.globals.params };
|
|
5
|
+
const { matcher } = router.stateRegistry;
|
|
6
|
+
return {
|
|
7
|
+
current,
|
|
8
|
+
params,
|
|
9
|
+
transition,
|
|
10
|
+
includes(stateOrName, values) {
|
|
11
|
+
let target = stateOrName;
|
|
12
|
+
if (isString(stateOrName) && Glob.is(stateOrName)) {
|
|
13
|
+
if (!Glob.fromString(stateOrName).matches($current.name)) return false;
|
|
14
|
+
target = $current.name;
|
|
15
|
+
}
|
|
16
|
+
const state = matcher.find(target, $current);
|
|
17
|
+
if (!state || !$current.includes[state.name]) return false;
|
|
18
|
+
if (!values) return true;
|
|
19
|
+
const schema = state.parameters({
|
|
20
|
+
inherit: true,
|
|
21
|
+
matchingKeys: values
|
|
22
|
+
});
|
|
23
|
+
return Param.equals(schema, Param.values(schema, params), values);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=route-snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-snapshot.js","mappings":"AAAA,SACE,MACA,UACA,aAMK;AA4BP,OAAO,SAAS,cACd,QACA,aAEgB,OAAO,QAAQ,sBAAsB,SAAS,GAC/C;CACf,MAAM,EAAE,UAAU,YAAY,OAAO;CAErC,MAAM,SAAoB,EAAE,GAAG,OAAO,QAAQ,OAAO;CACrD,MAAM,EAAE,YAAY,OAAO;CAE3B,OAAO;EACL;EACA;EACA;EACA,SAAS,aAAa,QAAQ;GAC5B,IAAI,SAAS;GAEb,IAAI,SAAS,WAAW,KAAK,KAAK,GAAG,WAAW,GAAG;IACjD,IAAI,CAAC,KAAK,WAAW,WAAW,CAAC,CAAC,QAAQ,SAAS,IAAI,GAAG,OAAO;IACjE,SAAS,SAAS;GACpB;GAGA,MAAM,QAAQ,QAAQ,KAAK,QAAQ,QAAQ;GAI3C,IAAI,CAAC,SAAS,CAAC,SAAS,SAAS,MAAM,OAAO,OAAO;GAErD,IAAI,CAAC,QAAQ,OAAO;GACpB,MAAM,SAAS,MAAM,WAAW;IAAE,SAAS;IAAM,cAAc;GAAO,CAAC;GAEvE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,QAAQ,MAAM,GAAG,MAAM;EAClE;CACF;AACF","names":[],"ignoreList":[],"sources":["../../../shared/route-snapshot/src/route-snapshot.ts"],"sourcesContent":["import {\n Glob,\n isString,\n Param,\n RawParams,\n StateDeclaration,\n StateOrName,\n Transition,\n UIRouter,\n} from '@uirouter/core';\n\n/**\n * The router's current state as one immutable value, for a reactive cell to hold.\n *\n * Taken once per successful transition; every field, `includes()` included,\n * answers for that moment. A selector asking during a later transition gets\n * the settled answer, not the in-flight one.\n */\nexport interface RouteSnapshot {\n /** The current state declaration (`globals.current`). */\n readonly current: StateDeclaration | undefined;\n\n /** The current parameter values (`globals.params`), replaced per transition. */\n readonly params: RawParams;\n\n /** The transition that produced this snapshot; `undefined` before the first. */\n readonly transition: Transition | undefined;\n\n /**\n * `StateService.includes` evaluated against this snapshot: is the state (or\n * glob pattern, e.g. `'admin.**'`) included in the snapshot's active state,\n * with these parameter values?\n */\n includes(stateOrName: StateOrName, params?: RawParams): boolean;\n}\n\n/** The snapshot of a router right now; `StateService.includes` minus the live reads. */\nexport function snapshotRoute(\n router: UIRouter,\n transition:\n | Transition\n | undefined = router.globals.successfulTransitions.peekTail(),\n): RouteSnapshot {\n const { $current, current } = router.globals;\n // eslint-disable-next-line typescript/no-misused-spread -- snapshot StateParams' own props as a fresh plain object per transition\n const params: RawParams = { ...router.globals.params };\n const { matcher } = router.stateRegistry;\n\n return {\n current,\n params,\n transition,\n includes(stateOrName, values) {\n let target = stateOrName;\n\n if (isString(stateOrName) && Glob.is(stateOrName)) {\n if (!Glob.fromString(stateOrName).matches($current.name)) return false;\n target = $current.name;\n }\n\n // SAFETY: `find` returns undefined for an unregistered state, which its signature omits.\n const state = matcher.find(target, $current) as\n | ReturnType<typeof matcher.find>\n | undefined;\n\n if (!state || !$current.includes[state.name]) return false;\n\n if (!values) return true;\n const schema = state.parameters({ inherit: true, matchingKeys: values });\n\n return Param.equals(schema, Param.values(schema, params), values);\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-router-effect",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-rc.0",
|
|
4
|
+
"description": "Effect bindings for UI-Router: a framework-agnostic SubscriptionRef of the router's current state",
|
|
5
|
+
"homepage": "https://lit-ui-router.dev/packages/ui-router-effect",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/simshanith/lit-ui-router/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Shane Daniel",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/simshanith/lit-ui-router.git",
|
|
14
|
+
"directory": "packages/ui-router-effect"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**",
|
|
18
|
+
"!dist/.*/**",
|
|
19
|
+
"src/*.ts"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./dist/*": "./dist/*",
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@uirouter/core": "^6.0.8",
|
|
36
|
+
"effect": "^3.22.0 || ^4.0.2"
|
|
37
|
+
},
|
|
38
|
+
"bundleProbe": {
|
|
39
|
+
".": {
|
|
40
|
+
"free": [
|
|
41
|
+
"lit",
|
|
42
|
+
"lit-ui-router"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
6
46
|
}
|
package/src/index.ts
ADDED
package/src/route-ref.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect, SubscriptionRef } from 'effect';
|
|
2
|
+
import { UIRouter } from '@uirouter/core';
|
|
3
|
+
|
|
4
|
+
import { RouteSnapshot, snapshotRoute } from '@repo/route-snapshot';
|
|
5
|
+
|
|
6
|
+
const routeRefs = new WeakMap<
|
|
7
|
+
UIRouter,
|
|
8
|
+
SubscriptionRef.SubscriptionRef<RouteSnapshot>
|
|
9
|
+
>();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The route ref for a router — one per router instance, attached lazily.
|
|
13
|
+
*
|
|
14
|
+
* No plugin and no router-configuration wiring: the first caller creates the
|
|
15
|
+
* ref and registers the single `onSuccess` hook that feeds it, and both live
|
|
16
|
+
* as long as the router does. `onSuccess` is the only hook a later transition
|
|
17
|
+
* cannot supersede, so every value the ref ever holds is a settled route.
|
|
18
|
+
*/
|
|
19
|
+
export function routeRef(
|
|
20
|
+
router: UIRouter,
|
|
21
|
+
): SubscriptionRef.SubscriptionRef<RouteSnapshot> {
|
|
22
|
+
const existing = routeRefs.get(router);
|
|
23
|
+
|
|
24
|
+
if (existing) return existing;
|
|
25
|
+
const ref = Effect.runSync(SubscriptionRef.make(snapshotRoute(router)));
|
|
26
|
+
routeRefs.set(router, ref);
|
|
27
|
+
router.transitionService.onSuccess({}, (transition) => {
|
|
28
|
+
Effect.runSync(SubscriptionRef.set(ref, snapshotRoute(router, transition)));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return ref;
|
|
32
|
+
}
|