From 0e4ae922451af967c78616057ed26b85ba5d4b5c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 20 Feb 2024 10:12:27 -0500 Subject: Popup preview frame API map (#712) * Add API map type safety * Add API map types * Simplify names * Remove unused type --- types/ext/core.d.ts | 3 -- types/ext/popup-preview-frame.d.ts | 75 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 types/ext/popup-preview-frame.d.ts (limited to 'types') 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 @@ -31,9 +31,6 @@ export type RejectionReason = SafeAny; /** This type is used as an explicit way of permitting the `object` type. */ 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}; 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 . + */ + +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 = BaseApiParams; + +export type ApiNames = BaseApiNames; + +export type ApiMap = BaseApiMap; + +export type ApiHandler = BaseApiHandler; + +export type ApiReturn = BaseApiReturn; + +type ApiMessage = { + action: TName; + params: ApiParams; +}; + +export type ApiMessageAny = {[name in ApiNames]: ApiMessage}[ApiNames]; -- cgit v1.2.3