@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.
Files changed (221) hide show
  1. package/package.json +62 -3
  2. package/src/components/button-copy.tsx +43 -0
  3. package/src/components/cards/card/index.tsx +214 -0
  4. package/src/components/cards/card/scene.tsx +107 -0
  5. package/src/components/cards/card/strip.tsx +198 -0
  6. package/src/components/cards/card/text.tsx +46 -0
  7. package/src/components/cards/card/tips.tsx +63 -0
  8. package/src/components/cards/default-item.tsx +47 -0
  9. package/src/components/cards/glare-filter.tsx +29 -0
  10. package/src/components/cards/paged-card.tsx +222 -0
  11. package/src/components/cards/slot-hitbox.tsx +213 -0
  12. package/src/components/cards/strip-card/buttons.tsx +106 -0
  13. package/src/components/cards/strip-card/index.tsx +214 -0
  14. package/src/components/cards/strip-card/member-cell.tsx +167 -0
  15. package/src/components/cards/strip-card/sprite.tsx +36 -0
  16. package/src/components/embed-card.tsx +44 -0
  17. package/src/components/mdx/recipe.tsx +129 -0
  18. package/src/components/tool-list.tsx +49 -0
  19. package/src/components/tree.tsx +98 -0
  20. package/src/components/views/alloy/index.tsx +112 -0
  21. package/src/components/views/alloy/list.tsx +85 -0
  22. package/src/components/views/alloy/mix/index.tsx +35 -0
  23. package/src/components/views/alloy/mix/ratio.tsx +94 -0
  24. package/src/components/views/alloy/mix/rows.tsx +145 -0
  25. package/src/components/views/alloy/mix/status.tsx +122 -0
  26. package/src/components/views/alloy/mix/total.tsx +132 -0
  27. package/src/components/views/alloy/range-bar.tsx +65 -0
  28. package/src/components/views/alloy/stack-bar.tsx +88 -0
  29. package/src/components/views/browser/axis-switcher.tsx +54 -0
  30. package/src/components/views/browser/card-grid.tsx +275 -0
  31. package/src/components/views/browser/favorite-button.tsx +46 -0
  32. package/src/components/views/browser/frame.tsx +112 -0
  33. package/src/components/views/browser/index.tsx +114 -0
  34. package/src/components/views/browser/item-panel/index.tsx +229 -0
  35. package/src/components/views/browser/item-panel/skeleton.tsx +26 -0
  36. package/src/components/views/browser/item-panel-grid/cell.tsx +178 -0
  37. package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +129 -0
  38. package/src/components/views/browser/item-panel-grid/index.tsx +105 -0
  39. package/src/components/views/browser/item-view/index.tsx +186 -0
  40. package/src/components/views/browser/item-view/tags.tsx +85 -0
  41. package/src/components/views/browser/item-view-header.tsx +131 -0
  42. package/src/components/views/browser/pane-tabs.tsx +61 -0
  43. package/src/components/views/browser/place-header.tsx +72 -0
  44. package/src/components/views/browser/query-controls.tsx +105 -0
  45. package/src/components/views/browser/recipe-item-header.tsx +60 -0
  46. package/src/components/views/browser/settings.tsx +52 -0
  47. package/src/components/views/browser/toolbar.tsx +54 -0
  48. package/src/components/views/browser/type-tabs.tsx +71 -0
  49. package/src/components/views/browser/type-view.tsx +184 -0
  50. package/src/components/views/browser/workstation-rail.tsx +43 -0
  51. package/src/components/views/calc/calculator/actions.tsx +47 -0
  52. package/src/components/views/calc/calculator/help.tsx +189 -0
  53. package/src/components/views/calc/calculator/index.tsx +172 -0
  54. package/src/components/views/calc/dot-overlay.tsx +80 -0
  55. package/src/components/views/calc/edge.tsx +152 -0
  56. package/src/components/views/calc/flow/index.tsx +305 -0
  57. package/src/components/views/calc/flow/picker-dialogs.tsx +146 -0
  58. package/src/components/views/calc/flow/toolbar.tsx +60 -0
  59. package/src/components/views/calc/flow/view-menu.tsx +117 -0
  60. package/src/components/views/calc/member-picker.tsx +120 -0
  61. package/src/components/views/calc/node-card/actions.tsx +90 -0
  62. package/src/components/views/calc/node-card/badges.tsx +59 -0
  63. package/src/components/views/calc/node-card/chips.tsx +187 -0
  64. package/src/components/views/calc/node-card/far.tsx +123 -0
  65. package/src/components/views/calc/node-card/full.tsx +332 -0
  66. package/src/components/views/calc/node-card/index.tsx +27 -0
  67. package/src/components/views/calc/node-card/menu.tsx +282 -0
  68. package/src/components/views/calc/node-card/port-cells.tsx +186 -0
  69. package/src/components/views/calc/node-card/port-rails.tsx +251 -0
  70. package/src/components/views/calc/node-card/ports.tsx +86 -0
  71. package/src/components/views/calc/recipe-picker/body.tsx +207 -0
  72. package/src/components/views/calc/recipe-picker/footer.tsx +131 -0
  73. package/src/components/views/calc/recipe-picker/index.tsx +52 -0
  74. package/src/components/views/calc/sidebar.tsx +171 -0
  75. package/src/components/views/calc/trees/icon-picker.tsx +97 -0
  76. package/src/components/views/calc/trees/index.tsx +134 -0
  77. package/src/components/views/calc/trees/label.tsx +67 -0
  78. package/src/components/views/calc/trees/rows.tsx +140 -0
  79. package/src/components/views/forge/gui.tsx +131 -0
  80. package/src/components/views/forge/index.tsx +112 -0
  81. package/src/components/views/forge/list.tsx +113 -0
  82. package/src/components/views/forge/workbench/controls.tsx +103 -0
  83. package/src/components/views/forge/workbench/index.tsx +85 -0
  84. package/src/components/views/forge/workbench/panel.tsx +228 -0
  85. package/src/components/views/forge/workbench/ruler.tsx +133 -0
  86. package/src/components/views/forge/workbench/status.tsx +55 -0
  87. package/src/components/views/forge/workbench/tape.tsx +70 -0
  88. package/src/hooks/alloy/use-fluid-colors.ts +125 -0
  89. package/src/hooks/alloy/use-mix-state.ts +240 -0
  90. package/src/hooks/calc/flow/use-engage.ts +129 -0
  91. package/src/hooks/calc/flow/use-handlers.ts +192 -0
  92. package/src/hooks/calc/flow/use-layout.ts +105 -0
  93. package/src/hooks/calc/flow/use-mount.ts +97 -0
  94. package/src/hooks/calc/flow/use-nodes.ts +260 -0
  95. package/src/hooks/calc/flow/use-pickers.ts +57 -0
  96. package/src/hooks/calc/flow/use-viewport.ts +141 -0
  97. package/src/hooks/calc/flow/use-window.ts +87 -0
  98. package/src/hooks/calc/use-actions.ts +355 -0
  99. package/src/hooks/calc/use-amounts.ts +64 -0
  100. package/src/hooks/calc/use-data.ts +203 -0
  101. package/src/hooks/calc/use-defaults.ts +40 -0
  102. package/src/hooks/calc/use-far-mode.ts +37 -0
  103. package/src/hooks/calc/use-focus.ts +31 -0
  104. package/src/hooks/calc/use-maps.ts +76 -0
  105. package/src/hooks/calc/use-reset.ts +15 -0
  106. package/src/hooks/calc/use-resolver.ts +70 -0
  107. package/src/hooks/calc/use-session.ts +13 -0
  108. package/src/hooks/calc/use-share.ts +64 -0
  109. package/src/hooks/calc/use-storage.ts +126 -0
  110. package/src/hooks/calc/use-tier.ts +13 -0
  111. package/src/hooks/calc/use-view-mode.ts +24 -0
  112. package/src/hooks/calc/use-worker.ts +204 -0
  113. package/src/hooks/forge/use-anvil-gui.ts +16 -0
  114. package/src/hooks/forge/use-forge-state.ts +135 -0
  115. package/src/hooks/forge/use-ruler.ts +100 -0
  116. package/src/hooks/use-add-to-calc.ts +51 -0
  117. package/src/hooks/use-categories-by-id.ts +18 -0
  118. package/src/hooks/use-favorite-hotkey.ts +39 -0
  119. package/src/hooks/use-favorites.ts +135 -0
  120. package/src/hooks/use-group-outlines.ts +65 -0
  121. package/src/hooks/use-hide-unused.ts +12 -0
  122. package/src/hooks/use-index.ts +72 -0
  123. package/src/hooks/use-item-feeds.ts +46 -0
  124. package/src/hooks/use-item-pane.ts +106 -0
  125. package/src/hooks/use-item-press.ts +89 -0
  126. package/src/hooks/use-item-tag-groups.ts +54 -0
  127. package/src/hooks/use-item-tooltips.ts +18 -0
  128. package/src/hooks/use-left-sidebar-tree.ts +34 -0
  129. package/src/hooks/use-mod-names.ts +17 -0
  130. package/src/hooks/use-mount-limit.ts +22 -0
  131. package/src/hooks/use-panel-cells.ts +117 -0
  132. package/src/hooks/use-panel-page.ts +54 -0
  133. package/src/hooks/use-panel-tabs.ts +43 -0
  134. package/src/hooks/use-query.ts +186 -0
  135. package/src/hooks/use-session.ts +88 -0
  136. package/src/hooks/use-sidebar-group.ts +16 -0
  137. package/src/hooks/use-tag-members.ts +16 -0
  138. package/src/hooks/use-tool-recipes.ts +26 -0
  139. package/src/hooks/use-type-filter.ts +73 -0
  140. package/src/lib/alloy/mix.ts +210 -0
  141. package/src/lib/alloy/parse.ts +37 -0
  142. package/src/lib/calc/defaults.ts +47 -0
  143. package/src/lib/calc/flow.ts +315 -0
  144. package/src/lib/calc/focus.ts +15 -0
  145. package/src/lib/calc/meta.ts +17 -0
  146. package/src/lib/calc/pack.ts +77 -0
  147. package/src/lib/calc/ports.ts +43 -0
  148. package/src/lib/calc/resolve.ts +198 -0
  149. package/src/lib/calc/route/buckets.ts +49 -0
  150. package/src/lib/calc/route/geometry.ts +51 -0
  151. package/src/lib/calc/route/index.ts +3 -0
  152. package/src/lib/calc/route/polyline.ts +103 -0
  153. package/src/lib/calc/route/router.ts +394 -0
  154. package/src/lib/calc/scheme.ts +226 -0
  155. package/src/lib/calc/storage/entry.ts +97 -0
  156. package/src/lib/calc/storage/index.ts +20 -0
  157. package/src/lib/calc/storage/keys.ts +38 -0
  158. package/src/lib/calc/storage/store.ts +198 -0
  159. package/src/lib/calc/tree/index.ts +4 -0
  160. package/src/lib/calc/tree/materials.ts +29 -0
  161. package/src/lib/calc/tree/recipe.ts +104 -0
  162. package/src/lib/calc/tree/share.ts +135 -0
  163. package/src/lib/calc/worker/api.ts +25 -0
  164. package/src/lib/calc/worker/fetch.ts +66 -0
  165. package/src/lib/calc/worker/flush.ts +39 -0
  166. package/src/lib/calc/worker/index.ts +8 -0
  167. package/src/lib/calc/worker/protocol.ts +35 -0
  168. package/src/lib/calc/worker/resolve.ts +49 -0
  169. package/src/lib/calc/worker/state.ts +48 -0
  170. package/src/lib/card-model.ts +65 -0
  171. package/src/lib/client/recipe-categories.ts +14 -0
  172. package/src/lib/client/recipe.ts +85 -0
  173. package/src/lib/client-index/catalog.ts +91 -0
  174. package/src/lib/client-index/chrome.ts +180 -0
  175. package/src/lib/client-index/index.ts +20 -0
  176. package/src/lib/client-index/registry.ts +121 -0
  177. package/src/lib/client-index/rows.ts +260 -0
  178. package/src/lib/client-index/tooltips.ts +74 -0
  179. package/src/lib/config.ts +18 -0
  180. package/src/lib/data/category/dto.ts +25 -0
  181. package/src/lib/data/category/load.ts +47 -0
  182. package/src/lib/data/category/parse.ts +71 -0
  183. package/src/lib/data/dto.ts +152 -0
  184. package/src/lib/data/grid.ts +40 -0
  185. package/src/lib/data/parse/entry.ts +85 -0
  186. package/src/lib/data/parse/index.ts +3 -0
  187. package/src/lib/data/parse/layout.ts +138 -0
  188. package/src/lib/data/parse/slots.ts +85 -0
  189. package/src/lib/data/parse/widgets.ts +81 -0
  190. package/src/lib/data/scene.ts +103 -0
  191. package/src/lib/data/slot-io.ts +44 -0
  192. package/src/lib/dump.ts +6 -0
  193. package/src/lib/embed.ts +22 -0
  194. package/src/lib/favorite-hover.ts +13 -0
  195. package/src/lib/fluid-outputs.ts +70 -0
  196. package/src/lib/forge/actions.ts +59 -0
  197. package/src/lib/forge/data.ts +51 -0
  198. package/src/lib/forge/solve.ts +80 -0
  199. package/src/lib/group.ts +23 -0
  200. package/src/lib/index-store.ts +70 -0
  201. package/src/lib/links.ts +131 -0
  202. package/src/lib/lookup.ts +119 -0
  203. package/src/lib/panel-outline.ts +86 -0
  204. package/src/lib/panel.ts +105 -0
  205. package/src/lib/preview.ts +32 -0
  206. package/src/lib/recipe-slots.ts +8 -0
  207. package/src/lib/search.ts +139 -0
  208. package/src/lib/sidebar.ts +47 -0
  209. package/src/lib/used-items.ts +25 -0
  210. package/src/locales/en_us.json +172 -0
  211. package/src/locales/ru_ru.json +172 -0
  212. package/src/locales.ts +6 -0
  213. package/src/types/alloy.ts +20 -0
  214. package/src/types/calc-flow-props.ts +44 -0
  215. package/src/types/calc.ts +92 -0
  216. package/src/types/forge.ts +21 -0
  217. package/src/types/index.ts +136 -0
  218. package/styles/calc.css +308 -0
  219. package/styles/strip.css +7 -0
  220. package/styles.css +2 -0
  221. package/README.md +0 -3
