@oliasoft-open-source/react-ui-library 4.4.8 → 4.5.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 (106) hide show
  1. package/dist/index.d.ts +55 -0
  2. package/dist/index.js +209 -8
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/{Color-6VNJS4EI-mlGeGy0N.js → Color-6VNJS4EI-OKUPsN5g.js} +1 -1
  5. package/dist/storybook/assets/{DocsRenderer-NNNQARDV-FLE8MQVp.js → DocsRenderer-NNNQARDV-GtO0h5cy.js} +1 -1
  6. package/dist/storybook/assets/{WithTooltip-4HIR6TLV-gwf45DIV.js → WithTooltip-4HIR6TLV-oJGDwI7F.js} +1 -1
  7. package/dist/storybook/assets/accordion-with-default-toggle-8PUIm8jP.js +1 -0
  8. package/dist/storybook/assets/accordion.stories-xUgAzm87.js +170 -0
  9. package/dist/storybook/assets/{afe.stories-u2K3NwaR.js → afe.stories-fh4-T0m2.js} +1 -1
  10. package/dist/storybook/assets/breadcrumb-WFZ7OoC2.js +1 -0
  11. package/dist/storybook/assets/breadcrumb.stories-mou0ppaX.js +1 -0
  12. package/dist/storybook/assets/{button.stories-f6VcbEgi.js → button.stories-PhWmZXOu.js} +1 -1
  13. package/dist/storybook/assets/{buttons-and-links-t1EEC4gc.js → buttons-and-links-mIhXkKfh.js} +2 -2
  14. package/dist/storybook/assets/{casing-loads.stories-ee6r2j2Q.js → casing-loads.stories-i9Kyuvs1.js} +1 -1
  15. package/dist/storybook/assets/{cell.stories-y081eSUk.js → cell.stories-QHDggPeA.js} +1 -1
  16. package/dist/storybook/assets/{chunk-HLWAVYOI-53hWDdvc.js → chunk-HLWAVYOI-YpA4-WPj.js} +1 -1
  17. package/dist/storybook/assets/{color-LlgCLGE5.js → color-0ogqq8EH.js} +1 -1
  18. package/dist/storybook/assets/{drawer.stories-ezk4vO0w.js → drawer.stories-BLdyJ3NA.js} +1 -1
  19. package/dist/storybook/assets/empty-PU0JdhZM.js +1 -0
  20. package/dist/storybook/assets/empty.stories-FYO6syUx.js +1 -0
  21. package/dist/storybook/assets/file-input-7-7kYhsS.js +1 -0
  22. package/dist/storybook/assets/file-input.stories-lW0gLK14.js +66 -0
  23. package/dist/storybook/assets/{flex-3eLDDUyy.js → flex-RYZsoWEN.js} +1 -1
  24. package/dist/storybook/assets/{flex.stories-_VBDAVzN.js → flex.stories-lLz0Xrt_.js} +1 -1
  25. package/dist/storybook/assets/{footer.stories-m5VFK6Bo.js → footer.stories-guoNYzr9.js} +1 -1
  26. package/dist/storybook/assets/{form.stories-z3f6tVdU.js → form.stories-tzZoKyyL.js} +1 -1
  27. package/dist/storybook/assets/{formatter-SWP5E3XI-TLomX0jS.js → formatter-SWP5E3XI-Z60pYM_f.js} +1 -1
  28. package/dist/storybook/assets/{preview-QdB_aBj_.css → global-M-3dCKk3.css} +1 -1
  29. package/dist/storybook/assets/{heading.stories-DmZLaZJb.js → heading.stories-HLMPkIPo.js} +1 -1
  30. package/dist/storybook/assets/{icon.stories-h0hheUmg.js → icon.stories-W-UgTWyK.js} +1 -1
  31. package/dist/storybook/assets/iframe-ybuSzuG4.js +7 -0
  32. package/dist/storybook/assets/{index-0dxTfrBP.js → index-isA0pQQP.js} +5 -5
  33. package/dist/storybook/assets/{input-validation-jCRmk_jl.js → input-validation-lBeNJX0o.js} +1 -1
  34. package/dist/storybook/assets/{inputs-ZpY3-Ny4.js → inputs-bYS5qR_g.js} +14 -14
  35. package/dist/storybook/assets/{layout-forms-tcQfdK2L.js → layout-forms-S1UZag29.js} +1 -1
  36. package/dist/storybook/assets/{layout-general-bz1oHjNF.js → layout-general-U3YRmnqR.js} +1 -1
  37. package/dist/storybook/assets/{list-8l-RGDgw.js → list-dAlCO11z.js} +1 -1
  38. package/dist/storybook/assets/{list.stories-uR6izjvO.js → list.stories-bt_cumRX.js} +1 -1
  39. package/dist/storybook/assets/{list.stories-data-9RrIjRci.js → list.stories-data-IcFu6vvd.js} +1 -1
  40. package/dist/storybook/assets/{menu.stories-5G4phywO.js → menu.stories-VwRF_Pbx.js} +1 -1
  41. package/dist/storybook/assets/{menu.stories-data-l5rlcD9_.js → menu.stories-data-hEz8P1yK.js} +1 -1
  42. package/dist/storybook/assets/{message-uMHaTEXV.js → message-yii7x6Na.js} +1 -1
  43. package/dist/storybook/assets/{message.stories-CDgUaLZP.js → message.stories-9RWD3-p1.js} +1 -1
  44. package/dist/storybook/assets/meta-content-2S9BpSoX.js +1 -0
  45. package/dist/storybook/assets/modal-BJKGBCkS.css +1 -0
  46. package/dist/storybook/assets/modal-Dr5HffrG.js +1 -0
  47. package/dist/storybook/assets/{modal.stories-15sY1c5H.js → modal.stories-rVfow_s3.js} +1 -1
  48. package/dist/storybook/assets/option-dropdown-6QvoS02o.js +1 -0
  49. package/dist/storybook/assets/option-dropdown.stories-5qw-N2Q9.js +21 -0
  50. package/dist/storybook/assets/{padding-and-spacing-dSuzf2dz.js → padding-and-spacing-Ej5fu8GG.js} +1 -1
  51. package/dist/storybook/assets/page.stories-4zM8wrxN.js +57 -0
  52. package/dist/storybook/assets/pop-confirm-nfz5S-f-.js +1 -0
  53. package/dist/storybook/assets/pop-confirm.stories-1vIAhdl-.js +9 -0
  54. package/dist/storybook/assets/{popover.stories-bWBLR9fB.js → popover.stories-b7Tt4S0j.js} +1 -1
  55. package/dist/storybook/assets/{preview-8q_cpMjL.js → preview-8d3sl769.js} +2 -2
  56. package/dist/storybook/assets/{preview-xbxc--KY.js → preview-UZXZGus9.js} +3 -3
  57. package/dist/storybook/assets/preview-agc3Xxfb.css +1 -0
  58. package/dist/storybook/assets/print-header-mVYWFles.js +1 -0
  59. package/dist/storybook/assets/{projects.stories-84p22lkF.js → projects.stories-bo3cPOP-.js} +1 -1
  60. package/dist/storybook/assets/{reservoirs.stories-CtIlcj-X.js → reservoirs.stories-RUFcw2h6.js} +1 -1
  61. package/dist/storybook/assets/{rich-text-input.stories-7UzvJ-A1.js → rich-text-input-W-kYpvgO.js} +52 -127
  62. package/dist/storybook/assets/rich-text-input.stories-6-587T_0.js +76 -0
  63. package/dist/storybook/assets/{row.stories-uPD-qTX2.js → row.stories-TurDc49t.js} +1 -1
  64. package/dist/storybook/assets/{side-bar.stories-0_pud_bN.js → side-bar.stories-sxBJCVnV.js} +1 -1
  65. package/dist/storybook/assets/{site.stories-UH3PK5eu.js → site.stories-Hnwa5Rxk.js} +1 -1
  66. package/dist/storybook/assets/{spacer.stories-bgTBb3VB.js → spacer.stories-eCrKj4b3.js} +1 -1
  67. package/dist/storybook/assets/{syntaxhighlighter-NMPM6SWI-1xSal2rv.js → syntaxhighlighter-NMPM6SWI-LVCFR00p.js} +1 -1
  68. package/dist/storybook/assets/{table.stories-GrJ75DyI.js → table.stories-TGOwb9FU.js} +1 -1
  69. package/dist/storybook/assets/{table.stories-data-9XfBJddg.js → table.stories-data-txTr9mYv.js} +1 -1
  70. package/dist/storybook/assets/text-link-1uKYQqn_.js +1 -0
  71. package/dist/storybook/assets/text-link.stories-ZcuOY5VK.js +1 -0
  72. package/dist/storybook/assets/{textarea-u-nirfI6.js → textarea-8bcldTyf.js} +1 -1
  73. package/dist/storybook/assets/{textarea.stories-Hl-oeUWU.js → textarea.stories-D9SctTMD.js} +1 -1
  74. package/dist/storybook/assets/{title.stories-RyQ9x-ug.js → title.stories-InoCrXr8.js} +1 -1
  75. package/dist/storybook/assets/{toaster-eOozfa7U.js → toaster-2HasMRmP.js} +1 -1
  76. package/dist/storybook/assets/{toaster.stories--z_U2gRN.js → toaster.stories-NBYloz0_.js} +1 -1
  77. package/dist/storybook/assets/{toggle.stories-HiGs6slZ.js → toggle.stories-aVmjpons.js} +1 -1
  78. package/dist/storybook/assets/{tooltip.test-case.stories-3T_tzhJs.js → tooltip.test-case.stories-kIeZayHw.js} +1 -1
  79. package/dist/storybook/assets/tree-Rhl5ea49.js +6 -0
  80. package/dist/storybook/assets/tree.stories-dFH-G6se.js +123 -0
  81. package/dist/storybook/assets/unit-input-fxjK7nON.js +1 -0
  82. package/dist/storybook/assets/unit-input.stories--UApgPT-.js +273 -0
  83. package/dist/storybook/assets/unit-table.stories-Vd1Nqk2h.js +434 -0
  84. package/dist/storybook/iframe.html +1 -1
  85. package/dist/storybook/index.json +1 -1
  86. package/dist/storybook/project.json +1 -1
  87. package/dist/storybook/stories.json +1 -1
  88. package/package.json +1 -1
  89. package/dist/404.html +0 -1
  90. package/dist/storybook/assets/accordion.stories-yWtLkrNK.js +0 -170
  91. package/dist/storybook/assets/breadcrumb.stories-V7ozYBO-.js +0 -1
  92. package/dist/storybook/assets/dialog-WKHRZcjc.js +0 -1
  93. package/dist/storybook/assets/dialog-gTGZ42G6.css +0 -1
  94. package/dist/storybook/assets/empty.stories-lva3DbfI.js +0 -1
  95. package/dist/storybook/assets/file-input.stories-6NjWeNyC.js +0 -66
  96. package/dist/storybook/assets/iframe-ujjJUTtn.js +0 -7
  97. package/dist/storybook/assets/list-heading-Vd3hu5Pf.js +0 -1
  98. package/dist/storybook/assets/option-dropdown.stories-Q2zd2AcS.js +0 -21
  99. package/dist/storybook/assets/page.stories-9XUTUblI.js +0 -57
  100. package/dist/storybook/assets/pop-confirm.stories-_agvSFJd.js +0 -9
  101. package/dist/storybook/assets/text-link.stories-kjfUeFtk.js +0 -1
  102. package/dist/storybook/assets/tree.stories-_5t-Rrls.js +0 -128
  103. package/dist/storybook/assets/unit-input.stories-u823izRm.js +0 -273
  104. /package/dist/storybook/assets/{accordion-tw1O4Ru6.css → accordion-with-default-toggle-tw1O4Ru6.css} +0 -0
  105. /package/dist/storybook/assets/{list-heading-Y8BAUuV6.css → meta-content-Y8BAUuV6.css} +0 -0
  106. /package/dist/storybook/assets/{page-6iak35D6.css → print-header-6iak35D6.css} +0 -0
