@headless-tree/core 1.2.1 → 1.4.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 +31 -0
- package/dist/index.d.mts +580 -0
- package/dist/index.d.ts +580 -0
- package/dist/index.js +2347 -0
- package/dist/index.mjs +2302 -0
- package/package.json +18 -10
- package/src/core/create-tree.ts +26 -15
- package/src/features/async-data-loader/feature.ts +5 -0
- package/src/features/async-data-loader/types.ts +2 -0
- package/src/features/checkboxes/checkboxes.spec.ts +20 -5
- package/src/features/checkboxes/feature.ts +31 -16
- package/src/features/checkboxes/types.ts +1 -0
- package/src/features/drag-and-drop/drag-and-drop.spec.ts +11 -2
- package/src/features/drag-and-drop/feature.ts +107 -24
- package/src/features/drag-and-drop/types.ts +21 -0
- package/src/features/drag-and-drop/utils.ts +8 -6
- package/src/features/keyboard-drag-and-drop/feature.ts +10 -1
- package/src/features/keyboard-drag-and-drop/keyboard-drag-and-drop.spec.ts +34 -3
- package/src/features/main/types.ts +0 -2
- package/src/features/sync-data-loader/feature.ts +5 -1
- package/src/features/tree/feature.ts +4 -3
- package/src/features/tree/tree.spec.ts +14 -4
- package/src/test-utils/test-tree-do.ts +2 -0
- package/src/test-utils/test-tree.ts +1 -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 -191
- 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/checkboxes/feature.d.ts +0 -2
- package/lib/cjs/features/checkboxes/feature.js +0 -94
- package/lib/cjs/features/checkboxes/types.d.ts +0 -26
- package/lib/cjs/features/checkboxes/types.js +0 -9
- package/lib/cjs/features/drag-and-drop/feature.d.ts +0 -2
- package/lib/cjs/features/drag-and-drop/feature.js +0 -205
- package/lib/cjs/features/drag-and-drop/types.d.ts +0 -71
- 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 -47
- 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 -244
- package/lib/cjs/features/tree/types.d.ts +0 -63
- package/lib/cjs/features/tree/types.js +0 -2
- package/lib/cjs/index.d.ts +0 -33
- package/lib/cjs/index.js +0 -51
- 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 -84
- 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 -187
- 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/checkboxes/feature.d.ts +0 -2
- package/lib/esm/features/checkboxes/feature.js +0 -91
- package/lib/esm/features/checkboxes/types.d.ts +0 -26
- package/lib/esm/features/checkboxes/types.js +0 -6
- package/lib/esm/features/drag-and-drop/feature.d.ts +0 -2
- package/lib/esm/features/drag-and-drop/feature.js +0 -202
- package/lib/esm/features/drag-and-drop/types.d.ts +0 -71
- 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 -47
- 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 -241
- package/lib/esm/features/tree/types.d.ts +0 -63
- package/lib/esm/features/tree/types.js +0 -1
- package/lib/esm/index.d.ts +0 -33
- package/lib/esm/index.js +0 -32
- 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 -84
- 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,203 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
11
|
-
import { beforeEach, describe, vi } from "vitest";
|
|
12
|
-
import { createTree } from "../core/create-tree";
|
|
13
|
-
import { TestTreeDo } from "./test-tree-do";
|
|
14
|
-
import { TestTreeExpect } from "./test-tree-expect";
|
|
15
|
-
import { syncDataLoaderFeature } from "../features/sync-data-loader/feature";
|
|
16
|
-
import { asyncDataLoaderFeature } from "../features/async-data-loader/feature";
|
|
17
|
-
import { buildProxiedInstance } from "../core/build-proxified-instance";
|
|
18
|
-
vi.useFakeTimers({ shouldAdvanceTime: true });
|
|
19
|
-
export class TestTree {
|
|
20
|
-
forSuits(runSuite) {
|
|
21
|
-
describe.for([
|
|
22
|
-
this.suits.sync(),
|
|
23
|
-
this.suits.async(),
|
|
24
|
-
this.suits.proxifiedSync(),
|
|
25
|
-
this.suits.proxifiedAsync(),
|
|
26
|
-
])("$title", ({ tree }) => {
|
|
27
|
-
tree.resetBeforeEach();
|
|
28
|
-
runSuite(tree);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
get instance() {
|
|
32
|
-
if (!this.treeInstance) {
|
|
33
|
-
this.treeInstance = createTree(this.config);
|
|
34
|
-
this.treeInstance.rebuildTree();
|
|
35
|
-
}
|
|
36
|
-
return this.treeInstance;
|
|
37
|
-
}
|
|
38
|
-
constructor(config) {
|
|
39
|
-
this.config = config;
|
|
40
|
-
this.do = new TestTreeDo(this);
|
|
41
|
-
this.expect = new TestTreeExpect(this);
|
|
42
|
-
this.treeInstance = null;
|
|
43
|
-
this.asyncDataLoaderImp = {
|
|
44
|
-
getItem: (id) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
yield new Promise((r) => {
|
|
46
|
-
r.debugName = `Loading getItem ${id}`;
|
|
47
|
-
TestTree.asyncLoaderResolvers.push(r);
|
|
48
|
-
});
|
|
49
|
-
return id;
|
|
50
|
-
}),
|
|
51
|
-
getChildren: (id) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
yield new Promise((r) => {
|
|
53
|
-
r.debugName = `Loading getChildren ${id}`;
|
|
54
|
-
TestTree.asyncLoaderResolvers.push(r);
|
|
55
|
-
});
|
|
56
|
-
return [`${id}1`, `${id}2`, `${id}3`, `${id}4`];
|
|
57
|
-
}),
|
|
58
|
-
};
|
|
59
|
-
this.suits = {
|
|
60
|
-
sync: () => ({
|
|
61
|
-
tree: this.withFeatures(syncDataLoaderFeature),
|
|
62
|
-
title: "Synchronous Data Loader",
|
|
63
|
-
}),
|
|
64
|
-
async: () => ({
|
|
65
|
-
tree: this.withFeatures(asyncDataLoaderFeature).with({
|
|
66
|
-
dataLoader: this.asyncDataLoaderImp,
|
|
67
|
-
}),
|
|
68
|
-
title: "Asynchronous Data Loader",
|
|
69
|
-
}),
|
|
70
|
-
proxifiedSync: () => ({
|
|
71
|
-
tree: this.withFeatures(syncDataLoaderFeature).with({
|
|
72
|
-
instanceBuilder: buildProxiedInstance,
|
|
73
|
-
}),
|
|
74
|
-
title: "Proxified Synchronous Data Loader",
|
|
75
|
-
}),
|
|
76
|
-
proxifiedAsync: () => ({
|
|
77
|
-
tree: this.withFeatures(asyncDataLoaderFeature).with({
|
|
78
|
-
instanceBuilder: buildProxiedInstance,
|
|
79
|
-
}),
|
|
80
|
-
title: "Proxified Asynchronous Data Loader",
|
|
81
|
-
}),
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
static resolveAsyncLoaders() {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
var _a;
|
|
87
|
-
do {
|
|
88
|
-
(_a = TestTree.asyncLoaderResolvers.shift()) === null || _a === void 0 ? void 0 : _a();
|
|
89
|
-
yield new Promise((r) => {
|
|
90
|
-
setTimeout(r);
|
|
91
|
-
});
|
|
92
|
-
} while (TestTree.asyncLoaderResolvers.length);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
resolveAsyncVisibleItems() {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
this.instance.getItems();
|
|
98
|
-
yield TestTree.resolveAsyncLoaders();
|
|
99
|
-
this.instance.getItems().forEach((i) => i.getItemName());
|
|
100
|
-
yield TestTree.resolveAsyncLoaders();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
static default(config) {
|
|
104
|
-
return new TestTree(Object.assign({ rootItemId: "x", createLoadingItemData: () => "loading", dataLoader: {
|
|
105
|
-
getItem: (id) => id,
|
|
106
|
-
getChildren: (id) => [`${id}1`, `${id}2`, `${id}3`, `${id}4`],
|
|
107
|
-
}, getItemName: (item) => item.getItemData(), indent: 20, isItemFolder: (item) => item.getItemMeta().level < 2, initialState: {
|
|
108
|
-
expandedItems: ["x1", "x11"],
|
|
109
|
-
}, features: [] }, config));
|
|
110
|
-
}
|
|
111
|
-
with(config) {
|
|
112
|
-
return new TestTree(Object.assign(Object.assign({}, this.config), config));
|
|
113
|
-
}
|
|
114
|
-
resetBeforeEach() {
|
|
115
|
-
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
yield this.createTestCaseTree();
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
createTestCaseTree() {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
this.reset();
|
|
122
|
-
vi.clearAllMocks();
|
|
123
|
-
// trigger instance creation
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
125
|
-
this.instance;
|
|
126
|
-
yield this.resolveAsyncVisibleItems();
|
|
127
|
-
return this;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
withFeatures(...features) {
|
|
131
|
-
var _a;
|
|
132
|
-
return this.with({
|
|
133
|
-
features: [...((_a = this.config.features) !== null && _a !== void 0 ? _a : []), ...features],
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
mockedHandler(handlerName) {
|
|
137
|
-
var _a;
|
|
138
|
-
const mock = vi.fn();
|
|
139
|
-
if (this.treeInstance) {
|
|
140
|
-
(_a = this.treeInstance) === null || _a === void 0 ? void 0 : _a.setConfig((prev) => (Object.assign(Object.assign({}, prev), { [handlerName]: mock })));
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
this.config[handlerName] = mock;
|
|
144
|
-
}
|
|
145
|
-
return mock;
|
|
146
|
-
}
|
|
147
|
-
item(itemId) {
|
|
148
|
-
return this.instance.getItemInstance(itemId);
|
|
149
|
-
}
|
|
150
|
-
reset() {
|
|
151
|
-
this.treeInstance = null;
|
|
152
|
-
TestTree.asyncLoaderResolvers = [];
|
|
153
|
-
}
|
|
154
|
-
debug() {
|
|
155
|
-
console.log(this.instance
|
|
156
|
-
.getItems()
|
|
157
|
-
.map((item) => [
|
|
158
|
-
" ".repeat(item.getItemMeta().level),
|
|
159
|
-
'"',
|
|
160
|
-
item.getItemName(),
|
|
161
|
-
'"',
|
|
162
|
-
].join(""))
|
|
163
|
-
.join("\n"));
|
|
164
|
-
}
|
|
165
|
-
setElementBoundingBox(itemId, bb = {
|
|
166
|
-
left: 0,
|
|
167
|
-
width: 100,
|
|
168
|
-
top: 0,
|
|
169
|
-
height: 20,
|
|
170
|
-
}) {
|
|
171
|
-
this.instance.registerElement({
|
|
172
|
-
getBoundingClientRect: () => ({
|
|
173
|
-
left: 0,
|
|
174
|
-
width: 100,
|
|
175
|
-
top: 0,
|
|
176
|
-
height: 10000,
|
|
177
|
-
}),
|
|
178
|
-
});
|
|
179
|
-
this.instance.getItemInstance(itemId).registerElement({
|
|
180
|
-
getBoundingClientRect: () => bb,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
static dragEvent(clientX = 1000, clientY = 0) {
|
|
184
|
-
return {
|
|
185
|
-
preventDefault: vi.fn(),
|
|
186
|
-
stopPropagation: vi.fn(),
|
|
187
|
-
dataTransfer: {
|
|
188
|
-
setData: vi.fn(),
|
|
189
|
-
getData: vi.fn(),
|
|
190
|
-
dropEffect: "unchaged-from-test",
|
|
191
|
-
},
|
|
192
|
-
clientX,
|
|
193
|
-
clientY,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
createTopDragEvent(indent = 0) {
|
|
197
|
-
return TestTree.dragEvent(indent * 20, 1);
|
|
198
|
-
}
|
|
199
|
-
createBottomDragEvent(indent = 0) {
|
|
200
|
-
return TestTree.dragEvent(indent * 20, 19);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
TestTree.asyncLoaderResolvers = [];
|
package/lib/esm/types/core.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { DragAndDropFeatureDef } from "../features/drag-and-drop/types";
|
|
2
|
-
import { MainFeatureDef } from "../features/main/types";
|
|
3
|
-
import { SelectionFeatureDef } from "../features/selection/types";
|
|
4
|
-
import { TreeFeatureDef } from "../features/tree/types";
|
|
5
|
-
import { HotkeyConfig, HotkeysCoreFeatureDef } from "../features/hotkeys-core/types";
|
|
6
|
-
import { SyncDataLoaderFeatureDef } from "../features/sync-data-loader/types";
|
|
7
|
-
import { AsyncDataLoaderFeatureDef } from "../features/async-data-loader/types";
|
|
8
|
-
import { SearchFeatureDef } from "../features/search/types";
|
|
9
|
-
import { RenamingFeatureDef } from "../features/renaming/types";
|
|
10
|
-
import { ExpandAllFeatureDef } from "../features/expand-all/types";
|
|
11
|
-
import { PropMemoizationFeatureDef } from "../features/prop-memoization/types";
|
|
12
|
-
import { KeyboardDragAndDropFeatureDef } from "../features/keyboard-drag-and-drop/types";
|
|
13
|
-
import { CheckboxesFeatureDef } from "../features/checkboxes/types";
|
|
14
|
-
export type Updater<T> = T | ((old: T) => T);
|
|
15
|
-
export type SetStateFn<T> = (updaterOrValue: Updater<T>) => void;
|
|
16
|
-
export type FeatureDef = {
|
|
17
|
-
state: any;
|
|
18
|
-
config: any;
|
|
19
|
-
treeInstance: any;
|
|
20
|
-
itemInstance: any;
|
|
21
|
-
hotkeys: string;
|
|
22
|
-
};
|
|
23
|
-
export type EmptyFeatureDef = {
|
|
24
|
-
state: {};
|
|
25
|
-
config: {};
|
|
26
|
-
treeInstance: {};
|
|
27
|
-
itemInstance: {};
|
|
28
|
-
hotkeys: never;
|
|
29
|
-
};
|
|
30
|
-
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
|
|
31
|
-
type MergedFeatures<F extends FeatureDef> = {
|
|
32
|
-
state: UnionToIntersection<F["state"]>;
|
|
33
|
-
config: UnionToIntersection<F["config"]>;
|
|
34
|
-
treeInstance: UnionToIntersection<F["treeInstance"]>;
|
|
35
|
-
itemInstance: UnionToIntersection<F["itemInstance"]>;
|
|
36
|
-
hotkeys: F["hotkeys"];
|
|
37
|
-
};
|
|
38
|
-
export type RegisteredFeatures<T> = MainFeatureDef<T> | TreeFeatureDef<T> | SelectionFeatureDef<T> | CheckboxesFeatureDef<T> | DragAndDropFeatureDef<T> | KeyboardDragAndDropFeatureDef<T> | HotkeysCoreFeatureDef<T> | SyncDataLoaderFeatureDef<T> | AsyncDataLoaderFeatureDef<T> | SearchFeatureDef<T> | RenamingFeatureDef<T> | ExpandAllFeatureDef | PropMemoizationFeatureDef;
|
|
39
|
-
type TreeStateType<T> = MergedFeatures<RegisteredFeatures<T>>["state"];
|
|
40
|
-
export interface TreeState<T> extends TreeStateType<T> {
|
|
41
|
-
}
|
|
42
|
-
type TreeConfigType<T> = MergedFeatures<RegisteredFeatures<T>>["config"];
|
|
43
|
-
export interface TreeConfig<T> extends TreeConfigType<T> {
|
|
44
|
-
}
|
|
45
|
-
type TreeInstanceType<T> = MergedFeatures<RegisteredFeatures<T>>["treeInstance"];
|
|
46
|
-
export interface TreeInstance<T> extends TreeInstanceType<T> {
|
|
47
|
-
}
|
|
48
|
-
type ItemInstanceType<T> = MergedFeatures<RegisteredFeatures<T>>["itemInstance"];
|
|
49
|
-
export interface ItemInstance<T> extends ItemInstanceType<T> {
|
|
50
|
-
}
|
|
51
|
-
export type HotkeyName = MergedFeatures<RegisteredFeatures<any>>["hotkeys"];
|
|
52
|
-
export type HotkeysConfig<T> = Record<HotkeyName, HotkeyConfig<T>>;
|
|
53
|
-
export type CustomHotkeysConfig<T> = Partial<Record<HotkeyName | `custom${string}`, Partial<HotkeyConfig<T>>>>;
|
|
54
|
-
type MayReturnNull<T extends (...x: any[]) => any> = (...args: Parameters<T>) => ReturnType<T> | null;
|
|
55
|
-
export type ItemInstanceOpts<Key extends keyof ItemInstance<any>> = {
|
|
56
|
-
item: ItemInstance<any>;
|
|
57
|
-
tree: TreeInstance<any>;
|
|
58
|
-
itemId: string;
|
|
59
|
-
prev?: MayReturnNull<ItemInstance<any>[Key]>;
|
|
60
|
-
};
|
|
61
|
-
export type TreeInstanceOpts<Key extends keyof TreeInstance<any>> = {
|
|
62
|
-
tree: TreeInstance<any>;
|
|
63
|
-
prev?: MayReturnNull<TreeInstance<any>[Key]>;
|
|
64
|
-
};
|
|
65
|
-
export type FeatureImplementation<T = any> = {
|
|
66
|
-
key?: string;
|
|
67
|
-
deps?: string[];
|
|
68
|
-
overwrites?: string[];
|
|
69
|
-
stateHandlerNames?: Partial<Record<keyof TreeState<T>, keyof TreeConfig<T>>>;
|
|
70
|
-
getInitialState?: (initialState: Partial<TreeState<T>>, tree: TreeInstance<T>) => Partial<TreeState<T>>;
|
|
71
|
-
getDefaultConfig?: (defaultConfig: Partial<TreeConfig<T>>, tree: TreeInstance<T>) => Partial<TreeConfig<T>>;
|
|
72
|
-
treeInstance?: {
|
|
73
|
-
[key in keyof TreeInstance<T>]?: (opts: TreeInstanceOpts<key>, ...args: Parameters<TreeInstance<T>[key]>) => void;
|
|
74
|
-
};
|
|
75
|
-
itemInstance?: {
|
|
76
|
-
[key in keyof ItemInstance<T>]?: (opts: ItemInstanceOpts<key>, ...args: Parameters<ItemInstance<T>[key]>) => void;
|
|
77
|
-
};
|
|
78
|
-
onTreeMount?: (instance: TreeInstance<T>, treeElement: HTMLElement) => void;
|
|
79
|
-
onTreeUnmount?: (instance: TreeInstance<T>, treeElement: HTMLElement) => void;
|
|
80
|
-
onItemMount?: (instance: ItemInstance<T>, itemElement: HTMLElement, tree: TreeInstance<T>) => void;
|
|
81
|
-
onItemUnmount?: (instance: ItemInstance<T>, itemElement: HTMLElement, tree: TreeInstance<T>) => void;
|
|
82
|
-
hotkeys?: Partial<HotkeysConfig<T>>;
|
|
83
|
-
};
|
|
84
|
-
export {};
|
package/lib/esm/types/core.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type TAllKeys<T> = T extends any ? keyof T : never;
|
|
2
|
-
type TIndexValue<T, K extends PropertyKey, D = never> = T extends any ? K extends keyof T ? T[K] : D : never;
|
|
3
|
-
type TPartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>> extends infer O ? {
|
|
4
|
-
[P in keyof O]: O[P];
|
|
5
|
-
} : never;
|
|
6
|
-
type TFunction = (...a: any[]) => any;
|
|
7
|
-
type TPrimitives = string | number | boolean | bigint | symbol | Date | TFunction;
|
|
8
|
-
export type TMerged<T> = [T] extends [Array<any>] ? {
|
|
9
|
-
[K in keyof T]: TMerged<T[K]>;
|
|
10
|
-
} : [T] extends [TPrimitives] ? T : [T] extends [object] ? TPartialKeys<{
|
|
11
|
-
[K in TAllKeys<T>]: TMerged<TIndexValue<T, K>>;
|
|
12
|
-
}, never> : T;
|
|
13
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ItemInstance } from "../types/core";
|
|
2
|
-
import { DragTarget } from "../features/drag-and-drop/types";
|
|
3
|
-
export declare const createOnDropHandler: <T>(onChangeChildren: (item: ItemInstance<T>, newChildren: string[]) => void) => (items: ItemInstance<T>[], target: DragTarget<T>) => Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { removeItemsFromParents } from "./remove-items-from-parents";
|
|
11
|
-
import { insertItemsAtTarget } from "./insert-items-at-target";
|
|
12
|
-
export const createOnDropHandler = (onChangeChildren) => (items, target) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const itemIds = items.map((item) => item.getId());
|
|
14
|
-
yield removeItemsFromParents(items, onChangeChildren);
|
|
15
|
-
yield insertItemsAtTarget(itemIds, target, onChangeChildren);
|
|
16
|
-
});
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ItemInstance } from "../types/core";
|
|
2
|
-
import { DragTarget } from "../features/drag-and-drop/types";
|
|
3
|
-
export declare const insertItemsAtTarget: <T>(itemIds: string[], target: DragTarget<T>, onChangeChildren: (item: ItemInstance<T>, newChildrenIds: string[]) => Promise<void> | void) => Promise<void>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export const insertItemsAtTarget = (itemIds, target, onChangeChildren) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
yield target.item.getTree().waitForItemChildrenLoaded(target.item.getId());
|
|
12
|
-
const oldChildrenIds = target.item
|
|
13
|
-
.getTree()
|
|
14
|
-
.retrieveChildrenIds(target.item.getId());
|
|
15
|
-
// add moved items to new common parent, if dropped onto parent
|
|
16
|
-
if (!("childIndex" in target)) {
|
|
17
|
-
const newChildren = [...oldChildrenIds, ...itemIds];
|
|
18
|
-
yield onChangeChildren(target.item, newChildren);
|
|
19
|
-
if (target.item && "updateCachedChildrenIds" in target.item) {
|
|
20
|
-
target.item.updateCachedChildrenIds(newChildren);
|
|
21
|
-
}
|
|
22
|
-
target.item.getTree().rebuildTree();
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// add moved items to new common parent, if dropped between siblings
|
|
26
|
-
const newChildren = [
|
|
27
|
-
...oldChildrenIds.slice(0, target.insertionIndex),
|
|
28
|
-
...itemIds,
|
|
29
|
-
...oldChildrenIds.slice(target.insertionIndex),
|
|
30
|
-
];
|
|
31
|
-
yield onChangeChildren(target.item, newChildren);
|
|
32
|
-
if (target.item && "updateCachedChildrenIds" in target.item) {
|
|
33
|
-
target.item.updateCachedChildrenIds(newChildren);
|
|
34
|
-
}
|
|
35
|
-
target.item.getTree().rebuildTree();
|
|
36
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export const removeItemsFromParents = (movedItems, onChangeChildren) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
const movedItemsIds = movedItems.map((item) => item.getId());
|
|
12
|
-
const uniqueParents = [
|
|
13
|
-
...new Set(movedItems.map((item) => item.getParent())),
|
|
14
|
-
];
|
|
15
|
-
for (const parent of uniqueParents) {
|
|
16
|
-
const siblings = parent === null || parent === void 0 ? void 0 : parent.getChildren();
|
|
17
|
-
if (siblings && parent) {
|
|
18
|
-
const newChildren = siblings
|
|
19
|
-
.filter((sibling) => !movedItemsIds.includes(sibling.getId()))
|
|
20
|
-
.map((i) => i.getId());
|
|
21
|
-
yield onChangeChildren(parent, newChildren);
|
|
22
|
-
if (parent && "updateCachedChildrenIds" in parent) {
|
|
23
|
-
parent === null || parent === void 0 ? void 0 : parent.updateCachedChildrenIds(newChildren);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
movedItems[0].getTree().rebuildTree();
|
|
28
|
-
});
|
package/lib/esm/utils.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SetStateFn, TreeState, Updater } from "./types/core";
|
|
2
|
-
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
3
|
-
export declare const memo: <D extends readonly any[], P extends readonly any[], R>(deps: (...args: [...P]) => [...D], fn: (...args: [...D]) => R) => (...a: P) => R;
|
|
4
|
-
export declare function functionalUpdate<T>(updater: Updater<T>, input: T): T;
|
|
5
|
-
export declare function makeStateUpdater<K extends keyof TreeState<any>>(key: K, instance: unknown): SetStateFn<TreeState<any>[K]>;
|
|
6
|
-
export declare const poll: (fn: () => boolean, interval?: number, timeout?: number) => Promise<void>;
|
package/lib/esm/utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export const memo = (deps, fn) => {
|
|
2
|
-
let value;
|
|
3
|
-
let oldDeps = null;
|
|
4
|
-
return (...a) => {
|
|
5
|
-
const newDeps = deps(...a);
|
|
6
|
-
if (!value) {
|
|
7
|
-
value = fn(...newDeps);
|
|
8
|
-
oldDeps = newDeps;
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
const match = oldDeps &&
|
|
12
|
-
oldDeps.length === newDeps.length &&
|
|
13
|
-
!oldDeps.some((dep, i) => dep !== newDeps[i]);
|
|
14
|
-
if (match) {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
value = fn(...newDeps);
|
|
18
|
-
oldDeps = newDeps;
|
|
19
|
-
return value;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export function functionalUpdate(updater, input) {
|
|
23
|
-
return typeof updater === "function"
|
|
24
|
-
? updater(input)
|
|
25
|
-
: updater;
|
|
26
|
-
}
|
|
27
|
-
export function makeStateUpdater(key, instance) {
|
|
28
|
-
return (updater) => {
|
|
29
|
-
instance.setState((old) => {
|
|
30
|
-
return Object.assign(Object.assign({}, old), { [key]: functionalUpdate(updater, old[key]) });
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export const poll = (fn, interval = 100, timeout = 1000) => new Promise((resolve) => {
|
|
35
|
-
let clear;
|
|
36
|
-
const i = setInterval(() => {
|
|
37
|
-
if (fn()) {
|
|
38
|
-
resolve();
|
|
39
|
-
clearInterval(i);
|
|
40
|
-
clearTimeout(clear);
|
|
41
|
-
}
|
|
42
|
-
}, interval);
|
|
43
|
-
clear = setTimeout(() => {
|
|
44
|
-
clearInterval(i);
|
|
45
|
-
}, timeout);
|
|
46
|
-
});
|