@tectra-ng/utils 0.4.0 → 0.4.2
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 +3 -1
- package/date/README.md +7 -5
- package/fesm2022/tectra-ng-utils-date.mjs +84 -23
- package/fesm2022/tectra-ng-utils-date.mjs.map +1 -1
- package/fesm2022/tectra-ng-utils-file.mjs +3 -13
- package/fesm2022/tectra-ng-utils-file.mjs.map +1 -1
- package/fesm2022/tectra-ng-utils-filter-state.mjs +6 -2
- package/fesm2022/tectra-ng-utils-filter-state.mjs.map +1 -1
- package/fesm2022/tectra-ng-utils-number.mjs +63 -0
- package/fesm2022/tectra-ng-utils-number.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-scrolling.mjs +64 -0
- package/fesm2022/tectra-ng-utils-scrolling.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-title.mjs +10 -4
- package/fesm2022/tectra-ng-utils-title.mjs.map +1 -1
- package/fesm2022/tectra-ng-utils.mjs +1 -1
- package/file/README.md +3 -3
- package/filter-state/README.md +5 -3
- package/number/README.md +23 -0
- package/package.json +14 -6
- package/scrolling/README.md +16 -0
- package/title/README.md +2 -1
- package/types/tectra-ng-utils-date.d.ts +37 -8
- package/types/tectra-ng-utils-date.d.ts.map +1 -1
- package/types/tectra-ng-utils-file.d.ts +3 -3
- package/types/tectra-ng-utils-file.d.ts.map +1 -1
- package/types/tectra-ng-utils-filter-state.d.ts +3 -3
- package/types/tectra-ng-utils-number.d.ts +29 -0
- package/types/tectra-ng-utils-number.d.ts.map +1 -0
- package/types/tectra-ng-utils-scrolling.d.ts +7 -0
- package/types/tectra-ng-utils-scrolling.d.ts.map +1 -0
- package/types/tectra-ng-utils-title.d.ts +7 -2
- package/types/tectra-ng-utils-title.d.ts.map +1 -1
- package/types/tectra-ng-utils.d.ts +1 -1
package/README.md
CHANGED
|
@@ -36,12 +36,13 @@ Part of `tectra-ng`. One entry point per utility, so you only bundle what you im
|
|
|
36
36
|
|
|
37
37
|
| Entry point | What it holds |
|
|
38
38
|
|---|---|
|
|
39
|
-
| `@tectra-ng/utils/date` | `txDate` and `txDateRange` pipes, `provideTxDateFormat`, calendar functions (`addDays`, `startOfWeek`, `calendarDaysBetween` …), format presets and time constants |
|
|
39
|
+
| `@tectra-ng/utils/date` | `txDate` (in the tectra locale) and `txDateRange` pipes, `provideTxDateFormat`, calendar functions (`addDays`, `startOfWeek`, `calendarDaysBetween` …), format presets and time constants |
|
|
40
40
|
| `@tectra-ng/utils/plural` | `txPluralForm` (`one` / `few` / `many` for translation keys) and `txPlural` pipes in the tectra locale |
|
|
41
41
|
| `@tectra-ng/utils/debounce-input` | `txDebounceInput` — reports a field's value after a pause, at once on Enter |
|
|
42
42
|
| `@tectra-ng/utils/form-validation` | `TxFormValidation.scrollToFirstInvalid`, `txScrollToInvalid` on a form, `markAllTouched` |
|
|
43
43
|
| `@tectra-ng/utils/filter-state` | `txFilterState` — filters in local storage and the URL; `TxUrlFilters` / `TxSaveFilters` base classes; `injectStorage`, `TxMemoryStorage` |
|
|
44
44
|
| `@tectra-ng/utils/http` | `buildHttpParams`, `retryHttpReads` (back-off, `Retry-After`), `txHttpStatusTone` / `txHttpStatusLabel` pipes |
|
|
45
|
+
| `@tectra-ng/utils/number` | `txNumber` — numbers in the tectra locale with any `Intl.NumberFormat` option, `formatLocaleNumber` |
|
|
45
46
|
| `@tectra-ng/utils/relative-time` | `txRelativeTime` — "5 minutes ago", "yesterday", "in 3 days" in the tectra locale |
|
|
46
47
|
| `@tectra-ng/utils/validators` | `TxValidators` — code, date, link, password, match, IP, domain, duplicate, time, JSON, price and more, with translated messages in `tx-field-error` |
|
|
47
48
|
| `@tectra-ng/utils/clipboard` | `txCopy` — copies on click with a kit toast; `TxClipboard`, `copyToClipboard` |
|
|
@@ -51,6 +52,7 @@ Part of `tectra-ng`. One entry point per utility, so you only bundle what you im
|
|
|
51
52
|
| `@tectra-ng/utils/currency` | `txCurrencySymbol` — the sign, code or name of any ISO currency in the tectra locale |
|
|
52
53
|
| `@tectra-ng/utils/in-view` | `txInView` (enter / leave classes, `entered` / `left`), `txVisibleOnScroll` (items seen in a scrolling list) |
|
|
53
54
|
| `@tectra-ng/utils/file` | `txFileSize`, `formatFileSize`, `downloadFile`, `downloadBlob` |
|
|
55
|
+
| `@tectra-ng/utils/scrolling` | `provideTxScrolling` — back / forward restore the scroll position, a new path starts at the top, query-only navigations (filters, paging) stay in place |
|
|
54
56
|
| `@tectra-ng/utils/title` | `provideTxTitle` — "Page · App" tab titles, a prefix for counters, translated keys |
|
|
55
57
|
| `@tectra-ng/utils/breakpoint` | `TxBreakpoints` — `isMobile`, `isTablet` and any media query as signals |
|
|
56
58
|
| `@tectra-ng/utils/selection` | `TxSelection` — checked rows by key with header checkbox state |
|
package/date/README.md
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
# Date
|
|
2
2
|
|
|
3
|
-
Dates in templates and code: the `txDate` pipe formats with Angular date patterns and shows `-` instead of an error for an empty or broken value; small calendar functions work on copies and count calendar days, not 24-hour blocks, so daylight saving time does not shift them.
|
|
3
|
+
Dates in templates and code: the `txDate` pipe formats in the tectra locale — with `Intl` date styles by default, or with Angular date patterns — follows a locale switch, and shows `-` instead of an error for an empty or broken value; small calendar functions work on copies and count calendar days, not 24-hour blocks, so daylight saving time does not shift them.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
|
-
import { TxDatePipe, TX_DATE_FORMATS, addDays, toIsoRange } from '@tectra-ng/utils/date';
|
|
6
|
+
import { TxDatePipe, TX_DATE_FORMATS, TX_DATE_STYLES, addDays, toIsoRange } from '@tectra-ng/utils/date';
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```html
|
|
10
|
+
{{ order.paidAt | txDate }} <!-- Nov 11, 2026 / 11 лист. 2026 р., or - when empty -->
|
|
11
|
+
{{ order.createdAt | txDate: TX_DATE_STYLES.dateTime }} <!-- Nov 11, 2026, 9:05 AM -->
|
|
10
12
|
{{ order.createdAt | txDate: TX_DATE_FORMATS.dateTime }} <!-- 11.11.26 09:05 -->
|
|
11
|
-
{{ order.paidAt | txDate }} <!-- Nov 11, 2026, or - when empty -->
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
## Pipes
|
|
15
16
|
| Name | Description |
|
|
16
17
|
|---|---|
|
|
17
|
-
| txDate: format?, timezone?, locale? | Formats a `Date`, ISO string or timestamp
|
|
18
|
+
| txDate: format?, timezone?, locale? | Formats a `Date`, ISO string or timestamp in the tectra locale and follows it as it changes. `format` is `Intl.DateTimeFormat` options (`TX_DATE_STYLES.dateTime`, `{ month: 'long', day: 'numeric' }`) or an Angular date pattern (`'dd.MM.yyyy'`, `'mediumDate'` …; month names need the Angular locale data, English otherwise); `timezone` is an offset (`'+0200'`), `'UTC'` or an IANA name; the empty text for `null`, `''` or an invalid date |
|
|
18
19
|
| txDateRange | `[start, end]` of a range datepicker → `{ start, end }` ISO strings, or `null` until both ends are picked |
|
|
19
20
|
|
|
20
21
|
## Providers
|
|
21
22
|
| Name | Description |
|
|
22
23
|
|---|---|
|
|
23
|
-
| provideTxDateFormat(config) | App or component defaults of `txDate`: `format` (`
|
|
24
|
+
| provideTxDateFormat(config) | App or component defaults of `txDate`: `format` (`TX_DATE_STYLES.date`), `empty` (`'-'`), `locale` (the tectra locale when not set), `timezone` |
|
|
24
25
|
|
|
25
26
|
## Functions
|
|
26
27
|
| Name | Description |
|
|
@@ -42,5 +43,6 @@ import { TxDatePipe, TX_DATE_FORMATS, addDays, toIsoRange } from '@tectra-ng/uti
|
|
|
42
43
|
## Constants
|
|
43
44
|
| Name | Description |
|
|
44
45
|
|---|---|
|
|
46
|
+
| TX_DATE_STYLES | `Intl` styles in the locale: `date` (Nov 11, 2026), `dateTime` (Nov 11, 2026, 9:05 AM), `time` (9:05 AM), `shortDate` (11/11/26), `longDate` (November 11, 2026) |
|
|
45
47
|
| TX_DATE_FORMATS | Patterns: `dateTime` `dd.MM.yy HH:mm`, `date` `dd.MM.yyyy`, `time` `HH:mm:ss`, `timeShort` `HH:mm`, `isoDay` `yyyy-MM-dd`, `isoMonth` `yyyy-MM`, `day` `dd`, `dayMonth` `dd.MM` |
|
|
46
48
|
| MS_IN_SECOND … MS_IN_WEEK | `MS_IN_SECOND`, `MS_IN_MINUTE`, `MS_IN_HOUR`, `MS_IN_DAY`, `MS_IN_WEEK`, `SECONDS_IN_MINUTE`, `SECONDS_IN_HOUR`, `SECONDS_IN_DAY`, `MINUTES_IN_HOUR`, `HOURS_IN_DAY`, `DAYS_IN_WEEK`, `MONTHS_IN_YEAR` |
|
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { InjectionToken, Pipe, inject } from "@angular/core";
|
|
3
3
|
import { formatDate } from "@angular/common";
|
|
4
|
-
|
|
5
|
-
format: "mediumDate",
|
|
6
|
-
empty: "-",
|
|
7
|
-
locale: "en-US",
|
|
8
|
-
timezone: void 0
|
|
9
|
-
};
|
|
10
|
-
const TX_DATE_FORMAT_CONFIG = new InjectionToken("TX_DATE_FORMAT_CONFIG", {
|
|
11
|
-
providedIn: "root",
|
|
12
|
-
factory: () => TX_DATE_FORMAT_DEFAULTS
|
|
13
|
-
});
|
|
14
|
-
function provideTxDateFormat(config) {
|
|
15
|
-
return {
|
|
16
|
-
provide: TX_DATE_FORMAT_CONFIG,
|
|
17
|
-
useValue: {
|
|
18
|
-
...TX_DATE_FORMAT_DEFAULTS,
|
|
19
|
-
...config
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
4
|
+
import { TxLocaleService } from "@tectra-ng/core/i18n";
|
|
23
5
|
const MS_IN_SECOND = 1e3;
|
|
24
6
|
const SECONDS_IN_MINUTE = 60;
|
|
25
7
|
const MINUTES_IN_HOUR = 60;
|
|
@@ -42,6 +24,35 @@ const TX_DATE_FORMATS = {
|
|
|
42
24
|
day: "dd",
|
|
43
25
|
dayMonth: "dd.MM"
|
|
44
26
|
};
|
|
27
|
+
const TX_DATE_STYLES = {
|
|
28
|
+
date: { dateStyle: "medium" },
|
|
29
|
+
dateTime: {
|
|
30
|
+
dateStyle: "medium",
|
|
31
|
+
timeStyle: "short"
|
|
32
|
+
},
|
|
33
|
+
time: { timeStyle: "short" },
|
|
34
|
+
shortDate: { dateStyle: "short" },
|
|
35
|
+
longDate: { dateStyle: "long" }
|
|
36
|
+
};
|
|
37
|
+
const TX_DATE_FORMAT_DEFAULTS = {
|
|
38
|
+
format: TX_DATE_STYLES.date,
|
|
39
|
+
empty: "-",
|
|
40
|
+
locale: void 0,
|
|
41
|
+
timezone: void 0
|
|
42
|
+
};
|
|
43
|
+
const TX_DATE_FORMAT_CONFIG = new InjectionToken("TX_DATE_FORMAT_CONFIG", {
|
|
44
|
+
providedIn: "root",
|
|
45
|
+
factory: () => TX_DATE_FORMAT_DEFAULTS
|
|
46
|
+
});
|
|
47
|
+
function provideTxDateFormat(config) {
|
|
48
|
+
return {
|
|
49
|
+
provide: TX_DATE_FORMAT_CONFIG,
|
|
50
|
+
useValue: {
|
|
51
|
+
...TX_DATE_FORMAT_DEFAULTS,
|
|
52
|
+
...config
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
45
56
|
const MIDDLE_OF_DAY_HOUR = 12;
|
|
46
57
|
function toDate(value) {
|
|
47
58
|
if (value === null || value === void 0 || value === "") return null;
|
|
@@ -126,17 +137,63 @@ function isExpiringWithin(value, periodMs = MS_IN_WEEK, now = Date.now()) {
|
|
|
126
137
|
const date = toDate(value);
|
|
127
138
|
return !!date && date.getTime() - new Date(now).getTime() <= periodMs;
|
|
128
139
|
}
|
|
140
|
+
const FALLBACK_LOCALE = "en-US";
|
|
141
|
+
const OFFSET = /^(?:UTC|GMT)?([+-])(\d{2}):?(\d{2})$/;
|
|
142
|
+
function formatDateIntl(date, options, locale, timezone) {
|
|
143
|
+
const offset = timezone ? OFFSET.exec(timezone) : null;
|
|
144
|
+
if (offset) {
|
|
145
|
+
const minutes = (Number(offset[2]) * 60 + Number(offset[3])) * (offset[1] === "-" ? -1 : 1);
|
|
146
|
+
return new Intl.DateTimeFormat(locale, {
|
|
147
|
+
...options,
|
|
148
|
+
timeZone: "UTC"
|
|
149
|
+
}).format(new Date(date.getTime() + minutes * MS_IN_MINUTE));
|
|
150
|
+
}
|
|
151
|
+
return new Intl.DateTimeFormat(locale, timezone ? {
|
|
152
|
+
...options,
|
|
153
|
+
timeZone: timezone
|
|
154
|
+
} : options).format(date);
|
|
155
|
+
}
|
|
129
156
|
var TxDatePipe = class TxDatePipe {
|
|
130
157
|
config = inject(TX_DATE_FORMAT_CONFIG);
|
|
158
|
+
localeService = inject(TxLocaleService);
|
|
159
|
+
lastKey = "";
|
|
160
|
+
lastText = "";
|
|
131
161
|
transform(value, format, timezone, locale) {
|
|
132
162
|
const date = toDate(value);
|
|
133
163
|
if (!date) return this.config.empty;
|
|
164
|
+
const pattern = format ?? this.config.format;
|
|
165
|
+
const zone = timezone ?? this.config.timezone;
|
|
166
|
+
const fixedLocale = locale ?? this.config.locale;
|
|
167
|
+
const activeLocale = fixedLocale ?? this.localeService.locale().intl;
|
|
168
|
+
const key = [
|
|
169
|
+
date.getTime(),
|
|
170
|
+
typeof pattern === "string" ? pattern : JSON.stringify(pattern),
|
|
171
|
+
zone,
|
|
172
|
+
activeLocale,
|
|
173
|
+
fixedLocale === void 0
|
|
174
|
+
].join("|");
|
|
175
|
+
if (key !== this.lastKey) {
|
|
176
|
+
this.lastKey = key;
|
|
177
|
+
this.lastText = this.format(date, pattern, zone, activeLocale, fixedLocale === void 0);
|
|
178
|
+
}
|
|
179
|
+
return this.lastText;
|
|
180
|
+
}
|
|
181
|
+
format(date, pattern, timezone, locale, followsActive) {
|
|
134
182
|
try {
|
|
135
|
-
return
|
|
183
|
+
if (typeof pattern !== "string") return formatDateIntl(date, pattern, locale, timezone);
|
|
184
|
+
return this.formatPattern(date, pattern, timezone, locale, followsActive) || this.config.empty;
|
|
136
185
|
} catch {
|
|
137
186
|
return this.config.empty;
|
|
138
187
|
}
|
|
139
188
|
}
|
|
189
|
+
formatPattern(date, pattern, timezone, locale, followsActive) {
|
|
190
|
+
try {
|
|
191
|
+
return formatDate(date, pattern, locale, timezone);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (!followsActive || locale === FALLBACK_LOCALE) throw error;
|
|
194
|
+
return formatDate(date, pattern, FALLBACK_LOCALE, timezone);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
140
197
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
141
198
|
minVersion: "12.0.0",
|
|
142
199
|
version: "22.2.5",
|
|
@@ -151,7 +208,8 @@ var TxDatePipe = class TxDatePipe {
|
|
|
151
208
|
ngImport: i0,
|
|
152
209
|
type: TxDatePipe,
|
|
153
210
|
isStandalone: true,
|
|
154
|
-
name: "txDate"
|
|
211
|
+
name: "txDate",
|
|
212
|
+
pure: false
|
|
155
213
|
});
|
|
156
214
|
};
|
|
157
215
|
i0.ɵɵngDeclareClassMetadata({
|
|
@@ -161,7 +219,10 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
161
219
|
type: TxDatePipe,
|
|
162
220
|
decorators: [{
|
|
163
221
|
type: Pipe,
|
|
164
|
-
args: [{
|
|
222
|
+
args: [{
|
|
223
|
+
name: "txDate",
|
|
224
|
+
pure: false
|
|
225
|
+
}]
|
|
165
226
|
}]
|
|
166
227
|
});
|
|
167
228
|
var TxDateRangePipe = class TxDateRangePipe {
|
|
@@ -195,6 +256,6 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
195
256
|
args: [{ name: "txDateRange" }]
|
|
196
257
|
}]
|
|
197
258
|
});
|
|
198
|
-
export { DAYS_IN_WEEK, HOURS_IN_DAY, MINUTES_IN_HOUR, MONTHS_IN_YEAR, MS_IN_DAY, MS_IN_HOUR, MS_IN_MINUTE, MS_IN_SECOND, MS_IN_WEEK, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, TX_DATE_FORMATS, TX_DATE_FORMAT_CONFIG, TX_DATE_FORMAT_DEFAULTS, TxDatePipe, TxDateRangePipe, addDays, addMonths, addYears, calendarDaysBetween, endOfDay, isExpiringWithin, isSameDay, isValidDate, middleOfDay, provideTxDateFormat, startOfDay, startOfWeek, toDate, toIsoDay, toIsoRange, toIsoString };
|
|
259
|
+
export { DAYS_IN_WEEK, HOURS_IN_DAY, MINUTES_IN_HOUR, MONTHS_IN_YEAR, MS_IN_DAY, MS_IN_HOUR, MS_IN_MINUTE, MS_IN_SECOND, MS_IN_WEEK, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, TX_DATE_FORMATS, TX_DATE_FORMAT_CONFIG, TX_DATE_FORMAT_DEFAULTS, TX_DATE_STYLES, TxDatePipe, TxDateRangePipe, addDays, addMonths, addYears, calendarDaysBetween, endOfDay, isExpiringWithin, isSameDay, isValidDate, middleOfDay, provideTxDateFormat, startOfDay, startOfWeek, toDate, toIsoDay, toIsoRange, toIsoString };
|
|
199
260
|
|
|
200
261
|
//# sourceMappingURL=tectra-ng-utils-date.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-date.mjs","names":[],"sources":["../../../../packages/utils/date/src/date.config.ts","../../../../packages/utils/date/src/date.constants.ts","../../../../packages/utils/date/src/date.functions.ts","../../../../packages/utils/date/src/date.pipe.ts"],"sourcesContent":["import { InjectionToken, Provider } from '@angular/core';\nimport { TxDateFormatConfig } from './date.types';\n\n/** Default date format settings: `mediumDate`, `-` for an empty value, `en-US`, the local time zone. */\nexport const TX_DATE_FORMAT_DEFAULTS: TxDateFormatConfig = {\n format: 'mediumDate',\n empty: '-',\n locale: 'en-US',\n timezone: undefined,\n};\n\n/** Date format settings used by the `txDate` pipe; set them with `provideTxDateFormat`. */\nexport const TX_DATE_FORMAT_CONFIG = new InjectionToken<TxDateFormatConfig>('TX_DATE_FORMAT_CONFIG', {\n providedIn: 'root',\n factory: () => TX_DATE_FORMAT_DEFAULTS,\n});\n\nexport function provideTxDateFormat(config: Partial<TxDateFormatConfig>): Provider {\n return { provide: TX_DATE_FORMAT_CONFIG, useValue: { ...TX_DATE_FORMAT_DEFAULTS, ...config } };\n}\n","export const MS_IN_SECOND = 1000;\n/** Seconds in a minute (60). */\nexport const SECONDS_IN_MINUTE = 60;\n/** Minutes in an hour (60). */\nexport const MINUTES_IN_HOUR = 60;\n/** Hours in a day (24). */\nexport const HOURS_IN_DAY = 24;\n/** Days in a week (7). */\nexport const DAYS_IN_WEEK = 7;\n/** Months in a year (12). */\nexport const MONTHS_IN_YEAR = 12;\n/** Seconds in an hour (3600). */\nexport const SECONDS_IN_HOUR = SECONDS_IN_MINUTE * MINUTES_IN_HOUR;\n/** Seconds in a day (86400). */\nexport const SECONDS_IN_DAY = SECONDS_IN_HOUR * HOURS_IN_DAY;\n/** Milliseconds in a minute (60000). */\nexport const MS_IN_MINUTE = MS_IN_SECOND * SECONDS_IN_MINUTE;\n/** Milliseconds in an hour (3600000). */\nexport const MS_IN_HOUR = MS_IN_MINUTE * MINUTES_IN_HOUR;\n/** Milliseconds in a day (86400000). */\nexport const MS_IN_DAY = MS_IN_HOUR * HOURS_IN_DAY;\n/** Milliseconds in a week (604800000). */\nexport const MS_IN_WEEK = MS_IN_DAY * DAYS_IN_WEEK;\n\nexport const TX_DATE_FORMATS = {\n dateTime: 'dd.MM.yy HH:mm',\n date: 'dd.MM.yyyy',\n time: 'HH:mm:ss',\n timeShort: 'HH:mm',\n isoDay: 'yyyy-MM-dd',\n isoMonth: 'yyyy-MM',\n day: 'dd',\n dayMonth: 'dd.MM',\n} as const;\n","import { DAYS_IN_WEEK, MS_IN_DAY, MS_IN_WEEK } from './date.constants';\nimport { TxDateInput, TxIsoRange } from './date.types';\n\nconst MIDDLE_OF_DAY_HOUR = 12;\n\nexport function toDate(value: TxDateInput): Date | null {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n}\n\nexport function isValidDate(value: TxDateInput): boolean {\n return toDate(value) !== null;\n}\n\nfunction copy(value: Date | string | number): Date {\n return value instanceof Date ? new Date(value.getTime()) : new Date(value);\n}\n\nexport function startOfDay(value: Date | string | number): Date {\n const date = copy(value);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n\n/** Returns a copy of the date set to 12:00 local time, away from the daylight-saving shifts around midnight. */\nexport function middleOfDay(value: Date | string | number): Date {\n const date = copy(value);\n date.setHours(MIDDLE_OF_DAY_HOUR, 0, 0, 0);\n return date;\n}\n\n/** Returns a copy of the date set to the last millisecond of the day, 23:59:59.999 local time. */\nexport function endOfDay(value: Date | string | number): Date {\n const date = copy(value);\n date.setHours(23, 59, 59, 999);\n return date;\n}\n\nexport function addDays(value: Date | string | number, days: number): Date {\n const date = copy(value);\n date.setDate(date.getDate() + days);\n return date;\n}\n\nexport function addMonths(value: Date | string | number, months: number): Date {\n const date = copy(value);\n const day = date.getDate();\n date.setDate(1);\n date.setMonth(date.getMonth() + months);\n const lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();\n date.setDate(Math.min(day, lastDay));\n return date;\n}\n\nexport function addYears(value: Date | string | number, years: number): Date {\n return addMonths(value, years * 12);\n}\n\nexport function startOfWeek(value: Date | string | number, firstDayOfWeek = 1): Date {\n const date = startOfDay(value);\n date.setDate(date.getDate() - ((date.getDay() - firstDayOfWeek + DAYS_IN_WEEK) % DAYS_IN_WEEK));\n return date;\n}\n\nexport function calendarDaysBetween(from: Date | string | number, to: Date | string | number): number {\n const start = startOfDay(from);\n const end = startOfDay(to);\n const startUtc = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());\n const endUtc = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());\n return Math.round((endUtc - startUtc) / MS_IN_DAY);\n}\n\nexport function isSameDay(a: TxDateInput, b: TxDateInput): boolean {\n const first = toDate(a);\n const second = toDate(b);\n return !!first && !!second && calendarDaysBetween(first, second) === 0;\n}\n\nexport function toIsoDay(value: Date | string | number): string {\n const date = copy(value);\n const month = String(date.getMonth() + 1).padStart(2, '0');\n const day = String(date.getDate()).padStart(2, '0');\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function toIsoString(value: TxDateInput): string | undefined {\n if (typeof value === 'string') {\n return value || undefined;\n }\n return toDate(value)?.toISOString();\n}\n\nexport function toIsoRange(range: readonly TxDateInput[] | null | undefined): TxIsoRange | null {\n if (!range || range.length !== 2) {\n return null;\n }\n const start = toDate(range[0]);\n const end = toDate(range[1]);\n return start && end ? { start: start.toISOString(), end: end.toISOString() } : null;\n}\n\nexport function isExpiringWithin(value: TxDateInput, periodMs = MS_IN_WEEK, now: Date | number = Date.now()): boolean {\n const date = toDate(value);\n return !!date && date.getTime() - new Date(now).getTime() <= periodMs;\n}\n","import { formatDate } from '@angular/common';\nimport { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TX_DATE_FORMAT_CONFIG } from './date.config';\nimport { toDate, toIsoRange } from './date.functions';\nimport { TxDateInput, TxIsoRange } from './date.types';\n\n@Pipe({ name: 'txDate' })\nexport class TxDatePipe implements PipeTransform {\n private readonly config = inject(TX_DATE_FORMAT_CONFIG);\n\n transform(value: TxDateInput, format?: string, timezone?: string, locale?: string): string {\n const date = toDate(value);\n if (!date) {\n return this.config.empty;\n }\n try {\n return formatDate(date, format ?? this.config.format, locale ?? this.config.locale, timezone ?? this.config.timezone) || this.config.empty;\n } catch {\n return this.config.empty;\n }\n }\n}\n\n@Pipe({ name: 'txDateRange' })\nexport class TxDateRangePipe implements PipeTransform {\n transform(range: readonly TxDateInput[] | null | undefined): TxIsoRange | null {\n return toIsoRange(range);\n }\n}\n"],"mappings":";;;AAIA,MAAa,0BAA8C;CACzD,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,UAAU;AACX;AAGD,MAAa,wBAAwB,IAAI,eAAmC,yBAAyB;CACnG,YAAY;CACZ,eAAe;AAChB,CAAA;AA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AA;EAAA,MAAA;EAAU,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAV,OAAA,QAAA,GAAA,gBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAU,cAAA;EAAA,MAAA;CAAA,CAAA;;AAAV,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAU,YAAA,CAAA;EADtB,MAAA;EAAK,MAAA,CAAA,EAAE,MAAM,SAAQ,CAAE;;;AAkBxB,IAAa,kBAAb,MAAa,gBAAe;CAC1B,UAAU,OAAgD;EACxD,OAAO,WAAW,KAAK;CACzB;CAHW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAe,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAf,OAAA,QAAA,GAAA,gBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAe,cAAA;EAAA,MAAA;CAAA,CAAA;;AAAf,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAe,YAAA,CAAA;EAD3B,MAAA;EAAK,MAAA,CAAA,EAAE,MAAM,cAAa,CAAE"}
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-date.mjs","names":[],"sources":["../../../../packages/utils/date/src/date.constants.ts","../../../../packages/utils/date/src/date.config.ts","../../../../packages/utils/date/src/date.functions.ts","../../../../packages/utils/date/src/date.pipe.ts"],"sourcesContent":["export const MS_IN_SECOND = 1000;\n/** Seconds in a minute (60). */\nexport const SECONDS_IN_MINUTE = 60;\n/** Minutes in an hour (60). */\nexport const MINUTES_IN_HOUR = 60;\n/** Hours in a day (24). */\nexport const HOURS_IN_DAY = 24;\n/** Days in a week (7). */\nexport const DAYS_IN_WEEK = 7;\n/** Months in a year (12). */\nexport const MONTHS_IN_YEAR = 12;\n/** Seconds in an hour (3600). */\nexport const SECONDS_IN_HOUR = SECONDS_IN_MINUTE * MINUTES_IN_HOUR;\n/** Seconds in a day (86400). */\nexport const SECONDS_IN_DAY = SECONDS_IN_HOUR * HOURS_IN_DAY;\n/** Milliseconds in a minute (60000). */\nexport const MS_IN_MINUTE = MS_IN_SECOND * SECONDS_IN_MINUTE;\n/** Milliseconds in an hour (3600000). */\nexport const MS_IN_HOUR = MS_IN_MINUTE * MINUTES_IN_HOUR;\n/** Milliseconds in a day (86400000). */\nexport const MS_IN_DAY = MS_IN_HOUR * HOURS_IN_DAY;\n/** Milliseconds in a week (604800000). */\nexport const MS_IN_WEEK = MS_IN_DAY * DAYS_IN_WEEK;\n\nexport const TX_DATE_FORMATS = {\n dateTime: 'dd.MM.yy HH:mm',\n date: 'dd.MM.yyyy',\n time: 'HH:mm:ss',\n timeShort: 'HH:mm',\n isoDay: 'yyyy-MM-dd',\n isoMonth: 'yyyy-MM',\n day: 'dd',\n dayMonth: 'dd.MM',\n} as const;\n\nexport const TX_DATE_STYLES = {\n date: { dateStyle: 'medium' },\n dateTime: { dateStyle: 'medium', timeStyle: 'short' },\n time: { timeStyle: 'short' },\n shortDate: { dateStyle: 'short' },\n longDate: { dateStyle: 'long' },\n} as const satisfies Record<string, Intl.DateTimeFormatOptions>;\n","import { InjectionToken, Provider } from '@angular/core';\nimport { TX_DATE_STYLES } from './date.constants';\nimport { TxDateFormatConfig } from './date.types';\n\n/** Default date format settings: a medium date in the tectra locale, `-` for an empty value, the local time zone. */\nexport const TX_DATE_FORMAT_DEFAULTS: TxDateFormatConfig = {\n format: TX_DATE_STYLES.date,\n empty: '-',\n locale: undefined,\n timezone: undefined,\n};\n\n/** Date format settings used by the `txDate` pipe; set them with `provideTxDateFormat`. */\nexport const TX_DATE_FORMAT_CONFIG = new InjectionToken<TxDateFormatConfig>('TX_DATE_FORMAT_CONFIG', {\n providedIn: 'root',\n factory: () => TX_DATE_FORMAT_DEFAULTS,\n});\n\nexport function provideTxDateFormat(config: Partial<TxDateFormatConfig>): Provider {\n return { provide: TX_DATE_FORMAT_CONFIG, useValue: { ...TX_DATE_FORMAT_DEFAULTS, ...config } };\n}\n","import { DAYS_IN_WEEK, MS_IN_DAY, MS_IN_WEEK } from './date.constants';\nimport { TxDateInput, TxIsoRange } from './date.types';\n\nconst MIDDLE_OF_DAY_HOUR = 12;\n\nexport function toDate(value: TxDateInput): Date | null {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n}\n\nexport function isValidDate(value: TxDateInput): boolean {\n return toDate(value) !== null;\n}\n\nfunction copy(value: Date | string | number): Date {\n return value instanceof Date ? new Date(value.getTime()) : new Date(value);\n}\n\nexport function startOfDay(value: Date | string | number): Date {\n const date = copy(value);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n\n/** Returns a copy of the date set to 12:00 local time, away from the daylight-saving shifts around midnight. */\nexport function middleOfDay(value: Date | string | number): Date {\n const date = copy(value);\n date.setHours(MIDDLE_OF_DAY_HOUR, 0, 0, 0);\n return date;\n}\n\n/** Returns a copy of the date set to the last millisecond of the day, 23:59:59.999 local time. */\nexport function endOfDay(value: Date | string | number): Date {\n const date = copy(value);\n date.setHours(23, 59, 59, 999);\n return date;\n}\n\nexport function addDays(value: Date | string | number, days: number): Date {\n const date = copy(value);\n date.setDate(date.getDate() + days);\n return date;\n}\n\nexport function addMonths(value: Date | string | number, months: number): Date {\n const date = copy(value);\n const day = date.getDate();\n date.setDate(1);\n date.setMonth(date.getMonth() + months);\n const lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();\n date.setDate(Math.min(day, lastDay));\n return date;\n}\n\nexport function addYears(value: Date | string | number, years: number): Date {\n return addMonths(value, years * 12);\n}\n\nexport function startOfWeek(value: Date | string | number, firstDayOfWeek = 1): Date {\n const date = startOfDay(value);\n date.setDate(date.getDate() - ((date.getDay() - firstDayOfWeek + DAYS_IN_WEEK) % DAYS_IN_WEEK));\n return date;\n}\n\nexport function calendarDaysBetween(from: Date | string | number, to: Date | string | number): number {\n const start = startOfDay(from);\n const end = startOfDay(to);\n const startUtc = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());\n const endUtc = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());\n return Math.round((endUtc - startUtc) / MS_IN_DAY);\n}\n\nexport function isSameDay(a: TxDateInput, b: TxDateInput): boolean {\n const first = toDate(a);\n const second = toDate(b);\n return !!first && !!second && calendarDaysBetween(first, second) === 0;\n}\n\nexport function toIsoDay(value: Date | string | number): string {\n const date = copy(value);\n const month = String(date.getMonth() + 1).padStart(2, '0');\n const day = String(date.getDate()).padStart(2, '0');\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function toIsoString(value: TxDateInput): string | undefined {\n if (typeof value === 'string') {\n return value || undefined;\n }\n return toDate(value)?.toISOString();\n}\n\nexport function toIsoRange(range: readonly TxDateInput[] | null | undefined): TxIsoRange | null {\n if (!range || range.length !== 2) {\n return null;\n }\n const start = toDate(range[0]);\n const end = toDate(range[1]);\n return start && end ? { start: start.toISOString(), end: end.toISOString() } : null;\n}\n\nexport function isExpiringWithin(value: TxDateInput, periodMs = MS_IN_WEEK, now: Date | number = Date.now()): boolean {\n const date = toDate(value);\n return !!date && date.getTime() - new Date(now).getTime() <= periodMs;\n}\n","import { formatDate } from '@angular/common';\nimport { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService } from '@tectra-ng/core/i18n';\nimport { TX_DATE_FORMAT_CONFIG } from './date.config';\nimport { MS_IN_MINUTE, MINUTES_IN_HOUR } from './date.constants';\nimport { toDate, toIsoRange } from './date.functions';\nimport { TxDateFormat, TxDateInput, TxIsoRange } from './date.types';\n\nconst FALLBACK_LOCALE = 'en-US';\nconst OFFSET = /^(?:UTC|GMT)?([+-])(\\d{2}):?(\\d{2})$/;\n\nfunction formatDateIntl(date: Date, options: Intl.DateTimeFormatOptions, locale: string, timezone?: string): string {\n const offset = timezone ? OFFSET.exec(timezone) : null;\n if (offset) {\n const minutes = (Number(offset[2]) * MINUTES_IN_HOUR + Number(offset[3])) * (offset[1] === '-' ? -1 : 1);\n return new Intl.DateTimeFormat(locale, { ...options, timeZone: 'UTC' }).format(new Date(date.getTime() + minutes * MS_IN_MINUTE));\n }\n return new Intl.DateTimeFormat(locale, timezone ? { ...options, timeZone: timezone } : options).format(date);\n}\n\n@Pipe({ name: 'txDate', pure: false })\nexport class TxDatePipe implements PipeTransform {\n private readonly config = inject(TX_DATE_FORMAT_CONFIG);\n private readonly localeService = inject(TxLocaleService);\n private lastKey = '';\n private lastText = '';\n\n transform(value: TxDateInput, format?: TxDateFormat, timezone?: string, locale?: string): string {\n const date = toDate(value);\n if (!date) {\n return this.config.empty;\n }\n const pattern = format ?? this.config.format;\n const zone = timezone ?? this.config.timezone;\n const fixedLocale = locale ?? this.config.locale;\n const activeLocale = fixedLocale ?? this.localeService.locale().intl;\n const key = [date.getTime(), typeof pattern === 'string' ? pattern : JSON.stringify(pattern), zone, activeLocale, fixedLocale === undefined].join('|');\n if (key !== this.lastKey) {\n this.lastKey = key;\n this.lastText = this.format(date, pattern, zone, activeLocale, fixedLocale === undefined);\n }\n return this.lastText;\n }\n\n private format(date: Date, pattern: TxDateFormat, timezone: string | undefined, locale: string, followsActive: boolean): string {\n try {\n if (typeof pattern !== 'string') {\n return formatDateIntl(date, pattern, locale, timezone);\n }\n return this.formatPattern(date, pattern, timezone, locale, followsActive) || this.config.empty;\n } catch {\n return this.config.empty;\n }\n }\n\n private formatPattern(date: Date, pattern: string, timezone: string | undefined, locale: string, followsActive: boolean): string {\n try {\n return formatDate(date, pattern, locale, timezone);\n } catch (error) {\n if (!followsActive || locale === FALLBACK_LOCALE) {\n throw error;\n }\n return formatDate(date, pattern, FALLBACK_LOCALE, timezone);\n }\n }\n}\n\n@Pipe({ name: 'txDateRange' })\nexport class TxDateRangePipe implements PipeTransform {\n transform(range: readonly TxDateInput[] | null | undef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;CAAA,MAAA;CAAe,YAAA,CAAA;EAD3B,MAAA;EAAK,MAAA,CAAA,EAAE,MAAM,cAAa,CAAE"}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { Pipe, inject } from "@angular/core";
|
|
3
|
-
import { TxLocaleService } from "@tectra-ng/core/i18n";
|
|
4
|
-
const UNITS = [
|
|
5
|
-
"B",
|
|
6
|
-
"KB",
|
|
7
|
-
"MB",
|
|
8
|
-
"GB",
|
|
9
|
-
"TB",
|
|
10
|
-
"PB"
|
|
11
|
-
];
|
|
3
|
+
import { TxLocaleService, formatBytes } from "@tectra-ng/core/i18n";
|
|
12
4
|
function formatFileSize(bytes, options = {}) {
|
|
13
|
-
const {
|
|
5
|
+
const { empty = "-", ...format } = options;
|
|
14
6
|
if (bytes === null || bytes === void 0 || !Number.isFinite(bytes) || bytes < 0) return empty;
|
|
15
|
-
|
|
16
|
-
const value = bytes / base ** exponent;
|
|
17
|
-
return `${new Intl.NumberFormat(locale, { maximumFractionDigits: exponent === 0 ? 0 : decimals }).format(value)} ${UNITS[exponent]}`;
|
|
7
|
+
return formatBytes(bytes, format);
|
|
18
8
|
}
|
|
19
9
|
function downloadBlob(blob, filename = "file", document = globalThis.document) {
|
|
20
10
|
const view = document?.defaultView;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-file.mjs","names":[],"sources":["../../../../packages/utils/file/src/file.ts"],"sourcesContent":["import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService } from '@tectra-ng/core/i18n';\n\n/** Options of `txFileSize` and `formatFileSize`. */\nexport interface TxFileSizeOptions {\n /** Maximum digits after the point for sizes above 1 KB (default 1). */\n decimals?: number;\n /** Size of a unit: `1024` (default) or `1000`. */\n base?: 1000 | 1024;\n /** Locale of the number format (default `en-US`; the pipe uses the tectra locale). */\n locale?: string;\n /** Text shown for a missing or negative size (default `-`). */\n empty?: string;\n}\n\
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-file.mjs","names":[],"sources":["../../../../packages/utils/file/src/file.ts"],"sourcesContent":["import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService, formatBytes } from '@tectra-ng/core/i18n';\n\n/** Options of `txFileSize` and `formatFileSize`. */\nexport interface TxFileSizeOptions {\n /** Maximum digits after the point for sizes above 1 KB (default 1). */\n decimals?: number;\n /** Size of a unit: `1024` (default) or `1000`. */\n base?: 1000 | 1024;\n /** Locale of the number format and the unit names (default `en-US`; the pipe uses the tectra locale). */\n locale?: string;\n /** Text shown for a missing or negative size (default `-`). */\n empty?: string;\n}\n\nexport function formatFileSize(bytes: number | null | undefined, options: TxFileSizeOptions = {}): string {\n const { empty = '-', ...format } = options;\n if (bytes === null || bytes === undefined || !Number.isFinite(bytes) || bytes < 0) {\n return empty;\n }\n return formatBytes(bytes, format);\n}\n\nexport function downloadBlob(blob: Blob, filename = 'file', document: Document | undefined = globalThis.document): void {\n const view = document?.defaultView;\n if (!document || !view) {\n return;\n }\n const url = view.URL.createObjectURL(blob);\n downloadFile(url, filename, document);\n view.setTimeout(() => view.URL.revokeObjectURL(url));\n}\n\nexport function downloadFile(url: string, filename?: string, document: Document | undefined = globalThis.document): void {\n if (!document?.body) {\n return;\n }\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.download = filename ?? url.split(/[?#]/)[0].split('/').pop() ?? 'file';\n anchor.rel = 'noopener';\n anchor.style.display = 'none';\n document.body.appendChild(anchor);\n anchor.click();\n document.body.removeChild(anchor);\n}\n\n@Pipe({ name: 'txFileSize', pure: false })\nexport class TxFileSizePipe implements PipeTransform {\n private readonly localeService = inject(TxLocaleService);\n\n transform(bytes: number | null | undefined, options: TxFileSizeOptions = {}): string {\n return formatFileSize(bytes, { ...options, locale: options.locale ?? this.localeService.locale().intl });\n }\n}\n"],"mappings":";;;AAeA,SAAgB,eAAe,OAAkC,UAA6B,CAAA,GAAE;CAC9F,MAAM,EAAE,QAA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AAAd,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAc,YAAA,CAAA;EAD1B,MAAA;EAAK,MAAA,CAAA;GAAE,MAAM;GAAc,MAAM;EAAK,CAAE"}
|
|
@@ -145,7 +145,10 @@ function txFilterState(options) {
|
|
|
145
145
|
const { key, initial } = options;
|
|
146
146
|
const storage = options.storage === false ? null : injectStorage(options.storage ?? "local");
|
|
147
147
|
const router = options.url ? inject(Router, { optional: true }) : null;
|
|
148
|
-
const value = signal(initial,
|
|
148
|
+
const value = signal(initial, {
|
|
149
|
+
...ngDevMode ? { debugName: "value" } : /* istanbul ignore next */ {},
|
|
150
|
+
equal: isSameValue
|
|
151
|
+
});
|
|
149
152
|
const sync = router ? new TxUrlSync(router, () => initial, inject(DestroyRef), (filters) => value.set(filters)) : null;
|
|
150
153
|
const stored = storage ? readJson(storage, key) : null;
|
|
151
154
|
value.set(sync?.read() ?? (stored && typeof stored === "object" ? {
|
|
@@ -153,6 +156,7 @@ function txFilterState(options) {
|
|
|
153
156
|
...stored
|
|
154
157
|
} : initial));
|
|
155
158
|
const set = (filters) => {
|
|
159
|
+
if (isSameValue(filters, untracked(value))) return;
|
|
156
160
|
value.set(filters);
|
|
157
161
|
if (storage) {
|
|
158
162
|
if (isSameValue(filters, initial)) storage.removeItem(key);
|
|
@@ -166,7 +170,7 @@ function txFilterState(options) {
|
|
|
166
170
|
changed: computed(() => Object.keys(initial).filter((name) => !isSameValue(value()[name], initial[name]))),
|
|
167
171
|
set,
|
|
168
172
|
patch: (filters) => set({
|
|
169
|
-
...value
|
|
173
|
+
...untracked(value),
|
|
170
174
|
...filters
|
|
171
175
|
}),
|
|
172
176
|
reset: () => set(initial)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-filter-state.mjs","names":[],"sources":["../../../../packages/utils/filter-state/src/storage.ts","../../../../packages/utils/filter-state/src/url-filters.functions.ts","../../../../packages/utils/filter-state/src/url-sync.ts","../../../../packages/utils/filter-state/src/filter-state.ts","../../../../packages/utils/filter-state/src/filter-state.base.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport { InjectionToken, inject } from '@angular/core';\nimport { TxStorageKind } from './filter-state.types';\n\n/**\n * A `Storage` that lives in memory; used when the browser storage is missing or blocked, and on the\n * server.\n */\nexport class TxMemoryStorage implements Storage {\n private readonly items = new Map<string, string>();\n\n constructor(source?: Storage) {\n if (!source) {\n return;\n }\n for (let index = 0; index < source.length; index++) {\n const key = source.key(index);\n if (key !== null) {\n this.items.set(key, source.getItem(key) ?? '');\n }\n }\n }\n\n /** Number of stored items. */\n get length(): number {\n return this.items.size;\n }\n\n /** Removes all items. */\n clear(): void {\n this.items.clear();\n }\n\n /** Returns the value of a key, or `null`. */\n getItem(key: string): string | null {\n return this.items.get(key) ?? null;\n }\n\n /** Returns the key at the given position, or `null`. */\n key(index: number): string | null {\n return Array.from(this.items.keys())[index] ?? null;\n }\n\n /** Removes a key. */\n removeItem(key: string): void {\n this.items.delete(key);\n }\n\n /** Stores a value under a key. */\n setItem(key: string, value: string): void {\n this.items.set(key, String(value));\n }\n}\n\nconst MEMORY = new InjectionToken<Record<TxStorageKind, TxMemoryStorage>>('TX_MEMORY_STORAGE', {\n providedIn: 'root',\n factory: () => ({ local: new TxMemoryStorage(), session: new TxMemoryStorage(), memory: new TxMemoryStorage() }),\n});\n\nexport function injectStorage(kind: TxStorageKind = 'local'): Storage {\n const memory = inject(MEMORY);\n const view = inject(DOCUMENT).defaultView;\n if (kind === 'memory' || !view) {\n return memory[kind];\n }\n try {\n const storage = kind === 'local' ? view.localStorage : view.sessionStorage;\n const probe = '__tx_storage__';\n storage.setItem(probe, probe);\n storage.removeItem(probe);\n return storage;\n } catch {\n return memory[kind];\n }\n}\n\nexport function readJson<T>(storage: Storage, key: string): T | null {\n const stored = storage.getItem(key);\n if (stored === null) {\n return null;\n }\n try {\n return JSON.parse(stored) as T;\n } catch {\n return null;\n }\n}\n\n/** Saves a value as JSON in the storage; ignores a full or blocked storage. */\nexport function writeJson(storage: Storage, key: string, value: unknown): void {\n try {\n storage.setItem(key, JSON.stringify(value));\n } catch {\n return;\n }\n}\n","import { Params } from '@angular/router';\n\n/** Compares two values by their JSON text. */\nexport function isSameValue(a: unknown, b: unknown): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}\n\nfunction isJson(value: string): boolean {\n if (value === '') {\n return false;\n }\n try {\n JSON.parse(value);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function encodeUrlFilterValue(value: unknown): string {\n if (typeof value !== 'string') {\n return JSON.stringify(value);\n }\n return isJson(value) ? JSON.stringify(value) : value;\n}\n\n/** Turns a query parameter back into a filter value: parsed when it is JSON, otherwise the plain text. */\nexport function decodeUrlFilterValue(value: string): unknown {\n return isJson(value) ? JSON.parse(value) : value;\n}\n\nexport function filtersToQueryParams<T extends object>(filters: T, initial: T): Params {\n return (Object.keys(initial) as (keyof T & string)[]).reduce<Params>((params, key) => {\n params[key] = isSameValue(filters[key], initial[key]) ? null : encodeUrlFilterValue(filters[key]);\n return params;\n }, {});\n}\n\nexport function queryParamsToFilters<T extends object>(params: Params, initial: T): T | null {\n const keys = Object.keys(initial).filter((key) => key in params);\n if (!keys.length) {\n return null;\n }\n return keys.reduce<T>((filters, key) => ({ ...filters, [key]: decodeUrlFilterValue(String(params[key])) }), { ...initial });\n}\n","import { DestroyRef, untracked } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { NavigationEnd, NavigationStart, Router, UrlTree } from '@angular/router';\nimport { filter, pairwise, startWith } from 'rxjs';\nimport { filtersToQueryParams, isSameValue, queryParamsToFilters } from './url-filters.functions';\n\nexport class TxUrlSync<T extends object> {\n private readonly path: string;\n private written = false;\n\n constructor(\n private readonly router: Router,\n private readonly initial: () => T,\n destroyRef: DestroyRef,\n onHistory: (filters: T) => void,\n ) {\n this.path = this.pathOf(this.currentTree());\n router.events\n .pipe(\n filter((event) => event instanceof NavigationStart || event instanceof NavigationEnd),\n startWith(null),\n pairwise(),\n filter(([previous, current]) => current instanceof NavigationEnd && previous instanceof NavigationStart && previous.navigationTrigger === 'popstate'),\n takeUntilDestroyed(destroyRef),\n )\n .subscribe(() => {\n const tree = router.parseUrl(router.url);\n if (this.pathOf(tree) === this.path) {\n onHistory(queryParamsToFilters(tree.queryParams, this.initial()) ?? this.initial());\n }\n });\n }\n\n read(): T | null {\n return queryParamsToFilters(this.currentTree().queryParams, this.initial());\n }\n\n write(filters: T): void {\n const tree = this.router.parseUrl(this.router.url);\n const replaceUrl = !this.written;\n this.written = true;\n if (this.pathOf(tree) !== this.path) {\n return;\n }\n const queryParams = { ...tree.queryParams };\n Object.entries(filtersToQueryParams(filters, this.initial())).forEach(([key, value]) => {\n if (value === null) {\n delete queryParams[key];\n } else {\n queryParams[key] = value;\n }\n });\n if (isSameValue(queryParams, tree.queryParams)) {\n return;\n }\n tree.queryParams = queryParams;\n void this.router.navigateByUrl(tree, { replaceUrl });\n }\n\n private currentTree(): UrlTree {\n return untracked(() => this.router.currentNavigation()?.finalUrl) ?? this.router.parseUrl(this.router.url);\n }\n\n private pathOf(tree: UrlTree): string {\n return this.router.serializeUrl(tree).split(/[?#]/)[0];\n }\n}\n","import { DestroyRef, computed, inject, signal } from '@angular/core';\nimport { Router } from '@angular/router';\nimport { TxFilterState, TxFilterStateOptions } from './filter-state.types';\nimport { injectStorage, readJson, writeJson } from './storage';\nimport { isSameValue } from './url-filters.functions';\nimport { TxUrlSync } from './url-sync';\n\nexport function txFilterState<T extends object>(options: TxFilterStateOptions<T>): TxFilterState<T> {\n const { key, initial } = options;\n const storage = options.storage === false ? null : injectStorage(options.storage ?? 'local');\n const router = options.url ? inject(Router, { optional: true }) : null;\n const value = signal<T>(initial);\n const sync = router ? new TxUrlSync<T>(router, () => initial, inject(DestroyRef), (filters) => value.set(filters)) : null;\n const stored = storage ? readJson<Partial<T>>(storage, key) : null;\n value.set(sync?.read() ?? (stored && typeof stored === 'object' ? { ...initial, ...stored } : initial));\n\n const set = (filters: T): void => {\n value.set(filters);\n if (storage) {\n if (isSameValue(filters, initial)) {\n storage.removeItem(key);\n } else {\n writeJson(storage, key, filters);\n }\n }\n sync?.write(filters);\n };\n\n return {\n value: value.asReadonly(),\n isInitial: computed(() => isSameValue(value(), initial)),\n changed: computed(() => (Object.keys(initial) as (keyof T)[]).filter((name) => !isSameValue(value()[name], initial[name]))),\n set,\n patch: (filters) => set({ ...value(), ...filters }),\n reset: () => set(initial),\n };\n}\n","import { DestroyRef, Injectable, inject } from '@angular/core';\nimport { Router } from '@angular/router';\nimport { injectStorage, readJson, writeJson } from './storage';\nimport { TxUrlSync } from './url-sync';\n\n/** Base class for a filters service that keeps its filters in local storage; set `localStorageKey`. */\n@Injectable()\nexport abstract class TxSaveFilters<T> {\n private readonly filterStorage = injectStorage('local');\n\n protected abstract localStorageKey: string;\n\n protected storeFilters(filters: T): void {\n writeJson(this.filterStorage, this.localStorageKey, filters);\n }\n\n protected getStoredFilters(): T | null {\n return readJson<T>(this.filterStorage, this.localStorageKey);\n }\n}\n\n/**\n * Base class for a filters service that keeps its filters in local storage and in the query string;\n * set `localStorageKey` and `initialFilters()`.\n */\n@Injectable()\nexport abstract class TxUrlFilters<T extends object> extends TxSaveFilters<T> {\n private readonly urlSync = new TxUrlSync<T>(inject(Router), () => this.initialFilters(), inject(DestroyRef), (filters) => this.applyUrlFilters?.(filters));\n\n protected abstract initialFilters(): T;\n\n protected applyUrlFilters?(filters: T): void;\n\n protected override storeFilters(filters: T): void {\n super.storeFilters(filters);\n this.urlSync.write(filters);\n }\n\n protected override getStoredFilters(): T | null {\n return this.urlSync.read() ?? super.getStoredFilters();\n }\n}\n"],"mappings":";;;;;;AAQA,IAAa,kBAAb,MAA4B;CACT,wBAAQ,IAAI,IAAG;CAEhC,YAAY,QAAgB;EAC1B,IAAI,CAAC,QACH;EAEF,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAA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;CAC7D;CAXoB,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAa,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAb,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAa,CAAA;;AAAb,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAa,YAAA,CAAA,EADlC,MAAA,W;;AAoBD,IAAsB,eAAtB,MAAsB,qBAAuC,cAAgB;CAC1D,UAAU,IAAI,UAAa,OAAO,MAAM,SAAS,KAAK,eAAc,GAAI,OAAO,UAAU,IAAI,YAAY,KAAK,kBAAkB,OAAO,CAAC;CAMtI,aAAa,SAAU;EACxC,MAAM,aAAa,OAAO;EAC1B,KAAK,QAAQ,MAAM,OAAO;CAC5B;CAEmB,mBAAgB;EACjC,OAAO,KAAK,QAAQ,KAAI,KAAM,MAAM,iBAAgB;CACtD;CAdoB,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAY,MAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAZ,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAY,CAAA;;AAAZ,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAY,YAAA,CAAA,EADjC,MAAA,W"}
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-filter-state.mjs","names":[],"sources":["../../../../packages/utils/filter-state/src/storage.ts","../../../../packages/utils/filter-state/src/url-filters.functions.ts","../../../../packages/utils/filter-state/src/url-sync.ts","../../../../packages/utils/filter-state/src/filter-state.ts","../../../../packages/utils/filter-state/src/filter-state.base.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport { InjectionToken, inject } from '@angular/core';\nimport { TxStorageKind } from './filter-state.types';\n\n/**\n * A `Storage` that lives in memory; used when the browser storage is missing or blocked, and on the\n * server.\n */\nexport class TxMemoryStorage implements Storage {\n private readonly items = new Map<string, string>();\n\n constructor(source?: Storage) {\n if (!source) {\n return;\n }\n for (let index = 0; index < source.length; index++) {\n const key = source.key(index);\n if (key !== null) {\n this.items.set(key, source.getItem(key) ?? '');\n }\n }\n }\n\n /** Number of stored items. */\n get length(): number {\n return this.items.size;\n }\n\n /** Removes all items. */\n clear(): void {\n this.items.clear();\n }\n\n /** Returns the value of a key, or `null`. */\n getItem(key: string): string | null {\n return this.items.get(key) ?? null;\n }\n\n /** Returns the key at the given position, or `null`. */\n key(index: number): string | null {\n return Array.from(this.items.keys())[index] ?? null;\n }\n\n /** Removes a key. */\n removeItem(key: string): void {\n this.items.delete(key);\n }\n\n /** Stores a value under a key. */\n setItem(key: string, value: string): void {\n this.items.set(key, String(value));\n }\n}\n\nconst MEMORY = new InjectionToken<Record<TxStorageKind, TxMemoryStorage>>('TX_MEMORY_STORAGE', {\n providedIn: 'root',\n factory: () => ({ local: new TxMemoryStorage(), session: new TxMemoryStorage(), memory: new TxMemoryStorage() }),\n});\n\nexport function injectStorage(kind: TxStorageKind = 'local'): Storage {\n const memory = inject(MEMORY);\n const view = inject(DOCUMENT).defaultView;\n if (kind === 'memory' || !view) {\n return memory[kind];\n }\n try {\n const storage = kind === 'local' ? view.localStorage : view.sessionStorage;\n const probe = '__tx_storage__';\n storage.setItem(probe, probe);\n storage.removeItem(probe);\n return storage;\n } catch {\n return memory[kind];\n }\n}\n\nexport function readJson<T>(storage: Storage, key: string): T | null {\n const stored = storage.getItem(key);\n if (stored === null) {\n return null;\n }\n try {\n return JSON.parse(stored) as T;\n } catch {\n return null;\n }\n}\n\n/** Saves a value as JSON in the storage; ignores a full or blocked storage. */\nexport function writeJson(storage: Storage, key: string, value: unknown): void {\n try {\n storage.setItem(key, JSON.stringify(value));\n } catch {\n return;\n }\n}\n","import { Params } from '@angular/router';\n\n/** Compares two values by their JSON text. */\nexport function isSameValue(a: unknown, b: unknown): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}\n\nfunction isJson(value: string): boolean {\n if (value === '') {\n return false;\n }\n try {\n JSON.parse(value);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function encodeUrlFilterValue(value: unknown): string {\n if (typeof value !== 'string') {\n return JSON.stringify(value);\n }\n return isJson(value) ? JSON.stringify(value) : value;\n}\n\n/** Turns a query parameter back into a filter value: parsed when it is JSON, otherwise the plain text. */\nexport function decodeUrlFilterValue(value: string): unknown {\n return isJson(value) ? JSON.parse(value) : value;\n}\n\nexport function filtersToQueryParams<T extends object>(filters: T, initial: T): Params {\n return (Object.keys(initial) as (keyof T & string)[]).reduce<Params>((params, key) => {\n params[key] = isSameValue(filters[key], initial[key]) ? null : encodeUrlFilterValue(filters[key]);\n return params;\n }, {});\n}\n\nexport function queryParamsToFilters<T extends object>(params: Params, initial: T): T | null {\n const keys = Object.keys(initial).filter((key) => key in params);\n if (!keys.length) {\n return null;\n }\n return keys.reduce<T>((filters, key) => ({ ...filters, [key]: decodeUrlFilterValue(String(params[key])) }), { ...initial });\n}\n","import { DestroyRef, untracked } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { NavigationEnd, NavigationStart, Router, UrlTree } from '@angular/router';\nimport { filter, pairwise, startWith } from 'rxjs';\nimport { filtersToQueryParams, isSameValue, queryParamsToFilters } from './url-filters.functions';\n\nexport class TxUrlSync<T extends object> {\n private readonly path: string;\n private written = false;\n\n constructor(\n private readonly router: Router,\n private readonly initial: () => T,\n destroyRef: DestroyRef,\n onHistory: (filters: T) => void,\n ) {\n this.path = this.pathOf(this.currentTree());\n router.events\n .pipe(\n filter((event) => event instanceof NavigationStart || event instanceof NavigationEnd),\n startWith(null),\n pairwise(),\n filter(([previous, current]) => current instanceof NavigationEnd && previous instanceof NavigationStart && previous.navigationTrigger === 'popstate'),\n takeUntilDestroyed(destroyRef),\n )\n .subscribe(() => {\n const tree = router.parseUrl(router.url);\n if (this.pathOf(tree) === this.path) {\n onHistory(queryParamsToFilters(tree.queryParams, this.initial()) ?? this.initial());\n }\n });\n }\n\n read(): T | null {\n return queryParamsToFilters(this.currentTree().queryParams, this.initial());\n }\n\n write(filters: T): void {\n const tree = this.router.parseUrl(this.router.url);\n const replaceUrl = !this.written;\n this.written = true;\n if (this.pathOf(tree) !== this.path) {\n return;\n }\n const queryParams = { ...tree.queryParams };\n Object.entries(filtersToQueryParams(filters, this.initial())).forEach(([key, value]) => {\n if (value === null) {\n delete queryParams[key];\n } else {\n queryParams[key] = value;\n }\n });\n if (isSameValue(queryParams, tree.queryParams)) {\n return;\n }\n tree.queryParams = queryParams;\n void this.router.navigateByUrl(tree, { replaceUrl });\n }\n\n private currentTree(): UrlTree {\n return untracked(() => this.router.currentNavigation()?.finalUrl) ?? this.router.parseUrl(this.router.url);\n }\n\n private pathOf(tree: UrlTree): string {\n return this.router.serializeUrl(tree).split(/[?#]/)[0];\n }\n}\n","import { DestroyRef, computed, inject, signal, untracked } from '@angular/core';\nimport { Router } from '@angular/router';\nimport { TxFilterState, TxFilterStateOptions } from './filter-state.types';\nimport { injectStorage, readJson, writeJson } from './storage';\nimport { isSameValue } from './url-filters.functions';\nimport { TxUrlSync } from './url-sync';\n\nexport function txFilterState<T extends object>(options: TxFilterStateOptions<T>): TxFilterState<T> {\n const { key, initial } = options;\n const storage = options.storage === false ? null : injectStorage(options.storage ?? 'local');\n const router = options.url ? inject(Router, { optional: true }) : null;\n const value = signal<T>(initial, { equal: isSameValue });\n const sync = router ? new TxUrlSync<T>(router, () => initial, inject(DestroyRef), (filters) => value.set(filters)) : null;\n const stored = storage ? readJson<Partial<T>>(storage, key) : null;\n value.set(sync?.read() ?? (stored && typeof stored === 'object' ? { ...initial, ...stored } : initial));\n\n const set = (filters: T): void => {\n if (isSameValue(filters, untracked(value))) {\n return;\n }\n value.set(filters);\n if (storage) {\n if (isSameValue(filters, initial)) {\n storage.removeItem(key);\n } else {\n writeJson(storage, key, filters);\n }\n }\n sync?.write(filters);\n };\n\n return {\n value: value.asReadonly(),\n isInitial: computed(() => isSameValue(value(), initial)),\n changed: computed(() => (Object.keys(initial) as (keyof T)[]).filter((name) => !isSameValue(value()[name], initial[name]))),\n set,\n patch: (filters) => set({ ...untracked(value), ...filters }),\n reset: () => set(initial),\n };\n}\n","import { DestroyRef, Injectable, inject } from '@angular/core';\nimport { Router } from '@angular/router';\nimport { injectStorage, readJson, writeJson } from './storage';\nimport { TxUrlSync } from './url-sync';\n\n/** Base class for a filters service that keeps its filters in local storage; set `localStorageKey`. */\n@Injectable()\nexport abstract class TxSaveFilters<T> {\n private readonly filterStorage = injectStorage('local');\n\n protected abstract localStorageKey: string;\n\n protected storeFilters(filters: T): void {\n writeJson(this.filterStorage, this.localStorageKey, filters);\n }\n\n protected getStoredFilters(): T | null {\n return readJson<T>(this.filterStorage, this.localStorageKey);\n }\n}\n\n/**\n * Base class for a filters service that keeps its filters in local storage and in the query string;\n * set `localStorageKey` and `initialFilters()`.\n */\n@Injectable()\nexport abstract class TxUrlFilters<T extends object> extends TxSaveFilters<T> {\n private readonly urlSync = new TxUrlSync<T>(inject(Router), () => this.initialFilters(), inject(DestroyRef), (filters) => this.applyUrlFilters?.(filters));\n\n protected abstract initialFilters(): T;\n\n protected applyUrlFilters?(filters: T): void;\n\n protected override storeFilters(filters: T): void {\n super.storeFilters(filters);\n this.urlSync.write(filters);\n }\n\n protected override getStoredFilters(): T | null {\n return this.urlSync.read() ?? super.getStoredFilters();\n }\n}\n"],"mappings":";;;;;;AAQA,IAAa,kBAAb,MAA4B;CACT,wBAAQ,IAAI,IAAG;CAEhC,YAAY,QAAgB;EAC1B,IAAI,CAAC,QACH;EAEF,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;GAClD,MAAM,MAAM,OAAO,IAAI,KAAK;GAC5B,IAAI,QAAQ,M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eAAe;CAC7D;CAXoB,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAa,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAb,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAa,CAAA;;AAAb,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAa,YAAA,CAAA,EADlC,MAAA,W;;AAoBD,IAAsB,eAAtB,MAAsB,qBAAuC,cAAgB;CAC1D,UAAU,IAAI,UAAa,OAAO,MAAM,SAAS,KAAK,eAAc,GAAI,OAAO,UAAU,IAAI,YAAY,KAAK,kBAAkB,OAAO,CAAC;CAMtI,aAAa,SAAU;EACxC,MAAM,aAAa,OAAO;EAC1B,KAAK,QAAQ,MAAM,OAAO;CAC5B;CAEmB,mBAAgB;EACjC,OAAO,KAAK,QAAQ,KAAI,KAAM,MAAM,iBAAgB;CACtD;CAdoB,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAY,MAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAZ,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAY,CAAA;;AAAZ,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAY,YAAA,CAAA,EADjC,MAAA,W"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Pipe, inject } from "@angular/core";
|
|
3
|
+
import { TxLocaleService } from "@tectra-ng/core/i18n";
|
|
4
|
+
function formatLocaleNumber(value, options = {}) {
|
|
5
|
+
const { locale = "en-US", empty = "-", ...format } = options;
|
|
6
|
+
const number = typeof value === "string" ? value.trim() === "" ? NaN : Number(value) : value;
|
|
7
|
+
if (number === null || number === void 0 || typeof number === "number" && !Number.isFinite(number)) return empty;
|
|
8
|
+
try {
|
|
9
|
+
return new Intl.NumberFormat(locale, format).format(number);
|
|
10
|
+
} catch {
|
|
11
|
+
return empty;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
var TxNumberPipe = class TxNumberPipe {
|
|
15
|
+
localeService = inject(TxLocaleService);
|
|
16
|
+
lastKey = "";
|
|
17
|
+
lastText = "";
|
|
18
|
+
transform(value, options = {}) {
|
|
19
|
+
const locale = options.locale ?? this.localeService.locale().intl;
|
|
20
|
+
const key = `${typeof value}|${String(value)}|${locale}|${JSON.stringify(options)}`;
|
|
21
|
+
if (key !== this.lastKey) {
|
|
22
|
+
this.lastKey = key;
|
|
23
|
+
this.lastText = formatLocaleNumber(value, {
|
|
24
|
+
...options,
|
|
25
|
+
locale
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return this.lastText;
|
|
29
|
+
}
|
|
30
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
31
|
+
minVersion: "12.0.0",
|
|
32
|
+
version: "22.2.5",
|
|
33
|
+
ngImport: i0,
|
|
34
|
+
type: TxNumberPipe,
|
|
35
|
+
deps: [],
|
|
36
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
37
|
+
});
|
|
38
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
39
|
+
minVersion: "14.0.0",
|
|
40
|
+
version: "22.2.5",
|
|
41
|
+
ngImport: i0,
|
|
42
|
+
type: TxNumberPipe,
|
|
43
|
+
isStandalone: true,
|
|
44
|
+
name: "txNumber",
|
|
45
|
+
pure: false
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
49
|
+
minVersion: "12.0.0",
|
|
50
|
+
version: "22.2.5",
|
|
51
|
+
ngImport: i0,
|
|
52
|
+
type: TxNumberPipe,
|
|
53
|
+
decorators: [{
|
|
54
|
+
type: Pipe,
|
|
55
|
+
args: [{
|
|
56
|
+
name: "txNumber",
|
|
57
|
+
pure: false
|
|
58
|
+
}]
|
|
59
|
+
}]
|
|
60
|
+
});
|
|
61
|
+
export { TxNumberPipe, formatLocaleNumber };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=tectra-ng-utils-number.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-number.mjs","names":[],"sources":["../../../../packages/utils/number/src/number.ts"],"sourcesContent":["import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService } from '@tectra-ng/core/i18n';\n\n/** Options of `txNumber` and `formatLocaleNumber`: `Intl.NumberFormat` options with a locale and an empty text. */\nexport interface TxNumberOptions extends Intl.NumberFormatOptions {\n /** Locale of the format (default `en-US`; the pipe uses the tectra locale). */\n locale?: string;\n /** Text shown for a missing or non-numeric value (default `-`). */\n empty?: string;\n}\n\n/** Anything `txNumber` accepts: a number, a numeric string, a bigint, or nothing. */\nexport type TxNumberInput = number | bigint | string | null | undefined;\n\nexport function formatLocaleNumber(value: TxNumberInput, options: TxNumberOptions = {}): string {\n const { locale = 'en-US', empty = '-', ...format } = options;\n const number = typeof value === 'string' ? (value.trim() === '' ? Number.NaN : Number(value)) : value;\n if (number === null || number === undefined || (typeof number === 'number' && !Number.isFinite(number))) {\n return empty;\n }\n try {\n return new Intl.NumberFormat(locale, format).format(number);\n } catch {\n return empty;\n }\n}\n\n@Pipe({ name: 'txNumber', pure: false })\nexport class TxNumberPipe implements PipeTransform {\n private readonly localeService = inject(TxLocaleService);\n private lastKey = '';\n private lastText = '';\n\n transform(value: TxNumberInput, options: TxNumberOptions = {}): string {\n const locale = options.locale ?? this.localeService.locale().intl;\n const key = `${typeof value}|${String(value)}|${locale}|${JSON.stringify(options)}`;\n if (key !== this.lastKey) {\n this.lastKey = key;\n this.lastText = formatLocaleNumber(value, { ...options, locale });\n }\n return this.lastText;\n }\n}\n"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AAE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ViewportScroller } from "@angular/common";
|
|
2
|
+
import { DOCUMENT, DestroyRef, inject, makeEnvironmentProviders, provideEnvironmentInitializer } from "@angular/core";
|
|
3
|
+
import { NavigationEnd, NavigationStart, Router } from "@angular/router";
|
|
4
|
+
function pathOf(router, url) {
|
|
5
|
+
const tree = router.parseUrl(url);
|
|
6
|
+
tree.queryParams = {};
|
|
7
|
+
tree.fragment = null;
|
|
8
|
+
return router.serializeUrl(tree);
|
|
9
|
+
}
|
|
10
|
+
function setUpScrolling() {
|
|
11
|
+
const view = inject(DOCUMENT).defaultView;
|
|
12
|
+
if (!view) return;
|
|
13
|
+
const router = inject(Router);
|
|
14
|
+
const scroller = inject(ViewportScroller);
|
|
15
|
+
const positions = /* @__PURE__ */ new Map();
|
|
16
|
+
let currentId = 0;
|
|
17
|
+
let currentPath;
|
|
18
|
+
let popstate = false;
|
|
19
|
+
let restoreId = 0;
|
|
20
|
+
let pending;
|
|
21
|
+
const later = (scroll) => {
|
|
22
|
+
pending?.();
|
|
23
|
+
let done = false;
|
|
24
|
+
const run = () => {
|
|
25
|
+
if (!done) {
|
|
26
|
+
done = true;
|
|
27
|
+
scroll();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const timer = view.setTimeout(run);
|
|
31
|
+
const frame = view.requestAnimationFrame?.(run);
|
|
32
|
+
pending = () => {
|
|
33
|
+
done = true;
|
|
34
|
+
view.clearTimeout(timer);
|
|
35
|
+
if (frame !== void 0) view.cancelAnimationFrame?.(frame);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
scroller.setHistoryScrollRestoration("manual");
|
|
39
|
+
const subscription = router.events.subscribe((event) => {
|
|
40
|
+
if (event instanceof NavigationStart) {
|
|
41
|
+
positions.set(currentId, scroller.getScrollPosition());
|
|
42
|
+
popstate = event.navigationTrigger === "popstate";
|
|
43
|
+
restoreId = event.restoredState?.navigationId ?? 0;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!(event instanceof NavigationEnd)) return;
|
|
47
|
+
const previousPath = currentPath;
|
|
48
|
+
currentId = event.id;
|
|
49
|
+
currentPath = pathOf(router, event.urlAfterRedirects);
|
|
50
|
+
const saved = popstate ? positions.get(restoreId) : void 0;
|
|
51
|
+
if (saved) later(() => scroller.scrollToPosition(saved));
|
|
52
|
+
else if (previousPath !== void 0 && !router.parseUrl(event.urlAfterRedirects).fragment && currentPath !== previousPath) later(() => scroller.scrollToPosition([0, 0]));
|
|
53
|
+
});
|
|
54
|
+
inject(DestroyRef).onDestroy(() => {
|
|
55
|
+
pending?.();
|
|
56
|
+
subscription.unsubscribe();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function provideTxScrolling() {
|
|
60
|
+
return makeEnvironmentProviders([provideEnvironmentInitializer(setUpScrolling)]);
|
|
61
|
+
}
|
|
62
|
+
export { provideTxScrolling };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=tectra-ng-utils-scrolling.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-scrolling.mjs","names":[],"sources":["../../../../packages/utils/scrolling/src/scrolling.ts"],"sourcesContent":["import { ViewportScroller } from '@angular/common';\nimport { DOCUMENT, DestroyRef, EnvironmentProviders, inject, makeEnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';\nimport { NavigationEnd, NavigationStart, Router } from '@angular/router';\n\nfunction pathOf(router: Router, url: string): string {\n const tree = router.parseUrl(url);\n tree.queryParams = {};\n tree.fragment = null;\n return router.serializeUrl(tree);\n}\n\nfunction setUpScrolling(): void {\n const view = inject(DOCUMENT).defaultView;\n if (!view) {\n return;\n }\n const router = inject(Router);\n const scroller = inject(ViewportScroller);\n const positions = new Map<number, [number, number]>();\n let currentId = 0;\n let currentPath: string | undefined;\n let popstate = false;\n let restoreId = 0;\n let pending: (() => void) | undefined;\n\n const later = (scroll: () => void) => {\n pending?.();\n let done = false;\n const run = () => {\n if (!done) {\n done = true;\n scroll();\n }\n };\n const timer = view.setTimeout(run);\n const frame = view.requestAnimationFrame?.(run);\n pending = () => {\n done = true;\n view.clearTimeout(timer);\n if (frame !== undefined) {\n view.cancelAnimationFrame?.(frame);\n }\n };\n };\n\n scroller.setHistoryScrollRestoration('manual');\n const subscription = router.events.subscribe((event) => {\n if (event instanceof NavigationStart) {\n positions.set(currentId, scroller.getScrollPosition());\n popstate = event.navigationTrigger === 'popstate';\n restoreId = event.restoredState?.navigationId ?? 0;\n return;\n }\n if (!(event instanceof NavigationEnd)) {\n return;\n }\n const previousPath = currentPath;\n currentId = event.id;\n currentPath = pathOf(router, event.urlAfterRedirects);\n const saved = popstate ? positions.get(restoreId) : undefined;\n if (saved) {\n later(() => scroller.scrollToPosition(saved));\n } else if (previousPath !== undefined && !router.parseUrl(event.urlAfterRedirects).fragment && currentPath !== previousPath) {\n later(() => scroller.scrollToPosition([0, 0]));\n }\n });\n inject(DestroyRef).onDestroy(() => {\n pending?.();\n subscription.unsubscribe();\n });\n}\n\nexport function provideTxScrolling(): EnvironmentProviders {\n return makeEnvironmentProviders([provideEnvironmentInitializer(setUpScrolling)]);\n}\n"],"mappings":";;;AAIA,SAAS,OAAO,QAAgB,KAAW;CACzC,MAAM,OAAO,OAAO,SAAS,GAAG;CAChC,KAAK,cAAc,CAAA;CACnB,KAAK,WAAW;CAChB,OAAO,OAAO,aAAa,IAAI;AACjC;AAEA,SAAS,iBAAc;CACrB,MAAM,OAAO,OAAO,QAAQ,CAAC,CAAC;CAC9B,IAAI,CAAC,MACH;CAEF,MAAM,SAAS,OAAO,MAAM;CAC5B,MAAM,WAAW,OAAO,gBAAgB;CACxC,MAAM,4BAAY,IAAI,IAAG;CACzB,IAAI,YAAY;CAChB,IAAI;CACJ,IAAI,WAAW;CACf,IAAI,YAAY;CAChB,IAAI;CAEJ,MAAM,SAAS,WAAsB;EACnC,UAAS;EACT,IAAI,OAAO;EACX,MAAM,YAAW;GACf,IAAI,CAAC,MAAM;IACT,OAAO;IACP,OAAM;GACR;EACF;EACA,MAAM,QAAQ,KAAK,WAAW,GAAG;EACjC,MAAM,QAAQ,KAAK,wBAAwB,GAAG;EAC9C,gBAAe;GACb,OAAO;GACP,KAAK,aAAa,KAAK;GACvB,IAAI,UAAU,QACZ,KAAK,uBAAuB,KAAK;EAErC;CACF;CAEA,SAAS,4BAA4B,QAAQ;CAC7C,MAAM,eAAe,OAAO,OAAO,WAAW,UAAS;EACrD,IAAI,iBAAiB,iBAAiB;GACpC,UAAU,IAAI,WAAW,SAAS,kBAAiB,CAAE;GACrD,WAAW,MAAM,sBAAsB;GACvC,YAAY,MAAM,eAAe,gBAAgB;GACjD;EACF;EACA,IAAI,EAAE,iBAAiB,gBACrB;EAEF,MAAM,eAAe;EACrB,YAAY,MAAM;EAClB,cAAc,OAAO,QAAQ,MAAM,iBAAiB;EACpD,MAAM,QAAQ,WAAW,UAAU,IAAI,SAAS,IAAI;EACpD,IAAI,OACF,YAAY,SAAS,iBAAiB,KAAK,CAAC;OACvC,IAAI,iBAAiB,UAAa,CAAC,OAAO,SAAS,MAAM,iBAAiB,CAAC,CAAC,YAAY,gBAAgB,cAC7G,YAAY,SAAS,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;CAEjD,CAAC;CACD,OAAO,UAAU,CAAC,CAAC,gBAAe;EAChC,UAAS;EACT,aAAa,YAAW;CAC1B,CAAC;AACH;AAEA,SAAgB,qBAAkB;CAChC,OAAO,yBAAyB,CAAC,8BAA8B,cAAc,CAAC,CAAC;AACjF"}
|
|
@@ -8,19 +8,25 @@ const TX_TITLE_CONFIG = new InjectionToken("TX_TITLE_CONFIG");
|
|
|
8
8
|
var TxTitle = class TxTitle {
|
|
9
9
|
title = inject(Title);
|
|
10
10
|
config = inject(TX_TITLE_CONFIG);
|
|
11
|
-
page$ = new BehaviorSubject(
|
|
11
|
+
page$ = new BehaviorSubject({
|
|
12
|
+
text: void 0,
|
|
13
|
+
translate: true
|
|
14
|
+
});
|
|
12
15
|
prefix$ = new BehaviorSubject("");
|
|
13
16
|
touched = false;
|
|
14
17
|
constructor() {
|
|
15
|
-
combineLatest([this.page$.pipe(switchMap((
|
|
18
|
+
combineLatest([this.page$.pipe(switchMap(({ text, translate }) => translate ? this.translate(text) : of(text))), this.prefix$]).pipe(filter(() => this.touched), takeUntilDestroyed(inject(DestroyRef))).subscribe(([page, prefix]) => {
|
|
16
19
|
const separator = this.config.separator ?? " · ";
|
|
17
20
|
const title = page ? `${page}${separator}${this.config.appName}` : this.config.appName;
|
|
18
21
|
this.title.setTitle(prefix ? `${prefix} ${title}` : title);
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
|
-
setPage(page) {
|
|
24
|
+
setPage(page, options) {
|
|
22
25
|
this.touched = true;
|
|
23
|
-
this.page$.next(
|
|
26
|
+
this.page$.next({
|
|
27
|
+
text: page,
|
|
28
|
+
translate: options?.translate ?? true
|
|
29
|
+
});
|
|
24
30
|
}
|
|
25
31
|
setPrefix(prefix) {
|
|
26
32
|
this.touched = true;
|
|
@@ -1 +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\n/** Settings of the tab title, passed to `provideTxTitle`. */\nexport interface TxTitleConfig {\n /** App name shown after the page title. */\n appName: string;\n /** Text between the page title and the app name (default ` · `). */\n separator?: string;\n /** Turns the title of a route into the shown text, as a string or an observable. */\n translate?: (page: string) => string | Observable<string>;\n}\n\n/** App name, separator and translation of page titles; set with `provideTxTitle`. */\nexport const TX_TITLE_CONFIG = new InjectionToken<TxTitleConfig>('TX_TITLE_CONFIG');\n\n/** Builds the tab title as \"prefix page · app\"; set the page and a prefix such as a counter. */\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((
|
|
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\n/** Settings of the tab title, passed to `provideTxTitle`. */\nexport interface TxTitleConfig {\n /** App name shown after the page title. */\n appName: string;\n /** Text between the page title and the app name (default ` · `). */\n separator?: string;\n /** Turns the title of a route into the shown text, as a string or an observable. */\n translate?: (page: string) => string | Observable<string>;\n}\n\n/** Options of `TxTitle.setPage`. */\nexport interface TxTitlePageOptions {\n /** `false` shows the text as it is, without the `translate` function of the config (default `true`). */\n translate?: boolean;\n}\n\n/** App name, separator and translation of page titles; set with `provideTxTitle`. */\nexport const TX_TITLE_CONFIG = new InjectionToken<TxTitleConfig>('TX_TITLE_CONFIG');\n\n/** Builds the tab title as \"prefix page · app\"; set the page and a prefix such as a counter. */\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<{ text: string | undefined; translate: boolean }>({ text: undefined, translate: true });\n private readonly prefix$ = new BehaviorSubject<string>('');\n private touched = false;\n\n constructor() {\n combineLatest([this.page$.pipe(switchMap(({ text, translate }) => (translate ? this.translate(text) : of(text)))), 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, options?: TxTitlePageOptions): void {\n this.touched = true;\n this.page$.next({ text: page, translate: options?.translate ?? true });\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/** Router title strategy that sets the page part of the tab title through `TxTitle`. */\n@Injectable()\nexport class TxTitleStrategy extends TitleStrategy {\n private readonly txTitle = inject(TxTitle);\n\n /** Sets the page title from the route titles after each navigation. */\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":";;;;;;AAuBA,MAAa,kBAAkB,IAAI,eAA8B,iBAAiB;AAIlF,IAAa,UAAb,MAAa,QAAO;CACD,QAAQ,OAAO,KAAK;CACpB,SAAS,OAAO,eAAe;CAC/B,QAAQ,IAAI,gBAAkE;EAAE,MAAM;EAAW,WAAW;CAAI,CAAE;CAClH,UAAU,IAAI,gBAAwB,EAAE;CACjD,UAAU;CAElB,cAAA;EACE,cAAc,CAAC,KAAK,MAAM,KAAK,WAAW,EAAE,MAAM,gBAAiB,YAAY,KAAK,UAAU,IAAI,IAAI,GAAG,IAAI,CAAE,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAC9H,KACC,aAAa,KAAK,OAAO,GACzB,mBAAmB,OAAO,UAAU,CAAC,CAAC,CACvC,CACA,WAA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AA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAe,CAAA;;AAAf,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAe,YAAA,CAAA,EAD3B,MAAA,W;;AAUD,SAAgB,eAAe,QAAqB;CAClD,OAAO;EAAC;GAAE,SAAS;GAAiB,UAAU;EAAM;EAAI;EAAS;GAAE,SAAS;GAAe,UAAU;EAAe;CAAE;AACxH"}
|
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 byte`, `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 }}
|
|
@@ -9,11 +9,11 @@ File sizes people can read — `512 B`, `1.5 KB`, `5 MB` in the locale number fo
|
|
|
9
9
|
## Pipes
|
|
10
10
|
| Name | Description |
|
|
11
11
|
|---|---|
|
|
12
|
-
| txFileSize: options? | Size in
|
|
12
|
+
| txFileSize: options? | Size in bytes, kB, MB, GB, TB, PB in the tectra locale, follows a locale switch; options `decimals` (1), `base` (`1024` or `1000`), `locale` (the tectra one by default), `empty` (`-` for no size) |
|
|
13
13
|
|
|
14
14
|
## Functions
|
|
15
15
|
| Name | Description |
|
|
16
16
|
|---|---|
|
|
17
|
-
| formatFileSize(bytes, options?) | The function behind the pipe; `en-US` by default |
|
|
17
|
+
| formatFileSize(bytes, options?) | The function behind the pipe; `en-US` by default. `tx-file-upload` shows sizes the same way |
|
|
18
18
|
| downloadFile(url, filename?) | Downloads a URL through a temporary link; the name comes from the URL when not given |
|
|
19
19
|
| downloadBlob(blob, filename?) | Downloads data made in the browser and frees its object URL |
|
package/filter-state/README.md
CHANGED
|
@@ -13,6 +13,8 @@ readonly orders = httpResource(() => ({ url: '/api/orders', params: buildHttpPar
|
|
|
13
13
|
<button txButton label="Reset" [disabled]="filters.isInitial()" (click)="filters.reset()"></button>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
With `url: true` every change is a router navigation that only changes the query string. Add `provideTxScrolling()` from `@tectra-ng/utils/scrolling` next to `provideRouter` and keep `scrollPositionRestoration` at `'disabled'`: the router's `'enabled'` or `'top'` scrolls to the top on each of those navigations — on every page, sort or filter change — while `provideTxScrolling()` leaves the page in place, starts a new path at the top and restores the position on back and forward.
|
|
17
|
+
|
|
16
18
|
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
19
|
|
|
18
20
|
## Functions
|
|
@@ -28,9 +30,9 @@ Pages built on a base class keep their code: extend `TxUrlFilters<T>` (or `TxSav
|
|
|
28
30
|
## Methods
|
|
29
31
|
| Name | Description |
|
|
30
32
|
|---|---|
|
|
31
|
-
| value | Signal of the current filters |
|
|
33
|
+
| value | Signal of the current filters; keeps the same object while the values stay equal |
|
|
32
34
|
| isInitial | Signal: nothing differs from `initial` |
|
|
33
35
|
| 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
|
+
| set(filters) | Replaces the filters and saves them; does nothing when every value equals the current one |
|
|
37
|
+
| patch(filters) | Changes some keys; does nothing when every patched value equals the current one, so a repeated patch never reloads a list |
|
|
36
38
|
| reset() | Back to `initial`; removes the stored copy and the query params |
|
package/number/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Number
|
|
2
|
+
|
|
3
|
+
Numbers in templates in the tectra locale — `1,234.5` in English, `1 234,5` in Ukrainian — with any `Intl.NumberFormat` option: fraction digits, percent, units, compact notation. The pipe follows a locale switch and shows `-` instead of `NaN` for an empty or broken value.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { TxNumberPipe } from '@tectra-ng/utils/number';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
{{ order.total | txNumber: { maximumFractionDigits: 2 } }} <!-- 1,234.57 -->
|
|
11
|
+
{{ conversion | txNumber: { style: 'percent' } }} <!-- 25% -->
|
|
12
|
+
{{ visitors | txNumber: { notation: 'compact' } }} <!-- 1.5K -->
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Pipes
|
|
16
|
+
| Name | Description |
|
|
17
|
+
|---|---|
|
|
18
|
+
| txNumber: options? | Formats a number, numeric string or bigint with `Intl.NumberFormat` options; `locale` (the tectra one by default, followed as it changes) and `empty` (`-` for no value) |
|
|
19
|
+
|
|
20
|
+
## Functions
|
|
21
|
+
| Name | Description |
|
|
22
|
+
|---|---|
|
|
23
|
+
| formatLocaleNumber(value, options?) | The function behind the pipe; `en-US` by default |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tectra-ng/utils",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "Angular utilities on signals next to the tectra components: date, 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 and breakpoints. Server rendering safe.",
|
|
3
|
+
"version": "0.4.2",
|
|
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",
|
|
7
7
|
"repository": {
|
|
@@ -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.2",
|
|
38
|
+
"@tectra-ng/icons": "^0.4.2",
|
|
39
|
+
"@tectra-ng/themes": "^0.4.2",
|
|
40
|
+
"@tectra-ng/ui": "^0.4.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@angular/forms": {
|
|
@@ -127,6 +127,10 @@
|
|
|
127
127
|
"types": "./types/tectra-ng-utils-in-view.d.ts",
|
|
128
128
|
"default": "./fesm2022/tectra-ng-utils-in-view.mjs"
|
|
129
129
|
},
|
|
130
|
+
"./number": {
|
|
131
|
+
"types": "./types/tectra-ng-utils-number.d.ts",
|
|
132
|
+
"default": "./fesm2022/tectra-ng-utils-number.mjs"
|
|
133
|
+
},
|
|
130
134
|
"./plural": {
|
|
131
135
|
"types": "./types/tectra-ng-utils-plural.d.ts",
|
|
132
136
|
"default": "./fesm2022/tectra-ng-utils-plural.mjs"
|
|
@@ -147,6 +151,10 @@
|
|
|
147
151
|
"types": "./types/tectra-ng-utils-scroll-end.d.ts",
|
|
148
152
|
"default": "./fesm2022/tectra-ng-utils-scroll-end.mjs"
|
|
149
153
|
},
|
|
154
|
+
"./scrolling": {
|
|
155
|
+
"types": "./types/tectra-ng-utils-scrolling.d.ts",
|
|
156
|
+
"default": "./fesm2022/tectra-ng-utils-scrolling.mjs"
|
|
157
|
+
},
|
|
150
158
|
"./selection": {
|
|
151
159
|
"types": "./types/tectra-ng-utils-selection.d.ts",
|
|
152
160
|
"default": "./fesm2022/tectra-ng-utils-selection.mjs"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Scrolling
|
|
2
|
+
|
|
3
|
+
Router scrolling for list pages: back and forward restore the saved position, a new path starts at the top, and navigations that only change the query string — paging, sorting, filters written by `txFilterState({ url: true })` — leave the page where it is. Links with a fragment are left to the router's anchor scrolling.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
bootstrapApplication(App, {
|
|
7
|
+
providers: [provideRouter(routes), provideTxScrolling()],
|
|
8
|
+
});
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Use it instead of the router's own restoration: keep `scrollPositionRestoration` at `'disabled'` (the default; with `withInMemoryScrolling({ scrollPositionRestoration: 'enabled' | 'top' })` every query change scrolls to the top). `withInMemoryScrolling({ anchorScrolling: 'enabled' })` can stay for fragments. Nothing runs on the server.
|
|
12
|
+
|
|
13
|
+
## Providers
|
|
14
|
+
| Name | Description |
|
|
15
|
+
|---|---|
|
|
16
|
+
| provideTxScrolling() | Sets the scrolling up next to `provideRouter`: restores the position on back / forward, scrolls to the top when the path changes, does nothing on query-only navigations and leaves fragments to the router |
|
package/title/README.md
CHANGED
|
@@ -12,6 +12,7 @@ bootstrapApplication(App, {
|
|
|
12
12
|
export const routes: Routes = [{ path: 'orders', title: 'orders', component: OrdersPage }];
|
|
13
13
|
|
|
14
14
|
inject(TxTitle).setPrefix(unread ? `(${unread})` : '');
|
|
15
|
+
inject(TxTitle).setPage(order.number, { translate: false });
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
## Providers
|
|
@@ -23,4 +24,4 @@ inject(TxTitle).setPrefix(unread ? `(${unread})` : '');
|
|
|
23
24
|
| Name | Description |
|
|
24
25
|
|---|---|
|
|
25
26
|
| TxTitle.setPrefix(prefix) | Text before every title, `''` to remove it |
|
|
26
|
-
| TxTitle.setPage(page) | Sets the page part by hand, for a title that is not on a route (a record name) |
|
|
27
|
+
| TxTitle.setPage(page, { translate? }) | Sets the page part by hand, for a title that is not on a route; `{ translate: false }` shows ready text (a record name) as it is, without the `translate` function |
|
|
@@ -2,14 +2,16 @@ import * as i0 from "@angular/core";
|
|
|
2
2
|
import { InjectionToken, PipeTransform, Provider } from "@angular/core";
|
|
3
3
|
/** Anything the date helpers accept: a `Date`, an ISO string, a timestamp in ms, or nothing. */
|
|
4
4
|
export type TxDateInput = Date | string | number | null | undefined;
|
|
5
|
+
/** A format of `txDate`: an Angular date pattern or preset (`'dd.MM.yyyy'`, `'mediumDate'`), or `Intl.DateTimeFormat` options such as `TX_DATE_STYLES.dateTime`. */
|
|
6
|
+
export type TxDateFormat = string | Intl.DateTimeFormatOptions;
|
|
5
7
|
/** Settings of the `txDate` pipe, set with `provideTxDateFormat`. */
|
|
6
8
|
export interface TxDateFormatConfig {
|
|
7
|
-
/**
|
|
8
|
-
format:
|
|
9
|
+
/** Format used when the pipe gets none (default `TX_DATE_STYLES.date`, a medium date in the locale). */
|
|
10
|
+
format: TxDateFormat;
|
|
9
11
|
/** Text shown for an empty or invalid date (default `-`). */
|
|
10
12
|
empty: string;
|
|
11
|
-
/** Locale of the formatted dates
|
|
12
|
-
locale: string;
|
|
13
|
+
/** Locale of the formatted dates; the tectra locale, followed as it changes, when not set. */
|
|
14
|
+
locale: string | undefined;
|
|
13
15
|
/** Time zone of the formatted dates; the local one when not set. */
|
|
14
16
|
timezone: string | undefined;
|
|
15
17
|
}
|
|
@@ -20,12 +22,12 @@ export interface TxIsoRange {
|
|
|
20
22
|
/** Last day or moment of the range. */
|
|
21
23
|
end: string;
|
|
22
24
|
}
|
|
23
|
-
/** Default date format settings:
|
|
25
|
+
/** Default date format settings: a medium date in the tectra locale, `-` for an empty value, the local time zone. */
|
|
24
26
|
export declare const TX_DATE_FORMAT_DEFAULTS: TxDateFormatConfig;
|
|
25
27
|
/** Date format settings used by the `txDate` pipe; set them with `provideTxDateFormat`. */
|
|
26
28
|
export declare const TX_DATE_FORMAT_CONFIG: InjectionToken<TxDateFormatConfig>;
|
|
27
29
|
/**
|
|
28
|
-
* App or component defaults of `txDate`: `format` (`
|
|
30
|
+
* App or component defaults of `txDate`: `format` (`TX_DATE_STYLES.date`), `empty` (`'-'`), `locale` (the tectra locale when not set), `timezone`
|
|
29
31
|
* @see https://tectra-ng.com/components/date
|
|
30
32
|
*/
|
|
31
33
|
export declare function provideTxDateFormat(config: Partial<TxDateFormatConfig>): Provider;
|
|
@@ -70,6 +72,28 @@ export declare const TX_DATE_FORMATS: {
|
|
|
70
72
|
readonly day: "dd";
|
|
71
73
|
readonly dayMonth: "dd.MM";
|
|
72
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* `Intl` styles in the locale: `date` (Nov 11, 2026), `dateTime` (Nov 11, 2026, 9:05 AM), `time` (9:05 AM), `shortDate` (11/11/26), `longDate` (November 11, 2026)
|
|
77
|
+
* @see https://tectra-ng.com/components/date
|
|
78
|
+
*/
|
|
79
|
+
export declare const TX_DATE_STYLES: {
|
|
80
|
+
readonly date: {
|
|
81
|
+
readonly dateStyle: "medium";
|
|
82
|
+
};
|
|
83
|
+
readonly dateTime: {
|
|
84
|
+
readonly dateStyle: "medium";
|
|
85
|
+
readonly timeStyle: "short";
|
|
86
|
+
};
|
|
87
|
+
readonly time: {
|
|
88
|
+
readonly timeStyle: "short";
|
|
89
|
+
};
|
|
90
|
+
readonly shortDate: {
|
|
91
|
+
readonly dateStyle: "short";
|
|
92
|
+
};
|
|
93
|
+
readonly longDate: {
|
|
94
|
+
readonly dateStyle: "long";
|
|
95
|
+
};
|
|
96
|
+
};
|
|
73
97
|
/**
|
|
74
98
|
* A new `Date` from a `Date`, string or number; `null` when empty or invalid
|
|
75
99
|
* @see https://tectra-ng.com/components/date
|
|
@@ -140,12 +164,17 @@ export declare function toIsoRange(range: readonly TxDateInput[] | null | undefi
|
|
|
140
164
|
*/
|
|
141
165
|
export declare function isExpiringWithin(value: TxDateInput, periodMs?: number, now?: Date | number): boolean;
|
|
142
166
|
/**
|
|
143
|
-
* Formats a `Date`, ISO string or timestamp
|
|
167
|
+
* Formats a `Date`, ISO string or timestamp in the tectra locale and follows it as it changes. `format` is `Intl.DateTimeFormat` options (`TX_DATE_STYLES.dateTime`, `{ month: 'long', day: 'numeric' }`) or an Angular date pattern (`'dd.MM.yyyy'`, `'mediumDate'` …; month names need the Angular locale data, English otherwise); `timezone` is an offset (`'+0200'`), `'UTC'` or an IANA name; the empty text for `null`, `''` or an invalid date
|
|
144
168
|
* @see https://tectra-ng.com/components/date
|
|
145
169
|
*/
|
|
146
170
|
export declare class TxDatePipe implements PipeTransform {
|
|
147
171
|
private readonly config;
|
|
148
|
-
|
|
172
|
+
private readonly localeService;
|
|
173
|
+
private lastKey;
|
|
174
|
+
private lastText;
|
|
175
|
+
transform(value: TxDateInput, format?: TxDateFormat, timezone?: string, locale?: string): string;
|
|
176
|
+
private format;
|
|
177
|
+
private formatPattern;
|
|
149
178
|
static ɵfac: i0.ɵɵFactoryDeclaration<TxDatePipe, never>;
|
|
150
179
|
static ɵpipe: i0.ɵɵPipeDeclaration<TxDatePipe, "txDate", true>;
|
|
151
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-date.d.ts","names":[],"sources":["../../../../packages/utils/date/src/date.types.ts","../../../../packages/utils/date/src/date.config.ts","../../../../packages/utils/date/src/date.constants.ts","../../../../packages/utils/date/src/date.functions.ts","../../../../packages/utils/date/src/date.pipe.ts"],"mappings":";;;YACY,cAAc;;
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-date.d.ts","names":[],"sources":["../../../../packages/utils/date/src/date.types.ts","../../../../packages/utils/date/src/date.config.ts","../../../../packages/utils/date/src/date.constants.ts","../../../../packages/utils/date/src/date.functions.ts","../../../../packages/utils/date/src/date.pipe.ts"],"mappings":";;;YACY,cAAc;;YAGd,wBAAwB,KAAK;;iBAGxB;;EAEf,QAAQ;;EAER;;EAEA;;EAEA;;;iBAIe;;EAEf;;EAEA;;;qBClBW,yBAAyB;;qBAQzB,uBAAqB,eAAA;;;;;wBAKlB,oBAAoB,QAAQ,QAAQ,sBAAsB;;;;;qBClB7D;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;qBAEA;;;;;qBAEA;;;;;;;;;;;;;;qBAWA;;;;;;;;;;;;;;;;;;;;;;wBC9BG,OAAO,OAAO,cAAc;;;;;wBAQ5B,YAAY,OAAO;;;;;wBAQnB,WAAW,OAAO,yBAAyB;;wBAO3C,YAAY,OAAO,yBAAyB;;wBAO5C,SAAS,OAAO,yBAAyB;;;;;wBAMzC,QAAQ,OAAO,wBAAwB,eAAe;;;;;wBAMtD,UAAU,OAAO,wBAAwB,iBAAiB;;;;;wBAU1D,SAAS,OAAO,wBAAwB,gBAAgB;;;;;wBAIxD,YAAY,OAAO,wBAAwB,0BAAqB;;;;;wBAMhE,oBAAoB,MAAM,wBAAwB,IAAI;;;;;wBAQtD,UAAU,GAAG,aAAa,GAAG;;;;;wBAM7B,SAAS,OAAO;;;;;wBAOhB,YAAY,OAAO;;;;;wBAOnB,WAAW,gBAAgB,mCAAmC;;;;;wBAS9D,iBAAiB,OAAO,aAAa,mBAAuB,MAAK;;;;;qBCnFpE,sBAAsB;mBAChB;mBACA;UACT;UACA;EAER,UAAU,OAAO,aAAa,SAAS,cAAc,mBAAmB;UAiBhE;UAWA;SAlCG,MAAA,GAAA,qBAAA;SAAA,OAAA,GAAA,kBAAA;;;;;;qBA+CA,2BAA2B;EACtC,UAAU,gBAAgB,mCAAmC;SADlD,MAAA,GAAA,qBAAA;SAAA,OAAA,GAAA,kBAAA"}
|
|
@@ -6,13 +6,13 @@ export interface TxFileSizeOptions {
|
|
|
6
6
|
decimals?: number;
|
|
7
7
|
/** Size of a unit: `1024` (default) or `1000`. */
|
|
8
8
|
base?: 1000 | 1024;
|
|
9
|
-
/** Locale of the number format (default `en-US`; the pipe uses the tectra locale). */
|
|
9
|
+
/** Locale of the number format and the unit names (default `en-US`; the pipe uses the tectra locale). */
|
|
10
10
|
locale?: string;
|
|
11
11
|
/** Text shown for a missing or negative size (default `-`). */
|
|
12
12
|
empty?: string;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* The function behind the pipe; `en-US` by default
|
|
15
|
+
* The function behind the pipe; `en-US` by default. `tx-file-upload` shows sizes the same way
|
|
16
16
|
* @see https://tectra-ng.com/components/file
|
|
17
17
|
*/
|
|
18
18
|
export declare function formatFileSize(bytes: number | null | undefined, options?: TxFileSizeOptions): string;
|
|
@@ -27,7 +27,7 @@ export declare function downloadBlob(blob: Blob, filename?: string, document?: D
|
|
|
27
27
|
*/
|
|
28
28
|
export declare function downloadFile(url: string, filename?: string, document?: Document | undefined): void;
|
|
29
29
|
/**
|
|
30
|
-
* Size in
|
|
30
|
+
* Size in bytes, kB, MB, GB, TB, PB in the tectra locale, follows a locale switch; options `decimals` (1), `base` (`1024` or `1000`), `locale` (the tectra one by default), `empty` (`-` for no size)
|
|
31
31
|
* @see https://tectra-ng.com/components/file
|
|
32
32
|
*/
|
|
33
33
|
export declare class TxFileSizePipe implements PipeTransform {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-file.d.ts","names":[],"sources":["../../../../packages/utils/file/src/file.ts"],"mappings":";;;iBAIiB;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-file.d.ts","names":[],"sources":["../../../../packages/utils/file/src/file.ts"],"mappings":";;;iBAIiB;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;wBAGc,eAAe,kCAAkC,UAAS;;;;;wBAQ1D,aAAa,MAAM,MAAM,mBAAmB,WAAU;;;;;wBAUtD,aAAa,aAAa,mBAAmB,WAAU;;;;;qBAe1D,0BAA0B;mBACpB;EAEjB,UAAU,kCAAkC,UAAS;SAH1C,MAAA,GAAA,qBAAA;SAAA,OAAA,GAAA,kBAAA"}
|
|
@@ -19,15 +19,15 @@ export interface TxFilterStateOptions<T extends object> {
|
|
|
19
19
|
* initial values.
|
|
20
20
|
*/
|
|
21
21
|
export interface TxFilterState<T extends object> {
|
|
22
|
-
/** Signal of the current filters */
|
|
22
|
+
/** Signal of the current filters; keeps the same object while the values stay equal */
|
|
23
23
|
readonly value: Signal<T>;
|
|
24
24
|
/** Signal: nothing differs from `initial` */
|
|
25
25
|
readonly isInitial: Signal<boolean>;
|
|
26
26
|
/** Signal: keys that differ from `initial` — for a "3 filters" badge */
|
|
27
27
|
readonly changed: Signal<(keyof T)[]>;
|
|
28
|
-
/** Replaces the filters and saves them */
|
|
28
|
+
/** Replaces the filters and saves them; does nothing when every value equals the current one */
|
|
29
29
|
set(filters: T): void;
|
|
30
|
-
/** Changes some keys */
|
|
30
|
+
/** Changes some keys; does nothing when every patched value equals the current one, so a repeated patch never reloads a list */
|
|
31
31
|
patch(filters: Partial<T>): void;
|
|
32
32
|
/** Back to `initial`; removes the stored copy and the query params */
|
|
33
33
|
reset(): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { PipeTransform } from "@angular/core";
|
|
3
|
+
/** Options of `txNumber` and `formatLocaleNumber`: `Intl.NumberFormat` options with a locale and an empty text. */
|
|
4
|
+
export interface TxNumberOptions extends Intl.NumberFormatOptions {
|
|
5
|
+
/** Locale of the format (default `en-US`; the pipe uses the tectra locale). */
|
|
6
|
+
locale?: string;
|
|
7
|
+
/** Text shown for a missing or non-numeric value (default `-`). */
|
|
8
|
+
empty?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Anything `txNumber` accepts: a number, a numeric string, a bigint, or nothing. */
|
|
11
|
+
export type TxNumberInput = number | bigint | string | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The function behind the pipe; `en-US` by default
|
|
14
|
+
* @see https://tectra-ng.com/components/number
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatLocaleNumber(value: TxNumberInput, options?: TxNumberOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* Formats a number, numeric string or bigint with `Intl.NumberFormat` options; `locale` (the tectra one by default, followed as it changes) and `empty` (`-` for no value)
|
|
19
|
+
* @see https://tectra-ng.com/components/number
|
|
20
|
+
*/
|
|
21
|
+
export declare class TxNumberPipe implements PipeTransform {
|
|
22
|
+
private readonly localeService;
|
|
23
|
+
private lastKey;
|
|
24
|
+
private lastText;
|
|
25
|
+
transform(value: TxNumberInput, options?: TxNumberOptions): string;
|
|
26
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TxNumberPipe, never>;
|
|
27
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<TxNumberPipe, "txNumber", true>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=tectra-ng-utils-number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-number.d.ts","names":[],"sources":["../../../../packages/utils/number/src/number.ts"],"mappings":";;;iBAIiB,wBAAwB,KAAK;;EAE5C;;EAEA;;;YAIU;;;;;wBAEI,mBAAmB,OAAO,eAAe,UAAS;;;;;qBAcrD,wBAAwB;mBAClB;UACT;UACA;EAER,UAAU,OAAO,eAAe,UAAS;SAL9B,MAAA,GAAA,qBAAA;SAAA,OAAA,GAAA,kBAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EnvironmentProviders } from "@angular/core";
|
|
2
|
+
/**
|
|
3
|
+
* Sets the scrolling up next to `provideRouter`: restores the position on back / forward, scrolls to the top when the path changes, does nothing on query-only navigations and leaves fragments to the router
|
|
4
|
+
* @see https://tectra-ng.com/components/scrolling
|
|
5
|
+
*/
|
|
6
|
+
export declare function provideTxScrolling(): EnvironmentProviders;
|
|
7
|
+
//# sourceMappingURL=tectra-ng-utils-scrolling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-scrolling.d.ts","names":[],"sources":["../../../../packages/utils/scrolling/src/scrolling.ts"],"mappings":";;;;;wBAwEgB,sBAAsB"}
|
|
@@ -11,6 +11,11 @@ export interface TxTitleConfig {
|
|
|
11
11
|
/** Turns the title of a route into the shown text, as a string or an observable. */
|
|
12
12
|
translate?: (page: string) => string | Observable<string>;
|
|
13
13
|
}
|
|
14
|
+
/** Options of `TxTitle.setPage`. */
|
|
15
|
+
export interface TxTitlePageOptions {
|
|
16
|
+
/** `false` shows the text as it is, without the `translate` function of the config (default `true`). */
|
|
17
|
+
translate?: boolean;
|
|
18
|
+
}
|
|
14
19
|
/** App name, separator and translation of page titles; set with `provideTxTitle`. */
|
|
15
20
|
export declare const TX_TITLE_CONFIG: InjectionToken<TxTitleConfig>;
|
|
16
21
|
/** Builds the tab title as "prefix page · app"; set the page and a prefix such as a counter. */
|
|
@@ -21,8 +26,8 @@ export declare class TxTitle {
|
|
|
21
26
|
private readonly prefix$;
|
|
22
27
|
private touched;
|
|
23
28
|
constructor();
|
|
24
|
-
/** Sets the page part by hand, for a title that is not on a route (a record name) */
|
|
25
|
-
setPage(page: string | undefined): void;
|
|
29
|
+
/** Sets the page part by hand, for a title that is not on a route; `{ translate: false }` shows ready text (a record name) as it is, without the `translate` function */
|
|
30
|
+
setPage(page: string | undefined, options?: TxTitlePageOptions): void;
|
|
26
31
|
/** Text before every title, `''` to remove it */
|
|
27
32
|
setPrefix(prefix: string): void;
|
|
28
33
|
private translate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tectra-ng-utils-title.d.ts","names":[],"sources":["../../../../packages/utils/title/src/title.ts"],"mappings":";;;;;iBAOiB;;EAEf;;EAEA;;EAEA,aAAa,0BAA0B;;;
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-title.d.ts","names":[],"sources":["../../../../packages/utils/title/src/title.ts"],"mappings":";;;;;iBAOiB;;EAEf;;EAEA;;EAEA,aAAa,0BAA0B;;;iBAIxB;;EAEf;;;qBAIW,iBAAe,eAAA;;qBAIf;mBACM;mBACA;mBACA;mBACA;UACT;;;EAeR,QAAQ,0BAA0B,UAAU;;EAK5C,UAAU;UAKF;SA9BG,MAAA,GAAA,qBAAA;;;;qBAyCA,wBAAwB;mBAClB;;EAGR,YAAY,UAAU;SAJpB,MAAA,GAAA,qBAAA;;;;;;;wBASG,eAAe,QAAQ,gBAAgB"}
|