@clevertask/react-sortable-tree 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +303 -83
  2. package/dist/e2e/index.js +51 -0
  3. package/dist/e2e/utils/drag-item.d.ts +15 -0
  4. package/dist/e2e/utils/expect-item-before.d.ts +2 -0
  5. package/dist/e2e/utils/expect-item-child-of.d.ts +3 -0
  6. package/dist/e2e/utils/get-tree-item-id.d.ts +2 -0
  7. package/dist/e2e/utils/index.d.ts +4 -0
  8. package/dist/{style.css → react-sortable-tree.css} +1 -1
  9. package/dist/react-sortable-tree.js +2404 -1381
  10. package/dist/react-sortable-tree.js.map +1 -1
  11. package/dist/src/SortableTree/SortableTree.d.ts +2 -0
  12. package/dist/src/SortableTree/components/TreeItem/TreeItem.d.ts +33 -0
  13. package/dist/{SortableTree → src/SortableTree}/components/TreeItem/index.d.ts +1 -0
  14. package/dist/src/SortableTree/components/TreeItemStructure/index.d.ts +39 -0
  15. package/dist/src/SortableTree/components/index.d.ts +4 -0
  16. package/dist/src/SortableTree/createSortableTreeGlobalStyles.d.ts +8 -0
  17. package/dist/src/SortableTree/index.d.ts +6 -0
  18. package/dist/{SortableTree → src/SortableTree}/types.d.ts +9 -11
  19. package/dist/{SortableTree → src/SortableTree}/utilities.d.ts +4 -4
  20. package/package.json +53 -29
  21. package/dist/SortableTree/SortableTree.d.ts +0 -4
  22. package/dist/SortableTree/components/TreeItem/TreeItem.d.ts +0 -23
  23. package/dist/SortableTree/components/index.d.ts +0 -1
  24. package/dist/SortableTree/index.d.ts +0 -3
  25. /package/dist/{SortableTree → src/SortableTree}/components/Action/Action.d.ts +0 -0
  26. /package/dist/{SortableTree → src/SortableTree}/components/Action/index.d.ts +0 -0
  27. /package/dist/{SortableTree → src/SortableTree}/components/Add/Add.d.ts +0 -0
  28. /package/dist/{SortableTree → src/SortableTree}/components/Add/index.d.ts +0 -0
  29. /package/dist/{SortableTree → src/SortableTree}/components/Handle/Handle.d.ts +0 -0
  30. /package/dist/{SortableTree → src/SortableTree}/components/Handle/index.d.ts +0 -0
  31. /package/dist/{SortableTree → src/SortableTree}/components/Remove/Remove.d.ts +0 -0
  32. /package/dist/{SortableTree → src/SortableTree}/components/Remove/index.d.ts +0 -0
  33. /package/dist/{SortableTree → src/SortableTree}/components/TreeItem/SortableTreeItem.d.ts +0 -0
  34. /package/dist/{SortableTree → src/SortableTree}/keyboardCoordinates.d.ts +0 -0
  35. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  36. /package/dist/{main.d.ts → src/main.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ import { SortableTreeProps, TreeItem } from './types';
2
+ export declare const SortableTree: <T extends TreeItem = TreeItem>(props: SortableTreeProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { default as React, HTMLAttributes } from 'react';
2
+ import { TreeItemStructureProps } from '../TreeItemStructure';
3
+ import { TreeItem as TTreeItem } from '../../types';
4
+ export interface RenderItemProps<T extends TTreeItem = TTreeItem> extends Pick<TreeItemStructureProps, 'classNames' | 'dropZoneStyle' | 'dropZoneRef' | 'draggableItemRef'>, Pick<Props, 'onCollapse' | 'childCount' | 'clone' | 'ghost' | 'indicator' | 'disableSelection' | 'disableInteraction' | 'collapsed'> {
5
+ dragListeners?: any;
6
+ treeItem: T;
7
+ dataSlots: {
8
+ dropZone: Record<string, string | boolean | undefined>;
9
+ draggableItem: Record<string, string>;
10
+ };
11
+ }
12
+ export interface Props<T extends TTreeItem = TTreeItem> extends Omit<HTMLAttributes<HTMLLIElement>, 'id'> {
13
+ childCount?: number;
14
+ clone?: boolean;
15
+ collapsed?: boolean;
16
+ depth: number;
17
+ disableInteraction?: boolean;
18
+ disableSelection?: boolean;
19
+ disableDragging?: boolean;
20
+ ghost?: boolean;
21
+ handleProps?: any;
22
+ indicator?: boolean;
23
+ indentationWidth: number;
24
+ value: T;
25
+ onCollapse?(): void;
26
+ onRemove?(): void;
27
+ onAdd?(): void;
28
+ onLabelClick?(): void;
29
+ wrapperRef: RenderItemProps<T>['dropZoneRef'];
30
+ renderItem?: (props: RenderItemProps<T>) => React.ReactNode;
31
+ }
32
+ export declare const _TreeItem: React.ForwardRefExoticComponent<Props<import('../..').BaseTreeItem<unknown>> & React.RefAttributes<HTMLDivElement>>;
33
+ export declare const TreeItem: React.NamedExoticComponent<Props<import('../..').BaseTreeItem<unknown>> & React.RefAttributes<HTMLDivElement>>;
@@ -1,2 +1,3 @@
1
1
  export { TreeItem } from './TreeItem';
2
2
  export { SortableTreeItem } from './SortableTreeItem';
3
+ export type { RenderItemProps } from './TreeItem';
@@ -0,0 +1,39 @@
1
+ import { TreeItem } from '../../types';
2
+ import { RenderItemProps } from '../TreeItem/TreeItem';
3
+ import { default as React } from 'react';
4
+ type AriaProps = {
5
+ 'aria-label'?: string;
6
+ 'aria-labelledby'?: string;
7
+ 'aria-describedby'?: string;
8
+ };
9
+ export type TreeItemStructureProps = {
10
+ treeItem: TreeItem & {
11
+ parentId?: string;
12
+ };
13
+ dropZoneRef: (element: HTMLElement | null) => void;
14
+ draggableItemRef: React.Ref<any>;
15
+ dropZoneStyle?: React.CSSProperties;
16
+ draggableItemStyle?: React.CSSProperties;
17
+ classNames?: {
18
+ dropZone?: string;
19
+ draggableItem?: string;
20
+ };
21
+ asDropZone?: React.ElementType;
22
+ asDraggableItem?: React.ElementType;
23
+ children?: React.ReactNode;
24
+ clone?: boolean;
25
+ dataSlots: {
26
+ dropZone?: AriaProps & Record<string, string | boolean | number | undefined>;
27
+ draggableItem?: AriaProps & Record<string, string>;
28
+ };
29
+ } & Pick<RenderItemProps, 'dragListeners'>;
30
+ export declare const TreeItemStructure: {
31
+ ({ dropZoneRef, draggableItemRef, dropZoneStyle, draggableItemStyle, classNames, asDropZone: DropZoneComponent, asDraggableItem: DraggableComponent, children, dataSlots, treeItem, clone, dragListeners, }: TreeItemStructureProps): import("react/jsx-runtime").JSX.Element;
32
+ DragHandler({ children, as: Component, className, style, }: {
33
+ children: React.ReactNode;
34
+ as?: React.ElementType;
35
+ className?: string;
36
+ style?: React.CSSProperties;
37
+ }): import("react/jsx-runtime").JSX.Element | null;
38
+ };
39
+ export {};
@@ -0,0 +1,4 @@
1
+ export { TreeItem, SortableTreeItem } from './TreeItem';
2
+ export type { RenderItemProps } from './TreeItem';
3
+ export { TreeItemStructure } from './TreeItemStructure';
4
+ export type { TreeItemStructureProps } from './TreeItemStructure';
@@ -0,0 +1,8 @@
1
+ type SortableTreeStyleOptions = {
2
+ indicatorColor?: string;
3
+ indicatorBorderColor?: string;
4
+ indicatorDotColor?: string;
5
+ dragBoxShadow?: string;
6
+ };
7
+ export declare const createSortableTreeGlobalStyles: (options?: SortableTreeStyleOptions) => () => void;
8
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from './types';
2
+ export { SortableTree } from './SortableTree';
3
+ export { TreeItemStructure } from './components';
4
+ export type { TreeItemStructureProps, RenderItemProps } from './components';
5
+ export { setTreeItemProperties, removeItemById, getItemById } from './utilities';
6
+ export { createSortableTreeGlobalStyles } from './createSortableTreeGlobalStyles';
@@ -1,9 +1,11 @@
1
1
  import { MutableRefObject } from 'react';
2
2
  import { UniqueIdentifier } from '@dnd-kit/core';
3
+ import { Props } from './components/TreeItem/TreeItem';
4
+ export type TreeItem<ExtraProps = unknown> = BaseTreeItem & ExtraProps;
3
5
  /**
4
6
  * Represents an item in the tree structure.
5
7
  */
6
- export type TreeItem = {
8
+ export type BaseTreeItem<ExtraProps = unknown> = {
7
9
  /**
8
10
  * Unique identifier for the item. Can be a string or number.
9
11
  */
@@ -15,7 +17,7 @@ export type TreeItem = {
15
17
  /**
16
18
  * An array of child TreeItems. If empty, the item is a leaf node.
17
19
  */
18
- children: TreeItem[];
20
+ children: TreeItem<ExtraProps>[];
19
21
  /**
20
22
  * Determines whether the item's children are initially collapsed.
21
23
  * @default false
@@ -34,12 +36,8 @@ export type TreeItem = {
34
36
  * @default false
35
37
  */
36
38
  disableDragging?: boolean;
37
- /**
38
- * Any additional custom properties can be added here.
39
- */
40
- [key: string]: any;
41
39
  };
42
- export type TreeItems = TreeItem[];
40
+ export type TreeItems<ExtraProps = unknown> = TreeItem<ExtraProps>[];
43
41
  export interface FlattenedItem extends TreeItem {
44
42
  parentId: UniqueIdentifier | null;
45
43
  depth: number;
@@ -52,7 +50,7 @@ export type SensorContext = MutableRefObject<{
52
50
  /**
53
51
  * Props for the SortableTree component.
54
52
  */
55
- export interface SortableTreeProps {
53
+ export interface SortableTreeProps<T extends TreeItem = TreeItem> {
56
54
  /**
57
55
  * A control that lets you add the indentation width for children elements
58
56
  */
@@ -60,12 +58,12 @@ export interface SortableTreeProps {
60
58
  /**
61
59
  * The array of tree items to be rendered.
62
60
  */
63
- items: TreeItems;
61
+ items: TreeItems<T>;
64
62
  /**
65
63
  * Callback function called when the tree structure changes.
66
64
  * @param items - The updated array of tree items.
67
65
  */
68
- setItems: React.Dispatch<React.SetStateAction<TreeItems>>;
66
+ setItems: React.Dispatch<React.SetStateAction<TreeItems<T>>>;
69
67
  /**
70
68
  * Determines if tree items can be collapsed/expanded.
71
69
  * @default false
@@ -119,7 +117,7 @@ export interface SortableTreeProps {
119
117
  * @param item
120
118
  * @returns
121
119
  */
122
- renderItem?: (item: TreeItem) => React.ReactNode;
120
+ renderItem?: Props<T>['renderItem'];
123
121
  }
124
122
  /**
125
123
  * Represents the result of a drag operation in the tree.
@@ -9,16 +9,16 @@ export declare function getProjection(items: FlattenedItem[], activeId: UniqueId
9
9
  };
10
10
  export declare function flattenTree(items: TreeItems): FlattenedItem[];
11
11
  export declare function buildTree(flattenedItems: FlattenedItem[]): TreeItems;
12
- export declare function findItem(items: TreeItem[], itemId: UniqueIdentifier): TreeItem | undefined;
12
+ export declare function findItem(items: TreeItem[], itemId: UniqueIdentifier): import('./types').BaseTreeItem<unknown> | undefined;
13
13
  export declare function findItemDeep(items: TreeItems, itemId: UniqueIdentifier): TreeItem | undefined;
14
- export declare function removeItemById(items: TreeItems, id: UniqueIdentifier): TreeItems;
15
- export declare function setTreeItemProperties(items: TreeItems, id: UniqueIdentifier, setter: (value: TreeItem) => Partial<TreeItem>): TreeItems;
14
+ export declare function removeItemById<T extends TreeItem>(items: TreeItems<T>, id: UniqueIdentifier): TreeItems<T>;
15
+ export declare function setTreeItemProperties<T extends TreeItem>(items: TreeItems<T>, id: UniqueIdentifier, setter: (value: T) => Partial<T>): TreeItems<T>;
16
16
  /**
17
17
  * Retrieves a tree item by its unique identifier.
18
18
  * @param structure The current tree items array
19
19
  * @param id The unique identifier of the item to retrieve.
20
20
  * @returns The tree item if found, undefined otherwise.
21
21
  */
22
- export declare function getItemById(items: TreeItems, id: UniqueIdentifier): TreeItem | undefined;
22
+ export declare function getItemById<T extends TreeItem>(items: TreeItems<T>, id: UniqueIdentifier): TreeItem<T> | undefined;
23
23
  export declare function getChildCount(treeStructure: TreeItems, id: UniqueIdentifier): number;
24
24
  export declare function removeChildrenOf(items: FlattenedItem[], ids: UniqueIdentifier[]): FlattenedItem[];
package/package.json CHANGED
@@ -1,46 +1,70 @@
1
1
  {
2
2
  "name": "@clevertask/react-sortable-tree",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "CleverTask",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
10
- "main": "./dist/react-sortable-tree.js",
11
- "types": "./dist/index.d.ts",
12
- "scripts": {
13
- "dev": "vite",
14
- "build": "rm -rf dist && tsc -b && vite build",
15
- "lint": "eslint .",
16
- "format": "prettier . --write",
17
- "preview": "vite preview",
18
- "prepublishOnly": "npm run build"
10
+ "homepage": "https://github.com/clevertask/react-sortable-tree#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/clevertask/react-sortable-tree/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/clevertask/react-sortable-tree"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/src/index.d.ts",
21
+ "default": "./dist/react-sortable-tree.js"
22
+ },
23
+ "./e2e": {
24
+ "types": "./dist/e2e/utils/index.d.ts",
25
+ "default": "./dist/e2e/index.js"
26
+ }
19
27
  },
20
28
  "dependencies": {
21
- "@dnd-kit/core": "^6.1.0",
22
- "@dnd-kit/sortable": "^8.0.0",
29
+ "@dnd-kit/core": "^6.3.1",
30
+ "@dnd-kit/sortable": "^10.0.0",
23
31
  "@dnd-kit/utilities": "^3.2.2",
32
+ "@griffel/react": "^1.5.29",
24
33
  "classnames": "^2.5.1"
25
34
  },
26
35
  "devDependencies": {
27
- "@eslint/js": "^9.9.0",
28
- "@types/node": "^22.7.6",
29
- "@types/react": "^18.3.11",
30
- "@types/react-dom": "^18.3.1",
31
- "@vitejs/plugin-react-swc": "^3.7.1",
32
- "eslint": "^9.12.0",
33
- "eslint-plugin-react-hooks": "^5.1.0-rc.0",
34
- "eslint-plugin-react-refresh": "^0.4.12",
35
- "globals": "^15.11.0",
36
- "prettier": "^3.3.3",
37
- "typescript": "^5.6.3",
38
- "typescript-eslint": "^8.10.0",
39
- "vite": "^5.4.9",
40
- "vite-plugin-dts": "^4.2.4"
36
+ "@eslint/js": "^9.25.0",
37
+ "@playwright/test": "^1.57.0",
38
+ "@types/node": "^22.14.1",
39
+ "@types/react": "^19.1.2",
40
+ "@types/react-dom": "^19.1.2",
41
+ "@vitejs/plugin-react-swc": "^3.9.0",
42
+ "eslint": "^9.25.0",
43
+ "eslint-plugin-react-hooks": "^5.2.0",
44
+ "eslint-plugin-react-refresh": "^0.4.19",
45
+ "globals": "^16.0.0",
46
+ "husky": "^9.1.7",
47
+ "lint-staged": "^16.2.7",
48
+ "prettier": "^3.5.3",
49
+ "typescript": "^5.8.3",
50
+ "typescript-eslint": "^8.30.1",
51
+ "vite": "^6.3.2",
52
+ "vite-plugin-dts": "^4.5.3"
41
53
  },
42
54
  "peerDependencies": {
43
- "react": "^18.3.1",
44
- "react-dom": "^18.3.1"
55
+ "react": ">=18.3.1 <20.0.0",
56
+ "react-dom": ">=18.3.1 <20.0.0"
57
+ },
58
+ "lint-staged": {
59
+ "*.{ts, tsx, css}": "pnpm run format"
60
+ },
61
+ "scripts": {
62
+ "dev": "vite",
63
+ "e2e": "playwright test",
64
+ "e2e:dev": "playwright test --ui",
65
+ "build": "rm -rf dist && vite build && vite build -c vite.test.config.ts",
66
+ "lint": "eslint .",
67
+ "format": "prettier --write",
68
+ "preview": "vite preview"
45
69
  }
46
- }
70
+ }
@@ -1,4 +0,0 @@
1
- import { SortableTreeProps } from './types';
2
- declare function PrivateSortableTree({ items, setItems, isCollapsible, onLazyLoadChildren, showDropIndicator, indentationWidth, isRemovable, onRemoveItem, allowNestedItemAddition, onAddItem, onDragEnd, onItemClick, renderItem, }: SortableTreeProps): import("react/jsx-runtime").JSX.Element;
3
- export declare const SortableTree: import('react').MemoExoticComponent<typeof PrivateSortableTree>;
4
- export {};
@@ -1,23 +0,0 @@
1
- import { default as React, HTMLAttributes } from 'react';
2
- export interface Props extends Omit<HTMLAttributes<HTMLLIElement>, 'id'> {
3
- childCount?: number;
4
- clone?: boolean;
5
- collapsed?: boolean;
6
- depth: number;
7
- disableInteraction?: boolean;
8
- disableSelection?: boolean;
9
- disableDragging?: boolean;
10
- ghost?: boolean;
11
- handleProps?: any;
12
- indicator?: boolean;
13
- indentationWidth: number;
14
- value: string;
15
- onCollapse?(): void;
16
- onRemove?(): void;
17
- onAdd?(): void;
18
- onLabelClick?(): void;
19
- wrapperRef?(node: HTMLLIElement): void;
20
- renderedItem?: React.ReactNode;
21
- }
22
- export declare const _TreeItem: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
23
- export declare const TreeItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>>;
@@ -1 +0,0 @@
1
- export { TreeItem, SortableTreeItem } from './TreeItem';
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export { SortableTree } from './SortableTree';
3
- export { setTreeItemProperties, removeItemById, getItemById } from './utilities';
File without changes
File without changes