@lavalogic/scoria 0.22.2 → 0.22.3

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.
@@ -225,6 +225,15 @@ export declare class TableContext<T extends object, RowIdType extends Primitive>
225
225
  private createRow;
226
226
  private columnDefReturnsTextValue;
227
227
  private _updateLocalStorageSettings;
228
+ /**
229
+ * Columns in visual display order: pinned-left → center → pinned-right,
230
+ * preserving memory order within each section. Only includes visible columns.
231
+ */
232
+ private get _visualColumns();
233
+ /** Returns the visual index of the column with the given id, or -1 if not found. */
234
+ columnVisualIndex(id: string): number;
235
+ get focusStartVisualColumn(): number;
236
+ get focusEndVisualColumn(): number;
228
237
  private _moveFocusEndRow;
229
238
  private _moveFocusRow;
230
239
  private getHighlightedRowData;
@@ -170,8 +170,8 @@ export class TableContext {
170
170
  this._focusedColumnIds = new Set();
171
171
  return;
172
172
  }
173
- const { row: startRowIndexId, column: startColumnIndex } = this.focusStart;
174
- const { row: endRowIndexId, column: endColumnIndex } = this.focusEnd;
173
+ const { row: startRowIndexId } = this.focusStart;
174
+ const { row: endRowIndexId } = this.focusEnd;
175
175
  const model = this.paginationRowModel;
