dumi 2.4.0-alpha.1 → 2.4.0-alpha.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.
- package/dist/client/theme-api/useNavData.js +5 -1
- package/dist/client/theme-api/useRouteMeta.js +6 -0
- package/dist/features/compile/index.js +8 -5
- package/dist/features/derivative.js +2 -2
- package/dist/features/theme/index.js +3 -5
- package/dist/templates/meta/exports.ts.tpl +13 -7
- package/package.json +7 -7
|
@@ -109,9 +109,13 @@ export var useNavData = function useNavData() {
|
|
|
109
109
|
}, {}));
|
|
110
110
|
data.forEach(function (item, i) {
|
|
111
111
|
var _item$children;
|
|
112
|
+
// item.link => the parent link is not in routes, but has children, will use parent.title or children.title
|
|
112
113
|
if (!item.link && ((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) === 1) {
|
|
113
114
|
// hoist nav item if only one child
|
|
114
|
-
|
|
115
|
+
var first = item.children[0];
|
|
116
|
+
data[i] = _objectSpread(_objectSpread({}, first), {}, {
|
|
117
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || first.title
|
|
118
|
+
});
|
|
115
119
|
} else if (item.children) {
|
|
116
120
|
// sort nav item children by order or title
|
|
117
121
|
item.children.sort(sidebarDataComparer);
|
|
@@ -4,6 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import deepmerge from 'deepmerge';
|
|
7
8
|
import { getRouteMetaById, matchRoutes, useAppData, useLocation, useRouteData } from 'dumi';
|
|
8
9
|
import { useCallback, useState } from 'react';
|
|
9
10
|
import { useIsomorphicLayoutEffect } from "./utils";
|
|
@@ -26,6 +27,11 @@ function getCachedRouteMeta(route) {
|
|
|
26
27
|
var _ref, _ref$key;
|
|
27
28
|
(_ref$key = (_ref = meta)[key]) !== null && _ref$key !== void 0 ? _ref$key : _ref[key] = route.meta[key];
|
|
28
29
|
});
|
|
30
|
+
meta.frontmatter = deepmerge(meta.frontmatter, route.meta.frontmatter, {
|
|
31
|
+
arrayMerge: function arrayMerge(_destinationArray, sourceArray) {
|
|
32
|
+
return sourceArray;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
29
35
|
}
|
|
30
36
|
return meta;
|
|
31
37
|
};
|
|
@@ -152,11 +152,14 @@ var compile_default = (api) => {
|
|
|
152
152
|
return memo;
|
|
153
153
|
});
|
|
154
154
|
api.modifyConfig((memo) => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
memo.mako.
|
|
158
|
-
|
|
159
|
-
|
|
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
|
+
];
|
|
160
163
|
}
|
|
161
164
|
return memo;
|
|
162
165
|
});
|
|
@@ -91,8 +91,8 @@ var derivative_default = (api) => {
|
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
93
|
(0, import_assert.default)(
|
|
94
|
-
!api.config.ssr || api.config.ssr.builder === "webpack",
|
|
95
|
-
"Only `webpack` builder is supported in SSR mode!"
|
|
94
|
+
!api.config.ssr || api.config.ssr.builder === "webpack" || api.config.ssr.builder === "mako",
|
|
95
|
+
"Only `webpack` and mako` builder is supported in SSR mode!"
|
|
96
96
|
);
|
|
97
97
|
(0, import_assert.default)(
|
|
98
98
|
((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0 && api.config.cssLoaderModules === void 0,
|
|
@@ -386,17 +386,15 @@ export default DumiLoading;
|
|
|
386
386
|
});
|
|
387
387
|
api.addEntryCodeAhead(() => {
|
|
388
388
|
const { prefersColor } = api.config.themeConfig;
|
|
389
|
-
if (typeof window === "undefined")
|
|
390
|
-
return "";
|
|
391
389
|
if (prefersColor.switch === false && prefersColor.default !== "auto") {
|
|
392
|
-
return `document.documentElement.setAttribute('${import_constants.PREFERS_COLOR_ATTR}', '${prefersColor.default}');`;
|
|
390
|
+
return `typeof document !== 'undefined' && document.documentElement.setAttribute('${import_constants.PREFERS_COLOR_ATTR}', '${prefersColor.default}');`;
|
|
393
391
|
}
|
|
394
392
|
return `(function () {
|
|
395
393
|
var cache = typeof navigator !== 'undefined' && navigator.cookieEnabled && typeof window.localStorage !== 'undefined' && localStorage.getItem('dumi:prefers-color') || '${prefersColor.default}';
|
|
396
|
-
var isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
394
|
+
var isDark = typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
397
395
|
var enums = ['light', 'dark', 'auto'];
|
|
398
396
|
|
|
399
|
-
document.documentElement.setAttribute(
|
|
397
|
+
typeof document !== 'undefined' && document.documentElement.setAttribute(
|
|
400
398
|
'${import_constants.PREFERS_COLOR_ATTR}',
|
|
401
399
|
cache === enums[2]
|
|
402
400
|
? (isDark ? enums[1] : enums[0])
|
|
@@ -138,15 +138,17 @@ 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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
frontmatter,
|
|
147
|
-
toc: toc,
|
|
141
|
+
? IRouteMeta
|
|
142
|
+
: Promise<IRouteMeta> {
|
|
143
|
+
const routeMeta: IRouteMeta = {
|
|
144
|
+
frontmatter: {},
|
|
145
|
+
toc: [],
|
|
148
146
|
texts: [],
|
|
149
147
|
};
|
|
148
|
+
if (filesMeta[id]) {
|
|
149
|
+
const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
|
|
150
|
+
routeMeta.frontmatter = frontmatter;
|
|
151
|
+
routeMeta.toc = toc;
|
|
150
152
|
|
|
151
153
|
if (opts?.syncOnly) {
|
|
152
154
|
if (tabs) {
|
|
@@ -174,6 +176,10 @@ export function getRouteMetaById<T extends { syncOnly?: boolean }>(
|
|
|
174
176
|
});
|
|
175
177
|
}
|
|
176
178
|
}
|
|
179
|
+
if (opts?.syncOnly) {
|
|
180
|
+
return routeMeta;
|
|
181
|
+
}
|
|
182
|
+
return Promise.resolve(routeMeta);
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.4.0-alpha.
|
|
3
|
+
"version": "2.4.0-alpha.11",
|
|
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.
|
|
69
|
-
"@umijs/core": "4.2.6-alpha.
|
|
70
|
-
"@umijs/utils": "4.2.6-alpha.
|
|
68
|
+
"@umijs/bundler-utils": "4.2.6-alpha.22",
|
|
69
|
+
"@umijs/core": "4.2.6-alpha.22",
|
|
70
|
+
"@umijs/utils": "4.2.6-alpha.22",
|
|
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.
|
|
122
|
+
"umi": "4.2.6-alpha.22",
|
|
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.
|
|
145
|
+
"@umijs/lint": "4.2.6-alpha.22",
|
|
146
146
|
"@umijs/plugins": "4.0.32",
|
|
147
147
|
"codesandbox-import-utils": "^2.2.3",
|
|
148
148
|
"eslint": "^8.46.0",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
"typescript": "~5.0.4",
|
|
164
164
|
"vitest": "^0.33.0",
|
|
165
165
|
"zx": "^7.2.3",
|
|
166
|
-
"dumi-theme-mobile": "2.3.
|
|
166
|
+
"dumi-theme-mobile": "2.3.5"
|
|
167
167
|
},
|
|
168
168
|
"peerDependencies": {
|
|
169
169
|
"react": ">=16.8",
|