dumi 2.0.0-beta.6 → 2.0.0-beta.7

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.
@@ -11,6 +11,7 @@ export var DumiDemo = function DumiDemo(props) {
11
11
  var _demos$props$demo$id = demos[props.demo.id],
12
12
  component = _demos$props$demo$id.component,
13
13
  asset = _demos$props$demo$id.asset;
14
+ if (props.demo.inline) return /*#__PURE__*/createElement(component);
14
15
  return /*#__PURE__*/React.createElement(Previewer, _extends({
15
16
  asset: asset,
16
17
  demoUrl: // allow user override demoUrl by frontmatter
@@ -1,7 +1,9 @@
1
+ import type { PICKED_PKG_FIELDS } from "../../constants";
1
2
  import type { AtomComponentAsset } from 'dumi-assets-types';
2
3
  import { type ComponentType } from 'react';
3
4
  import type { ILocalesConfig, IPreviewerProps, IThemeConfig } from './types';
4
5
  interface ISiteContext {
6
+ pkg: Partial<Record<keyof typeof PICKED_PKG_FIELDS, any>>;
5
7
  demos: Record<string, {
6
8
  component: ComponentType;
7
9
  asset: IPreviewerProps['asset'];
@@ -1,5 +1,6 @@
1
1
  import { createContext, useContext } from 'react';
2
2
  export var SiteContext = /*#__PURE__*/createContext({
3
+ pkg: {},
3
4
  demos: {},
4
5
  components: {},
5
6
  locales: [],
@@ -1,3 +1,12 @@
1
1
  export declare const LOCAL_THEME_DIR = ".dumi/theme";
2
2
  export declare const THEME_PREFIX = "dumi-theme-";
3
3
  export declare const SP_ROUTE_PREFIX = "~";
4
+ export declare const PICKED_PKG_FIELDS: {
5
+ name: string;
6
+ description: string;
7
+ version: string;
8
+ license: string;
9
+ repository: string;
10
+ author: string;
11
+ authors: string;
12
+ };
package/dist/constants.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
22
  LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
23
+ PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
23
24
  SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
24
25
  THEME_PREFIX: () => THEME_PREFIX
25
26
  });
@@ -27,9 +28,19 @@ module.exports = __toCommonJS(constants_exports);
27
28
  var LOCAL_THEME_DIR = ".dumi/theme";
28
29
  var THEME_PREFIX = "dumi-theme-";
29
30
  var SP_ROUTE_PREFIX = "~";
31
+ var PICKED_PKG_FIELDS = {
32
+ name: "",
33
+ description: "",
34
+ version: "",
35
+ license: "",
36
+ repository: "",
37
+ author: "",
38
+ authors: ""
39
+ };
30
40
  // Annotate the CommonJS export names for ESM import in node:
31
41
  0 && (module.exports = {
32
42
  LOCAL_THEME_DIR,
43
+ PICKED_PKG_FIELDS,
33
44
  SP_ROUTE_PREFIX,
34
45
  THEME_PREFIX
35
46
  });
@@ -55,7 +55,12 @@ var compile_default = (api) => {
55
55
  ...loaderBaseOpts,
56
56
  mode: "meta",
57
57
  onResolveDemos(demos) {
58
- (0, import_assets.addExampleAssets)(demos.map(({ asset }) => asset));
58
+ const assets = demos.reduce((ret, demo) => {
59
+ if ("asset" in demo)
60
+ ret.push(demo.asset);
61
+ return ret;
62
+ }, []);
63
+ (0, import_assets.addExampleAssets)(assets);
59
64
  }
60
65
  }).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
61
66
  ...loaderBaseOpts,
@@ -49,17 +49,22 @@ var parser_default = (api) => {
49
49
  return memo;
50
50
  });
51
51
  api.onStart(async () => {
52
- const { default: AtomAssetsParser } = await import("../assetParsers/atom");
52
+ const {
53
+ default: AtomAssetsParser
54
+ } = require("../assetParsers/atom");
53
55
  api.service.atomParser = new AtomAssetsParser({
54
56
  entryFile: api.config.resolve.entryFile,
55
57
  resolveDir: api.cwd
56
58
  });
57
- if (api.env === "production") {
58
- api.service.atomParser.parse().then(writeAtomsMetaFile);
59
- } else {
59
+ if (api.env === "development") {
60
60
  api.service.atomParser.watch(writeAtomsMetaFile);
61
61
  }
62
62
  });
63
+ if (api.env === "production") {
64
+ api.onGenerateFiles(async () => {
65
+ writeAtomsMetaFile(await api.service.atomParser.parse());
66
+ });
67
+ }
63
68
  };
64
69
  // Annotate the CommonJS export names for ESM import in node:
65
70
  0 && (module.exports = {});
@@ -112,7 +112,7 @@ var routes_default = (api) => {
112
112
  }
113
113
  Object.entries(pages).forEach(([, route]) => {
114
114
  route.parentId = docLayoutId;
115
- route.file = import_path.default.resolve(pagesDir, route.file);
115
+ route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(pagesDir, route.file));
116
116
  routes[route.id] = route;
117
117
  });
118
118
  docDirs.map(normalizeDocDir).forEach(({ type, dir }) => {
@@ -129,7 +129,7 @@ var routes_default = (api) => {
129
129
  route.path = `${pluralType}/${route.path}`.replace(/\/+$/, "/");
130
130
  route.absPath = `/${route.path}`;
131
131
  }
132
- route.file = import_path.default.resolve(base, route.file);
132
+ route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(base, route.file));
133
133
  localizeUmiRoute(route, api.config.locales);
134
134
  routes[route.id] = route;
135
135
  });
@@ -145,7 +145,7 @@ var routes_default = (api) => {
145
145
  path: routePath,
146
146
  absPath: `/${routePath}`,
147
147
  parentId: docLayoutId,
148
- file: import_path.default.resolve(base, file)
148
+ file: (0, import_plugin_utils.winPath)(import_path.default.resolve(base, file))
149
149
  };
150
150
  localizeUmiRoute(routes[routeId], api.config.locales);
151
151
  });
