dumi 2.0.0-beta.1 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/forkedDev.js +3 -0
- package/dist/assetParsers/atom.d.ts +14 -18
- package/dist/assetParsers/atom.js +61 -23
- package/dist/assetParsers/block.d.ts +1 -4
- package/dist/assetParsers/block.js +2 -12
- package/dist/cli.js +2 -2
- package/dist/client/theme-api/DumiDemo.js +2 -1
- package/dist/client/theme-api/DumiDemoGrid.js +2 -1
- package/dist/client/theme-api/DumiPage.d.ts +4 -0
- package/dist/client/theme-api/DumiPage.js +60 -0
- package/dist/client/theme-api/context.d.ts +5 -0
- package/dist/client/theme-api/context.js +2 -0
- package/dist/client/theme-api/index.d.ts +5 -1
- package/dist/client/theme-api/index.js +6 -2
- package/dist/client/theme-api/types.d.ts +48 -3
- package/dist/client/theme-api/useAtomAssets.d.ts +4 -0
- package/dist/client/theme-api/useAtomAssets.js +9 -0
- package/dist/client/theme-api/useLocale.d.ts +2 -1
- package/dist/client/theme-api/useNavData.js +2 -2
- package/dist/client/theme-api/useRouteMeta.js +4 -3
- package/dist/client/theme-api/useSidebarData.d.ts +3 -2
- package/dist/client/theme-api/useSidebarData.js +4 -2
- package/dist/client/theme-api/useSiteSearch.d.ts +23 -0
- package/dist/client/theme-api/useSiteSearch.js +347 -0
- package/dist/client/theme-api/useTabMeta.d.ts +4 -0
- package/dist/client/theme-api/useTabMeta.js +47 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +11 -0
- package/dist/features/assets.d.ts +12 -0
- package/dist/features/assets.js +67 -0
- package/dist/features/compile.js +13 -2
- package/dist/features/configPlugins/index.js +1 -1
- package/dist/features/configPlugins/schema.js +7 -4
- package/dist/features/exports.d.ts +5 -0
- package/dist/features/exports.js +23 -2
- package/dist/features/locales.js +19 -7
- package/dist/features/meta.d.ts +2 -0
- package/dist/features/meta.js +86 -31
- package/dist/features/parser.d.ts +3 -0
- package/dist/features/parser.js +70 -0
- package/dist/features/routes.js +42 -20
- package/dist/features/tabs.d.ts +14 -0
- package/dist/features/tabs.js +128 -0
- package/dist/features/theme/index.js +20 -8
- package/dist/features/theme/loader.d.ts +4 -0
- package/dist/features/theme/loader.js +5 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -1
- package/dist/loaders/markdown/index.d.ts +3 -2
- package/dist/loaders/markdown/index.js +69 -45
- package/dist/loaders/markdown/transformer/index.d.ts +10 -5
- package/dist/loaders/markdown/transformer/index.js +13 -7
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +4 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +24 -9
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +9 -1
- package/dist/loaders/markdown/transformer/rehypeImg.d.ts +6 -0
- package/dist/loaders/markdown/transformer/rehypeImg.js +57 -0
- package/dist/loaders/markdown/transformer/rehypeJsxify.js +18 -2
- package/dist/loaders/markdown/transformer/rehypeSlug.d.ts +2 -2
- package/dist/loaders/markdown/transformer/rehypeSlug.js +21 -57
- package/dist/loaders/markdown/transformer/rehypeText.d.ts +4 -0
- package/dist/loaders/markdown/transformer/rehypeText.js +110 -0
- package/dist/loaders/markdown/transformer/remarkEmbed.d.ts +4 -0
- package/dist/loaders/markdown/transformer/remarkEmbed.js +93 -0
- package/dist/loaders/markdown/transformer/remarkMeta.js +7 -2
- package/dist/loaders/page/index.d.ts +1 -0
- package/dist/loaders/page/index.js +42 -0
- package/dist/preset.js +4 -1
- package/dist/registerMethods.js +6 -1
- package/dist/service/cli.d.ts +5 -0
- package/dist/service/cli.js +69 -0
- package/dist/service/constants.d.ts +4 -0
- package/dist/service/constants.js +38 -0
- package/dist/service/dev.d.ts +1 -0
- package/dist/service/dev.js +45 -0
- package/dist/service/forkedDev.d.ts +1 -0
- package/dist/service/forkedDev.js +37 -0
- package/dist/service/printHelp.d.ts +1 -0
- package/dist/service/printHelp.js +37 -0
- package/dist/service/service.d.ts +13 -0
- package/dist/service/service.js +63 -0
- package/dist/types.d.ts +25 -3
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +34 -2
- package/index.d.ts +11 -0
- package/package.json +21 -14
- package/theme-default/builtins/API/index.d.ts +5 -0
- package/theme-default/builtins/API/index.js +58 -0
- package/theme-default/builtins/Previewer/index.js +1 -0
- package/theme-default/builtins/Table/index.d.ts +6 -0
- package/theme-default/builtins/Table/index.js +59 -0
- package/theme-default/builtins/Table/index.less +61 -0
- package/theme-default/layouts/DocLayout/index.js +3 -1
- package/theme-default/layouts/DocLayout/index.less +9 -4
- package/theme-default/locales/en-US.json +10 -1
- package/theme-default/locales/zh-CN.json +10 -1
- package/theme-default/slots/Content/index.less +19 -1
- package/theme-default/slots/ContentTabs/index.d.ts +11 -0
- package/theme-default/slots/ContentTabs/index.js +35 -0
- package/theme-default/slots/ContentTabs/index.less +57 -0
- package/theme-default/slots/Features/index.d.ts +4 -0
- package/theme-default/slots/Features/index.js +28 -0
- package/theme-default/slots/Features/index.less +49 -0
- package/theme-default/slots/Header/index.js +9 -2
- package/theme-default/slots/Header/index.less +18 -10
- package/theme-default/slots/Hero/index.d.ts +4 -0
- package/theme-default/slots/Hero/index.js +35 -0
- package/theme-default/slots/Hero/index.less +65 -0
- package/theme-default/slots/HeroTitle/index.d.ts +6 -0
- package/theme-default/slots/HeroTitle/index.js +10 -0
- package/theme-default/slots/HeroTitle/index.less +23 -0
- package/theme-default/slots/LangSwitch/index.js +33 -16
- package/theme-default/slots/LangSwitch/index.less +23 -0
- package/theme-default/slots/SearchBar/index.js +69 -9
- package/theme-default/slots/SearchBar/index.less +37 -4
- package/theme-default/slots/SearchResult/index.d.ts +9 -0
- package/theme-default/slots/SearchResult/index.js +168 -0
- package/theme-default/slots/SearchResult/index.less +119 -0
- package/theme-default/styles/variables.less +1 -0
- package/dist/client/tsconfig.json +0 -13
- package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +0 -12
- package/dist/loaders/markdown/transformer/rehypeEmbed.js +0 -87
package/bin/forkedDev.js
ADDED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { webpack } from 'umi';
|
|
3
|
-
declare class AtomParserWatchWebpackPlugin {
|
|
4
|
-
resolveDir: string;
|
|
5
|
-
onWatchRun: (files: string[]) => void;
|
|
6
|
-
constructor(opts: {
|
|
7
|
-
resolveDir: string;
|
|
8
|
-
onWatchRun: typeof AtomParserWatchWebpackPlugin.prototype.onWatchRun;
|
|
9
|
-
});
|
|
10
|
-
apply(compiler: webpack.Compiler): void;
|
|
11
|
-
}
|
|
1
|
+
import { AtomComponentAsset, AtomFunctionAsset } from 'dumi-assets-types';
|
|
12
2
|
declare class AtomAssetsParser {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
private entryDir;
|
|
4
|
+
private resolveDir;
|
|
5
|
+
private unresolvedFiles;
|
|
6
|
+
private parser;
|
|
7
|
+
private resolverDeferrer;
|
|
8
|
+
private watcher;
|
|
9
|
+
private cbs;
|
|
17
10
|
constructor(opts: {
|
|
18
11
|
entryFile: string;
|
|
19
12
|
resolveDir: string;
|
|
13
|
+
watch?: boolean;
|
|
20
14
|
});
|
|
21
|
-
parse(): Promise<
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
parse(): Promise<{
|
|
16
|
+
components: Record<string, AtomComponentAsset>;
|
|
17
|
+
functions: Record<string, AtomFunctionAsset>;
|
|
18
|
+
}>;
|
|
19
|
+
watch(cb: AtomAssetsParser['cbs'][number]): void;
|
|
24
20
|
}
|
|
25
21
|
export default AtomAssetsParser;
|
|
@@ -28,22 +28,14 @@ module.exports = __toCommonJS(atom_exports);
|
|
|
28
28
|
var import_parser = require("dumi-afx-deps/compiled/parser");
|
|
29
29
|
var import_path = __toESM(require("path"));
|
|
30
30
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
31
|
-
var
|
|
32
|
-
constructor(opts) {
|
|
33
|
-
this.resolveDir = opts.resolveDir;
|
|
34
|
-
this.onWatchRun = opts.onWatchRun;
|
|
35
|
-
}
|
|
36
|
-
apply(compiler) {
|
|
37
|
-
compiler.hooks.watchRun.tap(this.constructor.name, (compilation) => {
|
|
38
|
-
const files = Array.from(compilation.watchFileSystem.watcher.fileWatchers.keys());
|
|
39
|
-
this.onWatchRun(files.map((file) => (0, import_plugin_utils.winPath)(import_path.default.relative(this.resolveDir, file))).filter((file) => /\.(j|t)sx?$/.test(file) && !file.startsWith("../") && !file.includes(".umi")));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
31
|
+
var MAX_PARSE_SIZE = 1024 * 512;
|
|
43
32
|
var AtomAssetsParser = class {
|
|
44
33
|
constructor(opts) {
|
|
45
34
|
this.unresolvedFiles = [];
|
|
35
|
+
this.watcher = null;
|
|
36
|
+
this.cbs = [];
|
|
46
37
|
this.resolveDir = opts.resolveDir;
|
|
38
|
+
this.entryDir = import_path.default.relative(opts.resolveDir, import_path.default.dirname(opts.entryFile));
|
|
47
39
|
this.parser = new import_parser.SchemaParser({
|
|
48
40
|
entryPath: opts.entryFile,
|
|
49
41
|
basePath: opts.resolveDir,
|
|
@@ -51,23 +43,69 @@ var AtomAssetsParser = class {
|
|
|
51
43
|
});
|
|
52
44
|
}
|
|
53
45
|
async parse() {
|
|
54
|
-
if (!this.
|
|
55
|
-
this.
|
|
46
|
+
if (!this.resolverDeferrer || this.unresolvedFiles.length) {
|
|
47
|
+
this.resolverDeferrer = (async () => {
|
|
56
48
|
await this.parser.patch(this.unresolvedFiles);
|
|
57
49
|
return new import_parser.SchemaResolver(await this.parser.parse());
|
|
58
50
|
})();
|
|
59
51
|
}
|
|
60
|
-
return this.resolver
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
return this.resolverDeferrer.then((resolver) => {
|
|
53
|
+
const components = {};
|
|
54
|
+
const functions = {};
|
|
55
|
+
resolver.componentList.forEach((id) => {
|
|
56
|
+
let propsConfig = resolver.getComponent(id).props;
|
|
57
|
+
const size = Buffer.byteLength(JSON.stringify(propsConfig));
|
|
58
|
+
if (size > MAX_PARSE_SIZE) {
|
|
59
|
+
propsConfig = { type: "object", properties: {} };
|
|
60
|
+
import_plugin_utils.logger.warn(`Parsed component ${id} props size ${size} exceeds 512KB, skip it.`);
|
|
61
|
+
}
|
|
62
|
+
components[id] = {
|
|
63
|
+
type: "COMPONENT",
|
|
64
|
+
id,
|
|
65
|
+
title: id,
|
|
66
|
+
propsConfig
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
resolver.functionList.forEach((id) => {
|
|
70
|
+
let signature = resolver.getFunction(id).signature;
|
|
71
|
+
const size = Buffer.byteLength(JSON.stringify(signature));
|
|
72
|
+
if (size > MAX_PARSE_SIZE) {
|
|
73
|
+
signature = { arguments: [] };
|
|
74
|
+
import_plugin_utils.logger.warn(`Parsed function ${id} signature size ${size} exceeds 512KB, skip it.`);
|
|
75
|
+
}
|
|
76
|
+
functions[id] = {
|
|
77
|
+
type: "FUNCTION",
|
|
78
|
+
id,
|
|
79
|
+
title: id,
|
|
80
|
+
signature
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
return { components, functions };
|
|
69
84
|
});
|
|
70
85
|
}
|
|
86
|
+
watch(cb) {
|
|
87
|
+
this.cbs.push(cb);
|
|
88
|
+
if (!this.watcher) {
|
|
89
|
+
const lazyParse = import_plugin_utils.lodash.debounce(() => {
|
|
90
|
+
this.parse().then((data) => this.cbs.forEach((cb2) => cb2(data)));
|
|
91
|
+
}, 100);
|
|
92
|
+
this.watcher = import_plugin_utils.chokidar.watch(this.entryDir, {
|
|
93
|
+
cwd: this.resolveDir,
|
|
94
|
+
ignored: [
|
|
95
|
+
"**/.*",
|
|
96
|
+
"**/.*/**",
|
|
97
|
+
"**/_*",
|
|
98
|
+
"**/_*/**",
|
|
99
|
+
"**/*.{md,less,scss,sass,styl,css}"
|
|
100
|
+
]
|
|
101
|
+
}).on("all", (ev, file) => {
|
|
102
|
+
if (["add", "change"].includes(ev) && /\.(j|t)sx?$/.test(file)) {
|
|
103
|
+
this.unresolvedFiles.push(file);
|
|
104
|
+
lazyParse();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
71
109
|
};
|
|
72
110
|
var atom_default = AtomAssetsParser;
|
|
73
111
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { parseCodeFrontmatter } from "../utils";
|
|
1
2
|
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
2
3
|
export interface IParsedBlockAsset {
|
|
3
4
|
asset: ExampleBlockAsset;
|
|
4
5
|
sources: Record<string, string>;
|
|
5
6
|
frontmatter: ReturnType<typeof parseCodeFrontmatter>['frontmatter'];
|
|
6
7
|
}
|
|
7
|
-
declare function parseCodeFrontmatter(raw: string): {
|
|
8
|
-
code: string;
|
|
9
|
-
frontmatter: Record<string, any> | null;
|
|
10
|
-
};
|
|
11
8
|
declare function parseBlockAsset(opts: {
|
|
12
9
|
fileAbsPath: string;
|
|
13
10
|
id: string;
|
|
@@ -25,21 +25,11 @@ __export(block_exports, {
|
|
|
25
25
|
default: () => block_default
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(block_exports);
|
|
28
|
+
var import_utils = require("../utils");
|
|
28
29
|
var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
|
|
29
30
|
var import_fs = __toESM(require("fs"));
|
|
30
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
31
31
|
var import_path = __toESM(require("path"));
|
|
32
32
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
33
|
-
function parseCodeFrontmatter(raw) {
|
|
34
|
-
const [, comment = "", code = ""] = raw.replace(/^\n\s*/, "").match(/^(\/\*\*[^]*?\n\s*\*\/)?(?:\s|\n)*([^]+)?$/);
|
|
35
|
-
const yamlComment = comment.replace(/^\/|\/$/g, "").replace(/(^|\n)\s*\*+/g, "$1");
|
|
36
|
-
let frontmatter = null;
|
|
37
|
-
try {
|
|
38
|
-
frontmatter = import_js_yaml.default.load(yamlComment);
|
|
39
|
-
} catch {
|
|
40
|
-
}
|
|
41
|
-
return { code: frontmatter ? code : raw, frontmatter };
|
|
42
|
-
}
|
|
43
33
|
async function parseBlockAsset(opts) {
|
|
44
34
|
const asset = {
|
|
45
35
|
type: "BLOCK",
|
|
@@ -101,7 +91,7 @@ async function parseBlockAsset(opts) {
|
|
|
101
91
|
value: opts.entryPointCode ?? import_fs.default.readFileSync(args.path, "utf-8")
|
|
102
92
|
};
|
|
103
93
|
if (isEntryPoint) {
|
|
104
|
-
const { code, frontmatter } = parseCodeFrontmatter(asset.dependencies[filename].value);
|
|
94
|
+
const { code, frontmatter } = (0, import_utils.parseCodeFrontmatter)(asset.dependencies[filename].value);
|
|
105
95
|
if (frontmatter) {
|
|
106
96
|
asset.dependencies[filename].value = code;
|
|
107
97
|
result.frontmatter = frontmatter;
|
package/dist/cli.js
CHANGED
|
@@ -15,12 +15,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
16
16
|
|
|
17
17
|
// src/cli.ts
|
|
18
|
-
var import_umi = require("umi");
|
|
19
18
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
19
|
+
var import_cli = require("./service/cli");
|
|
20
20
|
(async () => {
|
|
21
21
|
try {
|
|
22
22
|
import_plugin_utils.logger.info(import_plugin_utils.chalk.cyan.bold(`dumi v${require("../package").version}`));
|
|
23
|
-
await (0,
|
|
23
|
+
await (0, import_cli.run)({
|
|
24
24
|
presets: [require.resolve("./preset")]
|
|
25
25
|
});
|
|
26
26
|
} catch (e) {
|
|
@@ -11,9 +11,10 @@ export var DumiDemo = function DumiDemo(props) {
|
|
|
11
11
|
var _demos$props$demo$id = demos[props.demo.id],
|
|
12
12
|
component = _demos$props$demo$id.component,
|
|
13
13
|
asset = _demos$props$demo$id.asset;
|
|
14
|
+
if (props.demo.inline) return /*#__PURE__*/createElement(component);
|
|
14
15
|
return /*#__PURE__*/React.createElement(Previewer, _extends({
|
|
15
16
|
asset: asset,
|
|
16
17
|
demoUrl: // allow user override demoUrl by frontmatter
|
|
17
|
-
props.previewerProps.demoUrl || "".concat(SP_ROUTE_PREFIX, "demos/").concat(props.demo.id)
|
|
18
|
+
props.previewerProps.demoUrl || "/".concat(SP_ROUTE_PREFIX, "demos/").concat(props.demo.id)
|
|
18
19
|
}, props.previewerProps), /*#__PURE__*/createElement(component));
|
|
19
20
|
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { useLocation, useRouteMeta, useSiteData } from 'dumi';
|
|
14
|
+
import ContentTabs from 'dumi/theme/slots/ContentTabs';
|
|
15
|
+
import React, { useEffect, useState } from 'react';
|
|
16
|
+
import { useTabQueryState } from "./useTabMeta";
|
|
17
|
+
export var DumiPage = function DumiPage(props) {
|
|
18
|
+
var _useLocation = useLocation(),
|
|
19
|
+
hash = _useLocation.hash;
|
|
20
|
+
|
|
21
|
+
var _useRouteMeta = useRouteMeta(),
|
|
22
|
+
tabs = _useRouteMeta.tabs;
|
|
23
|
+
|
|
24
|
+
var _useTabQueryState = useTabQueryState(),
|
|
25
|
+
_useTabQueryState2 = _slicedToArray(_useTabQueryState, 2),
|
|
26
|
+
tabKey = _useTabQueryState2[0],
|
|
27
|
+
setTabKey = _useTabQueryState2[1];
|
|
28
|
+
|
|
29
|
+
var _useState = useState(function () {
|
|
30
|
+
return tabs === null || tabs === void 0 ? void 0 : tabs.find(function (_ref) {
|
|
31
|
+
var key = _ref.key;
|
|
32
|
+
return key === tabKey;
|
|
33
|
+
});
|
|
34
|
+
}),
|
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
+
tab = _useState2[0],
|
|
37
|
+
setTab = _useState2[1];
|
|
38
|
+
|
|
39
|
+
var _useSiteData = useSiteData(),
|
|
40
|
+
setLoading = _useSiteData.setLoading; // update loading status when page loaded
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
setLoading(false);
|
|
45
|
+
}, []); // handle hash change
|
|
46
|
+
|
|
47
|
+
useEffect(function () {
|
|
48
|
+
var id = hash.replace('#', '');
|
|
49
|
+
var elm = id && document.getElementById(id);
|
|
50
|
+
if (elm) elm.scrollIntoView();
|
|
51
|
+
}, [hash]);
|
|
52
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
|
|
53
|
+
tabs: tabs,
|
|
54
|
+
tabKey: tabKey,
|
|
55
|
+
onChange: function onChange(val) {
|
|
56
|
+
setTab(val);
|
|
57
|
+
setTabKey(val === null || val === void 0 ? void 0 : val.key);
|
|
58
|
+
}
|
|
59
|
+
}), tab ? /*#__PURE__*/React.createElement(tab.components.default) : props.children);
|
|
60
|
+
};
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { PICKED_PKG_FIELDS } from "../../constants";
|
|
2
|
+
import type { AtomComponentAsset } from 'dumi-assets-types';
|
|
1
3
|
import { type ComponentType } from 'react';
|
|
2
4
|
import type { ILocalesConfig, IPreviewerProps, IThemeConfig } from './types';
|
|
3
5
|
interface ISiteContext {
|
|
6
|
+
pkg: Partial<Record<keyof typeof PICKED_PKG_FIELDS, any>>;
|
|
4
7
|
demos: Record<string, {
|
|
5
8
|
component: ComponentType;
|
|
6
9
|
asset: IPreviewerProps['asset'];
|
|
10
|
+
routeId: string;
|
|
7
11
|
}>;
|
|
12
|
+
components: Record<string, AtomComponentAsset>;
|
|
8
13
|
locales: NonNullable<ILocalesConfig>;
|
|
9
14
|
themeConfig: IThemeConfig;
|
|
10
15
|
loading: boolean;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
export { useIntl } from 'react-intl';
|
|
1
|
+
export { createIntlCache, defineMessages, FormattedDate, FormattedDateParts, FormattedDisplayName, FormattedList, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl, } from 'react-intl';
|
|
2
2
|
export { useSiteData } from './context';
|
|
3
3
|
export { DumiDemo } from './DumiDemo';
|
|
4
4
|
export { DumiDemoGrid } from './DumiDemoGrid';
|
|
5
|
+
export { DumiPage } from './DumiPage';
|
|
5
6
|
export type { IPreviewerProps } from './types';
|
|
7
|
+
export { useAtomAssets } from './useAtomAssets';
|
|
6
8
|
export { useLocale } from './useLocale';
|
|
7
9
|
export { useNavData } from './useNavData';
|
|
8
10
|
export { useRouteMeta } from './useRouteMeta';
|
|
9
11
|
export { useFullSidebarData, useSidebarData } from './useSidebarData';
|
|
12
|
+
export { useSiteSearch } from './useSiteSearch';
|
|
13
|
+
export { useTabMeta } from './useTabMeta';
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export { useIntl } from 'react-intl';
|
|
1
|
+
export { createIntlCache, defineMessages, FormattedDate, FormattedDateParts, FormattedDisplayName, FormattedList, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl } from 'react-intl';
|
|
2
2
|
export { useSiteData } from "./context";
|
|
3
3
|
export { DumiDemo } from "./DumiDemo";
|
|
4
4
|
export { DumiDemoGrid } from "./DumiDemoGrid";
|
|
5
|
+
export { DumiPage } from "./DumiPage";
|
|
6
|
+
export { useAtomAssets } from "./useAtomAssets";
|
|
5
7
|
export { useLocale } from "./useLocale";
|
|
6
8
|
export { useNavData } from "./useNavData";
|
|
7
9
|
export { useRouteMeta } from "./useRouteMeta";
|
|
8
|
-
export { useFullSidebarData, useSidebarData } from "./useSidebarData";
|
|
10
|
+
export { useFullSidebarData, useSidebarData } from "./useSidebarData";
|
|
11
|
+
export { useSiteSearch } from "./useSiteSearch";
|
|
12
|
+
export { useTabMeta } from "./useTabMeta";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
3
3
|
export interface IPreviewerProps {
|
|
4
4
|
/**
|
|
5
5
|
* title of current demo
|
|
@@ -57,6 +57,22 @@ export interface IRouteMeta {
|
|
|
57
57
|
order?: number;
|
|
58
58
|
};
|
|
59
59
|
order?: number;
|
|
60
|
+
hero?: {
|
|
61
|
+
title?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
background?: string;
|
|
64
|
+
links?: {
|
|
65
|
+
title: string;
|
|
66
|
+
link: string;
|
|
67
|
+
}[];
|
|
68
|
+
[key: string]: any;
|
|
69
|
+
};
|
|
70
|
+
features?: {
|
|
71
|
+
emoji?: string;
|
|
72
|
+
title?: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}[];
|
|
60
76
|
toc?: boolean | 'content' | 'menu';
|
|
61
77
|
demo?: {
|
|
62
78
|
cols?: number;
|
|
@@ -68,17 +84,44 @@ export interface IRouteMeta {
|
|
|
68
84
|
depth: number;
|
|
69
85
|
title: string;
|
|
70
86
|
}[];
|
|
87
|
+
texts: {
|
|
88
|
+
type?: 'content';
|
|
89
|
+
value: string;
|
|
90
|
+
/**
|
|
91
|
+
* paragraph index
|
|
92
|
+
*/
|
|
93
|
+
paraId: number;
|
|
94
|
+
/**
|
|
95
|
+
* title index in toc
|
|
96
|
+
*/
|
|
97
|
+
tocIndex?: number;
|
|
98
|
+
}[];
|
|
99
|
+
tabs?: {
|
|
100
|
+
key: string;
|
|
101
|
+
components: {
|
|
102
|
+
default: ComponentType;
|
|
103
|
+
Extra: ComponentType;
|
|
104
|
+
Action: ComponentType;
|
|
105
|
+
};
|
|
106
|
+
meta: {
|
|
107
|
+
frontmatter: Omit<IRouteMeta['frontmatter'], 'description' | 'keywords' | 'nav' | 'group' | 'hero' | 'features'>;
|
|
108
|
+
toc: IRouteMeta['toc'];
|
|
109
|
+
texts: IRouteMeta['texts'];
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
};
|
|
112
|
+
}[];
|
|
71
113
|
[key: string]: any;
|
|
72
114
|
}
|
|
73
115
|
declare type IBasicLocale = {
|
|
74
116
|
id: string;
|
|
75
117
|
name: string;
|
|
76
118
|
};
|
|
77
|
-
export declare type
|
|
119
|
+
export declare type ILocale = ((IBasicLocale & {
|
|
78
120
|
base: string;
|
|
79
121
|
}) | (IBasicLocale & {
|
|
80
122
|
suffix: string;
|
|
81
|
-
}))
|
|
123
|
+
}));
|
|
124
|
+
export declare type ILocalesConfig = ILocale[];
|
|
82
125
|
export interface INavItem {
|
|
83
126
|
title: string;
|
|
84
127
|
link: string;
|
|
@@ -88,6 +131,8 @@ export interface INavItem {
|
|
|
88
131
|
interface ISidebarItem {
|
|
89
132
|
title: string;
|
|
90
133
|
link: string;
|
|
134
|
+
order: number;
|
|
135
|
+
frontmatter: IRouteMeta['frontmatter'];
|
|
91
136
|
[key: string]: any;
|
|
92
137
|
}
|
|
93
138
|
export interface ISidebarGroup {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ILocale } from './types';
|
|
2
|
+
export declare const useLocale: () => ILocale;
|
|
@@ -37,11 +37,11 @@ export var useNavData = function useNavData() {
|
|
|
37
37
|
groups = _ref2[1];
|
|
38
38
|
|
|
39
39
|
var meta = Object.values(routes).reduce(function (ret, route) {
|
|
40
|
-
var _frontmatter$nav$orde;
|
|
40
|
+
var _route$meta, _frontmatter$nav$orde;
|
|
41
41
|
|
|
42
42
|
// find routes which within the nav path
|
|
43
43
|
if (route.path.startsWith(link.slice(1))) {
|
|
44
|
-
switch (_typeof(route.meta.frontmatter.nav)) {
|
|
44
|
+
switch (_typeof((_route$meta = route.meta) === null || _route$meta === void 0 ? void 0 : _route$meta.frontmatter.nav)) {
|
|
45
45
|
case 'object':
|
|
46
46
|
ret.title = route.meta.frontmatter.nav.title || ret.title;
|
|
47
47
|
ret.order = (_frontmatter$nav$orde = route.meta.frontmatter.nav.order) !== null && _frontmatter$nav$orde !== void 0 ? _frontmatter$nav$orde : ret.order;
|
|
@@ -11,7 +11,7 @@ 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,
|
|
14
|
+
import { useCallback, useLayoutEffect, useState } from 'react';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* hook for get matched route meta
|
|
@@ -42,7 +42,8 @@ export var useRouteMeta = function useRouteMeta() {
|
|
|
42
42
|
|
|
43
43
|
return ret || {
|
|
44
44
|
frontmatter: {},
|
|
45
|
-
toc: []
|
|
45
|
+
toc: [],
|
|
46
|
+
texts: []
|
|
46
47
|
};
|
|
47
48
|
}, [clientRoutes.length, pathname]);
|
|
48
49
|
|
|
@@ -51,7 +52,7 @@ export var useRouteMeta = function useRouteMeta() {
|
|
|
51
52
|
meta = _useState2[0],
|
|
52
53
|
setMeta = _useState2[1];
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
useLayoutEffect(function () {
|
|
55
56
|
setMeta(getter);
|
|
56
57
|
}, [clientRoutes.length, pathname]);
|
|
57
58
|
return meta;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { ISidebarGroup } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* hook for get sidebar data for all nav
|
|
3
4
|
*/
|
|
4
|
-
export declare const useFullSidebarData: () =>
|
|
5
|
+
export declare const useFullSidebarData: () => Record<string, ISidebarGroup[]>;
|
|
5
6
|
/**
|
|
6
7
|
* hook for get sidebar data for current nav
|
|
7
8
|
*/
|
|
8
|
-
export declare const useSidebarData: () =>
|
|
9
|
+
export declare const useSidebarData: () => ISidebarGroup[];
|
|
@@ -71,7 +71,8 @@ export var useFullSidebarData = function useFullSidebarData() {
|
|
|
71
71
|
children: [].concat(_toConsumableArray(((_ret$parentPath$title2 = ret[parentPath][titleKey]) === null || _ret$parentPath$title2 === void 0 ? void 0 : _ret$parentPath$title2.children) || []), [{
|
|
72
72
|
title: route.meta.frontmatter.title,
|
|
73
73
|
link: "/".concat(route.path),
|
|
74
|
-
order: route.meta.frontmatter.order || 0
|
|
74
|
+
order: route.meta.frontmatter.order || 0,
|
|
75
|
+
frontmatter: route.meta.frontmatter
|
|
75
76
|
}])
|
|
76
77
|
};
|
|
77
78
|
}
|
|
@@ -125,7 +126,8 @@ export var useSidebarData = function useSidebarData() {
|
|
|
125
126
|
// /a/b => /a
|
|
126
127
|
// /en-US/a => /en-US/a
|
|
127
128
|
// /en-US/a/b => /en-US/a
|
|
129
|
+
// /en-US/a/b/ => /en-US/a (also strip trailing /)
|
|
128
130
|
|
|
129
|
-
var parentPath = clearPath ? pathname.replace(/(\/[^/]+)(\/[^/]
|
|
131
|
+
var parentPath = clearPath ? pathname.replace(/(\/[^/]+)(\/[^/]+\/?)$/, '$1') : pathname;
|
|
130
132
|
return parentPath ? sidebar[parentPath] : [];
|
|
131
133
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface IHighlightText {
|
|
2
|
+
highlighted?: boolean;
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
interface ISearchNavResult {
|
|
6
|
+
title?: string;
|
|
7
|
+
priority: number;
|
|
8
|
+
hints: {
|
|
9
|
+
type: 'page' | 'title' | 'demo' | 'content';
|
|
10
|
+
link: string;
|
|
11
|
+
priority: number;
|
|
12
|
+
highlightTitleTexts: IHighlightText[];
|
|
13
|
+
highlightTexts: IHighlightText[];
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
declare type ISearchResult = ISearchNavResult[];
|
|
17
|
+
export declare const useSiteSearch: () => {
|
|
18
|
+
keywords: string;
|
|
19
|
+
setKeywords: (val: string) => void;
|
|
20
|
+
result: ISearchResult;
|
|
21
|
+
loading: boolean;
|
|
22
|
+
};
|
|
23
|
+
export {};
|