dumi 2.1.10 → 2.1.11

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.
@@ -55,7 +55,7 @@ var compile_default = (api) => {
55
55
  resolve: api.config.resolve,
56
56
  extraRemarkPlugins: api.config.extraRemarkPlugins,
57
57
  extraRehypePlugins: api.config.extraRehypePlugins,
58
- routers: api.appData.routes
58
+ routes: api.appData.routes
59
59
  };
60
60
  memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("md-meta").resourceQuery(/meta$/).use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-meta-loader").loader(loaderPath).options({
61
61
  ...loaderBaseOpts,
@@ -9,6 +9,7 @@ export interface IContentTab {
9
9
  }
10
10
  export declare function isTabRouteFile(file: string): boolean;
11
11
  export declare function getTabKeyFromFile(file: string): string;
12
+ export declare function getHostForTabRouteFile(file: string): string;
12
13
  /**
13
14
  * plugin for add conventional tab and plugin tab into page content
14
15
  */
@@ -23,6 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
23
23
  var tabs_exports = {};
24
24
  __export(tabs_exports, {
25
25
  default: () => tabs_default,
26
+ getHostForTabRouteFile: () => getHostForTabRouteFile,
26
27
  getTabKeyFromFile: () => getTabKeyFromFile,
27
28
  isTabRouteFile: () => isTabRouteFile
28
29
  });
