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
@@ -25,27 +25,18 @@ var _checkbox = _interopRequireDefault(require("../checkbox"));
25
25
 
26
26
  var _localeContext = _interopRequireDefault(require("../locale/locale-context"));
27
27
 
28
- var _formContext = _interopRequireDefault(require("../form-context"));
29
-
30
28
  var _button = _interopRequireDefault(require("../button"));
31
29
 
32
30
  var _input = _interopRequireDefault(require("../input"));
33
31
 
34
32
  require("./style");
35
33
 
36
- var _invariant = _interopRequireDefault(require("invariant"));
34
+ var _optionUtils = require("../utils/option-utils");
37
35
 
38
- var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options", "clearWhenOptionsUpdated"],
39
- _excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children"];
36
+ var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options", "clearWhenOptionsUpdated"];
40
37
 
41
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
42
39
 
43
- 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); }
44
-
45
- 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); } }
46
-
47
- 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); }); }; }
48
-
49
40
  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; }
50
41
 
51
42
  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; }
@@ -81,25 +72,6 @@ var Option = _select.default.Option,
81
72
  exports.OptGroup = OptGroup;
82
73
  exports.Option = Option;
83
74
 
84
- var compareOptions = function compareOptions(newOptions, oldOptions) {
85
- if ((oldOptions === null || oldOptions === void 0 ? void 0 : oldOptions.length) !== newOptions.length) {
86
- return true;
87
- }
88
-
89
- if (Array.isArray(oldOptions)) {
90
- for (var i = 0; i < oldOptions.length; i++) {
91
- var newOption = oldOptions[i];
92
- var originOption = newOptions[i];
93
-
94
- if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
95
- return true;
96
- }
97
- }
98
- }
99
-
100
- return false;
101
- };
102
-
103
75
  var IglooSelect = function IglooSelect(_ref) {
104
76
  var valueProp = _ref.value,
105
77
  className = _ref.className,
@@ -134,43 +106,38 @@ var IglooSelect = function IglooSelect(_ref) {
134
106
  displayOptions = _useState6[0],
135
107
  setDisplay = _useState6[1];
136
108
 
137
- var _useState7 = (0, _react.useState)(options),
138
- _useState8 = _slicedToArray(_useState7, 2),
139
- originOptions = _useState8[0],
140
- setOrigin = _useState8[1];
141
-
109
+ var originOptions = (0, _react.useRef)(options);
142
110
  (0, _react.useEffect)(function () {
143
111
  typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
144
112
  }, [selected]);
145
113
  (0, _react.useEffect)(function () {
146
- setSelected(valueProp);
114
+ valueProp !== selected && setSelected(valueProp);
147
115
  }, [valueProp]);
148
- (0, _react.useEffect)(function () {
149
- setDisplay(options);
150
- setOrigin(options);
151
- }, [options]);
152
116
  (0, _react.useEffect)(function () {
153
117
  var setFieldValue = rest.setFieldValue;
154
118
 
155
- if (clearWhenOptionsUpdated && compareOptions(options, originOptions)) {
156
- typeof setFieldValue === 'function' && setFieldValue();
157
- }
158
- }, [options, originOptions]);
159
- (0, _react.useEffect)(function () {
160
- var setFieldValue = rest.setFieldValue;
161
- var foundValue = options.find(function (option) {
162
- return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
163
- });
119
+ if ((0, _optionUtils.compareOptions)(options, originOptions.current)) {
120
+ if (clearWhenOptionsUpdated) {
121
+ typeof setFieldValue === 'function' && setFieldValue();
122
+ } else {
123
+ var foundValue = options.find(function (option) {
124
+ return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
125
+ });
126
+
127
+ if (!foundValue && valueProp !== undefined) {
128
+ typeof setFieldValue === 'function' && setFieldValue();
129
+ }
130
+ }
164
131
 
165
- if (!foundValue && valueProp !== undefined) {
166
- typeof setFieldValue === 'function' && setFieldValue();
132
+ setDisplay(options);
133
+ originOptions.current = options;
167
134
  }
168
- }, [valueProp, options]);
135
+ }, [options]);
169
136
 
170
- var _useState9 = (0, _react.useState)(false),
171
- _useState10 = _slicedToArray(_useState9, 2),
172
- dropVisible = _useState10[0],
173
- setDropVisible = _useState10[1];
137
+ var _useState7 = (0, _react.useState)(false),
138
+ _useState8 = _slicedToArray(_useState7, 2),
139
+ dropVisible = _useState8[0],
140
+ setDropVisible = _useState8[1];
174
141
 
175
142
  var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
176
143
  typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
@@ -361,152 +328,14 @@ var IglooSelect = function IglooSelect(_ref) {
361
328
  });
