2022-11-30 11:05:41 +08:00
|
|
|
import classNames from 'classnames';
|
2023-12-17 15:33:54 +08:00
|
|
|
import { FormattedMessage, useRouteMeta } from 'dumi';
|
2023-01-22 01:30:01 +08:00
|
|
|
import type { ReactNode } from 'react';
|
2023-12-17 15:33:54 +08:00
|
|
|
import React, { Suspense, useContext, useLayoutEffect, useMemo } from 'react';
|
|
|
|
import { Col, Space, Typography, Skeleton } from 'antd';
|
|
|
|
import { createStyles } from 'antd-style';
|
2023-05-24 14:27:03 +08:00
|
|
|
import useLayoutState from '../../../hooks/useLayoutState';
|
2022-11-09 12:28:04 +08:00
|
|
|
import useLocation from '../../../hooks/useLocation';
|
2022-11-30 11:05:41 +08:00
|
|
|
import type { DemoContextProps } from '../DemoContext';
|
|
|
|
import DemoContext from '../DemoContext';
|
2022-11-15 10:09:24 +08:00
|
|
|
import SiteContext from '../SiteContext';
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2023-12-17 15:33:54 +08:00
|
|
|
const Contributors = React.lazy(() => import('./Contributors'));
|
|
|
|
const ColumnCard = React.lazy(() => import('./ColumnCard'));
|
|
|
|
const DocAnchor = React.lazy(() => import('./DocAnchor'));
|
|
|
|
const DocMeta = React.lazy(() => import('./DocMeta'));
|
|
|
|
const Footer = React.lazy(() => import('../Footer'));
|
|
|
|
const PrevAndNext = React.lazy(() => import('../../common/PrevAndNext'));
|
|
|
|
const ComponentChangelog = React.lazy(() => import('../../common/ComponentChangelog'));
|
|
|
|
const EditButton = React.lazy(() => import('../../common/EditButton'));
|
|
|
|
|
|
|
|
const useStyle = createStyles(({ token, css }) => ({
|
|
|
|
articleWrapper: css`
|
2022-11-15 10:09:24 +08:00
|
|
|
padding: 0 170px 32px 64px;
|
|
|
|
|
|
|
|
&.rtl {
|
|
|
|
padding: 0 64px 144px 170px;
|
|
|
|
}
|
|
|
|
|
|
|
|
@media only screen and (max-width: ${token.screenLG}px) {
|
2022-11-24 20:11:50 +08:00
|
|
|
&,
|
|
|
|
&.rtl {
|
2023-01-22 01:30:01 +08:00
|
|
|
padding: 0 48px;
|
2022-11-15 10:09:24 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-09 12:28:04 +08:00
|
|
|
`,
|
2023-12-17 15:33:54 +08:00
|
|
|
}));
|
2023-03-16 11:27:25 +08:00
|
|
|
|
2022-11-24 20:11:50 +08:00
|
|
|
const Content: React.FC<{ children: ReactNode }> = ({ children }) => {
|
2022-11-09 12:28:04 +08:00
|
|
|
const meta = useRouteMeta();
|
2022-12-01 10:43:52 +08:00
|
|
|
const { pathname, hash } = useLocation();
|
2023-12-17 15:33:54 +08:00
|
|
|
const { direction } = useContext(SiteContext);
|
2023-07-20 19:27:33 +08:00
|
|
|
const { styles } = useStyle();
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2023-04-13 18:13:13 +08:00
|
|
|
const [showDebug, setShowDebug] = useLayoutState(false);
|
2022-11-17 01:22:09 +08:00
|
|
|
const debugDemos = useMemo(
|
|
|
|
() => meta.toc?.filter((item) => item._debug_demo).map((item) => item.id) || [],
|
|
|
|
[meta],
|
|
|
|
);
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2022-12-01 10:43:52 +08:00
|
|
|
const isDebugDemo = debugDemos.includes(hash.slice(1));
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
useLayoutEffect(() => {
|
2022-12-01 10:43:52 +08:00
|
|
|
setShowDebug(process.env.NODE_ENV === 'development' || isDebugDemo);
|
2022-11-09 12:28:04 +08:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const contextValue = useMemo<DemoContextProps>(
|
2022-11-17 01:22:09 +08:00
|
|
|
() => ({ showDebug, setShowDebug }),
|
2022-11-09 12:28:04 +08:00
|
|
|
[showDebug, debugDemos],
|
|
|
|
);
|
|
|
|
|
2022-11-15 10:09:24 +08:00
|
|
|
const isRTL = direction === 'rtl';
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
return (
|
|
|
|
<DemoContext.Provider value={contextValue}>
|
|
|
|
<Col xxl={20} xl={19} lg={18} md={18} sm={24} xs={24}>
|
2023-12-17 15:33:54 +08:00
|
|
|
<Suspense fallback={<Skeleton.Input active size="small" />}>
|
|
|
|
<DocAnchor showDebug={showDebug} debugDemos={debugDemos} />
|
|
|
|
</Suspense>
|
2023-07-20 19:27:33 +08:00
|
|
|
<article className={classNames(styles.articleWrapper, { rtl: isRTL })}>
|
2023-02-08 22:54:21 +08:00
|
|
|
{meta.frontmatter?.title ? (
|
2023-08-03 10:58:38 +08:00
|
|
|
<Typography.Title style={{ fontSize: 30, position: 'relative' }}>
|
|
|
|
<Space size="small">
|
|
|
|
{meta.frontmatter?.title}
|
|
|
|
{meta.frontmatter?.subtitle}
|
|
|
|
|
|
|
|
{!pathname.startsWith('/components/overview') && (
|
2023-12-17 15:33:54 +08:00
|
|
|
<Suspense fallback={null}>
|
|
|
|
<EditButton
|
|
|
|
title={<FormattedMessage id="app.content.edit-page" />}
|
|
|
|
filename={meta.frontmatter.filename}
|
|
|
|
/>
|
|
|
|
</Suspense>
|
2023-08-03 10:58:38 +08:00
|
|
|
)}
|
|
|
|
</Space>
|
2023-12-17 15:33:54 +08:00
|
|
|
{pathname.startsWith('/components/') && (
|
|
|
|
<Suspense fallback={null}>
|
|
|
|
<ComponentChangelog pathname={pathname} />
|
|
|
|
</Suspense>
|
|
|
|
)}
|
2023-02-01 21:55:20 +08:00
|
|
|
</Typography.Title>
|
|
|
|
) : null}
|
2023-12-17 15:33:54 +08:00
|
|
|
<Suspense fallback={<Skeleton.Input active size="small" />}>
|
|
|
|
<DocMeta />
|
|
|
|
</Suspense>
|
2023-03-14 20:34:36 +08:00
|
|
|
{!meta.frontmatter.__autoDescription && meta.frontmatter.description}
|
2023-07-24 19:56:17 +08:00
|
|
|
<div style={{ minHeight: 'calc(100vh - 64px)' }}>{children}</div>
|
2023-12-17 15:33:54 +08:00
|
|
|
<Suspense fallback={<Skeleton.Input active size="small" />}>
|
2023-06-22 21:11:12 +08:00
|
|
|
<ColumnCard
|
|
|
|
zhihuLink={meta.frontmatter.zhihu_url}
|
|
|
|
yuqueLink={meta.frontmatter.yuque_url}
|
2023-06-25 12:27:03 +08:00
|
|
|
juejinLink={meta.frontmatter.juejin_url}
|
2023-06-22 21:11:12 +08:00
|
|
|
/>
|
2023-12-17 15:33:54 +08:00
|
|
|
</Suspense>
|
|
|
|
<Suspense fallback={<Skeleton.Input active size="small" />}>
|
|
|
|
<Contributors filename={meta.frontmatter.filename} />
|
|
|
|
</Suspense>
|
2022-11-15 10:09:24 +08:00
|
|
|
</article>
|
2023-12-17 15:33:54 +08:00
|
|
|
<Suspense fallback={<Skeleton.Input active size="small" />}>
|
|
|
|
<PrevAndNext rtl={isRTL} />
|
|
|
|
</Suspense>
|
|
|
|
<Suspense fallback={null}>
|
|
|
|
<Footer />
|
|
|
|
</Suspense>
|
2022-11-09 12:28:04 +08:00
|
|
|
</Col>
|
|
|
|
</DemoContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Content;
|