dumi 2.0.0-alpha.2 → 2.0.0-alpha.4

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 (93) hide show
  1. package/dist/client/pages/404.d.ts +1 -0
  2. package/dist/client/pages/404.js +2 -0
  3. package/dist/client/pages/Demo.d.ts +3 -0
  4. package/dist/client/pages/Demo.js +17 -0
  5. package/dist/client/theme-api/DumiDemo.js +8 -5
  6. package/dist/client/theme-api/DumiDemoGrid.d.ts +1 -1
  7. package/dist/client/theme-api/DumiDemoGrid.js +9 -8
  8. package/dist/client/theme-api/context.d.ts +7 -4
  9. package/dist/client/theme-api/context.js +8 -4
  10. package/dist/client/theme-api/index.d.ts +8 -5
  11. package/dist/client/theme-api/index.js +7 -5
  12. package/dist/client/theme-api/types.d.ts +77 -9
  13. package/dist/client/theme-api/useLocale.d.ts +1 -0
  14. package/dist/client/theme-api/useLocale.js +31 -0
  15. package/dist/client/theme-api/useNavData.d.ts +6 -0
  16. package/dist/client/theme-api/useNavData.js +78 -0
  17. package/dist/client/theme-api/{useMatchedRouteMeta.d.ts → useRouteMeta.d.ts} +1 -1
  18. package/dist/client/theme-api/{useMatchedRouteMeta.js → useRouteMeta.js} +6 -3
  19. package/dist/client/theme-api/useSidebarData.d.ts +8 -0
  20. package/dist/client/theme-api/useSidebarData.js +131 -0
  21. package/dist/client/theme-api/utils.d.ts +2 -0
  22. package/dist/client/theme-api/utils.js +44 -0
  23. package/dist/client/tsconfig.json +2 -1
  24. package/dist/constants.d.ts +1 -0
  25. package/dist/constants.js +3 -0
  26. package/dist/features/compile.js +1 -1
  27. package/dist/features/configPlugins/index.js +2 -1
  28. package/dist/features/configPlugins/schema.js +2 -1
  29. package/dist/features/exports.d.ts +3 -0
  30. package/dist/features/exports.js +45 -0
  31. package/dist/features/locales.js +18 -10
  32. package/dist/features/meta.js +2 -2
  33. package/dist/features/routes.js +29 -2
  34. package/dist/features/theme/index.js +6 -6
  35. package/dist/index.d.ts +4 -3
  36. package/dist/index.js +1 -0
  37. package/dist/loaders/markdown/index.js +4 -2
  38. package/dist/loaders/markdown/transformer/index.d.ts +5 -2
  39. package/dist/loaders/markdown/transformer/index.js +4 -2
  40. package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +3 -0
  41. package/dist/loaders/markdown/transformer/rehypeDemo.js +14 -6
  42. package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +9 -1
  43. package/dist/loaders/markdown/transformer/rehypeEmbed.js +16 -4
  44. package/dist/loaders/markdown/transformer/rehypeRaw.js +2 -2
  45. package/dist/loaders/markdown/transformer/rehypeSlug.d.ts +4 -0
  46. package/dist/loaders/markdown/transformer/rehypeSlug.js +105 -0
  47. package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -2
  48. package/dist/loaders/markdown/transformer/remarkMeta.js +24 -3
  49. package/dist/preset.js +1 -0
  50. package/dist/types.d.ts +8 -2
  51. package/package.json +16 -1
  52. package/theme-default/builtins/{Previewer.d.ts → Previewer/index.d.ts} +2 -1
  53. package/theme-default/builtins/Previewer/index.js +162 -0
  54. package/theme-default/builtins/Previewer/index.less +297 -0
  55. package/theme-default/builtins/SourceCode/index.d.ts +9 -0
  56. package/theme-default/builtins/SourceCode/index.js +87 -0
  57. package/theme-default/builtins/SourceCode/index.less +50 -0
  58. package/theme-default/layouts/DocLayout/index.d.ts +1 -0
  59. package/theme-default/layouts/DocLayout/index.js +28 -6
  60. package/theme-default/layouts/DocLayout/index.less +17 -0
  61. package/theme-default/locales/en-US.json +9 -1
  62. package/theme-default/locales/zh-CN.json +9 -1
  63. package/theme-default/slots/Content/heti.scss +3 -0
  64. package/theme-default/slots/Content/index.d.ts +2 -0
  65. package/theme-default/slots/Content/index.js +6 -5
  66. package/theme-default/slots/Content/index.less +31 -0
  67. package/theme-default/slots/Header/index.d.ts +1 -0
  68. package/theme-default/slots/Header/index.js +10 -7
  69. package/theme-default/slots/Header/index.less +22 -0
  70. package/theme-default/slots/LangSwitch/index.d.ts +4 -0
  71. package/theme-default/slots/LangSwitch/index.js +81 -0
  72. package/theme-default/slots/LangSwitch/index.less +13 -0
  73. package/theme-default/slots/Logo/index.d.ts +1 -0
  74. package/theme-default/slots/Logo/index.js +13 -1
  75. package/theme-default/slots/Logo/index.less +16 -0
  76. package/theme-default/slots/Navbar/index.d.ts +1 -0
  77. package/theme-default/slots/Navbar/index.js +20 -1
  78. package/theme-default/slots/Navbar/index.less +33 -0
  79. package/theme-default/slots/NotFound/index.d.ts +4 -0
  80. package/theme-default/slots/NotFound/index.js +20 -0
  81. package/theme-default/slots/NotFound/index.less +26 -0
  82. package/theme-default/slots/SearchBar/index.d.ts +1 -0
  83. package/theme-default/slots/SearchBar/index.js +32 -4
  84. package/theme-default/slots/SearchBar/index.less +61 -0
  85. package/theme-default/slots/Sidebar/index.d.ts +1 -0
  86. package/theme-default/slots/Sidebar/index.js +23 -8
  87. package/theme-default/slots/Sidebar/index.less +57 -0
  88. package/theme-default/slots/Toc/index.d.ts +4 -0
  89. package/theme-default/slots/Toc/index.js +30 -0
  90. package/theme-default/slots/Toc/index.less +31 -0
  91. package/theme-default/styles/utils.less +46 -0
  92. package/theme-default/styles/variables.less +13 -0
  93. package/theme-default/builtins/Previewer.js +0 -11
package/dist/constants.js CHANGED
@@ -20,13 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
22
  LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
23
+ SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
23
24
  THEME_PREFIX: () => THEME_PREFIX
24
25
  });
25
26
  module.exports = __toCommonJS(constants_exports);
26
27
  var LOCAL_THEME_DIR = ".dumi/theme";
27
28
  var THEME_PREFIX = "dumi-theme-";
29
+ var SP_ROUTE_PREFIX = "~";
28
30
  // Annotate the CommonJS export names for ESM import in node:
29
31
  0 && (module.exports = {
30
32
  LOCAL_THEME_DIR,
33
+ SP_ROUTE_PREFIX,
31
34
  THEME_PREFIX
32
35
  });
@@ -50,7 +50,7 @@ var compile_default = (api) => {
50
50
  extraRemarkPlugins: api.config.extraRemarkPlugins,
51
51
  extraRehypePlugins: api.config.extraRehypePlugins
52
52
  };
53
- memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("demo-index").resourceQuery(/meta$/).use("demo-index-loader").loader(loaderPath).options({
53
+ memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("md-meta").resourceQuery(/meta$/).use("md-meta-loader").loader(loaderPath).options({
54
54
  ...loaderBaseOpts,
55
55
  mode: "meta"
56
56
  }).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
@@ -29,7 +29,8 @@ var configPlugins_default = (api) => {
29
29
  docDirs: ["docs"],
30
30
  entityDirs: [{ type: "component", dir: "src" }],
31
31
  codeBlockMode: "active"
32
- }
32
+ },
33
+ themeConfig: {}
33
34
  };
34
35
  const schemas = (0, import_schema.getSchemas)();
35
36
  for (const key of Object.keys(schemas)) {
@@ -33,7 +33,8 @@ function getSchemas() {
33
33
  codeBlockMode: Joi.string().valid("active", "passive").optional()
34
34
  }).optional(),
35
35
  extraRemarkPlugins: getUnifiedPluginSchema,
36
- extraRehypePlugins: getUnifiedPluginSchema
36
+ extraRehypePlugins: getUnifiedPluginSchema,
37
+ themeConfig: (Joi) => Joi.object().optional()
37
38
  };
38
39
  }
39
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,3 @@
1
+ import type { IApi } from "../types";
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,45 @@
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/features/exports.ts
23
+ var exports_exports = {};
24
+ __export(exports_exports, {
25
+ default: () => exports_default
26
+ });
27
+ module.exports = __toCommonJS(exports_exports);
28
+ var import_plugin_utils = require("umi/plugin-utils");
29
+ var exports_default = (api) => {
30
+ api.describe({ key: void 0 });
31
+ api.modifyConfig((memo) => {
32
+ memo.alias["dumi$"] = "@@/dumi/exports";
33
+ return memo;
34
+ });
35
+ api.onGenerateFiles(() => {
36
+ api.writeTmpFile({
37
+ noPluginDir: true,
38
+ path: "dumi/exports.ts",
39
+ content: `export * from '../exports.ts';
40
+ export * from '${(0, import_plugin_utils.winPath)(require.resolve("../client/theme-api"))}';`
41
+ });
42
+ });
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {});
@@ -23,9 +23,16 @@ __export(locales_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(locales_exports);
25
25
  var locales_default = (api) => {
26
+ var _a;
26
27
  api.describe({
27
28
  config: {
28
- default: [{ id: "zh-CN", name: "\u4E2D\u6587", base: "/" }],
29
+ default: [
30
+ {
31
+ id: "zh-CN",
32
+ name: "\u4E2D\u6587",
33
+ ...((_a = api.userConfig.locales) == null ? void 0 : _a[0]) && "suffix" in api.userConfig.locales[0] ? {} : { base: "/" }
34
+ }
35
+ ],
29
36
  schema: (Joi) => {
30
37
  const basicOpts = { id: Joi.string(), name: Joi.string() };
31
38
  return Joi.alternatives(Joi.array().items(Joi.object({
@@ -42,8 +49,8 @@ var locales_default = (api) => {
42
49
  key: "modifyConfig",
43
50
  stage: Infinity,
44
51
  fn: (memo) => {
45
- var _a;
46
- (_a = memo.locales) == null ? void 0 : _a.forEach((locale, i) => {
52
+ var _a2;
53
+ (_a2 = memo.locales) == null ? void 0 : _a2.forEach((locale, i) => {
47
54
  if (!("suffix" in locale)) {
48
55
  locale.base ?? (locale.base = i ? `/${locale.id}` : "/");
49
56
  }
@@ -62,7 +69,7 @@ export const messages = ${JSON.stringify(api.service.themeData.locales, null, 2)
62
69
  noPluginDir: true,
63
70
  path: "dumi/locales/runtime.tsx",
64
71
  content: `
65
- import { history } from 'umi';
72
+ import { history } from 'dumi';
66
73
  import React, { useState, type ReactNode } from 'react';
67
74
  import { RawIntlProvider, createIntl, createIntlCache } from 'react-intl';
68
75
  import { locales, messages } from './config';
@@ -71,16 +78,17 @@ const cache = createIntlCache();
71
78
 
72
79
  const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
73
80
  const [locale] = useState(() => {
74
- const matched = locales.find((locale) => (
75
- // base mode
76
- history.location.pathname.startsWith(locale.base) ||
77
- // suffix mode
78
- ('suffix' in locale && history.location.pathname.endsWith(locale.suffix))
81
+ const matched = locales.slice().reverse().find((locale) => (
82
+ 'suffix' in locale
83
+ // suffix mode
84
+ ? history.location.pathname.endsWith(locale.suffix)
85
+ // base mode
86
+ : history.location.pathname.startsWith(locale.base)
79
87
  ));
80
88
 
81
89
  return matched ? matched.id : locales[0].id;
82
90
  });
83
- const [intl] = useState(() => createIntl({ locale, messages: messages[locale] || {} }, cache))
91
+ const [intl] = useState(() => createIntl({ locale, messages: messages[locale] || {} }, cache));
84
92
 
85
93
  return <RawIntlProvider value={intl}>{props.children}</RawIntlProvider>;
86
94
  }
@@ -42,7 +42,7 @@ var meta_default = (api) => {
42
42
  noPluginDir: true,
43
43
  path: "dumi/meta/index.ts",
44
44
  content: import_plugin_utils.Mustache.render(`{{#mdRouteFiles}}
45
- import { demos as d{{{index}}}, frontmatter as fm{{{index}}} } from '{{{file}}}?type=meta';
45
+ import { demos as d{{{index}}}, frontmatter as fm{{{index}}}, toc as toc{{{index}}} } from '{{{file}}}?type=meta';
46
46
  {{/mdRouteFiles}}
47
47
 
48
48
  export const demos = {
@@ -53,7 +53,7 @@ export const demos = {
53
53
 
54
54
  export const routesMeta = {
55
55
  {{#mdRouteFiles}}
56
- '{{{id}}}': fm{{{index}}},
56
+ '{{{id}}}': { frontmatter: fm{{{index}}}, toc: toc{{{index}}} },
57
57
  {{/mdRouteFiles}}
58
58
  }`, { mdRouteFiles })
59
59
  });
@@ -25,6 +25,7 @@ __export(routes_exports, {
25
25
  default: () => routes_default
26
26
  });
27
27
  module.exports = __toCommonJS(routes_exports);
28
+ var import_constants = require("../constants");
28
29
  var import_core = require("@umijs/core");
29
30
  var import_utils = require("@umijs/core/dist/route/utils");
30
31
  var import_path = __toESM(require("path"));
@@ -36,7 +37,7 @@ function localizeUmiRoute(route, locales) {
36
37
  if (locale) {
37
38
  const base = !("base" in locale) || locale.base === "/" ? "" : locale.base.replace(/^(\/)(.+)$/, "$2$1");
38
39
  const suffix = "suffix" in locale ? locale.suffix : "";
39
- route.path = `${base}${route.path.replace(new RegExp(`/${locale.id}$`), "").replace(/(\/index|\/README)$/, "")}${suffix}`;
40
+ route.path = `${base}${route.path.replace(new RegExp(`/${locale.id}$`), "").replace(/((^|\/)(index|README))$/, "")}${suffix}`;
40
41
  route.absPath = route.path !== "/" ? `/${route.path}` : route.path;
41
42
  }
42
43
  }
@@ -66,11 +67,12 @@ var routes_default = (api) => {
66
67
  }
67
68
  return ret;
68
69
  }, {});
69
- const { DocLayout } = api.service.themeData.layouts;
70
+ const { DocLayout, DemoLayout } = api.service.themeData.layouts;
70
71
  const { docDirs, entityDirs } = api.config.resolve;
71
72
  const layoutRouteValues = Object.values(routes);
72
73
  const lastLayoutId = layoutRouteValues.find(({ id }) => layoutRouteValues.every(({ parentId }) => id !== parentId)).id;
73
74
  let docLayoutId = lastLayoutId;
75
+ let demoLayoutId = lastLayoutId;
74
76
  if (DocLayout) {
75
77
  docLayoutId = DocLayout.specifier;
76
78
  routes[DocLayout.specifier] = {
@@ -82,6 +84,17 @@ var routes_default = (api) => {
82
84
  isLayout: true
83
85
  };
84
86
  }
87
+ if (DemoLayout) {
88
+ demoLayoutId = DemoLayout.specifier;
89
+ routes[DemoLayout.specifier] = {
90
+ id: DemoLayout.specifier,
91
+ path: "/",
92
+ file: DemoLayout.source,
93
+ parentId: lastLayoutId,
94
+ absPath: "/",
95
+ isLayout: true
96
+ };
97
+ }
85
98
  docDirs.forEach((dir) => {
86
99
  const base = import_path.default.join(api.cwd, dir);
87
100
  const dirRoutes = (0, import_core.getConventionRoutes)({
@@ -112,6 +125,20 @@ var routes_default = (api) => {
112
125
  localizeUmiRoute(routes[routeId], api.config.locales);
113
126
  });
114
127
  });
128
+ routes["404"] = {
129
+ id: "404",
130
+ path: "*",
131
+ absPath: "/*",
132
+ parentId: docLayoutId,
133
+ file: require.resolve("../client/pages/404")
134
+ };
135
+ routes["demo-render"] = {
136
+ id: "demo-render",
137
+ path: `${import_constants.SP_ROUTE_PREFIX}demos/:id`,
138
+ absPath: `/${import_constants.SP_ROUTE_PREFIX}demos/:id`,
139
+ parentId: demoLayoutId,
140
+ file: require.resolve("../client/pages/Demo")
141
+ };
115
142
  return routes;
116
143
  });
117
144
  api.addLayouts(() => {
@@ -52,7 +52,7 @@ var theme_default = (api) => {
52
52
  async fn(memo) {
53
53
  const defaultThemeData = (0, import_loader.default)(DEFAULT_THEME_PATH);
54
54
  const pkgThemePath = getPkgThemePath(api);
55
- const pkgThemeData = (0, import_plugin_utils.deepmerge)(defaultThemeData, pkgThemePath ? (0, import_loader.default)(pkgThemePath) : {});
55
+ const pkgThemeData = (0, import_plugin_utils.deepmerge)(defaultThemeData, pkgThemePath ? (0, import_loader.default)(import_path.default.join(pkgThemePath, "dist")) : {});
56
56
  originalThemeData = await api.applyPlugins({
57
57
  key: "modifyTheme",
58
58
  initialValue: pkgThemeData
@@ -66,11 +66,11 @@ var theme_default = (api) => {
66
66
  Object.assign(api.service.themeData.builtins, {
67
67
  DumiDemo: {
68
68
  specifier: "{ DumiDemo }",
69
- source: "dumi/theme"
69
+ source: "dumi"
70
70
  },
71
71
  DumiDemoGrid: {
72
72
  specifier: "{ DumiDemoGrid }",
73
- source: "dumi/theme"
73
+ source: "dumi"
74
74
  }
75
75
  });
76
76
  return memo;
@@ -106,8 +106,8 @@ export { default } from '${item.source}';`
106
106
  api.writeTmpFile({
107
107
  noPluginDir: true,
108
108
  path: "dumi/theme/ContextWrapper.tsx",
109
- content: `import { Context } from 'dumi/theme';
110
- import { useOutlet } from 'umi';
109
+ content: `import { useOutlet } from 'dumi';
110
+ import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
111
111
  import { demos } from '../meta';
112
112
  import { locales } from '../locales/config';
113
113
 
@@ -115,7 +115,7 @@ export default function DumiContextWrapper() {
115
115
  const outlet = useOutlet();
116
116
 
117
117
  return (
118
- <Context.Provider value={{ demos, locales }}>{outlet}</Context.Provider>
118
+ <SiteContext.Provider value={{ demos, locales, themeConfig: ${JSON.stringify(api.config.themeConfig)} }}>{outlet}</SiteContext.Provider>
119
119
  );
120
120
  }`
121
121
  });
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type { IDumiConfig } from "./types";
1
+ import type { IDumiUserConfig } from "./types";
2
2
  declare let unistUtilVisit: typeof import('unist-util-visit');
3
+ export * from 'umi';
4
+ export * from './client/theme-api';
3
5
  export { IApi } from "./types";
4
6
  export type { Root as HastRoot } from 'hast';
5
- export * from 'umi';
6
7
  export type { Plugin as UnifiedPlugin, Transformer as UnifiedTransformer, } from 'unified';
7
8
  export { unistUtilVisit };
8
- export declare const defineConfig: (config: IDumiConfig) => IDumiConfig;
9
+ export declare const defineConfig: (config: IDumiUserConfig) => IDumiUserConfig;
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ __export(src_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(src_exports);
30
30
  __reExport(src_exports, require("umi"), module.exports);
31
+ __reExport(src_exports, require("./client/theme-api"), module.exports);
31
32
  var unistUtilVisit;
32
33
  (async () => {
33
34
  unistUtilVisit = await import("unist-util-visit");
@@ -45,7 +45,8 @@ function mdLoader(raw) {
45
45
  fileAbsPath: this.resourcePath
46
46
  }).then((ret) => {
47
47
  if (opts.mode === "meta") {
48
- const { demos, frontmatter = {} } = ret.meta;
48
+ const { demos, frontmatter, toc, embeds = [] } = ret.meta;
49
+ embeds.forEach((file) => this.addDependency(file));
49
50
  cb(null, import_plugin_utils.Mustache.render(`import React from 'react';
50
51
 
51
52
  export const demos = {
@@ -56,11 +57,12 @@ export const demos = {
56
57
  },
57
58
  {{/demos}}
58
59
  };
59
-
60
60
  export const frontmatter = {{{frontmatter}}};
61
+ export const toc = {{{toc}}}
61
62
  `, {
62
63
  demos,
63
64
  frontmatter: JSON.stringify(frontmatter),
65
+ toc: JSON.stringify(toc),
64
66
  renderAsset: function renderAsset() {
65
67
  Object.keys(this.sources).forEach((file) => {
66
68
  this.asset.dependencies[file].value = `{{{require('!!raw-loader!${this.sources[file]}?raw').default}}}`;
@@ -1,5 +1,5 @@
1
1
  import type { IParsedBlockAsset } from "../../../assetParsers/block";
2
- import type { IRouteMeta } from "../../../client/theme-api";
2
+ import type { IRouteMeta } from "../../../client/theme-api/types";
3
3
  import type { IDumiConfig, IDumiTechStack } from "../../../types";
4
4
  import type { DataMap } from 'vfile';
5
5
  declare module 'hast' {
@@ -22,12 +22,15 @@ declare module 'vfile' {
22
22
  asset: IParsedBlockAsset['asset'];
23
23
  sources: IParsedBlockAsset['sources'];
24
24
  }[];
25
- frontmatter: IRouteMeta;
25
+ frontmatter: IRouteMeta['frontmatter'];
26
+ toc: IRouteMeta['toc'];
27
+ embeds?: string[];
26
28
  }
27
29
  }
28
30
  export interface IMdTransformerOptions {
29
31
  cwd: string;
30
32
  fileAbsPath: string;
33
+ parentAbsPath?: string;
31
34
  techStacks: IDumiTechStack[];
32
35
  codeBlockMode: IDumiConfig['resolve']['codeBlockMode'];
33
36
  extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
@@ -30,6 +30,7 @@ var import_rehypeEmbed = __toESM(require("./rehypeEmbed"));
30
30
  var import_rehypeIsolation = __toESM(require("./rehypeIsolation"));
31
31
  var import_rehypeJsxify = __toESM(require("./rehypeJsxify"));
32
32
  var import_rehypeRaw = __toESM(require("./rehypeRaw"));
33
+ var import_rehypeSlug = __toESM(require("./rehypeSlug"));
33
34
  var import_rehypeStrip = __toESM(require("./rehypeStrip"));
34
35
  var import_remarkMeta = __toESM(require("./remarkMeta"));
35
36
  function applyUnifiedPlugin(opts) {
@@ -46,7 +47,8 @@ var transformer_default = async (raw, opts) => {
46
47
  const { default: remarkBreaks } = await import("remark-breaks");
47
48
  const { default: remarkGfm } = await import("remark-gfm");
48
49
  const { default: remarkRehype } = await import("remark-rehype");
49
- const processor = unified().use(remarkParse).use(remarkFrontmatter).use(import_remarkMeta.default).use(remarkBreaks).use(remarkGfm);
50
+ const { default: rehypeAutolinkHeadings } = await import("rehype-autolink-headings");
51
+ const processor = unified().use(remarkParse).use(remarkFrontmatter).use(import_remarkMeta.default, { fileAbsPath: opts.fileAbsPath }).use(remarkBreaks).use(remarkGfm);
50
52
  (_a = opts.extraRemarkPlugins) == null ? void 0 : _a.forEach((plugin) => applyUnifiedPlugin({
51
53
  plugin,
52
54
  processor,
@@ -59,7 +61,7 @@ var transformer_default = async (raw, opts) => {
59
61
  cwd: opts.cwd,
60
62
  fileAbsPath: opts.fileAbsPath,
61
63
  codeBlockMode: opts.codeBlockMode
62
- }).use(import_rehypeIsolation.default);
64
+ }).use(import_rehypeSlug.default, opts).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default);
63
65
  (_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
64
66
  plugin,
65
67
  processor,
@@ -1,6 +1,9 @@
1
1
  import type { Root } from 'hast';
2
2
  import type { Transformer } from 'unified';
3
3
  import type { IMdTransformerOptions } from '.';
4
+ export declare const DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
5
+ export declare const DUMI_DEMO_TAG = "DumiDemo";
6
+ export declare const DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
4
7
  declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'codeBlockMode'>;
5
8
  export default function rehypeDemo(opts: IRehypeDemoOptions): Transformer<Root>;
6
9
  export {};
@@ -22,6 +22,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/loaders/markdown/transformer/rehypeDemo.ts
23
23
  var rehypeDemo_exports = {};
24
24
  __export(rehypeDemo_exports, {
25
+ DEMO_PROP_VALUE_KEY: () => DEMO_PROP_VALUE_KEY,
26
+ DUMI_DEMO_GRID_TAG: () => DUMI_DEMO_GRID_TAG,
27
+ DUMI_DEMO_TAG: () => DUMI_DEMO_TAG,
25
28
  default: () => rehypeDemo
26
29
  });
27
30
  module.exports = __toCommonJS(rehypeDemo_exports);
@@ -35,9 +38,11 @@ var toString;
35
38
  var isElement;
36
39
  var DEMO_NODE_CONTAINER = "$demo-container";
37
40
  var DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
41
+ var DUMI_DEMO_TAG = "DumiDemo";
42
+ var DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
38
43
  (async () => {
39
44
  ({ visit, SKIP } = await import("unist-util-visit"));
40
- ({ toString } = await import("mdast-util-to-string"));
45
+ ({ toString } = await import("hast-util-to-string"));
41
46
  ({ isElement } = await import("hast-util-is-element"));
42
47
  })();
43
48
  function getCodeLang(node, opts) {
@@ -122,7 +127,7 @@ function rehypeDemo(opts) {
122
127
  if (isElement(codeNode, "code")) {
123
128
  const codeType = codeNode.data.type;
124
129
  const techStack = codeNode.data.techStack;
125
- const codeValue = toString(codeNode.children).trim();
130
+ const codeValue = toString(codeNode).trim();
126
131
  const parseOpts = {
127
132
  id: "",
128
133
  refAtomIds: [],
@@ -191,11 +196,11 @@ function rehypeDemo(opts) {
191
196
  replaceNodes.push(node);
192
197
  node.children = [];
193
198
  if (demosPropData.length === 1) {
194
- node.tagName = "DumiDemo";
199
+ node.tagName = DUMI_DEMO_TAG;
195
200
  node.data[DEMO_PROP_VALUE_KEY] = demosPropData[0];
196
201
  node.JSXAttributes = [{ type: "JSXSpreadAttribute", argument: "" }];
197
202
  } else {
198
- node.tagName = "DumiDemoGrid";
203
+ node.tagName = DUMI_DEMO_GRID_TAG;
199
204
  node.data[DEMO_PROP_VALUE_KEY] = demosPropData;
200
205
  node.JSXAttributes = [
201
206
  { type: "JSXAttribute", name: "items", value: "" }
@@ -213,10 +218,13 @@ function rehypeDemo(opts) {
213
218
  } else {
214
219
  node.JSXAttributes[0].argument = value;
215
220
  }
216
- delete node.data[DEMO_PROP_VALUE_KEY];
217
221
  });
218
222
  });
219
223
  };
220
224
  }
221
225
  // Annotate the CommonJS export names for ESM import in node:
222
- 0 && (module.exports = {});
226
+ 0 && (module.exports = {
227
+ DEMO_PROP_VALUE_KEY,
228
+ DUMI_DEMO_GRID_TAG,
229
+ DUMI_DEMO_TAG
230
+ });
@@ -1,4 +1,12 @@
1
- import type { Root } from 'hast';
1
+ /// <reference types="node" />
2
+ import type { Node, Root } from 'hast';
2
3
  import type { Transformer } from 'unified';
4
+ import url from 'url';
3
5
  import type { IMdTransformerOptions } from '.';
6
+ export declare type IEmbedNodeData = Node['data'] & {
7
+ tagName: string;
8
+ fileAbsPath: string;
9
+ query: InstanceType<typeof url.URLSearchParams>;
10
+ };
11
+ export declare const EMBED_TAG = "embed";
4
12
  export default function rehypeEmbed(opts: Pick<IMdTransformerOptions, 'fileAbsPath'>): Transformer<Root>;
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/loaders/markdown/transformer/rehypeEmbed.ts
23
23
  var rehypeEmbed_exports = {};
24
24
  __export(rehypeEmbed_exports, {
25
+ EMBED_TAG: () => EMBED_TAG,
25
26
  default: () => rehypeEmbed
26
27
  });
27
28
  module.exports = __toCommonJS(rehypeEmbed_exports);
@@ -31,11 +32,12 @@ var visit;
31
32
  (async () => {
32
33
  ({ visit } = await import("unist-util-visit"));
33
34
  })();
35
+ var EMBED_TAG = "embed";
34
36
  function rehypeEmbed(opts) {
35
- return async (tree) => {
37
+ return async (tree, vFile) => {
36
38
  visit(tree, "element", (node, idx, parent) => {
37
- var _a;
38
- if (node.tagName === "embed" && ((_a = node.properties) == null ? void 0 : _a.hasOwnProperty("src"))) {
39
+ var _a, _b;
40
+ if (node.tagName === EMBED_TAG && ((_a = node.properties) == null ? void 0 : _a.hasOwnProperty("src"))) {
39
41
  const { src } = node.properties;
40
42
  const parsed = import_url.default.parse((src == null ? void 0 : src.toString()) || "");
41
43
  const absPath = import_path.default.resolve(import_path.default.parse(opts.fileAbsPath).dir, parsed.pathname);
@@ -48,6 +50,11 @@ function rehypeEmbed(opts) {
48
50
  query.append("regexp", hash.substring(3));
49
51
  }
50
52
  const moduleReqPath = `${absPath}?${query}`;
53
+ const nodeData = {
54
+ tagName: EMBED_TAG,
55
+ fileAbsPath: absPath,
56
+ query
57
+ };
51
58
  switch (import_path.default.extname(parsed.pathname)) {
52
59
  case ".md":
53
60
  default:
@@ -56,6 +63,7 @@ function rehypeEmbed(opts) {
56
63
  tagName: "React.Fragment",
57
64
  children: [],
58
65
  properties: {},
66
+ data: nodeData,
59
67
  position: node.position,
60
68
  JSXAttributes: [
61
69
  {
@@ -66,10 +74,14 @@ function rehypeEmbed(opts) {
66
74
  ]
67
75
  });
68
76
  }
77
+ (_b = vFile.data).embeds ?? (_b.embeds = []);
78
+ vFile.data.embeds.push(absPath);
69
79
  }
70
80
  }
71
81
  });
72
82
  };
73
83
  }
74
84
  // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {});
85
+ 0 && (module.exports = {
86
+ EMBED_TAG
87
+ });
@@ -35,7 +35,7 @@ var CODE_META_STUB_ATTR = "$code-meta";
35
35
  ({ raw } = await import("hast-util-raw"));
36
36
  })();
37
37
  function rehypeRaw() {
38
- return (tree, file) => {
38
+ return (tree, vFile) => {
39
39
  visit(tree, (node) => {
40
40
  var _a;
41
41
  if (node.type === "raw" && COMPONENT_NAME_REGEX.test(node.value)) {
@@ -48,7 +48,7 @@ function rehypeRaw() {
48
48
  node.properties[CODE_META_STUB_ATTR] = node.data.meta;
49
49
  }
50
50
  });
51
- const newTree = raw(tree, file);
51
+ const newTree = raw(tree, vFile);
52
52
  visit(newTree, "element", (node) => {
53
53
  var _a, _b;
54
54
  if ((_a = node.properties) == null ? void 0 : _a[COMPONENT_STUB_ATTR]) {
@@ -0,0 +1,4 @@
1
+ import type { Root } from 'hast';
2
+ import type { Transformer } from 'unified';
3
+ import { type IMdTransformerOptions } from '.';
4
+ export default function rehypeSlug(opts: IMdTransformerOptions): Transformer<Root>;