@ibragim-dev-org/ui-forge-library 1.2.5 → 1.2.7
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.
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import * as i2$1 from '@angular/router';
|
|
2
|
+
import { NavigationEnd, NavigationStart, ActivationEnd } from '@angular/router';
|
|
3
|
+
import { BehaviorSubject, filter, take, fromEvent, tap, debounceTime, asyncScheduler, Subscription, timer, switchMap, scheduled, interval, takeWhile, finalize, Subject, takeUntil } from 'rxjs';
|
|
1
4
|
import * as i0 from '@angular/core';
|
|
2
5
|
import { input, effect, Directive, Injectable, EventEmitter, Output, Input, PLATFORM_ID, Inject, Pipe, Attribute, ChangeDetectionStrategy, Component, signal, model, computed, viewChild, untracked, output, Injector, afterRenderEffect, contentChildren, contentChild, ViewChildren } from '@angular/core';
|
|
3
6
|
import { isPlatformBrowser, DOCUMENT, NgStyle } from '@angular/common';
|
|
4
7
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
5
|
-
import { fromEvent, tap, debounceTime, asyncScheduler, Subscription, timer, switchMap, scheduled, filter, take, BehaviorSubject, Subject, takeUntil } from 'rxjs';
|
|
6
8
|
import * as i2 from '@angular/platform-browser';
|
|
7
9
|
import { PhoneNumberUtil, AsYouTypeFormatter } from 'google-libphonenumber';
|
|
8
10
|
import * as i1 from '@angular/cdk/overlay';
|
|
9
11
|
import { OverlayConfig, FlexibleConnectedPositionStrategy } from '@angular/cdk/overlay';
|
|
10
12
|
import { ComponentPortal } from '@angular/cdk/portal';
|
|
11
|
-
import * as i2$1 from '@angular/router';
|
|
12
|
-
import { NavigationEnd } from '@angular/router';
|
|
13
13
|
import { ulid } from 'ulid';
|
|
14
14
|
import { form } from '@angular/forms/signals';
|
|
15
15
|
|
|
@@ -54,6 +54,138 @@ class DateUtils {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
class RouterBehavior {
|
|
58
|
+
static router;
|
|
59
|
+
static previousUrl;
|
|
60
|
+
static navigationState;
|
|
61
|
+
static routeDataSubj = new BehaviorSubject({});
|
|
62
|
+
static trigger;
|
|
63
|
+
static location;
|
|
64
|
+
static get routeData() {
|
|
65
|
+
return this.routeDataSubj.value;
|
|
66
|
+
}
|
|
67
|
+
static get navigationTrigger() {
|
|
68
|
+
return this.trigger;
|
|
69
|
+
}
|
|
70
|
+
static get isImperative() {
|
|
71
|
+
return this.trigger === 'imperative';
|
|
72
|
+
}
|
|
73
|
+
static setup(router, location) {
|
|
74
|
+
this.router = router;
|
|
75
|
+
this.location = location;
|
|
76
|
+
this.observeEvents();
|
|
77
|
+
}
|
|
78
|
+
static onNavEnd(cb) {
|
|
79
|
+
this.router.events
|
|
80
|
+
.pipe(filter((e) => e instanceof NavigationEnd), take(1))
|
|
81
|
+
.subscribe(() => cb());
|
|
82
|
+
}
|
|
83
|
+
static onNavEndInfinity(cb) {
|
|
84
|
+
this.router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe(() => cb());
|
|
85
|
+
}
|
|
86
|
+
static getRouteDataChanges() {
|
|
87
|
+
return RouterBehavior.routeDataSubj.asObservable();
|
|
88
|
+
}
|
|
89
|
+
static clearQueryParam(currentParams, removeKey) {
|
|
90
|
+
if (typeof currentParams === 'string') {
|
|
91
|
+
currentParams = this.queryStringToObject(currentParams);
|
|
92
|
+
}
|
|
93
|
+
const params = { ...currentParams };
|
|
94
|
+
if (!params[removeKey]) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const path = this.location.path().split('?')[0];
|
|
98
|
+
const query = [];
|
|
99
|
+
delete params[removeKey];
|
|
100
|
+
Object.keys(params).forEach((key) => {
|
|
101
|
+
query.push(`${key}=${params[key]}`);
|
|
102
|
+
});
|
|
103
|
+
this.location.replaceState(path, query.join('&'));
|
|
104
|
+
}
|
|
105
|
+
static queryStringToObject(url) {
|
|
106
|
+
return [...new URLSearchParams(url.split('?')[1])].reduce((a, [k, v]) => ((a[k] = v), a), {});
|
|
107
|
+
}
|
|
108
|
+
static observeEvents() {
|
|
109
|
+
const isPrimaryOutlet = (snapshot) => snapshot.outlet === 'primary' && snapshot.parent?.outlet === 'primary';
|
|
110
|
+
let snapshotData = {};
|
|
111
|
+
let navStartUrl = '';
|
|
112
|
+
this.router.events.subscribe((event) => {
|
|
113
|
+
if (event instanceof NavigationStart) {
|
|
114
|
+
this.trigger = event.navigationTrigger;
|
|
115
|
+
this.navigationState = this.router.currentNavigation()?.extras.state || {};
|
|
116
|
+
snapshotData = {};
|
|
117
|
+
navStartUrl = this.router.url;
|
|
118
|
+
}
|
|
119
|
+
// we provide snapshot only of primary outlet of application routing
|
|
120
|
+
if (event instanceof ActivationEnd && isPrimaryOutlet(event.snapshot)) {
|
|
121
|
+
// aggregate snapshot date through all router levels
|
|
122
|
+
snapshotData = Object.assign(snapshotData, event.snapshot.data || {});
|
|
123
|
+
this.routeDataSubj.next(snapshotData);
|
|
124
|
+
}
|
|
125
|
+
// set snapshotData on activation end to prevent UI flickering
|
|
126
|
+
if (event instanceof NavigationEnd) {
|
|
127
|
+
this.previousUrl = navStartUrl;
|
|
128
|
+
this.routeDataSubj.next(snapshotData);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Create UrlTree from string, same as default but use string instead string[] */
|
|
134
|
+
function createUrlTree(url, extras) {
|
|
135
|
+
const urlTree = RouterBehavior.router.createUrlTree([url], extras);
|
|
136
|
+
removeUrlTreeOutlet(urlTree, 'primaryModal');
|
|
137
|
+
return urlTree;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Navigate by string url using NavigationExtras,
|
|
141
|
+
* because Router allows only NavigationBehaviorOptions at navigateByUrl()
|
|
142
|
+
*/
|
|
143
|
+
function navigateByUrl(url, extras, removeOutlet) {
|
|
144
|
+
if (url.includes('?')) {
|
|
145
|
+
const queryString = url.split('?')[1];
|
|
146
|
+
const urlParams = new URLSearchParams(queryString);
|
|
147
|
+
const query = paramsToObject(urlParams.entries());
|
|
148
|
+
url = url.replace(`?${queryString}`, '');
|
|
149
|
+
if (extras && extras.queryParams) {
|
|
150
|
+
extras.queryParams = { ...extras.queryParams, ...query };
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
extras = { queryParams: query };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const urlTree = createUrlTree(url, extras);
|
|
157
|
+
// close any modals on primary router navigation
|
|
158
|
+
removeUrlTreeOutlet(urlTree, 'primaryModal');
|
|
159
|
+
if (removeOutlet) {
|
|
160
|
+
removeUrlTreeOutlet(urlTree, removeOutlet);
|
|
161
|
+
}
|
|
162
|
+
return RouterBehavior.router.navigateByUrl(urlTree, extras);
|
|
163
|
+
}
|
|
164
|
+
function removeUrlTreeOutlet(urlTree, outlet) {
|
|
165
|
+
delete urlTree.root.children[outlet];
|
|
166
|
+
}
|
|
167
|
+
function paramsToObject(entries) {
|
|
168
|
+
const result = {};
|
|
169
|
+
for (const [key, value] of entries) {
|
|
170
|
+
result[key] = value;
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
function createUrl(url, moduleRoot) {
|
|
175
|
+
moduleRoot = moduleRoot ? `/${moduleRoot}/` : '/';
|
|
176
|
+
return url ? `${moduleRoot}${url}` : moduleRoot.replace(/\/$/, '');
|
|
177
|
+
}
|
|
178
|
+
function createNavigation(from, moduleRoot, overrides) {
|
|
179
|
+
const createdRoutes = {};
|
|
180
|
+
Object.keys(from).forEach((key) => {
|
|
181
|
+
createdRoutes[key] = (...args) => createUrl(from[key].apply(null, args), moduleRoot || '/').replace('//', '/');
|
|
182
|
+
});
|
|
183
|
+
Object.assign(createdRoutes, overrides);
|
|
184
|
+
return createdRoutes;
|
|
185
|
+
}
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
+
const extractParam = (key) => `:${key}`;
|
|
188
|
+
|
|
57
189
|
class AutoFocusDirective {
|
|
58
190
|
el;
|
|
59
191
|
$shouldFocus = input.required({ debugName: 'appAutoFocus' });
|
|
@@ -846,6 +978,8 @@ class UiAlertMessagesService {
|
|
|
846
978
|
$alerts = signal([], ...(ngDevMode ? [{ debugName: "$alerts" }] : []));
|
|
847
979
|
overlayRef;
|
|
848
980
|
component = null;
|
|
981
|
+
timerSubscriptions = new Map();
|
|
982
|
+
timerState = new Map();
|
|
849
983
|
constructor(overlay, router) {
|
|
850
984
|
this.overlay = overlay;
|
|
851
985
|
this.router = router;
|
|
@@ -882,7 +1016,26 @@ class UiAlertMessagesService {
|
|
|
882
1016
|
icon: 'warning.svg',
|
|
883
1017
|
}));
|
|
884
1018
|
}
|
|
1019
|
+
pauseTimer(alert) {
|
|
1020
|
+
const state = this.timerState.get(alert.id);
|
|
1021
|
+
if (state) {
|
|
1022
|
+
state.paused = true;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
resumeTimer(alert) {
|
|
1026
|
+
const state = this.timerState.get(alert.id);
|
|
1027
|
+
if (state) {
|
|
1028
|
+
state.paused = false;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
885
1031
|
remove(alert) {
|
|
1032
|
+
// Cancel any active timer for this alert
|
|
1033
|
+
const subscription = this.timerSubscriptions.get(alert.id);
|
|
1034
|
+
if (subscription) {
|
|
1035
|
+
subscription.unsubscribe();
|
|
1036
|
+
this.timerSubscriptions.delete(alert.id);
|
|
1037
|
+
}
|
|
1038
|
+
this.timerState.delete(alert.id);
|
|
886
1039
|
timer(250)
|
|
887
1040
|
.pipe(tap(() => {
|
|
888
1041
|
this.$alerts.set(this.$alerts().filter((x) => x !== alert));
|
|
@@ -927,11 +1080,25 @@ class UiAlertMessagesService {
|
|
|
927
1080
|
}), take(1))
|
|
928
1081
|
.subscribe();
|
|
929
1082
|
this.$alerts.set([...this.$alerts(), alert]);
|
|
930
|
-
timer
|
|
931
|
-
|
|
1083
|
+
// Create pausable timer with 100ms intervals
|
|
1084
|
+
this.timerState.set(alert.id, { paused: false, elapsed: 0 });
|
|
1085
|
+
const DURATION = 10000; // 10 seconds
|
|
1086
|
+
const CHECK_INTERVAL = 100; // Check every 100ms
|
|
1087
|
+
const subscription = interval(CHECK_INTERVAL)
|
|
1088
|
+
.pipe(takeWhile(() => {
|
|
1089
|
+
const state = this.timerState.get(alert.id);
|
|
1090
|
+
if (!state)
|
|
1091
|
+
return false;
|
|
1092
|
+
// Only increment elapsed time if not paused
|
|
1093
|
+
if (!state.paused) {
|
|
1094
|
+
state.elapsed += CHECK_INTERVAL;
|
|
1095
|
+
}
|
|
1096
|
+
return state.elapsed < DURATION;
|
|
1097
|
+
}), finalize(() => {
|
|
932
1098
|
this.remove(alert);
|
|
933
1099
|
}))
|
|
934
1100
|
.subscribe();
|
|
1101
|
+
this.timerSubscriptions.set(alert.id, subscription);
|
|
935
1102
|
}
|
|
936
1103
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UiAlertMessagesService, deps: [{ token: i1.Overlay }, { token: i2$1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
937
1104
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UiAlertMessagesService, providedIn: 'root' });
|
|
@@ -3839,5 +4006,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
3839
4006
|
* Generated bundle index. Do not edit.
|
|
3840
4007
|
*/
|
|
3841
4008
|
|
|
3842
|
-
export { Alert, AlertType, AppIconsLibrary, AutoFocusDirective, CenterEllipsisPipe, CountryService, DateUtils, EMAIL, HAS_CAPITAL_CASE, HAS_NUMBER, HAS_SMALL_CASE, HAS_SPECIAL_CHARTERS, HoverTipDirective, IconComponent, LazyImgDirective, MIN_LENGTH, MaskGradientDirective, SkeletonDirective, StickyObserverDirective, ThemeService, TrackLifecycleDirective, UIInputDateDirective, UIPhoneNumberDirective, UiAccordionComponent, UiAlertMessagesService, UiAvatarDirective, UiButtonDirective, UiCalendarDropdownDirective, UiCodeDirective, UiCopyButtonDirective, UiDailyCalendarDirective, UiDropdownContainerDirective, UiDropdownService, UiFieldBaseDirective, UiImageDirective, UiInputCheckboxDirective, UiInputCountryDirective, UiInputDirective, UiInputSelectDirective, UiInputSequenceDirective, UiInputTimeDirective, UiMonthlyCalendarDirective, UiPaginationDirective, UiPopupBackdropDirective, UiPopupContainerDirective, UiPopupImageDirective, UiPopupInstance, UiPopupService, UiSelectButtonsDirective, UiTabsDirective, UiTimeDropdownDirective, UiValidationErrorsDirective, UiYearlyCalendarDirective, emptyCountry, getAspectRatioFit, stringToHslColor };
|
|
4009
|
+
export { Alert, AlertType, AppIconsLibrary, AutoFocusDirective, CenterEllipsisPipe, CountryService, DateUtils, EMAIL, HAS_CAPITAL_CASE, HAS_NUMBER, HAS_SMALL_CASE, HAS_SPECIAL_CHARTERS, HoverTipDirective, IconComponent, LazyImgDirective, MIN_LENGTH, MaskGradientDirective, RouterBehavior, SkeletonDirective, StickyObserverDirective, ThemeService, TrackLifecycleDirective, UIInputDateDirective, UIPhoneNumberDirective, UiAccordionComponent, UiAlertMessagesService, UiAvatarDirective, UiButtonDirective, UiCalendarDropdownDirective, UiCodeDirective, UiCopyButtonDirective, UiDailyCalendarDirective, UiDropdownContainerDirective, UiDropdownService, UiFieldBaseDirective, UiImageDirective, UiInputCheckboxDirective, UiInputCountryDirective, UiInputDirective, UiInputSelectDirective, UiInputSequenceDirective, UiInputTimeDirective, UiMonthlyCalendarDirective, UiPaginationDirective, UiPopupBackdropDirective, UiPopupContainerDirective, UiPopupImageDirective, UiPopupInstance, UiPopupService, UiSelectButtonsDirective, UiTabsDirective, UiTimeDropdownDirective, UiValidationErrorsDirective, UiYearlyCalendarDirective, createNavigation, createUrl, createUrlTree, emptyCountry, extractParam, getAspectRatioFit, navigateByUrl, stringToHslColor };
|
|
3843
4010
|
//# sourceMappingURL=ibragim-dev-org-ui-forge-library.mjs.map
|