@wordpress/block-library
Version:
Block library for the WordPress editor.
35 lines (34 loc) • 1.45 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// packages/block-library/src/navigation/edit/are-blocks-dirty.js
function areBlocksDirty(originalBlocks, blocks) {
return !isDeepEqual(originalBlocks, blocks, (prop, x) => {
if (x?.name === "core/page-list" && prop === "innerBlocks") return true;
});
}
/**
* Conditionally compares two candidates for deep equality.
* Provides an option to skip a given property of an object during comparison.
*
* @param {*} x 1st candidate for comparison
* @param {*} y 2nd candidate for comparison
* @param {Function|undefined} shouldSkip a function which can be used to skip a given property of an object.
* @return {boolean} whether the two candidates are deeply equal.
*/
const isDeepEqual = (x, y, shouldSkip) => {
if (x === y) return true;
else if (typeof x === "object" && x !== null && x !== void 0 && typeof y === "object" && y !== null && y !== void 0) {
if (Object.keys(x).length !== Object.keys(y).length) return false;
for (const prop in x) if (y.hasOwnProperty(prop)) {
if (shouldSkip && shouldSkip(prop, x)) return true;
if (!isDeepEqual(x[prop], y[prop], shouldSkip)) return false;
} else return false;
return true;
}
return false;
};
exports.areBlocksDirty = areBlocksDirty;
//# sourceMappingURL=are-blocks-dirty.cjs.map