@uploadcare/file-uploader 0.50.1-alpha.2 → 1.0.0
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/README.md +22 -22
- package/abstract/Block.d.ts +4 -2
- package/abstract/Block.d.ts.map +1 -1
- package/abstract/Block.js +15 -19
- package/abstract/UploaderBlock.js +4 -4
- package/abstract/registerBlocks.d.ts.map +1 -1
- package/abstract/registerBlocks.js +2 -12
- package/blocks/CloudImageEditor/src/CloudImageEditorBlock.js +1 -1
- package/blocks/CloudImageEditor/src/EditorFilterControl.d.ts +2 -2
- package/blocks/CloudImageEditor/src/EditorFilterControl.d.ts.map +1 -1
- package/blocks/CloudImageEditor/src/EditorFilterControl.js +32 -22
- package/blocks/CloudImageEditor/src/EditorImageCropper.js +3 -3
- package/blocks/CloudImageEditor/src/EditorImageFader.d.ts +5 -5
- package/blocks/CloudImageEditor/src/EditorImageFader.d.ts.map +1 -1
- package/blocks/CloudImageEditor/src/EditorImageFader.js +17 -15
- package/blocks/CloudImageEditor/src/EditorToolbar.js +4 -4
- package/blocks/FileItem/FileItem.js +1 -1
- package/env.d.ts +1 -1
- package/env.d.ts.map +1 -1
- package/env.js +1 -1
- package/index.ssr.d.ts +1 -1
- package/index.ssr.d.ts.map +1 -1
- package/index.ssr.js +1 -1
- package/package.json +1 -1
- package/types/exported.d.ts +1 -1
- package/types/jsx.d.ts +1 -1
- package/web/blocks.iife.min.js +4 -4
- package/web/blocks.min.js +4 -4
- package/web/lr-cloud-image-editor.min.js +4 -4
- package/web/lr-file-uploader-inline.min.js +4 -4
- package/web/lr-file-uploader-minimal.min.js +3 -3
- package/web/lr-file-uploader-regular.min.js +4 -4
- package/web/lr-img.min.js +1 -1
- package/web/uc-cloud-image-editor.min.js +4 -4
- package/web/uc-file-uploader-inline.min.js +4 -4
- package/web/uc-file-uploader-minimal.min.js +3 -3
- package/web/uc-file-uploader-regular.min.js +4 -4
- package/web/uc-img.min.js +1 -1
package/README.md
CHANGED
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
<a href="https://twitter.com/Uploadcare?ref=github-readme">Twitter</a>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
|
-
# 📦 Uploadcare
|
|
19
|
+
# 📦 Uploadcare File Uploader: stack-agnostic library for uploading, processing, and editing images on-the-fly
|
|
20
20
|
|
|
21
|
-
[](https://www.npmjs.com/package/@uploadcare/
|
|
21
|
+
[](https://www.npmjs.com/package/@uploadcare/file-uploader)
|
|
22
22
|
[](https://github.com/uploadcare/blocks/actions?query=workflow%3ABuild+branch%3Amaster)
|
|
23
23
|
[](https://opensource.org/licenses/MIT)
|
|
24
24
|
|
|
25
|
-
_Uploadcare
|
|
25
|
+
_Uploadcare File Uploader_ is a powerful JavaScript library for creating custom file-handling services.
|
|
26
26
|
It includes various interactive and customizable UI components to enhance users' file uploading
|
|
27
27
|
and processing experience. As a bonus, you receive all the
|
|
28
28
|
[Uploadcare's](https://uploadcare.com/?ref=github-readme) versatile file-handling capabilities,
|
|
@@ -31,9 +31,9 @@ including [smart CDN](https://uploadcare.com/docs/delivery/cdn/#content-delivery
|
|
|
31
31
|
[signed uploads](https://uploadcare.com/docs/security/secure-uploads/?ref=github-readme),
|
|
32
32
|
and [even more](<(https://uploadcare.com/features/?ref=github-readme)>).
|
|
33
33
|
|
|
34
|
-
See Uploadcare
|
|
34
|
+
See Uploadcare File Uploader [in action](https://codesandbox.io/p/devbox/github/uploadcare/blocks-examples/tree/main/examples/js-uploader)!
|
|
35
35
|
|
|
36
|
-
<img alt="Uploadcare
|
|
36
|
+
<img alt="Uploadcare File Uploader examples" src="https://ucarecdn.com/2883da9f-6962-49db-9947-f91a3e25be2f/-/preview/">
|
|
37
37
|
|
|
38
38
|
## Core features
|
|
39
39
|
|
|
@@ -45,7 +45,7 @@ See Uploadcare Blocks [in action](https://codesandbox.io/p/devbox/github/uploadc
|
|
|
45
45
|
|
|
46
46
|
* **Coming soon!** Web Components for any media content management like audio, video, image galleries, and more.
|
|
47
47
|
|
|
48
|
-
## Why Uploadcare
|
|
48
|
+
## Why Uploadcare File Uploader?
|
|
49
49
|
|
|
50
50
|
### Rapid integration
|
|
51
51
|
|
|
@@ -53,11 +53,11 @@ We provide a ready-to-use set of UI components for file handling. It saves you v
|
|
|
53
53
|
|
|
54
54
|
### Cross-platform compatibility
|
|
55
55
|
|
|
56
|
-
Uploadcare
|
|
56
|
+
Uploadcare File Uploader are designed to work seamlessly across various platforms and frameworks. Whether you're building a web application using React, Vue.js, Angular, Svelte, or other frameworks, you get [integrations and support](https://uploadcare.com/docs/integrations/?ref=github-readme) for various development environments.
|
|
57
57
|
|
|
58
58
|
### Developer-friendly
|
|
59
59
|
|
|
60
|
-
The library comes with modern technologies at your fingertips, like [Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components), [ESM-level](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) code sharing, and other cutting-edge web standards. _Uploadcare
|
|
60
|
+
The library comes with modern technologies at your fingertips, like [Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components), [ESM-level](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) code sharing, and other cutting-edge web standards. _Uploadcare File Uploader_ is designed lightweight with minimum external dependencies for a cheap security audit.
|
|
61
61
|
|
|
62
62
|
### Typescript support
|
|
63
63
|
|
|
@@ -67,32 +67,32 @@ We use [JSDoc type annotations](https://www.typescriptlang.org/docs/handbook/int
|
|
|
67
67
|
|
|
68
68
|
### From CDN
|
|
69
69
|
|
|
70
|
-
1. Connect Uploadcare
|
|
70
|
+
1. Connect Uploadcare File Uploader directly from your document:
|
|
71
71
|
|
|
72
72
|
```html
|
|
73
73
|
<script type="module">
|
|
74
|
-
import * as UC from 'https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@
|
|
74
|
+
import * as UC from 'https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/blocks.min.js';
|
|
75
75
|
|
|
76
76
|
UC.registerBlocks(UC);
|
|
77
77
|
</script>
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
2. Start using Uploadcare
|
|
80
|
+
2. Start using Uploadcare File Uploader in your application markup:
|
|
81
81
|
|
|
82
82
|
```html
|
|
83
83
|
<link
|
|
84
84
|
rel="stylesheet"
|
|
85
|
-
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@
|
|
85
|
+
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/uc-file-uploader-regular.min.css"
|
|
86
86
|
/>
|
|
87
87
|
|
|
88
88
|
<uc-file-uploader-regular ctx-name="my-uploader"> </uc-file-uploader-regular>
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
3. Configure Uploadcare
|
|
91
|
+
3. Configure Uploadcare File Uploader and add your personal public key to the project. Discover the instructions in the [following section](#configuration).
|
|
92
92
|
|
|
93
93
|
### From NPM
|
|
94
94
|
|
|
95
|
-
1. Install Uploadcare
|
|
95
|
+
1. Install Uploadcare File Uploader package: `npm i @uploadcare/file-uploader`
|
|
96
96
|
2. Connect `Blocks` from your script file:
|
|
97
97
|
|
|
98
98
|
```js
|
|
@@ -101,22 +101,22 @@ import * as UC from '@uploadcare/file-uploader';
|
|
|
101
101
|
UC.registerBlocks(UC);
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
3. Start using Uploadcare
|
|
104
|
+
3. Start using Uploadcare File Uploader in your application markup:
|
|
105
105
|
|
|
106
106
|
```html
|
|
107
107
|
<link
|
|
108
108
|
rel="stylesheet"
|
|
109
|
-
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@
|
|
109
|
+
href="https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@1/web/uc-file-uploader-regular.min.css"
|
|
110
110
|
/>
|
|
111
111
|
|
|
112
112
|
<uc-file-uploader-inline ctx-name="my-uploader"> </uc-file-uploader-inline>
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
4. Configure Uploadcare
|
|
115
|
+
4. Configure Uploadcare File Uploader and add your personal public key to the project. Discover the instructions in the [following section](#configuration).
|
|
116
116
|
|
|
117
117
|
### Configuration
|
|
118
118
|
|
|
119
|
-
All configurations in Uploadcare
|
|
119
|
+
All configurations in Uploadcare File Uploader are managed from `uc-config` block.
|
|
120
120
|
|
|
121
121
|
1. Sign up to [Uploadcare](https://app.uploadcare.com/accounts/signup/?ref=github-readme).
|
|
122
122
|
2. Get a Public API key in [Uploadcare project's dashboard](https://app.uploadcare.com/projects/-/api-keys/?ref=github-readme).
|
|
@@ -128,11 +128,11 @@ All configurations in Uploadcare Blocks are managed from `uc-config` block.
|
|
|
128
128
|
|
|
129
129
|
4. Make sure that your config block uses the same `ctx-name` attribute value as your solution block.
|
|
130
130
|
|
|
131
|
-
Discover more about Uploadcare
|
|
131
|
+
Discover more about Uploadcare File Uploader configuration in [our documentation](https://uploadcare.com/docs/file-uploader/configuration/?ref=github-readme).
|
|
132
132
|
|
|
133
|
-
### Deep dive in Uploadcare
|
|
133
|
+
### Deep dive in Uploadcare File Uploader 🛠
|
|
134
134
|
|
|
135
|
-
Follow our [step-by-step installation guide](https://uploadcare.com/docs/file-uploader/installation/?ref=github-readme) to launch Uploadcare
|
|
135
|
+
Follow our [step-by-step installation guide](https://uploadcare.com/docs/file-uploader/installation/?ref=github-readme) to launch Uploadcare File Uploader in a few minutes and set it up based on your needs.
|
|
136
136
|
|
|
137
137
|
## Browser support
|
|
138
138
|
|
|
@@ -142,7 +142,7 @@ Internet Explorer is outdated and [not supported anymore](https://uploadcare.com
|
|
|
142
142
|
|
|
143
143
|
## Framework support
|
|
144
144
|
|
|
145
|
-
_Uploadcare
|
|
145
|
+
_Uploadcare File Uploader_ is a framework-agnostic solution, so you can use it with **any** runtime you like. Discover the integration examples:
|
|
146
146
|
<br/>
|
|
147
147
|
|
|
148
148
|
- [React](https://github.com/uploadcare/uc-blocks-examples/tree/main/examples/react-uploader)
|
package/abstract/Block.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export class Block extends BaseComponent<any> {
|
|
|
3
3
|
static StateConsumerScope: string | null;
|
|
4
4
|
/** @type {string[]} */
|
|
5
5
|
static styleAttrs: string[];
|
|
6
|
+
/** @param {String} [name] */
|
|
7
|
+
static reg(name?: string | undefined): void;
|
|
6
8
|
constructor();
|
|
7
9
|
/** @protected */
|
|
8
10
|
protected requireCtxName: boolean;
|
|
@@ -76,10 +78,10 @@ export class Block extends BaseComponent<any> {
|
|
|
76
78
|
protected destroyCtxCallback(): void;
|
|
77
79
|
/**
|
|
78
80
|
* @param {String} url
|
|
79
|
-
* @returns {String}
|
|
81
|
+
* @returns {Promise<String>}
|
|
80
82
|
* @protected
|
|
81
83
|
*/
|
|
82
|
-
protected proxyUrl(url: string): string
|
|
84
|
+
protected proxyUrl(url: string): Promise<string>;
|
|
83
85
|
/** @returns {import('../types').ConfigType} } */
|
|
84
86
|
get cfg(): import("../types").ConfigType;
|
|
85
87
|
/** @private */
|
package/abstract/Block.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Block.d.ts","sourceRoot":"","sources":["Block.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Block.d.ts","sourceRoot":"","sources":["Block.js"],"names":[],"mappings":"AAmBA;IACE,4BAA4B;IAC5B,2BADW,MAAM,GAAG,IAAI,CACS;IAEjC,uBAAuB;IACvB,mBADW,MAAM,EAAE,CACI;IAoTvB,6BAA6B;IAC7B,4CAQC;IAzQD,cAMC;IAxDD,iBAAiB;IACjB,kCAAuB;IAEvB,wDAAwD;IACxD,cADW,OAAO,oBAAoB,EAAE,YAAY,CAChC;IAEpB,UAAmB;IAEnB;;;;OAIG;IACH;;eAcC;IAED;;;;;OAKG;IACH,kBAIC;IAED;;;;OAIG;IACH,wBAJW,MAAM,YACN,MAAM,IAAI,QAKpB;IAIC,uDAAuD;IACvD,mBADW,IAAI,MAAM,EAAE,IAAI;QAAE,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC,CAAC,CACjB;IAKpC;;;;OAIG;IACH,WAJW;;qBAAuF,CAAC,CAAC,YACzF;;qBAAuF,CAAC,CAAC,YACzF;;qBAAuF,CAAC,CAAC,QASnG;IAED;;;OAGG;IACH,gCAHmB,KAAK,KAAK,OAAO,WAUnC;IAED;;;OAGG;IACH,oCAFW,GAAG,QASb;IAkED;;;OAGG;IACH,4BAEC;IAED;;;OAGG;IACH,kCAEC;IAED,yBAAyB;IACzB,iCAEC;IAsBD;;;;OAIG;IACH,qCAIC;IAED;;;;OAIG;IACH,iCAHa,eAAe,CA6B3B;IAED,iDAAiD;IACjD,yCA8BC;IA3BG,eAAe;IACf,mBAuBE;IAKN;;;;OAIG;IACH,6HAFwD,IAAI,QAQ3D;IAED,8BAA8B;IAC9B,oBADY,OAAO,EAAE,QAWpB;CAYF;;8BArVmC,sBAAsB;qBAarC,WAAW"}
|
package/abstract/Block.js
CHANGED
|
@@ -15,7 +15,6 @@ import { sharedConfigKey } from './sharedConfigKey.js';
|
|
|
15
15
|
import { A11y } from './a11y.js';
|
|
16
16
|
|
|
17
17
|
const TAG_PREFIX = 'uc-';
|
|
18
|
-
const LEGACY_TAG_PREFIX = 'lr-';
|
|
19
18
|
|
|
20
19
|
// @ts-ignore TODO: fix this
|
|
21
20
|
export class Block extends BaseComponent {
|
|
@@ -237,26 +236,30 @@ export class Block extends BaseComponent {
|
|
|
237
236
|
Data.deleteCtx(this.ctxName);
|
|
238
237
|
|
|
239
238
|
this.localeManager?.destroy();
|
|
240
|
-
this.a11y?.destroy();
|
|
241
239
|
}
|
|
242
240
|
|
|
243
241
|
/**
|
|
244
242
|
* @param {String} url
|
|
245
|
-
* @returns {String}
|
|
243
|
+
* @returns {Promise<String>}
|
|
246
244
|
* @protected
|
|
247
245
|
*/
|
|
248
|
-
proxyUrl(url) {
|
|
246
|
+
async proxyUrl(url) {
|
|
249
247
|
if (this.cfg.secureDeliveryProxy && this.cfg.secureDeliveryProxyUrlResolver) {
|
|
250
248
|
console.warn(
|
|
251
249
|
'Both secureDeliveryProxy and secureDeliveryProxyUrlResolver are set. The secureDeliveryProxyUrlResolver will be used.',
|
|
252
250
|
);
|
|
253
251
|
}
|
|
254
252
|
if (this.cfg.secureDeliveryProxyUrlResolver) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
253
|
+
try {
|
|
254
|
+
return await this.cfg.secureDeliveryProxyUrlResolver(url, {
|
|
255
|
+
uuid: extractUuid(url),
|
|
256
|
+
cdnUrlModifiers: extractCdnUrlModifiers(url),
|
|
257
|
+
fileName: extractFilename(url),
|
|
258
|
+
});
|
|
259
|
+
} catch (err) {
|
|
260
|
+
console.error('Failed to resolve secure delivery proxy URL. Falling back to the default URL.', err);
|
|
261
|
+
return url;
|
|
262
|
+
}
|
|
260
263
|
}
|
|
261
264
|
if (this.cfg.secureDeliveryProxy) {
|
|
262
265
|
return applyTemplateData(
|
|
@@ -327,21 +330,14 @@ export class Block extends BaseComponent {
|
|
|
327
330
|
console.log(`[${this.ctxName}]`, ...consoleArgs);
|
|
328
331
|
}
|
|
329
332
|
|
|
330
|
-
/**
|
|
331
|
-
|
|
332
|
-
* @param {Boolean} [isAlias]
|
|
333
|
-
*/
|
|
334
|
-
static reg(name, isAlias = false) {
|
|
333
|
+
/** @param {String} [name] */
|
|
334
|
+
static reg(name) {
|
|
335
335
|
if (!name) {
|
|
336
336
|
super.reg();
|
|
337
337
|
return;
|
|
338
338
|
}
|
|
339
339
|
if (name.startsWith(TAG_PREFIX)) {
|
|
340
|
-
super.reg(name
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (name.startsWith(LEGACY_TAG_PREFIX)) {
|
|
344
|
-
super.reg(name, isAlias);
|
|
340
|
+
super.reg(name);
|
|
345
341
|
}
|
|
346
342
|
}
|
|
347
343
|
}
|
|
@@ -281,10 +281,10 @@ export class UploaderBlock extends ActivityBlock {
|
|
|
281
281
|
return entry.getValue('errors').length > 0;
|
|
282
282
|
});
|
|
283
283
|
if (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
uploadCollection.size > 0 &&
|
|
285
|
+
errorItems.length === 0 &&
|
|
286
|
+
uploadCollection.size === loadedItems.length &&
|
|
287
|
+
this.$['*collectionErrors'].length === 0
|
|
288
288
|
) {
|
|
289
289
|
this.emit(
|
|
290
290
|
EventType.COMMON_UPLOAD_SUCCESS,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerBlocks.d.ts","sourceRoot":"","sources":["registerBlocks.js"],"names":[],"mappings":"AAAA,gDAAgD;AAChD;QADmB,MAAM,GAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"registerBlocks.d.ts","sourceRoot":"","sources":["registerBlocks.js"],"names":[],"mappings":"AAAA,gDAAgD;AAChD;QADmB,MAAM,GAAE,GAAG;SAoB7B"}
|
|
@@ -11,21 +11,11 @@ export function registerBlocks(blockExports) {
|
|
|
11
11
|
tagName = tagName.replace('-', '');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
let currentTagName = '';
|
|
15
14
|
if (!tagName.startsWith('uc-')) {
|
|
16
|
-
|
|
15
|
+
tagName = 'uc-' + tagName;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
let legacyTagName = '';
|
|
20
|
-
if (!tagName.startsWith('lr-')) {
|
|
21
|
-
legacyTagName = addPrefix('lr-', tagName);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
if (blockExports[blockName].reg) {
|
|
25
|
-
blockExports[blockName].reg(
|
|
26
|
-
blockExports[blockName].reg(legacyTagName, true);
|
|
18
|
+
blockExports[blockName].reg(tagName);
|
|
27
19
|
}
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
|
-
|
|
31
|
-
const addPrefix = (prefix, name) => prefix + name;
|
|
@@ -108,7 +108,7 @@ export class CloudImageEditorBlock extends Block {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
try {
|
|
111
|
-
const cdnUrl = createCdnUrl(this.$['*originalUrl'], createCdnUrlModifiers('json'));
|
|
111
|
+
const cdnUrl = await this.proxyUrl(createCdnUrl(this.$['*originalUrl'], createCdnUrlModifiers('json')));
|
|
112
112
|
const json = await fetch(cdnUrl).then((response) => response.json());
|
|
113
113
|
|
|
114
114
|
const { width, height } = /** @type {{ width: number; height: number }} */ (json);
|
|
@@ -4,10 +4,10 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
4
4
|
* @param {IntersectionObserverEntry[]} entries
|
|
5
5
|
* @param {IntersectionObserver} observer
|
|
6
6
|
*/
|
|
7
|
-
_observerCallback(entries: IntersectionObserverEntry[], observer: IntersectionObserver): void
|
|
7
|
+
_observerCallback(entries: IntersectionObserverEntry[], observer: IntersectionObserver): Promise<void>;
|
|
8
8
|
_cancelPreload: (() => void) | undefined;
|
|
9
9
|
_operation: string | undefined;
|
|
10
|
-
_filter:
|
|
10
|
+
_filter: string | undefined;
|
|
11
11
|
_observer: IntersectionObserver | undefined;
|
|
12
12
|
_originalUrl: any;
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorFilterControl.d.ts","sourceRoot":"","sources":["EditorFilterControl.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorFilterControl.d.ts","sourceRoot":"","sources":["EditorFilterControl.js"],"names":[],"mappings":"AAOA;IAeE,sBA2BC;IAED;;;OAGG;IACH,2BAHW,yBAAyB,EAAE,YAC3B,oBAAoB,iBAuB9B;IAfG,yCAA4B;IAoC1B,+BAA0B;IAC1B,4BAAqB;IAMzB,4CAEE;IAGF,kBAA+B;CAgDlC;;;;oCA3JmC,0BAA0B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { createCdnUrl, createCdnUrlModifiers } from '../../../utils/cdn-utils.js';
|
|
2
3
|
import { EditorButtonControl } from './EditorButtonControl.js';
|
|
3
4
|
import { FAKE_ORIGINAL_FILTER } from './EditorSlider.js';
|
|
@@ -5,15 +6,19 @@ import { COMMON_OPERATIONS, transformationsToOperations } from './lib/transforma
|
|
|
5
6
|
import { preloadImage } from './lib/preloadImage.js';
|
|
6
7
|
|
|
7
8
|
export class EditorFilterControl extends EditorButtonControl {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
|
|
12
|
+
this.init$ = {
|
|
13
|
+
...this.init$,
|
|
14
|
+
active: false,
|
|
15
|
+
title: '',
|
|
16
|
+
icon: '',
|
|
17
|
+
isOriginal: false,
|
|
18
|
+
iconSize: '20',
|
|
19
|
+
'on.click': null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
17
22
|
|
|
18
23
|
_previewSrc() {
|
|
19
24
|
let previewSize = parseInt(window.getComputedStyle(this).getPropertyValue('--l-base-min-width'), 10);
|
|
@@ -24,6 +29,7 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
24
29
|
|
|
25
30
|
/** @type {import('./types.js').Transformations} */
|
|
26
31
|
let transformations = { ...this.$['*editorTransformations'] };
|
|
32
|
+
// @ts-expect-error FIXME: fix this
|
|
27
33
|
transformations[this._operation] =
|
|
28
34
|
this._filter !== FAKE_ORIGINAL_FILTER
|
|
29
35
|
? {
|
|
@@ -47,10 +53,10 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
47
53
|
* @param {IntersectionObserverEntry[]} entries
|
|
48
54
|
* @param {IntersectionObserver} observer
|
|
49
55
|
*/
|
|
50
|
-
_observerCallback(entries, observer) {
|
|
56
|
+
async _observerCallback(entries, observer) {
|
|
51
57
|
let intersectionEntry = entries[0];
|
|
52
58
|
if (intersectionEntry.isIntersecting) {
|
|
53
|
-
let src = this.proxyUrl(this._previewSrc());
|
|
59
|
+
let src = await this.proxyUrl(this._previewSrc());
|
|
54
60
|
let previewEl = this.ref['preview-el'];
|
|
55
61
|
let { promise, cancel } = preloadImage(src);
|
|
56
62
|
this._cancelPreload = cancel;
|
|
@@ -66,14 +72,14 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
66
72
|
observer.unobserve(this);
|
|
67
73
|
});
|
|
68
74
|
} else {
|
|
69
|
-
this._cancelPreload
|
|
75
|
+
this._cancelPreload?.();
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
initCallback() {
|
|
74
80
|
super.initCallback();
|
|
75
81
|
|
|
76
|
-
this.$['on.click'] = (
|
|
82
|
+
this.$['on.click'] = () => {
|
|
77
83
|
if (!this.$.active) {
|
|
78
84
|
this.$['*sliderEl'].setOperation(this._operation, this._filter);
|
|
79
85
|
this.$['*sliderEl'].apply();
|
|
@@ -85,12 +91,16 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
85
91
|
this.$['*currentFilter'] = this._filter;
|
|
86
92
|
};
|
|
87
93
|
|
|
88
|
-
this.defineAccessor(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
this.defineAccessor(
|
|
95
|
+
'filter',
|
|
96
|
+
/** @param {string} filter */
|
|
97
|
+
(filter) => {
|
|
98
|
+
this._operation = 'filter';
|
|
99
|
+
this._filter = filter;
|
|
100
|
+
this.$.isOriginal = filter === FAKE_ORIGINAL_FILTER;
|
|
101
|
+
this.$.icon = this.$.isOriginal ? 'original' : 'slider';
|
|
102
|
+
},
|
|
103
|
+
);
|
|
94
104
|
|
|
95
105
|
this._observer = new window.IntersectionObserver(this._observerCallback.bind(this), {
|
|
96
106
|
threshold: [0, 1],
|
|
@@ -128,9 +138,9 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
128
138
|
}
|
|
129
139
|
});
|
|
130
140
|
|
|
131
|
-
this.sub('*networkProblems', (networkProblems) => {
|
|
141
|
+
this.sub('*networkProblems', async (networkProblems) => {
|
|
132
142
|
if (!networkProblems) {
|
|
133
|
-
let src = this.proxyUrl(this._previewSrc());
|
|
143
|
+
let src = await this.proxyUrl(this._previewSrc());
|
|
134
144
|
let previewEl = this.ref['preview-el'];
|
|
135
145
|
if (previewEl.style.backgroundImage) {
|
|
136
146
|
previewEl.style.backgroundImage = 'none';
|
|
@@ -143,7 +153,7 @@ export class EditorFilterControl extends EditorButtonControl {
|
|
|
143
153
|
destroyCallback() {
|
|
144
154
|
super.destroyCallback();
|
|
145
155
|
this._observer?.disconnect();
|
|
146
|
-
this._cancelPreload
|
|
156
|
+
this._cancelPreload?.();
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
|
|
@@ -461,7 +461,7 @@ export class EditorImageCropper extends Block {
|
|
|
461
461
|
* @param {import('./types.js').Transformations} transformations
|
|
462
462
|
* @returns {Promise<HTMLImageElement>}
|
|
463
463
|
*/
|
|
464
|
-
_waitForImage(originalUrl, transformations) {
|
|
464
|
+
async _waitForImage(originalUrl, transformations) {
|
|
465
465
|
let width = this.offsetWidth;
|
|
466
466
|
transformations = {
|
|
467
467
|
...transformations,
|
|
@@ -470,13 +470,13 @@ export class EditorImageCropper extends Block {
|
|
|
470
470
|
flip: undefined,
|
|
471
471
|
mirror: undefined,
|
|
472
472
|
};
|
|
473
|
-
let src = this.proxyUrl(viewerImageSrc(originalUrl, width, transformations));
|
|
473
|
+
let src = await this.proxyUrl(viewerImageSrc(originalUrl, width, transformations));
|
|
474
474
|
let { promise, cancel, image } = preloadImage(src);
|
|
475
475
|
|
|
476
476
|
let stop = this._handleImageLoading(src);
|
|
477
477
|
image.addEventListener('load', stop, { once: true });
|
|
478
478
|
image.addEventListener('error', stop, { once: true });
|
|
479
|
-
this._cancelPreload
|
|
479
|
+
this._cancelPreload?.();
|
|
480
480
|
this._cancelPreload = cancel;
|
|
481
481
|
|
|
482
482
|
return promise
|
|
@@ -35,14 +35,14 @@ export class EditorImageFader extends Block {
|
|
|
35
35
|
* @param {String} [options.filter]
|
|
36
36
|
* @param {String} [options.operation]
|
|
37
37
|
* @param {Number} [options.value]
|
|
38
|
-
* @returns {String}
|
|
38
|
+
* @returns {Promise<String>}
|
|
39
39
|
*/
|
|
40
40
|
private _imageSrc;
|
|
41
41
|
/**
|
|
42
42
|
* @private
|
|
43
43
|
* @param {String} operation
|
|
44
44
|
* @param {Number} value
|
|
45
|
-
* @returns {Keypoint}
|
|
45
|
+
* @returns {Promise<Keypoint>}
|
|
46
46
|
*/
|
|
47
47
|
private _constructKeypoint;
|
|
48
48
|
/**
|
|
@@ -79,7 +79,7 @@ export class EditorImageFader extends Block {
|
|
|
79
79
|
_cancelLastImages: any;
|
|
80
80
|
_container: HTMLDivElement | undefined;
|
|
81
81
|
/** @param {import('./types.js').Transformations} transformations */
|
|
82
|
-
setTransformations(transformations: import('./types.js').Transformations): void
|
|
82
|
+
setTransformations(transformations: import('./types.js').Transformations): Promise<void>;
|
|
83
83
|
_transformations: import("./types.js").Transformations | undefined;
|
|
84
84
|
/**
|
|
85
85
|
* @param {object} options
|
|
@@ -93,7 +93,7 @@ export class EditorImageFader extends Block {
|
|
|
93
93
|
operation: string;
|
|
94
94
|
value: number;
|
|
95
95
|
filter?: string | undefined;
|
|
96
|
-
}): void
|
|
96
|
+
}): Promise<void>;
|
|
97
97
|
_cancelBatchPreload: (() => void) | undefined;
|
|
98
98
|
/** @private */
|
|
99
99
|
private _setOriginalSrc;
|
|
@@ -111,7 +111,7 @@ export class EditorImageFader extends Block {
|
|
|
111
111
|
value?: number | undefined;
|
|
112
112
|
filter?: string | undefined;
|
|
113
113
|
fromViewer?: boolean | undefined;
|
|
114
|
-
}): void
|
|
114
|
+
}): Promise<void>;
|
|
115
115
|
_url: string | undefined;
|
|
116
116
|
_filter: string | undefined;
|
|
117
117
|
_fromViewer: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorImageFader.d.ts","sourceRoot":"","sources":["EditorImageFader.js"],"names":[],"mappings":"AA8DA;;;;;;;GAOG;AAEH;IAII;;;OAGG;IACH,kBAAsB;IAEtB;;;OAGG;IACH,gBAAmB;IAEnB,eAAe;IACf,8BAAwE;IAK1E;;;;OAIG;IACH,4BAmBC;IAED,eAAe;IACf,eAWC;IATC,yBAQE;IAGJ;;;;;;;;OAQG;IACH,kBAUC;IAED;;;;;OAKG;IACH,2BASC;IAED;;;;;;;OAOG;IACH,gBAEC;IAED;;;;;OAKG;IACH,qBA0CC;IAED,qCAAqC;IACrC,WADY,eAAe,QAK1B;IAED;;;;OAIG;IACH,gBAgBC;IAfC,+BAA2B;IAC3B,2BAAmB;IAgBrB,eAAe;IACf,4BAKC;IAED,eAAe;IACf,mBAmCC;IAjCC,mBAAqE;IAcrE,uBAGC;IAMC,uCAA2B;IAY/B,oEAAoE;IACpE,oCADY,OAAO,YAAY,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"EditorImageFader.d.ts","sourceRoot":"","sources":["EditorImageFader.js"],"names":[],"mappings":"AA8DA;;;;;;;GAOG;AAEH;IAII;;;OAGG;IACH,kBAAsB;IAEtB;;;OAGG;IACH,gBAAmB;IAEnB,eAAe;IACf,8BAAwE;IAK1E;;;;OAIG;IACH,4BAmBC;IAED,eAAe;IACf,eAWC;IATC,yBAQE;IAGJ;;;;;;;;OAQG;IACH,kBAUC;IAED;;;;;OAKG;IACH,2BASC;IAED;;;;;;;OAOG;IACH,gBAEC;IAED;;;;;OAKG;IACH,qBA0CC;IAED,qCAAqC;IACrC,WADY,eAAe,QAK1B;IAED;;;;OAIG;IACH,gBAgBC;IAfC,+BAA2B;IAC3B,2BAAmB;IAgBrB,eAAe;IACf,4BAKC;IAED,eAAe;IACf,mBAmCC;IAjCC,mBAAqE;IAcrE,uBAGC;IAMC,uCAA2B;IAY/B,oEAAoE;IACpE,oCADY,OAAO,YAAY,EAAE,eAAe,iBAmB/C;IAjBC,mEAAuC;IAmBzC;;;;;;OAMG;IACH;QAL2B,GAAG;QACH,SAAS;QACT,KAAK;QACJ,MAAM;sBAUjC;IADC,8CAAiC;IAGnC,eAAe;IACf,wBA4CC;IAED;;;;;;;OAOG;IACH;QAN2B,GAAG;QACF,SAAS;QACT,KAAK;QACL,MAAM;QACL,UAAU;sBAwBtC;IAnBC,yBAAe;IAGf,4BAAqB;IACrB,iCAA6B;IAS7B,mCAEC;IAMH,0CAA0C;IAC1C,sBADY;QAAE,IAAI,CAAC,UAAS;KAAE,QA4B7B;CACF;;;;;WApYa,gBAAgB;;;sBAlER,4BAA4B"}
|
|
@@ -138,9 +138,9 @@ export class EditorImageFader extends Block {
|
|
|
138
138
|
* @param {String} [options.filter]
|
|
139
139
|
* @param {String} [options.operation]
|
|
140
140
|
* @param {Number} [options.value]
|
|
141
|
-
* @returns {String}
|
|
141
|
+
* @returns {Promise<String>}
|
|
142
142
|
*/
|
|
143
|
-
_imageSrc({ url = this._url, filter = this._filter, operation, value } = {}) {
|
|
143
|
+
async _imageSrc({ url = this._url, filter = this._filter, operation, value } = {}) {
|
|
144
144
|
let transformations = { ...this._transformations };
|
|
145
145
|
|
|
146
146
|
if (operation) {
|
|
@@ -149,17 +149,17 @@ export class EditorImageFader extends Block {
|
|
|
149
149
|
|
|
150
150
|
// do not use getBoundingClientRect because scale transform affects it
|
|
151
151
|
let width = this.offsetWidth;
|
|
152
|
-
return this.proxyUrl(viewerImageSrc(url, width, transformations));
|
|
152
|
+
return await this.proxyUrl(viewerImageSrc(url, width, transformations));
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* @private
|
|
157
157
|
* @param {String} operation
|
|
158
158
|
* @param {Number} value
|
|
159
|
-
* @returns {Keypoint}
|
|
159
|
+
* @returns {Promise<Keypoint>}
|
|
160
160
|
*/
|
|
161
|
-
_constructKeypoint(operation, value) {
|
|
162
|
-
let src = this._imageSrc({ operation, value });
|
|
161
|
+
async _constructKeypoint(operation, value) {
|
|
162
|
+
let src = await this._imageSrc({ operation, value });
|
|
163
163
|
return {
|
|
164
164
|
src,
|
|
165
165
|
image: null,
|
|
@@ -187,14 +187,14 @@ export class EditorImageFader extends Block {
|
|
|
187
187
|
* @param {String | null} filter
|
|
188
188
|
* @param {Number} value
|
|
189
189
|
*/
|
|
190
|
-
_addKeypoint(operation, filter, value) {
|
|
190
|
+
async _addKeypoint(operation, filter, value) {
|
|
191
191
|
let shouldSkip = () =>
|
|
192
192
|
!this._isSame(operation, filter) || this._value !== value || !!this._keypoints.find((kp) => kp.value === value);
|
|
193
193
|
|
|
194
194
|
if (shouldSkip()) {
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
|
-
let keypoint = this._constructKeypoint(operation, value);
|
|
197
|
+
let keypoint = await this._constructKeypoint(operation, value);
|
|
198
198
|
let image = new Image();
|
|
199
199
|
image.src = keypoint.src;
|
|
200
200
|
let stop = this._handleImageLoading(keypoint.src);
|
|
@@ -308,10 +308,10 @@ export class EditorImageFader extends Block {
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
/** @param {import('./types.js').Transformations} transformations */
|
|
311
|
-
setTransformations(transformations) {
|
|
311
|
+
async setTransformations(transformations) {
|
|
312
312
|
this._transformations = transformations;
|
|
313
313
|
if (this._previewImage) {
|
|
314
|
-
let src = this._imageSrc();
|
|
314
|
+
let src = await this._imageSrc();
|
|
315
315
|
let stop = this._handleImageLoading(src);
|
|
316
316
|
this._previewImage.src = src;
|
|
317
317
|
this._previewImage.addEventListener('load', stop, { once: true });
|
|
@@ -335,11 +335,11 @@ export class EditorImageFader extends Block {
|
|
|
335
335
|
* @param {Number} options.value
|
|
336
336
|
* @param {String} [options.filter]
|
|
337
337
|
*/
|
|
338
|
-
preload({ url, filter, operation, value }) {
|
|
338
|
+
async preload({ url, filter, operation, value }) {
|
|
339
339
|
this._cancelBatchPreload && this._cancelBatchPreload();
|
|
340
340
|
|
|
341
341
|
let keypoints = keypointsRange(operation, value);
|
|
342
|
-
let srcList = keypoints.map((kp) => this._imageSrc({ url, filter, operation, value: kp }));
|
|
342
|
+
let srcList = await Promise.all(keypoints.map((kp) => this._imageSrc({ url, filter, operation, value: kp })));
|
|
343
343
|
let { cancel } = batchPreloadImages(srcList);
|
|
344
344
|
|
|
345
345
|
this._cancelBatchPreload = cancel;
|
|
@@ -400,7 +400,7 @@ export class EditorImageFader extends Block {
|
|
|
400
400
|
* @param {String} [options.filter]
|
|
401
401
|
* @param {Boolean} [options.fromViewer]
|
|
402
402
|
*/
|
|
403
|
-
activate({ url, operation, value, filter, fromViewer }) {
|
|
403
|
+
async activate({ url, operation, value, filter, fromViewer }) {
|
|
404
404
|
this._isActive = true;
|
|
405
405
|
this._hidden = false;
|
|
406
406
|
this._url = url;
|
|
@@ -411,12 +411,14 @@ export class EditorImageFader extends Block {
|
|
|
411
411
|
|
|
412
412
|
let isOriginal = typeof value !== 'number' && !filter;
|
|
413
413
|
if (isOriginal) {
|
|
414
|
-
let src = this._imageSrc({ operation, value });
|
|
414
|
+
let src = await this._imageSrc({ operation, value });
|
|
415
415
|
this._setOriginalSrc(src);
|
|
416
416
|
this._container && this._container.remove();
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
|
-
this._keypoints =
|
|
419
|
+
this._keypoints = await Promise.all(
|
|
420
|
+
keypointsRange(operation, value).map((keyValue) => this._constructKeypoint(operation, keyValue)),
|
|
421
|
+
);
|
|
420
422
|
|
|
421
423
|
this._update(operation, value);
|
|
422
424
|
this._initNodes();
|
|
@@ -105,7 +105,7 @@ export class EditorToolbar extends Block {
|
|
|
105
105
|
visible: 'uc-tab-toggles--visible',
|
|
106
106
|
},
|
|
107
107
|
'on.cancel': () => {
|
|
108
|
-
this._cancelPreload
|
|
108
|
+
this._cancelPreload?.();
|
|
109
109
|
this.$['*on.cancel']();
|
|
110
110
|
},
|
|
111
111
|
'on.apply': () => {
|
|
@@ -271,11 +271,11 @@ export class EditorToolbar extends Block {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
/** @private */
|
|
274
|
-
_preloadEditedImage() {
|
|
274
|
+
async _preloadEditedImage() {
|
|
275
275
|
if (this.$['*imgContainerEl'] && this.$['*originalUrl']) {
|
|
276
276
|
let width = this.$['*imgContainerEl'].offsetWidth;
|
|
277
|
-
let src = this.proxyUrl(viewerImageSrc(this.$['*originalUrl'], width, this.$['*editorTransformations']));
|
|
278
|
-
this._cancelPreload
|
|
277
|
+
let src = await this.proxyUrl(viewerImageSrc(this.$['*originalUrl'], width, this.$['*editorTransformations']));
|
|
278
|
+
this._cancelPreload?.();
|
|
279
279
|
let { cancel } = batchPreloadImages([src]);
|
|
280
280
|
this._cancelPreload = () => {
|
|
281
281
|
cancel();
|
|
@@ -132,7 +132,7 @@ export class FileItem extends UploaderBlock {
|
|
|
132
132
|
|
|
133
133
|
if (entry.getValue('fileInfo') && entry.getValue('isImage')) {
|
|
134
134
|
let size = this.cfg.thumbSize;
|
|
135
|
-
let thumbUrl = this.proxyUrl(
|
|
135
|
+
let thumbUrl = await this.proxyUrl(
|
|
136
136
|
createCdnUrl(
|
|
137
137
|
createOriginalUrl(this.cfg.cdnCname, this._entry.getValue('uuid')),
|
|
138
138
|
createCdnUrlModifiers(entry.getValue('cdnUrlModifiers'), `scale_crop/${size}x${size}/center`),
|