dumi 2.2.6 → 2.2.8
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 +2 -1
- package/dist/client/theme-api/useSidebarData.d.ts +2 -1
- package/dist/client/theme-api/useSidebarData.js +1 -1
- package/dist/features/derivative.js +36 -12
- package/dist/features/locales.js +12 -2
- package/dist/loaders/markdown/transformer/rehypeRaw.js +9 -6
- package/package.json +1 -1
- package/theme-default/builtins/API/index.js +2 -0
- package/theme-default/layouts/DocLayout/index.js +1 -1
- package/theme-default/slots/ColorSwitch/index.less +5 -4
- package/theme-default/slots/Toc/index.js +1 -1
|
@@ -16,6 +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
20
|
import { getLocaleNav, pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
20
21
|
function genNavItem(meta, groups, activePath, link) {
|
|
21
22
|
return _objectSpread({
|
|
@@ -69,7 +70,7 @@ export var useNavData = function useNavData() {
|
|
|
69
70
|
var _ref6 = _slicedToArray(_ref5, 2),
|
|
70
71
|
link = _ref6[0],
|
|
71
72
|
groups = _ref6[1];
|
|
72
|
-
var _ref7 = link.match(/^(\/[^/]+)([^]+)?$/),
|
|
73
|
+
var _ref7 = "/".concat(getLocaleClearPath(link.replace(/^\//, ''), locale)).match(/^(\/[^/]+)([^]+)?$/),
|
|
73
74
|
_ref8 = _slicedToArray(_ref7, 3),
|
|
74
75
|
parentPath = _ref8[1],
|
|
75
76
|
restPath = _ref8[2];
|
|
@@ -19,7 +19,7 @@ import { useLocale, useLocation, useRouteMeta, useSiteData } from 'dumi';
|
|
|
19
19
|
import { useState } from 'react';
|
|
20
20
|
import { pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
21
21
|
var DEFAULT_GROUP_STUB_TITLE = '$default-group-title';
|
|
22
|
-
var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
|
|
22
|
+
export var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
|
|
23
23
|
return 'base' in locale ? routePath.replace(locale.base.slice(1), '').replace(/^\//, '') : routePath;
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -65,7 +65,7 @@ function safeExcludeInMFSU(api, excludes) {
|
|
|
65
65
|
var derivative_default = (api) => {
|
|
66
66
|
api.describe({ key: "dumi:derivative" });
|
|
67
67
|
api.onCheck(() => {
|
|
68
|
-
var _a, _b, _c;
|
|
68
|
+
var _a, _b, _c, _d, _e;
|
|
69
69
|
[
|
|
70
70
|
"clientLoader",
|
|
71
71
|
"deadCode",
|
|
@@ -113,23 +113,47 @@ var derivative_default = (api) => {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
try {
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
const tsconfigPath = import_path.default.join(api.cwd, "tsconfig.json");
|
|
117
|
+
const tsconfig = require(tsconfigPath);
|
|
118
|
+
const configFileName = (_b = api.service.configManager) == null ? void 0 : _b.mainConfigFile;
|
|
119
|
+
const expected = [];
|
|
120
|
+
if (configFileName && /[\\/]\.[^\\/]+\.ts$/.test(configFileName)) {
|
|
121
|
+
expected.push((0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, configFileName)));
|
|
122
|
+
}
|
|
123
|
+
[
|
|
124
|
+
(_c = api.appData.globalJS) == null ? void 0 : _c[0],
|
|
125
|
+
api.appData.globalLoading,
|
|
126
|
+
(_d = api.appData.appJS) == null ? void 0 : _d.path
|
|
127
|
+
].forEach((file) => {
|
|
128
|
+
if (file && /([\\/])\.dumi\1.*\.tsx?$/.test(file)) {
|
|
129
|
+
expected.push((0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, file)));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (import_fs.default.existsSync(import_path.default.join(api.cwd, import_constants.LOCAL_THEME_DIR))) {
|
|
133
|
+
expected.push(`${import_constants.LOCAL_THEME_DIR}/**/*`);
|
|
124
134
|
}
|
|
125
|
-
if (
|
|
135
|
+
if ((_e = tsconfig.include) == null ? void 0 : _e.includes(".dumi/**/*")) {
|
|
136
|
+
tsconfig.include.splice(
|
|
137
|
+
tsconfig.include.indexOf(".dumi/**/*"),
|
|
138
|
+
1,
|
|
139
|
+
...expected.filter((f) => !tsconfig.include.includes(f))
|
|
140
|
+
);
|
|
141
|
+
import_fs.default.writeFileSync(
|
|
142
|
+
tsconfigPath,
|
|
143
|
+
JSON.stringify(tsconfig, null, 2),
|
|
144
|
+
"utf-8"
|
|
145
|
+
);
|
|
146
|
+
import_plugin_utils.logger.warn(
|
|
147
|
+
"tsconfig.json `include` option has been patched automatically, please check and commit it."
|
|
148
|
+
);
|
|
149
|
+
} else if (!expected.every((f) => {
|
|
126
150
|
var _a2;
|
|
127
151
|
return (_a2 = tsconfig.include) == null ? void 0 : _a2.includes(f);
|
|
128
152
|
})) {
|
|
129
153
|
import_plugin_utils.logger.warn(
|
|
130
154
|
`Please append ${expected.map((e) => `\`${e}\``).join(
|
|
131
|
-
"
|
|
132
|
-
)} into \`include\` option of
|
|
155
|
+
", "
|
|
156
|
+
)} into \`include\` option of tsconfig.json, to make sure the type prompt works for ${expected.length > 1 ? "them" : "it"}.`
|
|
133
157
|
);
|
|
134
158
|
}
|
|
135
159
|
} catch {
|
package/dist/features/locales.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(locales_exports, {
|
|
|
32
32
|
default: () => locales_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(locales_exports);
|
|
35
|
+
var import_constants = require("../constants");
|
|
35
36
|
var import_path = __toESM(require("path"));
|
|
36
37
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
37
38
|
var locales_default = (api) => {
|
|
@@ -125,15 +126,24 @@ const cache = createIntlCache();
|
|
|
125
126
|
|
|
126
127
|
const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
|
|
127
128
|
const getIntl = useCallback(() => {
|
|
129
|
+
const base = "${api.config.base.replace(/\/$/, "")}"
|
|
128
130
|
const matched = locales.slice().reverse().find((locale) => (
|
|
129
131
|
'suffix' in locale
|
|
130
132
|
// suffix mode
|
|
131
133
|
? history.location.pathname.replace(/([^/])\\/$/, '$1').endsWith(locale.suffix)
|
|
132
134
|
// base mode
|
|
133
135
|
: history.location.pathname.replace(/([^/])\\/$/, '$1')
|
|
134
|
-
.startsWith(
|
|
136
|
+
.startsWith(base + locale.base)
|
|
135
137
|
));
|
|
136
|
-
|
|
138
|
+
let locale = matched ? matched.id : locales[0].id;
|
|
139
|
+
// using query on demos
|
|
140
|
+
if(history.location.pathname.startsWith(base + '/${import_constants.SP_ROUTE_PREFIX}demos')){
|
|
141
|
+
const params = new URLSearchParams(history.location.search);
|
|
142
|
+
// match the locale of the query
|
|
143
|
+
if (params.get('locale')){
|
|
144
|
+
locale = params.get('locale');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
137
147
|
const localeMessages = messages[locale] || {};
|
|
138
148
|
|
|
139
149
|
// append internal message, for use intl as string template util
|
|
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(rehypeRaw_exports);
|
|
|
35
35
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
36
36
|
var raw;
|
|
37
37
|
var visit;
|
|
38
|
-
var COMPONENT_NAME_REGEX =
|
|
38
|
+
var COMPONENT_NAME_REGEX = /(<)([A-Z][a-zA-Z\d]*)([\s|>])/g;
|
|
39
39
|
var COMPONENT_PROP_REGEX = /\s[a-z][a-z\d]*[A-Z]+[a-zA-Z\d]*(=|\s|>)/g;
|
|
40
40
|
var COMPONENT_STUB_ATTR = "$tag-name";
|
|
41
41
|
var PROP_STUB_ATTR = "-$u";
|
|
@@ -53,10 +53,13 @@ function rehypeRaw(opts) {
|
|
|
53
53
|
visit(tree, (node) => {
|
|
54
54
|
var _a;
|
|
55
55
|
if (node.type === "raw" && COMPONENT_NAME_REGEX.test(node.value)) {
|
|
56
|
-
node.value = node.value.replace(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
node.value = node.value.replace(
|
|
57
|
+
COMPONENT_NAME_REGEX,
|
|
58
|
+
(str, bracket, tagName, next, i, full) => {
|
|
59
|
+
const isWithinQuotes = /="[^"]*$/.test(full.slice(0, i)) && /^[^"]*"/.test(full.slice(i)) || /='[^']*$/.test(full.slice(0, i)) && /^[^']*'/.test(full.slice(i));
|
|
60
|
+
return isWithinQuotes ? str : `${bracket}${tagName} ${COMPONENT_STUB_ATTR}="${tagName}"${next}`;
|
|
61
|
+
}
|
|
62
|
+
);
|
|
60
63
|
node.value = node.value.replace(COMPONENT_PROP_REGEX, (str) => {
|
|
61
64
|
return str.replace(
|
|
62
65
|
/[A-Z]/g,
|
|
@@ -72,7 +75,7 @@ function rehypeRaw(opts) {
|
|
|
72
75
|
File: ${opts.fileAbsPath}`);
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
|
-
const newTree = raw(tree, vFile);
|
|
78
|
+
const newTree = raw(tree, { file: vFile });
|
|
76
79
|
visit(newTree, "element", (node) => {
|
|
77
80
|
var _a, _b;
|
|
78
81
|
if ((_a = node.properties) == null ? void 0 : _a[COMPONENT_STUB_ATTR]) {
|
package/package.json
CHANGED
|
@@ -69,6 +69,8 @@ var HANDLERS = {
|
|
|
69
69
|
function: function _function(_ref3) {
|
|
70
70
|
var _this2 = this;
|
|
71
71
|
var signature = _ref3.signature;
|
|
72
|
+
// handle Function type without signature
|
|
73
|
+
if (!signature) return 'Function';
|
|
72
74
|
var signatures = 'oneOf' in signature ? signature.oneOf : [signature];
|
|
73
75
|
return signatures.map(function (signature) {
|
|
74
76
|
return "".concat(signature.isAsync ? 'async ' : '', "(").concat(signature.arguments.map(function (arg) {
|
|
@@ -4,11 +4,11 @@ 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 ContentFooter from "../../slots/ContentFooter";
|
|
8
7
|
import { ReactComponent as IconSidebar } from '@ant-design/icons-svg/inline-svg/outlined/align-left.svg';
|
|
9
8
|
import animateScrollTo from 'animated-scroll-to';
|
|
10
9
|
import { Helmet, useIntl, useLocation, useOutlet, useRouteMeta, useSidebarData, useSiteData } from 'dumi';
|
|
11
10
|
import Content from 'dumi/theme/slots/Content';
|
|
11
|
+
import ContentFooter from 'dumi/theme/slots/ContentFooter';
|
|
12
12
|
import Features from 'dumi/theme/slots/Features';
|
|
13
13
|
import Footer from 'dumi/theme/slots/Footer';
|
|
14
14
|
import Header from 'dumi/theme/slots/Header';
|
|
@@ -46,7 +46,7 @@ var Toc = function Toc() {
|
|
|
46
46
|
});
|
|
47
47
|
setSectionRefs(refs);
|
|
48
48
|
}
|
|
49
|
-
}, [pathname, search, loading]);
|
|
49
|
+
}, [pathname, search, loading, memoToc]);
|
|
50
50
|
return sectionRefs.length ? /*#__PURE__*/React.createElement(ScrollSpy, {
|
|
51
51
|
sectionRefs: sectionRefs
|
|
52
52
|
}, function (_ref3) {
|