@coolon/angular-ui-powerups 0.0.63 → 0.0.65

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 (46) hide show
  1. package/bundles/coolon-angular-ui-powerups.umd.js +722 -561
  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 +10 -10
  6. package/coolon-angular-ui-powerups.metadata.json +1 -1
  7. package/esm2015/coolon-angular-ui-powerups.js +10 -10
  8. package/esm2015/index.js +2 -2
  9. package/esm2015/lib/interaction/abstract-activity.js +5 -68
  10. package/esm2015/lib/interaction/activity.js +71 -11
  11. package/esm2015/lib/interaction/components/activity-container/activity-container.component.js +213 -120
  12. package/esm2015/lib/interaction/components/activity-outlet/activity-outlet-context.js +6 -7
  13. package/esm2015/lib/interaction/components/activity-outlet/activity-outlet.component.js +19 -43
  14. package/esm2015/lib/interaction/index.js +2 -2
  15. package/esm2015/lib/interaction/interaction-context.js +11 -5
  16. package/esm2015/lib/interaction/services/dialog-interaction.service.js +94 -65
  17. package/esm2015/lib/place/guards/leave-place.guard.js +95 -131
  18. package/esm2015/lib/place/place-router.js +87 -6
  19. package/esm2015/public_api.js +2 -2
  20. package/esm5/coolon-angular-ui-powerups.js +10 -10
  21. package/esm5/index.js +2 -2
  22. package/esm5/lib/interaction/abstract-activity.js +10 -96
  23. package/esm5/lib/interaction/activity.js +110 -11
  24. package/esm5/lib/interaction/components/activity-container/activity-container.component.js +285 -143
  25. package/esm5/lib/interaction/components/activity-outlet/activity-outlet-context.js +6 -7
  26. package/esm5/lib/interaction/components/activity-outlet/activity-outlet.component.js +19 -67
  27. package/esm5/lib/interaction/index.js +2 -2
  28. package/esm5/lib/interaction/interaction-context.js +18 -7
  29. package/esm5/lib/interaction/services/dialog-interaction.service.js +112 -64
  30. package/esm5/lib/place/guards/leave-place.guard.js +51 -137
  31. package/esm5/lib/place/place-router.js +96 -6
  32. package/esm5/public_api.js +2 -2
  33. package/fesm2015/coolon-angular-ui-powerups.js +582 -439
  34. package/fesm2015/coolon-angular-ui-powerups.js.map +1 -1
  35. package/fesm5/coolon-angular-ui-powerups.js +695 -535
  36. package/fesm5/coolon-angular-ui-powerups.js.map +1 -1
  37. package/lib/interaction/abstract-activity.d.ts +4 -13
  38. package/lib/interaction/activity.d.ts +13 -6
  39. package/lib/interaction/components/activity-container/activity-container.component.d.ts +37 -25
  40. package/lib/interaction/components/activity-outlet/activity-outlet-context.d.ts +2 -5
  41. package/lib/interaction/components/activity-outlet/activity-outlet.component.d.ts +1 -10
  42. package/lib/interaction/interaction-context.d.ts +6 -6
  43. package/lib/interaction/services/dialog-interaction.service.d.ts +4 -6
  44. package/lib/place/guards/leave-place.guard.d.ts +6 -7
  45. package/lib/place/place-router.d.ts +14 -1
  46. package/package.json +1 -1
@@ -5,18 +5,19 @@ import { MatDialog, MatButtonModule, MatDialogModule, MatTabsModule, MatProgress
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, DelegatingListModel, StoreInValueModel, Binding, MutableValueModel, Guard, OptionsHelper, ValueHolder, Trace } from '@coolon/pectin';
8
+ import { GarbageCollector, DelegatingFormValueModel, UseDelegate, ValueModel, ListModel, StoreInListModel, assert, UnaryCommand, lang, Dsl, Logger, DelegatingValueModel, MutableStream, MutableListModel, DelegatingListModel, StoreInValueModel, Binding, MutableValueModel, Guard as Guard$1, OptionsHelper, ValueHolder } from '@coolon/pectin';
9
9
  import { PortalModule } from '@angular/cdk/portal';
10
+ import ___default, { last, isNil } from 'lodash';
10
11
  import { assert as assert$1, Klass, Opts } from '@coolon/typescript-utilities';
11
12
  import { MatDialogConfig, MAT_DIALOG_DEFAULT_OPTIONS, MatDialog as MatDialog$1 } from '@angular/material/dialog';
12
- import { Router, RouterModule, NavigationEnd, NavigationError } from '@angular/router';
13
+ import { v1 } from 'uuid';
13
14
  import { MatIconModule } from '@angular/material/icon';
14
15
  import { MatListModule } from '@angular/material/list';
15
16
  import { MatTooltipModule } from '@angular/material/tooltip';
17
+ import { Router, NavigationStart, NavigationEnd, NavigationError, RouterModule } from '@angular/router';
16
18
  import { Memoize as Memoize$1 } from '@typescript-plus/fast-memoize-decorator/dist/src';
17
19
  import { Memoize } from '@typescript-plus/fast-memoize-decorator';
18
20
  import 'reflect-metadata';
19
- import ___default, { isNil } from 'lodash';
20
21
  import { style, query, group, animate, trigger, transition } from '@angular/animations';
21
22
  import ResizeObserver from 'resize-observer-polyfill';
22
23
 
