Skip to content

Commit

Permalink
Merge branch 'master' into u/bvalverde/triggerBeforePasteOnPlaintext
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanValverdeU authored Dec 16, 2024
2 parents aa36a0b + 5024d9a commit 95b97c8
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 95b97c8

Please sign in to comment.