diff --git a/packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts index ec6dfe6047f..2c14e9898dd 100644 --- a/packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts @@ -174,9 +174,24 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin { this.onDropHandler(this.editor); } break; + case 'extractContentWithDom': + this.removeImageEditing(event.clonedRoot); + break; } } + private removeImageEditing(clonedRoot: HTMLElement) { + const images = clonedRoot.querySelectorAll('img'); + images.forEach(image => { + if (image.dataset.isEditing) { + delete image.dataset.isEditing; + } + if (image.dataset.editingInfo) { + delete image.dataset.editingInfo; + } + }); + } + private isImageSelection(target: Node): target is HTMLElement { return ( isNodeOfType(target, 'ELEMENT_NODE') && diff --git a/packages/roosterjs-content-model-plugins/test/imageEdit/ImageEditPluginTest.ts b/packages/roosterjs-content-model-plugins/test/imageEdit/ImageEditPluginTest.ts index 9fa5393fe0d..1bc97e1075c 100644 --- a/packages/roosterjs-content-model-plugins/test/imageEdit/ImageEditPluginTest.ts +++ b/packages/roosterjs-content-model-plugins/test/imageEdit/ImageEditPluginTest.ts @@ -648,6 +648,28 @@ describe('ImageEditPlugin', () => { expect(editor.setEditorStyle).toHaveBeenCalledWith('imageEdit', null); expect(editor.setEditorStyle).toHaveBeenCalledWith('imageEditCaretColor', null); }); + + it('extractContentWithDom', () => { + const plugin = new ImageEditPlugin(); + plugin.initialize(editor); + const clonedRoot = document.createElement('div'); + const image = document.createElement('img'); + clonedRoot.appendChild(image); + image.dataset['editingInfo'] = JSON.stringify({ + src: 'test', + }); + image.dataset['isEditing'] = 'true'; + const event = { + eventType: 'extractContentWithDom', + clonedRoot, + } as any; + plugin.onPluginEvent(event); + const expectedClonedRoot = document.createElement('div'); + const expectedImage = document.createElement('img'); + expectedClonedRoot.appendChild(expectedImage); + expect(event.clonedRoot).toEqual(expectedClonedRoot); + plugin.dispose(); + }); }); class TestPlugin extends ImageEditPlugin {