@wordpress/blocks
Version:
Block API for WordPress.
8 lines (7 loc) • 2.96 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/api/categories.ts"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blocksStore } from '../store';\nimport type { BlockCategory } from '../types';\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 Block categories.\n */\nexport function getCategories(): BlockCategory[] {\n\treturn select( blocksStore ).getCategories();\n}\n\n/**\n * Sets the block categories.\n *\n * @param 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: BlockCategory[] ): void {\n\tdispatch( blocksStore ).setCategories( categories );\n}\n\n/**\n * Updates a category.\n *\n * @param slug Block category slug.\n * @param 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(\n\tslug: string,\n\tcategory: Partial< BlockCategory >\n): void {\n\tdispatch( blocksStore ).updateCategory( slug, category );\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiC;AAKjC,mBAAqC;AAW9B,SAAS,gBAAiC;AAChD,aAAO,oBAAQ,aAAAA,KAAY,EAAE,cAAc;AAC5C;AAqCO,SAAS,cAAe,YAAoC;AAClE,4BAAU,aAAAA,KAAY,EAAE,cAAe,UAAW;AACnD;AA4BO,SAAS,eACf,MACA,UACO;AACP,4BAAU,aAAAA,KAAY,EAAE,eAAgB,MAAM,QAAS;AACxD;",
"names": ["blocksStore"]
}