@skyux/modals 8.2.6 → 8.3.0

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { EventEmitter, NgModule, Component, ViewEncapsulation, Injectable, Inject, Injector, ViewContainerRef, Optional, ViewChild, Directive, Output, HostListener, inject, ChangeDetectorRef, ElementRef, Host, HostBinding, Input, InjectionToken } from '@angular/core';
2
+ import { EventEmitter, NgModule, Component, ViewEncapsulation, Injectable, Inject, Injector, ViewContainerRef, Optional, ViewChild, InjectionToken, Directive, Output, HostListener, inject, ChangeDetectorRef, ElementRef, Host, HostBinding, Input } from '@angular/core';
3
3
  import * as i4 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import * as i3 from '@skyux/core';
@@ -11,7 +11,7 @@ import { NavigationStart, RouterModule } from '@angular/router';
11
11
  import * as i6 from '@skyux/indicators';
12
12
  import { SkyIconModule } from '@skyux/indicators';
13
13
  import * as i2$1 from '@skyux/i18n';
14
- import { getLibStringForLocale, SkyI18nModule, SKY_LIB_RESOURCES_PROVIDERS } from '@skyux/i18n';
14
+ import { getLibStringForLocale, SkyI18nModule, SKY_LIB_RESOURCES_PROVIDERS, SkyLibResourcesService } from '@skyux/i18n';
15
15
  import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
16
16
  import { Subject, BehaviorSubject, ReplaySubject } from 'rxjs';
17
17
  import { takeUntil, takeWhile, take } from 'rxjs/operators';
@@ -67,6 +67,13 @@ const RESOURCES = {
67
67
  skyux_modal_open_help: { message: 'Open Help' },
68
68
  skyux_modal_footer_cancel_button: { message: 'Cancel' },
69
69
  skyux_modal_footer_primary_button: { message: 'Save' },
70
+ skyux_modal_dirty_default_message: {
71
+ message: 'Are you sure you want to discard your changes?',
72
+ },
73
+ skyux_modal_dirty_default_discard_changes_text: {
74
+ message: 'Discard changes',
75
+ },
76
+ skyux_modal_dirty_default_keep_working_text: { message: 'Keep working' },
70
77
  },
71
78
  };
72
79
  class SkyModalsResourcesProvider {
@@ -478,6 +485,226 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
478
485
  }]
479
486
  }] } });
480
487
 
488
+ /**
489
+ * @internal
490
+ */
491
+ const SKY_CONFIRM_CONFIG = new InjectionToken('SkyConfirmConfig');
492
+
493
+ /**
494
+ * Properties about the modal close action and a method to close the modal.
495
+ */
496
+ class SkyModalBeforeCloseHandler {
497
+ constructor(closeModal, closeArgs) {
498
+ this.closeArgs = closeArgs;
499
+ this.closeModal = closeModal;
500
+ }
501
+ }
502
+
503
+ /**
504
+ * Contains an object with the data passed from users when
505
+ * a modal is closed and the reason that the modal was closed.
506
+ */
507
+ class SkyModalCloseArgs {
508
+ }
509
+
510
+ var _SkyModalInstance_instances, _SkyModalInstance__beforeClose, _SkyModalInstance__closed, _SkyModalInstance__helpOpened, _SkyModalInstance_closeModal, _SkyModalInstance_notifyClosed;
511
+ class SkyModalInstance {
512
+ constructor() {
513
+ _SkyModalInstance_instances.add(this);
514
+ _SkyModalInstance__beforeClose.set(this, new Subject());
515
+ _SkyModalInstance__closed.set(this, new Subject());
516
+ _SkyModalInstance__helpOpened.set(this, new Subject());
517
+ }
518
+ /**
519
+ * An event that the modal instance emits when it is about to close.
520
+ * It emits a `SkyModalBeforeCloseHandler` object with a `closeModal` method
521
+ * that closes the modal. If a subscription exists for this event,
522
+ * the modal does not close until the subscriber calls the `closeModal` method.
523
+ */
524
+ get beforeClose() {
525
+ return __classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f");
526
+ }
527
+ /**
528
+ * An event that the modal instance emits when it closes.
529
+ * It emits a `SkyModalCloseArgs` object with a `data` property that includes
530
+ * data passed from users on close or save and a `reason` property that indicates
531
+ * whether the modal was saved or closed without saving.
532
+ * The `reason` property accepts any string value.
533
+ * Common examples include `"cancel"`, `"close"`, and `"save"`.
534
+ */
535
+ get closed() {
536
+ return __classPrivateFieldGet(this, _SkyModalInstance__closed, "f");
537
+ }
538
+ /**
539
+ * An event that the modal instance emits when users click
540
+ * the <i class="fa fa-question-circle" aria-hidden="true"></i> button.
541
+ * If a `helpKey` parameter was specified, the `helpOpened` event broadcasts the `helpKey`.
542
+ */
543
+ get helpOpened() {
544
+ return __classPrivateFieldGet(this, _SkyModalInstance__helpOpened, "f");
545
+ }
546
+ /**
547
+ * Closes the modal instance.
548
+ * @param result Specifies an object to emit to subscribers of the `closed` event of the
549
+ * modal instance. The `SkyModalInstance` provider can be injected into a component's constructor
550
+ * so that this `close` function can be called from a button in the `sky-modal-footer`.
551
+ * @param reason Specifies the reason for the modal closing, with the default reason of `"close"`.
552
+ * @param ignoreBeforeClose Indicates whether to ignore the modal instance's `beforeClose` event.
553
+ */
554
+ close(result, reason, ignoreBeforeClose) {
555
+ if (reason === undefined) {
556
+ reason = 'close';
557
+ }
558
+ __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_closeModal).call(this, reason, result, ignoreBeforeClose);
559
+ }
560
+ /**
561
+ * Closes the modal instance with `reason="cancel"`.
562
+ * @param result Specifies an object to emit to subscribers of the `closed` event of the modal
563
+ * instance. The `SkyModalInstance` provider can be injected into a component's constructor so
564
+ * that this cancel function can be called from a button in the `sky-modal-footer`.
565
+ */
566
+ cancel(result) {
567
+ __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_closeModal).call(this, 'cancel', result);
568
+ }
569
+ /**
570
+ * Closes the modal instance with `reason="save"`.
571
+ * @param result Specifies an object to emit to subscribers of the `closed` event of the modal
572
+ * instance. The `SkyModalInstance` provider can be injected into a component's constructor so
573
+ * that this `save` function can be called from a button in `the sky-modal-footer`.
574
+ */
575
+ save(result) {
576
+ __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_closeModal).call(this, 'save', result);
577
+ }
578
+ /**
579
+ * Triggers the `helpOpened` event that broadcasts a `helpKey` parameter to open
580
+ * when users click the <i class="fa fa-question-circle" aria-hidden="true"></i> button.
581
+ * @param helpKey Specifies a string to emit to subscribers of
582
+ * the modal instance's `helpOpened` event. Consumers can inject the `SkyModalInstance` provider
583
+ * into a component's constructor to call the `openHelp` function in the modal template.
584
+ */
585
+ openHelp(helpKey) {
586
+ __classPrivateFieldGet(this, _SkyModalInstance__helpOpened, "f").next(helpKey);
587
+ }
588
+ }
589
+ _SkyModalInstance__beforeClose = new WeakMap(), _SkyModalInstance__closed = new WeakMap(), _SkyModalInstance__helpOpened = new WeakMap(), _SkyModalInstance_instances = new WeakSet(), _SkyModalInstance_closeModal = function _SkyModalInstance_closeModal(type, result, ignoreBeforeClose = false) {
590
+ const args = new SkyModalCloseArgs();
591
+ args.reason = type;
592
+ args.data = result;
593
+ if (__classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f").observers.length === 0 || ignoreBeforeClose) {
594
+ __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_notifyClosed).call(this, args);
595
+ }
596
+ else {
597
+ __classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f").next(new SkyModalBeforeCloseHandler(() => {
598
+ __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_notifyClosed).call(this, args);
599
+ }, args));
600
+ }
601
+ }, _SkyModalInstance_notifyClosed = function _SkyModalInstance_notifyClosed(args) {
602
+ __classPrivateFieldGet(this, _SkyModalInstance__closed, "f").next(args);
603
+ __classPrivateFieldGet(this, _SkyModalInstance__closed, "f").complete();
604
+ __classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f").complete();
605
+ __classPrivateFieldGet(this, _SkyModalInstance__helpOpened, "f").complete();
606
+ };
607
+
608
+ var _SkyModalComponentAdapterService_instances, _SkyModalComponentAdapterService_coreAdapter, _SkyModalComponentAdapterService_setFullPageHeight;
609
+ /**
610
+ * @internal
611
+ */
612
+ class SkyModalComponentAdapterService {
613
+ constructor(coreAdapter) {
614
+ _SkyModalComponentAdapterService_instances.add(this);
615
+ _SkyModalComponentAdapterService_coreAdapter.set(this, void 0);
616
+ __classPrivateFieldSet(this, _SkyModalComponentAdapterService_coreAdapter, coreAdapter, "f");
617
+ }
618
+ handleWindowChange(modalEl) {
619
+ const boundedHeightEl = modalEl.nativeElement.querySelector('.sky-modal');
620
+ const fullPageModalEl = modalEl.nativeElement.querySelector('.sky-modal-full-page');
621
+ /*
622
+ Set modal height equal to max height of window (accounting for padding above and below modal)
623
+ */
624
+ const newHeight = window.innerHeight - 40;
625
+ boundedHeightEl.style.maxHeight = newHeight.toString() + 'px';
626
+ if (fullPageModalEl) {
627
+ __classPrivateFieldGet(this, _SkyModalComponentAdapterService_instances, "m", _SkyModalComponentAdapterService_setFullPageHeight).call(this, fullPageModalEl);
628
+ }
629
+ else {
630
+ /*
631
+ IE11 doesn't handle flex and max-height correctly so we have to explicitly add
632
+ max-height to the content that accounts for standard header and footer height.
633
+ */
634
+ const modalContentEl = modalEl.nativeElement.querySelector('.sky-modal-content');
635
+ const contentHeight = newHeight - 114;
636
+ modalContentEl.style.maxHeight = contentHeight.toString() + 'px';
637
+ }
638
+ }
639
+ isFocusInFirstItem(event, list) {
640
+ /* istanbul ignore next */
641
+ /* sanity check */
642
+ const eventTarget = event.target || event.srcElement;
643
+ return list.length > 0 && eventTarget === list[0];
644
+ }
645
+ isFocusInLastItem(event, list) {
646
+ /* istanbul ignore next */
647
+ /* sanity check */
648
+ const eventTarget = event.target || event.srcElement;
649
+ return list.length > 0 && eventTarget === list[list.length - 1];
650
+ }
651
+ isModalFocused(event, modalEl) {
652
+ /* istanbul ignore next */
653
+ /* sanity check */
654
+ const eventTarget = event.target || event.srcElement;
655
+ return (modalEl &&
656
+ eventTarget === modalEl.nativeElement.querySelector('.sky-modal-dialog'));
657
+ }
658
+ focusLastElement(list) {
659
+ if (list.length > 0) {
660
+ list[list.length - 1].focus();
661
+ return true;
662
+ }
663
+ return false;
664
+ }
665
+ focusFirstElement(list) {
666
+ if (list.length > 0) {
667
+ list[0].focus();
668
+ return true;
669
+ }
670
+ return false;
671
+ }
672
+ modalContentHasDirectChildViewkeeper(modalContentEl) {
673
+ return !!modalContentEl.nativeElement.querySelector('sky-modal-content > .sky-viewkeeper-fixed');
674
+ }
675
+ modalOpened(modalEl) {
676
+ /* istanbul ignore else */
677
+ /* handle the case where somehow there is a focused element already in the modal */
678
+ if (!(document.activeElement &&
679
+ modalEl.nativeElement.contains(document.activeElement))) {
680
+ const currentScrollX = window.pageXOffset;
681
+ const currentScrollY = window.pageYOffset;
682
+ const inputWithAutofocus = modalEl.nativeElement.querySelector('[autofocus]');
683
+ if (inputWithAutofocus) {
684
+ inputWithAutofocus.focus();
685
+ }
686
+ else {
687
+ __classPrivateFieldGet(this, _SkyModalComponentAdapterService_coreAdapter, "f").getFocusableChildrenAndApplyFocus(modalEl, '.sky-modal-content', true);
688
+ }
689
+ window.scrollTo(currentScrollX, currentScrollY);
690
+ }
691
+ }
692
+ }
693
+ _SkyModalComponentAdapterService_coreAdapter = new WeakMap(), _SkyModalComponentAdapterService_instances = new WeakSet(), _SkyModalComponentAdapterService_setFullPageHeight = function _SkyModalComponentAdapterService_setFullPageHeight(fullPageModalEl) {
694
+ const windowHeight = window.innerHeight;
695
+ const fullPageModalStyle = getComputedStyle(fullPageModalEl);
696
+ const marginTopBottom = parseInt(fullPageModalStyle.marginTop, 10) +
697
+ parseInt(fullPageModalStyle.marginBottom, 10);
698
+ const fullPageModalHeight = windowHeight - marginTopBottom + 'px';
699
+ fullPageModalEl.style.height = fullPageModalHeight;
700
+ fullPageModalEl.style.maxHeight = fullPageModalHeight;
701
+ };
702
+ SkyModalComponentAdapterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalComponentAdapterService, deps: [{ token: i3.SkyCoreAdapterService }], target: i0.ɵɵFactoryTarget.Injectable });
703
+ SkyModalComponentAdapterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalComponentAdapterService });
704
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalComponentAdapterService, decorators: [{
705
+ type: Injectable
706
+ }], ctorParameters: function () { return [{ type: i3.SkyCoreAdapterService }]; } });
707
+
481
708
  var _SkyModalScrollShadowDirective_instances, _SkyModalScrollShadowDirective_currentShadow, _SkyModalScrollShadowDirective_currentTheme, _SkyModalScrollShadowDirective_mutationObserver, _SkyModalScrollShadowDirective_ngUnsubscribe, _SkyModalScrollShadowDirective_elRef, _SkyModalScrollShadowDirective_mutationObserverSvc, _SkyModalScrollShadowDirective_ngZone, _SkyModalScrollShadowDirective_themeSvc, _SkyModalScrollShadowDirective_initMutationObserver, _SkyModalScrollShadowDirective_destroyMutationObserver, _SkyModalScrollShadowDirective_checkForShadow, _SkyModalScrollShadowDirective_buildShadowStyle, _SkyModalScrollShadowDirective_emitShadow;
482
709
  /**
483
710
  * Raises an event when the box shadow for the modal header or footer should be adjusted
@@ -597,119 +824,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
597
824
  args: ['scroll']
598
825
  }] } });
599
826
 
600
- var _SkyModalComponentAdapterService_instances, _SkyModalComponentAdapterService_coreAdapter, _SkyModalComponentAdapterService_setFullPageHeight;
827
+ var _SkyModalComponent_hostService, _SkyModalComponent_elRef, _SkyModalComponent_windowRef, _SkyModalComponent_componentAdapter, _SkyModalComponent_coreAdapter, _SkyModalComponent_dockService, _SkyModalComponent_mediaQueryService, _SkyModalComponent_ngUnsubscribe, _SkyModalComponent__ariaDescribedBy, _SkyModalComponent__ariaLabelledBy, _SkyModalComponent_changeDetector, _SkyModalComponent_liveAnnouncerSvc;
828
+ const ARIA_ROLE_DEFAULT = 'dialog';
601
829
  /**
602
- * @internal
830
+ * Provides a common look-and-feel for modal content with options to display
831
+ * a common modal header, specify body content, and display a common modal footer
832
+ * and buttons.
603
833
  */
604
- class SkyModalComponentAdapterService {
605
- constructor(coreAdapter) {
606
- _SkyModalComponentAdapterService_instances.add(this);
607
- _SkyModalComponentAdapterService_coreAdapter.set(this, void 0);
608
- __classPrivateFieldSet(this, _SkyModalComponentAdapterService_coreAdapter, coreAdapter, "f");
609
- }
610
- handleWindowChange(modalEl) {
611
- const boundedHeightEl = modalEl.nativeElement.querySelector('.sky-modal');
612
- const fullPageModalEl = modalEl.nativeElement.querySelector('.sky-modal-full-page');
613
- /*
614
- Set modal height equal to max height of window (accounting for padding above and below modal)
615
- */
616
- const newHeight = window.innerHeight - 40;
617
- boundedHeightEl.style.maxHeight = newHeight.toString() + 'px';
618
- if (fullPageModalEl) {
619
- __classPrivateFieldGet(this, _SkyModalComponentAdapterService_instances, "m", _SkyModalComponentAdapterService_setFullPageHeight).call(this, fullPageModalEl);
620
- }
621
- else {
622
- /*
623
- IE11 doesn't handle flex and max-height correctly so we have to explicitly add
624
- max-height to the content that accounts for standard header and footer height.
625
- */
626
- const modalContentEl = modalEl.nativeElement.querySelector('.sky-modal-content');
627
- const contentHeight = newHeight - 114;
628
- modalContentEl.style.maxHeight = contentHeight.toString() + 'px';
629
- }
630
- }
631
- isFocusInFirstItem(event, list) {
632
- /* istanbul ignore next */
633
- /* sanity check */
634
- const eventTarget = event.target || event.srcElement;
635
- return list.length > 0 && eventTarget === list[0];
636
- }
637
- isFocusInLastItem(event, list) {
638
- /* istanbul ignore next */
639
- /* sanity check */
640
- const eventTarget = event.target || event.srcElement;
641
- return list.length > 0 && eventTarget === list[list.length - 1];
642
- }
643
- isModalFocused(event, modalEl) {
644
- /* istanbul ignore next */
645
- /* sanity check */
646
- const eventTarget = event.target || event.srcElement;
647
- return (modalEl &&
648
- eventTarget === modalEl.nativeElement.querySelector('.sky-modal-dialog'));
649
- }
650
- focusLastElement(list) {
651
- if (list.length > 0) {
652
- list[list.length - 1].focus();
653
- return true;
654
- }
655
- return false;
656
- }
657
- focusFirstElement(list) {
658
- if (list.length > 0) {
659
- list[0].focus();
660
- return true;
661
- }
662
- return false;
663
- }
664
- modalContentHasDirectChildViewkeeper(modalContentEl) {
665
- return !!modalContentEl.nativeElement.querySelector('sky-modal-content > .sky-viewkeeper-fixed');
666
- }
667
- modalOpened(modalEl) {
668
- /* istanbul ignore else */
669
- /* handle the case where somehow there is a focused element already in the modal */
670
- if (!(document.activeElement &&
671
- modalEl.nativeElement.contains(document.activeElement))) {
672
- const currentScrollX = window.pageXOffset;
673
- const currentScrollY = window.pageYOffset;
674
- const inputWithAutofocus = modalEl.nativeElement.querySelector('[autofocus]');
675
- if (inputWithAutofocus) {
676
- inputWithAutofocus.focus();
677
- }
678
- else {
679
- __classPrivateFieldGet(this, _SkyModalComponentAdapterService_coreAdapter, "f").getFocusableChildrenAndApplyFocus(modalEl, '.sky-modal-content', true);
680
- }
681
- window.scrollTo(currentScrollX, currentScrollY);
682
- }
683
- }
684
- }
685
- _SkyModalComponentAdapterService_coreAdapter = new WeakMap(), _SkyModalComponentAdapterService_instances = new WeakSet(), _SkyModalComponentAdapterService_setFullPageHeight = function _SkyModalComponentAdapterService_setFullPageHeight(fullPageModalEl) {
686
- const windowHeight = window.innerHeight;
687
- const fullPageModalStyle = getComputedStyle(fullPageModalEl);
688
- const marginTopBottom = parseInt(fullPageModalStyle.marginTop, 10) +
689
- parseInt(fullPageModalStyle.marginBottom, 10);
690
- const fullPageModalHeight = windowHeight - marginTopBottom + 'px';
691
- fullPageModalEl.style.height = fullPageModalHeight;
692
- fullPageModalEl.style.maxHeight = fullPageModalHeight;
693
- };
694
- SkyModalComponentAdapterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalComponentAdapterService, deps: [{ token: i3.SkyCoreAdapterService }], target: i0.ɵɵFactoryTarget.Injectable });
695
- SkyModalComponentAdapterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalComponentAdapterService });
696
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalComponentAdapterService, decorators: [{
697
- type: Injectable
698
- }], ctorParameters: function () { return [{ type: i3.SkyCoreAdapterService }]; } });
699
-
700
- var _SkyModalComponent_hostService, _SkyModalComponent_elRef, _SkyModalComponent_windowRef, _SkyModalComponent_componentAdapter, _SkyModalComponent_coreAdapter, _SkyModalComponent_dockService, _SkyModalComponent_mediaQueryService, _SkyModalComponent_ngUnsubscribe, _SkyModalComponent__ariaDescribedBy, _SkyModalComponent__ariaLabelledBy, _SkyModalComponent_changeDetector, _SkyModalComponent_liveAnnouncerSvc;
701
- const ARIA_ROLE_DEFAULT = 'dialog';
702
- /**
703
- * Provides a common look-and-feel for modal content with options to display
704
- * a common modal header, specify body content, and display a common modal footer
705
- * and buttons.
706
- */
707
- class SkyModalComponent {
708
- /**
709
- * @internal
710
- */
711
- set ariaRole(value) {
712
- this.ariaRoleOrDefault = value || ARIA_ROLE_DEFAULT;
834
+ class SkyModalComponent {
835
+ /**
836
+ * @internal
837
+ */
838
+ set ariaRole(value) {
839
+ this.ariaRoleOrDefault = value || ARIA_ROLE_DEFAULT;
713
840
  }
714
841
  /**
715
842
  * @internal
@@ -891,180 +1018,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
891
1018
  args: ['document:keydown', ['$event']]
892
1019
  }] } });
893
1020
 
894
- class SkyModalModule {
895
- }
896
- SkyModalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
897
- SkyModalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, declarations: [SkyModalComponent,
898
- SkyModalContentComponent,
899
- SkyModalFooterComponent,
900
- SkyModalHeaderComponent,
901
- SkyModalHostComponent,
902
- SkyModalScrollShadowDirective], imports: [CommonModule,
903
- RouterModule,
904
- SkyIconModule,
905
- SkyIdModule,
906
- SkyModalsResourcesModule,
907
- SkyThemeModule,
908
- SkyTrimModule], exports: [SkyModalComponent,
909
- SkyModalContentComponent,
910
- SkyModalFooterComponent,
911
- SkyModalHeaderComponent] });
912
- SkyModalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, imports: [CommonModule,
913
- RouterModule,
914
- SkyIconModule,
915
- SkyIdModule,
916
- SkyModalsResourcesModule,
917
- SkyThemeModule,
918
- SkyTrimModule] });
919
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, decorators: [{
920
- type: NgModule,
921
- args: [{
922
- declarations: [
923
- SkyModalComponent,
924
- SkyModalContentComponent,
925
- SkyModalFooterComponent,
926
- SkyModalHeaderComponent,
927
- SkyModalHostComponent,
928
- SkyModalScrollShadowDirective,
929
- ],
930
- imports: [
931
- CommonModule,
932
- RouterModule,
933
- SkyIconModule,
934
- SkyIdModule,
935
- SkyModalsResourcesModule,
936
- SkyThemeModule,
937
- SkyTrimModule,
938
- ],
939
- exports: [
940
- SkyModalComponent,
941
- SkyModalContentComponent,
942
- SkyModalFooterComponent,
943
- SkyModalHeaderComponent,
944
- ],
945
- }]
946
- }] });
947
-
948
- /**
949
- * @internal
950
- */
951
- const SKY_CONFIRM_CONFIG = new InjectionToken('SkyConfirmConfig');
952
-
953
- /**
954
- * Properties about the modal close action and a method to close the modal.
955
- */
956
- class SkyModalBeforeCloseHandler {
957
- constructor(closeModal, closeArgs) {
958
- this.closeArgs = closeArgs;
959
- this.closeModal = closeModal;
960
- }
961
- }
962
-
963
- /**
964
- * Contains an object with the data passed from users when
965
- * a modal is closed and the reason that the modal was closed.
966
- */
967
- class SkyModalCloseArgs {
968
- }
969
-
970
- var _SkyModalInstance_instances, _SkyModalInstance__beforeClose, _SkyModalInstance__closed, _SkyModalInstance__helpOpened, _SkyModalInstance_closeModal, _SkyModalInstance_notifyClosed;
971
- class SkyModalInstance {
972
- constructor() {
973
- _SkyModalInstance_instances.add(this);
974
- _SkyModalInstance__beforeClose.set(this, new Subject());
975
- _SkyModalInstance__closed.set(this, new Subject());
976
- _SkyModalInstance__helpOpened.set(this, new Subject());
977
- }
978
- /**
979
- * An event that the modal instance emits when it is about to close.
980
- * It emits a `SkyModalBeforeCloseHandler` object with a `closeModal` method
981
- * that closes the modal. If a subscription exists for this event,
982
- * the modal does not close until the subscriber calls the `closeModal` method.
983
- */
984
- get beforeClose() {
985
- return __classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f");
986
- }
987
- /**
988
- * An event that the modal instance emits when it closes.
989
- * It emits a `SkyModalCloseArgs` object with a `data` property that includes
990
- * data passed from users on close or save and a `reason` property that indicates
991
- * whether the modal was saved or closed without saving.
992
- * The `reason` property accepts any string value.
993
- * Common examples include `"cancel"`, `"close"`, and `"save"`.
994
- */
995
- get closed() {
996
- return __classPrivateFieldGet(this, _SkyModalInstance__closed, "f");
997
- }
998
- /**
999
- * An event that the modal instance emits when users click
1000
- * the <i class="fa fa-question-circle" aria-hidden="true"></i> button.
1001
- * If a `helpKey` parameter was specified, the `helpOpened` event broadcasts the `helpKey`.
1002
- */
1003
- get helpOpened() {
1004
- return __classPrivateFieldGet(this, _SkyModalInstance__helpOpened, "f");
1005
- }
1006
- /**
1007
- * Closes the modal instance.
1008
- * @param result Specifies an object to emit to subscribers of the `closed` event of the
1009
- * modal instance. The `SkyModalInstance` provider can be injected into a component's constructor
1010
- * so that this `close` function can be called from a button in the `sky-modal-footer`.
1011
- * @param reason Specifies the reason for the modal closing, with the default reason of `"close"`.
1012
- * @param ignoreBeforeClose Indicates whether to ignore the modal instance's `beforeClose` event.
1013
- */
1014
- close(result, reason, ignoreBeforeClose) {
1015
- if (reason === undefined) {
1016
- reason = 'close';
1017
- }
1018
- __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_closeModal).call(this, reason, result, ignoreBeforeClose);
1019
- }
1020
- /**
1021
- * Closes the modal instance with `reason="cancel"`.
1022
- * @param result Specifies an object to emit to subscribers of the `closed` event of the modal
1023
- * instance. The `SkyModalInstance` provider can be injected into a component's constructor so
1024
- * that this cancel function can be called from a button in the `sky-modal-footer`.
1025
- */
1026
- cancel(result) {
1027
- __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_closeModal).call(this, 'cancel', result);
1028
- }
1029
- /**
1030
- * Closes the modal instance with `reason="save"`.
1031
- * @param result Specifies an object to emit to subscribers of the `closed` event of the modal
1032
- * instance. The `SkyModalInstance` provider can be injected into a component's constructor so
1033
- * that this `save` function can be called from a button in `the sky-modal-footer`.
1034
- */
1035
- save(result) {
1036
- __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_closeModal).call(this, 'save', result);
1037
- }
1038
- /**
1039
- * Triggers the `helpOpened` event that broadcasts a `helpKey` parameter to open
1040
- * when users click the <i class="fa fa-question-circle" aria-hidden="true"></i> button.
1041
- * @param helpKey Specifies a string to emit to subscribers of
1042
- * the modal instance's `helpOpened` event. Consumers can inject the `SkyModalInstance` provider
1043
- * into a component's constructor to call the `openHelp` function in the modal template.
1044
- */
1045
- openHelp(helpKey) {
1046
- __classPrivateFieldGet(this, _SkyModalInstance__helpOpened, "f").next(helpKey);
1047
- }
1048
- }
1049
- _SkyModalInstance__beforeClose = new WeakMap(), _SkyModalInstance__closed = new WeakMap(), _SkyModalInstance__helpOpened = new WeakMap(), _SkyModalInstance_instances = new WeakSet(), _SkyModalInstance_closeModal = function _SkyModalInstance_closeModal(type, result, ignoreBeforeClose = false) {
1050
- const args = new SkyModalCloseArgs();
1051
- args.reason = type;
1052
- args.data = result;
1053
- if (__classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f").observers.length === 0 || ignoreBeforeClose) {
1054
- __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_notifyClosed).call(this, args);
1055
- }
1056
- else {
1057
- __classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f").next(new SkyModalBeforeCloseHandler(() => {
1058
- __classPrivateFieldGet(this, _SkyModalInstance_instances, "m", _SkyModalInstance_notifyClosed).call(this, args);
1059
- }, args));
1060
- }
1061
- }, _SkyModalInstance_notifyClosed = function _SkyModalInstance_notifyClosed(args) {
1062
- __classPrivateFieldGet(this, _SkyModalInstance__closed, "f").next(args);
1063
- __classPrivateFieldGet(this, _SkyModalInstance__closed, "f").complete();
1064
- __classPrivateFieldGet(this, _SkyModalInstance__beforeClose, "f").complete();
1065
- __classPrivateFieldGet(this, _SkyModalInstance__helpOpened, "f").complete();
1066
- };
1067
-
1068
1021
  var _SkyConfirmComponent_instances, _SkyConfirmComponent_config, _SkyConfirmComponent_modal, _SkyConfirmComponent_resourcesService, _SkyConfirmComponent_getPresetButtons, _SkyConfirmComponent_getCustomButtons;
1069
1022
  class SkyConfirmComponent {
1070
1023
  constructor(config, modal, resourcesService, idService) {
@@ -1165,34 +1118,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1165
1118
  args: [SKY_CONFIRM_CONFIG]
1166
1119
  }] }, { type: SkyModalInstance }, { type: i2$1.SkyLibResourcesService }, { type: i3.SkyIdService }]; } });
1167
1120
 
1168
- class SkyConfirmModule {
1169
- }
1170
- SkyConfirmModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1171
- SkyConfirmModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, declarations: [SkyConfirmComponent], imports: [CommonModule,
1172
- SkyIdModule,
1173
- SkyModalModule,
1174
- SkyModalsResourcesModule,
1175
- SkyThemeModule], exports: [SkyConfirmComponent] });
1176
- SkyConfirmModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, imports: [CommonModule,
1177
- SkyIdModule,
1178
- SkyModalModule,
1179
- SkyModalsResourcesModule,
1180
- SkyThemeModule] });
1181
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, decorators: [{
1182
- type: NgModule,
1183
- args: [{
1184
- declarations: [SkyConfirmComponent],
1185
- imports: [
1186
- CommonModule,
1187
- SkyIdModule,
1188
- SkyModalModule,
1189
- SkyModalsResourcesModule,
1190
- SkyThemeModule,
1191
- ],
1192
- exports: [SkyConfirmComponent],
1193
- }]
1194
- }] });
1195
-
1196
1121
  var _SkyModalService_instances, _SkyModalService_dynamicComponentService, _SkyModalService_getConfigFromParameter, _SkyModalService_createHostComponent;
