@rspress/core 2.0.0-rc.1 → 2.0.0-rc.3
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/bin/rspress.js +1 -1
- package/dist/0~7675.723d12b2.js +1794 -0
- package/dist/3521.56e42d70.js +56 -0
- package/dist/4669.12208c6a.js +2 -0
- package/dist/5485.077f14ff.js +98 -0
- package/dist/6289.c67fe0d5.js +5 -0
- package/dist/8813.9da1f210.js +2 -0
- package/dist/9643.f109822d.js +5 -0
- package/dist/_private/react/render.js +17 -4
- package/dist/cli/config/index.js +4 -0
- package/dist/cli/config/loadConfigFile.js +30 -0
- package/dist/cli/index.cb89dbd1.js +3 -0
- package/dist/cli/index.js +122 -0
- package/dist/eject-theme/components/Badge/index.scss +1 -0
- package/dist/eject-theme/components/Banner/index.tsx +6 -5
- package/dist/eject-theme/components/Callout/index.scss +0 -2
- package/dist/eject-theme/components/Callout/index.tsx +8 -2
- package/dist/eject-theme/components/CodeBlock/index.scss +12 -18
- package/dist/eject-theme/components/CodeBlock/index.tsx +10 -1
- package/dist/eject-theme/components/CodeBlockRuntime/index.tsx +50 -11
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +1 -3
- package/dist/eject-theme/components/CodeButtonGroup/index.scss +5 -1
- package/dist/eject-theme/components/CodeButtonGroup/index.tsx +1 -3
- package/dist/eject-theme/components/DocContent/doc.scss +27 -7
- package/dist/eject-theme/components/DocContent/docComponents/pre.tsx +2 -1
- package/dist/eject-theme/components/DocContent/docComponents/table.tsx +10 -4
- package/dist/eject-theme/components/DocContent/index.tsx +21 -4
- package/dist/eject-theme/components/DocFooter/index.tsx +1 -6
- package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
- package/dist/eject-theme/components/HoverGroup/index.scss +1 -1
- package/dist/eject-theme/components/LastUpdated/index.tsx +8 -1
- package/dist/eject-theme/components/Link/index.tsx +22 -6
- package/dist/eject-theme/components/Nav/NavMenu.tsx +2 -3
- package/dist/eject-theme/components/NavHamburger/index.tsx +3 -4
- package/dist/eject-theme/components/NavScreen/NavScreenLangs.scss +6 -0
- package/dist/eject-theme/components/NavScreen/NavScreenLangs.tsx +23 -9
- package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +2 -3
- package/dist/eject-theme/components/NavScreen/NavScreenVersions.scss +6 -0
- package/dist/eject-theme/components/NavScreen/NavScreenVersions.tsx +22 -9
- package/dist/eject-theme/components/Overview/index.tsx +7 -8
- package/dist/eject-theme/components/{Overview/OverviewGroup.scss → OverviewGroup/index.scss} +66 -12
- package/dist/eject-theme/components/{Overview/OverviewGroup.tsx → OverviewGroup/index.tsx} +51 -5
- package/dist/eject-theme/components/PackageManagerTabs/index.tsx +12 -0
- package/dist/eject-theme/components/PrevNextPage/index.tsx +6 -3
- package/dist/eject-theme/components/Root/index.tsx +58 -0
- package/dist/eject-theme/components/Search/NoSearchResult.tsx +2 -3
- package/dist/eject-theme/components/Search/SearchButton.tsx +3 -4
- package/dist/eject-theme/components/Search/SearchPanel.tsx +12 -7
- package/dist/eject-theme/components/Search/SuggestItem.tsx +15 -12
- package/dist/eject-theme/components/Search/logic/util.test.ts +1 -1
- package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +2 -3
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -0
- package/dist/eject-theme/components/SidebarMenu/index.tsx +4 -4
- package/dist/eject-theme/components/SocialLinks/index.tsx +2 -3
- package/dist/eject-theme/components/SourceCode/index.tsx +6 -4
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +3 -5
- package/dist/eject-theme/components/Tabs/index.scss +31 -26
- package/dist/eject-theme/components/Tabs/index.tsx +16 -0
- package/dist/eject-theme/components/Tag/index.tsx +84 -5
- package/dist/eject-theme/components/Toc/TocItem.scss +3 -3
- package/dist/eject-theme/components/Toc/TocItem.tsx +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +16 -3134
- package/dist/node/PluginDriver.d.ts +1 -1
- package/dist/node/PluginDriver.js +142 -0
- package/dist/node/auto-nav-sidebar/index.js +44 -0
- package/dist/node/auto-nav-sidebar/locales.js +26 -0
- package/dist/node/auto-nav-sidebar/normalize.js +230 -0
- package/dist/node/auto-nav-sidebar/utils.js +68 -0
- package/dist/node/auto-nav-sidebar/walk.js +67 -0
- package/dist/node/build.js +31 -0
- package/dist/node/constants.d.ts +2 -0
- package/dist/node/constants.js +34 -0
- package/dist/node/dev.js +32 -0
- package/dist/node/eject.js +111 -0
- package/dist/node/index.d.ts +5 -5
- package/dist/node/initRsbuild.d.ts +2 -2
- package/dist/node/initRsbuild.js +346 -0
- package/dist/node/last-updated/index.js +28 -0
- package/dist/node/logger/hint.d.ts +1 -1
- package/dist/node/logger/hint.js +85 -0
- package/dist/node/mdx/loader.d.ts +1 -1
- package/dist/node/mdx/loader.e1578c62.js +13 -0
- package/dist/{loader.js → node/mdx/loader.js} +4 -3
- package/dist/node/mdx/options.d.ts +2 -2
- package/dist/node/mdx/options.js +103 -0
- package/dist/node/mdx/processor.d.ts +2 -2
- package/dist/node/mdx/processor.js +71 -0
- package/dist/node/mdx/rehypePlugins/codeMeta.js +10 -0
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +53 -0
- package/dist/node/mdx/rehypePlugins/shiki.js +34 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-lang.js +15 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-line-numbers.js +22 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-title.js +24 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-wrap-code.js +22 -0
- package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +5 -5
- package/dist/node/mdx/rehypePlugins/transformers/index.js +5 -0
- package/dist/node/mdx/rehypePlugins/transformers/meta-highlight.js +41 -0
- package/dist/node/mdx/remarkPlugins/builtin.js +11 -0
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +190 -0
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +66 -0
- package/dist/node/mdx/remarkPlugins/image.js +67 -0
- package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
- package/dist/node/mdx/remarkPlugins/link.js +99 -0
- package/dist/node/mdx/remarkPlugins/toc.js +50 -0
- package/dist/node/mdx/types.d.ts +3 -3
- package/dist/node/medium-zoom/index.d.ts +1 -1
- package/dist/node/medium-zoom/index.js +14 -0
- package/dist/node/route/RoutePage.d.ts +1 -1
- package/dist/node/route/RoutePage.js +61 -0
- package/dist/node/route/RouteService.d.ts +1 -1
- package/dist/node/route/RouteService.js +177 -0
- package/dist/node/route/extractPageData.d.ts +1 -1
- package/dist/node/route/extractPageData.js +112 -0
- package/dist/node/route/normalizeRoutePath.js +54 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +150 -0
- package/dist/node/runtimeModule/globalStyles.d.ts +1 -1
- package/dist/node/runtimeModule/globalStyles.js +12 -0
- package/dist/node/runtimeModule/globalUIComponents.d.ts +1 -1
- package/dist/node/runtimeModule/globalUIComponents.js +25 -0
- package/dist/node/runtimeModule/i18n.d.ts +2 -2
- package/dist/node/runtimeModule/i18n.js +83 -0
- package/dist/node/runtimeModule/pageData/createPageData.d.ts +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +64 -0
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +51 -0
- package/dist/node/runtimeModule/routeList.d.ts +1 -1
- package/dist/node/runtimeModule/routeList.js +7 -0
- package/dist/node/runtimeModule/searchHooks.d.ts +1 -1
- package/dist/node/runtimeModule/searchHooks.js +11 -0
- package/dist/node/runtimeModule/siteData/createSiteData.js +34 -0
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +94 -0
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.d.ts +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +24 -0
- package/dist/node/runtimeModule/socialLinks.d.ts +1 -1
- package/dist/node/runtimeModule/socialLinks.js +8 -0
- package/dist/node/runtimeModule/types.d.ts +2 -2
- package/dist/node/serve.js +23 -0
- package/dist/node/ssg/renderHtmlTemplate.js +33 -0
- package/dist/node/ssg/renderPage.js +34 -0
- package/dist/node/ssg/renderPageWorker.474f9f73.js +2 -0
- package/dist/node/ssg/renderPageWorker.js +15 -0
- package/dist/node/ssg/renderPages.d.ts +1 -1
- package/dist/node/ssg/renderPages.js +105 -0
- package/dist/node/ssg/renderPages.js.LICENSE.txt +4 -0
- package/dist/node/ssg/rsbuildPluginCSR.d.ts +1 -1
- package/dist/node/ssg/rsbuildPluginCSR.js +27 -0
- package/dist/node/ssg/rsbuildPluginSSG.d.ts +1 -1
- package/dist/node/ssg/rsbuildPluginSSG.js +72 -0
- package/dist/node/ssg/ssgEnv.js +33 -0
- package/dist/node/ssg/ssgEnv.js.LICENSE.txt +5 -0
- package/dist/node/ssg-md/llms/emitLlmsTxt.d.ts +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +84 -0
- package/dist/node/ssg-md/llms/llmsTxt.d.ts +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +66 -0
- package/dist/node/ssg-md/react/index.d.ts +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.js +244 -0
- package/dist/node/ssg-md/renderPage.js +31 -0
- package/dist/node/ssg-md/renderPages.d.ts +1 -1
- package/dist/node/ssg-md/renderPages.js +27 -0
- package/dist/node/ssg-md/rsbuildPluginSSGMD.d.ts +1 -1
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +47 -0
- package/dist/node/utils/applyReplaceRules.js +6 -0
- package/dist/node/utils/checkLanguageParity.js +77 -0
- package/dist/node/utils/createHash.js +5 -0
- package/dist/node/utils/error.d.ts +9 -0
- package/dist/node/utils/error.js +10 -0
- package/dist/node/utils/escapeHeadingIds.js +5 -0
- package/dist/node/utils/flattenMdxContent.js +74 -0
- package/dist/node/utils/fs.js +14 -0
- package/dist/node/utils/getImportAstNode.js +63 -0
- package/dist/node/utils/getPageKey.js +6 -0
- package/dist/node/utils/getSocialIcons.js +32 -0
- package/dist/node/utils/index.d.ts +10 -9
- package/dist/node/utils/normalizePath.js +10 -0
- package/dist/node/utils/reactAlias.d.ts +2 -0
- package/dist/node/utils/reactAlias.js +83 -0
- package/dist/rslib-runtime.99091bf6.js +18 -0
- package/dist/runtime/App.js +2 -2
- package/dist/runtime/ClientApp.d.ts +1 -1
- package/dist/runtime/ClientApp.js +0 -4
- package/dist/runtime/initPageData.js +1 -1
- package/dist/runtime/ssrMdServerEntry.js +1 -1
- package/dist/runtime/ssrServerEntry.js +2 -1
- package/dist/runtime.72d450ac.js +1 -0
- package/dist/runtime.js +3 -2
- package/dist/shiki-transformers.d.ts +1 -1
- package/dist/shiki-transformers.js +6 -120
- package/dist/theme/assets/deprecated.js +18 -0
- package/dist/theme/assets/experimental.js +21 -0
- package/dist/theme/components/Badge/index.css +1 -0
- package/dist/theme/components/Banner/index.d.ts +1 -1
- package/dist/theme/components/Banner/index.js +4 -5
- package/dist/theme/components/Callout/index.css +0 -2
- package/dist/theme/components/Callout/index.js +5 -2
- package/dist/theme/components/CodeBlock/index.css +11 -21
- package/dist/theme/components/CodeBlock/index.js +5 -1
- package/dist/theme/components/CodeBlockRuntime/index.d.ts +1 -1
- package/dist/theme/components/CodeBlockRuntime/index.js +38 -8
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +3 -5
- package/dist/theme/components/CodeButtonGroup/index.css +5 -1
- package/dist/theme/components/CodeButtonGroup/index.js +3 -5
- package/dist/theme/components/DocContent/doc.css +28 -7
- package/dist/theme/components/DocContent/docComponents/index.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/pre.js +3 -1
- package/dist/theme/components/DocContent/docComponents/table.d.ts +2 -2
- package/dist/theme/components/DocContent/docComponents/table.js +8 -3
- package/dist/theme/components/DocContent/index.d.ts +11 -2
- package/dist/theme/components/DocContent/index.js +6 -6
- package/dist/theme/components/DocFooter/index.js +1 -5
- package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
- package/dist/theme/components/HoverGroup/index.css +3 -3
- package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
- package/dist/theme/components/LastUpdated/index.d.ts +1 -1
- package/dist/theme/components/LastUpdated/index.js +5 -1
- package/dist/theme/components/Link/index.d.ts +1 -1
- package/dist/theme/components/Link/index.js +17 -7
- package/dist/theme/components/Nav/NavMenu.js +2 -3
- package/dist/theme/components/NavHamburger/index.js +3 -4
- package/dist/theme/components/NavScreen/NavScreenLangs.css +6 -0
- package/dist/theme/components/NavScreen/NavScreenLangs.js +13 -3
- package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
- package/dist/theme/components/NavScreen/NavScreenVersions.css +6 -0
- package/dist/theme/components/NavScreen/NavScreenVersions.js +12 -3
- package/dist/theme/components/Overview/index.d.ts +0 -1
- package/dist/theme/components/Overview/index.js +2 -3
- package/dist/theme/components/{Overview/OverviewGroup.css → OverviewGroup/index.css} +60 -8
- package/dist/theme/components/{Overview/OverviewGroup.d.ts → OverviewGroup/index.d.ts} +1 -1
- package/dist/theme/components/OverviewGroup/index.js +88 -0
- package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/index.js +4 -0
- package/dist/theme/components/PrevNextPage/index.js +3 -4
- package/dist/theme/components/Root/index.d.ts +54 -0
- package/dist/theme/components/Root/index.js +7 -0
- package/dist/theme/components/Search/NoSearchResult.js +2 -3
- package/dist/theme/components/Search/SearchButton.js +3 -4
- package/dist/theme/components/Search/SearchPanel.js +12 -15
- package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
- package/dist/theme/components/Search/SuggestItem.js +7 -11
- package/dist/theme/components/Search/logic/Provider.d.ts +1 -1
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +2 -2
- package/dist/theme/components/Search/logic/search.d.ts +1 -1
- package/dist/theme/components/Search/logic/util.test.js +1 -1
- package/dist/theme/components/Sidebar/SidebarGroup.js +2 -3
- package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
- package/dist/theme/components/SidebarMenu/index.js +3 -5
- package/dist/theme/components/SocialLinks/index.js +2 -3
- package/dist/theme/components/SourceCode/index.js +2 -4
- package/dist/theme/components/SwitchAppearance/index.js +3 -5
- package/dist/theme/components/Tabs/index.css +19 -27
- package/dist/theme/components/Tabs/index.js +9 -0
- package/dist/theme/components/Tag/index.d.ts +3 -0
- package/dist/theme/components/Tag/index.js +63 -8
- package/dist/theme/components/Toc/TocItem.css +2 -3
- package/dist/theme/components/Toc/TocItem.js +1 -0
- package/dist/theme/hooks/useActiveAnchor.js +1 -1
- package/dist/theme/icons.d.ts +27 -0
- package/dist/theme/icons.js +51 -0
- package/dist/theme/index.d.ts +64 -59
- package/dist/theme/index.js +7 -2
- package/dist/theme/layout/DocLayout/index.css +2 -4
- package/dist/theme/layout/Layout/index.js +1 -2
- package/dist/theme/layout/NotFountLayout/index.js +1 -1
- package/dist/theme/logic/useAppearance.js +1 -1
- package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
- package/dist/theme/logic/useMediaQuery.js +1 -1
- package/dist/theme/styles/base.css +1 -0
- package/dist/theme/styles/scrollbar.css +1 -0
- package/dist/theme/styles/shiki.css +9 -3
- package/dist/theme/styles/vars/base-vars.css +7 -5
- package/dist/theme/styles/vars/code-vars.css +2 -0
- package/dist/theme/styles/vars/home-vars.css +2 -1
- package/package.json +22 -23
- package/dist/3~128.js +0 -74
- package/dist/3~517.js +0 -1786
- package/dist/3~894.js +0 -26
- package/dist/cli.js +0 -259
- package/dist/index.js.LICENSE.txt +0 -10
- package/dist/node/auto-nav-sidebar/fixtures/docs/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/fixtures/docs-locales/en/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/fixtures/docs-locales/zh/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/locales.test.d.ts +0 -1
- package/dist/node/auto-nav-sidebar/walk.test.d.ts +0 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/image.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/link.test.d.ts +0 -1
- package/dist/node/route/RouteService.test.d.ts +0 -1
- package/dist/node/route/extractPageData.test.d.ts +0 -1
- package/dist/node/route/fixtures/basic/guide/c.d.ts +0 -2
- package/dist/node/route/normalizeRoutePath.test.d.ts +0 -1
- package/dist/node/runtimeModule/i18n.test.d.ts +0 -1
- package/dist/node/ssg-md/remarkSplitMdx.test.d.ts +0 -4
- package/dist/node/utils/checkLanguageParity.test.d.ts +0 -1
- package/dist/node/utils/detectCustomIcon.d.ts +0 -1
- package/dist/node/utils/detectReactVersion.d.ts +0 -3
- package/dist/processor.js +0 -4539
- package/dist/renderPageWorker.js +0 -196
- package/dist/theme/components/Overview/OverviewGroup.js +0 -58
- package/dist/theme/components/Search/logic/util.test.d.ts +0 -1
- /package/dist/cli/{config.d.ts → config/index.d.ts} +0 -0
- /package/dist/eject-theme/components/{Overview → OverviewGroup}/icons/plugin.svg +0 -0
- /package/dist/{shiki-transformers.js.LICENSE.txt → node/mdx/rehypePlugins/transformers/meta-highlight.js.LICENSE.txt} +0 -0
- /package/dist/theme/components/{DocContent/FallbackHeading.d.ts → FallbackHeading/index.d.ts} +0 -0
- /package/dist/theme/components/{Overview → OverviewGroup}/icons/plugin.js +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { matchPath } from "react-router-dom";
|
|
2
|
+
import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
3
|
+
import { glob } from "tinyglobby";
|
|
4
|
+
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
5
|
+
import { chunk, groupBy } from "lodash-es";
|
|
6
|
+
import { compile } from "@rspress/mdx-rs";
|
|
7
|
+
import { htmlToText } from "html-to-text";
|
|
8
|
+
import node_fs, { createReadStream, createWriteStream, readFileSync } from "node:fs";
|
|
9
|
+
import { mergeRsbuildConfig, rspack as core_rspack } from "@rsbuild/core";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { extname, join } from "./6289.c67fe0d5.js";
|
|
12
|
+
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
13
|
+
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
14
|
+
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
15
|
+
async setup (api) {
|
|
16
|
+
const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
|
|
17
|
+
const TEMP_DIR = join(api.context.rootPath, virtualFolderName);
|
|
18
|
+
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
19
|
+
let absolutePath = join(TEMP_DIR, i);
|
|
20
|
+
if (!extname(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
21
|
+
return [
|
|
22
|
+
i,
|
|
23
|
+
absolutePath
|
|
24
|
+
];
|
|
25
|
+
});
|
|
26
|
+
api.modifyBundlerChain((chain, { rspack })=>{
|
|
27
|
+
const pluginId = 'RSBUILD_VIRTUAL_MODULE_PLUGIN';
|
|
28
|
+
const virtualModules = Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
|
|
29
|
+
i[1],
|
|
30
|
+
''
|
|
31
|
+
]));
|
|
32
|
+
if (chain.plugins.has(pluginId)) chain.plugin(pluginId).tap((options)=>{
|
|
33
|
+
const existingPaths = new Set(Object.keys(options[0] ?? {}));
|
|
34
|
+
const conflictPath = virtualFileAbsolutePaths.find(([, path])=>existingPaths.has(path));
|
|
35
|
+
if (conflictPath) throw new Error(`Virtual module name conflicted: ${conflictPath[0]}`);
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
...options[0],
|
|
39
|
+
...virtualModules
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
});
|
|
43
|
+
else chain.plugin(pluginId).use(rspack.experiments.VirtualModulesPlugin, [
|
|
44
|
+
virtualModules
|
|
45
|
+
]);
|
|
46
|
+
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
47
|
+
});
|
|
48
|
+
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
49
|
+
const handler = virtualModules[moduleName];
|
|
50
|
+
if (handler) api.transform({
|
|
51
|
+
test: absolutePath
|
|
52
|
+
}, handler);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, DEFAULT_PAGE_EXTENSIONS, PLUGIN_REACT_NAME, chunk, compile, core_rspack, createHash, createReadStream, createWriteStream, glob, groupBy, htmlToText, matchPath, mergeRsbuildConfig, node_fs, pluginReact, pluginVirtualModule, readFileSync };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, isProduction, normalizeHref, parseUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase } from "@rspress/shared";
|
|
2
|
+
export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, isProduction, normalizeHref, parseUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import node_url, { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
4
|
+
var package_namespaceObject = {
|
|
5
|
+
rE: "2.0.0-rc.3"
|
|
6
|
+
};
|
|
7
|
+
async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
|
|
8
|
+
return new Promise((resolve_, reject_)=>{
|
|
9
|
+
if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
|
|
10
|
+
if ('function' != typeof mapper) throw new TypeError('Mapper function is required');
|
|
11
|
+
if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === 1 / 0)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
|
|
12
|
+
const result = [];
|
|
13
|
+
const errors = [];
|
|
14
|
+
const skippedIndexesMap = new Map();
|
|
15
|
+
let isRejected = false;
|
|
16
|
+
let isResolved = false;
|
|
17
|
+
let isIterableDone = false;
|
|
18
|
+
let resolvingCount = 0;
|
|
19
|
+
let currentIndex = 0;
|
|
20
|
+
const iterator = void 0 === iterable[Symbol.iterator] ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
|
21
|
+
const signalListener = ()=>{
|
|
22
|
+
reject(signal.reason);
|
|
23
|
+
};
|
|
24
|
+
const cleanup = ()=>{
|
|
25
|
+
signal?.removeEventListener('abort', signalListener);
|
|
26
|
+
};
|
|
27
|
+
const resolve = (value)=>{
|
|
28
|
+
resolve_(value);
|
|
29
|
+
cleanup();
|
|
30
|
+
};
|
|
31
|
+
const reject = (reason)=>{
|
|
32
|
+
isRejected = true;
|
|
33
|
+
isResolved = true;
|
|
34
|
+
reject_(reason);
|
|
35
|
+
cleanup();
|
|
36
|
+
};
|
|
37
|
+
if (signal) {
|
|
38
|
+
if (signal.aborted) reject(signal.reason);
|
|
39
|
+
signal.addEventListener('abort', signalListener, {
|
|
40
|
+
once: true
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const next = async ()=>{
|
|
44
|
+
if (isResolved) return;
|
|
45
|
+
const nextItem = await iterator.next();
|
|
46
|
+
const index = currentIndex;
|
|
47
|
+
currentIndex++;
|
|
48
|
+
if (nextItem.done) {
|
|
49
|
+
isIterableDone = true;
|
|
50
|
+
if (0 === resolvingCount && !isResolved) {
|
|
51
|
+
if (!stopOnError && errors.length > 0) return void reject(new AggregateError(errors));
|
|
52
|
+
isResolved = true;
|
|
53
|
+
if (0 === skippedIndexesMap.size) return void resolve(result);
|
|
54
|
+
const pureResult = [];
|
|
55
|
+
for (const [index, value] of result.entries())if (skippedIndexesMap.get(index) !== pMapSkip) pureResult.push(value);
|
|
56
|
+
resolve(pureResult);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
resolvingCount++;
|
|
61
|
+
(async ()=>{
|
|
62
|
+
try {
|
|
63
|
+
const element = await nextItem.value;
|
|
64
|
+
if (isResolved) return;
|
|
65
|
+
const value = await mapper(element, index);
|
|
66
|
+
if (value === pMapSkip) skippedIndexesMap.set(index, value);
|
|
67
|
+
result[index] = value;
|
|
68
|
+
resolvingCount--;
|
|
69
|
+
await next();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (stopOnError) reject(error);
|
|
72
|
+
else {
|
|
73
|
+
errors.push(error);
|
|
74
|
+
resolvingCount--;
|
|
75
|
+
try {
|
|
76
|
+
await next();
|
|
77
|
+
} catch (error) {
|
|
78
|
+
reject(error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
};
|
|
84
|
+
(async ()=>{
|
|
85
|
+
for(let index = 0; index < concurrency; index++){
|
|
86
|
+
try {
|
|
87
|
+
await next();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
reject(error);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (isIterableDone || isRejected) break;
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const pMapSkip = Symbol('skip');
|
|
98
|
+
export { createHead, createRequire, fileURLToPath, node_url, pMap, package_namespaceObject, pathToFileURL, transformHtmlTemplate };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { logger } from "@rspress/shared/logger";
|
|
2
|
+
import node_path, { extname, join, relative } from "node:path";
|
|
3
|
+
import promises, { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import picocolors from "picocolors";
|
|
5
|
+
export { extname, join, logger, mkdir, node_path, picocolors, promises, readFile, readdir, relative, rm, stat, writeFile };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter } from "@rspress/shared/node-utils";
|
|
2
|
+
import node_os, { constants } from "node:os";
|
|
3
|
+
import node_process, { cwd } from "node:process";
|
|
4
|
+
import { createProcessor, nodeTypes } from "@mdx-js/mdx";
|
|
5
|
+
export { constants, createProcessor, cwd, extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, nodeTypes, node_os, node_process };
|
|
@@ -29,11 +29,20 @@ function toMarkdown(root) {
|
|
|
29
29
|
case 'i':
|
|
30
30
|
return `*${childrenMd}*`;
|
|
31
31
|
case 'code':
|
|
32
|
+
if (root.parent?.type === 'pre') return childrenMd;
|
|
32
33
|
return `\`${childrenMd}\``;
|
|
33
34
|
case 'pre':
|
|
34
35
|
{
|
|
35
|
-
const
|
|
36
|
-
|
|
36
|
+
const _language = props['data-lang'] || props.language || props.lang || '';
|
|
37
|
+
const language = 'string' == typeof _language ? _language : '';
|
|
38
|
+
const title = props['data-title'] || '';
|
|
39
|
+
const block = [
|
|
40
|
+
'markdown',
|
|
41
|
+
'mdx',
|
|
42
|
+
'md',
|
|
43
|
+
''
|
|
44
|
+
].includes(language) ? '````' : '```';
|
|
45
|
+
return `\n${block}${language}${title ? ` title=${title}` : ''}\n${childrenMd}\n${block}\n`;
|
|
37
46
|
}
|
|
38
47
|
case 'a':
|
|
39
48
|
return `[${childrenMd}](${props.href || '#'})`;
|
|
@@ -88,8 +97,12 @@ function toMarkdown(root) {
|
|
|
88
97
|
}
|
|
89
98
|
async function renderToMarkdownString(element) {
|
|
90
99
|
const container = new MarkdownNode('root');
|
|
91
|
-
const root = reconciler.createContainer(container, 1, null, false, false, '', (
|
|
92
|
-
if (process.env.DEBUG)
|
|
100
|
+
const root = reconciler.createContainer(container, 1, null, false, false, '', (error, info)=>{
|
|
101
|
+
if (process.env.DEBUG) {
|
|
102
|
+
console.error('Reconciler Error:', error, info);
|
|
103
|
+
const message = 'Reconciler Error:' + error.message;
|
|
104
|
+
throw new Error(message);
|
|
105
|
+
}
|
|
93
106
|
}, ()=>{}, (...args)=>{
|
|
94
107
|
if (process.env.DEBUG) console.log('Reconciler onRecoverable Error:', ...args);
|
|
95
108
|
}, ()=>{}, null);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { node_fs, DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "../../3521.56e42d70.js";
|
|
2
|
+
import { node_path, logger } from "../../6289.c67fe0d5.js";
|
|
3
|
+
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
4
|
+
async function loadConfigFile(customConfigFile) {
|
|
5
|
+
const baseDir = process.cwd();
|
|
6
|
+
let configFilePath = '';
|
|
7
|
+
configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
|
|
8
|
+
if (!configFilePath) {
|
|
9
|
+
logger.info(`No config file found in ${baseDir}`);
|
|
10
|
+
return {
|
|
11
|
+
config: {},
|
|
12
|
+
configFilePath: ''
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const { loadConfig } = await import("@rsbuild/core");
|
|
16
|
+
const { content } = await loadConfig({
|
|
17
|
+
cwd: node_path.dirname(configFilePath),
|
|
18
|
+
path: configFilePath
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
config: content,
|
|
22
|
+
configFilePath
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveDocRoot(cwd, cliRoot, configRoot) {
|
|
26
|
+
if (cliRoot) return node_path.join(cwd, cliRoot);
|
|
27
|
+
if (configRoot) return node_path.isAbsolute(configRoot) ? configRoot : node_path.join(cwd, configRoot);
|
|
28
|
+
return node_path.join(cwd, 'docs');
|
|
29
|
+
}
|
|
30
|
+
export { loadConfigFile, resolveDocRoot };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { node_path, logger, join, picocolors } from "../6289.c67fe0d5.js";
|
|
2
|
+
import { chokidar, cac } from "./index.cb89dbd1.js";
|
|
3
|
+
import { package_namespaceObject } from "../5485.077f14ff.js";
|
|
4
|
+
import { loadConfigFile, resolveDocRoot } from "./config/loadConfigFile.js";
|
|
5
|
+
import { dev } from "../node/dev.js";
|
|
6
|
+
import { PUBLIC_DIR } from "../node/constants.js";
|
|
7
|
+
import { build } from "../node/build.js";
|
|
8
|
+
import { serve } from "../node/serve.js";
|
|
9
|
+
import { listComponents, ejectComponent } from "../node/eject.js";
|
|
10
|
+
const META_FILES = [
|
|
11
|
+
'_meta.json',
|
|
12
|
+
'_nav.json'
|
|
13
|
+
];
|
|
14
|
+
const cli = cac('rspress').version(package_namespaceObject.rE).help();
|
|
15
|
+
const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
|
|
16
|
+
logger.greet(landingMessage);
|
|
17
|
+
const setNodeEnv = (env)=>{
|
|
18
|
+
process.env.NODE_ENV = env;
|
|
19
|
+
};
|
|
20
|
+
cli.option('-c,--config [config]', 'Specify the path to the config file');
|
|
21
|
+
cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
|
|
22
|
+
setNodeEnv('development');
|
|
23
|
+
let isRestarting = false;
|
|
24
|
+
const cwd = process.cwd();
|
|
25
|
+
let cliWatcher;
|
|
26
|
+
let devServer;
|
|
27
|
+
const startDevServer = async ()=>{
|
|
28
|
+
const { port, host } = options || {};
|
|
29
|
+
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
30
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
31
|
+
const docDirectory = config.root;
|
|
32
|
+
devServer = await dev({
|
|
33
|
+
appDirectory: cwd,
|
|
34
|
+
docDirectory,
|
|
35
|
+
config,
|
|
36
|
+
configFilePath,
|
|
37
|
+
extraBuilderConfig: {
|
|
38
|
+
server: {
|
|
39
|
+
port,
|
|
40
|
+
host
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
cliWatcher = chokidar.watch([
|
|
45
|
+
configFilePath,
|
|
46
|
+
docDirectory
|
|
47
|
+
], {
|
|
48
|
+
ignoreInitial: true,
|
|
49
|
+
ignored: [
|
|
50
|
+
'**/node_modules/**',
|
|
51
|
+
'**/.git/**',
|
|
52
|
+
'**/.DS_Store/**',
|
|
53
|
+
join(docDirectory, PUBLIC_DIR)
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
cliWatcher.on('all', async (eventName, filepath)=>{
|
|
57
|
+
const basename = node_path.basename(filepath);
|
|
58
|
+
if ('change' === eventName && META_FILES.includes(basename)) return;
|
|
59
|
+
if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && filepath === configFilePath) {
|
|
60
|
+
if (isRestarting) return;
|
|
61
|
+
isRestarting = true;
|
|
62
|
+
console.log(`\n✨ ${eventName} ${picocolors.green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
|
|
63
|
+
await devServer.close();
|
|
64
|
+
await cliWatcher.close();
|
|
65
|
+
await startDevServer();
|
|
66
|
+
isRestarting = false;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
await startDevServer();
|
|
71
|
+
const exitProcess = async ()=>{
|
|
72
|
+
try {
|
|
73
|
+
await devServer.close();
|
|
74
|
+
await cliWatcher.close();
|
|
75
|
+
} finally{
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
process.on('SIGINT', exitProcess);
|
|
80
|
+
process.on('SIGTERM', exitProcess);
|
|
81
|
+
});
|
|
82
|
+
cli.command('build [root]').action(async (root, options)=>{
|
|
83
|
+
setNodeEnv('production');
|
|
84
|
+
const cwd = process.cwd();
|
|
85
|
+
const { config, configFilePath } = await loadConfigFile(options.config);
|
|
86
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
87
|
+
const docDirectory = config.root;
|
|
88
|
+
try {
|
|
89
|
+
await build({
|
|
90
|
+
docDirectory,
|
|
91
|
+
config,
|
|
92
|
+
configFilePath
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
logger.error(err);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
cli.command('preview [root]').alias('serve').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
|
|
100
|
+
setNodeEnv('production');
|
|
101
|
+
const cwd = process.cwd();
|
|
102
|
+
const { port, host } = options || {};
|
|
103
|
+
const { config, configFilePath } = await loadConfigFile(options?.config);
|
|
104
|
+
config.root = resolveDocRoot(cwd, root, config.root);
|
|
105
|
+
await serve({
|
|
106
|
+
config,
|
|
107
|
+
host,
|
|
108
|
+
port,
|
|
109
|
+
configFilePath
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
cli.command('eject [component]', 'Eject a theme component to customize it').action(async (component)=>{
|
|
113
|
+
if (!component) return void await listComponents();
|
|
114
|
+
const cwd = process.cwd();
|
|
115
|
+
try {
|
|
116
|
+
await ejectComponent(component, cwd);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
logger.error(`Failed to eject component: ${error}`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
cli.parse();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Link, mergeRefs, SvgWrapper } from '@theme';
|
|
2
|
-
import CloseSvg from '@theme-assets/close';
|
|
1
|
+
import { IconClose, Link, mergeRefs, SvgWrapper } from '@theme';
|
|
3
2
|
import clsx from 'clsx';
|
|
4
3
|
import { forwardRef, type ReactNode, useEffect, useState } from 'react';
|
|
5
4
|
import './index.scss';
|
|
@@ -31,7 +30,7 @@ export type BannerProps = {
|
|
|
31
30
|
/**
|
|
32
31
|
* @example
|
|
33
32
|
* // theme/index.tsx
|
|
34
|
-
* import { Layout as BasicLayout, Banner } from '@rspress/core/theme';
|
|
33
|
+
* import { Layout as BasicLayout, Banner } from '@rspress/core/theme-original';
|
|
35
34
|
* import { useLang } from '@rspress/core/runtime';
|
|
36
35
|
* const Layout = () => {
|
|
37
36
|
const lang = useLang();
|
|
@@ -75,7 +74,9 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
75
74
|
|
|
76
75
|
const [height, setHeight] = useState(36);
|
|
77
76
|
const ref = mergeRefs(forwardedRef, element => {
|
|
78
|
-
|
|
77
|
+
if (element?.offsetHeight) {
|
|
78
|
+
setHeight(element?.offsetHeight);
|
|
79
|
+
}
|
|
79
80
|
});
|
|
80
81
|
const [disable, setDisable] = useState(false);
|
|
81
82
|
|
|
@@ -100,7 +101,7 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
100
101
|
{message}
|
|
101
102
|
</Link>
|
|
102
103
|
<SvgWrapper
|
|
103
|
-
icon={
|
|
104
|
+
icon={IconClose}
|
|
104
105
|
onClick={() => {
|
|
105
106
|
setDisable(true);
|
|
106
107
|
if (storage) {
|
|
@@ -7,6 +7,10 @@ export interface CalloutProps {
|
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
function capitalize(type: string) {
|
|
11
|
+
return type.charAt(0).toUpperCase() + type.slice(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Construct the DOM structure of the container directive.
|
|
12
16
|
* For example:
|
|
@@ -30,7 +34,9 @@ export function Callout({ type, title, children }: CalloutProps): ReactNode {
|
|
|
30
34
|
if (isDetails) {
|
|
31
35
|
return (
|
|
32
36
|
<details className={`rp-callout rp-callout--${type}`}>
|
|
33
|
-
<summary className="rp-callout__title">
|
|
37
|
+
<summary className="rp-callout__title">
|
|
38
|
+
{title ?? capitalize(type)}
|
|
39
|
+
</summary>
|
|
34
40
|
<div className="rp-callout__content">{children}</div>
|
|
35
41
|
</details>
|
|
36
42
|
);
|
|
@@ -38,7 +44,7 @@ export function Callout({ type, title, children }: CalloutProps): ReactNode {
|
|
|
38
44
|
|
|
39
45
|
return (
|
|
40
46
|
<div className={`rp-callout rp-callout--${type}`}>
|
|
41
|
-
<div className="rp-callout__title">{title}</div>
|
|
47
|
+
<div className="rp-callout__title">{title ?? capitalize(type)}</div>
|
|
42
48
|
<div className="rp-callout__content">{children}</div>
|
|
43
49
|
</div>
|
|
44
50
|
);
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
.rp-codeblock {
|
|
2
2
|
position: relative;
|
|
3
|
-
margin:
|
|
3
|
+
margin: 1rem 0;
|
|
4
4
|
border: var(--rp-code-block-border);
|
|
5
|
+
box-shadow: var(--rp-code-block-shadow);
|
|
6
|
+
|
|
5
7
|
overflow-x: auto;
|
|
6
8
|
transition: none;
|
|
7
9
|
border-radius: var(--rp-radius);
|
|
8
10
|
|
|
9
11
|
@media (max-width: 640px) {
|
|
10
|
-
margin:
|
|
12
|
+
margin: 1.5rem 0;
|
|
11
13
|
contain: content;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
.rp-codeblock__title {
|
|
16
18
|
font-family: var(--rp-font-family-mono);
|
|
17
|
-
padding:
|
|
19
|
+
padding: 0.75rem 1rem;
|
|
18
20
|
font-size: var(--rp-code-font-size);
|
|
19
21
|
background-color: var(--rp-code-title-bg);
|
|
20
22
|
border-bottom: var(--rp-code-block-border);
|
|
@@ -25,6 +27,10 @@
|
|
|
25
27
|
color: var(--rp-code-block-color);
|
|
26
28
|
background-color: var(--rp-code-block-bg);
|
|
27
29
|
|
|
30
|
+
&__scroll-container {
|
|
31
|
+
overflow-x: auto;
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
& :where(pre) {
|
|
29
35
|
outline: none; // avoid focus outline https://github.com/web-infra-dev/rspack/issues/11775
|
|
30
36
|
|
|
@@ -47,25 +53,13 @@
|
|
|
47
53
|
z-index: 1;
|
|
48
54
|
margin: 0;
|
|
49
55
|
background: transparent;
|
|
50
|
-
overflow-x: auto;
|
|
51
|
-
&::-webkit-scrollbar {
|
|
52
|
-
height: 5px;
|
|
53
|
-
width: 5px;
|
|
54
|
-
}
|
|
55
|
-
&::-webkit-scrollbar-corner {
|
|
56
|
-
display: none;
|
|
57
|
-
}
|
|
58
|
-
&::-webkit-scrollbar-thumb {
|
|
59
|
-
background-color: var(--rp-code-block-scroll-bar-bg);
|
|
60
|
-
border-radius: 10px;
|
|
61
|
-
}
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
& :where(code) {
|
|
65
59
|
font-size: var(--rp-code-font-size);
|
|
66
60
|
font-family: var(--rp-font-family-mono);
|
|
67
61
|
display: inline-block;
|
|
68
|
-
padding:
|
|
62
|
+
padding: 1rem 0;
|
|
69
63
|
width: fit-content;
|
|
70
64
|
min-width: 100%;
|
|
71
65
|
line-height: 1.7;
|
|
@@ -82,8 +76,8 @@
|
|
|
82
76
|
& .line::before {
|
|
83
77
|
content: counter(step);
|
|
84
78
|
counter-increment: step;
|
|
85
|
-
width:
|
|
86
|
-
margin-right:
|
|
79
|
+
width: 1rem;
|
|
80
|
+
margin-right: 1rem;
|
|
87
81
|
display: inline-block;
|
|
88
82
|
text-align: right;
|
|
89
83
|
color: rgba(115, 138, 148, 0.4);
|
|
@@ -69,6 +69,10 @@ export function CodeBlock({
|
|
|
69
69
|
codeButtonGroupProps,
|
|
70
70
|
children,
|
|
71
71
|
}: CodeBlockProps) {
|
|
72
|
+
if (process.env.__SSR_MD__) {
|
|
73
|
+
return <>{children}</>;
|
|
74
|
+
}
|
|
75
|
+
|
|
72
76
|
const { codeWrap, toggleCodeWrap, copyElementRef } =
|
|
73
77
|
useCodeButtonGroup(wrapCodeProp);
|
|
74
78
|
return (
|
|
@@ -87,7 +91,12 @@ export function CodeBlock({
|
|
|
87
91
|
lineNumbersProp && 'rp-codeblock__content--line-numbers',
|
|
88
92
|
)}
|
|
89
93
|
>
|
|
90
|
-
<div
|
|
94
|
+
<div
|
|
95
|
+
className="rp-codeblock__content__scroll-container rp-scrollbar"
|
|
96
|
+
ref={copyElementRef}
|
|
97
|
+
>
|
|
98
|
+
{children}
|
|
99
|
+
</div>
|
|
91
100
|
<CodeButtonGroup
|
|
92
101
|
{...codeButtonGroupProps}
|
|
93
102
|
copyElementRef={copyElementRef}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { CodeBlockProps } from '@theme';
|
|
2
2
|
import { getCustomMDXComponent } from '@theme';
|
|
3
3
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Fragment,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
5
12
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
13
|
import {
|
|
7
14
|
type BundledLanguage,
|
|
@@ -47,9 +54,37 @@ export function CodeBlockRuntime({
|
|
|
47
54
|
children: _,
|
|
48
55
|
containerElementClassName,
|
|
49
56
|
onRendered,
|
|
50
|
-
|
|
57
|
+
wrapCode,
|
|
58
|
+
lineNumbers,
|
|
51
59
|
}: CodeBlockRuntimeProps) {
|
|
52
|
-
|
|
60
|
+
// getCustomMDXComponent is stable for theme rendering
|
|
61
|
+
const mdxComponents = useMemo(() => getCustomMDXComponent(), []);
|
|
62
|
+
const { pre: ShikiPre, code: Code, ...otherMdxComponents } = mdxComponents;
|
|
63
|
+
const fallback = useMemo(
|
|
64
|
+
() => (
|
|
65
|
+
<ShikiPre
|
|
66
|
+
title={title}
|
|
67
|
+
lang={lang}
|
|
68
|
+
wrapCode={wrapCode}
|
|
69
|
+
lineNumbers={lineNumbers}
|
|
70
|
+
containerElementClassName={containerElementClassName}
|
|
71
|
+
codeButtonGroupProps={codeButtonGroupProps}
|
|
72
|
+
className="shiki css-variables"
|
|
73
|
+
>
|
|
74
|
+
<Code style={{ padding: '1rem 1.25rem' }}>{code}</Code>
|
|
75
|
+
</ShikiPre>
|
|
76
|
+
),
|
|
77
|
+
[
|
|
78
|
+
title,
|
|
79
|
+
lang,
|
|
80
|
+
wrapCode,
|
|
81
|
+
lineNumbers,
|
|
82
|
+
containerElementClassName,
|
|
83
|
+
codeButtonGroupProps,
|
|
84
|
+
code,
|
|
85
|
+
],
|
|
86
|
+
);
|
|
87
|
+
const [child, setChild] = useState<ReactNode | null>(fallback);
|
|
53
88
|
const codeRef = useLatest(code);
|
|
54
89
|
|
|
55
90
|
useEffect(() => {
|
|
@@ -66,12 +101,6 @@ export function CodeBlockRuntime({
|
|
|
66
101
|
return;
|
|
67
102
|
}
|
|
68
103
|
|
|
69
|
-
const {
|
|
70
|
-
pre: ShikiPre,
|
|
71
|
-
code: Code,
|
|
72
|
-
...otherMdxComponents
|
|
73
|
-
} = getCustomMDXComponent();
|
|
74
|
-
|
|
75
104
|
const reactNode = toJsxRuntime(hast, {
|
|
76
105
|
jsx,
|
|
77
106
|
jsxs,
|
|
@@ -84,8 +113,9 @@ export function CodeBlockRuntime({
|
|
|
84
113
|
lang={lang}
|
|
85
114
|
containerElementClassName={containerElementClassName}
|
|
86
115
|
codeButtonGroupProps={codeButtonGroupProps}
|
|
116
|
+
wrapCode={wrapCode}
|
|
117
|
+
lineNumbers={lineNumbers}
|
|
87
118
|
{...props}
|
|
88
|
-
{...otherProps}
|
|
89
119
|
/>
|
|
90
120
|
),
|
|
91
121
|
code: props => <Code {...props} />,
|
|
@@ -96,7 +126,16 @@ export function CodeBlockRuntime({
|
|
|
96
126
|
setChild(reactNode);
|
|
97
127
|
};
|
|
98
128
|
void highlightCode();
|
|
99
|
-
}, [
|
|
129
|
+
}, [
|
|
130
|
+
code,
|
|
131
|
+
codeButtonGroupProps,
|
|
132
|
+
containerElementClassName,
|
|
133
|
+
lang,
|
|
134
|
+
lineNumbers,
|
|
135
|
+
shikiOptions,
|
|
136
|
+
title,
|
|
137
|
+
wrapCode,
|
|
138
|
+
]);
|
|
100
139
|
|
|
101
140
|
useEffect(() => {
|
|
102
141
|
if (child) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { SvgWrapper } from '@theme';
|
|
2
|
-
import IconCopy from '@theme-assets/copy';
|
|
3
|
-
import IconSuccess from '@theme-assets/success';
|
|
1
|
+
import { IconCopy, IconSuccess, SvgWrapper } from '@theme';
|
|
4
2
|
import copy from 'copy-to-clipboard';
|
|
5
3
|
import { useRef } from 'react';
|
|
6
4
|
import './CopyCodeButton.scss';
|