utools-utils
Version:
Common utilities for uTools
185 lines (181 loc) • 4.2 kB
TypeScript
type Action = StringAction | ImageAction | FilesAction | WindowAction;
interface AbstractAction {
code: string;
}
interface StringAction extends AbstractAction {
type: 'text' | 'regex' | 'over';
/**
* 主输入框文本
*/
payload: string;
}
interface ImageAction extends AbstractAction {
type: 'img';
/**
* Base64 编码的图片
*/
payload: string;
}
interface FilesAction extends AbstractAction {
type: 'files';
/**
* 文件列表
*/
payload: FilesPayload;
}
type FilesPayload = Array<FilePayload>;
interface FilePayload {
isFile: boolean;
isDirectory: boolean;
name: string;
path: string;
}
interface WindowAction extends AbstractAction {
type: 'window';
/**
* 窗口信息
*/
payload: WindowPayload;
}
interface WindowPayload {
id: number;
class?: string;
title: string;
x: number;
y: number;
width: number;
height: number;
appPath: string;
pid: number;
app: string;
}
interface TemplateExports {
[code: string]: TemplateExport;
}
type TemplateExport = NoneTemplateExport | ListTemplateExport | DocTemplateExport;
/**
* 无 UI 模式模板
*/
interface NoneTemplateExport {
mode: 'none';
args: NoneTemplateArgs;
}
interface NoneTemplateArgs {
/**
* 进入插件时调用
*/
enter(action: Action): void;
}
/**
* 列表模式模板
*/
interface ListTemplateExport {
mode: 'list';
args: ListTemplateArgs;
}
interface ListItem {
title: string;
description?: string;
/**
* 图标路径,默认为相对路径。如果为绝对路径,需要添加前缀 `file://`。除此之外,还可以填入 Base64 图片。
*/
icon?: string;
[prop: string]: any;
}
/**
* 渲染列表数据函数
*/
type ListRenderFunction = (list: Array<ListItem>) => void;
interface ListTemplateArgs {
/**
* 输入框占位符
* @default "搜索"
*/
placeholder?: string;
/**
* 进入插件时调用
*/
enter(action: Action, render: ListRenderFunction): void;
/**
* 输入框改变时调用
*/
search(action: Action, searchWord: string, render: ListRenderFunction): void;
/**
* 使用回车键选择某项时调用
*/
select(action: Action, item: ListItem, render: ListRenderFunction): void;
}
/**
* 文档模式模板
*/
interface DocTemplateExport {
mode: 'doc';
args: DocTemplateArgs;
}
interface DocIndex {
/**
* 标题
*/
t: string;
/**
* 描述
*/
d: string;
/**
* 页面
*/
p: string;
}
interface DocTemplateArgs {
/**
* 输入框占位符
* @default "搜索"
*/
placeholder?: string;
/**
* 文档索引集合
*/
indexes: Array<DocIndex>;
}
interface AbstractCmd {
label: string;
}
interface RegexMatchCmd extends AbstractCmd {
type: 'regex';
match: string;
minLength?: number;
maxLength?: number;
}
interface OverMatchCmd extends AbstractCmd {
type: 'over';
exclude?: string;
minLength?: number;
maxLength?: number;
}
interface ImageMatchCmd extends AbstractCmd {
type: 'img';
}
interface FilesMatchCmd extends AbstractCmd {
type: 'files';
fileType?: 'file' | 'directory';
match?: string;
minLength?: number;
maxLength?: number;
}
interface WindowMatchCmd extends AbstractCmd {
type: 'window';
match: {
app?: string[];
title?: string;
class?: string[];
};
}
type Platform = 'darwin' | 'win32' | 'linux';
interface Feature {
code: string;
explain: string;
platform?: Array<Platform>;
icon?: string;
cmds: Array<string | RegexMatchCmd | OverMatchCmd | ImageMatchCmd | FilesMatchCmd | WindowMatchCmd>;
}
export { Action, DocIndex, DocTemplateArgs, DocTemplateExport, Feature, FilePayload, FilesAction, FilesMatchCmd, FilesPayload, ImageAction, ImageMatchCmd, ListItem, ListRenderFunction, ListTemplateArgs, ListTemplateExport, NoneTemplateArgs, NoneTemplateExport, OverMatchCmd, Platform, RegexMatchCmd, StringAction, TemplateExport, TemplateExports, WindowAction, WindowMatchCmd, WindowPayload };