@equinor/apollo-components 3.1.2-rowfix.22 → 3.1.2-rowfix.3

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 CHANGED
@@ -661,8 +661,9 @@ function TableHeader({ table, sticky }) {
661
661
  }
662
662
 
663
663
  // src/DataTable/DataTable.tsx
664
+ var import_eds_core_react18 = require("@equinor/eds-core-react");
664
665
  var import_react_table3 = require("@tanstack/react-table");
665
- var import_react7 = require("react");
666
+ var import_react6 = require("react");
666
667
  var import_styled_components16 = __toESM(require("styled-components"));
667
668
 
668
669
  // src/DataTable/components/BasicTable.tsx
@@ -921,8 +922,7 @@ function TableBanner({
921
922
  });
922
923
  }
923
924
 
924
- // src/DataTable/components/VirtualTable.tsx
925
- var import_eds_core_react18 = require("@equinor/eds-core-react");
925
+ // src/DataTable/components/VirtualTableBody.tsx
926
926
  var import_react_virtual = require("@tanstack/react-virtual");
927
927
 
928
928
  // src/DataTable/components/PaddingRow.tsx
@@ -938,9 +938,9 @@ var PaddingRow = (props) => {
938
938
  });
939
939
  };
940
940
 
941
- // src/DataTable/components/VirtualTable.tsx
941
+ // src/DataTable/components/VirtualTableBody.tsx
942
942
  var import_jsx_runtime18 = require("react/jsx-runtime");
