dumi 2.0.0-beta.15 → 2.0.0-beta.16
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/types.d.ts +2 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +15 -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/derivative.js +13 -1
- package/dist/loaders/markdown/index.d.ts +1 -0
- package/dist/loaders/markdown/index.js +3 -0
- 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 +2 -2
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -3
- package/dist/loaders/markdown/transformer/remarkMeta.js +18 -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 +1 -1
- package/theme-default/builtins/Previewer/index.js +4 -122
- package/theme-default/builtins/Previewer/index.less +0 -165
- package/theme-default/slots/PreviewerActions/index.d.ts +11 -0
- package/theme-default/slots/PreviewerActions/index.js +128 -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
|
@@ -78,6 +78,8 @@ export interface IRouteMeta {
|
|
|
78
78
|
cols?: number;
|
|
79
79
|
tocDepth?: number;
|
|
80
80
|
};
|
|
81
|
+
atomId?: string;
|
|
82
|
+
[key: string]: any;
|
|
81
83
|
};
|
|
82
84
|
toc: {
|
|
83
85
|
id: string;
|
|
@@ -110,7 +112,6 @@ export interface IRouteMeta {
|
|
|
110
112
|
[key: string]: any;
|
|
111
113
|
};
|
|
112
114
|
}[];
|
|
113
|
-
[key: string]: any;
|
|
114
115
|
}
|
|
115
116
|
declare type IBasicLocale = {
|
|
116
117
|
id: string;
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -19,6 +19,7 @@ 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,
|
|
23
24
|
LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
|
|
24
25
|
PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
|
|
@@ -39,8 +40,22 @@ var PICKED_PKG_FIELDS = {
|
|
|
39
40
|
author: "",
|
|
40
41
|
authors: ""
|
|
41
42
|
};
|
|
43
|
+
var CLIENT_DEPS = [
|
|
44
|
+
"@ant-design/icons-svg",
|
|
45
|
+
"@makotot/ghostui",
|
|
46
|
+
"deepmerge",
|
|
47
|
+
"highlight-words-core",
|
|
48
|
+
"lodash.throttle",
|
|
49
|
+
"prism-react-renderer",
|
|
50
|
+
"prismjs",
|
|
51
|
+
"rc-tabs",
|
|
52
|
+
"react-copy-to-clipboard",
|
|
53
|
+
"react-helmet",
|
|
54
|
+
"react-intl"
|
|
55
|
+
];
|
|
42
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
57
|
0 && (module.exports = {
|
|
58
|
+
CLIENT_DEPS,
|
|
44
59
|
LOCAL_DUMI_DIR,
|
|
45
60
|
LOCAL_THEME_DIR,
|
|
46
61
|
PICKED_PKG_FIELDS,
|
|
@@ -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
|
|
@@ -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,17 @@ 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
|
+
memo.hash = true;
|
|
60
72
|
return memo;
|
|
61
73
|
});
|
|
62
74
|
api.modifyAppData((memo) => {
|
|
@@ -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 = {
|
|
@@ -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,7 +51,7 @@ 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;
|
|
@@ -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
|
|
@@ -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 {};
|
|
@@ -26,6 +26,7 @@ __export(remarkMeta_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(remarkMeta_exports);
|
|
28
28
|
var import_tabs = require("../../../features/tabs");
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
29
30
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
30
31
|
var import_path = __toESM(require("path"));
|
|
31
32
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
@@ -35,12 +36,27 @@ var toString;
|
|
|
35
36
|
({ visit } = await import("unist-util-visit"));
|
|
36
37
|
({ toString } = await import("mdast-util-to-string"));
|
|
37
38
|
})();
|
|
39
|
+
function getGuessAtomId(opts) {
|
|
40
|
+
const parsed = import_path.default.parse(opts.fileAbsPath);
|
|
41
|
+
const clearFileName = parsed.name.replace(/(?:\.$tab-[^.]+)?(?:\.[^.]+)?(\.[^.]+)$/, "$1");
|
|
42
|
+
const atomFile = [".tsx", ".jsx"].map((ext) => import_path.default.join(parsed.dir, `${clearFileName}${ext}`)).find(import_fs.default.existsSync);
|
|
43
|
+
if (atomFile) {
|
|
44
|
+
const atomAbsDir = opts.resolve.atomDirs.map(({ dir }) => import_path.default.resolve(opts.cwd, dir)).sort((a, b) => b.split("/").length - a.split("/").length).find((dir) => atomFile.startsWith(dir));
|
|
45
|
+
if (atomAbsDir) {
|
|
46
|
+
return import_path.default.relative(atomAbsDir, atomFile).replace(/((^|\/)index)?\.\w+$/, "");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
38
50
|
function remarkMeta(opts) {
|
|
39
51
|
return (tree, vFile) => {
|
|
40
|
-
|
|
52
|
+
const guessAtomId = getGuessAtomId(opts);
|
|
53
|
+
vFile.data.frontmatter = {
|
|
54
|
+
title: "",
|
|
55
|
+
...guessAtomId && { atomId: guessAtomId }
|
|
56
|
+
};
|
|
41
57
|
visit(tree, "yaml", (node) => {
|
|
42
58
|
try {
|
|
43
|
-
vFile.data.frontmatter
|
|
59
|
+
Object.assign(vFile.data.frontmatter, import_js_yaml.default.load(node.value));
|
|
44
60
|
} catch {
|
|
45
61
|
}
|
|
46
62
|
});
|
package/dist/preset.js
CHANGED
|
@@ -44,6 +44,7 @@ var preset_default = (api) => {
|
|
|
44
44
|
plugins: [
|
|
45
45
|
require.resolve("./registerMethods"),
|
|
46
46
|
require.resolve("./features/configPlugins"),
|
|
47
|
+
require.resolve("./features/autoAlias"),
|
|
47
48
|
require.resolve("./features/derivative"),
|
|
48
49
|
require.resolve("./features/sideEffects"),
|
|
49
50
|
require.resolve("./features/exports"),
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -26,4 +26,8 @@ export declare function parseCodeFrontmatter(raw: string): {
|
|
|
26
26
|
*/
|
|
27
27
|
declare const caches: Record<string, ReturnType<typeof Cache>>;
|
|
28
28
|
export declare function getCache(ns: string): typeof caches['0'];
|
|
29
|
+
/**
|
|
30
|
+
* try to get father config
|
|
31
|
+
*/
|
|
32
|
+
export declare function tryFatherBuildConfigs(cwd: string): Promise<any[]>;
|
|
29
33
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -26,7 +26,8 @@ __export(utils_exports, {
|
|
|
26
26
|
getFileContentByRegExp: () => getFileContentByRegExp,
|
|
27
27
|
getFileRangeLines: () => getFileRangeLines,
|
|
28
28
|
getRoutePathFromFsPath: () => getRoutePathFromFsPath,
|
|
29
|
-
parseCodeFrontmatter: () => parseCodeFrontmatter
|
|
29
|
+
parseCodeFrontmatter: () => parseCodeFrontmatter,
|
|
30
|
+
tryFatherBuildConfigs: () => tryFatherBuildConfigs
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(utils_exports);
|
|
32
33
|
var import_file_system_cache = __toESM(require("file-system-cache"));
|
|
@@ -78,11 +79,34 @@ function getCache(ns) {
|
|
|
78
79
|
}
|
|
79
80
|
return caches[ns] ?? (caches[ns] = (0, import_file_system_cache.default)({ basePath: import_path.default.join(CACHE_PATH, ns) }));
|
|
80
81
|
}
|
|
82
|
+
async function tryFatherBuildConfigs(cwd) {
|
|
83
|
+
let configs = [];
|
|
84
|
+
const APP_ROOT = process.env.APP_ROOT;
|
|
85
|
+
process.env.APP_ROOT = cwd;
|
|
86
|
+
try {
|
|
87
|
+
const { Service: FatherSvc } = await import("father/dist/service/service.js");
|
|
88
|
+
const { normalizeUserConfig: getBuildConfig } = await import("father/dist/builder/config.js");
|
|
89
|
+
const svc = new FatherSvc();
|
|
90
|
+
svc.commands.empty = {
|
|
91
|
+
name: "empty",
|
|
92
|
+
fn() {
|
|
93
|
+
},
|
|
94
|
+
configResolveMode: "loose",
|
|
95
|
+
plugin: { id: "empty" }
|
|
96
|
+
};
|
|
97
|
+
await svc.run({ name: "empty" });
|
|
98
|
+
configs = getBuildConfig(svc.config, svc.pkg);
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
process.env.APP_ROOT = APP_ROOT;
|
|
102
|
+
return configs;
|
|
103
|
+
}
|
|
81
104
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
105
|
0 && (module.exports = {
|
|
83
106
|
getCache,
|
|
84
107
|
getFileContentByRegExp,
|
|
85
108
|
getFileRangeLines,
|
|
86
109
|
getRoutePathFromFsPath,
|
|
87
|
-
parseCodeFrontmatter
|
|
110
|
+
parseCodeFrontmatter,
|
|
111
|
+
tryFatherBuildConfigs
|
|
88
112
|
});
|
package/package.json
CHANGED
|
@@ -1,78 +1,14 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 { ReactComponent as IconCodeSandbox } from '@ant-design/icons-svg/inline-svg/outlined/code-sandbox.svg';
|
|
16
|
-
import { ReactComponent as IconCodePen } from '@ant-design/icons-svg/inline-svg/outlined/codepen.svg';
|
|
17
|
-
import { useIntl, useLocation } from 'dumi';
|
|
18
|
-
import SourceCode from 'dumi/theme/builtins/SourceCode';
|
|
19
|
-
import Tabs from 'rc-tabs';
|
|
20
|
-
import React, { useState } from 'react';
|
|
3
|
+
import { useLocation } from 'dumi';
|
|
4
|
+
import PreviewerActions from 'dumi/theme/slots/PreviewerActions';
|
|
5
|
+
import React from 'react';
|
|
21
6
|
import "./index.less";
|
|
22
7
|
|
|
23
|
-
var IconCode = function IconCode() {
|
|
24
|
-
return /*#__PURE__*/React.createElement("svg", {
|
|
25
|
-
viewBox: "0 0 200 117"
|
|
26
|
-
}, /*#__PURE__*/React.createElement("path", {
|
|
27
|
-
d: "M59.688 2.578c-3.438-3.437-8.438-3.437-11.563 0L3.75 48.516c-5 5.937-5 14.062 0 19.062l44.063 45.938c1.562 1.562 4.062 2.5 5.937 2.5s4.063-.938 5.938-2.5c3.437-3.438 3.437-8.438 0-11.563l-42.5-43.437 42.5-44.063c3.437-3.437 3.437-8.437 0-11.875Zm135.937 45.938L151.25 2.578c-3.438-3.437-8.438-3.437-11.563 0-3.125 3.438-3.437 8.438 0 11.563l42.5 44.375-42.5 44.062c-3.437 3.438-3.437 8.438 0 11.563 1.563 1.562 3.438 2.5 5.938 2.5 2.5 0 4.063-.938 5.938-2.5l44.062-45.938c5.625-5.625 5.625-13.75 0-19.687Zm-75.938-45c-4.062-1.563-9.062.937-10.937 5l-34.063 95c-1.562 4.062.938 9.062 5 10.937.938 0 1.563.938 2.5.938 3.438 0 6.563-2.5 7.5-5.938l35-95.937c1.563-4.063-.937-9.063-5-10Z"
|
|
28
|
-
}));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var IconCodeExpand = function IconCodeExpand() {
|
|
32
|
-
return /*#__PURE__*/React.createElement("svg", {
|
|
33
|
-
viewBox: "0 0 200 117"
|
|
34
|
-
}, /*#__PURE__*/React.createElement("path", {
|
|
35
|
-
d: "M59.688 2.578c-3.438-3.437-8.438-3.437-11.563 0L3.75 48.516c-5 5.937-5 14.062 0 19.062l44.063 45.938c1.562 1.562 4.062 2.5 5.937 2.5s4.063-.938 5.938-2.5c3.437-3.438 3.437-8.438 0-11.563l-42.5-43.437 42.5-44.063c3.437-3.437 3.437-8.437 0-11.875Zm135.937 45.938L151.25 2.578c-3.438-3.437-8.438-3.437-11.563 0-3.125 3.438-3.437 8.438 0 11.563l42.5 44.375-42.5 44.062c-3.437 3.438-3.437 8.438 0 11.563 1.563 1.562 3.438 2.5 5.938 2.5 2.5 0 4.063-.938 5.938-2.5l44.062-45.938c5.625-5.625 5.625-13.75 0-19.687Z"
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var IconExternalLink = function IconExternalLink() {
|
|
40
|
-
return /*#__PURE__*/React.createElement("svg", {
|
|
41
|
-
viewBox: "0 0 1024 1024"
|
|
42
|
-
}, /*#__PURE__*/React.createElement("path", {
|
|
43
|
-
d: "M853.333 469.333A42.667 42.667 0 0 0 810.667 512v256A42.667 42.667 0 0 1 768 810.667H256A42.667 42.667 0 0 1 213.333 768V256A42.667 42.667 0 0 1 256 213.333h256A42.667 42.667 0 0 0 512 128H256a128 128 0 0 0-128 128v512a128 128 0 0 0 128 128h512a128 128 0 0 0 128-128V512a42.667 42.667 0 0 0-42.667-42.667z"
|
|
44
|
-
}), /*#__PURE__*/React.createElement("path", {
|
|
45
|
-
d: "M682.667 213.333h67.413L481.707 481.28a42.667 42.667 0 0 0 0 60.587 42.667 42.667 0 0 0 60.586 0L810.667 273.92v67.413A42.667 42.667 0 0 0 853.333 384 42.667 42.667 0 0 0 896 341.333V170.667A42.667 42.667 0 0 0 853.333 128H682.667a42.667 42.667 0 0 0 0 85.333z"
|
|
46
|
-
}));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
8
|
var Previewer = function Previewer(props) {
|
|
50
|
-
var _files$activeKey$0$ma;
|
|
51
|
-
|
|
52
|
-
var intl = useIntl();
|
|
53
|
-
|
|
54
9
|
var _useLocation = useLocation(),
|
|
55
10
|
hash = _useLocation.hash;
|
|
56
11
|
|
|
57
|
-
var files = Object.entries(props.asset.dependencies).filter(function (_ref) {
|
|
58
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
59
|
-
type = _ref2[1].type;
|
|
60
|
-
|
|
61
|
-
return type === 'FILE';
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
var _useState = useState(0),
|
|
65
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
66
|
-
activeKey = _useState2[0],
|
|
67
|
-
setActiveKey = _useState2[1];
|
|
68
|
-
|
|
69
|
-
var _useState3 = useState(false),
|
|
70
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
71
|
-
showCode = _useState4[0],
|
|
72
|
-
setShowCode = _useState4[1];
|
|
73
|
-
|
|
74
|
-
var isSingleFile = files.length === 1;
|
|
75
|
-
var lang = ((_files$activeKey$0$ma = files[activeKey][0].match(/\.([^.]+)$/)) === null || _files$activeKey$0$ma === void 0 ? void 0 : _files$activeKey$0$ma[1]) || 'text';
|
|
76
12
|
var link = "#".concat(props.asset.id);
|
|
77
13
|
return /*#__PURE__*/React.createElement("div", {
|
|
78
14
|
id: props.asset.id,
|
|
@@ -103,61 +39,7 @@ var Previewer = function Previewer(props) {
|
|
|
103
39
|
dangerouslySetInnerHTML: {
|
|
104
40
|
__html: props.description
|
|
105
41
|
}
|
|
106
|
-
})), /*#__PURE__*/React.createElement(
|
|
107
|
-
className: "dumi-default-previewer-actions"
|
|
108
|
-
}, /*#__PURE__*/React.createElement("button", {
|
|
109
|
-
className: "dumi-default-previewer-action-btn",
|
|
110
|
-
type: "button",
|
|
111
|
-
"data-dumi-tooltip": intl.formatMessage({
|
|
112
|
-
id: 'previewer.actions.codesandbox'
|
|
113
|
-
})
|
|
114
|
-
}, /*#__PURE__*/React.createElement(IconCodeSandbox, null)), /*#__PURE__*/React.createElement("button", {
|
|
115
|
-
className: "dumi-default-previewer-action-btn",
|
|
116
|
-
type: "button",
|
|
117
|
-
"data-dumi-tooltip": intl.formatMessage({
|
|
118
|
-
id: 'previewer.actions.codepen'
|
|
119
|
-
})
|
|
120
|
-
}, /*#__PURE__*/React.createElement(IconCodePen, null)), /*#__PURE__*/React.createElement("a", {
|
|
121
|
-
target: "_blank",
|
|
122
|
-
rel: "noreferrer",
|
|
123
|
-
href: props.demoUrl,
|
|
124
|
-
className: "dumi-default-previewer-action-btn",
|
|
125
|
-
"data-dumi-tooltip": intl.formatMessage({
|
|
126
|
-
id: 'previewer.actions.separate'
|
|
127
|
-
})
|
|
128
|
-
}, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement("button", {
|
|
129
|
-
className: "dumi-default-previewer-action-btn",
|
|
130
|
-
type: "button",
|
|
131
|
-
onClick: function onClick() {
|
|
132
|
-
return setShowCode(function (prev) {
|
|
133
|
-
return !prev;
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
"data-dumi-tooltip": intl.formatMessage({
|
|
137
|
-
id: "previewer.actions.code.".concat(showCode ? 'shrink' : 'expand')
|
|
138
|
-
})
|
|
139
|
-
}, showCode ? /*#__PURE__*/React.createElement(IconCodeExpand, null) : /*#__PURE__*/React.createElement(IconCode, null))), showCode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
140
|
-
className: "dumi-default-previewer-sources"
|
|
141
|
-
}, !isSingleFile && /*#__PURE__*/React.createElement(Tabs, {
|
|
142
|
-
className: "dumi-default-previewer-tabs",
|
|
143
|
-
prefixCls: "dumi-default-tabs",
|
|
144
|
-
moreIcon: "\xB7\xB7\xB7",
|
|
145
|
-
defaultActiveKey: String(activeKey),
|
|
146
|
-
onChange: function onChange(key) {
|
|
147
|
-
return setActiveKey(Number(key));
|
|
148
|
-
},
|
|
149
|
-
items: files.map(function (_ref3, i) {
|
|
150
|
-
var _ref4 = _slicedToArray(_ref3, 1),
|
|
151
|
-
filename = _ref4[0];
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
key: String(i),
|
|
155
|
-
label: filename
|
|
156
|
-
};
|
|
157
|
-
})
|
|
158
|
-
})), /*#__PURE__*/React.createElement(SourceCode, {
|
|
159
|
-
lang: lang
|
|
160
|
-
}, files[activeKey][1].value))));
|
|
42
|
+
})), /*#__PURE__*/React.createElement(PreviewerActions, props)));
|
|
161
43
|
};
|
|
162
44
|
|
|
163
45
|
export default Previewer;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
@import (reference) '../../styles/variables.less';
|
|
2
|
-
@import '../../styles/utils.less';
|
|
3
2
|
|
|
4
3
|
.@{prefix}-previewer {
|
|
5
4
|
margin: 24px 0 32px;
|
|
@@ -116,59 +115,6 @@
|
|
|
116
115
|
}
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
|
-
|
|
120
|
-
&-actions {
|
|
121
|
-
display: flex;
|
|
122
|
-
height: 32px;
|
|
123
|
-
align-items: center;
|
|
124
|
-
justify-content: center;
|
|
125
|
-
|
|
126
|
-
&:not(:last-child) {
|
|
127
|
-
border-bottom: 1px dashed @c-border-light;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
&-action-btn {
|
|
132
|
-
display: flex;
|
|
133
|
-
align-items: center;
|
|
134
|
-
justify-content: center;
|
|
135
|
-
width: 24px;
|
|
136
|
-
height: 24px;
|
|
137
|
-
padding: 0;
|
|
138
|
-
border: 0;
|
|
139
|
-
background: transparent;
|
|
140
|
-
cursor: pointer;
|
|
141
|
-
|
|
142
|
-
> svg {
|
|
143
|
-
width: 16px;
|
|
144
|
-
fill: darken(@c-border, 20%);
|
|
145
|
-
transition: fill 0.2s;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
&:hover > svg {
|
|
149
|
-
fill: darken(@c-border, 30%);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
&:not(:last-child) {
|
|
153
|
-
margin-right: 4px;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
&-tabs {
|
|
158
|
-
position: relative;
|
|
159
|
-
padding: 0 12px;
|
|
160
|
-
|
|
161
|
-
&::after {
|
|
162
|
-
content: '';
|
|
163
|
-
position: absolute;
|
|
164
|
-
left: 0;
|
|
165
|
-
bottom: 0;
|
|
166
|
-
width: 100%;
|
|
167
|
-
height: 0;
|
|
168
|
-
border-bottom: 1px dashed @c-border-light;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
118
|
// active
|
|
173
119
|
&[data-active] {
|
|
174
120
|
box-shadow: 0 0 0 4px fade(@c-primary, 10%);
|
|
@@ -184,114 +130,3 @@
|
|
|
184
130
|
}
|
|
185
131
|
}
|
|
186
132
|
}
|
|
187
|
-
|
|
188
|
-
.@{prefix}-tabs {
|
|
189
|
-
overflow: hidden;
|
|
190
|
-
|
|
191
|
-
&-top {
|
|
192
|
-
flex-direction: column;
|
|
193
|
-
|
|
194
|
-
.@{prefix}-tabs-ink-bar {
|
|
195
|
-
bottom: 0;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
&-nav {
|
|
200
|
-
display: flex;
|
|
201
|
-
|
|
202
|
-
&-wrap {
|
|
203
|
-
display: flex;
|
|
204
|
-
white-space: nowrap;
|
|
205
|
-
overflow: hidden;
|
|
206
|
-
|
|
207
|
-
&&-ping-left {
|
|
208
|
-
box-shadow: 5px 0 5px -5px rgb(0 0 0 / 10%) inset;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
&&-ping-right ~ * > .@{prefix}-tabs-nav-more {
|
|
212
|
-
box-shadow: 0 0 5px rgb(0 0 0 / 10%);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
&-list {
|
|
217
|
-
position: relative;
|
|
218
|
-
z-index: 1;
|
|
219
|
-
display: flex;
|
|
220
|
-
transition: transform 0.2s;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
&-more {
|
|
224
|
-
height: 100%;
|
|
225
|
-
cursor: pointer;
|
|
226
|
-
background: none;
|
|
227
|
-
border: 0;
|
|
228
|
-
transition: box-shadow 0.2s;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
&-tab {
|
|
233
|
-
display: flex;
|
|
234
|
-
margin: 0 12px;
|
|
235
|
-
|
|
236
|
-
&-btn {
|
|
237
|
-
padding: 0;
|
|
238
|
-
color: @c-text-secondary;
|
|
239
|
-
font-size: 14px;
|
|
240
|
-
line-height: 36px;
|
|
241
|
-
border: 0;
|
|
242
|
-
outline: none;
|
|
243
|
-
background: transparent;
|
|
244
|
-
box-sizing: border-box;
|
|
245
|
-
cursor: pointer;
|
|
246
|
-
transition: all 0.2s;
|
|
247
|
-
|
|
248
|
-
&:hover {
|
|
249
|
-
color: @c-text;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
&-active &-btn {
|
|
254
|
-
color: @c-text;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
&-ink-bar {
|
|
259
|
-
position: absolute;
|
|
260
|
-
height: 1px;
|
|
261
|
-
background: @c-primary;
|
|
262
|
-
transition: left 0.2s, width 0.2s;
|
|
263
|
-
pointer-events: none;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
&-dropdown {
|
|
267
|
-
position: absolute;
|
|
268
|
-
background: #fff;
|
|
269
|
-
border: 1px solid @c-border;
|
|
270
|
-
max-height: 200px;
|
|
271
|
-
overflow: auto;
|
|
272
|
-
|
|
273
|
-
> ul {
|
|
274
|
-
list-style: none;
|
|
275
|
-
margin: 0;
|
|
276
|
-
padding: 0;
|
|
277
|
-
|
|
278
|
-
> li {
|
|
279
|
-
padding: 4px 12px;
|
|
280
|
-
font-size: 14px;
|
|
281
|
-
cursor: pointer;
|
|
282
|
-
|
|
283
|
-
&:hover {
|
|
284
|
-
color: @c-primary;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
&:not(:last-child) {
|
|
288
|
-
border-bottom: 1px dashed @c-border;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
&-hidden {
|
|
294
|
-
display: none;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IPreviewerProps } from 'dumi';
|
|
2
|
+
import { type FC } from 'react';
|
|
3
|
+
import './index.less';
|
|
4
|
+
export interface IPreviewerActionsProps extends IPreviewerProps {
|
|
5
|
+
/**
|
|
6
|
+
* disabled actions
|
|
7
|
+
*/
|
|
8
|
+
disabledActions?: ('CSB' | 'CODEPEN' | 'EXTERNAL')[];
|
|
9
|
+
}
|
|
10
|
+
declare const PreviewerActions: FC<IPreviewerActionsProps>;
|
|
11
|
+
export default PreviewerActions;
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { ReactComponent as IconCodeSandbox } from '@ant-design/icons-svg/inline-svg/outlined/code-sandbox.svg';
|
|
14
|
+
import { ReactComponent as IconCodePen } from '@ant-design/icons-svg/inline-svg/outlined/codepen.svg';
|
|
15
|
+
import { useIntl } from 'dumi';
|
|
16
|
+
import SourceCode from 'dumi/theme/builtins/SourceCode';
|
|
17
|
+
import PreviewerActionsExtra from 'dumi/theme/slots/PreviewerActionsExtra';
|
|
18
|
+
import Tabs from 'rc-tabs';
|
|
19
|
+
import React, { useState } from 'react';
|
|
20
|
+
import "./index.less";
|
|
21
|
+
|
|
22
|
+
var IconCode = function IconCode() {
|
|
23
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
24
|
+
viewBox: "0 0 200 117"
|
|
25
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
26
|
+
d: "M59.688 2.578c-3.438-3.437-8.438-3.437-11.563 0L3.75 48.516c-5 5.937-5 14.062 0 19.062l44.063 45.938c1.562 1.562 4.062 2.5 5.937 2.5s4.063-.938 5.938-2.5c3.437-3.438 3.437-8.438 0-11.563l-42.5-43.437 42.5-44.063c3.437-3.437 3.437-8.437 0-11.875Zm135.937 45.938L151.25 2.578c-3.438-3.437-8.438-3.437-11.563 0-3.125 3.438-3.437 8.438 0 11.563l42.5 44.375-42.5 44.062c-3.437 3.438-3.437 8.438 0 11.563 1.563 1.562 3.438 2.5 5.938 2.5 2.5 0 4.063-.938 5.938-2.5l44.062-45.938c5.625-5.625 5.625-13.75 0-19.687Zm-75.938-45c-4.062-1.563-9.062.937-10.937 5l-34.063 95c-1.562 4.062.938 9.062 5 10.937.938 0 1.563.938 2.5.938 3.438 0 6.563-2.5 7.5-5.938l35-95.937c1.563-4.063-.937-9.063-5-10Z"
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var IconCodeExpand = function IconCodeExpand() {
|
|
31
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
32
|
+
viewBox: "0 0 200 117"
|
|
33
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
34
|
+
d: "M59.688 2.578c-3.438-3.437-8.438-3.437-11.563 0L3.75 48.516c-5 5.937-5 14.062 0 19.062l44.063 45.938c1.562 1.562 4.062 2.5 5.937 2.5s4.063-.938 5.938-2.5c3.437-3.438 3.437-8.438 0-11.563l-42.5-43.437 42.5-44.063c3.437-3.437 3.437-8.437 0-11.875Zm135.937 45.938L151.25 2.578c-3.438-3.437-8.438-3.437-11.563 0-3.125 3.438-3.437 8.438 0 11.563l42.5 44.375-42.5 44.062c-3.437 3.438-3.437 8.438 0 11.563 1.563 1.562 3.438 2.5 5.938 2.5 2.5 0 4.063-.938 5.938-2.5l44.062-45.938c5.625-5.625 5.625-13.75 0-19.687Z"
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var IconExternalLink = function IconExternalLink() {
|
|
39
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
40
|
+
viewBox: "0 0 1024 1024"
|
|
41
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
42
|
+
d: "M853.333 469.333A42.667 42.667 0 0 0 810.667 512v256A42.667 42.667 0 0 1 768 810.667H256A42.667 42.667 0 0 1 213.333 768V256A42.667 42.667 0 0 1 256 213.333h256A42.667 42.667 0 0 0 512 128H256a128 128 0 0 0-128 128v512a128 128 0 0 0 128 128h512a128 128 0 0 0 128-128V512a42.667 42.667 0 0 0-42.667-42.667z"
|
|
43
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
44
|
+
d: "M682.667 213.333h67.413L481.707 481.28a42.667 42.667 0 0 0 0 60.587 42.667 42.667 0 0 0 60.586 0L810.667 273.92v67.413A42.667 42.667 0 0 0 853.333 384 42.667 42.667 0 0 0 896 341.333V170.667A42.667 42.667 0 0 0 853.333 128H682.667a42.667 42.667 0 0 0 0 85.333z"
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var PreviewerActions = function PreviewerActions(props) {
|
|
49
|
+
var _files$activeKey$0$ma, _props$disabledAction, _props$disabledAction2, _props$disabledAction3;
|
|
50
|
+
|
|
51
|
+
var intl = useIntl();
|
|
52
|
+
var files = Object.entries(props.asset.dependencies).filter(function (_ref) {
|
|
53
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
54
|
+
type = _ref2[1].type;
|
|
55
|
+
|
|
56
|
+
return type === 'FILE';
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
var _useState = useState(0),
|
|
60
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
61
|
+
activeKey = _useState2[0],
|
|
62
|
+
setActiveKey = _useState2[1];
|
|
63
|
+
|
|
64
|
+
var _useState3 = useState(false),
|
|
65
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
66
|
+
showCode = _useState4[0],
|
|
67
|
+
setShowCode = _useState4[1];
|
|
68
|
+
|
|
69
|
+
var isSingleFile = files.length === 1;
|
|
70
|
+
var lang = ((_files$activeKey$0$ma = files[activeKey][0].match(/\.([^.]+)$/)) === null || _files$activeKey$0$ma === void 0 ? void 0 : _files$activeKey$0$ma[1]) || 'text';
|
|
71
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
className: "dumi-default-previewer-actions"
|
|
73
|
+
}, !((_props$disabledAction = props.disabledActions) !== null && _props$disabledAction !== void 0 && _props$disabledAction.includes('CSB')) && /*#__PURE__*/React.createElement("button", {
|
|
74
|
+
className: "dumi-default-previewer-action-btn",
|
|
75
|
+
type: "button",
|
|
76
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
77
|
+
id: 'previewer.actions.codesandbox'
|
|
78
|
+
})
|
|
79
|
+
}, /*#__PURE__*/React.createElement(IconCodeSandbox, null)), !((_props$disabledAction2 = props.disabledActions) !== null && _props$disabledAction2 !== void 0 && _props$disabledAction2.includes('CODEPEN')) && /*#__PURE__*/React.createElement("button", {
|
|
80
|
+
className: "dumi-default-previewer-action-btn",
|
|
81
|
+
type: "button",
|
|
82
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
83
|
+
id: 'previewer.actions.codepen'
|
|
84
|
+
})
|
|
85
|
+
}, /*#__PURE__*/React.createElement(IconCodePen, null)), !((_props$disabledAction3 = props.disabledActions) !== null && _props$disabledAction3 !== void 0 && _props$disabledAction3.includes('EXTERNAL')) && /*#__PURE__*/React.createElement("a", {
|
|
86
|
+
target: "_blank",
|
|
87
|
+
rel: "noreferrer",
|
|
88
|
+
href: props.demoUrl,
|
|
89
|
+
className: "dumi-default-previewer-action-btn",
|
|
90
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
91
|
+
id: 'previewer.actions.separate'
|
|
92
|
+
})
|
|
93
|
+
}, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement(PreviewerActionsExtra, props), /*#__PURE__*/React.createElement("button", {
|
|
94
|
+
className: "dumi-default-previewer-action-btn",
|
|
95
|
+
type: "button",
|
|
96
|
+
onClick: function onClick() {
|
|
97
|
+
return setShowCode(function (prev) {
|
|
98
|
+
return !prev;
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
102
|
+
id: "previewer.actions.code.".concat(showCode ? 'shrink' : 'expand')
|
|
103
|
+
})
|
|
104
|
+
}, showCode ? /*#__PURE__*/React.createElement(IconCodeExpand, null) : /*#__PURE__*/React.createElement(IconCode, null))), showCode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
105
|
+
className: "dumi-default-previewer-sources"
|
|
106
|
+
}, !isSingleFile && /*#__PURE__*/React.createElement(Tabs, {
|
|
107
|
+
className: "dumi-default-previewer-tabs",
|
|
108
|
+
prefixCls: "dumi-default-tabs",
|
|
109
|
+
moreIcon: "\xB7\xB7\xB7",
|
|
110
|
+
defaultActiveKey: String(activeKey),
|
|
111
|
+
onChange: function onChange(key) {
|
|
112
|
+
return setActiveKey(Number(key));
|
|
113
|
+
},
|
|
114
|
+
items: files.map(function (_ref3, i) {
|
|
115
|
+
var _ref4 = _slicedToArray(_ref3, 1),
|
|
116
|
+
filename = _ref4[0];
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
key: String(i),
|
|
120
|
+
label: filename
|
|
121
|
+
};
|
|
122
|
+
})
|
|
123
|
+
})), /*#__PURE__*/React.createElement(SourceCode, {
|
|
124
|
+
lang: lang
|
|
125
|
+
}, files[activeKey][1].value)));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default PreviewerActions;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
@import (reference) '../../styles/variables.less';
|
|
2
|
+
@import '../../styles/utils.less';
|
|
3
|
+
|
|
4
|
+
.@{prefix}-previewer{
|
|
5
|
+
&-actions {
|
|
6
|
+
display: flex;
|
|
7
|
+
height: 32px;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
|
|
11
|
+
&:not(:last-child) {
|
|
12
|
+
border-bottom: 1px dashed @c-border-light;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&-action-btn {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
width: 24px;
|
|
21
|
+
height: 24px;
|
|
22
|
+
padding: 0;
|
|
23
|
+
border: 0;
|
|
24
|
+
background: transparent;
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
|
|
27
|
+
> svg {
|
|
28
|
+
width: 16px;
|
|
29
|
+
fill: darken(@c-border, 20%);
|
|
30
|
+
transition: fill 0.2s;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:hover > svg {
|
|
34
|
+
fill: darken(@c-border, 30%);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&:not(:last-child) {
|
|
38
|
+
margin-right: 4px;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&-tabs {
|
|
43
|
+
position: relative;
|
|
44
|
+
padding: 0 12px;
|
|
45
|
+
|
|
46
|
+
&::after {
|
|
47
|
+
content: '';
|
|
48
|
+
position: absolute;
|
|
49
|
+
left: 0;
|
|
50
|
+
bottom: 0;
|
|
51
|
+
width: 100%;
|
|
52
|
+
height: 0;
|
|
53
|
+
border-bottom: 1px dashed @c-border-light;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.@{prefix}-tabs {
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
|
|
61
|
+
&-top {
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
|
|
64
|
+
.@{prefix}-tabs-ink-bar {
|
|
65
|
+
bottom: 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&-nav {
|
|
70
|
+
display: flex;
|
|
71
|
+
|
|
72
|
+
&-wrap {
|
|
73
|
+
display: flex;
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
|
|
77
|
+
&&-ping-left {
|
|
78
|
+
box-shadow: 5px 0 5px -5px rgb(0 0 0 / 10%) inset;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&&-ping-right ~ * > .@{prefix}-tabs-nav-more {
|
|
82
|
+
box-shadow: 0 0 5px rgb(0 0 0 / 10%);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&-list {
|
|
87
|
+
position: relative;
|
|
88
|
+
z-index: 1;
|
|
89
|
+
display: flex;
|
|
90
|
+
transition: transform 0.2s;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&-more {
|
|
94
|
+
height: 100%;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
background: none;
|
|
97
|
+
border: 0;
|
|
98
|
+
transition: box-shadow 0.2s;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&-tab {
|
|
103
|
+
display: flex;
|
|
104
|
+
margin: 0 12px;
|
|
105
|
+
|
|
106
|
+
&-btn {
|
|
107
|
+
padding: 0;
|
|
108
|
+
color: @c-text-secondary;
|
|
109
|
+
font-size: 14px;
|
|
110
|
+
line-height: 36px;
|
|
111
|
+
border: 0;
|
|
112
|
+
outline: none;
|
|
113
|
+
background: transparent;
|
|
114
|
+
box-sizing: border-box;
|
|
115
|
+
cursor: pointer;
|
|
116
|
+
transition: all 0.2s;
|
|
117
|
+
|
|
118
|
+
&:hover {
|
|
119
|
+
color: @c-text;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
&-active &-btn {
|
|
124
|
+
color: @c-text;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
&-ink-bar {
|
|
129
|
+
position: absolute;
|
|
130
|
+
height: 1px;
|
|
131
|
+
background: @c-primary;
|
|
132
|
+
transition: left 0.2s, width 0.2s;
|
|
133
|
+
pointer-events: none;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
&-dropdown {
|
|
137
|
+
position: absolute;
|
|
138
|
+
background: #fff;
|
|
139
|
+
border: 1px solid @c-border;
|
|
140
|
+
max-height: 200px;
|
|
141
|
+
overflow: auto;
|
|
142
|
+
|
|
143
|
+
> ul {
|
|
144
|
+
list-style: none;
|
|
145
|
+
margin: 0;
|
|
146
|
+
padding: 0;
|
|
147
|
+
|
|
148
|
+
> li {
|
|
149
|
+
padding: 4px 12px;
|
|
150
|
+
font-size: 14px;
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
|
|
153
|
+
&:hover {
|
|
154
|
+
color: @c-primary;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&:not(:last-child) {
|
|
158
|
+
border-bottom: 1px dashed @c-border;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
&-hidden {
|
|
164
|
+
display: none;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|