import type { IClipboardData, IGetDocInfo, IGetTreeStat, IKernelPlugin, IKernelPluginState, IMenu, IMenuBaseDetail, IMenuItem, IModels, IObject, IPosition, IProtyle, IProtyleOptions, IRefDefs, ISiyuan, IWebSocketData, TEditorMode, TProtyleAction, } from "./types"; import {App, Config, Custom, Files, Lute, MobileCustom, Model, Protyle, subMenu, Tab, Toolbar,} from "./types"; export * from "./types"; declare global { export interface Window extends Global { } } export type TDock = "file" | "outline" | "inbox" | "bookmark" | "tag" | "graph" | "globalGraph" | "backlink" | "agentChat" export type TTab = "Outline" | "Graph" | "Backlink" | "Asset" | "Editor" | "Search" | "siyuan-card" export type TCardType = "doc" | "notebook" | "all" export type TEventBus = keyof IEventBusMap export type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight" export type TOperation = "insert" | "restoreCreatedDoc" | "removeCreatedDoc" | "update" | "delete" | "move" | "foldHeading" | "unfoldHeading" | "setAttrs" | "updateAttrs" | "append" | "insertAttrViewBlock" | "removeAttrViewBlock" | "addAttrViewCol" | "removeAttrViewCol" | "addFlashcards" | "removeFlashcards" | "updateAttrViewCell" | "updateAttrViewCol" | "updateAttrViewColTemplate" | "sortAttrViewRow" | "sortAttrViewCol" | "sortAttrViewKey" | "setAttrViewColPin" | "setAttrViewColHidden" | "setAttrViewColWrap" | "setAttrViewColWidth" | "setAttrViewColAlign" | "updateAttrViewColOptions" | "removeAttrViewColOption" | "updateAttrViewColOption" | "setAttrViewName" | "setAttrViewNewItemTemplates" | "doUpdateUpdated" | "duplicateAttrViewKey" | "setAttrViewColIcon" | "setAttrViewFilters" | "setAttrViewSorts" | "setAttrViewColCalc" | "updateAttrViewColNumberFormat" | "replaceAttrViewBlock" | "addAttrViewView" | "setAttrViewViewName" | "removeAttrViewView" | "setAttrViewViewIcon" | "duplicateAttrViewView" | "sortAttrViewView" | "setAttrViewPageSize" | "updateAttrViewColRelation" | "moveOutlineHeading" | "updateAttrViewColRollup" | "hideAttrViewName" | "setAttrViewCardSize" | "setAttrViewCardAspectRatio" | "setAttrViewCoverFrom" | "setAttrViewCoverFromAssetKeyID" | "setAttrViewFitImage" | "setAttrViewShowIcon" | "setAttrViewWrapField" | "setAttrViewColDateFillCreated" | "setAttrViewColDateFillSpecificTime" | "setAttrViewViewDesc" | "setAttrViewColDesc" | "setAttrViewBlockView" | "setAttrViewGroup" | "removeAttrViewGroup" | "hideAttrViewAllGroups" | "syncAttrViewTableColWidth" | "hideAttrViewGroup" | "sortAttrViewGroup" | "foldAttrViewGroup" | "setAttrViewDisplayFieldName" | "setAttrViewFillColBackgroundColor" | "setAttrViewUpdatedIncludeTime" | "setAttrViewCreatedIncludeTime" export interface Global { Lute: typeof Lute; siyuan: ISiyuan; } export interface IEventBusMap { "before-hide-tooltip": { tooltipElement: HTMLElement, }; "before-show-tooltip": { message: string, target: Element, tooltipElement: HTMLElement, }; "common-menu-closed": { menu: HTMLElement, name: string | null, from: string | null, }; "common-menu-open": { menu: HTMLElement, name: string | null, from: string | null, mode: "popup" | "fullscreen", }; "click-flashcard-action": { card: ICard, type: string, // 1 - 重来;2 - 困难;3 - 良好;4 - 简单;-1 - 显示答案;-2 - 上一个 ;-3 - 跳过 }; "click-blockicon": { menu: subMenu, protyle: IProtyle, blockElements: HTMLElement[], }; "click-editorcontent": { protyle: IProtyle, event: MouseEvent, }; "click-editortitleicon": { menu: subMenu, protyle: IProtyle, data: IGetDocInfo, }; "click-pdf": { event: MouseEvent, }; "closed-notebook": IWebSocketData; "destroy-protyle": { protyle: IProtyle, }; "input-search": { protyle: Protyle, config: Config.IUILayoutTabSearchConfig, searchElement: HTMLInputElement, }; "loaded-protyle-dynamic": { protyle: IProtyle, position: "afterend" | "beforebegin", }; "loaded-protyle-static": { protyle: IProtyle, }; "lock-screen": void; "switch-protyle": { protyle: IProtyle, }; "switch-protyle-mode": { protyle: IProtyle, }; "open-menu-av": IMenuBaseDetail & { selectRowElements: HTMLElement[] }; "open-menu-blockref": IMenuBaseDetail; "open-menu-breadcrumbmore": { menu: subMenu, protyle: IProtyle, data: IGetTreeStat, }; "open-menu-content": IMenuBaseDetail & { range: Range }; "open-menu-fileannotationref": IMenuBaseDetail; "open-menu-image": IMenuBaseDetail; "open-menu-link": IMenuBaseDetail; "open-menu-tag": IMenuBaseDetail; "open-menu-doctree": { menu: subMenu, elements: NodeListOf, type: "doc" | "docs" | "notebook" | "notebooks" | "items", items: { id: string, path: string, notebookId: string }[], }; "open-menu-inbox": { menu: subMenu, element: HTMLElement, ids: string[], }; "open-noneditableblock": { protyle: IProtyle, toolbar: Toolbar, blockElement: HTMLElement, renderElement: HTMLElement, }; "open-siyuan-url-block": { url: string, id: string, focus: boolean, exist: boolean, }; "open-siyuan-url-plugin": { url: string, }; "opened-notebook": IWebSocketData; "paste": { protyle: IProtyle, resolve: (value: IClipboardData | PromiseLike | undefined) => void, textHTML: string, textPlain: string, siyuanHTML: string, localFiles: { path: string, size: number }[] files: FileList | DataTransferItemList }; "ws-main": IWebSocketData; "sync-start": IWebSocketData; "sync-end": IWebSocketData; "sync-fail": IWebSocketData; "mobile-keyboard-show": void; "mobile-keyboard-hide": void; "code-language-update": { languages: string[], type: "init" | "match", listElement: HTMLElement, value: string }; "code-language-change": { language: string, languageElements: HTMLElement[], protyle: IProtyle }; "kernel-plugin-state-change": IKernelPluginState; } export interface IPluginDockTab { position: TPluginDockPosition, size: Config.IUILayoutDockPanelSize, icon: string, hotkey?: string, title: string, index?: number show?: boolean } export interface ICommand { langKey: string, // 用于区分不同快捷键的 key, 同时作为 i18n 的字段名 langText?: string, // 显示的文本, 指定后不再使用 langKey 对应的 i18n 文本 /** * 目前需使用 MacOS 符号标识,顺序按照 ⌥⇧⌘,入 ⌥⇧⌘A * "Ctrl": "⌘", * "Shift": "⇧", * "Alt": "⌥", * "Tab": "⇥", * "Backspace": "⌫", * "Delete": "⌦", * "Enter": "↩", */ hotkey?: string, customHotkey?: string, callback?: () => void // 其余回调存在时将不会触发 globalCallback?: () => void // 焦点不在应用内时执行的回调 fileTreeCallback?: (file: Files) => void // 焦点在文档树上时执行的回调 editorCallback?: (protyle: IProtyle) => void // 焦点在编辑器上时执行的回调 dockCallback?: (element: HTMLElement) => void // 焦点在 dock 上时执行的回调 } export interface IAgentCapabilityEffects { localRead?: boolean; localWrite?: boolean; dataEgress?: boolean; externalCost?: boolean; } export interface ICard { deckID: string; cardID: string; blockID: string; nextDues: Record; lapses: number; // 遗忘次数 lastReview: number; // 最后复习时间 reps: number; // 复习次数 state: number; // 卡片状态 0:新卡 } export interface ICardData { cards: ICard[], unreviewedCount: number unreviewedNewCardCount: number unreviewedOldCardCount: number } export function adaptHotkey(hotkey: string): string export function confirm(title: string, text: string, confirmCallback?: (dialog: Dialog) => void, cancelCallback?: (dialog: Dialog) => void): void; export function fetchPost( url: string, data?: any, cb?: (response: IWebSocketData) => void, headers?: IObject, failCallback?: (response: IWebSocketData) => void ): void; export function fetchSyncPost(url: string, data?: any): Promise; export function fetchGet(url: string, callback: (response: IWebSocketData) => void): void; export function openWindow(options: { position?: { x: number, y: number, }, height?: number, width?: number, tab?: Tab, alwaysOnTop?: boolean, doc?: { id: string; // 块 id }, }): void; /** * 不支持移动端 * @param {boolean} [wndActive=true] - 当前活动窗口是否为激活状态 */ export function getActiveTab(wndActive?: boolean): Tab; /** * @param {boolean} [wndActive=true] - 当前活动窗口是否为激活状态 */ export function getActiveEditor(wndActive?: boolean): Protyle; export function expandDocTree(options: { id: string, isSetCurrent?: boolean }): void; export function openMobileFileById(app: App, id: string, action?: TProtyleAction[]): void; /** * @param {string} [options.doc.mode="wysiwyg"] - 只在首次打开时生效,切换可调用 switchMode 方法 */ export function openTab(options: { app: App, doc?: { id: string, // 块 id action?: TProtyleAction[], zoomIn?: boolean, // 是否缩放 mode?: TEditorMode }; pdf?: { path: string, page?: number, // pdf 页码 id?: string, // File Annotation id }; asset?: { path: string, }; search?: Config.IUILayoutTabSearchConfig; card?: { type: TCardType, id?: string, // cardType 为 all 时不传,否则传文档或笔记本 id title?: string, // cardType 为 all 时不传,否则传文档或笔记本名称 }; custom?: { id: string, // 插件名称+页签类型:plugin.name + tab.type icon: string, title: string, data?: any, }; position?: "right" | "bottom"; keepCursor?: boolean; // 是否跳转到新 tab 上 removeCurrentTab?: boolean; // 在当前页签打开时需移除原有页签 openNewTab?: boolean // 使用新页签打开 afterOpen?: () => void; // 打开后回调 }): Promise export function getFrontend(): "desktop" | "desktop-window" | "mobile" | "browser-desktop" | "browser-mobile"; export function getBackend(): "windows" | "linux" | "darwin" | "docker" | "android" | "ios" | "harmony"; export function lockScreen(app: App): void export function exitSiYuan(): void export function getAllEditor(): Protyle[] export function saveExportFile(uri: string, msgId?: string): Promise; export function getAllTabs(type?: TTab | string): Tab[] export function getAllModels(): IModels export function openSetting(app: App): Dialog | undefined; export function openEmoji(options: { position: IPosition, selectedCB?: (emoji: string) => void, dynamicIconURL?: string hideDynamicIcon?: boolean hideCustomIcon?: boolean }): void ; export function getModelByDockType(type: TDock | string): Model | any; /** * @param {IObject} [options.data] - 块属性值 * @param {HTMLElement} [options.nodeElement] - 块元素 * @param {"bookmark" | "name" | "alias" | "memo" | "av" | "custom"} [options.focusName="bookmark"] - av 为数据库页签,custom 为自定义页签,其余为内置输入框 * @param {IProtyle} [options.protyle] - 有数据库时需要传入 protyle */ export function openAttributePanel(options: { data?: IObject nodeElement?: HTMLElement, focusName: "bookmark" | "name" | "alias" | "memo" | "av" | "custom", protyle?: IProtyle, }): void; /** * 保存布局 * @param {function} [cb] - 保存后的回调函数 */ export function saveLayout(cb: () => void): void; /** * 全局命令 * @param {string} command - 命令名称 https://github.com/siyuan-note/siyuan/blob/master/app/src/boot/globalEvent/command/global.ts#L71 * @param {App} app */ export function globalCommand(command: string, app: App): void; /** * @param {number} [timeout=6000] - ms. 0: manual close;-1: always show; * @param {string} [type=info] */ export function showMessage(text: string, timeout?: number, type?: "info" | "error", id?: string): void; export function hideMessage(id?: string): void; export abstract class Plugin { eventBus: EventBus; i18n: Record; kernel: IKernelPlugin; data: any; displayName: string; readonly name: string; app: App; commands: ICommand[]; setting: Setting; customBlockRenders: { [key: string]: { icon: string, action: Array<"edit" | "more">, genCursor: boolean, render: (options: { app: App, element: Element }) => void } }; topBarIcons: Element[]; statusBarIcons: Element[]; agentActions: string[]; models: { [key: string]: (options: { tab: Tab, data: any }) => Custom }; docks: { [key: string]: { config: IPluginDockTab, model: (options: { tab: Tab }) => Custom, mobileModel: (element: Element) => MobileCustom } }; protyleSlash: { filter: string[], html: string, id: string, callback(protyle: Protyle, nodeElement: HTMLElement): void, }[]; protyleOptions: IProtyleOptions; constructor(options: { app: App, name: string, displayName: string, i18n: Record, }); onload(): Promise | void; onDataChanged(): void onunload(): void; uninstall(): void; onLayoutReady(): void; /** * Must be executed before the synchronous function. * @param {string} [options.position=right] * @param {string} options.icon - Support svg id or svg tag. */ addTopBar(options: { icon: string, title: string, callback: (event: MouseEvent) => void position?: "right" | "left" }): HTMLElement; /** * Must be executed before the synchronous function. * @param {string} [options.position=right] */ addStatusBar(options: { element: HTMLElement, position?: "right" | "left", }): HTMLElement; openSetting(): void; loadData(storageName: string): Promise; saveData(storageName: string, content: any): Promise; removeData(storageName: string): Promise; addIcons(svg: string): void; getOpenedTab(): { [key: string]: Custom[] }; /** * Must be executed before the synchronous function. */ addTab(options: { type: string, destroy?: () => void, beforeDestroy?: () => void, resize?: () => void, update?: () => void, init: () => void, }): (options: { tab: Tab, data: any }) => Custom; /** * Add Custom to Dock. * Must be executed before the synchronous function. */ addDock(options: { config: IPluginDockTab, data: any, type: string, destroy?: (this: Custom | MobileCustom) => void, resize?: (this: Custom | MobileCustom) => void, update?: (this: Custom | MobileCustom) => void, init: (this: Custom | MobileCustom) => void, }): { config: IPluginDockTab, model: (options: { tab: Tab }) => Custom, mobileModel: (element: Element) => MobileCustom }; addCommand(options: ICommand): void; /** * 按名称取密钥值(来自「设置 → 密钥和变量」的密钥库)。找不到时返回空字符串。 * 密钥在内核侧加密存储,此处读到的是运行时明文;仅在本地管理员身份下可用。 */ getSecret(name: string): string; /** * 按名称取变量值(来自「设置 → 密钥和变量」的变量库)。找不到时返回空字符串。 * 变量以明文存储,用于非敏感配置。 */ getVariable(name: string): string; addAgentCapability(options: { name: string, title?: string, description: string, inputSchema: Record, outputSchema?: Record, effects?: IAgentCapabilityEffects, actionEffects?: Record, handler: (args: Record, app: App) => Promise<{ result?: string; structuredContent?: unknown; error?: string; }>, }): string; addFloatLayer(options: { refDefs: IRefDefs[], x?: number, y?: number, targetElement?: HTMLElement, originalRefBlockIDs?: IObject, isBacklink: boolean, }): void; updateCards(options: ICardData): Promise; updateProtyleToolbar(toolbar: Array): Array; } export class Setting { constructor(options: { height?: string, width?: string, destroyCallback?: () => void, confirmCallback?: () => void, }); addItem(options: { title: string, direction?: "column" | "row" description?: string, actionElement?: HTMLElement, createActionElement?(): HTMLElement, }): void; open(name: string): void; } export class EventBus { on< K extends TEventBus, D = IEventBusMap[K], >(type: K, listener: (event: CustomEvent) => any): void; once< K extends TEventBus, D = IEventBusMap[K], >(type: K, listener: (event: CustomEvent) => any): void; off< K extends TEventBus, D = IEventBusMap[K], >(type: K, listener: (event: CustomEvent) => any): void; emit< K extends TEventBus, D = IEventBusMap[K], >(type: K, detail?: D): boolean; } export class Dialog { element: HTMLElement; editors: { [key: string]: Protyle }; data: any; constructor(options: { positionId?: string, title?: string, transparent?: boolean, content: string, width?: string, height?: string, destroyCallback?: (options?: IObject) => void, disableClose?: boolean, hideCloseIcon?: boolean, disableAnimation?: boolean, resizeCallback?: (type: string) => void }); destroy(options?: IObject): void; bindInput(inputElement: HTMLInputElement | HTMLTextAreaElement, enterEvent?: () => void): void; } export class Menu { private menu; isOpen: boolean; element: HTMLElement; constructor(id?: string, closeCB?: () => void); showSubMenu(subMenuElement: HTMLElement): void; addItem(option: IMenu): HTMLElement; addSeparator(options?: { index?: number, id?: string, ignore?: boolean }): HTMLElement; open(options: IPosition): void; /** * @param {string} [position=all] */ fullscreen(position?: "bottom" | "all"): void; close(): void; }