mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 23:35:50 +01:00
chore(react/type_widget): basic integration of web view
This commit is contained in:
@@ -11,6 +11,7 @@ import { TypeWidgetProps } from "./type_widgets/type_widget";
|
|||||||
import ProtectedSession from "./type_widgets/ProtectedSession";
|
import ProtectedSession from "./type_widgets/ProtectedSession";
|
||||||
import Book from "./type_widgets/Book";
|
import Book from "./type_widgets/Book";
|
||||||
import ContentWidget from "./type_widgets/ContentWidget";
|
import ContentWidget from "./type_widgets/ContentWidget";
|
||||||
|
import WebView from "./type_widgets/WebView";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `NoteType` altered by the note detail widget, taking into consideration whether the note is editable or not and adding special note types such as an empty one,
|
* A `NoteType` altered by the note detail widget, taking into consideration whether the note is editable or not and adding special note types such as an empty one,
|
||||||
@@ -64,6 +65,7 @@ function getCorrespondingWidget(noteType: ExtendedNoteType | undefined, props: T
|
|||||||
case "protectedSession": return <ProtectedSession />
|
case "protectedSession": return <ProtectedSession />
|
||||||
case "book": return <Book {...props} />
|
case "book": return <Book {...props} />
|
||||||
case "contentWidget": return <ContentWidget {...props} />
|
case "contentWidget": return <ContentWidget {...props} />
|
||||||
|
case "webView": return <WebView {...props} />
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
apps/client/src/widgets/type_widgets/WebView.tsx
Normal file
37
apps/client/src/widgets/type_widgets/WebView.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { t } from "../../services/i18n";
|
||||||
|
import utils from "../../services/utils";
|
||||||
|
import Alert from "../react/Alert";
|
||||||
|
import { useNoteLabel } from "../react/hooks";
|
||||||
|
import { TypeWidgetProps } from "./type_widget";
|
||||||
|
|
||||||
|
const isElectron = utils.isElectron();
|
||||||
|
|
||||||
|
export default function WebView({ note }: TypeWidgetProps) {
|
||||||
|
const [ webViewSrc ] = useNoteLabel(note, "webViewSrc");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="note-detail-web-view note-detail-printable" style={{ height: "100%" }}>
|
||||||
|
{webViewSrc
|
||||||
|
? <WebViewContent src={webViewSrc} />
|
||||||
|
: <WebViewHelp />}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function WebViewContent({ src }: { src: string }) {
|
||||||
|
if (!isElectron) {
|
||||||
|
return <iframe src={src} class="note-detail-web-view-content" sandbox="allow-same-origin allow-scripts allow-popups" />
|
||||||
|
} else {
|
||||||
|
return <webview src={src} class="note-detail-web-view-content" />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function WebViewHelp() {
|
||||||
|
return (
|
||||||
|
<Alert className="note-detail-web-view-help" type="warning" style={{ margin: "50px", padding: "20px 20px 0px 20px;" }}>
|
||||||
|
<h4>{t("web_view.web_view")}</h4>
|
||||||
|
<p>{t("web_view.embed_websites")}</p>
|
||||||
|
<p>{t("web_view.create_label")}</p>
|
||||||
|
</Alert>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -6,23 +6,13 @@ import type { EventData } from "../../components/app_context.js";
|
|||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<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;">
|
|
||||||
<h4>${t("web_view.web_view")}</h4>
|
|
||||||
|
|
||||||
<p>${t("web_view.embed_websites")}</p>
|
|
||||||
|
|
||||||
<p>${t("web_view.create_label")}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
${buildElement()}
|
${buildElement()}
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
function buildElement() {
|
function buildElement() {
|
||||||
if (!utils.isElectron()) {
|
if (!utils.isElectron()) {
|
||||||
return `<iframe class="note-detail-web-view-content" sandbox="allow-same-origin allow-scripts allow-popups"></iframe>`;
|
|
||||||
} else {
|
} else {
|
||||||
return `<webview class="note-detail-web-view-content"></webview>`;
|
return ``;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ type Labels = {
|
|||||||
"board:groupBy": string;
|
"board:groupBy": string;
|
||||||
maxNestingDepth: number;
|
maxNestingDepth: number;
|
||||||
includeArchived: boolean;
|
includeArchived: boolean;
|
||||||
|
|
||||||
|
// Note-type specific
|
||||||
|
webViewSrc: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user