Skip to content

Commit 38f3abd

Browse files
committed
setting
1 parent 5cfd0da commit 38f3abd

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

src/index.ts

+60-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
adaptHotkey,
99
getFrontend,
1010
getBackend,
11-
IModel
11+
IModel,
12+
Setting
1213
} from "siyuan";
1314
import "@/index.scss";
1415

@@ -129,6 +130,33 @@ export default class PluginSample extends Plugin {
129130
}
130131
});
131132

133+
const textareaElement = document.createElement("textarea");
134+
this.setting = new Setting({
135+
confirmCallback: () => {
136+
this.saveData(STORAGE_NAME, {readonlyText: textareaElement.value});
137+
}
138+
})
139+
this.setting.addItem({
140+
title: "Readonly text",
141+
createActionElement: () => {
142+
textareaElement.className = "b3-text-field fn__block";
143+
textareaElement.placeholder = "Readonly text in the menu";
144+
textareaElement.value = this.data[STORAGE_NAME].readonlyText;
145+
return textareaElement;
146+
},
147+
})
148+
const btnaElement = document.createElement("button");
149+
btnaElement.className = "b3-button b3-button--outline fn__flex-center";
150+
btnaElement.textContent = "Open";
151+
btnaElement.addEventListener("click", () => {
152+
window.open("https://github.com/siyuan-note/plugin-sample-vite-svelte")
153+
});
154+
this.setting.addItem({
155+
title: "Open plugin url",
156+
description: "Open plugin url in browser",
157+
actionElement: btnaElement,
158+
})
159+
132160
console.log(this.i18n.helloPlugin);
133161
}
134162

@@ -143,14 +171,17 @@ export default class PluginSample extends Plugin {
143171
console.log("onunload");
144172
}
145173

146-
openSetting(): void {
174+
/**
175+
* A custom setting pannel provided by svelte
176+
*/
177+
openDIYSetting(): void {
147178
let dialog = new Dialog({
148179
title: "SettingPannel",
149180
content: `<div id="SettingPanel"></div>`,
150181
width: "600px",
151182
destroyCallback: (options) => {
152183
console.log("destroyCallback", options);
153-
//You must destroy the component when the dialog is closed
184+
//You'd better destroy the component when the dialog is closed
154185
pannel.$destroy();
155186
}
156187
});
@@ -181,7 +212,6 @@ export default class PluginSample extends Plugin {
181212
content: `<div id="helloPanel" class="b3-dialog__content"></div>`,
182213
width: this.isMobile ? "92vw" : "720px",
183214
destroyCallback(options) {
184-
//Destroy the component when the dialog is closed
185215
// hello.$destroy();
186216
},
187217
});
@@ -364,9 +394,35 @@ export default class PluginSample extends Plugin {
364394
click: () => {
365395
this.eventBus.off("open-noneditableblock", this.eventBusLog);
366396
}
397+
}, {
398+
icon: "iconSelect",
399+
label: "On loaded-protyle",
400+
click: () => {
401+
this.eventBus.on("loaded-protyle", this.eventBusLog);
402+
}
403+
}, {
404+
icon: "iconClose",
405+
label: "Off loaded-protyle",
406+
click: () => {
407+
this.eventBus.off("loaded-protyle", this.eventBusLog);
408+
}
367409
}]
368410
});
369411
menu.addSeparator();
412+
menu.addItem({
413+
icon: "iconSettings",
414+
label: "Official Setting Dialog",
415+
click: () => {
416+
this.openSetting();
417+
}
418+
});
419+
menu.addItem({
420+
icon: "iconSettings",
421+
label: "A custom setting dialog (by svelte)",
422+
click: () => {
423+
this.openDIYSetting();
424+
}
425+
});
370426
menu.addItem({
371427
icon: "iconSparkles",
372428
label: this.data[STORAGE_NAME].readonlyText || "Readonly",

0 commit comments

Comments
 (0)