feat(editor): Sektionen-Handler + save-Patch mit section_heading

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-19 15:06:12 +02:00
parent b646720a6e
commit 7d6ee04fec

View File

@@ -43,7 +43,8 @@
qty: i.quantity !== null ? String(i.quantity).replace('.', ',') : '', qty: i.quantity !== null ? String(i.quantity).replace('.', ',') : '',
unit: i.unit ?? '', unit: i.unit ?? '',
name: i.name, name: i.name,
note: i.note ?? '' note: i.note ?? '',
section_heading: i.section_heading
})) }))
) )
); );
@@ -52,7 +53,7 @@
); );
function addIngredient() { function addIngredient() {
ingredients = [...ingredients, { qty: '', unit: '', name: '', note: '' }]; ingredients = [...ingredients, { qty: '', unit: '', name: '', note: '', section_heading: null }];
} }
function removeIngredient(idx: number) { function removeIngredient(idx: number) {
ingredients = ingredients.filter((_, i) => i !== idx); ingredients = ingredients.filter((_, i) => i !== idx);
@@ -64,6 +65,16 @@
[next[idx], next[target]] = [next[target], next[idx]]; [next[idx], next[target]] = [next[target], next[idx]];
ingredients = next; ingredients = next;
} }
function addSection(idx: number) {
const next = [...ingredients];
next[idx] = { ...next[idx], section_heading: '' };
ingredients = next;
}
function removeSection(idx: number) {
const next = [...ingredients];
next[idx] = { ...next[idx], section_heading: null };
ingredients = next;
}
function addStep() { function addStep() {
steps = [...steps, { text: '' }]; steps = [...steps, { text: '' }];
} }
@@ -94,13 +105,15 @@
if (qty !== null) rawParts.push(String(qty).replace('.', ',')); if (qty !== null) rawParts.push(String(qty).replace('.', ','));
if (unit) rawParts.push(unit); if (unit) rawParts.push(unit);
rawParts.push(name); rawParts.push(name);
const heading = i.section_heading === null ? null : (i.section_heading.trim() || null);
return { return {
position: idx + 1, position: idx + 1,
quantity: qty, quantity: qty,
unit, unit,
name, name,
note, note,
raw_text: rawParts.join(' ') raw_text: rawParts.join(' '),
section_heading: heading
}; };
}); });
const cleanedSteps: Step[] = steps const cleanedSteps: Step[] = steps
@@ -174,6 +187,8 @@
total={ingredients.length} total={ingredients.length}
onmove={(dir) => moveIngredient(idx, dir)} onmove={(dir) => moveIngredient(idx, dir)}
onremove={() => removeIngredient(idx)} onremove={() => removeIngredient(idx)}
onaddSection={() => addSection(idx)}
onremoveSection={() => removeSection(idx)}
/> />
{/each} {/each}
</ul> </ul>