@tectra-ng/utils 0.0.1 → 0.2.1
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/LICENSE +21 -0
- package/README.md +40 -1
- package/auto-focus/README.md +19 -0
- package/breakpoint/README.md +23 -0
- package/clipboard/README.md +37 -0
- package/clock/README.md +21 -0
- package/currency/README.md +17 -0
- package/date/README.md +46 -0
- package/debounce-input/README.md +31 -0
- package/drag-scroll/README.md +25 -0
- package/fesm2022/tectra-ng-utils-auto-focus.mjs +100 -0
- package/fesm2022/tectra-ng-utils-auto-focus.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-breakpoint.mjs +54 -0
- package/fesm2022/tectra-ng-utils-breakpoint.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-clipboard.mjs +225 -0
- package/fesm2022/tectra-ng-utils-clipboard.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-clock.mjs +59 -0
- package/fesm2022/tectra-ng-utils-clock.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-currency.mjs +63 -0
- package/fesm2022/tectra-ng-utils-currency.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-date.mjs +200 -0
- package/fesm2022/tectra-ng-utils-date.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-debounce-input.mjs +156 -0
- package/fesm2022/tectra-ng-utils-debounce-input.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-drag-scroll.mjs +199 -0
- package/fesm2022/tectra-ng-utils-drag-scroll.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-file.mjs +78 -0
- package/fesm2022/tectra-ng-utils-file.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-filter-state.mjs +238 -0
- package/fesm2022/tectra-ng-utils-filter-state.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-filter.mjs +88 -0
- package/fesm2022/tectra-ng-utils-filter.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-form-changes.mjs +70 -0
- package/fesm2022/tectra-ng-utils-form-changes.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-form-validation.mjs +162 -0
- package/fesm2022/tectra-ng-utils-form-validation.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-go-back.mjs +117 -0
- package/fesm2022/tectra-ng-utils-go-back.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-http.mjs +189 -0
- package/fesm2022/tectra-ng-utils-http.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-in-view.mjs +297 -0
- package/fesm2022/tectra-ng-utils-in-view.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-plural.mjs +98 -0
- package/fesm2022/tectra-ng-utils-plural.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-polling.mjs +109 -0
- package/fesm2022/tectra-ng-utils-polling.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-random.mjs +20 -0
- package/fesm2022/tectra-ng-utils-random.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-relative-time.mjs +87 -0
- package/fesm2022/tectra-ng-utils-relative-time.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-scroll-end.mjs +136 -0
- package/fesm2022/tectra-ng-utils-scroll-end.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-selection.mjs +52 -0
- package/fesm2022/tectra-ng-utils-selection.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-stop-propagation.mjs +92 -0
- package/fesm2022/tectra-ng-utils-stop-propagation.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-stream.mjs +30 -0
- package/fesm2022/tectra-ng-utils-stream.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-style-class.mjs +350 -0
- package/fesm2022/tectra-ng-utils-style-class.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-text.mjs +173 -0
- package/fesm2022/tectra-ng-utils-text.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-title.mjs +99 -0
- package/fesm2022/tectra-ng-utils-title.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-validators.mjs +232 -0
- package/fesm2022/tectra-ng-utils-validators.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils.mjs +4 -0
- package/fesm2022/tectra-ng-utils.mjs.map +1 -0
- package/file/README.md +19 -0
- package/filter/README.md +22 -0
- package/filter-state/README.md +36 -0
- package/form-changes/README.md +26 -0
- package/form-validation/README.md +40 -0
- package/go-back/README.md +28 -0
- package/http/README.md +34 -0
- package/in-view/README.md +34 -0
- package/package.json +173 -3
- package/plural/README.md +21 -0
- package/polling/README.md +34 -0
- package/random/README.md +10 -0
- package/relative-time/README.md +29 -0
- package/scroll-end/README.md +25 -0
- package/selection/README.md +24 -0
- package/stop-propagation/README.md +15 -0
- package/stream/README.md +14 -0
- package/style-class/README.md +34 -0
- package/text/README.md +25 -0
- package/title/README.md +26 -0
- package/types/tectra-ng-utils-auto-focus.d.ts +22 -0
- package/types/tectra-ng-utils-auto-focus.d.ts.map +1 -0
- package/types/tectra-ng-utils-breakpoint.d.ts +15 -0
- package/types/tectra-ng-utils-breakpoint.d.ts.map +1 -0
- package/types/tectra-ng-utils-clipboard.d.ts +48 -0
- package/types/tectra-ng-utils-clipboard.d.ts.map +1 -0
- package/types/tectra-ng-utils-clock.d.ts +18 -0
- package/types/tectra-ng-utils-clock.d.ts.map +1 -0
- package/types/tectra-ng-utils-currency.d.ts +11 -0
- package/types/tectra-ng-utils-currency.d.ts.map +1 -0
- package/types/tectra-ng-utils-date.d.ts +65 -0
- package/types/tectra-ng-utils-date.d.ts.map +1 -0
- package/types/tectra-ng-utils-debounce-input.d.ts +38 -0
- package/types/tectra-ng-utils-debounce-input.d.ts.map +1 -0
- package/types/tectra-ng-utils-drag-scroll.d.ts +41 -0
- package/types/tectra-ng-utils-drag-scroll.d.ts.map +1 -0
- package/types/tectra-ng-utils-file.d.ts +18 -0
- package/types/tectra-ng-utils-file.d.ts.map +1 -0
- package/types/tectra-ng-utils-filter-state.d.ts +55 -0
- package/types/tectra-ng-utils-filter-state.d.ts.map +1 -0
- package/types/tectra-ng-utils-filter.d.ts +21 -0
- package/types/tectra-ng-utils-filter.d.ts.map +1 -0
- package/types/tectra-ng-utils-form-changes.d.ts +22 -0
- package/types/tectra-ng-utils-form-changes.d.ts.map +1 -0
- package/types/tectra-ng-utils-form-validation.d.ts +45 -0
- package/types/tectra-ng-utils-form-validation.d.ts.map +1 -0
- package/types/tectra-ng-utils-go-back.d.ts +25 -0
- package/types/tectra-ng-utils-go-back.d.ts.map +1 -0
- package/types/tectra-ng-utils-http.d.ts +47 -0
- package/types/tectra-ng-utils-http.d.ts.map +1 -0
- package/types/tectra-ng-utils-in-view.d.ts +80 -0
- package/types/tectra-ng-utils-in-view.d.ts.map +1 -0
- package/types/tectra-ng-utils-plural.d.ts +21 -0
- package/types/tectra-ng-utils-plural.d.ts.map +1 -0
- package/types/tectra-ng-utils-polling.d.ts +61 -0
- package/types/tectra-ng-utils-polling.d.ts.map +1 -0
- package/types/tectra-ng-utils-random.d.ts +4 -0
- package/types/tectra-ng-utils-random.d.ts.map +1 -0
- package/types/tectra-ng-utils-relative-time.d.ts +22 -0
- package/types/tectra-ng-utils-relative-time.d.ts.map +1 -0
- package/types/tectra-ng-utils-scroll-end.d.ts +38 -0
- package/types/tectra-ng-utils-scroll-end.d.ts.map +1 -0
- package/types/tectra-ng-utils-selection.d.ts +21 -0
- package/types/tectra-ng-utils-selection.d.ts.map +1 -0
- package/types/tectra-ng-utils-stop-propagation.d.ts +22 -0
- package/types/tectra-ng-utils-stop-propagation.d.ts.map +1 -0
- package/types/tectra-ng-utils-stream.d.ts +3 -0
- package/types/tectra-ng-utils-stream.d.ts.map +1 -0
- package/types/tectra-ng-utils-style-class.d.ts +91 -0
- package/types/tectra-ng-utils-style-class.d.ts.map +1 -0
- package/types/tectra-ng-utils-text.d.ts +26 -0
- package/types/tectra-ng-utils-text.d.ts.map +1 -0
- package/types/tectra-ng-utils-title.d.ts +31 -0
- package/types/tectra-ng-utils-title.d.ts.map +1 -0
- package/types/tectra-ng-utils-validators.d.ts +67 -0
- package/types/tectra-ng-utils-validators.d.ts.map +1 -0
- package/types/tectra-ng-utils.d.ts +2 -0
- package/types/tectra-ng-utils.d.ts.map +1 -0
- package/validators/README.md +42 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { DestroyRef, Injectable, InjectionToken, inject } from "@angular/core";
|
|
3
|
+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
4
|
+
import { Title } from "@angular/platform-browser";
|
|
5
|
+
import { TitleStrategy } from "@angular/router";
|
|
6
|
+
import { BehaviorSubject, combineLatest, filter, isObservable, of, switchMap } from "rxjs";
|
|
7
|
+
const TX_TITLE_CONFIG = new InjectionToken("TX_TITLE_CONFIG");
|
|
8
|
+
var TxTitle = class TxTitle {
|
|
9
|
+
title = inject(Title);
|
|
10
|
+
config = inject(TX_TITLE_CONFIG);
|
|
11
|
+
page$ = new BehaviorSubject(void 0);
|
|
12
|
+
prefix$ = new BehaviorSubject("");
|
|
13
|
+
touched = false;
|
|
14
|
+
constructor() {
|
|
15
|
+
combineLatest([this.page$.pipe(switchMap((page) => this.translate(page))), this.prefix$]).pipe(filter(() => this.touched), takeUntilDestroyed(inject(DestroyRef))).subscribe(([page, prefix]) => {
|
|
16
|
+
const separator = this.config.separator ?? " · ";
|
|
17
|
+
const title = page ? `${page}${separator}${this.config.appName}` : this.config.appName;
|
|
18
|
+
this.title.setTitle(prefix ? `${prefix} ${title}` : title);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
setPage(page) {
|
|
22
|
+
this.touched = true;
|
|
23
|
+
this.page$.next(page);
|
|
24
|
+
}
|
|
25
|
+
setPrefix(prefix) {
|
|
26
|
+
this.touched = true;
|
|
27
|
+
this.prefix$.next(prefix);
|
|
28
|
+
}
|
|
29
|
+
translate(page) {
|
|
30
|
+
if (!page || !this.config.translate) return of(page);
|
|
31
|
+
const translated = this.config.translate(page);
|
|
32
|
+
return isObservable(translated) ? translated : of(translated);
|
|
33
|
+
}
|
|
34
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
35
|
+
minVersion: "12.0.0",
|
|
36
|
+
version: "22.2.3",
|
|
37
|
+
ngImport: i0,
|
|
38
|
+
type: TxTitle,
|
|
39
|
+
deps: [],
|
|
40
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
41
|
+
});
|
|
42
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
43
|
+
minVersion: "12.0.0",
|
|
44
|
+
version: "22.2.3",
|
|
45
|
+
ngImport: i0,
|
|
46
|
+
type: TxTitle
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
50
|
+
minVersion: "12.0.0",
|
|
51
|
+
version: "22.2.3",
|
|
52
|
+
ngImport: i0,
|
|
53
|
+
type: TxTitle,
|
|
54
|
+
decorators: [{ type: Injectable }],
|
|
55
|
+
ctorParameters: () => []
|
|
56
|
+
});
|
|
57
|
+
var TxTitleStrategy = class TxTitleStrategy extends TitleStrategy {
|
|
58
|
+
txTitle = inject(TxTitle);
|
|
59
|
+
updateTitle(snapshot) {
|
|
60
|
+
this.txTitle.setPage(this.buildTitle(snapshot));
|
|
61
|
+
}
|
|
62
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
63
|
+
minVersion: "12.0.0",
|
|
64
|
+
version: "22.2.3",
|
|
65
|
+
ngImport: i0,
|
|
66
|
+
type: TxTitleStrategy,
|
|
67
|
+
deps: null,
|
|
68
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
69
|
+
});
|
|
70
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
71
|
+
minVersion: "12.0.0",
|
|
72
|
+
version: "22.2.3",
|
|
73
|
+
ngImport: i0,
|
|
74
|
+
type: TxTitleStrategy
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
78
|
+
minVersion: "12.0.0",
|
|
79
|
+
version: "22.2.3",
|
|
80
|
+
ngImport: i0,
|
|
81
|
+
type: TxTitleStrategy,
|
|
82
|
+
decorators: [{ type: Injectable }]
|
|
83
|
+
});
|
|
84
|
+
function provideTxTitle(config) {
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
provide: TX_TITLE_CONFIG,
|
|
88
|
+
useValue: config
|
|
89
|
+
},
|
|
90
|
+
TxTitle,
|
|
91
|
+
{
|
|
92
|
+
provide: TitleStrategy,
|
|
93
|
+
useClass: TxTitleStrategy
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
export { TX_TITLE_CONFIG, TxTitle, TxTitleStrategy, provideTxTitle };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=tectra-ng-utils-title.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-title.mjs","names":[],"sources":["../../../../packages/utils/title/src/title.ts"],"sourcesContent":["import { DestroyRef, Injectable, InjectionToken, Provider, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { Title } from '@angular/platform-browser';\nimport { RouterStateSnapshot, TitleStrategy } from '@angular/router';\nimport { BehaviorSubject, Observable, combineLatest, filter, isObservable, of, switchMap } from 'rxjs';\n\nexport interface TxTitleConfig {\n appName: string;\n separator?: string;\n translate?: (page: string) => string | Observable<string>;\n}\n\nexport const TX_TITLE_CONFIG = new InjectionToken<TxTitleConfig>('TX_TITLE_CONFIG');\n\n@Injectable()\nexport class TxTitle {\n private readonly title = inject(Title);\n private readonly config = inject(TX_TITLE_CONFIG);\n private readonly page$ = new BehaviorSubject<string | undefined>(undefined);\n private readonly prefix$ = new BehaviorSubject<string>('');\n private touched = false;\n\n constructor() {\n combineLatest([this.page$.pipe(switchMap((page) => this.translate(page))), this.prefix$])\n .pipe(\n filter(() => this.touched),\n takeUntilDestroyed(inject(DestroyRef)),\n )\n .subscribe(([page, prefix]) => {\n const separator = this.config.separator ?? ' · ';\n const title = page ? `${page}${separator}${this.config.appName}` : this.config.appName;\n this.title.setTitle(prefix ? `${prefix} ${title}` : title);\n });\n }\n\n setPage(page: string | undefined): void {\n this.touched = true;\n this.page$.next(page);\n }\n\n setPrefix(prefix: string): void {\n this.touched = true;\n this.prefix$.next(prefix);\n }\n\n private translate(page: string | undefined): Observable<string | undefined> {\n if (!page || !this.config.translate) {\n return of(page);\n }\n const translated = this.config.translate(page);\n return isObservable(translated) ? translated : of(translated);\n }\n}\n\n@Injectable()\nexport class TxTitleStrategy extends TitleStrategy {\n private readonly txTitle = inject(TxTitle);\n\n override updateTitle(snapshot: RouterStateSnapshot): void {\n this.txTitle.setPage(this.buildTitle(snapshot));\n }\n}\n\nexport function provideTxTitle(config: TxTitleConfig): Provider[] {\n return [{ provide: TX_TITLE_CONFIG, useValue: config }, TxTitle, { provide: TitleStrategy, useClass: TxTitleStrategy }];\n}\n"],"mappings":";;;;;;AAYA,MAAa,kBAAkB,IAAI,eAA8B,iBAAiB;AAGlF,IAAa,UAAb,MAAa,QAAO;CACD,QAAQ,OAAO,KAAK;CACpB,SAAS,OAAO,eAAe;CAC/B,QAAQ,IAAI,gBAAoC,MAAS;CACzD,UAAU,IAAI,gBAAwB,EAAE;CACjD,UAAU;CAElB,cAAA;EACE,cAAc,CAAC,KAAK,MAAM,KAAK,WAAW,SAAS,KAAK,UAAU,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CACtF,KACC,aAAa,KAAK,OAAO,GACzB,mBAAmB,OAAO,UAAU,CAAC,CAAC,CACvC,CACA,WAAW,CAAC,MAAM,YAAW;GAC5B,MAAM,YAAY,KAAK,OAAO,aAAa;GAC3C,MAAM,QAAQ,OAAO,GAAG,OAAO,YAAY,KAAK,OAAO,YAAY,KAAK,OAAO;GAC/E,KAAK,MAAM,SAAS,SAAS,GAAG,OAAM,GAAI,UAAU,KAAK;EAC3D,CAAC;CACL;CAEA,QAA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E,SAAS;GAAe,UAAU;EAAe;CAAE;AACxH"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { FormArray } from "@angular/forms";
|
|
2
|
+
const TX_DOMAIN_PATTERN = "^\\s*([a-zA-Z\\u0400-\\u04FF0-9]{1,63}(-+[a-zA-Z\\u0400-\\u04FF0-9]{1,63})*\\.)+(xn--[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,57}[a-zA-Z0-9])?|[a-zA-Z\\u0400-\\u04FF]{2,63})\\.?\\s*$";
|
|
3
|
+
const DOMAIN = new RegExp(TX_DOMAIN_PATTERN);
|
|
4
|
+
const PRICE = /^\d{1,12}([.,]\d{1,2})?$/;
|
|
5
|
+
const TIME_24 = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
6
|
+
const ISO_DATE = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
7
|
+
const IPV4_PART = "(?:25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)";
|
|
8
|
+
const IPV4 = new RegExp(`^(?:${IPV4_PART}\\.){3}${IPV4_PART}$`);
|
|
9
|
+
const IPV4_CIDR = new RegExp(`^(?:${IPV4_PART}\\.){3}${IPV4_PART}(?:\\/(?:[0-9]|[12][0-9]|3[0-2]))?$`);
|
|
10
|
+
const IPV6_CHARS = /^[0-9a-fA-F:.]+$/;
|
|
11
|
+
const CONTROL_CHAR_MAX_CODE = 31;
|
|
12
|
+
const DELETE_CHAR_CODE = 127;
|
|
13
|
+
const UNSAFE_CHARS = ["<", ">"];
|
|
14
|
+
const isEmpty = (value) => value === null || value === void 0 || typeof value === "string" && value.trim() === "" || Array.isArray(value) && value.length === 0;
|
|
15
|
+
const text = (value) => (value ?? "").toString().trim();
|
|
16
|
+
function isIpv6(value) {
|
|
17
|
+
if (!value.includes(":") || !IPV6_CHARS.test(value)) return false;
|
|
18
|
+
try {
|
|
19
|
+
return !!new URL(`http://[${value}]`).hostname;
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function parsePrice(value) {
|
|
25
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
26
|
+
if (typeof value !== "string" || !PRICE.test(value.trim())) return null;
|
|
27
|
+
return Number(value.trim().replace(",", "."));
|
|
28
|
+
}
|
|
29
|
+
function numericCode(length = 6) {
|
|
30
|
+
const pattern = new RegExp(`^\\d{${length}}$`);
|
|
31
|
+
return (control) => isEmpty(control.value) || pattern.test(String(control.value)) ? null : { invalidCodeFormat: { length } };
|
|
32
|
+
}
|
|
33
|
+
function isoDate() {
|
|
34
|
+
return (control) => {
|
|
35
|
+
const value = control.value;
|
|
36
|
+
if (isEmpty(value)) return null;
|
|
37
|
+
if (typeof value === "string" && ISO_DATE.test(value)) {
|
|
38
|
+
const [year, month, day] = value.split("-").map(Number);
|
|
39
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
40
|
+
if (date.getUTCFullYear() === year && date.getUTCMonth() + 1 === month && date.getUTCDate() === day) return null;
|
|
41
|
+
}
|
|
42
|
+
return { invalidDate: true };
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function futureDate() {
|
|
46
|
+
return (control) => {
|
|
47
|
+
if (isEmpty(control.value)) return null;
|
|
48
|
+
const now = /* @__PURE__ */ new Date();
|
|
49
|
+
now.setSeconds(0, 0);
|
|
50
|
+
const value = new Date(control.value);
|
|
51
|
+
if (Number.isNaN(value.getTime())) return { invalidDate: true };
|
|
52
|
+
value.setSeconds(0, 0);
|
|
53
|
+
return value < now ? { pastDate: true } : null;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function url(options = {}) {
|
|
57
|
+
const { https = true, host } = options;
|
|
58
|
+
return (control) => {
|
|
59
|
+
const value = text(control.value);
|
|
60
|
+
if (!value) return null;
|
|
61
|
+
try {
|
|
62
|
+
const parsed = new URL(value);
|
|
63
|
+
const protocolOk = https ? parsed.protocol === "https:" : parsed.protocol === "https:" || parsed.protocol === "http:";
|
|
64
|
+
const hostOk = !host || (typeof host === "string" ? parsed.hostname === host || parsed.hostname.endsWith(`.${host}`) : host.test(parsed.hostname));
|
|
65
|
+
return protocolOk && hostOk && !/\s/.test(value) ? null : { invalidUrl: true };
|
|
66
|
+
} catch {
|
|
67
|
+
return { invalidUrl: true };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function strongPassword(options = {}) {
|
|
72
|
+
const { minLength = 6, upper = true, lower = true, digit = false, symbol = true } = options;
|
|
73
|
+
return (control) => {
|
|
74
|
+
const value = control.value;
|
|
75
|
+
if (isEmpty(value)) return null;
|
|
76
|
+
const password = String(value);
|
|
77
|
+
const missing = [
|
|
78
|
+
password.length < minLength && "length",
|
|
79
|
+
upper && !/\p{Lu}/u.test(password) && "upper",
|
|
80
|
+
lower && !/\p{Ll}/u.test(password) && "lower",
|
|
81
|
+
digit && !/\p{N}/u.test(password) && "digit",
|
|
82
|
+
symbol && !/[^\p{L}\p{N}\s]/u.test(password) && "symbol"
|
|
83
|
+
].filter((item) => !!item);
|
|
84
|
+
return missing.length ? { weakPassword: {
|
|
85
|
+
minLength,
|
|
86
|
+
missing
|
|
87
|
+
} } : null;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function matchFields(field, confirmField, errorKey = "mismatch") {
|
|
91
|
+
return (group) => {
|
|
92
|
+
const confirm = group.get(confirmField);
|
|
93
|
+
if (!confirm) return null;
|
|
94
|
+
const mismatch = !isEmpty(confirm.value) && group.get(field)?.value !== confirm.value;
|
|
95
|
+
const { [errorKey]: current, ...others } = confirm.errors ?? {};
|
|
96
|
+
if (mismatch && !current) confirm.setErrors({
|
|
97
|
+
...others,
|
|
98
|
+
[errorKey]: true
|
|
99
|
+
});
|
|
100
|
+
if (!mismatch && current) confirm.setErrors(Object.keys(others).length ? others : null);
|
|
101
|
+
return mismatch ? { [errorKey]: true } : null;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function distinctFields(first, second) {
|
|
105
|
+
return (group) => {
|
|
106
|
+
const left = group.get(first);
|
|
107
|
+
const right = group.get(second);
|
|
108
|
+
if (!left?.enabled || !right?.enabled || isEmpty(left.value)) return null;
|
|
109
|
+
return left.value === right.value ? { distinctControls: true } : null;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function ip(options = {}) {
|
|
113
|
+
const pattern = options.cidr ? IPV4_CIDR : IPV4;
|
|
114
|
+
return (control) => {
|
|
115
|
+
const value = text(control.value);
|
|
116
|
+
if (!value || pattern.test(value) || options.ipv6 && isIpv6(value.split("/")[0])) return null;
|
|
117
|
+
return { invalidIp: { value } };
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function domain() {
|
|
121
|
+
return (control) => isEmpty(control.value) || DOMAIN.test(String(control.value)) ? null : { invalidDomain: true };
|
|
122
|
+
}
|
|
123
|
+
function duplicate(taken, options = {}) {
|
|
124
|
+
const { message, caseSensitive = false, trim = true } = options;
|
|
125
|
+
const normalize = (raw) => {
|
|
126
|
+
let value = (raw ?? "").toString();
|
|
127
|
+
value = trim ? value.trim() : value;
|
|
128
|
+
return caseSensitive ? value : value.toLowerCase();
|
|
129
|
+
};
|
|
130
|
+
return (control) => {
|
|
131
|
+
const value = normalize(control.value);
|
|
132
|
+
const list = typeof taken === "function" ? taken() : taken;
|
|
133
|
+
if (!value || !list.some((item) => normalize(item) === value)) return null;
|
|
134
|
+
const resolved = typeof message === "function" ? message() : message;
|
|
135
|
+
return { duplicate: resolved ? { message: resolved } : true };
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function time24() {
|
|
139
|
+
return (control) => isEmpty(control.value) || TIME_24.test(String(control.value)) ? null : { invalidTime: true };
|
|
140
|
+
}
|
|
141
|
+
function noUnsafeChars() {
|
|
142
|
+
return (control) => {
|
|
143
|
+
const value = control.value;
|
|
144
|
+
if (typeof value !== "string" || !value) return null;
|
|
145
|
+
for (const char of value) {
|
|
146
|
+
const code = char.charCodeAt(0);
|
|
147
|
+
if (code <= CONTROL_CHAR_MAX_CODE || code === DELETE_CHAR_CODE || UNSAFE_CHARS.includes(char)) return { pattern: true };
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function jsonObject() {
|
|
153
|
+
return (control) => {
|
|
154
|
+
const value = text(control.value);
|
|
155
|
+
if (!value) return null;
|
|
156
|
+
try {
|
|
157
|
+
const parsed = JSON.parse(value);
|
|
158
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? null : { invalidJson: true };
|
|
159
|
+
} catch {
|
|
160
|
+
return { invalidJson: true };
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function exactValue(expected, message) {
|
|
165
|
+
return (control) => {
|
|
166
|
+
const value = text(control.value);
|
|
167
|
+
if (!value || value === expected) return null;
|
|
168
|
+
return { valueMismatch: message ? { message } : { expected } };
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function cssSelector(options = {}) {
|
|
172
|
+
const { allowClass = true, allowId = true } = options;
|
|
173
|
+
const prefixes = `${allowClass ? "." : ""}${allowId ? "#" : ""}`;
|
|
174
|
+
const requiredPattern = `^[${prefixes}][a-zA-Z_][a-zA-Z0-9_-]*$`;
|
|
175
|
+
const pattern = new RegExp(requiredPattern);
|
|
176
|
+
return (control) => {
|
|
177
|
+
const value = text(control.value);
|
|
178
|
+
if (!value || prefixes && pattern.test(value)) return null;
|
|
179
|
+
return { pattern: {
|
|
180
|
+
requiredPattern,
|
|
181
|
+
actualValue: value
|
|
182
|
+
} };
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function requiredWhen(field, isRequired = Boolean) {
|
|
186
|
+
return (control) => {
|
|
187
|
+
const sibling = control.parent?.get(field);
|
|
188
|
+
if (!sibling || !isRequired(sibling.value)) return null;
|
|
189
|
+
return isEmpty(control.value) ? { required: true } : null;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function arraySumMax(field, max) {
|
|
193
|
+
return (control) => {
|
|
194
|
+
if (!(control instanceof FormArray)) return null;
|
|
195
|
+
const total = control.controls.reduce((sum, item) => sum + (Number(item.value?.[field]) || 0), 0);
|
|
196
|
+
return total > max ? { sumExceeded: {
|
|
197
|
+
max,
|
|
198
|
+
total
|
|
199
|
+
} } : null;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function price() {
|
|
203
|
+
return (control) => {
|
|
204
|
+
if (isEmpty(control.value)) return null;
|
|
205
|
+
const parsed = parsePrice(control.value);
|
|
206
|
+
if (parsed === null) return { priceFormat: true };
|
|
207
|
+
return parsed <= 0 ? { pricePositive: true } : null;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const TxValidators = {
|
|
211
|
+
numericCode,
|
|
212
|
+
isoDate,
|
|
213
|
+
futureDate,
|
|
214
|
+
url,
|
|
215
|
+
strongPassword,
|
|
216
|
+
matchFields,
|
|
217
|
+
distinctFields,
|
|
218
|
+
ip,
|
|
219
|
+
domain,
|
|
220
|
+
duplicate,
|
|
221
|
+
time24,
|
|
222
|
+
noUnsafeChars,
|
|
223
|
+
jsonObject,
|
|
224
|
+
exactValue,
|
|
225
|
+
cssSelector,
|
|
226
|
+
requiredWhen,
|
|
227
|
+
arraySumMax,
|
|
228
|
+
price
|
|
229
|
+
};
|
|
230
|
+
export { TX_DOMAIN_PATTERN, TxValidators, parsePrice };
|
|
231
|
+
|
|
232
|
+
//# sourceMappingURL=tectra-ng-utils-validators.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-validators.mjs","names":[],"sources":["../../../../packages/utils/validators/src/validators.ts"],"sourcesContent":["import { AbstractControl, FormArray, ValidationErrors, ValidatorFn } from '@angular/forms';\nimport { TxCssSelectorValidatorOptions, TxDuplicateValidatorOptions, TxIpValidatorOptions, TxStrongPasswordOptions, TxUrlValidatorOptions } from './validators.types';\n\nexport const TX_DOMAIN_PATTERN =\n '^\\\\s*([a-zA-Z\\\\u0400-\\\\u04FF0-9]{1,63}(-+[a-zA-Z\\\\u0400-\\\\u04FF0-9]{1,63})*\\\\.)+(xn--[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,57}[a-zA-Z0-9])?|[a-zA-Z\\\\u0400-\\\\u04FF]{2,63})\\\\.?\\\\s*$';\n\nconst DOMAIN = new RegExp(TX_DOMAIN_PATTERN);\nconst PRICE = /^\\d{1,12}([.,]\\d{1,2})?$/;\nconst TIME_24 = /^([01]\\d|2[0-3]):([0-5]\\d)$/;\nconst ISO_DATE = /^\\d{4}-\\d{1,2}-\\d{1,2}$/;\nconst IPV4_PART = '(?:25[0-5]|2[0-4]\\\\d|1\\\\d{2}|[1-9]?\\\\d)';\nconst IPV4 = new RegExp(`^(?:${IPV4_PART}\\\\.){3}${IPV4_PART}$`);\nconst IPV4_CIDR = new RegExp(`^(?:${IPV4_PART}\\\\.){3}${IPV4_PART}(?:\\\\/(?:[0-9]|[12][0-9]|3[0-2]))?$`);\nconst IPV6_CHARS = /^[0-9a-fA-F:.]+$/;\nconst CONTROL_CHAR_MAX_CODE = 31;\nconst DELETE_CHAR_CODE = 127;\nconst UNSAFE_CHARS = ['<', '>'];\n\nconst isEmpty = (value: unknown): boolean => value === null || value === undefined || (typeof value === 'string' && value.trim() === '') || (Array.isArray(value) && value.length === 0);\n\nconst text = (value: unknown): string => (value ?? '').toString().trim();\n\nfunction isIpv6(value: string): boolean {\n if (!value.includes(':') || !IPV6_CHARS.test(value)) {\n return false;\n }\n try {\n return !!new URL(`http://[${value}]`).hostname;\n } catch {\n return false;\n }\n}\n\nexport function parsePrice(value: unknown): number | null {\n if (typeof value === 'number') {\n return Number.isFinite(value) ? value : null;\n }\n if (typeof value !== 'string' || !PRICE.test(value.trim())) {\n return null;\n }\n return Number(value.trim().replace(',', '.'));\n}\n\nfunction numericCode(length = 6): ValidatorFn {\n const pattern = new RegExp(`^\\\\d{${length}}$`);\n return (control) => (isEmpty(control.value) || pattern.test(String(control.value)) ? null : { invalidCodeFormat: { length } });\n}\n\nfunction isoDate(): ValidatorFn {\n return (control) => {\n const value = control.value;\n if (isEmpty(value)) {\n return null;\n }\n if (typeof value === 'string' && ISO_DATE.test(value)) {\n const [year, month, day] = value.split('-').map(Number);\n const date = new Date(Date.UTC(year, month - 1, day));\n if (date.getUTCFullYear() === year && date.getUTCMonth() + 1 === month && date.getUTCDate() === day) {\n return null;\n }\n }\n return { invalidDate: true };\n };\n}\n\nfunction futureDate(): ValidatorFn {\n return (control) => {\n if (isEmpty(control.value)) {\n return null;\n }\n const now = new Date();\n now.setSeconds(0, 0);\n const value = new Date(control.value);\n if (Number.isNaN(value.getTime())) {\n return { invalidDate: true };\n }\n value.setSeconds(0, 0);\n return value < now ? { pastDate: true } : null;\n };\n}\n\nfunction url(options: TxUrlValidatorOptions = {}): ValidatorFn {\n const { https = true, host } = options;\n return (control) => {\n const value = text(control.value);\n if (!value) {\n return null;\n }\n try {\n const parsed = new URL(value);\n const protocolOk = https ? parsed.protocol === 'https:' : parsed.protocol === 'https:' || parsed.protocol === 'http:';\n const hostOk = !host || (typeof host === 'string' ? parsed.hostname === host || parsed.hostname.endsWith(`.${host}`) : host.test(parsed.hostname));\n return protocolOk && hostOk && !/\\s/.test(value) ? null : { invalidUrl: true };\n } catch {\n return { invalidUrl: true };\n }\n };\n}\n\nfunction strongPassword(options: TxStrongPasswordOptions = {}): ValidatorFn {\n const { minLength = 6, upper = true, lower = true, digit = false, symbol = true } = options;\n return (control) => {\n const value = control.value;\n if (isEmpty(value)) {\n return null;\n }\n const password = String(value);\n const missing = [\n password.length < minLength && 'length',\n upper && !/\\p{Lu}/u.test(password) && 'upper',\n lower && !/\\p{Ll}/u.test(password) && 'lower',\n digit && !/\\p{N}/u.test(password) && 'digit',\n symbol && !/[^\\p{L}\\p{N}\\s]/u.test(password) && 'symbol',\n ].filter((item): item is string => !!item);\n return missing.length ? { weakPassword: { minLength, missing } } : null;\n };\n}\n\nfunction matchFields(field: string, confirmField: string, errorKey = 'mismatch'): ValidatorFn {\n return (group) => {\n const confirm = group.get(confirmField);\n if (!confirm) {\n return null;\n }\n const mismatch = !isEmpty(confirm.value) && group.get(field)?.value !== confirm.value;\n const { [errorKey]: current, ...others } = confirm.errors ?? {};\n if (mismatch && !current) {\n confirm.setErrors({ ...others, [errorKey]: true });\n }\n if (!mismatch && current) {\n confirm.setErrors(Object.keys(others).length ? others : null);\n }\n return mismatch ? { [errorKey]: true } : null;\n };\n}\n\nfunction distinctFields(first: string, second: string): ValidatorFn {\n return (group) => {\n const left = group.get(first);\n const right = group.get(second);\n if (!left?.enabled || !right?.enabled || isEmpty(left.value)) {\n return null;\n }\n return left.value === right.value ? { distinctControls: true } : null;\n };\n}\n\nfunction ip(options: TxIpValidatorOptions = {}): ValidatorFn {\n const pattern = options.cidr ? IPV4_CIDR : IPV4;\n return (control) => {\n const value = text(control.value);\n if (!value || pattern.test(value) || (options.ipv6 && isIpv6(value.split('/')[0]))) {\n return null;\n }\n return { invalidIp: { value } };\n };\n}\n\nfunction domain(): ValidatorFn {\n return (control) => (isEmpty(control.value) || DOMAIN.test(String(control.value)) ? null : { invalidDomain: true });\n}\n\nfunction duplicate(taken: readonly string[] | (() => readonly string[]), options: TxDuplicateValidatorOptions = {}): ValidatorFn {\n const { message, caseSensitive = false, trim = true } = options;\n const normalize = (raw: unknown): string => {\n let value = (raw ?? '').toString();\n value = trim ? value.trim() : value;\n return caseSensitive ? value : value.toLowerCase();\n };\n return (control) => {\n const value = normalize(control.value);\n const list = typeof taken === 'function' ? taken() : taken;\n if (!value || !list.some((item) => normalize(item) === value)) {\n return null;\n }\n const resolved = typeof message === 'function' ? message() : message;\n return { duplicate: resolved ? { message: resolved } : true };\n };\n}\n\nfunction time24(): ValidatorFn {\n return (control) => (isEmpty(control.value) || TIME_24.test(String(control.value)) ? null : { invalidTime: true });\n}\n\nfunction noUnsafeChars(): ValidatorFn {\n return (control) => {\n const value = control.value;\n if (typeof value !== 'string' || !value) {\n return null;\n }\n for (const char of value) {\n const code = char.charCodeAt(0);\n if (code <= CONTROL_CHAR_MAX_CODE || code === DELETE_CHAR_CODE || UNSAFE_CHARS.includes(char)) {\n return { pattern: true };\n }\n }\n return null;\n };\n}\n\nfunction jsonObject(): ValidatorFn {\n return (control) => {\n const value = text(control.value);\n if (!value) {\n return null;\n }\n try {\n const parsed: unknown = JSON.parse(value);\n return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? null : { invalidJson: true };\n } catch {\n return { invalidJson: true };\n }\n };\n}\n\nfunction exactValue(expected: string, message?: string): ValidatorFn {\n return (control) => {\n const value = text(control.value);\n if (!value || value === expected) {\n return null;\n }\n return { valueMismatch: message ? { message } : { expected } };\n };\n}\n\nfunction cssSelector(options: TxCssSelectorValidatorOptions = {}): ValidatorFn {\n const { allowClass = true, allowId = true } = options;\n const prefixes = `${allowClass ? '.' : ''}${allowId ? '#' : ''}`;\n const requiredPattern = `^[${prefixes}][a-zA-Z_][a-zA-Z0-9_-]*$`;\n const pattern = new RegExp(requiredPattern);\n return (control) => {\n const value = text(control.value);\n if (!value || (prefixes && pattern.test(value))) {\n return null;\n }\n return { pattern: { requiredPattern, actualValue: value } };\n };\n}\n\nfunction requiredWhen(field: string, isRequired: (value: unknown) => boolean = Boolean): ValidatorFn {\n return (control) => {\n const sibling = control.parent?.get(field);\n if (!sibling || !isRequired(sibling.value)) {\n return null;\n }\n return isEmpty(control.value) ? { required: true } : null;\n };\n}\n\nfunction arraySumMax(field: string, max: number): ValidatorFn {\n return (control) => {\n if (!(control instanceof FormArray)) {\n return null;\n }\n const total = control.controls.reduce((sum, item: AbstractControl) => sum + (Number(item.value?.[field]) || 0), 0);\n return total > max ? { sumExceeded: { max, total } } : null;\n };\n}\n\nfunction price(): ValidatorFn {\n return (control): ValidationErrors | null => {\n if (isEmpty(control.value)) {\n return null;\n }\n const parsed = parsePrice(control.value);\n if (parsed === null) {\n return { priceFormat: true };\n }\n return parsed <= 0 ? { pricePositive: true } : null;\n };\n}\n\nexport const TxValidators = {\n numericCode,\n isoDate,\n futureDate,\n url,\n strongPassword,\n matchFields,\n distinctFields,\n ip,\n domain,\n duplicate,\n time24,\n noUnsafeChars,\n jsonObject,\n exactValue,\n cssSelector,\n requiredWhen,\n arraySumMax,\n price,\n} as const;\n"],"mappings":";AAGA,MAAa,oBACX;AAEF,MAAM,SAAS,IAAI,OAAO,iBAAiB;AAC3C,MAAM,QAAQ;AACd,MAAM,UAAU;AAChB,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,OAAO,IAAI,OAAO,OAAO,UAAS,SAAU,UAAS,EAAG;AAC9D,MAAM,YAAY,IAAI,OAAO,OAAO,UAAS,SAAU,UAAS,oCAAqC;AACrG,MAAM,aAAa;AACnB,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AACzB,MAAM,eAAe,CAAC,KAAK,GAAG;AAE9B,MAAM,WAAW,UAA4B,UAAU,QAAQ,UAAU,UAAc,OAAO,UAAU,YAAY,MAAM,KAAI,MAAO,MAAQ,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW;AAEtL,MAAM,QAAQ,WAA4B,SAAS,GAAA,CAAI,SAAQ,CAAE,CAAC,KAAI;AAEtE,SAAS,OAAO,OAAa;CAC3B,IAAI,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,KAAK,KAAK,GAChD,OAAO;CAET,IAAI;EACF,OAAO,CAAC,CAAC,IAAI,IAAI,WAAW,MAAK,EAAG,CAAC,CAAC;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,OAAc;CACvC,IAAI,OAAO,UAAU,UACnB,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;CAE1C,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,KAAK,MAAM,KAAI,CAAE,GACvD,OAAO;CAET,OAAO,OAAO,MAAM,KAAI,CAAE,CAAC,QAAQ,KAAK,GAAG,CAAC;AAC9C;AAEA,SAAS,YAAY,S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-ng-utils.mjs","names":[],"sources":["../../../../packages/utils/index.ts"],"sourcesContent":["export const TECTRA_UTILS_VERSION = '0.0.0';\n"],"mappings":"AAAA,MAAa,uBAAuB"}
|
package/file/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# File
|
|
2
|
+
|
|
3
|
+
File sizes people can read — `512 B`, `1.5 KB`, `5 MB` in the locale number format — and downloads of a URL or a `Blob` from code (CSV built in the browser, a signed link from an API). Downloads do nothing on the server.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
{{ file.size | txFileSize }}
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Pipes
|
|
10
|
+
| Name | Description |
|
|
11
|
+
|---|---|
|
|
12
|
+
| txFileSize: options? | Size in B, KB, MB, GB, TB, PB; options `decimals` (1), `base` (`1024` or `1000`), `locale` (the tectra one by default), `empty` (`-` for no size) |
|
|
13
|
+
|
|
14
|
+
## Functions
|
|
15
|
+
| Name | Description |
|
|
16
|
+
|---|---|
|
|
17
|
+
| formatFileSize(bytes, options?) | The function behind the pipe; `en-US` by default |
|
|
18
|
+
| downloadFile(url, filename?) | Downloads a URL through a temporary link; the name comes from the URL when not given |
|
|
19
|
+
| downloadBlob(blob, filename?) | Downloads data made in the browser and frees its object URL |
|
package/filter/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Filter
|
|
2
|
+
|
|
3
|
+
Search and filters for lists in code or templates, with the same rules as the table filters: case, accents and extra spaces do not matter, nested fields are reached by a path (`team.name`), and the table's match modes work on any list.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
@for (person of people() | txSearch: query() : ['name', 'email', 'team.name']; track person.id) { … }
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Pipes
|
|
10
|
+
| Name | Description |
|
|
11
|
+
|---|---|
|
|
12
|
+
| txSearch: query, fields | Items where any of the fields contains the query; all items for an empty query. `fields` — paths or a function returning the values |
|
|
13
|
+
| txFilterBy: value, fields, matchMode? | Items where any field matches the value by a match mode (`contains` by default) or your own function |
|
|
14
|
+
|
|
15
|
+
## Functions
|
|
16
|
+
| Name | Description |
|
|
17
|
+
|---|---|
|
|
18
|
+
| filterBySearch(items, query, fields, locale?) | The function behind `txSearch` |
|
|
19
|
+
| filterBy(items, value, fields, matchMode?, locale?) | The function behind `txFilterBy`. Match modes: `startsWith`, `contains`, `notContains`, `endsWith`, `equals`, `notEquals`, `in`, `lt`, `lte`, `gt`, `gte`, `between`, `dateIs`, `dateIsNot`, `dateBefore`, `dateAfter`, or `(value, filter, locale) => boolean` |
|
|
20
|
+
| matches(value, filter, matchMode?, locale?) | One value against one filter |
|
|
21
|
+
| normalizeSearch(value, locale?) | Lower case without accents and outer spaces — compare your own strings the same way |
|
|
22
|
+
| resolveField(item, path) | A nested value by a dotted path |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Filter State
|
|
2
|
+
|
|
3
|
+
Filters of a list page that survive a reload and can be shared as a link: a signal of the filters, saved in local storage and, when asked, in the query string — only the values that differ from the initial ones. Back and forward restore the filters of that history entry. On the server and with blocked storage it falls back to memory, so nothing throws.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
readonly filters = txFilterState({ key: 'orders-filters', initial: { search: '', status: [] as string[], page: 1 }, url: true });
|
|
7
|
+
|
|
8
|
+
readonly orders = httpResource(() => ({ url: '/api/orders', params: buildHttpParams(this.filters.value()) }));
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<input txInput [ngModel]="filters.value().search" (ngModelChange)="filters.patch({ search: $event, page: 1 })" />
|
|
13
|
+
<button txButton label="Reset" [disabled]="filters.isInitial()" (click)="filters.reset()"></button>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Pages built on a base class keep their code: extend `TxUrlFilters<T>` (or `TxSaveFilters<T>` for storage only), set `localStorageKey` and `initialFilters()`, call `storeFilters()` / `getStoredFilters()`, override `applyUrlFilters()` to react to back and forward.
|
|
17
|
+
|
|
18
|
+
## Functions
|
|
19
|
+
| Name | Description |
|
|
20
|
+
|---|---|
|
|
21
|
+
| txFilterState({ key, initial, url?, storage? }) | Creates the state in an injection context; `url` (`false`) writes the query string, `storage` is `'local'` (default), `'session'`, `'memory'` or `false`. Start: URL → storage (merged over `initial`, so new keys get their defaults) → `initial` |
|
|
22
|
+
| injectStorage(kind?) | `localStorage` / `sessionStorage` when it works, a shared `TxMemoryStorage` on the server or when blocked |
|
|
23
|
+
| readJson(storage, key) / writeJson(storage, key, value) | JSON in a storage without throwing on broken data or a full quota |
|
|
24
|
+
| filtersToQueryParams(filters, initial) | Query params of the changed values, `null` for the rest (Angular removes them) |
|
|
25
|
+
| queryParamsToFilters(params, initial) | Filters from query params over `initial`, or `null` when the URL has none of their keys |
|
|
26
|
+
| encodeUrlFilterValue(value) / decodeUrlFilterValue(text) | Plain strings stay readable, everything else is JSON |
|
|
27
|
+
|
|
28
|
+
## Methods
|
|
29
|
+
| Name | Description |
|
|
30
|
+
|---|---|
|
|
31
|
+
| value | Signal of the current filters |
|
|
32
|
+
| isInitial | Signal: nothing differs from `initial` |
|
|
33
|
+
| changed | Signal: keys that differ from `initial` — for a "3 filters" badge |
|
|
34
|
+
| set(filters) | Replaces the filters and saves them |
|
|
35
|
+
| patch(filters) | Changes some keys |
|
|
36
|
+
| reset() | Back to `initial`; removes the stored copy and the query params |
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Form Changes
|
|
2
|
+
|
|
3
|
+
Knows whether a form differs from what was loaded — to enable Save, warn before leaving, or put the values back. Compares deeply (groups, arrays, dates by time, disabled controls too), and treats `null`, `undefined` and `''` as the same empty value.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
readonly changes = trackFormChanges(this.form);
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<button txButton label="Save" [disabled]="!changes.changed()" (click)="save()"></button>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Functions
|
|
14
|
+
| Name | Description |
|
|
15
|
+
|---|---|
|
|
16
|
+
| trackFormChanges(form) | In an injection context: `{ changed, commit(), revert() }` — a signal, take the current values as the new start, put the start values back |
|
|
17
|
+
| deepEqual(a, b) | The comparison it uses |
|
|
18
|
+
|
|
19
|
+
## Methods
|
|
20
|
+
| Name | Description |
|
|
21
|
+
|---|---|
|
|
22
|
+
| TxFormChangeTracker.initFormTracking(form) | Remembers the current values (provide the service in the component) |
|
|
23
|
+
| hasFormChanges(form) | `true` when the values differ from the remembered ones |
|
|
24
|
+
| updateInitialFormState(form) | Remembers the values again — after a save |
|
|
25
|
+
| resetFormToInitial(form) | Puts the remembered values back |
|
|
26
|
+
| resetFormTracking() | Forgets them |
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Form Validation
|
|
2
|
+
|
|
3
|
+
Shows the user what is wrong after a failed save: every control becomes touched and dirty (so the kit fields show their errors), the first invalid field scrolls into the middle of the screen and gets the focus — the inner input of a kit field (select, datepicker, multiselect …), not its wrapper. Smooth scrolling turns instant with reduced motion.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
private validation = inject(TxFormValidation);
|
|
7
|
+
|
|
8
|
+
save(): void {
|
|
9
|
+
if (this.form.invalid) {
|
|
10
|
+
this.validation.scrollToFirstInvalid(this.form);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or let the form do it on submit: `<form [formGroup]="form" txScrollToInvalid (validSubmit)="save()">`.
|
|
17
|
+
|
|
18
|
+
## Inputs
|
|
19
|
+
| Name | Description |
|
|
20
|
+
|---|---|
|
|
21
|
+
| focus | `txScrollToInvalid`: focus the field after scrolling |
|
|
22
|
+
| block | `txScrollToInvalid`: where the field lands — `center`, `start`, `end`, `nearest` |
|
|
23
|
+
|
|
24
|
+
## Outputs
|
|
25
|
+
| Name | Description |
|
|
26
|
+
|---|---|
|
|
27
|
+
| validSubmit | `txScrollToInvalid`: the form was submitted and is valid |
|
|
28
|
+
| invalidSubmit | `txScrollToInvalid`: the form was submitted invalid; the first error is in view |
|
|
29
|
+
|
|
30
|
+
## Methods
|
|
31
|
+
| Name | Description |
|
|
32
|
+
|---|---|
|
|
33
|
+
| scrollToFirstInvalid(form, options?) | `TxFormValidation`: marks all touched, scrolls to and focuses the first invalid field; `{ scope, focus, block }`; returns `true` when a field was found. Provide it in a component to search only inside it |
|
|
34
|
+
|
|
35
|
+
## Functions
|
|
36
|
+
| Name | Description |
|
|
37
|
+
|---|---|
|
|
38
|
+
| markAllTouched(control) | Touched and dirty for a control and every control inside groups and arrays |
|
|
39
|
+
| firstInvalidElement(scope) | The first element with `ng-invalid` that has no invalid element inside |
|
|
40
|
+
| focusTarget(element) | The element itself when it takes focus, or the first focusable element inside |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Go Back
|
|
2
|
+
|
|
3
|
+
A back button that never leaves the app: it goes back in history when the user came from another page of the app, and opens a fallback route when the page was opened directly (a link from an email, a new tab, a reload after a deep link).
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<button txButton icon="arrow-left" label="Back" txGoBack="/orders"></button>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Inputs
|
|
10
|
+
| Name | Description |
|
|
11
|
+
|---|---|
|
|
12
|
+
| txGoBack | Fallback route — a URL, router commands or a `UrlTree`; `/` by default |
|
|
13
|
+
|
|
14
|
+
## Outputs
|
|
15
|
+
| Name | Description |
|
|
16
|
+
|---|---|
|
|
17
|
+
| navigated | `back` or `fallback` — which way it went |
|
|
18
|
+
|
|
19
|
+
## Methods
|
|
20
|
+
| Name | Description |
|
|
21
|
+
|---|---|
|
|
22
|
+
| back() | Goes back now (`exportAs: 'txGoBack'`) |
|
|
23
|
+
| canGoBack() | `true` when an earlier page of the app is in the history |
|
|
24
|
+
|
|
25
|
+
## Keyboard
|
|
26
|
+
| Key | Action |
|
|
27
|
+
|---|---|
|
|
28
|
+
| Enter / Space | Goes back, when the host is not a button or a link already |
|
package/http/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# HTTP
|
|
2
|
+
|
|
3
|
+
Helpers around `HttpClient`: query params from a filter object, retries of reads with back-off, and pipes that turn a status code into a kit tone and a translated label.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
this.http.get<Page<Order>>('/api/orders', { params: buildHttpParams(filters) }).pipe(retryHttpReads());
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<tx-tag [value]="item.status | txHttpStatusLabel" [severity]="item.status | txHttpStatusTone" />
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Functions
|
|
14
|
+
| Name | Description |
|
|
15
|
+
|---|---|
|
|
16
|
+
| buildHttpParams(query) | `HttpParams` from an object: skips `null`, `undefined`, `''` and empty arrays, repeats a key for every array item, dates as ISO strings, objects as JSON; `0` and `false` stay |
|
|
17
|
+
| retryHttpReads(options?) | RxJS operator for GET requests: retries a network error, 429, 502, 503 and 504 with exponential back-off (2 s, 4 s, 8 s … up to 30 s, 5 times); a `Retry-After` header wins, and when it asks for longer than `maxDelayMs` the error goes through. Options: `count`, `baseDelayMs`, `maxDelayMs`, `statuses` |
|
|
18
|
+
| parseRetryAfter(value, now?) | Milliseconds from a `Retry-After` header — seconds or an HTTP date; `null` when missing or broken |
|
|
19
|
+
| httpRetryDelay({ error, attempt, baseDelayMs, maxDelayMs }) | The wait before an attempt, or `null` to stop |
|
|
20
|
+
| httpStatusGroup(status, warnCodes?) | `ok`, `redirect`, `clientError`, `serverError`, `warning` (codes you list), `noResponse` (no status or 0), `unknown` |
|
|
21
|
+
| httpStatusTone(status, warnCodes?) | Kit severity of a status: `success`, `info`, `warn`, `danger`, `secondary` |
|
|
22
|
+
|
|
23
|
+
## Pipes
|
|
24
|
+
| Name | Description |
|
|
25
|
+
|---|---|
|
|
26
|
+
| txHttpStatusTone: warnCodes? | Severity for `tx-tag`, `tx-status-icon`, `tx-badge` |
|
|
27
|
+
| txHttpStatusLabel: warnCodes? | Translated group name: OK, Redirect, Client error, Server error, Warning, No response, Unknown |
|
|
28
|
+
| txHttpStatusGroup: warnCodes? | The group as a key, for your own texts |
|
|
29
|
+
|
|
30
|
+
## Constants
|
|
31
|
+
| Name | Description |
|
|
32
|
+
|---|---|
|
|
33
|
+
| TX_HTTP_RETRYABLE_STATUSES | `0`, `429`, `502`, `503`, `504` |
|
|
34
|
+
| TX_HTTP_RETRY_COUNT / TX_HTTP_RETRY_BASE_DELAY_MS / TX_HTTP_RETRY_MAX_DELAY_MS / TX_HTTP_RETRY_FACTOR | `5`, `2000`, `30000`, `2` |
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# In View
|
|
2
|
+
|
|
3
|
+
Knows when an element scrolls into view — to animate it in, count an impression, load a picture or a chart late. `txInView` adds the `tx-in-view` class and your enter / leave classes, and reports `entered` and `left`; `txVisibleOnScroll` watches a scrolling list and reports each fully visible item once (mark notifications read, track seen rows). Both use one `IntersectionObserver`, start in the browser only, and treat a browser without it as "in view". To render a heavy block only when it comes near, use Angular's `@defer (on viewport)`.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<section txInView enterClass="fade-up" (entered)="track('pricing')">…</section>
|
|
7
|
+
|
|
8
|
+
<div class="list" [txVisibleOnScroll]="notifications()" (itemVisible)="markRead($event)">
|
|
9
|
+
@for (item of notifications(); track item.id) { <tx-message … /> }
|
|
10
|
+
</div>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Inputs
|
|
14
|
+
| Name | Description |
|
|
15
|
+
|---|---|
|
|
16
|
+
| threshold | `txInView`: share of the element that must be visible, 0–1 |
|
|
17
|
+
| rootMargin | `txInView`: grows or shrinks the viewport, e.g. `0px 0px -20% 0px` |
|
|
18
|
+
| once | `txInView`: stop watching after the first entry |
|
|
19
|
+
| enterClass | `txInView`: classes added when the element is in view |
|
|
20
|
+
| leaveClass | `txInView`: classes added when it leaves (with `once` off) |
|
|
21
|
+
| txVisibleOnScroll | Items of the list in the order of the children: `{ id, ignore? }`; ids that leave the list are forgotten |
|
|
22
|
+
| visibleRatio | `txVisibleOnScroll`: share of an item that counts as fully visible; items taller than the box never count |
|
|
23
|
+
|
|
24
|
+
## Outputs
|
|
25
|
+
| Name | Description |
|
|
26
|
+
|---|---|
|
|
27
|
+
| entered | `txInView`: the element came into view |
|
|
28
|
+
| left | `txInView`: the element left the view |
|
|
29
|
+
| itemVisible | `txVisibleOnScroll`: id of an item seen for the first time |
|
|
30
|
+
|
|
31
|
+
## Methods
|
|
32
|
+
| Name | Description |
|
|
33
|
+
|---|---|
|
|
34
|
+
| isInView | `txInView` (`exportAs: 'txInView'`): signal, `true` while in view (stays `true` with `once`) |
|