@coolon/angular-ui-powerups 0.0.61 → 0.0.63

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 (40) hide show
  1. package/bundles/coolon-angular-ui-powerups.umd.js +414 -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.metadata.json +1 -1
  6. package/esm2015/coolon-angular-ui-powerups.js +2 -2
  7. package/esm2015/index.js +2 -2
  8. package/esm2015/lib/interaction/activity.js +11 -1
  9. package/esm2015/lib/interaction/components/activity-container/activity-container.component.js +49 -1
  10. package/esm2015/lib/interaction/components/activity-outlet/activity-outlet.component.js +7 -56
  11. package/esm2015/lib/interaction/guards/close-interaction.guard.js +62 -0
  12. package/esm2015/lib/interaction/index.js +3 -2
  13. package/esm2015/lib/interaction/interaction-context.js +24 -5
  14. package/esm2015/lib/interaction/services/dialog-interaction.service.js +77 -4
  15. package/esm2015/lib/place/guards/leave-place.guard.js +144 -20
  16. package/esm2015/public_api.js +2 -2
  17. package/esm5/coolon-angular-ui-powerups.js +2 -2
  18. package/esm5/index.js +2 -2
  19. package/esm5/lib/interaction/activity.js +11 -1
  20. package/esm5/lib/interaction/components/activity-container/activity-container.component.js +67 -1
  21. package/esm5/lib/interaction/components/activity-outlet/activity-outlet.component.js +11 -78
  22. package/esm5/lib/interaction/guards/close-interaction.guard.js +66 -0
  23. package/esm5/lib/interaction/index.js +3 -2
  24. package/esm5/lib/interaction/interaction-context.js +25 -6
  25. package/esm5/lib/interaction/services/dialog-interaction.service.js +96 -4
  26. package/esm5/lib/place/guards/leave-place.guard.js +147 -20
  27. package/esm5/public_api.js +2 -2
  28. package/fesm2015/coolon-angular-ui-powerups.js +354 -82
  29. package/fesm2015/coolon-angular-ui-powerups.js.map +1 -1
  30. package/fesm5/coolon-angular-ui-powerups.js +401 -105
  31. package/fesm5/coolon-angular-ui-powerups.js.map +1 -1
  32. package/lib/interaction/activity.d.ts +2 -0
  33. package/lib/interaction/components/activity-container/activity-container.component.d.ts +10 -1
  34. package/lib/interaction/components/activity-outlet/activity-outlet.component.d.ts +2 -9
  35. package/lib/interaction/guards/close-interaction.guard.d.ts +12 -0
  36. package/lib/interaction/index.d.ts +1 -0
  37. package/lib/interaction/interaction-context.d.ts +17 -4
  38. package/lib/interaction/services/dialog-interaction.service.d.ts +15 -2
  39. package/lib/place/guards/leave-place.guard.d.ts +7 -1
  40. 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, 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,33 @@ 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
+ }
660
661
  }
661
662
  if (false) {
663
+ /**
664
+ * Returns the activity that is currently active.
665
+ * This model is only updated in the next tick after the view has been updated.
666
+ * @type {?}
667
+ */
668
+ InteractionContext.prototype.currentActivity;
669
+ /**
670
+ * Returns the current list of activities that are in progress.
671
+ * This model is only updated in the next tick after the view has been updated.
672
+ * @type {?}
673
+ */
674
+ InteractionContext.prototype.activityList;
675
+ /**
676
+ * Returns true if an activity is currently running.
677
+ * @abstract
678
+ * @return {?}
679
+ */
680
+ InteractionContext.prototype.isActive = function () { };
662
681
  /**
663
682
  * @abstract
664
683
  * @template D, R, E
@@ -710,6 +729,16 @@ if (false) {
710
729
  * @return {?}
711
730
  */
712
731
  Activity.prototype.initialise = function (activityContext) { };
732
+ /**
733
+ * @param {?} result
734
+ * @return {?}
735
+ */
736
+ Activity.prototype.done = function (result) { };
737
+ /**
738
+ * @param {?} e
739
+ * @return {?}
740
+ */
741
+ Activity.prototype.cancel = function (e) { };
713
742
  }
714
743
 
715
744
  /**
@@ -770,6 +799,12 @@ class ActivityOutletComponent {
770
799
  this.activityComponentRef = this.viewContainerRef.createComponent(componentFactory, 0, injector);
771
800
  this.activityComponentRef.instance.initialise(activityContext);
772
801
  }
802
+ /**
803
+ * @return {?}
804
+ */
805
+ get component() {
806
+ return this.activityComponentRef.instance;
807
+ }
773
808
  /**
774
809
  * @param {?} alert
775
810
  * @return {?}
@@ -854,60 +889,6 @@ if (false) {
854
889
  ActivityOutletComponent.prototype.injector;
855
890
  /* Skipping unhandled member: ;*/
856
891
  }
857
- (function (ActivityOutletComponent) {
858
- /**
859
- * @template D, R, E
860
- */
861
- class OutletInteractionContext {
862
- /**
863
- * @param {?} context
864
- */
865
- constructor(context) {
866
- this.context = context;
867
- }
868
- /**
869
- * @param {?} alert
870
- * @return {?}
871
- */
872
- alert(alert) {
873
- return lang.notImplemented();
874
- }
875
- /**
876
- * @param {?} confirm
877
- * @return {?}
878
- */
879
- confirm(confirm) {
880
- return lang.notImplemented();
881
- }
882
- /**
883
- * @template D1, R1, E1
884
- * @param {?} confirm
885
- * @param {?} activityType
886
- * @param {?=} data
887
- * @return {?}
888
- */
889
- confirmThen(confirm, activityType, data) {
890
- return lang.notImplemented();
891
- }
892
- /**
893
- * @template D1, R1, E1
894
- * @param {?} activityType
895
- * @param {?=} data
896
- * @return {?}
897
- */
898
- startActivity(activityType, data) {
899
- return lang.notImplemented();
900
- }
901
- }
902
- ActivityOutletComponent.OutletInteractionContext = OutletInteractionContext;
903
- if (false) {
904
- /**
905
- * @type {?}
906
- * @private
907
- */
908
- OutletInteractionContext.prototype.context;
909
- }
910
- })(ActivityOutletComponent || (ActivityOutletComponent = {}));
911
892
 
912
893
  /**
913
894
  * @fileoverview added by tsickle
@@ -1154,6 +1135,19 @@ class ActivityContainerComponent extends DisposableComponent {
1154
1135
  this.activityOutletTabs = new MutableListModel();
1155
1136
  this.obsoleteTabs = [];
1156
1137
  this.finished = false;
1138
+ this._activityList = new MutableListModel();
1139
+ }
1140
+ /**
1141
+ * @return {?}
1142
+ */
1143
+ isActive() {
1144
+ return this.parentInteractionContext.isActive();
1145
+ }
1146
+ /**
1147
+ * @return {?}
1148
+ */
1149
+ get activityList() {
1150
+ return this._activityList.readonly;
1157
1151
  }
1158
1152
  /**
1159
1153
  * @return {?}
@@ -1165,11 +1159,39 @@ class ActivityContainerComponent extends DisposableComponent {
1165
1159
  */
1166
1160
  ngAfterViewInit() {
1167
1161
  const { observe } = Dsl.disposeWith(this);
1162
+ this._activityList.value = this.outlets.toArray().map((/**
1163
+ * @param {?} c
1164
+ * @return {?}
1165
+ */
1166
+ c => c.component));
1167
+ observe.valuesFrom(this.outlets.changes).subscribe((/**
1168
+ * @param {?} change
1169
+ * @return {?}
1170
+ */
1171
+ (change) => {
1172
+ this.safelyUpdateActivityList(change.map((/**
1173
+ * @param {?} c
1174
+ * @return {?}
1175
+ */
1176
+ c => c.component)));
1177
+ }));
1168
1178
  observe.valuesFrom(this.tabs.animationDone).subscribe((/**
1169
1179
  * @return {?}
1170
1180
  */
1171
1181
  () => this.onAnimationFinished()));
1172
1182
  }
