diff --git a/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js b/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js index bc562c059eefd2571eb5c0b5af9754da7600274d..42f1adfeeaef7c4215dd9f19b3347382a56a5228 100644 --- a/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js +++ b/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js @@ -1,4 +1,5 @@ /* eslint-disable no-param-reassign */ +import { v4 as uuidv4 } from 'uuid'; import { Plugin, PluginKey } from 'prosemirror-state'; const disallowPasteImagesPlugin = new PluginKey('disallowPasteImagesPlugin'); @@ -15,14 +16,23 @@ export default onWarning => { let imageFound = false; content.forEach(node => { if (node.type.name === 'image') { + node.attrs.id = uuidv4(); node.attrs.src = ''; node.attrs.alt = ''; imageFound = true; } if (node.type.name === 'figure') { - node.lastChild.attrs.src = ''; - node.lastChild.attrs.alt = ''; - imageFound = true; + if (node.firstChild && node.firstChild.type.name === 'image') { + node.firstChild.attrs.id = uuidv4(); + node.firstChild.attrs.src = ''; + node.firstChild.attrs.alt = ''; + imageFound = true; + } else if (node.lastChild && node.lastChild.type.name === 'image') { + node.lastChild.attrs.id = uuidv4(); + node.lastChild.attrs.src = ''; + node.lastChild.attrs.alt = ''; + imageFound = true; + } } }); if (imageFound) onWarning();