@wordpress/blocks
Version:
Block API for WordPress.
8 lines (7 loc) • 11.4 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/store/actions.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { processBlockType } from './process-block-type';\n\n/** @typedef {import('../api/registration').WPBlockVariation} WPBlockVariation */\n/** @typedef {import('../api/registration').WPBlockType} WPBlockType */\n/** @typedef {import('./reducer').WPBlockCategory} WPBlockCategory */\n\n/**\n * Returns an action object used in signalling that block types have been added.\n * Ignored from documentation as the recommended usage for this action through registerBlockType from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {WPBlockType|WPBlockType[]} blockTypes Object or array of objects representing blocks to added.\n *\n *\n * @return {Object} Action object.\n */\nexport function addBlockTypes( blockTypes ) {\n\treturn {\n\t\ttype: 'ADD_BLOCK_TYPES',\n\t\tblockTypes: Array.isArray( blockTypes ) ? blockTypes : [ blockTypes ],\n\t};\n}\n\n/**\n * Signals that all block types should be computed again.\n * It uses stored unprocessed block types and all the most recent list of registered filters.\n *\n * It addresses the issue where third party block filters get registered after third party blocks. A sample sequence:\n * 1. Filter A.\n * 2. Block B.\n * 3. Block C.\n * 4. Filter D.\n * 5. Filter E.\n * 6. Block F.\n * 7. Filter G.\n * In this scenario some filters would not get applied for all blocks because they are registered too late.\n */\nexport function reapplyBlockTypeFilters() {\n\treturn ( { dispatch, select } ) => {\n\t\tconst processedBlockTypes = [];\n\t\tfor ( const [ name, settings ] of Object.entries(\n\t\t\tselect.getUnprocessedBlockTypes()\n\t\t) ) {\n\t\t\tconst result = dispatch( processBlockType( name, settings ) );\n\t\t\tif ( result ) {\n\t\t\t\tprocessedBlockTypes.push( result );\n\t\t\t}\n\t\t}\n\n\t\tif ( ! processedBlockTypes.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tdispatch.addBlockTypes( processedBlockTypes );\n\t};\n}\n\nexport function __experimentalReapplyBlockFilters() {\n\tdeprecated(\n\t\t'wp.data.dispatch( \"core/blocks\" ).__experimentalReapplyBlockFilters',\n\t\t{\n\t\t\tsince: '6.4',\n\t\t\talternative: 'reapplyBlockFilters',\n\t\t}\n\t);\n\n\treturn reapplyBlockTypeFilters();\n}\n\n/**\n * Returns an action object used to remove a registered block type.\n * Ignored from documentation as the recommended usage for this action through unregisterBlockType from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string|string[]} names Block name or array of block names to be removed.\n *\n *\n * @return {Object} Action object.\n */\nexport function removeBlockTypes( names ) {\n\treturn {\n\t\ttype: 'REMOVE_BLOCK_TYPES',\n\t\tnames: Array.isArray( names ) ? names : [ names ],\n\t};\n}\n\n/**\n * Returns an action object used in signalling that new block styles have been added.\n * Ignored from documentation as the recommended usage for this action through registerBlockStyle from @wordpress/blocks.\n *\n * @param {string|Array} blockNames Block names to register new styles for.\n * @param {Array|Object} styles Block style object or array of block style objects.\n *\n * @ignore\n *\n * @return {Object} Action object.\n */\nexport function addBlockStyles( blockNames, styles ) {\n\treturn {\n\t\ttype: 'ADD_BLOCK_STYLES',\n\t\tstyles: Array.isArray( styles ) ? styles : [ styles ],\n\t\tblockNames: Array.isArray( blockNames ) ? blockNames : [ blockNames ],\n\t};\n}\n\n/**\n * Returns an action object used in signalling that block styles have been removed.\n * Ignored from documentation as the recommended usage for this action through unregisterBlockStyle from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} blockName Block name.\n * @param {Array|string} styleNames Block style names or array of block style names.\n *\n * @return {Object} Action object.\n */\nexport function removeBlockStyles( blockName, styleNames ) {\n\treturn {\n\t\ttype: 'REMOVE_BLOCK_STYLES',\n\t\tstyleNames: Array.isArray( styleNames ) ? styleNames : [ styleNames ],\n\t\tblockName,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that new block variations have been added.\n * Ignored from documentation as the recommended usage for this action through registerBlockVariation from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} blockName Block name.\n * @param {WPBlockVariation|WPBlockVariation[]} variations Block variations.\n *\n * @return {Object} Action object.\n */\nexport function addBlockVariations( blockName, variations ) {\n\treturn {\n\t\ttype: 'ADD_BLOCK_VARIATIONS',\n\t\tvariations: Array.isArray( variations ) ? variations : [ variations ],\n\t\tblockName,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that block variations have been removed.\n * Ignored from documentation as the recommended usage for this action through unregisterBlockVariation from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} blockName Block name.\n * @param {string|string[]} variationNames Block variation names.\n *\n * @return {Object} Action object.\n */\nexport function removeBlockVariations( blockName, variationNames ) {\n\treturn {\n\t\ttype: 'REMOVE_BLOCK_VARIATIONS',\n\t\tvariationNames: Array.isArray( variationNames )\n\t\t\t? variationNames\n\t\t\t: [ variationNames ],\n\t\tblockName,\n\t};\n}\n\n/**\n * Returns an action object used to set the default block name.\n * Ignored from documentation as the recommended usage for this action through setDefaultBlockName from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} name Block name.\n *\n * @return {Object} Action object.\n */\nexport function setDefaultBlockName( name ) {\n\treturn {\n\t\ttype: 'SET_DEFAULT_BLOCK_NAME',\n\t\tname,\n\t};\n}\n\n/**\n * Returns an action object used to set the name of the block used as a fallback\n * for non-block content.\n * Ignored from documentation as the recommended usage for this action through setFreeformContentHandlerName from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} name Block name.\n *\n * @return {Object} Action object.\n */\nexport function setFreeformFallbackBlockName( name ) {\n\treturn {\n\t\ttype: 'SET_FREEFORM_FALLBACK_BLOCK_NAME',\n\t\tname,\n\t};\n}\n\n/**\n * Returns an action object used to set the name of the block used as a fallback\n * for unregistered blocks.\n * Ignored from documentation as the recommended usage for this action through setUnregisteredTypeHandlerName from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} name Block name.\n *\n * @return {Object} Action object.\n */\nexport function setUnregisteredFallbackBlockName( name ) {\n\treturn {\n\t\ttype: 'SET_UNREGISTERED_FALLBACK_BLOCK_NAME',\n\t\tname,\n\t};\n}\n\n/**\n * Returns an action object used to set the name of the block used\n * when grouping other blocks\n * eg: in \"Group/Ungroup\" interactions\n * Ignored from documentation as the recommended usage for this action through setGroupingBlockName from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} name Block name.\n *\n * @return {Object} Action object.\n */\nexport function setGroupingBlockName( name ) {\n\treturn {\n\t\ttype: 'SET_GROUPING_BLOCK_NAME',\n\t\tname,\n\t};\n}\n\n/**\n * Returns an action object used to set block categories.\n * Ignored from documentation as the recommended usage for this action through setCategories from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {WPBlockCategory[]} categories Block categories.\n *\n * @return {Object} Action object.\n */\nexport function setCategories( categories ) {\n\treturn {\n\t\ttype: 'SET_CATEGORIES',\n\t\tcategories,\n\t};\n}\n\n/**\n * Returns an action object used to update a category.\n * Ignored from documentation as the recommended usage for this action through updateCategory from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} slug Block category slug.\n * @param {Object} category Object containing the category properties that should be updated.\n *\n * @return {Object} Action object.\n */\nexport function updateCategory( slug, category ) {\n\treturn {\n\t\ttype: 'UPDATE_CATEGORY',\n\t\tslug,\n\t\tcategory,\n\t};\n}\n\n/**\n * Returns an action object used to add block collections\n * Ignored from documentation as the recommended usage for this action through registerBlockCollection from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} namespace The namespace of the blocks to put in the collection\n * @param {string} title The title to display in the block inserter\n * @param {Object} icon (optional) The icon to display in the block inserter\n *\n * @return {Object} Action object.\n */\nexport function addBlockCollection( namespace, title, icon ) {\n\treturn {\n\t\ttype: 'ADD_BLOCK_COLLECTION',\n\t\tnamespace,\n\t\ttitle,\n\t\ticon,\n\t};\n}\n\n/**\n * Returns an action object used to remove block collections\n * Ignored from documentation as the recommended usage for this action through unregisterBlockCollection from @wordpress/blocks.\n *\n * @ignore\n *\n * @param {string} namespace The namespace of the blocks to put in the collection\n *\n * @return {Object} Action object.\n */\nexport function removeBlockCollection( namespace ) {\n\treturn {\n\t\ttype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