@wordpress/block-library
Version:
Block library for the WordPress editor.
47 lines (46 loc) • 1.26 kB
JavaScript
// packages/block-library/src/form/index.js
import initBlock from "../utils/init-block";
import edit from "./edit";
import metadata from "./block.json";
import save from "./save";
import variations from "./variations";
import deprecated from "./deprecated";
import { addFilter } from "@wordpress/hooks";
var { name } = metadata;
var settings = {
edit,
save,
deprecated,
variations,
example: {}
};
var init = () => {
const DISALLOWED_PARENTS = ["core/form"];
addFilter(
"blockEditor.__unstableCanInsertBlockType",
"core/block-library/preventInsertingFormIntoAnotherForm",
(canInsert, blockType, rootClientId, { getBlock, getBlockParentsByBlockName }) => {
if (blockType.name !== "core/form") {
return canInsert;
}
for (const disallowedParentType of DISALLOWED_PARENTS) {
const hasDisallowedParent = getBlock(rootClientId)?.name === disallowedParentType || getBlockParentsByBlockName(
rootClientId,
disallowedParentType
).length;
if (hasDisallowedParent) {
return false;
}
}
return true;
}
);
return initBlock({ name, metadata, settings });
};
export {
init,
metadata,
name,
settings
};
//# sourceMappingURL=index.js.map