@koordinates/xstate-tree 4.3.0-beta.3 → 4.3.0-beta.5
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/xstate-tree.d.ts +15 -1
- package/lib/xstateTree.js +3 -2
- package/package.json +1 -1
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/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
|
@@ -152,7 +152,7 @@ function XstateTreeView({ interpreter }) {
|
|
|
152
152
|
// This is needed because the inState function needs to be recreated if the
|
|
153
153
|
// current state the machine is in changes. But _only_ then
|
|
154
154
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
|
-
[current.value]);
|
|
155
|
+
[current === null || current === void 0 ? void 0 : current.value]);
|
|
156
156
|
const selectorsProxy = (0, useConstant_1.useConstant)(() => {
|
|
157
157
|
return new Proxy({}, {
|
|
158
158
|
get: (_target, prop) => {
|
|
@@ -206,9 +206,10 @@ exports.XstateTreeView = XstateTreeView;
|
|
|
206
206
|
* @internal
|
|
207
207
|
*/
|
|
208
208
|
function recursivelySend(service, event) {
|
|
209
|
+
var _a;
|
|
209
210
|
const children = ([...service.children.values()] || []).filter((s) => s.id.includes("-slot"));
|
|
210
211
|
// If the service can't handle the event, don't send it
|
|
211
|
-
if (service.
|
|
212
|
+
if ((_a = service.getSnapshot()) === null || _a === void 0 ? void 0 : _a.nextEvents.includes(event.type)) {
|
|
212
213
|
try {
|
|
213
214
|
service.send(event);
|
|
214
215
|
}
|
package/package.json
CHANGED