@terrafirmagreg-team/recipe 1.2.28 → 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 (41) hide show
  1. package/package.json +5 -5
  2. package/src/components/cards/slot-hitbox.tsx +22 -4
  3. package/src/components/tree.tsx +4 -4
  4. package/src/components/views/alloy/list.tsx +1 -0
  5. package/src/components/views/browser/axis-switcher.tsx +6 -7
  6. package/src/components/views/browser/card-grid.tsx +10 -2
  7. package/src/components/views/browser/index.tsx +23 -9
  8. package/src/components/views/browser/item-panel/index.tsx +125 -75
  9. package/src/components/views/browser/item-panel-grid/cell.tsx +0 -6
  10. package/src/components/views/browser/item-panel-grid/index.tsx +10 -5
  11. package/src/components/views/browser/item-view/tags.tsx +2 -0
  12. package/src/components/views/browser/type-view.tsx +5 -4
  13. package/src/components/views/calc/calculator/index.tsx +2 -0
  14. package/src/components/views/calc/sidebar.tsx +4 -1
  15. package/src/components/views/forge/list.tsx +1 -0
  16. package/src/hooks/alloy/use-fluid-colors.ts +2 -3
  17. package/src/hooks/alloy/use-mix-state.ts +2 -0
  18. package/src/hooks/calc/use-actions.ts +6 -4
  19. package/src/hooks/calc/use-data.ts +1 -0
  20. package/src/hooks/calc/use-share.ts +6 -4
  21. package/src/hooks/use-add-to-calc.ts +2 -1
  22. package/src/hooks/use-index.ts +19 -8
  23. package/src/hooks/use-mount-limit.ts +9 -3
  24. package/src/hooks/use-panel-warmup.ts +129 -0
  25. package/src/hooks/use-query.ts +8 -2
  26. package/src/hooks/use-session.ts +11 -4
  27. package/src/lib/browser/fluid-outputs.ts +2 -3
  28. package/src/lib/cards/model.ts +5 -1
  29. package/src/lib/client/recipe.ts +23 -29
  30. package/src/lib/client-index/catalog.ts +2 -3
  31. package/src/lib/client-index/chrome.test.ts +87 -0
  32. package/src/lib/client-index/chrome.ts +27 -134
  33. package/src/lib/client-index/prepared-catalog.ts +80 -0
  34. package/src/lib/client-index/registry.ts +3 -4
  35. package/src/lib/client-index/rows.test.ts +127 -0
  36. package/src/lib/client-index/rows.ts +51 -194
  37. package/src/lib/client-index/store.ts +2 -3
  38. package/src/lib/client-index/tooltips.ts +2 -3
  39. package/src/lib/links.ts +10 -3
  40. package/src/types/catalog.ts +18 -0
  41. package/src/types/index.ts +1 -0
@@ -1,78 +1,34 @@
1
- import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
1
+ import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
2
2
  import type {
3
3
  RecipeCompactIndex,
4
4
  RecipeCompactRow,
5
5
  } from '@terrafirmagreg-team/recipe/types';
6
6
  import { clientDumpJson, loadClientManifest } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
7
7
  import { dumpRelPublicUrl } from '@terrafirmagreg-team/dump/lib/dump/paths';
8
- import { asNumber, asRecord, asString } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
9
- import {
10
- asTaggedReference,
11
- stackIdFromRef,
12
- } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
13
8
  import type { RecipeTypeRow } from '@terrafirmagreg-team/dump/lib/dump/manifest/dto';
9
+ import type {
10
+ PreparedRecipeRow,
11
+ RecipeRowsDocument,
12
+ } from '@terrafirmagreg-team/dump/lib/dump/gen';
14
13
  import {
15
- clientRecipeFileRels,
14
+ clientPreparedRecipeRows,
16
15
  loadClientRecipe,
17
16
  } from '@terrafirmagreg-team/recipe/lib/client/recipe';
18
- import {
19
- outputBoundary,
20
- slotIoRole,
21
- } from '@terrafirmagreg-team/recipe/lib/data/slot-io';
22
- import type { DumpRecipeLayout } from '@terrafirmagreg-team/recipe/lib/data/category/dto';
23
- import type {
24
- Recipe,
25
- RecipeSlotType,
26
- } from '@terrafirmagreg-team/recipe/lib/data/dto';
17
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
27
18
  import { createDatasetCache } from '@terrafirmagreg-team/dump/lib/dump/reader';
