@wordpress/block-editor
Version:
8 lines (7 loc) • 13.9 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/hooks/supports.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { Platform } from '@wordpress/element';\n\nconst ALIGN_SUPPORT_KEY = 'align';\nconst ALIGN_WIDE_SUPPORT_KEY = 'alignWide';\nconst BORDER_SUPPORT_KEY = '__experimentalBorder';\nconst COLOR_SUPPORT_KEY = 'color';\nconst CUSTOM_CLASS_NAME_SUPPORT_KEY = 'customClassName';\nconst FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';\nconst FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';\nconst LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';\n/**\n * Key within block settings' support array indicating support for font style.\n */\nconst FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';\n/**\n * Key within block settings' support array indicating support for font weight.\n */\nconst FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';\n/**\n * Key within block settings' supports array indicating support for text\n * align e.g. settings found in `block.json`.\n */\nconst TEXT_ALIGN_SUPPORT_KEY = 'typography.textAlign';\n/**\n * Key within block settings' supports array indicating support for text\n * columns e.g. settings found in `block.json`.\n */\nconst TEXT_COLUMNS_SUPPORT_KEY = 'typography.textColumns';\n/**\n * Key within block settings' supports array indicating support for text\n * decorations e.g. settings found in `block.json`.\n */\nconst TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';\n/**\n * Key within block settings' supports array indicating support for writing mode\n * e.g. settings found in `block.json`.\n */\nconst WRITING_MODE_SUPPORT_KEY = 'typography.__experimentalWritingMode';\n/**\n * Key within block settings' supports array indicating support for text\n * transforms e.g. settings found in `block.json`.\n */\nconst TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';\n\n/**\n * Key within block settings' supports array indicating support for letter-spacing\n * e.g. settings found in `block.json`.\n */\nconst LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';\nconst LAYOUT_SUPPORT_KEY = 'layout';\nconst TYPOGRAPHY_SUPPORT_KEYS = [\n\tLINE_HEIGHT_SUPPORT_KEY,\n\tFONT_SIZE_SUPPORT_KEY,\n\tFONT_STYLE_SUPPORT_KEY,\n\tFONT_WEIGHT_SUPPORT_KEY,\n\tFONT_FAMILY_SUPPORT_KEY,\n\tTEXT_ALIGN_SUPPORT_KEY,\n\tTEXT_COLUMNS_SUPPORT_KEY,\n\tTEXT_DECORATION_SUPPORT_KEY,\n\tTEXT_TRANSFORM_SUPPORT_KEY,\n\tWRITING_MODE_SUPPORT_KEY,\n\tLETTER_SPACING_SUPPORT_KEY,\n];\nconst EFFECTS_SUPPORT_KEYS = [ 'shadow' ];\nconst SPACING_SUPPORT_KEY = 'spacing';\nconst styleSupportKeys = [\n\t...EFFECTS_SUPPORT_KEYS,\n\t...TYPOGRAPHY_SUPPORT_KEYS,\n\tBORDER_SUPPORT_KEY,\n\tCOLOR_SUPPORT_KEY,\n\tSPACING_SUPPORT_KEY,\n];\n\n/**\n * Returns true if the block defines support for align.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasAlignSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, ALIGN_SUPPORT_KEY );\n\n/**\n * Returns the block support value for align, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getAlignSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, ALIGN_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for align wide.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasAlignWideSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, ALIGN_WIDE_SUPPORT_KEY );\n\n/**\n * Returns the block support value for align wide, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getAlignWideSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, ALIGN_WIDE_SUPPORT_KEY );\n\n/**\n * Determine whether there is block support for border properties.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @param {string} feature Border feature to check support for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBorderSupport( nameOrType, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( nameOrType, BORDER_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.color ||\n\t\t\tsupport?.radius ||\n\t\t\tsupport?.width ||\n\t\t\tsupport?.style\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Get block support for border properties.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @param {string} feature Border feature to get.\n *\n * @return {unknown} The block support.\n */\nexport const getBorderSupport = ( nameOrType, feature ) =>\n\tgetBlockSupport( nameOrType, [ BORDER_SUPPORT_KEY, feature ] );\n\n/**\n * Returns true if the block defines support for color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasColorSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\treturn (\n\t\tcolorSupport &&\n\t\t( colorSupport.link === true ||\n\t\t\tcolorSupport.gradient === true ||\n\t\t\tcolorSupport.background !== false ||\n\t\t\tcolorSupport.text !== false )\n\t);\n};\n\n/**\n * Returns true if the block defines support for link color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasLinkColorSupport = ( nameOrType ) => {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.link\n\t);\n};\n\n/**\n * Returns true if the block defines support for gradient color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasGradientSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.gradients\n\t);\n};\n\n/**\n * Returns true if the block defines support for background color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasBackgroundColorSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.background !== false;\n};\n\n/**\n * Returns true if the block defines support for text-align.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasTextAlignSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, TEXT_ALIGN_SUPPORT_KEY );\n\n/**\n * Returns the block support value for text-align, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getTextAlignSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, TEXT_ALIGN_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for background color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasTextColorSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.text !== false;\n};\n\n/**\n * Get block support for color properties.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @param {string} feature Color feature to get.\n *\n * @return {unknown} The block support.\n */\nexport const getColorSupport = ( nameOrType, feature ) =>\n\tgetBlockSupport( nameOrType, [ COLOR_SUPPORT_KEY, feature ] );\n\n/**\n * Returns true if the block defines support for custom class name.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasCustomClassNameSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true );\n\n/**\n * Returns the block support value for custom class name, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getCustomClassNameSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true );\n\n/**\n * Returns true if the block defines support for font family.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasFontFamilySupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, FONT_FAMILY_SUPPORT_KEY );\n\n/**\n * Returns the block support value for font family, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getFontFamilySupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, FONT_FAMILY_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for font size.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasFontSizeSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, FONT_SIZE_SUPPORT_KEY );\n\n/**\n * Returns the block support value for font size, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getFontSizeSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, FONT_SIZE_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for layout.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasLayoutSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, LAYOUT_SUPPORT_KEY );\n\n/**\n * Returns the block support value for layout, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getLayoutSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, LAYOUT_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for style.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasStyleSupport = ( nameOrType ) =>\n\tstyleSupportKeys.some( ( key ) => hasBlockSupport( nameOrType, key ) );\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAiD;AACjD,qBAAyB;AAEzB,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,qBAAqB;AAC3B,IAAM,oBAAoB;AAC1B,IAAM,gCAAgC;AACtC,IAAM,0BAA0B;AAChC,IAAM,wBAAwB;AAC9B,IAAM,0BAA0B;AAIhC,IAAM,yBAAyB;AAI/B,IAAM,0BAA0B;AAKhC,IAAM,yBAAyB;AAK/B,IAAM,2BAA2B;AAKjC,IAAM,8BAA8B;AAKpC,IAAM,2BAA2B;AAKjC,IAAM,6BAA6B;AAMnC,IAAM,6BAA6B;AACnC,IAAM,qBAAqB;AAC3B,IAAM,0BAA0B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AACA,IAAM,uBAAuB,CAAE,QAAS;AACxC,IAAM,sBAAsB;AAC5B,IAAM,mBAAmB;AAAA,EACxB,GAAG;AAAA,EACH,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AACD;AAQO,IAAM,kBAAkB,CAAE,mBAChC,+BAAiB,YAA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