@oliasoft-open-source/react-ui-library 4.7.1 → 4.8.0-beta-1
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/assets/{index-D5kcnHmD.js → index-DYGOUZH8.js} +0 -1
- package/dist/global.css +4 -1
- package/dist/index.d.ts +16 -6
- package/dist/index.html +1 -1
- package/dist/index.js +121 -158
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-ChInQPtm.js → Color-KGDBMAHA-TfNjzFol.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-D9jeh5x5.js → DocsRenderer-PKQXORMH-CvKaIyAS.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-sb-Y7MMb.js → accordion.stories-CbUgpQAC.js} +1 -1
- package/dist/storybook/assets/{afe.stories--E_j7kET.js → afe.stories-3nCmEH0q.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-CGABKYuN.js → buttons-and-links-DQXhygpA.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-EZlP6XsN.js → casing-loads.stories-CSdj5faI.js} +1 -1
- package/dist/storybook/assets/{cell.stories-D9KrTmCA.js → cell.stories-DBLJ17se.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-4dAs2eBm.js → chunk-HLWAVYOI-C9RjJIQI.js} +1 -1
- package/dist/storybook/assets/{color-Bif_5nQw.js → color-DiLYh1iE.js} +1 -1
- package/dist/storybook/assets/{footer.stories-B5zvZawz.js → footer.stories-CpsfxWaj.js} +1 -1
- package/dist/storybook/assets/{form.stories-D58sdhOk.js → form.stories-CqFk9g40.js} +1 -1
- package/dist/storybook/assets/{formation.stories-OtA8Hcp6.js → formation.stories-DN4l7-9g.js} +1 -1
- package/dist/storybook/assets/iframe-CeeVOkcX.js +2 -0
- package/dist/storybook/assets/{index-CdEG3ntG.js → index-B9Xm8jXL.js} +1 -1
- package/dist/storybook/assets/{index-0mVwGqNm.js → index-BesoTaoD.js} +4 -4
- package/dist/storybook/assets/{index-DQs5XS8h.js → index-DGl0obec.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-hHCmTbtu.js → input-group.stories-DctjyXor.js} +1 -1
- package/dist/storybook/assets/{input-validation-DGRN9eyS.js → input-validation-BVAuiwBg.js} +1 -1
- package/dist/storybook/assets/{inputs-C1zY_c9W.js → inputs-zvgQy7Ef.js} +4 -4
- package/dist/storybook/assets/{layout-forms-kbHRclqK.js → layout-forms-CiP17Xxu.js} +1 -1
- package/dist/storybook/assets/{layout-general-D5EVLJYf.js → layout-general-ChpChtZ5.js} +1 -1
- package/dist/storybook/assets/{modal.stories-ChRLG9ud.js → modal.stories-B31R5KLu.js} +1 -1
- package/dist/storybook/assets/number-input-RV1zn3_t.js +4 -0
- package/dist/storybook/assets/number-input.stories-CBser6Ry.js +153 -0
- package/dist/storybook/assets/{padding-and-spacing-BUAWfapl.js → padding-and-spacing-Ds9-kSBv.js} +1 -1
- package/dist/storybook/assets/{pagination-0wY_w1xz.js → pagination-BA9mb3NP.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-BagAIIz3.js → pagination.stories-2HPZnimC.js} +1 -1
- package/dist/storybook/assets/{popover.stories-ChwzGOlc.js → popover.stories-SMz7Cd0A.js} +1 -1
- package/dist/storybook/assets/{preview-C_kotj1_.js → preview-AeyuE7NC.js} +2 -2
- package/dist/storybook/assets/{preview-BZH-CnkP.js → preview-craejBWr.js} +1 -1
- package/dist/storybook/assets/{reservoirs.stories-DywuU8EY.js → reservoirs.stories-D_HCj-TY.js} +1 -1
- package/dist/storybook/assets/{rich-text-input.stories-Cw_6EJx8.js → rich-text-input.stories-rQEM-l57.js} +1 -1
- package/dist/storybook/assets/{row.stories-D7V0fxhq.js → row.stories-BHz3vX8n.js} +1 -1
- package/dist/storybook/assets/{select-yqiMF9-4.js → select-BPp24Pdw.js} +1 -1
- package/dist/storybook/assets/{select.stories-VMcOn7Ri.js → select.stories-hyJTR9B_.js} +1 -1
- package/dist/storybook/assets/{smart-upload-modal.stories-Cot88l9r.js → smart-upload-modal.stories-01X4DGpB.js} +1 -1
- package/dist/storybook/assets/{table-DmwpXp_Q.js → table-CWxrvmPS.js} +1 -1
- package/dist/storybook/assets/{table.stories-DKcZk5JR.js → table.stories-DXq-XP56.js} +1 -1
- package/dist/storybook/assets/{title.stories-CKbl0CB2.js → title.stories-D2obDA1k.js} +1 -1
- package/dist/storybook/assets/unit-input-5P4Cogho.css +1 -0
- package/dist/storybook/assets/unit-input.stories-CEzR1Pvn.js +354 -0
- package/dist/storybook/assets/unit-table.stories-CWGzy_cE.js +150 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/404.html +0 -1
- package/dist/storybook/assets/iframe-CPU35noh.js +0 -2
- package/dist/storybook/assets/number-input-B-Nmya5O.js +0 -4
- package/dist/storybook/assets/number-input.stories-COWyMRAs.js +0 -97
- package/dist/storybook/assets/unit-input-CoFS2qhN.css +0 -1
- package/dist/storybook/assets/unit-input.stories-BkkknmTW.js +0 -290
- package/dist/storybook/assets/unit-table.stories-BoNWlaAe.js +0 -150
|
@@ -75845,7 +75845,6 @@ function TreeInner(props, ref2) {
|
|
|
75845
75845
|
);
|
|
75846
75846
|
}
|
|
75847
75847
|
reactExports.forwardRef(TreeInner);
|
|
75848
|
-
requireUnits();
|
|
75849
75848
|
const Footer = () => {
|
|
75850
75849
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
75851
75850
|
/* @__PURE__ */ jsxRuntimeExports.jsx(Divider, {}),
|
package/dist/global.css
CHANGED
|
@@ -11222,6 +11222,9 @@ tbody ._staticCell_u3xdj_116 ._staticCellContent_u3xdj_119 {
|
|
|
11222
11222
|
background-color: var(--color-background-primary);
|
|
11223
11223
|
transform: translate(-50%, -50%);
|
|
11224
11224
|
}
|
|
11225
|
-
.
|
|
11225
|
+
._predefinedMenuActive_ye9w9_1 input {
|
|
11226
11226
|
background: var(--color-background-disabled) !important;
|
|
11227
11227
|
}
|
|
11228
|
+
._inputWrapper_ye9w9_4 {
|
|
11229
|
+
flex: 1;
|
|
11230
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -900,6 +900,7 @@ declare interface INumberInputCell extends TCommonCell {
|
|
|
900
900
|
left?: boolean;
|
|
901
901
|
validationCallback?: TEmpty;
|
|
902
902
|
allowEmpty?: boolean;
|
|
903
|
+
enableCosmeticRounding: boolean;
|
|
903
904
|
enableDisplayRounding: boolean;
|
|
904
905
|
roundDisplayValue: (value: TStringNumberNull) => TStringNumberNull;
|
|
905
906
|
}
|
|
@@ -928,8 +929,10 @@ export declare interface INumberInputProps {
|
|
|
928
929
|
allowEmpty?: boolean;
|
|
929
930
|
isInTable?: boolean;
|
|
930
931
|
groupOrder?: any;
|
|
932
|
+
enableCosmeticRounding?: boolean;
|
|
931
933
|
enableDisplayRounding?: boolean;
|
|
932
934
|
roundDisplayValue?: (args: TStringNumberNull) => TStringNumberNull;
|
|
935
|
+
disableInternalErrorValidationMessages?: boolean;
|
|
933
936
|
}
|
|
934
937
|
|
|
935
938
|
export declare interface IOptionDropdownProps {
|
|
@@ -1578,10 +1581,7 @@ export declare interface IUnitInputProps {
|
|
|
1578
1581
|
initialPredefinedOption?: boolean;
|
|
1579
1582
|
shouldLinkAutomaticly?: boolean;
|
|
1580
1583
|
selectedPredefinedOptionKey?: string;
|
|
1581
|
-
validationCallback?: (
|
|
1582
|
-
name: string;
|
|
1583
|
-
error: string | null;
|
|
1584
|
-
};
|
|
1584
|
+
validationCallback?: (params: IUnitInputValidationCallbackPayload) => void;
|
|
1585
1585
|
disabledValidation?: boolean;
|
|
1586
1586
|
allowEmpty?: boolean;
|
|
1587
1587
|
autoValue?: string;
|
|
@@ -1590,6 +1590,16 @@ export declare interface IUnitInputProps {
|
|
|
1590
1590
|
onClick?: MouseEventHandler<HTMLInputElement>;
|
|
1591
1591
|
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
1592
1592
|
unitTemplate?: Record<string, any>;
|
|
1593
|
+
convertBackToStorageUnit?: boolean;
|
|
1594
|
+
enableCosmeticRounding?: boolean;
|
|
1595
|
+
enableDisplayRounding?: boolean;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
declare interface IUnitInputValidationCallbackPayload {
|
|
1599
|
+
name: string | {
|
|
1600
|
+
fieldName: string;
|
|
1601
|
+
};
|
|
1602
|
+
error: string | null;
|
|
1593
1603
|
}
|
|
1594
1604
|
|
|
1595
1605
|
declare interface IUnitTable extends Omit<ITableProps['table'], 'rows'> {
|
|
@@ -1671,7 +1681,7 @@ export declare const Modal: ({ children, visible, centered, width, onEnter, onEs
|
|
|
1671
1681
|
|
|
1672
1682
|
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;
|
|
1673
1683
|
|
|
1674
|
-
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, }: INumberInputProps) => JSX_2.Element;
|
|
1684
|
+
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;
|
|
1675
1685
|
|
|
1676
1686
|
export declare const OptionDropdown: ({ name, label, options, onChange, showHeader, maxHeight, }: IOptionDropdownProps) => ReactElement;
|
|
1677
1687
|
|
|
@@ -1852,7 +1862,7 @@ export declare type TTriggerType = 'Text' | 'Button' | 'DropDownButton' | 'Compo
|
|
|
1852
1862
|
|
|
1853
1863
|
declare type TUnitTableCellShape = TCellShape | IUnitTableStaticCell | IUnitTableInputCell | IUnitTableNumberInputCell;
|
|
1854
1864
|
|
|
1855
|
-
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;
|
|
1865
|
+
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;
|
|
1856
1866
|
|
|
1857
1867
|
export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitTableProps) => JSX_2.Element;
|
|
1858
1868
|
|
package/dist/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><head><title>React UI Library</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1" user-scalable="no"><meta name="apple-mobile-web-app-capable" content="yes"><script type="module" crossorigin src="/react-ui-library/assets/index-
|
|
1
|
+
<!doctype html><head><title>React UI Library</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1" user-scalable="no"><meta name="apple-mobile-web-app-capable" content="yes"><script type="module" crossorigin src="/react-ui-library/assets/index-DYGOUZH8.js"></script><link rel="stylesheet" crossorigin href="/react-ui-library/assets/index-Oe0PlEED.css"></head><body><div id="content"></div></body>
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,8 @@ import React__default, { useContext, isValidElement, useState, useRef, useEffect
|
|
|
7
7
|
import * as PropTypes from "prop-types";
|
|
8
8
|
import PropTypes__default from "prop-types";
|
|
9
9
|
import ReactDOM, { createPortal, unstable_batchedUpdates, render } from "react-dom";
|
|
10
|
-
import _$1, { 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,
|
|
11
|
-
import { roundToFixed, validateNumber, cleanNumStr, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1,
|
|
12
|
-
import { isValueWithUnit as isValueWithUnit$1 } from "@oliasoft-open-source/units/dist/units";
|
|
10
|
+
import _$1, { 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";
|
|
11
|
+
import { isScientificStringNum, roundToPrecision, roundToFixed, validateNumber, 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";
|
|
13
12
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
14
13
|
function getDefaultExportFromCjs(x2) {
|
|
15
14
|
return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
|
|
@@ -55464,7 +55463,7 @@ const inputDisabled$1 = "_inputDisabled_u3xdj_61";
|
|
|
55464
55463
|
const hideScrollbars$1 = "_hideScrollbars_u3xdj_67";
|
|
55465
55464
|
const cell = "_cell_u3xdj_77";
|
|
55466
55465
|
const disabledLink = "_disabledLink_u3xdj_87";
|
|
55467
|
-
const inputWrapper = "_inputWrapper_u3xdj_91";
|
|
55466
|
+
const inputWrapper$1 = "_inputWrapper_u3xdj_91";
|
|
55468
55467
|
const breakWord = "_breakWord_u3xdj_106";
|
|
55469
55468
|
const inputCell = "_inputCell_u3xdj_109";
|
|
55470
55469
|
const sliderCell = "_sliderCell_u3xdj_112";
|
|
@@ -55494,7 +55493,7 @@ const styles$7 = {
|
|
|
55494
55493
|
hideScrollbars: hideScrollbars$1,
|
|
55495
55494
|
cell,
|
|
55496
55495
|
disabledLink,
|
|
55497
|
-
inputWrapper,
|
|
55496
|
+
inputWrapper: inputWrapper$1,
|
|
55498
55497
|
breakWord,
|
|
55499
55498
|
inputCell,
|
|
55500
55499
|
sliderCell,
|
|
@@ -55550,6 +55549,11 @@ const InputCell = ({
|
|
|
55550
55549
|
}
|
|
55551
55550
|
);
|
|
55552
55551
|
};
|
|
55552
|
+
const COSMETIC_ROUNDING_DEFAULT_PRECISION = 14;
|
|
55553
|
+
const roundNumberCosmetic = (value) => {
|
|
55554
|
+
const isScientific = isScientificStringNum(value);
|
|
55555
|
+
return !isScientific ? roundToPrecision(value, COSMETIC_ROUNDING_DEFAULT_PRECISION) : value;
|
|
55556
|
+
};
|
|
55553
55557
|
const getStringName$1 = (name2) => {
|
|
55554
55558
|
if (!name2) return "";
|
|
55555
55559
|
if (typeof name2 === "string") {
|
|
@@ -55583,61 +55587,58 @@ const NumberInput = ({
|
|
|
55583
55587
|
allowEmpty = false,
|
|
55584
55588
|
isInTable: isInTable2,
|
|
55585
55589
|
groupOrder,
|
|
55590
|
+
enableCosmeticRounding = true,
|
|
55586
55591
|
enableDisplayRounding = false,
|
|
55587
|
-
roundDisplayValue
|
|
55592
|
+
roundDisplayValue,
|
|
55593
|
+
disableInternalErrorValidationMessages = false
|
|
55588
55594
|
}) => {
|
|
55589
55595
|
const inputRef = useRef(null);
|
|
55590
|
-
const [displayValue, setDisplayValue] = useState(value);
|
|
55591
|
-
const [validationError, setValidationError] = useState(null);
|
|
55596
|
+
const [displayValue, setDisplayValue] = useState(String(value));
|
|
55592
55597
|
const [focus2, setFocus] = useState(false);
|
|
55598
|
+
const [pristine, setPristine] = useState(true);
|
|
55593
55599
|
const stringName = getStringName$1(name2);
|
|
55594
55600
|
const validateInputValue = (value2) => {
|
|
55595
|
-
|
|
55601
|
+
const validation = validateNumber(value2);
|
|
55596
55602
|
if (allowEmpty && value2 === "" || validation.valid) {
|
|
55597
55603
|
return { ...validation, valid: true, errors: void 0 };
|
|
55598
55604
|
} else {
|
|
55599
55605
|
return validation;
|
|
55600
55606
|
}
|
|
55601
55607
|
};
|
|
55608
|
+
const { valid, errors: errors2 } = validateInputValue(displayValue);
|
|
55609
|
+
const firstError = errors2 && errors2.length && !disableInternalErrorValidationMessages ? errors2[0] : null;
|
|
55602
55610
|
useEffect(() => {
|
|
55603
|
-
|
|
55604
|
-
|
|
55605
|
-
|
|
55606
|
-
|
|
55607
|
-
validationCallback(stringName, null);
|
|
55608
|
-
} else {
|
|
55609
|
-
const firstError = errors2 && errors2.length ? errors2[0] : null;
|
|
55610
|
-
setValidationError(firstError);
|
|
55611
|
+
setDisplayValue(String(value));
|
|
55612
|
+
}, [value, enableCosmeticRounding, enableDisplayRounding]);
|
|
55613
|
+
useEffect(() => {
|
|
55614
|
+
if (!focus2 && !valid) {
|
|
55611
55615
|
validationCallback(stringName, firstError);
|
|
55616
|
+
} else {
|
|
55617
|
+
validationCallback(stringName, null);
|
|
55612
55618
|
}
|
|
55613
|
-
}, [
|
|
55614
|
-
const
|
|
55615
|
-
|
|
55616
|
-
|
|
55617
|
-
const inputValue = cleanNumStr(
|
|
55618
|
-
value2.replaceAll(" ", "").replaceAll("|", "")
|
|
55619
|
-
);
|
|
55620
|
-
const { valid, errors: errors2 } = validateInputValue(inputValue);
|
|
55621
|
-
if (valid) {
|
|
55622
|
-
const newEvent = {
|
|
55619
|
+
}, [focus2, valid, error2]);
|
|
55620
|
+
const onChangeValue = (evt) => {
|
|
55621
|
+
if (valid && !pristine) {
|
|
55622
|
+
const event = {
|
|
55623
55623
|
...evt,
|
|
55624
55624
|
target: {
|
|
55625
55625
|
...evt.target,
|
|
55626
|
-
value:
|
|
55626
|
+
value: String(displayValue),
|
|
55627
55627
|
name: stringName
|
|
55628
55628
|
}
|
|
55629
55629
|
};
|
|
55630
|
-
onChange(
|
|
55631
|
-
setDisplayValue(inputValue);
|
|
55632
|
-
setValidationError(null);
|
|
55633
|
-
validationCallback(stringName, null);
|
|
55634
|
-
} else {
|
|
55635
|
-
setDisplayValue(inputValue);
|
|
55636
|
-
const firstError = errors2 && errors2.length ? errors2[0] : null;
|
|
55637
|
-
setValidationError(firstError);
|
|
55638
|
-
validationCallback(stringName, firstError);
|
|
55630
|
+
onChange(event);
|
|
55639
55631
|
}
|
|
55640
55632
|
};
|
|
55633
|
+
const onSetValue = (evt) => {
|
|
55634
|
+
const input2 = evt.target;
|
|
55635
|
+
const { value: value2 } = input2;
|
|
55636
|
+
const inputValue = cleanNumStr(
|
|
55637
|
+
value2.replaceAll(" ", "").replaceAll("|", "")
|
|
55638
|
+
);
|
|
55639
|
+
setDisplayValue(inputValue);
|
|
55640
|
+
setPristine(false);
|
|
55641
|
+
};
|
|
55641
55642
|
useEffect(() => {
|
|
55642
55643
|
if (inputRef && (inputRef == null ? void 0 : inputRef.current) && enableDisplayRounding && focus2) {
|
|
55643
55644
|
const textInput = inputRef.current;
|
|
@@ -55655,33 +55656,48 @@ const NumberInput = ({
|
|
|
55655
55656
|
};
|
|
55656
55657
|
const onInputBlur = (evt) => {
|
|
55657
55658
|
setFocus(false);
|
|
55659
|
+
onChangeValue(evt);
|
|
55658
55660
|
onBlur(evt);
|
|
55659
55661
|
};
|
|
55660
|
-
const
|
|
55662
|
+
const shouldDisplayRound = enableDisplayRounding && !focus2 && valid;
|
|
55663
|
+
const valueWithDisplayRounding = shouldDisplayRound ? roundDisplayValue ? String(roundDisplayValue(displayValue)) : roundToFixed(displayValue, 2) : displayValue;
|
|
55664
|
+
const displayValueEndsWithZero = !!(valueWithDisplayRounding == null ? void 0 : valueWithDisplayRounding.endsWith("0"));
|
|
55665
|
+
const shouldCosmeticallyRound = enableCosmeticRounding && // only when prop is enabled
|
|
55666
|
+
valueWithDisplayRounding && // not when empty typed value
|
|
55667
|
+
!displayValueEndsWithZero && // not when intentionally trying to type trailing zeros as interim values (OW-17109)
|
|
55668
|
+
valid;
|
|
55669
|
+
const valueWithCosmeticRounding = shouldCosmeticallyRound ? roundNumberCosmetic(valueWithDisplayRounding) : valueWithDisplayRounding;
|
|
55661
55670
|
return /* @__PURE__ */ jsx(
|
|
55662
|
-
|
|
55671
|
+
KeyboardEventHandler,
|
|
55663
55672
|
{
|
|
55664
|
-
|
|
55665
|
-
|
|
55666
|
-
|
|
55667
|
-
|
|
55668
|
-
|
|
55669
|
-
|
|
55670
|
-
|
|
55671
|
-
|
|
55672
|
-
|
|
55673
|
-
|
|
55674
|
-
|
|
55675
|
-
|
|
55676
|
-
|
|
55677
|
-
|
|
55678
|
-
|
|
55679
|
-
|
|
55680
|
-
|
|
55681
|
-
|
|
55682
|
-
|
|
55683
|
-
|
|
55684
|
-
|
|
55673
|
+
handleKeys: [EventKey.ENTER],
|
|
55674
|
+
onKeyEvent: (_key, evt) => onChangeValue(evt),
|
|
55675
|
+
children: /* @__PURE__ */ jsx(
|
|
55676
|
+
Input$1,
|
|
55677
|
+
{
|
|
55678
|
+
type: "text",
|
|
55679
|
+
name: stringName,
|
|
55680
|
+
testId,
|
|
55681
|
+
disabled: disabled2,
|
|
55682
|
+
placeholder: placeholder3,
|
|
55683
|
+
value: valueWithCosmeticRounding,
|
|
55684
|
+
onChange: onSetValue,
|
|
55685
|
+
onFocus: onInputFocus,
|
|
55686
|
+
onBlur: onInputBlur,
|
|
55687
|
+
error: !focus2 && (firstError || error2),
|
|
55688
|
+
warning: warning2,
|
|
55689
|
+
right: !left2,
|
|
55690
|
+
small: small2,
|
|
55691
|
+
width: width2,
|
|
55692
|
+
isInTable: isInTable2,
|
|
55693
|
+
groupOrder,
|
|
55694
|
+
tabIndex,
|
|
55695
|
+
tooltip: tooltip2,
|
|
55696
|
+
ref: inputRef
|
|
55697
|
+
},
|
|
55698
|
+
stringName
|
|
55699
|
+
)
|
|
55700
|
+
}
|
|
55685
55701
|
);
|
|
55686
55702
|
};
|
|
55687
55703
|
const NumberInputCell = ({ cell: cell2, testId }) => {
|
|
@@ -55707,6 +55723,7 @@ const NumberInputCell = ({ cell: cell2, testId }) => {
|
|
|
55707
55723
|
tooltip: cell2.tooltip,
|
|
55708
55724
|
validationCallback: cell2.validationCallback,
|
|
55709
55725
|
allowEmpty: cell2.allowEmpty,
|
|
55726
|
+
enableCosmeticRounding: cell2.enableCosmeticRounding,
|
|
55710
55727
|
enableDisplayRounding: cell2.enableDisplayRounding,
|
|
55711
55728
|
roundDisplayValue: cell2.roundDisplayValue
|
|
55712
55729
|
}
|
|
@@ -70077,45 +70094,6 @@ const getStringName = (name2) => {
|
|
|
70077
70094
|
}
|
|
70078
70095
|
return typeof name2 === "string" ? name2 : "";
|
|
70079
70096
|
};
|
|
70080
|
-
const isErrorObject = (error2) => isObjectLike(error2) && has$1(error2, "message");
|
|
70081
|
-
const getErrorMessage = (error2) => {
|
|
70082
|
-
if (typeof error2 === "string") {
|
|
70083
|
-
return error2;
|
|
70084
|
-
} else if (isErrorObject(error2)) {
|
|
70085
|
-
return error2.message;
|
|
70086
|
-
} else {
|
|
70087
|
-
return null;
|
|
70088
|
-
}
|
|
70089
|
-
};
|
|
70090
|
-
const hasLeadingZeroes = (value) => {
|
|
70091
|
-
return value.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g)) === 0;
|
|
70092
|
-
};
|
|
70093
|
-
const validate = (value, options) => {
|
|
70094
|
-
var _a;
|
|
70095
|
-
const {
|
|
70096
|
-
allowEmpty = false,
|
|
70097
|
-
autoValue,
|
|
70098
|
-
placeholder: placeholder3,
|
|
70099
|
-
disabledValidation = false
|
|
70100
|
-
} = options || {};
|
|
70101
|
-
const stringValue = String(value);
|
|
70102
|
-
if (disabledValidation || autoValue || placeholder3) {
|
|
70103
|
-
return null;
|
|
70104
|
-
}
|
|
70105
|
-
const cleanValue = isValueWithUnit$1(stringValue) ? getValue$1(stringValue) : stringValue;
|
|
70106
|
-
if (allowEmpty && cleanValue === "") {
|
|
70107
|
-
return null;
|
|
70108
|
-
}
|
|
70109
|
-
if (hasLeadingZeroes(cleanValue)) {
|
|
70110
|
-
return "Invalid number format due to leading zeroes";
|
|
70111
|
-
}
|
|
70112
|
-
const validationErrors = validateNumber(cleanValue);
|
|
70113
|
-
if (!validationErrors.valid) {
|
|
70114
|
-
const firstError = ((_a = validationErrors == null ? void 0 : validationErrors.errors) == null ? void 0 : _a[0]) ?? null;
|
|
70115
|
-
return getErrorMessage(firstError);
|
|
70116
|
-
}
|
|
70117
|
-
return null;
|
|
70118
|
-
};
|
|
70119
70097
|
const isUnitKnown = (unit2 = "") => {
|
|
70120
70098
|
var _a;
|
|
70121
70099
|
return (_a = KNOWN_UNITS) == null ? void 0 : _a.includes(unit2);
|
|
@@ -70124,9 +70102,11 @@ const isKnownUnit = (valueWithUnit, defaultUnit) => {
|
|
|
70124
70102
|
const unitFromValue = getUnit(valueWithUnit || "");
|
|
70125
70103
|
return isUnitKnown(defaultUnit) && isUnitKnown(unitFromValue);
|
|
70126
70104
|
};
|
|
70127
|
-
const predefinedMenuActive = "
|
|
70105
|
+
const predefinedMenuActive = "_predefinedMenuActive_ye9w9_1";
|
|
70106
|
+
const inputWrapper = "_inputWrapper_ye9w9_4";
|
|
70128
70107
|
const styles = {
|
|
70129
|
-
predefinedMenuActive
|
|
70108
|
+
predefinedMenuActive,
|
|
70109
|
+
inputWrapper
|
|
70130
70110
|
};
|
|
70131
70111
|
const UnitInput = ({
|
|
70132
70112
|
name: name2,
|
|
@@ -70160,7 +70140,10 @@ const UnitInput = ({
|
|
|
70160
70140
|
validationCallback = () => ({ name: "", error: null }),
|
|
70161
70141
|
disabledValidation = false,
|
|
70162
70142
|
allowEmpty = false,
|
|
70163
|
-
autoValue
|
|
70143
|
+
autoValue,
|
|
70144
|
+
convertBackToStorageUnit = false,
|
|
70145
|
+
enableCosmeticRounding = true,
|
|
70146
|
+
enableDisplayRounding = false
|
|
70164
70147
|
}) => {
|
|
70165
70148
|
if (typeof value === "number") {
|
|
70166
70149
|
value = `${value}`;
|
|
@@ -70189,11 +70172,11 @@ const UnitInput = ({
|
|
|
70189
70172
|
);
|
|
70190
70173
|
const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : convertedAutoValue !== "" ? { value: convertedAutoValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
|
|
70191
70174
|
const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
|
|
70192
|
-
const [validationError, setValidationError] = useState(null);
|
|
70193
70175
|
const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(
|
|
70194
70176
|
initialPredefinedOption ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM
|
|
70195
70177
|
);
|
|
70196
70178
|
const isAutoValue = propValue === "" && autoValue;
|
|
70179
|
+
const disableInternalErrorValidationMessages = !!(disabledValidation || autoValue || placeholder3);
|
|
70197
70180
|
const foundPredefinedMenuOption = predefinedOptions && predefinedOptions.find((el2) => {
|
|
70198
70181
|
if (!(el2 == null ? void 0 : el2.value)) return;
|
|
70199
70182
|
if (selectedPredefinedOptionKey) {
|
|
@@ -70223,33 +70206,16 @@ const UnitInput = ({
|
|
|
70223
70206
|
const stringName2 = getStringName(name2);
|
|
70224
70207
|
const input2 = evt.target;
|
|
70225
70208
|
const { value: inputValue, selectionStart: currentCursorPosition } = input2;
|
|
70226
|
-
const
|
|
70227
|
-
|
|
70228
|
-
|
|
70229
|
-
|
|
70230
|
-
|
|
70231
|
-
|
|
70232
|
-
|
|
70233
|
-
autoValue,
|
|
70234
|
-
placeholder: placeholder3,
|
|
70235
|
-
disabledValidation
|
|
70209
|
+
const newValue = withUnit(inputValue, (displayLayer == null ? void 0 : displayLayer.unit) || "");
|
|
70210
|
+
const returnValue = convertBackToStorageUnit ? withUnit(convertAndGetValue(newValue, propUnit), propUnit) : newValue;
|
|
70211
|
+
onChange({
|
|
70212
|
+
target: {
|
|
70213
|
+
value: returnValue,
|
|
70214
|
+
name: stringName2
|
|
70215
|
+
}
|
|
70236
70216
|
});
|
|
70237
|
-
|
|
70238
|
-
|
|
70239
|
-
target: {
|
|
70240
|
-
value: newValue,
|
|
70241
|
-
name: stringName2
|
|
70242
|
-
}
|
|
70243
|
-
});
|
|
70244
|
-
const [val, u] = split$1(newValue);
|
|
70245
|
-
setDisplayLayer({ value: val, unit: u });
|
|
70246
|
-
setValidationError(null);
|
|
70247
|
-
validationCallback(stringName2, null);
|
|
70248
|
-
} else {
|
|
70249
|
-
setDisplayLayer({ value: cleanInputValue, unit: displayLayer.unit });
|
|
70250
|
-
setValidationError(validationResult);
|
|
70251
|
-
validationCallback(stringName2, validationResult);
|
|
70252
|
-
}
|
|
70217
|
+
const [val, u] = split$1(newValue);
|
|
70218
|
+
setDisplayLayer({ value: val, unit: u });
|
|
70253
70219
|
runAfterUpdate(() => {
|
|
70254
70220
|
input2.selectionStart = currentCursorPosition;
|
|
70255
70221
|
input2.selectionEnd = currentCursorPosition;
|
|
@@ -70295,14 +70261,6 @@ const UnitInput = ({
|
|
|
70295
70261
|
}
|
|
70296
70262
|
}
|
|
70297
70263
|
}
|
|
70298
|
-
const cleanValue = checkAndCleanDecimalComma(propValue);
|
|
70299
|
-
const errorMessage = validate(cleanValue, {
|
|
70300
|
-
allowEmpty,
|
|
70301
|
-
autoValue,
|
|
70302
|
-
placeholder: placeholder3,
|
|
70303
|
-
disabledValidation
|
|
70304
|
-
});
|
|
70305
|
-
setValidationError(errorMessage);
|
|
70306
70264
|
}, [initDisplayUnit, value, error2, shouldLinkAutomaticly]);
|
|
70307
70265
|
const alternativeUnits = getAlternativeUnits();
|
|
70308
70266
|
const displayUnitLabel = label$b(displayLayer.unit) || displayLayer.unit || "";
|
|
@@ -70337,6 +70295,14 @@ const UnitInput = ({
|
|
|
70337
70295
|
selected: foundPredefinedMenuOption === el2 && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
|
|
70338
70296
|
};
|
|
70339
70297
|
};
|
|
70298
|
+
const handleValidationCallback = (name22, error22) => {
|
|
70299
|
+
if (validationCallback) {
|
|
70300
|
+
validationCallback({
|
|
70301
|
+
name: name22,
|
|
70302
|
+
error: error22
|
|
70303
|
+
});
|
|
70304
|
+
}
|
|
70305
|
+
};
|
|
70340
70306
|
sectionsPredefinedMenu = [
|
|
70341
70307
|
{
|
|
70342
70308
|
type: MenuType.OPTION,
|
|
@@ -70393,10 +70359,9 @@ const UnitInput = ({
|
|
|
70393
70359
|
)
|
|
70394
70360
|
}
|
|
70395
70361
|
),
|
|
70396
|
-
/* @__PURE__ */ jsx(
|
|
70397
|
-
|
|
70362
|
+
/* @__PURE__ */ jsx("div", { className: styles.inputWrapper, children: /* @__PURE__ */ jsx(
|
|
70363
|
+
NumberInput,
|
|
70398
70364
|
{
|
|
70399
|
-
type: "text",
|
|
70400
70365
|
name: stringName,
|
|
70401
70366
|
testId,
|
|
70402
70367
|
disabled: disabled2,
|
|
@@ -70409,12 +70374,18 @@ const UnitInput = ({
|
|
|
70409
70374
|
value: displayLayer.value,
|
|
70410
70375
|
onChange: onSetValue,
|
|
70411
70376
|
onFocus,
|
|
70412
|
-
error: error2
|
|
70413
|
-
warning: warning2,
|
|
70414
|
-
|
|
70377
|
+
error: error2 === null ? void 0 : error2,
|
|
70378
|
+
warning: warning2 === null ? void 0 : warning2,
|
|
70379
|
+
left: left2,
|
|
70380
|
+
allowEmpty,
|
|
70381
|
+
validationCallback: handleValidationCallback,
|
|
70382
|
+
enableCosmeticRounding,
|
|
70383
|
+
enableDisplayRounding,
|
|
70384
|
+
groupOrder: predefinedOptions ? "middle" : "first",
|
|
70385
|
+
disableInternalErrorValidationMessages
|
|
70415
70386
|
},
|
|
70416
70387
|
stringName
|
|
70417
|
-
),
|
|
70388
|
+
) }),
|
|
70418
70389
|
displayUnitLabel && (noConvert || !knownUnit ? /* @__PURE__ */ jsx(InputGroupAddon, { groupOrder: "last", children: displayUnitLabel }) : /* @__PURE__ */ jsx(
|
|
70419
70390
|
Menu,
|
|
70420
70391
|
{
|
|
@@ -70428,9 +70399,11 @@ const UnitInput = ({
|
|
|
70428
70399
|
small: small2,
|
|
70429
70400
|
sections: alternativeUnits.map(([value2, altUnit, label2]) => {
|
|
70430
70401
|
const displayUnit = label2 || altUnit || "";
|
|
70402
|
+
const safeValue = !isNaN(Number(value2)) ? value2 : "";
|
|
70403
|
+
const displayValue = enableCosmeticRounding ? roundNumberCosmetic(safeValue) : safeValue;
|
|
70431
70404
|
return {
|
|
70432
70405
|
type: "Option",
|
|
70433
|
-
label:
|
|
70406
|
+
label: displayValue,
|
|
70434
70407
|
inline: true,
|
|
70435
70408
|
onClick: (evt) => {
|
|
70436
70409
|
evt.stopPropagation();
|
|
@@ -70498,22 +70471,12 @@ const convertVisibleRows = ({
|
|
|
70498
70471
|
const storageUnit = storageUnits[unitKey];
|
|
70499
70472
|
const unitChanged = selectedUnit !== storageUnit;
|
|
70500
70473
|
const convertedValue = unitChanged ? convertAndGetValue(value, selectedUnit, storageUnit) : cell2.value;
|
|
70501
|
-
const
|
|
70502
|
-
const displayValue = enableCosmeticRounding && (unitChanged || !isScientific) ? (
|
|
70503
|
-
/*
|
|
70504
|
-
Optionally do Excel-style "cosmetic rounding" of display values (only if enableCosmeticRounding prop on)
|
|
70505
|
-
This means rounding to slightly less precision than the underlying floating-point number type, to
|
|
70506
|
-
resolve floating-point "rounding noise" associated with storing values in one unit but converting
|
|
70507
|
-
and displaying them in another unit. This solution was evaluated by Tools Team in relation to
|
|
70508
|
-
tickets OW-10614 and OW-15745.
|
|
70509
|
-
*/
|
|
70510
|
-
roundToPrecision(convertedValue, 14)
|
|
70511
|
-
) : convertedValue;
|
|
70512
|
-
const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(displayValue) : displayValue;
|
|
70474
|
+
const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(convertedValue) : convertedValue;
|
|
70513
70475
|
return {
|
|
70514
70476
|
...cell2,
|
|
70515
70477
|
value: formattedDisplayValue,
|
|
70516
|
-
enableCosmeticRounding,
|
|
70478
|
+
enableCosmeticRounding: enableCosmeticRounding && unitChanged,
|
|
70479
|
+
//todo: why did we need to check unitChanged here? (original rationale)
|
|
70517
70480
|
enableDisplayRounding,
|
|
70518
70481
|
roundDisplayValue,
|
|
70519
70482
|
onChange: (evt) => {
|