362
329
  };
363
330
 
364
- var AttachedSelect = function AttachedSelect(_ref11) {
365
- var options = _ref11.options,
366
- optionGroups = _ref11.optionGroups,
367
- getOptions = _ref11.getOptions,
368
- datasourceKey = _ref11.datasourceKey,
369
- dependField = _ref11.dependField,
370
- children = _ref11.children,
371
- rest = _objectWithoutProperties(_ref11, _excluded2);
372
-
373
- var _useState11 = (0, _react.useState)(),
374
- _useState12 = _slicedToArray(_useState11, 2),
375
- _options = _useState12[0],
376
- setOptions = _useState12[1];
377
-
378
- var _useContext2 = (0, _react.useContext)(_formContext.default),
379
- selectDatasourceApi = _useContext2.selectDatasourceApi;
380
-
381
- var getFormInstance = rest.getFormInstance;
382
- var form = typeof getFormInstance === 'function' && getFormInstance();
383
- var dependFieldValue = form && dependField && form.getFieldValue(dependField);
384
- var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
385
- (0, _invariant.default)(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
386
- (0, _react.useEffect)(function () {
387
- var calcOptions = /*#__PURE__*/function () {
388
- var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
389
- var _options2, query, api, rst, _yield$rst$json, data;
390
-
391
- return regeneratorRuntime.wrap(function _callee$(_context) {
392
- while (1) {
393
- switch (_context.prev = _context.next) {
394
- case 0:
395
- if (!Array.isArray(options)) {
396
- _context.next = 2;
397
- break;
398
- }
399
-
400
- return _context.abrupt("return", options);
401
-
402
- case 2:
403
- if (!(Array.isArray(children) || _typeof(children) === 'object')) {
404
- _context.next = 4;
405
- break;
406
- }
407
-
408
- return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
409
- return {
410
- label: child.props.children,
411
- value: child.props.value
412
- };
413
- }) : [{
414
- label: children.props.children,
415
- value: children.props.value
416
- }]);
417
-
418
- case 4:
419
- if (!Array.isArray(optionsFromGetOptions)) {
420
- _context.next = 6;
421
- break;
422
- }
423
-
424
- return _context.abrupt("return", optionsFromGetOptions);
425
-
426
- case 6:
427
- if (!optionGroups) {
428
- _context.next = 11;
429
- break;
430
- }
431
-
432
- if (!dependFieldValue) {
433
- _context.next = 11;
434
- break;
435
- }
436
-
437
- _options2 = [];
438
- optionGroups.forEach(function (_ref13) {
439
- var parentKey = _ref13.parentKey,
440
- _ref13$options = _ref13.options,
441
- options = _ref13$options === void 0 ? [] : _ref13$options;
442
-
443
- if (Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue) {
444
- _options2.push.apply(_options2, _toConsumableArray(options));
445
- }
446
- });
447
- return _context.abrupt("return", _options2);
448
-
449
- case 11:
450
- if (!(selectDatasourceApi && datasourceKey)) {
451
- _context.next = 28;
452
- break;
453
- }
454
-
455
- query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
456
- return "parent=".concat(v);
457
- }).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
458
- api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
459
- _context.prev = 14;
460
- _context.next = 17;
461
- return fetch(query ? "".concat(api, "?").concat(query) : api);
462
-
463
- case 17:
464
- rst = _context.sent;
465
- _context.next = 20;
466
- return rst.json();
467
-
468
- case 20:
469
- _yield$rst$json = _context.sent;
470
- data = _yield$rst$json.data;
471
- return _context.abrupt("return", data || []);
472
-
473
- case 25:
474
- _context.prev = 25;
475
- _context.t0 = _context["catch"](14);
476
- return _context.abrupt("return", []);
477
-
478
- case 28:
479
- return _context.abrupt("return", []);
480
-
481
- case 29:
482
- case "end":
483
- return _context.stop();
484
- }
485
- }
486
- }, _callee, null, [[14, 25]]);
487
- }));
488
-
489
- return function calcOptions() {
490
- return _ref12.apply(this, arguments);
491
- };
492
- }();
493
-
494
- calcOptions().then(function (newOptions) {
495
- if (compareOptions(newOptions, _options || [])) {
496
- setOptions(newOptions);
497
- }
498
- });
499
- }, [options, optionGroups, dependFieldValue, optionsFromGetOptions, _options]);
500
- return _options ? (0, _jsxRuntime.jsx)(IglooSelect, _objectSpread({
501
- options: _options
502
- }, rest)) : null;
503
- };
331
+ var AttachedSelect = Object.assign((0, _optionUtils.optionsHOC)(IglooSelect), {
332
+ Option: Option,
333
+ OptGroup: OptGroup
334
+ });
504
335
 
