@six-group/ui-library-angular 0.0.0-insider.a8d68c7 → 0.0.0-insider.b50c229

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,9 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Component, ChangeDetectionStrategy, Injectable, inject, Directive, HostListener, Input, APP_INITIALIZER, NgModule } from '@angular/core';
2
+ import { Component, ChangeDetectionStrategy, Injectable, inject, Directive, HostListener, Input, EventEmitter, Output, APP_INITIALIZER, NgModule } from '@angular/core';
3
3
  import { __decorate } from 'tslib';
4
4
  import { fromEvent } from 'rxjs';
5
5
  import { defineCustomElements } from '@six-group/ui-library/loader';
6
- import { NgControl, NG_VALUE_ACCESSOR, FormGroupDirective, FormControl, FormGroup, FormArray, NG_VALIDATORS, Validators } from '@angular/forms';
6
+ import * as i1 from '@angular/forms';
7
+ import { NgControl, NG_VALUE_ACCESSOR, FormControl, FormGroup, FormArray, NG_VALIDATORS, Validators } from '@angular/forms';
7
8
  import { getErrorMessage } from '@six-group/ui-library';
8
9
 
9
10
  /* eslint-disable */
@@ -215,7 +216,7 @@ SixCheckbox.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "
215
216
  SixCheckbox = __decorate([
216
217
  ProxyCmp({
217
218
  inputs: ['checked', 'disabled', 'errorText', 'indeterminate', 'invalid', 'label', 'name', 'required', 'value'],
218
- methods: ['setFocus', 'removeFocus', 'reset']
219
+ methods: ['setFocus', 'removeFocus']
219
220
  })
220
221
  ], SixCheckbox);
221
222
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixCheckbox, decorators: [{
@@ -878,7 +879,7 @@ SixRadio.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.
878
879
  SixRadio = __decorate([
879
880
  ProxyCmp({
880
881
  inputs: ['checked', 'disabled', 'invalid', 'name', 'value'],
881
- methods: ['setFocus', 'removeFocus', 'reset']
882
+ methods: ['setFocus', 'removeFocus']
882
883
  })
883
884
  ], SixRadio);
884
885
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixRadio, decorators: [{
@@ -1715,49 +1716,134 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1715
1716
  args: ['change', ['$event.target']]
1716
1717
  }] } });
1717
1718
 
1719
+ /**
1720
+ * This directive intercepts the ngSubmit event of an Angular form and introduces
1721
+ * a supplementary event named sixSubmit. The sixSubmit event is triggered exclusively
1722
+ * when the form is valid. In cases where the form is considered invalid, this directive
1723
+ * takes proactive actions by marking all form controls as touched and dirty. Additionally,
1724
+ * it shifts the focus to the initial invalid form element, facilitating quick error
1725
+ * resolution.
1726
+ *
1727
+ * To utilize this directive, apply it to an Angular form.
1728
+ * ```html
1729
+ * <form [formGroup]="form" sixForm (sixSubmit)="onSubmit($event)">
1730
+ * <!-- form content -->
1731
+ * </form>
1732
+ * ```
1733
+ *
1734
+ * For users needing greater flexibility in determining when error messages are displayed,
1735
+ * or for those who prefer not to rely solely on the form submission event,
1736
+ * an alternative is to use the SixFormUtilDirective.
1737
+ */
1738
+ class SixFormDirective {
1739
+ onNgSubmit(event) {
1740
+ if (this.formGroupDirective.invalid) {
1741
+ focusInvalidField(this.formGroupDirective, this.elementRef);
1742
+ }
1743
+ else {
1744
+ this.sixSubmit.emit(event);
1745
+ }
1746
+ }
1747
+ constructor(elementRef, formGroupDirective) {
1748
+ this.elementRef = elementRef;
1749
+ this.formGroupDirective = formGroupDirective;
1750
+ /**
1751
+ * Emits an event when the form is valid and the form submission has been triggered.
1752
+ */
1753
+ this.sixSubmit = new EventEmitter();
1754
+ }
1755
+ }
1756
+ SixFormDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixFormDirective, deps: [{ token: i0.ElementRef }, { token: i1.FormGroupDirective }], target: i0.ɵɵFactoryTarget.Directive });
1757
+ SixFormDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: SixFormDirective, selector: "form[sixForm]", outputs: { sixSubmit: "sixSubmit" }, host: { listeners: { "ngSubmit": "onNgSubmit($event)" } }, ngImport: i0 });
1758
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixFormDirective, decorators: [{
1759
+ type: Directive,
1760
+ args: [{
1761
+ selector: 'form[sixForm]',
1762
+ }]
1763
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.FormGroupDirective }]; }, propDecorators: { sixSubmit: [{
1764
+ type: Output
1765
+ }], onNgSubmit: [{
1766
+ type: HostListener,
1767
+ args: ['ngSubmit', ['$event']]
1768
+ }] } });
1769
+ /**
1770
+ * This directive provides a utility method, that marks all form controls
1771
+ * as touched and dirty, and focuses the first invalid form element.
1772
+ *
1773
+ * To utilize this directive, apply it to an Angular form.
1774
+ * ```html
1775
+ * <form [formGroup]="form" sixFormUtil (ngSubmit)="onSubmit($event)">
1776
+ * <!-- form content -->
1777
+ * </form>
1778
+ * ```
1779
+ *
1780
+ * Then, get a reference to the directive and invoke `focusInvalidField()` if the
1781
+ * form is invalid:
1782
+ * ```ts
1783
+ * @ViewChild(SixFormUtilDirective) sixFormUtil!: SixFormUtilDirective;
1784
+ * // ...
1785
+ * onSubmit() {
1786
+ * if (this.form.invalid) {
1787
+ * this.sixFormUtil.focusInvalidField();
1788
+ * } else {
1789
+ * // ...
1790
+ * }
1791
+ * }
1792
+ * ```
1793
+ */
1718
1794
  class SixFormUtilDirective {
1719
- constructor(elementRef, injector) {
1795
+ constructor(elementRef, formGroupDirective) {
1720
1796
  this.elementRef = elementRef;
1721
- this.injector = injector;
1797
+ this.formGroupDirective = formGroupDirective;
1722
1798
  }
1799
+ /** markAllControlsAsDirty(Object.values(formGroup.controls));
1800
+ * Marks all form controls as touched and dirty, and focuses the first
1801
+ * invalid form element.
1802
+ */
1723
1803
  focusInvalidField() {
1724
- const formGroupDirective = this.injector.get(FormGroupDirective);
1725
- if (formGroupDirective) {
1726
- formGroupDirective.form.markAllAsTouched();
1727
- markAllAsDirty(formGroupDirective.form);
1728
- const invalidField = this.elementRef.nativeElement.querySelector('.ng-invalid');
1729
- if (typeof invalidField?.setFocus === 'function') {
1730
- invalidField.setFocus();
1731
- }
1732
- else if (typeof invalidField?.focus === 'function') {
1733
- invalidField?.focus();
1734
- }
1735
- }
1804
+ focusInvalidField(this.formGroupDirective, this.elementRef);
1736
1805
  }
1737
1806
  }
1738
- SixFormUtilDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixFormUtilDirective, deps: [{ token: i0.ElementRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Directive });
1807
+ SixFormUtilDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixFormUtilDirective, deps: [{ token: i0.ElementRef }, { token: i1.FormGroupDirective }], target: i0.ɵɵFactoryTarget.Directive });
1739
1808
  SixFormUtilDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: SixFormUtilDirective, selector: "[sixFormUtil]", ngImport: i0 });
