@ecopages/browser-router 0.2.0-beta.32 → 0.2.0-beta.34
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
CHANGED
|
@@ -127,7 +127,7 @@ Use `data-eco-reload` on an anchor tag to bypass the router and force a full pag
|
|
|
127
127
|
|
|
128
128
|
## Events
|
|
129
129
|
|
|
130
|
-
Listen to navigation lifecycle events on the `document
|
|
130
|
+
Listen to navigation lifecycle events on the `document`. Event detail types live in `@ecopages/core/router/navigation-lifecycle`.
|
|
131
131
|
|
|
132
132
|
```ts
|
|
133
133
|
document.addEventListener('eco:before-swap', (e) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/browser-router",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.34",
|
|
4
4
|
"description": "Client-side router for Ecopages with view transitions support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"morphdom": "^2.7.8"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@ecopages/core": "0.2.0-beta.
|
|
38
|
+
"@ecopages/core": "0.2.0-beta.34"
|
|
39
39
|
},
|
|
40
40
|
"types": "./src/index.d.ts"
|
|
41
41
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Client-side router for Ecopages with morphdom-based DOM diffing.
|
|
3
3
|
* @module eco-router
|
|
4
4
|
*/
|
|
5
|
-
import type
|
|
5
|
+
import { type EcoRouterOptions } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Intercepts same-origin link clicks and performs client-side navigation
|
|
8
8
|
* using morphdom for efficient DOM diffing. Supports View Transitions API.
|
package/src/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { EcoRouter, createRouter } from './eco-router.js';
|
|
2
2
|
export { syncDocumentElementAttributes } from './document-element-sync.js';
|
|
3
|
-
export { DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, type BrowserRouterNavigateOptions, type
|
|
3
|
+
export { DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, type BrowserRouterNavigateOptions, type EcoRouterOptions, } from './types.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type EcoNavigationEvent } from '@ecopages/core/router/navigation-lifecycle';
|
|
1
2
|
import type { DomSwapper } from './dom/dom-swapper.js';
|
|
2
3
|
import type { PrefetchManager } from './services/prefetch-manager.js';
|
|
3
4
|
import type { ViewTransitionManager } from './services/view-transition-manager.js';
|
|
4
|
-
import type {
|
|
5
|
+
import type { EcoRouterOptions } from './types.js';
|
|
5
6
|
export type NavigationCommitOptions = {
|
|
6
7
|
html?: string;
|
|
7
8
|
isStaleNavigation?: () => boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getEcoNavigationRuntime } from '@ecopages/core/router/navigation-coordinator';
|
|
2
|
+
import { completeNavigationLifecycle, dispatchBeforeSwap, } from '@ecopages/core/router/navigation-lifecycle';
|
|
2
3
|
import { manageWindowScroll } from '@ecopages/core/client/scroll';
|
|
3
4
|
import { syncDocumentElementAttributes } from './document-element-sync.js';
|
|
4
5
|
/**
|
|
@@ -26,20 +27,15 @@ export class NavigationCommit {
|
|
|
26
27
|
const shouldCleanupCurrentOwner = currentDocumentOwner !== newDocumentOwner &&
|
|
27
28
|
currentDocumentOwner !== 'browser-router' &&
|
|
28
29
|
activeOwner === currentDocumentOwner;
|
|
29
|
-
|
|
30
|
-
const beforeSwapEvent = {
|
|
30
|
+
const { requestedReload } = dispatchBeforeSwap(document, {
|
|
31
31
|
url,
|
|
32
32
|
direction,
|
|
33
33
|
newDocument,
|
|
34
|
-
|
|
35
|
-
shouldReload = true;
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
document.dispatchEvent(new CustomEvent('eco:before-swap', { detail: beforeSwapEvent }));
|
|
34
|
+
});
|
|
39
35
|
if (isStaleNavigation()) {
|
|
40
36
|
return false;
|
|
41
37
|
}
|
|
42
|
-
if (
|
|
38
|
+
if (requestedReload) {
|
|
43
39
|
if (shouldCleanupCurrentOwner) {
|
|
44
40
|
await navigationRuntime.cleanupOwner(currentDocumentOwner);
|
|
45
41
|
}
|
|
@@ -95,22 +91,11 @@ export class NavigationCommit {
|
|
|
95
91
|
return false;
|
|
96
92
|
}
|
|
97
93
|
navigationRuntime.adoptDocumentOwner(newDocument, 'browser-router');
|
|
98
|
-
|
|
99
|
-
url,
|
|
100
|
-
direction,
|
|
101
|
-
};
|
|
102
|
-
document.dispatchEvent(new CustomEvent('eco:after-swap', { detail: afterSwapEvent }));
|
|
94
|
+
completeNavigationLifecycle(document, { url, direction }, { isStale: isStaleNavigation });
|
|
103
95
|
this.prefetchManager?.observeLinks();
|
|
104
96
|
if (options.html) {
|
|
105
97
|
this.prefetchManager?.cacheVisitedPage(url.href, options.html);
|
|
106
98
|
}
|
|
107
|
-
requestAnimationFrame(() => {
|
|
108
|
-
if (isStaleNavigation())
|
|
109
|
-
return;
|
|
110
|
-
document.dispatchEvent(new CustomEvent('eco:page-load', {
|
|
111
|
-
detail: { url, direction },
|
|
112
|
-
}));
|
|
113
|
-
});
|
|
114
99
|
return true;
|
|
115
100
|
}
|
|
116
101
|
reloadDocument(href) {
|
package/src/client/types.d.ts
CHANGED
|
@@ -77,25 +77,6 @@ export interface EcoRouterOptions {
|
|
|
77
77
|
export type BrowserRouterNavigateOptions = {
|
|
78
78
|
direction?: 'forward' | 'back' | 'replace';
|
|
79
79
|
};
|
|
80
|
-
/** Events emitted during the navigation lifecycle */
|
|
81
|
-
export interface EcoNavigationEvent {
|
|
82
|
-
url: URL;
|
|
83
|
-
direction: 'forward' | 'back' | 'replace';
|
|
84
|
-
}
|
|
85
|
-
/** Event fired before the DOM swap occurs */
|
|
86
|
-
export interface EcoBeforeSwapEvent extends EcoNavigationEvent {
|
|
87
|
-
newDocument: Document;
|
|
88
|
-
reload: () => void;
|
|
89
|
-
}
|
|
90
|
-
/** Event fired after the DOM swap completes */
|
|
91
|
-
export interface EcoAfterSwapEvent extends EcoNavigationEvent {
|
|
92
|
-
}
|
|
93
|
-
/** Custom event map for navigation lifecycle */
|
|
94
|
-
export interface EcoRouterEventMap {
|
|
95
|
-
'eco:before-swap': CustomEvent<EcoBeforeSwapEvent>;
|
|
96
|
-
'eco:after-swap': CustomEvent<EcoAfterSwapEvent>;
|
|
97
|
-
'eco:page-load': CustomEvent<EcoNavigationEvent>;
|
|
98
|
-
}
|
|
99
80
|
/** Default document-level `<html>` attributes synchronized during navigation swaps. */
|
|
100
81
|
export declare const DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC: string[];
|
|
101
82
|
/** Default configuration options */
|
package/src/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Client-side navigation and view transitions for Ecopages
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export { createRouter, DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, EcoRouter, syncDocumentElementAttributes, type BrowserRouterNavigateOptions, type
|
|
6
|
+
export { createRouter, DEFAULT_DOCUMENT_ELEMENT_ATTRIBUTES_TO_SYNC, DEFAULT_OPTIONS, EcoRouter, syncDocumentElementAttributes, type BrowserRouterNavigateOptions, type EcoRouterOptions, } from './client/index.js';
|
|
7
7
|
export { DomSwapper } from './client/dom/dom-swapper.js';
|
|
8
8
|
export { ViewTransitionManager } from './client/services/view-transition-manager.js';
|