@exmg/exm-upload 1.0.2 → 1.0.4
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 -2
- package/src/exm-upload-base.d.ts +1 -1
- package/src/exm-upload-item-base.d.ts +1 -1
- package/src/exm-upload-item-base.js +1 -3
- package/src/styles/exm-dialog-upload-css.js +1 -1
- package/src/upload/adapters/form-data-adapter.d.ts +7 -0
- package/src/upload/adapters/form-data-adapter.js +46 -0
- package/src/upload/service.d.ts +1 -1
- package/src/upload/service.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exmg/exm-upload",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@exmg/exm-button": "^1.0.1",
|
|
6
6
|
"@exmg/exm-collapsed": "^1.0.1",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "c1af4ad8444da5406a6bb82f58ba4a67e09b948d"
|
|
53
53
|
}
|
package/src/exm-upload-base.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare class ExmUploadBase extends ExmgElement {
|
|
|
51
51
|
/**
|
|
52
52
|
* The upload response type
|
|
53
53
|
*/
|
|
54
|
-
serverType: 'xhr' | '
|
|
54
|
+
serverType: 'xhr' | 'local' | 'form-data' | 'custom';
|
|
55
55
|
/**
|
|
56
56
|
* The CropperJS config see: https://github.com/fengyuanchen/cropperjs#options
|
|
57
57
|
*/
|
|
@@ -26,9 +26,7 @@ export class ExmUploadItemBase extends ExmgElement {
|
|
|
26
26
|
headers,
|
|
27
27
|
responseType: this.responseType,
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
payload.customAdapterPath = this.customAdapterPath || window.uploadDefaults.customAdapterPath;
|
|
31
|
-
}
|
|
29
|
+
payload.customAdapterPath = this.customAdapterPath || window.uploadDefaults.customAdapterPath;
|
|
32
30
|
this.uploadService = await UploadService.create(this.serverType, payload);
|
|
33
31
|
this.handleFileUpload();
|
|
34
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { css } from 'lit';
|
|
2
|
-
export const style = css `:host{border-start-start-radius:var(--md-dialog-container-shape-start-start, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));border-start-end-radius:var(--md-dialog-container-shape-start-end, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));border-end-end-radius:var(--md-dialog-container-shape-end-end, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));border-end-start-radius:var(--md-dialog-container-shape-end-start, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));display:contents;margin:auto;max-height:min(560px,100% - 48px);max-width:min(560px,100% - 48px);min-height:140px;min-width:280px;position:fixed;height:fit-content;width:fit-content}dialog{background:rgba(0,0,0,0);border:none;border-radius:inherit;flex-direction:column;height:inherit;margin:inherit;max-height:inherit;max-width:inherit;min-height:inherit;min-width:inherit;outline:none;overflow:visible;padding:0;width:inherit}dialog[open]{display:flex}::backdrop{background:none}.scrim{background:var(--md-sys-color-scrim, #000);display:none;inset:0;opacity:32%;pointer-events:none;position:fixed;z-index:1}:host([open]) .scrim{display:flex}h2{all:unset;align-self:stretch}.headline{align-items:center;color:var(--md-dialog-headline-color, var(--md-sys-color-on-surface, #1d1b20));display:flex;flex-direction:column;font-family:var(--md-dialog-headline-font, var(--md-sys-typescale-headline-small-font, var(--md-ref-typeface-brand, Roboto)));font-size:var(--md-dialog-headline-size, var(--md-sys-typescale-headline-small-size, 1.5rem));line-height:var(--md-dialog-headline-line-height, var(--md-sys-typescale-headline-small-line-height, 2rem));font-weight:var(--md-dialog-headline-weight, var(--md-sys-typescale-headline-small-weight, var(--md-ref-typeface-weight-regular, 400)));position:relative}slot[name=headline]::slotted(*){align-items:center;align-self:stretch;box-sizing:border-box;display:flex;gap:8px;padding:24px 24px 0}.icon{display:flex}slot[name=icon]::slotted(*){color:var(--md-dialog-icon-color, var(--md-sys-color-secondary, #625b71));fill:currentColor;font-size:var(--md-dialog-icon-size, 24px);margin-top:24px;height:var(--md-dialog-icon-size, 24px);width:var(--md-dialog-icon-size, 24px)}.has-icon slot[name=headline]::slotted(*){justify-content:center;padding-top:16px}.scrollable slot[name=headline]::slotted(*){padding-bottom:16px}.scrollable.has-headline slot[name=content]::slotted(*){padding-top:8px}.container{border-radius:inherit;display:flex;flex-direction:column;flex-grow:1;overflow:hidden;position:relative;transform-origin:top}.container::before{background:var(--md-dialog-container-color, var(--md-sys-color-surface-container-high, #ece6f0));border-radius:inherit;content:"";inset:0;position:absolute}.scroller{display:flex;flex:1;flex-direction:column;overflow:hidden;z-index:1}.scrollable .scroller{overflow-y:scroll}.content{color:var(--md-dialog-supporting-text-color, var(--md-sys-color-on-surface-variant, #49454f));font-family:var(--md-dialog-supporting-text-font, var(--md-sys-typescale-body-medium-font, var(--md-ref-typeface-plain, Roboto)));font-size:var(--md-dialog-supporting-text-size, var(--md-sys-typescale-body-medium-size, 0.875rem));line-height:var(--md-dialog-supporting-text-line-height, var(--md-sys-typescale-body-medium-line-height, 1.25rem));font-weight:var(--md-dialog-supporting-text-weight, var(--md-sys-typescale-body-medium-weight, var(--md-ref-typeface-weight-regular, 400)));height:min-content;position:relative}slot[name=content]::slotted(*){box-sizing:border-box;padding:24px}.anchor{position:absolute}.top.anchor{top:0}.bottom.anchor{bottom:0}.actions{position:relative}slot[name=actions]::slotted(*){box-sizing:border-box;display:flex;gap:8px;justify-content:flex-end;padding:16px 24px 24px}.has-actions slot[name=content]::slotted(*){padding-bottom:8px}md-divider{display:none;position:absolute}.has-headline.show-top-divider .headline md-divider,.has-actions.show-bottom-divider .actions md-divider{display:flex}.headline md-divider{bottom:0}.actions md-divider{top:0}@media(forced-colors: active){dialog{outline:2px solid WindowText}}[slot=headline]{display:flex;flex-direction:row-reverse;align-items:center}[showing-fullscreen] [slot=headline]{flex-direction:row}.headline{flex:1;display:block;text-align:left}exm-upload,::slotted(exm-upload){width:460px}`;
|
|
2
|
+
export const style = css `:host{border-start-start-radius:var(--md-dialog-container-shape-start-start, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));border-start-end-radius:var(--md-dialog-container-shape-start-end, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));border-end-end-radius:var(--md-dialog-container-shape-end-end, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));border-end-start-radius:var(--md-dialog-container-shape-end-start, var(--md-dialog-container-shape, var(--md-sys-shape-corner-extra-large, 28px)));display:contents;margin:auto;max-height:min(560px,100% - 48px);max-width:min(560px,100% - 48px);min-height:140px;min-width:280px;position:fixed;height:fit-content;width:fit-content}dialog{background:rgba(0,0,0,0);border:none;border-radius:inherit;flex-direction:column;height:inherit;margin:inherit;max-height:inherit;max-width:inherit;min-height:inherit;min-width:inherit;outline:none;overflow:visible;padding:0;width:inherit}dialog[open]{display:flex}::backdrop{background:none}.scrim{background:var(--md-sys-color-scrim, #000);display:none;inset:0;opacity:32%;pointer-events:none;position:fixed;z-index:1}:host([open]) .scrim{display:flex}h2{all:unset;align-self:stretch}.headline{align-items:center;color:var(--md-dialog-headline-color, var(--md-sys-color-on-surface, #1d1b20));display:flex;flex-direction:column;font-family:var(--md-dialog-headline-font, var(--md-sys-typescale-headline-small-font, var(--md-ref-typeface-brand, Roboto)));font-size:var(--md-dialog-headline-size, var(--md-sys-typescale-headline-small-size, 1.5rem));line-height:var(--md-dialog-headline-line-height, var(--md-sys-typescale-headline-small-line-height, 2rem));font-weight:var(--md-dialog-headline-weight, var(--md-sys-typescale-headline-small-weight, var(--md-ref-typeface-weight-regular, 400)));position:relative}slot[name=headline]::slotted(*){align-items:center;align-self:stretch;box-sizing:border-box;display:flex;gap:8px;padding:24px 24px 0}.icon{display:flex}slot[name=icon]::slotted(*){color:var(--md-dialog-icon-color, var(--md-sys-color-secondary, #625b71));fill:currentColor;font-size:var(--md-dialog-icon-size, 24px);margin-top:24px;height:var(--md-dialog-icon-size, 24px);width:var(--md-dialog-icon-size, 24px)}.has-icon slot[name=headline]::slotted(*){justify-content:center;padding-top:16px}.scrollable slot[name=headline]::slotted(*){padding-bottom:16px}.scrollable.has-headline slot[name=content]::slotted(*){padding-top:8px}.container{border-radius:inherit;display:flex;flex-direction:column;flex-grow:1;overflow:hidden;position:relative;transform-origin:top}.container::before{background:var(--md-dialog-container-color, var(--md-sys-color-surface-container-high, #ece6f0));border-radius:inherit;content:"";inset:0;position:absolute}.scroller{display:flex;flex:1;flex-direction:column;overflow:hidden;z-index:1}.scrollable .scroller{overflow-y:scroll}.content{color:var(--md-dialog-supporting-text-color, var(--md-sys-color-on-surface-variant, #49454f));font-family:var(--md-dialog-supporting-text-font, var(--md-sys-typescale-body-medium-font, var(--md-ref-typeface-plain, Roboto)));font-size:var(--md-dialog-supporting-text-size, var(--md-sys-typescale-body-medium-size, 0.875rem));line-height:var(--md-dialog-supporting-text-line-height, var(--md-sys-typescale-body-medium-line-height, 1.25rem));flex:1;font-weight:var(--md-dialog-supporting-text-weight, var(--md-sys-typescale-body-medium-weight, var(--md-ref-typeface-weight-regular, 400)));height:min-content;position:relative}slot[name=content]::slotted(*){box-sizing:border-box;padding:24px}.anchor{position:absolute}.top.anchor{top:0}.bottom.anchor{bottom:0}.actions{position:relative}slot[name=actions]::slotted(*){box-sizing:border-box;display:flex;gap:8px;justify-content:flex-end;padding:16px 24px 24px}.has-actions slot[name=content]::slotted(*){padding-bottom:8px}md-divider{display:none;position:absolute}.has-headline.show-top-divider .headline md-divider,.has-actions.show-bottom-divider .actions md-divider{display:flex}.headline md-divider{bottom:0}.actions md-divider{top:0}@media(forced-colors: active){dialog{outline:2px solid WindowText}}[slot=headline]{display:flex;flex-direction:row-reverse;align-items:center}[showing-fullscreen] [slot=headline]{flex-direction:row}.headline{flex:1;display:block;text-align:left}exm-upload,::slotted(exm-upload){width:460px}`;
|
|
3
3
|
export default style;
|
|
4
4
|
//# sourceMappingURL=exm-dialog-upload-css.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UploadAdapter, UploadConfig } from '../types.js';
|
|
2
|
+
declare class XHRJSONUploadAdapter implements UploadAdapter {
|
|
3
|
+
config: UploadConfig;
|
|
4
|
+
constructor(config: UploadConfig);
|
|
5
|
+
upload(file: File, progressCallback: (progress: number) => void): Promise<string>;
|
|
6
|
+
}
|
|
7
|
+
export { XHRJSONUploadAdapter as UploadAdapter };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class XHRJSONUploadAdapter {
|
|
2
|
+
constructor(config) {
|
|
3
|
+
this.config = config;
|
|
4
|
+
}
|
|
5
|
+
async upload(file, progressCallback) {
|
|
6
|
+
const onProgress = (event) => {
|
|
7
|
+
if (event.lengthComputable) {
|
|
8
|
+
const percentage = (event.loaded / event.total) * 100;
|
|
9
|
+
progressCallback(Math.round(percentage));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const xhr = new XMLHttpRequest();
|
|
13
|
+
xhr.upload.addEventListener('progress', onProgress);
|
|
14
|
+
const formData = new FormData();
|
|
15
|
+
formData.set('file', file);
|
|
16
|
+
formData.set('filename', file.name);
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const { uploadUrl } = this.config;
|
|
19
|
+
if (!uploadUrl)
|
|
20
|
+
reject(new Error(`Upload url not found`));
|
|
21
|
+
xhr.responseType = 'json';
|
|
22
|
+
xhr.open('POST', uploadUrl, true);
|
|
23
|
+
for (const key in this.config.headers || {}) {
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(this.config.headers, key)) {
|
|
25
|
+
xhr.setRequestHeader(key, this.config.headers[key]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
xhr.onreadystatechange = () => {
|
|
29
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
30
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
31
|
+
resolve(xhr.response);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
reject(new Error(`Upload failed with status ${xhr.status}`));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
xhr.onerror = () => {
|
|
39
|
+
reject(new Error('Upload failed due to network error'));
|
|
40
|
+
};
|
|
41
|
+
xhr.send(formData);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export { XHRJSONUploadAdapter as UploadAdapter };
|
|
46
|
+
//# sourceMappingURL=form-data-adapter.js.map
|
package/src/upload/service.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ declare class UploadService {
|
|
|
4
4
|
constructor(adapter: UploadAdapter);
|
|
5
5
|
upload(file: File, progressCallback: (progress: number) => void): Promise<string>;
|
|
6
6
|
abort(): void;
|
|
7
|
-
static create(destination: 'xhr' | 'local' | 'custom', config?: UploadConfig): Promise<UploadService>;
|
|
7
|
+
static create(destination: 'xhr' | 'local' | 'form-data' | 'custom', config?: UploadConfig): Promise<UploadService>;
|
|
8
8
|
}
|
|
9
9
|
export { UploadService };
|
package/src/upload/service.js
CHANGED
|
@@ -29,6 +29,9 @@ class UploadService {
|
|
|
29
29
|
case 'xhr':
|
|
30
30
|
adapter = await instantiateClass('./adapters/xhr-adapter.js', config);
|
|
31
31
|
break;
|
|
32
|
+
case 'form-data':
|
|
33
|
+
adapter = await instantiateClass('./adapters/form-data-adapter.js', config);
|
|
34
|
+
break;
|
|
32
35
|
case 'custom':
|
|
33
36
|
adapter = await instantiateClass(config === null || config === void 0 ? void 0 : config.customAdapterPath, config);
|
|
34
37
|
break;
|