mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 17:46:18 +08:00
fix: can not change editor mode
This commit is contained in:
@@ -41,7 +41,7 @@ export const EditorProvider = ({
|
||||
const [editor, setEditor] = useState<EditorContainer>();
|
||||
const [mode, setMode] = useState<EditorContainer['mode']>('page');
|
||||
|
||||
const editorHandlers = useEditorHandler(workspace);
|
||||
const editorHandlers = useEditorHandler({ workspace, editor });
|
||||
const onPropsUpdated = usePropsUpdated(editor);
|
||||
const onHistoryUpdated = useHistoryUpdated(page);
|
||||
|
||||
@@ -56,8 +56,9 @@ export const EditorProvider = ({
|
||||
}, [workspace, onHistoryUpdated]);
|
||||
|
||||
useEffect(() => {
|
||||
const event = new CustomEvent('affine.switch-mode', { detail: mode });
|
||||
window.dispatchEvent(event);
|
||||
// FIXME
|
||||
const editorContainer = document.querySelector('editor-container');
|
||||
editorContainer?.setAttribute('mode', mode as string);
|
||||
}, [mode]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -3,8 +3,15 @@ import { createPage, initialPage, generateDefaultPageId } from '../utils';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { useRouter } from 'next/router';
|
||||
import { EditorHandlers, PageMeta } from '../interface';
|
||||
import { EditorContainer } from '@blocksuite/editor';
|
||||
|
||||
export const useEditorHandler = (workspace?: Workspace): EditorHandlers => {
|
||||
export const useEditorHandler = ({
|
||||
editor,
|
||||
workspace,
|
||||
}: {
|
||||
workspace?: Workspace;
|
||||
editor?: EditorContainer;
|
||||
}): EditorHandlers => {
|
||||
const router = useRouter();
|
||||
|
||||
return {
|
||||
@@ -56,6 +63,10 @@ export const useEditorHandler = (workspace?: Workspace): EditorHandlers => {
|
||||
search: (query: QueryContent) => {
|
||||
return workspace!.search(query);
|
||||
},
|
||||
changeEditorMode: (pageId: string) => {
|
||||
editor!.mode = editor!.mode === 'page' ? 'edgeless' : 'page';
|
||||
workspace?.setPageMeta(pageId, { mode: editor!.mode });
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -37,4 +37,5 @@ export type EditorHandlers = {
|
||||
toggleFavoritePage: (pageId: string) => void;
|
||||
permanentlyDeletePage: (pageId: string) => void;
|
||||
search: (query: QueryContent) => Map<string, string | undefined>;
|
||||
changeEditorMode: (pageId: string) => void;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user