@factorialco/f0-react 2.55.3 → 2.57.0

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/dist/f0.d.ts CHANGED
@@ -1416,6 +1416,14 @@ export declare type BaseDataAdapter<R extends RecordType, Filters extends Filter
1416
1416
  * side-effects on reactive adapters (e.g. Apollo watchQuery).
1417
1417
  */
1418
1418
  exportFetchData?: (options: Options) => FetchReturn | Promise<FetchReturn>;
1419
+ /**
1420
+ * Optional id-relative capability: fetch the immediate neighbours of an
1421
+ * item under the current filters/sortings/search, without loading pages.
1422
+ * Enables detail-page prev/next on direct links / hard refresh, where the
1423
+ * item may not be in any loaded page window. One-shot semantics: when an
1424
+ * Observable is returned, only the first settled emission is consumed.
1425
+ */
1426
+ fetchItemNeighbors?: (options: ItemNeighborsFetchOptions<Filters, Options>) => ItemNeighborsResponse<R> | Promise<ItemNeighborsResponse<R>> | Observable<PromiseState<ItemNeighborsResponse<R>>>;
1419
1427
  };
1420
1428
 
1421
1429
  /**
@@ -3958,6 +3966,8 @@ export declare type DataSourceDefinition<R extends RecordType = RecordType, Filt
3958
3966
  }) => number | undefined;
3959
3967
  };
3960
3968
 
3969
+ export declare type DataSourceItemId = string | number | symbol;
3970
+
3961
3971
  /**
3962
3972
  * Wrapper component that conditionally renders a `data-testid` attribute.
3963
3973
  *
@@ -11732,6 +11742,44 @@ declare type ItemDefinition = {
11732
11742
  avatar?: AvatarVariant;
11733
11743
  };
11734
11744
 
11745
+ /**
11746
+ * Options for an id-relative neighbours fetch. Derived from the adapter's own
11747
+ * fetch options, so extended adapters (e.g. OneDataCollection's, which add
11748
+ * `navigationFilters`) carry their extra context automatically. Pagination is
11749
+ * stripped: the request is relative to an item id, not to a page.
11750
+ */
11751
+ export declare type ItemNeighborsFetchOptions<Filters extends FiltersDefinition, Options extends BaseFetchOptions<Filters> = BaseFetchOptions<Filters>> = Omit<Options, "pagination"> & {
11752
+ /** Id of the reference item (as produced by the source's idProvider) */
11753
+ id: ItemNeighborsId;
11754
+ };
11755
+
11756
+ /**
11757
+ * Identifier used to reference an item in id-relative fetches.
11758
+ * Symbols are excluded on purpose: the id must be serializable so it can
11759
+ * cross a network boundary to a backend.
11760
+ */
11761
+ export declare type ItemNeighborsId = string | number;
11762
+
11763
+ /**
11764
+ * Result of an id-relative neighbours fetch.
11765
+ *
11766
+ * `previous`/`next` are the immediate neighbours of the reference item under
11767
+ * the given filters/sortings/search, or null at the collection edges. If the
11768
+ * reference item itself does not match the current filters, return
11769
+ * `{ previous: null, next: null }` (optionally with `total`) — consumers
11770
+ * disable navigation in that case.
11771
+ */
11772
+ export declare type ItemNeighborsResponse<R> = {
11773
+ previous: R | null;
11774
+ next: R | null;
11775
+ /** 1-indexed position of the reference item in the filtered+sorted collection */
11776
+ position?: number;
11777
+ /** Total number of records matching the current filters/search */
11778
+ total?: number;
11779
+ };
11780
+
11781
+ export declare type ItemNeighborsResult<R> = ItemNeighborsResponse<R> | Promise<ItemNeighborsResponse<R>> | Observable<PromiseState<ItemNeighborsResponse<R>>>;
11782
+
11735
11783
  /**
11736
11784
  * Profile data for a job posting entity (ATS opening), resolved asynchronously
11737
11785
  * and displayed in the entity reference hover card.
@@ -12330,6 +12378,20 @@ declare type NavigationProps = {
12330
12378
 
12331
12379
  declare type NavTarget = HTMLAttributeAnchorTarget;
12332
12380
 
12381
+ export declare type NeighborResolution<R extends RecordType> = {
12382
+ /** Index of the active item within the loaded records, or -1 when not found */
12383
+ activeIndex: number;
12384
+ activeItem: R | null;
12385
+ previousItem: R | null;
12386
+ nextItem: R | null;
12387
+ /**
12388
+ * How the neighbours were resolved. "window" means they were located in the
12389
+ * loaded records. Reserved extension point for id-relative adapter
12390
+ * resolution (e.g. a `fetchItemNeighbors` capability).
12391
+ */
12392
+ resolvedBy: "window";
12393
+ };
12394
+
12333
12395
  /**
12334
12396
  * Utility type to extract all possible paths from nested object.
12335
12397
  * Generates hyphenated paths from nested object structure
@@ -12980,6 +13042,14 @@ export declare type PaginatedDataAdapter<R extends RecordType, Filters extends F
12980
13042
  * side-effects on reactive adapters (e.g. Apollo watchQuery).
12981
13043
  */
