🐛 fix: 模板提供的 button 的 click 事件不生效; close #31
This commit is contained in:
parent
2c45caf80f
commit
8daa01aedb
5 changed files with 30 additions and 8 deletions
|
@ -382,7 +382,7 @@ export default class PluginSample extends Plugin {
|
||||||
let dialog = new Dialog({
|
let dialog = new Dialog({
|
||||||
title: "SettingPannel",
|
title: "SettingPannel",
|
||||||
content: `<div id="SettingPanel" style="height: 100%;"></div>`,
|
content: `<div id="SettingPanel" style="height: 100%;"></div>`,
|
||||||
width: "600px",
|
width: "800px",
|
||||||
destroyCallback: (options) => {
|
destroyCallback: (options) => {
|
||||||
console.log("destroyCallback", options);
|
console.log("destroyCallback", options);
|
||||||
//You'd better destroy the component when the dialog is closed
|
//You'd better destroy the component when the dialog is closed
|
||||||
|
|
|
@ -14,11 +14,16 @@
|
||||||
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
|
||||||
|
export let button: {
|
||||||
|
label: string;
|
||||||
|
callback: () => void;
|
||||||
|
} = { label: settingValue, callback: () => {} }; // Use it if type is button
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
function clicked() {
|
function click() {
|
||||||
dispatch("clicked");
|
button?.callback();
|
||||||
|
dispatch("click", { key: settingKey });
|
||||||
}
|
}
|
||||||
|
|
||||||
function changed() {
|
function changed() {
|
||||||
|
@ -66,9 +71,9 @@
|
||||||
<button
|
<button
|
||||||
class="b3-button b3-button--outline fn__flex-center fn__size200"
|
class="b3-button b3-button--outline fn__flex-center fn__size200"
|
||||||
id={settingKey}
|
id={settingKey}
|
||||||
on:click={clicked}
|
on:click={click}
|
||||||
>
|
>
|
||||||
{settingValue}
|
{button.label}
|
||||||
</button>
|
</button>
|
||||||
{:else if type === "select"}
|
{:else if type === "select"}
|
||||||
<!-- Dropdown select -->
|
<!-- Dropdown select -->
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Author : frostime
|
Author : frostime
|
||||||
Date : 2023-07-01 19:23:50
|
Date : 2023-07-01 19:23:50
|
||||||
FilePath : /src/libs/setting-panel.svelte
|
FilePath : /src/libs/setting-panel.svelte
|
||||||
LastEditTime : 2023-11-28 21:45:10
|
LastEditTime : 2024-04-27 16:46:49
|
||||||
Description :
|
Description :
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
@ -39,6 +39,7 @@
|
||||||
placeholder={item?.placeholder}
|
placeholder={item?.placeholder}
|
||||||
options={item?.options}
|
options={item?.options}
|
||||||
slider={item?.slider}
|
slider={item?.slider}
|
||||||
|
button={item?.button}
|
||||||
on:click={onClick}
|
on:click={onClick}
|
||||||
on:changed={onChanged}
|
on:changed={onChanged}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author : frostime
|
* @Author : frostime
|
||||||
* @Date : 2023-12-17 18:28:19
|
* @Date : 2023-12-17 18:28:19
|
||||||
* @FilePath : /src/libs/setting-utils.ts
|
* @FilePath : /src/libs/setting-utils.ts
|
||||||
* @LastEditTime : 2024-01-15 20:45:16
|
* @LastEditTime : 2024-04-27 16:38:09
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -329,5 +329,4 @@ export class SettingUtils {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { showMessage } from "siyuan";
|
||||||
import SettingPanel from "./libs/setting-panel.svelte";
|
import SettingPanel from "./libs/setting-panel.svelte";
|
||||||
|
|
||||||
let groups: string[] = ["🌈 Default"];
|
let groups: string[] = ["🌈 Default"];
|
||||||
|
@ -43,6 +44,19 @@
|
||||||
max: 100,
|
max: 100,
|
||||||
step: 1
|
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>) => {
|
const onChanged = ({ detail }: CustomEvent<ChangeEvent>) => {
|
||||||
if (detail.group === groups[0]) {
|
if (detail.group === groups[0]) {
|
||||||
// setting.set(detail.key, detail.value);
|
// 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>
|
</script>
|
||||||
|
@ -83,6 +99,7 @@
|
||||||
settingItems={SettingItems}
|
settingItems={SettingItems}
|
||||||
display={focusGroup === groups[0]}
|
display={focusGroup === groups[0]}
|
||||||
on:changed={onChanged}
|
on:changed={onChanged}
|
||||||
|
on:click={({ detail }) => { console.debug("Click:", detail.key); }}
|
||||||
>
|
>
|
||||||
<div class="fn__flex b3-label">
|
<div class="fn__flex b3-label">
|
||||||
💡 This is our default settings.
|
💡 This is our default settings.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue