pixelize-design-library 2.3.1-beta.5 → 2.3.1-beta.7

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.
@@ -43,6 +43,15 @@ var __importStar = (this && this.__importStar) || (function () {
43
43
  return result;
44
44
  };
45
45
  })();
46
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
47
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
48
+ if (ar || !(i in from)) {
49
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
50
+ ar[i] = from[i];
51
+ }
52
+ }
53
+ return to.concat(ar || Array.prototype.slice.call(from));
54
+ };
46
55
  var __importDefault = (this && this.__importDefault) || function (mod) {
47
56
  return (mod && mod.__esModule) ? mod : { "default": mod };
48
57
  };
@@ -131,6 +140,32 @@ function Table(_a) {
131
140
  // Grouping is chosen by the user in Table Settings > Group and persisted to
132
141
  // preferences (`json.groupBy`); there is no `groupBy` prop.
133
142
  var _35 = (0, react_1.useState)(undefined), groupByState = _35[0], setGroupByState = _35[1];
143
+ // Grouped "Load more" accumulates pages here so loading more ADDS rows to the
144
+ // groups (server pagination replaces `data` each fetch). Reset on fresh loads
145
+ // (search / filter / sort / page-size). Only used in grouped + groupLoadMore mode.
146
+ var _36 = (0, react_1.useState)([]), accumulatedRows = _36[0], setAccumulatedRows = _36[1];
147
+ var pendingLoadMoreRef = (0, react_1.useRef)(false);
148
+ (0, react_1.useEffect)(function () {
149
+ if (!groupLoadMore)
150
+ return;
151
+ if (!pendingLoadMoreRef.current) {
152
+ // Fresh load (initial / search / filter / sort / page-size) → reset.
153
+ setAccumulatedRows(tableData);
154
+ return;
155
+ }
156
+ // A "Load more" is in flight. The parent may re-emit the SAME page (new array
157
+ // reference) on intermediate re-renders before the next page actually arrives,
158
+ // so only consume the pending flag once genuinely new rows (by id) show up.
159
+ setAccumulatedRows(function (prev) {
160
+ var seen = new Set(prev.map(function (r) { return r.id; }));
161
+ var newRows = tableData.filter(function (r) { return !seen.has(r.id); });
162
+ if (newRows.length === 0)
163
+ return prev; // same page re-emitted — keep waiting
164
+ pendingLoadMoreRef.current = false;
165
+ return __spreadArray(__spreadArray([], prev, true), newRows, true);
166
+ });
167
+ // eslint-disable-next-line react-hooks/exhaustive-deps
168
+ }, [tableData, groupLoadMore]);
134
169
  (0, react_1.useEffect)(function () {
135
170
  if (tablePreferences === null || tablePreferences === void 0 ? void 0 : tablePreferences.density)
136
171
  setDensityState(tablePreferences.density);
@@ -159,19 +194,22 @@ function Table(_a) {
159
194
  var isGrouped = !!groupByState;
160
195
  // Infinite scroll (server mode, not grouped): load more on scroll-near-bottom.
161
196
  var canInfinite = infiniteScroll && !isGrouped;
162
- // Grouped "Load more": chunked, button-triggered loading that merges into groups.
197
+ // Grouped "Load more": the accumulated pages back the grouped board so loading
198
+ // more grows the groups instead of replacing them.
199
+ var loadMoreBase = isGrouped && groupLoadMore ? accumulatedRows : tableData;
163
200
  var hasMoreEffective = typeof hasMore === "boolean"
164
201
  ? hasMore
165
202
  : isServerPagination
166
- ? tableData.length < totalRecords
203
+ ? loadMoreBase.length < totalRecords
167
204
  : false;
168
205
  var canGroupLoadMore = isGrouped && groupLoadMore && hasMoreEffective;
169
206
  var groupPalette = (0, react_1.useMemo)(function () { return (0, table_1.buildTablePalette)(theme); }, [theme]);
170
207
  var groupedSource = (0, react_1.useMemo)(function () {
171
208
  if (!isGrouped)
172
209
  return [];
173
- return (0, table_1.searchAndSortData)((0, table_1.SortMultiColumnData)(tableData, columnsSort), columnsSearch);
174
- }, [isGrouped, tableData, columnsSort, columnsSearch]);
210
+ var src = groupLoadMore ? accumulatedRows : tableData;
211
+ return (0, table_1.searchAndSortData)((0, table_1.SortMultiColumnData)(src, columnsSort), columnsSearch);
212
+ }, [isGrouped, groupLoadMore, accumulatedRows, tableData, columnsSort, columnsSearch]);
175
213
  var renderGroups = (0, react_1.useMemo)(function () {
176
214
  if (!isGrouped)
177
215
  return undefined;
@@ -210,11 +248,14 @@ function Table(_a) {
210
248
  if (isLoadingMore || isTableLoading || !hasMoreEffective)
211
249
  return;
212
250
  var chunk = loadMoreChunkSize !== null && loadMoreChunkSize !== void 0 ? loadMoreChunkSize : rowsPerPage;
213
- var nextPage = Math.floor(tableData.length / (chunk || 1)) + 1;
214
- var lastRecord = tableData.length > 0 ? tableData[tableData.length - 1] : undefined;
251
+ // Next page is derived from how many rows we've already accumulated, so each
252
+ // click advances (fixes "always fromIndex 2") and the parent can replace `data`.
253
+ var nextPage = Math.floor(loadMoreBase.length / (chunk || 1)) + 1;
254
+ var lastRecord = loadMoreBase.length > 0 ? loadMoreBase[loadMoreBase.length - 1] : undefined;
255
+ pendingLoadMoreRef.current = true;
215
256
  (_a = onPaginationRef.current) === null || _a === void 0 ? void 0 : _a.call(onPaginationRef, nextPage, chunk, lastRecord, "next");
216
257
  };
217
- var groupLoadMoreCaption = totalRecords > 0 ? "Showing ".concat(tableData.length, " of ").concat(totalRecords) : undefined;
258
+ var groupLoadMoreCaption = totalRecords > 0 ? "Showing ".concat(loadMoreBase.length, " of ").concat(totalRecords) : undefined;
218
259
  var tablePaginationText = (0, react_1.useMemo)(function () { return isServerPagination
219
260
  ? "".concat(startRow + 1, " - ").concat(Math.min(startRow + rowsPerPage, totalRecords), " of ").concat(totalRecords)
220
261
  : "".concat(startRow + 1, " - ").concat(endRow > tableData.length ? tableData.length : endRow, " of ").concat(tableData.length); }, [startRow, rowsPerPage, totalRecords, endRow, tableData.length]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "2.3.1-beta.5",
3
+ "version": "2.3.1-beta.7",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",