frayerjj-frontend 0.1.48 → 0.1.59
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 +2 -3
- package/src/ckeupload.js +34 -52
- package/src/index.js +1 -22
- package/src/init.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frayerjj-frontend",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.59",
|
|
4
4
|
"description": "My base frontend for various projects",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"author": "Joshua Frayer",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ckeditor/ckeditor5-
|
|
18
|
-
"@ckeditor/ckeditor5-editor-inline": "^44.3.0",
|
|
17
|
+
"@ckeditor/ckeditor5-build-classic": "^44.3.0",
|
|
19
18
|
"@popperjs/core": "^2.11.8",
|
|
20
19
|
"bootstrap": "^5.3.3"
|
|
21
20
|
}
|
package/src/ckeupload.js
CHANGED
|
@@ -1,56 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
|
|
2
|
+
import { message } from "./message";
|
|
2
3
|
|
|
3
4
|
export const ckeupload = {
|
|
5
|
+
adapter: editor => {
|
|
6
|
+
editor.plugins.get('FileRepository').createUploadAdapter = loader => {
|
|
7
|
+
return new CkeUploadAdapter(loader, editor.config._config.extraParams.uri, editor.config._config.extraParams.token);
|
|
8
|
+
};
|
|
9
|
+
},
|
|
4
10
|
init: () => {
|
|
5
|
-
// Ensure ClassicEditor is available
|
|
6
|
-
if (typeof window.ClassicEditor === 'undefined') {
|
|
7
|
-
message.warn('CKEditor not loaded.');
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
11
|
class CkeUploadAdapter {
|
|
12
12
|
constructor(loader, uri, token) {
|
|
13
13
|
this.loader = loader;
|
|
14
14
|
this.uri = uri;
|
|
15
15
|
this.token = token;
|
|
16
|
-
message.verbose('CKEditor Upload Adapter Initialized');
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
upload() {
|
|
20
|
-
return this.loader.file
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}));
|
|
18
|
+
return this.loader.file.then(file => new Promise((resolve, reject) => {
|
|
19
|
+
this._initRequest();
|
|
20
|
+
this._initListeners(resolve, reject, file);
|
|
21
|
+
this._sendRequest(file);
|
|
22
|
+
}));
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
abort() {
|
|
29
25
|
if (this.xhr) this.xhr.abort();
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
_initRequest() {
|
|
33
28
|
const xhr = this.xhr = new XMLHttpRequest();
|
|
34
29
|
xhr.open('POST', this.uri, true);
|
|
35
30
|
xhr.setRequestHeader('X-CSRFToken', this.token);
|
|
36
31
|
xhr.responseType = 'json';
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
_initListeners(resolve, reject, file) {
|
|
40
34
|
const xhr = this.xhr;
|
|
41
35
|
const loader = this.loader;
|
|
42
|
-
const genericErrorText = `Couldn't upload file: ${file.name}.`;
|
|
43
|
-
|
|
44
|
-
xhr.addEventListener('
|
|
45
|
-
xhr.addEventListener('
|
|
46
|
-
xhr.addEventListener('load', () => {
|
|
36
|
+
const genericErrorText = `Couldn't upload file: ${ file.name }.`;
|
|
37
|
+
xhr.addEventListener( 'error', () => reject(genericErrorText) );
|
|
38
|
+
xhr.addEventListener( 'abort', () => reject() );
|
|
39
|
+
xhr.addEventListener( 'load', () => {
|
|
47
40
|
const response = xhr.response;
|
|
48
|
-
if (!response || response.error)
|
|
41
|
+
if (!response || response.error)
|
|
49
42
|
return reject(response && response.error ? response.error.message : genericErrorText);
|
|
50
|
-
}
|
|
51
43
|
resolve({ default: response.url });
|
|
52
44
|
});
|
|
53
|
-
|
|
54
45
|
if (xhr.upload) {
|
|
55
46
|
xhr.upload.addEventListener('progress', evt => {
|
|
56
47
|
if (evt.lengthComputable) {
|
|
@@ -60,44 +51,35 @@ export const ckeupload = {
|
|
|
60
51
|
});
|
|
61
52
|
}
|
|
62
53
|
}
|
|
63
|
-
|
|
64
54
|
_sendRequest(file) {
|
|
65
55
|
const data = new FormData();
|
|
66
56
|
data.append('file', file);
|
|
67
57
|
this.xhr.send(data);
|
|
68
58
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Register the upload adapter plugin
|
|
72
|
-
window.CkeUploadAdapterPlugin = function (editor) {
|
|
73
|
-
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
|
|
74
|
-
const uri = document.querySelector('meta[name="asset-upload"]').getAttribute('content');
|
|
75
|
-
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
76
|
-
return new CkeUploadAdapter(loader, uri, token);
|
|
77
|
-
};
|
|
78
59
|
};
|
|
79
|
-
|
|
80
|
-
// Initialize editors
|
|
60
|
+
window.editors = [];
|
|
81
61
|
document.querySelectorAll('.wysiwyg').forEach(el => {
|
|
82
62
|
ClassicEditor.create(el, {
|
|
83
63
|
licenseKey: 'GPL',
|
|
84
64
|
htmlSupport: {
|
|
85
|
-
allow: [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
65
|
+
allow: [{
|
|
66
|
+
name: /.*/,
|
|
67
|
+
attributes: true,
|
|
68
|
+
classes: true,
|
|
69
|
+
styles: true
|
|
70
|
+
}]
|
|
71
|
+
},
|
|
72
|
+
extraParams: {
|
|
73
|
+
uri: document.querySelector('meta[name="asset-upload"]').getAttribute('content'),
|
|
74
|
+
token: document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
|
93
75
|
},
|
|
94
|
-
extraPlugins: [
|
|
76
|
+
extraPlugins: [ CkeUploadAdapter ]
|
|
95
77
|
}).then(editor => {
|
|
96
|
-
if (!window.editors) window.editors = [];
|
|
97
78
|
window.editors[el.id] = editor;
|
|
98
|
-
|
|
99
|
-
|
|
79
|
+
message.verbose('CKEditor Initialized');
|
|
80
|
+
}).catch( error => {
|
|
81
|
+
console.error( 'There was a problem initializing the editor.', error );
|
|
100
82
|
});
|
|
101
|
-
});
|
|
83
|
+
});
|
|
102
84
|
}
|
|
103
|
-
}
|
|
85
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
|
|
2
|
-
import { ajax } from './ajax';
|
|
3
1
|
import { init } from './init';
|
|
4
|
-
import { loading } from './loading';
|
|
5
|
-
import { message } from './message';
|
|
6
|
-
import { modal } from './modal';
|
|
7
|
-
import { session } from './session';
|
|
8
|
-
import { validate } from './validate';
|
|
9
|
-
import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
|
|
10
|
-
import InlineEditorBase from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor';
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
class InlineEditor extends InlineEditorBase {}
|
|
14
|
-
|
|
15
|
-
const plugins = [];
|
|
16
|
-
const config = {};
|
|
17
|
-
|
|
18
|
-
ClassicEditor.builtinPlugins = plugins;
|
|
19
|
-
ClassicEditor.defaultConfig = config;
|
|
20
|
-
|
|
21
|
-
InlineEditor.builtinPlugins = plugins;
|
|
22
|
-
InlineEditor.defaultConfig = config;
|
|
23
|
-
|
|
24
|
-
export { ClassicEditor, InlineEditor, ajax, init, loading, message, modal, session, validate };
|
|
3
|
+
export { init };
|
package/src/init.js
CHANGED
|
@@ -6,6 +6,8 @@ import { validate } from './validate';
|
|
|
6
6
|
import { loading } from './loading';
|
|
7
7
|
import { ajax } from './ajax';
|
|
8
8
|
import { session } from './session';
|
|
9
|
+
import { ckeupload } from './ckeupload';
|
|
10
|
+
import { ClassicEditor } from '@ckeditor/ckeditor5-build-classic';
|
|
9
11
|
|
|
10
12
|
export const init = () => {
|
|
11
13
|
|
|
@@ -17,6 +19,7 @@ export const init = () => {
|
|
|
17
19
|
window.session = session;
|
|
18
20
|
window.validate = validate;
|
|
19
21
|
window.loading = loading;
|
|
22
|
+
window.ClassicEditor = ClassicEditor;
|
|
20
23
|
loading.init();
|
|
21
24
|
|
|
22
25
|
window.addEventListener('load', () => {
|
|
@@ -24,6 +27,7 @@ export const init = () => {
|
|
|
24
27
|
message.verbose('Page Loaded, Initializing');
|
|
25
28
|
validate.init();
|
|
26
29
|
modal.ajax.init();
|
|
30
|
+
ckeupload.init();
|
|
27
31
|
|
|
28
32
|
// Updates the id in the form action inside a modal. Used for delete confirm and edit modals.
|
|
29
33
|
document.querySelectorAll('.modal-uuid-update').forEach(el => {
|