diff --git a/README.md b/README.md index a60da0e..5d10c31 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Each machine that forms the tree representing your UI has an associated set of s To assist in making xstate-tree easy to use with TypeScript there is the `createXStateTreeMachine` function for typing selectors, actions and view arguments and stapling the resulting functions to the xstate machine `createXStateTreeMachine` accepts the xstate machine as the first argument and takes an options argument with the following fields, it is important the fields are defined in this order or TypeScript will infer the wrong types: -* `selectors`, receives an object with `ctx`, `inState`, and `canHandleEvent` fields. `ctx` is the machines current context, `inState` is the xstate `state.matches` function to allow determining if the machine is in a given state, and `canHandleEvent` accepts an event object and returns whether the machine will do anything in response to that event in it's current state +* `selectors`, receives an object with `ctx`, `inState`, `canHandleEvent`, and `meta` fields. `ctx` is the machines current context, `inState` is the xstate `state.matches` function to allow determining if the machine is in a given state, and `canHandleEvent` accepts an event object and returns whether the machine will do anything in response to that event in it's current state. `meta` is the xstate `state.meta` object with all the per state meta flattened into an object * `actions`, receives an object with `send` and `selectors` fields. `send` is the xstate `send` function bound to the machine, and `selectors` is the result of calling the selector function * `view`, is a React component that receives `actions`, `selectors`, and `slots` as props. `actions` and `selectors` being the result of the action/selector functions and `slots` being an object with keys as the slot names and the values the slots React component diff --git a/src/types.ts b/src/types.ts index b6fca49..837f91a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -171,6 +171,7 @@ export type Selectors = (args: { ctx: ContextFrom; canHandleEvent: CanHandleEvent; inState: MatchesFrom; + meta?: unknown; }) => TOut; /** diff --git a/src/utils.ts b/src/utils.ts index 4dd67e4..fb185bb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -162,3 +162,14 @@ export function isNil( ): value is null | undefined { return value === null || value === undefined; } + +export function mergeMeta(meta: Record) { + return Object.keys(meta).reduce((acc, key) => { + const value = meta[key]; + + // Assuming each meta value is an object + Object.assign(acc, value); + + return acc; + }, {}); +} diff --git a/src/xstateTree.spec.tsx b/src/xstateTree.spec.tsx index 06e2f04..68dbb99 100644 --- a/src/xstateTree.spec.tsx +++ b/src/xstateTree.spec.tsx @@ -242,6 +242,34 @@ describe("xstate-tree", () => { expect(childMachineHandler).toHaveBeenCalled(); }); + it("passes the current states meta into the v2 selector functions", async () => { + const machine = createMachine({ + id: "test-selectors-meta", + initial: "idle", + states: { + idle: { + meta: { + foo: "bar", + }, + }, + }, + }); + + const XstateTreeMachine = createXStateTreeMachine(machine, { + selectors({ meta }) { + return { foo: (meta as any)?.foo }; + }, + View: ({ selectors }) => { + return

{selectors.foo}

; + }, + }); + const Root = buildRootComponent(XstateTreeMachine); + + const { findByText } = render(); + + expect(await findByText("bar")).toBeTruthy(); + }); + describe("getMultiSlotViewForChildren", () => { it("memoizes correctly", () => { const machine = createMachine({ diff --git a/src/xstateTree.tsx b/src/xstateTree.tsx index 1c1d4fe..fda1a1e 100644 --- a/src/xstateTree.tsx +++ b/src/xstateTree.tsx @@ -30,7 +30,7 @@ import { GetSlotNames, Slot } from "./slots"; import { GlobalEvents, AnyXstateTreeMachine, XstateTreeHistory } from "./types"; import { useConstant } from "./useConstant"; import { useService } from "./useService"; -import { assertIsDefined, isLikelyPageLoad } from "./utils"; +import { assertIsDefined, isLikelyPageLoad, mergeMeta } from "./utils"; export const emitter = new TinyEmitter(); @@ -249,6 +249,7 @@ export function XstateTreeView({ interpreter }: XStateTreeViewProps) { ctx: current.context, canHandleEvent, inState, + meta: mergeMeta(current.meta), }); break; } diff --git a/xstate-tree.api.md b/xstate-tree.api.md index 72092e0..e887b0e 100644 --- a/xstate-tree.api.md +++ b/xstate-tree.api.md @@ -1,472 +1,473 @@ -## API Report File for "@koordinates/xstate-tree" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import { AnyEventObject } from 'xstate'; -import type { AnyFunction } from 'xstate'; -import { AnyStateMachine } from 'xstate'; -import { BaseActionObject } from 'xstate'; -import { ComponentPropsWithRef } from 'react'; -import { ContextFrom } from 'xstate'; -import { EventFrom } from 'xstate'; -import { EventObject } from 'xstate'; -import { History as History_2 } from 'history'; -import type { InterpreterFrom } from 'xstate'; -import { JSXElementConstructor } from 'react'; -import { ParsedQuery } from 'query-string'; -import { default as React_2 } from 'react'; -import { ResolveTypegenMeta } from 'xstate'; -import { ServiceMap } from 'xstate'; -import type { StateFrom } from 'xstate'; -import { StateMachine } from 'xstate'; -import { TypegenDisabled } from 'xstate'; -import * as Z from 'zod'; - -// @public (undocumented) -export type Actions = (args: { - send: InterpreterFrom["send"]; - selectors: TSelectorsOutput; -}) => TOut; - -// @public -export type ActionsFrom = TMachine extends StateMachine ? TMeta extends { - meta: { - actions: infer TOut; - }; -} ? TOut extends (...args: any) => any ? ReturnType : never : never : never; - -// @public (undocumented) -export type AnyActions = (send: any, selectors: any) => any; - -// @public (undocumented) -export type AnyRoute = { - matches: (url: string, search: string) => any; - reverse: any; - navigate: any; - getEvent: any; - event: string; - preload: any; - basePath: string; - history: () => XstateTreeHistory; - parent?: AnyRoute; - paramsSchema?: Z.ZodObject; - querySchema?: Z.ZodObject; - matcher: (url: string, query: ParsedQuery | undefined) => any; - reverser: any; - redirect?: any; -}; - -// @public (undocumented) -export type AnySelector = V1Selectors; - -// @public (undocumented) -export type AnyXstateTreeMachine = StateMachine | XstateTreeMachineStateSchemaV2, any>; - -// @public (undocumented) -export type ArgumentsForRoute = T extends Route ? RouteArguments : never; - -// @public -export function broadcast(event: GlobalEvents): void; - -// @public @deprecated -export function buildActions["send"]>(__machine: TMachine, __selectors: TSelectors, actions: (send: TSend, selectors: OutputFromSelector) => TActions): (send: TSend, selectors: OutputFromSelector) => TActions; - -// @public -export function buildCreateRoute(history: () => XstateTreeHistory, basePath: string): { - simpleRoute(baseRoute?: TBaseRoute | undefined): | undefined, TQuerySchema extends Z.ZodObject | undefined, TMeta extends Record>({ url, paramsSchema, querySchema, ...args }: { - event: TEvent; - url: string; - paramsSchema?: TParamsSchema | undefined; - querySchema?: TQuerySchema | undefined; - meta?: TMeta | undefined; - redirect?: RouteRedirect, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta> & SharedMeta> | undefined; - preload?: RouteArgumentFunctions, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta>, RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta>>> | undefined; - }) => Route, ResolveZodType>, ResolveZodType, TEvent, MergeRouteTypes, TMeta> & SharedMeta>; - route(baseRoute?: TBaseRoute_1 | undefined): | undefined, TQuerySchema_1 extends Z.ZodObject | undefined, TMeta_1 extends Record>({ event, matcher, reverser, paramsSchema, querySchema, redirect, preload, }: { - event: TEvent_1; - paramsSchema?: TParamsSchema_1 | undefined; - querySchema?: TQuerySchema_1 | undefined; - meta?: TMeta_1 | undefined; - redirect?: RouteRedirect, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1> & SharedMeta> | undefined; - matcher: (url: string, query: ParsedQuery | undefined) => false | (RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>> & { - matchLength: number; - }); - reverser: RouteArgumentFunctions, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>, RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>>>; - preload?: RouteArgumentFunctions, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>, RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>>> | undefined; - }) => Route, ResolveZodType>, ResolveZodType, TEvent_1, MergeRouteTypes, TMeta_1> & SharedMeta>; -}; - -// @public -export function buildRootComponent(machine: AnyXstateTreeMachine, routing?: { - routes: AnyRoute[]; - history: XstateTreeHistory; - basePath: string; - getPathName?: () => string; - getQueryString?: () => string; -}): { - (): JSX.Element | null; - rootMachine: AnyXstateTreeMachine; -}; - -// Warning: (ae-incompatible-release-tags) The symbol "buildSelectors" is marked as @public, but its signature references "CanHandleEvent" which is marked as @internal -// Warning: (ae-incompatible-release-tags) The symbol "buildSelectors" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal -// -// @public @deprecated -export function buildSelectors>(__machine: TMachine, selectors: (ctx: TContext, canHandleEvent: CanHandleEvent, inState: MatchesFrom, __currentState: never) => TSelectors): V1Selectors, TSelectors, MatchesFrom>; - -// @public -export function buildTestRootComponent>(machine: StateMachine | XstateTreeMachineStateSchemaV2, EventFrom>, logger: typeof console.log): { - rootComponent: () => JSX.Element | null; - addTransitionListener: (listener: () => void) => void; - awaitTransition(): Promise; -}; - -// Warning: (ae-incompatible-release-tags) The symbol "buildView" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal -// -// @public @deprecated -export function buildView, TViewProps = ViewProps, TActions, TSlots, TMatches>, TSend = (send: TEvent) => void>(__machine: TMachine, __selectors: TSelectors, __actions: (send: TSend, selectors: OutputFromSelector) => TActions, __slots: TSlots, view: React_2.ComponentType): React_2.ComponentType; - -// Warning: (ae-forgotten-export) The symbol "InferViewProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "PropsOf" needs to be exported by the entry point index.d.ts -// -// @public -export function buildViewProps>(_view: C, props: Pick>, "actions" | "selectors">): InferViewProps>; - -// @public @deprecated -export function buildXStateTreeMachine(machine: TMachine, meta: XStateTreeMachineMetaV1): StateMachine, XstateTreeMachineStateSchemaV1, EventFrom, any, any, any, any>; - -// Warning: (ae-internal-missing-underscore) The name "CanHandleEvent" should be prefixed with an underscore because the declaration is marked as @internal -// -// @internal (undocumented) -export type CanHandleEvent = (e: EventFrom) => boolean; - -// @public -export function createXStateTreeMachine, TActionsOutput = Record, TSlots extends readonly Slot[] = []>(machine: TMachine, options: V2BuilderMeta): StateMachine, XstateTreeMachineStateSchemaV2, EventFrom, any, any, any, any>; - -// @public -export const genericSlotsTestingDummy: any; - -// @public (undocumented) -export type GetSlotNames = TSlots[number]["name"]; - -// @public -export type GlobalEvents = { - [I in keyof XstateTreeEvents]: XstateTreeEvents[I] extends string ? { - type: I; - } : XstateTreeEvents[I] & { - type: I; - }; -}[keyof XstateTreeEvents]; - -// Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "Context" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "Events" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "States" needs to be exported by the entry point index.d.ts -// -// @public -export function lazy(factory: () => Promise, { Loader, withContext, }?: Options): StateMachine; - -// Warning: (ae-forgotten-export) The symbol "LinkInner" needs to be exported by the entry point index.d.ts -// -// @public -export const Link: (props: { - to: TRoute; - children: React_2.ReactNode; - testId?: string | undefined; - onClick?: ((e: React_2.MouseEvent) => boolean | void) | undefined; - preloadOnInteraction?: boolean | undefined; - preloadOnHoverMs?: number | undefined; -} & RouteArguments ? TParams : undefined, TRoute extends Route ? TQuery : undefined, TRoute extends Route ? TMeta : undefined> & Omit, "href" | "onClick"> & { - ref?: React_2.ForwardedRef | undefined; -}) => ReturnType; - -// @public (undocumented) -export type LinkProps ? TParams : undefined, TRouteQuery = TRoute extends Route ? TQuery : undefined, TRouteMeta = TRoute extends Route ? TMeta : undefined> = { - to: TRoute; - children: React_2.ReactNode; - testId?: string; - onClick?: (e: React_2.MouseEvent) => boolean | void; - preloadOnInteraction?: boolean; - preloadOnHoverMs?: number; -} & RouteArguments & Omit, "href" | "onClick">; - -// @public (undocumented) -export function loggingMetaOptions(ignoredEvents: TEvents["type"][], ignoreContext?: (keyof TContext)[] | undefined): { - xstateTree: { - ignoredEvents: Map; - ignoreContext: (keyof TContext)[] | undefined; - }; -}; - -// Warning: (ae-internal-missing-underscore) The name "MatchesFrom" should be prefixed with an underscore because the declaration is marked as @internal -// -// @internal (undocumented) -export type MatchesFrom = StateFrom["matches"]; - -// Warning: (ae-forgotten-export) The symbol "Return" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export function matchRoute[]>(routes: TRoutes, basePath: string, path: string, search: string): Return; - -// @public -export type Meta = T extends { - meta: infer TMeta; -} ? TMeta : undefined; - -// @public (undocumented) -export type MultiSlot = { - type: SlotType.MultiSlot; - name: `${T}Multi`; - getId(id: string): string; -}; - -// @public (undocumented) -export function multiSlot(name: T): MultiSlot; - -// @public -export function onBroadcast(handler: (event: GlobalEvents) => void): () => void; - -// @public (undocumented) -export type OutputFromSelector = T extends V1Selectors ? O : never; - -// @public -export type Params = T extends { - params: infer TParams; -} ? TParams : undefined; - -// @public -export type PickEvent["type"]> = Extract; - -// @public -export type Query = T extends { - query: infer TQuery; -} ? TQuery : undefined; - -// @public -export type Route = { - matches: (url: string, search: string) => ({ - type: TEvent; - originalUrl: string; - } & RouteArguments) | false; - reverse: RouteArgumentFunctions; - navigate: RouteArgumentFunctions; - preload: RouteArgumentFunctions; - getEvent: RouteArgumentFunctions<{ - type: TEvent; - } & RouteArguments, TParams, TQuery, TMeta>; - matcher: (url: string, query: ParsedQuery | undefined) => (RouteArguments & { - matchLength: number; - }) | false; - reverser: RouteArgumentFunctions; - event: TEvent; - history: () => XstateTreeHistory; - basePath: string; - parent?: AnyRoute; - paramsSchema?: Z.ZodObject; - querySchema?: Z.ZodObject; - redirect?: RouteRedirect; -}; - -// Warning: (ae-forgotten-export) The symbol "IsEmptyObject" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "EmptyRouteArguments" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "MakeEmptyObjectPropertiesOptional" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export type RouteArgumentFunctions> = IsEmptyObject extends true ? () => TReturn : keyof TArgs extends "meta" ? (args?: TArgs) => TReturn : EmptyRouteArguments extends true ? (args?: Partial) => TReturn : (args: MakeEmptyObjectPropertiesOptional) => TReturn; - -// @public (undocumented) -export type RouteArguments = TParams extends undefined ? TQuery extends undefined ? TMeta extends undefined ? {} : { - meta?: TMeta; -} : TMeta extends undefined ? { - query: TQuery; -} : { - query: TQuery; - meta?: TMeta; -} : TQuery extends undefined ? TMeta extends undefined ? { - params: TParams; -} : { - params: TParams; - meta?: TMeta; -} : TMeta extends undefined ? { - params: TParams; - query: TQuery; -} : { - params: TParams; - query: TQuery; - meta?: TMeta; -}; - -// @public -export type RouteMeta = T extends Route ? TMeta : undefined; - -// @public -export type RouteParams = T extends Route ? TParams : undefined; - -// @public (undocumented) -export type Routing404Event = { - type: "ROUTING_404"; - url: string; -}; - -// @public -export type RoutingEvent = T extends Route ? { - type: TEvent; - originalUrl: string; - params: TParams; - query: TQuery; - meta: TMeta; -} : never; - -// @public (undocumented) -export type Selectors = (args: { - ctx: ContextFrom; - canHandleEvent: CanHandleEvent; - inState: MatchesFrom; -}) => TOut; - -// @public -export type SelectorsFrom = TMachine extends StateMachine ? TMeta extends { - meta: { - selectors: infer TOut; - }; -} ? TOut extends (...args: any) => any ? ReturnType : never : never : never; - -// @public (undocumented) -export type SharedMeta = { - doNotNotifyReactRouter?: boolean; - indexEvent?: boolean; - replace?: boolean; - onloadEvent?: boolean; -}; - -// @public (undocumented) -export type SingleSlot = { - type: SlotType.SingleSlot; - name: T; - getId(): string; -}; - -// @public (undocumented) -export function singleSlot(name: T): SingleSlot; - -// @public (undocumented) -export type Slot = SingleSlot | MultiSlot; - -// @public -export function slotTestingDummyFactory(name: string): StateMachine>, () => {}, () => {}>, AnyEventObject, any, any, any, any>; - -// @public (undocumented) -export enum SlotType { - // (undocumented) - MultiSlot = 1, - // (undocumented) - SingleSlot = 0 -} - -// @public (undocumented) -export type StyledLink = (props: LinkProps & TStyleProps) => JSX.Element; - -// @public -export function TestRoutingContext({ activeRouteEvents, children, }: { - activeRouteEvents: RoutingEvent[]; - children: React_2.ReactNode; -}): JSX.Element; - -// @public -export function useIsRouteActive(...routes: AnyRoute[]): boolean; - -// @public -export function useRouteArgsIfActive(route: TRoute): ArgumentsForRoute | undefined; - -// @public (undocumented) -export type V1Selectors = (ctx: TContext, canHandleEvent: (e: TEvent) => boolean, inState: TMatches, __currentState: never) => TSelectors; - -// @public (undocumented) -export type V2BuilderMeta, TActionsOutput = Record, TSlots extends readonly Slot[] = Slot[]> = { - selectors?: Selectors; - actions?: Actions; - slots?: TSlots; - View: View; -}; - -// @public (undocumented) -export type View = React_2.ComponentType<{ - slots: Record, React_2.ComponentType>; - actions: TActionsOutput; - selectors: TSelectorsOutput; -}>; - -// @public (undocumented) -export type ViewProps = { - slots: Record, React_2.ComponentType>; - actions: TActions; - selectors: TSelectors; - inState: TMatches; -}; - -// @public (undocumented) -export type XstateTreeHistory = History_2<{ - meta?: T; - previousUrl?: string; -}>; - -// @public (undocumented) -export type XStateTreeMachineMetaV1 = { - slots: TSlots; - view: React_2.ComponentType, ReturnType, TSlots, MatchesFrom>>; - selectors: TSelectors; - actions: TActions; - xstateTreeMachine?: true; -}; - -// @public (undocumented) -export type XstateTreeMachineStateSchemaV1 = { - meta: XStateTreeMachineMetaV1 & { - builderVersion: 1; - }; -}; - -// @public (undocumented) -export type XstateTreeMachineStateSchemaV2, TActionsOutput = Record, TSlots extends readonly Slot[] = Slot[]> = { - meta: Required & { - builderVersion: 2; - }>; -}; - -// Warnings were encountered during analysis: -// -// src/routing/createRoute/createRoute.ts:279:19 - (ae-forgotten-export) The symbol "MergeRouteTypes" needs to be exported by the entry point index.d.ts -// src/routing/createRoute/createRoute.ts:279:19 - (ae-forgotten-export) The symbol "ResolveZodType" needs to be exported by the entry point index.d.ts -// src/routing/createRoute/createRoute.ts:316:9 - (ae-forgotten-export) The symbol "RouteRedirect" needs to be exported by the entry point index.d.ts -// src/types.ts:25:3 - (ae-incompatible-release-tags) The symbol "view" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal -// src/types.ts:172:3 - (ae-incompatible-release-tags) The symbol "canHandleEvent" is marked as @public, but its signature references "CanHandleEvent" which is marked as @internal -// src/types.ts:173:3 - (ae-incompatible-release-tags) The symbol "inState" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal - -// (No @packageDocumentation comment for this package) - -``` +## API Report File for "@koordinates/xstate-tree" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { AnyEventObject } from 'xstate'; +import type { AnyFunction } from 'xstate'; +import { AnyStateMachine } from 'xstate'; +import { BaseActionObject } from 'xstate'; +import { ComponentPropsWithRef } from 'react'; +import { ContextFrom } from 'xstate'; +import { EventFrom } from 'xstate'; +import { EventObject } from 'xstate'; +import { History as History_2 } from 'history'; +import type { InterpreterFrom } from 'xstate'; +import { JSXElementConstructor } from 'react'; +import { ParsedQuery } from 'query-string'; +import { default as React_2 } from 'react'; +import { ResolveTypegenMeta } from 'xstate'; +import { ServiceMap } from 'xstate'; +import type { StateFrom } from 'xstate'; +import { StateMachine } from 'xstate'; +import { TypegenDisabled } from 'xstate'; +import * as Z from 'zod'; + +// @public (undocumented) +export type Actions = (args: { + send: InterpreterFrom["send"]; + selectors: TSelectorsOutput; +}) => TOut; + +// @public +export type ActionsFrom = TMachine extends StateMachine ? TMeta extends { + meta: { + actions: infer TOut; + }; +} ? TOut extends (...args: any) => any ? ReturnType : never : never : never; + +// @public (undocumented) +export type AnyActions = (send: any, selectors: any) => any; + +// @public (undocumented) +export type AnyRoute = { + matches: (url: string, search: string) => any; + reverse: any; + navigate: any; + getEvent: any; + event: string; + preload: any; + basePath: string; + history: () => XstateTreeHistory; + parent?: AnyRoute; + paramsSchema?: Z.ZodObject; + querySchema?: Z.ZodObject; + matcher: (url: string, query: ParsedQuery | undefined) => any; + reverser: any; + redirect?: any; +}; + +// @public (undocumented) +export type AnySelector = V1Selectors; + +// @public (undocumented) +export type AnyXstateTreeMachine = StateMachine | XstateTreeMachineStateSchemaV2, any>; + +// @public (undocumented) +export type ArgumentsForRoute = T extends Route ? RouteArguments : never; + +// @public +export function broadcast(event: GlobalEvents): void; + +// @public @deprecated +export function buildActions["send"]>(__machine: TMachine, __selectors: TSelectors, actions: (send: TSend, selectors: OutputFromSelector) => TActions): (send: TSend, selectors: OutputFromSelector) => TActions; + +// @public +export function buildCreateRoute(history: () => XstateTreeHistory, basePath: string): { + simpleRoute(baseRoute?: TBaseRoute | undefined): | undefined, TQuerySchema extends Z.ZodObject | undefined, TMeta extends Record>({ url, paramsSchema, querySchema, ...args }: { + event: TEvent; + url: string; + paramsSchema?: TParamsSchema | undefined; + querySchema?: TQuerySchema | undefined; + meta?: TMeta | undefined; + redirect?: RouteRedirect, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta> & SharedMeta> | undefined; + preload?: RouteArgumentFunctions, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta>, RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta>>> | undefined; + }) => Route, ResolveZodType>, ResolveZodType, TEvent, MergeRouteTypes, TMeta> & SharedMeta>; + route(baseRoute?: TBaseRoute_1 | undefined): | undefined, TQuerySchema_1 extends Z.ZodObject | undefined, TMeta_1 extends Record>({ event, matcher, reverser, paramsSchema, querySchema, redirect, preload, }: { + event: TEvent_1; + paramsSchema?: TParamsSchema_1 | undefined; + querySchema?: TQuerySchema_1 | undefined; + meta?: TMeta_1 | undefined; + redirect?: RouteRedirect, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1> & SharedMeta> | undefined; + matcher: (url: string, query: ParsedQuery | undefined) => false | (RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>> & { + matchLength: number; + }); + reverser: RouteArgumentFunctions, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>, RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>>>; + preload?: RouteArgumentFunctions, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>, RouteArguments, ResolveZodType>, ResolveZodType, MergeRouteTypes, TMeta_1>>> | undefined; + }) => Route, ResolveZodType>, ResolveZodType, TEvent_1, MergeRouteTypes, TMeta_1> & SharedMeta>; +}; + +// @public +export function buildRootComponent(machine: AnyXstateTreeMachine, routing?: { + routes: AnyRoute[]; + history: XstateTreeHistory; + basePath: string; + getPathName?: () => string; + getQueryString?: () => string; +}): { + (): JSX.Element | null; + rootMachine: AnyXstateTreeMachine; +}; + +// Warning: (ae-incompatible-release-tags) The symbol "buildSelectors" is marked as @public, but its signature references "CanHandleEvent" which is marked as @internal +// Warning: (ae-incompatible-release-tags) The symbol "buildSelectors" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal +// +// @public @deprecated +export function buildSelectors>(__machine: TMachine, selectors: (ctx: TContext, canHandleEvent: CanHandleEvent, inState: MatchesFrom, __currentState: never) => TSelectors): V1Selectors, TSelectors, MatchesFrom>; + +// @public +export function buildTestRootComponent>(machine: StateMachine | XstateTreeMachineStateSchemaV2, EventFrom>, logger: typeof console.log): { + rootComponent: () => JSX.Element | null; + addTransitionListener: (listener: () => void) => void; + awaitTransition(): Promise; +}; + +// Warning: (ae-incompatible-release-tags) The symbol "buildView" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal +// +// @public @deprecated +export function buildView, TViewProps = ViewProps, TActions, TSlots, TMatches>, TSend = (send: TEvent) => void>(__machine: TMachine, __selectors: TSelectors, __actions: (send: TSend, selectors: OutputFromSelector) => TActions, __slots: TSlots, view: React_2.ComponentType): React_2.ComponentType; + +// Warning: (ae-forgotten-export) The symbol "InferViewProps" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "PropsOf" needs to be exported by the entry point index.d.ts +// +// @public +export function buildViewProps>(_view: C, props: Pick>, "actions" | "selectors">): InferViewProps>; + +// @public @deprecated +export function buildXStateTreeMachine(machine: TMachine, meta: XStateTreeMachineMetaV1): StateMachine, XstateTreeMachineStateSchemaV1, EventFrom, any, any, any, any>; + +// Warning: (ae-internal-missing-underscore) The name "CanHandleEvent" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export type CanHandleEvent = (e: EventFrom) => boolean; + +// @public +export function createXStateTreeMachine, TActionsOutput = Record, TSlots extends readonly Slot[] = []>(machine: TMachine, options: V2BuilderMeta): StateMachine, XstateTreeMachineStateSchemaV2, EventFrom, any, any, any, any>; + +// @public +export const genericSlotsTestingDummy: any; + +// @public (undocumented) +export type GetSlotNames = TSlots[number]["name"]; + +// @public +export type GlobalEvents = { + [I in keyof XstateTreeEvents]: XstateTreeEvents[I] extends string ? { + type: I; + } : XstateTreeEvents[I] & { + type: I; + }; +}[keyof XstateTreeEvents]; + +// Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "Context" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "Events" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "States" needs to be exported by the entry point index.d.ts +// +// @public +export function lazy(factory: () => Promise, { Loader, withContext, }?: Options): StateMachine; + +// Warning: (ae-forgotten-export) The symbol "LinkInner" needs to be exported by the entry point index.d.ts +// +// @public +export const Link: (props: { + to: TRoute; + children: React_2.ReactNode; + testId?: string | undefined; + onClick?: ((e: React_2.MouseEvent) => boolean | void) | undefined; + preloadOnInteraction?: boolean | undefined; + preloadOnHoverMs?: number | undefined; +} & RouteArguments ? TParams : undefined, TRoute extends Route ? TQuery : undefined, TRoute extends Route ? TMeta : undefined> & Omit, "href" | "onClick"> & { + ref?: React_2.ForwardedRef | undefined; +}) => ReturnType; + +// @public (undocumented) +export type LinkProps ? TParams : undefined, TRouteQuery = TRoute extends Route ? TQuery : undefined, TRouteMeta = TRoute extends Route ? TMeta : undefined> = { + to: TRoute; + children: React_2.ReactNode; + testId?: string; + onClick?: (e: React_2.MouseEvent) => boolean | void; + preloadOnInteraction?: boolean; + preloadOnHoverMs?: number; +} & RouteArguments & Omit, "href" | "onClick">; + +// @public (undocumented) +export function loggingMetaOptions(ignoredEvents: TEvents["type"][], ignoreContext?: (keyof TContext)[] | undefined): { + xstateTree: { + ignoredEvents: Map; + ignoreContext: (keyof TContext)[] | undefined; + }; +}; + +// Warning: (ae-internal-missing-underscore) The name "MatchesFrom" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export type MatchesFrom = StateFrom["matches"]; + +// Warning: (ae-forgotten-export) The symbol "Return" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export function matchRoute[]>(routes: TRoutes, basePath: string, path: string, search: string): Return; + +// @public +export type Meta = T extends { + meta: infer TMeta; +} ? TMeta : undefined; + +// @public (undocumented) +export type MultiSlot = { + type: SlotType.MultiSlot; + name: `${T}Multi`; + getId(id: string): string; +}; + +// @public (undocumented) +export function multiSlot(name: T): MultiSlot; + +// @public +export function onBroadcast(handler: (event: GlobalEvents) => void): () => void; + +// @public (undocumented) +export type OutputFromSelector = T extends V1Selectors ? O : never; + +// @public +export type Params = T extends { + params: infer TParams; +} ? TParams : undefined; + +// @public +export type PickEvent["type"]> = Extract; + +// @public +export type Query = T extends { + query: infer TQuery; +} ? TQuery : undefined; + +// @public +export type Route = { + matches: (url: string, search: string) => ({ + type: TEvent; + originalUrl: string; + } & RouteArguments) | false; + reverse: RouteArgumentFunctions; + navigate: RouteArgumentFunctions; + preload: RouteArgumentFunctions; + getEvent: RouteArgumentFunctions<{ + type: TEvent; + } & RouteArguments, TParams, TQuery, TMeta>; + matcher: (url: string, query: ParsedQuery | undefined) => (RouteArguments & { + matchLength: number; + }) | false; + reverser: RouteArgumentFunctions; + event: TEvent; + history: () => XstateTreeHistory; + basePath: string; + parent?: AnyRoute; + paramsSchema?: Z.ZodObject; + querySchema?: Z.ZodObject; + redirect?: RouteRedirect; +}; + +// Warning: (ae-forgotten-export) The symbol "IsEmptyObject" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "EmptyRouteArguments" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "MakeEmptyObjectPropertiesOptional" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type RouteArgumentFunctions> = IsEmptyObject extends true ? () => TReturn : keyof TArgs extends "meta" ? (args?: TArgs) => TReturn : EmptyRouteArguments extends true ? (args?: Partial) => TReturn : (args: MakeEmptyObjectPropertiesOptional) => TReturn; + +// @public (undocumented) +export type RouteArguments = TParams extends undefined ? TQuery extends undefined ? TMeta extends undefined ? {} : { + meta?: TMeta; +} : TMeta extends undefined ? { + query: TQuery; +} : { + query: TQuery; + meta?: TMeta; +} : TQuery extends undefined ? TMeta extends undefined ? { + params: TParams; +} : { + params: TParams; + meta?: TMeta; +} : TMeta extends undefined ? { + params: TParams; + query: TQuery; +} : { + params: TParams; + query: TQuery; + meta?: TMeta; +}; + +// @public +export type RouteMeta = T extends Route ? TMeta : undefined; + +// @public +export type RouteParams = T extends Route ? TParams : undefined; + +// @public (undocumented) +export type Routing404Event = { + type: "ROUTING_404"; + url: string; +}; + +// @public +export type RoutingEvent = T extends Route ? { + type: TEvent; + originalUrl: string; + params: TParams; + query: TQuery; + meta: TMeta; +} : never; + +// @public (undocumented) +export type Selectors = (args: { + ctx: ContextFrom; + canHandleEvent: CanHandleEvent; + inState: MatchesFrom; + meta?: unknown; +}) => TOut; + +// @public +export type SelectorsFrom = TMachine extends StateMachine ? TMeta extends { + meta: { + selectors: infer TOut; + }; +} ? TOut extends (...args: any) => any ? ReturnType : never : never : never; + +// @public (undocumented) +export type SharedMeta = { + doNotNotifyReactRouter?: boolean; + indexEvent?: boolean; + replace?: boolean; + onloadEvent?: boolean; +}; + +// @public (undocumented) +export type SingleSlot = { + type: SlotType.SingleSlot; + name: T; + getId(): string; +}; + +// @public (undocumented) +export function singleSlot(name: T): SingleSlot; + +// @public (undocumented) +export type Slot = SingleSlot | MultiSlot; + +// @public +export function slotTestingDummyFactory(name: string): StateMachine>, () => {}, () => {}>, AnyEventObject, any, any, any, any>; + +// @public (undocumented) +export enum SlotType { + // (undocumented) + MultiSlot = 1, + // (undocumented) + SingleSlot = 0 +} + +// @public (undocumented) +export type StyledLink = (props: LinkProps & TStyleProps) => JSX.Element; + +// @public +export function TestRoutingContext({ activeRouteEvents, children, }: { + activeRouteEvents: RoutingEvent[]; + children: React_2.ReactNode; +}): JSX.Element; + +// @public +export function useIsRouteActive(...routes: AnyRoute[]): boolean; + +// @public +export function useRouteArgsIfActive(route: TRoute): ArgumentsForRoute | undefined; + +// @public (undocumented) +export type V1Selectors = (ctx: TContext, canHandleEvent: (e: TEvent) => boolean, inState: TMatches, __currentState: never) => TSelectors; + +// @public (undocumented) +export type V2BuilderMeta, TActionsOutput = Record, TSlots extends readonly Slot[] = Slot[]> = { + selectors?: Selectors; + actions?: Actions; + slots?: TSlots; + View: View; +}; + +// @public (undocumented) +export type View = React_2.ComponentType<{ + slots: Record, React_2.ComponentType>; + actions: TActionsOutput; + selectors: TSelectorsOutput; +}>; + +// @public (undocumented) +export type ViewProps = { + slots: Record, React_2.ComponentType>; + actions: TActions; + selectors: TSelectors; + inState: TMatches; +}; + +// @public (undocumented) +export type XstateTreeHistory = History_2<{ + meta?: T; + previousUrl?: string; +}>; + +// @public (undocumented) +export type XStateTreeMachineMetaV1 = { + slots: TSlots; + view: React_2.ComponentType, ReturnType, TSlots, MatchesFrom>>; + selectors: TSelectors; + actions: TActions; + xstateTreeMachine?: true; +}; + +// @public (undocumented) +export type XstateTreeMachineStateSchemaV1 = { + meta: XStateTreeMachineMetaV1 & { + builderVersion: 1; + }; +}; + +// @public (undocumented) +export type XstateTreeMachineStateSchemaV2, TActionsOutput = Record, TSlots extends readonly Slot[] = Slot[]> = { + meta: Required & { + builderVersion: 2; + }>; +}; + +// Warnings were encountered during analysis: +// +// src/routing/createRoute/createRoute.ts:279:19 - (ae-forgotten-export) The symbol "MergeRouteTypes" needs to be exported by the entry point index.d.ts +// src/routing/createRoute/createRoute.ts:279:19 - (ae-forgotten-export) The symbol "ResolveZodType" needs to be exported by the entry point index.d.ts +// src/routing/createRoute/createRoute.ts:316:9 - (ae-forgotten-export) The symbol "RouteRedirect" needs to be exported by the entry point index.d.ts +// src/types.ts:25:3 - (ae-incompatible-release-tags) The symbol "view" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal +// src/types.ts:172:3 - (ae-incompatible-release-tags) The symbol "canHandleEvent" is marked as @public, but its signature references "CanHandleEvent" which is marked as @internal +// src/types.ts:173:3 - (ae-incompatible-release-tags) The symbol "inState" is marked as @public, but its signature references "MatchesFrom" which is marked as @internal + +// (No @packageDocumentation comment for this package) + +```