From fe875bbd99980b175fc366a2bfd4395be9cbad72 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 20 Feb 2024 10:13:57 -0500 Subject: Constructor simplification (#713) * Update AudioDownloader * Update Translator * Update ClipboardMonitor * Update ClipboardReader * Update PanelElement * Update QueryParser * Update DisplayGenerator * Update DisplayHistory * Update DOMDataBinder * Remove unnecessary cast * Update Popup types * One declaration per line * Remove optionals from Frontend constructor * Fix Translator constructor --- ext/js/display/display-generator.js | 5 +++-- ext/js/display/display-history.js | 5 +++-- ext/js/display/display-profile-selection.js | 5 +---- ext/js/display/display.js | 23 +++++++---------------- ext/js/display/query-parser.js | 6 ++++-- ext/js/display/search-display-controller.js | 10 +++++----- 6 files changed, 23 insertions(+), 31 deletions(-) (limited to 'ext/js/display') diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 65736759..22912e9f 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -26,9 +26,10 @@ import {StructuredContentGenerator} from './sandbox/structured-content-generator export class DisplayGenerator { /** - * @param {import('display').DisplayGeneratorConstructorDetails} details + * @param {import('./display-content-manager.js').DisplayContentManager} contentManager + * @param {?import('../input/hotkey-help-controller.js').HotkeyHelpController} hotkeyHelpController */ - constructor({contentManager, hotkeyHelpController = null}) { + constructor(contentManager, hotkeyHelpController) { /** @type {import('./display-content-manager.js').DisplayContentManager} */ this._contentManager = contentManager; /** @type {?import('../input/hotkey-help-controller.js').HotkeyHelpController} */ diff --git a/ext/js/display/display-history.js b/ext/js/display/display-history.js index 255a8536..67690219 100644 --- a/ext/js/display/display-history.js +++ b/ext/js/display/display-history.js @@ -24,9 +24,10 @@ import {generateId, isObject} from '../core/utilities.js'; */ export class DisplayHistory extends EventDispatcher { /** - * @param {{clearable?: boolean, useBrowserHistory?: boolean}} details + * @param {boolean} clearable + * @param {boolean} useBrowserHistory */ - constructor({clearable = true, useBrowserHistory = false}) { + constructor(clearable, useBrowserHistory) { super(); /** @type {boolean} */ this._clearable = clearable; diff --git a/ext/js/display/display-profile-selection.js b/ext/js/display/display-profile-selection.js index 0aa08b00..6fd25835 100644 --- a/ext/js/display/display-profile-selection.js +++ b/ext/js/display/display-profile-selection.js @@ -35,10 +35,7 @@ export class DisplayProfileSelection { /** @type {HTMLElement} */ const profilePanelElement = querySelectorNotNull(document, '#profile-panel'); /** @type {PanelElement} */ - this._profilePanel = new PanelElement({ - node: profilePanelElement, - closingAnimationDuration: 375 // Milliseconds; includes buffer - }); + this._profilePanel = new PanelElement(profilePanelElement, 375); // Milliseconds; includes buffer /** @type {boolean} */ this._profileListNeedsUpdate = false; /** @type {EventListenerCollection} */ diff --git a/ext/js/display/display.js b/ext/js/display/display.js index d0edd0bd..750e0d69 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -83,16 +83,13 @@ export class Display extends EventDispatcher { /** @type {HotkeyHelpController} */ this._hotkeyHelpController = new HotkeyHelpController(); /** @type {DisplayGenerator} */ - this._displayGenerator = new DisplayGenerator({ - contentManager: this._contentManager, - hotkeyHelpController: this._hotkeyHelpController - }); + this._displayGenerator = new DisplayGenerator(this._contentManager, this._hotkeyHelpController); /** @type {import('display').DirectApiMap} */ this._directApiMap = new Map(); /** @type {import('api-map').ApiMap} */ // import('display').WindowApiMap this._windowApiMap = new Map(); /** @type {DisplayHistory} */ - this._history = new DisplayHistory({clearable: true, useBrowserHistory: false}); + this._history = new DisplayHistory(true, false); /** @type {boolean} */ this._historyChangeIgnore = false; /** @type {boolean} */ @@ -126,11 +123,7 @@ export class Display extends EventDispatcher { /** @type {TextSourceGenerator} */ this._textSourceGenerator = new TextSourceGenerator(); /** @type {QueryParser} */ - this._queryParser = new QueryParser({ - api: application.api, - getSearchContext: this._getSearchContext.bind(this), - textSourceGenerator: this._textSourceGenerator - }); + this._queryParser = new QueryParser(application.api, this._textSourceGenerator, this._getSearchContext.bind(this)); /** @type {HTMLElement} */ this._contentScrollElement = querySelectorNotNull(document, '#content-scroll'); /** @type {HTMLElement} */ @@ -1712,8 +1705,7 @@ export class Display extends EventDispatcher { const popupFactory = new PopupFactory(this._application); popupFactory.prepare(); - /** @type {import('frontend').ConstructorDetails} */ - const setupNestedPopupsOptions = { + const frontend = new Frontend({ application: this._application, useProxyPopup, parentPopupId, @@ -1723,10 +1715,9 @@ export class Display extends EventDispatcher { pageType: this._pageType, allowRootFramePopupProxy: true, childrenSupported: this._childrenSupported, - hotkeyHandler: this._hotkeyHandler - }; - - const frontend = new Frontend(setupNestedPopupsOptions); + hotkeyHandler: this._hotkeyHandler, + canUseWindowPopup: true + }); this._frontend = frontend; await frontend.prepare(); } diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index 875d9d5a..d27b9394 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -27,9 +27,11 @@ import {TextScanner} from '../language/text-scanner.js'; */ export class QueryParser extends EventDispatcher { /** - * @param {import('display').QueryParserConstructorDetails} details + * @param {import('../comm/api.js').API} api + * @param {import('../dom/text-source-generator').TextSourceGenerator} textSourceGenerator + * @param {import('display').GetSearchContextCallback} getSearchContext */ - constructor({api, getSearchContext, textSourceGenerator}) { + constructor(api, textSourceGenerator, getSearchContext) { super(); /** @type {import('../comm/api.js').API} */ this._api = api; diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index d8126027..e23d5d50 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -63,12 +63,12 @@ export class SearchDisplayController { this._introAnimationTimer = null; /** @type {boolean} */ this._clipboardMonitorEnabled = false; + /** @type {import('clipboard-monitor').ClipboardReaderLike} */ + const clipboardReader = { + getText: this._display.application.api.clipboardGet.bind(this._display.application.api) + }; /** @type {ClipboardMonitor} */ - this._clipboardMonitor = new ClipboardMonitor({ - clipboardReader: { - getText: this._display.application.api.clipboardGet.bind(this._display.application.api) - } - }); + this._clipboardMonitor = new ClipboardMonitor(clipboardReader); /** @type {import('application').ApiMap} */ this._apiMap = createApiMap([ ['searchDisplayControllerGetMode', this._onMessageGetMode.bind(this)], -- cgit v1.2.3