gnoxnahte_obsidian-auto-embed/preview-embed-modal.ts
GnoxNahte 21f7fd3b84 Remove "Markdown link content" from these 2 commits: 3ec1d6a2a1 and c0c5c58f0f
Following the previous commit, since there's a simpler and cleaner method to mark links to be embed, remove code from the 2 commits that aren't being used for future code
2024-03-11 13:11:32 +08:00

56 lines
No EOL
1.9 KiB
TypeScript

import AutoEmbedPlugin from "main";
import { Modal, Setting } from "obsidian";
export class PreviewEmbedModal extends Modal {
plugin: AutoEmbedPlugin;
url: string;
options: string;
constructor(plugin: AutoEmbedPlugin, url: string, options?: string) {
super(plugin.app);
this.plugin = plugin;
this.url = url;
this.options = options ?? "";
}
onOpen(): void {
const {contentEl} = this;
this.titleEl.textContent = "Preview Embed";
// let linkText = this.plugin.getLinkText(this.url, this.options);
let currEmbed: HTMLElement | null = null;
// ===== NOTE =====
// Setting is probably not meant to be used like this.
// But to make the user experience consistent, Use Setting inside this modal
// Think Setting just helps create and insert the html into contentEl? Hopefully not doing anything else. Couldn't find any documentation about it.
new Setting(contentEl)
.setName("Preview url")
.addText(text => text
.setValue(this.url)
.onChange((value) => {
this.url = value;
if (currEmbed)
contentEl.removeChild(currEmbed);
const readingViewAnchor = createEl("a", { text: "", href: this.url });
contentEl.appendChild(readingViewAnchor);
this.plugin.handleAnchor(readingViewAnchor);
}));
new Setting(contentEl)
.setName("Preview option")
.addText(text => text
.setValue(this.options))
// TODO: add invalid url
contentEl.appendChild(createEl("h3", { text: "Reading View:" }));
const readingViewAnchor = createEl("a", { text: "", href: this.url });
contentEl.appendChild(readingViewAnchor);
currEmbed = this.plugin.handleAnchor(readingViewAnchor);
}
}