943
- function VirtualTable({
943
+ function VirtualTableBody({
944
944
  table,
945
945
  rowConfig,
946
946
  cellConfig,
@@ -951,45 +951,36 @@ function VirtualTable({
951
951
  const { rows } = table.getRowModel();
952
952
  const rowVirtualizer = (0, import_react_virtual.useVirtualizer)({
953
953
  count: rows.length,
954
- estimateSize: () => 48,
955
954
  getScrollElement: () => containerRef.current,
955
+ estimateSize: () => 48,
956
956
  measureElement: (element) => element == null ? void 0 : element.getBoundingClientRect().height,
957
- overscan: 5
957
+ overscan: 2
958
958
  });
959
+ if (!rowVirtualizer)
960
+ return null;
959
961
  const virtualRows = rowVirtualizer.getVirtualItems();
960
962
  const paddingTop = virtualRows.length > 0 ? ((_a = virtualRows == null ? void 0 : virtualRows[0]) == null ? void 0 : _a.start) || 0 : 0;
961
963
  const paddingBottom = virtualRows.length > 0 ? rowVirtualizer.getTotalSize() - (((_b = virtualRows == null ? void 0 : virtualRows[virtualRows.length - 1]) == null ? void 0 : _b.end) || 0) : 0;
962
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_eds_core_react18.Table, {
964
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(TableBody, {
965
+ style: { height: rowVirtualizer.getTotalSize() },
963
966
  children: [
964
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_eds_core_react18.Table.Caption, {
965
- hidden: true,
966
- children: props.tableCaption
967
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PaddingRow, {
968
+ height: paddingTop
967
969
  }),
968
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TableHeader, {
969
- sticky: props.stickyHeader,
970
- table
970
+ rows.length ? virtualRows.map((virtualRow) => {
971
+ const row = rows[virtualRow.index];
972
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TableRow, {
973
+ row,
974
+ rowConfig,
975
+ cellConfig,
976
+ measureElement: rowVirtualizer.measureElement,
977
+ index: virtualRow.index
978
+ }, row.id);
979
+ }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PlaceholderRow, {
980
+ isLoading: props.isLoading
971
981
  }),
972
- /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(TableBody, {
973
- children: [
974
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PaddingRow, {
975
- height: paddingTop
976
- }),
977
- rows.length ? virtualRows.map((virtualRow) => {
978
- const row = rows[virtualRow.index];
979
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TableRow, {
980
- row,
981
- rowConfig,
982
- cellConfig,
983
- index: virtualRow.index,
984
- measureElement: rowVirtualizer.measureElement
985
- }, row.id);
986
- }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PlaceholderRow, {
987
- isLoading: props.isLoading
988
- }),
989
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PaddingRow, {
990
- height: paddingBottom
991
- })
992
- ]
982
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PaddingRow, {
983
+ height: paddingBottom
993
984
  })
994
985
  ]
995
986
  });
@@ -1024,13 +1015,6 @@ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
1024
1015
  return onTableContainerScroll;
1025
1016
  }
1026
1017
 
1027
- // src/DataTable/hooks/useForceRerender.ts
1028
- var import_react6 = require("react");
1029
- function useForceRerender() {
1030
- const [, setTick] = (0, import_react6.useState)(0);
1031
- return (0, import_react6.useCallback)(() => setTick((tick) => tick + 1), []);
1032
- }
1033
-
1034
1018
  // src/DataTable/DataTable.tsx
1035
1019
  var import_jsx_runtime19 = require("react/jsx-runtime");
1036
1020
  var DataTableWrapper = import_styled_components16.default.div`
@@ -1053,12 +1037,12 @@ var DataTableWrapper = import_styled_components16.default.div`
1053
1037
  function DataTable(props) {
1054
1038
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1055
1039
  const { columns, data, bannerConfig, cellConfig, sorting } = props;
1056
- const [internalColumnVisibility, setInternalColumnVisibility] = (0, import_react7.useState)({});
1040
+ const [internalColumnVisibility, setInternalColumnVisibility] = (0, import_react6.useState)({});
1057
1041
  const [columnVisibility, setColumnVisibility] = [
1058
1042
  ((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
1059
1043
  ((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
1060
1044
  ];
1061
- const [internalGlobalFilterState, setInternalGlobalFilterState] = (0, import_react7.useState)("");
1045
+ const [internalGlobalFilterState, setInternalGlobalFilterState] = (0, import_react6.useState)("");
1062
1046
  const [globalFilterState, setGlobalFilterState] = [
1063
1047
  ((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
1064
1048
  ((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
@@ -1067,17 +1051,17 @@ function DataTable(props) {
1067
1051
  function enableGlobalFilter(value) {
1068
1052
  return enableOrUndefined(shouldEnableGlobalFilter, value);
1069
1053
  }
1070
- const [internalSortingState, setInternalSortingState] = (0, import_react7.useState)([]);
1054
+ const [internalSortingState, setInternalSortingState] = (0, import_react6.useState)([]);
1071
1055
  const [sortingState, setSortingState] = [
1072
1056
  ((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
1073
1057
  ((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
1074
1058
  ];
1075
- const [internalRowSelectionState, setInternalRowSelectionState] = (0, import_react7.useState)({});
1059
+ const [internalRowSelectionState, setInternalRowSelectionState] = (0, import_react6.useState)({});
1076
1060
  const [rowSelectionState, setRowSelectionState] = [
1077
1061
  ((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
1078
1062
  ((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
1079
1063
  ];
1080
- const [internalExpandedState, setInternalExpandedState] = (0, import_react7.useState)({});
1064
+ const [internalExpandedState, setInternalExpandedState] = (0, import_react6.useState)({});
1081
1065
  const [expandedState, setExpandedState] = [
1082
1066
  ((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
1083
1067
  ((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
@@ -1120,23 +1104,18 @@ function DataTable(props) {
1120
1104
  getSubRows: props == null ? void 0 : props.getSubRows,
1121
1105
  getRowId: props == null ? void 0 : props.getRowId
1122
1106
  });
1123
- (0, import_react7.useEffect)(() => {
1107
+ (0, import_react6.useEffect)(() => {
1124
1108
  var _a2;
1125
1109
  if ((_a2 = props.expansion) == null ? void 0 : _a2.expandAllByDefault) {
1126
1110
  table.toggleAllRowsExpanded();
1127
1111
  }
1128
1112
  }, [table, (_p = props.expansion) == null ? void 0 : _p.expandAllByDefault]);
1129
1113
  const { isLoading, rowConfig } = props;
1130
- const tableContainerRef = (0, import_react7.useRef)(null);
1114
+ const tableContainerRef = (0, import_react6.useRef)(null);
1131
1115
  const onTableContainerScroll = useFetchMoreOnBottomReached(
1132
1116
  tableContainerRef,
1133
1117
  props.infiniteScroll
1134
1118
  );
1135
- const forceRerender = useForceRerender();
1136
- (0, import_react7.useEffect)(() => {
1137
- if (Boolean(tableContainerRef.current))
1138
- forceRerender();
1139
- }, [tableContainerRef.current === null]);
1140
1119
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DataTableWrapper, {
1141
1120
  height: props == null ? void 0 : props.height,
1142
1121
  width: props == null ? void 0 : props.width,
@@ -1162,14 +1141,26 @@ function DataTable(props) {
1162
1141
  }
1163
1142
  }
1164
1143
  },
1165
- children: (props == null ? void 0 : props.virtual) ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(VirtualTable, {
1166
- containerRef: tableContainerRef,
1167
- tableCaption: props.tableCaption,
1168
- table,
1169
- rowConfig,
1170
- cellConfig,
1171
- isLoading,
1172
- stickyHeader: props.stickyHeader
1144
+ children: (props == null ? void 0 : props.virtual) ? /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_eds_core_react18.Table, {
1145
+ children: [
1146
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_eds_core_react18.Table.Caption, {
1147
+ hidden: true,
1148
+ children: props.tableCaption
1149
+ }),
1150
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(TableHeader, {
1151
+ sticky: props.stickyHeader,
1152
+ table
1153
+ }),
1154
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(VirtualTableBody, {
1155
+ containerRef: tableContainerRef,
1156
+ tableCaption: props.tableCaption,
1157
+ table,
1158
+ rowConfig,
1159
+ cellConfig,
1160
+ isLoading,
1161
+ stickyHeader: props.stickyHeader
1162
+ })
1163
+ ]
1173
1164
  }) : /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(BasicTable, {
1174
1165
  tableCaption: props.tableCaption,
1175
1166
  table,
package/dist/index.mjs CHANGED
@@ -612,6 +612,7 @@ function TableHeader({ table, sticky }) {
612
612
  }
613
613
 
614
614
  // src/DataTable/DataTable.tsx
615
+ import { Table as Table9 } from "@equinor/eds-core-react";
615
616
  import {
616
617
  getCoreRowModel,
617
618
  getExpandedRowModel,
@@ -619,7 +620,7 @@ import {
619
620
  getSortedRowModel,
620
621
  useReactTable
621
622
  } from "@tanstack/react-table";
622
- import { useEffect as useEffect3, useRef as useRef3, useState as useState6 } from "react";
623
+ import { useEffect as useEffect3, useRef as useRef3, useState as useState5 } from "react";
623
624
  import styled16 from "styled-components";
624
625
 
625
626
  // src/DataTable/components/BasicTable.tsx
@@ -878,8 +879,7 @@ function TableBanner({
878
879
  });
879
880
  }
880
881
 
881
- // src/DataTable/components/VirtualTable.tsx
882
- import { Table as Table9 } from "@equinor/eds-core-react";
882
+ // src/DataTable/components/VirtualTableBody.tsx
883
883
  import { useVirtualizer } from "@tanstack/react-virtual";
884
884
 
885
885
  // src/DataTable/components/PaddingRow.tsx
@@ -895,9 +895,9 @@ var PaddingRow = (props) => {
895
895
  });
896
896
  };
897
897
 
898
- // src/DataTable/components/VirtualTable.tsx
898
+ // src/DataTable/components/VirtualTableBody.tsx
899
899
  import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
900
- function VirtualTable({
900
+ function VirtualTableBody({
901
901
  table,
902
902
  rowConfig,
903
903
  cellConfig,
@@ -908,45 +908,36 @@ function VirtualTable({
908
908
  const { rows } = table.getRowModel();
909
909
  const rowVirtualizer = useVirtualizer({
910
910
  count: rows.length,
911
- estimateSize: () => 48,
912
911
  getScrollElement: () => containerRef.current,
912
+ estimateSize: () => 48,
913
913
  measureElement: (element) => element == null ? void 0 : element.getBoundingClientRect().height,
914
- overscan: 5
914
+ overscan: 2
915
915
  });
916
+ if (!rowVirtualizer)
917
+ return null;
916
918
  const virtualRows = rowVirtualizer.getVirtualItems();
917
919
  const paddingTop = virtualRows.length > 0 ? ((_a = virtualRows == null ? void 0 : virtualRows[0]) == null ? void 0 : _a.start) || 0 : 0;
918
920
  const paddingBottom = virtualRows.length > 0 ? rowVirtualizer.getTotalSize() - (((_b = virtualRows == null ? void 0 : virtualRows[virtualRows.length - 1]) == null ? void 0 : _b.end) || 0) : 0;
919
- return /* @__PURE__ */ jsxs10(Table9, {
921
+ return /* @__PURE__ */ jsxs10(TableBody, {
922
+ style: { height: rowVirtualizer.getTotalSize() },
920
923
  children: [
921
- /* @__PURE__ */ jsx18(Table9.Caption, {
922
- hidden: true,
923
- children: props.tableCaption
924
+ /* @__PURE__ */ jsx18(PaddingRow, {
925
+ height: paddingTop
924
926
  }),
925
- /* @__PURE__ */ jsx18(TableHeader, {
926
- sticky: props.stickyHeader,
927
- table
927
+ rows.length ? virtualRows.map((virtualRow) => {
928
+ const row = rows[virtualRow.index];
929
+ return /* @__PURE__ */ jsx18(TableRow, {
930
+ row,
931
+ rowConfig,
932
+ cellConfig,
933
+ measureElement: rowVirtualizer.measureElement,
934
+ index: virtualRow.index
935
+ }, row.id);
936
+ }) : /* @__PURE__ */ jsx18(PlaceholderRow, {
937
+ isLoading: props.isLoading
928
938
  }),
929
- /* @__PURE__ */ jsxs10(TableBody, {
930
- children: [
931
- /* @__PURE__ */ jsx18(PaddingRow, {
932
- height: paddingTop
933
- }),
934
- rows.length ? virtualRows.map((virtualRow) => {
935
- const row = rows[virtualRow.index];
936
- return /* @__PURE__ */ jsx18(TableRow, {
937
- row,
938
- rowConfig,
939
- cellConfig,
940
- index: virtualRow.index,
941
- measureElement: rowVirtualizer.measureElement
942
- }, row.id);
943
- }) : /* @__PURE__ */ jsx18(PlaceholderRow, {
944
- isLoading: props.isLoading
945
- }),
946
- /* @__PURE__ */ jsx18(PaddingRow, {
947
- height: paddingBottom
948
- })
949
- ]
939
+ /* @__PURE__ */ jsx18(PaddingRow, {
940
+ height: paddingBottom
950
941
  })
951
942
  ]
952
943
  });
@@ -981,13 +972,6 @@ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
981
972
  return onTableContainerScroll;
982
973
  }
983
974
 
984
- // src/DataTable/hooks/useForceRerender.ts
985
- import { useCallback as useCallback2, useState as useState5 } from "react";
986
- function useForceRerender() {
987
- const [, setTick] = useState5(0);
988
- return useCallback2(() => setTick((tick) => tick + 1), []);
989
- }
990
-
991
975
  // src/DataTable/DataTable.tsx
992
976
  import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
993
977
  var DataTableWrapper = styled16.div`
@@ -1010,12 +994,12 @@ var DataTableWrapper = styled16.div`
1010
994
  function DataTable(props) {
1011
995
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1012
996
  const { columns, data, bannerConfig, cellConfig, sorting } = props;
1013
- const [internalColumnVisibility, setInternalColumnVisibility] = useState6({});
997
+ const [internalColumnVisibility, setInternalColumnVisibility] = useState5({});
1014
998
  const [columnVisibility, setColumnVisibility] = [
1015
999
  ((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
1016
1000
  ((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
1017
1001
  ];
1018
- const [internalGlobalFilterState, setInternalGlobalFilterState] = useState6("");
1002
+ const [internalGlobalFilterState, setInternalGlobalFilterState] = useState5("");
1019
1003
  const [globalFilterState, setGlobalFilterState] = [
1020
1004
  ((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
1021
1005
  ((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
@@ -1024,17 +1008,17 @@ function DataTable(props) {
1024
1008
  function enableGlobalFilter(value) {
1025
1009
  return enableOrUndefined(shouldEnableGlobalFilter, value);
1026
1010
  }
1027
- const [internalSortingState, setInternalSortingState] = useState6([]);
1011
+ const [internalSortingState, setInternalSortingState] = useState5([]);
1028
1012
  const [sortingState, setSortingState] = [
1029
1013
  ((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
1030
1014
  ((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
1031
1015
  ];
1032
- const [internalRowSelectionState, setInternalRowSelectionState] = useState6({});
1016
+ const [internalRowSelectionState, setInternalRowSelectionState] = useState5({});
1033
1017
  const [rowSelectionState, setRowSelectionState] = [
1034
1018
  ((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
1035
1019
  ((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
1036
1020
  ];
1037
- const [internalExpandedState, setInternalExpandedState] = useState6({});
1021
+ const [internalExpandedState, setInternalExpandedState] = useState5({});
1038
1022
  const [expandedState, setExpandedState] = [
1039
1023
  ((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
1040
1024
  ((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
@@ -1089,11 +1073,6 @@ function DataTable(props) {
1089
1073
  tableContainerRef,
1090
1074
  props.infiniteScroll
1091
1075
  );
1092
- const forceRerender = useForceRerender();
1093
- useEffect3(() => {
1094
- if (Boolean(tableContainerRef.current))
1095
- forceRerender();
1096
- }, [tableContainerRef.current === null]);
1097
1076
  return /* @__PURE__ */ jsxs11(DataTableWrapper, {
1098
1077
  height: props == null ? void 0 : props.height,
1099
1078
  width: props == null ? void 0 : props.width,
@@ -1119,14 +1098,26 @@ function DataTable(props) {
1119
1098
  }
1120
1099
  }
1121
1100
  },
1122
- children: (props == null ? void 0 : props.virtual) ? /* @__PURE__ */ jsx19(VirtualTable, {
1123
- containerRef: tableContainerRef,
1124
- tableCaption: props.tableCaption,
1125
- table,
1126
- rowConfig,
1127
- cellConfig,
1128
- isLoading,
1129
- stickyHeader: props.stickyHeader
1101
+ children: (props == null ? void 0 : props.virtual) ? /* @__PURE__ */ jsxs11(Table9, {
1102
+ children: [
1103
+ /* @__PURE__ */ jsx19(Table9.Caption, {
1104
+ hidden: true,
1105
+ children: props.tableCaption
1106
+ }),
1107
+ /* @__PURE__ */ jsx19(TableHeader, {
1108
+ sticky: props.stickyHeader,
1109
+ table
1110
+ }),
1111
+ /* @__PURE__ */ jsx19(VirtualTableBody, {
1112
+ containerRef: tableContainerRef,
1113
+ tableCaption: props.tableCaption,
1114
+ table,
1115
+ rowConfig,
1116
+ cellConfig,
1117
+ isLoading,
1118
+ stickyHeader: props.stickyHeader
1119
+ })
1120
+ ]
1130
1121
  }) : /* @__PURE__ */ jsx19(BasicTable, {
1131
1122
  tableCaption: props.tableCaption,
1132
1123
  table,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "3.1.2-rowfix.22",
3
+ "version": "3.1.2-rowfix.3",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",