@@ -91,7 +91,6 @@ export default class PluginEditor extends Component {
91
91
} ;
92
92
93
93
keyBindingFn = ( keyboardEvent ) => {
94
- // TODO optimize to break after the first one
95
94
let command = this . plugins
96
95
. map ( ( plugin ) => {
97
96
if ( plugin . keyBindingFn ) {
@@ -113,8 +112,6 @@ export default class PluginEditor extends Component {
113
112
}
114
113
}
115
114
116
- // TODO allow to provide a custom handleKeyCommand
117
-
118
115
return command !== undefined ? command : getDefaultKeyBinding ( keyboardEvent ) ;
119
116
} ;
120
117
@@ -141,87 +138,21 @@ export default class PluginEditor extends Component {
141
138
. find ( ( result ) => result !== undefined ) ;
142
139
} ;
143
140
144
- handleDroppedFiles = ( selection , files ) => {
145
- if ( this . props . handleDroppedFiles ) {
146
- const result = this . props . handleDroppedFiles ( {
147
- selection,
148
- files,
149
- getEditorState : this . getEditorState ,
150
- updateEditorState : this . onChange ,
151
- props : this . props ,
152
- } ) ;
153
- if ( result ) {
154
- return result ;
155
- }
156
- }
157
-
158
- return this . plugins
159
- . map ( ( plugin ) => {
160
- if ( plugin . handleDroppedFiles ) {
161
- const result = plugin . handleDroppedFiles ( {
162
- selection,
163
- files,
164
- getEditorState : this . getEditorState ,
165
- updateEditorState : this . onChange ,
166
- props : this . props ,
167
- } ) ;
168
- if ( result ) {
169
- return result ;
170
- }
171
- }
172
-
173
- return undefined ;
174
- } )
175
- . find ( ( result ) => result !== undefined ) ;
176
- } ;
177
-
178
- handleDrop = ( selection , dataTransfer , isInternal ) => {
179
- if ( this . props . handleDrop ) {
180
- const result = this . props . handleDrop ( {
181
- selection,
182
- dataTransfer,
183
- isInternal,
184
- getEditorState : this . getEditorState ,
185
- updateEditorState : this . onChange ,
186
- props : this . props ,
187
- } ) ;
188
- if ( result ) {
189
- return result ;
190
- }
191
- }
192
-
193
- return this . plugins
194
- . map ( ( plugin ) => {
195
- if ( plugin . handleDrop ) {
196
- const result = plugin . handleDrop ( {
197
- selection,
198
- dataTransfer,
199
- isInternal,
200
- getEditorState : this . getEditorState ,
201
- updateEditorState : this . onChange ,
202
- props : this . props ,
203
- } ) ;
204
- if ( result ) {
205
- return result ;
206
- }
207
- }
208
-
209
- return undefined ;
210
- } )
211
- . find ( ( result ) => result !== undefined ) ;
212
- } ;
213
-
214
141
// Put the keyboard focus on the editor
215
142
focus = ( ) => {
216
143
this . refs . editor . focus ( ) ;
217
144
} ;
218
145
219
- createHandleListener = ( name ) => ( event ) => (
220
- this . plugins
221
- . filter ( ( plug ) => plug [ name ] )
222
- . map ( ( plugin ) => plugin [ name ] ( event ) )
223
- . find ( ( result ) => result === true ) === true
224
- ) ;
146
+ createHandleListener = ( name ) => ( ...args ) => {
147
+ const newArgs = [ ] . slice . apply ( args ) ;
148
+ newArgs . push ( this . getEditorState ) ;
149
+ newArgs . push ( this . onChange ) ;
150
+
151
+ return this . plugins
152
+ . filter ( ( plugin ) => plugin [ name ] )
153
+ . map ( ( plugin ) => plugin [ name ] ( ...newArgs ) )
154
+ . find ( ( result ) => result === true ) === true ;
155
+ } ;
225
156
226
157
createOnListener = ( name ) => ( event ) => (
227
158
this . plugins
@@ -230,18 +161,12 @@ export default class PluginEditor extends Component {
230
161
) ;
231
162
232
163
createEventListeners = ( ) => {
233
- const listeners = {
234
- onChange : this . onChange ,
235
- handleKeyCommand : this . handleKeyCommand ,
236
- keyBindingFn : this . keyBindingFn ,
237
- handleReturn : this . handleReturn ,
238
- } ;
239
-
164
+ const listeners = { } ;
240
165
const keepHandlers = [ 'onChange' , 'handleKeyCommand' ] ;
241
166
242
167
// bind random onListeners and handleListeners
243
- this . plugins . forEach ( ( plug ) => {
244
- Object . keys ( plug ) . forEach ( ( attrName ) => {
168
+ this . plugins . forEach ( ( plugin ) => {
169
+ Object . keys ( plugin ) . forEach ( ( attrName ) => {
245
170
if ( attrName . indexOf ( 'on' ) === 0 && keepHandlers . indexOf ( attrName !== - 1 ) ) {
246
171
listeners [ attrName ] = this . createOnListener ( attrName ) ;
247
172
}
@@ -276,8 +201,9 @@ export default class PluginEditor extends Component {
276
201
{ ...pluginProps }
277
202
{ ...this . props }
278
203
{ ...listeners }
279
- handleDroppedFiles = { this . handleDroppedFiles }
280
- handleDrop = { this . handleDrop }
204
+ onChange = { this . onChange }
205
+ handleKeyCommand = { this . handleKeyCommand }
206
+ keyBindingFn = { this . keyBindingFn }
281
207
editorState = { this . editorState }
282
208
blockRendererFn = { this . blockRendererFn }
283
209
ref = "editor"
0 commit comments