@covalent/core 11.0.0-beta.2 → 11.0.0-beta.4

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,11 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { EventEmitter, Directive, Optional, Inject, ViewChild, ChangeDetectionStrategy, ViewEncapsulation, Component, HostListener, HostBinding, Injector, TemplateRef, Injectable, SkipSelf, Input, NgModule } from '@angular/core';
3
- import * as i1$1 from '@angular/cdk/overlay';
2
+ import { inject, ElementRef, ChangeDetectorRef, EventEmitter, Directive, ViewChild, ChangeDetectionStrategy, ViewEncapsulation, Component, HostListener, HostBinding, Injector, TemplateRef, Injectable, Optional, Inject, SkipSelf, Input, NgModule } from '@angular/core';
3
+ import * as i1 from '@angular/cdk/overlay';
4
4
  import { OverlayConfig } from '@angular/cdk/overlay';
5
5
  import { BasePortalOutlet, CdkPortalOutlet, ComponentPortal, TemplatePortal } from '@angular/cdk/portal';
6
6
  import { MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA, MAT_DIALOG_DEFAULT_OPTIONS } from '@angular/material/dialog';
7
7
  import { AnimationDurations, AnimationCurves } from '@angular/material/core';
8
- import * as i1 from '@angular/cdk/a11y';
8
+ import { ConfigurableFocusTrapFactory, FocusMonitor } from '@angular/cdk/a11y';
9
9
  import { DOCUMENT } from '@angular/common';
10
10
  import { trigger, state, transition, style, animate } from '@angular/animations';
11
11
  import { Subject, of } from 'rxjs';
@@ -55,12 +55,12 @@ function _getFocusedElementPierceShadowDom() {
55
55
  * animations as these are left to implementers of the side-sheet container.
56
56
  */
57
57
  class _CovalentSideSheetContainerBase extends BasePortalOutlet {
58
- _elementRef;
59
- _focusTrapFactory;
60
- _changeDetectorRef;
61
- _config;
62
- _focusMonitor;
63
- _document;
58
+ _elementRef = inject(ElementRef);
59
+ _focusTrapFactory = inject(ConfigurableFocusTrapFactory);
60
+ _changeDetectorRef = inject(ChangeDetectorRef);
61
+ _config = inject(CovalentSideSheetConfig);
62
+ _focusMonitor = inject(FocusMonitor);
63
+ _document = null;
64
64
  /** The portal outlet inside of this container into which the side-sheet content will be loaded. */
65
65
  _portalOutlet;
66
66
  /** The class that traps and manages focus within the side-sheet. */
@@ -79,15 +79,10 @@ class _CovalentSideSheetContainerBase extends BasePortalOutlet {
79
79
  _ariaLabelledBy;
80
80
  /** ID for the container DOM element. */
81
81
  _id;
82
- constructor(_elementRef, _focusTrapFactory, _changeDetectorRef, _document,
83
- /** The side-sheet configuration. */
84
- _config, _focusMonitor) {
82
+ constructor() {
83
+ const _document = inject(DOCUMENT, { optional: true });
85
84
  super();
86
- this._elementRef = _elementRef;
87
- this._focusTrapFactory = _focusTrapFactory;
88
- this._changeDetectorRef = _changeDetectorRef;
89
- this._config = _config;
90
- this._focusMonitor = _focusMonitor;
85
+ const _config = this._config;
91
86
  this._ariaLabelledBy = _config.ariaLabelledBy || null;
92
87
  this._document = _document;
93
88
  }
@@ -163,7 +158,7 @@ class _CovalentSideSheetContainerBase extends BasePortalOutlet {
163
158
  // the consumer moved it themselves before the animation was done, in which case we shouldn't
164
159
  // do anything.
165
160
  if (!activeElement ||
166
- activeElement === this._document.body ||
161
+ activeElement === this._document?.body ||
167
162
  activeElement === element ||
168
163
  element.contains(activeElement)) {
169
164
  if (this._focusMonitor) {
@@ -203,7 +198,7 @@ class _CovalentSideSheetContainerBase extends BasePortalOutlet {
203
198
  const activeElement = _getFocusedElementPierceShadowDom();
204
199
  return element === activeElement || element.contains(activeElement);
205
200
  }
206
- static ɵfac = function _CovalentSideSheetContainerBase_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || _CovalentSideSheetContainerBase)(i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i1.ConfigurableFocusTrapFactory), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(DOCUMENT, 8), i0.ɵɵdirectiveInject(CovalentSideSheetConfig), i0.ɵɵdirectiveInject(i1.FocusMonitor)); };
201
+ static ɵfac = function _CovalentSideSheetContainerBase_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || _CovalentSideSheetContainerBase)(); };
207
202
  static ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: _CovalentSideSheetContainerBase, viewQuery: function _CovalentSideSheetContainerBase_Query(rf, ctx) { if (rf & 1) {
208
203
  i0.ɵɵviewQuery(CdkPortalOutlet, 7);
209
204
  } if (rf & 2) {
@@ -213,12 +208,7 @@ class _CovalentSideSheetContainerBase extends BasePortalOutlet {
213
208
  }
214
209
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(_CovalentSideSheetContainerBase, [{
215
210
  type: Directive
216
- }], () => [{ type: i0.ElementRef }, { type: i1.ConfigurableFocusTrapFactory }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
217
- type: Optional
218
- }, {
219
- type: Inject,
220
- args: [DOCUMENT]
221
- }] }, { type: CovalentSideSheetConfig }, { type: i1.FocusMonitor }], { _portalOutlet: [{
211
+ }], () => [], { _portalOutlet: [{
222
212
  type: ViewChild,
223
213
  args: [CdkPortalOutlet, { static: true }]
224
214
  }] }); })();
