cursedbelt 6.28.0 β†’ 6.30.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 (107) hide show
  1. package/dist/react/canvas-hud/HudControls.d.ts +2 -0
  2. package/dist/react/canvas-hud/HudControls.d.ts.map +1 -1
  3. package/dist/react/canvas-hud/HudControls.js +3 -1
  4. package/dist/react/canvas-hud/HudControls.js.map +1 -1
  5. package/dist/react/components/ColorSwatches.d.ts.map +1 -1
  6. package/dist/react/components/ColorSwatches.js +1 -1
  7. package/dist/react/components/ColorSwatches.js.map +1 -1
  8. package/dist/react/components/DataTable/serverWindowWatch.d.ts +5 -4
  9. package/dist/react/components/DataTable/serverWindowWatch.d.ts.map +1 -1
  10. package/dist/react/components/DataTable/serverWindowWatch.js +7 -9
  11. package/dist/react/components/DataTable/serverWindowWatch.js.map +1 -1
  12. package/dist/react/components/ScrollArea.d.ts +9 -1
  13. package/dist/react/components/ScrollArea.d.ts.map +1 -1
  14. package/dist/react/components/ScrollArea.js +9 -3
  15. package/dist/react/components/ScrollArea.js.map +1 -1
  16. package/dist/react/components/TagsEditor.d.ts +12 -2
  17. package/dist/react/components/TagsEditor.d.ts.map +1 -1
  18. package/dist/react/components/TagsEditor.js +23 -8
  19. package/dist/react/components/TagsEditor.js.map +1 -1
  20. package/dist/react/index.d.ts +1 -0
  21. package/dist/react/index.d.ts.map +1 -1
  22. package/dist/react/index.js +1 -0
  23. package/dist/react/index.js.map +1 -1
  24. package/dist/react/lib/keepAsking.d.ts +30 -0
  25. package/dist/react/lib/keepAsking.d.ts.map +1 -0
  26. package/dist/react/lib/keepAsking.js +57 -0
  27. package/dist/react/lib/keepAsking.js.map +1 -0
  28. package/dist/react/lib/tagList.d.ts +15 -0
  29. package/dist/react/lib/tagList.d.ts.map +1 -1
  30. package/dist/react/lib/tagList.js +29 -0
  31. package/dist/react/lib/tagList.js.map +1 -1
  32. package/dist/react/map-frame/MapFrame.d.ts +11 -1
  33. package/dist/react/map-frame/MapFrame.d.ts.map +1 -1
  34. package/dist/react/map-frame/MapFrame.js +25 -2
  35. package/dist/react/map-frame/MapFrame.js.map +1 -1
  36. package/dist/react/map-frame/geo.d.ts +27 -0
  37. package/dist/react/map-frame/geo.d.ts.map +1 -1
  38. package/dist/react/map-frame/geo.js +38 -0
  39. package/dist/react/map-frame/geo.js.map +1 -1
  40. package/dist/react/map-frame/index.d.ts +4 -4
  41. package/dist/react/map-frame/index.d.ts.map +1 -1
  42. package/dist/react/map-frame/index.js +2 -2
  43. package/dist/react/map-frame/index.js.map +1 -1
  44. package/dist/react/media/DenseGalleryShell.d.ts +7 -1
  45. package/dist/react/media/DenseGalleryShell.d.ts.map +1 -1
  46. package/dist/react/media/DenseGalleryShell.js +2 -2
  47. package/dist/react/media/DenseGalleryShell.js.map +1 -1
  48. package/dist/react/media-gallery/GalleryTable.d.ts +12 -1
  49. package/dist/react/media-gallery/GalleryTable.d.ts.map +1 -1
  50. package/dist/react/media-gallery/GalleryTable.js +37 -6
  51. package/dist/react/media-gallery/GalleryTable.js.map +1 -1
  52. package/dist/react/media-gallery/MediaGallery.d.ts +39 -3
  53. package/dist/react/media-gallery/MediaGallery.d.ts.map +1 -1
  54. package/dist/react/media-gallery/MediaGallery.js +122 -12
  55. package/dist/react/media-gallery/MediaGallery.js.map +1 -1
  56. package/dist/react/media-gallery/index.d.ts +1 -1
  57. package/dist/react/media-gallery/index.d.ts.map +1 -1
  58. package/dist/react/media-gallery/index.js.map +1 -1
  59. package/dist/react/media-gallery/mediaGallery.css +16 -0
  60. package/dist/react/usePrefixList.d.ts +82 -0
  61. package/dist/react/usePrefixList.d.ts.map +1 -0
  62. package/dist/react/usePrefixList.js +139 -0
  63. package/dist/react/usePrefixList.js.map +1 -0
  64. package/dist/styles-areas/core.css +8 -4
  65. package/dist/styles-utilities.css +18 -0
  66. package/dist/testing/shell.d.ts +1 -0
  67. package/dist/testing/shell.d.ts.map +1 -1
  68. package/dist/testing/shell.js +2 -0
  69. package/dist/testing/shell.js.map +1 -1
  70. package/package.json +9 -3
  71. package/scripts/build.spec.ts +39 -0
  72. package/scripts/build.ts +131 -0
  73. package/scripts/styleAreas.ts +2 -0
  74. package/src/buildIsStaged.spec.ts +57 -47
  75. package/src/react/canvas-hud/HudControls.spec.tsx +13 -1
  76. package/src/react/canvas-hud/HudControls.tsx +3 -1
  77. package/src/react/components/ColorSwatches.tsx +5 -1
  78. package/src/react/components/DataTable/serverWindowWatch.ts +8 -9
  79. package/src/react/components/ScrollArea.spec.tsx +25 -0
  80. package/src/react/components/ScrollArea.tsx +18 -1
  81. package/src/react/components/TagsEditor.spec.tsx +66 -0
  82. package/src/react/components/TagsEditor.tsx +31 -7
  83. package/src/react/index.ts +6 -0
  84. package/src/react/lib/keepAsking.spec.ts +89 -0
  85. package/src/react/lib/keepAsking.ts +63 -0
  86. package/src/react/lib/tagList.spec.ts +23 -1
  87. package/src/react/lib/tagList.ts +33 -0
  88. package/src/react/map-frame/MapFrame.tsx +33 -0
  89. package/src/react/map-frame/MapFrame.wheel.spec.tsx +69 -0
  90. package/src/react/map-frame/geo.spec.ts +32 -0
  91. package/src/react/map-frame/geo.ts +54 -0
  92. package/src/react/map-frame/index.ts +5 -2
  93. package/src/react/media/DenseGalleryShell.tsx +8 -0
  94. package/src/react/media-gallery/GalleryTable.tsx +54 -6
  95. package/src/react/media-gallery/MediaGallery.spec.tsx +61 -0
  96. package/src/react/media-gallery/MediaGallery.tsx +170 -12
  97. package/src/react/media-gallery/index.ts +1 -0
  98. package/src/react/media-gallery/mediaGallery.css +16 -0
  99. package/src/react/usePrefixList.spec.tsx +156 -0
  100. package/src/react/usePrefixList.ts +229 -0
  101. package/src/styles-areas/core.css +8 -4
  102. package/src/styles-utilities.css +18 -0
  103. package/src/stylesAreas.spec.ts +2 -1
  104. package/src/stylesStaticMatches.spec.ts +2 -3
  105. package/src/stylesUtilitiesMatches.spec.ts +2 -3
  106. package/src/testing/shell.ts +2 -0
  107. package/src/verifyGraph.spec.ts +22 -6