505
336
  AttachedSelect.formItemPropsHandler = function (config) {
506
337
  return {};
507
338
  };
508
339
 
509
- AttachedSelect.Option = Option;
510
- AttachedSelect.OptGroup = OptGroup;
511
340
  var _default = AttachedSelect;
512
341
  exports.default = _default;
@@ -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,250 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.compareOptions = void 0;
7
+ exports.optionsHOC = optionsHOC;
8
+
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+
11
+ var _react = require("react");
12
+
13
+ var _formContext = _interopRequireDefault(require("../form-context"));
14
+
15
+ var _invariant = _interopRequireDefault(require("invariant"));
16
+
17
+ var _excluded = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children"];
18
+
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+
21
+ 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; }
22
+
23
+ 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; }
24
+
25
+ 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; }
26
+
27
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
28
+
29
+ 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."); }
30
+
31
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
32
+
33
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
34
+
35
+ 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); }
36
+
37
+ 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); } }
38
+
39
+ 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); }); }; }
40
+
41
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
42
+
43
+ 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."); }
44
+
45
+ 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); }
46
+
47
+ 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; }
48
+
49
+ 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; }
50
+
51
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
52
+
53
+ 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; }
54
+
55
+ 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; }
56
+
57
+ var compareOptions = function compareOptions(newOptions, oldOptions) {
58
+ if (!Array.isArray(oldOptions)) {
59
+ return true;
60
+ }
61
+
62
+ if ((oldOptions === null || oldOptions === void 0 ? void 0 : oldOptions.length) !== newOptions.length) {
63
+ return true;
64
+ }
65
+
66
+ if (Array.isArray(oldOptions)) {
67
+ for (var i = 0; i < oldOptions.length; i++) {
68
+ var newOption = oldOptions[i];
69
+ var originOption = newOptions[i];
70
+
71
+ if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
72
+ return true;
73
+ }
74
+ }
75
+ }
76
+
77
+ return false;
78
+ };
79
+
80
+ exports.compareOptions = compareOptions;
81
+
82
+ function optionsHOC(Component) {
83
+ return function (props) {
84
+ var options = props.options,
85
+ optionGroups = props.optionGroups,
86
+ getOptions = props.getOptions,
87
+ datasourceKey = props.datasourceKey,
88
+ dependField = props.dependField,
89
+ children = props.children,
90
+ rest = _objectWithoutProperties(props, _excluded);
91
+
92
+ var _useState = (0, _react.useState)(false),
93
+ _useState2 = _slicedToArray(_useState, 2),
94
+ updating = _useState2[0],
95
+ setUpdating = _useState2[1];
96
+
97
+ var _useState3 = (0, _react.useState)(),
98
+ _useState4 = _slicedToArray(_useState3, 2),
99
+ _options = _useState4[0],
100
+ setOptions = _useState4[1];
101
+
102
+ var _useState5 = (0, _react.useState)(),
103
+ _useState6 = _slicedToArray(_useState5, 2),
104
+ searchKey = _useState6[0],
105
+ setSearchKey = _useState6[1];
106
+
107
+ var optionsRef = (0, _react.useRef)(_options);
108
+
109
+ var _useContext = (0, _react.useContext)(_formContext.default),
110
+ selectDatasourceApi = _useContext.selectDatasourceApi;
111
+
112
+ var getFormInstance = rest.getFormInstance;
113
+ var form = typeof getFormInstance === 'function' && getFormInstance();
114
+ var dependFieldValue = form && dependField && form.getFieldValue(dependField);
115
+ var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
116
+ (0, _react.useEffect)(function () {
117
+ if (!Array.isArray(optionsFromGetOptions)) {
118
+ return;
119
+ }
120
+
121
+ if (compareOptions(optionsFromGetOptions, optionsRef.current)) {
122
+ optionsRef.current = optionsFromGetOptions;
123
+ setOptions(optionsFromGetOptions);
124
+ }
125
+ }, [optionsFromGetOptions]);
126
+ (0, _invariant.default)(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
127
+ (0, _react.useEffect)(function () {
128
+ setUpdating(true);
129
+
130
+ var calcOptions = /*#__PURE__*/function () {
131
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
132
+ var _options2, query, api, rst, _yield$rst$json, data;
133
+
134
+ return regeneratorRuntime.wrap(function _callee$(_context) {
135
+ while (1) {
136
+ switch (_context.prev = _context.next) {
137
+ case 0:
138
+ if (!Array.isArray(options)) {
139
+ _context.next = 2;
140
+ break;
141
+ }
142
+
143
+ return _context.abrupt("return", options);
144
+
145
+ case 2:
146
+ if (!(Array.isArray(children) || _typeof(children) === 'object')) {
147
+ _context.next = 4;
148
+ break;
149
+ }
150
+
151
+ return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
152
+ return {
153
+ label: child.props.children,
154
+ value: child.props.value
155
+ };
156
+ }) : [{
157
+ label: children.props.children,
158
+ value: children.props.value
159
+ }]);
160
+
161
+ case 4:
162
+ if (!optionGroups) {
163
+ _context.next = 9;
164
+ break;
165
+ }
166
+
167
+ if (!dependFieldValue) {
168
+ _context.next = 9;
169
+ break;
170
+ }
171
+
172
+ _options2 = [];
173
+ optionGroups.forEach(function (_ref2) {
174
+ var parentKey = _ref2.parentKey,
175
+ _ref2$options = _ref2.options,
176
+ options = _ref2$options === void 0 ? [] : _ref2$options;
177
+
178
+ if (Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue) {
179
+ _options2.push.apply(_options2, _toConsumableArray(options));
180
+ }
181
+ });
182
+ return _context.abrupt("return", _options2);
183
+
184
+ case 9:
185
+ if (!(selectDatasourceApi && datasourceKey)) {
186
+ _context.next = 27;
187
+ break;
188
+ }
189
+
190
+ query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
191
+ return "parent=".concat(v);
192
+ }).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
193
+
194
+ if (searchKey) {
195
+ query += "&search_keyword=".concat(searchKey);
196
+ }
197
+
198
+ api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
199
+ _context.prev = 13;
200
+ _context.next = 16;
201
+ return fetch(query ? "".concat(api, "?").concat(query) : api);
202
+
203
+ case 16:
204
+ rst = _context.sent;
205
+ _context.next = 19;
206
+ return rst.json();
207
+
208
+ case 19:
209
+ _yield$rst$json = _context.sent;
210
+ data = _yield$rst$json.data;
211
+ return _context.abrupt("return", data || []);
212
+
213
+ case 24:
214
+ _context.prev = 24;
215
+ _context.t0 = _context["catch"](13);
216
+ return _context.abrupt("return", []);
217
+
218
+ case 27:
219
+ return _context.abrupt("return", []);
220
+
221
+ case 28:
222
+ case "end":
223
+ return _context.stop();
224
+ }
225
+ }
226
+ }, _callee, null, [[13, 24]]);
227
+ }));
228
+
229
+ return function calcOptions() {
230
+ return _ref.apply(this, arguments);
231
+ };
232
+ }();
233
+
234
+ calcOptions().then(function (newOptions) {
235
+ if (compareOptions(newOptions, optionsRef.current)) {
236
+ setOptions(newOptions);
237
+ optionsRef.current = newOptions;
238
+ }
239
+
240
+ setUpdating(false);
241
+ });
242
+ }, [options, optionGroups, dependFieldValue, searchKey]);
243
+ return _options ? (0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread({
244
+ options: _options
245
+ }, rest), {}, {
246
+ onSearch: setSearchKey,
247
+ optionsUpdating: updating
248
+ })) : null;
249
+ };
250
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",
@@ -16,7 +16,8 @@
16
16
  "extract:zh": "locale=zh-CN formatjs extract 'src/**/*.ts*' --out-file src/locale/zh-CN/messages.json --format compile.js",
