-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: add SlashMenu back (#1421)
* add default slash menu * frontend: prevent scroll when slash menu opens
- Loading branch information
Showing
8 changed files
with
115 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Block as BlockNoteBlock, BlockNoteEditor} from './blocknote' | ||
import {HMBlockSchema} from './schema' | ||
import {useEffect, useState} from 'react' | ||
import {getBlockInfoFromPos} from './blocknote' | ||
|
||
export function useSelected( | ||
block: BlockNoteBlock<HMBlockSchema>, | ||
editor: BlockNoteEditor<HMBlockSchema>, | ||
) { | ||
const [selected, setSelected] = useState(false) | ||
const tiptapEditor = editor._tiptapEditor | ||
const selection = tiptapEditor.state.selection | ||
|
||
useEffect(() => { | ||
if (editor) { | ||
const selectedNode = getBlockInfoFromPos( | ||
tiptapEditor.state.doc, | ||
tiptapEditor.state.selection.from, | ||
) | ||
if (selectedNode && selectedNode.id) { | ||
if ( | ||
selectedNode.id === block.id && | ||
selectedNode.startPos === selection.$anchor.pos | ||
) { | ||
setSelected(true) | ||
} else if (selectedNode.id !== block.id) { | ||
setSelected(false) | ||
} | ||
} | ||
} | ||
}, [selection]) | ||
|
||
return selected | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters