reroute-js 0.5.0 → 0.7.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/README.md +142 -0
- package/_/basic/package.json +4 -4
- package/_/basic/src/client/index.html +1 -1
- package/_/basic/src/index.ts +1 -3
- package/_/blog/package.json +4 -4
- package/_/blog/src/client/App.tsx +1 -0
- package/_/blog/src/client/index.html +1 -1
- package/_/blog/src/client/routes/blog/content/1-hello-world.tsx +1 -1
- package/_/blog/src/client/routes/blog/content/3-markdown-with-syntax-highlighting.mdx +213 -0
- package/_/blog/src/client/routes/blog/content/4-content-in-markdown.md +143 -0
- package/_/blog/src/client/routes/blog/content/5-mdx-with-components.mdx +267 -0
- package/_/blog/src/client/routes/blog/index.tsx +59 -0
- package/_/blog/src/client/routes/client.tsx +564 -0
- package/_/blog/src/client/routes/docs.tsx +670 -0
- package/_/blog/src/client/routes/index.tsx +37 -0
- package/_/blog/src/client/routes/markdown-demo.md +169 -0
- package/_/blog/src/client/routes/markdown.tsx +160 -0
- package/_/blog/src/index.ts +5 -2
- package/_/store/package.json +4 -4
- package/_/store/src/client/index.html +1 -1
- package/_/store/src/index.ts +1 -1
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +1313 -74
- package/cli/bin.js.map +13 -7
- package/cli/index.d.ts +1 -1
- package/cli/index.js +428 -17
- package/cli/index.js.map +6 -3
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/boot.d.ts +1 -1
- package/cli/src/commands/build.d.ts +19 -0
- package/cli/src/commands/build.d.ts.map +1 -0
- package/cli/src/commands/dev.d.ts +18 -0
- package/cli/src/commands/dev.d.ts.map +1 -0
- package/cli/src/commands/gen.d.ts +1 -1
- package/cli/src/commands/gen.d.ts.map +1 -1
- package/cli/src/commands/init.d.ts +1 -1
- package/cli/src/commands/start.d.ts +19 -0
- package/cli/src/commands/start.d.ts.map +1 -0
- package/cli/src/libs/index.d.ts +4 -1
- package/cli/src/libs/index.d.ts.map +1 -1
- package/cli/src/libs/log.d.ts +46 -0
- package/cli/src/libs/log.d.ts.map +1 -0
- package/cli/src/libs/markdown-processor.d.ts +59 -0
- package/cli/src/libs/markdown-processor.d.ts.map +1 -0
- package/cli/src/libs/markdown.d.ts +33 -0
- package/cli/src/libs/markdown.d.ts.map +1 -0
- package/cli/src/libs/tailwind.d.ts +1 -1
- package/cli/src/libs/version.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +4 -4
- package/core/index.js.map +2 -2
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/bundler/transpile.d.ts +1 -1
- package/core/src/content/discovery.d.ts +1 -1
- package/core/src/content/index.d.ts +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/content/registry.d.ts +1 -1
- package/core/src/index.d.ts +1 -1
- package/core/src/ssr/data.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/modules.d.ts +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/seed.d.ts +1 -1
- package/core/src/template/html.d.ts +1 -1
- package/core/src/template/index.d.ts +1 -1
- package/core/src/types.d.ts +1 -1
- package/core/src/utils/cache.d.ts +1 -1
- package/core/src/utils/compression.d.ts +1 -1
- package/core/src/utils/index.d.ts +1 -1
- package/core/src/utils/mime.d.ts +1 -1
- package/core/src/utils/path.d.ts +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +4 -4
- package/elysia/index.js.map +2 -2
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/routes/artifacts.d.ts +1 -1
- package/elysia/src/routes/content.d.ts +1 -1
- package/elysia/src/routes/dev.d.ts +1 -1
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts +1 -1
- package/elysia/src/routes/static.d.ts +1 -1
- package/elysia/src/types.d.ts +1 -1
- package/package.json +22 -9
- package/react/index.d.ts +1 -1
- package/react/index.js +141 -36
- package/react/index.js.map +7 -6
- package/react/src/components/ClientOnly.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts.map +1 -1
- package/react/src/components/Image.d.ts +1 -1
- package/react/src/components/Link.d.ts +1 -1
- package/react/src/components/Link.d.ts.map +1 -1
- package/react/src/components/Markdown.d.ts +89 -0
- package/react/src/components/Markdown.d.ts.map +1 -0
- package/react/src/components/Outlet.d.ts +1 -1
- package/react/src/components/index.d.ts +2 -1
- package/react/src/components/index.d.ts.map +1 -1
- package/react/src/hooks/index.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts +1 -1
- package/react/src/hooks/useData.d.ts +1 -1
- package/react/src/hooks/useNavigate.d.ts +1 -1
- package/react/src/hooks/useParams.d.ts +1 -1
- package/react/src/hooks/useRouter.d.ts +1 -1
- package/react/src/hooks/useSearchParams.d.ts +1 -1
- package/react/src/index.d.ts +1 -1
- package/react/src/providers/ContentProvider.d.ts +1 -1
- package/react/src/providers/RerouteProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts.map +1 -1
- package/react/src/providers/index.d.ts +1 -1
- package/react/src/types/any.d.ts +1 -1
- package/react/src/types/index.d.ts +1 -1
- package/react/src/types/router.d.ts +1 -1
- package/react/src/utils/content.d.ts +1 -1
- package/react/src/utils/head.d.ts +1 -1
- package/react/src/utils/index.d.ts +1 -1
- package/_/blog/src/client/components/Counter.tsx +0 -14
package/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reroute-js v0.
|
|
2
|
+
* reroute-js v0.7.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2025 stewones <hi@stewan.io>
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
isValidElement,
|
|
31
31
|
useEffect as useEffect5,
|
|
32
32
|
useMemo as useMemo5,
|
|
33
|
+
useRef,
|
|
33
34
|
useState as useState5
|
|
34
35
|
} from "react";
|
|
35
36
|
|
|
@@ -406,6 +407,23 @@ function setScrollRestorationEnabled(enabled) {
|
|
|
406
407
|
scrollRestorationEnabled = enabled;
|
|
407
408
|
}
|
|
408
409
|
var scrollPositions = new Map;
|
|
410
|
+
function hasViewTransitionNames() {
|
|
411
|
+
if (!isBrowser2)
|
|
412
|
+
return false;
|
|
413
|
+
try {
|
|
414
|
+
const allElements = document.querySelectorAll("*");
|
|
415
|
+
for (const el of allElements) {
|
|
416
|
+
const computedStyle = window.getComputedStyle(el);
|
|
417
|
+
const transitionName = computedStyle.viewTransitionName;
|
|
418
|
+
if (transitionName && transitionName !== "none") {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
} catch {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
409
427
|
function navigateInternal(to, options = {}) {
|
|
410
428
|
if (!isBrowser2)
|
|
411
429
|
return;
|
|
@@ -437,7 +455,8 @@ function navigateInternal(to, options = {}) {
|
|
|
437
455
|
};
|
|
438
456
|
emitChange();
|
|
439
457
|
};
|
|
440
|
-
|
|
458
|
+
const shouldUseViewTransition = viewTransitionsEnabled && hasViewTransitionNames();
|
|
459
|
+
if (shouldUseViewTransition) {
|
|
441
460
|
document.startViewTransition(() => {
|
|
442
461
|
flushSync(() => {
|
|
443
462
|
updateState();
|
|
@@ -446,24 +465,24 @@ function navigateInternal(to, options = {}) {
|
|
|
446
465
|
} else {
|
|
447
466
|
updateState();
|
|
448
467
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
element
|
|
456
|
-
|
|
457
|
-
attempts
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
window.scrollTo({ top: 0, behavior: "instant" });
|
|
465
|
-
}
|
|
466
|
-
}
|
|
468
|
+
requestAnimationFrame(() => {
|
|
469
|
+
if (url.hash) {
|
|
470
|
+
let attempts = 0;
|
|
471
|
+
const maxAttempts = 10;
|
|
472
|
+
const tryScroll = () => {
|
|
473
|
+
const element = document.querySelector(url.hash);
|
|
474
|
+
if (element) {
|
|
475
|
+
element.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
476
|
+
} else if (attempts < maxAttempts) {
|
|
477
|
+
attempts++;
|
|
478
|
+
requestAnimationFrame(tryScroll);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
tryScroll();
|
|
482
|
+
} else {
|
|
483
|
+
window.scrollTo({ top: 0, left: 0, behavior: "instant" });
|
|
484
|
+
}
|
|
485
|
+
});
|
|
467
486
|
}
|
|
468
487
|
function RouterProvider({
|
|
469
488
|
children,
|
|
@@ -560,7 +579,8 @@ function RouterProvider({
|
|
|
560
579
|
currentLocation = next;
|
|
561
580
|
emitChange();
|
|
562
581
|
};
|
|
563
|
-
|
|
582
|
+
const shouldUseViewTransition = viewTransitionsEnabled && hasViewTransitionNames();
|
|
583
|
+
if (shouldUseViewTransition) {
|
|
564
584
|
document.startViewTransition(() => {
|
|
565
585
|
flushSync(() => {
|
|
566
586
|
updateState();
|
|
@@ -572,7 +592,7 @@ function RouterProvider({
|
|
|
572
592
|
if (scrollRestorationEnabled) {
|
|
573
593
|
const nextPath = next.pathname + next.search + next.hash;
|
|
574
594
|
const savedPosition = scrollPositions.get(nextPath);
|
|
575
|
-
|
|
595
|
+
const restoreScroll = () => {
|
|
576
596
|
if (next.hash) {
|
|
577
597
|
const element = document.querySelector(next.hash);
|
|
578
598
|
if (element) {
|
|
@@ -585,7 +605,14 @@ function RouterProvider({
|
|
|
585
605
|
behavior: "instant"
|
|
586
606
|
});
|
|
587
607
|
}
|
|
588
|
-
}
|
|
608
|
+
};
|
|
609
|
+
if (shouldUseViewTransition) {
|
|
610
|
+
requestAnimationFrame(() => {
|
|
611
|
+
requestAnimationFrame(restoreScroll);
|
|
612
|
+
});
|
|
613
|
+
} else {
|
|
614
|
+
requestAnimationFrame(restoreScroll);
|
|
615
|
+
}
|
|
589
616
|
}
|
|
590
617
|
};
|
|
591
618
|
window.addEventListener("popstate", handlePopState);
|
|
@@ -884,6 +911,7 @@ function ContentRoute({
|
|
|
884
911
|
const key = inferredName ? `${collection}:${inferredName}` : `${collection}:`;
|
|
885
912
|
const ctxGetEntry = useContentGetEntry();
|
|
886
913
|
const idx = useContentIndex();
|
|
914
|
+
const ensureCollection = useContentLoadCollection();
|
|
887
915
|
const resolveEntry = getEntry || ctxGetEntry || ((c, n) => {
|
|
888
916
|
try {
|
|
889
917
|
const list = idx?.[c];
|
|
@@ -920,6 +948,7 @@ function ContentRoute({
|
|
|
920
948
|
return () => null;
|
|
921
949
|
}, [key, entry]);
|
|
922
950
|
const [Comp, setComp] = useState5(() => initialComp);
|
|
951
|
+
const containerRef = useRef(null);
|
|
923
952
|
useEffect5(() => {
|
|
924
953
|
let cancelled = false;
|
|
925
954
|
if (entry?.module && typeof window !== "undefined") {
|
|
@@ -951,18 +980,59 @@ function ContentRoute({
|
|
|
951
980
|
applySsrHead(undefined);
|
|
952
981
|
};
|
|
953
982
|
}, [entry?.module, key]);
|
|
983
|
+
useEffect5(() => {
|
|
984
|
+
if (typeof window === "undefined")
|
|
985
|
+
return;
|
|
986
|
+
if (entry || !collection)
|
|
987
|
+
return;
|
|
988
|
+
try {
|
|
989
|
+
if (typeof ensureCollection === "function") {
|
|
990
|
+
ensureCollection(collection);
|
|
991
|
+
}
|
|
992
|
+
} catch {}
|
|
993
|
+
}, [collection, ensureCollection, entry]);
|
|
954
994
|
useEffect5(() => {
|
|
955
995
|
try {
|
|
956
996
|
if (entry && entry.meta)
|
|
957
997
|
applyPageMeta(entry.meta);
|
|
958
998
|
} catch {}
|
|
959
999
|
}, [entry]);
|
|
960
|
-
|
|
1000
|
+
useEffect5(() => {
|
|
1001
|
+
try {
|
|
1002
|
+
if (typeof window === "undefined")
|
|
1003
|
+
return;
|
|
1004
|
+
const isDev = typeof process !== "undefined" && (process.env?.NODE_ENV ?? "development") !== "production" || typeof document !== "undefined" && /^localhost|^127\.0\.0\.1/.test(window.location.hostname);
|
|
1005
|
+
if (!isDev)
|
|
1006
|
+
return;
|
|
1007
|
+
const root = containerRef.current;
|
|
1008
|
+
if (!root)
|
|
1009
|
+
return;
|
|
1010
|
+
const nested = root.querySelectorAll("p p");
|
|
1011
|
+
if (!nested.length) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
console.groupCollapsed(`[Reroute] DOM check: nested <p> found in ContentRoute (${key})`);
|
|
1015
|
+
nested.forEach((inner, idx2) => {
|
|
1016
|
+
const outer = inner.closest("p");
|
|
1017
|
+
const snippet = (el) => (el?.textContent || "").replace(/\s+/g, " ").trim().slice(0, 160);
|
|
1018
|
+
console.warn(`Case ${idx2 + 1}:`, {
|
|
1019
|
+
outerSnippet: snippet(outer),
|
|
1020
|
+
innerSnippet: snippet(inner)
|
|
1021
|
+
});
|
|
1022
|
+
});
|
|
1023
|
+
console.groupEnd();
|
|
1024
|
+
} catch {}
|
|
1025
|
+
}, [key]);
|
|
1026
|
+
return /* @__PURE__ */ jsx5("div", {
|
|
1027
|
+
"data-reroute": "content",
|
|
1028
|
+
ref: containerRef,
|
|
1029
|
+
children: /* @__PURE__ */ jsx5(Comp, {})
|
|
1030
|
+
});
|
|
961
1031
|
}
|
|
962
1032
|
// packages/react/src/components/Image.tsx
|
|
963
1033
|
import {
|
|
964
1034
|
useEffect as useEffect6,
|
|
965
|
-
useRef,
|
|
1035
|
+
useRef as useRef2,
|
|
966
1036
|
useState as useState6
|
|
967
1037
|
} from "react";
|
|
968
1038
|
import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
@@ -1023,7 +1093,7 @@ function Image({
|
|
|
1023
1093
|
}) {
|
|
1024
1094
|
const [isLoaded, setIsLoaded] = useState6(false);
|
|
1025
1095
|
const [hasError, setHasError] = useState6(false);
|
|
1026
|
-
const imgRef =
|
|
1096
|
+
const imgRef = useRef2(null);
|
|
1027
1097
|
const imageUrl = loader ? loader({ src, width: width || 0, quality, format }) : width ? defaultLoader({ src, width, quality, format }) : src;
|
|
1028
1098
|
useEffect6(() => {
|
|
1029
1099
|
const img = imgRef.current;
|
|
@@ -1167,7 +1237,7 @@ function Image({
|
|
|
1167
1237
|
});
|
|
1168
1238
|
}
|
|
1169
1239
|
// packages/react/src/components/Link.tsx
|
|
1170
|
-
import { useCallback as useCallback4, useMemo as useMemo6 } from "react";
|
|
1240
|
+
import { useCallback as useCallback4, useContext as useContext3, useMemo as useMemo6 } from "react";
|
|
1171
1241
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1172
1242
|
function Link({
|
|
1173
1243
|
to,
|
|
@@ -1180,15 +1250,24 @@ function Link({
|
|
|
1180
1250
|
onFocus,
|
|
1181
1251
|
...props
|
|
1182
1252
|
}) {
|
|
1183
|
-
const
|
|
1253
|
+
const routerContext = useContext3(RouterContext);
|
|
1254
|
+
const router = useRouter();
|
|
1184
1255
|
const resolver = useContentResolver();
|
|
1185
1256
|
const contentIndex = useContentIndex();
|
|
1186
1257
|
const ensureCollection = useContentLoadCollection();
|
|
1258
|
+
const hasRouter = !!routerContext;
|
|
1259
|
+
const { navigate, matchRoute } = router || {
|
|
1260
|
+
navigate: () => {},
|
|
1261
|
+
matchRoute: () => null
|
|
1262
|
+
};
|
|
1187
1263
|
const inferred = useMemo6(() => resolver ? resolver(String(to)) : undefined, [resolver, to]);
|
|
1188
1264
|
const handleClick = useCallback4(async (e) => {
|
|
1189
1265
|
if (onClick) {
|
|
1190
1266
|
onClick(e);
|
|
1191
1267
|
}
|
|
1268
|
+
if (!hasRouter) {
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1192
1271
|
if (e.defaultPrevented || e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || props.target === "_blank") {
|
|
1193
1272
|
return;
|
|
1194
1273
|
}
|
|
@@ -1241,7 +1320,8 @@ function Link({
|
|
|
1241
1320
|
prefetch,
|
|
1242
1321
|
inferred,
|
|
1243
1322
|
matchRoute,
|
|
1244
|
-
fragment
|
|
1323
|
+
fragment,
|
|
1324
|
+
hasRouter
|
|
1245
1325
|
]);
|
|
1246
1326
|
const handleMouseEnter = useCallback4((e) => {
|
|
1247
1327
|
if (prefetch && inferred && inferred.module)
|
|
@@ -1258,7 +1338,7 @@ function Link({
|
|
|
1258
1338
|
(async () => {
|
|
1259
1339
|
try {
|
|
1260
1340
|
const items = await ensureCollection(inferred.collection);
|
|
1261
|
-
const found = (items || []).find((
|
|
1341
|
+
const found = (items || []).find((item) => item?.name === inferred.name);
|
|
1262
1342
|
const mod = found?.module;
|
|
1263
1343
|
if (mod)
|
|
1264
1344
|
prefetchContent({ ...inferred, module: mod });
|
|
@@ -1312,7 +1392,7 @@ function Link({
|
|
|
1312
1392
|
(async () => {
|
|
1313
1393
|
try {
|
|
1314
1394
|
const items = await ensureCollection(inferred.collection);
|
|
1315
|
-
const found = (items || []).find((
|
|
1395
|
+
const found = (items || []).find((item) => item?.name === inferred.name);
|
|
1316
1396
|
const mod = found?.module;
|
|
1317
1397
|
if (mod)
|
|
1318
1398
|
prefetchContent({ ...inferred, module: mod });
|
|
@@ -1360,12 +1440,36 @@ function Link({
|
|
|
1360
1440
|
...props
|
|
1361
1441
|
});
|
|
1362
1442
|
}
|
|
1443
|
+
// packages/react/src/components/Markdown.tsx
|
|
1444
|
+
import ReactMarkdownLib from "react-markdown";
|
|
1445
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1446
|
+
function Markdown({
|
|
1447
|
+
children,
|
|
1448
|
+
className,
|
|
1449
|
+
skipHtml = false,
|
|
1450
|
+
components,
|
|
1451
|
+
remarkPlugins = [],
|
|
1452
|
+
rehypePlugins = []
|
|
1453
|
+
}) {
|
|
1454
|
+
const finalRemarkPlugins = [...remarkPlugins];
|
|
1455
|
+
const finalRehypePlugins = [...rehypePlugins];
|
|
1456
|
+
return /* @__PURE__ */ jsx8("div", {
|
|
1457
|
+
className,
|
|
1458
|
+
children: /* @__PURE__ */ jsx8(ReactMarkdownLib, {
|
|
1459
|
+
remarkPlugins: finalRemarkPlugins,
|
|
1460
|
+
rehypePlugins: finalRehypePlugins,
|
|
1461
|
+
skipHtml,
|
|
1462
|
+
components,
|
|
1463
|
+
children
|
|
1464
|
+
})
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1363
1467
|
// packages/react/src/components/Outlet.tsx
|
|
1364
|
-
import { useContext as
|
|
1365
|
-
import { jsx as
|
|
1468
|
+
import { useContext as useContext4 } from "react";
|
|
1469
|
+
import { jsx as jsx9, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
1366
1470
|
function Outlet() {
|
|
1367
|
-
const outletContent =
|
|
1368
|
-
return /* @__PURE__ */
|
|
1471
|
+
const outletContent = useContext4(OutletContext);
|
|
1472
|
+
return /* @__PURE__ */ jsx9(Fragment2, {
|
|
1369
1473
|
children: outletContent
|
|
1370
1474
|
});
|
|
1371
1475
|
}
|
|
@@ -1392,6 +1496,7 @@ export {
|
|
|
1392
1496
|
RerouteProvider,
|
|
1393
1497
|
OutletContext,
|
|
1394
1498
|
Outlet,
|
|
1499
|
+
Markdown,
|
|
1395
1500
|
Link,
|
|
1396
1501
|
Image,
|
|
1397
1502
|
ContentRoute,
|
|
@@ -1399,4 +1504,4 @@ export {
|
|
|
1399
1504
|
ClientOnly
|
|
1400
1505
|
};
|
|
1401
1506
|
|
|
1402
|
-
//# debugId=
|
|
1507
|
+
//# debugId=C9918CE64524583B64756E2164756E21
|