@ckeditor/ckeditor5-upload 0.0.0-internal-20241017.0 → 0.0.0-internal-20241206.0
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/LICENSE.md +7 -2
- package/README.md +17 -6
- package/dist/index.js +208 -238
- package/dist/index.js.map +1 -1
- package/dist/translations/af.d.ts +8 -0
- package/dist/translations/af.js +5 -0
- package/dist/translations/af.umd.js +11 -0
- package/dist/translations/ar.js +1 -1
- package/dist/translations/ar.umd.js +1 -1
- package/dist/translations/ast.d.ts +8 -0
- package/dist/translations/ast.js +5 -0
- package/dist/translations/ast.umd.js +11 -0
- package/dist/translations/bs.d.ts +8 -0
- package/dist/translations/bs.js +5 -0
- package/dist/translations/bs.umd.js +11 -0
- package/dist/translations/cs.js +1 -1
- package/dist/translations/cs.umd.js +1 -1
- package/dist/translations/en.js +1 -1
- package/dist/translations/en.umd.js +1 -1
- package/dist/translations/eo.d.ts +8 -0
- package/dist/translations/eo.js +5 -0
- package/dist/translations/eo.umd.js +11 -0
- package/dist/translations/es-co.js +1 -1
- package/dist/translations/es-co.umd.js +1 -1
- package/dist/translations/es.js +1 -1
- package/dist/translations/es.umd.js +1 -1
- package/dist/translations/eu.d.ts +8 -0
- package/dist/translations/eu.js +5 -0
- package/dist/translations/eu.umd.js +11 -0
- package/dist/translations/fa.js +1 -1
- package/dist/translations/fa.umd.js +1 -1
- package/dist/translations/fr.js +1 -1
- package/dist/translations/fr.umd.js +1 -1
- package/dist/translations/gu.d.ts +8 -0
- package/dist/translations/gu.js +5 -0
- package/dist/translations/gu.umd.js +11 -0
- package/dist/translations/he.js +1 -1
- package/dist/translations/he.umd.js +1 -1
- package/dist/translations/hr.js +1 -1
- package/dist/translations/hr.umd.js +1 -1
- package/dist/translations/hy.d.ts +8 -0
- package/dist/translations/hy.js +5 -0
- package/dist/translations/hy.umd.js +11 -0
- package/dist/translations/it.js +1 -1
- package/dist/translations/it.umd.js +1 -1
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/jv.umd.js +11 -0
- package/dist/translations/kk.d.ts +8 -0
- package/dist/translations/kk.js +5 -0
- package/dist/translations/kk.umd.js +11 -0
- package/dist/translations/km.d.ts +8 -0
- package/dist/translations/km.js +5 -0
- package/dist/translations/km.umd.js +11 -0
- package/dist/translations/kn.d.ts +8 -0
- package/dist/translations/kn.js +5 -0
- package/dist/translations/kn.umd.js +11 -0
- package/dist/translations/lt.js +1 -1
- package/dist/translations/lt.umd.js +1 -1
- package/dist/translations/lv.js +1 -1
- package/dist/translations/lv.umd.js +1 -1
- package/dist/translations/oc.d.ts +8 -0
- package/dist/translations/oc.js +5 -0
- package/dist/translations/oc.umd.js +11 -0
- package/dist/translations/pl.js +1 -1
- package/dist/translations/pl.umd.js +1 -1
- package/dist/translations/pt-br.js +1 -1
- package/dist/translations/pt-br.umd.js +1 -1
- package/dist/translations/pt.js +1 -1
- package/dist/translations/pt.umd.js +1 -1
- package/dist/translations/ro.js +1 -1
- package/dist/translations/ro.umd.js +1 -1
- package/dist/translations/ru.js +1 -1
- package/dist/translations/ru.umd.js +1 -1
- package/dist/translations/si.d.ts +8 -0
- package/dist/translations/si.js +5 -0
- package/dist/translations/si.umd.js +11 -0
- package/dist/translations/sk.js +1 -1
- package/dist/translations/sk.umd.js +1 -1
- package/dist/translations/sl.d.ts +8 -0
- package/dist/translations/sl.js +5 -0
- package/dist/translations/sl.umd.js +11 -0
- package/dist/translations/sr-latn.js +1 -1
- package/dist/translations/sr-latn.umd.js +1 -1
- package/dist/translations/sr.js +1 -1
- package/dist/translations/sr.umd.js +1 -1
- package/dist/translations/ti.d.ts +8 -0
- package/dist/translations/ti.js +5 -0
- package/dist/translations/ti.umd.js +11 -0
- package/dist/translations/tt.d.ts +8 -0
- package/dist/translations/tt.js +5 -0
- package/dist/translations/tt.umd.js +11 -0
- package/dist/translations/ug.js +1 -1
- package/dist/translations/ug.umd.js +1 -1
- package/dist/translations/uk.js +1 -1
- package/dist/translations/uk.umd.js +1 -1
- package/dist/translations/uz.js +1 -1
- package/dist/translations/uz.umd.js +1 -1
- package/lang/translations/af.po +16 -0
- package/lang/translations/ar.po +4 -10
- package/lang/translations/ast.po +16 -0
- package/lang/translations/az.po +3 -9
- package/lang/translations/bg.po +3 -9
- package/lang/translations/bn.po +3 -9
- package/lang/translations/bs.po +16 -0
- package/lang/translations/ca.po +3 -9
- package/lang/translations/cs.po +4 -10
- package/lang/translations/da.po +3 -9
- package/lang/translations/de-ch.po +3 -9
- package/lang/translations/de.po +3 -9
- package/lang/translations/el.po +3 -9
- package/lang/translations/en-au.po +3 -9
- package/lang/translations/en-gb.po +3 -9
- package/lang/translations/en.po +5 -11
- package/lang/translations/eo.po +16 -0
- package/lang/translations/es-co.po +4 -10
- package/lang/translations/es.po +4 -10
- package/lang/translations/et.po +3 -9
- package/lang/translations/eu.po +16 -0
- package/lang/translations/fa.po +4 -10
- package/lang/translations/fi.po +3 -9
- package/lang/translations/fr.po +4 -10
- package/lang/translations/gl.po +3 -9
- package/lang/translations/gu.po +16 -0
- package/lang/translations/he.po +4 -10
- package/lang/translations/hi.po +3 -9
- package/lang/translations/hr.po +4 -10
- package/lang/translations/hu.po +3 -9
- package/lang/translations/hy.po +16 -0
- package/lang/translations/id.po +3 -9
- package/lang/translations/it.po +4 -10
- package/lang/translations/ja.po +3 -9
- package/lang/translations/jv.po +16 -0
- package/lang/translations/kk.po +16 -0
- package/lang/translations/km.po +16 -0
- package/lang/translations/kn.po +16 -0
- package/lang/translations/ko.po +3 -9
- package/lang/translations/ku.po +3 -9
- package/lang/translations/lt.po +4 -10
- package/lang/translations/lv.po +4 -10
- package/lang/translations/ms.po +3 -9
- package/lang/translations/nb.po +3 -9
- package/lang/translations/ne.po +3 -9
- package/lang/translations/nl.po +3 -9
- package/lang/translations/no.po +3 -9
- package/lang/translations/oc.po +16 -0
- package/lang/translations/pl.po +4 -10
- package/lang/translations/pt-br.po +4 -10
- package/lang/translations/pt.po +4 -10
- package/lang/translations/ro.po +4 -10
- package/lang/translations/ru.po +4 -10
- package/lang/translations/si.po +16 -0
- package/lang/translations/sk.po +4 -10
- package/lang/translations/sl.po +16 -0
- package/lang/translations/sq.po +3 -9
- package/lang/translations/sr-latn.po +4 -10
- package/lang/translations/sr.po +4 -10
- package/lang/translations/sv.po +3 -9
- package/lang/translations/th.po +3 -9
- package/lang/translations/ti.po +16 -0
- package/lang/translations/tk.po +3 -9
- package/lang/translations/tr.po +3 -9
- package/lang/translations/tt.po +16 -0
- package/lang/translations/ug.po +4 -10
- package/lang/translations/uk.po +4 -10
- package/lang/translations/ur.po +3 -9
- package/lang/translations/uz.po +4 -10
- package/lang/translations/vi.po +3 -9
- package/lang/translations/zh-cn.po +3 -9
- package/lang/translations/zh.po +3 -9
- package/package.json +22 -5
- package/src/adapters/base64uploadadapter.d.ts +1 -1
- package/src/adapters/base64uploadadapter.js +1 -1
- package/src/adapters/simpleuploadadapter.d.ts +1 -1
- package/src/adapters/simpleuploadadapter.js +1 -1
- package/src/augmentation.d.ts +1 -1
- package/src/augmentation.js +1 -1
- package/src/filereader.d.ts +1 -1
- package/src/filereader.js +1 -1
- package/src/filerepository.d.ts +1 -1
- package/src/filerepository.js +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/uploadconfig.d.ts +1 -1
- package/src/uploadconfig.js +1 -1
- package/dist/adapters/base64uploadadapter.d.ts +0 -41
- package/dist/adapters/simpleuploadadapter.d.ts +0 -56
- package/dist/augmentation.d.ts +0 -24
- package/dist/filereader.d.ts +0 -60
- package/dist/filerepository.d.ts +0 -350
- package/dist/index.d.ts +0 -16
- package/dist/uploadconfig.d.ts +0 -94
package/dist/index.js
CHANGED
|
@@ -8,17 +8,9 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
8
8
|
/**
|
|
9
9
|
* Wrapper over the native `FileReader`.
|
|
10
10
|
*/ class FileReader extends /* #__PURE__ */ ObservableMixin() {
|
|
11
|
-
total;
|
|
12
11
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Holds the data of an already loaded file. The file must be first loaded
|
|
17
|
-
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
|
18
|
-
*/ _data;
|
|
19
|
-
/**
|
|
20
|
-
* Creates an instance of the FileReader.
|
|
21
|
-
*/ constructor(){
|
|
12
|
+
* Creates an instance of the FileReader.
|
|
13
|
+
*/ constructor(){
|
|
22
14
|
super();
|
|
23
15
|
const reader = new window.FileReader();
|
|
24
16
|
this._reader = reader;
|
|
@@ -29,23 +21,23 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
29
21
|
};
|
|
30
22
|
}
|
|
31
23
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
* Returns error that occurred during file reading.
|
|
25
|
+
*/ get error() {
|
|
34
26
|
return this._reader.error;
|
|
35
27
|
}
|
|
36
28
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
* Holds the data of an already loaded file. The file must be first loaded
|
|
30
|
+
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
|
31
|
+
*/ get data() {
|
|
40
32
|
return this._data;
|
|
41
33
|
}
|
|
42
34
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
* Reads the provided file.
|
|
36
|
+
*
|
|
37
|
+
* @param file Native File object.
|
|
38
|
+
* @returns Returns a promise that will be resolved with file's content.
|
|
39
|
+
* The promise will be rejected in case of an error or when the reading process is aborted.
|
|
40
|
+
*/ read(file) {
|
|
49
41
|
const reader = this._reader;
|
|
50
42
|
this.total = file.size;
|
|
51
43
|
return new Promise((resolve, reject)=>{
|
|
@@ -64,8 +56,8 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
64
56
|
});
|
|
65
57
|
}
|
|
66
58
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
* Aborts file reader.
|
|
60
|
+
*/ abort() {
|
|
69
61
|
this._reader.abort();
|
|
70
62
|
}
|
|
71
63
|
}
|
|
@@ -82,36 +74,39 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
82
74
|
* Then, you can use {@link module:upload/filerepository~FileRepository#createLoader `createLoader()`} and the returned
|
|
83
75
|
* {@link module:upload/filerepository~FileLoader} instance to load and upload files.
|
|
84
76
|
*/ class FileRepository extends Plugin {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
constructor(){
|
|
78
|
+
super(...arguments);
|
|
79
|
+
/**
|
|
80
|
+
* Collection of loaders associated with this repository.
|
|
81
|
+
*/ this.loaders = new Collection();
|
|
82
|
+
/**
|
|
83
|
+
* Loaders mappings used to retrieve loaders references.
|
|
84
|
+
*/ this._loadersMap = new Map();
|
|
85
|
+
/**
|
|
86
|
+
* Reference to a pending action registered in a {@link module:core/pendingactions~PendingActions} plugin
|
|
87
|
+
* while upload is in progress. When there is no upload then value is `null`.
|
|
88
|
+
*/ this._pendingAction = null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @inheritDoc
|
|
92
|
+
*/ static get pluginName() {
|
|
98
93
|
return 'FileRepository';
|
|
99
94
|
}
|
|
100
95
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
* @inheritDoc
|
|
97
|
+
*/ static get isOfficialPlugin() {
|
|
103
98
|
return true;
|
|
104
99
|
}
|
|
105
100
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
* @inheritDoc
|
|
102
|
+
*/ static get requires() {
|
|
108
103
|
return [
|
|
109
104
|
PendingActions
|
|
110
105
|
];
|
|
111
106
|
}
|
|
112
107
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
* @inheritDoc
|
|
109
|
+
*/ init() {
|
|
115
110
|
// Keeps upload in a sync with pending actions.
|
|
116
111
|
this.loaders.on('change', ()=>this._updatePendingAction());
|
|
117
112
|
this.set('uploaded', 0);
|
|
@@ -121,48 +116,48 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
121
116
|
});
|
|
122
117
|
}
|
|
123
118
|
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
* Returns the loader associated with specified file or promise.
|
|
120
|
+
*
|
|
121
|
+
* To get loader by id use `fileRepository.loaders.get( id )`.
|
|
122
|
+
*
|
|
123
|
+
* @param fileOrPromise Native file or promise handle.
|
|
124
|
+
*/ getLoader(fileOrPromise) {
|
|
130
125
|
return this._loadersMap.get(fileOrPromise) || null;
|
|
131
126
|
}
|
|
132
127
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
* Creates a loader instance for the given file.
|
|
129
|
+
*
|
|
130
|
+
* Requires {@link #createUploadAdapter} factory to be defined.
|
|
131
|
+
*
|
|
132
|
+
* @param fileOrPromise Native File object or native Promise object which resolves to a File.
|
|
133
|
+
*/ createLoader(fileOrPromise) {
|
|
139
134
|
if (!this.createUploadAdapter) {
|
|
140
135
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
136
|
+
* You need to enable an upload adapter in order to be able to upload files.
|
|
137
|
+
*
|
|
138
|
+
* This warning shows up when {@link module:upload/filerepository~FileRepository} is being used
|
|
139
|
+
* without {@link module:upload/filerepository~FileRepository#createUploadAdapter defining an upload adapter}.
|
|
140
|
+
*
|
|
141
|
+
* **If you see this warning when using one of the {@glink getting-started/legacy/installation-methods/predefined-builds
|
|
142
|
+
* CKEditor 5 Builds}**
|
|
143
|
+
* it means that you did not configure any of the upload adapters available by default in those builds.
|
|
144
|
+
*
|
|
145
|
+
* Predefined builds are a deprecated solution and we strongly advise
|
|
146
|
+
* {@glink updating/nim-migration/migration-to-new-installation-methods migrating to new installation methods}.
|
|
147
|
+
*
|
|
148
|
+
* See the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn which upload
|
|
149
|
+
* adapters are available in the builds and how to configure them.
|
|
150
|
+
*
|
|
151
|
+
* Otherwise, if you see this warning, there is a chance that you enabled
|
|
152
|
+
* a feature like {@link module:image/imageupload~ImageUpload},
|
|
153
|
+
* or {@link module:image/imageupload/imageuploadui~ImageUploadUI} but you did not enable any upload adapter.
|
|
154
|
+
* You can choose one of the existing upload adapters listed in the
|
|
155
|
+
* {@glink features/images/image-upload/image-upload "Image upload overview"}.
|
|
156
|
+
*
|
|
157
|
+
* You can also implement your {@glink framework/deep-dive/upload-adapter own image upload adapter}.
|
|
158
|
+
*
|
|
159
|
+
* @error filerepository-no-upload-adapter
|
|
160
|
+
*/ logWarning('filerepository-no-upload-adapter');
|
|
166
161
|
return null;
|
|
167
162
|
}
|
|
168
163
|
const loader = new FileLoader(Promise.resolve(fileOrPromise), this.createUploadAdapter);
|
|
@@ -196,10 +191,10 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
196
191
|
return loader;
|
|
197
192
|
}
|
|
198
193
|
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
194
|
+
* Destroys the given loader.
|
|
195
|
+
*
|
|
196
|
+
* @param fileOrPromiseOrLoader File or Promise associated with that loader or loader itself.
|
|
197
|
+
*/ destroyLoader(fileOrPromiseOrLoader) {
|
|
203
198
|
const loader = fileOrPromiseOrLoader instanceof FileLoader ? fileOrPromiseOrLoader : this.getLoader(fileOrPromiseOrLoader);
|
|
204
199
|
loader._destroy();
|
|
205
200
|
this.loaders.remove(loader);
|
|
@@ -210,8 +205,8 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
210
205
|
});
|
|
211
206
|
}
|
|
212
207
|
/**
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
* Registers or deregisters pending action bound with upload progress.
|
|
209
|
+
*/ _updatePendingAction() {
|
|
215
210
|
const pendingActions = this.editor.plugins.get(PendingActions);
|
|
216
211
|
if (this.loaders.length) {
|
|
217
212
|
if (!this._pendingAction) {
|
|
@@ -232,25 +227,11 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
232
227
|
* It is used to control the process of reading the file and uploading it using the specified upload adapter.
|
|
233
228
|
*/ class FileLoader extends /* #__PURE__ */ ObservableMixin() {
|
|
234
229
|
/**
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
* Additional wrapper over the initial file promise passed to this loader.
|
|
241
|
-
*/ _filePromiseWrapper;
|
|
242
|
-
/**
|
|
243
|
-
* Adapter instance associated with this file loader.
|
|
244
|
-
*/ _adapter;
|
|
245
|
-
/**
|
|
246
|
-
* FileReader used by FileLoader.
|
|
247
|
-
*/ _reader;
|
|
248
|
-
/**
|
|
249
|
-
* Creates a new instance of `FileLoader`.
|
|
250
|
-
*
|
|
251
|
-
* @param filePromise A promise which resolves to a file instance.
|
|
252
|
-
* @param uploadAdapterCreator The function which returns {@link module:upload/filerepository~UploadAdapter} instance.
|
|
253
|
-
*/ constructor(filePromise, uploadAdapterCreator){
|
|
230
|
+
* Creates a new instance of `FileLoader`.
|
|
231
|
+
*
|
|
232
|
+
* @param filePromise A promise which resolves to a file instance.
|
|
233
|
+
* @param uploadAdapterCreator The function which returns {@link module:upload/filerepository~UploadAdapter} instance.
|
|
234
|
+
*/ constructor(filePromise, uploadAdapterCreator){
|
|
254
235
|
super();
|
|
255
236
|
this.id = uid();
|
|
256
237
|
this._filePromiseWrapper = this._createFilePromiseWrapper(filePromise);
|
|
@@ -265,8 +246,8 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
265
246
|
this.set('uploadResponse', null);
|
|
266
247
|
}
|
|
267
248
|
/**
|
|
268
|
-
|
|
269
|
-
|
|
249
|
+
* A `Promise` which resolves to a `File` instance associated with this file loader.
|
|
250
|
+
*/ get file() {
|
|
270
251
|
if (!this._filePromiseWrapper) {
|
|
271
252
|
// Loader was destroyed, return promise which resolves to null.
|
|
272
253
|
return Promise.resolve(null);
|
|
@@ -283,40 +264,40 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
283
264
|
}
|
|
284
265
|
}
|
|
285
266
|
/**
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
267
|
+
* Returns the file data. To read its data, you need for first load the file
|
|
268
|
+
* by using the {@link module:upload/filerepository~FileLoader#read `read()`} method.
|
|
269
|
+
*/ get data() {
|
|
289
270
|
return this._reader.data;
|
|
290
271
|
}
|
|
291
272
|
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
273
|
+
* Reads file using {@link module:upload/filereader~FileReader}.
|
|
274
|
+
*
|
|
275
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-read-wrong-status` when status
|
|
276
|
+
* is different than `idle`.
|
|
277
|
+
*
|
|
278
|
+
* Example usage:
|
|
279
|
+
*
|
|
280
|
+
* ```ts
|
|
281
|
+
* fileLoader.read()
|
|
282
|
+
* .then( data => { ... } )
|
|
283
|
+
* .catch( err => {
|
|
284
|
+
* if ( err === 'aborted' ) {
|
|
285
|
+
* console.log( 'Reading aborted.' );
|
|
286
|
+
* } else {
|
|
287
|
+
* console.log( 'Reading error.', err );
|
|
288
|
+
* }
|
|
289
|
+
* } );
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* @returns Returns promise that will be resolved with read data. Promise will be rejected if error
|
|
293
|
+
* occurs or if read process is aborted.
|
|
294
|
+
*/ read() {
|
|
314
295
|
if (this.status != 'idle') {
|
|
315
296
|
/**
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
297
|
+
* You cannot call read if the status is different than idle.
|
|
298
|
+
*
|
|
299
|
+
* @error filerepository-read-wrong-status
|
|
300
|
+
*/ throw new CKEditorError('filerepository-read-wrong-status', this);
|
|
320
301
|
}
|
|
321
302
|
this.status = 'reading';
|
|
322
303
|
return this.file.then((file)=>this._reader.read(file)).then((data)=>{
|
|
@@ -337,33 +318,33 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
337
318
|
});
|
|
338
319
|
}
|
|
339
320
|
/**
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
321
|
+
* Reads file using the provided {@link module:upload/filerepository~UploadAdapter}.
|
|
322
|
+
*
|
|
323
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-upload-wrong-status` when status
|
|
324
|
+
* is different than `idle`.
|
|
325
|
+
* Example usage:
|
|
326
|
+
*
|
|
327
|
+
* ```ts
|
|
328
|
+
* fileLoader.upload()
|
|
329
|
+
* .then( data => { ... } )
|
|
330
|
+
* .catch( e => {
|
|
331
|
+
* if ( e === 'aborted' ) {
|
|
332
|
+
* console.log( 'Uploading aborted.' );
|
|
333
|
+
* } else {
|
|
334
|
+
* console.log( 'Uploading error.', e );
|
|
335
|
+
* }
|
|
336
|
+
* } );
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @returns Returns promise that will be resolved with response data. Promise will be rejected if error
|
|
340
|
+
* occurs or if read process is aborted.
|
|
341
|
+
*/ upload() {
|
|
361
342
|
if (this.status != 'idle') {
|
|
362
343
|
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
344
|
+
* You cannot call upload if the status is different than idle.
|
|
345
|
+
*
|
|
346
|
+
* @error filerepository-upload-wrong-status
|
|
347
|
+
*/ throw new CKEditorError('filerepository-upload-wrong-status', this);
|
|
367
348
|
}
|
|
368
349
|
this.status = 'uploading';
|
|
369
350
|
return this.file.then(()=>this._adapter.upload()).then((data)=>{
|
|
@@ -379,8 +360,8 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
379
360
|
});
|
|
380
361
|
}
|
|
381
362
|
/**
|
|
382
|
-
|
|
383
|
-
|
|
363
|
+
* Aborts loading process.
|
|
364
|
+
*/ abort() {
|
|
384
365
|
const status = this.status;
|
|
385
366
|
this.status = 'aborted';
|
|
386
367
|
if (!this._filePromiseWrapper.isFulfilled) {
|
|
@@ -397,21 +378,21 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
397
378
|
this._destroy();
|
|
398
379
|
}
|
|
399
380
|
/**
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
381
|
+
* Performs cleanup.
|
|
382
|
+
*
|
|
383
|
+
* @internal
|
|
384
|
+
*/ _destroy() {
|
|
404
385
|
this._filePromiseWrapper = undefined;
|
|
405
386
|
this._reader = undefined;
|
|
406
387
|
this._adapter = undefined;
|
|
407
388
|
this.uploadResponse = undefined;
|
|
408
389
|
}
|
|
409
390
|
/**
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
391
|
+
* Wraps a given file promise into another promise giving additional
|
|
392
|
+
* control (resolving, rejecting, checking if fulfilled) over it.
|
|
393
|
+
*
|
|
394
|
+
* @param filePromise The initial file promise to be wrapped.
|
|
395
|
+
*/ _createFilePromiseWrapper(filePromise) {
|
|
415
396
|
const wrapper = {};
|
|
416
397
|
wrapper.promise = new Promise((resolve, reject)=>{
|
|
417
398
|
wrapper.rejecter = reject;
|
|
@@ -439,25 +420,25 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
439
420
|
* other ways to upload images into CKEditor 5.
|
|
440
421
|
*/ class Base64UploadAdapter extends Plugin {
|
|
441
422
|
/**
|
|
442
|
-
|
|
443
|
-
|
|
423
|
+
* @inheritDoc
|
|
424
|
+
*/ static get requires() {
|
|
444
425
|
return [
|
|
445
426
|
FileRepository
|
|
446
427
|
];
|
|
447
428
|
}
|
|
448
429
|
/**
|
|
449
|
-
|
|
450
|
-
|
|
430
|
+
* @inheritDoc
|
|
431
|
+
*/ static get pluginName() {
|
|
451
432
|
return 'Base64UploadAdapter';
|
|
452
433
|
}
|
|
453
434
|
/**
|
|
454
|
-
|
|
455
|
-
|
|
435
|
+
* @inheritDoc
|
|
436
|
+
*/ static get isOfficialPlugin() {
|
|
456
437
|
return true;
|
|
457
438
|
}
|
|
458
439
|
/**
|
|
459
|
-
|
|
460
|
-
|
|
440
|
+
* @inheritDoc
|
|
441
|
+
*/ init() {
|
|
461
442
|
this.editor.plugins.get(FileRepository).createUploadAdapter = (loader)=>new Adapter$1(loader);
|
|
462
443
|
}
|
|
463
444
|
}
|
|
@@ -465,19 +446,15 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
465
446
|
* The upload adapter that converts images inserted into the editor into Base64 strings.
|
|
466
447
|
*/ let Adapter$1 = class Adapter {
|
|
467
448
|
/**
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
reader;
|
|
471
|
-
/**
|
|
472
|
-
* Creates a new adapter instance.
|
|
473
|
-
*/ constructor(loader){
|
|
449
|
+
* Creates a new adapter instance.
|
|
450
|
+
*/ constructor(loader){
|
|
474
451
|
this.loader = loader;
|
|
475
452
|
}
|
|
476
453
|
/**
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
454
|
+
* Starts the upload process.
|
|
455
|
+
*
|
|
456
|
+
* @see module:upload/filerepository~UploadAdapter#upload
|
|
457
|
+
*/ upload() {
|
|
481
458
|
return new Promise((resolve, reject)=>{
|
|
482
459
|
const reader = this.reader = new window.FileReader();
|
|
483
460
|
reader.addEventListener('load', ()=>{
|
|
@@ -497,10 +474,10 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
497
474
|
});
|
|
498
475
|
}
|
|
499
476
|
/**
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
477
|
+
* Aborts the upload process.
|
|
478
|
+
*
|
|
479
|
+
* @see module:upload/filerepository~UploadAdapter#abort
|
|
480
|
+
*/ abort() {
|
|
504
481
|
this.reader.abort();
|
|
505
482
|
}
|
|
506
483
|
};
|
|
@@ -531,37 +508,37 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
531
508
|
* other ways to upload images into CKEditor 5.
|
|
532
509
|
*/ class SimpleUploadAdapter extends Plugin {
|
|
533
510
|
/**
|
|
534
|
-
|
|
535
|
-
|
|
511
|
+
* @inheritDoc
|
|
512
|
+
*/ static get requires() {
|
|
536
513
|
return [
|
|
537
514
|
FileRepository
|
|
538
515
|
];
|
|
539
516
|
}
|
|
540
517
|
/**
|
|
541
|
-
|
|
542
|
-
|
|
518
|
+
* @inheritDoc
|
|
519
|
+
*/ static get pluginName() {
|
|
543
520
|
return 'SimpleUploadAdapter';
|
|
544
521
|
}
|
|
545
522
|
/**
|
|
546
|
-
|
|
547
|
-
|
|
523
|
+
* @inheritDoc
|
|
524
|
+
*/ static get isOfficialPlugin() {
|
|
548
525
|
return true;
|
|
549
526
|
}
|
|
550
527
|
/**
|
|
551
|
-
|
|
552
|
-
|
|
528
|
+
* @inheritDoc
|
|
529
|
+
*/ init() {
|
|
553
530
|
const options = this.editor.config.get('simpleUpload');
|
|
554
531
|
if (!options) {
|
|
555
532
|
return;
|
|
556
533
|
}
|
|
557
534
|
if (!options.uploadUrl) {
|
|
558
535
|
/**
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
536
|
+
* The {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `config.simpleUpload.uploadUrl`}
|
|
537
|
+
* configuration required by the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter `SimpleUploadAdapter`}
|
|
538
|
+
* is missing. Make sure the correct URL is specified for the image upload to work properly.
|
|
539
|
+
*
|
|
540
|
+
* @error simple-upload-adapter-missing-uploadurl
|
|
541
|
+
*/ logWarning('simple-upload-adapter-missing-uploadurl');
|
|
565
542
|
return;
|
|
566
543
|
}
|
|
567
544
|
this.editor.plugins.get(FileRepository).createUploadAdapter = (loader)=>{
|
|
@@ -573,23 +550,16 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
573
550
|
* Upload adapter.
|
|
574
551
|
*/ class Adapter {
|
|
575
552
|
/**
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* The configuration of the adapter.
|
|
580
|
-
*/ options;
|
|
581
|
-
xhr;
|
|
582
|
-
/**
|
|
583
|
-
* Creates a new adapter instance.
|
|
584
|
-
*/ constructor(loader, options){
|
|
553
|
+
* Creates a new adapter instance.
|
|
554
|
+
*/ constructor(loader, options){
|
|
585
555
|
this.loader = loader;
|
|
586
556
|
this.options = options;
|
|
587
557
|
}
|
|
588
558
|
/**
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
559
|
+
* Starts the upload process.
|
|
560
|
+
*
|
|
561
|
+
* @see module:upload/filerepository~UploadAdapter#upload
|
|
562
|
+
*/ upload() {
|
|
593
563
|
return this.loader.file.then((file)=>new Promise((resolve, reject)=>{
|
|
594
564
|
this._initRequest();
|
|
595
565
|
this._initListeners(resolve, reject, file);
|
|
@@ -597,30 +567,30 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
597
567
|
}));
|
|
598
568
|
}
|
|
599
569
|
/**
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
570
|
+
* Aborts the upload process.
|
|
571
|
+
*
|
|
572
|
+
* @see module:upload/filerepository~UploadAdapter#abort
|
|
573
|
+
*/ abort() {
|
|
604
574
|
if (this.xhr) {
|
|
605
575
|
this.xhr.abort();
|
|
606
576
|
}
|
|
607
577
|
}
|
|
608
578
|
/**
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
579
|
+
* Initializes the `XMLHttpRequest` object using the URL specified as
|
|
580
|
+
* {@link module:upload/uploadconfig~SimpleUploadConfig#uploadUrl `simpleUpload.uploadUrl`} in the editor's
|
|
581
|
+
* configuration.
|
|
582
|
+
*/ _initRequest() {
|
|
613
583
|
const xhr = this.xhr = new XMLHttpRequest();
|
|
614
584
|
xhr.open('POST', this.options.uploadUrl, true);
|
|
615
585
|
xhr.responseType = 'json';
|
|
616
586
|
}
|
|
617
587
|
/**
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
588
|
+
* Initializes XMLHttpRequest listeners
|
|
589
|
+
*
|
|
590
|
+
* @param resolve Callback function to be called when the request is successful.
|
|
591
|
+
* @param reject Callback function to be called when the request cannot be completed.
|
|
592
|
+
* @param file Native File object.
|
|
593
|
+
*/ _initListeners(resolve, reject, file) {
|
|
624
594
|
const xhr = this.xhr;
|
|
625
595
|
const loader = this.loader;
|
|
626
596
|
const genericErrorText = `Couldn't upload file: ${file.name}.`;
|
|
@@ -652,10 +622,10 @@ import { ObservableMixin, Collection, logWarning, uid, CKEditorError } from '@ck
|
|
|
652
622
|
}
|
|
653
623
|
}
|
|
654
624
|
/**
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
625
|
+
* Prepares the data and sends the request.
|
|
626
|
+
*
|
|
627
|
+
* @param file File instance to be uploaded.
|
|
628
|
+
*/ _sendRequest(file) {
|
|
659
629
|
// Set headers if specified.
|
|
660
630
|
const headers = this.options.headers || {};
|
|
661
631
|
// Use the withCredentials flag if specified.
|