@ckeditor/ckeditor5-upload 47.6.1 → 48.0.0-alpha.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.
Files changed (94) hide show
  1. package/ckeditor5-metadata.json +2 -2
  2. package/{src → dist}/adapters/simpleuploadadapter.d.ts +1 -1
  3. package/dist/index.css +3 -0
  4. package/dist/index.css.map +1 -0
  5. package/dist/index.js +2 -3
  6. package/dist/index.js.map +1 -1
  7. package/package.json +20 -40
  8. package/lang/contexts.json +0 -3
  9. package/lang/translations/af.po +0 -16
  10. package/lang/translations/ar.po +0 -16
  11. package/lang/translations/ast.po +0 -16
  12. package/lang/translations/az.po +0 -16
  13. package/lang/translations/be.po +0 -16
  14. package/lang/translations/bg.po +0 -16
  15. package/lang/translations/bn.po +0 -16
  16. package/lang/translations/bs.po +0 -16
  17. package/lang/translations/ca.po +0 -16
  18. package/lang/translations/cs.po +0 -16
  19. package/lang/translations/da.po +0 -16
  20. package/lang/translations/de-ch.po +0 -16
  21. package/lang/translations/de.po +0 -16
  22. package/lang/translations/el.po +0 -16
  23. package/lang/translations/en-au.po +0 -16
  24. package/lang/translations/en-gb.po +0 -16
  25. package/lang/translations/en.po +0 -16
  26. package/lang/translations/eo.po +0 -16
  27. package/lang/translations/es-co.po +0 -16
  28. package/lang/translations/es.po +0 -16
  29. package/lang/translations/et.po +0 -16
  30. package/lang/translations/eu.po +0 -16
  31. package/lang/translations/fa.po +0 -16
  32. package/lang/translations/fi.po +0 -16
  33. package/lang/translations/fr.po +0 -16
  34. package/lang/translations/gl.po +0 -16
  35. package/lang/translations/gu.po +0 -16
  36. package/lang/translations/he.po +0 -16
  37. package/lang/translations/hi.po +0 -16
  38. package/lang/translations/hr.po +0 -16
  39. package/lang/translations/hu.po +0 -16
  40. package/lang/translations/hy.po +0 -16
  41. package/lang/translations/id.po +0 -16
  42. package/lang/translations/it.po +0 -16
  43. package/lang/translations/ja.po +0 -16
  44. package/lang/translations/jv.po +0 -16
  45. package/lang/translations/kk.po +0 -16
  46. package/lang/translations/km.po +0 -16
  47. package/lang/translations/kn.po +0 -16
  48. package/lang/translations/ko.po +0 -16
  49. package/lang/translations/ku.po +0 -16
  50. package/lang/translations/lt.po +0 -16
  51. package/lang/translations/lv.po +0 -16
  52. package/lang/translations/ms.po +0 -16
  53. package/lang/translations/nb.po +0 -16
  54. package/lang/translations/ne.po +0 -16
  55. package/lang/translations/nl.po +0 -16
  56. package/lang/translations/no.po +0 -16
  57. package/lang/translations/oc.po +0 -16
  58. package/lang/translations/pl.po +0 -16
  59. package/lang/translations/pt-br.po +0 -16
  60. package/lang/translations/pt.po +0 -16
  61. package/lang/translations/ro.po +0 -16
  62. package/lang/translations/ru.po +0 -16
  63. package/lang/translations/si.po +0 -16
  64. package/lang/translations/sk.po +0 -16
  65. package/lang/translations/sl.po +0 -16
  66. package/lang/translations/sq.po +0 -16
  67. package/lang/translations/sr-latn.po +0 -16
  68. package/lang/translations/sr.po +0 -16
  69. package/lang/translations/sv.po +0 -16
  70. package/lang/translations/th.po +0 -16
  71. package/lang/translations/ti.po +0 -16
  72. package/lang/translations/tk.po +0 -16
  73. package/lang/translations/tr.po +0 -16
  74. package/lang/translations/tt.po +0 -16
  75. package/lang/translations/ug.po +0 -16
  76. package/lang/translations/uk.po +0 -16
  77. package/lang/translations/ur.po +0 -16
  78. package/lang/translations/uz.po +0 -16
  79. package/lang/translations/vi.po +0 -16
  80. package/lang/translations/zh-cn.po +0 -16
  81. package/lang/translations/zh.po +0 -16
  82. package/src/adapters/base64uploadadapter.js +0 -104
  83. package/src/adapters/simpleuploadadapter.js +0 -205
  84. package/src/augmentation.js +0 -5
  85. package/src/filereader.js +0 -80
  86. package/src/filerepository.js +0 -408
  87. package/src/index.js +0 -12
  88. package/src/uploadconfig.js +0 -5
  89. /package/{src → dist}/adapters/base64uploadadapter.d.ts +0 -0
  90. /package/{src → dist}/augmentation.d.ts +0 -0
  91. /package/{src → dist}/filereader.d.ts +0 -0
  92. /package/{src → dist}/filerepository.d.ts +0 -0
  93. /package/{src → dist}/index.d.ts +0 -0
  94. /package/{src → dist}/uploadconfig.d.ts +0 -0