19
+ import { resolveDatasetSnapshot } from '@terrafirmagreg-team/dump/lib/dump/snapshot';
28
20
 
29
21
  const typeRowsCache = createDatasetCache(
30
22
  async (
31
23
  dataset: DatasetRef,
32
- index: RecipeCompactIndex,
33
24
  typeId: string,
34
- ): Promise<RecipeCompactRow[]> => {
35
- const typeIndex = index.types.indexOf(typeId);
36
- if (typeIndex < 0) return [];
37
- const row = (await recipeTypeRows(dataset)).find(
38
- (entry) => entry.id === typeId,
39
- );
40
- if (!row?.files) return [];
41
- const layout = categoryLayout(index, typeId);
42
- const buckets = await Promise.all(
43
- Object.values(row.files).map(async (rel) => {
44
- if (!rel) return [];
45
- const bucket = await loadBucket(dataset, rel);
46
- return Object.entries(bucket).flatMap(([id, raw]) => {
47
- const parsed = rowFromBucketEntry(
48
- dataset,
49
- id,
50
- raw,
51
- typeIndex,
52
- rel,
53
- layout,
54
- );
55
- return parsed ? [parsed] : [];
56
- });
57
- }),
58
- );
59
- const rows = buckets
60
- .flat()
61
- .sort(
62
- (a, b) =>
63
- (a.o ?? Number.MAX_SAFE_INTEGER) - (b.o ?? Number.MAX_SAFE_INTEGER),
64
- );
65
- return rows;
66
- },
67
- (dataset, _index, typeId) => `${dataset.id}/${dataset.version ?? ''} ${typeId}`,
68
- );
69
-
70
- const bucketCache = createDatasetCache(
71
- async (dataset: DatasetRef, rel: string): Promise<Record<string, unknown>> => {
72
- const raw = await clientDumpJson(dataset, rel, 'high');
73
- return asRecord(raw) ?? {};
25
+ ): Promise<PreparedRecipeRow[]> => {
26
+ const type = (await recipeTypeRows(dataset)).find((entry) => entry.id === typeId);
27
+ if (!type) return [];
28
+ const document = await clientDumpJson(dataset, type.rows, 'high') as RecipeRowsDocument | undefined;
29
+ return (document?.rows ?? []).toSorted(comparePreparedRows);
74
30
  },
75
- (dataset, rel) => `${dataset.id}/${dataset.version ?? ''} ${rel}`,
31
+ (dataset, typeId) => datasetCacheKey(dataset, typeId),
76
32
  );
77
33
 
