@firestitch/form 18.0.13 → 18.0.14

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.
@@ -11,8 +11,8 @@ import * as i1 from '@angular/material/dialog';
11
11
  import { MAT_DIALOG_DATA, MatDialogModule, MatDialog, MatDialogRef } from '@angular/material/dialog';
12
12
  import * as i2 from '@firestitch/dialog';
13
13
  import { FsDialogModule } from '@firestitch/dialog';
14
- import { Subject, of, filter, BehaviorSubject, throwError, fromEvent, iif, defer, from, isObservable } from 'rxjs';
15
- import { switchMap, map, catchError, takeUntil, tap, take, mergeMap, filter as filter$1, delay, first, startWith, mapTo } from 'rxjs/operators';
14
+ import { Subject, of, BehaviorSubject, throwError, fromEvent, iif, defer, from, isObservable } from 'rxjs';
15
+ import { switchMap, map, catchError, takeUntil, filter, delay, tap, take, mergeMap, first, startWith, mapTo } from 'rxjs/operators';
16
16
  import * as i2$1 from '@angular/router';
17
17
  import { guid, email, isEmpty, isNumeric, phone, url } from '@firestitch/common';
18
18
  import * as i7 from '@firestitch/drawer';
@@ -81,7 +81,9 @@ var ConfirmResult;
81
81
  })(ConfirmResult || (ConfirmResult = {}));
82
82
 
83
83
  function confirmResultContinue(result) {
84
- return result === ConfirmResult.Discard || result === ConfirmResult.Save || result === ConfirmResult.Pristine;
84
+ return (result === ConfirmResult.Discard ||
85
+ result === ConfirmResult.Save ||
86
+ result === ConfirmResult.Pristine);
85
87
  }
86
88
 
