UNPKG

@wordpress/block-library

Version:
44 lines (36 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _element = require("@wordpress/element"); var _data = require("@wordpress/data"); var _blockEditor = require("@wordpress/block-editor"); /** * WordPress dependencies */ const PatternEdit = _ref => { let { attributes, clientId } = _ref; const selectedPattern = (0, _data.useSelect)(select => select(_blockEditor.store).__experimentalGetParsedPattern(attributes.slug), [attributes.slug]); const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } = (0, _data.useDispatch)(_blockEditor.store); // Run this effect when the component loads. // This adds the Pattern's contents to the post. // This change won't be saved. // It will continue to pull from the pattern file unless changes are made to its respective template part. (0, _element.useEffect)(() => { if (selectedPattern !== null && selectedPattern !== void 0 && selectedPattern.blocks) { __unstableMarkNextChangeAsNotPersistent(); replaceBlocks(clientId, selectedPattern.blocks); } }, [selectedPattern === null || selectedPattern === void 0 ? void 0 : selectedPattern.blocks]); const props = (0, _blockEditor.useBlockProps)(); return (0, _element.createElement)("div", props); }; var _default = PatternEdit; exports.default = _default; //# sourceMappingURL=edit.js.map