@@ -11,7 +11,7 @@ import {
11
11
IModel ,
12
12
Setting ,
13
13
fetchPost ,
14
- Protyle , openWindow
14
+ Protyle , openWindow , IOperation
15
15
} from "siyuan" ;
16
16
import "@/index.scss" ;
17
17
@@ -68,7 +68,7 @@ export default class PluginSample extends Plugin {
68
68
} ) ;
69
69
70
70
const statusIconTemp = document . createElement ( "template" ) ;
71
- statusIconTemp . innerHTML = `<div class="toolbar__item b3-tooltips b3-tooltips__w " aria-label="Remove plugin-sample Data">
71
+ statusIconTemp . innerHTML = `<div class="toolbar__item ariaLabel " aria-label="Remove plugin-sample Data">
72
72
<svg>
73
73
<use xlink:href="#iconTrashcan"></use>
74
74
</svg>
@@ -85,27 +85,6 @@ export default class PluginSample extends Plugin {
85
85
element : statusIconTemp . content . firstElementChild as HTMLElement ,
86
86
} ) ;
87
87
88
- let tabDiv = document . createElement ( "div" ) ;
89
- new HelloExample ( {
90
- target : tabDiv ,
91
- props : {
92
- app : this . app ,
93
- }
94
- } ) ;
95
- this . customTab = this . addTab ( {
96
- type : TAB_TYPE ,
97
- init ( ) {
98
- this . element . appendChild ( tabDiv ) ;
99
- console . log ( this . element ) ;
100
- } ,
101
- beforeDestroy ( ) {
102
- console . log ( "before destroy tab:" , TAB_TYPE ) ;
103
- } ,
104
- destroy ( ) {
105
- console . log ( "destroy tab:" , TAB_TYPE ) ;
106
- }
107
- } ) ;
108
-
109
88
this . addCommand ( {
110
89
langKey : "showDialog" ,
111
90
hotkey : "⇧⌘O" ,
@@ -244,6 +223,26 @@ export default class PluginSample extends Plugin {
244
223
// this.loadData(STORAGE_NAME);
245
224
this . settingUtils . load ( ) ;
246
225
console . log ( `frontend: ${ getFrontend ( ) } ; backend: ${ getBackend ( ) } ` ) ;
226
+ let tabDiv = document . createElement ( "div" ) ;
227
+ new HelloExample ( {
228
+ target : tabDiv ,
229
+ props : {
230
+ app : this . app ,
231
+ }
232
+ } ) ;
233
+ this . customTab = this . addTab ( {
234
+ type : TAB_TYPE ,
235
+ init ( ) {
236
+ this . element . appendChild ( tabDiv ) ;
237
+ console . log ( this . element ) ;
238
+ } ,
239
+ beforeDestroy ( ) {
240
+ console . log ( "before destroy tab:" , TAB_TYPE ) ;
241
+ } ,
242
+ destroy ( ) {
243
+ console . log ( "destroy tab:" , TAB_TYPE ) ;
244
+ }
245
+ } ) ;
247
246
}
248
247
249
248
async onunload ( ) {
@@ -272,19 +271,38 @@ export default class PluginSample extends Plugin {
272
271
} ) ;
273
272
}
274
273
274
+ private eventBusPaste ( event : any ) {
275
+ // 如果需异步处理请调用 preventDefault, 否则会进行默认处理
276
+ event . preventDefault ( ) ;
277
+ // 如果使用了 preventDefault,必须调用 resolve,否则程序会卡死
278
+ event . detail . resolve ( {
279
+ textPlain : event . detail . textPlain . trim ( ) ,
280
+ } ) ;
281
+ }
282
+
275
283
private eventBusLog ( { detail } : any ) {
276
284
console . log ( detail ) ;
277
285
}
278
286
279
287
private blockIconEvent ( { detail } : any ) {
280
- const ids : string [ ] = [ ] ;
281
- detail . blockElements . forEach ( ( item : HTMLElement ) => {
282
- ids . push ( item . getAttribute ( "data-node-id" ) ) ;
283
- } ) ;
284
288
detail . menu . addItem ( {
285
289
iconHTML : "" ,
286
- type : "readonly" ,
287
- label : "IDs<br>" + ids . join ( "<br>" ) ,
290
+ label : this . i18n . removeSpace ,
291
+ click : ( ) => {
292
+ const doOperations : IOperation [ ] = [ ] ;
293
+ detail . blockElements . forEach ( ( item : HTMLElement ) => {
294
+ const editElement = item . querySelector ( '[contenteditable="true"]' ) ;
295
+ if ( editElement ) {
296
+ editElement . textContent = editElement . textContent . replace ( / / g, "" ) ;
297
+ doOperations . push ( {
298
+ id : item . dataset . nodeId ,
299
+ data : item . outerHTML ,
300
+ action : "update"
301
+ } ) ;
302
+ }
303
+ } ) ;
304
+ detail . protyle . getInstance ( ) . transaction ( doOperations ) ;
305
+ }
288
306
} ) ;
289
307
}
290
308
@@ -488,9 +506,15 @@ export default class PluginSample extends Plugin {
488
506
}
489
507
} , {
490
508
icon : "iconSelect" ,
491
- label : "On loaded-protyle" ,
509
+ label : "On loaded-protyle-static " ,
492
510
click : ( ) => {
493
- this . eventBus . on ( "loaded-protyle" , this . eventBusLog ) ;
511
+ this . eventBus . on ( "loaded-protyle-static" , this . eventBusLog ) ;
512
+ }
513
+ } , {
514
+ icon : "iconClose" ,
515
+ label : "Off loaded-protyle-static" ,
516
+ click : ( ) => {
517
+ this . eventBus . off ( "loaded-protyle-static" , this . eventBusLog ) ;
494
518
}
495
519
} , {
496
520
icon : "iconSelect" ,
@@ -516,11 +540,17 @@ export default class PluginSample extends Plugin {
516
540
click : ( ) => {
517
541
this . eventBus . off ( "destroy-protyle" , this . eventBusLog ) ;
518
542
}
543
+ } , {
544
+ icon : "iconSelect" ,
545
+ label : "On open-menu-doctree" ,
546
+ click : ( ) => {
547
+ this . eventBus . on ( "open-menu-doctree" , this . eventBusLog ) ;
548
+ }
519
549
} , {
520
550
icon : "iconClose" ,
521
- label : "Off loaded-protyle " ,
551
+ label : "Off open-menu-doctree " ,
522
552
click : ( ) => {
523
- this . eventBus . off ( "loaded-protyle " , this . eventBusLog ) ;
553
+ this . eventBus . off ( "open-menu-doctree " , this . eventBusLog ) ;
524
554
}
525
555
} , {
526
556
icon : "iconSelect" ,
@@ -630,6 +660,18 @@ export default class PluginSample extends Plugin {
630
660
click : ( ) => {
631
661
this . eventBus . off ( "input-search" , this . eventBusLog ) ;
632
662
}
663
+ } , {
664
+ icon : "iconSelect" ,
665
+ label : "On paste" ,
666
+ click : ( ) => {
667
+ this . eventBus . on ( "paste" , this . eventBusPaste ) ;
668
+ }
669
+ } , {
670
+ icon : "iconClose" ,
671
+ label : "Off paste" ,
672
+ click : ( ) => {
673
+ this . eventBus . off ( "paste" , this . eventBusPaste ) ;
674
+ }
633
675
} , {
634
676
icon : "iconSelect" ,
635
677
label : "On open-siyuan-url-plugin" ,
0 commit comments