@oliasoft-open-source/react-ui-library 4.10.5 → 4.10.6-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.js +85 -31
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-B_oER2eh.js → Color-KGDBMAHA-D-NQaklH.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-BOKNVKu9.js → DocsRenderer-PKQXORMH-DxOnx1oV.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-C9hhQd51.js → buttons-and-links-CJpVkzrz.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-BfZEBT2B.js → chunk-HLWAVYOI-_rHyaL4V.js} +1 -1
- package/dist/storybook/assets/{color-BHnVca7t.js → color-DRFp7ikN.js} +1 -1
- package/dist/storybook/assets/file-input-B0-ERX66.js +13 -0
- package/dist/storybook/assets/{file-input.stories-CWD5XYE9.js → file-input.stories-Cpd1NHbq.js} +1 -1
- package/dist/storybook/assets/{iframe-b7FGO4kK.js → iframe-C_hdCZCj.js} +2 -2
- package/dist/storybook/assets/{index-DTpGZ2PI.js → index-DJTNHBDs.js} +88 -88
- package/dist/storybook/assets/{index-D0InYQf6.js → index-lKvKvOdk.js} +1 -1
- package/dist/storybook/assets/{input-validation-BpiPuwVL.js → input-validation-DxgmKoPU.js} +1 -1
- package/dist/storybook/assets/{inputs-Cnu7J7Dg.js → inputs-CGEfLq-p.js} +1 -1
- package/dist/storybook/assets/{layout-forms-QYlS6UGn.js → layout-forms-CozlBsFf.js} +1 -1
- package/dist/storybook/assets/{layout-general-DAhM0iBJ.js → layout-general-BVynyHt7.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-DIn5b2MK.js → padding-and-spacing-m7vZCGZE.js} +1 -1
- package/dist/storybook/assets/{preview-CSnr1bcK.js → preview-9AC4uNvp.js} +1 -1
- package/dist/storybook/assets/{preview-D2MA-QXv.js → preview-B4AfZSL8.js} +2 -2
- package/dist/storybook/assets/{smart-upload-modal.stories-Dn7dIsu1.js → smart-upload-modal.stories-xqiXR6jV.js} +1 -1
- package/dist/storybook/assets/{unit-input.stories-CkeTteis.js → unit-input.stories-9b23SnFs.js} +14 -14
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/404.html +0 -1
- package/dist/storybook/assets/file-input-X3BnZaHk.js +0 -13
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, isEqual as isEqual$4 } from "lodash";
|
|
19
|
-
import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, roundToFixed, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, label as label$b, isValidNum, altUnitsList, convertAndGetValue, getUnitsForQuantity, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
|
|
19
|
+
import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, roundToFixed, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, ALT_UNITS, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, label as label$b, isValidNum, getAltUnitsListByQuantity, altUnitsList, convertAndGetValue, 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;
|
|
@@ -70172,13 +70172,41 @@ var PredefinedOptionsMenuState = /* @__PURE__ */ ((PredefinedOptionsMenuState2)
|
|
|
70172
70172
|
const isWrongValue = (val) => {
|
|
70173
70173
|
return val === "undefined" || val === void 0 || val === "" || val === "null" || val === null || val === "NaN" || isNaN(val);
|
|
70174
70174
|
};
|
|
70175
|
-
const
|
|
70175
|
+
const checkConversion = ({
|
|
70176
|
+
value,
|
|
70177
|
+
unitkey,
|
|
70178
|
+
toUnit
|
|
70179
|
+
}) => {
|
|
70180
|
+
var _a2;
|
|
70181
|
+
const availableUnits = ALT_UNITS[unitkey];
|
|
70182
|
+
if (!availableUnits || availableUnits.length === 0) {
|
|
70183
|
+
return false;
|
|
70184
|
+
}
|
|
70185
|
+
if (!((_a2 = validateNumber(value)) == null ? void 0 : _a2.valid)) {
|
|
70186
|
+
return false;
|
|
70187
|
+
}
|
|
70188
|
+
if (!availableUnits.includes(toUnit)) {
|
|
70189
|
+
return false;
|
|
70190
|
+
}
|
|
70191
|
+
return true;
|
|
70192
|
+
};
|
|
70193
|
+
const convertUnit = (stringValue = "", toUnit, unitkey, defaultFromUnit = "", doNotConvertValue = false) => {
|
|
70194
|
+
var _a2;
|
|
70176
70195
|
if (doNotConvertValue) return stringValue;
|
|
70196
|
+
if (!((_a2 = validateNumber(stringValue)) == null ? void 0 : _a2.valid)) return;
|
|
70177
70197
|
if (toUnit && !isWrongValue(stringValue)) {
|
|
70178
70198
|
try {
|
|
70179
70199
|
const valueWithUnit = isValueWithUnit(stringValue) ? stringValue : withUnit(stringValue, defaultFromUnit);
|
|
70180
|
-
const
|
|
70181
|
-
|
|
70200
|
+
const shouldConvert = checkConversion({
|
|
70201
|
+
value: valueWithUnit,
|
|
70202
|
+
toUnit,
|
|
70203
|
+
unitkey
|
|
70204
|
+
});
|
|
70205
|
+
if (shouldConvert) {
|
|
70206
|
+
const result = convertSamePrecision(valueWithUnit, toUnit);
|
|
70207
|
+
return getValue$1(result);
|
|
70208
|
+
}
|
|
70209
|
+
return getValue$1(valueWithUnit);
|
|
70182
70210
|
} catch (e2) {
|
|
70183
70211
|
}
|
|
70184
70212
|
}
|
|
@@ -70187,7 +70215,13 @@ const isValueWithUnknownUnit = (value) => {
|
|
|
70187
70215
|
if (!value) return false;
|
|
70188
70216
|
return Boolean(getUnit(value));
|
|
70189
70217
|
};
|
|
70190
|
-
const safeConvertValue = (
|
|
70218
|
+
const safeConvertValue = ({
|
|
70219
|
+
value = "",
|
|
70220
|
+
toUnit,
|
|
70221
|
+
unitkey,
|
|
70222
|
+
defaultFromUnit,
|
|
70223
|
+
doNotConvertValue
|
|
70224
|
+
}) => {
|
|
70191
70225
|
const isWithUnit = isValueWithUnknownUnit(value) || isValueWithUnit(value);
|
|
70192
70226
|
const rawValue = getValue$1(value);
|
|
70193
70227
|
const isInvalidInput = isWrongValue(rawValue);
|
|
@@ -70197,7 +70231,13 @@ const safeConvertValue = (value = "", toUnit, defaultFromUnit, doNotConvertValue
|
|
|
70197
70231
|
if (!isWithUnit) {
|
|
70198
70232
|
return value;
|
|
70199
70233
|
}
|
|
70200
|
-
return convertUnit(
|
|
70234
|
+
return convertUnit(
|
|
70235
|
+
rawValue,
|
|
70236
|
+
toUnit,
|
|
70237
|
+
unitkey,
|
|
70238
|
+
defaultFromUnit,
|
|
70239
|
+
doNotConvertValue
|
|
70240
|
+
);
|
|
70201
70241
|
};
|
|
70202
70242
|
const getStringName = (name2) => {
|
|
70203
70243
|
if (isObject$5(name2) && !isArray$1(name2) && !isFunction$3(name2)) {
|
|
@@ -70277,18 +70317,20 @@ const UnitInput = ({
|
|
|
70277
70317
|
const knownUnit = isKnownUnit(value, preferredUnit);
|
|
70278
70318
|
const initDisplayUnit = initUnit || preferredUnit || propUnit;
|
|
70279
70319
|
const previousInitUnit = usePrevious(initDisplayUnit);
|
|
70280
|
-
const convertedValue = safeConvertValue(
|
|
70320
|
+
const convertedValue = safeConvertValue({
|
|
70281
70321
|
value,
|
|
70282
|
-
initDisplayUnit,
|
|
70283
|
-
|
|
70322
|
+
toUnit: initDisplayUnit,
|
|
70323
|
+
unitkey,
|
|
70324
|
+
defaultFromUnit: propUnit,
|
|
70284
70325
|
doNotConvertValue
|
|
70285
|
-
);
|
|
70286
|
-
const convertedAutoValue = safeConvertValue(
|
|
70287
|
-
autoValue,
|
|
70288
|
-
initDisplayUnit,
|
|
70289
|
-
|
|
70326
|
+
});
|
|
70327
|
+
const convertedAutoValue = safeConvertValue({
|
|
70328
|
+
value: autoValue,
|
|
70329
|
+
toUnit: initDisplayUnit,
|
|
70330
|
+
unitkey,
|
|
70331
|
+
defaultFromUnit: propAutoUnit,
|
|
70290
70332
|
doNotConvertValue
|
|
70291
|
-
);
|
|
70333
|
+
});
|
|
70292
70334
|
const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : convertedAutoValue !== "" ? { value: convertedAutoValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
|
|
70293
70335
|
const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
|
|
70294
70336
|
const derivedAllowEmpty = (displayLayer == null ? void 0 : displayLayer.value) === void 0;
|
|
@@ -70304,14 +70346,23 @@ const UnitInput = ({
|
|
|
70304
70346
|
}
|
|
70305
70347
|
const predefinedMenuItemUnit = isValueWithUnit(el2.value) ? getUnit(el2.value) : "";
|
|
70306
70348
|
return withUnit(
|
|
70307
|
-
convertUnit(value, predefinedMenuItemUnit),
|
|
70349
|
+
convertUnit(value, predefinedMenuItemUnit, unitkey),
|
|
70308
70350
|
predefinedMenuItemUnit
|
|
70309
70351
|
) === el2.value;
|
|
70310
70352
|
});
|
|
70311
70353
|
const getAlternativeUnits = () => {
|
|
70312
|
-
|
|
70354
|
+
const valueToList = isAutoValue ? autoValue : value ?? "";
|
|
70355
|
+
const initToUnit = displayLayer.unit;
|
|
70356
|
+
const shouldConvert = checkConversion({
|
|
70357
|
+
value: valueToList,
|
|
70358
|
+
unitkey,
|
|
70359
|
+
toUnit: initToUnit
|
|
70360
|
+
});
|
|
70361
|
+
if (!shouldConvert) {
|
|
70362
|
+
let alternativeUnits2 = getAltUnitsListByQuantity(unitkey);
|
|
70363
|
+
return alternativeUnits2 == null ? void 0 : alternativeUnits2.map((unitRow) => ["", unitRow == null ? void 0 : unitRow.unit]);
|
|
70364
|
+
} else if (unitkey) {
|
|
70313
70365
|
try {
|
|
70314
|
-
const valueToList = isAutoValue ? autoValue : value ?? "";
|
|
70315
70366
|
let alternativeUnits2 = altUnitsList(valueToList, unitkey);
|
|
70316
70367
|
if (getValue$1(valueToList) === "") {
|
|
70317
70368
|
return alternativeUnits2.map((unitRow) => ["", unitRow[1]]);
|
|
@@ -70354,20 +70405,22 @@ const UnitInput = ({
|
|
|
70354
70405
|
if (initDisplayUnit) {
|
|
70355
70406
|
let newValue, newUnit = "";
|
|
70356
70407
|
if (previousInitUnit !== initDisplayUnit) {
|
|
70357
|
-
newValue = safeConvertValue(
|
|
70408
|
+
newValue = safeConvertValue({
|
|
70358
70409
|
value,
|
|
70359
|
-
initDisplayUnit,
|
|
70360
|
-
|
|
70410
|
+
toUnit: initDisplayUnit,
|
|
70411
|
+
unitkey,
|
|
70412
|
+
defaultFromUnit: propUnit,
|
|
70361
70413
|
doNotConvertValue
|
|
70362
|
-
);
|
|
70414
|
+
});
|
|
70363
70415
|
newUnit = initDisplayUnit;
|
|
70364
70416
|
} else if (withUnit(displayLayer.value, displayLayer.unit) !== value) {
|
|
70365
|
-
newValue = safeConvertValue(
|
|
70417
|
+
newValue = safeConvertValue({
|
|
70366
70418
|
value,
|
|
70367
|
-
displayLayer.unit,
|
|
70368
|
-
|
|
70419
|
+
toUnit: displayLayer.unit,
|
|
70420
|
+
unitkey,
|
|
70421
|
+
defaultFromUnit: propUnit,
|
|
70369
70422
|
doNotConvertValue
|
|
70370
|
-
);
|
|
70423
|
+
});
|
|
70371
70424
|
newUnit = displayLayer.unit;
|
|
70372
70425
|
}
|
|
70373
70426
|
if (newValue !== void 0) {
|
|
@@ -70477,12 +70530,13 @@ const UnitInput = ({
|
|
|
70477
70530
|
name: stringName,
|
|
70478
70531
|
testId,
|
|
70479
70532
|
disabled: disabled2,
|
|
70480
|
-
placeholder: isAutoValue ? safeConvertValue(
|
|
70481
|
-
autoValue,
|
|
70482
|
-
displayLayer.unit,
|
|
70483
|
-
|
|
70533
|
+
placeholder: isAutoValue ? safeConvertValue({
|
|
70534
|
+
value: autoValue,
|
|
70535
|
+
toUnit: displayLayer.unit,
|
|
70536
|
+
unitkey,
|
|
70537
|
+
defaultFromUnit: propAutoUnit,
|
|
70484
70538
|
doNotConvertValue
|
|
70485
|
-
) : placeholder3,
|
|
70539
|
+
}) : placeholder3,
|
|
70486
70540
|
value: displayLayer.value,
|
|
70487
70541
|
onChange: onSetValue,
|
|
70488
70542
|
onFocus,
|