react-arborist 3.6.0 → 3.6.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.
@@ -29,7 +29,14 @@ function TreeProvider({ treeProps, imperativeHandle, children, }) {
29
29
  (0, react_1.useMemo)(() => {
30
30
  updateCount.current += 1;
31
31
  api.update(treeProps);
32
- }, [...Object.values(treeProps), state.nodes.open]);
32
+ }, [...Object.values(treeProps)]);
33
+ /* Rebuild visible nodes when open state changes, without clobbering
34
+ props set imperatively via api.update(). Bumping updateCount keeps
35
+ DataUpdates consumers (e.g. DefaultContainer) in sync. */
36
+ (0, react_1.useMemo)(() => {
37
+ updateCount.current += 1;
38
+ api.update(api.props);
39
+ }, [state.nodes.open]);
33
40
  /* Expose the tree api */
34
41
  (0, react_1.useImperativeHandle)(imperativeHandle, () => api);
35
42
  /* Change selection based on props */
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const react_1 = require("react");
5
+ const react_2 = require("@testing-library/react");
6
+ const tree_1 = require("./tree");
7
+ const data = [
8
+ {
9
+ id: "1",
10
+ name: "root",
11
+ children: [
12
+ { id: "2", name: "a" },
13
+ { id: "3", name: "b", children: [{ id: "4", name: "c" }] },
14
+ ],
15
+ },
16
+ ];
17
+ test("imperative tree.update() props survive node toggles (#228)", () => {
18
+ const ref = (0, react_1.createRef)();
19
+ (0, react_2.render)((0, jsx_runtime_1.jsx)(tree_1.Tree, { data: data, ref: ref, rowHeight: 24, openByDefault: false }));
20
+ const api = ref.current;
21
+ expect(api.rowHeight).toBe(24);
22
+ (0, react_2.act)(() => {
23
+ api.update(Object.assign(Object.assign({}, api.props), { rowHeight: 48 }));
24
+ });
25
+ expect(api.rowHeight).toBe(48);
26
+ /* Opening a node dispatches a redux action that changes state.nodes.open.
27
+ Before #337, the open-state effect re-ran api.update(treeProps), reverting
28
+ rowHeight to 24. */
29
+ (0, react_2.act)(() => {
30
+ api.open("1");
31
+ });
32
+ expect(api.rowHeight).toBe(48);
33
+ });
@@ -26,7 +26,14 @@ export function TreeProvider({ treeProps, imperativeHandle, children, }) {
26
26
  useMemo(() => {
27
27
  updateCount.current += 1;
28
28
  api.update(treeProps);
29
- }, [...Object.values(treeProps), state.nodes.open]);
29
+ }, [...Object.values(treeProps)]);
30
+ /* Rebuild visible nodes when open state changes, without clobbering
31
+ props set imperatively via api.update(). Bumping updateCount keeps
32
+ DataUpdates consumers (e.g. DefaultContainer) in sync. */
33
+ useMemo(() => {
34
+ updateCount.current += 1;
35
+ api.update(api.props);
36
+ }, [state.nodes.open]);
30
37
  /* Expose the tree api */
31
38
  useImperativeHandle(imperativeHandle, () => api);
