Skip to content

Commit

Permalink
chore: auto merge branches (ant-design#44052)
Browse files Browse the repository at this point in the history
chore: merge master into feature
  • Loading branch information
github-actions[bot] authored Aug 6, 2023
2 parents a4212f4 + fee14ec commit 1f03d37
Show file tree
Hide file tree
Showing 136 changed files with 4,842 additions and 2,592 deletions.
33 changes: 19 additions & 14 deletions .dumi/hooks/use.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
export default function use(promise: any) {
if (promise.status === 'fulfilled') {
return promise.value;
export default function use<T>(promise: PromiseLike<T>): T {
const internal: PromiseLike<T> & {
status?: 'pending' | 'fulfilled' | 'rejected';
value?: T;
reason?: any;
} = promise;
if (internal.status === 'fulfilled') {
return internal.value;
}
if (promise.status === 'rejected') {
throw promise.reason;
} else if (promise.status === 'pending') {
throw promise;
if (internal.status === 'rejected') {
throw internal.reason;
} else if (internal.status === 'pending') {
throw internal;
} else {
promise.status = 'pending';
promise.then(
internal.status = 'pending';
internal.then(
(result) => {
promise.status = 'fulfilled';
promise.value = result;
internal.status = 'fulfilled';
internal.value = result;
},
(reason) => {
promise.status = 'rejected';
promise.reason = reason;
internal.status = 'rejected';
internal.reason = reason;
},
);
throw promise;
throw internal;
}
}
21 changes: 21 additions & 0 deletions .dumi/hooks/useFetch/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default class FetchCache {
private cache: Map<string, PromiseLike<any>> = new Map();

get(key: string) {
return this.cache.get(key);
}

set(key: string, value: PromiseLike<any>) {
this.cache.set(key, value);
}

promise<T>(key: string, promiseFn: () => PromiseLike<T>): PromiseLike<T> {
const cached = this.get(key);
if (cached) {
return cached;
}
const promise = promiseFn();
this.set(key, promise);
return promise;
}
}
20 changes: 20 additions & 0 deletions .dumi/hooks/useFetch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fetch from 'cross-fetch';
import use from '../use';
import FetchCache from './cache';

const cache = new FetchCache();

const useFetch = <T>(options: string | { request: () => PromiseLike<T>; key: string }) => {
let request;
let key;
if (typeof options === 'string') {
request = () => fetch(options).then((res) => res.json());
key = options;
} else {
request = options.request;
key = options.key;
}
return use(cache.promise<T>(key, request));
};

export default useFetch;
41 changes: 28 additions & 13 deletions .dumi/hooks/useMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useFullSidebarData, useSidebarData } from 'dumi';
import React, { useMemo } from 'react';
import type { MenuProps } from 'antd';
import { Tag, theme } from 'antd';
import { Tag, version } from 'antd';
import Link from '../theme/common/Link';
import useLocation from './useLocation';

Expand All @@ -15,7 +15,6 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
const { pathname, search } = useLocation();
const sidebarData = useSidebarData();
const { before, after } = options;
const { token } = theme.useToken();

const menuItems = useMemo<MenuProps['items']>(() => {
const sidebarItems = [...(sidebarData ?? [])];
Expand All @@ -32,18 +31,31 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
key.startsWith('/changelog'),
)?.[1];
if (changelogData) {
sidebarItems.push(...changelogData);
sidebarItems.splice(1, 0, changelogData[0]);
}
}
if (pathname.startsWith('/changelog')) {
const reactDocData = Object.entries(fullData).find(([key]) =>
key.startsWith('/docs/react'),
)?.[1];
if (reactDocData) {
sidebarItems.unshift(...reactDocData);
sidebarItems.unshift(reactDocData[0]);
sidebarItems.push(...reactDocData.slice(1));
}
}

const getItemTag = (tag: string, show = true) =>
tag &&
show && (
<Tag
color={tag === 'New' ? 'success' : 'orange'}
bordered={false}
style={{ marginInlineStart: 'auto', marginInlineEnd: 0, marginTop: -2 }}
>
{tag.replace('VERSION', version)}
</Tag>
);

return (
sidebarItems?.reduce<Exclude<MenuProps['items'], undefined>>((result, group) => {
if (group?.title) {
Expand All @@ -52,7 +64,7 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
const childrenGroup = group.children.reduce<
Record<string, ReturnType<typeof useSidebarData>[number]['children']>
>((childrenResult, child) => {
const type = (child.frontmatter as any).type ?? 'default';
const type = child.frontmatter?.type ?? 'default';
if (!childrenResult[type]) {
childrenResult[type] = [];
}
Expand Down Expand Up @@ -103,17 +115,16 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
key: group?.title,
children: group.children?.map((item) => ({
label: (
<Link to={`${item.link}${search}`}>
<Link
to={`${item.link}${search}`}
style={{ display: 'flex', alignItems: 'center' }}
>
{before}
<span key="english">{item?.title}</span>
<span className="chinese" key="chinese">
{(item.frontmatter as any).subtitle}
{item.frontmatter?.subtitle}
</span>
{(item.frontmatter as any).tag && (
<Tag color="warning" style={{ marginInlineStart: token.marginXS }}>
{(item.frontmatter as any).tag}
</Tag>
)}
{getItemTag(item.frontmatter?.tag, !before && !after)}
{after}
</Link>
),
Expand All @@ -131,9 +142,13 @@ const useMenu = (options: UseMenuOptions = {}): [MenuProps['items'], string] =>
result.push(
...list.map((item) => ({
label: (
<Link to={`${item.link}${search}`}>
<Link
to={`${item.link}${search}`}
style={{ display: 'flex', alignItems: 'center' }}
>
{before}
{item?.title}
{getItemTag((item.frontmatter as any).tag, !before && !after)}
{after}
</Link>
),
Expand Down
11 changes: 3 additions & 8 deletions .dumi/pages/index/components/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { css } from 'antd-style';
import fetch from 'cross-fetch';
import use from '../../../hooks/use';
import useFetch from '../../../hooks/useFetch';

export interface Author {
avatar: string;
Expand Down Expand Up @@ -81,12 +80,8 @@ export function preLoad(list: string[]) {
}
}

const promise = fetch(`https://render.alipay.com/p/h5data/antd4-config_website-h5data.json`).then(
(res) => res.json(),
);

export function useSiteData(): [Partial<SiteData>, boolean] {
return use(promise);
export function useSiteData(): Partial<SiteData> {
return useFetch('https://render.alipay.com/p/h5data/antd4-config_website-h5data.json');
}

export const getCarouselStyle = () => ({
Expand Down
Empty file added .dumi/preset/.gitkeep
Empty file.
5 changes: 4 additions & 1 deletion .dumi/rehypeAntd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ function rehypeAntd(): UnifiedTransformer<HastRoot> {
node.tagName = 'VideoPlayer';
} else if (node.tagName === 'SourceCode') {
const { lang } = node.properties;
if (lang === 'sandpack') {
if (typeof lang === 'string' && lang.startsWith('sandpack')) {
parent!.children.splice(i!, 1, {
type: 'element',
tagName: 'Sandpack',
properties: {
dark: lang === 'sandpackdark',
},
children: [
{
type: 'text',
Expand Down
29 changes: 18 additions & 11 deletions .dumi/theme/builtins/ResourceArticles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ const useStyle = createStyles(({ token, css }) => {
padding: 0;
font-size: 14px;
list-style: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
${antCls}-avatar > img {
max-width: unset;
}
Expand Down Expand Up @@ -95,7 +97,7 @@ const ArticleList: React.FC<ArticleListProps> = ({ name, data = [], authors = []
);
};

const Articles = () => {
const Articles: React.FC = () => {
const [, lang] = useLocale();
const isZhCN = lang === 'cn';
const { articles = { cn: [], en: [] }, authors = [] } = useSiteData();
Expand All @@ -113,10 +115,16 @@ const Articles = () => {

const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a));

return yearList.length ? (
<Tabs>
{yearList.map((year) => (
<Tabs.TabPane tab={`${year}${isZhCN ? ' 年' : ''}`} key={year}>
if (yearList.length === 0) {
return null;
}

return (
<Tabs
items={yearList.map((year) => ({
key: year,
label: `${year}${isZhCN ? ' 年' : ''}`,
children: (
<table>
<tbody>
<tr>
Expand All @@ -133,15 +141,14 @@ const Articles = () => {
</tr>
</tbody>
</table>
</Tabs.TabPane>
))}
</Tabs>
) : null;
),
}))}
/>
);
};

export default () => {
const { styles } = useStyle();

return (
<div id="articles" className={styles.articles}>
<Suspense fallback={<Skeleton active />}>
Expand Down
15 changes: 13 additions & 2 deletions .dumi/theme/builtins/Sandpack/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ const setup = {

const options = {
activeFile: 'app.tsx' as never,
visibleFiles: ['index.tsx', 'app.tsx', 'package.json'] as any,
visibleFiles: ['index.tsx', 'app.tsx', 'package.json', 'index.css'] as any,
showLineNumbers: true,
editorHeight: '500px',
autorun: false,
};

const indexContent = `import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './app';
import './index.css';
const root = createRoot(document.getElementById("root"));
root.render(<App />);
Expand Down Expand Up @@ -62,7 +64,7 @@ const SandpackFallback = () => {
);
};

const Sandpack = ({ children }: { children: ReactNode }) => {
const Sandpack = ({ children, dark }: { children: ReactNode; dark: boolean }) => {
const [searchParams] = useSearchParams();

useServerInsertedHTML(() => (
Expand All @@ -81,6 +83,15 @@ const Sandpack = ({ children }: { children: ReactNode }) => {
options={options}
files={{
'index.tsx': indexContent,
'index.css': `html, body {
padding: 0;
margin: 0;
background: ${dark ? '#000' : '#fff'};
}
#root {
padding: 24px;
}`,
'app.tsx': children,
}}
/>
Expand Down
Loading

0 comments on commit 1f03d37

Please sign in to comment.