Skip to content

Commit

Permalink
chore: auto merge branches (ant-design#44328)
Browse files Browse the repository at this point in the history
chore: feature merge master
  • Loading branch information
github-actions[bot] authored Aug 21, 2023
2 parents 8e7d02c + beb61e6 commit f34ff52
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 272 deletions.
172 changes: 172 additions & 0 deletions .dumi/mirror-modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
(function createMirrorModal() {
if (
(navigator.languages.includes('zh') || navigator.languages.includes('zh-CN')) &&
/-cn\/?$/.test(window.location.pathname) &&
!['ant-design.gitee.io', 'ant-design.antgroup.com'].includes(window.location.hostname)
) {
const ANTD_DOT_NOT_SHOW_MIRROR_MODAL = 'ANT_DESIGN_DO_NOT_OPEN_MIRROR_MODAL';

const lastShowTime = window.localStorage.getItem(ANTD_DOT_NOT_SHOW_MIRROR_MODAL);
if (
lastShowTime &&
lastShowTime !== 'true' &&
Date.now() - new Date(lastShowTime).getTime() < 7 * 24 * 60 * 60 * 1000
) {
return;
}

const style = document.createElement('style');
style.innerHTML = `
@keyframes mirror-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes mirror-zoom-in {
from {
transform: scale(0.8);
}
to {
transform: scale(1);
}
}
.mirror-modal-mask {
position: fixed;
inset: 0;
height: '100vh';
width: '100vw';
background: rgba(0, 0, 0, 0.3);
z-index: 9999;
animation: mirror-fade-in 0.3s forwards;
}
.mirror-modal-dialog {
position: fixed;
inset: 0;
top: 120px;
margin-left: auto;
margin-right: auto;
width: 400px;
height: 120px;
display: flex;
align-items: center;
flex-direction: column;
border-radius: 8px;
border: 1px solid #eee;
background: #fff;
padding: 20px 24px;
box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);
animation: mirror-zoom-in 0.3s forwards;
}
.mirror-modal-title {
font-size: 16px;
font-weight: 500;
align-self: flex-start;
margin-bottom: 8px;
}
.mirror-modal-content {
font-size: 14px;
align-self: flex-start;
margin-bottom: 16px;
}
.mirror-modal-btns {
align-self: flex-end;
margin-top: auto;
display: flex;
align-items: center;
}
.mirror-modal-btn {
border-radius: 6px;
cursor: pointer;
height: 32px;
box-sizing: border-box;
font-size: 14px;
padding: 4px 16px;
display: inline-flex;
align-items: center;
text-decoration: none;
transition: all 0.2s;
}
.mirror-modal-confirm-btn {
background: #1677ff;
color: #fff;
}
.mirror-modal-confirm-btn:hover {
background: #4096ff;
}
.mirror-modal-confirm-btn:active {
background: #0958d9;
}
.mirror-modal-cancel-btn {
border: 1px solid #eee;
color: #000;
margin-right: 8px;
}
.mirror-modal-cancel-btn:hover {
border-color: #4096ff;
color: #4096ff
}
.mirror-modal-cancel-btn:active {
border-color: #0958d9;
color: #0958d9;
}
`;
document.head.append(style);

const modal = document.createElement('div');
modal.className = 'mirror-modal-mask';

const dialog = document.createElement('div');
dialog.className = 'mirror-modal-dialog';
modal.append(dialog);

const title = document.createElement('div');
title.className = 'mirror-modal-title';
title.innerText = '提示';
dialog.append(title);

const content = document.createElement('div');
content.className = 'mirror-modal-content';
content.innerText = '国内用户推荐访问国内镜像以获得极速体验~';
dialog.append(content);

const btnWrapper = document.createElement('div');
btnWrapper.className = 'mirror-modal-btns';
dialog.append(btnWrapper);

const cancelBtn = document.createElement('a');
cancelBtn.className = 'mirror-modal-cancel-btn mirror-modal-btn';
cancelBtn.innerText = '7 天内不再显示';
btnWrapper.append(cancelBtn);
cancelBtn.addEventListener('click', () => {
window.localStorage.setItem(ANTD_DOT_NOT_SHOW_MIRROR_MODAL, new Date().toISOString());
document.body.removeChild(modal);
document.head.removeChild(style);
document.body.style.overflow = '';
});

const confirmBtn = document.createElement('a');
confirmBtn.className = 'mirror-modal-confirm-btn mirror-modal-btn';
confirmBtn.href = window.location.href.replace(window.location.host, 'ant-design.antgroup.com');
confirmBtn.innerText = '🚀 立刻前往';
btnWrapper.append(confirmBtn);

document.body.append(modal);
document.body.style.overflow = 'hidden';
}
})();
21 changes: 21 additions & 0 deletions .dumi/theme/builtins/Previewer/Previewer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { IPreviewerProps } from 'dumi';
import { useTabMeta } from 'dumi';
import React from 'react';
import CodePreviewer from './CodePreviewer';
import DesignPreviewer from './DesignPreviewer';

export interface AntdPreviewerProps extends IPreviewerProps {
originDebug?: IPreviewerProps['debug'];
}

const Previewer: React.FC<AntdPreviewerProps> = (props) => {
const tab = useTabMeta();

if (tab?.frontmatter.title === 'Design') {
return <DesignPreviewer {...props} />;
}

return <CodePreviewer {...props} />;
};

export default Previewer;
25 changes: 7 additions & 18 deletions .dumi/theme/builtins/Previewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import React, { Suspense } from 'react';
import type { IPreviewerProps } from 'dumi';
import { useTabMeta } from 'dumi';
import React from 'react';
import CodePreviewer from './CodePreviewer';
import DesignPreviewer from './DesignPreviewer';

export interface AntdPreviewerProps extends IPreviewerProps {
originDebug?: IPreviewerProps['debug'];
}
const Previewer = React.lazy(() => import('./Previewer'));

const Previewer: React.FC<AntdPreviewerProps> = (props) => {
const tab = useTabMeta();

if (tab?.frontmatter.title === 'Design') {
return <DesignPreviewer {...props} />;
}

return <CodePreviewer {...props} />;
};

export default Previewer;
export default (props: IPreviewerProps) => (
<Suspense fallback={null}>
<Previewer {...props} />
</Suspense>
);
39 changes: 2 additions & 37 deletions .dumi/theme/slots/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import classNames from 'classnames';
import { useLocation, useSiteData } from 'dumi';
import DumiSearchBar from 'dumi/theme-default/slots/SearchBar';
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import { Col, Modal, Popover, Row, Select } from 'antd';
import { Col, Popover, Row, Select } from 'antd';
import useLocale from '../../../hooks/useLocale';
import DirectionIcon from '../../common/DirectionIcon';
import * as utils from '../../utils';
import { getThemeConfig, ping } from '../../utils';
import { getThemeConfig } from '../../utils';
import type { SiteContextProps } from '../SiteContext';
import SiteContext from '../SiteContext';
import Logo from './Logo';
Expand Down Expand Up @@ -109,16 +109,6 @@ const useStyle = createStyles(({ token, css }) => {
};
});

