1 line
24 KiB
JSON
1 line
24 KiB
JSON
|
{"ast":null,"code":"\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport { devUseWarning } from '../../../_util/warning';\nimport { getColumnKey, getColumnPos, renderColumnTitle } from '../../util';\nimport FilterDropdown, { flattenKeys } from './FilterDropdown';\nconst collectFilterStates = (columns, init, pos) => {\n let filterStates = [];\n (columns || []).forEach((column, index) => {\n var _a;\n const columnPos = getColumnPos(index, pos);\n if (column.filters || 'filterDropdown' in column || 'onFilter' in column) {\n if ('filteredValue' in column) {\n // Controlled\n let filteredValues = column.filteredValue;\n if (!('filterDropdown' in column)) {\n filteredValues = (_a = filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.map(String)) !== null && _a !== void 0 ? _a : filteredValues;\n }\n filterStates.push({\n column,\n key: getColumnKey(column, columnPos),\n filteredKeys: filteredValues,\n forceFiltered: column.filtered\n });\n } else {\n // Uncontrolled\n filterStates.push({\n column,\n key: getColumnKey(column, columnPos),\n filteredKeys: init && column.defaultFilteredValue ? column.defaultFilteredValue : undefined,\n forceFiltered: column.filtered\n });\n }\n }\n if ('children' in column) {\n filterStates = [].concat(_toConsumableArray(filterStates), _toConsumableArray(collectFilterStates(column.children, init, columnPos)));\n }\n });\n return filterStates;\n};\nfunction injectFilter(prefixCls, dropdownPrefixCls, columns, filterStates, locale, triggerFilter, getPopupContainer, pos, rootClassName) {\n return columns.map((column, index) => {\n const columnPos = getColumnPos(index, pos);\n const {\n filterOnClose = true,\n filterMultiple = true,\n filterMode,\n filterSearch\n } = column;\n let newColumn = column;\n if (newColumn.filters || newColumn.filterDropdown) {\n const columnKey = getColumnKey(newColumn, columnPos);\n const filterState = filterStates.find(_ref => {\n let {\n key\n } = _ref;\n return columnKey === key;\n });\n newColumn = Object.assign(Object.assign({}, newColumn), {\n title: renderProps => ( /*#__PURE__*/React.createElement(FilterDropdown, {\n tablePrefixCls: prefixCls,\n prefixCls: `${prefixCls}-filter`,\n dropdownPrefixCls: dropdownPrefixCls,\n column: newColumn,\n columnKey: columnKey,\n filterState: filterState,\n filterOnClose: filterOnClose,\n filterMultiple: filterMultiple,\n filterMode: filterMode,\n filterSearch: filterSearch,\n triggerFilter: triggerFilter,\n locale: locale,\n getPopupContainer: getPopupContainer,\n rootClassName: rootClassName\n }, renderColumnTitle(column.title, renderProps)))\n });\n }\n if ('children' in newColumn) {\n newColumn = Object.assign(Object.assign({}, newColumn), {\n children: injectFilter(prefixCls, dropdownPrefixCls, newColumn.children, filterStates, locale, triggerFilter, getPopupContainer, columnPos, rootClassName)\n });\n }\n return newColumn;\n });\n}\nconst generateFilterInfo = filterStates => {\n const currentFilters = {};\n filterStates.forEach(_ref2 => {\n let {\n key,\n filteredKeys,\n column\n } = _ref2;\n const keyAsString = key;\n const {\n filters,\n filterDropdown\n } = column;\n if (filterDropdown) {\n currentFilters[keyAsString] = filteredKeys || null;\n } else if (Array.isArray(filteredKeys)) {\n const keys = flattenKeys(filters);\n currentFilters[keyAsString] = keys.filter(originKey => filteredKeys.includes(String(originKey)));\n } else {\n currentFilters[keyAsString] = null;\n }\n });\n return currentFil
|