@koordinates/xstate-tree 5.1.0-next.12 → 5.1.0-next.13
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/xstate-tree.d.ts +4 -1
- package/lib/xstateTree.js +10 -11
- package/package.json +1 -1
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -136,7 +136,9 @@ export declare function buildCreateRoute(history: () => XstateTreeHistory, baseP
|
|
|
136
136
|
export declare function buildRootComponent<TMachine extends AnyXstateTreeMachine>(options: {
|
|
137
137
|
machine: TMachine;
|
|
138
138
|
} & MarkOptionalLikePropertiesOptional<RootOptions<InputFrom<TMachine>>>): {
|
|
139
|
-
(
|
|
139
|
+
({ children, }: {
|
|
140
|
+
children?: React_2.ReactNode;
|
|
141
|
+
}): JSX.Element;
|
|
140
142
|
rootMachine: TMachine;
|
|
141
143
|
};
|
|
142
144
|
|
|
@@ -699,6 +701,7 @@ export declare type View<TActionsOutput, TSelectorsOutput, TSlots extends readon
|
|
|
699
701
|
slots: Record<GetSlotNames<TSlots>, React_2.ComponentType>;
|
|
700
702
|
actions: TActionsOutput;
|
|
701
703
|
selectors: TSelectorsOutput;
|
|
704
|
+
children?: React_2.ReactNode;
|
|
702
705
|
}>;
|
|
703
706
|
|
|
704
707
|
/**
|
package/lib/xstateTree.js
CHANGED
|
@@ -69,7 +69,7 @@ interpreter) {
|
|
|
69
69
|
return interpreter.sessionId;
|
|
70
70
|
}
|
|
71
71
|
const getViewForInterpreter = (0, fast_memoize_1.default)((interpreter) => {
|
|
72
|
-
return react_2.default.memo(function InterpreterView() {
|
|
72
|
+
return react_2.default.memo(function InterpreterView({ children, }) {
|
|
73
73
|
const activeRouteEvents = (0, providers_1.useActiveRouteEvents)();
|
|
74
74
|
(0, react_2.useEffect)(() => {
|
|
75
75
|
if (activeRouteEvents) {
|
|
@@ -80,7 +80,7 @@ const getViewForInterpreter = (0, fast_memoize_1.default)((interpreter) => {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
}, []);
|
|
83
|
-
return react_2.default.createElement(XstateTreeView, { actor: interpreter });
|
|
83
|
+
return react_2.default.createElement(XstateTreeView, { actor: interpreter }, children);
|
|
84
84
|
});
|
|
85
85
|
},
|
|
86
86
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -105,7 +105,7 @@ function useSlots(interpreter, slots) {
|
|
|
105
105
|
return slots.reduce((views, slot) => {
|
|
106
106
|
return {
|
|
107
107
|
...views,
|
|
108
|
-
[slot]: () => {
|
|
108
|
+
[slot]: (({ children: reactChildren }) => {
|
|
109
109
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
110
110
|
const [__, children] = (0, useService_1.useService)(interpreter);
|
|
111
111
|
if (slot.toString().endsWith("Multi")) {
|
|
@@ -116,26 +116,25 @@ function useSlots(interpreter, slots) {
|
|
|
116
116
|
const interpreterForSlot = children[`${slot.toLowerCase()}-slot`];
|
|
117
117
|
if (interpreterForSlot) {
|
|
118
118
|
const View = getViewForInterpreter(interpreterForSlot);
|
|
119
|
-
return react_2.default.createElement(View, null);
|
|
119
|
+
return react_2.default.createElement(View, null, reactChildren);
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
122
|
// Waiting for the interpreter for this slot to be invoked
|
|
123
123
|
return null;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
},
|
|
126
|
+
}),
|
|
127
127
|
};
|
|
128
128
|
}, {});
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
function XstateTreeMultiSlotView({ childInterpreters, }) {
|
|
132
|
-
console.log("XstateTreeMultiSlotView", childInterpreters);
|
|
133
132
|
return (react_2.default.createElement(react_2.default.Fragment, null, childInterpreters.map((i) => (react_2.default.createElement(XstateTreeView, { key: i.id, actor: i })))));
|
|
134
133
|
}
|
|
135
134
|
/**
|
|
136
135
|
* @internal
|
|
137
136
|
*/
|
|
138
|
-
function XstateTreeView({ actor }) {
|
|
137
|
+
function XstateTreeView({ actor, children }) {
|
|
139
138
|
const [current] = (0, useService_1.useService)(actor);
|
|
140
139
|
const currentRef = (0, react_2.useRef)(current);
|
|
141
140
|
currentRef.current = current;
|
|
@@ -175,7 +174,7 @@ function XstateTreeView({ actor }) {
|
|
|
175
174
|
inState: inState,
|
|
176
175
|
meta: (0, utils_1.mergeMeta)(current.getMeta()),
|
|
177
176
|
});
|
|
178
|
-
return (react_2.default.createElement(View, { selectors: selectorsRef.current, actions: actions, slots: slots }));
|
|
177
|
+
return (react_2.default.createElement(View, { selectors: selectorsRef.current, actions: actions, slots: slots }, children));
|
|
179
178
|
}
|
|
180
179
|
exports.XstateTreeView = XstateTreeView;
|
|
181
180
|
/**
|
|
@@ -211,7 +210,7 @@ function buildRootComponent(options) {
|
|
|
211
210
|
if (!machine._xstateTree.View) {
|
|
212
211
|
throw new Error("Root machine has no associated view");
|
|
213
212
|
}
|
|
214
|
-
const RootComponent = function XstateTreeRootComponent() {
|
|
213
|
+
const RootComponent = function XstateTreeRootComponent({ children, }) {
|
|
215
214
|
const lastSnapshotsRef = (0, react_2.useRef)({});
|
|
216
215
|
const [_, __, interpreter] = (0, react_1.useActor)(machine, {
|
|
217
216
|
input,
|
|
@@ -367,10 +366,10 @@ function buildRootComponent(options) {
|
|
|
367
366
|
}, [activeRoute]);
|
|
368
367
|
if (routingProviderValue) {
|
|
369
368
|
return (react_2.default.createElement(routing_1.RoutingContext.Provider, { value: routingProviderValue },
|
|
370
|
-
react_2.default.createElement(XstateTreeView, { actor: interpreter })));
|
|
369
|
+
react_2.default.createElement(XstateTreeView, { actor: interpreter }, children)));
|
|
371
370
|
}
|
|
372
371
|
else {
|
|
373
|
-
return react_2.default.createElement(XstateTreeView, { actor: interpreter });
|
|
372
|
+
return react_2.default.createElement(XstateTreeView, { actor: interpreter }, children);
|
|
374
373
|
}
|
|
375
374
|
};
|
|
376
375
|
RootComponent.rootMachine = machine;
|
package/package.json
CHANGED