new text editor block that contains core blocks as inner blocks and prevents them from being used at top level

This commit is contained in:
2025-11-27 07:14:31 +00:00
parent 0400a80874
commit 1368386cc4
18 changed files with 233 additions and 45 deletions

View File

@@ -3,16 +3,10 @@ import.meta.glob([
'../fonts/**',
]);
import domReady from '@wordpress/dom-ready';
import blocks from './blocks.js';
import Header from './sections/header.js';
import LazyLoad from './lib/Lazy.js';
/**
* Application entrypoint
*/
domReady(async () => {
LazyLoad();
blocks();
Header();
});
LazyLoad();
blocks();
Header();

View File

@@ -1,6 +1,6 @@
import BadExample from "./blocks/BadExample";
// import BadExample from "./blocks/BadExample";
export default function()
{
BadExample();
// BadExample();
}

View File

@@ -1,4 +0,0 @@
export default function BadExample()
{
}

View File

@@ -1,5 +1,52 @@
import domReady from '@wordpress/dom-ready';
domReady(() => {
//
const restrictEditorParentBlocks = (settings, name) => {
const TEXT_EDITOR_BLOCKS = [
// Design
'core/separator',
'core/spacer',
// Media
'core/cover',
'core/file',
'core/gallery',
'core/image',
'core/media-text',
'core/audio',
'core/video',
// Text
'core/footnotes',
'core/heading',
'core/list',
'core/code',
'core/details',
'core/freeform',
'core/list-item',
'core/missing',
'core/paragraph',
'core/preformatted',
'core/pullquote',
'core/quote',
'core/table',
'core/verse',
];
if (TEXT_EDITOR_BLOCKS.includes(name)) {
settings.parent = ['acf/badegg-editor']
}
// console.log(settings, name)
return settings
}
wp.hooks.addFilter(
'blocks.registerBlockType',
'your-project-name/restrict-parent-blocks',
restrictEditorParentBlocks
);
});

View File

@@ -0,0 +1,12 @@
export default function isInsideMyACFBlock(blockName)
{
const editor = wp.data.select('core/block-editor');
const selectedId = editor.getSelectedBlockClientId();
if (!selectedId) return false;
const parents = editor.getBlockParents(selectedId);
const parentNames = parents.map(id => editor.getBlockName(id));
return parentNames.includes(blockName);
}