From 925d5c5aac623edefbd01343b0891e574fb75d55 Mon Sep 17 00:00:00 2001 From: frostime Date: Sat, 20 May 2023 11:09:27 +0800 Subject: [PATCH] feat: svelte example for setting pannel --- src/index.ts | 44 +++++++++++------ src/libs/setting-item.svelte | 90 +++++++++++++++++++++++++++++++++++ src/libs/setting-panel.svelte | 74 ++++++++++++++++++++++++++++ src/siyuan.d.ts | 23 +-------- src/sy-dtype.d.ts | 2 +- 5 files changed, 195 insertions(+), 38 deletions(-) create mode 100644 src/libs/setting-item.svelte create mode 100644 src/libs/setting-panel.svelte diff --git a/src/index.ts b/src/index.ts index 12844f3..2940cfd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,10 @@ * Copyright (c) 2023 frostime. All rights reserved. * https://github.com/frostime/sy-plugin-template-vite */ -import { Plugin, showMessage, Dialog } from "siyuan" -import Hello from "./hello.svelte" -import "./index.scss" +import { Plugin, showMessage, Dialog } from "siyuan"; +import Hello from "./hello.svelte"; +import SettingPannel from "./libs/setting-panel.svelte"; +import "./index.scss"; export default class SamplePlugin extends Plugin { @@ -15,22 +16,35 @@ export default class SamplePlugin extends Plugin { { icon: "iconEmoji", "title": "Hello SiYuan", - "callback": () => { - let dialog = new Dialog({ - title: "Hello World", - content: `
`, - }); - new Hello({ - target: dialog.element.querySelector("#helloPanel"), - props: { - name: this.i18n.name, - } - }); - } + "callback": () => this.openHelloDialog() } ) } + openSetting(): void { + let dialog = new Dialog({ + title: "SettingPannel", + content: `
`, + width: "600px" + }); + new SettingPannel({ + target: dialog.element.querySelector("#SettingPanel"), + }); + } + + private openHelloDialog() { + let dialog = new Dialog({ + title: "Hello World", + content: `
`, + }); + new Hello({ + target: dialog.element.querySelector("#helloPanel"), + props: { + name: this.i18n.name, + } + }); + } + async onunload() { showMessage("Goodbye World"); console.log("onunload"); diff --git a/src/libs/setting-item.svelte b/src/libs/setting-item.svelte new file mode 100644 index 0000000..74e08b5 --- /dev/null +++ b/src/libs/setting-item.svelte @@ -0,0 +1,90 @@ + + + diff --git a/src/libs/setting-panel.svelte b/src/libs/setting-panel.svelte new file mode 100644 index 0000000..cdc9f4c --- /dev/null +++ b/src/libs/setting-panel.svelte @@ -0,0 +1,74 @@ + + + + +
+ { + showMessage(`Checkbox changed: ${event.detail.key} = ${event.detail.value}`); + }} + /> + { + showMessage(`Input changed: ${event.detail.key} = ${event.detail.value}`); + }} + /> + { + showMessage("Button clicked"); + }} + /> + { + showMessage(`Select changed: ${event.detail.key} = ${event.detail.value}`); + }} + /> + { + showMessage(`Slide changed: ${event.detail.key} = ${event.detail.value}`); + }} + /> +
\ No newline at end of file diff --git a/src/siyuan.d.ts b/src/siyuan.d.ts index b197cbc..fbca339 100644 --- a/src/siyuan.d.ts +++ b/src/siyuan.d.ts @@ -1,26 +1,5 @@ /* - * Copyright (c) 2023, Terwer . All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Terwer designates this - * particular file as subject to the "Classpath" exception as provided - * by Terwer in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com - * or visit www.terwer.space if you need additional information or have any - * questions. + * Copyright (c) 2023, SiYuan, frostime, Terwer . All rights reserved. */ declare module "siyuan" { diff --git a/src/sy-dtype.d.ts b/src/sy-dtype.d.ts index 0be02f9..0c3b465 100644 --- a/src/sy-dtype.d.ts +++ b/src/sy-dtype.d.ts @@ -4,7 +4,7 @@ */ /** - * 思源内部常用的数据格式 + * Frequently used data structures in SiYuan */ declare module "sy-dtype" {