@wordpress/blocks
Version:
Block API for WordPress.
86 lines (80 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addBlockBindingsSource = addBlockBindingsSource;
exports.addBootstrappedBlockType = addBootstrappedBlockType;
exports.addUnprocessedBlockType = addUnprocessedBlockType;
exports.removeBlockBindingsSource = removeBlockBindingsSource;
var _processBlockType = require("./process-block-type");
/**
* Internal dependencies
*/
/** @typedef {import('../api/registration').WPBlockType} WPBlockType */
/**
* Add bootstrapped block type metadata to the store. These metadata usually come from
* the `block.json` file and are either statically bootstrapped from the server, or
* passed as the `metadata` parameter to the `registerBlockType` function.
*
* @param {string} name Block name.
* @param {WPBlockType} blockType Block type metadata.
*/
function addBootstrappedBlockType(name, blockType) {
return {
type: 'ADD_BOOTSTRAPPED_BLOCK_TYPE',
name,
blockType
};
}
/**
* Add unprocessed block type settings to the store. These data are passed as the
* `settings` parameter to the client-side `registerBlockType` function.
*
* @param {string} name Block name.
* @param {WPBlockType} blockType Unprocessed block type settings.
*/
function addUnprocessedBlockType(name, blockType) {
return ({
dispatch
}) => {
dispatch({
type: 'ADD_UNPROCESSED_BLOCK_TYPE',
name,
blockType
});
const processedBlockType = dispatch((0, _processBlockType.processBlockType)(name, blockType));
if (!processedBlockType) {
return;
}
dispatch.addBlockTypes(processedBlockType);
};
}
/**
* Adds new block bindings source.
*
* @param {string} source Name of the source to register.
*/
function addBlockBindingsSource(source) {
return {
type: 'ADD_BLOCK_BINDINGS_SOURCE',
name: source.name,
label: source.label,
usesContext: source.usesContext,
getValues: source.getValues,
setValues: source.setValues,
canUserEditValue: source.canUserEditValue,
getFieldsList: source.getFieldsList
};
}
/**
* Removes existing block bindings source.
*
* @param {string} name Name of the source to remove.
*/
function removeBlockBindingsSource(name) {
return {
type: 'REMOVE_BLOCK_BINDINGS_SOURCE',
name
};
}
//# sourceMappingURL=private-actions.js.map