1183
+ /**
1184
+ * Update in the next tick to avoid changing state in the current change detection cycle.
1185
+ * @private
1186
+ * @param {?} activities
1187
+ * @return {?}
1188
+ */
1189
+ safelyUpdateActivityList(activities) {
1190
+ setTimeout((/**
1191
+ * @return {?}
1192
+ */
1193
+ () => this._activityList.value = activities));
1194
+ }
1173
1195
  /**
1174
1196
  * @template D, R, E
1175
1197
  * @param {?} initialContext
@@ -1327,6 +1349,8 @@ if (false) {
1327
1349
  /** @type {?} */
1328
1350
  ActivityContainerComponent.prototype.initialActivityOutletContext;
1329
1351
  /** @type {?} */
1352
+ ActivityContainerComponent.prototype.currentActivity;
1353
+ /** @type {?} */
1330
1354
  ActivityContainerComponent.prototype.tabs;
1331
1355
  /** @type {?} */
1332
1356
  ActivityContainerComponent.prototype.outlets;
@@ -1342,6 +1366,11 @@ if (false) {
1342
1366
  * @private
1343
1367
  */
1344
1368
  ActivityContainerComponent.prototype.finished;
1369
+ /**
1370
+ * @type {?}
1371
+ * @private
1372
+ */
1373
+ ActivityContainerComponent.prototype._activityList;
1345
1374
  }
