@wawjs/ngx-bos 22.0.5 → 22.0.7

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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/RELEASES.md +38 -0
  3. package/ai/code-style.md +15 -0
  4. package/fesm2022/file.service-C8Erkqrm.mjs +48 -0
  5. package/fesm2022/file.service-C8Erkqrm.mjs.map +1 -0
  6. package/fesm2022/{wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs → ngx-bos.config-DjtgUjR8.mjs} +3 -5
  7. package/fesm2022/ngx-bos.config-DjtgUjR8.mjs.map +1 -0
  8. package/fesm2022/user-crud.component-B1_SlIDS.mjs +317 -0
  9. package/fesm2022/user-crud.component-B1_SlIDS.mjs.map +1 -0
  10. package/fesm2022/wawjs-ngx-bos.mjs +206 -187
  11. package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
  12. package/package.json +11 -9
  13. package/src/feature/file/file.component.html +1 -0
  14. package/src/feature/file/file.component.ts +265 -239
  15. package/src/feature/file/file.service.ts +36 -36
  16. package/src/feature/file/file.util.ts +9 -2
  17. package/src/feature/file/pages/files/files.component.html +12 -12
  18. package/src/feature/file/pages/files/files.component.ts +116 -116
  19. package/src/feature/user/guards/admins.guard.ts +21 -21
  20. package/src/feature/user/guards/authenticated.guard.ts +15 -15
  21. package/src/feature/user/guards/guest.guard.ts +15 -15
  22. package/src/feature/user/pages/clients/clients.component.ts +19 -45
  23. package/src/feature/user/pages/user-crud.component.ts +119 -0
  24. package/src/feature/user/pages/users/users.component.ts +33 -86
  25. package/src/feature/user/user.service.ts +120 -21
  26. package/src/feature/user/user.storage.ts +31 -31
  27. package/src/form-components/ace/ace.component.ts +15 -1
  28. package/src/form-components/file/file.component.html +2 -2
  29. package/src/form-components/form-config-cache.ts +70 -0
  30. package/src/form-components/input/input.form.ts +1 -1
  31. package/src/form-components/select/select.component.html +24 -24
  32. package/src/form-components/tinymce/tinymce.component.ts +12 -0
  33. package/src/icons/spider/spider.component.ts +4 -4
  34. package/src/ngx-bos.config.ts +7 -5
  35. package/src/pages/form/form.component.ts +137 -100
  36. package/src/pages/forms/forms.component.ts +14 -2
  37. package/src/public-api.ts +1 -1
  38. package/types/wawjs-ngx-bos.d.ts +52 -15
  39. package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +0 -1
  40. package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs +0 -181
  41. package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,4 @@
1
1
  {
2
- "name": "@wawjs/ngx-bos",
3
- "version": "22.0.5",
4
2
  "license": "MIT",
5
3
  "peerDependencies": {
6
4
  "@angular/common": "^22.0.0",
@@ -23,16 +21,20 @@
23
21
  "tslib": "2.8.1"
24
22
  },
25
23
  "sideEffects": false,
26
- "module": "fesm2022/wawjs-ngx-bos.mjs",
27
- "typings": "types/wawjs-ngx-bos.d.ts",
24
+ "name": "@wawjs/ngx-bos",
25
+ "type": "module",
26
+ "main": "./fesm2022/wawjs-ngx-bos.mjs",
27
+ "module": "./fesm2022/wawjs-ngx-bos.mjs",
28
+ "typings": "./types/wawjs-ngx-bos.d.ts",
29
+ "types": "./types/wawjs-ngx-bos.d.ts",
28
30
  "exports": {
29
- "./package.json": {
30
- "default": "./package.json"
31
- },
32
31
  ".": {
33
32
  "types": "./types/wawjs-ngx-bos.d.ts",
34
33
  "default": "./fesm2022/wawjs-ngx-bos.mjs"
34
+ },
35
+ "./package.json": {
36
+ "default": "./package.json"
35
37
  }
36
38
  },
37
- "type": "module"
38
- }
39
+ "version": "22.0.7"
40
+ }
@@ -47,6 +47,7 @@ _disabled = disabled(); @let _view = view();
47
47
  type="button"
48
48
  class="wfile__remove material-icons"
49
49
  (click)="clear(); $event.stopPropagation()"
50
+ (keydown)="$event.stopPropagation()"
50
51
  aria-label="Clear file"
51
52
  >
52
53
  close
