import { DragAndDropEvent } from './events'; import { TreeModel } from './tree-model'; import { TreeNode } from './tree-node'; /** * common functions to handle tree actions */ export interface ActionHandler { (tree: TreeModel, node: TreeNode, $event: T, ...args: any[]): void; } /** * a mapping model to link mouse events and keyboard events with actions */ export interface ActionMapping { mouse?: { click?: ActionHandler; dblClick?: ActionHandler; contextMenu?: ActionHandler; expanderClick?: ActionHandler; dragStart?: ActionHandler; drag?: ActionHandler; dragEnd?: ActionHandler; dragOver?: ActionHandler; dragLeave?: ActionHandler; dragEnter?: ActionHandler; drop?: ActionHandler; }; keys?: { [key: number]: ActionHandler; }; } export declare type PropType = TObj[TProp]; export declare type AvailableMouseEvents = keyof Exclude, undefined>; export interface DropTarget { parent: TreeNode; index: number; } export declare type IAllowDropFn = (element: TreeNode, to: DropTarget, $event?: DragEvent) => boolean; export declare type IAllowDragFn = (node: TreeNode) => boolean; export declare type ILevelPaddingFn = (node: TreeNode) => string; export declare const defaultUIOptions: TreeUIOptions; export declare const defaultDataOptions: TreeDataOptions; export interface TreeUIOptions { /** * Specify if dragging tree nodes is allowed. * This could be a boolean, or a function that receives a TreeNode and returns a boolean * * **Default value: false** * * Example: * ``` * options = { * allowDrag: true * } * ``` */ allowDrag?: boolean | IAllowDragFn; /** * Specify whether dropping inside the tree is allowed. Optional types: * - boolean * - (element:any, to:{parent:ITreeNode, index:number}):boolean * A function that receives the dragged element, and the drop location (parent node and index inside the parent), * and returns true or false. * * **Default Value: true** * * example: * ``` * options = { * allowDrop: (element, {parent, index}) => parent.isLeaf * } * ``` */ allowDrop?: boolean | IAllowDropFn; /** * Specify padding per node instead of children padding (to allow full row select for example) */ levelPadding?: ILevelPaddingFn; /** * Boolean whether virtual scroll should be used. * Increases performance for large trees * Default is false */ useVirtualScroll?: boolean; /** * the item height in tree the virtual scrolling algorithm will refer to, not determinate * if user provide a proper value, it would boost the initial rendering time for tree with big dataset initially */ referenceItemHeight?: number; /** * an optional field to prevent repeating viewport update, * which is caused by some massive tree structure changes, such as `collapseAll()`, `expandAll()` * setting this field with a number would be useful for large scale tree, like throttle tailing. * * however, it would also caused the tree to be irreponsible for a short while */ auditViewportUpdate?: number; /** * Supply function for getting a custom class for the node component */ nodeClass?(node: TreeNode): string; } export interface RawTreeUIOptions { allowDrag?: boolean | IAllowDragFn; allowDrop?: boolean | IAllowDropFn; levelPadding?: number | ILevelPaddingFn; useVirtualScroll?: boolean; referenceItemHeight?: number; auditViewportUpdate?: number; nodeClass?(node: TreeNode): string; } /** * create tree options about UI with defaults * @param rawOpts */ export declare function createTreeUIOptions(rawOpts?: RawTreeUIOptions): TreeUIOptions; export declare type CustomFieldPrefix = 'id' | 'children' | 'display' | 'isExpanded'; export declare type CustomFieldNames = 'idField' | 'childrenField' | 'displayField' | 'isExpandedField'; export interface TreeDataOptions { /** * Override children field. Default: 'children' */ childrenField?: string; /** * Override display field. Default: 'name' */ displayField?: string; /** * Override id field. Default: 'id' */ idField?: string; /** * Override isExpanded field. Default: 'isExpanded' */ isExpandedField?: string; /** * Change the default mouse and key actions on the tree */ actionMapping?: ActionMapping; /** * Supply function for getting fields asynchronously. Should return a Promise */ getChildren?(node: TreeNode): Promise; } /** * create tree options about data with defaults * @param rawOpts */ export declare function createTreeDataOptions(rawOpts?: TreeDataOptions): TreeDataOptions;