@theseam/ui-common 1.0.2-beta.39 → 1.0.2-beta.42

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,16 +1,19 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ElementRef, Directive, InjectionToken, ChangeDetectorRef, HostListener, HostBinding, Input, forwardRef, ViewContainerRef, isDevMode, TemplateRef, ContentChild, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule, ViewChild, EventEmitter, Output, Injectable, Injector, ViewChildren, Inject, Optional, ContentChildren } from '@angular/core';
3
- import { tap, map, startWith, switchMap, shareReplay, mapTo, take, auditTime, debounceTime, takeUntil, distinctUntilChanged, finalize, filter } from 'rxjs/operators';
2
+ import { isDevMode, inject, ElementRef, Directive, InjectionToken, ChangeDetectorRef, HostListener, HostBinding, Input, forwardRef, ViewContainerRef, TemplateRef, ContentChild, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule, ViewChild, EventEmitter, Output, Injectable, Injector, ViewChildren, Inject, Optional, ContentChildren } from '@angular/core';
3
+ import * as i3$2 from '@angular/forms';
4
+ import { AbstractControl, Validators, FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
5
+ import { isEmptyInputValue, hasProperty, notNullOrUndefined, observeControlValue, observeControlStatus, isNullOrUndefined } from '@theseam/ui-common/utils';
6
+ import { firstValueFrom, isObservable, BehaviorSubject, from, Subject, of, combineLatest, map as map$1, defer, Observable } from 'rxjs';
7
+ import { take, map, distinctUntilChanged, auditTime, tap, startWith, switchMap, shareReplay, mapTo, debounceTime, takeUntil, finalize, filter } from 'rxjs/operators';
8
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
9
  import * as i1 from '@angular/cdk/portal';
5
10
  import { TemplatePortal, PortalModule, BasePortalOutlet, ComponentPortal } from '@angular/cdk/portal';
6
11
  import * as i2$1 from '@angular/common';
7
12
  import { NgIf, NgFor, NgTemplateOutlet, AsyncPipe, CommonModule, NgStyle } from '@angular/common';
8
- import { BehaviorSubject, from, isObservable, Subject, of, combineLatest, map as map$1, defer, Observable } from 'rxjs';
9
13
  import { faAngleDoubleRight, faAngleDoubleLeft, faLock, faUnlock, faAngleLeft, faBars, faAngleDown } from '@fortawesome/free-solid-svg-icons';
10
14
  import * as i1$3 from '@theseam/ui-common/layout';
11
15
  import { TheSeamLayoutService, TheSeamLayoutModule } from '@theseam/ui-common/layout';
12
16
  import { TheSeamOverlayScrollbarDirective } from '@theseam/ui-common/scrollbar';
13
- import { hasProperty, notNullOrUndefined, observeControlValue, observeControlStatus, isNullOrUndefined } from '@theseam/ui-common/utils';
14
17
  import { __decorate } from 'tslib';
15
18
  import { coerceNumberProperty, coerceBooleanProperty } from '@angular/cdk/coercion';
16
19
  import * as i1$1 from '@angular/cdk/drag-drop';
@@ -37,8 +40,6 @@ import { MenuComponent, TheSeamMenuModule } from '@theseam/ui-common/menu';
37
40
  import { faUserCircle } from '@fortawesome/free-regular-svg-icons';
38
41
  import * as i1$5 from '@ajsf/core';
39
42
  import { JsonSchemaFormModule, isArray, buildTitleMap, hasOwn, JsonSchemaFormService, Framework, WidgetLibraryModule, FrameworkLibraryService, WidgetLibraryService } from '@ajsf/core';
40
- import * as i3$2 from '@angular/forms';
41
- import { ReactiveFormsModule } from '@angular/forms';
42
43
  import { TheSeamCheckboxComponent } from '@theseam/ui-common/checkbox';
43
44
  import * as i4$1 from '@theseam/ui-common/form-field';
44
45
  import { TheSeamFormFieldModule } from '@theseam/ui-common/form-field';
@@ -50,6 +51,274 @@ import { Platform } from '@angular/cdk/platform';
50
51
  import * as i4$2 from '@theseam/ui-common/tiled-select';
51
52
  import { TheSeamTiledSelectModule } from '@theseam/ui-common/tiled-select';
52
53
 
54
+ const DEFAULT_ADDRESS_FIELD_CONFIG = {
55
+ address1MaxLength: 50,
56
+ address2MaxLength: 50,
57
+ cityMaxLength: 50,
58
+ stateMaxLength: 200,
59
+ countryMaxLength: 10,
60
+ zipcodePattern: /^\d{5}(?:[-\s]\d{4})?$/,
61
+ };
62
+
63
+ const DEFAULT_USERNAME_FIELD_CONFIG = {
64
+ minLength: 8,
65
+ pattern: /^[a-zA-Z0-9\-._@+]+$/,
66
+ };
67
+
68
+ function isCountryUSA(control) {
69
+ return control.value === 'USA';
70
+ }
71
+
72
+ /**
73
+ * Use Validator if 'country' control value is 'USA'.
74
+ *
75
+ * If `countryControlOrPath` is not provided, it will be assumed there is a
76
+ * sibling named 'country'.
77
+ */
78
+ function ifUSA(fn, countryControlOrPath) {
79
+ return (control) => {
80
+ let countryControl = null;
81
+ if (countryControlOrPath) {
82
+ if (typeof countryControlOrPath === 'string' ||
83
+ Array.isArray(countryControlOrPath)) {
84
+ countryControl = control.parent?.get(countryControlOrPath) ?? null;
85
+ }
86
+ else {
87
+ countryControl = countryControlOrPath;
88
+ }
89
+ }
90
+ else {
91
+ countryControl = control.parent?.get('country') ?? null;
92
+ }
93
+ if (!countryControl) {
94
+ return null;
95
+ }
96
+ if (!(countryControl instanceof AbstractControl)) {
97
+ if (isDevMode()) {
98
+ // eslint-disable-next-line no-console
99
+ console.warn(`ifUSA expects 'country' control to be a FormControl.`);
100
+ }
101
+ return null;
102
+ }
103
+ if (!isEmptyInputValue(countryControl.value) &&
104
+ isCountryUSA(countryControl)) {
105
+ return fn(control);
106
+ }
107
+ return null;
108
+ };
109
+ }
110
+
111
+ function stateProvinceRegionValidator(stateCodes) {
112
+ return async (control) => {
113
+ const errorName = 'stateProvinceRegion';
114
+ const value = control.value;
115
+ if (isEmptyInputValue(value)) {
116
+ return null;
117
+ }
118
+ if (control.parent == null) {
119
+ return null;
120
+ }
121
+ const countryControl = control.parent.get('country');
122
+ if (countryControl === null) {
123
+ // eslint-disable-next-line no-console
124
+ console.warn(`stateProvinceRegionValidator requires sibling control named 'country'.`);
125
+ return null;
126
+ }
127
+ if (isCountryUSA(countryControl)) {
128
+ const isValidStateCode = await firstValueFrom(stateCodes.pipe(take(1), map((codes) => codes.indexOf(value) !== -1)));
129
+ return isValidStateCode
130
+ ? null
131
+ : {
132
+ [errorName]: {
133
+ reason: `If value of 'country' is 'USA' then a valid state must be selected.`,
134
+ },
135
+ };
136
+ }
137
+ return null;
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Validates that a username already exists.
143
+ *
144
+ * Mirrors the `emailExistsValidator` pattern from `@theseam/ui-common/validators`.
145
+ */
146
+ function usernameExistsValidator(userExists) {
147
+ return (control) => {
148
+ const validationResult = (exists) => {
149
+ return exists === false ? null : { usernameExists: {} };
150
+ };
151
+ const fnRes = userExists(control.value);
152
+ if (isObservable(fnRes)) {
153
+ return firstValueFrom(fnRes.pipe(map(validationResult)));
154
+ }
155
+ return Promise.resolve(fnRes).then(validationResult);
156
+ };
157
+ }
158
+
159
+ function getAddress1Validators(config, overrides) {
160
+ const c = { ...DEFAULT_ADDRESS_FIELD_CONFIG, ...config };
161
+ const o = { required: true, ...overrides };
162
+ const validators = [
163
+ ...(o.required ? [Validators.required] : []),
164
+ Validators.maxLength(c.address1MaxLength),
165
+ Validators.pattern(/[A-Za-z0-9]+/),
166
+ ];
167
+ return { validators, asyncValidators: [] };
168
+ }
169
+
170
+ function getAddress2Validators(config, overrides) {
171
+ const c = { ...DEFAULT_ADDRESS_FIELD_CONFIG, ...config };
172
+ const o = { required: false, ...overrides };
173
+ return {
174
+ validators: [
175
+ ...(o.required ? [Validators.required] : []),
176
+ Validators.maxLength(c.address2MaxLength),
177
+ ],
178
+ asyncValidators: [],
179
+ };
180
+ }
181
+
182
+ function getCityValidators(config, overrides) {
183
+ const c = { ...DEFAULT_ADDRESS_FIELD_CONFIG, ...config };
184
+ const o = { required: true, ...overrides };
185
+ const validators = [
186
+ ...(o.required ? [Validators.required] : []),
187
+ Validators.maxLength(c.cityMaxLength),
188
+ Validators.pattern(/[A-Za-z0-9]+/),
189
+ ];
190
+ return { validators, asyncValidators: [] };
191
+ }
192
+
193
+ const onlyAllowUsaValidator = (control) => {
194
+ if (isEmptyInputValue(control.value)) {
195
+ return null;
196
+ }
197
+ return control.value !== 'USA' ? { onlyAllowUsa: {} } : null;
198
+ };
199
+ function getCountryValidators(config, options, overrides) {
200
+ const c = { ...DEFAULT_ADDRESS_FIELD_CONFIG, ...config };
201
+ const o = { required: true, ...overrides };
202
+ const validators = [
203
+ ...(o.required ? [Validators.required] : []),
204
+ Validators.maxLength(c.countryMaxLength),
205
+ ];
206
+ if (options?.onlyAllowUsa) {
207
+ validators.push(onlyAllowUsaValidator);
208
+ }
209
+ return { validators, asyncValidators: [] };
210
+ }
211
+
212
+ function getStateValidators(stateCodes, countryControlOrPath, requiredOutsideUSA = true, config) {
213
+ const c = { ...DEFAULT_ADDRESS_FIELD_CONFIG, ...config };
214
+ const validators = [];
215
+ if (requiredOutsideUSA) {
216
+ validators.push(Validators.required);
217
+ }
218
+ else {
219
+ validators.push(ifUSA(Validators.required, countryControlOrPath));
220
+ }
221
+ validators.push(Validators.maxLength(c.stateMaxLength));
222
+ const asyncValidators = [
223
+ stateProvinceRegionValidator(stateCodes),
224
+ ];
225
+ return { validators, asyncValidators };
226
+ }
227
+
228
+ function getZipValidators(countryControlOrPath, config) {
229
+ const c = { ...DEFAULT_ADDRESS_FIELD_CONFIG, ...config };
230
+ return {
231
+ validators: [
232
+ ifUSA(Validators.required, countryControlOrPath),
233
+ ifUSA(Validators.pattern(c.zipcodePattern), countryControlOrPath),
234
+ Validators.maxLength(10),
235
+ ],
236
+ asyncValidators: [],
237
+ };
238
+ }
239
+
240
+ function getUsernameValidators(userExists, config, overrides) {
241
+ const c = { ...DEFAULT_USERNAME_FIELD_CONFIG, ...config };
242
+ const o = { required: true, ...overrides };
243
+ return {
244
+ validators: [
245
+ ...(o.required ? [Validators.required] : []),
246
+ Validators.minLength(c.minLength),
247
+ Validators.pattern(c.pattern),
248
+ ],
249
+ asyncValidators: [usernameExistsValidator(userExists)],
250
+ };
251
+ }
252
+
253
+ function createAddress1Control(formState = null, config, overrides) {
254
+ const v = getAddress1Validators(config, overrides);
255
+ return new FormControl(formState, v.validators, v.asyncValidators);
256
+ }
257
+
258
+ function createAddress2Control(formState = null, config, overrides) {
259
+ const v = getAddress2Validators(config, overrides);
260
+ return new FormControl(formState, v.validators, v.asyncValidators);
261
+ }
262
+
263
+ function createCityControl(formState = null, config, overrides) {
264
+ const v = getCityValidators(config, overrides);
265
+ return new FormControl(formState, v.validators, v.asyncValidators);
266
+ }
267
+
268
+ function createCountryControl(formState = null, options, overrides) {
269
+ const v = getCountryValidators(undefined, options, overrides);
270
+ return new FormControl(formState, v.validators, v.asyncValidators);
271
+ }
272
+
273
+ function createStateControl(formState = null, stateCodes, requiredOutsideUSA = true) {
274
+ const v = getStateValidators(stateCodes, undefined, requiredOutsideUSA);
275
+ return new FormControl(formState, v.validators, v.asyncValidators);
276
+ }
277
+
278
+ function createZipControl(formState = null) {
279
+ const v = getZipValidators();
280
+ return new FormControl(formState, v.validators, v.asyncValidators);
281
+ }
282
+
283
+ function createUsernameControl(formState = null, userExists, config, overrides) {
284
+ const v = getUsernameValidators(userExists, config, overrides);
285
+ return new FormControl(formState, v.validators, v.asyncValidators);
286
+ }
287
+
288
+ function createAddressFormGroup(options) {
289
+ const config = options.config;
290
+ const countryRequiredOutsideUSA = options.countryRequiredOutsideUSA ?? true;
291
+ const defaultCountry = options.defaultCountry ?? 'USA';
292
+ const group = new FormGroup({
293
+ address1: createAddress1Control(null, config),
294
+ address2: createAddress2Control(null, config),
295
+ city: createCityControl(null, config),
296
+ state: createStateControl(null, options.stateCodes, countryRequiredOutsideUSA),
297
+ zip: createZipControl(),
298
+ country: createCountryControl(defaultCountry),
299
+ });
300
+ const countryCtrl = group.controls.country;
301
+ let countryChange$ = countryCtrl.valueChanges.pipe(map(() => isCountryUSA(countryCtrl)), distinctUntilChanged(), auditTime(0), tap(() => {
302
+ const sv = getStateValidators(options.stateCodes, countryCtrl, countryRequiredOutsideUSA, config);
303
+ group.controls.state.setValidators(sv.validators);
304
+ group.controls.state.setAsyncValidators(sv.asyncValidators);
305
+ group.controls.state.updateValueAndValidity();
306
+ const zv = getZipValidators(countryCtrl, config);
307
+ group.controls.zip.setValidators(zv.validators);
308
+ group.controls.zip.setAsyncValidators(zv.asyncValidators);
309
+ group.controls.zip.updateValueAndValidity();
310
+ }));
311
+ if (options.destroyRef) {
312
+ countryChange$ = countryChange$.pipe(takeUntilDestroyed(options.destroyRef));
313
+ countryChange$.subscribe();
314
+ return group;
315
+ }
316
+ const subscription = countryChange$.subscribe();
317
+ return { group, subscription };
318
+ }
319
+
320
+ // Models
321
+
53
322
  class BaseLayoutContentFooterDirective {
54
323
  _elementRef = inject(ElementRef);
55
324
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: BaseLayoutContentFooterDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
@@ -4290,5 +4559,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
4290
4559
  * Generated bundle index. Do not edit.
4291
4560
  */
4292
4561
 
4293
- export { BaseLayoutContentDirective, BaseLayoutContentFooterDirective, BaseLayoutContentHeaderDirective, BaseLayoutSideBarDirective, BaseLayoutSideBarFooterDirective, BaseLayoutSideBarHeaderDirective, BaseLayoutTopBarDirective, DEFAULT_SIDE_NAV_CONFIG, DashboardComponent, DashboardWidgetContainerComponent, DashboardWidgetPortalOutletDirective, DashboardWidgetTemplateContainerComponent, DashboardWidgetsComponent, DashboardWidgetsPreferencesService, DashboardWidgetsService, HierarchyLevelResolver, HierarchyRouterOutletComponent, HorizontalNavComponent, NavItemComponent, SeamRouteShellComponent, SideNavComponent, SideNavItemComponent, SideNavToggleComponent, THESEAM_BASE_LAYOUT_REF, THESEAM_DASHBOARD_WIDGETS_PREFERENCES_ACCESSOR, THESEAM_SCHEMA_FRAMEWORK_OVERRIDES, THESEAM_SIDE_NAV_ACCESSOR, THESEAM_SIDE_NAV_CONFIG, THE_SEAM_BASE_LAYOUT, TheSeamBaseLayoutComponent, TheSeamBaseLayoutModule, TheSeamBaseLayoutNavToggleDirective, TheSeamDashboardModule, TheSeamDynamicRouterModule, TheSeamFramework, TheSeamNavModule, TheSeamSchemaFormFrameworkComponent, TheSeamSchemaFormModule, TheSeamSideNavModule, TheSeamTopBarComponent, TheSeamTopBarModule, TopBarCompactMenuBtnDetailDirective, TopBarItemDirective, TopBarMenuBtnDetailDirective, TopBarMenuButtonComponent, TopBarMenuDirective, TopBarNavToggleBtnDetailDirective, TopBarTitleComponent, applyItemConfig, areSameHorizontalNavItem, canBeActive, canExpand, canHaveChildren, computeDirection, extendFramework, fader, findHorizontalNavLinkItems, findLinkItems, getHorizontalNavItemStateProp, getItemStateProp, getUrlSegments, hasActiveChild, hasChildren, hasExpandedChild, horizontalNavItemCanBeActive, horizontalNavItemCanExpand, horizontalNavItemCanHaveChildren, horizontalNavItemHasActiveChild, horizontalNavItemHasChildren, horizontalNavItemHasExpandedChild, isExpanded, isHorizontalNavItemActive, isHorizontalNavItemExpanded, isHorizontalNavItemFocused, isHorizontalNavItemType, isNavItemActive, isNavItemType, routeChanges, seamRouteTransition, setDefaultHorizontalNavItemState, setDefaultState, setHorizontalNavItemStateProp, setItemStateProp, sideNavExpandStateChangeFn, sideToSide, slider, stepper, transformer };
4562
+ export { BaseLayoutContentDirective, BaseLayoutContentFooterDirective, BaseLayoutContentHeaderDirective, BaseLayoutSideBarDirective, BaseLayoutSideBarFooterDirective, BaseLayoutSideBarHeaderDirective, BaseLayoutTopBarDirective, DEFAULT_ADDRESS_FIELD_CONFIG, DEFAULT_SIDE_NAV_CONFIG, DEFAULT_USERNAME_FIELD_CONFIG, DashboardComponent, DashboardWidgetContainerComponent, DashboardWidgetPortalOutletDirective, DashboardWidgetTemplateContainerComponent, DashboardWidgetsComponent, DashboardWidgetsPreferencesService, DashboardWidgetsService, HierarchyLevelResolver, HierarchyRouterOutletComponent, HorizontalNavComponent, NavItemComponent, SeamRouteShellComponent, SideNavComponent, SideNavItemComponent, SideNavToggleComponent, THESEAM_BASE_LAYOUT_REF, THESEAM_DASHBOARD_WIDGETS_PREFERENCES_ACCESSOR, THESEAM_SCHEMA_FRAMEWORK_OVERRIDES, THESEAM_SIDE_NAV_ACCESSOR, THESEAM_SIDE_NAV_CONFIG, THE_SEAM_BASE_LAYOUT, TheSeamBaseLayoutComponent, TheSeamBaseLayoutModule, TheSeamBaseLayoutNavToggleDirective, TheSeamDashboardModule, TheSeamDynamicRouterModule, TheSeamFramework, TheSeamNavModule, TheSeamSchemaFormFrameworkComponent, TheSeamSchemaFormModule, TheSeamSideNavModule, TheSeamTopBarComponent, TheSeamTopBarModule, TopBarCompactMenuBtnDetailDirective, TopBarItemDirective, TopBarMenuBtnDetailDirective, TopBarMenuButtonComponent, TopBarMenuDirective, TopBarNavToggleBtnDetailDirective, TopBarTitleComponent, applyItemConfig, areSameHorizontalNavItem, canBeActive, canExpand, canHaveChildren, computeDirection, createAddress1Control, createAddress2Control, createAddressFormGroup, createCityControl, createCountryControl, createStateControl, createUsernameControl, createZipControl, extendFramework, fader, findHorizontalNavLinkItems, findLinkItems, getAddress1Validators, getAddress2Validators, getCityValidators, getCountryValidators, getHorizontalNavItemStateProp, getItemStateProp, getStateValidators, getUrlSegments, getUsernameValidators, getZipValidators, hasActiveChild, hasChildren, hasExpandedChild, horizontalNavItemCanBeActive, horizontalNavItemCanExpand, horizontalNavItemCanHaveChildren, horizontalNavItemHasActiveChild, horizontalNavItemHasChildren, horizontalNavItemHasExpandedChild, ifUSA, isCountryUSA, isExpanded, isHorizontalNavItemActive, isHorizontalNavItemExpanded, isHorizontalNavItemFocused, isHorizontalNavItemType, isNavItemActive, isNavItemType, routeChanges, seamRouteTransition, setDefaultHorizontalNavItemState, setDefaultState, setHorizontalNavItemStateProp, setItemStateProp, sideNavExpandStateChangeFn, sideToSide, slider, stateProvinceRegionValidator, stepper, transformer, usernameExistsValidator };
4294
4563
  //# sourceMappingURL=theseam-ui-common-framework.mjs.map