@ones-design/utils
Version:
ONES Design
56 lines (55 loc) • 2.47 kB
TypeScript
/**
* 比较 arr1 是否是 arr2 从 0 开始相同的子集
* @param arr1 较短的数组
* @param arr2 较长的数组
* @returns arr1 是否是 arr2 从 0 开始相同的子集
*/
declare function isSubArrayFromStart(arr1?: Record<string, any>, arr2?: Record<string, any>): boolean;
/**
* 移除指定位置的节点
* @param nodes 节点数组
* @param pos 节点位置
* @param childrenName 存放子节点的字段名
* @returns 移除的节点和更新后的树形数组
*/
declare function removeTreeNode<NodeType extends Record<string, any>>(nodes: NodeType[], pos: number | string | (number | string)[], childrenName?: string): {
node: NodeType | null;
nodes: NodeType[];
};
/**
* 在指定位置插入节点
* @param nodes 节点数组
* @param target 插入的目标位置
* @param node 要插入的节点
* @param pos 相对目标的位置,-1 为上面,0 为里面,1 为下面
* @param childrenName 存放子节点的字段名
* @returns 更新后的数组
*/
declare function insertTreeNode<NodeType extends Record<string, any>>(nodes: NodeType[], target: number | string | (number | string)[], node: NodeType, pos: -1 | 0 | 1, childrenName?: string): NodeType[];
/**
* 获取指定位置的节点
* @param nodes 节点数组
* @param pos 节点位置
* @param childrenName 存放子节点的字段名
* @returns 父节点
*/
declare function getTreeNode<NodeType extends Record<string, any>>(nodes: NodeType[], pos: number | string | (number | string)[], childrenName?: string): NodeType | null;
/**
* 移动树节点的位置
* @param nodes 节点数组
* @param source 原位置
* @param target 目标位置
* @param pos 相对目标的位置,-1 为上面,0 为里面,1 为下面
* @param childrenName 存放子节点的字段名
* @returns 更新后的新数组
*/
declare function moveTreeNode<NodeType extends Record<string, any>>(nodes: NodeType[], source: number | string | (number | string)[], target: number | string | (number | string)[], pos: -1 | 0 | 1, childrenName?: string): NodeType[];
/**
* 移动节点的位置
* @param nodes 节点数组
* @param source 原位置
* @param target 目标位置
* @returns 更新后的新数组
*/
declare function moveNode<NodeType extends Record<string, any>>(nodes: NodeType[], source: number | string, target: number | string): NodeType[];
export { isSubArrayFromStart, removeTreeNode, insertTreeNode, getTreeNode, moveTreeNode, moveNode };