17
17
  "extract:vi": "locale=vi-VN formatjs extract 'src/**/*.ts*' --out-file src/locale/vi-VN/messages.json --format compile.js",
18
18
  "extract:th": "locale=th-TH formatjs extract 'src/**/*.ts*' --out-file src/locale/th-TH/messages.json --format compile.js",
19
- "extract": "yarn extract:en && yarn extract:id && yarn extract:zh && yarn extract:vi && yarn extract:th",
19
+ "extract:zh-TW": "locale=zh-TW formatjs extract 'src/**/*.ts*' --out-file src/locale/zh-TW/messages.json --format compile.js",
20
+ "extract": "yarn extract:en && yarn extract:id && yarn extract:zh && yarn extract:vi && yarn extract:th && yarn extract:zh-TW",
20
21
  "preinstall": "rm -rf src/.umi && rm -rf src/.umi-production"
21
22
  },
22
23
  "main": "./lib/index.js",
@@ -42,7 +43,6 @@
42
43
  "invariant": "^2.2.4",
43
44
  "lodash.debounce": "^4.0.8",
44
45
  "omit.js": "^2.0.2",
45
- "react": "^16.12.0",
46
46
  "react-json-view": "^1.19.1",
47
47
  "react-pdf": "^5.7.2"
48
48
  },
