orcas-angular 1.0.5 → 2.0.0
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/async/README.md +46 -0
- package/dev/README.md +41 -0
- package/fesm2022/orcas-angular.mjs +5 -6
- package/fesm2022/orcas-angular.mjs.map +1 -1
- package/framework/README.md +34 -0
- package/localization/README.md +74 -0
- package/log/README.md +275 -0
- package/navigation/README.md +47 -0
- package/package.json +1 -1
- package/storage/README.md +75 -0
- package/theme/README.md +44 -0
- package/types/orcas-angular.d.ts +3 -2
- package/ui/README.md +42 -0
package/async/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# async
|
|
2
|
+
|
|
3
|
+
Utilities for working with asynchronous operations.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
### `async.ts`
|
|
8
|
+
|
|
9
|
+
The `Async` class provides static helper methods for common async patterns:
|
|
10
|
+
|
|
11
|
+
- **`Async.delay(ms)`** — Returns a `Promise` that resolves after a given number of milliseconds. Useful for introducing deliberate pauses in async flows.
|
|
12
|
+
- **`Async.until(check, timeoutMs?, frequencyMs?)`** — Polls a condition function at a given interval until it returns `true`. Throws a `Error` if the timeout is exceeded. Defaults to a 10-second timeout and 100 ms polling frequency.
|
|
13
|
+
|
|
14
|
+
### `cancellation-token.ts`
|
|
15
|
+
|
|
16
|
+
Provides a cooperative cancellation mechanism inspired by .NET's `CancellationToken` pattern:
|
|
17
|
+
|
|
18
|
+
- **`CancellationToken`** *(interface)* — Read-only token that exposes `isCancelled()` and `throwIfCancelled()`. Passed to async operations to signal cancellation without forcing an abort.
|
|
19
|
+
- **`CancellationTokenSource`** — Owns and controls a `CancellationToken`. Call `cancel()` to signal cancellation, or `newUnique(timeoutMs?)` to cancel the previous token and issue a fresh one (optionally with an auto-cancel timeout).
|
|
20
|
+
- **`CancellationError`** — Error subclass thrown by `throwIfCancelled()` when cancellation has been requested.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Async } from '@/lib/orcas-angular/async/async';
|
|
26
|
+
import { CancellationTokenSource } from '@/lib/orcas-angular/async/cancellation-token';
|
|
27
|
+
|
|
28
|
+
// Delay example
|
|
29
|
+
await Async.delay(500);
|
|
30
|
+
|
|
31
|
+
// Poll until condition
|
|
32
|
+
await Async.until(() => someFlag === true);
|
|
33
|
+
|
|
34
|
+
// Cancellation example
|
|
35
|
+
const cts = new CancellationTokenSource();
|
|
36
|
+
const token = cts.newUnique(5000); // auto-cancels after 5 s
|
|
37
|
+
|
|
38
|
+
async function doWork() {
|
|
39
|
+
token.throwIfCancelled();
|
|
40
|
+
await Async.delay(100);
|
|
41
|
+
token.throwIfCancelled();
|
|
42
|
+
// ...
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cts.cancel(); // cancel from outside
|
|
46
|
+
```
|
package/dev/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# dev
|
|
2
|
+
|
|
3
|
+
Development and debugging utilities. These helpers are meant for use during development only and should not be shipped as core application services.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
### `console-hook.ts`
|
|
8
|
+
|
|
9
|
+
`ConsoleHook` exposes a lightweight command registry that can be invoked from the browser console. It registers a global `window.r(command, ...args)` function so that developers can call application methods without needing to open Angular DevTools.
|
|
10
|
+
|
|
11
|
+
**Methods:**
|
|
12
|
+
- **`ConsoleHook.initialize()`** — Sets up `window.r` if it has not been set up yet.
|
|
13
|
+
- **`ConsoleHook.register(commandName, method)`** — Registers a named command. Automatically calls `initialize()`.
|
|
14
|
+
- **`ConsoleHook.run(input, ...additionalParams)`** — Parses the input string (command name + space-separated arguments) and executes the matching registered command.
|
|
15
|
+
|
|
16
|
+
**Browser console usage:**
|
|
17
|
+
```javascript
|
|
18
|
+
// Call a registered command named "example" with no extra args
|
|
19
|
+
r("example")
|
|
20
|
+
|
|
21
|
+
// Call "myCommand" with arguments
|
|
22
|
+
r("myCommand arg1 arg2")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### `debug.service.ts.example`
|
|
26
|
+
|
|
27
|
+
A template showing how to integrate `ConsoleHook` into an Angular service. Copy this file, rename it to `debug.service.ts`, and adapt it to register the commands relevant to your application.
|
|
28
|
+
|
|
29
|
+
The example registers two commands:
|
|
30
|
+
- `"example"` — returns the injected `ExampleService` instance.
|
|
31
|
+
- `"nop"` — logs `"nop"` to the console and returns `"1"`.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { ConsoleHook } from '@/lib/orcas-angular/dev/console-hook';
|
|
37
|
+
|
|
38
|
+
// In any service or component constructor:
|
|
39
|
+
ConsoleHook.register('reload', () => location.reload());
|
|
40
|
+
ConsoleHook.register('clearStorage', () => localStorage.clear());
|
|
41
|
+
```
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, computed,
|
|
3
|
-
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Injectable, computed, signal, Pipe, InjectionToken, HostListener, Directive, inject, effect, input, booleanAttribute, output, ViewChild, Component } from '@angular/core';
|
|
4
3
|
import * as i1 from '@angular/router';
|
|
5
4
|
import { NavigationEnd } from '@angular/router';
|
|
6
5
|
import * as i2 from '@angular/common';
|
|
7
6
|
import { CommonModule } from '@angular/common';
|
|
7
|
+
import { HttpClient } from '@angular/common/http';
|
|
8
8
|
import { lastValueFrom } from 'rxjs';
|
|
9
9
|
|
|
10
10
|
class Async {
|
|
@@ -148,20 +148,19 @@ class LocalizationService {
|
|
|
148
148
|
loaded = false;
|
|
149
149
|
$language;
|
|
150
150
|
$currentLang = computed(() => this.$language(), ...(ngDevMode ? [{ debugName: "$currentLang" }] : []));
|
|
151
|
-
http = inject(HttpClient);
|
|
152
151
|
constructor() {
|
|
153
152
|
this.$language = signal(this.getStoredLanguage(), ...(ngDevMode ? [{ debugName: "$language" }] : []));
|
|
154
153
|
}
|
|
155
|
-
async init(
|
|
154
|
+
async init(translationsJson = '{}', defaultLanguage = 'en', storageKey = 'orcas-language') {
|
|
156
155
|
this.defaultLanguage = defaultLanguage;
|
|
157
156
|
this.storageKey = storageKey;
|
|
158
157
|
this.$language.set(this.getStoredLanguage());
|
|
159
158
|
try {
|
|
160
|
-
this.translations =
|
|
159
|
+
this.translations = JSON.parse(translationsJson);
|
|
161
160
|
this.loaded = true;
|
|
162
161
|
}
|
|
163
162
|
catch (err) {
|
|
164
|
-
console.error('Failed to
|
|
163
|
+
console.error('Failed to parse translations:', err);
|
|
165
164
|
}
|
|
166
165
|
}
|
|
167
166
|
getLanguage() {
|