From c2edd93c72fd78acbc6e8ed53913160b86e34951 Mon Sep 17 00:00:00 2001 From: DiamondThree Date: Tue, 9 Aug 2022 12:14:14 +0800 Subject: [PATCH 1/3] fix page title tranform --- .../editor-blocks/src/blocks/page/PageView.tsx | 3 ++- .../editor-plugins/src/menu/command-menu/Menu.tsx | 5 +++++ .../editor-plugins/src/menu/inline-menu/Container.tsx | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/components/editor-blocks/src/blocks/page/PageView.tsx b/libs/components/editor-blocks/src/blocks/page/PageView.tsx index 685bd05826..7798a4327b 100644 --- a/libs/components/editor-blocks/src/blocks/page/PageView.tsx +++ b/libs/components/editor-blocks/src/blocks/page/PageView.tsx @@ -86,8 +86,9 @@ export const PageView: FC = ({ block, editor }) => { alwaysShowPlaceholder ref={textRef} className={'title'} - supportMarkdown={true} + supportMarkdown={false} handleEnter={onTextEnter} + handleConvert={() => {}} placeholder={'Untitled'} block={block} editor={editor} diff --git a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx index 78b6ef5ddd..8daf2c2b92 100644 --- a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx +++ b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx @@ -82,6 +82,11 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => { const checkIfShowCommandMenu = useCallback( async (event: React.KeyboardEvent) => { const { type, anchorNode } = editor.selection.currentSelectInfo; + // console.log(await editor.getBlockById(anchorNode.id)); + let activeBlock = await editor.getBlockById(anchorNode.id); + if (activeBlock.type === Protocol.Block.Type.page) { + return; + } if (event.key === '/' && type === 'Range') { if (anchorNode) { const text = editor.blockHelper.getBlockTextBeforeSelection( diff --git a/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx b/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx index 27807b6186..2023c4215b 100644 --- a/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx +++ b/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx @@ -1,4 +1,5 @@ import { useState, useEffect } from 'react'; +import { Protocol } from '@toeverything/datasource/db-service'; import { MuiClickAwayListener as ClickAwayListener, MuiGrow as Grow, @@ -22,8 +23,14 @@ export const InlineMenuContainer = ({ editor }: InlineMenuContainerProps) => { useEffect(() => { // const unsubscribe = editor.selection.onSelectionChange(info => { - const unsubscribe = editor.selection.onSelectEnd(info => { + const unsubscribe = editor.selection.onSelectEnd(async info => { const { type, browserSelection, anchorNode } = info; + if (anchorNode) { + let activeBlock = await editor.getBlockById(anchorNode.id); + if (activeBlock.type === Protocol.Block.Type.page) { + return; + } + } if ( type === 'None' || !anchorNode || From 81867d85e3acb57577e83680dfb5e6d7f96509bf Mon Sep 17 00:00:00 2001 From: Whitewater Date: Tue, 9 Aug 2022 12:33:56 +0800 Subject: [PATCH 2/3] chore: prefer const --- libs/components/editor-plugins/src/menu/command-menu/Menu.tsx | 2 +- .../editor-plugins/src/menu/inline-menu/Container.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx index 8daf2c2b92..b6d174e513 100644 --- a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx +++ b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx @@ -83,7 +83,7 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => { async (event: React.KeyboardEvent) => { const { type, anchorNode } = editor.selection.currentSelectInfo; // console.log(await editor.getBlockById(anchorNode.id)); - let activeBlock = await editor.getBlockById(anchorNode.id); + const activeBlock = await editor.getBlockById(anchorNode.id); if (activeBlock.type === Protocol.Block.Type.page) { return; } diff --git a/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx b/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx index 2023c4215b..f515f81141 100644 --- a/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx +++ b/libs/components/editor-plugins/src/menu/inline-menu/Container.tsx @@ -26,7 +26,7 @@ export const InlineMenuContainer = ({ editor }: InlineMenuContainerProps) => { const unsubscribe = editor.selection.onSelectEnd(async info => { const { type, browserSelection, anchorNode } = info; if (anchorNode) { - let activeBlock = await editor.getBlockById(anchorNode.id); + const activeBlock = await editor.getBlockById(anchorNode.id); if (activeBlock.type === Protocol.Block.Type.page) { return; } From 0d33006da2fcf222713e94ae02d7895aedb032d9 Mon Sep 17 00:00:00 2001 From: DiamondThree Date: Tue, 9 Aug 2022 17:38:57 +0800 Subject: [PATCH 3/3] fix page title tranform --- libs/components/editor-blocks/src/blocks/page/PageView.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/components/editor-blocks/src/blocks/page/PageView.tsx b/libs/components/editor-blocks/src/blocks/page/PageView.tsx index 7798a4327b..5aca7e6460 100644 --- a/libs/components/editor-blocks/src/blocks/page/PageView.tsx +++ b/libs/components/editor-blocks/src/blocks/page/PageView.tsx @@ -88,7 +88,6 @@ export const PageView: FC = ({ block, editor }) => { className={'title'} supportMarkdown={false} handleEnter={onTextEnter} - handleConvert={() => {}} placeholder={'Untitled'} block={block} editor={editor}