dumi 2.3.0-beta.7 → 2.3.0-beta.8

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 (40) hide show
  1. package/compiled/crates/swc_plugin_react_demo.wasm +0 -0
  2. package/dist/assetParsers/BaseParser.d.ts +55 -0
  3. package/dist/assetParsers/BaseParser.js +126 -0
  4. package/dist/assetParsers/atom.d.ts +18 -27
  5. package/dist/assetParsers/atom.js +84 -110
  6. package/dist/assetParsers/block.d.ts +2 -0
  7. package/dist/assetParsers/block.js +29 -16
  8. package/dist/assetParsers/utils.d.ts +79 -0
  9. package/dist/assetParsers/utils.js +112 -0
  10. package/dist/client/pages/Demo/index.js +11 -5
  11. package/dist/client/theme-api/DumiDemo/index.js +12 -4
  12. package/dist/client/theme-api/context.d.ts +1 -2
  13. package/dist/client/theme-api/index.d.ts +1 -1
  14. package/dist/client/theme-api/types.d.ts +12 -5
  15. package/dist/client/theme-api/useLiveDemo.js +114 -46
  16. package/dist/client/theme-api/useRenderer.d.ts +5 -0
  17. package/dist/client/theme-api/useRenderer.js +88 -0
  18. package/dist/constants.d.ts +2 -0
  19. package/dist/constants.js +13 -0
  20. package/dist/features/compile/index.js +15 -13
  21. package/dist/features/parser.js +9 -5
  22. package/dist/index.d.ts +3 -2
  23. package/dist/index.js +3 -0
  24. package/dist/loaders/markdown/index.js +24 -5
  25. package/dist/loaders/markdown/transformer/index.d.ts +11 -2
  26. package/dist/loaders/markdown/transformer/index.js +3 -0
  27. package/dist/loaders/markdown/transformer/rehypeDemo.js +22 -7
  28. package/dist/techStacks/react.js +6 -23
  29. package/dist/techStacks/utils.d.ts +18 -0
  30. package/dist/techStacks/utils.js +85 -0
  31. package/dist/types.d.ts +26 -3
  32. package/dist/utils.d.ts +2 -1
  33. package/dist/utils.js +2 -2
  34. package/package.json +7 -3
  35. package/tech-stack-utils.d.ts +12 -0
  36. package/tech-stack-utils.js +9 -0
  37. package/theme-default/builtins/API/index.d.ts +1 -0
  38. package/theme-default/builtins/API/index.js +12 -6
  39. package/theme-default/builtins/Previewer/index.less +1 -0
  40. package/theme-default/builtins/SourceCode/index.js +3 -2
package/dist/constants.js CHANGED
@@ -19,6 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/constants.ts
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
+ DEFAULT_DEMO_MODULE_EXTENSIONS: () => DEFAULT_DEMO_MODULE_EXTENSIONS,
23
+ DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS: () => DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS,
22
24
  FS_CACHE_DIR: () => FS_CACHE_DIR,
23
25
  LOCAL_DUMI_DIR: () => LOCAL_DUMI_DIR,
24
26
  LOCAL_PAGES_DIR: () => LOCAL_PAGES_DIR,
