@koordinates/xstate-tree 4.1.0-beta.2 → 4.1.0-beta.3
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/lib/routing/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export { joinRoutes } from "./joinRoutes";
|
|
|
3
3
|
export { Link } from "./Link";
|
|
4
4
|
export { matchRoute } from "./matchRoute";
|
|
5
5
|
export { handleLocationChange, } from "./handleLocationChange";
|
|
6
|
+
export { useIsRouteActive } from "./useIsRouteActive";
|
|
6
7
|
export { RoutingContext } from "./providers";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useActiveRouteEvents } from "./providers";
|
|
2
|
+
/**
|
|
3
|
+
* Accepts Routes and returns true if any route is currently active. False if not.
|
|
4
|
+
*
|
|
5
|
+
* If used outside of a RoutingContext, an error will be thrown.
|
|
6
|
+
* @param routes - the routes to check
|
|
7
|
+
* @returns true if any route is active, false if not
|
|
8
|
+
* @throws if used outside of a RoutingContext
|
|
9
|
+
*/
|
|
10
|
+
export function useIsRouteActive(...routes) {
|
|
11
|
+
const activeRouteEvents = useActiveRouteEvents();
|
|
12
|
+
if (!activeRouteEvents) {
|
|
13
|
+
throw new Error("useIsRouteActive must be used within a RoutingContext. Are you using it outside of an xstate-tree Root?");
|
|
14
|
+
}
|
|
15
|
+
return activeRouteEvents.some((activeRouteEvent) => {
|
|
16
|
+
return routes.some((route) => activeRouteEvent.type === route.event);
|
|
17
|
+
});
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@koordinates/xstate-tree",
|
|
3
3
|
"main": "lib/index.js",
|
|
4
4
|
"types": "lib/xstate-tree.d.ts",
|
|
5
|
-
"version": "4.1.0-beta.
|
|
5
|
+
"version": "4.1.0-beta.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Build UIs with Actors using xstate and React",
|
|
8
8
|
"keywords": [
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@saithodev/semantic-release-backmerge": "^2.1.2",
|
|
34
34
|
"@testing-library/dom": "^8.14.0",
|
|
35
35
|
"@testing-library/jest-dom": "^5.16.1",
|
|
36
|
-
"@testing-library/react": "^
|
|
36
|
+
"@testing-library/react": "^13.4.0",
|
|
37
37
|
"@testing-library/user-event": "^13.5.0",
|
|
38
38
|
"@types/history": "^4.7.7",
|
|
39
39
|
"@types/jest": "^28.1.4",
|
|
@@ -73,7 +73,8 @@
|
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@xstate/react": "^3.x",
|
|
75
75
|
"xstate": ">= 4.20 < 5.0.0",
|
|
76
|
-
"zod": "^3.x"
|
|
76
|
+
"zod": "^3.x",
|
|
77
|
+
"react": ">= 16.8.0 < 19.0.0"
|
|
77
78
|
},
|
|
78
79
|
"scripts": {
|
|
79
80
|
"lint": "eslint 'src/**/*'",
|