@svelte-lean/table 0.11.0 → 0.12.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,11 @@
1
1
  # @svelte-lean/table
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dba6ebc: `DataTable` takes `measureKey`: change it when what the cells show changes without the rows changing (a masked value revealed in place, a value a cell fetched itself), and the grid measures every row on the page again when idle, so the column widens instead of the value running over the next column. A column only grows; the first value measures nothing extra.
8
+
3
9
  ## 0.11.0
4
10
 
5
11
  ### Minor Changes
@@ -105,6 +105,7 @@
105
105
  loading = false,
106
106
  fetching = false,
107
107
  skeletonRows,
108
+ measureKey,
108
109
  error,
109
110
  onRetry,
110
111
  empty,
@@ -581,6 +582,22 @@
581
582
  whenIdle(() => measure(true, first));
582
583
  });
583
584
  });
585
+ /**
586
+ * A cell's content changed under the same rows (`measureKey`): every row on the page is
587
+ * measured again when idle, so a value revealed in place widens its column instead of
588
+ * running over the next one. Not on the first value: the rows are measured as they come.
589
+ */
590
+ let lastMeasureKey: unknown = undefined;
591
+ let measureKeySeen = false;
592
+ $effect(() => {
593
+ const key = measureKey;
594
+ if (!grid) return;
595
+ untrack(() => {
596
+ if (measureKeySeen && key !== lastMeasureKey) whenIdle(() => measure(true, true, true));
597
+ measureKeySeen = true;
598
+ lastMeasureKey = key;
599
+ });
600
+ });
584
601
  /**
585
602
  * What a body row stands, from the first section once its rows are drawn: the sections the
586
603
  * browser skips assume it, so the page is about as tall before they are drawn as after.
@@ -606,15 +623,15 @@
606
623
  * hidden table inside the root, laid out there with every cell at its max-content width
607
624
  * (`data-measuring`), read, and removed. The live rows are neither restyled nor laid out.
608
625
  */
609
- function measure(whole: boolean, first = true) {
626
+ function measure(whole: boolean, first = true, every = false) {
610
627
  const live = viewport?.firstElementChild as HTMLElement | null;
611
628
  if (!live || !root) return;
612
629
  const leaves = new Set(cols.map((col) => col.id));
613
630
  const rows = [...ownRows()];
614
631
  // The first rows and the header, and for a whole page twenty rows spread over the rest; a pass
615
632
  // over a page whose first rows were measured already (`first` false) takes only the spread.
616
- const sample = first ? rows.slice(0, MEASURE_ROWS) : [];
617
- if (whole && rows.length > MEASURE_ROWS) {
633
+ const sample = every ? rows : first ? rows.slice(0, MEASURE_ROWS) : [];
634
+ if (!every && whole && rows.length > MEASURE_ROWS) {
618
635
  const step = Math.ceil((rows.length - MEASURE_ROWS) / 20);
619
636
  for (let i = MEASURE_ROWS; i < rows.length; i += step) sample.push(rows[i]!);
620
637
  }
package/dist/types.d.ts CHANGED
@@ -273,6 +273,12 @@ export interface TableProps<T> {
273
273
  * 25, when paginated (so nothing below the table moves when the rows arrive); otherwise 5.
274
274
  */
275
275
  skeletonRows?: number;
276
+ /**
277
+ * Changes when what the cells show changes without the rows changing — a masked value
278
+ * revealed in place, a value the cell fetched itself. On each change after the first the grid
279
+ * measures every row on the page again, when idle; a column only grows.
280
+ */
281
+ measureKey?: unknown;
276
282
  error?: string;
277
283
  onRetry?: () => void;
278
284
  empty?: Snippet<[EmptyContext]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svelte-lean/table",
3
- "version": "0.11.0",
3
+ "version": "0.12.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",