iglooform 2.5.1 → 2.5.2

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.
@@ -47,8 +47,15 @@ var Amount = function Amount(_ref) {
47
47
  var handleOnBlur = function handleOnBlur(e) {
48
48
  var onChange = rest.onChange;
49
49
 
50
- if (typeof value === 'string' && value.endsWith('.')) {
51
- e.target.value = value.replace('.', '');
50
+ if (typeof value === 'string') {
51
+ if (value.endsWith('.')) {
52
+ e.target.value = value.replace('.', '');
53
+ }
54
+
55
+ if (value.endsWith('0') && value.includes('.')) {
56
+ e.target.value = value.replace(/[0]+$/, '');
57
+ }
58
+
52
59
  onChange && onChange(e);
53
60
  }
54
61
  };
@@ -75,7 +82,11 @@ Amount.formItemPropsHandler = function (_ref2) {
75
82
  getValueFromEvent: function getValueFromEvent(e) {
76
83
  var value = e.target.value;
77
84
  var str = value.replaceAll(seperator, '').replaceAll(/[^0-9\.]/g, '');
78
- if (value.endsWith('.')) return str;
85
+
86
+ if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
87
+ return str;
88
+ }
89
+
79
90
  return str ? parseFloat(str) : undefined;
80
91
  },
81
92
  rules: [{
@@ -17,8 +17,15 @@ var IglooInputNumber = function IglooInputNumber(props) {
17
17
  var value = props.value,
18
18
  onChange = props.onChange;
19
19
 
20
- if (typeof value === 'string' && value.endsWith('.')) {
21
- e.target.value = value.replace('.', '');
20
+ if (typeof value === 'string') {
21
+ if (value.endsWith('.')) {
22
+ e.target.value = value.replace('.', '');
23
+ }
24
+
25
+ if (value.endsWith('0') && value.includes('.')) {
26
+ e.target.value = value.replace(/[0]+$/, '');
27
+ }
28
+
22
29
  onChange && onChange(e);
23
30
  }
24
31
  };
@@ -36,7 +43,11 @@ IglooInputNumber.formItemPropsHandler = function (config) {
36
43
  getValueFromEvent: function getValueFromEvent(e) {
37
44
  var value = e.target.value;
38
45
  var str = value.replaceAll(/[^0-9\.]/g, '');
39
- if (value.endsWith('.')) return parseInt(str);
46
+
47
+ if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
48
+ return str;
49
+ }
50
+
40
51
  return str ? parseFloat(str) : undefined;
41
52
  }
42
53
  };
@@ -1,7 +1,7 @@
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"],
4
- _excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children", "clearWhenOptionsUpdated"];
3
+ var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options", "clearWhenOptionsUpdated"],
4
+ _excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children"];
5
5
 
6
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
7
 
@@ -56,6 +56,25 @@ var Option = _Select.Option,
56
56
  OptGroup = _Select.OptGroup;
57
57
  export { Option, OptGroup };
58
58
 
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
+
59
78
  var IglooSelect = function IglooSelect(_ref) {
60
79
  var valueProp = _ref.value,
61
80
  className = _ref.className,
@@ -68,6 +87,8 @@ var IglooSelect = function IglooSelect(_ref) {
68
87
  multiple = _ref.multiple,
69
88
  _ref$options = _ref.options,
70
89
  options = _ref$options === void 0 ? [] : _ref$options,
90
+ _ref$clearWhenOptions = _ref.clearWhenOptionsUpdated,
91
+ clearWhenOptionsUpdated = _ref$clearWhenOptions === void 0 ? false : _ref$clearWhenOptions,
71
92
  rest = _objectWithoutProperties(_ref, _excluded);
72
93
 
73
94
  var _useContext = useContext(LocaleContext),
@@ -88,6 +109,11 @@ var IglooSelect = function IglooSelect(_ref) {
88
109
  displayOptions = _useState6[0],
89
110
  setDisplay = _useState6[1];
90
111
 
112
+ var _useState7 = useState(options),
113
+ _useState8 = _slicedToArray(_useState7, 2),
114
+ originOptions = _useState8[0],
115
+ setOrigin = _useState8[1];
116
+
91
117
  useEffect(function () {
92
118
  typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
93
119
  }, [selected]);
@@ -96,22 +122,30 @@ var IglooSelect = function IglooSelect(_ref) {
96
122
  }, [valueProp]);
97
123
  useEffect(function () {
98
124
  setDisplay(options);
125
+ setOrigin(options);
99
126
  }, [options]);
127
+ useEffect(function () {
128
+ var setFieldValue = rest.setFieldValue;
129
+
130
+ if (clearWhenOptionsUpdated && compareOptions(options, originOptions)) {
131
+ typeof setFieldValue === 'function' && setFieldValue();
132
+ }
133
+ }, [options, originOptions]);
100
134
  useEffect(function () {
101
135
  var setFieldValue = rest.setFieldValue;
102
136
  var foundValue = options.find(function (option) {
103
137
  return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
104
138
  });
105
139
 
106
- if (!foundValue) {
140
+ if (!foundValue && valueProp !== undefined) {
107
141
  typeof setFieldValue === 'function' && setFieldValue();
108
142
  }
109
143
  }, [valueProp, options]);
110
144
 
111
- var _useState7 = useState(false),
112
- _useState8 = _slicedToArray(_useState7, 2),
113
- dropVisible = _useState8[0],
114
- setDropVisible = _useState8[1];
145
+ var _useState9 = useState(false),
146
+ _useState10 = _slicedToArray(_useState9, 2),
147
+ dropVisible = _useState10[0],
148
+ setDropVisible = _useState10[1];
115
149
 
116
150
  var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
117
151
  typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
@@ -309,14 +343,12 @@ var AttachedSelect = function AttachedSelect(_ref11) {
309
343
  datasourceKey = _ref11.datasourceKey,
310
344
  dependField = _ref11.dependField,
311
345
  children = _ref11.children,
312
- _ref11$clearWhenOptio = _ref11.clearWhenOptionsUpdated,
313
- clearWhenOptionsUpdated = _ref11$clearWhenOptio === void 0 ? false : _ref11$clearWhenOptio,
314
346
  rest = _objectWithoutProperties(_ref11, _excluded2);
315
347
 
316
- var _useState9 = useState(options || []),
317
- _useState10 = _slicedToArray(_useState9, 2),
318
- _options = _useState10[0],
319
- setOptions = _useState10[1];
348
+ var _useState11 = useState(),
349
+ _useState12 = _slicedToArray(_useState11, 2),
350
+ _options = _useState12[0],
351
+ setOptions = _useState12[1];
320
352
 
321
353
  var _useContext2 = useContext(FormContext),
322
354
  selectDatasourceApi = _useContext2.selectDatasourceApi;
@@ -434,36 +466,15 @@ var AttachedSelect = function AttachedSelect(_ref11) {
434
466
  };
435
467
  }();
436
468
 
437
- var compareOptions = function compareOptions(newOptions) {
438
- var updateOptions = _options.length !== newOptions.length;
439
-
440
- if (!updateOptions) {
441
- for (var i = 0; i < _options.length; i++) {
442
- var newOption = _options[i];
443
- var originOption = newOptions[i];
444
-
445
- if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
446
- updateOptions = true;
447
- break;
448
- }
449
- }
450
- }
451
-
452
- if (updateOptions) {
469
+ calcOptions().then(function (newOptions) {
470
+ if (compareOptions(newOptions, _options || [])) {
453
471
  setOptions(newOptions);
454
- var setFieldValue = rest.setFieldValue;
455
-
456
- if (clearWhenOptionsUpdated) {
457
- typeof setFieldValue === 'function' && setFieldValue();
458
- }
459
472
  }
460
- };
461
-
462
- calcOptions().then(compareOptions);
463
- }, [options, optionGroups, dependFieldValue, optionsFromGetOptions]);
464
- return _jsx(IglooSelect, _objectSpread({
473
+ });
474
+ }, [options, optionGroups, dependFieldValue, optionsFromGetOptions, _options]);
475
+ return _options ? _jsx(IglooSelect, _objectSpread({
465
476
  options: _options
466
- }, rest));
477
+ }, rest)) : null;
467
478
  };
468
479
 
469
480
  AttachedSelect.formItemPropsHandler = function (config) {
@@ -63,8 +63,15 @@ var Amount = function Amount(_ref) {
63
63
  var handleOnBlur = function handleOnBlur(e) {
64
64
  var onChange = rest.onChange;
65
65
 
66
- if (typeof value === 'string' && value.endsWith('.')) {
67
- e.target.value = value.replace('.', '');
66
+ if (typeof value === 'string') {
67
+ if (value.endsWith('.')) {
68
+ e.target.value = value.replace('.', '');
69
+ }
70
+
71
+ if (value.endsWith('0') && value.includes('.')) {
72
+ e.target.value = value.replace(/[0]+$/, '');
73
+ }
74
+
68
75
  onChange && onChange(e);
69
76
  }
70
77
  };
@@ -91,7 +98,11 @@ Amount.formItemPropsHandler = function (_ref2) {
91
98
  getValueFromEvent: function getValueFromEvent(e) {
92
99
  var value = e.target.value;
93
100
  var str = value.replaceAll(seperator, '').replaceAll(/[^0-9\.]/g, '');
94
- if (value.endsWith('.')) return str;
101
+
102
+ if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
103
+ return str;
104
+ }
105
+
95
106
  return str ? parseFloat(str) : undefined;
96
107
  },
97
108
  rules: [{
@@ -30,8 +30,15 @@ var IglooInputNumber = function IglooInputNumber(props) {
30
30
  var value = props.value,
31
31
  onChange = props.onChange;
32
32
 
33
- if (typeof value === 'string' && value.endsWith('.')) {
34
- e.target.value = value.replace('.', '');
33
+ if (typeof value === 'string') {
34
+ if (value.endsWith('.')) {
35
+ e.target.value = value.replace('.', '');
36
+ }
37
+
38
+ if (value.endsWith('0') && value.includes('.')) {
39
+ e.target.value = value.replace(/[0]+$/, '');
40
+ }
41
+
35
42
  onChange && onChange(e);
36
43
  }
37
44
  };
@@ -49,7 +56,11 @@ IglooInputNumber.formItemPropsHandler = function (config) {
49
56
  getValueFromEvent: function getValueFromEvent(e) {
50
57
  var value = e.target.value;
51
58
  var str = value.replaceAll(/[^0-9\.]/g, '');
52
- if (value.endsWith('.')) return parseInt(str);
59
+
60
+ if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
61
+ return str;
62
+ }
63
+
53
64
  return str ? parseFloat(str) : undefined;
54
65
  }
55
66
  };
@@ -35,8 +35,8 @@ require("./style");
35
35
 
36
36
  var _invariant = _interopRequireDefault(require("invariant"));
37
37
 
38
- var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options"],
39
- _excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children", "clearWhenOptionsUpdated"];
38
+ var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options", "clearWhenOptionsUpdated"],
39
+ _excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children"];
40
40
 
41
41
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
42
42
 
@@ -81,6 +81,25 @@ var Option = _select.default.Option,
81
81
  exports.OptGroup = OptGroup;
82
82
  exports.Option = Option;
83
83
 
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
+
84
103
  var IglooSelect = function IglooSelect(_ref) {
85
104
  var valueProp = _ref.value,
86
105
  className = _ref.className,
@@ -93,6 +112,8 @@ var IglooSelect = function IglooSelect(_ref) {
93
112
  multiple = _ref.multiple,
94
113
  _ref$options = _ref.options,
95
114
  options = _ref$options === void 0 ? [] : _ref$options,
115
+ _ref$clearWhenOptions = _ref.clearWhenOptionsUpdated,
116
+ clearWhenOptionsUpdated = _ref$clearWhenOptions === void 0 ? false : _ref$clearWhenOptions,
96
117
  rest = _objectWithoutProperties(_ref, _excluded);
97
118
 
98
119
  var _useContext = (0, _react.useContext)(_localeContext.default),
@@ -113,6 +134,11 @@ var IglooSelect = function IglooSelect(_ref) {
113
134
  displayOptions = _useState6[0],
114
135
  setDisplay = _useState6[1];
115
136
 
137
+ var _useState7 = (0, _react.useState)(options),
138
+ _useState8 = _slicedToArray(_useState7, 2),
139
+ originOptions = _useState8[0],
140
+ setOrigin = _useState8[1];
141
+
116
142
  (0, _react.useEffect)(function () {
117
143
  typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
118
144
  }, [selected]);
@@ -121,22 +147,30 @@ var IglooSelect = function IglooSelect(_ref) {
121
147
  }, [valueProp]);
122
148
  (0, _react.useEffect)(function () {
123
149
  setDisplay(options);
150
+ setOrigin(options);
124
151
  }, [options]);
152
+ (0, _react.useEffect)(function () {
153
+ var setFieldValue = rest.setFieldValue;
154
+
155
+ if (clearWhenOptionsUpdated && compareOptions(options, originOptions)) {
156
+ typeof setFieldValue === 'function' && setFieldValue();
157
+ }
158
+ }, [options, originOptions]);
125
159
  (0, _react.useEffect)(function () {
126
160
  var setFieldValue = rest.setFieldValue;
127
161
  var foundValue = options.find(function (option) {
128
162
  return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
129
163
  });
130
164
 
131
- if (!foundValue) {
165
+ if (!foundValue && valueProp !== undefined) {
132
166
  typeof setFieldValue === 'function' && setFieldValue();
133
167
  }
134
168
  }, [valueProp, options]);
135
169
 
136
- var _useState7 = (0, _react.useState)(false),
137
- _useState8 = _slicedToArray(_useState7, 2),
138
- dropVisible = _useState8[0],
139
- setDropVisible = _useState8[1];
170
+ var _useState9 = (0, _react.useState)(false),
171
+ _useState10 = _slicedToArray(_useState9, 2),
172
+ dropVisible = _useState10[0],
173
+ setDropVisible = _useState10[1];
140
174
 
141
175
  var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
142
176
  typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
@@ -334,14 +368,12 @@ var AttachedSelect = function AttachedSelect(_ref11) {
334
368
  datasourceKey = _ref11.datasourceKey,
335
369
  dependField = _ref11.dependField,
336
370
  children = _ref11.children,
337
- _ref11$clearWhenOptio = _ref11.clearWhenOptionsUpdated,
338
- clearWhenOptionsUpdated = _ref11$clearWhenOptio === void 0 ? false : _ref11$clearWhenOptio,
339
371
  rest = _objectWithoutProperties(_ref11, _excluded2);
340
372
 
341
- var _useState9 = (0, _react.useState)(options || []),
342
- _useState10 = _slicedToArray(_useState9, 2),
343
- _options = _useState10[0],
344
- setOptions = _useState10[1];
373
+ var _useState11 = (0, _react.useState)(),
374
+ _useState12 = _slicedToArray(_useState11, 2),
375
+ _options = _useState12[0],
376
+ setOptions = _useState12[1];
345
377
 
346
378
  var _useContext2 = (0, _react.useContext)(_formContext.default),
347
379
  selectDatasourceApi = _useContext2.selectDatasourceApi;
@@ -459,36 +491,15 @@ var AttachedSelect = function AttachedSelect(_ref11) {
459
491
  };
460
492
  }();
461
493
 
462
- var compareOptions = function compareOptions(newOptions) {
463
- var updateOptions = _options.length !== newOptions.length;
464
-
465
- if (!updateOptions) {
466
- for (var i = 0; i < _options.length; i++) {
467
- var newOption = _options[i];
468
- var originOption = newOptions[i];
469
-
470
- if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
471
- updateOptions = true;
472
- break;
473
- }
474
- }
475
- }
476
-
477
- if (updateOptions) {
494
+ calcOptions().then(function (newOptions) {
495
+ if (compareOptions(newOptions, _options || [])) {
478
496
  setOptions(newOptions);
479
- var setFieldValue = rest.setFieldValue;
480
-
481
- if (clearWhenOptionsUpdated) {
482
- typeof setFieldValue === 'function' && setFieldValue();
483
- }
484
497
  }
485
- };
486
-
487
- calcOptions().then(compareOptions);
488
- }, [options, optionGroups, dependFieldValue, optionsFromGetOptions]);
489
- return (0, _jsxRuntime.jsx)(IglooSelect, _objectSpread({
498
+ });
499
+ }, [options, optionGroups, dependFieldValue, optionsFromGetOptions, _options]);
500
+ return _options ? (0, _jsxRuntime.jsx)(IglooSelect, _objectSpread({
490
501
  options: _options
491
- }, rest));
502
+ }, rest)) : null;
492
503
  };
493
504
 
494
505
  AttachedSelect.formItemPropsHandler = function (config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",