@reltio/components 1.4.1958 → 1.4.1959

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.
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
1
  import { TreeNodeProps } from 'rc-tree';
2
+ import React from 'react';
3
3
  import { RCTreeNode } from './types';
4
4
  type Props = {
5
5
  treeData: RCTreeNode[];
@@ -14,7 +14,8 @@ type Props = {
14
14
  className?: string;
15
15
  minItemHeight?: number;
16
16
  isLeaf?: (node: TreeNodeProps & Record<string, unknown>) => boolean;
17
+ scrollToNode?: RCTreeNode;
17
18
  onChange?: (node: RCTreeNode[]) => void;
18
19
  };
19
- export declare const RCTree: ({ treeData, isVirtualized, canDrag, canDrop, onLoadChildren, height, defaultExpandAll, SwitchRenderer, className, renderNode, minItemHeight, isLeaf, onChange, }: Props) => React.JSX.Element;
20
+ export declare const RCTree: ({ treeData, isVirtualized, canDrag, canDrop, onLoadChildren, height, defaultExpandAll, SwitchRenderer, className, renderNode, minItemHeight, isLeaf, scrollToNode, onChange }: Props) => React.JSX.Element;
20
21
  export {};
@@ -27,18 +27,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.RCTree = void 0;
30
- var react_1 = __importStar(require("react"));
30
+ var classnames_1 = __importDefault(require("classnames"));
31
31
  var ramda_1 = require("ramda");
32
32
  var rc_tree_1 = __importDefault(require("rc-tree"));
33
- var classnames_1 = __importDefault(require("classnames"));
33
+ var react_1 = __importStar(require("react"));
34
34
  var DefaultSwitchRenderer_1 = require("./DefaultSwitchRenderer");
35
35
  var helper_1 = require("./helper");
36
36
  var styles_1 = require("./styles");
37
37
  var MIN_ROW_HEIGHT = 28;
38
38
  var RCTree = function (_a) {
39
- var treeData = _a.treeData, _b = _a.isVirtualized, isVirtualized = _b === void 0 ? true : _b, _c = _a.canDrag, canDrag = _c === void 0 ? false : _c, _d = _a.canDrop, canDrop = _d === void 0 ? function () { return false; } : _d, onLoadChildren = _a.onLoadChildren, height = _a.height, _e = _a.defaultExpandAll, defaultExpandAll = _e === void 0 ? false : _e, _f = _a.SwitchRenderer, SwitchRenderer = _f === void 0 ? DefaultSwitchRenderer_1.DefaultSwitchRenderer : _f, className = _a.className, renderNode = _a.renderNode, _g = _a.minItemHeight, minItemHeight = _g === void 0 ? MIN_ROW_HEIGHT : _g, _h = _a.isLeaf, isLeaf = _h === void 0 ? helper_1.defaultIsLeaf : _h, _j = _a.onChange, onChange = _j === void 0 ? ramda_1.identity : _j;
39
+ var treeData = _a.treeData, _b = _a.isVirtualized, isVirtualized = _b === void 0 ? true : _b, _c = _a.canDrag, canDrag = _c === void 0 ? false : _c, _d = _a.canDrop, canDrop = _d === void 0 ? function () { return false; } : _d, onLoadChildren = _a.onLoadChildren, height = _a.height, _e = _a.defaultExpandAll, defaultExpandAll = _e === void 0 ? false : _e, _f = _a.SwitchRenderer, SwitchRenderer = _f === void 0 ? DefaultSwitchRenderer_1.DefaultSwitchRenderer : _f, className = _a.className, renderNode = _a.renderNode, _g = _a.minItemHeight, minItemHeight = _g === void 0 ? MIN_ROW_HEIGHT : _g, _h = _a.isLeaf, isLeaf = _h === void 0 ? helper_1.defaultIsLeaf : _h, scrollToNode = _a.scrollToNode, _j = _a.onChange, onChange = _j === void 0 ? ramda_1.identity : _j;
40
40
  var styles = (0, styles_1.useStyles)();
41
41
  var internalTreeData = (0, react_1.useMemo)(function () { return (0, helper_1.convertTreeData)({ data: treeData, isLeaf: isLeaf }); }, [isLeaf, treeData]);
42
+ var treeRef = (0, react_1.useRef)(null);
43
+ (0, react_1.useEffect)(function () {
44
+ if (treeRef.current && scrollToNode) {
45
+ treeRef.current.scrollTo({ key: String(scrollToNode.nodeId) });
46
+ }
47
+ }, [scrollToNode]);
42
48
  // eslint-disable-next-line no-unused-vars
43
49
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
50
  var handleDrop = function (_a) {
@@ -69,6 +75,6 @@ var RCTree = function (_a) {
69
75
  return (0, helper_1.getExpandedKeys)(treeData);
70
76
  }, [treeData]);
71
77
  var renderSwitcherIcon = (0, react_1.useCallback)(function (node) { return react_1.default.createElement(SwitchRenderer, { node: node }); }, []);
72
- return internalTreeData ? (react_1.default.createElement(rc_tree_1.default, { allowDrop: canDrop, draggable: canDrag, onDragStart: function () { }, onDragEnter: handleDragEnter, onDrop: handleDrop, virtual: isVirtualized, itemHeight: minItemHeight, height: height, onExpand: handleExpand, showIcon: false, showLine: true, expandedKeys: expandedKeys, switcherIcon: renderSwitcherIcon, defaultExpandAll: defaultExpandAll, className: (0, classnames_1.default)(className, styles.treeWrapper), titleRender: renderNode ? function (node) { return renderNode(node.value); } : undefined, treeData: internalTreeData, selectable: false, loadData: onLoadChildren ? function (node) { return onLoadChildren(node.value); } : undefined, "data-reltio-id": "rc-tree" })) : null;
78
+ return internalTreeData ? (react_1.default.createElement(rc_tree_1.default, { allowDrop: canDrop, draggable: canDrag, onDragStart: function () { }, onDragEnter: handleDragEnter, onDrop: handleDrop, virtual: isVirtualized, itemHeight: minItemHeight, height: height, onExpand: handleExpand, showIcon: false, showLine: true, expandedKeys: expandedKeys, switcherIcon: renderSwitcherIcon, defaultExpandAll: defaultExpandAll, className: (0, classnames_1.default)(className, styles.treeWrapper), titleRender: renderNode ? function (node) { return renderNode(node.value); } : undefined, treeData: internalTreeData, selectable: false, loadData: onLoadChildren ? function (node) { return onLoadChildren(node.value); } : undefined, "data-reltio-id": "rc-tree", ref: treeRef })) : null;
73
79
  };
74
80
  exports.RCTree = RCTree;
@@ -49,9 +49,7 @@ exports.changeNodeAtPosition = changeNodeAtPosition;
49
49
  var getExpandedKeys = function (nodes) {
50
50
  if (nodes === void 0) { nodes = []; }
51
51
  return nodes.reduce(function (expandedKeys, node) {
52
- return expandedKeys
53
- .concat(node.expanded ? [String(node.nodeId)] : [])
54
- .concat((0, exports.getExpandedKeys)(node.children));
52
+ return expandedKeys.concat(node.expanded ? [String(node.nodeId)] : []).concat((0, exports.getExpandedKeys)(node.children));
55
53
  }, []);
56
54
  };
57
55
  exports.getExpandedKeys = getExpandedKeys;
@@ -214,7 +214,7 @@ exports.useStyles = (0, styles_1.makeStyles)(function () { return ({
214
214
  outline: 0,
215
215
  '&:hover': {
216
216
  backgroundColor: 'rgba(0,0,0,0.06)'
217
- },
217
+ }
218
218
  },
219
219
  '.rc-tree-treenode': {
220
220
  display: 'flex'
@@ -225,6 +225,6 @@ exports.useStyles = (0, styles_1.makeStyles)(function () { return ({
225
225
  '.rc-tree-title': {
226
226
  display: 'inline-block',
227
227
  width: '100%'
228
- },
228
+ }
229
229
  }
230
230
  }); });
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
1
  import { TreeNodeProps } from 'rc-tree';
2
+ import React from 'react';
3
3
  import { RCTreeNode } from './types';
4
4
  type Props = {
5
5
  treeData: RCTreeNode[];
@@ -14,7 +14,8 @@ type Props = {
14
14
  className?: string;
15
15
  minItemHeight?: number;
16
16
  isLeaf?: (node: TreeNodeProps & Record<string, unknown>) => boolean;
17
+ scrollToNode?: RCTreeNode;
17
18
  onChange?: (node: RCTreeNode[]) => void;
18
19
  };
19
- export declare const RCTree: ({ treeData, isVirtualized, canDrag, canDrop, onLoadChildren, height, defaultExpandAll, SwitchRenderer, className, renderNode, minItemHeight, isLeaf, onChange, }: Props) => React.JSX.Element;
20
+ export declare const RCTree: ({ treeData, isVirtualized, canDrag, canDrop, onLoadChildren, height, defaultExpandAll, SwitchRenderer, className, renderNode, minItemHeight, isLeaf, scrollToNode, onChange }: Props) => React.JSX.Element;
20
21
  export {};
@@ -1,15 +1,21 @@
1
- import React, { useCallback, useMemo } from 'react';
1
+ import classnames from 'classnames';
2
2
  import { assoc, identity } from 'ramda';
3
3
  import Tree from 'rc-tree';
4
- import classnames from 'classnames';
4
+ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
5
5
  import { DefaultSwitchRenderer } from './DefaultSwitchRenderer';
6
6
  import { changeNodeAtPosition, convertTreeData, defaultIsLeaf, getExpandedKeys } from './helper';
7
7
  import { useStyles } from './styles';
8
8
  var MIN_ROW_HEIGHT = 28;
9
9
  export var RCTree = function (_a) {
10
- var treeData = _a.treeData, _b = _a.isVirtualized, isVirtualized = _b === void 0 ? true : _b, _c = _a.canDrag, canDrag = _c === void 0 ? false : _c, _d = _a.canDrop, canDrop = _d === void 0 ? function () { return false; } : _d, onLoadChildren = _a.onLoadChildren, height = _a.height, _e = _a.defaultExpandAll, defaultExpandAll = _e === void 0 ? false : _e, _f = _a.SwitchRenderer, SwitchRenderer = _f === void 0 ? DefaultSwitchRenderer : _f, className = _a.className, renderNode = _a.renderNode, _g = _a.minItemHeight, minItemHeight = _g === void 0 ? MIN_ROW_HEIGHT : _g, _h = _a.isLeaf, isLeaf = _h === void 0 ? defaultIsLeaf : _h, _j = _a.onChange, onChange = _j === void 0 ? identity : _j;
10
+ var treeData = _a.treeData, _b = _a.isVirtualized, isVirtualized = _b === void 0 ? true : _b, _c = _a.canDrag, canDrag = _c === void 0 ? false : _c, _d = _a.canDrop, canDrop = _d === void 0 ? function () { return false; } : _d, onLoadChildren = _a.onLoadChildren, height = _a.height, _e = _a.defaultExpandAll, defaultExpandAll = _e === void 0 ? false : _e, _f = _a.SwitchRenderer, SwitchRenderer = _f === void 0 ? DefaultSwitchRenderer : _f, className = _a.className, renderNode = _a.renderNode, _g = _a.minItemHeight, minItemHeight = _g === void 0 ? MIN_ROW_HEIGHT : _g, _h = _a.isLeaf, isLeaf = _h === void 0 ? defaultIsLeaf : _h, scrollToNode = _a.scrollToNode, _j = _a.onChange, onChange = _j === void 0 ? identity : _j;
11
11
  var styles = useStyles();
12
12
  var internalTreeData = useMemo(function () { return convertTreeData({ data: treeData, isLeaf: isLeaf }); }, [isLeaf, treeData]);
13
+ var treeRef = useRef(null);
14
+ useEffect(function () {
15
+ if (treeRef.current && scrollToNode) {
16
+ treeRef.current.scrollTo({ key: String(scrollToNode.nodeId) });
17
+ }
18
+ }, [scrollToNode]);
13
19
  // eslint-disable-next-line no-unused-vars
14
20
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
21
  var handleDrop = function (_a) {
@@ -40,5 +46,5 @@ export var RCTree = function (_a) {
40
46
  return getExpandedKeys(treeData);
41
47
  }, [treeData]);
42
48
  var renderSwitcherIcon = useCallback(function (node) { return React.createElement(SwitchRenderer, { node: node }); }, []);
43
- return internalTreeData ? (React.createElement(Tree, { allowDrop: canDrop, draggable: canDrag, onDragStart: function () { }, onDragEnter: handleDragEnter, onDrop: handleDrop, virtual: isVirtualized, itemHeight: minItemHeight, height: height, onExpand: handleExpand, showIcon: false, showLine: true, expandedKeys: expandedKeys, switcherIcon: renderSwitcherIcon, defaultExpandAll: defaultExpandAll, className: classnames(className, styles.treeWrapper), titleRender: renderNode ? function (node) { return renderNode(node.value); } : undefined, treeData: internalTreeData, selectable: false, loadData: onLoadChildren ? function (node) { return onLoadChildren(node.value); } : undefined, "data-reltio-id": "rc-tree" })) : null;
49
+ return internalTreeData ? (React.createElement(Tree, { allowDrop: canDrop, draggable: canDrag, onDragStart: function () { }, onDragEnter: handleDragEnter, onDrop: handleDrop, virtual: isVirtualized, itemHeight: minItemHeight, height: height, onExpand: handleExpand, showIcon: false, showLine: true, expandedKeys: expandedKeys, switcherIcon: renderSwitcherIcon, defaultExpandAll: defaultExpandAll, className: classnames(className, styles.treeWrapper), titleRender: renderNode ? function (node) { return renderNode(node.value); } : undefined, treeData: internalTreeData, selectable: false, loadData: onLoadChildren ? function (node) { return onLoadChildren(node.value); } : undefined, "data-reltio-id": "rc-tree", ref: treeRef })) : null;
44
50
  };
@@ -43,8 +43,6 @@ export var changeNodeAtPosition = function (treeData, pos, changeNode) {
43
43
  export var getExpandedKeys = function (nodes) {
44
44
  if (nodes === void 0) { nodes = []; }
45
45
  return nodes.reduce(function (expandedKeys, node) {
46
- return expandedKeys
47
- .concat(node.expanded ? [String(node.nodeId)] : [])
48
- .concat(getExpandedKeys(node.children));
46
+ return expandedKeys.concat(node.expanded ? [String(node.nodeId)] : []).concat(getExpandedKeys(node.children));
49
47
  }, []);
50
48
  };
@@ -211,7 +211,7 @@ export var useStyles = makeStyles(function () { return ({
211
211
  outline: 0,
212
212
  '&:hover': {
213
213
  backgroundColor: 'rgba(0,0,0,0.06)'
214
- },
214
+ }
215
215
  },
216
216
  '.rc-tree-treenode': {
217
217
  display: 'flex'
@@ -222,6 +222,6 @@ export var useStyles = makeStyles(function () { return ({
222
222
  '.rc-tree-title': {
223
223
  display: 'inline-block',
224
224
  width: '100%'
225
- },
225
+ }
226
226
  }
227
227
  }); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1958",
3
+ "version": "1.4.1959",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",