dumi 2.1.2 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,8 @@ var AtomAssetsParser = class {
48
48
  async parse() {
49
49
  if (!this.parseDeferrer || this.unresolvedFiles.length) {
50
50
  this.parseDeferrer = (async () => {
51
- await this.parser.patch(this.unresolvedFiles.splice(0));
51
+ this.unresolvedFiles.splice(0);
52
+ await this.parser.patch([]);
52
53
  const resolver = new import_parser.SchemaResolver(await this.parser.parse());
53
54
  const result = {
54
55
  components: {},
@@ -21,6 +21,10 @@ export interface IPreviewerProps {
21
21
  * debug mark (will only render in dev by default)
22
22
  */
23
23
  debug?: boolean;
24
+ /**
25
+ * display the source code or not by default
26
+ */
27
+ defaultShowCode?: boolean;
24
28
  /**
25
29
  * url for render current demo in a single page
26
30
  */
@@ -85,6 +89,7 @@ export interface IRouteMeta {
85
89
  };
86
90
  atomId?: string;
87
91
  filename?: string;
92
+ debug?: boolean;
88
93
  [key: string]: any;
89
94
  };
90
95
  toc: {
@@ -110,8 +115,8 @@ export interface IRouteMeta {
110
115
  }[];
111
116
  tabs?: {
112
117
  key: string;
113
- name?: string;
114
- nameIntlId?: string;
118
+ title?: string;
119
+ titleIntlId?: string;
115
120
  components: {
116
121
  default: ComponentType;
117
122
  Extra: ComponentType;
@@ -138,15 +143,15 @@ export declare type ILocalesConfig = ILocale[];
138
143
  export interface INavItem {
139
144
  title: string;
140
145
  link: string;
141
- order: number;
146
+ order?: number;
142
147
  activePath?: string;
143
148
  [key: string]: any;
144
149
  }
145
150
  export interface ISidebarItem {
146
151
  title: string;
147
152
  link: string;
148
- order: number;
149
- frontmatter: IRouteMeta['frontmatter'];
153
+ order?: number;
154
+ frontmatter?: IRouteMeta['frontmatter'];
150
155
  [key: string]: any;
151
156
  }
152
157
  export interface ISidebarGroup {
@@ -163,7 +168,7 @@ export interface IThemeConfig {
163
168
  children?: INavItem[];
164
169
  })[]>;
165
170
  sidebar?: Record<string, ISidebarGroup[]>;
166
- footer?: string;
171
+ footer?: string | false;
167
172
  prefersColor: {
168
173
  default: 'light' | 'dark' | 'auto';
169
174
  switch: boolean;
@@ -47,7 +47,7 @@ function safeExcludeInMFSU(api, excludes) {
47
47
  var derivative_default = (api) => {
48
48
  api.describe({ key: "dumi:derivative" });
49
49
  api.onCheck(() => {
50
- var _a, _b;
50
+ var _a, _b, _c;
51
51
  (0, import_assert.default)(!api.config.mpa, "MPA mode is not supported in dumi!");
52
52
  (0, import_assert.default)(!api.config.vite, "Vite mode is not supported yet!");
53
53
  if (typeof api.config.mfsu === "object") {
@@ -61,12 +61,15 @@ var derivative_default = (api) => {
61
61
  }
62
62
  try {
63
63
  const tsconfig = require(import_path.default.join(api.cwd, "tsconfig.json"));
64
- const expected = [".dumi/**/*", ".dumirc.ts"];
64
+ const expected = [".dumi/**/*"];
65
+ if ((_c = api.service.configManager) == null ? void 0 : _c.mainConfigFile) {
66
+ expected.push((0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, api.service.configManager.mainConfigFile)));
67
+ }
65
68
  if (!expected.every((f) => {
66
69
  var _a2;
67
70
  return (_a2 = tsconfig.include) == null ? void 0 : _a2.includes(f);
68
71
  })) {
69
- import_plugin_utils.logger.warn("Please append `.dumi/**/*` & `.dumirc.ts` into `include` option of `tsconfig.json`, to make sure `defineConfig` works.");
72
+ import_plugin_utils.logger.warn(`Please append ${expected.map((e) => `\`${e}\``).join(" & ")} into \`include\` option of \`tsconfig.json\`, to make sure \`defineConfig\` works.`);
70
73
  }
71
74
  } catch {
72
75
  }
@@ -106,6 +109,9 @@ var derivative_default = (api) => {
106
109
  });
107
110
  api.modifyConfig((memo) => {
108
111
  var _a;
112
+ if (api.userConfig.mfsu === true) {
113
+ memo.mfsu = {};
114
+ }
109
115
  if ((_a = api.userConfig.alias) == null ? void 0 : _a["@"]) {
110
116
  memo.alias["@"] = api.userConfig.alias["@"];
111
117
  } else {
@@ -111,13 +111,26 @@ import deepmerge from '${(0, import_plugin_utils.winPath)(import_path.default.di
111
111
  export const patchRoutes = ({ routes }) => {
112
112
  Object.values(routes).forEach((route) => {
113
113
  if (filesMeta[route.id]) {
114
- route.meta = deepmerge(route.meta, filesMeta[route.id]);
114
+ if (process.env.NODE_ENV === 'production' && (route.meta?.frontmatter?.debug || filesMeta[route.id].frontmatter.debug)) {
115
+ // hide route in production which set hide frontmatter
116
+ delete routes[route.id];
117
+ } else {
118
+ // merge meta to route object
119
+ route.meta = deepmerge(route.meta, filesMeta[route.id]);
115
120
 
116
- // apply real tab data from id
117
- route.meta.tabs = route.meta.tabs?.map(id => ({
118
- ...tabs[id],
119
- meta: filesMeta[id],
120
- }));
121
+ // apply real tab data from id
122
+ route.meta.tabs = route.meta.tabs?.map((id) => {
123
+ const meta = {
124
+ frontmatter: { title: tabs[id].title },
125
+ toc: [],
126
+ texts: [],
127
+ }
128
+ return {
129
+ ...tabs[id],
130
+ meta: filesMeta[id] || meta,
131
+ }
132
+ });
133
+ }
121
134
  }
122
135
  });
123
136
  }
@@ -36,7 +36,11 @@ function normalizeDocDir(docDir) {
36
36
  return typeof docDir === "object" ? docDir : { dir: docDir };
37
37
  }
38
38
  function kebabCaseRoutePath(routePath) {
39
- return routePath.split("/").map((p) => import_plugin_utils.lodash.kebabCase(p)).join("/");
39
+ const replacer = (_, s1, s2, i) => {
40
+ const symbol = ["", "/"].includes(s1) || !i ? "" : "-";
41
+ return `${s1 || ""}${symbol}${s2.toLowerCase()}`;
42
+ };
43
+ return routePath.replace(/(.)?([A-Z][^A-Z/])/g, replacer).replace(/(.)?([A-Z]+)/g, replacer);
40
44
  }
41
45
  function localizeUmiRoute(route, locales) {
42
46
  const locale = locales.find((locale2) => route.path.endsWith(`/${locale2.id}`) && import_path.default.parse(route.file).name.endsWith(`.${locale2.id}`));
@@ -3,8 +3,8 @@ export interface IContentTab {
3
3
  key: string;
4
4
  id?: string;
5
5
  test?: RegExp;
6
- name?: string;
7
- nameIntlId?: string;
6
+ title?: string;
7
+ titleIntlId?: string;
8
8
  component: string;
9
9
  }
10
10
  export declare function isTabRouteFile(file: string): boolean;
@@ -86,8 +86,8 @@ var tabs_default = (api) => {
86
86
  index: tabs.length + index,
87
87
  key: tab.key,
88
88
  id: tab.id,
89
- name: tab.name,
90
- nameIntlId: tab.nameIntlId,
89
+ title: tab.title || import_plugin_utils.lodash.startCase(import_path.default.parse(tab.component).name),
90
+ titleIntlId: tab.titleIntlId,
91
91
  file: tab.component
92
92
  })));
93
93
  return routes;
@@ -101,11 +101,14 @@ var tabs_default = (api) => {
101
101
  }
102
102
  });
103
103
  tabs.forEach((tab) => {
104
- metaFiles.push({
105
- id: tab.id,
106
- file: tab.file,
107
- index: metaFiles.length
108
- });
104
+ const isFromPlugin = tabsFromPlugins.some((item) => item.id === tab.id);
105
+ if (!isFromPlugin) {
106
+ metaFiles.push({
107
+ id: tab.id,
108
+ file: tab.file,
109
+ index: metaFiles.length
110
+ });
111
+ }
109
112
  });
110
113
  return metaFiles;
111
114
  }
@@ -120,7 +123,7 @@ import * as tab{{{index}}} from '{{{file}}}';
120
123
 
121
124
  export const tabs = {
122
125
  {{#tabs}}
123
- '{{{id}}}': { key: '{{{key}}}', name: '{{{name}}}', nameIntlId: '{{{nameIntlId}}}', components: tab{{{index}}} },
126
+ '{{{id}}}': { key: '{{{key}}}', title: '{{{title}}}', titleIntlId: '{{{titleIntlId}}}', components: tab{{{index}}} },
124
127
  {{/tabs}}
125
128
  }
126
129
  `, { tabs })
@@ -163,6 +163,12 @@ function rehypeDemo(opts) {
163
163
  "snapshot",
164
164
  "keywords"
165
165
  ];
166
+ const techStackOpts = {
167
+ type: codeType,
168
+ mdAbsPath: opts.fileAbsPath,
169
+ fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
170
+ entryPointCode: parseOpts.entryPointCode
171
+ };
166
172
  Object.keys(restAttrs).forEach((key) => {
167
173
  if (restAttrs[key] === "")
168
174
  restAttrs[key] = true;
@@ -179,12 +185,7 @@ function rehypeDemo(opts) {
179
185
  component
180
186
  };
181
187
  }
182
- Object.assign(previewerProps, await ((_b = techStack.generatePreviewerProps) == null ? void 0 : _b.call(techStack, originalProps, {
183
- type: codeType,
184
- mdAbsPath: opts.fileAbsPath,
185
- fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
186
- entryPointCode: parseOpts.entryPointCode
187
- })) || originalProps);
188
+ Object.assign(previewerProps, await ((_b = techStack.generatePreviewerProps) == null ? void 0 : _b.call(techStack, originalProps, techStackOpts)) || originalProps);
188
189
  if (previewerProps.description) {
189
190
  const { unified } = await import("unified");
190
191
  const { default: remarkParse } = await import("remark-parse");
@@ -201,7 +202,7 @@ function rehypeDemo(opts) {
201
202
  return {
202
203
  id: asset.id,
203
204
  component,
204
- asset: techStack.generateMetadata ? await techStack.generateMetadata(asset) : asset,
205
+ asset: techStack.generateMetadata ? await techStack.generateMetadata(asset, techStackOpts) : asset,
205
206
  sources
206
207
  };
207
208
  }));
package/dist/types.d.ts CHANGED
@@ -71,16 +71,16 @@ export declare abstract class IDumiTechStack {
71
71
  /**
72
72
  * generator for return asset metadata
73
73
  */
74
- abstract generateMetadata?(asset: ExampleBlockAsset): Promise<ExampleBlockAsset> | ExampleBlockAsset;
75
- /**
76
- * generator for return previewer props
77
- */
78
- abstract generatePreviewerProps?(props: IDumiDemoProps['previewerProps'], opts: {
74
+ abstract generateMetadata?(asset: ExampleBlockAsset, opts: {
79
75
  type: Parameters<IDumiTechStack['transformCode']>[1]['type'];
80
76
  mdAbsPath: string;
81
77
  fileAbsPath?: string;
82
78
  entryPointCode?: string;
83
- }): Promise<IDumiDemoProps['previewerProps']> | IDumiDemoProps['previewerProps'];
79
+ }): Promise<ExampleBlockAsset> | ExampleBlockAsset;
80
+ /**
81
+ * generator for return previewer props
82
+ */
83
+ abstract generatePreviewerProps?(props: IDumiDemoProps['previewerProps'], opts: Parameters<NonNullable<IDumiTechStack['generateMetadata']>>[1]): Promise<IDumiDemoProps['previewerProps']> | IDumiDemoProps['previewerProps'];
84
84
  }
85
85
  export declare type IApi = IUmiApi & {
86
86
  config: IDumiConfig & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -107,7 +107,7 @@
107
107
  "prism-themes": "^1.9.0",
108
108
  "prismjs": "^1.29.0",
109
109
  "raw-loader": "^4.0.2",
110
- "rc-tabs": "12.1.0-alpha.1",
110
+ "rc-tabs": "^12.5.6",
111
111
  "react-copy-to-clipboard": "^5.1.0",
112
112
  "react-error-boundary": "^3.1.4",
113
113
  "react-intl": "^6.1.1",
@@ -10,7 +10,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
10
10
 
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
- import { FormattedMessage, useIntl, usePrefersColor, useSiteData } from 'dumi';
13
+ import { useIntl, usePrefersColor, useSiteData } from 'dumi';
14
14
  import React from 'react';
15
15
  import "./index.less";
16
16
 
@@ -68,19 +68,14 @@ var ColorSwitch = function ColorSwitch() {
68
68
  return setPrefersColor(ev.target.value);
69
69
  },
70
70
  value: prefersColor
71
- }, /*#__PURE__*/React.createElement("option", {
72
- value: "light"
73
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
74
- id: "header.color.mode.light"
75
- })), /*#__PURE__*/React.createElement("option", {
76
- value: "dark"
77
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
78
- id: "header.color.mode.dark"
79
- })), /*#__PURE__*/React.createElement("option", {
80
- value: "auto"
81
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
82
- id: "header.color.mode.auto"
83
- }))));
71
+ }, ['light', 'dark', 'auto'].map(function (c) {
72
+ return /*#__PURE__*/React.createElement("option", {
73
+ value: c,
74
+ key: c
75
+ }, intl.formatMessage({
76
+ id: "header.color.mode.".concat(c)
77
+ }));
78
+ })));
84
79
  };
85
80
 
86
81
  export default ColorSwitch;
@@ -28,9 +28,9 @@ var ContentTabs = function ContentTabs(_ref) {
28
28
  "data-active": key === tab.key || undefined
29
29
  }, /*#__PURE__*/React.createElement("button", {
30
30
  type: "button"
31
- }, tab.nameIntlId ? intl.formatMessage({
32
- id: tab.nameIntlId
33
- }) : tab.name || tab.meta.frontmatter.title));
31
+ }, tab.titleIntlId ? intl.formatMessage({
32
+ id: tab.titleIntlId
33
+ }) : tab.meta.frontmatter.title));
34
34
  })) : null;
35
35
  };
36
36
 
@@ -97,7 +97,7 @@ var PreviewerActions = function PreviewerActions(props) {
97
97
  "data-dumi-tooltip": intl.formatMessage({
98
98
  id: 'previewer.actions.separate'
99
99
  })
100
- }, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement(PreviewerActionsExtra, props), !(props !== null && props !== void 0 && props.forceShowCode) && /*#__PURE__*/React.createElement("button", {
100
+ }, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement(PreviewerActionsExtra, props), !props.forceShowCode && /*#__PURE__*/React.createElement("button", {
101
101
  className: "dumi-default-previewer-action-btn",
102
102
  type: "button",
103
103
  onClick: function onClick() {