implemented task editing right from the project list

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-07-25 22:03:53 +02:00
parent be0435db1b
commit 5bc84f1321
7 changed files with 284 additions and 26 deletions

View File

@@ -2,10 +2,17 @@
import { activeField } from './field_sync.svelte.js';
import { t } from '../translations.svelte.js';
let { editable = false, value = $bindable(null), onSet = (newVal) => {return true;} } = $props();
let {
editable = false,
onclick = evt => {},
onSet = newVal => {return true;},
type = 'div',
value = $bindable(null)
} = $props();
let editing = $state(false);
let editValue = value;
let start = 0;
async function applyEdit(){
let success = await onSet(editValue);
@@ -28,6 +35,35 @@
if (ev.keyCode == 27) resetEdit();
}
function measured(evt,duration){
if (duration < 500){
onclick(evt);
} else {
startEdit();
}
}
function onmousedown(evt){
evt.preventDefault();
start = evt.timeStamp;
}
function onmouseup(evt){
evt.preventDefault();
measured(evt, evt.timeStamp - start);
}
function ontouchstart(evt){
evt.preventDefault();
start = evt.timeStamp;
}
function ontouchend(evt){
evt.preventDefault();
measured(evt, evt.timeStamp - start);
}
activeField.subscribe((val) => resetEdit());
</script>
@@ -48,5 +84,5 @@
{#if editable && editing}
<input bind:value={editValue} onkeyup={typed} autofocus />
{:else}
<div ondblclick={startEdit} class={{editable}} title={t('double_click_to_edit')} >{value}</div>
<svelte:element this={type} {onmousedown} {onmouseup} {ontouchstart} {ontouchend} class={{editable}} title={t('double_click_to_edit')} >{value}</svelte:element>
{/if}