1740
1809
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SixFormUtilDirective, decorators: [{
1741
1810
  type: Directive,
1742
1811
  args: [{
1743
1812
  selector: '[sixFormUtil]',
1744
1813
  }]
1745
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Injector }]; } });
1746
- function markAllAsDirty(formGroup) {
1747
- function markAllControlsAsDirty(controls) {
1748
- controls.forEach((control) => {
1749
- if (control instanceof FormControl) {
1750
- control.markAsDirty({ onlySelf: true });
1751
- }
1752
- else if (control instanceof FormGroup) {
1753
- markAllControlsAsDirty(Object.values(control.controls));
1754
- }
1755
- else if (control instanceof FormArray) {
1756
- markAllControlsAsDirty(control.controls);
1757
- }
1758
- });
1814
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.FormGroupDirective }]; } });
1815
+ function focusInvalidField(formGroupDirective, formElement) {
1816
+ formGroupDirective.form.markAllAsTouched();
1817
+ markAllAsDirty([formGroupDirective.form]);
1818
+ const invalidElement = getInvalidElement(formElement.nativeElement);
1819
+ if ('setFocus' in invalidElement && typeof invalidElement?.setFocus === 'function') {
1820
+ invalidElement.setFocus();
1821
+ }
1822
+ if ('focus' in invalidElement && typeof invalidElement?.focus === 'function') {
1823
+ invalidElement.focus();
1759
1824
  }
1760
- markAllControlsAsDirty(Object.values(formGroup.controls));
1825
+ }
1826
+ function getInvalidElement(parent) {
1827
+ const invalidElement = parent.querySelector('.ng-invalid');
1828
+ if (invalidElement == null) {
1829
+ return parent;
1830
+ }
1831
+ return getInvalidElement(invalidElement);
1832
+ }
1833
+ function markAllAsDirty(controls) {
1834
+ controls.forEach((control) => {
1835
+ if (control instanceof FormControl) {
1836
+ control.markAsDirty({ onlySelf: true });
1837
+ }
1838
+ else if (control instanceof FormGroup) {
1839
+ control.markAsDirty({ onlySelf: true });
1840
+ markAllAsDirty(Object.values(control.controls));
1841
+ }
1842
+ else if (control instanceof FormArray) {
1843
+ control.markAsDirty({ onlySelf: true });
1844
+ markAllAsDirty(control.controls);
1845
+ }
1846
+ });
1761
1847
  }
1762
1848
 
1763
1849
  class SixUiLibraryValidators {
@@ -2086,6 +2172,7 @@ UiLibraryAngularModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0",
2086
2172
  MaxDateValidator,
2087
2173
  AllowedDatesValidator,
2088
2174
  // form helpers
2175
+ SixFormDirective,
2089
2176
  SixFormUtilDirective], exports: [SetAttributes, SixAlert, SixAvatar, SixBadge, SixButton, SixCard, SixCheckbox, SixDatepicker, SixDetails, SixDialog, SixDrawer, SixDropdown, SixErrorPage, SixFileList, SixFileListItem, SixFileUpload, SixFooter, SixGroupLabel, SixHeader, SixIcon, SixIconButton, SixInput, SixItemPicker, SixLanguageSwitcher, SixLayoutGrid, SixMainContainer, SixMenu, SixMenuDivider, SixMenuItem, SixMenuLabel, SixPicto, SixProgressBar, SixProgressRing, SixRadio, SixRange, SixRoot, SixSearchField, SixSelect, SixSidebar, SixSidebarItem, SixSidebarItemGroup, SixSpinner, SixStageIndicator, SixSwitch, SixTab, SixTabGroup, SixTabPanel, SixTag, SixTextarea, SixTile, SixTimepicker, SixTooltip,
2090
2177
  // value accessors
2091
2178
  TextValueAccessor,
@@ -2104,6 +2191,7 @@ UiLibraryAngularModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0",
2104
2191
  MaxDateValidator,
2105
2192
  AllowedDatesValidator,
2106
2193
  // form helpers
2194
+ SixFormDirective,
2107
2195
  SixFormUtilDirective] });