1346
1375
  (function (ActivityContainerComponent) {
1347
1376
  /**
@@ -1371,15 +1400,39 @@ const DIALOG_INTERACTION_SERVICE_DEFAULTS = new InjectionToken('DIALOG_INTERACTI
1371
1400
  class DialogInteractionService extends InteractionContext {
1372
1401
  /**
1373
1402
  * @param {?} dialogService
1403
+ * @param {?} router
1374
1404
  * @param {?} dialogServiceDefaults
1375
1405
  * @param {?} matDialogDefaultConfig
1376
1406
  */
1377
- constructor(dialogService, dialogServiceDefaults, matDialogDefaultConfig) {
1407
+ constructor(dialogService, router, dialogServiceDefaults, matDialogDefaultConfig) {
1378
1408
  super();
1379
1409
  this.dialogService = dialogService;
1410
+ this.router = router;
1380
1411
  this.dialogServiceDefaults = dialogServiceDefaults;
1381
1412
  this.matDialogDefaultConfig = matDialogDefaultConfig;
1413
+ this._activityList = new DelegatingListModel();
1414
+ this._active = false;
1382
1415
  assert$1.notNil(dialogService);
1416
+ const { chain, observe } = Dsl.disposeWith(this);
1417
+ this.currentActivity = chain(this.activityList).last();
1418
+ }
1419
+ /**
1420
+ * @return {?}
1421
+ */
1422
+ isActive() {
1423
+ return this._active;
1424
+ }
1425
+ /**
1426
+ * @return {?}
1427
+ */
1428
+ cancelActivity() {
1429
+ this.currentActivity.value.cancel(null);
1430
+ }
1431
+ /**
1432
+ * @return {?}
1433
+ */
1434
+ get activityList() {
1435
+ return this._activityList.readonly;
1383
1436
  }
1384
1437
  /**
1385
1438
  * @template D, R, E
@@ -1399,8 +1452,18 @@ class DialogInteractionService extends InteractionContext {
1399
1452
  * @return {?}
1400
1453
  */
1401
1454
  _startActivity(activityType, data, disableClose = true) {
1455
+ if (this.isActive()) {
1456
+ lang.illegalState(`Activity already in progress: ${this.activityList.value.map((/**
1457
+ * @param {?} a
1458
+ * @return {?}
1459
+ */
1460
+ a => a.constructor.name)).join(', ')}`);
1461
+ }
1462
+ this._active = true;
1463
+ /** @type {?} */
1464
+ const self = this;
1402
1465
  /** @type {?} */
1403
- const config = Object.assign({ autoFocus: false, hasBackdrop: true }, this.matDialogDefaultConfig, this.dialogServiceDefaults, {
1466
+ const config = Object.assign({ autoFocus: false, hasBackdrop: true, closeOnNavigation: false }, this.matDialogDefaultConfig, this.dialogServiceDefaults, {
1404
1467
  data,
1405
1468
  disableClose,
1406
1469
  panelClass: 'dialog-interaction-service'
@@ -1416,6 +1479,7 @@ class DialogInteractionService extends InteractionContext {
1416
1479
  /** @type {?} */
1417
1480
  const activityContainer = matDialogRef.componentInstance;
1418
1481
  activityContainer.parentInteractionContext = this;
1482
+ self.safelyUpdateActivityListDelegate(activityContainer.activityList);
1419
1483
  activityContainer.initialise({
1420
1484
  activityClass: activityType,
1421
1485
  activityData: data,
@@ -1439,8 +1503,25 @@ class DialogInteractionService extends InteractionContext {
1439
1503
  }
1440
1504
  });
1441
1505
  matDialogRef.updateSize();
1506
+ })).finally((/**
1507
+ * @return {?}
1508
+ */
1509
+ () => {
1510
+ self.safelyUpdateActivityListDelegate(null);
1511
+ self._active = false;
1442
1512
  }));
1443
1513
  }
1514
+ /**
1515
+ * Updates teh delegate on the next tick to avoid modifying state during the current change detection cycle.
1516
+ * @param {?} delegate
1517
+ * @return {?}
1518
+ */
1519
+ safelyUpdateActivityListDelegate(delegate) {
1520
+ setTimeout((/**
1521
+ * @return {?}
1522
+ */
1523
+ () => this._activityList.setDelegate(delegate)));
1524
+ }
1444
1525
  /**
1445
1526
  * @param {?} alert
1446
1527
  * @return {?}
@@ -1478,16 +1559,34 @@ DialogInteractionService.decorators = [
1478
1559
  /** @nocollapse */
1479
1560
  DialogInteractionService.ctorParameters = () => [
1480
1561
  { type: MatDialog },
1562
+ { type: Router },
1481
1563
  { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [DIALOG_INTERACTION_SERVICE_DEFAULTS,] }] },
1482
1564
  { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DIALOG_DEFAULT_OPTIONS,] }] }
1483
1565
  ];
1484
- /** @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" });
1566
+ /** @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" });
1485
1567
  if (false) {
1568
+ /** @type {?} */
1569
+ DialogInteractionService.prototype.currentActivity;
1570
+ /**
1571
+ * @type {?}
1572
+ * @private
1573
+ */
1574
+ DialogInteractionService.prototype._activityList;
1575
+ /**
1576
+ * @type {?}
1577
+ * @private
1578
+ */
1579
+ DialogInteractionService.prototype._active;
1486
1580
  /**
1487
1581
  * @type {?}
1488
1582
  * @private
1489
1583
  */
1490
1584
  DialogInteractionService.prototype.dialogService;
1585
+ /**
1586
+ * @type {?}
1587
+ * @private
1588
+ */
1589
+ DialogInteractionService.prototype.router;
1491
1590
  /** @type {?} */
1492
1591
  DialogInteractionService.prototype.dialogServiceDefaults;
1493
1592
  /** @type {?} */
@@ -3591,6 +3690,62 @@ if (false) {
3591
3690
  ActivityOutletContext.prototype.onCancel;
3592
3691
  }
