import { Service, EventObject, Machine } from '@zag-js/core'; type SortDirection = "ascending" | "descending"; interface SortDescriptor { column: keyof T; direction: SortDirection; } interface LoadDetails { signal: AbortSignal | undefined; filterText: string; cursor?: C | undefined; sortDescriptor?: SortDescriptor | undefined; } interface LoadResult { items: T[]; cursor?: C | undefined; } interface SortDetails { items: T[]; descriptor: SortDescriptor; filterText: string; } type LoadDependency = string | number | boolean | undefined | null; interface AsyncListProps { /** * The function to call when the list is loaded */ load: (args: LoadDetails) => Promise>; /** * The function to call when the list is sorted */ sort?: ((args: SortDetails) => Promise<{ items: T[]; }> | { items: T[]; } | undefined) | undefined; /** * The initial items to display */ initialItems?: T[] | undefined; /** * The initial sort descriptor to use */ initialSortDescriptor?: SortDescriptor | undefined; /** * The initial filter text to use */ initialFilterText?: string | undefined; /** * The dependencies to watch for changes */ dependencies?: LoadDependency[] | undefined; /** * Whether to automatically reload the list when the dependencies change */ autoReload?: boolean | undefined; /** * The function to call when the list is loaded successfully */ onSuccess?: ((details: { items: T[]; }) => void | undefined) | undefined; /** * The function to call when the list fails to load */ onError?: ((details: { error: Error; }) => void | undefined) | undefined; } interface AsyncListSchema { state: "idle" | "loading" | "sorting"; props: AsyncListProps; context: { items: T[]; filterText: string; cursor?: C | undefined; sortDescriptor?: SortDescriptor | undefined; error?: any | undefined; }; refs: { abort: AbortController | null; seq: number; }; event: EventObject; action: string; guard: string; effect: string; } type AsyncListService = Service>; type AsyncListMachine = Machine>; interface AsyncListApi { /** * The items in the list. */ items: T[]; /** * The filter text. */ filterText: string; /** * The cursor. */ cursor: C | undefined; /** * The sort descriptor. */ sortDescriptor: SortDescriptor | undefined; /** * Whether the list is loading. */ loading: boolean; /** * Whether the list is sorting. */ sorting: boolean; /** * Whether the list is empty. */ empty: boolean; /** * Whether there are more items to load. */ hasMore: boolean; /** * The error instance returned by the last fetch. */ error: any | undefined; /** * Function to abort the current fetch. */ abort: VoidFunction; /** * Function to reload the list */ reload: VoidFunction; /** * Function to load more items */ loadMore: VoidFunction; /** * Function to sort the list */ sort: (sortDescriptor: SortDescriptor) => void; /** * Function to set the filter text */ setFilterText: (filterText: string) => void; /** * Function to clear the filter text */ clearFilter: VoidFunction; } export type { AsyncListApi, AsyncListMachine, AsyncListProps, AsyncListSchema, AsyncListService, LoadDependency, LoadDetails, LoadResult, SortDescriptor, SortDetails, SortDirection };