{"version":3,"file":"get-transformed-attributes.cjs","names":["getBlockType","hasBlockSupport"],"sources":["../../src/utils/get-transformed-attributes.js"],"sourcesContent":["import { getBlockType, hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Transform block support attributes and metadata during block transforms.\n *\n * @param {Object}   attributes       Original attributes from the block being transformed.\n * @param {string}   newBlockName     Name of the target block after transformation.\n * @param {Function} bindingsCallback Optional callback to transform the `bindings` property object.\n * @return {Object} New attributes object with preserved block support attributes and metadata.\n */\nexport function getTransformedAttributes(\n\tattributes,\n\tnewBlockName,\n\tbindingsCallback = null\n) {\n\tif ( ! attributes ) {\n\t\treturn undefined;\n\t}\n\n\tconst newBlockType = getBlockType( newBlockName );\n\tif ( ! newBlockType ) {\n\t\treturn undefined;\n\t}\n\n\tconst transformedAttributes = {};\n\n\t// Handle attributes derived from block support. The custom class name and\n\t// allowed blocks attribute is handled separately.\n\tif ( hasBlockSupport( newBlockType, 'anchor' ) && attributes.anchor ) {\n\t\ttransformedAttributes.anchor = attributes.anchor;\n\t}\n\tif (\n\t\thasBlockSupport( newBlockType, 'ariaLabel' ) &&\n\t\tattributes.ariaLabel\n\t) {\n\t\ttransformedAttributes.ariaLabel = attributes.ariaLabel;\n\t}\n\n\t// Handle metadata transformation.\n\tif ( attributes.metadata ) {\n\t\t// The metadata properties that should be preserved after the transform.\n\t\t// The noteId, name, and blockVisibility properties are separately handled\n\t\t// in the `core/metadata/addTransforms` hook.\n\t\tconst transformedMetadata = [];\n\n\t\t// If there is a transform bindings callback, add the `id` and `bindings` properties.\n\t\tif ( bindingsCallback ) {\n\t\t\ttransformedMetadata.push( 'id', 'bindings' );\n\t\t}\n\n\t\t// Only process metadata if there are supported properties.\n\t\tif ( transformedMetadata.length > 0 ) {\n\t\t\tconst newMetadata = Object.entries( attributes.metadata ).reduce(\n\t\t\t\t( obj, [ prop, value ] ) => {\n\t\t\t\t\t// If prop is not supported, don't add it to the new metadata object.\n\t\t\t\t\tif ( ! transformedMetadata.includes( prop ) ) {\n\t\t\t\t\t\treturn obj;\n\t\t\t\t\t}\n\t\t\t\t\tobj[ prop ] =\n\t\t\t\t\t\tprop === 'bindings' ? bindingsCallback( value ) : value;\n\t\t\t\t\treturn obj;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\t// Only add metadata if object is not empty.\n\t\t\tif ( Object.keys( newMetadata ).length > 0 ) {\n\t\t\t\ttransformedAttributes.metadata = newMetadata;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( Object.keys( transformedAttributes ).length === 0 ) {\n\t\treturn undefined;\n\t}\n\n\treturn transformedAttributes;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAUA,SAAgB,yBACf,YACA,cACA,mBAAmB,MAClB;CACD,IAAK,CAAE,YACN;CAGD,MAAM,gBAAA,GAAeA,kBAAAA,aAAAA,CAAc,YAAa;CAChD,IAAK,CAAE,cACN;CAGD,MAAM,wBAAwB,CAAC;CAI/B,KAAA,GAAKC,kBAAAA,gBAAAA,CAAiB,cAAc,QAAS,KAAK,WAAW,QAC5D,sBAAsB,SAAS,WAAW;CAE3C,KAAA,GACCA,kBAAAA,gBAAAA,CAAiB,cAAc,WAAY,KAC3C,WAAW,WAEX,sBAAsB,YAAY,WAAW;CAI9C,IAAK,WAAW,UAAW;EAI1B,MAAM,sBAAsB,CAAC;EAG7B,IAAK,kBACJ,oBAAoB,KAAM,MAAM,UAAW;EAI5C,IAAK,oBAAoB,SAAS,GAAI;GACrC,MAAM,cAAc,OAAO,QAAS,WAAW,QAAS,CAAC,CAAC,QACvD,KAAK,CAAE,MAAM,WAAa;IAE3B,IAAK,CAAE,oBAAoB,SAAU,IAAK,GACzC,OAAO;IAER,IAAK,QACJ,SAAS,aAAa,iBAAkB,KAAM,IAAI;IACnD,OAAO;GACR,GACA,CAAC,CACF;GAGA,IAAK,OAAO,KAAM,WAAY,CAAC,CAAC,SAAS,GACxC,sBAAsB,WAAW;EAEnC;CACD;CAEA,IAAK,OAAO,KAAM,qBAAsB,CAAC,CAAC,WAAW,GACpD;CAGD,OAAO;AACR"}