1 line
36 KiB
JSON
1 line
36 KiB
JSON
|
{"ast":null,"code":"import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"children\"];\nimport toArray from \"rc-util/es/Children/toArray\";\nimport omit from \"rc-util/es/omit\";\nimport warning from \"rc-util/es/warning\";\nimport getEntity from \"./keyUtil\";\nexport function getPosition(level, index) {\n return \"\".concat(level, \"-\").concat(index);\n}\nexport function isTreeNode(node) {\n return node && node.type && node.type.isTreeNode;\n}\nexport function getKey(key, pos) {\n if (key !== null && key !== undefined) {\n return key;\n }\n return pos;\n}\nexport function fillFieldNames(fieldNames) {\n var _ref = fieldNames || {},\n title = _ref.title,\n _title = _ref._title,\n key = _ref.key,\n children = _ref.children;\n var mergedTitle = title || 'title';\n return {\n title: mergedTitle,\n _title: _title || [mergedTitle],\n key: key || 'key',\n children: children || 'children'\n };\n}\n\n/**\n * Warning if TreeNode do not provides key\n */\nexport function warningWithoutKey(treeData, fieldNames) {\n var keys = new Map();\n function dig(list) {\n var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n (list || []).forEach(function (treeNode) {\n var key = treeNode[fieldNames.key];\n var children = treeNode[fieldNames.children];\n warning(key !== null && key !== undefined, \"Tree node must have a certain key: [\".concat(path).concat(key, \"]\"));\n var recordKey = String(key);\n warning(!keys.has(recordKey) || key === null || key === undefined, \"Same 'key' exist in the Tree: \".concat(recordKey));\n keys.set(recordKey, true);\n dig(children, \"\".concat(path).concat(recordKey, \" > \"));\n });\n }\n dig(treeData);\n}\n\n/**\n * Convert `children` of Tree into `treeData` structure.\n */\nexport function convertTreeToData(rootNodes) {\n function dig(node) {\n var treeNodes = toArray(node);\n return treeNodes.map(function (treeNode) {\n // Filter invalidate node\n if (!isTreeNode(treeNode)) {\n warning(!treeNode, 'Tree/TreeNode can only accept TreeNode as children.');\n return null;\n }\n var key = treeNode.key;\n var _treeNode$props = treeNode.props,\n children = _treeNode$props.children,\n rest = _objectWithoutProperties(_treeNode$props, _excluded);\n var dataNode = _objectSpread({\n key: key\n }, rest);\n var parsedChildren = dig(children);\n if (parsedChildren.length) {\n dataNode.children = parsedChildren;\n }\n return dataNode;\n }).filter(function (dataNode) {\n return dataNode;\n });\n }\n return dig(rootNodes);\n}\n\n/**\n * Flat nest tree data into flatten list. This is used for virtual list render.\n * @param treeNodeList Origin data node list\n * @param expandedKeys\n * need expanded keys, provides `true` means all expanded (used in `rc-tree-select`).\n */\nexport function flattenTreeData(treeNodeList, expandedKeys, fieldNames) {\n var _fillFieldNames = fillFieldNames(fieldNames),\n fieldTitles = _fillFieldNames._title,\n fieldKey = _fillFieldNames.key,\n fieldChildren = _fillFieldNames.children;\n var expandedKeySet = new Set(expandedKeys === true ? [] : expandedKeys);\n var flattenList = [];\n function dig(list) {\n var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;\n return list.map(function (treeNode, index) {\n var pos = getPosition(parent ? parent.pos : '0', index);\n var mergedKey = getKey(treeNode[fieldKey], pos);\n\n // Pick matched title in field title list\n var mergedTitle;\n for (var i = 0; i < fieldTitles.length; i += 1) {\n var fieldTitle = fieldTitles[i];\n if (treeNode[fieldTitle] !== undefined) {\n
|