()
| 362 | |
| 363 | /** Create a new table state store instance. */ |
| 364 | export function createTableStateStore(): TableStateStore { |
| 365 | const table = new Map<string, TableLocalState>(); |
| 366 | |
| 367 | return Object.freeze({ |
| 368 | get: (id) => table.get(id) ?? DEFAULT_TABLE_STATE, |
| 369 | set: (id, patch) => { |
| 370 | const prev = table.get(id) ?? DEFAULT_TABLE_STATE; |
| 371 | const next: TableLocalState = Object.freeze({ |
| 372 | scrollTop: patch.scrollTop !== undefined ? patch.scrollTop : prev.scrollTop, |
| 373 | focusedRowIndex: |
| 374 | patch.focusedRowIndex !== undefined ? patch.focusedRowIndex : prev.focusedRowIndex, |
| 375 | focusedColumnIndex: |
| 376 | patch.focusedColumnIndex !== undefined |
| 377 | ? patch.focusedColumnIndex |
| 378 | : prev.focusedColumnIndex, |
| 379 | lastClickedKey: |
| 380 | patch.lastClickedKey !== undefined ? patch.lastClickedKey : prev.lastClickedKey, |
| 381 | viewportHeight: |
| 382 | patch.viewportHeight !== undefined ? patch.viewportHeight : prev.viewportHeight, |
| 383 | startIndex: patch.startIndex !== undefined ? patch.startIndex : prev.startIndex, |
| 384 | endIndex: patch.endIndex !== undefined ? patch.endIndex : prev.endIndex, |
| 385 | }); |
| 386 | table.set(id, next); |
| 387 | return next; |
| 388 | }, |
| 389 | delete: (id) => { |
| 390 | table.delete(id); |
| 391 | }, |
| 392 | keys: () => table.keys(), |
| 393 | }); |
| 394 | } |
| 395 | |
| 396 | /* ========== Tree State Store (GitHub issue #122) ========== */ |
| 397 |
no test coverage detected