@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
78 lines • 3.37 kB
TypeScript
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { type UniqueIdentifier } from '@dnd-kit/core';
import { type RefObject } from 'react';
import { type FlattenedTreeItem, type TreeItem } from './tree-view-types';
export type SensorContext<T> = RefObject<{
items: FlattenedTreeItem<T>[];
offset: number;
}>;
/**
* Takes a tree and flattens it into a list of item
* where each item has a depth and a parentId.
* @param tree the tree to flatten
* @param depth the depth of the root of the tree (default 0)
* @param parentId the id of the parent of the root of the tree (default null)
* @returns a list of items with depth and parentId
*/
export declare const flattenTree: <T>(tree: TreeItem<T>[], depth?: number, parentId?: UniqueIdentifier | null) => FlattenedTreeItem<T>[];
/**
* Removes the children of the items with the given ids
* @param items the flattened tree items to remove the children from
* @param ids the ids of the items to remove the children from
* @returns a new list of items with the children of the items with the given ids removed
*/
export declare function removeChildrenOf<T>(items: FlattenedTreeItem<T>[], ids: UniqueIdentifier[]): FlattenedTreeItem<T>[];
/**
* Builds a tree from a list of flattened tree items
* @param items the flattened tree items
* @returns the items as a tree data structure
*/
export declare function buildTree<T>(items: FlattenedTreeItem<T>[]): TreeItem<T>[];
/**
* Calculates the new depth, max depth, min depth and parent id of the item being dragged
* Used to project the position of the dragged item. For example, to convert the item being dragged into a placeholder.
* such as the line that appears when dragging an item in a tree view.
* @param items the flattened tree items
* @param activeId the id of the item being dragged
* @param overId the id of the item that the dragged item is being dragged over
* @param dragOffset the offset of the drag in pixels
* @param indentationWidth the width of the indentation in pixels
* @returns the depth, max depth, min depth and parent id of the item being dragged
*/
export declare function getProjection<T>(items: FlattenedTreeItem<T>[], activeId: UniqueIdentifier, overId: UniqueIdentifier, dragOffset: number, indentationWidth: number): {
depth: number;
maxDepth: number;
minDepth: number;
parentId: UniqueIdentifier | null;
};
/**
*
* @param transform a transform object
* @returns a css transform string
*/
export declare const transformToString: (transform: {
scaleX: number;
scaleY: number;
x: number;
y: number;
}) => string;
//# sourceMappingURL=tree-view-utils.d.ts.map