@headless-tree/core 1.2.0 → 1.3.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/CHANGELOG.md +27 -0
- package/dist/index.d.mts +577 -0
- package/dist/index.d.ts +577 -0
- package/dist/index.js +2321 -0
- package/dist/index.mjs +2276 -0
- package/package.json +18 -10
- package/src/core/create-tree.ts +26 -2
- package/src/features/async-data-loader/feature.ts +9 -4
- package/src/features/async-data-loader/types.ts +2 -0
- package/src/features/checkboxes/checkboxes.spec.ts +149 -0
- package/src/features/checkboxes/feature.ts +134 -0
- package/src/features/checkboxes/types.ts +29 -0
- package/src/features/drag-and-drop/drag-and-drop.spec.ts +11 -2
- package/src/features/drag-and-drop/feature.ts +88 -17
- package/src/features/drag-and-drop/types.ts +22 -0
- package/src/features/keyboard-drag-and-drop/feature.ts +8 -1
- package/src/features/keyboard-drag-and-drop/keyboard-drag-and-drop.spec.ts +34 -3
- package/src/features/sync-data-loader/feature.ts +5 -1
- package/src/features/tree/feature.ts +9 -3
- package/src/features/tree/tree.spec.ts +14 -4
- package/src/features/tree/types.ts +3 -2
- package/src/index.ts +2 -0
- package/src/test-utils/test-tree-do.ts +2 -0
- package/src/test-utils/test-tree.ts +1 -0
- package/src/types/core.ts +2 -0
- package/tsconfig.json +1 -4
- package/vitest.config.ts +3 -1
- package/lib/cjs/core/build-proxified-instance.d.ts +0 -2
- package/lib/cjs/core/build-proxified-instance.js +0 -58
- package/lib/cjs/core/build-static-instance.d.ts +0 -2
- package/lib/cjs/core/build-static-instance.js +0 -26
- package/lib/cjs/core/create-tree.d.ts +0 -2
- package/lib/cjs/core/create-tree.js +0 -182
- package/lib/cjs/features/async-data-loader/feature.d.ts +0 -2
- package/lib/cjs/features/async-data-loader/feature.js +0 -135
- package/lib/cjs/features/async-data-loader/types.d.ts +0 -47
- package/lib/cjs/features/async-data-loader/types.js +0 -2
- package/lib/cjs/features/drag-and-drop/feature.d.ts +0 -2
- package/lib/cjs/features/drag-and-drop/feature.js +0 -179
- package/lib/cjs/features/drag-and-drop/types.d.ts +0 -66
- package/lib/cjs/features/drag-and-drop/types.js +0 -9
- package/lib/cjs/features/drag-and-drop/utils.d.ts +0 -27
- package/lib/cjs/features/drag-and-drop/utils.js +0 -182
- package/lib/cjs/features/expand-all/feature.d.ts +0 -2
- package/lib/cjs/features/expand-all/feature.js +0 -70
- package/lib/cjs/features/expand-all/types.d.ts +0 -19
- package/lib/cjs/features/expand-all/types.js +0 -2
- package/lib/cjs/features/hotkeys-core/feature.d.ts +0 -2
- package/lib/cjs/features/hotkeys-core/feature.js +0 -107
- package/lib/cjs/features/hotkeys-core/types.d.ts +0 -27
- package/lib/cjs/features/hotkeys-core/types.js +0 -2
- package/lib/cjs/features/keyboard-drag-and-drop/feature.d.ts +0 -2
- package/lib/cjs/features/keyboard-drag-and-drop/feature.js +0 -206
- package/lib/cjs/features/keyboard-drag-and-drop/types.d.ts +0 -27
- package/lib/cjs/features/keyboard-drag-and-drop/types.js +0 -11
- package/lib/cjs/features/main/types.d.ts +0 -45
- package/lib/cjs/features/main/types.js +0 -2
- package/lib/cjs/features/prop-memoization/feature.d.ts +0 -2
- package/lib/cjs/features/prop-memoization/feature.js +0 -70
- package/lib/cjs/features/prop-memoization/types.d.ts +0 -15
- package/lib/cjs/features/prop-memoization/types.js +0 -2
- package/lib/cjs/features/renaming/feature.d.ts +0 -2
- package/lib/cjs/features/renaming/feature.js +0 -86
- package/lib/cjs/features/renaming/types.d.ts +0 -27
- package/lib/cjs/features/renaming/types.js +0 -2
- package/lib/cjs/features/search/feature.d.ts +0 -2
- package/lib/cjs/features/search/feature.js +0 -119
- package/lib/cjs/features/search/types.d.ts +0 -32
- package/lib/cjs/features/search/types.js +0 -2
- package/lib/cjs/features/selection/feature.d.ts +0 -2
- package/lib/cjs/features/selection/feature.js +0 -132
- package/lib/cjs/features/selection/types.d.ts +0 -21
- package/lib/cjs/features/selection/types.js +0 -2
- package/lib/cjs/features/sync-data-loader/feature.d.ts +0 -2
- package/lib/cjs/features/sync-data-loader/feature.js +0 -49
- package/lib/cjs/features/sync-data-loader/types.d.ts +0 -28
- package/lib/cjs/features/sync-data-loader/types.js +0 -2
- package/lib/cjs/features/tree/feature.d.ts +0 -2
- package/lib/cjs/features/tree/feature.js +0 -240
- package/lib/cjs/features/tree/types.d.ts +0 -62
- package/lib/cjs/features/tree/types.js +0 -2
- package/lib/cjs/index.d.ts +0 -31
- package/lib/cjs/index.js +0 -49
- package/lib/cjs/mddocs-entry.d.ts +0 -121
- package/lib/cjs/mddocs-entry.js +0 -17
- package/lib/cjs/test-utils/test-tree-do.d.ts +0 -23
- package/lib/cjs/test-utils/test-tree-do.js +0 -112
- package/lib/cjs/test-utils/test-tree-expect.d.ts +0 -17
- package/lib/cjs/test-utils/test-tree-expect.js +0 -66
- package/lib/cjs/test-utils/test-tree.d.ts +0 -48
- package/lib/cjs/test-utils/test-tree.js +0 -207
- package/lib/cjs/types/core.d.ts +0 -83
- package/lib/cjs/types/core.js +0 -2
- package/lib/cjs/types/deep-merge.d.ts +0 -13
- package/lib/cjs/types/deep-merge.js +0 -2
- package/lib/cjs/utilities/create-on-drop-handler.d.ts +0 -3
- package/lib/cjs/utilities/create-on-drop-handler.js +0 -20
- package/lib/cjs/utilities/errors.d.ts +0 -2
- package/lib/cjs/utilities/errors.js +0 -9
- package/lib/cjs/utilities/insert-items-at-target.d.ts +0 -3
- package/lib/cjs/utilities/insert-items-at-target.js +0 -40
- package/lib/cjs/utilities/remove-items-from-parents.d.ts +0 -2
- package/lib/cjs/utilities/remove-items-from-parents.js +0 -32
- package/lib/cjs/utils.d.ts +0 -6
- package/lib/cjs/utils.js +0 -53
- package/lib/esm/core/build-proxified-instance.d.ts +0 -2
- package/lib/esm/core/build-proxified-instance.js +0 -54
- package/lib/esm/core/build-static-instance.d.ts +0 -2
- package/lib/esm/core/build-static-instance.js +0 -22
- package/lib/esm/core/create-tree.d.ts +0 -2
- package/lib/esm/core/create-tree.js +0 -178
- package/lib/esm/features/async-data-loader/feature.d.ts +0 -2
- package/lib/esm/features/async-data-loader/feature.js +0 -132
- package/lib/esm/features/async-data-loader/types.d.ts +0 -47
- package/lib/esm/features/async-data-loader/types.js +0 -1
- package/lib/esm/features/drag-and-drop/feature.d.ts +0 -2
- package/lib/esm/features/drag-and-drop/feature.js +0 -176
- package/lib/esm/features/drag-and-drop/types.d.ts +0 -66
- package/lib/esm/features/drag-and-drop/types.js +0 -6
- package/lib/esm/features/drag-and-drop/utils.d.ts +0 -27
- package/lib/esm/features/drag-and-drop/utils.js +0 -172
- package/lib/esm/features/expand-all/feature.d.ts +0 -2
- package/lib/esm/features/expand-all/feature.js +0 -67
- package/lib/esm/features/expand-all/types.d.ts +0 -19
- package/lib/esm/features/expand-all/types.js +0 -1
- package/lib/esm/features/hotkeys-core/feature.d.ts +0 -2
- package/lib/esm/features/hotkeys-core/feature.js +0 -104
- package/lib/esm/features/hotkeys-core/types.d.ts +0 -27
- package/lib/esm/features/hotkeys-core/types.js +0 -1
- package/lib/esm/features/keyboard-drag-and-drop/feature.d.ts +0 -2
- package/lib/esm/features/keyboard-drag-and-drop/feature.js +0 -203
- package/lib/esm/features/keyboard-drag-and-drop/types.d.ts +0 -27
- package/lib/esm/features/keyboard-drag-and-drop/types.js +0 -8
- package/lib/esm/features/main/types.d.ts +0 -45
- package/lib/esm/features/main/types.js +0 -1
- package/lib/esm/features/prop-memoization/feature.d.ts +0 -2
- package/lib/esm/features/prop-memoization/feature.js +0 -67
- package/lib/esm/features/prop-memoization/types.d.ts +0 -15
- package/lib/esm/features/prop-memoization/types.js +0 -1
- package/lib/esm/features/renaming/feature.d.ts +0 -2
- package/lib/esm/features/renaming/feature.js +0 -83
- package/lib/esm/features/renaming/types.d.ts +0 -27
- package/lib/esm/features/renaming/types.js +0 -1
- package/lib/esm/features/search/feature.d.ts +0 -2
- package/lib/esm/features/search/feature.js +0 -116
- package/lib/esm/features/search/types.d.ts +0 -32
- package/lib/esm/features/search/types.js +0 -1
- package/lib/esm/features/selection/feature.d.ts +0 -2
- package/lib/esm/features/selection/feature.js +0 -129
- package/lib/esm/features/selection/types.d.ts +0 -21
- package/lib/esm/features/selection/types.js +0 -1
- package/lib/esm/features/sync-data-loader/feature.d.ts +0 -2
- package/lib/esm/features/sync-data-loader/feature.js +0 -46
- package/lib/esm/features/sync-data-loader/types.d.ts +0 -28
- package/lib/esm/features/sync-data-loader/types.js +0 -1
- package/lib/esm/features/tree/feature.d.ts +0 -2
- package/lib/esm/features/tree/feature.js +0 -237
- package/lib/esm/features/tree/types.d.ts +0 -62
- package/lib/esm/features/tree/types.js +0 -1
- package/lib/esm/index.d.ts +0 -31
- package/lib/esm/index.js +0 -30
- package/lib/esm/mddocs-entry.d.ts +0 -121
- package/lib/esm/mddocs-entry.js +0 -1
- package/lib/esm/test-utils/test-tree-do.d.ts +0 -23
- package/lib/esm/test-utils/test-tree-do.js +0 -108
- package/lib/esm/test-utils/test-tree-expect.d.ts +0 -17
- package/lib/esm/test-utils/test-tree-expect.js +0 -62
- package/lib/esm/test-utils/test-tree.d.ts +0 -48
- package/lib/esm/test-utils/test-tree.js +0 -203
- package/lib/esm/types/core.d.ts +0 -83
- package/lib/esm/types/core.js +0 -1
- package/lib/esm/types/deep-merge.d.ts +0 -13
- package/lib/esm/types/deep-merge.js +0 -1
- package/lib/esm/utilities/create-on-drop-handler.d.ts +0 -3
- package/lib/esm/utilities/create-on-drop-handler.js +0 -16
- package/lib/esm/utilities/errors.d.ts +0 -2
- package/lib/esm/utilities/errors.js +0 -4
- package/lib/esm/utilities/insert-items-at-target.d.ts +0 -3
- package/lib/esm/utilities/insert-items-at-target.js +0 -36
- package/lib/esm/utilities/remove-items-from-parents.d.ts +0 -2
- package/lib/esm/utilities/remove-items-from-parents.js +0 -28
- package/lib/esm/utils.d.ts +0 -6
- package/lib/esm/utils.js +0 -46
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTree = void 0;
|
|
4
|
-
const feature_1 = require("../features/tree/feature");
|
|
5
|
-
const build_static_instance_1 = require("./build-static-instance");
|
|
6
|
-
const errors_1 = require("../utilities/errors");
|
|
7
|
-
const verifyFeatures = (features) => {
|
|
8
|
-
var _a;
|
|
9
|
-
const loadedFeatures = features === null || features === void 0 ? void 0 : features.map((feature) => feature.key);
|
|
10
|
-
for (const feature of features !== null && features !== void 0 ? features : []) {
|
|
11
|
-
const missingDependency = (_a = feature.deps) === null || _a === void 0 ? void 0 : _a.find((dep) => !(loadedFeatures === null || loadedFeatures === void 0 ? void 0 : loadedFeatures.includes(dep)));
|
|
12
|
-
if (missingDependency) {
|
|
13
|
-
throw (0, errors_1.throwError)(`${feature.key} needs ${missingDependency}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
// Check all possible pairs and sort the array
|
|
18
|
-
const exhaustiveSort = (arr, compareFn) => {
|
|
19
|
-
const n = arr.length;
|
|
20
|
-
for (let i = 0; i < n; i++) {
|
|
21
|
-
for (let j = i + 1; j < n; j++) {
|
|
22
|
-
if (compareFn(arr[j], arr[i]) < 0) {
|
|
23
|
-
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return arr;
|
|
28
|
-
};
|
|
29
|
-
const compareFeatures = (originalOrder) => (feature1, feature2) => {
|
|
30
|
-
var _a, _b;
|
|
31
|
-
if (feature2.key && ((_a = feature1.overwrites) === null || _a === void 0 ? void 0 : _a.includes(feature2.key))) {
|
|
32
|
-
return 1;
|
|
33
|
-
}
|
|
34
|
-
if (feature1.key && ((_b = feature2.overwrites) === null || _b === void 0 ? void 0 : _b.includes(feature1.key))) {
|
|
35
|
-
return -1;
|
|
36
|
-
}
|
|
37
|
-
return originalOrder.indexOf(feature1) - originalOrder.indexOf(feature2);
|
|
38
|
-
};
|
|
39
|
-
const sortFeatures = (features = []) => exhaustiveSort(features, compareFeatures(features));
|
|
40
|
-
const createTree = (initialConfig) => {
|
|
41
|
-
var _a, _b, _c, _d;
|
|
42
|
-
const buildInstance = (_a = initialConfig.instanceBuilder) !== null && _a !== void 0 ? _a : build_static_instance_1.buildStaticInstance;
|
|
43
|
-
const additionalFeatures = [
|
|
44
|
-
feature_1.treeFeature,
|
|
45
|
-
...sortFeatures(initialConfig.features),
|
|
46
|
-
];
|
|
47
|
-
verifyFeatures(additionalFeatures);
|
|
48
|
-
const features = [...additionalFeatures];
|
|
49
|
-
const [treeInstance, finalizeTree] = buildInstance(features, "treeInstance", (tree) => ({ tree }));
|
|
50
|
-
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; }, (_c = (_b = initialConfig.initialState) !== null && _b !== void 0 ? _b : initialConfig.state) !== null && _c !== void 0 ? _c : {});
|
|
51
|
-
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);
|
|
52
|
-
const stateHandlerNames = additionalFeatures.reduce((acc, feature) => (Object.assign(Object.assign({}, acc), feature.stateHandlerNames)), {});
|
|
53
|
-
let treeElement;
|
|
54
|
-
const treeDataRef = { current: {} };
|
|
55
|
-
const itemInstancesMap = {};
|
|
56
|
-
let itemInstances = [];
|
|
57
|
-
const itemElementsMap = {};
|
|
58
|
-
const itemDataRefs = {};
|
|
59
|
-
let itemMetaMap = {};
|
|
60
|
-
const hotkeyPresets = {};
|
|
61
|
-
const rebuildItemMeta = () => {
|
|
62
|
-
// TODO can we find a way to only run this for the changed substructure?
|
|
63
|
-
itemInstances = [];
|
|
64
|
-
itemMetaMap = {};
|
|
65
|
-
const [rootInstance, finalizeRootInstance] = buildInstance(features, "itemInstance", (item) => ({ item, tree: treeInstance, itemId: config.rootItemId }));
|
|
66
|
-
finalizeRootInstance();
|
|
67
|
-
itemInstancesMap[config.rootItemId] = rootInstance;
|
|
68
|
-
itemMetaMap[config.rootItemId] = {
|
|
69
|
-
itemId: config.rootItemId,
|
|
70
|
-
index: -1,
|
|
71
|
-
parentId: null,
|
|
72
|
-
level: -1,
|
|
73
|
-
posInSet: 0,
|
|
74
|
-
setSize: 1,
|
|
75
|
-
};
|
|
76
|
-
for (const item of treeInstance.getItemsMeta()) {
|
|
77
|
-
itemMetaMap[item.itemId] = item;
|
|
78
|
-
if (!itemInstancesMap[item.itemId]) {
|
|
79
|
-
const [instance, finalizeInstance] = buildInstance(features, "itemInstance", (instance) => ({
|
|
80
|
-
item: instance,
|
|
81
|
-
tree: treeInstance,
|
|
82
|
-
itemId: item.itemId,
|
|
83
|
-
}));
|
|
84
|
-
finalizeInstance();
|
|
85
|
-
itemInstancesMap[item.itemId] = instance;
|
|
86
|
-
itemInstances.push(instance);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
itemInstances.push(itemInstancesMap[item.itemId]);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const eachFeature = (fn) => {
|
|
94
|
-
for (const feature of additionalFeatures) {
|
|
95
|
-
fn(feature);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const mainFeature = {
|
|
99
|
-
key: "main",
|
|
100
|
-
treeInstance: {
|
|
101
|
-
getState: () => state,
|
|
102
|
-
setState: ({}, updater) => {
|
|
103
|
-
var _a;
|
|
104
|
-
// Not necessary, since I think the subupdate below keeps the state fresh anyways?
|
|
105
|
-
// state = typeof updater === "function" ? updater(state) : updater;
|
|
106
|
-
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state); // TODO this cant be right... This doesnt allow external state updates
|
|
107
|
-
// TODO this is never used, remove
|
|
108
|
-
},
|
|
109
|
-
applySubStateUpdate: ({}, stateName, updater) => {
|
|
110
|
-
state[stateName] =
|
|
111
|
-
typeof updater === "function" ? updater(state[stateName]) : updater;
|
|
112
|
-
const externalStateSetter = config[stateHandlerNames[stateName]];
|
|
113
|
-
externalStateSetter === null || externalStateSetter === void 0 ? void 0 : externalStateSetter(state[stateName]);
|
|
114
|
-
},
|
|
115
|
-
// TODO rebuildSubTree: (itemId: string) => void;
|
|
116
|
-
rebuildTree: () => {
|
|
117
|
-
var _a;
|
|
118
|
-
rebuildItemMeta();
|
|
119
|
-
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
120
|
-
},
|
|
121
|
-
getConfig: () => config,
|
|
122
|
-
setConfig: (_, updater) => {
|
|
123
|
-
var _a, _b, _c;
|
|
124
|
-
const newConfig = typeof updater === "function" ? updater(config) : updater;
|
|
125
|
-
const hasChangedExpandedItems = ((_a = newConfig.state) === null || _a === void 0 ? void 0 : _a.expandedItems) &&
|
|
126
|
-
((_b = newConfig.state) === null || _b === void 0 ? void 0 : _b.expandedItems) !== state.expandedItems;
|
|
127
|
-
config = newConfig;
|
|
128
|
-
if (newConfig.state) {
|
|
129
|
-
state = Object.assign(Object.assign({}, state), newConfig.state);
|
|
130
|
-
}
|
|
131
|
-
if (hasChangedExpandedItems) {
|
|
132
|
-
// if expanded items where changed from the outside
|
|
133
|
-
rebuildItemMeta();
|
|
134
|
-
(_c = config.setState) === null || _c === void 0 ? void 0 : _c.call(config, state);
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
getItemInstance: ({}, itemId) => itemInstancesMap[itemId],
|
|
138
|
-
getItems: () => itemInstances,
|
|
139
|
-
registerElement: ({}, element) => {
|
|
140
|
-
if (treeElement === element) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (treeElement && !element) {
|
|
144
|
-
eachFeature((feature) => { var _a; return (_a = feature.onTreeUnmount) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance, treeElement); });
|
|
145
|
-
}
|
|
146
|
-
else if (!treeElement && element) {
|
|
147
|
-
eachFeature((feature) => { var _a; return (_a = feature.onTreeMount) === null || _a === void 0 ? void 0 : _a.call(feature, treeInstance, element); });
|
|
148
|
-
}
|
|
149
|
-
treeElement = element;
|
|
150
|
-
},
|
|
151
|
-
getElement: () => treeElement,
|
|
152
|
-
getDataRef: () => treeDataRef,
|
|
153
|
-
getHotkeyPresets: () => hotkeyPresets,
|
|
154
|
-
},
|
|
155
|
-
itemInstance: {
|
|
156
|
-
registerElement: ({ itemId, item }, element) => {
|
|
157
|
-
if (itemElementsMap[itemId] === element) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const oldElement = itemElementsMap[itemId];
|
|
161
|
-
if (oldElement && !element) {
|
|
162
|
-
eachFeature((feature) => { var _a; return (_a = feature.onItemUnmount) === null || _a === void 0 ? void 0 : _a.call(feature, item, oldElement, treeInstance); });
|
|
163
|
-
}
|
|
164
|
-
else if (!oldElement && element) {
|
|
165
|
-
eachFeature((feature) => { var _a; return (_a = feature.onItemMount) === null || _a === void 0 ? void 0 : _a.call(feature, item, element, treeInstance); });
|
|
166
|
-
}
|
|
167
|
-
itemElementsMap[itemId] = element;
|
|
168
|
-
},
|
|
169
|
-
getElement: ({ itemId }) => itemElementsMap[itemId],
|
|
170
|
-
// eslint-disable-next-line no-return-assign
|
|
171
|
-
getDataRef: ({ itemId }) => { var _a; return ((_a = itemDataRefs[itemId]) !== null && _a !== void 0 ? _a : (itemDataRefs[itemId] = { current: {} })); },
|
|
172
|
-
getItemMeta: ({ itemId }) => itemMetaMap[itemId],
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
features.unshift(mainFeature);
|
|
176
|
-
for (const feature of features) {
|
|
177
|
-
Object.assign(hotkeyPresets, (_d = feature.hotkeys) !== null && _d !== void 0 ? _d : {});
|
|
178
|
-
}
|
|
179
|
-
finalizeTree();
|
|
180
|
-
return treeInstance;
|
|
181
|
-
};
|
|
182
|
-
exports.createTree = createTree;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.asyncDataLoaderFeature = void 0;
|
|
13
|
-
const utils_1 = require("../../utils");
|
|
14
|
-
const getDataRef = (tree) => {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
var _c, _d;
|
|
17
|
-
const dataRef = tree.getDataRef();
|
|
18
|
-
(_a = (_c = dataRef.current).itemData) !== null && _a !== void 0 ? _a : (_c.itemData = {});
|
|
19
|
-
(_b = (_d = dataRef.current).childrenIds) !== null && _b !== void 0 ? _b : (_d.childrenIds = {});
|
|
20
|
-
return dataRef;
|
|
21
|
-
};
|
|
22
|
-
const loadItemData = (tree, itemId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
var _a;
|
|
24
|
-
const config = tree.getConfig();
|
|
25
|
-
const dataRef = getDataRef(tree);
|
|
26
|
-
const item = yield config.dataLoader.getItem(itemId);
|
|
27
|
-
dataRef.current.itemData[itemId] = item;
|
|
28
|
-
(_a = config.onLoadedItem) === null || _a === void 0 ? void 0 : _a.call(config, itemId, item);
|
|
29
|
-
tree.applySubStateUpdate("loadingItemData", (loadingItemData) => loadingItemData.filter((id) => id !== itemId));
|
|
30
|
-
return item;
|
|
31
|
-
});
|
|
32
|
-
const loadChildrenIds = (tree, itemId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
const config = tree.getConfig();
|
|
35
|
-
const dataRef = getDataRef(tree);
|
|
36
|
-
let childrenIds;
|
|
37
|
-
if ("getChildrenWithData" in config.dataLoader) {
|
|
38
|
-
const children = yield config.dataLoader.getChildrenWithData(itemId);
|
|
39
|
-
childrenIds = children.map((c) => c.id);
|
|
40
|
-
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
41
|
-
children.forEach(({ id, data }) => {
|
|
42
|
-
var _a;
|
|
43
|
-
dataRef.current.itemData[id] = data;
|
|
44
|
-
(_a = config.onLoadedItem) === null || _a === void 0 ? void 0 : _a.call(config, id, data);
|
|
45
|
-
});
|
|
46
|
-
(_a = config.onLoadedChildren) === null || _a === void 0 ? void 0 : _a.call(config, itemId, childrenIds);
|
|
47
|
-
tree.rebuildTree();
|
|
48
|
-
tree.applySubStateUpdate("loadingItemData", (loadingItemData) => loadingItemData.filter((id) => !childrenIds.includes(id)));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
childrenIds = yield config.dataLoader.getChildren(itemId);
|
|
52
|
-
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
53
|
-
(_b = config.onLoadedChildren) === null || _b === void 0 ? void 0 : _b.call(config, itemId, childrenIds);
|
|
54
|
-
tree.rebuildTree();
|
|
55
|
-
}
|
|
56
|
-
tree.applySubStateUpdate("loadingItemChildrens", (loadingItemChildrens) => loadingItemChildrens.filter((id) => id !== itemId));
|
|
57
|
-
return childrenIds;
|
|
58
|
-
});
|
|
59
|
-
exports.asyncDataLoaderFeature = {
|
|
60
|
-
key: "async-data-loader",
|
|
61
|
-
getInitialState: (initialState) => (Object.assign({ loadingItemData: [], loadingItemChildrens: [] }, initialState)),
|
|
62
|
-
getDefaultConfig: (defaultConfig, tree) => (Object.assign({ setLoadingItemData: (0, utils_1.makeStateUpdater)("loadingItemData", tree), setLoadingItemChildrens: (0, utils_1.makeStateUpdater)("loadingItemChildrens", tree) }, defaultConfig)),
|
|
63
|
-
stateHandlerNames: {
|
|
64
|
-
loadingItemData: "setLoadingItemData",
|
|
65
|
-
loadingItemChildrens: "setLoadingItemChildrens",
|
|
66
|
-
},
|
|
67
|
-
treeInstance: {
|
|
68
|
-
waitForItemDataLoaded: ({ tree }, itemId) => tree.loadItemData(itemId),
|
|
69
|
-
waitForItemChildrenLoaded: ({ tree }, itemId) => tree.loadChildrenIds(itemId),
|
|
70
|
-
loadItemData: (_a, itemId_1) => __awaiter(void 0, [_a, itemId_1], void 0, function* ({ tree }, itemId) {
|
|
71
|
-
var _b;
|
|
72
|
-
return ((_b = getDataRef(tree).current.itemData[itemId]) !== null && _b !== void 0 ? _b : (yield loadItemData(tree, itemId)));
|
|
73
|
-
}),
|
|
74
|
-
loadChildrenIds: (_a, itemId_1) => __awaiter(void 0, [_a, itemId_1], void 0, function* ({ tree }, itemId) {
|
|
75
|
-
var _b;
|
|
76
|
-
return ((_b = getDataRef(tree).current.childrenIds[itemId]) !== null && _b !== void 0 ? _b : (yield loadChildrenIds(tree, itemId)));
|
|
77
|
-
}),
|
|
78
|
-
retrieveItemData: ({ tree }, itemId) => {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
const config = tree.getConfig();
|
|
81
|
-
const dataRef = getDataRef(tree);
|
|
82
|
-
if (dataRef.current.itemData[itemId]) {
|
|
83
|
-
return dataRef.current.itemData[itemId];
|
|
84
|
-
}
|
|
85
|
-
if (!tree.getState().loadingItemData.includes(itemId)) {
|
|
86
|
-
tree.applySubStateUpdate("loadingItemData", (loadingItemData) => [
|
|
87
|
-
...loadingItemData,
|
|
88
|
-
itemId,
|
|
89
|
-
]);
|
|
90
|
-
loadItemData(tree, itemId);
|
|
91
|
-
}
|
|
92
|
-
return (_b = (_a = config.createLoadingItemData) === null || _a === void 0 ? void 0 : _a.call(config)) !== null && _b !== void 0 ? _b : null;
|
|
93
|
-
},
|
|
94
|
-
retrieveChildrenIds: ({ tree }, itemId) => {
|
|
95
|
-
const dataRef = getDataRef(tree);
|
|
96
|
-
if (dataRef.current.childrenIds[itemId]) {
|
|
97
|
-
return dataRef.current.childrenIds[itemId];
|
|
98
|
-
}
|
|
99
|
-
if (tree.getState().loadingItemChildrens.includes(itemId)) {
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
tree.applySubStateUpdate("loadingItemChildrens", (loadingItemChildrens) => [...loadingItemChildrens, itemId]);
|
|
103
|
-
loadChildrenIds(tree, itemId);
|
|
104
|
-
return [];
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
itemInstance: {
|
|
108
|
-
isLoading: ({ tree, item }) => tree.getState().loadingItemData.includes(item.getItemMeta().itemId) ||
|
|
109
|
-
tree.getState().loadingItemChildrens.includes(item.getItemMeta().itemId),
|
|
110
|
-
invalidateItemData: (_a, optimistic_1) => __awaiter(void 0, [_a, optimistic_1], void 0, function* ({ tree, itemId }, optimistic) {
|
|
111
|
-
var _b;
|
|
112
|
-
if (!optimistic) {
|
|
113
|
-
(_b = getDataRef(tree).current.itemData) === null || _b === void 0 ? true : delete _b[itemId];
|
|
114
|
-
tree.applySubStateUpdate("loadingItemData", (loadingItemData) => [
|
|
115
|
-
...loadingItemData,
|
|
116
|
-
itemId,
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
yield loadItemData(tree, itemId);
|
|
120
|
-
}),
|
|
121
|
-
invalidateChildrenIds: (_a, optimistic_1) => __awaiter(void 0, [_a, optimistic_1], void 0, function* ({ tree, itemId }, optimistic) {
|
|
122
|
-
var _b;
|
|
123
|
-
if (!optimistic) {
|
|
124
|
-
(_b = getDataRef(tree).current.childrenIds) === null || _b === void 0 ? true : delete _b[itemId];
|
|
125
|
-
tree.applySubStateUpdate("loadingItemChildrens", (loadingItemChildrens) => [...loadingItemChildrens, itemId]);
|
|
126
|
-
}
|
|
127
|
-
yield loadChildrenIds(tree, itemId);
|
|
128
|
-
}),
|
|
129
|
-
updateCachedChildrenIds: ({ tree, itemId }, childrenIds) => {
|
|
130
|
-
const dataRef = tree.getDataRef();
|
|
131
|
-
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
132
|
-
tree.rebuildTree();
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { SetStateFn } from "../../types/core";
|
|
2
|
-
import { SyncDataLoaderFeatureDef } from "../sync-data-loader/types";
|
|
3
|
-
export interface AsyncDataLoaderDataRef<T = any> {
|
|
4
|
-
itemData: Record<string, T>;
|
|
5
|
-
childrenIds: Record<string, string[]>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @category Async Data Loader/General
|
|
9
|
-
* */
|
|
10
|
-
export type AsyncDataLoaderFeatureDef<T> = {
|
|
11
|
-
state: {
|
|
12
|
-
loadingItemData: string[];
|
|
13
|
-
loadingItemChildrens: string[];
|
|
14
|
-
};
|
|
15
|
-
config: {
|
|
16
|
-
rootItemId: string;
|
|
17
|
-
/** Will be called when HT retrieves item data for an item whose item data is asynchronously being loaded.
|
|
18
|
-
* Can be used to create placeholder data to use for rendering the tree item while it is loaded. If not defined,
|
|
19
|
-
* the tree item data will be null. */
|
|
20
|
-
createLoadingItemData?: () => T;
|
|
21
|
-
setLoadingItemData?: SetStateFn<string[]>;
|
|
22
|
-
setLoadingItemChildrens?: SetStateFn<string[]>;
|
|
23
|
-
onLoadedItem?: (itemId: string, item: T) => void;
|
|
24
|
-
onLoadedChildren?: (itemId: string, childrenIds: string[]) => void;
|
|
25
|
-
};
|
|
26
|
-
treeInstance: SyncDataLoaderFeatureDef<T>["treeInstance"] & {
|
|
27
|
-
/** @deprecated use loadItemData instead */
|
|
28
|
-
waitForItemDataLoaded: (itemId: string) => Promise<void>;
|
|
29
|
-
/** @deprecated use loadChildrenIds instead */
|
|
30
|
-
waitForItemChildrenLoaded: (itemId: string) => Promise<void>;
|
|
31
|
-
loadItemData: (itemId: string) => Promise<T>;
|
|
32
|
-
loadChildrenIds: (itemId: string) => Promise<string[]>;
|
|
33
|
-
};
|
|
34
|
-
itemInstance: SyncDataLoaderFeatureDef<T>["itemInstance"] & {
|
|
35
|
-
/** Invalidate fetched data for item, and triggers a refetch and subsequent rerender if the item is visible
|
|
36
|
-
* @param optimistic If true, the item will not trigger a state update on `loadingItemData`, and
|
|
37
|
-
* the tree will continue to display the old data until the new data has loaded. */
|
|
38
|
-
invalidateItemData: (optimistic?: boolean) => Promise<void>;
|
|
39
|
-
/** Invalidate fetched children ids for item, and triggers a refetch and subsequent rerender if the item is visible
|
|
40
|
-
* @param optimistic If true, the item will not trigger a state update on `loadingItemChildrens`, and
|
|
41
|
-
* the tree will continue to display the old data until the new data has loaded. */
|
|
42
|
-
invalidateChildrenIds: (optimistic?: boolean) => Promise<void>;
|
|
43
|
-
updateCachedChildrenIds: (childrenIds: string[]) => void;
|
|
44
|
-
isLoading: () => boolean;
|
|
45
|
-
};
|
|
46
|
-
hotkeys: SyncDataLoaderFeatureDef<T>["hotkeys"];
|
|
47
|
-
};
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.dragAndDropFeature = void 0;
|
|
13
|
-
const utils_1 = require("./utils");
|
|
14
|
-
const utils_2 = require("../../utils");
|
|
15
|
-
exports.dragAndDropFeature = {
|
|
16
|
-
key: "drag-and-drop",
|
|
17
|
-
deps: ["selection"],
|
|
18
|
-
getDefaultConfig: (defaultConfig, tree) => (Object.assign({ canDrop: (_, target) => target.item.isFolder(), canDropForeignDragObject: () => false, setDndState: (0, utils_2.makeStateUpdater)("dnd", tree), canReorder: true }, defaultConfig)),
|
|
19
|
-
stateHandlerNames: {
|
|
20
|
-
dnd: "setDndState",
|
|
21
|
-
},
|
|
22
|
-
treeInstance: {
|
|
23
|
-
getDragTarget: ({ tree }) => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
return (_b = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.dragTarget) !== null && _b !== void 0 ? _b : null;
|
|
26
|
-
},
|
|
27
|
-
getDragLineData: ({ tree }) => {
|
|
28
|
-
var _a, _b, _c, _d, _e, _f;
|
|
29
|
-
const target = tree.getDragTarget();
|
|
30
|
-
const indent = ((_a = target === null || target === void 0 ? void 0 : target.item.getItemMeta().level) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
31
|
-
const treeBb = (_b = tree.getElement()) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
|
|
32
|
-
if (!target || !treeBb || !(0, utils_1.isOrderedDragTarget)(target))
|
|
33
|
-
return null;
|
|
34
|
-
const leftOffset = target.dragLineLevel * ((_c = tree.getConfig().indent) !== null && _c !== void 0 ? _c : 1);
|
|
35
|
-
const targetItem = tree.getItems()[target.dragLineIndex];
|
|
36
|
-
if (!targetItem) {
|
|
37
|
-
const bb = (_e = (_d = tree
|
|
38
|
-
.getItems()[target.dragLineIndex - 1]) === null || _d === void 0 ? void 0 : _d.getElement()) === null || _e === void 0 ? void 0 : _e.getBoundingClientRect();
|
|
39
|
-
if (bb) {
|
|
40
|
-
return {
|
|
41
|
-
indent,
|
|
42
|
-
top: bb.bottom - treeBb.top,
|
|
43
|
-
left: bb.left + leftOffset - treeBb.left,
|
|
44
|
-
width: bb.width - leftOffset,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const bb = (_f = targetItem.getElement()) === null || _f === void 0 ? void 0 : _f.getBoundingClientRect();
|
|
49
|
-
if (bb) {
|
|
50
|
-
return {
|
|
51
|
-
indent,
|
|
52
|
-
top: bb.top - treeBb.top,
|
|
53
|
-
left: bb.left + leftOffset - treeBb.left,
|
|
54
|
-
width: bb.width - leftOffset,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
},
|
|
59
|
-
getDragLineStyle: ({ tree }, topOffset = -1, leftOffset = -8) => {
|
|
60
|
-
const dragLine = tree.getDragLineData();
|
|
61
|
-
return dragLine
|
|
62
|
-
? {
|
|
63
|
-
position: "absolute",
|
|
64
|
-
top: `${dragLine.top + topOffset}px`,
|
|
65
|
-
left: `${dragLine.left + leftOffset}px`,
|
|
66
|
-
width: `${dragLine.width - leftOffset}px`,
|
|
67
|
-
pointerEvents: "none", // important to prevent capturing drag events
|
|
68
|
-
}
|
|
69
|
-
: { display: "none" };
|
|
70
|
-
},
|
|
71
|
-
getContainerProps: ({ prev }, treeLabel) => {
|
|
72
|
-
const prevProps = prev === null || prev === void 0 ? void 0 : prev(treeLabel);
|
|
73
|
-
return Object.assign(Object.assign({}, prevProps), { style: Object.assign(Object.assign({}, prevProps === null || prevProps === void 0 ? void 0 : prevProps.style), { position: "relative" }) });
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
itemInstance: {
|
|
77
|
-
getProps: ({ tree, item, prev }) => (Object.assign(Object.assign({}, prev === null || prev === void 0 ? void 0 : prev()), { draggable: true, onDragStart: (e) => {
|
|
78
|
-
var _a, _b, _c;
|
|
79
|
-
const selectedItems = tree.getSelectedItems();
|
|
80
|
-
const items = selectedItems.includes(item) ? selectedItems : [item];
|
|
81
|
-
const config = tree.getConfig();
|
|
82
|
-
if (!selectedItems.includes(item)) {
|
|
83
|
-
tree.setSelectedItems([item.getItemMeta().itemId]);
|
|
84
|
-
}
|
|
85
|
-
if (!((_b = (_a = config.canDrag) === null || _a === void 0 ? void 0 : _a.call(config, items)) !== null && _b !== void 0 ? _b : true)) {
|
|
86
|
-
e.preventDefault();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (config.createForeignDragObject) {
|
|
90
|
-
const { format, data } = config.createForeignDragObject(items);
|
|
91
|
-
(_c = e.dataTransfer) === null || _c === void 0 ? void 0 : _c.setData(format, data);
|
|
92
|
-
}
|
|
93
|
-
tree.applySubStateUpdate("dnd", {
|
|
94
|
-
draggedItems: items,
|
|
95
|
-
draggingOverItem: tree.getFocusedItem(),
|
|
96
|
-
});
|
|
97
|
-
}, onDragOver: (e) => {
|
|
98
|
-
var _a, _b, _c;
|
|
99
|
-
const dataRef = tree.getDataRef();
|
|
100
|
-
const nextDragCode = (0, utils_1.getDragCode)(e, item, tree);
|
|
101
|
-
if (nextDragCode === dataRef.current.lastDragCode) {
|
|
102
|
-
if (dataRef.current.lastAllowDrop) {
|
|
103
|
-
e.preventDefault();
|
|
104
|
-
}
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
dataRef.current.lastDragCode = nextDragCode;
|
|
108
|
-
const target = (0, utils_1.getDragTarget)(e, item, tree);
|
|
109
|
-
if (!((_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggedItems) &&
|
|
110
|
-
(!e.dataTransfer ||
|
|
111
|
-
!((_c = (_b = tree
|
|
112
|
-
.getConfig()).canDropForeignDragObject) === null || _c === void 0 ? void 0 : _c.call(_b, e.dataTransfer, target)))) {
|
|
113
|
-
dataRef.current.lastAllowDrop = false;
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (!(0, utils_1.canDrop)(e.dataTransfer, target, tree)) {
|
|
117
|
-
dataRef.current.lastAllowDrop = false;
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
tree.applySubStateUpdate("dnd", (state) => (Object.assign(Object.assign({}, state), { dragTarget: target, draggingOverItem: item })));
|
|
121
|
-
dataRef.current.lastAllowDrop = true;
|
|
122
|
-
e.preventDefault();
|
|
123
|
-
}, onDragLeave: () => {
|
|
124
|
-
const dataRef = tree.getDataRef();
|
|
125
|
-
dataRef.current.lastDragCode = "no-drag";
|
|
126
|
-
tree.applySubStateUpdate("dnd", (state) => (Object.assign(Object.assign({}, state), { draggingOverItem: undefined, dragTarget: undefined })));
|
|
127
|
-
}, onDragEnd: (e) => {
|
|
128
|
-
var _a, _b, _c, _d;
|
|
129
|
-
const draggedItems = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggedItems;
|
|
130
|
-
tree.applySubStateUpdate("dnd", null);
|
|
131
|
-
if (((_b = e.dataTransfer) === null || _b === void 0 ? void 0 : _b.dropEffect) === "none" || !draggedItems) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
(_d = (_c = tree.getConfig()).onCompleteForeignDrop) === null || _d === void 0 ? void 0 : _d.call(_c, draggedItems);
|
|
135
|
-
}, onDrop: (e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
-
var _a, _b, _c;
|
|
137
|
-
const dataRef = tree.getDataRef();
|
|
138
|
-
const target = (0, utils_1.getDragTarget)(e, item, tree);
|
|
139
|
-
if (!(0, utils_1.canDrop)(e.dataTransfer, target, tree)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
e.preventDefault();
|
|
143
|
-
const config = tree.getConfig();
|
|
144
|
-
const draggedItems = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggedItems;
|
|
145
|
-
dataRef.current.lastDragCode = undefined;
|
|
146
|
-
tree.applySubStateUpdate("dnd", null);
|
|
147
|
-
if (draggedItems) {
|
|
148
|
-
yield ((_b = config.onDrop) === null || _b === void 0 ? void 0 : _b.call(config, draggedItems, target));
|
|
149
|
-
}
|
|
150
|
-
else if (e.dataTransfer) {
|
|
151
|
-
yield ((_c = config.onDropForeignDragObject) === null || _c === void 0 ? void 0 : _c.call(config, e.dataTransfer, target));
|
|
152
|
-
}
|
|
153
|
-
}) })),
|
|
154
|
-
isDragTarget: ({ tree, item }) => {
|
|
155
|
-
const target = tree.getDragTarget();
|
|
156
|
-
return target ? target.item.getId() === item.getId() : false;
|
|
157
|
-
},
|
|
158
|
-
isDragTargetAbove: ({ tree, item }) => {
|
|
159
|
-
const target = tree.getDragTarget();
|
|
160
|
-
if (!target ||
|
|
161
|
-
!(0, utils_1.isOrderedDragTarget)(target) ||
|
|
162
|
-
target.item !== item.getParent())
|
|
163
|
-
return false;
|
|
164
|
-
return target.childIndex === item.getItemMeta().posInSet;
|
|
165
|
-
},
|
|
166
|
-
isDragTargetBelow: ({ tree, item }) => {
|
|
167
|
-
const target = tree.getDragTarget();
|
|
168
|
-
if (!target ||
|
|
169
|
-
!(0, utils_1.isOrderedDragTarget)(target) ||
|
|
170
|
-
target.item !== item.getParent())
|
|
171
|
-
return false;
|
|
172
|
-
return target.childIndex - 1 === item.getItemMeta().posInSet;
|
|
173
|
-
},
|
|
174
|
-
isDraggingOver: ({ tree, item }) => {
|
|
175
|
-
var _a, _b;
|
|
176
|
-
return ((_b = (_a = tree.getState().dnd) === null || _a === void 0 ? void 0 : _a.draggingOverItem) === null || _b === void 0 ? void 0 : _b.getId()) === item.getId();
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ItemInstance, SetStateFn } from "../../types/core";
|
|
2
|
-
export interface DndDataRef {
|
|
3
|
-
lastDragCode?: string;
|
|
4
|
-
lastAllowDrop?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface DndState<T> {
|
|
7
|
-
draggedItems?: ItemInstance<T>[];
|
|
8
|
-
draggingOverItem?: ItemInstance<T>;
|
|
9
|
-
dragTarget?: DragTarget<T>;
|
|
10
|
-
}
|
|
11
|
-
export interface DragLineData {
|
|
12
|
-
indent: number;
|
|
13
|
-
top: number;
|
|
14
|
-
left: number;
|
|
15
|
-
width: number;
|
|
16
|
-
}
|
|
17
|
-
export type DragTarget<T> = {
|
|
18
|
-
item: ItemInstance<T>;
|
|
19
|
-
childIndex: number;
|
|
20
|
-
insertionIndex: number;
|
|
21
|
-
dragLineIndex: number;
|
|
22
|
-
dragLineLevel: number;
|
|
23
|
-
} | {
|
|
24
|
-
item: ItemInstance<T>;
|
|
25
|
-
};
|
|
26
|
-
export declare enum DragTargetPosition {
|
|
27
|
-
Top = "top",
|
|
28
|
-
Bottom = "bottom",
|
|
29
|
-
Item = "item"
|
|
30
|
-
}
|
|
31
|
-
export type DragAndDropFeatureDef<T> = {
|
|
32
|
-
state: {
|
|
33
|
-
dnd?: DndState<T> | null;
|
|
34
|
-
};
|
|
35
|
-
config: {
|
|
36
|
-
setDndState?: SetStateFn<DndState<T> | undefined | null>;
|
|
37
|
-
/** Defines the size of the area at the top and bottom of an item where, when an item is dropped, the item willö
|
|
38
|
-
* be placed above or below the item within the same parent, as opposed to being placed inside the item.
|
|
39
|
-
* If `canReorder` is `false`, this is ignored. */
|
|
40
|
-
reorderAreaPercentage?: number;
|
|
41
|
-
canReorder?: boolean;
|
|
42
|
-
canDrag?: (items: ItemInstance<T>[]) => boolean;
|
|
43
|
-
canDrop?: (items: ItemInstance<T>[], target: DragTarget<T>) => boolean;
|
|
44
|
-
indent?: number;
|
|
45
|
-
createForeignDragObject?: (items: ItemInstance<T>[]) => {
|
|
46
|
-
format: string;
|
|
47
|
-
data: any;
|
|
48
|
-
};
|
|
49
|
-
canDropForeignDragObject?: (dataTransfer: DataTransfer, target: DragTarget<T>) => boolean;
|
|
50
|
-
onDrop?: (items: ItemInstance<T>[], target: DragTarget<T>) => void | Promise<void>;
|
|
51
|
-
onDropForeignDragObject?: (dataTransfer: DataTransfer, target: DragTarget<T>) => void | Promise<void>;
|
|
52
|
-
onCompleteForeignDrop?: (items: ItemInstance<T>[]) => void;
|
|
53
|
-
};
|
|
54
|
-
treeInstance: {
|
|
55
|
-
getDragTarget: () => DragTarget<T> | null;
|
|
56
|
-
getDragLineData: () => DragLineData | null;
|
|
57
|
-
getDragLineStyle: (topOffset?: number, leftOffset?: number) => Record<string, any>;
|
|
58
|
-
};
|
|
59
|
-
itemInstance: {
|
|
60
|
-
isDragTarget: () => boolean;
|
|
61
|
-
isDragTargetAbove: () => boolean;
|
|
62
|
-
isDragTargetBelow: () => boolean;
|
|
63
|
-
isDraggingOver: () => boolean;
|
|
64
|
-
};
|
|
65
|
-
hotkeys: never;
|
|
66
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DragTargetPosition = void 0;
|
|
4
|
-
var DragTargetPosition;
|
|
5
|
-
(function (DragTargetPosition) {
|
|
6
|
-
DragTargetPosition["Top"] = "top";
|
|
7
|
-
DragTargetPosition["Bottom"] = "bottom";
|
|
8
|
-
DragTargetPosition["Item"] = "item";
|
|
9
|
-
})(DragTargetPosition || (exports.DragTargetPosition = DragTargetPosition = {}));
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ItemInstance, TreeInstance } from "../../types/core";
|
|
2
|
-
import { DragTarget } from "./types";
|
|
3
|
-
export declare enum ItemDropCategory {
|
|
4
|
-
Item = 0,
|
|
5
|
-
ExpandedFolder = 1,
|
|
6
|
-
LastInGroup = 2
|
|
7
|
-
}
|
|
8
|
-
export declare const isOrderedDragTarget: <T>(dragTarget: DragTarget<T>) => dragTarget is {
|
|
9
|
-
item: ItemInstance<T>;
|
|
10
|
-
childIndex: number;
|
|
11
|
-
insertionIndex: number;
|
|
12
|
-
dragLineIndex: number;
|
|
13
|
-
dragLineLevel: number;
|
|
14
|
-
};
|
|
15
|
-
export declare const canDrop: (dataTransfer: DataTransfer | null, target: DragTarget<any>, tree: TreeInstance<any>) => boolean;
|
|
16
|
-
export declare const getItemDropCategory: (item: ItemInstance<any>) => ItemDropCategory;
|
|
17
|
-
export declare const getInsertionIndex: <T>(children: ItemInstance<T>[], childIndex: number, draggedItems: ItemInstance<T>[] | undefined) => number;
|
|
18
|
-
export declare const getDragCode: (e: any, item: ItemInstance<any>, tree: TreeInstance<any>) => string;
|
|
19
|
-
/** @param item refers to the bottom-most item of the container, at which bottom is being reparented on (e.g. root-1-2-6) */
|
|
20
|
-
export declare const getReparentTarget: <T>(item: ItemInstance<T>, reparentLevel: number, draggedItems: ItemInstance<T>[] | undefined) => {
|
|
21
|
-
item: ItemInstance<any>;
|
|
22
|
-
childIndex: number;
|
|
23
|
-
insertionIndex: number;
|
|
24
|
-
dragLineIndex: number;
|
|
25
|
-
dragLineLevel: number;
|
|
26
|
-
};
|
|
27
|
-
export declare const getDragTarget: (e: any, item: ItemInstance<any>, tree: TreeInstance<any>, canReorder?: boolean | undefined) => DragTarget<any>;
|