Skip to content

Commit e6f5580

Browse files
authored
Merge pull request #19 from siyuan-note/dev
Update
2 parents 77e337b + d5bf3cb commit e6f5580

File tree

6 files changed

+119
-13
lines changed

6 files changed

+119
-13
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.1.10
2+
3+
* [Add `bind this` example for eventBus in plugins](https://github.com/siyuan-note/siyuan/issues/8668)
4+
* [Add `open-menu-breadcrumbmore` event bus to plugins](https://github.com/siyuan-note/siyuan/issues/8666)
5+
6+
## 0.1.9
7+
8+
* [Add `open-menu-xxx` event bus for plugins ](https://github.com/siyuan-note/siyuan/issues/8617)
9+
110
## 0.1.8
211

312
* [Add protyleSlash to the plugin](https://github.com/siyuan-note/siyuan/issues/8599)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[中文版](./README_zh_CN.md)
55

6-
> 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).
6+
> 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)
77
88

99

README_zh_CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[English](./README.md)
55

66

7-
> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.8](https://github.com/siyuan-note/plugin-sample/tree/v0.1.8)
7+
> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.10](https://github.com/siyuan-note/plugin-sample/tree/v0.1.10)
88
99
1. 使用 vite 打包
1010
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plugin-sample-vite-svelte",
3-
"version": "0.1.8",
3+
"version": "0.1.10",
44
"type": "module",
55
"description": "",
66
"repository": "",
@@ -22,7 +22,7 @@
2222
"minimist": "^1.2.8",
2323
"rollup-plugin-livereload": "^2.0.5",
2424
"sass": "^1.62.1",
25-
"siyuan": "0.7.5",
25+
"siyuan": "0.7.7",
2626
"svelte": "^3.57.0",
2727
"ts-node": "^10.9.1",
2828
"typescript": "^5.0.4",

scripts/make_dev_link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ if (targetDir === '') {
9393
log('"targetDir" is empty, try to get SiYuan directory automatically....')
9494
let res = await getSiYuanDir();
9595

96-
if (res === null) {
96+
if (res === null || res === undefined || res.length === 0) {
9797
log('Failed! You can set the plugin directory in scripts/make_dev_link.js and try again');
9898
process.exit(1);
9999
}

src/index.ts

+105-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ export default class PluginSample extends Plugin {
2626

2727
private customTab: () => IModel;
2828
private isMobile: boolean;
29+
private blockIconEventBindThis = this.blockIconEvent.bind(this);
2930

3031
async onload() {
31-
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
32+
this.data[STORAGE_NAME] = { readonlyText: "Readonly" };
3233

3334
console.log("loading plugin-sample", this.i18n);
3435

@@ -72,7 +73,7 @@ export default class PluginSample extends Plugin {
7273
statusIconTemp.content.firstElementChild.addEventListener("click", () => {
7374
confirm("⚠️", this.i18n.confirmRemove.replace("${name}", this.name), () => {
7475
this.removeData(STORAGE_NAME).then(() => {
75-
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
76+
this.data[STORAGE_NAME] = { readonlyText: "Readonly" };
7677
showMessage(`[${this.name}]: ${this.i18n.removedData}`);
7778
});
7879
});
@@ -113,7 +114,7 @@ export default class PluginSample extends Plugin {
113114
this.addDock({
114115
config: {
115116
position: "LeftBottom",
116-
size: {width: 200, height: 0},
117+
size: { width: 200, height: 0 },
117118
icon: "iconSaving",
118119
title: "Custom Dock",
119120
},
@@ -144,7 +145,7 @@ export default class PluginSample extends Plugin {
144145
const textareaElement = document.createElement("textarea");
145146
this.setting = new Setting({
146147
confirmCallback: () => {
147-
this.saveData(STORAGE_NAME, {readonlyText: textareaElement.value});
148+
this.saveData(STORAGE_NAME, { readonlyText: textareaElement.value });
148149
}
149150
});
150151
this.setting.addItem({
@@ -210,11 +211,11 @@ export default class PluginSample extends Plugin {
210211
});
211212
}
212213

213-
private eventBusLog({detail}: any) {
214+
private eventBusLog({ detail }: any) {
214215
console.log(detail);
215216
}
216217

217-
private blockIconEvent({detail}: any) {
218+
private blockIconEvent({ detail }: any) {
218219
const ids: string[] = [];
219220
detail.blockElements.forEach((item: HTMLElement) => {
220221
ids.push(item.getAttribute("data-node-id"));
@@ -359,13 +360,13 @@ export default class PluginSample extends Plugin {
359360
icon: "iconSelect",
360361
label: "On click-blockicon",
361362
click: () => {
362-
this.eventBus.on("click-blockicon", this.blockIconEvent);
363+
this.eventBus.on("click-blockicon", this.blockIconEventBindThis);
363364
}
364365
}, {
365366
icon: "iconClose",
366367
label: "Off click-blockicon",
367368
click: () => {
368-
this.eventBus.off("click-blockicon", this.blockIconEvent);
369+
this.eventBus.off("click-blockicon", this.blockIconEventBindThis);
369370
}
370371
}, {
371372
icon: "iconSelect",
@@ -427,6 +428,102 @@ export default class PluginSample extends Plugin {
427428
click: () => {
428429
this.eventBus.off("loaded-protyle", this.eventBusLog);
429430
}
431+
}, {
432+
icon: "iconSelect",
433+
label: "On open-menu-blockref",
434+
click: () => {
435+
this.eventBus.on("open-menu-blockref", this.eventBusLog);
436+
}
437+
}, {
438+
icon: "iconClose",
439+
label: "Off open-menu-blockref",
440+
click: () => {
441+
this.eventBus.off("open-menu-blockref", this.eventBusLog);
442+
}
443+
}, {
444+
icon: "iconSelect",
445+
label: "On open-menu-fileannotationref",
446+
click: () => {
447+
this.eventBus.on("open-menu-fileannotationref", this.eventBusLog);
448+
}
449+
}, {
450+
icon: "iconClose",
451+
label: "Off open-menu-fileannotationref",
452+
click: () => {
453+
this.eventBus.off("open-menu-fileannotationref", this.eventBusLog);
454+
}
455+
}, {
456+
icon: "iconSelect",
457+
label: "On open-menu-tag",
458+
click: () => {
459+
this.eventBus.on("open-menu-tag", this.eventBusLog);
460+
}
461+
}, {
462+
icon: "iconClose",
463+
label: "Off open-menu-tag",
464+
click: () => {
465+
this.eventBus.off("open-menu-tag", this.eventBusLog);
466+
}
467+
}, {
468+
icon: "iconSelect",
469+
label: "On open-menu-link",
470+
click: () => {
471+
this.eventBus.on("open-menu-link", this.eventBusLog);
472+
}
473+
}, {
474+
icon: "iconClose",
475+
label: "Off open-menu-link",
476+
click: () => {
477+
this.eventBus.off("open-menu-link", this.eventBusLog);
478+
}
479+
}, {
480+
icon: "iconSelect",
481+
label: "On open-menu-image",
482+
click: () => {
483+
this.eventBus.on("open-menu-image", this.eventBusLog);
484+
}
485+
}, {
486+
icon: "iconClose",
487+
label: "Off open-menu-image",
488+
click: () => {
489+
this.eventBus.off("open-menu-image", this.eventBusLog);
490+
}
491+
}, {
492+
icon: "iconSelect",
493+
label: "On open-menu-av",
494+
click: () => {
495+
this.eventBus.on("open-menu-av", this.eventBusLog);
496+
}
497+
}, {
498+
icon: "iconClose",
499+
label: "Off open-menu-av",
500+
click: () => {
501+
this.eventBus.off("open-menu-av", this.eventBusLog);
502+
}
503+
}, {
504+
icon: "iconSelect",
505+
label: "On open-menu-content",
506+
click: () => {
507+
this.eventBus.on("open-menu-content", this.eventBusLog);
508+
}
509+
}, {
510+
icon: "iconClose",
511+
label: "Off open-menu-content",
512+
click: () => {
513+
this.eventBus.off("open-menu-content", this.eventBusLog);
514+
}
515+
}, {
516+
icon: "iconSelect",
517+
label: "On open-menu-breadcrumbmore",
518+
click: () => {
519+
this.eventBus.on("open-menu-breadcrumbmore", this.eventBusLog);
520+
}
521+
}, {
522+
icon: "iconClose",
523+
label: "Off open-menu-breadcrumbmore",
524+
click: () => {
525+
this.eventBus.off("open-menu-breadcrumbmore", this.eventBusLog);
526+
}
430527
}]
431528
});
432529
menu.addSeparator();

0 commit comments

Comments
 (0)