@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,186 @@
1
+ 'use client';
2
+
3
+ import { useMemo, useRef } from 'react';
4
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
6
+ import { ItemViewHeader } from '@terrafirmagreg-team/recipe/components/views/browser/item-view-header';
7
+ import {
8
+ RecipeCardGrid,
9
+ recipeCardDim,
10
+ } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
11
+ import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
12
+ import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
13
+ import { PaneTabs } from '@terrafirmagreg-team/recipe/components/views/browser/pane-tabs';
14
+ import { useFitPages } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
15
+ import { useCategoriesById } from '@terrafirmagreg-team/recipe/hooks/use-categories-by-id';
16
+ import { useTypeFilter } from '@terrafirmagreg-team/recipe/hooks/use-type-filter';
17
+ import { useFavorites } from '@terrafirmagreg-team/recipe/hooks/use-favorites';
18
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
19
+ import {
20
+ EMPTY_ROWS,
21
+ useItemFeeds,
22
+ } from '@terrafirmagreg-team/recipe/hooks/use-item-feeds';
23
+ import { useItemTagGroups } from '@terrafirmagreg-team/recipe/hooks/use-item-tag-groups';
24
+ import { ItemTagGroups } from '@terrafirmagreg-team/recipe/components/views/browser/item-view/tags';
25
+ import { useItemPane } from '@terrafirmagreg-team/recipe/hooks/use-item-pane';
26
+ import { useAddToCalc } from '@terrafirmagreg-team/recipe/hooks/use-add-to-calc';
27
+ import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
28
+ import { parseStackId, stackIdFromRef } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
29
+ import type { TaggedReference } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
30
+ import { customStackName } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
31
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
32
+ import type {
33
+ RecipeSession,
34
+ } from '@terrafirmagreg-team/recipe/types';
35
+
36
+ export function ItemView({ session }: { session: RecipeSession }) {
37
+ const t = useTranslations();
38
+ const {
39
+ dataset,
40
+ lang,
41
+ index,
42
+ indexLoading,
43
+ names,
44
+ nav,
45
+ rpage,
46
+ recipeId,
47
+ relation,
48
+ } = session;
49
+ const item = (session.item ?? session.fluid)!;
50
+ const kind = session.item ? 'item' : 'fluid';
51
+ const parsed = useMemo(() => parseStackId(item), [item]);
52
+ const favorites = useFavorites();
53
+ const name =
54
+ customStackName(session.langMap, item) ??
55
+ recipeItemName(names, lang, item);
56
+
57
+ const boxRef = useRef<HTMLDivElement | null>(null);
58
+
59
+ const categoriesById = useCategoriesById(index);
60
+
61
+ const feeds = useItemFeeds({ dataset, index, indexLoading, item, kind });
62
+ const { recipes, uses } = feeds;
63
+ const tags = useItemTagGroups({ dataset, index, item, kind });
64
+ const pane = useItemPane({
65
+ dataset,
66
+ lang,
67
+ nav,
68
+ relation,
69
+ recipeId,
70
+ recipes,
71
+ uses,
72
+ tagCount: tags.ids.length,
73
+ feedsPending: feeds.pending,
74
+ });
75
+ const addToCalc = useAddToCalc(session);
76
+
77
+ const feedRows = (pane.pane === 'uses' ? uses : recipes) ?? EMPTY_ROWS;
78
+ const typeFilter = useTypeFilter(session, feedRows);
79
+ const railRefs = useMemo(() => {
80
+ const seen = new Set<string>();
81
+ const refs: TaggedReference[] = [];
82
+ for (const ref of
83
+ categoriesById.get(typeFilter.active)?.workstations ?? []) {
84
+ const key = stackIdFromRef(ref);
85
+ if (!seen.has(key)) {
86
+ seen.add(key);
87
+ refs.push(ref);
88
+ }
89
+ }
90
+ return refs;
91
+ }, [categoriesById, typeFilter.active]);
92
+ const focusIndex = recipeId
93
+ ? typeFilter.rows.findIndex((row) => row.id === recipeId)
94
+ : -1;
95
+ const list = useFitPages(
96
+ boxRef,
97
+ typeFilter.rows,
98
+ (row, box) => {
99
+ const d = recipeCardDim(index, categoriesById, row);
100
+ return d.h > box.h ? { w: d.w, h: box.h } : d;
101
+ },
102
+ rpage,
103
+ 8,
104
+ focusIndex >= 0 ? focusIndex : undefined,
105
+ true,
106
+ );
107
+
108
+ const onSwipe = (dir: -1 | 1) => {
109
+ if (recipeId) {
110
+ const row = typeFilter.rows[focusIndex + dir];
111
+ if (focusIndex < 0 || !row) return;
112
+ replaceUrlState(
113
+ recipeHref(dataset, lang, { ...nav, id: row.id, rpage: undefined }),
114
+ );
115
+ return;
116
+ }
117
+ if (list.pages <= 1) return;
118
+ replaceUrlState(
119
+ recipeHref(dataset, lang, {
120
+ ...nav,
121
+ rpage: (list.page + dir + list.pages) % list.pages,
122
+ }),
123
+ );
124
+ };
125
+
126
+ return (
127
+ <RecipeFrame
128
+ session={session}
129
+ list={pane.pane === 'tags' ? undefined : list}
130
+ strip={
131
+ <RecipeTypeTabs
132
+ session={session}
133
+ ids={pane.pane !== 'tags' ? typeFilter.ids : []}
134
+ value={typeFilter.active}
135
+ onChange={typeFilter.setActive}
136
+ />
137
+ }
138
+ header={
139
+ <div className="flex flex-col gap-1.5">
140
+ <ItemViewHeader
141
+ item={item}
142
+ kind={kind}
143
+ name={name}
144
+ parsed={parsed}
145
+ favorite={favorites.isFavorite(item)}
146
+ onToggleFavorite={() => favorites.toggleItem(item)}
147
+ onAddToCalc={() => addToCalc(item, kind)}
148
+ />
149
+ <PaneTabs
150
+ value={pane.pane}
151
+ options={pane.options}
152
+ onChange={pane.select}
153
+ />
154
+ </div>
155
+ }
156
+ rail={
157
+ pane.pane !== 'tags' ? (
158
+ <WorkstationRail session={session} workstations={railRefs} />
159
+ ) : undefined
160
+ }
161
+ >
162
+ {pane.pane === 'tags' ? (
163
+ <ItemTagGroups
164
+ groups={tags.groups}
165
+ dataset={dataset}
166
+ lang={lang}
167
+ names={names}
168
+ query={session.query}
169
+ nav={nav}
170
+ />
171
+ ) : (
172
+ <RecipeCardGrid
173
+ session={session}
174
+ rows={list.shown}
175
+ boxRef={boxRef}
176
+ maxH={list.box.h}
177
+ maxW={list.box.w}
178
+ loading={feeds.pending}
179
+ empty={t('No recipes of this type.', { note: 'recipe.empty_type' })}
180
+ onSwipe={onSwipe}
181
+ />
182
+ )}
183
+ </RecipeFrame>
184
+ );
185
+ }
186
+
@@ -0,0 +1,85 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
6
+ import { LinkPreview } from '@terrafirmagreg-team/ui/components/blocks/link/link-preview';
7
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
8
+ import { tagPseudoId } from '@terrafirmagreg-team/dump/lib/dump/paths';
9
+ import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
10
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
11
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
12
+ import type { RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
13
+
14
+ export function ItemTagGroups({
15
+ groups,
16
+ dataset,
17
+ lang,
18
+ names,
19
+ query,
20
+ nav,
21
+ }: {
22
+ groups: [string, string[]][];
23
+ dataset: DatasetRef;
24
+ lang: Lang;
25
+ names: Record<string, Record<string, string>>;
26
+ query: string;
27
+ nav: RecipeHrefOpts;
28
+ }) {
29
+ const t = useTranslations();
30
+ if (!groups.length) {
31
+ return <EmptyState variant="empty">{t('No tags for this item.', { note: 'recipe.empty_tags' })}</EmptyState>;
32
+ }
33
+ return (
34
+ <div className="flex flex-col gap-3 pt-1">
35
+ {groups.map(([tagKind, ids]) => (
36
+ <div key={tagKind} className="flex flex-col gap-1.5">
37
+ {groups.length > 1 && (
38
+ <p className="text-xs font-medium text-muted-foreground">
39
+ {tagKind === 'block'
40
+ ? t('Blocks', { note: 'recipe.tags_block' })
41
+ : t('Items', { note: 'recipe.tags_item' })}
42
+ </p>
43
+ )}
44
+ <div className="flex flex-wrap gap-1">
45
+ {ids.map((id) => {
46
+ const bare = id.replace(/^#+/, '');
47
+ return (
48
+ <LinkPreview
49
+ key={`${tagKind}:${id}`}
50
+ href={recipeHref(dataset, lang, {
51
+ type: 'emi:tag',
52
+ id: tagPseudoId(id, tagKind),
53
+ search: query || undefined,
54
+ tab: nav.tab,
55
+ })}
56
+ variant="chip"
57
+ size="sm"
58
+ onClick={(event) => {
59
+ if (!event.shiftKey) return;
60
+ event.preventDefault();
61
+ const token = `#${bare}`;
62
+ const text = query.trim();
63
+ const search =
64
+ !text || text.split(/\s+/).includes(token)
65
+ ? text || token
66
+ : `${text} ${token}`;
67
+ replaceUrlState(
68
+ recipeHref(dataset, lang, {
69
+ type: 'emi:tag',
70
+ search,
71
+ }),
72
+ );
73
+ }}
74
+ >
75
+ {recipeItemName(names, lang, id)}
76
+ </LinkPreview>
77
+ );
78
+ })}
79
+ </div>
80
+ </div>
81
+ ))}
82
+ </div>
83
+ );
84
+ }
85
+
@@ -0,0 +1,131 @@
1
+ 'use client';
2
+
3
+ import { Braces, Calculator, Check, Copy } from 'lucide-react';
4
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { useModifierKeys } from '@terrafirmagreg-team/ui/hooks/use-modifier-keys';
6
+ import { ItemRow } from '@terrafirmagreg-team/ui/components/blocks/list/row';
7
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
8
+ import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
9
+ import { ButtonCopy } from '@terrafirmagreg-team/recipe/components/button-copy';
10
+ import { FavoriteButton } from '@terrafirmagreg-team/recipe/components/views/browser/favorite-button';
11
+ import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
12
+ import {
13
+ Popover,
14
+ PopoverContent,
15
+ PopoverTitle,
16
+ PopoverTrigger,
17
+ } from '@terrafirmagreg-team/ui/components/ui/popover';
18
+ import { formatNbt, formatNbtPretty } from '@terrafirmagreg-team/dump/lib/snbt';
19
+ import type { ParsedStackId } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
20
+ import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
21
+
22
+ export function ItemViewHeader({
23
+ item,
24
+ kind,
25
+ name,
26
+ parsed,
27
+ favorite,
28
+ onToggleFavorite,
29
+ onAddToCalc,
30
+ }: {
31
+ item: string;
32
+ kind: ReferenceKind;
33
+ name: string;
34
+ parsed: ParsedStackId;
35
+ favorite: boolean;
36
+ onToggleFavorite: () => void;
37
+ onAddToCalc?: () => void;
38
+ }) {
39
+ const t = useTranslations();
40
+ const held = useModifierKeys();
41
+ const nbt = formatNbt(parsed.nbt);
42
+ const pretty =
43
+ parsed.nbt !== undefined ? formatNbtPretty(parsed.nbt) : undefined;
44
+ const copyId = held.shift && nbt ? `${parsed.id}${nbt}` : parsed.id;
45
+ const copyTitle = held.shift ? t('Copy stack id', { note: 'recipe.copy_stack' }) : t('Copy id', { note: 'recipe.copy' });
46
+ return (
47
+ <>
48
+ <ItemRow
49
+ layout="header"
50
+ media={
51
+ <CopyIdMenu id={parsed.id} nbt={nbt}>
52
+ <Entry
53
+ id={item}
54
+ kind={kind}
55
+ name={name}
56
+ size="lg"
57
+ variant="chip"
58
+ href={false}
59
+ />
60
+ </CopyIdMenu>
61
+ }
62
+ title={name}
63
+ titleClassName="truncate"
64
+ code={
65
+ <span className="inline-flex max-w-full items-center gap-0.5">
66
+ <span className="truncate">{parsed.id}</span>
67
+ <ButtonCopy
68
+ value={copyId}
69
+ title={copyTitle}
70
+ aria-label={copyTitle}
71
+ copy={<Copy className="size-3" />}
72
+ copied={<Check className="size-3" />}
73
+ />
74
+ </span>
75
+ }
76
+ trailing={
77
+ <span className="flex items-center gap-1">
78
+ {nbt && pretty ? (
79
+ <Popover>
80
+ <PopoverTrigger
81
+ render={
82
+ <IconButton
83
+ variant="ghost"
84
+ tooltip={false}
85
+ label={t('NBT', { note: 'recipe.nbt' })}
86
+ className="size-7 rounded-lg text-muted-foreground hover:text-foreground [&_svg]:size-3.5"
87
+ >
88
+ <Braces />
89
+ </IconButton>
90
+ }
91
+ />
92
+ <PopoverContent
93
+ align="end"
94
+ className="w-96 max-w-[calc(100vw-2rem)]"
95
+ >
96
+ <div className="flex items-center justify-between">
97
+ <PopoverTitle className="text-xs font-medium tracking-wider text-muted-foreground uppercase">
98
+ {t('NBT', { note: 'recipe.nbt' })}
99
+ </PopoverTitle>
100
+ <ButtonCopy
101
+ value={nbt}
102
+ title={t('Copy NBT', { note: 'recipe.copy_nbt' })}
103
+ aria-label={t('Copy NBT', { note: 'recipe.copy_nbt' })}
104
+ copy={<Copy className="size-3" />}
105
+ copied={<Check className="size-3" />}
106
+ />
107
+ </div>
108
+ <pre className="max-h-80 overflow-auto rounded-md bg-muted/50 p-2 text-2xs leading-snug break-all whitespace-pre-wrap">
109
+ {pretty}
110
+ </pre>
111
+ </PopoverContent>
112
+ </Popover>
113
+ ) : null}
114
+ {onAddToCalc ? (
115
+ <IconButton
116
+ variant="ghost"
117
+ label={t('Add to calculator', { note: 'recipe.calc.add.title' })}
118
+ className="size-7 rounded-lg text-muted-foreground hover:text-foreground [&_svg]:size-3.5"
119
+ onClick={onAddToCalc}
120
+ >
121
+ <Calculator />
122
+ </IconButton>
123
+ ) : null}
124
+ <FavoriteButton active={favorite} onToggle={onToggleFavorite} />
125
+ </span>
126
+ }
127
+ />
128
+ </>
129
+ );
130
+ }
131
+
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+
3
+ import type { ReactNode } from 'react';
4
+ import {
5
+ Tooltip,
6
+ TooltipContent,
7
+ TooltipTrigger,
8
+ } from '@terrafirmagreg-team/ui/components/ui/tooltip';
9
+ import { Tabs, TabsList, TabsTrigger } from '@terrafirmagreg-team/ui/components/ui/tabs';
10
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
11
+
12
+ export type PaneTabOption<T extends string> = {
13
+ id: T;
14
+ label: string;
15
+ icon: ReactNode;
16
+ help?: string;
17
+ disabled?: boolean;
18
+ };
19
+
20
+ export function PaneTabs<T extends string>({
21
+ value,
22
+ options,
23
+ onChange,
24
+ className,
25
+ }: {
26
+ value: T;
27
+ options: PaneTabOption<T>[];
28
+ onChange: (id: T) => void;
29
+ className?: string;
30
+ }) {
31
+ return (
32
+ <Tabs
33
+ value={value}
34
+ onValueChange={(id) => onChange(id as T)}
35
+ className={cn('flex', className)}
36
+ >
37
+ <TabsList className="flex-wrap gap-1 bg-transparent p-0">
38
+ {options.map((option) => (
39
+ <Tooltip key={option.id}>
40
+ <TooltipTrigger
41
+ render={
42
+ <TabsTrigger
43
+ value={option.id}
44
+ disabled={option.disabled}
45
+ className="h-7 flex-none rounded-lg border border-border bg-background px-2.5 text-xs hover:bg-muted hover:text-foreground data-active:border-border data-active:bg-secondary data-active:text-secondary-foreground"
46
+ />
47
+ }
48
+ >
49
+ {option.icon}
50
+ {option.label}
51
+ </TooltipTrigger>
52
+ {option.help ? (
53
+ <TooltipContent>{option.help}</TooltipContent>
54
+ ) : null}
55
+ </Tooltip>
56
+ ))}
57
+ </TabsList>
58
+ </Tabs>
59
+ );
60
+ }
61
+
@@ -0,0 +1,72 @@
1
+ 'use client';
2
+
3
+ import { Calculator, Check, Copy } from 'lucide-react';
4
+ import { ItemRow } from '@terrafirmagreg-team/ui/components/blocks/list/row';
5
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
6
+ import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
7
+ import { ButtonCopy } from '@terrafirmagreg-team/recipe/components/button-copy';
8
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
9
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
10
+ import { RECIPE_ALL_TYPE } from '@terrafirmagreg-team/recipe/lib/links';
11
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
12
+
13
+ export function PlaceHeader({
14
+ session,
15
+ overline,
16
+ }: {
17
+ session: RecipeSession;
18
+ overline?: string;
19
+ }) {
20
+ const t = useTranslations();
21
+ const { lang, index, names, place, dataset } = session;
22
+ const isCalc = place?.kind === 'calc';
23
+ const placeId = place?.kind === 'type' ? place.id : undefined;
24
+ const category = placeId
25
+ ? index?.categories?.find((row) => row.id === placeId)
26
+ : undefined;
27
+ const title = isCalc
28
+ ? t('Calculator', { note: 'recipe.calculator' })
29
+ : placeId
30
+ ? recipeItemName(names, lang, placeId)
31
+ : '';
32
+ return (
33
+ <ItemRow
34
+ layout="header"
35
+ media={
36
+ isCalc ? (
37
+ <Calculator className="size-8 text-muted-foreground" />
38
+ ) : category?.icon ? (
39
+ <CopyIdMenu id={placeId ?? ''}>
40
+ <Entry
41
+ dataset={dataset}
42
+ reference={category.icon}
43
+ name={title}
44
+ size="lg"
45
+ href={false}
46
+ tooltip={false}
47
+ variant="chip"
48
+ />
49
+ </CopyIdMenu>
50
+ ) : undefined
51
+ }
52
+ overline={overline}
53
+ title={title}
54
+ titleClassName="truncate"
55
+ code={
56
+ placeId && placeId !== RECIPE_ALL_TYPE ? (
57
+ <span className="inline-flex max-w-full items-center gap-0.5">
58
+ <span className="truncate">{placeId}</span>
59
+ <ButtonCopy
60
+ value={placeId}
61
+ title={t('Copy id', { note: 'recipe.copy' })}
62
+ aria-label={t('Copy id', { note: 'recipe.copy' })}
63
+ copy={<Copy className="size-3" />}
64
+ copied={<Check className="size-3" />}
65
+ />
66
+ </span>
67
+ ) : undefined
68
+ }
69
+ />
70
+ );
71
+ }
72
+
@@ -0,0 +1,105 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import type { ReactNode } from 'react';
5
+ import { Search } from 'lucide-react';
6
+ import {
7
+ InputGroup,
8
+ InputGroupAddon,
9
+ InputGroupInput,
10
+ } from '@terrafirmagreg-team/ui/components/ui/input-group';
11
+ import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
12
+ import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
13
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
14
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
15
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
16
+ import type { RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
17
+
18
+ type QueryNav = {
19
+ dataset: DatasetRef;
20
+ lang: Lang;
21
+ params?: RecipeHrefOpts;
22
+ };
23
+
24
+ export function QuerySearch({
25
+ dataset,
26
+ lang,
27
+ params,
28
+ query,
29
+ onQuery,
30
+ placeholder,
31
+ className,
32
+ }: QueryNav & {
33
+ query: string;
34
+ onQuery: (query: string) => void;
35
+ placeholder?: string;
36
+ className?: string;
37
+ }) {
38
+ return (
39
+ <InputGroup className={cn('w-full', className)}>
40
+ <InputGroupAddon>
41
+ <Search />
42
+ </InputGroupAddon>
43
+ <InputGroupInput
44
+ type="search"
45
+ value={query}
46
+ placeholder={placeholder}
47
+ onChange={(event) => {
48
+ const next = event.target.value;
49
+ onQuery(next);
50
+ replaceUrlState(
51
+ recipeHref(dataset, lang, {
52
+ ...params,
53
+ search: next || undefined,
54
+ }),
55
+ );
56
+ }}
57
+ />
58
+ </InputGroup>
59
+ );
60
+ }
61
+
62
+ export function QueryPager({
63
+ dataset,
64
+ lang,
65
+ params,
66
+ query,
67
+ list,
68
+ label,
69
+ leading,
70
+ className,
71
+ }: QueryNav & {
72
+ query: string;
73
+ list: {
74
+ page: number;
75
+ pages: number;
76
+ from?: number;
77
+ to: number;
78
+ total: number;
79
+ };
80
+ label: string;
81
+ leading?: ReactNode;
82
+ className?: string;
83
+ }) {
84
+ return (
85
+ <Pager
86
+ page={list.page}
87
+ pages={list.pages}
88
+ to={list.to}
89
+ total={list.total}
90
+ label={label}
91
+ leading={leading}
92
+ className={className}
93
+ onPage={(next) =>
94
+ replaceUrlState(
95
+ recipeHref(dataset, lang, {
96
+ ...params,
97
+ search: query || undefined,
98
+ rpage: next + 1,
99
+ }),
100
+ )
101
+ }
102
+ />
103
+ );
104
+ }
105
+