@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.
- package/README.md +1 -1
- package/RELEASES.md +38 -0
- package/ai/code-style.md +15 -0
- package/fesm2022/file.service-C8Erkqrm.mjs +48 -0
- package/fesm2022/file.service-C8Erkqrm.mjs.map +1 -0
- package/fesm2022/{wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs → ngx-bos.config-DjtgUjR8.mjs} +3 -5
- package/fesm2022/ngx-bos.config-DjtgUjR8.mjs.map +1 -0
- package/fesm2022/user-crud.component-B1_SlIDS.mjs +317 -0
- package/fesm2022/user-crud.component-B1_SlIDS.mjs.map +1 -0
- package/fesm2022/wawjs-ngx-bos.mjs +206 -187
- package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
- package/package.json +11 -9
- package/src/feature/file/file.component.html +1 -0
- package/src/feature/file/file.component.ts +265 -239
- package/src/feature/file/file.service.ts +36 -36
- package/src/feature/file/file.util.ts +9 -2
- package/src/feature/file/pages/files/files.component.html +12 -12
- package/src/feature/file/pages/files/files.component.ts +116 -116
- package/src/feature/user/guards/admins.guard.ts +21 -21
- package/src/feature/user/guards/authenticated.guard.ts +15 -15
- package/src/feature/user/guards/guest.guard.ts +15 -15
- package/src/feature/user/pages/clients/clients.component.ts +19 -45
- package/src/feature/user/pages/user-crud.component.ts +119 -0
- package/src/feature/user/pages/users/users.component.ts +33 -86
- package/src/feature/user/user.service.ts +120 -21
- package/src/feature/user/user.storage.ts +31 -31
- package/src/form-components/ace/ace.component.ts +15 -1
- package/src/form-components/file/file.component.html +2 -2
- package/src/form-components/form-config-cache.ts +70 -0
- package/src/form-components/input/input.form.ts +1 -1
- package/src/form-components/select/select.component.html +24 -24
- package/src/form-components/tinymce/tinymce.component.ts +12 -0
- package/src/icons/spider/spider.component.ts +4 -4
- package/src/ngx-bos.config.ts +7 -5
- package/src/pages/form/form.component.ts +137 -100
- package/src/pages/forms/forms.component.ts +14 -2
- package/src/public-api.ts +1 -1
- package/types/wawjs-ngx-bos.d.ts +52 -15
- package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +0 -1
- package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs +0 -181
- 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
|
-
"
|
|
27
|
-
"
|
|
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
|
-
"
|
|
38
|
-
}
|
|
39
|
+
"version": "22.0.7"
|
|
40
|
+
}
|
|
@@ -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
|
-
|
|
66
|
-
readonly
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
const
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this.
|
|
200
|
-
} else if (mode === '
|
|
201
|
-
this.
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
private
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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>
|