diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-02-20 10:12:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 15:12:27 +0000 |
commit | 0e4ae922451af967c78616057ed26b85ba5d4b5c (patch) | |
tree | 8f1aed3d93e9c6e99e6c55e846b29d8dc154e113 /types | |
parent | 088c6c17ac7b6076604fd3bc40287d4afda0d940 (diff) |
Popup preview frame API map (#712)
* Add API map type safety
* Add API map types
* Simplify names
* Remove unused type
Diffstat (limited to 'types')
-rw-r--r-- | types/ext/core.d.ts | 3 | ||||
-rw-r--r-- | types/ext/popup-preview-frame.d.ts | 75 |
2 files changed, 75 insertions, 3 deletions
diff --git a/types/ext/core.d.ts b/types/ext/core.d.ts index a18a7bf7..8e8184b3 100644 --- a/types/ext/core.d.ts +++ b/types/ext/core.d.ts @@ -32,9 +32,6 @@ export type RejectionReason = SafeAny; export type SerializableObject = {[key: string]: unknown}; /** This type is used as an explicit way of permitting the `object` type. */ -export type SerializableObjectAny = {[key: string]: SafeAny}; - -/** This type is used as an explicit way of permitting the `object` type. */ export type UnknownObject = {[key: string | symbol]: unknown}; export type TokenString = string; diff --git a/types/ext/popup-preview-frame.d.ts b/types/ext/popup-preview-frame.d.ts new file mode 100644 index 00000000..4b4f3009 --- /dev/null +++ b/types/ext/popup-preview-frame.d.ts @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2024 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 { + ApiMap as BaseApiMap, + ApiHandler as BaseApiHandler, + ApiParams as BaseApiParams, + ApiNames as BaseApiNames, + ApiReturn as BaseApiReturn, +} from './api-map'; +import type {OptionsContext} from './settings'; + +export type ApiSurface = { + setText: { + params: { + text: string; + }; + return: void; + }; + setCustomCss: { + params: { + css: string; + }; + return: void; + }; + setCustomOuterCss: { + params: { + css: string; + }; + return: void; + }; + updateOptionsContext: { + params: { + optionsContext: OptionsContext; + }; + return: void; + }; + setLanguageExampleText: { + params: { + language: string; + }; + return: void; + }; +}; + +export type ApiParams<TName extends ApiNames> = BaseApiParams<ApiSurface[TName]>; + +export type ApiNames = BaseApiNames<ApiSurface>; + +export type ApiMap = BaseApiMap<ApiSurface>; + +export type ApiHandler<TName extends ApiNames> = BaseApiHandler<ApiSurface[TName]>; + +export type ApiReturn<TName extends ApiNames> = BaseApiReturn<ApiSurface[TName]>; + +type ApiMessage<TName extends ApiNames> = { + action: TName; + params: ApiParams<TName>; +}; + +export type ApiMessageAny = {[name in ApiNames]: ApiMessage<name>}[ApiNames]; |