Skip to content

Commit e2ed032

Browse files
committed
Merge branch 'dev'
2 parents 05c9f26 + bc63535 commit e2ed032

9 files changed

+111
-44
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# Changelog
22

3+
## 0.2.7 2023-10
4+
5+
## 0.2.6 2023-10-24
6+
7+
* [Deprecated `loaded-protyle` use `loaded-protyle-static` instead](https://github.com/siyuan-note/siyuan/issues/9468)
8+
9+
## 0.2.5 2023-10-10
10+
11+
* [Add plugin event bus `open-menu-doctree`](https://github.com/siyuan-note/siyuan/issues/9351)
12+
13+
## 0.2.4 2023-09-19
14+
15+
* Supports use in windows
16+
* [Add plugin function `transaction`](https://github.com/siyuan-note/siyuan/issues/9172)
17+
318
## 0.2.3 2023-09-05
419

20+
* [Add plugin function `transaction`](https://github.com/siyuan-note/siyuan/issues/9172)
521
* [Plugin API add openWindow and command.globalCallback](https://github.com/siyuan-note/siyuan/issues/9032)
622

723
## 0.2.2 2023-08-29

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

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "plugin-sample-vite-svelte",
3-
"version": "0.2.3",
3+
"version": "0.2.6",
44
"type": "module",
5-
"description": "",
5+
"description": "This is a sample plugin based on vite and svelte for Siyuan (https://b3log.org/siyuan)",
66
"repository": "",
77
"homepage": "",
88
"author": "",
9-
"license": "GPL-3.0",
9+
"license": "MIT",
1010
"scripts": {
1111
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
1212
"dev": "vite build --watch",
@@ -22,7 +22,7 @@
2222
"minimist": "^1.2.8",
2323
"rollup-plugin-livereload": "^2.0.5",
2424
"sass": "^1.62.1",
25-
"siyuan": "0.8.3",
25+
"siyuan": "0.8.7",
2626
"svelte": "^3.57.0",
2727
"ts-node": "^10.9.1",
2828
"typescript": "^5.0.4",

plugin.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
"name": "plugin-sample-vite-svelte",
33
"author": "frostime",
44
"url": "https://github.com/siyuan-note/plugin-sample-vite-svelte",
5-
"version": "0.2.3",
6-
"minAppVersion": "2.10.3",
7-
"backends": ["all"],
8-
"frontends": ["all"],
5+
"version": "0.2.6",
6+
"minAppVersion": "2.10.12",
7+
"backends": [
8+
"windows",
9+
"linux",
10+
"darwin"
11+
],
12+
"frontends": [
13+
"desktop",
14+
"desktop-window"
15+
],
916
"displayName": {
1017
"en_US": "Plugin sample with vite and svelte",
1118
"zh_CN": "插件样例 vite + svelte 版"

src/hello.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
export let app;
77
88
let time: string = "";
9-
let ver: string;
9+
let ver: string = "";
1010
1111
let divProtyle: HTMLDivElement;
1212
let protyle: any;

src/i18n/en_US.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"removedData": "Data deleted",
1010
"confirmRemove": "Confirm to delete the data in ${name}?",
1111
"insertEmoji": "Insert Emoji",
12+
"removeSpace": "Remove Space",
1213
"getTab": "Print out all opened custom tabs in the debugger",
1314
"name": "SiYuan",
1415
"hello": {

src/i18n/zh_CN.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"removedData": "数据已删除",
1010
"confirmRemove": "确认删除 ${name} 中的数据?",
1111
"insertEmoji": "插入表情",
12+
"removeSpace": "移除空格",
1213
"getTab": "在日志中打印出已打开的所有自定义页签",
1314
"name": "思源",
1415
"hello": {

src/index.ts

+75-33
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
IModel,
1212
Setting,
1313
fetchPost,
14-
Protyle, openWindow
14+
Protyle, openWindow, IOperation
1515
} from "siyuan";
1616
import "@/index.scss";
1717

@@ -68,7 +68,7 @@ export default class PluginSample extends Plugin {
6868
});
6969

7070
const statusIconTemp = document.createElement("template");
71-
statusIconTemp.innerHTML = `<div class="toolbar__item b3-tooltips b3-tooltips__w" aria-label="Remove plugin-sample Data">
71+
statusIconTemp.innerHTML = `<div class="toolbar__item ariaLabel" aria-label="Remove plugin-sample Data">
7272
<svg>
7373
<use xlink:href="#iconTrashcan"></use>
7474
</svg>
@@ -85,27 +85,6 @@ export default class PluginSample extends Plugin {
8585
element: statusIconTemp.content.firstElementChild as HTMLElement,
8686
});
8787

88-
let tabDiv = document.createElement("div");
89-
new HelloExample({
90-
target: tabDiv,
91-
props: {
92-
app: this.app,
93-
}
94-
});
95-
this.customTab = this.addTab({
96-
type: TAB_TYPE,
97-
init() {
98-
this.element.appendChild(tabDiv);
99-
console.log(this.element);
100-
},
101-
beforeDestroy() {
102-
console.log("before destroy tab:", TAB_TYPE);
103-
},
104-
destroy() {
105-
console.log("destroy tab:", TAB_TYPE);
106-
}
107-
});
108-
10988
this.addCommand({
11089
langKey: "showDialog",
11190
hotkey: "⇧⌘O",
@@ -244,6 +223,26 @@ export default class PluginSample extends Plugin {
244223
// this.loadData(STORAGE_NAME);
245224
this.settingUtils.load();
246225
console.log(`frontend: ${getFrontend()}; backend: ${getBackend()}`);
226+
let tabDiv = document.createElement("div");
227+
new HelloExample({
228+
target: tabDiv,
229+
props: {
230+
app: this.app,
231+
}
232+
});
233+
this.customTab = this.addTab({
234+
type: TAB_TYPE,
235+
init() {
236+
this.element.appendChild(tabDiv);
237+
console.log(this.element);
238+
},
239+
beforeDestroy() {
240+
console.log("before destroy tab:", TAB_TYPE);
241+
},
242+
destroy() {
243+
console.log("destroy tab:", TAB_TYPE);
244+
}
245+
});
247246
}
248247

249248
async onunload() {
@@ -272,19 +271,38 @@ export default class PluginSample extends Plugin {
272271
});
273272
}
274273

274+
private eventBusPaste(event: any) {
275+
// 如果需异步处理请调用 preventDefault, 否则会进行默认处理
276+
event.preventDefault();
277+
// 如果使用了 preventDefault,必须调用 resolve,否则程序会卡死
278+
event.detail.resolve({
279+
textPlain: event.detail.textPlain.trim(),
280+
});
281+
}
282+
275283
private eventBusLog({ detail }: any) {
276284
console.log(detail);
277285
}
278286

279287
private blockIconEvent({ detail }: any) {
280-
const ids: string[] = [];
281-
detail.blockElements.forEach((item: HTMLElement) => {
282-
ids.push(item.getAttribute("data-node-id"));
283-
});
284288
detail.menu.addItem({
285289
iconHTML: "",
286-
type: "readonly",
287-
label: "IDs<br>" + ids.join("<br>"),
290+
label: this.i18n.removeSpace,
291+
click: () => {
292+
const doOperations: IOperation[] = [];
293+
detail.blockElements.forEach((item: HTMLElement) => {
294+
const editElement = item.querySelector('[contenteditable="true"]');
295+
if (editElement) {
296+
editElement.textContent = editElement.textContent.replace(/ /g, "");
297+
doOperations.push({
298+
id: item.dataset.nodeId,
299+
data: item.outerHTML,
300+
action: "update"
301+
});
302+
}
303+
});
304+
detail.protyle.getInstance().transaction(doOperations);
305+
}
288306
});
289307
}
290308

@@ -488,9 +506,15 @@ export default class PluginSample extends Plugin {
488506
}
489507
}, {
490508
icon: "iconSelect",
491-
label: "On loaded-protyle",
509+
label: "On loaded-protyle-static",
492510
click: () => {
493-
this.eventBus.on("loaded-protyle", this.eventBusLog);
511+
this.eventBus.on("loaded-protyle-static", this.eventBusLog);
512+
}
513+
}, {
514+
icon: "iconClose",
515+
label: "Off loaded-protyle-static",
516+
click: () => {
517+
this.eventBus.off("loaded-protyle-static", this.eventBusLog);
494518
}
495519
}, {
496520
icon: "iconSelect",
@@ -516,11 +540,17 @@ export default class PluginSample extends Plugin {
516540
click: () => {
517541
this.eventBus.off("destroy-protyle", this.eventBusLog);
518542
}
543+
}, {
544+
icon: "iconSelect",
545+
label: "On open-menu-doctree",
546+
click: () => {
547+
this.eventBus.on("open-menu-doctree", this.eventBusLog);
548+
}
519549
}, {
520550
icon: "iconClose",
521-
label: "Off loaded-protyle",
551+
label: "Off open-menu-doctree",
522552
click: () => {
523-
this.eventBus.off("loaded-protyle", this.eventBusLog);
553+
this.eventBus.off("open-menu-doctree", this.eventBusLog);
524554
}
525555
}, {
526556
icon: "iconSelect",
@@ -630,6 +660,18 @@ export default class PluginSample extends Plugin {
630660
click: () => {
631661
this.eventBus.off("input-search", this.eventBusLog);
632662
}
663+
}, {
664+
icon: "iconSelect",
665+
label: "On paste",
666+
click: () => {
667+
this.eventBus.on("paste", this.eventBusPaste);
668+
}
669+
}, {
670+
icon: "iconClose",
671+
label: "Off paste",
672+
click: () => {
673+
this.eventBus.off("paste", this.eventBusPaste);
674+
}
633675
}, {
634676
icon: "iconSelect",
635677
label: "On open-siyuan-url-plugin",

0 commit comments

Comments
 (0)