client: improve render editor

pull/60/head
fantasticit 2022-05-26 00:57:05 +08:00
parent 12476d8c06
commit 85db72e0fe
4 changed files with 101 additions and 85 deletions

View File

@ -133,9 +133,9 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
<div ref={setContainer}>
<div className={cls(styles.editorWrap, editorWrapClassNames)} style={{ fontSize }}>
<div id="js-reader-container">
{document && <Seo title={document.title} />}
{user &&
(docAuthLoading ? (
<DataRender
loading={docAuthLoading}
loadingContent={
<div
style={{
minHeight: 240,
@ -147,7 +147,11 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
>
<Spin />
</div>
) : (
}
error={docAuthError}
normalContent={() => (
<>
<Seo title={document.title} />
<CollaborationEditor
editable={false}
user={user}
@ -155,21 +159,24 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
type="document"
renderInEditorPortal={renderAuthor}
onAwarenessUpdate={triggerJoinUser}
/>
))}
{user &&
(docAuthLoading ? null : (
renderOnMount={
<div className={styles.commentWrap}>
<CommentEditor documentId={documentId} />
</div>
))}
}
/>
{!isMobile && authority && authority.editable && container && (
<BackTop style={editBtnStyle} onClick={gotoEdit} target={() => container} visibilityHeight={200}>
<IconEdit />
</BackTop>
)}
<ImageViewer containerSelector="#js-reader-container" />
{container && <BackTop style={{ bottom: 65, right: isMobile ? 16 : 100 }} target={() => container} />}
{container && (
<BackTop style={{ bottom: 65, right: isMobile ? 16 : 100 }} target={() => container} />
)}
</>
)}
/>
</div>
</div>
</div>

View File

@ -26,6 +26,7 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps,
onTitleUpdate,
user,
menubar,
renderOnMount,
renderInEditorPortal,
onAwarenessUpdate,
} = props;
@ -94,6 +95,7 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps,
}, [hocuspocusProvider]);
return (
<>
<div className={styles.wrap}>
<DataRender
loading={loading}
@ -133,6 +135,8 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps,
)}
/>
</div>
{loading || !!error ? null : renderOnMount}
</>
);
});

View File

@ -43,6 +43,11 @@ export interface ICollaborationEditorProps {
* @element
*/
renderInEditorPortal?: (element: HTMLElement) => React.ReactNode;
/**
*
*/
renderOnMount?: React.ReactNode;
}
export type ProviderStatus = 'connecting' | 'connected' | 'disconnected' | 'loadCacheSuccess';