UNPKG

@wordpress/block-editor

Version:
66 lines (57 loc) 1.84 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = BlockEdit; Object.defineProperty(exports, "useBlockEditContext", { enumerable: true, get: function () { return _context.useBlockEditContext; } }); var _element = require("@wordpress/element"); var _blocks = require("@wordpress/blocks"); var _edit = _interopRequireDefault(require("./edit")); var _context = require("./context"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * The `useBlockEditContext` hook provides information about the block this hook is being used in. * It returns an object with the `name`, `isSelected` state, and the `clientId` of the block. * It is useful if you want to create custom hooks that need access to the current blocks clientId * but don't want to rely on the data getting passed in as a parameter. * * @return {Object} Block edit context */ function BlockEdit(props) { const { name, isSelected, clientId, attributes = {}, __unstableLayoutClassNames } = props; const { layout = null } = attributes; const layoutSupport = (0, _blocks.hasBlockSupport)(name, '__experimentalLayout', false); const context = { name, isSelected, clientId, layout: layoutSupport ? layout : null, __unstableLayoutClassNames }; return (0, _element.createElement)(_context.BlockEditContextProvider // It is important to return the same object if props haven't // changed to avoid unnecessary rerenders. // See https://reactjs.org/docs/context.html#caveats. , { value: (0, _element.useMemo)(() => context, Object.values(context)) }, (0, _element.createElement)(_edit.default, props)); } //# sourceMappingURL=index.js.map