@antv/dumi-theme-antv 0.1.0
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/README.md +9 -0
- package/es/antv/404/index.js +20 -0
- package/es/antv/Banner/Banner.module.less +412 -0
- package/es/antv/Banner/Notification.js +44 -0
- package/es/antv/Banner/Notification.module.less +108 -0
- package/es/antv/Banner/index.js +115 -0
- package/es/antv/Cases/Cases.js +124 -0
- package/es/antv/Cases/Cases.module.less +203 -0
- package/es/antv/Features/FeatureCard.js +25 -0
- package/es/antv/Features/FeatureCard.module.less +51 -0
- package/es/antv/Features/Features.module.less +169 -0
- package/es/antv/Features/index.js +102 -0
- package/es/antv/Footer/Footer.module.less +36 -0
- package/es/antv/Footer/index.js +232 -0
- package/es/antv/Header/Logo.js +130 -0
- package/es/antv/Products/Product.js +61 -0
- package/es/antv/Products/Product.module.less +146 -0
- package/es/antv/Products/getNewProducts.js +41 -0
- package/es/antv/Products/getProducts.js +466 -0
- package/es/antv/Products/index.js +81 -0
- package/es/antv/hooks.js +81 -0
- package/es/antv/mixins.less +21 -0
- package/es/antv/utils.js +49 -0
- package/es/builtins/API.js +37 -0
- package/es/builtins/Alert.js +9 -0
- package/es/builtins/Alert.less +62 -0
- package/es/builtins/Badge.js +9 -0
- package/es/builtins/Badge.less +31 -0
- package/es/builtins/Example.js +48 -0
- package/es/builtins/Example.less +47 -0
- package/es/builtins/Previewer.js +225 -0
- package/es/builtins/Previewer.less +406 -0
- package/es/builtins/SourceCode.js +72 -0
- package/es/builtins/SourceCode.less +103 -0
- package/es/builtins/Table.js +56 -0
- package/es/builtins/Table.less +43 -0
- package/es/builtins/Tree.js +219 -0
- package/es/builtins/Tree.less +159 -0
- package/es/components/Dark.js +125 -0
- package/es/components/Dark.less +121 -0
- package/es/components/LocaleSelect.js +53 -0
- package/es/components/LocaleSelect.less +59 -0
- package/es/components/Navbar.js +155 -0
- package/es/components/Navbar.less +180 -0
- package/es/components/SearchBar.js +83 -0
- package/es/components/SearchBar.less +165 -0
- package/es/components/SideMenu.js +99 -0
- package/es/components/SideMenu.less +379 -0
- package/es/components/SlugList.js +33 -0
- package/es/components/SlugList.less +18 -0
- package/es/layout.js +276 -0
- package/es/style/layout.less +402 -0
- package/es/style/markdown.less +240 -0
- package/es/style/variables.less +37 -0
- package/package.json +58 -0
- package/src/antv/404/index.tsx +25 -0
- package/src/antv/Banner/Banner.module.less +412 -0
- package/src/antv/Banner/Notification.module.less +108 -0
- package/src/antv/Banner/Notification.tsx +45 -0
- package/src/antv/Banner/index.tsx +121 -0
- package/src/antv/Cases/Cases.module.less +203 -0
- package/src/antv/Cases/Cases.tsx +116 -0
- package/src/antv/Features/FeatureCard.module.less +51 -0
- package/src/antv/Features/FeatureCard.tsx +24 -0
- package/src/antv/Features/Features.module.less +169 -0
- package/src/antv/Features/index.tsx +86 -0
- package/src/antv/Footer/Footer.module.less +36 -0
- package/src/antv/Footer/index.tsx +272 -0
- package/src/antv/Header/Logo.tsx +85 -0
- package/src/antv/Products/Product.module.less +146 -0
- package/src/antv/Products/Product.tsx +80 -0
- package/src/antv/Products/getNewProducts.tsx +53 -0
- package/src/antv/Products/getProducts.tsx +626 -0
- package/src/antv/Products/index.tsx +70 -0
- package/src/antv/hooks.ts +87 -0
- package/src/antv/mixins.less +21 -0
- package/src/antv/utils.ts +44 -0
- package/src/builtins/API.tsx +57 -0
- package/src/builtins/Alert.less +62 -0
- package/src/builtins/Alert.tsx +4 -0
- package/src/builtins/Badge.less +31 -0
- package/src/builtins/Badge.tsx +4 -0
- package/src/builtins/Example.less +47 -0
- package/src/builtins/Example.tsx +34 -0
- package/src/builtins/Previewer.less +406 -0
- package/src/builtins/Previewer.tsx +264 -0
- package/src/builtins/SourceCode.less +103 -0
- package/src/builtins/SourceCode.tsx +55 -0
- package/src/builtins/Table.less +43 -0
- package/src/builtins/Table.tsx +42 -0
- package/src/builtins/Tree.less +159 -0
- package/src/builtins/Tree.tsx +130 -0
- package/src/components/Dark.less +121 -0
- package/src/components/Dark.tsx +78 -0
- package/src/components/LocaleSelect.less +59 -0
- package/src/components/LocaleSelect.tsx +53 -0
- package/src/components/Navbar.less +180 -0
- package/src/components/Navbar.tsx +152 -0
- package/src/components/SearchBar.less +165 -0
- package/src/components/SearchBar.tsx +68 -0
- package/src/components/SideMenu.less +379 -0
- package/src/components/SideMenu.tsx +148 -0
- package/src/components/SlugList.less +18 -0
- package/src/components/SlugList.tsx +20 -0
- package/src/layout.tsx +225 -0
- package/src/style/layout.less +402 -0
- package/src/style/markdown.less +240 -0
- package/src/style/variables.less +37 -0
- package/src/test/SearchBar.test.ts +32 -0
- package/src/test/Table.test.tsx +41 -0
- package/src/test/index.test.tsx +377 -0
package/es/antv/utils.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export var ping = function ping(callback) {
|
|
2
|
+
var url = 'https://private-a' + 'lipay' + 'objects.alip' + 'ay.com/alip' + 'ay-rmsdeploy-image/rmsportal/RKuAiriJqrUhyqW.png';
|
|
3
|
+
var img = new Image();
|
|
4
|
+
var done = false;
|
|
5
|
+
|
|
6
|
+
var finish = function finish(status) {
|
|
7
|
+
if (!done) {
|
|
8
|
+
done = true;
|
|
9
|
+
img.src = '';
|
|
10
|
+
callback(status);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
img.onload = function () {
|
|
15
|
+
return finish('responded');
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
img.onerror = function () {
|
|
19
|
+
return finish('error');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
img.src = url;
|
|
23
|
+
return setTimeout(function () {
|
|
24
|
+
return finish('timeout');
|
|
25
|
+
}, 1500);
|
|
26
|
+
};
|
|
27
|
+
export var capitalize = function capitalize(s) {
|
|
28
|
+
if (typeof s !== 'string') {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
33
|
+
};
|
|
34
|
+
export var getChinaMirrorHost = function getChinaMirrorHost(host) {
|
|
35
|
+
var hostString = typeof host === 'undefined' ? window.location.host : host; // antv.vision => antv.gitee.io
|
|
36
|
+
|
|
37
|
+
if (hostString === 'antv.vision') {
|
|
38
|
+
return 'antv.gitee.io';
|
|
39
|
+
} // g2plot.antv.vision => antv-g2plot.gitee.io
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var match = hostString.match(/(.*)\.antv\.vision/);
|
|
43
|
+
|
|
44
|
+
if (match && match[1]) {
|
|
45
|
+
return "antv-".concat(match[1], ".gitee.io");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return hostString;
|
|
49
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { context, useApiData } from 'dumi/theme';
|
|
3
|
+
var LOCALE_TEXTS = {
|
|
4
|
+
'zh-CN': {
|
|
5
|
+
name: '属性名',
|
|
6
|
+
description: '描述',
|
|
7
|
+
type: '类型',
|
|
8
|
+
default: '默认值',
|
|
9
|
+
required: '(必选)'
|
|
10
|
+
},
|
|
11
|
+
'en-US': {
|
|
12
|
+
name: 'Name',
|
|
13
|
+
description: 'Description',
|
|
14
|
+
type: 'Type',
|
|
15
|
+
default: 'Default',
|
|
16
|
+
required: '(required)'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export default (function (_ref) {
|
|
20
|
+
var identifier = _ref.identifier,
|
|
21
|
+
expt = _ref.export;
|
|
22
|
+
var data = useApiData(identifier);
|
|
23
|
+
|
|
24
|
+
var _useContext = useContext(context),
|
|
25
|
+
locale = _useContext.locale;
|
|
26
|
+
|
|
27
|
+
var texts = /^zh|cn$/i.test(locale) ? LOCALE_TEXTS['zh-CN'] : LOCALE_TEXTS['en-US'];
|
|
28
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, data && /*#__PURE__*/React.createElement("table", {
|
|
29
|
+
style: {
|
|
30
|
+
marginTop: 24
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", null, texts.name), /*#__PURE__*/React.createElement("th", null, texts.description), /*#__PURE__*/React.createElement("th", null, texts.type), /*#__PURE__*/React.createElement("th", null, texts.default))), /*#__PURE__*/React.createElement("tbody", null, data[expt].map(function (row) {
|
|
33
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
34
|
+
key: row.identifier
|
|
35
|
+
}, /*#__PURE__*/React.createElement("td", null, row.identifier), /*#__PURE__*/React.createElement("td", null, row.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, row.type)), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, row.default || row.required && texts.required || '--')));
|
|
36
|
+
}))));
|
|
37
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import './Alert.less';
|
|
5
|
+
export default (function (props) {
|
|
6
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
7
|
+
className: "__dumi-default-alert"
|
|
8
|
+
}, props));
|
|
9
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
@import (reference) '../style/variables.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}-alert {
|
|
4
|
+
@s-border-right: 3px;
|
|
5
|
+
|
|
6
|
+
position: relative;
|
|
7
|
+
margin: 24px 0;
|
|
8
|
+
padding: 10px 20px;
|
|
9
|
+
color: @c-text;
|
|
10
|
+
font-size: 14px;
|
|
11
|
+
line-height: 20px;
|
|
12
|
+
border-left: 0;
|
|
13
|
+
background: #ffffff;
|
|
14
|
+
box-shadow: 0 6px 16px -2px rgba(0, 0, 0, 0.06);
|
|
15
|
+
border-radius: 1px;
|
|
16
|
+
|
|
17
|
+
[data-prefers-color=dark] & {
|
|
18
|
+
color: @c-text-dark;
|
|
19
|
+
background: @c-bg-dark;
|
|
20
|
+
box-shadow: 0 1px 2px -2px rgba(0,0,0,0.64), 0 3px 6px 0 rgba(0,0,0,0.48), 0 5px 12px 4px rgba(0,0,0,0.36);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&::after {
|
|
24
|
+
content: '';
|
|
25
|
+
position: absolute;
|
|
26
|
+
display: inline-block;
|
|
27
|
+
top: 0;
|
|
28
|
+
left: 0;
|
|
29
|
+
bottom: 0;
|
|
30
|
+
width: @s-border-right;
|
|
31
|
+
border-radius: 1px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:first-child {
|
|
35
|
+
margin-top: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&:not([type]),
|
|
39
|
+
&[type='warning'] {
|
|
40
|
+
&::after {
|
|
41
|
+
background: #ffc121;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&[type='info'] {
|
|
46
|
+
&::after {
|
|
47
|
+
background: #69b9ff;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&[type='success'] {
|
|
52
|
+
&::after {
|
|
53
|
+
background: #8cd225;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&[type='error'] {
|
|
58
|
+
&::after {
|
|
59
|
+
background: #ff4646;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import './Badge.less';
|
|
5
|
+
export default (function (props) {
|
|
6
|
+
return /*#__PURE__*/React.createElement("span", _extends({
|
|
7
|
+
className: "__dumi-default-badge"
|
|
8
|
+
}, props));
|
|
9
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@import (reference) '../style/variables.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}-badge {
|
|
4
|
+
display: inline-block;
|
|
5
|
+
margin-left: 6px;
|
|
6
|
+
padding: 1px 7px;
|
|
7
|
+
color: #fff;
|
|
8
|
+
font-size: 13px;
|
|
9
|
+
line-height: 20px;
|
|
10
|
+
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.1);
|
|
11
|
+
box-shadow: 0 6px 16px -2px rgba(0, 0, 0, 0.06);
|
|
12
|
+
border-radius: 1px;
|
|
13
|
+
vertical-align: top;
|
|
14
|
+
|
|
15
|
+
&:not([type]),
|
|
16
|
+
&[type='info'] {
|
|
17
|
+
background: #4569d4;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&[type='warning'] {
|
|
21
|
+
background: #ffc121;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&[type='success'] {
|
|
25
|
+
background: #8cd225;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&[type='error'] {
|
|
29
|
+
background: #ff4646;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 React, { useRef, useEffect, useState } from 'react';
|
|
14
|
+
import './Example.less';
|
|
15
|
+
export default (function (props) {
|
|
16
|
+
var elm = useRef();
|
|
17
|
+
|
|
18
|
+
var _useState = useState(0),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
height = _useState2[0],
|
|
21
|
+
setHeight = _useState2[1];
|
|
22
|
+
|
|
23
|
+
useEffect(function () {
|
|
24
|
+
setHeight(elm.current.contentWindow.document.documentElement.scrollHeight);
|
|
25
|
+
}, [elm]);
|
|
26
|
+
return props.route.meta.examplePath && /*#__PURE__*/React.createElement("div", {
|
|
27
|
+
className: "__dumi-default-example-wrapper"
|
|
28
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: "__dumi-default-example-wrapper-toolbar"
|
|
30
|
+
}, props.route.meta.description || props.route.meta.title, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("button", {
|
|
31
|
+
className: "__dumi-default-icon",
|
|
32
|
+
onClick: function onClick() {
|
|
33
|
+
return elm.current.contentWindow.location.reload();
|
|
34
|
+
}
|
|
35
|
+
}), /*#__PURE__*/React.createElement("a", {
|
|
36
|
+
target: "_blank",
|
|
37
|
+
rel: "noopener noreferrer",
|
|
38
|
+
href: props.route.meta.examplePath,
|
|
39
|
+
className: "__dumi-default-icon"
|
|
40
|
+
}))), /*#__PURE__*/React.createElement("iframe", {
|
|
41
|
+
src: props.route.meta.examplePath,
|
|
42
|
+
ref: elm,
|
|
43
|
+
style: {
|
|
44
|
+
height: height
|
|
45
|
+
},
|
|
46
|
+
title: "dumi"
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
@import (reference) '../style/variables.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}-example-wrapper {
|
|
4
|
+
padding-top: 16px;
|
|
5
|
+
height: calc(100vh - @s-nav-height - 2px);
|
|
6
|
+
|
|
7
|
+
@media @mobile {
|
|
8
|
+
padding-top: 16px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&-toolbar {
|
|
12
|
+
display: flex;
|
|
13
|
+
color: @c-heading;
|
|
14
|
+
font-size: 16px;
|
|
15
|
+
font-weight: 500;
|
|
16
|
+
justify-content: space-between;
|
|
17
|
+
margin-bottom: 16px;
|
|
18
|
+
border-bottom: 1px solid @c-border;
|
|
19
|
+
|
|
20
|
+
button,
|
|
21
|
+
a {
|
|
22
|
+
display: inline-block;
|
|
23
|
+
margin: 6px 0 6px 12px;
|
|
24
|
+
width: 16px;
|
|
25
|
+
height: 16px;
|
|
26
|
+
font-weight: 400;
|
|
27
|
+
border: 0;
|
|
28
|
+
outline: none;
|
|
29
|
+
vertical-align: middle;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
|
|
32
|
+
&:first-child {
|
|
33
|
+
background-position-x: -144px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&:nth-child(2) {
|
|
37
|
+
background-position-x: -126px;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
iframe {
|
|
43
|
+
width: 100%;
|
|
44
|
+
min-height: 100%;
|
|
45
|
+
border: 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
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 React, { useState, useContext, useRef, useEffect } from 'react';
|
|
14
|
+
import Tabs, { TabPane } from 'rc-tabs'; // @ts-ignore
|
|
15
|
+
|
|
16
|
+
import { history } from 'dumi';
|
|
17
|
+
import { context, useCodeSandbox, useRiddle, useMotions, useCopy, useLocaleProps, useDemoUrl, useTSPlaygroundUrl, Link, AnchorLink, usePrefersColor } from 'dumi/theme';
|
|
18
|
+
import SourceCode from './SourceCode';
|
|
19
|
+
import './Previewer.less';
|
|
20
|
+
/**
|
|
21
|
+
* get source code type for file
|
|
22
|
+
* @param file file path
|
|
23
|
+
* @param source file source object
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function getSourceType(file, source) {
|
|
27
|
+
var _file$match;
|
|
28
|
+
|
|
29
|
+
// use file extension as source type first
|
|
30
|
+
var type = (_file$match = file.match(/\.(\w+)$/)) === null || _file$match === void 0 ? void 0 : _file$match[1];
|
|
31
|
+
|
|
32
|
+
if (!type) {
|
|
33
|
+
type = source.tsx ? 'tsx' : 'jsx';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return type;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var Previewer = function Previewer(oProps) {
|
|
40
|
+
var _props$hideActions, _props$hideActions2, _props$hideActions3;
|
|
41
|
+
|
|
42
|
+
var demoRef = useRef();
|
|
43
|
+
|
|
44
|
+
var _useContext = useContext(context),
|
|
45
|
+
locale = _useContext.locale;
|
|
46
|
+
|
|
47
|
+
var props = useLocaleProps(locale, oProps);
|
|
48
|
+
var builtinDemoUrl = useDemoUrl(props.identifier);
|
|
49
|
+
var demoUrl = props.demoUrl || builtinDemoUrl;
|
|
50
|
+
var isActive = (history === null || history === void 0 ? void 0 : history.location.hash) === "#".concat(props.identifier);
|
|
51
|
+
var isSingleFile = Object.keys(props.sources).length === 1;
|
|
52
|
+
var openCSB = useCodeSandbox(((_props$hideActions = props.hideActions) === null || _props$hideActions === void 0 ? void 0 : _props$hideActions.includes('CSB')) ? null : props);
|
|
53
|
+
var openRiddle = useRiddle(((_props$hideActions2 = props.hideActions) === null || _props$hideActions2 === void 0 ? void 0 : _props$hideActions2.includes('RIDDLE')) ? null : props);
|
|
54
|
+
|
|
55
|
+
var _useMotions = useMotions(props.motions || [], demoRef.current),
|
|
56
|
+
_useMotions2 = _slicedToArray(_useMotions, 2),
|
|
57
|
+
execMotions = _useMotions2[0],
|
|
58
|
+
isMotionRunning = _useMotions2[1];
|
|
59
|
+
|
|
60
|
+
var _useCopy = useCopy(),
|
|
61
|
+
_useCopy2 = _slicedToArray(_useCopy, 2),
|
|
62
|
+
copyCode = _useCopy2[0],
|
|
63
|
+
copyStatus = _useCopy2[1];
|
|
64
|
+
|
|
65
|
+
var _useState = useState(function () {
|
|
66
|
+
return props.sources._ ? '_' : Object.keys(props.sources)[0];
|
|
67
|
+
}),
|
|
68
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
69
|
+
currentFile = _useState2[0],
|
|
70
|
+
setCurrentFile = _useState2[1];
|
|
71
|
+
|
|
72
|
+
var _useState3 = useState(getSourceType(currentFile, props.sources[currentFile])),
|
|
73
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
74
|
+
sourceType = _useState4[0],
|
|
75
|
+
setSourceType = _useState4[1];
|
|
76
|
+
|
|
77
|
+
var _useState5 = useState(Boolean(props.defaultShowCode)),
|
|
78
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
79
|
+
showSource = _useState6[0],
|
|
80
|
+
setShowSource = _useState6[1];
|
|
81
|
+
|
|
82
|
+
var _useState7 = useState(Math.random()),
|
|
83
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
84
|
+
iframeKey = _useState8[0],
|
|
85
|
+
setIframeKey = _useState8[1];
|
|
86
|
+
|
|
87
|
+
var currentFileCode = props.sources[currentFile][sourceType] || props.sources[currentFile].content;
|
|
88
|
+
var playgroundUrl = useTSPlaygroundUrl(locale, currentFileCode);
|
|
89
|
+
var iframeRef = useRef();
|
|
90
|
+
|
|
91
|
+
var _usePrefersColor = usePrefersColor(),
|
|
92
|
+
_usePrefersColor2 = _slicedToArray(_usePrefersColor, 1),
|
|
93
|
+
color = _usePrefersColor2[0];
|
|
94
|
+
|
|
95
|
+
var _props$actionBarRende = props.actionBarRender,
|
|
96
|
+
actionBarRender = _props$actionBarRende === void 0 ? function (o) {
|
|
97
|
+
return o;
|
|
98
|
+
} : _props$actionBarRende; // re-render iframe if prefers color changed
|
|
99
|
+
|
|
100
|
+
useEffect(function () {
|
|
101
|
+
setIframeKey(Math.random());
|
|
102
|
+
}, [color]);
|
|
103
|
+
|
|
104
|
+
function handleFileChange(filename) {
|
|
105
|
+
setCurrentFile(filename);
|
|
106
|
+
setSourceType(getSourceType(filename, props.sources[filename]));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
110
|
+
style: props.style,
|
|
111
|
+
className: [props.className, '__dumi-default-previewer', isActive ? '__dumi-default-previewer-target' : ''].filter(Boolean).join(' '),
|
|
112
|
+
id: props.identifier,
|
|
113
|
+
"data-debug": props.debug || undefined,
|
|
114
|
+
"data-iframe": props.iframe || undefined
|
|
115
|
+
}, props.iframe && /*#__PURE__*/React.createElement("div", {
|
|
116
|
+
className: "__dumi-default-previewer-browser-nav"
|
|
117
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
118
|
+
ref: demoRef,
|
|
119
|
+
className: "__dumi-default-previewer-demo",
|
|
120
|
+
style: {
|
|
121
|
+
transform: props.transform ? 'translate(0, 0)' : undefined,
|
|
122
|
+
padding: props.compact || props.iframe && props.compact !== false ? '0' : undefined,
|
|
123
|
+
background: props.background
|
|
124
|
+
}
|
|
125
|
+
}, props.iframe ? /*#__PURE__*/React.createElement("iframe", {
|
|
126
|
+
title: "dumi-previewer",
|
|
127
|
+
style: {
|
|
128
|
+
// both compatible with unit or non-unit, such as 100, 100px, 100vh
|
|
129
|
+
height: String(props.iframe).replace(/(\d)$/, '$1px')
|
|
130
|
+
},
|
|
131
|
+
key: iframeKey,
|
|
132
|
+
src: demoUrl,
|
|
133
|
+
ref: iframeRef
|
|
134
|
+
}) : props.children), /*#__PURE__*/React.createElement("div", {
|
|
135
|
+
className: "__dumi-default-previewer-desc",
|
|
136
|
+
"data-title": props.title
|
|
137
|
+
}, props.title && /*#__PURE__*/React.createElement(AnchorLink, {
|
|
138
|
+
to: "#".concat(props.identifier)
|
|
139
|
+
}, props.title), props.description && /*#__PURE__*/React.createElement("div", {
|
|
140
|
+
// eslint-disable-next-line
|
|
141
|
+
dangerouslySetInnerHTML: {
|
|
142
|
+
__html: props.description
|
|
143
|
+
}
|
|
144
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
145
|
+
className: "__dumi-default-previewer-actions"
|
|
146
|
+
}, actionBarRender( /*#__PURE__*/React.createElement(React.Fragment, null, openCSB && /*#__PURE__*/React.createElement("button", {
|
|
147
|
+
title: "Open demo on CodeSandbox.io",
|
|
148
|
+
className: "__dumi-default-icon",
|
|
149
|
+
role: "codesandbox",
|
|
150
|
+
onClick: openCSB
|
|
151
|
+
}), openRiddle && /*#__PURE__*/React.createElement("button", {
|
|
152
|
+
title: "Open demo on Riddle",
|
|
153
|
+
className: "__dumi-default-icon",
|
|
154
|
+
role: "riddle",
|
|
155
|
+
onClick: openRiddle
|
|
156
|
+
}), props.motions && /*#__PURE__*/React.createElement("button", {
|
|
157
|
+
title: "Execute motions",
|
|
158
|
+
className: "__dumi-default-icon",
|
|
159
|
+
role: "motions",
|
|
160
|
+
disabled: isMotionRunning,
|
|
161
|
+
onClick: function onClick() {
|
|
162
|
+
return execMotions();
|
|
163
|
+
}
|
|
164
|
+
}), props.iframe && /*#__PURE__*/React.createElement("button", {
|
|
165
|
+
title: "Reload demo iframe page",
|
|
166
|
+
className: "__dumi-default-icon",
|
|
167
|
+
role: "refresh",
|
|
168
|
+
onClick: function onClick() {
|
|
169
|
+
return setIframeKey(Math.random());
|
|
170
|
+
}
|
|
171
|
+
}), !((_props$hideActions3 = props.hideActions) === null || _props$hideActions3 === void 0 ? void 0 : _props$hideActions3.includes('EXTERNAL')) && /*#__PURE__*/React.createElement(Link, {
|
|
172
|
+
target: "_blank",
|
|
173
|
+
to: demoUrl
|
|
174
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
175
|
+
title: "Open demo in new tab",
|
|
176
|
+
className: "__dumi-default-icon",
|
|
177
|
+
role: "open-demo",
|
|
178
|
+
type: "button"
|
|
179
|
+
})), /*#__PURE__*/React.createElement("span", null), /*#__PURE__*/React.createElement("button", {
|
|
180
|
+
title: "Copy source code",
|
|
181
|
+
className: "__dumi-default-icon",
|
|
182
|
+
role: "copy",
|
|
183
|
+
"data-status": copyStatus,
|
|
184
|
+
onClick: function onClick() {
|
|
185
|
+
return copyCode(currentFileCode);
|
|
186
|
+
}
|
|
187
|
+
}), sourceType === 'tsx' && showSource && /*#__PURE__*/React.createElement(Link, {
|
|
188
|
+
target: "_blank",
|
|
189
|
+
to: playgroundUrl
|
|
190
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
191
|
+
title: "Get JSX via TypeScript Playground",
|
|
192
|
+
className: "__dumi-default-icon",
|
|
193
|
+
role: "change-tsx",
|
|
194
|
+
type: "button"
|
|
195
|
+
})), /*#__PURE__*/React.createElement("button", {
|
|
196
|
+
title: "Toggle source code panel",
|
|
197
|
+
className: "__dumi-default-icon".concat(showSource ? ' __dumi-default-btn-expand' : ''),
|
|
198
|
+
role: "source",
|
|
199
|
+
type: "button",
|
|
200
|
+
onClick: function onClick() {
|
|
201
|
+
return setShowSource(!showSource);
|
|
202
|
+
}
|
|
203
|
+
})))), showSource && /*#__PURE__*/React.createElement("div", {
|
|
204
|
+
className: "__dumi-default-previewer-source-wrapper"
|
|
205
|
+
}, !isSingleFile && /*#__PURE__*/React.createElement(Tabs, {
|
|
206
|
+
className: "__dumi-default-previewer-source-tab",
|
|
207
|
+
prefixCls: "__dumi-default-tabs",
|
|
208
|
+
moreIcon: "\xB7\xB7\xB7",
|
|
209
|
+
defaultActiveKey: currentFile,
|
|
210
|
+
onChange: handleFileChange
|
|
211
|
+
}, Object.keys(props.sources).map(function (filename) {
|
|
212
|
+
return /*#__PURE__*/React.createElement(TabPane, {
|
|
213
|
+
tab: filename === '_' ? "index.".concat(getSourceType(filename, props.sources[filename])) : filename,
|
|
214
|
+
key: filename
|
|
215
|
+
});
|
|
216
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
217
|
+
className: "__dumi-default-previewer-source"
|
|
218
|
+
}, /*#__PURE__*/React.createElement(SourceCode, {
|
|
219
|
+
code: currentFileCode,
|
|
220
|
+
lang: sourceType,
|
|
221
|
+
showCopy: false
|
|
222
|
+
}))));
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export default Previewer;
|