@uploadcare/file-uploader 1.15.0-alpha.10 → 1.15.0-alpha.12
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/blocks/FileItem/FileItem.d.ts +1 -4
- package/blocks/FileItem/FileItem.d.ts.map +1 -1
- package/blocks/FileItem/FileItem.js +6 -33
- package/blocks/ProgressBar/ProgressBar.d.ts.map +1 -1
- package/blocks/ProgressBar/ProgressBar.js +1 -0
- package/blocks/Thumb/Thumb.d.ts +12 -0
- package/blocks/Thumb/Thumb.d.ts.map +1 -1
- package/blocks/Thumb/Thumb.js +91 -6
- package/index.ssr.js +2 -2
- package/package.json +1 -1
- package/solutions/file-uploader/minimal/FileUploaderMinimal.d.ts.map +1 -1
- package/solutions/file-uploader/minimal/FileUploaderMinimal.js +1 -0
- package/web/file-uploader.iife.min.js +4 -4
- package/web/file-uploader.min.js +4 -4
- package/web/uc-file-uploader-inline.min.js +4 -4
- package/web/uc-file-uploader-minimal.min.js +4 -4
- package/web/uc-file-uploader-regular.min.js +4 -4
|
@@ -7,10 +7,6 @@ export class FileItem extends UploaderBlock {
|
|
|
7
7
|
*/
|
|
8
8
|
private _entry;
|
|
9
9
|
/** @private */
|
|
10
|
-
private _isIntersecting;
|
|
11
|
-
/** @private */
|
|
12
|
-
private _debouncedGenerateThumb;
|
|
13
|
-
/** @private */
|
|
14
10
|
private _debouncedCalculateState;
|
|
15
11
|
/** @private */
|
|
16
12
|
private _renderedOnce;
|
|
@@ -54,6 +50,7 @@ export class FileItem extends UploaderBlock {
|
|
|
54
50
|
* @param {IntersectionObserverEntry[]} entries
|
|
55
51
|
*/
|
|
56
52
|
private _observerCallback;
|
|
53
|
+
_isIntersecting: boolean | undefined;
|
|
57
54
|
_thumbRect: DOMRectReadOnly | undefined;
|
|
58
55
|
/** @private */
|
|
59
56
|
private _calculateState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["FileItem.js"],"names":[],"mappings":"AAoBA;IAIE,eAAe;IACf,mBAAuB;IACvB;;;OAGG;IACH,eAAc;
|
|
1
|
+
{"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["FileItem.js"],"names":[],"mappings":"AAoBA;IAIE,eAAe;IACf,mBAAuB;IACvB;;;OAGG;IACH,eAAc;IAEd,eAAe;IACf,iCAA0E;IAE1E,eAAe;IACf,sBAAsB;IAKpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA+BC;IAGH,eAQC;IAED;;;OAGG;IACH,0BAUC;IAPC,qCAA2C;IAC3C,wCAA0C;IAQ5C,eAAe;IACf,wBAgBC;IAED,eAAe;IACf,2BAuCC;IAED;;;;OAIG;IACH,kBAUC;IAED;;MAaQ;IAER;;;OAGG;IACH,uBAkCC;IAyDD,wEAAwE;IACxE,oBADY,CAAC,oBAAoB,CAAC,CAAC,MAAM,oBAAoB,CAAC,QA0B7D;IAaC,eAAe;IACf,kBAEE;IAUJ;;;MAEC;IAED;;;OAGG;IACH,uBAEC;IAED,wBAsFC;CACF;;;;;8BApb6B,iCAAiC;AAS/D;;;;;GAKG"}
|
|
@@ -29,10 +29,7 @@ export class FileItem extends UploaderBlock {
|
|
|
29
29
|
* @type {any} TODO: Add types for upload entry
|
|
30
30
|
*/
|
|
31
31
|
_entry = null;
|
|
32
|
-
|
|
33
|
-
_isIntersecting = false;
|
|
34
|
-
/** @private */
|
|
35
|
-
_debouncedGenerateThumb = debounce(this._generateThumbnail.bind(this), 100);
|
|
32
|
+
|
|
36
33
|
/** @private */
|
|
37
34
|
_debouncedCalculateState = debounce(this._calculateState.bind(this), 100);
|
|
38
35
|
|
|
@@ -81,7 +78,6 @@ export class FileItem extends UploaderBlock {
|
|
|
81
78
|
sub.remove();
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
this._debouncedGenerateThumb.cancel();
|
|
85
81
|
this._debouncedCalculateState.cancel();
|
|
86
82
|
this._entrySubs = new Set();
|
|
87
83
|
this._entry = null;
|
|
@@ -101,11 +97,6 @@ export class FileItem extends UploaderBlock {
|
|
|
101
97
|
this.render();
|
|
102
98
|
this._renderedOnce = true;
|
|
103
99
|
}
|
|
104
|
-
// if (entry.intersectionRatio === 0) {
|
|
105
|
-
// this._debouncedGenerateThumb.cancel();
|
|
106
|
-
// } else {
|
|
107
|
-
// this._debouncedGenerateThumb();
|
|
108
|
-
// }
|
|
109
100
|
}
|
|
110
101
|
|
|
111
102
|
/** @private */
|
|
@@ -230,21 +221,8 @@ export class FileItem extends UploaderBlock {
|
|
|
230
221
|
this.$.itemName = entry.getValue('fileName') || externalUrl || this.l10n('file-no-name');
|
|
231
222
|
});
|
|
232
223
|
|
|
233
|
-
this._subEntry('fileInfo', (
|
|
224
|
+
this._subEntry('fileInfo', () => {
|
|
234
225
|
this._debouncedCalculateState();
|
|
235
|
-
if (fileInfo && this._isIntersecting) {
|
|
236
|
-
this._debouncedGenerateThumb();
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
this._subEntry('cdnUrlModifiers', () => {
|
|
241
|
-
if (this._isIntersecting) {
|
|
242
|
-
this._debouncedGenerateThumb();
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
this._subEntry('thumbUrl', (thumbUrl) => {
|
|
247
|
-
this.$.thumbUrl = thumbUrl ? `url(${thumbUrl})` : '';
|
|
248
226
|
});
|
|
249
227
|
|
|
250
228
|
this._subEntry('errors', () => this._debouncedCalculateState());
|
|
@@ -252,10 +230,6 @@ export class FileItem extends UploaderBlock {
|
|
|
252
230
|
this._subEntry('fileSize', () => this._debouncedCalculateState());
|
|
253
231
|
this._subEntry('mimeType', () => this._debouncedCalculateState());
|
|
254
232
|
this._subEntry('isImage', () => this._debouncedCalculateState());
|
|
255
|
-
|
|
256
|
-
if (this._isIntersecting) {
|
|
257
|
-
this._debouncedGenerateThumb();
|
|
258
|
-
}
|
|
259
233
|
}
|
|
260
234
|
|
|
261
235
|
initCallback() {
|
|
@@ -271,12 +245,12 @@ export class FileItem extends UploaderBlock {
|
|
|
271
245
|
|
|
272
246
|
this.subConfigValue('useCloudImageEditor', () => this._debouncedCalculateState());
|
|
273
247
|
this.subConfigValue('filesViewMode', (mode) => {
|
|
274
|
-
if (this.cfg.filesViewMode === 'grid') {
|
|
275
|
-
this.$.showFileNames = this.cfg.gridShowFileNames;
|
|
276
|
-
}
|
|
277
248
|
if (this.cfg.filesViewMode === 'list') {
|
|
278
249
|
this.$.showFileNames = true;
|
|
279
250
|
}
|
|
251
|
+
if (this.cfg.filesViewMode === 'grid') {
|
|
252
|
+
this.$.showFileNames = this.cfg.gridShowFileNames;
|
|
253
|
+
}
|
|
280
254
|
|
|
281
255
|
this.setAttribute('mode', mode);
|
|
282
256
|
});
|
|
@@ -362,7 +336,6 @@ export class FileItem extends UploaderBlock {
|
|
|
362
336
|
disconnectedCallback() {
|
|
363
337
|
super.disconnectedCallback();
|
|
364
338
|
|
|
365
|
-
this._debouncedGenerateThumb.cancel();
|
|
366
339
|
this._observer?.disconnect();
|
|
367
340
|
}
|
|
368
341
|
|
|
@@ -469,7 +442,7 @@ export class FileItem extends UploaderBlock {
|
|
|
469
442
|
|
|
470
443
|
FileItem.template = /* HTML */ `
|
|
471
444
|
<div class="uc-inner" set="@finished: isFinished; @uploading: isUploading; @failed: isFailed; @focused: isFocused">
|
|
472
|
-
<uc-thumb set="uid:uid;
|
|
445
|
+
<uc-thumb set="uid:uid;badgeIcon:badgeIcon"></uc-thumb>
|
|
473
446
|
|
|
474
447
|
<div aria-atomic="true" aria-live="polite" class="uc-file-name-wrapper" set="@aria-label:ariaLabelStatusFile;">
|
|
475
448
|
<span class="uc-file-name" set="@hidden: !showFileNames">{{itemName}}</span>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressBar.d.ts","sourceRoot":"","sources":["ProgressBar.js"],"names":[],"mappings":"AAEA;IACE,qBAAqB;IACrB,eAAW;IAEX,sBAAsB;IACtB,kBAAgB;IAEhB,WAIE;
|
|
1
|
+
{"version":3,"file":"ProgressBar.d.ts","sourceRoot":"","sources":["ProgressBar.js"],"names":[],"mappings":"AAEA;IACE,qBAAqB;IACrB,eAAW;IAEX,sBAAsB;IACtB,kBAAgB;IAEhB,WAIE;CAgDH;;;;sBA7DqB,yBAAyB"}
|
|
@@ -54,6 +54,7 @@ export class ProgressBar extends Block {
|
|
|
54
54
|
this.defineAccessor('visible', (visible) => {
|
|
55
55
|
this._visible = visible;
|
|
56
56
|
|
|
57
|
+
this.classList.toggle('uc-progress-bar--hidden', !visible);
|
|
57
58
|
this.ref.realProgressLine.classList.toggle('uc-progress--hidden', !visible);
|
|
58
59
|
this.ref.fakeProgressLine.classList.toggle('uc-fake-progress--hidden', !visible);
|
|
59
60
|
});
|
package/blocks/Thumb/Thumb.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
export class Thumb extends UploaderBlock {
|
|
2
|
+
/**
|
|
3
|
+
* @private
|
|
4
|
+
* @type {any} TODO: Add types for upload entry
|
|
5
|
+
*/
|
|
6
|
+
private _entry;
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
* @type {IntersectionObserverEntry['boundingClientRect'] | null}
|
|
10
|
+
*/
|
|
11
|
+
private _thumbRect;
|
|
2
12
|
_debouncedGenerateThumb: (() => Promise<void>) & {
|
|
3
13
|
cancel: () => void;
|
|
4
14
|
};
|
|
15
|
+
_isIntersecting: boolean;
|
|
5
16
|
init$: {
|
|
6
17
|
thumbUrl: string;
|
|
7
18
|
badgeIcon: string;
|
|
@@ -20,6 +31,7 @@ export class Thumb extends UploaderBlock {
|
|
|
20
31
|
'*historyBack': null;
|
|
21
32
|
'*closeModal': () => void;
|
|
22
33
|
};
|
|
34
|
+
_calculateThumbSize(): number;
|
|
23
35
|
/** @private */
|
|
24
36
|
private _generateThumbnail;
|
|
25
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Thumb.d.ts","sourceRoot":"","sources":["Thumb.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Thumb.d.ts","sourceRoot":"","sources":["Thumb.js"],"names":[],"mappings":"AAMA;IACE;;;OAGG;IACH,eAAc;IAEd;;;OAGG;IACH,mBAAkB;IAElB;;MAA4E;IAE5E,yBAAwB;IAKtB;;;;;;;;;;;;;;;;;MAKC;IAGH,8BAYC;IAED,eAAe;IACf,2BAqCC;IAED;;;OAGG;IACH,0BAaC;IAqCC,4CAAuG;CAW1G;;;;8BAzJ6B,iCAAiC"}
|
package/blocks/Thumb/Thumb.js
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
|
|
3
1
|
import { UploaderBlock } from '../../abstract/UploaderBlock.js';
|
|
2
|
+
import { createCdnUrl, createCdnUrlModifiers, createOriginalUrl } from '../../utils/cdn-utils.js';
|
|
3
|
+
import { fileCssBg } from '../svg-backgrounds/svg-backgrounds.js';
|
|
4
4
|
import { debounce } from '../utils/debounce.js';
|
|
5
|
+
import { generateThumb } from '../utils/resizeImage.js';
|
|
5
6
|
|
|
6
7
|
export class Thumb extends UploaderBlock {
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
* @type {any} TODO: Add types for upload entry
|
|
11
|
+
*/
|
|
12
|
+
_entry = null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @private
|
|
16
|
+
* @type {IntersectionObserverEntry['boundingClientRect'] | null}
|
|
17
|
+
*/
|
|
18
|
+
_thumbRect = null;
|
|
19
|
+
|
|
7
20
|
_debouncedGenerateThumb = debounce(this._generateThumbnail.bind(this), 100);
|
|
8
21
|
|
|
22
|
+
_isIntersecting = false;
|
|
23
|
+
|
|
9
24
|
constructor() {
|
|
10
25
|
super();
|
|
11
26
|
|
|
@@ -17,9 +32,58 @@ export class Thumb extends UploaderBlock {
|
|
|
17
32
|
};
|
|
18
33
|
}
|
|
19
34
|
|
|
35
|
+
_calculateThumbSize() {
|
|
36
|
+
let size = Math.max(
|
|
37
|
+
parseInt(String(this?._thumbRect?.height || 0)),
|
|
38
|
+
parseInt(String(this?._thumbRect?.width || 0)),
|
|
39
|
+
this.cfg.thumbSize,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (window.devicePixelRatio > 1) {
|
|
43
|
+
size *= window.devicePixelRatio;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
|
|
20
49
|
/** @private */
|
|
21
50
|
async _generateThumbnail() {
|
|
22
|
-
|
|
51
|
+
if (!this._entry) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let entry = this._entry;
|
|
55
|
+
|
|
56
|
+
if (entry.getValue('fileInfo') && entry.getValue('isImage')) {
|
|
57
|
+
let size = this._calculateThumbSize();
|
|
58
|
+
|
|
59
|
+
let thumbUrl = await this.proxyUrl(
|
|
60
|
+
createCdnUrl(
|
|
61
|
+
createOriginalUrl(this.cfg.cdnCname, this._entry.getValue('uuid')),
|
|
62
|
+
createCdnUrlModifiers(entry.getValue('cdnUrlModifiers'), `scale_crop/${size}x${size}/center/-/preview/`),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
let currentThumbUrl = entry.getValue('thumbUrl');
|
|
66
|
+
if (currentThumbUrl !== thumbUrl) {
|
|
67
|
+
entry.setValue('thumbUrl', thumbUrl);
|
|
68
|
+
currentThumbUrl?.startsWith('blob:') && URL.revokeObjectURL(currentThumbUrl);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (entry.getValue('file')?.type.includes('image')) {
|
|
74
|
+
try {
|
|
75
|
+
let size = this._calculateThumbSize();
|
|
76
|
+
|
|
77
|
+
let thumbUrl = await generateThumb(entry.getValue('file'), size);
|
|
78
|
+
entry.setValue('thumbUrl', thumbUrl);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
let color = window.getComputedStyle(this).getPropertyValue('--uc-muted-foreground');
|
|
81
|
+
entry.setValue('thumbUrl', fileCssBg(color));
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
let color = window.getComputedStyle(this).getPropertyValue('--uc-muted-foreground');
|
|
85
|
+
entry.setValue('thumbUrl', fileCssBg(color));
|
|
86
|
+
}
|
|
23
87
|
}
|
|
24
88
|
|
|
25
89
|
/**
|
|
@@ -28,7 +92,10 @@ export class Thumb extends UploaderBlock {
|
|
|
28
92
|
*/
|
|
29
93
|
_observerCallback(entries) {
|
|
30
94
|
const [entry] = entries;
|
|
95
|
+
this._isIntersecting = entry.isIntersecting;
|
|
96
|
+
|
|
31
97
|
if (entry.isIntersecting) {
|
|
98
|
+
this._thumbRect = entry.boundingClientRect;
|
|
32
99
|
this._debouncedGenerateThumb();
|
|
33
100
|
this._observer?.disconnect();
|
|
34
101
|
}
|
|
@@ -41,13 +108,32 @@ export class Thumb extends UploaderBlock {
|
|
|
41
108
|
initCallback() {
|
|
42
109
|
super.initCallback();
|
|
43
110
|
|
|
44
|
-
this.defineAccessor('thumbUrl', (/** @type {string} */ val) => (this.$.thumbUrl = val));
|
|
45
111
|
this.defineAccessor('badgeIcon', (/** @type {string} */ val) => (this.$.badgeIcon = val));
|
|
46
112
|
|
|
47
113
|
this.defineAccessor('uid', (/** @type {string} */ value) => {
|
|
48
114
|
this.set$({ uid: value });
|
|
49
115
|
});
|
|
50
116
|
|
|
117
|
+
this.sub('uid', (value) => {
|
|
118
|
+
this._entry = this.uploadCollection.read(value);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
this._entry?.subscribe('fileInfo', (fileInfo) => {
|
|
122
|
+
if (fileInfo?.isImage && this._isIntersecting) {
|
|
123
|
+
this._debouncedGenerateThumb();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
this._entry?.subscribe('thumbUrl', (thumbUrl) => {
|
|
128
|
+
this.$.thumbUrl = thumbUrl ? `url(${thumbUrl})` : '';
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
this._entry?.subscribe('cdnUrlModifiers', () => {
|
|
132
|
+
if (this._isIntersecting) {
|
|
133
|
+
this._debouncedGenerateThumb();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
51
137
|
this.setAttribute('role', 'img');
|
|
52
138
|
}
|
|
53
139
|
|
|
@@ -62,6 +148,7 @@ export class Thumb extends UploaderBlock {
|
|
|
62
148
|
disconnectedCallback() {
|
|
63
149
|
super.disconnectedCallback();
|
|
64
150
|
|
|
151
|
+
this._debouncedGenerateThumb.cancel();
|
|
65
152
|
this._observer?.disconnect();
|
|
66
153
|
}
|
|
67
154
|
}
|
|
@@ -75,8 +162,6 @@ Thumb.template = /* html */ `
|
|
|
75
162
|
`;
|
|
76
163
|
|
|
77
164
|
Thumb.bindAttributes({
|
|
78
|
-
// @ts-expect-error TODO: fix types inside symbiote
|
|
79
|
-
thumbUrl: null,
|
|
80
165
|
// @ts-expect-error TODO: fix types inside symbiote
|
|
81
166
|
badgeIcon: null,
|
|
82
167
|
// @ts-expect-error TODO: fix types inside symbiote
|
package/index.ssr.js
CHANGED
|
@@ -840,7 +840,7 @@ export const ExternalUploadSource = {
|
|
|
840
840
|
export const FileItem = class {
|
|
841
841
|
static template = `
|
|
842
842
|
<div class="uc-inner" set="@finished: isFinished; @uploading: isUploading; @failed: isFailed; @focused: isFocused">
|
|
843
|
-
<uc-thumb set="uid:uid;
|
|
843
|
+
<uc-thumb set="uid:uid;badgeIcon:badgeIcon"></uc-thumb>
|
|
844
844
|
|
|
845
845
|
<div aria-atomic="true" aria-live="polite" class="uc-file-name-wrapper" set="@aria-label:ariaLabelStatusFile;">
|
|
846
846
|
<span class="uc-file-name" set="@hidden: !showFileNames">{{itemName}}</span>
|
|
@@ -1305,7 +1305,7 @@ export const Thumb = class {
|
|
|
1305
1305
|
</div>
|
|
1306
1306
|
</div>
|
|
1307
1307
|
`;
|
|
1308
|
-
static observedAttributes = ["
|
|
1308
|
+
static observedAttributes = ["badgeIcon", "uid"];
|
|
1309
1309
|
static extSrcList = {
|
|
1310
1310
|
FACEBOOK: "facebook",
|
|
1311
1311
|
DROPBOX: "dropbox",
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileUploaderMinimal.d.ts","sourceRoot":"","sources":["FileUploaderMinimal.js"],"names":[],"mappings":"AAQA;IAMI;;;;;;;;;;;;;;;;;;MAMC;IAXF;;;aAAkD;IAAlD;;;aAAkD;
|
|
1
|
+
{"version":3,"file":"FileUploaderMinimal.d.ts","sourceRoot":"","sources":["FileUploaderMinimal.js"],"names":[],"mappings":"AAQA;IAMI;;;;;;;;;;;;;;;;;;MAMC;IAXF;;;aAAkD;IAAlD;;;aAAkD;IAyGjD;;;4BAAuD;IACvD;;;4BAAyD;CAW5D;;;;8BA5H6B,oCAAoC"}
|