svelte-tably 1.0.0-next.18 → 1.0.0-next.19

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.
@@ -44,7 +44,6 @@
44
44
  Expandable: typeof Expandable<T>
45
45
  Row: typeof Row<T>
46
46
  readonly table: TableState<T>
47
- readonly data: T[]
48
47
  }
49
48
 
50
49
  type ContentSnippet = Snippet<[context: ContentCtx<T>]>
@@ -73,7 +72,6 @@
73
72
  >
74
73
 
75
74
  const table = new TableState<T>(properties) as TableState<T>
76
- const data = table.data
77
75
 
78
76
  const virtualization = new Virtualization(table)
79
77
 
@@ -304,7 +302,7 @@
304
302
  </tr>
305
303
  </thead>
306
304
  <tbody>
307
- {#each data.current as row, i}
305
+ {#each table.data as row, i}
308
306
  {#if (csv.selected && table.selected.includes(row)) || !csv.selected}
309
307
  <tr>
310
308
  {#each renderedColumns as column}
@@ -378,12 +376,12 @@
378
376
  data-column={column.id}
379
377
  class:header={isHeader}
380
378
  class:sortable
381
- use:conditional={[isHeader, (node) => data.sortAction(node, column.id)]}
379
+ use:conditional={[isHeader, (node) => table.dataState.sortAction(node, column.id)]}
382
380
  >
383
381
  {@render renderable(column)?.(args[0], args[1])}
384
- {#if isHeader && data.sortby === column.id && sortable}
382
+ {#if isHeader && table.dataState.sortby === column.id && sortable}
385
383
  <span class='sorting-icon'>
386
- {@render chevronSnippet(data.sortReverse ? 0 : 180)}
384
+ {@render chevronSnippet(table.dataState.sortReverse ? 0 : 180)}
387
385
  </span>
388
386
  {/if}
389
387
  </svelte:element>
@@ -405,12 +403,12 @@
405
403
  class:resizeable={isHeader && column.options.resizeable && table.options.resizeable}
406
404
  class:border={i == sticky.length - 1}
407
405
  class:sortable
408
- use:conditional={[isHeader, (node) => data.sortAction(node, column.id)]}
406
+ use:conditional={[isHeader, (node) => table.dataState.sortAction(node, column.id)]}
409
407
  >
410
408
  {@render renderable(column)?.(args[0], args[1])}
411
- {#if isHeader && data.sortby === column.id && sortable}
409
+ {#if isHeader && table.dataState.sortby === column.id && sortable}
412
410
  <span class='sorting-icon'>
413
- {@render chevronSnippet(data.sortReverse ? 0 : 180)}
411
+ {@render chevronSnippet(table.dataState.sortReverse ? 0 : 180)}
414
412
  </span>
415
413
  {/if}
416
414
  </svelte:element>
@@ -429,12 +427,12 @@
429
427
  use:observeColumnWidth={isHeader}
430
428
  class:resizeable={isHeader && column.options.resizeable && table.options.resizeable}
431
429
  class:sortable
432
- use:conditional={[isHeader, (node) => data.sortAction(node, column.id)]}
430
+ use:conditional={[isHeader, (node) => table.dataState.sortAction(node, column.id)]}
433
431
  >
434
432
  {@render renderable(column)?.(args[0], args[1])}
435
- {#if isHeader && data.sortby === column.id && sortable}
433
+ {#if isHeader && table.dataState.sortby === column.id && sortable}
436
434
  <span class='sorting-icon'>
437
- {@render chevronSnippet(data.sortReverse ? 0 : 180)}
435
+ {@render chevronSnippet(table.dataState.sortReverse ? 0 : 180)}
438
436
  </span>
439
437
  {/if}
440
438
  </svelte:element>
@@ -549,7 +547,7 @@
549
547
  id={table.id}
550
548
  class='table svelte-tably'
551
549
  style='--t: {virtualization.virtualTop}px; --b: {virtualization.virtualBottom}px;'
552
- aria-rowcount={data.current.length}
550
+ aria-rowcount={table.data.length}
553
551
  >
554
552
  {#if columns.some(v => v.snippets.header)}
555
553
  <thead class='headers' bind:this={elements.headers}>
@@ -558,7 +556,7 @@
558
556
  (column) => column.snippets.header,
559
557
  () => [{
560
558
  get header() { return true },
561
- get data() { return data.current }
559
+ get data() { return table.data }
562
560
  }],
563
561
  'header'
564
562
  )}
@@ -588,7 +586,7 @@
588
586
  return virtualization.area
589
587
  },
590
588
  get modify() {
591
- return data.origin
589
+ return table.dataState.origin
592
590
  },
593
591
  get startIndex() {
594
592
  return virtualization.topIndex
@@ -607,7 +605,7 @@
607
605
  {@render columnsSnippet(
608
606
  (column) => column.snippets.statusbar,
609
607
  () => [{
610
- get data() { return data.current }
608
+ get data() { return table.data }
611
609
  }],
612
610
  'statusbar'
613
611
  )}
@@ -632,7 +630,7 @@
632
630
  return table
633
631
  },
634
632
  get data() {
635
- return data.current
633
+ return table.data
636
634
  }
637
635
  })}
638
636
  </div>
@@ -681,11 +679,11 @@
681
679
  {#if select}
682
680
  {@render headerSnippet({
683
681
  get isSelected() {
684
- return data.current.length === table.selected?.length && data.current.length > 0
682
+ return table.data.length === table.selected?.length && table.data.length > 0
685
683
  },
686
684
  set isSelected(value) {
687
685
  if (value) {
688
- table.selected = data.current
686
+ table.selected = table.data
689
687
  } else {
690
688
  table.selected = []
691
689
  }
@@ -696,7 +694,7 @@
696
694
  get indeterminate() {
697
695
  return (
698
696
  (table.selected?.length || 0) > 0 &&
699
- data.current.length !== table.selected?.length
697
+ table.data.length !== table.selected?.length
700
698
  )
701
699
  }
702
700
  })}
@@ -727,7 +725,7 @@
727
725
  return item
728
726
  },
729
727
  get data() {
730
- return data.current
728
+ return table.data
731
729
  }
732
730
  })}
733
731
  {/if}
@@ -745,13 +743,13 @@
745
743
  {/if}
746
744
 
747
745
  {#if table.options.auto}
748
- {#each Object.keys(data.current[0] || {}) as key}
746
+ {#each Object.keys(table.data[0] || {}) as key}
749
747
  <Column
750
748
  id={key}
751
749
  value={r => r[key]}
752
750
  header={capitalize(segmentize(key))}
753
751
  sort={
754
- typeof data.current[0]?.[key] === 'number'
752
+ typeof table.data[0]?.[key] === 'number'
755
753
  ? (a, b) => a - b
756
754
  : (a, b) => String(a).localeCompare(String(b))
757
755
  }
@@ -766,9 +764,6 @@
766
764
  Row,
767
765
  get table() {
768
766
  return table
769
- },
770
- get data() {
771
- return data.current
772
767
  }
773
768
  })}
774
769
 
@@ -41,7 +41,7 @@ export class Data {
41
41
  if (sort === true) {
42
42
  sort = (a, b) => String(a).localeCompare(String(b));
43
43
  }
44
- if (this.#table.data.sortReverse) {
44
+ if (this.sortReverse) {
45
45
  this.sorted = this.origin.toSorted((a, b) => sort(value(b), value(a)));
46
46
  }
47
47
  else {
@@ -6,7 +6,8 @@ import { assign, boundAssign, boundPick, pick } from '../utility.svelte.js';
6
6
  export class TableState {
7
7
  #props = {};
8
8
  id = $state();
9
- data;
9
+ dataState = $state({});
10
+ data = $derived(this.dataState.current ?? []);
10
11
  columns = $state({});
11
12
  panels = $state({});
12
13
  expandable = $state();
@@ -43,7 +44,7 @@ export class TableState {
43
44
  this.positions.hidden = this.positions.hidden.filter((column) => column !== state);
44
45
  };
45
46
  if (state.defaults.sortby)
46
- this.data.sortBy(key);
47
+ this.dataState.sortBy(key);
47
48
  if (state.options.fixed) {
48
49
  this.positions.fixed.push(state);
49
50
  return clean;
@@ -71,7 +72,7 @@ export class TableState {
71
72
  constructor(tableProps) {
72
73
  this.#props = tableProps;
73
74
  this.id = tableProps.id ?? Array.from({ length: 12 }, () => String.fromCharCode(Math.floor(Math.random() * 26) + 97)).join('');
74
- this.data = new Data(this, tableProps);
75
+ this.dataState = new Data(this, tableProps);
75
76
  setContext('svelte-tably', this);
76
77
  }
77
78
  }
@@ -19,7 +19,7 @@ export class Virtualization {
19
19
  constructor(table) {
20
20
  let ticked = $state(false);
21
21
  $effect.pre(() => {
22
- table.data.origin;
22
+ table.dataState.origin;
23
23
  untrack(() => {
24
24
  ticked = false;
25
25
  requestAnimationFrame(() => ticked = true);
@@ -28,7 +28,7 @@ export class Virtualization {
28
28
  $effect(() => {
29
29
  if (!ticked)
30
30
  return;
31
- table.data.current;
31
+ table.dataState.current;
32
32
  untrack(() => {
33
33
  if (!this.viewport.element) {
34
34
  this.#heightPerItem = 8;
@@ -50,8 +50,8 @@ export class Virtualization {
50
50
  return;
51
51
  this.scrollTop;
52
52
  this.#heightPerItem;
53
- table.data.current.length;
54
- table.data.current;
53
+ table.dataState.current.length;
54
+ table.dataState.current;
55
55
  untrack(() => {
56
56
  if (!waitAnimationFrame) {
57
57
  setTimeout(() => {
@@ -59,7 +59,7 @@ export class Virtualization {
59
59
  let virtualTop = Math.max(this.scrollTop - this.#spacing, 0);
60
60
  virtualTop -= virtualTop % this.#heightPerItem;
61
61
  this.#virtualTop = virtualTop;
62
- let virtualBottom = this.#heightPerItem * table.data.current.length - virtualTop - this.#spacing * 4;
62
+ let virtualBottom = this.#heightPerItem * table.dataState.current.length - virtualTop - this.#spacing * 4;
63
63
  virtualBottom = Math.max(virtualBottom, 0);
64
64
  this.#virtualBottom = virtualBottom;
65
65
  }, 1000 / 60);
@@ -70,16 +70,16 @@ export class Virtualization {
70
70
  $effect(() => {
71
71
  if (!ticked)
72
72
  return;
73
- table.data.sortReverse;
74
- table.data.sortby;
73
+ table.dataState.sortReverse;
74
+ table.dataState.sortby;
75
75
  this.#heightPerItem;
76
76
  this.#virtualTop;
77
- table.data.current.length;
78
- table.data.current;
77
+ table.dataState.current.length;
78
+ table.dataState.current;
79
79
  untrack(() => {
80
80
  this.#topIndex = Math.round(this.#virtualTop / this.#heightPerItem || 0);
81
81
  const end = this.#topIndex + this.#renderItemLength;
82
- this.#area = table.data.current.slice(this.#topIndex, end);
82
+ this.#area = table.dataState.current.slice(this.#topIndex, end);
83
83
  });
84
84
  });
85
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-tably",
3
- "version": "1.0.0-next.18",
3
+ "version": "1.0.0-next.19",
4
4
  "repository": "github:refzlund/svelte-tably",
5
5
  "homepage": "https://github.com/Refzlund/svelte-tably",
6
6
  "bugs": {