@coolon/angular-ui-powerups 0.0.63 → 0.0.66

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