Skip to content

Commit c849761

Browse files
authored
Merge pull request #7 from siyuan-note/dev
Up to date with `plugin-sample` v0.0.5
2 parents 8b19031 + e8bf750 commit c849761

File tree

7 files changed

+277
-44
lines changed

7 files changed

+277
-44
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,26 @@ The github action is included in this sample, you can use it to publish your new
178178
prerelease: true # change this to false
179179
```
180180
181+
182+
## How to remove svelte dependencies
183+
184+
This plugin is packaged in vite and provides a dependency on the svelte framework. However, in practice some developers may not want to use svelte and only want to use the vite package.
185+
186+
In fact you can use this template without using svelte without any modifications at all. The compilation-related parts of the svelte compilation are loaded into the vite workflow as plugins, so even if you don't have svelte in your project, it won't matter much.
187+
188+
If you insist on removing all svelte dependencies so that they do not pollute your workspace, you can perform the following steps. 1.
189+
190+
1. delete the
191+
```json
192+
{
193+
"@sveltejs/vite-plugin-svelte": "^2.0.3",
194+
"@tsconfig/svelte": "^4.0.1",
195+
"svelte": "^3.57.0"
196+
}
197+
```
198+
2. delete the `svelte.config.js` file
199+
3. delete the following line from the `vite.config.js` file
200+
- Line 6: `import { svelte } from "@sveltejs/vite-plugin-svelte"`
201+
- Line 20: `svelte(),`
202+
4. delete line 37 of `tsconfig.json` from `"svelte"` 5.
203+
5. re-run `pnpm i`

README_zh_CN.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,25 @@ PR 社区集市仓库。
167167
prerelease: true # 把这个改为 false
168168
```
169169
170+
## 如何去掉 svelte 依赖
170171
172+
本插件使用 vite 打包,并提供了 svelte 框架依赖。不过实际情况下可能有些开发者并不想要 svelte,只希望使用 vite 打包。
173+
174+
实际上你可以完全不做任何修改,就可以在不使用 svelte 的前提下使用这个模板。与 svelte 编译的编译相关的部分是以插件的形式载入到 vite 的工作流中,所以即使你的项目里面没有 svelte,也不会有太大的影响。
175+
176+
如果你执意希望删除掉所有 svelte 依赖以免它们污染你的工作空间,可以执行一下步骤:
177+
178+
1. 删掉 package.json 中的
179+
```json
180+
{
181+
"@sveltejs/vite-plugin-svelte": "^2.0.3",
182+
"@tsconfig/svelte": "^4.0.1",
183+
"svelte": "^3.57.0"
184+
}
185+
```
186+
2. 删掉 `svelte.config.js` 文件
187+
3. 删掉 `vite.config.js` 文件中的
188+
- 第六行: `import { svelte } from "@sveltejs/vite-plugin-svelte"`
189+
- 第二十行: `svelte(),`
190+
4. 删掉 `tsconfig.json` 中 37 行 `"svelte"`
191+
5. 重新执行 `pnpm i`

src/hello.svelte

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
<!--
2-
* Copyright (c) 2023 frostime. All rights reserved.
3-
* https://github.com/frostime/sy-plugin-template-vite
4-
-->
51
<script lang="ts">
62
import { onDestroy, onMount } from "svelte";
73
import { version } from "./api";
84
import { showMessage } from "siyuan";
5+
import Typo from "./libs/b3-typography.svelte";
6+
97
export let name: string;
108
export let i18n: any;
119
@@ -43,9 +41,10 @@
4341
</div>
4442
</div>
4543

46-
<div>
44+
<Typo>
45+
<h2>Wellcome to plugin sample with vite & svelte</h2>
4746
<p>{@html i18n.makesure}</p>
48-
</div>
47+
</Typo>
4948

5049
</div>
5150

src/index.ts

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* Copyright (c) 2023 frostime. All rights reserved.
3-
* https://github.com/frostime/sy-plugin-template-vite
4-
*/
51
import { Plugin, showMessage, confirm, Dialog, Menu, isMobile, openTab } from "siyuan";
62
import "./index.scss";
73

@@ -15,14 +11,11 @@ const DOCK_TYPE = "dock_tab";
1511

1612
export default class SamplePlugin extends Plugin {
1713

18-
counter: { [key: string]: number } = {
19-
hello: 0,
20-
};
2114
private customTab: () => any;
2215

2316
async onload() {
2417
showMessage("Hello SiYuan Plugin");
25-
console.log(this.i18n.helloPlugin);
18+
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
2619

2720
const topBarElement = this.addTopBar({
2821
icon: "iconEmoji",
@@ -79,10 +72,35 @@ export default class SamplePlugin extends Plugin {
7972

8073
}
8174

75+
onLayoutReady() {
76+
this.loadData(STORAGE_NAME);
77+
}
78+
79+
onunload() {
80+
console.log(this.i18n.byePlugin);
81+
showMessage("Goodbye SiYuan Plugin");
82+
console.log("onunload");
83+
}
84+
8285
private wsEvent({ detail }: any) {
8386
console.log(detail);
8487
}
8588

89+
private blockIconEvent({detail}: any) {
90+
console.log(detail);
91+
detail.menu.addSeparator(0);
92+
const ids: string[] = [];
93+
detail.blockElements.forEach((item: HTMLElement) => {
94+
ids.push(item.getAttribute("data-node-id"));
95+
});
96+
detail.menu.addItem({
97+
index: 1,
98+
iconHTML: "",
99+
type: "readonly",
100+
label: "IDs<br>" + ids.join("<br>"),
101+
});
102+
}
103+
86104
private async addMenu(rect: DOMRect) {
87105
const menu = new Menu("topBarSample", () => {
88106
console.log(this.i18n.byeMenu);
@@ -127,25 +145,79 @@ export default class SamplePlugin extends Plugin {
127145
}
128146
});
129147
menu.addItem({
130-
icon: "iconTrashcan",
131-
label: "Remove Data",
148+
icon: "iconLayout",
149+
label: "Open Float Layer(open help)",
132150
click: () => {
133-
this.removeData(STORAGE_NAME);
151+
this.addFloatLayer({
152+
ids: ["20230523173319-xj1l3qu", "20230523173321-55o0w2n"],
153+
defIds: ["20230523173323-imgm9tp", "20230523173324-cxu98t3"],
154+
x: window.innerWidth - 768 - 120,
155+
y: 32
156+
});
134157
}
135158
});
136159
menu.addItem({
137-
icon: "iconSelect",
138-
label: "On ws-main",
160+
icon: "iconTrashcan",
161+
label: "Remove Data",
139162
click: () => {
140-
this.eventBus.on("ws-main", this.wsEvent);
163+
this.removeData(STORAGE_NAME).then(() => {
164+
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
165+
});
141166
}
142167
});
143168
menu.addItem({
144-
icon: "iconClose",
145-
label: "Off ws-main",
146-
click: () => {
147-
this.eventBus.off("ws-main", this.wsEvent);
148-
}
169+
icon: "iconScrollHoriz",
170+
label: "Event Bus",
171+
type: "submenu",
172+
submenu: [{
173+
icon: "iconSelect",
174+
label: "On ws-main",
175+
click: () => {
176+
this.eventBus.on("ws-main", this.wsEvent);
177+
}
178+
}, {
179+
icon: "iconClose",
180+
label: "Off ws-main",
181+
click: () => {
182+
this.eventBus.off("ws-main", this.wsEvent);
183+
}
184+
}, {
185+
icon: "iconSelect",
186+
label: "On click-blockicon",
187+
click: () => {
188+
this.eventBus.on("click-blockicon", this.blockIconEvent);
189+
}
190+
}, {
191+
icon: "iconClose",
192+
label: "Off click-blockicon",
193+
click: () => {
194+
this.eventBus.off("click-blockicon", this.blockIconEvent);
195+
}
196+
}, {
197+
icon: "iconSelect",
198+
label: "On click-pdf",
199+
click: () => {
200+
this.eventBus.on("click-pdf", this.wsEvent);
201+
}
202+
}, {
203+
icon: "iconClose",
204+
label: "Off click-pdf",
205+
click: () => {
206+
this.eventBus.off("click-pdf", this.wsEvent);
207+
}
208+
}, {
209+
icon: "iconSelect",
210+
label: "On click-editorcontent",
211+
click: () => {
212+
this.eventBus.on("click-editorcontent", this.wsEvent);
213+
}
214+
}, {
215+
icon: "iconClose",
216+
label: "Off click-editorcontent",
217+
click: () => {
218+
this.eventBus.off("click-editorcontent", this.wsEvent);
219+
}
220+
}]
149221
});
150222
menu.addSeparator();
151223
menu.addItem({
@@ -181,7 +253,6 @@ export default class SamplePlugin extends Plugin {
181253
}
182254

183255
private openHelloInDialog() {
184-
this.counter.hello++;
185256
let dialog = new Dialog({
186257
title: "Hello World",
187258
content: `<div id="helloPanel"></div>`,
@@ -198,9 +269,4 @@ export default class SamplePlugin extends Plugin {
198269
}
199270
});
200271
}
201-
202-
async onunload() {
203-
showMessage("Goodbye SiYuan Plugin");
204-
console.log("onunload");
205-
}
206272
}

src/libs/b3-list.svelte

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/libs/b3-typography.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="item__readme b3-typography">
2+
<slot/>
3+
</div>

0 commit comments

Comments
 (0)