dumi 2.2.1-alpha.0 → 2.2.2

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 (131) hide show
  1. package/compiled/crates/swc_plugin_react_demo.wasm +0 -0
  2. package/dist/assetParsers/atom.js +15 -5
  3. package/dist/assetParsers/block.js +27 -9
  4. package/dist/cli.js +8 -1
  5. package/dist/client/pages/Demo/index.js +3 -8
  6. package/dist/client/theme-api/AtomRenderer.d.ts +2 -2
  7. package/dist/client/theme-api/AtomRenderer.js +19 -35
  8. package/dist/client/theme-api/DumiDemo.js +8 -13
  9. package/dist/client/theme-api/DumiDemoGrid.js +12 -26
  10. package/dist/client/theme-api/DumiPage.js +16 -34
  11. package/dist/client/theme-api/openCodeSandbox.js +28 -26
  12. package/dist/client/theme-api/openStackBlitz.js +15 -16
  13. package/dist/client/theme-api/types.d.ts +15 -12
  14. package/dist/client/theme-api/useAtomAssets.js +1 -2
  15. package/dist/client/theme-api/useLocale.js +10 -19
  16. package/dist/client/theme-api/useNavData.js +78 -103
  17. package/dist/client/theme-api/usePrefersColor.d.ts +2 -2
  18. package/dist/client/theme-api/usePrefersColor.js +39 -66
  19. package/dist/client/theme-api/useRouteMeta.js +9 -23
  20. package/dist/client/theme-api/useSidebarData.js +124 -158
  21. package/dist/client/theme-api/useSiteSearch/index.d.ts +1 -1
  22. package/dist/client/theme-api/useSiteSearch/index.js +24 -38
  23. package/dist/client/theme-api/useTabMeta.js +8 -19
  24. package/dist/client/theme-api/utils.d.ts +6 -0
  25. package/dist/client/theme-api/utils.js +40 -46
  26. package/dist/client/typings.d.ts +0 -5
  27. package/dist/constants.d.ts +1 -0
  28. package/dist/constants.js +3 -0
  29. package/dist/features/assets.js +23 -4
  30. package/dist/features/autoAlias.js +8 -3
  31. package/dist/features/compile/babelLoaderCustomize.js +0 -2
  32. package/dist/features/compile/index.js +22 -10
  33. package/dist/features/configPlugins/index.js +3 -4
  34. package/dist/features/configPlugins/schema.d.ts +1 -1
  35. package/dist/features/configPlugins/schema.js +20 -3
  36. package/dist/features/derivative.js +54 -11
  37. package/dist/features/exportStatic.js +11 -7
  38. package/dist/features/exports.js +8 -3
  39. package/dist/features/html2sketch.js +7 -5
  40. package/dist/features/locales.js +53 -17
  41. package/dist/features/meta.js +23 -10
  42. package/dist/features/parser.js +17 -5
  43. package/dist/features/routes.js +63 -24
  44. package/dist/features/sideEffects/docSideEffectsWebpackPlugin.js +27 -16
  45. package/dist/features/sideEffects/index.js +13 -4
  46. package/dist/features/sitemap.js +17 -5
  47. package/dist/features/tabs.js +23 -11
  48. package/dist/features/theme/index.js +152 -39
  49. package/dist/features/theme/loader.js +23 -7
  50. package/dist/index.js +10 -2
  51. package/dist/loaders/demo/index.js +3 -3
  52. package/dist/loaders/markdown/index.d.ts +1 -1
  53. package/dist/loaders/markdown/index.js +36 -24
  54. package/dist/loaders/markdown/transformer/index.d.ts +4 -2
  55. package/dist/loaders/markdown/transformer/index.js +48 -19
  56. package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +3 -1
  57. package/dist/loaders/markdown/transformer/rehypeDemo.js +125 -68
  58. package/dist/loaders/markdown/transformer/rehypeDesc.js +8 -3
  59. package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +8 -3
  60. package/dist/loaders/markdown/transformer/rehypeHighlightLine.js +8 -3
  61. package/dist/loaders/markdown/transformer/rehypeImg.js +8 -3
  62. package/dist/loaders/markdown/transformer/rehypeIsolation.js +36 -21
  63. package/dist/loaders/markdown/transformer/rehypeJsxify.js +8 -3
  64. package/dist/loaders/markdown/transformer/rehypeLink.d.ts +1 -1
  65. package/dist/loaders/markdown/transformer/rehypeLink.js +24 -9
  66. package/dist/loaders/markdown/transformer/rehypeRaw.d.ts +1 -1
  67. package/dist/loaders/markdown/transformer/rehypeRaw.js +20 -6
  68. package/dist/loaders/markdown/transformer/rehypeSlug.js +16 -3
  69. package/dist/loaders/markdown/transformer/rehypeStrip.js +8 -3
  70. package/dist/loaders/markdown/transformer/rehypeText.js +14 -5
  71. package/dist/loaders/markdown/transformer/remarkBreaks.d.ts +3 -0
  72. package/dist/loaders/markdown/transformer/remarkBreaks.js +65 -0
  73. package/dist/loaders/markdown/transformer/remarkContainer.js +28 -13
  74. package/dist/loaders/markdown/transformer/remarkEmbed.js +43 -21
  75. package/dist/loaders/markdown/transformer/remarkMeta.d.ts +3 -1
  76. package/dist/loaders/markdown/transformer/remarkMeta.js +39 -9
  77. package/dist/loaders/page/index.js +12 -4
  78. package/dist/loaders/pre-raw/index.js +0 -2
  79. package/dist/preset.js +8 -3
  80. package/dist/registerMethods.js +0 -2
  81. package/dist/service/dev.js +8 -1
  82. package/dist/service/printHelp.js +3 -1
  83. package/dist/techStacks/react.js +8 -3
  84. package/dist/types.d.ts +6 -6
  85. package/dist/utils.d.ts +1 -1
  86. package/dist/utils.js +15 -6
  87. package/package.json +12 -10
  88. package/theme-default/builtins/API/index.js +15 -36
  89. package/theme-default/builtins/Badge/index.js +0 -3
  90. package/theme-default/builtins/Container/index.js +6 -15
  91. package/theme-default/builtins/Previewer/index.js +1 -8
  92. package/theme-default/builtins/SourceCode/index.js +15 -27
  93. package/theme-default/builtins/Table/index.js +10 -25
  94. package/theme-default/builtins/Tree/index.js +13 -44
  95. package/theme-default/layouts/DocLayout/index.js +14 -27
  96. package/theme-default/locales/en-US.json +4 -0
  97. package/theme-default/locales/zh-CN.json +4 -0
  98. package/theme-default/slots/ColorSwitch/index.js +7 -22
  99. package/theme-default/slots/Content/index.js +5 -7
  100. package/theme-default/slots/Content/index.less +16 -1
  101. package/theme-default/slots/ContentFooter/index.d.ts +4 -0
  102. package/theme-default/slots/ContentFooter/index.js +93 -0
  103. package/theme-default/slots/ContentFooter/index.less +163 -0
  104. package/theme-default/slots/ContentTabs/index.d.ts +1 -1
  105. package/theme-default/slots/ContentTabs/index.js +5 -5
  106. package/theme-default/slots/Features/index.js +6 -11
  107. package/theme-default/slots/Footer/index.js +1 -4
  108. package/theme-default/slots/Header/index.js +7 -18
  109. package/theme-default/slots/HeaderExtra/index.js +0 -2
  110. package/theme-default/slots/Hero/index.js +2 -6
  111. package/theme-default/slots/HeroTitle/index.js +0 -2
  112. package/theme-default/slots/LangSwitch/index.js +23 -35
  113. package/theme-default/slots/Logo/index.js +1 -4
  114. package/theme-default/slots/Navbar/index.js +14 -29
  115. package/theme-default/slots/NavbarExtra/index.js +0 -2
  116. package/theme-default/slots/NotFound/index.js +0 -2
  117. package/theme-default/slots/PreviewerActions/index.js +13 -35
  118. package/theme-default/slots/PreviewerActionsExtra/index.js +0 -2
  119. package/theme-default/slots/RtlSwitch/index.js +6 -20
  120. package/theme-default/slots/RtlSwitch/index.less +5 -0
  121. package/theme-default/slots/SearchBar/Input.d.ts +1 -1
  122. package/theme-default/slots/SearchBar/Input.js +6 -5
  123. package/theme-default/slots/SearchBar/Mask.d.ts +1 -1
  124. package/theme-default/slots/SearchBar/Mask.js +0 -1
  125. package/theme-default/slots/SearchBar/index.js +20 -41
  126. package/theme-default/slots/SearchResult/index.d.ts +1 -1
  127. package/theme-default/slots/SearchResult/index.js +13 -36
  128. package/theme-default/slots/Sidebar/index.js +1 -4
  129. package/theme-default/slots/SocialIcon/index.d.ts +2 -2
  130. package/theme-default/slots/SocialIcon/index.js +1 -3
  131. package/theme-default/slots/Toc/index.js +12 -28
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeDemo.ts
@@ -29,6 +36,7 @@ __export(rehypeDemo_exports, {
29
36
  });
