@lavalogic/scoria 0.0.28 → 0.0.29

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.
@@ -105,7 +105,7 @@
105
105
 
106
106
  <!-- svelte-ignore a11y_mouse_events_have_key_events -->
107
107
  <td
108
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
108
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
109
109
  tabIndex={hasValue ? 0 : undefined}
110
110
  class="focusable"
111
111
  class:multifocus={hasValue && focusDetails.isMultiFocused}
@@ -168,7 +168,7 @@
168
168
  <Portal>
169
169
  <div bind:this={popupRef} class="popup" style="--y: {y}px; --x: {x}px;">
170
170
  <div class="action-container">
171
- {#each actions as action (action.getLabel(cell.row.original, cell.row.index))}
171
+ {#each actions as action (action.getLabel(cell.row.original, cell.row.visibleIndex))}
172
172
  <TableAction {action} {cell} />
173
173
  {/each}
174
174
  </div>
@@ -58,7 +58,7 @@
58
58
 
59
59
  <!-- svelte-ignore a11y_mouse_events_have_key_events -->
60
60
  <td
61
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
61
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
62
62
  tabIndex={0}
63
63
  class="focusable"
64
64
  class:multifocus={focusDetails.isMultiFocused}
@@ -94,7 +94,7 @@
94
94
  {#each values as value}
95
95
  {@const colourPromise = (cell.column.columnDef as BubbleDef<T>).getColour?.(
96
96
  cell.row.original,
97
- cell.row.index,
97
+ cell.row.originalIndex,
98
98
  value
99
99
  )}
100
100
 
@@ -28,7 +28,7 @@
28
28
  );
29
29
 
30
30
  const enabled: boolean | Promise<boolean> = $derived(
31
- cell.column.columnDef.isEnabled?.(cell.row.original, cell.row.index)
31
+ cell.column.columnDef.isEnabled?.(cell.row.original, cell.row.originalIndex)
32
32
  );
33
33
  </script>
34
34
 
@@ -71,7 +71,7 @@
71
71
  {#snippet action(enabled: boolean)}
72
72
  <div class="noninteractive">
73
73
  <Action
74
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
74
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
75
75
  style={focusDetails.outline}
76
76
  disabled={!enabled}
77
77
  border={false}
@@ -41,7 +41,7 @@ class:top={focusDetails.topEdge}
41
41
  class:right={focusDetails.rightEdge}
42
42
  class:bottom={focusDetails.bottomEdge} -->
43
43
  <td
44
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
44
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
45
45
  tabIndex={hasValue ? 0 : undefined}
46
46
  class="focusable"
47
47
  style={focusDetails.outline}
@@ -57,13 +57,13 @@
57
57
  });
58
58
 
59
59
  const colours = $derived(
60
- cell.column.columnDef.getColour?.(cell.row.original, cell.row.index, value)
60
+ cell.column.columnDef.getColour?.(cell.row.original, cell.row.originalIndex, value)
61
61
  );
62
62
  </script>
63
63
 
64
64
  <!-- svelte-ignore a11y_mouse_events_have_key_events -->
65
65
  <td
66
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
66
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
67
67
  tabIndex={0}
68
68
  class="focusable"
69
69
  class:multifocus={focusDetails.isMultiFocused}
@@ -25,7 +25,7 @@
25
25
  const { action, cell }: TableActionProps<T> = $props();
26
26
 
27
27
  const isEnabledPromise: boolean | Promise<boolean> = $derived.by(() => {
28
- const disabled = action.isDisabled?.(cell.row.original, cell.row.index);
28
+ const disabled = action.isDisabled?.(cell.row.original, cell.row.originalIndex);
29
29
 
30
30
  if (disabled != null) {
31
31
  if (typeof disabled == 'boolean') {
@@ -37,14 +37,14 @@
37
37
  return (
38
38
  (cell.column.columnDef as ActionsDef<T>).isEnabled?.(
39
39
  cell.row.original,
40
- cell.row.index,
40
+ cell.row.originalIndex,
41
41
  action
42
42
  ) ?? true
43
43
  );
44
44
  });
45
45
 
46
46
  const labelPromise: Promise<string> = $derived.by(() => {
47
- const result = action.getLabel(cell.row.original, cell.row.index);
47
+ const result = action.getLabel(cell.row.original, cell.row.originalIndex);
48
48
 
49
49
  if (typeof result == 'object') {
50
50
  return result.then((it) => it);
@@ -61,12 +61,12 @@
61
61
  size={Size.Medium}
62
62
  colourSet={(cell.column.columnDef as ActionsDef<T>).getColourSet?.(
63
63
  cell.row.original,
64
- cell.row.index,
64
+ cell.row.originalIndex,
65
65
  action
66
66
  ) ?? ColourSet.Secondary}
67
67
  disabled={!isEnabled}
68
68
  onclick={() => {
69
- action.callback(cell.row.original, cell.row.index);
69
+ action.callback(cell.row.original, cell.row.originalIndex);
70
70
  }}>{label}</Button
71
71
  >
72
72
  {:catch e}
@@ -95,7 +95,7 @@
95
95
  >
96
96
  <input
97
97
  bind:this={inputRef}
98
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
98
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
99
99
  {onchange}
100
100
  type="checkbox"
101
101
  checked={!!value || undefined}
@@ -95,7 +95,7 @@
95
95
  <CurrentComponent {cell} />
96
96
  {:else}
97
97
  {@const valueOrComponentPromise =
98
- cell.column.columnDef.accessorFn?.(cell.row.original, cell.row.index) ??
98
+ cell.column.columnDef.accessorFn?.(cell.row.original, cell.row.originalIndex) ??
99
99
  cell.row.original[cell.column.id as keyof typeof cell.row.original] ??
100
100
  null}
101
101
 
@@ -27,7 +27,7 @@
27
27
 
28
28
  const columnDef = $derived(cell.column.columnDef);
29
29
  const coordinates: CellCoordinates = $derived({
30
- row: cell.row.index,
30
+ row: cell.row.visibleIndex,
31
31
  column: columnDef.index,
32
32
  id: columnDef.id as string & keyof T
33
33
  });
@@ -59,7 +59,7 @@
59
59
 
60
60
  let tdref: HTMLTableCellElement | undefined = $state();
61
61
 
62
- const id = $derived(`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`);
62
+ const id = $derived(`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`);
63
63
  function handleSingleClick(event?: Event) {
64
64
  if (
65
65
  editable &&
@@ -252,7 +252,7 @@
252
252
 
253
253
  <td class="input-cell">
254
254
  <NumberInput
255
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
255
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
256
256
  min={(cell.column.columnDef as NumberInputDef<T>).min}
257
257
  max={(cell.column.columnDef as NumberInputDef<T>).max}
258
258
  variant={InputVariant.Table}
@@ -269,7 +269,7 @@
269
269
 
270
270
  <td
271
271
  style={focusDetails.outline}
272
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
272
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
273
273
  onmousedown={(e) => {
274
274
  // start focus only on left click
275
275
  if (e.button === 0) {
@@ -212,7 +212,7 @@
212
212
  labelProp="label"
213
213
  valueAsObject={columnDef.valueAsObject as true}
214
214
  selectedValue={value}
215
- query={(v) => columnDef.query(v, cell.row.original, cell.row.index)}
215
+ query={(v) => columnDef.query(v, cell.row.original, cell.row.originalIndex)}
216
216
  bind:options={lastOptions}
217
217
  onfocus={addKeydownEvent}
218
218
  onchange={(newValue) => {
@@ -235,7 +235,7 @@
235
235
  style={focusDetails.outline}
236
236
  bind:this={tdref}
237
237
  tabIndex="0"
238
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
238
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
239
239
  class="focusable editable"
240
240
  class:multifocus={focusDetails.isMultiFocused}
241
241
  class:multifocus-start={focusDetails.isMultiFocusStart}
@@ -33,7 +33,7 @@
33
33
  const isSelectable = $derived(
34
34
  (cell.column.columnDef as RowSelectionDef<T>).isSelectable?.(
35
35
  cell.row.original,
36
- cell.row.index
36
+ cell.row.originalIndex
37
37
  ) ?? true
38
38
  );
39
39
 
@@ -97,7 +97,7 @@
97
97
 
98
98
  {#snippet input(isSelectable: boolean)}
99
99
  <input
100
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
100
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
101
101
  bind:this={inputRef}
102
102
  {onchange}
103
103
  type="checkbox"
@@ -249,7 +249,7 @@
249
249
  bind:this={tdref}
250
250
  tabIndex="0"
251
251
  style={focusDetails.outline}
252
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
252
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
253
253
  class="focusable editable"
254
254
  class:multifocus={focusDetails.isMultiFocused}
255
255
  class:multifocus-start={focusDetails.isMultiFocusStart}
@@ -258,7 +258,7 @@
258
258
  <!-- {#if true} -->
259
259
  <td class="input-cell">
260
260
  <TextInput
261
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
261
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
262
262
  onkeydown={handleInputKeydown}
263
263
  variant={InputVariant.Table}
264
264
  bind:value={tempTextValue}
@@ -278,7 +278,7 @@
278
278
  {:else}
279
279
  <!-- svelte-ignore a11y_mouse_events_have_key_events -->
280
280
  <td
281
- id={`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`}
281
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
282
282
  style={focusDetails.outline}
283
283
  onmousedown={(e) => {
284
284
  // start focus only on left click
@@ -87,7 +87,9 @@
87
87
  });
88
88
  });
89
89
 
90
- const thisId = $derived(`${tableContext.tableName}-cell-${cell.row.index}-${cell.column.id}`);
90
+ const thisId = $derived(
91
+ `${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`
92
+ );
91
93
 
92
94
  function onclose() {
93
95
  tableContext.setOpenModalCoordinates(null);
@@ -55,7 +55,7 @@
55
55
 
56
56
  let prevExpandedColumnDef: ExpandDef<T, object> | undefined = $state();
57
57
 
58
- const rowIndex = $derived(cells[0] && cells[0].row.index);
58
+ const rowIndex = $derived(cells[0] && cells[0].row.visibleIndex);
59
59
  const highlighted = $derived(
60
60
  rowIndex != undefined &&
61
61
  tableContext.highlightedItems.has(tableContext.selectionExtractor(row.original))
@@ -85,12 +85,12 @@
85
85
  prevExpandedColumnDef = expandedColumnDef;
86
86
  innerColumnDefs = expandedColumnDef.getInnerColumnDefs(
87
87
  cells[0].row.original,
88
- cells[0].row.index
88
+ cells[0].row.originalIndex
89
89
  );
90
90
 
91
91
  innerDataPromise = expandedColumnDef.accessorFn!(
92
92
  cells[0].row.original,
93
- cells[0].row.index
93
+ cells[0].row.originalIndex
94
94
  ) as Promise<object[]>;
95
95
  innerTableName = expandedColumnDef.innerTableName;
96
96
  } else if (
@@ -125,7 +125,7 @@ onMouseLeave={onMouseLeave} -->
125
125
  }}
126
126
  />
127
127
  {/if}
128
- {#each cells as cell (`${cell.id}-${cell.row.index}`)}
128
+ {#each cells as cell (`${cell.id}-${cell.row.visibleIndex}`)}
129
129
  <TableColumn {cell} {expandedColumnDef} {onExpandChange} />
130
130
  {/each}
131
131
  </tr>
@@ -2,7 +2,8 @@ import type { TableCell } from '../Columns/TableCell.js';
2
2
  export interface Row<T extends object> {
3
3
  getValue: (columnId: string) => any;
4
4
  original: T;
5
- index: number;
5
+ visibleIndex: number;
6
+ originalIndex: number;
6
7
  id: string;
7
8
  getLeftVisibleCells: () => TableCell<T>[];
8
9
  getRightVisibleCells: () => TableCell<T>[];
@@ -541,7 +541,8 @@ export class TableContext {
541
541
  const row = {
542
542
  getValue: (key) => this.columnDefsById.get(key).accessorFn?.(item, unsortedIndex) ?? item[key],
543
543
  original: item,
544
- index,
544
+ visibleIndex: index,
545
+ originalIndex: unsortedIndex,
545
546
  id: index.toString(),
546
547
  getLeftVisibleCells: () => leftVisibleCells,
547
548
  getRightVisibleCells: () => rightVisibleCells,
@@ -598,10 +599,12 @@ export class TableContext {
598
599
  paginationRowModel = $derived.by(() => {
599
600
  const sortedData = this._currentPageData;
600
601
  const rows = sortedData.map((item, index) => {
602
+ const unsortedIndex = this.originalRowIndices.get(item) ?? index;
601
603
  const row = {
602
604
  getValue: (key) => this.columnDefsById.get(key).accessorFn?.(item, index) ?? item[key],
603
605
  original: item,
604
- index,
606
+ visibleIndex: index,
607
+ originalIndex: unsortedIndex,
605
608
  id: index.toString(),
606
609
  getLeftVisibleCells: () => leftVisibleCells,
607
610
  getRightVisibleCells: () => rightVisibleCells,
@@ -1607,10 +1610,10 @@ export class TableContext {
1607
1610
  return;
1608
1611
  }
1609
1612
  const rows = this.paginationRowModel.rows;
1610
- const endRowIndex = rows.findIndex((row) => row.index === this.focusEnd.row);
1613
+ const endRowIndex = rows.findIndex((row) => row.visibleIndex === this.focusEnd.row);
1611
1614
  this.focusEnd = {
1612
1615
  ...this.focusEnd,
1613
- row: rows[Math.max(Math.min(endRowIndex + offset, rows.length - 1), 0)].index
1616
+ row: rows[Math.max(Math.min(endRowIndex + offset, rows.length - 1), 0)].visibleIndex
1614
1617
  };
1615
1618
  }
1616
1619
  _moveFocusRow(offset) {
@@ -1620,8 +1623,8 @@ export class TableContext {
1620
1623
  }
1621
1624
  const newEndRowIndex = (() => {
1622
1625
  const rows = this.paginationRowModel.rows;
1623
- const endRowIndex = rows.findIndex((row) => row.index === this.focusStart.row);
1624
- return rows[Math.max(Math.min(endRowIndex + offset, rows.length - 1), 0)].index;
1626
+ const endRowIndex = rows.findIndex((row) => row.visibleIndex === this.focusStart.row);
1627
+ return rows[Math.max(Math.min(endRowIndex + offset, rows.length - 1), 0)].visibleIndex;
1625
1628
  })();
1626
1629
  this.moveFocus({ ...this.focusStart, row: newEndRowIndex });
1627
1630
  }
@@ -1634,8 +1637,8 @@ export class TableContext {
1634
1637
  const { row: startRowIndexId, column: startColumnIndex } = this.focusStart;
1635
1638
  const { row: endRowIndexId, column: endColumnIndex } = this.focusEnd;
1636
1639
  const model = this.sortedRowModel;
1637
- const startRowIndex = model?.rows.findIndex((row) => row.index === startRowIndexId) ?? -1;
1638
- const endRowIndex = model?.rows.findIndex((row) => row.index === endRowIndexId) ?? -1;
1640
+ const startRowIndex = model?.rows.findIndex((row) => row.visibleIndex === startRowIndexId) ?? -1;
1641
+ const endRowIndex = model?.rows.findIndex((row) => row.visibleIndex === endRowIndexId) ?? -1;
1639
1642
  if (!model || startRowIndex == -1 || endRowIndex == -1) {
1640
1643
  return;
1641
1644
  }
@@ -1719,10 +1722,11 @@ export class TableContext {
1719
1722
  if (this.focusStart && this.focusEnd) {
1720
1723
  const { row: startRowIndexId, column: startColumnIndex } = this.focusStart;
1721
1724
  const { row: endRowIndexId, column: endColumnIndex } = this.focusEnd;
1722
- const model = this.sortedRowModel;
1723
- const startRowIndex = model?.rows.findIndex((row) => row.index === startRowIndexId) ?? -1;
1724
- const endRowIndex = model?.rows.findIndex((row) => row.index === endRowIndexId) ?? -1;
1725
- if (!this.dataRepo || startRowIndex == -1 || endRowIndex == -1) {
1725
+ // const model = this._currentPageData;
1726
+ const model = this.paginationRowModel;
1727
+ const startRowIndex = model?.rows.findIndex((row) => row.visibleIndex === startRowIndexId) ?? -1;
1728
+ const endRowIndex = model?.rows.findIndex((row) => row.visibleIndex === endRowIndexId) ?? -1;
1729
+ if (!this._currentPageData?.length || startRowIndex == -1 || endRowIndex == -1) {
1726
1730
  throw new Error(`copy was missing one of the two indices. First: ${startRowIndex}, second: ${endRowIndex}`);
1727
1731
  }
1728
1732
  const minRowIndex = Math.min(startRowIndex, endRowIndex);
@@ -1738,8 +1742,9 @@ export class TableContext {
1738
1742
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
1739
1743
  const indices = new Map();
1740
1744
  for (let i = minRowIndex; i <= maxRowIndex; i++) {
1741
- const itemIndex = model.rows[i].index;
1742
- const item = this.sortedData[itemIndex];
1745
+ const row = model.rows[i];
1746
+ const item = row.original;
1747
+ const itemIndex = row.originalIndex;
1743
1748
  selectedRows.push(item);
1744
1749
  indices.set(item, itemIndex);
1745
1750
  }
@@ -23,7 +23,7 @@ export class TableFocusDetails {
23
23
  this._tableContext = v;
24
24
  }
25
25
  _coordinates = $derived({
26
- row: this.cell.row.index,
26
+ row: this.cell.row.visibleIndex,
27
27
  column: this.cell.column.columnDef.index,
28
28
  id: this.cell.column.columnDef.id
29
29
  });
@@ -31,7 +31,7 @@ export class TableFocusDetails {
31
31
  return this._coordinates;
32
32
  }
33
33
  _isMultiFocused = $derived(this.tableContext.focusedColumnIds.has(this.cell.column.columnDef.id) &&
34
- this.tableContext.focusedRowIndexIds.has(this.cell.row.index));
34
+ this.tableContext.focusedRowIndexIds.has(this.cell.row.visibleIndex));
35
35
  get isMultiFocused() {
36
36
  return this._isMultiFocused;
37
37
  }
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.0.28",
4
+ "version": "0.0.29",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },