@ibragim-dev-org/ui-forge-library 1.2.6 → 1.2.8

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, interval, takeWhile, finalize, 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' });
@@ -978,14 +1110,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
978
1110
  }]
979
1111
  }], ctorParameters: () => [{ type: i1.Overlay }, { type: i2$1.Router }] });
980
1112
 
1113
+ const avatarSizes = ['small', 'medium', 'large'];
981
1114
  class UiAvatarDirective {
982
- $class = input.required(...(ngDevMode ? [{ debugName: "$class" }] : []));
1115
+ elementRef;
1116
+ renderer;
1117
+ $size = input('medium', ...(ngDevMode ? [{ debugName: "$size" }] : []));
1118
+ $isRounded = input(false, ...(ngDevMode ? [{ debugName: "$isRounded" }] : []));
983
1119
  $src = input.required(...(ngDevMode ? [{ debugName: "$src" }] : []));
984
1120
  $acronym = input.required(...(ngDevMode ? [{ debugName: "$acronym" }] : []));
985
- $backgroundColor = signal('', ...(ngDevMode ? [{ debugName: "$backgroundColor" }] : []));
986
1121
  $text = signal('', ...(ngDevMode ? [{ debugName: "$text" }] : []));
987
1122
  $canShowAvatar = signal(true, ...(ngDevMode ? [{ debugName: "$canShowAvatar" }] : []));
988
- constructor() {
1123
+ constructor(elementRef, renderer) {
1124
+ this.elementRef = elementRef;
1125
+ this.renderer = renderer;
989
1126
  effect(() => {
990
1127
  let acronym = '';
991
1128
  this.$acronym()
@@ -993,19 +1130,34 @@ class UiAvatarDirective {
993
1130
  .forEach((v) => {
994
1131
  acronym = acronym + v[0];
995
1132
  });
996
- this.$backgroundColor.set(stringToHslColor(acronym[0]));
1133
+ this.renderer.setStyle(this.elementRef.nativeElement, 'background-color', stringToHslColor(acronym[0]));
997
1134
  this.$text.set(acronym);
998
1135
  });
1136
+ effect(() => {
1137
+ if (this.$isRounded()) {
1138
+ this.renderer.addClass(this.elementRef.nativeElement, 'rounded');
1139
+ }
1140
+ else {
1141
+ this.renderer.removeClass(this.elementRef.nativeElement, 'rounded');
1142
+ }
1143
+ });
1144
+ effect(() => {
1145
+ avatarSizes.forEach((size) => {
1146
+ this.renderer.removeClass(this.elementRef.nativeElement, size);
1147
+ });
1148
+ const size = this.$size();
1149
+ this.renderer.addClass(this.elementRef.nativeElement, size);
1150
+ });
999
1151
  }
1000
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UiAvatarDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1001
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: UiAvatarDirective, isStandalone: true, selector: "app-ui-avatar", inputs: { $class: { classPropertyName: "$class", publicName: "$class", isSignal: true, isRequired: true, transformFunction: null }, $src: { classPropertyName: "$src", publicName: "$src", isSignal: true, isRequired: true, transformFunction: null }, $acronym: { classPropertyName: "$acronym", publicName: "$acronym", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
1152
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UiAvatarDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
1153
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: UiAvatarDirective, isStandalone: true, selector: "app-ui-avatar", inputs: { $size: { classPropertyName: "$size", publicName: "$size", isSignal: true, isRequired: false, transformFunction: null }, $isRounded: { classPropertyName: "$isRounded", publicName: "$isRounded", isSignal: true, isRequired: false, transformFunction: null }, $src: { classPropertyName: "$src", publicName: "$src", isSignal: true, isRequired: true, transformFunction: null }, $acronym: { classPropertyName: "$acronym", publicName: "$acronym", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
1002
1154
  }
1003
1155
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UiAvatarDirective, decorators: [{
1004
1156
  type: Directive,
1005
1157
  args: [{
1006
1158
  selector: 'app-ui-avatar',
1007
1159
  }]
1008
- }], ctorParameters: () => [], propDecorators: { $class: [{ type: i0.Input, args: [{ isSignal: true, alias: "$class", required: true }] }], $src: [{ type: i0.Input, args: [{ isSignal: true, alias: "$src", required: true }] }], $acronym: [{ type: i0.Input, args: [{ isSignal: true, alias: "$acronym", required: true }] }] } });
1160
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { $size: [{ type: i0.Input, args: [{ isSignal: true, alias: "$size", required: false }] }], $isRounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "$isRounded", required: false }] }], $src: [{ type: i0.Input, args: [{ isSignal: true, alias: "$src", required: true }] }], $acronym: [{ type: i0.Input, args: [{ isSignal: true, alias: "$acronym", required: true }] }] } });
1009
1161
 
1010
1162
  class UiDailyCalendarDirective {
1011
1163
  weekDaysEuropean = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
@@ -3874,5 +4026,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
3874
4026
  * Generated bundle index. Do not edit.
3875
4027
  */
3876
4028
 
3877
- 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 };
4029
+ 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 };
3878
4030
  //# sourceMappingURL=ibragim-dev-org-ui-forge-library.mjs.map