30
37
  module.exports = __toCommonJS(rehypeDemo_exports);
31
38
  var import_block = __toESM(require("../../../assetParsers/block"));
39
+ var import_tabs = require("../../../features/tabs");
32
40
  var import_utils = require("../../../utils");
33
41
  var import_path = __toESM(require("path"));
34
42
  var import_plugin_utils = require("umi/plugin-utils");
@@ -50,15 +58,24 @@ function getCodeLang(node, opts) {
50
58
  var _a, _b, _c, _d;
51
59
  let lang = "";
52
60
  if (typeof ((_a = node.properties) == null ? void 0 : _a.src) === "string") {
53
- node.properties.src = opts.resolver(import_path.default.dirname(opts.fileAbsPath), node.properties.src);
61
+ node.properties.src = opts.resolver(
62
+ import_path.default.dirname(opts.fileAbsPath),
63
+ node.properties.src
64
+ );
54
65
  lang = import_path.default.extname(node.properties.src).slice(1);
55
- } else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className) && (opts.resolve.codeBlockMode === "passive" ? / demo/.test(String((_c = node.data) == null ? void 0 : _c.meta)) : !/ pure/.test(String((_d = node.data) == null ? void 0 : _d.meta)))) {
66
+ } else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className) && (opts.resolve.codeBlockMode === "passive" ? (
67
+ // passive mode
68
+ / demo/.test(String((_c = node.data) == null ? void 0 : _c.meta))
69
+ ) : (
70
+ // active mode (default)
71
+ !/ pure/.test(String((_d = node.data) == null ? void 0 : _d.meta))
72
+ ))) {
56
73
  lang = String(node.properties.className[0]).replace("language-", "");
57
74
  }
