iglooform 2.5.2 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/es/checkbox/index.d.ts +7 -7
  2. package/es/checkbox/index.js +85 -5
  3. package/es/form/elements.js +3 -1
  4. package/es/index.d.ts +1 -0
  5. package/es/index.js +1 -0
  6. package/es/locale/en-US/messages.json +4 -0
  7. package/es/locale/id-ID/messages.json +4 -0
  8. package/es/locale/th-TH/messages.json +4 -0
  9. package/es/locale/vi-VN/messages.json +4 -0
  10. package/es/locale/zh-CN/messages.json +4 -0
  11. package/es/locale/zh-TW/messages.json +5 -0
  12. package/es/radio/index.d.ts +6 -6
  13. package/es/radio/index.js +79 -22
  14. package/es/radio/radio-group-with-other.d.ts +1 -1
  15. package/es/radio/radio-group-with-other.js +41 -4
  16. package/es/radio/style/empty.svg +12 -0
  17. package/es/search-box/index.d.ts +31 -0
  18. package/es/search-box/index.js +266 -0
  19. package/es/search-box/style/index.d.ts +1 -0
  20. package/es/search-box/style/index.js +1 -0
  21. package/es/search-box/style/index.less +162 -0
  22. package/es/select/attached-select.d.ts +2 -12
  23. package/es/select/attached-select.js +28 -198
  24. package/es/utils/option-utils.d.ts +24 -0
  25. package/es/utils/option-utils.js +233 -0
  26. package/lib/checkbox/index.d.ts +7 -7
  27. package/lib/checkbox/index.js +87 -5
  28. package/lib/form/elements.js +4 -1
  29. package/lib/index.d.ts +1 -0
  30. package/lib/index.js +9 -0
  31. package/lib/locale/en-US/messages.json +4 -0
  32. package/lib/locale/id-ID/messages.json +4 -0
  33. package/lib/locale/th-TH/messages.json +4 -0
  34. package/lib/locale/vi-VN/messages.json +4 -0
  35. package/lib/locale/zh-CN/messages.json +4 -0
  36. package/lib/locale/zh-TW/messages.json +5 -0
  37. package/lib/radio/index.d.ts +6 -6
  38. package/lib/radio/index.js +83 -22
  39. package/lib/radio/radio-group-with-other.d.ts +1 -1
  40. package/lib/radio/radio-group-with-other.js +41 -3
  41. package/lib/radio/style/empty.svg +12 -0
  42. package/lib/search-box/index.d.ts +31 -0
  43. package/lib/search-box/index.js +287 -0
  44. package/lib/search-box/style/index.d.ts +1 -0
  45. package/lib/search-box/style/index.js +3 -0
  46. package/lib/search-box/style/index.less +162 -0
  47. package/lib/select/attached-select.d.ts +2 -12
  48. package/lib/select/attached-select.js +27 -198
  49. package/lib/utils/option-utils.d.ts +24 -0
  50. package/lib/utils/option-utils.js +250 -0
  51. package/package.json +10 -9
@@ -1,13 +1,6 @@
1
1
  import "antd/es/select/style";
2
2
  import _Select from "antd/es/select";
3
- var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options", "clearWhenOptionsUpdated"],
4
- _excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children"];
5
-
6
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
-
8
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
-
10
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
3
+ var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options", "clearWhenOptionsUpdated"];
11
4
 
12
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
6
 
@@ -40,41 +33,21 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
40
33
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
41
34
 
42
35
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
43
- import { useEffect, useState, useContext } from 'react';
36
+ import { useEffect, useState, useContext, useRef } from 'react';
44
37
  import omit from 'omit.js';
45
38
  import formMethods from '../utils/form-methods';
46
39
  import { ArrowDownOutlined, ArrowUpOutlined, SearchOutlined } from 'iglooicon';
47
40
  import classnames from 'classnames';
48
41
  import Checkbox from '../checkbox';
49
42
  import LocaleContext from '../locale/locale-context';
50
- import FormContext from '../form-context';
51
43
  import Button from '../button';
52
44
  import Input from '../input';
53
45
  import './style';
54
- import invariant from 'invariant';
46
+ import { compareOptions, optionsHOC } from '../utils/option-utils';
55
47
  var Option = _Select.Option,
56
48
  OptGroup = _Select.OptGroup;
57
49
  export { Option, OptGroup };
58
50
 
