@terrafirmagreg-team/recipe 1.2.41 → 1.2.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/package.json +4 -4
  2. package/src/components/cards/calc-add-item.tsx +55 -0
  3. package/src/components/cards/card/index.tsx +2 -0
  4. package/src/components/cards/card/text.tsx +20 -4
  5. package/src/components/views/browser/card-grid.tsx +11 -23
  6. package/src/components/views/browser/frame.tsx +8 -33
  7. package/src/components/views/browser/item-view/index.tsx +8 -10
  8. package/src/components/views/browser/settings.tsx +6 -0
  9. package/src/components/views/browser/type-tabs.tsx +5 -0
  10. package/src/components/views/browser/type-view.tsx +9 -47
  11. package/src/components/views/calc/calculator/index.tsx +4 -0
  12. package/src/components/views/calc/flow/index.tsx +42 -1
  13. package/src/components/views/calc/flow/picker-dialogs.tsx +15 -8
  14. package/src/components/views/calc/flow/toolbar.tsx +2 -0
  15. package/src/components/views/calc/flow/view-menu.tsx +13 -0
  16. package/src/components/views/calc/member-picker.tsx +7 -2
  17. package/src/components/views/calc/node-card/actions.tsx +1 -1
  18. package/src/components/views/calc/node-card/badges.tsx +1 -1
  19. package/src/components/views/calc/node-card/far.tsx +1 -1
  20. package/src/components/views/calc/node-card/full.tsx +34 -5
  21. package/src/components/views/calc/node-card/menu.tsx +32 -0
  22. package/src/components/views/calc/recipe-picker/body.tsx +10 -36
  23. package/src/hooks/calc/flow/use-layout.ts +1 -1
  24. package/src/hooks/calc/flow/use-pickers.ts +14 -10
  25. package/src/hooks/calc/use-actions.ts +54 -31
  26. package/src/hooks/calc/use-recipe-ids.ts +33 -0
  27. package/src/hooks/use-card-grid.ts +14 -0
  28. package/src/lib/alloy/parse.ts +6 -3
  29. package/src/lib/browser/card-dim.test.ts +39 -0
  30. package/src/lib/browser/card-dim.ts +38 -0
  31. package/src/lib/browser/lookup.ts +3 -2
  32. package/src/lib/browser/row-match.test.ts +34 -0
  33. package/src/lib/browser/row-match.ts +8 -0
  34. package/src/lib/calc/flow.ts +3 -1
  35. package/src/lib/calc/member.test.ts +178 -0
  36. package/src/lib/calc/member.ts +90 -0
  37. package/src/lib/calc/scheme.test.ts +213 -0
  38. package/src/lib/calc/scheme.ts +8 -3
  39. package/src/lib/calc/tree/index.ts +5 -1
  40. package/src/lib/calc/tree/recipe.test.ts +88 -0
  41. package/src/lib/calc/tree/recipe.ts +19 -3
  42. package/src/lib/calc/wire.test.ts +70 -0
  43. package/src/lib/calc/wire.ts +6 -2
  44. package/src/lib/cards/model.test.ts +61 -1
  45. package/src/lib/cards/model.ts +9 -2
  46. package/src/types/calc-flow-props.ts +2 -0
  47. package/styles/calc.css +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrafirmagreg-team/recipe",
3
- "version": "1.2.41",
3
+ "version": "1.2.43",
4
4
  "type": "module",
5
5
  "description": "Recipe viewer and calculator",
6
6
  "license": "LGPL-3.0-only",
