@svelte-lean/table 0.10.0 → 0.11.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @svelte-lean/table
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 84e0055: A paginated `DataTable` loading without rows draws a page of placeholder rows by default (its page size, at most 25) instead of five, so the pager and whatever follows the table stand where they will be once the rows arrive. An unpaginated table still draws five; `skeletonRows` still sets the number.
8
+
9
+ ### Patch Changes
10
+
11
+ - 8ba61b8: A paginated `DataTable` on a page that no longer exists moves to the last page there is. The model already drew the last page, but the state kept the old index, so a manual table whose last page emptied (its last row approved or deleted) showed "page 23 of 23" while it kept asking the server for page 24 and drew it empty. Once the table is neither `loading` nor `fetching`, `state.pageIndex` now follows and `onStateChange` fires.
12
+
3
13
  ## 0.10.0
4
14
 
5
15
  No changes in this release.
@@ -104,7 +104,7 @@
104
104
  onExpandedRowsChange,
105
105
  loading = false,
106
106
  fetching = false,
107
- skeletonRows = 5,
107
+ skeletonRows,
108
108
  error,
109
109
  onRetry,
110
110
  empty,
@@ -180,6 +180,19 @@
180
180
  const m = $derived({ ...en, ...messages });
181
181
  const cols = $derived(table.visibleColumns);
182
182
  const model = $derived(table.model);
183
+ /**
184
+ * A page that no longer exists is left for the last one there is. When the rows of the last
185
+ * page go — a filter elsewhere, the last row on it approved, the total of a manual table
186
+ * shrinking — the model draws the last page that remains, and the state follows it, so a
187
+ * manual table's `onStateChange` asks for that page instead of drawing the empty one it asked
188
+ * for. Not while the table loads or fetches: a page count read before the answer arrives is
189
+ * not the data's.
190
+ */
191
+ $effect(() => {
192
+ if (loading || fetching || !pagination) return;
193
+ const last = model.pageIndex;
194
+ if (last < s.pageIndex) untrack(() => table.setPage(last));
195
+ });
183
196
  /** The expand toggle has a column of its own when asked for and when anything can expand. */
184
197
  const expander = $derived(expandColumn && (!!rowDetails || !!getSubRows));
185
198
  /** Every column of a full-width row: the leading control columns and the data columns. */
@@ -510,6 +523,8 @@
510
523
  const GRID_MAX = 480;
511
524
  const GRID_MIN = 48;
512
525
  const MEASURE_ROWS = 30;
526
+ /** The most placeholder rows a loading page draws when `skeletonRows` is not given. */
527
+ const MAX_PLACEHOLDERS = 25;
513
528
  const grid = $derived(layout === 'grid');
514
529
  let measured = $state<Record<string, number>>({});
515
530
  function gridWidth(col: Column<T>): number {
@@ -873,9 +888,17 @@
873
888
  manual && rowCount !== undefined ? rowCount + headerRowCount : undefined
874
889
  );
875
890
  const pageSizes = $derived([...new Set([...pageSizeOptions, s.pageSize])]);
891
+ /**
892
+ * A paged table loading draws a page of placeholders (at most 25, a screenful and more), so
893
+ * the pager and whatever follows the table stand where they will be once the rows arrive; five
894
+ * stood in for a page of twenty, and everything below moved when it came.
895
+ */
896
+ const skeletonCount = $derived(
897
+ skeletonRows ?? (pagination && s.pageSize > 0 ? Math.min(s.pageSize, MAX_PLACEHOLDERS) : 5)
898
+ );
876
899
  const skeleton = $derived(
877
900
  loading && !model.rows.length
878
- ? Array.from({ length: Math.max(0, skeletonRows) }, (_, i) => i)
901
+ ? Array.from({ length: Math.max(0, skeletonCount) }, (_, i) => i)
879
902
  : []
880
903
  );
881
904
  const emptyContext = $derived({
package/dist/types.d.ts CHANGED
@@ -268,7 +268,10 @@ export interface TableProps<T> {
268
268
  onExpandedRowsChange?: (rows: RowId[]) => void;
269
269
  loading?: boolean;
270
270
  fetching?: boolean;
271
- /** Skeleton rows drawn while `loading` and no row is present. */
271
+ /**
272
+ * Skeleton rows drawn while `loading` and no row is present. Default: the page size, at most
273
+ * 25, when paginated (so nothing below the table moves when the rows arrive); otherwise 5.
274
+ */
272
275
  skeletonRows?: number;
273
276
  error?: string;
274
277
  onRetry?: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svelte-lean/table",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "A Svelte-native table and data-grid engine that ships only the features you use.",
5
5
  "license": "MIT",
6
6
  "author": "Ömer Say",