add type for selector engine (#4174)

This commit is contained in:
Tom Jenkinson 2020-10-19 07:00:28 +01:00 committed by GitHub
parent bbdba42d30
commit 7103887bb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -17,12 +17,13 @@
import { evaluationScript } from './clientHelper';
import * as channels from '../protocol/channels';
import { ChannelOwner } from './channelOwner';
import { SelectorEngine } from './types';
export class Selectors {
private _channels = new Set<SelectorsOwner>();
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 params = { ...options, name, source };
for (const channel of this._channels)

View file

@ -86,3 +86,19 @@ export type LaunchServerOptions = {
port?: number,
logger?: Logger,
} & 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[];
};