@@ -37,6 +38,9 @@ function isTabRouteFile(file) {
37
38
  function getTabKeyFromFile(file) {
38
39
  return file.match(/\$tab-([^.]+)/)[1];
39
40
  }
41
+ function getHostForTabRouteFile(file) {
42
+ return file.replace(/\$tab-[^.]+\./, "");
43
+ }
40
44
  var tabs_default = (api) => {
41
45
  let tabsFromPlugins;
42
46
  const routesTabMapping = {};
@@ -132,6 +136,7 @@ export const tabs = {
132
136
  };
133
137
  // Annotate the CommonJS export names for ESM import in node:
134
138
  0 && (module.exports = {
139
+ getHostForTabRouteFile,
135
140
  getTabKeyFromFile,
136
141
  isTabRouteFile
137
142
  });
@@ -115,8 +115,22 @@ var theme_default = (api) => {
115
115
  memo.alias["dumi/theme-default"] = DEFAULT_THEME_PATH;
116
116
  memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
117
117
  memo.extraBabelIncludes.push(import_path.default.resolve(__dirname, "../../client/theme-api"));
118
- memo.theme ?? (memo.theme = {});
119
- memo.theme["dark-selector"] = `~'[${import_constants.PREFERS_COLOR_ATTR}="dark"]'`;
118
+ return memo;
119
+ });
120
+ api.chainWebpack((memo) => {
121
+ const lessRule = memo.module.rule("less");
122
+ ["css", "css-modules"].forEach((rule) => {
123
+ Object.values(lessRule.oneOf(rule).uses.entries()).forEach((loader) => {
124
+ if (loader.get("loader").includes("less-loader")) {
125
+ loader.tap((opts) => {
126
+ var _a;
127
+ (_a = opts.lessOptions).modifyVars ?? (_a.modifyVars = {});
128
+ opts.lessOptions.modifyVars["dark-selector"] = `~'[${import_constants.PREFERS_COLOR_ATTR}="dark"]'`;
129
+ return opts;
130
+ });
131
+ }
132
+ });
133
+ });
120
134
  return memo;
121
135
  });
122
136
  api.onGenerateFiles(() => {
@@ -41,7 +41,7 @@ export interface IMdTransformerOptions {
41
41
  resolve: IDumiConfig['resolve'];
42
42
  extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
43
43
  extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
44
- routers: Record<string, IRoute>;
44
+ routes: Record<string, IRoute>;
45
45
  }
46
46
  export interface IMdTransformerResult {
47
47
  content: string;
@@ -81,7 +81,7 @@ var transformer_default = async (raw, opts) => {
81
81
  resolver
82
82
  }).use(import_rehypeSlug.default).use(import_rehypeLink.default, {
83
83
  fileAbsPath: opts.fileAbsPath,
84
- routers: opts.routers
84
+ routes: opts.routes
85
85
  }).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default).use(import_rehypeEnhancedTag.default).use(import_rehypeDesc.default).use(import_rehypeText.default);
86
86
  (_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
87
87
  plugin,
@@ -100,13 +100,18 @@ function rehypeDemo(opts) {
100
100
  if (isFirstChild) {
101
101
  node.data ?? (node.data = {});
102
102
  node.data[DEMO_NODE_CONTAINER] = true;
103
- while (nextChild && (isElement(nextChild, "code") && tryMarkDemoNode(nextChild, opts) || isElement(nextChild, "br"))) {
104
- splitFrom += 1;
105
- nextChildIndex = splitFrom + 1;
106
- nextChild = node.children[nextChildIndex];
107
- }
108
103
  if (!nextChild)
109
104
  return SKIP;
105
+ while (nextChild) {
106
+ if (isElement(nextChild, "code") && tryMarkDemoNode(nextChild, opts) || isElement(nextChild, "br")) {
107
+ splitFrom += 1;
108
+ nextChildIndex = splitFrom + 1;
109
+ nextChild = node.children[nextChildIndex];
110
+ } else {
111
+ splitFrom += 1;
112
+ break;
113
+ }
114
+ }
110
115
  }
111
116
  const splitChildren = node.children.splice(splitFrom);
112
117
  parent.children.splice(nodeIndex + 1, 0, {
@@ -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' | 'routers'>;
4
+ declare type IRehypeLinkOptions = Pick<IMdTransformerOptions, 'fileAbsPath' | 'routes'>;
5
5
  export default function rehypeLink(opts: IRehypeLinkOptions): Transformer<Root>;
6
6
  export {};
@@ -25,6 +25,7 @@ __export(rehypeLink_exports, {
25
25
  default: () => rehypeLink
26
26
  });
27
27
  module.exports = __toCommonJS(rehypeLink_exports);
28
+ var import_tabs = require("../../../features/tabs");
28
29
  var import_path = __toESM(require("path"));
29
30
  var import_plugin_utils = require("umi/plugin-utils");
30
31
  var import_url = __toESM(require("url"));
@@ -40,16 +41,28 @@ function rehypeLink(opts) {
40
41
  if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string") {
41
42
  const href = node.properties.href;
42
43
  const parsedUrl = import_url.default.parse(href);
44
+ const hostAbsPath = (0, import_tabs.getHostForTabRouteFile)(opts.fileAbsPath);
43
45
  if (parsedUrl.hostname)
44
46
  return SKIP;
45
47
  if (/\.md$/i.test(parsedUrl.pathname)) {
46
- const { routers } = opts;
47
- const absPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(opts.fileAbsPath, "..", parsedUrl.pathname));
48
- Object.keys(routers).forEach((key) => {
49
- if (routers[key].file === absPath) {
50
- parsedUrl.pathname = routers[key].absPath;
48
+ const { routes } = opts;
49
+ const absPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(hostAbsPath, "..", parsedUrl.pathname));
50
+ Object.keys(routes).forEach((key) => {
51
+ if (routes[key].file === absPath) {
52
+ parsedUrl.pathname = routes[key].absPath;
51
53
  }
52
54
  });
55
+ } else if (/^\.?\.\//.test(parsedUrl.pathname) || /^(\w+:)?\/\//.test(parsedUrl.pathname)) {
56
+ const routes = Object.values(opts.routes);
57
+ const basePath = routes.find((route) => route.file === hostAbsPath).absPath;
58
+ const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
59
+ const rr6TargetPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(basePath, parsedUrl.pathname));
60
+ parsedUrl.pathname = htmlTargetPath;
61
+ if (routes.every((route) => route.absPath !== htmlTargetPath) && routes.some((route) => route.absPath === rr6TargetPath)) {
62
+ 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`);
65
+ }
53
66
  }
54
67
  parent.children.splice(i, 1, {
55
68
  type: "element",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.10",
3
+ "version": "2.1.11",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -11,8 +11,115 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import { useAtomAssets, useIntl, useRouteMeta } from 'dumi';
14
- import React from 'react';
14
+ import React, { useEffect, useState } from 'react';
15
15
  import Table from "../Table";
16
+ var HANDLERS = {
17
+ // entry method
18
+ toString: function toString(prop) {
19
+ if (typeof prop.type === 'string' && prop.type in this) {
20
+ // value from TypeMap
21
+ if ('enum' in prop) return this.enum(prop);
22
+ return this[prop.type](prop);
23
+ } else if (prop.type) {
24
+ // non-parsed type, such as ReactNode
25
+ return this.getValidClassName(prop) || prop.type;
26
+ } else if ('const' in prop) {
27
+ // const value
28
+ return prop.const;
29
+ } else if ('oneOf' in prop) {
30
+ // oneOf value
31
+ return this.oneOf(prop);
32
+ } // unknown type
33
+
34
+
35
+ return "unknown";
36
+ },
37
+ // type handlers
38
+ string: function string(prop) {
39
+ return prop.type;
40
+ },
41
+ number: function number(prop) {
42
+ return prop.type;
43
+ },
44
+ boolean: function boolean(prop) {
45
+ return prop.type;
46
+ },
47
+ any: function any(prop) {
48
+ return prop.type;
49
+ },
50
+ object: function object(prop) {
51
+ var _this = this;
52
+
53
+ var props = [];
54
+ Object.entries(prop.properties || {}).forEach(function (_ref) {
55
+ var _prop$required;
56
+
57
+ var _ref2 = _slicedToArray(_ref, 2),
58
+ key = _ref2[0],
59
+ value = _ref2[1];
60
+
61
+ // skip nested object type
62
+ props.push("".concat(key).concat((_prop$required = prop.required) !== null && _prop$required !== void 0 && _prop$required.includes(key) ? '' : '?', ": ").concat(value.type === 'object' ? 'object' : _this.toString(value)));
63
+ });
64
+ return props.length ? "{ ".concat(props.join('; '), " }") : '{}';
65
+ },
66
+ array: function array(prop) {
67
+ if (prop.items) {
68
+ var className = this.getValidClassName(prop.items);
69
+ return className ? "".concat(className, "[]") : "".concat(this.toString(prop.items), "[]");
70
+ }
71
+
72
+ return 'any[]';
73
+ },
74
+ // FIXME: extract real type
75
+ element: function element(prop) {
76
+ return "<".concat(prop.componentName, " />");
77
+ },
78
+ // FIXME: extract real type
79
+ function: function _function(_ref3) {
80
+ var _this2 = this;
81
+
82
+ var signature = _ref3.signature;
83
+ return "".concat(signature.isAsync ? 'async ' : '', "(").concat(signature.arguments.map(function (arg) {
84
+ return "".concat(arg.key, ": ").concat(_this2.toString(arg));
85
+ }).join(', '), ") => ").concat(this.toString(signature.returnType));
86
+ },
87
+ // FIXME: extract real type
88
+ dom: function dom(prop) {
89
+ return "<".concat(prop.$$__body.id, " />");
90
+ },
91
+ // special handlers
92
+ enum: function _enum(prop) {
93
+ return prop.enum.map(function (v) {
94
+ return JSON.stringify(v);
95
+ }).join(' | ');
96
+ },
97
+ oneOf: function oneOf(prop) {
98
+ var _this3 = this;
99
+
100
+ return prop.oneOf.map(function (v) {
101
+ return _this3.getValidClassName(v) || _this3.toString(v);
102
+ }).join(' | ');
103
+ },
104
+ // utils
105
+ getValidClassName: function getValidClassName(prop) {
106
+ return 'className' in prop && typeof prop.className === 'string' && prop.className !== '__type' ? prop.className : null;
107
+ }
108
+ };
109
+
110
+ var APIType = function APIType(prop) {
111
+ var _useState = useState(function () {
112
+ return HANDLERS.toString(prop);
113
+ }),
114
+ _useState2 = _slicedToArray(_useState, 2),
115
+ type = _useState2[0],
116
+ setType = _useState2[1];
117
+
118
+ useEffect(function () {
119
+ setType(HANDLERS.toString(prop));
120
+ }, [prop]);
121
+ return /*#__PURE__*/React.createElement("code", null, type);
122
+ };
16
123
 
17
124
  var API = function API(props) {
18
125
  var _definition$propsConf;
@@ -37,18 +144,18 @@ var API = function API(props) {
37
144
  id: 'api.component.type'
38
145
  })), /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
39
146
  id: 'api.component.default'
40
- })))), /*#__PURE__*/React.createElement("tbody", null, definition && (_definition$propsConf = definition.propsConfig) !== null && _definition$propsConf !== void 0 && _definition$propsConf.properties ? Object.entries(definition.propsConfig.properties).map(function (_ref) {
147
+ })))), /*#__PURE__*/React.createElement("tbody", null, definition && (_definition$propsConf = definition.propsConfig) !== null && _definition$propsConf !== void 0 && _definition$propsConf.properties ? Object.entries(definition.propsConfig.properties).map(function (_ref4) {
41
148
  var _definition$propsConf2;
42
149
 
43
- var _ref2 = _slicedToArray(_ref, 2),
44
- name = _ref2[0],
45
- prop = _ref2[1];
150
+ var _ref5 = _slicedToArray(_ref4, 2),
151
+ name = _ref5[0],
152
+ prop = _ref5[1];
46
153
 
47
154
  return /*#__PURE__*/React.createElement("tr", {
48
155
  key: name
49
- }, /*#__PURE__*/React.createElement("td", null, name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, prop.type)), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf2 = definition.propsConfig.required) !== null && _definition$propsConf2 !== void 0 && _definition$propsConf2.includes(name) ? intl.formatMessage({
156
+ }, /*#__PURE__*/React.createElement("td", null, name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(APIType, prop)), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf2 = definition.propsConfig.required) !== null && _definition$propsConf2 !== void 0 && _definition$propsConf2.includes(name) ? intl.formatMessage({
50
157
  id: 'api.component.required'
51
- }) : prop.default || '--')));
158
+ }) : JSON.stringify(prop.default) || '--')));
52
159
  }) : /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
53
160
  colSpan: 4
54
161
  }, intl.formatMessage({