@wordpress/block-editor
Version:
51 lines (47 loc) • 1.76 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Edit = void 0;
var _components = require("@wordpress/components");
var _blocks = require("@wordpress/blocks");
var _element = require("@wordpress/element");
var _blockContext = _interopRequireDefault(require("../block-context"));
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Default value used for blocks which do not define their own context needs,
* used to guarantee that a block's `context` prop will always be an object. It
* is assigned as a constant since it is always expected to be an empty object,
* and in order to avoid unnecessary React reconciliations of a changing object.
*
* @type {{}}
*/const DEFAULT_BLOCK_CONTEXT = {};
const Edit = props => {
const {
name
} = props;
const blockType = (0, _blocks.getBlockType)(name);
const blockContext = (0, _element.useContext)(_blockContext.default);
// Assign context values using the block type's declared context needs.
const context = (0, _element.useMemo)(() => {
return blockType && blockType.usesContext ? Object.fromEntries(Object.entries(blockContext).filter(([key]) => blockType.usesContext.includes(key))) : DEFAULT_BLOCK_CONTEXT;
}, [blockType, blockContext]);
if (!blockType) {
return null;
}
const Component = blockType.edit;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
...props,
context: context
});
};
exports.Edit = Edit;
var _default = exports.default = (0, _components.withFilters)('editor.BlockEdit')(Edit);
//# sourceMappingURL=edit.native.js.map