Skip to content

Commit

Permalink
remove data-istrue
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi committed Jan 28, 2025
1 parent 54c7dbe commit 4578669
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const MouseRightButton = 2;
const DRAG_ID = '_dragging';
const IMAGE_EDIT_CLASS = 'imageEdit';
const IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor';
const IMAGE_EDIT_DATASET = 'data-is-editing="true"';

/**
* ImageEdit plugin handles the following image editing features:
Expand Down Expand Up @@ -177,6 +178,9 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
case 'extractContentWithDom':
this.removeImageEditing(event.clonedRoot);
break;
case 'beforeSetContent':
this.beforeSetContentHandler(this.editor, event.newContent);
break;
}
}

Expand Down Expand Up @@ -279,6 +283,11 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
}
}

private beforeSetContentHandler(editor: IEditor, newContent: string) {
newContent.replace(IMAGE_EDIT_DATASET, '');
editor?.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
}

/**
* EXPOSED FOR TESTING PURPOSE ONLY
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,45 @@ describe('ImageEditPlugin', () => {
expect(event.clonedRoot).toEqual(expectedClonedRoot);
plugin.dispose();
});

it('beforeSetContent - should remove isEditing', () => {
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: 'beforeSetContent',
newContent: JSON.stringify(clonedRoot),
} as any;
plugin.onPluginEvent(event);
const isEditing = event.newContent.includes('data-is-editing="true"');
expect(isEditing).toBeFalse();
plugin.dispose();
});

it('beforeSetContent - should editor caret style', () => {
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: 'beforeSetContent',
newContent: JSON.stringify(clonedRoot),
} as any;
plugin.onPluginEvent(event);
expect(editor.setEditorStyle).toHaveBeenCalledWith('imageEditCaretColor', null);
plugin.dispose();
});
});

class TestPlugin extends ImageEditPlugin {
Expand Down

0 comments on commit 4578669

Please sign in to comment.