@firestitch/form 12.3.0 → 12.3.1

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.
@@ -217,7 +217,6 @@ class FsFormDirective {
217
217
  this.cleared = new EventEmitter();
218
218
  this.fsformClass = true;
219
219
  this._tabGroups = new QueryList();
220
- this._submitButtons = new QueryList();
221
220
  this._buttons = new QueryList();
222
221
  this._dialogBackdropEscape = false;
223
222
  this._snapshot = {};
@@ -339,7 +338,7 @@ class FsFormDirective {
339
338
  }
340
339
  disable() {
341
340
  this.ngForm.control.disable();
342
- this._submitButtons.forEach((button) => {
341
+ this._buttons.forEach((button) => {
343
342
  button.disable();
344
343
  });
345
344
  }
@@ -355,18 +354,6 @@ class FsFormDirective {
355
354
  .filter((item) => (button !== item)),
356
355
  ]);
357
356
  }
358
- addSubmitButton(submitButton) {
359
- this._submitButtons.reset([
360
- ...this._submitButtons.toArray(),
361
- submitButton,
362
- ]);
363
- }
364
- removeSubmitButton(submitButton) {
365
- this._submitButtons.reset([
366
- ...this._submitButtons.toArray()
367
- .filter((submitButton_) => (submitButton !== submitButton_)),
368
- ]);
369
- }
370
357
  _listenSubmit() {
371
358
  this.ngForm
372
359
  .ngSubmit
@@ -451,11 +438,14 @@ class FsFormDirective {
451
438
  });
452
439
  }
453
440
  }
