@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,229 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import {
5
+ memo,
6
+ useCallback,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from 'react';
11
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
12
+ import { useFavorites } from '@terrafirmagreg-team/recipe/hooks/use-favorites';
13
+ import { useFavoriteHotkey } from '@terrafirmagreg-team/recipe/hooks/use-favorite-hotkey';
14
+ import { useHideUnused } from '@terrafirmagreg-team/recipe/hooks/use-hide-unused';
15
+ import { usePagedList } from '@terrafirmagreg-team/ui/hooks/page/use-paged-list';
16
+ import { useSwipe } from '@terrafirmagreg-team/ui/hooks/use-swipe';
17
+ import { useElementSize } from '@terrafirmagreg-team/ui/hooks/use-element-size';
18
+ import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
19
+ import { type ItemPanelMode } from '@terrafirmagreg-team/recipe/lib/panel';
20
+ import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
21
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
22
+ import { favoriteHover } from '@terrafirmagreg-team/recipe/lib/favorite-hover';
23
+ import { IconPager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
24
+ import { FavoriteButton } from '@terrafirmagreg-team/recipe/components/views/browser/favorite-button';
25
+ import { ItemPanelGrid } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel-grid';
26
+ import { RecipeSettings } from '@terrafirmagreg-team/recipe/components/views/browser/settings';
27
+ import { QuerySearch } from '@terrafirmagreg-team/recipe/components/views/browser/query-controls';
28
+ import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
29
+ import { usePanelPage } from '@terrafirmagreg-team/recipe/hooks/use-panel-page';
30
+ import { useItemPress } from '@terrafirmagreg-team/recipe/hooks/use-item-press';
31
+ import { usePanelCells } from '@terrafirmagreg-team/recipe/hooks/use-panel-cells';
32
+ import { usePanelTabs } from '@terrafirmagreg-team/recipe/hooks/use-panel-tabs';
33
+ import { PanelSkeleton } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel/skeleton';
34
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
35
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
36
+ import type {
37
+ RecipeCompactIndex,
38
+ RecipeHrefOpts,
39
+ } from '@terrafirmagreg-team/recipe/types';
40
+
41
+ const CELL = 40;
42
+ const PANEL_COLS = 10;
43
+
44
+ export const ItemPanel = memo(function ItemPanel({
45
+ dataset,
46
+ lang,
47
+ index,
48
+ indexLoading,
49
+ names,
50
+ tab,
51
+ query,
52
+ setQuery,
53
+ isCalc,
54
+ nav,
55
+ className,
56
+ }: {
57
+ dataset: DatasetRef;
58
+ lang: Lang;
59
+ index: RecipeCompactIndex | null;
60
+ indexLoading: boolean;
61
+ names: Record<string, Record<string, string>>;
62
+ tab?: string;
63
+ query: string;
64
+ setQuery: (query: string) => void;
65
+ isCalc: boolean;
66
+ nav: RecipeHrefOpts;
67
+ className?: string;
68
+ }) {
69
+ const t = useTranslations();
70
+ const favorites = useFavorites();
71
+ const { hideUnused } = useHideUnused();
72
+ const [mode, setMode] = useState<ItemPanelMode>('all');
73
+ const boxRef = useRef<HTMLDivElement | null>(null);
74
+ useFavoriteHotkey();
75
+ const { w, h } = useElementSize(boxRef);
76
+ const cols = Math.min(PANEL_COLS, Math.max(1, Math.floor((w + 4) / CELL)));
77
+ const rows = Math.max(1, Math.floor((h + 4) / CELL));
78
+ const pageSize = cols * rows;
79
+ const measured = w > 0 && h > 0;
80
+
81
+ const [expandedGroups, setExpandedGroups] = useState<ReadonlySet<string>>(
82
+ new Set(),
83
+ );
84
+ const { cells, filtered, favoriteIds, dIndex, dNames, dLang } =
85
+ usePanelCells({
86
+ dataset,
87
+ index,
88
+ names,
89
+ lang,
90
+ mode,
91
+ query,
92
+ tab,
93
+ hideUnused,
94
+ favorites,
95
+ expandedGroups,
96
+ });
97
+ const favIds = useMemo(() => new Set(favoriteIds), [favoriteIds]);
98
+ const { page: panelPage, setPage: setPanelPage } = usePanelPage(dataset);
99
+ const list = usePagedList(cells, panelPage, pageSize);
100
+
101
+ const gridResetKey = useMemo(
102
+ () => [mode, filtered, favorites.entries],
103
+ [mode, filtered, favorites.entries],
104
+ );
105
+ const onToggleGroup = useCallback((groupId: string) => {
106
+ setExpandedGroups((prev) => {
107
+ const next = new Set(prev);
108
+ if (next.has(groupId)) next.delete(groupId);
109
+ else next.add(groupId);
110
+ return next;
111
+ });
112
+ }, []);
113
+
114
+ const onPress = useItemPress({ dataset, lang, nav, isCalc });
115
+
116
+ const setTab = (next: string) => {
117
+ setPanelPage(0);
118
+ replaceUrlState(
119
+ recipeHref(dataset, lang, {
120
+ ...nav,
121
+ tab: next || undefined,
122
+ }),
123
+ );
124
+ };
125
+
126
+ const goPage = (dir: number) => {
127
+ if (list.pages <= 1) return;
128
+ setPanelPage((list.page + dir + list.pages) % list.pages);
129
+ };
130
+ const swipe = useSwipe(goPage);
131
+
132
+ const tabOptions = usePanelTabs(dIndex, dNames, dLang);
133
+
134
+ let body;
135
+ const indexEmpty = !index?.items.length;
136
+ if (!measured || (indexLoading && indexEmpty)) {
137
+ body =
138
+ indexLoading && indexEmpty ? (
139
+ <PanelSkeleton cols={cols} rows={rows} />
140
+ ) : null;
141
+ } else if (!list.shown.length) {
142
+ body = (
143
+ <EmptyState variant="empty">
144
+ {mode === 'fav'
145
+ ? t('No favorites yet.', { note: 'recipe.favorites_empty' })
146
+ : hideUnused && !query.trim()
147
+ ? t('No items match with Hide unused enabled. Turn it off to browse the full catalog.', { note: 'recipe.hide_unused_empty' })
148
+ : t('No matching items.', { note: 'recipe.empty_items' })}
149
+ </EmptyState>
150
+ );
151
+ } else {
152
+ body = (
153
+ <ItemPanelGrid
154
+ cells={list.shown}
155
+ resetKey={gridResetKey}
156
+ dataset={dataset}
157
+ lang={dLang}
158
+ names={dNames}
159
+ nav={nav}
160
+ cols={cols}
161
+ rows={rows}
162
+ favIds={favIds}
163
+ onPress={onPress}
164
+ onHover={(target) => {
165
+ favoriteHover.base = target;
166
+ }}
167
+ onToggleGroup={onToggleGroup}
168
+ draggableStacks={isCalc}
169
+ />
170
+ );
171
+ }
172
+
173
+ return (
174
+ <div className={cn('not-prose flex min-h-0 flex-col gap-2', className)}>
175
+ <IconPager
176
+ value={mode === 'fav' ? 'fav' : (tab ?? '')}
177
+ options={tabOptions}
178
+ onChange={(id) => {
179
+ setMode('all');
180
+ setTab(id);
181
+ }}
182
+ />
183
+ <Pager
184
+ page={list.page}
185
+ pages={list.pages}
186
+ to={list.to}
187
+ total={list.total}
188
+ label={t('{page}/{pages}', { note: 'recipe.page_of' })}
189
+ onPage={setPanelPage}
190
+ leading={
191
+ <FavoriteButton
192
+ variant="outline"
193
+ active={mode === 'fav'}
194
+ label={t('Favorites', { note: 'recipe.favorites' })}
195
+ onToggle={() => {
196
+ setPanelPage(0);
197
+ setMode(mode === 'fav' ? 'all' : 'fav');
198
+ }}
199
+ className="size-9 [&_svg]:size-4.5"
200
+ />
201
+ }
202
+ />
203
+ <div
204
+ ref={boxRef}
205
+ {...swipe}
206
+ onWheel={(event) => goPage(event.deltaY > 0 ? 1 : -1)}
207
+ className="min-h-0 flex-1"
208
+ >
209
+ {body}
210
+ </div>
211
+ <div className="mx-auto flex w-full max-w-md items-center gap-2">
212
+ <RecipeSettings />
213
+ <QuerySearch
214
+ dataset={dataset}
215
+ lang={lang}
216
+ params={nav}
217
+ query={query}
218
+ onQuery={(next) => {
219
+ setPanelPage(0);
220
+ setQuery(next);
221
+ }}
222
+ placeholder={t('Search items', { note: 'recipe.search' })}
223
+ className="w-full"
224
+ />
225
+ </div>
226
+ </div>
227
+ );
228
+ });
229
+
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
4
+
5
+ export function PanelSkeleton({ cols, rows }: { cols: number; rows: number }) {
6
+ return (
7
+ <ul
8
+ aria-hidden
9
+ className="grid h-full w-full place-content-center gap-1"
10
+ style={{
11
+ gridTemplateColumns: `repeat(${Math.max(1, cols)}, 36px)`,
12
+ gridTemplateRows: `repeat(${Math.max(1, rows)}, 36px)`,
13
+ }}
14
+ >
15
+ {Array.from({ length: Math.max(1, cols) * Math.max(1, rows) }, (_, i) => (
16
+ <li
17
+ key={i}
18
+ className="flex min-h-0 min-w-0 items-center justify-center"
19
+ >
20
+ <Skeleton className="size-9 rounded-sm" />
21
+ </li>
22
+ ))}
23
+ </ul>
24
+ );
25
+ }
26
+
@@ -0,0 +1,178 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import type { ReactNode } from 'react';
5
+ import { Minus, Plus, Star } from 'lucide-react';
6
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
7
+ import { EntryGroup } from '@terrafirmagreg-team/game/components/entry/group';
8
+ import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
9
+ import { parseStackId } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
10
+ import { formatNbt } from '@terrafirmagreg-team/dump/lib/snbt';
11
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
12
+ import { Badge } from '@terrafirmagreg-team/ui/components/ui/badge';
13
+ import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
14
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
15
+ import { RecipeFavoriteCell } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel-grid/favorite-cell';
16
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
17
+ import type { EntrySize } from '@terrafirmagreg-team/game/types/entry';
18
+ import type { FavoriteHoverTarget } from '@terrafirmagreg-team/recipe/lib/favorite-hover';
19
+ import type { ItemPanelCell, RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
20
+
21
+ function PanelChip({
22
+ id,
23
+ size,
24
+ className,
25
+ badge,
26
+ kind = 'item',
27
+ names,
28
+ lang,
29
+ favIds,
30
+ }: {
31
+ id: string;
32
+ size: EntrySize;
33
+ className?: string;
34
+ badge?: { node: ReactNode; className?: string };
35
+ kind?: 'item' | 'fluid';
36
+ names: Record<string, Record<string, string>>;
37
+ lang: Lang;
38
+ favIds?: ReadonlySet<string>;
39
+ }) {
40
+ return (
41
+ <Entry
42
+ id={id}
43
+ kind={kind}
44
+ name={recipeItemName(names, lang, id)}
45
+ size={size}
46
+ variant="chip"
47
+ href={false}
48
+ className={cn('block', className)}
49
+ badge={
50
+ badge?.node ??
51
+ (favIds?.has(id) ? (
52
+ <Star className="size-2.5 fill-amber-500 text-amber-500" />
53
+ ) : undefined)
54
+ }
55
+ badgeClassName={
56
+ badge?.className ?? '-left-0.5 -top-0.5 right-auto bottom-auto'
57
+ }
58
+ />
59
+ );
60
+ }
61
+
62
+ export function PanelCell({
63
+ cell,
64
+ dataset,
65
+ lang,
66
+ names,
67
+ nav,
68
+ favIds,
69
+ expandLabel,
70
+ draggableStacks,
71
+ onPress,
72
+ onHover,
73
+ onToggleGroup,
74
+ }: {
75
+ cell: ItemPanelCell;
76
+ dataset: DatasetRef;
77
+ lang: Lang;
78
+ names: Record<string, Record<string, string>>;
79
+ nav: RecipeHrefOpts;
80
+ favIds?: ReadonlySet<string>;
81
+ expandLabel: string;
82
+ draggableStacks?: boolean;
83
+ onPress: (id: string, ref?: 'item' | 'fluid') => void;
84
+ onHover?: (target: FavoriteHoverTarget | undefined) => void;
85
+ onToggleGroup?: (id: string) => void;
86
+ }) {
87
+ const stack = cell.kind === 'stack' ? cell.id : undefined;
88
+ const parsed = stack ? parseStackId(stack) : undefined;
89
+ const nbt = parsed ? formatNbt(parsed.nbt) : undefined;
90
+ const hover: FavoriteHoverTarget | undefined =
91
+ cell.kind === 'stack'
92
+ ? {
93
+ kind: 'stack',
94
+ id: cell.id,
95
+ ...(cell.ref ? { ref: cell.ref } : {}),
96
+ }
97
+ : cell.kind === 'recipe'
98
+ ? {
99
+ kind: 'recipe',
100
+ id: cell.fav.id,
101
+ type: cell.fav.type,
102
+ ...(cell.fav.icon ? { icon: cell.fav.icon } : {}),
103
+ }
104
+ : undefined;
105
+ return (
106
+ <li
107
+ className="flex min-h-0 min-w-0 items-center justify-center"
108
+ onMouseEnter={() => onHover?.(hover)}
109
+ onMouseLeave={() => onHover?.(undefined)}
110
+ >
111
+ {cell.kind === 'recipe' ? (
112
+ <RecipeFavoriteCell
113
+ dataset={dataset}
114
+ lang={lang}
115
+ names={names}
116
+ nav={nav}
117
+ fav={cell.fav}
118
+ />
119
+ ) : cell.kind === 'group' ? (
120
+ <Hint label={cell.expanded ? undefined : expandLabel}>
121
+ <button
122
+ type="button"
123
+ aria-label={cell.label}
124
+ aria-pressed={cell.expanded}
125
+ onClick={() => onToggleGroup?.(cell.id)}
126
+ className="block rounded-sm"
127
+ >
128
+ <span className="relative flex size-9 items-center justify-center">
129
+ <EntryGroup members={cell.members} size="lg" />
130
+ <Badge className="absolute -right-0.5 -bottom-0.5 z-10 h-auto rounded-sm px-0.5 py-0 leading-tight">
131
+ {cell.expanded ? (
132
+ <Minus className="size-3" />
133
+ ) : (
134
+ <Plus className="size-3" />
135
+ )}
136
+ </Badge>
137
+ </span>
138
+ </button>
139
+ </Hint>
140
+ ) : (
141
+ <CopyIdMenu id={parsed?.id ?? cell.id} nbt={nbt}>
142
+ <button
143
+ type="button"
144
+ onClick={() => onPress(cell.id, cell.ref)}
145
+ aria-label={recipeItemName(names, lang, cell.id)}
146
+ className={cn('block rounded-sm', draggableStacks && 'cursor-grab')}
147
+ draggable={draggableStacks || undefined}
148
+ onDragStart={
149
+ draggableStacks
150
+ ? (event) => {
151
+ event.dataTransfer.setData(
152
+ 'application/x-tfg-calc',
153
+ JSON.stringify({
154
+ id: cell.id,
155
+ kind: cell.ref === 'fluid' ? 'fluid' : 'item',
156
+ }),
157
+ );
158
+ event.dataTransfer.effectAllowed = 'copy';
159
+ }
160
+ : undefined
161
+ }
162
+ >
163
+ <PanelChip
164
+ id={cell.id}
165
+ size="lg"
166
+ className="size-9"
167
+ kind={cell.ref === 'fluid' ? 'fluid' : 'item'}
168
+ names={names}
169
+ lang={lang}
170
+ favIds={favIds}
171
+ />
172
+ </button>
173
+ </CopyIdMenu>
174
+ )}
175
+ </li>
176
+ );
177
+ }
178
+
@@ -0,0 +1,129 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import Link from 'next/link';
5
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
6
+ import { EntryTooltip } from '@terrafirmagreg-team/game/components/entry/tooltip';
7
+ import { tooltipLoadKind } from '@terrafirmagreg-team/game/lib/entry/entry';
8
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
9
+ import {
10
+ recipeCardImageUrl,
11
+ recipeHref,
12
+ } from '@terrafirmagreg-team/recipe/lib/links';
13
+ import {
14
+ Tooltip,
15
+ TooltipContent,
16
+ TooltipTrigger,
17
+ } from '@terrafirmagreg-team/ui/components/ui/tooltip';
18
+ import { Badge } from '@terrafirmagreg-team/ui/components/ui/badge';
19
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
20
+ import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
21
+ import type { RecipeFavorite, RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
22
+
23
+ const TAG_SEGMENT_KIND: Record<string, ReferenceKind> = {
24
+ item: 'itemTag',
25
+ block: 'blockTag',
26
+ fluid: 'fluidTag',
27
+ entity_type: 'entityTag',
28
+ };
29
+
30
+ function favoriteIconKind(fav: RecipeFavorite): ReferenceKind {
31
+ if (fav.icon?.startsWith('#')) {
32
+ return TAG_SEGMENT_KIND[fav.id.split('/')[1] ?? ''] ?? 'itemTag';
33
+ }
34
+ return 'item';
35
+ }
36
+
37
+ export function RecipeFavoriteCell({
38
+ dataset,
39
+ lang,
40
+ names,
41
+ nav,
42
+ fav,
43
+ }: {
44
+ dataset: DatasetRef;
45
+ lang: Lang;
46
+ names: Record<string, Record<string, string>>;
47
+ nav: RecipeHrefOpts;
48
+ fav: RecipeFavorite;
49
+ }) {
50
+ const src = recipeCardImageUrl(dataset, fav.id);
51
+ const iconKind = favoriteIconKind(fav);
52
+ const itemName = fav.icon ? recipeItemName(names, lang, fav.icon) : fav.id;
53
+ const href = recipeHref(dataset, lang, {
54
+ ...nav,
55
+ type: fav.type,
56
+ id: fav.id,
57
+ item: undefined,
58
+ fluid: undefined,
59
+ relation: undefined,
60
+ rpage: undefined,
61
+ });
62
+ const cardImg = src ? (
63
+ // eslint-disable-next-line @next/next/no-img-element -- dump asset
64
+ <img
65
+ src={src}
66
+ alt={fav.id}
67
+ loading="lazy"
68
+ decoding="async"
69
+ className="max-h-24 rounded-sm"
70
+ />
71
+ ) : null;
72
+ const link = (
73
+ <Link href={href} aria-label={itemName} className="block rounded-sm">
74
+ {fav.icon ? (
75
+ <Entry
76
+ id={fav.icon}
77
+ kind={iconKind}
78
+ name={itemName}
79
+ size="lg"
80
+ variant="chip"
81
+ href={false}
82
+ tooltip={false}
83
+ badge={
84
+ <Badge className="h-auto rounded-sm px-0.5 py-0 text-3xs leading-tight">
85
+ R
86
+ </Badge>
87
+ }
88
+ />
89
+ ) : src ? (
90
+ // eslint-disable-next-line @next/next/no-img-element -- dump asset
91
+ <img
92
+ src={src}
93
+ alt={fav.id}
94
+ className="h-9 rounded-sm"
95
+ loading="lazy"
96
+ decoding="async"
97
+ />
98
+ ) : (
99
+ <span className="block max-w-9 truncate rounded-sm bg-muted px-1 text-2xs">
100
+ {fav.id}
101
+ </span>
102
+ )}
103
+ </Link>
104
+ );
105
+ if (fav.icon) {
106
+ return (
107
+ <EntryTooltip
108
+ dataset={dataset}
109
+ id={fav.icon.replace(/^#+/, '')}
110
+ name={itemName}
111
+ kind={tooltipLoadKind(iconKind)}
112
+ lang={lang}
113
+ footer={cardImg}
114
+ >
115
+ {link}
116
+ </EntryTooltip>
117
+ );
118
+ }
119
+ return (
120
+ <Tooltip>
121
+ <TooltipTrigger render={link} delay={150} closeDelay={100} />
122
+ <TooltipContent className="flex-col items-start gap-1.5 p-2.5">
123
+ <p className="text-sm font-medium">{itemName}</p>
124
+ {cardImg}
125
+ </TooltipContent>
126
+ </Tooltip>
127
+ );
128
+ }
129
+
@@ -0,0 +1,105 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { memo } from 'react';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import { PanelCell } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel-grid/cell';
7
+ import { useMountLimit } from '@terrafirmagreg-team/recipe/hooks/use-mount-limit';
8
+ import { useGroupOutlines } from '@terrafirmagreg-team/recipe/hooks/use-group-outlines';
9
+ import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
10
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
11
+ import type { FavoriteHoverTarget } from '@terrafirmagreg-team/recipe/lib/favorite-hover';
12
+ import type { ItemPanelCell, RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
13
+
14
+ const CELL = 36;
15
+
16
+ export const ItemPanelGrid = memo(function ItemPanelGrid({
17
+ cells,
18
+ resetKey,
19
+ dataset,
20
+ lang,
21
+ names,
22
+ nav,
23
+ cols,
24
+ rows,
25
+ favIds,
26
+ onPress,
27
+ onHover,
28
+ onToggleGroup,
29
+ draggableStacks,
30
+ }: {
31
+ cells: ItemPanelCell[];
32
+
33
+ resetKey: unknown;
34
+ dataset: DatasetRef;
35
+ lang: Lang;
36
+ names: Record<string, Record<string, string>>;
37
+ nav: RecipeHrefOpts;
38
+ cols: number;
39
+ rows: number;
40
+ favIds?: ReadonlySet<string>;
41
+ onPress: (id: string, ref?: 'item' | 'fluid') => void;
42
+ onHover?: (target: FavoriteHoverTarget | undefined) => void;
43
+ onToggleGroup?: (id: string) => void;
44
+ draggableStacks?: boolean;
45
+ }) {
46
+ const t = useTranslations();
47
+ const expandLabel = t('Expand', { note: 'recipe.expand' });
48
+ const limit = useMountLimit(cells.length, resetKey);
49
+ const shown = limit >= cells.length ? cells : cells.slice(0, limit);
50
+ const { gridRef, outlines } = useGroupOutlines(shown, cols, rows);
51
+
52
+ return (
53
+ <ul
54
+ ref={gridRef}
55
+ className="relative grid h-full w-full place-content-center gap-1"
56
+ style={{
57
+ gridTemplateColumns: `repeat(${cols}, ${CELL}px)`,
58
+ gridTemplateRows: `repeat(${rows}, ${CELL}px)`,
59
+ }}
60
+ >
61
+ {shown.map((cell) => (
62
+ <PanelCell
63
+ key={cell.kind === 'recipe' ? `R:${cell.fav.id}` : cell.id}
64
+ cell={cell}
65
+ dataset={dataset}
66
+ lang={lang}
67
+ names={names}
68
+ nav={nav}
69
+ favIds={favIds}
70
+ expandLabel={expandLabel}
71
+ draggableStacks={draggableStacks}
72
+ onPress={onPress}
73
+ onHover={onHover}
74
+ onToggleGroup={onToggleGroup}
75
+ />
76
+ ))}
77
+ {Array.from({ length: cells.length - shown.length }, (_, i) => (
78
+ <li
79
+ key={`skel-${i}`}
80
+ aria-hidden
81
+ className="flex min-h-0 min-w-0 items-center justify-center"
82
+ >
83
+ <Skeleton className="size-9 rounded-sm" />
84
+ </li>
85
+ ))}
86
+ <svg
87
+ aria-hidden
88
+ className="pointer-events-none absolute inset-0 h-full w-full overflow-visible"
89
+ >
90
+ {outlines.map((outline) => (
91
+ <path
92
+ key={outline.groupId + outline.d}
93
+ d={outline.d}
94
+ fill="none"
95
+ stroke="var(--color-foreground)"
96
+ strokeOpacity={0.4}
97
+ strokeWidth={1.5}
98
+ strokeLinejoin="round"
99
+ />
100
+ ))}
101
+ </svg>
102
+ </ul>
103
+ );
104
+ });
105
+