You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I trying to build a system where all patterns are pre-built as elements that should be inserted at page root level. They are basically top level page rows with content.
So I would like to always insert elements at BlockRootClient even if user has selected/clicked somewhere deeper inside than one the outermost one rows.
When the Pattern Explorer modal is open I can run following in the console and it select the insertion point I want:
const ed = wp.data.select('core/block-editor');
wp.data.dispatch('core/block-editor').selectBlock( ed.getBlockHierarchyRootClientId( ed.getSelectedBlockClientIds() ) );
And a selection moved "out" for example:
Page > Row > Section > Paragraph --> Page > Row
But when I tried to hack it to run on a subscribe, like so, the modal closes:
Not working. Modal closes.
wp.data.subscribe( () => {
const PatternModal = document.getElementsByClassName("components-modal__frame block-pattern-explorer__modal is-full-screen")[0];
//const spinner = document.getElementsByClassName("components-modal__frame block-pattern-explorer__modal is-full-screen .components-spinner")[0]
const ed = wp.data.select('core/block-editor');
const numOfParentsBlocks = ed.getBlockParents(ed.getSelectedBlockClientId()).length;
if(PatternModal && numOfParentsBlocks > 0 ) {
console.log("Pattern Modal exist! And number of parents is > 1");
wp.data.dispatch('core/block-editor').selectBlock( ed.getBlockHierarchyRootClientId( ed.getSelectedBlockClientIds() ) );
}
});
I also tried modifying use-insertion-point.js slightly, like so: const selectedBlockClientId = getBlockRootClientId( getSelectedBlockClientId() );
But got some strange results.
I clearly don't grasp the principles very well.
Could you perhaps point me in the right direction?
The text was updated successfully, but these errors were encountered:
I trying to build a system where all patterns are pre-built as elements that should be inserted at page root level. They are basically top level page rows with content.
So I would like to always insert elements at BlockRootClient even if user has selected/clicked somewhere deeper inside than one the outermost one rows.
When the Pattern Explorer modal is open I can run following in the console and it select the insertion point I want:
And a selection moved "out" for example:
Page > Row > Section > Paragraph --> Page > Row
But when I tried to hack it to run on a subscribe, like so, the modal closes:
Not working. Modal closes.
I also tried modifying use-insertion-point.js slightly, like so:
const selectedBlockClientId = getBlockRootClientId( getSelectedBlockClientId() );
But got some strange results.
I clearly don't grasp the principles very well.
Could you perhaps point me in the right direction?
The text was updated successfully, but these errors were encountered: