@lavalogic/scoria 0.11.5 → 0.11.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.
@@ -4,7 +4,7 @@
4
4
  import Action from '../../../../Action.svelte';
5
5
  import Portal from '../../../../Portal.svelte';
6
6
  import { ToastContext } from '../../../../../Contexts/ToastContext.svelte.js';
7
- import { refWrapper } from '../../../../../Helpers/Helpers.svelte.js';
7
+ import { asyncMap, refWrapper } from '../../../../../Helpers/Helpers.svelte.js';
8
8
  import { Colour, ColourSet } from '../../../../../scss/colours.js';
9
9
  import { Size } from '../../../../../Types/Internal/Size.js';
10
10
  import { Validity } from '../../../../../Types/Internal/Validity.js';
@@ -17,14 +17,13 @@
17
17
  </script>
18
18
 
19
19
  <script lang="ts" generics="T extends object">
20
- import { getContext, tick, untrack } from 'svelte';
21
- import TableAction, { type ActionsTableCell } from './TableAction.svelte';
22
20
  import type { ActionsDef } from '../../../Types/Columns/Definitions/Actions/ActionsDef.svelte.js';
23
21
  import type { TableActionButton } from '../../../Types/Columns/TableActionButton.js';
24
- import type { TableCell } from '../../../Types/Columns/TableCell.js';
25
22
  import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
26
23
  import { MultiFocusEdge } from '../../../Types/Focus/MultiFocusEdge.js';
27
24
  import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
25
+ import { getContext, tick, untrack } from 'svelte';
26
+ import TableAction, { type ActionsTableCell } from './TableAction.svelte';
28
27
 
29
28
  const { cell }: ActionsCellProps<T> = $props();
30
29
 
@@ -165,15 +164,23 @@
165
164
  />
166
165
  </div>
