dialog use protyle
This commit is contained in:
parent
22c27c0542
commit
73070a56fd
2 changed files with 33 additions and 53 deletions
|
@ -1,61 +1,49 @@
|
||||||
<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;
|
let time: string = "";
|
||||||
export let i18n: any;
|
let ver: string;
|
||||||
|
|
||||||
let time;
|
let divProtyle: HTMLDivElement;
|
||||||
let ver;
|
let protyle: any;
|
||||||
|
let blockID: string = '';
|
||||||
let intv1 = setInterval(async () => {
|
|
||||||
time = new Date();
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
time = new Date();
|
|
||||||
ver = await version();
|
ver = await version();
|
||||||
|
fetchPost("/api/system/currentTime", {}, (response) => {
|
||||||
|
time = new Date(response.data).toString();
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
protyle = new Protyle(this.app, divProtyle, {
|
||||||
|
blockId: blockID,
|
||||||
|
mode: "preview"
|
||||||
|
});
|
||||||
|
}
|
||||||
</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>
|
|
||||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -83,11 +83,7 @@ export default class PluginSample extends Plugin {
|
||||||
|
|
||||||
let tabDiv = document.createElement("div");
|
let tabDiv = document.createElement("div");
|
||||||
new HelloExample({
|
new HelloExample({
|
||||||
target: tabDiv,
|
target: tabDiv
|
||||||
props: {
|
|
||||||
name: this.i18n.name,
|
|
||||||
i18n: this.i18n.hello
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.customTab = this.addTab({
|
this.customTab = this.addTab({
|
||||||
type: TAB_TYPE,
|
type: TAB_TYPE,
|
||||||
|
@ -236,12 +232,8 @@ 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: {
|
|
||||||
name: this.i18n.name,
|
|
||||||
i18n: this.i18n.hello
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue