@lowentry/mui 1.2.9 → 1.2.11

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.
@@ -1,101 +1,99 @@
1
1
  import React from 'react';
2
2
  import {LeRed} from '@lowentry/react-redux';
3
- import {LeUtils, FLOAT_LAX, INT_LAX_ANY} from '@lowentry/utils';
3
+ import {FLOAT_LAX, INT_LAX_ANY, STRING} from '@lowentry/utils';
4
4
  import {LeMuiUtils} from '../LeMuiUtils.js';
5
5
  import TextField from './TextField.jsx';
6
6
 
7
7
 
8
- const NumericTextField = LeRed.memo(({decimals, allowZero, allowNegative, value, onChange, onRenderValue, className, inputProps, children, ...props}) =>
8
+ const getProcessedValue = (value, decimals, allowZero, allowNegative) =>
9
9
  {
10
- if(typeof allowZero === 'undefined')
11
- {
12
- allowZero = true;
13
- }
14
- if(typeof allowNegative === 'undefined')
15
- {
16
- allowNegative = true;
17
- }
18
- decimals = INT_LAX_ANY(decimals, 2);
10
+ let text = LeMuiUtils.purgePrependedHiddenChar(STRING(value));
11
+ let val = 0;
19
12
 
13
+ const negative = text.includes('-');
20
14
 
21
- const getVisualValue = (value) =>
15
+ text = text.replace(',', '.').replace(/[^0-9.]/g, '');
16
+ if(text !== '')
22
17
  {
23
- let text = FLOAT_LAX(LeMuiUtils.purgePrependedHiddenChar(value));
24
- if(!allowNegative)
18
+ let stringVal = Math.abs(FLOAT_LAX(text)).toFixed(decimals + 1); // prevents rounding (by adding an extra digit and then cutting it off)
19
+ stringVal = stringVal.substring(0, stringVal.length - 1);
20
+
21
+ const textDotCount = text.split('.').length - 1;
22
+ if((textDotCount <= 0) || (decimals <= 0))
23
+ {
24
+ text = stringVal.split('.')[0];
25
+ }
26
+ else if((textDotCount === 1) && text.endsWith('.'))
25
27
  {
26
- text = Math.abs(text);
28
+ text = stringVal.split('.')[0] + '.';
29
+ }
30
+ else
31
+ {
32
+ text = stringVal.substring(0, stringVal.length - Math.max(0, decimals - text.split('.')[1].length));
27
33
  }
28
34
 
29
- text = text.toFixed(decimals); // rounds it
30
- text = LeUtils.trimEnd(LeUtils.trimEnd(text, '0'), '.');
31
35
  if(!allowZero && (text === '0'))
32
36
  {
33
37
  text = '';
34
38
  }
35
- return text;
36
- };
39
+ }
40
+
41
+ if(allowNegative && negative)
42
+ {
43
+ text = '-' + text;
44
+ }
45
+
46
+ val = FLOAT_LAX(text);
47
+ if(val !== 0)
48
+ {
49
+ if(decimals > 0)
50
+ {
51
+ val = Math.round(val * Math.pow(10, decimals)) / Math.pow(10, decimals);
52
+ }
53
+ else
54
+ {
55
+ val = Math.round(val);
56
+ }
57
+ }
58
+
59
+ return {text, val};
60
+ };
61
+
62
+
63
+ const NumericTextField = LeRed.memo(({decimals, allowZero, allowNegative, value, onChange, onRenderValue, className, inputProps, children, ...props}) =>
64
+ {
65
+ allowZero = !!allowZero;
66
+ allowNegative = !!allowNegative;
67
+ decimals = INT_LAX_ANY(decimals, 0);
68
+
69
+
70
+ const getVisualValue = LeRed.useCallback((value) =>
71
+ {
72
+ return getProcessedValue(value, decimals, allowZero, allowNegative).text;
73
+ }, [decimals, allowZero, allowNegative]);
37
74
 
38
75
 
39
76
  const [visualValue, setVisualValue] = LeRed.useState(getVisualValue(value));
40
77
 
41
78
  LeRed.useEffect(() =>
42
79
  {
43
- setVisualValue(getVisualValue(value));
44
- }, [value]);
80
+ const newVisualValue = getVisualValue(value);
81
+ if(FLOAT_LAX(visualValue) !== FLOAT_LAX(newVisualValue))
82
+ {
83
+ setVisualValue(newVisualValue);
84
+ }
85
+ }, [value, getVisualValue]);
45
86
 
46
87
 
