mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 18:05:55 +01:00 
			
		
		
		
	chore(client/ts): port web_view
This commit is contained in:
		| @@ -1,18 +1,20 @@ | |||||||
| import { t } from "../../services/i18n.js"; | import { t } from "../../services/i18n.js"; | ||||||
| import TypeWidget from "./type_widget.js"; | import TypeWidget from "./type_widget.js"; | ||||||
| import attributeService from "../../services/attributes.js"; | import attributeService from "../../services/attributes.js"; | ||||||
|  | import type FNote from "../../entities/fnote.js"; | ||||||
|  | import type { EventData } from "../../components/app_context.js"; | ||||||
| 
 | 
 | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <div class="note-detail-web-view note-detail-printable" style="height: 100%"> | <div class="note-detail-web-view note-detail-printable" style="height: 100%"> | ||||||
|     <div class="note-detail-web-view-help alert alert-warning" style="margin: 50px; padding: 20px 20px 0px 20px;"> |     <div class="note-detail-web-view-help alert alert-warning" style="margin: 50px; padding: 20px 20px 0px 20px;"> | ||||||
|         <h4>${t("web_view.web_view")}</h4> |         <h4>${t("web_view.web_view")}</h4> | ||||||
|          | 
 | ||||||
|         <p>${t("web_view.embed_websites")}</p> |         <p>${t("web_view.embed_websites")}</p> | ||||||
| 
 | 
 | ||||||
|         <p>${t("web_view.create_label")}</p> |         <p>${t("web_view.create_label")}</p> | ||||||
| 
 | 
 | ||||||
|         <h4>${t("web_view.disclaimer")}</h4> |         <h4>${t("web_view.disclaimer")}</h4> | ||||||
|          | 
 | ||||||
|         <p>${t("web_view.experimental_note")}</p> |         <p>${t("web_view.experimental_note")}</p> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
| @@ -20,6 +22,10 @@ const TPL = ` | |||||||
| </div>`;
 | </div>`;
 | ||||||
| 
 | 
 | ||||||
| export default class WebViewTypeWidget extends TypeWidget { | export default class WebViewTypeWidget extends TypeWidget { | ||||||
|  | 
 | ||||||
|  |     private $noteDetailWebViewHelp!: JQuery<HTMLElement>; | ||||||
|  |     private $noteDetailWebViewContent!: JQuery<HTMLElement>; | ||||||
|  | 
 | ||||||
|     static getType() { |     static getType() { | ||||||
|         return "webView"; |         return "webView"; | ||||||
|     } |     } | ||||||
| @@ -34,11 +40,15 @@ export default class WebViewTypeWidget extends TypeWidget { | |||||||
|         super.doRender(); |         super.doRender(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async doRefresh(note) { |     async doRefresh(note: FNote) { | ||||||
|         this.$widget.show(); |         this.$widget.show(); | ||||||
|         this.$noteDetailWebViewHelp.hide(); |         this.$noteDetailWebViewHelp.hide(); | ||||||
|         this.$noteDetailWebViewContent.hide(); |         this.$noteDetailWebViewContent.hide(); | ||||||
| 
 | 
 | ||||||
|  |         if (!this.note) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         const webViewSrc = this.note.getLabelValue("webViewSrc"); |         const webViewSrc = this.note.getLabelValue("webViewSrc"); | ||||||
| 
 | 
 | ||||||
|         if (webViewSrc) { |         if (webViewSrc) { | ||||||
| @@ -54,17 +64,19 @@ export default class WebViewTypeWidget extends TypeWidget { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     cleanup() { |     cleanup() { | ||||||
|         this.$noteDetailWebViewContent.removeAttribute("src"); |         this.$noteDetailWebViewContent.removeAttr("src"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     setDimensions() { |     setDimensions() { | ||||||
|         const $parent = this.$widget; |         const $parent = this.$widget; | ||||||
| 
 | 
 | ||||||
|         this.$noteDetailWebViewContent.height($parent.height()).width($parent.width()); |         this.$noteDetailWebViewContent | ||||||
|  |             .height($parent.height() ?? 0) | ||||||
|  |             .width($parent.width() ?? 0); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     entitiesReloadedEvent({ loadResults }) { |     entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { | ||||||
|         if (loadResults.getAttributeRows().find((attr) => attr.name === "webViewSrc" && attributeService.isAffecting(attr, this.noteContext.note))) { |         if (loadResults.getAttributeRows().find((attr) => attr.name === "webViewSrc" && attributeService.isAffecting(attr, this.noteContext?.note))) { | ||||||
|             this.refresh(); |             this.refresh(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
		Reference in New Issue
	
	Block a user