@terrafirmagreg-team/recipe 1.2.42 → 1.2.44

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 (57) hide show
  1. package/package.json +6 -5
  2. package/src/components/cards/calc-add-item.tsx +2 -1
  3. package/src/components/views/browser/frame.tsx +46 -42
  4. package/src/components/views/browser/query-controls.tsx +6 -1
  5. package/src/components/views/browser/type-tabs.tsx +5 -0
  6. package/src/components/views/browser/type-view.tsx +22 -39
  7. package/src/components/views/calc/calculator/help.tsx +6 -6
  8. package/src/components/views/calc/calculator/index.tsx +29 -6
  9. package/src/components/views/calc/edge.tsx +197 -113
  10. package/src/components/views/calc/flow/index.tsx +120 -39
  11. package/src/components/views/calc/flow/notes.tsx +282 -0
  12. package/src/components/views/calc/flow/toolbar.tsx +46 -1
  13. package/src/components/views/calc/flow/view-menu.tsx +11 -0
  14. package/src/components/views/calc/material-picker.tsx +112 -0
  15. package/src/components/views/calc/node-card/actions.tsx +1 -1
  16. package/src/components/views/calc/node-card/badges.tsx +3 -3
  17. package/src/components/views/calc/node-card/far.tsx +1 -1
  18. package/src/components/views/calc/node-card/full.tsx +14 -3
  19. package/src/components/views/calc/node-card/menu.tsx +0 -17
  20. package/src/components/views/calc/node-card/port-cells.tsx +4 -4
  21. package/src/components/views/calc/node-card/ports.tsx +6 -1
  22. package/src/components/views/calc/recipe-picker/body.tsx +22 -32
  23. package/src/components/views/calc/recipe-picker/footer.tsx +1 -28
  24. package/src/hooks/calc/flow/use-handlers.ts +21 -14
  25. package/src/hooks/calc/flow/use-layout.ts +7 -7
  26. package/src/hooks/calc/flow/use-shift-held.ts +25 -0
  27. package/src/hooks/calc/use-actions.ts +126 -61
  28. package/src/hooks/calc/use-amounts.ts +8 -5
  29. package/src/hooks/calc/use-data.ts +11 -8
  30. package/src/hooks/calc/use-history.ts +98 -0
  31. package/src/hooks/calc/use-pipe-edit.ts +21 -0
  32. package/src/hooks/calc/use-snap.ts +17 -0
  33. package/src/hooks/calc/use-storage.ts +2 -1
  34. package/src/hooks/use-add-to-calc.ts +2 -1
  35. package/src/hooks/use-item-press.ts +4 -2
  36. package/src/hooks/use-query.ts +22 -1
  37. package/src/hooks/use-session.ts +2 -0
  38. package/src/lib/browser/row-search.test.ts +55 -0
  39. package/src/lib/browser/row-search.ts +24 -0
  40. package/src/lib/calc/flow.ts +31 -26
  41. package/src/lib/calc/member.test.ts +5 -5
  42. package/src/lib/calc/pack.ts +6 -6
  43. package/src/lib/calc/{wire.test.ts → pipe.test.ts} +5 -5
  44. package/src/lib/calc/{wire.ts → pipe.ts} +9 -9
  45. package/src/lib/calc/route/index.ts +1 -0
  46. package/src/lib/calc/scheme.test.ts +7 -7
  47. package/src/lib/calc/scheme.ts +16 -15
  48. package/src/lib/calc/storage/entry.test.ts +66 -0
  49. package/src/lib/calc/storage/entry.ts +29 -7
  50. package/src/lib/calc/storage/store.ts +3 -1
  51. package/src/lib/calc/tree/share.test.ts +102 -0
  52. package/src/lib/calc/tree/share.ts +43 -13
  53. package/src/lib/links.ts +3 -0
  54. package/src/types/calc-flow-props.ts +13 -2
  55. package/src/types/calc.ts +23 -3
  56. package/src/types/index.ts +3 -0
  57. package/styles/calc.css +65 -39