3593
3692
 
3693
+ /**
3694
+ * @fileoverview added by tsickle
3695
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3696
+ */
3697
+ class CloseInteractionGuard {
3698
+ /**
3699
+ * @param {?} router
3700
+ * @param {?} injector
3701
+ * @param {?} interactionContext
3702
+ */
3703
+ constructor(router, injector, interactionContext) {
3704
+ this.router = router;
3705
+ this.injector = injector;
3706
+ this.interactionContext = interactionContext;
3707
+ }
3708
+ /**
3709
+ * @param {?} component
3710
+ * @param {?} currentRoute
3711
+ * @param {?} currentState
3712
+ * @param {?=} nextState
3713
+ * @return {?}
3714
+ */
3715
+ canDeactivate(component, currentRoute, currentState, nextState) {
3716
+ return !this.interactionContext.isActive();
3717
+ }
3718
+ }
3719
+ CloseInteractionGuard.decorators = [
3720
+ { type: Injectable, args: [{
3721
+ providedIn: 'root'
3722
+ },] }
3723
+ ];
3724
+ /** @nocollapse */
3725
+ CloseInteractionGuard.ctorParameters = () => [
3726
+ { type: Router },
3727
+ { type: Injector },
3728
+ { type: InteractionContext }
3729
+ ];
3730
+ /** @nocollapse */ CloseInteractionGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function CloseInteractionGuard_Factory() { return new CloseInteractionGuard(ɵɵinject(Router), ɵɵinject(INJECTOR), ɵɵinject(InteractionContext)); }, token: CloseInteractionGuard, providedIn: "root" });
3731
+ if (false) {
3732
+ /**
3733
+ * @type {?}
3734
+ * @private
3735
+ */
3736
+ CloseInteractionGuard.prototype.router;
3737
+ /**
3738
+ * @type {?}
3739
+ * @private
3740
+ */
3741
+ CloseInteractionGuard.prototype.injector;
3742
+ /**
3743
+ * @type {?}
3744
+ * @private
3745
+ */
3746
+ CloseInteractionGuard.prototype.interactionContext;
3747
+ }
3748
+
3594
3749
  /**
3595
3750
  * @fileoverview added by tsickle
3596
3751
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3695,10 +3850,36 @@ class LeavePlaceGuard {
3695
3850
  /**
3696
3851
  * @param {?} router
3697
3852
  * @param {?} injector
3853
+ * @param {?} interactionContext
3854
+ * @param {?} location
3698
3855
  */
