UNPKG

4.37 kBTypeScriptView Raw
1import { EventCallback, INode, INodeRef, NodeId } from "./types";
2export declare const noop: () => void;
3export declare const composeHandlers: (...handlers: EventCallback[]) => EventCallback;
4export declare const difference: (a: Set<NodeId>, b: Set<NodeId>) => Set<NodeId>;
5export declare const symmetricDifference: (a: Set<NodeId>, b: Set<NodeId>) => Set<NodeId>;
6export declare const usePrevious: (x: Set<NodeId>) => Set<NodeId> | undefined;
7export declare const usePreviousData: (value: INode[]) => INode<IFlatMetadata>[] | undefined;
8export declare const isBranchNode: (data: INode[], i: NodeId) => boolean;
9export declare const scrollToRef: (ref: INodeRef) => void;
10export declare const focusRef: (ref: INodeRef) => void;
11export declare const getParent: (data: INode[], id: NodeId) => NodeId | null;
12export declare const getAncestors: (data: INode[], childId: NodeId, disabledIds: Set<NodeId>) => NodeId[];
13export declare const getDescendants: (data: INode[], id: NodeId, disabledIds: Set<NodeId>) => NodeId[];
14export declare const getChildren: (data: INode[], id: NodeId) => NodeId[];
15export declare const getSibling: (data: INode[], id: NodeId, diff: number) => NodeId | null;
16export declare const getLastAccessible: (data: INode[], id: NodeId, expandedIds: Set<NodeId>) => NodeId;
17export declare const getPreviousAccessible: (data: INode[], id: NodeId, expandedIds: Set<NodeId>) => NodeId | null;
18export declare const getNextAccessible: (data: INode[], id: NodeId, expandedIds: Set<NodeId>) => NodeId | null;
19export declare const propagateSelectChange: (data: INode[], ids: Set<NodeId>, selectedIds: Set<NodeId>, disabledIds: Set<NodeId>, halfSelectedIds: Set<NodeId>, multiSelect?: boolean) => {
20 every: Set<NodeId>;
21 some: Set<NodeId>;
22 none: Set<NodeId>;
23};
24export declare const getAccessibleRange: ({ data, expandedIds, from, to, }: {
25 data: INode[];
26 expandedIds: Set<NodeId>;
27 from: NodeId;
28 to: NodeId;
29}) => NodeId[];
30/**
31 * This is to help consumers to understand that we do not currently support metadata that is a nested object. If this is needed, make an issue in Github
32 */
33export type IFlatMetadata = Record<string, string | number | undefined | null>;
34interface ITreeNode<M extends IFlatMetadata> {
35 id?: NodeId;
36 name: string;
37 isBranch?: boolean;
38 children?: ITreeNode<M>[];
39 metadata?: M;
40}
41export declare const flattenTree: <M extends IFlatMetadata>(tree: ITreeNode<M>) => INode<M>[];
42export declare const getAriaSelected: ({ isSelected, isDisabled, multiSelect, }: {
43 isSelected: boolean;
44 isDisabled: boolean;
45 multiSelect: boolean;
46}) => boolean | undefined;
47export declare const getAriaChecked: ({ isSelected, isDisabled, isHalfSelected, multiSelect, }: {
48 isSelected: boolean;
49 isDisabled: boolean;
50 isHalfSelected: boolean;
51 multiSelect: boolean;
52}) => boolean | undefined | "mixed";
53export declare const propagatedIds: (data: INode[], ids: NodeId[], disabledIds: Set<NodeId>) => NodeId[];
54export declare const onComponentBlur: (event: React.FocusEvent, treeNode: HTMLUListElement | null, callback: () => void) => void;
55export declare const isBranchSelectedAndHasSelectedDescendants: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean;
56export declare const isBranchSelectedAndHasAllSelectedEnabledDescendants: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>, disabledIds: Set<NodeId>) => boolean;
57export declare const isBranchNotSelectedAndHasOnlySelectedChild: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean;
58export declare const isBranchSelectedAndHasOnlySelectedChild: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean;
59export declare const getOnSelectTreeAction: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>, disabledIds: Set<NodeId>) => "HALF_SELECT" | "TOGGLE_SELECT";
60export declare const getTreeParent: (data: INode[]) => INode;
61export declare const getTreeNode: (data: INode[], id: NodeId) => INode;
62/**
63 * We need to validate a tree data for
64 * - duplicates
65 * - node references to itself
66 * - node has duplicated children
67 * - no root node in a tree
68 * - more then one root node in a tree
69 * - to have nodes to display
70 * */
71export declare const validateTreeViewData: (data: INode[]) => void;
72export {};