diff --git a/.gitignore b/.gitignore index 7becaebeb..1902cebe8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ app/node_modules app/stage/build app/build +app/src/types/dist app/kernel* ios pprof diff --git a/app/.eslintignore b/app/.eslintignore index 55ab40b0b..10a626b12 100644 --- a/app/.eslintignore +++ b/app/.eslintignore @@ -1,7 +1,6 @@ build -dist node_modules -public src/asset/pdf +src/types/dist stage appearance diff --git a/app/src/block/util.ts b/app/src/block/util.ts index ec34570a6..272c2422d 100644 --- a/app/src/block/util.ts +++ b/app/src/block/util.ts @@ -85,10 +85,10 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "par openFileById({ app: protyle.app, id: targetId, - action: [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""] + action: targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS] }); /// #else - openMobileFileById(protyle.app, targetId, [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]); + openMobileFileById(protyle.app, targetId, targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]); /// #endif }); }; diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.ts index 726ec33e9..356f57132 100644 --- a/app/src/boot/globalEvent/command/global.ts +++ b/app/src/boot/globalEvent/command/global.ts @@ -262,10 +262,10 @@ export const globalCommand = (command: string, app: App) => { if (command === "closeTab") { const activeTabElement = document.querySelector(".layout__tab--active"); if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) { - let type = ""; + let type: TDock; Array.from(activeTabElement.classList).find(item => { if (item.startsWith("sy__")) { - type = item.replace("sy__", ""); + type = item.replace("sy__", "") as TDock; return true; } }); diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 26a47bc5b..03e34e243 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -41,7 +41,7 @@ export const openFileById = async (options: { id: string, position?: string, mode?: TEditorMode, - action?: string[] + action?: TProtyleAction[] keepCursor?: boolean zoomIn?: boolean removeCurrentTab?: boolean diff --git a/app/src/layout/dock/Bookmark.ts b/app/src/layout/dock/Bookmark.ts index 0b0d0c5a7..c655882d7 100644 --- a/app/src/layout/dock/Bookmark.ts +++ b/app/src/layout/dock/Bookmark.ts @@ -85,7 +85,7 @@ export class Bookmark extends Model { } } const id = element.getAttribute("data-node-id"); - checkFold(id, (zoomIn, action: string[]) => { + checkFold(id, (zoomIn, action: TProtyleAction[]) => { openFileById({ app, id, @@ -111,7 +111,7 @@ export class Bookmark extends Model { }, altClick: (element: HTMLElement,) => { const id = element.getAttribute("data-node-id"); - checkFold(id, (zoomIn, action: string[]) => { + checkFold(id, (zoomIn, action: TProtyleAction[]) => { openFileById({ app, id, @@ -123,7 +123,7 @@ export class Bookmark extends Model { }, shiftClick: (element: HTMLElement) => { const id = element.getAttribute("data-node-id"); - checkFold(id, (zoomIn, action: string[]) => { + checkFold(id, (zoomIn, action: TProtyleAction[]) => { openFileById({ app, id, diff --git a/app/src/layout/dock/Graph.ts b/app/src/layout/dock/Graph.ts index 43faa20f0..99c3d7f2b 100644 --- a/app/src/layout/dock/Graph.ts +++ b/app/src/layout/dock/Graph.ts @@ -667,7 +667,7 @@ export class Graph extends Model { return; } if (window.siyuan.shiftIsPressed) { - checkFold(node.id, (zoomIn, action: string[]) => { + checkFold(node.id, (zoomIn, action: TProtyleAction[]) => { openFileById({ app: this.app, id: node.id, @@ -677,7 +677,7 @@ export class Graph extends Model { }); }); } else if (window.siyuan.altIsPressed) { - checkFold(node.id, (zoomIn, action: string[]) => { + checkFold(node.id, (zoomIn, action: TProtyleAction[]) => { openFileById({ app: this.app, id: node.id, @@ -695,7 +695,7 @@ export class Graph extends Model { nodeIds: [node.id], })); } else { - checkFold(node.id, (zoomIn, action: string[]) => { + checkFold(node.id, (zoomIn, action: TProtyleAction[]) => { openFileById({ app: this.app, id: node.id, diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts index eaf289b2e..aa8d5d930 100644 --- a/app/src/layout/dock/index.ts +++ b/app/src/layout/dock/index.ts @@ -29,7 +29,7 @@ export class Dock { private app: App; public resizeElement: HTMLElement; public pin = true; - public data: { [key: string]: Model | boolean }; + public data: { [key in TDock | string]?: Model | boolean }; private hideResizeTimeout: number; constructor(options: { @@ -112,13 +112,13 @@ export class Dock { this.resizeElement.classList.add("fn__none"); } else { activeElements.forEach(item => { - this.toggleModel(item.getAttribute("data-type"), true, false, false, false); + this.toggleModel(item.getAttribute("data-type") as TDock, true, false, false, false); }); } this.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.isEqualNode(this.element)) { - const type = target.getAttribute("data-type"); + const type = target.getAttribute("data-type") as TDock; if (type) { this.toggleModel(type, false, true); event.preventDefault(); @@ -359,7 +359,7 @@ export class Dock { documentSelf.onselect = null; this.setSize(); this.element.querySelectorAll(".dock__item--active").forEach(item => { - const customModel = this.data[item.getAttribute("data-type")]; + const customModel = this.data[item.getAttribute("data-type") as TDock]; if (customModel && customModel instanceof Custom && customModel.resize) { customModel.resize(); } @@ -491,7 +491,7 @@ export class Dock { this.layout.element.querySelector(".layout__tab--active")?.classList.remove("layout__tab--active"); } - public toggleModel(type: string, show = false, close = false, hide = false, isSaveLayout = true) { + public toggleModel(type: TDock | string, show = false, close = false, hide = false, isSaveLayout = true) { if (!type) { return; } @@ -757,7 +757,7 @@ export class Dock { public add(index: number, sourceElement: Element, previousType?: string) { sourceElement.setAttribute("data-height", ""); sourceElement.setAttribute("data-width", ""); - const type = sourceElement.getAttribute("data-type"); + const type = sourceElement.getAttribute("data-type") as TDock; const sourceDock = getDockByType(type); if (sourceDock.element.querySelectorAll(".dock__item").length === 2) { sourceDock.element.classList.add("fn__none"); @@ -794,7 +794,7 @@ export class Dock { saveLayout(); } - public remove(key: string) { + public remove(key: TDock|string) { this.toggleModel(key, false, true, true); this.element.querySelector(`[data-type="${key}"]`).remove(); const custom = this.data[key] as Custom; @@ -809,12 +809,12 @@ export class Dock { activesElement.forEach((item) => { if (this.position === "Left" || this.position === "Right") { if (item.getAttribute("data-index") === "1" && activesElement.length > 1) { - item.setAttribute("data-height", (this.data[item.getAttribute("data-type")] as Model).parent.parent.element.clientHeight.toString()); + item.setAttribute("data-height", (this.data[item.getAttribute("data-type") as TDock] as Model).parent.parent.element.clientHeight.toString()); } item.setAttribute("data-width", this.layout.element.clientWidth.toString()); } else { if (item.getAttribute("data-index") === "1" && activesElement.length > 1) { - item.setAttribute("data-width", (this.data[item.getAttribute("data-type")] as Model).parent.parent.element.clientWidth.toString()); + item.setAttribute("data-width", (this.data[item.getAttribute("data-type") as TDock] as Model).parent.parent.element.clientWidth.toString()); } item.setAttribute("data-height", this.layout.element.clientHeight.toString()); } diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.ts index 20e9a0661..dce287d71 100644 --- a/app/src/layout/tabUtil.ts +++ b/app/src/layout/tabUtil.ts @@ -66,7 +66,7 @@ export const switchTabByIndex = (index: number) => { indexElement = activeDockIcoElement.parentElement.firstElementChild; } } - const type = indexElement?.getAttribute("data-type"); + const type = indexElement?.getAttribute("data-type") as TDock; if (type) { getDockByType(type)?.toggleModel(type, true, false); } @@ -142,7 +142,7 @@ export const resizeTabs = (isSaveLayout = true) => { }, 200); }; -export const getDockByType = (type: string) => { +export const getDockByType = (type: TDock | string) => { if (!window.siyuan.layout.leftDock) { return undefined; } @@ -253,7 +253,7 @@ export const copyTab = (app: App, tab: Tab) => { callback(newTab: Tab) { let model: Model; if (tab.model instanceof Editor) { - const newAction: string[] = []; + const newAction: TProtyleAction[] = []; // https://github.com/siyuan-note/siyuan/issues/12132 tab.model.editor.protyle.block.action.forEach(item => { if (item !== Constants.CB_GET_APPEND && item !== Constants.CB_GET_BEFORE && item !== Constants.CB_GET_HTML) { diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts index 4fd55ab9f..be984db7e 100644 --- a/app/src/plugin/API.ts +++ b/app/src/plugin/API.ts @@ -18,6 +18,7 @@ import {Protyle} from "../protyle"; import {openMobileFileById} from "../mobile/editor"; import {lockScreen, exitSiYuan} from "../dialog/processSystem"; import {Model} from "../layout/Model"; +import {getDockByType} from "../layout/tabUtil"; let openTab; let openWindow; @@ -52,7 +53,7 @@ openTab = (options: { app: App, doc?: { id: string, // 块 id - action?: string [] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮 + action?: TProtyleAction [] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮 zoomIn?: boolean // 是否缩放 }, pdf?: { @@ -166,23 +167,24 @@ openTab = (options: { /// #endif export const API = { - confirm: confirmDialog, - showMessage, adaptHotkey: updateHotkeyTip, + confirm: confirmDialog, + Constants, + showMessage, fetchPost, fetchSyncPost, fetchGet, getFrontend, getBackend, - lockScreen, - exitSiYuan, - openMobileFileById, + getDockByType, openTab, openWindow, + openMobileFileById, + lockScreen, + exitSiYuan, Protyle, Plugin, Dialog, Menu, Setting, - Constants, }; diff --git a/app/src/plugin/EventBus.ts b/app/src/plugin/EventBus.ts index 591d40b4a..40ea3f9f8 100644 --- a/app/src/plugin/EventBus.ts +++ b/app/src/plugin/EventBus.ts @@ -8,9 +8,6 @@ export class EventBus { } on(type: TEventBus, listener: (event: CustomEvent) => void) { - if (type ==="loaded-protyle") { - console.warn("0.8.8 将移除 loaded-protyle, 请使用 loaded-protyle-static 进行替代"); - } this.eventTarget.addEventListener(type, listener); } diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts index e5e10f5b3..8504816b2 100644 --- a/app/src/protyle/scroll/saveScroll.ts +++ b/app/src/protyle/scroll/saveScroll.ts @@ -56,7 +56,7 @@ export const getDocByScroll = (options: { focus?: boolean, updateReadonly?: boolean }) => { - let actions: string[] = []; + let actions: TProtyleAction[] = []; if (options.mergedOptions) { actions = options.mergedOptions.action; } else { diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index c882af144..212af95a9 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -24,7 +24,7 @@ import {getContenteditableElement} from "../wysiwyg/getBlock"; export const onGet = (options: { data: IWebSocketData, protyle: IProtyle, - action?: string[], + action?: TProtyleAction[], scrollAttr?: IScrollAttr updateReadonly?: boolean afterCB?: () => void @@ -290,7 +290,6 @@ const setHTML = (options: { } protyle.app.plugins.forEach(item => { - item.eventBus.emit("loaded-protyle", protyle); // 准备废弃 item.eventBus.emit("loaded-protyle-static", {protyle}); }); }; diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts index 9bebba93f..1f2676dad 100644 --- a/app/src/types/config.d.ts +++ b/app/src/types/config.d.ts @@ -1646,7 +1646,7 @@ declare namespace Config { /** * Tab type */ - type: string; + type: TDock | string; } /** diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 7bd5e7370..5c1fd76be 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -1,6 +1,7 @@ type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight" type TDockPosition = "Left" | "Right" | "Bottom" type TWS = "main" | "filetree" | "protyle" +type TDock = "file" | "outline" | "inbox" | "bookmark" | "tag" | "graph" | "globalGraph" | "backlink" type TOperation = "insert" | "update" @@ -63,7 +64,7 @@ type TEventBus = "ws-main" | "sync-start" | "sync-end" | "sync-fail" | "closed-notebook" | "paste" | "input-search" | - "loaded-protyle" | "loaded-protyle-dynamic" | "loaded-protyle-static" | + "loaded-protyle-dynamic" | "loaded-protyle-static" | "switch-protyle" | "destroy-protyle" | "lock-screen" | @@ -316,7 +317,7 @@ interface IBackStack { notebookId: string }, scrollTop?: number, - callback?: string[], + callback?: TProtyleAction[], position?: { start: number, end: number @@ -543,7 +544,7 @@ interface IOpenFileOptions { position?: string, // file 或者 asset,打开位置 page?: number | string, // asset mode?: TEditorMode // file - action?: string[] + action?: TProtyleAction[] keepCursor?: boolean // file,是否跳转到新 tab 上 zoomIn?: boolean // 是否缩放 removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签 diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index c6dc2ff62..0ba62b5af 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -498,7 +498,7 @@ interface IProtyle { showAll?: boolean mode?: number blockCount?: number - action?: string[] + action?: TProtyleAction[] }, disabled: boolean, selectElement?: HTMLElement, diff --git a/app/src/util/noRelyPCFunction.ts b/app/src/util/noRelyPCFunction.ts index b82a18f28..4d9e29bb4 100644 --- a/app/src/util/noRelyPCFunction.ts +++ b/app/src/util/noRelyPCFunction.ts @@ -35,7 +35,7 @@ export const getWorkspaceName = () => { return pathPosix().basename(window.siyuan.config.system.workspaceDir.replace(/\\/g, "/")); }; -export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[], isRoot: boolean) => void) => { +export const checkFold = (id: string, cb: (zoomIn: boolean, action: TProtyleAction[], isRoot: boolean) => void) => { if (!id) { return; } diff --git a/app/tsconfig.json b/app/tsconfig.json index 9480e8953..47999d51a 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "outDir": "./dist/", + "outDir": "./src/types/dist", "noImplicitAny": true, "module": "commonjs", "target": "es6",