rsuite 5.32.0 → 5.33.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.
- package/CHANGELOG.md +6 -0
- package/cjs/Cascader/Cascader.js +2 -2
- package/cjs/Cascader/utils.d.ts +0 -9
- package/cjs/Cascader/utils.js +2 -48
- package/cjs/CheckTreePicker/CheckTreePicker.js +16 -3
- package/cjs/Tree/Tree.d.ts +2 -0
- package/cjs/TreePicker/TreePicker.js +16 -3
- package/cjs/utils/treeUtils.d.ts +18 -0
- package/cjs/utils/treeUtils.js +78 -0
- package/dist/rsuite.js +6 -6
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Cascader/Cascader.js +2 -2
- package/esm/Cascader/utils.d.ts +0 -9
- package/esm/Cascader/utils.js +1 -44
- package/esm/CheckTreePicker/CheckTreePicker.js +17 -4
- package/esm/Tree/Tree.d.ts +2 -0
- package/esm/TreePicker/TreePicker.js +18 -5
- package/esm/utils/treeUtils.d.ts +18 -0
- package/esm/utils/treeUtils.js +73 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# [5.33.0](https://github.com/rsuite/rsuite/compare/v5.32.0...v5.33.0) (2023-04-28)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **Tree,TreePicker,CheckTree,CheckTreePicker:** add onSelectItem prop ([#3172](https://github.com/rsuite/rsuite/issues/3172)) ([9a5618a](https://github.com/rsuite/rsuite/commit/9a5618a3affb13e70330a5aea253e8b54c67b61b))
|
|
6
|
+
|
|
1
7
|
# [5.32.0](https://github.com/rsuite/rsuite/compare/v5.31.1...v5.32.0) (2023-04-21)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/cjs/Cascader/Cascader.js
CHANGED
|
@@ -111,7 +111,7 @@ var Cascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
111
111
|
var loadingItemsSet = (0, _reactUseSet.useSet)();
|
|
112
112
|
var asyncChildrenMap = (0, _useMap.useMap)();
|
|
113
113
|
var parentMap = (0, _react.useMemo)(function () {
|
|
114
|
-
return (0,
|
|
114
|
+
return (0, _treeUtils.getParentMap)(data, function (item) {
|
|
115
115
|
var _asyncChildrenMap$get;
|
|
116
116
|
|
|
117
117
|
return (_asyncChildrenMap$get = asyncChildrenMap.get(item)) !== null && _asyncChildrenMap$get !== void 0 ? _asyncChildrenMap$get : item[childrenKey];
|
|
@@ -365,7 +365,7 @@ var Cascader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
365
365
|
|
|
366
366
|
var renderSearchRow = function renderSearchRow(item, key) {
|
|
367
367
|
var regx = new RegExp((0, _utils2.getSafeRegExpString)(searchKeyword), 'ig');
|
|
368
|
-
var nodes = (0,
|
|
368
|
+
var nodes = (0, _treeUtils.getPathTowardsItem)(item, function (item) {
|
|
369
369
|
return parentMap.get(item);
|
|
370
370
|
});
|
|
371
371
|
var formattedNodes = nodes.map(function (node) {
|
package/cjs/Cascader/utils.d.ts
CHANGED
|
@@ -46,13 +46,4 @@ export declare function usePaths<T extends Record<string, unknown>>({ data, acti
|
|
|
46
46
|
pathTowardsSelectedItem: T[];
|
|
47
47
|
pathTowardsActiveItem: T[];
|
|
48
48
|
};
|
|
49
|
-
/**
|
|
50
|
-
* Returns a WeakMap that maps each item in `items` to its parent
|
|
51
|
-
* indicated by `getChildren` function
|
|
52
|
-
*/
|
|
53
|
-
export declare function getParentMap<T extends Record<string, unknown>>(items: readonly T[], getChildren: (item: T) => readonly T[] | undefined): WeakMap<T, T>;
|
|
54
|
-
/**
|
|
55
|
-
* Returns an array indicating the hirearchy path from root towards `target` item
|
|
56
|
-
*/
|
|
57
|
-
export declare function getPathTowardsItem<T>(target: T | undefined, getParent: (item: T) => T | undefined): T[];
|
|
58
49
|
export {};
|
package/cjs/Cascader/utils.js
CHANGED
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.getColumnsAndPaths = getColumnsAndPaths;
|
|
5
5
|
exports.usePaths = usePaths;
|
|
6
|
-
exports.getParentMap = getParentMap;
|
|
7
|
-
exports.getPathTowardsItem = getPathTowardsItem;
|
|
8
6
|
|
|
9
7
|
var _react = require("react");
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
-
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
9
|
+
var _treeUtils = require("../utils/treeUtils");
|
|
16
10
|
|
|
17
11
|
/**
|
|
18
12
|
* Calculate columns to be displayed:
|
|
@@ -76,7 +70,7 @@ function usePaths(_ref) {
|
|
|
76
70
|
getParent = _ref.getParent,
|
|
77
71
|
getChildren = _ref.getChildren;
|
|
78
72
|
var pathTowardsSelectedItem = (0, _react.useMemo)(function () {
|
|
79
|
-
return getPathTowardsItem(selectedItem, getParent);
|
|
73
|
+
return (0, _treeUtils.getPathTowardsItem)(selectedItem, getParent);
|
|
80
74
|
}, [getParent, selectedItem]);
|
|
81
75
|
|
|
82
76
|
var _useMemo = (0, _react.useMemo)(function () {
|
|
@@ -93,44 +87,4 @@ function usePaths(_ref) {
|
|
|
93
87
|
pathTowardsSelectedItem: pathTowardsSelectedItem,
|
|
94
88
|
pathTowardsActiveItem: pathTowardsActiveItem
|
|
95
89
|
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Returns a WeakMap that maps each item in `items` to its parent
|
|
99
|
-
* indicated by `getChildren` function
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
function getParentMap(items, getChildren) {
|
|
104
|
-
var map = new WeakMap();
|
|
105
|
-
|
|
106
|
-
for (var queue = [].concat(items); queue.length > 0;) {
|
|
107
|
-
var _item = queue.shift();
|
|
108
|
-
|
|
109
|
-
var children = getChildren(_item);
|
|
110
|
-
|
|
111
|
-
if (children) {
|
|
112
|
-
for (var _iterator = _createForOfIteratorHelperLoose(children), _step; !(_step = _iterator()).done;) {
|
|
113
|
-
var child = _step.value;
|
|
114
|
-
map.set(child, _item);
|
|
115
|
-
queue.push(child);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return map;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Returns an array indicating the hirearchy path from root towards `target` item
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
function getPathTowardsItem(target, getParent) {
|
|
128
|
-
if (!target) return [];
|
|
129
|
-
var path = [target];
|
|
130
|
-
|
|
131
|
-
for (var parent = getParent(target); !!parent; parent = getParent(parent)) {
|
|
132
|
-
path.unshift(parent);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return path;
|
|
136
90
|
}
|
|
@@ -117,13 +117,14 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
117
117
|
onExited = props.onExited,
|
|
118
118
|
onSearch = props.onSearch,
|
|
119
119
|
onSelect = props.onSelect,
|
|
120
|
+
onSelectItem = props.onSelectItem,
|
|
120
121
|
onOpen = props.onOpen,
|
|
121
122
|
onScroll = props.onScroll,
|
|
122
123
|
onExpand = props.onExpand,
|
|
123
124
|
renderValue = props.renderValue,
|
|
124
125
|
renderTreeIcon = props.renderTreeIcon,
|
|
125
126
|
renderTreeNode = props.renderTreeNode,
|
|
126
|
-
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "style", "appearance", "cleanable", "countable", "searchBy", "toggleAs", "searchKeyword", "showIndentLine", "locale", "cascade", "disabled", "valueKey", "labelKey", "placement", "childrenKey", "placeholder", "value", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "height", "menuMaxHeight", "menuStyle", "searchable", "virtualized", "className", "classPrefix", "menuClassName", "menuAutoWidth", "uncheckableItemValues", "id", "listProps", "renderMenu", "getChildren", "renderExtraFooter", "onEntered", "onChange", "onClean", "onClose", "onExited", "onSearch", "onSelect", "onOpen", "onScroll", "onExpand", "renderValue", "renderTreeIcon", "renderTreeNode"]);
|
|
127
|
+
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "style", "appearance", "cleanable", "countable", "searchBy", "toggleAs", "searchKeyword", "showIndentLine", "locale", "cascade", "disabled", "valueKey", "labelKey", "placement", "childrenKey", "placeholder", "value", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "height", "menuMaxHeight", "menuStyle", "searchable", "virtualized", "className", "classPrefix", "menuClassName", "menuAutoWidth", "uncheckableItemValues", "id", "listProps", "renderMenu", "getChildren", "renderExtraFooter", "onEntered", "onChange", "onClean", "onClose", "onExited", "onSearch", "onSelect", "onSelectItem", "onOpen", "onScroll", "onExpand", "renderValue", "renderTreeIcon", "renderTreeNode"]);
|
|
127
128
|
|
|
128
129
|
var _useContext = (0, _react.useContext)(_TreeContext.default),
|
|
129
130
|
inline = _useContext.inline;
|
|
@@ -368,7 +369,16 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
368
369
|
return values.filter(function (v) {
|
|
369
370
|
return !uncheckableItemValues.includes(v);
|
|
370
371
|
});
|
|
371
|
-
}, [flattenNodes, uncheckableItemValues, serializeListOnlyParent, toggleDownChecked, toggleUpChecked]);
|
|
372
|
+
}, [flattenNodes, uncheckableItemValues, serializeListOnlyParent, toggleDownChecked, toggleUpChecked]); // TODO-Doma
|
|
373
|
+
// Replace `getKeyParentMap` with `getParentMap`
|
|
374
|
+
|
|
375
|
+
var itemParentMap = (0, _react.useMemo)(function () {
|
|
376
|
+
return (0, _treeUtils.getKeyParentMap)(data, function (node) {
|
|
377
|
+
return node[valueKey];
|
|
378
|
+
}, function (node) {
|
|
379
|
+
return node[childrenKey];
|
|
380
|
+
});
|
|
381
|
+
}, [childrenKey, data, valueKey]);
|
|
372
382
|
var handleSelect = (0, _react.useCallback)(function (node, event) {
|
|
373
383
|
var currentNode = node.refKey ? flattenNodes[node.refKey] : null;
|
|
374
384
|
|
|
@@ -393,7 +403,10 @@ var CheckTreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
393
403
|
setFocusItemValue(node[valueKey]);
|
|
394
404
|
onChange === null || onChange === void 0 ? void 0 : onChange(selectedValues, event);
|
|
395
405
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(node, selectedValues, event);
|
|
396
|
-
|
|
406
|
+
onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(node, (0, _treeUtils.getPathTowardsItem)(node, function (item) {
|
|
407
|
+
return itemParentMap.get(item[valueKey]);
|
|
408
|
+
}));
|
|
409
|
+
}, [flattenNodes, toggleChecked, isControlled, valueKey, onChange, onSelect, onSelectItem, unSerializeList, cascade, uncheckableItemValues, setValue, itemParentMap]);
|
|
397
410
|
var handleOpen = (0, _react.useCallback)(function () {
|
|
398
411
|
var _triggerRef$current, _triggerRef$current$o;
|
|
399
412
|
|
package/cjs/Tree/Tree.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface TreeBaseProps<ValueType = string | number, ItemDataType = Recor
|
|
|
60
60
|
onExpand?: (expandItemValues: ItemDataType[], activeNode: ItemDataType, concat: (data: ItemDataType[], children: ItemDataType[]) => ItemDataType[]) => void;
|
|
61
61
|
/** Callback function after selecting tree node */
|
|
62
62
|
onSelect?: (activeNode: ItemDataType, value: ValueType, event: React.SyntheticEvent) => void;
|
|
63
|
+
/** Callback when a tree item is clicked */
|
|
64
|
+
onSelectItem?: (item: ItemDataType, path: ItemDataType[]) => void;
|
|
63
65
|
/** Custom Render tree Node */
|
|
64
66
|
renderTreeNode?: (nodeData: ItemDataType) => React.ReactNode;
|
|
65
67
|
/** Custom Render icon */
|
|
@@ -104,6 +104,7 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
104
104
|
onOpen = props.onOpen,
|
|
105
105
|
onSearch = props.onSearch,
|
|
106
106
|
onSelect = props.onSelect,
|
|
107
|
+
onSelectItem = props.onSelectItem,
|
|
107
108
|
onChange = props.onChange,
|
|
108
109
|
onEntered = props.onEntered,
|
|
109
110
|
onClose = props.onClose,
|
|
@@ -117,7 +118,7 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
117
118
|
renderExtraFooter = props.renderExtraFooter,
|
|
118
119
|
renderMenu = props.renderMenu,
|
|
119
120
|
renderValue = props.renderValue,
|
|
120
|
-
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "appearance", "style", "showIndentLine", "value", "locale", "height", "menuMaxHeight", "menuStyle", "className", "disabled", "placement", "cleanable", "searchable", "virtualized", "classPrefix", "defaultValue", "placeholder", "searchKeyword", "menuClassName", "menuAutoWidth", "searchBy", "toggleAs", "labelKey", "valueKey", "childrenKey", "draggable", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "id", "listProps", "getChildren", "renderTreeIcon", "renderTreeNode", "onExit", "onExited", "onClean", "onOpen", "onSearch", "onSelect", "onChange", "onEntered", "onClose", "onDragEnd", "onDragStart", "onDragEnter", "onDragLeave", "onDragOver", "onDrop", "onExpand", "renderExtraFooter", "renderMenu", "renderValue"]);
|
|
121
|
+
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "data", "appearance", "style", "showIndentLine", "value", "locale", "height", "menuMaxHeight", "menuStyle", "className", "disabled", "placement", "cleanable", "searchable", "virtualized", "classPrefix", "defaultValue", "placeholder", "searchKeyword", "menuClassName", "menuAutoWidth", "searchBy", "toggleAs", "labelKey", "valueKey", "childrenKey", "draggable", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "id", "listProps", "getChildren", "renderTreeIcon", "renderTreeNode", "onExit", "onExited", "onClean", "onOpen", "onSearch", "onSelect", "onSelectItem", "onChange", "onEntered", "onClose", "onDragEnd", "onDragStart", "onDragEnter", "onDragLeave", "onDragOver", "onDrop", "onExpand", "renderExtraFooter", "renderMenu", "renderValue"]);
|
|
121
122
|
var triggerRef = (0, _react.useRef)(null);
|
|
122
123
|
var targetRef = (0, _react.useRef)(null);
|
|
123
124
|
var listRef = (0, _react.useRef)(null);
|
|
@@ -313,8 +314,17 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
313
314
|
onRenderTreeNode: renderTreeNode,
|
|
314
315
|
onRenderTreeIcon: renderTreeIcon
|
|
315
316
|
};
|
|
316
|
-
};
|
|
317
|
+
}; // TODO-Doma
|
|
318
|
+
// Replace `getKeyParentMap` with `getParentMap`
|
|
319
|
+
|
|
317
320
|
|
|
321
|
+
var itemParentMap = (0, _react.useMemo)(function () {
|
|
322
|
+
return (0, _treeUtils.getKeyParentMap)(data, function (node) {
|
|
323
|
+
return node[valueKey];
|
|
324
|
+
}, function (node) {
|
|
325
|
+
return node[childrenKey];
|
|
326
|
+
});
|
|
327
|
+
}, [childrenKey, data, valueKey]);
|
|
318
328
|
var handleSelect = (0, _react.useCallback)(function (nodeData, event) {
|
|
319
329
|
var _targetRef$current, _triggerRef$current, _triggerRef$current$c;
|
|
320
330
|
|
|
@@ -331,9 +341,12 @@ var TreePicker = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
331
341
|
setFocusItemValue(nodeData[valueKey]);
|
|
332
342
|
onChange === null || onChange === void 0 ? void 0 : onChange(nodeValue, event);
|
|
333
343
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nodeData, nodeValue, event);
|
|
344
|
+
onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(nodeData, (0, _treeUtils.getPathTowardsItem)(nodeData, function (item) {
|
|
345
|
+
return itemParentMap.get(item[valueKey]);
|
|
346
|
+
}));
|
|
334
347
|
(_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.focus();
|
|
335
348
|
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : (_triggerRef$current$c = _triggerRef$current.close) === null || _triggerRef$current$c === void 0 ? void 0 : _triggerRef$current$c.call(_triggerRef$current);
|
|
336
|
-
}, [valueKey, isControlled, onChange, onSelect, setValue]);
|
|
349
|
+
}, [valueKey, isControlled, onChange, onSelect, onSelectItem, setValue, itemParentMap]);
|
|
337
350
|
var handleExpand = (0, _react.useCallback)(function (node) {
|
|
338
351
|
var nextExpandItemValues = (0, _treeUtils.toggleExpand)({
|
|
339
352
|
node: node,
|
package/cjs/utils/treeUtils.d.ts
CHANGED
|
@@ -278,3 +278,21 @@ export declare function createDragPreview(name: string, className: string): HTML
|
|
|
278
278
|
*/
|
|
279
279
|
export declare function removeDragPreview(): void;
|
|
280
280
|
export declare function stringifyTreeNodeLabel(label: string | React.ReactNode): string;
|
|
281
|
+
/**
|
|
282
|
+
* Returns a WeakMap that maps each item in `items` to its parent
|
|
283
|
+
* indicated by `getChildren` function
|
|
284
|
+
*/
|
|
285
|
+
export declare function getParentMap<T extends Record<string, unknown>>(items: readonly T[], getChildren: (item: T) => readonly T[] | undefined): WeakMap<T, T>;
|
|
286
|
+
/**
|
|
287
|
+
* Returns a Map that maps each item's "key", indicated by `getKey` function,
|
|
288
|
+
* to its parent indicated by `getChildren` function
|
|
289
|
+
*
|
|
290
|
+
* NOTICE:
|
|
291
|
+
* Using this function is discouraged.
|
|
292
|
+
* Use {@link getParentMap} whenever possible.
|
|
293
|
+
*/
|
|
294
|
+
export declare function getKeyParentMap<T extends Record<string, unknown>, K = React.Key>(items: readonly T[], getKey: (item: T) => K, getChildren: (item: T) => readonly T[] | undefined): Map<K, T>;
|
|
295
|
+
/**
|
|
296
|
+
* Returns an array indicating the hirearchy path from root towards `target` item
|
|
297
|
+
*/
|
|
298
|
+
export declare function getPathTowardsItem<T>(target: T | undefined, getParent: (item: T) => T | undefined): T[];
|
package/cjs/utils/treeUtils.js
CHANGED
|
@@ -39,6 +39,9 @@ exports.getNodeFormattedRefKey = getNodeFormattedRefKey;
|
|
|
39
39
|
exports.createDragPreview = createDragPreview;
|
|
40
40
|
exports.removeDragPreview = removeDragPreview;
|
|
41
41
|
exports.stringifyTreeNodeLabel = stringifyTreeNodeLabel;
|
|
42
|
+
exports.getParentMap = getParentMap;
|
|
43
|
+
exports.getKeyParentMap = getKeyParentMap;
|
|
44
|
+
exports.getPathTowardsItem = getPathTowardsItem;
|
|
42
45
|
exports.getScrollToIndex = exports.focusPreviousItem = exports.focusNextItem = exports.focusTreeNode = exports.getElementByDataKey = exports.getActiveItem = exports.getActiveIndex = exports.getFocusableItems = void 0;
|
|
43
46
|
|
|
44
47
|
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
@@ -73,6 +76,12 @@ var _constants = require("./constants");
|
|
|
73
76
|
|
|
74
77
|
var _attachParent = require("./attachParent");
|
|
75
78
|
|
|
79
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
80
|
+
|
|
81
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
82
|
+
|
|
83
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
84
|
+
|
|
76
85
|
// gap of tree node
|
|
77
86
|
var TREE_NODE_GAP = 4;
|
|
78
87
|
/**
|
|
@@ -1195,4 +1204,73 @@ function stringifyTreeNodeLabel(label) {
|
|
|
1195
1204
|
}
|
|
1196
1205
|
|
|
1197
1206
|
return '';
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Returns a WeakMap that maps each item in `items` to its parent
|
|
1210
|
+
* indicated by `getChildren` function
|
|
1211
|
+
*/
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
function getParentMap(items, getChildren) {
|
|
1215
|
+
var map = new WeakMap();
|
|
1216
|
+
|
|
1217
|
+
for (var queue = [].concat(items); queue.length > 0;) {
|
|
1218
|
+
var _item5 = queue.shift();
|
|
1219
|
+
|
|
1220
|
+
var children = getChildren(_item5);
|
|
1221
|
+
|
|
1222
|
+
if (children) {
|
|
1223
|
+
for (var _iterator = _createForOfIteratorHelperLoose(children), _step; !(_step = _iterator()).done;) {
|
|
1224
|
+
var child = _step.value;
|
|
1225
|
+
map.set(child, _item5);
|
|
1226
|
+
queue.push(child);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
return map;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Returns a Map that maps each item's "key", indicated by `getKey` function,
|
|
1235
|
+
* to its parent indicated by `getChildren` function
|
|
1236
|
+
*
|
|
1237
|
+
* NOTICE:
|
|
1238
|
+
* Using this function is discouraged.
|
|
1239
|
+
* Use {@link getParentMap} whenever possible.
|
|
1240
|
+
*/
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
function getKeyParentMap(items, getKey, getChildren) {
|
|
1244
|
+
var map = new Map();
|
|
1245
|
+
|
|
1246
|
+
for (var queue = [].concat(items); queue.length > 0;) {
|
|
1247
|
+
var _item6 = queue.shift();
|
|
1248
|
+
|
|
1249
|
+
var children = getChildren(_item6);
|
|
1250
|
+
|
|
1251
|
+
if (children) {
|
|
1252
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(children), _step2; !(_step2 = _iterator2()).done;) {
|
|
1253
|
+
var child = _step2.value;
|
|
1254
|
+
map.set(getKey(child), _item6);
|
|
1255
|
+
queue.push(child);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
return map;
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Returns an array indicating the hirearchy path from root towards `target` item
|
|
1264
|
+
*/
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
function getPathTowardsItem(target, getParent) {
|
|
1268
|
+
if (!target) return [];
|
|
1269
|
+
var path = [target];
|
|
1270
|
+
|
|
1271
|
+
for (var parent = getParent(target); !!parent; parent = getParent(parent)) {
|
|
1272
|
+
path.unshift(parent);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
return path;
|
|
1198
1276
|
}
|