@oliasoft-open-source/react-ui-library 4.5.0-beta-2 → 4.5.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 (47) hide show
  1. package/dist/404.html +1 -0
  2. package/dist/index.d.ts +50 -0
  3. package/dist/index.js +139 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/storybook/assets/{Color-6VNJS4EI-Wo3sTH7y.js → Color-6VNJS4EI-hAS5LjG0.js} +1 -1
  6. package/dist/storybook/assets/{DocsRenderer-NNNQARDV-Yh9Nd5gV.js → DocsRenderer-NNNQARDV-t6iXcjlI.js} +1 -1
  7. package/dist/storybook/assets/{WithTooltip-4HIR6TLV-sgH3fqcb.js → WithTooltip-4HIR6TLV-EXM_UisT.js} +1 -1
  8. package/dist/storybook/assets/{accordion.stories-DAmwlTmm.js → accordion.stories-HoiQl98a.js} +1 -1
  9. package/dist/storybook/assets/{afe.stories-1YkAm2l2.js → afe.stories-n9sXDAMv.js} +1 -1
  10. package/dist/storybook/assets/{buttons-and-links-G0egBJCQ.js → buttons-and-links-ftv0zbwN.js} +1 -1
  11. package/dist/storybook/assets/{casing-loads.stories--oHbAVn4.js → casing-loads.stories-ONI2BhpU.js} +1 -1
  12. package/dist/storybook/assets/{cell.stories-S9IDsuIA.js → cell.stories-FGJr13HC.js} +1 -1
  13. package/dist/storybook/assets/{chunk-HLWAVYOI-R756X9cQ.js → chunk-HLWAVYOI-jhhGhXKB.js} +1 -1
  14. package/dist/storybook/assets/{color-6FMn1O-g.js → color-4GYIInYi.js} +1 -1
  15. package/dist/storybook/assets/{drawer.stories-K-pmYbOj.js → drawer.stories-a2C35tbD.js} +1 -1
  16. package/dist/storybook/assets/{footer.stories-4uhW-z_4.js → footer.stories-nCkpV7Yt.js} +1 -1
  17. package/dist/storybook/assets/{formation.stories-ZGzBQKt1.js → formation.stories-R3W7H_Rc.js} +1 -1
  18. package/dist/storybook/assets/{formatter-SWP5E3XI-yTTNZ_t2.js → formatter-SWP5E3XI-nDlvV_yz.js} +1 -1
  19. package/dist/storybook/assets/iframe-fZf8RXY8.js +7 -0
  20. package/dist/storybook/assets/{index-4BJtFSI2.js → index-J809fMmq.js} +5 -5
  21. package/dist/storybook/assets/{input-validation-kZPNHjD7.js → input-validation-KCJCN0yQ.js} +1 -1
  22. package/dist/storybook/assets/{inputs-V80YGmaz.js → inputs-5Dsixbp9.js} +1 -1
  23. package/dist/storybook/assets/{layout-forms-FANlSXRU.js → layout-forms-hLUZFgjt.js} +1 -1
  24. package/dist/storybook/assets/{layout-general-LrT4H6RD.js → layout-general-pWHB8pQP.js} +1 -1
  25. package/dist/storybook/assets/{list-ciYNlkVM.js → list-FJ7byNrg.js} +1 -1
  26. package/dist/storybook/assets/{list.stories-khlFbVFq.js → list.stories-nWamVbJ2.js} +1 -1
  27. package/dist/storybook/assets/{padding-and-spacing-sd88NtLC.js → padding-and-spacing-PD_4uQcK.js} +1 -1
  28. package/dist/storybook/assets/{preview-ixZGzwV9.js → preview-cyb8LEBC.js} +1 -1
  29. package/dist/storybook/assets/{preview-HzqOHlF7.js → preview-jdsgMyUk.js} +2 -2
  30. package/dist/storybook/assets/{projects.stories-ojOsn6HU.js → projects.stories-UU4irLQZ.js} +1 -1
  31. package/dist/storybook/assets/{reservoirs.stories-Dg5QFAXV.js → reservoirs.stories-iKvudcEf.js} +1 -1
  32. package/dist/storybook/assets/{row.stories-HVr8m6RK.js → row.stories-J389Ezfp.js} +1 -1
  33. package/dist/storybook/assets/{site.stories-OEW6o2C_.js → site.stories-4pPVEtn7.js} +1 -1
  34. package/dist/storybook/assets/{syntaxhighlighter-NMPM6SWI-7eVUNnH3.js → syntaxhighlighter-NMPM6SWI-Bt8NQoOb.js} +1 -1
  35. package/dist/storybook/assets/{table-_jWgMFOi.js → table-fX2iU96a.js} +1 -1
  36. package/dist/storybook/assets/{table.stories-lwqVUJHa.js → table.stories-CIbyraqh.js} +1 -1
  37. package/dist/storybook/assets/{title.stories-Djnk3crF.js → title.stories-nSN4OumV.js} +1 -1
  38. package/dist/storybook/assets/unit-input.stories-0l2v-aF9.js +273 -0
  39. package/dist/storybook/assets/unit-table.stories-62i0bHyO.js +103 -0
  40. package/dist/storybook/assets/use-previous-VKMmnaK7.js +1 -0
  41. package/dist/storybook/iframe.html +1 -1
  42. package/dist/storybook/index.json +1 -1
  43. package/dist/storybook/project.json +1 -1
  44. package/dist/storybook/stories.json +1 -1
  45. package/package.json +3 -3
  46. package/dist/storybook/assets/iframe-SrZRNvhh.js +0 -7
  47. package/dist/storybook/assets/unit-input.stories-ZdrR9JWT.js +0 -273
