react-arborist 2.1.0 → 2.2.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/README.md +2 -3
- package/dist/hooks/use-simple-tree.d.ts +1 -1
- package/dist/index.js +35 -36
- package/dist/index.js.map +1 -1
- package/dist/interfaces/tree-api.d.ts +1 -1
- package/dist/module.js +35 -36
- package/dist/module.js.map +1 -1
- package/dist/types/tree-props.d.ts +5 -4
- package/package.json +3 -2
- package/src/components/default-container.tsx +33 -36
- package/src/components/row-container.tsx +1 -2
- package/src/data/create-root.ts +1 -1
- package/src/hooks/use-simple-tree.ts +1 -1
- package/src/interfaces/node-api.ts +2 -2
- package/src/interfaces/tree-api.ts +1 -1
- package/src/types/tree-props.ts +5 -4
|
@@ -6,8 +6,8 @@ import { ListOnScrollProps } from "react-window";
|
|
|
6
6
|
import { NodeApi } from "../interfaces/node-api";
|
|
7
7
|
import { OpenMap } from "../state/open-slice";
|
|
8
8
|
export interface TreeProps<T> {
|
|
9
|
-
data?: T[];
|
|
10
|
-
initialData?: T[];
|
|
9
|
+
data?: readonly T[];
|
|
10
|
+
initialData?: readonly T[];
|
|
11
11
|
onCreate?: handlers.CreateHandler<T>;
|
|
12
12
|
onMove?: handlers.MoveHandler<T>;
|
|
13
13
|
onRename?: handlers.RenameHandler<T>;
|
|
@@ -18,7 +18,7 @@ export interface TreeProps<T> {
|
|
|
18
18
|
renderCursor?: ElementType<renderers.CursorProps>;
|
|
19
19
|
renderContainer?: ElementType<{}>;
|
|
20
20
|
rowHeight?: number;
|
|
21
|
-
width?: number;
|
|
21
|
+
width?: number | string;
|
|
22
22
|
height?: number;
|
|
23
23
|
indent?: number;
|
|
24
24
|
paddingTop?: number;
|
|
@@ -26,9 +26,10 @@ export interface TreeProps<T> {
|
|
|
26
26
|
padding?: number;
|
|
27
27
|
openByDefault?: boolean;
|
|
28
28
|
selectionFollowsFocus?: boolean;
|
|
29
|
+
disableMultiSelection?: boolean;
|
|
29
30
|
disableDrag?: string | boolean | BoolFunc<T>;
|
|
30
31
|
disableDrop?: string | boolean | BoolFunc<T>;
|
|
31
|
-
childrenAccessor?: string | ((d: T) => T[]);
|
|
32
|
+
childrenAccessor?: string | ((d: T) => T[] | null);
|
|
32
33
|
idAccessor?: string | ((d: T) => string);
|
|
33
34
|
onActivate?: (node: NodeApi<T>) => void;
|
|
34
35
|
onSelect?: (nodes: NodeApi<T>[]) => void;
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-arborist",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
-
"repository": "
|
|
9
|
+
"repository": "github:brimdata/react-arborist",
|
|
10
10
|
"homepage": "https://react-arborist.netlify.app",
|
|
11
|
+
"bugs": "https://github.com/brimdata/react-arborist/issues",
|
|
11
12
|
"keywords": [
|
|
12
13
|
"react",
|
|
13
14
|
"arborist",
|
|
@@ -73,44 +73,47 @@ export function DefaultContainer() {
|
|
|
73
73
|
focusPrevElement(e.currentTarget);
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
if (e.key === "ArrowDown"
|
|
76
|
+
if (e.key === "ArrowDown") {
|
|
77
77
|
e.preventDefault();
|
|
78
78
|
const next = tree.nextNode;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
e.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const current = tree.focusedNode;
|
|
87
|
-
if (!current) {
|
|
88
|
-
tree.focus(tree.firstNode);
|
|
89
|
-
} else if (current.isSelected) {
|
|
90
|
-
tree.selectContiguous(next);
|
|
79
|
+
if (e.metaKey) {
|
|
80
|
+
tree.select(tree.focusedNode);
|
|
81
|
+
tree.activate(tree.focusedNode);
|
|
82
|
+
return;
|
|
83
|
+
} else if (!e.shiftKey || tree.props.disableMultiSelection) {
|
|
84
|
+
tree.focus(next);
|
|
85
|
+
return;
|
|
91
86
|
} else {
|
|
92
|
-
|
|
87
|
+
if (!next) return;
|
|
88
|
+
const current = tree.focusedNode;
|
|
89
|
+
if (!current) {
|
|
90
|
+
tree.focus(tree.firstNode);
|
|
91
|
+
} else if (current.isSelected) {
|
|
92
|
+
tree.selectContiguous(next);
|
|
93
|
+
} else {
|
|
94
|
+
tree.selectMulti(next);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
93
97
|
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (e.key === "ArrowUp" && !e.shiftKey) {
|
|
97
|
-
e.preventDefault();
|
|
98
|
-
tree.focus(tree.prevNode);
|
|
99
|
-
return;
|
|
100
98
|
}
|
|
101
|
-
if (e.key === "ArrowUp"
|
|
99
|
+
if (e.key === "ArrowUp") {
|
|
102
100
|
e.preventDefault();
|
|
103
101
|
const prev = tree.prevNode;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
tree.focus(tree.lastNode); // ?
|
|
108
|
-
} else if (current.isSelected) {
|
|
109
|
-
tree.selectContiguous(prev);
|
|
102
|
+
if (!e.shiftKey || tree.props.disableMultiSelection) {
|
|
103
|
+
tree.focus(prev);
|
|
104
|
+
return;
|
|
110
105
|
} else {
|
|
111
|
-
|
|
106
|
+
if (!prev) return;
|
|
107
|
+
const current = tree.focusedNode;
|
|
108
|
+
if (!current) {
|
|
109
|
+
tree.focus(tree.lastNode); // ?
|
|
110
|
+
} else if (current.isSelected) {
|
|
111
|
+
tree.selectContiguous(prev);
|
|
112
|
+
} else {
|
|
113
|
+
tree.selectMulti(prev);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
112
116
|
}
|
|
113
|
-
return;
|
|
114
117
|
}
|
|
115
118
|
if (e.key === "ArrowRight") {
|
|
116
119
|
const node = tree.focusedNode;
|
|
@@ -129,7 +132,7 @@ export function DefaultContainer() {
|
|
|
129
132
|
}
|
|
130
133
|
return;
|
|
131
134
|
}
|
|
132
|
-
if (e.key === "a" && e.metaKey) {
|
|
135
|
+
if (e.key === "a" && e.metaKey && !tree.props.disableMultiSelection) {
|
|
133
136
|
e.preventDefault();
|
|
134
137
|
tree.selectAll();
|
|
135
138
|
return;
|
|
@@ -182,12 +185,6 @@ export function DefaultContainer() {
|
|
|
182
185
|
tree.openSiblings(node);
|
|
183
186
|
return;
|
|
184
187
|
}
|
|
185
|
-
if (e.key === "ArrowDown" && e.metaKey) {
|
|
186
|
-
e.preventDefault();
|
|
187
|
-
tree.select(tree.focusedNode);
|
|
188
|
-
tree.activate(tree.focusedNode);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
188
|
if (e.key === "PageUp") {
|
|
192
189
|
e.preventDefault();
|
|
193
190
|
tree.pageUp();
|
|
@@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
|
2
2
|
import { useDataUpdates, useNodesContext, useTreeApi } from "../context";
|
|
3
3
|
import { useDragHook } from "../dnd/drag-hook";
|
|
4
4
|
import { useDropHook } from "../dnd/drop-hook";
|
|
5
|
-
import { IdObj } from "../types/utils";
|
|
6
5
|
import { useFreshNode } from "../hooks/use-fresh-node";
|
|
7
6
|
|
|
8
7
|
type Props = {
|
|
@@ -68,7 +67,7 @@ export const RowContainer = React.memo(function RowContainer<T>({
|
|
|
68
67
|
|
|
69
68
|
useEffect(() => {
|
|
70
69
|
if (!node.isEditing && node.isFocused) {
|
|
71
|
-
el.current?.focus();
|
|
70
|
+
el.current?.focus({ preventScroll: true });
|
|
72
71
|
}
|
|
73
72
|
}, [node.isEditing, node.isFocused, el.current]);
|
|
74
73
|
|
package/src/data/create-root.ts
CHANGED
|
@@ -44,7 +44,7 @@ export function createRoot<T>(tree: TreeApi<T>): NodeApi<T> {
|
|
|
44
44
|
rowIndex: null,
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
const data: T[] = tree.props.data ?? [];
|
|
47
|
+
const data: readonly T[] = tree.props.data ?? [];
|
|
48
48
|
|
|
49
49
|
root.children = data.map((child) => {
|
|
50
50
|
return visitSelfAndChildren(child, 0, root);
|
|
@@ -16,7 +16,7 @@ export type SimpleTreeData = {
|
|
|
16
16
|
|
|
17
17
|
let nextId = 0;
|
|
18
18
|
|
|
19
|
-
export function useSimpleTree<T>(initialData: T[]) {
|
|
19
|
+
export function useSimpleTree<T>(initialData: readonly T[]) {
|
|
20
20
|
const [data, setData] = useState(initialData);
|
|
21
21
|
const tree = useMemo(
|
|
22
22
|
() =>
|
|
@@ -186,9 +186,9 @@ export class NodeApi<T = any> {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
handleClick = (e: React.MouseEvent) => {
|
|
189
|
-
if (e.metaKey) {
|
|
189
|
+
if (e.metaKey && !this.tree.props.disableMultiSelection) {
|
|
190
190
|
this.isSelected ? this.deselect() : this.selectMulti();
|
|
191
|
-
} else if (e.shiftKey) {
|
|
191
|
+
} else if (e.shiftKey && !this.tree.props.disableMultiSelection) {
|
|
192
192
|
this.selectContiguous();
|
|
193
193
|
} else {
|
|
194
194
|
this.select();
|
package/src/types/tree-props.ts
CHANGED
|
@@ -8,8 +8,8 @@ import { OpenMap, OpenSlice } from "../state/open-slice";
|
|
|
8
8
|
|
|
9
9
|
export interface TreeProps<T> {
|
|
10
10
|
/* Data Options */
|
|
11
|
-
data?: T[];
|
|
12
|
-
initialData?: T[];
|
|
11
|
+
data?: readonly T[];
|
|
12
|
+
initialData?: readonly T[];
|
|
13
13
|
|
|
14
14
|
/* Data Handlers */
|
|
15
15
|
onCreate?: handlers.CreateHandler<T>;
|
|
@@ -26,7 +26,7 @@ export interface TreeProps<T> {
|
|
|
26
26
|
|
|
27
27
|
/* Sizes */
|
|
28
28
|
rowHeight?: number;
|
|
29
|
-
width?: number;
|
|
29
|
+
width?: number | string;
|
|
30
30
|
height?: number;
|
|
31
31
|
indent?: number;
|
|
32
32
|
paddingTop?: number;
|
|
@@ -36,9 +36,10 @@ export interface TreeProps<T> {
|
|
|
36
36
|
/* Config */
|
|
37
37
|
openByDefault?: boolean;
|
|
38
38
|
selectionFollowsFocus?: boolean;
|
|
39
|
+
disableMultiSelection?: boolean;
|
|
39
40
|
disableDrag?: string | boolean | BoolFunc<T>;
|
|
40
41
|
disableDrop?: string | boolean | BoolFunc<T>;
|
|
41
|
-
childrenAccessor?: string | ((d: T) => T[]);
|
|
42
|
+
childrenAccessor?: string | ((d: T) => T[] | null);
|
|
42
43
|
idAccessor?: string | ((d: T) => string);
|
|
43
44
|
|
|
44
45
|
/* Event Handlers */
|