@oliasoft-open-source/react-ui-library 4.13.0-beta-2 → 4.13.0-beta-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.d.ts CHANGED
@@ -1577,6 +1577,7 @@ export declare interface IUnitInputProps {
1577
1577
  convertBackToStorageUnit?: boolean;
1578
1578
  enableCosmeticRounding?: boolean;
1579
1579
  enableDisplayRounding?: boolean;
1580
+ roundDisplayValue?: (args: TStringOrNumber) => TStringOrNumber;
1580
1581
  }
1581
1582
 
1582
1583
  declare interface IUnitTable extends Omit<ITableProps['table'], 'rows'> {
@@ -1870,7 +1871,7 @@ declare type TUnitTableCellShape = TCellShape | IUnitTableStaticCell | IUnitTabl
1870
1871
 
1871
1872
  declare type UnitContextType = any;
1872
1873
 
1873
- export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, testId, warning, predefinedOptions, initialPredefinedOption, validationCallback, disabledValidation, allowEmpty, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitInputProps) => JSX_2.Element;
1874
+ export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, testId, warning, predefinedOptions, initialPredefinedOption, validationCallback, disabledValidation, allowEmpty, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, roundDisplayValue, }: IUnitInputProps) => JSX_2.Element;
1874
1875
 
1875
1876
  export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitTableProps) => JSX_2.Element;
