@@ -4,12 +4,13 @@ import {
4
4
InlineContentSchema ,
5
5
StyleSchema ,
6
6
} from "@blocknote/core" ;
7
- import { useCallback , useState } from "react" ;
7
+ import { useCallback , useMemo , useState } from "react" ;
8
8
import { RiIndentDecrease , RiIndentIncrease } from "react-icons/ri" ;
9
9
10
10
import { useBlockNoteEditor } from "../../../../hooks/useBlockNoteEditor" ;
11
11
import { useEditorContentOrSelectionChange } from "../../../../hooks/useEditorContentOrSelectionChange" ;
12
12
import { ToolbarButton } from "../../../mantine-shared/Toolbar/ToolbarButton" ;
13
+ import { useSelectedBlocks } from "../../../../hooks/useSelectedBlocks" ;
13
14
14
15
export const NestBlockButton = ( ) => {
15
16
const editor = useBlockNoteEditor <
@@ -18,6 +19,8 @@ export const NestBlockButton = () => {
18
19
StyleSchema
19
20
> ( ) ;
20
21
22
+ const selectedBlocks = useSelectedBlocks ( editor ) ;
23
+
21
24
const [ canNestBlock , setCanNestBlock ] = useState < boolean > ( ( ) =>
22
25
editor . canNestBlock ( )
23
26
) ;
@@ -31,6 +34,16 @@ export const NestBlockButton = () => {
31
34
editor . nestBlock ( ) ;
32
35
} , [ editor ] ) ;
33
36
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
+
34
47
return (
35
48
< ToolbarButton
36
49
onClick = { nestBlock }
@@ -45,6 +58,8 @@ export const NestBlockButton = () => {
45
58
export const UnnestBlockButton = ( ) => {
46
59
const editor = useBlockNoteEditor < any , any , any > ( ) ;
47
60
61
+ const selectedBlocks = useSelectedBlocks ( editor ) ;
62
+
48
63
const [ canUnnestBlock , setCanUnnestBlock ] = useState < boolean > ( ( ) =>
49
64
editor . canUnnestBlock ( )
50
65
) ;
@@ -58,6 +73,16 @@ export const UnnestBlockButton = () => {
58
73
editor . unnestBlock ( ) ;
59
74
} , [ editor ] ) ;
60
75
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
+
61
86
return (
62
87
< ToolbarButton
63
88
onClick = { unnestBlock }
0 commit comments