diff --git a/src/lib/components/RecipeEditor.svelte b/src/lib/components/RecipeEditor.svelte index e0d1843..8e66cda 100644 --- a/src/lib/components/RecipeEditor.svelte +++ b/src/lib/components/RecipeEditor.svelte @@ -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}