@payfit/unity-components
Version:
43 lines (42 loc) • 2.43 kB
TypeScript
import { Key } from 'react-aria-components/Breadcrumbs';
import { ProcessedDynamicContent, ProcessedFlatDynamicContent, SectionWithChildren, SelectableItem } from './SelectList.types.js';
/**
* Type guard to check if an object has a children array property,
* indicating it's a section containing selectable items.
* @param obj - Object to check
* @returns True if object is a section with children array
*/
export declare function hasSectionChildren<TChild extends SelectableItem>(obj: unknown): obj is SectionWithChildren<TChild>;
/**
* Type guard to check if items array contains nested sections or flat items
* by inspecting the first item in the iterable.
* Uses iterator directly to avoid converting entire iterable to array.
*/
export declare function isNestedStructure<TChild extends SelectableItem>(items: Iterable<unknown>): items is Iterable<SectionWithChildren<TChild>>;
/**
* Processes a flat array of items, partitioning them into selected
* and unselected groups based on the provided selected keys.
* @param items - Flat iterable of items to process
* @param selectedKeys - Set of currently selected item keys
* @returns Object with selectedItems and remainingItems arrays
*/
export declare function processSelectedItemsForFlatDynamicItems<TItem extends SelectableItem>(items: Iterable<TItem>, selectedKeys: Set<Key>): ProcessedFlatDynamicContent<TItem>;
/**
* Extracts all selectable child items from a nested section structure,
* flattening the hierarchy into a single array.
* @param items - Iterable of sections containing child items
* @returns Object with flat array of all child items
*/
export declare function extractAllSelectableItems<TSection extends SectionWithChildren<TChild>, TChild extends SelectableItem>(items: Iterable<TSection>): {
allItems: TChild[];
};
/**
* Processes a nested structure (sections with children), extracting selected
* items and creating modified sections with selected items removed.
* @param items - Iterable of sections containing child items
* @param selectedKeys - Set of currently selected item keys
* @returns Object with selectedItems array and modified sections array
*/
export declare function processSelectedItemsForNestedDynamicItems<TSection extends SectionWithChildren<TChild>, TChild extends SelectableItem & {
label: string;
}>(items: Iterable<TSection>, selectedKeys: Set<Key>): ProcessedDynamicContent<TChild | TSection>;