From 4da4827bcbcdd1ef163f635d9b29416ff272b0bb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 12:48:14 -0500 Subject: Add JSDoc type annotations to project (rebased) --- ext/js/pages/settings/dictionary-controller.js | 327 ++++++++++++++++++++----- 1 file changed, 265 insertions(+), 62 deletions(-) (limited to 'ext/js/pages/settings/dictionary-controller.js') diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 155ce55e..85f7493f 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -21,27 +21,49 @@ import {DictionaryWorker} from '../../language/dictionary-worker.js'; import {yomitan} from '../../yomitan.js'; class DictionaryEntry { + /** + * @param {DictionaryController} dictionaryController + * @param {DocumentFragment} fragment + * @param {number} index + * @param {import('dictionary-importer').Summary} dictionaryInfo + */ constructor(dictionaryController, fragment, index, dictionaryInfo) { + /** @type {DictionaryController} */ this._dictionaryController = dictionaryController; + /** @type {number} */ this._index = index; + /** @type {import('dictionary-importer').Summary} */ this._dictionaryInfo = dictionaryInfo; + /** @type {EventListenerCollection} */ this._eventListeners = new EventListenerCollection(); + /** @type {?import('dictionary-database').DictionaryCountGroup} */ this._counts = null; + /** @type {ChildNode[]} */ this._nodes = [...fragment.childNodes]; - this._enabledCheckbox = fragment.querySelector('.dictionary-enabled'); - this._priorityInput = fragment.querySelector('.dictionary-priority'); - this._menuButton = fragment.querySelector('.dictionary-menu-button'); - this._outdatedButton = fragment.querySelector('.dictionary-outdated-button'); - this._integrityButton = fragment.querySelector('.dictionary-integrity-button'); - this._titleNode = fragment.querySelector('.dictionary-title'); - this._versionNode = fragment.querySelector('.dictionary-version'); - this._titleContainer = fragment.querySelector('.dictionary-item-title-container'); - } - + /** @type {HTMLInputElement} */ + this._enabledCheckbox = /** @type {HTMLInputElement} */ (fragment.querySelector('.dictionary-enabled')); + /** @type {HTMLInputElement} */ + this._priorityInput = /** @type {HTMLInputElement} */ (fragment.querySelector('.dictionary-priority')); + /** @type {HTMLButtonElement} */ + this._menuButton = /** @type {HTMLButtonElement} */ (fragment.querySelector('.dictionary-menu-button')); + /** @type {HTMLButtonElement} */ + this._outdatedButton = /** @type {HTMLButtonElement} */ (fragment.querySelector('.dictionary-outdated-button')); + /** @type {HTMLButtonElement} */ + this._integrityButton = /** @type {HTMLButtonElement} */ (fragment.querySelector('.dictionary-integrity-button')); + /** @type {HTMLElement} */ + this._titleNode = /** @type {HTMLElement} */ (fragment.querySelector('.dictionary-title')); + /** @type {HTMLElement} */ + this._versionNode = /** @type {HTMLElement} */ (fragment.querySelector('.dictionary-version')); + /** @type {HTMLElement} */ + this._titleContainer = /** @type {HTMLElement} */ (fragment.querySelector('.dictionary-item-title-container')); + } + + /** @type {string} */ get dictionaryTitle() { return this._dictionaryInfo.title; } + /** */ prepare() { const index = this._index; const {title, revision, version} = this._dictionaryInfo; @@ -58,6 +80,7 @@ class DictionaryEntry { this._eventListeners.addEventListener(this._integrityButton, 'click', this._onIntegrityButtonClick.bind(this), false); } + /** */ cleanup() { this._eventListeners.removeAllEventListeners(); for (const node of this._nodes) { @@ -68,17 +91,26 @@ class DictionaryEntry { this._nodes = []; } + /** + * @param {import('dictionary-database').DictionaryCountGroup} counts + */ setCounts(counts) { this._counts = counts; this._integrityButton.hidden = false; } + /** + * @param {boolean} value + */ setEnabled(value) { this._enabledCheckbox.checked = value; } // Private + /** + * @param {import('popup-menu').MenuOpenEvent} e + */ _onMenuOpen(e) { const bodyNode = e.detail.menu.bodyNode; const count = this._dictionaryController.dictionaryOptionCount; @@ -87,6 +119,9 @@ class DictionaryEntry { this._setMenuActionEnabled(bodyNode, 'moveTo', count > 1); } + /** + * @param {import('popup-menu').MenuCloseEvent} e + */ _onMenuClose(e) { switch (e.detail.action) { case 'delete': @@ -107,36 +142,48 @@ class DictionaryEntry { } } + /** + * @param {import('dom-data-binder').SettingChangedEvent} e + */ _onEnabledChanged(e) { const {detail: {value}} = e; this._titleContainer.dataset.enabled = `${value}`; this._dictionaryController.updateDictionariesEnabled(); } + /** */ _onOutdatedButtonClick() { this._showDetails(); } + /** */ _onIntegrityButtonClick() { this._showDetails(); } + /** */ _showDetails() { const {title, revision, version, prefixWildcardsSupported} = this._dictionaryInfo; const modal = this._dictionaryController.modalController.getModal('dictionary-details'); + if (modal === null) { return; } - modal.node.querySelector('.dictionary-title').textContent = title; - modal.node.querySelector('.dictionary-version').textContent = `rev.${revision}`; - modal.node.querySelector('.dictionary-outdated-notification').hidden = (version >= 3); - modal.node.querySelector('.dictionary-counts').textContent = this._counts !== null ? JSON.stringify(this._counts, null, 4) : ''; - modal.node.querySelector('.dictionary-prefix-wildcard-searches-supported').checked = prefixWildcardsSupported; - this._setupDetails(modal.node.querySelector('.dictionary-details-table')); + /** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-title')).textContent = title; + /** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-version')).textContent = `rev.${revision}`; + /** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-outdated-notification')).hidden = (version >= 3); + /** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-counts')).textContent = this._counts !== null ? JSON.stringify(this._counts, null, 4) : ''; + /** @type {HTMLInputElement} */ (modal.node.querySelector('.dictionary-prefix-wildcard-searches-supported')).checked = prefixWildcardsSupported; + this._setupDetails(/** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-details-table'))); modal.setVisible(true); } + /** + * @param {Element} detailsTable + * @returns {boolean} + */ _setupDetails(detailsTable) { + /** @type {[label: string, key: 'author'|'url'|'description'|'attribution'][]} */ const targets = [ ['Author', 'author'], ['URL', 'url'], @@ -151,10 +198,10 @@ class DictionaryEntry { const info = dictionaryInfo[key]; if (typeof info !== 'string') { continue; } - const details = this._dictionaryController.instantiateTemplate('dictionary-details-entry'); + const details = /** @type {HTMLElement} */ (this._dictionaryController.instantiateTemplate('dictionary-details-entry')); details.dataset.type = key; - details.querySelector('.dictionary-details-entry-label').textContent = `${label}:`; - details.querySelector('.dictionary-details-entry-info').textContent = info; + /** @type {HTMLElement} */ (details.querySelector('.dictionary-details-entry-label')).textContent = `${label}:`; + /** @type {HTMLElement} */ (details.querySelector('.dictionary-details-entry-info')).textContent = info; fragment.appendChild(details); any = true; @@ -165,28 +212,40 @@ class DictionaryEntry { return any; } + /** */ _delete() { this._dictionaryController.deleteDictionary(this.dictionaryTitle); } + /** + * @param {number} offset + */ _move(offset) { this._dictionaryController.moveDictionaryOptions(this._index, this._index + offset); } + /** + * @param {Element} menu + * @param {string} action + * @param {boolean} enabled + */ _setMenuActionEnabled(menu, action, enabled) { - const element = menu.querySelector(`[data-menu-action="${action}"]`); + const element = /** @type {?HTMLButtonElement} */ (menu.querySelector(`[data-menu-action="${action}"]`)); if (element === null) { return; } element.disabled = !enabled; } + /** */ _showMoveToModal() { const {title} = this._dictionaryInfo; const count = this._dictionaryController.dictionaryOptionCount; const modal = this._dictionaryController.modalController.getModal('dictionary-move-location'); - const input = modal.node.querySelector('#dictionary-move-location'); + if (modal === null) { return; } + const input = /** @type {HTMLInputElement} */ (modal.node.querySelector('#dictionary-move-location')); + const titleNode = /** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-title')); modal.node.dataset.index = `${this._index}`; - modal.node.querySelector('.dictionary-title').textContent = title; + titleNode.textContent = title; input.value = `${this._index + 1}`; input.max = `${count}`; @@ -195,25 +254,45 @@ class DictionaryEntry { } class DictionaryExtraInfo { + /** + * @param {DictionaryController} parent + * @param {import('dictionary-database').DictionaryCountGroup} totalCounts + * @param {import('dictionary-database').DictionaryCountGroup} remainders + * @param {number} totalRemainder + */ constructor(parent, totalCounts, remainders, totalRemainder) { + /** @type {DictionaryController} */ this._parent = parent; + /** @type {import('dictionary-database').DictionaryCountGroup} */ this._totalCounts = totalCounts; + /** @type {import('dictionary-database').DictionaryCountGroup} */ this._remainders = remainders; + /** @type {number} */ this._totalRemainder = totalRemainder; + /** @type {EventListenerCollection} */ this._eventListeners = new EventListenerCollection(); - this._nodes = null; + /** @type {ChildNode[]} */ + this._nodes = []; } + /** + * @param {HTMLElement} container + */ prepare(container) { const fragment = this._parent.instantiateTemplateFragment('dictionary-extra'); - this._nodes = [...fragment.childNodes]; + for (const node of fragment.childNodes) { + this._nodes.push(node); + } + + const dictionaryIntegrityButton = /** @type {HTMLButtonElement} */ (fragment.querySelector('.dictionary-integrity-button')); this._setTitle(fragment.querySelector('.dictionary-total-count')); - this._eventListeners.addEventListener(fragment.querySelector('.dictionary-integrity-button'), 'click', this._onIntegrityButtonClick.bind(this), false); + this._eventListeners.addEventListener(dictionaryIntegrityButton, 'click', this._onIntegrityButtonClick.bind(this), false); container.appendChild(fragment); } + /** */ cleanup() { this._eventListeners.removeAllEventListeners(); for (const node of this._nodes) { @@ -221,74 +300,110 @@ class DictionaryExtraInfo { node.parentNode.removeChild(node); } } - this._nodes = []; + this._nodes.length =0; } // Private + /** */ _onIntegrityButtonClick() { this._showDetails(); } + /** */ _showDetails() { const modal = this._parent.modalController.getModal('dictionary-extra-data'); + if (modal === null) { return; } + + const dictionaryCounts = /** @type {HTMLElement} */ (modal.node.querySelector('.dictionary-counts')); const info = {counts: this._totalCounts, remainders: this._remainders}; - modal.node.querySelector('.dictionary-counts').textContent = JSON.stringify(info, null, 4); + dictionaryCounts.textContent = JSON.stringify(info, null, 4); this._setTitle(modal.node.querySelector('.dictionary-total-count')); modal.setVisible(true); } + /** + * @param {?Element} node + */ _setTitle(node) { + if (node === null) { return; } node.textContent = `${this._totalRemainder} item${this._totalRemainder !== 1 ? 's' : ''}`; } } export class DictionaryController { + /** + * @param {SettingsController} settingsController + * @param {ModalController} modalController + * @param {StatusFooter} statusFooter + */ constructor(settingsController, modalController, statusFooter) { + /** @type {SettingsController} */ this._settingsController = settingsController; + /** @type {ModalController} */ this._modalController = modalController; + /** @type {StatusFooter} */ this._statusFooter = statusFooter; + /** @type {?import('dictionary-importer').Summary[]} */ this._dictionaries = null; + /** @type {DictionaryEntry[]} */ this._dictionaryEntries = []; + /** @type {?import('core').TokenObject} */ this._databaseStateToken = null; + /** @type {boolean} */ this._checkingIntegrity = false; + /** @type {?HTMLButtonElement} */ this._checkIntegrityButton = null; + /** @type {?HTMLElement} */ this._dictionaryEntryContainer = null; + /** @type {?HTMLElement} */ this._dictionaryInstallCountNode = null; + /** @type {?HTMLElement} */ this._dictionaryEnabledCountNode = null; + /** @type {?NodeListOf} */ this._noDictionariesInstalledWarnings = null; + /** @type {?NodeListOf} */ this._noDictionariesEnabledWarnings = null; + /** @type {?Modal} */ this._deleteDictionaryModal = null; + /** @type {?HTMLInputElement} */ this._allCheckbox = null; + /** @type {?DictionaryExtraInfo} */ this._extraInfo = null; + /** @type {boolean} */ this._isDeleting = false; } + /** @type {ModalController} */ get modalController() { return this._modalController; } + /** @type {number} */ get dictionaryOptionCount() { return this._dictionaryEntries.length; } + /** */ async prepare() { - this._checkIntegrityButton = document.querySelector('#dictionary-check-integrity'); - this._dictionaryEntryContainer = document.querySelector('#dictionary-list'); - this._dictionaryInstallCountNode = document.querySelector('#dictionary-install-count'); - this._dictionaryEnabledCountNode = document.querySelector('#dictionary-enabled-count'); - this._noDictionariesInstalledWarnings = document.querySelectorAll('.no-dictionaries-installed-warning'); - this._noDictionariesEnabledWarnings = document.querySelectorAll('.no-dictionaries-enabled-warning'); + this._checkIntegrityButton = /** @type {HTMLButtonElement} */ (document.querySelector('#dictionary-check-integrity')); + this._dictionaryEntryContainer = /** @type {HTMLElement} */ (document.querySelector('#dictionary-list')); + this._dictionaryInstallCountNode = /** @type {HTMLElement} */ (document.querySelector('#dictionary-install-count')); + this._dictionaryEnabledCountNode = /** @type {HTMLElement} */ (document.querySelector('#dictionary-enabled-count')); + this._noDictionariesInstalledWarnings = /** @type {NodeListOf} */ (document.querySelectorAll('.no-dictionaries-installed-warning')); + this._noDictionariesEnabledWarnings = /** @type {NodeListOf} */ (document.querySelectorAll('.no-dictionaries-enabled-warning')); this._deleteDictionaryModal = this._modalController.getModal('dictionary-confirm-delete'); - this._allCheckbox = document.querySelector('#all-dictionaries-enabled'); + this._allCheckbox = /** @type {HTMLInputElement} */ (document.querySelector('#all-dictionaries-enabled')); + const dictionaryDeleteButton = /** @type {HTMLButtonElement} */ (document.querySelector('#dictionary-confirm-delete-button')); + const dictionaryMoveButton = /** @type {HTMLButtonElement} */ (document.querySelector('#dictionary-move-button')); yomitan.on('databaseUpdated', this._onDatabaseUpdated.bind(this)); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); this._allCheckbox.addEventListener('change', this._onAllCheckboxChange.bind(this), false); - document.querySelector('#dictionary-confirm-delete-button').addEventListener('click', this._onDictionaryConfirmDelete.bind(this), false); - document.querySelector('#dictionary-move-button').addEventListener('click', this._onDictionaryMoveButtonClick.bind(this), false); + dictionaryDeleteButton.addEventListener('click', this._onDictionaryConfirmDelete.bind(this), false); + dictionaryMoveButton.addEventListener('click', this._onDictionaryMoveButtonClick.bind(this), false); if (this._checkIntegrityButton !== null) { this._checkIntegrityButton.addEventListener('click', this._onCheckIntegrityButtonClick.bind(this), false); } @@ -298,14 +413,22 @@ export class DictionaryController { await this._onDatabaseUpdated(); } + /** + * @param {string} dictionaryTitle + */ deleteDictionary(dictionaryTitle) { if (this._isDeleting) { return; } - const modal = this._deleteDictionaryModal; + const modal = /** @type {Modal} */ (this._deleteDictionaryModal); modal.node.dataset.dictionaryTitle = dictionaryTitle; - modal.node.querySelector('#dictionary-confirm-delete-name').textContent = dictionaryTitle; + const nameElement = /** @type {Element} */ (modal.node.querySelector('#dictionary-confirm-delete-name')); + nameElement.textContent = dictionaryTitle; modal.setVisible(true); } + /** + * @param {number} currentIndex + * @param {number} targetIndex + */ async moveDictionaryOptions(currentIndex, targetIndex) { const options = await this._settingsController.getOptions(); const {dictionaries} = options; @@ -326,24 +449,40 @@ export class DictionaryController { value: dictionaries }]); - this._settingsController.trigger('dictionarySettingsReordered', {source: this}); + /** @type {import('settings-controller').DictionarySettingsReorderedEvent} */ + const event = {source: this}; + this._settingsController.trigger('dictionarySettingsReordered', event); await this._updateEntries(); } + /** + * @param {string} name + * @returns {Element} + */ instantiateTemplate(name) { return this._settingsController.instantiateTemplate(name); } + /** + * @param {string} name + * @returns {DocumentFragment} + */ instantiateTemplateFragment(name) { return this._settingsController.instantiateTemplateFragment(name); } + /** */ async updateDictionariesEnabled() { const options = await this._settingsController.getOptions(); this._updateDictionariesEnabledWarnings(options); } + /** + * @param {string} name + * @param {boolean} enabled + * @returns {import('settings').DictionaryOptions} + */ static createDefaultDictionarySettings(name, enabled) { return { name, @@ -354,6 +493,13 @@ export class DictionaryController { }; } + /** + * @param {SettingsController} settingsController + * @param {import('dictionary-importer').Summary[]|undefined} dictionaries + * @param {import('settings').Options|undefined} optionsFull + * @param {boolean} modifyGlobalSettings + * @param {boolean} newDictionariesEnabled + */ static async ensureDictionarySettings(settingsController, dictionaries, optionsFull, modifyGlobalSettings, newDictionariesEnabled) { if (typeof dictionaries === 'undefined') { dictionaries = await settingsController.getDictionaryInfo(); @@ -367,6 +513,7 @@ export class DictionaryController { installedDictionaries.add(title); } + /** @type {import('settings-modifications').Modification[]} */ const targets = []; const {profiles} = optionsFull; for (let i = 0, ii = profiles.length; i < ii; ++i) { @@ -405,6 +552,9 @@ export class DictionaryController { // Private + /** + * @param {import('settings-controller').OptionsChangedEvent} details + */ _onOptionsChanged({options}) { this._updateDictionariesEnabledWarnings(options); if (this._dictionaries !== null) { @@ -412,7 +562,9 @@ export class DictionaryController { } } + /** */ async _onDatabaseUpdated() { + /** @type {?import('core').TokenObject} */ const token = {}; this._databaseStateToken = token; this._dictionaries = null; @@ -423,14 +575,18 @@ export class DictionaryController { await this._updateEntries(); } + /** */ _onAllCheckboxChange() { - const value = this._allCheckbox.checked; - this._allCheckbox.checked = !value; + const allCheckbox = /** @type {HTMLInputElement} */ (this._allCheckbox); + const value = allCheckbox.checked; + allCheckbox.checked = !value; this._setAllDictionariesEnabled(value); } + /** */ async _updateEntries() { const dictionaries = this._dictionaries; + if (dictionaries === null) { return; } this._updateMainDictionarySelectOptions(dictionaries); for (const entry of this._dictionaryEntries) { @@ -444,7 +600,7 @@ export class DictionaryController { } const hasDictionary = (dictionaries.length > 0); - for (const node of this._noDictionariesInstalledWarnings) { + for (const node of /** @type {NodeListOf} */ (this._noDictionariesInstalledWarnings)) { node.hidden = hasDictionary; } @@ -453,8 +609,9 @@ export class DictionaryController { const options = await this._settingsController.getOptions(); this._updateDictionariesEnabledWarnings(options); + /** @type {Map} */ const dictionaryInfoMap = new Map(); - for (const dictionary of this._dictionaries) { + for (const dictionary of dictionaries) { dictionaryInfoMap.set(dictionary.title, dictionary); } @@ -467,6 +624,9 @@ export class DictionaryController { } } + /** + * @param {import('settings').ProfileOptions} options + */ _updateDictionariesEnabledWarnings(options) { const {dictionaries} = options; let enabledDictionaryCountValid = 0; @@ -489,7 +649,7 @@ export class DictionaryController { } const hasEnabledDictionary = (enabledDictionaryCountValid > 0); - for (const node of this._noDictionariesEnabledWarnings) { + for (const node of /** @type {NodeListOf} */ (this._noDictionariesEnabledWarnings)) { node.hidden = hasEnabledDictionary; } @@ -497,7 +657,7 @@ export class DictionaryController { this._dictionaryEnabledCountNode.textContent = `${enabledDictionaryCountValid}`; } - this._allCheckbox.checked = (enabledDictionaryCount >= dictionaryCount); + /** @type {HTMLInputElement} */ (this._allCheckbox).checked = (enabledDictionaryCount >= dictionaryCount); const entries = this._dictionaryEntries; for (let i = 0, ii = Math.min(entries.length, dictionaryCount); i < ii; ++i) { @@ -505,10 +665,13 @@ export class DictionaryController { } } + /** + * @param {MouseEvent} e + */ _onDictionaryConfirmDelete(e) { e.preventDefault(); - const modal = this._deleteDictionaryModal; + const modal = /** @type {Modal} */ (this._deleteDictionaryModal); modal.setVisible(false); const title = modal.node.dataset.dictionaryTitle; @@ -518,24 +681,32 @@ export class DictionaryController { this._deleteDictionary(title); } + /** + * @param {MouseEvent} e + */ _onCheckIntegrityButtonClick(e) { e.preventDefault(); this._checkIntegrity(); } + /** */ _onDictionaryMoveButtonClick() { - const modal = this._modalController.getModal('dictionary-move-location'); - let {index} = modal.node.dataset; - index = Number.parseInt(index, 10); + const modal = /** @type {Modal} */ (this._modalController.getModal('dictionary-move-location')); + const {index} = modal.node.dataset; + if (typeof index !== 'number') { return; } + const indexNumber = Number.parseInt(index, 10); - let target = document.querySelector('#dictionary-move-location').value; - target = Number.parseInt(target, 10) - 1; + const targetString = /** @type {HTMLInputElement} */ (document.querySelector('#dictionary-move-location')).value; + const target = Number.parseInt(targetString, 10) - 1; - if (!Number.isFinite(target) || !Number.isFinite(index) || index === target) { return; } + if (!Number.isFinite(target) || !Number.isFinite(indexNumber) || indexNumber === target) { return; } - this.moveDictionaryOptions(index, target); + this.moveDictionaryOptions(indexNumber, target); } + /** + * @param {import('dictionary-importer').Summary[]} dictionaries + */ _updateMainDictionarySelectOptions(dictionaries) { for (const select of document.querySelectorAll('[data-setting="general.mainDictionary"]')) { const fragment = document.createDocumentFragment(); @@ -559,6 +730,7 @@ export class DictionaryController { } } + /** */ async _checkIntegrity() { if (this._dictionaries === null || this._checkingIntegrity || this._isDeleting) { return; } @@ -576,13 +748,17 @@ export class DictionaryController { entry.setCounts(counts[i]); } - this._setCounts(counts, total); + this._setCounts(counts, /** @type {import('dictionary-database').DictionaryCountGroup} */ (total)); } finally { this._setButtonsEnabled(true); this._checkingIntegrity = false; } } + /** + * @param {import('dictionary-database').DictionaryCountGroup[]} dictionaryCounts + * @param {import('dictionary-database').DictionaryCountGroup} totalCounts + */ _setCounts(dictionaryCounts, totalCounts) { const remainders = Object.assign({}, totalCounts); const keys = Object.keys(remainders); @@ -603,12 +779,16 @@ export class DictionaryController { this._extraInfo = null; } - if (totalRemainder > 0) { + if (totalRemainder > 0 && this._dictionaryEntryContainer !== null) { this._extraInfo = new DictionaryExtraInfo(this, totalCounts, remainders, totalRemainder); this._extraInfo.prepare(this._dictionaryEntryContainer); } } + /** + * @param {number} index + * @param {import('dictionary-importer').Summary} dictionaryInfo + */ _createDictionaryEntry(index, dictionaryInfo) { const fragment = this.instantiateTemplateFragment('dictionary'); @@ -616,13 +796,16 @@ export class DictionaryController { this._dictionaryEntries.push(entry); entry.prepare(); - const container = this._dictionaryEntryContainer; + const container = /** @type {HTMLElement} */ (this._dictionaryEntryContainer); const relative = container.querySelector('.dictionary-item-bottom'); container.insertBefore(fragment, relative); this._updateDictionaryEntryCount(); } + /** + * @param {string} dictionaryTitle + */ async _deleteDictionary(dictionaryTitle) { if (this._isDeleting || this._checkingIntegrity) { return; } @@ -631,15 +814,18 @@ export class DictionaryController { const statusFooter = this._statusFooter; const progressSelector = '.dictionary-delete-progress'; - const progressContainers = document.querySelectorAll(`#dictionaries-modal ${progressSelector}`); - const progressBars = document.querySelectorAll(`${progressSelector} .progress-bar`); - const infoLabels = document.querySelectorAll(`${progressSelector} .progress-info`); - const statusLabels = document.querySelectorAll(`${progressSelector} .progress-status`); + const progressContainers = /** @type {NodeListOf} */ (document.querySelectorAll(`#dictionaries-modal ${progressSelector}`)); + const progressBars = /** @type {NodeListOf} */ (document.querySelectorAll(`${progressSelector} .progress-bar`)); + const infoLabels = /** @type {NodeListOf} */ (document.querySelectorAll(`${progressSelector} .progress-info`)); + const statusLabels = /** @type {NodeListOf} */ (document.querySelectorAll(`${progressSelector} .progress-status`)); const prevention = this._settingsController.preventPageExit(); try { this._isDeleting = true; this._setButtonsEnabled(false); + /** + * @param {import('dictionary-database').DeleteDictionaryProgressData} details + */ const onProgress = ({processed, count, storeCount, storesProcesed}) => { const percent = ( (count > 0 && storesProcesed > 0) ? @@ -672,21 +858,32 @@ export class DictionaryController { } } + /** + * @param {boolean} value + */ _setButtonsEnabled(value) { value = !value; - for (const node of document.querySelectorAll('.dictionary-database-mutating-input')) { + for (const node of /** @type {NodeListOf} */ (document.querySelectorAll('.dictionary-database-mutating-input'))) { node.disabled = value; } } + /** + * @param {string} dictionaryTitle + * @param {import('dictionary-worker').DeleteProgressCallback} onProgress + */ async _deleteDictionaryInternal(dictionaryTitle, onProgress) { await new DictionaryWorker().deleteDictionary(dictionaryTitle, onProgress); yomitan.api.triggerDatabaseUpdated('dictionary', 'delete'); } + /** + * @param {string} dictionaryTitle + */ async _deleteDictionarySettings(dictionaryTitle) { const optionsFull = await this._settingsController.getOptionsFull(); const {profiles} = optionsFull; + /** @type {import('settings-modifications').Modification[]} */ const targets = []; for (let i = 0, ii = profiles.length; i < ii; ++i) { const {options: {dictionaries}} = profiles[i]; @@ -705,18 +902,24 @@ export class DictionaryController { await this._settingsController.modifyGlobalSettings(targets); } + /** */ _triggerStorageChanged() { yomitan.trigger('storageChanged'); } + /** */ _updateDictionaryEntryCount() { - this._dictionaryEntryContainer.dataset.count = `${this._dictionaryEntries.length}`; + /** @type {HTMLElement} */ (this._dictionaryEntryContainer).dataset.count = `${this._dictionaryEntries.length}`; } + /** + * @param {boolean} value + */ async _setAllDictionariesEnabled(value) { const options = await this._settingsController.getOptions(); const {dictionaries} = options; + /** @type {import('settings-modifications').Modification[]} */ const targets = []; for (let i = 0, ii = dictionaries.length; i < ii; ++i) { targets.push({ -- cgit v1.2.3 From 208c43edbd714041b7f956d288e29172f1c0ce78 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 14:11:31 -0500 Subject: Update some common types --- .vscode/settings.json | 2 +- ext/js/pages/settings/anki-controller.js | 10 +++++----- ext/js/pages/settings/anki-templates-controller.js | 4 ++-- ext/js/pages/settings/audio-controller.js | 6 +++--- ext/js/pages/settings/backup-controller.js | 4 ++-- ext/js/pages/settings/collapsible-dictionary-controller.js | 4 ++-- ext/js/pages/settings/dictionary-controller.js | 6 +++--- ext/js/pages/settings/dictionary-import-controller.js | 4 ++-- .../pages/settings/extension-keyboard-shortcuts-controller.js | 4 ++-- ext/js/pages/settings/generic-setting-controller.js | 4 ++-- ext/js/pages/settings/keyboard-shortcuts-controller.js | 6 +++--- ext/js/pages/settings/nested-popups-controller.js | 4 ++-- ext/js/pages/settings/permissions-origin-controller.js | 4 ++-- ext/js/pages/settings/permissions-toggle-controller.js | 4 ++-- ext/js/pages/settings/popup-preview-controller.js | 4 ++-- ext/js/pages/settings/profile-conditions-ui.js | 10 +++++----- ext/js/pages/settings/profile-controller.js | 4 ++-- ext/js/pages/settings/scan-inputs-controller.js | 4 ++-- ext/js/pages/settings/scan-inputs-simple-controller.js | 4 ++-- .../pages/settings/secondary-search-dictionary-controller.js | 4 ++-- .../settings/sentence-termination-characters-controller.js | 6 +++--- ext/js/pages/settings/settings-display-controller.js | 4 ++-- ext/js/pages/settings/sort-frequency-dictionary-controller.js | 4 ++-- .../pages/settings/translation-text-replacements-controller.js | 4 ++-- 24 files changed, 57 insertions(+), 57 deletions(-) (limited to 'ext/js/pages/settings/dictionary-controller.js') diff --git a/.vscode/settings.json b/.vscode/settings.json index 81cd7b9c..734f6360 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "markdown.extension.toc.levels": "1..3", "editor.codeActionsOnSave": { "source.addMissingImports": false, - "source.organizeImports": true, + "source.organizeImports": false, "source.fixAll.eslint": false }, "eslint.format.enable": true, diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js index 722459df..05bfdadc 100644 --- a/ext/js/pages/settings/anki-controller.js +++ b/ext/js/pages/settings/anki-controller.js @@ -26,10 +26,10 @@ import {yomitan} from '../../yomitan.js'; export class AnkiController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {AnkiConnect} */ this._ankiConnect = new AnkiConnect(); @@ -67,7 +67,7 @@ export class AnkiController { this._validateFieldsToken = null; } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._settingsController; } @@ -562,12 +562,12 @@ export class AnkiController { class AnkiCardController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {AnkiController} ankiController * @param {HTMLElement} node */ constructor(settingsController, ankiController, node) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {AnkiController} */ this._ankiController = ankiController; diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js index a0ff96b2..875ade3c 100644 --- a/ext/js/pages/settings/anki-templates-controller.js +++ b/ext/js/pages/settings/anki-templates-controller.js @@ -23,12 +23,12 @@ import {yomitan} from '../../yomitan.js'; export class AnkiTemplatesController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {ModalController} modalController * @param {AnkiController} ankiController */ constructor(settingsController, modalController, ankiController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {ModalController} */ this._modalController = modalController; diff --git a/ext/js/pages/settings/audio-controller.js b/ext/js/pages/settings/audio-controller.js index 480597af..0bd56ff0 100644 --- a/ext/js/pages/settings/audio-controller.js +++ b/ext/js/pages/settings/audio-controller.js @@ -24,12 +24,12 @@ import {AudioSystem} from '../../media/audio-system.js'; */ export class AudioController extends EventDispatcher { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {ModalController} modalController */ constructor(settingsController, modalController) { super(); - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {ModalController} */ this._modalController = modalController; @@ -47,7 +47,7 @@ export class AudioController extends EventDispatcher { this._voices = []; } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._settingsController; } diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js index a05d0056..c701b975 100644 --- a/ext/js/pages/settings/backup-controller.js +++ b/ext/js/pages/settings/backup-controller.js @@ -25,11 +25,11 @@ import {DictionaryController} from './dictionary-controller.js'; export class BackupController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {?ModalController} modalController */ constructor(settingsController, modalController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?ModalController} */ this._modalController = modalController; diff --git a/ext/js/pages/settings/collapsible-dictionary-controller.js b/ext/js/pages/settings/collapsible-dictionary-controller.js index a508bae4..355292ad 100644 --- a/ext/js/pages/settings/collapsible-dictionary-controller.js +++ b/ext/js/pages/settings/collapsible-dictionary-controller.js @@ -21,10 +21,10 @@ import {yomitan} from '../../yomitan.js'; export class CollapsibleDictionaryController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?import('core').TokenObject} */ this._getDictionaryInfoToken = null; diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 85f7493f..aa59bb97 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -335,12 +335,12 @@ class DictionaryExtraInfo { export class DictionaryController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {ModalController} modalController * @param {StatusFooter} statusFooter */ constructor(settingsController, modalController, statusFooter) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {ModalController} */ this._modalController = modalController; @@ -494,7 +494,7 @@ export class DictionaryController { } /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {import('dictionary-importer').Summary[]|undefined} dictionaries * @param {import('settings').Options|undefined} optionsFull * @param {boolean} modifyGlobalSettings diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index af8c2fcd..04128b1a 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -24,12 +24,12 @@ import {DictionaryController} from './dictionary-controller.js'; export class DictionaryImportController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {ModalController} modalController * @param {StatusFooter} statusFooter */ constructor(settingsController, modalController, statusFooter) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {ModalController} */ this._modalController = modalController; diff --git a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js index 6c9a3864..d36d965a 100644 --- a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js +++ b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js @@ -23,10 +23,10 @@ import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; export class ExtensionKeyboardShortcutController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?HTMLButtonElement} */ this._resetButton = null; diff --git a/ext/js/pages/settings/generic-setting-controller.js b/ext/js/pages/settings/generic-setting-controller.js index 47c0d6fe..8666614b 100644 --- a/ext/js/pages/settings/generic-setting-controller.js +++ b/ext/js/pages/settings/generic-setting-controller.js @@ -22,10 +22,10 @@ import {DOMDataBinder} from '../../dom/dom-data-binder.js'; export class GenericSettingController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {import('settings-modifications').OptionsScopeType} */ this._defaultScope = 'profile'; diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js index 2fb1ff8a..32f22499 100644 --- a/ext/js/pages/settings/keyboard-shortcuts-controller.js +++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js @@ -24,10 +24,10 @@ import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; export class KeyboardShortcutController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {KeyboardShortcutHotkeyEntry[]} */ this._entries = []; @@ -71,7 +71,7 @@ export class KeyboardShortcutController { ]); } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._settingsController; } diff --git a/ext/js/pages/settings/nested-popups-controller.js b/ext/js/pages/settings/nested-popups-controller.js index ac078a0c..c01986ab 100644 --- a/ext/js/pages/settings/nested-popups-controller.js +++ b/ext/js/pages/settings/nested-popups-controller.js @@ -20,10 +20,10 @@ import {DocumentUtil} from '../../dom/document-util.js'; export class NestedPopupsController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {number} */ this._popupNestingMaxDepth = 0; diff --git a/ext/js/pages/settings/permissions-origin-controller.js b/ext/js/pages/settings/permissions-origin-controller.js index 9cad2fb2..a4271f92 100644 --- a/ext/js/pages/settings/permissions-origin-controller.js +++ b/ext/js/pages/settings/permissions-origin-controller.js @@ -20,10 +20,10 @@ import {EventListenerCollection} from '../../core.js'; export class PermissionsOriginController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?HTMLElement} */ this._originContainer = null; diff --git a/ext/js/pages/settings/permissions-toggle-controller.js b/ext/js/pages/settings/permissions-toggle-controller.js index ed4f7a8c..85752a7e 100644 --- a/ext/js/pages/settings/permissions-toggle-controller.js +++ b/ext/js/pages/settings/permissions-toggle-controller.js @@ -20,10 +20,10 @@ import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js' export class PermissionsToggleController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?NodeListOf} */ this._toggles = null; diff --git a/ext/js/pages/settings/popup-preview-controller.js b/ext/js/pages/settings/popup-preview-controller.js index c555f9cf..7239ca17 100644 --- a/ext/js/pages/settings/popup-preview-controller.js +++ b/ext/js/pages/settings/popup-preview-controller.js @@ -18,10 +18,10 @@ export class PopupPreviewController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {string} */ this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, ''); diff --git a/ext/js/pages/settings/profile-conditions-ui.js b/ext/js/pages/settings/profile-conditions-ui.js index 5ebd9011..8711518f 100644 --- a/ext/js/pages/settings/profile-conditions-ui.js +++ b/ext/js/pages/settings/profile-conditions-ui.js @@ -29,11 +29,11 @@ import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; */ export class ProfileConditionsUI extends EventDispatcher { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { super(); - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?import('environment').OperatingSystem} */ this._os = null; @@ -114,7 +114,7 @@ export class ProfileConditionsUI extends EventDispatcher { ]); } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._settingsController; } @@ -473,7 +473,7 @@ class ProfileConditionGroupUI { this._eventListeners = new EventListenerCollection(); } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._parent.settingsController; } @@ -652,7 +652,7 @@ class ProfileConditionUI { this._inputEventListeners = new EventListenerCollection(); } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._parent.parent.settingsController; } diff --git a/ext/js/pages/settings/profile-controller.js b/ext/js/pages/settings/profile-controller.js index a74a7567..64c2e2fd 100644 --- a/ext/js/pages/settings/profile-controller.js +++ b/ext/js/pages/settings/profile-controller.js @@ -22,11 +22,11 @@ import {ProfileConditionsUI} from './profile-conditions-ui.js'; export class ProfileController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {ModalController} modalController */ constructor(settingsController, modalController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {ModalController} */ this._modalController = modalController; diff --git a/ext/js/pages/settings/scan-inputs-controller.js b/ext/js/pages/settings/scan-inputs-controller.js index f294050b..0686540a 100644 --- a/ext/js/pages/settings/scan-inputs-controller.js +++ b/ext/js/pages/settings/scan-inputs-controller.js @@ -27,10 +27,10 @@ import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; export class ScanInputsController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?import('environment').OperatingSystem} */ this._os = null; diff --git a/ext/js/pages/settings/scan-inputs-simple-controller.js b/ext/js/pages/settings/scan-inputs-simple-controller.js index 1e422c5b..8d52af61 100644 --- a/ext/js/pages/settings/scan-inputs-simple-controller.js +++ b/ext/js/pages/settings/scan-inputs-simple-controller.js @@ -22,10 +22,10 @@ import {ScanInputsController} from './scan-inputs-controller.js'; export class ScanInputsSimpleController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?HTMLInputElement} */ this._middleMouseButtonScan = null; diff --git a/ext/js/pages/settings/secondary-search-dictionary-controller.js b/ext/js/pages/settings/secondary-search-dictionary-controller.js index 7c2d3907..b20bd475 100644 --- a/ext/js/pages/settings/secondary-search-dictionary-controller.js +++ b/ext/js/pages/settings/secondary-search-dictionary-controller.js @@ -21,10 +21,10 @@ import {yomitan} from '../../yomitan.js'; export class SecondarySearchDictionaryController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?import('core').TokenObject} */ this._getDictionaryInfoToken = null; diff --git a/ext/js/pages/settings/sentence-termination-characters-controller.js b/ext/js/pages/settings/sentence-termination-characters-controller.js index 3edabb67..80c4cdbe 100644 --- a/ext/js/pages/settings/sentence-termination-characters-controller.js +++ b/ext/js/pages/settings/sentence-termination-characters-controller.js @@ -20,10 +20,10 @@ import {EventListenerCollection} from '../../core.js'; export class SentenceTerminationCharactersController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {SentenceTerminationCharacterEntry[]} */ this._entries = []; @@ -39,7 +39,7 @@ export class SentenceTerminationCharactersController { this._emptyIndicator = null; } - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ get settingsController() { return this._settingsController; } diff --git a/ext/js/pages/settings/settings-display-controller.js b/ext/js/pages/settings/settings-display-controller.js index bcbd6a44..ca4fc32e 100644 --- a/ext/js/pages/settings/settings-display-controller.js +++ b/ext/js/pages/settings/settings-display-controller.js @@ -22,11 +22,11 @@ import {SelectorObserver} from '../../dom/selector-observer.js'; export class SettingsDisplayController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController * @param {ModalController} modalController */ constructor(settingsController, modalController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {ModalController} */ this._modalController = modalController; diff --git a/ext/js/pages/settings/sort-frequency-dictionary-controller.js b/ext/js/pages/settings/sort-frequency-dictionary-controller.js index 5c5841b1..e7759d95 100644 --- a/ext/js/pages/settings/sort-frequency-dictionary-controller.js +++ b/ext/js/pages/settings/sort-frequency-dictionary-controller.js @@ -20,10 +20,10 @@ import {yomitan} from '../../yomitan.js'; export class SortFrequencyDictionaryController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?HTMLSelectElement} */ this._sortFrequencyDictionarySelect = null; diff --git a/ext/js/pages/settings/translation-text-replacements-controller.js b/ext/js/pages/settings/translation-text-replacements-controller.js index 690ccfe8..050db8d1 100644 --- a/ext/js/pages/settings/translation-text-replacements-controller.js +++ b/ext/js/pages/settings/translation-text-replacements-controller.js @@ -20,10 +20,10 @@ import {EventListenerCollection} from '../../core.js'; export class TranslationTextReplacementsController { /** - * @param {SettingsController} settingsController + * @param {import('./settings-controller.js').SettingsController} settingsController */ constructor(settingsController) { - /** @type {SettingsController} */ + /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {?HTMLElement} */ this._entryContainer = null; -- cgit v1.2.3 From 5dc16745468c229e7c31f6cddaad83fb9c36b98f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 14:19:50 -0500 Subject: Update types --- .vscode/settings.json | 2 +- ext/js/pages/settings/anki-templates-controller.js | 10 +++++----- ext/js/pages/settings/audio-controller.js | 6 +++--- ext/js/pages/settings/backup-controller.js | 10 +++++----- ext/js/pages/settings/dictionary-controller.js | 18 +++++++++--------- .../pages/settings/dictionary-import-controller.js | 14 +++++++------- .../settings/keyboard-shortcuts-controller.js | 4 ++-- ext/js/pages/settings/popup-preview-frame.js | 8 ++++---- ext/js/pages/settings/profile-conditions-ui.js | 6 +----- ext/js/pages/settings/profile-controller.js | 22 +++++++++++----------- ext/js/pages/settings/scan-inputs-controller.js | 6 +----- .../pages/settings/settings-display-controller.js | 4 ++-- ext/js/pages/settings/storage-controller.js | 4 ++-- 13 files changed, 53 insertions(+), 61 deletions(-) (limited to 'ext/js/pages/settings/dictionary-controller.js') diff --git a/.vscode/settings.json b/.vscode/settings.json index 734f6360..81cd7b9c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "markdown.extension.toc.levels": "1..3", "editor.codeActionsOnSave": { "source.addMissingImports": false, - "source.organizeImports": false, + "source.organizeImports": true, "source.fixAll.eslint": false }, "eslint.format.enable": true, diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js index 875ade3c..89848ef3 100644 --- a/ext/js/pages/settings/anki-templates-controller.js +++ b/ext/js/pages/settings/anki-templates-controller.js @@ -24,15 +24,15 @@ import {yomitan} from '../../yomitan.js'; export class AnkiTemplatesController { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {ModalController} modalController - * @param {AnkiController} ankiController + * @param {import('./modal-controller.js').ModalController} modalController + * @param {import('./anki-controller.js').AnkiController} ankiController */ constructor(settingsController, modalController, ankiController) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; - /** @type {AnkiController} */ + /** @type {import('./anki-controller.js').AnkiController} */ this._ankiController = ankiController; /** @type {?import('dictionary').TermDictionaryEntry} */ this._cachedDictionaryEntryValue = null; @@ -48,7 +48,7 @@ export class AnkiTemplatesController { this._renderFieldInput = null; /** @type {?HTMLElement} */ this._renderResult = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._fieldTemplateResetModal = null; /** @type {AnkiNoteBuilder} */ this._ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil: new JapaneseUtil(null)}); diff --git a/ext/js/pages/settings/audio-controller.js b/ext/js/pages/settings/audio-controller.js index 0bd56ff0..0a3f9454 100644 --- a/ext/js/pages/settings/audio-controller.js +++ b/ext/js/pages/settings/audio-controller.js @@ -25,13 +25,13 @@ import {AudioSystem} from '../../media/audio-system.js'; export class AudioController extends EventDispatcher { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {ModalController} modalController + * @param {import('./modal-controller.js').ModalController} modalController */ constructor(settingsController, modalController) { super(); /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; /** @type {AudioSystem} */ this._audioSystem = new AudioSystem(); @@ -52,7 +52,7 @@ export class AudioController extends EventDispatcher { return this._settingsController; } - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ get modalController() { return this._modalController; } diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js index c701b975..50a50b1a 100644 --- a/ext/js/pages/settings/backup-controller.js +++ b/ext/js/pages/settings/backup-controller.js @@ -26,12 +26,12 @@ import {DictionaryController} from './dictionary-controller.js'; export class BackupController { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {?ModalController} modalController + * @param {?import('./modal-controller.js').ModalController} modalController */ constructor(settingsController, modalController) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {?ModalController} */ + /** @type {?import('./modal-controller.js').ModalController} */ this._modalController = modalController; /** @type {?import('core').TokenObject} */ this._settingsExportToken = null; @@ -39,11 +39,11 @@ export class BackupController { this._settingsExportRevoke = null; /** @type {number} */ this._currentVersion = 0; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._settingsResetModal = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._settingsImportErrorModal = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._settingsImportWarningModal = null; /** @type {?OptionsUtil} */ this._optionsUtil = null; diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index aa59bb97..de63b200 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -336,15 +336,15 @@ class DictionaryExtraInfo { export class DictionaryController { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {ModalController} modalController - * @param {StatusFooter} statusFooter + * @param {import('./modal-controller.js').ModalController} modalController + * @param {import('./status-footer.js').StatusFooter} statusFooter */ constructor(settingsController, modalController, statusFooter) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; - /** @type {StatusFooter} */ + /** @type {import('./status-footer.js').StatusFooter} */ this._statusFooter = statusFooter; /** @type {?import('dictionary-importer').Summary[]} */ this._dictionaries = null; @@ -366,7 +366,7 @@ export class DictionaryController { this._noDictionariesInstalledWarnings = null; /** @type {?NodeListOf} */ this._noDictionariesEnabledWarnings = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._deleteDictionaryModal = null; /** @type {?HTMLInputElement} */ this._allCheckbox = null; @@ -376,7 +376,7 @@ export class DictionaryController { this._isDeleting = false; } - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ get modalController() { return this._modalController; } @@ -418,7 +418,7 @@ export class DictionaryController { */ deleteDictionary(dictionaryTitle) { if (this._isDeleting) { return; } - const modal = /** @type {Modal} */ (this._deleteDictionaryModal); + const modal = /** @type {import('./modal.js').Modal} */ (this._deleteDictionaryModal); modal.node.dataset.dictionaryTitle = dictionaryTitle; const nameElement = /** @type {Element} */ (modal.node.querySelector('#dictionary-confirm-delete-name')); nameElement.textContent = dictionaryTitle; @@ -671,7 +671,7 @@ export class DictionaryController { _onDictionaryConfirmDelete(e) { e.preventDefault(); - const modal = /** @type {Modal} */ (this._deleteDictionaryModal); + const modal = /** @type {import('./modal.js').Modal} */ (this._deleteDictionaryModal); modal.setVisible(false); const title = modal.node.dataset.dictionaryTitle; @@ -691,7 +691,7 @@ export class DictionaryController { /** */ _onDictionaryMoveButtonClick() { - const modal = /** @type {Modal} */ (this._modalController.getModal('dictionary-move-location')); + const modal = /** @type {import('./modal.js').Modal} */ (this._modalController.getModal('dictionary-move-location')); const {index} = modal.node.dataset; if (typeof index !== 'number') { return; } const indexNumber = Number.parseInt(index, 10); diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index 04128b1a..d1255e11 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -25,15 +25,15 @@ import {DictionaryController} from './dictionary-controller.js'; export class DictionaryImportController { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {ModalController} modalController - * @param {StatusFooter} statusFooter + * @param {import('./modal-controller.js').ModalController} modalController + * @param {import('./status-footer.js').StatusFooter} statusFooter */ constructor(settingsController, modalController, statusFooter) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; - /** @type {StatusFooter} */ + /** @type {import('./status-footer.js').StatusFooter} */ this._statusFooter = statusFooter; /** @type {boolean} */ this._modifying = false; @@ -45,7 +45,7 @@ export class DictionaryImportController { this._importFileButton = null; /** @type {?HTMLInputElement} */ this._importFileInput = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._purgeConfirmModal = null; /** @type {?HTMLElement} */ this._errorContainer = null; @@ -95,7 +95,7 @@ export class DictionaryImportController { */ _onPurgeButtonClick(e) { e.preventDefault(); - /** @type {Modal} */ (this._purgeConfirmModal).setVisible(true); + /** @type {import('./modal.js').Modal} */ (this._purgeConfirmModal).setVisible(true); } /** @@ -103,7 +103,7 @@ export class DictionaryImportController { */ _onPurgeConfirmButtonClick(e) { e.preventDefault(); - /** @type {Modal} */ (this._purgeConfirmModal).setVisible(false); + /** @type {import('./modal.js').Modal} */ (this._purgeConfirmModal).setVisible(false); this._purgeDatabase(); } diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js index 32f22499..ad16b0e9 100644 --- a/ext/js/pages/settings/keyboard-shortcuts-controller.js +++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js @@ -267,7 +267,7 @@ class KeyboardShortcutHotkeyEntry { this._stringComparer = stringComparer; /** @type {?HTMLButtonElement} */ this._enabledButton = null; - /** @type {?PopupMenu} */ + /** @type {?import('../../dom/popup-menu.js').PopupMenu} */ this._scopeMenu = null; /** @type {EventListenerCollection} */ this._scopeMenuEventListeners = new EventListenerCollection(); @@ -629,7 +629,7 @@ class KeyboardShortcutHotkeyEntry { } /** - * @param {PopupMenu} menu + * @param {import('../../dom/popup-menu.js').PopupMenu} menu */ _updateScopeMenuItems(menu) { this._scopeMenuEventListeners.removeAllEventListeners(); diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js index acf4e0de..c1a0d706 100644 --- a/ext/js/pages/settings/popup-preview-frame.js +++ b/ext/js/pages/settings/popup-preview-frame.js @@ -25,17 +25,17 @@ export class PopupPreviewFrame { /** * @param {number} tabId * @param {number} frameId - * @param {PopupFactory} popupFactory - * @param {HotkeyHandler} hotkeyHandler + * @param {import('../../app/popup-factory.js').PopupFactory} popupFactory + * @param {import('../../input/hotkey-handler.js').HotkeyHandler} hotkeyHandler */ constructor(tabId, frameId, popupFactory, hotkeyHandler) { /** @type {number} */ this._tabId = tabId; /** @type {number} */ this._frameId = frameId; - /** @type {PopupFactory} */ + /** @type {import('../../app/popup-factory.js').PopupFactory} */ this._popupFactory = popupFactory; - /** @type {HotkeyHandler} */ + /** @type {import('../../input/hotkey-handler.js').HotkeyHandler} */ this._hotkeyHandler = hotkeyHandler; /** @type {?Frontend} */ this._frontend = null; diff --git a/ext/js/pages/settings/profile-conditions-ui.js b/ext/js/pages/settings/profile-conditions-ui.js index 8711518f..96aef83f 100644 --- a/ext/js/pages/settings/profile-conditions-ui.js +++ b/ext/js/pages/settings/profile-conditions-ui.js @@ -17,13 +17,9 @@ */ import {EventDispatcher, EventListenerCollection} from '../../core.js'; +import {DocumentUtil} from '../../dom/document-util.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; -/* global - * DocumentUtil - * KeyboardMouseInputField - */ - /** * @augments EventDispatcher */ diff --git a/ext/js/pages/settings/profile-controller.js b/ext/js/pages/settings/profile-controller.js index 64c2e2fd..c82223b8 100644 --- a/ext/js/pages/settings/profile-controller.js +++ b/ext/js/pages/settings/profile-controller.js @@ -23,12 +23,12 @@ import {ProfileConditionsUI} from './profile-conditions-ui.js'; export class ProfileController { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {ModalController} modalController + * @param {import('./modal-controller.js').ModalController} modalController */ constructor(settingsController, modalController) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; /** @type {ProfileConditionsUI} */ this._profileConditionsUI = new ProfileConditionsUI(settingsController); @@ -52,11 +52,11 @@ export class ProfileController { this._profileEntryListContainer = null; /** @type {?HTMLElement} */ this._profileConditionsProfileName = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._profileRemoveModal = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._profileCopyModal = null; - /** @type {?Modal} */ + /** @type {?import('./modal.js').Modal} */ this._profileConditionsModal = null; /** @type {boolean} */ this._profileEntriesSupported = false; @@ -340,8 +340,8 @@ export class ProfileController { if (profile === null || this.profileCount <= 1) { return; } /** @type {HTMLElement} */ (this._removeProfileNameElement).textContent = profile.name; - /** @type {Modal} */ (this._profileRemoveModal).node.dataset.profileIndex = `${profileIndex}`; - /** @type {Modal} */ (this._profileRemoveModal).setVisible(true); + /** @type {import('./modal.js').Modal} */ (this._profileRemoveModal).node.dataset.profileIndex = `${profileIndex}`; + /** @type {import('./modal.js').Modal} */ (this._profileRemoveModal).setVisible(true); } /** @@ -368,8 +368,8 @@ export class ProfileController { } select.value = `${copyFromIndex}`; - /** @type {Modal} */ (this._profileCopyModal).node.dataset.profileIndex = `${profileIndex}`; - /** @type {Modal} */ (this._profileCopyModal).setVisible(true); + /** @type {import('./modal.js').Modal} */ (this._profileCopyModal).node.dataset.profileIndex = `${profileIndex}`; + /** @type {import('./modal.js').Modal} */ (this._profileCopyModal).setVisible(true); } /** @@ -453,7 +453,7 @@ export class ProfileController { /** */ _onDeleteConfirm() { - const modal = /** @type {Modal} */ (this._profileRemoveModal); + const modal = /** @type {import('./modal.js').Modal} */ (this._profileRemoveModal); modal.setVisible(false); const {node} = modal; const profileIndex = node.dataset.profileIndex; @@ -467,7 +467,7 @@ export class ProfileController { /** */ _onCopyConfirm() { - const modal = /** @type {Modal} */ (this._profileCopyModal); + const modal = /** @type {import('./modal.js').Modal} */ (this._profileCopyModal); modal.setVisible(false); const {node} = modal; const destinationProfileIndex = node.dataset.profileIndex; diff --git a/ext/js/pages/settings/scan-inputs-controller.js b/ext/js/pages/settings/scan-inputs-controller.js index 0686540a..53423bdc 100644 --- a/ext/js/pages/settings/scan-inputs-controller.js +++ b/ext/js/pages/settings/scan-inputs-controller.js @@ -17,14 +17,10 @@ */ import {EventListenerCollection} from '../../core.js'; +import {DocumentUtil} from '../../dom/document-util.js'; import {yomitan} from '../../yomitan.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; -/* global - * DocumentUtil - * KeyboardMouseInputField - */ - export class ScanInputsController { /** * @param {import('./settings-controller.js').SettingsController} settingsController diff --git a/ext/js/pages/settings/settings-display-controller.js b/ext/js/pages/settings/settings-display-controller.js index ca4fc32e..16e6cfae 100644 --- a/ext/js/pages/settings/settings-display-controller.js +++ b/ext/js/pages/settings/settings-display-controller.js @@ -23,12 +23,12 @@ import {SelectorObserver} from '../../dom/selector-observer.js'; export class SettingsDisplayController { /** * @param {import('./settings-controller.js').SettingsController} settingsController - * @param {ModalController} modalController + * @param {import('./modal-controller.js').ModalController} modalController */ constructor(settingsController, modalController) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {ModalController} */ + /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; /** @type {?HTMLElement} */ this._contentNode = null; diff --git a/ext/js/pages/settings/storage-controller.js b/ext/js/pages/settings/storage-controller.js index 8af44b33..7f323b48 100644 --- a/ext/js/pages/settings/storage-controller.js +++ b/ext/js/pages/settings/storage-controller.js @@ -20,10 +20,10 @@ import {yomitan} from '../../yomitan.js'; export class StorageController { /** - * @param {PersistentStorageController} persistentStorageController + * @param {import('./persistent-storage-controller.js').PersistentStorageController} persistentStorageController */ constructor(persistentStorageController) { - /** @type {PersistentStorageController} */ + /** @type {import('./persistent-storage-controller.js').PersistentStorageController} */ this._persistentStorageController = persistentStorageController; /** @type {?StorageEstimate} */ this._mostRecentStorageEstimate = null; -- cgit v1.2.3