@coolon/angular-ui-powerups 16.1.0-alpha.326 → 16.1.0-alpha.327

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.
@@ -9902,7 +9902,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
9902
9902
  notifyActive(context) {
9903
9903
  assert$1.isTruthy(context.identifier);
9904
9904
  this.contextRegistry.start(context);
9905
- return this.isNavigationInProgress() ? Promise.resolve() : this.placeRouter.syncInteractionContextIdsWithRouter();
9905
+ return this.syncIdsWithRouter();
9906
9906
  }
9907
9907
  // @Trace()
9908
9908
  isNavigationInProgress() {
@@ -9911,16 +9911,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
9911
9911
  // @Trace()
9912
9912
  notifyFinished(context) {
9913
9913
  this.contextRegistry.finish(context);
9914
- // :: Important ::
9915
- // This method will be traversed by both the place router (during can canDeactivate guards) and user land code
9916
- // (both when routing is idle and while it is active in PlaceComponent.canDeactivate()).
9917
- // The result of pushInteractionIdsToRoute will not start until after the current route finishes, and the
9918
- // current route won't finish until after this promise returns... Deadlock.
9919
- // So in order to keep this logic out of the activities we perform the check here and ensure that
9920
- // any interactions with the context while routing is active returns immediately.
9921
- return this.isNavigationInProgress() ?
9922
- Promise.resolve() :
9923
- this.placeRouter.syncInteractionContextIdsWithRouter();
9914
+ return this.syncIdsWithRouter();
9915
+ }
9916
+ /**
9917
+ * Brings the url's interaction ids up to date. During a navigation the router runs the sync once
9918
+ * that navigation lands; skipping it instead left the url with the old ids, so Back left the place
9919
+ * rather than closing a dialog opened then, or kept the id of one closed then.
9920
+ *
9921
+ * :: Important ::
9922
+ * Only an idle router's sync is waited for. This is traversed by both the place router (during
9923
+ * canDeactivate guards) and user land code (both when routing is idle and while it is active in
9924
+ * PlaceComponent.canDeactivate()). A sync asked for during a navigation won't start until that
9925
+ * navigation finishes, and the navigation won't finish until this promise settles: deadlock.
9926
+ */
9927
+ syncIdsWithRouter() {
9928
+ const navigating = this.isNavigationInProgress();
9929
+ const synced = this.placeRouter.syncInteractionContextIdsWithRouter();
9930
+ return navigating ? Promise.resolve() : synced;
9924
9931
  }
9925
9932
  }
9926
9933
  InteractionService.ApiAdapter = ApiAdapter;
@@ -11094,8 +11101,10 @@ class PopStateDuringInteractionNavigation extends AbstractPopStateNavigation {
11094
11101
  }
11095
11102
  // @Trace()
11096
11103
  onRouterEnd(event) {
11097
- // this.context.transitionTo(new SynchroniseInteractionContextIdsWithRoute(this.context, this.poppedHistoryUrl, false));
11098
- this.context.finishRoutingSession();
11104
+ // Usually a pop during an interaction is refused (onRouterCancelled), but one that lands has to
11105
+ // record where it landed, as every other session does: finishing without the visit left
11106
+ // activeVisit$, and with it the places, on parameters the url no longer showed.
11107
+ this.context.finishRoutingSession(this.createUpdatedVisit(event.urlAfterRedirects));
11099
11108
  }
11100
11109
  handleCanDeactivateCancelledEventScenario(newUrl) {
11101
11110
  this.illegalTransition('Leaving interaction after pop-state should\'t block so should never see a back button click');
@@ -11955,6 +11964,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImpor
11955
11964
  }]
11956
11965
  }], ctorParameters: function () { return [{ type: i1$5.Router }, { type: i1$1.Location }, { type: i1$5.UrlSerializer }]; } });
11957
11966
 
11967
+ function resolveTarget(target) {
11968
+ return typeof target === 'function' ? target() : target;
11969
+ }
11958
11970
  // function asArray<T>(item: T | T[]): T[] {
11959
11971
  // return Array.isArray(item) ? item : [item];
11960
11972
  // }
