UNPKG

@wordpress/blocks

Version:
8 lines (7 loc) 2.62 kB
{ "version": 3, "sources": ["../../../src/api/parser/apply-built-in-validation-fixes.js"], "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { fixCustomClassname } from './fix-custom-classname';\nimport { fixGlobalAttribute } from './fix-global-attribute';\n\nconst ARIA_LABEL_ATTR_SCHEMA = {\n\ttype: 'string',\n\tsource: 'attribute',\n\tselector: '[data-aria-label] > *',\n\tattribute: 'aria-label',\n};\n\nconst ANCHOR_ATTR_SCHEMA = {\n\ttype: 'string',\n\tsource: 'attribute',\n\tselector: '[data-anchor] > *',\n\tattribute: 'id',\n};\n\n/**\n * Attempts to fix block invalidation by applying build-in validation fixes\n * like moving all extra classNames to the className attribute.\n *\n * @param {WPBlock} block block object.\n * @param {import('../registration').WPBlockType} blockType Block type. This is normalize not necessary and\n * can be inferred from the block name,\n * but it's here for performance reasons.\n *\n * @return {WPBlock} Fixed block object\n */\nexport function applyBuiltInValidationFixes( block, blockType ) {\n\tconst { attributes, originalContent } = block;\n\tlet updatedBlockAttributes = attributes;\n\n\t// Fix block invalidation for className attribute.\n\tupdatedBlockAttributes = fixCustomClassname(\n\t\tattributes,\n\t\tblockType,\n\t\toriginalContent\n\t);\n\t// Fix block invalidation for ariaLabel attribute.\n\tupdatedBlockAttributes = fixGlobalAttribute(\n\t\tupdatedBlockAttributes,\n\t\tblockType,\n\t\toriginalContent,\n\t\t'ariaLabel',\n\t\t'data-aria-label',\n\t\tARIA_LABEL_ATTR_SCHEMA\n\t);\n\t// Fix block invalidation for anchor attribute.\n\tupdatedBlockAttributes = fixGlobalAttribute(\n\t\tupdatedBlockAttributes,\n\t\tblockType,\n\t\toriginalContent,\n\t\t'anchor',\n\t\t'data-anchor',\n\t\tANCHOR_ATTR_SCHEMA\n\t);\n\n\treturn {\n\t\t...block,\n\t\tattributes: updatedBlockAttributes,\n\t};\n}\n"], "mappings": ";AAGA,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAEnC,IAAM,yBAAyB;AAAA,EAC9B,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AACZ;AAEA,IAAM,qBAAqB;AAAA,EAC1B,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AACZ;AAaO,SAAS,4BAA6B,OAAO,WAAY;AAC/D,QAAM,EAAE,YAAY,gBAAgB,IAAI;AACxC,MAAI,yBAAyB;AAG7B,2BAAyB;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,2BAAyB;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,2BAAyB;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,YAAY;AAAA,EACb;AACD;", "names": [] }