dumi 2.2.12 → 2.2.14
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.
|
Binary file
|
|
@@ -16,7 +16,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
16
16
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
17
|
import { useFullSidebarData, useLocale, useSiteData } from 'dumi';
|
|
18
18
|
import { useState } from 'react';
|
|
19
|
-
import { getLocaleClearPath } from "./useSidebarData";
|
|
19
|
+
import { getLocaleClearPath, getRouteParentPath } from "./useSidebarData";
|
|
20
20
|
import { getLocaleNav, pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
21
21
|
function genNavItem(meta, groups, activePath, link) {
|
|
22
22
|
return _objectSpread({
|
|
@@ -70,11 +70,14 @@ export var useNavData = function useNavData() {
|
|
|
70
70
|
var _ref6 = _slicedToArray(_ref5, 2),
|
|
71
71
|
link = _ref6[0],
|
|
72
72
|
groups = _ref6[1];
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
var clearPath = getLocaleClearPath(link.replace(/^\//, ''), locale);
|
|
74
|
+
var parentPath = link.replace(clearPath, function (s) {
|
|
75
|
+
return getRouteParentPath(s, {
|
|
76
|
+
is2LevelNav: is2LevelNav,
|
|
77
|
+
locale: locale
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
var isNestedNav = link.length > parentPath.length && is2LevelNav;
|
|
78
81
|
var _Object$values$reduce = Object.values(routes).reduce(function (ret, route) {
|
|
79
82
|
// find routes which within the nav path
|
|
80
83
|
if (route.path.startsWith(link.slice(1))) {
|
|
@@ -90,14 +93,14 @@ export var useNavData = function useNavData() {
|
|
|
90
93
|
if (isNestedNav) {
|
|
91
94
|
var _firstMeta$title, _ret$parentPath, _second$children;
|
|
92
95
|
// fallback to use parent path as 1-level nav title
|
|
93
|
-
(_firstMeta$title = firstMeta.title) !== null && _firstMeta$title !== void 0 ? _firstMeta$title : firstMeta.title = parentPath.
|
|
96
|
+
(_firstMeta$title = firstMeta.title) !== null && _firstMeta$title !== void 0 ? _firstMeta$title : firstMeta.title = parentPath.split('/').pop().replace(/^[a-z]/, function (s) {
|
|
94
97
|
return s.toUpperCase();
|
|
95
98
|
});
|
|
96
99
|
|
|
97
100
|
// handle nested nav item as parent children
|
|
98
101
|
var second = (_ret$parentPath = ret[parentPath]) !== null && _ret$parentPath !== void 0 ? _ret$parentPath : ret[parentPath] = genNavItem(firstMeta, groups, parentPath);
|
|
99
102
|
(_second$children = second.children) !== null && _second$children !== void 0 ? _second$children : second.children = [];
|
|
100
|
-
|
|
103
|
+
second.children.push(genNavItem(secondMeta, groups, link, groups[0].children[0].link));
|
|
101
104
|
} else {
|
|
102
105
|
// handle root nav item
|
|
103
106
|
ret[link] = genNavItem(firstMeta, groups, link, groups[0].children[0].link);
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type { ILocalesConfig, ISidebarGroup } from './types';
|
|
1
|
+
import type { ILocalesConfig, IRouteMeta, ISidebarGroup } from './types';
|
|
2
2
|
export declare const getLocaleClearPath: (routePath: string, locale: ILocalesConfig[0]) => string;
|
|
3
|
+
/**
|
|
4
|
+
* get parent path from route path
|
|
5
|
+
*/
|
|
6
|
+
export declare function getRouteParentPath(path: string, { meta, is2LevelNav, locale, }: {
|
|
7
|
+
meta?: IRouteMeta;
|
|
8
|
+
is2LevelNav: boolean;
|
|
9
|
+
locale: ILocalesConfig[0];
|
|
10
|
+
}): string;
|
|
3
11
|
/**
|
|
4
12
|
* hook for get sidebar data for all nav
|
|
5
13
|
*/
|
|
@@ -26,11 +26,12 @@ export var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
|
|
|
26
26
|
/**
|
|
27
27
|
* get parent path from route path
|
|
28
28
|
*/
|
|
29
|
-
function getRouteParentPath(path, _ref) {
|
|
30
|
-
var _meta$frontmatter$fil;
|
|
29
|
+
export function getRouteParentPath(path, _ref) {
|
|
31
30
|
var meta = _ref.meta,
|
|
32
|
-
is2LevelNav = _ref.is2LevelNav
|
|
33
|
-
|
|
31
|
+
is2LevelNav = _ref.is2LevelNav,
|
|
32
|
+
locale = _ref.locale;
|
|
33
|
+
var indexDocRegex = new RegExp("/index(\\.".concat(locale.id, ")?.md$"));
|
|
34
|
+
var isIndexDocRoute = (meta === null || meta === void 0 ? void 0 : meta.frontmatter.filename) && indexDocRegex.test(meta.frontmatter.filename) && !meta._atom_route && is2LevelNav;
|
|
34
35
|
var paths = path.split('/')
|
|
35
36
|
// strip end slash
|
|
36
37
|
.filter(Boolean);
|
|
@@ -74,7 +75,8 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
74
75
|
var parentPath = "/".concat(route.path.replace(clearPath, function (s) {
|
|
75
76
|
return getRouteParentPath(s, {
|
|
76
77
|
is2LevelNav: is2LevelNav,
|
|
77
|
-
meta: route.meta
|
|
78
|
+
meta: route.meta,
|
|
79
|
+
locale: locale
|
|
78
80
|
});
|
|
79
81
|
}));
|
|
80
82
|
var _pickRouteSortMeta = pickRouteSortMeta({
|
|
@@ -227,7 +229,8 @@ export var useSidebarData = function useSidebarData() {
|
|
|
227
229
|
var parentPath = clearPath ? pathname.replace(clearPath, function (s) {
|
|
228
230
|
return getRouteParentPath(s, {
|
|
229
231
|
is2LevelNav: is2LevelNav,
|
|
230
|
-
meta: meta
|
|
232
|
+
meta: meta,
|
|
233
|
+
locale: locale
|
|
231
234
|
});
|
|
232
235
|
}) : pathname;
|
|
233
236
|
return parentPath ? sidebar[parentPath] : [];
|
package/dist/features/routes.js
CHANGED
|
@@ -39,9 +39,6 @@ var import_path = __toESM(require("path"));
|
|
|
39
39
|
var import_pluralize = require("pluralize");
|
|
40
40
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
41
41
|
var CTX_LAYOUT_ID = "dumi-context-layout";
|
|
42
|
-
var ALIAS_THEME_TMP = "@/dumi__theme";
|
|
43
|
-
var ALIAS_LAYOUTS_LOCAL = "@/dumi__theme__layouts";
|
|
44
|
-
var ALIAS_INTERNAL_PAGES = "@/dumi__pages";
|
|
45
42
|
function normalizeDocDir(docDir) {
|
|
46
43
|
return typeof docDir === "object" ? docDir : { dir: docDir };
|
|
47
44
|
}
|
|
@@ -80,13 +77,6 @@ function flatRoute(route, docLayoutId) {
|
|
|
80
77
|
) : route.absPath.slice(1);
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
function getAliasLayoutFile({
|
|
84
|
-
source,
|
|
85
|
-
specifier
|
|
86
|
-
}) {
|
|
87
|
-
const alias = source.includes("/.dumi/theme/layouts/") ? ALIAS_LAYOUTS_LOCAL : `${ALIAS_THEME_TMP}/layouts`;
|
|
88
|
-
return `${alias}/${specifier}`;
|
|
89
|
-
}
|
|
90
80
|
var routes_default = (api) => {
|
|
91
81
|
api.describe({ key: "dumi:routes" });
|
|
92
82
|
api.addTmpGenerateWatcherPaths(
|
|
@@ -104,15 +94,6 @@ var routes_default = (api) => {
|
|
|
104
94
|
memo.resolve[key] = [];
|
|
105
95
|
});
|
|
106
96
|
}
|
|
107
|
-
memo.alias[ALIAS_THEME_TMP] = (0, import_plugin_utils.winPath)(
|
|
108
|
-
import_path.default.join(api.paths.absTmpPath, "dumi/theme")
|
|
109
|
-
);
|
|
110
|
-
memo.alias[ALIAS_LAYOUTS_LOCAL] = (0, import_plugin_utils.winPath)(
|
|
111
|
-
import_path.default.join(api.cwd, import_constants.LOCAL_THEME_DIR, "layouts")
|
|
112
|
-
);
|
|
113
|
-
memo.alias[ALIAS_INTERNAL_PAGES] = (0, import_plugin_utils.winPath)(
|
|
114
|
-
import_path.default.join(__dirname, "../client/pages")
|
|
115
|
-
);
|
|
116
97
|
return memo;
|
|
117
98
|
});
|
|
118
99
|
api.modifyRoutes((oRoutes) => {
|
|
@@ -141,10 +122,7 @@ var routes_default = (api) => {
|
|
|
141
122
|
routes[DocLayout.specifier] = {
|
|
142
123
|
id: DocLayout.specifier,
|
|
143
124
|
path: "/",
|
|
144
|
-
|
|
145
|
-
// because umi will generate chunk name from file path
|
|
146
|
-
// but source may too long in pnpm/monorepo project
|
|
147
|
-
file: getAliasLayoutFile(DocLayout),
|
|
125
|
+
file: DocLayout.source,
|
|
148
126
|
parentId: lastLayoutId,
|
|
149
127
|
absPath: "/",
|
|
150
128
|
isLayout: true
|
|
@@ -155,7 +133,7 @@ var routes_default = (api) => {
|
|
|
155
133
|
routes[DemoLayout.specifier] = {
|
|
156
134
|
id: DemoLayout.specifier,
|
|
157
135
|
path: "/",
|
|
158
|
-
file:
|
|
136
|
+
file: DemoLayout.source,
|
|
159
137
|
parentId: lastLayoutId,
|
|
160
138
|
absPath: "/",
|
|
161
139
|
isLayout: true
|
|
@@ -224,7 +202,7 @@ var routes_default = (api) => {
|
|
|
224
202
|
path: "*",
|
|
225
203
|
absPath: "/*",
|
|
226
204
|
parentId: docLayoutId,
|
|
227
|
-
file:
|
|
205
|
+
file: require.resolve("../client/pages/404")
|
|
228
206
|
};
|
|
229
207
|
}
|
|
230
208
|
routes["demo-render"] = {
|
|
@@ -232,7 +210,7 @@ var routes_default = (api) => {
|
|
|
232
210
|
path: `${import_constants.SP_ROUTE_PREFIX}demos/:id`,
|
|
233
211
|
absPath: `/${import_constants.SP_ROUTE_PREFIX}demos/:id`,
|
|
234
212
|
parentId: demoLayoutId,
|
|
235
|
-
file:
|
|
213
|
+
file: require.resolve("../client/pages/Demo")
|
|
236
214
|
};
|
|
237
215
|
return routes;
|
|
238
216
|
});
|
|
@@ -240,14 +218,14 @@ var routes_default = (api) => {
|
|
|
240
218
|
const layouts = [
|
|
241
219
|
{
|
|
242
220
|
id: CTX_LAYOUT_ID,
|
|
243
|
-
file: `${
|
|
221
|
+
file: `${api.paths.absTmpPath}/dumi/theme/ContextWrapper`
|
|
244
222
|
}
|
|
245
223
|
];
|
|
246
224
|
const { GlobalLayout } = api.service.themeData.layouts;
|
|
247
225
|
if (GlobalLayout) {
|
|
248
226
|
layouts.unshift({
|
|
249
227
|
id: GlobalLayout.specifier,
|
|
250
|
-
file:
|
|
228
|
+
file: GlobalLayout.source
|
|
251
229
|
});
|
|
252
230
|
}
|
|
253
231
|
return layouts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.14",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
"@swc/core": "1.3.72",
|
|
83
83
|
"@types/hast": "^2.3.5",
|
|
84
84
|
"@types/mdast": "^3.0.12",
|
|
85
|
-
"@umijs/bundler-utils": "^4.0.
|
|
86
|
-
"@umijs/core": "^4.0.
|
|
87
|
-
"@umijs/utils": "^4.0.
|
|
85
|
+
"@umijs/bundler-utils": "^4.0.84",
|
|
86
|
+
"@umijs/core": "^4.0.84",
|
|
87
|
+
"@umijs/utils": "^4.0.84",
|
|
88
88
|
"animated-scroll-to": "^2.3.0",
|
|
89
89
|
"classnames": "2.3.2",
|
|
90
90
|
"codesandbox": "^2.2.3",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"remark-rehype": "^10.1.0",
|
|
132
132
|
"sass": "^1.64.1",
|
|
133
133
|
"sitemap": "^7.1.1",
|
|
134
|
-
"umi": "^4.0.
|
|
134
|
+
"umi": "^4.0.84",
|
|
135
135
|
"unified": "^10.1.2",
|
|
136
136
|
"unist-util-visit": "^4.1.2",
|
|
137
137
|
"unist-util-visit-parents": "^5.1.3",
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
"@types/pluralize": "^0.0.30",
|
|
152
152
|
"@types/react": "^18.2.17",
|
|
153
153
|
"@types/react-copy-to-clipboard": "^5.0.4",
|
|
154
|
-
"@umijs/lint": "^4.0.
|
|
154
|
+
"@umijs/lint": "^4.0.84",
|
|
155
155
|
"@umijs/plugins": "4.0.32",
|
|
156
156
|
"dumi-theme-mobile": "workspace:*",
|
|
157
157
|
"eslint": "^8.46.0",
|