@@ -1,408 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module upload/filerepository
7
- */
8
- import { Plugin, PendingActions } from '@ckeditor/ckeditor5-core';
9
- import { CKEditorError, Collection, ObservableMixin, logWarning, uid } from '@ckeditor/ckeditor5-utils';
10
- import { FileReader } from './filereader.js';
11
- /**
12
- * File repository plugin. A central point for managing file upload.
13
- *
14
- * To use it, first you need an upload adapter. Upload adapter's job is to handle communication with the server
15
- * (sending the file and handling server's response). You can use one of the existing plugins introducing upload adapters
16
- * (e.g. {@link module:easy-image/cloudservicesuploadadapter~CloudServicesUploadAdapter} or
17
- * {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter}) or write your own one – see
18
- * the {@glink framework/deep-dive/upload-adapter Custom image upload adapter deep-dive} guide.
19
- *
20
- * Then, you can use {@link module:upload/filerepository~FileRepository#createLoader `createLoader()`} and the returned
21
- * {@link module:upload/filerepository~FileLoader} instance to load and upload files.
22
- */
23
- export class FileRepository extends Plugin {
24
- /**
25
- * Collection of loaders associated with this repository.
26
- */
27
- loaders = new Collection();
28
- /**
29
- * Loaders mappings used to retrieve loaders references.
30
- */
31
- _loadersMap = new Map();
32
- /**
33
- * Reference to a pending action registered in a {@link module:core/pendingactions~PendingActions} plugin
34
- * while upload is in progress. When there is no upload then value is `null`.
35
- */
36
- _pendingAction = null;
37
- /**
38
- * @inheritDoc
39
- */
40
- static get pluginName() {
41
- return 'FileRepository';
42
- }
43
- /**
44
- * @inheritDoc
45
- */
46
- static get isOfficialPlugin() {
47
- return true;
48
- }
49
- /**
50
- * @inheritDoc
51
- */
52
- static get requires() {
53
- return [PendingActions];
54
- }
55
- /**
56
- * @inheritDoc
57
- */
58
- init() {
59
- // Keeps upload in a sync with pending actions.
60
- this.loaders.on('change', () => this._updatePendingAction());
61
- this.set('uploaded', 0);
62
- this.set('uploadTotal', null);
63
- this.bind('uploadedPercent').to(this, 'uploaded', this, 'uploadTotal', (uploaded, total) => {
64
- return total ? (uploaded / total * 100) : 0;
65
- });
66
- }
67
- /**
68
- * Returns the loader associated with specified file or promise.
69
- *
70
- * To get loader by id use `fileRepository.loaders.get( id )`.
71
- *
72
- * @param fileOrPromise Native file or promise handle.
73
- */
74
- getLoader(fileOrPromise) {
75
- return this._loadersMap.get(fileOrPromise) || null;
76
- }
77
- /**
78
- * Creates a loader instance for the given file.
79
- *
80
- * Requires {@link #createUploadAdapter} factory to be defined.
81
- *
82
- * @param fileOrPromise Native File object or native Promise object which resolves to a File.
83
- */
84
- createLoader(fileOrPromise) {
85
- if (!this.createUploadAdapter) {
86
- /**
87
- * You need to enable an upload adapter in order to be able to upload files.
88
- *
89
- * This warning shows up when {@link module:upload/filerepository~FileRepository} is being used
90
- * without {@link module:upload/filerepository~FileRepository#createUploadAdapter defining an upload adapter}.
91
- *
92
- * **If you see this warning when using one of the now deprecated
93
- * {@glink getting-started/legacy/installation-methods/predefined-builds CKEditor 5 Builds}**
94
- * it means that you did not configure any of the upload adapters available by default in those builds.
95
- *
96
- * Predefined builds are a deprecated solution and we strongly advise
97
- * {@glink updating/nim-migration/migration-to-new-installation-methods migrating to new installation methods}.
98
- *
99
- * See the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn which upload
100
- * adapters are available in the builds and how to configure them.
101
- *
102
- * Otherwise, if you see this warning, there is a chance that you enabled
103
- * a feature like {@link module:image/imageupload~ImageUpload},
104
- * or {@link module:image/imageupload/imageuploadui~ImageUploadUI} but you did not enable any upload adapter.
105
- * You can choose one of the existing upload adapters listed in the
106
- * {@glink features/images/image-upload/image-upload "Image upload overview"}.
107
- *
108
- * You can also implement your {@glink framework/deep-dive/upload-adapter own image upload adapter}.
109
- *
110
- * @error filerepository-no-upload-adapter
111
- */
112
- logWarning('filerepository-no-upload-adapter');
113
- return null;
114
- }
115
- const loader = new FileLoader(Promise.resolve(fileOrPromise), this.createUploadAdapter);
116
- this.loaders.add(loader);
117
- this._loadersMap.set(fileOrPromise, loader);
118
- // Store also file => loader mapping so loader can be retrieved by file instance returned upon Promise resolution.
119
- if (fileOrPromise instanceof Promise) {
120
- loader.file
121
- .then(file => {
122
- this._loadersMap.set(file, loader);
123
- })
124
- // Every then() must have a catch().
125
- // File loader state (and rejections) are handled in read() and upload().
126
- // Also, see the "does not swallow the file promise rejection" test.
127
- .catch(() => { });
128
- }
129
- loader.on('change:uploaded', () => {
130
- let aggregatedUploaded = 0;
131
- for (const loader of this.loaders) {
132
- aggregatedUploaded += loader.uploaded;
133
- }
134
- this.uploaded = aggregatedUploaded;
135
- });
136
- loader.on('change:uploadTotal', () => {
137
- let aggregatedTotal = 0;
138
- for (const loader of this.loaders) {
139
- if (loader.uploadTotal) {
140
- aggregatedTotal += loader.uploadTotal;
141
- }
142
- }
143
- this.uploadTotal = aggregatedTotal;
144
- });
145
- return loader;
146
- }
147
- /**
148
- * Destroys the given loader.
149
- *
150
- * @param fileOrPromiseOrLoader File or Promise associated with that loader or loader itself.
151
- */
152
- destroyLoader(fileOrPromiseOrLoader) {
153
- const loader = fileOrPromiseOrLoader instanceof FileLoader ? fileOrPromiseOrLoader : this.getLoader(fileOrPromiseOrLoader);
154
- loader._destroy();
155
- this.loaders.remove(loader);
156
- this._loadersMap.forEach((value, key) => {
157
- if (value === loader) {
158
- this._loadersMap.delete(key);
159
- }
160
- });
161
- }
162
- /**
163
- * Registers or deregisters pending action bound with upload progress.
164
- */
165
- _updatePendingAction() {
166
- const pendingActions = this.editor.plugins.get(PendingActions);
167
- if (this.loaders.length) {
168
- if (!this._pendingAction) {
169
- const t = this.editor.t;
170
- const getMessage = (value) => `${t('Upload in progress')} ${parseInt(value)}%.`;
171
- this._pendingAction = pendingActions.add(getMessage(this.uploadedPercent));
172
- this._pendingAction.bind('message').to(this, 'uploadedPercent', getMessage);
173
- }
174
- }
175
- else {
176
- pendingActions.remove(this._pendingAction);
177
- this._pendingAction = null;
178
- }
179
- }
180
- }
181
- /**
182
- * File loader class.
183
- *
184
- * It is used to control the process of reading the file and uploading it using the specified upload adapter.
185
- */
186
- class FileLoader extends /* #__PURE__ */ ObservableMixin() {
187
- /**
188
- * Unique id of FileLoader instance.
189
- *
190
- * @readonly
191
- */
192
- id;
193
- /**
194
- * Additional wrapper over the initial file promise passed to this loader.
195
- */
196
- _filePromiseWrapper;
197
- /**
198
- * Adapter instance associated with this file loader.
199
- */
200
- _adapter;
201
- /**
202
- * FileReader used by FileLoader.
203
- */
204
- _reader;
205
- /**
206
- * Creates a new instance of `FileLoader`.
207
- *
208
- * @param filePromise A promise which resolves to a file instance.
209
- * @param uploadAdapterCreator The function which returns {@link module:upload/filerepository~UploadAdapter} instance.
210
- */
211
- constructor(filePromise, uploadAdapterCreator) {
212
- super();
213
- this.id = uid();
214
- this._filePromiseWrapper = this._createFilePromiseWrapper(filePromise);
215
- this._adapter = uploadAdapterCreator(this);
216
- this._reader = new FileReader();
217
- this.set('status', 'idle');
218
- this.set('uploaded', 0);
219
- this.set('uploadTotal', null);
220
- this.bind('uploadedPercent').to(this, 'uploaded', this, 'uploadTotal', (uploaded, total) => {
221
- return total ? (uploaded / total * 100) : 0;
222
- });
223
- this.set('uploadResponse', null);
224
- }
225
- /**
226
- * A `Promise` which resolves to a `File` instance associated with this file loader.
227
- */
228
- get file() {
229
- if (!this._filePromiseWrapper) {
230
- // Loader was destroyed, return promise which resolves to null.
231
- return Promise.resolve(null);
232
- }
233
- else {
234
- // The `this._filePromiseWrapper.promise` is chained and not simply returned to handle a case when:
235
- //
236
- // * The `loader.file.then( ... )` is called by external code (returned promise is pending).
237
- // * Then `loader._destroy()` is called (call is synchronous) which destroys the `loader`.
238
- // * Promise returned by the first `loader.file.then( ... )` call is resolved.
239
- //
240
- // Returning `this._filePromiseWrapper.promise` will still resolve to a `File` instance so there
241
- // is an additional check needed in the chain to see if `loader` was destroyed in the meantime.
242
- return this._filePromiseWrapper.promise.then(file => this._filePromiseWrapper ? file : null);
243
- }
244
- }
245
- /**
246
- * Returns the file data. To read its data, you need for first load the file
247
- * by using the {@link module:upload/filerepository~FileLoader#read `read()`} method.
248
- */
249
- get data() {
250
- return this._reader.data;
251
- }
252
- /**
253
- * Reads file using {@link module:upload/filereader~FileReader}.
254
- *
255
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-read-wrong-status` when status
256
- * is different than `idle`.
257
- *
258
- * Example usage:
259
- *
260
- * ```ts
261
- * fileLoader.read()
262
- * .then( data => { ... } )
263
- * .catch( err => {
264
- * if ( err === 'aborted' ) {
265
- * console.log( 'Reading aborted.' );
266
- * } else {
267
- * console.log( 'Reading error.', err );
268
- * }
269
- * } );
270
- * ```
271
- *
272
- * @returns Returns promise that will be resolved with read data. Promise will be rejected if error
273
- * occurs or if read process is aborted.
274
- */
275
- read() {
276
- if (this.status != 'idle') {
277
- /**
278
- * You cannot call read if the status is different than idle.
279
- *
280
- * @error filerepository-read-wrong-status
281
- */
282
- throw new CKEditorError('filerepository-read-wrong-status', this);
283
- }
284
- this.status = 'reading';
285
- return this.file
286
- .then(file => this._reader.read(file))
287
- .then(data => {
288
- // Edge case: reader was aborted after file was read - double check for proper status.
289
- // It can happen when image was deleted during its upload.
290
- if (this.status !== 'reading') {
291
- throw this.status;
292
- }
293
- this.status = 'idle';
294
- return data;
295
- })
296
- .catch(err => {
297
- if (err === 'aborted') {
298
- this.status = 'aborted';
299
- throw 'aborted';
300
- }
301
- this.status = 'error';
302
- throw this._reader.error ? this._reader.error : err;
303
- });
304
- }
305
- /**
306
- * Reads file using the provided {@link module:upload/filerepository~UploadAdapter}.
307
- *
308
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-upload-wrong-status` when status
309
- * is different than `idle`.
310
- * Example usage:
311
- *
312
- * ```ts
313
- * fileLoader.upload()
314
- * .then( data => { ... } )
315
- * .catch( e => {
316
- * if ( e === 'aborted' ) {
317
- * console.log( 'Uploading aborted.' );
318
- * } else {
319
- * console.log( 'Uploading error.', e );
320
- * }
321
- * } );
322
- * ```
323
- *
324
- * @returns Returns promise that will be resolved with response data. Promise will be rejected if error
325
- * occurs or if read process is aborted.
326
- */
327
- upload() {
328
- if (this.status != 'idle') {
329
- /**
330
- * You cannot call upload if the status is different than idle.
331
- *
332
- * @error filerepository-upload-wrong-status
333
- */
334
- throw new CKEditorError('filerepository-upload-wrong-status', this);
335
- }
336
- this.status = 'uploading';
337
- return this.file
338
- .then(() => this._adapter.upload())
339
- .then(data => {
340
- this.uploadResponse = data;
341
- this.status = 'idle';
342
- return data;
343
- })
344
- .catch(err => {
345
- if (this.status === 'aborted') {
346
- throw 'aborted';
347
- }
348
- this.status = 'error';
349
- throw err;
350
- });
351
- }
352
- /**
353
- * Aborts loading process.
354
- */
355
- abort() {
356
- const status = this.status;
357
- this.status = 'aborted';
358
- if (!this._filePromiseWrapper.isFulfilled) {
359
- // Edge case: file loader is aborted before read() is called
360
- // so it might happen that no one handled the rejection of this promise.
361
- // See https://github.com/ckeditor/ckeditor5-upload/pull/100
362
- this._filePromiseWrapper.promise.catch(() => { });
363
- this._filePromiseWrapper.rejecter('aborted');
364
- }
365
- else if (status == 'reading') {
366
- this._reader.abort();
367
- }
368
- else if (status == 'uploading' && this._adapter.abort) {
369
- this._adapter.abort();
370
- }
371
- this._destroy();
372
- }
373
- /**
374
- * Performs cleanup.
375
- *
376
- * @internal
377
- */
378
- _destroy() {
379
- this._filePromiseWrapper = undefined;
380
- this._reader = undefined;
381
- this._adapter = undefined;
382
- this.uploadResponse = undefined;
383
- }
384
- /**
385
- * Wraps a given file promise into another promise giving additional
386
- * control (resolving, rejecting, checking if fulfilled) over it.
387
- *
388
- * @param filePromise The initial file promise to be wrapped.
389
- */
390
- _createFilePromiseWrapper(filePromise) {
391
- const wrapper = {};
392
- wrapper.promise = new Promise((resolve, reject) => {
393
- wrapper.rejecter = reject;
394
- wrapper.isFulfilled = false;
395
- filePromise
396
- .then(file => {
397
- wrapper.isFulfilled = true;
398
- resolve(file);
399
- })
400
- .catch(err => {
401
- wrapper.isFulfilled = true;
402
- reject(err);
403
- });
404
- });
405
- return wrapper;
406
- }
407
- }
408
- export { FileLoader };
package/src/index.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module upload
7
- */
8
- export { FileRepository } from './filerepository.js';
9
- export { Base64UploadAdapter } from './adapters/base64uploadadapter.js';
10
- export { SimpleUploadAdapter } from './adapters/simpleuploadadapter.js';
11
- export { FileReader } from './filereader.js';
12
- import './augmentation.js';
@@ -1,5 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes