implemented editing of document in GUI + respective handlers in backend

This commit is contained in:
2025-07-12 23:34:05 +02:00
parent 2cc4d43e7c
commit 26fa72ef84
12 changed files with 190 additions and 81 deletions

View File

@@ -1,16 +1,20 @@
<script>
import { activeField } from './field_sync.svelte.js';
let { editable = false, value = $bindable(null) } = $props();
let { editable = false, value = $bindable(null), onSet = (newVal) => {} } = $props();
let editing = $state(false);
let editValue = $state({source:value.source,rendered:value.rendered});
let timer = null;
function applyEdit(){
value.source = editValue.source;
value.rendered = editValue.rendered;
editing = false;
async function applyEdit(){
let success = await onSet(editValue.source);
if (success) {
value.source = editValue.source;
value.rendered = editValue.rendered;
editing = false;
} else resetEdit();
}
function resetEdit(){
@@ -54,12 +58,12 @@
min-width: 40px;
min-height: 20px;
}
div:hover{
div.editable:hover{
border: 1px dotted;
}
</style>
{#if editable && editing}
{#if editing}
<textarea bind:value={editValue.source} onkeyup={typed} autofocus></textarea>
{/if}
<div onclick={startEdit}>{@html editValue.rendered}</div>
<div onclick={startEdit} class={{editable}}>{@html editValue.rendered}</div>