iglooform 2.5.12 → 2.5.15

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.
@@ -6,7 +6,9 @@ export interface AmountProps extends InputProps, IglooComponentProps {
6
6
  currencyProps?: InputProps;
7
7
  amount?: number;
8
8
  amountProps?: InputProps;
9
- seperator?: ',';
9
+ seperator?: ',' | '.';
10
+ separator?: ',' | '.';
11
+ decimalSeparator?: ',' | '.';
10
12
  }
11
13
  declare const Amount: FC<AmountProps>;
12
14
  export default Amount;
@@ -1,6 +1,6 @@
1
1
  import "antd/es/input/style";
2
2
  import _Input from "antd/es/input";
3
- var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "disabled"];
3
+ var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "separator", "decimalSeparator", "disabled"];
4
4
 
5
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; }
6
6
 
@@ -19,16 +19,16 @@ import classnames from 'classnames';
19
19
  import { staticFormatMessage } from '../locale';
20
20
  import './style/index.less';
21
21
 
22
- var thousands = function thousands(number) {
22
+ var thousands = function thousands(number, decimalSeparator, separator) {
23
23
  if (number === null || number === undefined) return undefined;
24
- var arr = String(number).split('.');
24
+ var arr = String(number).replace('.', decimalSeparator).split(decimalSeparator);
25
25
  return arr.map(function (s, index) {
26
26
  if (index === 0) {
27
- return s.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
27
+ return s.replace(/(?=(?!\b)(\d{3})+$)/g, separator);
28
28
  }
29
29
 
30
- return s.replace(/(\d{3})(?=[^$])/g, '$1,');
31
- }).join('.');
30
+ return s.replace(/(\d{3})(?=[^$])/g, "$1".concat(separator));
31
+ }).join(decimalSeparator);
32
32
  };
33
33
 
