@terrafirmagreg-team/recipe 1.2.28 → 1.2.30
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.
- package/package.json +11 -11
- package/src/components/cards/slot-hitbox.tsx +22 -4
- package/src/components/tree.tsx +4 -4
- package/src/components/views/alloy/list.tsx +1 -0
- package/src/components/views/browser/axis-switcher.tsx +6 -7
- package/src/components/views/browser/card-grid.tsx +10 -2
- package/src/components/views/browser/index.tsx +23 -9
- package/src/components/views/browser/item-panel/index.tsx +125 -75
- package/src/components/views/browser/item-panel-grid/cell.tsx +0 -6
- package/src/components/views/browser/item-panel-grid/index.tsx +10 -5
- package/src/components/views/browser/item-view/tags.tsx +2 -0
- package/src/components/views/browser/type-view.tsx +5 -4
- package/src/components/views/calc/calculator/index.tsx +2 -0
- package/src/components/views/calc/sidebar.tsx +4 -1
- package/src/components/views/forge/list.tsx +1 -0
- package/src/hooks/alloy/use-fluid-colors.ts +2 -3
- package/src/hooks/alloy/use-mix-state.ts +2 -0
- package/src/hooks/calc/use-actions.ts +6 -4
- package/src/hooks/calc/use-data.ts +1 -0
- package/src/hooks/calc/use-share.ts +6 -4
- package/src/hooks/use-add-to-calc.ts +3 -2
- package/src/hooks/use-index.ts +19 -8
- package/src/hooks/use-item-press.ts +1 -3
- package/src/hooks/use-mount-limit.ts +9 -3
- package/src/hooks/use-panel-warmup.ts +129 -0
- package/src/hooks/use-query.ts +8 -2
- package/src/hooks/use-session.ts +11 -4
- package/src/lib/browser/fluid-outputs.ts +2 -3
- package/src/lib/calc/storage/entry.ts +1 -1
- package/src/lib/calc/storage/keys.ts +2 -2
- package/src/lib/cards/model.ts +5 -1
- package/src/lib/client/recipe.ts +23 -29
- package/src/lib/client-index/catalog.ts +2 -3
- package/src/lib/client-index/chrome.test.ts +87 -0
- package/src/lib/client-index/chrome.ts +27 -134
- package/src/lib/client-index/prepared-catalog.ts +80 -0
- package/src/lib/client-index/registry.ts +3 -4
- package/src/lib/client-index/rows.test.ts +127 -0
- package/src/lib/client-index/rows.ts +51 -194
- package/src/lib/client-index/store.ts +2 -3
- package/src/lib/client-index/tooltips.ts +2 -3
- package/src/lib/links.ts +10 -3
- package/src/types/catalog.ts +18 -0
- package/src/types/index.ts +1 -0
|
@@ -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
|
|
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
|
|
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 =
|
|
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={
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import type
|
|
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) =>
|
|
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(
|
|
@@ -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))}${
|
|
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
|
}
|
|
@@ -32,7 +32,7 @@ export function useAddToCalc(session: RecipeSession) {
|
|
|
32
32
|
: [
|
|
33
33
|
...state.cards,
|
|
34
34
|
{
|
|
35
|
-
id: `c${
|
|
35
|
+
id: `c${crypto.randomUUID()}`,
|
|
36
36
|
materialId: item,
|
|
37
37
|
kind,
|
|
38
38
|
recipeId: null,
|
|
@@ -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
|
|
package/src/hooks/use-index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import type
|
|
2
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
3
3
|
|
|
4
4
|
import { startTransition, useMemo, useState } from 'react';
|
|
5
5
|
import { useLang } from '@terrafirmagreg-team/translate/provider';
|
|
@@ -37,17 +37,29 @@ export function useRecipeIndex(dataset: DatasetRef | undefined, lang: string) {
|
|
|
37
37
|
() => items?.map((item) => item.locale) ?? [lang],
|
|
38
38
|
[items, lang],
|
|
39
39
|
);
|
|
40
|
-
const key =
|
|
40
|
+
const key = dataset ? datasetCacheKey(dataset, lang) : '';
|
|
41
41
|
|
|
42
42
|
useAsyncEffect(async (isCancelled) => {
|
|
43
43
|
if (!dataset) return;
|
|
44
|
-
const skeleton = await loadRecipeSkeletonIndex(dataset)
|
|
45
|
-
|
|
44
|
+
const skeleton = await loadRecipeSkeletonIndex(dataset).catch(
|
|
45
|
+
() => undefined,
|
|
46
|
+
);
|
|
47
|
+
if (!skeleton || isCancelled()) {
|
|
48
|
+
if (!isCancelled()) setComplete(key);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
46
51
|
setLoaded({ key, index: skeleton });
|
|
47
52
|
publishRecipeIndex(dataset, lang, skeleton);
|
|
48
|
-
const chrome = await loadRecipeChromeClient(dataset, lang)
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
const chrome = await loadRecipeChromeClient(dataset, lang).catch(
|
|
54
|
+
() => undefined,
|
|
55
|
+
);
|
|
56
|
+
const index = chrome
|
|
57
|
+
? await loadRecipeCompactIndex(dataset, chrome).catch(() => undefined)
|
|
58
|
+
: undefined;
|
|
59
|
+
if (!chrome || !index || isCancelled()) {
|
|
60
|
+
if (!isCancelled()) setComplete(key);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
51
63
|
startTransition(() => {
|
|
52
64
|
setLoaded({ key, index });
|
|
53
65
|
setComplete(key);
|
|
@@ -100,4 +112,3 @@ export function useRecipeIndex(dataset: DatasetRef | undefined, lang: string) {
|
|
|
100
112
|
const index = active?.items.length ? active : (lastFull ?? active);
|
|
101
113
|
return { index, indexLoading: complete !== key };
|
|
102
114
|
}
|
|
103
|
-
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
|
-
export function useMountLimit(
|
|
6
|
-
|
|
5
|
+
export function useMountLimit(
|
|
6
|
+
length: number,
|
|
7
|
+
resetKey: unknown,
|
|
8
|
+
eager = false,
|
|
9
|
+
): number {
|
|
10
|
+
const [limit, setLimit] = useState(() => (eager ? length : 40));
|
|
7
11
|
const [lastKey, setLastKey] = useState(resetKey);
|
|
8
12
|
if (lastKey !== resetKey) {
|
|
9
13
|
setLastKey(resetKey);
|
|
10
|
-
setLimit(40);
|
|
14
|
+
setLimit(eager ? length : 40);
|
|
15
|
+
} else if (eager && limit < length) {
|
|
16
|
+
setLimit(length);
|
|
11
17
|
}
|
|
12
18
|
useEffect(() => {
|
|
13
19
|
if (limit >= length) return;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
3
|
+
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { parseStackId } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
|
|
6
|
+
import { loadClientModAtlases } from '@terrafirmagreg-team/dump/lib/dump/client/atlases';
|
|
7
|
+
import {
|
|
8
|
+
atlasPagePublicUrl,
|
|
9
|
+
lookupSpriteInBundle,
|
|
10
|
+
} from '@terrafirmagreg-team/dump/lib/dump/assets/atlas/lookup';
|
|
11
|
+
import type {
|
|
12
|
+
AtlasBundle,
|
|
13
|
+
SpriteQuery,
|
|
14
|
+
} from '@terrafirmagreg-team/dump/lib/dump/assets/atlas/dto';
|
|
15
|
+
import { loadStackDisplay } from '@terrafirmagreg-team/game/lib/entry/tooltip';
|
|
16
|
+
import type { ItemPanelCell } from '@terrafirmagreg-team/recipe/types';
|
|
17
|
+
|
|
18
|
+
const BATCH = 160;
|
|
19
|
+
const MAX_PAGES_CACHE = 6;
|
|
20
|
+
|
|
21
|
+
const prefetched = new Map<string, Set<string>>();
|
|
22
|
+
|
|
23
|
+
function idleStep(step: () => void) {
|
|
24
|
+
if (typeof requestIdleCallback === 'function') {
|
|
25
|
+
requestIdleCallback(step, { timeout: 900 });
|
|
26
|
+
} else {
|
|
27
|
+
window.setTimeout(step, 32);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function stackQuery(id: string, kind: SpriteQuery['kind']): SpriteQuery {
|
|
32
|
+
const parsed = parseStackId(id);
|
|
33
|
+
return {
|
|
34
|
+
id: parsed.id,
|
|
35
|
+
kind,
|
|
36
|
+
...(parsed.nbt !== undefined ? { tag: parsed.nbt } : {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function cellQueries(cell: ItemPanelCell): SpriteQuery[] {
|
|
41
|
+
switch (cell.kind) {
|
|
42
|
+
case 'stack':
|
|
43
|
+
return [stackQuery(cell.id, cell.ref === 'fluid' ? 'fluid' : 'item')];
|
|
44
|
+
case 'group':
|
|
45
|
+
return cell.members.map((id) => stackQuery(id, 'item'));
|
|
46
|
+
case 'recipe': {
|
|
47
|
+
const icon = cell.fav.icon;
|
|
48
|
+
return icon ? [stackQuery(icon, 'item')] : [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function warmCells(
|
|
54
|
+
dataset: DatasetRef,
|
|
55
|
+
cells: ItemPanelCell[],
|
|
56
|
+
seen: Set<string>,
|
|
57
|
+
) {
|
|
58
|
+
const bundles = new Map<string, AtlasBundle | null>();
|
|
59
|
+
for (const cell of cells) {
|
|
60
|
+
for (const query of cellQueries(cell)) {
|
|
61
|
+
const spriteId = query.id;
|
|
62
|
+
if (!spriteId || spriteId.startsWith('#')) continue;
|
|
63
|
+
const ns = spriteId.includes(':')
|
|
64
|
+
? spriteId.slice(0, spriteId.indexOf(':'))
|
|
65
|
+
: '';
|
|
66
|
+
if (!ns) continue;
|
|
67
|
+
let bundle = bundles.get(ns);
|
|
68
|
+
if (bundle === undefined) {
|
|
69
|
+
bundle = await loadClientModAtlases(dataset, ns);
|
|
70
|
+
bundles.set(ns, bundle);
|
|
71
|
+
}
|
|
72
|
+
const hit = lookupSpriteInBundle(bundle, query);
|
|
73
|
+
const url = hit
|
|
74
|
+
? atlasPagePublicUrl(dataset, hit.atlas, hit.page)
|
|
75
|
+
: undefined;
|
|
76
|
+
if (url && !seen.has(url)) {
|
|
77
|
+
seen.add(url);
|
|
78
|
+
const img = new Image();
|
|
79
|
+
img.decoding = 'async';
|
|
80
|
+
img.src = url;
|
|
81
|
+
}
|
|
82
|
+
void loadStackDisplay(dataset, spriteId, query.kind).catch(() => {});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function usePanelWarmup(
|
|
88
|
+
dataset: DatasetRef,
|
|
89
|
+
cells: ItemPanelCell[],
|
|
90
|
+
page: number,
|
|
91
|
+
pageSize: number,
|
|
92
|
+
) {
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!cells.length || pageSize <= 0) return;
|
|
95
|
+
const key = datasetCacheKey(dataset);
|
|
96
|
+
let seen = prefetched.get(key);
|
|
97
|
+
if (!seen) {
|
|
98
|
+
if (prefetched.size >= MAX_PAGES_CACHE) {
|
|
99
|
+
prefetched.delete(prefetched.keys().next().value!);
|
|
100
|
+
}
|
|
101
|
+
seen = new Set();
|
|
102
|
+
prefetched.set(key, seen);
|
|
103
|
+
}
|
|
104
|
+
let cancelled = false;
|
|
105
|
+
const order = cells.map((_, i) => i);
|
|
106
|
+
order.sort(
|
|
107
|
+
(a, b) =>
|
|
108
|
+
Math.abs(Math.floor(a / pageSize) - page) -
|
|
109
|
+
Math.abs(Math.floor(b / pageSize) - page),
|
|
110
|
+
);
|
|
111
|
+
let cursor = 0;
|
|
112
|
+
const step = () => {
|
|
113
|
+
if (cancelled) return;
|
|
114
|
+
const batch = order.slice(cursor, cursor + BATCH);
|
|
115
|
+
cursor += BATCH;
|
|
116
|
+
void warmCells(
|
|
117
|
+
dataset,
|
|
118
|
+
batch.map((i) => cells[i]!),
|
|
119
|
+
seen,
|
|
120
|
+
).then(() => {
|
|
121
|
+
if (!cancelled && cursor < order.length) idleStep(step);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
step();
|
|
125
|
+
return () => {
|
|
126
|
+
cancelled = true;
|
|
127
|
+
};
|
|
128
|
+
}, [dataset, cells, page, pageSize]);
|
|
129
|
+
}
|
package/src/hooks/use-query.ts
CHANGED
|
@@ -25,7 +25,7 @@ function urlRelation(
|
|
|
25
25
|
return value === 'uses' || value === 'tags' ? value : undefined;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function useRecipeQuery(dataset: DatasetRef) {
|
|
28
|
+
export function useRecipeQuery(dataset: DatasetRef, version?: string) {
|
|
29
29
|
const params = useLocationSearchParams();
|
|
30
30
|
const resolved = useResolvedLang();
|
|
31
31
|
|
|
@@ -80,13 +80,14 @@ export function useRecipeQuery(dataset: DatasetRef) {
|
|
|
80
80
|
if (!stray) return;
|
|
81
81
|
replaceUrlState(
|
|
82
82
|
isCalc
|
|
83
|
-
? recipeCalcHref(dataset, resolved, tree || undefined)
|
|
83
|
+
? recipeCalcHref(dataset, resolved, tree || undefined, version)
|
|
84
84
|
: recipeHref(dataset, resolved, {
|
|
85
85
|
tool: place.kind,
|
|
86
86
|
id: recipeId,
|
|
87
87
|
unit: alloyUnit,
|
|
88
88
|
mix: alloyMix,
|
|
89
89
|
tab,
|
|
90
|
+
version,
|
|
90
91
|
}),
|
|
91
92
|
);
|
|
92
93
|
}, [
|
|
@@ -95,6 +96,7 @@ export function useRecipeQuery(dataset: DatasetRef) {
|
|
|
95
96
|
place.kind,
|
|
96
97
|
resolved,
|
|
97
98
|
dataset,
|
|
99
|
+
version,
|
|
98
100
|
params,
|
|
99
101
|
tree,
|
|
100
102
|
recipeId,
|
|
@@ -117,6 +119,7 @@ export function useRecipeQuery(dataset: DatasetRef) {
|
|
|
117
119
|
tab,
|
|
118
120
|
search: searchParam || undefined,
|
|
119
121
|
rpage: rpageValue + 1,
|
|
122
|
+
version,
|
|
120
123
|
}),
|
|
121
124
|
);
|
|
122
125
|
}
|
|
@@ -124,6 +127,7 @@ export function useRecipeQuery(dataset: DatasetRef) {
|
|
|
124
127
|
isTool,
|
|
125
128
|
resolved,
|
|
126
129
|
dataset,
|
|
130
|
+
version,
|
|
127
131
|
params,
|
|
128
132
|
rawItem,
|
|
129
133
|
rawFluid,
|
|
@@ -151,12 +155,14 @@ export function useRecipeQuery(dataset: DatasetRef) {
|
|
|
151
155
|
tab,
|
|
152
156
|
search: searchParam || undefined,
|
|
153
157
|
rpage: rpageValue + 1,
|
|
158
|
+
version,
|
|
154
159
|
}),
|
|
155
160
|
);
|
|
156
161
|
}, [
|
|
157
162
|
isTool,
|
|
158
163
|
resolved,
|
|
159
164
|
dataset,
|
|
165
|
+
version,
|
|
160
166
|
params,
|
|
161
167
|
rawItem,
|
|
162
168
|
rawFluid,
|
package/src/hooks/use-session.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useMemo } from 'react';
|
|
4
4
|
import { useVersionedDataset } from '@terrafirmagreg-team/kit/hooks/use-versioned-dataset';
|
|
5
|
+
import { useActiveDatasetSnapshot } from '@terrafirmagreg-team/kit/hooks/use-dataset-snapshot';
|
|
5
6
|
import { useRecipeIndex } from '@terrafirmagreg-team/recipe/hooks/use-index';
|
|
6
7
|
import { useRecipeQuery } from '@terrafirmagreg-team/recipe/hooks/use-query';
|
|
7
8
|
import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
@@ -52,9 +53,14 @@ function mergeLangMap(
|
|
|
52
53
|
|
|
53
54
|
export function useRecipeSession(page: RecipePageData): RecipeSession {
|
|
54
55
|
const { dataset: id, lang } = page;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const
|
|
56
|
+
const selection = useVersionedDataset(id.id, { versions: page.versions });
|
|
57
|
+
const active = useActiveDatasetSnapshot(selection);
|
|
58
|
+
const snapshot = id.revision ? id : active ?? selection ?? id;
|
|
59
|
+
const dataset = useMemo(
|
|
60
|
+
() => ({ ...snapshot, pin: selection?.version }),
|
|
61
|
+
[snapshot, selection?.version],
|
|
62
|
+
);
|
|
63
|
+
const query = useRecipeQuery(dataset, selection?.version);
|
|
58
64
|
const { index, indexLoading } = useRecipeIndex(dataset, lang);
|
|
59
65
|
const placeOpts = recipePlaceOpts(query.place);
|
|
60
66
|
|
|
@@ -88,6 +94,7 @@ export function useRecipeSession(page: RecipePageData): RecipeSession {
|
|
|
88
94
|
relation: query.relation,
|
|
89
95
|
search: query.query || undefined,
|
|
90
96
|
rpage: query.rpage + 1,
|
|
97
|
+
version: selection?.version,
|
|
91
98
|
}),
|
|
92
99
|
[
|
|
93
100
|
navType,
|
|
@@ -99,6 +106,7 @@ export function useRecipeSession(page: RecipePageData): RecipeSession {
|
|
|
99
106
|
query.relation,
|
|
100
107
|
query.query,
|
|
101
108
|
query.rpage,
|
|
109
|
+
selection?.version,
|
|
102
110
|
],
|
|
103
111
|
);
|
|
104
112
|
|
|
@@ -137,4 +145,3 @@ export function useRecipeSession(page: RecipePageData): RecipeSession {
|
|
|
137
145
|
used,
|
|
138
146
|
};
|
|
139
147
|
}
|
|
140
|
-
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { datasetCacheKey, type DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
2
|
import type { RecipeCompactIndex } from '@terrafirmagreg-team/recipe/types';
|
|
3
3
|
import { outputBoundary } from '@terrafirmagreg-team/recipe/lib/data/slot-io';
|
|
4
4
|
import { loadTypeRows } from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
@@ -11,7 +11,7 @@ export type FluidIoIndex = {
|
|
|
11
11
|
|
|
12
12
|
const cache = createDatasetCache(
|
|
13
13
|
build,
|
|
14
|
-
(dataset) =>
|
|
14
|
+
(dataset) => datasetCacheKey(dataset),
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
function tankCategories(index: RecipeCompactIndex, role: 'input' | 'output') {
|
|
@@ -67,4 +67,3 @@ export function loadFluidIoIndex(
|
|
|
67
67
|
): Promise<FluidIoIndex> {
|
|
68
68
|
return cache(dataset, index);
|
|
69
69
|
}
|
|
70
|
-
|
|
@@ -16,7 +16,7 @@ export const EMPTY_ENTRIES: CalcTreeEntry[] = [];
|
|
|
16
16
|
|
|
17
17
|
export function newCalcEntry(state: CalculatorState, name?: string): CalcTreeEntry {
|
|
18
18
|
return {
|
|
19
|
-
id:
|
|
19
|
+
id: crypto.randomUUID(),
|
|
20
20
|
name,
|
|
21
21
|
savedAt: Date.now(),
|
|
22
22
|
state,
|
|
@@ -11,11 +11,11 @@ function calcTabId(): string {
|
|
|
11
11
|
try {
|
|
12
12
|
tabId = window.sessionStorage.getItem(TAB_KEY);
|
|
13
13
|
if (!tabId) {
|
|
14
|
-
tabId =
|
|
14
|
+
tabId = crypto.randomUUID();
|
|
15
15
|
window.sessionStorage.setItem(TAB_KEY, tabId);
|
|
16
16
|
}
|
|
17
17
|
} catch {
|
|
18
|
-
tabId ??= `tab-${
|
|
18
|
+
tabId ??= `tab-${crypto.randomUUID()}`;
|
|
19
19
|
}
|
|
20
20
|
return tabId;
|
|
21
21
|
}
|
package/src/lib/cards/model.ts
CHANGED
|
@@ -72,7 +72,11 @@ export function countCoveredText(
|
|
|
72
72
|
return slots.some(
|
|
73
73
|
(slot) =>
|
|
74
74
|
slot.count !== undefined &&
|
|
75
|
-
scales.some(
|
|
75
|
+
scales.some(
|
|
76
|
+
(scale) =>
|
|
77
|
+
Math.abs(num * scale - slot.count!) <=
|
|
78
|
+
Math.max(1, num * scale * 0.01),
|
|
79
|
+
) &&
|
|
76
80
|
widget.x + widget.w > slot.x &&
|
|
77
81
|
widget.x < slot.x + slot.w,
|
|
78
82
|
);
|