@ckeditor/ckeditor5-adapter-ckfinder 35.3.2 → 36.0.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 CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor 5 CKFinder adapter** – https://github.com/ckeditor/ckeditor5-adapter-ckfinder <br>
5
- Copyright (c) 2003-2022, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -1,4 +1,4 @@
1
1
  /*!
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
4
  */(()=>{var e={704:(e,t,r)=>{e.exports=r(79)("./src/core.js")},448:(e,t,r)=>{e.exports=r(79)("./src/upload.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o](s,s.exports,r),s.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";r.r(o),r.d(o,{UploadAdapter:()=>d});var e=r(704),t=r(448);const n="ckCsrfToken",s="abcdefghijklmnopqrstuvwxyz0123456789";function i(){let e=function(e){e=e.toLowerCase();const t=document.cookie.split(";");for(const r of t){const t=r.split("=");if(decodeURIComponent(t[0].trim().toLowerCase())===e)return decodeURIComponent(t[1])}return null}(n);var t,r;return e&&40==e.length||(e=function(e){let t="";const r=new Uint8Array(e);window.crypto.getRandomValues(r);for(let e=0;e<r.length;e++){const o=s.charAt(r[e]%s.length);t+=Math.random()>.5?o.toUpperCase():o}return t}(40),t=n,r=e,document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(r)+";path=/"),e}class d extends e.Plugin{static get requires(){return[t.FileRepository]}static get pluginName(){return"CKFinderUploadAdapter"}init(){const e=this.editor.config.get("ckfinder.uploadUrl");e&&(this.editor.plugins.get(t.FileRepository).createUploadAdapter=t=>new a(t,e,this.editor.t))}}class a{constructor(e,t,r){this.loader=e,this.url=t,this.t=r}upload(){return this.loader.file.then((e=>new Promise(((t,r)=>{this._initRequest(),this._initListeners(t,r,e),this._sendRequest(e)}))))}abort(){this.xhr&&this.xhr.abort()}_initRequest(){const e=this.xhr=new XMLHttpRequest;e.open("POST",this.url,!0),e.responseType="json"}_initListeners(e,t,r){const o=this.xhr,n=this.loader,s=(0,this.t)("Cannot upload file:")+` ${r.name}.`;o.addEventListener("error",(()=>t(s))),o.addEventListener("abort",(()=>t())),o.addEventListener("load",(()=>{const r=o.response;if(!r||!r.uploaded)return t(r&&r.error&&r.error.message?r.error.message:s);e({default:r.url})})),o.upload&&o.upload.addEventListener("progress",(e=>{e.lengthComputable&&(n.uploadTotal=e.total,n.uploaded=e.loaded)}))}_sendRequest(e){const t=new FormData;t.append("upload",e),t.append("ckCsrfToken",i()),this.xhr.send(t)}}})(),(window.CKEditor5=window.CKEditor5||{}).adapterCkfinder=o})();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "plugins": [
3
3
  {
4
- "name": "CKFinder Upload Adapter",
4
+ "name": "CKFinder upload adapter",
5
5
  "className": "CKFinderUploadAdapter",
6
6
  "path": "src/uploadadapter.js",
7
7
  "description": "Implements the CKEditor 5 upload adapter compatible with the CKFinder file manager and uploader's server–side connector.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-adapter-ckfinder",
3
- "version": "35.3.2",
3
+ "version": "36.0.0",
4
4
  "description": "CKFinder adapter for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,23 +12,24 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^35.3.2"
15
+ "ckeditor5": "^36.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-basic-styles": "^35.3.2",
19
- "@ckeditor/ckeditor5-core": "^35.3.2",
20
- "@ckeditor/ckeditor5-clipboard": "^35.3.2",
21
- "@ckeditor/ckeditor5-dev-utils": "^31.0.0",
22
- "@ckeditor/ckeditor5-editor-classic": "^35.3.2",
23
- "@ckeditor/ckeditor5-enter": "^35.3.2",
24
- "@ckeditor/ckeditor5-heading": "^35.3.2",
25
- "@ckeditor/ckeditor5-image": "^35.3.2",
26
- "@ckeditor/ckeditor5-list": "^35.3.2",
27
- "@ckeditor/ckeditor5-paragraph": "^35.3.2",
28
- "@ckeditor/ckeditor5-theme-lark": "^35.3.2",
29
- "@ckeditor/ckeditor5-typing": "^35.3.2",
30
- "@ckeditor/ckeditor5-undo": "^35.3.2",
31
- "@ckeditor/ckeditor5-upload": "^35.3.2",
18
+ "@ckeditor/ckeditor5-basic-styles": "^36.0.0",
19
+ "@ckeditor/ckeditor5-core": "^36.0.0",
20
+ "@ckeditor/ckeditor5-clipboard": "^36.0.0",
21
+ "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
22
+ "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
23
+ "@ckeditor/ckeditor5-enter": "^36.0.0",
24
+ "@ckeditor/ckeditor5-heading": "^36.0.0",
25
+ "@ckeditor/ckeditor5-image": "^36.0.0",
26
+ "@ckeditor/ckeditor5-list": "^36.0.0",
27
+ "@ckeditor/ckeditor5-paragraph": "^36.0.0",
28
+ "@ckeditor/ckeditor5-theme-lark": "^36.0.0",
29
+ "@ckeditor/ckeditor5-typing": "^36.0.0",
30
+ "@ckeditor/ckeditor5-undo": "^36.0.0",
31
+ "@ckeditor/ckeditor5-upload": "^36.0.0",
32
+ "typescript": "^4.8.4",
32
33
  "webpack": "^5.58.1",
33
34
  "webpack-cli": "^4.9.0"
34
35
  },
@@ -47,13 +48,16 @@
47
48
  },
48
49
  "files": [
49
50
  "lang",
50
- "src",
51
+ "src/**/*.js",
52
+ "src/**/*.d.ts",
51
53
  "theme",
52
54
  "build",
53
55
  "ckeditor5-metadata.json",
54
56
  "CHANGELOG.md"
55
57
  ],
56
58
  "scripts": {
57
- "dll:build": "webpack"
59
+ "dll:build": "webpack",
60
+ "build": "tsc -p ./tsconfig.release.json",
61
+ "postversion": "npm run build"
58
62
  }
59
63
  }