package/dist/404.html ADDED
@@ -0,0 +1 @@
1
+ <!doctype html><head><title>React UI Library</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1" user-scalable="no"><meta name="apple-mobile-web-app-capable" content="yes"><script type="module" crossorigin src="/react-ui-library/assets/index-neKlYvgy.js"></script><link rel="stylesheet" crossorigin href="/react-ui-library/assets/index-AkeNwthw.css"></head><body><div id="content"></div></body>
package/dist/index.d.ts CHANGED
@@ -1497,6 +1497,12 @@ export declare interface ITreeProps {
1497
1497
  allowParentReassignment?: boolean;
1498
1498
  }
1499
1499
 
1500
+ declare interface IUnitConfigItem {
1501
+ unitKey: string;
1502
+ storageUnit: string;
1503
+ preferredUnit: string;
1504
+ }
1505
+
1500
1506
  export declare interface IUnitInputProps {
1501
1507
  name: string | {
1502
1508
  fieldName?: string;
@@ -1533,6 +1539,46 @@ export declare interface IUnitInputProps {
1533
1539
  unitTemplate?: Record<string, any>;
1534
1540
  }
1535
1541
 
1542
+ declare interface IUnitTable extends Omit<ITableProps['table'], 'rows'> {
1543
+ rows?: IUnitTableRow[];
1544
+ }
1545
+
1546
+ declare interface IUnitTableCell {
1547
+ autoUnit: boolean;
1548
+ unitKey: string;
1549
+ formatDisplayValue?: (value: string | number) => void;
1550
+ }
1551
+
1552
+ declare interface IUnitTableInputCell extends IInputCell, IUnitTableCell {
1553
+ onChange: (args: any) => void;
1554
+ }
1555
+
1556
+ declare interface IUnitTableNumberInputCell extends INumberInputCell, IUnitTableCell {
1557
+ onChange: (args: any) => void;
1558
+ }
1559
+
1560
+ export declare interface IUnitTableOnChangeEvent extends React_2.ChangeEvent<HTMLInputElement> {
1561
+ target: EventTarget & HTMLInputElement & {
1562
+ rowIndex: number;
1563
+ cellIndex: number;
1564
+ unit: string;
1565
+ };
1566
+ }
1567
+
1568
+ export declare interface IUnitTableProps extends Omit<ITableProps, 'table'> {
1569
+ table: IUnitTable;
1570
+ unitConfig: IUnitConfigItem[];
1571
+ convertBackToStorageUnit: boolean;
1572
+ enableCosmeticRounding: boolean;
1573
+ }
1574
+
1575
+ export declare interface IUnitTableRow extends Omit<TRowType, 'cells'> {
1576
+ cells: TUnitTableCellShape[];
1577
+ }
1578
+
1579
+ declare interface IUnitTableStaticCell extends IStaticCell, IUnitTableCell {
1580
+ }
1581
+
1536
1582
  export declare const Label: ({ label, width, helpText, helpTextMaxWidth, onClickHelp, lock, info, libraryIcon, labelLeft, }: ILabelProps) => JSX_2.Element;
1537
1583
 
1538
1584
  export declare const List: ({ list, bordered, expanding, narrow, toggleNarrow, onToggleNarrow, invokeEditOnRowClick, noHeader, stickyHeader, draggable, onListReorder, marginBottom, height, testId, scrollDetails, }: IListProps) => JSX_2.Element;
@@ -1747,8 +1793,12 @@ declare type TTopBarContent = TLinkElement | TButtonElement | TMenuElement | TCo
1747
1793
 
1748
1794
  export declare type TTriggerType = 'Text' | 'Button' | 'DropDownButton' | 'Component';
1749
1795
 
1796
+ declare type TUnitTableCellShape = TCellShape | IUnitTableStaticCell | IUnitTableInputCell | IUnitTableNumberInputCell;
1797
+
1750
1798
  export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, doNotConvertValue, testId, warning, predefinedOptions, initialPredefinedOption, shouldLinkAutomaticly, selectedPredefinedOptionKey, validationCallback, disabledValidation, allowEmpty, autoValue, }: IUnitInputProps) => JSX_2.Element;