@@ -70,9 +70,9 @@ var tabs_default = (api) => {
70
70
  routesTabMapping[parentFile].push(routeId);
71
71
  } else {
72
72
  tabsFromPlugins.forEach((tab) => {
73
- var _a;
74
- if (!tab.test || route.absPath.match(tab.test)) {
75
- routesTabMapping[_a = route.file] ?? (routesTabMapping[_a] = []);
73
+ var _a, _b;
74
+ if ((!tab.test || route.absPath.match(tab.test)) && !((_a = routesTabMapping[route.file]) == null ? void 0 : _a.includes(tab.id))) {
75
+ routesTabMapping[_b = route.file] ?? (routesTabMapping[_b] = []);
76
76
  routesTabMapping[route.file].push(tab.id);
77
77
  }
78
78
  });
@@ -123,6 +123,7 @@ export default function DumiContextWrapper() {
123
123
 
124
124
  return (
125
125
  <SiteContext.Provider value={{
126
+ pkg: ${JSON.stringify(import_plugin_utils.lodash.pick(api.pkg, ...Object.keys(import_constants.PICKED_PKG_FIELDS)))},
126
127
  demos,
127
128
  components,
128
129
  locales,
@@ -67,10 +67,13 @@ export const toc = {{{toc}}}
67
67
  frontmatter: JSON.stringify(frontmatter),
68
68
  toc: JSON.stringify(toc),
69
69
  renderAsset: function renderAsset() {
70
- let asset = this.asset;
70
+ if (!("asset" in this))
71
+ return "null";
72
+ let { asset } = this;
73
+ const { sources } = this;
71
74
  Object.keys(this.sources).forEach((file) => {
72
- asset = import_plugin_utils.lodash.cloneDeep(this.asset);
73
- asset.dependencies[file].value = `{{{require('!!raw-loader!${this.sources[file]}?raw').default}}}`;
75
+ asset = import_plugin_utils.lodash.cloneDeep(asset);
76
+ asset.dependencies[file].value = `{{{require('!!raw-loader!${sources[file]}?raw').default}}}`;
74
77
  });
75
78
  return JSON.stringify(asset, null, 2).replace(/"{{{|}}}"/g, "");
76
79
  }
@@ -16,12 +16,15 @@ declare module 'hast' {
16
16
  }
17
17
  declare module 'vfile' {
18
18
  interface DataMap {
19
- demos: {
19
+ demos: ({
20
20
  id: string;
21
21
  component: string;
22
22
  asset: IParsedBlockAsset['asset'];
23
23
  sources: IParsedBlockAsset['sources'];
24
- }[];
24
+ } | {
25
+ id: string;
26
+ component: string;
27
+ })[];
25
28
  frontmatter: IRouteMeta['frontmatter'];
26
29
  toc: IRouteMeta['toc'];
27
30
  embeds?: string[];
@@ -150,8 +150,9 @@ function rehypeDemo(opts) {
150
150
  fileAbsPath: opts.fileAbsPath
151
151
  });
152
152
  }
153
+ const propDemo = { id: parseOpts.id };
153
154
  deferrers.push((0, import_block.default)(parseOpts).then(async ({ asset, sources, frontmatter }) => {
154
- var _a3;
155
+ var _a3, _b;
155
156
  const { src, className, ...restAttrs } = codeNode.properties || {};
156
157
  const validAssetAttrs = [
157
158
  "title",
@@ -167,7 +168,14 @@ function rehypeDemo(opts) {
167
168
  if (originalProps[key])
168
169
  asset[key] = originalProps[key];
169
170
  });
170
- Object.assign(previewerProps, await ((_a3 = techStack.generatePreviewerProps) == null ? void 0 : _a3.call(techStack, originalProps, {
171
+ if (/ inline/.test(String((_a3 = codeNode.data) == null ? void 0 : _a3.meta)) || originalProps.inline) {
172
+ propDemo.inline = true;
173
+ return {
174
+ id: asset.id,
175
+ component
176
+ };
177
+ }
178
+ Object.assign(previewerProps, await ((_b = techStack.generatePreviewerProps) == null ? void 0 : _b.call(techStack, originalProps, {
171
179
  type: codeType,
172
180
  mdAbsPath: opts.fileAbsPath,
173
181
  fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
@@ -194,7 +202,7 @@ function rehypeDemo(opts) {
194
202
  };
195
203
  }));
196
204
  demosPropData.push({
197
- demo: { id: parseOpts.id },
205
+ demo: propDemo,
198
206
  previewerProps
199
207
  });
200
208
  }
@@ -27,6 +27,7 @@ __export(rehypeEmbed_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(rehypeEmbed_exports);
29
29
  var import_path = __toESM(require("path"));
30
+ var import_plugin_utils = require("umi/plugin-utils");
30
31
  var import_url = __toESM(require("url"));
31
32
  var visit;
32
33
  (async () => {
@@ -40,7 +41,7 @@ function rehypeEmbed(opts) {
40
41
  if (node.tagName === EMBED_TAG && ((_a = node.properties) == null ? void 0 : _a.hasOwnProperty("src"))) {
41
42
  const { src } = node.properties;
42
43
  const parsed = import_url.default.parse((src == null ? void 0 : src.toString()) || "");
43
- const absPath = import_path.default.resolve(import_path.default.parse(opts.fileAbsPath).dir, parsed.pathname);
44
+ const absPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(import_path.default.parse(opts.fileAbsPath).dir, parsed.pathname));
44
45
  if (absPath) {
45
46
  const hash = decodeURIComponent(parsed.hash || "").replace("#", "");
46
47
  const query = new URLSearchParams();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0-beta.7",
4
4
  "description": "Framework for developing UI components",
5
5
  "keywords": [],
6
6
  "license": "MIT",