@@ -4,6 +4,7 @@ import { PluginRecord, RemixPluginPanel } from '@remix-ui/panel'
4
4
import packageJson from '../../../../../package.json'
5
5
import { PluginViewWrapper } from '@remix-ui/helper'
6
6
import { EventEmitter } from 'events'
7
+ import DOMPurify from 'dompurify' ;
7
8
8
9
import { AppAction , appActionTypes , AppState } from '@remix-ui/app'
9
10
@@ -23,6 +24,7 @@ export class PopupPanel extends AbstractPanel {
23
24
element : HTMLDivElement
24
25
dispatch : React . Dispatch < any > = ( ) => { }
25
26
appStateDispatch : React . Dispatch < AppAction > = ( ) => { }
27
+ hooks : boolean = false
26
28
27
29
constructor ( config = null ) {
28
30
super ( profile )
@@ -64,7 +66,6 @@ export class PopupPanel extends AbstractPanel {
64
66
}
65
67
66
68
async showPopupPanel ( show ) {
67
-
68
69
this . appStateDispatch ( {
69
70
type : appActionTypes . setShowPopupPanel ,
70
71
payload : show
@@ -85,6 +86,34 @@ export class PopupPanel extends AbstractPanel {
85
86
}
86
87
87
88
updateComponent ( state : popupPanelState , appState : Partial < AppState > ) {
89
+ if ( ! this . hooks ) {
90
+ try {
91
+ const markdown = document . getElementsByClassName ( 'nlux-composer-container' )
92
+ const button = markdown [ 0 ] . getElementsByTagName ( 'button' ) [ 0 ]
93
+ const textArea = markdown [ 0 ] . getElementsByTagName ( 'textarea' ) [ 0 ]
94
+ // only add event listeners if they are not already added
95
+ if ( ! textArea . dataset . listenerAdded ) {
96
+ textArea . addEventListener ( 'input' , ( event ) => {
97
+ const sanitizedInput = DOMPurify . sanitize ( textArea . value )
98
+ if ( sanitizedInput !== textArea . value ) {
99
+ textArea . value = sanitizedInput
100
+ }
101
+ } )
102
+ textArea . dataset . listenerAdded = 'true'
103
+ }
104
+
105
+ if ( ! button . dataset . listenerAdded ) {
106
+ button . dataset . listenerAdded = 'true'
107
+ button . addEventListener ( 'click' , ( event ) => {
108
+ const sanitizedInput = DOMPurify . sanitize ( textArea . value )
109
+ if ( sanitizedInput !== textArea . value ) {
110
+ textArea . value = sanitizedInput
111
+ }
112
+ } )
113
+ }
114
+ this . hooks = true
115
+ } catch ( error ) { this . hooks = false }
116
+ }
88
117
return (
89
118
< div
90
119
className = { `px-0 bg-light border-info ${ appState ?. showPopupPanel ? 'd-flex' : 'd-none' } ` }
0 commit comments