diff --git a/src/public/app/widgets/type_widgets/web_view.js b/src/public/app/widgets/type_widgets/web_view.ts similarity index 75% rename from src/public/app/widgets/type_widgets/web_view.js rename to src/public/app/widgets/type_widgets/web_view.ts index 5bfa74f05..57f2fc11a 100644 --- a/src/public/app/widgets/type_widgets/web_view.js +++ b/src/public/app/widgets/type_widgets/web_view.ts @@ -1,18 +1,20 @@ import { t } from "../../services/i18n.js"; import TypeWidget from "./type_widget.js"; import attributeService from "../../services/attributes.js"; +import type FNote from "../../entities/fnote.js"; +import type { EventData } from "../../components/app_context.js"; const TPL = `

${t("web_view.web_view")}

- +

${t("web_view.embed_websites")}

${t("web_view.create_label")}

${t("web_view.disclaimer")}

- +

${t("web_view.experimental_note")}

@@ -20,6 +22,10 @@ const TPL = `
`; export default class WebViewTypeWidget extends TypeWidget { + + private $noteDetailWebViewHelp!: JQuery; + private $noteDetailWebViewContent!: JQuery; + static getType() { return "webView"; } @@ -34,11 +40,15 @@ export default class WebViewTypeWidget extends TypeWidget { super.doRender(); } - async doRefresh(note) { + async doRefresh(note: FNote) { this.$widget.show(); this.$noteDetailWebViewHelp.hide(); this.$noteDetailWebViewContent.hide(); + if (!this.note) { + return; + } + const webViewSrc = this.note.getLabelValue("webViewSrc"); if (webViewSrc) { @@ -54,17 +64,19 @@ export default class WebViewTypeWidget extends TypeWidget { } cleanup() { - this.$noteDetailWebViewContent.removeAttribute("src"); + this.$noteDetailWebViewContent.removeAttr("src"); } setDimensions() { const $parent = this.$widget; - this.$noteDetailWebViewContent.height($parent.height()).width($parent.width()); + this.$noteDetailWebViewContent + .height($parent.height() ?? 0) + .width($parent.width() ?? 0); } - entitiesReloadedEvent({ loadResults }) { - if (loadResults.getAttributeRows().find((attr) => attr.name === "webViewSrc" && attributeService.isAffecting(attr, this.noteContext.note))) { + entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { + if (loadResults.getAttributeRows().find((attr) => attr.name === "webViewSrc" && attributeService.isAffecting(attr, this.noteContext?.note))) { this.refresh(); } }