cursedbelt 6.26.0 → 6.29.0

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.
Files changed (55) hide show
  1. package/dist/react/components/DataTable/DataTable.d.ts.map +1 -1
  2. package/dist/react/components/DataTable/DataTable.js +28 -9
  3. package/dist/react/components/DataTable/DataTable.js.map +1 -1
  4. package/dist/react/index.d.ts +1 -0
  5. package/dist/react/index.d.ts.map +1 -1
  6. package/dist/react/index.js +1 -0
  7. package/dist/react/index.js.map +1 -1
  8. package/dist/react/media/DenseGalleryShell.d.ts +7 -1
  9. package/dist/react/media/DenseGalleryShell.d.ts.map +1 -1
  10. package/dist/react/media/DenseGalleryShell.js +2 -2
  11. package/dist/react/media/DenseGalleryShell.js.map +1 -1
  12. package/dist/react/media-gallery/GalleryTable.d.ts +12 -1
  13. package/dist/react/media-gallery/GalleryTable.d.ts.map +1 -1
  14. package/dist/react/media-gallery/GalleryTable.js +37 -6
  15. package/dist/react/media-gallery/GalleryTable.js.map +1 -1
  16. package/dist/react/media-gallery/MediaGallery.d.ts +39 -3
  17. package/dist/react/media-gallery/MediaGallery.d.ts.map +1 -1
  18. package/dist/react/media-gallery/MediaGallery.js +122 -12
  19. package/dist/react/media-gallery/MediaGallery.js.map +1 -1
  20. package/dist/react/media-gallery/index.d.ts +1 -1
  21. package/dist/react/media-gallery/index.d.ts.map +1 -1
  22. package/dist/react/media-gallery/index.js.map +1 -1
  23. package/dist/react/media-gallery/mediaGallery.css +16 -0
  24. package/dist/react/notifications/issueCapture.d.ts +9 -0
  25. package/dist/react/notifications/issueCapture.d.ts.map +1 -1
  26. package/dist/react/notifications/issueCapture.js +25 -3
  27. package/dist/react/notifications/issueCapture.js.map +1 -1
  28. package/dist/react/usePrefixList.d.ts +82 -0
  29. package/dist/react/usePrefixList.d.ts.map +1 -0
  30. package/dist/react/usePrefixList.js +139 -0
  31. package/dist/react/usePrefixList.js.map +1 -0
  32. package/dist/scripts/guardrailsEnforce.d.ts.map +1 -1
  33. package/dist/testing/shell.d.ts +1 -0
  34. package/dist/testing/shell.d.ts.map +1 -1
  35. package/dist/testing/shell.js +2 -0
  36. package/dist/testing/shell.js.map +1 -1
  37. package/package.json +2 -2
  38. package/scripts/guardrails-baseline.json +1 -0
  39. package/scripts/guardrailsEnforce.spec.ts +31 -0
  40. package/scripts/guardrailsEnforce.ts +49 -0
  41. package/scripts/styleAreas.ts +2 -0
  42. package/src/react/components/DataTable/DataTable.tsx +26 -7
  43. package/src/react/components/DataTable/selection.spec.tsx +36 -0
  44. package/src/react/index.ts +6 -0
  45. package/src/react/media/DenseGalleryShell.tsx +8 -0
  46. package/src/react/media-gallery/GalleryTable.tsx +54 -6
  47. package/src/react/media-gallery/MediaGallery.spec.tsx +61 -0
  48. package/src/react/media-gallery/MediaGallery.tsx +170 -12
  49. package/src/react/media-gallery/index.ts +1 -0
  50. package/src/react/media-gallery/mediaGallery.css +16 -0
  51. package/src/react/notifications/issueCapture.spec.ts +21 -0
  52. package/src/react/notifications/issueCapture.ts +29 -3
  53. package/src/react/usePrefixList.spec.tsx +156 -0
  54. package/src/react/usePrefixList.ts +229 -0
  55. package/src/testing/shell.ts +2 -0
@@ -95,6 +95,42 @@ describe('DataTable row selection', () => {
95
95
  expect(clicks).toBe(0);
96
96
  });
97
97
 
