diff --git a/packages/client/src/components/document/reader/content.tsx b/packages/client/src/components/document/reader/public/content.tsx similarity index 66% rename from packages/client/src/components/document/reader/content.tsx rename to packages/client/src/components/document/reader/public/content.tsx index a08e101..0c40d55 100644 --- a/packages/client/src/components/document/reader/content.tsx +++ b/packages/client/src/components/document/reader/public/content.tsx @@ -4,12 +4,14 @@ import { Layout } from '@douyinfe/semi-ui'; import { IDocument } from '@think/domains'; import { DEFAULT_EXTENSION, DocumentWithTitle } from 'components/tiptap'; import { safeJSONParse } from 'helpers/json'; +import { CreateUser } from '../user'; interface IProps { document: IDocument; + createUserContainerSelector: string; } -export const DocumentContent: React.FC = ({ document }) => { +export const DocumentContent: React.FC = ({ document, createUserContainerSelector }) => { const c = safeJSONParse(document.content); let json = c.default || c; @@ -28,5 +30,10 @@ export const DocumentContent: React.FC = ({ document }) => { if (!json) return null; - return ; + return ( + <> + + window.document.querySelector(createUserContainerSelector)} /> + + ); }; diff --git a/packages/client/src/components/document/reader/public/index.tsx b/packages/client/src/components/document/reader/public/index.tsx index e44b40b..a0f8172 100644 --- a/packages/client/src/components/document/reader/public/index.tsx +++ b/packages/client/src/components/document/reader/public/index.tsx @@ -1,17 +1,6 @@ import React, { useMemo, useEffect } from 'react'; import cls from 'classnames'; -import { - Layout, - Nav, - Space, - Button, - Typography, - Skeleton, - Input, - Popover, - Modal, - BackTop, -} from '@douyinfe/semi-ui'; +import { Layout, Nav, Space, Button, Typography, Skeleton, Input, Popover, Modal, BackTop } from '@douyinfe/semi-ui'; import { IconArticle } from '@douyinfe/semi-icons'; import { Seo } from 'components/seo'; import { LogoImage, LogoText } from 'components/logo'; @@ -21,10 +10,10 @@ import { User } from 'components/user'; import { Theme } from 'components/theme'; import { useDocumentStyle } from 'hooks/useDocumentStyle'; import { useWindowSize } from 'hooks/useWindowSize'; +import { useLazyMount } from 'hooks/useMount'; import { usePublicDocument } from 'data/document'; import { DocumentSkeleton } from 'components/tiptap'; -import { DocumentContent } from '../content'; -import { CreateUser } from '../user'; +import { DocumentContent } from './content'; import styles from './index.module.scss'; const { Header, Content } = Layout; @@ -38,6 +27,7 @@ interface IProps { export const DocumentPublicReader: React.FC = ({ documentId, hideLogo = true }) => { if (!documentId) return null; + const mounted = useLazyMount(); const { data, loading, error, query } = usePublicDocument(documentId); const { width: windowWidth } = useWindowSize(); const { width, fontSize } = useDocumentStyle(); @@ -99,11 +89,7 @@ export const DocumentPublicReader: React.FC = ({ documentId, hideLogo = loading={loading} error={error} loadingContent={ - } - loading={true} - /> + } loading={true} /> } normalContent={() => ( @@ -131,21 +117,12 @@ export const DocumentPublicReader: React.FC = ({ documentId, hideLogo = style={{ fontSize }} id="js-share-document-editor-container" > - - - window.document.querySelector( - '#js-share-document-editor-container .ProseMirror .title' - ) - } + createUserContainerSelector="#js-share-document-editor-container .ProseMirror .title" /> - - document.querySelector('#js-share-document-editor-container').parentNode - } - /> + document.querySelector('#js-share-document-editor-container').parentNode} /> ); }} diff --git a/packages/client/src/components/document/reader/user.tsx b/packages/client/src/components/document/reader/user.tsx index 53432c2..0505769 100644 --- a/packages/client/src/components/document/reader/user.tsx +++ b/packages/client/src/components/document/reader/user.tsx @@ -43,6 +43,8 @@ export const CreateUser: React.FC<{ document: IDocument; container: () => HTMLEl const el = container && container(); + console.log(el); + if (!el) return content; return createPortal(content, el); };