UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 1.78 kB
{ "version": 3, "sources": ["../../../src/components/inserter/get-appender-label.js"], "sourcesContent": ["/**\n * Returns the appender label for a default block if available.\n *\n * This function calls the block's __experimentalLabel function with the 'appender'\n * context to get a custom label for the inserter button. The block should return\n * the full display label (e.g., \"Add page\") \u2014 consistent with how __experimentalLabel\n * works in other contexts like 'list-view'. The inserter uses the result directly\n * without reformatting.\n *\n * @param {Object} defaultBlock The default block configuration with name and attributes.\n * @param {Object} defaultBlockType The block type object containing __experimentalLabel.\n * @return {string|null} The full appender label, or null if not available.\n */\nconst MAX_APPENDER_LABEL_LENGTH = 50;\n\nexport function getAppenderLabel( defaultBlock, defaultBlockType ) {\n\tif (\n\t\t! defaultBlock ||\n\t\t! defaultBlock.attributes ||\n\t\t! defaultBlockType?.__experimentalLabel\n\t) {\n\t\treturn null;\n\t}\n\n\tconst result = defaultBlockType.__experimentalLabel(\n\t\tdefaultBlock.attributes,\n\t\t{ context: 'appender' }\n\t);\n\n\t// Only use if it's a string and not too long (safety check)\n\tif (\n\t\ttypeof result === 'string' &&\n\t\tresult.length < MAX_APPENDER_LABEL_LENGTH &&\n\t\tresult.length > 0\n\t) {\n\t\treturn result;\n\t}\n\n\treturn null;\n}\n"], "mappings": ";AAaA,IAAM,4BAA4B;AAE3B,SAAS,iBAAkB,cAAc,kBAAmB;AAClE,MACC,CAAE,gBACF,CAAE,aAAa,cACf,CAAE,kBAAkB,qBACnB;AACD,WAAO;AAAA,EACR;AAEA,QAAM,SAAS,iBAAiB;AAAA,IAC/B,aAAa;AAAA,IACb,EAAE,SAAS,WAAW;AAAA,EACvB;AAGA,MACC,OAAO,WAAW,YAClB,OAAO,SAAS,6BAChB,OAAO,SAAS,GACf;AACD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;", "names": [] }