@wordpress/block-editor
Version:
82 lines (80 loc) • 2.51 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/block-visibility/utils.js
var utils_exports = {};
__export(utils_exports, {
getHideEverywhereCheckboxState: () => getHideEverywhereCheckboxState,
getViewportCheckboxState: () => getViewportCheckboxState
});
module.exports = __toCommonJS(utils_exports);
var import_constants = require("./constants.cjs");
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 (!import_constants.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;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getHideEverywhereCheckboxState,
getViewportCheckboxState
});
//# sourceMappingURL=utils.cjs.map