Route Soma timers and document lookup through ActiveDom

active-uix
dev 5 months ago
parent ca9359c32f
commit 9a0ef78b62

@ -94,6 +94,8 @@ function ensurePair(
} }
function scheduleClear( function scheduleClear(
dom: ActiveDom,
target: HTMLElement,
key: string, key: string,
timeout: number, timeout: number,
task: () => void, task: () => void,
@ -106,10 +108,11 @@ function scheduleClear(
}); });
} }
const native = setTimeout(task, timeout); const win = dom.getWindow(target);
const native = win.setTimeout(task, timeout);
return { return {
cancel() { cancel() {
clearTimeout(native); win.clearTimeout(native);
return true; return true;
} }
}; };
@ -132,6 +135,8 @@ function write(
} }
if (pair.timer) pair.timer.cancel(); if (pair.timer) pair.timer.cancel();
pair.timer = scheduleClear( pair.timer = scheduleClear(
dom,
pair.a,
`soma:announce:global:${pair.a.id}`, `soma:announce:global:${pair.a.id}`,
timeout, timeout,
() => { () => {

@ -14,7 +14,7 @@ import {
} from '$libs/reactive'; } from '$libs/reactive';
import type { SomaFocusEvent, SomaKeyboardEvent, SomaMouseEvent, OnChangeFn } from '../../types'; import type { SomaFocusEvent, SomaKeyboardEvent, SomaMouseEvent, OnChangeFn } from '../../types';
import { KEYS, getDirectionalKeys } from '../../keyboard'; import { KEYS, getDirectionalKeys } from '../../keyboard';
import { getDocument, isBrowser } from '$adom'; import { isBrowser } from '$adom';
import { isNumberString } from '../../types/guards'; import { isNumberString } from '../../types/guards';
import { useId } from '../../id'; import { useId } from '../../id';
import { Soma } from '../../core/soma.svelte'; import { Soma } from '../../core/soma.svelte';
@ -759,7 +759,7 @@ export class DateFieldInputProvider {
readonly ariaDescribedBy = $derived.by(() => { readonly ariaDescribedBy = $derived.by(() => {
if (!isBrowser) return undefined; if (!isBrowser) return undefined;
const doc = getDocument(this.opts.ref.current); const doc = this.provider.soma.dom.getDocument(this.opts.ref.current);
const exists = doc?.getElementById(this.provider.descriptionId); const exists = doc?.getElementById(this.provider.descriptionId);
return exists ? this.provider.descriptionId : undefined; return exists ? this.provider.descriptionId : undefined;
}); });

@ -11,7 +11,7 @@ import {
} from '$libs/reactive'; } from '$libs/reactive';
import type { SomaFocusEvent, SomaKeyboardEvent, OnChangeFn } from '../../types'; import type { SomaFocusEvent, SomaKeyboardEvent, OnChangeFn } from '../../types';
import { KEYS, getDirectionalKeys } from '../../keyboard'; import { KEYS, getDirectionalKeys } from '../../keyboard';
import { getDocument, isBrowser } from '$adom'; import { isBrowser } from '$adom';
import { isNumberString } from '../../types/guards'; import { isNumberString } from '../../types/guards';
import { useId } from '../../id'; import { useId } from '../../id';
import { Soma } from '../../core/soma.svelte'; import { Soma } from '../../core/soma.svelte';
@ -517,7 +517,7 @@ export class TimeFieldInputProvider {
readonly ariaDescribedBy = $derived.by(() => { readonly ariaDescribedBy = $derived.by(() => {
if (!isBrowser) return undefined; if (!isBrowser) return undefined;
const doc = getDocument(this.opts.ref.current); const doc = this.provider.soma.dom.getDocument(this.opts.ref.current);
const exists = doc?.getElementById(this.provider.descriptionId); const exists = doc?.getElementById(this.provider.descriptionId);
return exists ? this.provider.descriptionId : undefined; return exists ? this.provider.descriptionId : undefined;
}); });

@ -72,7 +72,7 @@ export function getAnnouncer(dom: ActiveDom | null, target?: Node | null) {
} }
if (!log) return; if (!log) return;
dom.writeText(log, value); dom.writeText(log, value);
return setTimeout(() => { return dom.getWindow(log).setTimeout(() => {
dom.writeText(log, ''); dom.writeText(log, '');
}, timeout); }, timeout);
} }

@ -85,7 +85,8 @@ export class Dismissal {
if (!enabled || !ref) return; if (!enabled || !ref) return;
// Small delay to avoid catching the same event that opened the layer // Small delay to avoid catching the same event that opened the layer
const timer = setTimeout(() => { const win = opts.dom.getWindow(ref);
const timer = win.setTimeout(() => {
if (!opts.ref.current) return; if (!opts.ref.current) return;
registry.set(this, { registry.set(this, {
escapeBehavior: opts.escapeKeydownBehavior, escapeBehavior: opts.escapeKeydownBehavior,
@ -96,7 +97,7 @@ export class Dismissal {
}, 1); }, 1);
return () => { return () => {
clearTimeout(timer); win.clearTimeout(timer);
unsubEvents(); unsubEvents();
this.resetState(); this.resetState();
registry.delete(this); registry.delete(this);

Loading…
Cancel
Save

Powered by TurnKey Linux.