@arcblock/ux 2.4.40 → 2.4.41
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/lib/CodeBlock/LightBox.js +18 -0
- package/lib/CodeBlock/index.js +44 -21
- package/package.json +4 -4
- package/src/CodeBlock/LightBox.js +85 -0
- package/src/CodeBlock/index.js +68 -14
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
9
|
+
|
10
|
+
var _templateObject;
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
15
|
+
|
16
|
+
const LightBox = (0, _styled.default)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n pre code.hljs {\n display: block;\n overflow-x: auto;\n padding: 1em;\n }\n code.hljs {\n padding: 3px 5px;\n }\n .hljs {\n color: #383a42;\n background: #fafafa;\n }\n .hljs-comment,\n .hljs-quote {\n color: #a0a1a7;\n font-style: italic;\n }\n .hljs-doctag,\n .hljs-formula,\n .hljs-keyword {\n color: #a626a4;\n }\n .hljs-deletion,\n .hljs-name,\n .hljs-section,\n .hljs-selector-tag,\n .hljs-subst {\n color: #e45649;\n }\n .hljs-literal {\n color: #0184bb;\n }\n .hljs-addition,\n .hljs-attribute,\n .hljs-meta .hljs-string,\n .hljs-regexp,\n .hljs-string {\n color: #50a14f;\n }\n .hljs-attr,\n .hljs-number,\n .hljs-selector-attr,\n .hljs-selector-class,\n .hljs-selector-pseudo,\n .hljs-template-variable,\n .hljs-type,\n .hljs-variable {\n color: #986801;\n }\n .hljs-bullet,\n .hljs-link,\n .hljs-meta,\n .hljs-selector-id,\n .hljs-symbol,\n .hljs-title {\n color: #4078f2;\n }\n .hljs-built_in,\n .hljs-class .hljs-title,\n .hljs-title.class_ {\n color: #c18401;\n }\n .hljs-emphasis {\n font-style: italic;\n }\n .hljs-strong {\n font-weight: 700;\n }\n .hljs-link {\n text-decoration: underline;\n }\n\n .copy-button {\n > .default-text {\n color: #222;\n }\n }\n"])));
|
17
|
+
var _default = LightBox;
|
18
|
+
exports.default = _default;
|
package/lib/CodeBlock/index.js
CHANGED
@@ -11,8 +11,6 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
12
12
|
var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));
|
13
13
|
|
14
|
-
var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
|
15
|
-
|
16
14
|
var _useMountedState = _interopRequireDefault(require("react-use/lib/useMountedState"));
|
17
15
|
|
18
16
|
var _core = _interopRequireDefault(require("highlight.js/lib/core"));
|
@@ -55,11 +53,13 @@ var _Colors = _interopRequireDefault(require("../Colors"));
|
|
55
53
|
|
56
54
|
var _Theme = require("../Theme");
|
57
55
|
|
56
|
+
var _LightBox = _interopRequireDefault(require("./LightBox"));
|
57
|
+
|
58
58
|
var _jsxRuntime = require("react/jsx-runtime");
|
59
59
|
|
60
60
|
var _templateObject;
|
61
61
|
|
62
|
-
const _excluded = ["code", "language", "children"];
|
62
|
+
const _excluded = ["code", "language", "children", "dark"];
|
63
63
|
|
64
64
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
65
65
|
|
@@ -131,7 +131,8 @@ function CodeBlock(_ref) {
|
|
131
131
|
let {
|
132
132
|
code,
|
133
133
|
language,
|
134
|
-
children
|
134
|
+
children,
|
135
|
+
dark
|
135
136
|
} = _ref,
|
136
137
|
rest = _objectWithoutProperties(_ref, _excluded);
|
137
138
|
|
@@ -140,6 +141,10 @@ function CodeBlock(_ref) {
|
|
140
141
|
const source = code || children;
|
141
142
|
|
142
143
|
const onCopy = () => {
|
144
|
+
if (copied) {
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
|
143
148
|
(0, _copyToClipboard.default)(source);
|
144
149
|
setCopied(true); // 恢复 copied 状态
|
145
150
|
|
@@ -150,7 +155,7 @@ function CodeBlock(_ref) {
|
|
150
155
|
}, 1500);
|
151
156
|
};
|
152
157
|
|
153
|
-
|
158
|
+
const originEl = /*#__PURE__*/(0, _jsxRuntime.jsxs)(Pre, _objectSpread(_objectSpread({}, rest), {}, {
|
154
159
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
155
160
|
className: "codeblock__inner",
|
156
161
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("code", {
|
@@ -159,35 +164,53 @@ function CodeBlock(_ref) {
|
|
159
164
|
__html: _core.default.highlightAuto(source, [language]).value
|
160
165
|
}
|
161
166
|
})
|
162
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
167
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
163
168
|
className: "copy-button",
|
164
169
|
onClick: onCopy,
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
170
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
171
|
+
className: "default-text",
|
172
|
+
children: language
|
173
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
174
|
+
className: "hover-text",
|
175
|
+
children: !copied ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
176
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_FileCopy.default, {
|
177
|
+
className: "copy-icon"
|
178
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
179
|
+
className: "button-lang-text",
|
180
|
+
children: "copy"
|
181
|
+
})]
|
182
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
183
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Check.default, {
|
184
|
+
className: "copy-icon"
|
185
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
186
|
+
className: "button-lang-text",
|
187
|
+
children: "copied"
|
188
|
+
})]
|
189
|
+
})
|
177
190
|
})]
|
178
191
|
})]
|
179
192
|
}));
|
193
|
+
|
194
|
+
if (!dark) {
|
195
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LightBox.default, {
|
196
|
+
children: originEl
|
197
|
+
});
|
198
|
+
}
|
199
|
+
|
200
|
+
return originEl;
|
180
201
|
}
|
181
202
|
|
182
203
|
CodeBlock.propTypes = {
|
183
204
|
code: _propTypes.default.string,
|
184
205
|
language: _propTypes.default.string,
|
185
|
-
children: _propTypes.default.any
|
206
|
+
children: _propTypes.default.any,
|
207
|
+
dark: _propTypes.default.bool
|
186
208
|
};
|
187
209
|
CodeBlock.defaultProps = {
|
188
210
|
code: '',
|
189
211
|
language: 'text',
|
190
|
-
children: null
|
212
|
+
children: null,
|
213
|
+
dark: true
|
191
214
|
};
|
192
215
|
const fontFamily = 'source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace !important';
|
193
|
-
const Pre = (0, _Theme.styled)('pre')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-family: ", ";\n display: block;\n font-size: 14px;\n line-height: 1.42857143;\n margin: 0 0 32px;\n word-break: break-word;\n word-wrap: break-word;\n text-align: left;\n border-radius: 5px;\n border: 1px solid #dedede;\n background: #222;\n color:
|
216
|
+
const Pre = (0, _Theme.styled)('pre')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-family: ", ";\n display: block;\n font-size: 14px;\n line-height: 1.42857143;\n margin: 0 0 32px;\n word-break: break-word;\n word-wrap: break-word;\n text-align: left;\n border-radius: 5px;\n border: 1px solid #dedede;\n background: #222;\n color: ", ";\n position: relative;\n\n .codeblock__inner {\n display: block;\n width: 100%;\n max-height: 46.25rem;\n overflow: scroll;\n }\n\n .copy-button {\n display: flex;\n justify-content: center;\n align-items: center;\n position: absolute;\n top: 8px;\n right: 24px;\n padding: 4px;\n min-width: 72px;\n height: 24px;\n border-radius: 4px;\n background: transparent;\n cursor: pointer;\n transition: all ease 0.2s;\n\n .copy-icon {\n font-size: 16px;\n color: ", ";\n }\n\n .hover-text {\n display: none;\n }\n .default-text {\n font-size: 12px;\n color: ", ";\n }\n }\n\n &:hover {\n .copy-button {\n display: flex;\n background: ", ";\n\n .hover-text {\n display: flex;\n justify-content: center;\n align-items: center;\n color: ", ";\n }\n .default-text {\n display: none;\n font-size: 12px;\n }\n }\n }\n\n .button-lang-text {\n margin-left: 4px;\n font-size: 12px;\n color: ", ";\n }\n\n code {\n counter-reset: line;\n counter-increment: line;\n padding: 16px;\n font-family: ", ";\n * {\n font-family: ", ";\n }\n }\n\n .hljs * {\n white-space: normal; // autowrap\n }\n"])), fontFamily, _Colors.default.common.white, _Colors.default.common.white, _Colors.default.common.white, _Colors.default.primary.main, _Colors.default.common.white, _Colors.default.common.white, fontFamily, fontFamily);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.4.
|
3
|
+
"version": "2.4.41",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -47,10 +47,10 @@
|
|
47
47
|
"react": ">=18.1.0",
|
48
48
|
"react-ga": "^2.7.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "87dcf0b0f05b1bc45038095f34cd236c739c6180",
|
51
51
|
"dependencies": {
|
52
|
-
"@arcblock/icons": "^2.4.
|
53
|
-
"@arcblock/react-hooks": "^2.4.
|
52
|
+
"@arcblock/icons": "^2.4.41",
|
53
|
+
"@arcblock/react-hooks": "^2.4.41",
|
54
54
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
55
55
|
"@emotion/react": "^11.10.4",
|
56
56
|
"@emotion/styled": "^11.10.4",
|
@@ -0,0 +1,85 @@
|
|
1
|
+
// highlight.js/styles/atom-one-light.css
|
2
|
+
import styled from '@emotion/styled';
|
3
|
+
|
4
|
+
const LightBox = styled('div')`
|
5
|
+
display: block;
|
6
|
+
pre code.hljs {
|
7
|
+
display: block;
|
8
|
+
overflow-x: auto;
|
9
|
+
padding: 1em;
|
10
|
+
}
|
11
|
+
code.hljs {
|
12
|
+
padding: 3px 5px;
|
13
|
+
}
|
14
|
+
.hljs {
|
15
|
+
color: #383a42;
|
16
|
+
background: #fafafa;
|
17
|
+
}
|
18
|
+
.hljs-comment,
|
19
|
+
.hljs-quote {
|
20
|
+
color: #a0a1a7;
|
21
|
+
font-style: italic;
|
22
|
+
}
|
23
|
+
.hljs-doctag,
|
24
|
+
.hljs-formula,
|
25
|
+
.hljs-keyword {
|
26
|
+
color: #a626a4;
|
27
|
+
}
|
28
|
+
.hljs-deletion,
|
29
|
+
.hljs-name,
|
30
|
+
.hljs-section,
|
31
|
+
.hljs-selector-tag,
|
32
|
+
.hljs-subst {
|
33
|
+
color: #e45649;
|
34
|
+
}
|
35
|
+
.hljs-literal {
|
36
|
+
color: #0184bb;
|
37
|
+
}
|
38
|
+
.hljs-addition,
|
39
|
+
.hljs-attribute,
|
40
|
+
.hljs-meta .hljs-string,
|
41
|
+
.hljs-regexp,
|
42
|
+
.hljs-string {
|
43
|
+
color: #50a14f;
|
44
|
+
}
|
45
|
+
.hljs-attr,
|
46
|
+
.hljs-number,
|
47
|
+
.hljs-selector-attr,
|
48
|
+
.hljs-selector-class,
|
49
|
+
.hljs-selector-pseudo,
|
50
|
+
.hljs-template-variable,
|
51
|
+
.hljs-type,
|
52
|
+
.hljs-variable {
|
53
|
+
color: #986801;
|
54
|
+
}
|
55
|
+
.hljs-bullet,
|
56
|
+
.hljs-link,
|
57
|
+
.hljs-meta,
|
58
|
+
.hljs-selector-id,
|
59
|
+
.hljs-symbol,
|
60
|
+
.hljs-title {
|
61
|
+
color: #4078f2;
|
62
|
+
}
|
63
|
+
.hljs-built_in,
|
64
|
+
.hljs-class .hljs-title,
|
65
|
+
.hljs-title.class_ {
|
66
|
+
color: #c18401;
|
67
|
+
}
|
68
|
+
.hljs-emphasis {
|
69
|
+
font-style: italic;
|
70
|
+
}
|
71
|
+
.hljs-strong {
|
72
|
+
font-weight: 700;
|
73
|
+
}
|
74
|
+
.hljs-link {
|
75
|
+
text-decoration: underline;
|
76
|
+
}
|
77
|
+
|
78
|
+
.copy-button {
|
79
|
+
> .default-text {
|
80
|
+
color: #222;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
`;
|
84
|
+
|
85
|
+
export default LightBox;
|
package/src/CodeBlock/index.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
import { useState } from 'react';
|
3
3
|
import PropTypes from 'prop-types';
|
4
4
|
import Copy from 'copy-to-clipboard';
|
5
|
-
import Button from '@mui/material/IconButton';
|
6
5
|
import useMountedState from 'react-use/lib/useMountedState';
|
7
6
|
|
8
7
|
import hljs from 'highlight.js/lib/core';
|
@@ -27,6 +26,7 @@ import CopyIcon from '@mui/icons-material/FileCopy';
|
|
27
26
|
import CheckIcon from '@mui/icons-material/Check';
|
28
27
|
import colors from '../Colors';
|
29
28
|
import { styled } from '../Theme';
|
29
|
+
import LightBox from './LightBox';
|
30
30
|
|
31
31
|
hljs.registerLanguage('javascript', javascript);
|
32
32
|
hljs.registerLanguage('js', javascript);
|
@@ -55,12 +55,15 @@ hljs.registerLanguage('swift', swift);
|
|
55
55
|
hljs.registerLanguage('objectivec', objectivec);
|
56
56
|
hljs.registerLanguage('oc', objectivec);
|
57
57
|
|
58
|
-
export default function CodeBlock({ code, language, children, ...rest }) {
|
58
|
+
export default function CodeBlock({ code, language, children, dark, ...rest }) {
|
59
59
|
const [copied, setCopied] = useState(false);
|
60
60
|
const isMounted = useMountedState();
|
61
61
|
const source = code || children;
|
62
62
|
|
63
63
|
const onCopy = () => {
|
64
|
+
if (copied) {
|
65
|
+
return;
|
66
|
+
}
|
64
67
|
Copy(source);
|
65
68
|
setCopied(true);
|
66
69
|
// 恢复 copied 状态
|
@@ -71,7 +74,7 @@ export default function CodeBlock({ code, language, children, ...rest }) {
|
|
71
74
|
}, 1500);
|
72
75
|
};
|
73
76
|
|
74
|
-
|
77
|
+
const originEl = (
|
75
78
|
<Pre {...rest}>
|
76
79
|
<span className="codeblock__inner">
|
77
80
|
<code
|
@@ -79,24 +82,44 @@ export default function CodeBlock({ code, language, children, ...rest }) {
|
|
79
82
|
dangerouslySetInnerHTML={{ __html: hljs.highlightAuto(source, [language]).value }}
|
80
83
|
/>
|
81
84
|
</span>
|
82
|
-
<
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
<div className="copy-button" onClick={onCopy}>
|
86
|
+
<span className="default-text">{language}</span>
|
87
|
+
<span className="hover-text">
|
88
|
+
{!copied ? (
|
89
|
+
<>
|
90
|
+
<CopyIcon className="copy-icon" />
|
91
|
+
<span className="button-lang-text">copy</span>
|
92
|
+
</>
|
93
|
+
) : (
|
94
|
+
<>
|
95
|
+
<CheckIcon className="copy-icon" />
|
96
|
+
<span className="button-lang-text">copied</span>
|
97
|
+
</>
|
98
|
+
)}
|
99
|
+
</span>
|
100
|
+
</div>
|
86
101
|
</Pre>
|
87
102
|
);
|
103
|
+
|
104
|
+
if (!dark) {
|
105
|
+
return <LightBox>{originEl}</LightBox>;
|
106
|
+
}
|
107
|
+
|
108
|
+
return originEl;
|
88
109
|
}
|
89
110
|
|
90
111
|
CodeBlock.propTypes = {
|
91
112
|
code: PropTypes.string,
|
92
113
|
language: PropTypes.string,
|
93
114
|
children: PropTypes.any,
|
115
|
+
dark: PropTypes.bool,
|
94
116
|
};
|
95
117
|
|
96
118
|
CodeBlock.defaultProps = {
|
97
119
|
code: '',
|
98
120
|
language: 'text',
|
99
121
|
children: null,
|
122
|
+
dark: true,
|
100
123
|
};
|
101
124
|
|
102
125
|
const fontFamily = 'source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace !important';
|
@@ -112,7 +135,7 @@ const Pre = styled('pre')`
|
|
112
135
|
border-radius: 5px;
|
113
136
|
border: 1px solid #dedede;
|
114
137
|
background: #222;
|
115
|
-
color:
|
138
|
+
color: ${colors.common.white};
|
116
139
|
position: relative;
|
117
140
|
|
118
141
|
.codeblock__inner {
|
@@ -123,32 +146,63 @@ const Pre = styled('pre')`
|
|
123
146
|
}
|
124
147
|
|
125
148
|
.copy-button {
|
126
|
-
display:
|
149
|
+
display: flex;
|
150
|
+
justify-content: center;
|
151
|
+
align-items: center;
|
127
152
|
position: absolute;
|
128
153
|
top: 8px;
|
129
154
|
right: 24px;
|
130
155
|
padding: 4px;
|
156
|
+
min-width: 72px;
|
157
|
+
height: 24px;
|
131
158
|
border-radius: 4px;
|
159
|
+
background: transparent;
|
160
|
+
cursor: pointer;
|
161
|
+
transition: all ease 0.2s;
|
132
162
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
163
|
+
.copy-icon {
|
164
|
+
font-size: 16px;
|
165
|
+
color: ${colors.common.white};
|
166
|
+
}
|
167
|
+
|
168
|
+
.hover-text {
|
169
|
+
display: none;
|
170
|
+
}
|
171
|
+
.default-text {
|
172
|
+
font-size: 12px;
|
173
|
+
color: ${colors.common.white};
|
137
174
|
}
|
138
175
|
}
|
139
176
|
|
140
177
|
&:hover {
|
141
178
|
.copy-button {
|
142
179
|
display: flex;
|
180
|
+
background: ${colors.primary.main};
|
181
|
+
|
182
|
+
.hover-text {
|
183
|
+
display: flex;
|
184
|
+
justify-content: center;
|
185
|
+
align-items: center;
|
186
|
+
color: ${colors.common.white};
|
187
|
+
}
|
188
|
+
.default-text {
|
189
|
+
display: none;
|
190
|
+
font-size: 12px;
|
191
|
+
}
|
143
192
|
}
|
144
193
|
}
|
145
194
|
|
195
|
+
.button-lang-text {
|
196
|
+
margin-left: 4px;
|
197
|
+
font-size: 12px;
|
198
|
+
color: ${colors.common.white};
|
199
|
+
}
|
200
|
+
|
146
201
|
code {
|
147
202
|
counter-reset: line;
|
148
203
|
counter-increment: line;
|
149
204
|
padding: 16px;
|
150
205
|
font-family: ${fontFamily};
|
151
|
-
color: #fff;
|
152
206
|
* {
|
153
207
|
font-family: ${fontFamily};
|
154
208
|
}
|