@terrafirmagreg-team/recipe 0.0.0-stage → 0.1.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 (231) hide show
  1. package/package.json +62 -3
  2. package/src/components/button-copy.tsx +42 -0
  3. package/src/components/cards/card/index.tsx +212 -0
  4. package/src/components/cards/card/model.ts +64 -0
  5. package/src/components/cards/card/scene.tsx +105 -0
  6. package/src/components/cards/card/strip.tsx +196 -0
  7. package/src/components/cards/card/text.tsx +45 -0
  8. package/src/components/cards/card/tips.tsx +62 -0
  9. package/src/components/cards/default-item.tsx +43 -0
  10. package/src/components/cards/fit-card.tsx +26 -0
  11. package/src/components/cards/glare-filter.tsx +28 -0
  12. package/src/components/cards/paged-card.tsx +221 -0
  13. package/src/components/cards/slot-hitbox.tsx +211 -0
  14. package/src/components/cards/strip-card/buttons.tsx +101 -0
  15. package/src/components/cards/strip-card/index.tsx +212 -0
  16. package/src/components/cards/strip-card/member-cell.tsx +165 -0
  17. package/src/components/cards/strip-card/sprite.tsx +35 -0
  18. package/src/components/mdx/recipe.tsx +111 -0
  19. package/src/components/tool-list.tsx +48 -0
  20. package/src/components/views/alloy/index.tsx +105 -0
  21. package/src/components/views/alloy/list.tsx +84 -0
  22. package/src/components/views/alloy/mix/index.tsx +34 -0
  23. package/src/components/views/alloy/mix/ratio.tsx +93 -0
  24. package/src/components/views/alloy/mix/rows.tsx +146 -0
  25. package/src/components/views/alloy/mix/status.tsx +121 -0
  26. package/src/components/views/alloy/mix/total.tsx +131 -0
  27. package/src/components/views/alloy/range-bar.tsx +64 -0
  28. package/src/components/views/alloy/stack-bar.tsx +86 -0
  29. package/src/components/views/browser/axis-switcher.tsx +53 -0
  30. package/src/components/views/browser/card-grid.tsx +274 -0
  31. package/src/components/views/browser/favorite-button.tsx +45 -0
  32. package/src/components/views/browser/frame.tsx +111 -0
  33. package/src/components/views/browser/index.tsx +96 -0
  34. package/src/components/views/browser/item-panel/index.tsx +227 -0
  35. package/src/components/views/browser/item-panel/skeleton.tsx +25 -0
  36. package/src/components/views/browser/item-panel-grid/cell.tsx +176 -0
  37. package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +127 -0
  38. package/src/components/views/browser/item-panel-grid/index.tsx +103 -0
  39. package/src/components/views/browser/item-view/index.tsx +191 -0
  40. package/src/components/views/browser/item-view/tags.tsx +83 -0
  41. package/src/components/views/browser/item-view-header.tsx +130 -0
  42. package/src/components/views/browser/pane-tabs.tsx +60 -0
  43. package/src/components/views/browser/place-header.tsx +71 -0
  44. package/src/components/views/browser/query-controls.tsx +103 -0
  45. package/src/components/views/browser/recipe-item-header.tsx +59 -0
  46. package/src/components/views/browser/settings.tsx +51 -0
  47. package/src/components/views/browser/toolbar.tsx +53 -0
  48. package/src/components/views/browser/type-tabs.tsx +69 -0
  49. package/src/components/views/browser/type-view.tsx +189 -0
  50. package/src/components/views/browser/workstation-rail.tsx +42 -0
  51. package/src/components/views/calc/calculator/actions.tsx +57 -0
  52. package/src/components/views/calc/calculator/help.tsx +148 -0
  53. package/src/components/views/calc/calculator/index.tsx +220 -0
  54. package/src/components/views/calc/dot-overlay.tsx +79 -0
  55. package/src/components/views/calc/edge.tsx +50 -0
  56. package/src/components/views/calc/flow/index.tsx +267 -0
  57. package/src/components/views/calc/flow/picker-dialogs.tsx +68 -0
  58. package/src/components/views/calc/flow/toolbar.tsx +72 -0
  59. package/src/components/views/calc/flow/view-menu.tsx +221 -0
  60. package/src/components/views/calc/member-picker.tsx +118 -0
  61. package/src/components/views/calc/node-card/actions.tsx +168 -0
  62. package/src/components/views/calc/node-card/badges.tsx +77 -0
  63. package/src/components/views/calc/node-card/chips.tsx +219 -0
  64. package/src/components/views/calc/node-card/far.tsx +175 -0
  65. package/src/components/views/calc/node-card/full.tsx +282 -0
  66. package/src/components/views/calc/node-card/index.tsx +26 -0
  67. package/src/components/views/calc/node-card/menu.tsx +211 -0
  68. package/src/components/views/calc/recipe-picker/body.tsx +204 -0
  69. package/src/components/views/calc/recipe-picker/footer.tsx +129 -0
  70. package/src/components/views/calc/recipe-picker/index.tsx +47 -0
  71. package/src/components/views/calc/sidebar.tsx +162 -0
  72. package/src/components/views/calc/target.tsx +271 -0
  73. package/src/components/views/calc/trees/icon-picker.tsx +96 -0
  74. package/src/components/views/calc/trees/index.tsx +133 -0
  75. package/src/components/views/calc/trees/label.tsx +65 -0
  76. package/src/components/views/calc/trees/rows.tsx +139 -0
  77. package/src/components/views/forge/gui.tsx +130 -0
  78. package/src/components/views/forge/index.tsx +105 -0
  79. package/src/components/views/forge/list.tsx +112 -0
  80. package/src/components/views/forge/workbench/controls.tsx +96 -0
  81. package/src/components/views/forge/workbench/index.tsx +84 -0
  82. package/src/components/views/forge/workbench/panel.tsx +227 -0
  83. package/src/components/views/forge/workbench/ruler.tsx +132 -0
  84. package/src/components/views/forge/workbench/status.tsx +54 -0
  85. package/src/components/views/forge/workbench/tape.tsx +69 -0
  86. package/src/hooks/alloy/use-fluid-colors.ts +122 -0
  87. package/src/hooks/alloy/use-mix-state.ts +239 -0
  88. package/src/hooks/calc/flow/engage.ts +89 -0
  89. package/src/hooks/calc/flow/handlers.ts +115 -0
  90. package/src/hooks/calc/flow/layout.ts +149 -0
  91. package/src/hooks/calc/flow/mount.ts +96 -0
  92. package/src/hooks/calc/flow/nodes.ts +251 -0
  93. package/src/hooks/calc/flow/pickers.ts +50 -0
  94. package/src/hooks/calc/flow/props.ts +40 -0
  95. package/src/hooks/calc/flow/viewport.ts +154 -0
  96. package/src/hooks/calc/flow/window.ts +86 -0
  97. package/src/hooks/calc/use-actions.ts +376 -0
  98. package/src/hooks/calc/use-amounts.ts +101 -0
  99. package/src/hooks/calc/use-calc-fill.ts +91 -0
  100. package/src/hooks/calc/use-data.ts +289 -0
  101. package/src/hooks/calc/use-defaults.ts +38 -0
  102. package/src/hooks/calc/use-density.ts +28 -0
  103. package/src/hooks/calc/use-derived.ts +258 -0
  104. package/src/hooks/calc/use-direction.ts +23 -0
  105. package/src/hooks/calc/use-edge-style.ts +40 -0
  106. package/src/hooks/calc/use-far-mode.ts +36 -0
  107. package/src/hooks/calc/use-fill.ts +213 -0
  108. package/src/hooks/calc/use-focus.ts +30 -0
  109. package/src/hooks/calc/use-maps.ts +75 -0
  110. package/src/hooks/calc/use-reset.ts +14 -0
  111. package/src/hooks/calc/use-resolver.ts +234 -0
  112. package/src/hooks/calc/use-session.ts +12 -0
  113. package/src/hooks/calc/use-share.ts +61 -0
  114. package/src/hooks/calc/use-storage.ts +125 -0
  115. package/src/hooks/calc/use-tier.ts +12 -0
  116. package/src/hooks/calc/use-view-mode.ts +23 -0
  117. package/src/hooks/calc/use-worker.ts +269 -0
  118. package/src/hooks/forge/use-anvil-gui.ts +14 -0
  119. package/src/hooks/forge/use-forge-state.ts +134 -0
  120. package/src/hooks/forge/use-ruler.ts +99 -0
  121. package/src/hooks/use-add-to-calc.ts +47 -0
  122. package/src/hooks/use-favorite-hotkey.ts +38 -0
  123. package/src/hooks/use-favorites.ts +134 -0
  124. package/src/hooks/use-group-outlines.ts +64 -0
  125. package/src/hooks/use-hide-unused.ts +11 -0
  126. package/src/hooks/use-index.ts +68 -0
  127. package/src/hooks/use-item-feeds.ts +44 -0
  128. package/src/hooks/use-item-pane.ts +104 -0
  129. package/src/hooks/use-item-press.ts +85 -0
  130. package/src/hooks/use-item-tag-groups.ts +52 -0
  131. package/src/hooks/use-item-tooltips.ts +16 -0
  132. package/src/hooks/use-left-sidebar-tree.ts +26 -0
  133. package/src/hooks/use-mod-names.ts +15 -0
  134. package/src/hooks/use-mount-limit.ts +21 -0
  135. package/src/hooks/use-panel-cells.ts +115 -0
  136. package/src/hooks/use-panel-page.ts +51 -0
  137. package/src/hooks/use-panel-tabs.ts +42 -0
  138. package/src/hooks/use-query.ts +184 -0
  139. package/src/hooks/use-session.ts +84 -0
  140. package/src/hooks/use-sidebar-group.ts +20 -0
  141. package/src/hooks/use-tag-members.ts +14 -0
  142. package/src/hooks/use-tool-recipes.ts +25 -0
  143. package/src/hooks/use-type-filter.ts +72 -0
  144. package/src/lib/alloy/alloy.test.ts +186 -0
  145. package/src/lib/alloy/mix.ts +209 -0
  146. package/src/lib/alloy/parse.ts +36 -0
  147. package/src/lib/calc/defaults.ts +45 -0
  148. package/src/lib/calc/flow.ts +279 -0
  149. package/src/lib/calc/focus.ts +14 -0
  150. package/src/lib/calc/meta.ts +15 -0
  151. package/src/lib/calc/pack.ts +184 -0
  152. package/src/lib/calc/resolve.ts +230 -0
  153. package/src/lib/calc/route/buckets.ts +48 -0
  154. package/src/lib/calc/route/geometry.ts +62 -0
  155. package/src/lib/calc/route/index.ts +2 -0
  156. package/src/lib/calc/route/polyline.ts +103 -0
  157. package/src/lib/calc/route/router.ts +270 -0
  158. package/src/lib/calc/storage/entry.ts +89 -0
  159. package/src/lib/calc/storage/index.ts +18 -0
  160. package/src/lib/calc/storage/keys.ts +42 -0
  161. package/src/lib/calc/storage/store.ts +223 -0
  162. package/src/lib/calc/tree/build.ts +196 -0
  163. package/src/lib/calc/tree/context.ts +42 -0
  164. package/src/lib/calc/tree/goal.ts +64 -0
  165. package/src/lib/calc/tree/ideal.ts +36 -0
  166. package/src/lib/calc/tree/index.ts +18 -0
  167. package/src/lib/calc/tree/materials.ts +28 -0
  168. package/src/lib/calc/tree/pick.ts +68 -0
  169. package/src/lib/calc/tree/recipe.ts +103 -0
  170. package/src/lib/calc/tree/share.ts +198 -0
  171. package/src/lib/calc/tree/tree.test.ts +169 -0
  172. package/src/lib/calc/worker/api.ts +33 -0
  173. package/src/lib/calc/worker/fetch.ts +65 -0
  174. package/src/lib/calc/worker/fill.ts +123 -0
  175. package/src/lib/calc/worker/flush.ts +52 -0
  176. package/src/lib/calc/worker/index.ts +8 -0
  177. package/src/lib/calc/worker/protocol.ts +32 -0
  178. package/src/lib/calc/worker/resolve.ts +101 -0
  179. package/src/lib/calc/worker/state.ts +49 -0
  180. package/src/lib/client/recipe-categories.ts +96 -0
  181. package/src/lib/client/recipe.ts +83 -0
  182. package/src/lib/client-index/cache.ts +13 -0
  183. package/src/lib/client-index/catalog.ts +85 -0
  184. package/src/lib/client-index/chrome.ts +180 -0
  185. package/src/lib/client-index/index.ts +19 -0
  186. package/src/lib/client-index/registry.ts +110 -0
  187. package/src/lib/client-index/rows.ts +254 -0
  188. package/src/lib/client-index/tooltips.ts +80 -0
  189. package/src/lib/config.ts +17 -0
  190. package/src/lib/data/category/dto.ts +24 -0
  191. package/src/lib/data/category/load.ts +46 -0
  192. package/src/lib/data/category/parse.ts +70 -0
  193. package/src/lib/data/dto.ts +151 -0
  194. package/src/lib/data/grid.ts +39 -0
  195. package/src/lib/data/parse/entry.ts +84 -0
  196. package/src/lib/data/parse/index.ts +2 -0
  197. package/src/lib/data/parse/layout.ts +135 -0
  198. package/src/lib/data/parse/slots.ts +84 -0
  199. package/src/lib/data/parse/widgets.ts +80 -0
  200. package/src/lib/data/scene.ts +103 -0
  201. package/src/lib/data/slot-io.ts +43 -0
  202. package/src/lib/dump.ts +5 -0
  203. package/src/lib/favorite-hover.ts +12 -0
  204. package/src/lib/fluid-outputs.ts +72 -0
  205. package/src/lib/forge/actions.ts +58 -0
  206. package/src/lib/forge/data.ts +50 -0
  207. package/src/lib/forge/forge.test.ts +123 -0
  208. package/src/lib/forge/solve.ts +79 -0
  209. package/src/lib/group.ts +22 -0
  210. package/src/lib/index-store.ts +64 -0
  211. package/src/lib/links.ts +125 -0
  212. package/src/lib/lookup.ts +117 -0
  213. package/src/lib/panel-outline.ts +85 -0
  214. package/src/lib/panel.ts +104 -0
  215. package/src/lib/preview.ts +28 -0
  216. package/src/lib/recipe-slots.ts +7 -0
  217. package/src/lib/search.ts +138 -0
  218. package/src/lib/sidebar.ts +46 -0
  219. package/src/lib/tree.ts +90 -0
  220. package/src/lib/used-items.ts +24 -0
  221. package/src/locales/en_us.json +228 -0
  222. package/src/locales/ru_ru.json +228 -0
  223. package/src/locales.ts +5 -0
  224. package/src/types/alloy.ts +19 -0
  225. package/src/types/calc.ts +95 -0
  226. package/src/types/forge.ts +20 -0
  227. package/src/types/index.ts +134 -0
  228. package/styles/calc.css +47 -0
  229. package/styles/strip.css +7 -0
  230. package/styles.css +2 -0
  231. package/README.md +0 -3
