@@ -6,10 +6,8 @@ import { repeat } from 'lit/directives/repeat.js';
66import './emoji-button' ;
77import contentStyles from './styles/content.css?inline' ;
88import './comment-editor-skeleton' ;
9- import { consume } from '@lit/context' ;
10- import { configMapDataContext } from './context' ;
9+ import { property } from 'lit/decorators.js' ;
1110import baseStyles from './styles/base' ;
12- import type { ConfigMapData } from './types' ;
1311
1412interface ActionItem {
1513 name ?: string ;
@@ -75,16 +73,18 @@ const actionItems: ActionItem[] = [
7573] ;
7674
7775export class CommentEditor extends LitElement {
76+ @property ( { type : String } )
77+ placeholder : string | undefined ;
78+
79+ @property ( { type : Boolean , attribute : 'keep-alive' } )
80+ keepAlive = false ;
81+
7882 @state ( )
7983 editor : Editor | undefined ;
8084
8185 @state ( )
8286 loading = true ;
8387
84- @consume ( { context : configMapDataContext } )
85- @state ( )
86- configMapData : ConfigMapData | undefined ;
87-
8888 protected override firstUpdated ( _changedProperties : PropertyValues ) : void {
8989 super . firstUpdated ( _changedProperties ) ;
9090 this . createEditor ( ) ;
@@ -113,8 +113,7 @@ export class CommentEditor extends LitElement {
113113 } ) ,
114114
115115 Placeholder . configure ( {
116- placeholder :
117- this . configMapData ?. editor ?. placeholder || msg ( 'Write a comment' ) ,
116+ placeholder : this . placeholder || msg ( 'Write a comment' ) ,
118117 } ) ,
119118
120119 CodeBlockShiki . configure ( {
@@ -133,10 +132,25 @@ export class CommentEditor extends LitElement {
133132 this . requestUpdate ( ) ;
134133 } ,
135134 } ) ;
135+
136+ this . editor . on ( 'update' , ( ) => {
137+ this . dispatchEvent (
138+ new CustomEvent ( 'update' , {
139+ detail : {
140+ content : this . editor ?. getHTML ( ) ,
141+ characterCount : this . editor ?. storage . characterCount . characters ( ) ,
142+ } ,
143+ } )
144+ ) ;
145+ } ) ;
136146 }
137147
138148 override disconnectedCallback ( ) : void {
139- this . editor ?. destroy ( ) ;
149+ if ( ! this . keepAlive ) {
150+ this . editor ?. destroy ( ) ;
151+ this . editor = undefined ;
152+ }
153+ super . disconnectedCallback ( ) ;
140154 }
141155
142156 setFocus ( ) {
0 commit comments