ng-hub-ui-utils 1.1.0 → 22.1.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/README.md +199 -26
- package/fesm2022/ng-hub-ui-utils.mjs +593 -279
- package/fesm2022/ng-hub-ui-utils.mjs.map +1 -1
- package/ng-hub-ui-utils-22.1.0.tgz +0 -0
- package/package.json +7 -4
- package/{index.d.ts → types/ng-hub-ui-utils.d.ts} +213 -95
- package/ng-hub-ui-utils-1.1.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,30 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ng-hub-ui-utils
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/ng-hub-ui-utils)
|
|
4
4
|
[](LICENSE)
|
|
5
|
-
[](https://github.com/carlos-morcillo/ng-hub-ui/actions)
|
|
6
6
|
|
|
7
7
|
> Common utilities library for Angular, fundamental support for the Hub UI ecosystem.
|
|
8
8
|
|
|
9
9
|
[Español](./README.es.md) | **English**
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
11
|
+
## 📝 Description
|
|
12
|
+
|
|
13
|
+
`ng-hub-ui-utils` is the foundational utilities library for the entire Hub UI ecosystem. It provides a curated set of framework-agnostic helper functions, type guards, standalone Angular pipes, a flexible overlay/popup system, focus-trap and accessibility helpers, scrollbar compensation, a smooth transition engine, and a lightweight internationalization (i18n) system. It ships no visual components — instead it powers the shared low-level behavior used across the rest of the `ng-hub-ui` libraries, while remaining tree-shakable so you only bundle what you import.
|
|
14
|
+
|
|
15
|
+
## 📑 Table of Contents
|
|
16
|
+
|
|
17
|
+
- [Description](#-description)
|
|
18
|
+
- [Documentation and Live Examples](#-documentation-and-live-examples)
|
|
19
|
+
- [Library Family `ng-hub-ui`](#-library-family-ng-hub-ui)
|
|
20
|
+
- [Inspiration](#-inspiration)
|
|
21
|
+
- [Features](#-features)
|
|
22
|
+
- [Installation](#-installation)
|
|
23
|
+
- [Quick Start](#-quick-start)
|
|
24
|
+
- [Internationalization (i18n)](#-internationalization-i18n)
|
|
25
|
+
- [Utilities API](#-utilities-api)
|
|
26
|
+
- [Support Components](#-support-components)
|
|
27
|
+
- [Compatibility](#-compatibility)
|
|
28
|
+
- [Development](#-development)
|
|
29
|
+
- [Testing](#-testing)
|
|
30
|
+
- [Changelog](#-changelog)
|
|
31
|
+
- [Issues and Support](#-issues-and-support)
|
|
32
|
+
- [Support the Project](#-support-the-project)
|
|
33
|
+
- [Contributions](#-contributions)
|
|
34
|
+
- [License](#-license)
|
|
35
|
+
|
|
36
|
+
## 📚 Documentation and Live Examples
|
|
37
|
+
|
|
38
|
+
This package is part of [Hub UI](https://hubui.dev/), a collection of Angular component libraries for standalone apps.
|
|
39
|
+
|
|
40
|
+
- Docs: https://hubui.dev/utils/overview/
|
|
41
|
+
- Live examples: https://hubui.dev/utils/examples/
|
|
42
|
+
- Hub UI: https://hubui.dev/
|
|
43
|
+
|
|
44
|
+
## 🧩 Library Family `ng-hub-ui`
|
|
45
|
+
|
|
46
|
+
This library is part of the **ng-hub-ui** ecosystem:
|
|
47
|
+
|
|
48
|
+
- [**ng-hub-ui-accordion**](https://www.npmjs.com/package/ng-hub-ui-accordion) (deprecated — use ng-hub-ui-panels)
|
|
49
|
+
- [**ng-hub-ui-action-sheet**](https://www.npmjs.com/package/ng-hub-ui-action-sheet)
|
|
50
|
+
- [**ng-hub-ui-avatar**](https://www.npmjs.com/package/ng-hub-ui-avatar)
|
|
51
|
+
- [**ng-hub-ui-board**](https://www.npmjs.com/package/ng-hub-ui-board)
|
|
52
|
+
- [**ng-hub-ui-breadcrumbs**](https://www.npmjs.com/package/ng-hub-ui-breadcrumbs)
|
|
53
|
+
- [**ng-hub-ui-calendar**](https://www.npmjs.com/package/ng-hub-ui-calendar)
|
|
54
|
+
- [**ng-hub-ui-dropdown**](https://www.npmjs.com/package/ng-hub-ui-dropdown)
|
|
55
|
+
- [**ng-hub-ui-ds**](https://www.npmjs.com/package/ng-hub-ui-ds)
|
|
56
|
+
- [**ng-hub-ui-forms**](https://www.npmjs.com/package/ng-hub-ui-forms)
|
|
57
|
+
- [**ng-hub-ui-history**](https://www.npmjs.com/package/ng-hub-ui-history)
|
|
58
|
+
- [**ng-hub-ui-milestones**](https://www.npmjs.com/package/ng-hub-ui-milestones)
|
|
59
|
+
- [**ng-hub-ui-modal**](https://www.npmjs.com/package/ng-hub-ui-modal)
|
|
60
|
+
- [**ng-hub-ui-nav**](https://www.npmjs.com/package/ng-hub-ui-nav)
|
|
61
|
+
- [**ng-hub-ui-paginable**](https://www.npmjs.com/package/ng-hub-ui-paginable)
|
|
62
|
+
- [**ng-hub-ui-panels**](https://www.npmjs.com/package/ng-hub-ui-panels)
|
|
63
|
+
- [**ng-hub-ui-portal**](https://www.npmjs.com/package/ng-hub-ui-portal)
|
|
64
|
+
- [**ng-hub-ui-skeleton**](https://www.npmjs.com/package/ng-hub-ui-skeleton)
|
|
65
|
+
- [**ng-hub-ui-sortable**](https://www.npmjs.com/package/ng-hub-ui-sortable)
|
|
66
|
+
- [**ng-hub-ui-stepper**](https://www.npmjs.com/package/ng-hub-ui-stepper)
|
|
67
|
+
- [**ng-hub-ui-utils**](https://www.npmjs.com/package/ng-hub-ui-utils) ← You are here
|
|
28
68
|
|
|
29
69
|
## 💡 Inspiration
|
|
30
70
|
|
|
@@ -150,6 +190,45 @@ hubRunTransition(
|
|
|
150
190
|
});
|
|
151
191
|
```
|
|
152
192
|
|
|
193
|
+
### 🌐 Internationalization (i18n)
|
|
194
|
+
|
|
195
|
+
Lightweight, dependency-injection based translation system with a reactive pipe. Register translation dictionaries at bootstrap with `provideHubTranslation`, then translate keys in templates with the `translate` pipe.
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { provideHubTranslation, HubTranslationService, TranslatePipe } from 'ng-hub-ui-utils';
|
|
199
|
+
|
|
200
|
+
// In your application config / bootstrap providers
|
|
201
|
+
bootstrapApplication(AppComponent, {
|
|
202
|
+
providers: [
|
|
203
|
+
provideHubTranslation({
|
|
204
|
+
language: 'en',
|
|
205
|
+
fallbackLanguage: 'en',
|
|
206
|
+
dictionaries: {
|
|
207
|
+
en: { greeting: 'Hello {name}!' },
|
|
208
|
+
es: { greeting: '¡Hola {name}!' }
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
]
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
@Component({
|
|
217
|
+
standalone: true,
|
|
218
|
+
imports: [TranslatePipe],
|
|
219
|
+
template: `
|
|
220
|
+
<!-- Simple key -->
|
|
221
|
+
<p>{{ 'greeting' | translate }}</p>
|
|
222
|
+
|
|
223
|
+
<!-- With interpolation params -->
|
|
224
|
+
<p>{{ 'greeting' | translate: { name: 'Carlos' } }}</p>
|
|
225
|
+
`
|
|
226
|
+
})
|
|
227
|
+
export class ExampleComponent {}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
See [Internationalization (i18n)](#-internationalization-i18n) for the full API.
|
|
231
|
+
|
|
153
232
|
### 🧰 Standalone Angular Pipes
|
|
154
233
|
|
|
155
234
|
Complete set of utility pipes for validation, transformation, and data manipulation.
|
|
@@ -324,6 +403,91 @@ export class ExampleComponent {
|
|
|
324
403
|
}
|
|
325
404
|
```
|
|
326
405
|
|
|
406
|
+
## 🌐 Internationalization (i18n)
|
|
407
|
+
|
|
408
|
+
The i18n system (available since `v1.2.0`) lets you register translation dictionaries via dependency injection and resolve keys reactively in templates. Updating the active translations at runtime automatically refreshes any `translate` pipe in the view.
|
|
409
|
+
|
|
410
|
+
### `provideHubTranslation(config?)`
|
|
411
|
+
|
|
412
|
+
Environment provider helper that registers `HubTranslationService` and its configuration. Call it once in your application bootstrap providers.
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
function provideHubTranslation(config?: HubTranslationConfig): EnvironmentProviders;
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### `HubTranslationConfig`
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
interface HubTranslationConfig {
|
|
422
|
+
/** Map of language code → translation dictionary. */
|
|
423
|
+
dictionaries?: Record<string, Record<string, any>>;
|
|
424
|
+
/** Active language code (defaults to fallbackLanguage, then 'en'). */
|
|
425
|
+
language?: string;
|
|
426
|
+
/** Fallback language merged under the active language (defaults to 'en'). */
|
|
427
|
+
fallbackLanguage?: string;
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
The configuration is also exposed through the `HUB_TRANSLATION_CONFIG` injection token for advanced scenarios.
|
|
432
|
+
|
|
433
|
+
### `HubTranslationService`
|
|
434
|
+
|
|
435
|
+
Injectable service that holds the active translations and notifies subscribers when they change.
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
@Injectable()
|
|
439
|
+
class HubTranslationService {
|
|
440
|
+
/** Currently active flat translations map. */
|
|
441
|
+
translations: Record<string, string>;
|
|
442
|
+
/** Emits whenever the active translations are updated. */
|
|
443
|
+
translationObserver: Observable<Record<string, string>>;
|
|
444
|
+
|
|
445
|
+
/** Resolves a key (supports dot notation) against the active translations. */
|
|
446
|
+
getTranslation(key: string): any;
|
|
447
|
+
/** Replaces the active translations, merging them over the fallback dictionary. */
|
|
448
|
+
setTranslations(translations?: Record<string, string>): void;
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
import { HubTranslationService } from 'ng-hub-ui-utils';
|
|
454
|
+
|
|
455
|
+
@Component({ /* ... */ })
|
|
456
|
+
export class LanguageSwitcherComponent {
|
|
457
|
+
private translationSvc = inject(HubTranslationService);
|
|
458
|
+
|
|
459
|
+
switchToSpanish() {
|
|
460
|
+
// Swap the active dictionary at runtime; the `translate` pipe updates automatically.
|
|
461
|
+
this.translationSvc.setTranslations({ greeting: '¡Hola {name}!' });
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### `TranslatePipe` (`translate`)
|
|
467
|
+
|
|
468
|
+
Impure standalone pipe that resolves a translation key with optional interpolation params. It subscribes to the service so the view stays in sync when translations change.
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
// Simple key
|
|
472
|
+
{{ 'greeting' | translate }}
|
|
473
|
+
|
|
474
|
+
// With an object of interpolation params
|
|
475
|
+
{{ 'greeting' | translate: { name: 'Carlos' } }}
|
|
476
|
+
|
|
477
|
+
// Params can also be written inline as a pseudo-object string
|
|
478
|
+
{{ 'greeting' | translate: "{name: 'Carlos'}" }}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
If a key has no matching translation, the key itself is returned. Interpolation tokens use the `{paramName}` syntax (powered by the `interpolateString` utility).
|
|
482
|
+
|
|
483
|
+
### Supporting utilities
|
|
484
|
+
|
|
485
|
+
These functions back the i18n system and are exported for direct use:
|
|
486
|
+
|
|
487
|
+
- `getValue(target: any, key: string): any` - Reads a nested value by dot-notation key.
|
|
488
|
+
- `interpolateString(text: string, params?: object): string` - Replaces `{token}` placeholders in a string.
|
|
489
|
+
- `equals(o1: any, o2: any): boolean` - Deep equality check used to memoize the pipe value.
|
|
490
|
+
|
|
327
491
|
## 📊 Utilities API
|
|
328
492
|
|
|
329
493
|
### Conversion Functions
|
|
@@ -463,17 +627,17 @@ This library doesn't include visual components, but support utilities used by ot
|
|
|
463
627
|
|
|
464
628
|
| Utility | Description | Used by |
|
|
465
629
|
| --------------- | ----------------------------------- | -------------------------------------- |
|
|
466
|
-
| Overlay Service | Flexible overlay positioning system | ng-hub-ui-
|
|
467
|
-
| Focus Trap | Focus management in modals/overlays | ng-hub-ui-modal, ng-hub-ui-
|
|
630
|
+
| Overlay Service | Flexible overlay positioning system | ng-hub-ui-modal, ng-hub-ui-portal |
|
|
631
|
+
| Focus Trap | Focus management in modals/overlays | ng-hub-ui-modal, ng-hub-ui-portal |
|
|
468
632
|
| Scrollbar | Scrollbar compensation | ng-hub-ui-modal, ng-hub-ui-portal |
|
|
469
633
|
| Popup Service | Base class for popup components | ng-hub-ui-modal, ng-hub-ui-portal |
|
|
470
634
|
| Transitions | Smooth animations | ng-hub-ui-accordion, ng-hub-ui-modal |
|
|
471
|
-
| Type Guards | Type validation functions | ng-hub-ui-
|
|
635
|
+
| Type Guards | Type validation functions | ng-hub-ui-stepper |
|
|
472
636
|
| Pipes | Template utilities | All Hub UI components |
|
|
473
637
|
|
|
474
638
|
## 🤝 Compatibility
|
|
475
639
|
|
|
476
|
-
- Angular
|
|
640
|
+
- Angular 16+
|
|
477
641
|
- TypeScript 4.8+
|
|
478
642
|
- Node.js 16+
|
|
479
643
|
- Browsers: Chrome 90+, Firefox 88+, Safari 14+, Edge 90+
|
|
@@ -530,11 +694,20 @@ describe('ng-hub-ui-utils', () => {
|
|
|
530
694
|
});
|
|
531
695
|
```
|
|
532
696
|
|
|
697
|
+
## 📋 Changelog
|
|
698
|
+
|
|
699
|
+
All notable changes are documented in the [CHANGELOG.md](./CHANGELOG.md), following [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
700
|
+
|
|
701
|
+
Recent highlights:
|
|
702
|
+
|
|
703
|
+
- **1.2.1** — Renamed internal i18n files and refreshed `TranslatePipe`; added a test suite for `HubTranslationService`.
|
|
704
|
+
- **1.2.0** — Added the i18n system (`HubTranslationService`, `provideHubTranslation`, `TranslatePipe`, translation tokens) plus the `equals`, `interpolateString` and `getValue` utilities.
|
|
705
|
+
|
|
533
706
|
## 🐛 Issues and Support
|
|
534
707
|
|
|
535
708
|
- [Report a bug](https://github.com/carlos-morcillo/ng-hub-ui-utils/issues)
|
|
536
709
|
- [Request a feature](https://github.com/carlos-morcillo/ng-hub-ui-utils/issues/new?template=feature_request.md)
|
|
537
|
-
- [
|
|
710
|
+
- [Repository](https://github.com/carlos-morcillo/ng-hub-ui-utils)
|
|
538
711
|
|
|
539
712
|
## ☕ Support the Project
|
|
540
713
|
|
|
@@ -564,7 +737,7 @@ Check our [contribution guidelines](CONTRIBUTING.md) for more details.
|
|
|
564
737
|
|
|
565
738
|
## 📄 License
|
|
566
739
|
|
|
567
|
-
MIT ©
|
|
740
|
+
MIT © Hub UI contributors
|
|
568
741
|
|
|
569
742
|
```
|
|
570
743
|
MIT License
|
|
@@ -594,4 +767,4 @@ SOFTWARE.
|
|
|
594
767
|
|
|
595
768
|
⭐ **If you like this project, don't forget to give it a star on GitHub!**
|
|
596
769
|
|
|
597
|
-
[](https://github.com/carlos-morcillo/ng-hub-ui)
|