mirror of
https://github.com/siyuan-note/plugin-sample-vite-svelte.git
synced 2025-06-08 10:56:01 +00:00
Must destroy svelte
This commit is contained in:
parent
925d5c5aac
commit
aba6dfd544
3 changed files with 59 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { version } from "./api";
|
import { version } from "./api";
|
||||||
|
import { showMessage } from "siyuan";
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
|
||||||
let time;
|
let time;
|
||||||
|
@ -21,6 +22,14 @@
|
||||||
time = new Date();
|
time = new Date();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
setInterval(async () => {
|
||||||
|
ver = await version();
|
||||||
|
showMessage(
|
||||||
|
`Hello ${name} v${ver}`,
|
||||||
|
5000
|
||||||
|
);
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="hello">
|
<div id="hello">
|
||||||
|
|
22
src/index.ts
22
src/index.ts
|
@ -9,6 +9,10 @@ import "./index.scss";
|
||||||
|
|
||||||
export default class SamplePlugin extends Plugin {
|
export default class SamplePlugin extends Plugin {
|
||||||
|
|
||||||
|
counter: { [key: string]: number } = {
|
||||||
|
hello: 0,
|
||||||
|
};
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
console.log("onload");
|
console.log("onload");
|
||||||
showMessage("Hello World");
|
showMessage("Hello World");
|
||||||
|
@ -25,22 +29,32 @@ export default class SamplePlugin extends Plugin {
|
||||||
let dialog = new Dialog({
|
let dialog = new Dialog({
|
||||||
title: "SettingPannel",
|
title: "SettingPannel",
|
||||||
content: `<div id="SettingPanel"></div>`,
|
content: `<div id="SettingPanel"></div>`,
|
||||||
width: "600px"
|
width: "600px",
|
||||||
|
destroyCallback: (options) => {
|
||||||
|
console.log("destroyCallback", options);
|
||||||
|
//You must destroy the component when the dialog is closed
|
||||||
|
pannel.$destroy();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
new SettingPannel({
|
let pannel = new SettingPannel({
|
||||||
target: dialog.element.querySelector("#SettingPanel"),
|
target: dialog.element.querySelector("#SettingPanel"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private openHelloDialog() {
|
private openHelloDialog() {
|
||||||
|
this.counter.hello++;
|
||||||
let dialog = new Dialog({
|
let dialog = new Dialog({
|
||||||
title: "Hello World",
|
title: "Hello World",
|
||||||
content: `<div id="helloPanel"></div>`,
|
content: `<div id="helloPanel"></div>`,
|
||||||
|
destroyCallback(options) {
|
||||||
|
//You must destroy the component when the dialog is closed
|
||||||
|
hello.$destroy();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
new Hello({
|
let hello = new Hello({
|
||||||
target: dialog.element.querySelector("#helloPanel"),
|
target: dialog.element.querySelector("#helloPanel"),
|
||||||
props: {
|
props: {
|
||||||
name: this.i18n.name,
|
name: `[${this.counter.hello}]${this.i18n.name}`,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
<script>
|
<script>
|
||||||
import { } from "os";
|
|
||||||
import SettingItem from "./setting-item.svelte";
|
import SettingItem from "./setting-item.svelte";
|
||||||
import { showMessage } from "siyuan";
|
import { showMessage } from "siyuan";
|
||||||
|
import { onMount, onDestroy } from 'svelte';
|
||||||
|
onMount(() => {
|
||||||
|
showMessage("Setting panel opened");
|
||||||
|
});
|
||||||
|
onDestroy(() => {
|
||||||
|
showMessage("Setting panel closed");
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
@ -10,6 +16,17 @@ with the same UI style in SiYuan
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div class="config__tab-container">
|
<div class="config__tab-container">
|
||||||
|
<div data-type="Header" class="fn__flex b3-label">
|
||||||
|
<div class="fn_flex-1">
|
||||||
|
<h4>This setting panel is provided by a svelte component</h4>
|
||||||
|
<div class="b3-label__text">
|
||||||
|
<span class="fn__flex-1">
|
||||||
|
See:
|
||||||
|
<pre style="display: inline">/lib/setting-pannel.svelte</pre>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<SettingItem
|
<SettingItem
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
title="Checkbox"
|
title="Checkbox"
|
||||||
|
@ -17,7 +34,9 @@ with the same UI style in SiYuan
|
||||||
settingKey="Checkbox"
|
settingKey="Checkbox"
|
||||||
settingValue={true}
|
settingValue={true}
|
||||||
on:changed={(event) => {
|
on:changed={(event) => {
|
||||||
showMessage(`Checkbox changed: ${event.detail.key} = ${event.detail.value}`);
|
showMessage(
|
||||||
|
`Checkbox changed: ${event.detail.key} = ${event.detail.value}`
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<SettingItem
|
<SettingItem
|
||||||
|
@ -28,7 +47,9 @@ with the same UI style in SiYuan
|
||||||
settingValue=""
|
settingValue=""
|
||||||
placeholder="Input something"
|
placeholder="Input something"
|
||||||
on:changed={(event) => {
|
on:changed={(event) => {
|
||||||
showMessage(`Input changed: ${event.detail.key} = ${event.detail.value}`);
|
showMessage(
|
||||||
|
`Input changed: ${event.detail.key} = ${event.detail.value}`
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<SettingItem
|
<SettingItem
|
||||||
|
@ -53,7 +74,9 @@ with the same UI style in SiYuan
|
||||||
right: "Right",
|
right: "Right",
|
||||||
}}
|
}}
|
||||||
on:changed={(event) => {
|
on:changed={(event) => {
|
||||||
showMessage(`Select changed: ${event.detail.key} = ${event.detail.value}`);
|
showMessage(
|
||||||
|
`Select changed: ${event.detail.key} = ${event.detail.value}`
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<SettingItem
|
<SettingItem
|
||||||
|
@ -68,7 +91,9 @@ with the same UI style in SiYuan
|
||||||
step: 1,
|
step: 1,
|
||||||
}}
|
}}
|
||||||
on:changed={(event) => {
|
on:changed={(event) => {
|
||||||
showMessage(`Slide changed: ${event.detail.key} = ${event.detail.value}`);
|
showMessage(
|
||||||
|
`Slide changed: ${event.detail.key} = ${event.detail.value}`
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
Loading…
Add table
Add a link
Reference in a new issue