dumi 2.4.0-alpha.9 → 2.4.0

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.
@@ -64,4 +64,4 @@ options: RunLoaderOption,
64
64
  callback: (err: NodeJS.ErrnoException | null, result: RunLoaderResult) => any,
65
65
  ): void;
66
66
 
67
- export { }
67
+ export { }
@@ -41,14 +41,19 @@ function getCachedRouteMeta(route) {
41
41
  var proxyGetter = function proxyGetter(target, prop) {
42
42
  if (ASYNC_META_PROPS.includes(prop)) {
43
43
  if (!asyncCache.get(cacheKey)) {
44
+ var routeMetaPromise = getRouteMetaById(route.id);
44
45
  // load async meta then replace cache
45
- asyncCache.set(cacheKey, getRouteMetaById(route.id).then(function (full) {
46
- return cache.set(cacheKey, merge(full)).get(cacheKey);
47
- }));
46
+ if (routeMetaPromise) {
47
+ asyncCache.set(cacheKey, routeMetaPromise.then(function (full) {
48
+ return cache.set(cacheKey, merge(full)).get(cacheKey);
49
+ }));
50
+ }
48
51
  }
49
-
50
52
  // throw promise to trigger suspense
51
- throw asyncCache.get(cacheKey);
53
+ var currentCache = asyncCache.get(cacheKey);
54
+ if (currentCache) {
55
+ throw currentCache;
56
+ }
52
57
  }
53
58
  return target[prop];
54
59
  };
@@ -151,17 +151,20 @@ var compile_default = (api) => {
151
151
  }
152
152
  return memo;
153
153
  });
154
- api.modifyConfig((memo) => {
155
- var _a;
156
- if (memo.mako || ((_a = memo.ssr) == null ? void 0 : _a.builder) === "mako") {
157
- memo.mako ?? (memo.mako = {});
158
- memo.mako.plugins = [
159
- {
160
- load: (0, import_makoHooks.getLoadHook)(api)
161
- }
162
- ];
154
+ api.modifyConfig({
155
+ before: "mako",
156
+ fn: (memo) => {
157
+ var _a;
158
+ if (memo.mako || ((_a = memo.ssr) == null ? void 0 : _a.builder) === "mako") {
159
+ memo.mako ?? (memo.mako = {});
160
+ memo.mako.plugins = [
161
+ {
162
+ load: (0, import_makoHooks.getLoadHook)(api)
163
+ }
164
+ ];
165
+ }
166
+ return memo;
163
167
  }
164
- return memo;
165
168
  });
166
169
  };
167
170
  // Annotate the CommonJS export names for ESM import in node:
@@ -136,6 +136,10 @@ var getLoadHook = (api) => {
136
136
  return await customRunLoaders({
137
137
  resource: filePath,
138
138
  loaders: [
139
+ {
140
+ loader: require.resolve("../../loaders/post-raw"),
141
+ options: {}
142
+ },
139
143
  {
140
144
  loader: require.resolve("raw-loader"),
141
145
  options: {}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * loader for mako dumi-raw watch-parent
3
+ */
4
+ export default function postRawLoader(this: any, raw: string): string;
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/loaders/post-raw/index.ts
20
+ var post_raw_exports = {};
21
+ __export(post_raw_exports, {
22
+ default: () => postRawLoader
23
+ });
24
+ module.exports = __toCommonJS(post_raw_exports);
25
+ function postRawLoader(raw) {
26
+ return `
27
+ import '${this.resourcePath}?watch=parent';
28
+ ${raw};
29
+ `;
30
+ }
@@ -138,48 +138,51 @@ export function getRouteMetaById<T extends { syncOnly?: boolean }>(
138
138
  id: string,
139
139
  opts?: T,
140
140
  ): T extends { syncOnly: true }
141
- ? IRouteMeta
142
- : Promise<IRouteMeta> {
143
- const routeMeta: IRouteMeta = {
144
- frontmatter: {},
145
- toc: [],
146
- texts: [],
147
- };
141
+ ? IRouteMeta | undefined
142
+ : Promise<IRouteMeta> | undefined {
148
143
  if (filesMeta[id]) {
149
144
  const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
150
- routeMeta.frontmatter = frontmatter;
151
- routeMeta.toc = toc;
152
-
153
- if (opts?.syncOnly) {
154
- if (tabs) {
155
- routeMeta.tabs = tabs.map((tabId) =>
156
- genTab(tabId, getRouteMetaById(tabId, opts)),
157
- );
158
- }
159
-
160
- return routeMeta;
161
- } else {
162
- return new Promise(async (resolve) => {
163
- if (textGetter) {
164
- ({ texts: routeMeta.texts } = await textGetter());
165
- }
145
+ const routeMeta: IRouteMeta = {
146
+ frontmatter,
147
+ toc,
148
+ texts: [],
149
+ };
150
+ if (filesMeta[id]) {
151
+ const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
152
+ routeMeta.frontmatter = frontmatter;
153
+ routeMeta.toc = toc;
166
154
 
155
+ if (opts?.syncOnly) {
167
156
  if (tabs) {
168
- routeMeta.tabs = await Promise.all(
169
- tabs.map(async (tabId) =>
170
- genTab(tabId, await getRouteMetaById(tabId, opts)),
171
- ),
157
+ routeMeta.tabs = tabs.map((tabId) =>
158
+ genTab(tabId, getRouteMetaById(tabId, opts)),
172
159
  );
173
160
  }
174
161
 
175
- resolve(routeMeta);
176
- });
162
+ return routeMeta;
163
+ } else {
164
+ return new Promise(async (resolve) => {
165
+ if (textGetter) {
166
+ ({ texts: routeMeta.texts } = await textGetter());
167
+ }
168
+
169
+ if (tabs) {
170
+ routeMeta.tabs = await Promise.all(
171
+ tabs.map(async (tabId) =>
172
+ genTab(tabId, await getRouteMetaById(tabId, opts)),
173
+ ),
174
+ );
175
+ }
176
+
177
+ resolve(routeMeta);
178
+ });
179
+ }
180
+ }
181
+ if (opts?.syncOnly) {
182
+ return routeMeta;
177
183
  }
184
+ return Promise.resolve(routeMeta);
178
185
  }
179
- if (opts?.syncOnly) {
180
- return routeMeta;
181
- }
182
- return Promise.resolve(routeMeta);
183
186
  }
184
187
 
185
188
  /**
package/dist/utils.js CHANGED
@@ -146,7 +146,7 @@ function lastSlash(str) {
146
146
  }
147
147
  function componentToChunkName(component, cwdPath = "/") {
148
148
  const cwd = (0, import_plugin_utils.winPath)(cwdPath);
149
- return typeof component === "string" ? component.replace(
149
+ return typeof component === "string" ? (0, import_plugin_utils.winPath)(component).replace(
150
150
  new RegExp(
151
151
  `^(${// match app cwd first
152
152
  import_plugin_utils.lodash.escapeRegExp(lastSlash(cwd))})`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.0-alpha.9",
3
+ "version": "2.4.0",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -65,9 +65,9 @@
65
65
  "@swc/core": "1.4.2",
66
66
  "@types/hast": "^2.3.5",
67
67
  "@types/mdast": "^3.0.12",
68
- "@umijs/bundler-utils": "4.2.6-alpha.20",
69
- "@umijs/core": "4.2.6-alpha.20",
70
- "@umijs/utils": "4.2.6-alpha.20",
68
+ "@umijs/bundler-utils": "^4.3.0",
69
+ "@umijs/core": "^4.3.0",
70
+ "@umijs/utils": "^4.3.0",
71
71
  "animated-scroll-to": "^2.3.0",
72
72
  "classnames": "2.3.2",
73
73
  "codesandbox": "^2.2.3",
@@ -119,7 +119,7 @@
119
119
  "sass": "^1.64.1",
120
120
  "sitemap": "^7.1.1",
121
121
  "sucrase": "^3.34.0",
122
- "umi": "4.2.6-alpha.20",
122
+ "umi": "^4.3.0",
123
123
  "unified": "^10.1.2",
124
124
  "unist-util-visit": "^4.1.2",
125
125
  "unist-util-visit-parents": "^5.1.3",
@@ -142,7 +142,7 @@
142
142
  "@types/react": "^18.2.17",
143
143
  "@types/react-copy-to-clipboard": "^5.0.4",
144
144
  "@types/react-dom": "^18.2.7",
145
- "@umijs/lint": "4.2.6-alpha.20",
145
+ "@umijs/lint": "^4.3.0",
146
146
  "@umijs/plugins": "4.0.32",
147
147
  "codesandbox-import-utils": "^2.2.3",
148
148
  "eslint": "^8.46.0",
@@ -156,8 +156,8 @@
156
156
  "prettier": "^2.8.8",
157
157
  "prettier-plugin-organize-imports": "^3.2.3",
158
158
  "prettier-plugin-packagejson": "^2.4.5",
159
- "react": "^18.2.0",
160
- "react-dom": "^18.2.0",
159
+ "react": "^18.3.1",
160
+ "react-dom": "^18.3.1",
161
161
  "stylelint": "^15.10.2",
162
162
  "ts-node": "^10.9.1",
163
163
  "typescript": "~5.0.4",
@@ -262,7 +262,7 @@ var API = function API(props) {
262
262
  id: 'api.component.description'
263
263
  })), /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
264
264
  id: 'api.component.type'
265
- })), props.type === 'props' && /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
265
+ })), type === 'props' && /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
266
266
  id: 'api.component.default'
267
267
  })))), /*#__PURE__*/React.createElement("tbody", null, Object.keys(properties).length ? Object.entries(properties).map(function (_ref9) {
268
268
  var _definition$propsConf;
@@ -274,7 +274,7 @@ var API = function API(props) {
274
274
  }, /*#__PURE__*/React.createElement("td", null, releaseInfo[name] ? /*#__PURE__*/React.createElement(APIRelease, {
275
275
  name: name,
276
276
  info: releaseInfo[name]
277
- }) : name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(APIType, prop)), props.type === 'props' && /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf = definition.propsConfig.required) !== null && _definition$propsConf !== void 0 && _definition$propsConf.includes(name) ? intl.formatMessage({
277
+ }) : name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(APIType, prop)), type === 'props' && /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf = definition.propsConfig.required) !== null && _definition$propsConf !== void 0 && _definition$propsConf.includes(name) ? intl.formatMessage({
278
278
  id: 'api.component.required'
279
279
  }) : JSON.stringify(prop.default) || '--')));
280
280
  }) : /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
@@ -38,14 +38,23 @@ function getTreeFromList(nodes) {
38
38
  }
39
39
  case 'li':
40
40
  {
41
- var liLeafs = getTreeFromList(node.props.children, key);
41
+ var _node$props$children, _node$props$children$;
42
+ var hasEmptyUl = (_node$props$children = node.props.children) === null || _node$props$children === void 0 ? void 0 : (_node$props$children$ = _node$props$children.some) === null || _node$props$children$ === void 0 ? void 0 : _node$props$children$.call(_node$props$children, function (child) {
43
+ var _child$props$children;
44
+ return child.type === 'ul' && !((_child$props$children = child.props.children) !== null && _child$props$children !== void 0 && _child$props$children.length);
45
+ });
46
+ var title = [].concat(node.props.children).filter(function (child) {
47
+ return child.type !== 'ul';
48
+ });
49
+ var children = hasEmptyUl ? [] : getTreeFromList(node.props.children, key);
42
50
  data.push({
43
- title: [].concat(node.props.children).filter(function (child) {
44
- return child.type !== 'ul';
45
- }),
51
+ title: title,
46
52
  key: key,
47
- children: liLeafs,
48
- isLeaf: !liLeafs.length
53
+ children: children,
54
+ isLeaf: !hasEmptyUl && !children.length,
55
+ switcherIcon: hasEmptyUl ? /*#__PURE__*/React.createElement("span", {
56
+ className: "tree-switcher-leaf-line"
57
+ }) : undefined
49
58
  });
50
59
  break;
51
60
  }
@@ -65,8 +74,10 @@ var useListToTree = function useListToTree(nodes) {
65
74
  return tree;
66
75
  };
67
76
  var getIcon = function getIcon(props) {
77
+ var _data$children;
68
78
  var isLeaf = props.isLeaf,
69
- expanded = props.expanded;
79
+ expanded = props.expanded,
80
+ data = props.data;
70
81
  if (isLeaf) {
71
82
  return /*#__PURE__*/React.createElement("span", {
72
83
  className: "dumi-default-tree-icon"
@@ -74,13 +85,13 @@ var getIcon = function getIcon(props) {
74
85
  fill: "currentColor"
75
86
  }));
76
87
  }
77
- return expanded ? /*#__PURE__*/React.createElement("span", {
88
+ return !expanded || !(data !== null && data !== void 0 && (_data$children = data.children) !== null && _data$children !== void 0 && _data$children.length) ? /*#__PURE__*/React.createElement("span", {
78
89
  className: "dumi-default-tree-icon"
79
- }, /*#__PURE__*/React.createElement(FolderOpenOutlined, {
90
+ }, /*#__PURE__*/React.createElement(FolderOutlined, {
80
91
  fill: "currentColor"
81
92
  })) : /*#__PURE__*/React.createElement("span", {
82
93
  className: "dumi-default-tree-icon"
83
- }, /*#__PURE__*/React.createElement(FolderOutlined, {
94
+ }, /*#__PURE__*/React.createElement(FolderOpenOutlined, {
84
95
  fill: "currentColor"
85
96
  }));
86
97
  };
@@ -146,8 +157,10 @@ export default (function (props) {
146
157
  var data = useListToTree(props.children);
147
158
  var treeRef = /*#__PURE__*/createRef();
148
159
  var onClick = function onClick(event, node) {
160
+ var _node$children;
149
161
  var isLeaf = node.isLeaf;
150
- if (isLeaf || event.shiftKey || event.metaKey || event.ctrlKey) {
162
+ var isEmptyUl = !isLeaf && !((_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length);
163
+ if (isLeaf || isEmptyUl || event.shiftKey || event.metaKey || event.ctrlKey) {
151
164
  return;
152
165
  }
153
166
  treeRef.current.onNodeExpand(event, node);