feature: 1. add TOC & adjust get eidtor style;
This commit is contained in:
@@ -38,14 +38,8 @@ export function Page(props: PageProps) {
|
|||||||
const { showSpaceSidebar, fixedDisplay, setSpaceSidebarVisible } =
|
const { showSpaceSidebar, fixedDisplay, setSpaceSidebarVisible } =
|
||||||
useShowSpaceSidebar();
|
useShowSpaceSidebar();
|
||||||
const dailyNotesFlag = useFlag('BooleanDailyNotes', false);
|
const dailyNotesFlag = useFlag('BooleanDailyNotes', false);
|
||||||
const editorRef = useRef(null);
|
|
||||||
|
|
||||||
const onTabChange = v => setActiveTab(v);
|
const onTabChange = v => setActiveTab(v);
|
||||||
|
|
||||||
const getEditor = editor => {
|
|
||||||
editorRef.current = editor;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LigoApp>
|
<LigoApp>
|
||||||
<LigoLeftContainer style={{ width: fixedDisplay ? '300px' : 0 }}>
|
<LigoLeftContainer style={{ width: fixedDisplay ? '300px' : 0 }}>
|
||||||
@@ -92,16 +86,12 @@ export function Page(props: PageProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{activeTab === TabMap.get(TAB_TITLE.TOC).value && (
|
{activeTab === TabMap.get(TAB_TITLE.TOC).value && (
|
||||||
<TOC editor={editorRef.current}>TOC</TOC>
|
<TOC />
|
||||||
)}
|
)}
|
||||||
</WorkspaceSidebarContent>
|
</WorkspaceSidebarContent>
|
||||||
</WorkspaceSidebar>
|
</WorkspaceSidebar>
|
||||||
</LigoLeftContainer>
|
</LigoLeftContainer>
|
||||||
<EditorContainer
|
<EditorContainer workspace={props.workspace} pageId={page_id} />
|
||||||
workspace={props.workspace}
|
|
||||||
pageId={page_id}
|
|
||||||
getEditor={getEditor}
|
|
||||||
/>
|
|
||||||
</LigoApp>
|
</LigoApp>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -109,11 +99,9 @@ export function Page(props: PageProps) {
|
|||||||
const EditorContainer = ({
|
const EditorContainer = ({
|
||||||
pageId,
|
pageId,
|
||||||
workspace,
|
workspace,
|
||||||
getEditor,
|
|
||||||
}: {
|
}: {
|
||||||
pageId: string;
|
pageId: string;
|
||||||
workspace: string;
|
workspace: string;
|
||||||
getEditor: (editor: BlockEditor) => void;
|
|
||||||
}) => {
|
}) => {
|
||||||
const [lockScroll, setLockScroll] = useState(false);
|
const [lockScroll, setLockScroll] = useState(false);
|
||||||
const [scrollContainer, setScrollContainer] = useState<HTMLElement>();
|
const [scrollContainer, setScrollContainer] = useState<HTMLElement>();
|
||||||
@@ -131,7 +119,6 @@ const EditorContainer = ({
|
|||||||
setPageClientWidth(e[0].contentRect.width);
|
setPageClientWidth(e[0].contentRect.width);
|
||||||
});
|
});
|
||||||
|
|
||||||
getEditor(editorRef.current);
|
|
||||||
obv.observe(scrollContainer);
|
obv.observe(scrollContainer);
|
||||||
return () => obv.disconnect();
|
return () => obv.disconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
import type { Virgo } from '@toeverything/components/editor-core';
|
||||||
import { styled } from '@toeverything/components/ui';
|
import { styled } from '@toeverything/components/ui';
|
||||||
|
import { useCurrentEditors } from '@toeverything/datasource/state';
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
useCallback,
|
useCallback,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
@@ -14,7 +17,7 @@ import {
|
|||||||
getContentByAsyncBlocks,
|
getContentByAsyncBlocks,
|
||||||
getPageTOC,
|
getPageTOC,
|
||||||
} from './toc-util';
|
} from './toc-util';
|
||||||
import type { ListenerMap, TOCProps, TOCType } from './types';
|
import type { ListenerMap, TOCType } from './types';
|
||||||
|
|
||||||
const StyledTOCItem = styled('a')<{ type?: string; isActive?: boolean }>(
|
const StyledTOCItem = styled('a')<{ type?: string; isActive?: boolean }>(
|
||||||
({ type, isActive }) => {
|
({ type, isActive }) => {
|
||||||
@@ -112,8 +115,7 @@ const renderTOCContent = tocDataSource => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TOC = (props: TOCProps) => {
|
export const TOC = () => {
|
||||||
const { editor } = props;
|
|
||||||
const { page_id } = useParams();
|
const { page_id } = useParams();
|
||||||
const [tocDataSource, setTocDataSource] = useState<TOCType[]>([]);
|
const [tocDataSource, setTocDataSource] = useState<TOCType[]>([]);
|
||||||
const [activeBlockId, setActiveBlockId] = useState('');
|
const [activeBlockId, setActiveBlockId] = useState('');
|
||||||
@@ -121,6 +123,11 @@ export const TOC = (props: TOCProps) => {
|
|||||||
/* store page/block unmount-listener */
|
/* store page/block unmount-listener */
|
||||||
const listenerMapRef = useRef<ListenerMap>(new Map());
|
const listenerMapRef = useRef<ListenerMap>(new Map());
|
||||||
|
|
||||||
|
const { currentEditors } = useCurrentEditors();
|
||||||
|
const editor = useMemo(() => {
|
||||||
|
return currentEditors[page_id] as Virgo;
|
||||||
|
}, [currentEditors, page_id]);
|
||||||
|
|
||||||
const updateTocDataSource = useCallback(async () => {
|
const updateTocDataSource = useCallback(async () => {
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import type { BlockEditor } from '@toeverything/components/editor-core';
|
|
||||||
import type { ReactNode } from 'react';
|
|
||||||
|
|
||||||
export type TOCType = {
|
export type TOCType = {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
@@ -8,8 +5,3 @@ export type TOCType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ListenerMap = Map<string, () => void>;
|
export type ListenerMap = Map<string, () => void>;
|
||||||
|
|
||||||
export interface TOCProps {
|
|
||||||
children: ReactNode;
|
|
||||||
editor?: BlockEditor;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
* 6. Dependencies between plugins are not supported for the time being
|
* 6. Dependencies between plugins are not supported for the time being
|
||||||
*/
|
*/
|
||||||
import type { PatchNode } from '@toeverything/components/ui';
|
import type { PatchNode } from '@toeverything/components/ui';
|
||||||
import type { BlockFlavors } from '@toeverything/datasource/db-service';
|
import type {
|
||||||
|
BlockFlavors,
|
||||||
|
ReturnEditorBlock,
|
||||||
|
} from '@toeverything/datasource/db-service';
|
||||||
import type { IdList, SelectionInfo, SelectionManager } from './selection';
|
import type { IdList, SelectionInfo, SelectionManager } from './selection';
|
||||||
|
|
||||||
import { Point } from '@toeverything/utils';
|
import { Point } from '@toeverything/utils';
|
||||||
@@ -67,6 +70,8 @@ export interface Virgo {
|
|||||||
) => Promise<AsyncBlock>;
|
) => Promise<AsyncBlock>;
|
||||||
getRootBlockId: () => string;
|
getRootBlockId: () => string;
|
||||||
getBlockById(blockId: string): Promise<AsyncBlock | null>;
|
getBlockById(blockId: string): Promise<AsyncBlock | null>;
|
||||||
|
getBlockByIds(blockId: string[]): Promise<(AsyncBlock | null)[]>;
|
||||||
|
queryByPageId(pageId: string): Promise<(ReturnEditorBlock | null)[]>;
|
||||||
setHotKeysScope(scope?: string): void;
|
setHotKeysScope(scope?: string): void;
|
||||||
getBlockList: () => Promise<AsyncBlock[]>;
|
getBlockList: () => Promise<AsyncBlock[]>;
|
||||||
getBlockListByLevelOrder: () => Promise<AsyncBlock[]>;
|
getBlockListByLevelOrder: () => Promise<AsyncBlock[]>;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { atom, useAtom } from 'jotai';
|
import { atom, useAtom } from 'jotai';
|
||||||
import { useEffect } from 'react';
|
|
||||||
import { useLocation, useParams } from 'react-router-dom';
|
import { useLocation, useParams } from 'react-router-dom';
|
||||||
// import { Virgo } from '@toeverything/components/editor-core';
|
// import { Virgo } from '@toeverything/components/editor-core';
|
||||||
|
|
||||||
@@ -14,12 +13,13 @@ export const useCurrentEditors = () => {
|
|||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const [currentEditors, setCurrentEditors] = useAtom(_currentEditors);
|
const [currentEditors, setCurrentEditors] = useAtom(_currentEditors);
|
||||||
|
|
||||||
useEffect(() => {
|
/* not useful: 2022.8.25 */
|
||||||
if (!workspaceId || !pageId) return;
|
// useEffect(() => {
|
||||||
if (pathname.split('/').length >= 3) {
|
// if (!workspaceId || !pageId) return;
|
||||||
setCurrentEditors({});
|
// if (pathname.split('/').length >= 3) {
|
||||||
}
|
// setCurrentEditors({});
|
||||||
}, [pageId, pathname, setCurrentEditors, workspaceId]);
|
// }
|
||||||
|
// }, [pageId, pathname, setCurrentEditors, workspaceId]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentEditors,
|
currentEditors,
|
||||||
|
|||||||
Reference in New Issue
Block a user