@ckeditor/ckeditor5-upload 0.0.0-nightly-20240422.0 → 0.0.0-nightly-20240424.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/dist/index-content.css +4 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +4 -0
- package/dist/index.js +582 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/es-co.d.ts +8 -0
- package/dist/translations/es-co.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/nb.d.ts +8 -0
- package/dist/translations/nb.js +5 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/adapters/base64uploadadapter.d.ts +37 -0
- package/dist/types/adapters/simpleuploadadapter.d.ts +52 -0
- package/dist/types/augmentation.d.ts +24 -0
- package/dist/types/filereader.d.ts +60 -0
- package/dist/types/filerepository.d.ts +346 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/uploadconfig.d.ts +94 -0
- package/package.json +4 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
import type { Translations } from 'ckeditor5';
|
|
7
|
+
declare const translations: Translations;
|
|
8
|
+
export default translations;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
export default {"zh":{"dictionary":{"Upload in progress":"正在上傳"},getPluralForm(n){return 0;}}}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module upload/adapters/base64uploadadapter
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
13
|
+
import FileRepository from '../filerepository.js';
|
|
14
|
+
/**
|
|
15
|
+
* A plugin that converts images inserted into the editor into [Base64 strings](https://en.wikipedia.org/wiki/Base64)
|
|
16
|
+
* in the {@glink installation/getting-started/getting-and-setting-data editor output}.
|
|
17
|
+
*
|
|
18
|
+
* This kind of image upload does not require server processing – images are stored with the rest of the text and
|
|
19
|
+
* displayed by the web browser without additional requests.
|
|
20
|
+
*
|
|
21
|
+
* Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
|
|
22
|
+
* other ways to upload images into CKEditor 5.
|
|
23
|
+
*/
|
|
24
|
+
export default class Base64UploadAdapter extends Plugin {
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
static get requires(): readonly [typeof FileRepository];
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
static get pluginName(): "Base64UploadAdapter";
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
init(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module upload/adapters/simpleuploadadapter
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
13
|
+
import FileRepository from '../filerepository.js';
|
|
14
|
+
/**
|
|
15
|
+
* The Simple upload adapter allows uploading images to an application running on your server using
|
|
16
|
+
* the [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) API with a
|
|
17
|
+
* minimal {@link module:upload/uploadconfig~SimpleUploadConfig editor configuration}.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* ClassicEditor
|
|
21
|
+
* .create( document.querySelector( '#editor' ), {
|
|
22
|
+
* simpleUpload: {
|
|
23
|
+
* uploadUrl: 'http://example.com',
|
|
24
|
+
* headers: {
|
|
25
|
+
* ...
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* } )
|
|
29
|
+
* .then( ... )
|
|
30
|
+
* .catch( ... );
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* See the {@glink features/images/image-upload/simple-upload-adapter "Simple upload adapter"} guide to learn how to
|
|
34
|
+
* learn more about the feature (configuration, server–side requirements, etc.).
|
|
35
|
+
*
|
|
36
|
+
* Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
|
|
37
|
+
* other ways to upload images into CKEditor 5.
|
|
38
|
+
*/
|
|
39
|
+
export default class SimpleUploadAdapter extends Plugin {
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
static get requires(): readonly [typeof FileRepository];
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
*/
|
|
47
|
+
static get pluginName(): "SimpleUploadAdapter";
|
|
48
|
+
/**
|
|
49
|
+
* @inheritDoc
|
|
50
|
+
*/
|
|
51
|
+
init(): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
import type { SimpleUploadConfig, FileRepository, SimpleUploadAdapter, Base64UploadAdapter } from './index.js';
|
|
10
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
11
|
+
interface EditorConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The configuration of the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter simple upload adapter}.
|
|
14
|
+
*
|
|
15
|
+
* Read more in {@link module:upload/uploadconfig~SimpleUploadConfig}.
|
|
16
|
+
*/
|
|
17
|
+
simpleUpload?: SimpleUploadConfig;
|
|
18
|
+
}
|
|
19
|
+
interface PluginsMap {
|
|
20
|
+
[FileRepository.pluginName]: FileRepository;
|
|
21
|
+
[SimpleUploadAdapter.pluginName]: SimpleUploadAdapter;
|
|
22
|
+
[Base64UploadAdapter.pluginName]: Base64UploadAdapter;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
declare const FileReader_base: {
|
|
10
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
|
11
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Wrapper over the native `FileReader`.
|
|
15
|
+
*/
|
|
16
|
+
export default class FileReader extends FileReader_base {
|
|
17
|
+
total: number;
|
|
18
|
+
/**
|
|
19
|
+
* Instance of native FileReader.
|
|
20
|
+
*/
|
|
21
|
+
private readonly _reader;
|
|
22
|
+
/**
|
|
23
|
+
* Holds the data of an already loaded file. The file must be first loaded
|
|
24
|
+
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
|
25
|
+
*/
|
|
26
|
+
private _data?;
|
|
27
|
+
/**
|
|
28
|
+
* Number of bytes loaded.
|
|
29
|
+
*
|
|
30
|
+
* @readonly
|
|
31
|
+
* @observable
|
|
32
|
+
*/
|
|
33
|
+
loaded: number;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an instance of the FileReader.
|
|
36
|
+
*/
|
|
37
|
+
constructor();
|
|
38
|
+
/**
|
|
39
|
+
* Returns error that occurred during file reading.
|
|
40
|
+
*/
|
|
41
|
+
get error(): DOMException | null;
|
|
42
|
+
/**
|
|
43
|
+
* Holds the data of an already loaded file. The file must be first loaded
|
|
44
|
+
* by using {@link module:upload/filereader~FileReader#read `read()`}.
|
|
45
|
+
*/
|
|
46
|
+
get data(): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Reads the provided file.
|
|
49
|
+
*
|
|
50
|
+
* @param file Native File object.
|
|
51
|
+
* @returns Returns a promise that will be resolved with file's content.
|
|
52
|
+
* The promise will be rejected in case of an error or when the reading process is aborted.
|
|
53
|
+
*/
|
|
54
|
+
read(file: File): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Aborts file reader.
|
|
57
|
+
*/
|
|
58
|
+
abort(): void;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module upload/filerepository
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin, PendingActions } from '@ckeditor/ckeditor5-core';
|
|
13
|
+
import { Collection } from '@ckeditor/ckeditor5-utils';
|
|
14
|
+
/**
|
|
15
|
+
* File repository plugin. A central point for managing file upload.
|
|
16
|
+
*
|
|
17
|
+
* To use it, first you need an upload adapter. Upload adapter's job is to handle communication with the server
|
|
18
|
+
* (sending the file and handling server's response). You can use one of the existing plugins introducing upload adapters
|
|
19
|
+
* (e.g. {@link module:easy-image/cloudservicesuploadadapter~CloudServicesUploadAdapter} or
|
|
20
|
+
* {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter}) or write your own one – see
|
|
21
|
+
* the {@glink framework/deep-dive/upload-adapter Custom image upload adapter deep-dive} guide.
|
|
22
|
+
*
|
|
23
|
+
* Then, you can use {@link module:upload/filerepository~FileRepository#createLoader `createLoader()`} and the returned
|
|
24
|
+
* {@link module:upload/filerepository~FileLoader} instance to load and upload files.
|
|
25
|
+
*/
|
|
26
|
+
export default class FileRepository extends Plugin {
|
|
27
|
+
/**
|
|
28
|
+
* Collection of loaders associated with this repository.
|
|
29
|
+
*/
|
|
30
|
+
loaders: Collection<FileLoader>;
|
|
31
|
+
/**
|
|
32
|
+
* A factory function which should be defined before using `FileRepository`.
|
|
33
|
+
*
|
|
34
|
+
* It should return a new instance of {@link module:upload/filerepository~UploadAdapter} that will be used to upload files.
|
|
35
|
+
* {@link module:upload/filerepository~FileLoader} instance associated with the adapter
|
|
36
|
+
* will be passed to that function.
|
|
37
|
+
*
|
|
38
|
+
* For more information and example see {@link module:upload/filerepository~UploadAdapter}.
|
|
39
|
+
*/
|
|
40
|
+
createUploadAdapter?: (loader: FileLoader) => UploadAdapter;
|
|
41
|
+
/**
|
|
42
|
+
* Loaders mappings used to retrieve loaders references.
|
|
43
|
+
*/
|
|
44
|
+
private _loadersMap;
|
|
45
|
+
/**
|
|
46
|
+
* Reference to a pending action registered in a {@link module:core/pendingactions~PendingActions} plugin
|
|
47
|
+
* while upload is in progress. When there is no upload then value is `null`.
|
|
48
|
+
*/
|
|
49
|
+
private _pendingAction;
|
|
50
|
+
/**
|
|
51
|
+
* Number of bytes uploaded.
|
|
52
|
+
*
|
|
53
|
+
* @readonly
|
|
54
|
+
* @observable
|
|
55
|
+
*/
|
|
56
|
+
uploaded: number;
|
|
57
|
+
/**
|
|
58
|
+
* Number of total bytes to upload.
|
|
59
|
+
*
|
|
60
|
+
* It might be different than the file size because of headers and additional data.
|
|
61
|
+
* It contains `null` if value is not available yet, so it's better to use {@link #uploadedPercent} to monitor
|
|
62
|
+
* the progress.
|
|
63
|
+
*
|
|
64
|
+
* @readonly
|
|
65
|
+
* @observable
|
|
66
|
+
*/
|
|
67
|
+
uploadTotal: number | null;
|
|
68
|
+
/**
|
|
69
|
+
* Upload progress in percents.
|
|
70
|
+
*
|
|
71
|
+
* @readonly
|
|
72
|
+
* @observable
|
|
73
|
+
*/
|
|
74
|
+
uploadedPercent: number;
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
78
|
+
static get pluginName(): "FileRepository";
|
|
79
|
+
/**
|
|
80
|
+
* @inheritDoc
|
|
81
|
+
*/
|
|
82
|
+
static get requires(): readonly [typeof PendingActions];
|
|
83
|
+
/**
|
|
84
|
+
* @inheritDoc
|
|
85
|
+
*/
|
|
86
|
+
init(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the loader associated with specified file or promise.
|
|
89
|
+
*
|
|
90
|
+
* To get loader by id use `fileRepository.loaders.get( id )`.
|
|
91
|
+
*
|
|
92
|
+
* @param fileOrPromise Native file or promise handle.
|
|
93
|
+
*/
|
|
94
|
+
getLoader(fileOrPromise: File | Promise<File>): FileLoader | null;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a loader instance for the given file.
|
|
97
|
+
*
|
|
98
|
+
* Requires {@link #createUploadAdapter} factory to be defined.
|
|
99
|
+
*
|
|
100
|
+
* @param fileOrPromise Native File object or native Promise object which resolves to a File.
|
|
101
|
+
*/
|
|
102
|
+
createLoader(fileOrPromise: File | Promise<File>): FileLoader | null;
|
|
103
|
+
/**
|
|
104
|
+
* Destroys the given loader.
|
|
105
|
+
*
|
|
106
|
+
* @param fileOrPromiseOrLoader File or Promise associated with that loader or loader itself.
|
|
107
|
+
*/
|
|
108
|
+
destroyLoader(fileOrPromiseOrLoader: File | Promise<File> | FileLoader): void;
|
|
109
|
+
/**
|
|
110
|
+
* Registers or deregisters pending action bound with upload progress.
|
|
111
|
+
*/
|
|
112
|
+
private _updatePendingAction;
|
|
113
|
+
}
|
|
114
|
+
declare const FileLoader_base: {
|
|
115
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
|
116
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* File loader class.
|
|
120
|
+
*
|
|
121
|
+
* It is used to control the process of reading the file and uploading it using the specified upload adapter.
|
|
122
|
+
*/
|
|
123
|
+
declare class FileLoader extends FileLoader_base {
|
|
124
|
+
/**
|
|
125
|
+
* Unique id of FileLoader instance.
|
|
126
|
+
*
|
|
127
|
+
* @readonly
|
|
128
|
+
*/
|
|
129
|
+
readonly id: string;
|
|
130
|
+
/**
|
|
131
|
+
* Additional wrapper over the initial file promise passed to this loader.
|
|
132
|
+
*/
|
|
133
|
+
private _filePromiseWrapper;
|
|
134
|
+
/**
|
|
135
|
+
* Adapter instance associated with this file loader.
|
|
136
|
+
*/
|
|
137
|
+
private _adapter;
|
|
138
|
+
/**
|
|
139
|
+
* FileReader used by FileLoader.
|
|
140
|
+
*/
|
|
141
|
+
private _reader;
|
|
142
|
+
/**
|
|
143
|
+
* Current status of FileLoader. It can be one of the following:
|
|
144
|
+
*
|
|
145
|
+
* * 'idle',
|
|
146
|
+
* * 'reading',
|
|
147
|
+
* * 'uploading',
|
|
148
|
+
* * 'aborted',
|
|
149
|
+
* * 'error'.
|
|
150
|
+
*
|
|
151
|
+
* When reading status can change in a following way:
|
|
152
|
+
*
|
|
153
|
+
* `idle` -> `reading` -> `idle`
|
|
154
|
+
* `idle` -> `reading -> `aborted`
|
|
155
|
+
* `idle` -> `reading -> `error`
|
|
156
|
+
*
|
|
157
|
+
* When uploading status can change in a following way:
|
|
158
|
+
*
|
|
159
|
+
* `idle` -> `uploading` -> `idle`
|
|
160
|
+
* `idle` -> `uploading` -> `aborted`
|
|
161
|
+
* `idle` -> `uploading` -> `error`
|
|
162
|
+
*
|
|
163
|
+
* @readonly
|
|
164
|
+
* @observable
|
|
165
|
+
*/
|
|
166
|
+
status: 'idle' | 'reading' | 'uploading' | 'aborted' | 'error';
|
|
167
|
+
/**
|
|
168
|
+
* Number of bytes uploaded.
|
|
169
|
+
*
|
|
170
|
+
* @readonly
|
|
171
|
+
* @observable
|
|
172
|
+
*/
|
|
173
|
+
uploaded: number;
|
|
174
|
+
/**
|
|
175
|
+
* Number of total bytes to upload.
|
|
176
|
+
*
|
|
177
|
+
* @readonly
|
|
178
|
+
* @observable
|
|
179
|
+
*/
|
|
180
|
+
uploadTotal: number | null;
|
|
181
|
+
/**
|
|
182
|
+
* Upload progress in percents.
|
|
183
|
+
*
|
|
184
|
+
* @readonly
|
|
185
|
+
* @observable
|
|
186
|
+
*/
|
|
187
|
+
uploadedPercent: number;
|
|
188
|
+
/**
|
|
189
|
+
* Response of the upload.
|
|
190
|
+
*
|
|
191
|
+
* @readonly
|
|
192
|
+
* @observable
|
|
193
|
+
*/
|
|
194
|
+
uploadResponse?: UploadResponse | null;
|
|
195
|
+
/**
|
|
196
|
+
* Creates a new instance of `FileLoader`.
|
|
197
|
+
*
|
|
198
|
+
* @param filePromise A promise which resolves to a file instance.
|
|
199
|
+
* @param uploadAdapterCreator The function which returns {@link module:upload/filerepository~UploadAdapter} instance.
|
|
200
|
+
*/
|
|
201
|
+
constructor(filePromise: Promise<File>, uploadAdapterCreator: (loader: FileLoader) => UploadAdapter);
|
|
202
|
+
/**
|
|
203
|
+
* A `Promise` which resolves to a `File` instance associated with this file loader.
|
|
204
|
+
*/
|
|
205
|
+
get file(): Promise<File | null>;
|
|
206
|
+
/**
|
|
207
|
+
* Returns the file data. To read its data, you need for first load the file
|
|
208
|
+
* by using the {@link module:upload/filerepository~FileLoader#read `read()`} method.
|
|
209
|
+
*/
|
|
210
|
+
get data(): string | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Reads file using {@link module:upload/filereader~FileReader}.
|
|
213
|
+
*
|
|
214
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-read-wrong-status` when status
|
|
215
|
+
* is different than `idle`.
|
|
216
|
+
*
|
|
217
|
+
* Example usage:
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* fileLoader.read()
|
|
221
|
+
* .then( data => { ... } )
|
|
222
|
+
* .catch( err => {
|
|
223
|
+
* if ( err === 'aborted' ) {
|
|
224
|
+
* console.log( 'Reading aborted.' );
|
|
225
|
+
* } else {
|
|
226
|
+
* console.log( 'Reading error.', err );
|
|
227
|
+
* }
|
|
228
|
+
* } );
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @returns Returns promise that will be resolved with read data. Promise will be rejected if error
|
|
232
|
+
* occurs or if read process is aborted.
|
|
233
|
+
*/
|
|
234
|
+
read(): Promise<string>;
|
|
235
|
+
/**
|
|
236
|
+
* Reads file using the provided {@link module:upload/filerepository~UploadAdapter}.
|
|
237
|
+
*
|
|
238
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `filerepository-upload-wrong-status` when status
|
|
239
|
+
* is different than `idle`.
|
|
240
|
+
* Example usage:
|
|
241
|
+
*
|
|
242
|
+
* ```ts
|
|
243
|
+
* fileLoader.upload()
|
|
244
|
+
* .then( data => { ... } )
|
|
245
|
+
* .catch( e => {
|
|
246
|
+
* if ( e === 'aborted' ) {
|
|
247
|
+
* console.log( 'Uploading aborted.' );
|
|
248
|
+
* } else {
|
|
249
|
+
* console.log( 'Uploading error.', e );
|
|
250
|
+
* }
|
|
251
|
+
* } );
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @returns Returns promise that will be resolved with response data. Promise will be rejected if error
|
|
255
|
+
* occurs or if read process is aborted.
|
|
256
|
+
*/
|
|
257
|
+
upload(): Promise<UploadResponse>;
|
|
258
|
+
/**
|
|
259
|
+
* Aborts loading process.
|
|
260
|
+
*/
|
|
261
|
+
abort(): void;
|
|
262
|
+
/**
|
|
263
|
+
* Performs cleanup.
|
|
264
|
+
*
|
|
265
|
+
* @internal
|
|
266
|
+
*/
|
|
267
|
+
_destroy(): void;
|
|
268
|
+
/**
|
|
269
|
+
* Wraps a given file promise into another promise giving additional
|
|
270
|
+
* control (resolving, rejecting, checking if fulfilled) over it.
|
|
271
|
+
*
|
|
272
|
+
* @param filePromise The initial file promise to be wrapped.
|
|
273
|
+
*/
|
|
274
|
+
private _createFilePromiseWrapper;
|
|
275
|
+
}
|
|
276
|
+
export type { FileLoader };
|
|
277
|
+
/**
|
|
278
|
+
* Upload adapter interface used by the {@link module:upload/filerepository~FileRepository file repository}
|
|
279
|
+
* to handle file upload. An upload adapter is a bridge between the editor and server that handles file uploads.
|
|
280
|
+
* It should contain a logic necessary to initiate an upload process and monitor its progress.
|
|
281
|
+
*
|
|
282
|
+
* Learn how to develop your own upload adapter for CKEditor 5 in the
|
|
283
|
+
* {@glink framework/deep-dive/upload-adapter "Custom upload adapter"} guide.
|
|
284
|
+
*
|
|
285
|
+
* @interface UploadAdapter
|
|
286
|
+
*/
|
|
287
|
+
export interface UploadAdapter {
|
|
288
|
+
/**
|
|
289
|
+
* Executes the upload process.
|
|
290
|
+
* This method should return a promise that will resolve when data will be uploaded to server. Promise should be
|
|
291
|
+
* resolved with an object containing information about uploaded file:
|
|
292
|
+
*
|
|
293
|
+
* ```json
|
|
294
|
+
* {
|
|
295
|
+
* default: 'http://server/default-size.image.png'
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* Additionally, other image sizes can be provided:
|
|
300
|
+
*
|
|
301
|
+
* ```json
|
|
302
|
+
* {
|
|
303
|
+
* default: 'http://server/default-size.image.png',
|
|
304
|
+
* '160': 'http://server/size-160.image.png',
|
|
305
|
+
* '500': 'http://server/size-500.image.png',
|
|
306
|
+
* '1000': 'http://server/size-1000.image.png',
|
|
307
|
+
* '1052': 'http://server/default-size.image.png'
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* You can also pass additional properties from the server. In this case you need to wrap URLs
|
|
312
|
+
* in the `urls` object and pass additional properties along the `urls` property.
|
|
313
|
+
*
|
|
314
|
+
* ```json
|
|
315
|
+
* {
|
|
316
|
+
* myCustomProperty: 'foo',
|
|
317
|
+
* urls: {
|
|
318
|
+
* default: 'http://server/default-size.image.png',
|
|
319
|
+
* '160': 'http://server/size-160.image.png',
|
|
320
|
+
* '500': 'http://server/size-500.image.png',
|
|
321
|
+
* '1000': 'http://server/size-1000.image.png',
|
|
322
|
+
* '1052': 'http://server/default-size.image.png'
|
|
323
|
+
* }
|
|
324
|
+
* }
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
327
|
+
* NOTE: When returning multiple images, the widest returned one should equal the default one. It is essential to
|
|
328
|
+
* correctly set `width` attribute of the image. See this discussion:
|
|
329
|
+
* https://github.com/ckeditor/ckeditor5-easy-image/issues/4 for more information.
|
|
330
|
+
*
|
|
331
|
+
* Take a look at {@link module:upload/filerepository~UploadAdapter example Adapter implementation} and
|
|
332
|
+
* {@link module:upload/filerepository~FileRepository#createUploadAdapter createUploadAdapter method}.
|
|
333
|
+
*
|
|
334
|
+
* @returns Promise that should be resolved when data is uploaded.
|
|
335
|
+
*/
|
|
336
|
+
upload(): Promise<UploadResponse>;
|
|
337
|
+
/**
|
|
338
|
+
* Aborts the upload process.
|
|
339
|
+
* After aborting it should reject promise returned from {@link #upload upload()}.
|
|
340
|
+
*
|
|
341
|
+
* Take a look at {@link module:upload/filerepository~UploadAdapter example Adapter implementation} and
|
|
342
|
+
* {@link module:upload/filerepository~FileRepository#createUploadAdapter createUploadAdapter method}.
|
|
343
|
+
*/
|
|
344
|
+
abort?(): void;
|
|
345
|
+
}
|
|
346
|
+
export type UploadResponse = Record<string, unknown>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module upload
|
|
11
|
+
*/
|
|
12
|
+
export { default as FileRepository, type UploadAdapter, type UploadResponse, type FileLoader } from './filerepository.js';
|
|
13
|
+
export { default as Base64UploadAdapter } from './adapters/base64uploadadapter.js';
|
|
14
|
+
export { default as SimpleUploadAdapter } from './adapters/simpleuploadadapter.js';
|
|
15
|
+
export type { SimpleUploadConfig } from './uploadconfig.js';
|
|
16
|
+
import './augmentation.js';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module upload/uploadconfig
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The configuration of the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter simple upload adapter}.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* ClassicEditor
|
|
17
|
+
* .create( editorElement, {
|
|
18
|
+
* simpleUpload: {
|
|
19
|
+
* // The URL the images are uploaded to.
|
|
20
|
+
* uploadUrl: 'http://example.com',
|
|
21
|
+
*
|
|
22
|
+
* // Headers sent along with the XMLHttpRequest to the upload server.
|
|
23
|
+
* headers: {
|
|
24
|
+
* ...
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* } );
|
|
28
|
+
* .then( ... )
|
|
29
|
+
* .catch( ... );
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* See the {@glink features/images/image-upload/simple-upload-adapter "Simple upload adapter"} guide to learn more.
|
|
33
|
+
*
|
|
34
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
|
|
35
|
+
*/
|
|
36
|
+
export interface SimpleUploadConfig {
|
|
37
|
+
/**
|
|
38
|
+
* The path (URL) to the server (application) which handles the file upload. When specified, enables the automatic
|
|
39
|
+
* upload of resources (images) inserted into the editor content.
|
|
40
|
+
*
|
|
41
|
+
* Learn more about the server application requirements in the
|
|
42
|
+
* {@glink features/images/image-upload/simple-upload-adapter#server-side-configuration "Server-side configuration"} section
|
|
43
|
+
* of the feature guide.
|
|
44
|
+
*/
|
|
45
|
+
uploadUrl: string;
|
|
46
|
+
/**
|
|
47
|
+
* An object that defines additional [headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers) sent with
|
|
48
|
+
* the request to the server during the upload. This is the right place to implement security mechanisms like
|
|
49
|
+
* authentication and [CSRF](https://developer.mozilla.org/en-US/docs/Glossary/CSRF) protection.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* ClassicEditor
|
|
53
|
+
* .create( editorElement, {
|
|
54
|
+
* simpleUpload: {
|
|
55
|
+
* headers: {
|
|
56
|
+
* 'X-CSRF-TOKEN': 'CSRF-Token',
|
|
57
|
+
* Authorization: 'Bearer <JSON Web Token>'
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* } );
|
|
61
|
+
* .then( ... )
|
|
62
|
+
* .catch( ... );
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Learn more about the server application requirements in the
|
|
66
|
+
* {@glink features/images/image-upload/simple-upload-adapter#server-side-configuration "Server-side configuration"} section
|
|
67
|
+
* of the feature guide.
|
|
68
|
+
*/
|
|
69
|
+
headers?: Record<string, string>;
|
|
70
|
+
/**
|
|
71
|
+
* This flag enables the
|
|
72
|
+
* [`withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials)
|
|
73
|
+
* property of the request sent to the server during the upload. It affects cross-site requests only and, for instance,
|
|
74
|
+
* allows credentials such as cookies to be sent along with the request.
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* ClassicEditor
|
|
78
|
+
* .create( editorElement, {
|
|
79
|
+
* simpleUpload: {
|
|
80
|
+
* withCredentials: true
|
|
81
|
+
* }
|
|
82
|
+
* } );
|
|
83
|
+
* .then( ... )
|
|
84
|
+
* .catch( ... );
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* Learn more about the server application requirements in the
|
|
88
|
+
* {@glink features/images/image-upload/simple-upload-adapter#server-side-configuration "Server-side configuration"} section
|
|
89
|
+
* of the feature guide.
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
withCredentials?: boolean;
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-upload",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20240424.0",
|
|
4
4
|
"description": "Upload feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-core": "0.0.0-nightly-
|
|
16
|
-
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-
|
|
15
|
+
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20240424.0",
|
|
16
|
+
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20240424.0"
|
|
17
17
|
},
|
|
18
18
|
"author": "CKSource (http://cksource.com/)",
|
|
19
19
|
"license": "GPL-2.0-or-later",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"directory": "packages/ckeditor5-upload"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
+
"dist",
|
|
28
29
|
"lang",
|
|
29
30
|
"src/**/*.js",
|
|
30
31
|
"src/**/*.d.ts",
|