feat(react/widgets): port shared_info

This commit is contained in:
Elian Doran 2025-08-30 13:59:53 +03:00
parent 5f647a932d
commit fbec6d8873
No known key found for this signature in database
16 changed files with 103 additions and 104 deletions

View File

@ -17,7 +17,6 @@ import CreatePaneButton from "../widgets/buttons/create_pane_button.js";
import ClosePaneButton from "../widgets/buttons/close_pane_button.js";
import RightPaneContainer from "../widgets/containers/right_pane_container.js";
import NoteWrapperWidget from "../widgets/note_wrapper.js";
import SharedInfoWidget from "../widgets/shared_info.js";
import FindWidget from "../widgets/find.js";
import TocWidget from "../widgets/toc.js";
import HighlightsListWidget from "../widgets/highlights_list.js";
@ -42,6 +41,7 @@ import TitleBarButtons from "../widgets/title_bar_buttons.jsx";
import LeftPaneToggle from "../widgets/buttons/left_pane_toggle.js";
import ApiLog from "../widgets/api_log.jsx";
import CloseZenModeButton from "../widgets/close_zen_button.jsx";
import SharedInfo from "../widgets/shared_info.jsx";
export default class DesktopLayout {
@ -129,7 +129,7 @@ export default class DesktopLayout {
.child(new CreatePaneButton())
)
.child(<Ribbon />)
.child(new SharedInfoWidget())
.child(<SharedInfo />)
.child(new WatchedFileUpdateStatusWidget())
.child(<FloatingButtons items={DESKTOP_FLOATING_BUTTONS} />)
.child(

View File

@ -143,7 +143,7 @@ export default class MobileLayout {
.child(<NoteTitleWidget />)
.child(<MobileDetailMenu />)
)
.child(new SharedInfoWidget())
.child(<SharedInfoWidget />)
.child(<FloatingButtons items={MOBILE_FLOATING_BUTTONS} />)
.child(new PromotedAttributesWidget())
.child(

View File

@ -1440,8 +1440,8 @@
"open-in-popup": "快速编辑"
},
"shared_info": {
"shared_publicly": "此笔记已公开分享于",
"shared_locally": "此笔记已在本地分享于",
"shared_publicly": "",
"shared_locally": "",
"help_link": "访问 <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a> 获取帮助。"
},
"note_types": {

View File

@ -1404,8 +1404,8 @@
"open-in-popup": "Schnellbearbeitung"
},
"shared_info": {
"shared_publicly": "Diese Notiz ist öffentlich geteilt auf",
"shared_locally": "Diese Notiz ist lokal geteilt auf",
"shared_publicly": "Diese Notiz ist öffentlich geteilt auf {{- link}}",
"shared_locally": "Diese Notiz ist lokal geteilt auf {{- link}}",
"help_link": "Für Hilfe besuche <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."
},
"note_types": {

View File

@ -1602,8 +1602,8 @@
"open-in-popup": "Quick edit"
},
"shared_info": {
"shared_publicly": "This note is shared publicly on",
"shared_locally": "This note is shared locally on",
"shared_publicly": "This note is shared publicly on {{- link}}.",
"shared_locally": "This note is shared locally on {{- link}}.",
"help_link": "For help visit <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."
},
"note_types": {

View File

@ -1596,8 +1596,8 @@
"open-in-popup": "Edición rápida"
},
"shared_info": {
"shared_publicly": "Esta nota está compartida públicamente en",
"shared_locally": "Esta nota está compartida localmente en",
"shared_publicly": "Esta nota está compartida públicamente en {{- link}}",
"shared_locally": "Esta nota está compartida localmente en {{- link}}",
"help_link": "Para obtener ayuda visite <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."
},
"note_types": {

View File

@ -1389,8 +1389,8 @@
"convert-to-attachment-confirm": "Êtes-vous sûr de vouloir convertir les notes sélectionnées en pièces jointes de leurs notes parentes ?"
},
"shared_info": {
"shared_publicly": "Cette note est partagée publiquement sur",
"shared_locally": "Cette note est partagée localement sur",
"shared_publicly": "Cette note est partagée publiquement sur {{- link}}",
"shared_locally": "Cette note est partagée localement sur {{- link}}",
"help_link": "Pour obtenir de l'aide, visitez le <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."
},
"note_types": {

View File

@ -977,8 +977,8 @@
},
"open-help-page": "ヘルプページを開く",
"shared_info": {
"shared_publicly": "このノートは一般公開されています",
"shared_locally": "このノートはローカルで共有されています",
"shared_publicly": "",
"shared_locally": "",
"help_link": "ヘルプについては、<a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>をご覧ください。"
},
"highlights_list_2": {

View File

@ -2022,8 +2022,8 @@
"handshake_failed": "Falha no handshake com o servidor de sincronização, erro: {{message}}"
},
"shared_info": {
"shared_publicly": "Esta nota é compartilhada publicamente",
"shared_locally": "Esta nota é compartilhada localmente",
"shared_publicly": "",
"shared_locally": "",
"help_link": "Para ajuda, visite a <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>."
}
}

View File

@ -1373,8 +1373,8 @@
},
"shared_info": {
"help_link": "Pentru informații vizitați <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki-ul</a>.",
"shared_locally": "Această notiță este partajată local la",
"shared_publicly": "Această notiță este partajată public la"
"shared_locally": "Această notiță este partajată local la {{- link}}",
"shared_publicly": "Această notiță este partajată public la {{- link}}"
},
"note_types": {
"book": "Colecție",

View File

@ -1974,8 +1974,8 @@
},
"shared_info": {
"help_link": "Для получения справки посетите <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">вики</a>.",
"shared_locally": "Заметка общедоступна локально в",
"shared_publicly": "Заметка общедоступна публично в"
"shared_locally": "Заметка общедоступна локально в {{- link}}",
"shared_publicly": "Заметка общедоступна публично в {{- link}}"
},
"note_create": {
"duplicated": "Создан дубль заметки \"{{title}}\"."

View File

@ -1399,8 +1399,8 @@
"open-in-popup": "快速編輯"
},
"shared_info": {
"shared_publicly": "此筆記已公開分享在",
"shared_locally": "此筆記已在本地分享在",
"shared_publicly": "",
"shared_locally": "",
"help_link": "如需幫助,請訪問 <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">wiki</a>。"
},
"note_types": {

View File

@ -1909,8 +1909,8 @@
"open-in-popup": "Швидке редагування"
},
"shared_info": {
"shared_publicly": "Ця нотатка опублікована на",
"shared_locally": "Цю нотатку опубліковано локально на",
"shared_publicly": "Ця нотатка опублікована на {{- link}}",
"shared_locally": "Цю нотатку опубліковано локально на {{- link}}",
"help_link": "Щоб отримати допомогу, відвідайте <a href=\"https://triliumnext.github.io/Docs/Wiki/sharing.html\">вікі</a>."
},
"note_types": {

View File

@ -1,15 +1,17 @@
import { ComponentChildren } from "preact";
import { CSSProperties } from "preact/compat";
interface AlertProps {
type: "info" | "danger" | "warning";
title?: string;
children: ComponentChildren;
className?: string;
style?: CSSProperties;
}
export default function Alert({ title, type, children, className }: AlertProps) {
export default function Alert({ title, type, children, className, style }: AlertProps) {
return (
<div className={`alert alert-${type} ${className ?? ""}`}>
<div className={`alert alert-${type} ${className ?? ""}`} style={style}>
{title && <h4>{title}</h4>}
{children}

View File

@ -1,77 +0,0 @@
import NoteContextAwareWidget from "./note_context_aware_widget.js";
import options from "../services/options.js";
import attributeService from "../services/attributes.js";
import { t } from "../services/i18n.js";
import type FNote from "../entities/fnote.js";
import type { EventData } from "../components/app_context.js";
const TPL = /*html*/`
<div class="shared-info-widget alert alert-warning use-tn-links">
<style>
.shared-info-widget {
margin: 10px;
contain: none;
padding: 10px;
font-weight: bold;
}
</style>
<span class="shared-text"></span> <a class="shared-link external"></a>. ${t("shared_info.help_link")}
</div>`;
export default class SharedInfoWidget extends NoteContextAwareWidget {
private $sharedLink!: JQuery<HTMLElement>;
private $sharedText!: JQuery<HTMLElement>;
isEnabled() {
return super.isEnabled() && this.noteId !== "_share" && this.note?.hasAncestor("_share");
}
doRender() {
this.$widget = $(TPL);
this.$sharedLink = this.$widget.find(".shared-link");
this.$sharedText = this.$widget.find(".shared-text");
this.contentSized();
}
async refreshWithNote(note: FNote) {
const syncServerHost = options.get("syncServerHost");
let link;
const shareId = this.getShareId(note);
if (syncServerHost) {
link = `${syncServerHost}/share/${shareId}`;
this.$sharedText.text(t("shared_info.shared_publicly"));
} else {
let host = location.host;
if (host.endsWith("/")) {
// seems like IE has trailing slash
// https://github.com/zadam/trilium/issues/3782
host = host.substr(0, host.length - 1);
}
link = `${location.protocol}//${host}${location.pathname}share/${shareId}`;
this.$sharedText.text(t("shared_info.shared_locally"));
}
this.$sharedLink.attr("href", link).text(link);
}
getShareId(note: FNote) {
if (note.hasOwnedLabel("shareRoot")) {
return "";
}
return note.getOwnedLabelValue("shareAlias") || note.noteId;
}
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.getAttributeRows().find((attr) => attr.name?.startsWith("_share") && attributeService.isAffecting(attr, this.note))) {
this.refresh();
} else if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId)) {
this.refresh();
}
}
}

