@wordpress/blocks
Version:
Block API for WordPress.
8 lines (7 loc) • 5.85 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/api/parser/convert-legacy-block.js"],
"sourcesContent": ["/**\n * Convert legacy blocks to their canonical form. This function is used\n * both in the parser level for previous content and to convert such blocks\n * used in Custom Post Types templates.\n *\n * @param {string} name The block's name\n * @param {Object} attributes The block's attributes\n *\n * @return {[string, Object]} The block's name and attributes, changed accordingly if a match was found\n */\nexport function convertLegacyBlockNameAndAttributes( name, attributes ) {\n\tconst newAttributes = { ...attributes };\n\t// Convert 'core/cover-image' block in existing content to 'core/cover'.\n\tif ( 'core/cover-image' === name ) {\n\t\tname = 'core/cover';\n\t}\n\n\t// Convert 'core/text' blocks in existing content to 'core/paragraph'.\n\tif ( 'core/text' === name || 'core/cover-text' === name ) {\n\t\tname = 'core/paragraph';\n\t}\n\n\t// Convert derivative blocks such as 'core/social-link-wordpress' to the\n\t// canonical form 'core/social-link'.\n\tif ( name && name.indexOf( 'core/social-link-' ) === 0 ) {\n\t\t// Capture `social-link-wordpress` into `{\"service\":\"wordpress\"}`\n\t\tnewAttributes.service = name.substring( 17 );\n\t\tname = 'core/social-link';\n\t}\n\n\t// Convert derivative blocks such as 'core-embed/instagram' to the\n\t// canonical form 'core/embed'.\n\tif ( name && name.indexOf( 'core-embed/' ) === 0 ) {\n\t\t// Capture `core-embed/instagram` into `{\"providerNameSlug\":\"instagram\"}`\n\t\tconst providerSlug = name.substring( 11 );\n\t\tconst deprecated = {\n\t\t\tspeaker: 'speaker-deck',\n\t\t\tpolldaddy: 'crowdsignal',\n\t\t};\n\t\tnewAttributes.providerNameSlug =\n\t\t\tproviderSlug in deprecated\n\t\t\t\t? deprecated[ providerSlug ]\n\t\t\t\t: providerSlug;\n\t\t// This is needed as the `responsive` attribute was passed\n\t\t// in a different way before the refactoring to block variations.\n\t\tif ( ! [ 'amazon-kindle', 'wordpress' ].includes( providerSlug ) ) {\n\t\t\tnewAttributes.responsive = true;\n\t\t}\n\t\tname = 'core/embed';\n\t}\n\n\t// Convert Post Comment blocks in existing content to Comment blocks.\n\tif ( name === 'core/post-comment-author' ) {\n\t\tname = 'core/comment-author-name';\n\t}\n\tif ( name === 'core/post-comment-content' ) {\n\t\tname = 'core/comment-content';\n\t}\n\tif ( name === 'core/post-comment-date' ) {\n\t\tname = 'core/comment-date';\n\t}\n\tif ( name === 'core/comments-query-loop' ) {\n\t\tname = 'core/comments';\n\t\tconst { className = '' } = newAttributes;\n\t\tif ( ! className.includes( 'wp-block-comments-query-loop' ) ) {\n\t\t\tnewAttributes.className = [\n\t\t\t\t'wp-block-comments-query-loop',\n\t\t\t\tclassName,\n\t\t\t].join( ' ' );\n\t\t}\n\t\t// Note that we also had to add a deprecation to the block in order\n\t\t// for the ID change to work.\n\t}\n\tif ( name === 'core/post-comments' ) {\n\t\tname = 'core/comments';\n\t\tnewAttributes.legacy = true;\n\t}\n\n\t// Column count was stored as a string from WP 6.3-6.6. Convert it to a number.\n\tif (\n\t\tattributes.layout?.type === 'grid' &&\n\t\ttypeof attributes.layout?.columnCount === 'string'\n\t) {\n\t\tnewAttributes.layout = {\n\t\t\t...newAttributes.layout,\n\t\t\tcolumnCount: parseInt( attributes.layout.columnCount, 10 ),\n\t\t};\n\t}\n\n\t// Column span and row span were stored as strings in WP 6.6. Convert them to numbers.\n\tif ( typeof attributes.style?.layout?.columnSpan === 'string' ) {\n\t\tconst columnSpanNumber = parseInt(\n\t\t\tattributes.style.layout.columnSpan,\n\t\t\t10\n\t\t);\n\t\tnewAttributes.style = {\n\t\t\t...newAttributes.style,\n\t\t\tlayout: {\n\t\t\t\t...newAttributes.style.layout,\n\t\t\t\tcolumnSpan: isNaN( columnSpanNumber )\n\t\t\t\t\t? undefined\n\t\t\t\t\t: columnSpanNumber,\n\t\t\t},\n\t\t};\n\t}\n\tif ( typeof attributes.style?.layout?.rowSpan === 'string' ) {\n\t\tconst rowSpanNumber = parseInt( attributes.style.layout.rowSpan, 10 );\n\t\tnewAttributes.style = {\n\t\t\t...newAttributes.style,\n\t\t\tlayout: {\n\t\t\t\t...newAttributes.style.layout,\n\t\t\t\trowSpan: isNaN( rowSpanNumber ) ? undefined : rowSpanNumber,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn [ name, newAttributes ];\n}\n"],
"mappings": ";AAUO,SAAS,oCAAqC,MAAM,YAAa;AACvE,QAAM,gBAAgB,EAAE,GAAG,WAAW;AAEtC,MAAK,uBAAuB,MAAO;AAClC,WAAO;AAAA,EACR;AAGA,MAAK,gBAAgB,QAAQ,sBAAsB,MAAO;AACzD,WAAO;AAAA,EACR;AAIA,MAAK,QAAQ,KAAK,QAAS,mBAAoB,MAAM,GAAI;AAExD,kBAAc,UAAU,KAAK,UAAW,EAAG;AAC3C,WAAO;AAAA,EACR;AAIA,MAAK,QAAQ,KAAK,QAAS,aAAc,MAAM,GAAI;AAElD,UAAM,eAAe,KAAK,UAAW,EAAG;AACxC,UAAM,aAAa;AAAA,MAClB,SAAS;AAAA,MACT,WAAW;AAAA,IACZ;AACA,kBAAc,mBACb,gBAAgB,aACb,WAAY,YAAa,IACzB;AAGJ,QAAK,CAAE,CAAE,iBAAiB,WAAY,EAAE,SAAU,YAAa,GAAI;AAClE,oBAAc,aAAa;AAAA,IAC5B;AACA,WAAO;AAAA,EACR;AAGA,MAAK,SAAS,4BAA6B;AAC1C,WAAO;AAAA,EACR;AACA,MAAK,SAAS,6BAA8B;AAC3C,WAAO;AAAA,EACR;AACA,MAAK,SAAS,0BAA2B;AACxC,WAAO;AAAA,EACR;AACA,MAAK,SAAS,4BAA6B;AAC1C,WAAO;AACP,UAAM,EAAE,YAAY,GAAG,IAAI;AAC3B,QAAK,CAAE,UAAU,SAAU,8BAA+B,GAAI;AAC7D,oBAAc,YAAY;AAAA,QACzB;AAAA,QACA;AAAA,MACD,EAAE,KAAM,GAAI;AAAA,IACb;AAAA,EAGD;AACA,MAAK,SAAS,sBAAuB;AACpC,WAAO;AACP,kBAAc,SAAS;AAAA,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