add type for selector engine (#4174)
This commit is contained in:
parent
bbdba42d30
commit
7103887bb5
|
|
@ -17,12 +17,13 @@
|
||||||
import { evaluationScript } from './clientHelper';
|
import { evaluationScript } from './clientHelper';
|
||||||
import * as channels from '../protocol/channels';
|
import * as channels from '../protocol/channels';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
|
import { SelectorEngine } from './types';
|
||||||
|
|
||||||
export class Selectors {
|
export class Selectors {
|
||||||
private _channels = new Set<SelectorsOwner>();
|
private _channels = new Set<SelectorsOwner>();
|
||||||
private _registrations: channels.SelectorsRegisterParams[] = [];
|
private _registrations: channels.SelectorsRegisterParams[] = [];
|
||||||
|
|
||||||
async register(name: string, script: string | Function | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise<void> {
|
async register(name: string, script: string | (() => SelectorEngine) | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise<void> {
|
||||||
const source = await evaluationScript(script, undefined, false);
|
const source = await evaluationScript(script, undefined, false);
|
||||||
const params = { ...options, name, source };
|
const params = { ...options, name, source };
|
||||||
for (const channel of this._channels)
|
for (const channel of this._channels)
|
||||||
|
|
|
||||||
|
|
@ -86,3 +86,19 @@ export type LaunchServerOptions = {
|
||||||
port?: number,
|
port?: number,
|
||||||
logger?: Logger,
|
logger?: Logger,
|
||||||
} & FirefoxUserPrefs;
|
} & FirefoxUserPrefs;
|
||||||
|
|
||||||
|
export type SelectorEngine = {
|
||||||
|
/**
|
||||||
|
* Creates a selector that matches given target when queried at the root.
|
||||||
|
* Can return undefined if unable to create one.
|
||||||
|
*/
|
||||||
|
create(root: HTMLElement, target: HTMLElement): string | undefined;
|
||||||
|
/**
|
||||||
|
* Returns the first element matching given selector in the root's subtree.
|
||||||
|
*/
|
||||||
|
query(root: HTMLElement, selector: string): HTMLElement | null;
|
||||||
|
/**
|
||||||
|
* Returns all elements matching given selector in the root's subtree.
|
||||||
|
*/
|
||||||
|
queryAll(root: HTMLElement, selector: string): HTMLElement[];
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue