@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 3.89 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":["blocksPrivateApis"],"sources":["../../src/heading/index.js"],"sourcesContent":["import { heading as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tgetBlockType,\n\tunregisterBlockVariation,\n\tprivateApis as blocksPrivateApis,\n} from '@wordpress/blocks';\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\nimport { unlock } from '../lock-unlock';\n\nconst { editableRootKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\t// Opt into the editing host behaviour privately, like the paragraph.\n\t[ editableRootKey ]: true,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Code is Poetry' ),\n\t\t\tlevel: 2,\n\t\t\tstyle: {\n\t\t\t\ttypography: {\n\t\t\t\t\ttextAlign: 'center',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content, level } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasContent = content?.trim().length > 0;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasContent ) ) {\n\t\t\treturn customName || content;\n\t\t}\n\n\t\tif ( context === 'breadcrumb' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! hasContent\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: heading level. */\n\t\t\t\t\t\t__( 'Level %s. Empty.' ),\n\t\t\t\t\t\tlevel\n\t\t\t\t\t)\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. 1: heading level. 2: heading content. */\n\t\t\t\t\t\t__( 'Level %1$s. %2$s' ),\n\t\t\t\t\t\tlevel,\n\t\t\t\t\t\tcontent\n\t\t\t\t\t);\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n\tvariations,\n};\n\nexport const init = () => {\n\tconst block = initBlock( { name, metadata, settings } );\n\n\t// Unregister heading level variations based on `levelOptions` attribute.\n\t// This is for backwards compatibility, as extenders can now unregister the\n\t// variation directly: `wp.blocks.unregisterBlockVariation( 'core/heading', 'h1' )`.\n\tconst levelOptions =\n\t\tgetBlockType( name )?.attributes?.levelOptions?.default;\n\tif ( levelOptions ) {\n\t\t[ 1, 2, 3, 4, 5, 6 ].forEach( ( level ) => {\n\t\t\tif ( ! levelOptions.includes( level ) ) {\n\t\t\t\tunregisterBlockVariation( name, `h${ level }` );\n\t\t\t}\n\t\t} );\n\t}\n\n\treturn block;\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,EAAE,oBAAoB,OAAQA,WAAkB;AAEtD,MAAM,EAAE,SAAS;AAIjB,MAAa,WAAW;CACvB,MAAA;EAEE,kBAAmB;CACrB,SAAS,EACR,YAAY;EACX,SAAS,GAAI,gBAAiB;EAC9B,OAAO;EACP,OAAO,EACN,YAAY,EACX,WAAW,SACZ,EACD;CACD,EACD;CACA,oBAAqB,YAAY,EAAE,WAAY;EAC9C,MAAM,EAAE,SAAS,UAAU;EAE3B,MAAM,aAAa,YAAY,UAAU;EACzC,MAAM,aAAa,SAAS,KAAK,CAAC,CAAC,SAAS;EAI5C,IAAK,YAAY,gBAAiB,cAAc,aAC/C,OAAO,cAAc;EAGtB,IAAK,YAAY,gBAAgB,YAChC,OAAO;EAGR,IAAK,YAAY,iBAChB,OAAO,CAAE,aACN,QAEA,GAAI,kBAAmB,GACvB,KACD,IACC,QAEA,GAAI,kBAAmB,GACvB,OACA,OACD;CAEJ;CACA;CACA;CACA,MAAO,YAAY,mBAAoB;EACtC,OAAO,EACN,UACG,WAAW,WAAW,OACtB,kBAAkB,WAAW,IACjC;CACD;CACA;CACA;CACA;AACD;AAEA,MAAa,aAAa;CACzB,MAAM,QAAQ,UAAW;EAAE;EAAM;EAAU;CAAS,CAAE;CAKtD,MAAM,eACL,aAAc,IAAK,CAAC,EAAE,YAAY,cAAc;CACjD,IAAK,cACJ;EAAE;EAAG;EAAG;EAAG;EAAG;EAAG;CAAE,CAAC,CAAC,SAAW,UAAW;EAC1C,IAAK,CAAE,aAAa,SAAU,KAAM,GACnC,yBAA0B,MAAM,IAAK,OAAS;CAEhD,CAAE;CAGH,OAAO;AACR"}