@@ -67,49 +67,61 @@ window.Vaadin.Flow.tinymceConnector = {
67
67
if ( ! enabled ) {
68
68
baseconfig [ 'readonly' ] = true ;
69
69
}
70
+
70
71
71
72
baseconfig [ 'setup' ] = function ( ed ) {
72
- c . $connector . editor = ed ;
73
+ c . $connector . editor = ed ;
73
74
74
- ed . on ( 'change' , function ( e ) {
75
+ ed . on ( 'init' , e => {
76
+ if ( c . $connector . isInDialog ( ) ) {
77
+ // This is inside a shadowroot (Dialog in Vaadin)
78
+ // and needs some hacks to make this nagigateable with keyboard
79
+ if ( c . tabIndex < 0 ) {
80
+ // make the wrapping element also focusable
81
+ c . setAttribute ( "tabindex" , 0 ) ;
82
+ }
83
+ // on focus to wrapping element, pass forward to editor
84
+ c . addEventListener ( "focus" , e => {
85
+ ed . focus ( ) ;
86
+ } ) ;
87
+ // Move aux element as child from body to element to fix menus in modal Dialog
88
+ const aux = document . getElementsByClassName ( 'tox-tinymce-aux' ) [ 0 ] ;
89
+ aux . parentElement . removeChild ( aux ) ;
90
+ // Fix to allow menu grow outside Dialog
91
+ aux . style . position = 'absolute' ;
92
+ c . appendChild ( aux ) ;
93
+ }
94
+ } ) ;
95
+
96
+ ed . on ( 'change' , function ( e ) {
75
97
// console.log("TMCE change");
76
98
const event = new Event ( "tchange" ) ;
77
99
event . htmlString = ed . getContent ( ) ;
78
100
c . dispatchEvent ( event ) ;
79
- } ) ;
80
- ed . on ( 'blur' , function ( e ) {
101
+ } ) ;
102
+ ed . on ( 'blur' , function ( e ) {
81
103
//console.log("TMCE blur");
82
104
const event = new Event ( "tblur" ) ;
83
105
c . dispatchEvent ( event ) ;
84
- } ) ;
85
- ed . on ( 'focus' , function ( e ) {
106
+ } ) ;
107
+ ed . on ( 'focus' , function ( e ) {
86
108
//console.log("TMCE focus");
87
109
const event = new Event ( "tfocus" ) ;
88
110
c . dispatchEvent ( event ) ;
89
- } ) ;
111
+ } ) ;
90
112
91
- ed . on ( 'input' , function ( e ) {
113
+ ed . on ( 'input' , function ( e ) {
92
114
//console.log("TMCE input");
93
115
const event = new Event ( "tchange" ) ;
94
116
event . htmlString = ed . getContent ( ) ;
95
117
c . dispatchEvent ( event ) ;
96
- } ) ;
118
+ } ) ;
97
119
98
120
} ;
99
121
100
122
ta . innerHTML = initialContent ;
101
123
102
124
tinymce . init ( baseconfig ) ;
103
125
104
- // Move aux element as child to fix Dialog issues, TinyMCE is slow
105
- // to init, thus timeout needed
106
- setTimeout ( ( ) => {
107
- const aux = document . getElementsByClassName ( 'tox-tinymce-aux' ) [ 0 ] ;
108
- aux . parentElement . removeChild ( aux ) ;
109
- // Fix to allow menu grow outside Dialog
110
- aux . style . position = 'absolute' ;
111
- c . appendChild ( aux ) ;
112
- } , 500 ) ;
113
-
114
126
}
115
127
}
0 commit comments