11import { Component } from './component' ;
22import { getLoading , htmlToDom } from '../services/dom' ;
3- import { buildForInput } from '../wysiwyg-tinymce/config' ;
43import { Tabs } from "./tabs" ;
54import { PageCommentReference } from "./page-comment-reference" ;
65import { scrollAndHighlightElement } from "../services/util" ;
76import { PageCommentArchiveEventData , PageCommentReplyEventData } from "./page-comment" ;
7+ import { el } from "../wysiwyg/utils/dom" ;
8+ import { SimpleWysiwygEditorInterface } from "../wysiwyg" ;
89
910export class PageComments extends Component {
1011
@@ -28,9 +29,8 @@ export class PageComments extends Component {
2829 private hideFormButton ! : HTMLElement ;
2930 private removeReplyToButton ! : HTMLElement ;
3031 private removeReferenceButton ! : HTMLElement ;
31- private wysiwygLanguage ! : string ;
3232 private wysiwygTextDirection ! : string ;
33- private wysiwygEditor : any = null ;
33+ private wysiwygEditor : SimpleWysiwygEditorInterface | null = null ;
3434 private createdText ! : string ;
3535 private countText ! : string ;
3636 private archivedCountText ! : string ;
@@ -63,7 +63,6 @@ export class PageComments extends Component {
6363 this . removeReferenceButton = this . $refs . removeReferenceButton ;
6464
6565 // WYSIWYG options
66- this . wysiwygLanguage = this . $opts . wysiwygLanguage ;
6766 this . wysiwygTextDirection = this . $opts . wysiwygTextDirection ;
6867
6968 // Translations
@@ -107,7 +106,7 @@ export class PageComments extends Component {
107106 }
108107 }
109108
110- protected saveComment ( event : SubmitEvent ) : void {
109+ protected async saveComment ( event : SubmitEvent ) : Promise < void > {
111110 event . preventDefault ( ) ;
112111 event . stopPropagation ( ) ;
113112
@@ -117,7 +116,7 @@ export class PageComments extends Component {
117116 this . form . toggleAttribute ( 'hidden' , true ) ;
118117
119118 const reqData = {
120- html : this . wysiwygEditor . getContent ( ) ,
119+ html : ( await this . wysiwygEditor ?. getContentAsHtml ( ) ) || '' ,
121120 parent_id : this . parentId || null ,
122121 content_ref : this . contentReference ,
123122 } ;
@@ -189,27 +188,25 @@ export class PageComments extends Component {
189188 this . addButtonContainer . toggleAttribute ( 'hidden' , false ) ;
190189 }
191190
192- protected loadEditor ( ) : void {
191+ protected async loadEditor ( ) : Promise < void > {
193192 if ( this . wysiwygEditor ) {
194193 this . wysiwygEditor . focus ( ) ;
195194 return ;
196195 }
197196
198- const config = buildForInput ( {
199- language : this . wysiwygLanguage ,
200- containerElement : this . formInput ,
197+ type WysiwygModule = typeof import ( '../wysiwyg' ) ;
198+ const wysiwygModule = ( await window . importVersioned ( 'wysiwyg' ) ) as WysiwygModule ;
199+ const container = el ( 'div' , { class : 'comment-editor-container' } ) ;
200+ this . formInput . parentElement ?. appendChild ( container ) ;
201+ this . formInput . hidden = true ;
202+
203+ this . wysiwygEditor = wysiwygModule . createBasicEditorInstance ( container as HTMLElement , '<p></p>' , {
201204 darkMode : document . documentElement . classList . contains ( 'dark-mode' ) ,
202205 textDirection : this . wysiwygTextDirection ,
203- drawioUrl : '' ,
204- pageId : 0 ,
205- translations : { } ,
206- translationMap : ( window as unknown as Record < string , Object > ) . editor_translations ,
206+ translations : ( window as unknown as Record < string , Object > ) . editor_translations ,
207207 } ) ;
208208
209- ( window as unknown as { tinymce : { init : ( arg0 : Object ) => Promise < any > } } ) . tinymce . init ( config ) . then ( editors => {
210- this . wysiwygEditor = editors [ 0 ] ;
211- setTimeout ( ( ) => this . wysiwygEditor . focus ( ) , 50 ) ;
212- } ) ;
209+ this . wysiwygEditor . focus ( ) ;
213210 }
214211
215212 protected removeEditor ( ) : void {
0 commit comments