11import React from 'react' ;
2- import FilesafeEmbed from 'filesafe-embed' ;
32import EditorKit from '@standardnotes/editor-kit' ;
43import DOMPurify from 'dompurify' ;
54import { SKAlert } from 'sn-stylekit' ;
65
7- // Not used directly here, but required to be imported so that it is included
8- // in dist file.
9- // Note that filesafe-embed also imports filesafe-js, but conditionally, so
10- // it's not included in it's own dist files.
11- // eslint-disable-next-line no-unused-vars
12- import Filesafe from 'filesafe-js' ;
13-
146export default class Editor extends React . Component {
157
168 constructor ( props ) {
@@ -161,35 +153,25 @@ export default class Editor extends React.Component {
161153
162154 this . editorKit = new EditorKit ( delegate , {
163155 mode : 'html' ,
164- supportsFileSafe : true ,
165156 // Redactor has its own debouncing, so we'll set ours to 0
166157 coallesedSavingDelay : 0
167158 } ) ;
168159 }
169160
170161 async configureEditor ( ) {
171- // We need to set this as a window variable so that the filesafe plugin
172- // can interact with this object passing it as an opt for some reason
173- // strips any functions off the objects.
174- const filesafeInstance = await this . editorKit . getFileSafe ( ) ;
175- window . filesafe_params = {
176- embed : FilesafeEmbed ,
177- client : filesafeInstance
178- } ;
179162 this . redactor = $R ( '#editor' , {
180163 styles : true ,
181164 toolbarFixed : true , // sticky toolbar
182165 tabAsSpaces : 2 , // currently tab only works if you use spaces.
183166 tabKey : true , // explicitly set tabkey for editor use, not for focus.
184167 linkSize : 20000 , // redactor default is 30, which truncates the link.
185- buttonsAdd : [ 'filesafe' ] ,
186168 buttons : [
187169 'bold' , 'italic' , 'underline' , 'deleted' , 'format' , 'fontsize' ,
188- 'fontfamily' , 'fontcolor' , 'filesafe' , ' link', 'lists' , 'alignment' ,
170+ 'fontfamily' , 'fontcolor' , 'link' , 'lists' , 'alignment' ,
189171 'line' , 'redo' , 'undo' , 'indent' , 'outdent' , 'textdirection' , 'html'
190172 ] ,
191173 plugins : [
192- 'filesafe' , ' fontsize', 'fontfamily' , 'fontcolor' , 'alignment' ,
174+ 'fontsize' , 'fontfamily' , 'fontcolor' , 'alignment' ,
193175 'table' , 'inlinestyle' , 'textdirection'
194176 ] ,
195177 fontfamily : [
@@ -206,7 +188,7 @@ export default class Editor extends React.Component {
206188 this . editorKit . onEditorValueChanged ( html ) ;
207189 } ,
208190 pasted : ( _nodes ) => {
209- this . editorKit . onEditorPaste ( ) ;
191+ this . editorKit . onEditorPaste ?. ( ) ;
210192 } ,
211193 image : {
212194 resized : ( image ) => {
@@ -222,16 +204,12 @@ export default class Editor extends React.Component {
222204 imageEditable : false ,
223205 imageCaption : false ,
224206 imageLink : false ,
225- imageResizable : true , // requires image to be wrapped in a figure.
226- imageUpload : ( formData , files , _event ) => {
227- // Called when images are pasted from the clipboard too.
228- this . onEditorFilesDrop ( files ) ;
229- }
207+ imageResizable : true // requires image to be wrapped in a figure.
230208 } ) ;
231209
232210 this . redactor . editor . getElement ( ) . on ( 'keyup.textsearcher' , ( event ) => {
233211 const key = event . which ;
234- this . editorKit . onEditorKeyUp ( {
212+ this . editorKit . onEditorKeyUp ?. ( {
235213 key,
236214 isSpace : key == this . redactor . keycodes . SPACE ,
237215 isEnter : key == this . redactor . keycodes . ENTER
@@ -246,27 +224,6 @@ export default class Editor extends React.Component {
246224 }
247225 }
248226
249- onEditorFilesDrop ( files ) {
250- if ( ! this . editorKit . canUseFileSafe ( ) ) {
251- return ;
252- }
253-
254- if ( ! this . editorKit . canUploadFiles ( ) ) {
255- // Open filesafe modal
256- this . redactor . plugin . filesafe . open ( ) ;
257- return ;
258- }
259-
260- for ( const file of files ) {
261- // Observers in EditorKitInternal.js will handle successful upload
262- this . editorKit . uploadJSFileObject ( file ) . then ( ( descriptor ) => {
263- if ( ! descriptor || ! descriptor . uuid ) {
264- // alert("File failed to upload. Please try again");
265- }
266- } ) ;
267- }
268- }
269-
270227 /**
271228 * Checks if HTML is safe to render.
272229 */
0 commit comments