@tectra-ng/utils 0.4.2 → 0.4.3
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 +1 -0
- package/fesm2022/tectra-ng-utils-filter.mjs +1 -1
- package/fesm2022/tectra-ng-utils-filter.mjs.map +1 -1
- package/fesm2022/tectra-ng-utils-pagination.mjs +1 -0
- package/fesm2022/tectra-ng-utils.mjs +1 -1
- package/file/README.md +1 -1
- package/http/README.md +1 -1
- package/package.json +9 -5
- package/pagination/README.md +11 -0
- package/types/tectra-ng-utils-filter.d.ts +1 -1
- package/types/tectra-ng-utils-http.d.ts +1 -1
- package/types/tectra-ng-utils-pagination.d.ts +2 -0
- package/types/tectra-ng-utils.d.ts +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ Part of `tectra-ng`. One entry point per utility, so you only bundle what you im
|
|
|
63
63
|
| `@tectra-ng/utils/drag-scroll` | `txDragScroll` — drag a box to scroll it, or pan a canvas |
|
|
64
64
|
| `@tectra-ng/utils/form-changes` | `trackFormChanges` (`changed` signal, commit, revert), `TxFormChangeTracker` |
|
|
65
65
|
| `@tectra-ng/utils/scroll-end` | `txScrollEnd` — infinite scrolling for a box |
|
|
66
|
+
| `@tectra-ng/utils/pagination` | `firstToPage`, `pageToFirst`, `pageCountOf`, `pageLinksOf`, `TxPaginationParams` — page math without the paginator component |
|
|
66
67
|
| `@tectra-ng/utils/random` | `pickRandom`, `pickRandomN`, `shuffle` |
|
|
67
68
|
| `@tectra-ng/utils/auto-focus` | `txAutoFocus` — focus a field or the first field inside after render |
|
|
68
69
|
| `@tectra-ng/utils/style-class` | `txStyleClass` — show, hide or toggle an element by classes with enter / leave animations |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { Pipe } from "@angular/core";
|
|
3
|
-
import { matchesRule, resolveField } from "@tectra-ng/
|
|
3
|
+
import { matchesRule, resolveField } from "@tectra-ng/core/utils";
|
|
4
4
|
function normalizeSearch(value, locale) {
|
|
5
5
|
return String(value ?? "").normalize("NFD").replace(/\p{Diacritic}/gu, "").trim().toLocaleLowerCase(locale);
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-filter.mjs","names":[],"sources":["../../../../packages/utils/filter/src/filter.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\nimport { TxFilterMatchMode, matchesRule, resolveField } from '@tectra-ng/
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-filter.mjs","names":[],"sources":["../../../../packages/utils/filter/src/filter.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\nimport { TxFilterMatchMode, matchesRule, resolveField } from '@tectra-ng/core/utils';\n\n/**\n * Own match rule for a filter: gets the value, the filter and the locale, returns whether the item\n * matches.\n */\nexport type TxMatchFunction = (value: unknown, filter: unknown, locale?: string) => boolean;\n/** Where to look for a value in an item: a list of field paths or a function that returns the values. */\nexport type TxFilterFields<T> = readonly string[] | ((item: T) => readonly unknown[]);\n\nexport { resolveField };\n\nexport function normalizeSearch(value: unknown, locale?: string): string {\n return String(value ?? '')\n .normalize('NFD')\n .replace(/\\p{Diacritic}/gu, '')\n .trim()\n .toLocaleLowerCase(locale);\n}\n\nfunction valuesOf<T>(item: T, fields: TxFilterFields<T>): readonly unknown[] {\n return typeof fields === 'function' ? fields(item) : fields.map((field) => resolveField(item, field));\n}\n\nexport function filterBySearch<T>(items: readonly T[], query: string | null | undefined, fields: TxFilterFields<T>, locale?: string): T[] {\n const needle = normalizeSearch(query, locale);\n if (!needle) {\n return [...items];\n }\n return items.filter((item) =>\n valuesOf(item, fields)\n .filter((value) => value !== null && value !== undefined && value !== '')\n .some((value) => normalizeSearch(value, locale).includes(needle)),\n );\n}\n\nexport function matches(value: unknown, filter: unknown, matchMode: TxFilterMatchMode | TxMatchFunction = 'contains', locale?: string): boolean {\n return typeof matchMode === 'function' ? matchMode(value, filter, locale) : matchesRule(value, { value: filter, matchMode }, locale);\n}\n\nexport function filterBy<T>(items: readonly T[], filter: unknown, fields: TxFilterFields<T>, matchMode: TxFilterMatchMode | TxMatchFunction = 'contains', locale?: string): T[] {\n return items.filter((item) => valuesOf(item, fields).some((value) => matches(value, filter, matchMode, locale)));\n}\n\n@Pipe({ name: 'txSearch' })\nexport class TxSearchPipe implements PipeTransform {\n transform<T>(items: readonly T[] | null | undefined, query: string | null | undefined, fields: TxFilterFields<T>): T[] {\n return filterBySearch(items ?? [], query, fields);\n }\n}\n\n@Pipe({ name: 'txFilterBy' })\nexport class TxFilterByPipe implements PipeTransform {\n transform<T>(items: readonly T[] | null | undefined, filter: unknown, fields: TxFilterFields<T>, matchMode: TxFilterMatchMode | TxMatchFunction = 'contains'): T[] {\n return filterBy(items ?? [], filter, fields, matchMode);\n }\n}\n"],"mappings":";;;AAaA,SAAgB,gBAAgB,OAAgB,QAAe;CAC7D,OAAO,OAAO,SAAS,EAAE,CAAC,CACvB,UAAU,KAAK,CAAC,CAChB,QAAQ,mBAAmB,EAAE,CAAC,CAC9B,KAAI,CAAE,CACN,kBAAkB,MAAM;AAC7B;AAEA,SAAS,SAAY,MAAS,QAAyB;CACrD,OAAO,OAAO,WAAW,aAAa,OAAO,IAAI,IAAI,OAAO,KAAK,UAAU,aAAa,MAAM,KAAK,CAAC;AACtG;AAEA,SAAgB,eAAkB,OAAqB,OAAkC,QAA2B,QAAe;CACjI,MAAM,SAAS,gBAAgB,OAAO,MAAM;CAC5C,IAAI,CAAC,QACH,OAAO,CAAC,GAAG,KAAK;CAElB,OAAO,MAAM,QAAQ,SACnB,SAAS,MAAM,MAAM,CAAC,CACnB,QAAQ,UAAU,UAAU,QAAQ,UAAU,UAAa,UAAU,EAAE,CAAC,CACxE,MAAM,UAAU,gBAAgB,OAAO,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC;AAEvE;AAEA,SAAgB,QAAQ,OAAgB,QAAiB,YAAiD,YAAY,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AAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAc,YAAA,CAAA;EAD1B,MAAA;EAAK,MAAA,CAAA,EAAE,MAAM,aAAY,CAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { firstToPage, pageCountOf, pageLinksOf, pageToFirst } from "@tectra-ng/core/utils";
|
package/file/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# File
|
|
2
2
|
|
|
3
|
-
File sizes people can read — `512
|
|
3
|
+
File sizes people can read — `512 bytes`, `1.5 kB`, `5 MB`, with the number format and unit names of the locale — 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
4
|
|
|
5
5
|
```html
|
|
6
6
|
{{ file.size | txFileSize }}
|
package/http/README.md
CHANGED
|
@@ -23,7 +23,7 @@ this.http.get<Page<Order>>('/api/orders', { params: buildHttpParams(filters) }).
|
|
|
23
23
|
## Pipes
|
|
24
24
|
| Name | Description |
|
|
25
25
|
|---|---|
|
|
26
|
-
| txHttpStatusTone: warnCodes? | Severity for `tx-tag`, `tx-status-icon`, `tx-badge` |
|
|
26
|
+
| txHttpStatusTone: warnCodes? | Severity for `tx-tag`, `tx-pill` (`tone`), `tx-status-icon`, `tx-badge` |
|
|
27
27
|
| txHttpStatusLabel: warnCodes? | Translated group name: OK, Redirect, Client error, Server error, Warning, No response, Unknown |
|
|
28
28
|
| txHttpStatusGroup: warnCodes? | The group as a key, for your own texts |
|
|
29
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tectra-ng/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Angular utilities on signals next to the tectra components: date, number, relative time, plural, file size and currency pipes; debounced input, copy to clipboard, in view, defer, drag scroll and auto focus directives; form validators and scroll to the first invalid field; filters kept in storage and the URL; HTTP params, retries and polling; clock, page title, router scrolling and breakpoints. Server rendering safe.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://tectra-ng.com/components/date",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@angular/platform-browser": "^22.2.0",
|
|
35
35
|
"@angular/router": "^22.2.0",
|
|
36
36
|
"rxjs": "^7.8.0",
|
|
37
|
-
"@tectra-ng/core": "^0.4.
|
|
38
|
-
"@tectra-ng/icons": "^0.4.
|
|
39
|
-
"@tectra-ng/themes": "^0.4.
|
|
40
|
-
"@tectra-ng/ui": "^0.4.
|
|
37
|
+
"@tectra-ng/core": "^0.4.3",
|
|
38
|
+
"@tectra-ng/icons": "^0.4.3",
|
|
39
|
+
"@tectra-ng/themes": "^0.4.3",
|
|
40
|
+
"@tectra-ng/ui": "^0.4.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@angular/forms": {
|
|
@@ -131,6 +131,10 @@
|
|
|
131
131
|
"types": "./types/tectra-ng-utils-number.d.ts",
|
|
132
132
|
"default": "./fesm2022/tectra-ng-utils-number.mjs"
|
|
133
133
|
},
|
|
134
|
+
"./pagination": {
|
|
135
|
+
"types": "./types/tectra-ng-utils-pagination.d.ts",
|
|
136
|
+
"default": "./fesm2022/tectra-ng-utils-pagination.mjs"
|
|
137
|
+
},
|
|
134
138
|
"./plural": {
|
|
135
139
|
"types": "./types/tectra-ng-utils-plural.d.ts",
|
|
136
140
|
"default": "./fesm2022/tectra-ng-utils-plural.mjs"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Pagination
|
|
2
|
+
|
|
3
|
+
Page math for paginated lists and requests without the paginator component: convert between a zero-based page and the index of its first row, count pages, pick the page links around the current page. `TxPaginationParams` is the shape of a paginated request or response (`page` is 1-based, `limit` is the page size, `total` the number of records). `@tectra-ng/ui/paginator` exports the same functions.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
| Name | Description |
|
|
7
|
+
|---|---|
|
|
8
|
+
| firstToPage(first, rows) | Zero-based page of the row at index `first`; `0` when `rows` is `0` |
|
|
9
|
+
| pageToFirst(page, rows) | Index of the first row of a zero-based page |
|
|
10
|
+
| pageCountOf(totalRecords, rows) | Number of pages; `0` without records, `1` when `rows` is `0` |
|
|
11
|
+
| pageLinksOf(page, pageCount, linkSize) | Zero-based pages to show as links, the current one centred |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { PipeTransform } from "@angular/core";
|
|
3
|
-
import { TxFilterMatchMode, resolveField } from "@tectra-ng/
|
|
3
|
+
import { TxFilterMatchMode, resolveField } from "@tectra-ng/core/utils";
|
|
4
4
|
/**
|
|
5
5
|
* Own match rule for a filter: gets the value, the filter and the locale, returns whether the item
|
|
6
6
|
* matches.
|
|
@@ -89,7 +89,7 @@ export declare function httpStatusGroup(status: number | null | undefined, warnC
|
|
|
89
89
|
*/
|
|
90
90
|
export declare function httpStatusTone(status: number | null | undefined, warnCodes?: readonly number[]): TxHttpStatusTone;
|
|
91
91
|
/**
|
|
92
|
-
* Severity for `tx-tag`, `tx-status-icon`, `tx-badge`
|
|
92
|
+
* Severity for `tx-tag`, `tx-pill` (`tone`), `tx-status-icon`, `tx-badge`
|
|
93
93
|
* @see https://tectra-ng.com/components/http
|
|
94
94
|
*/
|
|
95
95
|
export declare class TxHttpStatusTonePipe implements PipeTransform {
|