Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work with CKEditor5 version 43.0.0 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions fileupload.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FileUploadEditing from "./src/fileuploadediting";
import FileUploadUI from "./src/fileuploadui";
import { Plugin } from 'ckeditor5'
import FileUploadEditing from './src/fileuploadediting'
import FileUploadUI from './src/fileuploadui'

export default class FileUpload extends Plugin {
static get requires () {
return [FileUploadEditing, FileUploadUI]
}

static get requires() {
return [ FileUploadEditing, FileUploadUI ];
}

/**
* @inheritDoc
*/
static get pluginName() {
return 'fileUpload';
}
/**
* @inheritDoc
*/
static get pluginName () {
return 'fileUpload'
}
}
970 changes: 894 additions & 76 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@emagtechlabs/ckeditor5-file-upload",
"version": "1.0.4",
"version": "1.1.0",
"description": "Classic File Upload Tool for CKEditor5",
"main": "src/fileupload.js",
"main": "fileupload.js",
"keywords": [
"ckeditor5",
"classic",
Expand All @@ -11,13 +11,7 @@
"plugin"
],
"dependencies": {
"@ckeditor/ckeditor5-core": "^17.0.0",
"@ckeditor/ckeditor5-upload": "^17.0.0",
"@ckeditor/ckeditor5-ui": "^17.0.0",
"@ckeditor/ckeditor5-clipboard": "^17.0.0",
"@ckeditor/ckeditor5-engine": "^17.0.0",
"@ckeditor/ckeditor5-utils": "^17.0.0",
"@ckeditor/ckeditor5-widget": "^17.0.0"
"ckeditor5": "43.0.0"
},
"repository": {
"type": "git",
Expand Down
67 changes: 33 additions & 34 deletions src/fileuploadcommand.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
import Command from '@ckeditor/ckeditor5-core/src/command';
import { insertFileLink, isFileAllowed } from './utils';
import { FileRepository, Command } from 'ckeditor5'
import { insertFileLink } from './utils'

export default class FileUploadCommand extends Command {
/**
* @inheritDoc
*/
refresh() {
this.isEnabled = true;
}
/**
* @inheritDoc
*/
refresh () {
this.isEnabled = true
}

/**
* Executes the command.
*
* @fires execute
* @param {Object} options Options for the executed command.
* @param {File|Array.<File>} options.file The file or an array of files to upload.
*/
execute( options ) {
const editor = this.editor;
const model = editor.model;
/**
* Executes the command.
*
* @fires execute
* @param {Object} options Options for the executed command.
* @param {File|Array.<File>} options.file The file or an array of files to upload.
*/
execute (options) {
const editor = this.editor
const model = editor.model

const fileRepository = editor.plugins.get( FileRepository );
const fileRepository = editor.plugins.get(FileRepository)

model.change( writer => {
const filesToUpload = options.file;
for ( const file of filesToUpload ) {
uploadFile( writer, model, fileRepository, file );
}
} );
}
model.change(writer => {
const filesToUpload = options.file
for (const file of filesToUpload) {
uploadFile(writer, model, fileRepository, file)
}
})
}
}

/**
Expand All @@ -39,13 +38,13 @@ export default class FileUploadCommand extends Command {
* @param {module:engine/model/model~Model} model
* @param {File} file
*/
function uploadFile( writer, model, fileRepository, file ) {
const loader = fileRepository.createLoader( file );
function uploadFile (writer, model, fileRepository, file) {
const loader = fileRepository.createLoader(file)

// Do not throw when upload adapter is not set. FileRepository will log an error anyway.
if ( !loader ) {
return;
}
// Do not throw when upload adapter is not set. FileRepository will log an error anyway.
if (!loader) {
return
}

insertFileLink( writer, model, {linkHref: "", uploadId: loader.id }, file );
insertFileLink(writer, model, { linkHref: '', uploadId: loader.id }, file)
}
Loading