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(
dom: ActiveDom,
target: HTMLElement,
key: string,
timeout: number,
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 {
cancel() {
clearTimeout(native);
win.clearTimeout(native);
return true;
}
};
@ -132,6 +135,8 @@ function write(
}
if (pair.timer) pair.timer.cancel();
pair.timer = scheduleClear(
dom,
pair.a,
`soma:announce:global:${pair.a.id}`,
timeout,
() => {

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

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

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

@ -85,7 +85,8 @@ export class Dismissal {
if (!enabled || !ref) return;
// 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;
registry.set(this, {
escapeBehavior: opts.escapeKeydownBehavior,
@ -96,7 +97,7 @@ export class Dismissal {
}, 1);
return () => {
clearTimeout(timer);
win.clearTimeout(timer);
unsubEvents();
this.resetState();
registry.delete(this);

Loading…
Cancel
Save

Powered by TurnKey Linux.