@terrafirmagreg-team/recipe 1.2.27 → 1.2.28
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 +5 -5
- package/src/components/cards/card/index.tsx +17 -13
- package/src/components/cards/scroll-card/index.tsx +5 -1
- package/src/components/mdx/recipe.tsx +2 -2
- package/src/components/tree.tsx +3 -2
- package/src/components/views/browser/card-grid.tsx +4 -5
- package/src/components/views/browser/item-panel/index.tsx +27 -22
- package/src/components/views/browser/item-panel-grid/cell.tsx +6 -0
- package/src/components/views/browser/item-panel-grid/index.tsx +3 -0
- package/src/components/views/landing.tsx +39 -11
- package/src/hooks/use-index.ts +10 -0
- package/src/hooks/use-panel-page.ts +8 -50
- package/src/hooks/use-session.ts +36 -3
- package/src/lib/client/recipe.ts +2 -2
- package/src/lib/client-index/chrome.ts +4 -4
- package/src/lib/client-index/tooltips.ts +2 -2
- package/src/lib/og.ts +39 -7
- package/src/lib/preview.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/recipe",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Recipe viewer and calculator",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@terrafirmagreg-team/data": "^1.2.13",
|
|
27
|
-
"@terrafirmagreg-team/dump": "^1.2.
|
|
28
|
-
"@terrafirmagreg-team/game": "^1.2.
|
|
29
|
-
"@terrafirmagreg-team/kit": "^1.2.
|
|
27
|
+
"@terrafirmagreg-team/dump": "^1.2.21",
|
|
28
|
+
"@terrafirmagreg-team/game": "^1.2.12",
|
|
29
|
+
"@terrafirmagreg-team/kit": "^1.2.29",
|
|
30
30
|
"@terrafirmagreg-team/mdx": "^1.2.12",
|
|
31
31
|
"@terrafirmagreg-team/preview": "^1.2.7",
|
|
32
32
|
"@terrafirmagreg-team/sites": "^1.2.4",
|
|
33
33
|
"@terrafirmagreg-team/translate": "^1.2.13",
|
|
34
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
34
|
+
"@terrafirmagreg-team/ui": "^1.2.20",
|
|
35
35
|
"@types/pathfinding": "^0.1.0",
|
|
36
36
|
"comlink": "^4.4.2",
|
|
37
37
|
"fflate": "0.8.3",
|
|
@@ -106,19 +106,23 @@ export function RecipeCard({
|
|
|
106
106
|
ref={rootRef}
|
|
107
107
|
className="relative w-fit overflow-hidden rounded-sm bg-mc-panel"
|
|
108
108
|
>
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
{src ? (
|
|
110
|
+
<>
|
|
111
|
+
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
112
|
+
<img
|
|
113
|
+
src={src}
|
|
114
|
+
alt={title}
|
|
115
|
+
className="block"
|
|
116
|
+
width={naturalW}
|
|
117
|
+
height={naturalH}
|
|
118
|
+
loading="lazy"
|
|
119
|
+
decoding="async"
|
|
120
|
+
draggable={false}
|
|
121
|
+
onError={onFail}
|
|
122
|
+
style={recipeGlareFilter}
|
|
123
|
+
/>
|
|
124
|
+
</>
|
|
125
|
+
) : null}
|
|
122
126
|
{inView && interactive && glbUrl ? (
|
|
123
127
|
<div
|
|
124
128
|
className="absolute"
|
|
@@ -328,7 +328,11 @@ export function ScrollCard(props: Props) {
|
|
|
328
328
|
top: horizontal ? y : shifted,
|
|
329
329
|
fontSize: 8 * scale,
|
|
330
330
|
color: `#${rgb.toString(16).padStart(6, '0')}`,
|
|
331
|
-
|
|
331
|
+
...(shadowRgb !== rgb
|
|
332
|
+
? {
|
|
333
|
+
textShadow: `${scale}px ${scale}px 0 #${shadowRgb.toString(16).padStart(6, '0')}`,
|
|
334
|
+
}
|
|
335
|
+
: {}),
|
|
332
336
|
}}
|
|
333
337
|
>
|
|
334
338
|
<McText text={el.text ?? ''} surface="dark" />
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
resolveRecipeRows,
|
|
20
20
|
} from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
21
21
|
import { loadClientRecipe } from '@terrafirmagreg-team/recipe/lib/client/recipe';
|
|
22
|
-
import {
|
|
22
|
+
import { clientDumpLangRecipe } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
23
23
|
import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
|
|
24
24
|
import { recipeImageUrl } from '@terrafirmagreg-team/dump/lib/dump/assets/urls';
|
|
25
25
|
import { recipeCardImageUrl, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
@@ -54,7 +54,7 @@ export function Recipe({
|
|
|
54
54
|
const [recipe, chrome, langMap] = await Promise.all([
|
|
55
55
|
loadClientRecipe(dataset, row.id, row.bucket),
|
|
56
56
|
loadRecipeChromeClient(dataset, lang),
|
|
57
|
-
|
|
57
|
+
clientDumpLangRecipe(dataset, lang),
|
|
58
58
|
]);
|
|
59
59
|
const title = recipe
|
|
60
60
|
? recipeTitle(recipe, langMap)
|
package/src/components/tree.tsx
CHANGED
|
@@ -3,7 +3,8 @@ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
|
3
3
|
import { createElement } from 'react';
|
|
4
4
|
import type * as PageTree from 'fumadocs-core/page-tree';
|
|
5
5
|
import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
6
|
-
import {
|
|
6
|
+
import { creativeTabName } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/load';
|
|
7
|
+
import { clientDumpLangNames } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
7
8
|
import { DUMP_POINTER_TTL } from '@terrafirmagreg-team/dump/lib/dump/json-reader';
|
|
8
9
|
import { createAsyncCache } from '@terrafirmagreg-team/data/lib/async-cache';
|
|
9
10
|
import { getRecipeSource } from '@terrafirmagreg-team/recipe/lib/source';
|
|
@@ -70,7 +71,7 @@ async function buildRecipeTrees(lang: Lang): Promise<SectionTrees> {
|
|
|
70
71
|
for (const { id, title: datasetTitle, languages } of datasets) {
|
|
71
72
|
if (!(languages ?? [defaultLanguage]).includes(lang)) continue;
|
|
72
73
|
const ref = { id };
|
|
73
|
-
const map = await
|
|
74
|
+
const map = await clientDumpLangNames(ref, lang);
|
|
74
75
|
const source = getRecipeSource();
|
|
75
76
|
const categories = await source.categories(ref);
|
|
76
77
|
const types = (await source.manifest(ref))?.indexes.recipes.types;
|
|
@@ -10,7 +10,6 @@ import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-m
|
|
|
10
10
|
import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
|
|
11
11
|
import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
|
|
12
12
|
import {
|
|
13
|
-
recipeCardImageUrl,
|
|
14
13
|
recipeHref,
|
|
15
14
|
recipeImageUrl,
|
|
16
15
|
} from '@terrafirmagreg-team/recipe/lib/links';
|
|
@@ -86,8 +85,8 @@ function RecipeGridCard({
|
|
|
86
85
|
modId: row.id.split(':', 1)[0],
|
|
87
86
|
image: row.image,
|
|
88
87
|
})
|
|
89
|
-
: undefined)
|
|
90
|
-
|
|
88
|
+
: undefined);
|
|
89
|
+
const expectsImage = recipe?.image !== undefined || row.image !== undefined;
|
|
91
90
|
|
|
92
91
|
const focus = () =>
|
|
93
92
|
pushUrlState(
|
|
@@ -159,7 +158,7 @@ function RecipeGridCard({
|
|
|
159
158
|
style={fit < 1 ? { zoom: fit } : undefined}
|
|
160
159
|
>
|
|
161
160
|
{recipe ? (
|
|
162
|
-
src && !failed ? (
|
|
161
|
+
!expectsImage || (src && !failed) ? (
|
|
163
162
|
<PagedCard
|
|
164
163
|
recipe={recipe}
|
|
165
164
|
dataset={dataset}
|
|
@@ -167,7 +166,7 @@ function RecipeGridCard({
|
|
|
167
166
|
langMap={langMap}
|
|
168
167
|
nav={nav}
|
|
169
168
|
title={title}
|
|
170
|
-
src={src}
|
|
169
|
+
src={src ?? ''}
|
|
171
170
|
naturalW={row.d?.w}
|
|
172
171
|
naturalH={row.d?.h}
|
|
173
172
|
maxH={maxH}
|
|
@@ -95,7 +95,7 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
95
95
|
const [expandedGroups, setExpandedGroups] = useState<ReadonlySet<string>>(
|
|
96
96
|
new Set(),
|
|
97
97
|
);
|
|
98
|
-
const { cells,
|
|
98
|
+
const { cells, favoriteIds, dIndex, dNames, dLang } =
|
|
99
99
|
usePanelCells({
|
|
100
100
|
dataset,
|
|
101
101
|
index,
|
|
@@ -112,10 +112,7 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
112
112
|
const { page: panelPage, setPage: setPanelPage } = usePanelPage(dataset);
|
|
113
113
|
const list = usePagedList(cells, panelPage, pageSize);
|
|
114
114
|
|
|
115
|
-
const gridResetKey =
|
|
116
|
-
() => [mode, filtered, favorites.entries],
|
|
117
|
-
[mode, filtered, favorites.entries],
|
|
118
|
-
);
|
|
115
|
+
const gridResetKey = mode;
|
|
119
116
|
const onToggleGroup = useCallback((groupId: string) => {
|
|
120
117
|
setExpandedGroups((prev) => {
|
|
121
118
|
const next = new Set(prev);
|
|
@@ -165,7 +162,13 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
165
162
|
pageRef.current = list.page;
|
|
166
163
|
const [startRaw, setStartRaw] = useState(list.page - (PAGE_WINDOW >> 1));
|
|
167
164
|
const maxStart = Math.max(0, list.pages - PAGE_WINDOW);
|
|
168
|
-
const start = Math.max(
|
|
165
|
+
const start = Math.max(
|
|
166
|
+
0,
|
|
167
|
+
Math.min(
|
|
168
|
+
maxStart,
|
|
169
|
+
Math.max(list.page - (PAGE_WINDOW - 1), Math.min(startRaw, list.page)),
|
|
170
|
+
),
|
|
171
|
+
);
|
|
169
172
|
const windowPages = useMemo(() => {
|
|
170
173
|
const end = Math.min(list.pages, start + PAGE_WINDOW);
|
|
171
174
|
const out: number[] = [];
|
|
@@ -178,12 +181,7 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
178
181
|
[cells, windowPages, pageSize],
|
|
179
182
|
);
|
|
180
183
|
|
|
181
|
-
|
|
182
|
-
if (list.page < start || list.page > start + PAGE_WINDOW - 1) {
|
|
183
|
-
setStartRaw(list.page - (PAGE_WINDOW >> 1));
|
|
184
|
-
}
|
|
185
|
-
}, [list.page, start]);
|
|
186
|
-
|
|
184
|
+
const didInitScroll = useRef(false);
|
|
187
185
|
useLayoutEffect(() => {
|
|
188
186
|
const el = stripRef.current;
|
|
189
187
|
if (!el || w <= 0) return;
|
|
@@ -191,13 +189,18 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
191
189
|
if (Math.abs(el.scrollLeft - target) > 2) {
|
|
192
190
|
el.scrollTo({
|
|
193
191
|
left: target,
|
|
194
|
-
behavior:
|
|
192
|
+
behavior:
|
|
193
|
+
fromScroll.current || !didInitScroll.current
|
|
194
|
+
? 'instant'
|
|
195
|
+
: 'smooth',
|
|
195
196
|
});
|
|
196
197
|
}
|
|
198
|
+
didInitScroll.current = true;
|
|
197
199
|
fromScroll.current = false;
|
|
198
|
-
}, [list.page,
|
|
200
|
+
}, [list.page, w]);
|
|
199
201
|
|
|
200
202
|
const idle = useRef<number | undefined>(undefined);
|
|
203
|
+
const [scrolling, setScrolling] = useState(false);
|
|
201
204
|
useEffect(() => () => window.clearTimeout(idle.current), []);
|
|
202
205
|
|
|
203
206
|
const onStripScroll = (event: UIEvent<HTMLDivElement>) => {
|
|
@@ -207,15 +210,16 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
207
210
|
0,
|
|
208
211
|
Math.min(list.pages - 1, Math.round(el.scrollLeft / w)),
|
|
209
212
|
);
|
|
210
|
-
|
|
211
|
-
fromScroll.current = true;
|
|
212
|
-
setPanelPage(next);
|
|
213
|
-
}
|
|
213
|
+
setScrolling(true);
|
|
214
214
|
window.clearTimeout(idle.current);
|
|
215
|
-
idle.current = window.setTimeout(
|
|
216
|
-
()
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
idle.current = window.setTimeout(() => {
|
|
216
|
+
setScrolling(false);
|
|
217
|
+
if (next !== pageRef.current) {
|
|
218
|
+
fromScroll.current = true;
|
|
219
|
+
setPanelPage(next);
|
|
220
|
+
}
|
|
221
|
+
setStartRaw(pageRef.current - (PAGE_WINDOW >> 1));
|
|
222
|
+
}, 160);
|
|
219
223
|
};
|
|
220
224
|
|
|
221
225
|
const tabOptions = usePanelTabs(dIndex, dNames, dLang);
|
|
@@ -278,6 +282,7 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
278
282
|
onHover={onHover}
|
|
279
283
|
onToggleGroup={onToggleGroup}
|
|
280
284
|
draggableStacks={isCalc}
|
|
285
|
+
tooltip={!scrolling}
|
|
281
286
|
/>
|
|
282
287
|
</div>
|
|
283
288
|
))}
|
|
@@ -27,6 +27,7 @@ function PanelChip({
|
|
|
27
27
|
names,
|
|
28
28
|
lang,
|
|
29
29
|
favIds,
|
|
30
|
+
tooltip,
|
|
30
31
|
}: {
|
|
31
32
|
id: string;
|
|
32
33
|
size: EntrySize;
|
|
@@ -36,11 +37,13 @@ function PanelChip({
|
|
|
36
37
|
names: Record<string, Record<string, string>>;
|
|
37
38
|
lang: Lang;
|
|
38
39
|
favIds?: ReadonlySet<string>;
|
|
40
|
+
tooltip?: boolean;
|
|
39
41
|
}) {
|
|
40
42
|
return (
|
|
41
43
|
<Entry
|
|
42
44
|
id={id}
|
|
43
45
|
kind={kind}
|
|
46
|
+
tooltip={tooltip === false ? false : undefined}
|
|
44
47
|
name={recipeItemName(names, lang, id)}
|
|
45
48
|
size={size}
|
|
46
49
|
variant="chip"
|
|
@@ -68,6 +71,7 @@ export const PanelCell = memo(function PanelCell({
|
|
|
68
71
|
favIds,
|
|
69
72
|
expandLabel,
|
|
70
73
|
draggableStacks,
|
|
74
|
+
tooltip,
|
|
71
75
|
onPress,
|
|
72
76
|
onHover,
|
|
73
77
|
onToggleGroup,
|
|
@@ -80,6 +84,7 @@ export const PanelCell = memo(function PanelCell({
|
|
|
80
84
|
favIds?: ReadonlySet<string>;
|
|
81
85
|
expandLabel: string;
|
|
82
86
|
draggableStacks?: boolean;
|
|
87
|
+
tooltip?: boolean;
|
|
83
88
|
onPress: (id: string, ref?: 'item' | 'fluid') => void;
|
|
84
89
|
onHover?: (target: FavoriteHoverTarget | undefined) => void;
|
|
85
90
|
onToggleGroup?: (id: string) => void;
|
|
@@ -168,6 +173,7 @@ export const PanelCell = memo(function PanelCell({
|
|
|
168
173
|
names={names}
|
|
169
174
|
lang={lang}
|
|
170
175
|
favIds={favIds}
|
|
176
|
+
tooltip={tooltip}
|
|
171
177
|
/>
|
|
172
178
|
</button>
|
|
173
179
|
</CopyIdMenu>
|
|
@@ -27,6 +27,7 @@ export const ItemPanelGrid = memo(function ItemPanelGrid({
|
|
|
27
27
|
onHover,
|
|
28
28
|
onToggleGroup,
|
|
29
29
|
draggableStacks,
|
|
30
|
+
tooltip,
|
|
30
31
|
}: {
|
|
31
32
|
cells: ItemPanelCell[];
|
|
32
33
|
|
|
@@ -42,6 +43,7 @@ export const ItemPanelGrid = memo(function ItemPanelGrid({
|
|
|
42
43
|
onHover?: (target: FavoriteHoverTarget | undefined) => void;
|
|
43
44
|
onToggleGroup?: (id: string) => void;
|
|
44
45
|
draggableStacks?: boolean;
|
|
46
|
+
tooltip?: boolean;
|
|
45
47
|
}) {
|
|
46
48
|
const t = useTranslations();
|
|
47
49
|
const expandLabel = t('Expand', { note: 'recipe.expand' });
|
|
@@ -75,6 +77,7 @@ export const ItemPanelGrid = memo(function ItemPanelGrid({
|
|
|
75
77
|
favIds={favIds}
|
|
76
78
|
expandLabel={expandLabel}
|
|
77
79
|
draggableStacks={draggableStacks}
|
|
80
|
+
tooltip={tooltip}
|
|
78
81
|
onPress={onPress}
|
|
79
82
|
onHover={onHover}
|
|
80
83
|
onToggleGroup={onToggleGroup}
|
|
@@ -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
|
-
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
};
|
package/src/hooks/use-index.ts
CHANGED
|
@@ -74,6 +74,16 @@ export function useRecipeIndex(dataset: DatasetRef | undefined, lang: string) {
|
|
|
74
74
|
|
|
75
75
|
useAsyncEffect(async (isCancelled) => {
|
|
76
76
|
if (!dataset || warmKey !== key) return;
|
|
77
|
+
const conn = (
|
|
78
|
+
navigator as Navigator & {
|
|
79
|
+
connection?: { effectiveType?: string; saveData?: boolean };
|
|
80
|
+
}
|
|
81
|
+
).connection;
|
|
82
|
+
if (
|
|
83
|
+
conn?.saveData ||
|
|
84
|
+
(conn?.effectiveType && conn.effectiveType !== '4g')
|
|
85
|
+
)
|
|
86
|
+
return;
|
|
77
87
|
for (const entry of locales.filter((item) => item !== lang)) {
|
|
78
88
|
await idle();
|
|
79
89
|
if (isCancelled()) return;
|
|
@@ -1,54 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
3
3
|
|
|
4
|
-
import { useCallback } from 'react';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!raw) return {};
|
|
13
|
-
try {
|
|
14
|
-
const parsed: unknown = JSON.parse(raw);
|
|
15
|
-
if (!parsed || typeof parsed !== 'object') return {};
|
|
16
|
-
const out: Record<string, number> = {};
|
|
17
|
-
for (const [key, value] of Object.entries(
|
|
18
|
-
parsed as Record<string, unknown>,
|
|
19
|
-
)) {
|
|
20
|
-
const page = Math.floor(Number(value));
|
|
21
|
-
if (Number.isFinite(page) && page > 0) out[key] = page;
|
|
22
|
-
}
|
|
23
|
-
return out;
|
|
24
|
-
} catch {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
write: (value) => JSON.stringify(value),
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const useStoredPanelPages = createStoredValue(
|
|
32
|
-
'wiki.recipe.panelPage',
|
|
33
|
-
codec,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export function usePanelPage(dataset: DatasetRef) {
|
|
37
|
-
const [pages, setPages] = useStoredPanelPages();
|
|
38
|
-
const refKey = `${dataset.id}/${dataset.version ?? ''}`;
|
|
39
|
-
const setPage = useCallback(
|
|
40
|
-
(page: number) => {
|
|
41
|
-
setPages((prev) => {
|
|
42
|
-
const next = page > 0 ? page : 0;
|
|
43
|
-
if ((prev[refKey] ?? 0) === next) return prev;
|
|
44
|
-
const copy = { ...prev };
|
|
45
|
-
if (next > 0) copy[refKey] = next;
|
|
46
|
-
else delete copy[refKey];
|
|
47
|
-
return copy;
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
[refKey, setPages],
|
|
51
|
-
);
|
|
52
|
-
return { page: pages[refKey] ?? 0, setPage };
|
|
4
|
+
import { useCallback, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
export function usePanelPage(_dataset: DatasetRef) {
|
|
7
|
+
const [page, setPageState] = useState(0);
|
|
8
|
+
const setPage = useCallback((next: number) => {
|
|
9
|
+
setPageState(Math.max(0, Math.floor(next)));
|
|
10
|
+
}, []);
|
|
11
|
+
return { page, setPage };
|
|
53
12
|
}
|
|
54
|
-
|
package/src/hooks/use-session.ts
CHANGED
|
@@ -6,7 +6,10 @@ import { useRecipeIndex } from '@terrafirmagreg-team/recipe/hooks/use-index';
|
|
|
6
6
|
import { useRecipeQuery } from '@terrafirmagreg-team/recipe/hooks/use-query';
|
|
7
7
|
import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
8
8
|
import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
clientDumpLangNames,
|
|
11
|
+
clientDumpLangRecipe,
|
|
12
|
+
} from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
10
13
|
import { useRecipeIndexNames } from '@terrafirmagreg-team/recipe/lib/client-index/store';
|
|
11
14
|
import {
|
|
12
15
|
RECIPE_ALL_TYPE,
|
|
@@ -21,6 +24,32 @@ import type {
|
|
|
21
24
|
RecipeSession,
|
|
22
25
|
} from '@terrafirmagreg-team/recipe/types';
|
|
23
26
|
|
|
27
|
+
let langMapMemo:
|
|
28
|
+
| {
|
|
29
|
+
names: Record<string, Record<string, string>>;
|
|
30
|
+
langRaw: Record<string, string> | undefined;
|
|
31
|
+
lang: string;
|
|
32
|
+
map: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
| undefined;
|
|
35
|
+
|
|
36
|
+
function mergeLangMap(
|
|
37
|
+
names: Record<string, Record<string, string>>,
|
|
38
|
+
langRaw: Record<string, string> | undefined,
|
|
39
|
+
lang: string,
|
|
40
|
+
): Record<string, string> {
|
|
41
|
+
if (
|
|
42
|
+
langMapMemo?.names === names &&
|
|
43
|
+
langMapMemo.langRaw === langRaw &&
|
|
44
|
+
langMapMemo.lang === lang
|
|
45
|
+
) {
|
|
46
|
+
return langMapMemo.map;
|
|
47
|
+
}
|
|
48
|
+
const map = { ...names.en_us, ...langRaw, ...names[lang] };
|
|
49
|
+
langMapMemo = { names, langRaw, lang, map };
|
|
50
|
+
return map;
|
|
51
|
+
}
|
|
52
|
+
|
|
24
53
|
export function useRecipeSession(page: RecipePageData): RecipeSession {
|
|
25
54
|
const { dataset: id, lang } = page;
|
|
26
55
|
const dataset =
|
|
@@ -35,11 +64,15 @@ export function useRecipeSession(page: RecipePageData): RecipeSession {
|
|
|
35
64
|
[indexNames, index],
|
|
36
65
|
);
|
|
37
66
|
const langRaw = useAsyncValue(
|
|
38
|
-
() =>
|
|
67
|
+
() =>
|
|
68
|
+
Promise.all([
|
|
69
|
+
clientDumpLangNames(dataset, lang),
|
|
70
|
+
clientDumpLangRecipe(dataset, lang),
|
|
71
|
+
]).then(([names, recipe]) => ({ ...names, ...recipe })),
|
|
39
72
|
[dataset, lang],
|
|
40
73
|
);
|
|
41
74
|
const langMap = useMemo(
|
|
42
|
-
() => (
|
|
75
|
+
() => mergeLangMap(names, langRaw, lang),
|
|
43
76
|
[langRaw, names, lang],
|
|
44
77
|
);
|
|
45
78
|
const used = useMemo(() => recipeUsedItems(index), [index]);
|
package/src/lib/client/recipe.ts
CHANGED
|
@@ -15,7 +15,7 @@ const recipeIndex = createDatasetCache(async (dataset: DatasetRef, ns: string) =
|
|
|
15
15
|
const listed = manifest?.namespaces[ns];
|
|
16
16
|
if (!listed || !listed.registry.includes('recipes')) return undefined;
|
|
17
17
|
return asRecord(
|
|
18
|
-
await clientDumpJson(dataset, 'registry/recipes.
|
|
18
|
+
await clientDumpJson(dataset, 'registry/recipes.ndjson', 'high'),
|
|
19
19
|
) as Record<string, string | string[]> | undefined;
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -43,7 +43,7 @@ export async function clientRecipeFileRels(
|
|
|
43
43
|
: category,
|
|
44
44
|
)
|
|
45
45
|
.filter((path) => !!path)
|
|
46
|
-
.map((path) => `data/${ns}/recipes/${path}.
|
|
46
|
+
.map((path) => `data/${ns}/recipes/${path}.ndjson`);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async function clientRecipeFileRel(
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
RecipeStackGroup,
|
|
6
6
|
} from '@terrafirmagreg-team/recipe/types';
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
clientDumpLangNames,
|
|
9
9
|
clientDumpNames,
|
|
10
10
|
loadClientManifest,
|
|
11
11
|
} from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
@@ -47,7 +47,7 @@ async function clientNamedCategories(
|
|
|
47
47
|
types: string[],
|
|
48
48
|
categories: RecipeCategory[],
|
|
49
49
|
): Promise<Record<string, string>> {
|
|
50
|
-
const map = await
|
|
50
|
+
const map = await clientDumpLangNames(dataset, lang);
|
|
51
51
|
const byId = new Map(categories.map((row) => [row.id, row]));
|
|
52
52
|
const names: Record<string, string> = {};
|
|
53
53
|
for (const id of types) {
|
|
@@ -67,7 +67,7 @@ async function clientRecipeGroups(
|
|
|
67
67
|
): Promise<RecipeStackGroup[]> {
|
|
68
68
|
const rows = await loadClientRegistryGroups(dataset);
|
|
69
69
|
if (!rows.length) return [];
|
|
70
|
-
const map = await
|
|
70
|
+
const map = await clientDumpLangNames(dataset, lang);
|
|
71
71
|
return rows.map((row) => ({
|
|
72
72
|
id: row.id,
|
|
73
73
|
...(row.name ? { name: dumpTextString(map, row.name) } : {}),
|
|
@@ -93,7 +93,7 @@ const loadChrome = createDatasetCache(
|
|
|
93
93
|
clientRecipeGroups(dataset, lang),
|
|
94
94
|
loadClientModNames(dataset, lang),
|
|
95
95
|
clientNamedCategories(dataset, lang, types, categories),
|
|
96
|
-
|
|
96
|
+
clientDumpLangNames(dataset, lang).then((map) => {
|
|
97
97
|
const names: Record<string, string> = {};
|
|
98
98
|
for (const tab of tabs) {
|
|
99
99
|
names[tab.id] = creativeTabName(map, tab.display.name ?? tab.id);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
|
-
import {
|
|
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 {
|
|
5
5
|
loadClientRegistryTooltips,
|
|
@@ -20,7 +20,7 @@ const tooltipsApiCache = createDatasetCache(
|
|
|
20
20
|
}> => {
|
|
21
21
|
const kinds = ['item', 'block', 'fluid', 'entity'] as const;
|
|
22
22
|
const [map, keybinds, shards, modShards] = await Promise.all([
|
|
23
|
-
|
|
23
|
+
clientDumpLangNames(dataset, lang),
|
|
24
24
|
loadClientKeybinds(dataset),
|
|
25
25
|
Promise.all(
|
|
26
26
|
kinds.map((kind) => loadClientRegistryTooltips(dataset, kind)),
|
package/src/lib/og.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
2
|
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
3
|
-
import {
|
|
3
|
+
import { clientDumpLangNames } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
4
4
|
import { loadClientTagMembers } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
|
|
5
5
|
import { stripMcFormat } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
6
6
|
import {
|
|
7
|
+
ogIconParam,
|
|
7
8
|
ogLocalized,
|
|
9
|
+
ogStackIcon,
|
|
8
10
|
ogStackName,
|
|
9
11
|
} from '@terrafirmagreg-team/dump/lib/dump/assets/og';
|
|
10
12
|
import {
|
|
11
13
|
ogImageQuery,
|
|
12
14
|
ogName,
|
|
15
|
+
registerOgIconResolver,
|
|
13
16
|
registerOgResolver,
|
|
14
17
|
type OgContext,
|
|
15
18
|
} from '@terrafirmagreg-team/preview/lib';
|
|
@@ -24,7 +27,12 @@ async function recipeOgContext(
|
|
|
24
27
|
): Promise<OgContext> {
|
|
25
28
|
const tool = search.get('tool');
|
|
26
29
|
if (tool) {
|
|
27
|
-
const
|
|
30
|
+
const glyph = TOOL_GLYPH[tool];
|
|
31
|
+
const entity = {
|
|
32
|
+
kind: 'tool',
|
|
33
|
+
name: recipeToolName(tool, lang),
|
|
34
|
+
...(glyph ? { icon: `glyph:${glyph}` } : {}),
|
|
35
|
+
};
|
|
28
36
|
return { entity, imageQuery: ogImageQuery(entity, tool) };
|
|
29
37
|
}
|
|
30
38
|
const item = search.get('item');
|
|
@@ -36,6 +44,7 @@ async function recipeOgContext(
|
|
|
36
44
|
kind,
|
|
37
45
|
name: await ogStackName(dataset, id, kind, lang),
|
|
38
46
|
id,
|
|
47
|
+
icon: `${kind}:${id}`,
|
|
39
48
|
};
|
|
40
49
|
return {
|
|
41
50
|
entity,
|
|
@@ -54,7 +63,12 @@ async function recipeOgContext(
|
|
|
54
63
|
const tagId = rest.length ? `${ns}:${tagPath}` : ns;
|
|
55
64
|
const members = await loadClientTagMembers(dataset, tagKind);
|
|
56
65
|
const list = tagId ? members?.[`#${tagId}`] : undefined;
|
|
57
|
-
const entity = {
|
|
66
|
+
const entity = {
|
|
67
|
+
kind: 'tag',
|
|
68
|
+
name: `#${tagId || id}`,
|
|
69
|
+
id,
|
|
70
|
+
icon: `${tagKind}Tag:#${tagId || id}`,
|
|
71
|
+
};
|
|
58
72
|
const description =
|
|
59
73
|
list != null
|
|
60
74
|
? `${list.length} member${list.length === 1 ? '' : 's'}`
|
|
@@ -67,7 +81,7 @@ async function recipeOgContext(
|
|
|
67
81
|
const out = recipe.outputs[0];
|
|
68
82
|
const [categories, map] = await Promise.all([
|
|
69
83
|
loadDatasetRecipeCategories(dataset),
|
|
70
|
-
|
|
84
|
+
clientDumpLangNames(dataset, lang),
|
|
71
85
|
]);
|
|
72
86
|
const category = categories.find((row) => row.id === recipe.type);
|
|
73
87
|
const catName = category
|
|
@@ -83,20 +97,31 @@ async function recipeOgContext(
|
|
|
83
97
|
lang,
|
|
84
98
|
).catch(() => recipe.id)
|
|
85
99
|
: recipe.id;
|
|
86
|
-
const entity = {
|
|
100
|
+
const entity = {
|
|
101
|
+
kind: 'recipe',
|
|
102
|
+
name,
|
|
103
|
+
id: recipe.id,
|
|
104
|
+
...(out ? { icon: `${out.kind === 'fluid' ? 'fluid' : 'item'}:${out.id}` } : {}),
|
|
105
|
+
};
|
|
87
106
|
const description = catName ?? recipe.id;
|
|
88
107
|
return { entity, description, imageQuery: ogImageQuery(entity, description) };
|
|
89
108
|
}
|
|
90
109
|
if (!type || type === 'all') return {};
|
|
91
110
|
const [categories, map] = await Promise.all([
|
|
92
111
|
loadDatasetRecipeCategories(dataset),
|
|
93
|
-
|
|
112
|
+
clientDumpLangNames(dataset, lang),
|
|
94
113
|
]);
|
|
95
114
|
const category = categories.find((row) => row.id === type);
|
|
96
115
|
if (!category) return {};
|
|
97
116
|
const localized =
|
|
98
117
|
ogLocalized(map, category.display?.name) ?? category.id;
|
|
99
|
-
const
|
|
118
|
+
const icon = ogIconParam(category.icon);
|
|
119
|
+
const entity = {
|
|
120
|
+
kind: 'category',
|
|
121
|
+
...ogName(localized),
|
|
122
|
+
id: category.id,
|
|
123
|
+
...(icon ? { icon } : {}),
|
|
124
|
+
};
|
|
100
125
|
return {
|
|
101
126
|
entity,
|
|
102
127
|
description: category.id,
|
|
@@ -104,4 +129,11 @@ async function recipeOgContext(
|
|
|
104
129
|
};
|
|
105
130
|
}
|
|
106
131
|
|
|
132
|
+
const TOOL_GLYPH: Record<string, string> = {
|
|
133
|
+
calc: 'calculator',
|
|
134
|
+
forge: 'anvil',
|
|
135
|
+
alloy: 'flask',
|
|
136
|
+
};
|
|
137
|
+
|
|
107
138
|
registerOgResolver('recipe', recipeOgContext);
|
|
139
|
+
registerOgIconResolver(ogStackIcon);
|
package/src/lib/preview.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerPreviewResolver } from '@terrafirmagreg-team/preview/lib';
|
|
2
|
-
import {
|
|
2
|
+
import { clientDumpLangNames } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
3
3
|
import { loadDatasetRecipeCategories } from '@terrafirmagreg-team/recipe/lib/data/category/load';
|
|
4
4
|
import { langString } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
5
5
|
import { entryPreviewIcon } from '@terrafirmagreg-team/game/lib/preview';
|
|
@@ -28,5 +28,5 @@ export async function recipeLinkPreview({
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
registerPreviewResolver('recipe', recipeLinkPreview, { langMap:
|
|
31
|
+
registerPreviewResolver('recipe', recipeLinkPreview, { langMap: clientDumpLangNames });
|
|
32
32
|
|