34
34
  var Amount = function Amount(_ref) {
@@ -39,8 +39,11 @@ var Amount = function Amount(_ref) {
39
39
  _ref$amountProps = _ref.amountProps,
40
40
  amountProps = _ref$amountProps === void 0 ? {} : _ref$amountProps,
41
41
  value = _ref.value,
42
- _ref$seperator = _ref.seperator,
43
- seperator = _ref$seperator === void 0 ? ',' : _ref$seperator,
42
+ seperator = _ref.seperator,
43
+ _ref$separator = _ref.separator,
44
+ separator = _ref$separator === void 0 ? seperator || ',' : _ref$separator,
45
+ _ref$decimalSeparator = _ref.decimalSeparator,
46
+ decimalSeparator = _ref$decimalSeparator === void 0 ? '.' : _ref$decimalSeparator,
44
47
  disabled = _ref.disabled,
45
48
  rest = _objectWithoutProperties(_ref, _excluded);
46
49
 
@@ -48,11 +51,11 @@ var Amount = function Amount(_ref) {
48
51
  var onChange = rest.onChange;
49
52
 
50
53
  if (typeof value === 'string') {
51
- if (value.endsWith('.')) {
52
- e.target.value = value.replace('.', '');
54
+ if (value.endsWith(decimalSeparator)) {
55
+ e.target.value = value.replace(decimalSeparator, '');
53
56
  }
54
57
 
55
- if (value.endsWith('0') && value.includes('.')) {
58
+ if (value.endsWith('0') && value.includes(decimalSeparator)) {
56
59
  e.target.value = value.replace(/[0]+$/, '');
57
60
  }
58
61
 
@@ -67,7 +70,7 @@ var Amount = function Amount(_ref) {
67
70
  className: classnames('igloo-input-amount', {
68
71
  'igloo-input-disable': disabled
69
72
  }, className),
70
- value: thousands(value),
73
+ value: thousands(value, decimalSeparator, separator),
71
74
  addonBefore: currency ? _jsx("span", {
72
75
  className: "igloo-input-areacode",
73
76
  children: currency
@@ -76,24 +79,31 @@ var Amount = function Amount(_ref) {
76
79
  };
77
80
 
78
81
  Amount.formItemPropsHandler = function (_ref2) {
79
- var _ref2$seperator = _ref2.seperator,
80
- seperator = _ref2$seperator === void 0 ? ',' : _ref2$seperator;
82
+ var _ref2$separator = _ref2.separator,
83
+ separator = _ref2$separator === void 0 ? ',' : _ref2$separator,
84
+ _ref2$decimalSeparato = _ref2.decimalSeparator,
85
+ decimalSeparator = _ref2$decimalSeparato === void 0 ? '.' : _ref2$decimalSeparato;
81
86
  return {
82
87
  getValueFromEvent: function getValueFromEvent(e) {
83
88
  var value = e.target.value;
84
- var str = value.replaceAll(seperator, '').replaceAll(/[^0-9\.]/g, '');
89
+ console.log('======', separator, decimalSeparator);
90
+ var str = value.replaceAll(separator, '').replaceAll(/[^0-9\.,]/g, '');
85
91
 
86
- if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
92
+ if (str.endsWith(decimalSeparator) || str.includes(decimalSeparator) && str.endsWith('0')) {
87
93
  return str;
88
94
  }
89
95
 
96
+ if (decimalSeparator === ',') {
97
+ str = str.replace(',', '.');
98
+ }
99
+
90
100
  return str ? parseFloat(str) : undefined;
91
101
  },
92
102
  rules: [{
93
103
  validator: function validator(_, value) {
94
104
  if (!value) return Promise.resolve();
95
- var seperatorArr = String(value).split('.');
96
- return seperatorArr.length > 2 ? Promise.reject(staticFormatMessage({
105
+ var separatorArr = String(value).split(decimalSeparator);
106
+ return separatorArr.length > 2 ? Promise.reject(staticFormatMessage({
97
107
  id: 'Please enter a valid amount.'
98
108
  })) : Promise.resolve();
99
109
  }
@@ -43,7 +43,7 @@ import LocaleContext from '../locale/locale-context';
43
43
  import Button from '../button';
44
44
  import Input from '../input';
45
45
  import './style';
46
- import { compareOptions, optionsHOC } from '../utils/option-utils';
46
+ import { compareOptions, compareSelected, optionsHOC } from '../utils/option-utils';
47
47
  var Option = _Select.Option,
48
48
  OptGroup = _Select.OptGroup;
49
49
  export { Option, OptGroup };
@@ -84,7 +84,7 @@ var IglooSelect = function IglooSelect(_ref) {
84
84
 
85
85
  var originOptions = useRef(options);
86
86
  useEffect(function () {
87
- typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
87
+ typeof rest.onChange === 'function' && compareSelected(selected, valueProp) && rest.onChange(selected, selectedOptions);
88
88
  }, [selected]);
89
89
  useEffect(function () {
90
90
  valueProp !== selected && setSelected(valueProp);
@@ -3,6 +3,7 @@ import { FormInstance } from 'antd/es/form';
3
3
  import { NamePath } from 'antd/es/form/interface';
4
4
  import { SelectProps, SelectValue } from 'antd/es/select';
5
5
  export declare const compareOptions: (newOptions: any[], oldOptions?: any[] | undefined) => boolean;
6
+ export declare const compareSelected: (newValue: any | any[], oldValue: any | any[]) => boolean;
6
7
  declare type Options = SelectProps<SelectValue>['options'];
7
8
  export interface HOCProps extends IglooComponentProps {
8
9
  options?: Options;
@@ -14,8 +14,6 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
14
14
 
15
15
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
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
17
  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
18
 
21
19
  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); }); }; }
@@ -36,6 +34,8 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
36
34
 
37
35
  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
36
 
37
+ 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); }
38
+
39
39
  import { jsx as _jsx } from "react/jsx-runtime";
40
40
  import { useEffect, useState, useContext, useRef } from 'react';
41
41
  import FormContext from '../form-context';
@@ -62,6 +62,25 @@ export var compareOptions = function compareOptions(newOptions, oldOptions) {
62
62
 
63
63
  return false;
64
64
  };
65
+ export var compareSelected = function compareSelected(newValue, oldValue) {
66
+ if (_typeof(newValue) !== _typeof(oldValue)) {
67
+ return true;
68
+ }
69
+
70
+ if (Array.isArray(newValue) && Array.isArray(oldValue)) {
71
+ if (newValue.length !== oldValue.length) {
72
+ return true;
73
+ }
74
+
75
+ return !newValue.every(function (v) {
76
+ return oldValue.find(function (ov) {
77
+ return v === ov;
78
+ });
79
+ });
80
+ }
81
+
82
+ return newValue !== oldValue;
83
+ };
65
84
  export function optionsHOC(Component) {
66
85
  return function (props) {
67
86
  var options = props.options,
@@ -6,7 +6,9 @@ export interface AmountProps extends InputProps, IglooComponentProps {
6
6
  currencyProps?: InputProps;
7
7
  amount?: number;
8
8
  amountProps?: InputProps;
9
- seperator?: ',';
9
+ seperator?: ',' | '.';
10
+ separator?: ',' | '.';
11
+ decimalSeparator?: ',' | '.';
10
12
  }
11
13
  declare const Amount: FC<AmountProps>;
12
14
  export default Amount;
@@ -21,7 +21,7 @@ var _locale = require("../locale");
21
21
 
22
22
  require("./style/index.less");
23
23
 
24
- var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "disabled"];
24
+ var _excluded = ["className", "currency", "currencyProps", "amountProps", "value", "seperator", "separator", "decimalSeparator", "disabled"];
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
@@ -35,16 +35,16 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
35
35
 
36
36
  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; }
37
37
 
38
- var thousands = function thousands(number) {
38
+ var thousands = function thousands(number, decimalSeparator, separator) {
39
39
  if (number === null || number === undefined) return undefined;
40
- var arr = String(number).split('.');
40
+ var arr = String(number).replace('.', decimalSeparator).split(decimalSeparator);
41
41
  return arr.map(function (s, index) {
42
42
  if (index === 0) {
43
- return s.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
43
+ return s.replace(/(?=(?!\b)(\d{3})+$)/g, separator);
44
44
  }
45
45
 
46
- return s.replace(/(\d{3})(?=[^$])/g, '$1,');
47
- }).join('.');
46
+ return s.replace(/(\d{3})(?=[^$])/g, "$1".concat(separator));
47
+ }).join(decimalSeparator);
48
48
  };
49
49
 
50
50
  var Amount = function Amount(_ref) {
@@ -55,8 +55,11 @@ var Amount = function Amount(_ref) {
55
55
  _ref$amountProps = _ref.amountProps,
56
56
  amountProps = _ref$amountProps === void 0 ? {} : _ref$amountProps,
57
57
  value = _ref.value,
58
- _ref$seperator = _ref.seperator,
59
- seperator = _ref$seperator === void 0 ? ',' : _ref$seperator,
58
+ seperator = _ref.seperator,
59
+ _ref$separator = _ref.separator,
60
+ separator = _ref$separator === void 0 ? seperator || ',' : _ref$separator,
61
+ _ref$decimalSeparator = _ref.decimalSeparator,
62
+ decimalSeparator = _ref$decimalSeparator === void 0 ? '.' : _ref$decimalSeparator,
60
63
  disabled = _ref.disabled,
61
64
  rest = _objectWithoutProperties(_ref, _excluded);
62
65
 
@@ -64,11 +67,11 @@ var Amount = function Amount(_ref) {
64
67
  var onChange = rest.onChange;
65
68
 
66
69
  if (typeof value === 'string') {
67
- if (value.endsWith('.')) {
68
- e.target.value = value.replace('.', '');
70
+ if (value.endsWith(decimalSeparator)) {
71
+ e.target.value = value.replace(decimalSeparator, '');
69
72
  }
70
73
 
71
- if (value.endsWith('0') && value.includes('.')) {
74
+ if (value.endsWith('0') && value.includes(decimalSeparator)) {
72
75
  e.target.value = value.replace(/[0]+$/, '');
73
76
  }
74
77
 
@@ -83,7 +86,7 @@ var Amount = function Amount(_ref) {
83
86
  className: (0, _classnames.default)('igloo-input-amount', {
84
87
  'igloo-input-disable': disabled
85
88
  }, className),
86
- value: thousands(value),
89
+ value: thousands(value, decimalSeparator, separator),
87
90
  addonBefore: currency ? (0, _jsxRuntime.jsx)("span", {
88
91
  className: "igloo-input-areacode",
89
92
  children: currency
@@ -92,24 +95,31 @@ var Amount = function Amount(_ref) {
92
95
  };
93
96
 
94
97
  Amount.formItemPropsHandler = function (_ref2) {
95
- var _ref2$seperator = _ref2.seperator,
96
- seperator = _ref2$seperator === void 0 ? ',' : _ref2$seperator;
98
+ var _ref2$separator = _ref2.separator,
99
+ separator = _ref2$separator === void 0 ? ',' : _ref2$separator,
100
+ _ref2$decimalSeparato = _ref2.decimalSeparator,
101
+ decimalSeparator = _ref2$decimalSeparato === void 0 ? '.' : _ref2$decimalSeparato;
97
102
  return {
98
103
  getValueFromEvent: function getValueFromEvent(e) {
99
104
  var value = e.target.value;
100
- var str = value.replaceAll(seperator, '').replaceAll(/[^0-9\.]/g, '');
105
+ console.log('======', separator, decimalSeparator);
106
+ var str = value.replaceAll(separator, '').replaceAll(/[^0-9\.,]/g, '');
101
107
 
102
- if (str.endsWith('.') || str.includes('.') && str.endsWith('0')) {
108
+ if (str.endsWith(decimalSeparator) || str.includes(decimalSeparator) && str.endsWith('0')) {
103
109
  return str;
104
110
  }
105
111
 
112
+ if (decimalSeparator === ',') {
113
+ str = str.replace(',', '.');
114
+ }
115
+
106
116
  return str ? parseFloat(str) : undefined;
107
117
  },
108
118
  rules: [{
109
119
  validator: function validator(_, value) {
110
120
  if (!value) return Promise.resolve();
111
- var seperatorArr = String(value).split('.');
112
- return seperatorArr.length > 2 ? Promise.reject((0, _locale.staticFormatMessage)({
121
+ var separatorArr = String(value).split(decimalSeparator);
122
+ return separatorArr.length > 2 ? Promise.reject((0, _locale.staticFormatMessage)({
113
123
  id: 'Please enter a valid amount.'
114
124
  })) : Promise.resolve();
115
125
  }
@@ -108,7 +108,7 @@ var IglooSelect = function IglooSelect(_ref) {
108
108
 
109
109
  var originOptions = (0, _react.useRef)(options);
110
110
  (0, _react.useEffect)(function () {
111
- typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
111
+ typeof rest.onChange === 'function' && (0, _optionUtils.compareSelected)(selected, valueProp) && rest.onChange(selected, selectedOptions);
112
112
  }, [selected]);
113
113
  (0, _react.useEffect)(function () {
114
114
  valueProp !== selected && setSelected(valueProp);
@@ -3,6 +3,7 @@ import { FormInstance } from 'antd/es/form';
3
3
  import { NamePath } from 'antd/es/form/interface';
4
4
  import { SelectProps, SelectValue } from 'antd/es/select';
5
5
  export declare const compareOptions: (newOptions: any[], oldOptions?: any[] | undefined) => boolean;
6
+ export declare const compareSelected: (newValue: any | any[], oldValue: any | any[]) => boolean;
6
7
  declare type Options = SelectProps<SelectValue>['options'];
7
8
  export interface HOCProps extends IglooComponentProps {
8
9
  options?: Options;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.compareOptions = void 0;
6
+ exports.compareSelected = exports.compareOptions = void 0;
7
7
  exports.optionsHOC = optionsHOC;
8
8
 
9
9
  var _jsxRuntime = require("react/jsx-runtime");
@@ -32,8 +32,6 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
32
32
 
33
33
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
34
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
35
  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
36
 
39
37
  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); }); }; }
@@ -54,6 +52,8 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
54
52
 
55
53
  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
54
 
55
+ 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); }
56
+
57
57
  var compareOptions = function compareOptions(newOptions, oldOptions) {
58
58
  if (!Array.isArray(oldOptions)) {
59
59
  return true;
@@ -79,6 +79,28 @@ var compareOptions = function compareOptions(newOptions, oldOptions) {
79
79
 
80
80
  exports.compareOptions = compareOptions;
81
81
 
82
+ var compareSelected = function compareSelected(newValue, oldValue) {
83
+ if (_typeof(newValue) !== _typeof(oldValue)) {
84
+ return true;
85
+ }
86
+
87
+ if (Array.isArray(newValue) && Array.isArray(oldValue)) {
88
+ if (newValue.length !== oldValue.length) {
89
+ return true;
90
+ }
91
+
92
+ return !newValue.every(function (v) {
93
+ return oldValue.find(function (ov) {
94
+ return v === ov;
95
+ });
96
+ });
97
+ }
98
+
99
+ return newValue !== oldValue;
100
+ };
101
+
102
+ exports.compareSelected = compareSelected;
103
+
82
104
  function optionsHOC(Component) {
83
105
  return function (props) {
84
106
  var options = props.options,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "2.5.12",
3
+ "version": "2.5.15",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",