implemented editing of document in GUI + respective handlers in backend
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user