dumi 2.0.0-beta.14 → 2.0.0-beta.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/block.d.ts +2 -0
  2. package/dist/assetParsers/block.js +4 -1
  3. package/dist/client/theme-api/types.d.ts +6 -5
  4. package/dist/constants.d.ts +1 -0
  5. package/dist/constants.js +15 -0
  6. package/dist/features/assets.d.ts +5 -1
  7. package/dist/features/assets.js +7 -1
  8. package/dist/features/autoAlias.d.ts +3 -0
  9. package/dist/features/autoAlias.js +65 -0
  10. package/dist/features/compile.js +3 -6
  11. package/dist/features/derivative.d.ts +5 -0
  12. package/dist/features/derivative.js +35 -2
  13. package/dist/features/exports.d.ts +0 -5
  14. package/dist/features/exports.js +3 -24
  15. package/dist/features/theme/index.js +2 -2
  16. package/dist/loaders/markdown/index.d.ts +1 -0
  17. package/dist/loaders/markdown/index.js +10 -9
  18. package/dist/loaders/markdown/transformer/index.d.ts +1 -1
  19. package/dist/loaders/markdown/transformer/index.js +6 -2
  20. package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -1
  21. package/dist/loaders/markdown/transformer/rehypeDemo.js +4 -3
  22. package/dist/loaders/markdown/transformer/rehypeImg.js +1 -1
  23. package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -3
  24. package/dist/loaders/markdown/transformer/remarkMeta.js +18 -2
  25. package/dist/preset.js +1 -0
  26. package/dist/techStacks/react.js +1 -0
  27. package/dist/types.d.ts +1 -0
  28. package/dist/utils.d.ts +4 -0
  29. package/dist/utils.js +26 -2
  30. package/package.json +1 -1
  31. package/theme-default/builtins/Previewer/index.js +4 -122
  32. package/theme-default/builtins/Previewer/index.less +0 -165
  33. package/theme-default/slots/Hero/index.js +8 -8
  34. package/theme-default/slots/Hero/index.less +1 -1
  35. package/theme-default/slots/PreviewerActions/index.d.ts +11 -0
  36. package/theme-default/slots/PreviewerActions/index.js +128 -0
  37. package/theme-default/slots/PreviewerActions/index.less +168 -0
  38. package/theme-default/slots/PreviewerActionsExtra/index.d.ts +4 -0
  39. package/theme-default/slots/PreviewerActionsExtra/index.js +7 -0
@@ -1,5 +1,6 @@
1
1
  import { parseCodeFrontmatter } from "../utils";
2
2
  import type { ExampleBlockAsset } from 'dumi-assets-types';
3
+ import type { sync } from 'enhanced-resolve';
3
4
  export interface IParsedBlockAsset {
4
5
  asset: ExampleBlockAsset;
5
6
  sources: Record<string, string>;
@@ -10,5 +11,6 @@ declare function parseBlockAsset(opts: {
10
11
  id: string;
11
12
  refAtomIds: string[];
12
13
  entryPointCode?: string;
14
+ resolver: typeof sync;
13
15
  }): Promise<IParsedBlockAsset>;
14
16
  export default parseBlockAsset;
@@ -27,6 +27,7 @@ __export(block_exports, {
27
27
  module.exports = __toCommonJS(block_exports);
28
28
  var import_utils = require("../utils");
29
29
  var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
30
+ var import_assert = __toESM(require("assert"));
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");
@@ -56,8 +57,10 @@ async function parseBlockAsset(opts) {
56
57
  setup: (builder) => {
57
58
  builder.onResolve({ filter: /.*/ }, (args) => {
58
59
  if (args.kind !== "entry-point" && !args.path.startsWith(".")) {
60
+ const resolved = opts.resolver(args.resolveDir, args.path);
61
+ (0, import_assert.default)(resolved, `Can't resolve ${args.path} from ${args.resolveDir}`);
59
62
  const pkgJsonPath = import_plugin_utils.pkgUp.pkgUpSync({
60
- cwd: require.resolve(args.path, { paths: [args.resolveDir] })
63
+ cwd: resolved
61
64
  });
62
65
  if (pkgJsonPath) {
63
66
  asset.dependencies[args.path] = {
@@ -61,8 +61,8 @@ export interface IRouteMeta {
61
61
  title?: string;
62
62
  description?: string;
63
63
  background?: string;
64
- links?: {
65
- title: string;
64
+ actions?: {
65
+ text: string;
66
66
  link: string;
67
67
  }[];
68
68
  [key: string]: any;
@@ -78,6 +78,8 @@ export interface IRouteMeta {
78
78
  cols?: number;
79
79
  tocDepth?: number;
80
80
  };
81
+ atomId?: string;
82
+ [key: string]: any;
81
83
  };
82
84
  toc: {
83
85
  id: string;
@@ -110,17 +112,16 @@ export interface IRouteMeta {
110
112
  [key: string]: any;
111
113
  };
112
114
  }[];
113
- [key: string]: any;
114
115
  }
115
116
  declare type IBasicLocale = {
116
117
  id: string;
117
118
  name: string;
118
119
  };
119
- export declare type ILocale = ((IBasicLocale & {
120
+ export declare type ILocale = (IBasicLocale & {
120
121
  base: string;
121
122
  }) | (IBasicLocale & {
122
123
  suffix: string;
123
- }));
124
+ });
124
125
  export declare type ILocalesConfig = ILocale[];
125
126
  export interface INavItem {
126
127
  title: string;
@@ -11,3 +11,4 @@ export declare const PICKED_PKG_FIELDS: {
11
11
  author: string;
12
12
  authors: string;
13
13
  };
14
+ export declare const CLIENT_DEPS: string[];
package/dist/constants.js CHANGED
@@ -19,6 +19,7 @@ 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,
22
23
  LOCAL_DUMI_DIR: () => LOCAL_DUMI_DIR,
23
24
  LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
24
25
  PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
@@ -39,8 +40,22 @@ var PICKED_PKG_FIELDS = {
39
40
  author: "",
40
41
  authors: ""
41
42
  };
43
+ var CLIENT_DEPS = [
44
+ "@ant-design/icons-svg",
45
+ "@makotot/ghostui",
46
+ "deepmerge",
47
+ "highlight-words-core",
48
+ "lodash.throttle",
49
+ "prism-react-renderer",
50
+ "prismjs",
51
+ "rc-tabs",
52
+ "react-copy-to-clipboard",
53
+ "react-helmet",
54
+ "react-intl"
55
+ ];
42
56
  // Annotate the CommonJS export names for ESM import in node:
43
57
  0 && (module.exports = {
58
+ CLIENT_DEPS,
44
59
  LOCAL_DUMI_DIR,
45
60
  LOCAL_THEME_DIR,
46
61
  PICKED_PKG_FIELDS,
@@ -1,10 +1,14 @@
1
1
  import type { IApi } from "../types";
2
- import type { ExampleAsset } from 'dumi-assets-types';
2
+ import type { AtomAsset, ExampleAsset } from 'dumi-assets-types';
3
3
  declare const examples: ExampleAsset[];
4
4
  /**
5
5
  * internal function to add example assets
6
6
  */
7
7
  export declare function addExampleAssets(data: typeof examples): void;
8
+ /**
9
+ * internal function to add meta for atom
10
+ */
11
+ export declare function addAtomMeta(atomId: string, data: Partial<AtomAsset>): void;
8
12
  /**
9
13
  * plugin for generate assets.json
10
14
  */
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/assets.ts
23
23
  var assets_exports = {};
24
24
  __export(assets_exports, {
25
+ addAtomMeta: () => addAtomMeta,
25
26
  addExampleAssets: () => addExampleAssets,
26
27
  default: () => assets_default
27
28
  });
@@ -30,9 +31,13 @@ var import_fs = __toESM(require("fs"));
30
31
  var import_path = __toESM(require("path"));
31
32
  var import_plugin_utils = require("umi/plugin-utils");
32
33
  var examples = [];
34
+ var atomsMeta = {};
33
35
  function addExampleAssets(data) {
34
36
  examples.push(...data);
35
37
  }
38
+ function addAtomMeta(atomId, data) {
39
+ atomsMeta[atomId] = import_plugin_utils.lodash.pick(data, ["title", "keywords", "deprecated"]);
40
+ }
36
41
  var assets_default = (api) => {
37
42
  api.describe({
38
43
  config: {
@@ -53,7 +58,7 @@ var assets_default = (api) => {
53
58
  homepage: api.pkg.homepage,
54
59
  repository: api.pkg.repository,
55
60
  assets: {
56
- atoms: Object.values(components),
61
+ atoms: Object.values(components).map((atom) => Object.assign(atom, atomsMeta[atom.id] || {})),
57
62
  examples: import_plugin_utils.lodash.uniqBy(examples, "id")
58
63
  }
59
64
  }
@@ -63,5 +68,6 @@ var assets_default = (api) => {
63
68
  };
64
69
  // Annotate the CommonJS export names for ESM import in node:
65
70
  0 && (module.exports = {
71
+ addAtomMeta,
66
72
  addExampleAssets
67
73
  });
@@ -0,0 +1,3 @@
1
+ import type { IApi } from "../types";
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,65 @@
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/autoAlias.ts
23
+ var autoAlias_exports = {};
24
+ __export(autoAlias_exports, {
25
+ default: () => autoAlias_default
26
+ });
27
+ module.exports = __toCommonJS(autoAlias_exports);
28
+ var import_utils = require("../utils");
29
+ var import_fs = __toESM(require("fs"));
30
+ var import_path = __toESM(require("path"));
31
+ var autoAlias_default = (api) => {
32
+ api.describe({
33
+ key: "autoAlias",
34
+ config: {
35
+ schema: (Joi) => Joi.bool()
36
+ },
37
+ enableBy: ({ userConfig }) => userConfig.autoAlias !== false
38
+ });
39
+ api.modifyDefaultConfig(async (memo) => {
40
+ var _a;
41
+ let entryDir = "";
42
+ if ((_a = api.userConfig.resolve) == null ? void 0 : _a.entryFile) {
43
+ entryDir = import_path.default.resolve(api.cwd, api.userConfig.resolve.entryFile);
44
+ } else if (import_fs.default.existsSync(import_path.default.join(api.cwd, "src"))) {
45
+ entryDir = import_path.default.join(api.cwd, "src");
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, _b;
51
+ const aLevel = (((_a2 = a.output) == null ? void 0 : _a2.path) || a.output).split("/").length;
52
+ const bLevel = (((_b = b.output) == null ? void 0 : _b.path) || b.output).split("/").length;
53
+ return bLevel - aLevel;
54
+ });
55
+ fatherConfigs.forEach((item) => {
56
+ var _a2;
57
+ memo.alias[`${api.pkg.name}/${((_a2 = item.output) == null ? void 0 : _a2.path) || item.output}`] = import_path.default.join(api.cwd, item.entry || item.input);
58
+ });
59
+ memo.alias[api.pkg.name] = entryDir;
60
+ }
61
+ return memo;
62
+ });
63
+ };
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {});
@@ -33,10 +33,6 @@ var compile_default = (api) => {
33
33
  stage: Infinity,
34
34
  fn: () => new import_react.default()
35
35
  });
36
- api.modifyDefaultConfig((memo) => {
37
- memo.alias.dumi$ = memo.alias.umi;
38
- return memo;
39
- });
40
36
  api.chainWebpack(async (memo) => {
41
37
  const babelInUmi = memo.module.rule("src").use("babel-loader").entries();
42
38
  const techStacks = await api.applyPlugins({
@@ -48,7 +44,7 @@ var compile_default = (api) => {
48
44
  techStacks,
49
45
  cwd: api.cwd,
50
46
  alias: api.config.alias,
51
- codeBlockMode: api.config.resolve.codeBlockMode,
47
+ resolve: api.config.resolve,
52
48
  extraRemarkPlugins: api.config.extraRemarkPlugins,
53
49
  extraRehypePlugins: api.config.extraRehypePlugins
54
50
  };
@@ -62,7 +58,8 @@ var compile_default = (api) => {
62
58
  return ret;
63
59
  }, []);
64
60
  (0, import_assets.addExampleAssets)(assets);
65
- }
61
+ },
62
+ onResolveAtomMeta: import_assets.addAtomMeta
66
63
  }).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
67
64
  ...loaderBaseOpts,
68
65
  builtins: api.service.themeData.builtins
@@ -1,4 +1,9 @@
1
1
  import type { IApi } from "../types";
2
+ /**
3
+ * exclude pre-compiling modules in mfsu mode
4
+ * and make sure there has no multiple instances problem (such as react)
5
+ */
6
+ export declare function safeExcludeInMFSU(api: IApi, excludes: RegExp[]): void;
2
7
  /**
3
8
  * plugin for derive default behaviors from umi
4
9
  */
@@ -22,12 +22,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/derivative.ts
23
23
  var derivative_exports = {};
24
24
  __export(derivative_exports, {
25
- default: () => derivative_default
25
+ default: () => derivative_default,
26
+ safeExcludeInMFSU: () => safeExcludeInMFSU
26
27
  });
27
28
  module.exports = __toCommonJS(derivative_exports);
28
29
  var import_constants = require("../constants");
30
+ var import_fs = __toESM(require("fs"));
29
31
  var import_path = __toESM(require("path"));
30
32
  var import_plugin_utils = require("umi/plugin-utils");
33
+ function safeExcludeInMFSU(api, excludes) {
34
+ if (api.userConfig.mfsu !== false) {
35
+ api.modifyDefaultConfig((memo) => {
36
+ if (memo.mfsu === false)
37
+ return memo;
38
+ memo.mfsu ?? (memo.mfsu = {});
39
+ memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
40
+ memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
41
+ memo.extraBabelIncludes.push(...excludes);
42
+ return memo;
43
+ });
44
+ }
45
+ }
31
46
  function getFilesByGlob(globExp, dir) {
32
47
  return import_plugin_utils.glob.sync(globExp, { cwd: dir }).map((file) => (0, import_plugin_utils.winPath)(import_path.default.join(dir, file)));
33
48
  }
@@ -40,6 +55,22 @@ var derivative_default = (api) => {
40
55
  overridesCSS: getFilesByGlob.bind(null, "overrides.{css,less,scss,sass}", dumiAbsDir)
41
56
  };
42
57
  api.describe({ key: "dumi:derivative" });
58
+ safeExcludeInMFSU(api, [new RegExp("dumi/dist/client")]);
59
+ api.modifyDefaultConfig((memo) => {
60
+ if (api.userConfig.mfsu !== false) {
61
+ if (import_fs.default.existsSync(import_path.default.join(api.cwd, "node_modules", ".pnpm"))) {
62
+ memo.mfsu = false;
63
+ } else {
64
+ memo.mfsu.strategy = "normal";
65
+ import_constants.CLIENT_DEPS.forEach((pkg) => {
66
+ memo.alias ?? (memo.alias = {});
67
+ memo.alias[pkg] = (0, import_plugin_utils.winPath)(import_path.default.dirname(require.resolve(`${pkg}/package.json`)));
68
+ });
69
+ }
70
+ }
71
+ memo.hash = true;
72
+ return memo;
73
+ });
43
74
  api.modifyAppData((memo) => {
44
75
  Object.entries(strategies).forEach(([key, fn]) => {
45
76
  memo[key] = fn();
@@ -56,4 +87,6 @@ var derivative_default = (api) => {
56
87
  });
57
88
  };
58
89
  // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {});
90
+ 0 && (module.exports = {
91
+ safeExcludeInMFSU
92
+ });
@@ -1,8 +1,3 @@
1
1
  import type { IApi } from "../types";
2
- /**
3
- * exclude pre-compiling modules in mfsu mode
4
- * and make sure there has no multiple instances problem (such as react)
5
- */
6
- export declare function safeExcludeInMFSU(api: IApi, excludes: RegExp[]): void;
7
2
  declare const _default: (api: IApi) => void;
8
3
  export default _default;
@@ -22,31 +22,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/exports.ts
23
23
  var exports_exports = {};
24
24
  __export(exports_exports, {
25
- default: () => exports_default,
26
- safeExcludeInMFSU: () => safeExcludeInMFSU
25
+ default: () => exports_default
27
26
  });
28
27
  module.exports = __toCommonJS(exports_exports);
29
28
  var import_plugin_utils = require("umi/plugin-utils");
30
- function safeExcludeInMFSU(api, excludes) {
31
- if (api.userConfig.mfsu !== false) {
32
- api.modifyDefaultConfig((memo) => {
33
- memo.mfsu ?? (memo.mfsu = {});
34
- memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
35
- memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
36
- memo.extraBabelIncludes.push(...excludes);
37
- return memo;
38
- });
39
- }
40
- }
41
29
  var exports_default = (api) => {
42
- api.describe({ key: void 0 });
43
- safeExcludeInMFSU(api, [new RegExp("dumi/dist/client")]);
44
- api.modifyDefaultConfig((memo) => {
45
- if (api.userConfig.mfsu !== false) {
46
- memo.mfsu = { strategy: "normal" };
47
- }
48
- return memo;
49
- });
30
+ api.describe({ key: "dumi:exports" });
50
31
  api.modifyConfig((memo) => {
51
32
  memo.alias["dumi$"] = "@@/dumi/exports";
52
33
  return memo;
@@ -61,6 +42,4 @@ export * from '${(0, import_plugin_utils.winPath)(require.resolve("../client/the
61
42
  });
62
43
  };
63
44
  // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- safeExcludeInMFSU
66
- });
45
+ 0 && (module.exports = {});
@@ -29,7 +29,7 @@ var import_constants = require("../../constants");
29
29
  var import_fs = __toESM(require("fs"));
30
30
  var import_path = __toESM(require("path"));
31
31
  var import_plugin_utils = require("umi/plugin-utils");
32
- var import_exports = require("../exports");
32
+ var import_derivative = require("../derivative");
33
33
  var import_loader = __toESM(require("./loader"));
34
34
  var DEFAULT_THEME_PATH = import_path.default.join(__dirname, "../../../theme-default");
35
35
  function getPkgThemeName(api) {
@@ -59,7 +59,7 @@ var theme_default = (api) => {
59
59
  api.registerPlugins([plugin]);
60
60
  }
61
61
  });
62
- (0, import_exports.safeExcludeInMFSU)(api, ["dumi/theme-default", "@ant-design/icons-svg", getPkgThemeName(api)].filter(Boolean).map((pkg) => new RegExp(pkg)));
62
+ (0, import_derivative.safeExcludeInMFSU)(api, ["dumi/theme-default", "@ant-design/icons-svg", getPkgThemeName(api)].filter(Boolean).map((pkg) => new RegExp(pkg)));
63
63
  api.register({
64
64
  key: "modifyAppData",
65
65
  before: "appData",
@@ -7,6 +7,7 @@ interface IMdLoaderDefaultModeOptions extends Omit<IMdTransformerOptions, 'fileA
7
7
  interface IMdLoaderDemosModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'builtins' | 'mode'> {
8
8
  mode: 'meta';
9
9
  onResolveDemos?: (demos: NonNullable<IMdTransformerResult['meta']['demos']>) => void;
10
+ onResolveAtomMeta?: (atomId: string, meta: IMdTransformerResult['meta']['frontmatter']) => void;
10
11
  }
11
12
  export declare type IMdLoaderOptions = IMdLoaderDefaultModeOptions | IMdLoaderDemosModeOptions;
12
13
  export default function mdLoader(this: any, content: string): void;
@@ -38,6 +38,9 @@ function emit(opts, ret) {
38
38
  if (demos && opts.onResolveDemos) {
39
39
  opts.onResolveDemos(demos);
40
40
  }
41
+ if (frontmatter.atomId && opts.onResolveAtomMeta) {
42
+ opts.onResolveAtomMeta(frontmatter.atomId, frontmatter);
43
+ }
41
44
  return import_plugin_utils.Mustache.render(`import React from 'react';
42
45
 
43
46
  export const demos = {
@@ -104,16 +107,14 @@ function mdLoader(content) {
104
107
  });
105
108
  return;
106
109
  }
107
- deferrer[cacheKey] = new Promise((resolve) => {
108
- (0, import_transformer.default)(content, {
109
- ...import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
110
- fileAbsPath: this.resourcePath
111
- }).then((ret) => {
112
- cache.setSync(cacheKey, ret);
113
- resolve(ret);
114
- cb(null, emit.call(this, opts, ret));
115
- }, cb);
110
+ deferrer[cacheKey] = (0, import_transformer.default)(content, {
111
+ ...import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
112
+ fileAbsPath: this.resourcePath
116
113
  });
114
+ deferrer[cacheKey].then((ret) => {
115
+ cache.setSync(cacheKey, ret);
116
+ cb(null, emit.call(this, opts, ret));
117
+ }).catch(cb);
117
118
  }
118
119
  // Annotate the CommonJS export names for ESM import in node:
119
120
  0 && (module.exports = {});
@@ -37,7 +37,7 @@ export interface IMdTransformerOptions {
37
37
  alias: object;
38
38
  parentAbsPath?: string;
39
39
  techStacks: IDumiTechStack[];
40
- codeBlockMode: IDumiConfig['resolve']['codeBlockMode'];
40
+ resolve: IDumiConfig['resolve'];
41
41
  extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
42
42
  extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
43
43
  }
@@ -57,7 +57,11 @@ var transformer_default = async (raw, opts) => {
57
57
  extensions: [".js", ".jsx", ".ts", ".tsx"],
58
58
  alias: opts.alias
59
59
  });
60
- const processor = unified().use(remarkParse).use(import_remarkEmbed.default, { fileAbsPath: opts.fileAbsPath, alias: opts.alias }).use(remarkFrontmatter).use(import_remarkMeta.default, { fileAbsPath: opts.fileAbsPath }).use(remarkBreaks).use(remarkGfm);
60
+ const processor = unified().use(remarkParse).use(import_remarkEmbed.default, { fileAbsPath: opts.fileAbsPath, alias: opts.alias }).use(remarkFrontmatter).use(import_remarkMeta.default, {
61
+ cwd: opts.cwd,
62
+ fileAbsPath: opts.fileAbsPath,
63
+ resolve: opts.resolve
64
+ }).use(remarkBreaks).use(remarkGfm);
61
65
  (_a = opts.extraRemarkPlugins) == null ? void 0 : _a.forEach((plugin) => applyUnifiedPlugin({
62
66
  plugin,
63
67
  processor,
@@ -67,7 +71,7 @@ var transformer_default = async (raw, opts) => {
67
71
  techStacks: opts.techStacks,
68
72
  cwd: opts.cwd,
69
73
  fileAbsPath: opts.fileAbsPath,
70
- codeBlockMode: opts.codeBlockMode,
74
+ resolve: opts.resolve,
71
75
  resolver
72
76
  }).use(import_rehypeSlug.default).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default).use(import_rehypeEnhancedTag.default).use(import_rehypeText.default);
73
77
  (_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
@@ -5,7 +5,7 @@ import type { IMdTransformerOptions } from '.';
5
5
  export declare const DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
6
6
  export declare const DUMI_DEMO_TAG = "DumiDemo";
7
7
  export declare const DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
8
- declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'codeBlockMode'> & {
8
+ declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'resolve'> & {
9
9
  resolver: typeof sync;
10
10
  };
11
11
  export default function rehypeDemo(opts: IRehypeDemoOptions): Transformer<Root>;
@@ -51,7 +51,7 @@ function getCodeLang(node, opts) {
51
51
  if (typeof ((_a = node.properties) == null ? void 0 : _a.src) === "string") {
52
52
  node.properties.src = opts.resolver(import_path.default.dirname(opts.fileAbsPath), node.properties.src);
53
53
  lang = import_path.default.extname(node.properties.src).slice(1);
54
- } else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className) && (opts.codeBlockMode === "passive" ? / demo/.test(String((_c = node.data) == null ? void 0 : _c.meta)) : !/ pure/.test(String((_d = node.data) == null ? void 0 : _d.meta)))) {
54
+ } 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)))) {
55
55
  lang = String(node.properties.className[0]).replace("language-", "");
56
56
  }
57
57
  return lang;
@@ -131,9 +131,10 @@ function rehypeDemo(opts) {
131
131
  const codeValue = toString(codeNode).trim();
132
132
  const parseOpts = {
133
133
  id: "",
134
- refAtomIds: [],
134
+ refAtomIds: vFile.data.frontmatter.atomId ? [vFile.data.frontmatter.atomId] : [],
135
135
  fileAbsPath: "",
136
- entryPointCode: codeType === "external" ? void 0 : codeValue
136
+ entryPointCode: codeType === "external" ? void 0 : codeValue,
137
+ resolver: opts.resolver
137
138
  };
138
139
  const previewerProps = {};
139
140
  let component = "";
@@ -39,7 +39,7 @@ function rehypeImg() {
39
39
  var _a;
40
40
  if (node.tagName === "img" && typeof ((_a = node.properties) == null ? void 0 : _a.src) === "string") {
41
41
  const src = node.properties.src.trim();
42
- if (isRelativeUrl(src)) {
42
+ if (src && isRelativeUrl(src)) {
43
43
  delete node.properties.src;
44
44
  node.JSXAttributes = [
45
45
  {
@@ -1,5 +1,6 @@
1
1
  import type { Root } from 'mdast';
2
2
  import type { Transformer } from 'unified';
3
- export default function remarkMeta(opts: {
4
- fileAbsPath: string;
5
- }): Transformer<Root>;
3
+ import type { IMdTransformerOptions } from '.';
4
+ declare type IRemarkMetaOpts = Pick<IMdTransformerOptions, 'cwd' | 'fileAbsPath' | 'resolve'>;
5
+ export default function remarkMeta(opts: IRemarkMetaOpts): Transformer<Root>;
6
+ export {};
@@ -26,6 +26,7 @@ __export(remarkMeta_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(remarkMeta_exports);
28
28
  var import_tabs = require("../../../features/tabs");
29
+ var import_fs = __toESM(require("fs"));
29
30
  var import_js_yaml = __toESM(require("js-yaml"));
30
31
  var import_path = __toESM(require("path"));
31
32
  var import_plugin_utils = require("umi/plugin-utils");
@@ -35,12 +36,27 @@ var toString;
35
36
  ({ visit } = await import("unist-util-visit"));
36
37
  ({ toString } = await import("mdast-util-to-string"));
37
38
  })();
39
+ function getGuessAtomId(opts) {
40
+ const parsed = import_path.default.parse(opts.fileAbsPath);
41
+ const clearFileName = parsed.name.replace(/(?:\.$tab-[^.]+)?(?:\.[^.]+)?(\.[^.]+)$/, "$1");
42
+ const atomFile = [".tsx", ".jsx"].map((ext) => import_path.default.join(parsed.dir, `${clearFileName}${ext}`)).find(import_fs.default.existsSync);
43
+ if (atomFile) {
44
+ const atomAbsDir = opts.resolve.atomDirs.map(({ dir }) => import_path.default.resolve(opts.cwd, dir)).sort((a, b) => b.split("/").length - a.split("/").length).find((dir) => atomFile.startsWith(dir));
45
+ if (atomAbsDir) {
46
+ return import_path.default.relative(atomAbsDir, atomFile).replace(/((^|\/)index)?\.\w+$/, "");
47
+ }
48
+ }
49
+ }
38
50
  function remarkMeta(opts) {
39
51
  return (tree, vFile) => {
40
- vFile.data.frontmatter = { title: "" };
52
+ const guessAtomId = getGuessAtomId(opts);
53
+ vFile.data.frontmatter = {
54
+ title: "",
55
+ ...guessAtomId && { atomId: guessAtomId }
56
+ };
41
57
  visit(tree, "yaml", (node) => {
42
58
  try {
43
- vFile.data.frontmatter = import_js_yaml.default.load(node.value);
59
+ Object.assign(vFile.data.frontmatter, import_js_yaml.default.load(node.value));
44
60
  } catch {
45
61
  }
46
62
  });
package/dist/preset.js CHANGED
@@ -44,6 +44,7 @@ var preset_default = (api) => {
44
44
  plugins: [
45
45
  require.resolve("./registerMethods"),
46
46
  require.resolve("./features/configPlugins"),
47
+ require.resolve("./features/autoAlias"),
47
48
  require.resolve("./features/derivative"),
48
49
  require.resolve("./features/sideEffects"),
49
50
  require.resolve("./features/exports"),
@@ -54,6 +54,7 @@ var ReactTechStack = class {
54
54
  if (opts.type === "code-block") {
55
55
  const isTSX = opts.fileAbsPath.endsWith(".tsx");
56
56
  const { code } = (0, import_core.transformSync)(raw, {
57
+ filename: opts.fileAbsPath,
57
58
  jsc: {
58
59
  parser: {
59
60
  syntax: isTSX ? "typescript" : "ecmascript",
package/dist/types.d.ts CHANGED
@@ -30,6 +30,7 @@ export interface IDumiConfig extends IUmiConfig {
30
30
  };
31
31
  locales: ILocalesConfig;
32
32
  themeConfig: IThemeConfig;
33
+ autoAlias?: boolean;
33
34
  /**
34
35
  * extra unified plugins
35
36
  */
package/dist/utils.d.ts CHANGED
@@ -26,4 +26,8 @@ export declare function parseCodeFrontmatter(raw: string): {
26
26
  */
27
27
  declare const caches: Record<string, ReturnType<typeof Cache>>;
28
28
  export declare function getCache(ns: string): typeof caches['0'];
29
+ /**
30
+ * try to get father config
31
+ */
32
+ export declare function tryFatherBuildConfigs(cwd: string): Promise<any[]>;
29
33
  export {};