1 line
11 KiB
JSON
1 line
11 KiB
JSON
|
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport warning from \"rc-util/es/warning\";\nimport * as React from 'react';\nimport { INTERNAL_HOOKS } from \"../constant\";\nimport { findAllChildrenKeys, renderExpandIcon } from \"../utils/expandUtil\";\nimport { getExpandableProps } from \"../utils/legacyUtil\";\nexport default function useExpand(props, mergedData, getRowKey) {\n var expandableConfig = getExpandableProps(props);\n var expandIcon = expandableConfig.expandIcon,\n expandedRowKeys = expandableConfig.expandedRowKeys,\n defaultExpandedRowKeys = expandableConfig.defaultExpandedRowKeys,\n defaultExpandAllRows = expandableConfig.defaultExpandAllRows,\n expandedRowRender = expandableConfig.expandedRowRender,\n onExpand = expandableConfig.onExpand,\n onExpandedRowsChange = expandableConfig.onExpandedRowsChange,\n childrenColumnName = expandableConfig.childrenColumnName;\n var mergedExpandIcon = expandIcon || renderExpandIcon;\n var mergedChildrenColumnName = childrenColumnName || 'children';\n var expandableType = React.useMemo(function () {\n if (expandedRowRender) {\n return 'row';\n }\n /* eslint-disable no-underscore-dangle */\n /**\n * Fix https://github.com/ant-design/ant-design/issues/21154\n * This is a workaround to not to break current behavior.\n * We can remove follow code after final release.\n *\n * To other developer:\n * Do not use `__PARENT_RENDER_ICON__` in prod since we will remove this when refactor\n */\n if (props.expandable && props.internalHooks === INTERNAL_HOOKS && props.expandable.__PARENT_RENDER_ICON__ || mergedData.some(function (record) {\n return record && _typeof(record) === 'object' && record[mergedChildrenColumnName];\n })) {\n return 'nest';\n }\n /* eslint-enable */\n return false;\n }, [!!expandedRowRender, mergedData]);\n var _React$useState = React.useState(function () {\n if (defaultExpandedRowKeys) {\n return defaultExpandedRowKeys;\n }\n if (defaultExpandAllRows) {\n return findAllChildrenKeys(mergedData, getRowKey, mergedChildrenColumnName);\n }\n return [];\n }),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n innerExpandedKeys = _React$useState2[0],\n setInnerExpandedKeys = _React$useState2[1];\n var mergedExpandedKeys = React.useMemo(function () {\n return new Set(expandedRowKeys || innerExpandedKeys || []);\n }, [expandedRowKeys, innerExpandedKeys]);\n var onTriggerExpand = React.useCallback(function (record) {\n var key = getRowKey(record, mergedData.indexOf(record));\n var newExpandedKeys;\n var hasKey = mergedExpandedKeys.has(key);\n if (hasKey) {\n mergedExpandedKeys.delete(key);\n newExpandedKeys = _toConsumableArray(mergedExpandedKeys);\n } else {\n newExpandedKeys = [].concat(_toConsumableArray(mergedExpandedKeys), [key]);\n }\n setInnerExpandedKeys(newExpandedKeys);\n if (onExpand) {\n onExpand(!hasKey, record);\n }\n if (onExpandedRowsChange) {\n onExpandedRowsChange(newExpandedKeys);\n }\n }, [getRowKey, mergedExpandedKeys, mergedData, onExpand, onExpandedRowsChange]);\n\n // Warning if use `expandedRowRender` and nest children in the same time\n if (process.env.NODE_ENV !== 'production' && expandedRowRender && mergedData.some(function (record) {\n return Array.isArray(record === null || record === void 0 ? void 0 : record[mergedChildrenColumnName]);\n })) {\n warning(false, '`expandedRowRender` should not use with nested Table');\n }\n return [expandableConfig, expandableType, mergedExpandedKeys, mergedExpandIcon, mergedChildrenColumnName, onTriggerExpand];\n}","map":{"version":3,"names":["_toConsumableArray","_slicedToArray","_typeof","warning","React","INTERNAL_HOOKS","findAllChildrenKeys","renderExpandIcon","getExpandableProps","useExpa
|