frayerjj-frontend 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ckeupload.js +56 -0
- package/src/index.js +2 -1
- package/src/init.js +1 -56
package/package.json
CHANGED
package/src/ckeupload.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const CkeUploadAdapterPlugin = function(editor) {
|
|
2
|
+
|
|
3
|
+
class CkeUploadAdapter {
|
|
4
|
+
constructor(loader, uri, token) {
|
|
5
|
+
this.loader = loader;
|
|
6
|
+
this.uri = uri;
|
|
7
|
+
this.token = token;
|
|
8
|
+
}
|
|
9
|
+
upload() {
|
|
10
|
+
return this.loader.file
|
|
11
|
+
.then(file => new Promise((resolve, reject) => {
|
|
12
|
+
this._initRequest();
|
|
13
|
+
this._initListeners(resolve, reject, file);
|
|
14
|
+
this._sendRequest(file);
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
abort() {
|
|
18
|
+
if (this.xhr) this.xhr.abort();
|
|
19
|
+
}
|
|
20
|
+
_initRequest() {
|
|
21
|
+
const xhr = this.xhr = new XMLHttpRequest();
|
|
22
|
+
xhr.open('POST', this.uri, true);
|
|
23
|
+
xhr.setRequestHeader('X-CSRFToken', this.token);
|
|
24
|
+
xhr.responseType = 'json';
|
|
25
|
+
}
|
|
26
|
+
_initListeners(resolve, reject, file) {
|
|
27
|
+
const xhr = this.xhr;
|
|
28
|
+
const loader = this.loader;
|
|
29
|
+
const genericErrorText = `Couldn't upload file: ${ file.name }.`;
|
|
30
|
+
xhr.addEventListener( 'error', () => reject(genericErrorText) );
|
|
31
|
+
xhr.addEventListener( 'abort', () => reject() );
|
|
32
|
+
xhr.addEventListener( 'load', () => {
|
|
33
|
+
const response = xhr.response;
|
|
34
|
+
if (!response || response.error) return reject(response && response.error ? response.error.message : genericErrorText);
|
|
35
|
+
resolve({ default: response.url });
|
|
36
|
+
});
|
|
37
|
+
if (xhr.upload) {
|
|
38
|
+
xhr.upload.addEventListener('progress', evt => {
|
|
39
|
+
if (evt.lengthComputable) {
|
|
40
|
+
loader.uploadTotal = evt.total;
|
|
41
|
+
loader.uploaded = evt.loaded;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
_sendRequest(file) {
|
|
47
|
+
const data = new FormData();
|
|
48
|
+
data.append('file', file);
|
|
49
|
+
this.xhr.send(data);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
|
|
54
|
+
return new CkeUploadAdapter(loader, editor.config._config.extraParams.uri, editor.config._config.extraParams.token);
|
|
55
|
+
};
|
|
56
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ajax } from './ajax';
|
|
2
|
+
import { CkeUploadAdapterPlugin } from './ckeupload';
|
|
2
3
|
import { init } from './init';
|
|
3
4
|
import { loading } from './loading';
|
|
4
5
|
import { message } from './message';
|
|
@@ -6,4 +7,4 @@ import { modal } from './modal';
|
|
|
6
7
|
import { session } from './session';
|
|
7
8
|
import { validate } from './validate';
|
|
8
9
|
|
|
9
|
-
export { ajax, init, loading, message, modal, session, validate };
|
|
10
|
+
export { ajax, CkeUploadAdapterPlugin, init, loading, message, modal, session, validate };
|
package/src/init.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { message } from './message';
|
|
2
2
|
import { modal } from './modal';
|
|
3
3
|
import { validate } from './validate';
|
|
4
|
+
import { CkeUploadAdapterPlugin } from '@ckeditor/ckeditor5-adapter-ckfinder';
|
|
4
5
|
import { ClassicEditor } from '@ckeditor/ckeditor5-build-classic';
|
|
5
6
|
|
|
6
7
|
export const init = () => {
|
|
@@ -75,62 +76,6 @@ export const init = () => {
|
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
78
|
|
|
78
|
-
class CkeUploadAdapter {
|
|
79
|
-
constructor(loader, uri, token) {
|
|
80
|
-
this.loader = loader;
|
|
81
|
-
this.uri = uri;
|
|
82
|
-
this.token = token;
|
|
83
|
-
}
|
|
84
|
-
upload() {
|
|
85
|
-
return this.loader.file
|
|
86
|
-
.then(file => new Promise((resolve, reject) => {
|
|
87
|
-
this._initRequest();
|
|
88
|
-
this._initListeners(resolve, reject, file);
|
|
89
|
-
this._sendRequest(file);
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
abort() {
|
|
93
|
-
if (this.xhr) this.xhr.abort();
|
|
94
|
-
}
|
|
95
|
-
_initRequest() {
|
|
96
|
-
const xhr = this.xhr = new XMLHttpRequest();
|
|
97
|
-
xhr.open('POST', this.uri, true);
|
|
98
|
-
xhr.setRequestHeader('X-CSRFToken', this.token);
|
|
99
|
-
xhr.responseType = 'json';
|
|
100
|
-
}
|
|
101
|
-
_initListeners(resolve, reject, file) {
|
|
102
|
-
const xhr = this.xhr;
|
|
103
|
-
const loader = this.loader;
|
|
104
|
-
const genericErrorText = `Couldn't upload file: ${ file.name }.`;
|
|
105
|
-
xhr.addEventListener( 'error', () => reject(genericErrorText) );
|
|
106
|
-
xhr.addEventListener( 'abort', () => reject() );
|
|
107
|
-
xhr.addEventListener( 'load', () => {
|
|
108
|
-
const response = xhr.response;
|
|
109
|
-
if (!response || response.error) return reject(response && response.error ? response.error.message : genericErrorText);
|
|
110
|
-
resolve({ default: response.url });
|
|
111
|
-
});
|
|
112
|
-
if (xhr.upload) {
|
|
113
|
-
xhr.upload.addEventListener('progress', evt => {
|
|
114
|
-
if (evt.lengthComputable) {
|
|
115
|
-
loader.uploadTotal = evt.total;
|
|
116
|
-
loader.uploaded = evt.loaded;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
_sendRequest(file) {
|
|
122
|
-
const data = new FormData();
|
|
123
|
-
data.append('file', file);
|
|
124
|
-
this.xhr.send(data);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
window.CkeUploadAdapterPlugin = function(editor) {
|
|
129
|
-
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
|
|
130
|
-
return new CkeUploadAdapter(loader, editor.config._config.extraParams.uri, editor.config._config.extraParams.token);
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
79
|
window.editors = [];
|
|
135
80
|
document.querySelectorAll('.wysiwyg').forEach(el => {
|
|
136
81
|
message.verbose('Enabling WYSIWYG Editor');
|