dumi 2.2.0-alpha.2 → 2.2.0-rc.1
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/README.md +2 -6
- package/compiled/_internal/searchWorker.min.js +1 -1
- package/compiled/crates/swc_plugin_react_demo.wasm +0 -0
- package/dist/assetParsers/atom.d.ts +2 -0
- package/dist/assetParsers/atom.js +19 -12
- package/dist/client/theme-api/DumiDemoGrid.js +2 -1
- package/dist/client/theme-api/DumiPage.js +2 -0
- package/dist/client/theme-api/types.d.ts +8 -1
- package/dist/client/theme-api/useNavData.js +77 -15
- package/dist/client/theme-api/useSidebarData.js +28 -7
- package/dist/client/theme-api/useSiteSearch/index.d.ts +1 -0
- package/dist/client/theme-api/utils.d.ts +3 -3
- package/dist/client/theme-api/utils.js +1 -1
- package/dist/features/autoAlias.js +20 -23
- package/dist/features/configPlugins/index.js +2 -1
- package/dist/features/configPlugins/schema.js +0 -1
- package/dist/features/derivative.js +0 -1
- package/dist/features/locales.js +2 -1
- package/dist/features/routes.js +27 -13
- package/dist/features/theme/index.js +77 -4
- package/dist/loaders/markdown/transformer/rehypeDemo.js +35 -9
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +1 -0
- package/dist/types.d.ts +2 -8
- package/dist/utils.d.ts +0 -4
- package/dist/utils.js +0 -14
- package/package.json +8 -3
- package/theme-default/builtins/API/index.js +1 -1
- package/theme-default/builtins/SourceCode/index.js +27 -13
- package/theme-default/builtins/SourceCode/index.less +53 -3
- package/theme-default/builtins/Tree/index.d.ts +4 -0
- package/theme-default/builtins/Tree/index.js +206 -0
- package/theme-default/builtins/Tree/index.less +186 -0
- package/theme-default/slots/ColorSwitch/index.less +4 -2
- package/theme-default/slots/Navbar/index.js +80 -13
- package/theme-default/slots/Navbar/index.less +128 -4
- package/theme-default/slots/RtlSwitch/index.less +2 -1
- package/theme-default/slots/SocialIcon/index.less +2 -1
- package/theme-default/slots/Toc/index.js +8 -2
package/README.md
CHANGED
|
@@ -10,13 +10,9 @@ dumi is a static site generator for component library development.
|
|
|
10
10
|
|
|
11
11
|
To view more online examples and docs, please visit [dumi official site](https://d.umijs.org).
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Contributing
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
$ pnpm install
|
|
17
|
-
$ pnpm dev
|
|
18
|
-
$ pnpm docs:dev
|
|
19
|
-
```
|
|
15
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
20
16
|
|
|
21
17
|
## Badge
|
|
22
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var P=Object.create;var
|
|
1
|
+
"use strict";(()=>{var P=Object.create;var I=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames,R=Object.getOwnPropertySymbols,B=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var O=(e,t,i)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,M=(e,t)=>{for(var i in t||(t={}))E.call(t,i)&&O(e,i,t[i]);if(R)for(var i of R(t))L.call(t,i)&&O(e,i,t[i]);return e};var F=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var N=(e,t,i,h)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of D(t))!E.call(e,a)&&a!==i&&I(e,a,{get:()=>t[a],enumerable:!(h=z(t,a))||h.enumerable});return e};var W=(e,t,i)=>(i=e!=null?P(B(e)):{},N(t||!e||!e.__esModule?I(i,"default",{value:e,enumerable:!0}):i,e));var j=F((K,w)=>{w.exports=function(e){var t={};function i(h){if(t[h])return t[h].exports;var a=t[h]={exports:{},id:h,loaded:!1};return e[h].call(a.exports,a,a.exports,i),a.loaded=!0,a.exports}return i.m=e,i.c=t,i.p="",i(0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var h=i(2);Object.defineProperty(t,"combineChunks",{enumerable:!0,get:function(){return h.combineChunks}}),Object.defineProperty(t,"fillInChunks",{enumerable:!0,get:function(){return h.fillInChunks}}),Object.defineProperty(t,"findAll",{enumerable:!0,get:function(){return h.findAll}}),Object.defineProperty(t,"findChunks",{enumerable:!0,get:function(){return h.findChunks}})},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=t.findAll=function(s){var n=s.autoEscape,c=s.caseSensitive,f=c===void 0?!1:c,p=s.findChunks,u=p===void 0?a:p,g=s.sanitize,v=s.searchWords,T=s.textToHighlight;return o({chunksToHighlight:h({chunks:u({autoEscape:n,caseSensitive:f,sanitize:g,searchWords:v,textToHighlight:T})}),totalLength:T?T.length:0})},h=t.combineChunks=function(s){var n=s.chunks;return n=n.sort(function(c,f){return c.start-f.start}).reduce(function(c,f){if(c.length===0)return[f];var p=c.pop();if(f.start<=p.end){var u=Math.max(p.end,f.end);c.push({highlight:!1,start:p.start,end:u})}else c.push(p,f);return c},[]),n},a=function(s){var n=s.autoEscape,c=s.caseSensitive,f=s.sanitize,p=f===void 0?d:f,u=s.searchWords,g=s.textToHighlight;return g=p(g),u.filter(function(v){return v}).reduce(function(v,T){T=p(T),n&&(T=r(T));for(var m=new RegExp(T,c?"g":"gi"),x=void 0;x=m.exec(g);){var S=x.index,$=m.lastIndex;$>S&&v.push({highlight:!1,start:S,end:$}),x.index===m.lastIndex&&m.lastIndex++}return v},[])};t.findChunks=a;var o=t.fillInChunks=function(s){var n=s.chunksToHighlight,c=s.totalLength,f=[],p=function(v,T,m){T-v>0&&f.push({start:v,end:T,highlight:m})};if(n.length===0)p(0,c,!1);else{var u=0;n.forEach(function(g){p(u,g.start,!1),p(g.start,g.end,!0),u=g.end}),p(u,c,!1)}return f};function d(l){return l}function r(l){return l.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}}])});var C=W(j());var H="tab";function k(e,t,i,h,a){let o=a!==void 0,d=h.reduce((r,l)=>(l.tocIndex===a&&(r[l.paraId]=(r[l.paraId]||"").concat(l.value)),r),[]).filter(Boolean);return Boolean(d.length)||o?{rawTitle:e,title:t,link:i,paragraphs:h.reduce((r,l)=>{var s,n;return l.tocIndex===a&&((n=r[s=l.paraId])!=null||(r[s]=""),r[l.paraId]+=l.value),r},[]).filter(Boolean)}:null}function y(e){return[e.title,e.subtitle].filter(Boolean).join(" ")}function _(e,t,i){let h=[],a=Object.values(t).reduce((o,d)=>{var r,l;return d.asset&&((l=o[r=d.routeId])!=null||(o[r]=[]),o[d.routeId].push(d)),o},{});return Object.values(e).forEach(o=>{var d;if("meta"in o&&!("isLayout"in o)){let r=o.meta,l=o.path.replace(/^([^/])/,"/$1")||"/",s=i.find(u=>l===u.link||l.startsWith(`${u.activePath}/`)),n=(a[o.id]||[]).map(u=>{var g;return(g=u.asset)==null?void 0:g.id}),c=k("",y(r.frontmatter),l,r.texts),f=r.toc.reduce((u,g,v)=>(!n.includes(g.id)&&g.depth>1&&u.push(k(g.title,`${y(r.frontmatter)} - ${g.title}`,`${l}#${g.id}`,r.texts,v)),u),[]),p=(r.tabs||[]).reduce((u,{key:g,meta:v})=>{let T=k("",`${y(r.frontmatter)} - ${v.frontmatter.title}`,`${l}?${H}=${g}`,v.texts);return T&&u.push(T),u.push(...v.toc.map((m,x)=>k(m.title,`${y(r.frontmatter)} - ${v.frontmatter.title} - ${m.title}`,`${l}?${H}=${g}#${m.id}`,v.texts,x))),u},[]);h.push({navTitle:s==null?void 0:s.title,navOrder:s?i.indexOf(s):1/0,title:y(r.frontmatter),link:l,sections:[...c?[c]:[],...f,...p],demos:((d=a[o.id])==null?void 0:d.map(u=>({link:`${l}#${u.asset.id}`,rawTitle:u.asset.title||"",title:u.asset.title||y(r.frontmatter),description:u.asset.description||"",keywords:u.asset.keywords||[]})))||[]})}}),h}function b(e="",t,i=1){let h=(0,C.findAll)({textToHighlight:e,searchWords:t,autoEscape:!0}),a={};return[h.map(({start:o,end:d,highlight:r},l)=>{let s={text:e.slice(o,d)};return l===0&&!r&&h.length>1&&s.text.length>20&&(s.text=`...${s.text.slice(-20)}`),r&&(s.highlighted=!0,a[t.find(n=>s.text.includes(n))]=i),s}),a]}function Y(e,t){let i=t.split(" "),h=new RegExp(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(" ","|"),"i"),a={};return e.forEach(o=>{var l,s;let d=o.title,r=[];if(o.sections.forEach(n=>{for(let c of n.paragraphs)if(h.test(c)){let[f,p]=b(n.title,i,10),[u,g]=b(c,i);r.push({type:"content",link:n.link,priority:Object.values(M(M({},g),p)).reduce((v,T)=>v+T,0),highlightTitleTexts:f,highlightTexts:u,pageTitle:d});return}if(h.test(n.rawTitle)){let[c,f]=b(n.title,i,10);r.push({type:"title",link:n.link,priority:Object.values(f).reduce((p,u)=>p+u,0),highlightTitleTexts:c,highlightTexts:b(n.paragraphs[0]||"",i)[0],pageTitle:d})}}),o.demos.forEach(n=>{if(h.test(n.rawTitle)||h.test(n.description)){let[c,f]=b(n.title,i,10),[p,u]=b(n.description,i);r.push({type:"demo",link:n.link,priority:Object.values(M(M({},u),f)).reduce((g,v)=>g+v,0),highlightTitleTexts:c,highlightTexts:p,pageTitle:d})}}),h.test(o.title)){let[n,c]=b(o.title,i,100);r.push({type:"page",link:o.link,priority:Object.values(c).reduce((f,p)=>f+p,0),highlightTitleTexts:n,highlightTexts:b(((l=o.sections[0])==null?void 0:l.paragraphs[0])||"",i)[0],pageTitle:d})}if(r.length){let n=o.navTitle||"$ROOT";(s=a[n])!=null||(a[n]={title:o.navTitle,priority:o.navOrder*1e3,hints:[]}),a[n].hints.push(...r)}}),Object.values(a).forEach(({hints:o})=>{o.sort((d,r)=>r.priority-d.priority)}),Object.values(a).sort((o,d)=>d.priority-o.priority)}var A;self.onmessage=({data:e})=>{switch(e.action){case"generate-metadata":A=_(e.args.routes,e.args.demos,e.args.nav);break;case"get-search-result":self.postMessage(Y(A,e.args.keywords));break;default:}};})();
|
|
Binary file
|
|
@@ -9,6 +9,7 @@ declare class AtomAssetsParser {
|
|
|
9
9
|
private watcher;
|
|
10
10
|
private cbs;
|
|
11
11
|
private resolveFilter;
|
|
12
|
+
private watchArgs;
|
|
12
13
|
constructor(opts: {
|
|
13
14
|
entryFile: string;
|
|
14
15
|
resolveDir: string;
|
|
@@ -23,6 +24,7 @@ declare class AtomAssetsParser {
|
|
|
23
24
|
}>;
|
|
24
25
|
watch(cb: AtomAssetsParser['cbs'][number]): void;
|
|
25
26
|
unwatch(cb: AtomAssetsParser['cbs'][number]): void;
|
|
27
|
+
patchWatchArgs(handler: (args: AtomAssetsParser['watchArgs']) => AtomAssetsParser['watchArgs']): void;
|
|
26
28
|
destroyWorker(): void;
|
|
27
29
|
}
|
|
28
30
|
export default AtomAssetsParser;
|
|
@@ -47,6 +47,20 @@ var AtomAssetsParser = class {
|
|
|
47
47
|
mode: "worker",
|
|
48
48
|
parseOptions: opts.parseOptions
|
|
49
49
|
});
|
|
50
|
+
this.watchArgs = {
|
|
51
|
+
paths: this.entryDir,
|
|
52
|
+
options: {
|
|
53
|
+
cwd: this.resolveDir,
|
|
54
|
+
ignored: [
|
|
55
|
+
"**/.*",
|
|
56
|
+
"**/.*/**",
|
|
57
|
+
"**/_*",
|
|
58
|
+
"**/_*/**",
|
|
59
|
+
"**/*.{md,less,scss,sass,styl,css}"
|
|
60
|
+
],
|
|
61
|
+
ignoreInitial: true
|
|
62
|
+
}
|
|
63
|
+
};
|
|
50
64
|
}
|
|
51
65
|
async parse() {
|
|
52
66
|
if (!this.parseDeferrer || this.unresolvedFiles.length && !this.isParsing) {
|
|
@@ -115,19 +129,9 @@ var AtomAssetsParser = class {
|
|
|
115
129
|
const lazyParse = import_plugin_utils.lodash.debounce(() => {
|
|
116
130
|
this.parse().then((data) => this.cbs.forEach((cb2) => cb2(data)));
|
|
117
131
|
}, 100);
|
|
118
|
-
this.watcher = import_plugin_utils.chokidar.watch(this.
|
|
119
|
-
cwd: this.resolveDir,
|
|
120
|
-
ignored: [
|
|
121
|
-
"**/.*",
|
|
122
|
-
"**/.*/**",
|
|
123
|
-
"**/_*",
|
|
124
|
-
"**/_*/**",
|
|
125
|
-
"**/*.{md,less,scss,sass,styl,css}"
|
|
126
|
-
],
|
|
127
|
-
ignoreInitial: true
|
|
128
|
-
}).on("all", (ev, file) => {
|
|
132
|
+
this.watcher = import_plugin_utils.chokidar.watch(this.watchArgs.paths, this.watchArgs.options).on("all", (ev, file) => {
|
|
129
133
|
if (["add", "change"].includes(ev) && /((?<!\.d)\.ts|\.(jsx?|tsx))$/.test(file)) {
|
|
130
|
-
this.unresolvedFiles.push(import_path.default.join(this.
|
|
134
|
+
this.unresolvedFiles.push(import_path.default.join(this.watchArgs.options.cwd, file));
|
|
131
135
|
lazyParse();
|
|
132
136
|
}
|
|
133
137
|
});
|
|
@@ -137,6 +141,9 @@ var AtomAssetsParser = class {
|
|
|
137
141
|
unwatch(cb) {
|
|
138
142
|
this.cbs.splice(this.cbs.indexOf(cb), 1);
|
|
139
143
|
}
|
|
144
|
+
patchWatchArgs(handler) {
|
|
145
|
+
this.watchArgs = handler(this.watchArgs);
|
|
146
|
+
}
|
|
140
147
|
destroyWorker() {
|
|
141
148
|
if (this.parseDeferrer) {
|
|
142
149
|
this.parseDeferrer.finally(() => this.parser.$$destroyWorker());
|
|
@@ -59,10 +59,11 @@ export var DumiDemoGrid = function DumiDemoGrid(props) {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
window.addEventListener('resize', handler);
|
|
62
|
+
handler();
|
|
62
63
|
return function () {
|
|
63
64
|
return window.removeEventListener('resize', handler);
|
|
64
65
|
};
|
|
65
|
-
}, []);
|
|
66
|
+
}, [props.items, fm.demo]);
|
|
66
67
|
return /*#__PURE__*/React.createElement("div", {
|
|
67
68
|
style: {
|
|
68
69
|
display: 'flex',
|
|
@@ -12,6 +12,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
12
12
|
|
|
13
13
|
import { useRouteMeta, useSiteData } from 'dumi';
|
|
14
14
|
import ContentTabs from 'dumi/theme/slots/ContentTabs';
|
|
15
|
+
import nprogress from 'nprogress';
|
|
15
16
|
import React, { useEffect, useState } from 'react';
|
|
16
17
|
import { useTabQueryState } from "./useTabMeta";
|
|
17
18
|
export var DumiPage = function DumiPage(props) {
|
|
@@ -39,6 +40,7 @@ export var DumiPage = function DumiPage(props) {
|
|
|
39
40
|
|
|
40
41
|
useEffect(function () {
|
|
41
42
|
setLoading(false);
|
|
43
|
+
nprogress.done();
|
|
42
44
|
}, []);
|
|
43
45
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
|
|
44
46
|
tabs: tabs,
|
|
@@ -59,6 +59,7 @@ export interface IRouteMeta {
|
|
|
59
59
|
nav?: string | {
|
|
60
60
|
title?: string;
|
|
61
61
|
order?: number;
|
|
62
|
+
parent?: Omit<IRouteMeta['frontmatter']['nav'], 'parent'>;
|
|
62
63
|
};
|
|
63
64
|
group?: string | {
|
|
64
65
|
title?: string;
|
|
@@ -134,6 +135,10 @@ export interface IRouteMeta {
|
|
|
134
135
|
[key: string]: any;
|
|
135
136
|
};
|
|
136
137
|
}[];
|
|
138
|
+
/**
|
|
139
|
+
* private field, will be removed in the future
|
|
140
|
+
*/
|
|
141
|
+
_atom_route?: boolean;
|
|
137
142
|
}
|
|
138
143
|
declare type IBasicLocale = {
|
|
139
144
|
id: string;
|
|
@@ -147,7 +152,7 @@ export declare type ILocale = (IBasicLocale & {
|
|
|
147
152
|
export declare type ILocalesConfig = ILocale[];
|
|
148
153
|
export interface INavItem {
|
|
149
154
|
title: string;
|
|
150
|
-
link
|
|
155
|
+
link?: string;
|
|
151
156
|
order?: number;
|
|
152
157
|
activePath?: string;
|
|
153
158
|
[key: string]: any;
|
|
@@ -192,10 +197,12 @@ export interface IThemeConfig {
|
|
|
192
197
|
nav?: IUserNavValue | NavWithMode<IUserNavValue>;
|
|
193
198
|
sidebar?: Record<string, ISidebarGroup[]>;
|
|
194
199
|
footer?: string | false;
|
|
200
|
+
showLineNum?: boolean;
|
|
195
201
|
prefersColor: {
|
|
196
202
|
default: 'light' | 'dark' | 'auto';
|
|
197
203
|
switch: boolean;
|
|
198
204
|
};
|
|
205
|
+
nprogress?: boolean;
|
|
199
206
|
socialLinks: {
|
|
200
207
|
[key in SocialTypes]: string;
|
|
201
208
|
};
|
|
@@ -18,13 +18,30 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
18
18
|
|
|
19
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
20
|
|
|
21
|
+
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; }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
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; }
|
|
26
|
+
|
|
21
27
|
import { useFullSidebarData, useLocale, useSiteData } from 'dumi';
|
|
22
28
|
import { useState } from 'react';
|
|
23
29
|
import { getLocaleNav, pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
30
|
+
|
|
31
|
+
function genNavItem(meta, groups, activePath, link) {
|
|
32
|
+
return _objectSpread({
|
|
33
|
+
title: meta.title || groups[0].title || groups[0].children[0].title,
|
|
34
|
+
order: meta.order || 0,
|
|
35
|
+
activePath: activePath
|
|
36
|
+
}, link ? {
|
|
37
|
+
link: link
|
|
38
|
+
} : {});
|
|
39
|
+
}
|
|
24
40
|
/**
|
|
25
41
|
* hook for get nav data
|
|
26
42
|
*/
|
|
27
43
|
|
|
44
|
+
|
|
28
45
|
export var useNavData = function useNavData() {
|
|
29
46
|
var locale = useLocale();
|
|
30
47
|
var routes = useLocaleDocRoutes();
|
|
@@ -54,28 +71,73 @@ export var useNavData = function useNavData() {
|
|
|
54
71
|
} // fallback to generate nav data from sidebar data
|
|
55
72
|
|
|
56
73
|
|
|
57
|
-
var data = Object.entries(sidebar)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
var data = Object.values(Object.entries(sidebar) // make sure shallow nav item before deep
|
|
75
|
+
.sort(function (_ref, _ref2) {
|
|
76
|
+
var _ref3 = _slicedToArray(_ref, 1),
|
|
77
|
+
a = _ref3[0];
|
|
78
|
+
|
|
79
|
+
var _ref4 = _slicedToArray(_ref2, 1),
|
|
80
|
+
b = _ref4[0];
|
|
81
|
+
|
|
82
|
+
return a.split('/').length - b.split('/').length;
|
|
83
|
+
}) // convert sidebar data to nav data
|
|
84
|
+
.reduce(function (ret, _ref5) {
|
|
85
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
86
|
+
link = _ref6[0],
|
|
87
|
+
groups = _ref6[1];
|
|
61
88
|
|
|
62
|
-
var
|
|
89
|
+
var _ref7 = link.match(/^(\/[^/]+)([^]+)?$/),
|
|
90
|
+
_ref8 = _slicedToArray(_ref7, 3),
|
|
91
|
+
parentPath = _ref8[1],
|
|
92
|
+
restPath = _ref8[2];
|
|
93
|
+
|
|
94
|
+
var isNestedNav = Boolean(restPath);
|
|
95
|
+
|
|
96
|
+
var _Object$values$reduce = Object.values(routes).reduce(function (ret, route) {
|
|
63
97
|
// find routes which within the nav path
|
|
64
98
|
if (route.path.startsWith(link.slice(1))) {
|
|
65
|
-
pickRouteSortMeta(ret, 'nav', route.meta.frontmatter);
|
|
99
|
+
pickRouteSortMeta(ret[0], 'nav', route.meta.frontmatter); // generate parent meta for nested nav
|
|
100
|
+
|
|
101
|
+
if (isNestedNav) pickRouteSortMeta(ret[1], 'nav.parent', route.meta.frontmatter);
|
|
66
102
|
}
|
|
67
103
|
|
|
68
104
|
return ret;
|
|
69
|
-
}, {})
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
}, [{}, {}]),
|
|
106
|
+
_Object$values$reduce2 = _slicedToArray(_Object$values$reduce, 2),
|
|
107
|
+
rootMeta = _Object$values$reduce2[0],
|
|
108
|
+
parentMeta = _Object$values$reduce2[1];
|
|
109
|
+
|
|
110
|
+
if (isNestedNav) {
|
|
111
|
+
var _parentMeta$title, _ret$parentPath, _parent$children;
|
|
112
|
+
|
|
113
|
+
// fallback to use parent path as title
|
|
114
|
+
(_parentMeta$title = parentMeta.title) !== null && _parentMeta$title !== void 0 ? _parentMeta$title : parentMeta.title = parentPath.slice(1).replace(/^[a-z]/, function (s) {
|
|
115
|
+
return s.toUpperCase();
|
|
116
|
+
}); // handle nested nav item as parent children
|
|
117
|
+
|
|
118
|
+
var parent = (_ret$parentPath = ret[parentPath]) !== null && _ret$parentPath !== void 0 ? _ret$parentPath : ret[parentPath] = genNavItem(parentMeta, groups, parentPath);
|
|
119
|
+
(_parent$children = parent.children) !== null && _parent$children !== void 0 ? _parent$children : parent.children = [];
|
|
120
|
+
ret[parentPath].children.push(genNavItem(rootMeta, groups, link, groups[0].children[0].link));
|
|
121
|
+
} else {
|
|
122
|
+
// handle root nav item
|
|
123
|
+
ret[link] = genNavItem(rootMeta, groups, link, groups[0].children[0].link);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return ret;
|
|
127
|
+
}, {}));
|
|
128
|
+
data.forEach(function (item, i) {
|
|
129
|
+
var _item$children;
|
|
130
|
+
|
|
131
|
+
if (!item.link && ((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) === 1) {
|
|
132
|
+
// hoist nav item if only one child
|
|
133
|
+
data[i] = item.children[0];
|
|
134
|
+
} else if (item.children) {
|
|
135
|
+
// sort nav item children by order or title
|
|
136
|
+
item.children.sort(sidebarDataComparer);
|
|
137
|
+
}
|
|
138
|
+
}); // sort nav items by order or title
|
|
78
139
|
|
|
140
|
+
data.sort(sidebarDataComparer);
|
|
79
141
|
if (mode === 'prepend') data.unshift.apply(data, _toConsumableArray(userNavValue));else if (mode === 'append') data.push.apply(data, _toConsumableArray(userNavValue));
|
|
80
142
|
return data;
|
|
81
143
|
}),
|
|
@@ -26,7 +26,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
26
26
|
|
|
27
27
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
28
|
|
|
29
|
-
import { useLocale, useLocation, useSiteData } from 'dumi';
|
|
29
|
+
import { useLocale, useLocation, useRouteMeta, useSiteData } from 'dumi';
|
|
30
30
|
import { useState } from 'react';
|
|
31
31
|
import { pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
32
32
|
var DEFAULT_GROUP_STUB_TITLE = '$default-group-title';
|
|
@@ -34,6 +34,22 @@ var DEFAULT_GROUP_STUB_TITLE = '$default-group-title';
|
|
|
34
34
|
var getLocaleClearPath = function getLocaleClearPath(routePath, locale) {
|
|
35
35
|
return 'base' in locale ? routePath.replace(locale.base.slice(1), '').replace(/^\//, '') : routePath;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* get parent path from route path
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function getRouteParentPath(path, meta) {
|
|
43
|
+
var _meta$frontmatter$fil;
|
|
44
|
+
|
|
45
|
+
var isIndexRoute = ((_meta$frontmatter$fil = meta.frontmatter.filename) === null || _meta$frontmatter$fil === void 0 ? void 0 : _meta$frontmatter$fil.endsWith('index.md')) && !meta._atom_route;
|
|
46
|
+
var paths = path.split('/');
|
|
47
|
+
var sliceEnd = Math.min(Math.max( // increase 1 level if route file is index.md
|
|
48
|
+
isIndexRoute ? paths.length : paths.length - 1, // least 1-level
|
|
49
|
+
1), // up to 2-level
|
|
50
|
+
2);
|
|
51
|
+
return paths.slice(0, sliceEnd).join('/');
|
|
52
|
+
}
|
|
37
53
|
/**
|
|
38
54
|
* hook for get sidebar data for all nav
|
|
39
55
|
*/
|
|
@@ -57,12 +73,16 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
57
73
|
var _ret$parentPath, _ret$parentPath$title, _ret$parentPath$title2;
|
|
58
74
|
|
|
59
75
|
// extract parent path from route path
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
76
|
+
// normal examples:
|
|
77
|
+
// a => /a
|
|
78
|
+
// en-US/a => /en-US/a
|
|
79
|
+
// a/b => /a
|
|
80
|
+
// en-US/a/b => /en-US/a
|
|
81
|
+
// convention 2-level navs examples:
|
|
82
|
+
// a/b => /a/b (if route file is a/b/index.md)
|
|
83
|
+
// a/b/c => /a/b
|
|
64
84
|
var parentPath = "/".concat(route.path.replace(clearPath, function (s) {
|
|
65
|
-
return s.
|
|
85
|
+
return getRouteParentPath(s, route.meta);
|
|
66
86
|
}));
|
|
67
87
|
|
|
68
88
|
var _pickRouteSortMeta = pickRouteSortMeta({
|
|
@@ -220,6 +240,7 @@ export var useSidebarData = function useSidebarData() {
|
|
|
220
240
|
var _useLocation = useLocation(),
|
|
221
241
|
pathname = _useLocation.pathname;
|
|
222
242
|
|
|
243
|
+
var meta = useRouteMeta();
|
|
223
244
|
var clearPath = getLocaleClearPath(pathname.slice(1), locale); // extract parent path from location pathname
|
|
224
245
|
// /a => /a
|
|
225
246
|
// /a/b => /a
|
|
@@ -228,7 +249,7 @@ export var useSidebarData = function useSidebarData() {
|
|
|
228
249
|
// /en-US/a/b/ => /en-US/a (also strip trailing /)
|
|
229
250
|
|
|
230
251
|
var parentPath = clearPath ? pathname.replace(clearPath, function (s) {
|
|
231
|
-
return s
|
|
252
|
+
return getRouteParentPath(s, meta);
|
|
232
253
|
}) : pathname;
|
|
233
254
|
return parentPath ? sidebar[parentPath] : [];
|
|
234
255
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
2
|
import type { ILocale, INav, INavItem, IRouteMeta, IRoutesById, IUserNavValue } from './types';
|
|
3
3
|
export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
4
4
|
/**
|
|
@@ -7,7 +7,7 @@ export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
|
7
7
|
* @returns code string
|
|
8
8
|
*/
|
|
9
9
|
export declare const genReactRenderCode: (version: string) => string;
|
|
10
|
-
export declare const useIsomorphicLayoutEffect: typeof
|
|
10
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
11
11
|
/**
|
|
12
12
|
* common comparer for sidebar/nav items
|
|
13
13
|
*/
|
|
@@ -20,5 +20,5 @@ export declare const useRouteDataComparer: <T extends {
|
|
|
20
20
|
/**
|
|
21
21
|
* common util for pick meta to sort sidebar/nav items
|
|
22
22
|
*/
|
|
23
|
-
export declare const pickRouteSortMeta: (original: Partial<Pick<INavItem, 'order' | 'title'>>, field: 'nav' | 'group', fm: IRouteMeta['frontmatter']) => Partial<Pick<INavItem, "title" | "order">>;
|
|
23
|
+
export declare const pickRouteSortMeta: (original: Partial<Pick<INavItem, 'order' | 'title'>>, field: 'nav' | 'nav.parent' | 'group', fm: IRouteMeta['frontmatter']) => Partial<Pick<INavItem, "title" | "order">>;
|
|
24
24
|
export declare function getLocaleNav(nav: IUserNavValue | INav, locale: ILocale): import("./types").IUserNavItems;
|
|
@@ -83,7 +83,7 @@ export var useRouteDataComparer = function useRouteDataComparer() {
|
|
|
83
83
|
export var pickRouteSortMeta = function pickRouteSortMeta(original, field, fm) {
|
|
84
84
|
var _sub$order;
|
|
85
85
|
|
|
86
|
-
var sub = fm[field];
|
|
86
|
+
var sub = field === 'nav.parent' ? _typeof(fm.nav) === 'object' ? fm.nav.parent : {} : fm[field];
|
|
87
87
|
|
|
88
88
|
switch (_typeof(sub)) {
|
|
89
89
|
case 'object':
|
|
@@ -29,7 +29,6 @@ var import_utils = require("../utils");
|
|
|
29
29
|
var import_fs = __toESM(require("fs"));
|
|
30
30
|
var import_path = __toESM(require("path"));
|
|
31
31
|
var autoAlias_default = (api) => {
|
|
32
|
-
let entryDir;
|
|
33
32
|
api.describe({
|
|
34
33
|
key: "autoAlias",
|
|
35
34
|
config: {
|
|
@@ -37,33 +36,31 @@ var autoAlias_default = (api) => {
|
|
|
37
36
|
},
|
|
38
37
|
enableBy: () => !!api.pkg.name
|
|
39
38
|
});
|
|
40
|
-
api.
|
|
41
|
-
var _a;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
memo.fatherConfigs = await (0, import_utils.tryFatherBuildConfigs)(api.cwd);
|
|
48
|
-
return memo;
|
|
49
|
-
});
|
|
50
|
-
api.chainWebpack((memo) => {
|
|
51
|
-
const fatherConfigs = api.appData.fatherConfigs;
|
|
39
|
+
api.modifyConfig(async (memo) => {
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
const fatherConfigs = await api.applyPlugins({
|
|
42
|
+
key: "dumi.modifyFatherConfigs",
|
|
43
|
+
type: api.ApplyPluginsType.modify,
|
|
44
|
+
initialValue: await (0, import_utils.tryFatherBuildConfigs)(api.cwd)
|
|
45
|
+
});
|
|
52
46
|
fatherConfigs.sort((a, b) => {
|
|
53
|
-
var
|
|
54
|
-
const aLevel = (((
|
|
55
|
-
const bLevel = (((
|
|
47
|
+
var _a2, _b2;
|
|
48
|
+
const aLevel = (((_a2 = a.output) == null ? void 0 : _a2.path) || a.output).split("/").length;
|
|
49
|
+
const bLevel = (((_b2 = b.output) == null ? void 0 : _b2.path) || b.output).split("/").length;
|
|
56
50
|
return bLevel - aLevel;
|
|
57
51
|
});
|
|
58
52
|
fatherConfigs.forEach((item) => {
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
if (!memo.resolve.alias.has(key)) {
|
|
62
|
-
memo.resolve.alias.set(key, import_path.default.join(api.cwd, item.entry || item.input));
|
|
63
|
-
}
|
|
53
|
+
var _a2, _b2, _c2;
|
|
54
|
+
(_b2 = memo.alias)[_c2 = `${api.pkg.name}/${((_a2 = item.output) == null ? void 0 : _a2.path) || item.output}`] ?? (_b2[_c2] = import_path.default.join(api.cwd, item.entry || item.input));
|
|
64
55
|
});
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
let entryDir = "";
|
|
57
|
+
if ((_a = memo.resolve) == null ? void 0 : _a.entryFile) {
|
|
58
|
+
entryDir = import_path.default.resolve(api.cwd, memo.resolve.entryFile);
|
|
59
|
+
} else if (import_fs.default.existsSync(import_path.default.join(api.cwd, "src"))) {
|
|
60
|
+
entryDir = import_path.default.join(api.cwd, "src");
|
|
61
|
+
}
|
|
62
|
+
if (entryDir) {
|
|
63
|
+
(_b = memo.alias)[_c = api.pkg.name] ?? (_b[_c] = entryDir);
|
|
67
64
|
}
|
|
68
65
|
return memo;
|
|
69
66
|
});
|
|
@@ -33,7 +33,8 @@ var configPlugins_default = (api) => {
|
|
|
33
33
|
},
|
|
34
34
|
themeConfig: {
|
|
35
35
|
footer: `Copyright \xA9 ${new Date().getFullYear()} | Powered by <a href="https://d.umijs.org" target="_blank" rel="noreferrer">dumi</a>`,
|
|
36
|
-
prefersColor: { default: "light", switch: true }
|
|
36
|
+
prefersColor: { default: "light", switch: true },
|
|
37
|
+
nprogress: true
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
const schemas = (0, import_schema.getSchemas)();
|
|
@@ -30,7 +30,6 @@ function getSchemas() {
|
|
|
30
30
|
resolve: (Joi) => Joi.object({
|
|
31
31
|
docDirs: Joi.array().items(Joi.alternatives(Joi.string(), Joi.object({ dir: Joi.string(), type: Joi.string().optional() }))).optional(),
|
|
32
32
|
atomDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
|
|
33
|
-
entityDirs: Joi.forbidden().error(new Error("`entityDirs` is already deprecated, please rename it to `atomDirs` in `.dumirc.ts`")),
|
|
34
33
|
codeBlockMode: Joi.string().valid("active", "passive").optional(),
|
|
35
34
|
entryFile: Joi.string().optional(),
|
|
36
35
|
forceKebabCaseRouting: Joi.bool().optional()
|
package/dist/features/locales.js
CHANGED
|
@@ -98,7 +98,8 @@ const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
|
|
|
98
98
|
// suffix mode
|
|
99
99
|
? history.location.pathname.replace(/([^/])\\/$/, '$1').endsWith(locale.suffix)
|
|
100
100
|
// base mode
|
|
101
|
-
: history.location.pathname.replace(/([^/])\\/$/, '$1')
|
|
101
|
+
: history.location.pathname.replace(/([^/])\\/$/, '$1')
|
|
102
|
+
.startsWith("${api.config.base.replace(/\/$/, "")}" + locale.base)
|
|
102
103
|
));
|
|
103
104
|
const locale = matched ? matched.id : locales[0].id;
|
|
104
105
|
|