2108
2196
  UiLibraryAngularModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UiLibraryAngularModule });
2109
2197
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UiLibraryAngularModule, decorators: [{
@@ -2129,6 +2217,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2129
2217
  MaxDateValidator,
2130
2218
  AllowedDatesValidator,
2131
2219
  // form helpers
2220
+ SixFormDirective,
2132
2221
  SixFormUtilDirective,
2133
2222
  ],
2134
2223
  imports: [],
@@ -2152,6 +2241,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2152
2241
  MaxDateValidator,
2153
2242
  AllowedDatesValidator,
2154
2243
  // form helpers
2244
+ SixFormDirective,
2155
2245
  SixFormUtilDirective,
2156
2246
  ],
2157
2247
  }]
@@ -2165,5 +2255,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
2165
2255
  * Generated bundle index. Do not edit.
2166
2256
  */
2167
2257
 
2168
- export { AllowedDatesValidator, CheckboxValueAccessor, DIRECTIVES, DatepickerValueAccessor, MaxDateValidator, MaxValidator, MinDateValidator, MinValidator, NumericValueAccessor, RadioValueAccessor, RangeValueAccessor, SelectValueAccessor, SetAttributes, SixAlert, SixAvatar, SixBadge, SixButton, SixCard, SixCheckbox, SixDatepicker, SixDetails, SixDialog, SixDrawer, SixDropdown, SixErrorPage, SixFileList, SixFileListItem, SixFileUpload, SixFooter, SixFormUtilDirective, SixGroupLabel, SixHeader, SixIcon, SixIconButton, SixInput, SixItemPicker, SixLanguageSwitcher, SixLayoutGrid, SixMainContainer, SixMenu, SixMenuDivider, SixMenuItem, SixMenuLabel, SixPicto, SixProgressBar, SixProgressRing, SixRadio, SixRange, SixRoot, SixSearchField, SixSelect, SixSidebar, SixSidebarItem, SixSidebarItemGroup, SixSpinner, SixStageIndicator, SixSwitch, SixTab, SixTabGroup, SixTabPanel, SixTag, SixTextarea, SixTile, SixTimepicker, SixTooltip, SixUiLibraryValidators, SwitchValueAccessor, TextValueAccessor, TimepickerValueAccessor, UiLibraryAngularModule, ValidationMessagesService, ValueAccessor };
2258
+ export { AllowedDatesValidator, CheckboxValueAccessor, DIRECTIVES, DatepickerValueAccessor, MaxDateValidator, MaxValidator, MinDateValidator, MinValidator, NumericValueAccessor, RadioValueAccessor, RangeValueAccessor, SelectValueAccessor, SetAttributes, SixAlert, SixAvatar, SixBadge, SixButton, SixCard, SixCheckbox, SixDatepicker, SixDetails, SixDialog, SixDrawer, SixDropdown, SixErrorPage, SixFileList, SixFileListItem, SixFileUpload, SixFooter, SixFormDirective, SixFormUtilDirective, SixGroupLabel, SixHeader, SixIcon, SixIconButton, SixInput, SixItemPicker, SixLanguageSwitcher, SixLayoutGrid, SixMainContainer, SixMenu, SixMenuDivider, SixMenuItem, SixMenuLabel, SixPicto, SixProgressBar, SixProgressRing, SixRadio, SixRange, SixRoot, SixSearchField, SixSelect, SixSidebar, SixSidebarItem, SixSidebarItemGroup, SixSpinner, SixStageIndicator, SixSwitch, SixTab, SixTabGroup, SixTabPanel, SixTag, SixTextarea, SixTile, SixTimepicker, SixTooltip, SixUiLibraryValidators, SwitchValueAccessor, TextValueAccessor, TimepickerValueAccessor, UiLibraryAngularModule, ValidationMessagesService, ValueAccessor };
2169
2259
  //# sourceMappingURL=six-group-ui-library-angular.mjs.map