@ckeditor/ckeditor5-upload 35.2.1 → 35.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +16 -6
- package/src/adapters/base64uploadadapter.js +63 -76
- package/src/adapters/simpleuploadadapter.js +151 -270
- package/src/filereader.js +76 -96
- package/src/filerepository.js +480 -623
- package/src/index.js +0 -2
- package/src/ui/filedialogbuttonview.js +119 -139
package/src/index.js
CHANGED
@@ -2,11 +2,9 @@
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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 upload
|
8
7
|
*/
|
9
|
-
|
10
8
|
export { default as FileRepository } from './filerepository';
|
11
9
|
export { default as FileDialogButtonView } from './ui/filedialogbuttonview';
|
12
10
|
export { default as Base64UploadAdapter } from './adapters/base64uploadadapter';
|
@@ -2,14 +2,11 @@
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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 upload/ui/filedialogbuttonview
|
8
7
|
*/
|
9
|
-
|
10
8
|
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
|
11
9
|
import View from '@ckeditor/ckeditor5-ui/src/view';
|
12
|
-
|
13
10
|
/**
|
14
11
|
* The file dialog button view.
|
15
12
|
*
|
@@ -38,84 +35,75 @@ import View from '@ckeditor/ckeditor5-ui/src/view';
|
|
38
35
|
* @extends module:ui/view~View
|
39
36
|
*/
|
40
37
|
export default class FileDialogButtonView extends View {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
/**
|
112
|
-
* Focuses the {@link #buttonView}.
|
113
|
-
*/
|
114
|
-
focus() {
|
115
|
-
this.buttonView.focus();
|
116
|
-
}
|
38
|
+
/**
|
39
|
+
* @inheritDoc
|
40
|
+
*/
|
41
|
+
constructor(locale) {
|
42
|
+
super(locale);
|
43
|
+
/**
|
44
|
+
* The button view of the component.
|
45
|
+
*
|
46
|
+
* @member {module:ui/button/buttonview~ButtonView}
|
47
|
+
*/
|
48
|
+
this.buttonView = new ButtonView(locale);
|
49
|
+
/**
|
50
|
+
* A hidden `<input>` view used to execute file dialog.
|
51
|
+
*
|
52
|
+
* @protected
|
53
|
+
* @member {module:upload/ui/filedialogbuttonview~FileInputView}
|
54
|
+
*/
|
55
|
+
this._fileInputView = new FileInputView(locale);
|
56
|
+
/**
|
57
|
+
* Accepted file types. Can be provided in form of file extensions, media type or one of:
|
58
|
+
* * `audio/*`,
|
59
|
+
* * `video/*`,
|
60
|
+
* * `image/*`.
|
61
|
+
*
|
62
|
+
* @observable
|
63
|
+
* @member {String} #acceptedType
|
64
|
+
*/
|
65
|
+
this._fileInputView.bind('acceptedType').to(this);
|
66
|
+
/**
|
67
|
+
* Indicates if multiple files can be selected. Defaults to `true`.
|
68
|
+
*
|
69
|
+
* @observable
|
70
|
+
* @member {Boolean} #allowMultipleFiles
|
71
|
+
*/
|
72
|
+
this._fileInputView.bind('allowMultipleFiles').to(this);
|
73
|
+
/**
|
74
|
+
* Fired when file dialog is closed with file selected.
|
75
|
+
*
|
76
|
+
* view.on( 'done', ( evt, files ) => {
|
77
|
+
* for ( const file of files ) {
|
78
|
+
* console.log( 'Selected file', file );
|
79
|
+
* }
|
80
|
+
* }
|
81
|
+
*
|
82
|
+
* @event done
|
83
|
+
* @param {Array.<File>} files Array of selected files.
|
84
|
+
*/
|
85
|
+
this._fileInputView.delegate('done').to(this);
|
86
|
+
this.setTemplate({
|
87
|
+
tag: 'span',
|
88
|
+
attributes: {
|
89
|
+
class: 'ck-file-dialog-button'
|
90
|
+
},
|
91
|
+
children: [
|
92
|
+
this.buttonView,
|
93
|
+
this._fileInputView
|
94
|
+
]
|
95
|
+
});
|
96
|
+
this.buttonView.on('execute', () => {
|
97
|
+
this._fileInputView.open();
|
98
|
+
});
|
99
|
+
}
|
100
|
+
/**
|
101
|
+
* Focuses the {@link #buttonView}.
|
102
|
+
*/
|
103
|
+
focus() {
|
104
|
+
this.buttonView.focus();
|
105
|
+
}
|
117
106
|
}
|
118
|
-
|
119
107
|
/**
|
120
108
|
* The hidden file input view class.
|
121
109
|
*
|
@@ -123,63 +111,55 @@ export default class FileDialogButtonView extends View {
|
|
123
111
|
* @extends module:ui/view~View
|
124
112
|
*/
|
125
113
|
class FileInputView extends View {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
/**
|
180
|
-
* Opens file dialog.
|
181
|
-
*/
|
182
|
-
open() {
|
183
|
-
this.element.click();
|
184
|
-
}
|
114
|
+
/**
|
115
|
+
* @inheritDoc
|
116
|
+
*/
|
117
|
+
constructor(locale) {
|
118
|
+
super(locale);
|
119
|
+
/**
|
120
|
+
* Accepted file types. Can be provided in form of file extensions, media type or one of:
|
121
|
+
* * `audio/*`,
|
122
|
+
* * `video/*`,
|
123
|
+
* * `image/*`.
|
124
|
+
*
|
125
|
+
* @observable
|
126
|
+
* @member {String} #acceptedType
|
127
|
+
*/
|
128
|
+
this.set('acceptedType', undefined);
|
129
|
+
/**
|
130
|
+
* Indicates if multiple files can be selected. Defaults to `false`.
|
131
|
+
*
|
132
|
+
* @observable
|
133
|
+
* @member {Boolean} #allowMultipleFiles
|
134
|
+
*/
|
135
|
+
this.set('allowMultipleFiles', false);
|
136
|
+
const bind = this.bindTemplate;
|
137
|
+
this.setTemplate({
|
138
|
+
tag: 'input',
|
139
|
+
attributes: {
|
140
|
+
class: [
|
141
|
+
'ck-hidden'
|
142
|
+
],
|
143
|
+
type: 'file',
|
144
|
+
tabindex: '-1',
|
145
|
+
accept: bind.to('acceptedType'),
|
146
|
+
multiple: bind.to('allowMultipleFiles')
|
147
|
+
},
|
148
|
+
on: {
|
149
|
+
// Removing from code coverage since we cannot programmatically set input element files.
|
150
|
+
change: bind.to(/* istanbul ignore next */ () => {
|
151
|
+
if (this.element && this.element.files && this.element.files.length) {
|
152
|
+
this.fire('done', this.element.files);
|
153
|
+
}
|
154
|
+
this.element.value = '';
|
155
|
+
})
|
156
|
+
}
|
157
|
+
});
|
158
|
+
}
|
159
|
+
/**
|
160
|
+
* Opens file dialog.
|
161
|
+
*/
|
162
|
+
open() {
|
163
|
+
this.element.click();
|
164
|
+
}
|
185
165
|
}
|