@coolon/angular-ui-powerups 16.1.0-alpha.271 → 16.1.0-alpha.273
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.
- package/esm2022/lib/place/guards/place.guard.mjs +16 -2
- package/esm2022/lib/place/navigation/session/interactions/navigating-during-interaction.mjs +11 -1
- package/esm2022/lib/place/navigation/session/interactions/pop-state-during-interaction-navigation.mjs +6 -1
- package/esm2022/lib/place/navigation/session/navigation-context.mjs +4 -2
- package/esm2022/lib/place/navigation/session/navigation-session.mjs +4 -4
- package/esm2022/lib/place/navigation/session/pop-state-navigation.mjs +11 -1
- package/esm2022/lib/place/place-router.mjs +49 -31
- package/esm2022/lib/place/url-snapshot.mjs +27 -4
- package/esm2022/lib/place/visit.mjs +12 -3
- package/fesm2022/coolon-angular-ui-powerups.mjs +129 -39
- package/fesm2022/coolon-angular-ui-powerups.mjs.map +1 -1
- package/lib/place/guards/place.guard.d.ts +10 -0
- package/lib/place/navigation/session/navigation-context.d.ts +9 -1
- package/lib/place/navigation/session/navigation-session.d.ts +3 -3
- package/lib/place/place-router.d.ts +22 -8
- package/package.json +2 -2
|
@@ -9062,8 +9062,17 @@ class Visit {
|
|
|
9062
9062
|
return this.segments.find(v => v.placeDefinition === placeDefinition);
|
|
9063
9063
|
}
|
|
9064
9064
|
getRouterCommands() {
|
|
9065
|
-
return this.segments.reduce((result, v) => {
|
|
9065
|
+
return this.segments.reduce((result, v, index) => {
|
|
9066
9066
|
const path = v.placeDefinition.path;
|
|
9067
|
+
// A NON-terminal route-id segment must have a resolved id: createRouterCommands omits a nil
|
|
9068
|
+
// id, so the next place's path would silently bind into the id slot (e.g. groups/:g followed
|
|
9069
|
+
// by a child serialises as groups/<child>, navigating to a "circuit" called <child>). A
|
|
9070
|
+
// TERMINAL nil id is fine — the generated `<path> -> <path>/` redirect supplies the empty
|
|
9071
|
+
// slot and the guard's sanitiser takes it from there.
|
|
9072
|
+
if (index < this.segments.length - 1 && v.placeDefinition.hasRouteId() && !v.hasRouteId()) {
|
|
9073
|
+
lang$1.illegalState(`can't build a url for '${this.destinationPlaceDef.path}' while ancestor '${path}' has no route id — ` +
|
|
9074
|
+
`the child path would bind into the empty id slot`);
|
|
9075
|
+
}
|
|
9067
9076
|
return isEmpty(path) ?
|
|
9068
9077
|
[...result, path] : // Angular doesn't support route params on empty path segments
|
|
9069
9078
|
[...result, path, ...v.createRouterCommands()];
|
|
@@ -9207,9 +9216,9 @@ class NavigationSession extends GarbageCollector {
|
|
|
9207
9216
|
}
|
|
9208
9217
|
/**
|
|
9209
9218
|
* Interruptible sessions are internal housekeeping navigations (e.g. interaction-id
|
|
9210
|
-
* synchronisation)
|
|
9211
|
-
*
|
|
9212
|
-
*
|
|
9219
|
+
* synchronisation). Historically only these queued an overlapping navigation while real
|
|
9220
|
+
* navigations dropped it; ALL overlapping navigations now queue (see
|
|
9221
|
+
* PlaceRouter.handleOverlappingNavigation), so this flag is diagnostic only.
|
|
9213
9222
|
*/
|
|
9214
9223
|
get isInterruptible() {
|
|
9215
9224
|
return this.isInteractionSync;
|
|
@@ -9589,6 +9598,11 @@ class NavigatingDuringInteraction extends NavigationSession {
|
|
|
9589
9598
|
isPopState = false;
|
|
9590
9599
|
// @Trace()
|
|
9591
9600
|
onRouterCancelled(event) {
|
|
9601
|
+
// A guard/sanitiser redirect is the navigation continuing — keep the session for the chain
|
|
9602
|
+
// (see Navigating / PopStateNavigation).
|
|
9603
|
+
if (event.code === 0 /* NavigationCancellationCode.Redirect */) {
|
|
9604
|
+
return;
|
|
9605
|
+
}
|
|
9592
9606
|
this.context.finishRoutingSession();
|
|
9593
9607
|
}
|
|
9594
9608
|
// @Trace()
|
|
@@ -9599,6 +9613,11 @@ class NavigatingDuringInteraction extends NavigationSession {
|
|
|
9599
9613
|
// @Trace()
|
|
9600
9614
|
onRouterEnd(event) {
|
|
9601
9615
|
if (this.context.routerInteractionAdapter.isActive()) {
|
|
9616
|
+
// The sync handover's own finish is deliberately visitless, so record the completed visit
|
|
9617
|
+
// HERE — dropping it left activeVisit$ (and remember/rememberLastChild history) stale, and a
|
|
9618
|
+
// later navigate() then built its url from an id-less groups-style segment, collapsing the
|
|
9619
|
+
// child path into the route-id slot.
|
|
9620
|
+
this.context.recordVisit(this.createUpdatedVisit(event.urlAfterRedirects));
|
|
9602
9621
|
this.context.transitionTo(new SynchroniseInteractionContextIdsWithRoute(this.context, this.startingUrl, false));
|
|
9603
9622
|
}
|
|
9604
9623
|
else {
|
|
@@ -9639,6 +9658,11 @@ class PopStateDuringInteractionNavigation extends AbstractPopStateNavigation {
|
|
|
9639
9658
|
*/
|
|
9640
9659
|
// @Trace()
|
|
9641
9660
|
onRouterCancelled(event) {
|
|
9661
|
+
// A guard/sanitiser redirect is the navigation continuing, not the refusal this handler was
|
|
9662
|
+
// written for — keep the session and let the redirect chain run (see PopStateNavigation).
|
|
9663
|
+
if (event.code === 0 /* NavigationCancellationCode.Redirect */) {
|
|
9664
|
+
return;
|
|
9665
|
+
}
|
|
9642
9666
|
this.repairBrowserHistoryAndUrlAfterGuardCancellation();
|
|
9643
9667
|
// NOTE: for now we need to wasTriggeredByPopState=false because we're resetting the url and history in the previous line.
|
|
9644
9668
|
this.context.transitionTo(new SynchroniseInteractionContextIdsWithRoute(this.context, this.poppedHistoryUrl, false));
|
|
@@ -9842,12 +9866,14 @@ var NavigationContext;
|
|
|
9842
9866
|
navigateByUrl;
|
|
9843
9867
|
transitionTo;
|
|
9844
9868
|
finishRoutingSession;
|
|
9845
|
-
|
|
9869
|
+
recordVisit;
|
|
9870
|
+
constructor(urlService, routerInteractionAdapter, navigateByUrl, transitionTo, finishRoutingSession, recordVisit) {
|
|
9846
9871
|
this.urlService = urlService;
|
|
9847
9872
|
this.routerInteractionAdapter = routerInteractionAdapter;
|
|
9848
9873
|
this.navigateByUrl = navigateByUrl;
|
|
9849
9874
|
this.transitionTo = transitionTo;
|
|
9850
9875
|
this.finishRoutingSession = finishRoutingSession;
|
|
9876
|
+
this.recordVisit = recordVisit;
|
|
9851
9877
|
}
|
|
9852
9878
|
}
|
|
9853
9879
|
NavigationContext.Impl = Impl;
|
|
@@ -9920,6 +9946,16 @@ class WaitUntilPopStateDuringCanDeactivateInteractionFinishes extends EventClean
|
|
|
9920
9946
|
|
|
9921
9947
|
class PopStateNavigation extends AbstractPopStateNavigation {
|
|
9922
9948
|
onRouterCancelled(event) {
|
|
9949
|
+
// A guard/sanitiser redirect is the navigation CONTINUING, not a rejection: keep the session
|
|
9950
|
+
// (as Navigating does) and repair nothing. Angular replaces the popped entry with the redirect
|
|
9951
|
+
// target for browser-triggered navigations, so history collapses correctly by itself — the
|
|
9952
|
+
// repair's replace+push here was what stranded the popped entry and made Back appear dead
|
|
9953
|
+
// (see the DEFECT PIN in place-router.spec.ts and master-detail-sanitiser-back.cy.ts).
|
|
9954
|
+
if (event.code === 0 /* NavigationCancellationCode.Redirect */) {
|
|
9955
|
+
return;
|
|
9956
|
+
}
|
|
9957
|
+
// A genuine rejection (e.g. canDeactivate refusal): the browser has already moved even though
|
|
9958
|
+
// the app refused, so restore it — the angular #13586 workaround.
|
|
9923
9959
|
this.repairBrowserHistoryAndUrlAfterGuardCancellation();
|
|
9924
9960
|
this.context.finishRoutingSession();
|
|
9925
9961
|
}
|
|
@@ -10307,14 +10343,29 @@ class UrlSnapshot {
|
|
|
10307
10343
|
const segments = [...extractPrimaryUrlSegments(newUrlTree)];
|
|
10308
10344
|
const urlSegments = this.getUrlSegmentsForVisitSegment(visitSegment);
|
|
10309
10345
|
const replaceAt = segments.findIndex(segment => segment.path === urlSegments[0].path);
|
|
10346
|
+
if (replaceAt < 0) {
|
|
10347
|
+
// findIndex's -1 would silently splice from the END, replacing unrelated segments.
|
|
10348
|
+
lang.illegalState(`updateVisitSegment: place '${visitSegment.placeDefinition.path}' is not in the url '${this.url}'`);
|
|
10349
|
+
}
|
|
10310
10350
|
// do not use the return value, it's the items that were removed!
|
|
10311
10351
|
segments.splice(replaceAt, urlSegments.length, ...urlSegments);
|
|
10312
10352
|
newUrlTree.root.children.primary.segments = segments;
|
|
10313
10353
|
return new UrlSnapshot(this.urlSerializer, newUrlTree.toString());
|
|
10314
10354
|
}
|
|
10315
10355
|
appendSegment(visitSegment) {
|
|
10316
|
-
//
|
|
10317
|
-
|
|
10356
|
+
// Tree-based, not string concatenation: concatenating onto the raw url appended after any
|
|
10357
|
+
// query string, and an empty route-id segment followed by a child serialises as `//`, which
|
|
10358
|
+
// Angular's parser silently truncates at — losing the child.
|
|
10359
|
+
const newUrlTree = this.urlSerializer.parse(this.url);
|
|
10360
|
+
const segments = [...extractPrimaryUrlSegments(newUrlTree)];
|
|
10361
|
+
if (last(segments)?.path === '') {
|
|
10362
|
+
// An empty trailing segment is an unresolved route id; a child appended after it is
|
|
10363
|
+
// unrepresentable in the URL (see above). Callers must resolve the id first.
|
|
10364
|
+
lang.illegalState(`appendSegment: can't append '${visitSegment.placeDefinition.path}' after an unresolved route id in '${this.url}'`);
|
|
10365
|
+
}
|
|
10366
|
+
segments.push(...this.getUrlSegmentsForVisitSegment(visitSegment));
|
|
10367
|
+
newUrlTree.root.children.primary.segments = segments;
|
|
10368
|
+
return new UrlSnapshot(this.urlSerializer, newUrlTree.toString());
|
|
10318
10369
|
}
|
|
10319
10370
|
getPrimaryUrlSegments() {
|
|
10320
10371
|
return extractPrimaryUrlSegments(this.urlTree);
|
|
@@ -10341,7 +10392,14 @@ class UrlSnapshot {
|
|
|
10341
10392
|
return this.getPrimaryUrlSegments().find(s => s.path === placeDef.path);
|
|
10342
10393
|
}
|
|
10343
10394
|
isLastPlaceInUrl(placeDef) {
|
|
10344
|
-
|
|
10395
|
+
const segments = this.getPrimaryUrlSegments();
|
|
10396
|
+
if (placeDef.hasRouteId()) {
|
|
10397
|
+
// A route-id place occupies TWO segments: its path plus the id slot (which is the empty
|
|
10398
|
+
// string when the id is unset — see getFormattedRouteId). The url terminates at the place
|
|
10399
|
+
// when its path is the second-to-last segment.
|
|
10400
|
+
return segments.length >= 2 && segments[segments.length - 2].path === placeDef.path;
|
|
10401
|
+
}
|
|
10402
|
+
return last(segments)?.path === placeDef.path;
|
|
10345
10403
|
}
|
|
10346
10404
|
createVisitSegmentFor(placeDef) {
|
|
10347
10405
|
return new VisitSegment(placeDef, new ConsolidatedParameterMap(this.getPrimaryUrlSegments()));
|
|
@@ -10516,6 +10574,8 @@ class PlaceRouter extends GarbageCollector {
|
|
|
10516
10574
|
this.transitionTo(state);
|
|
10517
10575
|
}, (segments) => {
|
|
10518
10576
|
this.routingSessionFinished(segments);
|
|
10577
|
+
}, (visit) => {
|
|
10578
|
+
this.recordFinishedVisit(visit);
|
|
10519
10579
|
});
|
|
10520
10580
|
const { chain } = Dsl.disposeWith(this);
|
|
10521
10581
|
this.navigationInProgress$ = chain(this.navigationSession$).isNotNil();
|
|
@@ -10698,15 +10758,18 @@ class PlaceRouter extends GarbageCollector {
|
|
|
10698
10758
|
}
|
|
10699
10759
|
}
|
|
10700
10760
|
/**
|
|
10701
|
-
* Handles a navigation triggered while another is already in flight
|
|
10761
|
+
* Handles a navigation triggered while another is already in flight: queue it (coalescing to the
|
|
10762
|
+
* latest) and run it once the in-flight session finishes.
|
|
10702
10763
|
*
|
|
10703
|
-
*
|
|
10704
|
-
* triggering action
|
|
10705
|
-
*
|
|
10706
|
-
*
|
|
10707
|
-
*
|
|
10708
|
-
*
|
|
10709
|
-
*
|
|
10764
|
+
* History: this used to throw `illegalState('Navigation already in progress')` (killed the
|
|
10765
|
+
* triggering action), then dropped real-vs-real collisions as an interim policy pending
|
|
10766
|
+
* production evidence. The evidence arrived: a `navigate()` issued from `onPlaceReady` or a
|
|
10767
|
+
* route-parameter subscription can land while the activating navigation's session is still
|
|
10768
|
+
* settling — dropping it leaves a place that never finishes navigating (e.g. a
|
|
10769
|
+
* redirectToFirstChild-style child that never appears), and the caller can't tell because the
|
|
10770
|
+
* dropped promise resolved normally. Popstate never enters doNavigation (it arrives via router
|
|
10771
|
+
* events -> onPopState), so queueing programmatic navigations behind an in-flight session
|
|
10772
|
+
* preserves user-intent ordering.
|
|
10710
10773
|
*/
|
|
10711
10774
|
handleOverlappingNavigation(visit, runNavigationCommands) {
|
|
10712
10775
|
const current = this.navigationSession;
|
|
@@ -10722,19 +10785,9 @@ class PlaceRouter extends GarbageCollector {
|
|
|
10722
10785
|
incoming: visit?.toDebugString(),
|
|
10723
10786
|
currentUrl: this.urlService.getCurrentRouterUrl(),
|
|
10724
10787
|
};
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
return this.queueNavigation(visit, runNavigationCommands);
|
|
10729
|
-
}
|
|
10730
|
-
// NOTE (interim policy): when a *real* navigation is already in progress we keep the first and
|
|
10731
|
-
// drop the incoming one, logging full context so we can see what actually collides in
|
|
10732
|
-
// production. We deliberately do NOT queue+coalesce here yet - once production logs show which
|
|
10733
|
-
// real-vs-real collisions occur we can decide whether "latest wins (queued)" is the better
|
|
10734
|
-
// behaviour. See the implementation plan for the queue+coalesce alternative.
|
|
10735
|
-
Logger.get(this).warn(`Navigation already in progress ('${current?.name}'); ignoring the incoming navigation. ` +
|
|
10736
|
-
`Review this if it occurs in production - it may need to be queued instead.`, debug);
|
|
10737
|
-
return Promise.resolve();
|
|
10788
|
+
Logger.get(this).warn(`Navigation triggered while session '${current?.name}' is in progress; ` +
|
|
10789
|
+
`queueing the incoming navigation to run once it finishes.`, debug);
|
|
10790
|
+
return this.queueNavigation(visit, runNavigationCommands);
|
|
10738
10791
|
}
|
|
10739
10792
|
queueNavigation(visit, runNavigationCommands) {
|
|
10740
10793
|
const flushAlreadyScheduled = !!this.pendingNavigation;
|
|
@@ -10825,21 +10878,37 @@ class PlaceRouter extends GarbageCollector {
|
|
|
10825
10878
|
routingSessionFinished(visit) {
|
|
10826
10879
|
if (visit) {
|
|
10827
10880
|
assert.isTruthy(this.navigationInProgress$.value);
|
|
10828
|
-
this.
|
|
10829
|
-
// We update the active visits before we finish the session so the
|
|
10830
|
-
// place outlets can ignore the incoming changes until things are settled.
|
|
10831
|
-
this._activeVisit$.value = visit;
|
|
10832
|
-
// console.log(visit.toDebugString())
|
|
10881
|
+
this.recordFinishedVisit(visit);
|
|
10833
10882
|
}
|
|
10834
10883
|
const session = this.currentSession;
|
|
10835
10884
|
session.dispose();
|
|
10836
10885
|
this.navigationSession$.value = null;
|
|
10837
10886
|
// console.log(`### Router Session Finished (was ${session.toString()})`);
|
|
10838
|
-
|
|
10887
|
+
// Snapshot-and-swap: jobs registered DURING the drain (e.g. the interaction-id sync's nested
|
|
10888
|
+
// completion job, or a queued navigation re-queueing) belong to the NEXT session finish. The
|
|
10889
|
+
// old forEach-then-reassign both skipped them (forEach doesn't visit appended items) and then
|
|
10890
|
+
// discarded them.
|
|
10891
|
+
const jobs = this.sessionFinishedJobs;
|
|
10839
10892
|
this.sessionFinishedJobs = [];
|
|
10893
|
+
jobs.forEach((job) => job());
|
|
10894
|
+
}
|
|
10895
|
+
/**
|
|
10896
|
+
* Records a completed navigation's visit without finishing the session. Shared by the normal
|
|
10897
|
+
* finish path and sessions that hand over to visitless housekeeping (see
|
|
10898
|
+
* NavigationContext.recordVisit).
|
|
10899
|
+
*/
|
|
10900
|
+
recordFinishedVisit(visit) {
|
|
10901
|
+
this.placeHistory.notifyNavigationFinished(visit);
|
|
10902
|
+
// We update the active visits before we finish the session so the
|
|
10903
|
+
// place outlets can ignore the incoming changes until things are settled.
|
|
10904
|
+
this._activeVisit$.value = visit;
|
|
10840
10905
|
}
|
|
10906
|
+
/**
|
|
10907
|
+
* Runs `func` when the NEXT navigation session finishes — which may be a session that hasn't
|
|
10908
|
+
* started yet (the interaction-id sync registers its completion job before starting the sync
|
|
10909
|
+
* session, and jobs registered while a drain is running belong to the following session).
|
|
10910
|
+
*/
|
|
10841
10911
|
runAfterRoutingSessionFinishes(func) {
|
|
10842
|
-
assert.isTruthy(this.navigationInProgress$);
|
|
10843
10912
|
this.sessionFinishedJobs.push(func);
|
|
10844
10913
|
}
|
|
10845
10914
|
/**
|
|
@@ -10855,14 +10924,21 @@ class PlaceRouter extends GarbageCollector {
|
|
|
10855
10924
|
// console.log(`Navigation active -> ${this.navigationSession.toString()}, sync delayed until finished.`);
|
|
10856
10925
|
// const session = this.navigationSession;
|
|
10857
10926
|
return new Promise((resolve) => {
|
|
10858
|
-
|
|
10927
|
+
const startSyncWhenIdle = () => {
|
|
10928
|
+
if (this.navigationSession) {
|
|
10929
|
+
// A job drained before us (e.g. a queued navigation) already started a new session;
|
|
10930
|
+
// transitioning now would dispose it mid-flight. Re-defer until that one finishes.
|
|
10931
|
+
this.runAfterRoutingSessionFinishes(startSyncWhenIdle);
|
|
10932
|
+
return;
|
|
10933
|
+
}
|
|
10859
10934
|
this.runAfterRoutingSessionFinishes(() => {
|
|
10860
10935
|
onSyncComplete();
|
|
10861
10936
|
resolve();
|
|
10862
10937
|
});
|
|
10863
10938
|
const syncSession = new SynchroniseInteractionContextIdsWithRoute(this.navigationContext, this.urlService.getCurrentRouterUrl(), false);
|
|
10864
10939
|
this.transitionTo(syncSession);
|
|
10865
|
-
}
|
|
10940
|
+
};
|
|
10941
|
+
this.runAfterRoutingSessionFinishes(startSyncWhenIdle);
|
|
10866
10942
|
});
|
|
10867
10943
|
}
|
|
10868
10944
|
else {
|
|
@@ -14313,7 +14389,7 @@ class PlaceGuard {
|
|
|
14313
14389
|
}
|
|
14314
14390
|
else {
|
|
14315
14391
|
// Our visit parameters are all sorted, now check if we should redirect to our child.
|
|
14316
|
-
if (
|
|
14392
|
+
if (this.shouldRedirectToChild(placeDefinition, destUrlSnapshot, sanitisedVisit)) {
|
|
14317
14393
|
if (placeDefinition.children.length < 1) {
|
|
14318
14394
|
lang.illegalState(`redirectToFirstChild set to true, but there were no children `);
|
|
14319
14395
|
}
|
|
@@ -14333,6 +14409,20 @@ class PlaceGuard {
|
|
|
14333
14409
|
return lang.illegalState(`expected component to be an instance of PlaceComponent, got ${activatedRoute.component}`);
|
|
14334
14410
|
}
|
|
14335
14411
|
}
|
|
14412
|
+
/**
|
|
14413
|
+
* Whether this guard pass should append a child segment to the url.
|
|
14414
|
+
*
|
|
14415
|
+
* For a route-id place the redirect must wait until the id is RESOLVED: an empty id followed by
|
|
14416
|
+
* a child is unrepresentable in the url (it serialises as `//`, which Angular's parser silently
|
|
14417
|
+
* truncates at). The check reads the SANITISED visit — the post-remember/default/sanitiser
|
|
14418
|
+
* truth — so a sanitiser-supplied id redirects on the corrected-url pass, and an id supplied
|
|
14419
|
+
* later (e.g. a selection model's auto-selection) redirects on that navigation's guard run.
|
|
14420
|
+
*/
|
|
14421
|
+
shouldRedirectToChild(placeDefinition, destUrlSnapshot, sanitisedVisit) {
|
|
14422
|
+
return placeDefinition.redirectToFirstChild
|
|
14423
|
+
&& destUrlSnapshot.isLastPlaceInUrl(placeDefinition)
|
|
14424
|
+
&& (!placeDefinition.hasRouteId() || sanitisedVisit.hasRouteId());
|
|
14425
|
+
}
|
|
14336
14426
|
/**
|
|
14337
14427
|
* Chooses the child to redirect to when {@link PlaceDefinition.redirectToFirstChild} is set. When
|
|
14338
14428
|
* `rememberLastChild` is enabled (the default) and we have a record of the last active child that is
|