dumi 2.0.0-alpha.0 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assetParsers/block.d.ts +17 -0
- package/dist/assetParsers/block.js +130 -0
- package/dist/client/theme-api/DumiDemo.d.ts +10 -0
- package/dist/client/theme-api/DumiDemo.js +16 -0
- package/dist/client/theme-api/DumiDemoGrid.d.ts +6 -0
- package/dist/client/theme-api/DumiDemoGrid.js +64 -0
- package/dist/client/theme-api/context.d.ts +10 -0
- package/dist/client/{theme → theme-api}/context.js +2 -1
- package/dist/client/theme-api/index.d.ts +6 -0
- package/dist/client/theme-api/index.js +6 -0
- package/dist/client/theme-api/types.d.ts +47 -0
- package/dist/client/theme-api/types.js +1 -0
- package/dist/client/theme-api/useMatchedRouteMeta.d.ts +5 -0
- package/dist/client/theme-api/useMatchedRouteMeta.js +55 -0
- package/dist/client/tsconfig.json +12 -0
- package/dist/features/compile.js +21 -3
- package/dist/features/configPlugins/index.js +2 -1
- package/dist/features/configPlugins/schema.js +8 -2
- package/dist/features/locales.d.ts +3 -0
- package/dist/features/locales.js +97 -0
- package/dist/features/meta.d.ts +3 -0
- package/dist/features/meta.js +77 -0
- package/dist/features/routes.js +27 -4
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.d.ts +14 -0
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.js +50 -0
- package/dist/features/sideEffects/index.d.ts +7 -0
- package/dist/features/sideEffects/index.js +47 -0
- package/dist/features/theme/index.js +13 -31
- package/dist/features/theme/loader.js +3 -3
- package/dist/index.d.ts +8 -2
- package/dist/index.js +16 -3
- package/dist/loaders/markdown/index.d.ts +1 -1
- package/dist/loaders/markdown/index.js +33 -7
- package/dist/loaders/markdown/transformer/index.d.ts +20 -13
- package/dist/loaders/markdown/transformer/index.js +29 -3
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +160 -29
- package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +4 -0
- package/dist/loaders/markdown/transformer/rehypeEmbed.js +75 -0
- package/dist/loaders/markdown/transformer/rehypeIsolation.js +1 -1
- package/dist/loaders/markdown/transformer/rehypeJsxify.js +1 -0
- package/dist/loaders/markdown/transformer/rehypeRaw.js +9 -1
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +3 -0
- package/dist/loaders/markdown/transformer/remarkMeta.js +44 -0
- package/dist/preset.js +4 -1
- package/dist/types.d.ts +17 -4
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +25 -1
- package/package.json +31 -13
- package/theme-default/builtins/Previewer.d.ts +4 -0
- package/theme-default/builtins/Previewer.js +11 -0
- package/theme-default/layouts/DocLayout/index.d.ts +3 -0
- package/theme-default/layouts/DocLayout/index.js +16 -0
- package/theme-default/locales/en-US.json +3 -0
- package/theme-default/locales/zh-CN.json +3 -0
- package/theme-default/slots/Content/index.d.ts +5 -0
- package/theme-default/slots/Content/index.js +13 -0
- package/theme-default/slots/Header/index.d.ts +3 -0
- package/theme-default/slots/Header/index.js +17 -0
- package/theme-default/slots/Logo/index.d.ts +3 -0
- package/theme-default/slots/Logo/index.js +7 -0
- package/theme-default/slots/Navbar/index.d.ts +3 -0
- package/theme-default/slots/Navbar/index.js +7 -0
- package/theme-default/slots/SearchBar/index.d.ts +3 -0
- package/theme-default/slots/SearchBar/index.js +9 -0
- package/theme-default/slots/Sidebar/index.d.ts +3 -0
- package/theme-default/slots/Sidebar/index.js +14 -0
- package/theme.d.ts +1 -0
- package/dist/client/theme/DumiDemo.d.ts +0 -4
- package/dist/client/theme/DumiDemo.js +0 -9
- package/dist/client/theme/context.d.ts +0 -5
- package/dist/client/theme/index.d.ts +0 -2
- package/dist/client/theme/index.js +0 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
2
|
+
export interface IParsedBlockAsset {
|
|
3
|
+
asset: ExampleBlockAsset;
|
|
4
|
+
sources: Record<string, string>;
|
|
5
|
+
frontmatter: ReturnType<typeof parseCodeFrontmatter>['frontmatter'];
|
|
6
|
+
}
|
|
7
|
+
declare function parseCodeFrontmatter(raw: string): {
|
|
8
|
+
code: string;
|
|
9
|
+
frontmatter: Record<string, any> | null;
|
|
10
|
+
};
|
|
11
|
+
declare function parseBlockAsset(opts: {
|
|
12
|
+
fileAbsPath: string;
|
|
13
|
+
id: string;
|
|
14
|
+
refAtomIds: string[];
|
|
15
|
+
entryPointCode?: string;
|
|
16
|
+
}): Promise<IParsedBlockAsset>;
|
|
17
|
+
export default parseBlockAsset;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
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));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/assetParsers/block.ts
|
|
23
|
+
var block_exports = {};
|
|
24
|
+
__export(block_exports, {
|
|
25
|
+
default: () => block_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(block_exports);
|
|
28
|
+
var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
31
|
+
var import_path = __toESM(require("path"));
|
|
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
|
+
async function parseBlockAsset(opts) {
|
|
44
|
+
const asset = {
|
|
45
|
+
type: "BLOCK",
|
|
46
|
+
id: opts.id,
|
|
47
|
+
refAtomIds: opts.refAtomIds,
|
|
48
|
+
dependencies: {}
|
|
49
|
+
};
|
|
50
|
+
const result = {
|
|
51
|
+
asset,
|
|
52
|
+
sources: {},
|
|
53
|
+
frontmatter: null
|
|
54
|
+
};
|
|
55
|
+
await (0, import_esbuild.build)({
|
|
56
|
+
write: false,
|
|
57
|
+
bundle: true,
|
|
58
|
+
logLevel: "silent",
|
|
59
|
+
format: "esm",
|
|
60
|
+
target: "esnext",
|
|
61
|
+
entryPoints: [import_path.default.basename(opts.fileAbsPath)],
|
|
62
|
+
absWorkingDir: import_path.default.dirname(opts.fileAbsPath),
|
|
63
|
+
plugins: [
|
|
64
|
+
{
|
|
65
|
+
name: "plugin-dumi-collect-deps",
|
|
66
|
+
setup: (builder) => {
|
|
67
|
+
builder.onResolve({ filter: /.*/ }, (args) => {
|
|
68
|
+
if (args.kind !== "entry-point" && !args.path.startsWith(".")) {
|
|
69
|
+
const pkgJsonPath = import_plugin_utils.pkgUp.pkgUpSync({
|
|
70
|
+
cwd: require.resolve(args.path, { paths: [args.resolveDir] })
|
|
71
|
+
});
|
|
72
|
+
if (pkgJsonPath) {
|
|
73
|
+
asset.dependencies[args.path] = {
|
|
74
|
+
type: "NPM",
|
|
75
|
+
value: require(pkgJsonPath).version
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { path: args.path, external: true };
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
path: import_path.default.join(args.resolveDir, args.path),
|
|
82
|
+
pluginData: { kind: args.kind, resolveDir: args.resolveDir }
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
builder.onLoad({ filter: /.*/ }, (args) => {
|
|
86
|
+
const ext = import_path.default.extname(args.path);
|
|
87
|
+
const isModule = [".js", ".jsx", ".ts", ".tsx"].includes(ext);
|
|
88
|
+
const isPlainText = [
|
|
89
|
+
".css",
|
|
90
|
+
".less",
|
|
91
|
+
".sass",
|
|
92
|
+
".scss",
|
|
93
|
+
".styl",
|
|
94
|
+
".json"
|
|
95
|
+
].includes(ext);
|
|
96
|
+
const isEntryPoint = args.pluginData.kind === "entry-point";
|
|
97
|
+
const filename = isEntryPoint ? `index${ext}` : (0, import_plugin_utils.winPath)(import_path.default.relative(import_path.default.dirname(opts.fileAbsPath), args.path));
|
|
98
|
+
if (isModule || isPlainText) {
|
|
99
|
+
asset.dependencies[filename] = {
|
|
100
|
+
type: "FILE",
|
|
101
|
+
value: opts.entryPointCode ?? import_fs.default.readFileSync(args.path, "utf-8")
|
|
102
|
+
};
|
|
103
|
+
if (isEntryPoint) {
|
|
104
|
+
const { code, frontmatter } = parseCodeFrontmatter(asset.dependencies[filename].value);
|
|
105
|
+
if (frontmatter) {
|
|
106
|
+
asset.dependencies[filename].value = code;
|
|
107
|
+
result.frontmatter = frontmatter;
|
|
108
|
+
["description", "title", "snapshot", "keywords"].forEach((key) => {
|
|
109
|
+
asset[key] = frontmatter == null ? void 0 : frontmatter[key];
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!isEntryPoint || !opts.entryPointCode) {
|
|
114
|
+
result.sources[filename] = args.path;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
contents: isModule ? asset.dependencies[filename].value : "",
|
|
118
|
+
loader: isModule ? ext.slice(1) : "text"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
var block_default = parseBlockAsset;
|
|
129
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
import type { IPreviewerProps } from './types';
|
|
3
|
+
export interface IDumiDemoProps {
|
|
4
|
+
demo: {
|
|
5
|
+
id: string;
|
|
6
|
+
inline?: boolean;
|
|
7
|
+
};
|
|
8
|
+
previewerProps: Omit<IPreviewerProps, 'asset' | 'children'>;
|
|
9
|
+
}
|
|
10
|
+
export declare const DumiDemo: FC<IDumiDemoProps>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import Previewer from 'dumi/theme/builtins/Previewer';
|
|
4
|
+
import React, { createElement, useContext } from 'react';
|
|
5
|
+
import { Context } from "./context";
|
|
6
|
+
export var DumiDemo = function DumiDemo(props) {
|
|
7
|
+
var _useContext = useContext(Context),
|
|
8
|
+
demos = _useContext.demos;
|
|
9
|
+
|
|
10
|
+
var _demos$props$demo$id = demos[props.demo.id],
|
|
11
|
+
component = _demos$props$demo$id.component,
|
|
12
|
+
asset = _demos$props$demo$id.asset;
|
|
13
|
+
return /*#__PURE__*/React.createElement(Previewer, _extends({
|
|
14
|
+
asset: asset
|
|
15
|
+
}, props.previewerProps), /*#__PURE__*/createElement(component));
|
|
16
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
+
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
12
|
+
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
|
|
15
|
+
import { useMatchedRouteMeta } from 'dumi/theme';
|
|
16
|
+
import React, { useState } from 'react';
|
|
17
|
+
import { DumiDemo } from "./DumiDemo";
|
|
18
|
+
export var DumiDemoGrid = function DumiDemoGrid(props) {
|
|
19
|
+
var meta = useMatchedRouteMeta();
|
|
20
|
+
|
|
21
|
+
var _useState = useState(function () {
|
|
22
|
+
var _meta$demo;
|
|
23
|
+
|
|
24
|
+
var cols = [];
|
|
25
|
+
|
|
26
|
+
if ((_meta$demo = meta.demo) !== null && _meta$demo !== void 0 && _meta$demo.cols && meta.demo.cols > 1) {
|
|
27
|
+
for (var i = 0; i < props.items.length; i += meta.demo.cols) {
|
|
28
|
+
props.items.slice(i, i + meta.demo.cols).forEach(function (item, j) {
|
|
29
|
+
var _cols$j;
|
|
30
|
+
|
|
31
|
+
(_cols$j = cols[j]) !== null && _cols$j !== void 0 ? _cols$j : cols[j] = [];
|
|
32
|
+
cols[j].push(item);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return cols;
|
|
37
|
+
} else {
|
|
38
|
+
cols.push(props.items);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return cols;
|
|
42
|
+
}),
|
|
43
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
44
|
+
cols = _useState2[0];
|
|
45
|
+
|
|
46
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
47
|
+
style: {
|
|
48
|
+
display: 'flex',
|
|
49
|
+
margin: -8
|
|
50
|
+
}
|
|
51
|
+
}, cols.map(function (col, i) {
|
|
52
|
+
return /*#__PURE__*/React.createElement("section", {
|
|
53
|
+
style: {
|
|
54
|
+
flex: 1,
|
|
55
|
+
padding: 8
|
|
56
|
+
},
|
|
57
|
+
key: String(i)
|
|
58
|
+
}, col.map(function (item) {
|
|
59
|
+
return /*#__PURE__*/React.createElement(DumiDemo, _extends({
|
|
60
|
+
key: item.demo.id
|
|
61
|
+
}, item));
|
|
62
|
+
}));
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
|
+
import type { ILocalesConfig, IPreviewerProps } from './types';
|
|
3
|
+
export interface IThemeContext {
|
|
4
|
+
demos: Record<string, {
|
|
5
|
+
component: ComponentType;
|
|
6
|
+
asset: IPreviewerProps['asset'];
|
|
7
|
+
}>;
|
|
8
|
+
locales: ILocalesConfig;
|
|
9
|
+
}
|
|
10
|
+
export declare const Context: import("react").Context<IThemeContext>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export interface IPreviewerProps {
|
|
4
|
+
/**
|
|
5
|
+
* title of current demo
|
|
6
|
+
*/
|
|
7
|
+
title?: string;
|
|
8
|
+
/**
|
|
9
|
+
* description of current demo
|
|
10
|
+
*/
|
|
11
|
+
description?: string;
|
|
12
|
+
/**
|
|
13
|
+
* file path of current demo
|
|
14
|
+
*/
|
|
15
|
+
filePath?: string;
|
|
16
|
+
/**
|
|
17
|
+
* asset metadata of current demo
|
|
18
|
+
*/
|
|
19
|
+
asset: ExampleBlockAsset;
|
|
20
|
+
/**
|
|
21
|
+
* react node of current demo
|
|
22
|
+
*/
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
export interface IRouteMeta {
|
|
27
|
+
title?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
keywords?: string[];
|
|
30
|
+
category?: string;
|
|
31
|
+
order?: number;
|
|
32
|
+
toc?: boolean | 'content' | 'menu';
|
|
33
|
+
demo?: {
|
|
34
|
+
cols?: number;
|
|
35
|
+
};
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
}
|
|
38
|
+
declare type IBasicLocale = {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
};
|
|
42
|
+
export declare type ILocalesConfig = ((IBasicLocale & {
|
|
43
|
+
base?: string;
|
|
44
|
+
}) | (IBasicLocale & {
|
|
45
|
+
suffix: string;
|
|
46
|
+
}))[];
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { matchRoutes, useAppData, useLocation, useRouteData } from 'dumi';
|
|
14
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* hook for get matched route meta
|
|
18
|
+
*/
|
|
19
|
+
export var useMatchedRouteMeta = function useMatchedRouteMeta() {
|
|
20
|
+
var _useRouteData = useRouteData(),
|
|
21
|
+
route = _useRouteData.route;
|
|
22
|
+
|
|
23
|
+
var _useLocation = useLocation(),
|
|
24
|
+
pathname = _useLocation.pathname;
|
|
25
|
+
|
|
26
|
+
var _useAppData = useAppData(),
|
|
27
|
+
clientRoutes = _useAppData.clientRoutes;
|
|
28
|
+
|
|
29
|
+
var getter = useCallback(function () {
|
|
30
|
+
var ret;
|
|
31
|
+
|
|
32
|
+
if (route.path === pathname) {
|
|
33
|
+
// use `useRouteData` result if matched, for performance
|
|
34
|
+
ret = route.meta;
|
|
35
|
+
} else {
|
|
36
|
+
var _matchRoutes, _matched$route;
|
|
37
|
+
|
|
38
|
+
// match manually for dynamic route & layout component
|
|
39
|
+
var matched = (_matchRoutes = matchRoutes(clientRoutes, pathname)) === null || _matchRoutes === void 0 ? void 0 : _matchRoutes.pop();
|
|
40
|
+
ret = matched === null || matched === void 0 ? void 0 : (_matched$route = matched.route) === null || _matched$route === void 0 ? void 0 : _matched$route.meta;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return ret || {};
|
|
44
|
+
}, [clientRoutes.length, pathname]);
|
|
45
|
+
|
|
46
|
+
var _useState = useState(getter),
|
|
47
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
48
|
+
meta = _useState2[0],
|
|
49
|
+
setMeta = _useState2[1];
|
|
50
|
+
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
setMeta(getter);
|
|
53
|
+
}, [clientRoutes.length, pathname]);
|
|
54
|
+
return meta;
|
|
55
|
+
};
|
package/dist/features/compile.js
CHANGED
|
@@ -27,20 +27,38 @@ __export(compile_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(compile_exports);
|
|
28
28
|
var import_react = __toESM(require("../techStacks/react"));
|
|
29
29
|
var compile_default = (api) => {
|
|
30
|
-
api.
|
|
30
|
+
api.register({
|
|
31
|
+
key: "registerTechStack",
|
|
32
|
+
stage: Infinity,
|
|
33
|
+
fn: () => new import_react.default()
|
|
34
|
+
});
|
|
35
|
+
api.modifyDefaultConfig((memo) => {
|
|
36
|
+
memo.alias.dumi$ = memo.alias.umi;
|
|
37
|
+
return memo;
|
|
38
|
+
});
|
|
31
39
|
api.chainWebpack(async (memo) => {
|
|
32
|
-
const loaderPath = require.resolve("../loaders/markdown");
|
|
33
40
|
const babelInUmi = memo.module.rule("src").use("babel-loader").entries();
|
|
34
41
|
const techStacks = await api.applyPlugins({
|
|
35
42
|
key: "registerTechStack",
|
|
36
43
|
type: api.ApplyPluginsType.add
|
|
37
44
|
});
|
|
38
|
-
|
|
45
|
+
const loaderPath = require.resolve("../loaders/markdown");
|
|
46
|
+
const loaderBaseOpts = {
|
|
39
47
|
techStacks,
|
|
40
48
|
cwd: api.cwd,
|
|
49
|
+
codeBlockMode: api.config.resolve.codeBlockMode,
|
|
50
|
+
extraRemarkPlugins: api.config.extraRemarkPlugins,
|
|
51
|
+
extraRehypePlugins: api.config.extraRehypePlugins
|
|
52
|
+
};
|
|
53
|
+
memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("demo-index").resourceQuery(/meta$/).use("demo-index-loader").loader(loaderPath).options({
|
|
54
|
+
...loaderBaseOpts,
|
|
55
|
+
mode: "meta"
|
|
56
|
+
}).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
|
|
57
|
+
...loaderBaseOpts,
|
|
41
58
|
builtins: api.service.themeData.builtins
|
|
42
59
|
});
|
|
43
60
|
memo.module.rule("dumi-demo").type("javascript/auto").test(/\..+$/).enforce("pre").resourceQuery(/techStack/).use("demo-loader").loader(require.resolve("../loaders/demo")).options({ techStacks, cwd: api.cwd });
|
|
61
|
+
memo.module.rule("dumi-raw").resourceQuery(/raw/).use("raw-loader").loader(require.resolve("raw-loader"));
|
|
44
62
|
if (api.env === "development") {
|
|
45
63
|
memo.plugin("fastRefresh").tap(([params]) => [
|
|
46
64
|
{
|
|
@@ -27,7 +27,8 @@ var configPlugins_default = (api) => {
|
|
|
27
27
|
const configDefaults = {
|
|
28
28
|
resolve: {
|
|
29
29
|
docDirs: ["docs"],
|
|
30
|
-
entityDirs: [{ type: "component", dir: "src" }]
|
|
30
|
+
entityDirs: [{ type: "component", dir: "src" }],
|
|
31
|
+
codeBlockMode: "active"
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
const schemas = (0, import_schema.getSchemas)();
|
|
@@ -22,12 +22,18 @@ __export(schema_exports, {
|
|
|
22
22
|
getSchemas: () => getSchemas
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(schema_exports);
|
|
25
|
+
function getUnifiedPluginSchema(Joi) {
|
|
26
|
+
return Joi.array().items(Joi.alternatives(Joi.string(), Joi.func(), Joi.array().items(Joi.alternatives(Joi.string(), Joi.func()), Joi.object()).length(2))).optional();
|
|
27
|
+
}
|
|
25
28
|
function getSchemas() {
|
|
26
29
|
return {
|
|
27
30
|
resolve: (Joi) => Joi.object({
|
|
28
31
|
docDirs: Joi.array().items(Joi.string()).optional(),
|
|
29
|
-
entityDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional()
|
|
30
|
-
|
|
32
|
+
entityDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
|
|
33
|
+
codeBlockMode: Joi.string().valid("active", "passive").optional()
|
|
34
|
+
}).optional(),
|
|
35
|
+
extraRemarkPlugins: getUnifiedPluginSchema,
|
|
36
|
+
extraRehypePlugins: getUnifiedPluginSchema
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,97 @@
|
|
|
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/locales.ts
|
|
20
|
+
var locales_exports = {};
|
|
21
|
+
__export(locales_exports, {
|
|
22
|
+
default: () => locales_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(locales_exports);
|
|
25
|
+
var locales_default = (api) => {
|
|
26
|
+
api.describe({
|
|
27
|
+
config: {
|
|
28
|
+
default: [{ id: "zh-CN", name: "\u4E2D\u6587", base: "/" }],
|
|
29
|
+
schema: (Joi) => {
|
|
30
|
+
const basicOpts = { id: Joi.string(), name: Joi.string() };
|
|
31
|
+
return Joi.alternatives(Joi.array().items(Joi.object({
|
|
32
|
+
...basicOpts,
|
|
33
|
+
base: Joi.string().optional()
|
|
34
|
+
})), Joi.array().items(Joi.object({
|
|
35
|
+
...basicOpts,
|
|
36
|
+
suffix: Joi.string().allow("")
|
|
37
|
+
})));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
api.register({
|
|
42
|
+
key: "modifyConfig",
|
|
43
|
+
stage: Infinity,
|
|
44
|
+
fn: (memo) => {
|
|
45
|
+
var _a;
|
|
46
|
+
(_a = memo.locales) == null ? void 0 : _a.forEach((locale, i) => {
|
|
47
|
+
if (!("suffix" in locale)) {
|
|
48
|
+
locale.base ?? (locale.base = i ? `/${locale.id}` : "/");
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return memo;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
api.onGenerateFiles(() => {
|
|
55
|
+
api.writeTmpFile({
|
|
56
|
+
noPluginDir: true,
|
|
57
|
+
path: "dumi/locales/config.ts",
|
|
58
|
+
content: `export const locales = ${JSON.stringify(api.config.locales, null, 2)};
|
|
59
|
+
export const messages = ${JSON.stringify(api.service.themeData.locales, null, 2)};`
|
|
60
|
+
});
|
|
61
|
+
api.writeTmpFile({
|
|
62
|
+
noPluginDir: true,
|
|
63
|
+
path: "dumi/locales/runtime.tsx",
|
|
64
|
+
content: `
|
|
65
|
+
import { history } from 'umi';
|
|
66
|
+
import React, { useState, type ReactNode } from 'react';
|
|
67
|
+
import { RawIntlProvider, createIntl, createIntlCache } from 'react-intl';
|
|
68
|
+
import { locales, messages } from './config';
|
|
69
|
+
|
|
70
|
+
const cache = createIntlCache();
|
|
71
|
+
|
|
72
|
+
const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
|
|
73
|
+
const [locale] = useState(() => {
|
|
74
|
+
const matched = locales.find((locale) => (
|
|
75
|
+
// base mode
|
|
76
|
+
history.location.pathname.startsWith(locale.base) ||
|
|
77
|
+
// suffix mode
|
|
78
|
+
('suffix' in locale && history.location.pathname.endsWith(locale.suffix))
|
|
79
|
+
));
|
|
80
|
+
|
|
81
|
+
return matched ? matched.id : locales[0].id;
|
|
82
|
+
});
|
|
83
|
+
const [intl] = useState(() => createIntl({ locale, messages: messages[locale] || {} }, cache))
|
|
84
|
+
|
|
85
|
+
return <RawIntlProvider value={intl}>{props.children}</RawIntlProvider>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function i18nProvider(container: Element) {
|
|
89
|
+
return React.createElement(LocalesContainer, null, container);
|
|
90
|
+
}
|
|
91
|
+
`
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
api.addRuntimePlugin(() => "@@/dumi/locales/runtime.tsx");
|
|
95
|
+
};
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {});
|