1197
1122
  /**
1198
1123
  * A service that launches modals.
@@ -1335,9 +1260,179 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1335
1260
  }]
1336
1261
  }], ctorParameters: function () { return [{ type: SkyModalService }]; } });
1337
1262
 
1263
+ var _SkyModalIsDirtyDirective_instances, _SkyModalIsDirtyDirective_ngUnsubscribe, _SkyModalIsDirtyDirective_modalInstance, _SkyModalIsDirtyDirective_confirmSvc, _SkyModalIsDirtyDirective_resourcesSvc, _SkyModalIsDirtyDirective_promptIfDirty;
1264
+ /**
1265
+ * Provides a way to mark a modal as "dirty" and displays a confirmation
1266
+ * message when a user closes the modal without saving.
1267
+ */
1268
+ class SkyModalIsDirtyDirective {
1269
+ constructor() {
1270
+ _SkyModalIsDirtyDirective_instances.add(this);
1271
+ /**
1272
+ * Whether the user edited an input on the modal.
1273
+ * @required
1274
+ */
1275
+ this.isDirty = false;
1276
+ _SkyModalIsDirtyDirective_ngUnsubscribe.set(this, new Subject());
1277
+ _SkyModalIsDirtyDirective_modalInstance.set(this, inject(SkyModalInstance));
1278
+ _SkyModalIsDirtyDirective_confirmSvc.set(this, inject(SkyConfirmService));
1279
+ _SkyModalIsDirtyDirective_resourcesSvc.set(this, inject(SkyLibResourcesService));
1280
+ }
1281
+ ngOnInit() {
1282
+ __classPrivateFieldGet(this, _SkyModalIsDirtyDirective_modalInstance, "f").beforeClose
1283
+ .pipe(takeUntil(__classPrivateFieldGet(this, _SkyModalIsDirtyDirective_ngUnsubscribe, "f")))
1284
+ .subscribe((handler) => __classPrivateFieldGet(this, _SkyModalIsDirtyDirective_instances, "m", _SkyModalIsDirtyDirective_promptIfDirty).call(this, handler));
1285
+ }
1286
+ ngOnDestroy() {
1287
+ __classPrivateFieldGet(this, _SkyModalIsDirtyDirective_ngUnsubscribe, "f").next();
1288
+ __classPrivateFieldGet(this, _SkyModalIsDirtyDirective_ngUnsubscribe, "f").complete();
1289
+ }
1290
+ }
1291
+ _SkyModalIsDirtyDirective_ngUnsubscribe = new WeakMap(), _SkyModalIsDirtyDirective_modalInstance = new WeakMap(), _SkyModalIsDirtyDirective_confirmSvc = new WeakMap(), _SkyModalIsDirtyDirective_resourcesSvc = new WeakMap(), _SkyModalIsDirtyDirective_instances = new WeakSet(), _SkyModalIsDirtyDirective_promptIfDirty = function _SkyModalIsDirtyDirective_promptIfDirty(handler) {
1292
+ if (this.isDirty && handler.closeArgs.reason === 'close') {
1293
+ __classPrivateFieldGet(this, _SkyModalIsDirtyDirective_resourcesSvc, "f")
1294
+ .getStrings({
1295
+ message: 'skyux_modal_dirty_default_message',
1296
+ discardActionText: 'skyux_modal_dirty_default_discard_changes_text',
1297
+ keepActionText: 'skyux_modal_dirty_default_keep_working_text',
1298
+ })
1299
+ .subscribe((textValues) => {
1300
+ const discardAction = 'discard';
1301
+ const keepAction = 'keep';
1302
+ __classPrivateFieldGet(this, _SkyModalIsDirtyDirective_confirmSvc, "f")
1303
+ .open({
1304
+ message: textValues.message,
1305
+ buttons: [
1306
+ {
1307
+ action: discardAction,
1308
+ text: textValues.discardActionText,
1309
+ styleType: 'primary',
1310
+ },
1311
+ {
1312
+ action: keepAction,
1313
+ text: textValues.keepActionText,
1314
+ styleType: 'link',
1315
+ },
1316
+ ],
1317
+ type: SkyConfirmType.Custom,
1318
+ })
1319
+ .closed.subscribe((args) => {
1320
+ if (args.action === discardAction) {
1321
+ handler.closeModal();
1322
+ }
1323
+ });
1324
+ });
1325
+ }
1326
+ else {
1327
+ handler.closeModal();
1328
+ }
1329
+ };
1330
+ SkyModalIsDirtyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalIsDirtyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1331
+ SkyModalIsDirtyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: SkyModalIsDirtyDirective, selector: "sky-modal[isDirty]", inputs: { isDirty: "isDirty" }, host: { properties: { "attr.data-sky-modal-is-dirty": "this.isDirty" } }, ngImport: i0 });
1332
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalIsDirtyDirective, decorators: [{
1333
+ type: Directive,
1334
+ args: [{
1335
+ // Since this is limited to sky-modal, it should be safe to
1336
+ // leave off the sky prefix.
1337
+ // eslint-disable-next-line @angular-eslint/directive-selector
1338
+ selector: 'sky-modal[isDirty]',
1339
+ }]
1340
+ }], propDecorators: { isDirty: [{
1341
+ type: Input
1342
+ }, {
1343
+ type: HostBinding,
1344
+ args: ['attr.data-sky-modal-is-dirty']
1345
+ }] } });
1346
+
1347
+ class SkyModalModule {
1348
+ }
1349
+ SkyModalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1350
+ SkyModalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, declarations: [SkyModalComponent,
1351
+ SkyModalContentComponent,
1352
+ SkyModalFooterComponent,
1353
+ SkyModalHeaderComponent,
1354
+ SkyModalHostComponent,
1355
+ SkyModalIsDirtyDirective,
1356
+ SkyModalScrollShadowDirective], imports: [CommonModule,
1357
+ RouterModule,
1358
+ SkyIconModule,
1359
+ SkyIdModule,
1360
+ SkyModalsResourcesModule,
1361
+ SkyThemeModule,
1362
+ SkyTrimModule], exports: [SkyModalComponent,
1363
+ SkyModalContentComponent,
1364
+ SkyModalFooterComponent,
1365
+ SkyModalHeaderComponent,
1366
+ SkyModalIsDirtyDirective] });
1367
+ SkyModalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, imports: [CommonModule,
1368
+ RouterModule,
1369
+ SkyIconModule,
1370
+ SkyIdModule,
1371
+ SkyModalsResourcesModule,
1372
+ SkyThemeModule,
1373
+ SkyTrimModule] });
1374
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyModalModule, decorators: [{
1375
+ type: NgModule,
1376
+ args: [{
1377
+ declarations: [
1378
+ SkyModalComponent,
1379
+ SkyModalContentComponent,
1380
+ SkyModalFooterComponent,
1381
+ SkyModalHeaderComponent,
1382
+ SkyModalHostComponent,
1383
+ SkyModalIsDirtyDirective,
1384
+ SkyModalScrollShadowDirective,
1385
+ ],
1386
+ imports: [
1387
+ CommonModule,
1388
+ RouterModule,
1389
+ SkyIconModule,
1390
+ SkyIdModule,
1391
+ SkyModalsResourcesModule,
1392
+ SkyThemeModule,
1393
+ SkyTrimModule,
1394
+ ],
1395
+ exports: [
1396
+ SkyModalComponent,
1397
+ SkyModalContentComponent,
1398
+ SkyModalFooterComponent,
1399
+ SkyModalHeaderComponent,
1400
+ SkyModalIsDirtyDirective,
1401
+ ],
1402
+ }]
1403
+ }] });
1404
+
1405
+ class SkyConfirmModule {
1406
+ }
1407
+ SkyConfirmModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1408
+ SkyConfirmModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, declarations: [SkyConfirmComponent], imports: [CommonModule,
1409
+ SkyIdModule,
1410
+ SkyModalModule,
1411
+ SkyModalsResourcesModule,
1412
+ SkyThemeModule], exports: [SkyConfirmComponent] });
1413
+ SkyConfirmModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, imports: [CommonModule,
1414
+ SkyIdModule,
1415
+ SkyModalModule,
1416
+ SkyModalsResourcesModule,
1417
+ SkyThemeModule] });
1418
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SkyConfirmModule, decorators: [{
1419
+ type: NgModule,
1420
+ args: [{
1421
+ declarations: [SkyConfirmComponent],
1422
+ imports: [
1423
+ CommonModule,
1424
+ SkyIdModule,
1425
+ SkyModalModule,
1426
+ SkyModalsResourcesModule,
1427
+ SkyThemeModule,
1428
+ ],
1429
+ exports: [SkyConfirmComponent],
1430
+ }]
1431
+ }] });
1432
+
1338
1433
  /**
1339
1434
  * Generated bundle index. Do not edit.
1340
1435
  */
1341
1436
 
1342
- export { SkyConfirmInstance, SkyConfirmModule, SkyConfirmService, SkyConfirmType, SkyModalBeforeCloseHandler, SkyModalCloseArgs, SkyModalConfiguration, SkyModalHostService, SkyModalInstance, SkyModalModule, SkyModalService, SkyConfirmComponent as λ1, SkyModalContentComponent as λ2, SkyModalFooterComponent as λ3, SkyModalHeaderComponent as λ4, SkyModalComponent as λ5 };
1437
+ export { SkyConfirmInstance, SkyConfirmModule, SkyConfirmService, SkyConfirmType, SkyModalBeforeCloseHandler, SkyModalCloseArgs, SkyModalConfiguration, SkyModalHostService, SkyModalInstance, SkyModalModule, SkyModalService, SkyConfirmComponent as λ1, SkyModalContentComponent as λ2, SkyModalFooterComponent as λ3, SkyModalHeaderComponent as λ4, SkyModalComponent as λ5, SkyModalIsDirtyDirective as λ6 };
1343
1438
  //# sourceMappingURL=skyux-modals.mjs.map