176
176
  if (current === latest_pageColData) {
177
177
  const startRowIndex = model.rows.findIndex((row) => row.visibleIndex === startRowIndexId);
@@ -185,20 +185,14 @@ export class TableContext {
185
185
  }
186
186
  const minRowIndex = Math.min(startRowIndex, endRowIndex);
187
187
  const maxRowIndex = Math.max(startRowIndex, endRowIndex);
188
- const minColumnIndex = Math.min(startColumnIndex, endColumnIndex);
189
- const maxColumnIndex = Math.max(startColumnIndex, endColumnIndex);
188
+ const startVisualIndex = this.columnVisualIndex(this.focusStart.id);
189
+ const endVisualIndex = this.columnVisualIndex(this.focusEnd.id);
190
+ const minVisualIndex = Math.min(startVisualIndex, endVisualIndex);
191
+ const maxVisualIndex = Math.max(startVisualIndex, endVisualIndex);
190
192
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
191
193
  const affectedColumns = new Set();
192
- const visibility = this.columnVisibility;
193
- this.columnDefs
194
- .filter((it) => 'index' in it &&
195
- visibility[it.id] !== false &&
196
- // TODO handle pinning behaviour
197
- // !columnPinning.left?.includes(it.id) &&
198
- // !columnPinning.right?.includes(it.id) &&
199
- // (!('columnType' in it) || it.columnType === undefined || it.columnType === 'Accessor') &&
200
- it.index >= minColumnIndex &&
201
- it.index <= maxColumnIndex)
194
+ this._visualColumns
195
+ .slice(minVisualIndex, maxVisualIndex + 1)
202
196
  .forEach((it) => affectedColumns.add(it.id));
203
197
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
204
198
  const indices = new Set();
@@ -1780,36 +1774,21 @@ export class TableContext {
1780
1774
  if (!this.focusEnd) {
1781
1775
  return;
1782
1776
  }
1783
- const visibility = this.columnVisibility;
1784
- const columnDefs = this.columnDefs;
1785
- const currentIndex = this.focusEnd.column;
1786
- let index = 0;
1787
- while (index < currentIndex) {
1788
- const newId = columnDefs[index].id;
1789
- if (newId && visibility[newId] !== false) {
1790
- this.focusEnd = { ...this.focusEnd, column: index };
1791
- return;
1792
- }
1793
- ++index;
1777
+ const visualCols = this._visualColumns;
1778
+ if (visualCols.length > 0) {
1779
+ const first = visualCols[0];
1780
+ this.focusEnd = { ...this.focusEnd, id: first.id, column: first.index };
1794
1781
  }
1795
1782
  };
1796
1783
  moveToStart = () => {
1797
1784
  if (!this.focusStart) {
1798
1785
  return;
1799
1786
  }
1800
- const visibility = this.columnVisibility;
1801
- const columnDefs = this.columnDefs;
1802
- const current = this.focusStart.column;
1803
- let index = 0;
1804
- while (index < current) {
1805
- const newId = columnDefs[index].id;
1806
- if (newId && visibility[newId] !== false) {
1807
- this.moveFocus({ ...this.focusStart, id: newId, column: index });
1808
- return;
1809
- }
1810
- ++index;
1787
+ const visualCols = this._visualColumns;
1788
+ if (visualCols.length > 0) {
1789
+ const first = visualCols[0];
1790
+ this.moveFocus({ ...this.focusStart, id: first.id, column: first.index });
1811
1791
  }
1812
- //otherwise return without doing anything
1813
1792
  };
1814
1793
  focusToEnd = () => {
1815
1794
  if (!this.allowCopy) {
@@ -1818,38 +1797,21 @@ export class TableContext {
1818
1797
  if (!this.focusEnd) {
1819
1798
  return;
1820
1799
  }
1821
- const current = this.focusEnd;
1822
- const visibility = this.columnVisibility;
1823
- const columnDefs = this.columnDefs;
1824
- const currentIndex = current.column;
1825
- let index = columnDefs.length - 1;
1826
- while (index > currentIndex) {
1827
- const newId = columnDefs[index].id;
1828
- if (newId && visibility[newId] !== false) {
1829
- this.focusEnd = { ...this.focusEnd, column: index };
1830
- return;
1831
- }
1832
- --index;
1800
+ const visualCols = this._visualColumns;
1801
+ if (visualCols.length > 0) {
1802
+ const last = visualCols[visualCols.length - 1];
1803
+ this.focusEnd = { ...this.focusEnd, id: last.id, column: last.index };
1833
1804
  }
1834
- this.focusEnd = current;
1835
1805
  };
1836
1806
  moveToEnd = () => {
1837
1807
  if (!this.focusStart) {
1838
1808
  return;
1839
1809
  }
1840
- const visibility = this.columnVisibility;
1841
- const columnDefs = this.columnDefs;
1842
- const current = this.focusStart.column;
1843
- let index = columnDefs.length - 1;
1844
- while (index > current) {
1845
- const newId = columnDefs[index].id;
1846
- if (newId && visibility[newId] !== false) {
1847
- this.moveFocus({ ...this.focusStart, id: newId, column: index });
1848
- return;
1849
- }
1850
- --index;
1810
+ const visualCols = this._visualColumns;
1811
+ if (visualCols.length > 0) {
1812
+ const last = visualCols[visualCols.length - 1];
1813
+ this.moveFocus({ ...this.focusStart, id: last.id, column: last.index });
1851
1814
  }
1852
- //otherwise return without doing anything
1853
1815
  };
1854
1816
  moveFocusDown = () => {
1855
1817
  if (!this.allowCopy) {
@@ -1865,15 +1827,11 @@ export class TableContext {
1865
1827
  return;
1866
1828
  }
1867
1829
  if (this.focusEnd != null) {
1868
- const visibility = this.columnVisibility;
1869
- let index = this.focusEnd.column - 1;
1870
- while (index > -1) {
1871
- const newId = this.columnDefs[index].id;
1872
- if (newId && visibility[newId] !== false) {
1873
- this.focusEnd = { ...this.focusEnd, column: index };
1874
- return;
1875
- }
1876
- --index;
1830
+ const visualCols = this._visualColumns;
1831
+ const visualIndex = this.columnVisualIndex(this.focusEnd.id);
1832
+ if (visualIndex > 0) {
1833
+ const prev = visualCols[visualIndex - 1];
1834
+ this.focusEnd = { ...this.focusEnd, id: prev.id, column: prev.index };
1877
1835
  }
1878
1836
  }
1879
1837
  };
@@ -1881,35 +1839,23 @@ export class TableContext {
1881
1839
  if (!this.focusStart) {
1882
1840
  return;
1883
1841
  }
1884
- const visibility = this.columnVisibility;
1885
- const columnDefs = this.columnDefs;
1886
- let index = this.focusStart.column - 1;
1887
- while (index > -1) {
1888
- const newId = columnDefs[index].id;
1889
- if (newId && visibility[newId] !== false) {
1890
- this.moveFocus({ ...this.focusStart, id: newId, column: index });
1891
- return;
1892
- }
1893
- --index;
1842
+ const visualCols = this._visualColumns;
1843
+ const visualIndex = this.columnVisualIndex(this.focusStart.id);
1844
+ if (visualIndex > 0) {
1845
+ const prev = visualCols[visualIndex - 1];
1846
+ this.moveFocus({ ...this.focusStart, id: prev.id, column: prev.index });
1894
1847
  }
1895
- //otherwise return without doing anything
1896
1848
  };
1897
1849
  moveFocusRight = () => {
1898
1850
  if (!this.allowCopy) {
1899
1851
  return;
1900
1852
  }
1901
1853
  if (this.focusEnd != null) {
1902
- const visibility = this.columnVisibility;
1903
- const columnDefs = this.columnDefs;
1904
- const upperBounds = columnDefs.length;
1905
- let index = this.focusEnd.column + 1;
1906
- while (index < upperBounds) {
1907
- const newId = columnDefs[index].id;
1908
- if (newId && visibility[newId] !== false) {
1909
- this.focusEnd = { ...this.focusEnd, column: index };
1910
- return;
1911
- }
1912
- ++index;
1854
+ const visualCols = this._visualColumns;
1855
+ const visualIndex = this.columnVisualIndex(this.focusEnd.id);
1856
+ if (visualIndex < visualCols.length - 1) {
1857
+ const next = visualCols[visualIndex + 1];
1858
+ this.focusEnd = { ...this.focusEnd, id: next.id, column: next.index };
1913
1859
  }
1914
1860
  }
1915
1861
  };
@@ -1917,19 +1863,12 @@ export class TableContext {
1917
1863
  if (!this.focusStart) {
1918
1864
  return;
1919
1865
  }
1920
- const visibility = this.columnVisibility;
1921
- const columnDefs = this.columnDefs;
1922
- const upperBounds = columnDefs.length;
1923
- let index = this.focusStart.column + 1;
1924
- while (index < upperBounds) {
1925
- const newId = columnDefs[index].id;
1926
- if (newId && visibility[newId] !== false) {
1927
- this.moveFocus({ ...this.focusStart, id: newId, column: index });
1928
- return;
1929
- }
1930
- ++index;
1866
+ const visualCols = this._visualColumns;
1867
+ const visualIndex = this.columnVisualIndex(this.focusStart.id);
1868
+ if (visualIndex < visualCols.length - 1) {
1869
+ const next = visualCols[visualIndex + 1];
1870
+ this.moveFocus({ ...this.focusStart, id: next.id, column: next.index });
1931
1871
  }
1932
- //otherwise return without doing anything
1933
1872
  };
1934
1873
  endFocus = (coords) => {
1935
1874
  if (this.isMousingDown) {
@@ -2125,6 +2064,37 @@ export class TableContext {
2125
2064
  };
2126
2065
  localStorage.setItem(`${this.userId}-${this.tableName}-settings`, JSON.stringify(settingsObject));
2127
2066
  }
2067
+ /**
2068
+ * Columns in visual display order: pinned-left → center → pinned-right,
2069
+ * preserving memory order within each section. Only includes visible columns.
2070
+ */
2071
+ get _visualColumns() {
2072
+ const visibility = this.columnVisibility;
2073
+ const pinLeft = this.columnPinning.left;
2074
+ const pinRight = this.columnPinning.right;
2075
+ const visible = this.columnDefs.filter((it) => visibility[it.id] !== false);
2076
+ return [
2077
+ ...visible.filter((it) => pinLeft?.has(it.id)),
2078
+ ...visible.filter((it) => !pinLeft?.has(it.id) && !pinRight?.has(it.id)),
2079
+ ...visible.filter((it) => pinRight?.has(it.id)),
2080
+ ];
2081
+ }
2082
+ /** Returns the visual index of the column with the given id, or -1 if not found. */
2083
+ columnVisualIndex(id) {
2084
+ return this._visualColumns.findIndex((it) => it.id === id);
2085
+ }
2086
+ get focusStartVisualColumn() {
2087
+ if (!this.focusStart) {
2088
+ return -1;
2089
+ }
2090
+ return this.columnVisualIndex(this.focusStart.id);
2091
+ }
2092
+ get focusEndVisualColumn() {
2093
+ if (!this.focusEnd) {
2094
+ return -1;
2095
+ }
2096
+ return this.columnVisualIndex(this.focusEnd.id);
2097
+ }
2128
2098
  _moveFocusEndRow(offset) {
2129
2099
  if (!this.allowCopy) {
2130
2100
  return;
@@ -2219,8 +2189,8 @@ export class TableContext {
2219
2189
  }
2220
2190
  async getFocusElementData() {
2221
2191
  if (this.focusStart && this.focusEnd) {
2222
- const { row: startRowIndexId, column: startColumnIndex } = this.focusStart;
2223
- const { row: endRowIndexId, column: endColumnIndex } = this.focusEnd;
2192
+ const { row: startRowIndexId } = this.focusStart;
2193
+ const { row: endRowIndexId } = this.focusEnd;
2224
2194
  // const model = this._currentPageData;
2225
2195
  const model = this.paginationRowModel;
2226
2196
  const startRowIndex = model.rows.findIndex((row) => row.visibleIndex === startRowIndexId);
@@ -2230,13 +2200,13 @@ export class TableContext {
2230
2200
  }
2231
2201
  const minRowIndex = Math.min(startRowIndex, endRowIndex);
2232
2202
  const maxRowIndex = Math.max(startRowIndex, endRowIndex);
2233
- const minColumnIndex = Math.min(startColumnIndex, endColumnIndex);
2234
- const maxColumnIndex = Math.max(startColumnIndex, endColumnIndex);
2235
- const affectedColumns = this.columnDefs.filter((it) => {
2236
- return (it.index >= minColumnIndex &&
2237
- it.index <= maxColumnIndex &&
2238
- this.columnDefReturnsTextValue(it));
2239
- });
2203
+ const startVisualIndex = this.columnVisualIndex(this.focusStart.id);
2204
+ const endVisualIndex = this.columnVisualIndex(this.focusEnd.id);
2205
+ const minVisualIndex = Math.min(startVisualIndex, endVisualIndex);
2206
+ const maxVisualIndex = Math.max(startVisualIndex, endVisualIndex);
2207
+ const affectedColumns = this._visualColumns
2208
+ .slice(minVisualIndex, maxVisualIndex + 1)
2209
+ .filter((it) => this.columnDefReturnsTextValue(it));
2240
2210
  const selectedRows = [];
2241
2211
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
2242
2212
  const indices = new Map();
@@ -29,7 +29,7 @@ export class TableFocusDetails {
29
29
  this.leftToRight = $derived.by(() => {
30
30
  void this.hasMultipleFocus;
31
31
  return (this.hasMultipleFocus &&
32
- (this.tableContext.focusStart?.column ?? 0) < (this.tableContext.focusEnd?.column ?? 0));
32
+ this.tableContext.focusStartVisualColumn < this.tableContext.focusEndVisualColumn);
33
33
  });
34
34
  }
35
35
  coordinates;
@@ -42,11 +42,12 @@ export class TableFocusDetails {
42
42
  void this.isMultiFocused;
43
43
  void this.leftToRight;
44
44
  if (this.isMultiFocused) {
45
+ const thisVisualIndex = this.tableContext.columnVisualIndex(this.cell.column.columnDef.id);
45
46
  if (this.leftToRight) {
46
- return this.coordinates.column === this.tableContext.focusStart?.column;
47
+ return thisVisualIndex === this.tableContext.focusStartVisualColumn;
47
48
  }
48
49
  else {
49
- return this.coordinates.column === this.tableContext.focusEnd?.column;
50
+ return thisVisualIndex === this.tableContext.focusEndVisualColumn;
50
51
  }
51
52
  }
52
53
  return false;
@@ -68,11 +69,12 @@ export class TableFocusDetails {
68
69
  void this.isMultiFocused;
69
70
  void this.leftToRight;
70
71
  if (this.isMultiFocused) {
72
+ const myVisual = this.tableContext.columnVisualIndex(this.cell.column.columnDef.id);
71
73
  if (this.leftToRight) {
72
- return this.coordinates.column === this.tableContext.focusEnd?.column;
74
+ return myVisual === this.tableContext.focusEndVisualColumn;
73
75
  }
74
76
  else {
75
- return this.coordinates.column === this.tableContext.focusStart?.column;
77
+ return myVisual === this.tableContext.focusStartVisualColumn;
76
78
  }
77
79
  }
78
80
  return false;
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.22.2",
4
+ "version": "0.22.3",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },