@oliasoft-open-source/react-ui-library 4.8.2 → 4.9.0-beta-2

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.
Files changed (67) hide show
  1. package/dist/index.d.ts +7 -2
  2. package/dist/index.js +44 -29
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/{Color-KGDBMAHA-CLI1j7TM.js → Color-KGDBMAHA-9iiZ9sw8.js} +1 -1
  5. package/dist/storybook/assets/{DocsRenderer-PKQXORMH-C-VGLian.js → DocsRenderer-PKQXORMH-ypxq1WaK.js} +1 -1
  6. package/dist/storybook/assets/{accordion.stories-CjdOndbq.js → accordion.stories-D8Jb5lRq.js} +2 -2
  7. package/dist/storybook/assets/{afe.stories-D-uQj_IO.js → afe.stories-Dxdcf-Wr.js} +2 -2
  8. package/dist/storybook/assets/{buttons-and-links-DLCyz4fu.js → buttons-and-links-CtCO9I4x.js} +1 -1
  9. package/dist/storybook/assets/{casing-loads.stories-Cb2t61c-.js → casing-loads.stories-Bo9VN-h1.js} +2 -2
  10. package/dist/storybook/assets/{cell.stories-B6XrqnOz.js → cell.stories-BRIh_VqD.js} +2 -2
  11. package/dist/storybook/assets/{chunk-HLWAVYOI-B-NqvPla.js → chunk-HLWAVYOI-pVr_pd7U.js} +1 -1
  12. package/dist/storybook/assets/{color-DFh0-vFc.js → color-DRpLnJug.js} +1 -1
  13. package/dist/storybook/assets/{footer.stories-BxFhNGsz.js → footer.stories-Cghb-yfM.js} +2 -2
  14. package/dist/storybook/assets/form.stories-Bs1kjjd-.js +49 -0
  15. package/dist/storybook/assets/{formation.stories-r9JrQX7d.js → formation.stories-DqRntQtC.js} +2 -2
  16. package/dist/storybook/assets/iframe-Dl9kSAK_.js +2 -0
  17. package/dist/storybook/assets/{index-BIH3zom3.js → index-B-vN3mVN.js} +1 -1
  18. package/dist/storybook/assets/{index-MQZw3-wz.js → index-BtLaQIRR.js} +88 -88
  19. package/dist/storybook/assets/{input-group.stories-dQnx3QX0.js → input-group.stories-CCXx8SUE.js} +3 -3
  20. package/dist/storybook/assets/{input-validation-BhTmzA8C.js → input-validation-CipliMS4.js} +2 -2
  21. package/dist/storybook/assets/{inputs-BZwMYCXB.js → inputs-CfCos_Do.js} +1 -1
  22. package/dist/storybook/assets/layout-forms-BQ06Ufkz.js +16 -0
  23. package/dist/storybook/assets/{layout-general-hZ1fwnpl.js → layout-general-BSEz3PKo.js} +1 -1
  24. package/dist/storybook/assets/{modal.stories-B-4WKtnM.js → modal.stories-BZHVz3SN.js} +2 -2
  25. package/dist/storybook/assets/number-input-CKbeoN5B.js +16 -0
  26. package/dist/storybook/assets/number-input.stories-XP0NZg9d.js +166 -0
  27. package/dist/storybook/assets/{padding-and-spacing-DZHdCzCJ.js → padding-and-spacing-BJI9HaUS.js} +1 -1
  28. package/dist/storybook/assets/{pagination-bLx5-m9c.js → pagination-CUucuCPT.js} +1 -1
  29. package/dist/storybook/assets/{pagination.stories-BHPRfynZ.js → pagination.stories-CN4-LYyQ.js} +2 -2
  30. package/dist/storybook/assets/popover.stories-Cxaq0SAc.js +10 -0
  31. package/dist/storybook/assets/{preview-_veCKVNG.js → preview-1dyDpjfs.js} +2 -2
  32. package/dist/storybook/assets/{preview-nWTzJqHS.js → preview-I-_KBbaH.js} +1 -1
  33. package/dist/storybook/assets/{projects.stories-CdvyNFKw.js → projects.stories-B1J-8EYu.js} +2 -2
  34. package/dist/storybook/assets/{radio-button-C3RuBqEf.js → radio-button-YWkXh8yt.js} +1 -1
  35. package/dist/storybook/assets/{radio-button.stories-CAHs1mr6.js → radio-button.stories-DB127127.js} +2 -2
  36. package/dist/storybook/assets/{reservoirs.stories-C98Z9kS0.js → reservoirs.stories-B2mJ74TZ.js} +2 -2
  37. package/dist/storybook/assets/{rich-text-input.stories-B2p90wTh.js → rich-text-input.stories-B3O7b7-u.js} +3 -3
  38. package/dist/storybook/assets/{row.stories-BRVnImTl.js → row.stories-D014hMyd.js} +2 -2
  39. package/dist/storybook/assets/select-BEc_mNg5.js +61 -0
  40. package/dist/storybook/assets/select.input-D0UkAPd9.js +1 -0
  41. package/dist/storybook/assets/{select.stories-B0d_sE6g.js → select.stories-DXD4AYSk.js} +2 -2
  42. package/dist/storybook/assets/{site.stories-lIyAWOdt.js → site.stories-CbJ0phLn.js} +2 -2
  43. package/dist/storybook/assets/{table-DWBe_npR.js → table-CsEdIPXW.js} +1 -1
  44. package/dist/storybook/assets/{table.stories-Cb7lE3nF.js → table.stories-B5frb4W9.js} +2 -2
  45. package/dist/storybook/assets/{tabs-BoToLVEP.js → tabs-C3NG6m9W.js} +1 -1
  46. package/dist/storybook/assets/tabs.stories-dsXjRHJy.js +30 -0
  47. package/dist/storybook/assets/{title.stories-TUTSNdwJ.js → title.stories-BisMTHc8.js} +3 -3
  48. package/dist/storybook/assets/unit-input.stories-DiZlUE9e.js +380 -0
  49. package/dist/storybook/assets/unit-table.stories-DPghKtFI.js +152 -0
  50. package/dist/storybook/iframe.html +1 -1
  51. package/dist/storybook/index.json +1 -1
  52. package/dist/storybook/project.json +1 -1
  53. package/package.json +3 -3
  54. package/dist/404.html +0 -1
  55. package/dist/storybook/assets/enum-Bnn40S8Q.js +0 -1
  56. package/dist/storybook/assets/form.stories-C_zflIAj.js +0 -49
  57. package/dist/storybook/assets/helpers-JJxzGegQ.js +0 -1
  58. package/dist/storybook/assets/iframe-DOgYbEjR.js +0 -2
  59. package/dist/storybook/assets/layout-forms-j_hFXArR.js +0 -16
  60. package/dist/storybook/assets/number-input-C8O0lnql.js +0 -16
  61. package/dist/storybook/assets/number-input.stories-e-MRb-7_.js +0 -124
  62. package/dist/storybook/assets/popover.stories-DyTPnA5y.js +0 -10
  63. package/dist/storybook/assets/select-BpALjE__.js +0 -61
  64. package/dist/storybook/assets/select.input-CJed_LLR.js +0 -1
  65. package/dist/storybook/assets/tabs.stories-B52iEaHf.js +0 -30
  66. package/dist/storybook/assets/unit-input.stories-CRAsgJro.js +0 -316
  67. package/dist/storybook/assets/unit-table.stories-BdTJv4W-.js +0 -152
package/dist/index.d.ts CHANGED
@@ -904,6 +904,7 @@ declare interface INumberInputCell extends TCommonCell {
904
904
  left?: boolean;
905
905
  validationCallback?: TEmpty;
906
906
  allowEmpty?: boolean;
907
+ enableCosmeticRounding: boolean;
907
908
  enableDisplayRounding: boolean;
908
909
  roundDisplayValue: (value: TStringOrNumber) => TStringOrNumber;
909
910
  }
@@ -932,6 +933,7 @@ export declare interface INumberInputProps {
932
933
  allowEmpty?: boolean;
933
934
  isInTable?: boolean;
934
935
  groupOrder?: any;
936
+ enableCosmeticRounding?: boolean;
935
937
  enableDisplayRounding?: boolean;
936
938
  roundDisplayValue?: (args: TStringOrNumber) => TStringOrNumber;
937
939
  disableInternalErrorValidationMessages?: boolean;
@@ -1583,6 +1585,9 @@ export declare interface IUnitInputProps {
1583
1585
  onClick?: MouseEventHandler<HTMLInputElement>;
1584
1586
  onFocus?: FocusEventHandler<HTMLInputElement>;
1585
1587
  unitTemplate?: Record<string, any>;
1588
+ convertBackToStorageUnit?: boolean;
1589
+ enableCosmeticRounding?: boolean;
1590
+ enableDisplayRounding?: boolean;
1586
1591
  }
1587
1592
 
1588
1593
  declare interface IUnitTable extends Omit<ITableProps['table'], 'rows'> {
@@ -1664,7 +1669,7 @@ export declare const Modal: ({ children, visible, centered, width, onEnter, onEs
1664
1669
 
1665
1670
  export declare const NativeSelect: ({ disabled, error, warning, tooltip, options, onChange, onFocus, onBlur, right, small, tabIndex, selectedOption, width, groupOrder, testId, isInTable, clearable, placeholder, hasNonExistentValue, maxTooltipWidth, borderRadius, }: INativeSelectProps) => JSX_2.Element;
1666
1671
 
1667
- export declare const NumberInput: ({ name, placeholder, disabled, error, left, small, width, value, onChange, onFocus, onBlur, tabIndex, testId, tooltip, warning, validationCallback, allowEmpty, isInTable, groupOrder, enableDisplayRounding, roundDisplayValue, disableInternalErrorValidationMessages, }: INumberInputProps) => JSX_2.Element;
1672
+ export declare const NumberInput: ({ name, placeholder, disabled, error, left, small, width, value, onChange, onFocus, onBlur, tabIndex, testId, tooltip, warning, validationCallback, allowEmpty, isInTable, groupOrder, enableCosmeticRounding, enableDisplayRounding, roundDisplayValue, disableInternalErrorValidationMessages, }: INumberInputProps) => JSX_2.Element;
1668
1673
 
1669
1674
  export declare const OptionDropdown: ({ name, label, options, onChange, showHeader, maxHeight, }: IOptionDropdownProps) => ReactElement;
1670
1675
 
@@ -1860,7 +1865,7 @@ declare type TUnitTableCellShape = TCellShape | IUnitTableStaticCell | IUnitTabl
1860
1865
 
1861
1866
  declare type UnitContextType = any;
1862
1867
 
1863
- export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, doNotConvertValue, testId, warning, predefinedOptions, initialPredefinedOption, shouldLinkAutomaticly, selectedPredefinedOptionKey, validationCallback, disabledValidation, allowEmpty, autoValue, }: IUnitInputProps) => JSX_2.Element;
1868
+ export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, doNotConvertValue, testId, warning, predefinedOptions, initialPredefinedOption, shouldLinkAutomaticly, selectedPredefinedOptionKey, validationCallback, disabledValidation, allowEmpty, autoValue, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitInputProps) => JSX_2.Element;
1864
1869
 
1865
1870
  export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitTableProps) => JSX_2.Element;
1866
1871
 
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import * as PropTypes from "prop-types";
16
16
  import PropTypes__default from "prop-types";
17
17
  import ReactDOM, { createPortal, unstable_batchedUpdates, render } from "react-dom";
18
18
  import { noop as noop$3, set, get as get$2, isString as isString$3, isNumber as isNumber$1, isBoolean as isBoolean$2, isFunction as isFunction$3, isEmpty, isArray as isArray$1, toNumber, debounce as debounce$2, isObject as isObject$5, isEqual as isEqual$4 } from "lodash";
19
- import { roundToFixed, toString as toString$1, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, label as label$b, altUnitsList, getUnitsForQuantity, convertAndGetValue, isScientificStringNum, roundToPrecision, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
19
+ import { isScientificStringNum, roundToPrecision, roundToFixed, toString as toString$1, validateNumber, stripLeadingZeros, cleanNumStr, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, label as label$b, altUnitsList, convertAndGetValue, getUnitsForQuantity, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
20
20
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
21
21
  function getDefaultExportFromCjs(x2) {
22
22
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
@@ -55696,6 +55696,11 @@ const InputCell = ({
55696
55696
  }
55697
55697
  );
55698
55698
  };
55699
+ const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
55700
+ const roundNumberCosmetic = (value) => {
55701
+ const isScientific = isScientificStringNum(value);
55702
+ return !isScientific ? roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION) : value;
55703
+ };
55699
55704
  const safeToString = (value) => String(toString$1(value));
55700
55705
  const getStringName$1 = (name2) => {
55701
55706
  if (!name2) return "";
@@ -55730,6 +55735,7 @@ const NumberInput = ({
55730
55735
  allowEmpty = false,
55731
55736
  isInTable: isInTable2,
55732
55737
  groupOrder,
55738
+ enableCosmeticRounding = true,
55733
55739
  enableDisplayRounding = false,
55734
55740
  roundDisplayValue,
55735
55741
  disableInternalErrorValidationMessages = false
@@ -55737,6 +55743,7 @@ const NumberInput = ({
55737
55743
  const inputRef = useRef(null);
55738
55744
  const [displayValue, setDisplayValue] = useState(safeToString(value));
55739
55745
  const [focus2, setFocus] = useState(false);
55746
+ const [pristine, setPristine] = useState(true);
55740
55747
  const stringName = getStringName$1(name2);
55741
55748
  const validateInputValue = (value2) => {
55742
55749
  const validation = validateNumber(value2);
@@ -55750,7 +55757,8 @@ const NumberInput = ({
55750
55757
  const firstError = errors2 && errors2.length && !disableInternalErrorValidationMessages ? errors2[0] : null;
55751
55758
  useEffect(() => {
55752
55759
  setDisplayValue(safeToString(value));
55753
- }, [value, enableDisplayRounding]);
55760
+ setPristine(true);
55761
+ }, [value, enableCosmeticRounding, enableDisplayRounding]);
55754
55762
  useEffect(() => {
55755
55763
  if (!focus2 && !valid) {
55756
55764
  validationCallback(stringName, firstError);
@@ -55759,24 +55767,27 @@ const NumberInput = ({
55759
55767
  }
55760
55768
  }, [focus2, valid, error2]);
55761
55769
  const onChangeValue = (evt) => {
55762
- var _a2, _b;
55763
- const value2 = evt instanceof KeyboardEvent ? displayValue : (_a2 = evt == null ? void 0 : evt.target) == null ? void 0 : _a2.value;
55764
- const inputValue = cleanNumStr(
55765
- value2.replaceAll(" ", "").replaceAll("|", "")
55766
- );
55767
- setDisplayValue(inputValue);
55768
- if ((_b = validateInputValue(inputValue)) == null ? void 0 : _b.valid) {
55770
+ if (valid && !pristine) {
55769
55771
  const event = {
55770
55772
  ...evt,
55771
55773
  target: {
55772
55774
  ...evt.target,
55773
- value: stripLeadingZeros(safeToString(inputValue)),
55775
+ value: stripLeadingZeros(safeToString(displayValue)),
55774
55776
  name: stringName
55775
55777
  }
55776
55778
  };
55777
55779
  onChange(event);
55778
55780
  }
55779
55781
  };
55782
+ const onSetValue = (evt) => {
55783
+ const input2 = evt.target;
55784
+ const { value: value2 } = input2;
55785
+ const inputValue = cleanNumStr(
55786
+ value2.replaceAll(" ", "").replaceAll("|", "")
55787
+ );
55788
+ setDisplayValue(inputValue);
55789
+ setPristine(false);
55790
+ };
55780
55791
  useEffect(() => {
55781
55792
  if (inputRef && (inputRef == null ? void 0 : inputRef.current) && enableDisplayRounding && focus2) {
55782
55793
  const textInput = inputRef.current;
@@ -55794,10 +55805,17 @@ const NumberInput = ({
55794
55805
  };
55795
55806
  const onInputBlur = (evt) => {
55796
55807
  setFocus(false);
55808
+ onChangeValue(evt);
55797
55809
  onBlur(evt);
55798
55810
  };
55799
55811
  const shouldDisplayRound = enableDisplayRounding && !focus2 && valid;
55800
55812
  const valueWithDisplayRounding = shouldDisplayRound ? roundDisplayValue ? safeToString(roundDisplayValue(displayValue)) : roundToFixed(displayValue, 2) : displayValue;
55813
+ const displayValueEndsWithZero = !!(valueWithDisplayRounding == null ? void 0 : valueWithDisplayRounding.endsWith("0"));
55814
+ const shouldCosmeticallyRound = enableCosmeticRounding && // only when prop is enabled
55815
+ valueWithDisplayRounding && // not when empty typed value
55816
+ !displayValueEndsWithZero && // not when intentionally trying to type trailing zeros as interim values (OW-17109)
55817
+ valid;
55818
+ const valueWithCosmeticRounding = shouldCosmeticallyRound ? roundNumberCosmetic(valueWithDisplayRounding) : valueWithDisplayRounding;
55801
55819
  return /* @__PURE__ */ jsx(
55802
55820
  KeyboardEventHandler,
55803
55821
  {
@@ -55811,11 +55829,11 @@ const NumberInput = ({
55811
55829
  testId,
55812
55830
  disabled: disabled2,
55813
55831
  placeholder: placeholder3,
55814
- value: valueWithDisplayRounding,
55815
- onChange: onChangeValue,
55832
+ value: valueWithCosmeticRounding,
55833
+ onChange: onSetValue,
55816
55834
  onFocus: onInputFocus,
55817
55835
  onBlur: onInputBlur,
55818
- error: firstError || error2,
55836
+ error: !focus2 && (firstError || error2),
55819
55837
  warning: warning2,
55820
55838
  right: !left2,
55821
55839
  small: small2,
@@ -55854,6 +55872,7 @@ const NumberInputCell = ({ cell: cell2, testId }) => {
55854
55872
  tooltip: cell2.tooltip,
55855
55873
  validationCallback: cell2.validationCallback,
55856
55874
  allowEmpty: cell2.allowEmpty,
55875
+ enableCosmeticRounding: cell2.enableCosmeticRounding,
55857
55876
  enableDisplayRounding: cell2.enableDisplayRounding,
55858
55877
  roundDisplayValue: cell2.roundDisplayValue
55859
55878
  }
@@ -70283,7 +70302,10 @@ const UnitInput = ({
70283
70302
  validationCallback = () => ({ name: "", error: null }),
70284
70303
  disabledValidation = false,
70285
70304
  allowEmpty = false,
70286
- autoValue
70305
+ autoValue,
70306
+ convertBackToStorageUnit = false,
70307
+ enableCosmeticRounding = true,
70308
+ enableDisplayRounding = false
70287
70309
  }) => {
70288
70310
  const context2 = useUnitContext();
70289
70311
  const runAfterUpdate = useRunAfterUpdate();
@@ -70348,9 +70370,10 @@ const UnitInput = ({
70348
70370
  const input2 = evt.target;
70349
70371
  const { value: inputValue, selectionStart: currentCursorPosition } = input2;
70350
70372
  const newValue = withUnit(inputValue, (displayLayer == null ? void 0 : displayLayer.unit) || "");
70373
+ const returnValue = convertBackToStorageUnit ? withUnit(convertAndGetValue(newValue, propUnit), propUnit) : newValue;
70351
70374
  onChange({
70352
70375
  target: {
70353
- value: newValue,
70376
+ value: returnValue,
70354
70377
  name: stringName2
70355
70378
  }
70356
70379
  });
@@ -70511,6 +70534,8 @@ const UnitInput = ({
70511
70534
  left: left2,
70512
70535
  allowEmpty,
70513
70536
  validationCallback: (_name, error22) => validationCallback(stringName, error22),
70537
+ enableCosmeticRounding,
70538
+ enableDisplayRounding,
70514
70539
  groupOrder: predefinedOptions ? "middle" : "first",
70515
70540
  disableInternalErrorValidationMessages
70516
70541
  },
@@ -70530,7 +70555,7 @@ const UnitInput = ({
70530
70555
  sections: alternativeUnits.map(([value2, altUnit, label2]) => {
70531
70556
  const displayUnit = label2 || altUnit || "";
70532
70557
  const safeValue = !isNaN(Number(value2)) ? value2 : "";
70533
- const displayValue = safeValue;
70558
+ const displayValue = enableCosmeticRounding ? roundNumberCosmetic(safeValue) : safeValue;
70534
70559
  return {
70535
70560
  type: "Option",
70536
70561
  label: displayValue,
@@ -70601,22 +70626,12 @@ const convertVisibleRows = ({
70601
70626
  const storageUnit = storageUnits[unitKey];
70602
70627
  const unitChanged = selectedUnit !== storageUnit;
70603
70628
  const convertedValue = unitChanged ? convertAndGetValue(value, selectedUnit, storageUnit) : cell2.value;
70604
- const isScientific = isScientificStringNum(value);
70605
- const displayValue = enableCosmeticRounding && (unitChanged || !isScientific) ? (
70606
- /*
70607
- Optionally do Excel-style "cosmetic rounding" of display values (only if enableCosmeticRounding prop on)
70608
- This means rounding to slightly less precision than the underlying floating-point number type, to
70609
- resolve floating-point "rounding noise" associated with storing values in one unit but converting
70610
- and displaying them in another unit. This solution was evaluated by Tools Team in relation to
70611
- tickets OW-10614 and OW-15745.
70612
- */
70613
- roundToPrecision(convertedValue, 14)
70614
- ) : convertedValue;
70615
- const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(displayValue) : displayValue;
70629
+ const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(convertedValue) : convertedValue;
70616
70630
  return {
70617
70631
  ...cell2,
70618
70632
  value: formattedDisplayValue,
70619
- enableCosmeticRounding,
70633
+ enableCosmeticRounding: enableCosmeticRounding && unitChanged,
70634
+ //todo: why did we need to check unitChanged here? (original rationale)
70620
70635
  enableDisplayRounding,
70621
70636
  roundDisplayValue,
70622
70637
  onChange: (evt) => {