made all document fields editable

This commit is contained in:
2025-07-11 23:13:09 +02:00
parent 2a7e9df334
commit e3e4dc16f9
5 changed files with 94 additions and 27 deletions

View File

@@ -37,5 +37,5 @@
{#if editable && editing}
<input bind:value={editValue} onkeyup={typed} autofocus />
{:else}
<div onclick={startEdit}>{value}</div>
<span onclick={startEdit}>{value}</span>
{/if}

View File

@@ -0,0 +1,50 @@
<script>
let { editable = false, value = $bindable(null) } = $props();
let editing = $state(false);
let editValue = $state(value);
let timer = null;
function applyEdit(){
value = editValue;
editing = false;
}
function resetEdit(){
editing = false;
editValue = value;
}
function startEdit(){
editing = editable;
}
function typed(ev){
if (ev.keyCode == 13 && ev.ctrlKey) applyEdit();
if (ev.keyCode == 27) resetEdit();
}
</script>
<style>
textarea{
width: 100%;
min-height: 100px;
}
div{
min-width: 40px;
min-height: 20px;
}
div:hover{
border: 1px dotted;
}
</style>
{#if editable && editing}
<textarea bind:value={editValue} onkeyup={typed} autofocus></textarea>
{:else}
<div onclick={startEdit}>
{#each value.split("\n") as line}
{line}<br/>
{/each}
</div>
{/if}