@vaadin/upload 24.0.0-alpha1 → 24.0.0-alpha10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/upload",
3
- "version": "24.0.0-alpha1",
3
+ "version": "24.0.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,16 +36,16 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/button": "24.0.0-alpha1",
40
- "@vaadin/component-base": "24.0.0-alpha1",
41
- "@vaadin/progress-bar": "24.0.0-alpha1",
42
- "@vaadin/vaadin-lumo-styles": "24.0.0-alpha1",
43
- "@vaadin/vaadin-material-styles": "24.0.0-alpha1",
44
- "@vaadin/vaadin-themable-mixin": "24.0.0-alpha1"
39
+ "@vaadin/button": "24.0.0-alpha10",
40
+ "@vaadin/component-base": "24.0.0-alpha10",
41
+ "@vaadin/progress-bar": "24.0.0-alpha10",
42
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha10",
43
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha10",
44
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha10"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@esm-bundle/chai": "^4.3.4",
48
- "@vaadin/form-layout": "24.0.0-alpha1",
48
+ "@vaadin/form-layout": "24.0.0-alpha10",
49
49
  "@vaadin/testing-helpers": "^0.3.2",
50
50
  "sinon": "^13.0.2"
51
51
  },
@@ -53,5 +53,5 @@
53
53
  "web-types.json",
54
54
  "web-types.lit.json"
55
55
  ],
56
- "gitHead": "427527c27c4b27822d61fd41d38d7b170134770b"
56
+ "gitHead": "2e04534d8b47bcd216f89b5f849bafef1a73b174"
57
57
  }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import './vaadin-upload-file.js';
