diff --git a/src/App.svelte b/src/App.svelte index 3045f4bf..c460dbee 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -3,7 +3,7 @@ import { type Cell, cellFactory } from "./cells/Cells"; import { BaseCell } from "./cells/BaseCell"; import MathCell from "./cells/MathCell.svelte"; - import TableCell from "./cells/TableCell"; + import TableCell from "./cells/TableCell.svelte"; import DataTableCell, { type InterpolationFunction } from "./cells/DataTableCell"; import PlotCell from "./cells/PlotCell"; import PiecewiseCell from "./cells/PiecewiseCell.svelte"; diff --git a/src/Cell.svelte b/src/Cell.svelte index f47af2c4..41a90c31 100644 --- a/src/Cell.svelte +++ b/src/Cell.svelte @@ -17,7 +17,7 @@ import MathCell from "./cells/MathCell.svelte"; import PlotCell from "./cells/PlotCell"; - import TableCell from "./cells/TableCell"; + import TableCell from "./cells/TableCell.svelte"; import DataTableCell from "./cells/DataTableCell"; import DocumentationCell from "./cells/DocumentationCell.svelte"; import PiecewiseCell from "./cells/PiecewiseCell.svelte"; @@ -281,8 +281,8 @@ /> {:else if cell instanceof TableCell} void; + insertInsertCellAfter: (arg: {detail: {index: number}}) => void; + } + + let { + index, + tableCell, + insertMathCellAfter, + insertInsertCellAfter + }: Props = $props(); + + let numColumns = $derived(tableCell.parameterFields.length); + let numRows = $derived(tableCell.rowLabels.length); + let hideUnselected = $derived(tableCell.hideUnselected); + let hideToolbar = $derived($activeCell !== index); let containerDiv: HTMLDivElement; - let hideToolbar = true; export function getMarkdown() { const row = tableCell.selectedRow; @@ -74,11 +89,6 @@ return result; } - const dispatch = createEventDispatcher<{ - insertMathCellAfter: {index: number}; - insertInsertCellAfter: {index: number}; - }>(); - onMount(() => { if (tableCell.rowJsons.length > 0) { (tableCell.richTextInstance as any).setContents(tableCell.rowJsons[tableCell.selectedRow]); @@ -99,7 +109,6 @@ } } - function handleSelectedRowChange() { $mathCellChanged = true; tableCell.parseTableStatements(); @@ -187,16 +196,11 @@ $cells[index] = $cells[index]; } - $: if ($activeCell === index) { + $effect( () => { + if ($activeCell === index) { focus(); } - - $: numColumns = tableCell.parameterFields.length; - $: numRows = tableCell.rowLabels.length; - $: hideUnselected = tableCell.hideUnselected; - - $: hideToolbar = $activeCell !== index; - + }); @@ -285,8 +289,8 @@ tableCell.rowJsons[tableCell.selectedRow] = e.detail.json; $nonMathCellChanged = true; }} - shiftEnter={() => dispatch("insertMathCellAfter", {index: index})} - modifierEnter={() => dispatch("insertInsertCellAfter", {index: index})} + shiftEnter={() => insertMathCellAfter({detail: {index: index}})} + modifierEnter={() => insertInsertCellAfter({detail: {index: index}})} /> {/if} @@ -306,8 +310,8 @@ parseLatex(e.latex, j, mathField)} - shiftEnter={() => dispatch("insertMathCellAfter", {index: index})} - modifierEnter={() => dispatch("insertInsertCellAfter", {index: index})} + shiftEnter={() => insertMathCellAfter({detail: {index: index}})} + modifierEnter={() => insertInsertCellAfter({detail: {index: index}})} mathField={mathField} parsingError={mathField.parsingError} bind:this={mathField.element} @@ -333,8 +337,8 @@ parseLatex(e.latex, j)} - shiftEnter={() => dispatch("insertMathCellAfter", {index: index})} - modifierEnter={() => dispatch("insertInsertCellAfter", {index: index})} + shiftEnter={() => insertMathCellAfter({detail: {index: index}})} + modifierEnter={() => insertInsertCellAfter({detail: {index: index}})} mathField={mathField} parsingError={mathField.parsingError} bind:this={mathField.element} @@ -368,15 +372,15 @@ name={`selected_row_${index}`} bind:group={tableCell.selectedRow} value={i} - on:change={handleSelectedRowChange} + onchange={handleSelectedRowChange} > handleEnter(i)} - on:shiftEnter={() => dispatch("insertMathCellAfter", {index: index})} - on:modifierEnter={() => dispatch("insertInsertCellAfter", {index: index})} + enter={() => handleEnter(i)} + shiftEnter={() => insertMathCellAfter({detail: {index: index}})} + modifierEnter={() => insertInsertCellAfter({detail: {index: index}})} id={`row-label-${index}-${i}`} bind:textContent={tableCell.rowLabels[i].label} - on:input={() => $nonMathCellChanged=true} + oninput={() => $nonMathCellChanged=true} > @@ -395,8 +399,8 @@ editable={true} update={(e) => parseLatex(e.latex, j, mathField)} enter={() => handleEnter(i)} - shiftEnter={() => dispatch("insertMathCellAfter", {index: index})} - modifierEnter={() => dispatch("insertInsertCellAfter", {index: index})} + shiftEnter={() => insertMathCellAfter({detail: {index: index}})} + modifierEnter={() => insertInsertCellAfter({detail: {index: index}})} mathField={mathField} parsingError={mathField.parsingError} bind:this={mathField.element} diff --git a/src/TextBox.svelte b/src/TextBox.svelte index f5785a09..07ec986f 100644 --- a/src/TextBox.svelte +++ b/src/TextBox.svelte @@ -1,25 +1,34 @@