@terrafirmagreg-team/recipe 1.2.27 → 1.2.29

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 (47) hide show
  1. package/package.json +6 -6
  2. package/src/components/cards/card/index.tsx +17 -13
  3. package/src/components/cards/scroll-card/index.tsx +5 -1
  4. package/src/components/cards/slot-hitbox.tsx +22 -4
  5. package/src/components/mdx/recipe.tsx +2 -2
  6. package/src/components/tree.tsx +7 -6
  7. package/src/components/views/alloy/list.tsx +1 -0
  8. package/src/components/views/browser/axis-switcher.tsx +6 -7
  9. package/src/components/views/browser/card-grid.tsx +14 -7
  10. package/src/components/views/browser/index.tsx +23 -9
  11. package/src/components/views/browser/item-panel/index.tsx +125 -70
  12. package/src/components/views/browser/item-panel-grid/index.tsx +10 -2
  13. package/src/components/views/browser/item-view/tags.tsx +2 -0
  14. package/src/components/views/browser/type-view.tsx +5 -4
  15. package/src/components/views/calc/calculator/index.tsx +2 -0
  16. package/src/components/views/calc/sidebar.tsx +4 -1
  17. package/src/components/views/forge/list.tsx +1 -0
  18. package/src/components/views/landing.tsx +39 -11
  19. package/src/hooks/alloy/use-fluid-colors.ts +2 -3
  20. package/src/hooks/alloy/use-mix-state.ts +2 -0
  21. package/src/hooks/calc/use-actions.ts +6 -4
  22. package/src/hooks/calc/use-data.ts +1 -0
  23. package/src/hooks/calc/use-share.ts +6 -4
  24. package/src/hooks/use-add-to-calc.ts +2 -1
  25. package/src/hooks/use-index.ts +29 -8
  26. package/src/hooks/use-mount-limit.ts +9 -3
  27. package/src/hooks/use-panel-page.ts +8 -50
  28. package/src/hooks/use-panel-warmup.ts +129 -0
  29. package/src/hooks/use-query.ts +8 -2
  30. package/src/hooks/use-session.ts +47 -7
  31. package/src/lib/browser/fluid-outputs.ts +2 -3
  32. package/src/lib/cards/model.ts +5 -1
  33. package/src/lib/client/recipe.ts +24 -30
  34. package/src/lib/client-index/catalog.ts +2 -3
  35. package/src/lib/client-index/chrome.test.ts +87 -0
  36. package/src/lib/client-index/chrome.ts +27 -134
  37. package/src/lib/client-index/prepared-catalog.ts +80 -0
  38. package/src/lib/client-index/registry.ts +3 -4
  39. package/src/lib/client-index/rows.test.ts +127 -0
  40. package/src/lib/client-index/rows.ts +51 -194
  41. package/src/lib/client-index/store.ts +2 -3
  42. package/src/lib/client-index/tooltips.ts +4 -5
  43. package/src/lib/links.ts +10 -3
  44. package/src/lib/og.ts +39 -7
  45. package/src/lib/preview.ts +2 -2
  46. package/src/types/catalog.ts +18 -0
  47. package/src/types/index.ts +1 -0
@@ -9,7 +9,6 @@ import {
9
9
  useMemo,
10
10
  useRef,
11
11
  useState,
12
- type UIEvent,
13
12
  } from 'react';
14
13
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
15
14
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
@@ -33,9 +32,11 @@ import { RecipeSettings } from '@terrafirmagreg-team/recipe/components/views/bro
33
32
  import { QuerySearch } from '@terrafirmagreg-team/recipe/components/views/browser/query-controls';
34
33
  import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
35
34
  import { usePanelPage } from '@terrafirmagreg-team/recipe/hooks/use-panel-page';
35
+ import { dismissOpenTooltips } from '@terrafirmagreg-team/ui/lib/dismiss-tooltips';
36
36
  import { useItemPress } from '@terrafirmagreg-team/recipe/hooks/use-item-press';
37
37
  import { usePanelCells } from '@terrafirmagreg-team/recipe/hooks/use-panel-cells';
