@oliasoft-open-source/react-ui-library 4.14.0 → 4.15.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.
- package/dist/index.d.ts +5 -7
- package/dist/index.js +194 -134
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1047,9 +1047,10 @@ export declare interface IPortalProps {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
1049
|
declare interface IPredefinedOption {
|
|
1050
|
-
value
|
|
1050
|
+
value: string;
|
|
1051
1051
|
label: string;
|
|
1052
1052
|
valueKey?: string;
|
|
1053
|
+
unit?: string;
|
|
1053
1054
|
}
|
|
1054
1055
|
|
|
1055
1056
|
export declare interface IPrintHeaderProps {
|
|
@@ -1569,17 +1570,14 @@ export declare interface IUnitInputProps {
|
|
|
1569
1570
|
unitkey?: string;
|
|
1570
1571
|
initUnit?: string;
|
|
1571
1572
|
noConversion?: boolean;
|
|
1572
|
-
doNotConvertValue?: boolean;
|
|
1573
1573
|
testId?: string;
|
|
1574
1574
|
warning?: string | boolean | null;
|
|
1575
1575
|
predefinedOptions?: IPredefinedOption[] | null;
|
|
1576
|
-
initialPredefinedOption?:
|
|
1577
|
-
|
|
1578
|
-
selectedPredefinedOptionKey?: string;
|
|
1576
|
+
initialPredefinedOption?: string;
|
|
1577
|
+
predefinedOptionLinked?: boolean;
|
|
1579
1578
|
validationCallback?: (name: string, error: string | null) => any;
|
|
1580
1579
|
disabledValidation?: boolean;
|
|
1581
1580
|
allowEmpty?: boolean;
|
|
1582
|
-
autoValue?: string;
|
|
1583
1581
|
onChange?: TOnChangeEventHandler;
|
|
1584
1582
|
onSwitchUnit?: (unit: string) => void;
|
|
1585
1583
|
onClick?: MouseEventHandler<HTMLInputElement>;
|
|
@@ -1886,7 +1884,7 @@ declare type TUnitTableCellShape = TCellShape | IUnitTableStaticCell | IUnitTabl
|
|
|
1886
1884
|
|
|
1887
1885
|
declare type UnitContextType = any;
|
|
1888
1886
|
|
|
1889
|
-
export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate,
|
|
1887
|
+
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, predefinedOptionLinked, validationCallback, disabledValidation, allowEmpty, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, roundDisplayValue, }: IUnitInputProps) => JSX_2.Element;
|
|
1890
1888
|
|
|
1891
1889
|
export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitTableProps) => JSX_2.Element;
|
|
1892
1890
|
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import React__default, { useContext, isValidElement, useState, useRef, useEffect
|
|
|
15
15
|
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
|
-
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";
|
|
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
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) {
|
|
@@ -70249,6 +70249,7 @@ const safeConvertValue = ({
|
|
|
70249
70249
|
}) => {
|
|
70250
70250
|
const rawValue = getValue$1(value);
|
|
70251
70251
|
const isInvalidInput = isWrongValue(rawValue);
|
|
70252
|
+
const availableUnits = ALT_UNITS[unitkey];
|
|
70252
70253
|
if (isValueWithUnknownUnit(value)) {
|
|
70253
70254
|
return { value: rawValue };
|
|
70254
70255
|
}
|
|
@@ -70258,6 +70259,9 @@ const safeConvertValue = ({
|
|
|
70258
70259
|
if (!isValueWithUnit(value)) {
|
|
70259
70260
|
return { value };
|
|
70260
70261
|
}
|
|
70262
|
+
if (!(availableUnits == null ? void 0 : availableUnits.includes(getUnit(value)))) {
|
|
70263
|
+
return { value: rawValue };
|
|
70264
|
+
}
|
|
70261
70265
|
return convertUnit({
|
|
70262
70266
|
value,
|
|
70263
70267
|
unitkey,
|
|
@@ -70292,6 +70296,144 @@ const initializeContext = (context2) => {
|
|
|
70292
70296
|
UnitContext = context2;
|
|
70293
70297
|
}
|
|
70294
70298
|
};
|
|
70299
|
+
const extractValue = (value) => {
|
|
70300
|
+
if (isNil(value)) return value;
|
|
70301
|
+
return isValueWithUnit(value) ? getValue$1(value) : value;
|
|
70302
|
+
};
|
|
70303
|
+
const PredefinedOptionsMenu = ({
|
|
70304
|
+
predefinedOptions,
|
|
70305
|
+
displayLayer,
|
|
70306
|
+
unitkey: rootUnitKey,
|
|
70307
|
+
unitTemplate,
|
|
70308
|
+
onPredefinedOptionSelect,
|
|
70309
|
+
disabled: disabled2,
|
|
70310
|
+
initialPredefinedOption,
|
|
70311
|
+
predefinedOptionLinked,
|
|
70312
|
+
predefinedOptionsMenuState,
|
|
70313
|
+
setPredefinedOptionsMenuState,
|
|
70314
|
+
testId
|
|
70315
|
+
}) => {
|
|
70316
|
+
const extractedValue = extractValue(displayLayer == null ? void 0 : displayLayer.value);
|
|
70317
|
+
const [foundPredefinedMenuOption, setFoundPredefinedMenuOption] = useState(void 0);
|
|
70318
|
+
const convertPredefinedOptions = ({
|
|
70319
|
+
value,
|
|
70320
|
+
unit: optionUnitKey
|
|
70321
|
+
}) => {
|
|
70322
|
+
if (!value || !rootUnitKey) return value;
|
|
70323
|
+
if (!isValueWithUnit(value)) return value;
|
|
70324
|
+
const selectedUnitKey = optionUnitKey || rootUnitKey;
|
|
70325
|
+
const preferredOptionUnit = getPreferredUnit(selectedUnitKey, unitTemplate);
|
|
70326
|
+
const { value: resultValue } = safeConvertValue({
|
|
70327
|
+
value,
|
|
70328
|
+
toUnit: preferredOptionUnit,
|
|
70329
|
+
unitkey: selectedUnitKey,
|
|
70330
|
+
defaultFromUnit: "",
|
|
70331
|
+
doNotConvertValue: false
|
|
70332
|
+
});
|
|
70333
|
+
return withUnit(resultValue, preferredOptionUnit);
|
|
70334
|
+
};
|
|
70335
|
+
const createPredefinedOption = (el2) => {
|
|
70336
|
+
const convertedValue = convertPredefinedOptions(el2);
|
|
70337
|
+
const [inputValue = "", unit2 = ""] = split$1(convertedValue);
|
|
70338
|
+
return {
|
|
70339
|
+
type: MenuType.OPTION,
|
|
70340
|
+
inline: true,
|
|
70341
|
+
onClick: () => {
|
|
70342
|
+
const validation = validateNumber(inputValue);
|
|
70343
|
+
const optionState = {
|
|
70344
|
+
predefinedSelected: true,
|
|
70345
|
+
predefinedOption: el2
|
|
70346
|
+
};
|
|
70347
|
+
if (validation.valid && !disabled2) {
|
|
70348
|
+
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
|
|
70349
|
+
onPredefinedOptionSelect(convertedValue, optionState);
|
|
70350
|
+
setFoundPredefinedMenuOption(el2);
|
|
70351
|
+
}
|
|
70352
|
+
},
|
|
70353
|
+
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
70354
|
+
/* @__PURE__ */ jsx(Text, { children: el2.label }),
|
|
70355
|
+
/* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
|
|
70356
|
+
] }),
|
|
70357
|
+
description: `${inputValue} ${unit2}`,
|
|
70358
|
+
selected: isEqual$4(foundPredefinedMenuOption, el2) && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
|
|
70359
|
+
};
|
|
70360
|
+
};
|
|
70361
|
+
const initialPredefinedOptionObject = useMemo$1(() => {
|
|
70362
|
+
return predefinedOptions.find(
|
|
70363
|
+
(option2) => [option2.value, option2.label, option2.valueKey].includes(
|
|
70364
|
+
initialPredefinedOption
|
|
70365
|
+
)
|
|
70366
|
+
);
|
|
70367
|
+
}, [initialPredefinedOption, predefinedOptionLinked]);
|
|
70368
|
+
useEffect(() => {
|
|
70369
|
+
if (initialPredefinedOptionObject) {
|
|
70370
|
+
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
|
|
70371
|
+
setFoundPredefinedMenuOption(initialPredefinedOptionObject);
|
|
70372
|
+
if (predefinedOptionLinked) {
|
|
70373
|
+
onPredefinedOptionSelect(initialPredefinedOptionObject.value, {
|
|
70374
|
+
predefinedSelected: true,
|
|
70375
|
+
predefinedOption: initialPredefinedOptionObject
|
|
70376
|
+
});
|
|
70377
|
+
}
|
|
70378
|
+
}
|
|
70379
|
+
}, [
|
|
70380
|
+
initialPredefinedOptionObject == null ? void 0 : initialPredefinedOptionObject.value,
|
|
70381
|
+
initialPredefinedOptionObject == null ? void 0 : initialPredefinedOptionObject.label
|
|
70382
|
+
]);
|
|
70383
|
+
useEffect(() => {
|
|
70384
|
+
const foundOption = predefinedOptionLinked && predefinedOptions.find((option2) => {
|
|
70385
|
+
const convertedValue = convertPredefinedOptions(option2);
|
|
70386
|
+
return convertedValue === withUnit(displayLayer == null ? void 0 : displayLayer.value, (displayLayer == null ? void 0 : displayLayer.unit) ?? "");
|
|
70387
|
+
});
|
|
70388
|
+
if (foundOption || initialPredefinedOptionObject) {
|
|
70389
|
+
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
|
|
70390
|
+
setFoundPredefinedMenuOption(
|
|
70391
|
+
foundOption || initialPredefinedOptionObject
|
|
70392
|
+
);
|
|
70393
|
+
} else {
|
|
70394
|
+
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
|
|
70395
|
+
setFoundPredefinedMenuOption(void 0);
|
|
70396
|
+
}
|
|
70397
|
+
}, [extractedValue, predefinedOptionLinked]);
|
|
70398
|
+
const sectionsPredefinedMenu = [
|
|
70399
|
+
{
|
|
70400
|
+
type: MenuType.OPTION,
|
|
70401
|
+
inline: true,
|
|
70402
|
+
onClick: () => {
|
|
70403
|
+
if (!disabled2) {
|
|
70404
|
+
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
|
|
70405
|
+
}
|
|
70406
|
+
},
|
|
70407
|
+
label: "Custom",
|
|
70408
|
+
selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
|
|
70409
|
+
},
|
|
70410
|
+
...predefinedOptions.map(createPredefinedOption)
|
|
70411
|
+
];
|
|
70412
|
+
return /* @__PURE__ */ jsx(
|
|
70413
|
+
Menu,
|
|
70414
|
+
{
|
|
70415
|
+
testId: testId && `${testId}-predefined-menu`,
|
|
70416
|
+
maxHeight: 380,
|
|
70417
|
+
groupOrder: "first",
|
|
70418
|
+
disabled: disabled2,
|
|
70419
|
+
menu: {
|
|
70420
|
+
colored: true,
|
|
70421
|
+
trigger: "Component",
|
|
70422
|
+
component: /* @__PURE__ */ jsx(
|
|
70423
|
+
Button$1,
|
|
70424
|
+
{
|
|
70425
|
+
groupOrder: "first",
|
|
70426
|
+
active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
|
|
70427
|
+
icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
|
|
70428
|
+
}
|
|
70429
|
+
),
|
|
70430
|
+
small: true,
|
|
70431
|
+
sections: sectionsPredefinedMenu
|
|
70432
|
+
},
|
|
70433
|
+
tooltip: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : ""
|
|
70434
|
+
}
|
|
70435
|
+
);
|
|
70436
|
+
};
|
|
70295
70437
|
const predefinedMenuActive = "_predefinedMenuActive_ye9w9_1";
|
|
70296
70438
|
const inputWrapper = "_inputWrapper_ye9w9_4";
|
|
70297
70439
|
const styles = {
|
|
@@ -70316,17 +70458,14 @@ const UnitInput = ({
|
|
|
70316
70458
|
onFocus = noop$3,
|
|
70317
70459
|
onSwitchUnit = noop$3,
|
|
70318
70460
|
unitTemplate,
|
|
70319
|
-
doNotConvertValue = false,
|
|
70320
70461
|
testId,
|
|
70321
70462
|
warning: warning2 = null,
|
|
70322
70463
|
predefinedOptions,
|
|
70323
|
-
initialPredefinedOption =
|
|
70324
|
-
|
|
70325
|
-
selectedPredefinedOptionKey,
|
|
70464
|
+
initialPredefinedOption = "",
|
|
70465
|
+
predefinedOptionLinked = true,
|
|
70326
70466
|
validationCallback = () => ({ name: "", error: null }),
|
|
70327
70467
|
disabledValidation = false,
|
|
70328
70468
|
allowEmpty = false,
|
|
70329
|
-
autoValue,
|
|
70330
70469
|
convertBackToStorageUnit = false,
|
|
70331
70470
|
enableCosmeticRounding = true,
|
|
70332
70471
|
enableDisplayRounding = false,
|
|
@@ -70334,11 +70473,11 @@ const UnitInput = ({
|
|
|
70334
70473
|
}) => {
|
|
70335
70474
|
const context2 = useUnitContext();
|
|
70336
70475
|
const runAfterUpdate = useRunAfterUpdate();
|
|
70476
|
+
const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(PredefinedOptionsMenuState.CUSTOM);
|
|
70337
70477
|
if (typeof value === "number") {
|
|
70338
70478
|
value = `${value}`;
|
|
70339
70479
|
}
|
|
70340
70480
|
const [propValue = "", propUnit = ""] = value !== void 0 ? split$1(value) : [];
|
|
70341
|
-
const propAutoUnit = autoValue ? getUnit(autoValue) : "";
|
|
70342
70481
|
const preferredUnit = useMemo$1(
|
|
70343
70482
|
() => getPreferredUnit(unitkey, unitTemplate || (context2 == null ? void 0 : context2.unitTemplate)),
|
|
70344
70483
|
[unitkey, unitTemplate, context2 == null ? void 0 : context2.unitTemplate]
|
|
@@ -70351,39 +70490,15 @@ const UnitInput = ({
|
|
|
70351
70490
|
toUnit: initDisplayUnit,
|
|
70352
70491
|
unitkey,
|
|
70353
70492
|
defaultFromUnit: propUnit,
|
|
70354
|
-
doNotConvertValue
|
|
70355
|
-
});
|
|
70356
|
-
const { value: convertedAutoValue } = safeConvertValue({
|
|
70357
|
-
value: autoValue,
|
|
70358
|
-
toUnit: initDisplayUnit,
|
|
70359
|
-
unitkey,
|
|
70360
|
-
defaultFromUnit: propAutoUnit,
|
|
70361
|
-
doNotConvertValue
|
|
70493
|
+
doNotConvertValue: noConversion
|
|
70362
70494
|
});
|
|
70363
|
-
const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } :
|
|
70495
|
+
const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
|
|
70364
70496
|
const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
|
|
70365
70497
|
const derivedAllowEmpty = allowEmpty || (displayLayer == null ? void 0 : displayLayer.value) === void 0;
|
|
70366
|
-
const
|
|
70367
|
-
initialPredefinedOption ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM
|
|
70368
|
-
);
|
|
70369
|
-
const isAutoValue = propValue === "" && autoValue;
|
|
70370
|
-
const disableInternalErrorValidationMessages = !!(disabledValidation || autoValue || disabled2);
|
|
70371
|
-
const foundPredefinedMenuOption = predefinedOptions && predefinedOptions.find((el2) => {
|
|
70372
|
-
if (!(el2 == null ? void 0 : el2.value)) return;
|
|
70373
|
-
if (selectedPredefinedOptionKey) {
|
|
70374
|
-
return selectedPredefinedOptionKey === el2.valueKey;
|
|
70375
|
-
}
|
|
70376
|
-
const predefinedMenuItemUnit = isValueWithUnit(el2.value) ? getUnit(el2.value) : "";
|
|
70377
|
-
const { value: resultValue = value } = convertUnit({
|
|
70378
|
-
value: String(value),
|
|
70379
|
-
unitkey,
|
|
70380
|
-
toUnit: predefinedMenuItemUnit
|
|
70381
|
-
});
|
|
70382
|
-
return withUnit(resultValue, predefinedMenuItemUnit) === el2.value;
|
|
70383
|
-
});
|
|
70498
|
+
const disableInternalErrorValidationMessages = !!disabledValidation || disabled2;
|
|
70384
70499
|
const getAlternativeUnits = () => {
|
|
70385
|
-
const valueToList =
|
|
70386
|
-
const initToUnit = displayLayer.unit;
|
|
70500
|
+
const valueToList = value ?? "";
|
|
70501
|
+
const initToUnit = displayLayer == null ? void 0 : displayLayer.unit;
|
|
70387
70502
|
const shouldConvert = checkConversion({
|
|
70388
70503
|
value: valueToList,
|
|
70389
70504
|
unitkey,
|
|
@@ -70441,7 +70556,7 @@ const UnitInput = ({
|
|
|
70441
70556
|
toUnit: initDisplayUnit,
|
|
70442
70557
|
unitkey,
|
|
70443
70558
|
defaultFromUnit: propUnit,
|
|
70444
|
-
doNotConvertValue
|
|
70559
|
+
doNotConvertValue: noConversion
|
|
70445
70560
|
});
|
|
70446
70561
|
newValue = resultValue;
|
|
70447
70562
|
newUnit = initDisplayUnit;
|
|
@@ -70451,96 +70566,29 @@ const UnitInput = ({
|
|
|
70451
70566
|
toUnit: displayLayer.unit,
|
|
70452
70567
|
unitkey,
|
|
70453
70568
|
defaultFromUnit: propUnit,
|
|
70454
|
-
doNotConvertValue
|
|
70569
|
+
doNotConvertValue: noConversion
|
|
70455
70570
|
});
|
|
70456
70571
|
newValue = resultValue;
|
|
70457
70572
|
newUnit = displayLayer.unit;
|
|
70458
70573
|
}
|
|
70459
|
-
if (newValue !== void 0) {
|
|
70574
|
+
if (newValue !== void 0 && !(initialPredefinedOption && !predefinedOptionLinked)) {
|
|
70460
70575
|
setDisplayLayer({ value: newValue, unit: newUnit });
|
|
70461
70576
|
}
|
|
70462
|
-
if (predefinedOptions) {
|
|
70463
|
-
if (foundPredefinedMenuOption && shouldLinkAutomaticly) {
|
|
70464
|
-
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
|
|
70465
|
-
} else {
|
|
70466
|
-
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
|
|
70467
|
-
}
|
|
70468
|
-
}
|
|
70469
70577
|
}
|
|
70470
|
-
}, [initDisplayUnit, value, error2
|
|
70578
|
+
}, [initDisplayUnit, value, error2]);
|
|
70471
70579
|
const alternativeUnits = getAlternativeUnits();
|
|
70472
70580
|
const displayUnitLabel = label$b(displayLayer.unit) || displayLayer.unit || "";
|
|
70473
70581
|
const noConvert = noConversion || !alternativeUnits || alternativeUnits && alternativeUnits.length === 1;
|
|
70474
70582
|
const stringName = getStringName(name2);
|
|
70475
|
-
let sectionsPredefinedMenu;
|
|
70476
|
-
const createPredefinedOption = (el2) => {
|
|
70477
|
-
const elementValue = (el2 == null ? void 0 : el2.value) ? el2.value : "";
|
|
70478
|
-
const [value2 = "", unit2 = ""] = isValueWithUnit(elementValue) ? split$1(elementValue) : [elementValue];
|
|
70479
|
-
return {
|
|
70480
|
-
type: MenuType.OPTION,
|
|
70481
|
-
inline: true,
|
|
70482
|
-
onClick: () => {
|
|
70483
|
-
const validation = validateNumber(value2);
|
|
70484
|
-
if (validation.valid && !disabled2) {
|
|
70485
|
-
setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
|
|
70486
|
-
onChange({
|
|
70487
|
-
target: {
|
|
70488
|
-
value: elementValue,
|
|
70489
|
-
name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || "",
|
|
70490
|
-
predefinedSelected: true,
|
|
70491
|
-
predefinedOption: el2
|
|
70492
|
-
}
|
|
70493
|
-
});
|
|
70494
|
-
}
|
|
70495
|
-
},
|
|
70496
|
-
label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
70497
|
-
/* @__PURE__ */ jsx(Text, { children: el2.label }),
|
|
70498
|
-
/* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
|
|
70499
|
-
] }),
|
|
70500
|
-
description: isValueWithUnit(elementValue) ? `${value2} ${unit2}` : elementValue,
|
|
70501
|
-
selected: foundPredefinedMenuOption === el2 && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
|
|
70502
|
-
};
|
|
70503
|
-
};
|
|
70504
|
-
sectionsPredefinedMenu = [
|
|
70505
|
-
{
|
|
70506
|
-
type: MenuType.OPTION,
|
|
70507
|
-
inline: true,
|
|
70508
|
-
onClick: () => {
|
|
70509
|
-
if (predefinedOptionsMenuState !== PredefinedOptionsMenuState.CUSTOM && !disabled2) {
|
|
70510
|
-
onChange({
|
|
70511
|
-
target: {
|
|
70512
|
-
value: withUnit(displayLayer.value, displayLayer.unit),
|
|
70513
|
-
name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || ""
|
|
70514
|
-
}
|
|
70515
|
-
});
|
|
70516
|
-
}
|
|
70517
|
-
},
|
|
70518
|
-
label: "Custom",
|
|
70519
|
-
selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
|
|
70520
|
-
}
|
|
70521
|
-
];
|
|
70522
|
-
if (predefinedOptions == null ? void 0 : predefinedOptions.length) {
|
|
70523
|
-
const dynamicOptions = predefinedOptions.map(createPredefinedOption);
|
|
70524
|
-
sectionsPredefinedMenu = [...sectionsPredefinedMenu, ...dynamicOptions];
|
|
70525
|
-
}
|
|
70526
70583
|
const getPlaceholder = (placeholder22) => {
|
|
70527
|
-
if (
|
|
70528
|
-
const { value: resultValue } = safeConvertValue({
|
|
70529
|
-
value: autoValue,
|
|
70530
|
-
toUnit: displayLayer.unit,
|
|
70531
|
-
unitkey,
|
|
70532
|
-
defaultFromUnit: propAutoUnit,
|
|
70533
|
-
doNotConvertValue
|
|
70534
|
-
});
|
|
70535
|
-
return resultValue;
|
|
70536
|
-
} else if (isValueWithUnit(placeholder22)) {
|
|
70584
|
+
if (isValueWithUnit(placeholder22)) {
|
|
70537
70585
|
const placeholderUnit = getUnit(placeholder22);
|
|
70538
70586
|
const { value: resultValue } = safeConvertValue({
|
|
70539
70587
|
value: placeholder22,
|
|
70540
70588
|
toUnit: displayLayer.unit,
|
|
70541
70589
|
unitkey,
|
|
70542
70590
|
defaultFromUnit: placeholderUnit,
|
|
70543
|
-
doNotConvertValue
|
|
70591
|
+
doNotConvertValue: noConversion
|
|
70544
70592
|
});
|
|
70545
70593
|
return resultValue;
|
|
70546
70594
|
}
|
|
@@ -70552,32 +70600,44 @@ const UnitInput = ({
|
|
|
70552
70600
|
className: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? cx$2(styles.predefinedMenuActive) : "",
|
|
70553
70601
|
children: /* @__PURE__ */ jsxs(InputGroup, { small: small2, width: width2, children: [
|
|
70554
70602
|
predefinedOptions && /* @__PURE__ */ jsx(
|
|
70555
|
-
|
|
70603
|
+
PredefinedOptionsMenu,
|
|
70556
70604
|
{
|
|
70557
|
-
|
|
70558
|
-
|
|
70559
|
-
|
|
70560
|
-
|
|
70561
|
-
|
|
70562
|
-
|
|
70563
|
-
|
|
70564
|
-
|
|
70565
|
-
|
|
70566
|
-
|
|
70567
|
-
|
|
70568
|
-
|
|
70569
|
-
|
|
70570
|
-
|
|
70571
|
-
|
|
70572
|
-
|
|
70573
|
-
|
|
70574
|
-
|
|
70575
|
-
|
|
70576
|
-
|
|
70577
|
-
|
|
70578
|
-
|
|
70605
|
+
testId,
|
|
70606
|
+
unitTemplate: unitTemplate || (context2 == null ? void 0 : context2.unitTemplate),
|
|
70607
|
+
unitkey,
|
|
70608
|
+
predefinedOptions,
|
|
70609
|
+
displayLayer,
|
|
70610
|
+
onPredefinedOptionSelect: (newValue, optionState) => {
|
|
70611
|
+
var _a2;
|
|
70612
|
+
if (predefinedOptionLinked && ((_a2 = optionState == null ? void 0 : optionState.predefinedOption) == null ? void 0 : _a2.unit)) {
|
|
70613
|
+
onChange({
|
|
70614
|
+
target: {
|
|
70615
|
+
value: withUnit(displayLayer == null ? void 0 : displayLayer.value, displayLayer == null ? void 0 : displayLayer.unit),
|
|
70616
|
+
name: stringName,
|
|
70617
|
+
predefinedSelected: optionState == null ? void 0 : optionState.predefinedSelected,
|
|
70618
|
+
predefinedOption: optionState == null ? void 0 : optionState.predefinedOption
|
|
70619
|
+
}
|
|
70620
|
+
});
|
|
70621
|
+
} else {
|
|
70622
|
+
onChange({
|
|
70623
|
+
target: {
|
|
70624
|
+
value: newValue,
|
|
70625
|
+
name: stringName,
|
|
70626
|
+
predefinedSelected: optionState == null ? void 0 : optionState.predefinedSelected,
|
|
70627
|
+
predefinedOption: optionState == null ? void 0 : optionState.predefinedOption
|
|
70628
|
+
}
|
|
70629
|
+
});
|
|
70630
|
+
setDisplayLayer({
|
|
70631
|
+
value: newValue,
|
|
70632
|
+
unit: getUnit(newValue) || displayLayer.unit
|
|
70633
|
+
});
|
|
70579
70634
|
}
|
|
70580
|
-
|
|
70635
|
+
},
|
|
70636
|
+
disabled: disabled2,
|
|
70637
|
+
initialPredefinedOption,
|
|
70638
|
+
predefinedOptionLinked,
|
|
70639
|
+
predefinedOptionsMenuState,
|
|
70640
|
+
setPredefinedOptionsMenuState
|
|
70581
70641
|
}
|
|
70582
70642
|
),
|
|
70583
70643
|
/* @__PURE__ */ jsx("div", { className: styles.inputWrapper, children: /* @__PURE__ */ jsx(
|
|
@@ -70625,7 +70685,7 @@ const UnitInput = ({
|
|
|
70625
70685
|
inline: true,
|
|
70626
70686
|
onClick: (evt) => {
|
|
70627
70687
|
evt.stopPropagation();
|
|
70628
|
-
onClickUnit(
|
|
70688
|
+
onClickUnit(value2, altUnit);
|
|
70629
70689
|
},
|
|
70630
70690
|
description: displayUnit,
|
|
70631
70691
|
selected: displayUnit === displayUnitLabel,
|