@ilha/router 0.11.10 → 0.11.11
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/dist/index.js +24 -23
- package/dist/server-island.js +13 -15
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -486,31 +486,32 @@ const resolveClickTarget = (_href, url) => {
|
|
|
486
486
|
}
|
|
487
487
|
return url.pathname + url.search + url.hash;
|
|
488
488
|
};
|
|
489
|
+
const onLinkClick = (event) => {
|
|
490
|
+
const mouseEvent = event;
|
|
491
|
+
if (mouseEvent.defaultPrevented || mouseEvent.button !== 0 || mouseEvent.metaKey || mouseEvent.ctrlKey || mouseEvent.shiftKey || mouseEvent.altKey) return;
|
|
492
|
+
const { target } = mouseEvent;
|
|
493
|
+
if (!(target instanceof Element)) return;
|
|
494
|
+
const anchor = target.closest("a");
|
|
495
|
+
if (!anchor || anchor.hasAttribute("download") || anchor.getAttribute("target") === "_blank" || anchor.matches("[data-no-intercept]")) return;
|
|
496
|
+
const href = anchor.getAttribute("href");
|
|
497
|
+
if (!href || NON_NAV_SCHEME.test(href)) return;
|
|
498
|
+
if (href.startsWith("#") && getHistoryMode() !== "hash") return;
|
|
499
|
+
if (href.startsWith("#") && !href.startsWith("#/")) return;
|
|
500
|
+
let url;
|
|
501
|
+
try {
|
|
502
|
+
url = new URL(href, location.href);
|
|
503
|
+
} catch {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (url.origin !== location.origin) return;
|
|
507
|
+
mouseEvent.preventDefault();
|
|
508
|
+
navigate(resolveClickTarget(href, url));
|
|
509
|
+
};
|
|
489
510
|
const enableLinkInterception = (root = document, _options = {}) => {
|
|
490
511
|
if (!isBrowser) return noop;
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const { target } = mouseEvent;
|
|
495
|
-
if (!(target instanceof Element)) return;
|
|
496
|
-
const anchor = target.closest("a");
|
|
497
|
-
if (!anchor || anchor.hasAttribute("download") || anchor.getAttribute("target") === "_blank" || anchor.matches("[data-no-intercept]")) return;
|
|
498
|
-
const href = anchor.getAttribute("href");
|
|
499
|
-
if (!href || NON_NAV_SCHEME.test(href)) return;
|
|
500
|
-
if (href.startsWith("#") && getHistoryMode() !== "hash") return;
|
|
501
|
-
if (href.startsWith("#") && !href.startsWith("#/")) return;
|
|
502
|
-
let url;
|
|
503
|
-
try {
|
|
504
|
-
url = new URL(href, location.href);
|
|
505
|
-
} catch {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
if (url.origin !== location.origin) return;
|
|
509
|
-
mouseEvent.preventDefault();
|
|
510
|
-
navigate(resolveClickTarget(href, url));
|
|
511
|
-
};
|
|
512
|
-
root.addEventListener("click", clickHandler);
|
|
513
|
-
return () => root.removeEventListener("click", clickHandler);
|
|
512
|
+
const listener = { handleEvent: onLinkClick };
|
|
513
|
+
root.addEventListener("click", listener);
|
|
514
|
+
return () => root.removeEventListener("click", listener);
|
|
514
515
|
};
|
|
515
516
|
const isActive = (pattern, options = {}) => {
|
|
516
517
|
if (options.end) return _path === pattern;
|
package/dist/server-island.js
CHANGED
|
@@ -178,15 +178,15 @@ const hydrateServerIsland = (host, id, wiring, props, moduleKey) => {
|
|
|
178
178
|
const actionFn = actionKey === null || actionKey === void 0 ? void 0 : wiring.actions?.[actionKey];
|
|
179
179
|
if (!actionFn) continue;
|
|
180
180
|
const boundKey = actionKey;
|
|
181
|
+
const run = async () => {
|
|
182
|
+
try {
|
|
183
|
+
await Promise.resolve(actionFn(...callArgs));
|
|
184
|
+
hooks.repaintModule();
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error(`[ilha-router] action "${String(boundKey)}" failed:`, error);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
181
189
|
const listener = () => {
|
|
182
|
-
const run = async () => {
|
|
183
|
-
try {
|
|
184
|
-
await Promise.resolve(actionFn(...callArgs));
|
|
185
|
-
hooks.repaintModule();
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error(`[ilha-router] action "${String(boundKey)}" failed:`, error);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
190
|
run();
|
|
191
191
|
};
|
|
192
192
|
el.addEventListener(eventType, listener);
|
|
@@ -209,14 +209,12 @@ const hydrateServerIsland = (host, id, wiring, props, moduleKey) => {
|
|
|
209
209
|
if (!actionFn) continue;
|
|
210
210
|
let args = [];
|
|
211
211
|
if (Array.isArray(marker.a)) args = marker.a;
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return result;
|
|
217
|
-
};
|
|
218
|
-
return run();
|
|
212
|
+
const run = async () => {
|
|
213
|
+
const result = await Promise.resolve(actionFn(...args));
|
|
214
|
+
hooks.repaintModule();
|
|
215
|
+
return result;
|
|
219
216
|
};
|
|
217
|
+
const revived = (..._runtimeArgs) => run();
|
|
220
218
|
Object.assign(next, { [key]: revived });
|
|
221
219
|
}
|
|
222
220
|
return next;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ilha/router",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11",
|
|
4
4
|
"description": "A tiny SPA router for Ilha",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"frontend",
|
|
@@ -73,12 +73,12 @@
|
|
|
73
73
|
"unplugin": "3.3.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"ilha": "^0.14.
|
|
76
|
+
"ilha": "^0.14.8",
|
|
77
77
|
"oxidejs": "^0.5.7",
|
|
78
|
-
"vite": "^8.
|
|
78
|
+
"vite": "^8.3.1"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"ilha": ">=0.14.
|
|
81
|
+
"ilha": ">=0.14.8",
|
|
82
82
|
"oxidejs": ">=0.5.7"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|