Skip to content

Commit 9f1ba11

Browse files
authored
Merge pull request #2919 from microsoft/u/juliaroldi/data-loss-cherry-pick
[Hot fix] Bump RoosterJS Plugins 9.16.1
2 parents 683c902 + ed1c954 commit 9f1ba11

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
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 {

versions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"react": "9.0.0",
33
"main": "9.16.0",
44
"legacyAdapter": "8.62.4",
5-
"overrides": {}
5+
"overrides": {
6+
"roosterjs-content-model-plugins": "9.16.1"
7+
}
68
}

0 commit comments

Comments
 (0)