454
- _getActiveButton() {
455
- const activeButton = this._submitButtons.find(button => {
441
+ _getActiveSubmitButton() {
442
+ const submitButtons = this._buttons
443
+ .filter((button) => button.submit);
444
+ const activeButton = submitButtons
445
+ .find(button => {
456
446
  return button.active;
457
447
  });
458
- return activeButton ? activeButton : this._submitButtons.first;
448
+ return activeButton ? activeButton : submitButtons[0];
459
449
  }
460
450
  _elementInForm(el) {
461
451
  if (el.isSameNode(this._element.nativeElement)) {
@@ -501,15 +491,18 @@ class FsFormDirective {
501
491
  this._status$.next(FormStatus.Invalid);
502
492
  }
503
493
  this._resetButtons();
494
+ this._resetActiveButtons();
504
495
  this._updateDirtySubmitButtons();
505
496
  });
506
497
  }
507
498
  _resetButtons() {
508
- this._submitButtons.forEach((button) => {
499
+ this._buttons.forEach((button) => {
509
500
  button.reset();
510
501
  });
502
+ }
503
+ _resetActiveButtons() {
511
504
  this._buttons.forEach((button) => {
512
- button.reset();
505
+ button.resetActive();
513
506
  });
514
507
  }
515
508
  _registerConfirm() {
@@ -670,14 +663,15 @@ class FsFormDirective {
670
663
  .subscribe(() => {
671
664
  this._updateDirtySubmitButtons();
672
665
  });
673
- this._submitButtons.changes
666
+ this._buttons.changes
674
667
  .pipe(takeUntil(this._destroy$))
675
668
  .subscribe(() => {
676
669
  this._updateDirtySubmitButtons();
677
670
  });
678
671
  }
679
672
  _updateDirtySubmitButtons() {
680
- this._submitButtons
673
+ this._buttons
674
+ .filter((button) => button.submit)
681
675
  .forEach((submitButton) => {
682
676
  if (!this.confirm || !this.dirtySubmitButton || this.ngForm.dirty || !submitButton.dirtySubmit) {
683
677
  submitButton.enable();
@@ -700,7 +694,7 @@ class FsFormDirective {
700
694
  });
701
695
  }
702
696
  _setupActiveSubmitButton() {
703
- this._activeSubmitButton = this._getActiveButton();
697
+ this._activeSubmitButton = this._getActiveSubmitButton();
704
698
  this._resetButtons();
705
699
  if (this._activeSubmitButton) {
706
700
  this._activeSubmitButton.process();
@@ -1783,7 +1777,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
1783
1777
  args: ['fsFormUrlMessage']
1784
1778
  }] } });
1785
1779
 
1786
- class FsSubmitButtonDirective {
1780
+ class FsButtonDirective {
1787
1781
  constructor(_matButton, _form, _elementRef, _cdRef) {
1788
1782
  this._matButton = _matButton;
1789
1783
  this._form = _form;
@@ -1792,31 +1786,37 @@ class FsSubmitButtonDirective {
1792
1786
  this.dirtySubmit = true;
1793
1787
  this.transitionStyle = null;
1794
1788
  this.active = false;
1789
+ this.submit = false;
1790
+ this._previousDisabled = false;
1795
1791
  this._destroy$ = new Subject();
1796
1792
  }
1797
1793
  ngOnInit() {
1794
+ this.submit = this._elementRef.nativeElement.getAttribute('type') === 'submit';
1798
1795
  if (this._form) {
1799
- this._form.addSubmitButton(this);
1800
- fromEvent(this.element, 'click')
1801
- .pipe(takeUntil(this._destroy$))
1802
- .subscribe(() => {
1803
- this.active = true;
1804
- });
1805
- if (this.dirtySubmit) {
1806
- if (this._form.dirtySubmitButton) {
1807
- if (!this._form.ngForm.dirty) {
1808
- this.disable();
1796
+ this._form.addButton(this);
1797
+ if (this.submit) {
1798
+ fromEvent(this.element, 'click')
1799
+ .pipe(takeUntil(this._destroy$))
1800
+ .subscribe(() => {
1801
+ this.active = true;
1802
+ });
1803
+ if (this.dirtySubmit) {
1804
+ if (this._form.dirtySubmitButton) {
1805
+ if (!this._form.ngForm.dirty) {
1806
+ this.disable();
1807
+ }
1809
1808
  }
1810
1809
  }
1810
+ this.transitionStyle = 'none';
1811
+ setTimeout(() => {
1812
+ this.transitionStyle = null;
1813
+ }, 500);
1811
1814
  }
1812
- this.transitionStyle = 'none';
1813
- setTimeout(() => {
1814
- this.transitionStyle = null;
1815
- }, 500);
1816
1815
  }
1817
1816
  }
1818
1817
  disable() {
1819
- if (this._matButton) {
1818
+ if (this._matButton && !this.active) {
1819
+ this._previousDisabled = this._matButton.disabled;
1820
1820
  this._matButton.disabled = true;
1821
1821
  this._cdRef.markForCheck();
1822
1822
  }
@@ -1850,9 +1850,13 @@ class FsSubmitButtonDirective {
1850
1850
  get element() {
1851
1851
  return this._elementRef.nativeElement;
1852
1852
  }
1853
- reset() {
1853
+ resetActive() {
1854
1854
  this.active = false;
1855
- this.enable();
1855
+ }
1856
+ reset() {
1857
+ if (!this._previousDisabled) {
1858
+ this.enable();
1859
+ }
1856
1860
  this.element.querySelectorAll('.svg-icon')
1857
1861
  .forEach((el) => {
1858
1862
  el.remove();
@@ -1864,7 +1868,7 @@ class FsSubmitButtonDirective {
1864
1868
  var _a;
1865
1869
  this._destroy$.next();
1866
1870
  this._destroy$.complete();
1867
- (_a = this._form) === null || _a === void 0 ? void 0 : _a.removeSubmitButton(this);
1871
+ (_a = this._form) === null || _a === void 0 ? void 0 : _a.removeButton(this);
1868
1872
  }
1869
1873
  _disableShadowAnimation() {
1870
1874
  // .mat-elevation-z2 removes the click shadow animation
@@ -1899,12 +1903,12 @@ class FsSubmitButtonDirective {
1899
1903
  }
1900
1904
  }
1901
1905
  }
1902
- FsSubmitButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsSubmitButtonDirective, deps: [{ token: i1$1.MatButton, host: true, optional: true }, { token: FsFormDirective, optional: true }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
1903
- FsSubmitButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsSubmitButtonDirective, selector: "button[type=\"submit\"]", inputs: { name: "name", dirtySubmit: "dirtySubmit" }, host: { properties: { "style.transition": "this.transitionStyle" } }, ngImport: i0 });
1904
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsSubmitButtonDirective, decorators: [{
1906
+ FsButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsButtonDirective, deps: [{ token: i1$1.MatButton, host: true, optional: true }, { token: FsFormDirective, optional: true }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
1907
+ FsButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsButtonDirective, selector: "[mat-raised-button],[mat-button],[mat-flat-button],[mat-stroked-button]", inputs: { name: "name", dirtySubmit: "dirtySubmit" }, host: { properties: { "style.transition": "this.transitionStyle" } }, ngImport: i0 });
1908
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsButtonDirective, decorators: [{
1905
1909
  type: Directive,
1906
1910
  args: [{
1907
- selector: 'button[type="submit"]',
1911
+ selector: '[mat-raised-button],[mat-button],[mat-flat-button],[mat-stroked-button]',
1908
1912
  }]
1909
1913
  }], ctorParameters: function () { return [{ type: i1$1.MatButton, decorators: [{
1910
1914
  type: Optional
@@ -1949,59 +1953,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
1949
1953
  args: ['validateData']
1950
1954
  }] } });
1951
1955
 
1952
- class FsButtonDirective {
1953
- constructor(_matButton, _form, _cdRef) {
1954
- this._matButton = _matButton;
1955
- this._form = _form;
1956
- this._cdRef = _cdRef;
1957
- this.previous = false;
1958
- this._destroy$ = new Subject();
1959
- }
1960
- disable() {
1961
- this.previous = this._matButton.disabled;
1962
- if (this._matButton && !this.previous) {
1963
- this._matButton.disabled = true;
1964
- this._cdRef.markForCheck();
1965
- }
1966
- }
1967
- enable() {
1968
- if (this._matButton) {
1969
- this._matButton.disabled = false;
1970
- this._cdRef.markForCheck();
1971
- }
1972
- }
1973
- reset() {
1974
- if (this._matButton && !this.previous) {
1975
- this.enable();
1976
- }
1977
- }
1978
- ngOnInit() {
1979
- if (this._form) {
1980
- this._form.addButton(this);
1981
- }
1982
- }
1983
- ngOnDestroy() {
1984
- var _a;
1985
- this._destroy$.next();
1986
- this._destroy$.complete();
1987
- (_a = this._form) === null || _a === void 0 ? void 0 : _a.removeButton(this);
1988
- }
1989
- }
1990
- FsButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsButtonDirective, deps: [{ token: i1$1.MatButton, host: true, optional: true }, { token: FsFormDirective, optional: true }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
1991
- FsButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: FsButtonDirective, selector: "[mat-raised-button][type=\"button\"],[mat-flat-button][type=\"button\"],[mat-stroked-button][type=\"button\"],[mat-button][type=\"button\"]", ngImport: i0 });
1992
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsButtonDirective, decorators: [{
1993
- type: Directive,
1994
- args: [{
1995
- selector: '[mat-raised-button][type="button"],[mat-flat-button][type="button"],[mat-stroked-button][type="button"],[mat-button][type="button"]',
1996
- }]
1997
- }], ctorParameters: function () { return [{ type: i1$1.MatButton, decorators: [{
1998
- type: Optional
1999
- }, {
2000
- type: Host
2001
- }] }, { type: FsFormDirective, decorators: [{
2002
- type: Optional
2003
- }] }, { type: i0.ChangeDetectorRef }]; } });
2004
-
2005
1956
  class FsFormDialogActionsComponent {
2006
1957
  constructor(_form, _dialogRef, _cdRef) {
2007
1958
  this._form = _form;
@@ -2054,7 +2005,7 @@ class FsFormDialogActionsComponent {
2054
2005
  }
2055
2006
  }
2056
2007
  FsFormDialogActionsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFormDialogActionsComponent, deps: [{ token: FsFormDirective, optional: true }, { token: i2$1.MatDialogRef, optional: true }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
2057
- FsFormDialogActionsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsFormDialogActionsComponent, selector: "fs-form-dialog-actions", inputs: { save: "save", create: "create", close: "close", closeData: "closeData", name: "name" }, ngImport: i0, template: "<div class=\"buttons\" [ngClass]=\"{ 'save-create': save || create }\">\n <ng-container *ngIf=\"save\">\n <button\n mat-button\n type=\"submit\"\n color=\"primary\"\n [name]=\"name\">\n {{create ? 'Create' : 'Save'}}\n </button>\n <button\n mat-button\n type=\"button\"\n [disabled]=\"close && !dirty && !create\"\n [matDialogClose]=\"null\">\n Cancel\n </button>\n </ng-container>\n\n <ng-container *ngIf=\"save || create\">\n <ng-template [ngTemplateOutlet]=\"content\"></ng-template>\n </ng-container>\n\n <div class=\"close\" *ngIf=\"close\">\n <button\n mat-button\n type=\"button\"\n [color]=\"dirty ? 'basic' : 'primary'\"\n (click)=\"closeClick()\">\n Close\n </button>\n </div>\n\n <ng-container *ngIf=\"!(save || create)\">\n <ng-template [ngTemplateOutlet]=\"content\"></ng-template>\n </ng-container>\n</div>\n\n<ng-template #content>\n <ng-content></ng-content>\n</ng-template>\n", styles: [".buttons{display:flex;flex-grow:1;align-items:center}.buttons.save-create .close{display:flex;flex-grow:1;justify-content:flex-end}:host{display:flex;flex-grow:1}@media only screen and (max-width: 599px){.buttons{flex-direction:column}}\n"], components: [{ type: i1$1.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: FsSubmitButtonDirective, selector: "button[type=\"submit\"]", inputs: ["name", "dirtySubmit"] }, { type: FsButtonDirective, selector: "[mat-raised-button][type=\"button\"],[mat-flat-button][type=\"button\"],[mat-stroked-button][type=\"button\"],[mat-button][type=\"button\"]" }, { type: i2$1.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["type", "mat-dialog-close", "aria-label", "matDialogClose"], exportAs: ["matDialogClose"] }, { type: i4.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2008
+ FsFormDialogActionsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsFormDialogActionsComponent, selector: "fs-form-dialog-actions", inputs: { save: "save", create: "create", close: "close", closeData: "closeData", name: "name" }, ngImport: i0, template: "<div class=\"buttons\" [ngClass]=\"{ 'save-create': save || create }\">\n <ng-container *ngIf=\"save\">\n <button\n mat-button\n type=\"submit\"\n color=\"primary\"\n [name]=\"name\">\n {{create ? 'Create' : 'Save'}}\n </button>\n <button\n mat-button\n type=\"button\"\n [disabled]=\"close && !dirty && !create\"\n [matDialogClose]=\"null\">\n Cancel\n </button>\n </ng-container>\n\n <ng-container *ngIf=\"save || create\">\n <ng-template [ngTemplateOutlet]=\"content\"></ng-template>\n </ng-container>\n\n <div class=\"close\" *ngIf=\"close\">\n <button\n mat-button\n type=\"button\"\n [color]=\"dirty ? 'basic' : 'primary'\"\n (click)=\"closeClick()\">\n Close\n </button>\n </div>\n\n <ng-container *ngIf=\"!(save || create)\">\n <ng-template [ngTemplateOutlet]=\"content\"></ng-template>\n </ng-container>\n</div>\n\n<ng-template #content>\n <ng-content></ng-content>\n</ng-template>\n", styles: [".buttons{display:flex;flex-grow:1;align-items:center}.buttons.save-create .close{display:flex;flex-grow:1;justify-content:flex-end}:host{display:flex;flex-grow:1}@media only screen and (max-width: 599px){.buttons{flex-direction:column}}\n"], components: [{ type: i1$1.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: FsButtonDirective, selector: "[mat-raised-button],[mat-button],[mat-flat-button],[mat-stroked-button]", inputs: ["name", "dirtySubmit"] }, { type: i2$1.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["type", "mat-dialog-close", "aria-label", "matDialogClose"], exportAs: ["matDialogClose"] }, { type: i4.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2058
2009
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFormDialogActionsComponent, decorators: [{
2059
2010
  type: Component,
2060
2011
  args: [{
@@ -2156,7 +2107,6 @@ FsFormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "
2156
2107
  FsFormLesserDirective,
2157
2108
  FsFormUrlDirective,
2158
2109
  FsFormDialogCloseDirective,
2159
- FsSubmitButtonDirective,
2160
2110
  FsFormValidateDirective,
2161
2111
  FsFormDialogActionsComponent,
2162
2112
  FsFormNoFsValidatorsDirective,
@@ -2183,7 +2133,6 @@ FsFormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "
2183
2133
  FsFormLesserDirective,
2184
2134
  FsFormUrlDirective,
2185
2135
  FsFormDialogCloseDirective,
2186
- FsSubmitButtonDirective,
2187
2136
  FsFormValidateDirective,
2188
2137
  FsFormDialogActionsComponent,
2189
2138
  FsFormNoFsValidatorsDirective,
@@ -2229,7 +2178,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
2229
2178
  FsFormLesserDirective,
2230
2179
  FsFormUrlDirective,
2231
2180
  FsFormDialogCloseDirective,
2232
- FsSubmitButtonDirective,
2233
2181
  FsFormValidateDirective,
2234
2182
  FsFormDialogActionsComponent,
2235
2183
  FsFormNoFsValidatorsDirective,
@@ -2256,7 +2204,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
2256
2204
  FsFormLesserDirective,
2257
2205
  FsFormUrlDirective,
2258
2206
  FsFormDialogCloseDirective,
2259
- FsSubmitButtonDirective,
2260
2207
  FsFormValidateDirective,
2261
2208
  FsFormDialogActionsComponent,
2262
2209
  FsFormNoFsValidatorsDirective,
@@ -2308,5 +2255,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
2308
2255
  * Generated bundle index. Do not edit.
2309
2256
  */
2310
2257
 
2311
- export { ConfirmResult, FormDeactivateGuard, FormStatus, FsButtonDirective, FsControlDirective, FsForm, FsFormCompareDirective, FsFormDateRangeDirective, FsFormDialogActionsComponent, FsFormDialogCloseDirective, FsFormDirective, FsFormEmailDirective, FsFormEmailsDirective, FsFormFunctionDirective, FsFormGreaterDirective, FsFormIntegerDirective, FsFormLesserDirective, FsFormMaxDirective, FsFormMaxLengthDirective, FsFormMinDirective, FsFormMinLengthDirective, FsFormModule, FsFormNoFsValidatorsDirective, FsFormNumericDirective, FsFormPatternDirective, FsFormPhoneDirective, FsFormRequiredDirective, FsFormUrlDirective, FsFormValidateDirective, FsSubmitButtonDirective, FsValidators };
2258
+ export { ConfirmResult, FormDeactivateGuard, FormStatus, FsButtonDirective, FsControlDirective, FsForm, FsFormCompareDirective, FsFormDateRangeDirective, FsFormDialogActionsComponent, FsFormDialogCloseDirective, FsFormDirective, FsFormEmailDirective, FsFormEmailsDirective, FsFormFunctionDirective, FsFormGreaterDirective, FsFormIntegerDirective, FsFormLesserDirective, FsFormMaxDirective, FsFormMaxLengthDirective, FsFormMinDirective, FsFormMinLengthDirective, FsFormModule, FsFormNoFsValidatorsDirective, FsFormNumericDirective, FsFormPatternDirective, FsFormPhoneDirective, FsFormRequiredDirective, FsFormUrlDirective, FsFormValidateDirective, FsValidators };
2312
2259
  //# sourceMappingURL=firestitch-form.js.map