@tectra-ng/utils 0.0.1 → 0.2.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.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -1
  3. package/auto-focus/README.md +19 -0
  4. package/breakpoint/README.md +23 -0
  5. package/clipboard/README.md +37 -0
  6. package/clock/README.md +21 -0
  7. package/currency/README.md +17 -0
  8. package/date/README.md +46 -0
  9. package/debounce-input/README.md +31 -0
  10. package/drag-scroll/README.md +25 -0
  11. package/fesm2022/tectra-ng-utils-auto-focus.mjs +100 -0
  12. package/fesm2022/tectra-ng-utils-auto-focus.mjs.map +1 -0
  13. package/fesm2022/tectra-ng-utils-breakpoint.mjs +54 -0
  14. package/fesm2022/tectra-ng-utils-breakpoint.mjs.map +1 -0
  15. package/fesm2022/tectra-ng-utils-clipboard.mjs +225 -0
  16. package/fesm2022/tectra-ng-utils-clipboard.mjs.map +1 -0
  17. package/fesm2022/tectra-ng-utils-clock.mjs +59 -0
  18. package/fesm2022/tectra-ng-utils-clock.mjs.map +1 -0
  19. package/fesm2022/tectra-ng-utils-currency.mjs +63 -0
  20. package/fesm2022/tectra-ng-utils-currency.mjs.map +1 -0
  21. package/fesm2022/tectra-ng-utils-date.mjs +200 -0
  22. package/fesm2022/tectra-ng-utils-date.mjs.map +1 -0
  23. package/fesm2022/tectra-ng-utils-debounce-input.mjs +156 -0
  24. package/fesm2022/tectra-ng-utils-debounce-input.mjs.map +1 -0
  25. package/fesm2022/tectra-ng-utils-drag-scroll.mjs +199 -0
  26. package/fesm2022/tectra-ng-utils-drag-scroll.mjs.map +1 -0
  27. package/fesm2022/tectra-ng-utils-file.mjs +78 -0
  28. package/fesm2022/tectra-ng-utils-file.mjs.map +1 -0
  29. package/fesm2022/tectra-ng-utils-filter-state.mjs +238 -0
  30. package/fesm2022/tectra-ng-utils-filter-state.mjs.map +1 -0
  31. package/fesm2022/tectra-ng-utils-filter.mjs +88 -0
  32. package/fesm2022/tectra-ng-utils-filter.mjs.map +1 -0
  33. package/fesm2022/tectra-ng-utils-form-changes.mjs +70 -0
  34. package/fesm2022/tectra-ng-utils-form-changes.mjs.map +1 -0
  35. package/fesm2022/tectra-ng-utils-form-validation.mjs +162 -0
  36. package/fesm2022/tectra-ng-utils-form-validation.mjs.map +1 -0
  37. package/fesm2022/tectra-ng-utils-go-back.mjs +117 -0
  38. package/fesm2022/tectra-ng-utils-go-back.mjs.map +1 -0
  39. package/fesm2022/tectra-ng-utils-http.mjs +189 -0
  40. package/fesm2022/tectra-ng-utils-http.mjs.map +1 -0
  41. package/fesm2022/tectra-ng-utils-in-view.mjs +297 -0
  42. package/fesm2022/tectra-ng-utils-in-view.mjs.map +1 -0
  43. package/fesm2022/tectra-ng-utils-plural.mjs +98 -0
  44. package/fesm2022/tectra-ng-utils-plural.mjs.map +1 -0
  45. package/fesm2022/tectra-ng-utils-polling.mjs +109 -0
  46. package/fesm2022/tectra-ng-utils-polling.mjs.map +1 -0
  47. package/fesm2022/tectra-ng-utils-random.mjs +20 -0
  48. package/fesm2022/tectra-ng-utils-random.mjs.map +1 -0
  49. package/fesm2022/tectra-ng-utils-relative-time.mjs +87 -0
  50. package/fesm2022/tectra-ng-utils-relative-time.mjs.map +1 -0
  51. package/fesm2022/tectra-ng-utils-scroll-end.mjs +136 -0
  52. package/fesm2022/tectra-ng-utils-scroll-end.mjs.map +1 -0
  53. package/fesm2022/tectra-ng-utils-selection.mjs +52 -0
  54. package/fesm2022/tectra-ng-utils-selection.mjs.map +1 -0
  55. package/fesm2022/tectra-ng-utils-stop-propagation.mjs +92 -0
  56. package/fesm2022/tectra-ng-utils-stop-propagation.mjs.map +1 -0
  57. package/fesm2022/tectra-ng-utils-stream.mjs +30 -0
  58. package/fesm2022/tectra-ng-utils-stream.mjs.map +1 -0
  59. package/fesm2022/tectra-ng-utils-style-class.mjs +350 -0
  60. package/fesm2022/tectra-ng-utils-style-class.mjs.map +1 -0
  61. package/fesm2022/tectra-ng-utils-text.mjs +173 -0
  62. package/fesm2022/tectra-ng-utils-text.mjs.map +1 -0
  63. package/fesm2022/tectra-ng-utils-title.mjs +99 -0
  64. package/fesm2022/tectra-ng-utils-title.mjs.map +1 -0
  65. package/fesm2022/tectra-ng-utils-validators.mjs +232 -0
  66. package/fesm2022/tectra-ng-utils-validators.mjs.map +1 -0
  67. package/fesm2022/tectra-ng-utils.mjs +4 -0
  68. package/fesm2022/tectra-ng-utils.mjs.map +1 -0
  69. package/file/README.md +19 -0
  70. package/filter/README.md +22 -0
  71. package/filter-state/README.md +36 -0
  72. package/form-changes/README.md +26 -0
  73. package/form-validation/README.md +40 -0
  74. package/go-back/README.md +28 -0
  75. package/http/README.md +34 -0
  76. package/in-view/README.md +34 -0
  77. package/package.json +173 -3
  78. package/plural/README.md +21 -0
  79. package/polling/README.md +34 -0
  80. package/random/README.md +10 -0
  81. package/relative-time/README.md +29 -0
  82. package/scroll-end/README.md +25 -0
  83. package/selection/README.md +24 -0
  84. package/stop-propagation/README.md +15 -0
  85. package/stream/README.md +14 -0
  86. package/style-class/README.md +34 -0
  87. package/text/README.md +25 -0
  88. package/title/README.md +26 -0
  89. package/types/tectra-ng-utils-auto-focus.d.ts +22 -0
  90. package/types/tectra-ng-utils-auto-focus.d.ts.map +1 -0
  91. package/types/tectra-ng-utils-breakpoint.d.ts +15 -0
  92. package/types/tectra-ng-utils-breakpoint.d.ts.map +1 -0
  93. package/types/tectra-ng-utils-clipboard.d.ts +48 -0
  94. package/types/tectra-ng-utils-clipboard.d.ts.map +1 -0
  95. package/types/tectra-ng-utils-clock.d.ts +18 -0
  96. package/types/tectra-ng-utils-clock.d.ts.map +1 -0
  97. package/types/tectra-ng-utils-currency.d.ts +11 -0
  98. package/types/tectra-ng-utils-currency.d.ts.map +1 -0
  99. package/types/tectra-ng-utils-date.d.ts +65 -0
  100. package/types/tectra-ng-utils-date.d.ts.map +1 -0
  101. package/types/tectra-ng-utils-debounce-input.d.ts +38 -0
  102. package/types/tectra-ng-utils-debounce-input.d.ts.map +1 -0
  103. package/types/tectra-ng-utils-drag-scroll.d.ts +41 -0
  104. package/types/tectra-ng-utils-drag-scroll.d.ts.map +1 -0
  105. package/types/tectra-ng-utils-file.d.ts +18 -0
  106. package/types/tectra-ng-utils-file.d.ts.map +1 -0
  107. package/types/tectra-ng-utils-filter-state.d.ts +55 -0
  108. package/types/tectra-ng-utils-filter-state.d.ts.map +1 -0
  109. package/types/tectra-ng-utils-filter.d.ts +21 -0
  110. package/types/tectra-ng-utils-filter.d.ts.map +1 -0
  111. package/types/tectra-ng-utils-form-changes.d.ts +22 -0
  112. package/types/tectra-ng-utils-form-changes.d.ts.map +1 -0
  113. package/types/tectra-ng-utils-form-validation.d.ts +45 -0
  114. package/types/tectra-ng-utils-form-validation.d.ts.map +1 -0
  115. package/types/tectra-ng-utils-go-back.d.ts +25 -0
  116. package/types/tectra-ng-utils-go-back.d.ts.map +1 -0
  117. package/types/tectra-ng-utils-http.d.ts +47 -0
  118. package/types/tectra-ng-utils-http.d.ts.map +1 -0
  119. package/types/tectra-ng-utils-in-view.d.ts +80 -0
  120. package/types/tectra-ng-utils-in-view.d.ts.map +1 -0
  121. package/types/tectra-ng-utils-plural.d.ts +21 -0
  122. package/types/tectra-ng-utils-plural.d.ts.map +1 -0
  123. package/types/tectra-ng-utils-polling.d.ts +61 -0
  124. package/types/tectra-ng-utils-polling.d.ts.map +1 -0
  125. package/types/tectra-ng-utils-random.d.ts +4 -0
  126. package/types/tectra-ng-utils-random.d.ts.map +1 -0
  127. package/types/tectra-ng-utils-relative-time.d.ts +22 -0
  128. package/types/tectra-ng-utils-relative-time.d.ts.map +1 -0
  129. package/types/tectra-ng-utils-scroll-end.d.ts +38 -0
  130. package/types/tectra-ng-utils-scroll-end.d.ts.map +1 -0
  131. package/types/tectra-ng-utils-selection.d.ts +21 -0
  132. package/types/tectra-ng-utils-selection.d.ts.map +1 -0
  133. package/types/tectra-ng-utils-stop-propagation.d.ts +22 -0
  134. package/types/tectra-ng-utils-stop-propagation.d.ts.map +1 -0
  135. package/types/tectra-ng-utils-stream.d.ts +3 -0
  136. package/types/tectra-ng-utils-stream.d.ts.map +1 -0
  137. package/types/tectra-ng-utils-style-class.d.ts +91 -0
  138. package/types/tectra-ng-utils-style-class.d.ts.map +1 -0
  139. package/types/tectra-ng-utils-text.d.ts +26 -0
  140. package/types/tectra-ng-utils-text.d.ts.map +1 -0
  141. package/types/tectra-ng-utils-title.d.ts +31 -0
  142. package/types/tectra-ng-utils-title.d.ts.map +1 -0
  143. package/types/tectra-ng-utils-validators.d.ts +67 -0
  144. package/types/tectra-ng-utils-validators.d.ts.map +1 -0
  145. package/types/tectra-ng-utils.d.ts +2 -0
  146. package/types/tectra-ng-utils.d.ts.map +1 -0
  147. package/validators/README.md +42 -0
@@ -0,0 +1,98 @@
1
+ import { TxLocaleService, formatMessage } from "@tectra-ng/core/i18n";
2
+ import * as i0 from "@angular/core";
3
+ import { Pipe, inject } from "@angular/core";
4
+ const rulesCache = /* @__PURE__ */ new Map();
5
+ function rules(locale) {
6
+ let found = rulesCache.get(locale);
7
+ if (!found) {
8
+ found = new Intl.PluralRules(locale);
9
+ rulesCache.set(locale, found);
10
+ }
11
+ return found;
12
+ }
13
+ function pluralCategory(count, locale = "en-US") {
14
+ return rules(locale).select(count);
15
+ }
16
+ function pluralForm(count, locale = "en-US") {
17
+ const category = pluralCategory(count, locale);
18
+ return category === "one" || category === "few" ? category : "many";
19
+ }
20
+ function plural(count, forms, locale = "en-US") {
21
+ if (typeof forms === "string") return formatMessage(forms, { count }, locale);
22
+ return (forms[`=${count}`] ?? forms[pluralCategory(count, locale)] ?? forms.other ?? forms.many ?? "").replace(/#/g, String(count));
23
+ }
24
+ var TxPluralFormPipe = class TxPluralFormPipe {
25
+ localeService = inject(TxLocaleService);
26
+ transform(count, locale) {
27
+ return pluralForm(count ?? 0, locale ?? this.localeService.locale().intl);
28
+ }
29
+ static ɵfac = i0.ɵɵngDeclareFactory({
30
+ minVersion: "12.0.0",
31
+ version: "22.2.3",
32
+ ngImport: i0,
33
+ type: TxPluralFormPipe,
34
+ deps: [],
35
+ target: i0.ɵɵFactoryTarget.Pipe
36
+ });
37
+ static ɵpipe = i0.ɵɵngDeclarePipe({
38
+ minVersion: "14.0.0",
39
+ version: "22.2.3",
40
+ ngImport: i0,
41
+ type: TxPluralFormPipe,
42
+ isStandalone: true,
43
+ name: "txPluralForm",
44
+ pure: false
45
+ });
46
+ };
47
+ i0.ɵɵngDeclareClassMetadata({
48
+ minVersion: "12.0.0",
49
+ version: "22.2.3",
50
+ ngImport: i0,
51
+ type: TxPluralFormPipe,
52
+ decorators: [{
53
+ type: Pipe,
54
+ args: [{
55
+ name: "txPluralForm",
56
+ pure: false
57
+ }]
58
+ }]
59
+ });
60
+ var TxPluralPipe = class TxPluralPipe {
61
+ localeService = inject(TxLocaleService);
62
+ transform(count, forms, locale) {
63
+ return plural(count ?? 0, forms, locale ?? this.localeService.locale().intl);
64
+ }
65
+ static ɵfac = i0.ɵɵngDeclareFactory({
66
+ minVersion: "12.0.0",
67
+ version: "22.2.3",
68
+ ngImport: i0,
69
+ type: TxPluralPipe,
70
+ deps: [],
71
+ target: i0.ɵɵFactoryTarget.Pipe
72
+ });
73
+ static ɵpipe = i0.ɵɵngDeclarePipe({
74
+ minVersion: "14.0.0",
75
+ version: "22.2.3",
76
+ ngImport: i0,
77
+ type: TxPluralPipe,
78
+ isStandalone: true,
79
+ name: "txPlural",
80
+ pure: false
81
+ });
82
+ };
83
+ i0.ɵɵngDeclareClassMetadata({
84
+ minVersion: "12.0.0",
85
+ version: "22.2.3",
86
+ ngImport: i0,
87
+ type: TxPluralPipe,
88
+ decorators: [{
89
+ type: Pipe,
90
+ args: [{
91
+ name: "txPlural",
92
+ pure: false
93
+ }]
94
+ }]
95
+ });
96
+ export { TxPluralFormPipe, TxPluralPipe, plural, pluralCategory, pluralForm };
97
+
98
+ //# sourceMappingURL=tectra-ng-utils-plural.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-plural.mjs","names":[],"sources":["../../../../packages/utils/plural/src/plural.functions.ts","../../../../packages/utils/plural/src/plural.pipe.ts"],"sourcesContent":["import { formatMessage } from '@tectra-ng/core/i18n';\nimport { TxPluralCategory, TxPluralForm, TxPluralForms } from './plural.types';\n\nconst rulesCache = new Map<string, Intl.PluralRules>();\n\nfunction rules(locale: string): Intl.PluralRules {\n let found = rulesCache.get(locale);\n if (!found) {\n found = new Intl.PluralRules(locale);\n rulesCache.set(locale, found);\n }\n return found;\n}\n\nexport function pluralCategory(count: number, locale = 'en-US'): TxPluralCategory {\n return rules(locale).select(count);\n}\n\nexport function pluralForm(count: number, locale = 'en-US'): TxPluralForm {\n const category = pluralCategory(count, locale);\n return category === 'one' || category === 'few' ? category : 'many';\n}\n\nexport function plural(count: number, forms: string | TxPluralForms, locale = 'en-US'): string {\n if (typeof forms === 'string') {\n return formatMessage(forms, { count }, locale);\n }\n const text = forms[`=${count}`] ?? forms[pluralCategory(count, locale)] ?? forms.other ?? forms.many ?? '';\n return text.replace(/#/g, String(count));\n}\n","import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService } from '@tectra-ng/core/i18n';\nimport { plural, pluralForm } from './plural.functions';\nimport { TxPluralForm, TxPluralForms } from './plural.types';\n\n@Pipe({ name: 'txPluralForm', pure: false })\nexport class TxPluralFormPipe implements PipeTransform {\n private readonly localeService = inject(TxLocaleService);\n\n transform(count: number | null | undefined, locale?: string): TxPluralForm {\n return pluralForm(count ?? 0, locale ?? this.localeService.locale().intl);\n }\n}\n\n@Pipe({ name: 'txPlural', pure: false })\nexport class TxPluralPipe implements PipeTransform {\n private readonly localeService = inject(TxLocaleService);\n\n transform(count: number | null | undefined, forms: string | TxPluralForms, locale?: string): string {\n return plural(count ?? 0, forms, locale ?? this.localeService.locale().intl);\n }\n}\n"],"mappings":";;;AAGA,MAAM,6BAAa,IAAI,IAAG;AAE1B,SAAS,MA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Aa,eAAb,MAAa,aAAY;CACN,gBAAgB,OAAO,eAAe;CAEvD,UAAU,OAAkC,OAA+B,QAAe;EACxF,OAAO,OAAO,SAAS,GAAG,OAAO,UAAU,KAAK,cAAc,OAAM,CAAE,CAAC,IAAI;CAC7E;CALW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAY,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAZ,OAAA,QAAA,GAAA,gBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAY,cAAA;EAAA,MAAA;EAAA,MAAA;CAAA,CAAA;;AAAZ,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAY,YAAA,CAAA;EADxB,MAAA;EAAK,MAAA,CAAA;GAAE,MAAM;GAAY,MAAM;EAAK,CAAE"}
@@ -0,0 +1,109 @@
1
+ import { HttpErrorResponse } from "@angular/common/http";
2
+ import { retryHttpReads } from "@tectra-ng/utils/http";
3
+ import { EMPTY, Subject, catchError, defer, exhaustMap, expand, filter, finalize, fromEvent, map, of, startWith, switchMap, take, takeUntil, tap, timer } from "rxjs";
4
+ import { signal } from "@angular/core";
5
+ const TX_POLL_DEFAULT_DELAY = {
6
+ startMs: 2e3,
7
+ factor: 1.5,
8
+ maxMs: 15e3
9
+ };
10
+ const TX_POLL_SLOW_DELAY = {
11
+ startMs: 5e3,
12
+ factor: 1.5,
13
+ maxMs: 3e4
14
+ };
15
+ const hasDocument = () => typeof document !== "undefined";
16
+ function pollDelay(delay, attempt) {
17
+ return typeof delay === "number" ? delay : Math.min(delay.startMs * delay.factor ** attempt, delay.maxMs);
18
+ }
19
+ function isPageHidden() {
20
+ return hasDocument() && document.visibilityState === "hidden";
21
+ }
22
+ function waitUntilVisible() {
23
+ return defer(() => isPageHidden() ? fromEvent(document, "visibilitychange").pipe(filter(() => !isPageHidden()), take(1), map(() => void 0)) : of(void 0));
24
+ }
25
+ function toPollingError(error) {
26
+ if (!(error instanceof HttpErrorResponse)) return {
27
+ status: 0,
28
+ message: null
29
+ };
30
+ const message = error.error?.error ?? error.error?.message;
31
+ return {
32
+ status: error.status,
33
+ message: typeof message === "string" ? message : null
34
+ };
35
+ }
36
+ function poll(config) {
37
+ const { request, isActive, delay = TX_POLL_DEFAULT_DELAY, maxAttempts = Number.POSITIVE_INFINITY, retry = {}, skipErrors = false, pauseWhenHidden = true, initial } = config;
38
+ const load = (attempt) => retry === false ? request(attempt) : request(attempt).pipe(retryHttpReads(retry));
39
+ return (initial !== void 0 ? of({
40
+ value: initial,
41
+ fresh: false
42
+ }) : load(0).pipe(map((value) => ({
43
+ value,
44
+ fresh: true
45
+ })))).pipe(expand((state, index) => {
46
+ if (!hasDocument() || !isActive(state.value) || index >= maxAttempts) return EMPTY;
47
+ const next = timer(pollDelay(delay, index)).pipe(switchMap(() => pauseWhenHidden ? waitUntilVisible() : of(void 0)), switchMap(() => load(index + 1)), map((value) => ({
48
+ value,
49
+ fresh: true
50
+ })));
51
+ return skipErrors ? next.pipe(catchError(() => of({
52
+ value: state.value,
53
+ fresh: false
54
+ }))) : next;
55
+ }), filter((state) => state.fresh), map((state) => state.value));
56
+ }
57
+ function refreshEvery(config) {
58
+ const { request, delay, when = () => true, immediate = false, pauseWhenHidden = true, skipErrors = true } = config;
59
+ if (!hasDocument()) return EMPTY;
60
+ return timer(immediate ? 0 : delay, delay).pipe(filter(() => !(pauseWhenHidden && isPageHidden()) && when()), exhaustMap(() => skipErrors ? request().pipe(catchError(() => EMPTY)) : request()));
61
+ }
62
+ var TxPoller = class {
63
+ config;
64
+ restarts = new Subject();
65
+ stops = new Subject();
66
+ isLoading = signal(false, ...ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []);
67
+ isPolling = signal(false, ...ngDevMode ? [{ debugName: "isPolling" }] : /* istanbul ignore next */ []);
68
+ error = signal(null, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
69
+ constructor(config) {
70
+ this.config = config;
71
+ }
72
+ watch(params) {
73
+ this.stops.next();
74
+ return this.restarts.pipe(startWith(void 0), switchMap(() => this.cycle(params)), takeUntil(this.stops));
75
+ }
76
+ restart() {
77
+ this.restarts.next();
78
+ }
79
+ stop() {
80
+ this.stops.next();
81
+ this.error.set(null);
82
+ }
83
+ cycle(params) {
84
+ return defer(() => {
85
+ this.isLoading.set(true);
86
+ this.isPolling.set(true);
87
+ this.error.set(null);
88
+ return poll({
89
+ ...this.config,
90
+ request: (attempt) => this.config.request({
91
+ params,
92
+ attempt
93
+ })
94
+ }).pipe(tap(() => {
95
+ this.isLoading.set(false);
96
+ this.error.set(null);
97
+ }), catchError((error) => {
98
+ this.error.set(toPollingError(error));
99
+ return EMPTY;
100
+ }), finalize(() => {
101
+ this.isLoading.set(false);
102
+ this.isPolling.set(false);
103
+ }));
104
+ });
105
+ }
106
+ };
107
+ export { TX_POLL_DEFAULT_DELAY, TX_POLL_SLOW_DELAY, TxPoller, isPageHidden, poll, pollDelay, refreshEvery, toPollingError, waitUntilVisible };
108
+
109
+ //# sourceMappingURL=tectra-ng-utils-polling.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-polling.mjs","names":[],"sources":["../../../../packages/utils/polling/src/poll.ts","../../../../packages/utils/polling/src/poller.ts"],"sourcesContent":["import { HttpErrorResponse } from '@angular/common/http';\nimport { retryHttpReads } from '@tectra-ng/utils/http';\nimport { EMPTY, Observable, catchError, defer, exhaustMap, expand, filter, fromEvent, map, of, switchMap, take, timer } from 'rxjs';\nimport { TxPollBackoff, TxPollConfig, TxPollDelay, TxPollingError, TxRefreshEveryConfig } from './polling.types';\n\nexport const TX_POLL_DEFAULT_DELAY: TxPollBackoff = { startMs: 2000, factor: 1.5, maxMs: 15000 };\nexport const TX_POLL_SLOW_DELAY: TxPollBackoff = { startMs: 5000, factor: 1.5, maxMs: 30000 };\n\ninterface PollState<T> {\n value: T;\n fresh: boolean;\n}\n\nconst hasDocument = (): boolean => typeof document !== 'undefined';\n\nexport function pollDelay(delay: TxPollDelay, attempt: number): number {\n return typeof delay === 'number' ? delay : Math.min(delay.startMs * delay.factor ** attempt, delay.maxMs);\n}\n\nexport function isPageHidden(): boolean {\n return hasDocument() && document.visibilityState === 'hidden';\n}\n\nexport function waitUntilVisible(): Observable<void> {\n return defer(() =>\n isPageHidden()\n ? fromEvent(document, 'visibilitychange').pipe(\n filter(() => !isPageHidden()),\n take(1),\n map(() => undefined),\n )\n : of(undefined),\n );\n}\n\nexport function toPollingError(error: unknown): TxPollingError {\n if (!(error instanceof HttpErrorResponse)) {\n return { status: 0, message: null };\n }\n const message: unknown = error.error?.error ?? error.error?.message;\n return { status: error.status, message: typeof message === 'string' ? message : null };\n}\n\nexport function poll<T>(config: TxPollConfig<T>): Observable<T> {\n const { request, isActive, delay = TX_POLL_DEFAULT_DELAY, maxAttempts = Number.POSITIVE_INFINITY, retry = {}, skipErrors = false, pauseWhenHidden = true, initial } = config;\n const load = (attempt: number): Observable<T> => (retry === false ? request(attempt) : request(attempt).pipe(retryHttpReads(retry)));\n const first: Observable<PollState<T>> = initial !== undefined ? of({ value: initial, fresh: false }) : load(0).pipe(map((value) => ({ value, fresh: true })));\n\n return first.pipe(\n expand((state, index) => {\n if (!hasDocument() || !isActive(state.value) || index >= maxAttempts) {\n return EMPTY;\n }\n const next = timer(pollDelay(delay, index)).pipe(\n switchMap(() => (pauseWhenHidden ? waitUntilVisible() : of(undefined))),\n switchMap(() => load(index + 1)),\n map((value) => ({ value, fresh: true })),\n );\n return skipErrors ? next.pipe(catchError(() => of({ value: state.value, fresh: false }))) : next;\n }),\n filter((state) => state.fresh),\n map((state) => state.value),\n );\n}\n\nexport function refreshEvery<T>(config: TxRefreshEveryConfig<T>): Observable<T> {\n const { request, delay, when = () => true, immediate = false, pauseWhenHidden = true, skipErrors = true } = config;\n if (!hasDocument()) {\n return EMPTY;\n }\n return timer(immediate ? 0 : delay, delay).pipe(\n filter(() => !(pauseWhenHidden && isPageHidden()) && when()),\n exhaustMap(() => (skipErrors ? request().pipe(catchError(() => EMPTY)) : request())),\n );\n}\n","import { signal } from '@angular/core';\nimport { EMPTY, Observable, Subject, catchError, defer, finalize, startWith, switchMap, takeUntil, tap } from 'rxjs';\nimport { poll, toPollingError } from './poll';\nimport { TxPollerConfig, TxPollingError } from './polling.types';\n\nexport class TxPoller<TParams, T> {\n private readonly restarts = new Subject<void>();\n private readonly stops = new Subject<void>();\n\n readonly isLoading = signal(false);\n readonly isPolling = signal(false);\n readonly error = signal<TxPollingError | null>(null);\n\n constructor(private readonly config: TxPollerConfig<TParams, T>) {}\n\n watch(params: TParams): Observable<T> {\n this.stops.next();\n return this.restarts.pipe(\n startWith(undefined),\n switchMap(() => this.cycle(params)),\n takeUntil(this.stops),\n );\n }\n\n restart(): void {\n this.restarts.next();\n }\n\n stop(): void {\n this.stops.next();\n this.error.set(null);\n }\n\n private cycle(params: TParams): Observable<T> {\n return defer(() => {\n this.isLoading.set(true);\n this.isPolling.set(true);\n this.error.set(null);\n return poll<T>({ ...this.config, request: (attempt) => this.config.request({ params, attempt }) }).pipe(\n tap(() => {\n this.isLoading.set(false);\n this.error.set(null);\n }),\n catchError((error: unknown) => {\n this.error.set(toPollingError(error));\n return EMPTY;\n }),\n finalize(() => {\n this.isLoading.set(false);\n this.isPolling.set(false);\n }),\n );\n });\n }\n}\n"],"mappings":";;;;AAKA,MAAa,wBAAuC;CAAE,SAAS;CAAM,QAAQ;CAAK,OAAO;AAAK;AAC9F,MAAa,qBAAoC;CAAE,SAAS;CAAM,QAAQ;CAAK,OAAO;AAAK;AAO3F,MAAM,oBAA6B,OAAO,aAAa;AAEvD,SAAgB,UAAU,OAAoB,SAAe;CAC3D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAK,IAAI,MAAM,UAAU,MAAM,UAAU,SAAS,MAAM,KAAK;AAC1G;AAEA,SAAgB,eAAY;CAC1B,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AAK,UAAU,IAAI,IAAI;GACvB,KAAK,MAAM,IAAI,IAAI;GACnB,OAAO,KAAQ;IAAE,GAAG,KAAK;IAAQ,UAAU,YAAY,KAAK,OAAO,QAAQ;KAAE;KAAQ;IAAO,CAAE;GAAC,CAAE,CAAC,CAAC,KACjG,UAAS;IACP,KAAK,UAAU,IAAI,KAAK;IACxB,KAAK,MAAM,IAAI,IAAI;GACrB,CAAC,GACD,YAAY,UAAkB;IAC5B,KAAK,MAAM,IAAI,eAAe,KAAK,CAAC;IACpC,OAAO;GACT,CAAC,GACD,eAAc;IACZ,KAAK,UAAU,IAAI,KAAK;IACxB,KAAK,UAAU,IAAI,KAAK;GAC1B,CAAC,CAAC;EAEN,CAAC;CACH;AACD"}
@@ -0,0 +1,20 @@
1
+ function pickRandom(items, random = Math.random) {
2
+ if (!items?.length) return null;
3
+ return items[Math.floor(random() * items.length)];
4
+ }
5
+ function pickRandomN(items, count, random = Math.random) {
6
+ if (!items?.length || count <= 0) return [];
7
+ const pool = [...items];
8
+ const size = Math.min(count, pool.length);
9
+ for (let index = 0; index < size; index++) {
10
+ const swap = index + Math.floor(random() * (pool.length - index));
11
+ [pool[index], pool[swap]] = [pool[swap], pool[index]];
12
+ }
13
+ return pool.slice(0, size);
14
+ }
15
+ function shuffle(items, random = Math.random) {
16
+ return pickRandomN(items, items.length, random);
17
+ }
18
+ export { pickRandom, pickRandomN, shuffle };
19
+
20
+ //# sourceMappingURL=tectra-ng-utils-random.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-random.mjs","names":[],"sources":["../../../../packages/utils/random/src/random.ts"],"sourcesContent":["export function pickRandom<T>(items: readonly T[] | null | undefined, random: () => number = Math.random): T | null {\n if (!items?.length) {\n return null;\n }\n return items[Math.floor(random() * items.length)];\n}\n\nexport function pickRandomN<T>(items: readonly T[] | null | undefined, count: number, random: () => number = Math.random): T[] {\n if (!items?.length || count <= 0) {\n return [];\n }\n const pool = [...items];\n const size = Math.min(count, pool.length);\n for (let index = 0; index < size; index++) {\n const swap = index + Math.floor(random() * (pool.length - index));\n [pool[index], pool[swap]] = [pool[swap], pool[index]];\n }\n return pool.slice(0, size);\n}\n\nexport function shuffle<T>(items: readonly T[], random: () => number = Math.random): T[] {\n return pickRandomN(items, items.length, random);\n}\n"],"mappings":"AAAA,SAAgB,WAAc,OAAwC,SAAuB,KAAK,QAAM;CACtG,IAAI,CAAC,OAAO,QACV,OAAO;CAET,OAAO,MAAM,KAAK,MAAM,OAAM,IAAK,MAAM,MAAM;AACjD;AAEA,SAAgB,YAAe,OAAwC,OAAe,SAAuB,KAAK,QAAM;CACtH,IAAI,CAAC,OAAO,UAAU,SAAS,GAC7B,OAAO,CAAA;CAET,MAAM,OAAO,CAAC,GAAG,KAAK;CACtB,MAAM,OAAO,KAAK,IAAI,OAAO,KAAK,MAAM;CACxC,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,SAAS;EACzC,MAAM,OAAO,QAAQ,KAAK,MAAM,OAAM,KAAM,KAAK,SAAS,MAAM;EAChE,CAAC,KAAK,QAAQ,KAAK,SAAS,CAAC,KAAK,OAAO,KAAK,MAAM;CACtD;CACA,OAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEA,SAAgB,QAAW,OAAqB,SAAuB,KAAK,QAAM;CAChF,OAAO,YAAY,OAAO,MAAM,QAAQ,MAAM;AAChD"}
@@ -0,0 +1,87 @@
1
+ import * as i0 from "@angular/core";
2
+ import { Pipe, inject } from "@angular/core";
3
+ import { TxLocaleService } from "@tectra-ng/core/i18n";
4
+ import { MS_IN_SECOND, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, calendarDaysBetween, toDate } from "@tectra-ng/utils/date";
5
+ const DAYS_IN_MONTH = 30;
6
+ const DAYS_IN_YEAR = 365;
7
+ function relativeTime(value, options = {}) {
8
+ const date = toDate(value);
9
+ if (!date) return "";
10
+ const now = new Date(options.now ?? Date.now());
11
+ const format = new Intl.RelativeTimeFormat(options.locale ?? "en-US", {
12
+ numeric: options.numeric ?? "auto",
13
+ style: options.style ?? "long"
14
+ });
15
+ const days = calendarDaysBetween(now, date);
16
+ if (options.granularity !== "day") {
17
+ const seconds = (date.getTime() - now.getTime()) / MS_IN_SECOND;
18
+ const absolute = Math.abs(seconds);
19
+ if (absolute < SECONDS_IN_MINUTE) return format.format(options.numeric === "always" ? Math.trunc(seconds) : 0, "second");
20
+ if (absolute < SECONDS_IN_HOUR) return format.format(Math.trunc(seconds / SECONDS_IN_MINUTE), "minute");
21
+ if (absolute < SECONDS_IN_DAY && days === 0) return format.format(Math.trunc(seconds / SECONDS_IN_HOUR), "hour");
22
+ }
23
+ const largest = options.largestUnit ?? "year";
24
+ if (largest === "day" || Math.abs(days) < DAYS_IN_MONTH) return format.format(days, "day");
25
+ if (largest === "month" || Math.abs(days) < DAYS_IN_YEAR) return format.format(Math.trunc(days / DAYS_IN_MONTH), "month");
26
+ return format.format(Math.trunc(days / DAYS_IN_YEAR), "year");
27
+ }
28
+ var TxRelativeTimePipe = class TxRelativeTimePipe {
29
+ localeService = inject(TxLocaleService);
30
+ lastKey = "";
31
+ lastText = "";
32
+ transform(value, options = {}) {
33
+ const locale = options.locale ?? this.localeService.locale().intl;
34
+ const now = options.now ?? Date.now();
35
+ const key = [
36
+ value instanceof Date ? value.getTime() : value,
37
+ locale,
38
+ new Date(now).getTime(),
39
+ options.granularity,
40
+ options.largestUnit,
41
+ options.numeric,
42
+ options.style
43
+ ].join("|");
44
+ if (key !== this.lastKey) {
45
+ this.lastKey = key;
46
+ this.lastText = relativeTime(value, {
47
+ ...options,
48
+ locale,
49
+ now
50
+ });
51
+ }
52
+ return this.lastText;
53
+ }
54
+ static ɵfac = i0.ɵɵngDeclareFactory({
55
+ minVersion: "12.0.0",
56
+ version: "22.2.3",
57
+ ngImport: i0,
58
+ type: TxRelativeTimePipe,
59
+ deps: [],
60
+ target: i0.ɵɵFactoryTarget.Pipe
61
+ });
62
+ static ɵpipe = i0.ɵɵngDeclarePipe({
63
+ minVersion: "14.0.0",
64
+ version: "22.2.3",
65
+ ngImport: i0,
66
+ type: TxRelativeTimePipe,
67
+ isStandalone: true,
68
+ name: "txRelativeTime",
69
+ pure: false
70
+ });
71
+ };
72
+ i0.ɵɵngDeclareClassMetadata({
73
+ minVersion: "12.0.0",
74
+ version: "22.2.3",
75
+ ngImport: i0,
76
+ type: TxRelativeTimePipe,
77
+ decorators: [{
78
+ type: Pipe,
79
+ args: [{
80
+ name: "txRelativeTime",
81
+ pure: false
82
+ }]
83
+ }]
84
+ });
85
+ export { TxRelativeTimePipe, relativeTime };
86
+
87
+ //# sourceMappingURL=tectra-ng-utils-relative-time.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-relative-time.mjs","names":[],"sources":["../../../../packages/utils/relative-time/src/relative-time.ts"],"sourcesContent":["import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { TxLocaleService } from '@tectra-ng/core/i18n';\nimport { MS_IN_SECOND, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, TxDateInput, calendarDaysBetween, toDate } from '@tectra-ng/utils/date';\nimport { TxRelativeTimeOptions } from './relative-time.types';\n\nconst DAYS_IN_MONTH = 30;\nconst DAYS_IN_YEAR = 365;\n\nexport function relativeTime(value: TxDateInput, options: TxRelativeTimeOptions = {}): string {\n const date = toDate(value);\n if (!date) {\n return '';\n }\n const now = new Date(options.now ?? Date.now());\n const format = new Intl.RelativeTimeFormat(options.locale ?? 'en-US', { numeric: options.numeric ?? 'auto', style: options.style ?? 'long' });\n const days = calendarDaysBetween(now, date);\n\n if (options.granularity !== 'day') {\n const seconds = (date.getTime() - now.getTime()) / MS_IN_SECOND;\n const absolute = Math.abs(seconds);\n if (absolute < SECONDS_IN_MINUTE) {\n return format.format(options.numeric === 'always' ? Math.trunc(seconds) : 0, 'second');\n }\n if (absolute < SECONDS_IN_HOUR) {\n return format.format(Math.trunc(seconds / SECONDS_IN_MINUTE), 'minute');\n }\n if (absolute < SECONDS_IN_DAY && days === 0) {\n return format.format(Math.trunc(seconds / SECONDS_IN_HOUR), 'hour');\n }\n }\n\n const largest = options.largestUnit ?? 'year';\n if (largest === 'day' || Math.abs(days) < DAYS_IN_MONTH) {\n return format.format(days, 'day');\n }\n if (largest === 'month' || Math.abs(days) < DAYS_IN_YEAR) {\n return format.format(Math.trunc(days / DAYS_IN_MONTH), 'month');\n }\n return format.format(Math.trunc(days / DAYS_IN_YEAR), 'year');\n}\n\n@Pipe({ name: 'txRelativeTime', pure: false })\nexport class TxRelativeTimePipe implements PipeTransform {\n private readonly localeService = inject(TxLocaleService);\n private lastKey = '';\n private lastText = '';\n\n transform(value: TxDateInput, options: TxRelativeTimeOptions = {}): string {\n const locale = options.locale ?? this.localeService.locale().intl;\n const now = options.now ?? Date.now();\n const key = [value instanceof Date ? value.getTime() : value, locale, new Date(now).getTime(), options.granularity, options.largestUnit, options.numeric, options.style].join('|');\n if (key !== this.lastKey) {\n this.lastKey = key;\n this.lastText = relativeTime(value, { ...options, locale, now });\n }\n return this.lastText;\n }\n}\n"],"mappings":";;;;AAKA,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAErB,SAAgB,aAAa,OAAoB,UAAiC,CAAA,GAAE;CAClF,MAAM,OAAO,OAAO,KAAK;CACzB,IAAI,CAAC,MACH,OAAO;CAET,MAAM,MAAM,IAAI,KAAK,QAAQ,OAAO,KAAK,IAAG,CAAE;CAC9C,MAAM,SAAS,IAAI,KAAK,mBAAmB,QAAQ,UAAU,SAAS;EAAE,SAAS,QAAQ,WAAW;EAAQ,OAAO,QAAQ,SAAS;CAAM,CAAE;CAC5I,MAAM,OAAO,oBAAoB,KAAK,IAAI;CAE1C,IAAI,QAAQ,gBAAgB,OAAO;EACjC,MAAM,WAAW,KAAK,QAAO,IAAK,IAAI,QAAO,KAAM;EACnD,MAAM,WAAW,KAAK,IAAI,OAAO;EACjC,IAAI,WAAW,mBACb,OAAO,OAAO,OA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AA;CAAlB,OAAA,QAAA,GAAA,gBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAkB,cAAA;EAAA,MAAA;EAAA,MAAA;CAAA,CAAA;;AAAlB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAkB,YAAA,CAAA;EAD9B,MAAA;EAAK,MAAA,CAAA;GAAE,MAAM;GAAkB,MAAM;EAAK,CAAE"}
@@ -0,0 +1,136 @@
1
+ import * as i0 from "@angular/core";
2
+ import { Directive, ElementRef, booleanAttribute, inject, input, numberAttribute, output } from "@angular/core";
3
+ var TxScrollEnd = class TxScrollEnd {
4
+ host = inject(ElementRef).nativeElement;
5
+ reportedHeight = -1;
6
+ offset = input(48, {
7
+ ...ngDevMode ? { debugName: "offset" } : /* istanbul ignore next */ {},
8
+ transform: numberAttribute
9
+ });
10
+ maxLimit = input(Number.POSITIVE_INFINITY, {
11
+ ...ngDevMode ? { debugName: "maxLimit" } : /* istanbul ignore next */ {},
12
+ transform: numberAttribute
13
+ });
14
+ currentCount = input(0, {
15
+ ...ngDevMode ? { debugName: "currentCount" } : /* istanbul ignore next */ {},
16
+ transform: numberAttribute
17
+ });
18
+ disabled = input(false, {
19
+ ...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
20
+ transform: booleanAttribute
21
+ });
22
+ scrolledToBottom = output();
23
+ check() {
24
+ const { scrollHeight, scrollTop, clientHeight } = this.host;
25
+ if (!(scrollHeight - scrollTop - clientHeight <= this.offset()) || this.disabled() || this.currentCount() >= this.maxLimit() || scrollHeight === this.reportedHeight) return;
26
+ this.reportedHeight = scrollHeight;
27
+ this.scrolledToBottom.emit();
28
+ }
29
+ reset() {
30
+ this.reportedHeight = -1;
31
+ }
32
+ static ɵfac = i0.ɵɵngDeclareFactory({
33
+ minVersion: "12.0.0",
34
+ version: "22.2.3",
35
+ ngImport: i0,
36
+ type: TxScrollEnd,
37
+ deps: [],
38
+ target: i0.ɵɵFactoryTarget.Directive
39
+ });
40
+ static ɵdir = i0.ɵɵngDeclareDirective({
41
+ minVersion: "17.1.0",
42
+ version: "22.2.3",
43
+ type: TxScrollEnd,
44
+ isStandalone: true,
45
+ selector: "[txScrollEnd]",
46
+ inputs: {
47
+ offset: {
48
+ classPropertyName: "offset",
49
+ publicName: "offset",
50
+ isSignal: true,
51
+ isRequired: false,
52
+ transformFunction: null
53
+ },
54
+ maxLimit: {
55
+ classPropertyName: "maxLimit",
56
+ publicName: "maxLimit",
57
+ isSignal: true,
58
+ isRequired: false,
59
+ transformFunction: null
60
+ },
61
+ currentCount: {
62
+ classPropertyName: "currentCount",
63
+ publicName: "currentCount",
64
+ isSignal: true,
65
+ isRequired: false,
66
+ transformFunction: null
67
+ },
68
+ disabled: {
69
+ classPropertyName: "disabled",
70
+ publicName: "disabled",
71
+ isSignal: true,
72
+ isRequired: false,
73
+ transformFunction: null
74
+ }
75
+ },
76
+ outputs: { scrolledToBottom: "scrolledToBottom" },
77
+ host: { listeners: { "scroll": "check()" } },
78
+ exportAs: ["txScrollEnd"],
79
+ ngImport: i0
80
+ });
81
+ };
82
+ i0.ɵɵngDeclareClassMetadata({
83
+ minVersion: "12.0.0",
84
+ version: "22.2.3",
85
+ ngImport: i0,
86
+ type: TxScrollEnd,
87
+ decorators: [{
88
+ type: Directive,
89
+ args: [{
90
+ selector: "[txScrollEnd]",
91
+ exportAs: "txScrollEnd",
92
+ host: { "(scroll)": "check()" }
93
+ }]
94
+ }],
95
+ propDecorators: {
96
+ offset: [{
97
+ type: i0.Input,
98
+ args: [{
99
+ isSignal: true,
100
+ alias: "offset",
101
+ required: false
102
+ }]
103
+ }],
104
+ maxLimit: [{
105
+ type: i0.Input,
106
+ args: [{
107
+ isSignal: true,
108
+ alias: "maxLimit",
109
+ required: false
110
+ }]
111
+ }],
112
+ currentCount: [{
113
+ type: i0.Input,
114
+ args: [{
115
+ isSignal: true,
116
+ alias: "currentCount",
117
+ required: false
118
+ }]
119
+ }],
120
+ disabled: [{
121
+ type: i0.Input,
122
+ args: [{
123
+ isSignal: true,
124
+ alias: "disabled",
125
+ required: false
126
+ }]
127
+ }],
128
+ scrolledToBottom: [{
129
+ type: i0.Output,
130
+ args: ["scrolledToBottom"]
131
+ }]
132
+ }
133
+ });
134
+ export { TxScrollEnd };
135
+
136
+ //# sourceMappingURL=tectra-ng-utils-scroll-end.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-scroll-end.mjs","names":[],"sources":["../../../../packages/utils/scroll-end/src/scroll-end.directive.ts"],"sourcesContent":["import { Directive, ElementRef, booleanAttribute, inject, input, numberAttribute, output } from '@angular/core';\n\n@Directive({\n selector: '[txScrollEnd]',\n exportAs: 'txScrollEnd',\n host: { '(scroll)': 'check()' },\n})\nexport class TxScrollEnd {\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private reportedHeight = -1;\n\n readonly offset = input<number, unknown>(48, { transform: numberAttribute });\n readonly maxLimit = input<number, unknown>(Number.POSITIVE_INFINITY, { transform: numberAttribute });\n readonly currentCount = input<number, unknown>(0, { transform: numberAttribute });\n readonly disabled = input<boolean, unknown>(false, { transform: booleanAttribute });\n\n readonly scrolledToBottom = output<void>();\n\n check(): void {\n const { scrollHeight, scrollTop, clientHeight } = this.host;\n const atEnd = scrollHeight - scrollTop - clientHeight <= this.offset();\n if (!atEnd || this.disabled() || this.currentCount() >= this.maxLimit() || scrollHeight === this.reportedHeight) {\n return;\n }\n this.reportedHeight = scrollHeight;\n this.scrolledToBottom.emit();\n }\n\n reset(): void {\n this.reportedHeight = -1;\n }\n}\n"],"mappings":";;AAOA,IAAa,cAAb,MAAa,YAAW;CACL,OAAO,OAAgC,UAAU,CAAC,CAAC;CAC5D,iBAAiB;CAEhB,SAAS,MAAuB,IAAE;EAAA,GAAA,YAAA,EAAA,WAAA,SAAA,+BAAA,CAAA;EAAI,WAAW;CAAe,CAAA;CAChE,WAAW,MAAuB,OAAO,m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EAAA,UAAA,CAAA,aAAA;EAAA,UAAA;CAAA,CAAA;;AAAX,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAW,YAAA,CAAA;EALvB,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM,EAAE,YAAY,UAAS;EAC9B,CAAA"}
@@ -0,0 +1,52 @@
1
+ import { computed, signal } from "@angular/core";
2
+ var TxSelection = class {
3
+ getKey;
4
+ selected = signal(/* @__PURE__ */ new Set(), ...ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []);
5
+ selectedIds = this.selected.asReadonly();
6
+ count = computed(() => this.selected().size, ...ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []);
7
+ constructor(getKey) {
8
+ this.getKey = getKey;
9
+ }
10
+ select(predicate, items, isChecked) {
11
+ this.change(items.filter(predicate).map((item) => this.getKey(item)), isChecked);
12
+ }
13
+ toggleOne(idOrItem, isChecked = !this.isSelected(idOrItem)) {
14
+ this.change([this.keyOf(idOrItem)], isChecked);
15
+ }
16
+ toggleAll(items, isChecked = !this.areAllSelected(items)) {
17
+ this.change(items.map((item) => this.getKey(item)), isChecked);
18
+ }
19
+ isSelected(idOrItem) {
20
+ return this.selected().has(this.keyOf(idOrItem));
21
+ }
22
+ areAllSelected(items) {
23
+ return items.length > 0 && items.every((item) => this.selected().has(this.getKey(item)));
24
+ }
25
+ areAllSelectedWithPredicate(items, predicate) {
26
+ return this.areAllSelected(items.filter(predicate));
27
+ }
28
+ isPartial(items) {
29
+ const chosen = items.filter((item) => this.selected().has(this.getKey(item))).length;
30
+ return chosen > 0 && chosen < items.length;
31
+ }
32
+ selectedItems(items) {
33
+ return items.filter((item) => this.selected().has(this.getKey(item)));
34
+ }
35
+ setSelected(ids) {
36
+ this.selected.set(new Set(ids));
37
+ }
38
+ clear() {
39
+ this.selected.set(/* @__PURE__ */ new Set());
40
+ }
41
+ keyOf(idOrItem) {
42
+ return typeof idOrItem === "string" ? idOrItem : this.getKey(idOrItem);
43
+ }
44
+ change(keys, isChecked) {
45
+ const next = new Set(this.selected());
46
+ keys.forEach((key) => isChecked ? next.add(key) : next.delete(key));
47
+ this.selected.set(next);
48
+ }
49
+ };
50
+ export { TxSelection };
51
+
52
+ //# sourceMappingURL=tectra-ng-utils-selection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-selection.mjs","names":[],"sources":["../../../../packages/utils/selection/src/selection.ts"],"sourcesContent":["import { Signal, computed, signal } from '@angular/core';\n\nexport class TxSelection<T> {\n private readonly selected = signal<ReadonlySet<string>>(new Set());\n\n readonly selectedIds: Signal<ReadonlySet<string>> = this.selected.asReadonly();\n readonly count = computed(() => this.selected().size);\n\n constructor(private readonly getKey: (item: T) => string) {}\n\n select(predicate: (item: T) => boolean, items: readonly T[], isChecked: boolean): void {\n this.change(items.filter(predicate).map((item) => this.getKey(item)), isChecked);\n }\n\n toggleOne(idOrItem: string | T, isChecked = !this.isSelected(idOrItem)): void {\n this.change([this.keyOf(idOrItem)], isChecked);\n }\n\n toggleAll(items: readonly T[], isChecked = !this.areAllSelected(items)): void {\n this.change(items.map((item) => this.getKey(item)), isChecked);\n }\n\n isSelected(idOrItem: string | T): boolean {\n return this.selected().has(this.keyOf(idOrItem));\n }\n\n areAllSelected(items: readonly T[]): boolean {\n return items.length > 0 && items.every((item) => this.selected().has(this.getKey(item)));\n }\n\n areAllSelectedWithPredicate(items: readonly T[], predicate: (item: T) => boolean): boolean {\n return this.areAllSelected(items.filter(predicate));\n }\n\n isPartial(items: readonly T[]): boolean {\n const chosen = items.filter((item) => this.selected().has(this.getKey(item))).length;\n return chosen > 0 && chosen < items.length;\n }\n\n selectedItems(items: readonly T[]): T[] {\n return items.filter((item) => this.selected().has(this.getKey(item)));\n }\n\n setSelected(ids: readonly string[]): void {\n this.selected.set(new Set(ids));\n }\n\n clear(): void {\n this.selected.set(new Set());\n }\n\n private keyOf(idOrItem: string | T): string {\n return typeof idOrItem === 'string' ? idOrItem : this.getKey(idOrItem);\n }\n\n private change(keys: readonly string[], isChecked: boolean): void {\n const next = new Set(this.selected());\n keys.forEach((key) => (isChecked ? next.add(key) : next.delete(key)));\n this.selected.set(next);\n }\n}\n"],"mappings":";AAEA,IAAa,cAAb,MAAwB;CAMO;CALZ,WAAW,uBAA4B,IAAI,IAAG,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAEzD,cAA2C,KAAK,SAAS,WAAU;CACnE,QAAQ,eAAe,KAAK,SAAQ,CAAE,CAAC,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAErD,YAA6B,QAA2B;EAA3B,KAAA,SAAA;CAA8B;CAE3D,OAAO,WAAiC,OAAqB,WAAkB;EAC7E,KAAK,OAAO,MAAM,OAAO,SAAS,CAAC,CAAC,KAAK,SAAS,KAAK,OAAO,IAAI,CAAC,GAAG,SAAS;CACjF;CAEA,UAAU,UAAsB,YAAY,CAAC,KAAK,WAAW,QAAQ,GAAC;EACpE,KAAK,OAAO,CAAC,KAAK,MAAM,QAAQ,CAAC,GAAG,SAAS;CAC/C;CAEA,UAAU,OAAqB,YAAY,CAAC,KAAK,eAAe,KAAK,GAAC;EACpE,KAAK,OAAO,MAAM,KAAK,SAAS,KAAK,OAAO,IAAI,CAAC,GAAG,SAAS;CAC/D;CAEA,WAAW,UAAoB;EAC7B,OAAO,KAAK,SAAQ,CAAE,CAAC,IAAI,KAAK,MAAM,QAAQ,CAAC;CACjD;CAEA,eAAe,OAAmB;EAChC,OAAO,MAAM,SAAS,KAAK,MAAM,OAAO,SAAS,KAAK,SAAQ,CAAE,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC;CACzF;CAEA,4BAA4B,OAAqB,WAA+B;EAC9E,OAAO,KAAK,eAAe,MAAM,OAAO,SAAS,CAAC;CACpD;CAEA,UAAU,OAAmB;EAC3B,MAAM,SAAS,MAAM,QAAQ,SAAS,KAAK,SAAQ,CAAE,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;EAC9E,OAAO,SAAS,KAAK,SAAS,MAAM;CACtC;CAEA,cAAc,OAAmB;EAC/B,OAAO,MAAM,QAAQ,SAAS,KAAK,SAAQ,CAAE,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC;CACtE;CAEA,YAAY,KAAsB;EAChC,KAAK,SAAS,IAAI,IAAI,IAAI,GAAG,CAAC;CAChC;CAEA,QAAK;EACH,KAAK,SAAS,oBAAI,IAAI,IAAG,CAAE;CAC7B;CAEQ,MAAM,UAAoB;EAChC,OAAO,OAAO,aAAa,WAAW,WAAW,KAAK,OAAO,QAAQ;CACvE;CAEQ,OAAO,MAAyB,WAAkB;EACxD,MAAM,OAAO,IAAI,IAAI,KAAK,SAAQ,CAAE;EACpC,KAAK,SAAS,QAAS,YAAY,KAAK,IAAI,GAAG,IAAI,KAAK,OAAO,GAAG,CAAE;EACpE,KAAK,SAAS,IAAI,IAAI;CACxB;AACD"}
@@ -0,0 +1,92 @@
1
+ import * as i0 from "@angular/core";
2
+ import { Directive, ElementRef, Renderer2, booleanAttribute, effect, inject, input } from "@angular/core";
3
+ function toEventList(value) {
4
+ if (Array.isArray(value)) return value;
5
+ return typeof value === "string" && value.trim() ? value.trim().split(/[\s,]+/) : ["click"];
6
+ }
7
+ var TxStopPropagation = class TxStopPropagation {
8
+ element = inject(ElementRef).nativeElement;
9
+ renderer = inject(Renderer2);
10
+ events = input(["click"], {
11
+ ...ngDevMode ? { debugName: "events" } : /* istanbul ignore next */ {},
12
+ alias: "txStopPropagation",
13
+ transform: toEventList
14
+ });
15
+ preventDefault = input(false, {
16
+ ...ngDevMode ? { debugName: "preventDefault" } : /* istanbul ignore next */ {},
17
+ transform: booleanAttribute
18
+ });
19
+ constructor() {
20
+ effect((onCleanup) => {
21
+ const stops = [...this.events()].map((name) => this.renderer.listen(this.element, name, (event) => {
22
+ event.stopPropagation();
23
+ if (this.preventDefault()) event.preventDefault();
24
+ }));
25
+ onCleanup(() => stops.forEach((stop) => stop()));
26
+ });
27
+ }
28
+ static ɵfac = i0.ɵɵngDeclareFactory({
29
+ minVersion: "12.0.0",
30
+ version: "22.2.3",
31
+ ngImport: i0,
32
+ type: TxStopPropagation,
33
+ deps: [],
34
+ target: i0.ɵɵFactoryTarget.Directive
35
+ });
36
+ static ɵdir = i0.ɵɵngDeclareDirective({
37
+ minVersion: "17.1.0",
38
+ version: "22.2.3",
39
+ type: TxStopPropagation,
40
+ isStandalone: true,
41
+ selector: "[txStopPropagation]",
42
+ inputs: {
43
+ events: {
44
+ classPropertyName: "events",
45
+ publicName: "txStopPropagation",
46
+ isSignal: true,
47
+ isRequired: false,
48
+ transformFunction: null
49
+ },
50
+ preventDefault: {
51
+ classPropertyName: "preventDefault",
52
+ publicName: "preventDefault",
53
+ isSignal: true,
54
+ isRequired: false,
55
+ transformFunction: null
56
+ }
57
+ },
58
+ ngImport: i0
59
+ });
60
+ };
61
+ i0.ɵɵngDeclareClassMetadata({
62
+ minVersion: "12.0.0",
63
+ version: "22.2.3",
64
+ ngImport: i0,
65
+ type: TxStopPropagation,
66
+ decorators: [{
67
+ type: Directive,
68
+ args: [{ selector: "[txStopPropagation]" }]
69
+ }],
70
+ ctorParameters: () => [],
71
+ propDecorators: {
72
+ events: [{
73
+ type: i0.Input,
74
+ args: [{
75
+ isSignal: true,
76
+ alias: "txStopPropagation",
77
+ required: false
78
+ }]
79
+ }],
80
+ preventDefault: [{
81
+ type: i0.Input,
82
+ args: [{
83
+ isSignal: true,
84
+ alias: "preventDefault",
85
+ required: false
86
+ }]
87
+ }]
88
+ }
89
+ });
90
+ export { TxStopPropagation };
91
+
92
+ //# sourceMappingURL=tectra-ng-utils-stop-propagation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tectra-ng-utils-stop-propagation.mjs","names":[],"sources":["../../../../packages/utils/stop-propagation/src/stop-propagation.directive.ts"],"sourcesContent":["import { Directive, ElementRef, Renderer2, booleanAttribute, effect, inject, input } from '@angular/core';\n\nfunction toEventList(value: unknown): readonly string[] {\n if (Array.isArray(value)) {\n return value;\n }\n return typeof value === 'string' && value.trim() ? value.trim().split(/[\\s,]+/) : ['click'];\n}\n\n@Directive({ selector: '[txStopPropagation]' })\nexport class TxStopPropagation {\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly renderer = inject(Renderer2);\n\n readonly events = input<readonly string[], unknown>(['click'], { alias: 'txStopPropagation', transform: toEventList });\n readonly preventDefault = input<boolean, unknown>(false, { transform: booleanAttribute });\n\n constructor() {\n effect((onCleanup) => {\n const stops = [...this.events()].map((name) =>\n this.renderer.listen(this.element, name, (event: Event) => {\n event.stopPropagation();\n if (this.preventDefault()) {\n event.preventDefault();\n }\n }),\n );\n onCleanup(() => stops.forEach((stop) => stop()));\n });\n }\n}\n"],"mappings":";;AAEA,SAAS,YAAY,OAAc;CACjC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO;CAET,OAAO,OAAO,UAAU,YAAY,MAAM,KAAI,IAAK,MAAM,KAAI,CAAE,CAAC,MAAM,QAAQ,IAAI,CAAC,OAAO;AAC5F;AAGA,IAAa,oBAAb,MAAa,kBAAiB;CACX,UAAU,OAAgC,UAAU,CAAC,CAAC;CACtD,WAAW,OAAO,SAAS;CAEnC,SAAS,MAAkC,CAAC,OAAO,GAAC;EAAA,GAAA,YAAA,EAAA,WAAA,SAAA,+BAAA,CAAA;EAAI,OAAO;EAAqB,WAAW;CAAW,CAAA;CAC1G,iBAAiB,MAAwB,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,iBAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CAEtF,cAAA;EACE,QAAQ,cAAa;GACnB,MAAM,QAAQ,CAAC,GAAG,KAAK,OAAM,CAAE,CAAC,CAAC,KAAK,SACpC,KAAK,SAAS,OAAO,KAAK,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