react-arborist 3.3.0-rc.1 → 3.3.1-0
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/main/components/cursor.d.ts +1 -0
- package/dist/main/components/cursor.js +20 -0
- package/dist/{components → main/components}/default-container.d.ts +1 -2
- package/dist/main/components/default-container.js +238 -0
- package/dist/main/components/default-cursor.js +35 -0
- package/dist/{components → main/components}/default-drag-preview.d.ts +1 -2
- package/dist/main/components/default-drag-preview.js +57 -0
- package/dist/{components → main/components}/default-node.d.ts +1 -2
- package/dist/main/components/default-node.js +32 -0
- package/dist/{components → main/components}/default-row.d.ts +1 -2
- package/dist/main/components/default-row.js +8 -0
- package/dist/main/components/drag-preview-container.d.ts +1 -0
- package/dist/main/components/drag-preview-container.js +21 -0
- package/dist/{components → main/components}/list-inner-element.d.ts +1 -1
- package/dist/main/components/list-inner-element.js +25 -0
- package/dist/main/components/list-outer-element.d.ts +2 -0
- package/dist/main/components/list-outer-element.js +38 -0
- package/dist/main/components/outer-drop.js +9 -0
- package/dist/{components → main/components}/provider.d.ts +2 -2
- package/dist/main/components/provider.js +52 -0
- package/dist/{components → main/components}/row-container.d.ts +2 -2
- package/dist/main/components/row-container.js +84 -0
- package/dist/main/components/tree-container.d.ts +1 -0
- package/dist/main/components/tree-container.js +12 -0
- package/dist/{components → main/components}/tree.d.ts +1 -1
- package/dist/main/components/tree.js +15 -0
- package/dist/{context.d.ts → main/context.d.ts} +4 -4
- package/dist/main/context.js +33 -0
- package/dist/main/data/create-index.js +10 -0
- package/dist/main/data/create-list.js +62 -0
- package/dist/main/data/create-root.js +43 -0
- package/dist/main/data/make-tree.d.ts +5 -0
- package/dist/main/data/make-tree.js +40 -0
- package/dist/{data → main/data}/simple-tree.d.ts +1 -1
- package/dist/main/data/simple-tree.js +100 -0
- package/dist/{dnd → main/dnd}/compute-drop.d.ts +6 -6
- package/dist/main/dnd/compute-drop.js +129 -0
- package/dist/main/dnd/drag-hook.js +46 -0
- package/dist/{dnd → main/dnd}/drop-hook.d.ts +1 -1
- package/dist/main/dnd/drop-hook.js +42 -0
- package/dist/main/dnd/measure-hover.d.ts +8 -0
- package/dist/main/dnd/measure-hover.js +21 -0
- package/dist/main/dnd/outer-drop-hook.js +45 -0
- package/dist/main/hooks/use-fresh-node.js +18 -0
- package/dist/{hooks → main/hooks}/use-simple-tree.d.ts +1 -1
- package/dist/main/hooks/use-simple-tree.js +35 -0
- package/dist/main/hooks/use-validated-props.js +29 -0
- package/dist/main/index.js +27 -0
- package/dist/{interfaces → main/interfaces}/node-api.d.ts +1 -1
- package/dist/main/interfaces/node-api.js +164 -0
- package/dist/{interfaces → main/interfaces}/tree-api.d.ts +87 -7
- package/dist/main/interfaces/tree-api.js +649 -0
- package/dist/main/interfaces/tree-api.test.d.ts +1 -0
- package/dist/main/interfaces/tree-api.test.js +14 -0
- package/dist/{state → main/state}/dnd-slice.d.ts +1 -1
- package/dist/main/state/dnd-slice.js +35 -0
- package/dist/{state → main/state}/drag-slice.d.ts +1 -1
- package/dist/main/state/drag-slice.js +24 -0
- package/dist/{state → main/state}/edit-slice.d.ts +1 -1
- package/dist/main/state/edit-slice.js +18 -0
- package/dist/{state → main/state}/focus-slice.d.ts +1 -1
- package/dist/main/state/focus-slice.js +26 -0
- package/dist/main/state/initial.js +29 -0
- package/dist/{state → main/state}/open-slice.d.ts +2 -2
- package/dist/main/state/open-slice.js +48 -0
- package/dist/main/state/root-reducer.d.ts +96 -0
- package/dist/main/state/root-reducer.js +20 -0
- package/dist/{state → main/state}/selection-slice.d.ts +1 -1
- package/dist/main/state/selection-slice.js +59 -0
- package/dist/{types → main/types}/dnd.d.ts +2 -2
- package/dist/main/types/dnd.js +2 -0
- package/dist/{types → main/types}/handlers.d.ts +5 -5
- package/dist/main/types/handlers.js +2 -0
- package/dist/{types → main/types}/renderers.d.ts +4 -4
- package/dist/main/types/renderers.js +2 -0
- package/dist/main/types/state.d.ts +2 -0
- package/dist/main/types/state.js +2 -0
- package/dist/main/types/tree-props.js +2 -0
- package/dist/{types → main/types}/utils.d.ts +5 -5
- package/dist/main/types/utils.js +2 -0
- package/dist/main/utils.js +183 -0
- package/dist/module/components/cursor.d.ts +1 -0
- package/dist/module/components/cursor.js +16 -0
- package/dist/module/components/default-container.d.ts +6 -0
- package/dist/module/components/default-container.js +234 -0
- package/dist/module/components/default-cursor.d.ts +3 -0
- package/dist/module/components/default-cursor.js +29 -0
- package/dist/module/components/default-drag-preview.d.ts +2 -0
- package/dist/module/components/default-drag-preview.js +53 -0
- package/dist/module/components/default-node.d.ts +2 -0
- package/dist/module/components/default-node.js +28 -0
- package/dist/module/components/default-row.d.ts +2 -0
- package/dist/module/components/default-row.js +4 -0
- package/dist/module/components/drag-preview-container.d.ts +1 -0
- package/dist/module/components/drag-preview-container.js +17 -0
- package/dist/module/components/list-inner-element.d.ts +2 -0
- package/dist/module/components/list-inner-element.js +22 -0
- package/dist/module/components/list-outer-element.d.ts +2 -0
- package/dist/module/components/list-outer-element.js +35 -0
- package/dist/module/components/outer-drop.d.ts +4 -0
- package/dist/module/components/outer-drop.js +5 -0
- package/dist/module/components/provider.d.ts +10 -0
- package/dist/module/components/provider.js +48 -0
- package/dist/module/components/row-container.d.ts +7 -0
- package/dist/module/components/row-container.js +58 -0
- package/dist/module/components/tree-container.d.ts +1 -0
- package/dist/module/components/tree-container.js +8 -0
- package/dist/module/components/tree.d.ts +8 -0
- package/dist/module/components/tree.js +12 -0
- package/dist/module/context.d.ts +22 -0
- package/dist/module/context.js +26 -0
- package/dist/module/data/create-index.d.ts +4 -0
- package/dist/module/data/create-index.js +6 -0
- package/dist/module/data/create-list.d.ts +3 -0
- package/dist/module/data/create-list.js +58 -0
- package/dist/module/data/create-root.d.ts +4 -0
- package/dist/module/data/create-root.js +39 -0
- package/dist/module/data/make-tree.d.ts +5 -0
- package/dist/module/data/make-tree.js +36 -0
- package/dist/module/data/simple-tree.d.ts +44 -0
- package/dist/module/data/simple-tree.js +96 -0
- package/dist/module/dnd/compute-drop.d.ts +37 -0
- package/dist/module/dnd/compute-drop.js +125 -0
- package/dist/module/dnd/drag-hook.d.ts +3 -0
- package/dist/module/dnd/drag-hook.js +42 -0
- package/dist/module/dnd/drop-hook.d.ts +8 -0
- package/dist/module/dnd/drop-hook.js +38 -0
- package/dist/module/dnd/measure-hover.d.ts +8 -0
- package/dist/module/dnd/measure-hover.js +17 -0
- package/dist/module/dnd/outer-drop-hook.d.ts +1 -0
- package/dist/module/dnd/outer-drop-hook.js +41 -0
- package/dist/module/hooks/use-fresh-node.d.ts +1 -0
- package/dist/module/hooks/use-fresh-node.js +14 -0
- package/dist/module/hooks/use-simple-tree.d.ts +12 -0
- package/dist/module/hooks/use-simple-tree.js +31 -0
- package/dist/module/hooks/use-validated-props.d.ts +2 -0
- package/dist/module/hooks/use-validated-props.js +25 -0
- package/dist/module/index.d.ts +8 -0
- package/dist/module/index.js +9 -0
- package/dist/module/interfaces/node-api.d.ts +71 -0
- package/dist/module/interfaces/node-api.js +160 -0
- package/dist/module/interfaces/tree-api.d.ts +214 -0
- package/dist/module/interfaces/tree-api.js +622 -0
- package/dist/module/interfaces/tree-api.test.d.ts +1 -0
- package/dist/module/interfaces/tree-api.test.js +12 -0
- package/dist/module/state/dnd-slice.d.ts +29 -0
- package/dist/module/state/dnd-slice.js +31 -0
- package/dist/module/state/drag-slice.d.ts +9 -0
- package/dist/module/state/drag-slice.js +20 -0
- package/dist/module/state/edit-slice.d.ts +8 -0
- package/dist/module/state/edit-slice.js +13 -0
- package/dist/module/state/focus-slice.d.ts +12 -0
- package/dist/module/state/focus-slice.js +20 -0
- package/dist/module/state/initial.d.ts +3 -0
- package/dist/module/state/initial.js +25 -0
- package/dist/module/state/open-slice.d.ts +30 -0
- package/dist/module/state/open-slice.js +44 -0
- package/dist/module/state/root-reducer.d.ts +96 -0
- package/dist/module/state/root-reducer.js +17 -0
- package/dist/module/state/selection-slice.d.ts +42 -0
- package/dist/module/state/selection-slice.js +55 -0
- package/dist/module/types/dnd.d.ts +8 -0
- package/dist/module/types/dnd.js +1 -0
- package/dist/module/types/handlers.d.ts +30 -0
- package/dist/module/types/handlers.js +1 -0
- package/dist/module/types/renderers.d.ts +29 -0
- package/dist/module/types/renderers.js +1 -0
- package/dist/module/types/state.d.ts +2 -0
- package/dist/module/types/state.js +1 -0
- package/dist/module/types/tree-props.d.ts +56 -0
- package/dist/module/types/tree-props.js +1 -0
- package/dist/module/types/utils.d.ts +17 -0
- package/dist/module/types/utils.js +1 -0
- package/dist/module/utils.d.ts +24 -0
- package/dist/module/utils.js +162 -0
- package/package.json +26 -25
- package/src/components/default-container.tsx +2 -0
- package/src/components/provider.tsx +3 -2
- package/src/components/row-container.tsx +1 -1
- package/dist/components/cursor.d.ts +0 -2
- package/dist/components/drag-preview-container.d.ts +0 -2
- package/dist/components/list-outer-element.d.ts +0 -2
- package/dist/components/tree-container.d.ts +0 -2
- package/dist/index.js +0 -2433
- package/dist/index.js.map +0 -1
- package/dist/module.js +0 -2406
- package/dist/module.js.map +0 -1
- package/dist/state/root-reducer.d.ts +0 -13
- package/dist/types/state.d.ts +0 -2
- package/jest.config.js +0 -5
- package/tsconfig.json +0 -4
- /package/dist/{components → main/components}/default-cursor.d.ts +0 -0
- /package/dist/{components → main/components}/outer-drop.d.ts +0 -0
- /package/dist/{data → main/data}/create-index.d.ts +0 -0
- /package/dist/{data → main/data}/create-list.d.ts +0 -0
- /package/dist/{data → main/data}/create-root.d.ts +0 -0
- /package/dist/{dnd → main/dnd}/drag-hook.d.ts +0 -0
- /package/dist/{dnd → main/dnd}/outer-drop-hook.d.ts +0 -0
- /package/dist/{hooks → main/hooks}/use-fresh-node.d.ts +0 -0
- /package/dist/{hooks → main/hooks}/use-validated-props.d.ts +0 -0
- /package/dist/{index.d.ts → main/index.d.ts} +0 -0
- /package/dist/{state → main/state}/initial.d.ts +0 -0
- /package/dist/{types → main/types}/tree-props.d.ts +0 -0
- /package/dist/{utils.d.ts → main/utils.d.ts} +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDropHook = void 0;
|
|
4
|
+
const react_dnd_1 = require("react-dnd");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const compute_drop_1 = require("./compute-drop");
|
|
7
|
+
const dnd_slice_1 = require("../state/dnd-slice");
|
|
8
|
+
function useDropHook(el, node) {
|
|
9
|
+
const tree = (0, context_1.useTreeApi)();
|
|
10
|
+
const [_, dropRef] = (0, react_dnd_1.useDrop)(() => ({
|
|
11
|
+
accept: "NODE",
|
|
12
|
+
canDrop: () => tree.canDrop(),
|
|
13
|
+
hover: (_item, m) => {
|
|
14
|
+
const offset = m.getClientOffset();
|
|
15
|
+
if (!el.current || !offset)
|
|
16
|
+
return;
|
|
17
|
+
const { cursor, drop } = (0, compute_drop_1.computeDrop)({
|
|
18
|
+
element: el.current,
|
|
19
|
+
offset: offset,
|
|
20
|
+
indent: tree.indent,
|
|
21
|
+
node: node,
|
|
22
|
+
prevNode: node.prev,
|
|
23
|
+
nextNode: node.next,
|
|
24
|
+
});
|
|
25
|
+
if (drop)
|
|
26
|
+
tree.dispatch(dnd_slice_1.actions.hovering(drop.parentId, drop.index));
|
|
27
|
+
if (m.canDrop()) {
|
|
28
|
+
if (cursor)
|
|
29
|
+
tree.showCursor(cursor);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
tree.hideCursor();
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
drop: (_, m) => {
|
|
36
|
+
if (!m.canDrop())
|
|
37
|
+
return null;
|
|
38
|
+
},
|
|
39
|
+
}), [node, el.current, tree.props]);
|
|
40
|
+
return dropRef;
|
|
41
|
+
}
|
|
42
|
+
exports.useDropHook = useDropHook;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { XYCoord } from "react-dnd";
|
|
2
|
+
export declare function measureHover(el: HTMLElement, offset: XYCoord, indent: number): {
|
|
3
|
+
level: number;
|
|
4
|
+
inTopHalf: boolean;
|
|
5
|
+
inBottomHalf: boolean;
|
|
6
|
+
inMiddle: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type HoverData = ReturnType<typeof measureHover>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.measureHover = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
function measureHover(el, offset, indent) {
|
|
6
|
+
const nextEl = el.nextElementSibling;
|
|
7
|
+
const prevEl = el.previousElementSibling;
|
|
8
|
+
const rect = el.getBoundingClientRect();
|
|
9
|
+
const x = offset.x - Math.round(rect.x);
|
|
10
|
+
const y = offset.y - Math.round(rect.y);
|
|
11
|
+
const height = rect.height;
|
|
12
|
+
const inTopHalf = y < height / 2;
|
|
13
|
+
const inBottomHalf = !inTopHalf;
|
|
14
|
+
const pad = height / 4;
|
|
15
|
+
const inMiddle = y > pad && y < height - pad;
|
|
16
|
+
const maxLevel = Number(inBottomHalf ? el.dataset.level : prevEl ? prevEl.dataset.level : 0);
|
|
17
|
+
const minLevel = Number(inTopHalf ? el.dataset.level : nextEl ? nextEl.dataset.level : 0);
|
|
18
|
+
const level = (0, utils_1.bound)(Math.floor(x / indent), minLevel, maxLevel);
|
|
19
|
+
return { level, inTopHalf, inBottomHalf, inMiddle };
|
|
20
|
+
}
|
|
21
|
+
exports.measureHover = measureHover;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOuterDrop = void 0;
|
|
4
|
+
const react_dnd_1 = require("react-dnd");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const compute_drop_1 = require("./compute-drop");
|
|
7
|
+
const dnd_slice_1 = require("../state/dnd-slice");
|
|
8
|
+
function useOuterDrop() {
|
|
9
|
+
const tree = (0, context_1.useTreeApi)();
|
|
10
|
+
// In case we drop an item at the bottom of the list
|
|
11
|
+
const [, drop] = (0, react_dnd_1.useDrop)(() => ({
|
|
12
|
+
accept: "NODE",
|
|
13
|
+
canDrop: (_item, m) => {
|
|
14
|
+
if (!m.isOver({ shallow: true }))
|
|
15
|
+
return false;
|
|
16
|
+
return tree.canDrop();
|
|
17
|
+
},
|
|
18
|
+
hover: (_item, m) => {
|
|
19
|
+
if (!m.isOver({ shallow: true }))
|
|
20
|
+
return;
|
|
21
|
+
const offset = m.getClientOffset();
|
|
22
|
+
if (!tree.listEl.current || !offset)
|
|
23
|
+
return;
|
|
24
|
+
const { cursor, drop } = (0, compute_drop_1.computeDrop)({
|
|
25
|
+
element: tree.listEl.current,
|
|
26
|
+
offset: offset,
|
|
27
|
+
indent: tree.indent,
|
|
28
|
+
node: null,
|
|
29
|
+
prevNode: tree.visibleNodes[tree.visibleNodes.length - 1],
|
|
30
|
+
nextNode: null,
|
|
31
|
+
});
|
|
32
|
+
if (drop)
|
|
33
|
+
tree.dispatch(dnd_slice_1.actions.hovering(drop.parentId, drop.index));
|
|
34
|
+
if (m.canDrop()) {
|
|
35
|
+
if (cursor)
|
|
36
|
+
tree.showCursor(cursor);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
tree.hideCursor();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
}), [tree]);
|
|
43
|
+
drop(tree.listEl);
|
|
44
|
+
}
|
|
45
|
+
exports.useOuterDrop = useOuterDrop;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFreshNode = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
function useFreshNode(index) {
|
|
7
|
+
const tree = (0, context_1.useTreeApi)();
|
|
8
|
+
const original = tree.at(index);
|
|
9
|
+
if (!original)
|
|
10
|
+
throw new Error(`Could not find node for index: ${index}`);
|
|
11
|
+
return (0, react_1.useMemo)(() => {
|
|
12
|
+
const fresh = original.clone();
|
|
13
|
+
tree.visibleNodes[index] = fresh; // sneaky
|
|
14
|
+
return fresh;
|
|
15
|
+
// Return a fresh instance if the state values change
|
|
16
|
+
}, [...Object.values(original.state), original]);
|
|
17
|
+
}
|
|
18
|
+
exports.useFreshNode = useFreshNode;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSimpleTree = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const simple_tree_1 = require("../data/simple-tree");
|
|
6
|
+
let nextId = 0;
|
|
7
|
+
function useSimpleTree(initialData) {
|
|
8
|
+
const [data, setData] = (0, react_1.useState)(initialData);
|
|
9
|
+
const tree = (0, react_1.useMemo)(() => new simple_tree_1.SimpleTree(data), [data]);
|
|
10
|
+
const onMove = (args) => {
|
|
11
|
+
for (const id of args.dragIds) {
|
|
12
|
+
tree.move({ id, parentId: args.parentId, index: args.index });
|
|
13
|
+
}
|
|
14
|
+
setData(tree.data);
|
|
15
|
+
};
|
|
16
|
+
const onRename = ({ name, id }) => {
|
|
17
|
+
tree.update({ id, changes: { name } });
|
|
18
|
+
setData(tree.data);
|
|
19
|
+
};
|
|
20
|
+
const onCreate = ({ parentId, index, type }) => {
|
|
21
|
+
const data = { id: `simple-tree-id-${nextId++}`, name: "" };
|
|
22
|
+
if (type === "internal")
|
|
23
|
+
data.children = [];
|
|
24
|
+
tree.create({ parentId, index, data });
|
|
25
|
+
setData(tree.data);
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
const onDelete = (args) => {
|
|
29
|
+
args.ids.forEach((id) => tree.drop({ id }));
|
|
30
|
+
setData(tree.data);
|
|
31
|
+
};
|
|
32
|
+
const controller = { onMove, onRename, onCreate, onDelete };
|
|
33
|
+
return [data, controller];
|
|
34
|
+
}
|
|
35
|
+
exports.useSimpleTree = useSimpleTree;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useValidatedProps = void 0;
|
|
4
|
+
const use_simple_tree_1 = require("./use-simple-tree");
|
|
5
|
+
function useValidatedProps(props) {
|
|
6
|
+
if (props.initialData && props.data) {
|
|
7
|
+
throw new Error(`React Arborist Tree => Provide either a data or initialData prop, but not both.`);
|
|
8
|
+
}
|
|
9
|
+
if (props.initialData &&
|
|
10
|
+
(props.onCreate || props.onDelete || props.onMove || props.onRename)) {
|
|
11
|
+
throw new Error(`React Arborist Tree => You passed the initialData prop along with a data handler.
|
|
12
|
+
Use the data prop if you want to provide your own handlers.`);
|
|
13
|
+
}
|
|
14
|
+
if (props.initialData) {
|
|
15
|
+
/**
|
|
16
|
+
* Let's break the rules of hooks here. If the initialData prop
|
|
17
|
+
* is provided, we will assume it will not change for the life of
|
|
18
|
+
* the component.
|
|
19
|
+
*
|
|
20
|
+
* We will provide the real data and the handlers to update it.
|
|
21
|
+
* */
|
|
22
|
+
const [data, controller] = (0, use_simple_tree_1.useSimpleTree)(props.initialData);
|
|
23
|
+
return Object.assign(Object.assign(Object.assign({}, props), controller), { data });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return props;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.useValidatedProps = useValidatedProps;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Tree = void 0;
|
|
18
|
+
/* The Public Api */
|
|
19
|
+
var tree_1 = require("./components/tree");
|
|
20
|
+
Object.defineProperty(exports, "Tree", { enumerable: true, get: function () { return tree_1.Tree; } });
|
|
21
|
+
__exportStar(require("./types/handlers"), exports);
|
|
22
|
+
__exportStar(require("./types/renderers"), exports);
|
|
23
|
+
__exportStar(require("./types/state"), exports);
|
|
24
|
+
__exportStar(require("./interfaces/node-api"), exports);
|
|
25
|
+
__exportStar(require("./interfaces/tree-api"), exports);
|
|
26
|
+
__exportStar(require("./data/simple-tree"), exports);
|
|
27
|
+
__exportStar(require("./hooks/use-simple-tree"), exports);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeApi = void 0;
|
|
4
|
+
const create_root_1 = require("../data/create-root");
|
|
5
|
+
class NodeApi {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
this.handleClick = (e) => {
|
|
8
|
+
if (e.metaKey && !this.tree.props.disableMultiSelection) {
|
|
9
|
+
this.isSelected ? this.deselect() : this.selectMulti();
|
|
10
|
+
}
|
|
11
|
+
else if (e.shiftKey && !this.tree.props.disableMultiSelection) {
|
|
12
|
+
this.selectContiguous();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.select();
|
|
16
|
+
this.activate();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
this.tree = params.tree;
|
|
20
|
+
this.id = params.id;
|
|
21
|
+
this.data = params.data;
|
|
22
|
+
this.level = params.level;
|
|
23
|
+
this.children = params.children;
|
|
24
|
+
this.parent = params.parent;
|
|
25
|
+
this.isDraggable = params.isDraggable;
|
|
26
|
+
this.rowIndex = params.rowIndex;
|
|
27
|
+
}
|
|
28
|
+
get isRoot() {
|
|
29
|
+
return this.id === create_root_1.ROOT_ID;
|
|
30
|
+
}
|
|
31
|
+
get isLeaf() {
|
|
32
|
+
return !Array.isArray(this.children);
|
|
33
|
+
}
|
|
34
|
+
get isInternal() {
|
|
35
|
+
return !this.isLeaf;
|
|
36
|
+
}
|
|
37
|
+
get isOpen() {
|
|
38
|
+
return this.isLeaf ? false : this.tree.isOpen(this.id);
|
|
39
|
+
}
|
|
40
|
+
get isClosed() {
|
|
41
|
+
return this.isLeaf ? false : !this.tree.isOpen(this.id);
|
|
42
|
+
}
|
|
43
|
+
get isEditable() {
|
|
44
|
+
return this.tree.isEditable(this.data);
|
|
45
|
+
}
|
|
46
|
+
get isEditing() {
|
|
47
|
+
return this.tree.editingId === this.id;
|
|
48
|
+
}
|
|
49
|
+
get isSelected() {
|
|
50
|
+
return this.tree.isSelected(this.id);
|
|
51
|
+
}
|
|
52
|
+
get isOnlySelection() {
|
|
53
|
+
return this.isSelected && this.tree.hasOneSelection;
|
|
54
|
+
}
|
|
55
|
+
get isSelectedStart() {
|
|
56
|
+
var _a;
|
|
57
|
+
return this.isSelected && !((_a = this.prev) === null || _a === void 0 ? void 0 : _a.isSelected);
|
|
58
|
+
}
|
|
59
|
+
get isSelectedEnd() {
|
|
60
|
+
var _a;
|
|
61
|
+
return this.isSelected && !((_a = this.next) === null || _a === void 0 ? void 0 : _a.isSelected);
|
|
62
|
+
}
|
|
63
|
+
get isFocused() {
|
|
64
|
+
return this.tree.isFocused(this.id);
|
|
65
|
+
}
|
|
66
|
+
get isDragging() {
|
|
67
|
+
return this.tree.isDragging(this.id);
|
|
68
|
+
}
|
|
69
|
+
get willReceiveDrop() {
|
|
70
|
+
return this.tree.willReceiveDrop(this.id);
|
|
71
|
+
}
|
|
72
|
+
get state() {
|
|
73
|
+
return {
|
|
74
|
+
isClosed: this.isClosed,
|
|
75
|
+
isDragging: this.isDragging,
|
|
76
|
+
isEditing: this.isEditing,
|
|
77
|
+
isFocused: this.isFocused,
|
|
78
|
+
isInternal: this.isInternal,
|
|
79
|
+
isLeaf: this.isLeaf,
|
|
80
|
+
isOpen: this.isOpen,
|
|
81
|
+
isSelected: this.isSelected,
|
|
82
|
+
isSelectedEnd: this.isSelectedEnd,
|
|
83
|
+
isSelectedStart: this.isSelectedStart,
|
|
84
|
+
willReceiveDrop: this.willReceiveDrop,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
get childIndex() {
|
|
88
|
+
if (this.parent && this.parent.children) {
|
|
89
|
+
return this.parent.children.findIndex((child) => child.id === this.id);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
get next() {
|
|
96
|
+
if (this.rowIndex === null)
|
|
97
|
+
return null;
|
|
98
|
+
return this.tree.at(this.rowIndex + 1);
|
|
99
|
+
}
|
|
100
|
+
get prev() {
|
|
101
|
+
if (this.rowIndex === null)
|
|
102
|
+
return null;
|
|
103
|
+
return this.tree.at(this.rowIndex - 1);
|
|
104
|
+
}
|
|
105
|
+
get nextSibling() {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const i = this.childIndex;
|
|
108
|
+
return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.children[i + 1]) !== null && _b !== void 0 ? _b : null;
|
|
109
|
+
}
|
|
110
|
+
isAncestorOf(node) {
|
|
111
|
+
if (!node)
|
|
112
|
+
return false;
|
|
113
|
+
let ancestor = node;
|
|
114
|
+
while (ancestor) {
|
|
115
|
+
if (ancestor.id === this.id)
|
|
116
|
+
return true;
|
|
117
|
+
ancestor = ancestor.parent;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
select() {
|
|
122
|
+
this.tree.select(this);
|
|
123
|
+
}
|
|
124
|
+
deselect() {
|
|
125
|
+
this.tree.deselect(this);
|
|
126
|
+
}
|
|
127
|
+
selectMulti() {
|
|
128
|
+
this.tree.selectMulti(this);
|
|
129
|
+
}
|
|
130
|
+
selectContiguous() {
|
|
131
|
+
this.tree.selectContiguous(this);
|
|
132
|
+
}
|
|
133
|
+
activate() {
|
|
134
|
+
this.tree.activate(this);
|
|
135
|
+
}
|
|
136
|
+
focus() {
|
|
137
|
+
this.tree.focus(this);
|
|
138
|
+
}
|
|
139
|
+
toggle() {
|
|
140
|
+
this.tree.toggle(this);
|
|
141
|
+
}
|
|
142
|
+
open() {
|
|
143
|
+
this.tree.open(this);
|
|
144
|
+
}
|
|
145
|
+
openParents() {
|
|
146
|
+
this.tree.openParents(this);
|
|
147
|
+
}
|
|
148
|
+
close() {
|
|
149
|
+
this.tree.close(this);
|
|
150
|
+
}
|
|
151
|
+
submit(value) {
|
|
152
|
+
this.tree.submit(this, value);
|
|
153
|
+
}
|
|
154
|
+
reset() {
|
|
155
|
+
this.tree.reset();
|
|
156
|
+
}
|
|
157
|
+
clone() {
|
|
158
|
+
return new NodeApi(Object.assign({}, this));
|
|
159
|
+
}
|
|
160
|
+
edit() {
|
|
161
|
+
return this.tree.edit(this);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.NodeApi = NodeApi;
|
|
@@ -26,17 +26,97 @@ export declare class TreeApi<T> {
|
|
|
26
26
|
};
|
|
27
27
|
constructor(store: Store<RootState, Actions>, props: TreeProps<T>, list: MutableRefObject<FixedSizeList | null>, listEl: MutableRefObject<HTMLDivElement | null>);
|
|
28
28
|
update(props: TreeProps<T>): void;
|
|
29
|
-
dispatch(action: Actions):
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
dispatch(action: Actions): {
|
|
30
|
+
type: "FOCUS";
|
|
31
|
+
id: string | null;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "TREE_BLUR";
|
|
34
|
+
} | {
|
|
35
|
+
type: "EDIT";
|
|
36
|
+
id: string | null;
|
|
37
|
+
} | import("../types/utils").ActionTypes<{
|
|
38
|
+
open(id: string, filtered: boolean): {
|
|
39
|
+
type: "VISIBILITY_OPEN";
|
|
40
|
+
id: string;
|
|
41
|
+
filtered: boolean;
|
|
42
|
+
};
|
|
43
|
+
close(id: string, filtered: boolean): {
|
|
44
|
+
type: "VISIBILITY_CLOSE";
|
|
45
|
+
id: string;
|
|
46
|
+
filtered: boolean;
|
|
47
|
+
};
|
|
48
|
+
toggle(id: string, filtered: boolean): {
|
|
49
|
+
type: "VISIBILITY_TOGGLE";
|
|
50
|
+
id: string;
|
|
51
|
+
filtered: boolean;
|
|
52
|
+
};
|
|
53
|
+
clear(filtered: boolean): {
|
|
54
|
+
type: "VISIBILITY_CLEAR";
|
|
55
|
+
filtered: boolean;
|
|
56
|
+
};
|
|
57
|
+
}> | import("../types/utils").ActionTypes<{
|
|
58
|
+
clear: () => {
|
|
59
|
+
type: "SELECTION_CLEAR";
|
|
60
|
+
};
|
|
61
|
+
only: (id: string | IdObj) => {
|
|
62
|
+
type: "SELECTION_ONLY";
|
|
63
|
+
id: string;
|
|
64
|
+
};
|
|
65
|
+
add: (id: string | IdObj | string[] | IdObj[]) => {
|
|
66
|
+
type: "SELECTION_ADD";
|
|
67
|
+
ids: string[];
|
|
68
|
+
};
|
|
69
|
+
remove: (id: string | IdObj | string[] | IdObj[]) => {
|
|
70
|
+
type: "SELECTION_REMOVE";
|
|
71
|
+
ids: string[];
|
|
72
|
+
};
|
|
73
|
+
set: (args: {
|
|
74
|
+
ids: Set<string>;
|
|
75
|
+
anchor: string | null;
|
|
76
|
+
mostRecent: string | null;
|
|
77
|
+
}) => {
|
|
78
|
+
ids: Set<string>;
|
|
79
|
+
anchor: string | null;
|
|
80
|
+
mostRecent: string | null;
|
|
81
|
+
type: "SELECTION_SET";
|
|
82
|
+
};
|
|
83
|
+
mostRecent: (id: string | IdObj | null) => {
|
|
84
|
+
type: "SELECTION_MOST_RECENT";
|
|
85
|
+
id: string | null;
|
|
86
|
+
};
|
|
87
|
+
anchor: (id: string | IdObj | null) => {
|
|
88
|
+
type: "SELECTION_ANCHOR";
|
|
89
|
+
id: string | null;
|
|
90
|
+
};
|
|
91
|
+
}> | import("../types/utils").ActionTypes<{
|
|
92
|
+
cursor(cursor: Cursor): {
|
|
93
|
+
type: "DND_CURSOR";
|
|
94
|
+
cursor: Cursor;
|
|
95
|
+
};
|
|
96
|
+
dragStart(id: string, dragIds: string[]): {
|
|
97
|
+
type: "DND_DRAG_START";
|
|
98
|
+
id: string;
|
|
99
|
+
dragIds: string[];
|
|
100
|
+
};
|
|
101
|
+
dragEnd(): {
|
|
102
|
+
type: "DND_DRAG_END";
|
|
103
|
+
};
|
|
104
|
+
hovering(parentId: string | null, index: number | null): {
|
|
105
|
+
type: "DND_HOVERING";
|
|
106
|
+
parentId: string | null;
|
|
107
|
+
index: number | null;
|
|
108
|
+
};
|
|
109
|
+
}>;
|
|
110
|
+
get state(): {
|
|
111
|
+
nodes: {
|
|
32
112
|
focus: import("../state/focus-slice").FocusState;
|
|
33
113
|
edit: import("../state/edit-slice").EditState;
|
|
34
114
|
open: import("../state/open-slice").OpenSlice;
|
|
35
115
|
selection: import("../state/selection-slice").SelectionState;
|
|
36
116
|
drag: import("../state/drag-slice").DragSlice;
|
|
37
|
-
}
|
|
117
|
+
};
|
|
38
118
|
dnd: import("../state/dnd-slice").DndState;
|
|
39
|
-
}
|
|
119
|
+
};
|
|
40
120
|
get openState(): import("../state/open-slice").OpenMap;
|
|
41
121
|
get width(): string | number;
|
|
42
122
|
get height(): number;
|
|
@@ -129,6 +209,6 @@ export declare class TreeApi<T> {
|
|
|
129
209
|
get renderContainer(): import("react").ElementType<{}> | typeof DefaultContainer;
|
|
130
210
|
get renderRow(): import("react").ElementType<import("..").RowRendererProps<T>> | typeof DefaultRow;
|
|
131
211
|
get renderNode(): import("react").ElementType<import("..").NodeRendererProps<T>> | typeof DefaultNode;
|
|
132
|
-
get renderDragPreview(): import("react").
|
|
133
|
-
get renderCursor(): import("react").
|
|
212
|
+
get renderDragPreview(): import("react").ElementType<import("..").DragPreviewProps> | typeof DefaultDragPreview;
|
|
213
|
+
get renderCursor(): import("react").ElementType<import("..").CursorProps> | import("react").NamedExoticComponent<import("..").CursorProps>;
|
|
134
214
|
}
|