Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAD-3459 Prevent flashing of design library in Lifter LMS #580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const eslintConfig = {
Masonry: 'readable',
IntersectionObserver: 'readable',
getComputedStyle: 'readable',
MutationObserver: 'readonly',
},
rules: {
'@wordpress/i18n-text-domain': [
Expand Down
32 changes: 21 additions & 11 deletions src/plugins/prebuilt-library/toolbar-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import { kadenceBlocksIcon } from '@kadence/icons';
function ToolbarLibrary() {
const { getSelectedBlock, getBlockIndex, getBlockHierarchyRootClientId } = useSelect(blockEditorStore);
const { replaceBlocks, insertBlocks } = useDispatch(blockEditorStore);
const [kadenceIcon, setKadenceIcon] = useState(applyFilters('kadence.blocks_icon', kadenceBlocksIcon));
const kadenceIcon = applyFilters('kadence.blocks_icon', kadenceBlocksIcon);

const LibraryButton = () => (
<ToolbarButton
className="kb-toolbar-prebuilt-button"
icon={kadenceIcon}
// isPrimary
onClick={() => {
const selectedBlock = getSelectedBlock();
if (selectedBlock && isUnmodifiedDefaultBlock(selectedBlock)) {
Expand Down Expand Up @@ -72,17 +72,27 @@ function ToolbarLibrary() {
selector.appendChild(patternButton);
render(<LibraryButton />, patternButton);
};

if (showSettings('show', 'kadence/designlibrary') && kadence_blocks_params.showDesignLibrary) {
// Watch for the toolbar to be visible and the design library button to be missing.
const unsubscribe = subscribe(() => {
const editToolbar = document.querySelector('.edit-post-header-toolbar');
if (!editToolbar) {
return;
}
if (!editToolbar.querySelector('.kadence-toolbar-design-library')) {
renderButton(editToolbar);
const targetNode = document.querySelector('.block-editor__container');
const config = { childList: true, subtree: true };

const callback = function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const editToolbar = document.querySelector('.edit-post-header-toolbar');
if (editToolbar && !editToolbar.querySelector('.kadence-toolbar-design-library')) {
renderButton(editToolbar);
observer.disconnect();
}
}
}
});
};

const observer = new MutationObserver(callback);
if (targetNode) {
observer.observe(targetNode, config);
}
}

return null;
Expand Down
Loading