@terrafirmagreg-team/recipe 1.2.43 → 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 (54) hide show
  1. package/package.json +4 -3
  2. package/src/components/cards/calc-add-item.tsx +2 -1
  3. package/src/components/views/browser/frame.tsx +36 -9
  4. package/src/components/views/browser/query-controls.tsx +6 -1
  5. package/src/components/views/browser/type-view.tsx +21 -2
  6. package/src/components/views/calc/calculator/help.tsx +6 -6
  7. package/src/components/views/calc/calculator/index.tsx +29 -6
  8. package/src/components/views/calc/edge.tsx +197 -113
  9. package/src/components/views/calc/flow/index.tsx +120 -39
  10. package/src/components/views/calc/flow/notes.tsx +282 -0
  11. package/src/components/views/calc/flow/toolbar.tsx +46 -1
  12. package/src/components/views/calc/flow/view-menu.tsx +11 -0
  13. package/src/components/views/calc/material-picker.tsx +112 -0
  14. package/src/components/views/calc/node-card/badges.tsx +2 -2
  15. package/src/components/views/calc/node-card/full.tsx +13 -2
  16. package/src/components/views/calc/node-card/menu.tsx +0 -17
  17. package/src/components/views/calc/node-card/port-cells.tsx +4 -4
  18. package/src/components/views/calc/node-card/ports.tsx +6 -1
  19. package/src/components/views/calc/recipe-picker/body.tsx +21 -5
  20. package/src/components/views/calc/recipe-picker/footer.tsx +1 -28
  21. package/src/hooks/calc/flow/use-handlers.ts +21 -14
  22. package/src/hooks/calc/flow/use-layout.ts +7 -7
  23. package/src/hooks/calc/flow/use-shift-held.ts +25 -0
  24. package/src/hooks/calc/use-actions.ts +126 -61
  25. package/src/hooks/calc/use-amounts.ts +8 -5
  26. package/src/hooks/calc/use-data.ts +11 -8
  27. package/src/hooks/calc/use-history.ts +98 -0
  28. package/src/hooks/calc/use-pipe-edit.ts +21 -0
  29. package/src/hooks/calc/use-snap.ts +17 -0
  30. package/src/hooks/calc/use-storage.ts +2 -1
  31. package/src/hooks/use-add-to-calc.ts +2 -1
  32. package/src/hooks/use-item-press.ts +4 -2
  33. package/src/hooks/use-query.ts +22 -1
  34. package/src/hooks/use-session.ts +2 -0
  35. package/src/lib/browser/row-search.test.ts +55 -0
  36. package/src/lib/browser/row-search.ts +24 -0
  37. package/src/lib/calc/flow.ts +31 -26
  38. package/src/lib/calc/member.test.ts +5 -5
  39. package/src/lib/calc/pack.ts +6 -6
  40. package/src/lib/calc/{wire.test.ts → pipe.test.ts} +5 -5
  41. package/src/lib/calc/{wire.ts → pipe.ts} +9 -9
  42. package/src/lib/calc/route/index.ts +1 -0
  43. package/src/lib/calc/scheme.test.ts +7 -7
  44. package/src/lib/calc/scheme.ts +16 -15
  45. package/src/lib/calc/storage/entry.test.ts +66 -0
  46. package/src/lib/calc/storage/entry.ts +29 -7
  47. package/src/lib/calc/storage/store.ts +3 -1
  48. package/src/lib/calc/tree/share.test.ts +102 -0
  49. package/src/lib/calc/tree/share.ts +43 -13
  50. package/src/lib/links.ts +3 -0
  51. package/src/types/calc-flow-props.ts +13 -2
  52. package/src/types/calc.ts +23 -3
  53. package/src/types/index.ts +3 -0
  54. package/styles/calc.css +65 -39
@@ -16,6 +16,11 @@ import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browse
16
16
  import { RecipeCardGrid } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
17
17
  import { recipeCardFitDim } from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
18
18
  import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
19
+ import {
20
+ rowMatchesTerms,
21
+ rowSearchTerms,
22
+ } from '@terrafirmagreg-team/recipe/lib/browser/row-search';
23
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
19
24
  import { PlaceHeader } from '@terrafirmagreg-team/recipe/components/views/browser/place-header';
20
25
  import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
21
26
  import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