59
- var compareOptions = function compareOptions(newOptions, oldOptions) {
60
- if ((oldOptions === null || oldOptions === void 0 ? void 0 : oldOptions.length) !== newOptions.length) {
61
- return true;
62
- }
63
-
64
- if (Array.isArray(oldOptions)) {
65
- for (var i = 0; i < oldOptions.length; i++) {
66
- var newOption = oldOptions[i];
67
- var originOption = newOptions[i];
68
-
69
- if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
70
- return true;
71
- }
72
- }
73
- }
74
-
75
- return false;
76
- };
77
-
78
51
  var IglooSelect = function IglooSelect(_ref) {
79
52
  var valueProp = _ref.value,
80
53
  className = _ref.className,
@@ -109,43 +82,38 @@ var IglooSelect = function IglooSelect(_ref) {
109
82
  displayOptions = _useState6[0],
110
83
  setDisplay = _useState6[1];
111
84
 
112
- var _useState7 = useState(options),
113
- _useState8 = _slicedToArray(_useState7, 2),
114
- originOptions = _useState8[0],
115
- setOrigin = _useState8[1];
116
-
85
+ var originOptions = useRef(options);
117
86
  useEffect(function () {
118
87
  typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
119
88
  }, [selected]);
120
89
  useEffect(function () {
121
- setSelected(valueProp);
90
+ valueProp !== selected && setSelected(valueProp);
122
91
  }, [valueProp]);
123
- useEffect(function () {
124
- setDisplay(options);
125
- setOrigin(options);
126
- }, [options]);
127
92
  useEffect(function () {
128
93
  var setFieldValue = rest.setFieldValue;
129
94
 
130
- if (clearWhenOptionsUpdated && compareOptions(options, originOptions)) {
131
- typeof setFieldValue === 'function' && setFieldValue();
132
- }
133
- }, [options, originOptions]);
134
- useEffect(function () {
135
- var setFieldValue = rest.setFieldValue;
136
- var foundValue = options.find(function (option) {
137
- return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
138
- });
95
+ if (compareOptions(options, originOptions.current)) {
96
+ if (clearWhenOptionsUpdated) {
97
+ typeof setFieldValue === 'function' && setFieldValue();
98
+ } else {
99
+ var foundValue = options.find(function (option) {
100
+ return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
101
+ });
139
102
 
140
- if (!foundValue && valueProp !== undefined) {
141
- typeof setFieldValue === 'function' && setFieldValue();
103
+ if (!foundValue && valueProp !== undefined) {
104
+ typeof setFieldValue === 'function' && setFieldValue();
105
+ }
106
+ }
107
+
108
+ setDisplay(options);
109
+ originOptions.current = options;
142
110
  }
143
- }, [valueProp, options]);
111
+ }, [options]);
144
112
 
145
- var _useState9 = useState(false),
146
- _useState10 = _slicedToArray(_useState9, 2),
147
- dropVisible = _useState10[0],
148
- setDropVisible = _useState10[1];
113
+ var _useState7 = useState(false),
114
+ _useState8 = _slicedToArray(_useState7, 2),
115
+ dropVisible = _useState8[0],
116
+ setDropVisible = _useState8[1];
149
117
 
150
118
  var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
151
119
  typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
@@ -336,151 +304,13 @@ var IglooSelect = function IglooSelect(_ref) {
336
304
  });
337
305
  };
338
306
 
