react-arborist 3.4.1 → 3.4.3

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.
@@ -68,6 +68,7 @@ exports.RowContainer = react_1.default.memo(function RowContainer({ index, style
68
68
  role: "treeitem",
69
69
  "aria-level": node.level + 1,
70
70
  "aria-selected": node.isSelected,
71
+ "aria-expanded": node.isOpen,
71
72
  style: rowStyle,
72
73
  tabIndex: -1,
73
74
  className: tree.props.rowClassName,
@@ -6,8 +6,6 @@ const react_dnd_1 = require("react-dnd");
6
6
  const react_dnd_html5_backend_1 = require("react-dnd-html5-backend");
7
7
  const context_1 = require("../context");
8
8
  const dnd_slice_1 = require("../state/dnd-slice");
9
- const utils_1 = require("../utils");
10
- const create_root_1 = require("../data/create-root");
11
9
  function useDragHook(node) {
12
10
  const tree = (0, context_1.useTreeApi)();
13
11
  const ids = tree.selectedIds;
@@ -22,19 +20,6 @@ function useDragHook(node) {
22
20
  },
23
21
  end: () => {
24
22
  tree.hideCursor();
25
- let { parentId, index, dragIds } = tree.state.dnd;
26
- // If they held down meta, we need to create a copy
27
- // if (drop.dropEffect === "copy")
28
- if (tree.canDrop()) {
29
- (0, utils_1.safeRun)(tree.props.onMove, {
30
- dragIds,
31
- parentId: parentId === create_root_1.ROOT_ID ? null : parentId,
32
- index: index === null ? 0 : index, // When it's null it was dropped over a folder
33
- dragNodes: tree.dragNodes,
34
- parentNode: tree.get(parentId),
35
- });
36
- tree.open(parentId);
37
- }
38
23
  tree.dispatch(dnd_slice_1.actions.dragEnd());
39
24
  },
40
25
  }), [ids, node]);
@@ -5,6 +5,8 @@ const react_dnd_1 = require("react-dnd");
5
5
  const context_1 = require("../context");
6
6
  const compute_drop_1 = require("./compute-drop");
7
7
  const dnd_slice_1 = require("../state/dnd-slice");
8
+ const utils_1 = require("../utils");
9
+ const create_root_1 = require("../data/create-root");
8
10
  function useDropHook(el, node) {
9
11
  const tree = (0, context_1.useTreeApi)();
10
12
  const [_, dropRef] = (0, react_dnd_1.useDrop)(() => ({
@@ -35,6 +37,15 @@ function useDropHook(el, node) {
35
37
  drop: (_, m) => {
36
38
  if (!m.canDrop())
37
39
  return null;
40
+ let { parentId, index, dragIds } = tree.state.dnd;
41
+ (0, utils_1.safeRun)(tree.props.onMove, {
42
+ dragIds,
43
+ parentId: parentId === create_root_1.ROOT_ID ? null : parentId,
44
+ index: index === null ? 0 : index, // When it's null it was dropped over a folder
45
+ dragNodes: tree.dragNodes,
46
+ parentNode: tree.get(parentId),
47
+ });
48
+ tree.open(parentId);
38
49
  },
39
50
  }), [node, el.current, tree.props]);
40
51
  return dropRef;
@@ -347,6 +347,7 @@ class TreeApi {
347
347
  return;
348
348
  const id = identify(node);
349
349
  this.dispatch(selection_slice_1.actions.remove(id));
350
+ safeRun(this.props.onSelect, this.selectedNodes);
350
351
  }
351
352
  selectMulti(identity) {
352
353
  const node = this.get(identifyNull(identity));
@@ -42,6 +42,7 @@ export const RowContainer = React.memo(function RowContainer({ index, style, })
42
42
  role: "treeitem",
43
43
  "aria-level": node.level + 1,
44
44
  "aria-selected": node.isSelected,
45
+ "aria-expanded": node.isOpen,
45
46
  style: rowStyle,
46
47
  tabIndex: -1,
47
48
  className: tree.props.rowClassName,
@@ -3,8 +3,6 @@ import { useDrag } from "react-dnd";
3
3
  import { getEmptyImage } from "react-dnd-html5-backend";
4
4
  import { useTreeApi } from "../context";
5
5
  import { actions as dnd } from "../state/dnd-slice";
6
- import { safeRun } from "../utils";
7
- import { ROOT_ID } from "../data/create-root";
8
6
  export function useDragHook(node) {
9
7
  const tree = useTreeApi();
10
8
  const ids = tree.selectedIds;
@@ -19,19 +17,6 @@ export function useDragHook(node) {
19
17
  },
20
18
  end: () => {
21
19
  tree.hideCursor();
22
- let { parentId, index, dragIds } = tree.state.dnd;
23
- // If they held down meta, we need to create a copy
24
- // if (drop.dropEffect === "copy")
25
- if (tree.canDrop()) {
26
- safeRun(tree.props.onMove, {
27
- dragIds,
28
- parentId: parentId === ROOT_ID ? null : parentId,
29
- index: index === null ? 0 : index, // When it's null it was dropped over a folder
30
- dragNodes: tree.dragNodes,
31
- parentNode: tree.get(parentId),
32
- });
33
- tree.open(parentId);
34
- }
35
20
  tree.dispatch(dnd.dragEnd());
36
21
  },
37
22
  }), [ids, node]);
@@ -2,6 +2,8 @@ import { useDrop } from "react-dnd";
2
2
  import { useTreeApi } from "../context";
3
3
  import { computeDrop } from "./compute-drop";
4
4
  import { actions as dnd } from "../state/dnd-slice";
5
+ import { safeRun } from "../utils";
6
+ import { ROOT_ID } from "../data/create-root";
5
7
  export function useDropHook(el, node) {
6
8
  const tree = useTreeApi();
7
9
  const [_, dropRef] = useDrop(() => ({
@@ -32,6 +34,15 @@ export function useDropHook(el, node) {
32
34
  drop: (_, m) => {
33
35
  if (!m.canDrop())
34
36
  return null;
37
+ let { parentId, index, dragIds } = tree.state.dnd;
38
+ safeRun(tree.props.onMove, {
39
+ dragIds,
40
+ parentId: parentId === ROOT_ID ? null : parentId,
41
+ index: index === null ? 0 : index, // When it's null it was dropped over a folder
42
+ dragNodes: tree.dragNodes,
43
+ parentNode: tree.get(parentId),
44
+ });
45
+ tree.open(parentId);
35
46
  },
36
47
  }), [node, el.current, tree.props]);
37
48
  return dropRef;
@@ -321,6 +321,7 @@ export class TreeApi {
321
321
  return;
322
322
  const id = identify(node);
323
323
  this.dispatch(selection.remove(id));
324
+ safeRun(this.props.onSelect, this.selectedNodes);
324
325
  }
325
326
  selectMulti(identity) {
326
327
  const node = this.get(identifyNull(identity));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-arborist",
3
- "version": "3.4.1",
3
+ "version": "3.4.3",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main/index.js",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "react-dnd": "^14.0.3",
42
42
  "react-dnd-html5-backend": "^14.0.3",
43
- "react-window": "^1.8.10",
43
+ "react-window": "^1.8.11",
44
44
  "redux": "^5.0.0",
45
45
  "use-sync-external-store": "^1.2.0"
46
46
  },
@@ -60,6 +60,7 @@ export const RowContainer = React.memo(function RowContainer<T>({
60
60
  role: "treeitem",
61
61
  "aria-level": node.level + 1,
62
62
  "aria-selected": node.isSelected,
63
+ "aria-expanded": node.isOpen,
63
64
  style: rowStyle,
64
65
  tabIndex: -1,
65
66
  className: tree.props.rowClassName,
@@ -6,8 +6,6 @@ import { NodeApi } from "../interfaces/node-api";
6
6
  import { DragItem } from "../types/dnd";
7
7
  import { DropResult } from "./drop-hook";
8
8
  import { actions as dnd } from "../state/dnd-slice";
9
- import { safeRun } from "../utils";
10
- import { ROOT_ID } from "../data/create-root";
11
9
 
12
10
  export function useDragHook<T>(node: NodeApi<T>): ConnectDragSource {
13
11
  const tree = useTreeApi();
@@ -24,23 +22,10 @@ export function useDragHook<T>(node: NodeApi<T>): ConnectDragSource {
24
22
  },
25
23
  end: () => {
26
24
  tree.hideCursor();
27
- let { parentId, index, dragIds } = tree.state.dnd;
28
- // If they held down meta, we need to create a copy
29
- // if (drop.dropEffect === "copy")
30
- if (tree.canDrop()) {
31
- safeRun(tree.props.onMove, {
32
- dragIds,
33
- parentId: parentId === ROOT_ID ? null : parentId,
34
- index: index === null ? 0 : index, // When it's null it was dropped over a folder
35
- dragNodes: tree.dragNodes,
36
- parentNode: tree.get(parentId),
37
- });
38
- tree.open(parentId);
39
- }
40
25
  tree.dispatch(dnd.dragEnd());
41
26
  },
42
27
  }),
43
- [ids, node]
28
+ [ids, node],
44
29
  );
45
30
 
46
31
  useEffect(() => {
@@ -5,6 +5,8 @@ import { NodeApi } from "../interfaces/node-api";
5
5
  import { DragItem } from "../types/dnd";
6
6
  import { computeDrop } from "./compute-drop";
7
7
  import { actions as dnd } from "../state/dnd-slice";
8
+ import { safeRun } from "../utils";
9
+ import { ROOT_ID } from "../data/create-root";
8
10
 
9
11
  export type DropResult = {
10
12
  parentId: string | null;
@@ -13,7 +15,7 @@ export type DropResult = {
13
15
 
14
16
  export function useDropHook(
15
17
  el: RefObject<HTMLElement | null>,
16
- node: NodeApi<any>
18
+ node: NodeApi<any>,
17
19
  ): ConnectDropTarget {
18
20
  const tree = useTreeApi();
19
21
  const [_, dropRef] = useDrop<DragItem, DropResult | null, void>(
@@ -41,9 +43,18 @@ export function useDropHook(
41
43
  },
42
44
  drop: (_, m) => {
43
45
  if (!m.canDrop()) return null;
46
+ let { parentId, index, dragIds } = tree.state.dnd;
47
+ safeRun(tree.props.onMove, {
48
+ dragIds,
49
+ parentId: parentId === ROOT_ID ? null : parentId,
50
+ index: index === null ? 0 : index, // When it's null it was dropped over a folder
51
+ dragNodes: tree.dragNodes,
52
+ parentNode: tree.get(parentId),
53
+ });
54
+ tree.open(parentId);
44
55
  },
45
56
  }),
46
- [node, el.current, tree.props]
57
+ [node, el.current, tree.props],
47
58
  );
48
59
 
49
60
  return dropRef;
@@ -342,6 +342,7 @@ export class TreeApi<T> {
342
342
  if (!node) return;
343
343
  const id = identify(node);
344
344
  this.dispatch(selection.remove(id));
345
+ safeRun(this.props.onSelect, this.selectedNodes);
345
346
  }
346
347
 
347
348
  selectMulti(identity: Identity) {