Skip to content

Commit 756ae7f

Browse files
committed
Merge pull request #2912 from microsoft/u/juliaroldi/remove-dataset
Remove Image dataset
1 parent 683c902 commit 756ae7f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/roosterjs-content-model-plugins/lib/imageEdit/ImageEditPlugin.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,24 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
174174
this.onDropHandler(this.editor);
175175
}
176176
break;
177+
case 'extractContentWithDom':
178+
this.removeImageEditing(event.clonedRoot);
179+
break;
177180
}
178181
}
179182

183+
private removeImageEditing(clonedRoot: HTMLElement) {
184+
const images = clonedRoot.querySelectorAll('img');
185+
images.forEach(image => {
186+
if (image.dataset.isEditing) {
187+
delete image.dataset.isEditing;
188+
}
189+
if (image.dataset.editingInfo) {
190+
delete image.dataset.editingInfo;
191+
}
192+
});
193+
}
194+
180195
private isImageSelection(target: Node): target is HTMLElement {
181196
return (
182197
isNodeOfType(target, 'ELEMENT_NODE') &&

packages/roosterjs-content-model-plugins/test/imageEdit/ImageEditPluginTest.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,28 @@ describe('ImageEditPlugin', () => {
648648
expect(editor.setEditorStyle).toHaveBeenCalledWith('imageEdit', null);
649649
expect(editor.setEditorStyle).toHaveBeenCalledWith('imageEditCaretColor', null);
650650
});
651+
652+
it('extractContentWithDom', () => {
653+
const plugin = new ImageEditPlugin();
654+
plugin.initialize(editor);
655+
const clonedRoot = document.createElement('div');
656+
const image = document.createElement('img');
657+
clonedRoot.appendChild(image);
658+
image.dataset['editingInfo'] = JSON.stringify({
659+
src: 'test',
660+
});
661+
image.dataset['isEditing'] = 'true';
662+
const event = {
663+
eventType: 'extractContentWithDom',
664+
clonedRoot,
665+
} as any;
666+
plugin.onPluginEvent(event);
667+
const expectedClonedRoot = document.createElement('div');
668+
const expectedImage = document.createElement('img');
669+
expectedClonedRoot.appendChild(expectedImage);
670+
expect(event.clonedRoot).toEqual(expectedClonedRoot);
671+
plugin.dispose();
672+
});
651673
});
652674

653675
class TestPlugin extends ImageEditPlugin {

0 commit comments

Comments
 (0)