dumi 2.0.0-rc.0 → 2.0.0-rc.10
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/compiled/@umijs/plugins/index.js +1 -0
- package/compiled/@umijs/plugins/package.json +1 -0
- package/dist/assetParsers/block.js +6 -2
- package/dist/client/pages/404.js +1 -1
- package/dist/client/pages/{Demo.d.ts → Demo/index.d.ts} +1 -0
- package/dist/client/pages/{Demo.js → Demo/index.js} +1 -0
- package/dist/client/pages/Demo/index.less +4 -0
- package/dist/client/theme-api/DumiDemo.js +23 -3
- package/dist/client/theme-api/DumiPage.js +7 -10
- package/dist/client/theme-api/types.d.ts +6 -1
- package/dist/client/theme-api/useNavData.js +4 -22
- package/dist/client/theme-api/useRouteMeta.js +4 -3
- package/dist/client/theme-api/useSidebarData.d.ts +11 -0
- package/dist/client/theme-api/useSidebarData.js +122 -25
- package/dist/client/theme-api/utils.d.ts +16 -1
- package/dist/client/theme-api/utils.js +45 -2
- package/dist/features/assets.d.ts +4 -0
- package/dist/features/assets.js +7 -2
- package/dist/features/compile/babelLoaderCustomize.d.ts +4 -0
- package/dist/features/compile/babelLoaderCustomize.js +37 -0
- package/dist/features/compile/index.d.ts +3 -0
- package/dist/features/{compile.js → compile/index.js} +18 -9
- package/dist/features/derivative.js +28 -12
- package/dist/features/{compile.d.ts → exportStatic.d.ts} +0 -0
- package/dist/features/exportStatic.js +48 -0
- package/dist/features/locales.js +2 -1
- package/dist/features/routes.js +29 -11
- package/dist/features/sitemap.d.ts +3 -0
- package/dist/features/sitemap.js +64 -0
- package/dist/features/theme/index.js +31 -5
- package/dist/features/theme/loader.js +6 -4
- package/dist/loaders/markdown/index.js +17 -8
- package/dist/loaders/markdown/transformer/index.d.ts +2 -0
- package/dist/loaders/markdown/transformer/index.js +9 -2
- package/dist/loaders/markdown/transformer/rehypeDemo.js +2 -1
- package/dist/loaders/markdown/transformer/rehypeDesc.d.ts +6 -0
- package/dist/loaders/markdown/transformer/rehypeDesc.js +51 -0
- package/dist/loaders/markdown/transformer/rehypeLink.d.ts +6 -0
- package/dist/loaders/markdown/transformer/rehypeLink.js +68 -0
- package/dist/loaders/markdown/transformer/rehypeSlug.js +7 -2
- package/dist/loaders/markdown/transformer/remarkContainer.d.ts +3 -0
- package/dist/loaders/markdown/transformer/remarkContainer.js +53 -0
- package/dist/loaders/markdown/transformer/remarkEmbed.js +4 -1
- package/dist/preset.js +3 -1
- package/package.json +11 -8
- package/theme-default/builtins/Badge/index.d.ts +7 -0
- package/theme-default/builtins/Badge/index.js +12 -0
- package/theme-default/builtins/Badge/index.less +33 -0
- package/theme-default/builtins/Container/index.d.ts +8 -0
- package/theme-default/builtins/Container/index.js +39 -0
- package/theme-default/builtins/Container/index.less +94 -0
- package/theme-default/builtins/Previewer/index.js +1 -1
- package/theme-default/builtins/Table/index.js +10 -2
- package/theme-default/builtins/Table/index.less +9 -9
- package/theme-default/layouts/DocLayout/index.js +47 -12
- package/theme-default/layouts/DocLayout/index.less +60 -1
- package/theme-default/locales/en-US.json +2 -1
- package/theme-default/locales/zh-CN.json +2 -1
- package/theme-default/slots/Content/index.less +62 -1
- package/theme-default/slots/ContentTabs/index.less +14 -0
- package/theme-default/slots/Features/index.less +25 -3
- package/theme-default/slots/Footer/index.less +5 -0
- package/theme-default/slots/Header/index.js +39 -7
- package/theme-default/slots/Header/index.less +50 -0
- package/theme-default/slots/Hero/index.js +3 -2
- package/theme-default/slots/Hero/index.less +18 -1
- package/theme-default/slots/HeroTitle/index.less +4 -0
- package/theme-default/slots/Logo/index.less +12 -0
- package/theme-default/slots/Navbar/index.js +5 -1
- package/theme-default/slots/Navbar/index.less +14 -0
- package/theme-default/slots/PreviewerActions/index.js +2 -2
- package/theme-default/slots/SearchBar/index.js +15 -3
- package/theme-default/slots/SearchBar/index.less +9 -0
- package/theme-default/slots/SearchResult/index.d.ts +2 -2
- package/theme-default/slots/SearchResult/index.js +4 -2
- package/theme-default/slots/Sidebar/index.js +3 -2
- package/theme-default/slots/Sidebar/index.less +20 -0
- package/theme-default/styles/variables.less +10 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){var e={226:function(e){var n=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var r=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var __export=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:true})};var __copyProps=(e,o,i,c)=>{if(o&&typeof o==="object"||typeof o==="function"){for(let s of r(o))if(!a.call(e,s)&&s!==i)n(e,s,{get:()=>o[s],enumerable:!(c=t(o,s))||c.enumerable})}return e};var __toCommonJS=e=>__copyProps(n({},"__esModule",{value:true}),e);var o={};__export(o,{default:()=>analytics_default});e.exports=__toCommonJS(o);var analytics_default=e=>{const n=process.env.GA_KEY;const t=process.env.GA_V2_KEY;const enableBy=e=>e.config.analytics||n;e.describe({key:"analytics",config:{schema(e){return e.alternatives().try(e.object({baidu:e.string(),ga:e.string(),ga_v2:e.string()}),e.boolean().invalid(true))},onChange:e.ConfigChangeType.reload},enableBy:enableBy});const baiduTpl=e=>`\n (function() {\n var hm = document.createElement('script');\n hm.src = '//hm.baidu.com/hm.js?${e}';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(hm, s);\n })();\n `;const gaTpl=e=>`\n (function(){\n if (!location.port) {\n (function (i, s, o, g, r, a, m) {\n i['GoogleAnalyticsObject'] = r;\n i[r] = i[r] || function () {\n (i[r].q = i[r].q || []).push(arguments)\n }, i[r].l = 1 * new Date();\n a = s.createElement(o),\n m = s.getElementsByTagName(o)[0];\n a.async = 1;\n a.src = g;\n m.parentNode.insertBefore(a, m)\n })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');\n ga('create', '${e}', 'auto');\n ga('send', 'pageview');\n }\n })();\n `;const gaV2Tpl=e=>`\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${e}');\n `.trim();e.addHTMLHeadScripts((()=>{const r=e.config.analytics||{};const{baidu:a,ga:o=n,ga_v2:i=t}=r;const c=[];if(a){c.push({content:"var _hmt = _hmt || [];"})}if(e.env!=="development"){if(a){c.push({content:baiduTpl(a)})}if(o){c.push({content:gaTpl(o)})}if(i){c.push({async:true,src:`//www.googletagmanager.com/gtag/js?id=${i}`},{content:gaV2Tpl(i)})}}return c.filter(Boolean)}))};0&&0}};var n={};function __nccwpck_require__(t){var r=n[t];if(r!==undefined){return r.exports}var a=n[t]={exports:{}};var o=true;try{e[t](a,a.exports,__nccwpck_require__);o=false}finally{if(o)delete n[t]}return a.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(226);module.exports=t})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@umijs/plugins","version":"4.0.30","authors":["chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"],"license":"MIT","_lastModified":"2022-11-13T07:05:33.094Z"}
|
|
@@ -43,7 +43,7 @@ async function parseBlockAsset(opts) {
|
|
|
43
43
|
sources: {},
|
|
44
44
|
frontmatter: null
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
const deferrer = (0, import_esbuild.build)({
|
|
47
47
|
write: false,
|
|
48
48
|
bundle: true,
|
|
49
49
|
logLevel: "silent",
|
|
@@ -71,7 +71,7 @@ async function parseBlockAsset(opts) {
|
|
|
71
71
|
return { path: args.path, external: true };
|
|
72
72
|
}
|
|
73
73
|
return {
|
|
74
|
-
path: import_path.default.join(args.resolveDir, args.path),
|
|
74
|
+
path: args.kind !== "entry-point" ? opts.resolver(args.resolveDir, args.path) : import_path.default.join(args.resolveDir, args.path),
|
|
75
75
|
pluginData: { kind: args.kind, resolveDir: args.resolveDir }
|
|
76
76
|
};
|
|
77
77
|
});
|
|
@@ -116,6 +116,10 @@ async function parseBlockAsset(opts) {
|
|
|
116
116
|
}
|
|
117
117
|
]
|
|
118
118
|
});
|
|
119
|
+
try {
|
|
120
|
+
await deferrer;
|
|
121
|
+
} catch {
|
|
122
|
+
}
|
|
119
123
|
return result;
|
|
120
124
|
}
|
|
121
125
|
var block_default = parseBlockAsset;
|
package/dist/client/pages/404.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// allow customize 404 via theme slots
|
|
2
|
-
export { default } from
|
|
2
|
+
export { default } from "dumi/theme/slots/NotFound";
|
|
@@ -2,8 +2,24 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
2
2
|
|
|
3
3
|
import { SP_ROUTE_PREFIX } from "../../constants";
|
|
4
4
|
import { useSiteData } from 'dumi';
|
|
5
|
-
import
|
|
5
|
+
import Container from "dumi/theme/builtins/Container";
|
|
6
|
+
import Previewer from "dumi/theme/builtins/Previewer";
|
|
6
7
|
import React, { createElement } from 'react';
|
|
8
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
9
|
+
|
|
10
|
+
var DemoErrorBoundary = function DemoErrorBoundary(props) {
|
|
11
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
12
|
+
fallbackRender: function fallbackRender(_ref) {
|
|
13
|
+
var error = _ref.error;
|
|
14
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
15
|
+
type: "error"
|
|
16
|
+
}, /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement("strong", null, error.message || 'This demo has been crashed.')), error.stack && /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement("details", {
|
|
17
|
+
open: true
|
|
18
|
+
}, /*#__PURE__*/React.createElement("summary", null, "Error stack"), /*#__PURE__*/React.createElement("pre", null, error.stack))));
|
|
19
|
+
}
|
|
20
|
+
}, props.children);
|
|
21
|
+
};
|
|
22
|
+
|
|
7
23
|
export var DumiDemo = function DumiDemo(props) {
|
|
8
24
|
var _useSiteData = useSiteData(),
|
|
9
25
|
demos = _useSiteData.demos;
|
|
@@ -11,10 +27,14 @@ export var DumiDemo = function DumiDemo(props) {
|
|
|
11
27
|
var _demos$props$demo$id = demos[props.demo.id],
|
|
12
28
|
component = _demos$props$demo$id.component,
|
|
13
29
|
asset = _demos$props$demo$id.asset;
|
|
14
|
-
|
|
30
|
+
|
|
31
|
+
if (props.demo.inline) {
|
|
32
|
+
return /*#__PURE__*/React.createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(component));
|
|
33
|
+
}
|
|
34
|
+
|
|
15
35
|
return /*#__PURE__*/React.createElement(Previewer, _extends({
|
|
16
36
|
asset: asset,
|
|
17
37
|
demoUrl: // allow user override demoUrl by frontmatter
|
|
18
38
|
props.previewerProps.demoUrl || "/".concat(SP_ROUTE_PREFIX, "demos/").concat(props.demo.id)
|
|
19
|
-
}, props.previewerProps), /*#__PURE__*/createElement(component));
|
|
39
|
+
}, props.previewerProps), props.previewerProps.iframe ? null : /*#__PURE__*/React.createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(component)));
|
|
20
40
|
};
|
|
@@ -11,13 +11,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
12
|
|
|
13
13
|
import { useLocation, useRouteMeta, useSiteData } from 'dumi';
|
|
14
|
-
import ContentTabs from
|
|
14
|
+
import ContentTabs from "dumi/theme/slots/ContentTabs";
|
|
15
15
|
import React, { useEffect, useState } from 'react';
|
|
16
16
|
import { useTabQueryState } from "./useTabMeta";
|
|
17
17
|
export var DumiPage = function DumiPage(props) {
|
|
18
18
|
var _useLocation = useLocation(),
|
|
19
|
-
hash = _useLocation.hash
|
|
20
|
-
pathname = _useLocation.pathname;
|
|
19
|
+
hash = _useLocation.hash;
|
|
21
20
|
|
|
22
21
|
var _useRouteMeta = useRouteMeta(),
|
|
23
22
|
tabs = _useRouteMeta.tabs;
|
|
@@ -47,13 +46,11 @@ export var DumiPage = function DumiPage(props) {
|
|
|
47
46
|
|
|
48
47
|
useEffect(function () {
|
|
49
48
|
var id = hash.replace('#', '');
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
document.documentElement.scrollTo(0, 0);
|
|
56
|
-
}, [pathname]);
|
|
49
|
+
setTimeout(function () {
|
|
50
|
+
var elm = id && document.getElementById(decodeURIComponent(id));
|
|
51
|
+
if (elm) document.documentElement.scrollTo(0, elm.offsetTop - 80);
|
|
52
|
+
}, 1);
|
|
53
|
+
}, [hash]);
|
|
57
54
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
|
|
58
55
|
tabs: tabs,
|
|
59
56
|
tabKey: tabKey,
|
|
@@ -86,6 +86,10 @@ export interface IRouteMeta {
|
|
|
86
86
|
id: string;
|
|
87
87
|
depth: number;
|
|
88
88
|
title: string;
|
|
89
|
+
/**
|
|
90
|
+
* private field, will be removed in the future
|
|
91
|
+
*/
|
|
92
|
+
_debug_demo?: boolean;
|
|
89
93
|
}[];
|
|
90
94
|
texts: {
|
|
91
95
|
type?: 'content';
|
|
@@ -127,10 +131,11 @@ export declare type ILocalesConfig = ILocale[];
|
|
|
127
131
|
export interface INavItem {
|
|
128
132
|
title: string;
|
|
129
133
|
link: string;
|
|
134
|
+
order: number;
|
|
130
135
|
activePath?: string;
|
|
131
136
|
[key: string]: any;
|
|
132
137
|
}
|
|
133
|
-
interface ISidebarItem {
|
|
138
|
+
export interface ISidebarItem {
|
|
134
139
|
title: string;
|
|
135
140
|
link: string;
|
|
136
141
|
order: number;
|
|
@@ -1,5 +1,3 @@
|
|
|
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
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
2
|
|
|
5
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."); }
|
|
@@ -14,7 +12,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
14
12
|
|
|
15
13
|
import { useFullSidebarData, useSiteData } from 'dumi';
|
|
16
14
|
import { useState } from 'react';
|
|
17
|
-
import { useLocaleDocRoutes } from "./utils";
|
|
15
|
+
import { pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
18
16
|
/**
|
|
19
17
|
* hook for get nav data
|
|
20
18
|
*/
|
|
@@ -26,6 +24,7 @@ export var useNavData = function useNavData() {
|
|
|
26
24
|
themeConfig = _useSiteData.themeConfig;
|
|
27
25
|
|
|
28
26
|
var sidebar = useFullSidebarData();
|
|
27
|
+
var sidebarDataComparer = useRouteDataComparer();
|
|
29
28
|
|
|
30
29
|
var _useState = useState(function () {
|
|
31
30
|
// use user config first
|
|
@@ -37,22 +36,9 @@ export var useNavData = function useNavData() {
|
|
|
37
36
|
groups = _ref2[1];
|
|
38
37
|
|
|
39
38
|
var meta = Object.values(routes).reduce(function (ret, route) {
|
|
40
|
-
var _route$meta, _frontmatter$nav$orde;
|
|
41
|
-
|
|
42
39
|
// find routes which within the nav path
|
|
43
40
|
if (route.path.startsWith(link.slice(1))) {
|
|
44
|
-
|
|
45
|
-
case 'object':
|
|
46
|
-
ret.title = route.meta.frontmatter.nav.title || ret.title;
|
|
47
|
-
ret.order = (_frontmatter$nav$orde = route.meta.frontmatter.nav.order) !== null && _frontmatter$nav$orde !== void 0 ? _frontmatter$nav$orde : ret.order;
|
|
48
|
-
break;
|
|
49
|
-
|
|
50
|
-
case 'string':
|
|
51
|
-
ret.title = route.meta.frontmatter.nav || ret.title;
|
|
52
|
-
break;
|
|
53
|
-
|
|
54
|
-
default:
|
|
55
|
-
}
|
|
41
|
+
pickRouteSortMeta(ret, 'nav', route.meta.frontmatter);
|
|
56
42
|
}
|
|
57
43
|
|
|
58
44
|
return ret;
|
|
@@ -65,11 +51,7 @@ export var useNavData = function useNavData() {
|
|
|
65
51
|
};
|
|
66
52
|
}); // TODO: 2-level nav data
|
|
67
53
|
|
|
68
|
-
return data.sort(
|
|
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
|
-
});
|
|
54
|
+
return data.sort(sidebarDataComparer);
|
|
73
55
|
}),
|
|
74
56
|
_useState2 = _slicedToArray(_useState, 1),
|
|
75
57
|
nav = _useState2[0];
|
|
@@ -11,11 +11,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
12
|
|
|
13
13
|
import { matchRoutes, useAppData, useLocation, useRouteData } from 'dumi';
|
|
14
|
-
import { useCallback,
|
|
15
|
-
|
|
14
|
+
import { useCallback, useState } from 'react';
|
|
15
|
+
import { useIsomorphicLayoutEffect } from "./utils";
|
|
16
16
|
/**
|
|
17
17
|
* hook for get matched route meta
|
|
18
18
|
*/
|
|
19
|
+
|
|
19
20
|
export var useRouteMeta = function useRouteMeta() {
|
|
20
21
|
var _useRouteData = useRouteData(),
|
|
21
22
|
route = _useRouteData.route;
|
|
@@ -52,7 +53,7 @@ export var useRouteMeta = function useRouteMeta() {
|
|
|
52
53
|
meta = _useState2[0],
|
|
53
54
|
setMeta = _useState2[1];
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
useIsomorphicLayoutEffect(function () {
|
|
56
57
|
setMeta(getter);
|
|
57
58
|
}, [clientRoutes.length, pathname]);
|
|
58
59
|
return meta;
|
|
@@ -3,7 +3,18 @@ import type { ISidebarGroup } from './types';
|
|
|
3
3
|
* hook for get sidebar data for all nav
|
|
4
4
|
*/
|
|
5
5
|
export declare const useFullSidebarData: () => Record<string, ISidebarGroup[]>;
|
|
6
|
+
interface ITreeSidebarLeaf {
|
|
7
|
+
path: string;
|
|
8
|
+
title: string;
|
|
9
|
+
order: number;
|
|
10
|
+
children: (ITreeSidebarLeaf | ISidebarGroup)[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* hook for get full sidebar data in tree structure
|
|
14
|
+
*/
|
|
15
|
+
export declare const useTreeSidebarData: () => ITreeSidebarLeaf[];
|
|
6
16
|
/**
|
|
7
17
|
* hook for get sidebar data for current nav
|
|
8
18
|
*/
|
|
9
19
|
export declare const useSidebarData: () => ISidebarGroup[];
|
|
20
|
+
export {};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8
|
+
|
|
1
9
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
10
|
|
|
3
11
|
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."); }
|
|
@@ -6,8 +14,6 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
|
|
|
6
14
|
|
|
7
15
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
16
|
|
|
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
17
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
18
|
|
|
13
19
|
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."); }
|
|
@@ -22,7 +28,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
22
28
|
|
|
23
29
|
import { useLocale, useLocation, useSiteData } from 'dumi';
|
|
24
30
|
import { useState } from 'react';
|
|
25
|
-
import { useLocaleDocRoutes } from "./utils";
|
|
31
|
+
import { pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
26
32
|
var DEFAULT_GROUP_STUB_TITLE = '$default-group-title';
|
|
27
33
|
|
|
28
34
|
var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
|
|
@@ -40,6 +46,8 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
40
46
|
var _useSiteData = useSiteData(),
|
|
41
47
|
themeConfig = _useSiteData.themeConfig;
|
|
42
48
|
|
|
49
|
+
var sidebarDataComparer = useRouteDataComparer();
|
|
50
|
+
|
|
43
51
|
var _useState = useState(function () {
|
|
44
52
|
// auto generate sidebar data from routes
|
|
45
53
|
var data = Object.values(routes).reduce(function (ret, route) {
|
|
@@ -55,12 +63,11 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
55
63
|
// en-US/a/b => /en-US/a
|
|
56
64
|
var parentPath = "/".concat(route.path.replace(/\/[^/]+$/, ''));
|
|
57
65
|
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
title =
|
|
62
|
-
|
|
63
|
-
order = _ref$order === void 0 ? 0 : _ref$order;
|
|
66
|
+
var _pickRouteSortMeta = pickRouteSortMeta({
|
|
67
|
+
order: 0
|
|
68
|
+
}, 'group', route.meta.frontmatter),
|
|
69
|
+
title = _pickRouteSortMeta.title,
|
|
70
|
+
order = _pickRouteSortMeta.order;
|
|
64
71
|
|
|
65
72
|
var titleKey = title || DEFAULT_GROUP_STUB_TITLE; // create group data by nav path & group name
|
|
66
73
|
|
|
@@ -80,25 +87,15 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
80
87
|
return ret;
|
|
81
88
|
}, {}); // destruct sidebar data into sidebar config
|
|
82
89
|
|
|
83
|
-
var sidebarConfig = Object.entries(data).reduce(function (ret,
|
|
84
|
-
var
|
|
85
|
-
navPath =
|
|
86
|
-
groups =
|
|
87
|
-
|
|
88
|
-
ret[navPath] = Object.values(groups).sort(function (a, b) {
|
|
89
|
-
var _a$title;
|
|
90
|
+
var sidebarConfig = Object.entries(data).reduce(function (ret, _ref) {
|
|
91
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
92
|
+
navPath = _ref2[0],
|
|
93
|
+
groups = _ref2[1];
|
|
90
94
|
|
|
91
|
-
|
|
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
|
|
95
|
+
ret[navPath] = Object.values(groups).sort(sidebarDataComparer); // sort group children by order or title
|
|
97
96
|
|
|
98
97
|
ret[navPath].forEach(function (group) {
|
|
99
|
-
return group.children.sort(
|
|
100
|
-
return a.order - b.order || a.title.localeCompare(b.title);
|
|
101
|
-
});
|
|
98
|
+
return group.children.sort(sidebarDataComparer);
|
|
102
99
|
});
|
|
103
100
|
return ret;
|
|
104
101
|
}, {}); // allow user partial override
|
|
@@ -110,6 +107,106 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
110
107
|
|
|
111
108
|
return sidebar;
|
|
112
109
|
};
|
|
110
|
+
|
|
111
|
+
function getLeafMeta(data) {
|
|
112
|
+
var leafMeta = {
|
|
113
|
+
order: 0,
|
|
114
|
+
title: ''
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
var _iterator = _createForOfIteratorHelper(data),
|
|
118
|
+
_step;
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
122
|
+
var group = _step.value;
|
|
123
|
+
|
|
124
|
+
var _iterator2 = _createForOfIteratorHelper(group.children),
|
|
125
|
+
_step2;
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
129
|
+
var item = _step2.value;
|
|
130
|
+
|
|
131
|
+
if ('frontmatter' in item) {
|
|
132
|
+
pickRouteSortMeta(leafMeta, 'nav', item.frontmatter);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
_iterator2.e(err);
|
|
137
|
+
} finally {
|
|
138
|
+
_iterator2.f();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
_iterator.e(err);
|
|
143
|
+
} finally {
|
|
144
|
+
_iterator.f();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return leafMeta;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* hook for get full sidebar data in tree structure
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
export var useTreeSidebarData = function useTreeSidebarData() {
|
|
155
|
+
var original = useFullSidebarData();
|
|
156
|
+
var sidebarDataComparer = useRouteDataComparer();
|
|
157
|
+
|
|
158
|
+
var _useState3 = useState(function () {
|
|
159
|
+
var data = Object.entries(original) // match from the deepest level
|
|
160
|
+
.sort(function (a, b) {
|
|
161
|
+
return b[0].split('/').length - a[0].split('/').length;
|
|
162
|
+
}).reduce(function (ret, _ref3) {
|
|
163
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
164
|
+
path = _ref4[0],
|
|
165
|
+
data = _ref4[1];
|
|
166
|
+
|
|
167
|
+
var parent = path.replace(/\/[^/]+$/, '');
|
|
168
|
+
|
|
169
|
+
if (parent) {
|
|
170
|
+
var _ret$parent;
|
|
171
|
+
|
|
172
|
+
// handle nested sidebar data
|
|
173
|
+
// init parent first
|
|
174
|
+
(_ret$parent = ret[parent]) !== null && _ret$parent !== void 0 ? _ret$parent : ret[parent] = _objectSpread({
|
|
175
|
+
path: parent,
|
|
176
|
+
children: original[parent] || []
|
|
177
|
+
}, getLeafMeta(original[parent] || []));
|
|
178
|
+
|
|
179
|
+
if (ret[path]) {
|
|
180
|
+
// sort children first
|
|
181
|
+
ret[path].children.sort(sidebarDataComparer); // put n-level sidebar data as parent children
|
|
182
|
+
|
|
183
|
+
ret[parent].children.push(ret[path]);
|
|
184
|
+
delete ret[path];
|
|
185
|
+
} else {
|
|
186
|
+
var _ret$parent$children;
|
|
187
|
+
|
|
188
|
+
// put last-level sidebar data as parent children
|
|
189
|
+
(_ret$parent$children = ret[parent].children).push.apply(_ret$parent$children, _toConsumableArray(data));
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
// sort children first
|
|
193
|
+
data.sort(sidebarDataComparer); // put top-level sidebar data
|
|
194
|
+
|
|
195
|
+
ret[path] = _objectSpread({
|
|
196
|
+
path: path,
|
|
197
|
+
children: data
|
|
198
|
+
}, getLeafMeta(data));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return ret;
|
|
202
|
+
}, {});
|
|
203
|
+
return Object.values(data);
|
|
204
|
+
}),
|
|
205
|
+
_useState4 = _slicedToArray(_useState3, 1),
|
|
206
|
+
sidebar = _useState4[0];
|
|
207
|
+
|
|
208
|
+
return sidebar;
|
|
209
|
+
};
|
|
113
210
|
/**
|
|
114
211
|
* hook for get sidebar data for current nav
|
|
115
212
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import type { INavItem, IRouteMeta, IRoutesById } from './types';
|
|
2
3
|
export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
3
4
|
/**
|
|
4
5
|
* 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
|
|
@@ -6,3 +7,17 @@ export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
|
6
7
|
* @returns code string
|
|
7
8
|
*/
|
|
8
9
|
export declare const genReactRenderCode: (version: string) => string;
|
|
10
|
+
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
11
|
+
/**
|
|
12
|
+
* common comparer for sidebar/nav items
|
|
13
|
+
*/
|
|
14
|
+
export declare const useRouteDataComparer: <T extends {
|
|
15
|
+
order?: number | undefined;
|
|
16
|
+
link?: string | undefined;
|
|
17
|
+
path?: string | undefined;
|
|
18
|
+
title?: string | undefined;
|
|
19
|
+
}>() => (a: T, b: T) => number;
|
|
20
|
+
/**
|
|
21
|
+
* common util for pick meta to sort sidebar/nav items
|
|
22
|
+
*/
|
|
23
|
+
export declare const pickRouteSortMeta: (original: Partial<Pick<INavItem, 'order' | 'title'>>, field: 'nav' | 'group', fm: IRouteMeta['frontmatter']) => Partial<Pick<INavItem, "title" | "order">>;
|
|
@@ -1,3 +1,5 @@
|
|
|
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
|
+
|
|
1
3
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
4
|
|
|
3
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."); }
|
|
@@ -11,7 +13,8 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
11
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
14
|
|
|
13
15
|
import { useAppData, useIntl, useSiteData } from 'dumi';
|
|
14
|
-
import { useState } from 'react';
|
|
16
|
+
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
|
17
|
+
import { useLocale } from "./useLocale";
|
|
15
18
|
export var useLocaleDocRoutes = function useLocaleDocRoutes() {
|
|
16
19
|
var intl = useIntl();
|
|
17
20
|
|
|
@@ -55,5 +58,45 @@ export var genReactRenderCode = function genReactRenderCode(version) {
|
|
|
55
58
|
return "".concat(annotation, "\n\nimport React from 'react';\nimport { createRoot } from \"react-dom/client\";\nimport App from \"./App\";\n\nconst rootElement = document.getElementById(\"root\");\nconst root = createRoot(rootElement);\n\nroot.render(<App />);");
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
return "".concat(annotation, "\n
|
|
61
|
+
return "".concat(annotation, "\n\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './App';\n\nReactDOM.render(\n <App />,\n document.getElementById('root'),\n);");
|
|
62
|
+
};
|
|
63
|
+
export var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
64
|
+
/**
|
|
65
|
+
* common comparer for sidebar/nav items
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
export var useRouteDataComparer = function useRouteDataComparer() {
|
|
69
|
+
var locale = useLocale();
|
|
70
|
+
return useCallback(function (a, b) {
|
|
71
|
+
return (// smaller before larger for all
|
|
72
|
+
('order' in a && 'order' in b ? a.order - b.order : 0) || ( // shallower before deeper for sidebar item
|
|
73
|
+
'link' in a && 'link' in b ? a.link.split('/').length - b.link.split('/').length : 0) || ( // shallower before deeper for sidebar leaf
|
|
74
|
+
'path' in a && 'path' in b ? a.path.split('/').length - b.path.split('/').length : 0) || ( // fallback to compare title (put non-title item at the end)
|
|
75
|
+
a.title ? a.title.localeCompare(b.title || '', locale.id) : -1)
|
|
76
|
+
);
|
|
77
|
+
}, []);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* common util for pick meta to sort sidebar/nav items
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
export var pickRouteSortMeta = function pickRouteSortMeta(original, field, fm) {
|
|
84
|
+
var _sub$order;
|
|
85
|
+
|
|
86
|
+
var sub = fm[field];
|
|
87
|
+
|
|
88
|
+
switch (_typeof(sub)) {
|
|
89
|
+
case 'object':
|
|
90
|
+
original.title = sub.title || original.title;
|
|
91
|
+
original.order = (_sub$order = sub.order) !== null && _sub$order !== void 0 ? _sub$order : original.order;
|
|
92
|
+
break;
|
|
93
|
+
|
|
94
|
+
case 'string':
|
|
95
|
+
original.title = sub || original.title;
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
default:
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return original;
|
|
59
102
|
};
|
|
@@ -5,6 +5,10 @@ declare const examples: ExampleAsset[];
|
|
|
5
5
|
* internal function to add example assets
|
|
6
6
|
*/
|
|
7
7
|
export declare function addExampleAssets(data: typeof examples): void;
|
|
8
|
+
/**
|
|
9
|
+
* internal function to get atom assets
|
|
10
|
+
*/
|
|
11
|
+
export declare function getExampleAssets(): ExampleAsset[];
|
|
8
12
|
/**
|
|
9
13
|
* internal function to add meta for atom
|
|
10
14
|
*/
|
package/dist/features/assets.js
CHANGED
|
@@ -24,7 +24,8 @@ var assets_exports = {};
|
|
|
24
24
|
__export(assets_exports, {
|
|
25
25
|
addAtomMeta: () => addAtomMeta,
|
|
26
26
|
addExampleAssets: () => addExampleAssets,
|
|
27
|
-
default: () => assets_default
|
|
27
|
+
default: () => assets_default,
|
|
28
|
+
getExampleAssets: () => getExampleAssets
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(assets_exports);
|
|
30
31
|
var import_fs = __toESM(require("fs"));
|
|
@@ -35,6 +36,9 @@ var atomsMeta = {};
|
|
|
35
36
|
function addExampleAssets(data) {
|
|
36
37
|
examples.push(...data);
|
|
37
38
|
}
|
|
39
|
+
function getExampleAssets() {
|
|
40
|
+
return examples;
|
|
41
|
+
}
|
|
38
42
|
function addAtomMeta(atomId, data) {
|
|
39
43
|
atomsMeta[atomId] = import_plugin_utils.lodash.pick(data, ["title", "keywords", "deprecated"]);
|
|
40
44
|
}
|
|
@@ -69,5 +73,6 @@ var assets_default = (api) => {
|
|
|
69
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
74
|
0 && (module.exports = {
|
|
71
75
|
addAtomMeta,
|
|
72
|
-
addExampleAssets
|
|
76
|
+
addExampleAssets,
|
|
77
|
+
getExampleAssets
|
|
73
78
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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/features/compile/babelLoaderCustomize.ts
|
|
20
|
+
var babelLoaderCustomize_exports = {};
|
|
21
|
+
__export(babelLoaderCustomize_exports, {
|
|
22
|
+
default: () => babelLoaderCustomize
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(babelLoaderCustomize_exports);
|
|
25
|
+
function babelLoaderCustomize() {
|
|
26
|
+
return {
|
|
27
|
+
config(config) {
|
|
28
|
+
const context = this;
|
|
29
|
+
if (config.options.filename && context.resourceQuery.includes("type=meta")) {
|
|
30
|
+
config.options.filename += context.resourceQuery;
|
|
31
|
+
}
|
|
32
|
+
return config.options;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {});
|