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,162 @@
|
|
|
1
|
+
export function bound(n, min, max) {
|
|
2
|
+
return Math.max(Math.min(n, max), min);
|
|
3
|
+
}
|
|
4
|
+
export function isItem(node) {
|
|
5
|
+
return node && node.isLeaf;
|
|
6
|
+
}
|
|
7
|
+
export function isClosed(node) {
|
|
8
|
+
return node && node.isInternal && !node.isOpen;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Is first param a descendant of the second param
|
|
12
|
+
*/
|
|
13
|
+
export const isDescendant = (a, b) => {
|
|
14
|
+
let n = a;
|
|
15
|
+
while (n) {
|
|
16
|
+
if (n.id === b.id)
|
|
17
|
+
return true;
|
|
18
|
+
n = n.parent;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
export const indexOf = (node) => {
|
|
23
|
+
if (!node.parent)
|
|
24
|
+
throw Error("Node does not have a parent");
|
|
25
|
+
return node.parent.children.findIndex((c) => c.id === node.id);
|
|
26
|
+
};
|
|
27
|
+
export function noop() { }
|
|
28
|
+
export function dfs(node, id) {
|
|
29
|
+
if (!node)
|
|
30
|
+
return null;
|
|
31
|
+
if (node.id === id)
|
|
32
|
+
return node;
|
|
33
|
+
if (node.children) {
|
|
34
|
+
for (let child of node.children) {
|
|
35
|
+
const result = dfs(child, id);
|
|
36
|
+
if (result)
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
export function walk(node, fn) {
|
|
43
|
+
fn(node);
|
|
44
|
+
if (node.children) {
|
|
45
|
+
for (let child of node.children) {
|
|
46
|
+
walk(child, fn);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function focusNextElement(target) {
|
|
51
|
+
const elements = getFocusable(target);
|
|
52
|
+
let next;
|
|
53
|
+
for (let i = 0; i < elements.length; ++i) {
|
|
54
|
+
const item = elements[i];
|
|
55
|
+
if (item === target) {
|
|
56
|
+
next = nextItem(elements, i);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// @ts-ignore ??
|
|
61
|
+
next === null || next === void 0 ? void 0 : next.focus();
|
|
62
|
+
}
|
|
63
|
+
export function focusPrevElement(target) {
|
|
64
|
+
const elements = getFocusable(target);
|
|
65
|
+
let next;
|
|
66
|
+
for (let i = 0; i < elements.length; ++i) {
|
|
67
|
+
const item = elements[i];
|
|
68
|
+
if (item === target) {
|
|
69
|
+
next = prevItem(elements, i);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
next === null || next === void 0 ? void 0 : next.focus();
|
|
75
|
+
}
|
|
76
|
+
function nextItem(list, index) {
|
|
77
|
+
if (index + 1 < list.length) {
|
|
78
|
+
return list[index + 1];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return list[0];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function prevItem(list, index) {
|
|
85
|
+
if (index - 1 >= 0) {
|
|
86
|
+
return list[index - 1];
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return list[list.length - 1];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function getFocusable(target) {
|
|
93
|
+
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));
|
|
94
|
+
}
|
|
95
|
+
export function access(obj, accessor) {
|
|
96
|
+
if (typeof accessor === "boolean")
|
|
97
|
+
return accessor;
|
|
98
|
+
if (typeof accessor === "string")
|
|
99
|
+
return obj[accessor];
|
|
100
|
+
return accessor(obj);
|
|
101
|
+
}
|
|
102
|
+
export function identifyNull(obj) {
|
|
103
|
+
if (obj === null)
|
|
104
|
+
return null;
|
|
105
|
+
else
|
|
106
|
+
return identify(obj);
|
|
107
|
+
}
|
|
108
|
+
export function identify(obj) {
|
|
109
|
+
return typeof obj === "string" ? obj : obj.id;
|
|
110
|
+
}
|
|
111
|
+
export function mergeRefs(...refs) {
|
|
112
|
+
return (instance) => {
|
|
113
|
+
refs.forEach((ref) => {
|
|
114
|
+
if (typeof ref === "function") {
|
|
115
|
+
ref(instance);
|
|
116
|
+
}
|
|
117
|
+
else if (ref != null) {
|
|
118
|
+
ref.current = instance;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export function safeRun(fn, ...args) {
|
|
124
|
+
if (fn)
|
|
125
|
+
return fn(...args);
|
|
126
|
+
}
|
|
127
|
+
export function waitFor(fn) {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
let tries = 0;
|
|
130
|
+
function check() {
|
|
131
|
+
tries += 1;
|
|
132
|
+
if (tries === 100)
|
|
133
|
+
reject();
|
|
134
|
+
if (fn())
|
|
135
|
+
resolve();
|
|
136
|
+
else
|
|
137
|
+
setTimeout(check, 10);
|
|
138
|
+
}
|
|
139
|
+
check();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export function getInsertIndex(tree) {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
const focus = tree.focusedNode;
|
|
145
|
+
if (!focus)
|
|
146
|
+
return (_b = (_a = tree.root.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
147
|
+
if (focus.isOpen)
|
|
148
|
+
return 0;
|
|
149
|
+
if (focus.parent)
|
|
150
|
+
return focus.childIndex + 1;
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
export function getInsertParentId(tree) {
|
|
154
|
+
const focus = tree.focusedNode;
|
|
155
|
+
if (!focus)
|
|
156
|
+
return null;
|
|
157
|
+
if (focus.isOpen)
|
|
158
|
+
return focus.id;
|
|
159
|
+
if (focus.parent && !focus.parent.isRoot)
|
|
160
|
+
return focus.parent.id;
|
|
161
|
+
return null;
|
|
162
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-arborist",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"module": "dist/module.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "dist/main/index.js",
|
|
7
|
+
"module": "dist/module/index.js",
|
|
8
|
+
"types": "dist/module/index.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
11
|
+
"build:cjs": "tsc --outDir dist/main",
|
|
12
|
+
"build:es": "tsc --outDir dist/module --module es2022 --moduleResolution node",
|
|
12
13
|
"build": "npm-run-all clean -p 'build:**'",
|
|
13
|
-
"test": "jest",
|
|
14
|
-
"build:js": "parcel build --target main --target module",
|
|
15
|
-
"build:types": "tsc --outDir dist",
|
|
16
14
|
"clean": "rimraf dist",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
15
|
+
"prepack": "yarn build",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"watch": "yarn build:es --watch"
|
|
20
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"src",
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
21
23
|
"repository": {
|
|
22
24
|
"type": "git",
|
|
23
25
|
"url": "https://github.com/brimdata/react-arborist.git"
|
|
@@ -37,9 +39,9 @@
|
|
|
37
39
|
],
|
|
38
40
|
"dependencies": {
|
|
39
41
|
"react-dnd": "^14.0.3",
|
|
40
|
-
"react-dnd-html5-backend": "^14.0.
|
|
41
|
-
"react-window": "^1.8.
|
|
42
|
-
"redux": "^
|
|
42
|
+
"react-dnd-html5-backend": "^14.0.3",
|
|
43
|
+
"react-window": "^1.8.10",
|
|
44
|
+
"redux": "^5.0.0",
|
|
43
45
|
"use-sync-external-store": "^1.2.0"
|
|
44
46
|
},
|
|
45
47
|
"peerDependencies": {
|
|
@@ -47,16 +49,14 @@
|
|
|
47
49
|
"react-dom": ">= 16.14"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@types/
|
|
52
|
-
"@types/react": "^
|
|
53
|
-
"@types/
|
|
54
|
-
"
|
|
55
|
-
"jest": "^29.4.1",
|
|
52
|
+
"@types/jest": "^29.5.11",
|
|
53
|
+
"@types/react": "^18.2.43",
|
|
54
|
+
"@types/react-window": "^1.8.8",
|
|
55
|
+
"@types/use-sync-external-store": "^0.0.6",
|
|
56
|
+
"jest": "^29.7.0",
|
|
56
57
|
"npm-run-all": "^4.1.5",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"typescript": "^4.6.2"
|
|
58
|
+
"rimraf": "^5.0.5",
|
|
59
|
+
"ts-jest": "^29.1.1",
|
|
60
|
+
"typescript": "^5.3.3"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -18,6 +18,7 @@ export function DefaultContainer() {
|
|
|
18
18
|
const tree = useTreeApi();
|
|
19
19
|
return (
|
|
20
20
|
<div
|
|
21
|
+
role="tree"
|
|
21
22
|
style={{
|
|
22
23
|
height: tree.height,
|
|
23
24
|
width: tree.width,
|
|
@@ -215,6 +216,7 @@ export function DefaultContainer() {
|
|
|
215
216
|
if (node) tree.focus(node.id);
|
|
216
217
|
}}
|
|
217
218
|
>
|
|
219
|
+
{/* @ts-ignore */}
|
|
218
220
|
<FixedSizeList
|
|
219
221
|
className={tree.props.className}
|
|
220
222
|
outerRef={tree.listEl}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "../context";
|
|
16
16
|
import { TreeApi } from "../interfaces/tree-api";
|
|
17
17
|
import { initialState } from "../state/initial";
|
|
18
|
-
import { rootReducer, RootState } from "../state/root-reducer";
|
|
18
|
+
import { Actions, rootReducer, RootState } from "../state/root-reducer";
|
|
19
19
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
20
20
|
import { DndProvider } from "react-dnd";
|
|
21
21
|
import { TreeProps } from "../types/tree-props";
|
|
@@ -37,7 +37,8 @@ export function TreeProvider<T>({
|
|
|
37
37
|
}: Props<T>) {
|
|
38
38
|
const list = useRef<FixedSizeList | null>(null);
|
|
39
39
|
const listEl = useRef<HTMLDivElement | null>(null);
|
|
40
|
-
const store = useRef<Store
|
|
40
|
+
const store = useRef<Store<RootState, Actions>>(
|
|
41
|
+
// @ts-ignore
|
|
41
42
|
createStore(rootReducer, initialState(treeProps))
|
|
42
43
|
);
|
|
43
44
|
const state = useSyncExternalStore<RootState>(
|
|
@@ -58,7 +58,7 @@ export const RowContainer = React.memo(function RowContainer<T>({
|
|
|
58
58
|
);
|
|
59
59
|
const rowAttrs: React.HTMLAttributes<any> = {
|
|
60
60
|
role: "treeitem",
|
|
61
|
-
"aria-level": node.level,
|
|
61
|
+
"aria-level": node.level + 1,
|
|
62
62
|
"aria-selected": node.isSelected,
|
|
63
63
|
style: rowStyle,
|
|
64
64
|
tabIndex: -1,
|
|
@@ -105,7 +105,7 @@ export class TreeApi<T> {
|
|
|
105
105
|
|
|
106
106
|
accessChildren(data: T) {
|
|
107
107
|
const get = this.props.childrenAccessor || "children";
|
|
108
|
-
return utils.access<T[] | undefined>(data, get) ?? null;
|
|
108
|
+
return utils.access<readonly T[] | undefined>(data, get) ?? null;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
accessId(data: T) {
|
package/src/types/tree-props.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface TreeProps<T> {
|
|
|
36
36
|
padding?: number;
|
|
37
37
|
|
|
38
38
|
/* Config */
|
|
39
|
-
childrenAccessor?: string | ((d: T) => T[] | null);
|
|
39
|
+
childrenAccessor?: string | ((d: T) => readonly T[] | null);
|
|
40
40
|
idAccessor?: string | ((d: T) => string);
|
|
41
41
|
openByDefault?: boolean;
|
|
42
42
|
selectionFollowsFocus?: boolean;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const ListOuterElement: import("react").ForwardRefExoticComponent<Pick<import("react").HTMLProps<HTMLDivElement>, "id" | "children" | "data" | "open" | "cite" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "start" | "hidden" | "color" | "content" | "size" | "default" | "wrap" | "multiple" | "disabled" | "onFocus" | "onClick" | "list" | "name" | "defaultValue" | "onBlur" | "onKeyDown" | "accessKey" | "dir" | "draggable" | "lang" | "translate" | "className" | "classID" | "value" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "download" | "alt" | "coords" | "autoPlay" | "controls" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "accept" | "capture" | "checked" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "charSet" | "httpEquiv" | "high" | "low" | "reversed" | "selected" | "async" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "maxLength" | "minLength" | "kind" | "src" | "srcLang" | "preload" | "crossOrigin" | "defer" | "height" | "href" | "hrefLang" | "integrity" | "loop" | "marginHeight" | "marginWidth" | "max" | "media" | "mediaGroup" | "method" | "min" | "muted" | "nonce" | "noValidate" | "optimum" | "placeholder" | "playsInline" | "poster" | "readOnly" | "rel" | "required" | "rows" | "sandbox" | "scoped" | "scrolling" | "seamless" | "shape" | "sizes" | "srcDoc" | "srcSet" | "step" | "target" | "type" | "useMap" | "width" | "wmode" | "contentEditable" | "contextMenu" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & import("react").RefAttributes<unknown>>;
|