58
75
  return lang;
59
76
  }
60
77
  function getCodeId(cwd, fileAbsPath, localId, atomId) {
61
- const prefix = atomId || (0, import_utils.getRoutePathFromFsPath)(import_path.default.relative(cwd, fileAbsPath)).replace(/\//g, "-");
78
+ const prefix = atomId || (0, import_utils.getFileIdFromFsPath)(import_path.default.relative(cwd, fileAbsPath));
62
79
  return [prefix.toLowerCase(), "demo", localId.toLowerCase()].filter(Boolean).join("-");
63
80
  }
64
81
  function tryMarkDemoNode(node, opts) {
@@ -143,7 +160,9 @@ function rehypeDemo(opts) {
143
160
  }
144
161
  });
145
162
  if (process.env.NODE_ENV === "production" && (hasOnlySign || hasSkipSign)) {
146
- import_plugin_utils.logger.warn(`The 'only' or 'skip' mark is not supported in production environment, please remove it. at ${vFile.data.frontmatter.filename}`);
163
+ import_plugin_utils.logger.warn(
164
+ `The 'only' or 'skip' mark is not supported in production environment, please remove it. at ${vFile.data.frontmatter.filename}`
165
+ );
147
166
  }
148
167
  visit(tree, "element", (node) => {
149
168
  var _a, _b, _c;
@@ -169,16 +188,36 @@ function rehypeDemo(opts) {
169
188
  let component = "";
170
189
  if (codeType === "external") {
171
190
  const chunkName = [vFile.data.frontmatter.atomId, "demos"].filter(Boolean).join("__");
172
- parseOpts.fileAbsPath = (0, import_plugin_utils.winPath)(codeNode.properties.src);
173
- let localId = ((_b = codeNode.properties) == null ? void 0 : _b.id) ?? import_path.default.parse(parseOpts.fileAbsPath.replace(/\/index\.(j|t)sx?$/, "")).name;
174
- parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, localId, vFile.data.frontmatter.atomId);
175
- component = `React.memo(React.lazy(() => import( /* webpackChunkName: "${chunkName}" */ '${(0, import_plugin_utils.winPath)(parseOpts.fileAbsPath)}?techStack=${techStack.name}')))`;
191
+ parseOpts.fileAbsPath = (0, import_plugin_utils.winPath)(
192
+ codeNode.properties.src
193
+ );
194
+ let localId = ((_b = codeNode.properties) == null ? void 0 : _b.id) ?? import_path.default.parse(
195
+ parseOpts.fileAbsPath.replace(/\/index\.(j|t)sx?$/, "")
196
+ ).name;
197
+ parseOpts.id = getCodeId(
198
+ opts.cwd,
199
+ opts.fileLocaleLessPath,
200
+ localId,
201
+ vFile.data.frontmatter.atomId
202
+ );
203
+ component = `React.memo(React.lazy(() => import( /* webpackChunkName: "${chunkName}" */ '${(0, import_plugin_utils.winPath)(
204
+ parseOpts.fileAbsPath
205
+ )}?techStack=${techStack.name}')))`;
176
206
  if (codeValue)
177
207
  codeNode.properties.title = codeValue;
178
- (_c = codeNode.properties).filename ?? (_c.filename = (0, import_plugin_utils.winPath)(import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)));
208
+ (_c = codeNode.properties).filename ?? (_c.filename = (0, import_plugin_utils.winPath)(
209
+ import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)
210
+ ));
179
211
  } else {
212
+ const tabKey = (0, import_tabs.isTabRouteFile)(opts.fileAbsPath) ? (0, import_tabs.getTabKeyFromFile)(opts.fileAbsPath) : "";
213
+ const localId = [tabKey, opts.fileLocale, String(index++)].filter(Boolean).join("-");
180
214
  parseOpts.fileAbsPath = opts.fileAbsPath.replace(".md", ".tsx");
181
- parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, String(index++), vFile.data.frontmatter.atomId);
215
+ parseOpts.id = getCodeId(
216
+ opts.cwd,
217
+ opts.fileLocaleLessPath,
218
+ localId,
219
+ vFile.data.frontmatter.atomId
220
+ );
182
221
  component = techStack.transformCode(codeValue, {
183
222
  type: "code-block",
184
223
  fileAbsPath: parseOpts.fileAbsPath
@@ -186,63 +225,81 @@ function rehypeDemo(opts) {
186
225
  }
187
226
  const propDemo = { id: parseOpts.id };
188
227
  demoIds.push(parseOpts.id);
189
- deferrers.push((0, import_block.default)(parseOpts).then(async ({ asset, sources, frontmatter }) => {
190
- var _a2, _b2, _c2;
191
- if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
192
- const startLine = (_a2 = node.position) == null ? void 0 : _a2.start.line;
193
- const suffix = startLine ? `:${startLine}` : "";
194
- 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.
195
- at ${opts.fileAbsPath}${suffix}`);
196
- }
197
- const { src, className, ...restAttrs } = codeNode.properties || {};
198
- const validAssetAttrs = [
199
- "title",
200
- "snapshot",
201
- "keywords"
202
- ];
203
- const techStackOpts = {
204
- type: codeType,
205
- mdAbsPath: opts.fileAbsPath,
206
- fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
207
- entryPointCode: parseOpts.entryPointCode
208
- };
209
- Object.keys(restAttrs).forEach((key) => {
210
- if (restAttrs[key] === "")
211
- restAttrs[key] = true;
212
- });
213
- const originalProps = Object.assign({}, frontmatter, restAttrs);
214
- validAssetAttrs.forEach((key) => {
215
- if (originalProps[key])
216
- asset[key] = originalProps[key];
217
- });
218
- if (/ inline/.test(String((_b2 = codeNode.data) == null ? void 0 : _b2.meta)) || originalProps.inline) {
219
- propDemo.inline = true;
220
- return {
221
- id: asset.id,
222
- component
223
- };
224
- }
225
- Object.assign(previewerProps, await ((_c2 = techStack.generatePreviewerProps) == null ? void 0 : _c2.call(techStack, originalProps, techStackOpts)) || originalProps);
226
- if (previewerProps.description) {
227
- const { unified } = await import("unified");
228
- const { default: remarkParse } = await import("remark-parse");
229
- const { default: remarkGfm } = await import("remark-gfm");
230
- const { default: remarkRehype } = await import("remark-rehype");
231
- const { default: rehypeStringify } = await import("rehype-stringify");
232
- const { convert } = require("html-to-text");
233
- const result = await unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeStringify, { allowDangerousHtml: true }).process(previewerProps.description);
234
- previewerProps.description = String(result.value);
235
- asset.description = convert(result.value, {
236
- wordwrap: false
237
- });
238
- }
239
- return {
240
- id: asset.id,
241
- component,
242
- asset: techStack.generateMetadata ? await techStack.generateMetadata(asset, techStackOpts) : asset,
243
- sources: techStack.generateSources ? await techStack.generateSources(sources, techStackOpts) : sources
244
- };
245
- }));
228
+ deferrers.push(
229
+ (0, import_block.default)(parseOpts).then(
230
+ async ({ asset, sources, frontmatter }) => {
231
+ var _a2, _b2, _c2;
232
+ if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
233
+ const startLine = (_a2 = node.position) == null ? void 0 : _a2.start.line;
234
+ const suffix = startLine ? `:${startLine}` : "";
235
+ import_plugin_utils.logger.warn(
236
+ `Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this.
237
+ at ${opts.fileAbsPath}${suffix}`
238
+ );
239
+ }
240
+ const { src, className, ...restAttrs } = codeNode.properties || {};
241
+ const validAssetAttrs = [
242
+ "title",
243
+ "snapshot",
244
+ "keywords"
245
+ ];
246
+ const techStackOpts = {
247
+ type: codeType,
248
+ mdAbsPath: opts.fileAbsPath,
249
+ fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
250
+ entryPointCode: parseOpts.entryPointCode
251
+ };
252
+ Object.keys(restAttrs).forEach((key) => {
253
+ if (restAttrs[key] === "")
254
+ restAttrs[key] = true;
255
+ });
256
+ const originalProps = Object.assign(
257
+ {},
258
+ frontmatter,
259
+ restAttrs
260
+ );
261
+ validAssetAttrs.forEach((key) => {
262
+ if (originalProps[key])
263
+ asset[key] = originalProps[key];
264
+ });
265
+ if (/ inline/.test(String((_b2 = codeNode.data) == null ? void 0 : _b2.meta)) || originalProps.inline) {
266
+ propDemo.inline = true;
267
+ return {
268
+ // TODO: special id for inline demo
269
+ id: asset.id,
270
+ component
271
+ };
272
+ }
273
+ Object.assign(
274
+ previewerProps,
275
+ await ((_c2 = techStack.generatePreviewerProps) == null ? void 0 : _c2.call(
276
+ techStack,
277
+ originalProps,
278
+ techStackOpts
279
+ )) || originalProps
280
+ );
281
+ if (previewerProps.description) {
282
+ const { unified } = await import("unified");
283
+ const { default: remarkParse } = await import("remark-parse");
284
+ const { default: remarkGfm } = await import("remark-gfm");
285
+ const { default: remarkRehype } = await import("remark-rehype");
286
+ const { default: rehypeStringify } = await import("rehype-stringify");
287
+ const { convert } = require("html-to-text");
288
+ const result = await unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeStringify, { allowDangerousHtml: true }).process(previewerProps.description);
289
+ previewerProps.description = String(result.value);
290
+ asset.description = convert(result.value, {
291
+ wordwrap: false
292
+ });
293
+ }
294
+ return {
295
+ id: asset.id,
296
+ component,
297
+ asset: techStack.generateMetadata ? await techStack.generateMetadata(asset, techStackOpts) : asset,
298
+ sources: techStack.generateSources ? await techStack.generateSources(sources, techStackOpts) : sources
299
+ };
300
+ }
301
+ )
302
+ );
246
303
  demosPropData.push({
247
304
  demo: propDemo,
248
305
  previewerProps
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeDesc.ts
@@ -47,5 +54,3 @@ function rehypeDesc() {
47
54
  }
48
55
  };
49
56
  }
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {});
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeEnhancedTag.ts
@@ -77,5 +84,3 @@ function rehypeEnhancedTag() {
77
84
  });
78
85
  };
79
86
  }
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {});
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeHighlightLine.ts
@@ -56,5 +63,3 @@ function rehypeHighlightLine() {
56
63
  };
57
64
  }
58
65
  var rehypeHighlightLine_default = rehypeHighlightLine;
59
- // Annotate the CommonJS export names for ESM import in node:
60
- 0 && (module.exports = {});
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeImg.ts
@@ -53,5 +60,3 @@ function rehypeImg() {
53
60
  });
54
61
  };
55
62
  }
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {});
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeIsolation.ts
@@ -39,27 +46,35 @@ function isReactComponent(node) {
39
46
  function rehypeIsolation() {
40
47
  return (tree) => {
41
48
  visit(tree, "root", (node) => {
42
- node.children = node.children.reduce((nextChildren, current) => {
43
- var _a, _b;
44
- let prevSibling = nextChildren[nextChildren.length - 1];
45
- if (isDemoNode(current)) {
46
- nextChildren.push(current);
47
- } else if (current.tagName === "p" && ((_a = current.children) == null ? void 0 : _a.length) === 1 && isReactComponent(current.children[0]) || isReactComponent(current)) {
48
- nextChildren.push(current.tagName === "p" ? (_b = current.children) == null ? void 0 : _b[0] : current);
49
- } else {
50
- if (!prevSibling || isDemoNode(prevSibling) || isReactComponent(prevSibling)) {
51
- prevSibling = {
52
- type: "element",
53
- tagName: "div",
54
- properties: { className: ["markdown"] },
55
- children: []
56
- };
57
- nextChildren.push(prevSibling);
49
+ node.children = node.children.reduce(
50
+ (nextChildren, current) => {
51
+ var _a, _b;
52
+ let prevSibling = nextChildren[nextChildren.length - 1];
53
+ if (isDemoNode(current)) {
54
+ nextChildren.push(current);
55
+ } else if (
56
+ // <p><Test></Test></p> or <Test></Test>
57
+ current.tagName === "p" && ((_a = current.children) == null ? void 0 : _a.length) === 1 && isReactComponent(current.children[0]) || isReactComponent(current)
58
+ ) {
59
+ nextChildren.push(
60
+ current.tagName === "p" ? (_b = current.children) == null ? void 0 : _b[0] : current
61
+ );
62
+ } else {
63
+ if (!prevSibling || isDemoNode(prevSibling) || isReactComponent(prevSibling)) {
64
+ prevSibling = {
65
+ type: "element",
66
+ tagName: "div",
67
+ properties: { className: ["markdown"] },
68
+ children: []
69
+ };
70
+ nextChildren.push(prevSibling);
71
+ }
72
+ prevSibling.children.push(current);
58
73
  }
59
- prevSibling.children.push(current);
60
- }
61
- return nextChildren;
62
- }, []);
74
+ return nextChildren;
75
+ },
76
+ []
77
+ );
63
78
  });
64
79
  };
65
80
  }
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeJsxify.ts
@@ -105,5 +112,3 @@ function rehypeJsxify() {
105
112
  return toJs(esTree, { handlers: jsx }).value.trim().slice(0, -1);
106
113
  };
107
114
  }
108
- // Annotate the CommonJS export names for ESM import in node:
109
- 0 && (module.exports = {});
@@ -1,6 +1,6 @@
1
1
  import type { Root } from 'hast';
2
2
  import type { Transformer } from 'unified';
3
3
  import type { IMdTransformerOptions } from '.';
4
- declare type IRehypeLinkOptions = Pick<IMdTransformerOptions, 'fileAbsPath' | 'routes'>;
4
+ type IRehypeLinkOptions = Pick<IMdTransformerOptions, 'fileAbsPath' | 'routes'>;
5
5
  export default function rehypeLink(opts: IRehypeLinkOptions): Transformer<Root>;
6
6
  export {};
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeLink.ts
@@ -38,7 +45,9 @@ function rehypeLink(opts) {
38
45
  return (tree) => {
39
46
  visit(tree, "element", (node, i, parent) => {
40
47
  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)) {
48
+ if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string" && // skip target specified link
49
+ !((_b = node.properties) == null ? void 0 : _b.target) && // skip download link
50
+ !((_c = node.properties) == null ? void 0 : _c.download)) {
42
51
  const href = node.properties.href;
43
52
  const parsedUrl = import_url.default.parse(href);
44
53
  const hostAbsPath = (0, import_tabs.getHostForTabRouteFile)(opts.fileAbsPath);
@@ -46,7 +55,9 @@ function rehypeLink(opts) {
46
55
  return SKIP;
47
56
  if (/\.md$/i.test(parsedUrl.pathname)) {
48
57
  const { routes } = opts;
49
- const absPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(hostAbsPath, "..", parsedUrl.pathname));
58
+ const absPath = (0, import_plugin_utils.winPath)(
59
+ import_path.default.resolve(hostAbsPath, "..", parsedUrl.pathname)
60
+ );
50
61
  Object.keys(routes).forEach((key) => {
51
62
  if (routes[key].file === absPath) {
52
63
  parsedUrl.pathname = routes[key].absPath;
@@ -54,14 +65,20 @@ function rehypeLink(opts) {
54
65
  });
55
66
  } else if (parsedUrl.pathname && /^[^/]+/.test(parsedUrl.pathname)) {
56
67
  const routes = Object.values(opts.routes);
57
- const basePath = routes.find((route) => route.file === hostAbsPath).absPath;
68
+ const basePath = routes.find(
69
+ (route) => route.file === hostAbsPath
70
+ ).absPath;
58
71
  const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
59
- const rr6TargetPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(basePath, parsedUrl.pathname));
72
+ const rr6TargetPath = (0, import_plugin_utils.winPath)(
73
+ import_path.default.resolve(basePath, parsedUrl.pathname)
74
+ );
60
75
  parsedUrl.pathname = htmlTargetPath;
61
76
  if (routes.every((route) => route.absPath !== htmlTargetPath) && routes.some((route) => route.absPath === rr6TargetPath)) {
62
77
  parsedUrl.pathname = rr6TargetPath;
63
- import_plugin_utils.logger.warn(`Detected ambiguous link \`${href}\` in \`${opts.fileAbsPath}\`, please use \`./xxx.md\` file path instead of normal relative path, dumi will deprecate this behavior in the future.
64
- See more: https://github.com/umijs/dumi/pull/1491`);
78
+ import_plugin_utils.logger.warn(
79
+ `Detected ambiguous link \`${href}\` in \`${opts.fileAbsPath}\`, please use \`./xxx.md\` file path instead of normal relative path, dumi will deprecate this behavior in the future.
80
+ See more: https://github.com/umijs/dumi/pull/1491`
81
+ );
65
82
  }
66
83
  }
67
84
  parent.children.splice(i, 1, {
@@ -77,5 +94,3 @@ function rehypeLink(opts) {
77
94
  });
78
95
  };
79
96
  }
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {});
@@ -1,6 +1,6 @@
1
1
  import type { Root } from 'hast';
