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