1751
1799
 
1800
+ export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, }: IUnitTableProps) => JSX_2.Element;
1801
+
1752
1802
  export declare const useFocus: () => UseFocusReturnType;
1753
1803
 
1754
1804
  declare type UseFocusReturnType = [MutableRefObject<HTMLInputElement | null>, TEmpty];
package/dist/index.js CHANGED
@@ -10,8 +10,8 @@ import React__default, { useContext, isValidElement, useState, useRef, useEffect
10
10
  import * as PropTypes from "prop-types";
11
11
  import PropTypes__default from "prop-types";
12
12
  import ReactDOM, { createPortal, unstable_batchedUpdates, render } from "react-dom";
13
- import _$1, { set, get as get$2, isString as isString$3, isNumber as isNumber$1, isBoolean as isBoolean$2, isFunction as isFunction$3, isEmpty, isArray as isArray$1, toNumber, debounce as debounce$2, isObject as isObject$5, isObjectLike, has as has$1 } from "lodash";
14
- import { validateNumber, cleanNumStr, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, checkAndCleanDecimalComma, label as label$b, altUnitsList } from "@oliasoft-open-source/units";
13
+ import _$1, { set, get as get$2, isString as isString$3, isNumber as isNumber$1, isBoolean as isBoolean$2, isFunction as isFunction$3, isEmpty, isArray as isArray$1, toNumber, debounce as debounce$2, isObject as isObject$5, isObjectLike, has as has$1, isEqual as isEqual$4 } from "lodash";
14
+ import { validateNumber, cleanNumStr, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, checkAndCleanDecimalComma, label as label$b, altUnitsList, getUnitsForQuantity, convertAndGetValue, isScientificStringNum, roundToPrecision } from "@oliasoft-open-source/units";
15
15
  import { isValueWithUnit as isValueWithUnit$1 } from "@oliasoft-open-source/units/dist/units";
16
16
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
17
17
  function getDefaultExportFromCjs(x2) {
@@ -56126,6 +56126,7 @@ var CellType = /* @__PURE__ */ ((CellType2) => {
56126
56126
  CellType2["SLIDER"] = "Slider";
56127
56127
  CellType2["CHECKBOX"] = "CheckBox";
56128
56128
  CellType2["ACTIONS"] = "Actions";
56129
+ CellType2["AUTO_UNIT"] = "AutoUnit";
56129
56130
  return CellType2;
56130
56131
  })(CellType || {});
56131
56132
  const Cell = ({
@@ -70595,6 +70596,141 @@ const UnitInput = ({
70595
70596
  }
70596
70597
  );
70597
70598
  };
70599
+ const normalizeUnits = (unitConfig) => unitConfig.reduce(
70600
+ ({ preferredUnits, storageUnits }, { unitKey, preferredUnit, storageUnit }) => {
70601
+ preferredUnits[unitKey] = preferredUnit;
70602
+ storageUnits[unitKey] = storageUnit;
70603
+ return { preferredUnits, storageUnits };
70604
+ },
70605
+ { preferredUnits: {}, storageUnits: {} }
70606
+ );
70607
+ const convertVisibleRows = ({
70608
+ headers,
70609
+ rows,
70610
+ selectedUnits,
70611
+ storageUnits,
70612
+ onChangeUnit,
70613
+ convertBackToStorageUnit,
70614
+ enableCosmeticRounding
70615
+ }) => {
70616
+ const convertedHeaders = headers ? headers.map((headerRow) => ({
70617
+ ...headerRow,
70618
+ cells: headerRow.cells.map((headerCell) => {
70619
+ if (headerCell.type === CellType.AUTO_UNIT) {
70620
+ const { unitKey } = headerCell;
70621
+ return {
70622
+ value: selectedUnits[unitKey],
70623
+ type: CellType.SELECT,
70624
+ options: getUnitsForQuantity(unitKey),
70625
+ native: true,
70626
+ onChange: (evt) => onChangeUnit({ unitKey, value: evt.target.value })
70627
+ };
70628
+ }
70629
+ return headerCell;
70630
+ })
70631
+ })) : [];
70632
+ const convertedRows = rows ? rows.map((row2, rowIndex) => ({
70633
+ ...row2,
70634
+ cells: row2.cells.map((cell2, cellIndex) => {
70635
+ if ("autoUnit" in cell2 && (cell2 == null ? void 0 : cell2.autoUnit) && (typeof (cell2 == null ? void 0 : cell2.value) === "string" || typeof (cell2 == null ? void 0 : cell2.value) === "number")) {
70636
+ const { formatDisplayValue, unitKey, value } = cell2;
70637
+ const selectedUnit = selectedUnits[unitKey];
70638
+ const storageUnit = storageUnits[unitKey];
70639
+ const unitChanged = selectedUnit !== storageUnit;
70640
+ const convertedValue = unitChanged ? convertAndGetValue(value, selectedUnit, storageUnit) : cell2.value;
70641
+ const isScientific = isScientificStringNum(value);
70642
+ const displayValue = enableCosmeticRounding && (unitChanged || !isScientific) ? (
70643
+ /*
70644
+ Optionally do Excel-style "cosmetic rounding" of display values (only if enableCosmeticRounding prop on)
70645
+ This means rounding to slightly less precision than the underlying floating-point number type, to
70646
+ resolve floating-point "rounding noise" associated with storing values in one unit but converting
70647
+ and displaying them in another unit. This solution was evaluated by Tools Team in relation to
70648
+ tickets OW-10614 and OW-15745.
70649
+ */
70650
+ roundToPrecision(convertedValue, 14)
70651
+ ) : convertedValue;
70652
+ const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(displayValue) : displayValue;
70653
+ return {
70654
+ ...cell2,
70655
+ value: formattedDisplayValue,
70656
+ onChange: (evt) => {
70657
+ const { value: value2 } = evt.target;
70658
+ const storageUnit2 = storageUnits[unitKey];
70659
+ const selectedUnit2 = selectedUnits[unitKey];
70660
+ const unitChanged2 = selectedUnit2 !== storageUnit2;
70661
+ const nextValueConverted = unitChanged2 ? convertAndGetValue(value2, storageUnit2, selectedUnit2) : value2;
70662
+ const nextUnit = convertBackToStorageUnit ? storageUnit2 : selectedUnit2;
70663
+ if ("onChange" in cell2) {
70664
+ const { onChange } = cell2;
70665
+ const event = {
70666
+ ...evt,
70667
+ target: {
70668
+ ...evt.target,
70669
+ value: String(nextValueConverted),
70670
+ rowIndex,
70671
+ cellIndex,
70672
+ unit: nextUnit
70673
+ }
70674
+ };
70675
+ onChange(event);
70676
+ }
70677
+ }
70678
+ };
70679
+ }
70680
+ return cell2;
70681
+ })
70682
+ })) : [];
70683
+ return { convertedHeaders, convertedRows };
70684
+ };
70685
+ const UnitTable = ({
70686
+ table: table2,
70687
+ unitConfig,
70688
+ convertBackToStorageUnit = true,
70689
+ enableCosmeticRounding = true
70690
+ }) => {
70691
+ const { rows, headers, ...otherProps } = table2;
70692
+ const { storageUnits, preferredUnits } = normalizeUnits(unitConfig);
70693
+ const previousPreferredUnits = usePrevious(preferredUnits);
70694
+ const [selectedUnits, setSelectedUnits] = useState(preferredUnits);
70695
+ const onChangeUnit = ({
70696
+ unitKey,
70697
+ value
70698
+ }) => setSelectedUnits({
70699
+ ...selectedUnits,
70700
+ [unitKey]: value
70701
+ });
70702
+ const convertViewData = (selectedUnits2) => convertVisibleRows({
70703
+ headers,
70704
+ rows,
70705
+ selectedUnits: selectedUnits2,
70706
+ storageUnits,
70707
+ onChangeUnit,
70708
+ convertBackToStorageUnit,
70709
+ enableCosmeticRounding
70710
+ });
70711
+ const convertedViewData = convertViewData(selectedUnits);
70712
+ const [viewData, setViewData] = useState(convertedViewData);
70713
+ useEffect(() => {
70714
+ const templateChanged = !isEqual$4(preferredUnits, previousPreferredUnits);
70715
+ if (templateChanged) {
70716
+ setSelectedUnits(preferredUnits);
70717
+ setViewData(convertViewData(preferredUnits));
70718
+ }
70719
+ }, [unitConfig]);
70720
+ useEffect(() => {
70721
+ setViewData(convertViewData(selectedUnits));
70722
+ }, [table2, selectedUnits]);
70723
+ return /* @__PURE__ */ jsx(
70724
+ Table,
70725
+ {
70726
+ table: {
70727
+ ...otherProps,
70728
+ headers: viewData.convertedHeaders,
70729
+ rows: viewData.convertedRows
70730
+ }
70731
+ }
70732
+ );
70733
+ };
70598
70734
  export {
70599
70735
  Accordion,
70600
70736
  AccordionWithDefaultToggle,
@@ -70674,6 +70810,7 @@ export {
70674
70810
  Tree,
70675
70811
  TriggerType,
70676
70812
  UnitInput,
70813
+ UnitTable,
70677
70814
  dismissToast,
70678
70815
  readFile,
70679
70816
  toast,