@headless-tree/core 0.0.1 → 0.0.2
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/CHANGELOG.md +7 -0
- package/lib/{features → cjs/features}/drag-and-drop/feature.js +0 -46
- package/lib/{features → cjs/features}/drag-and-drop/types.d.ts +1 -1
- package/lib/{features → cjs/features}/drag-and-drop/utils.d.ts +0 -1
- package/lib/{features → cjs/features}/drag-and-drop/utils.js +1 -60
- package/lib/{features → cjs/features}/hotkeys-core/feature.js +0 -1
- package/lib/{features → cjs/features}/tree/feature.js +0 -2
- package/lib/esm/core/create-tree.d.ts +2 -0
- package/lib/esm/core/create-tree.js +112 -0
- package/lib/esm/data-adapters/nested-data-adapter.d.ts +9 -0
- package/lib/esm/data-adapters/nested-data-adapter.js +28 -0
- package/lib/esm/data-adapters/types.d.ts +7 -0
- package/lib/esm/data-adapters/types.js +1 -0
- package/lib/esm/features/async-data-loader/feature.d.ts +5 -0
- package/lib/esm/features/async-data-loader/feature.js +77 -0
- package/lib/esm/features/async-data-loader/types.d.ts +41 -0
- package/lib/esm/features/async-data-loader/types.js +1 -0
- package/lib/esm/features/drag-and-drop/feature.d.ts +3 -0
- package/lib/esm/features/drag-and-drop/feature.js +95 -0
- package/lib/esm/features/drag-and-drop/types.d.ts +49 -0
- package/lib/esm/features/drag-and-drop/types.js +6 -0
- package/lib/esm/features/drag-and-drop/utils.d.ts +6 -0
- package/lib/esm/features/drag-and-drop/utils.js +55 -0
- package/lib/esm/features/expand-all/feature.d.ts +6 -0
- package/lib/esm/features/expand-all/feature.js +36 -0
- package/lib/esm/features/expand-all/types.d.ts +17 -0
- package/lib/esm/features/expand-all/types.js +1 -0
- package/lib/esm/features/hotkeys-core/feature.d.ts +4 -0
- package/lib/esm/features/hotkeys-core/feature.js +69 -0
- package/lib/esm/features/hotkeys-core/types.d.ts +25 -0
- package/lib/esm/features/hotkeys-core/types.js +1 -0
- package/lib/esm/features/main/types.d.ts +36 -0
- package/lib/esm/features/main/types.js +1 -0
- package/lib/esm/features/renaming/feature.d.ts +5 -0
- package/lib/esm/features/renaming/feature.js +62 -0
- package/lib/esm/features/renaming/types.d.ts +27 -0
- package/lib/esm/features/renaming/types.js +1 -0
- package/lib/esm/features/search/feature.d.ts +5 -0
- package/lib/esm/features/search/feature.js +87 -0
- package/lib/esm/features/search/types.d.ts +33 -0
- package/lib/esm/features/search/types.js +1 -0
- package/lib/esm/features/selection/feature.d.ts +5 -0
- package/lib/esm/features/selection/feature.js +109 -0
- package/lib/esm/features/selection/types.d.ts +21 -0
- package/lib/esm/features/selection/types.js +1 -0
- package/lib/esm/features/sync-data-loader/feature.d.ts +4 -0
- package/lib/esm/features/sync-data-loader/feature.js +6 -0
- package/lib/esm/features/sync-data-loader/types.d.ts +19 -0
- package/lib/esm/features/sync-data-loader/types.js +1 -0
- package/lib/esm/features/tree/feature.d.ts +6 -0
- package/lib/esm/features/tree/feature.js +211 -0
- package/lib/esm/features/tree/types.d.ts +57 -0
- package/lib/esm/features/tree/types.js +1 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +21 -0
- package/lib/esm/mddocs-entry.d.ts +21 -0
- package/lib/esm/mddocs-entry.js +1 -0
- package/lib/esm/types/core.d.ts +68 -0
- package/lib/esm/types/core.js +1 -0
- package/lib/esm/types/deep-merge.d.ts +13 -0
- package/lib/esm/types/deep-merge.js +1 -0
- package/lib/esm/utils.d.ts +9 -0
- package/lib/esm/utils.js +96 -0
- package/package.json +11 -4
- package/tsconfig.json +7 -7
- /package/lib/{core → cjs/core}/create-tree.d.ts +0 -0
- /package/lib/{core → cjs/core}/create-tree.js +0 -0
- /package/lib/{data-adapters → cjs/data-adapters}/nested-data-adapter.d.ts +0 -0
- /package/lib/{data-adapters → cjs/data-adapters}/nested-data-adapter.js +0 -0
- /package/lib/{data-adapters → cjs/data-adapters}/types.d.ts +0 -0
- /package/lib/{data-adapters → cjs/data-adapters}/types.js +0 -0
- /package/lib/{features → cjs/features}/async-data-loader/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/async-data-loader/feature.js +0 -0
- /package/lib/{features → cjs/features}/async-data-loader/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/async-data-loader/types.js +0 -0
- /package/lib/{features → cjs/features}/drag-and-drop/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/drag-and-drop/types.js +0 -0
- /package/lib/{features → cjs/features}/expand-all/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/expand-all/feature.js +0 -0
- /package/lib/{features → cjs/features}/expand-all/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/expand-all/types.js +0 -0
- /package/lib/{features → cjs/features}/hotkeys-core/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/hotkeys-core/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/hotkeys-core/types.js +0 -0
- /package/lib/{features → cjs/features}/main/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/main/types.js +0 -0
- /package/lib/{features → cjs/features}/renaming/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/renaming/feature.js +0 -0
- /package/lib/{features → cjs/features}/renaming/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/renaming/types.js +0 -0
- /package/lib/{features → cjs/features}/search/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/search/feature.js +0 -0
- /package/lib/{features → cjs/features}/search/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/search/types.js +0 -0
- /package/lib/{features → cjs/features}/selection/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/selection/feature.js +0 -0
- /package/lib/{features → cjs/features}/selection/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/selection/types.js +0 -0
- /package/lib/{features → cjs/features}/sync-data-loader/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/sync-data-loader/feature.js +0 -0
- /package/lib/{features → cjs/features}/sync-data-loader/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/sync-data-loader/types.js +0 -0
- /package/lib/{features → cjs/features}/tree/feature.d.ts +0 -0
- /package/lib/{features → cjs/features}/tree/types.d.ts +0 -0
- /package/lib/{features → cjs/features}/tree/types.js +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{index.js → cjs/index.js} +0 -0
- /package/lib/{mddocs-entry.d.ts → cjs/mddocs-entry.d.ts} +0 -0
- /package/lib/{mddocs-entry.js → cjs/mddocs-entry.js} +0 -0
- /package/lib/{types → cjs/types}/core.d.ts +0 -0
- /package/lib/{types → cjs/types}/core.js +0 -0
- /package/lib/{types → cjs/types}/deep-merge.d.ts +0 -0
- /package/lib/{types → cjs/types}/deep-merge.js +0 -0
- /package/lib/{utils.d.ts → cjs/utils.d.ts} +0 -0
- /package/lib/{utils.js → cjs/utils.js} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -95,50 +95,4 @@ exports.dragAndDropFeature = {
|
|
|
95
95
|
var _a, _b;
|
|
96
96
|
return ((_b = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggingOverItem) === null || _b === void 0 ? void 0 : _b.getId()) === item.getId();
|
|
97
97
|
} })),
|
|
98
|
-
hotkeys: {
|
|
99
|
-
startDnd: {
|
|
100
|
-
hotkey: "Control+Alt+d",
|
|
101
|
-
handler: (e, tree) => {
|
|
102
|
-
console.log("DRAG");
|
|
103
|
-
tree.getFocusedItem().getProps().onDragStart(e);
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
cancelDnd: {
|
|
107
|
-
hotkey: "Escape",
|
|
108
|
-
isEnabled: (tree) => !!tree.getState().dnd,
|
|
109
|
-
handler: (e, tree) => {
|
|
110
|
-
var _a, _b;
|
|
111
|
-
(_b = (_a = tree.getConfig()).setDndState) === null || _b === void 0 ? void 0 : _b.call(_a, null);
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
completeDnd: {
|
|
115
|
-
hotkey: "Enter",
|
|
116
|
-
isEnabled: (tree) => !!tree.getState().dnd,
|
|
117
|
-
handler: (e, tree) => {
|
|
118
|
-
console.log("DROP");
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
dndDown: {
|
|
122
|
-
preventDefault: true,
|
|
123
|
-
hotkey: "ArrowDown",
|
|
124
|
-
isEnabled: (tree) => !!tree.getState().dnd,
|
|
125
|
-
handler: (e, tree) => {
|
|
126
|
-
var _a, _b;
|
|
127
|
-
const target = (0, utils_1.searchDropTarget)(tree, false);
|
|
128
|
-
console.log("Down", target);
|
|
129
|
-
(_b = (_a = tree.getConfig()).setDndState) === null || _b === void 0 ? void 0 : _b.call(_a, (state) => (Object.assign(Object.assign({}, state), { dragTarget: target !== null && target !== void 0 ? target : undefined })));
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
dndUp: {
|
|
133
|
-
preventDefault: true,
|
|
134
|
-
hotkey: "ArrowUp",
|
|
135
|
-
isEnabled: (tree) => !!tree.getState().dnd,
|
|
136
|
-
handler: (e, tree) => {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
const target = (0, utils_1.searchDropTarget)(tree, true);
|
|
139
|
-
console.log("Up", target);
|
|
140
|
-
(_b = (_a = tree.getConfig()).setDndState) === null || _b === void 0 ? void 0 : _b.call(_a, (state) => (Object.assign(Object.assign({}, state), { dragTarget: target !== null && target !== void 0 ? target : undefined })));
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
98
|
};
|
|
@@ -4,4 +4,3 @@ export declare const getDragCode: ({ item, childIndex }: DropTarget<any>) => str
|
|
|
4
4
|
export declare const getDropOffset: (e: any, item: ItemInstance<any>) => number;
|
|
5
5
|
export declare const canDrop: (dataTransfer: DataTransfer | null, target: DropTarget<any>, tree: TreeInstance<any>) => boolean;
|
|
6
6
|
export declare const getDropTarget: (e: any, item: ItemInstance<any>, tree: TreeInstance<any>) => DropTarget<any>;
|
|
7
|
-
export declare const searchDropTarget: (tree: TreeInstance<any>, upwards?: boolean) => DropTarget<any> | null | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getDropTarget = exports.canDrop = exports.getDropOffset = exports.getDragCode = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const getDragCode = ({ item, childIndex }) => `${item.getId()}__${childIndex !== null && childIndex !== void 0 ? childIndex : "none"}`;
|
|
6
6
|
exports.getDragCode = getDragCode;
|
|
@@ -60,62 +60,3 @@ const getDropTarget = (e, item, tree) => {
|
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
exports.getDropTarget = getDropTarget;
|
|
63
|
-
const searchDropTarget = (tree, upwards = false) => {
|
|
64
|
-
const state = tree.getState().dnd;
|
|
65
|
-
console.log("!", state);
|
|
66
|
-
if (!state || !state.draggingOverItem)
|
|
67
|
-
return null;
|
|
68
|
-
let currentItem = state.draggingOverItem;
|
|
69
|
-
while (currentItem) {
|
|
70
|
-
// const targetAbove: DropTarget<any> = {
|
|
71
|
-
// item: currentItem.getParent(),
|
|
72
|
-
// childIndex: currentItem.getIndexInParent() + (upwards ? -1 : 1),
|
|
73
|
-
// };
|
|
74
|
-
// if (canDrop(null, targetAbove, tree)) {
|
|
75
|
-
// return targetAbove;
|
|
76
|
-
// }
|
|
77
|
-
const itemTarget = {
|
|
78
|
-
item: currentItem,
|
|
79
|
-
childIndex: null,
|
|
80
|
-
};
|
|
81
|
-
if ((0, exports.canDrop)(null, itemTarget, tree)) {
|
|
82
|
-
return itemTarget;
|
|
83
|
-
}
|
|
84
|
-
currentItem = upwards
|
|
85
|
-
? currentItem.getItemAbove()
|
|
86
|
-
: currentItem.getItemBelow();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
exports.searchDropTarget = searchDropTarget;
|
|
90
|
-
/*
|
|
91
|
-
|
|
92
|
-
export const searchDropTarget = (
|
|
93
|
-
tree: TreeInstance<any>,
|
|
94
|
-
backwards = false,
|
|
95
|
-
target = tree.getState().dnd?.dragTarget
|
|
96
|
-
) => {
|
|
97
|
-
const state = tree.getState().dnd;
|
|
98
|
-
if (!state) return null;
|
|
99
|
-
if (target && canDrop(null, target, tree)) return target;
|
|
100
|
-
|
|
101
|
-
if (target?.childIndex && target?.childIndex > 0 && !backwards) {
|
|
102
|
-
return searchDropTarget(tree, backwards, {
|
|
103
|
-
...target,
|
|
104
|
-
childIndex: target.childIndex - 1,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
target?.childIndex &&
|
|
110
|
-
target?.childIndex < target.item.getChildren().length - 1 &&
|
|
111
|
-
backwards
|
|
112
|
-
) {
|
|
113
|
-
return searchDropTarget(tree, backwards, {
|
|
114
|
-
...target,
|
|
115
|
-
childIndex: target.childIndex + 1,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
*/
|
|
@@ -29,7 +29,6 @@ exports.hotkeysCoreFeature = {
|
|
|
29
29
|
(_a = (_c = data.current).pressedKeys) !== null && _a !== void 0 ? _a : (_c.pressedKeys = new Set());
|
|
30
30
|
const newMatch = !data.current.pressedKeys.has(e.key);
|
|
31
31
|
data.current.pressedKeys.add(e.key);
|
|
32
|
-
console.log(data.current.pressedKeys);
|
|
33
32
|
const hotkeyName = findHotkeyMatch(data.current.pressedKeys, tree, tree.getHotkeyPresets(), tree.getConfig().hotkeys);
|
|
34
33
|
if (!hotkeyName)
|
|
35
34
|
return;
|
|
@@ -199,7 +199,6 @@ exports.treeFeature = {
|
|
|
199
199
|
focusFirstItem: {
|
|
200
200
|
hotkey: "Home",
|
|
201
201
|
handler: (e, tree) => {
|
|
202
|
-
console.log("home", tree.getItems()[0], tree.getItems());
|
|
203
202
|
tree.focusItem(tree.getItems()[0].getId());
|
|
204
203
|
tree.updateDomFocus();
|
|
205
204
|
},
|
|
@@ -207,7 +206,6 @@ exports.treeFeature = {
|
|
|
207
206
|
focusLastItem: {
|
|
208
207
|
hotkey: "End",
|
|
209
208
|
handler: (e, tree) => {
|
|
210
|
-
console.log("end");
|
|
211
209
|
tree.focusItem(tree.getItems()[tree.getItems().length - 1].getId());
|
|
212
210
|
tree.updateDomFocus();
|
|
213
211
|
},
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { treeFeature } from "../features/tree/feature";
|
|
2
|
+
const buildItemInstance = (features, tree, itemId) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const itemInstance = {};
|
|
5
|
+
for (const feature of features) {
|
|
6
|
+
Object.assign(itemInstance, (_b = (_a = feature.createItemInstance) === null || _a === void 0 ? void 0 : _a.call(feature, Object.assign({}, itemInstance), itemInstance, tree, itemId)) !== null && _b !== void 0 ? _b : {});
|
|
7
|
+
}
|
|
8
|
+
return itemInstance;
|
|
9
|
+
};
|
|
10
|
+
export const createTree = (initialConfig) => {
|
|
11
|
+
var _a, _b, _c, _d, _e;
|
|
12
|
+
const treeInstance = {};
|
|
13
|
+
const additionalFeatures = [treeFeature, ...((_a = initialConfig.features) !== null && _a !== void 0 ? _a : [])];
|
|
14
|
+
let state = additionalFeatures.reduce((acc, feature) => { var _a, _b; return (_b = (_a = feature.getInitialState) === null || _a === void 0 ? void 0 : _a.call(feature, acc, treeInstance)) !== null && _b !== void 0 ? _b : acc; }, (_b = initialConfig.state) !== null && _b !== void 0 ? _b : {});
|
|
15
|
+
let config = additionalFeatures.reduce((acc, feature) => { var _a, _b; return (_b = (_a = feature.getDefaultConfig) === null || _a === void 0 ? void 0 : _a.call(feature, acc, treeInstance)) !== null && _b !== void 0 ? _b : acc; }, initialConfig);
|
|
16
|
+
let treeElement;
|
|
17
|
+
const treeDataRef = { current: {} };
|
|
18
|
+
const itemInstancesMap = {};
|
|
19
|
+
let itemInstances = [];
|
|
20
|
+
const itemElementsMap = {};
|
|
21
|
+
const itemDataRefs = {};
|
|
22
|
+
let itemMetaMap = {};
|
|
23
|
+
const hotkeyPresets = {};
|
|
24
|
+
const rebuildItemMeta = (main) => {
|
|
25
|
+
// TODO can we find a way to only run this for the changed substructure?
|
|
26
|
+
itemInstances = [];
|
|
27
|
+
itemMetaMap = {};
|
|
28
|
+
const rootInstance = buildItemInstance([main, ...additionalFeatures], treeInstance, config.rootItemId);
|
|
29
|
+
itemInstancesMap[config.rootItemId] = rootInstance;
|
|
30
|
+
itemMetaMap[config.rootItemId] = {
|
|
31
|
+
itemId: config.rootItemId,
|
|
32
|
+
index: -1,
|
|
33
|
+
parentId: null,
|
|
34
|
+
level: -1,
|
|
35
|
+
posInSet: 0,
|
|
36
|
+
setSize: 1,
|
|
37
|
+
};
|
|
38
|
+
for (const item of treeInstance.getItemsMeta()) {
|
|
39
|
+
itemMetaMap[item.itemId] = item;
|
|
40
|
+
if (!itemInstancesMap[item.itemId]) {
|
|
41
|
+
const instance = buildItemInstance([main, ...additionalFeatures], treeInstance, item.itemId);
|
|
42
|
+
itemInstancesMap[item.itemId] = instance;
|
|
43
|
+
itemInstances.push(instance);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
itemInstances.push(itemInstancesMap[item.itemId]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
console.log("REBUILT");
|
|
50
|
+
};
|
|
51
|
+
const eachFeature = (fn) => {
|
|
52
|
+
for (const feature of additionalFeatures) {
|
|
53
|
+
fn(feature);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const mainFeature = {
|
|
57
|
+
key: "main",
|
|
58
|
+
createTreeInstance: (prev) => (Object.assign(Object.assign({}, prev), { getState: () => state, setState: (updater) => {
|
|
59
|
+
var _a;
|
|
60
|
+
state = typeof updater === "function" ? updater(state) : updater;
|
|
61
|
+
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
62
|
+
eachFeature((feature) => { var _a; return (_a = feature.setState) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance); });
|
|
63
|
+
eachFeature((feature) => { var _a; return (_a = feature.onStateOrConfigChange) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance); });
|
|
64
|
+
}, rebuildTree: () => {
|
|
65
|
+
var _a;
|
|
66
|
+
rebuildItemMeta(mainFeature);
|
|
67
|
+
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
68
|
+
}, getConfig: () => config, setConfig: (updater) => {
|
|
69
|
+
config = typeof updater === "function" ? updater(config) : updater;
|
|
70
|
+
if (config.state) {
|
|
71
|
+
state = Object.assign(Object.assign({}, state), config.state);
|
|
72
|
+
eachFeature((feature) => { var _a; return (_a = feature.setState) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance); });
|
|
73
|
+
}
|
|
74
|
+
eachFeature((feature) => { var _a; return (_a = feature.onConfigChange) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance); });
|
|
75
|
+
eachFeature((feature) => { var _a; return (_a = feature.onStateOrConfigChange) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance); });
|
|
76
|
+
}, getItemInstance: (itemId) => itemInstancesMap[itemId], getItems: () => itemInstances, registerElement: (element) => {
|
|
77
|
+
if (treeElement === element) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (treeElement && !element) {
|
|
81
|
+
eachFeature((feature) => { var _a; return (_a = feature.onTreeUnmount) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance, treeElement); });
|
|
82
|
+
}
|
|
83
|
+
else if (!treeElement && element) {
|
|
84
|
+
eachFeature((feature) => { var _a; return (_a = feature.onTreeMount) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance, element); });
|
|
85
|
+
}
|
|
86
|
+
treeElement = element;
|
|
87
|
+
}, getElement: () => treeElement, getDataRef: () => treeDataRef, getHotkeyPresets: () => hotkeyPresets })),
|
|
88
|
+
createItemInstance: (prev, instance, _, itemId) => (Object.assign(Object.assign({}, prev), { registerElement: (element) => {
|
|
89
|
+
if (itemElementsMap[itemId] === element) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const oldElement = itemElementsMap[itemId];
|
|
93
|
+
if (oldElement && !element) {
|
|
94
|
+
eachFeature((feature) => { var _a; return (_a = feature.onItemUnmount) === null || _a === void 0 ? void 0 : _a.call(feature, instance, oldElement, treeInstance); });
|
|
95
|
+
}
|
|
96
|
+
else if (!oldElement && element) {
|
|
97
|
+
eachFeature((feature) => { var _a; return (_a = feature.onItemMount) === null || _a === void 0 ? void 0 : _a.call(feature, instance, element, treeInstance); });
|
|
98
|
+
}
|
|
99
|
+
itemElementsMap[itemId] = element;
|
|
100
|
+
}, getElement: () => itemElementsMap[itemId],
|
|
101
|
+
// eslint-disable-next-line no-return-assign
|
|
102
|
+
getDataRef: () => { var _a; return ((_a = itemDataRefs[itemId]) !== null && _a !== void 0 ? _a : (itemDataRefs[itemId] = { current: {} })); }, getItemMeta: () => itemMetaMap[itemId] })),
|
|
103
|
+
};
|
|
104
|
+
// todo sort features
|
|
105
|
+
const features = [mainFeature, ...additionalFeatures];
|
|
106
|
+
for (const feature of features) {
|
|
107
|
+
Object.assign(treeInstance, (_d = (_c = feature.createTreeInstance) === null || _c === void 0 ? void 0 : _c.call(feature, Object.assign({}, treeInstance), treeInstance)) !== null && _d !== void 0 ? _d : {});
|
|
108
|
+
Object.assign(hotkeyPresets, (_e = feature.hotkeys) !== null && _e !== void 0 ? _e : {});
|
|
109
|
+
}
|
|
110
|
+
rebuildItemMeta(mainFeature);
|
|
111
|
+
return treeInstance;
|
|
112
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataAdapterConfig } from "./types";
|
|
2
|
+
interface NestedDataAdapterProps<T> {
|
|
3
|
+
rootItem: T;
|
|
4
|
+
getItemId: (item: T) => string;
|
|
5
|
+
getChildren: (item: T) => T[] | undefined;
|
|
6
|
+
changeChildren?: (item: T, children: T[]) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const nestedDataAdapter: <T = any>(props: NestedDataAdapterProps<T>) => DataAdapterConfig<T>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { performItemsMove } from "../utils";
|
|
2
|
+
const createItemMap = (props, item, map = {}) => {
|
|
3
|
+
var _a;
|
|
4
|
+
map[props.getItemId(item)] = item;
|
|
5
|
+
(_a = props.getChildren(item)) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
|
|
6
|
+
createItemMap(props, child, map);
|
|
7
|
+
});
|
|
8
|
+
return map;
|
|
9
|
+
};
|
|
10
|
+
export const nestedDataAdapter = (props) => {
|
|
11
|
+
const itemMap = createItemMap(props, props.rootItem);
|
|
12
|
+
return {
|
|
13
|
+
rootItemId: props.getItemId(props.rootItem),
|
|
14
|
+
dataLoader: {
|
|
15
|
+
getItem: (itemId) => itemMap[itemId],
|
|
16
|
+
getChildren: (itemId) => { var _a, _b; return (_b = (_a = props.getChildren(itemMap[itemId])) === null || _a === void 0 ? void 0 : _a.map(props.getItemId)) !== null && _b !== void 0 ? _b : []; },
|
|
17
|
+
},
|
|
18
|
+
onDrop: (items, target) => {
|
|
19
|
+
if (!props.changeChildren) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
performItemsMove(items, target, (item, newChildren) => {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = props.changeChildren) === null || _a === void 0 ? void 0 : _a.call(props, item.getItemData(), newChildren.map((child) => child.getItemData()));
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DragAndDropFeatureDef } from "../features/drag-and-drop/types";
|
|
2
|
+
import { SyncDataLoaderFeatureDef } from "../features/sync-data-loader/types";
|
|
3
|
+
export type DataAdapterConfig<T> = {
|
|
4
|
+
rootItemId: SyncDataLoaderFeatureDef<T>["config"]["rootItemId"];
|
|
5
|
+
dataLoader: SyncDataLoaderFeatureDef<T>["config"]["dataLoader"];
|
|
6
|
+
onDrop: DragAndDropFeatureDef<T>["config"]["onDrop"];
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FeatureImplementation } from "../../types/core";
|
|
2
|
+
import { AsyncDataLoaderFeatureDef } from "./types";
|
|
3
|
+
import { MainFeatureDef } from "../main/types";
|
|
4
|
+
import { TreeFeatureDef } from "../tree/types";
|
|
5
|
+
export declare const asyncDataLoaderFeature: FeatureImplementation<any, AsyncDataLoaderFeatureDef<any>, MainFeatureDef | TreeFeatureDef<any> | AsyncDataLoaderFeatureDef<any>>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { makeStateUpdater } from "../../utils";
|
|
2
|
+
export const asyncDataLoaderFeature = {
|
|
3
|
+
key: "async-data-loader",
|
|
4
|
+
dependingFeatures: ["main"],
|
|
5
|
+
getInitialState: (initialState) => (Object.assign({ loadingItems: [] }, initialState)),
|
|
6
|
+
getDefaultConfig: (defaultConfig, tree) => (Object.assign({ setLoadingItems: makeStateUpdater("loadingItems", tree) }, defaultConfig)),
|
|
7
|
+
createTreeInstance: (prev, instance) => (Object.assign(Object.assign({}, prev), { retrieveItemData: (itemId) => {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f;
|
|
9
|
+
var _g, _h;
|
|
10
|
+
const config = instance.getConfig();
|
|
11
|
+
const dataRef = instance.getDataRef();
|
|
12
|
+
(_a = (_g = dataRef.current).itemData) !== null && _a !== void 0 ? _a : (_g.itemData = {});
|
|
13
|
+
(_b = (_h = dataRef.current).childrenIds) !== null && _b !== void 0 ? _b : (_h.childrenIds = {});
|
|
14
|
+
if (dataRef.current.itemData[itemId]) {
|
|
15
|
+
return dataRef.current.itemData[itemId];
|
|
16
|
+
}
|
|
17
|
+
if (!instance.getState().loadingItems.includes(itemId)) {
|
|
18
|
+
(_c = config.setLoadingItems) === null || _c === void 0 ? void 0 : _c.call(config, (loadingItems) => [...loadingItems, itemId]);
|
|
19
|
+
(_d = config.asyncDataLoader) === null || _d === void 0 ? void 0 : _d.getItem(itemId).then((item) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
dataRef.current.itemData[itemId] = item;
|
|
22
|
+
(_a = config.onLoadedItem) === null || _a === void 0 ? void 0 : _a.call(config, itemId, item);
|
|
23
|
+
(_b = config.setLoadingItems) === null || _b === void 0 ? void 0 : _b.call(config, (loadingItems) => loadingItems.filter((id) => id !== itemId));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return (_f = (_e = config.createLoadingItemData) === null || _e === void 0 ? void 0 : _e.call(config)) !== null && _f !== void 0 ? _f : null;
|
|
27
|
+
}, retrieveChildrenIds: (itemId) => {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
29
|
+
var _g, _h;
|
|
30
|
+
const config = instance.getConfig();
|
|
31
|
+
const dataRef = instance.getDataRef();
|
|
32
|
+
(_a = (_g = dataRef.current).itemData) !== null && _a !== void 0 ? _a : (_g.itemData = {});
|
|
33
|
+
(_b = (_h = dataRef.current).childrenIds) !== null && _b !== void 0 ? _b : (_h.childrenIds = {});
|
|
34
|
+
if (dataRef.current.childrenIds[itemId]) {
|
|
35
|
+
return dataRef.current.childrenIds[itemId];
|
|
36
|
+
}
|
|
37
|
+
if (instance.getState().loadingItems.includes(itemId)) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
(_c = config.setLoadingItems) === null || _c === void 0 ? void 0 : _c.call(config, (loadingItems) => [...loadingItems, itemId]);
|
|
41
|
+
if ((_d = config.asyncDataLoader) === null || _d === void 0 ? void 0 : _d.getChildrenWithData) {
|
|
42
|
+
(_e = config.asyncDataLoader) === null || _e === void 0 ? void 0 : _e.getChildrenWithData(itemId).then((children) => {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
for (const { id, data } of children) {
|
|
45
|
+
dataRef.current.itemData[id] = data;
|
|
46
|
+
(_a = config.onLoadedItem) === null || _a === void 0 ? void 0 : _a.call(config, id, data);
|
|
47
|
+
}
|
|
48
|
+
const childrenIds = children.map(({ id }) => id);
|
|
49
|
+
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
50
|
+
(_b = config.onLoadedChildren) === null || _b === void 0 ? void 0 : _b.call(config, itemId, childrenIds);
|
|
51
|
+
(_c = config.setLoadingItems) === null || _c === void 0 ? void 0 : _c.call(config, (loadingItems) => loadingItems.filter((id) => id !== itemId));
|
|
52
|
+
instance.rebuildTree();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
(_f = config.asyncDataLoader) === null || _f === void 0 ? void 0 : _f.getChildren(itemId).then((childrenIds) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
59
|
+
(_a = config.onLoadedChildren) === null || _a === void 0 ? void 0 : _a.call(config, itemId, childrenIds);
|
|
60
|
+
(_b = config.setLoadingItems) === null || _b === void 0 ? void 0 : _b.call(config, (loadingItems) => loadingItems.filter((id) => id !== itemId));
|
|
61
|
+
instance.rebuildTree();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
}, invalidateItemData: (itemId) => {
|
|
66
|
+
var _a;
|
|
67
|
+
const dataRef = instance.getDataRef();
|
|
68
|
+
(_a = dataRef.current.itemData) === null || _a === void 0 ? true : delete _a[itemId];
|
|
69
|
+
instance.retrieveItemData(itemId);
|
|
70
|
+
}, invalidateChildrenIds: (itemId) => {
|
|
71
|
+
var _a;
|
|
72
|
+
const dataRef = instance.getDataRef();
|
|
73
|
+
(_a = dataRef.current.childrenIds) === null || _a === void 0 ? true : delete _a[itemId];
|
|
74
|
+
instance.retrieveChildrenIds(itemId);
|
|
75
|
+
} })),
|
|
76
|
+
createItemInstance: (prev, item, tree) => (Object.assign(Object.assign({}, prev), { isLoading: () => tree.getState().loadingItems.includes(item.getItemMeta().itemId), invalidateItemData: () => tree.invalidateItemData(item.getItemMeta().itemId), invalidateChildrenIds: () => tree.invalidateChildrenIds(item.getItemMeta().itemId) })),
|
|
77
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SetStateFn } from "../../types/core";
|
|
2
|
+
import { SyncDataLoaderFeatureDef } from "../sync-data-loader/types";
|
|
3
|
+
export type AsyncTreeDataLoader<T> = {
|
|
4
|
+
getItem: (itemId: string) => Promise<T>;
|
|
5
|
+
getChildren: (itemId: string) => Promise<string[]>;
|
|
6
|
+
getChildrenWithData?: (itemId: string) => Promise<{
|
|
7
|
+
id: string;
|
|
8
|
+
data: T;
|
|
9
|
+
}[]>;
|
|
10
|
+
};
|
|
11
|
+
export type AsyncDataLoaderRef<T = any> = {
|
|
12
|
+
itemData: Record<string, T>;
|
|
13
|
+
childrenIds: Record<string, string[]>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @category Async Data Loader/General
|
|
17
|
+
* */
|
|
18
|
+
export type AsyncDataLoaderFeatureDef<T> = {
|
|
19
|
+
state: {
|
|
20
|
+
loadingItems: string[];
|
|
21
|
+
};
|
|
22
|
+
config: {
|
|
23
|
+
rootItemId: string;
|
|
24
|
+
createLoadingItemData?: () => T;
|
|
25
|
+
setLoadingItems?: SetStateFn<string[]>;
|
|
26
|
+
onLoadedItem?: (itemId: string, item: T) => void;
|
|
27
|
+
onLoadedChildren?: (itemId: string, childrenIds: string[]) => void;
|
|
28
|
+
asyncDataLoader?: AsyncTreeDataLoader<T>;
|
|
29
|
+
};
|
|
30
|
+
treeInstance: SyncDataLoaderFeatureDef<T>["treeInstance"] & {
|
|
31
|
+
/** Invalidate fetched data for item, and triggers a refetch and subsequent rerender if the item is visible */
|
|
32
|
+
invalidateItemData: (itemId: string) => void;
|
|
33
|
+
invalidateChildrenIds: (itemId: string) => void;
|
|
34
|
+
};
|
|
35
|
+
itemInstance: SyncDataLoaderFeatureDef<T>["itemInstance"] & {
|
|
36
|
+
invalidateItemData: () => void;
|
|
37
|
+
invalidateChildrenIds: () => void;
|
|
38
|
+
isLoading: () => void;
|
|
39
|
+
};
|
|
40
|
+
hotkeys: SyncDataLoaderFeatureDef<T>["hotkeys"];
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { canDrop, getDragCode, getDropTarget } from "./utils";
|
|
2
|
+
import { makeStateUpdater } from "../../utils";
|
|
3
|
+
export const dragAndDropFeature = {
|
|
4
|
+
key: "dragAndDrop",
|
|
5
|
+
dependingFeatures: ["main", "tree", "selection"],
|
|
6
|
+
getDefaultConfig: (defaultConfig, tree) => (Object.assign({ canDrop: (_, target) => target.item.isFolder(), setDndState: makeStateUpdater("dnd", tree) }, defaultConfig)),
|
|
7
|
+
createTreeInstance: (prev, tree) => (Object.assign(Object.assign({}, prev), { getDropTarget: () => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
return (_b = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.dragTarget) !== null && _b !== void 0 ? _b : null;
|
|
10
|
+
} })),
|
|
11
|
+
createItemInstance: (prev, item, tree) => (Object.assign(Object.assign({}, prev), { getProps: () => {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
return (Object.assign(Object.assign({}, prev.getProps()), { draggable: (_c = (_b = (_a = tree.getConfig()).isItemDraggable) === null || _b === void 0 ? void 0 : _b.call(_a, item)) !== null && _c !== void 0 ? _c : true, onDragStart: (e) => {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
15
|
+
const selectedItems = tree.getSelectedItems();
|
|
16
|
+
const items = selectedItems.includes(item) ? selectedItems : [item];
|
|
17
|
+
const config = tree.getConfig();
|
|
18
|
+
if (!selectedItems.includes(item)) {
|
|
19
|
+
tree.setSelectedItems([item.getItemMeta().itemId]);
|
|
20
|
+
}
|
|
21
|
+
if (!((_b = (_a = config.canDrag) === null || _a === void 0 ? void 0 : _a.call(config, items)) !== null && _b !== void 0 ? _b : true)) {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (config.createForeignDragObject) {
|
|
26
|
+
const { format, data } = config.createForeignDragObject(items);
|
|
27
|
+
(_c = e.dataTransfer) === null || _c === void 0 ? void 0 : _c.setData(format, data);
|
|
28
|
+
}
|
|
29
|
+
(_e = (_d = tree.getConfig()).setDndState) === null || _e === void 0 ? void 0 : _e.call(_d, {
|
|
30
|
+
draggedItems: items,
|
|
31
|
+
draggingOverItem: tree.getFocusedItem(),
|
|
32
|
+
});
|
|
33
|
+
}, onDragOver: (e) => {
|
|
34
|
+
var _a, _b, _c, _d, _e;
|
|
35
|
+
const target = getDropTarget(e, item, tree);
|
|
36
|
+
const dataRef = tree.getDataRef();
|
|
37
|
+
if (!((_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggedItems) &&
|
|
38
|
+
!((_c = (_b = tree.getConfig()).canDropForeignDragObject) === null || _c === void 0 ? void 0 : _c.call(_b, e.dataTransfer, target))) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!canDrop(e.dataTransfer, target, tree)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
const nextDragCode = getDragCode(target);
|
|
46
|
+
if (nextDragCode === dataRef.current.lastDragCode) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
dataRef.current.lastDragCode = nextDragCode;
|
|
50
|
+
(_e = (_d = tree.getConfig()).setDndState) === null || _e === void 0 ? void 0 : _e.call(_d, (state) => (Object.assign(Object.assign({}, state), { dragTarget: target, draggingOverItem: item })));
|
|
51
|
+
}, onDragLeave: () => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const dataRef = tree.getDataRef();
|
|
54
|
+
dataRef.current.lastDragCode = "no-drag";
|
|
55
|
+
(_b = (_a = tree.getConfig()).setDndState) === null || _b === void 0 ? void 0 : _b.call(_a, (state) => (Object.assign(Object.assign({}, state), { draggingOverItem: undefined, dragTarget: undefined })));
|
|
56
|
+
}, onDrop: (e) => {
|
|
57
|
+
var _a, _b, _c, _d, _e;
|
|
58
|
+
const dataRef = tree.getDataRef();
|
|
59
|
+
const target = getDropTarget(e, item, tree);
|
|
60
|
+
if (!canDrop(e.dataTransfer, target, tree)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
const config = tree.getConfig();
|
|
65
|
+
const draggedItems = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggedItems;
|
|
66
|
+
dataRef.current.lastDragCode = undefined;
|
|
67
|
+
(_c = (_b = tree.getConfig()).setDndState) === null || _c === void 0 ? void 0 : _c.call(_b, null);
|
|
68
|
+
if (draggedItems) {
|
|
69
|
+
(_d = config.onDrop) === null || _d === void 0 ? void 0 : _d.call(config, draggedItems, target);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
(_e = config.onDropForeignDragObject) === null || _e === void 0 ? void 0 : _e.call(config, e.dataTransfer, target);
|
|
73
|
+
}
|
|
74
|
+
// TODO rebuild tree?
|
|
75
|
+
} }));
|
|
76
|
+
}, isDropTarget: () => {
|
|
77
|
+
const target = tree.getDropTarget();
|
|
78
|
+
return target ? target.item.getId() === item.getId() : false;
|
|
79
|
+
}, isDropTargetAbove: () => {
|
|
80
|
+
const target = tree.getDropTarget();
|
|
81
|
+
if (!target || target.childIndex === null)
|
|
82
|
+
return false;
|
|
83
|
+
const targetIndex = target.item.getItemMeta().index;
|
|
84
|
+
return targetIndex + target.childIndex + 1 === item.getItemMeta().index;
|
|
85
|
+
}, isDropTargetBelow: () => {
|
|
86
|
+
const target = tree.getDropTarget();
|
|
87
|
+
if (!target || target.childIndex === null)
|
|
88
|
+
return false;
|
|
89
|
+
const targetIndex = target.item.getItemMeta().index;
|
|
90
|
+
return targetIndex + target.childIndex === item.getItemMeta().index;
|
|
91
|
+
}, isDraggingOver: () => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
return ((_b = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggingOverItem) === null || _b === void 0 ? void 0 : _b.getId()) === item.getId();
|
|
94
|
+
} })),
|
|
95
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ItemInstance, SetStateFn } from "../../types/core";
|
|
2
|
+
export type DndDataRef = {
|
|
3
|
+
lastDragCode?: string;
|
|
4
|
+
};
|
|
5
|
+
export type DndState<T> = {
|
|
6
|
+
draggedItems?: ItemInstance<T>[];
|
|
7
|
+
draggingOverItem?: ItemInstance<T>;
|
|
8
|
+
dragTarget?: DropTarget<T>;
|
|
9
|
+
};
|
|
10
|
+
export type DropTarget<T> = {
|
|
11
|
+
item: ItemInstance<T>;
|
|
12
|
+
childIndex: number | null;
|
|
13
|
+
};
|
|
14
|
+
export declare enum DropTargetPosition {
|
|
15
|
+
Top = "top",
|
|
16
|
+
Bottom = "bottom",
|
|
17
|
+
Item = "item"
|
|
18
|
+
}
|
|
19
|
+
export type DragAndDropFeatureDef<T> = {
|
|
20
|
+
state: {
|
|
21
|
+
dnd?: DndState<T> | null;
|
|
22
|
+
};
|
|
23
|
+
config: {
|
|
24
|
+
setDndState?: SetStateFn<DndState<T> | null>;
|
|
25
|
+
topLinePercentage?: number;
|
|
26
|
+
bottomLinePercentage?: number;
|
|
27
|
+
canDropInbetween?: boolean;
|
|
28
|
+
isItemDraggable?: (item: ItemInstance<T>) => boolean;
|
|
29
|
+
canDrag?: (items: ItemInstance<T>[]) => boolean;
|
|
30
|
+
canDrop?: (items: ItemInstance<T>[], target: DropTarget<T>) => boolean;
|
|
31
|
+
createForeignDragObject?: (items: ItemInstance<T>[]) => {
|
|
32
|
+
format: string;
|
|
33
|
+
data: any;
|
|
34
|
+
};
|
|
35
|
+
canDropForeignDragObject?: (dataTransfer: DataTransfer, target: DropTarget<T>) => boolean;
|
|
36
|
+
onDrop?: (items: ItemInstance<T>[], target: DropTarget<T>) => void;
|
|
37
|
+
onDropForeignDragObject?: (dataTransfer: DataTransfer, target: DropTarget<T>) => void;
|
|
38
|
+
};
|
|
39
|
+
treeInstance: {
|
|
40
|
+
getDropTarget: () => DropTarget<T> | null;
|
|
41
|
+
};
|
|
42
|
+
itemInstance: {
|
|
43
|
+
isDropTarget: () => boolean;
|
|
44
|
+
isDropTargetAbove: () => boolean;
|
|
45
|
+
isDropTargetBelow: () => boolean;
|
|
46
|
+
isDraggingOver: () => boolean;
|
|
47
|
+
};
|
|
48
|
+
hotkeys: never;
|
|
49
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ItemInstance, TreeInstance } from "../../types/core";
|
|
2
|
+
import { DropTarget } from "./types";
|
|
3
|
+
export declare const getDragCode: ({ item, childIndex }: DropTarget<any>) => string;
|
|
4
|
+
export declare const getDropOffset: (e: any, item: ItemInstance<any>) => number;
|
|
5
|
+
export declare const canDrop: (dataTransfer: DataTransfer | null, target: DropTarget<any>, tree: TreeInstance<any>) => boolean;
|
|
6
|
+
export declare const getDropTarget: (e: any, item: ItemInstance<any>, tree: TreeInstance<any>) => DropTarget<any>;
|