@@ -28,7 +33,6 @@ export function PickerBody({
28
33
  onSelectRecipe,
29
34
  onSelectTagMember,
30
35
  recipeDefaults,
31
- onSetRecipeDefault,
32
36
  actions,
33
37
  close,
34
38
  }: {
@@ -52,6 +56,7 @@ export function PickerBody({
52
56
  const [tab, setTab] = useState<string | null>(null);
53
57
  const [page, setPage] = useState(0);
54
58
  const [pinned, setPinned] = useState(true);
59
+ const [query, setQuery] = useState('');
55
60
  const recipeKey = `${node.materialId}${node.recipe?.recipeId ?? ''}`;
56
61
  const [seenRecipeKey, setSeenRecipeKey] = useState(recipeKey);
57
62
  if (seenRecipeKey !== recipeKey) {
@@ -59,6 +64,7 @@ export function PickerBody({
59
64
  setTab(null);
60
65
  setPinned(true);
61
66
  setPage(0);
67
+ setQuery('');
62
68
  }
63
69
  const defaultRecipeId = recipeDefaults[node.materialId];
64
70
  const active =
@@ -69,16 +75,24 @@ export function PickerBody({
69
75
  recipes.find((row) => row.recipeId === defaultRecipeId)?.category ??
70
76
  categories[0]);
71
77
  const categoriesById = useCategoriesById(index);
78
+ const terms = useMemo(() => rowSearchTerms(query), [query]);
72
79
  const rows = useMemo(
73
80
  () =>
74
81
  recipes
75
- .filter((row) => row.category === active)
82
+ .filter(
83
+ (row) =>
84
+ row.category === active &&
85
+ (!terms.length ||
86
+ rowMatchesTerms(row.row, terms, (id) =>
87
+ recipeItemName(session.names, lang, id),
88
+ )),
89
+ )
76
90
  .sort((a, b) =>
77
91
  (b.recipeId === defaultRecipeId ? 1 : 0) -
78
92
  (a.recipeId === defaultRecipeId ? 1 : 0),
79
93
  )
80
94
  .map((row) => row.row),
81
- [recipes, active, defaultRecipeId],
95
+ [recipes, active, terms, defaultRecipeId, session.names, lang],
82
96
  );
83
97
  const boxRef = useRef<HTMLDivElement | null>(null);
84
98
  const focusIndex = rows.findIndex(
@@ -109,6 +123,8 @@ export function PickerBody({
109
123
  const frameSession = {
110
124
  ...session,
111
125
  place: active ? { kind: 'type' as const, id: active } : session.place,
126
+ rquery: query,
127
+ setRquery: setQuery,
112
128
  };
113
129
  const gridSession = { ...frameSession, recipeId: node.recipe?.recipeId };
114
130
 
@@ -178,6 +194,8 @@ export function PickerBody({
178
194
  />
179
195
  }
180
196
  onPageChange={goPage}
197
+ search
198
+ searchPersist={false}
181
199
  >
182
200
  <RecipeCardGrid
183
201
  session={gridSession}
@@ -204,8 +222,6 @@ export function PickerBody({
204
222
  dataset={dataset}
205
223
  lang={lang}
206
224
  langMap={langMap}
207
- recipeDefaults={recipeDefaults}
208
- onSetRecipeDefault={onSetRecipeDefault}
209
225
  onSelectTagMember={onSelectTagMember}
210
226
  />
211
227
  </>
@@ -6,8 +6,6 @@ import { ListFilter } from 'lucide-react';
6
6
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
7
7
  import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
8
8
  import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
9
- import { Checkbox } from '@terrafirmagreg-team/ui/components/ui/checkbox';
10
- import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
11
9
  import { formatCount } from '@terrafirmagreg-team/ui/lib/utils/format';
12
10
  import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
13
11
  import { CalcMemberList } from '@terrafirmagreg-team/recipe/components/views/calc/member-picker';
@@ -20,8 +18,6 @@ export function PickerFooter({
20
18
  dataset,
21
19
  lang,
22
20
  langMap,
23
- recipeDefaults,
24
- onSetRecipeDefault,
25
21
  onSelectTagMember,
26
22
  }: {
27
23
  node: CalcFlowData['node'];
@@ -29,15 +25,13 @@ export function PickerFooter({
29
25
  dataset: DatasetRef;
30
26
  lang: Lang;
31
27
  langMap?: Record<string, string>;
32
- recipeDefaults: CalcFlowData['recipeDefaults'];
33
- onSetRecipeDefault: CalcFlowData['onSetRecipeDefault'];
34
28
  onSelectTagMember: CalcFlowData['onSelectTagMember'];
35
29
  }) {
36
30
  const t = useTranslations();
37
31
  const [memberPickerOpen, setMemberPickerOpen] = useState(false);
38
32
  return (
39
33
  <>
40
- {members || node.recipe ? (
34
+ {members ? (
41
35
  <div className="flex shrink-0 items-center gap-2 rounded-md border border-border bg-card px-2 py-1.5">
42
36
  {members ? (
43
37
  <>
@@ -72,27 +66,6 @@ export function PickerFooter({
72
66
  </Button>
73
67
  </>
74
68
  ) : null}
75
- {node.recipe ? (
76
- <label
77
- className={cn(
78
- 'flex shrink-0 cursor-pointer select-none items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground',
79
- members ? 'ms-auto' : 'w-full',
80
- )}
81
- >
82
- <Checkbox
83
- checked={
84
- recipeDefaults[node.materialId] === node.recipe.recipeId
85
- }
86
- onCheckedChange={(checked) =>
87
- onSetRecipeDefault(
88
- node.materialId,
89
- checked ? node.recipe!.recipeId : null,
90
- )
91
- }
92
- />
93
- {t('Pin as default recipe', { note: 'recipe.calc.set_default' })}
94
- </label>
95
- ) : null}
96
69
  </div>
97
70
  ) : null}
98
71
  {memberPickerOpen && members ? (
@@ -27,6 +27,8 @@ export function useFlowHandlers({
27
27
  applyEngaged,
28
28
  centerOnNode,
29
29
  setPickerNode,
30
+ openPipeEdit,
31
+ closePipeEdit,
30
32
  }: {
31
33
  data: Omit<
32
34
  CalcFlowData,
@@ -36,6 +38,8 @@ export function useFlowHandlers({
36
38
  applyEngaged: (id: string | null) => void;
37
39
  centerOnNode: (node: AnyCalcFlowNode) => void;
38
40
  setPickerNode: (node: CalcNode | null) => void;
41
+ openPipeEdit: (edgeId: string) => void;
42
+ closePipeEdit: () => void;
39
43
  }) {
40
44
  const { screenToFlowPosition, getNode } = useReactFlow();
41
45
  const slotAccepts = useCallback(
@@ -81,10 +85,10 @@ export function useFlowHandlers({
81
85
  },
82
86
  [setPickerNode],
83
87
  );
84
- const handlePaneClick = useCallback(
85
- () => applyFocus(null),
86
- [applyFocus],
87
- );
88
+ const handlePaneClick = useCallback(() => {
89
+ applyFocus(null);
90
+ closePipeEdit();
91
+ }, [applyFocus, closePipeEdit]);
88
92
  const handleDragOver = useCallback((event: DragEvent) => {
89
93
  if (event.dataTransfer.types.includes('application/x-tfg-calc')) {
90
94
  event.preventDefault();
@@ -128,19 +132,19 @@ export function useFlowHandlers({
128
132
  const slot = tNode?.inputs[input];
129
133
  const srcOut = sNode?.outputs[out];
130
134
  if (!sNode || !tNode || !slotAccepts(slot, srcOut)) return;
131
- data.onWire(source, target, input, out);
135
+ data.onConnect(source, target, input, out);
132
136
  },
133
137
  [data, getNode, slotAccepts],
134
138
  );
135
139
 
136
140
  const handleReconnect = useCallback(
137
141
  (oldEdge: Edge, conn: Connection) => {
138
- const wire = oldEdge.data?.wire as
142
+ const pipe = oldEdge.data?.pipe as
139
143
  | { from: string; to: string; input: number; out?: number }
140
144
  | undefined;
141
145
  const input = Number(/^in-(\d+)$/.exec(conn.targetHandle ?? '')?.[1] ?? -1);
142
146
  const outMatch = /^out(?:-(\d+))?$/.exec(conn.sourceHandle ?? '');
143
- if (!wire || !conn.source || !conn.target || input < 0 || !outMatch)
147
+ if (!pipe || !conn.source || !conn.target || input < 0 || !outMatch)
144
148
  return;
145
149
  const out = Number(outMatch[1] ?? 0);
146
150
  if (conn.source === conn.target) return;
@@ -149,7 +153,7 @@ export function useFlowHandlers({
149
153
  const slot = tNode?.inputs[input];
150
154
  const srcOut = sNode?.outputs[out];
151
155
  if (!sNode || !tNode || !slotAccepts(slot, srcOut)) return;
152
- data.onRewire(wire.from, wire.to, wire.input, {
156
+ data.onReroute(pipe.from, pipe.to, pipe.input, {
153
157
  from: conn.source,
154
158
  to: conn.target,
155
159
  input,
@@ -162,10 +166,10 @@ export function useFlowHandlers({
162
166
  const handleEdgesDelete = useCallback(
163
167
  (edges: Edge[]) => {
164
168
  for (const edge of edges) {
165
- const wire = edge.data?.wire as
169
+ const pipe = edge.data?.pipe as
166
170
  | { from: string; to: string; input: number; out?: number }
167
171
  | undefined;
168
- if (wire) data.onUnwire(wire.from, wire.to, wire.input, wire.out);
172
+ if (pipe) data.onDisconnect(pipe.from, pipe.to, pipe.input, pipe.out);
169
173
  }
170
174
  },
171
175
  [data],
@@ -173,13 +177,16 @@ export function useFlowHandlers({
173
177
 
174
178
  const handleEdgeClick = useCallback(
175
179
  (event: MouseEvent, edge: Edge) => {
176
- if (!event.shiftKey) return;
177
- const wire = edge.data?.wire as
180
+ const pipe = edge.data?.pipe as
178
181
  | { from: string; to: string; input: number; out?: number }
179
182
  | undefined;
180
- if (wire) data.onUnwire(wire.from, wire.to, wire.input, wire.out);
183
+ if (event.shiftKey) {
184
+ if (pipe) data.onDisconnect(pipe.from, pipe.to, pipe.input, pipe.out);
185
+ return;
186
+ }
187
+ if (pipe) openPipeEdit(edge.id);
181
188
  },
182
- [data],
189
+ [data, openPipeEdit],
183
190
  );
184
191
 
185
192
  return {
@@ -13,12 +13,12 @@ import { layoutCards } from '@terrafirmagreg-team/recipe/lib/calc/pack';
13
13
  import type {
14
14
  CalcCard,
15
15
  CalcNode,
16
- CalcWire,
16
+ CalcPipe,
17
17
  } from '@terrafirmagreg-team/recipe/types/calc';
18
18
 
19
19
  export function useFlowLayout({
20
20
  nodes,
21
- wires,
21
+ pipes,
22
22
  flows,
23
23
  cards,
24
24
  data,
@@ -29,7 +29,7 @@ export function useFlowLayout({
29
29
  onRequestDemand,
30
30
  }: {
31
31
  nodes: CalcNode[];
32
- wires: CalcWire[];
32
+ pipes: CalcPipe[];
33
33
  flows?: readonly (number | undefined)[];
34
34
  cards: CalcCard[];
35
35
  data: Omit<
@@ -68,8 +68,8 @@ export function useFlowLayout({
68
68
  ],
69
69
  );
70
70
  const rawFlow = useMemo(
71
- () => cardsToFlow(nodes, wires, flowData, flows),
72
- [nodes, wires, flowData, flows],
71
+ () => cardsToFlow(nodes, pipes, flowData, flows),
72
+ [nodes, pipes, flowData, flows],
73
73
  );
74
74
 
75
75
  const storedPos = useMemo(() => {
@@ -97,12 +97,12 @@ export function useFlowLayout({
97
97
  }, [rawFlow, storedPos]);
98
98
 
99
99
  const relayout = useCallback(
100
- () => layoutCards(nodes, wires, {
100
+ () => layoutCards(nodes, pipes, {
101
101
  mode,
102
102
  gaps: GRID_GAPS,
103
103
  recipeBody: data.recipeBody,
104
104
  }),
105
- [nodes, wires, mode, data.recipeBody],
105
+ [nodes, pipes, mode, data.recipeBody],
106
106
  );
107
107
 
108
108
  return { rawFlow, positioned, relayout };
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+
5
+ export function useShiftHeld() {
6
+ const [held, setHeld] = useState(false);
7
+ useEffect(() => {
8
+ const down = (e: KeyboardEvent) => {
9
+ if (e.key === 'Shift') setHeld(true);
10
+ };
11
+ const up = (e: KeyboardEvent) => {
12
+ if (e.key === 'Shift') setHeld(false);
13
+ };
14
+ const blur = () => setHeld(false);
15
+ window.addEventListener('keydown', down);
16
+ window.addEventListener('keyup', up);
17
+ window.addEventListener('blur', blur);
18
+ return () => {
19
+ window.removeEventListener('keydown', down);
20
+ window.removeEventListener('keyup', up);
21
+ window.removeEventListener('blur', blur);
22
+ };
23
+ }, []);
24
+ return held;
25
+ }