@@ -14,13 +14,14 @@ import {
1414 nameContext ,
1515 toastContext ,
1616} from './context' ;
17- import './emoji-button' ;
1817import './icons/icon-loading' ;
1918import { msg } from '@lit/localize' ;
2019import type { ToastManager } from './lit-toast' ;
2120import baseStyles from './styles/base' ;
2221import varStyles from './styles/var' ;
2322import type { ConfigMapData } from './types' ;
23+ import './comment-editor' ;
24+ import type { CommentEditor } from './comment-editor' ;
2425
2526export class BaseForm extends LitElement {
2627 @consume ( { context : baseUrlContext } )
@@ -64,6 +65,8 @@ export class BaseForm extends LitElement {
6465
6566 textareaRef : Ref < HTMLTextAreaElement > = createRef < HTMLTextAreaElement > ( ) ;
6667
68+ editorRef : Ref < CommentEditor > = createRef < CommentEditor > ( ) ;
69+
6770 get customAccount ( ) {
6871 return JSON . parse (
6972 localStorage . getItem ( 'halo-comment-custom-account' ) || '{}'
@@ -168,14 +171,6 @@ export class BaseForm extends LitElement {
168171 target . style . height = `${ target . scrollHeight } px` ;
169172 }
170173
171- onEmojiSelect ( e : CustomEvent ) {
172- const data = e . detail ;
173- if ( this . textareaRef . value ) {
174- this . textareaRef . value . value += data . native ;
175- this . textareaRef . value . focus ( ) ;
176- }
177- }
178-
179174 onKeydown ( e : KeyboardEvent ) {
180175 if ( e . key === 'Enter' && ( e . metaKey || e . ctrlKey ) ) {
181176 const form = this . shadowRoot ?. querySelector ( 'form' ) ;
@@ -197,15 +192,7 @@ export class BaseForm extends LitElement {
197192 override render ( ) {
198193 return html `
199194 <for m class= "form" @submit = "${ this . onSubmit } " >
200- <textarea
201- class= "form__editor"
202- ${ ref ( this . textareaRef ) }
203- placeholder = ${ msg ( 'Write a comment' ) }
204- rows= "4"
205- name= "content"
206- required
207- @input = ${ this . onContentInput }
208- > </ textarea>
195+ <comment- edito r ${ ref ( this . editorRef ) } > </ comment- edito r>
209196
210197 ${
211198 ! this . currentUser && this . allowAnonymousComments
@@ -269,7 +256,6 @@ export class BaseForm extends LitElement {
269256 : ''
270257 }
271258
272- <emoji- butto n @emoji-select = ${ this . onEmojiSelect } > </ emoji- butto n>
273259 <butto n
274260 .disabled = ${ this . submitting }
275261 type= "submit"
@@ -299,8 +285,13 @@ export class BaseForm extends LitElement {
299285 }
300286
301287 private debouncedSubmit = debounce ( ( data : Record < string , unknown > ) => {
288+ const content = this . editorRef . value ?. editor ?. getHTML ( ) || '' ;
289+
302290 const event = new CustomEvent ( 'submit' , {
303- detail : data ,
291+ detail : {
292+ ...data ,
293+ content,
294+ } ,
304295 } ) ;
305296 this . dispatchEvent ( event ) ;
306297 } , 300 ) ;
@@ -327,10 +318,12 @@ export class BaseForm extends LitElement {
327318 resetForm ( ) {
328319 const form = this . shadowRoot ?. querySelector ( 'form' ) ;
329320 form ?. reset ( ) ;
321+ this . editorRef . value ?. reset ( ) ;
330322 }
331323
332324 setFocus ( ) {
333325 this . textareaRef . value ?. focus ( ) ;
326+ this . editorRef . value ?. setFocus ( ) ;
334327 }
335328
336329 static override styles = [
0 commit comments