aboutsummaryrefslogtreecommitdiff
path: root/ext/js/app/popup-window.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
commit4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch)
treea8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/app/popup-window.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/app/popup-window.js')
-rw-r--r--ext/js/app/popup-window.js67
1 files changed, 40 insertions, 27 deletions
diff --git a/ext/js/app/popup-window.js b/ext/js/app/popup-window.js
index 88370684..af1ac1e4 100644
--- a/ext/js/app/popup-window.js
+++ b/ext/js/app/popup-window.js
@@ -22,14 +22,12 @@ import {Popup} from './popup.js';
/**
* This class represents a popup that is hosted in a new native window.
+ * @augments EventDispatcher<import('popup').PopupAnyEventType>
*/
export class PopupWindow extends EventDispatcher {
/**
* Creates a new instance.
- * @param {object} details Details about how to set up the instance.
- * @param {string} details.id The ID of the popup.
- * @param {number} details.depth The depth of the popup.
- * @param {number} details.frameId The ID of the host frame.
+ * @param {import('popup').PopupWindowConstructorDetails} details Details about how to set up the instance.
*/
constructor({
id,
@@ -37,9 +35,13 @@ export class PopupWindow extends EventDispatcher {
frameId
}) {
super();
+ /** @type {string} */
this._id = id;
+ /** @type {number} */
this._depth = depth;
+ /** @type {number} */
this._frameId = frameId;
+ /** @type {?number} */
this._popupTabId = null;
}
@@ -51,6 +53,9 @@ export class PopupWindow extends EventDispatcher {
return this._id;
}
+ /**
+ * @type {?Popup}
+ */
get parent() {
return null;
}
@@ -68,7 +73,7 @@ export class PopupWindow extends EventDispatcher {
/**
* The popup child popup, which is always null for `PopupWindow` instances,
* since any potential child popups are in a different frame.
- * @type {Popup}
+ * @type {?Popup}
*/
get child() {
return null;
@@ -85,7 +90,7 @@ export class PopupWindow extends EventDispatcher {
/**
* The depth of the popup.
- * @type {numer}
+ * @type {number}
*/
get depth() {
return this._depth;
@@ -94,7 +99,7 @@ export class PopupWindow extends EventDispatcher {
/**
* Gets the content window of the frame. This value is null,
* since the window is hosted in a different frame.
- * @type {Window}
+ * @type {?Window}
*/
get frameContentWindow() {
return null;
@@ -102,7 +107,7 @@ export class PopupWindow extends EventDispatcher {
/**
* Gets the DOM node that contains the frame.
- * @type {Element}
+ * @type {?Element}
*/
get container() {
return null;
@@ -118,11 +123,11 @@ export class PopupWindow extends EventDispatcher {
/**
* Sets the options context for the popup.
- * @param {object} optionsContext The options context object.
+ * @param {import('settings').OptionsContext} optionsContext The options context object.
* @returns {Promise<void>}
*/
- setOptionsContext(optionsContext) {
- return this._invoke(false, 'Display.setOptionsContext', {id: this._id, optionsContext});
+ async setOptionsContext(optionsContext) {
+ await this._invoke(false, 'Display.setOptionsContext', {id: this._id, optionsContext});
}
/**
@@ -145,7 +150,7 @@ export class PopupWindow extends EventDispatcher {
* Force assigns the visibility of the popup.
* @param {boolean} _value Whether or not the popup should be visible.
* @param {number} _priority The priority of the override.
- * @returns {Promise<string?>} A token used which can be passed to `clearVisibleOverride`,
+ * @returns {Promise<?import('core').TokenString>} A token used which can be passed to `clearVisibleOverride`,
* or null if the override wasn't assigned.
*/
async setVisibleOverride(_value, _priority) {
@@ -154,10 +159,10 @@ export class PopupWindow extends EventDispatcher {
/**
* Clears a visibility override that was generated by `setVisibleOverride`.
- * @param {string} _token The token returned from `setVisibleOverride`.
- * @returns {boolean} `true` if the override existed and was removed, `false` otherwise.
+ * @param {import('core').TokenString} _token The token returned from `setVisibleOverride`.
+ * @returns {Promise<boolean>} `true` if the override existed and was removed, `false` otherwise.
*/
- clearVisibleOverride(_token) {
+ async clearVisibleOverride(_token) {
return false;
}
@@ -173,8 +178,8 @@ export class PopupWindow extends EventDispatcher {
/**
* Shows and updates the positioning and content of the popup.
- * @param {Popup.ContentDetails} _details Settings for the outer popup.
- * @param {Display.ContentDetails} displayDetails The details parameter passed to `Display.setContent`.
+ * @param {import('popup').ContentDetails} _details Settings for the outer popup.
+ * @param {?import('display').ContentDetails} displayDetails The details parameter passed to `Display.setContent`.
* @returns {Promise<void>}
*/
async showContent(_details, displayDetails) {
@@ -187,23 +192,23 @@ export class PopupWindow extends EventDispatcher {
* @param {string} css The CSS rules.
* @returns {Promise<void>}
*/
- setCustomCss(css) {
- return this._invoke(false, 'Display.setCustomCss', {id: this._id, css});
+ async setCustomCss(css) {
+ await this._invoke(false, 'Display.setCustomCss', {id: this._id, css});
}
/**
* Stops the audio auto-play timer, if one has started.
* @returns {Promise<void>}
*/
- clearAutoPlayTimer() {
- return this._invoke(false, 'Display.clearAutoPlayTimer', {id: this._id});
+ async clearAutoPlayTimer() {
+ await this._invoke(false, 'Display.clearAutoPlayTimer', {id: this._id});
}
/**
* Sets the scaling factor of the popup content.
* @param {number} _scale The scaling factor.
*/
- setContentScale(_scale) {
+ async setContentScale(_scale) {
// NOP
}
@@ -235,7 +240,7 @@ export class PopupWindow extends EventDispatcher {
/**
* Gets the rectangle of the DOM frame, synchronously.
- * @returns {Popup.ValidRect} The rect.
+ * @returns {import('popup').ValidRect} The rect.
* `valid` is `false` for `PopupProxy`, since the DOM node is hosted in a different frame.
*/
getFrameRect() {
@@ -244,7 +249,7 @@ export class PopupWindow extends EventDispatcher {
/**
* Gets the size of the DOM frame.
- * @returns {Promise<{width: number, height: number, valid: boolean}>} The size and whether or not it is valid.
+ * @returns {Promise<import('popup').ValidSize>} The size and whether or not it is valid.
*/
async getFrameSize() {
return {width: 0, height: 0, valid: false};
@@ -262,9 +267,17 @@ export class PopupWindow extends EventDispatcher {
// Private
- async _invoke(open, action, params={}, defaultReturnValue) {
+ /**
+ * @template {import('core').SerializableObject} TParams
+ * @template [TReturn=unknown]
+ * @param {boolean} open
+ * @param {string} action
+ * @param {TParams} params
+ * @returns {Promise<TReturn|undefined>}
+ */
+ async _invoke(open, action, params) {
if (yomitan.isExtensionUnloaded) {
- return defaultReturnValue;
+ return void 0;
}
const frameId = 0;
@@ -280,7 +293,7 @@ export class PopupWindow extends EventDispatcher {
}
if (!open) {
- return defaultReturnValue;
+ return void 0;
}
const {tabId} = await yomitan.api.getOrCreateSearchPopup({focus: 'ifCreated'});