2024-02-19 12:56:28 -05:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2024-02-28 16:32:45 -05:00
|
|
|
import Service, { inject as service } from "@ember/service";
|
|
|
|
import { IMAGE_MARKDOWN_REGEX } from "../lib/utilities";
|
2024-02-19 12:56:28 -05:00
|
|
|
|
|
|
|
export default class ImageCaptionPopup extends Service {
|
2024-02-28 16:32:45 -05:00
|
|
|
@service composer;
|
|
|
|
@service appEvents;
|
|
|
|
|
2024-02-19 12:56:28 -05:00
|
|
|
@tracked showPopup = false;
|
|
|
|
@tracked imageIndex = null;
|
|
|
|
@tracked imageSrc = null;
|
|
|
|
@tracked newCaption = null;
|
|
|
|
@tracked loading = false;
|
2024-02-28 16:32:45 -05:00
|
|
|
@tracked popupTrigger = null;
|
2024-05-27 13:49:24 -04:00
|
|
|
@tracked showAutoCaptionLoader = false;
|
2024-02-28 16:32:45 -05:00
|
|
|
@tracked _request = null;
|
|
|
|
|
|
|
|
updateCaption() {
|
|
|
|
const matchingPlaceholder =
|
|
|
|
this.composer.model.reply.match(IMAGE_MARKDOWN_REGEX);
|
|
|
|
|
|
|
|
if (matchingPlaceholder) {
|
|
|
|
const match = matchingPlaceholder[this.imageIndex];
|
|
|
|
const replacement = match.replace(
|
|
|
|
IMAGE_MARKDOWN_REGEX,
|
|
|
|
`![${this.newCaption}|$2$3$4]($5)`
|
|
|
|
);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
this.appEvents.trigger("composer:replace-text", match, replacement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleLoadingState(loading) {
|
|
|
|
if (loading) {
|
|
|
|
this.popupTrigger?.classList.add("disabled");
|
|
|
|
return (this.loading = true);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.popupTrigger?.classList.remove("disabled");
|
|
|
|
return (this.loading = false);
|
|
|
|
}
|
2024-02-19 12:56:28 -05:00
|
|
|
}
|