@real-router/angular 0.10.0 → 0.11.1
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/README.md +23 -2
- package/dist/README.md +23 -2
- package/dist/fesm2022/real-router-angular.mjs +533 -20
- package/dist/fesm2022/real-router-angular.mjs.map +1 -1
- package/dist/types/real-router-angular.d.ts +62 -0
- package/dist/types/real-router-angular.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/dom-utils/index.ts +4 -0
- package/src/dom-utils/scroll-restore.ts +99 -12
- package/src/dom-utils/scroll-spy.ts +688 -0
- package/src/internal/install.ts +15 -2
- package/src/providers.ts +13 -1
- package/src/providersFactory.ts +21 -3
package/src/internal/install.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ApplicationRef, DestroyRef, inject } from "@angular/core";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createScrollRestoration,
|
|
5
|
+
createScrollSpy,
|
|
6
|
+
createViewTransitions,
|
|
7
|
+
} from "../dom-utils";
|
|
4
8
|
import { ROUTER } from "../providers";
|
|
5
9
|
|
|
6
|
-
import type { ScrollRestorationOptions } from "../dom-utils";
|
|
10
|
+
import type { ScrollRestorationOptions, ScrollSpyOptions } from "../dom-utils";
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Shared installation helpers for `provideRealRouter` and
|
|
@@ -27,6 +31,15 @@ export function installScrollRestoration(
|
|
|
27
31
|
});
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
export function installScrollSpy(options: ScrollSpyOptions): void {
|
|
35
|
+
const router = inject(ROUTER);
|
|
36
|
+
const spy = createScrollSpy(router, options);
|
|
37
|
+
|
|
38
|
+
inject(DestroyRef).onDestroy(() => {
|
|
39
|
+
spy.destroy();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
export function installViewTransitions(): void {
|
|
31
44
|
const router = inject(ROUTER);
|
|
32
45
|
|
package/src/providers.ts
CHANGED
|
@@ -9,11 +9,12 @@ import { createRouteSource } from "@real-router/sources";
|
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
installScrollRestoration,
|
|
12
|
+
installScrollSpy,
|
|
12
13
|
installViewTransitions,
|
|
13
14
|
} from "./internal/install";
|
|
14
15
|
import { sourceToSignal } from "./sourceToSignal";
|
|
15
16
|
|
|
16
|
-
import type { ScrollRestorationOptions } from "./dom-utils";
|
|
17
|
+
import type { ScrollRestorationOptions, ScrollSpyOptions } from "./dom-utils";
|
|
17
18
|
import type { RouteSignals } from "./types";
|
|
18
19
|
|
|
19
20
|
export const ROUTER = new InjectionToken<Router>("ROUTER");
|
|
@@ -24,6 +25,7 @@ export const ROUTE = new InjectionToken<RouteSignals>("ROUTE");
|
|
|
24
25
|
|
|
25
26
|
export interface RealRouterOptions {
|
|
26
27
|
scrollRestoration?: ScrollRestorationOptions;
|
|
28
|
+
scrollSpy?: ScrollSpyOptions;
|
|
27
29
|
viewTransitions?: boolean;
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -60,6 +62,16 @@ export function provideRealRouter(
|
|
|
60
62
|
);
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
if (options?.scrollSpy && options.scrollSpy.selector !== "") {
|
|
66
|
+
const spyOpts = options.scrollSpy;
|
|
67
|
+
|
|
68
|
+
providers.push(
|
|
69
|
+
provideEnvironmentInitializer(() => {
|
|
70
|
+
installScrollSpy(spyOpts);
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
if (options?.viewTransitions === true) {
|
|
64
76
|
providers.push(provideEnvironmentInitializer(installViewTransitions));
|
|
65
77
|
}
|
package/src/providersFactory.ts
CHANGED
|
@@ -21,12 +21,13 @@ import { createRouteSource } from "@real-router/sources";
|
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
23
|
installScrollRestoration,
|
|
24
|
+
installScrollSpy,
|
|
24
25
|
installViewTransitions,
|
|
25
26
|
} from "./internal/install";
|
|
26
27
|
import { NAVIGATOR, ROUTE, ROUTER } from "./providers";
|
|
27
28
|
import { sourceToSignal } from "./sourceToSignal";
|
|
28
29
|
|
|
29
|
-
import type { ScrollRestorationOptions } from "./dom-utils";
|
|
30
|
+
import type { ScrollRestorationOptions, ScrollSpyOptions } from "./dom-utils";
|
|
30
31
|
import type { RouteSignals } from "./types";
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -124,6 +125,9 @@ export interface RealRouterFactoryOptions<
|
|
|
124
125
|
/** Optional scroll restoration — same semantics as `provideRealRouter`. */
|
|
125
126
|
scrollRestoration?: ScrollRestorationOptions;
|
|
126
127
|
|
|
128
|
+
/** Optional scroll spy — same semantics as `provideRealRouter`. */
|
|
129
|
+
scrollSpy?: ScrollSpyOptions;
|
|
130
|
+
|
|
127
131
|
/** Optional view transitions — same semantics as `provideRealRouter`. */
|
|
128
132
|
viewTransitions?: boolean;
|
|
129
133
|
}
|
|
@@ -156,8 +160,14 @@ export interface RealRouterFactoryOptions<
|
|
|
156
160
|
export function provideRealRouterFactory<
|
|
157
161
|
TDeps extends DefaultDependencies = DefaultDependencies,
|
|
158
162
|
>(options: RealRouterFactoryOptions<TDeps>): EnvironmentProviders {
|
|
159
|
-
const {
|
|
160
|
-
|
|
163
|
+
const {
|
|
164
|
+
baseRouter,
|
|
165
|
+
plugins,
|
|
166
|
+
deps,
|
|
167
|
+
scrollRestoration,
|
|
168
|
+
scrollSpy,
|
|
169
|
+
viewTransitions,
|
|
170
|
+
} = options;
|
|
161
171
|
|
|
162
172
|
const providers: Parameters<typeof makeEnvironmentProviders>[0] = [
|
|
163
173
|
{
|
|
@@ -270,6 +280,14 @@ export function provideRealRouterFactory<
|
|
|
270
280
|
);
|
|
271
281
|
}
|
|
272
282
|
|
|
283
|
+
if (scrollSpy && scrollSpy.selector !== "") {
|
|
284
|
+
providers.push(
|
|
285
|
+
provideEnvironmentInitializer(() => {
|
|
286
|
+
installScrollSpy(scrollSpy);
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
273
291
|
if (viewTransitions === true) {
|
|
274
292
|
providers.push(provideEnvironmentInitializer(installViewTransitions));
|
|
275
293
|
}
|