32
39
  /* Change selection based on props */
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createRef } from "react";
3
+ import { act, render } from "@testing-library/react";
4
+ import { Tree } from "./tree";
5
+ const data = [
6
+ {
7
+ id: "1",
8
+ name: "root",
9
+ children: [
10
+ { id: "2", name: "a" },
11
+ { id: "3", name: "b", children: [{ id: "4", name: "c" }] },
12
+ ],
13
+ },
14
+ ];
15
+ test("imperative tree.update() props survive node toggles (#228)", () => {
16
+ const ref = createRef();
17
+ render(_jsx(Tree, { data: data, ref: ref, rowHeight: 24, openByDefault: false }));
18
+ const api = ref.current;
19
+ expect(api.rowHeight).toBe(24);
20
+ act(() => {
21
+ api.update(Object.assign(Object.assign({}, api.props), { rowHeight: 48 }));
22
+ });
23
+ expect(api.rowHeight).toBe(48);
24
+ /* Opening a node dispatches a redux action that changes state.nodes.open.
25
+ Before #337, the open-state effect re-ran api.update(treeProps), reverting
26
+ rowHeight to 24. */
27
+ act(() => {
28
+ api.open("1");
29
+ });
30
+ expect(api.rowHeight).toBe(48);
31
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-arborist",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main/index.js",
@@ -49,12 +49,18 @@
49
49
  "react-dom": ">= 16.14"
50
50
  },
51
51
  "devDependencies": {
52
+ "@testing-library/dom": "^9.3.0",
53
+ "@testing-library/react": "^14.0.0",
52
54
  "@types/jest": "^29.5.11",
53
55
  "@types/react": "^18.2.43",
56
+ "@types/react-dom": "^18.2.0",
54
57
  "@types/react-window": "^1.8.8",
55
58
  "@types/use-sync-external-store": "^0.0.6",
56
59
  "jest": "^29.7.0",
60
+ "jest-environment-jsdom": "^29.7.0",
57
61
  "npm-run-all": "^4.1.5",
62
+ "react": "^18.2.0",
63
+ "react-dom": "^18.2.0",
58
64
  "rimraf": "^5.0.5",
59
65
  "ts-jest": "^29.1.1",
60
66
  "typescript": "^5.6.0"
@@ -0,0 +1,44 @@
1
+ import { createRef } from "react";
2
+ import { act, render } from "@testing-library/react";
3
+ import { Tree } from "./tree";
4
+ import { TreeApi } from "../interfaces/tree-api";
5
+
6
+ type Datum = { id: string; name: string; children?: Datum[] };
7
+
8
+ const data: Datum[] = [
9
+ {
10
+ id: "1",
11
+ name: "root",
12
+ children: [
13
+ { id: "2", name: "a" },
14
+ { id: "3", name: "b", children: [{ id: "4", name: "c" }] },
15
+ ],
16
+ },
17
+ ];
18
+
19
+ test("imperative tree.update() props survive node toggles (#228)", () => {
20
+ const ref = createRef<TreeApi<Datum> | undefined>();
21
+ render(
22
+ <Tree<Datum>
23
+ data={data}
24
+ ref={ref}
25
+ rowHeight={24}
26
+ openByDefault={false}
27
+ />
28
+ );
29
+ const api = ref.current!;
30
+ expect(api.rowHeight).toBe(24);
31
+
32
+ act(() => {
33
+ api.update({ ...api.props, rowHeight: 48 });
34
+ });
35
+ expect(api.rowHeight).toBe(48);
36
+
37
+ /* Opening a node dispatches a redux action that changes state.nodes.open.
38
+ Before #337, the open-state effect re-ran api.update(treeProps), reverting
39
+ rowHeight to 24. */
40
+ act(() => {
41
+ api.open("1");
42
+ });
43
+ expect(api.rowHeight).toBe(48);
44
+ });
@@ -57,7 +57,15 @@ export function TreeProvider<T>({
57
57
  useMemo(() => {
58
58
  updateCount.current += 1;
59
59
  api.update(treeProps);
60
- }, [...Object.values(treeProps), state.nodes.open]);
60
+ }, [...Object.values(treeProps)]);
61
+
62
+ /* Rebuild visible nodes when open state changes, without clobbering
63
+ props set imperatively via api.update(). Bumping updateCount keeps
64
+ DataUpdates consumers (e.g. DefaultContainer) in sync. */
65
+ useMemo(() => {
66
+ updateCount.current += 1;
67
+ api.update(api.props);
68
+ }, [state.nodes.open]);
61
69
 
62
70
  /* Expose the tree api */
63
71
  useImperativeHandle(imperativeHandle, () => api);