From 38b8677c15b76056b8153329ef6a5a82bc31d1b0 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 15 Jul 2023 15:21:40 +0800 Subject: [PATCH 1/2] upgrade to v0.1.10 --- CHANGELOG.md | 9 ++++ README.md | 2 +- README_zh_CN.md | 2 +- package.json | 4 +- src/index.ts | 113 ++++++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 118 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd09d9c..19a59a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 0.1.10 + +* [Add `bind this` example for eventBus in plugins](https://github.com/siyuan-note/siyuan/issues/8668) +* [Add `open-menu-breadcrumbmore` event bus to plugins](https://github.com/siyuan-note/siyuan/issues/8666) + +## 0.1.9 + +* [Add `open-menu-xxx` event bus for plugins ](https://github.com/siyuan-note/siyuan/issues/8617) + ## 0.1.8 * [Add protyleSlash to the plugin](https://github.com/siyuan-note/siyuan/issues/8599) diff --git a/README.md b/README.md index 737800a..98b04e1 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.8](https://github.com/siyuan-note/plugin-sample/tree/v0.1.8). +> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.10](https://github.com/siyuan-note/plugin-sample/tree/v0.1.10) diff --git a/README_zh_CN.md b/README_zh_CN.md index 5177733..0f3203b 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.8](https://github.com/siyuan-note/plugin-sample/tree/v0.1.8) +> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.10](https://github.com/siyuan-note/plugin-sample/tree/v0.1.10) 1. 使用 vite 打包 2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发 diff --git a/package.json b/package.json index 901a1c1..829bbb5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-sample-vite-svelte", - "version": "0.1.8", + "version": "0.1.10", "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.5", + "siyuan": "0.7.7", "svelte": "^3.57.0", "ts-node": "^10.9.1", "typescript": "^5.0.4", diff --git a/src/index.ts b/src/index.ts index 897dcf1..661f792 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,9 +26,10 @@ export default class PluginSample extends Plugin { private customTab: () => IModel; private isMobile: boolean; + private blockIconEventBindThis = this.blockIconEvent.bind(this); async onload() { - this.data[STORAGE_NAME] = {readonlyText: "Readonly"}; + this.data[STORAGE_NAME] = { readonlyText: "Readonly" }; console.log("loading plugin-sample", this.i18n); @@ -72,7 +73,7 @@ export default class PluginSample extends Plugin { statusIconTemp.content.firstElementChild.addEventListener("click", () => { confirm("⚠️", this.i18n.confirmRemove.replace("${name}", this.name), () => { this.removeData(STORAGE_NAME).then(() => { - this.data[STORAGE_NAME] = {readonlyText: "Readonly"}; + this.data[STORAGE_NAME] = { readonlyText: "Readonly" }; showMessage(`[${this.name}]: ${this.i18n.removedData}`); }); }); @@ -113,7 +114,7 @@ export default class PluginSample extends Plugin { this.addDock({ config: { position: "LeftBottom", - size: {width: 200, height: 0}, + size: { width: 200, height: 0 }, icon: "iconSaving", title: "Custom Dock", }, @@ -144,7 +145,7 @@ export default class PluginSample extends Plugin { const textareaElement = document.createElement("textarea"); this.setting = new Setting({ confirmCallback: () => { - this.saveData(STORAGE_NAME, {readonlyText: textareaElement.value}); + this.saveData(STORAGE_NAME, { readonlyText: textareaElement.value }); } }); this.setting.addItem({ @@ -210,11 +211,11 @@ export default class PluginSample extends Plugin { }); } - private eventBusLog({detail}: any) { + private eventBusLog({ detail }: any) { console.log(detail); } - private blockIconEvent({detail}: any) { + private blockIconEvent({ detail }: any) { const ids: string[] = []; detail.blockElements.forEach((item: HTMLElement) => { ids.push(item.getAttribute("data-node-id")); @@ -359,13 +360,13 @@ export default class PluginSample extends Plugin { icon: "iconSelect", label: "On click-blockicon", click: () => { - this.eventBus.on("click-blockicon", this.blockIconEvent); + this.eventBus.on("click-blockicon", this.blockIconEventBindThis); } }, { icon: "iconClose", label: "Off click-blockicon", click: () => { - this.eventBus.off("click-blockicon", this.blockIconEvent); + this.eventBus.off("click-blockicon", this.blockIconEventBindThis); } }, { icon: "iconSelect", @@ -427,6 +428,102 @@ export default class PluginSample extends Plugin { click: () => { this.eventBus.off("loaded-protyle", this.eventBusLog); } + }, { + icon: "iconSelect", + label: "On open-menu-blockref", + click: () => { + this.eventBus.on("open-menu-blockref", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-blockref", + click: () => { + this.eventBus.off("open-menu-blockref", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-fileannotationref", + click: () => { + this.eventBus.on("open-menu-fileannotationref", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-fileannotationref", + click: () => { + this.eventBus.off("open-menu-fileannotationref", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-tag", + click: () => { + this.eventBus.on("open-menu-tag", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-tag", + click: () => { + this.eventBus.off("open-menu-tag", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-link", + click: () => { + this.eventBus.on("open-menu-link", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-link", + click: () => { + this.eventBus.off("open-menu-link", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-image", + click: () => { + this.eventBus.on("open-menu-image", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-image", + click: () => { + this.eventBus.off("open-menu-image", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-av", + click: () => { + this.eventBus.on("open-menu-av", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-av", + click: () => { + this.eventBus.off("open-menu-av", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-content", + click: () => { + this.eventBus.on("open-menu-content", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-content", + click: () => { + this.eventBus.off("open-menu-content", this.eventBusLog); + } + }, { + icon: "iconSelect", + label: "On open-menu-breadcrumbmore", + click: () => { + this.eventBus.on("open-menu-breadcrumbmore", this.eventBusLog); + } + }, { + icon: "iconClose", + label: "Off open-menu-breadcrumbmore", + click: () => { + this.eventBus.off("open-menu-breadcrumbmore", this.eventBusLog); + } }] }); menu.addSeparator(); From d5bf3cbc661d4cedcd1dcb8c024aac75c7c55639 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 15 Jul 2023 15:28:30 +0800 Subject: [PATCH 2/2] update make-link --- scripts/make_dev_link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/make_dev_link.js b/scripts/make_dev_link.js index 26e3df7..9095aad 100644 --- a/scripts/make_dev_link.js +++ b/scripts/make_dev_link.js @@ -93,7 +93,7 @@ if (targetDir === '') { log('"targetDir" is empty, try to get SiYuan directory automatically....') let res = await getSiYuanDir(); - if (res === null) { + if (res === null || res === undefined || res.length === 0) { log('Failed! You can set the plugin directory in scripts/make_dev_link.js and try again'); process.exit(1); }