@@ -322,7 +312,7 @@ class CovalentSideSheetContainerComponent extends _CovalentSideSheetContainerBas
322
312
  type: HostListener,
323
313
  args: ['@sideSheetContainer.done', ['$event']]
324
314
  }] }); })();
325
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CovalentSideSheetContainerComponent, { className: "CovalentSideSheetContainerComponent", filePath: "side-sheet-container.ts", lineNumber: 255 }); })();
315
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CovalentSideSheetContainerComponent, { className: "CovalentSideSheetContainerComponent", filePath: "side-sheet-container.ts", lineNumber: 256 }); })();
326
316
 
327
317
  // Counter for unique dialog ids.
328
318
  let uniqueId = 0;
@@ -352,6 +342,7 @@ function _closeSideSheetVia(ref, interactionType, result) {
352
342
  return ref.close(result);
353
343
  }
354
344
 
345
+ /* eslint-disable @angular-eslint/prefer-inject */
355
346
  /* tslint:disable */
356
347
  class _CovalentSideSheetBase {
357
348
  _overlay;
@@ -552,7 +543,7 @@ class _CovalentSideSheetBase {
552
543
  }
553
544
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(_CovalentSideSheetBase, [{
554
545
  type: Directive
555
- }], () => [{ type: i1$1.Overlay }, { type: i0.Injector }, { type: undefined }, { type: undefined }, { type: i0.Type }, { type: i0.Type }, { type: i0.InjectionToken }], null); })();
546
+ }], () => [{ type: i1.Overlay }, { type: i0.Injector }, { type: undefined }, { type: undefined }, { type: i0.Type }, { type: i0.Type }, { type: i0.InjectionToken }], null); })();
556
547
  /**
557
548
  * Service to open Covalent Design side-sheet.
558
549
  */