38
38
  import { usePanelTabs } from '@terrafirmagreg-team/recipe/hooks/use-panel-tabs';
39
+ import { usePanelWarmup } from '@terrafirmagreg-team/recipe/hooks/use-panel-warmup';
39
40
  import {
40
41
  RecipePanelSkeleton,
41
42
  RecipeTabsSkeleton,
@@ -95,7 +96,7 @@ export const ItemPanel = memo(function ItemPanel({
95
96
  const [expandedGroups, setExpandedGroups] = useState<ReadonlySet<string>>(
96
97
  new Set(),
97
98
  );
98
- const { cells, filtered, favoriteIds, dIndex, dNames, dLang } =
99
+ const { cells, favoriteIds, dIndex, dNames, dLang } =
99
100
  usePanelCells({
100
101
  dataset,
101
102
  index,
@@ -111,11 +112,17 @@ export const ItemPanel = memo(function ItemPanel({
111
112
  const favIds = useMemo(() => new Set(favoriteIds), [favoriteIds]);
112
113
  const { page: panelPage, setPage: setPanelPage } = usePanelPage(dataset);
113
114
  const list = usePagedList(cells, panelPage, pageSize);
115
+ const stripRef = useRef<HTMLDivElement | null>(null);
116
+ const drag = useRef(false);
117
+ const suppressScroll = useRef(0);
118
+ const lastWheelAt = useRef(0);
119
+ const flyTimer = useRef<number | undefined>(undefined);
120
+ const [flying, setFlying] = useState(false);
121
+ const [viewPage, setViewPage] = useState(list.page);
122
+ useEffect(() => setViewPage(list.page), [list.page]);
123
+ usePanelWarmup(dataset, cells, viewPage, pageSize);
114
124
 
115
- const gridResetKey = useMemo(
116
- () => [mode, filtered, favorites.entries],
117
- [mode, filtered, favorites.entries],
118
- );
125
+ const gridResetKey = mode;
119
126
  const onToggleGroup = useCallback((groupId: string) => {
120
127
  setExpandedGroups((prev) => {
121
128
  const next = new Set(prev);
@@ -134,6 +141,7 @@ export const ItemPanel = memo(function ItemPanel({
134
141
  tool: navTool,
135
142
  unit: navUnit,
136
143
  mix: navMix,
144
+ version: navVersion,
137
145
  } = nav;
138
146
  const cellNav = useMemo<RecipeHrefOpts>(
139
147
  () => ({
@@ -142,15 +150,16 @@ export const ItemPanel = memo(function ItemPanel({
142
150
  tool: navTool,
143
151
  unit: navUnit,
144
152
  mix: navMix,
153
+ version: navVersion,
145
154
  }),
146
- [navTab, navSearch, navTool, navUnit, navMix],
155
+ [navTab, navSearch, navTool, navUnit, navMix, navVersion],
147
156
  );
148
157
  const onHover = useCallback((target: FavoriteHoverTarget | undefined) => {
149
158
  favoriteHover.base = target;
150
159
  }, []);
151
160
 
152
161
  const setTab = (next: string) => {
153
- setPanelPage(0);
162
+ selectPage(0);
154
163
  replaceUrlState(
155
164
  recipeHref(dataset, resolved, {
156
165
  ...nav,
@@ -159,62 +168,89 @@ export const ItemPanel = memo(function ItemPanel({
159
168
  );
160
169
  };
161
170
 
162
- const stripRef = useRef<HTMLDivElement | null>(null);
163
- const fromScroll = useRef(false);
164
171
  const pageRef = useRef(list.page);
165
- pageRef.current = list.page;
166
- const [startRaw, setStartRaw] = useState(list.page - (PAGE_WINDOW >> 1));
167
- const maxStart = Math.max(0, list.pages - PAGE_WINDOW);
168
- const start = Math.max(0, Math.min(startRaw, maxStart));
172
+ useEffect(() => {
173
+ pageRef.current = list.page;
174
+ }, [list.page]);
175
+ const selectPage = (next: number) => {
176
+ const total = list.pages;
177
+ const wrapped = total > 1 ? ((next % total) + total) % total : 0;
178
+ pageRef.current = wrapped;
179
+ setViewPage(wrapped);
180
+ setPanelPage(wrapped);
181
+ };
182
+ const circular = list.pages > PAGE_WINDOW;
183
+ const base = circular
184
+ ? ((list.page - (PAGE_WINDOW >> 1)) % list.pages + list.pages) % list.pages
185
+ : 0;
169
186
  const windowPages = useMemo(() => {
170
- const end = Math.min(list.pages, start + PAGE_WINDOW);
171
- const out: number[] = [];
172
- for (let i = start; i < end; i++) out.push(i);
173
- return out;
174
- }, [start, list.pages]);
187
+ if (!circular) {
188
+ return Array.from({ length: list.pages }, (_, i) => i);
189
+ }
190
+ return Array.from(
191
+ { length: PAGE_WINDOW },
192
+ (_, i) => (base + i) % list.pages,
193
+ );
194
+ }, [circular, base, list.pages]);
175
195
  const windowCells = useMemo(
176
196
  () =>
177
197
  windowPages.map((p) => cells.slice(p * pageSize, (p + 1) * pageSize)),
178
198
  [cells, windowPages, pageSize],
179
199
  );
180
200
 
181
- useEffect(() => {
182
- if (list.page < start || list.page > start + PAGE_WINDOW - 1) {
183
- setStartRaw(list.page - (PAGE_WINDOW >> 1));
184
- }
185
- }, [list.page, start]);
186
-
187
201
  useLayoutEffect(() => {
188
202
  const el = stripRef.current;
189
203
  if (!el || w <= 0) return;
190
- const target = list.page * w;
204
+ const target = (circular ? PAGE_WINDOW >> 1 : list.page) * w;
191
205
  if (Math.abs(el.scrollLeft - target) > 2) {
192
- el.scrollTo({
193
- left: target,
194
- behavior: fromScroll.current ? 'instant' : 'smooth',
195
- });
206
+ suppressScroll.current = performance.now() + 120;
207
+ el.scrollLeft = target;
196
208
  }
197
- fromScroll.current = false;
198
- }, [list.page, start, w]);
209
+ }, [list.page, circular, w]);
199
210
 
200
211
  const idle = useRef<number | undefined>(undefined);
201
- useEffect(() => () => window.clearTimeout(idle.current), []);
202
-
203
- const onStripScroll = (event: UIEvent<HTMLDivElement>) => {
204
- const el = event.currentTarget;
205
- if (w <= 0) return;
206
- const next = Math.max(
207
- 0,
208
- Math.min(list.pages - 1, Math.round(el.scrollLeft / w)),
209
- );
212
+ const [scrolling, setScrolling] = useState(false);
213
+ useEffect(() => {
214
+ const up = () => {
215
+ drag.current = false;
216
+ };
217
+ window.addEventListener('pointerup', up);
218
+ window.addEventListener('pointercancel', up);
219
+ return () => {
220
+ window.removeEventListener('pointerup', up);
221
+ window.removeEventListener('pointercancel', up);
222
+ window.clearTimeout(idle.current);
223
+ window.clearTimeout(flyTimer.current);
224
+ };
225
+ }, []);
226
+ const endScroll = useCallback(() => {
227
+ const el = stripRef.current;
228
+ if (!el || w <= 0) return;
229
+ setScrolling(false);
230
+ const pos = Math.round(el.scrollLeft / w);
231
+ const next = circular
232
+ ? (((base + pos) % list.pages) + list.pages) % list.pages
233
+ : Math.max(0, Math.min(list.pages - 1, pos));
234
+ setViewPage(next);
210
235
  if (next !== pageRef.current) {
211
- fromScroll.current = true;
236
+ pageRef.current = next;
212
237
  setPanelPage(next);
213
238
  }
239
+ }, [w, circular, base, list.pages, setPanelPage]);
240
+
241
+ const onStripScroll = () => {
242
+ const el = stripRef.current;
243
+ if (!el || w <= 0) return;
244
+ dismissOpenTooltips();
245
+ if (performance.now() < suppressScroll.current) return;
246
+ if (drag.current) setScrolling(true);
214
247
  window.clearTimeout(idle.current);
215
- idle.current = window.setTimeout(
216
- () => setStartRaw(pageRef.current - (PAGE_WINDOW >> 1)),
217
- 160,
248
+ idle.current = window.setTimeout(endScroll, 160);
249
+ const pos = Math.round(el.scrollLeft / w);
250
+ setViewPage(
251
+ circular
252
+ ? (((base + pos) % list.pages) + list.pages) % list.pages
253
+ : Math.max(0, Math.min(list.pages - 1, pos)),
218
254
  );
219
255
  };
220
256
 
@@ -244,25 +280,47 @@ export const ItemPanel = memo(function ItemPanel({
244
280
  <div
245
281
  ref={stripRef}
246
282
  onScroll={onStripScroll}
283
+ onPointerDown={() => {
284
+ drag.current = true;
285
+ }}
247
286
  onWheel={(event) => {
248
- const el = stripRef.current;
249
- if (!el || w <= 0) return;
250
- el.scrollBy({
251
- left: Math.sign(event.deltaY) * w,
252
- behavior: 'smooth',
253
- });
287
+ if (w <= 0) return;
288
+ const delta =
289
+ Math.abs(event.deltaX) > Math.abs(event.deltaY)
290
+ ? event.deltaX
291
+ : event.deltaY;
292
+ const dir = Math.sign(delta);
293
+ if (!dir) return;
294
+ dismissOpenTooltips();
295
+ const now = performance.now();
296
+ if (now - lastWheelAt.current < 120) {
297
+ setFlying(true);
298
+ window.clearTimeout(flyTimer.current);
299
+ flyTimer.current = window.setTimeout(
300
+ () => setFlying(false),
301
+ 140,
302
+ );
303
+ }
304
+ lastWheelAt.current = now;
305
+ selectPage(pageRef.current + dir);
254
306
  }}
255
- className="flex h-full snap-x snap-mandatory overflow-x-auto overscroll-x-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
307
+ className={cn(
308
+ 'flex h-full snap-x snap-proximity overflow-x-auto overscroll-x-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',
309
+ (scrolling || flying) && '[&>*]:pointer-events-none',
310
+ )}
256
311
  >
257
- <div
258
- aria-hidden
259
- className="h-full shrink-0"
260
- style={{ width: start * w }}
261
- />
262
312
  {windowPages.map((pageIndex, i) => (
263
313
  <div
264
314
  key={pageIndex}
265
315
  className="h-full w-full shrink-0 snap-center"
316
+ style={
317
+ pageIndex === list.page
318
+ ? undefined
319
+ : {
320
+ contentVisibility: 'auto',
321
+ containIntrinsicSize: `${w}px ${h}px`,
322
+ }
323
+ }
266
324
  >
267
325
  <ItemPanelGrid
268
326
  cells={windowCells[i]}
@@ -278,17 +336,13 @@ export const ItemPanel = memo(function ItemPanel({
278
336
  onHover={onHover}
279
337
  onToggleGroup={onToggleGroup}
280
338
  draggableStacks={isCalc}
339
+ eager={pageIndex === viewPage}
340
+ frozen={
341
+ flying || (scrolling && pageIndex !== viewPage)
342
+ }
281
343
  />
282
344
  </div>
283
345
  ))}
284
- <div
285
- aria-hidden
286
- className="h-full shrink-0"
287
- style={{
288
- width:
289
- Math.max(0, list.pages - start - windowPages.length) * w,
290
- }}
291
- />
292
346
  </div>
293
347
  );
294
348
  }
@@ -308,19 +362,20 @@ export const ItemPanel = memo(function ItemPanel({
308
362
  />
309
363
  )}
310
364
  <Pager
311
- page={list.page}
365
+ loop
366
+ page={viewPage}
312
367
  pages={list.pages}
313
- to={list.to}
368
+ to={Math.min(list.total, (viewPage + 1) * pageSize)}
314
369
  total={list.total}
315
370
  label={t('{page}/{pages}', { note: 'recipe.page_of' })}
316
- onPage={setPanelPage}
371
+ onPage={selectPage}
317
372
  leading={
318
373
  <FavoriteButton
319
374
  variant="outline"
320
375
  active={mode === 'fav'}
321
376
  label={t('Favorites', { note: 'recipe.favorites' })}
322
377
  onToggle={() => {
323
- setPanelPage(0);
378
+ selectPage(0);
324
379
  setMode(mode === 'fav' ? 'all' : 'fav');
325
380
  }}
326
381
  className="size-9 [&_svg]:size-4.5"
@@ -337,7 +392,7 @@ export const ItemPanel = memo(function ItemPanel({
337
392
  params={nav}
338
393
  query={query}
339
394
  onQuery={(next) => {
340
- setPanelPage(0);
395
+ selectPage(0);
341
396
  setQuery(next);
342
397
  }}
343
398
  placeholder={t('Search items', { note: 'recipe.search' })}
@@ -27,6 +27,8 @@ export const ItemPanelGrid = memo(function ItemPanelGrid({
27
27
  onHover,
28
28
  onToggleGroup,
29
29
  draggableStacks,
30
+ eager,
31
+ frozen,
30
32
  }: {
31
33
  cells: ItemPanelCell[];
32
34
 
@@ -42,11 +44,17 @@ export const ItemPanelGrid = memo(function ItemPanelGrid({
42
44
  onHover?: (target: FavoriteHoverTarget | undefined) => void;
43
45
  onToggleGroup?: (id: string) => void;
44
46
  draggableStacks?: boolean;
47
+ eager?: boolean;
48
+ frozen?: boolean;
45
49
  }) {
46
50
  const t = useTranslations();
47
51
  const expandLabel = t('Expand', { note: 'recipe.expand' });
48
- const limit = useMountLimit(cells.length, resetKey);
49
- const shown = limit >= cells.length ? cells : cells.slice(0, limit);
52
+ const limit = useMountLimit(cells.length, resetKey, eager);
53
+ const shown = frozen
54
+ ? []
55
+ : limit >= cells.length
56
+ ? cells
57
+ : cells.slice(0, limit);
50
58
  const { gridRef, outlines } = useGroupOutlines(shown, cols, rows);
51
59
 
52
60
  return (
@@ -54,6 +54,7 @@ export function ItemTagGroups({
54
54
  id: tagPseudoId(id, tagKind),
55
55
  search: query || undefined,
56
56
  tab: nav.tab,
57
+ version: nav.version,
57
58
  })}
58
59
  variant="chip"
59
60
  size="sm"
@@ -70,6 +71,7 @@ export function ItemTagGroups({
70
71
  recipeHref(dataset, resolved, {
71
72
  type: 'emi:tag',
72
73
  search,
74
+ version: nav.version,
73
75
  }),
74
76
  );
75
77
  }}
@@ -3,7 +3,7 @@
3
3
  import { useEffect, useRef } from 'react';
4
4
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
5
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
6
- import { useAsyncResult, useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
6
+ import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
7
7
  import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
8
8
  import {
9
9
  RecipeCardGrid,
@@ -51,13 +51,14 @@ export function TypeView({ session }: { session: RecipeSession }) {
51
51
  placeId !== RECIPE_ALL_TYPE && nonEmptyIds.includes(placeId)
52
52
  ? placeId
53
53
  : nonEmptyIds[0];
54
- const rows = useAsyncValue(
54
+ const rowsRes = useAsyncResult(
55
55
  () =>
56
56
  index && shown
57
57
  ? loadTypeRows(dataset, index, shown)
58
58
  : Promise.resolve(EMPTY_ROWS),
59
59
  [dataset, index, shown],
60
60
  );
61
+ const rows = rowsRes.error ? EMPTY_ROWS : rowsRes.value;
61
62
 
62
63
  const allRows = rows ?? EMPTY_ROWS;
63
64
  const focusIndex = recipeId
@@ -123,7 +124,7 @@ export function TypeView({ session }: { session: RecipeSession }) {
123
124
  );
124
125
  };
125
126
 
126
- const body = index && !index.types.length && !indexLoading ? (
127
+ const body = !indexLoading && (!index || !index.types.length) ? (
127
128
  <RecipeCardGrid
128
129
  session={session}
129
130
  rows={EMPTY_ROWS}
@@ -137,7 +138,7 @@ export function TypeView({ session }: { session: RecipeSession }) {
137
138
  boxRef={boxRef}
138
139
  maxH={list.box.h}
139
140
  maxW={list.box.w}
140
- loading={index == null || (shown != null && rows === undefined)}
141
+ loading={indexLoading || (shown != null && rows === undefined)}
141
142
  empty={t('No recipes of this type.', { note: 'recipe.empty_type' })}
142
143
  onSwipe={onSwipe}
143
144
  />
@@ -70,6 +70,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
70
70
  } = useCalcActions({
71
71
  dataset,
72
72
  lang,
73
+ linkVersion: session.nav.version,
73
74
  cards: displayCards,
74
75
  wires,
75
76
  tagSelections,
@@ -108,6 +109,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
108
109
  <CalcSidebar
109
110
  dataset={dataset}
110
111
  lang={lang}
112
+ version={session.nav.version}
111
113
  langMap={deferredLangMap}
112
114
  summary={summary}
113
115
  onFocus={onFocusNode}
@@ -23,9 +23,11 @@ export function CalcSidebar({
23
23
  summary,
24
24
  onFocus,
25
25
  trees,
26
+ version,
26
27
  }: {
27
28
  dataset: DatasetRef;
28
29
  lang: string;
30
+ version?: string;
29
31
  langMap?: Record<string, string>;
30
32
  summary: {
31
33
  raw: CalcMaterial[];
@@ -82,6 +84,7 @@ export function CalcSidebar({
82
84
  children: rows.map((row): PageTree.Item => {
83
85
  const url = recipeStackHref(dataset, lang, row.id, {
84
86
  kind: row.kind,
87
+ version,
85
88
  });
86
89
  focusByUrl.set(url, row.id);
87
90
  return {
@@ -123,7 +126,7 @@ export function CalcSidebar({
123
126
  tree: { name: 'calc', $id: `calc:${stamp}`, children } as PageTree.Root,
124
127
  focusByUrl,
125
128
  };
126
- }, [dataset, lang, langMap, summary, t]);
129
+ }, [dataset, lang, langMap, summary, t, version]);
127
130
 
128
131
  const CalcItem = useMemo(() => {
129
132
  const focus = focusByUrl;
@@ -75,6 +75,7 @@ export function ForgeList({ session }: { session: RecipeSession }) {
75
75
  tool: 'forge',
76
76
  id: recipe.id,
77
77
  tab: session.tab,
78
+ version: session.nav.version,
78
79
  }),
79
80
  name: (
80
81
  <Entry
@@ -5,27 +5,55 @@ import type {
5
5
  SectionLandingView,
6
6
  } from '@terrafirmagreg-team/kit/components/views/routes';
7
7
  import type { RecipeSource } from '@terrafirmagreg-team/recipe/lib/source';
8
+ import { dumpPreloadHrefs } from '@terrafirmagreg-team/dump/lib/dump/preloads';
8
9
  import {
9
10
  RecipeBrowser,
10
11
  RecipeBrowserFallback,
11
12
  } from '@terrafirmagreg-team/recipe/components/views/browser';
12
13
 
13
- export function recipeLanding({
14
+ export async function recipeLanding({
14
15
  page,
15
16
  lang,
16
- }: SectionLandingProps<RecipeSource>): SectionLandingView {
17
+ }: SectionLandingProps<RecipeSource>): Promise<SectionLandingView> {
18
+ const { origin, hrefs } = await dumpPreloadHrefs({ id: page.dataset.id }, [
19
+ 'objects.json.gz',
20
+ 'manifest.json',
21
+ 'registry/items.ndjson',
22
+ 'registry/fluids.ndjson',
23
+ 'registry/items.icons.ndjson',
24
+ 'registry/fluids.icons.ndjson',
25
+ 'registry/blocks.icons.ndjson',
26
+ 'registry/tabs.ndjson',
27
+ 'registry/groups.ndjson',
28
+ 'registry/tags.ndjson',
29
+ 'registry/recipe_categories.ndjson',
30
+ `lang/${lang}.names.ndjson`,
31
+ `names/${lang}.ndjson`,
32
+ ]);
17
33
  return {
18
34
  node: (
19
- <WorkspaceBody className="viewport-body">
20
- <Suspense fallback={<RecipeBrowserFallback />}>
21
- <RecipeBrowser
22
- dataset={page.dataset.id}
23
- datasetTitle={page.datasetTitle ?? page.dataset.id}
24
- lang={lang}
25
- versions={page.versions}
35
+ <>
36
+ {origin ? <link rel="preconnect" href={origin} /> : null}
37
+ {hrefs.map((href) => (
38
+ <link
39
+ key={href}
40
+ rel="preload"
41
+ href={href}
42
+ as="fetch"
43
+ crossOrigin="anonymous"
26
44
  />
27
- </Suspense>
28
- </WorkspaceBody>
45
+ ))}
46
+ <WorkspaceBody className="viewport-body">
47
+ <Suspense fallback={<RecipeBrowserFallback />}>
48
+ <RecipeBrowser
49
+ dataset={page.dataset.id}
50
+ datasetTitle={page.datasetTitle ?? page.dataset.id}
51
+ lang={lang}
52
+ versions={page.versions}
53
+ />
54
+ </Suspense>
55
+ </WorkspaceBody>
56
+ </>
29
57
  ),
30
58
  workspace: { full: true, pagination: false },
31
59
  };
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
2
+ import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
3
3
 
4
4
  import { useEffect, useMemo, useReducer } from 'react';
5
5
  import { loadClientModAtlases } from '@terrafirmagreg-team/dump/lib/dump/client/atlases';
@@ -86,7 +86,7 @@ const loadFluidColor = createDatasetCache(
86
86
  }
87
87
  return n ? displayColor(r / n, g / n, b / n) : null;
88
88
  },
89
- (dataset, id) => `${dataset.id}/${dataset.version ?? ''}|${id}`,
89
+ (dataset, id) => datasetCacheKey(dataset, id),
90
90
  );
91
91
 
92
92
  export function useFluidColors(
@@ -122,4 +122,3 @@ export function useFluidColors(
122
122
  id ? (loadFluidColor.peek(dataset, id) ?? undefined) : undefined,
123
123
  );
124
124
  }
125
-
@@ -103,6 +103,7 @@ export function useMixState(recipe: AlloyRecipe, session: RecipeSession) {
103
103
  tab: session.tab,
104
104
  unit: unit === 'ingot' ? 'ingot' : undefined,
105
105
  mix,
106
+ version: session.nav.version,
106
107
  }),
107
108
  );
108
109
  }, [
@@ -112,6 +113,7 @@ export function useMixState(recipe: AlloyRecipe, session: RecipeSession) {
112
113
  session.dataset,
113
114
  resolved,
114
115
  session.tab,
116
+ session.nav.version,
115
117
  ]);
116
118
  const mix = useMemo(
117
119
  () => checkMix(recipe.components, amounts),
@@ -33,6 +33,7 @@ const newCardId = () =>
33
33
  export function useCalcActions({
34
34
  dataset,
35
35
  lang,
36
+ linkVersion,
36
37
  cards,
37
38
  wires,
38
39
  tagSelections,
@@ -49,6 +50,7 @@ export function useCalcActions({
49
50
  }: {
50
51
  dataset: DatasetRef;
51
52
  lang: Lang;
53
+ linkVersion?: string;
52
54
  cards: CalcCard[];
53
55
  wires: CalcWire[];
54
56
  tagSelections: Record<string, string>;
@@ -80,14 +82,14 @@ export function useCalcActions({
80
82
  } | null;
81
83
  if (res?.id) {
82
84
  await navigator.clipboard.writeText(
83
- `${window.location.origin}${recipeCalcHref(res.dataset ?? dataset, undefined, `s${res.id}`)}`,
85
+ `${window.location.origin}${recipeCalcHref(res.dataset ?? dataset, undefined, `s${res.id}`, linkVersion)}`,
84
86
  );
85
87
  return;
86
88
  }
87
89
  } catch {
88
90
  }
89
91
  await navigator.clipboard.writeText(
90
- `${window.location.origin}${recipeCalcHref(dataset, undefined, tree)}`,
92
+ `${window.location.origin}${recipeCalcHref(dataset, undefined, tree, linkVersion)}`,
91
93
  );
92
94
  });
93
95
 
@@ -278,12 +280,12 @@ export function useCalcActions({
278
280
  const onOpenItem = useCallback(
279
281
  (materialId: string, kind: CalcKind, relation?: RecipeRelation) => {
280
282
  window.open(
281
- recipeStackHref(dataset, lang, materialId, { kind, relation }),
283
+ recipeStackHref(dataset, lang, materialId, { kind, relation, version: linkVersion }),
282
284
  '_blank',
283
285
  'noopener',
284
286
  );
285
287
  },
286
- [dataset, lang],
288
+ [dataset, lang, linkVersion],
287
289
  );
288
290
 
289
291
  const onRemoveCard = useCallback(
@@ -28,6 +28,7 @@ export function useCalcData(session: RecipeSession) {
28
28
  storageKey,
29
29
  dataset,
30
30
  incoming: session.tree ?? '',
31
+ version: session.nav.version,
31
32
  });
32
33
  const {
33
34
  calcState,
@@ -16,19 +16,21 @@ export function useCalcShare({
16
16
  storageKey,
17
17
  dataset,
18
18
  incoming,
19
+ version,
19
20
  }: {
20
21
  storageKey: string;
21
22
  dataset: DatasetRef;
22
23
  incoming: string;
24
+ version?: string;
23
25
  }): boolean {
24
26
  const isShareId = incoming.startsWith('s');
25
27
  const [sharedTree, setSharedTree] = useState<string | null>(null);
26
28
  useEffect(() => {
27
29
  if (!isShareId) return;
28
30
  let cancelled = false;
29
- const { id: datasetId, version } = dataset;
31
+ const { id: datasetId, version: resolvedVersion } = dataset;
30
32
  void fetch(
31
- `/api/share/recipe/${encodeURIComponent(datasetId)}/${encodeURIComponent(incoming.slice(1))}${version ? `?version=${encodeURIComponent(version)}` : ''}`,
33
+ `/api/share/recipe/${encodeURIComponent(datasetId)}/${encodeURIComponent(incoming.slice(1))}${resolvedVersion ? `?version=${encodeURIComponent(resolvedVersion)}` : ''}`,
32
34
  )
33
35
  .then((res) => (res.ok ? res.json() : null))
34
36
  .then((body: { tree?: unknown } | null) => {
@@ -56,8 +58,8 @@ export function useCalcShare({
56
58
  entry.id,
57
59
  );
58
60
  }
59
- if (incoming) replaceUrlState(recipeCalcHref(dataset, resolved));
60
- }, [transport, storageKey, dataset, resolved, incoming]);
61
+ if (incoming) replaceUrlState(recipeCalcHref(dataset, resolved, undefined, version));
62
+ }, [transport, storageKey, dataset, resolved, incoming, version]);
61
63
 
62
64
  return isShareId && sharedTree === null;
63
65
  }
@@ -44,10 +44,11 @@ export function useAddToCalc(session: RecipeSession) {
44
44
  dataset,
45
45
  resolved,
46
46
  encodeCalcState({ ...state, cards }),
47
+ session.nav.version,
47
48
  ),
48
49
  );
49
50
  },
50
- [tree, dataset, resolved],
51
+ [tree, dataset, resolved, session.nav.version],
51
52
  );
52
53
  }
53
54