From d236b2ac1513a38674690547ec81a3bf3c9a2867 Mon Sep 17 00:00:00 2001 From: Thomas Winter Date: Thu, 17 Aug 2023 09:18:52 +1200 Subject: [PATCH] feat(routing): forwards refs for Link component Moving preventDefault down to just before the navigation event In the onClick event Radix is checking whether the default event was prevented and bails out of doing its things. Since this should just be for preventing the browser from following the link's url, it should be fine to run it just before the navigate call. --- src/routing/Link.tsx | 50 ++- xstate-tree.api.md | 933 ++++++++++++++++++++++--------------------- 2 files changed, 501 insertions(+), 482 deletions(-) diff --git a/src/routing/Link.tsx b/src/routing/Link.tsx index 5ee8621..82f47e8 100644 --- a/src/routing/Link.tsx +++ b/src/routing/Link.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { forwardRef } from "react"; import { AnyRoute, Route, RouteArguments } from "./createRoute"; import { useHref } from "./useHref"; @@ -38,25 +38,20 @@ export type LinkProps< } & RouteArguments & Omit, "href" | "onClick">; -/** - * @public - * - * Renders an anchor tag pointing at the provided Route - * - * The query/params/meta props are conditionally required based on the - * route passed as the To parameter - */ -export function Link({ - to, - children, - testId, - preloadOnHoverMs, - preloadOnInteraction, - onMouseDown: _onMouseDown, - onMouseEnter: _onMouseEnter, - onMouseLeave: _onMouseLeave, - ...rest -}: LinkProps) { +function LinkInner( + { + to, + children, + testId, + preloadOnHoverMs, + preloadOnInteraction, + onMouseDown: _onMouseDown, + onMouseEnter: _onMouseEnter, + onMouseLeave: _onMouseLeave, + ...rest + }: LinkProps, + ref: React.ForwardedRef +) { // @ts-ignore, these fields _might_ exist, so typechecking doesn't believe they exist // and everything that consumes params/query already checks for undefined const { params, query, meta, ...props } = rest; @@ -95,13 +90,13 @@ export function Link({ return ( { - e.preventDefault(); if (props.onClick?.(e) === false) { return; } @@ -112,6 +107,7 @@ export function Link({ return; } + e.preventDefault(); to.navigate({ params, query, meta }); }} > @@ -119,3 +115,15 @@ export function Link({ ); } + +/** + * @public + * + * Renders an anchor tag pointing at the provided Route + * + * The query/params/meta props are conditionally required based on the + * route passed as the To parameter + */ +export const Link = forwardRef(LinkInner) as ( + props: LinkProps & { ref?: React.ForwardedRef } +) => ReturnType; diff --git a/xstate-tree.api.md b/xstate-tree.api.md index ded9e6c..72092e0 100644 --- a/xstate-tree.api.md +++ b/xstate-tree.api.md @@ -1,461 +1,472 @@ -## 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; - -// @public -export function Link({ to, children, testId, preloadOnHoverMs, preloadOnInteraction, onMouseDown: _onMouseDown, onMouseEnter: _onMouseEnter, onMouseLeave: _onMouseLeave, ...rest }: LinkProps): JSX.Element; - -// @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; +}) => 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) + +```