@ecopages/browser-router 0.2.0-alpha.25 → 0.2.0-alpha.27
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/browser-router",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.27",
|
|
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-alpha.
|
|
38
|
+
"@ecopages/core": "0.2.0-alpha.27"
|
|
39
39
|
},
|
|
40
40
|
"types": "./src/index.d.ts"
|
|
41
41
|
}
|
|
@@ -71,6 +71,7 @@ export declare class DomSwapper {
|
|
|
71
71
|
* @returns Always `false` to tell morphdom to skip updating this element.
|
|
72
72
|
*/
|
|
73
73
|
private replaceCustomElement;
|
|
74
|
+
private materializeCustomElement;
|
|
74
75
|
/**
|
|
75
76
|
* Replaces all deferred custom elements after morphdom has finished traversing.
|
|
76
77
|
*
|
|
@@ -235,9 +235,17 @@ class DomSwapper {
|
|
|
235
235
|
* @returns Always `false` to tell morphdom to skip updating this element.
|
|
236
236
|
*/
|
|
237
237
|
replaceCustomElement(fromEl, toEl, deferred) {
|
|
238
|
-
deferred.push({ from: fromEl, to: toEl });
|
|
238
|
+
deferred.push({ from: fromEl, to: toEl.cloneNode(true) });
|
|
239
239
|
return false;
|
|
240
240
|
}
|
|
241
|
+
materializeCustomElement(element) {
|
|
242
|
+
const materializedElement = document.createElement(element.localName);
|
|
243
|
+
for (const attr of element.attributes) {
|
|
244
|
+
materializedElement.setAttribute(attr.name, attr.value);
|
|
245
|
+
}
|
|
246
|
+
materializedElement.innerHTML = element.innerHTML;
|
|
247
|
+
return materializedElement;
|
|
248
|
+
}
|
|
241
249
|
/**
|
|
242
250
|
* Replaces all deferred custom elements after morphdom has finished traversing.
|
|
243
251
|
*
|
|
@@ -249,11 +257,7 @@ class DomSwapper {
|
|
|
249
257
|
flushDeferredCustomElementReplacements(deferred) {
|
|
250
258
|
for (const { from, to } of deferred) {
|
|
251
259
|
if (!from.isConnected) continue;
|
|
252
|
-
const newEl =
|
|
253
|
-
for (const attr of to.attributes) {
|
|
254
|
-
newEl.setAttribute(attr.name, attr.value);
|
|
255
|
-
}
|
|
256
|
-
newEl.innerHTML = to.innerHTML;
|
|
260
|
+
const newEl = this.materializeCustomElement(to);
|
|
257
261
|
from.replaceWith(newEl);
|
|
258
262
|
}
|
|
259
263
|
}
|
|
@@ -268,6 +272,12 @@ class DomSwapper {
|
|
|
268
272
|
const deferredReplacements = [];
|
|
269
273
|
morphdom(document.body, newDocument.body, {
|
|
270
274
|
getNodeKey: (node) => getBodyMorphKey(node, persistAttr),
|
|
275
|
+
onBeforeNodeAdded: (node) => {
|
|
276
|
+
if (node instanceof Element && this.isLightDomCustomElement(node)) {
|
|
277
|
+
return this.materializeCustomElement(node);
|
|
278
|
+
}
|
|
279
|
+
return node;
|
|
280
|
+
},
|
|
271
281
|
onBeforeElUpdated: (fromEl, toEl) => {
|
|
272
282
|
if (isPersisted(fromEl, persistAttr)) {
|
|
273
283
|
return false;
|