3699
- constructor(router, injector) {
3856
+ constructor(router, injector, interactionContext, location) {
3700
3857
  this.router = router;
3701
3858
  this.injector = injector;
3859
+ this.interactionContext = interactionContext;
3860
+ this.location = location;
3861
+ // TODO: should probably replace this with a RouteTracker thingy.
3862
+ this._alreadyAccepted = [];
3863
+ console.log('***** Created new guard ******');
3864
+ /** @type {?} */
3865
+ const self = this;
3866
+ this.router.events.subscribe((/**
3867
+ * @param {?} event
3868
+ * @return {?}
3869
+ */
3870
+ event => {
3871
+ // NavigationStart -> .... -> NavigationCancel === redirect (so don't ask again)
3872
+ // NavigationStart -> .... -> NavigationEnd === navigated (so ask next time)
3873
+ // NavigationStart -> .... -> NavigationError === canceled (guard cancelled so ask next time)
3874
+ if (event instanceof NavigationEnd) {
3875
+ console.log('navigation ended');
3876
+ self._alreadyAccepted = [];
3877
+ }
3878
+ if (event instanceof NavigationError) {
3879
+ console.log('navigation errored');
3880
+ self._alreadyAccepted = [];
3881
+ }
3882
+ }));
3702
3883
  }
3703
3884
  /**
3704
3885
  * @param {?} component
@@ -3708,27 +3889,101 @@ class LeavePlaceGuard {
3708
3889
  * @return {?}
3709
3890
  */
3710
3891
  canDeactivate(component, currentRoute, currentState, nextState) {
3711
- // HACK: this will break with child routes...
3712
3892
  /** @type {?} */
3713
- const path = `/${component.placeDefinition.path}`;
3714
- // let thisTree = this.router.parseUrl(currentState.url);
3715
- // let nextTree = this.router.parseUrl(nextState.url);
3716
- // console.log({
3717
- // placePath: path,
3718
- // currentRoute: currentRoute.toString(),
3719
- // currentStateUrl: currentState.url,
3720
- // nextStateUrl: nextState.url,
3721
- // currentStateUrlTree: thisTree.root.children[PRIMARY_OUTLET].segments,
3722
- // nextStateUrlTree: nextTree.root.children[PRIMARY_OUTLET].segments
3723
- // });
3724
- // nextState is the full path...
3725
- if (!nextState.url.startsWith(path)) {
3726
- return component.canDeactivate();
3893
+ const placeDefinitionPath = `/${component.placeDefinition.path}`;
3894
+ console.log('canDeactivate', {
3895
+ staticPath: placeDefinitionPath,
3896
+ currentStateUrl: currentState.url,
3897
+ nextStateUrl: nextState.url,
3898
+ alreadyDeclined: this._alreadyAccepted
3899
+ });
3900
+ // Example of the above when navigating to a different child route.
3901
+ // canDeactivate {staticPath: "/hero-details",
3902
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-details",
3903
+ // nextStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats"
3904
+ // }
3905
+ // Example clicking on router tab of the parent component (de-activates the parent due to route param changes)
3906
+ // canDeactivate {
3907
+ // staticPath: "/hero-stats",
3908
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3909
+ // nextStateUrl: "/route-parameters/"
3910
+ // }
3911
+ // canDeactivate {
3912
+ // staticPath: "/route-parameters",
3913
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3914
+ // nextStateUrl: "/route-parameters/"
3915
+ // }
3916
+ // logger.class.js:54 ParameterSnapshot.sanitise -> {idModel: -1, pv: undefined, pl: Array(0), dv: undefined, dl: Array(0), …}
3917
+ // parameter-snapshot.ts:20 {name: "idModel", mine: -1, theirs: null}
3918
+ // place-router.ts:28 redirect path (3) ["route-parameters", "-1", {…}]
3919
+ // canDeactivate {
3920
+ // staticPath: "/hero-stats",
3921
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3922
+ // nextStateUrl: "/route-parameters/-1"
3923
+ // }
3924
+ // canDeactivate {
3925
+ // staticPath: "/route-parameters",
3926
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3927
+ // nextStateUrl: "/route-parameters/-1"
3928
+ // }
3929
+ // logger.class.js:54 ParameterSnapshot.sanitise -> {idModel: -1, pv: undefined, pl: Array(0), dv: "A", dl: Array(3), …}
3930
+ // parameter-snapshot.ts:20 {name: "dv", mine: "A", theirs: undefined}
3931
+ // place-router.ts:28 redirect path (3) ["route-parameters", "-1", {…}]
3932
+ // canDeactivate {
3933
+ // staticPath: "/hero-stats",
3934
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
3935
+ // nextStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c"
3936
+ // }
3937
+ // HACK: this will break with child routes...
3938
+ if (this.alreadyAccepted(component)) {
3939
+ return true;
3727
3940
  }
3728
3941
  else {
3942
+ if (!nextState.url.startsWith(placeDefinitionPath)) {
3943
+ /** @type {?} */
3944
+ const self = this;
3945
+ return Promise.resolve(component.canDeactivate())
3946
+ .then((/**
3947
+ * @param {?} canLeave
3948
+ * @return {?}
3949
+ */
3950
+ canLeave => {
3951
+ if (!canLeave) {
3952
+ // Angular doesn't preserve the url when a guard cancels the back button.
3953
+ // See https://github.com/angular/angular/issues/13586#issuecomment-432795720
3954
+ this.location.go(currentState.url);
3955
+ return false;
3956
+ }
3957
+ else {
3958
+ if (this.interactionContext.isActive()) {
3959
+ this.interactionContext.currentActivity.value.cancel(null);
3960
+ return false;
3961
+ }
3962
+ else {
3963
+ return true;
3964
+ }
3965
+ }
3966
+ })).then((/**
3967
+ * @param {?} canDeactivate
3968
+ * @return {?}
3969
+ */
3970
+ canDeactivate => {
3971
+ if (canDeactivate) {
3972
+ self._alreadyAccepted.push(component);
3973
+ }
3974
+ return canDeactivate;
3975
+ }));
3976
+ }
3729
3977
  return true;
3730
3978
  }
3731
3979
  }
3980
+ /**
3981
+ * @param {?} placeComponent
3982
+ * @return {?}
3983
+ */
3984
+ alreadyAccepted(placeComponent) {
3985
+ return this._alreadyAccepted.includes(placeComponent);
3986
+ }
3732
3987
  }
3733
3988
  LeavePlaceGuard.decorators = [
3734
3989
  { type: Injectable, args: [{
@@ -3738,10 +3993,23 @@ LeavePlaceGuard.decorators = [
3738
3993
  /** @nocollapse */
3739
3994
  LeavePlaceGuard.ctorParameters = () => [
3740
3995
  { type: Router },
3741
- { type: Injector }
3996
+ { type: Injector },
3997
+ { type: InteractionContext },
3998
+ { type: Location }
3742
3999
  ];
3743
- /** @nocollapse */ LeavePlaceGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function LeavePlaceGuard_Factory() { return new LeavePlaceGuard(ɵɵinject(Router), ɵɵinject(INJECTOR)); }, token: LeavePlaceGuard, providedIn: "root" });
4000
+ /** @nocollapse */ LeavePlaceGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function LeavePlaceGuard_Factory() { return new LeavePlaceGuard(ɵɵinject(Router), ɵɵinject(INJECTOR), ɵɵinject(InteractionContext), ɵɵinject(Location)); }, token: LeavePlaceGuard, providedIn: "root" });
4001
+ __decorate([
4002
+ Trace(),
4003
+ __metadata("design:type", Function),
4004
+ __metadata("design:paramtypes", [PlaceComponent]),
4005
+ __metadata("design:returntype", Boolean)
4006
+ ], LeavePlaceGuard.prototype, "alreadyAccepted", null);
3744
4007
  if (false) {
4008
+ /**
4009
+ * @type {?}
4010
+ * @private
4011
+ */
4012
+ LeavePlaceGuard.prototype._alreadyAccepted;
3745
4013
  /**
3746
4014
  * @type {?}
3747
4015
  * @private
@@ -3752,6 +4020,10 @@ if (false) {
3752
4020
  * @private
3753
4021
  */
3754
4022
  LeavePlaceGuard.prototype.injector;
4023
+ /** @type {?} */
4024
+ LeavePlaceGuard.prototype.interactionContext;
4025
+ /** @type {?} */
4026
+ LeavePlaceGuard.prototype.location;
3755
4027
  }
3756
4028
 
3757
4029
  /**
@@ -4024,5 +4296,5 @@ var ParameterType;
4024
4296
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4025
4297
  */
4026
4298
 
4027
- export { ACTIVITY_DATA, AbstractActivity, AbstractInputComponent, AbstractPlaceNavigationComponent, ActivityContainerComponent, ActivityOutletComponent, AlertDialogComponent, AngularUiPowerupsModule, Bounds, BusyOverlayComponent, CommandDirective, ConfirmThenDialogComponent, 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, 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 };
4299
+ 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 };
4028
4300
  //# sourceMappingURL=coolon-angular-ui-powerups.js.map