linear-react-components-ui 1.1.22-beta.11 → 1.1.22-beta.13

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.
@@ -0,0 +1,13 @@
1
+ type UseSecurityParams = {
2
+ showSecurity: boolean;
3
+ title?: string;
4
+ message?: string;
5
+ onClose: () => void;
6
+ };
7
+ type UseSecurityReturn = {
8
+ handleClose: () => void;
9
+ SecurityComponent: () => JSX.Element | null;
10
+ };
11
+ declare function useSecurity({ showSecurity, title, message, onClose, }: UseSecurityParams): UseSecurityReturn;
12
+
13
+ export { useSecurity };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSecurity = useSecurity;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _dialog = require("../../dialog");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ function useSecurity(_ref) {
12
+ let {
13
+ showSecurity = false,
14
+ title = 'Dados Alterados',
15
+ message = 'Você possui dados alterados, confirma o fechamento?',
16
+ onClose
17
+ } = _ref;
18
+ const [showDialogAlert, setShowDialogAlert] = (0, _react.useState)(false);
19
+ const handleClose = () => {
20
+ if (showSecurity) {
21
+ setShowDialogAlert(true);
22
+ return;
23
+ }
24
+ onClose();
25
+ };
26
+ const onConfirmClick = () => {
27
+ setShowDialogAlert(false);
28
+ onClose();
29
+ };
30
+ const onUnconfirmClick = () => {
31
+ setShowDialogAlert(false);
32
+ };
33
+ const onBeforeUnload = ev => {
34
+ ev.preventDefault();
35
+ };
36
+ const DialogComponent = () => /*#__PURE__*/_react.default.createElement(_dialog.DialogQuestion, {
37
+ zIndex: "99999999",
38
+ title: title,
39
+ text: message,
40
+ visible: showDialogAlert,
41
+ onConfirmClick: onConfirmClick,
42
+ onUnconfirmClick: onUnconfirmClick
43
+ });
44
+ (0, _react.useEffect)(() => {
45
+ if (showSecurity) {
46
+ window.addEventListener('beforeunload', onBeforeUnload);
47
+ }
48
+ return () => {
49
+ window.removeEventListener('beforeunload', onBeforeUnload);
50
+ };
51
+ }, [showSecurity]);
52
+ return {
53
+ handleClose,
54
+ SecurityComponent: DialogComponent
55
+ };
56
+ }
@@ -34,7 +34,7 @@ const returnEventFormattedValue = (props, event) => {
34
34
  const value = props.defaultValue || '';
35
35
  return _objectSpread(_objectSpread({}, event), {}, {
36
36
  target: {
37
- value: (0, _format_number.numberToEnUS)(value),
37
+ value: String((0, _format_number.numberToEnUS)(value)),
38
38
  name
39
39
  }
40
40
  });
@@ -151,10 +151,13 @@ const BaseMask = _ref => {
151
151
  }
152
152
  });
