@pyreon/router 0.12.15 → 0.13.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/lib/analysis/index.js.html +1 -1
- package/lib/index.js +22 -5
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +0 -14
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/components.tsx +1 -0
- package/src/manifest.ts +336 -0
- package/src/router.ts +31 -13
- package/src/tests/manifest-snapshot.test.ts +97 -0
|
@@ -5386,7 +5386,7 @@ var drawChart = (function (exports) {
|
|
|
5386
5386
|
</script>
|
|
5387
5387
|
<script>
|
|
5388
5388
|
/*<!--*/
|
|
5389
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"
|
|
5389
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"aa1c31e3-1","name":"loader.ts"},{"uid":"aa1c31e3-3","name":"match.ts"},{"uid":"aa1c31e3-5","name":"scroll.ts"},{"uid":"aa1c31e3-7","name":"types.ts"},{"uid":"aa1c31e3-9","name":"router.ts"},{"uid":"aa1c31e3-11","name":"components.tsx"},{"uid":"aa1c31e3-13","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"aa1c31e3-1":{"renderedLength":2824,"gzipLength":1233,"brotliLength":0,"metaUid":"aa1c31e3-0"},"aa1c31e3-3":{"renderedLength":12203,"gzipLength":3691,"brotliLength":0,"metaUid":"aa1c31e3-2"},"aa1c31e3-5":{"renderedLength":2194,"gzipLength":899,"brotliLength":0,"metaUid":"aa1c31e3-4"},"aa1c31e3-7":{"renderedLength":385,"gzipLength":246,"brotliLength":0,"metaUid":"aa1c31e3-6"},"aa1c31e3-9":{"renderedLength":23568,"gzipLength":6469,"brotliLength":0,"metaUid":"aa1c31e3-8"},"aa1c31e3-11":{"renderedLength":7151,"gzipLength":2635,"brotliLength":0,"metaUid":"aa1c31e3-10"},"aa1c31e3-13":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"aa1c31e3-12"}},"nodeMetas":{"aa1c31e3-0":{"id":"/src/loader.ts","moduleParts":{"index.js":"aa1c31e3-1"},"imported":[{"uid":"aa1c31e3-14"}],"importedBy":[{"uid":"aa1c31e3-12"},{"uid":"aa1c31e3-10"}]},"aa1c31e3-2":{"id":"/src/match.ts","moduleParts":{"index.js":"aa1c31e3-3"},"imported":[],"importedBy":[{"uid":"aa1c31e3-12"},{"uid":"aa1c31e3-8"}]},"aa1c31e3-4":{"id":"/src/scroll.ts","moduleParts":{"index.js":"aa1c31e3-5"},"imported":[],"importedBy":[{"uid":"aa1c31e3-8"}]},"aa1c31e3-6":{"id":"/src/types.ts","moduleParts":{"index.js":"aa1c31e3-7"},"imported":[],"importedBy":[{"uid":"aa1c31e3-12"},{"uid":"aa1c31e3-8"}]},"aa1c31e3-8":{"id":"/src/router.ts","moduleParts":{"index.js":"aa1c31e3-9"},"imported":[{"uid":"aa1c31e3-14"},{"uid":"aa1c31e3-15"},{"uid":"aa1c31e3-2"},{"uid":"aa1c31e3-4"},{"uid":"aa1c31e3-6"}],"importedBy":[{"uid":"aa1c31e3-12"},{"uid":"aa1c31e3-10"}]},"aa1c31e3-10":{"id":"/src/components.tsx","moduleParts":{"index.js":"aa1c31e3-11"},"imported":[{"uid":"aa1c31e3-14"},{"uid":"aa1c31e3-0"},{"uid":"aa1c31e3-8"}],"importedBy":[{"uid":"aa1c31e3-12"}]},"aa1c31e3-12":{"id":"/src/index.ts","moduleParts":{"index.js":"aa1c31e3-13"},"imported":[{"uid":"aa1c31e3-10"},{"uid":"aa1c31e3-0"},{"uid":"aa1c31e3-2"},{"uid":"aa1c31e3-8"},{"uid":"aa1c31e3-6"}],"importedBy":[],"isEntry":true},"aa1c31e3-14":{"id":"@pyreon/core","moduleParts":{},"imported":[],"importedBy":[{"uid":"aa1c31e3-10"},{"uid":"aa1c31e3-0"},{"uid":"aa1c31e3-8"}]},"aa1c31e3-15":{"id":"@pyreon/reactivity","moduleParts":{},"imported":[],"importedBy":[{"uid":"aa1c31e3-8"}]}},"env":{"rollup":"4.23.0"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
5390
5390
|
|
|
5391
5391
|
const run = () => {
|
|
5392
5392
|
const width = window.innerWidth;
|
package/lib/index.js
CHANGED
|
@@ -662,17 +662,31 @@ function onBeforeRouteUpdate(guard) {
|
|
|
662
662
|
* })
|
|
663
663
|
* // later: blocker.remove()
|
|
664
664
|
*/
|
|
665
|
+
let _beforeUnloadRefCount = 0;
|
|
666
|
+
const _beforeUnloadHandler = (e) => {
|
|
667
|
+
e.preventDefault();
|
|
668
|
+
};
|
|
669
|
+
function retainBeforeUnload() {
|
|
670
|
+
if (!_isBrowser) return;
|
|
671
|
+
if (_beforeUnloadRefCount === 0) window.addEventListener("beforeunload", _beforeUnloadHandler);
|
|
672
|
+
_beforeUnloadRefCount++;
|
|
673
|
+
}
|
|
674
|
+
function releaseBeforeUnload() {
|
|
675
|
+
if (!_isBrowser) return;
|
|
676
|
+
_beforeUnloadRefCount--;
|
|
677
|
+
if (_beforeUnloadRefCount <= 0) {
|
|
678
|
+
_beforeUnloadRefCount = 0;
|
|
679
|
+
window.removeEventListener("beforeunload", _beforeUnloadHandler);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
665
682
|
function useBlocker(fn) {
|
|
666
683
|
const router = useContext(RouterContext) ?? _activeRouter;
|
|
667
684
|
if (!router) throw new Error("[Pyreon] No router installed. Wrap your app in <RouterProvider router={router}>.");
|
|
668
685
|
router._blockers.add(fn);
|
|
669
|
-
|
|
670
|
-
e.preventDefault();
|
|
671
|
-
} : null;
|
|
672
|
-
if (beforeUnloadHandler) window.addEventListener("beforeunload", beforeUnloadHandler);
|
|
686
|
+
retainBeforeUnload();
|
|
673
687
|
const remove = () => {
|
|
674
688
|
router._blockers.delete(fn);
|
|
675
|
-
|
|
689
|
+
releaseBeforeUnload();
|
|
676
690
|
};
|
|
677
691
|
onUnmount(() => remove());
|
|
678
692
|
return { remove };
|
|
@@ -1172,11 +1186,13 @@ function createRouter(options) {
|
|
|
1172
1186
|
if (_hashchangeHandler) window.removeEventListener("hashchange", _hashchangeHandler);
|
|
1173
1187
|
guards.length = 0;
|
|
1174
1188
|
afterHooks.length = 0;
|
|
1189
|
+
for (let i = router._blockers.size; i > 0; i--) releaseBeforeUnload();
|
|
1175
1190
|
router._blockers.clear();
|
|
1176
1191
|
componentCache.clear();
|
|
1177
1192
|
router._loaderData.clear();
|
|
1178
1193
|
router._abortController?.abort();
|
|
1179
1194
|
router._abortController = null;
|
|
1195
|
+
if (_activeRouter === router) _activeRouter = null;
|
|
1180
1196
|
},
|
|
1181
1197
|
_resolve: (rawPath) => resolveRoute(rawPath, routes)
|
|
1182
1198
|
};
|
|
@@ -1331,6 +1347,7 @@ const RouterLink = (props) => {
|
|
|
1331
1347
|
if (!router) return "";
|
|
1332
1348
|
const current = router.currentRoute().path;
|
|
1333
1349
|
const target = props.to;
|
|
1350
|
+
if (typeof target !== "string") return "";
|
|
1334
1351
|
const isExact = current === target;
|
|
1335
1352
|
const isActive = isExact || !props.exact && isSegmentPrefix(current, target);
|
|
1336
1353
|
const classes = [];
|