@oliasoft-open-source/react-ui-library 5.0.7-beta-1 → 5.0.8-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 +4 -0
- package/dist/index.js +132 -113
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1357,6 +1357,10 @@ export declare interface ITableProps {
|
|
|
1357
1357
|
to: number;
|
|
1358
1358
|
}) => boolean;
|
|
1359
1359
|
table: ITableTableProps;
|
|
1360
|
+
beforeRenderRow?: ({ row, rowIndex, }: {
|
|
1361
|
+
row: TRowType;
|
|
1362
|
+
rowIndex: number;
|
|
1363
|
+
}) => TRowType;
|
|
1360
1364
|
}
|
|
1361
1365
|
|
|
1362
1366
|
declare interface ITableTableProps {
|
package/dist/index.js
CHANGED
|
@@ -169508,6 +169508,7 @@ const Table = (props) => {
|
|
|
169508
169508
|
onListReorder = () => {
|
|
169509
169509
|
},
|
|
169510
169510
|
canListReorder = () => true,
|
|
169511
|
+
beforeRenderRow = null,
|
|
169511
169512
|
table: propTable
|
|
169512
169513
|
} = props;
|
|
169513
169514
|
const {
|
|
@@ -169627,36 +169628,44 @@ const Table = (props) => {
|
|
|
169627
169628
|
`0_${rowIndex}`
|
|
169628
169629
|
);
|
|
169629
169630
|
}) }),
|
|
169630
|
-
/* @__PURE__ */ jsx("tbody", { ref: tbodyRef, children: virtualizer ? virtualizer.getVirtualItems().map((virtualRow2) =>
|
|
169631
|
-
|
|
169632
|
-
|
|
169633
|
-
|
|
169634
|
-
|
|
169635
|
-
|
|
169636
|
-
|
|
169637
|
-
|
|
169638
|
-
|
|
169639
|
-
|
|
169640
|
-
|
|
169641
|
-
|
|
169642
|
-
|
|
169643
|
-
|
|
169644
|
-
|
|
169645
|
-
|
|
169646
|
-
|
|
169647
|
-
|
|
169648
|
-
rowIndex
|
|
169649
|
-
|
|
169650
|
-
|
|
169651
|
-
|
|
169652
|
-
|
|
169653
|
-
|
|
169654
|
-
|
|
169655
|
-
|
|
169656
|
-
|
|
169657
|
-
|
|
169658
|
-
|
|
169659
|
-
|
|
169631
|
+
/* @__PURE__ */ jsx("tbody", { ref: tbodyRef, children: virtualizer ? virtualizer.getVirtualItems().map((virtualRow2) => {
|
|
169632
|
+
const rowIndex = virtualRow2.index;
|
|
169633
|
+
const row2 = rows[rowIndex];
|
|
169634
|
+
const preparedRow = beforeRenderRow ? beforeRenderRow({ row: row2, rowIndex }) : row2;
|
|
169635
|
+
return /* @__PURE__ */ jsx(
|
|
169636
|
+
Row,
|
|
169637
|
+
{
|
|
169638
|
+
rowIndex,
|
|
169639
|
+
row: preparedRow,
|
|
169640
|
+
columnCount,
|
|
169641
|
+
columnWidths,
|
|
169642
|
+
colSpan,
|
|
169643
|
+
hasRowActions: rowActions,
|
|
169644
|
+
columnAlignment,
|
|
169645
|
+
draggableTable: draggable,
|
|
169646
|
+
height: virtualRow2.size,
|
|
169647
|
+
dropDisabled
|
|
169648
|
+
},
|
|
169649
|
+
`1_${rowIndex}`
|
|
169650
|
+
);
|
|
169651
|
+
}) : rows.map((row2, index2) => {
|
|
169652
|
+
const preparedRow = beforeRenderRow ? beforeRenderRow({ row: row2, rowIndex: index2 }) : row2;
|
|
169653
|
+
return /* @__PURE__ */ jsx(
|
|
169654
|
+
Row,
|
|
169655
|
+
{
|
|
169656
|
+
rowIndex: index2,
|
|
169657
|
+
row: preparedRow,
|
|
169658
|
+
columnCount,
|
|
169659
|
+
columnWidths,
|
|
169660
|
+
colSpan,
|
|
169661
|
+
hasRowActions: rowActions,
|
|
169662
|
+
columnAlignment,
|
|
169663
|
+
draggableTable: draggable,
|
|
169664
|
+
dropDisabled
|
|
169665
|
+
},
|
|
169666
|
+
`1_${index2}`
|
|
169667
|
+
);
|
|
169668
|
+
}) })
|
|
169660
169669
|
]
|
|
169661
169670
|
}
|
|
169662
169671
|
) })
|
|
@@ -183882,17 +183891,77 @@ const normalizeUnits = (unitConfig) => unitConfig.reduce(
|
|
|
183882
183891
|
},
|
|
183883
183892
|
{ preferredUnits: {}, storageUnits: {} }
|
|
183884
183893
|
);
|
|
183885
|
-
const
|
|
183886
|
-
|
|
183887
|
-
|
|
183894
|
+
const convertRow = ({
|
|
183895
|
+
row: row2,
|
|
183896
|
+
rowIndex,
|
|
183888
183897
|
selectedUnits,
|
|
183889
183898
|
storageUnits,
|
|
183890
|
-
onChangeUnit,
|
|
183891
183899
|
convertBackToStorageUnit,
|
|
183892
183900
|
enableCosmeticRounding,
|
|
183893
183901
|
enableDisplayRounding
|
|
183902
|
+
}) => ({
|
|
183903
|
+
...row2,
|
|
183904
|
+
cells: row2.cells.map((cell2, cellIndex) => {
|
|
183905
|
+
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")) {
|
|
183906
|
+
const { unitKey, value, formatDisplayValue } = cell2;
|
|
183907
|
+
const roundDisplayValue = enableDisplayRounding && "roundDisplayValue" in cell2 ? cell2 == null ? void 0 : cell2.roundDisplayValue : null;
|
|
183908
|
+
const selectedUnit = selectedUnits[unitKey];
|
|
183909
|
+
const storageUnit = storageUnits[unitKey];
|
|
183910
|
+
const unitChanged = selectedUnit !== storageUnit;
|
|
183911
|
+
const { value: resultValue = value } = convertUnit({
|
|
183912
|
+
value: safeToString(value),
|
|
183913
|
+
unitkey: unitKey,
|
|
183914
|
+
toUnit: selectedUnit,
|
|
183915
|
+
fromUnit: storageUnit
|
|
183916
|
+
});
|
|
183917
|
+
const convertedValue = unitChanged ? resultValue : cell2.value;
|
|
183918
|
+
const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(convertedValue, selectedUnit) : convertedValue;
|
|
183919
|
+
return {
|
|
183920
|
+
...cell2,
|
|
183921
|
+
value: formattedDisplayValue,
|
|
183922
|
+
enableCosmeticRounding,
|
|
183923
|
+
enableDisplayRounding,
|
|
183924
|
+
roundDisplayValue,
|
|
183925
|
+
selectOnFocus: true,
|
|
183926
|
+
onChange: (evt) => {
|
|
183927
|
+
const { value: value2 } = evt.target;
|
|
183928
|
+
const storageUnit2 = storageUnits[unitKey];
|
|
183929
|
+
const selectedUnit2 = selectedUnits[unitKey];
|
|
183930
|
+
const unitChanged2 = selectedUnit2 !== storageUnit2;
|
|
183931
|
+
const nextUnit = convertBackToStorageUnit ? storageUnit2 : selectedUnit2;
|
|
183932
|
+
const { value: resultValue2 = value2 } = convertUnit({
|
|
183933
|
+
value: String(value2),
|
|
183934
|
+
unitkey: unitKey,
|
|
183935
|
+
toUnit: nextUnit,
|
|
183936
|
+
fromUnit: selectedUnit2
|
|
183937
|
+
});
|
|
183938
|
+
const nextValueConverted = unitChanged2 ? resultValue2 : value2;
|
|
183939
|
+
if ("onChange" in cell2) {
|
|
183940
|
+
const { onChange } = cell2;
|
|
183941
|
+
const event = {
|
|
183942
|
+
...evt,
|
|
183943
|
+
target: {
|
|
183944
|
+
...evt.target,
|
|
183945
|
+
value: String(nextValueConverted),
|
|
183946
|
+
rowIndex,
|
|
183947
|
+
cellIndex,
|
|
183948
|
+
unit: nextUnit
|
|
183949
|
+
}
|
|
183950
|
+
};
|
|
183951
|
+
onChange(event);
|
|
183952
|
+
}
|
|
183953
|
+
}
|
|
183954
|
+
};
|
|
183955
|
+
}
|
|
183956
|
+
return cell2;
|
|
183957
|
+
})
|
|
183958
|
+
});
|
|
183959
|
+
const convertHeaderRows = ({
|
|
183960
|
+
headers,
|
|
183961
|
+
selectedUnits,
|
|
183962
|
+
onChangeUnit
|
|
183894
183963
|
}) => {
|
|
183895
|
-
|
|
183964
|
+
return headers ? headers.map((headerRow) => ({
|
|
183896
183965
|
...headerRow,
|
|
183897
183966
|
cells: headerRow.cells.map((headerCell) => {
|
|
183898
183967
|
var _a2;
|
|
@@ -183915,64 +183984,6 @@ const convertVisibleRows = ({
|
|
|
183915
183984
|
return headerCell;
|
|
183916
183985
|
})
|
|
183917
183986
|
})) : [];
|
|
183918
|
-
const convertedRows = rows ? rows.map((row2, rowIndex) => ({
|
|
183919
|
-
...row2,
|
|
183920
|
-
cells: row2.cells.map((cell2, cellIndex) => {
|
|
183921
|
-
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")) {
|
|
183922
|
-
const { unitKey, value, formatDisplayValue } = cell2;
|
|
183923
|
-
const roundDisplayValue = enableDisplayRounding && "roundDisplayValue" in cell2 ? cell2 == null ? void 0 : cell2.roundDisplayValue : null;
|
|
183924
|
-
const selectedUnit = selectedUnits[unitKey];
|
|
183925
|
-
const storageUnit = storageUnits[unitKey];
|
|
183926
|
-
const unitChanged = selectedUnit !== storageUnit;
|
|
183927
|
-
const { value: resultValue = value } = convertUnit({
|
|
183928
|
-
value: safeToString(value),
|
|
183929
|
-
unitkey: unitKey,
|
|
183930
|
-
toUnit: selectedUnit,
|
|
183931
|
-
fromUnit: storageUnit
|
|
183932
|
-
});
|
|
183933
|
-
const convertedValue = unitChanged ? resultValue : cell2.value;
|
|
183934
|
-
const formattedDisplayValue = formatDisplayValue ? formatDisplayValue(convertedValue, selectedUnit) : convertedValue;
|
|
183935
|
-
return {
|
|
183936
|
-
...cell2,
|
|
183937
|
-
value: formattedDisplayValue,
|
|
183938
|
-
enableCosmeticRounding,
|
|
183939
|
-
enableDisplayRounding,
|
|
183940
|
-
roundDisplayValue,
|
|
183941
|
-
selectOnFocus: true,
|
|
183942
|
-
onChange: (evt) => {
|
|
183943
|
-
const { value: value2 } = evt.target;
|
|
183944
|
-
const storageUnit2 = storageUnits[unitKey];
|
|
183945
|
-
const selectedUnit2 = selectedUnits[unitKey];
|
|
183946
|
-
const unitChanged2 = selectedUnit2 !== storageUnit2;
|
|
183947
|
-
const nextUnit = convertBackToStorageUnit ? storageUnit2 : selectedUnit2;
|
|
183948
|
-
const { value: resultValue2 = value2 } = convertUnit({
|
|
183949
|
-
value: String(value2),
|
|
183950
|
-
unitkey: unitKey,
|
|
183951
|
-
toUnit: nextUnit,
|
|
183952
|
-
fromUnit: selectedUnit2
|
|
183953
|
-
});
|
|
183954
|
-
const nextValueConverted = unitChanged2 ? resultValue2 : value2;
|
|
183955
|
-
if ("onChange" in cell2) {
|
|
183956
|
-
const { onChange } = cell2;
|
|
183957
|
-
const event = {
|
|
183958
|
-
...evt,
|
|
183959
|
-
target: {
|
|
183960
|
-
...evt.target,
|
|
183961
|
-
value: String(nextValueConverted),
|
|
183962
|
-
rowIndex,
|
|
183963
|
-
cellIndex,
|
|
183964
|
-
unit: nextUnit
|
|
183965
|
-
}
|
|
183966
|
-
};
|
|
183967
|
-
onChange(event);
|
|
183968
|
-
}
|
|
183969
|
-
}
|
|
183970
|
-
};
|
|
183971
|
-
}
|
|
183972
|
-
return cell2;
|
|
183973
|
-
})
|
|
183974
|
-
})) : [];
|
|
183975
|
-
return { convertedHeaders, convertedRows };
|
|
183976
183987
|
};
|
|
183977
183988
|
const UnitTable = ({
|
|
183978
183989
|
table: table2,
|
|
@@ -183983,7 +183994,7 @@ const UnitTable = ({
|
|
|
183983
183994
|
onListReorder,
|
|
183984
183995
|
canListReorder
|
|
183985
183996
|
}) => {
|
|
183986
|
-
const {
|
|
183997
|
+
const { headers, ...otherProps } = table2;
|
|
183987
183998
|
const { storageUnits, preferredUnits } = normalizeUnits(unitConfig);
|
|
183988
183999
|
const previousPreferredUnits = usePrevious(preferredUnits);
|
|
183989
184000
|
const [selectedUnits, setSelectedUnits] = useState(preferredUnits);
|
|
@@ -184006,18 +184017,26 @@ const UnitTable = ({
|
|
|
184006
184017
|
});
|
|
184007
184018
|
}
|
|
184008
184019
|
};
|
|
184009
|
-
const
|
|
184010
|
-
|
|
184011
|
-
|
|
184012
|
-
|
|
184013
|
-
|
|
184014
|
-
|
|
184015
|
-
|
|
184016
|
-
|
|
184017
|
-
|
|
184018
|
-
|
|
184019
|
-
|
|
184020
|
-
|
|
184020
|
+
const beforeRenderRow = useCallback(
|
|
184021
|
+
({ row: row2, rowIndex }) => {
|
|
184022
|
+
return convertRow({
|
|
184023
|
+
row: row2,
|
|
184024
|
+
rowIndex,
|
|
184025
|
+
selectedUnits,
|
|
184026
|
+
storageUnits,
|
|
184027
|
+
convertBackToStorageUnit,
|
|
184028
|
+
enableCosmeticRounding,
|
|
184029
|
+
enableDisplayRounding
|
|
184030
|
+
});
|
|
184031
|
+
},
|
|
184032
|
+
[
|
|
184033
|
+
selectedUnits,
|
|
184034
|
+
storageUnits,
|
|
184035
|
+
convertBackToStorageUnit,
|
|
184036
|
+
enableCosmeticRounding,
|
|
184037
|
+
enableDisplayRounding
|
|
184038
|
+
]
|
|
184039
|
+
);
|
|
184021
184040
|
useEffect(() => {
|
|
184022
184041
|
const templateChanged = !isEqual$3(preferredUnits, previousPreferredUnits);
|
|
184023
184042
|
if (templateChanged) {
|
|
@@ -184028,22 +184047,22 @@ const UnitTable = ({
|
|
|
184028
184047
|
onChangeUnit({ unitKey, value: newUnit });
|
|
184029
184048
|
}
|
|
184030
184049
|
});
|
|
184031
|
-
setViewData(convertViewData(preferredUnits));
|
|
184032
184050
|
}
|
|
184033
184051
|
}, [unitConfig]);
|
|
184034
|
-
useEffect(() => {
|
|
184035
|
-
setViewData(convertViewData(selectedUnits));
|
|
184036
|
-
}, [table2, selectedUnits]);
|
|
184037
184052
|
return /* @__PURE__ */ jsx(
|
|
184038
184053
|
Table,
|
|
184039
184054
|
{
|
|
184040
184055
|
table: {
|
|
184041
184056
|
...otherProps,
|
|
184042
|
-
headers:
|
|
184043
|
-
|
|
184057
|
+
headers: convertHeaderRows({
|
|
184058
|
+
headers: table2.headers,
|
|
184059
|
+
selectedUnits,
|
|
184060
|
+
onChangeUnit
|
|
184061
|
+
})
|
|
184044
184062
|
},
|
|
184045
184063
|
onListReorder,
|
|
184046
|
-
canListReorder
|
|
184064
|
+
canListReorder,
|
|
184065
|
+
beforeRenderRow
|
|
184047
184066
|
}
|
|
184048
184067
|
);
|
|
184049
184068
|
};
|