INIT
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
import { type ConfigurableDocumentOrShadowRoot, type ConfigurableWindow } from "../../internal/configurable-globals.js";
|
||||
export interface ActiveElementOptions extends ConfigurableDocumentOrShadowRoot, ConfigurableWindow {
|
||||
}
|
||||
export declare class ActiveElement {
|
||||
#private;
|
||||
constructor(options?: ActiveElementOptions);
|
||||
get current(): Element | null;
|
||||
}
|
||||
/**
|
||||
* An object holding a reactive value that is equal to `document.activeElement`.
|
||||
* It automatically listens for changes, keeping the reference up to date.
|
||||
*
|
||||
* If you wish to use a custom document or shadowRoot, you should use
|
||||
* [useActiveElement](https://runed.dev/docs/utilities/active-element) instead.
|
||||
*
|
||||
* @see {@link https://runed.dev/docs/utilities/active-element}
|
||||
*/
|
||||
export declare const activeElement: ActiveElement;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { defaultWindow, } from "../../internal/configurable-globals.js";
|
||||
import { getActiveElement } from "../../internal/utils/dom.js";
|
||||
import { on } from "svelte/events";
|
||||
import { createSubscriber } from "svelte/reactivity";
|
||||
export class ActiveElement {
|
||||
#document;
|
||||
#subscribe;
|
||||
constructor(options = {}) {
|
||||
const { window = defaultWindow, document = window?.document } = options;
|
||||
if (window === undefined)
|
||||
return;
|
||||
this.#document = document;
|
||||
this.#subscribe = createSubscriber((update) => {
|
||||
const cleanupFocusIn = on(window, "focusin", update);
|
||||
const cleanupFocusOut = on(window, "focusout", update);
|
||||
return () => {
|
||||
cleanupFocusIn();
|
||||
cleanupFocusOut();
|
||||
};
|
||||
});
|
||||
}
|
||||
get current() {
|
||||
this.#subscribe?.();
|
||||
if (!this.#document)
|
||||
return null;
|
||||
return getActiveElement(this.#document);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* An object holding a reactive value that is equal to `document.activeElement`.
|
||||
* It automatically listens for changes, keeping the reference up to date.
|
||||
*
|
||||
* If you wish to use a custom document or shadowRoot, you should use
|
||||
* [useActiveElement](https://runed.dev/docs/utilities/active-element) instead.
|
||||
*
|
||||
* @see {@link https://runed.dev/docs/utilities/active-element}
|
||||
*/
|
||||
export const activeElement = new ActiveElement();
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from "./active-element.svelte.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from "./active-element.svelte.js";
|
||||
Reference in New Issue
Block a user