@wawjs/ngx-bos 22.0.1 → 22.0.2

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.1",
3
+ "version": "22.0.2",
4
4
  "license": "MIT",
5
5
  "peerDependencies": {
6
6
  "@angular/common": "^22.0.0",
@@ -1,5 +1,5 @@
1
1
  @let _label = label(); @let _ph = placeholder(); @let _files = files(); @let
2
- _disabled = isDisabled(); @let _view = view();
2
+ _disabled = disabled(); @let _view = view();
3
3
 
4
4
  <div class="wfile" [class._disabled]="_disabled">
5
5
  @if (_label) {
@@ -62,7 +62,6 @@ export class FileComponent {
62
62
  private readonly _modal = inject(ModalService);
63
63
  private readonly _fs = inject(FileService);
64
64
 
65
- readonly isDisabled = computed(() => this.disabled());
66
65
  readonly isMultiple = computed(() => this.mode().startsWith('multi-'));
67
66
  readonly isImageMode = computed(() => this.mode().includes('image'));
68
67
 
@@ -84,7 +83,7 @@ export class FileComponent {
84
83
  });
85
84
 
86
85
  triggerPick(input: HTMLInputElement): void {
87
- if (!this.isDisabled()) {
86
+ if (!this.disabled()) {
88
87
  input.click();
89
88
  }
90
89
  }
@@ -110,6 +109,9 @@ export class FileComponent {
110
109
  const dataUrl = await fileToDataUrl(f);
111
110
 
112
111
  if (doCrop) {
112
+ const cropWidth = this.cropWidth()!;
113
+ const cropHeight = this.cropHeight()!;
114
+
113
115
  // Lazy-load fabric crop modal only when actually cropping
114
116
  const { FabricCropModalComponent } = await import(
115
117
  '@wawjs/ngx-fabric'
@@ -119,16 +121,19 @@ export class FileComponent {
119
121
  component: FabricCropModalComponent,
120
122
  size: 'big',
121
123
  image: dataUrl,
122
- width: this.cropWidth()!,
123
- height: this.cropHeight()!,
124
- aspectRatio: this.cropWidth()! / this.cropHeight()!,
125
- outputWidth: this.cropWidth()!,
126
- outputHeight: this.cropHeight()!,
124
+ width: this._cropStageWidth(cropWidth),
125
+ height: this._cropStageHeight(cropHeight),
126
+ aspectRatio: cropWidth / cropHeight,
127
+ outputWidth: cropWidth,
128
+ outputHeight: cropHeight,
127
129
  onCrop: (result: FabricCropResult) => {
128
130
  this._fs
129
131
  .uploadBase64(result.base64, container, name)
130
132
  .then((url) => {
131
- urls.push(url);
133
+ if (url) {
134
+ urls.push(url);
135
+ }
136
+
132
137
  resolve();
133
138
  });
134
139
  },
@@ -141,7 +146,10 @@ export class FileComponent {
141
146
  container,
142
147
  name,
143
148
  );
144
- urls.push(url);
149
+
150
+ if (url) {
151
+ urls.push(url);
152
+ }
145
153
  }
146
154
 
147
155
  // If single mode, ignore extra files after first
@@ -191,6 +199,14 @@ export class FileComponent {
191
199
  }
192
200
  }
193
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
+
194
210
  private _applyNewUrls(urls: string[]): void {
195
211
  const mode = this.mode();
196
212
 
@@ -1,13 +1,15 @@
1
- import { Injectable, inject } from '@angular/core';
1
+ import { Service, inject } from '@angular/core';
2
2
  import { CrudService } from '@wawjs/ngx-crud';
3
3
  import { HttpService } from '@wawjs/ngx-http';
4
- import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
5
4
  import { File } from './file.interface';
6
5
 
7
- @Injectable({ providedIn: 'root' })
6
+ interface UploadBase64Response {
7
+ publicUrl?: string;
8
+ }
9
+
10
+ @Service()
8
11
  export class FileService extends CrudService<File> {
9
12
  private readonly _http = inject(HttpService);
10
- private readonly _bosConfig = inject(NGX_BOS_CONFIG);
11
13
 
12
14
  constructor() {
13
15
  super({ name: 'file' });
@@ -26,8 +28,7 @@ export class FileService extends CrudService<File> {
26
28
  this._http.post(
27
29
  '/api/cloudflare/upload-base64',
28
30
  { container, name, dataUrl },
29
- (resp: { key: string }) =>
30
- resolve(this._bosConfig.cdnUrl + '/' + resp.key),
31
+ (resp: UploadBase64Response) => resolve(resp.publicUrl || ''),
31
32
  );
32
33
  });
33
34
  }
@@ -1,11 +1,8 @@
1
1
  <wselect
2
2
  [placeholder]="placeholder()"
3
3
  [items]="items()"
4
+ [wModel]="wModel()"
5
+ (wChange)="onSelect($event)"
4
6
  bindLabel="name"
5
7
  bindValue="_id"
6
8
  ></wselect>
7
-
8
- <!--
9
- [(wModel)]="wModel()"
10
- (wChange)="wChange.emit($event as string | null)"
11
- -->
@@ -1,14 +1,7 @@
1
- import {
2
- Component,
3
- inject,
4
- input,
5
- output,
6
- Signal,
7
- signal,
8
- } from '@angular/core';
9
- import { SelectComponent } from '@wawjs/ngx-ui';
1
+ import { Component, inject, input, output } from '@angular/core';
2
+ import { SelectComponent, SelectValue } from '@wawjs/ngx-ui';
10
3
  import { TranslateService } from '@wawjs/ngx-translate';
11
- import { File, FileService } from '../..';
4
+ import { FileService } from '../..';
12
5
 
13
6
  @Component({
14
7
  selector: 'file-selector',
@@ -21,7 +14,11 @@ export class FileSelectorComponent {
21
14
  readonly wModel = input<string | null>(null, { alias: 'wModel' });
22
15
  readonly wChange = output<string | null>();
23
16
 
24
- readonly items: Signal<File[]> = signal(this._files.documents());
17
+ readonly items = this._files.documents;
25
18
 
26
19
  readonly placeholder = this._translate.translate('Select file...');
20
+
21
+ onSelect(value: SelectValue): void {
22
+ this.wChange.emit((value ?? null) as string | null);
23
+ }
27
24
  }
@@ -7,8 +7,9 @@
7
7
  >
8
8
  @for (role of roles; track role) {
9
9
  <ng-template [cell]="role" let-user>
10
- <winput
11
- (wChange)="user.is[role] = $event; update(user)"
10
+ <winput
11
+ (click)="$event.stopPropagation()"
12
+ (wChange)="updateRole(user, role, !!$event)"
12
13
  [wModel]="user.is[role]"
13
14
  type="checkbox"
14
15
  />
@@ -0,0 +1,12 @@
1
+ :host ::ng-deep {
2
+ .wtable__th:nth-child(n + 3):not(:last-child),
3
+ .wtable__td:nth-child(n + 3):not(:last-child) {
4
+ width: 1%;
5
+ padding-inline: var(--sp-2);
6
+ white-space: nowrap;
7
+ }
8
+
9
+ .wtable__td:nth-child(n + 3):not(:last-child) winput {
10
+ display: inline-flex;
11
+ }
12
+ }
@@ -8,29 +8,55 @@ import { User } from '../../user.interface';
8
8
  import { UserService } from '../../user.service';
9
9
 
10
10
  @Component({
11
- imports: [TableComponent, CellDirective, InputComponent],
12
- templateUrl: './users.component.html',
13
- })
11
+ imports: [TableComponent, CellDirective, InputComponent],
12
+ templateUrl: './users.component.html',
13
+ styleUrl: './users.component.scss',
14
+ })
14
15
  export class UsersComponent extends CrudComponent<
15
16
  UserService,
16
17
  User,
17
18
  FormInterface
18
19
  > {
19
- protected override configType: 'server' | 'local' = 'local';
20
+ protected override configType: 'server' | 'local' = 'local';
21
+ private readonly _formService = inject(FormService);
20
22
 
21
23
  protected override allowUrl(): boolean {
22
24
  return false;
23
25
  }
24
26
 
25
- protected override async delete(doc: User) {
27
+ protected override async delete(doc: User) {
26
28
  this.userService.deleteAdmin(doc).subscribe(() => {
27
29
  this.setDocuments();
28
30
  });
29
- }
31
+ }
32
+
33
+ protected override update(doc: User): void {
34
+ if (this.form.formId) {
35
+ this._formService.reset(
36
+ this.form.formId,
37
+ doc as unknown as Record<string, unknown>,
38
+ );
39
+ }
40
+
41
+ this._formService.modal(
42
+ this.form,
43
+ {
44
+ label: 'Update',
45
+ click: (updated: unknown, close: () => void) => {
46
+ close();
47
+ Object.assign(doc, updated as User);
48
+ this.userService.updateAdmin(doc).subscribe(() => {
49
+ this.setDocuments();
50
+ });
51
+ },
52
+ },
53
+ doc,
54
+ );
55
+ }
30
56
 
31
57
  private _router = inject(Router);
32
58
 
33
- userService = inject(UserService);
59
+ userService = inject(UserService);
34
60
 
35
61
  readonly roles = this._router.url.includes('admin')
36
62
  ? this.userService.roles
@@ -53,5 +79,12 @@ export class UsersComponent extends CrudComponent<
53
79
  for (const role of this.userService.roles) {
54
80
  this.columns.push(role);
55
81
  }
56
- }
57
- }
82
+ }
83
+
84
+ updateRole(user: User, role: string, value: boolean): void {
85
+ user.is[role] = value;
86
+ this.userService.updateAdmin(user).subscribe(() => {
87
+ this.setDocuments();
88
+ });
89
+ }
90
+ }
@@ -24,7 +24,7 @@ export class UserService extends CrudService<User> {
24
24
 
25
25
  employees = this._bosConfig.roles;
26
26
 
27
- users = signal<User[]>(this.documents());
27
+ readonly users = this.documents;
28
28
 
29
29
  user = signal<User>(
30
30
  localStorage.getItem('waw_user')
@@ -37,7 +37,9 @@ export class UserService extends CrudService<User> {
37
37
 
38
38
  return !thumb || thumb.includes(this._bosConfig.defaultUserThumb)
39
39
  ? this._bosConfig.defaultUserThumb
40
- : this.url + thumb;
40
+ : /^https?:\/\//i.test(thumb)
41
+ ? thumb
42
+ : this.url + thumb;
41
43
  });
42
44
 
43
45
  role(role: string): boolean {
@@ -12,5 +12,6 @@
12
12
  [wClass]="data.props.wClass ?? inputDefaults.wClass"
13
13
  [autocomplete]="data.props.autocomplete ?? inputDefaults.autocomplete"
14
14
  [error]="data.props.error ?? inputDefaults.error"
15
+ (wChange)="data.props.onChange?.($event); data.wChange?.()"
15
16
  ></winput>
16
17
  </ng-template>
@@ -1,6 +1,6 @@
1
1
  <ng-template #templateRef let-data>
2
2
  <wselect
3
- [formField]="data.formField"
3
+ [formField]="data.field"
4
4
  [items]="data.props.items ?? selectDefaults.items"
5
5
  [placeholder]="
6
6
  data.props.placeholder ?? selectDefaults.placeholder
@@ -19,6 +19,6 @@
19
19
  data.props.disabled === true ||
20
20
  data.component.disabled === true
21
21
  "
22
- (wChange)="data.props.onChange?.($event)"
22
+ (wChange)="data.props.onChange?.($event); data.wChange?.()"
23
23
  ></wselect>
24
24
  </ng-template>
@@ -48,14 +48,14 @@ export class FormComponent extends CrudComponent<
48
48
  /** wtable config built by CrudComponent, aware of server mode */
49
49
  config = this.getConfig();
50
50
 
51
- constructor(
52
- _formcomponentService: FormcomponentService,
53
- _formService: FormService,
54
- ) {
55
- super(formcomponentForm, _formService, _formcomponentService, 'user');
51
+ constructor() {
52
+ const formcomponentService = inject(FormcomponentService);
53
+ const formService = inject(FormService);
54
+
55
+ super(formcomponentForm, formService, formcomponentService, 'user');
56
56
 
57
57
  effect(() => {
58
- if (_formcomponentService.isLoaded()) {
58
+ if (formcomponentService.isLoaded()) {
59
59
  this.setDocuments();
60
60
  }
61
61
  });
@@ -63,7 +63,7 @@ export class FormComponent extends CrudComponent<
63
63
  this.config.buttons.unshift({
64
64
  icon: 'settings',
65
65
  click: (doc: Formcomponent) => {
66
- _formService.modal<Record<string, unknown>>(
66
+ formService.modal<Record<string, unknown>>(
67
67
  FORM_COMPONENT_FORM(doc.name),
68
68
  {
69
69
  label: 'Update',
@@ -75,7 +75,7 @@ export class FormComponent extends CrudComponent<
75
75
  ...(updated as object),
76
76
  };
77
77
 
78
- _formcomponentService.update(doc);
78
+ formcomponentService.update(doc);
79
79
  },
80
80
  },
81
81
  doc.props || {},
package/src/public-api.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * the source app into the package.
6
6
  */
7
7
 
8
- export const NGX_BOS_VERSION = '22.0.0' as const;
8
+ export const NGX_BOS_VERSION = '22.0.2' as const;
9
9
 
10
10
  export type NgxBosVersion = typeof NGX_BOS_VERSION;
11
11
 
@@ -1,12 +1,12 @@
1
1
  import * as _wawjs_ngx_crud from '@wawjs/ngx-crud';
2
2
  import { CrudDocument, CrudService, CrudComponent } from '@wawjs/ngx-crud';
3
- import { FormComponentInterface, FormInterface, FormcomponentService, Formcomponent, FormService, Form } from '@wawjs/ngx-form';
3
+ import { FormComponentInterface, FormInterface, FormcomponentService, Formcomponent, Form } from '@wawjs/ngx-form';
4
4
  import * as rxjs from 'rxjs';
5
5
  import * as _angular_core from '@angular/core';
6
- import { InjectionToken, EnvironmentProviders, TemplateRef, Signal, Type, Provider, PipeTransform } from '@angular/core';
7
- import { CountryCode } from 'libphonenumber-js';
6
+ import { InjectionToken, EnvironmentProviders, TemplateRef, Type, Provider, PipeTransform } from '@angular/core';
8
7
  import * as _wawjs_ngx_bos from '@wawjs/ngx-bos';
9
8
  import { SelectValue } from '@wawjs/ngx-ui';
9
+ import { CountryCode } from 'libphonenumber-js';
10
10
  import { Routes, CanActivateFn } from '@angular/router';
11
11
 
12
12
  interface NgxBosConfig {
@@ -54,7 +54,6 @@ declare class FileComponent {
54
54
  readonly wFiles: _angular_core.ModelSignal<string[]>;
55
55
  private readonly _modal;
56
56
  private readonly _fs;
57
- readonly isDisabled: _angular_core.Signal<boolean>;
58
57
  readonly isMultiple: _angular_core.Signal<boolean>;
59
58
  readonly isImageMode: _angular_core.Signal<boolean>;
60
59
  /** Normalized list of URLs for rendering */
@@ -64,6 +63,8 @@ declare class FileComponent {
64
63
  onPicked(input: HTMLInputElement): Promise<void>;
65
64
  removeAt(index: number): void;
66
65
  clear(): void;
66
+ private _cropStageWidth;
67
+ private _cropStageHeight;
67
68
  private _applyNewUrls;
68
69
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<FileComponent, never>;
69
70
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<FileComponent, "ngx-file", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "clearable": { "alias": "clearable"; "required": false; "isSignal": true; }; "accept": { "alias": "accept"; "required": false; "isSignal": true; }; "preview": { "alias": "preview"; "required": false; "isSignal": true; }; "mode": { "alias": "mode"; "required": false; "isSignal": true; }; "view": { "alias": "view"; "required": false; "isSignal": true; }; "cropWidth": { "alias": "cropWidth"; "required": false; "isSignal": true; }; "cropHeight": { "alias": "cropHeight"; "required": false; "isSignal": true; }; "t_item": { "alias": "t_item"; "required": false; "isSignal": true; }; "t_empty": { "alias": "t_empty"; "required": false; "isSignal": true; }; "container": { "alias": "container"; "required": false; "isSignal": true; }; "name": { "alias": "name"; "required": false; "isSignal": true; }; "wImage": { "alias": "wImage"; "required": false; "isSignal": true; }; "wFile": { "alias": "wFile"; "required": false; "isSignal": true; }; "wImages": { "alias": "wImages"; "required": false; "isSignal": true; }; "wFiles": { "alias": "wFiles"; "required": false; "isSignal": true; }; }, { "wImage": "wImageChange"; "wFile": "wFileChange"; "wImages": "wImagesChange"; "wFiles": "wFilesChange"; }, never, never, true, never>;
@@ -81,7 +82,6 @@ interface ImageResizeBounds {
81
82
 
82
83
  declare class FileService extends CrudService<File$1> {
83
84
  private readonly _http;
84
- private readonly _bosConfig;
85
85
  constructor();
86
86
  /**
87
87
  * Upload base64 (data URL) to backend with optional container/name.
@@ -122,8 +122,9 @@ declare class FileSelectorComponent {
122
122
  private _translate;
123
123
  readonly wModel: _angular_core.InputSignal<string | null>;
124
124
  readonly wChange: _angular_core.OutputEmitterRef<string | null>;
125
- readonly items: Signal<File$1[]>;
125
+ readonly items: _angular_core.Signal<_wawjs_ngx_bos.File[]>;
126
126
  readonly placeholder: _angular_core.WritableSignal<string>;
127
+ onSelect(value: SelectValue): void;
127
128
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<FileSelectorComponent, never>;
128
129
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<FileSelectorComponent, "file-selector", never, { "wModel": { "alias": "wModel"; "required": false; "isSignal": true; }; }, { "wChange": "wChange"; }, never, never, true, never>;
129
130
  }
@@ -199,7 +200,7 @@ declare class UserService extends CrudService<User> {
199
200
  readonly url: string;
200
201
  roles: string[];
201
202
  employees: string[];
202
- users: _angular_core.WritableSignal<User[]>;
203
+ readonly users: _angular_core.Signal<User[]>;
203
204
  user: _angular_core.WritableSignal<User>;
204
205
  thumb: _angular_core.Signal<string>;
205
206
  role(role: string): boolean;
@@ -239,14 +240,17 @@ declare class UserPreviewComponent {
239
240
 
240
241
  declare class UsersComponent extends CrudComponent<UserService, User, FormInterface> {
241
242
  protected configType: 'server' | 'local';
243
+ private readonly _formService;
242
244
  protected allowUrl(): boolean;
243
245
  protected delete(doc: User): Promise<void>;
246
+ protected update(doc: User): void;
244
247
  private _router;
245
248
  userService: UserService;
246
249
  readonly roles: string[];
247
250
  columns: string[];
248
251
  config: _wawjs_ngx_crud.TableConfig<User>;
249
252
  constructor();
253
+ updateRole(user: User, role: string, value: boolean): void;
250
254
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<UsersComponent, never>;
251
255
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<UsersComponent, "ng-component", never, {}, {}, never, never, true, never>;
252
256
  }
@@ -280,7 +284,7 @@ declare class FormComponent extends CrudComponent<FormcomponentService, Formcomp
280
284
  columns: string[];
281
285
  /** wtable config built by CrudComponent, aware of server mode */
282
286
  config: _wawjs_ngx_crud.TableConfig<Formcomponent>;
283
- constructor(_formcomponentService: FormcomponentService, _formService: FormService);
287
+ constructor();
284
288
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<FormComponent, never>;
285
289
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<FormComponent, "ng-component", never, {}, {}, never, never, true, never>;
286
290
  }
@@ -325,7 +329,7 @@ declare class PhonePipe implements PipeTransform {
325
329
  static ɵpipe: _angular_core.ɵɵPipeDeclaration<PhonePipe, "phone", true>;
326
330
  }
327
331
 
328
- declare const NGX_BOS_VERSION: "22.0.0";
332
+ declare const NGX_BOS_VERSION: "22.0.2";
329
333
  type NgxBosVersion = typeof NGX_BOS_VERSION;
330
334
 
331
335
  export { ClientsComponent, DEFAULT_NGX_BOS_CONFIG, FORM_COMPONENTS, FORM_COMPONENT_FORM, FORM_TEMPLATE_COMPONENTS, FileComponent, FileSelectorComponent, FileService, FilesComponent, FormComponent, FormsComponent, NEW_USER, NGX_BOS_CONFIG, NGX_BOS_VERSION, PhonePipe, SpiderComponent, UserPreviewComponent, UserSelectorComponent, UserService, UsersComponent, adminsGuard, authenticatedGuard, clientsRoutes, createUserFormComponents, fileDefaults, fileToDataUrl, filesRoutes, formRoutes, formsRoutes, guestGuard, ngxBosProvide, provideFormComponents, provideNgxBos, resizeImageToBounds, userFormComponentsFactory, usersRoutes };