dumi 2.1.14 → 2.1.16

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 (39) hide show
  1. package/dist/assetParsers/atom.d.ts +1 -0
  2. package/dist/assetParsers/atom.js +2 -1
  3. package/dist/client/pages/404.js +1 -1
  4. package/dist/client/theme-api/DumiDemo.js +2 -2
  5. package/dist/client/theme-api/DumiPage.js +1 -1
  6. package/dist/constants.d.ts +0 -1
  7. package/dist/constants.js +0 -13
  8. package/dist/features/autoAlias.js +26 -19
  9. package/dist/features/derivative.js +19 -19
  10. package/dist/features/exportStatic.js +37 -29
  11. package/dist/features/parser.js +4 -2
  12. package/dist/features/routes.js +5 -17
  13. package/dist/features/theme/index.js +6 -2
  14. package/dist/loaders/markdown/transformer/index.js +3 -0
  15. package/dist/loaders/markdown/transformer/rehypeDemo.js +15 -6
  16. package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +9 -1
  17. package/dist/loaders/markdown/transformer/rehypeHighlightLine.d.ts +4 -0
  18. package/dist/loaders/markdown/transformer/rehypeHighlightLine.js +60 -0
  19. package/dist/loaders/markdown/transformer/rehypeLink.js +4 -4
  20. package/dist/utils.d.ts +4 -0
  21. package/dist/utils.js +14 -0
  22. package/package.json +5 -5
  23. package/theme-default/builtins/Previewer/index.js +1 -1
  24. package/theme-default/builtins/Previewer/index.less +1 -1
  25. package/theme-default/builtins/SourceCode/index.d.ts +4 -2
  26. package/theme-default/builtins/SourceCode/index.js +16 -10
  27. package/theme-default/builtins/SourceCode/index.less +12 -0
  28. package/theme-default/layouts/DocLayout/index.js +7 -7
  29. package/theme-default/slots/Content/index.js +7 -2
  30. package/theme-default/slots/Content/index.less +17 -0
  31. package/theme-default/slots/Header/index.js +6 -6
  32. package/theme-default/slots/Hero/index.js +1 -1
  33. package/theme-default/slots/Logo/index.less +1 -1
  34. package/theme-default/slots/Navbar/index.js +1 -1
  35. package/theme-default/slots/Navbar/index.less +1 -1
  36. package/theme-default/slots/PreviewerActions/index.js +2 -2
  37. package/theme-default/slots/Sidebar/index.js +1 -1
  38. package/theme-default/slots/Sidebar/index.less +2 -2
  39. package/theme-default/slots/Toc/index.js +18 -9
@@ -15,6 +15,7 @@ declare class AtomAssetsParser {
15
15
  resolveFilter?: AtomAssetsParser['resolveFilter'];
16
16
  unpkgHost?: string;
17
17
  watch?: boolean;
18
+ parseOptions?: object;
18
19
  });
19
20
  parse(): Promise<{
20
21
  components: Record<string, AtomComponentAsset>;
@@ -44,7 +44,8 @@ var AtomAssetsParser = class {
44
44
  entryPath: absEntryFile,
45
45
  basePath: (0, import_utils.getProjectRoot)(opts.resolveDir),
46
46
  unPkgHost: opts.unpkgHost ?? "https://unpkg.com",
47
- mode: "worker"
47
+ mode: "worker",
48
+ parseOptions: opts.parseOptions
48
49
  });
49
50
  }
50
51
  async parse() {
@@ -1,2 +1,2 @@
1
1
  // allow customize 404 via theme slots
2
- export { default } from "dumi/theme/slots/NotFound";
2
+ export { default } from 'dumi/theme/slots/NotFound';
@@ -2,8 +2,8 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
 
3
3
  import { SP_ROUTE_PREFIX } from "../../constants";
4
4
  import { useAppData, useSiteData } from 'dumi';
5
- import Container from "dumi/theme/builtins/Container";
6
- import Previewer from "dumi/theme/builtins/Previewer";
5
+ import Container from 'dumi/theme/builtins/Container';
6
+ import Previewer from 'dumi/theme/builtins/Previewer';
7
7
  import React, { createElement } from 'react';
8
8
  import { ErrorBoundary } from 'react-error-boundary';
9
9
 
@@ -11,7 +11,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import { useRouteMeta, useSiteData } from 'dumi';
14
- import ContentTabs from "dumi/theme/slots/ContentTabs";
14
+ import ContentTabs from 'dumi/theme/slots/ContentTabs';
15
15
  import React, { useEffect, useState } from 'react';
16
16
  import { useTabQueryState } from "./useTabMeta";
17
17
  export var DumiPage = function DumiPage(props) {
@@ -14,5 +14,4 @@ export declare const PICKED_PKG_FIELDS: {
14
14
  author: string;
15
15
  authors: string;
16
16
  };
17
- export declare const CLIENT_DEPS: string[];
18
17
  export declare const USELESS_TMP_FILES: string[];
package/dist/constants.js CHANGED
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/constants.ts
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
- CLIENT_DEPS: () => CLIENT_DEPS,
23
22
  LOCAL_DUMI_DIR: () => LOCAL_DUMI_DIR,
24
23
  LOCAL_PAGES_DIR: () => LOCAL_PAGES_DIR,
25
24
  LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
@@ -47,21 +46,9 @@ var PICKED_PKG_FIELDS = {
47
46
  author: "",
48
47
  authors: ""
49
48
  };
50
- var CLIENT_DEPS = [
51
- "@ant-design/icons-svg",
52
- "@makotot/ghostui",
53
- "deepmerge",
54
- "lodash.throttle",
55
- "prism-react-renderer",
56
- "prismjs",
57
- "rc-tabs",
58
- "react-copy-to-clipboard",
59
- "react-intl"
60
- ];
61
49
  var USELESS_TMP_FILES = ["tsconfig.json", "typings.d.ts"];
62
50
  // Annotate the CommonJS export names for ESM import in node:
63
51
  0 && (module.exports = {
64
- CLIENT_DEPS,
65
52
  LOCAL_DUMI_DIR,
66
53
  LOCAL_PAGES_DIR,
67
54
  LOCAL_THEME_DIR,
@@ -29,34 +29,41 @@ var import_utils = require("../utils");
29
29
  var import_fs = __toESM(require("fs"));
30
30
  var import_path = __toESM(require("path"));
31
31
  var autoAlias_default = (api) => {
32
+ let entryDir;
32
33
  api.describe({
33
34
  key: "autoAlias",
34
35
  config: {
35
36
  schema: (Joi) => Joi.bool()
36
37
  },
37
- enableBy: ({ userConfig }) => userConfig.autoAlias !== false
38
+ enableBy: () => !!api.pkg.name
38
39
  });
39
- api.modifyConfig(async (memo) => {
40
- var _a, _b, _c;
41
- let entryDir = "";
42
- if ((_a = memo.resolve) == null ? void 0 : _a.entryFile) {
43
- entryDir = import_path.default.resolve(api.cwd, memo.resolve.entryFile);
40
+ api.modifyAppData(async (memo) => {
41
+ var _a;
42
+ if ((_a = api.config.resolve) == null ? void 0 : _a.entryFile) {
43
+ entryDir = import_path.default.resolve(api.cwd, api.config.resolve.entryFile);
44
44
  } else if (import_fs.default.existsSync(import_path.default.join(api.cwd, "src"))) {
45
45
  entryDir = import_path.default.join(api.cwd, "src");
46
46
  }
47
- if (entryDir && api.pkg.name) {
48
- const fatherConfigs = await (0, import_utils.tryFatherBuildConfigs)(api.cwd);
49
- fatherConfigs.sort((a, b) => {
50
- var _a2, _b2;
51
- const aLevel = (((_a2 = a.output) == null ? void 0 : _a2.path) || a.output).split("/").length;
52
- const bLevel = (((_b2 = b.output) == null ? void 0 : _b2.path) || b.output).split("/").length;
53
- return bLevel - aLevel;
54
- });
55
- fatherConfigs.forEach((item) => {
56
- var _a2, _b2, _c2;
57
- (_b2 = memo.alias)[_c2 = `${api.pkg.name}/${((_a2 = item.output) == null ? void 0 : _a2.path) || item.output}`] ?? (_b2[_c2] = import_path.default.join(api.cwd, item.entry || item.input));
58
- });
59
- (_b = memo.alias)[_c = api.pkg.name] ?? (_b[_c] = entryDir);
47
+ memo.fatherConfigs = await (0, import_utils.tryFatherBuildConfigs)(api.cwd);
48
+ return memo;
49
+ });
50
+ api.chainWebpack((memo) => {
51
+ const fatherConfigs = api.appData.fatherConfigs;
52
+ fatherConfigs.sort((a, b) => {
53
+ var _a, _b;
54
+ const aLevel = (((_a = a.output) == null ? void 0 : _a.path) || a.output).split("/").length;
55
+ const bLevel = (((_b = b.output) == null ? void 0 : _b.path) || b.output).split("/").length;
56
+ return bLevel - aLevel;
57
+ });
58
+ fatherConfigs.forEach((item) => {
59
+ var _a;
60
+ const key = `${api.pkg.name}/${((_a = item.output) == null ? void 0 : _a.path) || item.output}`;
61
+ if (!memo.resolve.alias.has(key)) {
62
+ memo.resolve.alias.set(key, import_path.default.join(api.cwd, item.entry || item.input));
63
+ }
64
+ });
65
+ if (entryDir && !memo.resolve.alias.has(api.pkg.name)) {
66
+ memo.resolve.alias.set(api.pkg.name, entryDir);
60
67
  }
61
68
  return memo;
62
69
  });
@@ -31,11 +31,16 @@ var import_assert = __toESM(require("assert"));
31
31
  var import_fs = __toESM(require("fs"));
32
32
  var import_path = __toESM(require("path"));
33
33
  var import_plugin_utils = require("umi/plugin-utils");
34
+ function isMFSUAvailable(api) {
35
+ return process.platform !== "win32" && api.userConfig.mfsu !== false;
36
+ }
34
37
  function safeExcludeInMFSU(api, excludes) {
35
- if (api.userConfig.mfsu !== false) {
36
- api.modifyDefaultConfig((memo) => {
38
+ if (isMFSUAvailable(api)) {
39
+ api.modifyConfig((memo) => {
37
40
  if (memo.mfsu === false)
38
41
  return memo;
42
+ else if (memo.mfsu === true)
43
+ memo.mfsu = {};
39
44
  memo.mfsu ?? (memo.mfsu = {});
40
45
  memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
41
46
  memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
@@ -87,20 +92,14 @@ var derivative_default = (api) => {
87
92
  new RegExp("compiled/_internal/searchWorker")
88
93
  ]);
89
94
  api.modifyDefaultConfig((memo) => {
90
- if (api.userConfig.mfsu !== false) {
91
- if (import_fs.default.existsSync(import_path.default.join(api.cwd, "node_modules", ".pnpm")) || process.platform === "win32") {
92
- memo.mfsu = false;
93
- } else {
94
- memo.mfsu.strategy = "normal";
95
- memo.mfsu.shared = {
96
- react: { singleton: true },
97
- "react-dom": { singleton: true }
98
- };
99
- import_constants.CLIENT_DEPS.forEach((pkg) => {
100
- memo.alias ?? (memo.alias = {});
101
- memo.alias[pkg] = (0, import_plugin_utils.winPath)(import_path.default.dirname(require.resolve(`${pkg}/package.json`)));
102
- });
103
- }
95
+ if (!isMFSUAvailable(api)) {
96
+ memo.mfsu = false;
97
+ } else {
98
+ memo.mfsu.strategy = "normal";
99
+ memo.mfsu.shared = {
100
+ react: { singleton: true },
101
+ "react-dom": { singleton: true }
102
+ };
104
103
  }
105
104
  if (api.userConfig.conventionRoutes !== false) {
106
105
  memo.conventionRoutes = {
@@ -117,9 +116,6 @@ var derivative_default = (api) => {
117
116
  });
118
117
  api.modifyConfig((memo) => {
119
118
  var _a;
120
- if (api.userConfig.mfsu === true) {
121
- memo.mfsu = {};
122
- }
123
119
  if ((_a = api.userConfig.alias) == null ? void 0 : _a["@"]) {
124
120
  memo.alias["@"] = api.userConfig.alias["@"];
125
121
  } else {
@@ -140,6 +136,10 @@ var derivative_default = (api) => {
140
136
  });
141
137
  const umiPath = import_path.default.join(api.paths.absTmpPath, "umi.ts");
142
138
  import_plugin_utils.fsExtra.writeFileSync(umiPath, import_plugin_utils.fsExtra.readFileSync(umiPath, "utf-8").replace("'@/loading'", "'../loading'"));
139
+ if (api.config.ssr && import_plugin_utils.semver.subset(api.appData.umi.version, "4.0.54 - 4.0.55")) {
140
+ const helmetPath = import_path.default.join(api.paths.absTmpPath, "core/helmet.ts");
141
+ import_plugin_utils.fsExtra.writeFileSync(helmetPath, import_plugin_utils.fsExtra.readFileSync(helmetPath, "utf-8").replace(/(return )(React\.createElement)/, "$1typeof window === 'undefined' ? container : $2"));
142
+ }
143
143
  }
144
144
  });
145
145
  api.registerPlugins([require.resolve("../../compiled/@umijs/plugins")]);
@@ -23,46 +23,54 @@ __export(exportStatic_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(exportStatic_exports);
25
25
  var import_constants = require("../constants");
26
- var import_plugin_utils = require("umi/plugin-utils");
27
26
  var import_assets = require("./assets");
27
+ var NO_PRERENDER_ROUTES = [
28
+ "demo-render"
29
+ ];
28
30
  var exportStatic_default = (api) => {
29
- const prevExtraRoutePaths = [];
30
31
  api.describe({ key: "dumi:exportStatic" });
31
- api.register({
32
- key: "modifyDefaultConfig",
32
+ api.modifyRoutes({
33
33
  stage: Infinity,
34
34
  fn(memo) {
35
- if (memo.exportStatic && memo.exportStatic.extraRoutePaths) {
36
- prevExtraRoutePaths.push(memo.exportStatic.extraRoutePaths);
37
- }
35
+ NO_PRERENDER_ROUTES.forEach((id) => {
36
+ if (memo[id])
37
+ memo[id].prerender = false;
38
+ });
39
+ return memo;
38
40
  }
39
41
  });
40
- api.register({
41
- key: "modifyConfig",
42
- stage: Infinity,
42
+ api.modifyExportHTMLFiles({
43
+ before: "exportStatic",
43
44
  fn(memo) {
44
- var _a;
45
- if (memo.exportStatic !== false) {
46
- if ((_a = memo.exportStatic) == null ? void 0 : _a.extraRoutePaths) {
47
- prevExtraRoutePaths.push(memo.exportStatic.extraRoutePaths);
48
- }
49
- memo.exportStatic ?? (memo.exportStatic = {});
50
- memo.exportStatic.extraRoutePaths = async () => {
51
- const examples = (0, import_assets.getExampleAssets)();
52
- const userExtraPaths = [];
53
- const isSupportDisablePrerender = import_plugin_utils.semver.gte(api.appData.umi.version, "4.0.48");
54
- for (const prev of prevExtraRoutePaths) {
55
- userExtraPaths.push(...typeof prev === "function" ? await prev() : prev);
56
- }
57
- return userExtraPaths.concat(examples.map(({ id }) => {
58
- const demoPath = `/${import_constants.SP_ROUTE_PREFIX}demos/${id}`;
59
- return isSupportDisablePrerender ? { path: demoPath, prerender: false } : demoPath;
60
- }));
61
- };
62
- }
45
+ const routePrefix = `${import_constants.SP_ROUTE_PREFIX}demos`;
46
+ const examples = (0, import_assets.getExampleAssets)();
47
+ api.appData.exportHtmlData.push(...examples.map(({ id }) => ({
48
+ route: { path: `/${routePrefix}/${id}` },
49
+ file: `${routePrefix}/${id}/index.html`,
50
+ prerender: false
51
+ })));
63
52
  return memo;
64
53
  }
65
54
  });
55
+ api.onGenerateFiles(() => {
56
+ api.writeTmpFile({
57
+ path: "dumi/exportStaticRuntimePlugin.ts",
58
+ content: `
59
+ export function modifyClientRenderOpts(memo: any) {
60
+ const { history, hydrate } = memo;
61
+
62
+ return {
63
+ ...memo,
64
+ hydrate: hydrate && !history.location.pathname.startsWith('/${import_constants.SP_ROUTE_PREFIX}demos'),
65
+ };
66
+ }
67
+ `.trim(),
68
+ noPluginDir: true
69
+ });
70
+ });
71
+ api.addRuntimePlugin(() => {
72
+ return [`@@/dumi/exportStaticRuntimePlugin.ts`];
73
+ });
66
74
  };
67
75
  // Annotate the CommonJS export names for ESM import in node:
68
76
  0 && (module.exports = {});
@@ -42,7 +42,8 @@ var parser_default = (api) => {
42
42
  config: {
43
43
  schema: (Joi) => Joi.object({
44
44
  unpkgHost: Joi.string().uri().optional(),
45
- resolveFilter: Joi.function().optional()
45
+ resolveFilter: Joi.function().optional(),
46
+ parseOptions: Joi.object().optional()
46
47
  })
47
48
  }
48
49
  });
@@ -59,7 +60,8 @@ var parser_default = (api) => {
59
60
  entryFile: api.config.resolve.entryFile,
60
61
  resolveDir: api.cwd,
61
62
  unpkgHost: api.config.apiParser.unpkgHost,
62
- resolveFilter: api.config.apiParser.resolveFilter
63
+ resolveFilter: api.config.apiParser.resolveFilter,
64
+ parseOptions: api.config.apiParser.parseOptions
63
65
  });
64
66
  });
65
67
  api.onDevCompileDone(({ isFirstCompile }) => {
@@ -26,8 +26,9 @@ __export(routes_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(routes_exports);
28
28
  var import_constants = require("../constants");
29
+ var import_utils = require("../utils");
29
30
  var import_core = require("@umijs/core");
30
- var import_utils = require("@umijs/core/dist/route/utils");
31
+ var import_utils2 = require("@umijs/core/dist/route/utils");
31
32
  var import_path = __toESM(require("path"));
32
33
  var import_pluralize = require("pluralize");
33
34
  var import_plugin_utils = require("umi/plugin-utils");
@@ -61,18 +62,6 @@ function flatRoute(route, docLayoutId) {
61
62
  route.path = route.path === "*" ? route.path : route.absPath.slice(1);
62
63
  }
63
64
  }
64
- function getClientPageFile(file, cwd) {
65
- let clientFile;
66
- try {
67
- clientFile = import_plugin_utils.resolve.sync(`dumi/dist/${file}`, {
68
- basedir: cwd,
69
- preserveSymlinks: false
70
- });
71
- } catch {
72
- clientFile = require.resolve(`../${file}`);
73
- }
74
- return (0, import_plugin_utils.winPath)(clientFile);
75
- }
76
65
  var routes_default = (api) => {
77
66
  var _a, _b, _c;
78
67
  const extraWatchPaths = [
@@ -159,7 +148,7 @@ var routes_default = (api) => {
159
148
  atomFiles.forEach((file) => {
160
149
  const routeFile = (0, import_plugin_utils.winPath)(import_path.default.join((0, import_pluralize.plural)(type), file));
161
150
  const routePath = routeFile.replace(/(\/index|\/README)?\.md$/, "").replace(/\./g, "/");
162
- const routeId = (0, import_utils.createRouteId)(routeFile);
151
+ const routeId = (0, import_utils2.createRouteId)(routeFile);
163
152
  routes[routeId] = {
164
153
  id: routeId,
165
154
  path: routePath,
@@ -184,7 +173,7 @@ var routes_default = (api) => {
184
173
  path: "*",
185
174
  absPath: "/*",
186
175
  parentId: docLayoutId,
187
- file: getClientPageFile("client/pages/404", api.cwd)
176
+ file: (0, import_utils.getClientDistFile)("dist/client/pages/404", api.cwd)
188
177
  };
189
178
  }
190
179
  routes["demo-render"] = {
@@ -192,8 +181,7 @@ var routes_default = (api) => {
192
181
  path: `${import_constants.SP_ROUTE_PREFIX}demos/:id`,
193
182
  absPath: `/${import_constants.SP_ROUTE_PREFIX}demos/:id`,
194
183
  parentId: demoLayoutId,
195
- file: getClientPageFile("client/pages/Demo", api.cwd),
196
- prerender: false
184
+ file: (0, import_utils.getClientDistFile)("dist/client/pages/Demo", api.cwd)
197
185
  };
198
186
  return routes;
199
187
  });
@@ -26,13 +26,13 @@ __export(theme_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(theme_exports);
28
28
  var import_constants = require("../../constants");
29
+ var import_utils = require("../../utils");
29
30
  var import_bundler_utils = require("@umijs/bundler-utils");
30
31
  var import_fs = __toESM(require("fs"));
31
32
  var import_path = __toESM(require("path"));
32
33
  var import_plugin_utils = require("umi/plugin-utils");
33
34
  var import_derivative = require("../derivative");
34
35
  var import_loader = __toESM(require("./loader"));
35
- var DEFAULT_THEME_PATH = import_path.default.join(__dirname, "../../../theme-default");
36
36
  function getPkgThemeName(api) {
37
37
  const validDeps = Object.assign({}, api.pkg.dependencies, api.pkg.devDependencies);
38
38
  const pkgThemeName = Object.keys(validDeps).find((pkg) => pkg.split("/").pop().startsWith(import_constants.THEME_PREFIX));
@@ -40,7 +40,10 @@ function getPkgThemeName(api) {
40
40
  }
41
41
  function getPkgThemePath(api) {
42
42
  const pkgThemeName = getPkgThemeName(api);
43
- return pkgThemeName && import_path.default.dirname(require.resolve(`${pkgThemeName}/package.json`, { paths: [api.cwd] }));
43
+ return pkgThemeName && import_path.default.dirname(import_plugin_utils.resolve.sync(`${pkgThemeName}/package.json`, {
44
+ basedir: api.cwd,
45
+ preserveSymlinks: true
46
+ }));
44
47
  }
45
48
  function getModuleExports(modulePath) {
46
49
  return (0, import_bundler_utils.parseModuleSync)({
@@ -49,6 +52,7 @@ function getModuleExports(modulePath) {
49
52
  })[1];
50
53
  }
51
54
  var theme_default = (api) => {
55
+ const DEFAULT_THEME_PATH = import_path.default.join((0, import_utils.getClientDistFile)("package.json", api.cwd), "../theme-default");
52
56
  const defaultThemeData = (0, import_loader.default)(DEFAULT_THEME_PATH);
53
57
  const pkgThemePath = getPkgThemePath(api);
54
58
  const pkgThemeData = (0, import_plugin_utils.deepmerge)(defaultThemeData, pkgThemePath ? (0, import_loader.default)(import_path.default.join(pkgThemePath, "dist")) : {});
@@ -29,6 +29,7 @@ var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
29
29
  var import_rehypeDemo = __toESM(require("./rehypeDemo"));
30
30
  var import_rehypeDesc = __toESM(require("./rehypeDesc"));
31
31
  var import_rehypeEnhancedTag = __toESM(require("./rehypeEnhancedTag"));
32
+ var import_rehypeHighlightLine = __toESM(require("./rehypeHighlightLine"));
32
33
  var import_rehypeImg = __toESM(require("./rehypeImg"));
33
34
  var import_rehypeIsolation = __toESM(require("./rehypeIsolation"));
34
35
  var import_rehypeJsxify = __toESM(require("./rehypeJsxify"));
@@ -73,6 +74,8 @@ var transformer_default = async (raw, opts) => {
73
74
  }));
74
75
  processor.use(remarkRehype, { allowDangerousHtml: true }).use(import_rehypeRaw.default, {
75
76
  fileAbsPath: opts.fileAbsPath
77
+ }).use(import_rehypeHighlightLine.default, {
78
+ resolve: opts.resolve
76
79
  }).use(rehypeRemoveComments, { removeConditional: true }).use(import_rehypeStrip.default).use(import_rehypeImg.default).use(import_rehypeDemo.default, {
77
80
  techStacks: opts.techStacks,
78
81
  cwd: opts.cwd,
@@ -79,6 +79,7 @@ function tryMarkDemoNode(node, opts) {
79
79
  function rehypeDemo(opts) {
80
80
  return async (tree, vFile) => {
81
81
  const deferrers = [];
82
+ const demoIds = [];
82
83
  const replaceNodes = [];
83
84
  let index = 0;
84
85
  visit(tree, "element", (node) => {
@@ -129,7 +130,7 @@ function rehypeDemo(opts) {
129
130
  if (isElement(node, "p") && ((_a = node.data) == null ? void 0 : _a[DEMO_NODE_CONTAINER])) {
130
131
  const demosPropData = [];
131
132
  node.children.forEach((codeNode) => {
132
- var _a2;
133
+ var _a2, _b;
133
134
  if (isElement(codeNode, "code")) {
134
135
  const codeType = codeNode.data.type;
135
136
  const techStack = codeNode.data.techStack;
@@ -146,11 +147,12 @@ function rehypeDemo(opts) {
146
147
  if (codeType === "external") {
147
148
  const chunkName = [vFile.data.frontmatter.atomId, "demos"].filter(Boolean).join("__");
148
149
  parseOpts.fileAbsPath = (0, import_plugin_utils.winPath)(codeNode.properties.src);
149
- parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, import_path.default.parse(parseOpts.fileAbsPath.replace(/\/index\.(j|t)sx?$/, "")).name, vFile.data.frontmatter.atomId);
150
+ let localId = ((_a2 = codeNode.properties) == null ? void 0 : _a2.id) ?? import_path.default.parse(parseOpts.fileAbsPath.replace(/\/index\.(j|t)sx?$/, "")).name;
151
+ parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, localId, vFile.data.frontmatter.atomId);
150
152
  component = `React.lazy(() => import( /* webpackChunkName: "${chunkName}" */ '${(0, import_plugin_utils.winPath)(parseOpts.fileAbsPath)}?techStack=${techStack.name}'))`;
151
153
  if (codeValue)
152
154
  codeNode.properties.title = codeValue;
153
- (_a2 = codeNode.properties).filename ?? (_a2.filename = (0, import_plugin_utils.winPath)(import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)));
155
+ (_b = codeNode.properties).filename ?? (_b.filename = (0, import_plugin_utils.winPath)(import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)));
154
156
  } else {
155
157
  parseOpts.fileAbsPath = opts.fileAbsPath.replace(".md", ".tsx");
156
158
  parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, String(index++), vFile.data.frontmatter.atomId);
@@ -160,8 +162,15 @@ function rehypeDemo(opts) {
160
162
  });
161
163
  }
162
164
  const propDemo = { id: parseOpts.id };
165
+ demoIds.push(parseOpts.id);
163
166
  deferrers.push((0, import_block.default)(parseOpts).then(async ({ asset, sources, frontmatter }) => {
164
- var _a3, _b;
167
+ var _a3, _b2, _c;
168
+ if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
169
+ const startLine = (_a3 = node.position) == null ? void 0 : _a3.start.line;
170
+ const suffix = startLine ? `:${startLine}` : "";
171
+ import_plugin_utils.logger.warn(`Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this.
172
+ at ${opts.fileAbsPath}${suffix}`);
173
+ }
165
174
  const { src, className, ...restAttrs } = codeNode.properties || {};
166
175
  const validAssetAttrs = [
167
176
  "title",
@@ -183,14 +192,14 @@ function rehypeDemo(opts) {
183
192
  if (originalProps[key])
184
193
  asset[key] = originalProps[key];
185
194
  });
186
- if (/ inline/.test(String((_a3 = codeNode.data) == null ? void 0 : _a3.meta)) || originalProps.inline) {
195
+ if (/ inline/.test(String((_b2 = codeNode.data) == null ? void 0 : _b2.meta)) || originalProps.inline) {
187
196
  propDemo.inline = true;
188
197
  return {
189
198
  id: asset.id,
190
199
  component
191
200
  };
192
201
  }
193
- Object.assign(previewerProps, await ((_b = techStack.generatePreviewerProps) == null ? void 0 : _b.call(techStack, originalProps, techStackOpts)) || originalProps);
202
+ Object.assign(previewerProps, await ((_c = techStack.generatePreviewerProps) == null ? void 0 : _c.call(techStack, originalProps, techStackOpts)) || originalProps);
194
203
  if (previewerProps.description) {
195
204
  const { unified } = await import("unified");
196
205
  const { default: remarkParse } = await import("remark-parse");
@@ -36,14 +36,22 @@ var toString;
36
36
  function rehypeEnhancedTag() {
37
37
  return async (tree) => {
38
38
  visit(tree, "element", (node, i, parent) => {
39
- var _a, _b, _c;
39
+ var _a, _b, _c, _d;
40
40
  if (node.tagName === "pre" && isElement((_a = node.children) == null ? void 0 : _a[0]) && node.children[0].tagName === "code") {
41
41
  const className = ((_b = node.children[0].properties) == null ? void 0 : _b.className) || [];
42
42
  const lang = (_c = className.join("").match(/language-(\w+)(?:$| )/)) == null ? void 0 : _c[1];
43
+ const highlightLines = (_d = node.children[0].data) == null ? void 0 : _d.highlightLines;
43
44
  parent.children.splice(i, 1, {
44
45
  type: "element",
45
46
  tagName: "SourceCode",
46
47
  properties: { lang },
48
+ JSXAttributes: [
49
+ {
50
+ type: "JSXAttribute",
51
+ name: "highlightLines",
52
+ value: JSON.stringify(highlightLines)
53
+ }
54
+ ],
47
55
  children: [
48
56
  {
49
57
  type: "text",
@@ -0,0 +1,4 @@
1
+ import type { Root } from 'hast';
2
+ import type { Transformer } from 'unified';
3
+ declare function rehypeHighlightLine(): Transformer<Root>;
4
+ export default rehypeHighlightLine;
@@ -0,0 +1,60 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/loaders/markdown/transformer/rehypeHighlightLine.ts
23
+ var rehypeHighlightLine_exports = {};
24
+ __export(rehypeHighlightLine_exports, {
25
+ default: () => rehypeHighlightLine_default
26
+ });
27
+ module.exports = __toCommonJS(rehypeHighlightLine_exports);
28
+ var visit;
29
+ var isElement;
30
+ var RE = /{((?:\d+(?:-\d+)?,?)+)}/;
31
+ (async () => {
32
+ ({ visit } = await import("unist-util-visit"));
33
+ ({ isElement } = await import("hast-util-is-element"));
34
+ })();
35
+ var attrsToLines = (attrs) => {
36
+ const result = [];
37
+ attrs.split(",").map((v) => v.split("-").map((v2) => parseInt(v2, 10))).forEach(([start, end = start]) => {
38
+ for (let i = start; i <= end; i++) {
39
+ result.push(i);
40
+ }
41
+ });
42
+ return result;
43
+ };
44
+ function rehypeHighlightLine() {
45
+ return async (tree) => {
46
+ visit(tree, "element", (node) => {
47
+ var _a, _b;
48
+ if (isElement(node, "code") && typeof ((_a = node.data) == null ? void 0 : _a.meta) === "string") {
49
+ const lines = (_b = node.data.meta.match(RE)) == null ? void 0 : _b[1];
50
+ if (lines) {
51
+ node.data.meta = node.data.meta.replace(lines, "").trim();
52
+ node.data.highlightLines = attrsToLines(lines);
53
+ }
54
+ }
55
+ });
56
+ };
57
+ }
58
+ var rehypeHighlightLine_default = rehypeHighlightLine;
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {});
@@ -37,12 +37,12 @@ var SKIP;
37
37
  function rehypeLink(opts) {
38
38
  return (tree) => {
39
39
  visit(tree, "element", (node, i, parent) => {
40
- var _a;
41
- if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string") {
40
+ var _a, _b, _c;
41
+ if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string" && !((_b = node.properties) == null ? void 0 : _b.target) && !((_c = node.properties) == null ? void 0 : _c.download)) {
42
42
  const href = node.properties.href;
43
43
  const parsedUrl = import_url.default.parse(href);
44
44
  const hostAbsPath = (0, import_tabs.getHostForTabRouteFile)(opts.fileAbsPath);
45
- if (parsedUrl.hostname)
45
+ if (parsedUrl.protocol || href.startsWith("//"))
46
46
  return SKIP;
47
47
  if (/\.md$/i.test(parsedUrl.pathname)) {
48
48
  const { routes } = opts;
@@ -52,7 +52,7 @@ function rehypeLink(opts) {
52
52
  parsedUrl.pathname = routes[key].absPath;
53
53
  }
54
54
  });
55
- } else if (/^\.?\.\//.test(parsedUrl.pathname) || /^(\w+:)?\/\//.test(parsedUrl.pathname)) {
55
+ } else if (parsedUrl.pathname && /^[^/]+/.test(parsedUrl.pathname)) {
56
56
  const routes = Object.values(opts.routes);
57
57
  const basePath = routes.find((route) => route.file === hostAbsPath).absPath;
58
58
  const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
package/dist/utils.d.ts CHANGED
@@ -34,4 +34,8 @@ export declare function tryFatherBuildConfigs(cwd: string): Promise<any[]>;
34
34
  * get root dir for monorepo project
35
35
  */
36
36
  export declare function getProjectRoot(cwd: string): string;
37
+ /**
38
+ * get dumi client dist file and preserve symlink(pnpm, tnpm & etc.) to make chunk name clean
39
+ */
40
+ export declare function getClientDistFile(file: string, cwd: string): string;
37
41
  export {};
package/dist/utils.js CHANGED
@@ -23,6 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
23
23
  var utils_exports = {};
24
24
  __export(utils_exports, {
25
25
  getCache: () => getCache,
26
+ getClientDistFile: () => getClientDistFile,
26
27
  getFileContentByRegExp: () => getFileContentByRegExp,
27
28
  getFileRangeLines: () => getFileRangeLines,
28
29
  getProjectRoot: () => getProjectRoot,
@@ -117,9 +118,22 @@ function getProjectRoot(cwd) {
117
118
  }
118
119
  return (0, import_plugin_utils.winPath)(cwd);
119
120
  }
121
+ function getClientDistFile(file, cwd) {
122
+ let clientFile;
123
+ try {
124
+ clientFile = import_plugin_utils.resolve.sync(`dumi/${file}`, {
125
+ basedir: cwd,
126
+ preserveSymlinks: true
127
+ });
128
+ } catch {
129
+ clientFile = require.resolve(`../${file}`);
130
+ }
131
+ return (0, import_plugin_utils.winPath)(clientFile);
132
+ }
120
133
  // Annotate the CommonJS export names for ESM import in node:
121
134
  0 && (module.exports = {
122
135
  getCache,
136
+ getClientDistFile,
123
137
  getFileContentByRegExp,
124
138
  getFileRangeLines,
125
139
  getProjectRoot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.14",
3
+ "version": "2.1.16",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -80,8 +80,8 @@
80
80
  "@swc/core": "^1.2.224",
81
81
  "@types/hast": "^2.3.4",
82
82
  "@types/mdast": "^3.0.10",
83
- "@umijs/bundler-utils": "^4.0.53",
84
- "@umijs/core": "^4.0.53",
83
+ "@umijs/bundler-utils": "^4.0.59",
84
+ "@umijs/core": "^4.0.59",
85
85
  "animated-scroll-to": "^2.3.0",
86
86
  "classnames": "2.3.2",
87
87
  "codesandbox": "^2.2.3",
@@ -122,7 +122,7 @@
122
122
  "remark-rehype": "^10.1.0",
123
123
  "sass": "^1.55.0",
124
124
  "sitemap": "^7.1.1",
125
- "umi": "^4.0.53",
125
+ "umi": "^4.0.59",
126
126
  "unified": "^10.1.2",
127
127
  "unist-util-visit": "^4.1.0",
128
128
  "unist-util-visit-parents": "^5.1.1",
@@ -141,7 +141,7 @@
141
141
  "@types/pluralize": "^0.0.29",
142
142
  "@types/react": "^18.0.16",
143
143
  "@types/react-copy-to-clipboard": "^5.0.4",
144
- "@umijs/lint": "^4.0.53",
144
+ "@umijs/lint": "^4.0.59",
145
145
  "@umijs/plugins": "4.0.32",
146
146
  "dumi-theme-mobile": "workspace:*",
147
147
  "eslint": "^8.20.0",
@@ -2,7 +2,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2
2
 
3
3
  import classnames from 'classnames';
4
4
  import { useLocation } from 'dumi';
5
- import PreviewerActions from "dumi/theme/slots/PreviewerActions";
5
+ import PreviewerActions from 'dumi/theme/slots/PreviewerActions';
6
6
  import React from 'react';
7
7
  import "./index.less";
8
8
 
@@ -107,7 +107,7 @@
107
107
  display: inline-block;
108
108
  font-size: 14px;
109
109
  line-height: 1;
110
- font-weight: 500;
110
+ font-weight: bold;
111
111
  background: linear-gradient(
112
112
  to top,
113
113
  rgba(255, 255, 255, 100%),
@@ -2,8 +2,10 @@ import { type Language } from 'prism-react-renderer';
2
2
  import 'prism-themes/themes/prism-one-light.css';
3
3
  import { type FC } from 'react';
4
4
  import './index.less';
5
- declare const SourceCode: FC<{
5
+ interface SourceCodeProps {
6
6
  children: string;
7
7
  lang: Language;
8
- }>;
8
+ highlightLines?: number[];
9
+ }
10
+ declare const SourceCode: FC<SourceCodeProps>;
9
11
  export default SourceCode;
@@ -14,6 +14,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
15
  import { ReactComponent as IconCheck } from '@ant-design/icons-svg/inline-svg/outlined/check.svg';
16
16
  import { ReactComponent as IconCopy } from '@ant-design/icons-svg/inline-svg/outlined/copy.svg';
17
+ import classNames from 'classnames';
17
18
  import Highlight, { defaultProps } from 'prism-react-renderer';
18
19
  import 'prism-themes/themes/prism-one-light.css';
19
20
  import React, { useRef, useState } from 'react';
@@ -28,9 +29,11 @@ var SIMILAR_DSL = {
28
29
  axml: 'markup'
29
30
  };
30
31
 
31
- var SourceCode = function SourceCode(_ref) {
32
- var children = _ref.children,
33
- lang = _ref.lang;
32
+ var SourceCode = function SourceCode(props) {
33
+ var children = props.children,
34
+ lang = props.lang,
35
+ _props$highlightLines = props.highlightLines,
36
+ highlightLines = _props$highlightLines === void 0 ? [] : _props$highlightLines;
34
37
  var timer = useRef();
35
38
 
36
39
  var _useState = useState(false),
@@ -57,12 +60,12 @@ var SourceCode = function SourceCode(_ref) {
57
60
  code: children.trim(),
58
61
  language: SIMILAR_DSL[lang] || lang,
59
62
  theme: undefined
60
- }), function (_ref2) {
61
- var className = _ref2.className,
62
- style = _ref2.style,
63
- tokens = _ref2.tokens,
64
- getLineProps = _ref2.getLineProps,
65
- getTokenProps = _ref2.getTokenProps;
63
+ }), function (_ref) {
64
+ var className = _ref.className,
65
+ style = _ref.style,
66
+ tokens = _ref.tokens,
67
+ getLineProps = _ref.getLineProps,
68
+ getTokenProps = _ref.getTokenProps;
66
69
  return /*#__PURE__*/React.createElement("pre", {
67
70
  className: className,
68
71
  style: style
@@ -71,7 +74,10 @@ var SourceCode = function SourceCode(_ref) {
71
74
  key: String(i)
72
75
  }, getLineProps({
73
76
  line: line,
74
- key: i
77
+ key: i,
78
+ className: classNames({
79
+ highlighted: highlightLines.includes(i + 1)
80
+ })
75
81
  })), line.map(function (token, key) {
76
82
  return /*#__PURE__*/React.createElement("span", _extends({
77
83
  key: String(i)
@@ -38,6 +38,14 @@
38
38
  &::after {
39
39
  content: none;
40
40
  }
41
+
42
+ // highlight line
43
+ & > .highlighted {
44
+ background-color: shade(@bg-color, 5%);
45
+ width: calc(100% + 48px);
46
+ margin-inline-start: -24px;
47
+ padding-inline-start: 24px;
48
+ }
41
49
  }
42
50
 
43
51
  &-copy {
@@ -92,5 +100,9 @@
92
100
  &-copy {
93
101
  background-color: fadeout(@bg-color, 80%);
94
102
  }
103
+
104
+ & > pre.prism-code > .highlighted {
105
+ background-color: tint(@bg-color, 10%);
106
+ }
95
107
  }
96
108
  }
@@ -13,13 +13,13 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import { ReactComponent as IconSidebar } from '@ant-design/icons-svg/inline-svg/outlined/align-left.svg';
14
14
  import animateScrollTo from 'animated-scroll-to';
15
15
  import { Helmet, useIntl, useLocation, useOutlet, useRouteMeta, useSidebarData, useSiteData } from 'dumi';
16
- import Content from "dumi/theme/slots/Content";
17
- import Features from "dumi/theme/slots/Features";
18
- import Footer from "dumi/theme/slots/Footer";
19
- import Header from "dumi/theme/slots/Header";
20
- import Hero from "dumi/theme/slots/Hero";
21
- import Sidebar from "dumi/theme/slots/Sidebar";
22
- import Toc from "dumi/theme/slots/Toc";
16
+ import Content from 'dumi/theme/slots/Content';
17
+ import Features from 'dumi/theme/slots/Features';
18
+ import Footer from 'dumi/theme/slots/Footer';
19
+ import Header from 'dumi/theme/slots/Header';
20
+ import Hero from 'dumi/theme/slots/Hero';
21
+ import Sidebar from 'dumi/theme/slots/Sidebar';
22
+ import Toc from 'dumi/theme/slots/Toc';
23
23
  import React, { useEffect, useState } from 'react';
24
24
  import "./index.less";
25
25
 
@@ -1,13 +1,18 @@
1
- import { useSidebarData } from 'dumi';
1
+ import { useSidebarData, useSiteData } from 'dumi';
2
2
  import React from 'react';
3
3
  import "./heti.scss";
4
4
  import "./index.less";
5
5
 
6
6
  var Content = function Content(props) {
7
7
  var sidebar = useSidebarData();
8
+
9
+ var _useSiteData = useSiteData(),
10
+ themeConfig = _useSiteData.themeConfig;
11
+
8
12
  return /*#__PURE__*/React.createElement("div", {
9
13
  className: "dumi-default-content",
10
- "data-no-sidebar": !sidebar || undefined
14
+ "data-no-sidebar": !sidebar || undefined,
15
+ "data-no-footer": themeConfig.footer === false || undefined
11
16
  }, props.children);
12
17
  };
13
18
 
@@ -51,6 +51,7 @@
51
51
  // table
52
52
  table {
53
53
  width: 100%;
54
+ table-layout: auto;
54
55
  }
55
56
 
56
57
  th {
@@ -157,12 +158,20 @@
157
158
  background-color: lighten(@c-site-bg-dark, 3%);
158
159
  }
159
160
 
161
+ &[data-no-footer] {
162
+ padding-bottom: @s-content-padding;
163
+ }
164
+
160
165
  @media @mobile {
161
166
  max-width: initial;
162
167
  margin: 0 -24px;
163
168
  padding: 24px 24px 0;
164
169
  border-radius: 0;
165
170
  box-shadow: none;
171
+
172
+ &[data-no-footer] {
173
+ padding: 24px;
174
+ }
166
175
  }
167
176
  }
168
177
 
@@ -174,4 +183,12 @@
174
183
  min-height: calc(100vh - @s-header-height-m);
175
184
  }
176
185
  }
186
+
187
+ &[data-no-sidebar][data-no-footer] {
188
+ margin-bottom: @s-content-padding;
189
+
190
+ @media @mobile {
191
+ margin-bottom: 24px;
192
+ }
193
+ }
177
194
  }
@@ -14,12 +14,12 @@ import HeaderExtra from "../HeadeExtra";
14
14
  import { ReactComponent as IconClose } from '@ant-design/icons-svg/inline-svg/outlined/close.svg';
15
15
  import { ReactComponent as IconMenu } from '@ant-design/icons-svg/inline-svg/outlined/menu.svg';
16
16
  import { useRouteMeta, useSiteData } from 'dumi';
17
- import ColorSwitch from "dumi/theme/slots/ColorSwitch";
18
- import LangSwitch from "dumi/theme/slots/LangSwitch";
19
- import Logo from "dumi/theme/slots/Logo";
20
- import Navbar from "dumi/theme/slots/Navbar";
21
- import RtlSwitch from "dumi/theme/slots/RtlSwitch";
22
- import SearchBar from "dumi/theme/slots/SearchBar";
17
+ import ColorSwitch from 'dumi/theme/slots/ColorSwitch';
18
+ import LangSwitch from 'dumi/theme/slots/LangSwitch';
19
+ import Logo from 'dumi/theme/slots/Logo';
20
+ import Navbar from 'dumi/theme/slots/Navbar';
21
+ import RtlSwitch from 'dumi/theme/slots/RtlSwitch';
22
+ import SearchBar from 'dumi/theme/slots/SearchBar';
23
23
  import React, { useMemo, useState } from 'react';
24
24
  import SocialIcon from "../SocialIcon";
25
25
  import "./index.less";
@@ -1,5 +1,5 @@
1
1
  import { Link, useRouteMeta } from 'dumi';
2
- import HeroTitle from "dumi/theme/slots/HeroTitle";
2
+ import HeroTitle from 'dumi/theme/slots/HeroTitle';
3
3
  import React from 'react';
4
4
  import "./index.less";
5
5
 
@@ -6,7 +6,7 @@
6
6
  color: @c-text;
7
7
  font-size: 22px;
8
8
  line-height: 1;
9
- font-weight: 500;
9
+ font-weight: bold;
10
10
  text-decoration: none;
11
11
 
12
12
  @{dark-selector} & {
@@ -1,7 +1,7 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import { Link, useLocation, useNavData } from 'dumi';
4
- import NavbarExtra from "dumi/theme/slots/NavbarExtra";
4
+ import NavbarExtra from 'dumi/theme/slots/NavbarExtra';
5
5
  import React from 'react';
6
6
  import "./index.less";
7
7
 
@@ -40,7 +40,7 @@
40
40
 
41
41
  &.active {
42
42
  color: @c-text;
43
- font-weight: 500;
43
+ font-weight: bold;
44
44
 
45
45
  @{dark-selector} & {
46
46
  color: @c-text-dark;
@@ -14,8 +14,8 @@ import { ReactComponent as IconCodeSandbox } from '@ant-design/icons-svg/inline-
14
14
 
15
15
  import { ReactComponent as IconStackBlitz } from '@ant-design/icons-svg/inline-svg/outlined/thunderbolt.svg';
16
16
  import { openCodeSandbox, openStackBlitz, useIntl } from 'dumi';
17
- import SourceCode from "dumi/theme/builtins/SourceCode";
18
- import PreviewerActionsExtra from "dumi/theme/slots/PreviewerActionsExtra";
17
+ import SourceCode from 'dumi/theme/builtins/SourceCode';
18
+ import PreviewerActionsExtra from 'dumi/theme/slots/PreviewerActionsExtra';
19
19
  import Tabs from 'rc-tabs';
20
20
  import React, { useState } from 'react';
21
21
  import "./index.less";
@@ -1,5 +1,5 @@
1
1
  import { NavLink, useLocation, useRouteMeta, useSidebarData } from 'dumi';
2
- import Toc from "dumi/theme/slots/Toc";
2
+ import Toc from 'dumi/theme/slots/Toc';
3
3
  import React from 'react';
4
4
  import "./index.less";
5
5
 
@@ -46,7 +46,7 @@
46
46
  margin: 8px 0;
47
47
  color: @c-text;
48
48
  font-size: 14px;
49
- font-weight: 500;
49
+ font-weight: bold;
50
50
  white-space: nowrap;
51
51
  overflow: hidden;
52
52
  text-overflow: ellipsis;
@@ -86,7 +86,7 @@
86
86
 
87
87
  &.active {
88
88
  color: @c-primary;
89
- font-weight: 500;
89
+ font-weight: bold;
90
90
 
91
91
  @{dark-selector} & {
92
92
  color: @c-primary-dark;
@@ -13,7 +13,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
13
13
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
15
  import { Scrollspy as ScrollSpy } from '@makotot/ghostui/src/Scrollspy';
16
- import { Link, useLocation, useRouteMeta, useSiteData } from 'dumi';
16
+ import { Link, useLocation, useRouteMeta, useSiteData, useTabMeta } from 'dumi';
17
17
  import React, { useEffect, useRef, useState } from 'react';
18
18
  import "./index.less";
19
19
 
@@ -23,6 +23,7 @@ var Toc = function Toc() {
23
23
  search = _useLocation.search;
24
24
 
25
25
  var meta = useRouteMeta();
26
+ var tabMeta = useTabMeta();
26
27
 
27
28
  var _useSiteData = useSiteData(),
28
29
  loading = _useSiteData.loading;
@@ -32,18 +33,26 @@ var Toc = function Toc() {
32
33
  var _useState = useState([]),
33
34
  _useState2 = _slicedToArray(_useState, 2),
34
35
  sectionRefs = _useState2[0],
35
- setSectionRefs = _useState2[1]; // only render h2 ~ h4
36
+ setSectionRefs = _useState2[1];
36
37
 
38
+ var memoToc = React.useMemo(function () {
39
+ var toc = meta.toc;
37
40
 
38
- var toc = meta.toc.filter(function (_ref) {
39
- var depth = _ref.depth;
40
- return depth > 1 && depth < 4;
41
- });
41
+ if (tabMeta) {
42
+ toc = tabMeta.toc;
43
+ } // only render h2 ~ h4
44
+
45
+
46
+ return toc.filter(function (_ref) {
47
+ var depth = _ref.depth;
48
+ return depth > 1 && depth < 4;
49
+ });
50
+ }, [meta, tabMeta]);
42
51
  useEffect(function () {
43
52
  // wait for page component ready (DOM ready)
44
53
  if (!loading) {
45
54
  // find all valid headings as ref elements
46
- var refs = toc.map(function (_ref2) {
55
+ var refs = memoToc.map(function (_ref2) {
47
56
  var id = _ref2.id;
48
57
  return {
49
58
  current: document.getElementById(id)
@@ -60,11 +69,11 @@ var Toc = function Toc() {
60
69
  if (currentElementIndexInViewport > -1) prevIndexRef.current = currentElementIndexInViewport;
61
70
  return /*#__PURE__*/React.createElement("ul", {
62
71
  className: "dumi-default-toc"
63
- }, toc.filter(function (_ref4) {
72
+ }, memoToc.filter(function (_ref4) {
64
73
  var depth = _ref4.depth;
65
74
  return depth > 1 && depth < 4;
66
75
  }).map(function (item, i) {
67
- var link = "#".concat(encodeURIComponent(item.id));
76
+ var link = "".concat(search, "#").concat(encodeURIComponent(item.id));
68
77
  var activeIndex = currentElementIndexInViewport > -1 ? currentElementIndexInViewport : prevIndexRef.current;
69
78
  return /*#__PURE__*/React.createElement("li", {
70
79
  key: item.id,