UNPKG

@wordpress/block-library

Version:
36 lines (31 loc) 1.3 kB
import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { useSelect, useDispatch } from '@wordpress/data'; import { useEffect } from '@wordpress/element'; import { store as blockEditorStore, useBlockProps } from '@wordpress/block-editor'; const PatternEdit = _ref => { let { attributes, clientId } = _ref; const selectedPattern = useSelect(select => select(blockEditorStore).__experimentalGetParsedPattern(attributes.slug), [attributes.slug]); const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } = useDispatch(blockEditorStore); // 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. 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 = useBlockProps(); return createElement("div", props); }; export default PatternEdit; //# sourceMappingURL=edit.js.map