73fa0a2d1521e01c707ad294862ad478.json
19.4 KB
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport _extends from \"@babel/runtime/helpers/extends\";\nimport _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nimport * as React from 'react';\nimport { getColumnPos, renderColumnTitle, getColumnKey } from '../../util';\nimport FilterDropdown from './FilterDropdown';\n\nfunction collectFilterStates(columns, init, pos) {\n var filterStates = [];\n (columns || []).forEach(function (column, index) {\n var columnPos = getColumnPos(index, pos);\n\n if ('children' in column) {\n filterStates = [].concat(_toConsumableArray(filterStates), _toConsumableArray(collectFilterStates(column.children, init, columnPos)));\n } else if (column.filters || 'filterDropdown' in column || 'onFilter' in column) {\n if ('filteredValue' in column) {\n // Controlled\n filterStates.push({\n column: column,\n key: getColumnKey(column, columnPos),\n filteredKeys: column.filteredValue,\n forceFiltered: column.filtered\n });\n } else {\n // Uncontrolled\n filterStates.push({\n column: column,\n key: getColumnKey(column, columnPos),\n filteredKeys: init && column.defaultFilteredValue ? column.defaultFilteredValue : undefined,\n forceFiltered: column.filtered\n });\n }\n }\n });\n return filterStates;\n}\n\nfunction injectFilter(prefixCls, dropdownPrefixCls, columns, filterStates, triggerFilter, getPopupContainer, locale, pos) {\n return columns.map(function (column, index) {\n var columnPos = getColumnPos(index, pos);\n var _column$filterMultipl = column.filterMultiple,\n filterMultiple = _column$filterMultipl === void 0 ? true : _column$filterMultipl;\n var newColumn = column;\n\n if (newColumn.filters || newColumn.filterDropdown) {\n var columnKey = getColumnKey(newColumn, columnPos);\n var filterState = filterStates.find(function (_ref) {\n var key = _ref.key;\n return columnKey === key;\n });\n newColumn = _extends(_extends({}, newColumn), {\n title: function title(renderProps) {\n return /*#__PURE__*/React.createElement(FilterDropdown, {\n prefixCls: \"\".concat(prefixCls, \"-filter\"),\n dropdownPrefixCls: dropdownPrefixCls,\n column: newColumn,\n columnKey: columnKey,\n filterState: filterState,\n filterMultiple: filterMultiple,\n triggerFilter: triggerFilter,\n locale: locale,\n getPopupContainer: getPopupContainer\n }, renderColumnTitle(column.title, renderProps));\n }\n });\n }\n\n if ('children' in newColumn) {\n newColumn = _extends(_extends({}, newColumn), {\n children: injectFilter(prefixCls, dropdownPrefixCls, newColumn.children, filterStates, triggerFilter, getPopupContainer, locale, columnPos)\n });\n }\n\n return newColumn;\n });\n}\n\nfunction generateFilterInfo(filterStates) {\n var currentFilters = {};\n filterStates.forEach(function (_ref2) {\n var key = _ref2.key,\n filteredKeys = _ref2.filteredKeys;\n currentFilters[key] = filteredKeys || null;\n });\n return currentFilters;\n}\n\nfunction flattenKeys(filters) {\n var keys = [];\n (filters || []).forEach(function (_ref3) {\n var value = _ref3.value,\n children = _ref3.children;\n keys.push(value);\n\n if (children) {\n keys = [].concat(_toConsumableArray(keys), _toConsumableArray(flattenKeys(children)));\n }\n });\n return keys;\n}\n\nexport function getFilterData(data, filterStates) {\n return filterStates.reduce(function (currentData, filterState) {\n var _filterState$column = filterState.column,\n onFilter = _filterState$column.onFilter,\n filters = _filterState$column.filters,\n filteredKeys = filterState.filteredKeys;\n\n if (onFilter && filteredKeys && filteredKeys.length) {\n return currentData.filter(function (record) {\n return filteredKeys.some(function (key) {\n var keys = flattenKeys(filters);\n var keyIndex = keys.findIndex(function (k) {\n return String(k) === String(key);\n });\n var realKey = keyIndex !== -1 ? keys[keyIndex] : key;\n return onFilter(realKey, record);\n });\n });\n }\n\n return currentData;\n }, data);\n}\n\nfunction useFilter(_ref4) {\n var prefixCls = _ref4.prefixCls,\n dropdownPrefixCls = _ref4.dropdownPrefixCls,\n mergedColumns = _ref4.mergedColumns,\n onFilterChange = _ref4.onFilterChange,\n getPopupContainer = _ref4.getPopupContainer,\n tableLocale = _ref4.locale;\n\n var _React$useState = React.useState(collectFilterStates(mergedColumns, true)),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n filterStates = _React$useState2[0],\n setFilterStates = _React$useState2[1];\n\n var mergedFilterStates = React.useMemo(function () {\n var collectedStates = collectFilterStates(mergedColumns, false); // Return if not controlled\n\n if (collectedStates.every(function (_ref5) {\n var filteredKeys = _ref5.filteredKeys;\n return filteredKeys === undefined;\n })) {\n return filterStates;\n }\n\n return collectedStates;\n }, [mergedColumns, filterStates]);\n var getFilters = React.useCallback(function () {\n return generateFilterInfo(mergedFilterStates);\n }, [mergedFilterStates]);\n\n var triggerFilter = function triggerFilter(filterState) {\n var newFilterStates = mergedFilterStates.filter(function (_ref6) {\n var key = _ref6.key;\n return key !== filterState.key;\n });\n newFilterStates.push(filterState);\n setFilterStates(newFilterStates);\n onFilterChange(generateFilterInfo(newFilterStates), newFilterStates);\n };\n\n var transformColumns = function transformColumns(innerColumns) {\n return injectFilter(prefixCls, dropdownPrefixCls, innerColumns, mergedFilterStates, triggerFilter, getPopupContainer, tableLocale);\n };\n\n return [transformColumns, mergedFilterStates, getFilters];\n}\n\nexport default useFilter;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/antd/es/table/hooks/useFilter/index.js"],"names":["_slicedToArray","_extends","_toConsumableArray","React","getColumnPos","renderColumnTitle","getColumnKey","FilterDropdown","collectFilterStates","columns","init","pos","filterStates","forEach","column","index","columnPos","concat","children","filters","push","key","filteredKeys","filteredValue","forceFiltered","filtered","defaultFilteredValue","undefined","injectFilter","prefixCls","dropdownPrefixCls","triggerFilter","getPopupContainer","locale","map","_column$filterMultipl","filterMultiple","newColumn","filterDropdown","columnKey","filterState","find","_ref","title","renderProps","createElement","generateFilterInfo","currentFilters","_ref2","flattenKeys","keys","_ref3","value","getFilterData","data","reduce","currentData","_filterState$column","onFilter","length","filter","record","some","keyIndex","findIndex","k","String","realKey","useFilter","_ref4","mergedColumns","onFilterChange","tableLocale","_React$useState","useState","_React$useState2","setFilterStates","mergedFilterStates","useMemo","collectedStates","every","_ref5","getFilters","useCallback","newFilterStates","_ref6","transformColumns","innerColumns"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,sCAA3B;AACA,OAAOC,Q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,CAXsB,CAAzB;AAYA,MAAIsE,UAAU,GAAG/E,KAAK,CAACgF,WAAN,CAAkB,YAAY;AAC7C,WAAOrC,kBAAkB,CAAC+B,kBAAD,CAAzB;AACD,GAFgB,EAEd,CAACA,kBAAD,CAFc,CAAjB;;AAIA,MAAI9C,aAAa,GAAG,SAASA,aAAT,CAAuBS,WAAvB,EAAoC;AACtD,QAAI4C,eAAe,GAAGP,kBAAkB,CAACjB,MAAnB,CAA0B,UAAUyB,KAAV,EAAiB;AAC/D,UAAIhE,GAAG,GAAGgE,KAAK,CAAChE,GAAhB;AACA,aAAOA,GAAG,KAAKmB,WAAW,CAACnB,GAA3B;AACD,KAHqB,CAAtB;AAIA+D,IAAAA,eAAe,CAAChE,IAAhB,CAAqBoB,WAArB;AACAoC,IAAAA,eAAe,CAACQ,eAAD,CAAf;AACAb,IAAAA,cAAc,CAACzB,kBAAkB,CAACsC,eAAD,CAAnB,EAAsCA,eAAtC,CAAd;AACD,GARD;;AAUA,MAAIE,gBAAgB,GAAG,SAASA,gBAAT,CAA0BC,YAA1B,EAAwC;AAC7D,WAAO3D,YAAY,CAACC,SAAD,EAAYC,iBAAZ,EAA+ByD,YAA/B,EAA6CV,kBAA7C,EAAiE9C,aAAjE,EAAgFC,iBAAhF,EAAmGwC,WAAnG,CAAnB;AACD,GAFD;;AAIA,SAAO,CAACc,gBAAD,EAAmBT,kBAAnB,EAAuCK,UAAvC,CAAP;AACD;;AAED,eAAed,SAAf","sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport _extends from \"@babel/runtime/helpers/extends\";\nimport _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nimport * as React from 'react';\nimport { getColumnPos, renderColumnTitle, getColumnKey } from '../../util';\nimport FilterDropdown from './FilterDropdown';\n\nfunction collectFilterStates(columns, init, pos) {\n var filterStates = [];\n (columns || []).forEach(function (column, index) {\n var columnPos = getColumnPos(index, pos);\n\n if ('children' in column) {\n filterStates = [].concat(_toConsumableArray(filterStates), _toConsumableArray(collectFilterStates(column.children, init, columnPos)));\n } else if (column.filters || 'filterDropdown' in column || 'onFilter' in column) {\n if ('filteredValue' in column) {\n // Controlled\n filterStates.push({\n column: column,\n key: getColumnKey(column, columnPos),\n filteredKeys: column.filteredValue,\n forceFiltered: column.filtered\n });\n } else {\n // Uncontrolled\n filterStates.push({\n column: column,\n key: getColumnKey(column, columnPos),\n filteredKeys: init && column.defaultFilteredValue ? column.defaultFilteredValue : undefined,\n forceFiltered: column.filtered\n });\n }\n }\n });\n return filterStates;\n}\n\nfunction injectFilter(prefixCls, dropdownPrefixCls, columns, filterStates, triggerFilter, getPopupContainer, locale, pos) {\n return columns.map(function (column, index) {\n var columnPos = getColumnPos(index, pos);\n var _column$filterMultipl = column.filterMultiple,\n filterMultiple = _column$filterMultipl === void 0 ? true : _column$filterMultipl;\n var newColumn = column;\n\n if (newColumn.filters || newColumn.filterDropdown) {\n var columnKey = getColumnKey(newColumn, columnPos);\n var filterState = filterStates.find(function (_ref) {\n var key = _ref.key;\n return columnKey === key;\n });\n newColumn = _extends(_extends({}, newColumn), {\n title: function title(renderProps) {\n return /*#__PURE__*/React.createElement(FilterDropdown, {\n prefixCls: \"\".concat(prefixCls, \"-filter\"),\n dropdownPrefixCls: dropdownPrefixCls,\n column: newColumn,\n columnKey: columnKey,\n filterState: filterState,\n filterMultiple: filterMultiple,\n triggerFilter: triggerFilter,\n locale: locale,\n getPopupContainer: getPopupContainer\n }, renderColumnTitle(column.title, renderProps));\n }\n });\n }\n\n if ('children' in newColumn) {\n newColumn = _extends(_extends({}, newColumn), {\n children: injectFilter(prefixCls, dropdownPrefixCls, newColumn.children, filterStates, triggerFilter, getPopupContainer, locale, columnPos)\n });\n }\n\n return newColumn;\n });\n}\n\nfunction generateFilterInfo(filterStates) {\n var currentFilters = {};\n filterStates.forEach(function (_ref2) {\n var key = _ref2.key,\n filteredKeys = _ref2.filteredKeys;\n currentFilters[key] = filteredKeys || null;\n });\n return currentFilters;\n}\n\nfunction flattenKeys(filters) {\n var keys = [];\n (filters || []).forEach(function (_ref3) {\n var value = _ref3.value,\n children = _ref3.children;\n keys.push(value);\n\n if (children) {\n keys = [].concat(_toConsumableArray(keys), _toConsumableArray(flattenKeys(children)));\n }\n });\n return keys;\n}\n\nexport function getFilterData(data, filterStates) {\n return filterStates.reduce(function (currentData, filterState) {\n var _filterState$column = filterState.column,\n onFilter = _filterState$column.onFilter,\n filters = _filterState$column.filters,\n filteredKeys = filterState.filteredKeys;\n\n if (onFilter && filteredKeys && filteredKeys.length) {\n return currentData.filter(function (record) {\n return filteredKeys.some(function (key) {\n var keys = flattenKeys(filters);\n var keyIndex = keys.findIndex(function (k) {\n return String(k) === String(key);\n });\n var realKey = keyIndex !== -1 ? keys[keyIndex] : key;\n return onFilter(realKey, record);\n });\n });\n }\n\n return currentData;\n }, data);\n}\n\nfunction useFilter(_ref4) {\n var prefixCls = _ref4.prefixCls,\n dropdownPrefixCls = _ref4.dropdownPrefixCls,\n mergedColumns = _ref4.mergedColumns,\n onFilterChange = _ref4.onFilterChange,\n getPopupContainer = _ref4.getPopupContainer,\n tableLocale = _ref4.locale;\n\n var _React$useState = React.useState(collectFilterStates(mergedColumns, true)),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n filterStates = _React$useState2[0],\n setFilterStates = _React$useState2[1];\n\n var mergedFilterStates = React.useMemo(function () {\n var collectedStates = collectFilterStates(mergedColumns, false); // Return if not controlled\n\n if (collectedStates.every(function (_ref5) {\n var filteredKeys = _ref5.filteredKeys;\n return filteredKeys === undefined;\n })) {\n return filterStates;\n }\n\n return collectedStates;\n }, [mergedColumns, filterStates]);\n var getFilters = React.useCallback(function () {\n return generateFilterInfo(mergedFilterStates);\n }, [mergedFilterStates]);\n\n var triggerFilter = function triggerFilter(filterState) {\n var newFilterStates = mergedFilterStates.filter(function (_ref6) {\n var key = _ref6.key;\n return key !== filterState.key;\n });\n newFilterStates.push(filterState);\n setFilterStates(newFilterStates);\n onFilterChange(generateFilterInfo(newFilterStates), newFilterStates);\n };\n\n var transformColumns = function transformColumns(innerColumns) {\n return injectFilter(prefixCls, dropdownPrefixCls, innerColumns, mergedFilterStates, triggerFilter, getPopupContainer, tableLocale);\n };\n\n return [transformColumns, mergedFilterStates, getFilters];\n}\n\nexport default useFilter;"]},"metadata":{},"sourceType":"module"}