@ckeditor/ckeditor5-upload 36.0.1 → 37.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -6
- package/src/adapters/base64uploadadapter.d.ts +32 -0
- package/src/adapters/base64uploadadapter.js +0 -14
- package/src/adapters/simpleuploadadapter.d.ts +47 -0
- package/src/adapters/simpleuploadadapter.js +20 -42
- package/src/augmentation.d.ts +20 -0
- package/src/augmentation.js +5 -0
- package/src/filereader.d.ts +56 -0
- package/src/filereader.js +2 -19
- package/src/filerepository.d.ts +342 -0
- package/src/filerepository.js +48 -175
- package/src/index.d.ts +13 -0
- package/src/index.js +1 -0
- package/src/ui/filedialogbuttonview.d.ts +84 -0
- package/src/ui/filedialogbuttonview.js +17 -73
- package/src/uploadconfig.d.ts +90 -0
- package/src/uploadconfig.js +5 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-upload",
|
3
|
-
"version": "
|
3
|
+
"version": "37.0.0-alpha.1",
|
4
4
|
"description": "Upload feature for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -11,9 +11,9 @@
|
|
11
11
|
],
|
12
12
|
"main": "src/index.js",
|
13
13
|
"dependencies": {
|
14
|
-
"@ckeditor/ckeditor5-core": "^
|
15
|
-
"@ckeditor/ckeditor5-utils": "^
|
16
|
-
"@ckeditor/ckeditor5-ui": "^
|
14
|
+
"@ckeditor/ckeditor5-core": "^37.0.0-alpha.1",
|
15
|
+
"@ckeditor/ckeditor5-utils": "^37.0.0-alpha.1",
|
16
|
+
"@ckeditor/ckeditor5-ui": "^37.0.0-alpha.1"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
19
|
"typescript": "^4.8.4",
|
@@ -42,7 +42,8 @@
|
|
42
42
|
"CHANGELOG.md"
|
43
43
|
],
|
44
44
|
"scripts": {
|
45
|
-
"build": "tsc -p ./tsconfig.
|
45
|
+
"build": "tsc -p ./tsconfig.json",
|
46
46
|
"postversion": "npm run build"
|
47
|
-
}
|
47
|
+
},
|
48
|
+
"types": "src/index.d.ts"
|
48
49
|
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module upload/adapters/base64uploadadapter
|
7
|
+
*/
|
8
|
+
import { Plugin, type PluginDependencies } from '@ckeditor/ckeditor5-core';
|
9
|
+
/**
|
10
|
+
* A plugin that converts images inserted into the editor into [Base64 strings](https://en.wikipedia.org/wiki/Base64)
|
11
|
+
* in the {@glink installation/getting-started/getting-and-setting-data editor output}.
|
12
|
+
*
|
13
|
+
* This kind of image upload does not require server processing – images are stored with the rest of the text and
|
14
|
+
* displayed by the web browser without additional requests.
|
15
|
+
*
|
16
|
+
* Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
|
17
|
+
* other ways to upload images into CKEditor 5.
|
18
|
+
*/
|
19
|
+
export default class Base64UploadAdapter extends Plugin {
|
20
|
+
/**
|
21
|
+
* @inheritDoc
|
22
|
+
*/
|
23
|
+
static get requires(): PluginDependencies;
|
24
|
+
/**
|
25
|
+
* @inheritDoc
|
26
|
+
*/
|
27
|
+
static get pluginName(): 'Base64UploadAdapter';
|
28
|
+
/**
|
29
|
+
* @inheritDoc
|
30
|
+
*/
|
31
|
+
init(): void;
|
32
|
+
}
|
@@ -17,8 +17,6 @@ import FileRepository from '../filerepository';
|
|
17
17
|
*
|
18
18
|
* Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
|
19
19
|
* other ways to upload images into CKEditor 5.
|
20
|
-
*
|
21
|
-
* @extends module:core/plugin~Plugin
|
22
20
|
*/
|
23
21
|
export default class Base64UploadAdapter extends Plugin {
|
24
22
|
/**
|
@@ -42,29 +40,18 @@ export default class Base64UploadAdapter extends Plugin {
|
|
42
40
|
}
|
43
41
|
/**
|
44
42
|
* The upload adapter that converts images inserted into the editor into Base64 strings.
|
45
|
-
*
|
46
|
-
* @private
|
47
|
-
* @implements module:upload/filerepository~UploadAdapter
|
48
43
|
*/
|
49
44
|
class Adapter {
|
50
45
|
/**
|
51
46
|
* Creates a new adapter instance.
|
52
|
-
*
|
53
|
-
* @param {module:upload/filerepository~FileLoader} loader
|
54
47
|
*/
|
55
48
|
constructor(loader) {
|
56
|
-
/**
|
57
|
-
* `FileLoader` instance to use during the upload.
|
58
|
-
*
|
59
|
-
* @member {module:upload/filerepository~FileLoader} #loader
|
60
|
-
*/
|
61
49
|
this.loader = loader;
|
62
50
|
}
|
63
51
|
/**
|
64
52
|
* Starts the upload process.
|
65
53
|
*
|
66
54
|
* @see module:upload/filerepository~UploadAdapter#upload
|
67
|
-
* @returns {Promise}
|
68
55
|
*/
|
69
56
|
upload() {
|
70
57
|
return new Promise((resolve, reject) => {
|
@@ -87,7 +74,6 @@ class Adapter {
|
|
87
74
|
* Aborts the upload process.
|
88
75
|
*
|
89
76
|
* @see module:upload/filerepository~UploadAdapter#abort
|
90
|
-
* @returns {Promise}
|
91
77
|
*/
|
92
78
|
abort() {
|
93
79
|
this.reader.abort();
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module upload/adapters/simpleuploadadapter
|
7
|
+
*/
|
8
|
+
import { Plugin, type PluginDependencies } from '@ckeditor/ckeditor5-core';
|
9
|
+
/**
|
10
|
+
* The Simple upload adapter allows uploading images to an application running on your server using
|
11
|
+
* the [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) API with a
|
12
|
+
* minimal {@link module:upload/uploadconfig~SimpleUploadConfig editor configuration}.
|
13
|
+
*
|
14
|
+
* ```ts
|
15
|
+
* ClassicEditor
|
16
|
+
* .create( document.querySelector( '#editor' ), {
|
17
|
+
* simpleUpload: {
|
18
|
+
* uploadUrl: 'http://example.com',
|
19
|
+
* headers: {
|
20
|
+
* ...
|
21
|
+
* }
|
22
|
+
* }
|
23
|
+
* } )
|
24
|
+
* .then( ... )
|
25
|
+
* .catch( ... );
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* See the {@glink features/images/image-upload/simple-upload-adapter "Simple upload adapter"} guide to learn how to
|
29
|
+
* learn more about the feature (configuration, server–side requirements, etc.).
|
30
|
+
*
|
31
|
+
* Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
|
32
|
+
* other ways to upload images into CKEditor 5.
|
33
|
+
*/
|
34
|
+
export default class SimpleUploadAdapter extends Plugin {
|
35
|
+
/**
|
36
|
+
* @inheritDoc
|
37
|
+
*/
|
38
|
+
static get requires(): PluginDependencies;
|
39
|
+
/**
|
40
|
+
* @inheritDoc
|
41
|
+
*/
|
42
|
+
static get pluginName(): 'SimpleUploadAdapter';
|
43
|
+
/**
|
44
|
+
* @inheritDoc
|
45
|
+
*/
|
46
|
+
init(): void;
|
47
|
+
}
|
@@ -12,27 +12,27 @@ import { logWarning } from '@ckeditor/ckeditor5-utils';
|
|
12
12
|
/**
|
13
13
|
* The Simple upload adapter allows uploading images to an application running on your server using
|
14
14
|
* the [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) API with a
|
15
|
-
* minimal {@link module:upload/
|
15
|
+
* minimal {@link module:upload/uploadconfig~SimpleUploadConfig editor configuration}.
|
16
16
|
*
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
17
|
+
* ```ts
|
18
|
+
* ClassicEditor
|
19
|
+
* .create( document.querySelector( '#editor' ), {
|
20
|
+
* simpleUpload: {
|
21
|
+
* uploadUrl: 'http://example.com',
|
22
|
+
* headers: {
|
23
|
+
* ...
|
24
|
+
* }
|
25
|
+
* }
|
26
|
+
* } )
|
27
|
+
* .then( ... )
|
28
|
+
* .catch( ... );
|
29
|
+
* ```
|
28
30
|
*
|
29
31
|
* See the {@glink features/images/image-upload/simple-upload-adapter "Simple upload adapter"} guide to learn how to
|
30
32
|
* learn more about the feature (configuration, server–side requirements, etc.).
|
31
33
|
*
|
32
34
|
* Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
|
33
35
|
* other ways to upload images into CKEditor 5.
|
34
|
-
*
|
35
|
-
* @extends module:core/plugin~Plugin
|
36
36
|
*/
|
37
37
|
export default class SimpleUploadAdapter extends Plugin {
|
38
38
|
/**
|
@@ -57,7 +57,7 @@ export default class SimpleUploadAdapter extends Plugin {
|
|
57
57
|
}
|
58
58
|
if (!options.uploadUrl) {
|
59
59
|
/**
|
60
|
-
* The {@link module:upload/
|
60
|
+
* The {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `config.simpleUpload.uploadUrl`}
|
61
61
|
* configuration required by the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter `SimpleUploadAdapter`}
|
62
62
|
* is missing. Make sure the correct URL is specified for the image upload to work properly.
|
63
63
|
*
|
@@ -73,36 +73,19 @@ export default class SimpleUploadAdapter extends Plugin {
|
|
73
73
|
}
|
74
74
|
/**
|
75
75
|
* Upload adapter.
|
76
|
-
*
|
77
|
-
* @private
|
78
|
-
* @implements module:upload/filerepository~UploadAdapter
|
79
76
|
*/
|
80
77
|
class Adapter {
|
81
78
|
/**
|
82
79
|
* Creates a new adapter instance.
|
83
|
-
*
|
84
|
-
* @param {module:upload/filerepository~FileLoader} loader
|
85
|
-
* @param {module:upload/adapters/simpleuploadadapter~SimpleUploadConfig} options
|
86
80
|
*/
|
87
81
|
constructor(loader, options) {
|
88
|
-
/**
|
89
|
-
* FileLoader instance to use during the upload.
|
90
|
-
*
|
91
|
-
* @member {module:upload/filerepository~FileLoader} #loader
|
92
|
-
*/
|
93
82
|
this.loader = loader;
|
94
|
-
/**
|
95
|
-
* The configuration of the adapter.
|
96
|
-
*
|
97
|
-
* @member {module:upload/adapters/simpleuploadadapter~SimpleUploadConfig} #options
|
98
|
-
*/
|
99
83
|
this.options = options;
|
100
84
|
}
|
101
85
|
/**
|
102
86
|
* Starts the upload process.
|
103
87
|
*
|
104
88
|
* @see module:upload/filerepository~UploadAdapter#upload
|
105
|
-
* @returns {Promise}
|
106
89
|
*/
|
107
90
|
upload() {
|
108
91
|
return this.loader.file
|
@@ -116,7 +99,6 @@ class Adapter {
|
|
116
99
|
* Aborts the upload process.
|
117
100
|
*
|
118
101
|
* @see module:upload/filerepository~UploadAdapter#abort
|
119
|
-
* @returns {Promise}
|
120
102
|
*/
|
121
103
|
abort() {
|
122
104
|
if (this.xhr) {
|
@@ -125,10 +107,8 @@ class Adapter {
|
|
125
107
|
}
|
126
108
|
/**
|
127
109
|
* Initializes the `XMLHttpRequest` object using the URL specified as
|
128
|
-
* {@link module:upload/
|
110
|
+
* {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `simpleUpload.uploadUrl`} in the editor's
|
129
111
|
* configuration.
|
130
|
-
*
|
131
|
-
* @private
|
132
112
|
*/
|
133
113
|
_initRequest() {
|
134
114
|
const xhr = this.xhr = new XMLHttpRequest();
|
@@ -138,10 +118,9 @@ class Adapter {
|
|
138
118
|
/**
|
139
119
|
* Initializes XMLHttpRequest listeners
|
140
120
|
*
|
141
|
-
* @
|
142
|
-
* @param
|
143
|
-
* @param
|
144
|
-
* @param {File} file Native File object.
|
121
|
+
* @param resolve Callback function to be called when the request is successful.
|
122
|
+
* @param reject Callback function to be called when the request cannot be completed.
|
123
|
+
* @param file Native File object.
|
145
124
|
*/
|
146
125
|
_initListeners(resolve, reject, file) {
|
147
126
|
const xhr = this.xhr;
|
@@ -176,8 +155,7 @@ class Adapter {
|
|
176
155
|
/**
|
177
156
|
* Prepares the data and sends the request.
|
178
157
|
*
|
179
|
-
* @
|
180
|
-
* @param {File} file File instance to be uploaded.
|
158
|
+
* @param file File instance to be uploaded.
|
181
159
|
*/
|
182
160
|
_sendRequest(file) {
|
183
161
|
// Set headers if specified.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
import type { SimpleUploadConfig, FileRepository, SimpleUploadAdapter, Base64UploadAdapter } from './index';
|
6
|
+
declare module '@ckeditor/ckeditor5-core' {
|
7
|
+
interface EditorConfig {
|
8
|
+
/**
|
9
|
+
* The configuration of the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter simple upload adapter}.
|
10
|
+
*
|
11
|
+
* Read more in {@link module:upload/uploadconfig~SimpleUploadConfig}.
|
12
|
+
*/
|
13
|
+
simpleUpload?: SimpleUploadConfig;
|
14
|
+
}
|
15
|
+
interface PluginsMap {
|
16
|
+
[FileRepository.pluginName]: FileRepository;
|
17
|
+
[SimpleUploadAdapter.pluginName]: SimpleUploadAdapter;
|
18
|
+
[Base64UploadAdapter.pluginName]: Base64UploadAdapter;
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
declare const FileReader_base: {
|
6
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
7
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
8
|
+
};
|
9
|
+
/**
|
10
|
+
* Wrapper over the native `FileReader`.
|
11
|
+
*/
|
12
|
+
export default class FileReader extends FileReader_base {
|
13
|
+
total: number;
|
14
|
+
/**
|
15
|
+
* Instance of native FileReader.
|
16
|
+
*/
|
17
|
+
private readonly _reader;
|
18
|
+
/**
|
19
|
+
* Holds the data of an already loaded file. The file must be first loaded
|
20
|
+
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
21
|
+
*/
|
22
|
+
private _data?;
|
23
|
+
/**
|
24
|
+
* Number of bytes loaded.
|
25
|
+
*
|
26
|
+
* @readonly
|
27
|
+
* @observable
|
28
|
+
*/
|
29
|
+
loaded: number;
|
30
|
+
/**
|
31
|
+
* Creates an instance of the FileReader.
|
32
|
+
*/
|
33
|
+
constructor();
|
34
|
+
/**
|
35
|
+
* Returns error that occurred during file reading.
|
36
|
+
*/
|
37
|
+
get error(): DOMException | null;
|
38
|
+
/**
|
39
|
+
* Holds the data of an already loaded file. The file must be first loaded
|
40
|
+
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
41
|
+
*/
|
42
|
+
get data(): string | undefined;
|
43
|
+
/**
|
44
|
+
* Reads the provided file.
|
45
|
+
*
|
46
|
+
* @param file Native File object.
|
47
|
+
* @returns Returns a promise that will be resolved with file's content.
|
48
|
+
* The promise will be rejected in case of an error or when the reading process is aborted.
|
49
|
+
*/
|
50
|
+
read(file: File): Promise<string>;
|
51
|
+
/**
|
52
|
+
* Aborts file reader.
|
53
|
+
*/
|
54
|
+
abort(): void;
|
55
|
+
}
|
56
|
+
export {};
|
package/src/filereader.js
CHANGED
@@ -17,21 +17,8 @@ export default class FileReader extends ObservableMixin() {
|
|
17
17
|
constructor() {
|
18
18
|
super();
|
19
19
|
const reader = new window.FileReader();
|
20
|
-
/**
|
21
|
-
* Instance of native FileReader.
|
22
|
-
*
|
23
|
-
* @private
|
24
|
-
* @member {FileReader} #_reader
|
25
|
-
*/
|
26
20
|
this._reader = reader;
|
27
21
|
this._data = undefined;
|
28
|
-
/**
|
29
|
-
* Number of bytes loaded.
|
30
|
-
*
|
31
|
-
* @readonly
|
32
|
-
* @observable
|
33
|
-
* @member {Number} #loaded
|
34
|
-
*/
|
35
22
|
this.set('loaded', 0);
|
36
23
|
reader.onprogress = evt => {
|
37
24
|
this.loaded = evt.loaded;
|
@@ -39,8 +26,6 @@ export default class FileReader extends ObservableMixin() {
|
|
39
26
|
}
|
40
27
|
/**
|
41
28
|
* Returns error that occurred during file reading.
|
42
|
-
*
|
43
|
-
* @returns {Error}
|
44
29
|
*/
|
45
30
|
get error() {
|
46
31
|
return this._reader.error;
|
@@ -48,8 +33,6 @@ export default class FileReader extends ObservableMixin() {
|
|
48
33
|
/**
|
49
34
|
* Holds the data of an already loaded file. The file must be first loaded
|
50
35
|
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
51
|
-
*
|
52
|
-
* @type {File|undefined}
|
53
36
|
*/
|
54
37
|
get data() {
|
55
38
|
return this._data;
|
@@ -57,8 +40,8 @@ export default class FileReader extends ObservableMixin() {
|
|
57
40
|
/**
|
58
41
|
* Reads the provided file.
|
59
42
|
*
|
60
|
-
* @param
|
61
|
-
* @returns
|
43
|
+
* @param file Native File object.
|
44
|
+
* @returns Returns a promise that will be resolved with file's content.
|
62
45
|
* The promise will be rejected in case of an error or when the reading process is aborted.
|
63
46
|
*/
|
64
47
|
read(file) {
|