UNPKG

@wordpress/block-editor

Version:
56 lines (55 loc) 1.4 kB
// packages/block-editor/src/components/block-visibility/utils.js import { BLOCK_VISIBILITY_VIEWPORT_ENTRIES } from "./constants.mjs"; function isBlockHiddenForViewport(block, viewport) { if (!block) { return false; } const blockVisibility = block.attributes?.metadata?.blockVisibility; if (blockVisibility === true) { return false; } if ("object" !== typeof blockVisibility) { return false; } if (!BLOCK_VISIBILITY_VIEWPORT_ENTRIES.some( ([, { key }]) => key === viewport )) { return false; } return blockVisibility[viewport] === false; } function getViewportCheckboxState(blocks, viewport) { if (!blocks?.length) { return false; } const hiddenCount = blocks.filter( (block) => isBlockHiddenForViewport(block, viewport) ).length; if (hiddenCount === 0) { return false; } if (hiddenCount === blocks.length) { return true; } return null; } function getHideEverywhereCheckboxState(blocks) { if (!blocks?.length) { return false; } const hiddenEverywhereCount = blocks.filter( (block) => block && block.attributes?.metadata?.blockVisibility === false ).length; if (hiddenEverywhereCount === 0) { return false; } if (hiddenEverywhereCount === blocks.length) { return true; } return null; } export { getHideEverywhereCheckboxState, getViewportCheckboxState }; //# sourceMappingURL=utils.mjs.map