View File

@ -0,0 +1,74 @@
import { useEffect, useState } from "preact/hooks";
import { t } from "../services/i18n";
import Alert from "./react/Alert";
import { useNoteContext, useTriliumEvent, useTriliumOption } from "./react/hooks";
import FNote from "../entities/fnote";
import attributes from "../services/attributes";
import RawHtml from "./react/RawHtml";
import HelpButton from "./react/HelpButton";
export default function SharedInfo() {
const { note } = useNoteContext();
const [ syncServerHost ] = useTriliumOption("syncServerHost");
const [ link, setLink ] = useState<string>();
function refresh() {
if (!note) return;
if (note.noteId === "_share" || !note?.hasAncestor("_share")) {
setLink(undefined);
return;
}
let link;
const shareId = getShareId(note);
if (syncServerHost) {
link = `${syncServerHost}/share/${shareId}`;
} else {
let host = location.host;
if (host.endsWith("/")) {
// seems like IE has trailing slash
// https://github.com/zadam/trilium/issues/3782
host = host.substring(0, host.length - 1);
}
link = `${location.protocol}//${host}${location.pathname}share/${shareId}`;
}
setLink(`<a href="${link}" class="external">${link}</a>`);
}
useEffect(refresh, [ note ]);
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
if (loadResults.getAttributeRows().find((attr) => attr.name?.startsWith("_share") && attributes.isAffecting(attr, note))) {
refresh();
} else if (loadResults.getBranchRows().find((branch) => branch.noteId === note?.noteId)) {
refresh();
}
});
return (
<Alert className="shared-info-widget" type="warning" style={{
contain: "none",
margin: "10px",
padding: "10px",
fontWeight: "bold",
display: !link ? "none" : undefined
}}>
{link && (
<RawHtml html={syncServerHost
? t("shared_info.shared_publicly", { link })
: t("shared_info.shared_locally", { link })} />
)}
<HelpButton helpPage="R9pX4DGra2Vt" style={{ width: "24px", height: "24px" }} />
</Alert>
)
}
function getShareId(note: FNote) {
if (note.hasOwnedLabel("shareRoot")) {
return "";
}
return note.getOwnedLabelValue("shareAlias") || note.noteId;
}