339
- var AttachedSelect = function AttachedSelect(_ref11) {
340
- var options = _ref11.options,
341
- optionGroups = _ref11.optionGroups,
342
- getOptions = _ref11.getOptions,
343
- datasourceKey = _ref11.datasourceKey,
344
- dependField = _ref11.dependField,
345
- children = _ref11.children,
346
- rest = _objectWithoutProperties(_ref11, _excluded2);
347
-
348
- var _useState11 = useState(),
349
- _useState12 = _slicedToArray(_useState11, 2),
350
- _options = _useState12[0],
351
- setOptions = _useState12[1];
352
-
353
- var _useContext2 = useContext(FormContext),
354
- selectDatasourceApi = _useContext2.selectDatasourceApi;
355
-
356
- var getFormInstance = rest.getFormInstance;
357
- var form = typeof getFormInstance === 'function' && getFormInstance();
358
- var dependFieldValue = form && dependField && form.getFieldValue(dependField);
359
- var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
360
- invariant(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
361
- useEffect(function () {
362
- var calcOptions = /*#__PURE__*/function () {
363
- var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
364
- var _options2, query, api, rst, _yield$rst$json, data;
365
-
366
- return regeneratorRuntime.wrap(function _callee$(_context) {
367
- while (1) {
368
- switch (_context.prev = _context.next) {
369
- case 0:
370
- if (!Array.isArray(options)) {
371
- _context.next = 2;
372
- break;
373
- }
374
-
375
- return _context.abrupt("return", options);
376
-
377
- case 2:
378
- if (!(Array.isArray(children) || _typeof(children) === 'object')) {
379
- _context.next = 4;
380
- break;
381
- }
382
-
383
- return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
384
- return {
385
- label: child.props.children,
386
- value: child.props.value
387
- };
388
- }) : [{
389
- label: children.props.children,
390
- value: children.props.value
391
- }]);
392
-
393
- case 4:
394
- if (!Array.isArray(optionsFromGetOptions)) {
395
- _context.next = 6;
396
- break;
397
- }
398
-
399
- return _context.abrupt("return", optionsFromGetOptions);
400
-
401
- case 6:
402
- if (!optionGroups) {
403
- _context.next = 11;
404
- break;
405
- }
406
-
407
- if (!dependFieldValue) {
408
- _context.next = 11;
409
- break;
410
- }
411
-
412
- _options2 = [];
413
- optionGroups.forEach(function (_ref13) {
414
- var parentKey = _ref13.parentKey,
415
- _ref13$options = _ref13.options,
416
- options = _ref13$options === void 0 ? [] : _ref13$options;
417
-
418
- if (Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue) {
419
- _options2.push.apply(_options2, _toConsumableArray(options));
420
- }
421
- });
422
- return _context.abrupt("return", _options2);
423
-
424
- case 11:
425
- if (!(selectDatasourceApi && datasourceKey)) {
426
- _context.next = 28;
427
- break;
428
- }
429
-
430
- query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
431
- return "parent=".concat(v);
432
- }).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
433
- api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
434
- _context.prev = 14;
435
- _context.next = 17;
436
- return fetch(query ? "".concat(api, "?").concat(query) : api);
437
-
438
- case 17:
439
- rst = _context.sent;
440
- _context.next = 20;
441
- return rst.json();
442
-
443
- case 20:
444
- _yield$rst$json = _context.sent;
445
- data = _yield$rst$json.data;
446
- return _context.abrupt("return", data || []);
447
-
448
- case 25:
449
- _context.prev = 25;
450
- _context.t0 = _context["catch"](14);
451
- return _context.abrupt("return", []);
452
-
453
- case 28:
454
- return _context.abrupt("return", []);
455
-
456
- case 29:
457
- case "end":
458
- return _context.stop();
459
- }
460
- }
461
- }, _callee, null, [[14, 25]]);
462
- }));
463
-
464
- return function calcOptions() {
465
- return _ref12.apply(this, arguments);
466
- };
467
- }();
468
-
469
- calcOptions().then(function (newOptions) {
470
- if (compareOptions(newOptions, _options || [])) {
471
- setOptions(newOptions);
472
- }
473
- });
474
- }, [options, optionGroups, dependFieldValue, optionsFromGetOptions, _options]);
475
- return _options ? _jsx(IglooSelect, _objectSpread({
476
- options: _options
477
- }, rest)) : null;
478
- };
307
+ var AttachedSelect = Object.assign(optionsHOC(IglooSelect), {
308
+ Option: Option,
309
+ OptGroup: OptGroup
310
+ });
479
311
 
480
312
  AttachedSelect.formItemPropsHandler = function (config) {
481
313
  return {};
482
314
  };
483
315
 
484
- AttachedSelect.Option = Option;
485
- AttachedSelect.OptGroup = OptGroup;
486
316
  export default AttachedSelect;
