improved line editor and price editor

This commit is contained in:
2025-07-11 08:41:12 +02:00
parent 50adc206b2
commit 713e6ff8ff
3 changed files with 37 additions and 18 deletions

View File

@@ -2,18 +2,30 @@
let { editable = false, value = $bindable(null) } = $props();
let editing = $state(false);
function toggleEdit(){
editing = !editing;
let editValue = value;
function applyEdit(){
value = editValue;
editing=false;
}
function resetEdit(){
editing = false;
editValue = value;
}
function startEdit(){
editing = editable;
}
function typed(ev){
if (ev.keyCode == 13) toggleEdit();
if (ev.keyCode == 13) applyEdit();
if (ev.keyCode == 27) resetEdit();
}
</script>
{#if editable && editing}
<input bind:value onkeyup={typed} />
<input bind:value={editValue} onkeyup={typed} autofocus />
{:else}
<div onclick={toggleEdit}>{value}</div>
<div onclick={startEdit}>{value}</div>
{/if}