wacom 21.2.3 → 21.2.4
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 +58 -64
- package/fesm2022/wacom.mjs +112 -150
- package/fesm2022/wacom.mjs.map +1 -1
- package/package.json +2 -2
- package/types/wacom.d.ts +16 -15
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ $ npm i --save wacom
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import { provideWacom } from
|
|
18
|
+
import { provideWacom } from 'wacom';
|
|
19
19
|
|
|
20
20
|
export const appConfig = {
|
|
21
21
|
providers: [provideWacom()],
|
|
@@ -29,13 +29,13 @@ export const appConfig = {
|
|
|
29
29
|
You can pass an optional configuration object to `provideWacom` to override the library defaults.
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
|
-
import { provideWacom } from
|
|
32
|
+
import { provideWacom } from 'wacom';
|
|
33
33
|
|
|
34
34
|
export const appConfig = {
|
|
35
35
|
providers: [
|
|
36
36
|
provideWacom({
|
|
37
|
-
http: { url:
|
|
38
|
-
store: { prefix:
|
|
37
|
+
http: { url: 'https://api.example.com' },
|
|
38
|
+
store: { prefix: 'waStore' },
|
|
39
39
|
meta: {
|
|
40
40
|
useTitleSuffix: false,
|
|
41
41
|
defaults: { links: {} },
|
|
@@ -66,7 +66,7 @@ export const appConfig = {
|
|
|
66
66
|
| [**`RTC`**](https://www.npmjs.com/package/wacom#rtc-service) | Wraps WebRTC peer connections and local media streams |
|
|
67
67
|
| [**`Util`**](https://www.npmjs.com/package/wacom#util-service) | Utility methods for forms, validation, and CSS variables |
|
|
68
68
|
| [**`Theme`**](#theme-service) | Manages UI theme mode, density, and radius preferences |
|
|
69
|
-
| [**`
|
|
69
|
+
| [**`Translate`**](#translate-service) | Lightweight, signal-based runtime translate engine |
|
|
70
70
|
|
|
71
71
|
## [Core Service](#core-service)
|
|
72
72
|
|
|
@@ -490,18 +490,18 @@ Example:
|
|
|
490
490
|
|
|
491
491
|
```ts
|
|
492
492
|
// Somewhere that waits for a single task
|
|
493
|
-
this.emitter.onComplete(
|
|
493
|
+
this.emitter.onComplete('profile:loaded').subscribe(() => {
|
|
494
494
|
// safe to render UI
|
|
495
495
|
});
|
|
496
496
|
|
|
497
497
|
// Somewhere that fulfills it
|
|
498
498
|
await api.loadProfile();
|
|
499
|
-
this.emitter.complete(
|
|
499
|
+
this.emitter.complete('profile:loaded');
|
|
500
500
|
|
|
501
501
|
// Wait for any of several tasks
|
|
502
502
|
this.emitter
|
|
503
|
-
.onComplete([
|
|
504
|
-
.subscribe(
|
|
503
|
+
.onComplete(['a', 'b'], { mode: 'any', timeoutMs: 5000 })
|
|
504
|
+
.subscribe(which => console.log('First done:', which));
|
|
505
505
|
```
|
|
506
506
|
|
|
507
507
|
## [Http Service](#http-service)
|
|
@@ -731,7 +731,7 @@ It supports raw values, safe JSON handling, key prefixing, and optional lifecycl
|
|
|
731
731
|
### Prefixing keys
|
|
732
732
|
|
|
733
733
|
```ts
|
|
734
|
-
storeService.setPrefix(
|
|
734
|
+
storeService.setPrefix('app_');
|
|
735
735
|
```
|
|
736
736
|
|
|
737
737
|
All keys will be stored as `app_<key>` (plus global config prefix if defined).
|
|
@@ -743,14 +743,14 @@ All keys will be stored as `app_<key>` (plus global config prefix if defined).
|
|
|
743
743
|
Stores a raw string value.
|
|
744
744
|
|
|
745
745
|
```ts
|
|
746
|
-
await storeService.set(
|
|
746
|
+
await storeService.set('token', 'abc123');
|
|
747
747
|
```
|
|
748
748
|
|
|
749
749
|
With hooks:
|
|
750
750
|
|
|
751
751
|
```ts
|
|
752
|
-
await storeService.set(
|
|
753
|
-
onSuccess: () => console.log(
|
|
752
|
+
await storeService.set('token', 'abc123', {
|
|
753
|
+
onSuccess: () => console.log('saved'),
|
|
754
754
|
onError: console.error,
|
|
755
755
|
});
|
|
756
756
|
```
|
|
@@ -764,14 +764,14 @@ await storeService.set("token", "abc123", {
|
|
|
764
764
|
Retrieves a raw string value.
|
|
765
765
|
|
|
766
766
|
```ts
|
|
767
|
-
const token = await storeService.get(
|
|
767
|
+
const token = await storeService.get('token');
|
|
768
768
|
```
|
|
769
769
|
|
|
770
770
|
With hooks:
|
|
771
771
|
|
|
772
772
|
```ts
|
|
773
|
-
const token = await storeService.get(
|
|
774
|
-
onSuccess:
|
|
773
|
+
const token = await storeService.get('token', {
|
|
774
|
+
onSuccess: v => console.log(v),
|
|
775
775
|
onError: console.error,
|
|
776
776
|
});
|
|
777
777
|
```
|
|
@@ -785,14 +785,14 @@ const token = await storeService.get("token", {
|
|
|
785
785
|
Stores a JSON-serializable value.
|
|
786
786
|
|
|
787
787
|
```ts
|
|
788
|
-
await storeService.setJson(
|
|
788
|
+
await storeService.setJson('profile', { name: 'Den', role: 'dev' });
|
|
789
789
|
```
|
|
790
790
|
|
|
791
791
|
With hooks:
|
|
792
792
|
|
|
793
793
|
```ts
|
|
794
|
-
await storeService.setJson(
|
|
795
|
-
onSuccess: () => console.log(
|
|
794
|
+
await storeService.setJson('profile', user, {
|
|
795
|
+
onSuccess: () => console.log('saved'),
|
|
796
796
|
onError: console.error,
|
|
797
797
|
});
|
|
798
798
|
```
|
|
@@ -809,13 +809,13 @@ Retrieves a JSON value safely.
|
|
|
809
809
|
- corrupted JSON → auto-cleared (by default)
|
|
810
810
|
|
|
811
811
|
```ts
|
|
812
|
-
const profile = await storeService.getJson<User>(
|
|
812
|
+
const profile = await storeService.getJson<User>('profile');
|
|
813
813
|
```
|
|
814
814
|
|
|
815
815
|
With defaults and error handling:
|
|
816
816
|
|
|
817
817
|
```ts
|
|
818
|
-
const profile = await storeService.getJson<User>(
|
|
818
|
+
const profile = await storeService.getJson<User>('profile', {
|
|
819
819
|
defaultValue: {},
|
|
820
820
|
onError: console.warn,
|
|
821
821
|
});
|
|
@@ -824,7 +824,7 @@ const profile = await storeService.getJson<User>("profile", {
|
|
|
824
824
|
Disable auto-clean:
|
|
825
825
|
|
|
826
826
|
```ts
|
|
827
|
-
await storeService.getJson(
|
|
827
|
+
await storeService.getJson('profile', {
|
|
828
828
|
clearOnError: false,
|
|
829
829
|
});
|
|
830
830
|
```
|
|
@@ -838,14 +838,14 @@ await storeService.getJson("profile", {
|
|
|
838
838
|
Removes a single key.
|
|
839
839
|
|
|
840
840
|
```ts
|
|
841
|
-
await storeService.remove(
|
|
841
|
+
await storeService.remove('token');
|
|
842
842
|
```
|
|
843
843
|
|
|
844
844
|
With hooks:
|
|
845
845
|
|
|
846
846
|
```ts
|
|
847
|
-
await storeService.remove(
|
|
848
|
-
onSuccess: () => console.log(
|
|
847
|
+
await storeService.remove('token', {
|
|
848
|
+
onSuccess: () => console.log('removed'),
|
|
849
849
|
onError: console.error,
|
|
850
850
|
});
|
|
851
851
|
```
|
|
@@ -866,7 +866,7 @@ With hooks:
|
|
|
866
866
|
|
|
867
867
|
```ts
|
|
868
868
|
await storeService.clear({
|
|
869
|
-
onSuccess: () => console.log(
|
|
869
|
+
onSuccess: () => console.log('cleared'),
|
|
870
870
|
onError: console.error,
|
|
871
871
|
});
|
|
872
872
|
```
|
|
@@ -1387,14 +1387,8 @@ interface CrudDocument {
|
|
|
1387
1387
|
### Code sample use
|
|
1388
1388
|
|
|
1389
1389
|
```typescript
|
|
1390
|
-
import { Injectable } from
|
|
1391
|
-
import {
|
|
1392
|
-
CoreService,
|
|
1393
|
-
HttpService,
|
|
1394
|
-
StoreService,
|
|
1395
|
-
CrudService,
|
|
1396
|
-
CrudDocument,
|
|
1397
|
-
} from "wacom";
|
|
1390
|
+
import { Injectable } from '@angular/core';
|
|
1391
|
+
import { CoreService, HttpService, StoreService, CrudService, CrudDocument } from 'wacom';
|
|
1398
1392
|
|
|
1399
1393
|
export interface Work extends CrudDocument {
|
|
1400
1394
|
name: string;
|
|
@@ -1402,7 +1396,7 @@ export interface Work extends CrudDocument {
|
|
|
1402
1396
|
}
|
|
1403
1397
|
|
|
1404
1398
|
@Injectable({
|
|
1405
|
-
providedIn:
|
|
1399
|
+
providedIn: 'root',
|
|
1406
1400
|
})
|
|
1407
1401
|
export class WorkService extends CrudService<Work> {
|
|
1408
1402
|
works: Work[] = this.getDocs();
|
|
@@ -1410,7 +1404,7 @@ export class WorkService extends CrudService<Work> {
|
|
|
1410
1404
|
constructor(_http: HttpService, _store: StoreService, _core: CoreService) {
|
|
1411
1405
|
super(
|
|
1412
1406
|
{
|
|
1413
|
-
name:
|
|
1407
|
+
name: 'work',
|
|
1414
1408
|
},
|
|
1415
1409
|
_http,
|
|
1416
1410
|
_store,
|
|
@@ -1477,26 +1471,26 @@ socketService.emit('message', { text: 'Hello, World!' });
|
|
|
1477
1471
|
### Usage Example
|
|
1478
1472
|
|
|
1479
1473
|
```typescript
|
|
1480
|
-
import { SocketService } from
|
|
1474
|
+
import { SocketService } from 'wacom';
|
|
1481
1475
|
|
|
1482
1476
|
@Component({
|
|
1483
|
-
selector:
|
|
1484
|
-
templateUrl:
|
|
1485
|
-
styleUrls: [
|
|
1477
|
+
selector: 'app-root',
|
|
1478
|
+
templateUrl: './app.component.html',
|
|
1479
|
+
styleUrls: ['./app.component.css'],
|
|
1486
1480
|
})
|
|
1487
1481
|
export class AppComponent {
|
|
1488
1482
|
constructor(private socketService: SocketService) {
|
|
1489
|
-
this.socketService.setUrl(
|
|
1490
|
-
this.socketService.on(
|
|
1491
|
-
console.log(
|
|
1483
|
+
this.socketService.setUrl('https://example.com');
|
|
1484
|
+
this.socketService.on('connect', () => {
|
|
1485
|
+
console.log('Connected to WebSocket');
|
|
1492
1486
|
});
|
|
1493
|
-
this.socketService.on(
|
|
1494
|
-
console.log(
|
|
1487
|
+
this.socketService.on('message', msg => {
|
|
1488
|
+
console.log('Received message:', msg);
|
|
1495
1489
|
});
|
|
1496
1490
|
}
|
|
1497
1491
|
|
|
1498
1492
|
sendMessage() {
|
|
1499
|
-
this.socketService.emit(
|
|
1493
|
+
this.socketService.emit('message', { text: 'Hello, World!' });
|
|
1500
1494
|
}
|
|
1501
1495
|
}
|
|
1502
1496
|
```
|
|
@@ -2150,7 +2144,7 @@ ngOnInit() {
|
|
|
2150
2144
|
}
|
|
2151
2145
|
```
|
|
2152
2146
|
|
|
2153
|
-
## [
|
|
2147
|
+
## [Translate Service](#translate-service)
|
|
2154
2148
|
|
|
2155
2149
|
Wacom includes a lightweight, signal-based runtime translation engine built for Angular Signals.
|
|
2156
2150
|
|
|
@@ -2166,13 +2160,13 @@ Unlike compile-time Angular i18n, this works fully at runtime.
|
|
|
2166
2160
|
|
|
2167
2161
|
---
|
|
2168
2162
|
|
|
2169
|
-
###
|
|
2163
|
+
### Translate model
|
|
2170
2164
|
|
|
2171
2165
|
```ts
|
|
2172
|
-
export interface
|
|
2173
|
-
sourceText: string;
|
|
2174
|
-
text: string;
|
|
2175
|
-
}
|
|
2166
|
+
export interface Translate {
|
|
2167
|
+
sourceText: string;
|
|
2168
|
+
text: string;
|
|
2169
|
+
}
|
|
2176
2170
|
```
|
|
2177
2171
|
|
|
2178
2172
|
Each `sourceText` acts as both:
|
|
@@ -2185,11 +2179,11 @@ Each `sourceText` acts as both:
|
|
|
2185
2179
|
### Basic usage (signal API)
|
|
2186
2180
|
|
|
2187
2181
|
```ts
|
|
2188
|
-
import {
|
|
2189
|
-
|
|
2190
|
-
private
|
|
2191
|
-
|
|
2192
|
-
title = this.
|
|
2182
|
+
import { TranslateService } from "wacom";
|
|
2183
|
+
|
|
2184
|
+
private _translateService = inject(TranslateService);
|
|
2185
|
+
|
|
2186
|
+
title = this._translateService.translate("Create project");
|
|
2193
2187
|
```
|
|
2194
2188
|
|
|
2195
2189
|
The returned value is a `WritableSignal<string>`.
|
|
@@ -2207,9 +2201,9 @@ automatically.
|
|
|
2207
2201
|
### Updating translations in bulk (language switch)
|
|
2208
2202
|
|
|
2209
2203
|
```ts
|
|
2210
|
-
this.
|
|
2211
|
-
{ sourceText:
|
|
2212
|
-
{ sourceText:
|
|
2204
|
+
this._translateService.setMany([
|
|
2205
|
+
{ sourceText: 'Create project', text: 'Створити проєкт' },
|
|
2206
|
+
{ sourceText: 'Save', text: 'Зберегти' },
|
|
2213
2207
|
]);
|
|
2214
2208
|
```
|
|
2215
2209
|
|
|
@@ -2224,9 +2218,9 @@ Behavior:
|
|
|
2224
2218
|
### Updating a single translation
|
|
2225
2219
|
|
|
2226
2220
|
```ts
|
|
2227
|
-
this.
|
|
2228
|
-
sourceText:
|
|
2229
|
-
text:
|
|
2221
|
+
this._translateService.setOne({
|
|
2222
|
+
sourceText: 'Save',
|
|
2223
|
+
text: 'Зберегти',
|
|
2230
2224
|
});
|
|
2231
2225
|
```
|
|
2232
2226
|
|
|
@@ -2269,7 +2263,7 @@ Optional explicit key:
|
|
|
2269
2263
|
|
|
2270
2264
|
### Persistence
|
|
2271
2265
|
|
|
2272
|
-
|
|
2266
|
+
Translate entries are automatically:
|
|
2273
2267
|
|
|
2274
2268
|
- hydrated from storage on startup
|
|
2275
2269
|
- synced after every update
|