@koordinates/xstate-tree 4.3.0-beta.2 → 4.3.0-beta.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/lib/routing/Link.js +35 -15
- package/lib/routing/index.js +2 -1
- package/lib/routing/providers.js +9 -1
- package/lib/xstate-tree.d.ts +15 -1
- package/lib/xstateTree.js +8 -0
- package/package.json +4 -3
package/lib/routing/Link.js
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.Link = void 0;
|
|
7
|
-
const react_1 =
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
8
28
|
const useHref_1 = require("./useHref");
|
|
9
|
-
|
|
10
|
-
* @public
|
|
11
|
-
*
|
|
12
|
-
* Renders an anchor tag pointing at the provided Route
|
|
13
|
-
*
|
|
14
|
-
* The query/params/meta props are conditionally required based on the
|
|
15
|
-
* route passed as the To parameter
|
|
16
|
-
*/
|
|
17
|
-
function Link({ to, children, testId, preloadOnHoverMs, preloadOnInteraction, onMouseDown: _onMouseDown, onMouseEnter: _onMouseEnter, onMouseLeave: _onMouseLeave, ...rest }) {
|
|
29
|
+
function LinkInner({ to, children, testId, preloadOnHoverMs, preloadOnInteraction, onMouseDown: _onMouseDown, onMouseEnter: _onMouseEnter, onMouseLeave: _onMouseLeave, ...rest }, ref) {
|
|
18
30
|
// @ts-ignore, these fields _might_ exist, so typechecking doesn't believe they exist
|
|
19
31
|
// and everything that consumes params/query already checks for undefined
|
|
20
32
|
const { params, query, meta, ...props } = rest;
|
|
@@ -42,9 +54,8 @@ function Link({ to, children, testId, preloadOnHoverMs, preloadOnInteraction, on
|
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
56
|
: undefined;
|
|
45
|
-
return (react_1.default.createElement("a", { ...props, href: href, "data-testid": testId, onMouseDown: onMouseDown !== null && onMouseDown !== void 0 ? onMouseDown : _onMouseDown, onMouseEnter: onMouseEnter !== null && onMouseEnter !== void 0 ? onMouseEnter : _onMouseEnter, onMouseLeave: onMouseLeave !== null && onMouseLeave !== void 0 ? onMouseLeave : _onMouseLeave, onClick: (e) => {
|
|
57
|
+
return (react_1.default.createElement("a", { ...props, ref: ref, href: href, "data-testid": testId, onMouseDown: onMouseDown !== null && onMouseDown !== void 0 ? onMouseDown : _onMouseDown, onMouseEnter: onMouseEnter !== null && onMouseEnter !== void 0 ? onMouseEnter : _onMouseEnter, onMouseLeave: onMouseLeave !== null && onMouseLeave !== void 0 ? onMouseLeave : _onMouseLeave, onClick: (e) => {
|
|
46
58
|
var _a;
|
|
47
|
-
e.preventDefault();
|
|
48
59
|
if (((_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e)) === false) {
|
|
49
60
|
return;
|
|
50
61
|
}
|
|
@@ -53,7 +64,16 @@ function Link({ to, children, testId, preloadOnHoverMs, preloadOnInteraction, on
|
|
|
53
64
|
if (e.metaKey || e.ctrlKey) {
|
|
54
65
|
return;
|
|
55
66
|
}
|
|
67
|
+
e.preventDefault();
|
|
56
68
|
to.navigate({ params, query, meta });
|
|
57
69
|
} }, children));
|
|
58
70
|
}
|
|
59
|
-
|
|
71
|
+
/**
|
|
72
|
+
* @public
|
|
73
|
+
*
|
|
74
|
+
* Renders an anchor tag pointing at the provided Route
|
|
75
|
+
*
|
|
76
|
+
* The query/params/meta props are conditionally required based on the
|
|
77
|
+
* route passed as the To parameter
|
|
78
|
+
*/
|
|
79
|
+
exports.Link = (0, react_1.forwardRef)(LinkInner);
|
package/lib/routing/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TestRoutingContext = exports.RoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.handleLocationChange = exports.matchRoute = exports.Link = exports.joinRoutes = exports.buildCreateRoute = void 0;
|
|
3
|
+
exports.useInRoutingContext = exports.TestRoutingContext = exports.RoutingContext = exports.useRouteArgsIfActive = exports.useIsRouteActive = exports.handleLocationChange = exports.matchRoute = exports.Link = exports.joinRoutes = exports.buildCreateRoute = void 0;
|
|
4
4
|
var createRoute_1 = require("./createRoute");
|
|
5
5
|
Object.defineProperty(exports, "buildCreateRoute", { enumerable: true, get: function () { return createRoute_1.buildCreateRoute; } });
|
|
6
6
|
var joinRoutes_1 = require("./joinRoutes");
|
|
@@ -18,3 +18,4 @@ Object.defineProperty(exports, "useRouteArgsIfActive", { enumerable: true, get:
|
|
|
18
18
|
var providers_1 = require("./providers");
|
|
19
19
|
Object.defineProperty(exports, "RoutingContext", { enumerable: true, get: function () { return providers_1.RoutingContext; } });
|
|
20
20
|
Object.defineProperty(exports, "TestRoutingContext", { enumerable: true, get: function () { return providers_1.TestRoutingContext; } });
|
|
21
|
+
Object.defineProperty(exports, "useInRoutingContext", { enumerable: true, get: function () { return providers_1.useInRoutingContext; } });
|
package/lib/routing/providers.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TestRoutingContext = exports.useActiveRouteEvents = exports.RoutingContext = void 0;
|
|
6
|
+
exports.TestRoutingContext = exports.useActiveRouteEvents = exports.useInRoutingContext = exports.RoutingContext = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const react_2 = require("react");
|
|
9
9
|
exports.RoutingContext = (0, react_2.createContext)(undefined);
|
|
@@ -14,6 +14,14 @@ function useRoutingContext() {
|
|
|
14
14
|
}
|
|
15
15
|
return context;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
function useInRoutingContext() {
|
|
21
|
+
const context = (0, react_2.useContext)(exports.RoutingContext);
|
|
22
|
+
return context !== undefined;
|
|
23
|
+
}
|
|
24
|
+
exports.useInRoutingContext = useInRoutingContext;
|
|
17
25
|
function useActiveRouteEvents() {
|
|
18
26
|
var _a;
|
|
19
27
|
try {
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -355,7 +355,21 @@ export declare function lazy<TMachine extends AnyStateMachine>(factory: () => Pr
|
|
|
355
355
|
* The query/params/meta props are conditionally required based on the
|
|
356
356
|
* route passed as the To parameter
|
|
357
357
|
*/
|
|
358
|
-
export declare
|
|
358
|
+
export declare const Link: <TRoute extends AnyRoute>(props: {
|
|
359
|
+
to: TRoute;
|
|
360
|
+
children: React_2.ReactNode;
|
|
361
|
+
testId?: string | undefined;
|
|
362
|
+
/**
|
|
363
|
+
* onClick works as normal, but if you return false from it the navigation will not happen
|
|
364
|
+
*/
|
|
365
|
+
onClick?: ((e: React_2.MouseEvent<HTMLAnchorElement>) => boolean | void) | undefined;
|
|
366
|
+
preloadOnInteraction?: boolean | undefined;
|
|
367
|
+
preloadOnHoverMs?: number | undefined;
|
|
368
|
+
} & RouteArguments<TRoute extends Route<infer TParams, any, any, any> ? TParams : undefined, TRoute extends Route<any, infer TQuery, any, any> ? TQuery : undefined, TRoute extends Route<any, any, any, infer TMeta> ? TMeta : undefined> & Omit<React_2.AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "onClick"> & {
|
|
369
|
+
ref?: React_2.ForwardedRef<HTMLAnchorElement> | undefined;
|
|
370
|
+
}) => ReturnType<typeof LinkInner>;
|
|
371
|
+
|
|
372
|
+
declare function LinkInner<TRoute extends AnyRoute>({ to, children, testId, preloadOnHoverMs, preloadOnInteraction, onMouseDown: _onMouseDown, onMouseEnter: _onMouseEnter, onMouseLeave: _onMouseLeave, ...rest }: LinkProps<TRoute>, ref: React_2.ForwardedRef<HTMLAnchorElement>): JSX.Element;
|
|
359
373
|
|
|
360
374
|
/**
|
|
361
375
|
* @public
|
package/lib/xstateTree.js
CHANGED
|
@@ -251,6 +251,14 @@ function buildRootComponent(machine, routing) {
|
|
|
251
251
|
const setActiveRouteEvents = (events) => {
|
|
252
252
|
activeRouteEventsRef.current = events;
|
|
253
253
|
};
|
|
254
|
+
const insideRoutingContext = (0, routing_1.useInRoutingContext)();
|
|
255
|
+
if (insideRoutingContext && typeof routing !== "undefined") {
|
|
256
|
+
const m = "Routing root rendered inside routing context, this implies a bug";
|
|
257
|
+
if (process.env.NODE_ENV !== "production") {
|
|
258
|
+
throw new Error(m);
|
|
259
|
+
}
|
|
260
|
+
console.error(m);
|
|
261
|
+
}
|
|
254
262
|
(0, react_2.useEffect)(() => {
|
|
255
263
|
function handler(event) {
|
|
256
264
|
recursivelySend(interpreter, event);
|
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.3.0-beta.
|
|
5
|
+
"version": "4.3.0-beta.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Build UIs with Actors using xstate and React",
|
|
8
8
|
"keywords": [
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@testing-library/user-event": "^14.4.3",
|
|
38
38
|
"@types/history": "^4.7.7",
|
|
39
39
|
"@types/jest": "^28.1.4",
|
|
40
|
+
"@types/node": "^20.4.9",
|
|
40
41
|
"@types/react": "^17.0.29",
|
|
41
42
|
"@types/react-dom": "^18.0.6",
|
|
42
43
|
"@types/testing-library__jest-dom": "^5.14.1",
|
|
@@ -72,9 +73,9 @@
|
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
75
|
"@xstate/react": "^3.x",
|
|
76
|
+
"react": ">= 16.8.0 < 19.0.0",
|
|
75
77
|
"xstate": ">= 4.20 < 5.0.0",
|
|
76
|
-
"zod": "^3.x"
|
|
77
|
-
"react": ">= 16.8.0 < 19.0.0"
|
|
78
|
+
"zod": "^3.x"
|
|
78
79
|
},
|
|
79
80
|
"scripts": {
|
|
80
81
|
"lint": "eslint 'src/**/*'",
|