@wordpress/block-editor
Version:
309 lines (283 loc) • 12.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hasBackgroundColorSupport = exports.hasAlignWideSupport = exports.hasAlignSupport = exports.getTextAlignSupport = exports.getLayoutSupport = exports.getFontSizeSupport = exports.getFontFamilySupport = exports.getCustomClassNameSupport = exports.getColorSupport = exports.getBorderSupport = exports.getAlignWideSupport = exports.getAlignSupport = void 0;
exports.hasBorderSupport = hasBorderSupport;
exports.hasTextColorSupport = exports.hasTextAlignSupport = exports.hasStyleSupport = exports.hasLinkColorSupport = exports.hasLayoutSupport = exports.hasGradientSupport = exports.hasFontSizeSupport = exports.hasFontFamilySupport = exports.hasCustomClassNameSupport = exports.hasColorSupport = void 0;
var _blocks = require("@wordpress/blocks");
var _element = require("@wordpress/element");
/**
* WordPress dependencies
*/
const ALIGN_SUPPORT_KEY = 'align';
const ALIGN_WIDE_SUPPORT_KEY = 'alignWide';
const BORDER_SUPPORT_KEY = '__experimentalBorder';
const COLOR_SUPPORT_KEY = 'color';
const CUSTOM_CLASS_NAME_SUPPORT_KEY = 'customClassName';
const FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';
const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';
const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
/**
* Key within block settings' support array indicating support for font style.
*/
const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
/**
* Key within block settings' support array indicating support for font weight.
*/
const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';
/**
* Key within block settings' supports array indicating support for text
* align e.g. settings found in `block.json`.
*/
const TEXT_ALIGN_SUPPORT_KEY = 'typography.textAlign';
/**
* Key within block settings' supports array indicating support for text
* columns e.g. settings found in `block.json`.
*/
const TEXT_COLUMNS_SUPPORT_KEY = 'typography.textColumns';
/**
* Key within block settings' supports array indicating support for text
* decorations e.g. settings found in `block.json`.
*/
const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
/**
* Key within block settings' supports array indicating support for writing mode
* e.g. settings found in `block.json`.
*/
const WRITING_MODE_SUPPORT_KEY = 'typography.__experimentalWritingMode';
/**
* Key within block settings' supports array indicating support for text
* transforms e.g. settings found in `block.json`.
*/
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
/**
* Key within block settings' supports array indicating support for letter-spacing
* e.g. settings found in `block.json`.
*/
const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
const LAYOUT_SUPPORT_KEY = 'layout';
const TYPOGRAPHY_SUPPORT_KEYS = [LINE_HEIGHT_SUPPORT_KEY, FONT_SIZE_SUPPORT_KEY, FONT_STYLE_SUPPORT_KEY, FONT_WEIGHT_SUPPORT_KEY, FONT_FAMILY_SUPPORT_KEY, TEXT_ALIGN_SUPPORT_KEY, TEXT_COLUMNS_SUPPORT_KEY, TEXT_DECORATION_SUPPORT_KEY, TEXT_TRANSFORM_SUPPORT_KEY, WRITING_MODE_SUPPORT_KEY, LETTER_SPACING_SUPPORT_KEY];
const EFFECTS_SUPPORT_KEYS = ['shadow'];
const SPACING_SUPPORT_KEY = 'spacing';
const styleSupportKeys = [...EFFECTS_SUPPORT_KEYS, ...TYPOGRAPHY_SUPPORT_KEYS, BORDER_SUPPORT_KEY, COLOR_SUPPORT_KEY, SPACING_SUPPORT_KEY];
/**
* Returns true if the block defines support for align.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
const hasAlignSupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, ALIGN_SUPPORT_KEY);
/**
* Returns the block support value for align, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasAlignSupport = hasAlignSupport;
const getAlignSupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, ALIGN_SUPPORT_KEY);
/**
* Returns true if the block defines support for align wide.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getAlignSupport = getAlignSupport;
const hasAlignWideSupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, ALIGN_WIDE_SUPPORT_KEY);
/**
* Returns the block support value for align wide, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasAlignWideSupport = hasAlignWideSupport;
const getAlignWideSupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, ALIGN_WIDE_SUPPORT_KEY);
/**
* Determine whether there is block support for border properties.
*
* @param {string|Object} nameOrType Block name or type object.
* @param {string} feature Border feature to check support for.
*
* @return {boolean} Whether there is support.
*/
exports.getAlignWideSupport = getAlignWideSupport;
function hasBorderSupport(nameOrType, feature = 'any') {
if (_element.Platform.OS !== 'web') {
return false;
}
const support = (0, _blocks.getBlockSupport)(nameOrType, BORDER_SUPPORT_KEY);
if (support === true) {
return true;
}
if (feature === 'any') {
return !!(support?.color || support?.radius || support?.width || support?.style);
}
return !!support?.[feature];
}
/**
* Get block support for border properties.
*
* @param {string|Object} nameOrType Block name or type object.
* @param {string} feature Border feature to get.
*
* @return {unknown} The block support.
*/
const getBorderSupport = (nameOrType, feature) => (0, _blocks.getBlockSupport)(nameOrType, [BORDER_SUPPORT_KEY, feature]);
/**
* Returns true if the block defines support for color.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getBorderSupport = getBorderSupport;
const hasColorSupport = nameOrType => {
const colorSupport = (0, _blocks.getBlockSupport)(nameOrType, COLOR_SUPPORT_KEY);
return colorSupport && (colorSupport.link === true || colorSupport.gradient === true || colorSupport.background !== false || colorSupport.text !== false);
};
/**
* Returns true if the block defines support for link color.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.hasColorSupport = hasColorSupport;
const hasLinkColorSupport = nameOrType => {
if (_element.Platform.OS !== 'web') {
return false;
}
const colorSupport = (0, _blocks.getBlockSupport)(nameOrType, COLOR_SUPPORT_KEY);
return colorSupport !== null && typeof colorSupport === 'object' && !!colorSupport.link;
};
/**
* Returns true if the block defines support for gradient color.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.hasLinkColorSupport = hasLinkColorSupport;
const hasGradientSupport = nameOrType => {
const colorSupport = (0, _blocks.getBlockSupport)(nameOrType, COLOR_SUPPORT_KEY);
return colorSupport !== null && typeof colorSupport === 'object' && !!colorSupport.gradients;
};
/**
* Returns true if the block defines support for background color.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.hasGradientSupport = hasGradientSupport;
const hasBackgroundColorSupport = nameOrType => {
const colorSupport = (0, _blocks.getBlockSupport)(nameOrType, COLOR_SUPPORT_KEY);
return colorSupport && colorSupport.background !== false;
};
/**
* Returns true if the block defines support for text-align.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.hasBackgroundColorSupport = hasBackgroundColorSupport;
const hasTextAlignSupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, TEXT_ALIGN_SUPPORT_KEY);
/**
* Returns the block support value for text-align, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasTextAlignSupport = hasTextAlignSupport;
const getTextAlignSupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, TEXT_ALIGN_SUPPORT_KEY);
/**
* Returns true if the block defines support for background color.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getTextAlignSupport = getTextAlignSupport;
const hasTextColorSupport = nameOrType => {
const colorSupport = (0, _blocks.getBlockSupport)(nameOrType, COLOR_SUPPORT_KEY);
return colorSupport && colorSupport.text !== false;
};
/**
* Get block support for color properties.
*
* @param {string|Object} nameOrType Block name or type object.
* @param {string} feature Color feature to get.
*
* @return {unknown} The block support.
*/
exports.hasTextColorSupport = hasTextColorSupport;
const getColorSupport = (nameOrType, feature) => (0, _blocks.getBlockSupport)(nameOrType, [COLOR_SUPPORT_KEY, feature]);
/**
* Returns true if the block defines support for custom class name.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getColorSupport = getColorSupport;
const hasCustomClassNameSupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true);
/**
* Returns the block support value for custom class name, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasCustomClassNameSupport = hasCustomClassNameSupport;
const getCustomClassNameSupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true);
/**
* Returns true if the block defines support for font family.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getCustomClassNameSupport = getCustomClassNameSupport;
const hasFontFamilySupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, FONT_FAMILY_SUPPORT_KEY);
/**
* Returns the block support value for font family, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasFontFamilySupport = hasFontFamilySupport;
const getFontFamilySupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, FONT_FAMILY_SUPPORT_KEY);
/**
* Returns true if the block defines support for font size.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getFontFamilySupport = getFontFamilySupport;
const hasFontSizeSupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, FONT_SIZE_SUPPORT_KEY);
/**
* Returns the block support value for font size, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasFontSizeSupport = hasFontSizeSupport;
const getFontSizeSupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, FONT_SIZE_SUPPORT_KEY);
/**
* Returns true if the block defines support for layout.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getFontSizeSupport = getFontSizeSupport;
const hasLayoutSupport = nameOrType => (0, _blocks.hasBlockSupport)(nameOrType, LAYOUT_SUPPORT_KEY);
/**
* Returns the block support value for layout, if defined.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {unknown} The block support value.
*/
exports.hasLayoutSupport = hasLayoutSupport;
const getLayoutSupport = nameOrType => (0, _blocks.getBlockSupport)(nameOrType, LAYOUT_SUPPORT_KEY);
/**
* Returns true if the block defines support for style.
*
* @param {string|Object} nameOrType Block name or type object.
* @return {boolean} Whether the block supports the feature.
*/
exports.getLayoutSupport = getLayoutSupport;
const hasStyleSupport = nameOrType => styleSupportKeys.some(key => (0, _blocks.hasBlockSupport)(nameOrType, key));
exports.hasStyleSupport = hasStyleSupport;
//# sourceMappingURL=supports.js.map