@real-router/angular 0.24.4 → 0.24.6
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.
|
@@ -12,46 +12,56 @@ function createDirectionTracker(router) {
|
|
|
12
12
|
if (typeof document === "undefined") return NOOP_INSTANCE$4;
|
|
13
13
|
let popstateFlag = false;
|
|
14
14
|
document.documentElement.dataset.navDirection = "forward";
|
|
15
|
-
let
|
|
16
|
-
let
|
|
17
|
-
const
|
|
18
|
-
const state = router.getState();
|
|
15
|
+
let inFlight;
|
|
16
|
+
let replay;
|
|
17
|
+
const hrefOf = (state) => {
|
|
19
18
|
const buildUrl = router.buildUrl;
|
|
20
|
-
if (
|
|
19
|
+
if (buildUrl === void 0) return;
|
|
21
20
|
try {
|
|
22
21
|
const hash = state.context?.url?.hash;
|
|
23
22
|
const url = buildUrl(state.name, state.params, state.search, hash ? { hash } : void 0);
|
|
24
|
-
return url
|
|
23
|
+
return url === void 0 ? void 0 : new URL(url, globalThis.location.href).href;
|
|
25
24
|
} catch {
|
|
26
|
-
return
|
|
25
|
+
return;
|
|
27
26
|
}
|
|
28
27
|
};
|
|
28
|
+
const landsOnRouterState = () => {
|
|
29
|
+
const state = router.getState();
|
|
30
|
+
return state !== void 0 && hrefOf(state) === globalThis.location.href;
|
|
31
|
+
};
|
|
29
32
|
const onPopstate = () => {
|
|
30
|
-
if (landsOnRouterState())
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
if (landsOnRouterState()) {
|
|
34
|
+
if (inFlight === void 0) popstateFlag = false;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (inFlight === void 0) popstateFlag = true;
|
|
38
|
+
else replay = globalThis.location.href;
|
|
33
39
|
};
|
|
34
40
|
globalThis.addEventListener("popstate", onPopstate);
|
|
35
41
|
const api = getPluginApi(router);
|
|
36
42
|
const onSettled = () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
inFlight = void 0;
|
|
44
|
+
popstateFlag = replay !== void 0;
|
|
45
|
+
replay = void 0;
|
|
46
|
+
};
|
|
47
|
+
const onError = (toState) => {
|
|
48
|
+
if (inFlight === void 0 || toState?.context === inFlight.context) {
|
|
49
|
+
onSettled();
|
|
40
50
|
return;
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
const href = toState === void 0 ? void 0 : hrefOf(toState);
|
|
53
|
+
if (href === void 0 || href === replay) replay = void 0;
|
|
43
54
|
};
|
|
44
55
|
const unsubs = [
|
|
45
|
-
api.addEventListener(events.TRANSITION_START, () => {
|
|
46
|
-
|
|
56
|
+
api.addEventListener(events.TRANSITION_START, (toState) => {
|
|
57
|
+
inFlight = toState;
|
|
47
58
|
}),
|
|
48
59
|
api.addEventListener(events.TRANSITION_SUCCESS, onSettled),
|
|
49
|
-
api.addEventListener(events.TRANSITION_ERROR,
|
|
60
|
+
api.addEventListener(events.TRANSITION_ERROR, onError),
|
|
50
61
|
api.addEventListener(events.TRANSITION_CANCEL, onSettled),
|
|
51
62
|
router.subscribeLeave(() => {
|
|
52
63
|
document.documentElement.dataset.navDirection = popstateFlag ? "back" : "forward";
|
|
53
64
|
popstateFlag = false;
|
|
54
|
-
armedMidTransition = false;
|
|
55
65
|
})
|
|
56
66
|
];
|
|
57
67
|
return { destroy: () => {
|
|
@@ -78,7 +88,6 @@ function createRouteAnnouncer(router, options) {
|
|
|
78
88
|
if (typeof document === "undefined") return NOOP_INSTANCE$3;
|
|
79
89
|
const prefix = options?.prefix ?? "Navigated to ";
|
|
80
90
|
const getCustomText = options?.getAnnouncementText;
|
|
81
|
-
let isInitialNavigation = true;
|
|
82
91
|
let isReady = false;
|
|
83
92
|
let isDestroyed = false;
|
|
84
93
|
let lastAnnouncedText = "";
|
|
@@ -104,9 +113,10 @@ function createRouteAnnouncer(router, options) {
|
|
|
104
113
|
doAnnounce(text, document.querySelector("h1"));
|
|
105
114
|
}
|
|
106
115
|
}, SAFARI_READY_DELAY);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
let initialLoadPending = router.getState() === void 0;
|
|
117
|
+
const unsubscribe = router.subscribe(({ route, previousRoute }) => {
|
|
118
|
+
if (previousRoute === void 0 && initialLoadPending) {
|
|
119
|
+
initialLoadPending = false;
|
|
110
120
|
return;
|
|
111
121
|
}
|
|
112
122
|
requestAnimationFrame(() => {
|