@@ -0,0 +1,69 @@
1
+ /**
2
+ * What a wheel over the map MEANS, per mode (DESIGN CNV-1, forge task 5761).
3
+ *
4
+ * An embedded map (trivia's Learn more, photos' Places) sits in a scrolling page: a plain wheel
5
+ * must scroll the page β€” no `preventDefault`, no committed view (a commit is a billable render)
6
+ * β€” and the frame says "Hold ⌘ to zoom". A pinch (ctrlKey) or ⌘ still zooms. A fullscreen map
7
+ * (family's atlas, the default) zooms on every wheel, as before.
8
+ */
9
+ import { afterEach, describe, expect, jest, test } from 'bun:test';
10
+ import { act, cleanup, render } from '@testing-library/react';
11
+ import { MapFrame, type MapWheelMode, VIEW_HEIGHT, VIEW_WIDTH, WHEEL_SETTLE_MS } from './MapFrame.js';
12
+
13
+ afterEach(() => {
14
+ cleanup();
15
+ jest.useRealTimers();
16
+ });
17
+
18
+ function mount(wheel: MapWheelMode | undefined) {
19
+ const onViewChange = jest.fn();
20
+ const { container } = render(
21
+ <MapFrame center={{ lat: 52.5, lng: -2.1 }} zoom={5} theme='light' label='A map' onViewChange={onViewChange} wheel={wheel}>
22
+ {() => null}
23
+ </MapFrame>,
24
+ );
25
+ const svg = container.querySelector('svg') as SVGSVGElement;
26
+ // happy-dom lays nothing out; the frame reads its box to anchor the zoom.
27
+ svg.getBoundingClientRect = () => ({ left: 0, top: 0, width: VIEW_WIDTH, height: VIEW_HEIGHT }) as DOMRect;
28
+ const spin = (init: WheelEventInit) => {
29
+ const event = new WheelEvent('wheel', { bubbles: true, cancelable: true, clientX: 320, clientY: 200, deltaY: -100, ...init });
30
+ // happy-dom's WheelEvent drops the modifier keys from its init; a browser keeps them.
31
+ for (const key of ['ctrlKey', 'metaKey', 'shiftKey'] as const) Object.defineProperty(event, key, { value: Boolean(init[key]) });
32
+ act(() => {
33
+ svg.dispatchEvent(event);
34
+ });
35
+ act(() => {
36
+ jest.advanceTimersByTime(WHEEL_SETTLE_MS + 10);
37
+ });
38
+ return event;
39
+ };
40
+ return { container, onViewChange, spin };
41
+ }
42
+
43
+ describe('MapFrame wheel modes', () => {
44
+ test('embedded: a plain wheel scrolls the page β€” no preventDefault, no committed view β€” and shows the hint', () => {
45
+ jest.useFakeTimers();
46
+ const { container, onViewChange, spin } = mount('embedded');
47
+ const event = spin({});
48
+ expect(event.defaultPrevented).toBe(false);
49
+ expect(onViewChange).not.toHaveBeenCalled();
50
+ expect(container.querySelector('[data-testid="canvas-zoom-hint"]')?.getAttribute('aria-hidden')).toBe('false');
51
+ });
52
+
53
+ test('embedded: a pinch (ctrlKey) zooms and commits ONE view', () => {
54
+ jest.useFakeTimers();
55
+ const { onViewChange, spin } = mount('embedded');
56
+ const event = spin({ ctrlKey: true });
57
+ expect(event.defaultPrevented).toBe(true);
58
+ expect(onViewChange).toHaveBeenCalledTimes(1);
59
+ });
60
+
61
+ test('fullscreen (the default): a plain wheel zooms, and no hint is drawn', () => {
62
+ jest.useFakeTimers();
63
+ const { container, onViewChange, spin } = mount(undefined);
64
+ const event = spin({});
65
+ expect(event.defaultPrevented).toBe(true);
66
+ expect(onViewChange).toHaveBeenCalledTimes(1);
67
+ expect(container.querySelector('[data-testid="canvas-zoom-hint"]')).toBeNull();
68
+ });
69
+ });
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { describe, expect, test } from "bun:test";
11
11
  import {
12
+ labelSides,
12
13
  boundsOf,
13
14
  centerOf,
14
15
  type Clusterable,
@@ -391,3 +392,34 @@ describe("clusterByScreen β€” the answer to forty pins on one degree", () => {
391
392
  });
392
393
  });
