@@ -4,12 +4,13 @@ import {
44 InlineContentSchema ,
55 StyleSchema ,
66} from "@blocknote/core" ;
7- import { useCallback , useState } from "react" ;
7+ import { useCallback , useMemo , useState } from "react" ;
88import { RiIndentDecrease , RiIndentIncrease } from "react-icons/ri" ;
99
1010import { useBlockNoteEditor } from "../../../../hooks/useBlockNoteEditor" ;
1111import { useEditorContentOrSelectionChange } from "../../../../hooks/useEditorContentOrSelectionChange" ;
1212import { ToolbarButton } from "../../../mantine-shared/Toolbar/ToolbarButton" ;
13+ import { useSelectedBlocks } from "../../../../hooks/useSelectedBlocks" ;
1314
1415export const NestBlockButton = ( ) => {
1516 const editor = useBlockNoteEditor <
@@ -18,6 +19,8 @@ export const NestBlockButton = () => {
1819 StyleSchema
1920 > ( ) ;
2021
22+ const selectedBlocks = useSelectedBlocks ( editor ) ;
23+
2124 const [ canNestBlock , setCanNestBlock ] = useState < boolean > ( ( ) =>
2225 editor . canNestBlock ( )
2326 ) ;
@@ -31,6 +34,16 @@ export const NestBlockButton = () => {
3134 editor . nestBlock ( ) ;
3235 } , [ editor ] ) ;
3336
37+ const show = useMemo ( ( ) => {
38+ return ! selectedBlocks . find (
39+ ( block ) => editor . schema . blockSchema [ block . type ] . content !== "inline"
40+ ) ;
41+ } , [ editor . schema . blockSchema , selectedBlocks ] ) ;
42+
43+ if ( ! show ) {
44+ return null ;
45+ }
46+
3447 return (
3548 < ToolbarButton
3649 onClick = { nestBlock }
@@ -45,6 +58,8 @@ export const NestBlockButton = () => {
4558export const UnnestBlockButton = ( ) => {
4659 const editor = useBlockNoteEditor < any , any , any > ( ) ;
4760
61+ const selectedBlocks = useSelectedBlocks ( editor ) ;
62+
4863 const [ canUnnestBlock , setCanUnnestBlock ] = useState < boolean > ( ( ) =>
4964 editor . canUnnestBlock ( )
5065 ) ;
@@ -58,6 +73,16 @@ export const UnnestBlockButton = () => {
5873 editor . unnestBlock ( ) ;
5974 } , [ editor ] ) ;
6075
76+ const show = useMemo ( ( ) => {
77+ return ! selectedBlocks . find (
78+ ( block ) => editor . schema . blockSchema [ block . type ] . content !== "inline"
79+ ) ;
80+ } , [ editor . schema . blockSchema , selectedBlocks ] ) ;
81+
82+ if ( ! show ) {
83+ return null ;
84+ }
85+
6186 return (
6287 < ToolbarButton
6388 onClick = { unnestBlock }
0 commit comments