@rspress/core 0.1.1 → 1.0.0-beta.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.
Files changed (42) hide show
  1. package/dist/index.js +62 -24
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +1 -1
  4. package/dist/loader.js +17 -33
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.js +4 -4
  7. package/dist/runtime/Content.js +14 -2
  8. package/dist/runtime/hooks.d.ts +17 -0
  9. package/dist/runtime/hooks.js +27 -1
  10. package/dist/runtime/index.d.ts +1 -1
  11. package/dist/runtime/index.js +1 -1
  12. package/dist/runtime/utils.d.ts +3 -2
  13. package/dist/runtime/utils.js +6 -2
  14. package/dist/theme/bundle.css +44 -4
  15. package/dist/theme/bundle.d.ts +6 -1
  16. package/dist/theme/bundle.js +150 -77
  17. package/dist/theme/bundle.js.map +1 -1
  18. package/package.json +7 -7
  19. package/src/runtime/App.tsx +5 -6
  20. package/src/runtime/Content.tsx +24 -2
  21. package/src/runtime/global.d.ts +4 -5
  22. package/src/runtime/hooks.ts +67 -1
  23. package/src/runtime/index.ts +1 -1
  24. package/src/runtime/utils.ts +9 -8
  25. package/src/theme-default/components/DocFooter/index.tsx +1 -1
  26. package/src/theme-default/components/HomeHero/index.tsx +1 -1
  27. package/src/theme-default/components/Link/index.module.scss +0 -1
  28. package/src/theme-default/components/Link/index.tsx +21 -2
  29. package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +1 -1
  30. package/src/theme-default/components/Nav/index.tsx +19 -5
  31. package/src/theme-default/components/Overview/index.tsx +1 -1
  32. package/src/theme-default/components/Search/logic/search.ts +1 -1
  33. package/src/theme-default/components/Sidebar/SidebarGroup.tsx +1 -1
  34. package/src/theme-default/components/Sidebar/SidebarItem.tsx +1 -1
  35. package/src/theme-default/index.ts +2 -0
  36. package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +4 -0
  37. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +14 -23
  38. package/src/theme-default/layout/DocLayout/index.module.scss +46 -0
  39. package/src/theme-default/layout/HomeLayout/index.tsx +1 -0
  40. package/src/theme-default/logic/index.ts +1 -0
  41. package/src/theme-default/logic/sideEffects.ts +7 -0
  42. package/src/theme-default/logic/usePathUtils.ts +73 -0