167
166
  {#if thisPopupIsVisibile}
168
- <Portal>
169
- <div bind:this={popupRef} class="popup" style="--y: {y}px; --x: {x}px;">
170
- <div class="action-container">
171
- {#each actions as action (action.getLabel(cell.row.original, cell.row.visibleIndex))}
172
- <TableAction {action} {cell} />
173
- {/each}
167
+ {@const awaitedActions = asyncMap<TableActionButton<T>, [TableActionButton<T>, string]>(
168
+ actions,
169
+ async (item) => {
170
+ return [item, await item.getLabel(cell.row.original, cell.row.visibleIndex)];
171
+ }
172
+ )}
173
+ {#await awaitedActions then actions}
174
+ <Portal>
175
+ <div bind:this={popupRef} class="popup" style="--y: {y}px; --x: {x}px;">
176
+ <div class="action-container">
177
+ {#each actions as [action, label] (label)}
178
+ <TableAction {action} {cell} />
179
+ {/each}
180
+ </div>
174
181
  </div>
175
- </div>
176
- </Portal>
182
+ </Portal>
183
+ {/await}
177
184
  {/if}
178
185
  </td>
179
186
 
@@ -5,18 +5,18 @@
5
5
  ContextMenuContext,
6
6
  type IContextMenuOption
7
7
  } from '../../Contexts/ContextMenuContext.svelte.js';
8
- import { setContext, getContext, untrack, onMount, tick } from 'svelte';
8
+ import { refWrapper } from '../../Helpers/Helpers.svelte.js';
9
+ import { getContext, onMount, setContext, tick, untrack } from 'svelte';
9
10
  import LoadingOverlay from '../LoadingOverlay.svelte';
11
+ import { shownPopup } from './Body/Rows/Columns/ActionsCell.svelte';
12
+ import TableBody, { type HeightData } from './Body/TableBody.svelte';
13
+ import TableHead from './Headers/TableHead.svelte';
14
+ import TableFooter from './Misc/TableFooter.svelte';
15
+ import TableHorizontalBar from './Misc/TableHorizontalBar.svelte';
16
+ import TableSidebar from './Misc/TableSidebar.svelte';
10
17
  import { TableContext } from './Types/Context/TableContext.svelte.js';
11
18
  import { PaginationType } from './Types/Pagination/PaginationType.js';
12
19
  import { ToolbarPosition } from './Types/Toolbar/ToolbarPosition.js';
13
- import { refWrapper } from '../../Helpers/Helpers.svelte.js';
14
- import TableHorizontalBar from './Misc/TableHorizontalBar.svelte';
15
- import TableSidebar from './Misc/TableSidebar.svelte';
16
- import TableFooter from './Misc/TableFooter.svelte';
17
- import TableHead from './Headers/TableHead.svelte';
18
- import TableBody, { type HeightData } from './Body/TableBody.svelte';
19
- import { shownPopup } from './Body/Rows/Columns/ActionsCell.svelte';
20
20
 
21
21
  declare global {
22
22
  interface HTMLElementEventMap {
@@ -247,20 +247,6 @@
247
247
  }
248
248
  });
249
249
 
250
- $effect(() => {
251
- if (tableContext.dataRepo?.data) {
252
- untrack(() => {
253
- if (
254
- tableContext.paginationRepo?.paginationState.pageIndex != undefined &&
255
- tableContext.paginationRepo?.paginationState.pageSize != undefined
256
- ) {
257
- tableContext.updateSelectedItems();
258
- tableContext.resetHighlightedRows();
259
- }
260
- });
261
- }
262
- });
263
-
264
250
  const leftTotalSize = $derived(tableContext.table.getLeftTotalSize());
265
251
  const centreTotalSize = $derived(tableContext.table.getCenterTotalSize());
266
252
  const rightTotalSize = $derived(tableContext.table.getRightTotalSize());
@@ -148,7 +148,8 @@ export declare class TableContext<T extends object> {
148
148
  get filteredIndices(): number[];
149
149
  set filteredIndices(v: number[]);
150
150
  readonly filteredData: T[];
151
- readonly sortedData: T[];
151
+ private _sortedData;
152
+ get sortedData(): T[];
152
153
  readonly sortedRowModel: RowModel<T>;
153
154
  _currentPageData: T[];
154
155
  get currentPageData(): T[];
@@ -1,6 +1,6 @@
1
1
  import { browser, dev } from '$app/environment';
2
2
  import { asyncAll, asyncFilterIndices, asyncSleep, getCanvasContext, getErrorMessage } from '../../../../Helpers/Helpers.svelte.js';
3
- import { tick } from 'svelte';
3
+ import { tick, untrack } from 'svelte';
4
4
  import { SvelteMap, SvelteSet } from 'svelte/reactivity';
5
5
  import { ColumnType } from '../Columns/ColumnType.js';
6
6
  import { AccessorDef } from '../Columns/Definitions/Accessors/AccessorDef.svelte.js';
@@ -66,17 +66,57 @@ export class TableContext {
66
66
  }
67
67
  this._dataRepo = $state(dataRepo);
68
68
  // this.dataRepo.forceRefresh = this.forceVisibilityUpdate;
69
- const [_currentPageData, _originalRowIndices] = $derived.by(() => {
70
- const x = dataRepo.paginationType == PaginationType.Local
71
- ? this.sortedData.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive)
72
- : (this.sortedData ?? []);
73
- const y = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
74
- return [x, y];
69
+ const [_sortedData, _currentPageData, _originalRowIndices] = $derived.by(() => {
70
+ const sd = (() => {
71
+ if (this.paginationRepo?.paginationType == PaginationType.Local) {
72
+ const state = this.dataRepo?.sorting ?? [];
73
+ const sortedData = this.showSelectedOnly
74
+ ? // FIXME this will show the selected items by order of insertion to the selectedItems map.
75
+ [...this.selectedItems.values()]
76
+ : this.filteredData.concat();
77
+ sortedData.sort((a, b) => {
78
+ const end = state.length;
79
+ for (let i = 0; i < end; i++) {
80
+ const { id, desc } = state[i];
81
+ const sortingFn = this.getSortingFn(id, desc);
82
+ if (sortingFn) {
83
+ const result = sortingFn(a, b);
84
+ if (result != 0) {
85
+ return result;
86
+ }
87
+ }
88
+ else {
89
+ console.warn('no sorting fn found for ' + id);
90
+ }
91
+ }
92
+ return 0;
93
+ });
94
+ return sortedData;
95
+ }
96
+ return this.filteredData ?? [];
97
+ })();
98
+ const cpd = dataRepo.paginationType == PaginationType.Local
99
+ ? sd.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive)
100
+ : (sd ?? []);
101
+ const ori = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
102
+ return [sd, cpd, ori];
75
103
  });
76
104
  $effect(() => {
105
+ this._sortedData = _sortedData;
77
106
  this._currentPageData = _currentPageData;
78
107
  this._originalRowIndices = _originalRowIndices;
79
108
  });
109
+ $effect(() => {
110
+ if (_currentPageData) {
111
+ untrack(() => {
112
+ if (this.paginationRepo?.paginationState.pageIndex != undefined &&
113
+ this.paginationRepo?.paginationState.pageSize != undefined) {
114
+ this.updateSelectedItems();
115
+ this.resetHighlightedRows();
116
+ }
117
+ });
118
+ }
119
+ });
80
120
  if (defaultColumnDefs.remoteFilters) {
81
121
  this.remoteFilters = defaultColumnDefs.remoteFilters;
82
122
  }
@@ -638,41 +678,17 @@ export class TableContext {
638
678
  }
639
679
  return this.showSelectedOnly ? [...this.selectedItems.values()] : (this.dataRepo?.data ?? []);
640
680
  });
641
- sortedData = $derived.by(() => {
642
- if (this.paginationRepo?.paginationType == PaginationType.Local) {
643
- const state = this.dataRepo?.sorting ?? [];
644
- const sortedData = this.showSelectedOnly
645
- ? // FIXME this will show the selected items by order of insertion to the selectedItems map.
646
- [...this.selectedItems.values()]
647
- : this.filteredData.concat();
648
- sortedData.sort((a, b) => {
649
- const end = state.length;
650
- for (let i = 0; i < end; i++) {
651
- const { id, desc } = state[i];
652
- const sortingFn = this.getSortingFn(id, desc);
653
- if (sortingFn) {
654
- const result = sortingFn(a, b);
655
- if (result != 0) {
656
- return result;
657
- }
658
- }
659
- else {
660
- console.warn('no sorting fn found for ' + id);
661
- }
662
- }
663
- return 0;
664
- });
665
- return sortedData;
666
- }
667
- return this.filteredData ?? [];
668
- });
681
+ _sortedData = $state([]);
682
+ get sortedData() {
683
+ return this._sortedData;
684
+ }
669
685
  sortedRowModel = $derived.by(() => {
670
686
  const rows = this.sortedData.map((item, index) => {
671
687
  const originalIndex = this._originalRowIndices.get(item);
672
688
  const unsortedIndex = originalIndex ?? index;
673
689
  if (originalIndex == null) {
674
- console.log($state.snapshot(this.sortedData));
675
- console.log($state.snapshot(this._originalRowIndices));
690
+ $inspect(this.sortedData);
691
+ $inspect(this._originalRowIndices);
676
692
  throw new Error(`Sorted Data not found in Original Row Indices: original index ${originalIndex}, index ${index}`);
677
693
  }
678
694
  return this.createRow(item, index, unsortedIndex);
@@ -859,7 +875,7 @@ export class TableContext {
859
875
  const item = this.sortedData[index];
860
876
  // HACK: Please find why this is happening and fix it properly
861
877
  if (!item) {
862
- console.warn(`skipping update because there is a data mismatch, page start index: ${pageStartIndex}, current index ${index}, page end index (exlusive) ${pageEndIndexExclusive}`, $state.snapshot(this.sortedData));
878
+ console.warn(`skipping update because there is a data mismatch, page start index: ${pageStartIndex}, current index ${index}, page end index (exclusive) ${pageEndIndexExclusive}`, $state.snapshot(this.sortedData));
863
879
  return;
864
880
  }
865
881
  if (await selectableMethod(item, index)) {
@@ -872,7 +888,7 @@ export class TableContext {
872
888
  const item = this.sortedData[index];
873
889
  // HACK: Please find why this is happening and fix it properly
874
890
  if (!item) {
875
- console.warn(`skipping update because there is a data mismatch, page start index: ${pageStartIndex}, current index ${index}, page end index (exlusive) ${pageEndIndexExclusive}`, $state.snapshot(this.sortedData));
891
+ console.warn(`skipping update because there is a data mismatch, page start index: ${pageStartIndex}, current index ${index}, page end index (exclusive) ${pageEndIndexExclusive}`, $state.snapshot(this.sortedData));
876
892
  return;
877
893
  }
878
894
  updateSelectedItem(item);
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.11.5",
4
+ "version": "0.11.7",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },