@koordinates/xstate-tree 4.1.0-beta.4 → 4.1.0-beta.6
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/builders.js +1 -1
- package/lib/index.js +1 -1
- package/lib/routing/index.js +1 -1
- package/lib/routing/providers.js +12 -0
- package/lib/xstate-tree.d.ts +14 -1
- package/lib/xstateTree.js +12 -3
- package/package.json +1 -1
package/lib/builders.js
CHANGED
|
@@ -122,7 +122,7 @@ export function createXStateTreeMachine(machine, options) {
|
|
|
122
122
|
const xstateTreeMeta = {
|
|
123
123
|
selectors,
|
|
124
124
|
actions,
|
|
125
|
-
|
|
125
|
+
View: options.View,
|
|
126
126
|
slots: (_c = options.slots) !== null && _c !== void 0 ? _c : [],
|
|
127
127
|
};
|
|
128
128
|
machine.meta = {
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,6 @@ export * from "./slots";
|
|
|
3
3
|
export { broadcast, buildRootComponent, onBroadcast } from "./xstateTree";
|
|
4
4
|
export * from "./types";
|
|
5
5
|
export { buildTestRootComponent, buildViewProps, genericSlotsTestingDummy, slotTestingDummyFactory, } from "./testingUtilities";
|
|
6
|
-
export { Link, buildCreateRoute, matchRoute, useIsRouteActive, useRouteArgsIfActive, } from "./routing";
|
|
6
|
+
export { Link, buildCreateRoute, matchRoute, useIsRouteActive, useRouteArgsIfActive, TestRoutingContext, } from "./routing";
|
|
7
7
|
export { loggingMetaOptions } from "./useService";
|
|
8
8
|
export { lazy } from "./lazy";
|
package/lib/routing/index.js
CHANGED
|
@@ -5,4 +5,4 @@ export { matchRoute } from "./matchRoute";
|
|
|
5
5
|
export { handleLocationChange, } from "./handleLocationChange";
|
|
6
6
|
export { useIsRouteActive } from "./useIsRouteActive";
|
|
7
7
|
export { useRouteArgsIfActive } from "./useRouteArgsIfActive";
|
|
8
|
-
export { RoutingContext } from "./providers";
|
|
8
|
+
export { RoutingContext, TestRoutingContext } from "./providers";
|
package/lib/routing/providers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { createContext, useContext } from "react";
|
|
2
3
|
export const RoutingContext = createContext(undefined);
|
|
3
4
|
function useRoutingContext() {
|
|
@@ -17,3 +18,14 @@ export function useActiveRouteEvents() {
|
|
|
17
18
|
return undefined;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*
|
|
24
|
+
* Renders the xstate-tree routing context. Designed for use in tests/storybook
|
|
25
|
+
* for components that make use of routing hooks but aren't part of an xstate-tree view
|
|
26
|
+
*
|
|
27
|
+
* @param activeRouteEvents - The active route events to use in the context
|
|
28
|
+
*/
|
|
29
|
+
export function TestRoutingContext({ activeRouteEvents, children, }) {
|
|
30
|
+
return (React.createElement(RoutingContext.Provider, { value: { activeRouteEvents: { current: activeRouteEvents } } }, children));
|
|
31
|
+
}
|
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -697,6 +697,19 @@ declare type States = {
|
|
|
697
697
|
*/
|
|
698
698
|
export declare type StyledLink<TStyleProps = {}> = <TRoute extends AnyRoute>(props: LinkProps<TRoute> & TStyleProps) => JSX.Element;
|
|
699
699
|
|
|
700
|
+
/**
|
|
701
|
+
* @public
|
|
702
|
+
*
|
|
703
|
+
* Renders the xstate-tree routing context. Designed for use in tests/storybook
|
|
704
|
+
* for components that make use of routing hooks but aren't part of an xstate-tree view
|
|
705
|
+
*
|
|
706
|
+
* @param activeRouteEvents - The active route events to use in the context
|
|
707
|
+
*/
|
|
708
|
+
export declare function TestRoutingContext({ activeRouteEvents, children, }: {
|
|
709
|
+
activeRouteEvents: RoutingEvent<any>[];
|
|
710
|
+
children: React_2.ReactNode;
|
|
711
|
+
}): JSX.Element;
|
|
712
|
+
|
|
700
713
|
/**
|
|
701
714
|
* @public
|
|
702
715
|
* Accepts Routes and returns true if any route is currently active. False if not.
|
|
@@ -731,7 +744,7 @@ export declare type V2BuilderMeta<TMachine extends AnyStateMachine, TSelectorsOu
|
|
|
731
744
|
selectors?: Selectors<TMachine, TSelectorsOutput>;
|
|
732
745
|
actions?: Actions<TMachine, TSelectorsOutput, TActionsOutput>;
|
|
733
746
|
slots?: TSlots;
|
|
734
|
-
|
|
747
|
+
View: View<TActionsOutput, TSelectorsOutput, TSlots>;
|
|
735
748
|
};
|
|
736
749
|
|
|
737
750
|
/**
|
package/lib/xstateTree.js
CHANGED
|
@@ -165,7 +165,7 @@ export function XstateTreeView({ interpreter }) {
|
|
|
165
165
|
const ViewV1 = interpreter.machine.meta.view;
|
|
166
166
|
return (React.createElement(ViewV1, { selectors: selectorsRef.current, actions: actions, slots: slots, inState: inState }));
|
|
167
167
|
case 2:
|
|
168
|
-
const ViewV2 = interpreter.machine.meta.
|
|
168
|
+
const ViewV2 = interpreter.machine.meta.View;
|
|
169
169
|
return (React.createElement(ViewV2, { selectors: selectorsRef.current, actions: actions, slots: slots }));
|
|
170
170
|
default:
|
|
171
171
|
throw new Error("builderVersion not set");
|
|
@@ -199,8 +199,17 @@ export function buildRootComponent(machine, routing) {
|
|
|
199
199
|
if (!machine.meta) {
|
|
200
200
|
throw new Error("Root machine has no meta");
|
|
201
201
|
}
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
switch (machine.meta.builderVersion) {
|
|
203
|
+
case 1:
|
|
204
|
+
if (!machine.meta.view) {
|
|
205
|
+
throw new Error("Root machine has no associated view");
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case 2:
|
|
209
|
+
if (!machine.meta.View) {
|
|
210
|
+
throw new Error("Root machine has no associated view");
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
204
213
|
}
|
|
205
214
|
const RootComponent = function XstateTreeRootComponent() {
|
|
206
215
|
const [_, __, interpreter] = useMachine(machine, { devTools: true });
|
package/package.json
CHANGED