Skip to content

Commit 8d168d4

Browse files
authored
fix: Removes filesafe dependency from bold editor (#69)
* fix: remove filesafe dependency from bold editor * chore: yarn install * fix: update webpack config * chore: update webpack config
1 parent 8c18225 commit 8d168d4

File tree

7 files changed

+5
-75
lines changed

7 files changed

+5
-75
lines changed
-45.8 KB
Binary file not shown.
-546 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.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,13 @@ module.exports = {
6060
template: 'editor.index.ejs',
6161
filename: 'index.html'
6262
}),
63-
new CopyWebpackPlugin({
64-
patterns: [
65-
{ from: require.resolve('filesafe-js/dist/filesafe-js/EncryptionWorker.js'), to: 'filesafe-js/EncryptionWorker.js' },
66-
],
67-
}),
6863
new MergeIntoSingleFilePlugin({
6964
files: {
7065
"vendor.js": [
7166
'redactor/src/redactor.min.js',
7267
'redactor/plugins/**/*.min.js',
7368
],
7469
"vendor.css": [
75-
require.resolve('filesafe-embed/dist/dist.css'),
7670
'redactor/src/redactor.min.css',
7771
'redactor/plugins/inlinestyle/inlinestyle.min.css'
7872
]

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',

yarn.lock

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7165,8 +7165,6 @@ __metadata:
71657165
dompurify: ^2.2.9
71667166
eslint: "*"
71677167
eslint-plugin-react: "*"
7168-
filesafe-embed: 1.0.13
7169-
filesafe-js: 1.0.5
71707168
html-webpack-plugin: ^5.3.1
71717169
mini-css-extract-plugin: ^1.4.0
71727170
react: 17.x
@@ -16274,27 +16272,13 @@ __metadata:
1627416272
languageName: node
1627516273
linkType: hard
1627616274

16277-
"filesafe-embed@npm:1.0.13":
16278-
version: 1.0.13
16279-
resolution: "filesafe-embed@npm:1.0.13"
16280-
checksum: 8e69eb0fc784355b38958cbf707e24c0b9304466964eac47d9126fe9fcf3561623d1e6b62802db253d8bd5a536c952bcce1249651658e226be84bde15eed430c
16281-
languageName: node
16282-
linkType: hard
16283-
1628416275
"filesafe-embed@standardnotes/filesafe-embed#309a4282959ffe08ebb8d0e23dbddb60adbd09ce":
1628516276
version: 1.1.0
1628616277
resolution: "filesafe-embed@https://github.com/standardnotes/filesafe-embed.git#commit=309a4282959ffe08ebb8d0e23dbddb60adbd09ce"
1628716278
checksum: 3e795f069b31564b1c77d6af9920c75f63c034d12e9b1437e4de1384e30003496fe4e72bc85961d5a862be114e6f0acec51481288041d76e2ebd819675fbad04
1628816279
languageName: node
1628916280
linkType: hard
1629016281

16291-
"filesafe-js@npm:1.0.5":
16292-
version: 1.0.5
16293-
resolution: "filesafe-js@npm:1.0.5"
16294-
checksum: 1db0bad1861f072067011e271af35ef0f87a4c8b6f9b4e525d5e2ae8872da19418555d72467a5aca86145f678644f3d34e0118f4ea17c7cfc7094380a26f9551
16295-
languageName: node
16296-
linkType: hard
16297-
1629816282
"filesafe-js@standardnotes/filesafe-js#09278cc13b61b4dd672613201f69a034d5c41ed4":
1629916283
version: 1.0.6
1630016284
resolution: "filesafe-js@https://github.com/standardnotes/filesafe-js.git#commit=09278cc13b61b4dd672613201f69a034d5c41ed4"

0 commit comments

Comments
 (0)