diff --git a/README.md b/README.md index f06510f6..346523e2 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ CREATE DATABASE `think` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_c #### 可选:Redis +如果需要文档版本服务,请在 `@think/config` 的 `yaml` 配置中进行 `db.redis` 的配置。 + ``` docker pull redis:latest docker run --name think-redis -p 6379:6379 -d redis --appendonly yes --requirepass "root" diff --git a/packages/client/src/components/document/editor/editor.tsx b/packages/client/src/components/document/editor/editor.tsx index 2b7c8035..c6e86462 100644 --- a/packages/client/src/components/document/editor/editor.tsx +++ b/packages/client/src/components/document/editor/editor.tsx @@ -21,7 +21,7 @@ import { DataRender } from 'components/data-render'; import { joinUser } from 'components/document/collaboration'; import { Banner } from 'components/banner'; import { debounce } from 'helpers/debounce'; -import { changeTitle } from './index'; +import { em, changeTitle, USE_DATA_VERSION } from './index'; import styles from './index.module.scss'; interface IProps { @@ -64,7 +64,7 @@ export const Editor: React.FC = ({ user, documentId, authority, classNam const title = transaction.doc.content.firstChild.content.firstChild.textContent; changeTitle(title); } catch (e) {} - }, 200), + }, 50), }); const [loading, toggleLoading] = useToggle(true); @@ -89,6 +89,16 @@ export const Editor: React.FC = ({ user, documentId, authority, classNam }; }, []); + useEffect(() => { + if (!editor) return; + const handler = (data) => editor.commands.setContent(data); + em.on(USE_DATA_VERSION, handler); + + return () => { + em.off(USE_DATA_VERSION, handler); + }; + }, [editor]); + return ( { em.emit(TITLE_CHANGE_EVENT, title); }; +const useVersion = (data) => { + em.emit(USE_DATA_VERSION, data); +}; + interface IProps { documentId: string; } @@ -90,7 +95,7 @@ export const DocumentEditor: React.FC = ({ documentId }) => { )} - + }> + {onSelect && ( + + )} + + + } + footer={null} > - - -