2
2
  import type { Transformer } from 'unified';
3
3
  import type { IMdTransformerOptions } from '.';
4
- declare type IRehypeRawOptions = Pick<IMdTransformerOptions, 'fileAbsPath'>;
4
+ type IRehypeRawOptions = Pick<IMdTransformerOptions, 'fileAbsPath'>;
5
5
  export default function rehypeRaw(opts: IRehypeRawOptions): Transformer<Root>;
6
6
  export {};
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeRaw.ts
@@ -32,7 +39,10 @@ var COMPONENT_NAME_REGEX = /<[A-Z][a-zA-Z\d]*/g;
32
39
  var COMPONENT_PROP_REGEX = /\s[a-z][a-z\d]*[A-Z]+[a-zA-Z\d]*(=|\s|>)/g;
33
40
  var COMPONENT_STUB_ATTR = "$tag-name";
34
41
  var PROP_STUB_ATTR = "-$u";
35
- var PROP_STUB_ATTR_REGEX = new RegExp(`${PROP_STUB_ATTR.replace("$", "\\$")}[a-z]`, "g");
42
+ var PROP_STUB_ATTR_REGEX = new RegExp(
43
+ `${PROP_STUB_ATTR.replace("$", "\\$")}[a-z]`,
44
+ "g"
45
+ );
36
46
  var CODE_META_STUB_ATTR = "$code-meta";
