From ad62a440d31a07cfb6a16cc04bf84e25cf7c3a86 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 15 May 2026 13:19:32 +0200 Subject: [PATCH] Route Soma clipboard reset through timers --- .../clipboard/clipboard-provider.svelte.ts | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/uix/soma/components/clipboard/clipboard-provider.svelte.ts b/src/uix/soma/components/clipboard/clipboard-provider.svelte.ts index a5fa2faaa..828f6f2df 100644 --- a/src/uix/soma/components/clipboard/clipboard-provider.svelte.ts +++ b/src/uix/soma/components/clipboard/clipboard-provider.svelte.ts @@ -5,7 +5,7 @@ import { Soma } from '../../core/soma.svelte'; import { CLIPBOARD_LANGS } from './langs'; import { clipboardMorfo } from '../../../morfo/components/clipboard'; import type { SomaRuntime, SomaRuntimePart } from '../../runtime.svelte'; - +import type { TimerHandle } from '$timer'; // ── Root provider ────────────────────────────────────────────────────────── @@ -37,7 +37,7 @@ export class ClipboardProvider { } copied = $state(false); - private resetTimer: ReturnType | null = null; + private resetTimer: TimerHandle | null = null; private constructor(opts: ClipboardOpts) { this.opts = opts; @@ -56,9 +56,7 @@ export class ClipboardProvider { }); $effect(() => { - return () => { - if (this.resetTimer) clearTimeout(this.resetTimer); - }; + return () => this.clearResetTimer(); }); } @@ -79,17 +77,33 @@ export class ClipboardProvider { this.copied = true; this.opts.onCopy.current?.(value); - if (this.resetTimer) clearTimeout(this.resetTimer); - this.resetTimer = setTimeout(() => { - this.copied = false; - this.resetTimer = null; - }, this.opts.timeout.current); + this.clearResetTimer(); + this.resetTimer = this.soma.uix.timers.schedule( + this.resetTimerKey, + this.opts.timeout.current, + () => { + this.copied = false; + this.resetTimer = null; + }, + { replace: true, meta: { component: 'clipboard', action: 'reset-copied' } } + ); } catch (err) { this.opts.onError.current?.(err); throw err; } }; + private clearResetTimer() { + if (this.resetTimer) { + this.resetTimer.cancel(); + this.resetTimer = null; + } + } + + private get resetTimerKey() { + return `soma:clipboard:${this.opts.id.current}:reset`; + } + readonly snippetProps = $derived.by(() => ({ value: this.opts.value.current, copied: this.copied,