@ng-desktop/router 0.0.0-stage → 0.4.0
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/LICENSE +21 -0
- package/README.md +13 -2
- package/fesm2022/index.d.ts +3 -0
- package/fesm2022/index.js +3 -0
- package/fesm2022/platform-location.d.ts +42 -0
- package/fesm2022/platform-location.js +164 -0
- package/fesm2022/route-strategies.d.ts +38 -0
- package/fesm2022/route-strategies.js +129 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gaspar1992 and NgDesktop Engine Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ng-desktop/router
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DOM-free Angular Router PlatformLocation & navigation stack for Native GTK4 / WinUI 3 / AppKit windows
|
|
4
|
+
|
|
5
|
+
Part of **[NgDesktop Engine](https://github.com/Gaspar1992/ng-desktop-engine)** — Native desktop rendering engine for Angular 22+ (`GTK4`, `WinUI 3`, `AppKit`).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @ng-desktop/router
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Repository path: `packages/router-native`
|
|
14
|
+
- Documentation & Ecosystem Guide: https://github.com/Gaspar1992/ng-desktop-engine/blob/main/docs/ECOSYSTEM_COMPATIBILITY.md
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive, RouterOutlet, withComponentInputBinding, type Routes, } from '@angular/router';
|
|
2
|
+
export { NativePlatformLocation, provideNativeRouter } from './platform-location';
|
|
3
|
+
export { NATIVE_TITLE_PREFIX, NativeStackRouteReuseStrategy, NativeTitleStrategy, withNativeRouteReuse, withNativeTitleStrategy, } from './route-strategies';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive, RouterOutlet, withComponentInputBinding, } from '@angular/router';
|
|
2
|
+
export { NativePlatformLocation, provideNativeRouter } from './platform-location.js';
|
|
3
|
+
export { NATIVE_TITLE_PREFIX, NativeStackRouteReuseStrategy, NativeTitleStrategy, withNativeRouteReuse, withNativeTitleStrategy, } from './route-strategies.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type LocationChangeListener, PlatformLocation } from '@angular/common';
|
|
2
|
+
import { type EnvironmentProviders } from '@angular/core';
|
|
3
|
+
import { type RouterFeatures, type Routes } from '@angular/router';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* DOM-free Angular `PlatformLocation` implementation for native desktop applications.
|
|
7
|
+
* Maintains an in-memory URL and state history stack so `@angular/router` (`<router-outlet>`,
|
|
8
|
+
* `routerLink`, guards, resolvers, lazy loading) runs natively without `window.location`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class NativePlatformLocation extends PlatformLocation {
|
|
11
|
+
private readonly historyStack;
|
|
12
|
+
private currentIndex;
|
|
13
|
+
private readonly popStateListeners;
|
|
14
|
+
private readonly hashChangeListeners;
|
|
15
|
+
readonly hostname = "ng-native.local";
|
|
16
|
+
readonly protocol = "ng-native:";
|
|
17
|
+
readonly port = "";
|
|
18
|
+
getBaseHrefFromDOM(): string;
|
|
19
|
+
getState(): unknown;
|
|
20
|
+
onPopState(fn: LocationChangeListener): VoidFunction;
|
|
21
|
+
onHashChange(fn: LocationChangeListener): VoidFunction;
|
|
22
|
+
get href(): string;
|
|
23
|
+
get pathname(): string;
|
|
24
|
+
get search(): string;
|
|
25
|
+
get hash(): string;
|
|
26
|
+
replaceState(state: unknown, title: string, url: string): void;
|
|
27
|
+
pushState(state: unknown, title: string, url: string): void;
|
|
28
|
+
canGoBack(): boolean;
|
|
29
|
+
canGoForward(): boolean;
|
|
30
|
+
forward(): void;
|
|
31
|
+
back(): void;
|
|
32
|
+
historyGo(relativePosition?: number): void;
|
|
33
|
+
private notifyHashChange;
|
|
34
|
+
private currentEntry;
|
|
35
|
+
private normalizeUrl;
|
|
36
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativePlatformLocation, never>;
|
|
37
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Provides `@angular/router` backed by `NativePlatformLocation` for DOM-free native windows.
|
|
41
|
+
*/
|
|
42
|
+
export declare function provideNativeRouter(routes: Routes, ...features: RouterFeatures[]): EnvironmentProviders;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { PlatformLocation, } from '@angular/common';
|
|
2
|
+
import { Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
+
import { provideRouter } from '@angular/router';
|
|
4
|
+
import { withNativeTitleStrategy } from './route-strategies.js';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* DOM-free Angular `PlatformLocation` implementation for native desktop applications.
|
|
8
|
+
* Maintains an in-memory URL and state history stack so `@angular/router` (`<router-outlet>`,
|
|
9
|
+
* `routerLink`, guards, resolvers, lazy loading) runs natively without `window.location`.
|
|
10
|
+
*/
|
|
11
|
+
export class NativePlatformLocation extends PlatformLocation {
|
|
12
|
+
historyStack = [{ url: '/', title: '', state: null }];
|
|
13
|
+
currentIndex = 0;
|
|
14
|
+
popStateListeners = new Set();
|
|
15
|
+
hashChangeListeners = new Set();
|
|
16
|
+
hostname = 'ng-native.local';
|
|
17
|
+
protocol = 'ng-native:';
|
|
18
|
+
port = '';
|
|
19
|
+
getBaseHrefFromDOM() {
|
|
20
|
+
return '/';
|
|
21
|
+
}
|
|
22
|
+
getState() {
|
|
23
|
+
return this.currentEntry().state;
|
|
24
|
+
}
|
|
25
|
+
onPopState(fn) {
|
|
26
|
+
this.popStateListeners.add(fn);
|
|
27
|
+
return () => {
|
|
28
|
+
this.popStateListeners.delete(fn);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
onHashChange(fn) {
|
|
32
|
+
this.hashChangeListeners.add(fn);
|
|
33
|
+
return () => {
|
|
34
|
+
this.hashChangeListeners.delete(fn);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
get href() {
|
|
38
|
+
return `${this.protocol}//${this.hostname}${this.currentEntry().url}`;
|
|
39
|
+
}
|
|
40
|
+
get pathname() {
|
|
41
|
+
const raw = this.currentEntry().url;
|
|
42
|
+
const qIdx = raw.indexOf('?');
|
|
43
|
+
const hIdx = raw.indexOf('#');
|
|
44
|
+
const end = qIdx !== -1 && hIdx !== -1
|
|
45
|
+
? Math.min(qIdx, hIdx)
|
|
46
|
+
: qIdx !== -1
|
|
47
|
+
? qIdx
|
|
48
|
+
: hIdx !== -1
|
|
49
|
+
? hIdx
|
|
50
|
+
: raw.length;
|
|
51
|
+
return raw.slice(0, end) || '/';
|
|
52
|
+
}
|
|
53
|
+
get search() {
|
|
54
|
+
const raw = this.currentEntry().url;
|
|
55
|
+
const qIdx = raw.indexOf('?');
|
|
56
|
+
if (qIdx === -1) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
const hIdx = raw.indexOf('#', qIdx);
|
|
60
|
+
return hIdx === -1 ? raw.slice(qIdx) : raw.slice(qIdx, hIdx);
|
|
61
|
+
}
|
|
62
|
+
get hash() {
|
|
63
|
+
const raw = this.currentEntry().url;
|
|
64
|
+
const hIdx = raw.indexOf('#');
|
|
65
|
+
return hIdx === -1 ? '' : raw.slice(hIdx);
|
|
66
|
+
}
|
|
67
|
+
replaceState(state, title, url) {
|
|
68
|
+
const prevHash = this.hash;
|
|
69
|
+
this.historyStack[this.currentIndex] = {
|
|
70
|
+
url: this.normalizeUrl(url),
|
|
71
|
+
title,
|
|
72
|
+
state,
|
|
73
|
+
};
|
|
74
|
+
if (this.hash !== prevHash) {
|
|
75
|
+
this.notifyHashChange(state);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
pushState(state, title, url) {
|
|
79
|
+
const prevHash = this.hash;
|
|
80
|
+
this.historyStack.splice(this.currentIndex + 1);
|
|
81
|
+
this.historyStack.push({
|
|
82
|
+
url: this.normalizeUrl(url),
|
|
83
|
+
title,
|
|
84
|
+
state,
|
|
85
|
+
});
|
|
86
|
+
this.currentIndex = this.historyStack.length - 1;
|
|
87
|
+
if (this.hash !== prevHash) {
|
|
88
|
+
this.notifyHashChange(state);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
canGoBack() {
|
|
92
|
+
return this.currentIndex > 0;
|
|
93
|
+
}
|
|
94
|
+
canGoForward() {
|
|
95
|
+
return this.currentIndex + 1 < this.historyStack.length;
|
|
96
|
+
}
|
|
97
|
+
forward() {
|
|
98
|
+
this.historyGo(1);
|
|
99
|
+
}
|
|
100
|
+
back() {
|
|
101
|
+
this.historyGo(-1);
|
|
102
|
+
}
|
|
103
|
+
historyGo(relativePosition = 0) {
|
|
104
|
+
if (relativePosition === 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const nextIdx = this.currentIndex + relativePosition;
|
|
108
|
+
if (nextIdx < 0 || nextIdx >= this.historyStack.length) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const prevHash = this.hash;
|
|
112
|
+
this.currentIndex = nextIdx;
|
|
113
|
+
const state = this.currentEntry().state;
|
|
114
|
+
const evt = {
|
|
115
|
+
type: 'popstate',
|
|
116
|
+
state,
|
|
117
|
+
};
|
|
118
|
+
for (const listener of this.popStateListeners) {
|
|
119
|
+
listener(evt);
|
|
120
|
+
}
|
|
121
|
+
if (this.hash !== prevHash) {
|
|
122
|
+
this.notifyHashChange(state);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
notifyHashChange(state) {
|
|
126
|
+
const evt = {
|
|
127
|
+
type: 'hashchange',
|
|
128
|
+
state,
|
|
129
|
+
};
|
|
130
|
+
for (const listener of this.hashChangeListeners) {
|
|
131
|
+
listener(evt);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
currentEntry() {
|
|
135
|
+
return (this.historyStack[this.currentIndex] ?? {
|
|
136
|
+
url: '/',
|
|
137
|
+
title: '',
|
|
138
|
+
state: null,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
normalizeUrl(url) {
|
|
142
|
+
const trimmed = url.trim();
|
|
143
|
+
if (!trimmed) {
|
|
144
|
+
return '/';
|
|
145
|
+
}
|
|
146
|
+
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
|
|
147
|
+
}
|
|
148
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativePlatformLocation, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
149
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativePlatformLocation, providedIn: 'root' });
|
|
150
|
+
}
|
|
151
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativePlatformLocation, decorators: [{
|
|
152
|
+
type: Injectable,
|
|
153
|
+
args: [{ providedIn: 'root' }]
|
|
154
|
+
}] });
|
|
155
|
+
/**
|
|
156
|
+
* Provides `@angular/router` backed by `NativePlatformLocation` for DOM-free native windows.
|
|
157
|
+
*/
|
|
158
|
+
export function provideNativeRouter(routes, ...features) {
|
|
159
|
+
return makeEnvironmentProviders([
|
|
160
|
+
{ provide: PlatformLocation, useExisting: NativePlatformLocation },
|
|
161
|
+
provideRouter(routes, ...features),
|
|
162
|
+
withNativeTitleStrategy(),
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EnvironmentProviders, InjectionToken } from '@angular/core';
|
|
2
|
+
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy, RouterStateSnapshot, TitleStrategy } from '@angular/router';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export declare const NATIVE_TITLE_PREFIX: InjectionToken<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Angular `TitleStrategy` that mirrors active route titles directly onto the OS window
|
|
7
|
+
* (`gtk_window_set_title` / `NSWindow.title` / `AppWindow.Title`) via `NativeTitleService`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class NativeTitleStrategy extends TitleStrategy {
|
|
10
|
+
private readonly titleService;
|
|
11
|
+
private readonly appPrefix;
|
|
12
|
+
updateTitle(snapshot: RouterStateSnapshot): void;
|
|
13
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeTitleStrategy, never>;
|
|
14
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Bounded `RouteReuseStrategy` tailored for native desktop navigation stacks (`GtkStack` /
|
|
18
|
+
* `AdwNavigationView`): preserves mounted page handles so back/forward transitions stay instant
|
|
19
|
+
* with scroll, focus, and state intact.
|
|
20
|
+
*/
|
|
21
|
+
export declare class NativeStackRouteReuseStrategy implements RouteReuseStrategy {
|
|
22
|
+
private readonly handles;
|
|
23
|
+
private readonly maxCachedPages;
|
|
24
|
+
shouldDetach(route: ActivatedRouteSnapshot): boolean;
|
|
25
|
+
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void;
|
|
26
|
+
shouldAttach(route: ActivatedRouteSnapshot): boolean;
|
|
27
|
+
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null;
|
|
28
|
+
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
|
|
29
|
+
retrieveStoredRouteHandles(): DetachedRouteHandle[];
|
|
30
|
+
clearCache(): void;
|
|
31
|
+
private destroyDetachedHandle;
|
|
32
|
+
cachedRoutes(): string[];
|
|
33
|
+
private routeKey;
|
|
34
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NativeStackRouteReuseStrategy, never>;
|
|
35
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
36
|
+
}
|
|
37
|
+
export declare function withNativeTitleStrategy(appPrefix?: string): EnvironmentProviders;
|
|
38
|
+
export declare function withNativeRouteReuse(): EnvironmentProviders;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { inject, Injectable, InjectionToken, makeEnvironmentProviders, } from '@angular/core';
|
|
2
|
+
import { RouteReuseStrategy, TitleStrategy, } from '@angular/router';
|
|
3
|
+
import { NativeTitleService } from '@ng-desktop/platform';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export const NATIVE_TITLE_PREFIX = new InjectionToken('NATIVE_TITLE_PREFIX', {
|
|
6
|
+
providedIn: 'root',
|
|
7
|
+
factory: () => '',
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Angular `TitleStrategy` that mirrors active route titles directly onto the OS window
|
|
11
|
+
* (`gtk_window_set_title` / `NSWindow.title` / `AppWindow.Title`) via `NativeTitleService`.
|
|
12
|
+
*/
|
|
13
|
+
export class NativeTitleStrategy extends TitleStrategy {
|
|
14
|
+
titleService = inject(NativeTitleService);
|
|
15
|
+
appPrefix = inject(NATIVE_TITLE_PREFIX);
|
|
16
|
+
updateTitle(snapshot) {
|
|
17
|
+
const routeTitle = this.buildTitle(snapshot);
|
|
18
|
+
if (routeTitle !== undefined) {
|
|
19
|
+
const resolved = this.appPrefix ? `${this.appPrefix} — ${routeTitle}` : routeTitle;
|
|
20
|
+
this.titleService.setTitle(resolved);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeTitleStrategy, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
24
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeTitleStrategy, providedIn: 'root' });
|
|
25
|
+
}
|
|
26
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeTitleStrategy, decorators: [{
|
|
27
|
+
type: Injectable,
|
|
28
|
+
args: [{ providedIn: 'root' }]
|
|
29
|
+
}] });
|
|
30
|
+
/**
|
|
31
|
+
* Bounded `RouteReuseStrategy` tailored for native desktop navigation stacks (`GtkStack` /
|
|
32
|
+
* `AdwNavigationView`): preserves mounted page handles so back/forward transitions stay instant
|
|
33
|
+
* with scroll, focus, and state intact.
|
|
34
|
+
*/
|
|
35
|
+
export class NativeStackRouteReuseStrategy {
|
|
36
|
+
handles = new Map();
|
|
37
|
+
maxCachedPages = 16;
|
|
38
|
+
shouldDetach(route) {
|
|
39
|
+
if (!route.routeConfig || route.routeConfig.loadChildren) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return route.data['reuse'] !== false;
|
|
43
|
+
}
|
|
44
|
+
store(route, handle) {
|
|
45
|
+
const key = this.routeKey(route);
|
|
46
|
+
if (!key) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const existing = this.handles.get(key);
|
|
50
|
+
if (handle === null) {
|
|
51
|
+
this.destroyDetachedHandle(existing);
|
|
52
|
+
this.handles.delete(key);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (existing && existing !== handle) {
|
|
56
|
+
this.destroyDetachedHandle(existing);
|
|
57
|
+
}
|
|
58
|
+
if (!existing && this.handles.size >= this.maxCachedPages) {
|
|
59
|
+
const oldestKey = this.handles.keys().next().value;
|
|
60
|
+
if (oldestKey !== undefined) {
|
|
61
|
+
this.destroyDetachedHandle(this.handles.get(oldestKey));
|
|
62
|
+
this.handles.delete(oldestKey);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.handles.delete(key);
|
|
66
|
+
this.handles.set(key, handle);
|
|
67
|
+
}
|
|
68
|
+
shouldAttach(route) {
|
|
69
|
+
const key = this.routeKey(route);
|
|
70
|
+
return key.length > 0 && this.handles.has(key);
|
|
71
|
+
}
|
|
72
|
+
retrieve(route) {
|
|
73
|
+
const key = this.routeKey(route);
|
|
74
|
+
if (!key) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return this.handles.get(key) ?? null;
|
|
78
|
+
}
|
|
79
|
+
shouldReuseRoute(future, curr) {
|
|
80
|
+
return future.routeConfig === curr.routeConfig;
|
|
81
|
+
}
|
|
82
|
+
retrieveStoredRouteHandles() {
|
|
83
|
+
return Array.from(this.handles.values());
|
|
84
|
+
}
|
|
85
|
+
clearCache() {
|
|
86
|
+
for (const handle of this.handles.values()) {
|
|
87
|
+
this.destroyDetachedHandle(handle);
|
|
88
|
+
}
|
|
89
|
+
this.handles.clear();
|
|
90
|
+
}
|
|
91
|
+
destroyDetachedHandle(handle) {
|
|
92
|
+
if (!handle || typeof handle !== 'object') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const componentRef = handle.componentRef;
|
|
96
|
+
componentRef?.destroy?.();
|
|
97
|
+
}
|
|
98
|
+
cachedRoutes() {
|
|
99
|
+
return Array.from(this.handles.keys());
|
|
100
|
+
}
|
|
101
|
+
routeKey(route) {
|
|
102
|
+
const segments = route.pathFromRoot
|
|
103
|
+
.flatMap((snap) => snap.url.map((seg) => seg.path))
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
if (segments.length > 0) {
|
|
106
|
+
return `/${segments.join('/')}`;
|
|
107
|
+
}
|
|
108
|
+
return route.routeConfig?.path ?? '';
|
|
109
|
+
}
|
|
110
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeStackRouteReuseStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
111
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeStackRouteReuseStrategy, providedIn: 'root' });
|
|
112
|
+
}
|
|
113
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeStackRouteReuseStrategy, decorators: [{
|
|
114
|
+
type: Injectable,
|
|
115
|
+
args: [{ providedIn: 'root' }]
|
|
116
|
+
}] });
|
|
117
|
+
export function withNativeTitleStrategy(appPrefix = '') {
|
|
118
|
+
return makeEnvironmentProviders([
|
|
119
|
+
{ provide: NATIVE_TITLE_PREFIX, useValue: appPrefix },
|
|
120
|
+
NativeTitleStrategy,
|
|
121
|
+
{ provide: TitleStrategy, useExisting: NativeTitleStrategy },
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
export function withNativeRouteReuse() {
|
|
125
|
+
return makeEnvironmentProviders([
|
|
126
|
+
NativeStackRouteReuseStrategy,
|
|
127
|
+
{ provide: RouteReuseStrategy, useExisting: NativeStackRouteReuseStrategy },
|
|
128
|
+
]);
|
|
129
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-desktop/router",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "DOM-free Angular Router PlatformLocation & navigation stack for Native GTK4 / WinUI 3 / AppKit windows",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"angular",
|
|
8
|
+
"angular22",
|
|
9
|
+
"desktop",
|
|
10
|
+
"native",
|
|
11
|
+
"gtk4",
|
|
12
|
+
"winui3",
|
|
13
|
+
"appkit",
|
|
14
|
+
"rust"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/Gaspar1992/ng-desktop-engine",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Gaspar1992/ng-desktop-engine/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Gaspar1992/ng-desktop-engine.git",
|
|
23
|
+
"directory": "packages/router-native"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"files": [
|
|
31
|
+
"fesm2022",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"!**/*.map"
|
|
35
|
+
],
|
|
36
|
+
"main": "./fesm2022/index.js",
|
|
37
|
+
"module": "./fesm2022/index.js",
|
|
38
|
+
"types": "./fesm2022/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./fesm2022/index.d.ts",
|
|
42
|
+
"default": "./fesm2022/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": {
|
|
45
|
+
"default": "./package.json"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@angular/common": ">=22.0.0",
|
|
50
|
+
"@angular/core": ">=22.0.0",
|
|
51
|
+
"@angular/router": ">=22.0.0",
|
|
52
|
+
"@ng-desktop/platform": ">=0.4.0"
|
|
53
|
+
}
|
|
54
|
+
}
|