98
+ test('🔴 ⇧-click checks every row from the last box clicked, and ⇧-click on a checked one unchecks the range (the owner, 2026-11-22)', () => {
99
+ const changes: string[][] = [];
100
+ const { container } = render(<Harness onChange={(next) => changes.push([...next].sort())} />);
101
+ fireEvent.click(rowBox(container, 'Metroid'));
102
+ fireEvent.click(rowBox(container, 'Mario Paint'), { shiftKey: true });
103
+ expect(changes.at(-1)).toEqual(['g1', 'g2', 'g3', 'g4']);
104
+ fireEvent.click(rowBox(container, 'Mario Kart'), { shiftKey: true });
105
+ expect(changes.at(-1)).toEqual(['g1']);
106
+ // The padding around the box takes ⇧ too.
107
+ fireEvent.click(rowBox(container, 'Kirby').closest('td') as HTMLElement, { shiftKey: true });
108
+ expect(changes.at(-1)).toEqual(['g1', 'g2', 'g3', 'g4', 'g5']);
109
+ });
110
+
111
+ test('⇧ ranges run over the rows as SHOWN — sorted — and skip a row that cannot be selected', () => {
112
+ const changes: string[][] = [];
113
+ const { container } = render(
114
+ <Harness
115
+ columns={[{ ...COLUMNS[0], sortable: true } as ColDef<Game>, ...COLUMNS.slice(1)]}
116
+ defaultSort={[{ id: 'title', desc: false }]}
117
+ isRowSelectable={(row) => row.id !== 'g2'}
118
+ onChange={(next) => changes.push([...next].sort())}
119
+ />,
120
+ );
121
+ // By title: Kirby, Mario Kart (unselectable), Mario Paint, Metroid, Zelda.
122
+ fireEvent.click(rowBox(container, 'Kirby'));
123
+ fireEvent.click(rowBox(container, 'Metroid'), { shiftKey: true });
124
+ expect(changes.at(-1)).toEqual(['g1', 'g4', 'g5']);
125
+ });
126
+
127
+ test('⇧ with no box clicked yet is an ordinary click', () => {
128
+ const changes: string[][] = [];
129
+ const { container } = render(<Harness onChange={(next) => changes.push([...next])} />);
130
+ fireEvent.click(rowBox(container, 'Zelda'), { shiftKey: true });
131
+ expect(changes.at(-1)).toEqual(['g3']);
132
+ });
133
+
98
134
  test('the WHOLE cell is the hit target, not just the 16px box', () => {
99
135
  const changes: string[][] = [];
100
136
  const { container } = render(<Harness onChange={(next) => changes.push([...next])} />);
@@ -1020,6 +1020,12 @@ export {
1020
1020
  type UsePagedListOptions,
1021
1021
  usePagedList,
1022
1022
  } from './usePagedList.js';
1023
+ export {
1024
+ type PrefixList,
1025
+ type PrefixListWindow,
1026
+ type UsePrefixListOptions,
1027
+ usePrefixList,
1028
+ } from './usePrefixList.js';
1023
1029
  export {
1024
1030
  type UseWindowedListOptions,
1025
1031
  useWindowedList,
@@ -15,6 +15,7 @@ import {
15
15
  } from 'react';
16
16
  import { VirtualMediaGrid } from './VirtualMediaGrid.js';
17
17
  import type { FastScrollOptions } from '../components/FastScroller.js';
18
+ import type { CardGridServerWindow } from '../VirtualCardGrid.js';
18
19
  import { Tooltip } from '../components/Tooltip.js';
19
20
  import { MediaResizeBar, MediaResizeCorner, useMediaResize } from './MediaResize.js';
20
21
  import { STAGE_HEIGHT_KEY } from './stageResize.js';
@@ -237,6 +238,11 @@ export interface DenseGalleryShellProps<O extends string = string> {
237
238
  onNearEnd?: () => void;
238
239
  /** The browse grid's fast scroller for a finger — {@link VirtualCardGridProps.fastScroll}. */
239
240
  fastScroll?: boolean | FastScrollOptions;
241
+ /**
242
+ * The browse grid's tiles are a window of a longer set the server holds — {@link VirtualCardGridProps.serverWindow}.
243
+ * Not the `body`'s: a caller passing its own body windows it itself.
244
+ */
245
+ serverWindow?: CardGridServerWindow;
240
246
  loading?: boolean;
241
247
  /** Shown when the grid is empty AND not loading. */
242
248
  empty?: ReactNode;
@@ -283,6 +289,7 @@ export function DenseGalleryShell<O extends string = string>({
283
289
  body,
284
290
  onNearEnd,
285
291
  fastScroll,
292
+ serverWindow,
286
293
  loading,
287
294
  empty,
288
295
  emptyAction,
@@ -336,6 +343,7 @@ export function DenseGalleryShell<O extends string = string>({
336
343
  rowExtraHeight={rowExtraHeight}
337
344
  onNearEnd={onNearEnd}
338
345
  fastScroll={fastScroll}
346
+ {...(serverWindow ? { serverWindow } : {})}
339
347
  empty={
340
348
  loading || !empty
341
349
  ? null
@@ -70,6 +70,11 @@ export const GALLERY_TABLE_ROW_HEIGHTS: Readonly<Record<CardSize, { fine: number
70
70
  /** Rows rendered above and below the visible window, so a fast scroll does not flash blank. */
71
71
  const OVERSCAN = 6;
72
72
 
73
+ /** How long a scroll wholly past a window's loaded rows must be still before the table asks for them — the card grid's. */
74
+ const WINDOW_SETTLE_MS = 120;
75
+ /** How often a screen of placeholder rows that has come to rest asks again. */
76
+ const WINDOW_RETRY_MS = 3000;
77
+
73
78
  /**
74
79
  * Which sort pair a column header drives, and which way its two directions read.
75
80
  *
@@ -216,6 +221,14 @@ export interface GalleryTableProps {
216
221
  onOrderChange: (order: MediaGalleryOrder) => void;
217
222
  onOpen: (item: MediaGalleryItem) => void;
218
223
  onNearEnd?: () => void;
224
+ /**
225
+ * The rows are the FIRST `items.length` of `total` the server holds, in its order (`MediaGallery`'s `serverWindow`,
226
+ * forge task 5701): the table lays out all `total`, a row not loaded draws as a placeholder, and the screen reaching
227
+ * past the loaded end asks `onNeedThrough` for the rows through it — at once near the edge, once a scroll RESTS when
228
+ * the screen is wholly past it, so a thumb dragged down the track asks once, where it lands. `onNearEnd` is not for a
229
+ * window.
230
+ */
231
+ serverWindow?: { total: number; onNeedThrough: (end: number) => void };
219
232
  /** A fast scroller on the table's own frame for a finger — {@link FastScrollOptions}. */
220
233
  fastScroll?: boolean | FastScrollOptions;
221
234
  loading?: boolean;
@@ -277,6 +290,7 @@ export function GalleryTable({
277
290
  onOrderChange,
278
291
  onOpen,
279
292
  onNearEnd,
293
+ serverWindow,
280
294
  fastScroll,
281
295
  loading,
282
296
  empty,
@@ -298,7 +312,9 @@ export function GalleryTable({
298
312
  // 4px short per row, so a long table's scrollbar jumped as rows came and went on a phone.
299
313
  const coarse = useMediaQuery('(pointer: coarse)');
300
314
  const rowHeight = GALLERY_TABLE_ROW_HEIGHTS[rowSize][coarse ? 'coarse' : 'fine'];
301
- const { start, end } = visibleWindow(items.length, scrollTop, viewportHeight, rowHeight);
315
+ /** Every row the table lays out: the whole set under a window, else what it was handed. */
316
+ const count = serverWindow ? Math.max(serverWindow.total, items.length) : items.length;
317
+ const { start, end } = visibleWindow(count, scrollTop, viewportHeight, rowHeight);
302
318
 
303
319
  // 🔴 A column the width drops is NOT RENDERED, not merely `display: none` (forge task 4782).
304
320
  // WebKit's `table-layout: fixed` still allots a track to a column whose cells are all
@@ -314,9 +330,28 @@ export function GalleryTable({
314
330
  // Paging is the consumer's, and it fires on approach rather than on arrival so the next
315
331
  // page is already in flight by the time the last row is on screen.
316
332
  useEffect(() => {
317
- if (!onNearEnd || items.length === 0) return;
333
+ if (serverWindow || !onNearEnd || items.length === 0) return;
318
334
  if (end >= items.length - 3) onNearEnd();
319
- }, [end, items.length, onNearEnd]);
335
+ }, [end, items.length, onNearEnd, serverWindow]);
336
+
337
+ // A window's asks — see `serverWindow`. The callback is read at FIRE time, as the card grid's are.
338
+ const needRef = useRef(serverWindow?.onNeedThrough);
339
+ needRef.current = serverWindow?.onNeedThrough;
340
+ const windowed = serverWindow !== undefined;
341
+ useEffect(() => {
342
+ if (!windowed || items.length >= count || end < items.length - 3) return;
343
+ if (start < items.length) {
344
+ needRef.current?.(Math.min(count, Math.max(end, items.length + 1)));
345
+ return;
346
+ }
347
+ // …and while the screen stays wholly past the loaded rows, asked again every few seconds: a page that failed is
348
+ // fetched again on a repeat ask, and nothing else would repeat it under a still screen.
349
+ let timer = setTimeout(function ask() {
350
+ needRef.current?.(end);
351
+ timer = setTimeout(ask, WINDOW_RETRY_MS);
352
+ }, WINDOW_SETTLE_MS);
353
+ return () => clearTimeout(timer);
354
+ }, [windowed, start, end, items.length, count]);
320
355
 
321
356
  const onScroll = useCallback((event: React.UIEvent<HTMLDivElement>) => {
322
357
  setScrollTop(event.currentTarget.scrollTop);
@@ -327,7 +362,10 @@ export function GalleryTable({
327
362
  // count of columns NOT rendered is a phantom track in WebKit (see `columns` above).
328
363
  const columnCount = 2 + (selection ? 1 : 0) + Object.values(columns).filter(Boolean).length;
329
364
  const above = start * rowHeight;
330
- const below = Math.max(0, (items.length - end) * rowHeight);
365
+ const below = Math.max(0, (count - end) * rowHeight);
366
+ /** The loaded rows on screen, and how many places past them are still on their way. */
367
+ const shownEnd = Math.min(end, items.length);
368
+ const waiting = Math.max(0, end - Math.max(start, items.length));
331
369
 
332
370
  return (
333
371
  <div
@@ -338,7 +376,7 @@ export function GalleryTable({
338
376
  onScroll={onScroll}
339
377
  data-cb-fast-scroll-root={fastScroll ? '' : undefined}
340
378
  >
341
- {listFastScroller(fastScroll, items.length)}
379
+ {listFastScroller(fastScroll, count)}
342
380
  {/*
343
381
  * guardrails-ignore no-raw-data-table: cursedbelt's DataTable is the right answer
344
382
  * almost everywhere and is the wrong one here, for two independent reasons. (1) This
@@ -418,7 +456,7 @@ export function GalleryTable({
418
456
  * there. An empty cell is simply an empty cell.
419
457
  */}
420
458
  {above > 0 ? <tr className='cbgt-spacer' style={{ height: above }}><td colSpan={columnCount} /></tr> : null}
421
- {items.slice(start, end).map((item) => (
459
+ {items.slice(start, shownEnd).map((item) => (
422
460
  <GalleryTableRow
423
461
  key={item.id}
424
462
  item={item}
@@ -432,6 +470,16 @@ export function GalleryTable({
432
470
  {...(playing?.id === item.id ? { stageMark: playing.label } : {})}
433
471
  />
434
472
  ))}
473
+ {Array.from({ length: waiting }, (_, i) => {
474
+ const index = Math.max(start, items.length) + i;
475
+ return (
476
+ <tr key={`cbgt-wait-${index}`} className='cbgt-row cbgt-row--wait' data-cb-table-placeholder=''>
477
+ <td colSpan={columnCount}>
478
+ <span className='cbgt-wait-bar' />
479
+ </td>
480
+ </tr>
481
+ );
482
+ })}
435
483
  {below > 0 ? <tr className='cbgt-spacer' style={{ height: below }}><td colSpan={columnCount} /></tr> : null}
436
484
  </tbody>
437
485
  </table>
@@ -3717,3 +3717,64 @@ describe('MediaGallery — Trim carries keyframes in and the mode out', () => {
3717
3717
  expect(document.querySelector('.cbvc-sheet')?.textContent).not.toContain('Your cuts are exact.');
3718
3718
  });
3719
3719
  });
3720
+
3721
+ /**
3722
+ * A server window (`serverWindow`, forge task 5701): the items are the first n of `total` in the server's order. The
3723
+ * browser half — a thumb dragged to the bottom of 4,180 files — is `e2e/gallery-window.spec.ts`.
3724
+ */
3725
+ describe('🔴 MediaGallery — a server window', () => {
3726
+ const many = (n: number): MediaGalleryItem[] =>
3727
+ Array.from({ length: n }, (_, i) => ({ id: `f${i}`, name: `file-${String(i).padStart(4, '0')}.jpg`, url: `/f/${i}`, createdAt: i }));
3728
+ const title = (c: HTMLElement) => c.querySelector('.cbgd-watch-title')?.textContent;
3729
+
3730
+ test('draws the server order as given — no client re-sort under a window', () => {
3731
+ // Newest-first would put file-0002 (createdAt 2) first; the server's order is kept.
3732
+ const asks: number[] = [];
3733
+ const { container } = render(
3734
+ <MediaGallery items={many(3)} order='recent' viewMode='table' serverWindow={{ total: 3, onNeedThrough: (end) => asks.push(end) }} />,
3735
+ );
3736
+ const names = Array.from(container.querySelectorAll('.cbgt-row')).map((r) => r.querySelector('.cbgt-cell--name')?.textContent ?? '');
3737
+ expect(names[0]).toContain('file-0000');
3738
+ expect(names[2]).toContain('file-0002');
3739
+ });
3740
+
3741
+ test('the table lays out the whole set, draws what is not loaded as placeholders, and asks for it', () => {
3742
+ const asks: number[] = [];
3743
+ const { container } = render(
3744
+ <MediaGallery items={many(3)} viewMode='table' serverWindow={{ total: 4180, onNeedThrough: (end) => asks.push(end) }} />,
3745
+ );
3746
+ expect(container.querySelectorAll('[data-cb-table-placeholder]').length).toBeGreaterThan(0);
3747
+ expect(asks.length).toBeGreaterThan(0);
3748
+ expect(Math.max(...asks)).toBeGreaterThan(3);
3749
+ });
3750
+
3751
+ test('Next on the last LOADED file asks for more and lands on the next one, not the first', () => {
3752
+ const asks: number[] = [];
3753
+ const window = { total: 10, onNeedThrough: (end: number) => asks.push(end) };
3754
+ const { container, getByRole, rerender } = render(<MediaGallery items={many(3)} serverWindow={window} />);
3755
+ fireEvent.click(getByRole('button', { name: 'Open file-0002.jpg' }));
3756
+ fireEvent.click(getByRole('button', { name: 'Next file' }));
3757
+ expect(title(container)).toBe('file-0002.jpg');
3758
+ expect(asks).toContain(4);
3759
+ rerender(<MediaGallery items={many(6)} serverWindow={window} />);
3760
+ expect(title(container)).toBe('file-0003.jpg');
3761
+ });
3762
+
3763
+ test('Select all says it ticks what is LOADED while only part of the set is in, and only then', () => {
3764
+ const window = { total: 4180, onNeedThrough: () => undefined };
3765
+ const view = render(<MediaGallery items={many(3)} selectable serverWindow={window} />);
3766
+ expect(view.getByText('Select loaded')).toBeDefined();
3767
+ fireEvent.click(view.getByText('Select loaded'));
3768
+ expect(view.getByText('All loaded selected')).toBeDefined();
3769
+ view.rerender(<MediaGallery items={many(3)} selectable serverWindow={{ ...window, total: 3 }} />);
3770
+ expect(view.getByText('All selected')).toBeDefined();
3771
+ });
3772
+
3773
+ test('a local search stands the window down: it filters what is loaded, and lays out no placeholders', () => {
3774
+ const { container } = render(
3775
+ <MediaGallery items={many(3)} viewMode='table' query='0001' serverWindow={{ total: 4180, onNeedThrough: () => undefined }} />,
3776
+ );
3777
+ expect(container.querySelectorAll('.cbgt-row:not(.cbgt-row--wait)').length).toBe(1);
3778
+ expect(container.querySelectorAll('[data-cb-table-placeholder]').length).toBe(0);
3779
+ });
3780
+ });
@@ -78,6 +78,7 @@ import type { PlayableVideo } from 'cursedbelt-core/media';
78
78
  import { CATEGORY_LABEL, FileTypeIcon } from '../components/FileTypeIcon.js';
79
79
  import { DeleteButton } from '../components/DeleteButton.js';
80
80
  import type { FastScrollOptions } from '../components/FastScroller.js';
81
+ import type { CardGridServerWindow } from '../VirtualCardGrid.js';
81
82
  import {
82
83
  type CheckboxHeaderState,
83
84
  useCheckboxSelection,
@@ -1894,13 +1895,49 @@ export interface MediaGalleryFastScroll extends Omit<FastScrollOptions, 'bubble'
1894
1895
  bubble?: (index: number, item: MediaGalleryItem | undefined) => ReactNode;
1895
1896
  }
1896
1897
 
1898
+ /**
1899
+ * {@link MediaGalleryProps.serverWindow}: `items` are the FIRST `items.length` of `total` the server holds, in the
1900
+ * server's order — a prefix that grows (`usePrefixList` hands back exactly this).
1901
+ */
1902
+ export interface MediaGalleryServerWindow {
1903
+ /** How many items the server's query matches — what the scroll space and a fast scroller's track describe. */
1904
+ total: number;
1905
+ /**
1906
+ * Load at least the first `end` items. Asked when the screen nears the loaded end, when a scroll or a thumb comes to
1907
+ * rest past it (with the screen's last index), and when the stage steps past the last loaded item. Asked again while
1908
+ * still short, so ignore an ask the loads in flight already answer.
1909
+ */
1910
+ onNeedThrough: (end: number) => void;
1911
+ }
1912
+
1897
1913
  export interface MediaGalleryProps {
1898
1914
  items: MediaGalleryItem[];
1899
1915
  /** Header title. */
1900
1916
  title?: string;
1901
1917
  loading?: boolean;
1902
- /** Infinite scroll — forwarded to the virtualized grids. */
1918
+ /** Infinite scroll — forwarded to the virtualized grids. With {@link serverWindow}, leave it out. */
1903
1919
  onNearEnd?: () => void;
1920
+ /**
1921
+ * The items are a PREFIX of a longer list the server holds ({@link MediaGalleryServerWindow}): the browse grid and the
1922
+ * table lay out all `total`, unloaded places draw as placeholders, and reaching past the loaded end asks for more
1923
+ * through `onNeedThrough` — so a fast scroller's thumb spans the whole set and a drag to the bottom lands on the last
1924
+ * item (forge task 5701: a 4,000-file Collections album whose thumb reached file 200, twenty drags to the end).
1925
+ *
1926
+ * 🔴 While it is on, the SERVER owns the order and the filter, because a prefix re-sorted or narrowed here is no longer
1927
+ * the server's first `n`, and every index would point at the wrong place:
1928
+ * - the gallery draws `items` as given — no sort by `order`, which then only labels (the fast scroller's bubble, the
1929
+ * table's header arrow). A sort pill or a table header calls `onOrderChange`, and the app sorts on the server: pass
1930
+ * `order` and `onOrderChange` with this.
1931
+ * - a search typed into `query`, a kind chip the gallery holds itself or a tag chip narrows what is LOADED, as without
1932
+ * a window: while one is on the window stands down, the grid holds the matches, and nearing its end loads the next
1933
+ * page. An app that filters on the server (`kindFilter`, its own search) keeps the window.
1934
+ * - Select all ticks what is loaded, and says so ("Select loaded", "All loaded selected"); a bulk verb acts on those.
1935
+ * - the stage's Next past the last loaded item asks for more and steps once it lands; Previous from the first item
1936
+ * wraps to the true last one, loading through it. Shuffle draws from what is loaded.
1937
+ *
1938
+ * The related strip under an open file keeps appending a page at a time.
1939
+ */
1940
+ serverWindow?: MediaGalleryServerWindow;
1904
1941
  /**
1905
1942
  * A fast scroller for a finger on the browse view — the tiles and the table alike ({@link FastScroller}): a
1906
1943
  * 5,000-file folder in one drag, a bubble naming where the finger is. `true` is enough: the bubble then says the
@@ -1908,7 +1945,8 @@ export interface MediaGalleryProps {
1908
1945
  * wins, and gets the index into the items as shown (sorted and filtered) and the item there — the way to name a key the
1909
1946
  * item does not carry, like the month a file was added under the server's own order (`as-given`, which alone says
1910
1947
  * nothing). Shown only on a coarse pointer, once the list is four screens long. With `onNearEnd` the far end is as
1911
- * far as has loaded, and a drag there loads the next page.
1948
+ * far as has loaded, and a drag there loads the next page; with {@link serverWindow} the track is the whole set, and
1949
+ * over a place not loaded yet the bubble says which of how many it is ("3,201 of 4,180") in place of `bubble`.
1912
1950
  */
1913
1951
  fastScroll?: boolean | MediaGalleryFastScroll;
1914
1952
  initialOrder?: MediaGalleryOrder;
@@ -2437,6 +2475,7 @@ export function MediaGallery({
2437
2475
  title = 'Media',
2438
2476
  loading,
2439
2477
  onNearEnd,
2478
+ serverWindow,
2440
2479
  fastScroll,
2441
2480
  initialOrder = 'recent',
2442
2481
  order: controlledOrder,
@@ -2633,17 +2672,69 @@ export function MediaGallery({
2633
2672
  const activeKind = kindFilter ? kindFilter.value : kind;
2634
2673
  const tag = tagFilter ? tagFilter.value : ownTag;
2635
2674
  const stripQuiet = kindChips === 'on' && activeKind === null && tag === null;
2675
+ /*
2676
+ * ── The server window (`serverWindow`, forge task 5701) ─────────────────────────────────
2677
+ * `windowTotal` is the whole set's size; `windowed` is the window IN FORCE — the server's prefix drawn as given, with
2678
+ * no narrowing of the gallery's own on top (the prop's doc says why a narrowing stands it down).
2679
+ */
2680
+ const windowTotal = serverWindow ? Math.max(serverWindow.total, items.length) : items.length;
2681
+ const windowed = serverWindow !== undefined && !query.trim() && localKind === null && tag === null;
2636
2682
  const displayItems = useMemo(
2637
- () => sortGalleryItems(filterGalleryItems(items, { query, kind: localKind, tag }), order),
2638
- [items, query, localKind, tag, order],
2683
+ () => (windowed ? items : sortGalleryItems(filterGalleryItems(items, { query, kind: localKind, tag }), order)),
2684
+ [windowed, items, query, localKind, tag, order],
2685
+ );
2686
+ /** Ask for the first `end` items — read through refs, so the asks below are stable callbacks. */
2687
+ const windowLive = useRef({ serverWindow, loaded: items.length, total: windowTotal });
2688
+ windowLive.current = { serverWindow, loaded: items.length, total: windowTotal };
2689
+ const needThrough = useCallback((end: number): void => {
2690
+ const now = windowLive.current;
2691
+ if (!now.serverWindow || now.loaded >= now.total || end <= now.loaded) return;
2692
+ now.serverWindow.onNeedThrough(Math.min(end, now.total));
2693
+ }, []);
2694
+ /** The browse grid's window, in `VirtualCardGrid`'s terms: a window that always starts at 0. */
2695
+ const gridWindow = useMemo(
2696
+ (): CardGridServerWindow | undefined =>
2697
+ windowed
2698
+ ? {
2699
+ start: 0,
2700
+ total: windowTotal,
2701
+ onReachEnd: () => needThrough(windowLive.current.loaded + 1),
2702
+ onNeedWindow: (_first, last) => needThrough(last),
2703
+ }
2704
+ : undefined,
2705
+ [windowed, windowTotal, needThrough],
2706
+ );
2707
+ /** The browse table's, in `GalleryTable`'s. */
2708
+ const tableWindow = useMemo(
2709
+ () => (windowed ? { total: windowTotal, onNeedThrough: needThrough } : undefined),
2710
+ [windowed, windowTotal, needThrough],
2639
2711
  );
2712
+ /**
2713
+ * Appending a page at a time: the app's own `onNearEnd`, or — with a window the strip under an open file and a
2714
+ * narrowed grid do not lay out — the next page of the prefix.
2715
+ */
2716
+ const appendMore = serverWindow
2717
+ ? items.length < windowTotal
2718
+ ? () => needThrough(windowLive.current.loaded + 1)
2719
+ : undefined
2720
+ : onNearEnd;
2721
+ const browseNearEnd = windowed ? undefined : appendMore;
2640
2722
 
2641
- /* The fast scroller names where the finger is by the key the gallery is sorted by, unless the app says otherwise. */
2723
+ /*
2724
+ * The fast scroller names where the finger is by the key the gallery is sorted by, unless the app says otherwise. Over
2725
+ * a place the window has not loaded there is no item to name, so it says which of how many it is.
2726
+ */
2642
2727
  const galleryFastScroll = useMemo((): FastScrollOptions | undefined => {
2643
2728
  if (!fastScroll) return undefined;
2644
2729
  const { bubble, ...options } = fastScroll === true ? {} : fastScroll;
2645
- return { ...options, bubble: galleryBubble(displayItems, order, bubble) };
2646
- }, [fastScroll, displayItems, order]);
2730
+ const named = galleryBubble(displayItems, order, bubble);
2731
+ if (!windowed) return { ...options, bubble: named };
2732
+ const shown = displayItems.length;
2733
+ return {
2734
+ ...options,
2735
+ bubble: (index: number) => (index < shown ? named(index) : `${(index + 1).toLocaleString()} of ${windowTotal.toLocaleString()}`),
2736
+ };
2737
+ }, [fastScroll, displayItems, order, windowed, windowTotal]);
2647
2738
 
2648
2739
  /*
2649
2740
  * Is there anything to preview at all?
@@ -2734,6 +2825,21 @@ export function MediaGallery({
2734
2825
  onSelectedChange?.(item);
2735
2826
  };
2736
2827
 
2828
+ /**
2829
+ * 🔴 A step off the loaded edge of a {@link MediaGalleryProps.serverWindow} is NOT a wrap: the item after the last
2830
+ * loaded one is the next item of the set, and the one before the first is the set's true last. So the step is held,
2831
+ * the prefix is asked to load through its target, and the step lands once it has (the effect below) — unless the
2832
+ * reader has moved on by then. True when the step was held.
2833
+ */
2834
+ const pendingStep = useRef<{ from: string; delta: number } | null>(null);
2835
+ const stepPastWindow = (delta: number): boolean => {
2836
+ if (!windowed || !selectedId || displayItems.length >= windowTotal) return false;
2837
+ const at = displayIds.indexOf(selectedId);
2838
+ if (at < 0 || (at + delta >= 0 && at + delta < displayItems.length)) return false;
2839
+ pendingStep.current = { from: selectedId, delta };
2840
+ needThrough(delta > 0 ? at + delta + 1 : windowTotal);
2841
+ return true;
2842
+ };
2737
2843
  /**
2738
2844
  * Step through the DISPLAYED order — the same order the grid shows, so "next" always means
2739
2845
  * the tile to the right rather than a hidden neighbor from the unfiltered set.
@@ -2750,11 +2856,44 @@ export function MediaGallery({
2750
2856
  * mean different things — see the note on `stepId`.
2751
2857
  */
2752
2858
  const step = (delta: number): void => {
2859
+ if (stepPastWindow(delta)) return;
2753
2860
  const nextId = stepId(displayIds, selectedId, delta);
2754
2861
  const next = nextId ? displayItems.find((i) => i.id === nextId) : undefined;
2755
2862
  if (next) select(next);
2756
2863
  };
2757
2864
 
2865
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the loaded prefix growing IS the trigger; `select` is read fresh each render.
2866
+ useEffect(() => {
2867
+ const held = pendingStep.current;
2868
+ if (!held) return;
2869
+ if (held.from !== selectedId) {
2870
+ pendingStep.current = null;
2871
+ return;
2872
+ }
2873
+ const target = displayIds.indexOf(held.from) + held.delta;
2874
+ const next = target >= 0 ? displayItems[target] : undefined;
2875
+ if (next) {
2876
+ pendingStep.current = null;
2877
+ select(next);
2878
+ } else if (!windowed || displayItems.length >= windowTotal) {
2879
+ // Everything is in (or the window stood down): an ordinary step, which wraps.
2880
+ pendingStep.current = null;
2881
+ const nextId = stepId(displayIds, selectedId, held.delta);
2882
+ const wrapped = nextId ? displayItems.find((i) => i.id === nextId) : undefined;
2883
+ if (wrapped) select(wrapped);
2884
+ }
2885
+ }, [displayItems, displayIds, selectedId, windowed, windowTotal]);
2886
+
2887
+ /*
2888
+ * The stage nearing the loaded end asks for the next page ahead of the reader, so Next rarely has to wait. Twelve is
2889
+ * a little more than a phone's screen of tiles under the stage.
2890
+ */
2891
+ useEffect(() => {
2892
+ if (!windowed || !selectedId) return;
2893
+ const at = displayIds.indexOf(selectedId);
2894
+ if (at >= 0 && at >= displayIds.length - 12) needThrough(at + 13);
2895
+ }, [windowed, selectedId, displayIds, needThrough]);
2896
+
2758
2897
  /*
2759
2898
  * ── The standard detail capabilities' own state ───────────────────────────────────────
2760
2899
  *
@@ -3006,6 +3145,8 @@ export function MediaGallery({
3006
3145
  selectedIdRef.current = selectedId;
3007
3146
  itemsRef.current = items;
3008
3147
  selectRef.current = select;
3148
+ const stepPastWindowRef = useRef(stepPastWindow);
3149
+ stepPastWindowRef.current = stepPastWindow;
3009
3150
 
3010
3151
  const playedRef = useRef<string[]>([]);
3011
3152
  const advance = useCallback(() => {
@@ -3016,6 +3157,12 @@ export function MediaGallery({
3016
3157
  played: playedRef.current,
3017
3158
  });
3018
3159
  playedRef.current = step.played;
3160
+ // The run's end of a server window's PREFIX is not the end of the set: the next item is the one not loaded yet.
3161
+ const ids = displayIdsRef.current;
3162
+ const current = selectedIdRef.current;
3163
+ const pastWindow = stepPastWindowRef.current;
3164
+ const behavior = playbackEndRef.current;
3165
+ if (runAdvances(behavior) && behavior !== 'shuffle' && current && ids[ids.length - 1] === current && pastWindow(1)) return;
3019
3166
  if (!step.nextId) return;
3020
3167
  const next = itemsRef.current.find((i) => i.id === step.nextId);
3021
3168
  if (next) selectRef.current(next);
@@ -4228,7 +4375,7 @@ export function MediaGallery({
4228
4375
  relatedLabel='Files'
4229
4376
  itemCount={displayItems.length}
4230
4377
  loading={loading}
4231
- onNearEnd={onNearEnd}
4378
+ onNearEnd={appendMore}
4232
4379
  minColumnWidth={minColumnWidth}
4233
4380
  /*
4234
4381
  * 🔴 The rows/tiles toggle reaches THIS screen too (2026-09-10).
@@ -4251,7 +4398,7 @@ export function MediaGallery({
4251
4398
  order={order}
4252
4399
  onOrderChange={setOrder}
4253
4400
  onOpen={select}
4254
- {...(onNearEnd ? { onNearEnd } : {})}
4401
+ {...(appendMore ? { onNearEnd: appendMore } : {})}
4255
4402
  {...(loading === undefined ? {} : { loading })}
4256
4403
  /* 🔴 The same `thumbAutoplay` the tiles take. Owner, 2026-09-11: *"in table
4257
4404
  view the play all thumbnails isn't working but if I go back to grid view it
@@ -4418,6 +4565,7 @@ export function MediaGallery({
4418
4565
  <BulkBar
4419
4566
  count={checks.count}
4420
4567
  total={displayItems.length}
4568
+ {...(windowed && displayItems.length < windowTotal ? { partial: true } : {})}
4421
4569
  headerState={checks.headerState}
4422
4570
  onToggleAll={checks.toggleAll}
4423
4571
  {...(selectionReveal === 'on-demand'
@@ -4455,7 +4603,8 @@ export function MediaGallery({
4455
4603
  }
4456
4604
  itemCount={displayItems.length}
4457
4605
  loading={loading}
4458
- onNearEnd={onNearEnd}
4606
+ onNearEnd={browseNearEnd}
4607
+ {...(gridWindow ? { serverWindow: gridWindow } : {})}
4459
4608
  fastScroll={galleryFastScroll}
4460
4609
  empty={empty ?? <div className='cbgd-empty'>No files yet.</div>}
4461
4610
  emptyAction={emptyAction}
@@ -4470,7 +4619,8 @@ export function MediaGallery({
4470
4619
  // question nobody should have to answer; see GalleryTable's header.
4471
4620
  onOrderChange={setOrder}
4472
4621
  onOpen={select}
4473
- {...(onNearEnd ? { onNearEnd } : {})}
4622
+ {...(browseNearEnd ? { onNearEnd: browseNearEnd } : {})}
4623
+ {...(tableWindow ? { serverWindow: tableWindow } : {})}
4474
4624
  fastScroll={galleryFastScroll}
4475
4625
  {...(loading === undefined ? {} : { loading })}
4476
4626
  {...(empty === undefined ? {} : { empty })}
@@ -4552,6 +4702,7 @@ function stageMeta(line: string | undefined, description?: string): ReactNode {
4552
4702
  function BulkBar({
4553
4703
  count,
4554
4704
  total,
4705
+ partial,
4555
4706
  headerState,
4556
4707
  armed,
4557
4708
  onToggleArmed,
@@ -4559,6 +4710,11 @@ function BulkBar({
4559
4710
  }: {
4560
4711
  count: number;
4561
4712
  total: number;
4713
+ /**
4714
+ * The tiles are a server window's loaded prefix, not the whole set (`serverWindow`), so the box ticks what is LOADED
4715
+ * and says so — "All selected" over 200 of 4,000 would promise a bulk verb the other 3,800.
4716
+ */
4717
+ partial?: boolean;
4562
4718
  headerState: CheckboxHeaderState;
4563
4719
  /** Present only under `selectionReveal='on-demand'`; absent means the boxes always show. */
4564
4720
  armed?: boolean;
@@ -4598,7 +4754,9 @@ function BulkBar({
4598
4754
  />
4599
4755
  {/* `is-idle` lets the one-line toolbar keep "Select all" as the box's NAME but not its
4600
4756
  width on a phone (`denseGallery.css`). The count is the selection bar's readout. */}
4601
- <span className='cbmg-bulkbar-all-idle'>{count > 0 && headerState === true ? 'All selected' : 'Select all'}</span>
4757
+ <span className='cbmg-bulkbar-all-idle'>
4758
+ {count > 0 && headerState === true ? (partial ? 'All loaded selected' : 'All selected') : partial ? 'Select loaded' : 'Select all'}
4759
+ </span>
4602
4760
  </label>
4603
4761
  </div>
4604
4762
  );
@@ -8,6 +8,7 @@ export {
8
8
  MediaGallery,
9
9
  type MediaGalleryFastScroll,
10
10
  type MediaGalleryProps,
11
+ type MediaGalleryServerWindow,
11
12
  SelectionAction,
12
13
  } from './MediaGallery.js';
13
14
  // The table VIEW is exported on its own so an app that renders its own shell (the
@@ -958,6 +958,22 @@
958
958
  background: var(--card-raised, var(--muted));
959
959
  }
960
960
 
961
+ /* A row a server window has not loaded yet (`GalleryTable`'s `serverWindow`, forge task 5701):
962
+ the row's own height, so the track and the thumb stay true, with one quiet bar where the
963
+ name would be — never a spinner per row, and no hover, since there is nothing to press. */
964
+ .cbgt-row--wait,
965
+ .cbgt-row--wait:hover {
966
+ background: transparent;
967
+ }
968
+ .cbgt-wait-bar {
969
+ display: block;
970
+ width: 38%;
971
+ height: 10px;
972
+ border-radius: 5px;
973
+ background: var(--muted);
974
+ opacity: 0.6;
975
+ }
976
+
961
977
  .cbgt-row.is-selected {
962
978
  background: var(--card-overlay, var(--muted));
963
979
  box-shadow: inset 3px 0 0 0 var(--accent);
@@ -148,6 +148,27 @@ describe('the connection and the code', () => {
148
148
  expect(issueSnapshot().diagnostics.at(-1)?.kind).toBe('error');
149
149
  });
150
150
 
151
+ test('🔴 a script the browser injected (the page itself, line 1) is evidence, not "needs a fix" — forge tasks 5719-5728', () => {
152
+ install();
153
+ const page = 'https://app.test/?ssoError=x';
154
+ window.dispatchEvent(new ErrorEvent('error', { message: "ReferenceError: Can't find variable: __firefox__", filename: page, lineno: 1, colno: 12 }));
155
+ window.dispatchEvent(
156
+ new ErrorEvent('error', {
157
+ message: "TypeError: undefined is not an object (evaluating 'window.ethereum.selectedAddress = undefined')",
158
+ filename: 'https://app.test/#/login?next=%2Fsso',
159
+ lineno: 1,
160
+ colno: 16,
161
+ }),
162
+ );
163
+ expect(ids()).toEqual([]);
164
+ expect(issueSnapshot().diagnostics.at(-1)?.text).toContain('window.ethereum');
165
+ // The app's own code is still a bug: its bundle, a dev module, an inline script below the doctype.
166
+ window.dispatchEvent(new ErrorEvent('error', { message: 'TypeError: a', filename: 'https://app.test/assets/index-x.js', lineno: 1, colno: 2 }));
167
+ window.dispatchEvent(new ErrorEvent('error', { message: 'TypeError: b', filename: 'http://localhost:5173/src/main.tsx?t=1', lineno: 1, colno: 2 }));
168
+ window.dispatchEvent(new ErrorEvent('error', { message: 'TypeError: c', filename: page, lineno: 40, colno: 2 }));
169
+ expect(ids()).toHaveLength(3);
170
+ });
171
+
151
172
  test('console.error is recorded and still logs', () => {
152
173
  const logged: unknown[][] = [];
153
174
  const prior = console.error;