react-arborist 3.3.0-rc.1 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/components/cursor.d.ts +1 -0
- package/dist/main/components/cursor.js +20 -0
- package/dist/{components → main/components}/default-container.d.ts +1 -2
- package/dist/main/components/default-container.js +238 -0
- package/dist/main/components/default-cursor.js +35 -0
- package/dist/{components → main/components}/default-drag-preview.d.ts +1 -2
- package/dist/main/components/default-drag-preview.js +57 -0
- package/dist/{components → main/components}/default-node.d.ts +1 -2
- package/dist/main/components/default-node.js +32 -0
- package/dist/{components → main/components}/default-row.d.ts +1 -2
- package/dist/main/components/default-row.js +8 -0
- package/dist/main/components/drag-preview-container.d.ts +1 -0
- package/dist/main/components/drag-preview-container.js +21 -0
- package/dist/{components → main/components}/list-inner-element.d.ts +1 -1
- package/dist/main/components/list-inner-element.js +25 -0
- package/dist/main/components/list-outer-element.d.ts +2 -0
- package/dist/main/components/list-outer-element.js +38 -0
- package/dist/main/components/outer-drop.js +9 -0
- package/dist/{components → main/components}/provider.d.ts +2 -2
- package/dist/main/components/provider.js +52 -0
- package/dist/{components → main/components}/row-container.d.ts +2 -2
- package/dist/main/components/row-container.js +84 -0
- package/dist/main/components/tree-container.d.ts +1 -0
- package/dist/main/components/tree-container.js +12 -0
- package/dist/{components → main/components}/tree.d.ts +1 -1
- package/dist/main/components/tree.js +15 -0
- package/dist/{context.d.ts → main/context.d.ts} +4 -4
- package/dist/main/context.js +33 -0
- package/dist/main/data/create-index.js +10 -0
- package/dist/main/data/create-list.js +62 -0
- package/dist/main/data/create-root.js +43 -0
- package/dist/main/data/make-tree.d.ts +5 -0
- package/dist/main/data/make-tree.js +40 -0
- package/dist/{data → main/data}/simple-tree.d.ts +1 -1
- package/dist/main/data/simple-tree.js +100 -0
- package/dist/{dnd → main/dnd}/compute-drop.d.ts +6 -6
- package/dist/main/dnd/compute-drop.js +129 -0
- package/dist/main/dnd/drag-hook.js +46 -0
- package/dist/{dnd → main/dnd}/drop-hook.d.ts +1 -1
- package/dist/main/dnd/drop-hook.js +42 -0
- package/dist/main/dnd/measure-hover.d.ts +8 -0
- package/dist/main/dnd/measure-hover.js +21 -0
- package/dist/main/dnd/outer-drop-hook.js +45 -0
- package/dist/main/hooks/use-fresh-node.js +18 -0
- package/dist/{hooks → main/hooks}/use-simple-tree.d.ts +1 -1
- package/dist/main/hooks/use-simple-tree.js +35 -0
- package/dist/main/hooks/use-validated-props.js +29 -0
- package/dist/main/index.js +27 -0
- package/dist/{interfaces → main/interfaces}/node-api.d.ts +1 -1
- package/dist/main/interfaces/node-api.js +164 -0
- package/dist/{interfaces → main/interfaces}/tree-api.d.ts +88 -8
- package/dist/main/interfaces/tree-api.js +649 -0
- package/dist/main/interfaces/tree-api.test.d.ts +1 -0
- package/dist/main/interfaces/tree-api.test.js +14 -0
- package/dist/{state → main/state}/dnd-slice.d.ts +1 -1
- package/dist/main/state/dnd-slice.js +35 -0
- package/dist/{state → main/state}/drag-slice.d.ts +1 -1
- package/dist/main/state/drag-slice.js +24 -0
- package/dist/{state → main/state}/edit-slice.d.ts +1 -1
- package/dist/main/state/edit-slice.js +18 -0
- package/dist/{state → main/state}/focus-slice.d.ts +1 -1
- package/dist/main/state/focus-slice.js +26 -0
- package/dist/main/state/initial.js +29 -0
- package/dist/{state → main/state}/open-slice.d.ts +2 -2
- package/dist/main/state/open-slice.js +48 -0
- package/dist/main/state/root-reducer.d.ts +96 -0
- package/dist/main/state/root-reducer.js +20 -0
- package/dist/{state → main/state}/selection-slice.d.ts +1 -1
- package/dist/main/state/selection-slice.js +59 -0
- package/dist/{types → main/types}/dnd.d.ts +2 -2
- package/dist/main/types/dnd.js +2 -0
- package/dist/{types → main/types}/handlers.d.ts +5 -5
- package/dist/main/types/handlers.js +2 -0
- package/dist/{types → main/types}/renderers.d.ts +4 -4
- package/dist/main/types/renderers.js +2 -0
- package/dist/main/types/state.d.ts +2 -0
- package/dist/main/types/state.js +2 -0
- package/dist/{types → main/types}/tree-props.d.ts +1 -1
- package/dist/main/types/tree-props.js +2 -0
- package/dist/{types → main/types}/utils.d.ts +5 -5
- package/dist/main/types/utils.js +2 -0
- package/dist/main/utils.js +183 -0
- package/dist/module/components/cursor.d.ts +1 -0
- package/dist/module/components/cursor.js +16 -0
- package/dist/module/components/default-container.d.ts +6 -0
- package/dist/module/components/default-container.js +234 -0
- package/dist/module/components/default-cursor.d.ts +3 -0
- package/dist/module/components/default-cursor.js +29 -0
- package/dist/module/components/default-drag-preview.d.ts +2 -0
- package/dist/module/components/default-drag-preview.js +53 -0
- package/dist/module/components/default-node.d.ts +2 -0
- package/dist/module/components/default-node.js +28 -0
- package/dist/module/components/default-row.d.ts +2 -0
- package/dist/module/components/default-row.js +4 -0
- package/dist/module/components/drag-preview-container.d.ts +1 -0
- package/dist/module/components/drag-preview-container.js +17 -0
- package/dist/module/components/list-inner-element.d.ts +2 -0
- package/dist/module/components/list-inner-element.js +22 -0
- package/dist/module/components/list-outer-element.d.ts +2 -0
- package/dist/module/components/list-outer-element.js +35 -0
- package/dist/module/components/outer-drop.d.ts +4 -0
- package/dist/module/components/outer-drop.js +5 -0
- package/dist/module/components/provider.d.ts +10 -0
- package/dist/module/components/provider.js +48 -0
- package/dist/module/components/row-container.d.ts +7 -0
- package/dist/module/components/row-container.js +58 -0
- package/dist/module/components/tree-container.d.ts +1 -0
- package/dist/module/components/tree-container.js +8 -0
- package/dist/module/components/tree.d.ts +8 -0
- package/dist/module/components/tree.js +12 -0
- package/dist/module/context.d.ts +22 -0
- package/dist/module/context.js +26 -0
- package/dist/module/data/create-index.d.ts +4 -0
- package/dist/module/data/create-index.js +6 -0
- package/dist/module/data/create-list.d.ts +3 -0
- package/dist/module/data/create-list.js +58 -0
- package/dist/module/data/create-root.d.ts +4 -0
- package/dist/module/data/create-root.js +39 -0
- package/dist/module/data/make-tree.d.ts +5 -0
- package/dist/module/data/make-tree.js +36 -0
- package/dist/module/data/simple-tree.d.ts +44 -0
- package/dist/module/data/simple-tree.js +96 -0
- package/dist/module/dnd/compute-drop.d.ts +37 -0
- package/dist/module/dnd/compute-drop.js +125 -0
- package/dist/module/dnd/drag-hook.d.ts +3 -0
- package/dist/module/dnd/drag-hook.js +42 -0
- package/dist/module/dnd/drop-hook.d.ts +8 -0
- package/dist/module/dnd/drop-hook.js +38 -0
- package/dist/module/dnd/measure-hover.d.ts +8 -0
- package/dist/module/dnd/measure-hover.js +17 -0
- package/dist/module/dnd/outer-drop-hook.d.ts +1 -0
- package/dist/module/dnd/outer-drop-hook.js +41 -0
- package/dist/module/hooks/use-fresh-node.d.ts +1 -0
- package/dist/module/hooks/use-fresh-node.js +14 -0
- package/dist/module/hooks/use-simple-tree.d.ts +12 -0
- package/dist/module/hooks/use-simple-tree.js +31 -0
- package/dist/module/hooks/use-validated-props.d.ts +2 -0
- package/dist/module/hooks/use-validated-props.js +25 -0
- package/dist/module/index.d.ts +8 -0
- package/dist/module/index.js +9 -0
- package/dist/module/interfaces/node-api.d.ts +71 -0
- package/dist/module/interfaces/node-api.js +160 -0
- package/dist/module/interfaces/tree-api.d.ts +214 -0
- package/dist/module/interfaces/tree-api.js +622 -0
- package/dist/module/interfaces/tree-api.test.d.ts +1 -0
- package/dist/module/interfaces/tree-api.test.js +12 -0
- package/dist/module/state/dnd-slice.d.ts +29 -0
- package/dist/module/state/dnd-slice.js +31 -0
- package/dist/module/state/drag-slice.d.ts +9 -0
- package/dist/module/state/drag-slice.js +20 -0
- package/dist/module/state/edit-slice.d.ts +8 -0
- package/dist/module/state/edit-slice.js +13 -0
- package/dist/module/state/focus-slice.d.ts +12 -0
- package/dist/module/state/focus-slice.js +20 -0
- package/dist/module/state/initial.d.ts +3 -0
- package/dist/module/state/initial.js +25 -0
- package/dist/module/state/open-slice.d.ts +30 -0
- package/dist/module/state/open-slice.js +44 -0
- package/dist/module/state/root-reducer.d.ts +96 -0
- package/dist/module/state/root-reducer.js +17 -0
- package/dist/module/state/selection-slice.d.ts +42 -0
- package/dist/module/state/selection-slice.js +55 -0
- package/dist/module/types/dnd.d.ts +8 -0
- package/dist/module/types/dnd.js +1 -0
- package/dist/module/types/handlers.d.ts +30 -0
- package/dist/module/types/handlers.js +1 -0
- package/dist/module/types/renderers.d.ts +29 -0
- package/dist/module/types/renderers.js +1 -0
- package/dist/module/types/state.d.ts +2 -0
- package/dist/module/types/state.js +1 -0
- package/dist/module/types/tree-props.d.ts +56 -0
- package/dist/module/types/tree-props.js +1 -0
- package/dist/module/types/utils.d.ts +17 -0
- package/dist/module/types/utils.js +1 -0
- package/dist/module/utils.d.ts +24 -0
- package/dist/module/utils.js +162 -0
- package/package.json +24 -24
- package/src/components/default-container.tsx +2 -0
- package/src/components/provider.tsx +3 -2
- package/src/components/row-container.tsx +1 -1
- package/src/interfaces/tree-api.ts +1 -1
- package/src/types/tree-props.ts +1 -1
- package/dist/components/cursor.d.ts +0 -2
- package/dist/components/drag-preview-container.d.ts +0 -2
- package/dist/components/list-outer-element.d.ts +0 -2
- package/dist/components/tree-container.d.ts +0 -2
- package/dist/index.js +0 -2433
- package/dist/index.js.map +0 -1
- package/dist/module.js +0 -2406
- package/dist/module.js.map +0 -1
- package/dist/state/root-reducer.d.ts +0 -13
- package/dist/types/state.d.ts +0 -2
- package/jest.config.js +0 -5
- package/tsconfig.json +0 -4
- /package/dist/{components → main/components}/default-cursor.d.ts +0 -0
- /package/dist/{components → main/components}/outer-drop.d.ts +0 -0
- /package/dist/{data → main/data}/create-index.d.ts +0 -0
- /package/dist/{data → main/data}/create-list.d.ts +0 -0
- /package/dist/{data → main/data}/create-root.d.ts +0 -0
- /package/dist/{dnd → main/dnd}/drag-hook.d.ts +0 -0
- /package/dist/{dnd → main/dnd}/outer-drop-hook.d.ts +0 -0
- /package/dist/{hooks → main/hooks}/use-fresh-node.d.ts +0 -0
- /package/dist/{hooks → main/hooks}/use-validated-props.d.ts +0 -0
- /package/dist/{index.d.ts → main/index.d.ts} +0 -0
- /package/dist/{state → main/state}/initial.d.ts +0 -0
- /package/dist/{utils.d.ts → main/utils.d.ts} +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInsertParentId = exports.getInsertIndex = exports.waitFor = exports.safeRun = exports.mergeRefs = exports.identify = exports.identifyNull = exports.access = exports.focusPrevElement = exports.focusNextElement = exports.walk = exports.dfs = exports.noop = exports.indexOf = exports.isDescendant = exports.isClosed = exports.isItem = exports.bound = void 0;
|
|
4
|
+
function bound(n, min, max) {
|
|
5
|
+
return Math.max(Math.min(n, max), min);
|
|
6
|
+
}
|
|
7
|
+
exports.bound = bound;
|
|
8
|
+
function isItem(node) {
|
|
9
|
+
return node && node.isLeaf;
|
|
10
|
+
}
|
|
11
|
+
exports.isItem = isItem;
|
|
12
|
+
function isClosed(node) {
|
|
13
|
+
return node && node.isInternal && !node.isOpen;
|
|
14
|
+
}
|
|
15
|
+
exports.isClosed = isClosed;
|
|
16
|
+
/**
|
|
17
|
+
* Is first param a descendant of the second param
|
|
18
|
+
*/
|
|
19
|
+
const isDescendant = (a, b) => {
|
|
20
|
+
let n = a;
|
|
21
|
+
while (n) {
|
|
22
|
+
if (n.id === b.id)
|
|
23
|
+
return true;
|
|
24
|
+
n = n.parent;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
exports.isDescendant = isDescendant;
|
|
29
|
+
const indexOf = (node) => {
|
|
30
|
+
if (!node.parent)
|
|
31
|
+
throw Error("Node does not have a parent");
|
|
32
|
+
return node.parent.children.findIndex((c) => c.id === node.id);
|
|
33
|
+
};
|
|
34
|
+
exports.indexOf = indexOf;
|
|
35
|
+
function noop() { }
|
|
36
|
+
exports.noop = noop;
|
|
37
|
+
function dfs(node, id) {
|
|
38
|
+
if (!node)
|
|
39
|
+
return null;
|
|
40
|
+
if (node.id === id)
|
|
41
|
+
return node;
|
|
42
|
+
if (node.children) {
|
|
43
|
+
for (let child of node.children) {
|
|
44
|
+
const result = dfs(child, id);
|
|
45
|
+
if (result)
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
exports.dfs = dfs;
|
|
52
|
+
function walk(node, fn) {
|
|
53
|
+
fn(node);
|
|
54
|
+
if (node.children) {
|
|
55
|
+
for (let child of node.children) {
|
|
56
|
+
walk(child, fn);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.walk = walk;
|
|
61
|
+
function focusNextElement(target) {
|
|
62
|
+
const elements = getFocusable(target);
|
|
63
|
+
let next;
|
|
64
|
+
for (let i = 0; i < elements.length; ++i) {
|
|
65
|
+
const item = elements[i];
|
|
66
|
+
if (item === target) {
|
|
67
|
+
next = nextItem(elements, i);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// @ts-ignore ??
|
|
72
|
+
next === null || next === void 0 ? void 0 : next.focus();
|
|
73
|
+
}
|
|
74
|
+
exports.focusNextElement = focusNextElement;
|
|
75
|
+
function focusPrevElement(target) {
|
|
76
|
+
const elements = getFocusable(target);
|
|
77
|
+
let next;
|
|
78
|
+
for (let i = 0; i < elements.length; ++i) {
|
|
79
|
+
const item = elements[i];
|
|
80
|
+
if (item === target) {
|
|
81
|
+
next = prevItem(elements, i);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
next === null || next === void 0 ? void 0 : next.focus();
|
|
87
|
+
}
|
|
88
|
+
exports.focusPrevElement = focusPrevElement;
|
|
89
|
+
function nextItem(list, index) {
|
|
90
|
+
if (index + 1 < list.length) {
|
|
91
|
+
return list[index + 1];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return list[0];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function prevItem(list, index) {
|
|
98
|
+
if (index - 1 >= 0) {
|
|
99
|
+
return list[index - 1];
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return list[list.length - 1];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function getFocusable(target) {
|
|
106
|
+
return Array.from(document.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled]), details:not([disabled]), summary:not(:disabled)')).filter((e) => e === target || !target.contains(e));
|
|
107
|
+
}
|
|
108
|
+
function access(obj, accessor) {
|
|
109
|
+
if (typeof accessor === "boolean")
|
|
110
|
+
return accessor;
|
|
111
|
+
if (typeof accessor === "string")
|
|
112
|
+
return obj[accessor];
|
|
113
|
+
return accessor(obj);
|
|
114
|
+
}
|
|
115
|
+
exports.access = access;
|
|
116
|
+
function identifyNull(obj) {
|
|
117
|
+
if (obj === null)
|
|
118
|
+
return null;
|
|
119
|
+
else
|
|
120
|
+
return identify(obj);
|
|
121
|
+
}
|
|
122
|
+
exports.identifyNull = identifyNull;
|
|
123
|
+
function identify(obj) {
|
|
124
|
+
return typeof obj === "string" ? obj : obj.id;
|
|
125
|
+
}
|
|
126
|
+
exports.identify = identify;
|
|
127
|
+
function mergeRefs(...refs) {
|
|
128
|
+
return (instance) => {
|
|
129
|
+
refs.forEach((ref) => {
|
|
130
|
+
if (typeof ref === "function") {
|
|
131
|
+
ref(instance);
|
|
132
|
+
}
|
|
133
|
+
else if (ref != null) {
|
|
134
|
+
ref.current = instance;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
exports.mergeRefs = mergeRefs;
|
|
140
|
+
function safeRun(fn, ...args) {
|
|
141
|
+
if (fn)
|
|
142
|
+
return fn(...args);
|
|
143
|
+
}
|
|
144
|
+
exports.safeRun = safeRun;
|
|
145
|
+
function waitFor(fn) {
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
let tries = 0;
|
|
148
|
+
function check() {
|
|
149
|
+
tries += 1;
|
|
150
|
+
if (tries === 100)
|
|
151
|
+
reject();
|
|
152
|
+
if (fn())
|
|
153
|
+
resolve();
|
|
154
|
+
else
|
|
155
|
+
setTimeout(check, 10);
|
|
156
|
+
}
|
|
157
|
+
check();
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
exports.waitFor = waitFor;
|
|
161
|
+
function getInsertIndex(tree) {
|
|
162
|
+
var _a, _b;
|
|
163
|
+
const focus = tree.focusedNode;
|
|
164
|
+
if (!focus)
|
|
165
|
+
return (_b = (_a = tree.root.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
166
|
+
if (focus.isOpen)
|
|
167
|
+
return 0;
|
|
168
|
+
if (focus.parent)
|
|
169
|
+
return focus.childIndex + 1;
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
exports.getInsertIndex = getInsertIndex;
|
|
173
|
+
function getInsertParentId(tree) {
|
|
174
|
+
const focus = tree.focusedNode;
|
|
175
|
+
if (!focus)
|
|
176
|
+
return null;
|
|
177
|
+
if (focus.isOpen)
|
|
178
|
+
return focus.id;
|
|
179
|
+
if (focus.parent && !focus.parent.isRoot)
|
|
180
|
+
return focus.parent.id;
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
exports.getInsertParentId = getInsertParentId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Cursor(): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useDndContext, useTreeApi } from "../context";
|
|
3
|
+
export function Cursor() {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const tree = useTreeApi();
|
|
6
|
+
const state = useDndContext();
|
|
7
|
+
const cursor = state.cursor;
|
|
8
|
+
if (!cursor || cursor.type !== "line")
|
|
9
|
+
return null;
|
|
10
|
+
const indent = tree.indent;
|
|
11
|
+
const top = tree.rowHeight * cursor.index +
|
|
12
|
+
((_b = (_a = tree.props.padding) !== null && _a !== void 0 ? _a : tree.props.paddingTop) !== null && _b !== void 0 ? _b : 0);
|
|
13
|
+
const left = indent * cursor.level;
|
|
14
|
+
const Cursor = tree.renderCursor;
|
|
15
|
+
return _jsx(Cursor, { top, left, indent });
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All these keyboard shortcuts seem like they should be configurable.
|
|
3
|
+
* Each operation should be a given a name and separated from
|
|
4
|
+
* the event handler. Future clean up welcome.
|
|
5
|
+
*/
|
|
6
|
+
export declare function DefaultContainer(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FixedSizeList } from "react-window";
|
|
3
|
+
import { useDataUpdates, useTreeApi } from "../context";
|
|
4
|
+
import { focusNextElement, focusPrevElement } from "../utils";
|
|
5
|
+
import { ListOuterElement } from "./list-outer-element";
|
|
6
|
+
import { ListInnerElement } from "./list-inner-element";
|
|
7
|
+
import { RowContainer } from "./row-container";
|
|
8
|
+
let focusSearchTerm = "";
|
|
9
|
+
let timeoutId = null;
|
|
10
|
+
/**
|
|
11
|
+
* All these keyboard shortcuts seem like they should be configurable.
|
|
12
|
+
* Each operation should be a given a name and separated from
|
|
13
|
+
* the event handler. Future clean up welcome.
|
|
14
|
+
*/
|
|
15
|
+
export function DefaultContainer() {
|
|
16
|
+
useDataUpdates();
|
|
17
|
+
const tree = useTreeApi();
|
|
18
|
+
return (_jsx("div", { role: "tree", style: {
|
|
19
|
+
height: tree.height,
|
|
20
|
+
width: tree.width,
|
|
21
|
+
minHeight: 0,
|
|
22
|
+
minWidth: 0,
|
|
23
|
+
}, onContextMenu: tree.props.onContextMenu, onClick: tree.props.onClick, tabIndex: 0, onFocus: (e) => {
|
|
24
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
25
|
+
tree.onFocus();
|
|
26
|
+
}
|
|
27
|
+
}, onBlur: (e) => {
|
|
28
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
29
|
+
tree.onBlur();
|
|
30
|
+
}
|
|
31
|
+
}, onKeyDown: (e) => {
|
|
32
|
+
var _a;
|
|
33
|
+
if (tree.isEditing) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (e.key === "Backspace") {
|
|
37
|
+
if (!tree.props.onDelete)
|
|
38
|
+
return;
|
|
39
|
+
const ids = Array.from(tree.selectedIds);
|
|
40
|
+
if (ids.length > 1) {
|
|
41
|
+
let nextFocus = tree.mostRecentNode;
|
|
42
|
+
while (nextFocus && nextFocus.isSelected) {
|
|
43
|
+
nextFocus = nextFocus.nextSibling;
|
|
44
|
+
}
|
|
45
|
+
if (!nextFocus)
|
|
46
|
+
nextFocus = tree.lastNode;
|
|
47
|
+
tree.focus(nextFocus, { scroll: false });
|
|
48
|
+
tree.delete(Array.from(ids));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const node = tree.focusedNode;
|
|
52
|
+
if (node) {
|
|
53
|
+
const sib = node.nextSibling;
|
|
54
|
+
const parent = node.parent;
|
|
55
|
+
tree.focus(sib || parent, { scroll: false });
|
|
56
|
+
tree.delete(node);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (e.key === "Tab" && !e.shiftKey) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
focusNextElement(e.currentTarget);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (e.key === "Tab" && e.shiftKey) {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
focusPrevElement(e.currentTarget);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (e.key === "ArrowDown") {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
const next = tree.nextNode;
|
|
74
|
+
if (e.metaKey) {
|
|
75
|
+
tree.select(tree.focusedNode);
|
|
76
|
+
tree.activate(tree.focusedNode);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
else if (!e.shiftKey || tree.props.disableMultiSelection) {
|
|
80
|
+
tree.focus(next);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (!next)
|
|
85
|
+
return;
|
|
86
|
+
const current = tree.focusedNode;
|
|
87
|
+
if (!current) {
|
|
88
|
+
tree.focus(tree.firstNode);
|
|
89
|
+
}
|
|
90
|
+
else if (current.isSelected) {
|
|
91
|
+
tree.selectContiguous(next);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
tree.selectMulti(next);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (e.key === "ArrowUp") {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
const prev = tree.prevNode;
|
|
102
|
+
if (!e.shiftKey || tree.props.disableMultiSelection) {
|
|
103
|
+
tree.focus(prev);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if (!prev)
|
|
108
|
+
return;
|
|
109
|
+
const current = tree.focusedNode;
|
|
110
|
+
if (!current) {
|
|
111
|
+
tree.focus(tree.lastNode); // ?
|
|
112
|
+
}
|
|
113
|
+
else if (current.isSelected) {
|
|
114
|
+
tree.selectContiguous(prev);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
tree.selectMulti(prev);
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (e.key === "ArrowRight") {
|
|
123
|
+
const node = tree.focusedNode;
|
|
124
|
+
if (!node)
|
|
125
|
+
return;
|
|
126
|
+
if (node.isInternal && node.isOpen) {
|
|
127
|
+
tree.focus(tree.nextNode);
|
|
128
|
+
}
|
|
129
|
+
else if (node.isInternal)
|
|
130
|
+
tree.open(node.id);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (e.key === "ArrowLeft") {
|
|
134
|
+
const node = tree.focusedNode;
|
|
135
|
+
if (!node || node.isRoot)
|
|
136
|
+
return;
|
|
137
|
+
if (node.isInternal && node.isOpen)
|
|
138
|
+
tree.close(node.id);
|
|
139
|
+
else if (!((_a = node.parent) === null || _a === void 0 ? void 0 : _a.isRoot)) {
|
|
140
|
+
tree.focus(node.parent);
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (e.key === "a" && e.metaKey && !tree.props.disableMultiSelection) {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
tree.selectAll();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (e.key === "a" && !e.metaKey && tree.props.onCreate) {
|
|
150
|
+
tree.createLeaf();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (e.key === "A" && !e.metaKey) {
|
|
154
|
+
if (!tree.props.onCreate)
|
|
155
|
+
return;
|
|
156
|
+
tree.createInternal();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (e.key === "Home") {
|
|
160
|
+
// add shift keys
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
tree.focus(tree.firstNode);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (e.key === "End") {
|
|
166
|
+
// add shift keys
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
tree.focus(tree.lastNode);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (e.key === "Enter") {
|
|
172
|
+
const node = tree.focusedNode;
|
|
173
|
+
if (!node)
|
|
174
|
+
return;
|
|
175
|
+
if (!node.isEditable || !tree.props.onRename)
|
|
176
|
+
return;
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
if (node)
|
|
179
|
+
tree.edit(node);
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (e.key === " ") {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
const node = tree.focusedNode;
|
|
186
|
+
if (!node)
|
|
187
|
+
return;
|
|
188
|
+
if (node.isLeaf) {
|
|
189
|
+
node.select();
|
|
190
|
+
node.activate();
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
node.toggle();
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (e.key === "*") {
|
|
198
|
+
const node = tree.focusedNode;
|
|
199
|
+
if (!node)
|
|
200
|
+
return;
|
|
201
|
+
tree.openSiblings(node);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (e.key === "PageUp") {
|
|
205
|
+
e.preventDefault();
|
|
206
|
+
tree.pageUp();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (e.key === "PageDown") {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
tree.pageDown();
|
|
212
|
+
}
|
|
213
|
+
// If they type a sequence of characters
|
|
214
|
+
// collect them. Reset them after a timeout.
|
|
215
|
+
// Use it to search the tree for a node, then focus it.
|
|
216
|
+
// Clean this up a bit later
|
|
217
|
+
clearTimeout(timeoutId);
|
|
218
|
+
focusSearchTerm += e.key;
|
|
219
|
+
timeoutId = setTimeout(() => {
|
|
220
|
+
focusSearchTerm = "";
|
|
221
|
+
}, 600);
|
|
222
|
+
const node = tree.visibleNodes.find((n) => {
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
const name = n.data.name;
|
|
225
|
+
if (typeof name === "string") {
|
|
226
|
+
return name.toLowerCase().startsWith(focusSearchTerm);
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
return false;
|
|
230
|
+
});
|
|
231
|
+
if (node)
|
|
232
|
+
tree.focus(node.id);
|
|
233
|
+
}, children: _jsx(FixedSizeList, { className: tree.props.className, outerRef: tree.listEl, itemCount: tree.visibleNodes.length, height: tree.height, width: tree.width, itemSize: tree.rowHeight, overscanCount: tree.overscanCount, itemKey: (index) => { var _a; return ((_a = tree.visibleNodes[index]) === null || _a === void 0 ? void 0 : _a.id) || index; }, outerElementType: ListOuterElement, innerElementType: ListInnerElement, onScroll: tree.props.onScroll, onItemsRendered: tree.onItemsRendered.bind(tree), ref: tree.list, children: RowContainer }) }));
|
|
234
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
const placeholderStyle = {
|
|
4
|
+
display: "flex",
|
|
5
|
+
alignItems: "center",
|
|
6
|
+
zIndex: 1,
|
|
7
|
+
};
|
|
8
|
+
const lineStyle = {
|
|
9
|
+
flex: 1,
|
|
10
|
+
height: "2px",
|
|
11
|
+
background: "#4B91E2",
|
|
12
|
+
borderRadius: "1px",
|
|
13
|
+
};
|
|
14
|
+
const circleStyle = {
|
|
15
|
+
width: "4px",
|
|
16
|
+
height: "4px",
|
|
17
|
+
boxShadow: "0 0 0 3px #4B91E2",
|
|
18
|
+
borderRadius: "50%",
|
|
19
|
+
};
|
|
20
|
+
export const DefaultCursor = React.memo(function DefaultCursor({ top, left, indent, }) {
|
|
21
|
+
const style = {
|
|
22
|
+
position: "absolute",
|
|
23
|
+
pointerEvents: "none",
|
|
24
|
+
top: top - 2 + "px",
|
|
25
|
+
left: left + "px",
|
|
26
|
+
right: indent + "px",
|
|
27
|
+
};
|
|
28
|
+
return (_jsxs("div", { style: Object.assign(Object.assign({}, placeholderStyle), style), children: [_jsx("div", { style: Object.assign({}, circleStyle) }), _jsx("div", { style: Object.assign({}, lineStyle) })] }));
|
|
29
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { useTreeApi } from "../context";
|
|
4
|
+
const layerStyles = {
|
|
5
|
+
position: "fixed",
|
|
6
|
+
pointerEvents: "none",
|
|
7
|
+
zIndex: 100,
|
|
8
|
+
left: 0,
|
|
9
|
+
top: 0,
|
|
10
|
+
width: "100%",
|
|
11
|
+
height: "100%",
|
|
12
|
+
};
|
|
13
|
+
const getStyle = (offset) => {
|
|
14
|
+
if (!offset)
|
|
15
|
+
return { display: "none" };
|
|
16
|
+
const { x, y } = offset;
|
|
17
|
+
return { transform: `translate(${x}px, ${y}px)` };
|
|
18
|
+
};
|
|
19
|
+
const getCountStyle = (offset) => {
|
|
20
|
+
if (!offset)
|
|
21
|
+
return { display: "none" };
|
|
22
|
+
const { x, y } = offset;
|
|
23
|
+
return { transform: `translate(${x + 10}px, ${y + 10}px)` };
|
|
24
|
+
};
|
|
25
|
+
export function DefaultDragPreview({ offset, mouse, id, dragIds, isDragging, }) {
|
|
26
|
+
return (_jsxs(Overlay, { isDragging: isDragging, children: [_jsx(Position, { offset: offset, children: _jsx(PreviewNode, { id: id, dragIds: dragIds }) }), _jsx(Count, { mouse: mouse, count: dragIds.length })] }));
|
|
27
|
+
}
|
|
28
|
+
const Overlay = memo(function Overlay(props) {
|
|
29
|
+
if (!props.isDragging)
|
|
30
|
+
return null;
|
|
31
|
+
return _jsx("div", { style: layerStyles, children: props.children });
|
|
32
|
+
});
|
|
33
|
+
function Position(props) {
|
|
34
|
+
return (_jsx("div", { className: "row preview", style: getStyle(props.offset), children: props.children }));
|
|
35
|
+
}
|
|
36
|
+
function Count(props) {
|
|
37
|
+
const { count, mouse } = props;
|
|
38
|
+
if (count > 1)
|
|
39
|
+
return (_jsx("div", { className: "selected-count", style: getCountStyle(mouse), children: count }));
|
|
40
|
+
else
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const PreviewNode = memo(function PreviewNode(props) {
|
|
44
|
+
const tree = useTreeApi();
|
|
45
|
+
const node = tree.get(props.id);
|
|
46
|
+
if (!node)
|
|
47
|
+
return null;
|
|
48
|
+
return (_jsx(tree.renderNode, { preview: true, node: node, style: {
|
|
49
|
+
paddingLeft: node.level * tree.indent,
|
|
50
|
+
opacity: 0.2,
|
|
51
|
+
background: "transparent",
|
|
52
|
+
}, tree: tree }));
|
|
53
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
export function DefaultNode(props) {
|
|
4
|
+
return (_jsxs("div", { ref: props.dragHandle, style: props.style, children: [_jsx("span", { onClick: (e) => {
|
|
5
|
+
e.stopPropagation();
|
|
6
|
+
props.node.toggle();
|
|
7
|
+
}, children: props.node.isLeaf ? "🌳" : props.node.isOpen ? "🗁" : "🗀" }), " ", props.node.isEditing ? _jsx(Edit, Object.assign({}, props)) : _jsx(Show, Object.assign({}, props))] }));
|
|
8
|
+
}
|
|
9
|
+
function Show(props) {
|
|
10
|
+
return (_jsx(_Fragment, { children: _jsx("span", { children: props.node.data.name }) }));
|
|
11
|
+
}
|
|
12
|
+
function Edit({ node }) {
|
|
13
|
+
const input = useRef();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
(_a = input.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
17
|
+
(_b = input.current) === null || _b === void 0 ? void 0 : _b.select();
|
|
18
|
+
}, []);
|
|
19
|
+
return (_jsx("input", { ref: input,
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
defaultValue: node.data.name, onBlur: () => node.reset(), onKeyDown: (e) => {
|
|
22
|
+
var _a;
|
|
23
|
+
if (e.key === "Escape")
|
|
24
|
+
node.reset();
|
|
25
|
+
if (e.key === "Enter")
|
|
26
|
+
node.submit(((_a = input.current) === null || _a === void 0 ? void 0 : _a.value) || "");
|
|
27
|
+
} }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function DefaultRow({ node, attrs, innerRef, children, }) {
|
|
3
|
+
return (_jsx("div", Object.assign({}, attrs, { ref: innerRef, onFocus: (e) => e.stopPropagation(), onClick: node.handleClick, children: children })));
|
|
4
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DragPreviewContainer(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useDragLayer } from "react-dnd";
|
|
3
|
+
import { useTreeApi } from "../context";
|
|
4
|
+
import { DefaultDragPreview } from "./default-drag-preview";
|
|
5
|
+
export function DragPreviewContainer() {
|
|
6
|
+
const tree = useTreeApi();
|
|
7
|
+
const { offset, mouse, item, isDragging } = useDragLayer((m) => {
|
|
8
|
+
return {
|
|
9
|
+
offset: m.getSourceClientOffset(),
|
|
10
|
+
mouse: m.getClientOffset(),
|
|
11
|
+
item: m.getItem(),
|
|
12
|
+
isDragging: m.isDragging(),
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
const DragPreview = tree.props.renderDragPreview || DefaultDragPreview;
|
|
16
|
+
return (_jsx(DragPreview, { offset: offset, mouse: mouse, id: (item === null || item === void 0 ? void 0 : item.id) || null, dragIds: (item === null || item === void 0 ? void 0 : item.dragIds) || [], isDragging: isDragging }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef } from "react";
|
|
14
|
+
import { useTreeApi } from "../context";
|
|
15
|
+
export const ListInnerElement = forwardRef(function InnerElement(_a, ref) {
|
|
16
|
+
var _b, _c, _d, _e;
|
|
17
|
+
var { style } = _a, rest = __rest(_a, ["style"]);
|
|
18
|
+
const tree = useTreeApi();
|
|
19
|
+
const paddingTop = (_c = (_b = tree.props.padding) !== null && _b !== void 0 ? _b : tree.props.paddingTop) !== null && _c !== void 0 ? _c : 0;
|
|
20
|
+
const paddingBottom = (_e = (_d = tree.props.padding) !== null && _d !== void 0 ? _d : tree.props.paddingBottom) !== null && _e !== void 0 ? _e : 0;
|
|
21
|
+
return (_jsx("div", Object.assign({ ref: ref, style: Object.assign(Object.assign({}, style), { height: `${parseFloat(style.height) + paddingTop + paddingBottom}px` }) }, rest)));
|
|
22
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef } from "react";
|
|
14
|
+
import { useTreeApi } from "../context";
|
|
15
|
+
import { Cursor } from "./cursor";
|
|
16
|
+
export const ListOuterElement = forwardRef(function Outer(props, ref) {
|
|
17
|
+
const { children } = props, rest = __rest(props, ["children"]);
|
|
18
|
+
const tree = useTreeApi();
|
|
19
|
+
return (_jsxs("div", Object.assign({
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
ref: ref }, rest, { onClick: (e) => {
|
|
22
|
+
if (e.currentTarget === e.target)
|
|
23
|
+
tree.deselectAll();
|
|
24
|
+
}, children: [_jsx(DropContainer, {}), children] })));
|
|
25
|
+
});
|
|
26
|
+
const DropContainer = () => {
|
|
27
|
+
const tree = useTreeApi();
|
|
28
|
+
return (_jsx("div", { style: {
|
|
29
|
+
height: tree.visibleNodes.length * tree.rowHeight,
|
|
30
|
+
width: "100%",
|
|
31
|
+
position: "absolute",
|
|
32
|
+
left: "0",
|
|
33
|
+
right: "0",
|
|
34
|
+
}, children: _jsx(Cursor, {}) }));
|
|
35
|
+
};
|