dumi 2.0.0-alpha.2 → 2.0.0-alpha.4
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/pages/404.d.ts +1 -0
- package/dist/client/pages/404.js +2 -0
- package/dist/client/pages/Demo.d.ts +3 -0
- package/dist/client/pages/Demo.js +17 -0
- package/dist/client/theme-api/DumiDemo.js +8 -5
- package/dist/client/theme-api/DumiDemoGrid.d.ts +1 -1
- package/dist/client/theme-api/DumiDemoGrid.js +9 -8
- package/dist/client/theme-api/context.d.ts +7 -4
- package/dist/client/theme-api/context.js +8 -4
- package/dist/client/theme-api/index.d.ts +8 -5
- package/dist/client/theme-api/index.js +7 -5
- package/dist/client/theme-api/types.d.ts +77 -9
- package/dist/client/theme-api/useLocale.d.ts +1 -0
- package/dist/client/theme-api/useLocale.js +31 -0
- package/dist/client/theme-api/useNavData.d.ts +6 -0
- package/dist/client/theme-api/useNavData.js +78 -0
- package/dist/client/theme-api/{useMatchedRouteMeta.d.ts → useRouteMeta.d.ts} +1 -1
- package/dist/client/theme-api/{useMatchedRouteMeta.js → useRouteMeta.js} +6 -3
- package/dist/client/theme-api/useSidebarData.d.ts +8 -0
- package/dist/client/theme-api/useSidebarData.js +131 -0
- package/dist/client/theme-api/utils.d.ts +2 -0
- package/dist/client/theme-api/utils.js +44 -0
- package/dist/client/tsconfig.json +2 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +3 -0
- package/dist/features/compile.js +1 -1
- package/dist/features/configPlugins/index.js +2 -1
- package/dist/features/configPlugins/schema.js +2 -1
- package/dist/features/exports.d.ts +3 -0
- package/dist/features/exports.js +45 -0
- package/dist/features/locales.js +18 -10
- package/dist/features/meta.js +2 -2
- package/dist/features/routes.js +29 -2
- package/dist/features/theme/index.js +6 -6
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -0
- package/dist/loaders/markdown/index.js +4 -2
- package/dist/loaders/markdown/transformer/index.d.ts +5 -2
- package/dist/loaders/markdown/transformer/index.js +4 -2
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +3 -0
- package/dist/loaders/markdown/transformer/rehypeDemo.js +14 -6
- package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +9 -1
- package/dist/loaders/markdown/transformer/rehypeEmbed.js +16 -4
- package/dist/loaders/markdown/transformer/rehypeRaw.js +2 -2
- package/dist/loaders/markdown/transformer/rehypeSlug.d.ts +4 -0
- package/dist/loaders/markdown/transformer/rehypeSlug.js +105 -0
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -2
- package/dist/loaders/markdown/transformer/remarkMeta.js +24 -3
- package/dist/preset.js +1 -0
- package/dist/types.d.ts +8 -2
- package/package.json +16 -1
- package/theme-default/builtins/{Previewer.d.ts → Previewer/index.d.ts} +2 -1
- package/theme-default/builtins/Previewer/index.js +162 -0
- package/theme-default/builtins/Previewer/index.less +297 -0
- package/theme-default/builtins/SourceCode/index.d.ts +9 -0
- package/theme-default/builtins/SourceCode/index.js +87 -0
- package/theme-default/builtins/SourceCode/index.less +50 -0
- package/theme-default/layouts/DocLayout/index.d.ts +1 -0
- package/theme-default/layouts/DocLayout/index.js +28 -6
- package/theme-default/layouts/DocLayout/index.less +17 -0
- package/theme-default/locales/en-US.json +9 -1
- package/theme-default/locales/zh-CN.json +9 -1
- package/theme-default/slots/Content/heti.scss +3 -0
- package/theme-default/slots/Content/index.d.ts +2 -0
- package/theme-default/slots/Content/index.js +6 -5
- package/theme-default/slots/Content/index.less +31 -0
- package/theme-default/slots/Header/index.d.ts +1 -0
- package/theme-default/slots/Header/index.js +10 -7
- package/theme-default/slots/Header/index.less +22 -0
- package/theme-default/slots/LangSwitch/index.d.ts +4 -0
- package/theme-default/slots/LangSwitch/index.js +81 -0
- package/theme-default/slots/LangSwitch/index.less +13 -0
- package/theme-default/slots/Logo/index.d.ts +1 -0
- package/theme-default/slots/Logo/index.js +13 -1
- package/theme-default/slots/Logo/index.less +16 -0
- package/theme-default/slots/Navbar/index.d.ts +1 -0
- package/theme-default/slots/Navbar/index.js +20 -1
- package/theme-default/slots/Navbar/index.less +33 -0
- package/theme-default/slots/NotFound/index.d.ts +4 -0
- package/theme-default/slots/NotFound/index.js +20 -0
- package/theme-default/slots/NotFound/index.less +26 -0
- package/theme-default/slots/SearchBar/index.d.ts +1 -0
- package/theme-default/slots/SearchBar/index.js +32 -4
- package/theme-default/slots/SearchBar/index.less +61 -0
- package/theme-default/slots/Sidebar/index.d.ts +1 -0
- package/theme-default/slots/Sidebar/index.js +23 -8
- package/theme-default/slots/Sidebar/index.less +57 -0
- package/theme-default/slots/Toc/index.d.ts +4 -0
- package/theme-default/slots/Toc/index.js +30 -0
- package/theme-default/slots/Toc/index.less +31 -0
- package/theme-default/styles/utils.less +46 -0
- package/theme-default/styles/variables.less +13 -0
- package/theme-default/builtins/Previewer.js +0 -11
|
@@ -0,0 +1,105 @@
|
|
|
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/loaders/markdown/transformer/rehypeSlug.ts
|
|
23
|
+
var rehypeSlug_exports = {};
|
|
24
|
+
__export(rehypeSlug_exports, {
|
|
25
|
+
default: () => rehypeSlug
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(rehypeSlug_exports);
|
|
28
|
+
var import_utils = require("../../../utils");
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_github_slugger = __toESM(require("github-slugger"));
|
|
31
|
+
var import__ = __toESM(require("."));
|
|
32
|
+
var import_rehypeDemo = require("./rehypeDemo");
|
|
33
|
+
var import_rehypeEmbed = require("./rehypeEmbed");
|
|
34
|
+
var visit;
|
|
35
|
+
var toString;
|
|
36
|
+
var sharedSluggers = /* @__PURE__ */ new Map();
|
|
37
|
+
function getFileSlugger(fileAbsPath, parentAbsPath) {
|
|
38
|
+
if (parentAbsPath)
|
|
39
|
+
return sharedSluggers.get(parentAbsPath);
|
|
40
|
+
const slugger = new import_github_slugger.default();
|
|
41
|
+
sharedSluggers.set(fileAbsPath, slugger);
|
|
42
|
+
return slugger;
|
|
43
|
+
}
|
|
44
|
+
(async () => {
|
|
45
|
+
({ visit } = await import("unist-util-visit"));
|
|
46
|
+
({ toString } = await import("hast-util-to-string"));
|
|
47
|
+
})();
|
|
48
|
+
var HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
49
|
+
function rehypeSlug(opts) {
|
|
50
|
+
return async (tree, vFile) => {
|
|
51
|
+
const pathWithRandom = `${opts.fileAbsPath}?${Math.random()}`;
|
|
52
|
+
const slugger = getFileSlugger(pathWithRandom, opts.parentAbsPath);
|
|
53
|
+
const deferrers = [];
|
|
54
|
+
vFile.data.toc = [];
|
|
55
|
+
visit(tree, "element", (node) => {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
if (HEADING_TAGS.includes(node.tagName)) {
|
|
58
|
+
const title = toString(node);
|
|
59
|
+
const depth = Number(node.tagName.slice(1));
|
|
60
|
+
deferrers.push(() => {
|
|
61
|
+
const id = slugger.slug(title);
|
|
62
|
+
node.properties.id = id;
|
|
63
|
+
vFile.data.toc.push({ id, depth, title });
|
|
64
|
+
});
|
|
65
|
+
} else if (((_a = node.data) == null ? void 0 : _a.tagName) === import_rehypeEmbed.EMBED_TAG) {
|
|
66
|
+
const { fileAbsPath, query } = node.data;
|
|
67
|
+
let content = import_fs.default.readFileSync(fileAbsPath, "utf-8");
|
|
68
|
+
if (query.get("range")) {
|
|
69
|
+
content = (0, import_utils.getFileRangeLines)(content, query.get("range"));
|
|
70
|
+
} else if (query.get("regexp")) {
|
|
71
|
+
content = (0, import_utils.getFileContentByRegExp)(content, query.get("regexp"), fileAbsPath);
|
|
72
|
+
}
|
|
73
|
+
deferrers.push(async () => {
|
|
74
|
+
const {
|
|
75
|
+
meta: { toc }
|
|
76
|
+
} = await (0, import__.default)(content, {
|
|
77
|
+
...opts,
|
|
78
|
+
parentAbsPath: opts.parentAbsPath || pathWithRandom
|
|
79
|
+
});
|
|
80
|
+
vFile.data.toc.push(...toc);
|
|
81
|
+
});
|
|
82
|
+
} else if ([import_rehypeDemo.DUMI_DEMO_TAG, import_rehypeDemo.DUMI_DEMO_GRID_TAG].includes(node.tagName) && ((_b = node.data) == null ? void 0 : _b[import_rehypeDemo.DEMO_PROP_VALUE_KEY])) {
|
|
83
|
+
const demos = [].concat((_c = node.data) == null ? void 0 : _c[import_rehypeDemo.DEMO_PROP_VALUE_KEY]);
|
|
84
|
+
deferrers.push(() => {
|
|
85
|
+
demos.forEach(({ demo, previewerProps }) => {
|
|
86
|
+
var _a2, _b2;
|
|
87
|
+
if (!demo.inline && previewerProps.title) {
|
|
88
|
+
vFile.data.toc.push({
|
|
89
|
+
id: slugger.slug(demo.id),
|
|
90
|
+
depth: ((_b2 = (_a2 = vFile.data.frontmatter) == null ? void 0 : _a2.demo) == null ? void 0 : _b2.tocDepth) || 3,
|
|
91
|
+
title: previewerProps.title
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
for (let deferrer of deferrers) {
|
|
99
|
+
await deferrer();
|
|
100
|
+
}
|
|
101
|
+
sharedSluggers.delete(pathWithRandom);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { Root } from '
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
2
|
import type { Transformer } from 'unified';
|
|
3
|
-
export default function remarkMeta(
|
|
3
|
+
export default function remarkMeta(opts: {
|
|
4
|
+
fileAbsPath: string;
|
|
5
|
+
}): Transformer<Root>;
|
|
@@ -26,18 +26,39 @@ __export(remarkMeta_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(remarkMeta_exports);
|
|
28
28
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
29
31
|
var visit;
|
|
32
|
+
var toString;
|
|
30
33
|
(async () => {
|
|
31
34
|
({ visit } = await import("unist-util-visit"));
|
|
35
|
+
({ toString } = await import("mdast-util-to-string"));
|
|
32
36
|
})();
|
|
33
|
-
function remarkMeta() {
|
|
34
|
-
return (tree,
|
|
37
|
+
function remarkMeta(opts) {
|
|
38
|
+
return (tree, vFile) => {
|
|
39
|
+
vFile.data.frontmatter = { title: "" };
|
|
35
40
|
visit(tree, "yaml", (node) => {
|
|
36
41
|
try {
|
|
37
|
-
|
|
42
|
+
vFile.data.frontmatter = import_js_yaml.default.load(node.value);
|
|
38
43
|
} catch {
|
|
39
44
|
}
|
|
40
45
|
});
|
|
46
|
+
const titleReaders = [
|
|
47
|
+
() => {
|
|
48
|
+
visit(tree, "heading", (node) => {
|
|
49
|
+
if (node.depth === 1) {
|
|
50
|
+
vFile.data.frontmatter.title = toString(node.children);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
() => {
|
|
55
|
+
const pathWithoutIndex = opts.fileAbsPath.replace(/(\/index([^/]+)?)?\.md$/, "");
|
|
56
|
+
vFile.data.frontmatter.title = import_plugin_utils.lodash.startCase(import_path.default.basename(pathWithoutIndex));
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
while (!vFile.data.frontmatter.title && titleReaders.length) {
|
|
60
|
+
titleReaders.shift()();
|
|
61
|
+
}
|
|
41
62
|
};
|
|
42
63
|
}
|
|
43
64
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/preset.js
CHANGED
|
@@ -32,6 +32,7 @@ var preset_default = (api) => {
|
|
|
32
32
|
require.resolve("./registerMethods"),
|
|
33
33
|
require.resolve("./features/configPlugins"),
|
|
34
34
|
require.resolve("./features/sideEffects"),
|
|
35
|
+
require.resolve("./features/exports"),
|
|
35
36
|
require.resolve("./features/compile"),
|
|
36
37
|
require.resolve("./features/routes"),
|
|
37
38
|
require.resolve("./features/meta"),
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { IDumiDemoProps
|
|
1
|
+
import type { IDumiDemoProps } from "./client/theme-api/DumiDemo";
|
|
2
|
+
import type { ILocalesConfig, IThemeConfig } from "./client/theme-api/types";
|
|
2
3
|
import type { IThemeLoadResult } from "./features/theme/loader";
|
|
3
4
|
import type { IModify } from '@umijs/core';
|
|
4
5
|
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
@@ -15,12 +16,17 @@ export interface IDumiConfig extends IUmiConfig {
|
|
|
15
16
|
codeBlockMode: 'active' | 'passive';
|
|
16
17
|
};
|
|
17
18
|
locales: ILocalesConfig;
|
|
19
|
+
themeConfig: IThemeConfig;
|
|
18
20
|
/**
|
|
19
21
|
* extra unified plugins
|
|
20
22
|
*/
|
|
21
23
|
extraRemarkPlugins?: (string | Function | [string | Function, object])[];
|
|
22
24
|
extraRehypePlugins?: (string | Function | [string | Function, object])[];
|
|
23
25
|
}
|
|
26
|
+
export interface IDumiUserConfig extends Partial<Omit<IDumiConfig, 'resolve' | 'locales'>> {
|
|
27
|
+
resolve?: Partial<IDumiConfig['resolve']>;
|
|
28
|
+
locales?: (IDumiConfig['locales'][0] | Omit<IDumiConfig['locales'][0], 'base'>)[];
|
|
29
|
+
}
|
|
24
30
|
export declare abstract class IDumiTechStack {
|
|
25
31
|
/**
|
|
26
32
|
* tech stack name, such as 'react'
|
|
@@ -53,7 +59,7 @@ export declare abstract class IDumiTechStack {
|
|
|
53
59
|
}
|
|
54
60
|
export declare type IApi = IUmiApi & {
|
|
55
61
|
config: IDumiConfig;
|
|
56
|
-
userConfig:
|
|
62
|
+
userConfig: IDumiUserConfig;
|
|
57
63
|
service: IUmiApi['service'] & {
|
|
58
64
|
themeData: IThemeLoadResult;
|
|
59
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.4",
|
|
4
4
|
"description": "Framework for developing UI components",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,28 +48,40 @@
|
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
+
"@ant-design/icons-svg": "^4.2.1",
|
|
51
52
|
"@swc/core": "^1.2.224",
|
|
52
53
|
"@types/hast": "^2.3.4",
|
|
54
|
+
"@types/mdast": "^3.0.10",
|
|
53
55
|
"@umijs/bundler-utils": "^4.0.22",
|
|
54
56
|
"@umijs/core": "^4.0.22",
|
|
55
57
|
"dumi-assets-types": "2.0.0-alpha.0",
|
|
56
58
|
"estree-util-to-js": "^1.1.0",
|
|
57
59
|
"estree-util-visit": "^1.2.0",
|
|
60
|
+
"github-slugger": "^1.4.0",
|
|
58
61
|
"hast-util-is-element": "^2.1.2",
|
|
59
62
|
"hast-util-raw": "^7.2.2",
|
|
60
63
|
"hast-util-to-estree": "^2.1.0",
|
|
64
|
+
"hast-util-to-string": "^2.0.0",
|
|
65
|
+
"heti": "^0.9.2",
|
|
61
66
|
"html-to-text": "^8.2.1",
|
|
62
67
|
"js-yaml": "^4.1.0",
|
|
63
68
|
"mdast-util-to-string": "^3.1.0",
|
|
64
69
|
"pluralize": "^8.0.0",
|
|
70
|
+
"prism-react-renderer": "^1.3.5",
|
|
71
|
+
"prismjs": "^1.29.0",
|
|
65
72
|
"raw-loader": "^4.0.2",
|
|
73
|
+
"rc-tabs": "12.1.0-alpha.1",
|
|
74
|
+
"react-copy-to-clipboard": "^5.1.0",
|
|
75
|
+
"react-helmet": "^6.1.0",
|
|
66
76
|
"react-intl": "^6.1.1",
|
|
77
|
+
"rehype-autolink-headings": "^6.1.1",
|
|
67
78
|
"rehype-stringify": "^9.0.3",
|
|
68
79
|
"remark-breaks": "^3.0.2",
|
|
69
80
|
"remark-frontmatter": "^4.0.1",
|
|
70
81
|
"remark-gfm": "^3.0.1",
|
|
71
82
|
"remark-parse": "^10.0.1",
|
|
72
83
|
"remark-rehype": "^10.1.0",
|
|
84
|
+
"sass": "^1.55.0",
|
|
73
85
|
"umi": "^4.0.22",
|
|
74
86
|
"unified": "^10.1.2",
|
|
75
87
|
"unist-util-visit": "^4.1.0",
|
|
@@ -81,11 +93,14 @@
|
|
|
81
93
|
"@commitlint/cli": "^17.0.3",
|
|
82
94
|
"@commitlint/config-conventional": "^17.0.3",
|
|
83
95
|
"@jest/types": "^27.0.0",
|
|
96
|
+
"@types/github-slugger": "^1.3.0",
|
|
84
97
|
"@types/jest": "^27.0.0",
|
|
85
98
|
"@types/js-yaml": "^4.0.5",
|
|
86
99
|
"@types/node": "^18.6.3",
|
|
87
100
|
"@types/pluralize": "^0.0.29",
|
|
88
101
|
"@types/react": "^18.0.16",
|
|
102
|
+
"@types/react-copy-to-clipboard": "^5.0.4",
|
|
103
|
+
"@types/react-helmet": "^6.1.5",
|
|
89
104
|
"@umijs/lint": "^4.0.22",
|
|
90
105
|
"@umijs/test": "^4.0.22",
|
|
91
106
|
"cross-env": "^7.0.3",
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
|
|
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 { 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';
|
|
21
|
+
import "./index.less";
|
|
22
|
+
|
|
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
|
+
var Previewer = function Previewer(props) {
|
|
50
|
+
var _files$activeKey$0$ma;
|
|
51
|
+
|
|
52
|
+
var intl = useIntl();
|
|
53
|
+
|
|
54
|
+
var _useLocation = useLocation(),
|
|
55
|
+
hash = _useLocation.hash;
|
|
56
|
+
|
|
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
|
+
var link = "#".concat(props.asset.id);
|
|
77
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
className: "dumi-default-previewer",
|
|
79
|
+
"data-debug": props.debug,
|
|
80
|
+
"data-active": hash === link || undefined
|
|
81
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: "dumi-default-previewer-demo",
|
|
83
|
+
style: {
|
|
84
|
+
background: props.background
|
|
85
|
+
},
|
|
86
|
+
"data-compact": props.compact || undefined,
|
|
87
|
+
"data-transform": props.transform || undefined,
|
|
88
|
+
"data-iframe": props.iframe || undefined
|
|
89
|
+
}, props.iframe ? /*#__PURE__*/React.createElement("iframe", {
|
|
90
|
+
style: ['string', 'number'].includes(_typeof(props.iframe)) ? {
|
|
91
|
+
height: Number(props.iframe)
|
|
92
|
+
} : {},
|
|
93
|
+
src: "/~demos/".concat(props.asset.id)
|
|
94
|
+
}) : props.children), /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: "dumi-default-previewer-meta"
|
|
96
|
+
}, (props.title || props.debug) && /*#__PURE__*/React.createElement("div", {
|
|
97
|
+
className: "dumi-default-previewer-desc"
|
|
98
|
+
}, /*#__PURE__*/React.createElement("h5", null, /*#__PURE__*/React.createElement("a", {
|
|
99
|
+
href: link
|
|
100
|
+
}, props.debug && /*#__PURE__*/React.createElement("strong", null, "DEV ONLY"), props.title)), props.description && /*#__PURE__*/React.createElement("div", {
|
|
101
|
+
className: "markdown",
|
|
102
|
+
dangerouslySetInnerHTML: {
|
|
103
|
+
__html: props.description
|
|
104
|
+
}
|
|
105
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
106
|
+
className: "dumi-default-previewer-actions"
|
|
107
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
108
|
+
className: "dumi-default-previewer-action-btn",
|
|
109
|
+
type: "button",
|
|
110
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
111
|
+
id: 'previewer.actions.codesandbox'
|
|
112
|
+
})
|
|
113
|
+
}, /*#__PURE__*/React.createElement(IconCodeSandbox, null)), /*#__PURE__*/React.createElement("button", {
|
|
114
|
+
className: "dumi-default-previewer-action-btn",
|
|
115
|
+
type: "button",
|
|
116
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
117
|
+
id: 'previewer.actions.codepen'
|
|
118
|
+
})
|
|
119
|
+
}, /*#__PURE__*/React.createElement(IconCodePen, null)), /*#__PURE__*/React.createElement("a", {
|
|
120
|
+
target: "_blank",
|
|
121
|
+
rel: "noreferrer",
|
|
122
|
+
href: props.demoUrl,
|
|
123
|
+
className: "dumi-default-previewer-action-btn",
|
|
124
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
125
|
+
id: 'previewer.actions.separate'
|
|
126
|
+
})
|
|
127
|
+
}, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement("button", {
|
|
128
|
+
className: "dumi-default-previewer-action-btn",
|
|
129
|
+
type: "button",
|
|
130
|
+
onClick: function onClick() {
|
|
131
|
+
return setShowCode(function (prev) {
|
|
132
|
+
return !prev;
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
136
|
+
id: "previewer.actions.code.".concat(showCode ? 'shrink' : 'expand')
|
|
137
|
+
})
|
|
138
|
+
}, showCode ? /*#__PURE__*/React.createElement(IconCodeExpand, null) : /*#__PURE__*/React.createElement(IconCode, null))), showCode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
139
|
+
className: "dumi-default-previewer-sources"
|
|
140
|
+
}, !isSingleFile && /*#__PURE__*/React.createElement(Tabs, {
|
|
141
|
+
className: "dumi-default-previewer-tabs",
|
|
142
|
+
prefixCls: "dumi-default-tabs",
|
|
143
|
+
moreIcon: "\xB7\xB7\xB7",
|
|
144
|
+
defaultActiveKey: String(activeKey),
|
|
145
|
+
onChange: function onChange(key) {
|
|
146
|
+
return setActiveKey(Number(key));
|
|
147
|
+
},
|
|
148
|
+
items: files.map(function (_ref3, i) {
|
|
149
|
+
var _ref4 = _slicedToArray(_ref3, 1),
|
|
150
|
+
filename = _ref4[0];
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
key: String(i),
|
|
154
|
+
label: filename
|
|
155
|
+
};
|
|
156
|
+
})
|
|
157
|
+
})), /*#__PURE__*/React.createElement(SourceCode, {
|
|
158
|
+
lang: lang
|
|
159
|
+
}, files[activeKey][1].value))));
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default Previewer;
|