diff --git a/editors/demo/src/Editoria/config/config.js b/editors/demo/src/Editoria/config/config.js index 332bad0418d997014e9678510d312e33c3061b01..0cce640a9b8b1f83b0098e34d6a0349a190ab62d 100644 --- a/editors/demo/src/Editoria/config/config.js +++ b/editors/demo/src/Editoria/config/config.js @@ -44,6 +44,7 @@ import { CustomTagBlockToolGroupService, CustomTagService, YjsService, + disallowPasteImagesPlugin, } from 'wax-prosemirror-services'; import { EditoriaSchema } from 'wax-prosemirror-core'; @@ -72,6 +73,10 @@ const updateTrackStatus = status => { // console.log('status', status); }; +const onWarning = message => { + console.log(message); +}; + export default { MenuService: [ { @@ -140,7 +145,16 @@ export default { reject: true, }, }, - PmPlugins: [columnResizing(), tableEditing(), invisibles([hardBreak()])], + PmPlugins: [ + columnResizing(), + tableEditing(), + invisibles([hardBreak()]), + disallowPasteImagesPlugin(() => + onWarning( + 'Images are not allowed. Please upload them through filemanager', + ), + ), + ], ImageService: { showAlt: true }, CustomTagService: { tags: [ diff --git a/wax-prosemirror-services/index.js b/wax-prosemirror-services/index.js index f58d39841de99d028fcd65b3eaf3f57e7d52f012..e413c6e6ad8de85cc606246d4baa92c0eab4d3db 100644 --- a/wax-prosemirror-services/index.js +++ b/wax-prosemirror-services/index.js @@ -68,3 +68,7 @@ export { default as QuestionsDropDownToolGroupService } from './src/WaxToolGroup export { default as OENContainersToolGroupService } from './src/WaxToolGroups/OENContainersToolGroupService/OENContainersToolGroupService'; export { default as OENLeftToolGroupService } from './src/WaxToolGroups/OENLeftToolGroupService/OENLeftToolGroupService'; export { default as FindAndReplaceToolGroupService } from './src/WaxToolGroups/FindAndReplaceToolGroupService/FindAndReplaceToolGroupService'; + +/* Plugins */ + +export { default as disallowPasteImagesPlugin } from './src/ImageService/plugins/disallowPasteImagesPlugin'; diff --git a/wax-prosemirror-services/src/ImageService/ImageService.js b/wax-prosemirror-services/src/ImageService/ImageService.js index e23e55aacb3daff37a58d3eef73a286c3a6b3548..f24ac92000a4a45c8f5cc12618cbfaa9dd4d8dba 100644 --- a/wax-prosemirror-services/src/ImageService/ImageService.js +++ b/wax-prosemirror-services/src/ImageService/ImageService.js @@ -2,6 +2,7 @@ import { Service } from 'wax-prosemirror-core'; import { imageNode, figureCaptionNode, figureNode } from './schema'; import PlaceHolderPlugin from './plugins/placeHolderPlugin'; import captionPlugin from './plugins/captionPlugin'; +import disallowPasteImagesPlugin from './plugins/disallowPasteImagesPlugin'; import Image from './Image'; import './image.css'; import AltComponent from './AltComponent'; @@ -10,6 +11,11 @@ class ImageService extends Service { name = 'ImageService'; boot() { + // this.app.PmPlugins.add( + // 'disallowPasteImagesPlugin', + // disallowPasteImagesPlugin('disallowPasteImagesPlugin', this.app.context), + // ); + this.app.PmPlugins.add( 'imagePlaceHolder', PlaceHolderPlugin('imagePlaceHolder'), diff --git a/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js b/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js new file mode 100644 index 0000000000000000000000000000000000000000..bc562c059eefd2571eb5c0b5af9754da7600274d --- /dev/null +++ b/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js @@ -0,0 +1,33 @@ +/* eslint-disable no-param-reassign */ +import { Plugin, PluginKey } from 'prosemirror-state'; + +const disallowPasteImagesPlugin = new PluginKey('disallowPasteImagesPlugin'); + +export default onWarning => { + return new Plugin({ + key: disallowPasteImagesPlugin, + props: { + transformPasted: slice => { + const { + content: { content }, + } = slice; + + let imageFound = false; + content.forEach(node => { + if (node.type.name === 'image') { + node.attrs.src = ''; + node.attrs.alt = ''; + imageFound = true; + } + if (node.type.name === 'figure') { + node.lastChild.attrs.src = ''; + node.lastChild.attrs.alt = ''; + imageFound = true; + } + }); + if (imageFound) onWarning(); + return slice; + }, + }, + }); +};