@wawjs/ngx-bos 22.0.4 → 22.0.6

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.6",
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": {
@@ -102,64 +102,67 @@ export class FileComponent {
102
102
  const container = this.container();
103
103
  const name = this.name();
104
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(),
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
+ });
141
143
  });
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);
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
+ }
152
154
  }
153
- }
154
155
 
155
- // If single mode, ignore extra files after first
156
- if (!this.isMultiple()) {
157
- break;
156
+ // If single mode, ignore extra files after first
157
+ if (!this.isMultiple()) {
158
+ break;
159
+ }
158
160
  }
161
+ } finally {
162
+ // Keep uploads that succeeded before a failure and always reset the input.
163
+ this._applyNewUrls(urls);
164
+ input.value = '';
159
165
  }
160
-
161
- this._applyNewUrls(urls);
162
- input.value = '';
163
166
  }
164
167
 
165
168
  removeAt(index: number): void {
@@ -17,18 +17,19 @@ export class FileService extends CrudService<File> {
17
17
 
18
18
  /**
19
19
  * Upload base64 (data URL) to backend with optional container/name.
20
- * Returns a URL string from the API.
20
+ * Returns a URL string from the API; rejects when the request fails.
21
21
  */
22
22
  async uploadBase64(
23
23
  dataUrl: string,
24
24
  container = 'general',
25
25
  name = '',
26
26
  ): Promise<string> {
27
- return await new Promise<string>((resolve) => {
27
+ return await new Promise<string>((resolve, reject) => {
28
28
  this._http.post(
29
29
  '/api/cloudflare/upload-base64',
30
30
  { container, name, dataUrl },
31
- (resp: UploadBase64Response) => resolve(resp.publicUrl || ''),
31
+ (resp: UploadBase64Response) => resolve(resp?.publicUrl || ''),
32
+ { err: (error: unknown) => reject(error) },
32
33
  );
33
34
  });
34
35
  }
@@ -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,4 +1,4 @@
1
- <wtable title="Files" [columns]="columns" [config]="config" [rows]="rows">
1
+ <wtable title="Files" [columns]="columns" [config]="config" [rows]="rows()">
2
2
  <ng-template cell="img" let-element>
3
3
  <img
4
4
  [src]="element.url || ''"
@@ -1,6 +1,6 @@
1
1
  import { Clipboard } from '@angular/cdk/clipboard';
2
- import { Component, inject } from '@angular/core';
3
- import { AlertService, TableComponent } from '@wawjs/ngx-ui';
2
+ import { Component, inject, signal } from '@angular/core';
3
+ import { AlertService, CellDirective, TableComponent } from '@wawjs/ngx-ui';
4
4
  import { FormInterface, FormService } from '@wawjs/ngx-form';
5
5
  import { CoreService } from '@wawjs/ngx-core';
6
6
  import { File, FileService } from '../..';
@@ -38,7 +38,7 @@ const fileFormComponents = {
38
38
 
39
39
  @Component({
40
40
  templateUrl: './files.component.html',
41
- imports: [TableComponent],
41
+ imports: [TableComponent, CellDirective],
42
42
  })
43
43
  export class FilesComponent {
44
44
  private _fileService = inject(FileService);
@@ -84,7 +84,7 @@ export class FilesComponent {
84
84
  },
85
85
  };
86
86
 
87
- rows: File[] = [];
87
+ readonly rows = signal<File[]>([]);
88
88
 
89
89
  constructor() {
90
90
  this.setRows();
@@ -101,8 +101,7 @@ export class FilesComponent {
101
101
  this,
102
102
  () => {
103
103
  this._fileService.get({ page }).subscribe((rows) => {
104
- this.rows.splice(0, this.rows.length);
105
- this.rows.push(...rows);
104
+ this.rows.set([...rows]);
106
105
  });
107
106
  },
108
107
  250,
@@ -1,26 +1,19 @@
1
- import { inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
1
+ import { inject } from '@angular/core';
3
2
  import { CanActivateFn, Router } from '@angular/router';
4
3
  import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
5
 
6
6
  export const adminsGuard: CanActivateFn = () => {
7
7
  const router = inject(Router);
8
8
  const config = inject(NGX_BOS_CONFIG);
9
9
 
10
- if (!isPlatformBrowser(inject(PLATFORM_ID))) {
11
- // See authenticatedGuard — no real session at build/prerender time, defer to the client.
12
- return true;
13
- }
10
+ const user = readStoredUser();
14
11
 
15
- const stored = localStorage.getItem('waw_user');
16
-
17
- if (!stored) {
12
+ if (!user) {
18
13
  return router.parseUrl(config.signPath);
19
14
  }
20
15
 
21
- const user = JSON.parse(stored);
22
-
23
- if (user.is && user.is.admin) {
16
+ if (user.is?.['admin']) {
24
17
  return true;
25
18
  }
26
19
 
@@ -1,20 +1,13 @@
1
- import { inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
1
+ import { inject } from '@angular/core';
3
2
  import { CanActivateFn, Router } from '@angular/router';
4
3
  import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
5
 
6
6
  export const authenticatedGuard: CanActivateFn = () => {
7
7
  const router = inject(Router);
8
8
  const config = inject(NGX_BOS_CONFIG);
9
9
 
10
- if (!isPlatformBrowser(inject(PLATFORM_ID))) {
11
- // No real session exists at build/prerender time — render the shell and let the client
12
- // re-check against the real localStorage after hydration, instead of baking a redirect
13
- // stub into the static file (which would bounce an already-authenticated user on reload).
14
- return true;
15
- }
16
-
17
- if (localStorage.getItem('waw_user')) {
10
+ if (readStoredUser()) {
18
11
  return true;
19
12
  }
20
13
 
@@ -1,13 +1,13 @@
1
- import { inject, PLATFORM_ID } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
1
+ import { inject } from '@angular/core';
3
2
  import { CanActivateFn, Router } from '@angular/router';
4
3
  import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
5
 
6
6
  export const guestGuard: CanActivateFn = () => {
7
7
  const router = inject(Router);
8
8
  const config = inject(NGX_BOS_CONFIG);
9
9
 
10
- if (isPlatformBrowser(inject(PLATFORM_ID)) && localStorage.getItem('waw_user')) {
10
+ if (readStoredUser()) {
11
11
  return router.parseUrl(config.profilePath);
12
12
  }
13
13
 
@@ -1,5 +1,4 @@
1
1
  import { Component, inject } from '@angular/core';
2
- import { Router } from '@angular/router';
3
2
  import { FormInterface, FormService } from '@wawjs/ngx-form';
4
3
  import { CrudComponent } from '@wawjs/ngx-crud';
5
4
  import { CellDirective, InputComponent, TableComponent } from '@wawjs/ngx-ui';
@@ -54,13 +53,10 @@ export class UsersComponent extends CrudComponent<
54
53
  );
55
54
  }
56
55
 
57
- private _router = inject(Router);
58
-
59
56
  userService = inject(UserService);
60
57
 
61
- readonly roles = this._router.url.includes('admin')
62
- ? this.userService.roles
63
- : this.userService.employees;
58
+ /** Every role gets a checkbox column; matches the columns added in the constructor. */
59
+ readonly roles = this.userService.roles;
64
60
 
65
61
  columns = ['name', 'email'];
66
62
 
@@ -1,5 +1,4 @@
1
- import { Service, computed, inject, PLATFORM_ID, signal } from '@angular/core';
2
- import { isPlatformBrowser } from '@angular/common';
1
+ import { Service, computed, inject, signal } from '@angular/core';
3
2
  import { Router } from '@angular/router';
4
3
  import { AlertService } from '@wawjs/ngx-ui';
5
4
  import { CrudService } from '@wawjs/ngx-crud';
@@ -7,6 +6,7 @@ import { EmitterService } from '@wawjs/ngx-core';
7
6
  import { HttpService } from '@wawjs/ngx-http';
8
7
  import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
9
8
  import { User } from './user.interface';
9
+ import { readStoredUser, USER_STORAGE_KEY } from './user.storage';
10
10
  @Service()
11
11
  export class UserService extends CrudService<User> {
12
12
  private readonly _userHttpService = inject(HttpService);
@@ -19,8 +19,6 @@ export class UserService extends CrudService<User> {
19
19
 
20
20
  private readonly _bosConfig = inject(NGX_BOS_CONFIG);
21
21
 
22
- private readonly _isBrowserPlatform = isPlatformBrowser(inject(PLATFORM_ID));
23
-
24
22
  readonly url = this._bosConfig.url;
25
23
 
26
24
  roles = this._bosConfig.roles.concat(['admin']);
@@ -29,13 +27,7 @@ export class UserService extends CrudService<User> {
29
27
 
30
28
  readonly users = this.documents;
31
29
 
32
- private readonly _storedUser = this._isBrowserPlatform ? localStorage.getItem('waw_user') : null;
33
-
34
- user = signal<User>(
35
- this._storedUser
36
- ? JSON.parse(this._storedUser)
37
- : this.prepareDocument()(),
38
- );
30
+ user = signal<User>(readStoredUser() ?? this.prepareDocument()());
39
31
 
40
32
  thumb = computed(() => {
41
33
  const thumb = this.user().thumb;
@@ -86,18 +78,11 @@ export class UserService extends CrudService<User> {
86
78
  },
87
79
  });
88
80
 
89
- if (this._isBrowserPlatform && localStorage.getItem('waw_user')) {
81
+ if (localStorage.getItem(USER_STORAGE_KEY)) {
90
82
  this.fetch({}, { name: 'me' }).subscribe((user: User) => {
91
83
  if (user) {
92
- if (
93
- !localStorage.getItem('waw_user') &&
94
- this._router.url === this._bosConfig.signPath
95
- ) {
96
- this._router.navigateByUrl(this._bosConfig.profilePath);
97
- }
98
-
99
84
  this.setUser(user);
100
- } else if (localStorage.getItem('waw_user')) {
85
+ } else if (localStorage.getItem(USER_STORAGE_KEY)) {
101
86
  this.logout();
102
87
  }
103
88
  });
@@ -111,7 +96,7 @@ export class UserService extends CrudService<User> {
111
96
  setUser(user: User) {
112
97
  this.user.set(user);
113
98
 
114
- localStorage.setItem('waw_user', JSON.stringify(user));
99
+ localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
115
100
 
116
101
  this._emitterService.complete('us.user');
117
102
  }
@@ -156,17 +141,29 @@ export class UserService extends CrudService<User> {
156
141
  logout() {
157
142
  this.user.set(this.prepareDocument()());
158
143
 
159
- localStorage.removeItem('waw_user');
144
+ localStorage.removeItem(USER_STORAGE_KEY);
160
145
 
161
- this._userHttpService.remove('token');
146
+ // Reload only after the server has cleared the session cookie: reloading right away can
147
+ // cancel the request and leave the session alive. Do not wait longer than 3s if the API is down.
148
+ let finished = false;
162
149
 
163
- this._userHttpService.get('/api/user/logout');
150
+ const finish = () => {
151
+ if (finished) return;
164
152
 
165
- this._router.navigateByUrl(this._bosConfig.signPath);
153
+ finished = true;
154
+
155
+ this._router.navigateByUrl(this._bosConfig.signPath);
156
+
157
+ setTimeout(() => {
158
+ location.reload();
159
+ }, 100);
160
+ };
161
+
162
+ this._userHttpService.get('/api/user/logout', finish, { err: finish });
163
+
164
+ this._userHttpService.remove('token');
166
165
 
167
- setTimeout(() => {
168
- location.reload();
169
- }, 100);
166
+ setTimeout(finish, 3000);
170
167
  }
171
168
 
172
169
  updateAdmin(user: User) {
@@ -0,0 +1,31 @@
1
+ import { User } from './user.interface';
2
+
3
+ /** localStorage key holding the signed-in user snapshot. */
4
+ export const USER_STORAGE_KEY = 'waw_user';
5
+
6
+ /**
7
+ * Reads the stored user snapshot. Returns `null` when nothing is stored or when the
8
+ * stored value is corrupted; a corrupted value is removed so it cannot break guards
9
+ * or service initialization again.
10
+ */
11
+ export function readStoredUser(): User | null {
12
+ const stored = localStorage.getItem(USER_STORAGE_KEY);
13
+
14
+ if (!stored) {
15
+ return null;
16
+ }
17
+
18
+ try {
19
+ const user = JSON.parse(stored) as User | null;
20
+
21
+ if (user && typeof user === 'object') {
22
+ return user;
23
+ }
24
+ } catch {
25
+ // fall through to cleanup
26
+ }
27
+
28
+ localStorage.removeItem(USER_STORAGE_KEY);
29
+
30
+ return null;
31
+ }
@@ -6,10 +6,10 @@ import { Component, input } from '@angular/core';
6
6
  styleUrl: './spider.component.scss',
7
7
  host: {
8
8
  class: 'spider',
9
- '[style.--spider-w]': 'width()',
10
- '[style.--spider-h]': 'height()',
11
- '[style.--spider-start]': 'start()',
12
- '[style.--spider-end]': 'end()',
9
+ '[style.--spider-w]': 'width()',
10
+ '[style.--spider-h]': 'height()',
11
+ '[style.--spider-start]': 'start()',
12
+ '[style.--spider-end]': 'end()',
13
13
  },
14
14
  })
15
15
  export class SpiderComponent {
@@ -27,7 +27,7 @@ export const DEFAULT_NGX_BOS_CONFIG: Required<NgxBosConfig> = {
27
27
  userForm: [],
28
28
  signPath: '/sign',
29
29
  profilePath: '/profile',
30
- defaultUserThumb: 'default.png',
30
+ defaultUserThumb: 'default.png',
31
31
  };
32
32
 
33
33
  export const NGX_BOS_CONFIG = new InjectionToken<Required<NgxBosConfig>>(
@@ -1,5 +1,6 @@
1
- import { Component, effect, inject } from '@angular/core';
2
- import { Router } from '@angular/router';
1
+ import { Component, computed, effect, inject } from '@angular/core';
2
+ import { toSignal } from '@angular/core/rxjs-interop';
3
+ import { ActivatedRoute } from '@angular/router';
3
4
  import { TableComponent } from '@wawjs/ngx-ui';
4
5
  import {
5
6
  Formcomponent,
@@ -21,21 +22,26 @@ export class FormComponent extends CrudComponent<
21
22
  Formcomponent,
22
23
  FormInterface
23
24
  > {
24
- private _router = inject(Router);
25
+ private _route = inject(ActivatedRoute);
25
26
  private _bosConfig = inject(NGX_BOS_CONFIG);
26
27
 
27
- readonly formId = this._router.url.split('form/')[1];
28
+ private readonly _params = toSignal(this._route.paramMap, {
29
+ initialValue: this._route.snapshot.paramMap,
30
+ });
31
+
32
+ /** Current `:formId` route param; updates when navigating between forms. */
33
+ readonly formId = computed(() => this._params().get('formId') || '');
28
34
 
29
35
  protected override configType: 'server' | 'local' = 'local';
30
36
 
31
37
  protected override preCreate(doc: Formcomponent) {
32
- doc.formId = this.formId;
38
+ doc.formId = this.formId();
33
39
 
34
40
  doc.appId = this._bosConfig.appId;
35
41
  }
36
42
 
37
43
  protected override localDocumentsFilter = (doc: Formcomponent) => {
38
- return doc.formId === this.formId;
44
+ return doc.formId === this.formId();
39
45
  };
40
46
 
41
47
  protected override allowUrl() {
@@ -52,9 +58,17 @@ export class FormComponent extends CrudComponent<
52
58
  const formcomponentService = inject(FormcomponentService);
53
59
  const formService = inject(FormService);
54
60
 
55
- super(formcomponentForm, formService, formcomponentService, 'user');
61
+ super(
62
+ formcomponentForm,
63
+ formService,
64
+ formcomponentService,
65
+ 'formcomponent',
66
+ );
56
67
 
57
68
  effect(() => {
69
+ // Re-filter when the route's formId changes (component is reused).
70
+ this.formId();
71
+
58
72
  if (formcomponentService.isLoaded()) {
59
73
  this.setDocuments();
60
74
  }
@@ -1,9 +1,4 @@
1
- import {
2
- Component,
3
- effect,
4
- inject,
5
- signal,
6
- } from '@angular/core';
1
+ import { Component, computed, inject } from '@angular/core';
7
2
  import { Form, formForm, FormService } from '@wawjs/ngx-form';
8
3
  import { TableComponent } from '@wawjs/ngx-ui';
9
4
  import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
@@ -56,22 +51,14 @@ export class FormsComponent {
56
51
  ],
57
52
  };
58
53
 
59
- documents = signal<Form[]>([]);
54
+ readonly documents = computed<Form[]>(() => {
55
+ const byFormId = this._formService.getFieldSignals('formId')();
60
56
 
61
- constructor() {
62
- effect(() => {
63
- const byFormId = this._formService.getFieldSignals('formId')();
64
-
65
- this.documents.set(
66
- this._formService.formIds().map((formId) => {
67
- return {
68
- formId,
69
- ...(byFormId[formId]?.length
70
- ? byFormId[formId][0]()
71
- : {}),
72
- } as Form;
73
- }),
74
- );
57
+ return this._formService.formIds().map((formId) => {
58
+ return {
59
+ formId,
60
+ ...(byFormId[formId]?.length ? byFormId[formId][0]() : {}),
61
+ } as Form;
75
62
  });
76
- }
63
+ });
77
64
  }
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.4' as const;
8
+ export const NGX_BOS_VERSION = '22.0.5' as const;
9
9
 
10
10
  export type NgxBosVersion = typeof NGX_BOS_VERSION;
11
11