@@ -11977,8 +11989,9 @@ class PlaceRouter extends GarbageCollector {
11977
11989
  // agnostic about what the metadata means - producers (e.g. SingleSelectionModel corrections) tag
11978
11990
  // the transaction and register a predicate here. See skipHistoryIf / notifyVisitSegmentChanged.
11979
11991
  skipHistoryPredicates = [];
11980
- // A navigation triggered while an interruptible session is in flight is parked here and run when
11981
- // that session finishes. Only the most recent pending navigation is retained (coalescing).
11992
+ // A navigation triggered while a session is in flight is parked here and run when that session
11993
+ // finishes. Only the most recent target is kept (coalescing), but every caller it replaced waits
11994
+ // with it: see queueNavigation.
11982
11995
  pendingNavigation;
11983
11996
  queuedNavigationDepth = 0;
11984
11997
  static MAX_QUEUED_NAVIGATION_DEPTH = 5;
@@ -12163,21 +12176,30 @@ class PlaceRouter extends GarbageCollector {
12163
12176
  this.currentSession.onRouterEnd(event);
12164
12177
  }
12165
12178
  async navigate(visitOrPlaceComponent, params) {
12166
- const visit = this.toVisit(visitOrPlaceComponent, params).copyWithDefaultsFrom(this.activeVisit$.value);
12167
- return this.doNavigation(visit, async () => {
12168
- await this.angularRouter.navigate(visit.getRouterCommands());
12179
+ const target = this.toVisit(visitOrPlaceComponent, params);
12180
+ // The defaults are filled in when the navigation runs. One that queues behind a navigation in
12181
+ // flight would otherwise take the ancestors that navigation replaces.
12182
+ return this.doNavigation(() => target.copyWithDefaultsFrom(this.activeVisit$.value), async (router, visit) => {
12183
+ await router.navigate(visit.getRouterCommands());
12169
12184
  });
12170
12185
  }
12186
+ /**
12187
+ * Runs a navigation, or queues it behind the one in flight. The returned promise settles once the
12188
+ * navigation has landed (or been refused): a caller may treat it as the route being current, as
12189
+ * the place outlet does. A {@link PlaceRouter.NavigationTarget} given as a function is resolved
12190
+ * when the navigation runs, so a queued one is built from the visit it runs after.
12191
+ */
12171
12192
  // @Trace()
12172
- async doNavigation(visit, runNavigationCommands) {
12193
+ async doNavigation(target, runNavigationCommands) {
12173
12194
  if (this.navigationInProgress$.value) {
12174
- return this.handleOverlappingNavigation(visit, runNavigationCommands);
12195
+ return this.handleOverlappingNavigation(target, runNavigationCommands);
12175
12196
  }
12197
+ const visit = resolveTarget(target);
12176
12198
  const navigation = this.createNavigationSession(this.urlService.getCurrentRouterUrl());
12177
12199
  navigation.initialiseVisitSegments(visit);
12178
12200
  this.transitionTo(navigation);
12179
12201
  try {
12180
- await runNavigationCommands(this.angularRouter);
12202
+ await runNavigationCommands(this.angularRouter, visit);
12181
12203
  }
12182
12204
  finally {
12183
12205
  // Check if the router has finished (in the case where no router change required) and we're still in a
@@ -12201,7 +12223,8 @@ class PlaceRouter extends GarbageCollector {
12201
12223
  * events -> onPopState), so queueing programmatic navigations behind an in-flight session
12202
12224
  * preserves user-intent ordering.
12203
12225
  */
12204
- handleOverlappingNavigation(visit, runNavigationCommands) {
12226
+ handleOverlappingNavigation(target, runNavigationCommands) {
12227
+ const visit = resolveTarget(target);
12205
12228
  const current = this.navigationSession;
12206
12229
  const debug = {
12207
12230
  inProgress: {
@@ -12217,17 +12240,25 @@ class PlaceRouter extends GarbageCollector {
12217
12240
  };
12218
12241
  Logger.get(this).warn(`Navigation triggered while session '${current?.name}' is in progress; ` +
12219
12242
  `queueing the incoming navigation to run once it finishes.`, debug);
12220
- return this.queueNavigation(visit, runNavigationCommands);
12243
+ return this.queueNavigation(target, runNavigationCommands);
12221
12244
  }
12222
- queueNavigation(visit, runNavigationCommands) {
12223
- const flushAlreadyScheduled = !!this.pendingNavigation;
12224
- if (this.pendingNavigation) {
12225
- // Coalesce: supersede the previously queued navigation so only the most recent target runs.
12226
- this.pendingNavigation.resolve();
12227
- }
12245
+ /**
12246
+ * Coalesces to the latest target, but a superseded caller is NOT settled here: it waits for the
12247
+ * navigation that replaced it. Settling it at once told the caller its navigation had landed while
12248
+ * the route was unchanged. The place outlet then wrote that route back to its place; a selection
12249
+ * that couldn't hold it selected again and navigated again, superseding the next one, and that
12250
+ * cycle ran on microtasks alone, so the session in flight never finished (mars-v2's groups pages
12251
+ * hung after a create).
12252
+ */
12253
+ queueNavigation(target, runNavigationCommands) {
12254
+ const superseded = this.pendingNavigation;
12228
12255
  return new Promise((resolve, reject) => {
12229
- this.pendingNavigation = { visit, runNavigationCommands, resolve, reject };
12230
- if (!flushAlreadyScheduled) {
12256
+ this.pendingNavigation = {
12257
+ target,
12258
+ runNavigationCommands,
12259
+ callers: [...(superseded?.callers ?? []), { resolve, reject }],
12260
+ };
12261
+ if (!superseded) {
12231
12262
  this.runAfterRoutingSessionFinishes(() => this.flushPendingNavigation());
12232
12263
  }
12233
12264
  });
@@ -12240,18 +12271,19 @@ class PlaceRouter extends GarbageCollector {
12240
12271
  this.pendingNavigation = undefined;
12241
12272
  if (this.queuedNavigationDepth >= PlaceRouter.MAX_QUEUED_NAVIGATION_DEPTH) {
12242
12273
  Logger.get(this).warn(`Dropping queued navigation after ${this.queuedNavigationDepth} consecutive deferrals to ` +
12243
- `avoid a navigation loop.`, { visit: pending.visit?.toDebugString() });
12274
+ `avoid a navigation loop.`, { visit: resolveTarget(pending.target)?.toDebugString() });
12244
12275
  this.queuedNavigationDepth = 0;
12245
- pending.resolve();
12276
+ // Nothing navigated, so the route its callers read back is still the current one.
12277
+ pending.callers.forEach(caller => caller.resolve());
12246
12278
  return;
12247
12279
  }
12248
12280
  this.queuedNavigationDepth++;
12249
- this.doNavigation(pending.visit, pending.runNavigationCommands).then(() => {
12281
+ this.doNavigation(pending.target, pending.runNavigationCommands).then(() => {
12250
12282
  this.queuedNavigationDepth = 0;
12251
- pending.resolve();
12283
+ pending.callers.forEach(caller => caller.resolve());
12252
12284
  }, (error) => {
12253
12285
  this.queuedNavigationDepth = 0;
12254
- pending.reject(error);
12286
+ pending.callers.forEach(caller => caller.reject(error));
12255
12287
  });
12256
12288
  }
12257
12289
  navigateByUrl(urlSnapshot, navigationExtras) {
@@ -12268,8 +12300,6 @@ class PlaceRouter extends GarbageCollector {
12268
12300
  async notifyVisitSegmentChanged(is, was, metadata) {
12269
12301
  // console.log("PlaceRouter.notifyVisitSegmentChanged", is.toDebugString(), was.toDebugString());
12270
12302
  this.placeHistory.updateVisitSegment(is);
12271
- // FIXME: no route id -> route id duplicates route parameters
12272
- const visit = this.activeVisit$.value.copyAndReplaceSegment(is);
12273
12303
  if (is.hasRoutingChangedFrom(was)) {
12274
12304
  // An in-place parameter change (model -> route) pushes a history entry by default so a
12275
12305
  // deliberate selection is reachable via the back button. Automatic refinements
@@ -12279,7 +12309,9 @@ class PlaceRouter extends GarbageCollector {
12279
12309
  // that entry, and a pushed one would leave the pop on an entry that still holds the interaction. The closing
12280
12310
  // session then pushes the change after the entry it pops to (RemoveLastInteractionFromUrlNavigationSession).
12281
12311
  const replaceUrl = this.interactionService.isActive() || this.shouldReplaceHistory(metadata);
12282
- await this.doNavigation(visit, () => {
12312
+ // Both the visit and the url are built when the navigation runs, from what is current then.
12313
+ // FIXME: no route id -> route id duplicates route parameters
12314
+ await this.doNavigation(() => this.activeVisit$.value.copyAndReplaceSegment(is), () => {
12283
12315
  const urlSnapshot = this.urlService
12284
12316
  .parseUrl(this.angularRouter.routerState.snapshot.url)
12285
12317
  .updateVisitSegment(is);