@terrafirmagreg-team/recipe 1.2.43 → 1.2.44
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.
- package/package.json +4 -3
- package/src/components/cards/calc-add-item.tsx +2 -1
- package/src/components/views/browser/frame.tsx +36 -9
- package/src/components/views/browser/query-controls.tsx +6 -1
- package/src/components/views/browser/type-view.tsx +21 -2
- package/src/components/views/calc/calculator/help.tsx +6 -6
- package/src/components/views/calc/calculator/index.tsx +29 -6
- package/src/components/views/calc/edge.tsx +197 -113
- package/src/components/views/calc/flow/index.tsx +120 -39
- package/src/components/views/calc/flow/notes.tsx +282 -0
- package/src/components/views/calc/flow/toolbar.tsx +46 -1
- package/src/components/views/calc/flow/view-menu.tsx +11 -0
- package/src/components/views/calc/material-picker.tsx +112 -0
- package/src/components/views/calc/node-card/badges.tsx +2 -2
- package/src/components/views/calc/node-card/full.tsx +13 -2
- package/src/components/views/calc/node-card/menu.tsx +0 -17
- package/src/components/views/calc/node-card/port-cells.tsx +4 -4
- package/src/components/views/calc/node-card/ports.tsx +6 -1
- package/src/components/views/calc/recipe-picker/body.tsx +21 -5
- package/src/components/views/calc/recipe-picker/footer.tsx +1 -28
- package/src/hooks/calc/flow/use-handlers.ts +21 -14
- package/src/hooks/calc/flow/use-layout.ts +7 -7
- package/src/hooks/calc/flow/use-shift-held.ts +25 -0
- package/src/hooks/calc/use-actions.ts +126 -61
- package/src/hooks/calc/use-amounts.ts +8 -5
- package/src/hooks/calc/use-data.ts +11 -8
- package/src/hooks/calc/use-history.ts +98 -0
- package/src/hooks/calc/use-pipe-edit.ts +21 -0
- package/src/hooks/calc/use-snap.ts +17 -0
- package/src/hooks/calc/use-storage.ts +2 -1
- package/src/hooks/use-add-to-calc.ts +2 -1
- package/src/hooks/use-item-press.ts +4 -2
- package/src/hooks/use-query.ts +22 -1
- package/src/hooks/use-session.ts +2 -0
- package/src/lib/browser/row-search.test.ts +55 -0
- package/src/lib/browser/row-search.ts +24 -0
- package/src/lib/calc/flow.ts +31 -26
- package/src/lib/calc/member.test.ts +5 -5
- package/src/lib/calc/pack.ts +6 -6
- package/src/lib/calc/{wire.test.ts → pipe.test.ts} +5 -5
- package/src/lib/calc/{wire.ts → pipe.ts} +9 -9
- package/src/lib/calc/route/index.ts +1 -0
- package/src/lib/calc/scheme.test.ts +7 -7
- package/src/lib/calc/scheme.ts +16 -15
- package/src/lib/calc/storage/entry.test.ts +66 -0
- package/src/lib/calc/storage/entry.ts +29 -7
- package/src/lib/calc/storage/store.ts +3 -1
- package/src/lib/calc/tree/share.test.ts +102 -0
- package/src/lib/calc/tree/share.ts +43 -13
- package/src/lib/links.ts +3 -0
- package/src/types/calc-flow-props.ts +13 -2
- package/src/types/calc.ts +23 -3
- package/src/types/index.ts +3 -0
- package/styles/calc.css +65 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/recipe",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Recipe viewer and calculator",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@terrafirmagreg-team/preview": "^1.2.12",
|
|
32
32
|
"@terrafirmagreg-team/sites": "^1.2.5",
|
|
33
33
|
"@terrafirmagreg-team/translate": "^1.2.17",
|
|
34
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
34
|
+
"@terrafirmagreg-team/ui": "^1.2.33",
|
|
35
35
|
"@types/pathfinding": "^0.1.0",
|
|
36
36
|
"comlink": "^4.4.2",
|
|
37
37
|
"fflate": "0.8.3",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"fumadocs-core": ">=16",
|
|
44
44
|
"next": ">=15",
|
|
45
|
-
"react": ">=19"
|
|
45
|
+
"react": ">=19",
|
|
46
|
+
"react-dom": ">=19"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@types/node": "^26.6.6",
|
|
@@ -5,7 +5,10 @@ import { useRef, type ReactNode } from 'react';
|
|
|
5
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
6
|
import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
|
|
7
7
|
import { useElementSize } from '@terrafirmagreg-team/ui/hooks/use-element-size';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
QueryPager,
|
|
10
|
+
QuerySearch,
|
|
11
|
+
} from '@terrafirmagreg-team/recipe/components/views/browser/query-controls';
|
|
9
12
|
import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
|
|
10
13
|
import { RecipeToolbar } from '@terrafirmagreg-team/recipe/components/views/browser/toolbar';
|
|
11
14
|
import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
@@ -27,6 +30,8 @@ export function RecipeFrame({
|
|
|
27
30
|
strip,
|
|
28
31
|
rail,
|
|
29
32
|
back,
|
|
33
|
+
search,
|
|
34
|
+
searchPersist = true,
|
|
30
35
|
onPageChange,
|
|
31
36
|
children,
|
|
32
37
|
}: {
|
|
@@ -36,6 +41,8 @@ export function RecipeFrame({
|
|
|
36
41
|
strip?: ReactNode;
|
|
37
42
|
rail?: ReactNode;
|
|
38
43
|
back?: { href: string; label: string };
|
|
44
|
+
search?: boolean;
|
|
45
|
+
searchPersist?: boolean;
|
|
39
46
|
onPageChange?: (page: number) => void;
|
|
40
47
|
children: ReactNode;
|
|
41
48
|
}) {
|
|
@@ -43,21 +50,26 @@ export function RecipeFrame({
|
|
|
43
50
|
const resolved = useResolvedLang();
|
|
44
51
|
const railBoxRef = useRef<HTMLDivElement | null>(null);
|
|
45
52
|
const railSize = useElementSize(railBoxRef);
|
|
46
|
-
const
|
|
47
|
-
if (!list
|
|
48
|
-
const
|
|
53
|
+
const setPage = (next: number) => {
|
|
54
|
+
if (!list) return;
|
|
55
|
+
const clamped = Math.min(list.pages - 1, Math.max(0, next));
|
|
56
|
+
if (clamped === list.page) return;
|
|
49
57
|
if (onPageChange) {
|
|
50
|
-
onPageChange(
|
|
58
|
+
onPageChange(clamped);
|
|
51
59
|
return;
|
|
52
60
|
}
|
|
53
61
|
replaceUrlState(
|
|
54
62
|
recipeHref(session.dataset, resolved, {
|
|
55
63
|
...session.nav,
|
|
56
64
|
id: undefined,
|
|
57
|
-
rpage:
|
|
65
|
+
rpage: clamped > 0 ? clamped + 1 : undefined,
|
|
58
66
|
}),
|
|
59
67
|
);
|
|
60
68
|
};
|
|
69
|
+
const goPage = (dir: number) => {
|
|
70
|
+
if (!list || list.pages <= 1) return;
|
|
71
|
+
setPage((list.page + dir + list.pages) % list.pages);
|
|
72
|
+
};
|
|
61
73
|
const onPagerWheel = (event: { deltaY: number }) =>
|
|
62
74
|
goPage(event.deltaY > 0 ? 1 : -1);
|
|
63
75
|
return (
|
|
@@ -84,7 +96,7 @@ export function RecipeFrame({
|
|
|
84
96
|
</div>
|
|
85
97
|
</div>
|
|
86
98
|
{list ? (
|
|
87
|
-
<div onWheel={onPagerWheel} className="mx-auto w-full sm:max-w-90">
|
|
99
|
+
<div onWheel={onPagerWheel} className="mx-auto w-full pt-2 sm:max-w-90">
|
|
88
100
|
{onPageChange ? (
|
|
89
101
|
<Pager
|
|
90
102
|
layout="spread"
|
|
@@ -93,7 +105,6 @@ export function RecipeFrame({
|
|
|
93
105
|
to={list.to}
|
|
94
106
|
total={list.total}
|
|
95
107
|
label={t('{page}/{pages}', { note: 'recipe.page_of' })}
|
|
96
|
-
className="pt-2"
|
|
97
108
|
onPage={onPageChange}
|
|
98
109
|
/>
|
|
99
110
|
) : (
|
|
@@ -103,7 +114,6 @@ export function RecipeFrame({
|
|
|
103
114
|
query={session.query}
|
|
104
115
|
list={list}
|
|
105
116
|
label={t('{page}/{pages}', { note: 'recipe.page_of' })}
|
|
106
|
-
className="pt-2"
|
|
107
117
|
/>
|
|
108
118
|
)}
|
|
109
119
|
</div>
|
|
@@ -122,6 +132,23 @@ export function RecipeFrame({
|
|
|
122
132
|
{children}
|
|
123
133
|
</div>
|
|
124
134
|
</div>
|
|
135
|
+
{search ? (
|
|
136
|
+
<div className="flex shrink-0 justify-center pb-1 pt-1.5">
|
|
137
|
+
<div className="w-56 sm:w-72">
|
|
138
|
+
<QuerySearch
|
|
139
|
+
dataset={session.dataset}
|
|
140
|
+
param="rsearch"
|
|
141
|
+
params={{ ...session.nav, id: undefined, rpage: undefined }}
|
|
142
|
+
query={session.rquery}
|
|
143
|
+
onQuery={session.setRquery}
|
|
144
|
+
persist={searchPersist}
|
|
145
|
+
placeholder={t('Search materials', {
|
|
146
|
+
note: 'recipe.search_materials',
|
|
147
|
+
})}
|
|
148
|
+
/>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
) : null}
|
|
125
152
|
</div>
|
|
126
153
|
);
|
|
127
154
|
}
|
|
@@ -23,15 +23,19 @@ type QueryNav = {
|
|
|
23
23
|
export function QuerySearch({
|
|
24
24
|
dataset,
|
|
25
25
|
params,
|
|
26
|
+
param = 'search',
|
|
26
27
|
query,
|
|
27
28
|
onQuery,
|
|
28
29
|
placeholder,
|
|
29
30
|
className,
|
|
31
|
+
persist = true,
|
|
30
32
|
}: QueryNav & {
|
|
33
|
+
param?: 'search' | 'rsearch';
|
|
31
34
|
query: string;
|
|
32
35
|
onQuery: (query: string) => void;
|
|
33
36
|
placeholder?: string;
|
|
34
37
|
className?: string;
|
|
38
|
+
persist?: boolean;
|
|
35
39
|
}) {
|
|
36
40
|
const resolved = useResolvedLang();
|
|
37
41
|
return (
|
|
@@ -46,10 +50,11 @@ export function QuerySearch({
|
|
|
46
50
|
onChange={(event) => {
|
|
47
51
|
const next = event.target.value;
|
|
48
52
|
onQuery(next);
|
|
53
|
+
if (!persist) return;
|
|
49
54
|
replaceUrlState(
|
|
50
55
|
recipeHref(dataset, resolved, {
|
|
51
56
|
...params,
|
|
52
|
-
|
|
57
|
+
[param]: next || undefined,
|
|
53
58
|
}),
|
|
54
59
|
);
|
|
55
60
|
}}
|
|
@@ -14,8 +14,13 @@ import { useFitPages } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
|
|
|
14
14
|
import {
|
|
15
15
|
loadTypeRows,
|
|
16
16
|
nonEmptyCategoryIds,
|
|
17
|
+
recipeItemName,
|
|
17
18
|
resolveRecipeRows,
|
|
18
19
|
} from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
20
|
+
import {
|
|
21
|
+
rowMatchesTerms,
|
|
22
|
+
rowSearchTerms,
|
|
23
|
+
} from '@terrafirmagreg-team/recipe/lib/browser/row-search';
|
|
19
24
|
import { RECIPE_ALL_TYPE, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
20
25
|
import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
|
|
21
26
|
import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
|
|
@@ -71,12 +76,25 @@ export function TypeView({ session }: { session: RecipeSession }) {
|
|
|
71
76
|
[dataset, index, recipeId, rows, focusIndex],
|
|
72
77
|
);
|
|
73
78
|
const solo = recipeId != null && session.solo === '1';
|
|
79
|
+
const terms = rowSearchTerms(session.rquery);
|
|
80
|
+
const filteredRows = terms.length
|
|
81
|
+
? allRows.filter((row) =>
|
|
82
|
+
rowMatchesTerms(row, terms, (id) =>
|
|
83
|
+
recipeItemName(session.names, session.lang, id),
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
: allRows;
|
|
74
87
|
const feedRows = solo
|
|
75
88
|
? focusIndex >= 0
|
|
76
89
|
? [allRows[focusIndex]]
|
|
77
90
|
: (focusRes.value ?? EMPTY_ROWS)
|
|
78
|
-
:
|
|
79
|
-
const feedFocus =
|
|
91
|
+
: filteredRows;
|
|
92
|
+
const feedFocus =
|
|
93
|
+
solo && focusIndex >= 0
|
|
94
|
+
? 0
|
|
95
|
+
: recipeId
|
|
96
|
+
? filteredRows.findIndex((row) => row.id === recipeId)
|
|
97
|
+
: -1;
|
|
80
98
|
useEffect(() => {
|
|
81
99
|
if (!recipeId || !index || rows === undefined || focusIndex >= 0) return;
|
|
82
100
|
if (focusRes.pending) return;
|
|
@@ -146,6 +164,7 @@ export function TypeView({ session }: { session: RecipeSession }) {
|
|
|
146
164
|
<RecipeFrame
|
|
147
165
|
session={session}
|
|
148
166
|
list={list}
|
|
167
|
+
search
|
|
149
168
|
strip={
|
|
150
169
|
<RecipeTypeTabs
|
|
151
170
|
session={session}
|
|
@@ -78,19 +78,19 @@ export function CalcHelp() {
|
|
|
78
78
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
79
79
|
<span className="size-3.5 rounded-sm border border-emerald-500" />
|
|
80
80
|
</span>
|
|
81
|
-
{t('Input port: click to pick a supplier or drag a
|
|
81
|
+
{t('Input port: click to pick a supplier or drag a pipe', { note: 'recipe.calc.help.port_in' })}
|
|
82
82
|
</li>
|
|
83
83
|
<li className="flex items-center gap-2">
|
|
84
84
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
85
85
|
<span className="size-3.5 rounded-sm border border-red-400" />
|
|
86
86
|
</span>
|
|
87
|
-
{t('Output port: click to pick a recipe or drag a
|
|
87
|
+
{t('Output port: click to pick a recipe or drag a pipe', { note: 'recipe.calc.help.port_out' })}
|
|
88
88
|
</li>
|
|
89
89
|
<li className="flex items-center gap-2">
|
|
90
90
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
91
91
|
<span className="size-3.5 rounded-sm border border-dotted border-emerald-500" />
|
|
92
92
|
</span>
|
|
93
|
-
{t('Catalyst: needed but not consumed;
|
|
93
|
+
{t('Catalyst: needed but not consumed; pipe it or click to pick a supplier', { note: 'recipe.calc.help.port_cat' })}
|
|
94
94
|
</li>
|
|
95
95
|
<li className="flex items-center gap-2">
|
|
96
96
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
@@ -127,7 +127,7 @@ export function CalcHelp() {
|
|
|
127
127
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
128
128
|
<span className="h-0 w-4 border-t border-dashed border-primary/70" />
|
|
129
129
|
</span>
|
|
130
|
-
{t('Drag port to port to link; drag a
|
|
130
|
+
{t('Drag port to port to link; drag a pipe end to retarget', { note: 'recipe.calc.help.edge_link' })}
|
|
131
131
|
</li>
|
|
132
132
|
<li className="flex items-center gap-2">
|
|
133
133
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
@@ -135,13 +135,13 @@ export function CalcHelp() {
|
|
|
135
135
|
16
|
|
136
136
|
</span>
|
|
137
137
|
</span>
|
|
138
|
-
{t('Flow on a
|
|
138
|
+
{t('Flow on a pipe - shows on hover; click to cap the amount', { note: 'recipe.calc.help.edge_flow' })}
|
|
139
139
|
</li>
|
|
140
140
|
<li className="flex items-center gap-2">
|
|
141
141
|
<span className="flex w-5 shrink-0 items-center justify-center">
|
|
142
142
|
<Scissors className="size-3.5 text-muted-foreground" />
|
|
143
143
|
</span>
|
|
144
|
-
{t('Shift +
|
|
144
|
+
{t('Shift + click a pipe to disconnect it', { note: 'recipe.calc.help.edge_cut' })}
|
|
145
145
|
</li>
|
|
146
146
|
</ul>
|
|
147
147
|
</section>
|
|
@@ -17,6 +17,8 @@ import { useCalcData } from '@terrafirmagreg-team/recipe/hooks/calc/use-data';
|
|
|
17
17
|
import { useCalcViewMode } from '@terrafirmagreg-team/recipe/hooks/calc/use-view-mode';
|
|
18
18
|
import { useCalcFarMode } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
|
|
19
19
|
import { useCalcRecipeIdsMode } from '@terrafirmagreg-team/recipe/hooks/calc/use-recipe-ids';
|
|
20
|
+
import { useCalcSnap } from '@terrafirmagreg-team/recipe/hooks/calc/use-snap';
|
|
21
|
+
import { useCalcHistory } from '@terrafirmagreg-team/recipe/hooks/calc/use-history';
|
|
20
22
|
|
|
21
23
|
export function Calculator({ session }: { session: RecipeSession }) {
|
|
22
24
|
const t = useTranslations();
|
|
@@ -24,10 +26,12 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
24
26
|
const [mode, setMode] = useCalcViewMode();
|
|
25
27
|
const [farCards, setFarCards] = useCalcFarMode();
|
|
26
28
|
const [recipeIds, setRecipeIds] = useCalcRecipeIdsMode();
|
|
29
|
+
const [snap, setSnap] = useCalcSnap();
|
|
27
30
|
const {
|
|
28
31
|
cards,
|
|
29
|
-
|
|
32
|
+
pipes,
|
|
30
33
|
tagSelections,
|
|
34
|
+
notes,
|
|
31
35
|
tabs,
|
|
32
36
|
activeTabId,
|
|
33
37
|
history,
|
|
@@ -52,6 +56,17 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
52
56
|
settled,
|
|
53
57
|
shareFailed,
|
|
54
58
|
} = useCalcData(session);
|
|
59
|
+
const {
|
|
60
|
+
write: persistTracked,
|
|
61
|
+
undo,
|
|
62
|
+
redo,
|
|
63
|
+
canUndo,
|
|
64
|
+
canRedo,
|
|
65
|
+
} = useCalcHistory(
|
|
66
|
+
{ cards, pipes, tagSelections, notes },
|
|
67
|
+
persist,
|
|
68
|
+
activeTabId ?? undefined,
|
|
69
|
+
);
|
|
55
70
|
const deferredNodes = useDeferredValue(nodes);
|
|
56
71
|
const deferredFlows = useDeferredValue(flows);
|
|
57
72
|
const deferredLangMap = useDeferredValue(session.langMap);
|
|
@@ -61,10 +76,11 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
61
76
|
const { displayCards, pendingCrafts, flushAmounts, onCrafts } =
|
|
62
77
|
useCalcAmounts({
|
|
63
78
|
cards,
|
|
64
|
-
|
|
79
|
+
pipes,
|
|
65
80
|
tagSelections,
|
|
81
|
+
notes,
|
|
66
82
|
resolved: deferredNodes,
|
|
67
|
-
persist,
|
|
83
|
+
persist: persistTracked,
|
|
68
84
|
});
|
|
69
85
|
const {
|
|
70
86
|
shared,
|
|
@@ -73,15 +89,17 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
73
89
|
onShare,
|
|
74
90
|
flowData,
|
|
75
91
|
onMoveCards,
|
|
92
|
+
onAddNote,
|
|
76
93
|
onClear,
|
|
77
94
|
} = useCalcActions({
|
|
78
95
|
dataset,
|
|
79
96
|
lang,
|
|
80
97
|
linkVersion: session.nav.version,
|
|
81
98
|
cards: displayCards,
|
|
82
|
-
|
|
99
|
+
pipes,
|
|
83
100
|
tagSelections,
|
|
84
|
-
|
|
101
|
+
notes,
|
|
102
|
+
persist: persistTracked,
|
|
85
103
|
recipeDefaults,
|
|
86
104
|
setRecipeDefault,
|
|
87
105
|
recipeBody,
|
|
@@ -143,7 +161,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
143
161
|
</LeftSidebarPortal>
|
|
144
162
|
<CalcFlow
|
|
145
163
|
nodes={deferredNodes}
|
|
146
|
-
|
|
164
|
+
pipes={pipes}
|
|
147
165
|
flows={deferredFlows}
|
|
148
166
|
cards={displayCards}
|
|
149
167
|
dataset={dataset}
|
|
@@ -155,6 +173,11 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
155
173
|
onFarCardsChange={setFarCards}
|
|
156
174
|
recipeIds={recipeIds}
|
|
157
175
|
onRecipeIdsChange={setRecipeIds}
|
|
176
|
+
snap={snap}
|
|
177
|
+
onSnapChange={setSnap}
|
|
178
|
+
notes={notes}
|
|
179
|
+
onAddNote={onAddNote}
|
|
180
|
+
history={{ canUndo, canRedo, onUndo: undo, onRedo: redo }}
|
|
158
181
|
treeReady={settled}
|
|
159
182
|
resetGen={resetGen}
|
|
160
183
|
canvasId={activeTabId ?? undefined}
|