@@ -25,13 +25,13 @@
25
25
  "dependencies": {
26
26
  "@terrafirmagreg-team/data": "^1.2.14",
27
27
  "@terrafirmagreg-team/dump": "^1.2.25",
28
- "@terrafirmagreg-team/game": "^1.2.17",
28
+ "@terrafirmagreg-team/game": "^1.2.18",
29
29
  "@terrafirmagreg-team/kit": "^1.2.37",
30
30
  "@terrafirmagreg-team/mdx": "^1.2.14",
31
31
  "@terrafirmagreg-team/preview": "^1.2.12",
32
32
  "@terrafirmagreg-team/sites": "^1.2.5",
33
- "@terrafirmagreg-team/translate": "^1.2.16",
34
- "@terrafirmagreg-team/ui": "^1.2.31",
33
+ "@terrafirmagreg-team/translate": "^1.2.17",
34
+ "@terrafirmagreg-team/ui": "^1.2.32",
35
35
  "@types/pathfinding": "^0.1.0",
36
36
  "comlink": "^4.4.2",
37
37
  "fflate": "0.8.3",
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ import type { RecipeCompactRow, RecipeSession } from '@terrafirmagreg-team/recipe/types';
3
+
4
+ import { Workflow } from 'lucide-react';
5
+ import { ContextMenuItem } from '@terrafirmagreg-team/ui/components/ui/context-menu';
6
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
7
+ import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
8
+ import { encodeCalcState } from '@terrafirmagreg-team/recipe/lib/calc/tree';
9
+ import { recipeCalcHref } from '@terrafirmagreg-team/recipe/lib/links';
10
+ import { stackIdBase } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
11
+ import { pushUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
12
+
13
+ export function CalcAddMenuItem({
14
+ session,
15
+ row,
16
+ }: {
17
+ session: RecipeSession;
18
+ row: RecipeCompactRow;
19
+ }) {
20
+ const t = useTranslations();
21
+ const resolved = useResolvedLang();
22
+ const out = row.out[0];
23
+ if (!out) return null;
24
+ const materialId = stackIdBase(out);
25
+ const kind = session.index?.fluids?.includes(materialId) ? 'fluid' : 'item';
26
+ return (
27
+ <ContextMenuItem
28
+ onClick={() =>
29
+ pushUrlState(
30
+ recipeCalcHref(
31
+ session.dataset,
32
+ resolved,
33
+ encodeCalcState({
34
+ cards: [
35
+ {
36
+ id: `c${crypto.randomUUID()}`,
37
+ materialId,
38
+ kind,
39
+ recipeId: row.id,
40
+ crafts: 1,
41
+ },
42
+ ],
43
+ wires: [],
44
+ tagSelections: {},
45
+ }),
46
+ session.nav.version,
47
+ ),
48
+ )
49
+ }
50
+ >
51
+ <Workflow />
52
+ {t('Add to new scheme', { note: 'recipe.calc.new_scheme' })}
53
+ </ContextMenuItem>
54
+ );
55
+ }
@@ -104,6 +104,7 @@ export function RecipeCard({
104
104
  return (
105
105
  <div
106
106
  ref={rootRef}
107
+ data-marquee-hover
107
108
  className="relative w-fit overflow-hidden rounded-sm bg-mc-panel"
108
109
  >
109
110
  {src ? (
@@ -209,6 +210,7 @@ export function RecipeCard({
209
210
  scale={scale}
210
211
  langMap={langMap}
211
212
  size={micro}
213
+ rightGui={margin + contentGuiW}
212
214
  {...(labelSlot
213
215
  ? {
214
216
  anchor: {
@@ -2,9 +2,12 @@
2
2
 
3
3
  import { McText } from '@terrafirmagreg-team/game/components/entry/mc-text';
4
4
  import { dumpTextString } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
5
+ import { Marquee } from '@terrafirmagreg-team/ui/components/blocks/text/marquee';
5
6
  import { widgetTextColor } from '@terrafirmagreg-team/recipe/lib/cards/model';
6
7
  import type { RecipeTextWidget } from '@terrafirmagreg-team/recipe/lib/data/dto';
7
8
 
9
+ const LEFT_INSET = 1;
10
+
8
11
  export function CardText({
9
12
  widget,
10
13
  offX = 0,
@@ -13,6 +16,7 @@ export function CardText({
13
16
  langMap,
14
17
  anchor,
15
18
  size,
19
+ rightGui,
16
20
  }: {
17
21
  widget: RecipeTextWidget;
18
22
  offX?: number;
@@ -21,6 +25,7 @@ export function CardText({
21
25
  langMap?: Record<string, string>;
22
26
  anchor?: { x: number; y: number; w: number };
23
27
  size?: number;
28
+ rightGui?: number;
24
29
  }) {
25
30
  const content = widget.component
26
31
  ? dumpTextString(langMap ?? {}, widget.component) || widget.text
@@ -29,6 +34,12 @@ export function CardText({
29
34
  const wrap = widget.type === 'paragraph';
30
35
  const rgb = widgetTextColor(widget.color, widget.shadow === true);
31
36
  const shadowRgb = ((rgb & 0xfcfcfc) >> 2) & 0xffffff;
37
+ const relX = widget.x + offX;
38
+ const clamped = !anchor && !wrap && rightGui !== undefined;
39
+ const leftGui = clamped ? Math.max(relX, LEFT_INSET) : relX;
40
+ const widthGui = clamped
41
+ ? Math.max(rightGui - leftGui, 0)
42
+ : widget.w;
32
43
  return (
33
44
  <span
34
45
  className={`font-mc pointer-events-none absolute leading-none ${wrap ? 'whitespace-pre-wrap' : 'whitespace-pre'}`}
@@ -41,9 +52,9 @@ export function CardText({
41
52
  textAlign: 'right' as const,
42
53
  }
43
54
  : {
44
- left: (widget.x + offX) * scale,
55
+ left: leftGui * scale,
45
56
  top: (widget.y + offY) * scale,
46
- ...(wrap ? { width: widget.w * scale } : {}),
57
+ ...(wrap || clamped ? { width: widthGui * scale } : {}),
47
58
  }),
48
59
  fontSize: size ?? 8 * scale,
49
60
  fontWeight: 700,
@@ -55,8 +66,13 @@ export function CardText({
55
66
  : {}),
56
67
  }}
57
68
  >
58
- <McText text={content} surface="normal" />
69
+ {clamped ? (
70
+ <Marquee>
71
+ <McText text={content} surface="normal" />
72
+ </Marquee>
73
+ ) : (
74
+ <McText text={content} surface="normal" />
75
+ )}
59
76
  </span>
60
77
  );
61
78
  }
62
-
@@ -6,6 +6,7 @@ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-transl
6
6
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
7
7
  import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
8
8
  import { RecipeDefaultMenuItem } from '@terrafirmagreg-team/recipe/components/cards/default-item';
9
+ import { CalcAddMenuItem } from '@terrafirmagreg-team/recipe/components/cards/calc-add-item';
9
10
  import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
10
11
  import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
11
12
  import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
@@ -19,35 +20,14 @@ import { pushUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
19
20
  import { useSwipe } from '@terrafirmagreg-team/ui/hooks/use-swipe';
20
21
  import { dismissOpenTooltips } from '@terrafirmagreg-team/ui/lib/dismiss-tooltips';
21
22
  import { favoriteHover } from '@terrafirmagreg-team/recipe/lib/browser/favorite-hover';
23
+ import { FALLBACK_DIM } from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
22
24
  import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
23
25
  import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
24
- import type { FitDim } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
25
26
  import type {
26
- RecipeCategory,
27
- RecipeCompactIndex,
28
27
  RecipeCompactRow,
29
28
  RecipeSession,
30
29
  } from '@terrafirmagreg-team/recipe/types';
31
30
 
32
- const FALLBACK_DIM: FitDim = { w: 320, h: 80 };
33
-
34
- export function recipeCardDim(
35
- index: RecipeCompactIndex | null,
36
- categoriesById: Map<string, RecipeCategory>,
37
- row: RecipeCompactRow,
38
- ): FitDim {
39
- if (row.d) return { w: row.d.w, h: row.d.h };
40
- const typeId = index?.types[row.type];
41
- const layout = typeId ? categoriesById.get(typeId)?.layout : undefined;
42
- if (!layout) return FALLBACK_DIM;
43
- const scale = layout.scale ?? 2;
44
- const margin = layout.margin ?? 0;
45
- return {
46
- w: (layout.w + margin * 2) * scale,
47
- h: (layout.h + margin * 2) * scale,
48
- };
49
- }
50
-
51
31
  function RecipeGridCard({
52
32
  row,
53
33
  session,
@@ -122,6 +102,7 @@ function RecipeGridCard({
122
102
  materialId={defaultMaterial ?? row.out[0]}
123
103
  recipeId={row.id}
124
104
  />
105
+ <CalcAddMenuItem session={session} row={row} />
125
106
  {menuExtra?.(row)}
126
107
  </>
127
108
  }
@@ -217,6 +198,7 @@ export function RecipeCardGrid({
217
198
  boxRef,
218
199
  maxH,
219
200
  maxW,
201
+ vertical,
220
202
  loading,
221
203
  empty,
222
204
  onSwipe,
@@ -229,6 +211,7 @@ export function RecipeCardGrid({
229
211
  boxRef: RefObject<HTMLDivElement | null>;
230
212
  maxH?: number;
231
213
  maxW?: number;
214
+ vertical?: boolean;
232
215
  loading?: boolean;
233
216
  empty?: string;
234
217
  onSwipe?: (dir: -1 | 1) => void;
@@ -276,7 +259,12 @@ export function RecipeCardGrid({
276
259
  ref={boxRef}
277
260
  {...swipe}
278
261
  onScroll={dismissOpenTooltips}
279
- className="flex min-h-0 flex-1 flex-col items-center justify-start gap-2 overflow-x-auto overflow-y-clip"
262
+ className={cn(
263
+ 'flex min-h-0 flex-1 items-center gap-2 overflow-x-clip overflow-y-auto',
264
+ vertical
265
+ ? 'flex-col'
266
+ : 'flex-row flex-wrap content-start justify-center',
267
+ )}
280
268
  >
281
269
  {body}
282
270
  </div>
@@ -1,15 +1,15 @@
1
1
  'use client';
2
2
 
3
3
  import Link from 'next/link';
4
- import type { ReactNode } from 'react';
4
+ import { useRef, type ReactNode } from 'react';
5
5
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
6
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
7
+ import { useElementSize } from '@terrafirmagreg-team/ui/hooks/use-element-size';
7
8
  import { QueryPager } from '@terrafirmagreg-team/recipe/components/views/browser/query-controls';
8
9
  import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
9
10
  import { RecipeToolbar } from '@terrafirmagreg-team/recipe/components/views/browser/toolbar';
10
11
  import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
11
12
  import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
12
- import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
13
13
  import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
14
14
 
15
15
  type FeedList = {
@@ -27,9 +27,6 @@ export function RecipeFrame({
27
27
  strip,
28
28
  rail,
29
29
  back,
30
- navPrev,
31
- navNext,
32
- onNavWheel,
33
30
  onPageChange,
34
31
  children,
35
32
  }: {
@@ -39,14 +36,13 @@ export function RecipeFrame({
39
36
  strip?: ReactNode;
40
37
  rail?: ReactNode;
41
38
  back?: { href: string; label: string };
42
- navPrev?: ReactNode;
43
- navNext?: ReactNode;
44
- onNavWheel?: (dir: -1 | 1) => void;
45
39
  onPageChange?: (page: number) => void;
46
40
  children: ReactNode;
47
41
  }) {
48
42
  const t = useTranslations();
49
43
  const resolved = useResolvedLang();
44
+ const railBoxRef = useRef<HTMLDivElement | null>(null);
45
+ const railSize = useElementSize(railBoxRef);
50
46
  const goPage = (dir: number) => {
51
47
  if (!list || list.pages <= 1) return;
52
48
  const next = (list.page + dir + list.pages) % list.pages;
@@ -71,14 +67,7 @@ export function RecipeFrame({
71
67
  <div className="min-w-0 flex-1">{strip}</div>
72
68
  </div>
73
69
  ) : null}
74
- <div
75
- className={cn(
76
- 'relative grid items-center gap-x-3 border-b border-border pb-2 pt-2 max-sm:pe-11',
77
- navPrev || navNext
78
- ? 'grid-cols-[auto_minmax(0,1fr)_auto] sm:grid-cols-[minmax(0,1fr)_minmax(0,360px)_minmax(0,1fr)]'
79
- : 'grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)]',
80
- )}
81
- >
70
+ <div className="relative grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-x-3 border-b border-border pb-2 pt-2 max-sm:pe-11">
82
71
  <div className="flex min-w-0 justify-start">
83
72
  {back ? (
84
73
  <Link
@@ -89,22 +78,7 @@ export function RecipeFrame({
89
78
  </Link>
90
79
  ) : null}
91
80
  </div>
92
- {navPrev || navNext ? (
93
- <div
94
- onWheel={
95
- onNavWheel
96
- ? (event) => onNavWheel(event.deltaY > 0 ? 1 : -1)
97
- : undefined
98
- }
99
- className="flex w-full max-w-90 min-w-0 items-center gap-2"
100
- >
101
- {navPrev}
102
- <div className="min-w-0 flex-1">{header}</div>
103
- {navNext}
104
- </div>
105
- ) : (
106
- <div className="min-w-0 max-w-full">{header}</div>
107
- )}
81
+ <div className="min-w-0 max-w-full">{header}</div>
108
82
  <div className="flex min-w-0 items-center justify-self-end max-sm:absolute max-sm:end-1.5 max-sm:top-1/2 max-sm:-translate-y-1/2">
109
83
  <RecipeToolbar session={session} />
110
84
  </div>
@@ -136,13 +110,14 @@ export function RecipeFrame({
136
110
  ) : null}
137
111
  <div className="relative flex min-h-0 flex-1 overflow-hidden pt-2">
138
112
  {rail ? (
139
- <div className="z-10 flex flex-col sm:absolute sm:start-0 sm:top-2 sm:bottom-0">
113
+ <div ref={railBoxRef} className="z-10 flex shrink-0 flex-col">
140
114
  {rail}
141
115
  </div>
142
116
  ) : null}
143
117
  <div
144
118
  onWheel={(event) => goPage(event.deltaY > 0 ? 1 : -1)}
145
119
  className="flex min-w-0 flex-1 flex-col"
120
+ style={rail ? { paddingInlineEnd: railSize.w } : undefined}
146
121
  >
147
122
  {children}
148
123
  </div>
@@ -5,14 +5,13 @@ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-transl
5
5
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
6
6
  import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
7
7
  import { ItemViewHeader } from '@terrafirmagreg-team/recipe/components/views/browser/item-view-header';
8
- import {
9
- RecipeCardGrid,
10
- recipeCardDim,
11
- } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
8
+ import { RecipeCardGrid } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
9
+ import { recipeCardFitDim } from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
12
10
  import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
13
11
  import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
14
12
  import { PaneTabs } from '@terrafirmagreg-team/recipe/components/views/browser/pane-tabs';
15
13
  import { useFitPages } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
14
+ import { useCardGrid } from '@terrafirmagreg-team/recipe/hooks/use-card-grid';
16
15
  import { useCategoriesById } from '@terrafirmagreg-team/recipe/hooks/use-categories-by-id';
17
16
  import { useTypeFilter } from '@terrafirmagreg-team/recipe/hooks/use-type-filter';
18
17
  import { useFavorites } from '@terrafirmagreg-team/recipe/hooks/use-favorites';
@@ -93,17 +92,15 @@ export function ItemView({ session }: { session: RecipeSession }) {
93
92
  const focusIndex = recipeId
94
93
  ? typeFilter.rows.findIndex((row) => row.id === recipeId)
95
94
  : -1;
95
+ const { grid } = useCardGrid();
96
96
  const list = useFitPages(
97
97
  boxRef,
98
98
  typeFilter.rows,
99
- (row, box) => {
100
- const d = recipeCardDim(index, categoriesById, row);
101
- return d.h > box.h ? { w: d.w, h: box.h } : d;
102
- },
99
+ (row, box) => recipeCardFitDim(index, categoriesById, row, box),
103
100
  rpage,
104
101
  8,
105
102
  focusIndex >= 0 ? focusIndex : undefined,
106
- true,
103
+ !grid,
107
104
  );
108
105
 
109
106
  const onSwipe = (dir: -1 | 1) => {
@@ -177,7 +174,8 @@ export function ItemView({ session }: { session: RecipeSession }) {
177
174
  boxRef={boxRef}
178
175
  maxH={list.box.h}
179
176
  maxW={list.box.w}
180
- loading={feeds.pending}
177
+ vertical={!grid}
178
+ loading={feeds.pending || !list.measured}
181
179
  empty={t('No recipes of this type.', { note: 'recipe.empty_type' })}
182
180
  onSwipe={onSwipe}
183
181
  />
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { Settings2 } from 'lucide-react';
4
4
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { useCardGrid } from '@terrafirmagreg-team/recipe/hooks/use-card-grid';
5
6
  import { useHideUnused } from '@terrafirmagreg-team/recipe/hooks/use-hide-unused';
6
7
  import { useSidebarGroup } from '@terrafirmagreg-team/recipe/hooks/use-sidebar-group';
7
8
  import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
@@ -17,6 +18,7 @@ export function RecipeSettings() {
17
18
  const t = useTranslations();
18
19
  const { hideUnused, setHideUnused } = useHideUnused();
19
20
  const { sidebarGroup, setSidebarGroup } = useSidebarGroup();
21
+ const { grid, setGrid } = useCardGrid();
20
22
 
21
23
  return (
22
24
  <Popover>
@@ -45,6 +47,10 @@ export function RecipeSettings() {
45
47
  />
46
48
  {t('Group sidebar by mod', { note: 'recipe.sidebar_group_mod' })}
47
49
  </Label>
50
+ <Label className="gap-1.5 text-sm font-normal">
51
+ <Switch size="sm" checked={grid} onCheckedChange={setGrid} />
52
+ {t('Cards grid', { note: 'recipe.cards_grid' })}
53
+ </Label>
48
54
  </PopoverContent>
49
55
  </Popover>
50
56
  );
@@ -7,6 +7,7 @@ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
7
7
  import { creativeTabName } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
8
8
  import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
9
9
  import { IconPager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
10
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
10
11
  import type { RecipeCategory, RecipeSession } from '@terrafirmagreg-team/recipe/types';
11
12
 
12
13
  function CategoryGlyph({
@@ -48,6 +49,7 @@ export function RecipeTypeTabs({
48
49
  className?: string;
49
50
  }) {
50
51
  const { lang, names, index, dataset, langMap } = session;
52
+ const t = useTranslations();
51
53
 
52
54
  const options = useMemo(() => {
53
55
  const byId = new Map(
@@ -72,6 +74,9 @@ export function RecipeTypeTabs({
72
74
  value={value}
73
75
  options={options}
74
76
  onChange={onChange ?? (() => {})}
77
+ step="option"
78
+ prevLabel={t('Previous category', { note: 'recipe.axis.prev' })}
79
+ nextLabel={t('Next category', { note: 'recipe.axis.next' })}
75
80
  className={className}
76
81
  />
77
82
  );
@@ -1,16 +1,14 @@
1
1
  'use client';
2
2
 
3
3
  import { useEffect, useRef } from 'react';
4
- import { PagerArrow } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
5
4
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
5
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
7
6
  import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
8
7
  import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
9
- import {
10
- RecipeCardGrid,
11
- recipeCardDim,
12
- } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
8
+ import { RecipeCardGrid } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
9
+ import { recipeCardFitDim } from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
13
10
  import { PlaceHeader } from '@terrafirmagreg-team/recipe/components/views/browser/place-header';
11
+ import { useCardGrid } from '@terrafirmagreg-team/recipe/hooks/use-card-grid';
14
12
  import { useCategoriesById } from '@terrafirmagreg-team/recipe/hooks/use-categories-by-id';
15
13
  import { useFitPages } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
16
14
  import {
@@ -93,35 +91,17 @@ export function TypeView({ session }: { session: RecipeSession }) {
93
91
  }),
94
92
  );
95
93
  }, [focusIndex, focusRes.pending, focusRes.value, index, nav, dataset, resolved, recipeId, rows, shown]);
94
+ const { grid } = useCardGrid();
96
95
  const list = useFitPages(
97
96
  boxRef,
98
97
  feedRows,
99
- (row, box) => {
100
- const d = recipeCardDim(index, categoriesById, row);
101
- return d.h > box.h ? { w: d.w, h: box.h } : d;
102
- },
98
+ (row, box) => recipeCardFitDim(index, categoriesById, row, box),
103
99
  rpage,
104
100
  8,
105
101
  feedFocus >= 0 ? feedFocus : undefined,
106
- true,
102
+ !grid,
107
103
  );
108
104
 
109
- const goCategory = (dir: -1 | 1) => {
110
- const cur = nonEmptyIds.indexOf(shown ?? '');
111
- const next =
112
- nonEmptyIds[(cur + dir + nonEmptyIds.length) % nonEmptyIds.length];
113
- if (!next || next === shown) return;
114
- replaceUrlState(
115
- recipeHref(dataset, resolved, {
116
- ...nav,
117
- type: next,
118
- id: undefined,
119
- solo: undefined,
120
- rpage: undefined,
121
- }),
122
- );
123
- };
124
-
125
105
  const onSwipe = (dir: -1 | 1) => {
126
106
  if (recipeId) {
127
107
  const next = focusIndex + dir;
@@ -155,7 +135,8 @@ export function TypeView({ session }: { session: RecipeSession }) {
155
135
  boxRef={boxRef}
156
136
  maxH={list.box.h}
157
137
  maxW={list.box.w}
158
- loading={indexLoading || (shown != null && rows === undefined)}
138
+ vertical={!grid}
139
+ loading={indexLoading || (shown != null && rows === undefined) || !list.measured}
159
140
  empty={t('No recipes of this type.', { note: 'recipe.empty_type' })}
160
141
  onSwipe={onSwipe}
161
142
  />
@@ -184,27 +165,8 @@ export function TypeView({ session }: { session: RecipeSession }) {
184
165
  }}
185
166
  />
186
167
  }
187
- navPrev={
188
- <PagerArrow
189
- dir={-1}
190
- label={t('Previous category', { note: 'recipe.axis.prev' })}
191
- disabled={nonEmptyIds.length < 2}
192
- className="max-sm:hidden"
193
- onClick={() => goCategory(-1)}
194
- />
195
- }
196
- navNext={
197
- <PagerArrow
198
- dir={1}
199
- label={t('Next category', { note: 'recipe.axis.next' })}
200
- disabled={nonEmptyIds.length < 2}
201
- className="max-sm:hidden"
202
- onClick={() => goCategory(1)}
203
- />
204
- }
205
- onNavWheel={goCategory}
206
168
  header={
207
- <div className="flex min-w-0 justify-center">
169
+ <div className="mx-auto w-full max-w-90">
208
170
  <PlaceHeader
209
171
  session={session}
210
172
  overline={t('Categories', { note: 'recipe.axis_type' })}
@@ -16,12 +16,14 @@ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
16
16
  import { useCalcData } from '@terrafirmagreg-team/recipe/hooks/calc/use-data';
17
17
  import { useCalcViewMode } from '@terrafirmagreg-team/recipe/hooks/calc/use-view-mode';
18
18
  import { useCalcFarMode } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
19
+ import { useCalcRecipeIdsMode } from '@terrafirmagreg-team/recipe/hooks/calc/use-recipe-ids';
19
20
 
20
21
  export function Calculator({ session }: { session: RecipeSession }) {
21
22
  const t = useTranslations();
22
23
  const { dataset, lang } = session;
23
24
  const [mode, setMode] = useCalcViewMode();
24
25
  const [farCards, setFarCards] = useCalcFarMode();
26
+ const [recipeIds, setRecipeIds] = useCalcRecipeIdsMode();
25
27
  const {
26
28
  cards,
27
29
  wires,
@@ -151,6 +153,8 @@ export function Calculator({ session }: { session: RecipeSession }) {
151
153
  onModeChange={setMode}
152
154
  farCards={farCards}
153
155
  onFarCardsChange={setFarCards}
156
+ recipeIds={recipeIds}
157
+ onRecipeIdsChange={setRecipeIds}
154
158
  treeReady={settled}
155
159
  resetGen={resetGen}
156
160
  canvasId={activeTabId ?? undefined}
@@ -28,6 +28,7 @@ import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty
28
28
  import { CalcEdge } from '@terrafirmagreg-team/recipe/components/views/calc/edge';
29
29
  import { CalcSessionProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-calc-session';
30
30
  import { CalcFarProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
31
+ import { CalcRecipeIdsProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-recipe-ids';
31
32
  import { CalcTierProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-tier';
32
33
  import { useFlowPickers } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-pickers';
33
34
  import { useFlowLayout } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-layout';
@@ -77,6 +78,8 @@ function CalcFlowInner({
77
78
  onModeChange,
78
79
  farCards,
79
80
  onFarCardsChange,
81
+ recipeIds,
82
+ onRecipeIdsChange,
80
83
  treeReady = true,
81
84
  resetGen = 0,
82
85
  canvasId,
@@ -176,6 +179,40 @@ function CalcFlowInner({
176
179
  focusId,
177
180
  });
178
181
 
182
+ const boundsKey = useStore((s) => {
183
+ let out = '';
184
+ for (const node of s.nodeLookup.values()) {
185
+ const hb = node.internals?.handleBounds;
186
+ out +=
187
+ `${node.id}:` +
188
+ (hb?.source?.map((h) => h.id).join('+') ?? '') +
189
+ '/' +
190
+ (hb?.target?.map((h) => h.id).join('+') ?? '') +
191
+ '|';
192
+ }
193
+ return out;
194
+ });
195
+ const readyEdges = useMemo(() => {
196
+ const bounds = new Map<
197
+ string,
198
+ { src: Set<string | null>; tgt: Set<string | null> }
199
+ >();
200
+ for (const part of boundsKey.split('|')) {
201
+ if (!part) continue;
202
+ const [id, rest = ''] = part.split(':');
203
+ const [src = '', tgt = ''] = rest.split('/');
204
+ bounds.set(id, {
205
+ src: new Set(src ? src.split('+') : []),
206
+ tgt: new Set(tgt ? tgt.split('+') : []),
207
+ });
208
+ }
209
+ return edges.filter(
210
+ (e) =>
211
+ bounds.get(e.source)?.src.has(e.sourceHandle ?? null) &&
212
+ bounds.get(e.target)?.tgt.has(e.targetHandle ?? null),
213
+ );
214
+ }, [edges, boundsKey]);
215
+
179
216
  const [prevCanvasId, setPrevCanvasId] = useState(canvasId);
180
217
  if (prevCanvasId !== canvasId) {
181
218
  setPrevCanvasId(canvasId);
@@ -217,6 +254,7 @@ function CalcFlowInner({
217
254
  return (
218
255
  <CalcSessionProvider value={session}>
219
256
  <CalcFarProvider value={farCards}>
257
+ <CalcRecipeIdsProvider value={recipeIds}>
220
258
  <CalcTierProvider value={tier}>
221
259
  <FlowCanvas<AnyCalcFlowNode>
222
260
  shellProps={shellProps}
@@ -227,7 +265,7 @@ function CalcFlowInner({
227
265
  )}
228
266
 
229
267
  nodes={tier === 'dot' ? EMPTY_FLOW : nodes}
230
- edges={tier === 'dot' ? EMPTY_EDGES : edges}
268
+ edges={tier === 'dot' ? EMPTY_EDGES : readyEdges}
231
269
  extraRects={extraRects}
232
270
  fitNodes={fitRecipeNodes}
233
271
  nodeTypes={nodeTypes}
@@ -271,6 +309,8 @@ function CalcFlowInner({
271
309
  onModeChange={onModeChange}
272
310
  farCards={farCards}
273
311
  onFarCardsChange={onFarCardsChange}
312
+ recipeIds={recipeIds}
313
+ onRecipeIdsChange={onRecipeIdsChange}
274
314
  />
275
315
  {schemeNodes.length ? (
276
316
  ready ? null : (
@@ -298,6 +338,7 @@ function CalcFlowInner({
298
338
  onCloseDemand={closeDemand}
299
339
  />
300
340
  </CalcTierProvider>
341
+ </CalcRecipeIdsProvider>
301
342
  </CalcFarProvider>
302
343
  </CalcSessionProvider>
303
344
  );