@@ -27,10 +27,9 @@ export async function initPageData(routePath) {
27
27
  // eslint-disable-next-line prefer-const
28
28
  toc = [],
29
29
  // eslint-disable-next-line prefer-const
30
- title = "",
31
- frontmatter
32
- } = globalThis.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
33
- frontmatter = frontmatter || mod.frontmatter || {};
30
+ title = ""
31
+ } = mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
32
+ const frontmatter = mod.frontmatter || {};
34
33
  return {
35
34
  siteData,
36
35
  page: {
@@ -59,6 +58,7 @@ export async function initPageData(routePath) {
59
58
  frontmatter: {},
60
59
  title: "404",
61
60
  toc: [],
61
+ version: "",
62
62
  _filepath: "",
63
63
  _relativePath: ""
64
64
  }
@@ -1,8 +1,18 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Suspense } from "react";
2
+ import { Suspense, memo } from "react";
3
3
  import { matchRoutes, useLocation } from "react-router-dom";
4
+ import siteData from "virtual-site-data";
4
5
  import { normalizeRoutePath } from "./utils";
6
+ import { useViewTransition } from "./hooks";
5
7
  const { routes } = process.env.__SSR__ ? require("virtual-routes-ssr") : require("virtual-routes");
8
+ function TransitionContentImpl(props) {
9
+ let element = props.el;
10
+ if (siteData?.themeConfig?.enableContentAnimation) {
11
+ element = useViewTransition(props.el);
12
+ }
13
+ return element;
14
+ }
15
+ const TransitionContent = /* @__PURE__ */ memo(TransitionContentImpl, (prevProps, nextProps) => prevProps.el === nextProps.el);
6
16
  export const Content = ({ fallback = /* @__PURE__ */ _jsx(_Fragment, {}) }) => {
7
17
  const { pathname } = useLocation();
8
18
  const matched = matchRoutes(routes, normalizeRoutePath(pathname));
@@ -15,6 +25,8 @@ export const Content = ({ fallback = /* @__PURE__ */ _jsx(_Fragment, {}) }) => {
15
25
  }
16
26
  return /* @__PURE__ */ _jsx(Suspense, {
17
27
  fallback,
18
- children: routesElement
28
+ children: /* @__PURE__ */ _jsx(TransitionContent, {
29
+ el: routesElement
30
+ })
19
31
  });
20
32
  };
@@ -17,6 +17,23 @@ export declare const DataContext: import("react").Context<IDataContext>;
17
17
  export declare const ThemeContext: import("react").Context<IThemeContext>;
18
18
  export declare function usePageData(): PageData;
19
19
  export declare function useLang(): string;
20
+ export declare function useVersion(): string;
20
21
  export declare function useDark(): boolean;
21
22
  export declare function useI18n<T = Record<string, Record<string, string>>>(): (key: keyof T) => any;
23
+ declare global {
24
+ interface Document {
25
+ startViewTransition: (callback: () => void) => void;
26
+ }
27
+ }
28
+ /**
29
+ * There is a pitfall.
30
+ * I was working on the navigation between pages with hash. eg. from `guide/start` -> `config/repress#nav`
31
+ * I need a time to dispatch an event so that the sideEffect.ts would know that
32
+ * the dom is attached to the browser. Otherwise the scroll position and the
33
+ * animation would be incorrect. You can search for `RspressReloadContent` in this codebase
34
+ * to findout the logic that are consuming the event.
35
+ * The reason I didn't write it here is that I hope the logic of handling scroll and position
36
+ * could be in one place so that people wouldn't be confused.
37
+ */
38
+ export declare function useViewTransition(dom: any): any;
22
39
  export {};
@@ -1,5 +1,6 @@
1
- import { createContext, useContext } from "react";
1
+ import { createContext, useContext, useLayoutEffect, useState } from "react";
2
2
  import i18nTextData from "virtual-i18n-text";
3
+ import { flushSync } from "react-dom";
3
4
  export const DataContext = createContext({});
4
5
  export const ThemeContext = createContext({});
5
6
  export function usePageData() {
@@ -10,6 +11,10 @@ export function useLang() {
10
11
  const ctx = useContext(DataContext);
11
12
  return ctx.data.page.lang || "";
12
13
  }
14
+ export function useVersion() {
15
+ const ctx = useContext(DataContext);
16
+ return ctx.data.page.version || "";
17
+ }
13
18
  export function useDark() {
14
19
  const ctx = useContext(ThemeContext);
15
20
  return ctx.theme === "dark";
@@ -18,3 +23,24 @@ export function useI18n() {
18
23
  const lang = useLang();
19
24
  return (key) => i18nTextData[key][lang];
20
25
  }
26
+ export function useViewTransition(dom) {
27
+ const [element, setElement] = useState(dom);
28
+ useLayoutEffect(() => {
29
+ if (document.startViewTransition && element !== dom) {
30
+ document.startViewTransition(() => {
31
+ flushSync(() => {
32
+ setElement(dom);
33
+ });
34
+ window.dispatchEvent(new Event("RspressReloadContent"));
35
+ });
36
+ } else {
37
+ flushSync(() => {
38
+ setElement(dom);
39
+ });
40
+ window.dispatchEvent(new Event("RspressReloadContent"));
41
+ }
42
+ }, [
43
+ dom
44
+ ]);
45
+ return element;
46
+ }
@@ -1,6 +1,6 @@
1
1
  export * from './hooks';
2
2
  export * from './Content';
3
- export { normalizeHref, withBase, removeBase, addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeRoutePath, isEqualPath } from './utils';
3
+ export { normalizeHrefInRuntime, withBase, removeBase, addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeRoutePath, isEqualPath } from './utils';
4
4
  export { useLocation, useNavigate } from 'react-router-dom';
5
5
  export { Helmet } from 'react-helmet-async';
6
6
  export { NoSSR } from './NoSSR';
@@ -1,6 +1,6 @@
1
1
  export * from "./hooks";
2
2
  export * from "./Content";
3
- export { normalizeHref, withBase, removeBase, addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeRoutePath, isEqualPath } from "./utils";
3
+ export { normalizeHrefInRuntime, withBase, removeBase, addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeRoutePath, isEqualPath } from "./utils";
4
4
  export { useLocation, useNavigate } from "react-router-dom";
5
5
  export { Helmet } from "react-helmet-async";
6
6
  export { NoSSR } from "./NoSSR";
@@ -1,6 +1,7 @@
1
- import { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeHref } from '@rspress/shared';
1
+ import { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction } from '@rspress/shared';
2
2
  export declare function normalizeRoutePath(routePath: string): string;
3
3
  export declare function withBase(url?: string): string;
4
4
  export declare function removeBase(url: string): string;
5
5
  export declare function isEqualPath(a: string, b: string): boolean;
6
- export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeHref };
6
+ export declare function normalizeHrefInRuntime(a: string): string;
7
+ export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction };
@@ -10,6 +10,10 @@ export function removeBase(url) {
10
10
  return rawRemoveBase(url, siteData.base);
11
11
  }
12
12
  export function isEqualPath(a, b) {
13
- return withBase(normalizeHref(a)) === withBase(normalizeHref(b));
13
+ return withBase(normalizeHrefInRuntime(a)) === withBase(normalizeHrefInRuntime(b));
14
14
  }
15
- export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeHref };
15
+ export function normalizeHrefInRuntime(a) {
16
+ const cleanUrls = Boolean(siteData?.route?.cleanUrls);
17
+ return normalizeHref(a, cleanUrls);
18
+ }
19
+ export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction };
@@ -1444,14 +1444,13 @@ button:focus-visible {
1444
1444
  color: var(--rp-c-brand-dark);
1445
1445
  }
1446
1446
 
1447
- /* src/theme-default/components/Link/index.module.scss?css_virtual&hash=b863786183fb8875da59238226b359ae */
1447
+ /* src/theme-default/components/Link/index.module.scss?css_virtual&hash=bb9fa7255cb6499c6f823a2fd851a6fd */
1448
1448
  .link_b3367:hover {
1449
1449
  color: var(--rp-c-brand);
1450
1450
  transition: color 0.2s;
1451
1451
  }
1452
1452
  .link_b3367 {
1453
1453
  display: block;
1454
- font-size: 14px;
1455
1454
  font-weight: 500;
1456
1455
  }
1457
1456
 
@@ -1795,7 +1794,7 @@ button:focus-visible {
1795
1794
  }
1796
1795
  }
1797
1796
 
1798
- /* src/theme-default/layout/DocLayout/index.module.scss?css_virtual&hash=250b13c9ea37442f400d97809303b004 */
1797
+ /* src/theme-default/layout/DocLayout/index.module.scss?css_virtual&hash=25669c7207a2c741ceb395341c44f545 */
1799
1798
  .aside-container_feeda {
1800
1799
  position: sticky;
1801
1800
  display: none;
@@ -1810,6 +1809,44 @@ button:focus-visible {
1810
1809
  .aside-container_feeda::-webkit-scrollbar {
1811
1810
  display: none;
1812
1811
  }
1812
+ .rspress-doc {
1813
+ min-height: 60vh;
1814
+ view-transition-name: flip;
1815
+ }
1816
+ * {
1817
+ view-transition-name: none;
1818
+ }
1819
+ @keyframes fade-out_feeda {
1820
+ from {
1821
+ opacity: 1;
1822
+ }
1823
+ to {
1824
+ opacity: 0;
1825
+ transform: translateY(20px);
1826
+ }
1827
+ }
1828
+ @keyframes fade-in_feeda {
1829
+ from {
1830
+ opacity: 0;
1831
+ transform: translateY(20px);
1832
+ }
1833
+ to {
1834
+ opacity: 1;
1835
+ }
1836
+ }
1837
+ ::view-transition-old(flip),
1838
+ ::view-transition-new(flip) {
1839
+ animation-time: 250ms;
1840
+ }
1841
+ ::view-transition-old(flip) {
1842
+ animation-name: fade-out_feeda;
1843
+ transition-timing-function: cubic-bezier(0, 0, 0.58, 1);
1844
+ }
1845
+ ::view-transition-new(flip) {
1846
+ animation-name: fade-in_feeda;
1847
+ animation-delay: 180ms;
1848
+ transition-timing-function: cubic-bezier(0.42, 0, 1, 1);
1849
+ }
1813
1850
  @media (max-width: 960px) {
1814
1851
  .docLayout_feeda {
1815
1852
  position: relative;
@@ -2577,7 +2614,7 @@ button:focus-visible {
2577
2614
  background-color: var(--rp-c-bg-mute) !important;
2578
2615
  }
2579
2616
 
2580
- /* src/theme-default/layout/DocLayout/docComponents/index.module.scss?css_virtual&hash=c8929e12ddaa45bf7c7aba8314fe1e7c */
2617
+ /* src/theme-default/layout/DocLayout/docComponents/index.module.scss?css_virtual&hash=b8aad7bec210b5a8a58874e911240716 */
2581
2618
  .title_f1ea0 {
2582
2619
  position: relative;
2583
2620
  font-weight: 600;
@@ -2635,3 +2672,6 @@ summary a:hover {
2635
2672
  .rspress-doc details:hover {
2636
2673
  background-color: var(--rp-c-bg-mute);
2637
2674
  }
2675
+ .inline-link_f1ea0 {
2676
+ display: inline;
2677
+ }
@@ -29,6 +29,7 @@ type LayoutProps = {
29
29
  top?: react__default.ReactNode;
30
30
  bottom?: react__default.ReactNode;
31
31
  } & DocLayoutProps & HomeLayoutProps & NavProps;
32
+ declare const Layout: react__default.FC<LayoutProps>;
32
33
 
33
34
  declare function NotFoundLayout(): JSX.Element;
34
35
 
@@ -54,6 +55,10 @@ declare function scrollToTarget(target: HTMLElement, isSmooth: boolean): void;
54
55
  declare function bindingAsideScroll(): () => void;
55
56
  declare function setup(): void;
56
57
 
58
+ declare function usePathUtils(): {
59
+ normalizeLinkHref: (rawHref: string) => string;
60
+ };
61
+
57
62
  declare function isActive(currentPath: string, targetLink?: string, strict?: boolean): boolean;
58
63
  declare function isExternalHref(href: string): boolean;
59
64
  declare function getLogoUrl(rawLogo: string | {
@@ -164,4 +169,4 @@ declare const _default: {
164
169
  setup: typeof setup;
165
170
  };
166
171
 
167
- export { Button, HomeFooter, Link, Nav, PackageManagerTabs, Search, SearchPanel, Tab, Tabs, Toc, bindingAsideScroll, _default as default, getCustomMDXComponent, getLogoUrl, isActive, isExternalHref, isMobileDevice, scrollToTarget, setup, useEditLink, useLocaleSiteData, usePrevNextPage, useSidebarData };
172
+ export { Button, HomeFooter, HomeLayout, Layout, Link, Nav, NotFoundLayout, PackageManagerTabs, Search, SearchPanel, Tab, Tabs, Toc, bindingAsideScroll, _default as default, getCustomMDXComponent, getLogoUrl, isActive, isExternalHref, isMobileDevice, scrollToTarget, setup, useEditLink, useLocaleSiteData, usePathUtils, usePrevNextPage, useSidebarData };