37
47
  (async () => {
38
48
  ({ visit } = await import("unist-util-visit"));
@@ -48,7 +58,10 @@ function rehypeRaw(opts) {
48
58
  return `${str} ${COMPONENT_STUB_ATTR}="${tagName}"`;
49
59
  });
50
60
  node.value = node.value.replace(COMPONENT_PROP_REGEX, (str) => {
51
- return str.replace(/[A-Z]/g, (s) => `${PROP_STUB_ATTR}${s.toLowerCase()}`);
61
+ return str.replace(
62
+ /[A-Z]/g,
63
+ (s) => `${PROP_STUB_ATTR}${s.toLowerCase()}`
64
+ );
52
65
  });
53
66
  } else if (node.type === "element" && ((_a = node.data) == null ? void 0 : _a.meta)) {
54
67
  node.properties ?? (node.properties = {});
@@ -71,7 +84,10 @@ File: ${opts.fileAbsPath}`);
71
84
  }
72
85
  Object.keys(node.properties || {}).forEach((p) => {
73
86
  if (PROP_STUB_ATTR_REGEX.test(p)) {
74
- const originalName = p.replace(PROP_STUB_ATTR_REGEX, (s) => s.slice(PROP_STUB_ATTR.length).toUpperCase());
87
+ const originalName = p.replace(
88
+ PROP_STUB_ATTR_REGEX,
89
+ (s) => s.slice(PROP_STUB_ATTR.length).toUpperCase()
90
+ );
75
91
  node.properties[originalName] = node.properties[p];
76
92
  node.properties[originalName.toLowerCase()] = node.properties[p];
77
93
  delete node.properties[p];
@@ -81,5 +97,3 @@ File: ${opts.fileAbsPath}`);
81
97
  return newTree;
82
98
  };
83
99
  }
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {});
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
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));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
20
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
28
 
22
29
  // src/loaders/markdown/transformer/rehypeSlug.ts
@@ -45,14 +52,19 @@ function rehypeSlug() {
45
52
  const title = toString({
46
53
  type: "element",
47
54
  tagName: node.tagName,
48
- children: node.children.filter((child) => child.type !== "element" || child.tagName !== "Badge")
55
+ // discard text within Badge tag
56
+ children: node.children.filter(
57
+ (child) => child.type !== "element" || child.tagName !== "Badge"
58
+ )
49
59
  }).trim();
50
60
  const depth = Number(node.tagName.slice(1));
51
61
  const id = slugger.slug(title);
52
62
  node.properties.id = id;
53
63
  vFile.data.toc.push({ id, depth, title });
54
64
  } else if ([import_rehypeDemo.DUMI_DEMO_TAG, import_rehypeDemo.DUMI_DEMO_GRID_TAG].includes(node.tagName) && ((_a = node.data) == null ? void 0 : _a[import_rehypeDemo.DEMO_PROP_VALUE_KEY])) {
55
- const demos = [].concat((_b = node.data) == null ? void 0 : _b[import_rehypeDemo.DEMO_PROP_VALUE_KEY]);
65
+ const demos = [].concat(
66
+ (_b = node.data) == null ? void 0 : _b[import_rehypeDemo.DEMO_PROP_VALUE_KEY]
67
+ );
56
68
  demos.forEach(({ demo, previewerProps }) => {
57
69
  var _a2, _b2;
58
70
  if (!demo.inline && previewerProps.title) {
@@ -60,6 +72,7 @@ function rehypeSlug() {
60
72
  id: slugger.slug(demo.id),
61
73
  depth: ((_b2 = (_a2 = vFile.data.frontmatter) == null ? void 0 : _a2.demo) == null ? void 0 : _b2.tocDepth) || 3,
62
74
  title: previewerProps.title,
75
+ // put debug flag to control hide/show in toc
63
76
  ...previewerProps.debug ? { _debug_demo: true } : {}
64
77
  });
65
78
  }