1 | "use strict";
|
2 |
|
3 | var _typeof = require("@babel/runtime/helpers/typeof");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = void 0;
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | var _legacyUtil = require("../utils/legacyUtil");
|
10 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
11 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var useOptions = function useOptions(options, children, fieldNames, optionFilterProp, optionLabelProp) {
|
17 | return React.useMemo(function () {
|
18 | var mergedOptions = options;
|
19 | var childrenAsData = !options;
|
20 | if (childrenAsData) {
|
21 | mergedOptions = (0, _legacyUtil.convertChildrenToData)(children);
|
22 | }
|
23 | var valueOptions = new Map();
|
24 | var labelOptions = new Map();
|
25 | var setLabelOptions = function setLabelOptions(labelOptionsMap, option, key) {
|
26 | if (key && typeof key === 'string') {
|
27 | labelOptionsMap.set(option[key], option);
|
28 | }
|
29 | };
|
30 | var dig = function dig(optionList) {
|
31 | var isChildren = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
32 |
|
33 | for (var i = 0; i < optionList.length; i += 1) {
|
34 | var option = optionList[i];
|
35 | if (!option[fieldNames.options] || isChildren) {
|
36 | valueOptions.set(option[fieldNames.value], option);
|
37 | setLabelOptions(labelOptions, option, fieldNames.label);
|
38 |
|
39 | setLabelOptions(labelOptions, option, optionFilterProp);
|
40 | setLabelOptions(labelOptions, option, optionLabelProp);
|
41 | } else {
|
42 | dig(option[fieldNames.options], true);
|
43 | }
|
44 | }
|
45 | };
|
46 | dig(mergedOptions);
|
47 | return {
|
48 | options: mergedOptions,
|
49 | valueOptions: valueOptions,
|
50 | labelOptions: labelOptions
|
51 | };
|
52 | }, [options, children, fieldNames, optionFilterProp, optionLabelProp]);
|
53 | };
|
54 | var _default = exports.default = useOptions; |
\ | No newline at end of file |