12982
13044
  exportFetchData?: (options: Options) => FetchReturn | Promise<FetchReturn>;
13045
+ /**
13046
+ * Optional id-relative capability: fetch the immediate neighbours of an
13047
+ * item under the current filters/sortings/search, without loading pages.
13048
+ * Enables detail-page prev/next on direct links / hard refresh, where the
13049
+ * item may not be in any loaded page window. One-shot semantics: when an
13050
+ * Observable is returned, only the first settled emission is consumed.
13051
+ */
13052
+ fetchItemNeighbors?: (options: ItemNeighborsFetchOptions<Filters, Options>) => ItemNeighborsResponse<R> | Promise<ItemNeighborsResponse<R>> | Observable<PromiseState<ItemNeighborsResponse<R>>>;
12983
13053
  };
12984
13054
 
12985
13055
  export declare type PaginatedFetchOptions<Filters extends FiltersDefinition> = BaseFetchOptions<Filters> & {
@@ -13785,6 +13855,34 @@ export declare interface ResolvedStepAnswer {
13785
13855
  cancelled?: boolean;
13786
13856
  }
13787
13857
 
13858
+ /**
13859
+ * Normalizes the three `fetchItemNeighbors` return channels (sync value,
13860
+ * Promise, Observable of PromiseState) into a single one-shot Promise.
13861
+ *
13862
+ * Observables are consumed one-shot: the first emission carrying `data`
13863
+ * resolves, the first emission carrying `error` rejects, and the
13864
+ * subscription is closed either way — live updates are intentionally out of
13865
+ * scope for neighbour resolution.
13866
+ *
13867
+ * `cancel()` unsubscribes/abandons the request: the returned promise then
13868
+ * never settles, so a cancelled request can never reach consumer state.
13869
+ */
13870
+ export declare function resolveItemNeighbors<R>(result: ItemNeighborsResult<R>): {
13871
+ promise: Promise<ItemNeighborsResponse<R>>;
13872
+ cancel: () => void;
13873
+ };
13874
+
13875
+ /**
13876
+ * Locates the active item and its immediate neighbours within the currently
13877
+ * loaded records ("the window"). Pure — the single place neighbour resolution
13878
+ * happens, so alternative resolution strategies can be merged at this point.
13879
+ */
13880
+ export declare function resolveWindowNeighbors<R extends RecordType>({ records, activeItemId, idProvider, }: {
13881
+ records: readonly R[];
13882
+ activeItemId: DataSourceItemId | null;
13883
+ idProvider: (item: R, index?: number) => DataSourceItemId;
13884
+ }): NeighborResolution<R>;
13885
+
13788
13886
  declare type ResourceHeaderProps = Props_4;
13789
13887
 
13790
13888
  /** All styling props that can be overridden per breakpoint */
@@ -15361,13 +15459,21 @@ declare type UseChatHistoryReturn = {
15361
15459
  * - paginationInfo: Pagination state and metadata if available
15362
15460
  * - setPage: Function to navigate to a specific page
15363
15461
  */
15364
- export declare function useData<R extends RecordType = RecordType, Filters extends FiltersDefinition = FiltersDefinition, Sortings extends SortingsDefinition = SortingsDefinition, Grouping extends GroupingDefinition<R> = GroupingDefinition<R>>(source: DataSource<R, Filters, Sortings, Grouping>, { filters, onError, fetchParamsProvider, onResponse, }?: UseDataOptions<R, Filters>, deps?: unknown[]): UseDataReturn<R>;
15462
+ export declare function useData<R extends RecordType = RecordType, Filters extends FiltersDefinition = FiltersDefinition, Sortings extends SortingsDefinition = SortingsDefinition, Grouping extends GroupingDefinition<R> = GroupingDefinition<R>>(source: DataSource<R, Filters, Sortings, Grouping>, { filters, enabled, onError, fetchParamsProvider, onResponse, }?: UseDataOptions<R, Filters>, deps?: unknown[]): UseDataReturn<R>;
15365
15463
 
15366
15464
  /**
15367
15465
  * Hook options for useData
15368
15466
  */
15369
15467
  export declare interface UseDataOptions<R extends RecordType, Filters extends FiltersDefinition> {
15370
15468
  filters?: Partial<FiltersState<Filters>>;
15469
+ /**
15470
+ * When false, suspends all data fetching: the initial fetch effect does not
15471
+ * run until `enabled` becomes true. Useful to delay the first fetch until
15472
+ * async state (e.g. persisted filters) has been applied to the source.
15473
+ * `isInitialLoading` stays true while disabled.
15474
+ * @default true
15475
+ */
15476
+ enabled?: boolean;
15371
15477
  /**
15372
15478
  * A function that is called when an error occurs during data fetching.
15373
15479
  * It is called with the error object.
@@ -15443,6 +15549,72 @@ export declare interface UseDataReturn<R extends RecordType> {
15443
15549
  */
15444
15550
  export declare function useDataSource<R extends RecordType = RecordType, FiltersSchema extends FiltersDefinition = FiltersDefinition, Sortings extends SortingsDefinition = SortingsDefinition, Grouping extends GroupingDefinition<R> = GroupingDefinition<R>>({ defaultFilters, currentFilters: externalCurrentFilters, defaultGrouping: externalDefaultGrouping, currentGrouping: externalCurrentGrouping, filters, search, defaultSortings, currentSortings: externalCurrentSortings, dataAdapter, grouping, ...rest }: DataSourceDefinition<R, FiltersSchema, Sortings, Grouping>, deps?: ReadonlyArray<unknown>): DataSource<R, FiltersSchema, Sortings, Grouping>;
15445
15551
 
15552
+ export declare function useDataSourceItemNavigation<R extends RecordType>(props: UseDataSourceItemNavigationProps<R>): UseDataSourceItemNavigationReturn<R>;
15553
+
15554
+ export declare interface UseDataSourceItemNavigationProps<R extends RecordType> {
15555
+ /** The data source returned by `useDataSource`. Used to extract `idProvider` */
15556
+ dataSource: {
15557
+ idProvider?: <Item extends R>(item: Item, index?: number) => DataSourceItemId;
15558
+ };
15559
+ /** The data returned by `useData` */
15560
+ data: Data<R>;
15561
+ /** Pagination info returned by `useData` */
15562
+ paginationInfo: PaginationInfo | null;
15563
+ /** Navigate to a specific page (from `useData`) */
15564
+ setPage: UseDataReturn<R>["setPage"];
15565
+ /** Load more items for infinite-scroll (from `useData`) */
15566
+ loadMore: UseDataReturn<R>["loadMore"];
15567
+ /** Whether `useData` is currently loading data */
15568
+ isLoading: boolean;
15569
+ /** Overrides `dataSource.idProvider`. Extracts a unique ID from a record. Falls back to `item.id` */
15570
+ idProvider?: (item: R, index?: number) => DataSourceItemId;
15571
+ /** Returns the URL for a given item. Used to derive `nextItemUrl` / `previousItemUrl` */
15572
+ itemUrl?: (item: R) => string | undefined;
15573
+ /** Controlled active item ID */
15574
+ activeItemId?: DataSourceItemId | null;
15575
+ /** Default active item ID (uncontrolled) */
15576
+ defaultActiveItemId?: DataSourceItemId | null;
15577
+ /** Callback when active item changes */
15578
+ onActiveItemChange?: (id: DataSourceItemId | null) => void;
15579
+ }
15580
+
15581
+ export declare interface UseDataSourceItemNavigationReturn<R extends RecordType> {
15582
+ /** The currently active item ID */
15583
+ activeItemId: DataSourceItemId | null;
15584
+ /** The currently active item record, or null if not found in loaded data */
15585
+ activeItem: R | null;
15586
+ /** The active item index within the currently loaded records */
15587
+ activeIndex: number;
15588
+ /** The active item index within the full collection when it can be inferred */
15589
+ absoluteIndex: number | null;
15590
+ /** Number of records currently loaded into the datasource */
15591
+ loadedItemsCount: number;
15592
+ /** Total number of matching records when pagination exposes it */
15593
+ totalItems: number | undefined;
15594
+ /** The previous loaded item record, or null if unavailable */
15595
+ previousItem: R | null;
15596
+ /** The next loaded item record, or null if unavailable */
15597
+ nextItem: R | null;
15598
+ /** URL of the active item (derived via `itemUrl`), or null if unavailable */
15599
+ activeItemUrl: string | null;
15600
+ /** Navigate to the next item. Fetches next page if at boundary */
15601
+ goToNext: () => void;
15602
+ /** Navigate to the previous item. Fetches previous page if at boundary */
15603
+ goToPrevious: () => void;
15604
+ /** Whether there is a next item (or more pages to load) */
15605
+ hasNext: boolean;
15606
+ /** Whether there is a previous item (or previous pages to load) */
15607
+ hasPrevious: boolean;
15608
+ /** Directly set the active item ID */
15609
+ setActiveItemId: (id: DataSourceItemId | null) => void;
15610
+ /** True while waiting for a page transition to resolve the pending navigation */
15611
+ isNavigating: boolean;
15612
+ /** URL of the next loaded item (derived via `itemUrl`), or null if unavailable */
15613
+ nextItemUrl: string | null;
15614
+ /** URL of the previous loaded item (derived via `itemUrl`), or null if unavailable */
15615
+ previousItemUrl: string | null;
15616
+ }
15617
+
15446
15618
  export declare function useDndEvents(handler: (e: {
15447
15619
  phase: "start" | "over" | "drop" | "cancel";
15448
15620
  source: DragPayload;
@@ -15693,6 +15865,56 @@ export declare const useGroups: <R extends RecordType>(groups: GroupRecord<R>[],
15693
15865
  setGroupOpen: (key: string, open: boolean) => void;
15694
15866
  };
15695
15867
 
15868
+ /**
15869
+ * Resolves the previous/next neighbours of an item through the adapter's
15870
+ * optional id-relative `fetchItemNeighbors` capability.
15871
+ *
15872
+ * Built for detail-page navigation on direct links: when the active item is
15873
+ * not in any loaded page window, this asks the backend for its immediate
15874
+ * neighbours (plus position/total for the counter) under the current
15875
+ * filters/sortings/search instead of walking pages.
15876
+ *
15877
+ * Semantics:
15878
+ * - `neighbors` only ever reflects the current `{id, filters, sortings,
15879
+ * search}` — stale responses from superseded requests are dropped.
15880
+ * - Responses are cached per request key, so navigating back and forth
15881
+ * between already-visited ids is instant. The cache is cleared whenever
15882
+ * filters/sortings/search change; errors are never cached.
15883
+ * - When the capability is absent (`isSupported: false`), disabled, or the
15884
+ * id is null, nothing is fetched and `neighbors` stays null — consumers
15885
+ * keep their fallback behaviour.
15886
+ */
15887
+ export declare function useItemNeighbors<R extends RecordType, Filters extends FiltersDefinition>({ dataAdapter, id, filters, sortings, search, enabled, onError, }: UseItemNeighborsOptions<R, Filters>): UseItemNeighborsReturn<R>;
15888
+
15889
+ export declare interface UseItemNeighborsOptions<R extends RecordType, Filters extends FiltersDefinition> {
15890
+ /** The adapter that may implement the `fetchItemNeighbors` capability */
15891
+ dataAdapter: DataAdapter<R, Filters>;
15892
+ /** Active item id. Null disables resolution (symbol ids cannot be used) */
15893
+ id: ItemNeighborsId | null;
15894
+ /** Current filters — same values `fetchData` receives */
15895
+ filters: FiltersState<Filters>;
15896
+ /** Current sortings — same composed array `fetchData` receives */
15897
+ sortings: SortingsStateMultiple;
15898
+ /** Current search — same value `fetchData` receives */
15899
+ search?: string;
15900
+ /**
15901
+ * Gate: resolve only while true (e.g. only when the snapshot path failed
15902
+ * to locate the item in the loaded window).
15903
+ * @default true
15904
+ */
15905
+ enabled?: boolean;
15906
+ onError?: (error: DataError) => void;
15907
+ }
15908
+
15909
+ export declare interface UseItemNeighborsReturn<R extends RecordType> {
15910
+ /** True when the adapter implements `fetchItemNeighbors` */
15911
+ isSupported: boolean;
15912
+ /** Resolved neighbours for the CURRENT id+context, or null while unresolved */
15913
+ neighbors: ItemNeighborsResponse<R> | null;
15914
+ isResolving: boolean;
15915
+ error: DataError | null;
15916
+ }
15917
+
15696
15918
  export declare const usePrivacyMode: () => {
15697
15919
  enabled: boolean;
15698
15920
  enable: () => void;