@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,332 @@
1
+ 'use client';
2
+
3
+ import { memo, useEffect, useState } from 'react';
4
+ import { Minus, Plus } from 'lucide-react';
5
+ import {
6
+ useUpdateNodeInternals,
7
+ type NodeProps,
8
+ } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
9
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
10
+ import {
11
+ ContextMenu,
12
+ ContextMenuTrigger,
13
+ } from '@terrafirmagreg-team/ui/components/ui/context-menu';
14
+ import {
15
+ HoverCard,
16
+ HoverCardTrigger,
17
+ } from '@terrafirmagreg-team/ui/components/ui/hover-card';
18
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
19
+ import { StackCount } from '@terrafirmagreg-team/game/components/entry/stack-count';
20
+ import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
21
+ import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
22
+ import { useCalcSession } from '@terrafirmagreg-team/recipe/hooks/calc/use-session';
23
+ import { useCalcFar } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
24
+ import { useCalcTier } from '@terrafirmagreg-team/recipe/hooks/calc/use-tier';
25
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
26
+ import {
27
+ recipeCardImageUrl,
28
+ recipeImageUrl,
29
+ } from '@terrafirmagreg-team/recipe/lib/links';
30
+ import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
31
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
32
+ import { CALC_NODE_W } from '@terrafirmagreg-team/recipe/lib/calc/flow';
33
+ import { railSpans } from '@terrafirmagreg-team/recipe/lib/calc/ports';
34
+ import type { CalcFlowNode } from '@terrafirmagreg-team/recipe/lib/calc/flow';
35
+ import { NodeBadges } from './badges';
36
+ import { NodeChips } from './chips';
37
+ import { NodeActions } from './actions';
38
+ import { PortRailIn, PortRailOut } from './port-rails';
39
+ import { NodeContextMenu, NodeHoverContent } from './menu';
40
+
41
+ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
42
+ data,
43
+ id,
44
+ selected,
45
+ }: NodeProps<CalcFlowNode>) {
46
+ const {
47
+ node,
48
+ dataset,
49
+ mode,
50
+ recipeBody,
51
+ onRequestPicker,
52
+ onRequestMemberPicker,
53
+ onCrafts,
54
+ } = data;
55
+ const t = useTranslations();
56
+ const session = useCalcSession();
57
+ const farCards = useCalcFar();
58
+ const lang = session?.lang ?? 'en_us';
59
+ const names = session?.names ?? {};
60
+ const langMap = session?.langMap;
61
+ const tier = useCalcTier();
62
+ const lodOk = tier === 'near';
63
+ const [imgFail, setImgFail] = useState(false);
64
+ const name = recipeItemName(names, lang, node.materialId);
65
+ const recipes = node.availableRecipes;
66
+ const body = node.recipe ? recipeBody(node.recipe.recipeId) : undefined;
67
+ const src = body
68
+ ? (recipeImageUrl(dataset, body) ??
69
+ recipeCardImageUrl(dataset, body.id))
70
+ : undefined;
71
+ const lod = farCards === 'full' || lodOk;
72
+ const card = mode === 'detailed' && lod && body && src && !imgFail;
73
+
74
+ const hoverCard =
75
+ mode !== 'detailed' && body && src && !imgFail ? true : undefined;
76
+ const hasAlternatives =
77
+ recipes.length > 1 ||
78
+ (node.tagId != null && (node.members?.length ?? 0) > 1);
79
+ const category = node.recipe
80
+ ? session?.index?.categories?.find(
81
+ (row) =>
82
+ row.id ===
83
+ recipes.find((r) => r.recipeId === node.recipe!.recipeId)
84
+ ?.category,
85
+ )
86
+ : undefined;
87
+
88
+ const [prevSrc, setPrevSrc] = useState(src);
89
+ if (prevSrc !== src) {
90
+ setPrevSrc(src);
91
+ setImgFail(false);
92
+ }
93
+
94
+ const staged = !lodOk && card;
95
+ const [bodyReady, setBodyReady] = useState(false);
96
+ const [prevStaged, setPrevStaged] = useState(staged);
97
+ if (prevStaged !== staged) {
98
+ setPrevStaged(staged);
99
+ if (!staged) setBodyReady(false);
100
+ }
101
+ useEffect(() => {
102
+ if (!staged || bodyReady) return;
103
+ const id = setTimeout(() => setBodyReady(true), 0);
104
+ return () => clearTimeout(id);
105
+ }, [staged, bodyReady]);
106
+ const cardOn = card && (!staged || bodyReady);
107
+
108
+ useEffect(
109
+ () => () => {
110
+ railSpans.delete(id);
111
+ },
112
+ [id],
113
+ );
114
+
115
+ const skeleton =
116
+ mode === 'detailed' && node.recipe != null && !cardOn;
117
+ const stateCls = cn(
118
+ node.cycle && 'border-red-500/70',
119
+ !node.cycle && node.recipe && 'border-primary/60',
120
+ !node.recipe && 'border-dashed border-muted-foreground/50',
121
+ selected && 'ring-2 ring-primary/70',
122
+ );
123
+
124
+ const interactive = tier === 'near';
125
+ const updateNodeInternals = useUpdateNodeInternals();
126
+ useEffect(() => {
127
+ updateNodeInternals(id);
128
+ }, [
129
+ id,
130
+ updateNodeInternals,
131
+ mode,
132
+ interactive,
133
+ node.recipe?.recipeId,
134
+ node.inputs.length,
135
+ node.outputs.length,
136
+ ]);
137
+ const innerContent = (
138
+ <div
139
+ className={cn(
140
+ 'flex min-w-0 flex-1 flex-col justify-center gap-0.5 px-2 py-1',
141
+ mode === 'mini' ? 'items-center px-1.5' : '',
142
+ )}
143
+ >
144
+ {mode === 'mini' ? (
145
+ <div className="mx-3 flex w-auto flex-col items-center gap-0.5">
146
+ <Entry
147
+ id={node.materialId}
148
+ kind={node.kind}
149
+ dataset={dataset}
150
+ lang={lang}
151
+ langMap={langMap}
152
+ name={name}
153
+ size="lg"
154
+ href={false}
155
+ tooltip="adaptive"
156
+ badge={<StackCount count={node.produced} />}
157
+ />
158
+ <span className="w-full truncate px-0.5 text-center text-[9px] leading-tight text-muted-foreground">
159
+ {name}
160
+ </span>
161
+ <NodeChips
162
+ node={node}
163
+ mini
164
+ name={name}
165
+ category={category}
166
+ hasAlternatives={hasAlternatives}
167
+ dataset={dataset}
168
+ lang={lang}
169
+ langMap={langMap}
170
+ onRequestPicker={onRequestPicker}
171
+ onRequestMemberPicker={onRequestMemberPicker}
172
+ />
173
+ </div>
174
+ ) : (
175
+ <>
176
+ <div className="mx-1 flex min-w-0 items-center gap-1.5">
177
+ <Entry
178
+ id={node.materialId}
179
+ kind={node.kind}
180
+ dataset={dataset}
181
+ lang={lang}
182
+ langMap={langMap}
183
+ size="lg"
184
+ labeled
185
+ href={false}
186
+ tooltip="adaptive"
187
+ badge={<StackCount count={node.produced} />}
188
+ className="min-w-0 flex-1 justify-start truncate"
189
+ />
190
+ <NodeChips
191
+ node={node}
192
+ mini={false}
193
+ name={name}
194
+ category={category}
195
+ hasAlternatives={hasAlternatives}
196
+ dataset={dataset}
197
+ lang={lang}
198
+ langMap={langMap}
199
+ onRequestPicker={onRequestPicker}
200
+ onRequestMemberPicker={onRequestMemberPicker}
201
+ />
202
+ </div>
203
+ <div className="mx-1 flex min-w-0 items-center gap-1">
204
+ {interactive ? (
205
+ <span className="nodrag ml-auto flex shrink-0 items-center gap-0.5">
206
+ <button
207
+ type="button"
208
+ aria-label={t('Fewer crafts', { note: 'recipe.calc.crafts.down' })}
209
+ className="grid size-4 place-items-center rounded border border-border bg-background text-muted-foreground hover:text-foreground"
210
+ onClick={(e) => {
211
+ e.stopPropagation();
212
+ onCrafts(id, Math.max(1, node.crafts - 1));
213
+ }}
214
+ >
215
+ <Minus className="size-2.5" />
216
+ </button>
217
+ <span
218
+ className="min-w-6 text-center tabular-nums"
219
+ title={t('Crafts', { note: 'recipe.calc.crafts.title' })}
220
+ >
221
+ {node.crafts}
222
+ </span>
223
+ <button
224
+ type="button"
225
+ aria-label={t('More crafts', { note: 'recipe.calc.crafts.up' })}
226
+ className="grid size-4 place-items-center rounded border border-border bg-background text-muted-foreground hover:text-foreground"
227
+ onClick={(e) => {
228
+ e.stopPropagation();
229
+ onCrafts(id, node.crafts + 1);
230
+ }}
231
+ >
232
+ <Plus className="size-2.5" />
233
+ </button>
234
+ </span>
235
+ ) : null}
236
+ </div>
237
+ </>
238
+ )}
239
+ {cardOn && body && src ? (
240
+ <div
241
+ className="nodrag relative z-20 mx-auto mt-1"
242
+ onClick={(e) => e.stopPropagation()}
243
+ >
244
+ <PagedCard
245
+ recipe={body}
246
+ dataset={dataset}
247
+ lang={lang}
248
+ langMap={langMap}
249
+ title={recipeTitle(body, langMap ?? {})}
250
+ src={src}
251
+ naturalW={body.w}
252
+ naturalH={body.h}
253
+ interactive={false}
254
+ slotTooltip={interactive ? 'adaptive' : 'none'}
255
+ eager
256
+ onFail={() => setImgFail(true)}
257
+ />
258
+ </div>
259
+ ) : skeleton ? (
260
+ <Skeleton
261
+ className="nodrag mx-auto mt-1 max-w-full"
262
+ style={
263
+ body?.w && body.h
264
+ ? { width: body.w, height: body.h }
265
+ : { width: CALC_NODE_W - 16, height: 40 }
266
+ }
267
+ />
268
+ ) : null}
269
+ </div>
270
+ );
271
+ const hoverBody =
272
+ interactive && hoverCard ? (
273
+ <HoverCardTrigger render={innerContent} />
274
+ ) : (
275
+ innerContent
276
+ );
277
+ const cardBody = (
278
+ <div
279
+ data-calc-card
280
+ className={cn(
281
+ 'relative flex h-full w-full select-none flex-col text-xs outline-none',
282
+ 'rounded-md border bg-card',
283
+ stateCls,
284
+ )}
285
+ >
286
+ <PortRailIn
287
+ node={node}
288
+ data={data}
289
+ dataset={dataset}
290
+ lang={lang}
291
+ langMap={langMap}
292
+ names={names}
293
+ connectable={interactive}
294
+ />
295
+ {hoverBody}
296
+ <PortRailOut
297
+ node={node}
298
+ data={data}
299
+ dataset={dataset}
300
+ lang={lang}
301
+ langMap={langMap}
302
+ names={names}
303
+ connectable={interactive}
304
+ onOpen={() => onRequestPicker(node)}
305
+ />
306
+ {interactive ? <NodeActions data={data} nodeId={id} /> : null}
307
+ <NodeBadges node={node} />
308
+ </div>
309
+ );
310
+ if (!interactive) return cardBody;
311
+ return (
312
+ <HoverCard>
313
+ <ContextMenu>
314
+ <ContextMenuTrigger render={cardBody} />
315
+ <NodeContextMenu data={data} lang={lang} langMap={langMap} />
316
+ </ContextMenu>
317
+ {hoverCard ? (
318
+ <NodeHoverContent
319
+ data={data}
320
+ lang={lang}
321
+ langMap={langMap}
322
+ category={category}
323
+ body={body}
324
+ src={src}
325
+ name={name}
326
+ onFail={() => setImgFail(true)}
327
+ />
328
+ ) : null}
329
+ </HoverCard>
330
+ );
331
+ });
332
+
@@ -0,0 +1,27 @@
1
+ 'use client';
2
+
3
+ import { memo } from 'react';
4
+ import type { NodeProps } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
5
+ import { useCalcFar } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
6
+ import { useCalcTier } from '@terrafirmagreg-team/recipe/hooks/calc/use-tier';
7
+ import type { CalcFlowNode } from '@terrafirmagreg-team/recipe/lib/calc/flow';
8
+ import { CalcNodeCardFull } from '@terrafirmagreg-team/recipe/components/views/calc/node-card/full';
9
+ import {
10
+ CalcDotCard,
11
+ CalcFarCard,
12
+ CalcHiddenCard,
13
+ } from '@terrafirmagreg-team/recipe/components/views/calc/node-card/far';
14
+
15
+ export const CalcNodeCard = memo(function CalcNodeCard(
16
+ props: NodeProps<CalcFlowNode>,
17
+ ) {
18
+
19
+ const farCards = useCalcFar();
20
+ const tier = useCalcTier();
21
+ if (tier === 'near') return <CalcNodeCardFull {...props} />;
22
+ if (farCards === 'hidden') return <CalcHiddenCard {...props} />;
23
+ if (farCards === 'full') return <CalcNodeCardFull {...props} />;
24
+ if (tier === 'dot') return <CalcDotCard {...props} />;
25
+ return <CalcFarCard {...props} />;
26
+ });
27
+
@@ -0,0 +1,282 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import {
5
+ ExternalLink,
6
+ ListFilter,
7
+ Pin,
8
+ PinOff,
9
+ Plus,
10
+ Shapes,
11
+ Target,
12
+ Undo2,
13
+ } from 'lucide-react';
14
+ import {
15
+ ContextMenuContent,
16
+ ContextMenuGroup,
17
+ ContextMenuItem,
18
+ ContextMenuLabel,
19
+ ContextMenuSeparator,
20
+ } from '@terrafirmagreg-team/ui/components/ui/context-menu';
21
+ import { HoverCardContent } from '@terrafirmagreg-team/ui/components/ui/hover-card';
22
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
23
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
24
+ import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
25
+ import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
26
+ import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
27
+ import type { CalcKind } from '@terrafirmagreg-team/recipe/types/calc';
28
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
29
+ import type { RecipeCategory } from '@terrafirmagreg-team/recipe/types';
30
+
31
+ export function NodeContextMenu({
32
+ data,
33
+ lang,
34
+ langMap,
35
+ }: {
36
+ data: CalcFlowData;
37
+ lang: string;
38
+ langMap?: Record<string, string>;
39
+ }) {
40
+ const {
41
+ node,
42
+ dataset,
43
+ onAddCard,
44
+ onOpenItem,
45
+ onSelectRecipe,
46
+ onRequestPicker,
47
+ onRequestMemberPicker,
48
+ recipeDefaults,
49
+ onSetRecipeDefault,
50
+ } = data;
51
+ const members = node.members;
52
+ const t = useTranslations();
53
+ return (
54
+ <ContextMenuContent>
55
+ <ContextMenuGroup>
56
+ <ContextMenuLabel className="flex items-center gap-1.5">
57
+ <Entry
58
+ id={node.materialId}
59
+ kind={node.kind}
60
+ dataset={dataset}
61
+ lang={lang}
62
+ langMap={langMap}
63
+ size="sm"
64
+ labeled
65
+ href={false}
66
+ tooltip={false}
67
+ />
68
+ </ContextMenuLabel>
69
+ </ContextMenuGroup>
70
+ <ContextMenuSeparator />
71
+ <ContextMenuItem
72
+ className="whitespace-nowrap"
73
+ onClick={() => onAddCard(node.materialId, node.kind)}
74
+ >
75
+ <Target />
76
+ {t('Add card', { note: 'recipe.calc.add.goal' })}
77
+ </ContextMenuItem>
78
+ <ContextMenuItem
79
+ className="whitespace-nowrap"
80
+ onClick={() => onOpenItem(node.materialId, node.kind)}
81
+ >
82
+ <ExternalLink />
83
+ {t('Open item page', { note: 'recipe.calc.open.item' })}
84
+ </ContextMenuItem>
85
+ {node.recipe ? (
86
+ <ContextMenuItem
87
+ className="whitespace-nowrap"
88
+ onClick={() =>
89
+ onSetRecipeDefault(
90
+ node.materialId,
91
+ recipeDefaults[node.materialId] === node.recipe!.recipeId
92
+ ? null
93
+ : node.recipe!.recipeId,
94
+ )
95
+ }
96
+ >
97
+ {recipeDefaults[node.materialId] === node.recipe.recipeId ? (
98
+ <>
99
+ <PinOff />
100
+ {t('Unpin default recipe', { note: 'recipe.calc.clear.default' })}
101
+ </>
102
+ ) : (
103
+ <>
104
+ <Pin />
105
+ {t('Pin as default recipe', { note: 'recipe.calc.set_default' })}
106
+ </>
107
+ )}
108
+ </ContextMenuItem>
109
+ ) : null}
110
+ {node.recipe ? (
111
+ <ContextMenuItem
112
+ className="whitespace-nowrap"
113
+ onClick={() => onSelectRecipe(node.id, null)}
114
+ >
115
+ <Undo2 />
116
+ {t('Remove recipe', { note: 'recipe.calc.remove.recipe' })}
117
+ </ContextMenuItem>
118
+ ) : null}
119
+ {!node.recipe && node.availableRecipes.length > 0 ? (
120
+ <ContextMenuItem
121
+ className="whitespace-nowrap"
122
+ onClick={() => onRequestPicker(node)}
123
+ >
124
+ <Plus />
125
+ {t('Pick a recipe', { note: 'recipe.calc.pick.title' })}
126
+ </ContextMenuItem>
127
+ ) : null}
128
+ {node.tagId && members && members.length > 1 ? (
129
+ <ContextMenuItem
130
+ className="whitespace-nowrap"
131
+ onClick={() => onRequestMemberPicker(node)}
132
+ >
133
+ <ListFilter />
134
+ {t('Choose tag member', { note: 'recipe.calc.member.title' })}
135
+ </ContextMenuItem>
136
+ ) : null}
137
+ </ContextMenuContent>
138
+ );
139
+ }
140
+
141
+ export function PortContextMenu({
142
+ data,
143
+ node,
144
+ input,
145
+ out,
146
+ id,
147
+ kind,
148
+ dataset,
149
+ lang,
150
+ langMap,
151
+ }: {
152
+ data: CalcFlowData;
153
+ node: CalcFlowData['node'];
154
+ input?: number;
155
+ out?: number;
156
+ id: string;
157
+ kind: CalcKind;
158
+ dataset: DatasetRef;
159
+ lang: string;
160
+ langMap?: Record<string, string>;
161
+ }) {
162
+ const { onAddCard, onOpenItem, onRequestPicker, onRequestSupply } = data;
163
+ const t = useTranslations();
164
+ return (
165
+ <ContextMenuContent>
166
+ <ContextMenuGroup>
167
+ <ContextMenuLabel className="flex items-center gap-1.5">
168
+ <Entry
169
+ id={id}
170
+ kind={kind}
171
+ dataset={dataset}
172
+ lang={lang}
173
+ langMap={langMap}
174
+ size="sm"
175
+ labeled
176
+ href={false}
177
+ tooltip={false}
178
+ />
179
+ </ContextMenuLabel>
180
+ </ContextMenuGroup>
181
+ <ContextMenuSeparator />
182
+ {input != null ? (
183
+ <ContextMenuItem
184
+ className="whitespace-nowrap"
185
+ onClick={() => onRequestSupply(node, input)}
186
+ >
187
+ <Plus />
188
+ {t('Keep as external source', { note: 'recipe.calc.supply.source' })}
189
+ </ContextMenuItem>
190
+ ) : null}
191
+ {out === 0 && !node.recipe && node.availableRecipes.length > 0 ? (
192
+ <ContextMenuItem
193
+ className="whitespace-nowrap"
194
+ onClick={() => onRequestPicker(node)}
195
+ >
196
+ <ListFilter />
197
+ {t('Pick a recipe', { note: 'recipe.calc.pick.title' })}
198
+ </ContextMenuItem>
199
+ ) : null}
200
+ <ContextMenuItem
201
+ className="whitespace-nowrap"
202
+ onClick={() => onAddCard(id, kind)}
203
+ >
204
+ <Target />
205
+ {t('Add card', { note: 'recipe.calc.add.goal' })}
206
+ </ContextMenuItem>
207
+ <ContextMenuItem
208
+ className="whitespace-nowrap"
209
+ onClick={() => onOpenItem(id, kind)}
210
+ >
211
+ <ExternalLink />
212
+ {t('Open item page', { note: 'recipe.calc.open.item' })}
213
+ </ContextMenuItem>
214
+ </ContextMenuContent>
215
+ );
216
+ }
217
+
218
+ export function NodeHoverContent({
219
+ data,
220
+ lang,
221
+ langMap,
222
+ category,
223
+ body,
224
+ src,
225
+ name,
226
+ onFail,
227
+ }: {
228
+ data: CalcFlowData;
229
+ lang: string;
230
+ langMap?: Record<string, string>;
231
+ category: RecipeCategory | undefined;
232
+ body: Recipe | undefined;
233
+ src: string | undefined;
234
+ name: string;
235
+ onFail: () => void;
236
+ }) {
237
+ const { node, dataset } = data;
238
+ return (
239
+ <HoverCardContent
240
+ side="right"
241
+ align="start"
242
+ className="w-fit max-w-[min(80vw,560px)] overflow-hidden p-0"
243
+ >
244
+ <div className="flex items-center gap-1.5 border-b border-border px-2 py-1.5 text-xs text-muted-foreground">
245
+ {category?.icon ? (
246
+ <Entry
247
+ dataset={dataset}
248
+ lang={lang}
249
+ langMap={langMap}
250
+ reference={category.icon}
251
+ name={node.recipe!.category}
252
+ size="sm"
253
+ href={false}
254
+ tooltip={false}
255
+ missing="hide"
256
+ />
257
+ ) : (
258
+ <Shapes className="size-3.5 shrink-0" />
259
+ )}
260
+ <span className="truncate">
261
+ {body ? recipeTitle(body, langMap ?? {}) : name}
262
+ </span>
263
+ </div>
264
+ {body && src ? (
265
+ <PagedCard
266
+ recipe={body}
267
+ dataset={dataset}
268
+ lang={lang}
269
+ langMap={langMap}
270
+ title={recipeTitle(body, langMap ?? {})}
271
+ src={src}
272
+ naturalW={body.w}
273
+ naturalH={body.h}
274
+ interactive={false}
275
+ slotTooltip="none"
276
+ onFail={onFail}
277
+ />
278
+ ) : null}
279
+ </HoverCardContent>
280
+ );
281
+ }
282
+