@oliasoft-open-source/react-ui-library 4.11.0-beta-3 → 4.12.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.
Files changed (166) hide show
  1. package/dist/assets/{index-BpSdrNXy.css → index-BU9wzZv9.css} +336 -336
  2. package/dist/assets/{index-DoFa61ar.js → index-BVCFmQTa.js} +144 -164
  3. package/dist/index.d.ts +2 -6
  4. package/dist/index.html +1 -1
  5. package/dist/index.js +190 -181
  6. package/dist/index.js.map +1 -1
  7. package/dist/storybook/assets/{Color-KGDBMAHA-DeGjmgTY.js → Color-KGDBMAHA-CK3d59Om.js} +1 -1
  8. package/dist/storybook/assets/{DocsRenderer-PKQXORMH-DJIj_qEG.js → DocsRenderer-PKQXORMH-C_QE44cn.js} +1 -1
  9. package/dist/storybook/assets/{accordion.stories-BTxV-ybU.js → accordion.stories-C3VY77Jy.js} +2 -2
  10. package/dist/storybook/assets/{actions-D-uVCDzk.js → actions-Bax0KeqM.js} +2 -2
  11. package/dist/storybook/assets/{actions.stories-gKfuiKQy.js → actions.stories-BnPZKqOJ.js} +1 -1
  12. package/dist/storybook/assets/{afe.stories-DFQsvqIV.js → afe.stories-C9XjJj62.js} +2 -2
  13. package/dist/storybook/assets/{badge.stories-Dkq_XgEW.js → badge.stories-DA_eeQyi.js} +1 -1
  14. package/dist/storybook/assets/{blowout.stories-DHdofVc-.js → blowout.stories-DH-sYHgB.js} +1 -1
  15. package/dist/storybook/assets/button-Cbv7WK6k.js +1 -0
  16. package/dist/storybook/assets/button-DtgxLQCF.css +1 -0
  17. package/dist/storybook/assets/{button-group-1DEZPmxq.js → button-group-D2fGP_bX.js} +1 -1
  18. package/dist/storybook/assets/{button-group.stories-C4V1k0z_.js → button-group.stories-BETADGti.js} +1 -1
  19. package/dist/storybook/assets/{button.stories-DA9DGYD2.js → button.stories-C03VvX8K.js} +1 -1
  20. package/dist/storybook/assets/{buttons-and-links-BHGzZGPV.js → buttons-and-links-FQEbqz9H.js} +1 -1
  21. package/dist/storybook/assets/{casing-loads.stories-CJpnsmsZ.js → casing-loads.stories-B7JIoJVk.js} +2 -2
  22. package/dist/storybook/assets/{cell.stories-Bpl0Squh.js → cell.stories-xZiHEc0P.js} +2 -2
  23. package/dist/storybook/assets/check-box.stories-BJ0ShmeC.js +97 -0
  24. package/dist/storybook/assets/check-box.test-case.stories-CzuYZkUh.js +30 -0
  25. package/dist/storybook/assets/{chunk-HLWAVYOI-D2p4xoma.js → chunk-HLWAVYOI-EhWEisNT.js} +1 -1
  26. package/dist/storybook/assets/{color-D9KYOiNh.js → color-B3dajHjs.js} +1 -1
  27. package/dist/storybook/assets/{dialog-BelCA1mt.js → dialog-DkpQscuI.js} +1 -1
  28. package/dist/storybook/assets/drawer-BVc1xI9q.css +1 -0
  29. package/dist/storybook/assets/drawer-DaQ1xGjV.js +3 -0
  30. package/dist/storybook/assets/{drawer.stories-DcjyDHEs.js → drawer.stories-C08XBVTq.js} +1 -1
  31. package/dist/storybook/assets/{empty.stories-DcwF0pkK.js → empty.stories-L7LSMcLe.js} +1 -1
  32. package/dist/storybook/assets/enum-Bnn40S8Q.js +1 -0
  33. package/dist/storybook/assets/{field.stories-DUGMwi1O.js → field.stories-CYpQ669-.js} +1 -1
  34. package/dist/storybook/assets/{file-button.stories-CU2pZcEO.js → file-button.stories-CRaTdLfv.js} +1 -1
  35. package/dist/storybook/assets/{file-input-B0-ERX66.js → file-input-yalPf7-m.js} +1 -1
  36. package/dist/storybook/assets/{file-input.stories-Cpd1NHbq.js → file-input.stories-DMTQqAF8.js} +1 -1
  37. package/dist/storybook/assets/{flex.stories-BhvJpHpN.js → flex.stories-CLwPyEMp.js} +1 -1
  38. package/dist/storybook/assets/footer.stories-BxzKeFAK.js +3 -0
  39. package/dist/storybook/assets/form.stories-BNORsn6Z.js +49 -0
  40. package/dist/storybook/assets/formation.stories-C5Hkb3iK.js +74 -0
  41. package/dist/storybook/assets/helpers-JJxzGegQ.js +1 -0
  42. package/dist/storybook/assets/iframe-DOUoMheZ.js +2 -0
  43. package/dist/storybook/assets/{index-C0Iaso0O.js → index-AKsHS-dO.js} +4 -4
  44. package/dist/storybook/assets/{index-CNkaN_wz.js → index-KVAIZqzA.js} +1 -1
  45. package/dist/storybook/assets/initialize-context-rEvM6bdZ.js +1 -0
  46. package/dist/storybook/assets/input-Db9WkmPP.js +1 -0
  47. package/dist/storybook/assets/input-Dz1ZZYN5.css +1 -0
  48. package/dist/storybook/assets/{input-group.stories-CElwRt3p.js → input-group.stories-BCajsqAk.js} +3 -3
  49. package/dist/storybook/assets/{input-validation-Ccgprl1C.js → input-validation-BNoUk3q6.js} +2 -2
  50. package/dist/storybook/assets/{input.stories-FKl0qVhm.js → input.stories-SJy3TKkD.js} +1 -1
  51. package/dist/storybook/assets/{inputs-DtQ245kS.js → inputs-Dql6Fq32.js} +2 -2
  52. package/dist/storybook/assets/{layout-forms-Bm7FYA3V.js → layout-forms-DuFo_rwV.js} +5 -5
  53. package/dist/storybook/assets/{layout-general-V7ekuEG7.js → layout-general-C-UddRr1.js} +1 -1
  54. package/dist/storybook/assets/{list-bKpz6I9Q.js → list-By3wp5Wa.js} +1 -1
  55. package/dist/storybook/assets/{list.stories-Cgmt29Wv.js → list.stories-BcDHHHYJ.js} +1 -1
  56. package/dist/storybook/assets/{list.stories-data-D_Aj3AN4.js → list.stories-data-Doo2Rqun.js} +1 -1
  57. package/dist/storybook/assets/{loader.stories-pS8zRM4u.js → loader.stories-Q0U2BqZX.js} +1 -1
  58. package/dist/storybook/assets/menu.stories-1I5AGGQx.js +82 -0
  59. package/dist/storybook/assets/menu.test-case.stories-BFYhvtSH.js +3 -0
  60. package/dist/storybook/assets/message-BRyKdRaX.js +1 -0
  61. package/dist/storybook/assets/message-C2ZCkHX6.css +1 -0
  62. package/dist/storybook/assets/{message.stories-r_UlbshI.js → message.stories-bCqCYIuN.js} +1 -1
  63. package/dist/storybook/assets/meta-content-ByVTG0hd.css +1 -0
  64. package/dist/storybook/assets/meta-content-DNgQbAW0.js +9 -0
  65. package/dist/storybook/assets/modal.stories-C2d-Em5V.js +200 -0
  66. package/dist/storybook/assets/modal.test-case.stories-H8AYyvAl.js +21 -0
  67. package/dist/storybook/assets/{number-input-Bpg4Yqmo.js → number-input-CNnU6gOF.js} +2 -2
  68. package/dist/storybook/assets/number-input.stories-Bo26PJmJ.js +89 -0
  69. package/dist/storybook/assets/number-input.test-case.stories-BBKpBWfA.js +92 -0
  70. package/dist/storybook/assets/{option-dropdown.stories-CIvqMhQ3.js → option-dropdown.stories-CznUbXVi.js} +1 -1
  71. package/dist/storybook/assets/{padding-and-spacing-IKi7rvQ-.js → padding-and-spacing-B9ObVTUS.js} +1 -1
  72. package/dist/storybook/assets/{page.stories-DnCh8h8y.js → page.stories-DthnK8qb.js} +1 -1
  73. package/dist/storybook/assets/{pagination-CLt-kUlx.js → pagination-CR1nxnnq.js} +1 -1
  74. package/dist/storybook/assets/{pagination.stories-CTRM0Xou.js → pagination.stories-qXmBYwYc.js} +2 -2
  75. package/dist/storybook/assets/{pop-confirm.stories-DCpooB2O.js → pop-confirm.stories-CHa0qUBe.js} +1 -1
  76. package/dist/storybook/assets/{popover-rq33c1W2.js → popover-C_2P8LFJ.js} +1 -1
  77. package/dist/storybook/assets/popover.stories-DZTfimDf.js +10 -0
  78. package/dist/storybook/assets/{preview-ZgLLfBPl.js → preview-_21fnvwa.js} +2 -2
  79. package/dist/storybook/assets/{preview-CtQzjqBP.js → preview-dBqj-M8_.js} +1 -1
  80. package/dist/storybook/assets/projects.stories-BPm6ucAe.js +47 -0
  81. package/dist/storybook/assets/{radio-button-DmDuw4DA.js → radio-button-C4ljBRED.js} +1 -1
  82. package/dist/storybook/assets/radio-button.stories-D1rWr6ms.js +61 -0
  83. package/dist/storybook/assets/radio-button.test-case.stories-DglmHlWs.js +11 -0
  84. package/dist/storybook/assets/{reservoirs.stories-B12tIrmZ.js → reservoirs.stories-r1Ip90kJ.js} +2 -2
  85. package/dist/storybook/assets/{rich-text-input-dDjxXFl-.css → rich-text-input-BJfL0Me_.css} +1 -1
  86. package/dist/storybook/assets/{rich-text-input.stories-DkaOBgbE.js → rich-text-input.stories-DwaseXZv.js} +3 -3
  87. package/dist/storybook/assets/{row.stories-msEoNdGI.js → row.stories-BrPMTnKK.js} +2 -2
  88. package/dist/storybook/assets/select-BmYXTl_0.css +1 -0
  89. package/dist/storybook/assets/select-Cwks-WA0.js +61 -0
  90. package/dist/storybook/assets/select.input-CJed_LLR.js +1 -0
  91. package/dist/storybook/assets/select.stories-DjGSNDXK.js +498 -0
  92. package/dist/storybook/assets/select.stories-data-DxgWKlU6.js +1 -0
  93. package/dist/storybook/assets/select.test-case.stories-B6On-PjA.js +82 -0
  94. package/dist/storybook/assets/side-bar-fBbBqyAT.css +1 -0
  95. package/dist/storybook/assets/side-bar-wpFQ5NEE.js +24 -0
  96. package/dist/storybook/assets/{side-bar.stories-M6FsuCrQ.js → side-bar.stories-LjClxJcG.js} +1 -1
  97. package/dist/storybook/assets/{site.stories-umpPYjkq.js → site.stories-BnWmALGd.js} +2 -2
  98. package/dist/storybook/assets/{slider-C7vnj_3M.js → slider-CcpE4BLD.js} +1 -1
  99. package/dist/storybook/assets/{slider.stories-BzBb3PkP.js → slider.stories-BqlRLY_C.js} +1 -1
  100. package/dist/storybook/assets/{smart-upload-modal.stories-xqiXR6jV.js → smart-upload-modal.stories-BlTSF64K.js} +1 -1
  101. package/dist/storybook/assets/{spacer.stories-BBTt2LdE.js → spacer.stories-BT2S6B0R.js} +1 -1
  102. package/dist/storybook/assets/table-BtBtDwPu.css +1 -0
  103. package/dist/storybook/assets/table-iVsvoMpy.js +86 -0
  104. package/dist/storybook/assets/{table.stories-Clltxls0.js → table.stories-DmGMjcFw.js} +2 -2
  105. package/dist/storybook/assets/{table.stories-data-C3vJedB1.js → table.stories-data-C7mC5R8Q.js} +1 -1
  106. package/dist/storybook/assets/{tabs-C3NG6m9W.js → tabs-BoToLVEP.js} +1 -1
  107. package/dist/storybook/assets/tabs.stories-B52iEaHf.js +30 -0
  108. package/dist/storybook/assets/{textarea-D6ltcKhz.js → textarea-DflOOrxV.js} +2 -2
  109. package/dist/storybook/assets/textarea-TqxidmV4.css +1 -0
  110. package/dist/storybook/assets/{textarea.stories-CJ-Oqytp.js → textarea.stories-CzsqRVpC.js} +1 -1
  111. package/dist/storybook/assets/{title.stories-CsrYTGde.js → title.stories-D2LDNgbT.js} +3 -3
  112. package/dist/storybook/assets/{toaster-BoBcvmf9.js → toaster-O8ftrUAJ.js} +1 -1
  113. package/dist/storybook/assets/toaster.stories-CdpwLBSo.js +84 -0
  114. package/dist/storybook/assets/toaster.test-case.stories-BhWnh4Cd.js +6 -0
  115. package/dist/storybook/assets/toggle.stories-BAislK3I.js +106 -0
  116. package/dist/storybook/assets/toggle.test-case.stories-CeUwdhGD.js +36 -0
  117. package/dist/storybook/assets/{tooltip.test-case.stories-CHibN8rC.js → tooltip.test-case.stories-De9h8ThH.js} +1 -1
  118. package/dist/storybook/assets/{top-bar-DkXSzzqt.js → top-bar-Bjf6PQE1.js} +1 -1
  119. package/dist/storybook/assets/{top-bar.stories-HDmWT243.js → top-bar.stories-1hZmlzDT.js} +1 -1
  120. package/dist/storybook/assets/{top-bar.testcase.stories-DfmrkEpT.js → top-bar.testcase.stories-BsFYqaw6.js} +1 -1
  121. package/dist/storybook/assets/{tree.stories-feLUcTtm.js → tree.stories-NGZfmH_B.js} +1 -1
  122. package/dist/storybook/assets/unit-input-Byipu-z0.js +10 -0
  123. package/dist/storybook/assets/unit-input.stories-CChVbxmI.js +198 -0
  124. package/dist/storybook/assets/unit-input.test-case.stories-BwKiucyc.js +220 -0
  125. package/dist/storybook/assets/unit-table.stories-B7rN0MF0.js +152 -0
  126. package/dist/storybook/assets/unit-table.test-case.stories-BIMbgiTz.js +1 -0
  127. package/dist/storybook/iframe.html +1 -1
  128. package/dist/storybook/index.json +1 -1
  129. package/dist/storybook/project.json +1 -1
  130. package/package.json +1 -1
  131. package/dist/storybook/assets/button-DHevvVBE.js +0 -1
  132. package/dist/storybook/assets/button-fAxt_G4d.css +0 -1
  133. package/dist/storybook/assets/check-box.stories-DfbWw6mD.js +0 -126
  134. package/dist/storybook/assets/drawer-DOWJp9T4.js +0 -3
  135. package/dist/storybook/assets/drawer-DhrjYsQu.css +0 -1
  136. package/dist/storybook/assets/footer.stories-DgjDE_JR.js +0 -3
  137. package/dist/storybook/assets/form.stories-BrUnmw7R.js +0 -49
  138. package/dist/storybook/assets/formation.stories-BT8VrcqV.js +0 -74
  139. package/dist/storybook/assets/iframe-B8VgeFPT.js +0 -2
  140. package/dist/storybook/assets/initialize-context-DOqEe1Xq.js +0 -1
  141. package/dist/storybook/assets/input-DD7t4kHm.css +0 -1
  142. package/dist/storybook/assets/input-DTXbDJaL.js +0 -1
  143. package/dist/storybook/assets/menu.stories-xWX80Eh2.js +0 -84
  144. package/dist/storybook/assets/message-Cl3kn7ZD.css +0 -1
  145. package/dist/storybook/assets/message-Y48EomV-.js +0 -1
  146. package/dist/storybook/assets/meta-content-DWZbURV2.js +0 -9
  147. package/dist/storybook/assets/meta-content-DnZPPeTF.css +0 -1
  148. package/dist/storybook/assets/modal.stories-LhoWfDE6.js +0 -220
  149. package/dist/storybook/assets/number-input.stories-DhCjZ37u.js +0 -180
  150. package/dist/storybook/assets/popover.stories-CGm0M5fv.js +0 -10
  151. package/dist/storybook/assets/projects.stories-BQswWVCx.js +0 -47
  152. package/dist/storybook/assets/radio-button.stories-5gvV0LD0.js +0 -71
  153. package/dist/storybook/assets/select-DnRuRG_N.js +0 -61
  154. package/dist/storybook/assets/select-H-9tdhwc.css +0 -1
  155. package/dist/storybook/assets/select.input-D0UkAPd9.js +0 -1
  156. package/dist/storybook/assets/select.stories-B9w9ONzj.js +0 -579
  157. package/dist/storybook/assets/side-bar-CSx5wI-k.js +0 -24
  158. package/dist/storybook/assets/side-bar-auov230-.css +0 -1
  159. package/dist/storybook/assets/table-5Y5KPNSk.js +0 -86
  160. package/dist/storybook/assets/table-B8ojy8Nj.css +0 -1
  161. package/dist/storybook/assets/tabs.stories-dsXjRHJy.js +0 -30
  162. package/dist/storybook/assets/textarea-H-YTEwr8.css +0 -1
  163. package/dist/storybook/assets/toaster.stories-HO4VBTy-.js +0 -89
  164. package/dist/storybook/assets/toggle.stories-qTHFTXxI.js +0 -141
  165. package/dist/storybook/assets/unit-input.stories-QnEpR0rY.js +0 -426
  166. package/dist/storybook/assets/unit-table.stories-BZCc0yfc.js +0 -152
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, 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";
19
+ import { toString as toString$1, isScientificStringNum, roundToPrecision, toNum, roundToFixed, validateNumber, cleanNumStr, stripLeadingZeros, unitFromQuantity, getUnit, ALT_UNITS, isValueWithUnit, getValue as getValue$1, withUnit, convertSamePrecision, convertAndGetValue, KNOWN_UNITS, split as split$1, label as label$b, isValidNum, getAltUnitsListByQuantity, altUnitsList, getUnitsForQuantity, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
20
20
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
21
21
  function getDefaultExportFromCjs(x2) {
22
22
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
@@ -55766,7 +55766,6 @@ const NumberInput = ({
55766
55766
  };
55767
55767
  const onInputBlur = (evt) => {
55768
55768
  setFocus(false);
55769
- onChangeValue(evt);
55770
55769
  onBlur(evt);
55771
55770
  };
55772
55771
  const shouldDisplayRound = enableDisplayRounding && !focus2 && valid;
@@ -70176,6 +70175,10 @@ var PredefinedOptionsMenuState = /* @__PURE__ */ ((PredefinedOptionsMenuState2)
70176
70175
  const isWrongValue = (val) => {
70177
70176
  return val === "undefined" || val === void 0 || val === "" || val === "null" || val === null || val === "NaN" || isNaN(val);
70178
70177
  };
70178
+ const isValueWithUnknownUnit = (value) => {
70179
+ if (!value) return false;
70180
+ return Boolean(getUnit(value));
70181
+ };
70179
70182
  const checkConversion = ({
70180
70183
  value,
70181
70184
  unitkey,
@@ -70194,31 +70197,43 @@ const checkConversion = ({
70194
70197
  }
70195
70198
  return true;
70196
70199
  };
70197
- const convertUnit = (stringValue = "", toUnit, unitkey, defaultFromUnit = "", doNotConvertValue = false) => {
70200
+ const convertUnit = ({
70201
+ value: inputValue,
70202
+ unitkey,
70203
+ toUnit,
70204
+ fromUnit,
70205
+ doNotConvertValue = false,
70206
+ exactPrecision = false
70207
+ }) => {
70198
70208
  var _a2;
70199
- if (doNotConvertValue) return stringValue;
70200
- if (!((_a2 = validateNumber(stringValue)) == null ? void 0 : _a2.valid)) return;
70201
- if (toUnit && !isWrongValue(stringValue)) {
70202
- try {
70203
- const valueWithUnit = isValueWithUnit(stringValue) ? stringValue : withUnit(stringValue, defaultFromUnit);
70204
- const shouldConvert = checkConversion({
70205
- value: valueWithUnit,
70206
- toUnit,
70207
- unitkey
70208
- });
70209
- if (shouldConvert) {
70210
- const result = convertSamePrecision(valueWithUnit, toUnit);
70211
- return getValue$1(result);
70212
- }
70213
- return getValue$1(valueWithUnit);
70214
- } catch (e2) {
70209
+ const value = isValueWithUnit(inputValue) ? getValue$1(inputValue) : inputValue;
70210
+ if (doNotConvertValue) {
70211
+ return { value, error: null };
70212
+ }
70213
+ const defaultFromUnit = fromUnit || (isValueWithUnit(inputValue) ? getUnit(inputValue) : unitFromQuantity(unitkey));
70214
+ if (!((_a2 = validateNumber(value)) == null ? void 0 : _a2.valid)) {
70215
+ return { value: void 0, error: "Invalid number format" };
70216
+ }
70217
+ if (!toUnit) {
70218
+ return { value: void 0, error: "Target unit is missing" };
70219
+ }
70220
+ if (!defaultFromUnit) {
70221
+ return { value: void 0, error: "Source unit is missing" };
70222
+ }
70223
+ if (isWrongValue(value)) {
70224
+ return { value: void 0, error: "Value is invalid for conversion" };
70225
+ }
70226
+ try {
70227
+ const valueWithUnit = withUnit(value, defaultFromUnit);
70228
+ if (checkConversion({ value: valueWithUnit, toUnit, unitkey })) {
70229
+ const result = exactPrecision ? convertSamePrecision(valueWithUnit, toUnit) : convertAndGetValue(valueWithUnit, toUnit);
70230
+ return { value: getValue$1(safeToString(result)), error: null };
70215
70231
  }
70232
+ return { value: getValue$1(valueWithUnit), error: null };
70233
+ } catch (e2) {
70234
+ return { value: void 0, error: "Conversion not possible" };
70216
70235
  }
70217
70236
  };
70218
- const isValueWithUnknownUnit = (value) => {
70219
- if (!value) return false;
70220
- return Boolean(getUnit(value));
70221
- };
70222
70237
  const safeConvertValue = ({
70223
70238
  value = "",
70224
70239
  toUnit,
@@ -70230,18 +70245,19 @@ const safeConvertValue = ({
70230
70245
  const rawValue = getValue$1(value);
70231
70246
  const isInvalidInput = isWrongValue(rawValue);
70232
70247
  if (isInvalidInput) {
70233
- return rawValue;
70248
+ return { value: rawValue };
70234
70249
  }
70235
70250
  if (!isWithUnit) {
70236
- return value;
70251
+ return { value };
70237
70252
  }
70238
- return convertUnit(
70239
- rawValue,
70240
- toUnit,
70253
+ return convertUnit({
70254
+ value,
70241
70255
  unitkey,
70242
- defaultFromUnit,
70243
- doNotConvertValue
70244
- );
70256
+ toUnit,
70257
+ fromUnit: defaultFromUnit,
70258
+ doNotConvertValue,
70259
+ exactPrecision: true
70260
+ });
70245
70261
  };
70246
70262
  const getStringName = (name2) => {
70247
70263
  if (isObject$5(name2) && !isArray$1(name2) && !isFunction$3(name2)) {
@@ -70268,6 +70284,95 @@ const initializeContext = (context2) => {
70268
70284
  UnitContext = context2;
70269
70285
  }
70270
70286
  };
70287
+ const PredefinedOptionsMenu = ({
70288
+ predefinedOptions,
70289
+ value,
70290
+ onPredefinedOptionSelect,
70291
+ disabled: disabled2,
70292
+ initialPredefinedOption,
70293
+ predefinedOptionsMenuState,
70294
+ setPredefinedOptionsMenuState,
70295
+ testId
70296
+ }) => {
70297
+ const [foundPredefinedMenuOption, setFoundPredefinedMenuOption] = useState(void 0);
70298
+ const createPredefinedOption = (el2) => {
70299
+ const elementValue = (el2 == null ? void 0 : el2.value) ? el2.value : "";
70300
+ const [inputValue = "", unit2 = ""] = isValueWithUnit(elementValue) ? split$1(elementValue) : [elementValue];
70301
+ return {
70302
+ type: MenuType.OPTION,
70303
+ inline: true,
70304
+ onClick: () => {
70305
+ const validation = validateNumber(inputValue);
70306
+ if (validation.valid && !disabled2) {
70307
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70308
+ onPredefinedOptionSelect(elementValue);
70309
+ setFoundPredefinedMenuOption(el2);
70310
+ }
70311
+ },
70312
+ label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
70313
+ /* @__PURE__ */ jsx(Text, { children: el2.label }),
70314
+ /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70315
+ ] }),
70316
+ description: isValueWithUnit(elementValue) ? `${inputValue} ${unit2}` : elementValue,
70317
+ selected: value === elementValue && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70318
+ };
70319
+ };
70320
+ const initialPredefinedOptionObject = useMemo$1(() => {
70321
+ return predefinedOptions.find(
70322
+ (option2) => option2.value === initialPredefinedOption || option2.label === initialPredefinedOption || option2.valueKey === initialPredefinedOption
70323
+ );
70324
+ }, [initialPredefinedOption, predefinedOptions]);
70325
+ useEffect(() => {
70326
+ if (initialPredefinedOptionObject) {
70327
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70328
+ setFoundPredefinedMenuOption(initialPredefinedOptionObject);
70329
+ onPredefinedOptionSelect(initialPredefinedOptionObject.value);
70330
+ }
70331
+ }, [initialPredefinedOptionObject]);
70332
+ const sectionsPredefinedMenu = [
70333
+ {
70334
+ type: MenuType.OPTION,
70335
+ inline: true,
70336
+ onClick: () => {
70337
+ if (!disabled2) {
70338
+ setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70339
+ }
70340
+ },
70341
+ label: "Custom",
70342
+ selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
70343
+ },
70344
+ ...predefinedOptions.map(createPredefinedOption)
70345
+ ];
70346
+ return /* @__PURE__ */ jsx(
70347
+ Tooltip,
70348
+ {
70349
+ text: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : "",
70350
+ children: /* @__PURE__ */ jsx(
70351
+ Menu,
70352
+ {
70353
+ testId: testId && `${testId}-predefined-menu`,
70354
+ maxHeight: 380,
70355
+ groupOrder: "first",
70356
+ disabled: disabled2,
70357
+ menu: {
70358
+ colored: true,
70359
+ trigger: "Component",
70360
+ component: /* @__PURE__ */ jsx(
70361
+ Button$1,
70362
+ {
70363
+ groupOrder: "first",
70364
+ active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
70365
+ icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
70366
+ }
70367
+ ),
70368
+ small: true,
70369
+ sections: sectionsPredefinedMenu
70370
+ }
70371
+ }
70372
+ )
70373
+ }
70374
+ );
70375
+ };
70271
70376
  const predefinedMenuActive = "_predefinedMenuActive_ye9w9_1";
70272
70377
  const inputWrapper = "_inputWrapper_ye9w9_4";
70273
70378
  const styles = {
@@ -70292,28 +70397,24 @@ const UnitInput = ({
70292
70397
  onFocus = noop$3,
70293
70398
  onSwitchUnit = noop$3,
70294
70399
  unitTemplate,
70295
- doNotConvertValue = false,
70296
70400
  testId,
70297
70401
  warning: warning2 = null,
70298
70402
  predefinedOptions,
70299
- initialPredefinedOption = false,
70300
- shouldLinkAutomaticly = true,
70301
- selectedPredefinedOptionKey,
70403
+ initialPredefinedOption = "",
70302
70404
  validationCallback = () => ({ name: "", error: null }),
70303
70405
  disabledValidation = false,
70304
70406
  allowEmpty = false,
70305
- autoValue,
70306
70407
  convertBackToStorageUnit = false,
70307
70408
  enableCosmeticRounding = true,
70308
70409
  enableDisplayRounding = false
70309
70410
  }) => {
70310
70411
  const context2 = useUnitContext();
70311
70412
  const runAfterUpdate = useRunAfterUpdate();
70413
+ const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(PredefinedOptionsMenuState.CUSTOM);
70312
70414
  if (typeof value === "number") {
70313
70415
  value = `${value}`;
70314
70416
  }
70315
70417
  const [propValue = "", propUnit = ""] = value !== void 0 ? split$1(value) : [];
70316
- const propAutoUnit = autoValue ? getUnit(autoValue) : "";
70317
70418
  const preferredUnit = useMemo$1(
70318
70419
  () => getPreferredUnit(unitkey, unitTemplate || (context2 == null ? void 0 : context2.unitTemplate)),
70319
70420
  [unitkey, unitTemplate, context2 == null ? void 0 : context2.unitTemplate]
@@ -70321,41 +70422,19 @@ const UnitInput = ({
70321
70422
  const knownUnit = isKnownUnit(value, preferredUnit);
70322
70423
  const initDisplayUnit = initUnit || preferredUnit || propUnit;
70323
70424
  const previousInitUnit = usePrevious(initDisplayUnit);
70324
- const convertedValue = safeConvertValue({
70425
+ const { value: convertedValue } = safeConvertValue({
70325
70426
  value,
70326
70427
  toUnit: initDisplayUnit,
70327
70428
  unitkey,
70328
70429
  defaultFromUnit: propUnit,
70329
- doNotConvertValue
70330
- });
70331
- const convertedAutoValue = safeConvertValue({
70332
- value: autoValue,
70333
- toUnit: initDisplayUnit,
70334
- unitkey,
70335
- defaultFromUnit: propAutoUnit,
70336
- doNotConvertValue
70430
+ doNotConvertValue: noConversion
70337
70431
  });
70338
- const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : convertedAutoValue !== "" ? { value: convertedAutoValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
70432
+ const initDisplayLayer = convertedValue !== "" ? { value: convertedValue, unit: initDisplayUnit } : { value: propValue, unit: propUnit };
70339
70433
  const [displayLayer, setDisplayLayer] = useState(initDisplayLayer);
70340
- const derivedAllowEmpty = (displayLayer == null ? void 0 : displayLayer.value) === void 0;
70341
- const [predefinedOptionsMenuState, setPredefinedOptionsMenuState] = useState(
70342
- initialPredefinedOption ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM
70343
- );
70344
- const isAutoValue = propValue === "" && autoValue;
70345
- const disableInternalErrorValidationMessages = !!(disabledValidation || autoValue);
70346
- const foundPredefinedMenuOption = predefinedOptions && predefinedOptions.find((el2) => {
70347
- if (!(el2 == null ? void 0 : el2.value)) return;
70348
- if (selectedPredefinedOptionKey) {
70349
- return selectedPredefinedOptionKey === el2.valueKey;
70350
- }
70351
- const predefinedMenuItemUnit = isValueWithUnit(el2.value) ? getUnit(el2.value) : "";
70352
- return withUnit(
70353
- convertUnit(value, predefinedMenuItemUnit, unitkey),
70354
- predefinedMenuItemUnit
70355
- ) === el2.value;
70356
- });
70434
+ const derivedAllowEmpty = allowEmpty || (displayLayer == null ? void 0 : displayLayer.value) === void 0;
70435
+ const disableInternalErrorValidationMessages = !!disabledValidation;
70357
70436
  const getAlternativeUnits = () => {
70358
- const valueToList = isAutoValue ? autoValue : value ?? "";
70437
+ const valueToList = value ?? "";
70359
70438
  const initToUnit = displayLayer.unit;
70360
70439
  const shouldConvert = checkConversion({
70361
70440
  value: valueToList,
@@ -70409,109 +70488,46 @@ const UnitInput = ({
70409
70488
  if (initDisplayUnit) {
70410
70489
  let newValue, newUnit = "";
70411
70490
  if (previousInitUnit !== initDisplayUnit) {
70412
- newValue = safeConvertValue({
70491
+ const { value: resultValue } = safeConvertValue({
70413
70492
  value,
70414
70493
  toUnit: initDisplayUnit,
70415
70494
  unitkey,
70416
70495
  defaultFromUnit: propUnit,
70417
- doNotConvertValue
70496
+ doNotConvertValue: noConversion
70418
70497
  });
70498
+ newValue = resultValue;
70419
70499
  newUnit = initDisplayUnit;
70420
70500
  } else if (withUnit(displayLayer.value, displayLayer.unit) !== value) {
70421
- newValue = safeConvertValue({
70501
+ const { value: resultValue } = safeConvertValue({
70422
70502
  value,
70423
70503
  toUnit: displayLayer.unit,
70424
70504
  unitkey,
70425
70505
  defaultFromUnit: propUnit,
70426
- doNotConvertValue
70506
+ doNotConvertValue: noConversion
70427
70507
  });
70508
+ newValue = resultValue;
70428
70509
  newUnit = displayLayer.unit;
70429
70510
  }
70430
- if (newValue !== void 0) {
70511
+ if (newValue !== void 0 && !initialPredefinedOption) {
70431
70512
  setDisplayLayer({ value: newValue, unit: newUnit });
70432
70513
  }
70433
- if (predefinedOptions) {
70434
- if (foundPredefinedMenuOption && shouldLinkAutomaticly) {
70435
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70436
- } else {
70437
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.CUSTOM);
70438
- }
70439
- }
70440
70514
  }
70441
- }, [initDisplayUnit, value, error2, shouldLinkAutomaticly]);
70515
+ }, [initDisplayUnit, value, error2]);
70442
70516
  const alternativeUnits = getAlternativeUnits();
70443
70517
  const displayUnitLabel = label$b(displayLayer.unit) || displayLayer.unit || "";
70444
70518
  const noConvert = noConversion || !alternativeUnits || alternativeUnits && alternativeUnits.length === 1;
70445
70519
  const stringName = getStringName(name2);
70446
- let sectionsPredefinedMenu;
70447
- const createPredefinedOption = (el2) => {
70448
- const elementValue = (el2 == null ? void 0 : el2.value) ? el2.value : "";
70449
- const [value2 = "", unit2 = ""] = isValueWithUnit(elementValue) ? split$1(elementValue) : [elementValue];
70450
- return {
70451
- type: MenuType.OPTION,
70452
- inline: true,
70453
- onClick: () => {
70454
- const validation = validateNumber(value2);
70455
- if (validation.valid && !disabled2) {
70456
- setPredefinedOptionsMenuState(PredefinedOptionsMenuState.PREDEFINED);
70457
- onChange({
70458
- target: {
70459
- value: elementValue,
70460
- name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || "",
70461
- predefinedSelected: true,
70462
- predefinedOption: el2
70463
- }
70464
- });
70465
- }
70466
- },
70467
- label: /* @__PURE__ */ jsxs(Fragment$1, { children: [
70468
- /* @__PURE__ */ jsx(Text, { children: el2.label }),
70469
- /* @__PURE__ */ jsx(Spacer, { width: "20px", height: "0" })
70470
- ] }),
70471
- description: isValueWithUnit(elementValue) ? `${value2} ${unit2}` : elementValue,
70472
- selected: foundPredefinedMenuOption === el2 && predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED
70473
- };
70474
- };
70475
- sectionsPredefinedMenu = [
70476
- {
70477
- type: MenuType.OPTION,
70478
- inline: true,
70479
- onClick: () => {
70480
- if (predefinedOptionsMenuState !== PredefinedOptionsMenuState.CUSTOM && !disabled2) {
70481
- onChange({
70482
- target: {
70483
- value: withUnit(displayLayer.value, displayLayer.unit),
70484
- name: typeof name2 === "string" ? name2 : (name2 == null ? void 0 : name2.fieldName) || ""
70485
- }
70486
- });
70487
- }
70488
- },
70489
- label: "Custom",
70490
- selected: predefinedOptionsMenuState === PredefinedOptionsMenuState.CUSTOM
70491
- }
70492
- ];
70493
- if (predefinedOptions == null ? void 0 : predefinedOptions.length) {
70494
- const dynamicOptions = predefinedOptions.map(createPredefinedOption);
70495
- sectionsPredefinedMenu = [...sectionsPredefinedMenu, ...dynamicOptions];
70496
- }
70497
70520
  const getPlaceholder = (placeholder22) => {
70498
- if (isAutoValue) {
70499
- return safeConvertValue({
70500
- value: autoValue,
70501
- toUnit: displayLayer.unit,
70502
- unitkey,
70503
- defaultFromUnit: propAutoUnit,
70504
- doNotConvertValue
70505
- });
70506
- } else if (isValueWithUnit(placeholder22)) {
70521
+ if (isValueWithUnit(placeholder22)) {
70507
70522
  const placeholderUnit = getUnit(placeholder22);
70508
- return safeConvertValue({
70523
+ const { value: resultValue } = safeConvertValue({
70509
70524
  value: placeholder22,
70510
70525
  toUnit: displayLayer.unit,
70511
70526
  unitkey,
70512
70527
  defaultFromUnit: placeholderUnit,
70513
- doNotConvertValue
70528
+ doNotConvertValue: noConversion
70514
70529
  });
70530
+ return resultValue;
70515
70531
  }
70516
70532
  return placeholder22;
70517
70533
  };
@@ -70521,32 +70537,27 @@ const UnitInput = ({
70521
70537
  className: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? cx$2(styles.predefinedMenuActive) : "",
70522
70538
  children: /* @__PURE__ */ jsxs(InputGroup, { small: small2, width: width2, children: [
70523
70539
  predefinedOptions && /* @__PURE__ */ jsx(
70524
- Tooltip,
70540
+ PredefinedOptionsMenu,
70525
70541
  {
70526
- text: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? foundPredefinedMenuOption == null ? void 0 : foundPredefinedMenuOption.label : "",
70527
- children: /* @__PURE__ */ jsx(
70528
- Menu,
70529
- {
70530
- maxHeight: 380,
70531
- groupOrder: "first",
70532
- testId: testId && `${testId}-predefined-menu`,
70533
- disabled: disabled2,
70534
- menu: {
70535
- colored: true,
70536
- trigger: "Component",
70537
- component: /* @__PURE__ */ jsx(
70538
- Button$1,
70539
- {
70540
- groupOrder: "first",
70541
- active: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED,
70542
- icon: predefinedOptionsMenuState === PredefinedOptionsMenuState.PREDEFINED ? "link" : "unlink"
70543
- }
70544
- ),
70545
- small: small2,
70546
- sections: sectionsPredefinedMenu
70542
+ testId,
70543
+ predefinedOptions,
70544
+ value: displayLayer.value,
70545
+ onPredefinedOptionSelect: (newValue) => {
70546
+ onChange({
70547
+ target: {
70548
+ value: newValue,
70549
+ name: stringName
70547
70550
  }
70548
- }
70549
- )
70551
+ });
70552
+ setDisplayLayer({
70553
+ value: newValue,
70554
+ unit: getUnit(newValue) || displayLayer.unit
70555
+ });
70556
+ },
70557
+ disabled: disabled2,
70558
+ initialPredefinedOption,
70559
+ predefinedOptionsMenuState,
70560
+ setPredefinedOptionsMenuState
70550
70561
  }
70551
70562
  ),
70552
70563
  /* @__PURE__ */ jsx("div", { className: styles.inputWrapper, children: /* @__PURE__ */ jsx(
@@ -70593,7 +70604,7 @@ const UnitInput = ({
70593
70604
  inline: true,
70594
70605
  onClick: (evt) => {
70595
70606
  evt.stopPropagation();
70596
- onClickUnit(isAutoValue ? "" : value2, altUnit);
70607
+ onClickUnit(value2, altUnit);
70597
70608
  },
70598
70609
  description: displayUnit,
70599
70610
  selected: displayUnit === displayUnitLabel,
@@ -70616,20 +70627,6 @@ const normalizeUnits = (unitConfig) => unitConfig.reduce(
70616
70627
  },
70617
70628
  { preferredUnits: {}, storageUnits: {} }
70618
70629
  );
70619
- const tryConvertValue = (value, unitKey, selectedUnit, storageUnit) => {
70620
- if (checkConversion({
70621
- value,
70622
- unitkey: unitKey,
70623
- toUnit: selectedUnit
70624
- })) {
70625
- try {
70626
- return convertAndGetValue(value, selectedUnit, storageUnit);
70627
- } catch {
70628
- return value;
70629
- }
70630
- }
70631
- return value;
70632
- };
70633
70630
  const convertVisibleRows = ({
70634
70631
  headers,
70635
70632
  rows,
@@ -70671,7 +70668,13 @@ const convertVisibleRows = ({
70671
70668
  const selectedUnit = selectedUnits[unitKey];
70672
70669
  const storageUnit = storageUnits[unitKey];
70673
70670
  const unitChanged = selectedUnit !== storageUnit;
70674
- const convertedValue = unitChanged ? tryConvertValue(value, unitKey, selectedUnit, storageUnit) : cell2.value;
70671
+ const { value: resultValue = value } = convertUnit({
70672
+ value: safeToString(value),
70673
+ unitkey: unitKey,
70674
+ toUnit: selectedUnit,
70675
+ fromUnit: storageUnit
70676
+ });
70677
+ const convertedValue = unitChanged ? resultValue : cell2.value;
70675
70678
  const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(convertedValue) : convertedValue;
70676
70679
  return {
70677
70680
  ...cell2,
@@ -70686,7 +70689,13 @@ const convertVisibleRows = ({
70686
70689
  const selectedUnit2 = selectedUnits[unitKey];
70687
70690
  const unitChanged2 = selectedUnit2 !== storageUnit2;
70688
70691
  const nextUnit = convertBackToStorageUnit ? storageUnit2 : selectedUnit2;
70689
- const nextValueConverted = unitChanged2 ? tryConvertValue(value2, unitKey, nextUnit, selectedUnit2) : value2;
70692
+ const { value: resultValue2 = value2 } = convertUnit({
70693
+ value: String(value2),
70694
+ unitkey: unitKey,
70695
+ toUnit: nextUnit,
70696
+ fromUnit: selectedUnit2
70697
+ });
70698
+ const nextValueConverted = unitChanged2 ? resultValue2 : value2;
70690
70699
  if ("onChange" in cell2) {
70691
70700
  const { onChange } = cell2;
70692
70701
  const event = {