153
153
  (0, _react.useEffect)(() => {
154
- if (typeof valueProp === 'number') {
155
- if (String(valueProp).trim().length > 0) setTypedValue(valueProp);else setTypedValue(0);
154
+ if (mask === Number) {
155
+ const typedValue = (0, _format_number.numberToEnUS)(String(valueProp));
156
+ if (!Number.isNaN(typedValue)) setTypedValue(typedValue);
157
+ return;
156
158
  }
157
- setValue((0, _format_number.numberToPtBR)(valueProp) ?? '');
159
+ const updatedValue = valueProp ? String(valueProp) : '';
160
+ setValue(updatedValue);
158
161
  }, [valueProp]);
159
162
  return /*#__PURE__*/_react.default.createElement(_InputTextBase.default, _extends({
160
163
  inputRef: r => {
@@ -30,7 +30,7 @@ const getMaskOptions = _ref => {
30
30
  pattern = '',
31
31
  radix = ' ',
32
32
  thousandsSeparator = '',
33
- mapToRadix = [],
33
+ mapToRadix = ['.'],
34
34
  scale = 2,
35
35
  normalizeZeros = true,
36
36
  padFractionalZeros = true,
@@ -29,7 +29,7 @@ const returnEventFormattedValue = (props, event) => {
29
29
  } = event.target;
30
30
  return _objectSpread(_objectSpread({}, event), {}, {
31
31
  target: {
32
- value: (0, _format_number.numberToEnUS)(value),
32
+ value: String((0, _format_number.numberToEnUS)(value)),
33
33
  name
34
34
  }
35
35
  });
@@ -67,10 +67,11 @@ const BaseNumber = _ref => {
67
67
  returnFormattedValueOnKeyDown: true
68
68
  });
69
69
  return /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({
70
- value: (0, _format_number.numberToPtBR)(value ?? 0),
70
+ mask: Number,
71
+ value: value ?? 0,
71
72
  thousandsSeparator: ".",
72
73
  radix: ",",
73
- mask: Number,
74
+ mapToRadix: ['.'],
74
75
  isNumeric: true
75
76
  }, props, getEventProps(eventProps)));
76
77
  };
@@ -1,5 +1,5 @@
1
1
  declare const numberToPtBR: (value?: string | number) => string | undefined;
2
- declare const numberToEnUS: (value: string) => string | number;
2
+ declare const numberToEnUS: (value: string) => number;
3
3
  declare const formatOnlyNumbers: (value: string) => string;
4
4
 
5
5
  export { formatOnlyNumbers, numberToEnUS, numberToPtBR };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.numberToPtBR = exports.numberToEnUS = exports.formatOnlyNumbers = void 0;
7
+ const ptBRRegex = /\b\d{1,3}(?:\.\d{3})*,\d+\b/;
7
8
  const numberToPtBR = value => {
8
9
  if (value !== undefined && typeof value === 'number') {
9
10
  return value.toLocaleString('pt-BR');
@@ -13,11 +14,12 @@ const numberToPtBR = value => {
13
14
  exports.numberToPtBR = numberToPtBR;
14
15
  const numberToEnUS = value => {
15
16
  let formattedNumber;
16
- if (value) {
17
+ const isPTBR = ptBRRegex.test(value);
18
+ if (isPTBR) {
17
19
  formattedNumber = value.replaceAll('.', '').replaceAll(',', '.');
18
20
  return Number(formattedNumber);
19
21
  }
20
- return value;
22
+ return Number(value);
21
23
  };
22
24
  exports.numberToEnUS = numberToEnUS;
23
25
  const formatOnlyNumbers = value => {
@@ -12,7 +12,7 @@ import '../../@types/Icon.js';
12
12
  import '../../icons/helper.js';
13
13
 
14
14
  interface INumberFieldProps extends IMaskHOCProps {
15
- value?: string;
15
+ value?: string | number;
16
16
  permissionAttr?: PermissionAttr;
17
17
  disabled?: boolean;
18
18
  hint?: string | string[];
@@ -141,9 +141,6 @@ const SimpleSelect = props => {
141
141
  if (props.onBlur) {
142
142
  const event = getSelectEvent(selected);
143
143
  props.onBlur(event);
144
- if (selected && opened) {
145
- onSelect(selected);
146
- }
147
144
  if (selected && descriptionKeyIsString && inputText !== selected[descriptionKey] || !descriptionKeyIsString && inputText !== descriptionKey(selected)) {
148
145
  setSelected(null);
149
146
  setInputText(inputText);
@@ -223,6 +220,9 @@ const SimpleSelect = props => {
223
220
  setSelected(newCurrent);
224
221
  if (descriptionKeyIsString) setInputText(newCurrent ? newCurrent[descriptionKey] : '');else setInputText(newCurrent ? descriptionKey(newCurrent) : '');
225
222
  }
223
+ if (dataSourceWithAllOptions.length === 0 && inputText) {
224
+ setInputText('');
225
+ }
226
226
  }, [dataSourceWithAllOptions.length, value]);
227
227
  (0, _react.useEffect)(() => {
228
228
  if (!_lodash.default.isEqual(dataCombo, dataSourceWithAllOptions)) {
@@ -50,7 +50,7 @@ interface IInputHOCProps {
50
50
  }
51
51
  interface IMaskHOCProps {
52
52
  label?: string;
53
- value?: string;
53
+ value?: string | number;
54
54
  unmask?: boolean;
55
55
  name?: string;
56
56
  commit?: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "1.1.22-beta.11",
3
+ "version": "1.1.22-beta.13",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.cjs",
@@ -8,7 +8,7 @@
8
8
  "lib"
9
9
  ],
10
10
  "scripts": {
11
- "lib": "babel src/lib/ -d lib/ --extensions \".js,.jsx,.ts,.tsx\" --ignore **/*.spec.tsx && babel src/lib/assets -d lib/assets --copy-files && npm run lib:types",
11
+ "lib": "rm -rf lib && babel src/lib/ -d lib/ --extensions \".js,.jsx,.ts,.tsx\" --ignore **/*.spec.tsx && babel src/lib/assets -d lib/assets --copy-files && npm run lib:types",
12
12
  "lib:types": "tsup --dts-only --dts --external react",
13
13
  "demo": "node scripts/start.js",
14
14
  "demo:prod": "webpack --config ./config/webpack.config.js --mode production",