@wawjs/ngx-bos 22.0.4 → 22.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@wawjs/ngx-bos",
3
- "version": "22.0.4",
3
+ "version": "22.0.5",
4
4
  "license": "MIT",
5
5
  "peerDependencies": {
6
6
  "@angular/common": "^22.0.0",
@@ -8,15 +8,15 @@
8
8
  "@angular/core": "^22.0.0",
9
9
  "@angular/forms": "^22.0.0",
10
10
  "@angular/router": "^22.0.0",
11
- "@wawjs/ngx-core": "^22.0.7",
12
- "@wawjs/ngx-crud": "^22.0.7",
13
- "@wawjs/ngx-ace": "^22.0.7",
14
- "@wawjs/ngx-fabric": "^22.0.7",
15
- "@wawjs/ngx-form": "^22.0.7",
16
- "@wawjs/ngx-http": "^22.0.7",
17
- "@wawjs/ngx-tinymce": "^22.0.7",
18
- "@wawjs/ngx-translate": "^22.0.7",
19
- "@wawjs/ngx-ui": "^22.0.7",
11
+ "@wawjs/ngx-core": "^22.0.9",
12
+ "@wawjs/ngx-crud": "^22.0.9",
13
+ "@wawjs/ngx-ace": "^22.0.9",
14
+ "@wawjs/ngx-fabric": "^22.0.9",
15
+ "@wawjs/ngx-form": "^22.0.9",
16
+ "@wawjs/ngx-http": "^22.0.9",
17
+ "@wawjs/ngx-tinymce": "^22.0.9",
18
+ "@wawjs/ngx-translate": "^22.0.9",
19
+ "@wawjs/ngx-ui": "^22.0.9",
20
20
  "libphonenumber-js": "^1.13.7"
21
21
  },
22
22
  "dependencies": {
@@ -1,236 +1,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 { 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
- for (let i = 0; i < list.length; i++) {
106
- const f = list.item(i)!;
107
-
108
- // Always read file as data URL
109
- const dataUrl = await fileToDataUrl(f);
110
-
111
- if (doCrop) {
112
- const cropWidth = this.cropWidth()!;
113
- const cropHeight = this.cropHeight()!;
114
-
115
- // Lazy-load fabric crop modal only when actually cropping
116
- const { FabricCropModalComponent } = await import(
117
- '@wawjs/ngx-fabric'
118
- );
119
- await new Promise<void>((resolve) => {
120
- this._modal.show({
121
- component: FabricCropModalComponent,
122
- size: 'big',
123
- image: dataUrl,
124
- width: this._cropStageWidth(cropWidth),
125
- height: this._cropStageHeight(cropHeight),
126
- aspectRatio: cropWidth / cropHeight,
127
- outputWidth: cropWidth,
128
- outputHeight: cropHeight,
129
- onCrop: (result: FabricCropResult) => {
130
- this._fs
131
- .uploadBase64(result.base64, container, name)
132
- .then((url) => {
133
- if (url) {
134
- urls.push(url);
135
- }
136
-
137
- resolve();
138
- });
139
- },
140
- onCancel: () => resolve(),
141
- });
142
- });
143
- } else {
144
- const url = await this._fs.uploadBase64(
145
- dataUrl,
146
- container,
147
- name,
148
- );
149
-
150
- if (url) {
151
- urls.push(url);
152
- }
153
- }
154
-
155
- // If single mode, ignore extra files after first
156
- if (!this.isMultiple()) {
157
- break;
158
- }
159
- }
160
-
161
- this._applyNewUrls(urls);
162
- input.value = '';
163
- }
164
-
165
- removeAt(index: number): void {
166
- const mode = this.mode();
167
-
168
- if (mode === 'single-image') {
169
- this.wImage.set(null);
170
- return;
171
- }
172
-
173
- if (mode === 'single-file') {
174
- this.wFile.set(null);
175
- return;
176
- }
177
-
178
- // Multi modes
179
- const current = [...this.files()];
180
- current.splice(index, 1);
181
-
182
- if (mode === 'multi-image') {
183
- this.wImages.set(current);
184
- } else if (mode === 'multi-file') {
185
- this.wFiles.set(current);
186
- }
187
- }
188
-
189
- clear(): void {
190
- const mode = this.mode();
191
- if (mode === 'single-image') {
192
- this.wImage.set(null);
193
- } else if (mode === 'single-file') {
194
- this.wFile.set(null);
195
- } else if (mode === 'multi-image') {
196
- this.wImages.set([]);
197
- } else if (mode === 'multi-file') {
198
- this.wFiles.set([]);
199
- }
200
- }
201
-
202
- private _cropStageWidth(width: number): number {
203
- return Math.min(820, Math.max(width, Math.round(width * 1.45)));
204
- }
205
-
206
- private _cropStageHeight(height: number): number {
207
- return Math.min(620, Math.max(height, Math.round(height * 1.12)));
208
- }
209
-
210
- private _applyNewUrls(urls: string[]): void {
211
- const mode = this.mode();
212
-
213
- if (!urls.length) {
214
- return;
215
- }
216
-
217
- if (mode === 'single-image') {
218
- this.wImage.set(urls[0] ?? null);
219
- return;
220
- }
221
-
222
- if (mode === 'single-file') {
223
- this.wFile.set(urls[0] ?? null);
224
- return;
225
- }
226
-
227
- if (mode === 'multi-image') {
228
- this.wImages.set([...this.wImages(), ...urls]);
229
- return;
230
- }
231
-
232
- if (mode === 'multi-file') {
233
- this.wFiles.set([...this.wFiles(), ...urls]);
234
- }
235
- }
236
- }
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,35 +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.
21
- */
22
- async uploadBase64(
23
- dataUrl: string,
24
- container = 'general',
25
- name = '',
26
- ): Promise<string> {
27
- return await new Promise<string>((resolve) => {
28
- this._http.post(
29
- '/api/cloudflare/upload-base64',
30
- { container, name, dataUrl },
31
- (resp: UploadBase64Response) => resolve(resp.publicUrl || ''),
32
- );
33
- });
34
- }
35
- }
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,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>