78
34
  export async function recipeTypeRows(
@@ -82,95 +38,40 @@ export async function recipeTypeRows(
82
38
  return manifest?.indexes.recipes.types ?? [];
83
39
  }
84
40
 
85
- const categoryLayoutCache = new WeakMap<
86
- RecipeCompactIndex,
87
- Map<string, DumpRecipeLayout>
88
- >();
89
-
90
- function categoryLayout(
91
- index: RecipeCompactIndex,
92
- typeId: string | undefined,
93
- ): DumpRecipeLayout | undefined {
94
- if (!typeId) return undefined;
95
- let map = categoryLayoutCache.get(index);
96
- if (!map) {
97
- map = new Map();
98
- for (const cat of index.categories ?? []) {
99
- if (cat.layout) map.set(cat.id, cat.layout);
100
- }
101
- categoryLayoutCache.set(index, map);
102
- }
103
- return map.get(typeId);
104
- }
105
-
106
- function slotRefIds(
107
- raw: unknown,
108
- role: 'input' | 'output',
109
- layout?: DumpRecipeLayout,
110
- ): string[] {
111
- const slots = asRecord(raw);
112
- if (!slots) return [];
113
- const boundary = outputBoundary(
114
- slots as Record<string, { type?: unknown; x?: unknown } | undefined>,
115
- layout,
116
- );
117
- const laid = layout
118
- ? new Map(layout.slots.map((slot) => [slot.id, slot]))
119
- : undefined;
120
- const out: string[] = [];
121
- for (const [slotId, slot] of Object.entries(slots)) {
122
- const row = asRecord(slot);
123
- const ref = asTaggedReference(row?.ref);
124
- if (!ref) continue;
125
- const slotType = asString(row?.type) ?? 'input';
126
- const x = asNumber(row?.x) ?? laid?.get(slotId)?.x;
127
- if (slotIoRole(slotType as RecipeSlotType, x, boundary) === role) {
128
- out.push(stackIdFromRef(ref));
129
- }
130
- }
131
- return out;
132
- }
133
-
134
- function rowFromBucketEntry(
41
+ function compactRow(
135
42
  dataset: DatasetRef,
136
- id: string,
137
- raw: unknown,
138
- typeIndex: number,
139
- rel: string,
140
- layout?: DumpRecipeLayout,
141
- ): RecipeCompactRow | undefined {
142
- const recipe = asRecord(raw);
143
- if (!recipe) return undefined;
144
- const w = asNumber(recipe.w);
145
- const h = asNumber(recipe.h);
146
- const image = asString(recipe.image);
147
- const order = asNumber(recipe.order);
43
+ index: RecipeCompactIndex,
44
+ row: PreparedRecipeRow,
45
+ ): RecipeCompactRow {
46
+ const typeIndex = index.types.indexOf(row.category);
148
47
  return {
149
- id,
150
- type: typeIndex,
151
- ...(order != null ? { o: order } : {}),
152
- in: slotRefIds(recipe.slots, 'input', layout),
153
- out: slotRefIds(recipe.slots, 'output', layout),
154
- bodyUrl: dumpRelPublicUrl(dataset, rel),
155
- ...(image ? { image } : {}),
156
- bucket: rel,
157
- ...(w != null && h != null ? { d: { w, h } } : {}),
48
+ id: row.id,
49
+ type: typeIndex < 0 ? 0 : typeIndex,
50
+ ...(typeIndex < 0 ? { cat: row.category } : {}),
51
+ ...(row.order != null ? { o: row.order } : {}),
52
+ in: row.inputs,
53
+ out: row.outputs,
54
+ bodyUrl: dumpRelPublicUrl(dataset, row.bucket),
55
+ ...(row.image ? { image: row.image } : {}),
56
+ bucket: row.bucket,
57
+ ...(row.w != null && row.h != null ? { d: { w: row.w, h: row.h } } : {}),
158
58
  };
159
59
  }
160
60
 
161
- function loadBucket(
162
- dataset: DatasetRef,
163
- rel: string,
164
- ): Promise<Record<string, unknown>> {
165
- return bucketCache(dataset, rel);
61
+ function comparePreparedRows(a: PreparedRecipeRow, b: PreparedRecipeRow): number {
62
+ return (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER)
63
+ || a.category.localeCompare(b.category)
64
+ || a.id.localeCompare(b.id);
166
65
  }
167
66
 
168
- export function loadTypeRows(
67
+ export async function loadTypeRows(
169
68
  dataset: DatasetRef,
170
69
  index: RecipeCompactIndex,
171
70
  typeId: string,
172
71
  ): Promise<RecipeCompactRow[]> {
173
- return typeRowsCache(dataset, index, typeId);
72
+ if (!index.types.includes(typeId)) return [];
73
+ dataset = await resolveDatasetSnapshot(dataset);
74
+ return (await typeRowsCache(dataset, typeId)).map((row) => compactRow(dataset, index, row));
174
75
  }
175
76
 
176
77
  export async function loadCategoryRecipes(
@@ -178,12 +79,14 @@ export async function loadCategoryRecipes(
178
79
  index: RecipeCompactIndex,
179
80
  typeId: string,
180
81
  ): Promise<Recipe[]> {
82
+ dataset = await resolveDatasetSnapshot(dataset);
181
83
  const rows = await loadTypeRows(dataset, index, typeId);
182
84
  const seen = new Set<string>();
183
85
  const recipes = await Promise.all(
184
86
  rows.map(async (row) => {
185
- if (seen.has(row.id)) return undefined;
186
- seen.add(row.id);
87
+ const key = `${row.cat ?? index.types[row.type]}|${row.id}`;
88
+ if (seen.has(key)) return undefined;
89
+ seen.add(key);
187
90
  const recipe = await loadClientRecipe(dataset, row.id, row.bucket);
188
91
  if (!recipe || recipe.type !== typeId) return undefined;
189
92
  return recipe;
@@ -200,62 +103,16 @@ export async function resolveRecipeRows(
200
103
  ids: Iterable<string>,
201
104
  opts?: { includeTagRows?: boolean },
202
105
  ): Promise<RecipeCompactRow[]> {
203
- const includeTagRows = opts?.includeTagRows ?? true;
204
- const wanted = new Set<string>();
205
- const byBucket = new Map<string, Set<string>>();
206
- for (const id of ids) {
207
- if (!id || wanted.has(id)) continue;
208
- wanted.add(id);
209
- const rels = await clientRecipeFileRels(dataset, id);
210
- for (const rel of rels) {
211
- const set = byBucket.get(rel);
212
- if (set) set.add(id);
213
- else byBucket.set(rel, new Set([id]));
214
- }
215
- }
216
- const out: RecipeCompactRow[] = [];
106
+ dataset = await resolveDatasetSnapshot(dataset);
107
+ const prepared = await clientPreparedRecipeRows(dataset, ids);
217
108
  const seen = new Set<string>();
218
- await Promise.all(
219
- [...byBucket.entries()].map(async ([rel, idsInBucket]) => {
220
- const bucket = await loadBucket(dataset, rel);
221
- for (const id of idsInBucket) {
222
- const raw = bucket[id];
223
- const category = asString(asRecord(raw)?.category);
224
- const typeIndex = category ? index.types.indexOf(category) : -1;
225
- if (!includeTagRows && category === TAG_RECIPE_TYPE) continue;
226
- const row = rowFromBucketEntry(
227
- dataset,
228
- id,
229
- raw,
230
- typeIndex < 0 ? 0 : typeIndex,
231
- rel,
232
- categoryLayout(index, category),
233
- );
234
- if (row && typeIndex < 0 && category) row.cat = category;
235
- if (row && !seen.has(row.id)) {
236
- seen.add(row.id);
237
- out.push(row);
238
- }
239
- }
240
- }),
241
- );
242
-
243
- const byBase = new Map<string, RecipeCompactRow>();
244
- for (const row of out) {
245
- const base = row.id.replace(/\/dup_\d+$/, '');
246
- const key = `${row.type}:${base}`;
247
- const prev = byBase.get(key);
248
- if (
249
- !prev ||
250
- (/\/dup_\d+$/.test(prev.id) && !/\/dup_\d+$/.test(row.id))
251
- ) {
252
- byBase.set(key, row);
253
- }
109
+ const rows: PreparedRecipeRow[] = [];
110
+ for (const row of prepared) {
111
+ if (opts?.includeTagRows === false && row.category === TAG_RECIPE_TYPE) continue;
112
+ const key = `${row.category}|${row.id}`;
113
+ if (seen.has(key)) continue;
114
+ seen.add(key);
115
+ rows.push(row);
254
116
  }
255
- const deduped = [...byBase.values()];
256
- deduped.sort(
257
- (a, b) => (a.o ?? Number.MAX_SAFE_INTEGER) - (b.o ?? Number.MAX_SAFE_INTEGER),
258
- );
259
- return deduped;
117
+ return rows.sort(comparePreparedRows).map((row) => compactRow(dataset, index, row));
260
118
  }
261
-
@@ -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 { useSyncExternalStore } from 'react';
5
5
  import type { RecipeCompactIndex } from '@terrafirmagreg-team/recipe/types';
@@ -8,7 +8,7 @@ const indexes = new Map<string, RecipeCompactIndex>();
8
8
  const listeners = new Set<() => void>();
9
9
 
10
10
  function refKey(dataset: DatasetRef) {
11
- return `${dataset.id}/${dataset.version ?? ''}`;
11
+ return datasetCacheKey(dataset);
12
12
  }
13
13
 
14
14
  function key(dataset: DatasetRef, lang: string) {
@@ -67,4 +67,3 @@ export function useRecipeIndexNames(
67
67
  () => null,
68
68
  );
69
69
  }
70
-
@@ -1,4 +1,4 @@
1
- import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
1
+ import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
2
2
  import { clientDumpLangNames } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
3
3
  import { loadClientKeybinds } from '@terrafirmagreg-team/dump/lib/dump/client/keybinds';
4
4
  import {
@@ -62,7 +62,7 @@ const tooltipsCache = createDatasetCache(
62
62
  lang: string,
63
63
  ): Promise<Record<string, string[]>> =>
64
64
  (await tooltipsApiCache(dataset, lang)).lines,
65
- (dataset, lang) => `${dataset.id}/${dataset.version ?? ''} ${lang}`,
65
+ (dataset, lang) => datasetCacheKey(dataset, lang),
66
66
  );
67
67
 
68
68
  export async function loadItemTooltips(
@@ -71,4 +71,3 @@ export async function loadItemTooltips(
71
71
  ): Promise<Record<string, string[]>> {
72
72
  return tooltipsCache(dataset, lang);
73
73
  }
74
-
package/src/lib/links.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { encodeQueryValue, withLang } from '@terrafirmagreg-team/translate/lib/url';
2
2
  import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
3
3
  import {
4
+ datasetUrlVersion,
4
5
  type DatasetRef,
5
6
  sectionUrl,
6
7
  } from '@terrafirmagreg-team/sites/location';
@@ -46,6 +47,10 @@ export function recipePlaceOpts(
46
47
  return place ? { tool: place.kind } : {};
47
48
  }
48
49
 
50
+ export function hrefVersion(dataset: DatasetRef): string | undefined {
51
+ return datasetUrlVersion(dataset);
52
+ }
53
+
49
54
  export function recipeHref(
50
55
  dataset: DatasetRef,
51
56
  lang: Lang | undefined,
@@ -67,7 +72,7 @@ export function recipeHref(
67
72
  'rpage',
68
73
  opts?.rpage && opts.rpage > 1 ? Math.floor(opts.rpage) : undefined,
69
74
  ],
70
- ['version', dataset.version],
75
+ ['version', opts?.version ?? hrefVersion(dataset)],
71
76
  ]);
72
77
  const base = recipeBasePath(dataset);
73
78
  const href = query ? `${base}?${query}` : base;
@@ -78,11 +83,12 @@ export function recipeCalcHref(
78
83
  dataset: DatasetRef,
79
84
  lang: Lang | undefined,
80
85
  tree?: string,
86
+ version?: string,
81
87
  ): string {
82
88
  const query = recipeQuery([
83
89
  ['tool', 'calc'],
84
90
  ['tree', tree],
85
- ['version', dataset.version],
91
+ ['version', version ?? hrefVersion(dataset)],
86
92
  ]);
87
93
  const href = `${recipeBasePath(dataset)}?${query}`;
88
94
  return lang ? withLang(href, lang) : href;
@@ -92,7 +98,7 @@ export function recipeStackHref(
92
98
  dataset: DatasetRef,
93
99
  lang: Lang,
94
100
  id: string,
95
- opts?: Pick<RecipeHrefOpts, 'tab' | 'search' | 'relation'> & {
101
+ opts?: Pick<RecipeHrefOpts, 'tab' | 'search' | 'relation' | 'version'> & {
96
102
  kind?: 'item' | 'fluid' | 'tag';
97
103
  tagKind?: string;
98
104
  },
@@ -101,6 +107,7 @@ export function recipeStackHref(
101
107
  tab: opts?.tab,
102
108
  search: opts?.search,
103
109
  relation: opts?.relation,
110
+ version: opts?.version,
104
111
  };
105
112
  if (opts?.kind === 'tag' || id.startsWith('#')) {
106
113
  const bare = id.startsWith('#') ? id.slice(1) : id;
@@ -0,0 +1,18 @@
1
+ import type { DumpCreativeTab } from '@terrafirmagreg-team/dump/lib/dump/data/tab/dto';
2
+ import type { RecipeCategory } from './index';
3
+
4
+ export type PreparedCatalog = {
5
+ items: string[];
6
+ fluids: string[];
7
+ usedIds: string[];
8
+ tabs: DumpCreativeTab[];
9
+ tabItems: Record<string, string[]>;
10
+ categories: RecipeCategory[];
11
+ groups: { id: string; members: string[] }[];
12
+ };
13
+
14
+ export type CatalogLabels = {
15
+ mods: Record<string, string>;
16
+ names: Record<string, string>;
17
+ groups: Record<string, string>;
18
+ };
@@ -26,6 +26,7 @@ export type RecipeHrefOpts = {
26
26
  type?: string;
27
27
  relation?: RecipeRelation;
28
28
  tool?: RecipeTool;
29
+ version?: string;
29
30
 
30
31
  unit?: 'mb' | 'ingot';
31
32