mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 04:21:40 +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 [editor, setEditor] = useState<EditorContainer>();
|
||||||
const [mode, setMode] = useState<EditorContainer['mode']>('page');
|
const [mode, setMode] = useState<EditorContainer['mode']>('page');
|
||||||
|
|
||||||
const editorHandlers = useEditorHandler(workspace);
|
const editorHandlers = useEditorHandler({ workspace, editor });
|
||||||
const onPropsUpdated = usePropsUpdated(editor);
|
const onPropsUpdated = usePropsUpdated(editor);
|
||||||
const onHistoryUpdated = useHistoryUpdated(page);
|
const onHistoryUpdated = useHistoryUpdated(page);
|
||||||
|
|
||||||
@@ -56,8 +56,9 @@ export const EditorProvider = ({
|
|||||||
}, [workspace, onHistoryUpdated]);
|
}, [workspace, onHistoryUpdated]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const event = new CustomEvent('affine.switch-mode', { detail: mode });
|
// FIXME
|
||||||
window.dispatchEvent(event);
|
const editorContainer = document.querySelector('editor-container');
|
||||||
|
editorContainer?.setAttribute('mode', mode as string);
|
||||||
}, [mode]);
|
}, [mode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -3,8 +3,15 @@ import { createPage, initialPage, generateDefaultPageId } from '../utils';
|
|||||||
import { Workspace } from '@blocksuite/store';
|
import { Workspace } from '@blocksuite/store';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { EditorHandlers, PageMeta } from '../interface';
|
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();
|
const router = useRouter();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -56,6 +63,10 @@ export const useEditorHandler = (workspace?: Workspace): EditorHandlers => {
|
|||||||
search: (query: QueryContent) => {
|
search: (query: QueryContent) => {
|
||||||
return workspace!.search(query);
|
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;
|
toggleFavoritePage: (pageId: string) => void;
|
||||||
permanentlyDeletePage: (pageId: string) => void;
|
permanentlyDeletePage: (pageId: string) => void;
|
||||||
search: (query: QueryContent) => Map<string, string | undefined>;
|
search: (query: QueryContent) => Map<string, string | undefined>;
|
||||||
|
changeEditorMode: (pageId: string) => void;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user