From d4f9ffa6872a019a51ae282d8abeca6ef7a178e0 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 17 Jun 2023 14:17:44 +0800 Subject: [PATCH] update to v0.1.5 --- README.md | 2 +- README_zh_CN.md | 2 +- package.json | 4 ++-- plugin.json | 2 +- src/index.ts | 26 +++++++++++++++++++------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c6aeaa4..71d9860 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [中文版](./README_zh_CN.md) -> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.4](https://github.com/siyuan-note/plugin-sample/tree/v0.1.4). +> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.5](https://github.com/siyuan-note/plugin-sample/tree/v0.1.5). diff --git a/README_zh_CN.md b/README_zh_CN.md index 9b704e1..260eaf0 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -4,7 +4,7 @@ [English](./README.md) -> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.4](https://github.com/siyuan-note/plugin-sample/tree/v0.1.4). +> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.5](https://github.com/siyuan-note/plugin-sample/tree/v0.1.5) 1. 使用 vite 打包 2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发 diff --git a/package.json b/package.json index faa7403..27331d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-sample-vite-svelte", - "version": "0.1.4", + "version": "0.1.5", "type": "module", "description": "", "repository": "", @@ -22,7 +22,7 @@ "minimist": "^1.2.8", "rollup-plugin-livereload": "^2.0.5", "sass": "^1.62.1", - "siyuan": "0.7.3", + "siyuan": "0.7.4", "svelte": "^3.57.0", "ts-node": "^10.9.1", "typescript": "^5.0.4", diff --git a/plugin.json b/plugin.json index cc9fcb6..50fdf74 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "plugin-sample-vite-svelte", "author": "frostime", "url": "https://github.com/siyuan-note/plugin-sample-vite-svelte", - "version": "0.1.4", + "version": "0.1.5", "minAppVersion": "2.9.0", "backends": ["all"], "frontends": ["all"], diff --git a/src/index.ts b/src/index.ts index 057a3b7..51c40af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,12 +45,19 @@ export default class PluginSample extends Plugin { title: this.i18n.addTopBarIcon, position: "right", callback: () => { - let rect = topBarElement.getBoundingClientRect(); - // 如果被隐藏,则使用更多按钮 - if (rect.width === 0) { - rect = document.querySelector("#barPlugins").getBoundingClientRect(); + if (this.isMobile) { + this.addMenu(); + } else { + let rect = topBarElement.getBoundingClientRect(); + // 如果被隐藏,则使用更多按钮 + if (rect.width === 0) { + rect = document.querySelector("#barMore").getBoundingClientRect(); + } + if (rect.width === 0) { + rect = document.querySelector("#barPlugins").getBoundingClientRect(); + } + this.addMenu(rect); } - this.addMenu(rect); } }); @@ -86,6 +93,9 @@ export default class PluginSample extends Plugin { this.element.appendChild(tabDiv); console.log(this.element); }, + beforeDestroy() { + console.log("before destroy tab:", TAB_TYPE); + }, destroy() { console.log("destroy tab:", TAB_TYPE); } @@ -224,7 +234,7 @@ export default class PluginSample extends Plugin { }); } - private addMenu(rect: DOMRect) { + private addMenu(rect?: DOMRect) { const menu = new Menu("topBarSample", () => { console.log(this.i18n.byeMenu); }); @@ -232,7 +242,9 @@ export default class PluginSample extends Plugin { icon: "iconInfo", label: "Dialog", accelerator: this.commands[0].customHotkey, - click: () => this.showDialog() + click: () => { + this.showDialog() + } }); if (!this.isMobile) { menu.addItem({