@terrafirmagreg-team/recipe 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +62 -3
- package/src/components/button-copy.tsx +43 -0
- package/src/components/cards/card/index.tsx +214 -0
- package/src/components/cards/card/scene.tsx +107 -0
- package/src/components/cards/card/strip.tsx +198 -0
- package/src/components/cards/card/text.tsx +46 -0
- package/src/components/cards/card/tips.tsx +63 -0
- package/src/components/cards/default-item.tsx +47 -0
- package/src/components/cards/glare-filter.tsx +29 -0
- package/src/components/cards/paged-card.tsx +222 -0
- package/src/components/cards/slot-hitbox.tsx +213 -0
- package/src/components/cards/strip-card/buttons.tsx +106 -0
- package/src/components/cards/strip-card/index.tsx +214 -0
- package/src/components/cards/strip-card/member-cell.tsx +167 -0
- package/src/components/cards/strip-card/sprite.tsx +36 -0
- package/src/components/embed-card.tsx +44 -0
- package/src/components/mdx/recipe.tsx +129 -0
- package/src/components/tool-list.tsx +49 -0
- package/src/components/tree.tsx +98 -0
- package/src/components/views/alloy/index.tsx +112 -0
- package/src/components/views/alloy/list.tsx +85 -0
- package/src/components/views/alloy/mix/index.tsx +35 -0
- package/src/components/views/alloy/mix/ratio.tsx +94 -0
- package/src/components/views/alloy/mix/rows.tsx +145 -0
- package/src/components/views/alloy/mix/status.tsx +122 -0
- package/src/components/views/alloy/mix/total.tsx +132 -0
- package/src/components/views/alloy/range-bar.tsx +65 -0
- package/src/components/views/alloy/stack-bar.tsx +88 -0
- package/src/components/views/browser/axis-switcher.tsx +54 -0
- package/src/components/views/browser/card-grid.tsx +275 -0
- package/src/components/views/browser/favorite-button.tsx +46 -0
- package/src/components/views/browser/frame.tsx +112 -0
- package/src/components/views/browser/index.tsx +114 -0
- package/src/components/views/browser/item-panel/index.tsx +229 -0
- package/src/components/views/browser/item-panel/skeleton.tsx +26 -0
- package/src/components/views/browser/item-panel-grid/cell.tsx +178 -0
- package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +129 -0
- package/src/components/views/browser/item-panel-grid/index.tsx +105 -0
- package/src/components/views/browser/item-view/index.tsx +186 -0
- package/src/components/views/browser/item-view/tags.tsx +85 -0
- package/src/components/views/browser/item-view-header.tsx +131 -0
- package/src/components/views/browser/pane-tabs.tsx +61 -0
- package/src/components/views/browser/place-header.tsx +72 -0
- package/src/components/views/browser/query-controls.tsx +105 -0
- package/src/components/views/browser/recipe-item-header.tsx +60 -0
- package/src/components/views/browser/settings.tsx +52 -0
- package/src/components/views/browser/toolbar.tsx +54 -0
- package/src/components/views/browser/type-tabs.tsx +71 -0
- package/src/components/views/browser/type-view.tsx +184 -0
- package/src/components/views/browser/workstation-rail.tsx +43 -0
- package/src/components/views/calc/calculator/actions.tsx +47 -0
- package/src/components/views/calc/calculator/help.tsx +189 -0
- package/src/components/views/calc/calculator/index.tsx +172 -0
- package/src/components/views/calc/dot-overlay.tsx +80 -0
- package/src/components/views/calc/edge.tsx +152 -0
- package/src/components/views/calc/flow/index.tsx +305 -0
- package/src/components/views/calc/flow/picker-dialogs.tsx +146 -0
- package/src/components/views/calc/flow/toolbar.tsx +60 -0
- package/src/components/views/calc/flow/view-menu.tsx +117 -0
- package/src/components/views/calc/member-picker.tsx +120 -0
- package/src/components/views/calc/node-card/actions.tsx +90 -0
- package/src/components/views/calc/node-card/badges.tsx +59 -0
- package/src/components/views/calc/node-card/chips.tsx +187 -0
- package/src/components/views/calc/node-card/far.tsx +123 -0
- package/src/components/views/calc/node-card/full.tsx +332 -0
- package/src/components/views/calc/node-card/index.tsx +27 -0
- package/src/components/views/calc/node-card/menu.tsx +282 -0
- package/src/components/views/calc/node-card/port-cells.tsx +186 -0
- package/src/components/views/calc/node-card/port-rails.tsx +251 -0
- package/src/components/views/calc/node-card/ports.tsx +86 -0
- package/src/components/views/calc/recipe-picker/body.tsx +207 -0
- package/src/components/views/calc/recipe-picker/footer.tsx +131 -0
- package/src/components/views/calc/recipe-picker/index.tsx +52 -0
- package/src/components/views/calc/sidebar.tsx +171 -0
- package/src/components/views/calc/trees/icon-picker.tsx +97 -0
- package/src/components/views/calc/trees/index.tsx +134 -0
- package/src/components/views/calc/trees/label.tsx +67 -0
- package/src/components/views/calc/trees/rows.tsx +140 -0
- package/src/components/views/forge/gui.tsx +131 -0
- package/src/components/views/forge/index.tsx +112 -0
- package/src/components/views/forge/list.tsx +113 -0
- package/src/components/views/forge/workbench/controls.tsx +103 -0
- package/src/components/views/forge/workbench/index.tsx +85 -0
- package/src/components/views/forge/workbench/panel.tsx +228 -0
- package/src/components/views/forge/workbench/ruler.tsx +133 -0
- package/src/components/views/forge/workbench/status.tsx +55 -0
- package/src/components/views/forge/workbench/tape.tsx +70 -0
- package/src/hooks/alloy/use-fluid-colors.ts +125 -0
- package/src/hooks/alloy/use-mix-state.ts +240 -0
- package/src/hooks/calc/flow/use-engage.ts +129 -0
- package/src/hooks/calc/flow/use-handlers.ts +192 -0
- package/src/hooks/calc/flow/use-layout.ts +105 -0
- package/src/hooks/calc/flow/use-mount.ts +97 -0
- package/src/hooks/calc/flow/use-nodes.ts +260 -0
- package/src/hooks/calc/flow/use-pickers.ts +57 -0
- package/src/hooks/calc/flow/use-viewport.ts +141 -0
- package/src/hooks/calc/flow/use-window.ts +87 -0
- package/src/hooks/calc/use-actions.ts +355 -0
- package/src/hooks/calc/use-amounts.ts +64 -0
- package/src/hooks/calc/use-data.ts +203 -0
- package/src/hooks/calc/use-defaults.ts +40 -0
- package/src/hooks/calc/use-far-mode.ts +37 -0
- package/src/hooks/calc/use-focus.ts +31 -0
- package/src/hooks/calc/use-maps.ts +76 -0
- package/src/hooks/calc/use-reset.ts +15 -0
- package/src/hooks/calc/use-resolver.ts +70 -0
- package/src/hooks/calc/use-session.ts +13 -0
- package/src/hooks/calc/use-share.ts +64 -0
- package/src/hooks/calc/use-storage.ts +126 -0
- package/src/hooks/calc/use-tier.ts +13 -0
- package/src/hooks/calc/use-view-mode.ts +24 -0
- package/src/hooks/calc/use-worker.ts +204 -0
- package/src/hooks/forge/use-anvil-gui.ts +16 -0
- package/src/hooks/forge/use-forge-state.ts +135 -0
- package/src/hooks/forge/use-ruler.ts +100 -0
- package/src/hooks/use-add-to-calc.ts +51 -0
- package/src/hooks/use-categories-by-id.ts +18 -0
- package/src/hooks/use-favorite-hotkey.ts +39 -0
- package/src/hooks/use-favorites.ts +135 -0
- package/src/hooks/use-group-outlines.ts +65 -0
- package/src/hooks/use-hide-unused.ts +12 -0
- package/src/hooks/use-index.ts +72 -0
- package/src/hooks/use-item-feeds.ts +46 -0
- package/src/hooks/use-item-pane.ts +106 -0
- package/src/hooks/use-item-press.ts +89 -0
- package/src/hooks/use-item-tag-groups.ts +54 -0
- package/src/hooks/use-item-tooltips.ts +18 -0
- package/src/hooks/use-left-sidebar-tree.ts +34 -0
- package/src/hooks/use-mod-names.ts +17 -0
- package/src/hooks/use-mount-limit.ts +22 -0
- package/src/hooks/use-panel-cells.ts +117 -0
- package/src/hooks/use-panel-page.ts +54 -0
- package/src/hooks/use-panel-tabs.ts +43 -0
- package/src/hooks/use-query.ts +186 -0
- package/src/hooks/use-session.ts +88 -0
- package/src/hooks/use-sidebar-group.ts +16 -0
- package/src/hooks/use-tag-members.ts +16 -0
- package/src/hooks/use-tool-recipes.ts +26 -0
- package/src/hooks/use-type-filter.ts +73 -0
- package/src/lib/alloy/mix.ts +210 -0
- package/src/lib/alloy/parse.ts +37 -0
- package/src/lib/calc/defaults.ts +47 -0
- package/src/lib/calc/flow.ts +315 -0
- package/src/lib/calc/focus.ts +15 -0
- package/src/lib/calc/meta.ts +17 -0
- package/src/lib/calc/pack.ts +77 -0
- package/src/lib/calc/ports.ts +43 -0
- package/src/lib/calc/resolve.ts +198 -0
- package/src/lib/calc/route/buckets.ts +49 -0
- package/src/lib/calc/route/geometry.ts +51 -0
- package/src/lib/calc/route/index.ts +3 -0
- package/src/lib/calc/route/polyline.ts +103 -0
- package/src/lib/calc/route/router.ts +394 -0
- package/src/lib/calc/scheme.ts +226 -0
- package/src/lib/calc/storage/entry.ts +97 -0
- package/src/lib/calc/storage/index.ts +20 -0
- package/src/lib/calc/storage/keys.ts +38 -0
- package/src/lib/calc/storage/store.ts +198 -0
- package/src/lib/calc/tree/index.ts +4 -0
- package/src/lib/calc/tree/materials.ts +29 -0
- package/src/lib/calc/tree/recipe.ts +104 -0
- package/src/lib/calc/tree/share.ts +135 -0
- package/src/lib/calc/worker/api.ts +25 -0
- package/src/lib/calc/worker/fetch.ts +66 -0
- package/src/lib/calc/worker/flush.ts +39 -0
- package/src/lib/calc/worker/index.ts +8 -0
- package/src/lib/calc/worker/protocol.ts +35 -0
- package/src/lib/calc/worker/resolve.ts +49 -0
- package/src/lib/calc/worker/state.ts +48 -0
- package/src/lib/card-model.ts +65 -0
- package/src/lib/client/recipe-categories.ts +14 -0
- package/src/lib/client/recipe.ts +85 -0
- package/src/lib/client-index/catalog.ts +91 -0
- package/src/lib/client-index/chrome.ts +180 -0
- package/src/lib/client-index/index.ts +20 -0
- package/src/lib/client-index/registry.ts +121 -0
- package/src/lib/client-index/rows.ts +260 -0
- package/src/lib/client-index/tooltips.ts +74 -0
- package/src/lib/config.ts +18 -0
- package/src/lib/data/category/dto.ts +25 -0
- package/src/lib/data/category/load.ts +47 -0
- package/src/lib/data/category/parse.ts +71 -0
- package/src/lib/data/dto.ts +152 -0
- package/src/lib/data/grid.ts +40 -0
- package/src/lib/data/parse/entry.ts +85 -0
- package/src/lib/data/parse/index.ts +3 -0
- package/src/lib/data/parse/layout.ts +138 -0
- package/src/lib/data/parse/slots.ts +85 -0
- package/src/lib/data/parse/widgets.ts +81 -0
- package/src/lib/data/scene.ts +103 -0
- package/src/lib/data/slot-io.ts +44 -0
- package/src/lib/dump.ts +6 -0
- package/src/lib/embed.ts +22 -0
- package/src/lib/favorite-hover.ts +13 -0
- package/src/lib/fluid-outputs.ts +70 -0
- package/src/lib/forge/actions.ts +59 -0
- package/src/lib/forge/data.ts +51 -0
- package/src/lib/forge/solve.ts +80 -0
- package/src/lib/group.ts +23 -0
- package/src/lib/index-store.ts +70 -0
- package/src/lib/links.ts +131 -0
- package/src/lib/lookup.ts +119 -0
- package/src/lib/panel-outline.ts +86 -0
- package/src/lib/panel.ts +105 -0
- package/src/lib/preview.ts +32 -0
- package/src/lib/recipe-slots.ts +8 -0
- package/src/lib/search.ts +139 -0
- package/src/lib/sidebar.ts +47 -0
- package/src/lib/used-items.ts +25 -0
- package/src/locales/en_us.json +172 -0
- package/src/locales/ru_ru.json +172 -0
- package/src/locales.ts +6 -0
- package/src/types/alloy.ts +20 -0
- package/src/types/calc-flow-props.ts +44 -0
- package/src/types/calc.ts +92 -0
- package/src/types/forge.ts +21 -0
- package/src/types/index.ts +136 -0
- package/styles/calc.css +308 -0
- package/styles/strip.css +7 -0
- package/styles.css +2 -0
- package/README.md +0 -3
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState, type ReactNode, type RefObject } from 'react';
|
|
4
|
+
import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
5
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
|
+
import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
|
|
7
|
+
import { RecipeDefaultMenuItem } from '@terrafirmagreg-team/recipe/components/cards/default-item';
|
|
8
|
+
import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
|
|
9
|
+
import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
|
|
10
|
+
import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
|
|
11
|
+
import {
|
|
12
|
+
recipeCardImageUrl,
|
|
13
|
+
recipeHref,
|
|
14
|
+
recipeImageUrl,
|
|
15
|
+
} from '@terrafirmagreg-team/recipe/lib/links';
|
|
16
|
+
import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
17
|
+
import { loadClientRecipe } from '@terrafirmagreg-team/recipe/lib/client/recipe';
|
|
18
|
+
import { pushUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
|
|
19
|
+
import { useSwipe } from '@terrafirmagreg-team/ui/hooks/use-swipe';
|
|
20
|
+
import { favoriteHover } from '@terrafirmagreg-team/recipe/lib/favorite-hover';
|
|
21
|
+
import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
|
|
22
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
23
|
+
import type { FitDim } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
|
|
24
|
+
import type {
|
|
25
|
+
RecipeCategory,
|
|
26
|
+
RecipeCompactIndex,
|
|
27
|
+
RecipeCompactRow,
|
|
28
|
+
RecipeSession,
|
|
29
|
+
} from '@terrafirmagreg-team/recipe/types';
|
|
30
|
+
|
|
31
|
+
const FALLBACK_DIM: FitDim = { w: 320, h: 80 };
|
|
32
|
+
|
|
33
|
+
export function recipeCardDim(
|
|
34
|
+
index: RecipeCompactIndex | null,
|
|
35
|
+
categoriesById: Map<string, RecipeCategory>,
|
|
36
|
+
row: RecipeCompactRow,
|
|
37
|
+
): FitDim {
|
|
38
|
+
if (row.d) return { w: row.d.w, h: row.d.h };
|
|
39
|
+
const typeId = index?.types[row.type];
|
|
40
|
+
const layout = typeId ? categoriesById.get(typeId)?.layout : undefined;
|
|
41
|
+
if (!layout) return FALLBACK_DIM;
|
|
42
|
+
const scale = layout.scale ?? 2;
|
|
43
|
+
const margin = layout.margin ?? 0;
|
|
44
|
+
return {
|
|
45
|
+
w: (layout.w + margin * 2) * scale,
|
|
46
|
+
h: (layout.h + margin * 2) * scale,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function RecipeGridCard({
|
|
51
|
+
row,
|
|
52
|
+
session,
|
|
53
|
+
focused,
|
|
54
|
+
maxH,
|
|
55
|
+
maxW,
|
|
56
|
+
onPick,
|
|
57
|
+
menuExtra,
|
|
58
|
+
defaultMaterial,
|
|
59
|
+
}: {
|
|
60
|
+
row: RecipeCompactRow;
|
|
61
|
+
session: RecipeSession;
|
|
62
|
+
focused: boolean;
|
|
63
|
+
maxH?: number;
|
|
64
|
+
maxW?: number;
|
|
65
|
+
onPick?: (recipeId: string) => void;
|
|
66
|
+
menuExtra?: (row: RecipeCompactRow) => ReactNode;
|
|
67
|
+
defaultMaterial?: string;
|
|
68
|
+
}) {
|
|
69
|
+
const t = useTranslations();
|
|
70
|
+
const { dataset, lang, langMap, names, nav, index } = session;
|
|
71
|
+
const recipe = useAsyncValue(
|
|
72
|
+
() => loadClientRecipe(dataset, row.id, row.bucket),
|
|
73
|
+
[dataset, row.id, row.bucket],
|
|
74
|
+
);
|
|
75
|
+
const [failed, setFailed] = useState(false);
|
|
76
|
+
|
|
77
|
+
const title = recipe
|
|
78
|
+
? recipeTitle(recipe, langMap)
|
|
79
|
+
: recipeItemName(names, lang, row.out[0] ?? row.id);
|
|
80
|
+
const src =
|
|
81
|
+
(recipe ? recipeImageUrl(dataset, recipe) : undefined) ??
|
|
82
|
+
(row.image
|
|
83
|
+
? recipeImageUrl(dataset, {
|
|
84
|
+
modId: row.id.split(':', 1)[0],
|
|
85
|
+
image: row.image,
|
|
86
|
+
})
|
|
87
|
+
: undefined) ??
|
|
88
|
+
recipeCardImageUrl(dataset, row.id);
|
|
89
|
+
|
|
90
|
+
const focus = () =>
|
|
91
|
+
pushUrlState(
|
|
92
|
+
recipeHref(dataset, lang, { ...nav, id: row.id, solo: undefined }),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const isolate = () =>
|
|
96
|
+
pushUrlState(
|
|
97
|
+
recipeHref(dataset, lang, { ...nav, id: row.id, solo: '1' }),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const openNewTab = () =>
|
|
101
|
+
window.open(
|
|
102
|
+
recipeHref(dataset, lang, { ...nav, id: row.id, solo: '1' }),
|
|
103
|
+
'_blank',
|
|
104
|
+
'noopener',
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const recipeType = index?.types[row.type];
|
|
108
|
+
const cardW = recipe?.w ?? row.d?.w ?? 0;
|
|
109
|
+
const fit = maxW && cardW > maxW ? maxW / cardW : 1;
|
|
110
|
+
return (
|
|
111
|
+
<CopyIdMenu
|
|
112
|
+
id={row.id}
|
|
113
|
+
label="recipe.copy_recipe_id"
|
|
114
|
+
extra={
|
|
115
|
+
<>
|
|
116
|
+
<RecipeDefaultMenuItem
|
|
117
|
+
dataset={dataset}
|
|
118
|
+
materialId={defaultMaterial ?? row.out[0]}
|
|
119
|
+
recipeId={row.id}
|
|
120
|
+
/>
|
|
121
|
+
{menuExtra?.(row)}
|
|
122
|
+
</>
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
<div
|
|
126
|
+
onClick={(event) => {
|
|
127
|
+
if ((event.target as HTMLElement).closest('a,button')) return;
|
|
128
|
+
if (onPick) onPick(row.id);
|
|
129
|
+
else focus();
|
|
130
|
+
}}
|
|
131
|
+
onDoubleClick={(event) => {
|
|
132
|
+
if ((event.target as HTMLElement).closest('a,button')) return;
|
|
133
|
+
if (onPick) openNewTab();
|
|
134
|
+
else isolate();
|
|
135
|
+
}}
|
|
136
|
+
onMouseEnter={() => {
|
|
137
|
+
favoriteHover.base = recipeType
|
|
138
|
+
? {
|
|
139
|
+
kind: 'recipe',
|
|
140
|
+
id: row.id,
|
|
141
|
+
type: recipeType,
|
|
142
|
+
...(row.out[0] ?? row.in[0]
|
|
143
|
+
? { icon: (row.out[0] ?? row.in[0])! }
|
|
144
|
+
: {}),
|
|
145
|
+
}
|
|
146
|
+
: undefined;
|
|
147
|
+
}}
|
|
148
|
+
onMouseLeave={() => {
|
|
149
|
+
favoriteHover.base = undefined;
|
|
150
|
+
favoriteHover.slot = undefined;
|
|
151
|
+
}}
|
|
152
|
+
aria-current={focused || undefined}
|
|
153
|
+
className={cn(
|
|
154
|
+
'relative w-fit flex-none rounded-md',
|
|
155
|
+
focused && 'ring-2 ring-primary ring-offset-1',
|
|
156
|
+
)}
|
|
157
|
+
style={fit < 1 ? { zoom: fit } : undefined}
|
|
158
|
+
>
|
|
159
|
+
{recipe ? (
|
|
160
|
+
src && !failed ? (
|
|
161
|
+
<PagedCard
|
|
162
|
+
recipe={recipe}
|
|
163
|
+
dataset={dataset}
|
|
164
|
+
lang={lang}
|
|
165
|
+
langMap={langMap}
|
|
166
|
+
nav={nav}
|
|
167
|
+
title={title}
|
|
168
|
+
src={src}
|
|
169
|
+
naturalW={row.d?.w}
|
|
170
|
+
naturalH={row.d?.h}
|
|
171
|
+
maxH={maxH}
|
|
172
|
+
interactive={focused}
|
|
173
|
+
onFail={() => setFailed(true)}
|
|
174
|
+
/>
|
|
175
|
+
) : (
|
|
176
|
+
<EmptyState variant="empty">{t('No recipe image in dump.', { note: 'recipe.no_image' })}</EmptyState>
|
|
177
|
+
)
|
|
178
|
+
) : src && !failed ? (
|
|
179
|
+
// eslint-disable-next-line @next/next/no-img-element -- dump asset
|
|
180
|
+
<img
|
|
181
|
+
src={src}
|
|
182
|
+
alt={title}
|
|
183
|
+
width={row.d?.w}
|
|
184
|
+
height={row.d?.h}
|
|
185
|
+
loading="lazy"
|
|
186
|
+
decoding="async"
|
|
187
|
+
onError={() => setFailed(true)}
|
|
188
|
+
className="block rounded-sm"
|
|
189
|
+
/>
|
|
190
|
+
) : (
|
|
191
|
+
<Skeleton
|
|
192
|
+
className="rounded-sm"
|
|
193
|
+
style={{
|
|
194
|
+
width: row.d?.w ?? FALLBACK_DIM.w,
|
|
195
|
+
height: row.d?.h ?? FALLBACK_DIM.h,
|
|
196
|
+
maxWidth: '100%',
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
</CopyIdMenu>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function RecipeCardGrid({
|
|
206
|
+
session,
|
|
207
|
+
rows,
|
|
208
|
+
boxRef,
|
|
209
|
+
maxH,
|
|
210
|
+
maxW,
|
|
211
|
+
loading,
|
|
212
|
+
empty,
|
|
213
|
+
onSwipe,
|
|
214
|
+
onPick,
|
|
215
|
+
cardMenuExtra,
|
|
216
|
+
defaultMaterial,
|
|
217
|
+
}: {
|
|
218
|
+
session: RecipeSession;
|
|
219
|
+
rows: RecipeCompactRow[];
|
|
220
|
+
boxRef: RefObject<HTMLDivElement | null>;
|
|
221
|
+
maxH?: number;
|
|
222
|
+
maxW?: number;
|
|
223
|
+
loading?: boolean;
|
|
224
|
+
empty?: string;
|
|
225
|
+
onSwipe?: (dir: -1 | 1) => void;
|
|
226
|
+
onPick?: (recipeId: string) => void;
|
|
227
|
+
cardMenuExtra?: (row: RecipeCompactRow) => ReactNode;
|
|
228
|
+
defaultMaterial?: string;
|
|
229
|
+
}) {
|
|
230
|
+
const { recipeId } = session;
|
|
231
|
+
const swipe = useSwipe((dir) => onSwipe?.(dir));
|
|
232
|
+
const { dataset } = session;
|
|
233
|
+
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
for (const row of rows) void loadClientRecipe(dataset, row.id, row.bucket);
|
|
236
|
+
}, [dataset, rows]);
|
|
237
|
+
|
|
238
|
+
let body;
|
|
239
|
+
if (loading) {
|
|
240
|
+
body = Array.from({ length: 6 }, (_, i) => (
|
|
241
|
+
<Skeleton
|
|
242
|
+
key={i}
|
|
243
|
+
className="h-24 rounded-md"
|
|
244
|
+
style={{ width: 220 + (i % 3) * 60 }}
|
|
245
|
+
/>
|
|
246
|
+
));
|
|
247
|
+
} else if (!rows.length) {
|
|
248
|
+
body = empty ? <EmptyState variant="empty">{empty}</EmptyState> : null;
|
|
249
|
+
} else {
|
|
250
|
+
body = rows.map((row) => (
|
|
251
|
+
<RecipeGridCard
|
|
252
|
+
key={`${row.bucket ?? ''}#${row.id}`}
|
|
253
|
+
row={row}
|
|
254
|
+
session={session}
|
|
255
|
+
focused={row.id === recipeId}
|
|
256
|
+
maxH={maxH}
|
|
257
|
+
maxW={maxW}
|
|
258
|
+
onPick={onPick}
|
|
259
|
+
defaultMaterial={defaultMaterial}
|
|
260
|
+
menuExtra={cardMenuExtra}
|
|
261
|
+
/>
|
|
262
|
+
));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<div
|
|
267
|
+
ref={boxRef}
|
|
268
|
+
{...swipe}
|
|
269
|
+
className="flex min-h-0 flex-1 flex-col items-center justify-start gap-2 overflow-x-hidden"
|
|
270
|
+
>
|
|
271
|
+
{body}
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Star } from 'lucide-react';
|
|
4
|
+
import { Toggle } from '@terrafirmagreg-team/ui/components/ui/toggle';
|
|
5
|
+
import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
|
|
6
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
7
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
8
|
+
|
|
9
|
+
export function FavoriteButton({
|
|
10
|
+
active,
|
|
11
|
+
onToggle,
|
|
12
|
+
label,
|
|
13
|
+
variant = 'ghost',
|
|
14
|
+
className,
|
|
15
|
+
}: {
|
|
16
|
+
active: boolean;
|
|
17
|
+
onToggle: () => void;
|
|
18
|
+
label?: string;
|
|
19
|
+
variant?: 'ghost' | 'outline' | 'overlay';
|
|
20
|
+
className?: string;
|
|
21
|
+
}) {
|
|
22
|
+
const t = useTranslations();
|
|
23
|
+
const text =
|
|
24
|
+
label ??
|
|
25
|
+
(active ? t('Remove from favorites', { note: 'recipe.remove_favorite' }) : t('Add to favorites', { note: 'recipe.add_favorite' }));
|
|
26
|
+
return (
|
|
27
|
+
<Hint label={text}>
|
|
28
|
+
<Toggle
|
|
29
|
+
variant={variant === 'outline' ? 'outline' : 'default'}
|
|
30
|
+
pressed={active}
|
|
31
|
+
onPressedChange={onToggle}
|
|
32
|
+
aria-label={text}
|
|
33
|
+
className={cn(
|
|
34
|
+
'size-7 rounded-lg p-0 data-pressed:bg-transparent [&_svg]:size-3.5',
|
|
35
|
+
variant === 'overlay' &&
|
|
36
|
+
'absolute bottom-1 right-1 z-10 size-6 rounded-sm bg-background/80',
|
|
37
|
+
active && 'text-amber-500',
|
|
38
|
+
className,
|
|
39
|
+
)}
|
|
40
|
+
>
|
|
41
|
+
<Star className={cn(active && 'fill-current')} />
|
|
42
|
+
</Toggle>
|
|
43
|
+
</Hint>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
|
+
import { QueryPager } from '@terrafirmagreg-team/recipe/components/views/browser/query-controls';
|
|
7
|
+
import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
|
|
8
|
+
import { RecipeToolbar } from '@terrafirmagreg-team/recipe/components/views/browser/toolbar';
|
|
9
|
+
import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
10
|
+
import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
|
|
11
|
+
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
12
|
+
|
|
13
|
+
type FeedList = {
|
|
14
|
+
page: number;
|
|
15
|
+
pages: number;
|
|
16
|
+
from?: number;
|
|
17
|
+
to: number;
|
|
18
|
+
total: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function RecipeFrame({
|
|
22
|
+
session,
|
|
23
|
+
header,
|
|
24
|
+
list,
|
|
25
|
+
strip,
|
|
26
|
+
rail,
|
|
27
|
+
back,
|
|
28
|
+
onPageChange,
|
|
29
|
+
children,
|
|
30
|
+
}: {
|
|
31
|
+
session: RecipeSession;
|
|
32
|
+
header: ReactNode;
|
|
33
|
+
list?: FeedList;
|
|
34
|
+
strip?: ReactNode;
|
|
35
|
+
rail?: ReactNode;
|
|
36
|
+
back?: { href: string; label: string };
|
|
37
|
+
onPageChange?: (page: number) => void;
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
}) {
|
|
40
|
+
const t = useTranslations();
|
|
41
|
+
const goPage = (dir: number) => {
|
|
42
|
+
if (!list || list.pages <= 1) return;
|
|
43
|
+
const next = (list.page + dir + list.pages) % list.pages;
|
|
44
|
+
if (onPageChange) {
|
|
45
|
+
onPageChange(next);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
replaceUrlState(
|
|
49
|
+
recipeHref(session.dataset, session.lang, {
|
|
50
|
+
...session.nav,
|
|
51
|
+
id: undefined,
|
|
52
|
+
rpage: next > 0 ? next + 1 : undefined,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
return (
|
|
57
|
+
<div className="flex h-full min-h-0 flex-1 flex-col">
|
|
58
|
+
{strip ? (
|
|
59
|
+
<div className="flex items-center gap-2">
|
|
60
|
+
<div className="min-w-0 flex-1">{strip}</div>
|
|
61
|
+
</div>
|
|
62
|
+
) : null}
|
|
63
|
+
<div className="flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-border pb-2 pt-2">
|
|
64
|
+
{back ? (
|
|
65
|
+
<Link
|
|
66
|
+
href={back.href}
|
|
67
|
+
className="shrink-0 text-xs text-muted-foreground hover:text-foreground"
|
|
68
|
+
>
|
|
69
|
+
← {back.label}
|
|
70
|
+
</Link>
|
|
71
|
+
) : null}
|
|
72
|
+
<div className="min-w-0 flex-1">{header}</div>
|
|
73
|
+
<div className="ms-auto flex items-center gap-2">
|
|
74
|
+
<RecipeToolbar session={session} />
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
{list ? (
|
|
78
|
+
onPageChange ? (
|
|
79
|
+
<Pager
|
|
80
|
+
page={list.page}
|
|
81
|
+
pages={list.pages}
|
|
82
|
+
to={list.to}
|
|
83
|
+
total={list.total}
|
|
84
|
+
label={t('{page}/{pages}', { note: 'recipe.page_of' })}
|
|
85
|
+
className="pt-2"
|
|
86
|
+
onPage={onPageChange}
|
|
87
|
+
/>
|
|
88
|
+
) : (
|
|
89
|
+
<QueryPager
|
|
90
|
+
dataset={session.dataset}
|
|
91
|
+
lang={session.lang}
|
|
92
|
+
params={{ ...session.nav, id: undefined }}
|
|
93
|
+
query={session.query}
|
|
94
|
+
list={list}
|
|
95
|
+
label={t('{page}/{pages}', { note: 'recipe.page_of' })}
|
|
96
|
+
className="pt-2"
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
) : null}
|
|
100
|
+
<div className="flex min-h-0 flex-1 gap-2 overflow-hidden pt-2">
|
|
101
|
+
{rail}
|
|
102
|
+
<div
|
|
103
|
+
onWheel={(event) => goPage(event.deltaY > 0 ? 1 : -1)}
|
|
104
|
+
className="flex min-w-0 flex-1 flex-col"
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useDocumentTitle } from '@terrafirmagreg-team/ui/hooks/use-document-title';
|
|
4
|
+
import { useRecipeSession } from '@terrafirmagreg-team/recipe/hooks/use-session';
|
|
5
|
+
import { recipeConfig } from '@terrafirmagreg-team/recipe/lib/config';
|
|
6
|
+
import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
7
|
+
import { ItemPanel } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel';
|
|
8
|
+
import { RecipeGlareFilter } from '@terrafirmagreg-team/recipe/components/cards/glare-filter';
|
|
9
|
+
import { RightSidebarPortal } from '@terrafirmagreg-team/ui/components/layouts/right-sidebar';
|
|
10
|
+
import { TypeView } from '@terrafirmagreg-team/recipe/components/views/browser/type-view';
|
|
11
|
+
import { ItemView } from '@terrafirmagreg-team/recipe/components/views/browser/item-view';
|
|
12
|
+
import { Calculator } from '@terrafirmagreg-team/recipe/components/views/calc/calculator';
|
|
13
|
+
import { ForgeCalculator } from '@terrafirmagreg-team/recipe/components/views/forge';
|
|
14
|
+
import { AlloyCalculator } from '@terrafirmagreg-team/recipe/components/views/alloy';
|
|
15
|
+
import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
|
|
16
|
+
import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
|
|
17
|
+
import { ItemRow } from '@terrafirmagreg-team/ui/components/blocks/list/row';
|
|
18
|
+
import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
|
|
19
|
+
import { EntryProvider } from '@terrafirmagreg-team/game/hooks/use-entry-context';
|
|
20
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
21
|
+
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
22
|
+
import type { RecipePageData } from '@terrafirmagreg-team/recipe/types';
|
|
23
|
+
|
|
24
|
+
export function RecipeBrowser({
|
|
25
|
+
dataset: id,
|
|
26
|
+
datasetTitle,
|
|
27
|
+
lang,
|
|
28
|
+
versions,
|
|
29
|
+
}: {
|
|
30
|
+
dataset: string;
|
|
31
|
+
datasetTitle: string;
|
|
32
|
+
lang: Lang;
|
|
33
|
+
versions?: readonly string[];
|
|
34
|
+
}) {
|
|
35
|
+
const page: RecipePageData = {
|
|
36
|
+
title: datasetTitle,
|
|
37
|
+
dataset: { id },
|
|
38
|
+
lang,
|
|
39
|
+
versions: versions as string[] | undefined,
|
|
40
|
+
};
|
|
41
|
+
const session = useRecipeSession(page);
|
|
42
|
+
const { dataset, item, fluid, names } = session;
|
|
43
|
+
const focusId = item ?? fluid;
|
|
44
|
+
|
|
45
|
+
const focusTitle = focusId
|
|
46
|
+
? recipeItemName(names, lang, focusId)
|
|
47
|
+
: (session.recipeId ?? '');
|
|
48
|
+
useDocumentTitle(`${focusTitle || page.title} | ${recipeConfig().appName}`);
|
|
49
|
+
|
|
50
|
+
const isCalc = session.place?.kind === 'calc';
|
|
51
|
+
|
|
52
|
+
let main;
|
|
53
|
+
if (focusId) {
|
|
54
|
+
main = <ItemView session={session} />;
|
|
55
|
+
} else if (isCalc) {
|
|
56
|
+
main = <Calculator session={session} />;
|
|
57
|
+
} else if (session.place?.kind === 'forge') {
|
|
58
|
+
main = <ForgeCalculator session={session} />;
|
|
59
|
+
} else if (session.place?.kind === 'alloy') {
|
|
60
|
+
main = <AlloyCalculator session={session} />;
|
|
61
|
+
} else if (session.place?.kind === 'type') {
|
|
62
|
+
main = <TypeView session={session} />;
|
|
63
|
+
} else {
|
|
64
|
+
main = (
|
|
65
|
+
<RecipeFrame
|
|
66
|
+
session={session}
|
|
67
|
+
strip={<RecipeTypeTabs session={session} ids={[]} />}
|
|
68
|
+
header={<ItemRow layout="header" title={page.title} />}
|
|
69
|
+
>
|
|
70
|
+
<div className="flex min-h-0 flex-1 flex-col items-center justify-start gap-2 pt-2">
|
|
71
|
+
{Array.from({ length: 6 }, (_, i) => (
|
|
72
|
+
<Skeleton
|
|
73
|
+
key={i}
|
|
74
|
+
className="h-24 rounded-md"
|
|
75
|
+
style={{ width: 240 + (i % 3) * 70 }}
|
|
76
|
+
/>
|
|
77
|
+
))}
|
|
78
|
+
</div>
|
|
79
|
+
</RecipeFrame>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<EntryProvider dataset={dataset} lang={lang} langMap={session.langMap}>
|
|
85
|
+
<RecipeGlareFilter />
|
|
86
|
+
<div
|
|
87
|
+
className={cn(
|
|
88
|
+
'viewport-shell recipe-viewport not-prose flex w-full flex-col gap-3',
|
|
89
|
+
isCalc && 'calc-viewport',
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
<div className="flex min-h-0 flex-1 gap-4">
|
|
93
|
+
<main className="flex min-w-0 flex-1 flex-col">{main}</main>
|
|
94
|
+
</div>
|
|
95
|
+
<RightSidebarPortal>
|
|
96
|
+
<ItemPanel
|
|
97
|
+
dataset={dataset}
|
|
98
|
+
lang={lang}
|
|
99
|
+
index={session.index}
|
|
100
|
+
indexLoading={session.indexLoading}
|
|
101
|
+
names={names}
|
|
102
|
+
tab={session.tab}
|
|
103
|
+
query={session.query}
|
|
104
|
+
setQuery={session.setQuery}
|
|
105
|
+
isCalc={isCalc}
|
|
106
|
+
nav={session.nav}
|
|
107
|
+
className="hidden h-full w-90 lg:flex"
|
|
108
|
+
/>
|
|
109
|
+
</RightSidebarPortal>
|
|
110
|
+
</div>
|
|
111
|
+
</EntryProvider>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|