mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-06 08:50:50 +08:00
feat(mobile): mobile toc menu (#9582)
Close [BS-1787](https://linear.app/affine-design/issue/BS-1787/toc-移动端适配)
This commit is contained in:
@@ -11,6 +11,7 @@ import type { ReactNode } from 'react';
|
||||
export interface MenuProps {
|
||||
children: ReactNode;
|
||||
items: ReactNode;
|
||||
title?: string;
|
||||
portalOptions?: Omit<DropdownMenuPortalProps, 'children'>;
|
||||
rootOptions?: Omit<DropdownMenuProps, 'children'>;
|
||||
contentOptions?: Omit<DropdownMenuContentProps, 'children'>;
|
||||
|
||||
@@ -20,6 +20,7 @@ import { MobileMenuSubRaw } from './sub';
|
||||
export const MobileMenu = ({
|
||||
children,
|
||||
items,
|
||||
title,
|
||||
contentOptions: {
|
||||
className,
|
||||
onPointerDownOutside,
|
||||
@@ -108,7 +109,7 @@ export const MobileMenu = ({
|
||||
*/
|
||||
if (pSetOpen) {
|
||||
return (
|
||||
<MobileMenuSubRaw items={items} subOptions={rootOptions}>
|
||||
<MobileMenuSubRaw title={title} items={items} subOptions={rootOptions}>
|
||||
{children}
|
||||
</MobileMenuSubRaw>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
type AffineEditorContainer,
|
||||
MobileOutlineMenu,
|
||||
} from '@blocksuite/affine/presets';
|
||||
import { useCallback, useRef } from 'react';
|
||||
|
||||
export const MobileTocMenu = ({
|
||||
editor,
|
||||
}: {
|
||||
editor: AffineEditorContainer | null;
|
||||
}) => {
|
||||
const outlineMenuRef = useRef<MobileOutlineMenu | null>(null);
|
||||
const onRefChange = useCallback((container: HTMLDivElement | null) => {
|
||||
if (container) {
|
||||
if (outlineMenuRef.current === null) {
|
||||
console.error('mobile outline menu should be initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
container.append(outlineMenuRef.current);
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!editor) return;
|
||||
|
||||
if (!outlineMenuRef.current) {
|
||||
outlineMenuRef.current = new MobileOutlineMenu();
|
||||
}
|
||||
if (outlineMenuRef.current.editor !== editor) {
|
||||
outlineMenuRef.current.editor = editor;
|
||||
}
|
||||
|
||||
return <div ref={onRefChange} />;
|
||||
};
|
||||
+3
-2
@@ -7,8 +7,8 @@ import {
|
||||
} from '@affine/component/ui/menu';
|
||||
import { useFavorite } from '@affine/core/components/blocksuite/block-suite-header/favorite';
|
||||
import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
|
||||
import { EditorOutlinePanel } from '@affine/core/desktop/pages/workspace/detail-page/tabs/outline';
|
||||
import { DocInfoSheet } from '@affine/core/mobile/components';
|
||||
import { MobileTocMenu } from '@affine/core/mobile/components/toc-menu';
|
||||
import { DocService } from '@affine/core/modules/doc';
|
||||
import { EditorService } from '@affine/core/modules/editor';
|
||||
import { ViewService } from '@affine/core/modules/workbench/services/view';
|
||||
@@ -120,9 +120,10 @@ export const PageHeaderMenuButton = () => {
|
||||
<span>{t['com.affine.page-properties.page-info.view']()}</span>
|
||||
</MenuSub>
|
||||
<MobileMenu
|
||||
title={t['com.affine.header.menu.toc']()}
|
||||
items={
|
||||
<div className={styles.outlinePanel}>
|
||||
<EditorOutlinePanel editor={editorContainer} />
|
||||
<MobileTocMenu editor={editorContainer} />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -2079,6 +2079,10 @@ export function useAFFiNEI18N(): {
|
||||
* `View table of contents`
|
||||
*/
|
||||
["com.affine.header.option.view-toc"](): string;
|
||||
/**
|
||||
* `Table of contents`
|
||||
*/
|
||||
["com.affine.header.menu.toc"](): string;
|
||||
/**
|
||||
* `Contact us`
|
||||
*/
|
||||
|
||||
@@ -519,6 +519,7 @@
|
||||
"com.affine.header.option.open-in-desktop": "Open in desktop app",
|
||||
"com.affine.header.option.view-frame": "View all frames",
|
||||
"com.affine.header.option.view-toc": "View table of contents",
|
||||
"com.affine.header.menu.toc": "Table of contents",
|
||||
"com.affine.helpIsland.contactUs": "Contact us",
|
||||
"com.affine.helpIsland.gettingStarted": "Getting started",
|
||||
"com.affine.helpIsland.helpAndFeedback": "Help and feedback",
|
||||
|
||||
Reference in New Issue
Block a user