@@ -0,0 +1,71 @@
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('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('recipe.copy')}
62
+ aria-label={t('recipe.copy')}
63
+ copy={<Copy className="size-3" />}
64
+ copied={<Check className="size-3" />}
65
+ />
66
+ </span>
67
+ ) : undefined
68
+ }
69
+ />
70
+ );
71
+ }
@@ -0,0 +1,103 @@
1
+ 'use client';
2
+
3
+ import type { ReactNode } from 'react';
4
+ import { Search } from 'lucide-react';
5
+ import {
6
+ InputGroup,
7
+ InputGroupAddon,
8
+ InputGroupInput,
9
+ } from '@terrafirmagreg-team/ui/components/ui/input-group';
10
+ import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
11
+ import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
12
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
13
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
14
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
15
+ import type { RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
16
+
17
+ type QueryNav = {
18
+ dataset: string;
19
+ lang: Lang;
20
+ params?: RecipeHrefOpts;
21
+ };
22
+
23
+ export function QuerySearch({
24
+ dataset,
25
+ lang,
26
+ params,
27
+ query,
28
+ onQuery,
29
+ placeholder,
30
+ className,
31
+ }: QueryNav & {
32
+ query: string;
33
+ onQuery: (query: string) => void;
34
+ placeholder?: string;
35
+ className?: string;
36
+ }) {
37
+ return (
38
+ <InputGroup className={cn('w-full', className)}>
39
+ <InputGroupAddon>
40
+ <Search />
41
+ </InputGroupAddon>
42
+ <InputGroupInput
43
+ type="search"
44
+ value={query}
45
+ placeholder={placeholder}
46
+ onChange={(event) => {
47
+ const next = event.target.value;
48
+ onQuery(next);
49
+ replaceUrlState(
50
+ recipeHref(dataset, lang, {
51
+ ...params,
52
+ search: next || undefined,
53
+ }),
54
+ );
55
+ }}
56
+ />
57
+ </InputGroup>
58
+ );
59
+ }
60
+
61
+ export function QueryPager({
62
+ dataset,
63
+ lang,
64
+ params,
65
+ query,
66
+ list,
67
+ label,
68
+ leading,
69
+ className,
70
+ }: QueryNav & {
71
+ query: string;
72
+ list: {
73
+ page: number;
74
+ pages: number;
75
+ from?: number;
76
+ to: number;
77
+ total: number;
78
+ };
79
+ label: string;
80
+ leading?: ReactNode;
81
+ className?: string;
82
+ }) {
83
+ return (
84
+ <Pager
85
+ page={list.page}
86
+ pages={list.pages}
87
+ to={list.to}
88
+ total={list.total}
89
+ label={label}
90
+ leading={leading}
91
+ className={className}
92
+ onPage={(next) =>
93
+ replaceUrlState(
94
+ recipeHref(dataset, lang, {
95
+ ...params,
96
+ search: query || undefined,
97
+ rpage: next + 1,
98
+ }),
99
+ )
100
+ }
101
+ />
102
+ );
103
+ }
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+
3
+ import { Check, Copy } from 'lucide-react';
4
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { ItemRow } from '@terrafirmagreg-team/ui/components/blocks/list/row';
6
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
7
+ import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
8
+ import { ButtonCopy } from '@terrafirmagreg-team/recipe/components/button-copy';
9
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
10
+ import { parseStackId } from '@terrafirmagreg-team/game/lib/dump/contract/ref';
11
+ import { formatNbt } from '@terrafirmagreg-team/game/lib/snbt';
12
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
13
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
14
+
15
+ export function RecipeItemHeader({
16
+ recipe,
17
+ session,
18
+ }: {
19
+ recipe: Recipe;
20
+ session: RecipeSession;
21
+ }) {
22
+ const t = useTranslations();
23
+ const output = recipe.outputs[0];
24
+ const stackId = output?.id ?? recipe.id;
25
+ const parsed = parseStackId(stackId);
26
+ const name = recipeItemName(session.names, session.lang, parsed.id);
27
+ const nbt = formatNbt(parsed.nbt);
28
+ return (
29
+ <ItemRow
30
+ layout="header"
31
+ media={
32
+ <CopyIdMenu id={parsed.id} nbt={nbt}>
33
+ <Entry
34
+ id={stackId}
35
+ kind={output?.kind === 'fluid' ? 'fluid' : 'item'}
36
+ name={name}
37
+ size="lg"
38
+ variant="chip"
39
+ href={false}
40
+ />
41
+ </CopyIdMenu>
42
+ }
43
+ title={name}
44
+ titleClassName="truncate"
45
+ code={
46
+ <span className="inline-flex max-w-full items-center gap-0.5">
47
+ <span className="truncate">{recipe.id}</span>
48
+ <ButtonCopy
49
+ value={recipe.id}
50
+ title={t('recipe.copy_recipe_id')}
51
+ aria-label={t('recipe.copy_recipe_id')}
52
+ copy={<Copy className="size-3" />}
53
+ copied={<Check className="size-3" />}
54
+ />
55
+ </span>
56
+ }
57
+ />
58
+ );
59
+ }
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+
3
+ import { Settings2 } from 'lucide-react';
4
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { useHideUnused } from '@terrafirmagreg-team/recipe/hooks/use-hide-unused';
6
+ import { useSidebarGroup } from '@terrafirmagreg-team/recipe/hooks/use-sidebar-group';
7
+ import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
8
+ import { Label } from '@terrafirmagreg-team/ui/components/ui/label';
9
+ import { Switch } from '@terrafirmagreg-team/ui/components/ui/switch';
10
+ import {
11
+ Popover,
12
+ PopoverContent,
13
+ PopoverTrigger,
14
+ } from '@terrafirmagreg-team/ui/components/ui/popover';
15
+
16
+ export function RecipeSettings() {
17
+ const t = useTranslations();
18
+ const { hideUnused, setHideUnused } = useHideUnused();
19
+ const { sidebarGroup, setSidebarGroup } = useSidebarGroup();
20
+
21
+ return (
22
+ <Popover>
23
+ <PopoverTrigger
24
+ render={
25
+ <Button
26
+ variant="outline"
27
+ size="icon-sm"
28
+ aria-label={t('recipe.settings')}
29
+ className="rounded-lg"
30
+ />
31
+ }
32
+ >
33
+ <Settings2 className="size-4" />
34
+ </PopoverTrigger>
35
+ <PopoverContent align="start" className="flex w-56 flex-col gap-2">
36
+ <Label className="gap-1.5 text-sm font-normal">
37
+ <Switch size="sm" checked={hideUnused} onCheckedChange={setHideUnused} />
38
+ {t('recipe.hide_unused')}
39
+ </Label>
40
+ <Label className="gap-1.5 text-sm font-normal">
41
+ <Switch
42
+ size="sm"
43
+ checked={sidebarGroup === 'mod'}
44
+ onCheckedChange={(value) => setSidebarGroup(value ? 'mod' : 'flat')}
45
+ />
46
+ {t('recipe.sidebar_group_mod')}
47
+ </Label>
48
+ </PopoverContent>
49
+ </Popover>
50
+ );
51
+ }
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { LayoutGrid } from 'lucide-react';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
7
+ import {
8
+ Sheet,
9
+ SheetContent,
10
+ SheetHeader,
11
+ SheetTitle,
12
+ } from '@terrafirmagreg-team/ui/components/ui/sheet';
13
+ import { ItemPanel } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel';
14
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
15
+
16
+ export function RecipeToolbar({ session }: { session: RecipeSession }) {
17
+ const t = useTranslations();
18
+ const [itemsOpen, setItemsOpen] = useState(false);
19
+
20
+ return (
21
+ <div className="flex items-center gap-2">
22
+ <Button
23
+ variant="outline"
24
+ size="sm"
25
+ className="lg:hidden"
26
+ onClick={() => setItemsOpen(true)}
27
+ >
28
+ <LayoutGrid className="size-3.5" />
29
+ {t('recipe.items')}
30
+ </Button>
31
+ <Sheet open={itemsOpen} onOpenChange={setItemsOpen}>
32
+ <SheetContent side="right" className="w-full gap-3 sm:max-w-md">
33
+ <SheetHeader>
34
+ <SheetTitle>{t('recipe.items')}</SheetTitle>
35
+ </SheetHeader>
36
+ <ItemPanel
37
+ dataset={session.dataset}
38
+ lang={session.lang}
39
+ index={session.index}
40
+ indexLoading={session.indexLoading}
41
+ names={session.names}
42
+ tab={session.tab}
43
+ query={session.query}
44
+ setQuery={session.setQuery}
45
+ isCalc={session.place?.kind === 'calc'}
46
+ nav={session.nav}
47
+ className="min-h-0 w-full flex-1 px-4 pb-4"
48
+ />
49
+ </SheetContent>
50
+ </Sheet>
51
+ </div>
52
+ );
53
+ }
@@ -0,0 +1,69 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from 'react';
4
+ import { Shapes } from 'lucide-react';
5
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
6
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
7
+ import { IconTabs } from '@terrafirmagreg-team/game/components/entry/icon/tabs';
8
+ import type { RecipeCategory, RecipeSession } from '@terrafirmagreg-team/recipe/types';
9
+
10
+ function CategoryGlyph({
11
+ category,
12
+ dataset,
13
+ }: {
14
+ category?: RecipeCategory;
15
+ dataset: string;
16
+ }) {
17
+ return category?.icon ? (
18
+ <Entry
19
+ dataset={dataset}
20
+ reference={category.icon}
21
+ name={category.id}
22
+ size="lg"
23
+ href={false}
24
+ tooltip={false}
25
+ missing="hide"
26
+ />
27
+ ) : (
28
+ <Shapes className="size-8" />
29
+ );
30
+ }
31
+
32
+ export function RecipeTypeTabs({
33
+ session,
34
+ ids,
35
+ value,
36
+ onChange,
37
+ className,
38
+ }: {
39
+ session: Pick<RecipeSession, 'lang' | 'names' | 'index' | 'dataset'>;
40
+ ids: string[];
41
+ value?: string;
42
+ onChange?: (id: string) => void;
43
+ className?: string;
44
+ }) {
45
+ const { lang, names, index, dataset } = session;
46
+
47
+ const options = useMemo(() => {
48
+ const byId = new Map(
49
+ (index?.categories ?? []).map((row) => [row.id, row]),
50
+ );
51
+ return ids.map((id) => {
52
+ const category = byId.get(id);
53
+ return {
54
+ id,
55
+ icon: <CategoryGlyph category={category} dataset={dataset} />,
56
+ help: recipeItemName(names, lang, id),
57
+ };
58
+ });
59
+ }, [index, ids, lang, names, dataset]);
60
+
61
+ return (
62
+ <IconTabs
63
+ value={value}
64
+ options={options}
65
+ onChange={onChange ?? (() => {})}
66
+ className={className}
67
+ />
68
+ );
69
+ }
@@ -0,0 +1,189 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useMemo, useRef } from 'react';
4
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
5
+ import { useAsyncResult, useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
6
+ import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
7
+ import {
8
+ RecipeCardGrid,
9
+ recipeCardDim,
10
+ } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
11
+ import { PlaceHeader } from '@terrafirmagreg-team/recipe/components/views/browser/place-header';
12
+ import { useFitPages } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
13
+ import {
14
+ loadTypeRows,
15
+ nonEmptyCategoryIds,
16
+ resolveRecipeRows,
17
+ } from '@terrafirmagreg-team/recipe/lib/client-index';
18
+ import { RECIPE_ALL_TYPE, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
19
+ import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
20
+ import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
21
+ import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
22
+ import type {
23
+ RecipeCategory,
24
+ RecipeCompactRow,
25
+ RecipeSession,
26
+ } from '@terrafirmagreg-team/recipe/types';
27
+
28
+ const EMPTY_ROWS: RecipeCompactRow[] = [];
29
+
30
+ export function TypeView({ session }: { session: RecipeSession }) {
31
+ const t = useTranslations();
32
+ const {
33
+ dataset,
34
+ lang,
35
+ index,
36
+ indexLoading,
37
+ place,
38
+ nav,
39
+ recipeId,
40
+ rpage,
41
+ } = session;
42
+ const boxRef = useRef<HTMLDivElement | null>(null);
43
+
44
+ const placeId = place?.kind === 'type' ? place.id : RECIPE_ALL_TYPE;
45
+
46
+ const categoriesById = useMemo(
47
+ () =>
48
+ new Map<string, RecipeCategory>(
49
+ (index?.categories ?? []).map((row) => [row.id, row]),
50
+ ),
51
+ [index],
52
+ );
53
+ const nonEmptyIds = nonEmptyCategoryIds(index);
54
+
55
+ const shown =
56
+ placeId !== RECIPE_ALL_TYPE && nonEmptyIds.includes(placeId)
57
+ ? placeId
58
+ : nonEmptyIds[0];
59
+ const rows = useAsyncValue(
60
+ () =>
61
+ index && shown
62
+ ? loadTypeRows(dataset, index, shown)
63
+ : Promise.resolve(EMPTY_ROWS),
64
+ [dataset, index, shown],
65
+ );
66
+
67
+ const allRows = rows ?? EMPTY_ROWS;
68
+ const focusIndex = recipeId
69
+ ? allRows.findIndex((row) => row.id === recipeId)
70
+ : -1;
71
+ const focusRes = useAsyncResult(
72
+ () =>
73
+ recipeId && index && rows !== undefined && focusIndex < 0
74
+ ? resolveRecipeRows(dataset, index, [recipeId])
75
+ : Promise.resolve(undefined),
76
+ [dataset, index, recipeId, rows, focusIndex],
77
+ );
78
+ const solo = recipeId != null && session.solo === '1';
79
+ const feedRows = solo
80
+ ? focusIndex >= 0
81
+ ? [allRows[focusIndex]]
82
+ : (focusRes.value ?? EMPTY_ROWS)
83
+ : allRows;
84
+ const feedFocus = solo && focusIndex >= 0 ? 0 : focusIndex;
85
+ useEffect(() => {
86
+ if (!recipeId || !index || rows === undefined || focusIndex >= 0) return;
87
+ if (focusRes.pending) return;
88
+ const row = focusRes.value?.[0];
89
+ const category = row ? index.types[row.type] : undefined;
90
+ replaceUrlState(
91
+ recipeHref(dataset, lang, {
92
+ ...nav,
93
+ ...(category && category !== shown ? { type: category } : {}),
94
+ ...(category ? {} : { id: undefined }),
95
+ rpage: undefined,
96
+ }),
97
+ );
98
+ }, [focusIndex, focusRes.pending, focusRes.value, index, nav, dataset, lang, recipeId, rows, shown]);
99
+ const list = useFitPages(
100
+ boxRef,
101
+ feedRows,
102
+ (row, box) => {
103
+ const d = recipeCardDim(index, categoriesById, row);
104
+ return d.h > box.h ? { w: d.w, h: box.h } : d;
105
+ },
106
+ rpage,
107
+ 8,
108
+ feedFocus >= 0 ? feedFocus : undefined,
109
+ true,
110
+ );
111
+
112
+ const onSwipe = (dir: -1 | 1) => {
113
+ if (recipeId) {
114
+ const next = focusIndex + dir;
115
+ const row = allRows[next];
116
+ if (focusIndex < 0 || !row) return;
117
+ replaceUrlState(
118
+ recipeHref(dataset, lang, { ...nav, id: row.id, rpage: undefined }),
119
+ );
120
+ return;
121
+ }
122
+ if (list.pages <= 1) return;
123
+ replaceUrlState(
124
+ recipeHref(dataset, lang, {
125
+ ...nav,
126
+ rpage: (list.page + dir + list.pages) % list.pages,
127
+ }),
128
+ );
129
+ };
130
+
131
+ const body = index && !index.types.length && !indexLoading ? (
132
+ <RecipeCardGrid
133
+ session={session}
134
+ rows={EMPTY_ROWS}
135
+ boxRef={boxRef}
136
+ empty={t('recipe.no_dump')}
137
+ />
138
+ ) : (
139
+ <RecipeCardGrid
140
+ session={session}
141
+ rows={list.shown}
142
+ boxRef={boxRef}
143
+ maxH={list.box.h}
144
+ maxW={list.box.w}
145
+ loading={index == null || (shown != null && rows === undefined)}
146
+ empty={t('recipe.empty_type')}
147
+ onSwipe={onSwipe}
148
+ />
149
+ );
150
+
151
+ return (
152
+ <RecipeFrame
153
+ session={session}
154
+ list={list}
155
+ strip={
156
+ <RecipeTypeTabs
157
+ session={session}
158
+ ids={nonEmptyIds}
159
+ value={shown}
160
+ onChange={(id) => {
161
+ if (id === shown) return;
162
+ replaceUrlState(
163
+ recipeHref(dataset, lang, {
164
+ ...nav,
165
+ type: id,
166
+ id: undefined,
167
+ solo: undefined,
168
+ rpage: undefined,
169
+ }),
170
+ );
171
+ }}
172
+ />
173
+ }
174
+ header={
175
+ <PlaceHeader session={session} overline={t('recipe.axis_type')} />
176
+ }
177
+ rail={
178
+ <WorkstationRail
179
+ session={session}
180
+ workstations={
181
+ shown ? categoriesById.get(shown)?.workstations : undefined
182
+ }
183
+ />
184
+ }
185
+ >
186
+ {body}
187
+ </RecipeFrame>
188
+ );
189
+ }
@@ -0,0 +1,42 @@
1
+ 'use client';
2
+
3
+ import { Factory } from 'lucide-react';
4
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
5
+ import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
6
+ import { stackIdFromRef } from '@terrafirmagreg-team/game/lib/dump/contract/ref';
7
+ import type { TaggedReference } from '@terrafirmagreg-team/game/lib/dump/contract/ref';
8
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
9
+
10
+ export function WorkstationRail({
11
+ session,
12
+ workstations,
13
+ }: {
14
+ session: RecipeSession;
15
+ workstations: TaggedReference[] | undefined;
16
+ }) {
17
+ if (!workstations?.length) return null;
18
+ const { lang, names, nav } = session;
19
+ return (
20
+ <div className="flex max-h-full self-start flex-col flex-wrap content-start items-center gap-1 rounded-lg border border-border bg-muted/60 p-1">
21
+ <Factory
22
+ className="m-1 size-3.5 shrink-0 text-muted-foreground"
23
+ aria-hidden
24
+ />
25
+ {workstations.map((ref) => {
26
+ const id = stackIdFromRef(ref);
27
+ return (
28
+ <Entry
29
+ key={id}
30
+ reference={ref}
31
+ name={recipeItemName(names, lang, id)}
32
+ variant="chip"
33
+ size="lg"
34
+ className="size-9 shrink-0"
35
+ tab={nav.tab}
36
+ search={nav.search}
37
+ />
38
+ );
39
+ })}
40
+ </div>
41
+ );
42
+ }
@@ -0,0 +1,57 @@
1
+ 'use client';
2
+
3
+ import { Play, Share2, Trash2 } from 'lucide-react';
4
+ import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
5
+ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import { RecipeToolbar } from '@terrafirmagreg-team/recipe/components/views/browser/toolbar';
7
+ import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
8
+ import { CalcHelp } from './help';
9
+
10
+ export function CalcActions({
11
+ session,
12
+ shared,
13
+ onShare,
14
+ hasTargets,
15
+ onAutoBuild,
16
+ onClear,
17
+ }: {
18
+ session: RecipeSession;
19
+ shared: boolean;
20
+ onShare: () => void;
21
+ hasTargets: boolean;
22
+ onAutoBuild: () => void;
23
+ onClear: () => void;
24
+ }) {
25
+ const t = useTranslations();
26
+ return (
27
+ <>
28
+ <RecipeToolbar session={session} />
29
+ <IconButton
30
+ overlay
31
+ label={shared ? t('recipe.copied') : t('recipe.calc.share')}
32
+ onClick={onShare}
33
+ >
34
+ <Share2 className="size-3.5" />
35
+ </IconButton>
36
+ <CalcHelp />
37
+ {hasTargets ? (
38
+ <IconButton
39
+ overlay
40
+ label={t('recipe.calc.auto.build')}
41
+ onClick={onAutoBuild}
42
+ >
43
+ <Play className="size-3.5" />
44
+ </IconButton>
45
+ ) : null}
46
+ {hasTargets ? (
47
+ <IconButton
48
+ overlay
49
+ label={t('recipe.calc.clear.title')}
50
+ onClick={onClear}
51
+ >
52
+ <Trash2 className="size-3.5" />
53
+ </IconButton>
54
+ ) : null}
55
+ </>
56
+ );
57
+ }