@@ -655,17 +656,22 @@ if (false) {
655
656
  * @abstract
656
657
  */
657
658
  class InteractionContext extends GarbageCollector {
659
+ /**
660
+ * @protected
661
+ */
658
662
  constructor() {
659
663
  super();
660
664
  }
661
- }
662
- if (false) {
663
665
  /**
664
666
  * Returns the activity that is currently active.
665
667
  * This model is only updated in the next tick after the view has been updated.
666
- * @type {?}
668
+ * @return {?}
667
669
  */
668
- InteractionContext.prototype.currentActivity;
670
+ get currentActivity() {
671
+ return last(this.activityList.value);
672
+ }
673
+ }
674
+ if (false) {
669
675
  /**
670
676
  * Returns the current list of activities that are in progress.
671
677
  * This model is only updated in the next tick after the view has been updated.
@@ -717,29 +723,87 @@ if (false) {
717
723
  /** @type {?} */
718
724
  const ACTIVITY_DATA = new InjectionToken('InteractionActivityData');
719
725
  /**
720
- * @record
726
+ * @abstract
721
727
  * @template D, R, E
722
728
  */
723
- function Activity() { }
724
- if (false) {
725
- /** @type {?} */
726
- Activity.prototype.busy;
729
+ class Activity {
730
+ constructor() {
731
+ this._busyModel = new DelegatingValueModel().withDefault(false);
732
+ }
727
733
  /**
728
734
  * @param {?} activityContext
729
735
  * @return {?}
730
736
  */
731
- Activity.prototype.initialise = function (activityContext) { };
737
+ initialise(activityContext) {
738
+ assert$1.isNil(this._activityContext);
739
+ this._activityContext = activityContext;
740
+ }
732
741
  /**
733
- * @param {?} result
742
+ * @param {?=} result
743
+ * @return {?}
744
+ */
745
+ done(result) {
746
+ return this._activityContext.onDone(result);
747
+ }
748
+ /**
749
+ * @param {?=} error
734
750
  * @return {?}
735
751
  */
736
- Activity.prototype.done = function (result) { };
752
+ cancel(error) {
753
+ this._activityContext.onCancel(error);
754
+ }
755
+ // @Trace()
756
+ /**
757
+ * @return {?}
758
+ */
759
+ onActivityReady() {
760
+ }
737
761
  /**
738
- * @param {?} e
739
762
  * @return {?}
740
763
  */
741
- Activity.prototype.cancel = function (e) { };
764
+ get busy() {
765
+ return this._busyModel.readonly;
766
+ }
767
+ /**
768
+ * @param {?} busyModel
769
+ * @return {?}
770
+ */
771
+ busyWhile(busyModel) {
772
+ this._busyModel.setDelegate(busyModel);
773
+ }
774
+ /**
775
+ * @return {?}
776
+ */
777
+ isBusy() {
778
+ return this._busyModel.value;
779
+ }
780
+ }
781
+ if (false) {
782
+ /**
783
+ * @type {?}
784
+ * @private
785
+ */
786
+ Activity.prototype._busyModel;
787
+ /**
788
+ * @type {?}
789
+ * @private
790
+ */
791
+ Activity.prototype._activityContext;
742
792
  }
793
+ (function (Activity) {
794
+ /**
795
+ * @record
796
+ * @template R, E
797
+ */
798
+ function Callbacks() { }
799
+ Activity.Callbacks = Callbacks;
800
+ if (false) {
801
+ /** @type {?} */
802
+ Callbacks.prototype.onDone;
803
+ /** @type {?} */
804
+ Callbacks.prototype.onCancel;
805
+ }
806
+ })(Activity || (Activity = {}));
743
807
 
744
808
  /**
745
809
  * @fileoverview added by tsickle
@@ -769,9 +833,17 @@ class ActivityOutletComponent {
769
833
  * @return {?}
770
834
  */
771
835
  set activityContext(activityContext) {
836
+ assert.isNil(this._activityContext);
837
+ this._activityContext = activityContext;
772
838
  this.loadActivity(activityContext);
773
839
  }
774
840
  ;
841
+ /**
842
+ * @return {?}
843
+ */
844
+ get activityContext() {
845
+ return this._activityContext;
846
+ }
775
847
  /**
776
848
  * @return {?}
777
849
  */
@@ -787,7 +859,7 @@ class ActivityOutletComponent {
787
859
  providers: [
788
860
  {
789
861
  provide: InteractionContext,
790
- useValue: this
862
+ useValue: this.interactionContext
791
863
  },
792
864
  { provide: ACTIVITY_DATA, useValue: activityContext.activityData }
793
865
  ],
@@ -798,6 +870,9 @@ class ActivityOutletComponent {
798
870
  this.viewContainerRef.clear();
799
871
  this.activityComponentRef = this.viewContainerRef.createComponent(componentFactory, 0, injector);
800
872
  this.activityComponentRef.instance.initialise(activityContext);
873
+ if (this.activityContext.componentReady) {
874
+ this.activityContext.componentReady(this.component);
875
+ }
801
876
  }
802
877
  /**
803
878
  * @return {?}
@@ -805,47 +880,6 @@ class ActivityOutletComponent {
805
880
  get component() {
806
881
  return this.activityComponentRef.instance;
807
882
  }
808
- /**
809
- * @param {?} alert
810
- * @return {?}
811
- */
812
- alert(alert) {
813
- return this.interactionContext.alert(alert);
814
- }
815
- /**
816
- * @param {?} confirm
817
- * @return {?}
818
- */
819
- confirm(confirm) {
820
- return this.interactionContext.confirm(confirm);
821
- }
822
- /**
823
- * @template D1, R1, E1
824
- * @param {?} confirm
825
- * @param {?} activityType
826
- * @param {?=} data
827
- * @return {?}
828
- */
829
- confirmThen(confirm, activityType, data) {
830
- return this.interactionContext.confirmThen(confirm, activityType, data);
831
- }
832
- /**
833
- * @template D1, R1, E1
834
- * @param {?} activityType
835
- * @param {?=} data
836
- * @return {?}
837
- */
838
- startActivity(activityType, data) {
839
- return this.interactionContext.startActivity(activityType, data);
840
- }
841
- /**
842
- * @return {?}
843
- */
844
- notifyReady() {
845
- if (this.activityComponentRef.instance['onActivityReady']) {
846
- this.activityComponentRef.instance['onActivityReady']();
847
- }
848
- }
849
883
  }
850
884
  ActivityOutletComponent.decorators = [
851
885
  { type: Component, args: [{
@@ -867,6 +901,11 @@ ActivityOutletComponent.propDecorators = {
867
901
  if (false) {
868
902
  /** @type {?} */
869
903
  ActivityOutletComponent.prototype.interactionContext;
904
+ /**
905
+ * @type {?}
906
+ * @private
907
+ */
908
+ ActivityOutletComponent.prototype._activityContext;
870
909
  /**
871
910
  * @type {?}
872
911
  * @private
@@ -895,72 +934,11 @@ if (false) {
895
934
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
896
935
  */
897
936
  /**
937
+ * Deprecated. You can now extend the Activity class directly.
938
+ * @abstract
898
939
  * @template D, R, E
899
940
  */
900
- class AbstractActivity extends DisposableComponent {
901
- constructor() {
902
- super(...arguments);
903
- this._busyModel = new DelegatingValueModel().withDefault(false);
904
- }
905
- /**
906
- * @param {?} activityContext
907
- * @return {?}
908
- */
909
- initialise(activityContext) {
910
- assert$1.isNil(this.activityContext);
911
- this.activityContext = activityContext;
912
- }
913
- /**
914
- * @param {?=} result
915
- * @return {?}
916
- */
917
- done(result) {
918
- return this.activityContext.onDone(result);
919
- }
920
- /**
921
- * @param {?=} error
922
- * @return {?}
923
- */
924
- cancel(error) {
925
- this.activityContext.onCancel(error);
926
- }
927
- // @Trace()
928
- /**
929
- * @return {?}
930
- */
931
- onActivityReady() {
932
- }
933
- /**
934
- * @return {?}
935
- */
936
- get busy() {
937
- return this._busyModel.readonly;
938
- }
939
- /**
940
- * @param {?} busyModel
941
- * @return {?}
942
- */
943
- busyWhile(busyModel) {
944
- this._busyModel.setDelegate(busyModel);
945
- }
946
- /**
947
- * @return {?}
948
- */
949
- isBusy() {
950
- return this._busyModel.value;
951
- }
952
- }
953
- if (false) {
954
- /**
955
- * @type {?}
956
- * @private
957
- */
958
- AbstractActivity.prototype._busyModel;
959
- /**
960
- * @type {?}
961
- * @private
962
- */
963
- AbstractActivity.prototype.activityContext;
941
+ class AbstractActivity extends Activity {
964
942
  }
965
943
 
966
944
  /**
@@ -1129,101 +1107,175 @@ if (false) {
1129
1107
  * @fileoverview added by tsickle
1130
1108
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1131
1109
  */
1132
- class ActivityContainerComponent extends DisposableComponent {
1133
- constructor() {
1134
- super();
1135
- this.activityOutletTabs = new MutableListModel();
1136
- this.obsoleteTabs = [];
1137
- this.finished = false;
1138
- this._activityList = new MutableListModel();
1110
+ /**
1111
+ * Note: this class is mutable and is stored in a list model. This is normally a big no no but
1112
+ * we're manually deriving other models from the list after view state changes. I.e. we not
1113
+ * using pectin chains on any of the mutable fields.
1114
+ * @template D, R, E
1115
+ */
1116
+ class TabContext {
1117
+ /**
1118
+ * @param {?} activityData
1119
+ * @param {?} activityClass
1120
+ * @param {?} interactionContext
1121
+ * @param {?} activityCallbacks
1122
+ */
1123
+ constructor(activityData, activityClass, interactionContext, activityCallbacks) {
1124
+ this.activityData = activityData;
1125
+ this.activityClass = activityClass;
1126
+ this.interactionContext = interactionContext;
1127
+ this.activityCallbacks = activityCallbacks;
1128
+ this._complete = false;
1139
1129
  }
1140
1130
  /**
1141
1131
  * @return {?}
1142
1132
  */
1143
- isActive() {
1144
- return this.parentInteractionContext.isActive();
1133
+ isComponentRealised() {
1134
+ return !!this._component;
1145
1135
  }
1146
1136
  /**
1147
1137
  * @return {?}
1148
1138
  */
1149
- get activityList() {
1150
- return this._activityList.readonly;
1139
+ isComplete() {
1140
+ return this._complete;
1151
1141
  }
1152
1142
  /**
1143
+ * @param {?} component
1153
1144
  * @return {?}
1154
1145
  */
1155
- ngOnInit() {
1146
+ componentReady(component) {
1147
+ assert.isNil(this._component);
1148
+ this._component = component;
1156
1149
  }
1157
1150
  /**
1158
1151
  * @return {?}
1159
1152
  */
1160
- ngAfterViewInit() {
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
- }));
1178
- observe.valuesFrom(this.tabs.animationDone).subscribe((/**
1179
- * @return {?}
1180
- */
1181
- () => this.onAnimationFinished()));
1153
+ get component() {
1154
+ return this._component;
1182
1155
  }
1156
+ // @Trace()
1183
1157
  /**
1184
- * Update in the next tick to avoid changing state in the current change detection cycle.
1185
- * @private
1186
- * @param {?} activities
1158
+ * @param {?} result
1187
1159
  * @return {?}
1188
1160
  */
1189
- safelyUpdateActivityList(activities) {
1190
- setTimeout((/**
1161
+ onDone(result) {
1162
+ this._complete = true;
1163
+ this.activityCallbacks.onDone(result);
1164
+ }
1165
+ // @Trace()
1166
+ /**
1167
+ * @param {?} error
1168
+ * @return {?}
1169
+ */
1170
+ onCancel(error) {
1171
+ this._complete = true;
1172
+ this.activityCallbacks.onCancel(error);
1173
+ }
1174
+ }
1175
+ if (false) {
1176
+ /**
1177
+ * @type {?}
1178
+ * @private
1179
+ */
1180
+ TabContext.prototype._complete;
1181
+ /**
1182
+ * @type {?}
1183
+ * @private
1184
+ */
1185
+ TabContext.prototype._component;
1186
+ /** @type {?} */
1187
+ TabContext.prototype.activityData;
1188
+ /** @type {?} */
1189
+ TabContext.prototype.activityClass;
1190
+ /** @type {?} */
1191
+ TabContext.prototype.interactionContext;
1192
+ /** @type {?} */
1193
+ TabContext.prototype.activityCallbacks;
1194
+ }
1195
+ /**
1196
+ * @template D, R, E
1197
+ */
1198
+ class ActivityContainerComponent extends InteractionContext {
1199
+ constructor() {
1200
+ super();
1201
+ this.activityFinishedEvents = new MutableStream();
1202
+ this.activityTabs = new MutableListModel();
1203
+ this.finished = false;
1204
+ this._activityList = new MutableListModel();
1205
+ const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);
1206
+ chain(this.activityFinishedEvents).throttle(50).subscribe((/**
1191
1207
  * @return {?}
1192
1208
  */
1193
- () => this._activityList.value = activities));
1209
+ () => this.onActivityFinished()));
1194
1210
  }
1195
1211
  /**
1196
- * @template D, R, E
1197
1212
  * @param {?} initialContext
1198
1213
  * @return {?}
1199
1214
  */
1200
- initialise(initialContext) {
1201
- /** @type {?} */
1202
- const self = this;
1203
- this.initialActivityOutletContext = {
1204
- activityClass: initialContext.activityClass,
1205
- activityData: initialContext.activityData,
1215
+ set initialActivityOutletContext(initialContext) {
1216
+ assert.isNil(this.initialActivityOutletContext);
1217
+ this.activityTabs.push(new TabContext(initialContext.activityData, initialContext.activityClass, this, {
1206
1218
  onDone: (/**
1207
1219
  * @param {?} result
1208
1220
  * @return {?}
1209
1221
  */
1210
- function (result) {
1211
- self.finished = true;
1222
+ (result) => {
1223
+ this.finished = true;
1212
1224
  return initialContext.onDone(result);
1213
1225
  }),
1214
1226
  onCancel: (/**
1215
1227
  * @param {?} error
1216
1228
  * @return {?}
1217
1229
  */
1218
- function (error) {
1219
- self.finished = true;
1230
+ (error) => {
1231
+ this.finished = true;
1220
1232
  return initialContext.onCancel(error);
1221
- }),
1222
- interactionContext: this
1223
- };
1233
+ })
1234
+ }));
1235
+ }
1236
+ /**
1237
+ * @return {?}
1238
+ */
1239
+ get initialActivityOutletContext() {
1240
+ return this.activityTabs.length > 0 ? this.activityTabs.value[0] : null;
1241
+ }
1242
+ /**
1243
+ * @return {?}
1244
+ */
1245
+ isActive() {
1246
+ return this.parentInteractionContext.isActive();
1247
+ }
1248
+ /**
1249
+ * @return {?}
1250
+ */
1251
+ get activityList() {
1252
+ return this._activityList.readonly;
1253
+ }
1254
+ /**
1255
+ * @return {?}
1256
+ */
1257
+ ngOnInit() {
1258
+ }
1259
+ /**
1260
+ * @return {?}
1261
+ */
1262
+ ngAfterViewInit() {
1263
+ const { chain, observe } = Dsl.disposeWith(this);
1264
+ observe.valuesFrom(this.outlets.changes).subscribe((/**
1265
+ * @return {?}
1266
+ */
1267
+ () => setTimeout((/**
1268
+ * @return {?}
1269
+ */
1270
+ () => this.updateActivityList()))));
1271
+ observe.valuesFrom(this.tabs.animationDone).subscribe((/**
1272
+ * @return {?}
1273
+ */
1274
+ () => this.onAnimationFinished()));
1275
+ this.updateActivityList();
1224
1276
  }
1225
1277
  /**
1226
- * @template D, R, E
1278
+ * @template D1, R1, E1
1227
1279
  * @param {?} activityType
1228
1280
  * @param {?=} data
1229
1281
  * @return {?}
@@ -1238,41 +1290,26 @@ class ActivityContainerComponent extends DisposableComponent {
1238
1290
  */
1239
1291
  (resolve, reject) => {
1240
1292
  /** @type {?} */
1241
- const context = {
1242
- interactionContext: self,
1243
- activityClass: activityType,
1244
- activityData: data,
1293
+ const context = new TabContext(data, activityType, self, {
1245
1294
  onDone: (/**
1246
1295
  * @param {?} result
1247
1296
  * @return {?}
1248
1297
  */
1249
1298
  function (result) {
1250
- self.obsoleteTabs.push(context);
1251
- // animating on the next tick gives chained done's a chance to
1252
- // finished before we start an animations
1253
1299
  resolve(result);
1254
- setTimeout((/**
1255
- * @return {?}
1256
- */
1257
- () => self.animateTabs()));
1300
+ self.activityFinishedEvents.publish({});
1258
1301
  }),
1259
1302
  onCancel: (/**
1260
1303
  * @param {?} error
1261
1304
  * @return {?}
1262
1305
  */
1263
1306
  function (error) {
1264
- self.obsoleteTabs.push(context);
1265
- // finished before we start an animations
1266
1307
  reject(error);
1267
- // animating on the next tick gives chained done's a chance to complete before we animate
1268
- setTimeout((/**
1269
- * @return {?}
1270
- */
1271
- () => self.animateTabs()));
1308
+ self.activityFinishedEvents.publish({});
1272
1309
  })
1273
- };
1274
- self.activityOutletTabs.push(context);
1275
- self.tabs.selectedIndex = this.activityOutletTabs.length;
1310
+ });
1311
+ self.activityTabs.push(context);
1312
+ self.tabs.selectedIndex = this.activityTabs.length;
1276
1313
  }));
1277
1314
  }
1278
1315
  /**
@@ -1290,7 +1327,7 @@ class ActivityContainerComponent extends DisposableComponent {
1290
1327
  return this.startActivity(ConfirmationDialogComponent, confirm);
1291
1328
  }
1292
1329
  /**
1293
- * @template D, R, E
1330
+ * @template D1, R1, E1
1294
1331
  * @param {?} confirm
1295
1332
  * @param {?} activityType
1296
1333
  * @param {?=} data
@@ -1303,35 +1340,92 @@ class ActivityContainerComponent extends DisposableComponent {
1303
1340
  data: data
1304
1341
  });
1305
1342
  }
1343
+ // @Trace()
1344
+ /**
1345
+ * @private
1346
+ * @return {?}
1347
+ */
1348
+ onActivityFinished() {
1349
+ // don't do anything if job already queued up.
1350
+ if (!this.finished) {
1351
+ if (this.synchroniseSelectedTabIndex()) {
1352
+ this.cleanupStaleActivities();
1353
+ }
1354
+ this.updateActivityList();
1355
+ }
1356
+ }
1357
+ // @Trace()
1358
+ /**
1359
+ * @private
1360
+ * @return {?}
1361
+ */
1362
+ cleanupStaleActivities() {
1363
+ // clean up old tabs
1364
+ if (this.tabs.selectedIndex < this.activityTabs.length - 1) {
1365
+ this.activityTabs.runInTransaction((/**
1366
+ * @param {?} draft
1367
+ * @return {?}
1368
+ */
1369
+ draft => {
1370
+ draft.value = draft.value.slice(0, 1 + this.tabs.selectedIndex);
1371
+ }));
1372
+ }
1373
+ }
1374
+ /**
1375
+ * Synchronises the selected tab index. Returns true if there was no change to the selected index.
1376
+ * @private
1377
+ * @return {?}
1378
+ */
1379
+ // @Trace()
1380
+ synchroniseSelectedTabIndex() {
1381
+ /** @type {?} */
1382
+ const previousIndex = this.tabs.selectedIndex;
1383
+ /** @type {?} */
1384
+ const newIndex = this.activityTabs.query().findIndex((/**
1385
+ * @param {?} t
1386
+ * @return {?}
1387
+ */
1388
+ t => t.isComplete())) - 1;
1389
+ this.tabs.selectedIndex = newIndex;
1390
+ return previousIndex === newIndex;
1391
+ }
1392
+ // @Trace()
1306
1393
  /**
1307
1394
  * @private
1308
1395
  * @return {?}
1309
1396
  */
1310
1397
  onAnimationFinished() {
1311
- this.activityOutletTabs.value = this.activityOutletTabs.value.filter((/**
1312
- * @param {?} tab
1398
+ this.getSelectedOutlet().component.onActivityReady();
1399
+ this.cleanupStaleActivities();
1400
+ this.updateActivityList();
1401
+ }
1402
+ /**
1403
+ * @private
1404
+ * @return {?}
1405
+ */
1406
+ updateActivityList() {
1407
+ this._activityList.value = this.activityTabs.value.filter((/**
1408
+ * @param {?} t
1313
1409
  * @return {?}
1314
1410
  */
1315
- tab => {
1316
- return !this.obsoleteTabs.includes(tab);
1317
- }));
1318
- this.obsoleteTabs = [];
1319
- this.outlets.toArray()[this.tabs.selectedIndex].notifyReady();
1411
+ t => !t.isComplete() && t.isComponentRealised())).map((/**
1412
+ * @param {?} t
1413
+ * @return {?}
1414
+ */
1415
+ t => t.component));
1320
1416
  }
1321
1417
  /**
1322
1418
  * @private
1323
1419
  * @return {?}
1324
1420
  */
1325
- animateTabs() {
1326
- if (!this.finished) {
1327
- this.tabs.selectedIndex = this.activityOutletTabs.length - this.obsoleteTabs.length;
1328
- }
1421
+ getSelectedOutlet() {
1422
+ return this.outlets.toArray()[this.tabs.selectedIndex];
1329
1423
  }
1330
1424
  }
1331
1425
  ActivityContainerComponent.decorators = [
1332
1426
  { type: Component, args: [{
1333
1427
  selector: 'angular-ui-powerups-activity-container',
1334
- template: "<mat-tab-group #tabs no-tab-header [dynamicHeight]=\"true\">\n <mat-tab>\n <angular-ui-powerups-activity-outlet [interactionContext]=\"this\"\n [activityContext]=\"initialActivityOutletContext\"></angular-ui-powerups-activity-outlet>\n </mat-tab>\n <mat-tab *ngFor=\"let tab of activityOutletTabs.value\">\n <angular-ui-powerups-activity-outlet [interactionContext]=\"this\"\n [activityContext]=\"tab\"></angular-ui-powerups-activity-outlet>\n </mat-tab>\n</mat-tab-group>\n",
1428
+ template: "<mat-tab-group #tabs no-tab-header [dynamicHeight]=\"true\">\n <mat-tab *ngFor=\"let tab of activityTabs.value\">\n <angular-ui-powerups-activity-outlet [interactionContext]=\"this\"\n [activityContext]=\"tab\"></angular-ui-powerups-activity-outlet>\n </mat-tab>\n</mat-tab-group>\n",
1335
1429
  styles: [":host{display:block}"]
1336
1430
  }] }
1337
1431
  ];
@@ -1344,23 +1438,19 @@ ActivityContainerComponent.propDecorators = {
1344
1438
  outlets: [{ type: ViewChildren, args: [ActivityOutletComponent,] }]
1345
1439
  };
1346
1440
  if (false) {
1441
+ /**
1442
+ * @type {?}
1443
+ * @private
1444
+ */
1445
+ ActivityContainerComponent.prototype.activityFinishedEvents;
1347
1446
  /** @type {?} */
1348
1447
  ActivityContainerComponent.prototype.parentInteractionContext;
1349
1448
  /** @type {?} */
1350
- ActivityContainerComponent.prototype.initialActivityOutletContext;
1351
- /** @type {?} */
1352
- ActivityContainerComponent.prototype.currentActivity;
1353
- /** @type {?} */
1354
1449
  ActivityContainerComponent.prototype.tabs;
1355
1450
  /** @type {?} */
1356
1451
  ActivityContainerComponent.prototype.outlets;
1357
1452
  /** @type {?} */
1358
- ActivityContainerComponent.prototype.activityOutletTabs;
1359
- /**
1360
- * @type {?}
1361
- * @private
1362
- */
1363
- ActivityContainerComponent.prototype.obsoleteTabs;
1453
+ ActivityContainerComponent.prototype.activityTabs;
1364
1454
  /**
1365
1455
  * @type {?}
1366
1456
  * @private
@@ -1372,24 +1462,6 @@ if (false) {
1372
1462
  */
1373
1463
  ActivityContainerComponent.prototype._activityList;
1374
1464
  }
1375
- (function (ActivityContainerComponent) {
1376
- /**
1377
- * @record
1378
- * @template D, R, E
1379
- */
1380
- function ActivityContext() { }
1381
- ActivityContainerComponent.ActivityContext = ActivityContext;
1382
- if (false) {
1383
- /** @type {?} */
1384
- ActivityContext.prototype.activityClass;
1385
- /** @type {?} */
1386
- ActivityContext.prototype.activityData;
1387
- /** @type {?} */
1388
- ActivityContext.prototype.onDone;
1389
- /** @type {?} */
1390
- ActivityContext.prototype.onCancel;
1391
- }
1392
- })(ActivityContainerComponent || (ActivityContainerComponent = {}));
1393
1465
 
1394
1466
  /**
1395
1467
  * @fileoverview added by tsickle
@@ -1397,36 +1469,66 @@ if (false) {
1397
1469
  */
1398
1470
  /** @type {?} */
1399
1471
  const DIALOG_INTERACTION_SERVICE_DEFAULTS = new InjectionToken('DIALOG_INTERACTION_SERVICE_DEFAULTS');
1472
+ class Guard extends ValueModel {
1473
+ constructor() {
1474
+ super({ initialValue: false });
1475
+ }
1476
+ /**
1477
+ * @return {?}
1478
+ */
1479
+ get value() {
1480
+ return this.store.read();
1481
+ }
1482
+ /**
1483
+ * @template R
1484
+ * @param {?} fun
1485
+ * @return {?}
1486
+ */
1487
+ whileTrue(fun) {
1488
+ this.startTransaction().commit(true);
1489
+ try {
1490
+ return fun();
1491
+ }
1492
+ finally {
1493
+ this.startTransaction().commit(false);
1494
+ }
1495
+ }
1496
+ /**
1497
+ * @template R
1498
+ * @param {?} fun
1499
+ * @param {?=} defaultValue
1500
+ * @return {?}
1501
+ */
1502
+ runIfFalse(fun, defaultValue = null) {
1503
+ return !this.value ? fun() : defaultValue;
1504
+ }
1505
+ }
1400
1506
  class DialogInteractionService extends InteractionContext {
1401
1507
  /**
1402
1508
  * @param {?} dialogService
1403
- * @param {?} router
1404
1509
  * @param {?} dialogServiceDefaults
1405
1510
  * @param {?} matDialogDefaultConfig
1406
1511
  */
1407
- constructor(dialogService, router, dialogServiceDefaults, matDialogDefaultConfig) {
1512
+ constructor(dialogService, dialogServiceDefaults, matDialogDefaultConfig) {
1408
1513
  super();
1409
1514
  this.dialogService = dialogService;
1410
- this.router = router;
1411
1515
  this.dialogServiceDefaults = dialogServiceDefaults;
1412
1516
  this.matDialogDefaultConfig = matDialogDefaultConfig;
1413
1517
  this._activityList = new DelegatingListModel();
1414
- this._active = false;
1518
+ this.startingGuard = new Guard();
1415
1519
  assert$1.notNil(dialogService);
1416
- const { chain, observe } = Dsl.disposeWith(this);
1417
- this.currentActivity = chain(this.activityList).last();
1418
1520
  }
1419
1521
  /**
1420
1522
  * @return {?}
1421
1523
  */
1422
1524
  isActive() {
1423
- return this._active;
1525
+ return !!this.currentActivityId;
1424
1526
  }
1425
1527
  /**
1426
1528
  * @return {?}
1427
1529
  */
1428
1530
  cancelActivity() {
1429
- this.currentActivity.value.cancel(null);
1531
+ this.currentActivity.cancel(null);
1430
1532
  }
1431
1533
  /**
1432
1534
  * @return {?}
@@ -1459,56 +1561,59 @@ class DialogInteractionService extends InteractionContext {
1459
1561
  */
1460
1562
  a => a.constructor.name)).join(', ')}`);
1461
1563
  }
1462
- this._active = true;
1463
- /** @type {?} */
1464
- const self = this;
1465
- /** @type {?} */
1466
- const config = Object.assign({ autoFocus: false, hasBackdrop: true, closeOnNavigation: false }, this.matDialogDefaultConfig, this.dialogServiceDefaults, {
1467
- data,
1468
- disableClose,
1469
- panelClass: 'dialog-interaction-service'
1470
- });
1471
- /** @type {?} */
1472
- const matDialogRef = (/** @type {?} */ (this.dialogService.open(ActivityContainerComponent, config)));
1473
- return new Promise((/**
1474
- * @param {?} resolve
1475
- * @param {?} reject
1564
+ return this.startingGuard.whileTrue((/**
1476
1565
  * @return {?}
1477
1566
  */
1478
- (resolve, reject) => {
1567
+ () => {
1568
+ this.currentActivityId = v1();
1479
1569
  /** @type {?} */
1480
- const activityContainer = matDialogRef.componentInstance;
1481
- activityContainer.parentInteractionContext = this;
1482
- self.safelyUpdateActivityListDelegate(activityContainer.activityList);
1483
- activityContainer.initialise({
1484
- activityClass: activityType,
1485
- activityData: data,
1486
- /**
1487
- * @param {?} result
1488
- * @return {?}
1489
- */
1490
- onDone(result) {
1491
- // TODO: should I be calling resolve after close?
1492
- resolve(result);
1493
- matDialogRef.close(result);
1494
- },
1495
- /**
1496
- * @param {?} error
1497
- * @return {?}
1498
- */
1499
- onCancel(error) {
1500
- // TODO: should I be calling reject after close?
1501
- reject(error);
1502
- matDialogRef.close(error);
1503
- }
1570
+ const self = this;
1571
+ /** @type {?} */
1572
+ const config = Object.assign({ autoFocus: false, hasBackdrop: true, closeOnNavigation: false }, this.matDialogDefaultConfig, this.dialogServiceDefaults, {
1573
+ data,
1574
+ disableClose,
1575
+ panelClass: 'dialog-interaction-service'
1504
1576
  });
1505
- matDialogRef.updateSize();
1506
- })).finally((/**
1507
- * @return {?}
1508
- */
1509
- () => {
1510
- self.safelyUpdateActivityListDelegate(null);
1511
- self._active = false;
1577
+ /** @type {?} */
1578
+ const matDialogRef = (/** @type {?} */ (this.dialogService.open(ActivityContainerComponent, config)));
1579
+ return new Promise((/**
1580
+ * @param {?} resolve
1581
+ * @param {?} reject
1582
+ * @return {?}
1583
+ */
1584
+ (resolve, reject) => {
1585
+ /** @type {?} */
1586
+ const activityContainer = matDialogRef.componentInstance;
1587
+ activityContainer.parentInteractionContext = this;
1588
+ self.safelyUpdateActivityListDelegate(activityContainer.activityList);
1589
+ activityContainer.initialActivityOutletContext = {
1590
+ activityClass: activityType,
1591
+ activityData: data,
1592
+ /**
1593
+ * @param {?} result
1594
+ * @return {?}
1595
+ */
1596
+ onDone(result) {
1597
+ resolve(result);
1598
+ matDialogRef.close(result);
1599
+ },
1600
+ /**
1601
+ * @param {?} error
1602
+ * @return {?}
1603
+ */
1604
+ onCancel(error) {
1605
+ reject(error);
1606
+ matDialogRef.close(error);
1607
+ }
1608
+ };
1609
+ matDialogRef.updateSize();
1610
+ })).finally((/**
1611
+ * @return {?}
1612
+ */
1613
+ () => {
1614
+ this.currentActivityId = null;
1615
+ self.safelyUpdateActivityListDelegate(null);
1616
+ }));
1512
1617
  }));
1513
1618
  }
1514
1619
  /**
@@ -1559,14 +1664,11 @@ DialogInteractionService.decorators = [
1559
1664
  /** @nocollapse */
1560
1665
  DialogInteractionService.ctorParameters = () => [
1561
1666
  { type: MatDialog },
1562
- { type: Router },
1563
1667
  { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [DIALOG_INTERACTION_SERVICE_DEFAULTS,] }] },
1564
1668
  { type: MatDialogConfig, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DIALOG_DEFAULT_OPTIONS,] }] }
1565
1669
  ];
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" });
1670
+ /** @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" });
1567
1671
  if (false) {
1568
- /** @type {?} */
1569
- DialogInteractionService.prototype.currentActivity;
1570
1672
  /**
1571
1673
  * @type {?}
1572
1674
  * @private
@@ -1576,17 +1678,17 @@ if (false) {
1576
1678
  * @type {?}
1577
1679
  * @private
1578
1680
  */
1579
- DialogInteractionService.prototype._active;
1681
+ DialogInteractionService.prototype.startingGuard;
1580
1682
  /**
1581
1683
  * @type {?}
1582
1684
  * @private
1583
1685
  */
1584
- DialogInteractionService.prototype.dialogService;
1686
+ DialogInteractionService.prototype.currentActivityId;
1585
1687
  /**
1586
1688
  * @type {?}
1587
1689
  * @private
1588
1690
  */
1589
- DialogInteractionService.prototype.router;
1691
+ DialogInteractionService.prototype.dialogService;
1590
1692
  /** @type {?} */
1591
1693
  DialogInteractionService.prototype.dialogServiceDefaults;
1592
1694
  /** @type {?} */
@@ -2100,12 +2202,85 @@ if (false) {
2100
2202
  * @fileoverview added by tsickle
2101
2203
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2102
2204
  */
2205
+ class NavigationSession {
2206
+ /**
2207
+ * @param {?} isPopState
2208
+ * @param {?} initialUrl
2209
+ */
2210
+ constructor(isPopState, initialUrl) {
2211
+ this.isPopState = isPopState;
2212
+ this.initialUrl = initialUrl;
2213
+ this._alreadyAccepted = [];
2214
+ console.log('NavigationSession', { isPopState, initialUrl });
2215
+ }
2216
+ /**
2217
+ * @param {?} placeComponent
2218
+ * @return {?}
2219
+ */
2220
+ alreadyAccepted(placeComponent) {
2221
+ return this._alreadyAccepted.includes(placeComponent);
2222
+ }
2223
+ /**
2224
+ * @param {?} component
2225
+ * @return {?}
2226
+ */
2227
+ rememberAcceptanceOf(component) {
2228
+ this._alreadyAccepted.push(component);
2229
+ }
2230
+ }
2231
+ if (false) {
2232
+ /**
2233
+ * @type {?}
2234
+ * @private
2235
+ */
2236
+ NavigationSession.prototype._alreadyAccepted;
2237
+ /** @type {?} */
2238
+ NavigationSession.prototype.isPopState;
2239
+ /** @type {?} */
2240
+ NavigationSession.prototype.initialUrl;
2241
+ }
2103
2242
  class PlaceRouter {
2104
2243
  /**
2105
2244
  * @param {?} router
2245
+ * @param {?} angularLocation
2106
2246
  */
2107
- constructor(router) {
2247
+ constructor(router, angularLocation) {
2108
2248
  this.router = router;
2249
+ this._navigationSession = new MutableValueModel();
2250
+ angularLocation.onUrlChange((/**
2251
+ * @param {?} url
2252
+ * @return {?}
2253
+ */
2254
+ url => {
2255
+ console.log(`### ${url}`);
2256
+ }));
2257
+ this.router.events.subscribe((/**
2258
+ * @param {?} event
2259
+ * @return {?}
2260
+ */
2261
+ event => {
2262
+ // console.log(`${event.constructor.name}`, location.pathname, angularLocation.getState());
2263
+ // NavigationStart -> .... -> NavigationCancel === redirect (so don't ask again)
2264
+ // NavigationStart -> .... -> NavigationEnd === navigated (so ask next time)
2265
+ // NavigationStart -> .... -> NavigationError === canceled (guard cancelled so ask next time)
2266
+ if (event instanceof NavigationStart && !this.navigationSession) {
2267
+ this._navigationSession.value = new NavigationSession(event.navigationTrigger === 'popstate', this.router.routerState.snapshot.url);
2268
+ }
2269
+ if (event instanceof NavigationEnd) {
2270
+ console.log('navigation ended');
2271
+ this._navigationSession.value = null;
2272
+ }
2273
+ if (event instanceof NavigationError) {
2274
+ console.log('navigation errored');
2275
+ this._navigationSession.value = null;
2276
+ }
2277
+ }));
2278
+ }
2279
+ /**
2280
+ * @return {?}
2281
+ */
2282
+ get navigationSession() {
2283
+ return this._navigationSession.value;
2109
2284
  }
2110
2285
  /**
2111
2286
  * @param {?} activatedRoute
@@ -2135,7 +2310,6 @@ class PlaceRouter {
2135
2310
  const commands = (weHaveARouteId) ?
2136
2311
  [urlSegments[0].path, sanitised.getFormattedRouteId(), sanitised.getFormattedParameters()] :
2137
2312
  [urlSegments[0].path, sanitised.getFormattedParameters()];
2138
- console.log("redirect path", commands);
2139
2313
  return this.router.createUrlTree(commands);
2140
2314
  }
2141
2315
  /**
@@ -2170,10 +2344,16 @@ PlaceRouter.decorators = [
2170
2344
  ];
2171
2345
  /** @nocollapse */
2172
2346
  PlaceRouter.ctorParameters = () => [
2173
- { type: Router }
2347
+ { type: Router },
2348
+ { type: Location }
2174
2349
  ];
2175
- /** @nocollapse */ PlaceRouter.ngInjectableDef = ɵɵdefineInjectable({ factory: function PlaceRouter_Factory() { return new PlaceRouter(ɵɵinject(Router)); }, token: PlaceRouter, providedIn: "root" });
2350
+ /** @nocollapse */ PlaceRouter.ngInjectableDef = ɵɵdefineInjectable({ factory: function PlaceRouter_Factory() { return new PlaceRouter(ɵɵinject(Router), ɵɵinject(Location)); }, token: PlaceRouter, providedIn: "root" });
2176
2351
  if (false) {
2352
+ /**
2353
+ * @type {?}
2354
+ * @private
2355
+ */
2356
+ PlaceRouter.prototype._navigationSession;
2177
2357
  /**
2178
2358
  * @type {?}
2179
2359
  * @private
@@ -3054,8 +3234,8 @@ class PlaceOutletComponent extends DisposableComponent {
3054
3234
  this.placeHistory = placeHistory;
3055
3235
  this.animate = true;
3056
3236
  this._activePlace = new MutableValueModel();
3057
- this._incomingRouteChange = new Guard();
3058
- this._inOutletUpdate = new Guard();
3237
+ this._incomingRouteChange = new Guard$1();
3238
+ this._inOutletUpdate = new Guard$1();
3059
3239
  this._activatedRouteModel = new MutableValueModel();
3060
3240
  this._placeDefinition = new MutableValueModel();
3061
3241
  this._resolvedParameters = new MutableValueModel();
@@ -3678,16 +3858,15 @@ function Result() { }
3678
3858
  */
3679
3859
  function ActivityOutletContext() { }
3680
3860
  if (false) {
3681
- /** @type {?} */
3682
- ActivityOutletContext.prototype.interactionContext;
3683
3861
  /** @type {?} */
3684
3862
  ActivityOutletContext.prototype.activityClass;
3685
3863
  /** @type {?} */
3686
3864
  ActivityOutletContext.prototype.activityData;
3687
- /** @type {?} */
3688
- ActivityOutletContext.prototype.onDone;
3689
- /** @type {?} */
3690
- ActivityOutletContext.prototype.onCancel;
3865
+ /**
3866
+ * @param {?} component
3867
+ * @return {?}
3868
+ */
3869
+ ActivityOutletContext.prototype.componentReady = function (component) { };
3691
3870
  }
3692
3871
 
3693
3872
  /**
@@ -3850,36 +4029,16 @@ class LeavePlaceGuard {
3850
4029
  /**
3851
4030
  * @param {?} router
3852
4031
  * @param {?} injector
4032
+ * @param {?} placeRouter
3853
4033
  * @param {?} interactionContext
3854
- * @param {?} location
4034
+ * @param {?} angularLocation
3855
4035
  */
3856
- constructor(router, injector, interactionContext, location) {
4036
+ constructor(router, injector, placeRouter, interactionContext, angularLocation) {
3857
4037
  this.router = router;
3858
4038
  this.injector = injector;
4039
+ this.placeRouter = placeRouter;
3859
4040
  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
- }));
4041
+ this.angularLocation = angularLocation;
3883
4042
  }
3884
4043
  /**
3885
4044
  * @param {?} component
@@ -3889,100 +4048,89 @@ class LeavePlaceGuard {
3889
4048
  * @return {?}
3890
4049
  */
3891
4050
  canDeactivate(component, currentRoute, currentState, nextState) {
3892
- /** @type {?} */
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;
3940
- }
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;
4051
+ return __awaiter(this, void 0, void 0, function* () {
4052
+ /** @type {?} */
4053
+ const placeDefinitionPath = `/${component.placeDefinition.path}`;
4054
+ // console.log('canDeactivate', {
4055
+ // staticPath: placeDefinitionPath,
4056
+ // currentStateUrl: currentState.url,
4057
+ // nextStateUrl: nextState.url
4058
+ // // alreadyDeclined: this._alreadyAccepted
4059
+ // });
4060
+ // Example of the above when navigating to a different child route.
4061
+ // canDeactivate {staticPath: "/hero-details",
4062
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-details",
4063
+ // nextStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats"
4064
+ // }
4065
+ // Example clicking on router tab of the parent component (de-activates the parent due to route param changes)
4066
+ // canDeactivate {
4067
+ // staticPath: "/hero-stats",
4068
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
4069
+ // nextStateUrl: "/route-parameters/"
4070
+ // }
4071
+ // canDeactivate {
4072
+ // staticPath: "/route-parameters",
4073
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
4074
+ // nextStateUrl: "/route-parameters/"
4075
+ // }
4076
+ // logger.class.js:54 ParameterSnapshot.sanitise -> {idModel: -1, pv: undefined, pl: Array(0), dv: undefined, dl: Array(0), …}
4077
+ // parameter-snapshot.ts:20 {name: "idModel", mine: -1, theirs: null}
4078
+ // place-router.ts:28 redirect path (3) ["route-parameters", "-1", {…}]
4079
+ // canDeactivate {
4080
+ // staticPath: "/hero-stats",
4081
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
4082
+ // nextStateUrl: "/route-parameters/-1"
4083
+ // }
4084
+ // canDeactivate {
4085
+ // staticPath: "/route-parameters",
4086
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
4087
+ // nextStateUrl: "/route-parameters/-1"
4088
+ // }
4089
+ // logger.class.js:54 ParameterSnapshot.sanitise -> {idModel: -1, pv: undefined, pl: Array(0), dv: "A", dl: Array(3), …}
4090
+ // parameter-snapshot.ts:20 {name: "dv", mine: "A", theirs: undefined}
4091
+ // place-router.ts:28 redirect path (3) ["route-parameters", "-1", {…}]
4092
+ // canDeactivate {
4093
+ // staticPath: "/hero-stats",
4094
+ // currentStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c/hero-stats",
4095
+ // nextStateUrl: "/route-parameters/-1;dv=A;dl=a,b,c;rdv=A;rdl=a,b,c"
4096
+ // }
4097
+ if (this.placeRouter.navigationSession.alreadyAccepted(component)) {
4098
+ return true;
4099
+ }
4100
+ else {
4101
+ // TODO: this will break with child routes... need to examine the router states properly.
4102
+ if (!nextState.url.startsWith(placeDefinitionPath)) {
4103
+ /** @type {?} */
4104
+ const self = this;
4105
+ /** @type {?} */
4106
+ let canLeave = yield component.canDeactivate();
4107
+ // component is happy to leave but we need to check if it's left an interaction
4108
+ // open. If so we close and stay where we are.
4109
+ if (canLeave && this.interactionContext.isActive()) {
4110
+ canLeave = false;
4111
+ console.log("cancelling", { activity: this.interactionContext.currentActivity });
4112
+ this.interactionContext.currentActivity.cancel(null);
4113
+ }
4114
+ // If we're still leaving then remember it since angular will call this method multiple
4115
+ // times if any route parameters are changed along the way.
4116
+ if (canLeave) {
4117
+ self.placeRouter.navigationSession.rememberAcceptanceOf(component);
3956
4118
  }
3957
4119
  else {
3958
- if (this.interactionContext.isActive()) {
3959
- this.interactionContext.currentActivity.value.cancel(null);
3960
- return false;
3961
- }
3962
- else {
3963
- return true;
4120
+ // Angular doesn't preserve the url when a guard cancels the back button.
4121
+ // See https://github.com/angular/angular/issues/13586#issuecomment-432795720
4122
+ if (this.placeRouter.navigationSession.isPopState) {
4123
+ console.log('cancelled during popstate');
4124
+ this.angularLocation.go(this.placeRouter.navigationSession.initialUrl);
3964
4125
  }
3965
4126
  }
3966
- })).then((/**
3967
- * @param {?} canDeactivate
3968
- * @return {?}
3969
- */
3970
- canDeactivate => {
3971
- if (canDeactivate) {
3972
- self._alreadyAccepted.push(component);
3973
- }
3974
- return canDeactivate;
3975
- }));
4127
+ return canLeave;
4128
+ }
4129
+ else {
4130
+ return true;
4131
+ }
3976
4132
  }
3977
- return true;
3978
- }
3979
- }
3980
- /**
3981
- * @param {?} placeComponent
3982
- * @return {?}
3983
- */
3984
- alreadyAccepted(placeComponent) {
3985
- return this._alreadyAccepted.includes(placeComponent);
4133
+ });
3986
4134
  }
3987
4135
  }
3988
4136
  LeavePlaceGuard.decorators = [
@@ -3994,36 +4142,31 @@ LeavePlaceGuard.decorators = [
3994
4142
  LeavePlaceGuard.ctorParameters = () => [
3995
4143
  { type: Router },
3996
4144
  { type: Injector },
4145
+ { type: PlaceRouter },
3997
4146
  { type: InteractionContext },
3998
4147
  { type: Location }
3999
4148
  ];
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);
4149
+ /** @nocollapse */ LeavePlaceGuard.ngInjectableDef = ɵɵdefineInjectable({ factory: function LeavePlaceGuard_Factory() { return new LeavePlaceGuard(ɵɵinject(Router), ɵɵinject(INJECTOR), ɵɵinject(PlaceRouter), ɵɵinject(InteractionContext), ɵɵinject(Location)); }, token: LeavePlaceGuard, providedIn: "root" });
4007
4150
  if (false) {
4008
4151
  /**
4009
4152
  * @type {?}
4010
4153
  * @private
4011
4154
  */
4012
- LeavePlaceGuard.prototype._alreadyAccepted;
4155
+ LeavePlaceGuard.prototype.router;
4013
4156
  /**
4014
4157
  * @type {?}
4015
4158
  * @private
4016
4159
  */
4017
- LeavePlaceGuard.prototype.router;
4160
+ LeavePlaceGuard.prototype.injector;
4018
4161
  /**
4019
4162
  * @type {?}
4020
4163
  * @private
4021
4164
  */
4022
- LeavePlaceGuard.prototype.injector;
4165
+ LeavePlaceGuard.prototype.placeRouter;
4023
4166
  /** @type {?} */
4024
4167
  LeavePlaceGuard.prototype.interactionContext;
4025
4168
  /** @type {?} */
4026
- LeavePlaceGuard.prototype.location;
4169
+ LeavePlaceGuard.prototype.angularLocation;
4027
4170
  }
4028
4171
 
4029
4172
  /**
@@ -4296,5 +4439,5 @@ var ParameterType;
4296
4439
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4297
4440
  */
4298
4441
 
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 };
4442
+ export { ACTIVITY_DATA, AbstractActivity, AbstractInputComponent, AbstractPlaceNavigationComponent, Activity, 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, Activity as ɵba, ConfirmThenDialogComponent as ɵbc, AlertDialogComponent as ɵbd, DIALOG_INTERACTION_SERVICE_DEFAULTS as ɵbf, DialogInteractionService as ɵbg, 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, InteractionContext as ɵv, ActivityOutletComponent as ɵw, ConfirmationDialogComponent as ɵx, AbstractActivity as ɵy, ACTIVITY_DATA as ɵz };
4300
4443
  //# sourceMappingURL=coolon-angular-ui-powerups.js.map