const SHOULD_OPEN_ANT_DESIGN_MIRROR_MODAL = 'ANT_DESIGN_DO_NOT_OPEN_MIRROR_MODAL';

function disableAntdMirrorModal() {
window.localStorage.setItem(SHOULD_OPEN_ANT_DESIGN_MIRROR_MODAL, 'true');
}

function shouldOpenAntdMirrorModal() {
return !window.localStorage.getItem(SHOULD_OPEN_ANT_DESIGN_MIRROR_MODAL);
}

interface HeaderState {
menuVisible: boolean;
windowWidth: number;
Expand Down Expand Up @@ -167,31 +157,6 @@ const Header: React.FC = () => {
useEffect(() => {
onWindowResize();
window.addEventListener('resize', onWindowResize);
pingTimer.current = ping((status) => {
if (status !== 'timeout' && status !== 'error') {
if (
// process.env.NODE_ENV === 'production' &&
window.location.host !== 'ant-design.antgroup.com' &&
shouldOpenAntdMirrorModal()
) {
Modal.confirm({
title: '提示',
content: '内网用户推荐访问国内镜像以获得极速体验~',
okText: '🚀 立刻前往',
cancelText: '不再弹出',
closable: true,
zIndex: 99999,
onOk() {
window.location.host = 'ant-design.antgroup.com';
disableAntdMirrorModal();
},
onCancel() {
disableAntdMirrorModal();
},
});
}
}
});
return () => {
window.removeEventListener('resize', onWindowResize);
if (pingTimer.current) {
Expand Down
23 changes: 15 additions & 8 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import rehypeAntd from './.dumi/rehypeAntd';
import remarkAntd from './.dumi/remarkAntd';
import { version } from './package.json';
import * as fs from 'fs-extra';

export default defineConfig({
conventionRoutes: {
Expand Down Expand Up @@ -44,56 +45,56 @@ export default defineConfig({
},
links: [
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff2',
type: 'font/woff2',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff',
type: 'font/woff',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.ttf',
type: 'font/ttf',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff2',
type: 'font/woff2',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff',
type: 'font/woff',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.ttf',
type: 'font/ttf',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/Gsw2PSKrftc1yNWMNlXgw.woff2',
type: 'font/woff2',
crossorigin: true,
},
{
rel: 'preload',
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/vtu73by4O2gEBcvBuLgeu.woff',
type: 'font/woff2',
Expand Down Expand Up @@ -158,4 +159,10 @@ export default defineConfig({
})();
`,
],
scripts: [
{
async: true,
content: fs.readFileSync(path.join(__dirname, '.dumi', 'mirror-modal.js')).toString(),
},
],
});
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ module.exports = {
'@typescript-eslint/no-shadow': [2, { ignoreTypeValueShadow: true }],
// https://github.com/typescript-eslint/typescript-eslint/issues/2528#issuecomment-689369395
'no-undef': 0,
'import/order': 0,
},
globals: {
gtag: true,
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"trailingComma": "all",
"printWidth": 100,
"proseWrap": "never",
"importOrder": ["^(react|react-dom)$", "^([a-z]|@[a-z])", ".*"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"overrides": [
{
"files": ".prettierrc",
Expand Down
Loading

0 comments on commit f34ff52

Please sign in to comment.