Skip to content

Commit 3c6bd3b

Browse files
committed
fix: remove filesafe dependency from bold editor
1 parent 8c18225 commit 3c6bd3b

File tree

4 files changed

+5
-53
lines changed

4 files changed

+5
-53
lines changed
133 KB
Binary file not shown.

packages/com.sncommunity.bold-editor/app/components/Editor.js

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import React from 'react';
2-
import FilesafeEmbed from 'filesafe-embed';
32
import EditorKit from '@standardnotes/editor-kit';
43
import DOMPurify from 'dompurify';
54
import { 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-
146
export 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
*/

packages/com.sncommunity.bold-editor/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
"dompurify": "^2.2.9",
4242
"eslint": "*",
4343
"eslint-plugin-react": "*",
44-
"filesafe-embed": "1.0.13",
45-
"filesafe-js": "1.0.5",
4644
"html-webpack-plugin": "^5.3.1",
4745
"mini-css-extract-plugin": "^1.4.0",
4846
"react": "17.x",

packages/com.sncommunity.bold-editor/webpack.dev.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ module.exports = merge(config, {
77
devtool: 'cheap-source-map',
88
devServer: {
99
port: 8001,
10-
contentBase: path.resolve(__dirname, 'dist'),
11-
disableHostCheck: true,
1210
historyApiFallback: true,
13-
watchOptions: { aggregateTimeout: 300, poll: 1000 },
1411
headers: {
1512
'Access-Control-Allow-Origin': '*',
1613
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',

0 commit comments

Comments
 (0)