Add facets in a block pattern

<?php
/**
 ** including a facetwp shortcode in a block pattern
 **/
if ( ! is_admin() && ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
    echo do_shortcode('[facetwp facet="categories"]');
} else {    
    echo '<!-- wp:shortcode -->[facetwp facet="categories"]<!-- /wp:shortcode -->';
} ?>