@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 3.14 kB
Source Map (JSON)
{"version":3,"file":"transforms.mjs","names":["createElement"],"sources":["../../src/buttons/transforms.js"],"sourcesContent":["import { createBlock } from '@wordpress/blocks';\nimport { __unstableCreateElement as createElement } from '@wordpress/rich-text';\nimport { getTransformedAttributes } from '../utils/get-transformed-attributes';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tisMultiBlock: true,\n\t\t\tblocks: [ 'core/button' ],\n\t\t\ttransform: ( buttons ) =>\n\t\t\t\t// Creates the buttons block.\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/buttons',\n\t\t\t\t\t{},\n\t\t\t\t\t// Loop the selected buttons.\n\t\t\t\t\tbuttons.map( ( attributes ) =>\n\t\t\t\t\t\t// Create singular button in the buttons block.\n\t\t\t\t\t\tcreateBlock( 'core/button', attributes )\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tisMultiBlock: true,\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( buttons ) =>\n\t\t\t\t// Creates the buttons block.\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/buttons',\n\t\t\t\t\t{},\n\t\t\t\t\t// Loop the selected buttons.\n\t\t\t\t\tbuttons.map( ( attributes ) => {\n\t\t\t\t\t\tconst { content } = attributes;\n\t\t\t\t\t\tconst element = createElement( document, content );\n\t\t\t\t\t\t// Remove any HTML tags.\n\t\t\t\t\t\tconst text = element.innerText || '';\n\t\t\t\t\t\t// Get first url.\n\t\t\t\t\t\tconst link = element.querySelector( 'a' );\n\t\t\t\t\t\tconst url = link?.getAttribute( 'href' );\n\t\t\t\t\t\t// Create singular button in the buttons block.\n\t\t\t\t\t\treturn createBlock( 'core/button', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\t...getTransformedAttributes(\n\t\t\t\t\t\t\t\tattributes,\n\t\t\t\t\t\t\t\t'core/button',\n\t\t\t\t\t\t\t\t( { content: contentBinding } ) => ( {\n\t\t\t\t\t\t\t\t\ttext: contentBinding,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} )\n\t\t\t\t),\n\t\t\tisMatch: ( paragraphs ) => {\n\t\t\t\treturn paragraphs.every( ( attributes ) => {\n\t\t\t\t\tconst element = createElement(\n\t\t\t\t\t\tdocument,\n\t\t\t\t\t\tattributes.content\n\t\t\t\t\t);\n\t\t\t\t\tconst text = element.innerText || '';\n\t\t\t\t\tconst links = element.querySelectorAll( 'a' );\n\t\t\t\t\treturn text.length <= 30 && links.length <= 1;\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],"mappings":";;;;AAIA,MAAM,aAAa,EAClB,MAAM,CACL;CACC,MAAM;CACN,cAAc;CACd,QAAQ,CAAE,aAAc;CACxB,YAAa,YAEZ,YACC,gBACA,CAAC,GAED,QAAQ,KAAO,eAEd,YAAa,eAAe,UAAW,CACxC,CACD;AACF,GACA;CACC,MAAM;CACN,cAAc;CACd,QAAQ,CAAE,gBAAiB;CAC3B,YAAa,YAEZ,YACC,gBACA,CAAC,GAED,QAAQ,KAAO,eAAgB;EAC9B,MAAM,EAAE,YAAY;EACpB,MAAM,UAAUA,wBAAe,UAAU,OAAQ;EAEjD,MAAM,OAAO,QAAQ,aAAa;EAGlC,MAAM,MADO,QAAQ,cAAe,GACrB,CAAC,EAAE,aAAc,MAAO;EAEvC,OAAO,YAAa,eAAe;GAClC,GAAG;GACH,GAAG,yBACF,YACA,gBACE,EAAE,SAAS,sBAAwB,EACpC,MAAM,eACP,EACD;GACA;GACA;EACD,CAAE;CACH,CAAE,CACH;CACD,UAAW,eAAgB;EAC1B,OAAO,WAAW,OAAS,eAAgB;GAC1C,MAAM,UAAUA,wBACf,UACA,WAAW,OACZ;GACA,MAAM,OAAO,QAAQ,aAAa;GAClC,MAAM,QAAQ,QAAQ,iBAAkB,GAAI;GAC5C,OAAO,KAAK,UAAU,MAAM,MAAM,UAAU;EAC7C,CAAE;CACH;AACD,CACD,EACD"}