87
89
  function getActiveRoute(route) {
@@ -119,7 +121,7 @@ class FsForm {
119
121
  this._formDirectiveStore.delete(routeComponent);
120
122
  }
121
123
  confirmUnsaved(form) {
122
- if (!form.confirm || !form.ngForm.dirty) {
124
+ if (!form.confirm) {
123
125
  return of(ConfirmResult.Pristine);
124
126
  }
125
127
  let title = 'You Have Unsaved Changes';
@@ -134,7 +136,8 @@ class FsForm {
134
136
  discardLabel = form.confirm.discardLabel || discardLabel;
135
137
  cancelLabel = form.confirm.cancelLabel || cancelLabel;
136
138
  }
137
- return this._dialog.open(ConfirmUnsavedComponent, {
139
+ return this._dialog
140
+ .open(ConfirmUnsavedComponent, {
138
141
  data: {
139
142
  title,
140
143
  message,
@@ -156,7 +159,12 @@ class FsForm {
156
159
  if (result === 'save') {
157
160
  form.ngForm.control.markAsPristine();
158
161
  return form.submit$({ confirmed: true })
159
- .pipe(map(() => ConfirmResult.Save), catchError(() => {
162
+ .pipe(map((submitEvent) => {
163
+ if (submitEvent.error) {
164
+ return ConfirmResult.Invalid;
165
+ }
166
+ return ConfirmResult.Save;
167
+ }), catchError(() => {
160
168
  return of(ConfirmResult.Invalid);
161
169
  }));
162
170
  }
@@ -285,32 +293,31 @@ class FsFormBaseDirective {
285
293
  this._registerConfirmTabGroup(tabGroup);
286
294
  });
287
295
  }
296
+ _currentTabIndex;
297
+ _tabConfirming;
288
298
  _registerConfirmTabGroup(tabGroup) {
289
- const confirmTabGroup = tabGroup;
290
- if (!confirmTabGroup._originalHandleClick) {
291
- confirmTabGroup._originalHandleClick = tabGroup._handleClick;
292
- confirmTabGroup._handlClick$ = new Subject();
293
- confirmTabGroup._handleClick = (tab, tabHeader, idx) => {
294
- if (confirmTabGroup._handlClick$.observers.length) {
295
- confirmTabGroup._handlClick$.next({ tab, tabHeader, idx });
296
- }
297
- else {
298
- confirmTabGroup._originalHandleClick(tab, tabHeader, idx);
299
- }
300
- };
301
- }
302
- confirmTabGroup._handlClick$
303
- .pipe(filter(() => !this.submitting), switchMap((event) => {
299
+ this._currentTabIndex = tabGroup.selectedIndex;
300
+ tabGroup.selectedIndexChange
301
+ .pipe(filter(() => !this._tabConfirming), switchMap((selectedIndex) => {
304
302
  if (this.confirm && this.confirmTabs) {
303
+ tabGroup.selectedIndex = this._currentTabIndex;
304
+ this._tabConfirming = true;
305
305
  return this.triggerConfirm()
306
- .pipe(tap((result) => {
306
+ .pipe(map((result) => {
307
307
  if (confirmResultContinue(result)) {
308
- confirmTabGroup.selectedIndex = event.idx;
308
+ tabGroup.selectedIndex = selectedIndex;
309
+ return selectedIndex;
309
310
  }
311
+ return null;
312
+ }), delay(50), tap(() => {
313
+ this._tabConfirming = false;
310
314
  }));
311
315
  }
312
- confirmTabGroup._originalHandleClick(event.tab, event.tabHeader, event.idx);
313
- return of(null);
316
+ return of(selectedIndex);
317
+ }), tap((selectedIndex) => {
318
+ if (selectedIndex !== null) {
319
+ this._currentTabIndex = selectedIndex;
320
+ }
314
321
  }), takeUntil(this._destroy$))
315
322
  .subscribe();
316
323
  }
@@ -571,9 +578,12 @@ class FsFormDirective extends FsFormBaseDirective {
571
578
  return this._formValidState$;
572
579
  }), catchError((e) => {
573
580
  this._handleError(e);
574
- return of(null);
581
+ return of({
582
+ ...this._submitEvent,
583
+ error: e.message,
584
+ });
575
585
  }), tap((submittedEvent) => {
576
- if (submittedEvent) {
586
+ if (!submittedEvent.error) {
577
587
  this._completeSubmit(true, submittedEvent);
578
588
  }
579
589
  }));
@@ -584,7 +594,7 @@ class FsFormDirective extends FsFormBaseDirective {
584
594
  .ngSubmit
585
595
  .pipe(tap((event) => {
586
596
  event?.preventDefault();
587
- }), filter$1(() => {
597
+ }), filter(() => {
588
598
  return [FormStatus.Valid, FormStatus.Invalid]
589
599
  .includes(this._status$.getValue());
590
600
  }), switchMap(() => this.submit$(this._submitEvent)), takeUntil(this.destroy$))
@@ -650,7 +660,7 @@ class FsFormDirective extends FsFormBaseDirective {
650
660
  _formClose() {
651
661
  if (this.confirm && this.confirmDialog) {
652
662
  this.triggerConfirm()
653
- .pipe(filter$1((result) => confirmResultContinue(result)), switchMap((result) => {
663
+ .pipe(filter((result) => confirmResultContinue(result)), switchMap((result) => {
654
664
  return result === ConfirmResult.Pristine || result === ConfirmResult.Discard
655
665
  ? of(null)
656
666
  : this.submitted.asObservable();
@@ -754,7 +764,7 @@ class FsFormDirective extends FsFormBaseDirective {
754
764
  .subscribe((subscriber) => {
755
765
  if (this.submitting) {
756
766
  this._status$
757
- .pipe(filter$1((status) => status === FormStatus.Success || status === FormStatus.Error), takeUntil(this.destroy$))
767
+ .pipe(filter((status) => status === FormStatus.Success || status === FormStatus.Error), takeUntil(this.destroy$))
758
768
  .subscribe((status) => {
759
769
  if (status === FormStatus.Success) {
760
770
  subscriber.next(null);
@@ -991,7 +1001,7 @@ class FsFormDialogCloseDirective {
991
1001
  closeClick() {
992
1002
  if (this._form) {
993
1003
  this._form.triggerConfirm()
994
- .pipe(filter$1((confirmResult) => (confirmResult !== ConfirmResult.Review)), takeUntil(this._destroy$))
1004
+ .pipe(filter((confirmResult) => (confirmResult !== ConfirmResult.Review)), takeUntil(this._destroy$))
995
1005
  .subscribe(() => {
996
1006
  this._dialogRef.close(this.closeData);
997
1007
  });
@@ -1182,7 +1192,7 @@ class FsFormDialogActionsComponent {
1182
1192
  ngOnInit() {
1183
1193
  if (this._form) {
1184
1194
  this._form.ngForm.valueChanges
1185
- .pipe(filter$1(() => (!this.dirty)), takeUntil(this._destroy$))
1195
+ .pipe(filter(() => (!this.dirty)), takeUntil(this._destroy$))
1186
1196
  .subscribe(() => {
1187
1197
  this.dirty = this._form.ngForm.dirty;
1188
1198
  this._cdRef.markForCheck();