🐛 fix: 模板提供的 button 的 click 事件不生效; close #31

This commit is contained in:
frostime 2024-04-27 16:55:46 +08:00
parent 2c45caf80f
commit 8daa01aedb
5 changed files with 30 additions and 8 deletions

View file

@ -382,7 +382,7 @@ export default class PluginSample extends Plugin {
let dialog = new Dialog({
title: "SettingPannel",
content: `<div id="SettingPanel" style="height: 100%;"></div>`,
width: "600px",
width: "800px",
destroyCallback: (options) => {
console.log("destroyCallback", options);
//You'd better destroy the component when the dialog is closed

View file

@ -14,11 +14,16 @@
max: number;
step: number;
} = { min: 0, max: 100, step: 1 }; // Use it if type is slider
export let button: {
label: string;
callback: () => void;
} = { label: settingValue, callback: () => {} }; // Use it if type is button
const dispatch = createEventDispatcher();
function clicked() {
dispatch("clicked");
function click() {
button?.callback();
dispatch("click", { key: settingKey });
}
function changed() {
@ -66,9 +71,9 @@
<button
class="b3-button b3-button--outline fn__flex-center fn__size200"
id={settingKey}
on:click={clicked}
on:click={click}
>
{settingValue}
{button.label}
</button>
{:else if type === "select"}
<!-- Dropdown select -->

View file

@ -3,7 +3,7 @@
Author : frostime
Date : 2023-07-01 19:23:50
FilePath : /src/libs/setting-panel.svelte
LastEditTime : 2023-11-28 21:45:10
LastEditTime : 2024-04-27 16:46:49
Description :
-->
<script lang="ts">
@ -39,6 +39,7 @@
placeholder={item?.placeholder}
options={item?.options}
slider={item?.slider}
button={item?.button}
on:click={onClick}
on:changed={onChanged}
/>

View file

@ -3,7 +3,7 @@
* @Author : frostime
* @Date : 2023-12-17 18:28:19
* @FilePath : /src/libs/setting-utils.ts
* @LastEditTime : 2024-01-15 20:45:16
* @LastEditTime : 2024-04-27 16:38:09
* @Description :
*/
@ -329,5 +329,4 @@ export class SettingUtils {
break;
}
}
}

View file

@ -1,4 +1,5 @@
<script lang="ts">
import { showMessage } from "siyuan";
import SettingPanel from "./libs/setting-panel.svelte";
let groups: string[] = ["🌈 Default"];
@ -43,6 +44,19 @@
max: 100,
step: 1
}
},
{
type: 'button',
title: 'button',
description: 'This is a button',
key: 'e',
value: 'Click Button',
button: {
label: 'Click Me',
callback: () => {
showMessage('Hello, world!');
}
}
}
];
@ -56,6 +70,8 @@
const onChanged = ({ detail }: CustomEvent<ChangeEvent>) => {
if (detail.group === groups[0]) {
// setting.set(detail.key, detail.value);
//Please add your code here
//Udpate the plugins setting data, don't forget to call plugin.save() for data persistence
}
};
</script>
@ -83,6 +99,7 @@
settingItems={SettingItems}
display={focusGroup === groups[0]}
on:changed={onChanged}
on:click={({ detail }) => { console.debug("Click:", detail.key); }}
>
<div class="fn__flex b3-label">
💡 This is our default settings.