commit
f0ef27efab
11 changed files with 103 additions and 66 deletions
12
CHANGELOG.md
12
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
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
[中文版](./README_zh_CN.md)
|
[中文版](./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).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
[English](./README.md)
|
[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 打包
|
1. 使用 vite 打包
|
||||||
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发
|
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "plugin-sample-vite-svelte",
|
"name": "plugin-sample-vite-svelte",
|
||||||
"version": "0.1.5",
|
"version": "0.1.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "",
|
"description": "",
|
||||||
"repository": "",
|
"repository": "",
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"rollup-plugin-livereload": "^2.0.5",
|
"rollup-plugin-livereload": "^2.0.5",
|
||||||
"sass": "^1.62.1",
|
"sass": "^1.62.1",
|
||||||
"siyuan": "0.7.4",
|
"siyuan": "0.7.5",
|
||||||
"svelte": "^3.57.0",
|
"svelte": "^3.57.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "plugin-sample-vite-svelte",
|
"name": "plugin-sample-vite-svelte",
|
||||||
"author": "frostime",
|
"author": "frostime",
|
||||||
"url": "https://github.com/siyuan-note/plugin-sample-vite-svelte",
|
"url": "https://github.com/siyuan-note/plugin-sample-vite-svelte",
|
||||||
"version": "0.1.5",
|
"version": "0.1.8",
|
||||||
"minAppVersion": "2.9.0",
|
"minAppVersion": "2.9.0",
|
||||||
"backends": ["all"],
|
"backends": ["all"],
|
||||||
"frontends": ["all"],
|
"frontends": ["all"],
|
||||||
|
|
|
@ -1,61 +1,50 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy, onMount } from "svelte";
|
import { onDestroy, onMount } from "svelte";
|
||||||
import { version } from "@/api";
|
import { version, sql as query } from "@/api";
|
||||||
import { showMessage } from "siyuan";
|
import { showMessage, fetchPost, Protyle } from "siyuan";
|
||||||
import Typo from "@/libs/b3-typography.svelte";
|
|
||||||
|
|
||||||
export let name: string;
|
export let app;
|
||||||
export let i18n: any;
|
|
||||||
|
|
||||||
let time;
|
let time: string = "";
|
||||||
let ver;
|
let ver: string;
|
||||||
|
|
||||||
let intv1 = setInterval(async () => {
|
let divProtyle: HTMLDivElement;
|
||||||
time = new Date();
|
let protyle: any;
|
||||||
}, 1000);
|
let blockID: string = '';
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
time = new Date();
|
|
||||||
ver = await version();
|
ver = await version();
|
||||||
|
fetchPost("/api/system/currentTime", {}, (response) => {
|
||||||
|
time = new Date(response.data).toString();
|
||||||
|
});
|
||||||
|
protyle = await initProtyle();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* You must call this function when the component is destroyed.
|
|
||||||
*/
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
showMessage("Hello panel closed");
|
showMessage("Hello panel closed");
|
||||||
clearInterval(intv1);
|
protyle.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
$: time_str = new Date(time).toLocaleTimeString();
|
async function initProtyle() {
|
||||||
|
let sql = "SELECT * FROM blocks ORDER BY RANDOM () LIMIT 1;";
|
||||||
|
let blocks: Block[] = await query(sql);
|
||||||
|
blockID = blocks[0].id;
|
||||||
|
return new Protyle(app, divProtyle, {
|
||||||
|
blockId: blockID
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="hello">
|
<div class="b3-dialog__content">
|
||||||
<div class="fn__flex">
|
<div>API demo:</div>
|
||||||
<div class="fn__flex-1">
|
<div class="fn__hr" />
|
||||||
<h2>Hello {name} v{ver}</h2>
|
<div class="plugin-sample__time">
|
||||||
</div>
|
System current time: <span id="time">{time}</span>
|
||||||
<div class="fn__flex-1 b3-label__text __text-right">
|
|
||||||
{time_str}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="fn__hr" />
|
||||||
<Typo>
|
<div class="fn__hr" />
|
||||||
<h2>Wellcome to plugin sample with vite & svelte</h2>
|
<div>Protyle demo: id = {blockID}</div>
|
||||||
<p>{@html i18n.makesure}</p>
|
<div class="fn__hr" />
|
||||||
</Typo>
|
<div id="protyle" style="height: 360px;" bind:this={divProtyle}/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
#hello {
|
|
||||||
margin: 20px;
|
|
||||||
div {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.__text-right {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"showDialog": "Show dialog",
|
"showDialog": "Show dialog",
|
||||||
"removedData": "Data deleted",
|
"removedData": "Data deleted",
|
||||||
"confirmRemove": "Confirm to delete the data in ${name}?",
|
"confirmRemove": "Confirm to delete the data in ${name}?",
|
||||||
|
"insertEmoji": "Insert Emoji",
|
||||||
"name": "SiYuan",
|
"name": "SiYuan",
|
||||||
"hello": {
|
"hello": {
|
||||||
"makesure": "Before using this template, please read the <a href=\"https://github.com/siyuan-note/plugin-sample\">offical sample</a>, make sure that you've known about the pipeline for plugin developing."
|
"makesure": "Before using this template, please read the <a href=\"https://github.com/siyuan-note/plugin-sample\">offical sample</a>, make sure that you've known about the pipeline for plugin developing."
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"showDialog": "弹出一个对话框",
|
"showDialog": "弹出一个对话框",
|
||||||
"removedData": "数据已删除",
|
"removedData": "数据已删除",
|
||||||
"confirmRemove": "确认删除 ${name} 中的数据?",
|
"confirmRemove": "确认删除 ${name} 中的数据?",
|
||||||
|
"insertEmoji": "插入表情",
|
||||||
"name": "思源",
|
"name": "思源",
|
||||||
"hello": {
|
"hello": {
|
||||||
"makesure": "使用这个模板之前,请阅读<a href=\"https://github.com/siyuan-note/plugin-sample\">官方教程</a>, 确保自己已经理解了插件的基本开发流程。"
|
"makesure": "使用这个模板之前,请阅读<a href=\"https://github.com/siyuan-note/plugin-sample\">官方教程</a>, 确保自己已经理解了插件的基本开发流程。"
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
#helloPanel {
|
#helloPanel {
|
||||||
border: 1px rgb(189, 119, 119) dashed;
|
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;
|
||||||
|
}
|
||||||
|
}
|
25
src/index.ts
25
src/index.ts
|
@ -9,7 +9,9 @@ import {
|
||||||
getFrontend,
|
getFrontend,
|
||||||
getBackend,
|
getBackend,
|
||||||
IModel,
|
IModel,
|
||||||
Setting
|
Setting,
|
||||||
|
fetchPost,
|
||||||
|
Protyle
|
||||||
} from "siyuan";
|
} from "siyuan";
|
||||||
import "@/index.scss";
|
import "@/index.scss";
|
||||||
|
|
||||||
|
@ -83,8 +85,7 @@ export default class PluginSample extends Plugin {
|
||||||
new HelloExample({
|
new HelloExample({
|
||||||
target: tabDiv,
|
target: tabDiv,
|
||||||
props: {
|
props: {
|
||||||
name: this.i18n.name,
|
app: this.app,
|
||||||
i18n: this.i18n.hello
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.customTab = this.addTab({
|
this.customTab = this.addTab({
|
||||||
|
@ -167,6 +168,15 @@ export default class PluginSample extends Plugin {
|
||||||
actionElement: btnaElement,
|
actionElement: btnaElement,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.protyleSlash = [{
|
||||||
|
filter: ["insert emoji 😊", "插入表情 😊", "crbqwx"],
|
||||||
|
html: `<div class="b3-list-item__first"><span class="b3-list-item__text">${this.i18n.insertEmoji}</span><span class="b3-list-item__meta">😊</span></div>`,
|
||||||
|
id: "insertEmoji",
|
||||||
|
callback(protyle: Protyle) {
|
||||||
|
protyle.insert("😊");
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
console.log(this.i18n.helloPlugin);
|
console.log(this.i18n.helloPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,11 +235,10 @@ export default class PluginSample extends Plugin {
|
||||||
// hello.$destroy();
|
// hello.$destroy();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
let hello = new HelloExample({
|
new HelloExample({
|
||||||
target: dialog.element.querySelector("#helloPanel"),
|
target: dialog.element.querySelector("#helloPanel"),
|
||||||
props: {
|
props: {
|
||||||
name: this.i18n.name,
|
app: this.app,
|
||||||
i18n: this.i18n.hello
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -240,10 +249,10 @@ export default class PluginSample extends Plugin {
|
||||||
});
|
});
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
icon: "iconInfo",
|
icon: "iconInfo",
|
||||||
label: "Dialog",
|
label: "Dialog(open help first)",
|
||||||
accelerator: this.commands[0].customHotkey,
|
accelerator: this.commands[0].customHotkey,
|
||||||
click: () => {
|
click: () => {
|
||||||
this.showDialog()
|
this.showDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!this.isMobile) {
|
if (!this.isMobile) {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
min: number;
|
min: number;
|
||||||
max: number;
|
max: number;
|
||||||
step: 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();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
@ -76,15 +76,17 @@
|
||||||
</select>
|
</select>
|
||||||
{:else if type == "slider"}
|
{:else if type == "slider"}
|
||||||
<!-- Slider -->
|
<!-- Slider -->
|
||||||
<input
|
<div class="b3-tooltips b3-tooltips__n" aria-label={settingValue}>
|
||||||
class="b3-slider fn__size200"
|
<input
|
||||||
id="fontSize"
|
class="b3-slider fn__size200"
|
||||||
min="{slider.min}"
|
id="fontSize"
|
||||||
max="{slider.max}"
|
min={slider.min}
|
||||||
step="{slider.step}"
|
max={slider.max}
|
||||||
type="range"
|
step={slider.step}
|
||||||
bind:value={settingValue}
|
type="range"
|
||||||
on:change={changed}
|
bind:value={settingValue}
|
||||||
/>
|
on:change={changed}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</label>
|
</label>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue