Ok, I found the solution by myself. Inside withSelect
it is needed to assign default value if getEditedPostAttribute
is empty.
// Helper function to check if received meta object is empty or not
function isEmpty(obj) {
for(var key in obj) {
if(obj.hasOwnProperty(key))
return false;
}
return true;
}
PhotoControl = withSelect(
(select) => {
let myFocal = select('core/editor').getEditedPostAttribute('meta')['focalPoint'];
if(isEmpty(myFocal)) { focal={ "x": 0.5, "y": 0.5 }; } // Solution is here. If is empty object assign default values.
return {
img: select('core/editor').getEditedPostAttribute('meta')['img'],
focalPoint: myFocal
}
}
)(PhotoControl);