@@ -0,0 +1,24 @@
1
+ import { FC, IglooComponentProps } from '../types';
2
+ import { FormInstance } from 'antd/es/form';
3
+ import { NamePath } from 'antd/es/form/interface';
4
+ import { SelectProps, SelectValue } from 'antd/es/select';
5
+ export declare const compareOptions: (newOptions: any[], oldOptions?: any[] | undefined) => boolean;
6
+ declare type Options = SelectProps<SelectValue>['options'];
7
+ export interface HOCProps extends IglooComponentProps {
8
+ options?: Options;
9
+ getOptions?: (form: FormInstance) => any[];
10
+ optionGroups?: {
11
+ parentKey: string;
12
+ options: Options;
13
+ }[];
14
+ datasourceKey?: string;
15
+ datasourceApi?: string;
16
+ dependField?: NamePath;
17
+ passCompareOptions?: boolean;
18
+ }
19
+ export interface ComponentProps extends IglooComponentProps {
20
+ options?: Options;
21
+ clearWhenOptionsUpdated?: boolean;
22
+ }
23
+ export declare function optionsHOC<T>(Component: FC<T>): FC<HOCProps & T>;
24
+ export {};
@@ -0,0 +1,233 @@
1
+ var _excluded = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children"];
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+
9
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
+
11
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+
13
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
+
15
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
+
17
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
18
+
19
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
20
+
21
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
22
+
23
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
+
25
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
26
+
27
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
28
+
29
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
30
+
31
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
32
+
33
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
34
+
35
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
36
+
37
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
38
+
39
+ import { jsx as _jsx } from "react/jsx-runtime";
40
+ import { useEffect, useState, useContext, useRef } from 'react';
41
+ import FormContext from '../form-context';
42
+ import invariant from 'invariant';
43
+ export var compareOptions = function compareOptions(newOptions, oldOptions) {
44
+ if (!Array.isArray(oldOptions)) {
45
+ return true;
46
+ }
47
+
48
+ if ((oldOptions === null || oldOptions === void 0 ? void 0 : oldOptions.length) !== newOptions.length) {
49
+ return true;
50
+ }
51
+
52
+ if (Array.isArray(oldOptions)) {
53
+ for (var i = 0; i < oldOptions.length; i++) {
54
+ var newOption = oldOptions[i];
55
+ var originOption = newOptions[i];
56
+
57
+ if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
58
+ return true;
59
+ }
60
+ }
61
+ }
62
+
63
+ return false;
64
+ };
65
+ export function optionsHOC(Component) {
66
+ return function (props) {
67
+ var options = props.options,
68
+ optionGroups = props.optionGroups,
69
+ getOptions = props.getOptions,
70
+ datasourceKey = props.datasourceKey,
71
+ dependField = props.dependField,
72
+ children = props.children,
73
+ rest = _objectWithoutProperties(props, _excluded);
74
+
75
+ var _useState = useState(false),
76
+ _useState2 = _slicedToArray(_useState, 2),
77
+ updating = _useState2[0],
78
+ setUpdating = _useState2[1];
79
+
80
+ var _useState3 = useState(),
81
+ _useState4 = _slicedToArray(_useState3, 2),
82
+ _options = _useState4[0],
83
+ setOptions = _useState4[1];
84
+
85
+ var _useState5 = useState(),
86
+ _useState6 = _slicedToArray(_useState5, 2),
87
+ searchKey = _useState6[0],
88
+ setSearchKey = _useState6[1];
89
+
90
+ var optionsRef = useRef(_options);
91
+
92
+ var _useContext = useContext(FormContext),
93
+ selectDatasourceApi = _useContext.selectDatasourceApi;
94
+
95
+ var getFormInstance = rest.getFormInstance;
96
+ var form = typeof getFormInstance === 'function' && getFormInstance();
97
+ var dependFieldValue = form && dependField && form.getFieldValue(dependField);
98
+ var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
99
+ useEffect(function () {
100
+ if (!Array.isArray(optionsFromGetOptions)) {
101
+ return;
102
+ }
103
+
104
+ if (compareOptions(optionsFromGetOptions, optionsRef.current)) {
105
+ optionsRef.current = optionsFromGetOptions;
106
+ setOptions(optionsFromGetOptions);
107
+ }
108
+ }, [optionsFromGetOptions]);
109
+ invariant(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
110
+ useEffect(function () {
111
+ setUpdating(true);
112
+
113
+ var calcOptions = /*#__PURE__*/function () {
114
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
115
+ var _options2, query, api, rst, _yield$rst$json, data;
116
+
117
+ return regeneratorRuntime.wrap(function _callee$(_context) {
118
+ while (1) {
119
+ switch (_context.prev = _context.next) {
120
+ case 0:
121
+ if (!Array.isArray(options)) {
122
+ _context.next = 2;
123
+ break;
124
+ }
125
+
126
+ return _context.abrupt("return", options);
127
+
128
+ case 2:
129
+ if (!(Array.isArray(children) || _typeof(children) === 'object')) {
130
+ _context.next = 4;
131
+ break;
132
+ }
133
+
134
+ return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
135
+ return {
136
+ label: child.props.children,
137
+ value: child.props.value
138
+ };
139
+ }) : [{
140
+ label: children.props.children,
141
+ value: children.props.value
142
+ }]);
143
+
144
+ case 4:
145
+ if (!optionGroups) {
146
+ _context.next = 9;
147
+ break;
148
+ }
149
+
150
+ if (!dependFieldValue) {
151
+ _context.next = 9;
152
+ break;
153
+ }
154
+
155
+ _options2 = [];
156
+ optionGroups.forEach(function (_ref2) {
157
+ var parentKey = _ref2.parentKey,
158
+ _ref2$options = _ref2.options,
159
+ options = _ref2$options === void 0 ? [] : _ref2$options;
160
+
161
+ if (Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue) {
162
+ _options2.push.apply(_options2, _toConsumableArray(options));
163
+ }
164
+ });
165
+ return _context.abrupt("return", _options2);
166
+
167
+ case 9:
168
+ if (!(selectDatasourceApi && datasourceKey)) {
169
+ _context.next = 27;
170
+ break;
171
+ }
172
+
173
+ query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
174
+ return "parent=".concat(v);
175
+ }).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
176
+
177
+ if (searchKey) {
178
+ query += "&search_keyword=".concat(searchKey);
179
+ }
180
+
181
+ api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
182
+ _context.prev = 13;
183
+ _context.next = 16;
184
+ return fetch(query ? "".concat(api, "?").concat(query) : api);
185
+
186
+ case 16:
187
+ rst = _context.sent;
188
+ _context.next = 19;
189
+ return rst.json();
190
+
191
+ case 19:
192
+ _yield$rst$json = _context.sent;
193
+ data = _yield$rst$json.data;
194
+ return _context.abrupt("return", data || []);
195
+
196
+ case 24:
197
+ _context.prev = 24;
198
+ _context.t0 = _context["catch"](13);
199
+ return _context.abrupt("return", []);
200
+
201
+ case 27:
202
+ return _context.abrupt("return", []);
203
+
204
+ case 28:
205
+ case "end":
206
+ return _context.stop();
207
+ }
208
+ }
209
+ }, _callee, null, [[13, 24]]);
210
+ }));
211
+
212
+ return function calcOptions() {
213
+ return _ref.apply(this, arguments);
214
+ };
215
+ }();
216
+
217
+ calcOptions().then(function (newOptions) {
218
+ if (compareOptions(newOptions, optionsRef.current)) {
219
+ setOptions(newOptions);
220
+ optionsRef.current = newOptions;
221
+ }
222
+
223
+ setUpdating(false);
224
+ });
225
+ }, [options, optionGroups, dependFieldValue, searchKey]);
226
+ return _options ? _jsx(Component, _objectSpread(_objectSpread({
227
+ options: _options
228
+ }, rest), {}, {
229
+ onSearch: setSearchKey,
230
+ optionsUpdating: updating
231
+ })) : null;
232
+ };
233
+ }
@@ -1,21 +1,21 @@
1
1
  import { CheckboxProps, CheckboxGroupProps } from 'antd/es/checkbox';
