@lavalogic/scoria 0.38.14 → 0.38.15

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.
@@ -115,20 +115,34 @@
115
115
  }
116
116
  const current = tableContext.paginationRepo.paginationState.pageIndex + 1;
117
117
  const last = tableContext.lastPage;
118
+ // Empty / no-results case: render a single "1" button rather than
119
+ // a "0" button. `lastPage` is a 1-indexed count, never 0; a
120
+ // misbehaving data repo that returns 0 would otherwise leak
121
+ // through to a "Previous 0 1 Next" strip (see the page-0
122
+ // regression captured in image 2 of the bug report).
123
+ if (last < 1) {
124
+ pageButtons = [1];
125
+ return;
126
+ }
118
127
  // `pages` accumulates the dedup'd, sorted button set. The minimum
119
128
  // the user always sees between the Previous and Next arrows is the
120
129
  // current page, the next page (when one exists), and the last
121
130
  // page. On top of that we still surface a small window around the
122
- // current page for visual context.
131
+ // current page for visual context. Every value pushed is clamped
132
+ // to `[1, last]` defensively so an out-of-range current page (e.g.
133
+ // a stale `pageIndex` waiting for the next remote reload to
134
+ // settle) cannot resurface a page-0 button.
123
135
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
124
136
  const pages = new Set<number>();
125
137
  const windowStart = Math.max(1, Math.min(current - 2, last - 4));
126
138
  for (let i = windowStart; i < windowStart + 5 && i <= last; i++) {
127
139
  pages.add(i);
128
140
  }
129
- pages.add(current);
130
- if (current + 1 <= last) {
131
- pages.add(current + 1);
141
+ if (current >= 1 && current <= last) {
142
+ pages.add(current);
143
+ if (current + 1 <= last) {
144
+ pages.add(current + 1);
145
+ }
132
146
  }
133
147
  pages.add(last);
134
148
  pageButtons = [...pages].sort((a, b) => a - b);
@@ -235,7 +235,7 @@ export class BuiltInRemoteRepository extends TableDataRepository {
235
235
  const transformed = this._applyResponseTransform(raw);
236
236
  this._data = [...transformed.rows];
237
237
  this._totalRows = transformed.totalRows;
238
- this._lastPage = Math.max(0, Math.ceil(transformed.totalRows / this.paginationState.pageSize) - 1);
238
+ this._lastPage = Math.max(1, Math.ceil(transformed.totalRows / this.paginationState.pageSize));
239
239
  }
240
240
  catch (e) {
241
241
  if (e.name === 'AbortError') {
@@ -490,7 +490,7 @@ export class CustomRemoteRepository extends TableDataRepository {
490
490
  }
491
491
  this._data = [...response.rows];
492
492
  this._totalRows = response.totalRows;
493
- this._lastPage = Math.max(0, Math.ceil(response.totalRows / this.paginationState.pageSize) - 1);
493
+ this._lastPage = Math.max(1, Math.ceil(response.totalRows / this.paginationState.pageSize));
494
494
  }
495
495
  catch (e) {
496
496
  if (e.name === 'AbortError') {
@@ -91,9 +91,15 @@ export declare class LocalTableDataRepository<T extends object> extends TableDat
91
91
  /** Clears every active filter value (keeps filter modes intact). */
92
92
  readonly resetFilters: () => void;
93
93
  /**
94
- * Sets the page size and clamps the current page index so the new
95
- * page count covers the current view. Accepts a string so a raw
96
- * `<select>` value can be passed through without parsing first.
94
+ * Sets the page size and resets the page index to 0 (page 1). A
95
+ * page-size change is a "show me the start of the list at this
96
+ * density" action; clamping the previous page index forward instead
97
+ * (e.g. page 5 of size 20 -> page 5 of size 100) leaves the user on
98
+ * an arbitrary window of the new page-sized result, which does not
99
+ * match the user's mental model.
100
+ *
101
+ * Accepts a string so a raw `<select>` value can be passed through
102
+ * without parsing first.
97
103
  */
98
104
  setPageSize: (size: number | string) => void;
99
105
  /** Jumps to the given 1-based page number, clamped to the last page. */
@@ -219,9 +219,15 @@ export class LocalTableDataRepository extends TableDataRepository {
219
219
  this.resetToFirstPage();
220
220
  };
221
221
  /**
222
- * Sets the page size and clamps the current page index so the new
223
- * page count covers the current view. Accepts a string so a raw
224
- * `<select>` value can be passed through without parsing first.
222
+ * Sets the page size and resets the page index to 0 (page 1). A
223
+ * page-size change is a "show me the start of the list at this
224
+ * density" action; clamping the previous page index forward instead
225
+ * (e.g. page 5 of size 20 -> page 5 of size 100) leaves the user on
226
+ * an arbitrary window of the new page-sized result, which does not
227
+ * match the user's mental model.
228
+ *
229
+ * Accepts a string so a raw `<select>` value can be passed through
230
+ * without parsing first.
225
231
  */
226
232
  setPageSize = (size) => {
227
233
  if (typeof size === 'string') {
@@ -231,10 +237,9 @@ export class LocalTableDataRepository extends TableDataRepository {
231
237
  console.warn('page size is nan');
232
238
  return;
233
239
  }
234
- const lastIndex = Math.ceil(this._dataRef.value.length / size) - 1;
235
240
  this.paginationState = {
236
241
  pageSize: size,
237
- pageIndex: Math.max(0, Math.min(this.paginationState.pageIndex, lastIndex)),
242
+ pageIndex: 0,
238
243
  };
239
244
  };
240
245
  /** Jumps to the given 1-based page number, clamped to the last page. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lavalogic/scoria",
3
3
  "description": "Svelte components used for the FloWMS Web Frontend",
4
- "version": "0.38.14",
4
+ "version": "0.38.15",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },