From 4dde9da239e7cc89995d630059e8c1c3bf99c935 Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 20:34:16 +0800 Subject: [PATCH 1/7] chore --- CHANGELOG.md | 12 ++++++++++++ package.json | 4 ++-- plugin.json | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..cd09d9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +## 0.1.8 + +* [Add protyleSlash to the plugin](https://github.com/siyuan-note/siyuan/issues/8599) +* [Add plugin API protyle](https://github.com/siyuan-note/siyuan/issues/8445) + +## 0.1.7 + +* [Support build js and json](https://github.com/siyuan-note/plugin-sample/pull/8) + +## 0.1.6 + +* add `fetchPost` example diff --git a/package.json b/package.json index 27331d9..901a1c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-sample-vite-svelte", - "version": "0.1.5", + "version": "0.1.8", "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.4", + "siyuan": "0.7.5", "svelte": "^3.57.0", "ts-node": "^10.9.1", "typescript": "^5.0.4", diff --git a/plugin.json b/plugin.json index 50fdf74..0cb1325 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.5", + "version": "0.1.8", "minAppVersion": "2.9.0", "backends": ["all"], "frontends": ["all"], From 837f5ae1f5ddb70c897fa9fd1cc2207c6e837f13 Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 20:35:12 +0800 Subject: [PATCH 2/7] i18n --- src/i18n/en_US.json | 1 + src/i18n/zh_CN.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index c336270..58f63ff 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -8,6 +8,7 @@ "showDialog": "Show dialog", "removedData": "Data deleted", "confirmRemove": "Confirm to delete the data in ${name}?", + "insertEmoji": "Insert Emoji", "name": "SiYuan", "hello": { "makesure": "Before using this template, please read the offical sample, make sure that you've known about the pipeline for plugin developing." diff --git a/src/i18n/zh_CN.json b/src/i18n/zh_CN.json index 568cccd..a1ee598 100644 --- a/src/i18n/zh_CN.json +++ b/src/i18n/zh_CN.json @@ -8,6 +8,7 @@ "showDialog": "弹出一个对话框", "removedData": "数据已删除", "confirmRemove": "确认删除 ${name} 中的数据?", + "insertEmoji": "插入表情", "name": "思源", "hello": { "makesure": "使用这个模板之前,请阅读官方教程, 确保自己已经理解了插件的基本开发流程。" From 22c27c0542439725287068ce77e2727facc42cce Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 20:43:58 +0800 Subject: [PATCH 3/7] change --- src/index.scss | 23 +++++++++++++++++++++++ src/index.ts | 17 ++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/index.scss b/src/index.scss index cb1be95..c8efd4f 100644 --- a/src/index.scss +++ b/src/index.scss @@ -1,3 +1,26 @@ #helloPanel { border: 1px rgb(189, 119, 119) dashed; +} + +.plugin-sample { + &__custom-tab { + background-color: var(--b3-theme-background); + height: 100%; + width: 100%; + display: flex; + justify-content: center; + align-items: center; + } + + &__custom-dock { + display: flex; + justify-content: center; + align-items: center; + } + + &__time { + background: var(--b3-card-info-background); + border-radius: 4px; + padding: 2px 8px; + } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 51c40af..a5ccd12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,9 @@ import { getFrontend, getBackend, IModel, - Setting + Setting, + fetchPost, + Protyle } from "siyuan"; import "@/index.scss"; @@ -167,6 +169,15 @@ export default class PluginSample extends Plugin { actionElement: btnaElement, }); + this.protyleSlash = [{ + filter: ["insert emoji 😊", "插入表情 😊", "crbqwx"], + html: `
${this.i18n.insertEmoji}😊
`, + id: "insertEmoji", + callback(protyle: Protyle) { + protyle.insert("😊"); + } + }]; + console.log(this.i18n.helloPlugin); } @@ -240,10 +251,10 @@ export default class PluginSample extends Plugin { }); menu.addItem({ icon: "iconInfo", - label: "Dialog", + label: "Dialog(open help first)", accelerator: this.commands[0].customHotkey, click: () => { - this.showDialog() + this.showDialog(); } }); if (!this.isMobile) { From 73070a56fdea059c32064fac3083c8dd43ea5f6b Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 21:11:35 +0800 Subject: [PATCH 4/7] dialog use protyle --- src/hello.svelte | 74 ++++++++++++++++++++---------------------------- src/index.ts | 12 ++------ 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/hello.svelte b/src/hello.svelte index 9094eb3..30665f1 100644 --- a/src/hello.svelte +++ b/src/hello.svelte @@ -1,61 +1,49 @@ -
-
-
-

Hello {name} v{ver}

-
-
- {time_str} -
+
+
API demo:
+
+
+ System current time: {time}
- - -

Wellcome to plugin sample with vite & svelte

-

{@html i18n.makesure}

-
- +
+
+
Protyle demo: id = {blockID}
+
+
- diff --git a/src/index.ts b/src/index.ts index a5ccd12..e12c75c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,11 +83,7 @@ export default class PluginSample extends Plugin { let tabDiv = document.createElement("div"); new HelloExample({ - target: tabDiv, - props: { - name: this.i18n.name, - i18n: this.i18n.hello - } + target: tabDiv }); this.customTab = this.addTab({ type: TAB_TYPE, @@ -236,12 +232,8 @@ export default class PluginSample extends Plugin { // hello.$destroy(); }, }); - let hello = new HelloExample({ + new HelloExample({ target: dialog.element.querySelector("#helloPanel"), - props: { - name: this.i18n.name, - i18n: this.i18n.hello - } }); } From b1660caa305cbc7182264468ba390144766a2182 Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 21:17:34 +0800 Subject: [PATCH 5/7] slider tooltips --- src/libs/setting-item.svelte | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libs/setting-item.svelte b/src/libs/setting-item.svelte index 74e08b5..b728cf4 100644 --- a/src/libs/setting-item.svelte +++ b/src/libs/setting-item.svelte @@ -13,7 +13,7 @@ min: number; max: number; step: number; - } = {min: 0, max: 100, step: 1}; // Use it if type is slider + } = { min: 0, max: 100, step: 1 }; // Use it if type is slider const dispatch = createEventDispatcher(); @@ -76,15 +76,17 @@ {:else if type == "slider"} - +
+ +
{/if} From 34e3646add5c0fc69bc5304794be8fcc16a1be9d Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 21:18:04 +0800 Subject: [PATCH 6/7] doc --- README.md | 2 +- README_zh_CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71d9860..737800a 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.5](https://github.com/siyuan-note/plugin-sample/tree/v0.1.5). +> 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). diff --git a/README_zh_CN.md b/README_zh_CN.md index 260eaf0..5177733 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.5](https://github.com/siyuan-note/plugin-sample/tree/v0.1.5) +> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.1.8](https://github.com/siyuan-note/plugin-sample/tree/v0.1.8) 1. 使用 vite 打包 2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发 From ddca3e0e24eeadbb136d6aef27864aa5ceafa0f2 Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 28 Jun 2023 21:28:38 +0800 Subject: [PATCH 7/7] fix: protyle --- src/hello.svelte | 9 +++++---- src/index.ts | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hello.svelte b/src/hello.svelte index 30665f1..6d10108 100644 --- a/src/hello.svelte +++ b/src/hello.svelte @@ -3,6 +3,8 @@ import { version, sql as query } from "@/api"; import { showMessage, fetchPost, Protyle } from "siyuan"; + export let app; + let time: string = ""; let ver: string; @@ -15,7 +17,7 @@ fetchPost("/api/system/currentTime", {}, (response) => { time = new Date(response.data).toString(); }); - await initProtyle(); + protyle = await initProtyle(); }); onDestroy(() => { @@ -27,9 +29,8 @@ let sql = "SELECT * FROM blocks ORDER BY RANDOM () LIMIT 1;"; let blocks: Block[] = await query(sql); blockID = blocks[0].id; - protyle = new Protyle(this.app, divProtyle, { - blockId: blockID, - mode: "preview" + return new Protyle(app, divProtyle, { + blockId: blockID }); } diff --git a/src/index.ts b/src/index.ts index e12c75c..897dcf1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,7 +83,10 @@ export default class PluginSample extends Plugin { let tabDiv = document.createElement("div"); new HelloExample({ - target: tabDiv + target: tabDiv, + props: { + app: this.app, + } }); this.customTab = this.addTab({ type: TAB_TYPE, @@ -234,6 +237,9 @@ export default class PluginSample extends Plugin { }); new HelloExample({ target: dialog.element.querySelector("#helloPanel"), + props: { + app: this.app, + } }); }