@@ -1,239 +1,265 @@
1
- import { NgTemplateOutlet } from '@angular/common';
2
- import {
3
- Component,
4
- TemplateRef,
5
- computed,
6
- inject,
7
- input,
8
- model,
9
- } from '@angular/core';
10
- import { ButtonComponent, ModalService } from '@wawjs/ngx-ui';
11
- import { fileToDataUrl } from './file.util';
12
- import { TranslateDirective } from '@wawjs/ngx-translate';
13
- import type { FabricCropResult } from '@wawjs/ngx-fabric';
14
- import { fileDefaults } from './file.const';
15
- import { FileService } from './file.service';
16
-
17
- export type FileMode =
18
- | 'single-image'
19
- | 'single-file'
20
- | 'multi-image'
21
- | 'multi-file';
22
-
23
- export type FileView = 'dropzone' | 'list' | 'thumb-only';
24
-
25
- @Component({
26
- selector: 'ngx-file',
27
- imports: [NgTemplateOutlet, TranslateDirective, ButtonComponent],
28
- templateUrl: './file.component.html',
29
- styleUrl: './file.component.scss',
30
- })
31
- export class FileComponent {
32
- /** UI props */
33
- readonly label = input<string>(fileDefaults.label);
34
- readonly placeholder = input<string>(fileDefaults.placeholder);
35
- readonly disabled = input<boolean>(fileDefaults.disabled);
36
- readonly clearable = input<boolean>(fileDefaults.clearable);
37
- readonly accept = input<string>(fileDefaults.accept);
38
- readonly preview = input<boolean>(fileDefaults.preview);
39
-
40
- /** Behaviour */
41
- readonly mode = input<FileMode>(fileDefaults.mode as FileMode);
42
- readonly view = input<FileView>(fileDefaults.view as FileView);
43
-
44
- /** Optional crop box (for image modes) */
45
- readonly cropWidth = input<number | null>(fileDefaults.cropWidth);
46
- readonly cropHeight = input<number | null>(fileDefaults.cropHeight);
47
-
48
- /** Custom templates */
49
- readonly t_item = input<TemplateRef<unknown>>();
50
- readonly t_empty = input<TemplateRef<unknown>>();
51
-
52
- /** Back-end routing */
53
- readonly container = input<string>(fileDefaults.container);
54
- readonly name = input<string>(fileDefaults.name);
55
-
56
- /** Separate models for each mode */
57
- readonly wImage = model<string | null>(null, { alias: 'wImage' });
58
- readonly wFile = model<string | null>(null, { alias: 'wFile' });
59
- readonly wImages = model<string[]>([], { alias: 'wImages' });
60
- readonly wFiles = model<string[]>([], { alias: 'wFiles' });
61
-
62
- private readonly _modal = inject(ModalService);
63
- private readonly _fs = inject(FileService);
64
-
65
- readonly isMultiple = computed(() => this.mode().startsWith('multi-'));
66
- readonly isImageMode = computed(() => this.mode().includes('image'));
67
-
68
- /** Normalized list of URLs for rendering */
69
- readonly files = computed<string[]>(() => {
70
- const mode = this.mode();
71
- switch (mode) {
72
- case 'single-image':
73
- return this.wImage() ? [this.wImage() as string] : [];
74
- case 'single-file':
75
- return this.wFile() ? [this.wFile() as string] : [];
76
- case 'multi-image':
77
- return this.wImages();
78
- case 'multi-file':
79
- return this.wFiles();
80
- default:
81
- return [];
82
- }
83
- });
84
-
85
- triggerPick(input: HTMLInputElement): void {
86
- if (!this.disabled()) {
87
- input.click();
88
- }
89
- }
90
-
91
- isImage(src: string): boolean {
92
- return /\.(png|jpe?g|webp|gif)(\?|$)/i.test(src ?? '');
93
- }
94
-
95
- async onPicked(input: HTMLInputElement): Promise<void> {
96
- const list = input.files;
97
- if (!list || !list.length) return;
98
-
99
- const doCrop =
100
- this.isImageMode() && !!this.cropWidth() && !!this.cropHeight();
101
- const urls: string[] = [];
102
- const container = this.container();
103
- const name = this.name();
104
-
105
- try {
106
- for (let i = 0; i < list.length; i++) {
107
- const f = list.item(i)!;
108
-
109
- // Always read file as data URL
110
- const dataUrl = await fileToDataUrl(f);
111
-
112
- if (doCrop) {
113
- const cropWidth = this.cropWidth()!;
114
- const cropHeight = this.cropHeight()!;
115
-
116
- // Lazy-load fabric crop modal only when actually cropping
117
- const { FabricCropModalComponent } = await import(
118
- '@wawjs/ngx-fabric'
119
- );
120
- await new Promise<void>((resolve, reject) => {
121
- this._modal.show({
122
- component: FabricCropModalComponent,
123
- size: 'big',
124
- image: dataUrl,
125
- width: this._cropStageWidth(cropWidth),
126
- height: this._cropStageHeight(cropHeight),
127
- aspectRatio: cropWidth / cropHeight,
128
- outputWidth: cropWidth,
129
- outputHeight: cropHeight,
130
- onCrop: (result: FabricCropResult) => {
131
- this._fs
132
- .uploadBase64(result.base64, container, name)
133
- .then((url) => {
134
- if (url) {
135
- urls.push(url);
136
- }
137
-
138
- resolve();
139
- }, reject);
140
- },
141
- onCancel: () => resolve(),
142
- });
143
- });
144
- } else {
145
- const url = await this._fs.uploadBase64(
146
- dataUrl,
147
- container,
148
- name,
149
- );
150
-
151
- if (url) {
152
- urls.push(url);
153
- }
154
- }
155
-
156
- // If single mode, ignore extra files after first
157
- if (!this.isMultiple()) {
158
- break;
159
- }
160
- }
161
- } finally {
162
- // Keep uploads that succeeded before a failure and always reset the input.
163
- this._applyNewUrls(urls);
164
- input.value = '';
165
- }
166
- }
167
-
168
- removeAt(index: number): void {
169
- const mode = this.mode();
170
-
171
- if (mode === 'single-image') {
172
- this.wImage.set(null);
173
- return;
174
- }
175
-
176
- if (mode === 'single-file') {
177
- this.wFile.set(null);
178
- return;
179
- }
180
-
181
- // Multi modes
182
- const current = [...this.files()];
183
- current.splice(index, 1);
184
-
185
- if (mode === 'multi-image') {
186
- this.wImages.set(current);
187
- } else if (mode === 'multi-file') {
188
- this.wFiles.set(current);
189
- }
190
- }
191
-
192
- clear(): void {
193
- const mode = this.mode();
194
- if (mode === 'single-image') {
195
- this.wImage.set(null);
196
- } else if (mode === 'single-file') {
197
- this.wFile.set(null);
198
- } else if (mode === 'multi-image') {
199
- this.wImages.set([]);
200
- } else if (mode === 'multi-file') {
201
- this.wFiles.set([]);
202
- }
203
- }
204
-
205
- private _cropStageWidth(width: number): number {
206
- return Math.min(820, Math.max(width, Math.round(width * 1.45)));
207
- }
208
-
209
- private _cropStageHeight(height: number): number {
210
- return Math.min(620, Math.max(height, Math.round(height * 1.12)));
211
- }
212
-
213
- private _applyNewUrls(urls: string[]): void {
214
- const mode = this.mode();
215
-
216
- if (!urls.length) {
217
- return;
218
- }
219
-
220
- if (mode === 'single-image') {
221
- this.wImage.set(urls[0] ?? null);
222
- return;
223
- }
224
-
225
- if (mode === 'single-file') {
226
- this.wFile.set(urls[0] ?? null);
227
- return;
228
- }
229
-
230
- if (mode === 'multi-image') {
231
- this.wImages.set([...this.wImages(), ...urls]);
232
- return;
233
- }
234
-
235
- if (mode === 'multi-file') {
236
- this.wFiles.set([...this.wFiles(), ...urls]);
237
- }
238
- }
239
- }
1
+ import { NgTemplateOutlet } from '@angular/common';
2
+ import {
3
+ Component,
4
+ TemplateRef,
5
+ computed,
6
+ inject,
7
+ input,
8
+ model,
9
+ } from '@angular/core';
10
+ import { AlertService, ButtonComponent, ModalService } from '@wawjs/ngx-ui';
11
+ import { fileToDataUrl } from './file.util';
12
+ import { TranslateDirective } from '@wawjs/ngx-translate';
13
+ import type { FabricCropResult } from '@wawjs/ngx-fabric';
14
+ import { fileDefaults } from './file.const';
15
+ import { FileService } from './file.service';
16
+
17
+ export type FileMode =
18
+ | 'single-image'
19
+ | 'single-file'
20
+ | 'multi-image'
21
+ | 'multi-file';
22
+
23
+ export type FileView = 'dropzone' | 'list' | 'thumb-only';
24
+
25
+ @Component({
26
+ selector: 'ngx-file',
27
+ imports: [NgTemplateOutlet, TranslateDirective, ButtonComponent],
28
+ templateUrl: './file.component.html',
29
+ styleUrl: './file.component.scss',
30
+ })
31
+ export class FileComponent {
32
+ /** UI props */
33
+ readonly label = input<string>(fileDefaults.label);
34
+ readonly placeholder = input<string>(fileDefaults.placeholder);
35
+ readonly disabled = input<boolean>(fileDefaults.disabled);
36
+ readonly clearable = input<boolean>(fileDefaults.clearable);
37
+ readonly accept = input<string>(fileDefaults.accept);
38
+ readonly preview = input<boolean>(fileDefaults.preview);
39
+
40
+ /** Behaviour */
41
+ readonly mode = input<FileMode>(fileDefaults.mode as FileMode);
42
+ readonly view = input<FileView>(fileDefaults.view as FileView);
43
+
44
+ /** Optional crop box (for image modes) */
45
+ readonly cropWidth = input<number | null>(fileDefaults.cropWidth);
46
+ readonly cropHeight = input<number | null>(fileDefaults.cropHeight);
47
+
48
+ /** Custom templates */
49
+ readonly t_item = input<TemplateRef<unknown>>();
50
+ readonly t_empty = input<TemplateRef<unknown>>();
51
+
52
+ /** Back-end routing */
53
+ readonly container = input<string>(fileDefaults.container);
54
+ readonly name = input<string>(fileDefaults.name);
55
+
56
+ /** Separate models for each mode */
57
+ readonly wImage = model<string | null>(null, { alias: 'wImage' });
58
+ readonly wFile = model<string | null>(null, { alias: 'wFile' });
59
+ readonly wImages = model<string[]>([], { alias: 'wImages' });
60
+ readonly wFiles = model<string[]>([], { alias: 'wFiles' });
61
+
62
+ private readonly _modal = inject(ModalService);
63
+ private readonly _fs = inject(FileService);
64
+ private readonly _alert = inject(AlertService);
65
+
66
+ readonly isMultiple = computed(() => this.mode().startsWith('multi-'));
67
+ readonly isImageMode = computed(() => this.mode().includes('image'));
68
+
69
+ /** Normalized list of URLs for rendering */
70
+ readonly files = computed<string[]>(() => {
71
+ const mode = this.mode();
72
+ switch (mode) {
73
+ case 'single-image':
74
+ return this.wImage() ? [this.wImage() as string] : [];
75
+ case 'single-file':
76
+ return this.wFile() ? [this.wFile() as string] : [];
77
+ case 'multi-image':
78
+ return this.wImages() ?? [];
79
+ case 'multi-file':
80
+ return this.wFiles() ?? [];
81
+ default:
82
+ return [];
83
+ }
84
+ });
85
+
86
+ triggerPick(input: HTMLInputElement): void {
87
+ if (!this.disabled()) {
88
+ input.click();
89
+ }
90
+ }
91
+
92
+ isImage(src: string): boolean {
93
+ return /\.(png|jpe?g|webp|gif)(\?|$)/i.test(src ?? '');
94
+ }
95
+
96
+ async onPicked(input: HTMLInputElement): Promise<void> {
97
+ const list = input.files;
98
+ if (!list || !list.length) return;
99
+
100
+ const doCrop =
101
+ this.isImageMode() && !!this.cropWidth() && !!this.cropHeight();
102
+ const urls: string[] = [];
103
+ const container = this.container();
104
+
105
+ try {
106
+ for (let i = 0; i < list.length; i++) {
107
+ const f = list.item(i)!;
108
+
109
+ // Always read file as data URL
110
+ const dataUrl = await fileToDataUrl(f);
111
+
112
+ if (doCrop) {
113
+ const cropWidth = this.cropWidth()!;
114
+ const cropHeight = this.cropHeight()!;
115
+
116
+ // Lazy-load fabric crop modal only when actually cropping
117
+ const { FabricCropModalComponent } = await import(
118
+ '@wawjs/ngx-fabric'
119
+ );
120
+ await new Promise<void>((resolve, reject) => {
121
+ this._modal.show({
122
+ component: FabricCropModalComponent,
123
+ size: 'big',
124
+ image: dataUrl,
125
+ width: this._cropStageWidth(cropWidth),
126
+ height: this._cropStageHeight(cropHeight),
127
+ aspectRatio: cropWidth / cropHeight,
128
+ outputWidth: cropWidth,
129
+ outputHeight: cropHeight,
130
+ onCrop: (result: FabricCropResult) => {
131
+ this._fs
132
+ .uploadBase64(result.base64, container, this._uploadName(result.base64, f.name))
133
+ .then((url) => {
134
+ if (url) {
135
+ urls.push(url);
136
+ }
137
+
138
+ resolve();
139
+ }, reject);
140
+ },
141
+ onCancel: () => resolve(),
142
+ // Escape, backdrop and the close button only call onClose.
143
+ onClose: () => resolve(),
144
+ });
145
+ });
146
+ } else {
147
+ const url = await this._fs.uploadBase64(
148
+ dataUrl,
149
+ container,
150
+ this._uploadName(dataUrl, f.name),
151
+ );
152
+
153
+ if (url) {
154
+ urls.push(url);
155
+ }
156
+ }
157
+
158
+ // If single mode, ignore extra files after first
159
+ if (!this.isMultiple()) {
160
+ break;
161
+ }
162
+ }
163
+ } catch {
164
+ this._alert.error({ text: 'File upload failed' });
165
+ } finally {
166
+ // Keep uploads that succeeded before a failure and always reset the input.
167
+ this._applyNewUrls(urls);
168
+ input.value = '';
169
+ }
170
+ }
171
+
172
+ removeAt(index: number): void {
173
+ const mode = this.mode();
174
+
175
+ if (mode === 'single-image') {
176
+ this.wImage.set(null);
177
+ return;
178
+ }
179
+
180
+ if (mode === 'single-file') {
181
+ this.wFile.set(null);
182
+ return;
183
+ }
184
+
185
+ // Multi modes
186
+ const current = [...this.files()];
187
+ current.splice(index, 1);
188
+
189
+ if (mode === 'multi-image') {
190
+ this.wImages.set(current);
191
+ } else if (mode === 'multi-file') {
192
+ this.wFiles.set(current);
193
+ }
194
+ }
195
+
196
+ clear(): void {
197
+ const mode = this.mode();
198
+ if (mode === 'single-image') {
199
+ this.wImage.set(null);
200
+ } else if (mode === 'single-file') {
201
+ this.wFile.set(null);
202
+ } else if (mode === 'multi-image') {
203
+ this.wImages.set([]);
204
+ } else if (mode === 'multi-file') {
205
+ this.wFiles.set([]);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * The backend takes the stored file's extension from `name`; without one, images are saved
211
+ * with no extension and are later shown as plain links.
212
+ */
213
+ private _uploadName(dataUrl: string, fileName: string): string {
214
+ const configured = this.name();
215
+
216
+ if (configured) {
217
+ return configured;
218
+ }
219
+
220
+ const mime = /^data:([^;,]+)/.exec(dataUrl)?.[1] ?? '';
221
+ const extension: Record<string, string> = {
222
+ 'image/jpeg': 'jpg',
223
+ 'image/png': 'png',
224
+ 'image/webp': 'webp',
225
+ 'image/gif': 'gif',
226
+ };
227
+
228
+ return extension[mime] ? `file.${extension[mime]}` : fileName;
229
+ }
230
+
231
+ private _cropStageWidth(width: number): number {
232
+ return Math.min(820, Math.max(width, Math.round(width * 1.45)));
233
+ }
234
+
235
+ private _cropStageHeight(height: number): number {
236
+ return Math.min(620, Math.max(height, Math.round(height * 1.12)));
237
+ }
238
+
239
+ private _applyNewUrls(urls: string[]): void {
240
+ const mode = this.mode();
241
+
242
+ if (!urls.length) {
243
+ return;
244
+ }
245
+
246
+ if (mode === 'single-image') {
247
+ this.wImage.set(urls[0] ?? null);
248
+ return;
249
+ }
250
+
251
+ if (mode === 'single-file') {
252
+ this.wFile.set(urls[0] ?? null);
253
+ return;
254
+ }
255
+
256
+ if (mode === 'multi-image') {
257
+ this.wImages.set([...(this.wImages() ?? []), ...urls]);
258
+ return;
259
+ }
260
+
261
+ if (mode === 'multi-file') {
262
+ this.wFiles.set([...(this.wFiles() ?? []), ...urls]);
263
+ }
264
+ }
265
+ }
@@ -1,36 +1,36 @@
1
- import { Service, inject } from '@angular/core';
2
- import { CrudService } from '@wawjs/ngx-crud';
3
- import { HttpService } from '@wawjs/ngx-http';
4
- import { File } from './file.interface';
5
-
6
- interface UploadBase64Response {
7
- publicUrl?: string;
8
- }
9
-
10
- @Service()
11
- export class FileService extends CrudService<File> {
12
- private readonly _http = inject(HttpService);
13
-
14
- constructor() {
15
- super({ name: 'file' });
16
- }
17
-
18
- /**
19
- * Upload base64 (data URL) to backend with optional container/name.
20
- * Returns a URL string from the API; rejects when the request fails.
21
- */
22
- async uploadBase64(
23
- dataUrl: string,
24
- container = 'general',
25
- name = '',
26
- ): Promise<string> {
27
- return await new Promise<string>((resolve, reject) => {
28
- this._http.post(
29
- '/api/cloudflare/upload-base64',
30
- { container, name, dataUrl },
31
- (resp: UploadBase64Response) => resolve(resp?.publicUrl || ''),
32
- { err: (error: unknown) => reject(error) },
33
- );
34
- });
35
- }
36
- }
1
+ import { Service, inject } from '@angular/core';
2
+ import { CrudService } from '@wawjs/ngx-crud';
3
+ import { HttpService } from '@wawjs/ngx-http';
4
+ import { File } from './file.interface';
5
+
6
+ interface UploadBase64Response {
7
+ publicUrl?: string;
8
+ }
9
+
10
+ @Service()
11
+ export class FileService extends CrudService<File> {
12
+ private readonly _http = inject(HttpService);
13
+
14
+ constructor() {
15
+ super({ name: 'file' });
16
+ }
17
+
18
+ /**
19
+ * Upload base64 (data URL) to backend with optional container/name.
20
+ * Returns a URL string from the API; rejects when the request fails.
21
+ */
22
+ async uploadBase64(
23
+ dataUrl: string,
24
+ container = 'general',
25
+ name = '',
26
+ ): Promise<string> {
27
+ return await new Promise<string>((resolve, reject) => {
28
+ this._http.post(
29
+ '/api/cloudflare/upload-base64',
30
+ { container, name, dataUrl },
31
+ (resp: UploadBase64Response) => resolve(resp?.publicUrl || ''),
32
+ { err: (error: unknown) => reject(error) },
33
+ );
34
+ });
35
+ }
36
+ }
@@ -63,10 +63,17 @@ export async function resizeImageToBounds(
63
63
  const ctx = canvas.getContext('2d');
64
64
  ctx?.drawImage(img, 0, 0, width, height);
65
65
 
66
- const resized = canvas.toDataURL('image/jpeg', 1);
67
- resolve(resized);
66
+ // PNG and WebP keep their format so transparent areas stay transparent.
67
+ const type =
68
+ file.type === 'image/png' || file.type === 'image/webp' ? file.type : 'image/jpeg';
69
+
70
+ resolve(canvas.toDataURL(type, 1));
68
71
  };
69
72
 
73
+ // A file the browser cannot decode (broken, or an unsupported format) is passed through
74
+ // unchanged instead of leaving the upload waiting forever.
75
+ img.onerror = () => resolve(original);
76
+
70
77
  img.src = original;
71
78
  });
72
79
  }
@@ -1,12 +1,12 @@
1
- <wtable title="Files" [columns]="columns" [config]="config" [rows]="rows()">
2
- <ng-template cell="img" let-element>
3
- <img
4
- [src]="element.url || ''"
5
- (click)="copy(element.url)"
6
- style="height: 100px"
7
- />
8
- </ng-template>
9
- <ng-template cell="url" let-element>
10
- <span (click)="copy(element.url || '')">{{ element.url }}</span>
11
- </ng-template>
12
- </wtable>
1
+ <wtable title="Files" [columns]="columns" [config]="config" [rows]="rows()">
2
+ <ng-template cell="img" let-element>
3
+ <img
4
+ [src]="element.url || ''"
5
+ (click)="copy(element.url)"
6
+ style="height: 100px"
7
+ />
8
+ </ng-template>
9
+ <ng-template cell="url" let-element>
10
+ <span (click)="copy(element.url || '')">{{ element.url }}</span>
11
+ </ng-template>
12
+ </wtable>