47
88
  const onChanged = LeRed.useCallback((event) =>
48
89
  {
49
90
  const originalTargetValue = event.target.value;
50
- const targetValue = LeMuiUtils.purgePrependedHiddenChar(originalTargetValue);
51
-
52
- let text = targetValue;
53
- let val = 0;
91
+ const {text, val} = getProcessedValue(originalTargetValue, decimals, allowZero, allowNegative);
54
92
 
55
- {// visual >>
56
- const minus = text.includes('-');
57
- text = text.replace(',', '.').replace(/[^0-9.]/g, '');
58
- if(text !== '')
59
- {
60
- val = Math.abs(FLOAT_LAX(text));
61
- if(allowNegative && minus)
62
- {
63
- val = -val;
64
- }
65
-
66
- let stringVal = val.toFixed(decimals + 1); // prevents rounding (by adding an extra digit and then cutting it off)
67
- stringVal = stringVal.substring(0, stringVal.length - 1);
68
-
69
- if(!text.includes('.') || (decimals <= 0))
70
- {
71
- text = stringVal.split('.')[0];
72
- }
73
- else if(text.endsWith('.'))
74
- {
75
- text = stringVal.split('.')[0] + '.';
76
- }
77
- else
78
- {
79
- text = stringVal.substring(0, stringVal.length - Math.max(0, decimals - text.split('.')[1].length));
80
- }
81
- setVisualValue(text);
82
- }
83
- }// visual <<
93
+ setVisualValue(text);
84
94
 
85
95
  if(onChange)
86
96
  {
87
- if(val !== 0)
88
- {
89
- if(decimals > 0)
90
- {
91
- val = Math.round(val * Math.pow(10, decimals)) / Math.pow(10, decimals);
92
- }
93
- else
94
- {
95
- val = Math.round(val);
96
- }
97
- }
98
-
99
97
  const newEvent = {
100
98
  ...event,
101
99
  target:{
@@ -35,7 +35,7 @@ const RemovableNumericTextField = LeRed.memo(({onRemove, onChange, onSelect, cla
35
35
 
36
36
 
37
37
  return (<>
38
- <NumericTextField className={'lowentry-mui--removable-textfield lowentry-mui--removable-numeric-textfield ' + (className ?? '')} onRenderValue={LeMuiUtils.prependHiddenChar} onChange={onChanged} onSelect={onSelected}>{children}</NumericTextField>
38
+ <NumericTextField className={'lowentry-mui--removable-textfield lowentry-mui--removable-numeric-textfield ' + (className ?? '')} onRenderValue={LeMuiUtils.prependHiddenChar} onChange={onChanged} onSelect={onSelected} {...props}>{children}</NumericTextField>
39
39
  </>);
40
40
  });
41
41
  export default RemovableNumericTextField;
@@ -1,2 +1,29 @@
1
- function e(e,t){void 0===t&&(t={});var d=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===d&&n.firstChild?n.insertBefore(s,n.firstChild):n.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}export{e as s};
1
+ function styleInject(css, ref) {
2
+ if ( ref === void 0 ) ref = {};
3
+ var insertAt = ref.insertAt;
4
+
5
+ if (!css || typeof document === 'undefined') { return; }
6
+
7
+ var head = document.head || document.getElementsByTagName('head')[0];
8
+ var style = document.createElement('style');
9
+ style.type = 'text/css';
10
+
11
+ if (insertAt === 'top') {
12
+ if (head.firstChild) {
13
+ head.insertBefore(style, head.firstChild);
14
+ } else {
15
+ head.appendChild(style);
16
+ }
17
+ } else {
18
+ head.appendChild(style);
19
+ }
20
+
21
+ if (style.styleSheet) {
22
+ style.styleSheet.cssText = css;
23
+ } else {
24
+ style.appendChild(document.createTextNode(css));
25
+ }
26
+ }
27
+
28
+ export { styleInject as s };
2
29
  //# sourceMappingURL=style-inject.es-1f59c1d0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style-inject.es-1f59c1d0.js","sources":["../node_modules/style-inject/dist/style-inject.es.js"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n"],"names":["styleInject","css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode"],"mappings":"AAAA,SAASA,EAAYC,EAAKC,QACX,IAARA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAKF,GAA2B,oBAAbG,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBY,CAqB1D"}
1
+ {"version":3,"file":"style-inject.es-1f59c1d0.js","sources":["../node_modules/style-inject/dist/style-inject.es.js"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;AAC/B,EAAE,KAAK,GAAG,KAAK,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;AACjC,EAAE,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC9B;AACA,EAAE,IAAI,CAAC,GAAG,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,EAAE,OAAO,EAAE;AAC1D;AACA,EAAE,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,EAAE,IAAI,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAC9C,EAAE,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC;AAC1B;AACA,EAAE,IAAI,QAAQ,KAAK,KAAK,EAAE;AAC1B,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;AACzB,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAChD,KAAK,MAAM;AACX,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC9B,KAAK;AACL,GAAG,MAAM;AACT,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,GAAG;AACH;AACA,EAAE,IAAI,KAAK,CAAC,UAAU,EAAE;AACxB,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC;AACnC,GAAG,MAAM;AACT,IAAI,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;AACpD,GAAG;AACH;;;;"}