* Traverse all the data by `treeData`. * Please not use it out of the `rc-tree` since we may refactor this code.
(dataNodes, callback, // To avoid too many params, let use config instead of origin param config)
| 120555 | */ |
| 120556 | |
| 120557 | function traverseDataNodes(dataNodes, callback, // To avoid too many params, let use config instead of origin param |
| 120558 | config) { |
| 120559 | // Init config |
| 120560 | var externalGetKey = null; |
| 120561 | var childrenPropName; |
| 120562 | |
| 120563 | var configType = Object(_babel_runtime_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(config); |
| 120564 | |
| 120565 | if (configType === 'function' || configType === 'string') { |
| 120566 | // Legacy getKey param |
| 120567 | externalGetKey = config; |
| 120568 | } else if (config && configType === 'object') { |
| 120569 | childrenPropName = config.childrenPropName; |
| 120570 | externalGetKey = config.externalGetKey; |
| 120571 | } |
| 120572 | |
| 120573 | childrenPropName = childrenPropName || 'children'; // Get keys |
| 120574 | |
| 120575 | var syntheticGetKey; |
| 120576 | |
| 120577 | if (externalGetKey) { |
| 120578 | if (typeof externalGetKey === 'string') { |
| 120579 | syntheticGetKey = function syntheticGetKey(node) { |
| 120580 | return node[externalGetKey]; |
| 120581 | }; |
| 120582 | } else if (typeof externalGetKey === 'function') { |
| 120583 | syntheticGetKey = function syntheticGetKey(node) { |
| 120584 | return externalGetKey(node); |
| 120585 | }; |
| 120586 | } |
| 120587 | } else { |
| 120588 | syntheticGetKey = function syntheticGetKey(node, pos) { |
| 120589 | return getKey(node.key, pos); |
| 120590 | }; |
| 120591 | } // Process |
| 120592 | |
| 120593 | |
| 120594 | function processNode(node, index, parent) { |
| 120595 | var children = node ? node[childrenPropName] : dataNodes; |
| 120596 | var pos = node ? Object(_util__WEBPACK_IMPORTED_MODULE_6__[/* getPosition */ "h"])(parent.pos, index) : '0'; // Process node if is not root |
| 120597 | |
| 120598 | if (node) { |
| 120599 | var key = syntheticGetKey(node, pos); |
| 120600 | var data = { |
| 120601 | node: node, |
| 120602 | index: index, |
| 120603 | pos: pos, |
| 120604 | key: key, |
| 120605 | parentPos: parent.node ? parent.pos : null, |
| 120606 | level: parent.level + 1 |
| 120607 | }; |
| 120608 | callback(data); |
| 120609 | } // Process children node |
| 120610 | |
| 120611 | |
| 120612 | if (children) { |
| 120613 | children.forEach(function (subNode, subIndex) { |
| 120614 | processNode(subNode, subIndex, { |
no test coverage detected
searching dependent graphs…