@bpmn-io/form-js-viewer 0.10.0-alpha.2 → 0.10.0-alpha.3

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.
package/dist/index.cjs CHANGED
@@ -585,16 +585,16 @@ function countDecimals(number) {
585
585
  function isValidNumber(value) {
586
586
  return (typeof value === 'number' || typeof value === 'string') && value !== '' && !isNaN(Number(value));
587
587
  }
588
- function willKeyProduceValidNumber(key, previousValue, carretIndex, selectionWidth, decimalDigits) {
588
+ function willKeyProduceValidNumber(key, previousValue, caretIndex, selectionWidth, decimalDigits) {
589
589
  // Dot and comma are both treated as dot
590
590
  previousValue = previousValue.replace(',', '.');
591
591
  const isFirstDot = !previousValue.includes('.') && (key === '.' || key === ',');
592
- const isFirstMinus = !previousValue.includes('-') && key === '-' && carretIndex === 0;
592
+ const isFirstMinus = !previousValue.includes('-') && key === '-' && caretIndex === 0;
593
593
  const keypressIsNumeric = /^[0-9]$/i.test(key);
594
- const dotIndex = previousValue?.indexOf('.') ?? -1;
594
+ const dotIndex = previousValue === undefined ? -1 : previousValue.indexOf('.');
595
595
 
596
- // If the carret is positioned after a dot, and the current decimal digits count is equal or greater to the maximum, disallow the key press
597
- const overflowsDecimalSpace = typeof decimalDigits === 'number' && selectionWidth === 0 && dotIndex !== -1 && previousValue.includes('.') && previousValue.split('.')[1].length >= decimalDigits && carretIndex > dotIndex;
596
+ // If the caret is positioned after a dot, and the current decimal digits count is equal or greater to the maximum, disallow the key press
597
+ const overflowsDecimalSpace = typeof decimalDigits === 'number' && selectionWidth === 0 && dotIndex !== -1 && previousValue.includes('.') && previousValue.split('.')[1].length >= decimalDigits && caretIndex > dotIndex;
598
598
  const keypressIsAllowedChar = keypressIsNumeric || decimalDigits !== 0 && isFirstDot || isFirstMinus;
599
599
  return keypressIsAllowedChar && !overflowsDecimalSpace;
600
600
  }
@@ -1940,10 +1940,10 @@ function Numberfield(props) {
1940
1940
 
1941
1941
  // intercept key presses which would lead to an invalid number
1942
1942
  const onKeyPress = e => {
1943
- const carretIndex = inputRef.current.selectionStart;
1943
+ const caretIndex = inputRef.current.selectionStart;
1944
1944
  const selectionWidth = inputRef.current.selectionStart - inputRef.current.selectionEnd;
1945
1945
  const previousValue = inputRef.current.value;
1946
- if (!willKeyProduceValidNumber(e.key, previousValue, carretIndex, selectionWidth, decimalDigits)) {
1946
+ if (!willKeyProduceValidNumber(e.key, previousValue, caretIndex, selectionWidth, decimalDigits)) {
1947
1947
  e.preventDefault();
1948
1948
  }
1949
1949
  };