@@ -0,0 +1,282 @@
1
+ 'use client';
2
+
3
+ import { useRef, useState } from 'react';
4
+ import {
5
+ ViewportPortal,
6
+ useStore,
7
+ } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
8
+ import { Palette, X } from 'lucide-react';
9
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
10
+ import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
11
+ import {
12
+ Popover,
13
+ PopoverContent,
14
+ PopoverTrigger,
15
+ } from '@terrafirmagreg-team/ui/components/ui/popover';
16
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
17
+ import { CORNER_BUTTON } from '@terrafirmagreg-team/recipe/components/views/calc/node-card/actions';
18
+ import {
19
+ CALC_NOTE_COLORS,
20
+ type CalcNote,
21
+ type CalcNoteColor,
22
+ } from '@terrafirmagreg-team/recipe/types/calc';
23
+ import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
24
+
25
+ const GRID = 16;
26
+
27
+ const NOTE_STYLES: Record<
28
+ CalcNoteColor,
29
+ { card: string; placeholder: string; swatch: string }
30
+ > = {
31
+ amber: {
32
+ card: 'border-amber-400/70 bg-amber-100/95 text-amber-950 dark:border-amber-500/40 dark:bg-amber-950/90 dark:text-amber-50',
33
+ placeholder:
34
+ 'placeholder:text-amber-900/50 dark:placeholder:text-amber-100/40',
35
+ swatch: 'bg-amber-400',
36
+ },
37
+ slate: {
38
+ card: 'border-slate-400/70 bg-slate-100/95 text-slate-950 dark:border-slate-500/40 dark:bg-slate-800/90 dark:text-slate-50',
39
+ placeholder:
40
+ 'placeholder:text-slate-900/50 dark:placeholder:text-slate-100/40',
41
+ swatch: 'bg-slate-400',
42
+ },
43
+ sky: {
44
+ card: 'border-sky-400/70 bg-sky-100/95 text-sky-950 dark:border-sky-500/40 dark:bg-sky-950/90 dark:text-sky-50',
45
+ placeholder: 'placeholder:text-sky-900/50 dark:placeholder:text-sky-100/40',
46
+ swatch: 'bg-sky-400',
47
+ },
48
+ emerald: {
49
+ card: 'border-emerald-400/70 bg-emerald-100/95 text-emerald-950 dark:border-emerald-500/40 dark:bg-emerald-950/90 dark:text-emerald-50',
50
+ placeholder:
51
+ 'placeholder:text-emerald-900/50 dark:placeholder:text-emerald-100/40',
52
+ swatch: 'bg-emerald-400',
53
+ },
54
+ rose: {
55
+ card: 'border-rose-400/70 bg-rose-100/95 text-rose-950 dark:border-rose-500/40 dark:bg-rose-950/90 dark:text-rose-50',
56
+ placeholder:
57
+ 'placeholder:text-rose-900/50 dark:placeholder:text-rose-100/40',
58
+ swatch: 'bg-rose-400',
59
+ },
60
+ violet: {
61
+ card: 'border-violet-400/70 bg-violet-100/95 text-violet-950 dark:border-violet-500/40 dark:bg-violet-950/90 dark:text-violet-50',
62
+ placeholder:
63
+ 'placeholder:text-violet-900/50 dark:placeholder:text-violet-100/40',
64
+ swatch: 'bg-violet-400',
65
+ },
66
+ };
67
+
68
+ type NoteActions = Pick<
69
+ CalcFlowData,
70
+ 'onMoveCard' | 'onRemoveCard' | 'onEditNote' | 'onNoteColor'
71
+ >;
72
+
73
+ function CalcNoteCard({
74
+ note,
75
+ snap,
76
+ data,
77
+ }: {
78
+ note: CalcNote;
79
+ snap: boolean;
80
+ data: NoteActions;
81
+ }) {
82
+ const t = useTranslations();
83
+ const transform = useStore((s) => s.transform);
84
+ const zoom = transform[2];
85
+ const [drag, setDrag] = useState<{ x: number; y: number } | null>(null);
86
+ const [paletteOpen, setPaletteOpen] = useState(false);
87
+ const [seenTransform, setSeenTransform] = useState(transform);
88
+ if (seenTransform !== transform) {
89
+ setSeenTransform(transform);
90
+ setPaletteOpen(false);
91
+ }
92
+ const grab = useRef<{
93
+ pointerId: number;
94
+ sx: number;
95
+ sy: number;
96
+ px: number;
97
+ py: number;
98
+ } | null>(null);
99
+
100
+ const snapTo = (pos: { x: number; y: number }) =>
101
+ snap
102
+ ? { x: Math.round(pos.x / GRID) * GRID, y: Math.round(pos.y / GRID) * GRID }
103
+ : pos;
104
+
105
+ const pos = drag ?? note.pos;
106
+ const styles = NOTE_STYLES[note.color ?? 'amber'];
107
+
108
+ return (
109
+ <div
110
+ className="nodrag nopan nowheel pointer-events-auto absolute z-10"
111
+ style={{ left: pos.x, top: pos.y }}
112
+ >
113
+ <div
114
+ className={cn(
115
+ 'relative flex min-w-[180px] flex-col rounded-md border shadow-md',
116
+ styles.card,
117
+ )}
118
+ >
119
+ <span className="pointer-events-auto absolute -top-2.5 right-3 z-30 flex gap-0.5">
120
+ <Popover open={paletteOpen} onOpenChange={setPaletteOpen}>
121
+ <Hint
122
+ label={t('Note color', { note: 'recipe.calc.note_color' })}
123
+ side="top"
124
+ >
125
+ <PopoverTrigger
126
+ render={
127
+ <button
128
+ type="button"
129
+ aria-label={t('Note color', {
130
+ note: 'recipe.calc.note_color',
131
+ })}
132
+ onPointerDown={(e) => e.stopPropagation()}
133
+ className={CORNER_BUTTON}
134
+ />
135
+ }
136
+ >
137
+ <Palette className="size-2.5" />
138
+ </PopoverTrigger>
139
+ </Hint>
140
+ <PopoverContent
141
+ side="top"
142
+ align="end"
143
+ className="nodrag flex w-auto gap-1 p-1.5"
144
+ >
145
+ {CALC_NOTE_COLORS.map((color) => (
146
+ <button
147
+ key={color}
148
+ type="button"
149
+ aria-label={color}
150
+ aria-pressed={(note.color ?? 'amber') === color}
151
+ className={cn(
152
+ 'size-4 rounded-full border border-border/60 transition-transform hover:scale-110',
153
+ NOTE_STYLES[color].swatch,
154
+ (note.color ?? 'amber') === color &&
155
+ 'ring-2 ring-foreground/60 ring-offset-1 ring-offset-background',
156
+ )}
157
+ onClick={() => {
158
+ data.onNoteColor(note.id, color);
159
+ setPaletteOpen(false);
160
+ }}
161
+ />
162
+ ))}
163
+ </PopoverContent>
164
+ </Popover>
165
+ <Hint
166
+ label={t('Remove note', { note: 'recipe.calc.note_remove' })}
167
+ side="top"
168
+ >
169
+ <button
170
+ type="button"
171
+ aria-label={t('Remove note', {
172
+ note: 'recipe.calc.note_remove',
173
+ })}
174
+ onPointerDown={(e) => e.stopPropagation()}
175
+ onClick={(e) => {
176
+ e.stopPropagation();
177
+ data.onRemoveCard(note.id);
178
+ }}
179
+ className={cn(CORNER_BUTTON, 'hover:text-destructive')}
180
+ >
181
+ <X className="size-3" />
182
+ </button>
183
+ </Hint>
184
+ </span>
185
+ <div
186
+ role="button"
187
+ tabIndex={0}
188
+ aria-label={t('Move note', { note: 'recipe.calc.note_move' })}
189
+ className="flex cursor-grab touch-none items-center gap-1 px-1.5 py-0.5 active:cursor-grabbing"
190
+ onKeyDown={(e) => {
191
+ const d = { x: 0, y: 0 };
192
+ if (e.key === 'ArrowLeft') d.x = -GRID;
193
+ else if (e.key === 'ArrowRight') d.x = GRID;
194
+ else if (e.key === 'ArrowUp') d.y = -GRID;
195
+ else if (e.key === 'ArrowDown') d.y = GRID;
196
+ else return;
197
+ e.preventDefault();
198
+ data.onMoveCard(
199
+ note.id,
200
+ snapTo({ x: note.pos.x + d.x, y: note.pos.y + d.y }),
201
+ );
202
+ }}
203
+ onPointerDown={(e) => {
204
+ if (e.button !== 0) return;
205
+ e.preventDefault();
206
+ grab.current = {
207
+ pointerId: e.pointerId,
208
+ sx: e.clientX,
209
+ sy: e.clientY,
210
+ px: note.pos.x,
211
+ py: note.pos.y,
212
+ };
213
+ e.currentTarget.setPointerCapture(e.pointerId);
214
+ }}
215
+ onPointerMove={(e) => {
216
+ const g = grab.current;
217
+ if (!g || g.pointerId !== e.pointerId) return;
218
+ setDrag(
219
+ snapTo({
220
+ x: g.px + (e.clientX - g.sx) / zoom,
221
+ y: g.py + (e.clientY - g.sy) / zoom,
222
+ }),
223
+ );
224
+ }}
225
+ onPointerUp={(e) => {
226
+ const g = grab.current;
227
+ if (!g || g.pointerId !== e.pointerId) return;
228
+ grab.current = null;
229
+ const next = snapTo({
230
+ x: g.px + (e.clientX - g.sx) / zoom,
231
+ y: g.py + (e.clientY - g.sy) / zoom,
232
+ });
233
+ setDrag(null);
234
+ if (next.x !== note.pos.x || next.y !== note.pos.y) {
235
+ data.onMoveCard(note.id, next);
236
+ }
237
+ }}
238
+ onPointerCancel={() => {
239
+ grab.current = null;
240
+ setDrag(null);
241
+ }}
242
+ >
243
+ <span className="flex-1" />
244
+ </div>
245
+ <textarea
246
+ key={note.text}
247
+ defaultValue={note.text}
248
+ rows={3}
249
+ placeholder={t('Note…', { note: 'recipe.calc.note_placeholder' })}
250
+ className={cn(
251
+ 'nodrag nopan nowheel min-h-9 min-w-[180px] resize bg-transparent px-2 pb-1.5 text-xs leading-4 outline-none',
252
+ styles.placeholder,
253
+ )}
254
+ onPointerDown={(e) => e.stopPropagation()}
255
+ onBlur={(e) => {
256
+ const text = e.currentTarget.value;
257
+ if (text !== note.text) data.onEditNote(note.id, text);
258
+ }}
259
+ />
260
+ </div>
261
+ </div>
262
+ );
263
+ }
264
+
265
+ export function CalcNotes({
266
+ notes,
267
+ snap,
268
+ data,
269
+ }: {
270
+ notes: CalcNote[];
271
+ snap: boolean;
272
+ data: NoteActions;
273
+ }) {
274
+ if (!notes.length) return null;
275
+ return (
276
+ <ViewportPortal>
277
+ {notes.map((note) => (
278
+ <CalcNoteCard key={note.id} note={note} snap={snap} data={data} />
279
+ ))}
280
+ </ViewportPortal>
281
+ );
282
+ }
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import type { ReactNode } from 'react';
4
- import { RotateCcw } from 'lucide-react';
4
+ import { Redo2, RotateCcw, StickyNote, Undo2 } from 'lucide-react';
5
5
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
6
  import {
7
7
  ViewerControls,
@@ -19,20 +19,31 @@ export function CalcToolbar({
19
19
  onRelayout,
20
20
  onZoomIn,
21
21
  onZoomOut,
22
+ onAddNote,
22
23
  actions,
24
+ history,
23
25
  ...view
24
26
  }: {
25
27
  onFit: () => void;
26
28
  onRelayout: () => void;
27
29
  onZoomIn: () => void;
28
30
  onZoomOut: () => void;
31
+ onAddNote?: () => void;
29
32
  actions?: ReactNode;
33
+ history?: {
34
+ canUndo: boolean;
35
+ canRedo: boolean;
36
+ onUndo: () => void;
37
+ onRedo: () => void;
38
+ };
30
39
  mode: CalcViewMode;
31
40
  onModeChange: (mode: CalcViewMode) => void;
32
41
  farCards: CalcFarMode;
33
42
  onFarCardsChange: (mode: CalcFarMode) => void;
34
43
  recipeIds: boolean;
35
44
  onRecipeIdsChange: (show: boolean) => void;
45
+ snap: boolean;
46
+ onSnapChange: (snap: boolean) => void;
36
47
  }) {
37
48
  const t = useTranslations();
38
49
  return (
@@ -40,6 +51,28 @@ export function CalcToolbar({
40
51
  <ViewerControls
41
52
  start={[
42
53
  <CalcViewMenu key="view" {...view} />,
54
+ ...(history
55
+ ? [
56
+ <IconButton
57
+ key="undo"
58
+ overlay
59
+ disabled={!history.canUndo}
60
+ label={t('Undo', { note: 'recipe.calc.undo' })}
61
+ onClick={history.onUndo}
62
+ >
63
+ <Undo2 className="size-3.5" />
64
+ </IconButton>,
65
+ <IconButton
66
+ key="redo"
67
+ overlay
68
+ disabled={!history.canRedo}
69
+ label={t('Redo', { note: 'recipe.calc.redo' })}
70
+ onClick={history.onRedo}
71
+ >
72
+ <Redo2 className="size-3.5" />
73
+ </IconButton>,
74
+ ]
75
+ : []),
43
76
  <IconButton
44
77
  key="relayout"
45
78
  overlay
@@ -48,6 +81,18 @@ export function CalcToolbar({
48
81
  >
49
82
  <RotateCcw className="size-3.5" />
50
83
  </IconButton>,
84
+ ...(onAddNote
85
+ ? [
86
+ <IconButton
87
+ key="note"
88
+ overlay
89
+ label={t('Add note', { note: 'recipe.calc.note_add' })}
90
+ onClick={onAddNote}
91
+ >
92
+ <StickyNote className="size-3.5" />
93
+ </IconButton>,
94
+ ]
95
+ : []),
51
96
  ]}
52
97
  zoom={{
53
98
  onZoomIn,
@@ -38,6 +38,8 @@ export function CalcViewMenu({
38
38
  onFarCardsChange,
39
39
  recipeIds,
40
40
  onRecipeIdsChange,
41
+ snap,
42
+ onSnapChange,
41
43
  }: {
42
44
  mode: CalcViewMode;
43
45
  onModeChange: (mode: CalcViewMode) => void;
@@ -45,6 +47,8 @@ export function CalcViewMenu({
45
47
  onFarCardsChange: (mode: CalcFarMode) => void;
46
48
  recipeIds: boolean;
47
49
  onRecipeIdsChange: (show: boolean) => void;
50
+ snap: boolean;
51
+ onSnapChange: (snap: boolean) => void;
48
52
  }) {
49
53
  const t = useTranslations();
50
54
  const modeLabels: Record<CalcViewMode, string> = {
@@ -116,6 +120,13 @@ export function CalcViewMenu({
116
120
  </>
117
121
  ) : null}
118
122
  <DropdownMenuSeparator />
123
+ <DropdownMenuCheckboxItem
124
+ className="whitespace-nowrap"
125
+ checked={snap}
126
+ onCheckedChange={(checked) => onSnapChange(checked === true)}
127
+ >
128
+ {t('Snap to grid', { note: 'recipe.calc.snap' })}
129
+ </DropdownMenuCheckboxItem>
119
130
  <DropdownMenuCheckboxItem
120
131
  className="whitespace-nowrap"
121
132
  checked={recipeIds}
@@ -0,0 +1,112 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { useMemo, useState } from 'react';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import {
7
+ CommandDialog,
8
+ CommandEmpty,
9
+ CommandGroup,
10
+ CommandInput,
11
+ CommandItem,
12
+ CommandList,
13
+ } from '@terrafirmagreg-team/ui/components/ui/command';
14
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
15
+ import { stackDisplayName } from '@terrafirmagreg-team/game/lib/entry/display';
16
+ import type { RecipeCompactIndex } from '@terrafirmagreg-team/recipe/types';
17
+ import type { CalcKind } from '@terrafirmagreg-team/recipe/types/calc';
18
+
19
+ const PAGE = 80;
20
+
21
+ export function CalcMaterialPicker({
22
+ open,
23
+ onOpenChange,
24
+ index,
25
+ dataset,
26
+ lang,
27
+ langMap,
28
+ onSelect,
29
+ }: {
30
+ open: boolean;
31
+ onOpenChange: (open: boolean) => void;
32
+ index: RecipeCompactIndex | null;
33
+ dataset: DatasetRef;
34
+ lang: string;
35
+ langMap?: Record<string, string>;
36
+ onSelect: (id: string, kind: CalcKind) => void;
37
+ }) {
38
+ const t = useTranslations();
39
+ const [query, setQuery] = useState('');
40
+ const materials = useMemo(() => {
41
+ const fluids = new Set(index?.fluids ?? []);
42
+ const out: { id: string; kind: CalcKind; name: string }[] = [];
43
+ for (const id of index?.usedIds ?? []) {
44
+ if (id.startsWith('#')) continue;
45
+ out.push({
46
+ id,
47
+ kind: fluids.has(id) ? 'fluid' : 'item',
48
+ name: stackDisplayName(langMap, id),
49
+ });
50
+ }
51
+ out.sort((a, b) => a.name.localeCompare(b.name, lang.replace('_', '-')));
52
+ return out;
53
+ }, [index, langMap, lang]);
54
+ const shown = useMemo(() => {
55
+ const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
56
+ const hits = terms.length
57
+ ? materials.filter((m) =>
58
+ terms.every(
59
+ (term) =>
60
+ m.id.toLowerCase().includes(term) ||
61
+ m.name.toLowerCase().includes(term),
62
+ ),
63
+ )
64
+ : materials;
65
+ return hits.slice(0, PAGE);
66
+ }, [materials, query]);
67
+ return (
68
+ <CommandDialog
69
+ open={open}
70
+ onOpenChange={onOpenChange}
71
+ title={t('Add card', { note: 'recipe.calc.add.goal' })}
72
+ description={t('Add card', { note: 'recipe.calc.add.goal' })}
73
+ className="sm:max-w-md"
74
+ commandProps={{ shouldFilter: false }}
75
+ >
76
+ <CommandInput
77
+ value={query}
78
+ onValueChange={setQuery}
79
+ placeholder={t('Search materials', { note: 'recipe.search_materials' })}
80
+ />
81
+ <CommandList>
82
+ <CommandEmpty>
83
+ {t('No results found', { note: 'recipe.search_empty' })}
84
+ </CommandEmpty>
85
+ <CommandGroup>
86
+ {shown.map((mat) => (
87
+ <CommandItem
88
+ key={mat.id}
89
+ value={mat.id}
90
+ onSelect={() => {
91
+ onSelect(mat.id, mat.kind);
92
+ onOpenChange(false);
93
+ }}
94
+ >
95
+ <Entry
96
+ id={mat.id}
97
+ kind={mat.kind}
98
+ dataset={dataset}
99
+ lang={lang}
100
+ langMap={langMap}
101
+ size="sm"
102
+ labeled
103
+ href={false}
104
+ tooltip="adaptive"
105
+ />
106
+ </CommandItem>
107
+ ))}
108
+ </CommandGroup>
109
+ </CommandList>
110
+ </CommandDialog>
111
+ );
112
+ }
@@ -29,7 +29,7 @@ export function NodeActions({
29
29
  const canPick = node.recipe != null || node.availableRecipes.length > 0;
30
30
 
31
31
  return (
32
- <span className="pointer-events-auto absolute -top-2 right-3 z-30 flex gap-0.5">
32
+ <span className="pointer-events-auto absolute -top-2.5 right-3 z-30 flex gap-0.5">
33
33
  {canPick ? (
34
34
  <Hint label={t('Pick a recipe', { note: 'recipe.calc.pick.title' })} side="top">
35
35
  <button
@@ -46,10 +46,10 @@ export function NodeBadges({
46
46
  node.kind === 'fluid'
47
47
  ? formatFluidAmount
48
48
  : (n: number) => formatCount(n, 1_000);
49
- const overTip = t('Shortage: {wired} wired, only {produced} produced', {
49
+ const overTip = t('Shortage: {connected} connected, only {produced} produced', {
50
50
  note: 'recipe.calc.overdrawn',
51
51
  })
52
- .replaceAll('{wired}', fmtAmount(node.allocated))
52
+ .replaceAll('{connected}', fmtAmount(node.allocated))
53
53
  .replaceAll('{produced}', fmtAmount(node.produced));
54
54
  chips.push(
55
55
  <Hint key="over" label={overTip} side="top">
@@ -65,7 +65,7 @@ export function NodeBadges({
65
65
  }
66
66
  if (!chips.length) return null;
67
67
  return (
68
- <span className="pointer-events-auto absolute right-3 -bottom-1.5 z-30 flex flex-col-reverse items-end gap-0.5">
68
+ <span className="pointer-events-auto absolute right-3 -bottom-2 z-30 flex flex-col-reverse items-end gap-0.5">
69
69
  {chips}
70
70
  </span>
71
71
  );
@@ -91,7 +91,7 @@ export function CalcFarCard({ data, selected }: NodeProps<CalcFlowNode>) {
91
91
  event.stopPropagation();
92
92
  onRequestPicker(node);
93
93
  }}
94
- className={cn(CORNER_BUTTON, 'absolute -top-2 right-1')}
94
+ className={cn(CORNER_BUTTON, 'absolute -top-2.5 right-1')}
95
95
  >
96
96
  <ListFilter className="size-2.5" />
97
97
  </button>
@@ -145,7 +145,7 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
145
145
  node.kind === 'fluid'
146
146
  ? formatFluidAmount
147
147
  : (n: number) => formatCount(n, 1_000);
148
- const producedTip = t('Surplus: {produced} produced, {allocated} wired, {remaining} left', {
148
+ const producedTip = t('Surplus: {produced} produced, {allocated} connected, {remaining} left', {
149
149
  note: 'recipe.calc.hint.produced',
150
150
  })
151
151
  .replaceAll('{produced}', fmtAmount(node.produced))
@@ -297,6 +297,14 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
297
297
  aria-label={t('Crafts', { note: 'recipe.calc.crafts.title' })}
298
298
  className="w-auto min-w-9 rounded border border-border bg-transparent text-center tabular-nums focus:outline-none"
299
299
  onClick={(e) => e.stopPropagation()}
300
+ onWheel={(e) => {
301
+ e.stopPropagation();
302
+ if (document.activeElement !== e.currentTarget) return;
303
+ const step = e.shiftKey ? 10 : 1;
304
+ onCrafts(id, (crafts) =>
305
+ Math.max(1, crafts + (e.deltaY < 0 ? step : -step)),
306
+ );
307
+ }}
300
308
  onKeyDown={(e) => {
301
309
  if (e.key === 'Enter') e.currentTarget.blur();
302
310
  }}
@@ -411,7 +419,7 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
411
419
  />
412
420
  {interactive ? <NodeActions data={data} nodeId={id} /> : null}
413
421
  {showIds && body ? (
414
- <span className="nodrag absolute -bottom-2 left-3 z-30 flex">
422
+ <span className="nodrag absolute -bottom-2.5 left-3 z-30 flex">
415
423
  <span className="inline-flex max-w-full items-center gap-0.5 rounded-sm border border-border bg-background px-1 py-px shadow-sm">
416
424
  <code className="truncate text-[8px] leading-tight text-muted-foreground">
417
425
  {body.id}
@@ -434,7 +442,10 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
434
442
  return (
435
443
  <HoverCard>
436
444
  <ContextMenu>
437
- <ContextMenuTrigger render={cardBody} />
445
+ <ContextMenuTrigger
446
+ render={cardBody}
447
+ onContextMenu={(e) => e.stopPropagation()}
448
+ />
438
449
  <NodeContextMenu data={data} lang={lang} langMap={langMap} />
439
450
  </ContextMenu>
440
451
  {hoverCard ? (
@@ -12,7 +12,6 @@ import {
12
12
  PinOff,
13
13
  Plus,
14
14
  Shapes,
15
- Target,
16
15
  Undo2,
17
16
  } from 'lucide-react';
18
17
  import {
@@ -46,7 +45,6 @@ export function NodeContextMenu({
46
45
  const {
47
46
  node,
48
47
  dataset,
49
- onAddCard,
50
48
  onOpenItem,
51
49
  onSelectRecipe,
52
50
  onRequestPicker,
@@ -74,13 +72,6 @@ export function NodeContextMenu({
74
72
  </ContextMenuLabel>
75
73
  </ContextMenuGroup>
76
74
  <ContextMenuSeparator />
77
- <ContextMenuItem
78
- className="whitespace-nowrap"
79
- onClick={() => onAddCard(node.materialId, node.kind)}
80
- >
81
- <Target />
82
- {t('Add card', { note: 'recipe.calc.add.goal' })}
83
- </ContextMenuItem>
84
75
  <ContextMenuItem
85
76
  className="whitespace-nowrap"
86
77
  onClick={() => onOpenItem(node.materialId, node.kind)}
@@ -166,7 +157,6 @@ export function PortContextMenu({
166
157
  langMap?: Record<string, string>;
167
158
  }) {
168
159
  const {
169
- onAddCard,
170
160
  onOpenItem,
171
161
  onRequestPicker,
172
162
  onRequestSupply,
@@ -239,13 +229,6 @@ export function PortContextMenu({
239
229
  {t('Pick a recipe', { note: 'recipe.calc.pick.title' })}
240
230
  </ContextMenuItem>
241
231
  ) : null}
242
- <ContextMenuItem
243
- className="whitespace-nowrap"
244
- onClick={() => onAddCard(id, kind)}
245
- >
246
- <Target />
247
- {t('Add card', { note: 'recipe.calc.add.goal' })}
248
- </ContextMenuItem>
249
232
  <ContextMenuItem
250
233
  className="whitespace-nowrap"
251
234
  onClick={() => onOpenItem(id, kind)}
@@ -83,7 +83,7 @@ export function OutputCell({
83
83
  lang={lang}
84
84
  langMap={langMap}
85
85
  name={name}
86
- subheader={portAmountLine(count, out.kind)}
86
+ subheader={portAmountLine(count, out.kind, out.chance)}
87
87
  size="sm"
88
88
  href={false}
89
89
  tooltip="adaptive"
@@ -123,7 +123,7 @@ export function InputCell({
123
123
  const id = inp.id;
124
124
  const name = id ? recipeItemName(names, lang, id) : (inp.tagId ?? '?');
125
125
  const uncovered = Math.max(0, inp.amount - inp.covered);
126
- const state = inp.wired
126
+ const state = inp.connected
127
127
  ? uncovered <= 0
128
128
  ? 'full'
129
129
  : 'partial'
@@ -160,7 +160,7 @@ export function InputCell({
160
160
  lang={lang}
161
161
  langMap={langMap}
162
162
  name={name}
163
- subheader={portAmountLine(uncovered, inp.kind)}
163
+ subheader={portAmountLine(uncovered, inp.kind, inp.chance)}
164
164
  size="sm"
165
165
  href={false}
166
166
  tooltip="adaptive"
@@ -173,7 +173,7 @@ export function InputCell({
173
173
  lang={lang}
174
174
  langMap={langMap}
175
175
  name={name}
176
- subheader={portAmountLine(uncovered, inp.kind)}
176
+ subheader={portAmountLine(uncovered, inp.kind, inp.chance)}
177
177
  size="sm"
178
178
  href={false}
179
179
  tooltip="adaptive"