@oliasoft-open-source/react-ui-library 4.13.0-beta-2 → 4.13.0-beta-4
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 +3 -2
- package/dist/index.js +28 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1548,7 +1548,7 @@ declare interface IUnitConfigItem {
|
|
|
1548
1548
|
}
|
|
1549
1549
|
|
|
1550
1550
|
export declare interface IUnitInputProps {
|
|
1551
|
-
name
|
|
1551
|
+
name?: string | {
|
|
1552
1552
|
fieldName?: string;
|
|
1553
1553
|
};
|
|
1554
1554
|
placeholder?: string;
|
|
@@ -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,
|
|
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)) :
|
|
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 = ({
|
|
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(
|
|
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,
|
|
@@ -70180,9 +70192,13 @@ const convertUnit = ({
|
|
|
70180
70192
|
}) => {
|
|
70181
70193
|
var _a2;
|
|
70182
70194
|
const value = isValueWithUnit(inputValue) ? getValue$1(inputValue) : inputValue;
|
|
70195
|
+
const isInfinity = [Infinity, -Infinity].includes(Number(value));
|
|
70183
70196
|
if (doNotConvertValue) {
|
|
70184
70197
|
return { value, error: null };
|
|
70185
70198
|
}
|
|
70199
|
+
if (isInfinity) {
|
|
70200
|
+
return { value, error: null };
|
|
70201
|
+
}
|
|
70186
70202
|
const defaultFromUnit = fromUnit || (isValueWithUnit(inputValue) ? getUnit(inputValue) : unitFromQuantity(unitkey));
|
|
70187
70203
|
if (!((_a2 = validateNumber(value)) == null ? void 0 : _a2.valid)) {
|
|
70188
70204
|
return { value: void 0, error: "Invalid number format" };
|
|
@@ -70303,7 +70319,7 @@ const PredefinedOptionsMenu = ({
|
|
|
70303
70319
|
const validation = validateNumber(inputValue);
|
|
70304
70320
|
if (validation.valid && !disabled2) {
|
|
70305
70321
|
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
|
|
70306
|
-
onPredefinedOptionSelect(
|
|
70322
|
+
onPredefinedOptionSelect(convertedValue, el2);
|
|
70307
70323
|
setFoundPredefinedMenuOption(el2);
|
|
70308
70324
|
}
|
|
70309
70325
|
},
|
|
@@ -70312,7 +70328,7 @@ const PredefinedOptionsMenu = ({
|
|
|
70312
70328
|
/* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
|
|
70313
70329
|
] }),
|
|
70314
70330
|
description: `${inputValue} ${unit2}`,
|
|
70315
|
-
selected:
|
|
70331
|
+
selected: isEqual$4(foundPredefinedMenuOption, el2) && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
|
|
70316
70332
|
};
|
|
70317
70333
|
};
|
|
70318
70334
|
const initialPredefinedOptionObject = useMemo$1(() => {
|
|
@@ -70420,7 +70436,8 @@ const UnitInput = ({
|
|
|
70420
70436
|
allowEmpty = false,
|
|
70421
70437
|
convertBackToStorageUnit = false,
|
|
70422
70438
|
enableCosmeticRounding = true,
|
|
70423
|
-
enableDisplayRounding = false
|
|
70439
|
+
enableDisplayRounding = false,
|
|
70440
|
+
roundDisplayValue
|
|
70424
70441
|
}) => {
|
|
70425
70442
|
const context2 = useUnitContext();
|
|
70426
70443
|
const runAfterUpdate = useRunAfterUpdate();
|
|
@@ -70446,7 +70463,7 @@ const UnitInput = ({
|
|
|
70446
70463
|
const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
|
|
70447
70464
|
const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
|
|
70448
70465
|
const derivedAllowEmpty = allowEmpty || (displayLayer == null ? void 0 : displayLayer.value) === void 0;
|
|
70449
|
-
const disableInternalErrorValidationMessages = !!disabledValidation;
|
|
70466
|
+
const disableInternalErrorValidationMessages = !!disabledValidation || disabled2;
|
|
70450
70467
|
const getAlternativeUnits = () => {
|
|
70451
70468
|
const valueToList = value ?? "";
|
|
70452
70469
|
const initToUnit = displayLayer == null ? void 0 : displayLayer.unit;
|
|
@@ -70595,6 +70612,7 @@ const UnitInput = ({
|
|
|
70595
70612
|
validationCallback: (_name, error22) => validationCallback(stringName, error22),
|
|
70596
70613
|
enableCosmeticRounding,
|
|
70597
70614
|
enableDisplayRounding,
|
|
70615
|
+
roundDisplayValue,
|
|
70598
70616
|
groupOrder: predefinedOptions ? "middle" : "first",
|
|
70599
70617
|
disableInternalErrorValidationMessages,
|
|
70600
70618
|
small: small2
|
|
@@ -70697,8 +70715,7 @@ const convertVisibleRows = ({
|
|
|
70697
70715
|
return {
|
|
70698
70716
|
...cell2,
|
|
70699
70717
|
value: formattedDisplayValue,
|
|
70700
|
-
enableCosmeticRounding
|
|
70701
|
-
//comment on unitChanged rationale would be good
|
|
70718
|
+
enableCosmeticRounding,
|
|
70702
70719
|
enableDisplayRounding,
|
|
70703
70720
|
roundDisplayValue,
|
|
70704
70721
|
onChange: (evt) => {
|