7
+ import { html as legacyHtml, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
+ import { html, render } from 'lit';
9
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+
11
+ /**
12
+ * An element used internally by `<vaadin-upload>`. Not intended to be used separately.
13
+ *
14
+ * @extends HTMLElement
15
+ * @mixes FocusMixin
16
+ * @private
17
+ */
18
+ class UploadFileList extends ThemableMixin(PolymerElement) {
19
+ static get is() {
20
+ return 'vaadin-upload-file-list';
21
+ }
22
+
23
+ static get template() {
24
+ return legacyHtml`
25
+ <style>
26
+ :host {
27
+ display: block;
28
+ }
29
+
30
+ :host([hidden]) {
31
+ display: none !important;
32
+ }
33
+
34
+ [part='list'] {
35
+ padding: 0;
36
+ margin: 0;
37
+ list-style-type: none;
38
+ }
39
+ </style>
40
+ <ul part="list">
41
+ <slot></slot>
42
+ </ul>
43
+ `;
44
+ }
45
+
46
+ static get properties() {
47
+ return {
48
+ /**
49
+ * The array of files being processed, or already uploaded.
50
+ */
51
+ items: {
52
+ type: Array,
53
+ },
54
+
55
+ /**
56
+ * The object used to localize upload files.
57
+ */
58
+ i18n: {
59
+ type: Object,
60
+ },
61
+ };
62
+ }
63
+
64
+ static get observers() {
65
+ return ['__updateItems(items, i18n)'];
66
+ }
67
+
68
+ /** @private */
69
+ __updateItems(items, i18n) {
70
+ if (items && i18n) {
71
+ this.requestContentUpdate();
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Requests an update for the `vaadin-upload-file` elements.
77
+ *
78
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
79
+ */
80
+ requestContentUpdate() {
81
+ const { items, i18n } = this;
82
+
83
+ render(
84
+ html`
85
+ ${items.map(
86
+ (file) => html`
87
+ <li>
88
+ <vaadin-upload-file
89
+ .file="${file}"
90
+ .complete="${file.complete}"
91
+ .errorMessage="${file.error}"
92
+ .fileName="${file.name}"
93
+ .held="${file.held}"
94
+ .indeterminate="${file.indeterminate}"
95
+ .progress="${file.progress}"
96
+ .status="${file.status}"
97
+ .uploading="${file.uploading}"
98
+ .i18n="${i18n}"
99
+ ></vaadin-upload-file>
100
+ </li>
101
+ `,
102
+ )}
103
+ `,
104
+ this,
105
+ );
106
+ }
107
+ }
108
+
109
+ customElements.define(UploadFileList.is, UploadFileList);
110
+
111
+ export { UploadFileList };
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/progress-bar/src/vaadin-progress-bar.js';
7
7
  import './vaadin-upload-icons.js';
8
8
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
9
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
9
10
  import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
11
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
10
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
13
 
12
14
  /**
@@ -30,7 +32,6 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
30
32
  * `start-button` | Start file upload button
31
33
  * `retry-button` | Retry file upload button
32
34
  * `remove-button` | Remove file button
33
- * `progress` | Progress bar
34
35
  *
35
36
  * The following state attributes are available for styling:
36
37
  *
@@ -46,10 +47,11 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
46
47
  * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
47
48
  *
48
49
  * @extends HTMLElement
50
+ * @mixes ControllerMixin
49
51
  * @mixes FocusMixin
50
52
  * @mixes ThemableMixin
51
53
  */
52
- class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
54
+ class UploadFile extends FocusMixin(ThemableMixin(ControllerMixin(PolymerElement))) {
53
55
  static get template() {
54
56
  return html`
55
57
  <style>
@@ -71,17 +73,22 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
71
73
  border: none;
72
74
  box-shadow: none;
73
75
  }
76
+
77
+ :host([complete]) ::slotted([slot='progress']),
78
+ :host([error]) ::slotted([slot='progress']) {
79
+ display: none !important;
80
+ }
74
81
  </style>
75
82
 
76
83
  <div part="row">
77
84
  <div part="info">
78
- <div part="done-icon" hidden$="[[!file.complete]]" aria-hidden="true"></div>
79
- <div part="warning-icon" hidden$="[[!file.error]]" aria-hidden="true"></div>
85
+ <div part="done-icon" hidden$="[[!complete]]" aria-hidden="true"></div>
86
+ <div part="warning-icon" hidden$="[[!errorMessage]]" aria-hidden="true"></div>
80
87
 
81
88
  <div part="meta">
82
- <div part="name" id="name">[[file.name]]</div>
83
- <div part="status" hidden$="[[!file.status]]" id="status">[[file.status]]</div>
84
- <div part="error" id="error" hidden$="[[!file.error]]">[[file.error]]</div>
89
+ <div part="name" id="name">[[fileName]]</div>
90
+ <div part="status" hidden$="[[!status]]" id="status">[[status]]</div>
91
+ <div part="error" id="error" hidden$="[[!errorMessage]]">[[errorMessage]]</div>
85
92
  </div>
86
93
  </div>
87
94
  <div part="commands">
@@ -90,7 +97,7 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
90
97
  part="start-button"
91
98
  file-event="file-start"
92
99
  on-click="_fireFileEvent"
93
- hidden$="[[!file.held]]"
100
+ hidden$="[[!held]]"
94
101
  aria-label$="[[i18n.file.start]]"
95
102
  aria-describedby="name"
96
103
  ></button>
@@ -99,7 +106,7 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
99
106
  part="retry-button"
100
107
  file-event="file-retry"
101
108
  on-click="_fireFileEvent"
102
- hidden$="[[!file.error]]"
109
+ hidden$="[[!errorMessage]]"
103
110
  aria-label$="[[i18n.file.retry]]"
104
111
  aria-describedby="name"
105
112
  ></button>
@@ -114,15 +121,7 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
114
121
  </div>
115
122
  </div>
116
123
 
117
- <vaadin-progress-bar
118
- part="progress"
119
- id="progress"
120
- value$="[[_formatProgressValue(file.progress)]]"
121
- error$="[[file.error]]"
122
- indeterminate$="[[file.indeterminate]]"
123
- uploading$="[[file.uploading]]"
124
- complete$="[[file.complete]]"
125
- ></vaadin-progress-bar>
124
+ <slot name="progress"></slot>
126
125
  `;
127
126
  }
128
127
 
@@ -132,9 +131,75 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
132
131
 
133
132
  static get properties() {
134
133
  return {
135
- file: Object,
134
+ /**
135
+ * True if uploading is completed, false otherwise.
136
+ */
137
+ complete: {
138
+ type: Boolean,
139
+ value: false,
140
+ reflectToAttribute: true,
141
+ },
142
+
143
+ /**
144
+ * Error message returned by the server, if any.
145
+ */
146
+ errorMessage: {
147
+ type: String,
148
+ value: '',
149
+ observer: '_errorMessageChanged',
150
+ },
151
+
152
+ /**
153
+ * The object representing a file.
154
+ */
155
+ file: {
156
+ type: Object,
157
+ },
158
+
159
+ /**
160
+ * Name of the uploading file.
161
+ */
162
+ fileName: {
163
+ type: String,
164
+ },
136
165
 
137
- i18n: Object,
166
+ /**
167
+ * True if uploading is not started, false otherwise.
168
+ */
169
+ held: {
170
+ type: Boolean,
171
+ value: false,
172
+ },
173
+
174
+ /**
175
+ * True if remaining time is unknown, false otherwise.
176
+ */
177
+ indeterminate: {
178
+ type: Boolean,
179
+ value: false,
180
+ reflectToAttribute: true,
181
+ },
182
+
183
+ /**
184
+ * The object used to localize this component.
185
+ */
186
+ i18n: {
187
+ type: Object,
188
+ },
189
+
190
+ /**
191
+ * Number representing the uploading progress.
192
+ */
193
+ progress: {
194
+ type: Number,
195
+ },
196
+
197
+ /**
198
+ * Uploading status.
199
+ */
200
+ status: {
201
+ type: String,
202
+ },
138
203
 
139
204
  /**
140
205
  * Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
@@ -145,23 +210,39 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
145
210
  value: 0,
146
211
  reflectToAttribute: true,
147
212
  },
213
+
214
+ /**
215
+ * True if uploading is in progress, false otherwise.
216
+ */
217
+ uploading: {
218
+ type: Boolean,
219
+ value: false,
220
+ reflectToAttribute: true,
221
+ },
222
+
223
+ /** @private */
224
+ _progress: {
225
+ type: Object,
226
+ },
148
227
  };
149
228
  }
150
229
 
151
230
  static get observers() {
152
- return [
153
- '_fileAborted(file.abort)',
154
- '_toggleHostAttribute(file.error, "error")',
155
- '_toggleHostAttribute(file.indeterminate, "indeterminate")',
156
- '_toggleHostAttribute(file.uploading, "uploading")',
157
- '_toggleHostAttribute(file.complete, "complete")',
158
- ];
231
+ return ['__updateProgress(_progress, progress, indeterminate)'];
159
232
  }
160
233
 
161
234
  /** @protected */
162
235
  ready() {
163
236
  super.ready();
164
237
 
238
+ this.addController(
239
+ new SlotController(this, 'progress', 'vaadin-progress-bar', {
240
+ initializer: (progress) => {
241
+ this._progress = progress;
242
+ },
243
+ }),
244
+ );
245
+
165
246
  // Handle moving focus to the button on Tab.
166
247
  this.shadowRoot.addEventListener('focusin', (e) => {
167
248
  const target = e.composedPath()[0];
@@ -191,26 +272,16 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
191
272
  }
192
273
 
193
274
  /** @private */
194
- _fileAborted(abort) {
195
- if (abort) {
196
- this._remove();
197
- }
198
- }
199
-
200
- /** @private */
201
- _remove() {
202
- this.dispatchEvent(
203
- new CustomEvent('file-remove', {
204
- detail: { file: this.file },
205
- bubbles: true,
206
- composed: true,
207
- }),
208
- );
275
+ _errorMessageChanged(errorMessage) {
276
+ this.toggleAttribute('error', Boolean(errorMessage));
209
277
  }
210
278
 
211
279
  /** @private */
212
- _formatProgressValue(progress) {
213
- return progress / 100;
280
+ __updateProgress(progress, value, indeterminate) {
281
+ if (progress) {
282
+ progress.value = isNaN(value) ? 0 : value / 100;
283
+ progress.indeterminate = indeterminate;
284
+ }
214
285
  }
215
286
 
216
287
  /** @private */
@@ -225,19 +296,6 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
225
296
  );
226
297
  }
227
298
 
228
- /** @private */
229
- _toggleHostAttribute(value, attributeName) {
230
- const shouldHave = Boolean(value);
231
- const has = this.hasAttribute(attributeName);
232
- if (has !== shouldHave) {
233
- if (shouldHave) {
234
- this.setAttribute(attributeName, '');
235
- } else {
236
- this.removeAttribute(attributeName);
237
- }
238
- }
239
- }
240
-
241
299
  /**
242
300
  * Fired when the retry button is pressed. It is listened by `vaadin-upload`
243
301
  * which will start a new upload process of this file.
@@ -258,23 +316,12 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
258
316
 
259
317
  /**
260
318
  * Fired when abort button is pressed. It is listened by `vaadin-upload` which
261
- * will abort the upload in progress, but will not remove the file from the list
262
- * to allow the animation to hide the element to be run.
319
+ * will abort the upload in progress, and then remove the file from the list.
263
320
  *
264
321
  * @event file-abort
265
322
  * @param {Object} detail
266
323
  * @param {Object} detail.file file to abort upload of
267
324
  */
268
-
269
- /**
270
- * Fired after the animation to hide the element has finished. It is listened
271
- * by `vaadin-upload` which will actually remove the file from the upload
272
- * file list.
273
- *
274
- * @event file-remove
275
- * @param {Object} detail
276
- * @param {Object} detail.file file to remove from the upload of
277
- */
278
325
  }
279
326
 
280
327
  customElements.define(UploadFile.is, UploadFile);
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+
9
+ /**
10
+ * An element used internally by `<vaadin-upload>`. Not intended to be used separately.
11
+ *
12
+ * @extends HTMLElement
13
+ * @private
14
+ */
15
+ class UploadIcon extends ThemableMixin(PolymerElement) {
16
+ static get is() {
17
+ return 'vaadin-upload-icon';
18
+ }
19
+
20
+ static get template() {
21
+ return html`
22
+ <style>
23
+ :host {
24
+ display: inline-block;
25
+ }
26
+
27
+ :host([hidden]) {
28
+ display: none !important;
29
+ }
30
+ </style>
31
+ `;
32
+ }
33
+ }
34
+
35
+ customElements.define(UploadIcon.is, UploadIcon);
36
+
37
+ export { UploadIcon };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  const template = document.createElement('template');
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
6
7
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
9
 
@@ -180,13 +181,10 @@ export interface UploadEventMap extends HTMLElementEventMap, UploadCustomEventMa
180
181
  *
181
182
  * The following shadow DOM parts are available for styling:
182
183
  *
183
- * Part name | Description
184
- * ---|---
185
- * `primary-buttons` | Upload container
186
- * `upload-button` | Upload button
187
- * `drop-label` | Label for drop indicator
188
- * `drop-label-icon` | Icon for drop indicator
189
- * `file-list` | File list container
184
+ * Part name | Description
185
+ * -------------------|-------------------------------------
186
+ * `primary-buttons` | Upload container
187
+ * `drop-label` | Element wrapping drop label and icon
190
188
  *
191
189
  * The following state attributes are available for styling:
192
190
  *
@@ -212,7 +210,7 @@ export interface UploadEventMap extends HTMLElementEventMap, UploadCustomEventMa
212
210
  * @fires {CustomEvent} upload-retry - Fired when retry upload is requested.
213
211
  * @fires {CustomEvent} upload-abort - Fired when upload abort is requested.
214
212
  */
215
- declare class Upload extends ThemableMixin(ElementMixin(HTMLElement)) {
213
+ declare class Upload extends ThemableMixin(ElementMixin(ControllerMixin(HTMLElement))) {
216
214
  /**
217
215
  * Define whether the element supports dropping files on it for uploading.
218
216
  * By default it's enabled in desktop and disabled in touch devices