Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckeditor/ckeditor5-upload

Package Overview
Dependencies
Maintainers
1
Versions
796
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-upload - npm Package Compare versions

Comparing version 0.0.0-nightly-20241219.0 to 0.0.0-nightly-20241219.1

444

dist/index.js

@@ -11,5 +11,13 @@ /**

*/ class FileReader extends /* #__PURE__ */ ObservableMixin() {
total;
/**
* Creates an instance of the FileReader.
*/ constructor(){
* Instance of native FileReader.
*/ _reader;
/**
* Holds the data of an already loaded file. The file must be first loaded
* by using {@link module:upload/filereader~FileReader#read `read()`}.
*/ _data;
/**
* Creates an instance of the FileReader.
*/ constructor(){
super();

@@ -25,19 +33,19 @@ const reader = new window.FileReader();

/**
* Returns error that occurred during file reading.
*/ get error() {
* Returns error that occurred during file reading.
*/ get error() {
return this._reader.error;
}
/**
* Holds the data of an already loaded file. The file must be first loaded
* by using {@link module:upload/filereader~FileReader#read `read()`}.
*/ get data() {
* Holds the data of an already loaded file. The file must be first loaded
* by using {@link module:upload/filereader~FileReader#read `read()`}.
*/ get data() {
return this._data;
}
/**
* Reads the provided file.
*
* @param file Native File object.
* @returns Returns a promise that will be resolved with file's content.
* The promise will be rejected in case of an error or when the reading process is aborted.
*/ read(file) {
* Reads the provided file.
*
* @param file Native File object.
* @returns Returns a promise that will be resolved with file's content.
* The promise will be rejected in case of an error or when the reading process is aborted.
*/ read(file) {
const reader = this._reader;

@@ -61,4 +69,4 @@ this.total = file.size;

/**
* Aborts file reader.
*/ abort() {
* Aborts file reader.
*/ abort() {
this._reader.abort();

@@ -80,28 +88,25 @@ }

*/ class FileRepository extends Plugin {
constructor(){
super(...arguments);
/**
* Collection of loaders associated with this repository.
*/ this.loaders = new Collection();
/**
* Loaders mappings used to retrieve loaders references.
*/ this._loadersMap = new Map();
/**
* Reference to a pending action registered in a {@link module:core/pendingactions~PendingActions} plugin
* while upload is in progress. When there is no upload then value is `null`.
*/ this._pendingAction = null;
}
/**
* @inheritDoc
*/ static get pluginName() {
* Collection of loaders associated with this repository.
*/ loaders = new Collection();
/**
* Loaders mappings used to retrieve loaders references.
*/ _loadersMap = new Map();
/**
* Reference to a pending action registered in a {@link module:core/pendingactions~PendingActions} plugin
* while upload is in progress. When there is no upload then value is `null`.
*/ _pendingAction = null;
/**
* @inheritDoc
*/ static get pluginName() {
return 'FileRepository';
}
/**
* @inheritDoc
*/ static get isOfficialPlugin() {
* @inheritDoc
*/ static get isOfficialPlugin() {
return true;
}
/**
* @inheritDoc
*/ static get requires() {
* @inheritDoc
*/ static get requires() {
return [

@@ -112,4 +117,4 @@ PendingActions

/**
* @inheritDoc
*/ init() {
* @inheritDoc
*/ init() {
// Keeps upload in a sync with pending actions.

@@ -124,44 +129,44 @@ this.loaders.on('change', ()=>this._updatePendingAction());

/**
* Returns the loader associated with specified file or promise.
*
* To get loader by id use `fileRepository.loaders.get( id )`.
*
* @param fileOrPromise Native file or promise handle.
*/ getLoader(fileOrPromise) {
* Returns the loader associated with specified file or promise.
*
* To get loader by id use `fileRepository.loaders.get( id )`.
*
* @param fileOrPromise Native file or promise handle.
*/ getLoader(fileOrPromise) {
return this._loadersMap.get(fileOrPromise) || null;
}
/**
* Creates a loader instance for the given file.
*
* Requires {@link #createUploadAdapter} factory to be defined.
*
* @param fileOrPromise Native File object or native Promise object which resolves to a File.
*/ createLoader(fileOrPromise) {
* Creates a loader instance for the given file.
*
* Requires {@link #createUploadAdapter} factory to be defined.
*
* @param fileOrPromise Native File object or native Promise object which resolves to a File.
*/ createLoader(fileOrPromise) {
if (!this.createUploadAdapter) {
/**
* You need to enable an upload adapter in order to be able to upload files.
*
* This warning shows up when {@link module:upload/filerepository~FileRepository} is being used
* without {@link module:upload/filerepository~FileRepository#createUploadAdapter defining an upload adapter}.
*
* **If you see this warning when using one of the {@glink getting-started/legacy/installation-methods/predefined-builds
* CKEditor 5 Builds}**
* it means that you did not configure any of the upload adapters available by default in those builds.
*
* Predefined builds are a deprecated solution and we strongly advise
* {@glink updating/nim-migration/migration-to-new-installation-methods migrating to new installation methods}.
*
* See the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn which upload
* adapters are available in the builds and how to configure them.
*
* Otherwise, if you see this warning, there is a chance that you enabled
* a feature like {@link module:image/imageupload~ImageUpload},
* or {@link module:image/imageupload/imageuploadui~ImageUploadUI} but you did not enable any upload adapter.
* You can choose one of the existing upload adapters listed in the
* {@glink features/images/image-upload/image-upload "Image upload overview"}.
*
* You can also implement your {@glink framework/deep-dive/upload-adapter own image upload adapter}.
*
* @error filerepository-no-upload-adapter
*/ logWarning('filerepository-no-upload-adapter');
* You need to enable an upload adapter in order to be able to upload files.
*
* This warning shows up when {@link module:upload/filerepository~FileRepository} is being used
* without {@link module:upload/filerepository~FileRepository#createUploadAdapter defining an upload adapter}.
*
* **If you see this warning when using one of the {@glink getting-started/legacy/installation-methods/predefined-builds
* CKEditor 5 Builds}**
* it means that you did not configure any of the upload adapters available by default in those builds.
*
* Predefined builds are a deprecated solution and we strongly advise
* {@glink updating/nim-migration/migration-to-new-installation-methods migrating to new installation methods}.
*
* See the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn which upload
* adapters are available in the builds and how to configure them.
*
* Otherwise, if you see this warning, there is a chance that you enabled
* a feature like {@link module:image/imageupload~ImageUpload},
* or {@link module:image/imageupload/imageuploadui~ImageUploadUI} but you did not enable any upload adapter.
* You can choose one of the existing upload adapters listed in the
* {@glink features/images/image-upload/image-upload "Image upload overview"}.
*
* You can also implement your {@glink framework/deep-dive/upload-adapter own image upload adapter}.
*
* @error filerepository-no-upload-adapter
*/ logWarning('filerepository-no-upload-adapter');
return null;

@@ -200,6 +205,6 @@ }

/**
* Destroys the given loader.
*
* @param fileOrPromiseOrLoader File or Promise associated with that loader or loader itself.
*/ destroyLoader(fileOrPromiseOrLoader) {
* Destroys the given loader.
*
* @param fileOrPromiseOrLoader File or Promise associated with that loader or loader itself.
*/ destroyLoader(fileOrPromiseOrLoader) {
const loader = fileOrPromiseOrLoader instanceof FileLoader ? fileOrPromiseOrLoader : this.getLoader(fileOrPromiseOrLoader);

@@ -215,4 +220,4 @@ loader._destroy();

/**
* Registers or deregisters pending action bound with upload progress.
*/ _updatePendingAction() {
* Registers or deregisters pending action bound with upload progress.
*/ _updatePendingAction() {
const pendingActions = this.editor.plugins.get(PendingActions);

@@ -238,7 +243,21 @@ if (this.loaders.length) {

/**
* Creates a new instance of `FileLoader`.
*
* @param filePromise A promise which resolves to a file instance.
* @param uploadAdapterCreator The function which returns {@link module:upload/filerepository~UploadAdapter} instance.
*/ constructor(filePromise, uploadAdapterCreator){
* Unique id of FileLoader instance.
*
* @readonly
*/ id;
/**
* Additional wrapper over the initial file promise passed to this loader.
*/ _filePromiseWrapper;
/**
* Adapter instance associated with this file loader.
*/ _adapter;
/**
* FileReader used by FileLoader.
*/ _reader;
/**
* Creates a new instance of `FileLoader`.
*
* @param filePromise A promise which resolves to a file instance.
* @param uploadAdapterCreator The function which returns {@link module:upload/filerepository~UploadAdapter} instance.
*/ constructor(filePromise, uploadAdapterCreator){
super();

@@ -258,4 +277,4 @@ this.id = uid();

/**
* A `Promise` which resolves to a `File` instance associated with this file loader.
*/ get file() {
* A `Promise` which resolves to a `File` instance associated with this file loader.
*/ get file() {
if (!this._filePromiseWrapper) {

@@ -277,36 +296,36 @@ // Loader was destroyed, return promise which resolves to null.

/**
* Returns the file data. To read its data, you need for first load the file
* by using the {@link module:upload/filerepository~FileLoader#read `read()`} method.
*/ get data() {
* Returns the file data. To read its data, you need for first load the file
* by using the {@link module:upload/filerepository~FileLoader#read `read()`} method.
*/ get data() {
return this._reader.data;
}
/**
* Reads file using {@link module:upload/filereader~FileReader}.
*
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-read-wrong-status` when status
* is different than `idle`.
*
* Example usage:
*
* ```ts
* fileLoader.read()
* .then( data => { ... } )
* .catch( err => {
* if ( err === 'aborted' ) {
* console.log( 'Reading aborted.' );
* } else {
* console.log( 'Reading error.', err );
* }
* } );
* ```
*
* @returns Returns promise that will be resolved with read data. Promise will be rejected if error
* occurs or if read process is aborted.
*/ read() {
* Reads file using {@link module:upload/filereader~FileReader}.
*
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-read-wrong-status` when status
* is different than `idle`.
*
* Example usage:
*
* ```ts
* fileLoader.read()
* .then( data => { ... } )
* .catch( err => {
* if ( err === 'aborted' ) {
* console.log( 'Reading aborted.' );
* } else {
* console.log( 'Reading error.', err );
* }
* } );
* ```
*
* @returns Returns promise that will be resolved with read data. Promise will be rejected if error
* occurs or if read process is aborted.
*/ read() {
if (this.status != 'idle') {
/**
* You cannot call read if the status is different than idle.
*
* @error filerepository-read-wrong-status
*/ throw new CKEditorError('filerepository-read-wrong-status', this);
* You cannot call read if the status is different than idle.
*
* @error filerepository-read-wrong-status
*/ throw new CKEditorError('filerepository-read-wrong-status', this);
}

@@ -332,29 +351,29 @@ this.status = 'reading';

/**
* Reads file using the provided {@link module:upload/filerepository~UploadAdapter}.
*
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-upload-wrong-status` when status
* is different than `idle`.
* Example usage:
*
* ```ts
* fileLoader.upload()
* .then( data => { ... } )
* .catch( e => {
* if ( e === 'aborted' ) {
* console.log( 'Uploading aborted.' );
* } else {
* console.log( 'Uploading error.', e );
* }
* } );
* ```
*
* @returns Returns promise that will be resolved with response data. Promise will be rejected if error
* occurs or if read process is aborted.
*/ upload() {
* Reads file using the provided {@link module:upload/filerepository~UploadAdapter}.
*
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-upload-wrong-status` when status
* is different than `idle`.
* Example usage:
*
* ```ts
* fileLoader.upload()
* .then( data => { ... } )
* .catch( e => {
* if ( e === 'aborted' ) {
* console.log( 'Uploading aborted.' );
* } else {
* console.log( 'Uploading error.', e );
* }
* } );
* ```
*
* @returns Returns promise that will be resolved with response data. Promise will be rejected if error
* occurs or if read process is aborted.
*/ upload() {
if (this.status != 'idle') {
/**
* You cannot call upload if the status is different than idle.
*
* @error filerepository-upload-wrong-status
*/ throw new CKEditorError('filerepository-upload-wrong-status', this);
* You cannot call upload if the status is different than idle.
*
* @error filerepository-upload-wrong-status
*/ throw new CKEditorError('filerepository-upload-wrong-status', this);
}

@@ -375,4 +394,4 @@ this.status = 'uploading';

/**
* Aborts loading process.
*/ abort() {
* Aborts loading process.
*/ abort() {
const status = this.status;

@@ -394,6 +413,6 @@ this.status = 'aborted';

/**
* Performs cleanup.
*
* @internal
*/ _destroy() {
* Performs cleanup.
*
* @internal
*/ _destroy() {
this._filePromiseWrapper = undefined;

@@ -405,7 +424,7 @@ this._reader = undefined;

/**
* Wraps a given file promise into another promise giving additional
* control (resolving, rejecting, checking if fulfilled) over it.
*
* @param filePromise The initial file promise to be wrapped.
*/ _createFilePromiseWrapper(filePromise) {
* Wraps a given file promise into another promise giving additional
* control (resolving, rejecting, checking if fulfilled) over it.
*
* @param filePromise The initial file promise to be wrapped.
*/ _createFilePromiseWrapper(filePromise) {
const wrapper = {};

@@ -438,4 +457,4 @@ wrapper.promise = new Promise((resolve, reject)=>{

/**
* @inheritDoc
*/ static get requires() {
* @inheritDoc
*/ static get requires() {
return [

@@ -446,14 +465,14 @@ FileRepository

/**
* @inheritDoc
*/ static get pluginName() {
* @inheritDoc
*/ static get pluginName() {
return 'Base64UploadAdapter';
}
/**
* @inheritDoc
*/ static get isOfficialPlugin() {
* @inheritDoc
*/ static get isOfficialPlugin() {
return true;
}
/**
* @inheritDoc
*/ init() {
* @inheritDoc
*/ init() {
this.editor.plugins.get(FileRepository).createUploadAdapter = (loader)=>new Adapter$1(loader);

@@ -466,11 +485,15 @@ }

/**
* Creates a new adapter instance.
*/ constructor(loader){
* `FileLoader` instance to use during the upload.
*/ loader;
reader;
/**
* Creates a new adapter instance.
*/ constructor(loader){
this.loader = loader;
}
/**
* Starts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#upload
*/ upload() {
* Starts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#upload
*/ upload() {
return new Promise((resolve, reject)=>{

@@ -495,6 +518,6 @@ const reader = this.reader = new window.FileReader();

/**
* Aborts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#abort
*/ abort() {
* Aborts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#abort
*/ abort() {
this.reader.abort();

@@ -530,4 +553,4 @@ }

/**
* @inheritDoc
*/ static get requires() {
* @inheritDoc
*/ static get requires() {
return [

@@ -538,14 +561,14 @@ FileRepository

/**
* @inheritDoc
*/ static get pluginName() {
* @inheritDoc
*/ static get pluginName() {
return 'SimpleUploadAdapter';
}
/**
* @inheritDoc
*/ static get isOfficialPlugin() {
* @inheritDoc
*/ static get isOfficialPlugin() {
return true;
}
/**
* @inheritDoc
*/ init() {
* @inheritDoc
*/ init() {
const options = this.editor.config.get('simpleUpload');

@@ -557,8 +580,8 @@ if (!options) {

/**
* The {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `config.simpleUpload.uploadUrl`}
* configuration required by the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter `SimpleUploadAdapter`}
* is missing. Make sure the correct URL is specified for the image upload to work properly.
*
* @error simple-upload-adapter-missing-uploadurl
*/ logWarning('simple-upload-adapter-missing-uploadurl');
* The {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `config.simpleUpload.uploadUrl`}
* configuration required by the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter `SimpleUploadAdapter`}
* is missing. Make sure the correct URL is specified for the image upload to work properly.
*
* @error simple-upload-adapter-missing-uploadurl
*/ logWarning('simple-upload-adapter-missing-uploadurl');
return;

@@ -575,4 +598,11 @@ }

/**
* Creates a new adapter instance.
*/ constructor(loader, options){
* FileLoader instance to use during the upload.
*/ loader;
/**
* The configuration of the adapter.
*/ options;
xhr;
/**
* Creates a new adapter instance.
*/ constructor(loader, options){
this.loader = loader;

@@ -582,6 +612,6 @@ this.options = options;

/**
* Starts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#upload
*/ upload() {
* Starts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#upload
*/ upload() {
return this.loader.file.then((file)=>new Promise((resolve, reject)=>{

@@ -594,6 +624,6 @@ this._initRequest();

/**
* Aborts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#abort
*/ abort() {
* Aborts the upload process.
*
* @see module:upload/filerepository~UploadAdapter#abort
*/ abort() {
if (this.xhr) {

@@ -604,6 +634,6 @@ this.xhr.abort();

/**
* Initializes the `XMLHttpRequest` object using the URL specified as
* {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `simpleUpload.uploadUrl`} in the editor's
* configuration.
*/ _initRequest() {
* Initializes the `XMLHttpRequest` object using the URL specified as
* {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `simpleUpload.uploadUrl`} in the editor's
* configuration.
*/ _initRequest() {
const xhr = this.xhr = new XMLHttpRequest();

@@ -614,8 +644,8 @@ xhr.open('POST', this.options.uploadUrl, true);

/**
* Initializes XMLHttpRequest listeners
*
* @param resolve Callback function to be called when the request is successful.
* @param reject Callback function to be called when the request cannot be completed.
* @param file Native File object.
*/ _initListeners(resolve, reject, file) {
* Initializes XMLHttpRequest listeners
*
* @param resolve Callback function to be called when the request is successful.
* @param reject Callback function to be called when the request cannot be completed.
* @param file Native File object.
*/ _initListeners(resolve, reject, file) {
const xhr = this.xhr;

@@ -652,6 +682,6 @@ const loader = this.loader;

/**
* Prepares the data and sends the request.
*
* @param file File instance to be uploaded.
*/ _sendRequest(file) {
* Prepares the data and sends the request.
*
* @param file File instance to be uploaded.
*/ _sendRequest(file) {
// Set headers if specified.

@@ -658,0 +688,0 @@ const headers = this.options.headers || {};

{
"name": "@ckeditor/ckeditor5-upload",
"version": "0.0.0-nightly-20241219.0",
"version": "0.0.0-nightly-20241219.1",
"description": "Upload feature for CKEditor 5.",

@@ -15,4 +15,4 @@ "keywords": [

"dependencies": {
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20241219.0",
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20241219.0"
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20241219.1",
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20241219.1"
},

@@ -19,0 +19,0 @@ "author": "CKSource (http://cksource.com/)",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc