react-arborist 3.1.0 → 3.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.
@@ -20,9 +20,15 @@ export declare const actions: {
20
20
  type: "SELECTION_REMOVE";
21
21
  ids: string[];
22
22
  };
23
- set: (ids: Set<string>) => {
24
- type: "SELECTION_SET";
23
+ set: (args: {
24
+ ids: Set<string>;
25
+ anchor: string | null;
26
+ mostRecent: string | null;
27
+ }) => {
25
28
  ids: Set<string>;
29
+ anchor: string | null;
30
+ mostRecent: string | null;
31
+ type: "SELECTION_SET";
26
32
  };
27
33
  mostRecent: (id: string | null | IdObj) => {
28
34
  type: "SELECTION_MOST_RECENT";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-arborist",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,6 @@ import {
14
14
  TreeApiContext,
15
15
  } from "../context";
16
16
  import { TreeApi } from "../interfaces/tree-api";
17
- import { IdObj } from "../types/utils";
18
17
  import { initialState } from "../state/initial";
19
18
  import { rootReducer, RootState } from "../state/root-reducer";
20
19
  import { HTML5Backend } from "react-dnd-html5-backend";
@@ -370,21 +370,33 @@ export class TreeApi<T> {
370
370
  }
371
371
 
372
372
  deselectAll() {
373
- this.dispatch(selection.clear());
374
- this.dispatch(selection.anchor(null));
375
- this.dispatch(selection.mostRecent(null));
373
+ this.setSelection({ ids: [], anchor: null, mostRecent: null });
376
374
  safeRun(this.props.onSelect, this.selectedNodes);
377
375
  }
378
376
 
379
377
  selectAll() {
380
- this.dispatch(selection.set(new Set(Object.keys(this.idToIndex))));
378
+ this.setSelection({
379
+ ids: Object.keys(this.idToIndex),
380
+ anchor: this.firstNode,
381
+ mostRecent: this.lastNode,
382
+ });
381
383
  this.dispatch(focus(this.lastNode?.id));
382
- this.dispatch(selection.anchor(this.firstNode));
383
- this.dispatch(selection.mostRecent(this.lastNode));
384
384
  if (this.focusedNode) safeRun(this.props.onFocus, this.focusedNode);
385
385
  safeRun(this.props.onSelect, this.selectedNodes);
386
386
  }
387
387
 
388
+ setSelection(args: {
389
+ ids: (IdObj | string)[] | null;
390
+ anchor: IdObj | string | null;
391
+ mostRecent: IdObj | string | null;
392
+ }) {
393
+ const ids = new Set(args.ids?.map(identify));
394
+ const anchor = identifyNull(args.anchor);
395
+ const mostRecent = identifyNull(args.mostRecent);
396
+ this.dispatch(selection.set({ ids, anchor, mostRecent }));
397
+ safeRun(this.props.onSelect, this.selectedNodes);
398
+ }
399
+
388
400
  /* Drag and Drop */
389
401
 
390
402
  get cursorParentId() {
@@ -28,9 +28,13 @@ export const actions = {
28
28
  ids: (Array.isArray(id) ? id : [id]).map(identify),
29
29
  }),
30
30
 
31
- set: (ids: Set<string>) => ({
31
+ set: (args: {
32
+ ids: Set<string>;
33
+ anchor: string | null;
34
+ mostRecent: string | null;
35
+ }) => ({
32
36
  type: "SELECTION_SET" as const,
33
- ids,
37
+ ...args,
34
38
  }),
35
39
 
36
40
  mostRecent: (id: string | null | IdObj) => ({
@@ -64,7 +68,12 @@ export function reducer(
64
68
  action.ids.forEach((id) => ids.delete(id));
65
69
  return { ...state, ids: new Set(ids) };
66
70
  case "SELECTION_SET":
67
- return { ...state, ids: new Set(action.ids) };
71
+ return {
72
+ ...state,
73
+ ids: action.ids,
74
+ mostRecent: action.mostRecent,
75
+ anchor: action.anchor,
76
+ };
68
77
  case "SELECTION_MOST_RECENT":
69
78
  return { ...state, mostRecent: action.id };
70
79
  case "SELECTION_ANCHOR":
@@ -5,7 +5,7 @@ import { ElementType, MouseEventHandler } from "react";
5
5
  import { ListOnScrollProps } from "react-window";
6
6
  import { NodeApi } from "../interfaces/node-api";
7
7
  import { OpenMap } from "../state/open-slice";
8
- import { useDragDropManager } from "react-dnd"
8
+ import { useDragDropManager } from "react-dnd";
9
9
 
10
10
  export interface TreeProps<T> {
11
11
  /* Data Options */
@@ -76,5 +76,5 @@ export interface TreeProps<T> {
76
76
  dndRootElement?: globalThis.Node | null;
77
77
  onClick?: MouseEventHandler;
78
78
  onContextMenu?: MouseEventHandler;
79
- dndManager?: ReturnType<typeof useDragDropManager>
79
+ dndManager?: ReturnType<typeof useDragDropManager>;
80
80
  }