1 line
9.8 KiB
JSON
1 line
9.8 KiB
JSON
|
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nexport var SEARCH_MARK = '__rc_cascader_search_mark__';\nvar defaultFilter = function defaultFilter(search, options, _ref) {\n var _ref$label = _ref.label,\n label = _ref$label === void 0 ? '' : _ref$label;\n return options.some(function (opt) {\n return String(opt[label]).toLowerCase().includes(search.toLowerCase());\n });\n};\nvar defaultRender = function defaultRender(inputValue, path, prefixCls, fieldNames) {\n return path.map(function (opt) {\n return opt[fieldNames.label];\n }).join(' / ');\n};\nexport default (function (search, options, fieldNames, prefixCls, config, changeOnSelect) {\n var _config$filter = config.filter,\n filter = _config$filter === void 0 ? defaultFilter : _config$filter,\n _config$render = config.render,\n render = _config$render === void 0 ? defaultRender : _config$render,\n _config$limit = config.limit,\n limit = _config$limit === void 0 ? 50 : _config$limit,\n sort = config.sort;\n return React.useMemo(function () {\n var filteredOptions = [];\n if (!search) {\n return [];\n }\n function dig(list, pathOptions) {\n var parentDisabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n list.forEach(function (option) {\n // Perf saving when `sort` is disabled and `limit` is provided\n if (!sort && limit !== false && limit > 0 && filteredOptions.length >= limit) {\n return;\n }\n var connectedPathOptions = [].concat(_toConsumableArray(pathOptions), [option]);\n var children = option[fieldNames.children];\n var mergedDisabled = parentDisabled || option.disabled;\n\n // If current option is filterable\n if (\n // If is leaf option\n !children || children.length === 0 ||\n // If is changeOnSelect\n changeOnSelect) {\n if (filter(search, connectedPathOptions, {\n label: fieldNames.label\n })) {\n filteredOptions.push(_objectSpread(_objectSpread({}, option), {}, _defineProperty(_defineProperty(_defineProperty({\n disabled: mergedDisabled\n }, fieldNames.label, render(search, connectedPathOptions, prefixCls, fieldNames)), SEARCH_MARK, connectedPathOptions), fieldNames.children, undefined)));\n }\n }\n if (children) {\n dig(option[fieldNames.children], connectedPathOptions, mergedDisabled);\n }\n });\n }\n dig(options, []);\n\n // Do sort\n if (sort) {\n filteredOptions.sort(function (a, b) {\n return sort(a[SEARCH_MARK], b[SEARCH_MARK], search, fieldNames);\n });\n }\n return limit !== false && limit > 0 ? filteredOptions.slice(0, limit) : filteredOptions;\n }, [search, options, fieldNames, prefixCls, render, changeOnSelect, filter, sort, limit]);\n});","map":{"version":3,"names":["_defineProperty","_objectSpread","_toConsumableArray","React","SEARCH_MARK","defaultFilter","search","options","_ref","_ref$label","label","some","opt","String","toLowerCase","includes","defaultRender","inputValue","path","prefixCls","fieldNames","map","join","config","changeOnSelect","_config$filter","filter","_config$render","render","_config$limit","limit","sort","useMemo","filteredOptions","dig","list","pathOptions","parentDisabled","arguments","length","undefined","forEach","option","connectedPathOptions","concat","children","mergedDisabled","disabled","push","a","b","slice"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-cascader/es/hooks/useSearchOptions.js"],"sourcesContent":["import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toCo
|