@@ -560,12 +551,12 @@ class CovalentSideSheet extends _CovalentSideSheetBase {
560
551
  constructor(overlay, injector, defaultOptions, parentSideSheet) {
561
552
  super(overlay, injector, defaultOptions, parentSideSheet, CovalentSideSheetRef, CovalentSideSheetContainerComponent, MAT_DIALOG_DATA);
562
553
  }
563
- static ɵfac = function CovalentSideSheet_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentSideSheet)(i0.ɵɵinject(i1$1.Overlay), i0.ɵɵinject(i0.Injector), i0.ɵɵinject(MAT_DIALOG_DEFAULT_OPTIONS, 8), i0.ɵɵinject(CovalentSideSheet, 12)); };
554
+ static ɵfac = function CovalentSideSheet_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentSideSheet)(i0.ɵɵinject(i1.Overlay), i0.ɵɵinject(i0.Injector), i0.ɵɵinject(MAT_DIALOG_DEFAULT_OPTIONS, 8), i0.ɵɵinject(CovalentSideSheet, 12)); };
564
555
  static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: CovalentSideSheet, factory: CovalentSideSheet.ɵfac });
565
556
  }
566
557
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CovalentSideSheet, [{
567
558
  type: Injectable
568
- }], () => [{ type: i1$1.Overlay }, { type: i0.Injector }, { type: CovalentSideSheetConfig, decorators: [{
559
+ }], () => [{ type: i1.Overlay }, { type: i0.Injector }, { type: CovalentSideSheetConfig, decorators: [{
569
560
  type: Optional
570
561
  }, {
571
562
  type: Inject,
@@ -583,9 +574,11 @@ let dialogElementUid = 0;
583
574
  * Button that will close the current dialog.
584
575
  */
585
576
  class CovalentSideSheetCloseDirective {
586
- dialogRef;
587
- _elementRef;
588
- _dialog;
577
+ dialogRef = inject(CovalentSideSheetRef, {
578
+ optional: true,
579
+ });
580
+ _elementRef = inject(ElementRef);
581
+ _dialog = inject(CovalentSideSheet);
589
582
  /** Screenreader label for the button. */
590
583
  ariaLabel;
591
584
  /** Default to "button" to prevents accidental form submits. */
@@ -596,11 +589,6 @@ class CovalentSideSheetCloseDirective {
596
589
  onClick($event) {
597
590
  this._onButtonClick($event);
598
591
  }
599
- constructor(dialogRef, _elementRef, _dialog) {
600
- this.dialogRef = dialogRef;
601
- this._elementRef = _elementRef;
602
- this._dialog = _dialog;
603
- }
604
592
  ngOnInit() {
605
593
  if (!this.dialogRef) {
606
594
  // When this directive is included in a dialog via TemplateRef (rather than being
@@ -623,9 +611,12 @@ class CovalentSideSheetCloseDirective {
623
611
  // result in incorrect origins. Most of the time, close buttons will be auto focused in the
624
612
  // dialog, and therefore clicking the button won't result in a focus change. This means that
625
613
  // the FocusMonitor won't detect any origin change, and will always output `program`.
614
+ if (!this.dialogRef) {
615
+ return;
616
+ }
626
617
  _closeSideSheetVia(this.dialogRef, event.screenX === 0 && event.screenY === 0 ? 'keyboard' : 'mouse', this.dialogResult);
627
618
  }
628
- static ɵfac = function CovalentSideSheetCloseDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentSideSheetCloseDirective)(i0.ɵɵdirectiveInject(CovalentSideSheetRef, 8), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(CovalentSideSheet)); };
619
+ static ɵfac = function CovalentSideSheetCloseDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentSideSheetCloseDirective)(); };
629
620
  static ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: CovalentSideSheetCloseDirective, selectors: [["", "td-side-sheet-close", ""], ["", "CovalentSideSheetClose", ""]], hostVars: 2, hostBindings: function CovalentSideSheetCloseDirective_HostBindings(rf, ctx) { if (rf & 1) {
630
621
  i0.ɵɵlistener("click", function CovalentSideSheetCloseDirective_click_HostBindingHandler($event) { return ctx.onClick($event); });
631
622
  } if (rf & 2) {
@@ -638,9 +629,7 @@ class CovalentSideSheetCloseDirective {
638
629
  selector: '[td-side-sheet-close], [CovalentSideSheetClose]',
639
630
  exportAs: 'CovalentSideSheetClose',
640
631
  }]
641
- }], () => [{ type: CovalentSideSheetRef, decorators: [{
642
- type: Optional
643
- }] }, { type: i0.ElementRef }, { type: CovalentSideSheet }], { ariaLabel: [{
632
+ }], null, { ariaLabel: [{
644
633
  type: HostBinding,
645
634
  args: ['attr.arial-label']
646
635
  }, {
@@ -665,25 +654,19 @@ class CovalentSideSheetCloseDirective {
665
654
  * Title of a side sheet element. Stays fixed to the top of the side sheet when scrolling.
666
655
  */
667
656
  class CovalentSideSheetTitleDirective {
668
- _dialogRef;
669
- _elementRef;
670
- _dialog;
657
+ _dialogRef = inject(CovalentSideSheetRef, {
658
+ optional: true,
659
+ });
660
+ _elementRef = inject(ElementRef);
661
+ _dialog = inject(CovalentSideSheet);
671
662
  /** Unique id for the dialog title. If none is supplied, it will be auto-generated. */
672
663
  id = `td-side-sheet-title-${dialogElementUid++}`;
673
664
  tdSideSheetTitle = true;
674
665
  idAttr = this.id;
675
- constructor(
676
- // The dialog title directive is always used in combination with a `CovalentSideSheetRef`.
677
- // tslint:disable-next-line: lightweight-tokens
678
- _dialogRef, _elementRef, _dialog) {
679
- this._dialogRef = _dialogRef;
680
- this._elementRef = _elementRef;
681
- this._dialog = _dialog;
682
- }
683
666
  ngOnInit() {
684
667
  if (this._dialogRef) {
685
668
  Promise.resolve().then(() => {
686
- const container = this._dialogRef._containerInstance;
669
+ const container = this._dialogRef?._containerInstance;
687
670
  if (container && !container._ariaLabelledByQueue.includes(this.id)) {
688
671
  container._ariaLabelledByQueue.push(this.id);
689
672
  }
@@ -693,7 +676,7 @@ class CovalentSideSheetTitleDirective {
693
676
  this._dialogRef = getClosestDialog(this._elementRef, this._dialog.openSideSheets);
694
677
  }
695
678
  }
696
- static ɵfac = function CovalentSideSheetTitleDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentSideSheetTitleDirective)(i0.ɵɵdirectiveInject(CovalentSideSheetRef, 8), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(CovalentSideSheet)); };
679
+ static ɵfac = function CovalentSideSheetTitleDirective_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CovalentSideSheetTitleDirective)(); };
697
680
  static ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: CovalentSideSheetTitleDirective, selectors: [["", "td-side-sheet-title", ""], ["", "CovalentSideSheetTitle", ""]], hostVars: 3, hostBindings: function CovalentSideSheetTitleDirective_HostBindings(rf, ctx) { if (rf & 2) {
698
681
  i0.ɵɵattribute("id", ctx.idAttr);
699
682
  i0.ɵɵclassProp("td-side-sheet-title", ctx.tdSideSheetTitle);
@@ -705,9 +688,7 @@ class CovalentSideSheetTitleDirective {
705
688
  selector: '[td-side-sheet-title], [CovalentSideSheetTitle]',
706
689
  exportAs: 'CovalentSideSheetTitle',
707
690
  }]
708
- }], () => [{ type: CovalentSideSheetRef, decorators: [{
709
- type: Optional
710
- }] }, { type: i0.ElementRef }, { type: CovalentSideSheet }], { id: [{
691
+ }], null, { id: [{
711
692
  type: Input
712
693
  }], tdSideSheetTitle: [{
713
694
  type: HostBinding,
@@ -785,7 +766,7 @@ function getClosestDialog(element, openDialogs) {
785
766
  parent = parent.parentElement;
786
767
  }
787
768
  return parent
788
- ? openDialogs.find((dialog) => dialog.id === parent?.id) ?? openDialogs[0]
769
+ ? (openDialogs.find((dialog) => dialog.id === parent?.id) ?? openDialogs[0])
789
770
  : openDialogs[0];
790
771
  }
791
772