@exmg/exm-upload 1.0.4 → 1.0.5

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,12 +1,12 @@
1
1
  {
2
2
  "name": "@exmg/exm-upload",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "dependencies": {
5
- "@exmg/exm-button": "^1.0.1",
5
+ "@exmg/exm-button": "^1.0.2",
6
6
  "@exmg/exm-collapsed": "^1.0.1",
7
- "@exmg/exm-dialogs": "^1.0.2",
7
+ "@exmg/exm-dialogs": "^1.0.3",
8
8
  "@exmg/lit-base": "^2.0.1",
9
- "@material/web": "^1.3.0",
9
+ "@material/web": "^2.2.0",
10
10
  "cropperjs": "^1.5.13",
11
11
  "lit": "^3.0.0",
12
12
  "tslib": "^2.6.2"
@@ -49,5 +49,5 @@
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "gitHead": "c1af4ad8444da5406a6bb82f58ba4a67e09b948d"
52
+ "gitHead": "274f2fb879258487017192fcfe33c8cd23244dbb"
53
53
  }
@@ -51,7 +51,7 @@ export declare class ExmUploadBase extends ExmgElement {
51
51
  /**
52
52
  * The upload response type
53
53
  */
54
- serverType: 'xhr' | 'local' | 'form-data' | 'custom';
54
+ serverType: 'xhr' | 'custom' | 'local';
55
55
  /**
56
56
  * The CropperJS config see: https://github.com/fengyuanchen/cropperjs#options
57
57
  */
@@ -13,7 +13,7 @@ export declare class ExmUploadItemBase extends ExmgElement {
13
13
  /**
14
14
  * The upload response type
15
15
  */
16
- serverType: 'xhr' | 'local' | 'form-data' | 'custom';
16
+ serverType: 'xhr' | 'local' | 'custom';
17
17
  /**
18
18
  * The upload response type
19
19
  */
@@ -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' | 'form-data' | 'custom', config?: UploadConfig): Promise<UploadService>;
7
+ static create(destination: 'xhr' | 'local' | 'custom', config?: UploadConfig): Promise<UploadService>;
8
8
  }
9
9
  export { UploadService };
@@ -29,9 +29,6 @@ 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;
35
32
  case 'custom':
36
33
  adapter = await instantiateClass(config === null || config === void 0 ? void 0 : config.customAdapterPath, config);
37
34
  break;
@@ -1,7 +0,0 @@
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 };
@@ -1,46 +0,0 @@
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