@coolon/angular-ui-powerups 0.0.60 → 0.0.62

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.
Files changed (48) hide show
  1. package/bundles/coolon-angular-ui-powerups.umd.js +599 -117
  2. package/bundles/coolon-angular-ui-powerups.umd.js.map +1 -1
  3. package/bundles/coolon-angular-ui-powerups.umd.min.js +1 -1
  4. package/bundles/coolon-angular-ui-powerups.umd.min.js.map +1 -1
  5. package/coolon-angular-ui-powerups.d.ts +5 -4
  6. package/coolon-angular-ui-powerups.metadata.json +1 -1
  7. package/esm2015/coolon-angular-ui-powerups.js +6 -5
  8. package/esm2015/index.js +2 -2
  9. package/esm2015/lib/interaction/abstract-activity.js +2 -9
  10. package/esm2015/lib/interaction/activity.js +11 -1
  11. package/esm2015/lib/interaction/components/activity-container/activity-container.component.js +64 -1
  12. package/esm2015/lib/interaction/components/activity-outlet/activity-outlet.component.js +17 -53
  13. package/esm2015/lib/interaction/components/confirm-then-dialog/confirm-then-dialog.component.js +92 -0
  14. package/esm2015/lib/interaction/guards/close-interaction.guard.js +62 -0
  15. package/esm2015/lib/interaction/index.js +4 -2
  16. package/esm2015/lib/interaction/interaction-context.js +35 -5
  17. package/esm2015/lib/interaction/interaction.module.js +5 -2
  18. package/esm2015/lib/interaction/services/dialog-interaction.service.js +108 -4
  19. package/esm2015/lib/place/guards/leave-place.guard.js +128 -20
  20. package/esm2015/public_api.js +2 -2
  21. package/esm5/coolon-angular-ui-powerups.js +6 -5
  22. package/esm5/index.js +2 -2
  23. package/esm5/lib/interaction/abstract-activity.js +9 -9
  24. package/esm5/lib/interaction/activity.js +11 -1
  25. package/esm5/lib/interaction/components/activity-container/activity-container.component.js +89 -1
  26. package/esm5/lib/interaction/components/activity-outlet/activity-outlet.component.js +28 -68
  27. package/esm5/lib/interaction/components/confirm-then-dialog/confirm-then-dialog.component.js +107 -0
  28. package/esm5/lib/interaction/guards/close-interaction.guard.js +66 -0
  29. package/esm5/lib/interaction/index.js +4 -2
  30. package/esm5/lib/interaction/interaction-context.js +43 -6
  31. package/esm5/lib/interaction/interaction.module.js +5 -2
  32. package/esm5/lib/interaction/services/dialog-interaction.service.js +131 -4
  33. package/esm5/lib/place/guards/leave-place.guard.js +131 -20
  34. package/esm5/public_api.js +2 -2
  35. package/fesm2015/coolon-angular-ui-powerups.js +493 -85
  36. package/fesm2015/coolon-angular-ui-powerups.js.map +1 -1
  37. package/fesm5/coolon-angular-ui-powerups.js +582 -102
  38. package/fesm5/coolon-angular-ui-powerups.js.map +1 -1
  39. package/lib/interaction/activity.d.ts +2 -0
  40. package/lib/interaction/components/activity-container/activity-container.component.d.ts +11 -1
  41. package/lib/interaction/components/activity-outlet/activity-outlet.component.d.ts +3 -8
  42. package/lib/interaction/components/confirm-then-dialog/confirm-then-dialog.component.d.ts +22 -0
  43. package/lib/interaction/guards/close-interaction.guard.d.ts +12 -0
  44. package/lib/interaction/index.d.ts +2 -0
  45. package/lib/interaction/interaction-context.d.ts +24 -4
  46. package/lib/interaction/services/dialog-interaction.service.d.ts +15 -2
  47. package/lib/place/guards/leave-place.guard.d.ts +7 -1
  48. package/package.json +1 -1
@@ -1,18 +1,18 @@
1
- import { DOCUMENT, CommonModule } from '@angular/common';
1
+ import { DOCUMENT, CommonModule, Location } from '@angular/common';
2
2
  import { EventEmitter, Input, Output, HostListener, Component, Directive, ElementRef, Inject, NgZone, InjectionToken, Injector, ComponentFactoryResolver, ViewContainerRef, ViewChild, ViewChildren, Injectable, Optional, ɵɵdefineInjectable, ɵɵinject, NgModule, HostBinding, INJECTOR } from '@angular/core';
3
3
  import { FormsModule } from '@angular/forms';
4
4
  import { MatDialog, MatButtonModule, MatDialogModule, MatTabsModule, MatProgressSpinnerModule, MatInputModule, MatFormFieldModule, MatSelectModule } from '@angular/material';
5
5
  import { MatTabsModule as MatTabsModule$1 } from '@angular/material/tabs';
6
6
  import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7
7
  import { __decorate, __metadata, __awaiter } from 'tslib';
8
- import { GarbageCollector, DelegatingFormValueModel, UseDelegate, ValueModel, ListModel, StoreInListModel, assert, UnaryCommand, lang, Dsl, Logger, Trace, DelegatingValueModel, MutableListModel, StoreInValueModel, Binding, MutableValueModel, Guard, OptionsHelper, ValueHolder } from '@coolon/pectin';
8
+ import { GarbageCollector, DelegatingFormValueModel, UseDelegate, ValueModel, ListModel, StoreInListModel, assert, UnaryCommand, lang, Dsl, Logger, DelegatingValueModel, MutableListModel, DelegatingListModel, StoreInValueModel, Binding, MutableValueModel, Guard, OptionsHelper, ValueHolder, Trace } from '@coolon/pectin';
9
9
  import { PortalModule } from '@angular/cdk/portal';
