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
@@ -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);
@@ -0,0 +1,156 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
+ import { act, renderHook, waitFor } from '@testing-library/react';
4
+ import type { ReactNode } from 'react';
5
+ import { createElement } from 'react';
6
+ import { joinPrefix, prefixEnabledThrough, prefixPageCount, usePrefixList } from './usePrefixList.js';
7
+ import type { WindowPage } from './useWindowedList.js';
8
+
9
+ // The prefix behind Collections' whole-album scroller (forge task 5701). The browser half — a thumb dragged to the
10
+ // bottom of 4,180 files at 390×844 — is `e2e/gallery-window.spec.ts`; these pin the page math and the request shape.
11
+
12
+ const page = (from: number, n: number, total: number): WindowPage<number> => ({
13
+ items: Array.from({ length: n }, (_, i) => from + i),
14
+ total,
15
+ });
16
+
17
+ describe('prefixPageCount', () => {
18
+ test('holds enough pages for the reach, at least one', () => {
19
+ expect(prefixPageCount(0, 500, undefined)).toBe(1);
20
+ expect(prefixPageCount(500, 500, undefined)).toBe(1);
21
+ expect(prefixPageCount(501, 500, undefined)).toBe(2);
22
+ });
23
+
24
+ test('never asks past the last page once the size is known', () => {
25
+ expect(prefixPageCount(99_999, 500, 4180)).toBe(9);
26
+ expect(prefixPageCount(10, 500, 0)).toBe(1);
27
+ });
28
+ });
29
+
30
+ describe('prefixEnabledThrough', () => {
31
+ test('opens `inFlight` pages from the first one missing', () => {
32
+ expect(prefixEnabledThrough([true, true, false, false, false, false, false], 4)).toBe(6);
33
+ });
34
+
35
+ test('opens every page once all are in hand', () => {
36
+ expect(prefixEnabledThrough([true, true, true], 4)).toBe(3);
37
+ });
38
+
39
+ test('opens at least one, whatever inFlight says', () => {
40
+ expect(prefixEnabledThrough([false, false], 0)).toBe(1);
41
+ });
42
+ });
43
+
44
+ describe('joinPrefix', () => {
45
+ test('joins the pages from 0 and stops at the first gap', () => {
46
+ const joined = joinPrefix([page(0, 3, 10), undefined, page(6, 3, 10)], 3);
47
+ expect(joined.items).toEqual([0, 1, 2]);
48
+ expect(joined.total).toBe(10);
49
+ });
50
+
51
+ test('has no size before the first page', () => {
52
+ expect(joinPrefix([undefined, page(3, 3, 10)], 3)).toEqual({ items: [], total: undefined });
53
+ });
54
+
55
+ test('🔴 an optimistic delete in page 0 keeps the size right — what lies past the last page is the one true number', () => {
56
+ // Row 1 deleted: page 0 lost it and its own total dropped to 9; page 1 still says 10.
57
+ const edited = { items: [0, 2], total: 9 };
58
+ const joined = joinPrefix([edited, page(3, 3, 10)], 3);
59
+ expect(joined.items).toEqual([0, 2, 3, 4, 5]);
60
+ expect(joined.total).toBe(9);
61
+ });
62
+
63
+ test('drops a row a refetched page repeats from the page after it', () => {
64
+ // Page 0 refetched after a delete elsewhere shifted every offset by one: its last row is page 1's first.
65
+ const joined = joinPrefix([{ items: [0, 1, 3], total: 9 }, { items: [3, 4, 5], total: 10 }], 3, (n) => n);
66
+ expect(joined.items).toEqual([0, 1, 3, 4, 5]);
67
+ });
68
+ });
69
+
70
+ describe('usePrefixList', () => {
71
+ const TOTAL = 4180;
72
+ const PAGE = 500;
73
+ const makeServer = () => {
74
+ const calls: number[] = [];
75
+ const fetchRange = (offset: number, limit: number) => {
76
+ calls.push(offset);
77
+ return Promise.resolve(page(offset, Math.max(0, Math.min(limit, TOTAL - offset)), TOTAL));
78
+ };
79
+ return { calls, fetchRange };
80
+ };
81
+ const wrapper = () => {
82
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
83
+ return ({ children }: { children: ReactNode }) => createElement(QueryClientProvider, { client }, children);
84
+ };
85
+
86
+ test('loads one page, then THROUGH a far reach — each offset once, in order, the last item last', async () => {
87
+ const server = makeServer();
88
+ const { result } = renderHook(
89
+ () => usePrefixList({ queryKey: ['album'], fetchRange: server.fetchRange, pageSize: PAGE }),
90
+ { wrapper: wrapper() },
91
+ );
92
+ expect(result.current.isLoading).toBe(true);
93
+ await waitFor(() => expect(result.current.items.length).toBe(PAGE));
94
+ expect(result.current.total).toBe(TOTAL);
95
+ expect(result.current.serverWindow.total).toBe(TOTAL);
96
+
97
+ act(() => result.current.serverWindow.onNeedThrough(TOTAL));
98
+ await waitFor(() => expect(result.current.items.length).toBe(TOTAL));
99
+ expect(result.current.items.at(-1)).toBe(TOTAL - 1);
100
+ expect(result.current.items.every((n, i) => n === i)).toBe(true);
101
+ expect(server.calls).toEqual([0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000]);
102
+ });
103
+
104
+ test('an ask the prefix already answers fetches nothing', async () => {
105
+ const server = makeServer();
106
+ const { result } = renderHook(
107
+ () => usePrefixList({ queryKey: ['again'], fetchRange: server.fetchRange, pageSize: PAGE }),
108
+ { wrapper: wrapper() },
109
+ );
110
+ await waitFor(() => expect(result.current.items.length).toBe(PAGE));
111
+ act(() => result.current.needThrough(120));
112
+ act(() => result.current.needThrough(PAGE));
113
+ await new Promise((r) => setTimeout(r, 20));
114
+ expect(server.calls).toEqual([0]);
115
+ });
116
+
117
+ test('a new key starts again at one page', async () => {
118
+ const server = makeServer();
119
+ let key = 'a';
120
+ const { result, rerender } = renderHook(
121
+ () => usePrefixList({ queryKey: ['place', key], fetchRange: server.fetchRange, pageSize: PAGE }),
122
+ { wrapper: wrapper() },
123
+ );
124
+ await waitFor(() => expect(result.current.items.length).toBe(PAGE));
125
+ act(() => result.current.needThrough(1200));
126
+ await waitFor(() => expect(result.current.items.length).toBe(1500));
127
+ key = 'b';
128
+ rerender();
129
+ await waitFor(() => expect(result.current.items.length).toBe(PAGE));
130
+ expect(server.calls.slice(3)).toEqual([0]);
131
+ });
132
+
133
+ test('🔴 a failed refresh over a held page is a refetch error, never the empty-state error (STA-11)', async () => {
134
+ let fail = false;
135
+ const fetchRange = (offset: number, limit: number) =>
136
+ fail ? Promise.reject(new Error('offline')) : Promise.resolve(page(offset, limit, TOTAL));
137
+ const { result } = renderHook(() => usePrefixList({ queryKey: ['held'], fetchRange, pageSize: PAGE }), {
138
+ wrapper: wrapper(),
139
+ });
140
+ await waitFor(() => expect(result.current.items.length).toBe(PAGE));
141
+ fail = true;
142
+ act(() => result.current.refetch());
143
+ await waitFor(() => expect(result.current.isRefetchError).toBe(true));
144
+ expect(result.current.isLoadingError).toBe(false);
145
+ expect(result.current.items.length).toBe(PAGE);
146
+ });
147
+
148
+ test('a first page that fails is a loading error', async () => {
149
+ const fetchRange = () => Promise.reject(new Error('offline'));
150
+ const { result } = renderHook(() => usePrefixList({ queryKey: ['never'], fetchRange, pageSize: PAGE }), {
151
+ wrapper: wrapper(),
152
+ });
153
+ await waitFor(() => expect(result.current.isLoadingError).toBe(true));
154
+ expect(result.current.isRefetchError).toBe(false);
155
+ });
156
+ });