@@ -14,13 +14,14 @@ import {
14
14
nameContext ,
15
15
toastContext ,
16
16
} from './context' ;
17
- import './emoji-button' ;
18
17
import './icons/icon-loading' ;
19
18
import { msg } from '@lit/localize' ;
20
19
import type { ToastManager } from './lit-toast' ;
21
20
import baseStyles from './styles/base' ;
22
21
import varStyles from './styles/var' ;
23
22
import type { ConfigMapData } from './types' ;
23
+ import './comment-editor' ;
24
+ import type { CommentEditor } from './comment-editor' ;
24
25
25
26
export class BaseForm extends LitElement {
26
27
@consume ( { context : baseUrlContext } )
@@ -64,6 +65,8 @@ export class BaseForm extends LitElement {
64
65
65
66
textareaRef : Ref < HTMLTextAreaElement > = createRef < HTMLTextAreaElement > ( ) ;
66
67
68
+ editorRef : Ref < CommentEditor > = createRef < CommentEditor > ( ) ;
69
+
67
70
get customAccount ( ) {
68
71
return JSON . parse (
69
72
localStorage . getItem ( 'halo-comment-custom-account' ) || '{}'
@@ -168,14 +171,6 @@ export class BaseForm extends LitElement {
168
171
target . style . height = `${ target . scrollHeight } px` ;
169
172
}
170
173
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
-
179
174
onKeydown ( e : KeyboardEvent ) {
180
175
if ( e . key === 'Enter' && ( e . metaKey || e . ctrlKey ) ) {
181
176
const form = this . shadowRoot ?. querySelector ( 'form' ) ;
@@ -197,15 +192,7 @@ export class BaseForm extends LitElement {
197
192
override render ( ) {
198
193
return html `
199
194
<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>
209
196
210
197
${
211
198
! this . currentUser && this . allowAnonymousComments
@@ -269,7 +256,6 @@ export class BaseForm extends LitElement {
269
256
: ''
270
257
}
271
258
272
- <emoji- butto n @emoji-select = ${ this . onEmojiSelect } > </ emoji- butto n>
273
259
<butto n
274
260
.disabled = ${ this . submitting }
275
261
type= "submit"
@@ -299,8 +285,21 @@ export class BaseForm extends LitElement {
299
285
}
300
286
301
287
private debouncedSubmit = debounce ( ( data : Record < string , unknown > ) => {
288
+ const content = this . editorRef . value ?. editor ?. getHTML ( ) || '' ;
289
+ const characterCount =
290
+ this . editorRef . value ?. editor ?. storage . characterCount . characters ( ) ;
291
+
292
+ if ( ! characterCount ) {
293
+ this . toastManager ?. warn ( msg ( 'Please enter content' ) ) ;
294
+ this . editorRef . value ?. setFocus ( ) ;
295
+ return ;
296
+ }
297
+
302
298
const event = new CustomEvent ( 'submit' , {
303
- detail : data ,
299
+ detail : {
300
+ ...data ,
301
+ content,
302
+ } ,
304
303
} ) ;
305
304
this . dispatchEvent ( event ) ;
306
305
} , 300 ) ;
@@ -327,10 +326,12 @@ export class BaseForm extends LitElement {
327
326
resetForm ( ) {
328
327
const form = this . shadowRoot ?. querySelector ( 'form' ) ;
329
328
form ?. reset ( ) ;
329
+ this . editorRef . value ?. reset ( ) ;
330
330
}
331
331
332
332
setFocus ( ) {
333
333
this . textareaRef . value ?. focus ( ) ;
334
+ this . editorRef . value ?. setFocus ( ) ;
334
335
}
335
336
336
337
static override styles = [
0 commit comments