11import { Component } from './component' ;
22import { getLoading , htmlToDom } from '../services/dom' ;
3+ import { buildForInput } from "../wysiwyg/config" ;
34
45export class PageComments extends Component {
56
@@ -21,6 +22,11 @@ export class PageComments extends Component {
2122 this . hideFormButton = this . $refs . hideFormButton ;
2223 this . removeReplyToButton = this . $refs . removeReplyToButton ;
2324
25+ // WYSIWYG options
26+ this . wysiwygLanguage = this . $opts . wysiwygLanguage ;
27+ this . wysiwygTextDirection = this . $opts . wysiwygTextDirection ;
28+ this . wysiwygEditor = null ;
29+
2430 // Translations
2531 this . createdText = this . $opts . createdText ;
2632 this . countText = this . $opts . countText ;
@@ -96,9 +102,7 @@ export class PageComments extends Component {
96102 this . formContainer . toggleAttribute ( 'hidden' , false ) ;
97103 this . addButtonContainer . toggleAttribute ( 'hidden' , true ) ;
98104 this . formContainer . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } ) ;
99- setTimeout ( ( ) => {
100- this . formInput . focus ( ) ;
101- } , 100 ) ;
105+ this . loadEditor ( ) ;
102106 }
103107
104108 hideForm ( ) {
@@ -112,6 +116,26 @@ export class PageComments extends Component {
112116 this . addButtonContainer . toggleAttribute ( 'hidden' , false ) ;
113117 }
114118
119+ loadEditor ( ) {
120+ if ( this . wysiwygEditor ) {
121+ return ;
122+ }
123+
124+ const config = buildForInput ( {
125+ language : this . wysiwygLanguage ,
126+ containerElement : this . formInput ,
127+ darkMode : document . documentElement . classList . contains ( 'dark-mode' ) ,
128+ textDirection : this . wysiwygTextDirection ,
129+ translations : { } ,
130+ translationMap : window . editor_translations ,
131+ } ) ;
132+
133+ window . tinymce . init ( config ) . then ( editors => {
134+ this . wysiwygEditor = editors [ 0 ] ;
135+ this . wysiwygEditor . focus ( ) ;
136+ } ) ;
137+ }
138+
115139 getCommentCount ( ) {
116140 return this . container . querySelectorAll ( '[component="page-comment"]' ) . length ;
117141 }
0 commit comments