10
10
  import { assert as assert$1, Klass, Opts } from '@coolon/typescript-utilities';
11
11
  import { MatDialogConfig, MAT_DIALOG_DEFAULT_OPTIONS, MatDialog as MatDialog$1 } from '@angular/material/dialog';
12
+ import { Router, RouterModule, NavigationEnd, NavigationError } from '@angular/router';
12
13
  import { MatIconModule } from '@angular/material/icon';
13
14
  import { MatListModule } from '@angular/material/list';
14
15
  import { MatTooltipModule } from '@angular/material/tooltip';
15
- import { Router, RouterModule } from '@angular/router';
16
16
  import { Memoize as Memoize$1 } from '@typescript-plus/fast-memoize-decorator/dist/src';
17
17
  import { Memoize } from '@typescript-plus/fast-memoize-decorator';
18
18
  import 'reflect-metadata';
@@ -651,14 +651,34 @@ if (false) {
651
651
  * @fileoverview added by tsickle
652
652
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
653
653
  */
654
- /** @type {?} */
655
- const INTERACTION_CONTEXT = new InjectionToken('InteractionContext');
656
654
  /**
657
655
  * @abstract
658
656
  */
659
- class InteractionContext {
657
+ class InteractionContext extends GarbageCollector {
658
+ constructor() {
659
+ super();
660
+ }
661
+ /**
662
+ * Returns true if an activity is currently running.
663
+ * @return {?}
664
+ */
665
+ isActive() {
666
+ return this.activityList.length > 0;
667
+ }
660
668
  }
661
669
  if (false) {
670
+ /**
671
+ * Returns the activity that is currently active.
672
+ * This model is only updated in the next tick after the view has been updated.
673
+ * @type {?}
674
+ */
675
+ InteractionContext.prototype.currentActivity;
676
+ /**
677
+ * Returns the current list of activities that are in progress.
678
+ * This model is only updated in the next tick after the view has been updated.
679
+ * @type {?}
680
+ */
681
+ InteractionContext.prototype.activityList;
662
682
  /**
663
683
  * @abstract
664
684
  * @template D, R, E
@@ -673,6 +693,16 @@ if (false) {
673
693
  * @return {?}
674
694
  */
675
695
  InteractionContext.prototype.confirm = function (confirm) { };
696
+ /**
697
+ * Presents the confirmation to the user and runs the activity only if the user confirms.
698
+ * @abstract
699
+ * @template D, R, E
700
+ * @param {?} confirm
701
+ * @param {?} activityType the activity to run if confirmed.
702
+ * @param {?=} data the activity data.
703
+ * @return {?}
704
+ */
705
+ InteractionContext.prototype.confirmThen = function (confirm, activityType, data) { };
676
706
  /**
677
707
  * @abstract
678
708
  * @param {?} alert
@@ -700,6 +730,16 @@ if (false) {
700
730
  * @return {?}
701
731
  */
702
732
  Activity.prototype.initialise = function (activityContext) { };
733
+ /**
734
+ * @param {?} result
735
+ * @return {?}
736
+ */
737
+ Activity.prototype.done = function (result) { };
738
+ /**
739
+ * @param {?} e
740
+ * @return {?}
741
+ */
742
+ Activity.prototype.cancel = function (e) { };
703
743
  }
704
744
 
705
745
  /**
@@ -760,6 +800,12 @@ class ActivityOutletComponent {
760
800
  this.activityComponentRef = this.viewContainerRef.createComponent(componentFactory, 0, injector);
761
801
  this.activityComponentRef.instance.initialise(activityContext);
762
802
  }
803
+ /**
804
+ * @return {?}
805
+ */
806
+ get component() {
807
+ return this.activityComponentRef.instance;
808
+ }
763
809
  /**
764
810
  * @param {?} alert
765
811
  * @return {?}
@@ -774,6 +820,16 @@ class ActivityOutletComponent {
774
820
  confirm(confirm) {
775
821
  return this.interactionContext.confirm(confirm);
776
822
  }
823
+ /**
824
+ * @template D1, R1, E1
825
+ * @param {?} confirm
826
+ * @param {?} activityType
827
+ * @param {?=} data
828
+ * @return {?}
829
+ */
830
+ confirmThen(confirm, activityType, data) {
831
+ return this.interactionContext.confirmThen(confirm, activityType, data);
832
+ }
777
833
  /**
778
834
  * @template D1, R1, E1
779
835
  * @param {?} activityType
@@ -809,12 +865,6 @@ ActivityOutletComponent.propDecorators = {
809
865
  interactionContext: [{ type: Input }],
810
866
  activityContext: [{ type: Input }]
811
867
  };
812
- __decorate([
813
- Trace(),
814
- __metadata("design:type", Function),
815
- __metadata("design:paramtypes", [Object]),
816
- __metadata("design:returntype", void 0)
817
- ], ActivityOutletComponent.prototype, "loadActivity", null);
818
868
  if (false) {
819
869
  /** @type {?} */
820
870
  ActivityOutletComponent.prototype.interactionContext;
@@ -840,50 +890,6 @@ if (false) {
840
890
  ActivityOutletComponent.prototype.injector;
841
891
  /* Skipping unhandled member: ;*/
842
892
  }
843
- (function (ActivityOutletComponent) {
844
- /**
845
- * @template D, R, E
846
- */
847
- class OutletInteractionContext {
848
- /**
849
- * @param {?} context
850
- */
851
- constructor(context) {
852
- this.context = context;
853
- }
854
- /**
855
- * @param {?} alert
856
- * @return {?}
857
- */
858
- alert(alert) {
859
- return lang.notImplemented();
860
- }
861
- /**
862
- * @param {?} confirm
863
- * @return {?}
864
- */
865
- confirm(confirm) {
866
- return lang.notImplemented();
867
- }
868
- /**
869
- * @template D1, R1, E1
870
- * @param {?} activityType
871
- * @param {?=} data
872
- * @return {?}
873
- */
874
- startActivity(activityType, data) {
875
- return lang.notImplemented();
876
- }
877
- }
878
- ActivityOutletComponent.OutletInteractionContext = OutletInteractionContext;
879
- if (false) {
880
- /**
881
- * @type {?}
882
- * @private
883
- */
884
- OutletInteractionContext.prototype.context;
885
- }
886
- })(ActivityOutletComponent || (ActivityOutletComponent = {}));
887
893
 
888
894
  /**
889
895
  * @fileoverview added by tsickle
@@ -945,12 +951,6 @@ class AbstractActivity extends DisposableComponent {
945
951
  return this._busyModel.value;
946
952
  }
947
953
  }
948
- __decorate([
949
- Trace(),
950
- __metadata("design:type", Function),
951
- __metadata("design:paramtypes", [Object]),
952
- __metadata("design:returntype", void 0)
953
- ], AbstractActivity.prototype, "initialise", null);
954
954
  if (false) {
955
955
  /**
956
956
  * @type {?}
@@ -998,6 +998,93 @@ if (false) {
998
998
  AlertDialogComponent.prototype.alert;
999
999
  }
1000
1000
 
1001
+ /**
1002
+ * @fileoverview added by tsickle
1003
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1004
+ */
1005
+ /**
1006
+ * @template D, R, E
1007
+ */
1008
+ class ConfirmThenDialogComponent extends AbstractActivity {
1009
+ /**
1010
+ * @param {?} config
1011
+ * @param {?} interactionContext
1012
+ */
1013
+ constructor(config, interactionContext) {
1014
+ super();
1015
+ this.config = config;
1016
+ this.interactionContext = interactionContext;
1017
+ assert.notNil(config);
1018
+ }
1019
+ /**
1020
+ * @return {?}
1021
+ */
1022
+ ngOnInit() {
1023
+ }
1024
+ /**
1025
+ * @return {?}
1026
+ */
1027
+ get confirm() {
1028
+ return this.config.confirm;
1029
+ }
1030
+ /**
1031
+ * @return {?}
1032
+ */
1033
+ isDestructive() {
1034
+ return this.confirm.destructive && this.confirm.destructive();
1035
+ }
1036
+ /**
1037
+ * @return {?}
1038
+ */
1039
+ onConfirm() {
1040
+ this.interactionContext.startActivity(this.config.activityType, this.config.data)
1041
+ .then((/**
1042
+ * @param {?} result
1043
+ * @return {?}
1044
+ */
1045
+ (result) => this.done(result)))
1046
+ .catch((/**
1047
+ * @param {?} error
1048
+ * @return {?}
1049
+ */
1050
+ error => this.cancel(error)));
1051
+ }
1052
+ }
1053
+ ConfirmThenDialogComponent.decorators = [
1054
+ { type: Component, args: [{
1055
+ selector: 'angular-ui-powerups-confirmation-dialog',
1056
+ template: "<h3 matDialogTitle *ngIf=\"confirm.title\">{{confirm.title()}}</h3>\n<div matDialogContent>\n <p *ngFor=\"let line of confirm.content()\">{{line}}</p>\n</div>\n<p matDialogActions>\n <button mat-button (click)=\"cancel()\">{{confirm.cancel()}}</button>\n <button mat-raised-button [color]=\"isDestructive() ? 'warn' : 'primary'\"\n (click)=\"onConfirm()\">{{confirm.ok()}}</button>\n</p>\n\n",
1057
+ styles: [":host{display:block;padding:var(--angular-ui-powerups-default-padding)}.mat-dialog-actions{justify-content:flex-end}"]
1058
+ }] }
1059
+ ];
1060
+ /** @nocollapse */
1061
+ ConfirmThenDialogComponent.ctorParameters = () => [
1062
+ { type: undefined, decorators: [{ type: Inject, args: [ACTIVITY_DATA,] }] },
1063
+ { type: InteractionContext }
1064
+ ];
1065
+ if (false) {
1066
+ /** @type {?} */
1067
+ ConfirmThenDialogComponent.prototype.config;
1068
+ /** @type {?} */
1069
+ ConfirmThenDialogComponent.prototype.interactionContext;
1070
+ }
1071
+ (function (ConfirmThenDialogComponent) {
1072
+ /**
1073
+ * @record
1074
+ * @template D, R, E
1075
+ */
1076
+ function Data() { }
1077
+ ConfirmThenDialogComponent.Data = Data;
1078
+ if (false) {
1079
+ /** @type {?} */
1080
+ Data.prototype.confirm;
1081
+ /** @type {?} */
1082
+ Data.prototype.activityType;
1083
+ /** @type {?} */
1084
+ Data.prototype.data;
1085
+ }
1086
+ })(ConfirmThenDialogComponent || (ConfirmThenDialogComponent = {}));
1087
+
1001
1088
  /**
1002
1089
  * @fileoverview added by tsickle
1003
1090
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -1049,6 +1136,19 @@ class ActivityContainerComponent extends DisposableComponent {
1049
1136
  this.activityOutletTabs = new MutableListModel();
1050
1137
  this.obsoleteTabs = [];
1051
1138
  this.finished = false;
1139
+ this._activityList = new MutableListModel();
1140
+ }
1141
+ /**
1142
+ * @return {?}
1143
+ */
1144
+ isActive() {
1145
+ return this.parentInteractionContext.isActive();
1146
+ }
1147
+ /**
1148
+ * @return {?}
1149
+ */
1150
+ get activityList() {
1151
+ return this._activityList.readonly;
1052
1152
  }
1053
1153
  /**
1054
1154
  * @return {?}
@@ -1060,11 +1160,39 @@ class ActivityContainerComponent extends DisposableComponent {
1060
1160
  */
1061
1161
  ngAfterViewInit() {
1062
1162
  const { observe } = Dsl.disposeWith(this);
1163
+ this._activityList.value = this.outlets.toArray().map((/**
1164
+ * @param {?} c
1165
+ * @return {?}
1166
+ */
1167
+ c => c.component));
1168
+ observe.valuesFrom(this.outlets.changes).subscribe((/**
1169
+ * @param {?} change
1170
+ * @return {?}
1171
+ */
1172
+ (change) => {
1173
+ this.safelyUpdateActivityList(change.map((/**
1174
+ * @param {?} c
1175
+ * @return {?}
1176
+ */
1177
+ c => c.component)));
1178
+ }));
1063
1179
  observe.valuesFrom(this.tabs.animationDone).subscribe((/**
1064
1180
  * @return {?}
1065
1181
  */
1066
1182
  () => this.onAnimationFinished()));
1067
1183
  }
1184
+ /**
1185
+ * Update in the next tick to avoid changing state in the current change detection cycle.
1186
+ * @private
1187
+ * @param {?} activities
1188
+ * @return {?}
1189
+ */
1190
+ safelyUpdateActivityList(activities) {
1191
+ setTimeout((/**
1192
+ * @return {?}
1193
+ */
1194
+ () => this._activityList.value = activities));
1195
+ }
1068
1196
  /**
1069
1197
  * @template D, R, E
1070
1198
  * @param {?} initialContext
@@ -1162,6 +1290,20 @@ class ActivityContainerComponent extends DisposableComponent {
1162
1290
  confirm(confirm) {
1163
1291
  return this.startActivity(ConfirmationDialogComponent, confirm);
1164
1292
  }
1293
+ /**
1294
+ * @template D, R, E
1295
+ * @param {?} confirm
1296
+ * @param {?} activityType
1297
+ * @param {?=} data
1298
+ * @return {?}
1299
+ */
1300
+ confirmThen(confirm, activityType, data) {
1301
+ return this.startActivity(ConfirmThenDialogComponent, {
1302
+ confirm,
1303
+ activityType: activityType,
1304
+ data: data
1305
+ });
1306
+ }
1165
1307
  /**
1166
1308
  * @private
1167
1309
  * @return {?}
@@ -1208,6 +1350,8 @@ if (false) {
1208
1350
  /** @type {?} */
1209
1351
  ActivityContainerComponent.prototype.initialActivityOutletContext;
1210
1352
  /** @type {?} */
1353
+ ActivityContainerComponent.prototype.currentActivity;
1354
+ /** @type {?} */
1211
1355
  ActivityContainerComponent.prototype.tabs;
1212
1356
  /** @type {?} */
1213
1357
  ActivityContainerComponent.prototype.outlets;
@@ -1223,6 +1367,11 @@ if (false) {
1223
1367
  * @private
1224
1368
  */
1225
1369
  ActivityContainerComponent.prototype.finished;
1370
+ /**
1371
+ * @type {?}
1372
+ * @private
1373
+ */
1374
+ ActivityContainerComponent.prototype._activityList;
1226
1375
  }
1227
1376
  (function (ActivityContainerComponent) {
1228
1377
  /**
@@ -1252,15 +1401,55 @@ const DIALOG_INTERACTION_SERVICE_DEFAULTS = new InjectionToken('DIALOG_INTERACTI
1252
1401
  class DialogInteractionService extends InteractionContext {
1253
1402
  /**
1254
1403
  * @param {?} dialogService
1404
+ * @param {?} router
1255
1405
  * @param {?} dialogServiceDefaults
1256
1406
  * @param {?} matDialogDefaultConfig
1257
1407
  */
1258
- constructor(dialogService, dialogServiceDefaults, matDialogDefaultConfig) {
1408
+ constructor(dialogService, router, dialogServiceDefaults, matDialogDefaultConfig) {
1259
1409
  super();
1260
1410
  this.dialogService = dialogService;
1411
+ this.router = router;
1261
1412
  this.dialogServiceDefaults = dialogServiceDefaults;
1262
1413
  this.matDialogDefaultConfig = matDialogDefaultConfig;
1414
+ this._activityList = new DelegatingListModel();
1415
+ this._active = false;
1263
1416
  assert$1.notNil(dialogService);
1417
+ const { chain, observe } = Dsl.disposeWith(this);
1418
+ this.currentActivity = chain(this.activityList).last();
1419
+ // observe.valuesFrom(this.router.events)
1420
+ // .tap((event:RouterEvent) => {
1421
+ // const nav = router.getCurrentNavigation();
1422
+ // console.log({
1423
+ // previousUrl: nav.previousNavigation && nav.previousNavigation.finalUrl,
1424
+ // initialUrl: nav.initialUrl,
1425
+ // finalUrl: nav.finalUrl,
1426
+ // });
1427
+ //
1428
+ // })
1429
+ // .filter(event => event instanceof NavigationStart)
1430
+ // .subscribe((event: NavigationStart) => {
1431
+ // console.log(event.navigationTrigger);
1432
+ // if (event.navigationTrigger === 'popstate' && this.isActive()) {
1433
+ // const prev = router.getCurrentNavigation().previousNavigation.finalUrl;
1434
+ // // this.router.navigateByUrl(prev.toString(), {
1435
+ // // replaceUrl: true,
1436
+ // // skipLocationChange: false
1437
+ // // });
1438
+ // // this.cancelActivity();
1439
+ // }
1440
+ // });
1441
+ }
1442
+ /**
1443
+ * @return {?}
1444
+ */
1445
+ cancelActivity() {
1446
+ this.currentActivity.value.cancel(null);
1447
+ }
1448
+ /**
1449
+ * @return {?}
1450
+ */
1451
+ get activityList() {
1452
+ return this._activityList.readonly;
1264
1453
  }
1265
1454
  /**
1266
1455
  * @template D, R, E
@@ -1280,8 +1469,18 @@ class DialogInteractionService extends InteractionContext {
1280
1469
  * @return {?}
1281
1470
  */
1282
1471
  _startActivity(activityType, data, disableClose = true) {
1472
+ if (this.isActive()) {
1473
+ lang.illegalState(`Activity already in progress: ${this.activityList.value.map((/**
1474
+ * @param {?} a
1475
+ * @return {?}
1476
+ */
1477
+ a => a.constructor.name)).join(', ')}`);
1478
+ }
1479
+ this._active = true;
1283
1480
  /** @type {?} */
1284
- const config = Object.assign({ autoFocus: false, hasBackdrop: true }, this.matDialogDefaultConfig, this.dialogServiceDefaults, {
1481
+ const self = this;
1482
+ /** @type {?} */
1483
+ const config = Object.assign({ autoFocus: false, hasBackdrop: true, closeOnNavigation: false }, this.matDialogDefaultConfig, this.dialogServiceDefaults, {
1285
1484
  data,
1286
1485
  disableClose,
1287
1486
  panelClass: 'dialog-interaction-service'
@@ -1297,6 +1496,7 @@ class DialogInteractionService extends InteractionContext {
1297
1496
  /** @type {?} */
1298
1497
  const activityContainer = matDialogRef.componentInstance;
1299
1498
  activityContainer.parentInteractionContext = this;
1499
+ self.safelyUpdateActivityListDelegate(activityContainer.activityList);
1300
1500
  activityContainer.initialise({
1301
1501
  activityClass: activityType,
1302
1502
  activityData: data,
@@ -1320,8 +1520,25 @@ class DialogInteractionService extends InteractionContext {
1320
1520
  }
1321
1521
  });
1322
1522
  matDialogRef.updateSize();
1523
+ })).finally((/**
1524
+ * @return {?}
1525
+ */
1526
+ () => {
1527
+ self.safelyUpdateActivityListDelegate(null);
1528
+ self._active = false;
1323
1529
  }));
1324
1530
  }
1531
+ /**
1532
+ * Updates teh delegate on the next tick to avoid modifying state during the current change detection cycle.
1533
+ * @param {?} delegate
1534
+ * @return {?}
1535
+ */
1536
+ safelyUpdateActivityListDelegate(delegate) {
1537
+ setTimeout((/**
1538
+ * @return {?}
1539
+ */
1540
+ () => this._activityList.setDelegate(delegate)));
1541
+ }
1325
1542
  /**
1326
1543
  * @param {?} alert
1327
1544
  * @return {?}
@@ -1336,6 +1553,20 @@ class DialogInteractionService extends InteractionContext {
1336
1553
  confirm(confirm) {
1337
1554
  return this._startActivity(ConfirmationDialogComponent, confirm, true);
1338
1555
  }
1556
+ /**
1557
+ * @template D, R, E
1558
+ * @param {?} confirm
1559
+ * @param {?} activityType
1560
+ * @param {?=} data
1561
+ * @return {?}
1562
+ */
1563
+ confirmThen(confirm, activityType, data) {
1564
+ return this._startActivity(ConfirmThenDialogComponent, {
1565
+ confirm,
1566
+ activityType: activityType,
1567
+ data: data
1568
+ }, true);
1569
+ }
1339
1570
  }
1340
1571
  DialogInteractionService.decorators = [
1341
1572
  { type: Injectable, args: [{
@@ -1345,16 +1576,34 @@ DialogInteractionService.decorators = [
1345
1576
  /** @nocollapse */
1346
1577
  DialogInteractionService.ctorParameters = () => [
1347
1578
  { type: MatDialog },
1579
+ { type: Router },
1348
1580
  { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [DIALOG_INTERACTION_SERVICE_DEFAULTS,] }] },
1349
1581
  { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DIALOG_DEFAULT_OPTIONS,] }] }
1350
1582
  ];
1351
- /** @nocollapse */ DialogInteractionService.ngInjectableDef = ɵɵdefineInjectable({ factory: function DialogInteractionService_Factory() { return new DialogInteractionService(ɵɵinject(MatDialog$1), ɵɵinject(DIALOG_INTERACTION_SERVICE_DEFAULTS, 8), ɵɵinject(MAT_DIALOG_DEFAULT_OPTIONS, 8)); }, token: DialogInteractionService, providedIn: "root" });
1583
+ /** @nocollapse */ DialogInteractionService.ngInjectableDef = ɵɵdefineInjectable({ factory: function DialogInteractionService_Factory() { return new DialogInteractionService(ɵɵinject(MatDialog$1), ɵɵinject(Router), ɵɵinject(DIALOG_INTERACTION_SERVICE_DEFAULTS, 8), ɵɵinject(MAT_DIALOG_DEFAULT_OPTIONS, 8)); }, token: DialogInteractionService, providedIn: "root" });
1352
1584
  if (false) {
1585
+ /** @type {?} */
1586
+ DialogInteractionService.prototype.currentActivity;
1587
+ /**
1588
+ * @type {?}
1589
+ * @private
1590
+ */
1591
+ DialogInteractionService.prototype._activityList;
1592
+ /**
1593
+ * @type {?}
1594
+ * @private
1595
+ */
1596
+ DialogInteractionService.prototype._active;
1353
1597
  /**
1354
1598
  * @type {?}
1355
1599
  * @private
1356
1600
  */
1357
1601
  DialogInteractionService.prototype.dialogService;
1602
+ /**
1603
+ * @type {?}
1604
+ * @private
1605
+ */
1606
+ DialogInteractionService.prototype.router;
1358
1607
  /** @type {?} */
1359
1608
  DialogInteractionService.prototype.dialogServiceDefaults;
1360
1609
  /** @type {?} */
@@ -1379,16 +1628,18 @@ InteractionModule.decorators = [
1379
1628
  declarations: [
1380
1629
  ActivityContainerComponent,
1381
1630
  ConfirmationDialogComponent,
1631
+ ConfirmThenDialogComponent,
1382
1632
  AlertDialogComponent,
1383
1633
  ActivityOutletComponent
1384
1634
  ],
1385
1635
  exports: [
1386
1636
  ActivityContainerComponent,
1387
- ActivityOutletComponent
1637
+ ActivityOutletComponent,
1388
1638
  ],
1389
1639
  entryComponents: [
1390
1640
  ActivityContainerComponent,
1391
1641
  ConfirmationDialogComponent,
1642
+ ConfirmThenDialogComponent,
1392
1643
  AlertDialogComponent
1393
1644
  ],
1394
1645
  providers: [
@@ -3456,6 +3707,62 @@ if (false) {
3456
3707
  ActivityOutletContext.prototype.onCancel;
3457
3708
  }
3458
3709
 
3710
+ /**
3711
+ * @fileoverview added by tsickle
3712
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3713
+ */
3714
+ class CloseInteractionGuard {
3715
+ /**
3716
+ * @param {?} router
3717
+ * @param {?} injector
3718
+ * @param {?} interactionContext
3719
+ */
3720
+ constructor(router, injector, interactionContext) {
3721
+ this.router = router;
3722
+ this.injector = injector;
3723
+ this.interactionContext = interactionContext;
3724
+ }
3725
+ /**
3726
+ * @param {?} component
3727
+ * @param {?} currentRoute
3728
+ * @param {?} currentState
3729
+ * @param {?=} nextState
3730
+ * @return {?}
3731
+ */
3732
+ canDeactivate(component, currentRoute, currentState, nextState) {
3733
+ return !this.interactionContext.isActive();
3734
+ }
3735
+ }
3736
+ CloseInteractionGuard.decorators = [
3737
+ { type: Injectable, args: [{
3738
+ providedIn: 'root'
3739
+ },] }
3740
+ ];
3741
+ /** @nocollapse */
3742
+ CloseInteractionGuard.ctorParameters = () => [
3743
+ { type: Router },
3744
+ { type: Injector },
3745
+ { type: InteractionContext }
3746
+ ];
3747
+ /** @nocollapse */ CloseInteractionGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function CloseInteractionGuard_Factory() { return new CloseInteractionGuard(ɵɵinject(Router), ɵɵinject(INJECTOR), ɵɵinject(InteractionContext)); }, token: CloseInteractionGuard, providedIn: "root" });
3748
+ if (false) {
3749
+ /**
3750
+ * @type {?}
3751
+ * @private
3752
+ */
3753
+ CloseInteractionGuard.prototype.router;
3754
+ /**
3755
+ * @type {?}
3756
+ * @private
3757
+ */
3758
+ CloseInteractionGuard.prototype.injector;
3759
+ /**
3760
+ * @type {?}
3761
+ * @private
3762
+ */
3763
+ CloseInteractionGuard.prototype.interactionContext;
3764
+ }
3765
+
3459
3766
  /**
3460
3767
  * @fileoverview added by tsickle
3461
3768
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3560,10 +3867,36 @@ class LeavePlaceGuard {
3560
3867
  /**
3561
3868
  * @param {?} router
3562
3869
  * @param {?} injector
3870
+ * @param {?} interactionContext
3871
+ * @param {?} location
3563
3872
  */
3564
- constructor(router, injector) {
3873
+ constructor(router, injector, interactionContext, location) {
3565
3874
  this.router = router;
3566
3875
  this.injector = injector;
3876
+ this.interactionContext = interactionContext;
3877
+ this.location = location;
3878
+ // TODO: should probably replace this with a RouteTracker thingy.
3879
+ this._alreadyAccepted = [];
3880
+ console.log('***** Created new guard ******');
3881
+ /** @type {?} */
3882
+ const self = this;
3883
+ this.router.events.subscribe((/**
3884
+ * @param {?} event
3885
+ * @return {?}
3886
+ */
3887
+ event => {
3888
+ // NavigationStart -> .... -> NavigationCancel === redirect (so don't ask again)
3889
+ // NavigationStart -> .... -> NavigationEnd === navigated (so ask next time)
3890
+ // NavigationStart -> .... -> NavigationError === canceled (guard cancelled so ask next time)
3891
+ if (event instanceof NavigationEnd) {
3892
+ console.log("navigation ended");
3893
+ self._alreadyAccepted = [];
3894
+ }
3895
+ if (event instanceof NavigationError) {
3896
+ console.log("navigation errored");
3897
+ self._alreadyAccepted = [];
3898
+ }
3899
+ }));
3567
3900
  }
3568
3901
  /**
3569
3902
  * @param {?} component
@@ -3573,27 +3906,85 @@ class LeavePlaceGuard {
3573
3906
  * @return {?}
3574
3907
  */
3575
3908
  canDeactivate(component, currentRoute, currentState, nextState) {
3576
- // HACK: this will break with child routes...
3577
3909
  /** @type {?} */
3578
- const path = `/${component.placeDefinition.path}`;
3579
- // let thisTree = this.router.parseUrl(currentState.url);
3580
- // let nextTree = this.router.parseUrl(nextState.url);
3581
- // console.log({
3582
- // placePath: path,
3583
- // currentRoute: currentRoute.toString(),
3584
- // currentStateUrl: currentState.url,
3585
- // nextStateUrl: nextState.url,
3586
- // currentStateUrlTree: thisTree.root.children[PRIMARY_OUTLET].segments,
3587
- // nextStateUrlTree: nextTree.root.children[PRIMARY_OUTLET].segments
3588
- // });
3589
- // nextState is the full path...
3590
- if (!nextState.url.startsWith(path)) {
3591
- return component.canDeactivate();
3910
+ const placeDefinitionPath = `/${component.placeDefinition.path}`;
3911
+ console.log('canDeactivate', {
3912
+ staticPath: placeDefinitionPath,
3913
+ currentStateUrl: currentState.url,
3914
+ nextStateUrl: nextState.url,
3915
+ alreadyDeclined: this._alreadyAccepted
3916
+ });
3917
+ // Example of the above when navigating to a different child route.
3918
+ // canDeactivate {staticPath: "/hero-details",
3919
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-details",
3920
+ // nextStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats"
3921
+ // }
3922
+ // Example clicking on router tab of the parent component (de-activates the parent due to route param changes)
3923
+ // canDeactivate {
3924
+ // staticPath: "/hero-stats",
3925
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3926
+ // nextStateUrl: "/route-parameters/"
3927
+ // }
3928
+ // canDeactivate {
3929
+ // staticPath: "/route-parameters",
3930
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3931
+ // nextStateUrl: "/route-parameters/"
3932
+ // }
3933
+ // logger.class.js:54 ParameterSnapshot.sanitise -> {idModel: -1, pv: undefined, pl: Array(0), dv: undefined, dl: Array(0), …}
3934
+ // parameter-snapshot.ts:20 {name: "idModel", mine: -1, theirs: null}
3935
+ // place-router.ts:28 redirect path (3) ["route-parameters", "-1", {…}]
3936
+ // canDeactivate {
3937
+ // staticPath: "/hero-stats",
3938
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3939
+ // nextStateUrl: "/route-parameters/-1"
3940
+ // }
3941
+ // canDeactivate {
3942
+ // staticPath: "/route-parameters",
3943
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3944
+ // nextStateUrl: "/route-parameters/-1"
3945
+ // }
3946
+ // logger.class.js:54 ParameterSnapshot.sanitise -> {idModel: -1, pv: undefined, pl: Array(0), dv: "A", dl: Array(3), …}
3947
+ // parameter-snapshot.ts:20 {name: "dv", mine: "A", theirs: undefined}
3948
+ // place-router.ts:28 redirect path (3) ["route-parameters", "-1", {…}]
3949
+ // canDeactivate {
3950
+ // staticPath: "/hero-stats",
3951
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3952
+ // nextStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c"
3953
+ // }
3954
+ // HACK: this will break with child routes...
3955
+ if (this.alreadyAccepted(component)) {
3956
+ return true;
3592
3957
  }
3593
3958
  else {
3959
+ if (!nextState.url.startsWith(placeDefinitionPath)) {
3960
+ /** @type {?} */
3961
+ const self = this;
3962
+ return Promise.resolve(component.canDeactivate()).then((/**
3963
+ * @param {?} canLeave
3964
+ * @return {?}
3965
+ */
3966
+ canLeave => {
3967
+ if (!canLeave) {
3968
+ // Angular doesn't preserve the url when a guard cancels the back button.
3969
+ // See https://github.com/angular/angular/issues/13586#issuecomment-432795720
3970
+ this.location.go(currentState.url);
3971
+ }
3972
+ else {
3973
+ self._alreadyAccepted.push(component);
3974
+ }
3975
+ return canLeave;
3976
+ }));
3977
+ }
3594
3978
  return true;
3595
3979
  }
3596
3980
  }
3981
+ /**
3982
+ * @param {?} placeComponent
3983
+ * @return {?}
3984
+ */
3985
+ alreadyAccepted(placeComponent) {
3986
+ return this._alreadyAccepted.includes(placeComponent);
3987
+ }
3597
3988
  }
3598
3989
  LeavePlaceGuard.decorators = [
3599
3990
  { type: Injectable, args: [{
@@ -3603,10 +3994,23 @@ LeavePlaceGuard.decorators = [
3603
3994
  /** @nocollapse */
3604
3995
  LeavePlaceGuard.ctorParameters = () => [
3605
3996
  { type: Router },
3606
- { type: Injector }
3997
+ { type: Injector },
3998
+ { type: InteractionContext },
3999
+ { type: Location }
3607
4000
  ];
3608
- /** @nocollapse */ LeavePlaceGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function LeavePlaceGuard_Factory() { return new LeavePlaceGuard(ɵɵinject(Router), ɵɵinject(INJECTOR)); }, token: LeavePlaceGuard, providedIn: "root" });
4001
+ /** @nocollapse */ LeavePlaceGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function LeavePlaceGuard_Factory() { return new LeavePlaceGuard(ɵɵinject(Router), ɵɵinject(INJECTOR), ɵɵinject(InteractionContext), ɵɵinject(Location)); }, token: LeavePlaceGuard, providedIn: "root" });
4002
+ __decorate([
4003
+ Trace(),
4004
+ __metadata("design:type", Function),
4005
+ __metadata("design:paramtypes", [PlaceComponent]),
4006
+ __metadata("design:returntype", Boolean)
4007
+ ], LeavePlaceGuard.prototype, "alreadyAccepted", null);
3609
4008
  if (false) {
4009
+ /**
4010
+ * @type {?}
4011
+ * @private
4012
+ */
4013
+ LeavePlaceGuard.prototype._alreadyAccepted;
3610
4014
  /**
3611
4015
  * @type {?}
3612
4016
  * @private
@@ -3617,6 +4021,10 @@ if (false) {
3617
4021
  * @private
3618
4022
  */
3619
4023
  LeavePlaceGuard.prototype.injector;
4024
+ /** @type {?} */
4025
+ LeavePlaceGuard.prototype.interactionContext;
4026
+ /** @type {?} */
4027
+ LeavePlaceGuard.prototype.location;
3620
4028
  }
3621
4029
 
3622
4030
  /**
@@ -3889,5 +4297,5 @@ var ParameterType;
3889
4297
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3890
4298
  */
3891
4299
 
3892
- export { ACTIVITY_DATA, AbstractActivity, AbstractInputComponent, AbstractPlaceNavigationComponent, ActivityContainerComponent, ActivityOutletComponent, AlertDialogComponent, AngularUiPowerupsModule, Bounds, BusyOverlayComponent, CommandDirective, ConfirmationDialogComponent, DEFINITION_META_DATA_KEY, DIALOG_INTERACTION_SERVICE_DEFAULTS, DialogInteractionService, Dimension, DisposableComponent, EmptyStateComponent, FocusBindingDirective, INTERACTION_CONTEXT, InteractionContext, InteractionModule, LEFT_RIGHT_PLACE_ANIMATION, LeavePlaceGuard, ListPlaceNavComponent, NumberInputComponent, ParameterDefinition, ParameterSnapshot, ParameterType, PasswordInputComponent, Place, PlaceComponent, PlaceDefinition, PlaceHistory, PlaceModule, PlaceOutletComponent, PlaceRouteGuard, PlaceRouter, Point, ROUTE_PARAMETER_LIST_KEY, ResizeAwareComponent, RouteId, RouteParameter, RouteParameterList, RouteParameterValue, SelectInputComponent, StringInputComponent, TabbedPlaceNavigationComponent, leftRightPlaceAnimation, slideDownAndUpAnimation, CommandDirective as ɵa, FocusBindingDirective as ɵb, AlertDialogComponent as ɵba, DIALOG_INTERACTION_SERVICE_DEFAULTS as ɵbc, DialogInteractionService as ɵbd, InteractionContext as ɵbe, DisposableComponent as ɵc, NumberInputComponent as ɵd, AbstractInputComponent as ɵe, StringInputComponent as ɵf, PasswordInputComponent as ɵg, SelectInputComponent as ɵh, PlaceModule as ɵi, EmptyStateComponent as ɵj, BusyOverlayComponent as ɵk, PlaceOutletComponent as ɵl, leftRightPlaceAnimation as ɵm, LEFT_RIGHT_PLACE_ANIMATION as ɵn, PlaceRouter as ɵo, PlaceHistory as ɵp, TabbedPlaceNavigationComponent as ɵq, AbstractPlaceNavigationComponent as ɵr, ListPlaceNavComponent as ɵs, InteractionModule as ɵt, ActivityContainerComponent as ɵu, ActivityOutletComponent as ɵv, ConfirmationDialogComponent as ɵw, AbstractActivity as ɵx, ACTIVITY_DATA as ɵy };
4300
+ export { ACTIVITY_DATA, AbstractActivity, AbstractInputComponent, AbstractPlaceNavigationComponent, ActivityContainerComponent, ActivityOutletComponent, AlertDialogComponent, AngularUiPowerupsModule, Bounds, BusyOverlayComponent, CloseInteractionGuard, CommandDirective, ConfirmThenDialogComponent, ConfirmationDialogComponent, DEFINITION_META_DATA_KEY, DIALOG_INTERACTION_SERVICE_DEFAULTS, DialogInteractionService, Dimension, DisposableComponent, EmptyStateComponent, FocusBindingDirective, InteractionContext, InteractionModule, LEFT_RIGHT_PLACE_ANIMATION, LeavePlaceGuard, ListPlaceNavComponent, NumberInputComponent, ParameterDefinition, ParameterSnapshot, ParameterType, PasswordInputComponent, Place, PlaceComponent, PlaceDefinition, PlaceHistory, PlaceModule, PlaceOutletComponent, PlaceRouteGuard, PlaceRouter, Point, ROUTE_PARAMETER_LIST_KEY, ResizeAwareComponent, RouteId, RouteParameter, RouteParameterList, RouteParameterValue, SelectInputComponent, StringInputComponent, TabbedPlaceNavigationComponent, leftRightPlaceAnimation, slideDownAndUpAnimation, CommandDirective as ɵa, FocusBindingDirective as ɵb, ConfirmThenDialogComponent as ɵba, InteractionContext as ɵbb, AlertDialogComponent as ɵbc, DIALOG_INTERACTION_SERVICE_DEFAULTS as ɵbe, DialogInteractionService as ɵbf, DisposableComponent as ɵc, NumberInputComponent as ɵd, AbstractInputComponent as ɵe, StringInputComponent as ɵf, PasswordInputComponent as ɵg, SelectInputComponent as ɵh, PlaceModule as ɵi, EmptyStateComponent as ɵj, BusyOverlayComponent as ɵk, PlaceOutletComponent as ɵl, leftRightPlaceAnimation as ɵm, LEFT_RIGHT_PLACE_ANIMATION as ɵn, PlaceRouter as ɵo, PlaceHistory as ɵp, TabbedPlaceNavigationComponent as ɵq, AbstractPlaceNavigationComponent as ɵr, ListPlaceNavComponent as ɵs, InteractionModule as ɵt, ActivityContainerComponent as ɵu, ActivityOutletComponent as ɵv, ConfirmationDialogComponent as ɵw, AbstractActivity as ɵx, ACTIVITY_DATA as ɵy };
3893
4301
  //# sourceMappingURL=coolon-angular-ui-powerups.js.map