393
394
 
395
+
396
+ describe("labelSides β€” a pin's name stays inside what the box shows and off every other (forge task 5761)", () => {
397
+ // What a 358Γ—448 phone box shows of the 640Γ—400 viewport (visibleArea's slice).
398
+ const phone = { x: 160, width: 320 };
399
+ const mark = (name: string, x: number, y: number, rank = 0) => ({ x, y, r: 8, name: `${name} place`, rank });
400
+
401
+ test("reads to the right with room, to the left near the visible right edge", () => {
402
+ expect(labelSides([mark("green", 200, 100), mark("bellevue", 460, 300)], phone)).toEqual(["right", "left"]);
403
+ });
404
+
405
+ test("two names on one line: the lower rank chooses first, the other takes the free side", () => {
406
+ expect(labelSides([mark("pike", 200, 300, 0), mark("bellevue", 330, 300, 1)], phone)).toEqual(["right", "right"]);
407
+ expect(labelSides([mark("pike", 260, 300, 0), mark("bellevue", 300, 300, 1)], phone)).toEqual(["left", "right"]);
408
+ // Rank, not position, decides: the same two listed the other way round answer the same, by position.
409
+ expect(labelSides([mark("bellevue", 300, 300, 1), mark("pike", 260, 300, 0)], phone)).toEqual(["right", "left"]);
410
+ });
411
+
412
+ test("a name with no free side is left off, and a mark with no name is skipped", () => {
413
+ expect(labelSides([{ ...mark("long", 320, 300), name: "The house on the hill above the river where everyone stayed" }], phone)).toEqual([null]);
414
+ expect(labelSides([mark("west", 250, 300, 0), mark("east", 330, 300, 0), mark("mid", 265, 300, 1)], phone)).toEqual(["left", "right", null]);
415
+ expect(labelSides([{ x: 200, y: 100, r: 8, name: null }], phone)).toEqual([null]);
416
+ });
417
+
418
+ test("two pins on one spot: the first-ranked takes the right, the other the left", () => {
419
+ const marks = [
420
+ { name: "Sagrada FamΓ­lia", x: 500, y: 100, r: 7, rank: 3 },
421
+ { name: "Barcelona", x: 500, y: 100, r: 7, rank: 0 },
422
+ ];
423
+ expect(labelSides(marks, { x: 0, width: 640 })).toEqual(["left", "right"]);
424
+ });
425
+ });
@@ -419,3 +419,57 @@ function formatScaleNumber(value: number): string {
419
419
  * Mercator's ground resolution is defined against. */
420
420
  const EQUATOR_METRES = 40075016.686;
421
421
  const METRES_PER_MILE = 1609.344;
422
+
423
+ /** One pin a name may be printed beside, in viewport units. */
424
+ export interface LabelMark {
425
+ x: number;
426
+ y: number;
427
+ /** The pin's radius β€” the name starts just past it. */
428
+ r: number;
429
+ /** The name to print, or null for a pin with no name to place. */
430
+ name: string | null;
431
+ /** Who chooses first: the LOWER rank picks its side before the higher. Ties keep their order. Default 0. */
432
+ rank?: number;
433
+ }
434
+
435
+ /** A name's width per character at the overlay's 12-unit type β€” an estimate, kept on the generous side. */
436
+ export const LABEL_EM = 6.6;
437
+
438
+ /**
439
+ * Pure: which side of its pin each name reads on β€” right, else left, else not printed (null).
440
+ * Marks choose by `rank` (lowest first, so the right answer or the heaviest place gets its
441
+ * side before the rest); a name may not cover another name, any other pin, or run past
442
+ * `area` β€” the part of the frame the box actually shows (`visibleArea`). A name left off is
443
+ * still the pin's `<title>` and whatever list the app draws under the map.
444
+ *
445
+ * Returned BY POSITION, matching `marks` (forge task 5761 lifted it from photos' PlacesMap,
446
+ * which keyed by id, and trivia's LearnMap, which ranked by role).
447
+ */
448
+ export function labelSides(marks: readonly LabelMark[], area: { x: number; width: number }): ("right" | "left" | null)[] {
449
+ type Rect = { left: number; top: number; right: number; bottom: number };
450
+ const overlaps = (a: Rect, b: Rect): boolean => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
451
+ const pins: Rect[] = marks.map((m) => ({ left: m.x - m.r, top: m.y - m.r, right: m.x + m.r, bottom: m.y + m.r }));
452
+ const taken: Rect[] = [];
453
+ const sides: ("right" | "left" | null)[] = marks.map(() => null);
454
+ const byRank = marks.map((m, i) => ({ m, i })).sort((a, b) => (a.m.rank ?? 0) - (b.m.rank ?? 0) || a.i - b.i);
455
+ for (const { m, i } of byRank) {
456
+ if (m.name === null) continue;
457
+ const width = m.name.length * LABEL_EM;
458
+ const top = m.y - 8;
459
+ const bottom = m.y + 6;
460
+ const candidates = [
461
+ { side: "right" as const, rect: { left: m.x + m.r + 4, top, right: m.x + m.r + 6 + width, bottom } },
462
+ { side: "left" as const, rect: { left: m.x - m.r - 6 - width, top, right: m.x - m.r - 4, bottom } },
463
+ ];
464
+ const fits = candidates.find(
465
+ ({ rect }) =>
466
+ rect.left >= area.x + 2 &&
467
+ rect.right <= area.x + area.width - 2 &&
468
+ !taken.some((t) => overlaps(t, rect)) &&
469
+ !pins.some((p, j) => j !== i && overlaps(p, rect)),
470
+ );
471
+ sides[i] = fits?.side ?? null;
472
+ if (fits) taken.push(fits.rect);
473
+ }
474
+ return sides;
475
+ }
@@ -2,7 +2,7 @@
2
2
  // overlay on top that projects with the same Web Mercator math, one billable render per
3
3
  // gesture (forge task 3700, lifted from apps/family). Its own subpath, so a page with no map
4
4
  // never pulls it in; the pure math is also its own leaf, `cursedbelt/react/map-frame/geo`.
5
- export type { Bounds, Cluster, Clusterable, LatLng, Viewport } from './geo.js';
5
+ export type { Bounds, Cluster, Clusterable, LabelMark, LatLng, Viewport } from './geo.js';
6
6
  export {
7
7
  boundsOf,
8
8
  centerOf,
@@ -10,6 +10,8 @@ export {
10
10
  formatDistance,
11
11
  fromWorldFraction,
12
12
  haversineKm,
13
+ LABEL_EM,
14
+ labelSides,
13
15
  MAX_ZOOM,
14
16
  MERCATOR_MAX_LAT,
15
17
  MIN_ZOOM,
@@ -21,7 +23,7 @@ export {
21
23
  zoomAnchoredAt,
22
24
  zoomToFit,
23
25
  } from './geo.js';
24
- export type { MapFrameProps } from './MapFrame.js';
26
+ export type { MapFrameProps, MapWheelMode } from './MapFrame.js';
25
27
  export {
26
28
  imagePlacement,
27
29
  MapFrame,
@@ -30,5 +32,6 @@ export {
30
32
  VIEW_HEIGHT,
31
33
  VIEW_WIDTH,
32
34
  visibleArea,
35
+ WHEEL_HINT_MS,
33
36
  WHEEL_SETTLE_MS,
34
37
  } from './MapFrame.js';
@@ -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
+ });