aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-28 22:17:38 -0500
committerGitHub <noreply@github.com>2023-12-29 03:17:38 +0000
commit1e254fd1d4423b984e176547ef36a14383bbd7f5 (patch)
tree8aae2c47f80265d5f1f39c927e19455ec3986387 /types
parenta51ae1533c54162f14785652e9128f90afb86aed (diff)
Event dispatcher refactor (#463)
* Refactor EventDispatcher template type * Update core types * Update log * Update clipboard monitor * Update application events * Update popup events * Update text scanner * Update cross frame API * Update display events * Type updates * Update display history * Update query parser * Update search persistent state controller * Update panel element * Update popup menu * Update audio system * Update hotkey handler * Update settings controller * Update audio controller * Update types * Update types * Update types * Add event handler types * Update type * Fix issues * Remove error suppression * Fix typo
Diffstat (limited to 'types')
-rw-r--r--types/ext/application.d.ts20
-rw-r--r--types/ext/audio-controller.d.ts8
-rw-r--r--types/ext/audio-system.d.ts8
-rw-r--r--types/ext/clipboard-monitor.d.ts14
-rw-r--r--types/ext/core.d.ts14
-rw-r--r--types/ext/cross-frame-api.d.ts5
-rw-r--r--types/ext/display-history.d.ts11
-rw-r--r--types/ext/display.d.ts82
-rw-r--r--types/ext/dynamic-property.d.ts10
-rw-r--r--types/ext/event-listener-collection.d.ts9
-rw-r--r--types/ext/extension.d.ts2
-rw-r--r--types/ext/hotkey-handler.d.ts13
-rw-r--r--types/ext/keyboard-mouse-input-field.d.ts15
-rw-r--r--types/ext/log.d.ts14
-rw-r--r--types/ext/panel-element.d.ts23
-rw-r--r--types/ext/popup-menu.d.ts29
-rw-r--r--types/ext/popup.d.ts28
-rw-r--r--types/ext/profile-conditions-ui.d.ts15
-rw-r--r--types/ext/query-parser.d.ts39
-rw-r--r--types/ext/search-persistent-state-controller.d.ts27
-rw-r--r--types/ext/settings-controller.d.ts33
-rw-r--r--types/ext/text-scanner.d.ts12
22 files changed, 276 insertions, 155 deletions
diff --git a/types/ext/application.d.ts b/types/ext/application.d.ts
index ac594abc..5c103fd7 100644
--- a/types/ext/application.d.ts
+++ b/types/ext/application.d.ts
@@ -19,6 +19,7 @@ import type {TokenString} from './core';
import type {SearchMode} from './display';
import type {FrameEndpointReadyDetails, FrameEndpointConnectedDetails} from './frame-client';
import type {DatabaseUpdateType, DatabaseUpdateCause} from './backend';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
import type {
ApiMap as BaseApiMap,
ApiHandler as BaseApiHandler,
@@ -146,3 +147,22 @@ export type ApiMap = BaseApiMap<ApiSurface>;
export type ApiHandler<TName extends ApiNames> = BaseApiHandler<ApiSurface[TName]>;
export type ApiReturn<TName extends ApiNames> = BaseApiReturn<ApiSurface[TName]>;
+
+export type Events = {
+ extensionUnloaded: Record<string, never>;
+ optionsUpdated: {
+ source: string;
+ };
+ databaseUpdated: {
+ type: DatabaseUpdateType;
+ cause: DatabaseUpdateCause;
+ };
+ zoomChanged: {
+ oldZoomFactor: number;
+ newZoomFactor: number;
+ };
+ closePopups: Record<string, never>;
+ storageChanged: Record<string, never>;
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/audio-controller.d.ts b/types/ext/audio-controller.d.ts
index e8317aaf..cc1887fb 100644
--- a/types/ext/audio-controller.d.ts
+++ b/types/ext/audio-controller.d.ts
@@ -15,7 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export type EventType = 'voicesUpdated';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
+
+export type Events = {
+ voicesUpdated: Record<string, never>;
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type VoiceInfo = {
voice: SpeechSynthesisVoice;
diff --git a/types/ext/audio-system.d.ts b/types/ext/audio-system.d.ts
index e9766ed1..715f6afe 100644
--- a/types/ext/audio-system.d.ts
+++ b/types/ext/audio-system.d.ts
@@ -15,4 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export type EventType = 'voiceschanged';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
+
+export type Events = {
+ voiceschanged: Event;
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/clipboard-monitor.d.ts b/types/ext/clipboard-monitor.d.ts
index f8cf7d02..b0bb840b 100644
--- a/types/ext/clipboard-monitor.d.ts
+++ b/types/ext/clipboard-monitor.d.ts
@@ -15,12 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export type EventType = 'change';
-
-export type ChangeEvent = {
- text: string;
-};
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
export type ClipboardReaderLike = {
getText: (useRichText: boolean) => Promise<string>;
};
+
+export type Events = {
+ change: {
+ text: string;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/core.d.ts b/types/ext/core.d.ts
index c71a8ec4..b94b649b 100644
--- a/types/ext/core.d.ts
+++ b/types/ext/core.d.ts
@@ -88,3 +88,17 @@ export type MessageHandlerMapInit = MessageHandlerMapInitItem[];
export type MessageHandlerMapInitItem = [key: string, handlerDetails: MessageHandler];
export type Timeout = number | NodeJS.Timeout;
+
+export type EventSurface = {[name: string]: unknown};
+
+export type EventNames<TSurface extends EventSurface> = keyof TSurface & string;
+
+export type EventArgument<TSurface extends EventSurface, TName extends EventNames<TSurface>> = TSurface[TName];
+
+export type EventDispatcherOffGeneric = {
+ off(eventName: string, callback: (...args: SafeAny) => void): boolean;
+};
+
+export type EventHandler<TSurface extends EventSurface, TName extends EventNames<TSurface>> = (details: EventArgument<TSurface, TName>) => void;
+
+export type EventHandlerAny = (details: SafeAny) => void;
diff --git a/types/ext/cross-frame-api.d.ts b/types/ext/cross-frame-api.d.ts
index b9cf8ad1..8ddca6e7 100644
--- a/types/ext/cross-frame-api.d.ts
+++ b/types/ext/cross-frame-api.d.ts
@@ -15,9 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import type {CrossFrameAPIPort} from '../../ext/js/comm/cross-frame-api.js';
import type * as Core from './core';
-export type CrossFrameAPIPortEventType = 'disconnect';
+export type CrossFrameAPIPortEvents = {
+ disconnect: CrossFrameAPIPort;
+};
export type AcknowledgeMessage = {
type: 'ack';
diff --git a/types/ext/display-history.d.ts b/types/ext/display-history.d.ts
index 2ba5006b..3a99d443 100644
--- a/types/ext/display-history.d.ts
+++ b/types/ext/display-history.d.ts
@@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
import type * as Display from './display';
export type Entry = {
@@ -30,8 +31,10 @@ export type EntryState = Display.HistoryState;
export type EntryContent = Display.HistoryContent;
-export type EventType = 'stateChanged';
-
-export type StateChangedEvent = {
- synthetic: boolean;
+export type Events = {
+ stateChanged: {
+ synthetic: boolean;
+ };
};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/display.d.ts b/types/ext/display.d.ts
index aa0f0353..bafb1fa1 100644
--- a/types/ext/display.d.ts
+++ b/types/ext/display.d.ts
@@ -18,13 +18,12 @@
import type {DisplayContentManager} from '../../ext/js/display/display-content-manager';
import type {HotkeyHelpController} from '../../ext/js/input/hotkey-help-controller';
import type {JapaneseUtil} from '../../ext/js/language/sandbox/japanese-util';
-import type {TextScanner} from '../../ext/js/language/text-scanner';
import type * as Core from './core';
import type * as Dictionary from './dictionary';
import type * as Extension from './extension';
import type * as Settings from './settings';
import type * as TextScannerTypes from './text-scanner';
-import type * as TextSource from './text-source';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
export type HistoryMode = 'clear' | 'overwrite' | 'new';
@@ -114,8 +113,6 @@ export type HistoryContent = {
contentOrigin?: Extension.ContentOrigin;
};
-export type SearchPersistentStateControllerEventType = 'modeChange';
-
export type SearchMode = null | 'popup' | 'action-popup';
export type GetSearchContextCallback = TextScannerTypes.GetSearchContextCallbackSync;
@@ -134,56 +131,33 @@ export type QueryParserOptions = {
scanning: TextScannerTypes.Options;
};
-export type QueryParserEventType = 'searched';
-
-export type QueryParserSearchedEvent = {
- textScanner: TextScanner;
- type: PageType;
- dictionaryEntries: Dictionary.DictionaryEntry[];
- sentence: HistoryStateSentence;
- inputInfo: TextScannerTypes.InputInfo;
- textSource: TextSource.TextSource;
- optionsContext: Settings.OptionsContext;
- sentenceOffset: number | null;
-};
-
-export type DisplayEventType = (
- 'optionsUpdated' |
- 'frameVisibilityChange' |
- 'logDictionaryEntryData' |
- 'contentClear' |
- 'contentUpdateStart' |
- 'contentUpdateEntry' |
- 'contentUpdateComplete'
-);
-
-export type OptionsUpdatedEvent = {
- options: Settings.ProfileOptions;
-};
-
-export type FrameVisibilityChangeEvent = {
- value: boolean;
-};
-
-export type LogDictionaryEntryDataEvent = {
- dictionaryEntry: Dictionary.DictionaryEntry;
- promises: Promise<unknown>[];
-};
-
-export type ContentUpdateStartEvent = {
- type: PageType;
- query: string;
-};
-
-export type ContentUpdateEntryEvent = {
- dictionaryEntry: Dictionary.DictionaryEntry;
- element: Element;
- index: number;
-};
-
-export type ContentUpdateCompleteEvent = {
- type: PageType;
-};
+export type Events = {
+ optionsUpdated: {
+ options: Settings.ProfileOptions;
+ };
+ frameVisibilityChange: {
+ value: boolean;
+ };
+ logDictionaryEntryData: {
+ dictionaryEntry: Dictionary.DictionaryEntry;
+ promises: Promise<unknown>[];
+ };
+ contentClear: Record<string, never>;
+ contentUpdateStart: {
+ type: PageType;
+ query: string;
+ };
+ contentUpdateEntry: {
+ dictionaryEntry: Dictionary.DictionaryEntry;
+ element: Element;
+ index: number;
+ };
+ contentUpdateComplete: {
+ type: PageType;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type ConfigureMessageDetails = {
depth: number;
diff --git a/types/ext/dynamic-property.d.ts b/types/ext/dynamic-property.d.ts
index ba15257a..8dde372b 100644
--- a/types/ext/dynamic-property.d.ts
+++ b/types/ext/dynamic-property.d.ts
@@ -15,8 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export type EventType = 'change';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type ChangeEventDetails<T = unknown> = {
- value: T;
+export type Events<T = unknown> = {
+ change: {
+ value: T;
+ };
};
+
+export type EventArgument<T, TName extends EventNames<Events<T>>> = BaseEventArgument<Events<T>, TName>;
diff --git a/types/ext/event-listener-collection.d.ts b/types/ext/event-listener-collection.d.ts
index 988baa76..415c48c4 100644
--- a/types/ext/event-listener-collection.d.ts
+++ b/types/ext/event-listener-collection.d.ts
@@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type {EventDispatcher} from '../../ext/js/core';
import type * as Core from './core';
export type EventListenerFunction = (...args: Core.SafeAny[]) => unknown;
@@ -55,7 +54,7 @@ export type ExtensionEventDetails = {
export type EventDispatcherDetails = {
type: 'off';
- target: EventDispatcher<string>;
+ target: Core.EventDispatcherOffGeneric;
eventName: string;
callback: EventListenerFunction;
};
@@ -68,9 +67,3 @@ export type AddEventListenerArgs = [
listener: EventListener | EventListenerObject | EventListenerFunction,
options?: AddEventListenerOptions | boolean,
];
-
-export type OnArgs = [
- target: EventDispatcher<string>,
- eventName: string,
- callback: (details: Core.SafeAny) => void,
-];
diff --git a/types/ext/extension.d.ts b/types/ext/extension.d.ts
index 5a244566..5c4aa175 100644
--- a/types/ext/extension.d.ts
+++ b/types/ext/extension.d.ts
@@ -47,8 +47,6 @@ export type ChromeRuntimeSendMessageArgs5 = [
export type ChromeRuntimeSendMessageArgs = ChromeRuntimeSendMessageArgs1 | ChromeRuntimeSendMessageArgs2 | ChromeRuntimeSendMessageArgs3 | ChromeRuntimeSendMessageArgs4 | ChromeRuntimeSendMessageArgs5;
-export type ExtensionEventType = 'extensionUnloaded' | 'optionsUpdated' | 'databaseUpdated' | 'zoomChanged' | 'closePopups' | 'dynamicLoaderSentinel' | 'storageChanged';
-
export type HtmlElementWithContentWindow = HTMLIFrameElement | HTMLFrameElement | HTMLObjectElement;
export type ContentOrigin = {
diff --git a/types/ext/hotkey-handler.d.ts b/types/ext/hotkey-handler.d.ts
index 7b2b4cb3..c108d347 100644
--- a/types/ext/hotkey-handler.d.ts
+++ b/types/ext/hotkey-handler.d.ts
@@ -15,12 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type * as Input from './input';
-
-export type EventType = 'keydownNonHotkey';
+import type {ModifierKey} from './input';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
export type HotkeyInfo = {
- modifiers: Set<Input.ModifierKey>;
+ modifiers: Set<ModifierKey>;
action: string;
argument: unknown;
};
@@ -28,3 +27,9 @@ export type HotkeyInfo = {
export type HotkeyHandlers = {
handlers: HotkeyInfo[];
};
+
+export type Events = {
+ keydownNonHotkey: KeyboardEvent;
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/keyboard-mouse-input-field.d.ts b/types/ext/keyboard-mouse-input-field.d.ts
index 321e49cc..572ffc56 100644
--- a/types/ext/keyboard-mouse-input-field.d.ts
+++ b/types/ext/keyboard-mouse-input-field.d.ts
@@ -15,11 +15,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type * as Input from './input';
+import type {Modifier} from './input';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type EventType = 'change';
-
-export type ChangeEvent = {
- key: string | null;
- modifiers: Input.Modifier[];
+export type Events = {
+ change: {
+ key: string | null;
+ modifiers: Modifier[];
+ };
};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/log.d.ts b/types/ext/log.d.ts
index 904bf848..e8ca4c43 100644
--- a/types/ext/log.d.ts
+++ b/types/ext/log.d.ts
@@ -15,9 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export type LogLevel = 'log' | 'info' | 'debug' | 'warn' | 'error';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type LoggerEventType = 'log';
+export type LogLevel = 'log' | 'info' | 'debug' | 'warn' | 'error';
export type LogContext = {
url: string;
@@ -33,3 +33,13 @@ export type LogContext = {
* `2` _error_ level.
*/
export type LogErrorLevelValue = 0 | 1 | 2;
+
+export type Events = {
+ log: {
+ error: unknown;
+ level: LogLevel;
+ context: LogContext;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/panel-element.d.ts b/types/ext/panel-element.d.ts
index d267b836..164acba5 100644
--- a/types/ext/panel-element.d.ts
+++ b/types/ext/panel-element.d.ts
@@ -15,23 +15,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export type EventType = 'visibilityChanged' | 'closeCompleted';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type VisibilityChangedEvent = {
- visible: boolean;
+export type Events = {
+ visibilityChanged: {
+ visible: boolean;
+ };
+ closeCompleted: {
+ reopening: boolean;
+ };
};
-export type CloseCompletedEvent = {
- reopening: boolean;
-};
-
-/* eslint-disable @stylistic/ts/indent */
-export type Event<T extends EventType> = (
- T extends 'visibilityChanged' ? VisibilityChangedEvent :
- T extends 'closeCompleted' ? CloseCompletedEvent :
- never
-);
-/* eslint-enable @stylistic/ts/indent */
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type ConstructorDetails = {
node: HTMLElement;
diff --git a/types/ext/popup-menu.d.ts b/types/ext/popup-menu.d.ts
index b6e37316..71b94468 100644
--- a/types/ext/popup-menu.d.ts
+++ b/types/ext/popup-menu.d.ts
@@ -16,8 +16,22 @@
*/
import type {PopupMenu} from '../../ext/js/dom/popup-menu';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type EventType = 'close';
+export type Events = {
+ close: {
+ menu: PopupMenu;
+ item: HTMLElement | null;
+ action: string | null;
+ cause: CloseReason;
+ altKey: boolean;
+ ctrlKey: boolean;
+ metaKey: boolean;
+ shiftKey: boolean;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type CloseReason = 'close' | 'outside' | 'item' | 'resize';
@@ -25,17 +39,6 @@ export type MenuOpenEventDetails = {
menu: PopupMenu;
};
-export type MenuCloseEventDetails = {
- menu: PopupMenu;
- item: HTMLElement | null;
- action: string | null;
- cause: CloseReason;
- altKey: boolean;
- ctrlKey: boolean;
- metaKey: boolean;
- shiftKey: boolean;
-};
-
export type MenuOpenEvent = CustomEvent<MenuOpenEventDetails>;
-export type MenuCloseEvent = CustomEvent<MenuCloseEventDetails>;
+export type MenuCloseEvent = CustomEvent<EventArgument<'close'>>;
diff --git a/types/ext/popup.d.ts b/types/ext/popup.d.ts
index 65725f96..6f39f1e4 100644
--- a/types/ext/popup.d.ts
+++ b/types/ext/popup.d.ts
@@ -21,6 +21,7 @@ import type {PopupWindow} from '../../ext/js/app/popup-window';
import type {FrameOffsetForwarder} from '../../ext/js/comm/frame-offset-forwarder';
import type * as DocumentUtil from './document-util';
import type * as Settings from './settings';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
export type PopupAny = Popup | PopupWindow | PopupProxy;
@@ -90,20 +91,6 @@ export type ValidSize = {
valid: boolean;
};
-export type CustomOuterCssChangedEvent = {
- node: HTMLStyleElement | HTMLLinkElement | null;
- useWebExtensionApi: boolean;
- inShadow: boolean;
-};
-
-export type PopupAnyEventType = PopupEventType | PopupProxyEventType | PopupWindowEventType;
-
-export type PopupEventType = 'customOuterCssChanged' | 'framePointerOver' | 'framePointerOut' | 'offsetNotFound';
-
-export type PopupProxyEventType = 'offsetNotFound';
-
-export type PopupWindowEventType = never;
-
export type PopupConstructorDetails = {
/** The ID of the popup. */
id: string;
@@ -134,3 +121,16 @@ export type PopupProxyConstructorDetails = {
/** A `FrameOffsetForwarder` instance which is used to determine frame positioning. */
frameOffsetForwarder: FrameOffsetForwarder | null;
};
+
+export type Events = {
+ customOuterCssChanged: {
+ node: HTMLStyleElement | HTMLLinkElement | null;
+ useWebExtensionApi: boolean;
+ inShadow: boolean;
+ };
+ framePointerOver: Record<string, never>;
+ framePointerOut: Record<string, never>;
+ offsetNotFound: Record<string, never>;
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/profile-conditions-ui.d.ts b/types/ext/profile-conditions-ui.d.ts
index 7aa22e93..4e326781 100644
--- a/types/ext/profile-conditions-ui.d.ts
+++ b/types/ext/profile-conditions-ui.d.ts
@@ -16,8 +16,16 @@
*/
import type * as Settings from './settings';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type EventType = 'conditionGroupCountChanged';
+export type Events = {
+ conditionGroupCountChanged: {
+ count: number;
+ profileIndex: number;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type DescriptorType = Settings.ProfileConditionType;
@@ -49,11 +57,6 @@ export type Operator = {
normalize: NormalizeFunction | null;
};
-export type ConditionGroupCountChangedEvent = {
- count: number;
- profileIndex: number;
-};
-
export type DescriptorInfo = {
name: DescriptorType;
displayName: string;
diff --git a/types/ext/query-parser.d.ts b/types/ext/query-parser.d.ts
new file mode 100644
index 00000000..ea711d9e
--- /dev/null
+++ b/types/ext/query-parser.d.ts
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2023 Yomitan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+import type {TextScanner} from '../../ext/js/language/text-scanner';
+import type {DictionaryEntry} from './dictionary';
+import type {OptionsContext} from './settings';
+import type {InputInfo} from './text-scanner';
+import type {TextSource} from './text-source';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
+import type {HistoryStateSentence, PageType} from './display';
+
+export type Events = {
+ searched: {
+ textScanner: TextScanner;
+ type: PageType;
+ dictionaryEntries: DictionaryEntry[];
+ sentence: HistoryStateSentence;
+ inputInfo: InputInfo;
+ textSource: TextSource;
+ optionsContext: OptionsContext;
+ sentenceOffset: number | null;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/search-persistent-state-controller.d.ts b/types/ext/search-persistent-state-controller.d.ts
new file mode 100644
index 00000000..47b07119
--- /dev/null
+++ b/types/ext/search-persistent-state-controller.d.ts
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2023 Yomitan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+import type {SearchMode} from './display';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
+
+export type Events = {
+ modeChange: {
+ mode: SearchMode;
+ };
+};
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
diff --git a/types/ext/settings-controller.d.ts b/types/ext/settings-controller.d.ts
index 697de878..e0633c21 100644
--- a/types/ext/settings-controller.d.ts
+++ b/types/ext/settings-controller.d.ts
@@ -21,29 +21,30 @@ import type {ScanInputsSimpleController} from '../../ext/js/pages/settings/scan-
import type * as Core from './core';
import type * as Settings from './settings';
import type * as SettingsModifications from './settings-modifications';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
export type PageExitPrevention = {
end: () => void;
};
-export type EventType = 'optionsChanged' | 'optionsContextChanged' | 'permissionsChanged' | 'dictionarySettingsReordered' | 'scanInputsChanged';
-
-export type OptionsChangedEvent = {
- options: Settings.ProfileOptions;
- optionsContext: Settings.OptionsContext;
-};
-
-export type PermissionsChangedEvent = {
- permissions: chrome.permissions.Permissions;
+export type Events = {
+ optionsChanged: {
+ options: Settings.ProfileOptions;
+ optionsContext: Settings.OptionsContext;
+ };
+ optionsContextChanged: Record<string, never>;
+ permissionsChanged: {
+ permissions: chrome.permissions.Permissions;
+ };
+ dictionarySettingsReordered: {
+ source: DictionaryController;
+ };
+ scanInputsChanged: {
+ source: ScanInputsController | ScanInputsSimpleController;
+ };
};
-export type DictionarySettingsReorderedEvent = {
- source: DictionaryController;
-};
-
-export type ScanInputsChangedEvent = {
- source: ScanInputsController | ScanInputsSimpleController;
-};
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type SettingsRead<THasScope extends boolean> = THasScope extends true ? SettingsModifications.ScopedRead : SettingsModifications.Read;
diff --git a/types/ext/text-scanner.d.ts b/types/ext/text-scanner.d.ts
index d56d623a..e2779e4d 100644
--- a/types/ext/text-scanner.d.ts
+++ b/types/ext/text-scanner.d.ts
@@ -21,6 +21,7 @@ import type * as Display from './display';
import type * as Input from './input';
import type * as Settings from './settings';
import type * as TextSource from './text-source';
+import type {EventNames, EventArgument as BaseEventArgument} from './core';
export type SearchResultDetail = {
documentTitle: string;
@@ -118,7 +119,16 @@ export type InputInfoDetail = {
restoreSelection: boolean;
};
-export type EventType = 'searched' | 'clear';
+export type Events = {
+ searched: SearchedEventDetails;
+ clear: {
+ reason: ClearReason;
+ };
+};
+
+export type ClearReason = 'mousedown';
+
+export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
export type GetSearchContextCallback = GetSearchContextCallbackSync | GetSearchContextCallbackAsync;