react-arborist 1.2.0 → 2.0.0-rc
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.
- package/dist/components/{drop-cursor.d.ts → cursor.d.ts} +0 -0
- package/dist/components/default-container.d.ts +2 -0
- package/dist/components/default-cursor.d.ts +3 -0
- package/dist/components/default-drag-preview.d.ts +3 -0
- package/dist/components/default-node.d.ts +4 -0
- package/dist/components/default-row.d.ts +4 -0
- package/dist/components/drag-preview-container.d.ts +2 -0
- package/dist/components/list-inner-element.d.ts +2 -0
- package/dist/components/provider.d.ts +11 -0
- package/dist/components/row-container.d.ts +8 -0
- package/dist/components/tree-container.d.ts +2 -0
- package/dist/components/tree.d.ts +5 -4
- package/dist/context.d.ts +20 -2
- package/dist/data/create-index.d.ts +5 -0
- package/dist/data/create-list.d.ts +4 -0
- package/dist/data/create-root.d.ts +5 -0
- package/dist/data/flatten-tree.d.ts +4 -2
- package/dist/data/simple-tree.d.ts +43 -0
- package/dist/dnd/compute-drop.d.ts +4 -4
- package/dist/dnd/drag-hook.d.ts +3 -4
- package/dist/dnd/drop-hook.d.ts +2 -3
- package/dist/hooks/use-fresh-node.d.ts +2 -0
- package/dist/hooks/use-simple-tree.d.ts +13 -0
- package/dist/hooks/use-uncontrolled-tree.d.ts +24 -0
- package/dist/hooks/use-validated-props.d.ts +3 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +1900 -971
- package/dist/index.js.map +1 -1
- package/dist/interfaces/node-api.d.ts +67 -0
- package/dist/interfaces/tree-api.d.ts +112 -0
- package/dist/module.js +1886 -976
- package/dist/module.js.map +1 -1
- package/dist/state/dnd-slice.d.ts +20 -0
- package/dist/state/drag-slice.d.ts +7 -0
- package/dist/state/edit-slice.d.ts +8 -0
- package/dist/state/focus-slice.d.ts +12 -0
- package/dist/state/initial.d.ts +3 -0
- package/dist/state/open-slice.d.ts +30 -0
- package/dist/state/root-reducer.d.ts +13 -0
- package/dist/state/selection-slice.d.ts +36 -0
- package/dist/types/dnd.d.ts +9 -0
- package/dist/types/handlers.d.ts +24 -0
- package/dist/types/renderers.d.ts +30 -0
- package/dist/types/state.d.ts +2 -0
- package/dist/types/tree-props.d.ts +43 -0
- package/dist/types/utils.d.ts +21 -0
- package/dist/utils/props.d.ts +3 -0
- package/dist/utils.d.ts +15 -6
- package/package.json +10 -7
- package/src/components/cursor.tsx +15 -0
- package/src/components/default-container.tsx +229 -0
- package/src/components/{default-drop-cursor.tsx → default-cursor.tsx} +9 -8
- package/src/components/{preview.tsx → default-drag-preview.tsx} +25 -41
- package/src/components/default-node.tsx +15 -0
- package/src/components/default-row.tsx +21 -0
- package/src/components/drag-preview-container.tsx +26 -0
- package/src/components/list-inner-element.tsx +22 -0
- package/src/components/list-outer-element.tsx +26 -15
- package/src/components/provider.tsx +97 -0
- package/src/components/row-container.tsx +82 -0
- package/src/components/tree-container.tsx +13 -0
- package/src/components/tree.tsx +16 -44
- package/src/context.ts +36 -0
- package/src/data/create-index.ts +9 -0
- package/src/data/create-list.ts +56 -0
- package/src/data/create-root.ts +53 -0
- package/src/data/simple-tree.ts +103 -0
- package/src/dnd/compute-drop.ts +16 -16
- package/src/dnd/drag-hook.ts +25 -19
- package/src/dnd/drop-hook.ts +31 -17
- package/src/dnd/outer-drop-hook.ts +1 -1
- package/src/hooks/use-fresh-node.ts +16 -0
- package/src/hooks/use-simple-tree.ts +55 -0
- package/src/hooks/use-validated-props.ts +35 -0
- package/src/index.ts +9 -19
- package/src/interfaces/node-api.ts +187 -0
- package/src/interfaces/tree-api.ts +552 -0
- package/src/state/dnd-slice.ts +36 -0
- package/src/state/drag-slice.ts +31 -0
- package/src/state/edit-slice.ts +19 -0
- package/src/state/focus-slice.ts +28 -0
- package/src/state/initial.ts +14 -0
- package/src/state/open-slice.ts +53 -0
- package/src/state/root-reducer.ts +21 -0
- package/src/state/selection-slice.ts +75 -0
- package/src/types/dnd.ts +10 -0
- package/src/types/handlers.ts +24 -0
- package/src/types/renderers.ts +34 -0
- package/src/types/state.ts +3 -0
- package/src/types/tree-props.ts +63 -0
- package/src/types/utils.ts +26 -0
- package/src/utils/props.ts +8 -0
- package/src/utils.ts +125 -11
- package/README.md +0 -221
- package/dist/components/default-drop-cursor.d.ts +0 -3
- package/dist/components/list.d.ts +0 -4
- package/dist/components/preview.d.ts +0 -2
- package/dist/components/row.d.ts +0 -8
- package/dist/data/enrich-tree.d.ts +0 -2
- package/dist/provider.d.ts +0 -3
- package/dist/reducer.d.ts +0 -46
- package/dist/selection/range.d.ts +0 -13
- package/dist/selection/selection-hook.d.ts +0 -4
- package/dist/selection/selection.d.ts +0 -33
- package/dist/tree-api.d.ts +0 -50
- package/dist/types.d.ts +0 -122
- package/src/components/drop-cursor.tsx +0 -12
- package/src/components/list.tsx +0 -25
- package/src/components/row.tsx +0 -112
- package/src/context.tsx +0 -13
- package/src/data/enrich-tree.ts +0 -74
- package/src/data/flatten-tree.ts +0 -17
- package/src/provider.tsx +0 -41
- package/src/reducer.ts +0 -161
- package/src/selection/range.ts +0 -41
- package/src/selection/selection-hook.ts +0 -25
- package/src/selection/selection.test.ts +0 -111
- package/src/selection/selection.ts +0 -186
- package/src/tree-api.ts +0 -230
- package/src/types.ts +0 -148
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { TreeApi } from "../interfaces/tree-api";
|
|
3
|
+
import { IdObj } from "../types/utils";
|
|
4
|
+
import { TreeProps } from "../types/tree-props";
|
|
5
|
+
declare type Props<T extends IdObj> = {
|
|
6
|
+
treeProps: TreeProps<T>;
|
|
7
|
+
imperativeHandle: React.Ref<TreeApi<T> | undefined>;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare function TreeProvider<T extends IdObj>({ treeProps, imperativeHandle, children, }: Props<T>): JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IdObj } from "../types/utils";
|
|
3
|
+
declare type Props = {
|
|
4
|
+
style: React.CSSProperties;
|
|
5
|
+
index: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const RowContainer: React.MemoExoticComponent<(<T extends IdObj>({ index, style, }: Props) => JSX.Element)>;
|
|
8
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { TreeApi } from "../tree-api";
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TreeApi } from "../interfaces/tree-api";
|
|
3
|
+
import { TreeProps } from "../types/tree-props";
|
|
4
|
+
import { IdObj } from "../types/utils";
|
|
5
|
+
export declare const Tree: <T extends IdObj>(props: TreeProps<T> & import("react").RefAttributes<TreeApi<T> | undefined>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { TreeApi } from "./tree-api";
|
|
3
|
-
import { IdObj } from "./types";
|
|
2
|
+
import { TreeApi } from "./interfaces/tree-api";
|
|
3
|
+
import { IdObj } from "./types/utils";
|
|
4
4
|
export declare const TreeApiContext: React.Context<TreeApi<any> | null>;
|
|
5
5
|
export declare function useTreeApi<T extends IdObj>(): TreeApi<T>;
|
|
6
|
+
export declare const NodesContext: React.Context<import("redux").CombinedState<{
|
|
7
|
+
focus: import("./state/focus-slice").FocusState;
|
|
8
|
+
edit: import("./state/edit-slice").EditState;
|
|
9
|
+
open: import("./state/open-slice").OpenSlice;
|
|
10
|
+
selection: import("./state/selection-slice").SelectionState;
|
|
11
|
+
drag: import("./state/drag-slice").DragSlice;
|
|
12
|
+
}> | null>;
|
|
13
|
+
export declare function useNodesContext(): import("redux").CombinedState<{
|
|
14
|
+
focus: import("./state/focus-slice").FocusState;
|
|
15
|
+
edit: import("./state/edit-slice").EditState;
|
|
16
|
+
open: import("./state/open-slice").OpenSlice;
|
|
17
|
+
selection: import("./state/selection-slice").SelectionState;
|
|
18
|
+
drag: import("./state/drag-slice").DragSlice;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const DndContext: React.Context<import("./state/dnd-slice").DndState | null>;
|
|
21
|
+
export declare function useDndContext(): import("./state/dnd-slice").DndState;
|
|
22
|
+
export declare const DataUpdatesContext: React.Context<number>;
|
|
23
|
+
export declare function useDataUpdates(): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IdObj } from "../types/utils";
|
|
2
|
+
import { NodeApi } from "../interfaces/node-api";
|
|
3
|
+
import { TreeApi } from "../interfaces/tree-api";
|
|
4
|
+
export declare const ROOT_ID = "__REACT_ARBORIST_INTERNAL_ROOT__";
|
|
5
|
+
export declare function createRoot<T extends IdObj>(tree: TreeApi<T>): NodeApi<T>;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { NodeApi } from "../interfaces/node-api";
|
|
2
|
+
import { IdObj } from "../types/utils";
|
|
3
|
+
export declare function flattenTree<T extends IdObj>(root: NodeApi<T>): NodeApi<T>[];
|
|
4
|
+
export declare function filterTree<T extends IdObj>(root: NodeApi<T>, isMatch: (n: NodeApi<T>) => boolean): NodeApi<T>[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
declare type IdObj = {
|
|
2
|
+
id: string;
|
|
3
|
+
children?: IdObj[];
|
|
4
|
+
};
|
|
5
|
+
export declare class SimpleTree<T extends IdObj> {
|
|
6
|
+
root: SimpleNode<T>;
|
|
7
|
+
constructor(data: T[]);
|
|
8
|
+
get data(): T[];
|
|
9
|
+
create(args: {
|
|
10
|
+
parentId: string | null;
|
|
11
|
+
index: number;
|
|
12
|
+
data: T;
|
|
13
|
+
}): null | undefined;
|
|
14
|
+
move(args: {
|
|
15
|
+
id: string;
|
|
16
|
+
parentId: string | null;
|
|
17
|
+
index: number;
|
|
18
|
+
}): void;
|
|
19
|
+
update(args: {
|
|
20
|
+
id: string;
|
|
21
|
+
changes: Partial<T>;
|
|
22
|
+
}): void;
|
|
23
|
+
drop(args: {
|
|
24
|
+
id: string;
|
|
25
|
+
}): void;
|
|
26
|
+
find(id: string, node?: SimpleNode<T>): SimpleNode<T> | null;
|
|
27
|
+
}
|
|
28
|
+
declare class SimpleNode<T extends IdObj> {
|
|
29
|
+
data: T;
|
|
30
|
+
parent: SimpleNode<T> | null;
|
|
31
|
+
id: string;
|
|
32
|
+
children?: SimpleNode<T>[];
|
|
33
|
+
constructor(data: T, parent: SimpleNode<T> | null);
|
|
34
|
+
hasParent(): this is this & {
|
|
35
|
+
parent: SimpleNode<T>;
|
|
36
|
+
};
|
|
37
|
+
get childIndex(): number;
|
|
38
|
+
addChild(data: T, index: number): void;
|
|
39
|
+
removeChild(index: number): void;
|
|
40
|
+
update(changes: Partial<T>): void;
|
|
41
|
+
drop(): void;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { XYCoord } from "react-dnd";
|
|
2
|
-
import {
|
|
2
|
+
import { NodeApi } from "../interfaces/node-api";
|
|
3
3
|
import { DropResult } from "./drop-hook";
|
|
4
4
|
declare type Args = {
|
|
5
5
|
element: HTMLElement;
|
|
6
6
|
offset: XYCoord;
|
|
7
7
|
indent: number;
|
|
8
|
-
node:
|
|
9
|
-
prevNode:
|
|
10
|
-
nextNode:
|
|
8
|
+
node: NodeApi | null;
|
|
9
|
+
prevNode: NodeApi | null;
|
|
10
|
+
nextNode: NodeApi | null;
|
|
11
11
|
};
|
|
12
12
|
export declare type ComputedDrop = {
|
|
13
13
|
drop: DropResult | null;
|
package/dist/dnd/drag-hook.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ConnectDragSource } from "react-dnd";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}, ConnectDragSource];
|
|
2
|
+
import { NodeApi } from "../interfaces/node-api";
|
|
3
|
+
import { IdObj } from "../types/utils";
|
|
4
|
+
export declare function useDragHook<T extends IdObj>(node: NodeApi<T>): ConnectDragSource;
|
package/dist/dnd/drop-hook.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
2
|
import { ConnectDropTarget } from "react-dnd";
|
|
3
|
-
import {
|
|
3
|
+
import { NodeApi } from "../interfaces/node-api";
|
|
4
4
|
export declare type DropResult = {
|
|
5
5
|
parentId: string | null;
|
|
6
6
|
index: number;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
9
|
-
export declare function useDropHook(el: RefObject<HTMLElement | null>, node: Node, prev: Node | null, next: Node | null): [CollectedProps, ConnectDropTarget];
|
|
8
|
+
export declare function useDropHook(el: RefObject<HTMLElement | null>, node: NodeApi<any>): ConnectDropTarget;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CreateHandler, DeleteHandler, MoveHandler, RenameHandler } from "../types/handlers";
|
|
2
|
+
import { IdObj } from "../types/utils";
|
|
3
|
+
export declare type SimpleTreeData = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
children?: SimpleTreeData[];
|
|
7
|
+
};
|
|
8
|
+
export declare function useSimpleTree<T extends IdObj>(initialData: T[]): readonly [T[], {
|
|
9
|
+
onMove: MoveHandler;
|
|
10
|
+
onRename: RenameHandler;
|
|
11
|
+
onCreate: CreateHandler;
|
|
12
|
+
onDelete: DeleteHandler;
|
|
13
|
+
}];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare type Data = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
children?: Data[];
|
|
5
|
+
};
|
|
6
|
+
export declare function useUncontrolledTree(initialData: Data[]): readonly [Data[], {
|
|
7
|
+
move: (args: {
|
|
8
|
+
dragIds: string[];
|
|
9
|
+
parentId: string;
|
|
10
|
+
index: number;
|
|
11
|
+
}) => void;
|
|
12
|
+
rename: (args: {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
create: ({ parentId, index }: {
|
|
17
|
+
parentId: string;
|
|
18
|
+
index: number;
|
|
19
|
+
}) => Data;
|
|
20
|
+
drop: (args: {
|
|
21
|
+
id: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
}];
|
|
24
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
export { Tree } from "./components/tree";
|
|
2
|
+
export * from "./types/handlers";
|
|
3
|
+
export * from "./types/renderers";
|
|
4
|
+
export * from "./types/state";
|
|
5
|
+
export * from "./interfaces/node-api";
|
|
6
|
+
export * from "./interfaces/tree-api";
|
|
7
|
+
export * from "./data/simple-tree";
|
|
8
|
+
export * from "./hooks/use-simple-tree";
|