@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 2.46 kB
Source Map (JSON)
{"version":3,"file":"are-blocks-dirty.mjs","names":[],"sources":["../../../src/navigation/edit/are-blocks-dirty.js"],"sourcesContent":["export function areBlocksDirty( originalBlocks, blocks ) {\n\treturn ! isDeepEqual( originalBlocks, blocks, ( prop, x ) => {\n\t\t// Skip inner blocks of page list during comparison as they\n\t\t// are **always** controlled and may be updated async due to\n\t\t// syncing with entity records. Left unchecked this would\n\t\t// inadvertently trigger the dirty state.\n\t\tif ( x?.name === 'core/page-list' && prop === 'innerBlocks' ) {\n\t\t\treturn true;\n\t\t}\n\t} );\n}\n\n/**\n * Conditionally compares two candidates for deep equality.\n * Provides an option to skip a given property of an object during comparison.\n *\n * @param {*} x 1st candidate for comparison\n * @param {*} y 2nd candidate for comparison\n * @param {Function|undefined} shouldSkip a function which can be used to skip a given property of an object.\n * @return {boolean} whether the two candidates are deeply equal.\n */\nconst isDeepEqual = ( x, y, shouldSkip ) => {\n\tif ( x === y ) {\n\t\treturn true;\n\t} else if (\n\t\ttypeof x === 'object' &&\n\t\tx !== null &&\n\t\tx !== undefined &&\n\t\ttypeof y === 'object' &&\n\t\ty !== null &&\n\t\ty !== undefined\n\t) {\n\t\tif ( Object.keys( x ).length !== Object.keys( y ).length ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor ( const prop in x ) {\n\t\t\tif ( y.hasOwnProperty( prop ) ) {\n\t\t\t\t// Afford skipping a given property of an object.\n\t\t\t\tif ( shouldSkip && shouldSkip( prop, x ) ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isDeepEqual( x[ prop ], y[ prop ], shouldSkip ) ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n"],"mappings":";AAAA,SAAgB,eAAgB,gBAAgB,QAAS;CACxD,OAAO,CAAE,YAAa,gBAAgB,SAAU,MAAM,MAAO;EAK5D,IAAK,GAAG,SAAS,oBAAoB,SAAS,eAC7C,OAAO;CAET,CAAE;AACH;;;;;;;;;;AAWA,MAAM,eAAgB,GAAG,GAAG,eAAgB;CAC3C,IAAK,MAAM,GACV,OAAO;MACD,IACN,OAAO,MAAM,YACb,MAAM,QACN,MAAM,KAAA,KACN,OAAO,MAAM,YACb,MAAM,QACN,MAAM,KAAA,GACL;EACD,IAAK,OAAO,KAAM,CAAE,CAAC,CAAC,WAAW,OAAO,KAAM,CAAE,CAAC,CAAC,QACjD,OAAO;EAGR,KAAM,MAAM,QAAQ,GACnB,IAAK,EAAE,eAAgB,IAAK,GAAI;GAE/B,IAAK,cAAc,WAAY,MAAM,CAAE,GACtC,OAAO;GAGR,IAAK,CAAE,YAAa,EAAG,OAAQ,EAAG,OAAQ,UAAW,GACpD,OAAO;EAET,OACC,OAAO;EAIT,OAAO;CACR;CAEA,OAAO;AACR"}