@rovula/ui 0.0.49 → 0.0.50

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.
@@ -3,6 +3,7 @@ import Tree from "./Tree";
3
3
  declare const meta: Meta<typeof Tree>;
4
4
  export default meta;
5
5
  export declare const Default: StoryObj<typeof Tree>;
6
+ export declare const Controller: StoryObj<typeof Tree>;
6
7
  export declare const onClick: StoryObj<typeof Tree>;
7
8
  export declare const CustomIcon: StoryObj<typeof Tree>;
8
9
  export declare const renderRightSection: StoryObj<typeof Tree>;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useState } from "react";
3
3
  import TreeItem from "./TreeItem";
4
- const Tree = ({ classes, data, defaultExpandedId = [], defaultCheckedId = [], checkedId, loadingId, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, }) => {
4
+ const Tree = ({ classes, data, defaultExpandedId, defaultCheckedId, checkedId, loadingId, renderIcon, renderRightSection, renderElement, renderTitle, onExpandChange, onCheckedChange, defaultExpandAll = false, defaultCheckAll = false, hierarchicalCheck = false, showIcon = true, disabled, enableSeparatorLine = true, }) => {
5
5
  const [checkedState, setCheckedState] = useState({});
6
6
  const [expandedState, setExpandedState] = useState({});
7
7
  const traverseTree = (nodes, callback) => {
@@ -13,7 +13,7 @@ const Tree = ({ classes, data, defaultExpandedId = [], defaultCheckedId = [], ch
13
13
  });
14
14
  };
15
15
  useEffect(() => {
16
- if (defaultExpandAll) {
16
+ if (data.length && defaultExpandAll) {
17
17
  const allExpanded = {};
18
18
  traverseTree(data, (node) => {
19
19
  allExpanded[node.id] = true;
@@ -29,21 +29,23 @@ const Tree = ({ classes, data, defaultExpandedId = [], defaultCheckedId = [], ch
29
29
  }
30
30
  }, [data, defaultExpandedId, defaultExpandAll]);
31
31
  useEffect(() => {
32
- if (defaultCheckAll) {
32
+ var _a;
33
+ if (data.length && defaultCheckAll) {
33
34
  const allChecked = {};
34
35
  traverseTree(data, (node) => {
35
36
  allChecked[node.id] = true;
36
37
  });
37
38
  setCheckedState(allChecked);
38
39
  }
39
- else if (!checkedId && (defaultCheckedId === null || defaultCheckedId === void 0 ? void 0 : defaultCheckedId.length)) {
40
+ else if (((_a = Object.keys(checkedState)) === null || _a === void 0 ? void 0 : _a.length) === 0 &&
41
+ (defaultCheckedId === null || defaultCheckedId === void 0 ? void 0 : defaultCheckedId.length)) {
40
42
  const initialCheckedState = defaultCheckedId.reduce((acc, id) => {
41
43
  acc[id] = true;
42
44
  return acc;
43
45
  }, {});
44
46
  setCheckedState(initialCheckedState);
45
47
  }
46
- }, [data, defaultCheckedId, checkedId, defaultCheckAll]);
48
+ }, [data, defaultCheckedId, defaultCheckAll]);
47
49
  const handleExpandChange = useCallback((id, expanded) => {
48
50
  onExpandChange === null || onExpandChange === void 0 ? void 0 : onExpandChange(id, expanded);
49
51
  setExpandedState((prev) => (Object.assign(Object.assign({}, prev), { [id]: expanded })));