2
2
  import { FC, IglooComponentProps } from '@/types';
3
+ import { ComponentProps } from '../utils/option-utils';
4
+ import { DefaultOptionType } from 'rc-select/lib/Select';
3
5
  import './style/index.less';
4
6
  interface Props extends IglooComponentProps, CheckboxProps {
5
7
  }
6
- interface Option {
7
- label?: any;
8
- value?: string;
9
- disabled?: boolean;
8
+ export interface Option extends DefaultOptionType {
10
9
  extraInfo?: {
11
10
  content: any;
12
11
  shownTrigger: 'unchecked' | 'checked' | 'all';
13
12
  };
14
13
  }
15
- export interface IProps extends IglooComponentProps, Omit<CheckboxGroupProps, 'options'> {
16
- options: Option[];
14
+ export interface IProps extends IglooComponentProps, Omit<CheckboxGroupProps, 'options'>, ComponentProps {
17
15
  className?: string;
16
+ radioType?: string;
17
+ options: Option[];
18
18
  }
19
19
  declare const IglooCheckbox: FC<Props>;
20
20
  export default IglooCheckbox;
21
- export declare const CheckboxGroup: FC<IProps>;
21
+ export declare const CheckboxGroup: FC<import("../utils/option-utils").HOCProps & IProps>;