@wordpress/blocks
Version:
Block API for WordPress.
8 lines (7 loc) • 2.93 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/api/categories.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blocksStore } from '../store';\n\n/** @typedef {import('../store/reducer').WPBlockCategory} WPBlockCategory */\n\n/**\n * Returns all the block categories.\n * Ignored from documentation as the recommended usage is via useSelect from @wordpress/data.\n *\n * @ignore\n *\n * @return {WPBlockCategory[]} Block categories.\n */\nexport function getCategories() {\n\treturn select( blocksStore ).getCategories();\n}\n\n/**\n * Sets the block categories.\n *\n * @param {WPBlockCategory[]} categories Block categories.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { store as blocksStore, setCategories } from '@wordpress/blocks';\n * import { useSelect } from '@wordpress/data';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * // Retrieve the list of current categories.\n * const blockCategories = useSelect(\n * ( select ) => select( blocksStore ).getCategories(),\n * []\n * );\n *\n * return (\n * <Button\n * onClick={ () => {\n * // Add a custom category to the existing list.\n * setCategories( [\n * ...blockCategories,\n * { title: 'Custom Category', slug: 'custom-category' },\n * ] );\n * } }\n * >\n * { __( 'Add a new custom block category' ) }\n * </Button>\n * );\n * };\n * ```\n */\nexport function setCategories( categories ) {\n\tdispatch( blocksStore ).setCategories( categories );\n}\n\n/**\n * Updates a category.\n *\n * @param {string} slug Block category slug.\n * @param {WPBlockCategory} category Object containing the category properties\n * that should be updated.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { updateCategory } from '@wordpress/blocks';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * return (\n * <Button\n * onClick={ () => {\n * updateCategory( 'text', { title: __( 'Written Word' ) } );\n * } }\n * >\n * { __( 'Update Text category title' ) }\n * </Button>\n * ) ;\n * };\n * ```\n */\nexport function updateCategory( slug, category ) {\n\tdispatch( blocksStore ).updateCategory( slug, category );\n}\n"],
"mappings": ";AAGA,SAAS,UAAU,cAAc;AAKjC,SAAS,SAAS,mBAAmB;AAY9B,SAAS,gBAAgB;AAC/B,SAAO,OAAQ,WAAY,EAAE,cAAc;AAC5C;AAqCO,SAAS,cAAe,YAAa;AAC3C,WAAU,WAAY,EAAE,cAAe,UAAW;AACnD;AA4BO,SAAS,eAAgB,MAAM,UAAW;AAChD,WAAU,WAAY,EAAE,eAAgB,MAAM,QAAS;AACxD;",
"names": []
}