@@ -0,0 +1,305 @@
1
+ 'use client';
2
+
3
+ import {
4
+ memo,
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from 'react';
11
+ import {
12
+ ReactFlowProvider,
13
+ useReactFlow,
14
+ useStore,
15
+ type Edge,
16
+ } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
17
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
18
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
19
+ import { FlowCanvas } from '@terrafirmagreg-team/ui/components/blocks/canvas/flow-canvas';
20
+ import {
21
+ CALC_LOD_DOT,
22
+ CALC_LOD_FAR,
23
+ type AnyCalcFlowNode,
24
+ } from '@terrafirmagreg-team/recipe/lib/calc/flow';
25
+ import { CalcNodeCard } from '@terrafirmagreg-team/recipe/components/views/calc/node-card';
26
+ import { CalcDotOverlay } from '@terrafirmagreg-team/recipe/components/views/calc/dot-overlay';
27
+ import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
28
+ import { CalcEdge } from '@terrafirmagreg-team/recipe/components/views/calc/edge';
29
+ import { CalcSessionProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-session';
30
+ import { CalcFarProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
31
+ import { CalcTierProvider } from '@terrafirmagreg-team/recipe/hooks/calc/use-tier';
32
+ import { useFlowPickers } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-pickers';
33
+ import { useFlowLayout } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-layout';
34
+ import { useFlowNodes } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-nodes';
35
+ import { useFlowViewport } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-viewport';
36
+ import { CalcToolbar } from '@terrafirmagreg-team/recipe/components/views/calc/flow/toolbar';
37
+ import { CalcPickers } from '@terrafirmagreg-team/recipe/components/views/calc/flow/picker-dialogs';
38
+ import { useFlowHandlers } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-handlers';
39
+ import type { CalcFlowProps } from '@terrafirmagreg-team/recipe/types/calc-flow-props';
40
+
41
+ const nodeTypes = { calcMaterial: CalcNodeCard };
42
+ const edgeTypes = { calcEdge: CalcEdge };
43
+ const EMPTY_FLOW: AnyCalcFlowNode[] = [];
44
+ const EMPTY_EDGES: Edge[] = [];
45
+
46
+ function useShiftHeld() {
47
+ const [held, setHeld] = useState(false);
48
+ useEffect(() => {
49
+ const down = (e: KeyboardEvent) => {
50
+ if (e.key === 'Shift') setHeld(true);
51
+ };
52
+ const up = (e: KeyboardEvent) => {
53
+ if (e.key === 'Shift') setHeld(false);
54
+ };
55
+ const blur = () => setHeld(false);
56
+ window.addEventListener('keydown', down);
57
+ window.addEventListener('keyup', up);
58
+ window.addEventListener('blur', blur);
59
+ return () => {
60
+ window.removeEventListener('keydown', down);
61
+ window.removeEventListener('keyup', up);
62
+ window.removeEventListener('blur', blur);
63
+ };
64
+ }, []);
65
+ return held;
66
+ }
67
+
68
+ function CalcFlowInner({
69
+ nodes: schemeNodes,
70
+ wires,
71
+ flows,
72
+ cards,
73
+ dataset,
74
+ session,
75
+ data,
76
+ mode,
77
+ onModeChange,
78
+ farCards,
79
+ onFarCardsChange,
80
+ treeReady = true,
81
+ resetGen = 0,
82
+ canvasId,
83
+ actions,
84
+ empty,
85
+ focusRef,
86
+ focusNodeId,
87
+ onFocusedNode,
88
+ onRelayout,
89
+ }: CalcFlowProps) {
90
+ const t = useTranslations();
91
+ const { zoomIn, zoomOut } = useReactFlow();
92
+ const shiftHeld = useShiftHeld();
93
+ const {
94
+ pickerNode,
95
+ setPickerNode,
96
+ memberNode,
97
+ setMemberNode,
98
+ supply,
99
+ setSupply,
100
+ onRequestPicker,
101
+ onRequestMemberPicker,
102
+ onRequestSupply,
103
+ } = useFlowPickers(schemeNodes);
104
+
105
+ const flowData = useMemo(
106
+ () => ({ ...data, onRequestSupply }),
107
+ [data, onRequestSupply],
108
+ );
109
+
110
+ const tier = useStore((s) =>
111
+ s.transform[2] < CALC_LOD_DOT
112
+ ? ('dot' as const)
113
+ : s.transform[2] < CALC_LOD_FAR
114
+ ? ('far' as const)
115
+ : ('near' as const),
116
+ );
117
+ const { rawFlow, positioned, relayout } = useFlowLayout({
118
+ nodes: schemeNodes,
119
+ wires,
120
+ flows,
121
+ cards,
122
+ data,
123
+ mode,
124
+ onRequestPicker,
125
+ onRequestMemberPicker,
126
+ onRequestSupply,
127
+ });
128
+ const focusIdRef = useRef<string | null>(null);
129
+ const [focusId, setFocusId] = useState<string | null>(null);
130
+ const applyFocus = useCallback((id: string | null) => {
131
+ if (focusIdRef.current === id) return;
132
+ focusIdRef.current = id;
133
+ setFocusId(id);
134
+ }, []);
135
+ const focusSeqRef = useRef<{ id: string; index: number } | null>(null);
136
+ const {
137
+ nodes,
138
+ edges,
139
+ mergedFlow,
140
+ extraRects,
141
+ onNodesChange,
142
+ onEdgesChange,
143
+ applyEngaged,
144
+ resetNodes,
145
+ } = useFlowNodes({
146
+ positioned,
147
+ shift: null,
148
+ data: flowData,
149
+ focusId,
150
+ focusIdRef,
151
+ rawFlow,
152
+ mode,
153
+ canvasId,
154
+ });
155
+ const {
156
+ ready,
157
+ centerOnNode,
158
+ handleMoveStart,
159
+ viewportConfig,
160
+ shellProps,
161
+ } = useFlowViewport({
162
+ mergedNodes: mergedFlow.nodes,
163
+ dataset,
164
+ resetGen,
165
+ treeReady,
166
+ mode,
167
+ applyFocus,
168
+ focusSeqRef,
169
+ focusRef,
170
+ focusNodeId,
171
+ onFocusedNode,
172
+ focusId,
173
+ });
174
+
175
+ const [prevCanvasId, setPrevCanvasId] = useState(canvasId);
176
+ if (prevCanvasId !== canvasId) {
177
+ setPrevCanvasId(canvasId);
178
+ resetNodes();
179
+ setPickerNode(null);
180
+ setMemberNode(null);
181
+ setSupply(null);
182
+ }
183
+
184
+ const {
185
+ handleNodeEnter,
186
+ handleNodeLeave,
187
+ handleNodeClick,
188
+ handleNodeDoubleClick,
189
+ handlePaneClick,
190
+ handleDragOver,
191
+ handleDrop,
192
+ handleConnect,
193
+ handleReconnect,
194
+ handleEdgesDelete,
195
+ handleEdgeClick,
196
+ fitRecipeNodes,
197
+ } = useFlowHandlers({
198
+ data: flowData,
199
+ applyFocus,
200
+ applyEngaged,
201
+ centerOnNode,
202
+ setPickerNode,
203
+ });
204
+ const closePicker = useCallback(() => setPickerNode(null), [setPickerNode]);
205
+ const closeMember = useCallback(() => setMemberNode(null), [setMemberNode]);
206
+ const closeSupply = useCallback(() => setSupply(null), [setSupply]);
207
+ const runRelayout = useCallback(() => {
208
+ onRelayout?.(relayout());
209
+ }, [onRelayout, relayout]);
210
+
211
+ return (
212
+ <CalcSessionProvider value={session}>
213
+ <CalcFarProvider value={farCards}>
214
+ <CalcTierProvider value={tier}>
215
+ <FlowCanvas<AnyCalcFlowNode>
216
+ shellProps={shellProps}
217
+ className={cn(
218
+ 'calc-flow h-full min-h-0 flex-1',
219
+ tier === 'dot' && 'calc-flow--dots',
220
+ shiftHeld && 'calc-flow--shift',
221
+ )}
222
+
223
+ nodes={tier === 'dot' ? EMPTY_FLOW : nodes}
224
+ edges={tier === 'dot' ? EMPTY_EDGES : edges}
225
+ extraRects={extraRects}
226
+ fitNodes={fitRecipeNodes}
227
+ nodeTypes={nodeTypes}
228
+ edgeTypes={edgeTypes}
229
+ onNodeMouseEnter={handleNodeEnter}
230
+ onNodeMouseLeave={handleNodeLeave}
231
+ onNodeClick={handleNodeClick}
232
+ onNodeDoubleClick={handleNodeDoubleClick}
233
+ onPaneClick={handlePaneClick}
234
+ onNodesChange={onNodesChange}
235
+ onEdgesChange={onEdgesChange}
236
+ onMoveStart={handleMoveStart}
237
+ onDragOver={handleDragOver}
238
+ onDrop={handleDrop}
239
+ onConnect={handleConnect}
240
+ onReconnect={handleReconnect}
241
+ edgesReconnectable={tier === 'near'}
242
+ onEdgeClick={handleEdgeClick}
243
+ onEdgesDelete={handleEdgesDelete}
244
+ deleteKeyCode={['Backspace', 'Delete']}
245
+ nodesDraggable={tier !== 'dot'}
246
+ nodesConnectable={tier === 'near'}
247
+ selectionKeyCode="Shift"
248
+ multiSelectionKeyCode={['Meta', 'Control']}
249
+ onlyRenderVisibleElements
250
+ minZoom={0.02}
251
+ viewportConfig={viewportConfig}
252
+ >
253
+ {({ onFit }) => (
254
+ <>
255
+ {tier === 'dot' ? (
256
+ <CalcDotOverlay nodes={mergedFlow.nodes} focusId={focusId} />
257
+ ) : null}
258
+ <CalcToolbar
259
+ onFit={onFit}
260
+ onRelayout={runRelayout}
261
+ onZoomIn={() => void zoomIn({ duration: 150 })}
262
+ onZoomOut={() => void zoomOut({ duration: 150 })}
263
+ actions={actions}
264
+ mode={mode}
265
+ onModeChange={onModeChange}
266
+ farCards={farCards}
267
+ onFarCardsChange={onFarCardsChange}
268
+ />
269
+ {schemeNodes.length ? (
270
+ ready ? null : (
271
+ <div className="pointer-events-none absolute inset-x-0 bottom-4 z-10 flex justify-center">
272
+ <EmptyState variant="loading">{t('Loading recipe…', { note: 'recipe.loading' })}</EmptyState>
273
+ </div>
274
+ )
275
+ ) : (
276
+ empty
277
+ )}
278
+ </>
279
+ )}
280
+ </FlowCanvas>
281
+ <CalcPickers
282
+ pickerNode={pickerNode}
283
+ memberNode={memberNode}
284
+ supply={supply}
285
+ session={session}
286
+ dataset={dataset}
287
+ data={data}
288
+ onClosePicker={closePicker}
289
+ onCloseMember={closeMember}
290
+ onCloseSupply={closeSupply}
291
+ />
292
+ </CalcTierProvider>
293
+ </CalcFarProvider>
294
+ </CalcSessionProvider>
295
+ );
296
+ }
297
+
298
+ export const CalcFlow = memo(function CalcFlow(props: CalcFlowProps) {
299
+ return (
300
+ <ReactFlowProvider>
301
+ <CalcFlowInner {...props} />
302
+ </ReactFlowProvider>
303
+ );
304
+ });
305
+
@@ -0,0 +1,146 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { Mountain } from 'lucide-react';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
7
+ import { CalcRecipePicker } from '@terrafirmagreg-team/recipe/components/views/calc/recipe-picker';
8
+ import { CalcMemberPicker } from '@terrafirmagreg-team/recipe/components/views/calc/member-picker';
9
+ import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
10
+ import type { SupplyRequest } from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-pickers';
11
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
12
+ import type { CalcNode } from '@terrafirmagreg-team/recipe/types/calc';
13
+
14
+ function SupplyPicker({
15
+ supply,
16
+ session,
17
+ data,
18
+ onClose,
19
+ }: {
20
+ supply: SupplyRequest;
21
+ session: RecipeSession;
22
+ data: Omit<
23
+ CalcFlowData,
24
+ 'node' | 'mode' | 'onRequestPicker' | 'onRequestMemberPicker' | 'onRequestSupply'
25
+ >;
26
+ onClose: () => void;
27
+ }) {
28
+ const t = useTranslations();
29
+ const { node, input } = supply;
30
+ const slot = node.inputs[input];
31
+ if (!slot?.id) return null;
32
+ const materialId = slot.id;
33
+ const recipes = data.getRecipesForItem(materialId, slot.kind);
34
+ const supplyNode: CalcNode = {
35
+ ...node,
36
+ materialId,
37
+ kind: slot.kind,
38
+ recipe: null,
39
+ availableRecipes: recipes,
40
+ tagId: undefined,
41
+ members: undefined,
42
+ inputs: [],
43
+ };
44
+ return (
45
+ <CalcRecipePicker
46
+ open
47
+ onOpenChange={(open) => {
48
+ if (!open) onClose();
49
+ }}
50
+ node={supplyNode}
51
+ session={session}
52
+ onSelectRecipe={(_cardId, recipeId) => {
53
+ const row = recipes.find((r) => r.recipeId === recipeId);
54
+ data.onSupplyInput(node.id, input, recipeId, row?.outputAmount);
55
+ }}
56
+ onSelectTagMember={data.onSelectTagMember}
57
+ recipeDefaults={data.recipeDefaults}
58
+ onSetRecipeDefault={data.onSetRecipeDefault}
59
+ actions={
60
+ <Button
61
+ size="xs"
62
+ variant="outline"
63
+ className={supplyNode.availableRecipes.length ? 'shrink-0' : 'ms-auto shrink-0'}
64
+ onClick={() => {
65
+ data.onSupplyInput(node.id, input, null);
66
+ onClose();
67
+ }}
68
+ >
69
+ <Mountain className="size-3.5" />
70
+ {t('Keep as external source', { note: 'recipe.calc.supply.source' })}
71
+ </Button>
72
+ }
73
+ />
74
+ );
75
+ }
76
+
77
+ export function CalcPickers({
78
+ pickerNode,
79
+ memberNode,
80
+ supply,
81
+ session,
82
+ dataset,
83
+ data,
84
+ onClosePicker,
85
+ onCloseMember,
86
+ onCloseSupply,
87
+ }: {
88
+ pickerNode: CalcNode | null;
89
+ memberNode: CalcNode | null;
90
+ supply: SupplyRequest | null;
91
+ session: RecipeSession;
92
+ dataset: DatasetRef;
93
+ data: Omit<
94
+ CalcFlowData,
95
+ 'node' | 'mode' | 'onRequestPicker' | 'onRequestMemberPicker' | 'onRequestSupply'
96
+ >;
97
+ onClosePicker: () => void;
98
+ onCloseMember: () => void;
99
+ onCloseSupply: () => void;
100
+ }) {
101
+ return (
102
+ <>
103
+ {pickerNode ? (
104
+ <CalcRecipePicker
105
+ open
106
+ onOpenChange={(open) => {
107
+ if (!open) onClosePicker();
108
+ }}
109
+ node={pickerNode}
110
+ session={session}
111
+ onSelectRecipe={(_materialId, recipeId) =>
112
+ data.onSelectRecipe(pickerNode.id, recipeId)
113
+ }
114
+ onSelectTagMember={data.onSelectTagMember}
115
+ recipeDefaults={data.recipeDefaults}
116
+ onSetRecipeDefault={data.onSetRecipeDefault}
117
+ />
118
+ ) : null}
119
+ {memberNode?.tagId && memberNode.members ? (
120
+ <CalcMemberPicker
121
+ open
122
+ onOpenChange={(open) => {
123
+ if (!open) onCloseMember();
124
+ }}
125
+ tagId={memberNode.tagId}
126
+ members={memberNode.members}
127
+ selected={memberNode.materialId}
128
+ memberKind={memberNode.kind}
129
+ dataset={dataset}
130
+ lang={session.lang}
131
+ langMap={session.langMap}
132
+ onSelect={data.onSelectTagMember}
133
+ />
134
+ ) : null}
135
+ {supply ? (
136
+ <SupplyPicker
137
+ supply={supply}
138
+ session={session}
139
+ data={data}
140
+ onClose={onCloseSupply}
141
+ />
142
+ ) : null}
143
+ </>
144
+ );
145
+ }
146
+
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+
3
+ import type { ReactNode } from 'react';
4
+ import { RotateCcw } from 'lucide-react';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import {
7
+ ViewerControls,
8
+ ViewerToolbar,
9
+ } from '@terrafirmagreg-team/ui/components/blocks/viewer/controls';
10
+ import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
11
+ import { CalcViewMenu } from './view-menu';
12
+ import type {
13
+ CalcFarMode,
14
+ CalcViewMode,
15
+ } from '@terrafirmagreg-team/recipe/lib/calc/flow';
16
+
17
+ export function CalcToolbar({
18
+ onFit,
19
+ onRelayout,
20
+ onZoomIn,
21
+ onZoomOut,
22
+ actions,
23
+ ...view
24
+ }: {
25
+ onFit: () => void;
26
+ onRelayout: () => void;
27
+ onZoomIn: () => void;
28
+ onZoomOut: () => void;
29
+ actions?: ReactNode;
30
+ mode: CalcViewMode;
31
+ onModeChange: (mode: CalcViewMode) => void;
32
+ farCards: CalcFarMode;
33
+ onFarCardsChange: (mode: CalcFarMode) => void;
34
+ }) {
35
+ const t = useTranslations();
36
+ return (
37
+ <ViewerToolbar>
38
+ <ViewerControls
39
+ start={[
40
+ <CalcViewMenu key="view" {...view} />,
41
+ <IconButton
42
+ key="relayout"
43
+ overlay
44
+ label={t('Auto layout', { note: 'recipe.calc.relayout' })}
45
+ onClick={onRelayout}
46
+ >
47
+ <RotateCcw className="size-3.5" />
48
+ </IconButton>,
49
+ ]}
50
+ zoom={{
51
+ onZoomIn,
52
+ onZoomOut,
53
+ onFit,
54
+ }}
55
+ extra={actions}
56
+ />
57
+ </ViewerToolbar>
58
+ );
59
+ }
60
+
@@ -0,0 +1,117 @@
1
+ 'use client';
2
+
3
+ import {
4
+ GalleryHorizontal,
5
+ LayoutGrid,
6
+ RectangleHorizontal,
7
+ Settings2,
8
+ } from 'lucide-react';
9
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
10
+ import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
11
+ import {
12
+ DropdownMenu,
13
+ DropdownMenuContent,
14
+ DropdownMenuLabel,
15
+ DropdownMenuRadioGroup,
16
+ DropdownMenuRadioItem,
17
+ DropdownMenuSeparator,
18
+ DropdownMenuTrigger,
19
+ } from '@terrafirmagreg-team/ui/components/ui/dropdown-menu';
20
+ import type {
21
+ CalcFarMode,
22
+ CalcViewMode,
23
+ } from '@terrafirmagreg-team/recipe/lib/calc/flow';
24
+
25
+ const MODE_ICONS = {
26
+ mini: LayoutGrid,
27
+ normal: RectangleHorizontal,
28
+ detailed: GalleryHorizontal,
29
+ } as const;
30
+
31
+ const FAR_MODES: CalcFarMode[] = ['full', 'preview', 'hidden'];
32
+
33
+ export function CalcViewMenu({
34
+ mode,
35
+ onModeChange,
36
+ farCards,
37
+ onFarCardsChange,
38
+ }: {
39
+ mode: CalcViewMode;
40
+ onModeChange: (mode: CalcViewMode) => void;
41
+ farCards: CalcFarMode;
42
+ onFarCardsChange: (mode: CalcFarMode) => void;
43
+ }) {
44
+ const t = useTranslations();
45
+ const modeLabels: Record<CalcViewMode, string> = {
46
+ mini: t('Compact view', { note: 'recipe.calc.mode.mini' }),
47
+ normal: t('Card view', { note: 'recipe.calc.mode.normal' }),
48
+ detailed: t('Recipe view', { note: 'recipe.calc.mode.detailed' }),
49
+ };
50
+ const farLabels: Record<CalcFarMode, string> = {
51
+ full: t('Full card', { note: 'recipe.calc.far.full' }),
52
+ preview: t('Preview', { note: 'recipe.calc.far.preview' }),
53
+ hidden: t('Hide', { note: 'recipe.calc.far.hidden' }),
54
+ };
55
+
56
+ return (
57
+ <DropdownMenu>
58
+ <DropdownMenuTrigger
59
+ render={<IconButton overlay label={t('View settings', { note: 'recipe.calc.view.title' })} />}
60
+ >
61
+ <Settings2 className="size-3.5" />
62
+ </DropdownMenuTrigger>
63
+ <DropdownMenuContent
64
+ side="bottom"
65
+ align="start"
66
+ className="w-fit min-w-48"
67
+ >
68
+ <DropdownMenuRadioGroup
69
+ value={mode}
70
+ onValueChange={(value) => onModeChange(value as CalcViewMode)}
71
+ >
72
+ <DropdownMenuLabel className="whitespace-nowrap">
73
+ {t('Cards', { note: 'recipe.calc.view.modes' })}
74
+ </DropdownMenuLabel>
75
+ {(Object.keys(MODE_ICONS) as CalcViewMode[]).map((value) => {
76
+ const ModeIcon = MODE_ICONS[value];
77
+ return (
78
+ <DropdownMenuRadioItem
79
+ key={value}
80
+ value={value}
81
+ className="whitespace-nowrap"
82
+ >
83
+ <ModeIcon className="size-4" />
84
+ {modeLabels[value]}
85
+ </DropdownMenuRadioItem>
86
+ );
87
+ })}
88
+ </DropdownMenuRadioGroup>
89
+ {mode === 'detailed' ? (
90
+ <>
91
+ <DropdownMenuSeparator />
92
+ <DropdownMenuRadioGroup
93
+ value={farCards}
94
+ onValueChange={(value) =>
95
+ onFarCardsChange(value as CalcFarMode)
96
+ }
97
+ >
98
+ <DropdownMenuLabel className="whitespace-nowrap">
99
+ {t('Cards when zoomed out', { note: 'recipe.calc.far.title' })}
100
+ </DropdownMenuLabel>
101
+ {FAR_MODES.map((value) => (
102
+ <DropdownMenuRadioItem
103
+ key={value}
104
+ value={value}
105
+ className="whitespace-nowrap"
106
+ >
107
+ {farLabels[value]}
108
+ </DropdownMenuRadioItem>
109
+ ))}
110
+ </DropdownMenuRadioGroup>
111
+ </>
112
+ ) : null}
113
+ </DropdownMenuContent>
114
+ </DropdownMenu>
115
+ );
116
+ }
117
+