1 line
7.6 KiB
JSON
1 line
7.6 KiB
JSON
|
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nimport { toArray } from \"../utils/commonUtil\";\nimport { injectPropsWithOption } from \"../utils/valueUtil\";\nfunction includes(test, search) {\n return toArray(test).join('').toUpperCase().includes(search);\n}\nexport default (function (options, fieldNames, searchValue, filterOption, optionFilterProp) {\n return React.useMemo(function () {\n if (!searchValue || filterOption === false) {\n return options;\n }\n var fieldOptions = fieldNames.options,\n fieldLabel = fieldNames.label,\n fieldValue = fieldNames.value;\n var filteredOptions = [];\n var customizeFilter = typeof filterOption === 'function';\n var upperSearch = searchValue.toUpperCase();\n var filterFunc = customizeFilter ? filterOption : function (_, option) {\n // Use provided `optionFilterProp`\n if (optionFilterProp) {\n return includes(option[optionFilterProp], upperSearch);\n }\n\n // Auto select `label` or `value` by option type\n if (option[fieldOptions]) {\n // hack `fieldLabel` since `OptionGroup` children is not `label`\n return includes(option[fieldLabel !== 'children' ? fieldLabel : 'label'], upperSearch);\n }\n return includes(option[fieldValue], upperSearch);\n };\n var wrapOption = customizeFilter ? function (opt) {\n return injectPropsWithOption(opt);\n } : function (opt) {\n return opt;\n };\n options.forEach(function (item) {\n // Group should check child options\n if (item[fieldOptions]) {\n // Check group first\n var matchGroup = filterFunc(searchValue, wrapOption(item));\n if (matchGroup) {\n filteredOptions.push(item);\n } else {\n // Check option\n var subOptions = item[fieldOptions].filter(function (subItem) {\n return filterFunc(searchValue, wrapOption(subItem));\n });\n if (subOptions.length) {\n filteredOptions.push(_objectSpread(_objectSpread({}, item), {}, _defineProperty({}, fieldOptions, subOptions)));\n }\n }\n return;\n }\n if (filterFunc(searchValue, wrapOption(item))) {\n filteredOptions.push(item);\n }\n });\n return filteredOptions;\n }, [options, filterOption, optionFilterProp, searchValue, fieldNames]);\n});","map":{"version":3,"names":["_defineProperty","_objectSpread","React","toArray","injectPropsWithOption","includes","test","search","join","toUpperCase","options","fieldNames","searchValue","filterOption","optionFilterProp","useMemo","fieldOptions","fieldLabel","label","fieldValue","value","filteredOptions","customizeFilter","upperSearch","filterFunc","_","option","wrapOption","opt","forEach","item","matchGroup","push","subOptions","filter","subItem","length"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-select/es/hooks/useFilterOptions.js"],"sourcesContent":["import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nimport { toArray } from \"../utils/commonUtil\";\nimport { injectPropsWithOption } from \"../utils/valueUtil\";\nfunction includes(test, search) {\n return toArray(test).join('').toUpperCase().includes(search);\n}\nexport default (function (options, fieldNames, searchValue, filterOption, optionFilterProp) {\n return React.useMemo(function () {\n if (!searchValue || filterOption === false) {\n return options;\n }\n var fieldOptions = fieldNames.options,\n fieldLabel = fieldNames.label,\n fieldValue = fieldNames.value;\n var filteredOptions = [];\n var customizeFilter = typeof filterOption === 'function';\n var upperSearch = searchValue.toUpperCase();\n var filterFunc = customizeFilter ? filterOption : function (_, option) {\n // Use provided `option
|