UNPKG

@gechiui/block-editor

Version:
42 lines (36 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.__experimentalGetMatchingVariation = void 0; var _lodash = require("lodash"); /** * External dependencies */ /** @typedef {import('@gechiui/blocks').GCBlockVariation} GCBlockVariation */ /** * Matches the provided block variations with a block's attributes. If no match * or more than one matches are found it returns `undefined`. If a single match is * found it returns it. * * This is a simple implementation for now as it takes into account only the attributes * of a block variation and not `InnerBlocks`. * * @param {Object} blockAttributes - The block attributes to try to find a match. * @param {GCBlockVariation[]} variations - A list of block variations to test for a match. * @return {?GCBlockVariation} - If a match is found returns it. If not or more than one matches are found returns `undefined`. */ const __experimentalGetMatchingVariation = (blockAttributes, variations) => { if (!variations || !blockAttributes) return; const matches = variations.filter(_ref => { let { attributes } = _ref; if (!attributes || !Object.keys(attributes).length) return false; return (0, _lodash.isMatch)(blockAttributes, attributes); }); if (matches.length !== 1) return; return matches[0]; }; exports.__experimentalGetMatchingVariation = __experimentalGetMatchingVariation; //# sourceMappingURL=block-variation-transforms.js.map