From dfd42bad0b46845ad88d1fdc5fa82b4f03bab0f3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 1 Feb 2024 10:00:59 -0500 Subject: Application refactor (#591) * Rename Yomitan class to Application, change initialization style * Rename file * Update init * Update config * Remove dead code --- types/ext/anki-note-builder.d.ts | 20 ++++++++++++++++++++ types/ext/display.d.ts | 2 ++ types/ext/frontend.d.ts | 3 +++ types/ext/popup.d.ts | 7 +++++++ types/ext/text-scanner.d.ts | 2 ++ 5 files changed, 34 insertions(+) (limited to 'types/ext') diff --git a/types/ext/anki-note-builder.d.ts b/types/ext/anki-note-builder.d.ts index 092978ed..8aec3342 100644 --- a/types/ext/anki-note-builder.d.ts +++ b/types/ext/anki-note-builder.d.ts @@ -23,6 +23,7 @@ import type * as Dictionary from './dictionary'; import type * as Extension from './extension'; import type * as Settings from './settings'; import type * as TemplateRenderer from './template-renderer'; +import type * as Api from './api'; export type CreateNoteDetails = { dictionaryEntry: Dictionary.DictionaryEntry; @@ -118,3 +119,22 @@ export type BatchedRequestData = { reject: (reason?: unknown) => void; marker: string; }; + +export type MinimalApi = { + injectAnkiNoteMedia( + timestamp: Api.ApiParam<'injectAnkiNoteMedia', 'timestamp'>, + definitionDetails: Api.ApiParam<'injectAnkiNoteMedia', 'definitionDetails'>, + audioDetails: Api.ApiParam<'injectAnkiNoteMedia', 'audioDetails'>, + screenshotDetails: Api.ApiParam<'injectAnkiNoteMedia', 'screenshotDetails'>, + clipboardDetails: Api.ApiParam<'injectAnkiNoteMedia', 'clipboardDetails'>, + dictionaryMediaDetails: Api.ApiParam<'injectAnkiNoteMedia', 'dictionaryMediaDetails'>, + ): Promise>; + + parseText( + text: Api.ApiParam<'parseText', 'text'>, + optionsContext: Api.ApiParam<'parseText', 'optionsContext'>, + scanLength: Api.ApiParam<'parseText', 'scanLength'>, + useInternalParser: Api.ApiParam<'parseText', 'useInternalParser'>, + useMecabParser: Api.ApiParam<'parseText', 'useMecabParser'>, + ): Promise>; +}; diff --git a/types/ext/display.d.ts b/types/ext/display.d.ts index da24af75..351cf067 100644 --- a/types/ext/display.d.ts +++ b/types/ext/display.d.ts @@ -18,6 +18,7 @@ import type {DisplayContentManager} from '../../ext/js/display/display-content-manager'; import type {HotkeyHelpController} from '../../ext/js/input/hotkey-help-controller'; import type {TextSourceGenerator} from '../../ext/js/dom/text-source-generator'; +import type {API} from '../../ext/js/comm/api'; import type * as Dictionary from './dictionary'; import type * as Extension from './extension'; import type * as Settings from './settings'; @@ -127,6 +128,7 @@ export type SearchMode = null | 'popup' | 'action-popup'; export type GetSearchContextCallback = TextScannerTypes.GetSearchContextCallbackSync; export type QueryParserConstructorDetails = { + api: API; getSearchContext: GetSearchContextCallback; textSourceGenerator: TextSourceGenerator; }; diff --git a/types/ext/frontend.d.ts b/types/ext/frontend.d.ts index 53a849a2..17f3d121 100644 --- a/types/ext/frontend.d.ts +++ b/types/ext/frontend.d.ts @@ -17,9 +17,12 @@ import type {PopupFactory} from '../../ext/js/app/popup-factory'; import type {HotkeyHandler} from '../../ext/js/input/hotkey-handler'; +import type {Application} from '../../ext/js/application'; /** Details about how to set up the instance. */ export type ConstructorDetails = { + /** The main application instance. */ + application: Application; /** The type of page, one of 'web', 'popup', or 'search'. */ pageType: PageType; /** A PopupFactory instance to use for generating popups. */ diff --git a/types/ext/popup.d.ts b/types/ext/popup.d.ts index 4246e24e..1ea25c15 100644 --- a/types/ext/popup.d.ts +++ b/types/ext/popup.d.ts @@ -19,6 +19,7 @@ import type {Popup} from '../../ext/js/app/popup'; import type {PopupProxy} from '../../ext/js/app/popup-proxy'; import type {PopupWindow} from '../../ext/js/app/popup-window'; import type {FrameOffsetForwarder} from '../../ext/js/comm/frame-offset-forwarder'; +import type {Application} from '../../ext/js/application'; import type * as DocumentUtil from './document-util'; import type * as Settings from './settings'; import type {EventNames, EventArgument as BaseEventArgument} from './core'; @@ -92,6 +93,8 @@ export type ValidSize = { }; export type PopupConstructorDetails = { + /** The main application instance. */ + application: Application; /** The ID of the popup. */ id: string; /** The depth of the popup. */ @@ -103,6 +106,8 @@ export type PopupConstructorDetails = { }; export type PopupWindowConstructorDetails = { + /** The main application instance. */ + application: Application; /** The ID of the popup. */ id: string; /** The depth of the popup. */ @@ -112,6 +117,8 @@ export type PopupWindowConstructorDetails = { }; export type PopupProxyConstructorDetails = { + /** The main application instance. */ + application: Application; /** The ID of the popup. */ id: string; /** The depth of the popup. */ diff --git a/types/ext/text-scanner.d.ts b/types/ext/text-scanner.d.ts index 3e1cb6c2..4253d6cc 100644 --- a/types/ext/text-scanner.d.ts +++ b/types/ext/text-scanner.d.ts @@ -17,6 +17,7 @@ import type {TextScanner} from '../../ext/js/language/text-scanner'; import type {TextSourceGenerator} from '../../ext/js/dom/text-source-generator'; +import type {API} from '../../ext/js/comm/api'; import type * as Dictionary from './dictionary'; import type * as Display from './display'; import type * as Input from './input'; @@ -138,6 +139,7 @@ export type GetSearchContextCallbackSync = () => SearchContext; export type GetSearchContextCallbackAsync = () => Promise; export type ConstructorDetails = { + api: API; node: HTMLElement | Window; getSearchContext: GetSearchContextCallback; ignoreElements?: (() => Element[]) | null; -- cgit v1.2.3