@koordinates/xstate-tree 5.1.0-next.7 → 5.1.0-next.9
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 +27 -15
- package/lib/xstateTree.js +3 -1
- package/package.json +1 -1
package/lib/xstate-tree.d.ts
CHANGED
|
@@ -133,15 +133,11 @@ export declare function buildCreateRoute(history: () => XstateTreeHistory, baseP
|
|
|
133
133
|
* @param machine - The root machine of the tree
|
|
134
134
|
* @param routing - The routing configuration for the tree
|
|
135
135
|
*/
|
|
136
|
-
export declare function buildRootComponent(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
basePath: string;
|
|
140
|
-
getPathName?: () => string;
|
|
141
|
-
getQueryString?: () => string;
|
|
142
|
-
}): {
|
|
136
|
+
export declare function buildRootComponent<TMachine extends AnyXstateTreeMachine>(options: {
|
|
137
|
+
machine: TMachine;
|
|
138
|
+
} & MarkOptionalLikePropertiesOptional<RootOptions<InputFrom<TMachine>>>): {
|
|
143
139
|
(): JSX.Element;
|
|
144
|
-
rootMachine:
|
|
140
|
+
rootMachine: TMachine;
|
|
145
141
|
};
|
|
146
142
|
|
|
147
143
|
/**
|
|
@@ -177,7 +173,7 @@ export declare type CanHandleEvent<TMachine extends AnyStateMachine> = (e: Event
|
|
|
177
173
|
* @param machine - The xstate machine to create the xstate-tree machine from
|
|
178
174
|
* @param options - the xstate-tree options
|
|
179
175
|
*/
|
|
180
|
-
export declare function createXStateTreeMachine<TMachine extends AnyStateMachine, TSelectorsOutput = ContextFrom<TMachine>, TActionsOutput = Record<never, string>, TSlots extends readonly Slot[] = []>(machine: TMachine, options: V2BuilderMeta<TMachine, TSelectorsOutput, TActionsOutput, TSlots>): XstateTreeMachine<TMachine>;
|
|
176
|
+
export declare function createXStateTreeMachine<TMachine extends AnyStateMachine, TSelectorsOutput = ContextFrom<TMachine>, TActionsOutput = Record<never, string>, TSlots extends readonly Slot[] = []>(machine: TMachine, options: V2BuilderMeta<TMachine, TSelectorsOutput, TActionsOutput, TSlots>): XstateTreeMachine<TMachine, TSelectorsOutput, TActionsOutput, TSlots>;
|
|
181
177
|
|
|
182
178
|
declare type EmptyKeys<T> = keyof {
|
|
183
179
|
[K in keyof T as IsEmptyObject<T[K], true> extends true ? K : never]: T[K];
|
|
@@ -217,6 +213,8 @@ declare type IsEmptyObject<Obj, ExcludeOptional extends boolean = false> = undef
|
|
|
217
213
|
never
|
|
218
214
|
] ? true : false;
|
|
219
215
|
|
|
216
|
+
declare type IsUnknown<T> = unknown extends T ? true : false;
|
|
217
|
+
|
|
220
218
|
/**
|
|
221
219
|
* @public
|
|
222
220
|
*
|
|
@@ -278,7 +276,10 @@ export declare function loggingMetaOptions<TEvents extends EventObject, TContext
|
|
|
278
276
|
};
|
|
279
277
|
};
|
|
280
278
|
|
|
281
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Marks any required property that can accept undefined as optional
|
|
281
|
+
*/
|
|
282
|
+
declare type MarkOptionalLikePropertiesOptional<T> = Omit<T, EmptyKeys<T>> & Partial<Pick<T, EmptyKeys<T>>>;
|
|
282
283
|
|
|
283
284
|
/**
|
|
284
285
|
* @internal
|
|
@@ -382,6 +383,17 @@ declare type Return<TRoutes extends Route<any, any, any, any>[]> = {
|
|
|
382
383
|
error: unknown;
|
|
383
384
|
};
|
|
384
385
|
|
|
386
|
+
declare type RootOptions<TInput> = {
|
|
387
|
+
routing: {
|
|
388
|
+
routes: AnyRoute[];
|
|
389
|
+
history: XstateTreeHistory<any>;
|
|
390
|
+
basePath: string;
|
|
391
|
+
getPathName?: () => string;
|
|
392
|
+
getQueryString?: () => string;
|
|
393
|
+
} | undefined;
|
|
394
|
+
input: IsUnknown<TInput> extends true ? undefined : TInput;
|
|
395
|
+
};
|
|
396
|
+
|
|
385
397
|
/**
|
|
386
398
|
* @public
|
|
387
399
|
*
|
|
@@ -457,7 +469,7 @@ export declare type Route<TParams, TQuery, TEvent, TMeta> = {
|
|
|
457
469
|
/**
|
|
458
470
|
* @public
|
|
459
471
|
*/
|
|
460
|
-
export declare type RouteArgumentFunctions<TReturn, TParams, TQuery, TMeta, TArgs = RouteArguments<TParams, TQuery, TMeta>> = IsEmptyObject<TArgs> extends true ? () => TReturn : keyof TArgs extends "meta" ? (args?: TArgs) => TReturn : EmptyRouteArguments<TParams, TQuery> extends true ? (args?: Partial<TArgs>) => TReturn : (args:
|
|
472
|
+
export declare type RouteArgumentFunctions<TReturn, TParams, TQuery, TMeta, TArgs = RouteArguments<TParams, TQuery, TMeta>> = IsEmptyObject<TArgs> extends true ? () => TReturn : keyof TArgs extends "meta" ? (args?: TArgs) => TReturn : EmptyRouteArguments<TParams, TQuery> extends true ? (args?: Partial<TArgs>) => TReturn : (args: MarkOptionalLikePropertiesOptional<TArgs>) => TReturn;
|
|
461
473
|
|
|
462
474
|
/**
|
|
463
475
|
* @public
|
|
@@ -504,7 +516,7 @@ export declare type RouteParams<T> = T extends Route<infer TParams, any, any, an
|
|
|
504
516
|
*/
|
|
505
517
|
export declare type RouteQuery<T> = T extends Route<any, infer TQuery, any, any> ? TQuery : undefined;
|
|
506
518
|
|
|
507
|
-
declare type RouteRedirect<TParams, TQuery, TMeta> = (args:
|
|
519
|
+
declare type RouteRedirect<TParams, TQuery, TMeta> = (args: MarkOptionalLikePropertiesOptional<{
|
|
508
520
|
params: TParams;
|
|
509
521
|
query: TQuery;
|
|
510
522
|
meta?: TMeta;
|
|
@@ -704,13 +716,13 @@ export declare type XstateTreeHistory<T = unknown> = History_2<{
|
|
|
704
716
|
/**
|
|
705
717
|
* @public
|
|
706
718
|
*/
|
|
707
|
-
export declare type XstateTreeMachine<TMachine extends AnyStateMachine> = TMachine & XstateTreeMachineInjection<TMachine>;
|
|
719
|
+
export declare type XstateTreeMachine<TMachine extends AnyStateMachine, TSelectorsOutput = ContextFrom<TMachine>, TActionsOutput = Record<never, string>, TSlots extends readonly Slot[] = Slot[]> = TMachine & XstateTreeMachineInjection<TMachine, TSelectorsOutput, TActionsOutput, TSlots>;
|
|
708
720
|
|
|
709
721
|
/**
|
|
710
722
|
* @internal
|
|
711
723
|
*/
|
|
712
|
-
export declare type XstateTreeMachineInjection<TMachine extends AnyStateMachine> = {
|
|
713
|
-
_xstateTree: XstateTreeMachineStateSchemaV2<TMachine>;
|
|
724
|
+
export declare type XstateTreeMachineInjection<TMachine extends AnyStateMachine, TSelectorsOutput = ContextFrom<TMachine>, TActionsOutput = Record<never, string>, TSlots extends readonly Slot[] = Slot[]> = {
|
|
725
|
+
_xstateTree: XstateTreeMachineStateSchemaV2<TMachine, TSelectorsOutput, TActionsOutput, TSlots>;
|
|
714
726
|
};
|
|
715
727
|
|
|
716
728
|
/**
|
package/lib/xstateTree.js
CHANGED
|
@@ -203,7 +203,8 @@ exports.recursivelySend = recursivelySend;
|
|
|
203
203
|
* @param machine - The root machine of the tree
|
|
204
204
|
* @param routing - The routing configuration for the tree
|
|
205
205
|
*/
|
|
206
|
-
function buildRootComponent(
|
|
206
|
+
function buildRootComponent(options) {
|
|
207
|
+
const { input, machine, routing } = options;
|
|
207
208
|
if (!machine._xstateTree) {
|
|
208
209
|
throw new Error("Root machine is not an xstate-tree machine, missing metadata");
|
|
209
210
|
}
|
|
@@ -213,6 +214,7 @@ function buildRootComponent(machine, routing) {
|
|
|
213
214
|
const RootComponent = function XstateTreeRootComponent() {
|
|
214
215
|
const lastSnapshotsRef = (0, react_2.useRef)({});
|
|
215
216
|
const [_, __, interpreter] = (0, react_1.useActor)(machine, {
|
|
217
|
+
input,
|
|
216
218
|
inspect(event) {
|
|
217
219
|
switch (event.type) {
|
|
218
220
|
case "@xstate.actor":
|
package/package.json
CHANGED