From 85db72e0fe093bd3ddfa43a766264802c13e4baa Mon Sep 17 00:00:00 2001 From: fantasticit Date: Thu, 26 May 2022 00:57:05 +0800 Subject: [PATCH] client: improve render editor --- .../src/components/document/reader/index.tsx | 59 +++++++------ .../document/reader/public/index.tsx | 40 ++++----- .../collaboration/collaboration/index.tsx | 82 ++++++++++--------- .../collaboration/collaboration/type.ts | 5 ++ 4 files changed, 101 insertions(+), 85 deletions(-) diff --git a/packages/client/src/components/document/reader/index.tsx b/packages/client/src/components/document/reader/index.tsx index 12ffc66c..c34ba1dd 100644 --- a/packages/client/src/components/document/reader/index.tsx +++ b/packages/client/src/components/document/reader/index.tsx @@ -133,9 +133,9 @@ export const DocumentReader: React.FC = ({ documentId }) => {
- {document && } - {user && - (docAuthLoading ? ( + = ({ documentId }) => { >
- ) : ( - - ))} - {user && - (docAuthLoading ? null : ( -
- -
- ))} - {!isMobile && authority && authority.editable && container && ( - container} visibilityHeight={200}> - - - )} - - {container && container} />} + } + error={docAuthError} + normalContent={() => ( + <> + + + +
+ } + /> + {!isMobile && authority && authority.editable && container && ( + container} visibilityHeight={200}> + + + )} + + {container && ( + container} /> + )} + + )} + />
diff --git a/packages/client/src/components/document/reader/public/index.tsx b/packages/client/src/components/document/reader/public/index.tsx index 45570400..177eb0fc 100644 --- a/packages/client/src/components/document/reader/public/index.tsx +++ b/packages/client/src/components/document/reader/public/index.tsx @@ -100,25 +100,25 @@ export const DocumentPublicReader: React.FC = ({ documentId, hideLogo = return (
- {data && } - {mounted && } - - document.querySelector('#js-share-document-editor-container').parentNode} - /> -
+ id="js-share-document-editor-container" + className={cls(styles.editorWrap, editorWrapClassNames)} + style={{ fontSize }} + > + {data && } + {mounted && } + + document.querySelector('#js-share-document-editor-container').parentNode} + /> + ) }, [error, data, mounted, editorWrapClassNames, fontSize]) @@ -161,7 +161,7 @@ export const DocumentPublicReader: React.FC = ({ documentId, hideLogo = - {content} + {content} ); diff --git a/packages/client/src/tiptap/editor/collaboration/collaboration/index.tsx b/packages/client/src/tiptap/editor/collaboration/collaboration/index.tsx index e85c7573..7d05c92c 100644 --- a/packages/client/src/tiptap/editor/collaboration/collaboration/index.tsx +++ b/packages/client/src/tiptap/editor/collaboration/collaboration/index.tsx @@ -26,6 +26,7 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps, onTitleUpdate, user, menubar, + renderOnMount, renderInEditorPortal, onAwarenessUpdate, } = props; @@ -94,45 +95,48 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps, }, [hocuspocusProvider]); return ( -
- - -
- } - error={error} - errorContent={(error) => ( -
- - - {(error && error.message) || '未知错误'} - -
- )} - normalContent={() => ( - - )} - /> - + <> +
+ + +
+ } + error={error} + errorContent={(error) => ( +
+ + + {(error && error.message) || '未知错误'} + +
+ )} + normalContent={() => ( + + )} + /> + + {loading || !!error ? null : renderOnMount} + ); }); diff --git a/packages/client/src/tiptap/editor/collaboration/collaboration/type.ts b/packages/client/src/tiptap/editor/collaboration/collaboration/type.ts index 39a0e62e..d86a7085 100644 --- a/packages/client/src/tiptap/editor/collaboration/collaboration/type.ts +++ b/packages/client/src/tiptap/editor/collaboration/collaboration/type.ts @@ -43,6 +43,11 @@ export interface ICollaborationEditorProps { * @element 编辑器渲染父节点 */ renderInEditorPortal?: (element: HTMLElement) => React.ReactNode; + + /** + * 子节点,在编辑器渲染后才会加载 + */ + renderOnMount?: React.ReactNode; } export type ProviderStatus = 'connecting' | 'connected' | 'disconnected' | 'loadCacheSuccess';