Fail if settings elementType isnt supported + concept for inner-blocks + debounce for storage update

This commit is contained in:
Niels Lyngsø
2020-10-23 15:08:27 +02:00
parent 99e2990d07
commit cb902c4e08
2 changed files with 37 additions and 5 deletions

View File

@@ -791,7 +791,15 @@
return null;
}
var blockConfiguration;
if (blockData.data) {
// Ensure that we support the alias:
blockConfiguration = this.getBlockConfiguration(blockData.data.contentTypeKey);
if(blockConfiguration === null) {
return null;
}
this.value.contentData.push(blockData.data);
} else {
// We do not have data, this cannot be succesful paste.
@@ -799,7 +807,19 @@
}
if (blockData.settingsData) {
this.value.settingsData.push(blockData.settingsData);
// Ensure that we support the alias:
if(blockConfiguration.settingsElementTypeKey) {
// If we have settings for this Block Configuration, we need to check that they align, if we dont we do not want to fail.
if(blockConfiguration.settingsElementTypeKey === blockData.settingsData.contentTypeKey) {
this.value.settingsData.push(blockData.settingsData);
} else {
// Settings ElementType does not align, so we will fail.
return null;
}
} else {
// We do not have settings currently, so lets get rid of the settings part and move on with the paste.
delete layoutEntry.settingUdi;
}
}
return layoutEntry;

View File

@@ -52,6 +52,18 @@ function clipboardService($window, notificationsService, eventsService, localSto
propMethod(block.settingsData[key], TYPES.RAW);
});
}
/*
// Concept for supporting Block that contains other Blocks.
// Missing clearifications:
// How do we ensure that the inner blocks of a block is supported in the new scenario. Not that likely but still relevant, so conciderations should be made.
if(block.references) {
// A Block clipboard entry can contain other Block Clipboard Entries, here we will make sure to resolve those identical to the main entry.
for (var r = 0; r < block.references.length; r++) {
clipboardTypeResolvers[TYPES.BLOCK](block.references[r], propMethod);
}
}
*/
}
clipboardTypeResolvers[TYPES.RAW] = function(data, propMethod) {
for (var p = 0; p < data.length; p++) {
@@ -453,12 +465,12 @@ function clipboardService($window, notificationsService, eventsService, localSto
};
var emitClipboardStorageUpdate = _.debounce(function(e) {
eventsService.emit("clipboardService.storageUpdate");
}, 1000);
// Fires if LocalStorage was changed from another tab than this one.
$window.addEventListener("storage", localStorageChanged);
function localStorageChanged() {
eventsService.emit("clipboardService.storageUpdate");
}
$window.addEventListener("storage", emitClipboardStorageUpdate);