@koordinates/xstate-tree 5.1.0-next.6 → 5.1.0-next.8

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.
@@ -19,7 +19,7 @@ function handleLocationChange(routes, basePath, path, search, meta) {
19
19
  return;
20
20
  }
21
21
  else if (match.type === "match-error") {
22
- console.error("Error matching route for", location.pathname);
22
+ console.error("Error matching route for", location.pathname, match.error);
23
23
  return;
24
24
  }
25
25
  else {
@@ -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(machine: AnyXstateTreeMachine, routing?: {
137
- routes: AnyRoute[];
138
- history: XstateTreeHistory<any>;
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: AnyXstateTreeMachine;
140
+ rootMachine: TMachine;
145
141
  };
146
142
 
147
143
  /**
@@ -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
- declare type MakeEmptyObjectPropertiesOptional<T> = Omit<T, EmptyKeys<T>> & Partial<Pick<T, EmptyKeys<T>>>;
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: MakeEmptyObjectPropertiesOptional<TArgs>) => TReturn;
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: MakeEmptyObjectPropertiesOptional<{
519
+ declare type RouteRedirect<TParams, TQuery, TMeta> = (args: MarkOptionalLikePropertiesOptional<{
508
520
  params: TParams;
509
521
  query: TQuery;
510
522
  meta?: TMeta;
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(machine, routing) {
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
@@ -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": "5.1.0-next.6",
5
+ "version": "5.1.0-next.8",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [