@arcblock/result-html-pages 3.4.14 → 3.5.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/package.json +6 -2
- package/src/ResultHTMLPages.stories.jsx +0 -101
- package/src/icons.js +0 -5
- package/src/index.js +0 -42
- package/src/template.js +0 -75
- package/src/translations.js +0 -63
- package/vite.config.mjs +0 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/result-html-pages",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "This package provide a function that generates html code for common error pages such as 404, 500, etc.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arcblock",
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
33
33
|
},
|
|
34
|
+
"files": [
|
|
35
|
+
"lib",
|
|
36
|
+
"es"
|
|
37
|
+
],
|
|
34
38
|
"publishConfig": {
|
|
35
39
|
"access": "public"
|
|
36
40
|
},
|
|
@@ -38,5 +42,5 @@
|
|
|
38
42
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
39
43
|
"jest": "^29.7.0"
|
|
40
44
|
},
|
|
41
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "1cfc816004525cf1b352ec2b64d459f4769f0237"
|
|
42
46
|
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { useState, useMemo } from 'react';
|
|
2
|
-
import { Box, Select, MenuItem } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
import { render } from './index';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Feedback/ResultHTMLPages',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function Default() {
|
|
11
|
-
const [status, setStatus] = useState('404');
|
|
12
|
-
const html = useMemo(() => render({ status }), [status]);
|
|
13
|
-
|
|
14
|
-
const handleChange = (event) => {
|
|
15
|
-
setStatus(event.target.value);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<Box>
|
|
20
|
-
<Box
|
|
21
|
-
sx={{
|
|
22
|
-
m: 2,
|
|
23
|
-
}}>
|
|
24
|
-
<Select value={status} onChange={handleChange}>
|
|
25
|
-
<MenuItem value="404">404</MenuItem>
|
|
26
|
-
<MenuItem value="403">403</MenuItem>
|
|
27
|
-
<MenuItem value="500">500</MenuItem>
|
|
28
|
-
<MenuItem value="502">502</MenuItem>
|
|
29
|
-
<MenuItem value="error">error</MenuItem>
|
|
30
|
-
<MenuItem value="maintenance">maintenance</MenuItem>
|
|
31
|
-
<MenuItem value="comingSoon">comingSoon</MenuItem>
|
|
32
|
-
</Select>
|
|
33
|
-
</Box>
|
|
34
|
-
<Box
|
|
35
|
-
sx={{
|
|
36
|
-
height: 600,
|
|
37
|
-
m: 2,
|
|
38
|
-
border: 1,
|
|
39
|
-
}}>
|
|
40
|
-
<iframe
|
|
41
|
-
title="html page"
|
|
42
|
-
src={`data:text/html;charset=utf-8,${encodeURIComponent(html)}`}
|
|
43
|
-
frameBorder={0}
|
|
44
|
-
style={{ width: '100%', height: '100%' }}
|
|
45
|
-
/>
|
|
46
|
-
</Box>
|
|
47
|
-
</Box>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
Default.storyName = 'default';
|
|
52
|
-
|
|
53
|
-
export function InfoPage() {
|
|
54
|
-
const html = render({
|
|
55
|
-
status: 'info',
|
|
56
|
-
title: 'Here is a info message',
|
|
57
|
-
extra: '<a href="/">Back Home</a>',
|
|
58
|
-
});
|
|
59
|
-
return (
|
|
60
|
-
<Box
|
|
61
|
-
sx={{
|
|
62
|
-
height: 600,
|
|
63
|
-
m: 2,
|
|
64
|
-
border: 1,
|
|
65
|
-
}}>
|
|
66
|
-
<iframe
|
|
67
|
-
title="info page"
|
|
68
|
-
src={`data:text/html;charset=utf-8,${encodeURIComponent(html)}`}
|
|
69
|
-
frameBorder={0}
|
|
70
|
-
style={{ width: '100%', height: '100%' }}
|
|
71
|
-
/>
|
|
72
|
-
</Box>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
InfoPage.storyName = 'info page';
|
|
77
|
-
|
|
78
|
-
export function WithoutIcon() {
|
|
79
|
-
const html = render({
|
|
80
|
-
status: '404',
|
|
81
|
-
icon: null,
|
|
82
|
-
extra: '<a href="/">Back Home</a>',
|
|
83
|
-
});
|
|
84
|
-
return (
|
|
85
|
-
<Box
|
|
86
|
-
sx={{
|
|
87
|
-
height: 600,
|
|
88
|
-
m: 2,
|
|
89
|
-
border: 1,
|
|
90
|
-
}}>
|
|
91
|
-
<iframe
|
|
92
|
-
title="custom 404 page"
|
|
93
|
-
src={`data:text/html;charset=utf-8,${encodeURIComponent(html)}`}
|
|
94
|
-
frameBorder={0}
|
|
95
|
-
style={{ width: '100%', height: '100%' }}
|
|
96
|
-
/>
|
|
97
|
-
</Box>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
WithoutIcon.storyName = 'without icon';
|
package/src/icons.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export const ErrorIcon =
|
|
2
|
-
'<svg focusable="false" viewBox="0 0 24 24" aria-hidden="true" style="color: rgb(241, 110, 110); font-size: 72px;"><path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm4.3 14.3c-.39.39-1.02.39-1.41 0L12 13.41 9.11 16.3c-.39.39-1.02.39-1.41 0a.9959.9959 0 010-1.41L10.59 12 7.7 9.11a.9959.9959 0 010-1.41c.39-.39 1.02-.39 1.41 0L12 10.59l2.89-2.89c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41L13.41 12l2.89 2.89c.38.38.38 1.02 0 1.41z"></path></svg>';
|
|
3
|
-
|
|
4
|
-
export const InfoIcon =
|
|
5
|
-
'<svg focusable="false" viewBox="0 0 24 24" aria-hidden="true" style="color: rgb(7, 117, 248); font-size: 72px;"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"></path></svg>';
|
package/src/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import template from './template';
|
|
2
|
-
import translations from './translations';
|
|
3
|
-
import { ErrorIcon, InfoIcon } from './icons';
|
|
4
|
-
|
|
5
|
-
const renderHandler = ({ type, locale, icon, ...rest }) => {
|
|
6
|
-
const translation = translations[locale] || translations.en;
|
|
7
|
-
return template.render({
|
|
8
|
-
icon,
|
|
9
|
-
title: translation[type].title,
|
|
10
|
-
description: translation[type].description,
|
|
11
|
-
...rest,
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const renderers = {
|
|
16
|
-
404: ({ locale = 'en', ...rest }) => renderHandler({ type: 404, locale, icon: ErrorIcon, ...rest }),
|
|
17
|
-
403: ({ locale = 'en', ...rest }) => renderHandler({ type: 403, locale, icon: ErrorIcon, ...rest }),
|
|
18
|
-
500: ({ locale = 'en', ...rest }) => renderHandler({ type: 500, locale, icon: ErrorIcon, ...rest }),
|
|
19
|
-
502: ({ locale = 'en', ...rest }) => renderHandler({ type: 502, locale, icon: ErrorIcon, ...rest }),
|
|
20
|
-
error: ({ locale = 'en', ...rest }) => renderHandler({ type: 'error', locale, icon: ErrorIcon, ...rest }),
|
|
21
|
-
maintenance: ({ locale = 'en', ...rest }) => renderHandler({ type: 'maintenance', locale, icon: InfoIcon, ...rest }),
|
|
22
|
-
comingSoon: ({ locale = 'en', ...rest }) => renderHandler({ type: 'comingSoon', locale, icon: InfoIcon, ...rest }),
|
|
23
|
-
info: (props) => {
|
|
24
|
-
return template.render({
|
|
25
|
-
icon: InfoIcon,
|
|
26
|
-
...props,
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
32
|
-
export function render(options = {}) {
|
|
33
|
-
const { status, locale = 'en', ...rest } = options;
|
|
34
|
-
if (status) {
|
|
35
|
-
const renderer = renderers[status];
|
|
36
|
-
if (!renderer) {
|
|
37
|
-
throw new Error(`Please provide a valid status. Valid values are: ${Object.keys(renderers).join(', ')}`);
|
|
38
|
-
}
|
|
39
|
-
return renderer({ locale, ...rest });
|
|
40
|
-
}
|
|
41
|
-
return template.render({ ...rest });
|
|
42
|
-
}
|
package/src/template.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
function render({ pageTitle, title, icon, description, extra, hiddenText = '' }) {
|
|
2
|
-
if (!title) {
|
|
3
|
-
throw new Error('title is required');
|
|
4
|
-
}
|
|
5
|
-
// eslint-disable-next-line no-param-reassign
|
|
6
|
-
pageTitle = pageTitle || `${title} - Blocklet Server`;
|
|
7
|
-
return `
|
|
8
|
-
<!DOCTYPE html>
|
|
9
|
-
<html lang="en">
|
|
10
|
-
<head>
|
|
11
|
-
<meta charset="UTF-8">
|
|
12
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
13
|
-
<title>${pageTitle}</title>
|
|
14
|
-
<style>
|
|
15
|
-
html {
|
|
16
|
-
box-sizing: border-box;
|
|
17
|
-
font-size: 16px;
|
|
18
|
-
}
|
|
19
|
-
*, *::before, *::after {
|
|
20
|
-
box-sizing: inherit;
|
|
21
|
-
}
|
|
22
|
-
html, body {
|
|
23
|
-
height: 100%;
|
|
24
|
-
}
|
|
25
|
-
body {
|
|
26
|
-
margin: 0;
|
|
27
|
-
}
|
|
28
|
-
.container {
|
|
29
|
-
display: flex;
|
|
30
|
-
flex-direction: column;
|
|
31
|
-
justify-content: center;
|
|
32
|
-
align-items: center;
|
|
33
|
-
height: 100%;
|
|
34
|
-
padding: 16px;
|
|
35
|
-
background-color: #f7f8fb;
|
|
36
|
-
}
|
|
37
|
-
.svg-wrapper > * {
|
|
38
|
-
fill: currentColor;
|
|
39
|
-
width: 1em;
|
|
40
|
-
height: 1em;
|
|
41
|
-
display: inline-block;
|
|
42
|
-
}
|
|
43
|
-
.title {
|
|
44
|
-
margin-top: 24px;
|
|
45
|
-
font-size: 22px;
|
|
46
|
-
font-weight: 400;
|
|
47
|
-
color: #47494E;
|
|
48
|
-
text-align: center;
|
|
49
|
-
}
|
|
50
|
-
.description {
|
|
51
|
-
margin-top: 8px;
|
|
52
|
-
font-size: 14px;
|
|
53
|
-
color: #7F828B;
|
|
54
|
-
text-align: center;
|
|
55
|
-
}
|
|
56
|
-
.extra {
|
|
57
|
-
margin-top: 24px;
|
|
58
|
-
}
|
|
59
|
-
</style>
|
|
60
|
-
</head>
|
|
61
|
-
<body>
|
|
62
|
-
<div class="container">
|
|
63
|
-
${icon ? `<span class="svg-wrapper">${icon}</span>` : ''}
|
|
64
|
-
<div class="title">
|
|
65
|
-
${title}
|
|
66
|
-
</div>
|
|
67
|
-
${description ? `<div class="description">${description}</div>` : ''}
|
|
68
|
-
${extra ? `<div class="extra">${extra}</div>` : ''}
|
|
69
|
-
${hiddenText ? `<div style="display:none;">${hiddenText}</div>` : ''}
|
|
70
|
-
</div>
|
|
71
|
-
</body>
|
|
72
|
-
</html>`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export default { render };
|
package/src/translations.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
en: {
|
|
3
|
-
404: {
|
|
4
|
-
title: '404 - Page Not Found',
|
|
5
|
-
description: 'Sorry about that, the page you are looking for does not exist or has been moved.',
|
|
6
|
-
},
|
|
7
|
-
403: {
|
|
8
|
-
title: '403 – Forbidden',
|
|
9
|
-
description: 'Sorry, you are not authorized to access this page.',
|
|
10
|
-
},
|
|
11
|
-
500: {
|
|
12
|
-
title: '500 - Internal Server Error',
|
|
13
|
-
description: 'An internal server error has occurred. Please try again later.',
|
|
14
|
-
},
|
|
15
|
-
502: {
|
|
16
|
-
title: '502 - Bad Gateway',
|
|
17
|
-
description: 'Proxy to destination server failed. Please try again later.',
|
|
18
|
-
},
|
|
19
|
-
error: {
|
|
20
|
-
title: 'Application Error',
|
|
21
|
-
description: 'Something went wrong. Please try again later.',
|
|
22
|
-
},
|
|
23
|
-
maintenance: {
|
|
24
|
-
title: 'Offline for maintenance',
|
|
25
|
-
description: 'This app is undergoing maintenance right now. Please check back later.',
|
|
26
|
-
},
|
|
27
|
-
comingSoon: {
|
|
28
|
-
title: 'Coming Soon',
|
|
29
|
-
description: "Our website is under construction. We'll be here soon with our new website.",
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
zh: {
|
|
34
|
-
404: {
|
|
35
|
-
title: '404 - 页面未找到',
|
|
36
|
-
description: '很抱歉,您正在寻找的页面不存在或已被移动。',
|
|
37
|
-
},
|
|
38
|
-
403: {
|
|
39
|
-
title: '403 – 禁止访问',
|
|
40
|
-
description: '很抱歉,您没有权限访问此页面。',
|
|
41
|
-
},
|
|
42
|
-
500: {
|
|
43
|
-
title: '500 - 内部服务器错误',
|
|
44
|
-
description: '发生了一个内部服务器错误。请稍后再试。',
|
|
45
|
-
},
|
|
46
|
-
502: {
|
|
47
|
-
title: '502 - 网关错误',
|
|
48
|
-
description: '无法代理到目的服务器。请稍后再试。',
|
|
49
|
-
},
|
|
50
|
-
error: {
|
|
51
|
-
title: 'Application Error',
|
|
52
|
-
description: '出错了, 请稍后再试。',
|
|
53
|
-
},
|
|
54
|
-
maintenance: {
|
|
55
|
-
title: '维护中',
|
|
56
|
-
description: '应用程序正在进行维护。请稍后再查看。',
|
|
57
|
-
},
|
|
58
|
-
comingSoon: {
|
|
59
|
-
title: '即将上线',
|
|
60
|
-
description: '我们的网站正在建设中。我们很快就会在这里推出我们的新网站。',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
};
|
package/vite.config.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import svgr from 'vite-plugin-svgr';
|
|
3
|
-
import react from '@vitejs/plugin-react';
|
|
4
|
-
import noBundlePlugin from 'vite-plugin-no-bundle';
|
|
5
|
-
import fg from 'fast-glob';
|
|
6
|
-
|
|
7
|
-
export default defineConfig({
|
|
8
|
-
plugins: [
|
|
9
|
-
react({ jsxRuntime: 'automatic' }),
|
|
10
|
-
svgr({
|
|
11
|
-
include: ['**/*.svg', '**/*.svg?react'],
|
|
12
|
-
}),
|
|
13
|
-
noBundlePlugin({
|
|
14
|
-
root: 'src',
|
|
15
|
-
copy: ['**/*.png', '**/*.gif', '**/*.jpg', '**/*.jpeg', '**/*.d.ts'],
|
|
16
|
-
}),
|
|
17
|
-
],
|
|
18
|
-
build: {
|
|
19
|
-
lib: {
|
|
20
|
-
entry: fg.sync('src/**/*.{tsx,ts,jsx,js}', {
|
|
21
|
-
ignore: ['**/stories/**', '**/demo/**', '**/*.d.ts', '**/*.stories.*'],
|
|
22
|
-
}),
|
|
23
|
-
formats: ['es', 'cjs'],
|
|
24
|
-
fileName: (format, entryName) => `${format === 'es' ? 'es' : 'lib'}/${entryName}.js`,
|
|
25
|
-
},
|
|
26
|
-
outDir: './',
|
|
27
|
-
emptyOutDir: false,
|
|
28
|
-
},
|
|
29
|
-
});
|