From 2561cfb10d7fc4c9969ff1ff93fa032340815f05 Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Sun, 20 Oct 2024 13:12:40 +0200 Subject: [PATCH] Add plugin interface and package.json --- lib/main.d.ts | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 ++++++++++ 2 files changed, 107 insertions(+) create mode 100644 lib/main.d.ts create mode 100644 package.json diff --git a/lib/main.d.ts b/lib/main.d.ts new file mode 100644 index 0000000..032fbb8 --- /dev/null +++ b/lib/main.d.ts @@ -0,0 +1,90 @@ + +export interface IZenPlugin { + name: string; + version: string; + description: string; + + settings: IPluginSettings; + events: IPluginEvents; + context: IPluginContextMenu[]; +} + +export interface IPluginSetting { + name: string; + type: "string" | "number" | "boolean"; + default?: any; + description?: string; +} + +export interface IWorkspace { + uuid: string; + name: string; + icon?: string; + position: number; +} + +export interface ISandboxedTab { + getTitle(): string; + getIcon(): string; + getWorkspace(): IWorkspace; + getPluginData(): any; + setPluginData(data: any): void; + + close(): void; + select(): void; + unload(): void; + + readonly isSelected: boolean; +} + +export type IPluginEventKey = "onInit" | "onUnload" | "onTabChange" | "onTabClose" + | "onTabOpen" | "onWorkspaceChange" | "onWorkspaceClose" + | "onWorkspaceOpen" | "onPreferencesChange"; + +export type IPluginEventProps = + T extends "onInit" ? { } + : T extends "onUnload" ? { } + : T extends "onTabChange" ? { tabId: string } + : T extends "onTabClose" ? { tabId: string } + : T extends "onTabOpen" ? { tabId: string } + : T extends "onWorkspaceChange" ? { workspace: IWorkspace } + : T extends "onWorkspaceClose" ? { workspace: IWorkspace } + : T extends "onWorkspaceOpen" ? { workspace: IWorkspace } + : T extends "onPreferencesChange" ? { settings: IPluginSettings } + : never; + +export type IPluginEvent = (props: IPluginEventProps) => void; +export type IPluginEvents = { + [K in IPluginEventKey]?: IPluginEvent; +}; + +export type IPluginContextMenu = { + type: "tab" | "link" | "toolbar" | "text"; + label: string; + icon?: string; + action: () => void; + + get enabled(): boolean; + set enabled(value: boolean); +}; + +export type IPluginSettings = IPluginSetting[]; +export default IZenPlugin; + +// API + +export interface IZenAPI { + getTabs(): ISandboxedTab[]; + getWorkspaces(): IWorkspace[]; + + getSetting(name: string): any; + setSetting(name: string, value: any): void; + + set plugin(plugin: IZenPlugin); +} + +declare global { + interface Window { + plugins: IZenAPI; + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ec8461a --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "plugin", + "version": "1.0.0", + "description": "📦 A plugin library interface for typescript projects", + "types": "./lib/main.d.ts", + "repository": { + "type": "git", + "url": "git+https://github.com/zen-browser/plugin.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/zen-browser/plugin/issues" + }, + "homepage": "https://github.com/zen-browser/plugin#readme" +}