{
  "version": 3,
  "sources": ["../../../src/components/provider/use-hide-blocks-from-inserter.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { addFilter, removeFilter } from '@wordpress/hooks';\n\n// These post types are \"structural\" block lists.\n// We should be allowed to use\n// the post content and template parts blocks within them.\nconst POST_TYPES_ALLOWING_POST_CONTENT_TEMPLATE_PART = [\n\t'wp_block',\n\t'wp_template',\n\t'wp_template_part',\n];\n\n/**\n * In some specific contexts,\n * the template part and post content blocks need to be hidden.\n *\n * @param {string} postType Post Type\n * @param {string} mode     Rendering mode\n */\nexport function useHideBlocksFromInserter( postType, mode ) {\n\tuseEffect( () => {\n\t\t/*\n\t\t * Prevent adding template part in the editor.\n\t\t */\n\t\taddFilter(\n\t\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t\t'removeTemplatePartsFromInserter',\n\t\t\t( canInsert, blockType ) => {\n\t\t\t\tif (\n\t\t\t\t\t! POST_TYPES_ALLOWING_POST_CONTENT_TEMPLATE_PART.includes(\n\t\t\t\t\t\tpostType\n\t\t\t\t\t) &&\n\t\t\t\t\tblockType.name === 'core/template-part' &&\n\t\t\t\t\tmode === 'post-only'\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn canInsert;\n\t\t\t}\n\t\t);\n\n\t\t/*\n\t\t * Prevent adding post content block (except in query block) in the editor.\n\t\t */\n\t\taddFilter(\n\t\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t\t'removePostContentFromInserter',\n\t\t\t(\n\t\t\t\tcanInsert,\n\t\t\t\tblockType,\n\t\t\t\trootClientId,\n\t\t\t\t{ getBlockParentsByBlockName }\n\t\t\t) => {\n\t\t\t\tif (\n\t\t\t\t\t! POST_TYPES_ALLOWING_POST_CONTENT_TEMPLATE_PART.includes(\n\t\t\t\t\t\tpostType\n\t\t\t\t\t) &&\n\t\t\t\t\tblockType.name === 'core/post-content'\n\t\t\t\t) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tgetBlockParentsByBlockName( rootClientId, 'core/query' )\n\t\t\t\t\t\t\t.length > 0\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn canInsert;\n\t\t\t}\n\t\t);\n\n\t\treturn () => {\n\t\t\tremoveFilter(\n\t\t\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t\t\t'removeTemplatePartsFromInserter'\n\t\t\t);\n\t\t\tremoveFilter(\n\t\t\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t\t\t'removePostContentFromInserter'\n\t\t\t);\n\t\t};\n\t}, [ postType, mode ] );\n}\n"],
  "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,WAAW,oBAAoB;AAKxC,IAAM,iDAAiD;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AACD;AASO,SAAS,0BAA2B,UAAU,MAAO;AAC3D,YAAW,MAAM;AAIhB;AAAA,MACC;AAAA,MACA;AAAA,MACA,CAAE,WAAW,cAAe;AAC3B,YACC,CAAE,+CAA+C;AAAA,UAChD;AAAA,QACD,KACA,UAAU,SAAS,wBACnB,SAAS,aACR;AACD,iBAAO;AAAA,QACR;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAKA;AAAA,MACC;AAAA,MACA;AAAA,MACA,CACC,WACA,WACA,cACA,EAAE,2BAA2B,MACzB;AACJ,YACC,CAAE,+CAA+C;AAAA,UAChD;AAAA,QACD,KACA,UAAU,SAAS,qBAClB;AACD,iBACC,2BAA4B,cAAc,YAAa,EACrD,SAAS;AAAA,QAEb;AACA,eAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO,MAAM;AACZ;AAAA,QACC;AAAA,QACA;AAAA,MACD;AACA;AAAA,QACC;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,UAAU,IAAK,CAAE;AACvB;",
  "names": []
}
