@wordpress/block-editor
Version:
8 lines (7 loc) • 1.51 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/utils/order-inserter-block-items.js"],
"sourcesContent": ["/** @typedef {import('../store/selectors').WPEditorInserterItem} WPEditorInserterItem */\n\n/**\n * Helper function to order inserter block items according to a provided array of prioritized blocks.\n *\n * @param {WPEditorInserterItem[]} items The array of editor inserter block items to be sorted.\n * @param {string[]} priority The array of block names to be prioritized.\n * @return {WPEditorInserterItem[]} The sorted array of editor inserter block items.\n */\nexport const orderInserterBlockItems = ( items, priority ) => {\n\tif ( ! priority ) {\n\t\treturn items;\n\t}\n\n\titems.sort( ( { id: aName }, { id: bName } ) => {\n\t\t// Sort block items according to `priority`.\n\t\tlet aIndex = priority.indexOf( aName );\n\t\tlet bIndex = priority.indexOf( bName );\n\t\t// All other block items should come after that.\n\t\tif ( aIndex < 0 ) {\n\t\t\taIndex = priority.length;\n\t\t}\n\t\tif ( bIndex < 0 ) {\n\t\t\tbIndex = priority.length;\n\t\t}\n\t\treturn aIndex - bIndex;\n\t} );\n\n\treturn items;\n};\n"],
"mappings": ";AASO,IAAM,0BAA0B,CAAE,OAAO,aAAc;AAC7D,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,QAAM,KAAM,CAAE,EAAE,IAAI,MAAM,GAAG,EAAE,IAAI,MAAM,MAAO;AAE/C,QAAI,SAAS,SAAS,QAAS,KAAM;AACrC,QAAI,SAAS,SAAS,QAAS,KAAM;AAErC,QAAK,SAAS,GAAI;AACjB,eAAS,SAAS;AAAA,IACnB;AACA,QAAK,SAAS,GAAI;AACjB,eAAS,SAAS;AAAA,IACnB;AACA,WAAO,SAAS;AAAA,EACjB,CAAE;AAEF,SAAO;AACR;",
"names": []
}