package/dist/index.d.ts CHANGED
@@ -158,6 +158,8 @@ export declare interface IActionProps {
158
158
  closeLayer?: TEmpty;
159
159
  }
160
160
 
161
+ declare type IActionsType = (IAction | ISubAction | IChildComponent)[];
162
+
161
163
  export declare interface IBadgeProps {
162
164
  children?: ReactNode;
163
165
  color?: string;
@@ -231,6 +233,20 @@ export declare interface ICardProps {
231
233
  children?: ReactNode;
232
234
  }
233
235
 
236
+ declare interface ICell {
237
+ value: number | string;
238
+ type: string;
239
+ onChange: (e: ChangeEvent<HTMLInputElement>) => void;
240
+ placeholder?: string;
241
+ testId?: string;
242
+ disabled?: boolean;
243
+ style?: object;
244
+ options?: {
245
+ label: string;
246
+ value: string | number;
247
+ }[];
248
+ }
249
+
234
250
  declare interface ICheckBoxCell extends TCommonCell {
235
251
  label?: string | null;
236
252
  checked: boolean;
@@ -256,6 +272,11 @@ export declare interface ICheckBoxProps {
256
272
  onClickHelp?: TEmpty;
257
273
  }
258
274
 
275
+ declare interface IChildComponent {
276
+ childComponent: ReactNode | (() => ReactNode);
277
+ testId?: string;
278
+ }
279
+
259
280
  /**
260
281
  * Icon wrapper component to support different icon formats:
261
282
  * - string names (default recommendation)
@@ -1281,6 +1302,25 @@ declare interface ISubAction_2 {
1281
1302
  onClick: TEmpty;
1282
1303
  }
1283
1304
 
1305
+ declare interface ITableActions {
1306
+ addRow?: () => void;
1307
+ reorderComponents?: () => void;
1308
+ }
1309
+
1310
+ declare interface ITableDefinition {
1311
+ key: string;
1312
+ header: string;
1313
+ translationKey: string;
1314
+ type: string;
1315
+ convertible: boolean;
1316
+ unitKey: string;
1317
+ columnAlignment: string;
1318
+ columnWidth: string;
1319
+ defaultValue?: number | string | null;
1320
+ options?: Array<any>;
1321
+ placeholder?: string;
1322
+ }
1323
+
1284
1324
  export declare interface ITableProps {
1285
1325
  onListReorder?: (obj: {
1286
1326
  from: number;
@@ -1532,6 +1572,19 @@ export declare interface IUnitInputProps {
1532
1572
  unitTemplate?: Record<string, any>;
1533
1573
  }
1534
1574
 
1575
+ declare interface IUnitTableProps {
1576
+ data: Array<any>;
1577
+ unitTemplate: Record<string, any>;
1578
+ tableDef: ITableDefinition[];
1579
+ convertToCells: (displayedData: Array<any>, displayedUnits: Record<string, any>) => {
1580
+ cells: ICell[];
1581
+ actions: IActionsType;
1582
+ }[];
1583
+ tableActions: ITableActions;
1584
+ oldStructureType?: string | null;
1585
+ testId: string;
1586
+ }
1587
+
1535
1588
  export declare const Label: ({ label, width, helpText, helpTextMaxWidth, onClickHelp, lock, info, libraryIcon, labelLeft, }: ILabelProps) => JSX_2.Element;
1536
1589
 
1537
1590
  export declare const List: ({ list, bordered, expanding, narrow, toggleNarrow, onToggleNarrow, invokeEditOnRowClick, noHeader, stickyHeader, draggable, onListReorder, marginBottom, height, testId, scrollDetails, }: IListProps) => JSX_2.Element;
@@ -1748,6 +1801,8 @@ export declare type TTriggerType = 'Text' | 'Button' | 'DropDownButton' | 'Compo
1748
1801
 
1749
1802
  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;
1750
1803
 
1804
+ export declare const UnitTable: ({ data, unitTemplate, tableDef, convertToCells, tableActions, testId, oldStructureType, }: IUnitTableProps) => JSX_2.Element;
1805
+
1751
1806
  export declare const useFocus: () => UseFocusReturnType;
1752
1807
 
1753
1808
  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, cloneDeep } 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, convertAndGetValue, isNumeric, getAltUnitsListByQuantity } 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) {
@@ -55702,8 +55702,7 @@ const styles$7 = {
55702
55702
  const InputCell = ({
55703
55703
  cell: cell2,
55704
55704
  columnAlignment,
55705
- testId,
55706
- type
55705
+ testId
55707
55706
  }) => {
55708
55707
  return /* @__PURE__ */ jsx(
55709
55708
  Input$1,
@@ -55727,8 +55726,7 @@ const InputCell = ({
55727
55726
  right: columnAlignment === Align.RIGHT,
55728
55727
  testId,
55729
55728
  tabIndex: cell2.disabled ? -1 : 0,
55730
- tooltip: cell2.tooltip,
55731
- type
55729
+ tooltip: cell2.tooltip
55732
55730
  }
55733
55731
  );
55734
55732
  };
@@ -55910,7 +55908,7 @@ const InputCellWrapper = ({
55910
55908
  columnAlignment,
55911
55909
  testId
55912
55910
  }
55913
- ) : cell2.type === "NumberInput" ? /* @__PURE__ */ jsx(NumberInputCell, { cell: cell2, testId }) : cell2.type === "DateInput" ? /* @__PURE__ */ jsx(InputCell, { cell: cell2, testId, type: "date" }) : cell2.type === "Select" ? /* @__PURE__ */ jsx(
55911
+ ) : cell2.type === "NumberInput" ? /* @__PURE__ */ jsx(NumberInputCell, { cell: cell2, testId }) : cell2.type === "Select" ? /* @__PURE__ */ jsx(
55914
55912
  SelectCell,
55915
55913
  {
55916
55914
  cell: cell2,
@@ -56092,7 +56090,6 @@ const CellWrapper = ({
56092
56090
  switch (cell2.type) {
56093
56091
  case "Input":
56094
56092
  case "NumberInput":
56095
- case "DateInput":
56096
56093
  case "Select":
56097
56094
  return /* @__PURE__ */ jsx(
56098
56095
  InputCellWrapper,
@@ -70544,6 +70541,209 @@ const UnitInput = ({
70544
70541
  }
70545
70542
  );
70546
70543
  };
70544
+ const STRUCTURE_TYPE = Object.freeze({
70545
+ ARRAY: "array",
70546
+ OBJECT: "object"
70547
+ });
70548
+ const getUnitCells = ({
70549
+ tableDef,
70550
+ displayedUnits,
70551
+ handleUnitChange,
70552
+ oldStructureType
70553
+ }) => {
70554
+ return tableDef.map(({ convertible, unitKey, key: key2 }, ix) => {
70555
+ var _a;
70556
+ if (!convertible) {
70557
+ return { value: "" };
70558
+ }
70559
+ const oldUnit = oldStructureType === STRUCTURE_TYPE.ARRAY ? displayedUnits[ix] : displayedUnits[key2];
70560
+ const options = (_a = getAltUnitsListByQuantity(unitKey)) == null ? void 0 : _a.map(
70561
+ ({ unit: unit2, label: label2 }) => ({
70562
+ label: label2,
70563
+ value: unit2
70564
+ })
70565
+ );
70566
+ const onChange = ({
70567
+ target: { value: newUnit }
70568
+ }) => {
70569
+ if (newUnit === oldUnit) {
70570
+ return;
70571
+ }
70572
+ handleUnitChange(key2, newUnit, ix);
70573
+ };
70574
+ return {
70575
+ value: oldUnit,
70576
+ options,
70577
+ type: "Select",
70578
+ onChange
70579
+ };
70580
+ });
70581
+ };
70582
+ const getHeaders = ({ tableDef }) => tableDef.map(({ header: header2 }) => ({
70583
+ value: header2
70584
+ }));
70585
+ const onConvertData = (data, displayedUnits, tableDef, oldStructureType) => {
70586
+ if (!(data == null ? void 0 : data.length))
70587
+ return [];
70588
+ let storedUnits;
70589
+ const tableData = cloneDeep(data);
70590
+ if (oldStructureType) {
70591
+ [storedUnits] = tableData.splice(0, 1);
70592
+ }
70593
+ const convertedTable = tableData.map((row2) => {
70594
+ const convertedRow = tableDef.reduce((prev2, colDef, columnIx) => {
70595
+ const { key: key2, defaultValue } = colDef;
70596
+ const unitTo = oldStructureType === STRUCTURE_TYPE.ARRAY ? (
70597
+ // @ts-ignore TODO Peter B
70598
+ displayedUnits[columnIx]
70599
+ ) : (
70600
+ // @ts-ignore TODO Peter B
70601
+ displayedUnits[key2]
70602
+ );
70603
+ const unitFrom = oldStructureType === STRUCTURE_TYPE.ARRAY ? (
70604
+ // @ts-ignore TODO Peter B
70605
+ storedUnits[columnIx]
70606
+ ) : (
70607
+ // @ts-ignore TODO Peter B
70608
+ storedUnits == null ? void 0 : storedUnits[key2]
70609
+ );
70610
+ const value = oldStructureType === STRUCTURE_TYPE.ARRAY ? row2[columnIx] : row2[key2];
70611
+ let displayedValue = value ?? defaultValue;
70612
+ if (unitFrom && unitTo) {
70613
+ displayedValue = convertAndGetValue(displayedValue, unitTo, unitFrom);
70614
+ }
70615
+ if (oldStructureType) {
70616
+ if (oldStructureType === STRUCTURE_TYPE.ARRAY) {
70617
+ row2[columnIx] = displayedValue;
70618
+ return row2;
70619
+ }
70620
+ } else {
70621
+ if (isValueWithUnit(value) && unitTo) {
70622
+ const convertedValue = convertAndGetValue(displayedValue, unitTo);
70623
+ displayedValue = isNumeric(convertedValue) ? withUnit(convertedValue, unitTo) : displayedValue;
70624
+ }
70625
+ }
70626
+ return {
70627
+ ...prev2,
70628
+ [key2]: displayedValue
70629
+ };
70630
+ }, {});
70631
+ return convertedRow;
70632
+ });
70633
+ return oldStructureType ? [displayedUnits, ...convertedTable] : convertedTable;
70634
+ };
70635
+ const addRowHeader = (addRow, data, displayedUnits) => ({
70636
+ label: "Add",
70637
+ icon: "plus",
70638
+ primary: true,
70639
+ onClick: () => addRow(data, displayedUnits),
70640
+ testId: "lithology-table-add-new-row"
70641
+ });
70642
+ const getDisplayedUnits = (tableDef, unitTemplate, oldStructureType) => {
70643
+ if (oldStructureType === STRUCTURE_TYPE.ARRAY) {
70644
+ return tableDef.reduce((prev2, curr, ix) => {
70645
+ const { unitKey } = curr;
70646
+ prev2[ix] = unitTemplate[unitKey];
70647
+ return prev2;
70648
+ }, []);
70649
+ }
70650
+ return tableDef.reduce((prev2, curr) => {
70651
+ const { key: key2, unitKey } = curr;
70652
+ return {
70653
+ ...prev2,
70654
+ [key2]: unitTemplate[unitKey]
70655
+ };
70656
+ }, {});
70657
+ };
70658
+ const buildTable = ({
70659
+ rows,
70660
+ tableDef,
70661
+ displayedUnits,
70662
+ handleUnitChange,
70663
+ tableActions,
70664
+ oldStructureType = STRUCTURE_TYPE.OBJECT
70665
+ }) => {
70666
+ if (!rows) {
70667
+ return {
70668
+ rows: [],
70669
+ headers: []
70670
+ };
70671
+ }
70672
+ const { addRow } = tableActions;
70673
+ const headers = [
70674
+ {
70675
+ cells: getHeaders({ tableDef }),
70676
+ actions: addRow ? [addRowHeader(addRow, rows, displayedUnits)] : []
70677
+ },
70678
+ {
70679
+ cells: getUnitCells({
70680
+ tableDef,
70681
+ displayedUnits,
70682
+ handleUnitChange,
70683
+ oldStructureType
70684
+ })
70685
+ }
70686
+ ];
70687
+ return {
70688
+ headers,
70689
+ rows
70690
+ };
70691
+ };
70692
+ const UnitTable = ({
70693
+ data,
70694
+ unitTemplate,
70695
+ tableDef,
70696
+ convertToCells,
70697
+ tableActions,
70698
+ testId,
70699
+ oldStructureType = STRUCTURE_TYPE.OBJECT
70700
+ }) => {
70701
+ const [displayedUnits, setDisplayedUnits] = useState(getDisplayedUnits(tableDef, unitTemplate, oldStructureType));
70702
+ useEffect(() => {
70703
+ setDisplayedUnits(
70704
+ getDisplayedUnits(tableDef, unitTemplate, oldStructureType)
70705
+ );
70706
+ }, [unitTemplate]);
70707
+ const handleUnitChange = (key2, unit2, ix) => {
70708
+ if (oldStructureType === STRUCTURE_TYPE.ARRAY) {
70709
+ setDisplayedUnits((prev2) => {
70710
+ const newUnits = [...prev2];
70711
+ newUnits[ix] = unit2;
70712
+ return newUnits;
70713
+ });
70714
+ } else {
70715
+ setDisplayedUnits((prev2) => ({ ...prev2, [key2]: unit2 }));
70716
+ }
70717
+ };
70718
+ const { headers, rows } = useMemo$1(
70719
+ () => buildTable({
70720
+ rows: convertToCells(
70721
+ onConvertData(data, displayedUnits, tableDef, oldStructureType),
70722
+ displayedUnits
70723
+ ),
70724
+ tableDef,
70725
+ displayedUnits,
70726
+ handleUnitChange,
70727
+ tableActions,
70728
+ oldStructureType
70729
+ }),
70730
+ [displayedUnits, data]
70731
+ );
70732
+ return /* @__PURE__ */ jsx(
70733
+ Table,
70734
+ {
70735
+ table: {
70736
+ testId,
70737
+ headers,
70738
+ rows,
70739
+ columnAlignment: tableDef.map((def) => def.columnAlignment),
70740
+ columnWidths: tableDef.map((def) => def.columnWidth),
70741
+ fixedWidth: "auto"
70742
+ },
70743
+ onListReorder: (tableActions == null ? void 0 : tableActions.reorderComponents) || void 0
70744
+ }
70745
+ );
70746
+ };
70547
70747
  export {
70548
70748
  Accordion,
70549
70749
  AccordionWithDefaultToggle,
@@ -70623,6 +70823,7 @@ export {
70623
70823
  Tree,
70624
70824
  TriggerType,
70625
70825
  UnitInput,
70826
+ UnitTable,
70626
70827
  dismissToast,
70627
70828
  readFile,
70628
70829
  toast,