@@ -52,9 +54,20 @@ var PICKED_PKG_FIELDS = {
52
54
  var USELESS_TMP_FILES = ["tsconfig.json", "typings.d.ts"];
53
55
  var VERSION_2_LEVEL_NAV = "^2.2.0";
54
56
  var VERSION_2_DEPRECATE_SOFT_BREAKS = "^2.2.0";
57
+ var DEFAULT_DEMO_MODULE_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx"];
58
+ var DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS = [
59
+ ".css",
60
+ ".less",
61
+ ".sass",
62
+ ".scss",
63
+ ".styl",
64
+ ".json"
65
+ ];
55
66
  var FS_CACHE_DIR = "node_modules/.cache/dumi";
56
67
  // Annotate the CommonJS export names for ESM import in node:
57
68
  0 && (module.exports = {
69
+ DEFAULT_DEMO_MODULE_EXTENSIONS,
70
+ DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS,
58
71
  FS_CACHE_DIR,
59
72
  LOCAL_DUMI_DIR,
60
73
  LOCAL_PAGES_DIR,
@@ -108,22 +108,24 @@ var compile_default = (api) => {
108
108
  ...loaderBaseOpts,
109
109
  mode: "demo"
110
110
  }).end().end();
111
- mdRule.oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
112
- ...loaderBaseOpts,
113
- builtins: api.service.themeData.builtins,
114
- onResolveDemos(demos) {
115
- const assets = demos.reduce(
116
- (ret, demo) => {
111
+ mdRule.oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options(
112
+ api.isPluginEnable("assets") || api.isPluginEnable("exportStatic") ? {
113
+ ...loaderBaseOpts,
114
+ builtins: api.service.themeData.builtins,
115
+ onResolveDemos(demos) {
116
+ const assets = demos.reduce((ret, demo) => {
117
117
  if ("asset" in demo)
118
118
  ret.push(demo.asset);
119
119
  return ret;
120
- },
121
- []
122
- );
123
- (0, import_assets.addExampleAssets)(assets);
124
- },
125
- onResolveAtomMeta: import_assets.addAtomMeta
126
- });
120
+ }, []);
121
+ (0, import_assets.addExampleAssets)(assets);
122
+ },
123
+ onResolveAtomMeta: import_assets.addAtomMeta
124
+ } : {
125
+ ...loaderBaseOpts,
126
+ builtins: api.service.themeData.builtins
127
+ }
128
+ );
127
129
  memo.module.rule("dumi-page").type("javascript/auto").test(/\.(j|t)sx?$/).resourceQuery(/frontmatter$/).use("page-meta-loader").loader(require.resolve("../../loaders/page"));
128
130
  memo.module.rule("dumi-demo").type("javascript/auto").test(/\..+$/).enforce("pre").resourceQuery(/techStack/).use("demo-loader").loader(require.resolve("../../loaders/demo")).options({ techStacks, cwd: api.cwd });
129
131
  memo.module.rule("dumi-raw").type("javascript/auto").post().resourceQuery(/dumi-raw/).use("raw-loader").loader(require.resolve("raw-loader")).end().use("pre-raw-loader").loader(require.resolve("../../loaders/pre-raw"));