@@ -57,23 +57,24 @@
57
57
  "@umijs/plugin-antd": "^0.8.0",
58
58
  "@umijs/plugin-esbuild": "^1.3.1",
59
59
  "@umijs/test": "^3.0.5",
60
- "antd-dayjs-webpack-plugin": "^1.0.6",
61
60
  "babel-plugin-import": "^1.13.3",
62
- "dayjs": "^1.10.3",
63
61
  "dumi": "^v1.1.0-rc.5",
64
62
  "father-build": "^1.19.1",
65
63
  "gh-pages": "^3.0.0",
66
64
  "lint-staged": "^10.0.7",
67
- "moment": "^2.29.1",
68
65
  "prettier": "^1.19.1",
69
66
  "url-loader": "^4.1.1",
70
67
  "vfile-message": "^2.0.4",
71
68
  "yorkie": "^2.0.0"
72
69
  },
73
70
  "peerDependencies": {
74
- "@ant-design/icons": "^4.2.2",
75
- "antd": "^4.6.5",
76
- "dayjs": "^1.10.3"
71
+ "@ant-design/icons": ">=4.0.0",
72
+ "antd": ">=4.6.5",
73
+ "antd-dayjs-webpack-plugin": ">=1.0.0",
74
+ "dayjs": ">=1.0.0",
75
+ "moment": ">=2.0.0",
76
+ "react": ">16.9.0",
77
+ "react-dom": ">=16.9.0"
77
78
  },
78
79
  "license": "MIT"
79
80
  }