8
8
adaptHotkey ,
9
9
getFrontend ,
10
10
getBackend ,
11
- IModel
11
+ IModel ,
12
+ Setting
12
13
} from "siyuan" ;
13
14
import "@/index.scss" ;
14
15
@@ -129,6 +130,33 @@ export default class PluginSample extends Plugin {
129
130
}
130
131
} ) ;
131
132
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
+
132
160
console . log ( this . i18n . helloPlugin ) ;
133
161
}
134
162
@@ -143,14 +171,17 @@ export default class PluginSample extends Plugin {
143
171
console . log ( "onunload" ) ;
144
172
}
145
173
146
- openSetting ( ) : void {
174
+ /**
175
+ * A custom setting pannel provided by svelte
176
+ */
177
+ openDIYSetting ( ) : void {
147
178
let dialog = new Dialog ( {
148
179
title : "SettingPannel" ,
149
180
content : `<div id="SettingPanel"></div>` ,
150
181
width : "600px" ,
151
182
destroyCallback : ( options ) => {
152
183
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
154
185
pannel . $destroy ( ) ;
155
186
}
156
187
} ) ;
@@ -181,7 +212,6 @@ export default class PluginSample extends Plugin {
181
212
content : `<div id="helloPanel" class="b3-dialog__content"></div>` ,
182
213
width : this . isMobile ? "92vw" : "720px" ,
183
214
destroyCallback ( options ) {
184
- //Destroy the component when the dialog is closed
185
215
// hello.$destroy();
186
216
} ,
187
217
} ) ;
@@ -364,9 +394,35 @@ export default class PluginSample extends Plugin {
364
394
click : ( ) => {
365
395
this . eventBus . off ( "open-noneditableblock" , this . eventBusLog ) ;
366
396
}
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
+ }
367
409
} ]
368
410
} ) ;
369
411
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
+ } ) ;
370
426
menu . addItem ( {
371
427
icon : "iconSparkles" ,
372
428
label : this . data [ STORAGE_NAME ] . readonlyText || "Readonly" ,
0 commit comments