e9fd7dec54f89f31349b65d222c8464c.json
11.3 KB
{"ast":null,"code":"import _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nimport warning from \"rc-util/es/warning\";\nimport { convertChildrenToData } from '../utils/legacyUtil';\nvar MAX_WARNING_TIMES = 10;\n\nfunction parseSimpleTreeData(treeData, _ref) {\n var id = _ref.id,\n pId = _ref.pId,\n rootPId = _ref.rootPId;\n var keyNodes = {};\n var rootNodeList = []; // Fill in the map\n\n var nodeList = treeData.map(function (node) {\n var clone = _objectSpread({}, node);\n\n var key = clone[id];\n keyNodes[key] = clone;\n clone.key = clone.key || key;\n return clone;\n }); // Connect tree\n\n nodeList.forEach(function (node) {\n var parentKey = node[pId];\n var parent = keyNodes[parentKey]; // Fill parent\n\n if (parent) {\n parent.children = parent.children || [];\n parent.children.push(node);\n } // Fill root tree node\n\n\n if (parentKey === rootPId || !parent && rootPId === null) {\n rootNodeList.push(node);\n }\n });\n return rootNodeList;\n}\n/**\n * Format `treeData` with `value` & `key` which is used for calculation\n */\n\n\nfunction formatTreeData(treeData, getLabelProp) {\n var warningTimes = 0;\n var valueSet = new Set();\n\n function dig(dataNodes) {\n return (dataNodes || []).map(function (node) {\n var key = node.key,\n value = node.value,\n children = node.children,\n rest = _objectWithoutProperties(node, [\"key\", \"value\", \"children\"]);\n\n var mergedValue = 'value' in node ? value : key;\n\n var dataNode = _objectSpread(_objectSpread({}, rest), {}, {\n key: key !== null && key !== undefined ? key : mergedValue,\n value: mergedValue,\n title: getLabelProp(node)\n }); // Check `key` & `value` and warning user\n\n\n if (process.env.NODE_ENV !== 'production') {\n if (key !== null && key !== undefined && value !== undefined && String(key) !== String(value) && warningTimes < MAX_WARNING_TIMES) {\n warningTimes += 1;\n warning(false, \"`key` or `value` with TreeNode must be the same or you can remove one of them. key: \".concat(key, \", value: \").concat(value, \".\"));\n }\n\n warning(!valueSet.has(value), \"Same `value` exist in the tree: \".concat(value));\n valueSet.add(value);\n }\n\n if ('children' in node) {\n dataNode.children = dig(children);\n }\n\n return dataNode;\n });\n }\n\n return dig(treeData);\n}\n/**\n * Convert `treeData` or `children` into formatted `treeData`.\n * Will not re-calculate if `treeData` or `children` not change.\n */\n\n\nexport default function useTreeData(treeData, children, _ref2) {\n var getLabelProp = _ref2.getLabelProp,\n simpleMode = _ref2.simpleMode;\n var cacheRef = React.useRef({});\n\n if (treeData) {\n cacheRef.current.formatTreeData = cacheRef.current.treeData === treeData ? cacheRef.current.formatTreeData : formatTreeData(simpleMode ? parseSimpleTreeData(treeData, _objectSpread({\n id: 'id',\n pId: 'pId',\n rootPId: null\n }, simpleMode !== true ? simpleMode : {})) : treeData, getLabelProp);\n cacheRef.current.treeData = treeData;\n } else {\n cacheRef.current.formatTreeData = cacheRef.current.children === children ? cacheRef.current.formatTreeData : formatTreeData(convertChildrenToData(children), getLabelProp);\n }\n\n return cacheRef.current.formatTreeData;\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-tree-select/es/hooks/useTreeData.js"],"names":["_objectWithoutProperties","_objectSpread","React","warning","convertChildrenToData","MAX_WARNING_TIMES","parseSimpleTreeData","treeData","_ref","id","pId","rootPId","keyNodes","rootNodeList","nodeList","map","node","clone","key","forEach","parentKey","parent","children","push","formatTreeData","getLabelProp","warningTimes","valueSet","Set","dig","dataNodes","value","rest","mergedValue","dataNode","undefined","title","process","env","NODE_ENV","String","concat","has","add","useTreeData","_ref2","simpleMode","cacheRef","useRef","current"],"mappings":"AAAA,OAAOA,wBAAP,MAAqC,oDAArC;AACA,OAAOC,aAAP,MAA0B,0CAA1B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,oBAApB;AACA,SAASC,qBAAT,QAAsC,qBAAtC;AACA,IAAIC,iBAAiB,GAAG,EAAxB;;AAEA,SAASC,mBAAT,CAA6BC,QAA7B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jB,GAA4BA,QAA5B;AACD,GAPD,MAOO;AACLwC,IAAAA,QAAQ,CAACE,OAAT,CAAiBzB,cAAjB,GAAkCuB,QAAQ,CAACE,OAAT,CAAiB3B,QAAjB,KAA8BA,QAA9B,GAAyCyB,QAAQ,CAACE,OAAT,CAAiBzB,cAA1D,GAA2EA,cAAc,CAACpB,qBAAqB,CAACkB,QAAD,CAAtB,EAAkCG,YAAlC,CAA3H;AACD;;AAED,SAAOsB,QAAQ,CAACE,OAAT,CAAiBzB,cAAxB;AACD","sourcesContent":["import _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nimport warning from \"rc-util/es/warning\";\nimport { convertChildrenToData } from '../utils/legacyUtil';\nvar MAX_WARNING_TIMES = 10;\n\nfunction parseSimpleTreeData(treeData, _ref) {\n var id = _ref.id,\n pId = _ref.pId,\n rootPId = _ref.rootPId;\n var keyNodes = {};\n var rootNodeList = []; // Fill in the map\n\n var nodeList = treeData.map(function (node) {\n var clone = _objectSpread({}, node);\n\n var key = clone[id];\n keyNodes[key] = clone;\n clone.key = clone.key || key;\n return clone;\n }); // Connect tree\n\n nodeList.forEach(function (node) {\n var parentKey = node[pId];\n var parent = keyNodes[parentKey]; // Fill parent\n\n if (parent) {\n parent.children = parent.children || [];\n parent.children.push(node);\n } // Fill root tree node\n\n\n if (parentKey === rootPId || !parent && rootPId === null) {\n rootNodeList.push(node);\n }\n });\n return rootNodeList;\n}\n/**\n * Format `treeData` with `value` & `key` which is used for calculation\n */\n\n\nfunction formatTreeData(treeData, getLabelProp) {\n var warningTimes = 0;\n var valueSet = new Set();\n\n function dig(dataNodes) {\n return (dataNodes || []).map(function (node) {\n var key = node.key,\n value = node.value,\n children = node.children,\n rest = _objectWithoutProperties(node, [\"key\", \"value\", \"children\"]);\n\n var mergedValue = 'value' in node ? value : key;\n\n var dataNode = _objectSpread(_objectSpread({}, rest), {}, {\n key: key !== null && key !== undefined ? key : mergedValue,\n value: mergedValue,\n title: getLabelProp(node)\n }); // Check `key` & `value` and warning user\n\n\n if (process.env.NODE_ENV !== 'production') {\n if (key !== null && key !== undefined && value !== undefined && String(key) !== String(value) && warningTimes < MAX_WARNING_TIMES) {\n warningTimes += 1;\n warning(false, \"`key` or `value` with TreeNode must be the same or you can remove one of them. key: \".concat(key, \", value: \").concat(value, \".\"));\n }\n\n warning(!valueSet.has(value), \"Same `value` exist in the tree: \".concat(value));\n valueSet.add(value);\n }\n\n if ('children' in node) {\n dataNode.children = dig(children);\n }\n\n return dataNode;\n });\n }\n\n return dig(treeData);\n}\n/**\n * Convert `treeData` or `children` into formatted `treeData`.\n * Will not re-calculate if `treeData` or `children` not change.\n */\n\n\nexport default function useTreeData(treeData, children, _ref2) {\n var getLabelProp = _ref2.getLabelProp,\n simpleMode = _ref2.simpleMode;\n var cacheRef = React.useRef({});\n\n if (treeData) {\n cacheRef.current.formatTreeData = cacheRef.current.treeData === treeData ? cacheRef.current.formatTreeData : formatTreeData(simpleMode ? parseSimpleTreeData(treeData, _objectSpread({\n id: 'id',\n pId: 'pId',\n rootPId: null\n }, simpleMode !== true ? simpleMode : {})) : treeData, getLabelProp);\n cacheRef.current.treeData = treeData;\n } else {\n cacheRef.current.formatTreeData = cacheRef.current.children === children ? cacheRef.current.formatTreeData : formatTreeData(convertChildrenToData(children), getLabelProp);\n }\n\n return cacheRef.current.formatTreeData;\n}"]},"metadata":{},"sourceType":"module"}