Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit a5a70fc

Browse files
feat: delete image in inline editor
1 parent 471fac0 commit a5a70fc

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

studio/src/app/components/editor/app-editor-toolbar/app-editor-toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ export class AppEditorToolbar {
710710
private renderDelete() {
711711
return <a onClick={() => this.deleteElement()} title="Delete"
712712
class={this.deckBusy && this.deckOrSlide ? "delete disabled" : "delete"}>
713-
<ion-icon name="trash"></ion-icon>
713+
<ion-icon ios="md-trash" md="md-trash"></ion-icon>
714714
</a>
715715
}
716716

webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ div.deckgo-tools {
214214
}
215215
}
216216

217-
&.ordered-list, &.unordered-list, &.link, &.image, &.image-align {
217+
&.ordered-list, &.unordered-list, &.link, &.image, &.image-align, &.image-delete {
218218
> div {
219219
-webkit-mask-repeat: no-repeat;
220220
mask-repeat: no-repeat;
@@ -291,6 +291,16 @@ div.deckgo-tools {
291291
}
292292
}
293293
}
294+
295+
&.image-delete {
296+
> div {
297+
-webkit-mask-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"%3E%3Cpath d="M128 405.429C128 428.846 147.198 448 170.667 448h170.667C364.802 448 384 428.846 384 405.429V160H128v245.429zM416 96h-80l-26.785-32H202.786L176 96H96v32h320V96z"/%3E%3C/svg%3E');
298+
mask-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"%3E%3Cpath d="M128 405.429C128 428.846 147.198 448 170.667 448h170.667C364.802 448 384 428.846 384 405.429V160H128v245.429zM416 96h-80l-26.785-32H202.786L176 96H96v32h320V96z"/%3E%3C/svg%3E');
299+
300+
width: 20px;
301+
height: 20px;
302+
}
303+
}
294304
}
295305

296306
&.deckgo-tools-mobile {

webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,6 @@ export class DeckdeckgoInlineEditor {
840840
private setImageWith = async (size: ImageSize) => {
841841
const anchorImg: HTMLImageElement = this.anchorEvent.target as HTMLImageElement;
842842
anchorImg.style.setProperty(this.imgPropertyWidth, size.toString());
843-
844-
const container: HTMLElement = await this.findContainer(anchorImg);
845-
this.imgDidChange.emit(container);
846843
};
847844

848845
private setImageAlignment = (align: ImageAlign) => {
@@ -878,6 +875,40 @@ export class DeckdeckgoInlineEditor {
878875
});
879876
}
880877

878+
private deleteImage(e: UIEvent): Promise<void> {
879+
return new Promise<void>(async (resolve) => {
880+
const isAnchorImg: boolean = await this.isAnchorImage();
881+
if (!isAnchorImg) {
882+
resolve();
883+
return;
884+
}
885+
886+
e.stopPropagation();
887+
888+
const anchorImg: HTMLImageElement = this.anchorEvent.target as HTMLImageElement;
889+
890+
if (!anchorImg || !anchorImg.parentElement) {
891+
resolve();
892+
return;
893+
}
894+
895+
const container: HTMLElement = await this.findContainer(anchorImg);
896+
897+
if (!container) {
898+
resolve();
899+
return;
900+
}
901+
902+
anchorImg.parentElement.removeChild(anchorImg);
903+
904+
this.imgDidChange.emit(container);
905+
906+
await this.reset(true);
907+
908+
resolve();
909+
});
910+
}
911+
881912
render() {
882913
let classNames: string = this.toolsActivated ? (this.mobile ? 'deckgo-tools deckgo-tools-activated deckgo-tools-mobile' : 'deckgo-tools deckgo-tools-activated') : (this.mobile ? 'deckgo-tools deckgo-tools-mobile' : 'deckgo-tools');
883914

@@ -946,10 +977,7 @@ export class DeckdeckgoInlineEditor {
946977
<div class="separator"></div>,
947978

948979
<button
949-
disabled={this.disabledTitle}
950-
onClick={() => {
951-
this.toggleLink()
952-
}} class={this.link ? "link active" : "link"}>
980+
disabled={this.disabledTitle} onClick={() => this.toggleLink()} class={this.link ? "link active" : "link"}>
953981
<div></div>
954982
</button>
955983
];
@@ -989,7 +1017,16 @@ export class DeckdeckgoInlineEditor {
9891017
onClick={(e: UIEvent) => this.styleImage(e, this.setImageAlignment, ImageAlign.START)}
9901018
class={this.imageAlign === ImageAlign.START ? "image-align start active" : "image-align start"}>
9911019
<div></div>
1020+
</button>,
1021+
1022+
<div class="separator"></div>,
1023+
1024+
<button
1025+
onClick={(e: UIEvent) => this.deleteImage(e)} class="image-delete">
1026+
<div></div>
9921027
</button>
1028+
1029+
9931030
];
9941031
}
9951032
}

webcomponents/inline-editor/src/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ <h3 contenteditable>Credits</h3>
2020

2121
<p contenteditable>The following solution was inspired by the one developed in the Ionic core project. One of the entry point for me was discovering the method setupConfig in their source code. Therefore kudos to the awesome <a href="https://ionicframework.com">Ionic</a> team ❤️</p>
2222

23-
<p contenteditable style="width: 400px;"><img style="max-width: 100%;" src="https://pixabay.com/get/ea34b50f2cfd033ed1584d05fb1d4794e070e2d71eb80c4090f5c679a2edb4b0d8_1280.jpg"/></p>
24-
25-
<p><deckgo-lazy-img img-src="https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjcwODc4fQ" class="hydrated"></deckgo-lazy-img></p>
23+
<p contenteditable><img src="https://deckdeckgo.com/assets/img/deckdeckgo.png"/></p>
2624

2725
<deckgo-inline-editor sticky-desktop="false" sticky-mobile="true" containers="h1,h2,h3,h4,h5,h6,p"></deckgo-inline-editor>
2826

0 commit comments

Comments
 (0)