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