dumi 2.0.0-alpha.1 → 2.0.0-alpha.3
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/assetParsers/block.js +1 -1
- package/dist/client/theme-api/DumiDemoGrid.js +56 -6
- package/dist/client/theme-api/context.d.ts +3 -6
- package/dist/client/theme-api/context.js +2 -1
- package/dist/client/theme-api/index.d.ts +3 -0
- package/dist/client/theme-api/index.js +4 -1
- package/dist/client/theme-api/types.d.ts +64 -0
- package/dist/client/theme-api/useNavData.d.ts +6 -0
- package/dist/client/theme-api/useNavData.js +78 -0
- package/dist/client/theme-api/useRouteMeta.d.ts +5 -0
- package/dist/client/theme-api/useRouteMeta.js +55 -0
- package/dist/client/theme-api/useSidebarData.d.ts +8 -0
- package/dist/client/theme-api/useSidebarData.js +132 -0
- package/dist/client/theme-api/utils.d.ts +3 -0
- package/dist/client/theme-api/utils.js +62 -0
- package/dist/client/tsconfig.json +2 -0
- package/dist/features/compile.js +20 -3
- package/dist/features/configPlugins/index.js +4 -2
- package/dist/features/configPlugins/schema.js +11 -1
- package/dist/features/locales.js +30 -10
- package/dist/features/meta.d.ts +3 -0
- package/dist/features/meta.js +77 -0
- package/dist/features/routes.js +17 -4
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.d.ts +14 -0
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.js +50 -0
- package/dist/features/sideEffects/index.d.ts +7 -0
- package/dist/features/sideEffects/index.js +47 -0
- package/dist/features/theme/index.js +6 -29
- package/dist/index.d.ts +8 -2
- package/dist/index.js +16 -3
- package/dist/loaders/markdown/index.d.ts +1 -1
- package/dist/loaders/markdown/index.js +22 -7
- package/dist/loaders/markdown/transformer/index.d.ts +6 -1
- package/dist/loaders/markdown/transformer/index.js +27 -3
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +41 -16
- package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +4 -0
- package/dist/loaders/markdown/transformer/rehypeEmbed.js +75 -0
- package/dist/loaders/markdown/transformer/rehypeRaw.js +9 -1
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +3 -0
- package/dist/loaders/markdown/transformer/remarkMeta.js +44 -0
- package/dist/preset.js +2 -0
- package/dist/types.d.ts +20 -7
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +25 -1
- package/package.json +13 -9
- package/theme-default/layouts/DocLayout/index.d.ts +3 -0
- package/theme-default/layouts/DocLayout/index.js +37 -0
- package/theme-default/slots/Content/index.d.ts +5 -0
- package/theme-default/slots/Content/index.js +13 -0
- package/theme-default/slots/Header/index.d.ts +3 -0
- package/theme-default/slots/Header/index.js +17 -0
- package/theme-default/slots/Logo/index.d.ts +3 -0
- package/theme-default/slots/Logo/index.js +7 -0
- package/theme-default/slots/Navbar/index.d.ts +3 -0
- package/theme-default/slots/Navbar/index.js +7 -0
- package/theme-default/slots/SearchBar/index.d.ts +3 -0
- package/theme-default/slots/SearchBar/index.js +9 -0
- package/theme-default/slots/Sidebar/index.d.ts +3 -0
- package/theme-default/slots/Sidebar/index.js +14 -0
|
@@ -1,14 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
12
|
+
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
|
|
15
|
+
import { useRouteMeta } from 'dumi/theme';
|
|
16
|
+
import React, { useState } from 'react';
|
|
2
17
|
import { DumiDemo } from "./DumiDemo";
|
|
3
18
|
export var DumiDemoGrid = function DumiDemoGrid(props) {
|
|
19
|
+
var meta = useRouteMeta();
|
|
20
|
+
|
|
21
|
+
var _useState = useState(function () {
|
|
22
|
+
var _meta$demo;
|
|
23
|
+
|
|
24
|
+
var cols = [];
|
|
25
|
+
|
|
26
|
+
if ((_meta$demo = meta.demo) !== null && _meta$demo !== void 0 && _meta$demo.cols && meta.demo.cols > 1) {
|
|
27
|
+
for (var i = 0; i < props.items.length; i += meta.demo.cols) {
|
|
28
|
+
props.items.slice(i, i + meta.demo.cols).forEach(function (item, j) {
|
|
29
|
+
var _cols$j;
|
|
30
|
+
|
|
31
|
+
(_cols$j = cols[j]) !== null && _cols$j !== void 0 ? _cols$j : cols[j] = [];
|
|
32
|
+
cols[j].push(item);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return cols;
|
|
37
|
+
} else {
|
|
38
|
+
cols.push(props.items);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return cols;
|
|
42
|
+
}),
|
|
43
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
44
|
+
cols = _useState2[0];
|
|
45
|
+
|
|
4
46
|
return /*#__PURE__*/React.createElement("div", {
|
|
5
47
|
style: {
|
|
6
|
-
display: '
|
|
7
|
-
|
|
48
|
+
display: 'flex',
|
|
49
|
+
margin: -8
|
|
8
50
|
}
|
|
9
|
-
},
|
|
51
|
+
}, cols.map(function (col, i) {
|
|
10
52
|
return /*#__PURE__*/React.createElement("section", {
|
|
11
|
-
|
|
12
|
-
|
|
53
|
+
style: {
|
|
54
|
+
flex: 1,
|
|
55
|
+
padding: 8
|
|
56
|
+
},
|
|
57
|
+
key: String(i)
|
|
58
|
+
}, col.map(function (item) {
|
|
59
|
+
return /*#__PURE__*/React.createElement(DumiDemo, _extends({
|
|
60
|
+
key: item.demo.id
|
|
61
|
+
}, item));
|
|
62
|
+
}));
|
|
13
63
|
}));
|
|
14
64
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { type ComponentType } from 'react';
|
|
2
|
-
import type { IPreviewerProps } from './types';
|
|
2
|
+
import type { ILocalesConfig, IPreviewerProps, IThemeConfig } from './types';
|
|
3
3
|
export interface IThemeContext {
|
|
4
4
|
demos: Record<string, {
|
|
5
5
|
component: ComponentType;
|
|
6
6
|
asset: IPreviewerProps['asset'];
|
|
7
7
|
}>;
|
|
8
|
-
locales:
|
|
9
|
-
|
|
10
|
-
name: string;
|
|
11
|
-
base: string;
|
|
12
|
-
}[];
|
|
8
|
+
locales: NonNullable<ILocalesConfig>;
|
|
9
|
+
themeConfig: IThemeConfig;
|
|
13
10
|
}
|
|
14
11
|
export declare const Context: import("react").Context<IThemeContext>;
|
|
@@ -2,4 +2,7 @@ export { useIntl } from 'react-intl';
|
|
|
2
2
|
export * from "./context";
|
|
3
3
|
export * from "./DumiDemo";
|
|
4
4
|
export * from "./DumiDemoGrid";
|
|
5
|
-
export * from "./types";
|
|
5
|
+
export * from "./types";
|
|
6
|
+
export * from "./useNavData";
|
|
7
|
+
export * from "./useRouteMeta";
|
|
8
|
+
export * from "./useSidebarData";
|
|
@@ -9,6 +9,10 @@ export interface IPreviewerProps {
|
|
|
9
9
|
* description of current demo
|
|
10
10
|
*/
|
|
11
11
|
description?: string;
|
|
12
|
+
/**
|
|
13
|
+
* file path of current demo
|
|
14
|
+
*/
|
|
15
|
+
filePath?: string;
|
|
12
16
|
/**
|
|
13
17
|
* asset metadata of current demo
|
|
14
18
|
*/
|
|
@@ -17,4 +21,64 @@ export interface IPreviewerProps {
|
|
|
17
21
|
* react node of current demo
|
|
18
22
|
*/
|
|
19
23
|
children: ReactNode;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
export interface IRouteMeta {
|
|
27
|
+
title: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
keywords?: string[];
|
|
30
|
+
nav?: string | {
|
|
31
|
+
title?: string;
|
|
32
|
+
order?: number;
|
|
33
|
+
};
|
|
34
|
+
group?: string | {
|
|
35
|
+
title?: string;
|
|
36
|
+
order?: number;
|
|
37
|
+
};
|
|
38
|
+
order?: number;
|
|
39
|
+
toc?: boolean | 'content' | 'menu';
|
|
40
|
+
demo?: {
|
|
41
|
+
cols?: number;
|
|
42
|
+
};
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
}
|
|
45
|
+
declare type IBasicLocale = {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
};
|
|
49
|
+
export declare type ILocalesConfig = ((IBasicLocale & {
|
|
50
|
+
base: string;
|
|
51
|
+
}) | (IBasicLocale & {
|
|
52
|
+
suffix: string;
|
|
53
|
+
}))[];
|
|
54
|
+
export interface INavItem {
|
|
55
|
+
title: string;
|
|
56
|
+
link: string;
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
}
|
|
59
|
+
interface ISidebarItem {
|
|
60
|
+
title: string;
|
|
61
|
+
link: string;
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}
|
|
64
|
+
export interface ISidebarGroup {
|
|
65
|
+
title?: string;
|
|
66
|
+
children: ISidebarItem[];
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
}
|
|
69
|
+
export interface IThemeConfig {
|
|
70
|
+
nav?: (INavItem & {
|
|
71
|
+
children?: INavItem[];
|
|
72
|
+
})[];
|
|
73
|
+
sidebar?: Record<string, ISidebarGroup[]>;
|
|
74
|
+
[key: string]: any;
|
|
20
75
|
}
|
|
76
|
+
export declare type IRoutesById = Record<string, {
|
|
77
|
+
path?: string;
|
|
78
|
+
parentId?: string;
|
|
79
|
+
meta?: IRouteMeta;
|
|
80
|
+
id: string;
|
|
81
|
+
redirect?: string;
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
}>;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
12
|
+
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
|
|
15
|
+
import { Context } from 'dumi/theme';
|
|
16
|
+
import { useContext, useState } from 'react';
|
|
17
|
+
import { useFullSidebarData } from "./useSidebarData";
|
|
18
|
+
import { useLocaleDocRoutes } from "./utils";
|
|
19
|
+
/**
|
|
20
|
+
* hook for get nav data
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export var useNavData = function useNavData() {
|
|
24
|
+
var routes = useLocaleDocRoutes();
|
|
25
|
+
|
|
26
|
+
var _useContext = useContext(Context),
|
|
27
|
+
themeConfig = _useContext.themeConfig;
|
|
28
|
+
|
|
29
|
+
var sidebar = useFullSidebarData();
|
|
30
|
+
|
|
31
|
+
var _useState = useState(function () {
|
|
32
|
+
// use user config first
|
|
33
|
+
if (themeConfig.nav) return themeConfig.nav; // fallback to generate nav data from sidebar data
|
|
34
|
+
|
|
35
|
+
var data = Object.entries(sidebar).map(function (_ref) {
|
|
36
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
37
|
+
link = _ref2[0],
|
|
38
|
+
groups = _ref2[1];
|
|
39
|
+
|
|
40
|
+
var meta = Object.values(routes).reduce(function (ret, route) {
|
|
41
|
+
var _nav$order;
|
|
42
|
+
|
|
43
|
+
// find routes which within the nav path
|
|
44
|
+
if (route.path.startsWith(link.slice(1))) {
|
|
45
|
+
switch (_typeof(route.meta.nav)) {
|
|
46
|
+
case 'object':
|
|
47
|
+
ret.title = route.meta.nav.title || ret.title;
|
|
48
|
+
ret.order = (_nav$order = route.meta.nav.order) !== null && _nav$order !== void 0 ? _nav$order : ret.order;
|
|
49
|
+
break;
|
|
50
|
+
|
|
51
|
+
case 'string':
|
|
52
|
+
ret.title = route.meta.nav || ret.title;
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
default:
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return ret;
|
|
60
|
+
}, {});
|
|
61
|
+
return {
|
|
62
|
+
title: meta.title || groups[0].title || groups[0].children[0].title,
|
|
63
|
+
order: meta.order || 0,
|
|
64
|
+
link: groups[0].children[0].link
|
|
65
|
+
};
|
|
66
|
+
}); // TODO: 2-level nav data
|
|
67
|
+
|
|
68
|
+
return data.sort(function (a, b) {
|
|
69
|
+
var _a$title;
|
|
70
|
+
|
|
71
|
+
return a.order - b.order || ((_a$title = a.title) === null || _a$title === void 0 ? void 0 : _a$title.localeCompare(b.title));
|
|
72
|
+
});
|
|
73
|
+
}),
|
|
74
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
75
|
+
nav = _useState2[0];
|
|
76
|
+
|
|
77
|
+
return nav;
|
|
78
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { matchRoutes, useAppData, useLocation, useRouteData } from 'dumi';
|
|
14
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* hook for get matched route meta
|
|
18
|
+
*/
|
|
19
|
+
export var useRouteMeta = function useRouteMeta() {
|
|
20
|
+
var _useRouteData = useRouteData(),
|
|
21
|
+
route = _useRouteData.route;
|
|
22
|
+
|
|
23
|
+
var _useLocation = useLocation(),
|
|
24
|
+
pathname = _useLocation.pathname;
|
|
25
|
+
|
|
26
|
+
var _useAppData = useAppData(),
|
|
27
|
+
clientRoutes = _useAppData.clientRoutes;
|
|
28
|
+
|
|
29
|
+
var getter = useCallback(function () {
|
|
30
|
+
var ret;
|
|
31
|
+
|
|
32
|
+
if (route.path === pathname && !('isLayout' in route)) {
|
|
33
|
+
// use `useRouteData` result if matched, for performance
|
|
34
|
+
ret = route.meta;
|
|
35
|
+
} else {
|
|
36
|
+
var _matchRoutes, _matched$route;
|
|
37
|
+
|
|
38
|
+
// match manually for dynamic route & layout component
|
|
39
|
+
var matched = (_matchRoutes = matchRoutes(clientRoutes, pathname)) === null || _matchRoutes === void 0 ? void 0 : _matchRoutes.pop();
|
|
40
|
+
ret = matched === null || matched === void 0 ? void 0 : (_matched$route = matched.route) === null || _matched$route === void 0 ? void 0 : _matched$route.meta;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return ret || {};
|
|
44
|
+
}, [clientRoutes.length, pathname]);
|
|
45
|
+
|
|
46
|
+
var _useState = useState(getter),
|
|
47
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
48
|
+
meta = _useState2[0],
|
|
49
|
+
setMeta = _useState2[1];
|
|
50
|
+
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
setMeta(getter);
|
|
53
|
+
}, [clientRoutes.length, pathname]);
|
|
54
|
+
return meta;
|
|
55
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
|
|
9
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
|
+
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
|
|
19
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
+
|
|
23
|
+
import { useLocation } from 'dumi';
|
|
24
|
+
import { Context } from 'dumi/theme';
|
|
25
|
+
import { useContext, useState } from 'react';
|
|
26
|
+
import { useLocale, useLocaleDocRoutes } from "./utils";
|
|
27
|
+
var DEFAULT_GROUP_STUB_TITLE = '$default-group-title';
|
|
28
|
+
|
|
29
|
+
var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
|
|
30
|
+
return 'base' in locale ? routePath.replace(locale.base.slice(1), '').replace(/^\//, '') : routePath;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* hook for get sidebar data for all nav
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export var useFullSidebarData = function useFullSidebarData() {
|
|
38
|
+
var locale = useLocale();
|
|
39
|
+
var routes = useLocaleDocRoutes();
|
|
40
|
+
|
|
41
|
+
var _useContext = useContext(Context),
|
|
42
|
+
themeConfig = _useContext.themeConfig;
|
|
43
|
+
|
|
44
|
+
var _useState = useState(function () {
|
|
45
|
+
// auto generate sidebar data from routes
|
|
46
|
+
var data = Object.values(routes).reduce(function (ret, route) {
|
|
47
|
+
var clearPath = getLocaleClearPath(route.path, locale); // skip index routes
|
|
48
|
+
|
|
49
|
+
if (clearPath) {
|
|
50
|
+
var _ret$parentPath, _ret$parentPath$title, _ret$parentPath$title2;
|
|
51
|
+
|
|
52
|
+
// extract parent path from route path
|
|
53
|
+
// a => /a
|
|
54
|
+
// en-US/a => /en-US/a
|
|
55
|
+
// a/b => /a
|
|
56
|
+
// en-US/a/b => /en-US/a
|
|
57
|
+
var parentPath = "/".concat(route.path.replace(/\/[^/]+$/, ''));
|
|
58
|
+
|
|
59
|
+
var _ref = _typeof(route.meta.group) === 'object' ? route.meta.group : {
|
|
60
|
+
title: route.meta.group
|
|
61
|
+
},
|
|
62
|
+
title = _ref.title,
|
|
63
|
+
_ref$order = _ref.order,
|
|
64
|
+
order = _ref$order === void 0 ? 0 : _ref$order;
|
|
65
|
+
|
|
66
|
+
var titleKey = title || DEFAULT_GROUP_STUB_TITLE; // create group data by nav path & group name
|
|
67
|
+
|
|
68
|
+
(_ret$parentPath = ret[parentPath]) !== null && _ret$parentPath !== void 0 ? _ret$parentPath : ret[parentPath] = {};
|
|
69
|
+
ret[parentPath][titleKey] = {
|
|
70
|
+
title: title,
|
|
71
|
+
order: ((_ret$parentPath$title = ret[parentPath][titleKey]) === null || _ret$parentPath$title === void 0 ? void 0 : _ret$parentPath$title.order) || order,
|
|
72
|
+
children: [].concat(_toConsumableArray(((_ret$parentPath$title2 = ret[parentPath][titleKey]) === null || _ret$parentPath$title2 === void 0 ? void 0 : _ret$parentPath$title2.children) || []), [{
|
|
73
|
+
title: route.meta.title,
|
|
74
|
+
link: "/".concat(route.path),
|
|
75
|
+
order: route.meta.order || 0
|
|
76
|
+
}])
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return ret;
|
|
81
|
+
}, {}); // destruct sidebar data into sidebar config
|
|
82
|
+
|
|
83
|
+
var sidebarConfig = Object.entries(data).reduce(function (ret, _ref2) {
|
|
84
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
85
|
+
navPath = _ref3[0],
|
|
86
|
+
groups = _ref3[1];
|
|
87
|
+
|
|
88
|
+
ret[navPath] = Object.values(groups).sort(function (a, b) {
|
|
89
|
+
var _a$title;
|
|
90
|
+
|
|
91
|
+
return (// sort by group order
|
|
92
|
+
a.order - b.order || (a.title ? // sort by group title
|
|
93
|
+
(_a$title = a.title) === null || _a$title === void 0 ? void 0 : _a$title.localeCompare(b.title || '') : // put non-title group at the end
|
|
94
|
+
-1)
|
|
95
|
+
);
|
|
96
|
+
}); // sort group children by order or title
|
|
97
|
+
|
|
98
|
+
ret[navPath].forEach(function (group) {
|
|
99
|
+
return group.children.sort(function (a, b) {
|
|
100
|
+
return a.order - b.order || a.title.localeCompare(b.title);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
return ret;
|
|
104
|
+
}, {}); // allow user partial override
|
|
105
|
+
|
|
106
|
+
return Object.assign(sidebarConfig, themeConfig.sidebar);
|
|
107
|
+
}),
|
|
108
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
109
|
+
sidebar = _useState2[0];
|
|
110
|
+
|
|
111
|
+
return sidebar;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* hook for get sidebar data for current nav
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
export var useSidebarData = function useSidebarData() {
|
|
118
|
+
var locale = useLocale();
|
|
119
|
+
var sidebar = useFullSidebarData();
|
|
120
|
+
|
|
121
|
+
var _useLocation = useLocation(),
|
|
122
|
+
pathname = _useLocation.pathname;
|
|
123
|
+
|
|
124
|
+
var clearPath = getLocaleClearPath(pathname.slice(1), locale); // extract parent path from location pathname
|
|
125
|
+
// /a => /a
|
|
126
|
+
// /a/b => /a
|
|
127
|
+
// /en-US/a => /en-US/a
|
|
128
|
+
// /en-US/a/b => /en-US/a
|
|
129
|
+
|
|
130
|
+
var parentPath = clearPath ? pathname.replace(/(\/[^/]+)(\/[^/]+)$/, '$1') : pathname;
|
|
131
|
+
return parentPath ? sidebar[parentPath] : [];
|
|
132
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { useAppData } from 'dumi';
|
|
14
|
+
import { Context, useIntl } from 'dumi/theme';
|
|
15
|
+
import { useContext, useState } from 'react';
|
|
16
|
+
export var useLocale = function useLocale() {
|
|
17
|
+
var intl = useIntl();
|
|
18
|
+
|
|
19
|
+
var _useContext = useContext(Context),
|
|
20
|
+
locales = _useContext.locales;
|
|
21
|
+
|
|
22
|
+
var _useState = useState(function () {
|
|
23
|
+
return locales.find(function (_ref) {
|
|
24
|
+
var id = _ref.id;
|
|
25
|
+
return id === intl.locale;
|
|
26
|
+
});
|
|
27
|
+
}),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
29
|
+
locale = _useState2[0];
|
|
30
|
+
|
|
31
|
+
return locale;
|
|
32
|
+
};
|
|
33
|
+
export var useLocaleDocRoutes = function useLocaleDocRoutes() {
|
|
34
|
+
var intl = useIntl();
|
|
35
|
+
|
|
36
|
+
var _useAppData = useAppData(),
|
|
37
|
+
routes = _useAppData.routes;
|
|
38
|
+
|
|
39
|
+
var _useContext2 = useContext(Context),
|
|
40
|
+
locales = _useContext2.locales;
|
|
41
|
+
|
|
42
|
+
var _useState3 = useState(function () {
|
|
43
|
+
var reversedLocales = locales.slice().reverse();
|
|
44
|
+
return Object.values(routes).reduce(function (ret, route) {
|
|
45
|
+
var matched = reversedLocales.find(function (locale) {
|
|
46
|
+
return 'suffix' in locale ? // suffix mode
|
|
47
|
+
route.path.endsWith(locale.suffix) : // base mode
|
|
48
|
+
route.path.startsWith(locale.base.slice(1));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (route.parentId === 'DocLayout' && matched.id === intl.locale) {
|
|
52
|
+
ret[route.id] = route;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return ret;
|
|
56
|
+
}, {});
|
|
57
|
+
}),
|
|
58
|
+
_useState4 = _slicedToArray(_useState3, 1),
|
|
59
|
+
localeDocRoutes = _useState4[0];
|
|
60
|
+
|
|
61
|
+
return localeDocRoutes;
|
|
62
|
+
};
|
package/dist/features/compile.js
CHANGED
|
@@ -27,17 +27,34 @@ __export(compile_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(compile_exports);
|
|
28
28
|
var import_react = __toESM(require("../techStacks/react"));
|
|
29
29
|
var compile_default = (api) => {
|
|
30
|
-
api.
|
|
30
|
+
api.register({
|
|
31
|
+
key: "registerTechStack",
|
|
32
|
+
stage: Infinity,
|
|
33
|
+
fn: () => new import_react.default()
|
|
34
|
+
});
|
|
35
|
+
api.modifyDefaultConfig((memo) => {
|
|
36
|
+
memo.alias.dumi$ = memo.alias.umi;
|
|
37
|
+
return memo;
|
|
38
|
+
});
|
|
31
39
|
api.chainWebpack(async (memo) => {
|
|
32
|
-
const loaderPath = require.resolve("../loaders/markdown");
|
|
33
40
|
const babelInUmi = memo.module.rule("src").use("babel-loader").entries();
|
|
34
41
|
const techStacks = await api.applyPlugins({
|
|
35
42
|
key: "registerTechStack",
|
|
36
43
|
type: api.ApplyPluginsType.add
|
|
37
44
|
});
|
|
38
|
-
|
|
45
|
+
const loaderPath = require.resolve("../loaders/markdown");
|
|
46
|
+
const loaderBaseOpts = {
|
|
39
47
|
techStacks,
|
|
40
48
|
cwd: api.cwd,
|
|
49
|
+
codeBlockMode: api.config.resolve.codeBlockMode,
|
|
50
|
+
extraRemarkPlugins: api.config.extraRemarkPlugins,
|
|
51
|
+
extraRehypePlugins: api.config.extraRehypePlugins
|
|
52
|
+
};
|
|
53
|
+
memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("demo-index").resourceQuery(/meta$/).use("demo-index-loader").loader(loaderPath).options({
|
|
54
|
+
...loaderBaseOpts,
|
|
55
|
+
mode: "meta"
|
|
56
|
+
}).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
|
|
57
|
+
...loaderBaseOpts,
|
|
41
58
|
builtins: api.service.themeData.builtins
|
|
42
59
|
});
|
|
43
60
|
memo.module.rule("dumi-demo").type("javascript/auto").test(/\..+$/).enforce("pre").resourceQuery(/techStack/).use("demo-loader").loader(require.resolve("../loaders/demo")).options({ techStacks, cwd: api.cwd });
|
|
@@ -27,8 +27,10 @@ var configPlugins_default = (api) => {
|
|
|
27
27
|
const configDefaults = {
|
|
28
28
|
resolve: {
|
|
29
29
|
docDirs: ["docs"],
|
|
30
|
-
entityDirs: [{ type: "component", dir: "src" }]
|
|
31
|
-
|
|
30
|
+
entityDirs: [{ type: "component", dir: "src" }],
|
|
31
|
+
codeBlockMode: "active"
|
|
32
|
+
},
|
|
33
|
+
themeConfig: {}
|
|
32
34
|
};
|
|
33
35
|
const schemas = (0, import_schema.getSchemas)();
|
|
34
36
|
for (const key of Object.keys(schemas)) {
|
|
@@ -22,11 +22,21 @@ __export(schema_exports, {
|
|
|
22
22
|
getSchemas: () => getSchemas
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(schema_exports);
|
|
25
|
+
function getUnifiedPluginSchema(Joi) {
|
|
26
|
+
return Joi.array().items(Joi.alternatives(Joi.string(), Joi.func(), Joi.array().items(Joi.alternatives(Joi.string(), Joi.func()), Joi.object()).length(2))).optional();
|
|
27
|
+
}
|
|
25
28
|
function getSchemas() {
|
|
26
29
|
return {
|
|
27
30
|
resolve: (Joi) => Joi.object({
|
|
28
31
|
docDirs: Joi.array().items(Joi.string()).optional(),
|
|
29
|
-
entityDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional()
|
|
32
|
+
entityDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
|
|
33
|
+
codeBlockMode: Joi.string().valid("active", "passive").optional()
|
|
34
|
+
}).optional(),
|
|
35
|
+
extraRemarkPlugins: getUnifiedPluginSchema,
|
|
36
|
+
extraRehypePlugins: getUnifiedPluginSchema,
|
|
37
|
+
themeConfig: (Joi) => Joi.object({
|
|
38
|
+
nav: Joi.array().items(Joi.object()).optional(),
|
|
39
|
+
sidebar: Joi.object().optional()
|
|
30
40
|
}).optional()
|
|
31
41
|
};
|
|
32
42
|
}
|