mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore(typescript): migrate src/Dialog (#5639)
This PR changes `src/Dialog.js` to `src/Dialog.ts` and rewrites accordingly. Most of the changes are straight forward; the only interesting one from a TS point of view is the `DialogType` enum. I expose it again as `Dialog.Type` to avoid a breaking change. This PR also exposed some bugs with our ESLint TypeScript settings and applying the overrides, so I fixed those too. I also updated our DocLint tool to work on TS source files over JS lib files if they exist. This is the minimal change to keep the existing doc system working as we're working on moving away from this system longer term.
This commit is contained in:
@@ -14,48 +14,46 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const {assert} = require('./helper');
|
||||
import helpers = require('./helper');
|
||||
|
||||
const {assert} = helpers;
|
||||
|
||||
enum DialogType {
|
||||
Alert = 'alert',
|
||||
BeforeUnload = 'beforeunload',
|
||||
Confirm = 'confirm',
|
||||
Prompt = 'prompt'
|
||||
}
|
||||
|
||||
class Dialog {
|
||||
/**
|
||||
* @param {!Puppeteer.CDPSession} client
|
||||
* @param {string} type
|
||||
* @param {string} message
|
||||
* @param {(string|undefined)} defaultValue
|
||||
*/
|
||||
constructor(client, type, message, defaultValue = '') {
|
||||
static Type = DialogType;
|
||||
|
||||
private _client: Puppeteer.CDPSession;
|
||||
private _type: DialogType;
|
||||
private _message: string;
|
||||
private _defaultValue: string;
|
||||
private _handled = false;
|
||||
|
||||
constructor(client: Puppeteer.CDPSession, type: DialogType, message: string, defaultValue = '') {
|
||||
this._client = client;
|
||||
this._type = type;
|
||||
this._message = message;
|
||||
this._handled = false;
|
||||
this._defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
type() {
|
||||
type(): DialogType {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
message() {
|
||||
message(): string {
|
||||
return this._message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
defaultValue() {
|
||||
defaultValue(): string {
|
||||
return this._defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} promptText
|
||||
*/
|
||||
async accept(promptText) {
|
||||
async accept(promptText?: string): Promise<void> {
|
||||
assert(!this._handled, 'Cannot accept dialog which is already handled!');
|
||||
this._handled = true;
|
||||
await this._client.send('Page.handleJavaScriptDialog', {
|
||||
@@ -64,7 +62,7 @@ class Dialog {
|
||||
});
|
||||
}
|
||||
|
||||
async dismiss() {
|
||||
async dismiss(): Promise<void> {
|
||||
assert(!this._handled, 'Cannot dismiss dialog which is already handled!');
|
||||
this._handled = true;
|
||||
await this._client.send('Page.handleJavaScriptDialog', {
|
||||
@@ -73,11 +71,4 @@ class Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
Dialog.Type = {
|
||||
Alert: 'alert',
|
||||
BeforeUnload: 'beforeunload',
|
||||
Confirm: 'confirm',
|
||||
Prompt: 'prompt'
|
||||
};
|
||||
|
||||
module.exports = {Dialog};
|
||||
export = {Dialog};
|
||||
Reference in New Issue
Block a user