Skip to content

Commit

Permalink
Merge pull request #2912 from microsoft/u/juliaroldi/remove-dataset
Browse files Browse the repository at this point in the history
Remove Image dataset
  • Loading branch information
juliaroldi authored Dec 16, 2024
2 parents ffc58bf + d78bba2 commit 5024d9a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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') &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5024d9a

Please sign in to comment.