package/src/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module adapter-ckfinder
8
7
  */
9
-
10
8
  export { default as UploadAdapter } from './uploadadapter';
@@ -1,19 +1,14 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /* globals XMLHttpRequest, FormData */
7
-
8
6
  /**
9
7
  * @module adapter-ckfinder/uploadadapter
10
8
  */
11
-
12
9
  import { Plugin } from 'ckeditor5/src/core';
13
10
  import { FileRepository } from 'ckeditor5/src/upload';
14
-
15
11
  import { getCsrfToken } from './utils';
16
-
17
12
  /**
18
13
  * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.
19
14
  *
@@ -23,168 +18,121 @@ import { getCsrfToken } from './utils';
23
18
  *
24
19
  * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} to learn about
25
20
  * other ways to upload images into CKEditor 5.
26
- *
27
- * @extends module:core/plugin~Plugin
28
21
  */
29
22
  export default class CKFinderUploadAdapter extends Plugin {
30
- /**
31
- * @inheritDoc
32
- */
33
- static get requires() {
34
- return [ FileRepository ];
35
- }
36
-
37
- /**
38
- * @inheritDoc
39
- */
40
- static get pluginName() {
41
- return 'CKFinderUploadAdapter';
42
- }
43
-
44
- /**
45
- * @inheritDoc
46
- */
47
- init() {
48
- const url = this.editor.config.get( 'ckfinder.uploadUrl' );
49
-
50
- if ( !url ) {
51
- return;
52
- }
53
-
54
- // Register CKFinderAdapter
55
- this.editor.plugins.get( FileRepository ).createUploadAdapter = loader => new UploadAdapter( loader, url, this.editor.t );
56
- }
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires() {
27
+ return [FileRepository];
28
+ }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName() {
33
+ return 'CKFinderUploadAdapter';
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ init() {
39
+ const url = this.editor.config.get('ckfinder.uploadUrl');
40
+ if (!url) {
41
+ return;
42
+ }
43
+ // Register CKFinderAdapter
44
+ this.editor.plugins.get(FileRepository).createUploadAdapter = loader => new UploadAdapter(loader, url, this.editor.t);
45
+ }
57
46
  }
58
-
59
47
  /**
60
48
  * Upload adapter for CKFinder.
61
- *
62
- * @private
63
- * @implements module:upload/filerepository~UploadAdapter
64
49
  */
65
50
  class UploadAdapter {
66
- /**
67
- * Creates a new adapter instance.
68
- *
69
- * @param {module:upload/filerepository~FileLoader} loader
70
- * @param {String} url
71
- * @param {module:utils/locale~Locale#t} t
72
- */
73
- constructor( loader, url, t ) {
74
- /**
75
- * FileLoader instance to use during the upload.
76
- *
77
- * @member {module:upload/filerepository~FileLoader} #loader
78
- */
79
- this.loader = loader;
80
-
81
- /**
82
- * Upload URL.
83
- *
84
- * @member {String} #url
85
- */
86
- this.url = url;
87
-
88
- /**
89
- * Locale translation method.
90
- *
91
- * @member {module:utils/locale~Locale#t} #t
92
- */
93
- this.t = t;
94
- }
95
-
96
- /**
97
- * Starts the upload process.
98
- *
99
- * @see module:upload/filerepository~UploadAdapter#upload
100
- * @returns {Promise.<Object>}
101
- */
102
- upload() {
103
- return this.loader.file.then( file => {
104
- return new Promise( ( resolve, reject ) => {
105
- this._initRequest();
106
- this._initListeners( resolve, reject, file );
107
- this._sendRequest( file );
108
- } );
109
- } );
110
- }
111
-
112
- /**
113
- * Aborts the upload process.
114
- *
115
- * @see module:upload/filerepository~UploadAdapter#abort
116
- */
117
- abort() {
118
- if ( this.xhr ) {
119
- this.xhr.abort();
120
- }
121
- }
122
-
123
- /**
124
- * Initializes the XMLHttpRequest object.
125
- *
126
- * @private
127
- */
128
- _initRequest() {
129
- const xhr = this.xhr = new XMLHttpRequest();
130
-
131
- xhr.open( 'POST', this.url, true );
132
- xhr.responseType = 'json';
133
- }
134
-
135
- /**
136
- * Initializes XMLHttpRequest listeners.
137
- *
138
- * @private
139
- * @param {Function} resolve Callback function to be called when the request is successful.
140
- * @param {Function} reject Callback function to be called when the request cannot be completed.
141
- * @param {File} file File instance to be uploaded.
142
- */
143
- _initListeners( resolve, reject, file ) {
144
- const xhr = this.xhr;
145
- const loader = this.loader;
146
- const t = this.t;
147
- const genericError = t( 'Cannot upload file:' ) + ` ${ file.name }.`;
148
-
149
- xhr.addEventListener( 'error', () => reject( genericError ) );
150
- xhr.addEventListener( 'abort', () => reject() );
151
- xhr.addEventListener( 'load', () => {
152
- const response = xhr.response;
153
-
154
- if ( !response || !response.uploaded ) {
155
- return reject( response && response.error && response.error.message ? response.error.message : genericError );
156
- }
157
-
158
- resolve( {
159
- default: response.url
160
- } );
161
- } );
162
-
163
- // Upload progress when it's supported.
164
- /* istanbul ignore else */
165
- if ( xhr.upload ) {
166
- xhr.upload.addEventListener( 'progress', evt => {
167
- if ( evt.lengthComputable ) {
168
- loader.uploadTotal = evt.total;
169
- loader.uploaded = evt.loaded;
170
- }
171
- } );
172
- }
173
- }
174
-
175
- /**
176
- * Prepares the data and sends the request.
177
- *
178
- * @private
179
- * @param {File} file File instance to be uploaded.
180
- */
181
- _sendRequest( file ) {
182
- // Prepare form data.
183
- const data = new FormData();
184
- data.append( 'upload', file );
185
- data.append( 'ckCsrfToken', getCsrfToken() );
186
-
187
- // Send request.
188
- this.xhr.send( data );
189
- }
51
+ /**
52
+ * Creates a new adapter instance.
53
+ */
54
+ constructor(loader, url, t) {
55
+ this.loader = loader;
56
+ this.url = url;
57
+ this.t = t;
58
+ }
59
+ /**
60
+ * Starts the upload process.
61
+ *
62
+ * @see module:upload/filerepository~UploadAdapter#upload
63
+ */
64
+ upload() {
65
+ return this.loader.file.then(file => {
66
+ return new Promise((resolve, reject) => {
67
+ this._initRequest();
68
+ this._initListeners(resolve, reject, file);
69
+ this._sendRequest(file);
70
+ });
71
+ });
72
+ }
73
+ /**
74
+ * Aborts the upload process.
75
+ *
76
+ * @see module:upload/filerepository~UploadAdapter#abort
77
+ */
78
+ abort() {
79
+ if (this.xhr) {
80
+ this.xhr.abort();
81
+ }
82
+ }
83
+ /**
84
+ * Initializes the XMLHttpRequest object.
85
+ */
86
+ _initRequest() {
87
+ const xhr = this.xhr = new XMLHttpRequest();
88
+ xhr.open('POST', this.url, true);
89
+ xhr.responseType = 'json';
90
+ }
91
+ /**
92
+ * Initializes XMLHttpRequest listeners.
93
+ *
94
+ * @param resolve Callback function to be called when the request is successful.
95
+ * @param reject Callback function to be called when the request cannot be completed.
96
+ * @param file File instance to be uploaded.
97
+ */
98
+ _initListeners(resolve, reject, file) {
99
+ const xhr = this.xhr;
100
+ const loader = this.loader;
101
+ const t = this.t;
102
+ const genericError = t('Cannot upload file:') + ` ${file.name}.`;
103
+ xhr.addEventListener('error', () => reject(genericError));
104
+ xhr.addEventListener('abort', () => reject());
105
+ xhr.addEventListener('load', () => {
106
+ const response = xhr.response;
107
+ if (!response || !response.uploaded) {
108
+ return reject(response && response.error && response.error.message ? response.error.message : genericError);
109
+ }
110
+ resolve({
111
+ default: response.url
112
+ });
113
+ });
114
+ // Upload progress when it's supported.
115
+ /* istanbul ignore else */
116
+ if (xhr.upload) {
117
+ xhr.upload.addEventListener('progress', evt => {
118
+ if (evt.lengthComputable) {
119
+ loader.uploadTotal = evt.total;
120
+ loader.uploaded = evt.loaded;
121
+ }
122
+ });
123
+ }
124
+ }
125
+ /**
126
+ * Prepares the data and sends the request.
127
+ *
128
+ * @param file File instance to be uploaded.
129
+ */
130
+ _sendRequest(file) {
131
+ // Prepare form data.
132
+ const data = new FormData();
133
+ data.append('upload', file);
134
+ data.append('ckCsrfToken', getCsrfToken());
135
+ // Send request.
136
+ this.xhr.send(data);
137
+ }
190
138
  }
package/src/utils.js CHANGED
@@ -1,83 +1,58 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /* globals window, document */
7
-
8
6
  /**
9
7
  * @module adapter-ckfinder/utils
10
8
  */
11
-
12
9
  const TOKEN_COOKIE_NAME = 'ckCsrfToken';
13
10
  const TOKEN_LENGTH = 40;
14
11
  const tokenCharset = 'abcdefghijklmnopqrstuvwxyz0123456789';
15
-
16
12
  /**
17
13
  * Returns the CSRF token value. The value is a hash stored in `document.cookie`
18
14
  * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication
19
15
  * between the web browser and the CKFinder server.
20
- *
21
- * @returns {String}
22
16
  */
23
17
  export function getCsrfToken() {
24
- let token = getCookie( TOKEN_COOKIE_NAME );
25
-
26
- if ( !token || token.length != TOKEN_LENGTH ) {
27
- token = generateToken( TOKEN_LENGTH );
28
- setCookie( TOKEN_COOKIE_NAME, token );
29
- }
30
-
31
- return token;
18
+ let token = getCookie(TOKEN_COOKIE_NAME);
19
+ if (!token || token.length != TOKEN_LENGTH) {
20
+ token = generateToken(TOKEN_LENGTH);
21
+ setCookie(TOKEN_COOKIE_NAME, token);
22
+ }
23
+ return token;
32
24
  }
33
-
34
25
  /**
35
26
  * Returns the value of the cookie with a given name or `null` if the cookie is not found.
36
- *
37
- * @param {String} name
38
- * @returns {String|null}
39
27
  */
40
- export function getCookie( name ) {
41
- name = name.toLowerCase();
42
- const parts = document.cookie.split( ';' );
43
-
44
- for ( const part of parts ) {
45
- const pair = part.split( '=' );
46
- const key = decodeURIComponent( pair[ 0 ].trim().toLowerCase() );
47
-
48
- if ( key === name ) {
49
- return decodeURIComponent( pair[ 1 ] );
50
- }
51
- }
52
-
53
- return null;
28
+ export function getCookie(name) {
29
+ name = name.toLowerCase();
30
+ const parts = document.cookie.split(';');
31
+ for (const part of parts) {
32
+ const pair = part.split('=');
33
+ const key = decodeURIComponent(pair[0].trim().toLowerCase());
34
+ if (key === name) {
35
+ return decodeURIComponent(pair[1]);
36
+ }
37
+ }
38
+ return null;
54
39
  }
55
-
56
40
  /**
57
41
  * Sets the value of the cookie with a given name.
58
- *
59
- * @param {String} name
60
- * @param {String} value
61
42
  */
62
- export function setCookie( name, value ) {
63
- document.cookie = encodeURIComponent( name ) + '=' + encodeURIComponent( value ) + ';path=/';
43
+ export function setCookie(name, value) {
44
+ document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';path=/';
64
45
  }
65
-
66
- // Generates the CSRF token with the given length.
67
- //
68
- // @private
69
- // @param {Number} length
70
- // @returns {string}
71
- function generateToken( length ) {
72
- let result = '';
73
- const randValues = new Uint8Array( length );
74
-
75
- window.crypto.getRandomValues( randValues );
76
-
77
- for ( let j = 0; j < randValues.length; j++ ) {
78
- const character = tokenCharset.charAt( randValues[ j ] % tokenCharset.length );
79
- result += Math.random() > 0.5 ? character.toUpperCase() : character;
80
- }
81
-
82
- return result;
46
+ /**
47
+ * Generates the CSRF token with the given length.
48
+ */
49
+ function generateToken(length) {
50
+ let result = '';
51
+ const randValues = new Uint8Array(length);
52
+ window.crypto.getRandomValues(randValues);
53
+ for (let j = 0; j < randValues.length; j++) {
54
+ const character = tokenCharset.charAt(randValues[j] % tokenCharset.length);
55
+ result += Math.random() > 0.5 ? character.toUpperCase() : character;
56
+ }
57
+ return result;
83
58
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter-ckfinder.js","mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAE4C;AACU;;AAEf;;AAEvC;AACA;AACA;AACA,YAAY,wFAAwF;AACpG;AACA,oBAAoB,yCAAyC;AAC7D;AACA,kBAAkB,wFAAwF;AAC1G;AACA;AACA;AACA;AACe,oCAAoC,sDAAM;AACzD;AACA;AACA;AACA;AACA,WAAW,gEAAc;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,2BAA2B,gEAAc;AACzC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,yCAAyC;AACrD,YAAY,QAAQ;AACpB,YAAY,8BAA8B;AAC1C;AACA;AACA;AACA;AACA;AACA,cAAc,yCAAyC;AACvD;AACA;;AAEA;AACA;AACA;AACA,cAAc,QAAQ;AACtB;AACA;;AAEA;AACA;AACA;AACA,cAAc,8BAA8B;AAC5C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,IAAI;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,MAAM;AAClB;AACA;AACA;AACA;AACA;AACA,yDAAyD,WAAW;;AAEpE;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL,IAAI;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,MAAM;AAClB;AACA;AACA;AACA;AACA;AACA,8BAA8B,oDAAY;;AAE1C;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC7LA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACO;AACP;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb;AACO;AACP;AACA,wCAAwC;;AAExC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB;AACO;AACP,sFAAsF;AACtF;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb;AACA;AACA;;AAEA;;AAEA,kBAAkB,uBAAuB;AACzC;AACA;AACA;;AAEA;AACA;;;;;;;;;;;AClFA;;;;;;;;;;ACAA;;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;ACNA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAE2D","sources":["webpack://CKEditor5.adapterCkfinder/./src/uploadadapter.js","webpack://CKEditor5.adapterCkfinder/./src/utils.js","webpack://CKEditor5.adapterCkfinder/delegated \"./src/core.js\" from dll-reference CKEditor5.dll","webpack://CKEditor5.adapterCkfinder/delegated \"./src/upload.js\" from dll-reference CKEditor5.dll","webpack://CKEditor5.adapterCkfinder/external var \"CKEditor5.dll\"","webpack://CKEditor5.adapterCkfinder/webpack/bootstrap","webpack://CKEditor5.adapterCkfinder/webpack/runtime/define property getters","webpack://CKEditor5.adapterCkfinder/webpack/runtime/hasOwnProperty shorthand","webpack://CKEditor5.adapterCkfinder/webpack/runtime/make namespace object","webpack://CKEditor5.adapterCkfinder/./src/index.js"],"sourcesContent":["/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/* globals XMLHttpRequest, FormData */\n\n/**\n * @module adapter-ckfinder/uploadadapter\n */\n\nimport { Plugin } from 'ckeditor5/src/core';\nimport { FileRepository } from 'ckeditor5/src/upload';\n\nimport { getCsrfToken } from './utils';\n\n/**\n * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.\n *\n * See the {@glink features/images/image-upload/ckfinder \"CKFinder file manager integration\" guide} to learn how to configure\n * and use this feature as well as find out more about the full integration with the file manager\n * provided by the {@link module:ckfinder/ckfinder~CKFinder} plugin.\n *\n * Check out the {@glink features/images/image-upload/image-upload comprehensive \"Image upload overview\"} to learn about\n * other ways to upload images into CKEditor 5.\n *\n * @extends module:core/plugin~Plugin\n */\nexport default class CKFinderUploadAdapter extends Plugin {\n\t/**\n\t * @inheritDoc\n\t */\n\tstatic get requires() {\n\t\treturn [ FileRepository ];\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tstatic get pluginName() {\n\t\treturn 'CKFinderUploadAdapter';\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tinit() {\n\t\tconst url = this.editor.config.get( 'ckfinder.uploadUrl' );\n\n\t\tif ( !url ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Register CKFinderAdapter\n\t\tthis.editor.plugins.get( FileRepository ).createUploadAdapter = loader => new UploadAdapter( loader, url, this.editor.t );\n\t}\n}\n\n/**\n * Upload adapter for CKFinder.\n *\n * @private\n * @implements module:upload/filerepository~UploadAdapter\n */\nclass UploadAdapter {\n\t/**\n\t * Creates a new adapter instance.\n\t *\n\t * @param {module:upload/filerepository~FileLoader} loader\n\t * @param {String} url\n\t * @param {module:utils/locale~Locale#t} t\n\t */\n\tconstructor( loader, url, t ) {\n\t\t/**\n\t\t * FileLoader instance to use during the upload.\n\t\t *\n\t\t * @member {module:upload/filerepository~FileLoader} #loader\n\t\t */\n\t\tthis.loader = loader;\n\n\t\t/**\n\t\t * Upload URL.\n\t\t *\n\t\t * @member {String} #url\n\t\t */\n\t\tthis.url = url;\n\n\t\t/**\n\t\t * Locale translation method.\n\t\t *\n\t\t * @member {module:utils/locale~Locale#t} #t\n\t\t */\n\t\tthis.t = t;\n\t}\n\n\t/**\n\t * Starts the upload process.\n\t *\n\t * @see module:upload/filerepository~UploadAdapter#upload\n\t * @returns {Promise.<Object>}\n\t */\n\tupload() {\n\t\treturn this.loader.file.then( file => {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tthis._initRequest();\n\t\t\t\tthis._initListeners( resolve, reject, file );\n\t\t\t\tthis._sendRequest( file );\n\t\t\t} );\n\t\t} );\n\t}\n\n\t/**\n\t * Aborts the upload process.\n\t *\n\t * @see module:upload/filerepository~UploadAdapter#abort\n\t */\n\tabort() {\n\t\tif ( this.xhr ) {\n\t\t\tthis.xhr.abort();\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the XMLHttpRequest object.\n\t *\n\t * @private\n\t */\n\t_initRequest() {\n\t\tconst xhr = this.xhr = new XMLHttpRequest();\n\n\t\txhr.open( 'POST', this.url, true );\n\t\txhr.responseType = 'json';\n\t}\n\n\t/**\n\t * Initializes XMLHttpRequest listeners.\n\t *\n\t * @private\n\t * @param {Function} resolve Callback function to be called when the request is successful.\n\t * @param {Function} reject Callback function to be called when the request cannot be completed.\n\t * @param {File} file File instance to be uploaded.\n\t */\n\t_initListeners( resolve, reject, file ) {\n\t\tconst xhr = this.xhr;\n\t\tconst loader = this.loader;\n\t\tconst t = this.t;\n\t\tconst genericError = t( 'Cannot upload file:' ) + ` ${ file.name }.`;\n\n\t\txhr.addEventListener( 'error', () => reject( genericError ) );\n\t\txhr.addEventListener( 'abort', () => reject() );\n\t\txhr.addEventListener( 'load', () => {\n\t\t\tconst response = xhr.response;\n\n\t\t\tif ( !response || !response.uploaded ) {\n\t\t\t\treturn reject( response && response.error && response.error.message ? response.error.message : genericError );\n\t\t\t}\n\n\t\t\tresolve( {\n\t\t\t\tdefault: response.url\n\t\t\t} );\n\t\t} );\n\n\t\t// Upload progress when it's supported.\n\t\t/* istanbul ignore else */\n\t\tif ( xhr.upload ) {\n\t\t\txhr.upload.addEventListener( 'progress', evt => {\n\t\t\t\tif ( evt.lengthComputable ) {\n\t\t\t\t\tloader.uploadTotal = evt.total;\n\t\t\t\t\tloader.uploaded = evt.loaded;\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Prepares the data and sends the request.\n\t *\n\t * @private\n\t * @param {File} file File instance to be uploaded.\n\t */\n\t_sendRequest( file ) {\n\t\t// Prepare form data.\n\t\tconst data = new FormData();\n\t\tdata.append( 'upload', file );\n\t\tdata.append( 'ckCsrfToken', getCsrfToken() );\n\n\t\t// Send request.\n\t\tthis.xhr.send( data );\n\t}\n}\n","/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/* globals window, document */\n\n/**\n * @module adapter-ckfinder/utils\n */\n\nconst TOKEN_COOKIE_NAME = 'ckCsrfToken';\nconst TOKEN_LENGTH = 40;\nconst tokenCharset = 'abcdefghijklmnopqrstuvwxyz0123456789';\n\n/**\n * Returns the CSRF token value. The value is a hash stored in `document.cookie`\n * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication\n * between the web browser and the CKFinder server.\n *\n * @returns {String}\n */\nexport function getCsrfToken() {\n\tlet token = getCookie( TOKEN_COOKIE_NAME );\n\n\tif ( !token || token.length != TOKEN_LENGTH ) {\n\t\ttoken = generateToken( TOKEN_LENGTH );\n\t\tsetCookie( TOKEN_COOKIE_NAME, token );\n\t}\n\n\treturn token;\n}\n\n/**\n * Returns the value of the cookie with a given name or `null` if the cookie is not found.\n *\n * @param {String} name\n * @returns {String|null}\n */\nexport function getCookie( name ) {\n\tname = name.toLowerCase();\n\tconst parts = document.cookie.split( ';' );\n\n\tfor ( const part of parts ) {\n\t\tconst pair = part.split( '=' );\n\t\tconst key = decodeURIComponent( pair[ 0 ].trim().toLowerCase() );\n\n\t\tif ( key === name ) {\n\t\t\treturn decodeURIComponent( pair[ 1 ] );\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Sets the value of the cookie with a given name.\n *\n * @param {String} name\n * @param {String} value\n */\nexport function setCookie( name, value ) {\n\tdocument.cookie = encodeURIComponent( name ) + '=' + encodeURIComponent( value ) + ';path=/';\n}\n\n// Generates the CSRF token with the given length.\n//\n// @private\n// @param {Number} length\n// @returns {string}\nfunction generateToken( length ) {\n\tlet result = '';\n\tconst randValues = new Uint8Array( length );\n\n\twindow.crypto.getRandomValues( randValues );\n\n\tfor ( let j = 0; j < randValues.length; j++ ) {\n\t\tconst character = tokenCharset.charAt( randValues[ j ] % tokenCharset.length );\n\t\tresult += Math.random() > 0.5 ? character.toUpperCase() : character;\n\t}\n\n\treturn result;\n}\n","module.exports = (__webpack_require__(/*! dll-reference CKEditor5.dll */ \"dll-reference CKEditor5.dll\"))(\"./src/core.js\");","module.exports = (__webpack_require__(/*! dll-reference CKEditor5.dll */ \"dll-reference CKEditor5.dll\"))(\"./src/upload.js\");","module.exports = CKEditor5.dll;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module adapter-ckfinder\n */\n\nexport { default as UploadAdapter } from './uploadadapter';\n"],"names":[],"sourceRoot":""}