@@ -34,6 +34,7 @@ __export(parser_exports, {
34
34
  module.exports = __toCommonJS(parser_exports);
35
35
  var import_utils = require("@umijs/utils");
36
36
  var import_assert = __toESM(require("assert"));
37
+ var import_BaseParser = require("../assetParsers/BaseParser");
37
38
  var import_meta = require("./meta");
38
39
  function filterIgnoredProps(props) {
39
40
  return import_utils.lodash.pickBy(props, (prop) => {
@@ -89,15 +90,18 @@ var parser_default = (api) => {
89
90
  return memo;
90
91
  });
91
92
  api.onCheckPkgJSON(async () => {
93
+ if (api.service.atomParser instanceof import_BaseParser.BaseAtomAssetsParser)
94
+ return;
92
95
  const {
93
- default: AtomAssetsParser
96
+ default: ReactAtomAssetsParser
94
97
  } = require("../assetParsers/atom");
95
- api.service.atomParser = new AtomAssetsParser({
98
+ const apiParser = api.config.apiParser;
99
+ api.service.atomParser = new ReactAtomAssetsParser({
96
100
  entryFile: api.config.resolve.entryFile,
97
101
  resolveDir: api.cwd,
98
- unpkgHost: api.config.apiParser.unpkgHost,
99
- resolveFilter: api.config.apiParser.resolveFilter,
100
- parseOptions: api.config.apiParser.parseOptions
102
+ unpkgHost: apiParser.unpkgHost,
103
+ resolveFilter: apiParser.resolveFilter,
104
+ parseOptions: apiParser.parseOptions
101
105
  });
102
106
  });
103
107
  api.onDevCompileDone(({ isFirstCompile }) => {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { IDumiUserConfig } from "./types";
1
+ import type { IDumiTechStack, IDumiTechStackRuntimeOpts, IDumiUserConfig } from "./types";
2
2
  declare let unistUtilVisit: typeof import('unist-util-visit');
3
3
  export * from 'umi';
4
- export { unistUtilVisit };
4
+ export { getProjectRoot } from './utils';
5
+ export { unistUtilVisit, IDumiTechStack, IDumiTechStackRuntimeOpts };
5
6
  export declare const defineConfig: (config: IDumiUserConfig) => IDumiUserConfig;
package/dist/index.js CHANGED
@@ -31,10 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  defineConfig: () => defineConfig,
34
+ getProjectRoot: () => import_utils.getProjectRoot,
34
35
  unistUtilVisit: () => unistUtilVisit
35
36
  });
36
37
  module.exports = __toCommonJS(src_exports);
37
38
  __reExport(src_exports, require("umi"), module.exports);
39
+ var import_utils = require("./utils");
38
40
  var unistUtilVisit;
39
41
  (async () => {
40
42
  unistUtilVisit = await import("unist-util-visit");
@@ -43,6 +45,7 @@ var defineConfig = (config) => config;
43
45
  // Annotate the CommonJS export names for ESM import in node:
44
46
  0 && (module.exports = {
45
47
  defineConfig,
48
+ getProjectRoot,
46
49
  unistUtilVisit,
47
50
  ...require("umi")
48
51
  });
@@ -84,7 +84,9 @@ function emitDemo(opts, ret) {
84
84
  export const demos = {
85
85
  {{#demos}}
86
86
  '{{{id}}}': {
87
+ {{#component}}
87
88
  component: {{{component}}},
89
+ {{/component}}
88
90
  asset: {{{renderAsset}}},
89
91
  context: {{{renderContext}}},
90
92
  renderOpts: {{{renderRenderOpts}}},
@@ -124,15 +126,29 @@ export const demos = {
124
126
  return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, "");
125
127
  },
126
128
  renderRenderOpts: function renderRenderOpts() {
127
- if (!("renderOpts" in this) || !this.renderOpts.compilePath) {
129
+ if (!("renderOpts" in this)) {
128
130
  return "undefined";
129
131
  }
130
- return `{
132
+ const renderOpts = this.renderOpts;
133
+ const propertyArray = [];
134
+ if (renderOpts.compilePath) {
135
+ propertyArray.push(`
131
136
  compile: async (...args) => {
132
137
  return (await import('${(0, import_plugin_utils.winPath)(
133
- this.renderOpts.compilePath
134
- )}')).default(...args);
135
- },
138
+ renderOpts.compilePath
139
+ )}')).default(...args);
140
+ },`);
141
+ }
142
+ if (renderOpts.rendererPath) {
143
+ propertyArray.push(`
144
+ renderer: (await import('${(0, import_plugin_utils.winPath)(
145
+ renderOpts.rendererPath
146
+ )}')).default,`);
147
+ }
148
+ if (propertyArray.length === 0)
149
+ return "undefined";
150
+ return `{
151
+ ${propertyArray.join("\n")}
136
152
  }`;
137
153
  }
138
154
  }
@@ -201,6 +217,9 @@ var depsMapping = {};
201
217
  function mdLoader(content) {
202
218
  const opts = this.getOptions();
203
219
  const cb = this.async();
220
+ if (process.env.NODE_ENV === "production" && ["onResolveDemos", "onResolveAtomMeta"].some((k) => k in opts)) {
221
+ this.cacheable(false);
222
+ }
204
223
  const cache = (0, import_utils.getCache)("md-loader");
205
224
  const baseCacheKey = [
206
225
  this.resourcePath,
@@ -1,6 +1,6 @@
1
1
  import type { IParsedBlockAsset } from "../../../assetParsers/block";
2
2
  import type { ILocalesConfig, IRouteMeta } from "../../../client/theme-api/types";
3
- import type { IApi, IDumiConfig, IDumiTechStack, IDumiTechStackRuntimeOpts } from "../../../types";
3
+ import type { IApi, IDumiConfig, IDumiTechStack } from "../../../types";
4
4
  import type { IRoute } from 'umi';
5
5
  import type { Data } from 'vfile';
6
6
  declare module 'hast' {
@@ -22,10 +22,19 @@ declare module 'vfile' {
22
22
  component: string;
23
23
  asset: IParsedBlockAsset['asset'];
24
24
  resolveMap: IParsedBlockAsset['resolveMap'];
25
- renderOpts: Pick<IDumiTechStackRuntimeOpts, 'compilePath'>;
25
+ renderOpts: {
26
+ type?: string;
27
+ rendererPath?: string;
28
+ compilePath?: string;
29
+ };
26
30
  } | {
27
31
  id: string;
28
32
  component: string;
33
+ renderOpts: {
34
+ type?: string;
35
+ rendererPath?: string;
36
+ compilePath?: string;
37
+ };
29
38
  })[];
30
39
  texts: IRouteMeta['texts'];
31
40
  frontmatter: IRouteMeta['frontmatter'];
@@ -80,6 +80,9 @@ var transformer_default = async (raw, opts) => {
80
80
  const resolver = import_enhanced_resolve.default.create.sync({
81
81
  mainFields: ["browser", "module", "main"],
82
82
  extensions: [".js", ".jsx", ".ts", ".tsx"],
83
+ // Common conditionName needs to be configured,
84
+ // otherwise some common library paths cannot be parsed, such as vue, pinia, etc.
85
+ conditionNames: ["import", "require", "default", "browser", "node"],
83
86
  alias: opts.alias
84
87
  });
85
88
  const fileLocale = (_a = opts.locales.find(
@@ -180,9 +180,12 @@ function rehypeDemo(opts) {
180
180
  id: "",
181
181
  refAtomIds: vFile.data.frontmatter.atomId ? [vFile.data.frontmatter.atomId] : [],
182
182
  fileAbsPath: "",
183
+ lang: codeNode.data.lang,
183
184
  entryPointCode: codeType === "external" ? void 0 : codeValue,
184
- resolver: opts.resolver
185
+ resolver: opts.resolver,
186
+ techStack
185
187
  };
188
+ const runtimeOpts = techStack.runtimeOpts;
186
189
  const previewerProps = {};
187
190
  let component = "";
188
191
  if (codeType === "external") {
@@ -199,9 +202,14 @@ function rehypeDemo(opts) {
199
202
  localId,
200
203
  vFile.data.frontmatter.atomId
201
204
  );
202
- component = `React.memo(React.lazy(() => import( /* webpackChunkName: "${chunkName}" */ '${(0, import_plugin_utils.winPath)(
205
+ const importChunk = `import( /* webpackChunkName: "${chunkName}" */ '${(0, import_plugin_utils.winPath)(
203
206
  parseOpts.fileAbsPath
204
- )}?techStack=${techStack.name}')))`;
207
+ )}?techStack=${techStack.name}')`;
208
+ if (runtimeOpts == null ? void 0 : runtimeOpts.rendererPath) {
209
+ component = `(async () => ${importChunk})()`;
210
+ } else {
211
+ component = `React.memo(React.lazy(() => ${importChunk}))`;
212
+ }
205
213
  if (codeValue)
206
214
  codeNode.properties.title = codeValue;
207
215
  (_c = codeNode.properties).filename ?? (_c.filename = (0, import_plugin_utils.winPath)(
@@ -209,7 +217,10 @@ function rehypeDemo(opts) {
209
217
  ));
210
218
  } else {
211
219
  const localId = [opts.fileLocale, String(index++)].filter(Boolean).join("-");
212
- parseOpts.fileAbsPath = opts.fileAbsPath.replace(".md", ".tsx");
220
+ parseOpts.fileAbsPath = opts.fileAbsPath.replace(
221
+ ".md",
222
+ `.${parseOpts.lang}`
223
+ );
213
224
  parseOpts.id = getCodeId(
214
225
  opts.cwd,
215
226
  opts.fileLocaleLessPath,
@@ -226,7 +237,7 @@ function rehypeDemo(opts) {
226
237
  deferrers.push(
227
238
  (0, import_block.default)(parseOpts).then(
228
239
  async ({ asset, resolveMap, frontmatter }) => {
229
- var _a2, _b2, _c2, _d;
240
+ var _a2, _b2, _c2;
230
241
  if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
231
242
  const startLine = (_a2 = node.position) == null ? void 0 : _a2.start.line;
232
243
  const suffix = startLine ? `:${startLine}` : "";
@@ -265,7 +276,10 @@ function rehypeDemo(opts) {
265
276
  return {
266
277
  // TODO: special id for inline demo
267
278
  id: asset.id,
268
- component
279
+ component,
280
+ renderOpts: {
281
+ rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath
282
+ }
269
283
  };
270
284
  }
271
285
  Object.assign(
@@ -301,7 +315,8 @@ function rehypeDemo(opts) {
301
315
  techStackOpts
302
316
  ) : resolveMap,
303
317
  renderOpts: {
304
- compilePath: (_d = techStack.runtimeOpts) == null ? void 0 : _d.compilePath
318
+ rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
319
+ compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath
305
320
  }
306
321
  };
307
322
  }
@@ -32,7 +32,7 @@ __export(react_exports, {
32
32
  default: () => ReactTechStack
33
33
  });
34
34
  module.exports = __toCommonJS(react_exports);
35
- var import_core = require("@swc/core");
35
+ var import_utils = require("./utils");
36
36
  var ReactTechStack = class {
37
37
  constructor() {
38
38
  this.name = "react";
@@ -46,31 +46,14 @@ var ReactTechStack = class {
46
46
  transformCode(...[raw, opts]) {
47
47
  if (opts.type === "code-block") {
48
48
  const isTSX = opts.fileAbsPath.endsWith(".tsx");
49
- const { code } = (0, import_core.transformSync)(raw, {
49
+ const code = (0, import_utils.wrapDemoWithFn)(raw, {
50
50
  filename: opts.fileAbsPath,
51
- jsc: {
52
- parser: {
53
- syntax: isTSX ? "typescript" : "ecmascript",
54
- [isTSX ? "tsx" : "jsx"]: true
55
- },
56
- target: "es2022",
57
- experimental: {
58
- cacheRoot: "node_modules/.cache/swc",
59
- plugins: [
60
- [
61
- require.resolve("../../compiled/crates/swc_plugin_react_demo.wasm"),
62
- {}
63
- ]
64
- ]
65
- }
66
- },
67
- module: {
68
- type: "es6"
51
+ parserConfig: {
52
+ syntax: isTSX ? "typescript" : "ecmascript",
53
+ [isTSX ? "tsx" : "jsx"]: true
69
54
  }
70
55
  });
71
- return `React.memo(React.lazy(async () => {
72
- ${code}
73
- }))`;
56
+ return `React.memo(React.lazy(${code}))`;
74
57
  }
75
58
  return raw;
76
59
  }
@@ -0,0 +1,18 @@
1
+ import type { ParserConfig } from '@swc/core';
2
+ export { IDumiTechStack, IDumiTechStackOnBlockLoadArgs, IDumiTechStackOnBlockLoadResult, IDumiTechStackRuntimeOpts, } from '../types';
3
+ /**
4
+ * for frameworks like vue , we need to extract the JS fragments in their scripts
5
+ * @param htmlLike HTML, vue and other html-like files are available
6
+ * @returns js/ts code
7
+ */
8
+ export declare function extractScript(htmlLike: string): string;
9
+ export interface IWrapDemoWithFnOptions {
10
+ filename: string;
11
+ parserConfig: ParserConfig;
12
+ }
13
+ /**
14
+ * Use swc to convert es module into async function.
15
+ * More transform process detail, refer to:
16
+ * https://github.com/umijs/dumi/blob/master/crates/swc_plugin_react_demo/src/lib.rs#L126
17
+ */
18
+ export declare function wrapDemoWithFn(code: string, opts: IWrapDemoWithFnOptions): string;
@@ -0,0 +1,85 @@
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(
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
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/techStacks/utils.ts
30
+ var utils_exports = {};
31
+ __export(utils_exports, {
32
+ IDumiTechStack: () => import_types.IDumiTechStack,
33
+ IDumiTechStackOnBlockLoadArgs: () => import_types.IDumiTechStackOnBlockLoadArgs,
34
+ IDumiTechStackOnBlockLoadResult: () => import_types.IDumiTechStackOnBlockLoadResult,
35
+ IDumiTechStackRuntimeOpts: () => import_types.IDumiTechStackRuntimeOpts,
36
+ extractScript: () => extractScript,
37
+ wrapDemoWithFn: () => wrapDemoWithFn
38
+ });
39
+ module.exports = __toCommonJS(utils_exports);
40
+ var import_core = require("@swc/core");
41
+ var import_types = require("../types");
42
+ function extractScript(htmlLike) {
43
+ const htmlScriptReg = /<script\b(?:\s[^>]*>|>)(.*?)<\/script>/gims;
44
+ let match = htmlScriptReg.exec(htmlLike);
45
+ let scripts = "";
46
+ while (match) {
47
+ scripts += match[1] + "\n";
48
+ match = htmlScriptReg.exec(htmlLike);
49
+ }
50
+ return scripts;
51
+ }
52
+ function wrapDemoWithFn(code, opts) {
53
+ const { filename, parserConfig } = opts;
54
+ const result = (0, import_core.transformSync)(code, {
55
+ filename,
56
+ jsc: {
57
+ parser: parserConfig,
58
+ target: "es2022",
59
+ experimental: {
60
+ cacheRoot: "node_modules/.cache/swc",
61
+ plugins: [
62
+ [
63
+ require.resolve("../../compiled/crates/swc_plugin_react_demo.wasm"),
64
+ {}
65
+ ]
66
+ ]
67
+ }
68
+ },
69
+ module: {
70
+ type: "es6"
71
+ }
72
+ });
73
+ return `async function() {
74
+ ${result.code}
75
+ }`;
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ IDumiTechStack,
80
+ IDumiTechStackOnBlockLoadArgs,
81
+ IDumiTechStackOnBlockLoadResult,
82
+ IDumiTechStackRuntimeOpts,
83
+ extractScript,
84
+ wrapDemoWithFn
85
+ });
package/dist/types.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import type AtomAssetsParser from "./assetParsers/atom";
1
+ import type { BaseAtomAssetsParser as IAtomAssetsParser } from "./assetParsers/BaseParser";
2
2
  import type { IParsedBlockAsset } from "./assetParsers/block";
3
3
  import type { IDumiDemoProps } from "./client/theme-api/DumiDemo";
4
4
  import type { ILocalesConfig, IThemeConfig } from "./client/theme-api/types";
5
5
  import type { IContentTab } from "./features/tabs";
6
6
  import type { IThemeLoadResult } from "./features/theme/loader";
7
+ import { OnLoadArgs, OnLoadResult } from '@umijs/bundler-utils/compiled/esbuild';
7
8
  import type { IModify } from '@umijs/core';
8
9
  import type { AssetsPackage, ExampleBlockAsset } from 'dumi-assets-types';
9
10
  import type { Element } from 'hast';
@@ -48,7 +49,20 @@ export type IDumiUserConfig = Subset<Omit<IDumiConfig, 'locales'>> & {
48
49
  }>, 'base'>[];
49
50
  [key: string]: any;
50
51
  };
52
+ export interface IDumiTechStackOnBlockLoadResult {
53
+ content: string;
54
+ type: Required<OnLoadResult>['loader'];
55
+ }
56
+ export type IDumiTechStackOnBlockLoadArgs = OnLoadArgs & {
57
+ entryPointCode: string;
58
+ filename: string;
59
+ };
51
60
  export interface IDumiTechStackRuntimeOpts {
61
+ /**
62
+ * path of the cancelable{@link IDemoCancelableFn} function
63
+ * that manipulate(mount/unmount) third-party framework component
64
+ */
65
+ rendererPath?: string;
52
66
  /**
53
67
  * path to runtime compile function module
54
68
  */
@@ -72,7 +86,7 @@ export declare abstract class IDumiTechStack {
72
86
  */
73
87
  abstract isSupported(node: Element, lang: string): boolean;
74
88
  /**
75
- * transform for parse demo source to react component
89
+ * transform for parse demo source to expression/function/class
76
90
  */
77
91
  abstract transformCode(raw: string, opts: {
78
92
  type: 'external' | 'code-block';
@@ -95,6 +109,15 @@ export declare abstract class IDumiTechStack {
95
109
  * generator for return file path of demo source
96
110
  */
97
111
  abstract generateSources?(source: IParsedBlockAsset['resolveMap'], opts: Parameters<NonNullable<IDumiTechStack['generateMetadata']>>[1]): Promise<IParsedBlockAsset['resolveMap']> | IParsedBlockAsset['resolveMap'];
112
+ /**
113
+ * Use current function as onLoad CallBack(https://esbuild.github.io/plugins/#on-load)
114
+ * @description
115
+ * Why use this method?
116
+ * By default, dumi can only support the parsing of js/ts related code blocks,
117
+ * but many front-end frameworks have custom extensions,
118
+ * so this method is provided to facilitate developers to convert codes.
119
+ */
120
+ abstract onBlockLoad?(args: IDumiTechStackOnBlockLoadArgs): IDumiTechStackOnBlockLoadResult | null;
98
121
  }
99
122
  export type IApi = IUmiApi & {
100
123
  config: IDumiConfig & {
@@ -103,7 +126,7 @@ export type IApi = IUmiApi & {
103
126
  userConfig: IDumiUserConfig;
104
127
  service: IUmiApi['service'] & {
105
128
  themeData: IThemeLoadResult;
106
- atomParser: AtomAssetsParser;
129
+ atomParser: IAtomAssetsParser;
107
130
  };
108
131
  /**
109
132
  * register a new tech stack
package/dist/utils.d.ts CHANGED
@@ -15,7 +15,8 @@ export declare const getFileRangeLines: (content: string, range: string) => stri
15
15
  */
16
16
  export declare const getFileContentByRegExp: (content: string, regexp: string, filePath: string) => string;
17
17
  /**
18
- * parse frontmatter from code string
18
+ * parse frontmatter from code string,
19
+ * also supports html/xml comments
19
20
  */
20
21
  export declare function parseCodeFrontmatter(raw: string): {
21
22
  code: string;
package/dist/utils.js CHANGED
@@ -73,8 +73,8 @@ Error: ${err}`);
73
73
  }
74
74
  };
75
75
  function parseCodeFrontmatter(raw) {
76
- const [, comment = "", code = ""] = raw.replace(/^\n\s*/, "").match(/^(\/\*\*[^]*?\n\s*\*\/)?(?:\s|\n)*([^]+)?$/);
77
- const yamlComment = comment.replace(/^\/|\/$/g, "").replace(/(^|\n)\s*\*+/g, "$1");
76
+ const [, comment = "", code = ""] = raw.replace(/^\n\s*/, "").match(/^(\/\*\*[^]*?\n\s*\*\/|<!--[^]*?\n\s*-->)?(?:\s|\n)*([^]+)?$/);
77
+ const yamlComment = comment.replace(/^(\/|<!--)|(\/|-->)$/g, "").replace(/(^|\n)\s*\*+/g, "$1");
78
78
  let frontmatter = null;
79
79
  try {
80
80
  frontmatter = import_js_yaml.default.load(yamlComment);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.3.0-beta.7",
3
+ "version": "2.3.0-beta.8",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -32,7 +32,9 @@
32
32
  "theme-default",
33
33
  "index.d.ts",
34
34
  "plugin-utils.js",
35
- "plugin-utils.d.ts"
35
+ "plugin-utils.d.ts",
36
+ "tech-stack-utils.js",
37
+ "tech-stack-utils.d.ts"
36
38
  ],
37
39
  "scripts": {
38
40
  "build": "father build && npm run build:crates",
@@ -79,7 +81,7 @@
79
81
  "@ant-design/icons-svg": "^4.2.1",
80
82
  "@makotot/ghostui": "^2.0.0",
81
83
  "@stackblitz/sdk": "^1.9.0",
82
- "@swc/core": "1.3.72",
84
+ "@swc/core": "1.4.2",
83
85
  "@types/hast": "^2.3.5",
84
86
  "@types/mdast": "^3.0.12",
85
87
  "@umijs/bundler-utils": "^4.0.84",
@@ -88,6 +90,7 @@
88
90
  "animated-scroll-to": "^2.3.0",
89
91
  "classnames": "2.3.2",
90
92
  "codesandbox": "^2.2.3",
93
+ "comlink": "^4.4.1",
91
94
  "copy-to-clipboard": "^3.3.3",
92
95
  "deepmerge": "^4.3.1",
93
96
  "dumi-afx-deps": "^1.0.0-alpha.19",
@@ -159,6 +162,7 @@
159
162
  "@types/react-dom": "^18.2.7",
160
163
  "@umijs/lint": "^4.0.84",
161
164
  "@umijs/plugins": "4.0.32",
165
+ "codesandbox-import-utils": "^2.2.3",
162
166
  "dumi-theme-mobile": "workspace:*",
163
167
  "eslint": "^8.46.0",
164
168
  "fast-glob": "^3.3.1",
@@ -0,0 +1,12 @@
1
+ import type * as BabelCore from '@umijs/bundler-utils/compiled/@babel/core';
2
+ export {
3
+ IBaseApiParserOptions,
4
+ ILanguageMetaParser,
5
+ IPatchFile,
6
+ } from './dist/assetParsers/BaseParser';
7
+ export { createApiParser } from './dist/assetParsers/utils';
8
+ export * from './dist/techStacks/utils';
9
+ export { BabelCore };
10
+ export const babelCore: () => typeof import('@umijs/bundler-utils/compiled/@babel/core');
11
+ export const babelPresetTypeScript: () => BabelCore.PluginItem;
12
+ export const babelPresetEnv: () => BabelCore.PluginItem;
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ ...require('./dist/techStacks/utils'),
3
+ createApiParser: require('./dist/assetParsers/utils').createApiParser,
4
+ babelCore: () => require('@umijs/bundler-utils/compiled/babel/core'),
5
+ babelPresetTypeScript: () =>
6
+ require('@umijs/bundler-utils/compiled/babel/preset-typescript'),
7
+ babelPresetEnv: () =>
8
+ require('@umijs/bundler-utils/compiled/babel/preset-env'),
9
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FC } from 'react';
2
2
  declare const API: FC<{
3
3
  id?: string;
4
+ type?: 'props' | 'events' | 'slots' | 'methods';
4
5
  }>;
5
6
  export default API;