1876
1877
 
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, isNil, isEqual as isEqual$4 } from "lodash";
19
- import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, roundToFixed, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, getUnit, KNOWN_UNITS, ALT_UNITS, isValueWithUnit, getValue as getValue$1, withUnit, convertSamePrecision, convertAndGetValue, split as split$1, label as label$b, isValidNum, getAltUnitsListByQuantity, altUnitsList, getUnitsForQuantity, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
19
+ import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, validateNumber, cleanNumStr, stripLeadingZeros, roundToFixed, roundByMagnitude, unitFromQuantity, getUnit, KNOWN_UNITS, ALT_UNITS, isValueWithUnit, getValue as getValue$1, withUnit, convertSamePrecision, convertAndGetValue, split as split$1, label as label$b, isValidNum, getAltUnitsListByQuantity, altUnitsList, 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;
@@ -55742,8 +55742,9 @@ const NumberInput = ({
55742
55742
  setFocus(false);
55743
55743
  onBlur(evt);
55744
55744
  };
55745
+ const defaultDisplayRound = (value2) => isInTable2 ? roundToFixed(value2, 2) : roundByMagnitude(value2, 4);
55745
55746
  const shouldDisplayRound = enableDisplayRounding && !focus2 && valid;
55746
- const valueWithDisplayRounding = shouldDisplayRound ? roundDisplayValue ? safeToString(roundDisplayValue(displayValue)) : roundToFixed(displayValue, 2) : displayValue;
55747
+ const valueWithDisplayRounding = shouldDisplayRound ? roundDisplayValue ? safeToString(roundDisplayValue(displayValue)) : defaultDisplayRound(value) : displayValue;
55747
55748
  return /* @__PURE__ */ jsx(
55748
55749
  KeyboardEventHandler,
55749
55750
  {
@@ -55777,7 +55778,11 @@ const NumberInput = ({
55777
55778
  }
55778
55779
  );
55779
55780
  };
55780
- const NumberInputCell = ({ cell: cell2, testId }) => {
55781
+ const NumberInputCell = ({
55782
+ cell: cell2,
55783
+ columnAlignment,
55784
+ testId
55785
+ }) => {
55781
55786
  return /* @__PURE__ */ jsx(
55782
55787
  NumberInput,
55783
55788
  {
@@ -55794,7 +55799,7 @@ const NumberInputCell = ({ cell: cell2, testId }) => {
55794
55799
  warning: cell2.warning,
55795
55800
  disabled: cell2.disabled,
55796
55801
  isInTable: true,
55797
- left: cell2.left,
55802
+ left: cell2.left ?? columnAlignment === Align.LEFT,
55798
55803
  tabIndex: cell2.disabled ? -1 : 0,
55799
55804
  testId,
55800
55805
  tooltip: cell2.tooltip,
@@ -55861,7 +55866,14 @@ const InputCellWrapper = ({
55861
55866
  columnAlignment,
55862
55867
  testId
55863
55868
  }
55864
- ) : cell2.type === "NumberInput" ? /* @__PURE__ */ jsx(NumberInputCell, { cell: cell2, testId }) : cell2.type === "DateInput" ? /* @__PURE__ */ jsx(InputCell, { cell: cell2, testId, type: "date" }) : cell2.type === "Select" ? /* @__PURE__ */ jsx(
55869
+ ) : cell2.type === "NumberInput" ? /* @__PURE__ */ jsx(
55870
+ NumberInputCell,
55871
+ {
55872
+ cell: cell2,
55873
+ columnAlignment,
55874
+ testId
55875
+ }
55876
+ ) : cell2.type === "DateInput" ? /* @__PURE__ */ jsx(InputCell, { cell: cell2, testId, type: "date" }) : cell2.type === "Select" ? /* @__PURE__ */ jsx(
55865
55877
  SelectCell,
55866
55878
  {
55867
55879
  cell: cell2,
@@ -70296,6 +70308,7 @@ const PredefinedOptionsMenu = ({
70296
70308
  const createPredefinedOption = (el2) => {
70297
70309
  const convertedValue = convertPredefinedOptions(el2);
70298
70310
  const [inputValue = "", unit2 = ""] = split$1(convertedValue);
70311
+ console.log(foundPredefinedMenuOption);
70299
70312
  return {
70300
70313
  type: MenuType.OPTION,
70301
70314
  inline: true,
@@ -70312,7 +70325,7 @@ const PredefinedOptionsMenu = ({
70312
70325
  /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70313
70326
  ] }),
70314
70327
  description: `${inputValue} ${unit2}`,
70315
- selected: withUnit(displayLayer == null ? void 0 : displayLayer.value, (displayLayer == null ? void 0 : displayLayer.unit) ?? "") === convertedValue && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70328
+ selected: isEqual$4(foundPredefinedMenuOption, el2) && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70316
70329
  };
70317
70330
  };
70318
70331
  const initialPredefinedOptionObject = useMemo$1(() => {
@@ -70420,7 +70433,8 @@ const UnitInput = ({
70420
70433
  allowEmpty = false,
70421
70434
  convertBackToStorageUnit = false,
70422
70435
  enableCosmeticRounding = true,
70423
- enableDisplayRounding = false
70436
+ enableDisplayRounding = false,
70437
+ roundDisplayValue
70424
70438
  }) => {
70425
70439
  const context2 = useUnitContext();
70426
70440
  const runAfterUpdate = useRunAfterUpdate();
@@ -70595,6 +70609,7 @@ const UnitInput = ({
70595
70609
  validationCallback: (_name, error22) => validationCallback(stringName, error22),
70596
70610
  enableCosmeticRounding,
70597
70611
  enableDisplayRounding,
70612
+ roundDisplayValue,
70598
70613
  groupOrder: predefinedOptions ? "middle" : "first",
70599
70614
  disableInternalErrorValidationMessages,
70600
70615
  small: small2
@@ -70697,8 +70712,7 @@ const convertVisibleRows = ({
70697
70712
  return {
70698
70713
  ...cell2,
70699
70714
  value: formattedDisplayValue,
70700
- enableCosmeticRounding: enableCosmeticRounding && unitChanged,
70701
- //comment on unitChanged rationale would be good
70715
+ enableCosmeticRounding,
70702
70716
  enableDisplayRounding,
70703
70717
  roundDisplayValue,
70704
70718
  onChange: (evt) => {