awing-library 2.1.2-dev.543 → 2.1.2-dev.544

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,7 @@ import { fireEvent, render, screen } from "@testing-library/react";
6
6
  import { Constants } from "../../Commons/Constant.js";
7
7
  import container from "./container.js";
8
8
  var __webpack_modules__ = {
9
- "../DataInput": function(module) {
9
+ "AWING/DataInput": function(module) {
10
10
  module.exports = __WEBPACK_EXTERNAL_MODULE__DataInput_index_js_c7933a4f__;
11
11
  },
12
12
  "../helper": function(module) {
@@ -23,7 +23,7 @@ function __webpack_require__(moduleId) {
23
23
  __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
24
24
  return module.exports;
25
25
  }
26
- var index_js_ = __webpack_require__("../DataInput");
26
+ var index_js_ = __webpack_require__("AWING/DataInput");
27
27
  jest.mock('../DataInput', ()=>({
28
28
  __esModule: true,
29
29
  default: jest.fn(),
@@ -91,7 +91,7 @@ jest.mock('@mui/material', ()=>({
91
91
  children: children
92
92
  })
93
93
  }));
94
- const mockInputFactory = __webpack_require__("../DataInput")["default"];
94
+ const mockInputFactory = __webpack_require__("AWING/DataInput")["default"];
95
95
  const mockCalculateValue = __webpack_require__("../helper").calculateValue;
96
96
  const mockConvertFormulaToBinaryTree = __webpack_require__("../helper").convertFormulaToBinaryTree;
97
97
  const mockReplaceFieldsValue = __webpack_require__("../helper").replaceFieldsValue;
@@ -5,7 +5,7 @@ import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"
5
5
  import containerOptimized from "./containerOptimized.js";
6
6
  import { createFormStateManager } from "./formStateManager.js";
7
7
  var __webpack_modules__ = {
8
- "../DataInput": function(module) {
8
+ "AWING/DataInput": function(module) {
9
9
  module.exports = __WEBPACK_EXTERNAL_MODULE__DataInput_index_js_c7933a4f__;
10
10
  }
11
11
  };
@@ -98,7 +98,7 @@ jest.mock('@mui/material', ()=>({
98
98
  children: children
99
99
  })
100
100
  }));
101
- const mockInputFactory = __webpack_require__("../DataInput")["default"];
101
+ const mockInputFactory = __webpack_require__("AWING/DataInput")["default"];
102
102
  describe('DataForm Optimized - Performance Tests', ()=>{
103
103
  let inputRenderCounts = {};
104
104
  const mockFields = [
@@ -1 +1 @@
1
- {"version":3,"file":"NumberInput.d.ts","sourceRoot":"","sources":["../../../../src/AWING/DataInput/components/NumberInput.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IACtE,IAAI,EAAE,UAAU,CAAC,MAAM,GAAG,QAAQ,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,UAOpE;AAED,eAAO,MAAM,WAAW,oBAAqB,qBAAqB,4CAmEjE,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"NumberInput.d.ts","sourceRoot":"","sources":["../../../../src/AWING/DataInput/components/NumberInput.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IACtE,IAAI,EAAE,UAAU,CAAC,MAAM,GAAG,QAAQ,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,UAOpE;AAED,eAAO,MAAM,WAAW,oBAAqB,qBAAqB,4CAmFjE,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
3
3
  import i18n from "../../../translate/i18n.js";
4
4
  import NumberFormat from "../../NumberFormat/index.js";
5
5
  import { numberNotNullValid } from "../../ultis/index.js";
6
- import { useEffect, useState } from "react";
6
+ import { useEffect, useRef, useState } from "react";
7
7
  function clampNumber(value, min, max) {
8
8
  let result = value;
9
9
  if (void 0 !== min) result = Math.max(result, min);
@@ -16,8 +16,9 @@ const NumberInput = (fieldDefinition)=>{
16
16
  });
17
17
  const { name, defaultValue, value, onChange, error, disableHelperText, helperText, min, max, onValidateCustom, ...other } = fieldDefinition;
18
18
  const [valueInput, setValueInput] = useState(defaultValue || value || '');
19
+ const isComposing = useRef(false);
19
20
  useEffect(()=>{
20
- if (valueInput !== value) setValueInput(value ?? '');
21
+ if (!isComposing.current && valueInput !== value) setValueInput(value ?? '');
21
22
  }, [
22
23
  value
23
24
  ]);
@@ -25,16 +26,18 @@ const NumberInput = (fieldDefinition)=>{
25
26
  if (onValidateCustom) return onValidateCustom(Number(val));
26
27
  return (void 0 === min || Number(val) >= min) && (void 0 === max || Number(val) <= max) && numberNotNullValid(Number(val));
27
28
  };
28
- const handleChange = (event)=>{
29
- const newValue = event.target.value;
29
+ const processChange = (newValue)=>{
30
30
  if ('-' === newValue || '' === newValue) return void ('-' === newValue && void 0 !== min && min >= 0 ? setValueInput(0) : setValueInput(newValue));
31
31
  const numberValue = Number(newValue);
32
32
  if (!isNaN(numberValue)) {
33
33
  const currentValue = clampNumber(numberValue, min, max);
34
34
  setValueInput(currentValue);
35
- onChange && onChange(currentValue, onValidate(currentValue), numberValue);
35
+ if (!isComposing.current) onChange && onChange(currentValue, onValidate(currentValue), numberValue);
36
36
  }
37
37
  };
38
+ const handleChange = (event)=>{
39
+ processChange(event.target.value);
40
+ };
38
41
  return /*#__PURE__*/ jsx(NumberFormat, {
39
42
  id: name?.toString(),
40
43
  name: name?.toString(),
@@ -42,6 +45,13 @@ const NumberInput = (fieldDefinition)=>{
42
45
  variant: "standard",
43
46
  value: valueInput,
44
47
  onChange: handleChange,
48
+ onCompositionStart: ()=>{
49
+ isComposing.current = true;
50
+ },
51
+ onCompositionEnd: (event)=>{
52
+ isComposing.current = false;
53
+ processChange(event.target.value);
54
+ },
45
55
  error: error,
46
56
  helperText: !disableHelperText && error ? helperText ?? t('Common.InvalidData') : '',
47
57
  ...other
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../src/AWING/DataInput/components/TextInput.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IAEpE,IAAI,EACE,UAAU,CAAC,IAAI,GACf,UAAU,CAAC,KAAK,GAChB,UAAU,CAAC,GAAG,GACd,UAAU,CAAC,SAAS,GACpB,UAAU,CAAC,GAAG,GACd,UAAU,CAAC,QAAQ,GACnB,MAAM,GACN,OAAO,GACP,KAAK,GACL,WAAW,GACX,KAAK,GACL,UAAU,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,SAAS,oBAAqB,mBAAmB,4CAyD7D,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../src/AWING/DataInput/components/TextInput.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB,CAAC,MAAM,CAAC;IAEpE,IAAI,EACE,UAAU,CAAC,IAAI,GACf,UAAU,CAAC,KAAK,GAChB,UAAU,CAAC,GAAG,GACd,UAAU,CAAC,SAAS,GACpB,UAAU,CAAC,GAAG,GACd,UAAU,CAAC,QAAQ,GACnB,MAAM,GACN,OAAO,GACP,KAAK,GACL,WAAW,GACX,KAAK,GACL,UAAU,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,SAAS,oBAAqB,mBAAmB,4CA6F7D,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { useEffect, useRef, useState } from "react";
3
3
  import { useTranslation } from "react-i18next";
4
4
  import { TextField } from "@mui/material";
5
5
  import i18n from "../../../translate/i18n.js";
@@ -11,6 +11,14 @@ const TextInput_TextInput = (fieldDefinition)=>{
11
11
  });
12
12
  const { name, value, onChange, error, disableHelperText, helperText, type, length, pattern, onValidateCustom, fieldName, ...other } = fieldDefinition;
13
13
  const [errorText, setErrorText] = useState(t('Common.InvalidData'));
14
+ const [localValue, setLocalValue] = useState(value ?? '');
15
+ const isComposing = useRef(false);
16
+ const isFocused = useRef(false);
17
+ useEffect(()=>{
18
+ if (!isComposing.current && !isFocused.current && value !== localValue) setLocalValue(value ?? '');
19
+ }, [
20
+ value
21
+ ]);
14
22
  const onValidate = (val)=>{
15
23
  if (onValidateCustom) return onValidateCustom(val ?? '');
16
24
  if (type === FIELD_TYPE.EMAIL) return emailValid(val ?? '');
@@ -24,6 +32,10 @@ const TextInput_TextInput = (fieldDefinition)=>{
24
32
  return valid;
25
33
  }
26
34
  };
35
+ const handleTextChange = (newValue)=>{
36
+ setLocalValue(newValue);
37
+ if (!isComposing.current) onChange && onChange(newValue, onValidate(newValue));
38
+ };
27
39
  return /*#__PURE__*/ jsx(TextField, {
28
40
  id: name?.toString(),
29
41
  name: name?.toString(),
@@ -33,8 +45,24 @@ const TextInput_TextInput = (fieldDefinition)=>{
33
45
  multiline: type === FIELD_TYPE.TEXT_AREA,
34
46
  error: error,
35
47
  helperText: !disableHelperText && (error ? helperText ?? errorText : helperText),
36
- value: value ?? '',
37
- onChange: (event)=>onChange && onChange(event.target.value, onValidate(event.target.value)),
48
+ value: localValue,
49
+ onChange: (event)=>handleTextChange(event.target.value),
50
+ onFocus: ()=>{
51
+ isFocused.current = true;
52
+ },
53
+ onBlur: (event)=>{
54
+ isFocused.current = false;
55
+ const finalValue = event.target.value;
56
+ onChange && onChange(finalValue, onValidate(finalValue));
57
+ },
58
+ onCompositionStart: ()=>{
59
+ isComposing.current = true;
60
+ },
61
+ onCompositionEnd: (event)=>{
62
+ isComposing.current = false;
63
+ const finalValue = event.target.value;
64
+ handleTextChange(finalValue);
65
+ },
38
66
  disabled: fieldDefinition.readOnly,
39
67
  ...other
40
68
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.2-dev.543",
3
+ "version": "2.1.2-dev.544",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {