@wordpress/components
Version:
UI components for WordPress.
85 lines (69 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.alignmentHelpers = exports.WIDE_ALIGNMENTS = exports.ALIGNMENT_BREAKPOINTS = void 0;
var _blocks = require("@wordpress/blocks");
/**
* WordPress dependencies
*/
const WIDE_ALIGNMENTS = {
alignments: {
wide: 'wide',
full: 'full'
},
excludeBlocks: ['core/heading'],
notInnerContainers: ['core/separator', 'core/media-text', 'core/pullquote']
};
exports.WIDE_ALIGNMENTS = WIDE_ALIGNMENTS;
const ALIGNMENT_BREAKPOINTS = {
wide: 1024,
large: 820,
medium: 768,
small: 680,
mobile: 480
};
exports.ALIGNMENT_BREAKPOINTS = ALIGNMENT_BREAKPOINTS;
const isFullWidth = align => align === WIDE_ALIGNMENTS.alignments.full;
const isWideWidth = align => align === WIDE_ALIGNMENTS.alignments.wide;
const isWider = (width, breakpoint) => width > ALIGNMENT_BREAKPOINTS[breakpoint];
const isContainerRelated = blockName => {
if (WIDE_ALIGNMENTS.notInnerContainers.includes(blockName)) {
return false;
}
if (hasFullWidthSupport(blockName)) {
return true;
}
return hasParentFullWidthSupport(blockName);
};
/**
* Whether the block has support for full width alignment.
*
* @param {string} blockName
* @return {boolean} Return whether the block supports full width alignment.
*/
function hasFullWidthSupport(blockName) {
var _blockType$supports;
const blockType = (0, _blocks.getBlockType)(blockName);
const blockAlign = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports = blockType.supports) === null || _blockType$supports === void 0 ? void 0 : _blockType$supports.align;
return !!Array.isArray(blockAlign) && blockAlign.includes(WIDE_ALIGNMENTS.alignments.full);
}
/**
* Whether the block's parent has support for full width alignment.
*
* @param {string} blockName
* @return {boolean} Return whether the block's parent supports full width alignment.
*/
function hasParentFullWidthSupport(blockName) {
var _blockType$parent;
const blockType = (0, _blocks.getBlockType)(blockName);
return !!(blockType !== null && blockType !== void 0 && (_blockType$parent = blockType.parent) !== null && _blockType$parent !== void 0 && _blockType$parent.some(hasFullWidthSupport));
}
const alignmentHelpers = {
isFullWidth,
isWideWidth,
isWider,
isContainerRelated
};
exports.alignmentHelpers = alignmentHelpers;
//# sourceMappingURL=alignments.native.js.map