dumi 2.0.0-beta.15 → 2.0.0-beta.17
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/client/theme-api/index.d.ts +1 -0
- package/dist/client/theme-api/index.js +1 -0
- package/dist/client/theme-api/openCodeSandbox.d.ts +9 -0
- package/dist/client/theme-api/openCodeSandbox.js +110 -0
- package/dist/client/theme-api/types.d.ts +6 -3
- package/dist/client/theme-api/utils.d.ts +6 -0
- package/dist/client/theme-api/utils.js +15 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +18 -0
- package/dist/features/assets.d.ts +5 -1
- package/dist/features/assets.js +7 -1
- package/dist/features/autoAlias.d.ts +3 -0
- package/dist/features/autoAlias.js +65 -0
- package/dist/features/compile.js +3 -2
- package/dist/features/configPlugins/index.js +3 -1
- package/dist/features/derivative.js +19 -1
- package/dist/features/routes.js +2 -9
- package/dist/loaders/markdown/index.d.ts +1 -0
- package/dist/loaders/markdown/index.js +18 -2
- package/dist/loaders/markdown/transformer/index.d.ts +1 -1
- package/dist/loaders/markdown/transformer/index.js +6 -2
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +6 -6
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -3
- package/dist/loaders/markdown/transformer/remarkMeta.js +20 -2
- package/dist/preset.js +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +26 -2
- package/package.json +2 -3
- package/theme-default/builtins/Previewer/index.js +4 -122
- package/theme-default/builtins/Previewer/index.less +0 -165
- package/theme-default/layouts/DocLayout/index.js +5 -1
- package/theme-default/layouts/DocLayout/index.less +18 -0
- package/theme-default/locales/en-US.json +1 -1
- package/theme-default/locales/zh-CN.json +1 -1
- package/theme-default/slots/Content/index.less +7 -1
- package/theme-default/slots/Features/index.js +6 -2
- package/theme-default/slots/Features/index.less +9 -1
- package/theme-default/slots/Footer/index.d.ts +4 -0
- package/theme-default/slots/Footer/index.js +18 -0
- package/theme-default/slots/Footer/index.less +19 -0
- package/theme-default/slots/Hero/index.less +9 -5
- package/theme-default/slots/PreviewerActions/index.d.ts +11 -0
- package/theme-default/slots/PreviewerActions/index.js +131 -0
- package/theme-default/slots/PreviewerActions/index.less +168 -0
- package/theme-default/slots/PreviewerActionsExtra/index.d.ts +4 -0
- package/theme-default/slots/PreviewerActionsExtra/index.js +7 -0
- package/theme-default/slots/Sidebar/index.js +3 -2
- package/theme-default/slots/Toc/index.less +4 -0
- package/theme.d.ts +0 -1
|
@@ -3,6 +3,7 @@ export { useSiteData } from './context';
|
|
|
3
3
|
export { DumiDemo } from './DumiDemo';
|
|
4
4
|
export { DumiDemoGrid } from './DumiDemoGrid';
|
|
5
5
|
export { DumiPage } from './DumiPage';
|
|
6
|
+
export { openCodeSandbox } from './openCodeSandbox';
|
|
6
7
|
export type { IPreviewerProps } from './types';
|
|
7
8
|
export { useAtomAssets } from './useAtomAssets';
|
|
8
9
|
export { useLocale } from './useLocale';
|
|
@@ -3,6 +3,7 @@ export { useSiteData } from "./context";
|
|
|
3
3
|
export { DumiDemo } from "./DumiDemo";
|
|
4
4
|
export { DumiDemoGrid } from "./DumiDemoGrid";
|
|
5
5
|
export { DumiPage } from "./DumiPage";
|
|
6
|
+
export { openCodeSandbox } from "./openCodeSandbox";
|
|
6
7
|
export { useAtomAssets } from "./useAtomAssets";
|
|
7
8
|
export { useLocale } from "./useLocale";
|
|
8
9
|
export { useNavData } from "./useNavData";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use CodeSandbox.io
|
|
3
|
+
* @param data previewer opts
|
|
4
|
+
* @param opts the api that CodeSandbox calls when creating the demo
|
|
5
|
+
* @note return a open function for open demo on codesandbox.io
|
|
6
|
+
*/
|
|
7
|
+
export declare const openCodeSandbox: (data: IPreviewerProps, opts?: {
|
|
8
|
+
api?: string;
|
|
9
|
+
}) => void;
|
|
@@ -0,0 +1,110 @@
|
|
|
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 { getParameters } from 'codesandbox/lib/api/define';
|
|
14
|
+
import { genReactRenderCode } from "./utils";
|
|
15
|
+
var CSB_API_ENDPOINT = 'https://codesandbox.io/api/v1/sandboxes/define';
|
|
16
|
+
/**
|
|
17
|
+
* get serialized data that use to submit to codesandbox.io
|
|
18
|
+
* @param opts previewer props
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function getCSBData(opts) {
|
|
22
|
+
var _opts$asset$dependenc, _react, _deps$_react, _reactDom, _deps$_reactDom;
|
|
23
|
+
|
|
24
|
+
var isTSX = Boolean((_opts$asset$dependenc = opts.asset.dependencies) === null || _opts$asset$dependenc === void 0 ? void 0 : _opts$asset$dependenc['index.tsx']);
|
|
25
|
+
var ext = isTSX ? '.tsx' : '.jsx';
|
|
26
|
+
var files = {};
|
|
27
|
+
var deps = {};
|
|
28
|
+
var entryFileName = "index".concat(ext);
|
|
29
|
+
Object.entries(opts.asset.dependencies).forEach(function (_ref) {
|
|
30
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
31
|
+
name = _ref2[0],
|
|
32
|
+
_ref2$ = _ref2[1],
|
|
33
|
+
type = _ref2$.type,
|
|
34
|
+
value = _ref2$.value;
|
|
35
|
+
|
|
36
|
+
if (type === 'NPM') {
|
|
37
|
+
// generate dependencies
|
|
38
|
+
deps[name] = value;
|
|
39
|
+
} else {
|
|
40
|
+
// append other imported local files
|
|
41
|
+
files[name === entryFileName ? "App".concat(ext) : name] = {
|
|
42
|
+
content: value,
|
|
43
|
+
isBinary: false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}); // add react、react-dom dependency
|
|
47
|
+
|
|
48
|
+
(_deps$_react = deps[_react = 'react']) !== null && _deps$_react !== void 0 ? _deps$_react : deps[_react] = 'latest';
|
|
49
|
+
(_deps$_reactDom = deps[_reactDom = 'react-dom']) !== null && _deps$_reactDom !== void 0 ? _deps$_reactDom : deps[_reactDom] = deps.react; // append sandbox.config.json
|
|
50
|
+
|
|
51
|
+
files['sandbox.config.json'] = {
|
|
52
|
+
content: JSON.stringify({
|
|
53
|
+
template: isTSX ? 'create-react-app-typescript' : 'create-react-app'
|
|
54
|
+
}, null, 2),
|
|
55
|
+
isBinary: false
|
|
56
|
+
}; // append package.json
|
|
57
|
+
|
|
58
|
+
files['package.json'] = {
|
|
59
|
+
content: JSON.stringify({
|
|
60
|
+
name: opts.title,
|
|
61
|
+
description: opts.description || 'An auto-generated demo by dumi',
|
|
62
|
+
main: entryFileName,
|
|
63
|
+
dependencies: deps,
|
|
64
|
+
// add TypeScript dependency if required, must in devDeps to avoid csb compile error
|
|
65
|
+
devDependencies: isTSX ? {
|
|
66
|
+
typescript: '^4'
|
|
67
|
+
} : {}
|
|
68
|
+
}, null, 2),
|
|
69
|
+
isBinary: false
|
|
70
|
+
}; // append index.html
|
|
71
|
+
|
|
72
|
+
files['index.html'] = {
|
|
73
|
+
content: '<div style="margin: 16px;" id="root"></div>',
|
|
74
|
+
isBinary: false
|
|
75
|
+
}; // append entry file
|
|
76
|
+
|
|
77
|
+
files[entryFileName] = {
|
|
78
|
+
content: genReactRenderCode(deps.react),
|
|
79
|
+
isBinary: false
|
|
80
|
+
};
|
|
81
|
+
return getParameters({
|
|
82
|
+
files: files
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* use CodeSandbox.io
|
|
87
|
+
* @param data previewer opts
|
|
88
|
+
* @param opts the api that CodeSandbox calls when creating the demo
|
|
89
|
+
* @note return a open function for open demo on codesandbox.io
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
export var openCodeSandbox = function openCodeSandbox(data, opts) {
|
|
94
|
+
var _data$assets;
|
|
95
|
+
|
|
96
|
+
var form = document.createElement('form');
|
|
97
|
+
var input = document.createElement('input');
|
|
98
|
+
var CSBData = getCSBData(data);
|
|
99
|
+
form.method = 'POST';
|
|
100
|
+
form.target = '_blank';
|
|
101
|
+
form.style.display = 'none';
|
|
102
|
+
form.action = (opts === null || opts === void 0 ? void 0 : opts.api) || CSB_API_ENDPOINT;
|
|
103
|
+
form.appendChild(input);
|
|
104
|
+
form.setAttribute('data-demo', ((_data$assets = data.assets) === null || _data$assets === void 0 ? void 0 : _data$assets.id) || '');
|
|
105
|
+
input.name = 'parameters';
|
|
106
|
+
input.value = CSBData;
|
|
107
|
+
document.body.appendChild(form);
|
|
108
|
+
form.submit();
|
|
109
|
+
form.remove();
|
|
110
|
+
};
|
|
@@ -10,9 +10,9 @@ export interface IPreviewerProps {
|
|
|
10
10
|
*/
|
|
11
11
|
description?: string;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* filename of current demo
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
filename?: string;
|
|
16
16
|
/**
|
|
17
17
|
* use iframe to render demo
|
|
18
18
|
*/
|
|
@@ -78,6 +78,9 @@ export interface IRouteMeta {
|
|
|
78
78
|
cols?: number;
|
|
79
79
|
tocDepth?: number;
|
|
80
80
|
};
|
|
81
|
+
atomId?: string;
|
|
82
|
+
filename?: string;
|
|
83
|
+
[key: string]: any;
|
|
81
84
|
};
|
|
82
85
|
toc: {
|
|
83
86
|
id: string;
|
|
@@ -110,7 +113,6 @@ export interface IRouteMeta {
|
|
|
110
113
|
[key: string]: any;
|
|
111
114
|
};
|
|
112
115
|
}[];
|
|
113
|
-
[key: string]: any;
|
|
114
116
|
}
|
|
115
117
|
declare type IBasicLocale = {
|
|
116
118
|
id: string;
|
|
@@ -147,6 +149,7 @@ export interface IThemeConfig {
|
|
|
147
149
|
children?: INavItem[];
|
|
148
150
|
})[];
|
|
149
151
|
sidebar?: Record<string, ISidebarGroup[]>;
|
|
152
|
+
footer?: string;
|
|
150
153
|
[key: string]: any;
|
|
151
154
|
}
|
|
152
155
|
export declare type IRoutesById = Record<string, {
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { IRoutesById } from './types';
|
|
2
2
|
export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
3
|
+
/**
|
|
4
|
+
* 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
|
|
5
|
+
* @param version react version
|
|
6
|
+
* @returns code string
|
|
7
|
+
*/
|
|
8
|
+
export declare const genReactRenderCode: (version: string) => string;
|
|
@@ -41,4 +41,19 @@ export var useLocaleDocRoutes = function useLocaleDocRoutes() {
|
|
|
41
41
|
localeDocRoutes = _useState2[0];
|
|
42
42
|
|
|
43
43
|
return localeDocRoutes;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
|
|
47
|
+
* @param version react version
|
|
48
|
+
* @returns code string
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export var genReactRenderCode = function genReactRenderCode(version) {
|
|
52
|
+
var annotation = "/**\n * This is an auto-generated demo by dumi\n * if you think it is not working as expected,\n * please report the issue at\n * https://github.com/umijs/dumi/issues\n */";
|
|
53
|
+
|
|
54
|
+
if (version.startsWith('18.') || version === 'latest') {
|
|
55
|
+
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
|
+
}
|
|
57
|
+
|
|
58
|
+
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);");
|
|
44
59
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const LOCAL_DUMI_DIR = ".dumi";
|
|
2
2
|
export declare const LOCAL_THEME_DIR: string;
|
|
3
|
+
export declare const LOCAL_PAGES_DIR: string;
|
|
3
4
|
export declare const THEME_PREFIX = "dumi-theme-";
|
|
4
5
|
export declare const SP_ROUTE_PREFIX = "~";
|
|
5
6
|
export declare const PICKED_PKG_FIELDS: {
|
|
@@ -11,3 +12,4 @@ export declare const PICKED_PKG_FIELDS: {
|
|
|
11
12
|
author: string;
|
|
12
13
|
authors: string;
|
|
13
14
|
};
|
|
15
|
+
export declare const CLIENT_DEPS: string[];
|
package/dist/constants.js
CHANGED
|
@@ -19,7 +19,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/constants.ts
|
|
20
20
|
var constants_exports = {};
|
|
21
21
|
__export(constants_exports, {
|
|
22
|
+
CLIENT_DEPS: () => CLIENT_DEPS,
|
|
22
23
|
LOCAL_DUMI_DIR: () => LOCAL_DUMI_DIR,
|
|
24
|
+
LOCAL_PAGES_DIR: () => LOCAL_PAGES_DIR,
|
|
23
25
|
LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
|
|
24
26
|
PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
|
|
25
27
|
SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
|
|
@@ -28,6 +30,7 @@ __export(constants_exports, {
|
|
|
28
30
|
module.exports = __toCommonJS(constants_exports);
|
|
29
31
|
var LOCAL_DUMI_DIR = ".dumi";
|
|
30
32
|
var LOCAL_THEME_DIR = `${LOCAL_DUMI_DIR}/theme`;
|
|
33
|
+
var LOCAL_PAGES_DIR = `${LOCAL_DUMI_DIR}/pages`;
|
|
31
34
|
var THEME_PREFIX = "dumi-theme-";
|
|
32
35
|
var SP_ROUTE_PREFIX = "~";
|
|
33
36
|
var PICKED_PKG_FIELDS = {
|
|
@@ -39,9 +42,24 @@ var PICKED_PKG_FIELDS = {
|
|
|
39
42
|
author: "",
|
|
40
43
|
authors: ""
|
|
41
44
|
};
|
|
45
|
+
var CLIENT_DEPS = [
|
|
46
|
+
"@ant-design/icons-svg",
|
|
47
|
+
"@makotot/ghostui",
|
|
48
|
+
"deepmerge",
|
|
49
|
+
"highlight-words-core",
|
|
50
|
+
"lodash.throttle",
|
|
51
|
+
"prism-react-renderer",
|
|
52
|
+
"prismjs",
|
|
53
|
+
"rc-tabs",
|
|
54
|
+
"react-copy-to-clipboard",
|
|
55
|
+
"react-helmet",
|
|
56
|
+
"react-intl"
|
|
57
|
+
];
|
|
42
58
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
59
|
0 && (module.exports = {
|
|
60
|
+
CLIENT_DEPS,
|
|
44
61
|
LOCAL_DUMI_DIR,
|
|
62
|
+
LOCAL_PAGES_DIR,
|
|
45
63
|
LOCAL_THEME_DIR,
|
|
46
64
|
PICKED_PKG_FIELDS,
|
|
47
65
|
SP_ROUTE_PREFIX,
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { IApi } from "../types";
|
|
2
|
-
import type { ExampleAsset } from 'dumi-assets-types';
|
|
2
|
+
import type { AtomAsset, ExampleAsset } from 'dumi-assets-types';
|
|
3
3
|
declare const examples: ExampleAsset[];
|
|
4
4
|
/**
|
|
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 add meta for atom
|
|
10
|
+
*/
|
|
11
|
+
export declare function addAtomMeta(atomId: string, data: Partial<AtomAsset>): void;
|
|
8
12
|
/**
|
|
9
13
|
* plugin for generate assets.json
|
|
10
14
|
*/
|
package/dist/features/assets.js
CHANGED
|
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/features/assets.ts
|
|
23
23
|
var assets_exports = {};
|
|
24
24
|
__export(assets_exports, {
|
|
25
|
+
addAtomMeta: () => addAtomMeta,
|
|
25
26
|
addExampleAssets: () => addExampleAssets,
|
|
26
27
|
default: () => assets_default
|
|
27
28
|
});
|
|
@@ -30,9 +31,13 @@ var import_fs = __toESM(require("fs"));
|
|
|
30
31
|
var import_path = __toESM(require("path"));
|
|
31
32
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
32
33
|
var examples = [];
|
|
34
|
+
var atomsMeta = {};
|
|
33
35
|
function addExampleAssets(data) {
|
|
34
36
|
examples.push(...data);
|
|
35
37
|
}
|
|
38
|
+
function addAtomMeta(atomId, data) {
|
|
39
|
+
atomsMeta[atomId] = import_plugin_utils.lodash.pick(data, ["title", "keywords", "deprecated"]);
|
|
40
|
+
}
|
|
36
41
|
var assets_default = (api) => {
|
|
37
42
|
api.describe({
|
|
38
43
|
config: {
|
|
@@ -53,7 +58,7 @@ var assets_default = (api) => {
|
|
|
53
58
|
homepage: api.pkg.homepage,
|
|
54
59
|
repository: api.pkg.repository,
|
|
55
60
|
assets: {
|
|
56
|
-
atoms: Object.values(components),
|
|
61
|
+
atoms: Object.values(components).map((atom) => Object.assign(atom, atomsMeta[atom.id] || {})),
|
|
57
62
|
examples: import_plugin_utils.lodash.uniqBy(examples, "id")
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -63,5 +68,6 @@ var assets_default = (api) => {
|
|
|
63
68
|
};
|
|
64
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
70
|
0 && (module.exports = {
|
|
71
|
+
addAtomMeta,
|
|
66
72
|
addExampleAssets
|
|
67
73
|
});
|
|
@@ -0,0 +1,65 @@
|
|
|
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/features/autoAlias.ts
|
|
23
|
+
var autoAlias_exports = {};
|
|
24
|
+
__export(autoAlias_exports, {
|
|
25
|
+
default: () => autoAlias_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(autoAlias_exports);
|
|
28
|
+
var import_utils = require("../utils");
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
31
|
+
var autoAlias_default = (api) => {
|
|
32
|
+
api.describe({
|
|
33
|
+
key: "autoAlias",
|
|
34
|
+
config: {
|
|
35
|
+
schema: (Joi) => Joi.bool()
|
|
36
|
+
},
|
|
37
|
+
enableBy: ({ userConfig }) => userConfig.autoAlias !== false
|
|
38
|
+
});
|
|
39
|
+
api.modifyDefaultConfig(async (memo) => {
|
|
40
|
+
var _a;
|
|
41
|
+
let entryDir = "";
|
|
42
|
+
if ((_a = api.userConfig.resolve) == null ? void 0 : _a.entryFile) {
|
|
43
|
+
entryDir = import_path.default.resolve(api.cwd, api.userConfig.resolve.entryFile);
|
|
44
|
+
} else if (import_fs.default.existsSync(import_path.default.join(api.cwd, "src"))) {
|
|
45
|
+
entryDir = import_path.default.join(api.cwd, "src");
|
|
46
|
+
}
|
|
47
|
+
if (entryDir && api.pkg.name) {
|
|
48
|
+
const fatherConfigs = await (0, import_utils.tryFatherBuildConfigs)(api.cwd);
|
|
49
|
+
fatherConfigs.sort((a, b) => {
|
|
50
|
+
var _a2, _b;
|
|
51
|
+
const aLevel = (((_a2 = a.output) == null ? void 0 : _a2.path) || a.output).split("/").length;
|
|
52
|
+
const bLevel = (((_b = b.output) == null ? void 0 : _b.path) || b.output).split("/").length;
|
|
53
|
+
return bLevel - aLevel;
|
|
54
|
+
});
|
|
55
|
+
fatherConfigs.forEach((item) => {
|
|
56
|
+
var _a2;
|
|
57
|
+
memo.alias[`${api.pkg.name}/${((_a2 = item.output) == null ? void 0 : _a2.path) || item.output}`] = import_path.default.join(api.cwd, item.entry || item.input);
|
|
58
|
+
});
|
|
59
|
+
memo.alias[api.pkg.name] = entryDir;
|
|
60
|
+
}
|
|
61
|
+
return memo;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {});
|
package/dist/features/compile.js
CHANGED
|
@@ -44,7 +44,7 @@ var compile_default = (api) => {
|
|
|
44
44
|
techStacks,
|
|
45
45
|
cwd: api.cwd,
|
|
46
46
|
alias: api.config.alias,
|
|
47
|
-
|
|
47
|
+
resolve: api.config.resolve,
|
|
48
48
|
extraRemarkPlugins: api.config.extraRemarkPlugins,
|
|
49
49
|
extraRehypePlugins: api.config.extraRehypePlugins
|
|
50
50
|
};
|
|
@@ -58,7 +58,8 @@ var compile_default = (api) => {
|
|
|
58
58
|
return ret;
|
|
59
59
|
}, []);
|
|
60
60
|
(0, import_assets.addExampleAssets)(assets);
|
|
61
|
-
}
|
|
61
|
+
},
|
|
62
|
+
onResolveAtomMeta: import_assets.addAtomMeta
|
|
62
63
|
}).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
|
|
63
64
|
...loaderBaseOpts,
|
|
64
65
|
builtins: api.service.themeData.builtins
|
|
@@ -30,7 +30,9 @@ var configPlugins_default = (api) => {
|
|
|
30
30
|
atomDirs: [{ type: "component", dir: "src" }],
|
|
31
31
|
codeBlockMode: "active"
|
|
32
32
|
},
|
|
33
|
-
themeConfig: {
|
|
33
|
+
themeConfig: {
|
|
34
|
+
footer: `Copyright \xA9 ${new Date().getFullYear()} | Powered by <a href="https://d.umijs.org" target="_blank" rel="noreferrer">dumi</a>`
|
|
35
|
+
}
|
|
34
36
|
};
|
|
35
37
|
const schemas = (0, import_schema.getSchemas)();
|
|
36
38
|
for (const key of Object.keys(schemas)) {
|
|
@@ -27,11 +27,14 @@ __export(derivative_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(derivative_exports);
|
|
29
29
|
var import_constants = require("../constants");
|
|
30
|
+
var import_fs = __toESM(require("fs"));
|
|
30
31
|
var import_path = __toESM(require("path"));
|
|
31
32
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
32
33
|
function safeExcludeInMFSU(api, excludes) {
|
|
33
34
|
if (api.userConfig.mfsu !== false) {
|
|
34
35
|
api.modifyDefaultConfig((memo) => {
|
|
36
|
+
if (memo.mfsu === false)
|
|
37
|
+
return memo;
|
|
35
38
|
memo.mfsu ?? (memo.mfsu = {});
|
|
36
39
|
memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
|
|
37
40
|
memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
|
|
@@ -55,8 +58,23 @@ var derivative_default = (api) => {
|
|
|
55
58
|
safeExcludeInMFSU(api, [new RegExp("dumi/dist/client")]);
|
|
56
59
|
api.modifyDefaultConfig((memo) => {
|
|
57
60
|
if (api.userConfig.mfsu !== false) {
|
|
58
|
-
|
|
61
|
+
if (import_fs.default.existsSync(import_path.default.join(api.cwd, "node_modules", ".pnpm"))) {
|
|
62
|
+
memo.mfsu = false;
|
|
63
|
+
} else {
|
|
64
|
+
memo.mfsu.strategy = "normal";
|
|
65
|
+
import_constants.CLIENT_DEPS.forEach((pkg) => {
|
|
66
|
+
memo.alias ?? (memo.alias = {});
|
|
67
|
+
memo.alias[pkg] = (0, import_plugin_utils.winPath)(import_path.default.dirname(require.resolve(`${pkg}/package.json`)));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
59
70
|
}
|
|
71
|
+
if (api.userConfig.conventionRoutes !== false) {
|
|
72
|
+
memo.conventionRoutes = {
|
|
73
|
+
base: import_path.default.join(api.cwd, import_constants.LOCAL_PAGES_DIR),
|
|
74
|
+
exclude: [/(\/|^)(\.|_\/)/]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
memo.hash = true;
|
|
60
78
|
return memo;
|
|
61
79
|
});
|
|
62
80
|
api.modifyAppData((memo) => {
|
package/dist/features/routes.js
CHANGED
|
@@ -58,15 +58,8 @@ var routes_default = (api) => {
|
|
|
58
58
|
{ dir: "docs" }
|
|
59
59
|
]
|
|
60
60
|
].map(({ dir }) => import_path.default.join(api.cwd, dir, "**/*.md"));
|
|
61
|
-
const pagesDir = import_path.default.join(api.cwd, ".dumi/pages");
|
|
62
61
|
api.describe({ key: "dumi:routes" });
|
|
63
62
|
api.addTmpGenerateWatcherPaths(() => extraWatchPaths);
|
|
64
|
-
api.modifyConfig((memo) => {
|
|
65
|
-
memo.conventionRoutes = {
|
|
66
|
-
base: pagesDir
|
|
67
|
-
};
|
|
68
|
-
return memo;
|
|
69
|
-
});
|
|
70
63
|
api.modifyDefaultConfig((memo) => {
|
|
71
64
|
if (api.userConfig.resolve) {
|
|
72
65
|
const keys = ["docDirs", "atomDirs"];
|
|
@@ -117,7 +110,7 @@ var routes_default = (api) => {
|
|
|
117
110
|
};
|
|
118
111
|
}
|
|
119
112
|
Object.entries(pages).forEach(([, route]) => {
|
|
120
|
-
route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(
|
|
113
|
+
route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(api.config.conventionRoutes.base, route.file));
|
|
121
114
|
flatRoute(route);
|
|
122
115
|
routes[route.id] = route;
|
|
123
116
|
});
|
|
@@ -125,7 +118,7 @@ var routes_default = (api) => {
|
|
|
125
118
|
const base = import_path.default.join(api.cwd, dir);
|
|
126
119
|
const dirRoutes = (0, import_core.getConventionRoutes)({
|
|
127
120
|
base,
|
|
128
|
-
exclude: [/.*(?<!md)
|
|
121
|
+
exclude: [/.*(?<!md)$/, /(\/|^)(\.|_\/)/]
|
|
129
122
|
});
|
|
130
123
|
Object.entries(dirRoutes).forEach(([key, route]) => {
|
|
131
124
|
route.id = `${dir}/${key}`;
|
|
@@ -7,6 +7,7 @@ interface IMdLoaderDefaultModeOptions extends Omit<IMdTransformerOptions, 'fileA
|
|
|
7
7
|
interface IMdLoaderDemosModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'builtins' | 'mode'> {
|
|
8
8
|
mode: 'meta';
|
|
9
9
|
onResolveDemos?: (demos: NonNullable<IMdTransformerResult['meta']['demos']>) => void;
|
|
10
|
+
onResolveAtomMeta?: (atomId: string, meta: IMdTransformerResult['meta']['frontmatter']) => void;
|
|
10
11
|
}
|
|
11
12
|
export declare type IMdLoaderOptions = IMdLoaderDefaultModeOptions | IMdLoaderDemosModeOptions;
|
|
12
13
|
export default function mdLoader(this: any, content: string): void;
|
|
@@ -38,6 +38,9 @@ function emit(opts, ret) {
|
|
|
38
38
|
if (demos && opts.onResolveDemos) {
|
|
39
39
|
opts.onResolveDemos(demos);
|
|
40
40
|
}
|
|
41
|
+
if (frontmatter.atomId && opts.onResolveAtomMeta) {
|
|
42
|
+
opts.onResolveAtomMeta(frontmatter.atomId, frontmatter);
|
|
43
|
+
}
|
|
41
44
|
return import_plugin_utils.Mustache.render(`import React from 'react';
|
|
42
45
|
|
|
43
46
|
export const demos = {
|
|
@@ -84,16 +87,24 @@ function DumiMarkdownContent() {
|
|
|
84
87
|
export default DumiMarkdownContent;`;
|
|
85
88
|
}
|
|
86
89
|
}
|
|
90
|
+
function getEmbedsCacheKey(embeds = []) {
|
|
91
|
+
return JSON.stringify(embeds.map((file) => `${file}:${import_fs.default.statSync(file).mtimeMs}`));
|
|
92
|
+
}
|
|
87
93
|
var deferrer = {};
|
|
94
|
+
var embedsMapping = {};
|
|
88
95
|
function mdLoader(content) {
|
|
89
96
|
const opts = this.getOptions();
|
|
90
97
|
const cb = this.async();
|
|
91
98
|
const cache = (0, import_utils.getCache)("md-loader");
|
|
92
|
-
const
|
|
99
|
+
const baseCacheKey = [
|
|
93
100
|
this.resourcePath,
|
|
94
101
|
import_fs.default.statSync(this.resourcePath).mtimeMs,
|
|
95
102
|
JSON.stringify(import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]))
|
|
96
103
|
].join(":");
|
|
104
|
+
const cacheKey = [
|
|
105
|
+
baseCacheKey,
|
|
106
|
+
getEmbedsCacheKey(embedsMapping[this.resourcePath])
|
|
107
|
+
].join(":");
|
|
97
108
|
const cacheRet = cache.getSync(cacheKey, "");
|
|
98
109
|
if (cacheRet) {
|
|
99
110
|
cb(null, emit.call(this, opts, cacheRet));
|
|
@@ -109,7 +120,12 @@ function mdLoader(content) {
|
|
|
109
120
|
fileAbsPath: this.resourcePath
|
|
110
121
|
});
|
|
111
122
|
deferrer[cacheKey].then((ret) => {
|
|
112
|
-
|
|
123
|
+
const finalCacheKey = [
|
|
124
|
+
baseCacheKey,
|
|
125
|
+
getEmbedsCacheKey(ret.meta.embeds)
|
|
126
|
+
].join(":");
|
|
127
|
+
embedsMapping[this.resourcePath] = ret.meta.embeds || [];
|
|
128
|
+
cache.setSync(finalCacheKey, ret);
|
|
113
129
|
cb(null, emit.call(this, opts, ret));
|
|
114
130
|
}).catch(cb);
|
|
115
131
|
}
|
|
@@ -37,7 +37,7 @@ export interface IMdTransformerOptions {
|
|
|
37
37
|
alias: object;
|
|
38
38
|
parentAbsPath?: string;
|
|
39
39
|
techStacks: IDumiTechStack[];
|
|
40
|
-
|
|
40
|
+
resolve: IDumiConfig['resolve'];
|
|
41
41
|
extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
|
|
42
42
|
extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
|
|
43
43
|
}
|
|
@@ -57,7 +57,11 @@ var transformer_default = async (raw, opts) => {
|
|
|
57
57
|
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
|
58
58
|
alias: opts.alias
|
|
59
59
|
});
|
|
60
|
-
const processor = unified().use(remarkParse).use(import_remarkEmbed.default, { fileAbsPath: opts.fileAbsPath, alias: opts.alias }).use(remarkFrontmatter).use(import_remarkMeta.default, {
|
|
60
|
+
const processor = unified().use(remarkParse).use(import_remarkEmbed.default, { fileAbsPath: opts.fileAbsPath, alias: opts.alias }).use(remarkFrontmatter).use(import_remarkMeta.default, {
|
|
61
|
+
cwd: opts.cwd,
|
|
62
|
+
fileAbsPath: opts.fileAbsPath,
|
|
63
|
+
resolve: opts.resolve
|
|
64
|
+
}).use(remarkBreaks).use(remarkGfm);
|
|
61
65
|
(_a = opts.extraRemarkPlugins) == null ? void 0 : _a.forEach((plugin) => applyUnifiedPlugin({
|
|
62
66
|
plugin,
|
|
63
67
|
processor,
|
|
@@ -67,7 +71,7 @@ var transformer_default = async (raw, opts) => {
|
|
|
67
71
|
techStacks: opts.techStacks,
|
|
68
72
|
cwd: opts.cwd,
|
|
69
73
|
fileAbsPath: opts.fileAbsPath,
|
|
70
|
-
|
|
74
|
+
resolve: opts.resolve,
|
|
71
75
|
resolver
|
|
72
76
|
}).use(import_rehypeSlug.default).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default).use(import_rehypeEnhancedTag.default).use(import_rehypeText.default);
|
|
73
77
|
(_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
|
|
@@ -5,7 +5,7 @@ import type { IMdTransformerOptions } from '.';
|
|
|
5
5
|
export declare const DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
6
6
|
export declare const DUMI_DEMO_TAG = "DumiDemo";
|
|
7
7
|
export declare const DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
|
|
8
|
-
declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | '
|
|
8
|
+
declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'resolve'> & {
|
|
9
9
|
resolver: typeof sync;
|
|
10
10
|
};
|
|
11
11
|
export default function rehypeDemo(opts: IRehypeDemoOptions): Transformer<Root>;
|
|
@@ -51,14 +51,14 @@ function getCodeLang(node, opts) {
|
|
|
51
51
|
if (typeof ((_a = node.properties) == null ? void 0 : _a.src) === "string") {
|
|
52
52
|
node.properties.src = opts.resolver(import_path.default.dirname(opts.fileAbsPath), node.properties.src);
|
|
53
53
|
lang = import_path.default.extname(node.properties.src).slice(1);
|
|
54
|
-
} else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className) && (opts.codeBlockMode === "passive" ? / demo/.test(String((_c = node.data) == null ? void 0 : _c.meta)) : !/ pure/.test(String((_d = node.data) == null ? void 0 : _d.meta)))) {
|
|
54
|
+
} else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className) && (opts.resolve.codeBlockMode === "passive" ? / demo/.test(String((_c = node.data) == null ? void 0 : _c.meta)) : !/ pure/.test(String((_d = node.data) == null ? void 0 : _d.meta)))) {
|
|
55
55
|
lang = String(node.properties.className[0]).replace("language-", "");
|
|
56
56
|
}
|
|
57
57
|
return lang;
|
|
58
58
|
}
|
|
59
59
|
function getCodeId(cwd, fileAbsPath, localId, atomId) {
|
|
60
60
|
const prefix = atomId || (0, import_utils.getRoutePathFromFsPath)(import_path.default.relative(cwd, fileAbsPath)).replace(/\//g, "-");
|
|
61
|
-
return [prefix, "demo", localId].filter(Boolean).join("-");
|
|
61
|
+
return [prefix.toLowerCase(), "demo", localId.toLowerCase()].filter(Boolean).join("-");
|
|
62
62
|
}
|
|
63
63
|
function tryMarkDemoNode(node, opts) {
|
|
64
64
|
var _a, _b;
|
|
@@ -131,7 +131,7 @@ function rehypeDemo(opts) {
|
|
|
131
131
|
const codeValue = toString(codeNode).trim();
|
|
132
132
|
const parseOpts = {
|
|
133
133
|
id: "",
|
|
134
|
-
refAtomIds: [],
|
|
134
|
+
refAtomIds: vFile.data.frontmatter.atomId ? [vFile.data.frontmatter.atomId] : [],
|
|
135
135
|
fileAbsPath: "",
|
|
136
136
|
entryPointCode: codeType === "external" ? void 0 : codeValue,
|
|
137
137
|
resolver: opts.resolver
|
|
@@ -140,13 +140,13 @@ function rehypeDemo(opts) {
|
|
|
140
140
|
let component = "";
|
|
141
141
|
if (codeType === "external") {
|
|
142
142
|
parseOpts.fileAbsPath = codeNode.properties.src;
|
|
143
|
-
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, import_path.default.parse(parseOpts.fileAbsPath).name);
|
|
143
|
+
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, import_path.default.parse(parseOpts.fileAbsPath).name, vFile.data.frontmatter.atomId);
|
|
144
144
|
component = `React.lazy(() => import('${(0, import_plugin_utils.winPath)(parseOpts.fileAbsPath)}?techStack=${techStack.name}'))`;
|
|
145
145
|
codeNode.properties.title = codeValue || void 0;
|
|
146
|
-
(_a2 = codeNode.properties).
|
|
146
|
+
(_a2 = codeNode.properties).filename ?? (_a2.filename = (0, import_plugin_utils.winPath)(import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)));
|
|
147
147
|
} else {
|
|
148
148
|
parseOpts.fileAbsPath = opts.fileAbsPath.replace(".md", ".tsx");
|
|
149
|
-
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, String(index++));
|
|
149
|
+
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, String(index++), vFile.data.frontmatter.atomId);
|
|
150
150
|
component = techStack.transformCode(codeValue, {
|
|
151
151
|
type: "code-block",
|
|
152
152
|
fileAbsPath: opts.fileAbsPath
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
2
|
import type { Transformer } from 'unified';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type { IMdTransformerOptions } from '.';
|
|
4
|
+
declare type IRemarkMetaOpts = Pick<IMdTransformerOptions, 'cwd' | 'fileAbsPath' | 'resolve'>;
|
|
5
|
+
export default function remarkMeta(opts: IRemarkMetaOpts): Transformer<Root>;
|
|
6
|
+
export {};
|