UNPKG

@wordpress/block-library

Version:
1 lines • 1.78 kB
{"version":3,"file":"transforms.cjs","names":["metadata","getBlockAttributes","createBlock"],"sources":["../../src/paragraph/transforms.js"],"sourcesContent":["import { createBlock, getBlockAttributes } from '@wordpress/blocks';\nimport metadata from './block.json';\n\nconst { name } = metadata;\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'raw',\n\t\t\t// Paragraph is a fallback and should be matched last.\n\t\t\tpriority: 20,\n\t\t\tselector: 'p',\n\t\t\tschema: ( { phrasingContentSchema, isPaste } ) => ( {\n\t\t\t\tp: {\n\t\t\t\t\tchildren: phrasingContentSchema,\n\t\t\t\t\tattributes: isPaste ? [] : [ 'style', 'id' ],\n\t\t\t\t},\n\t\t\t} ),\n\t\t\ttransform( node ) {\n\t\t\t\tconst attributes = getBlockAttributes( name, node.outerHTML );\n\t\t\t\tconst { textAlign } = node.style || {};\n\n\t\t\t\tif (\n\t\t\t\t\ttextAlign === 'left' ||\n\t\t\t\t\ttextAlign === 'center' ||\n\t\t\t\t\ttextAlign === 'right'\n\t\t\t\t) {\n\t\t\t\t\tattributes.style = {\n\t\t\t\t\t\t...attributes.style,\n\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t...attributes.style?.typography,\n\t\t\t\t\t\t\ttextAlign,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn createBlock( name, attributes );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,EAAE,SAASA,aAAAA;AAEjB,MAAM,aAAa,EAClB,MAAM,CACL;CACC,MAAM;CAEN,UAAU;CACV,UAAU;CACV,SAAU,EAAE,uBAAuB,eAAiB,EACnD,GAAG;EACF,UAAU;EACV,YAAY,UAAU,CAAC,IAAI,CAAE,SAAS,IAAK;CAC5C,EACD;CACA,UAAW,MAAO;EACjB,MAAM,cAAA,GAAaC,kBAAAA,mBAAAA,CAAoB,MAAM,KAAK,SAAU;EAC5D,MAAM,EAAE,cAAc,KAAK,SAAS,CAAC;EAErC,IACC,cAAc,UACd,cAAc,YACd,cAAc,SAEd,WAAW,QAAQ;GAClB,GAAG,WAAW;GACd,YAAY;IACX,GAAG,WAAW,OAAO;IACrB;GACD;EACD;EAGD,QAAA,GAAOC,kBAAAA,YAAAA,CAAa,MAAM,UAAW;CACtC;AACD,CACD,EACD"}