Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client): show the note badges on the old layout
Elian Doran60cffbe32d8c
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex cdd984f7a7..6226d07f0e 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -591,10 +591,6 @@ type EventMappings = {noteIds: string[];};refreshData: { ntxId: string | null | undefined };- contentSafeMarginChanged: {- top: number;- noteContext: NoteContext;- };};export type EventListener<T extends EventNames> = {diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsxindex 2df4eea4c5..70ccbad7aa 100644--- a/apps/client/src/layouts/desktop_layout.tsx+++ b/apps/client/src/layouts/desktop_layout.tsx@@ -12,7 +12,6 @@ import MovePaneButton from "../widgets/buttons/move_pane_button.js";import RightPaneToggle from "../widgets/buttons/right_pane_toggle.jsx";import CloseZenModeButton from "../widgets/close_zen_button.jsx";import NoteList from "../widgets/collections/NoteList.jsx";-import ContentHeader from "../widgets/containers/content_header.js";import FlexContainer from "../widgets/containers/flex_container.js";import LeftPaneContainer from "../widgets/containers/left_pane_container.js";import RootContainer from "../widgets/containers/root_container.js";@@ -36,13 +35,11 @@ import NoteWrapperWidget from "../widgets/note_wrapper.js";import NoteDetail from "../widgets/NoteDetail.jsx";import PromotedAttributes from "../widgets/PromotedAttributes.jsx";import QuickSearch from "../widgets/quick_search.jsx";-import ReadOnlyNoteInfoBar from "../widgets/ReadOnlyNoteInfoBar.jsx";import { FixedFormattingToolbar } from "../widgets/ribbon/FormattingToolbar.jsx";import LazyComponent from "../widgets/react/LazyComponent.jsx";import NoteActions from "../widgets/ribbon/NoteActions.jsx";import ScrollPadding from "../widgets/scroll_padding.js";import SearchResult from "../widgets/search_result.jsx";-import SharedInfo from "../widgets/shared_info.jsx";import RightPanelContainer from "../widgets/sidebar/RightPanelContainer.jsx";import TabRowWidget from "../widgets/tab_row.js";import TabHistoryNavigationButtons from "../widgets/TabHistoryNavigationButtons.jsx";@@ -134,7 +131,7 @@ export default class DesktopLayout {.cssBlock(".title-row > * { margin: 5px; }").child(<NoteIconWidget />).child(<NoteTitleWidget />)- .optChild(isNewLayout, <NoteBadges />)+ .child(<NoteBadges />).child(<SpacerWidget baseSize={0} growthFactor={1} />).optChild(!isNewLayout, <MovePaneButton direction="left" />).optChild(!isNewLayout, <MovePaneButton direction="right" />)@@ -149,10 +146,6 @@ export default class DesktopLayout {.filling().optChild(isNewLayout, <InlineTitle />).optChild(isNewLayout, <NoteTitleActions />)- .optChild(!isNewLayout, new ContentHeader()- .child(<ReadOnlyNoteInfoBar />)- .child(<SharedInfo />)- ).optChild(!isNewLayout, <PromotedAttributes />).child(<NoteDetail />).child(<NoteList media="screen" />)diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 2dd2a918ee..a5c8e03f09 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -2407,7 +2407,6 @@ body.zen .right-pane-peek-button,body.zen #mobile-sidebar-wrapper,body.zen .tab-row-container,body.zen .tab-row-widget,-body.zen .shared-info-widget,body.zen .ribbon-container,body.zen .title-row .icon-action,body.zen .note-badges > *:not(.read-only-badge),diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex a6712a466f..f3bc73ab50 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2509,16 +2509,7 @@"clone": "Clone","clone-tooltip": "Clone, to have the same note in two places at once"},- "shared_info": {- "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>.",- "shared_preview": "This note is shared on {{- link}}, but only this browser can open that page, and only while Trilium is open in it. Publishing it for others needs a Trilium server.",- "shared_export_only": "This note is shared, but the mobile app cannot open shared pages. To publish it, export the subtree as \"{{format}}\" and host the files on any web server, or use a Trilium server."- },"read-only-info": {- "read-only-note": "Currently viewing a read-only note.",- "auto-read-only-note": "This note is shown in a read-only mode for faster loading.","edit-note": "Edit note"},"note_types": {diff --git a/apps/client/src/widgets/FloatingButtons.tsx b/apps/client/src/widgets/FloatingButtons.tsxindex 55620d4b97..42d5ee3493 100644--- a/apps/client/src/widgets/FloatingButtons.tsx+++ b/apps/client/src/widgets/FloatingButtons.tsx@@ -1,6 +1,6 @@import { t } from "i18next";import "./FloatingButtons.css";-import { useNoteContext, useNoteLabel, useNoteLabelBoolean, useTriliumEvent } from "./react/hooks";+import { useNoteContext, useNoteLabel, useNoteLabelBoolean } from "./react/hooks";import { useContext, useEffect, useMemo, useState } from "preact/hooks";import { ParentComponent } from "./react/react_utils";import { EventData, EventNames } from "../components/app_context";@@ -20,7 +20,6 @@ interface FloatingButtonsProps {* properly handle rounded corners, as defined by the --border-radius CSS variable.*/export default function FloatingButtons({ items }: FloatingButtonsProps) {- const [ top, setTop ] = useState(0);const { note, noteContext } = useNoteContext();const parentComponent = useContext(ParentComponent);const [ viewType ] = useNoteLabel(note, "viewType");@@ -48,14 +47,8 @@ export default function FloatingButtons({ items }: FloatingButtonsProps) {const [ visible, setVisible ] = useState(true);useEffect(() => setVisible(true), [ note ]);- useTriliumEvent("contentSafeMarginChanged", (e) => {- if (e.noteContext === noteContext) {- setTop(e.top);- }- });-return (- <div className="floating-buttons no-print" style={{ top: `${top}px` }}>+ <div className="floating-buttons no-print"><div className={`floating-buttons-children ${!visible ? "temporarily-hidden" : ""}`}>{context && items.map((Component) => (<Component {...context} />diff --git a/apps/client/src/widgets/ReadOnlyNoteInfoBar.css b/apps/client/src/widgets/ReadOnlyNoteInfoBar.cssdeleted file mode 100644index bf222a611a..0000000000--- a/apps/client/src/widgets/ReadOnlyNoteInfoBar.css+++ /dev/null@@ -1,20 +0,0 @@-body.zen div.read-only-note-info-bar-widget {- width: fit-content;- max-width: var(--max-content-width);- border-radius: 8px;- border: unset;- margin: 0 auto 10px auto;-}--.read-only-note-info-bar-widget-content {- display: flex;- justify-content: space-between;- align-items: center;- gap: 20px;-}--:root div.read-only-note-info-bar-widget button {- white-space: nowrap;- padding: 2px 8px;- flex-shrink: 0;-}\ No newline at end of filediff --git a/apps/client/src/widgets/ReadOnlyNoteInfoBar.tsx b/apps/client/src/widgets/ReadOnlyNoteInfoBar.tsxdeleted file mode 100644index af305fc1cc..0000000000--- a/apps/client/src/widgets/ReadOnlyNoteInfoBar.tsx+++ /dev/null@@ -1,35 +0,0 @@-import "./ReadOnlyNoteInfoBar.css";-import { t } from "../services/i18n";-import { useIsNoteReadOnly, useNoteContext, useTriliumEvent } from "./react/hooks"-import Button from "./react/Button";-import InfoBar from "./react/InfoBar";-import HelpButton from "./react/HelpButton";--export default function ReadOnlyNoteInfoBar(props: {}) {- const { note, noteContext } = useNoteContext();- const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);- const isExplicitReadOnly = note?.isLabelTruthy("readOnly");-- return (- <InfoBar- className="read-only-note-info-bar-widget"- type={(isExplicitReadOnly ? "subtle" : "prominent")}- style={{display: (!isReadOnly) ? "none" : undefined}}- >- <div class="read-only-note-info-bar-widget-content">- {(isExplicitReadOnly) ? (- <div>{t("read-only-info.read-only-note")}</div>- ) : (- <div>- {t("read-only-info.auto-read-only-note")}- {" "}- <HelpButton helpPage="CoFPLs3dRlXc" />- </div>- )}-- <Button text={t("read-only-info.edit-note")}- icon="bx-pencil" onClick={() => enableEditing()} />- </div>- </InfoBar>- );-}diff --git a/apps/client/src/widgets/containers/content_header.ts b/apps/client/src/widgets/containers/content_header.tsdeleted file mode 100644index ac001d40a8..0000000000--- a/apps/client/src/widgets/containers/content_header.ts+++ /dev/null@@ -1,63 +0,0 @@-import { EventData } from "../../components/app_context";-import BasicWidget from "../basic_widget";-import Container from "./container";-import NoteContext from "../../components/note_context";--export default class ContentHeader extends Container<BasicWidget> {-- noteContext?: NoteContext;- thisElement?: HTMLElement;- parentElement?: HTMLElement;- resizeObserver: ResizeObserver;- currentHeight: number = 0;- currentSafeMargin: number = NaN;-- constructor() {- super();-- this.class("content-header-widget");- this.css("contain", "unset");- this.resizeObserver = new ResizeObserver(this.onResize.bind(this));- }-- setNoteContextEvent({ noteContext }: EventData<"setNoteContext">) {- this.noteContext = noteContext;- this.init();- }-- init() {- this.parentElement = this.parent?.$widget.get(0);- if (!this.parentElement) {- console.warn("No parent set for <ContentHeader>.");- return;- }-- this.thisElement = this.$widget.get(0)!;-- this.resizeObserver.observe(this.thisElement);- this.parentElement.addEventListener("scroll", this.updateSafeMargin.bind(this));- }-- updateSafeMargin() {- const newSafeMargin = Math.max(this.currentHeight - this.parentElement!.scrollTop, 0);-- if (newSafeMargin !== this.currentSafeMargin) {- this.currentSafeMargin = newSafeMargin;-- this.triggerEvent("contentSafeMarginChanged", {- top: newSafeMargin,- noteContext: this.noteContext!- });- }- }-- onResize(entries: ResizeObserverEntry[]) {- for (const entry of entries) {- if (entry.target === this.thisElement) {- this.currentHeight = entry.contentRect.height;- this.updateSafeMargin();- }- }- }--}\ No newline at end of filediff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsxindex 8294506dc5..4f1d299e53 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx@@ -106,7 +106,6 @@ vi.mock("../FloatingButtonsDefinitions", () => ({POPUP_HIDDEN_FLOATING_BUTTONS: [ "hidden" ]}));vi.mock("../PromotedAttributes", () => ({ default: () => null }));-vi.mock("../ReadOnlyNoteInfoBar", () => ({ default: () => null }));vi.mock("../layout/NoteBadges", () => ({ default: () => null }));vi.mock("../layout/NoteTypeSwitcher", () => ({default: () => <div className="note-type-switcher-stub" />diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsxindex 62ea947ef6..7c0f8a125b 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx@@ -5,7 +5,6 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "pimport appContext from "../../components/app_context";import NoteContext from "../../components/note_context";-import { isExperimentalFeatureEnabled } from "../../services/experimental_features";import froca from "../../services/froca";import { t } from "../../services/i18n";import tree from "../../services/tree";@@ -20,13 +19,10 @@ import PromotedAttributes from "../PromotedAttributes";import { useContainedLinkNavigation, useNoteContext, useNoteLabel, useTriliumEvent } from "../react/hooks";import Modal from "../react/Modal";import { NoteContextContext, ParentComponent } from "../react/react_utils";-import ReadOnlyNoteInfoBar from "../ReadOnlyNoteInfoBar";import StandaloneRibbonAdapter from "../ribbon/components/StandaloneRibbonAdapter";import FormattingToolbar, { showFormattingToolbar } from "../ribbon/FormattingToolbar";import MobileEditorToolbar from "../type_widgets/text/mobile_editor_toolbar";-const isNewLayout = isExperimentalFeatureEnabled("new-layout");-/** The layer the stylesheet gives this popup while it stands over another modal. */const STACKED_LAYER = 1100;@@ -184,7 +180,6 @@ export default function PopupEditor() {noFocus // automatic focus breaks block popupstackable>- {!isNewLayout && <ReadOnlyNoteInfoBar />}<PromotedAttributes />{isMobilediff --git a/apps/client/src/widgets/layout/NoteBadges.spec.tsx b/apps/client/src/widgets/layout/NoteBadges.spec.tsxindex 50d6f7758f..6f395cf349 100644--- a/apps/client/src/widgets/layout/NoteBadges.spec.tsx+++ b/apps/client/src/widgets/layout/NoteBadges.spec.tsx@@ -22,7 +22,7 @@ vi.mock("../../services/i18n", () => ({import { buildNote } from "../../test/easy-froca";import { renderInto } from "../../test/render";-import { OfficePreviewBadge } from "./NoteBadges";+import { getShareScope, OfficePreviewBadge } from "./NoteBadges";const DOCX_MIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";@@ -52,3 +52,18 @@ describe("OfficePreviewBadge", () => {return renderInto(<OfficePreviewBadge />).querySelector(".office-preview-badge");}});++describe("getShareScope", () => {+ it("tells a public share from a local one, a standalone preview and one only an export publishes", () => {+ const syncServerHost = "https://sync.example.com";+ const platform = { isElectron: false, isStandalone: false, isMobileApp: false };++ expect(getShareScope({ ...platform, syncServerHost: "" })).toBe("public");+ expect(getShareScope({ ...platform, isElectron: true, syncServerHost: "" })).toBe("local");+ expect(getShareScope({ ...platform, isElectron: true, syncServerHost })).toBe("public");+ expect(getShareScope({ ...platform, isStandalone: true, syncServerHost: "" })).toBe("preview");+ expect(getShareScope({ ...platform, isStandalone: true, syncServerHost })).toBe("public");+ expect(getShareScope({ ...platform, isStandalone: true, isMobileApp: true, syncServerHost: "" })).toBe("export-only");+ expect(getShareScope({ ...platform, isStandalone: true, isMobileApp: true, syncServerHost })).toBe("public");+ });+});diff --git a/apps/client/src/widgets/layout/NoteBadges.tsx b/apps/client/src/widgets/layout/NoteBadges.tsxindex c93830509b..30871764a0 100644--- a/apps/client/src/widgets/layout/NoteBadges.tsx+++ b/apps/client/src/widgets/layout/NoteBadges.tsx@@ -5,20 +5,22 @@ import { clsx } from "clsx";import { useCallback, useEffect, useState } from "preact/hooks";import FNote from "../../entities/fnote";+import attributes from "../../services/attributes";import branches from "../../services/branches";import { copyTextWithToast } from "../../services/clipboard_ext";import dialog from "../../services/dialog";import { t } from "../../services/i18n";import { goToLinkExt } from "../../services/link";import server from "../../services/server";+import { buildShareLink } from "../../services/share_link";import sync from "../../services/sync";+import { isElectron, isMobileApp, isStandalone } from "../../services/utils";import { Badge, BadgeWithDropdown } from "../react/Badge";import { FormDropdownDivider, FormListItem } from "../react/FormList";import {useGetContextDataFrom, useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty,- useTriliumEvent+ useTriliumEvent, useTriliumOption} from "../react/hooks";-import { type ShareScope, useShareInfo } from "../shared_info";import { ActiveContentBadges } from "./ActiveContentBadges";import { SnippetBadge } from "./SnippetBadge";@@ -264,3 +266,76 @@ export function useShareState(note: FNote | null | undefined) {return [ isShared, switchShareState ] as const;}++function useShareInfo(note: FNote | null | undefined) {+ const [ linkHref, setLinkHref ] = useState<string>();+ const [ syncServerHost ] = useTriliumOption("syncServerHost");++ function refresh() {+ if (!note) return;+ if (note.noteId === "_share" || !note?.hasAncestor("_share")) {+ setLinkHref(undefined);+ return;+ }++ setLinkHref(buildShareLink(getShareId(note), syncServerHost));+ }++ useEffect(refresh, [ note, syncServerHost ]);+ 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 {+ linkHref,+ scope: getShareScope({+ isElectron: isElectron(),+ isStandalone: !!isStandalone,+ isMobileApp: isMobileApp(),+ syncServerHost+ })+ };+}++/**+ * Where a shared note can be opened from. `local` is the desktop app without a sync server, which+ * serves the page on the loopback address. `preview` is the standalone build without a sync server,+ * which renders the page in its own service worker, so only this browser can open it. `export-only`+ * is the mobile app without a sync server: its link opens nowhere, so the static export is the only+ * way to publish the note. A server cannot tell whether it is reachable from outside, so it always+ * reports `public`.+ */+export function getShareScope({ isElectron, isStandalone, isMobileApp, syncServerHost }: {+ isElectron: boolean;+ isStandalone: boolean;+ isMobileApp: boolean;+ syncServerHost: string | null | undefined;+}): ShareScope {+ if (syncServerHost) {+ return "public";+ }++ if (isMobileApp) {+ return "export-only";+ }++ if (isStandalone) {+ return "preview";+ }++ return isElectron ? "local" : "public";+}++type ShareScope = "public" | "local" | "preview" | "export-only";++function getShareId(note: FNote) {+ if (note.hasOwnedLabel("shareRoot")) {+ return "";+ }++ return note.getOwnedLabelValue("shareAlias") || note.noteId;+}diff --git a/apps/client/src/widgets/layout/TitleRow.tsx b/apps/client/src/widgets/layout/TitleRow.tsxindex 3edb970b24..169654b9da 100644--- a/apps/client/src/widgets/layout/TitleRow.tsx+++ b/apps/client/src/widgets/layout/TitleRow.tsx@@ -3,7 +3,6 @@ import "./TitleRow.css";import clsx from "clsx";import { useEffect, useState } from "preact/hooks";-import { isExperimentalFeatureEnabled } from "../../services/experimental_features";import froca from "../../services/froca";import { t } from "../../services/i18n";import NoteIcon from "../note_icon";@@ -12,7 +11,6 @@ import { useNoteContext, useTriliumEvent } from "../react/hooks";import Icon from "../react/Icon";import NoteBadges from "./NoteBadges";-const isNewLayout = isExperimentalFeatureEnabled("new-layout");/*** What heads a note shown outside a split of its own: icon, title and badges, each editable in place@@ -36,7 +34,7 @@ export default function TitleRow({ compact }: {<div className={className}><NoteIcon /><NoteTitleWidget />- {isNewLayout && <NoteBadges />}+ <NoteBadges /></div>);}diff --git a/apps/client/src/widgets/react/InfoBar.css b/apps/client/src/widgets/react/InfoBar.cssdeleted file mode 100644index cf9774e0b4..0000000000--- a/apps/client/src/widgets/react/InfoBar.css+++ /dev/null@@ -1,23 +0,0 @@-.info-bar {- --link-color: currentColor;-- margin-top: 4px;- contain: unset !important;- padding: 8px 20px;- color: var(--read-only-note-info-bar-color);- font-size: .9em;- cursor: default;- user-select: none;-}--.info-bar-prominent {- background: var(--alert-bar-background, var(--accented-background-color));-}--.info-bar-subtle {- color: var(--muted-text-color);- background: var(--main-background-color);- border-bottom: 1px solid var(--main-border-color);- margin-block: 0;- padding-inline: 22px;-}\ No newline at end of filediff --git a/apps/client/src/widgets/react/InfoBar.tsx b/apps/client/src/widgets/react/InfoBar.tsxdeleted file mode 100644index f1aebbcb51..0000000000--- a/apps/client/src/widgets/react/InfoBar.tsx+++ /dev/null@@ -1,15 +0,0 @@-import "./InfoBar.css";-import { ComponentChildren, CSSProperties } from "preact";--export type InfoBarParams = {- type?: "prominent" | "subtle",- className: string;- style: CSSProperties- children: ComponentChildren;-};--export default function InfoBar({ type = "prominent", className, style, children }: InfoBarParams) {- return <div className={`info-bar ${className} info-bar-${type}`} style={style}>- {children}- </div>-}diff --git a/apps/client/src/widgets/ribbon/Ribbon.css b/apps/client/src/widgets/ribbon/Ribbon.cssindex 72e11fb50f..871dd94a60 100644--- a/apps/client/src/widgets/ribbon/Ribbon.css+++ b/apps/client/src/widgets/ribbon/Ribbon.css@@ -4,12 +4,6 @@z-index: 998;}-/* When content header is floating, ribbon sticks below it */-.scrolling-container:has(.content-header-widget.floating) .ribbon-container {- position: sticky;- top: var(--content-header-height, 100px);-}-.ribbon-top-row {display: flex;min-height: 36px;diff --git a/apps/client/src/widgets/shared_info.css b/apps/client/src/widgets/shared_info.cssdeleted file mode 100644index bc44b49841..0000000000--- a/apps/client/src/widgets/shared_info.css+++ /dev/null@@ -1,7 +0,0 @@-.shared-info-widget {- display: flex;-}--.shared-info-widget button {- margin-inline-start: 8px;-}\ No newline at end of filediff --git a/apps/client/src/widgets/shared_info.spec.tsx b/apps/client/src/widgets/shared_info.spec.tsxdeleted file mode 100644index 7ae7ebf1e1..0000000000--- a/apps/client/src/widgets/shared_info.spec.tsx+++ /dev/null@@ -1,41 +0,0 @@-import { describe, expect, it } from "vitest";--import { buildShareLinkHtml, getShareScope } from "./shared_info";--describe("buildShareLinkHtml", () => {- it("keeps the whole link in the anchor's href and text, whatever characters it carries", () => {- const link = `http://host/share/my alias"x`;- const anchor = parseAnchor(buildShareLinkHtml(link));-- expect(anchor.getAttribute("href")).toBe(link);- expect(anchor.textContent).toBe(link);- expect(anchor.getAttributeNames().sort()).toEqual([ "class", "href" ]);- });-});--describe("getShareScope", () => {- it("tells a public share from a local one, a standalone preview and one only an export publishes", () => {- const syncServerHost = "https://sync.example.com";- const platform = { isElectron: false, isStandalone: false, isMobileApp: false };-- expect(getShareScope({ ...platform, syncServerHost: "" })).toBe("public");- expect(getShareScope({ ...platform, isElectron: true, syncServerHost: "" })).toBe("local");- expect(getShareScope({ ...platform, isElectron: true, syncServerHost })).toBe("public");- expect(getShareScope({ ...platform, isStandalone: true, syncServerHost: "" })).toBe("preview");- expect(getShareScope({ ...platform, isStandalone: true, syncServerHost })).toBe("public");- expect(getShareScope({ ...platform, isStandalone: true, isMobileApp: true, syncServerHost: "" })).toBe("export-only");- expect(getShareScope({ ...platform, isStandalone: true, isMobileApp: true, syncServerHost })).toBe("public");- });-});--function parseAnchor(html: string) {- const container = document.createElement("div");- container.innerHTML = html;-- const anchor = container.querySelector("a");- if (!anchor) {- throw new Error(`No anchor in ${html}`);- }-- return anchor;-}diff --git a/apps/client/src/widgets/shared_info.tsx b/apps/client/src/widgets/shared_info.tsxdeleted file mode 100644index c622c89bbf..0000000000--- a/apps/client/src/widgets/shared_info.tsx+++ /dev/null@@ -1,117 +0,0 @@-import "./shared_info.css";--import { useEffect, useState } from "preact/hooks";--import FNote from "../entities/fnote";-import attributes from "../services/attributes";-import { t } from "../services/i18n";-import { buildShareLink } from "../services/share_link";-import { escapeHtml, isElectron, isMobileApp, isStandalone } from "../services/utils";-import HelpButton from "./react/HelpButton";-import { useNoteContext, useTriliumEvent, useTriliumOption } from "./react/hooks";-import InfoBar from "./react/InfoBar";-import RawHtml from "./react/RawHtml";--export default function SharedInfo() {- const { note } = useNoteContext();- const { scope, link } = useShareInfo(note);-- return (- <InfoBar className="shared-info-widget" type="subtle" style={{display: (!link) ? "none" : undefined}}>- {link && <RawHtml html={t(SCOPE_MESSAGES[scope], { link, format: t("export.format_share_name") })} />}- <HelpButton helpPage="R9pX4DGra2Vt" style={{ width: "24px", height: "24px" }} />- </InfoBar>- );-}--export function useShareInfo(note: FNote | null | undefined) {- const [ link, setLink ] = useState<string>();- const [ linkHref, setLinkHref ] = useState<string>();- const [ syncServerHost ] = useTriliumOption("syncServerHost");-- function refresh() {- if (!note) return;- if (note.noteId === "_share" || !note?.hasAncestor("_share")) {- setLink(undefined);- setLinkHref(undefined);- return;- }-- const link = buildShareLink(getShareId(note), syncServerHost);-- setLink(buildShareLinkHtml(link));- setLinkHref(link);- }-- useEffect(refresh, [ note, syncServerHost ]);- 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 {- link,- linkHref,- scope: getShareScope({- isElectron: isElectron(),- isStandalone: !!isStandalone,- isMobileApp: isMobileApp(),- syncServerHost- })- };-}--/**- * Where a shared note can be opened from. `local` is the desktop app without a sync server, which- * serves the page on the loopback address. `preview` is the standalone build without a sync server,- * which renders the page in its own service worker, so only this browser can open it. `export-only`- * is the mobile app without a sync server: its link opens nowhere, so the static export is the only- * way to publish the note. A server cannot tell whether it is reachable from outside, so it always- * reports `public`.- */-export function getShareScope({ isElectron, isStandalone, isMobileApp, syncServerHost }: {- isElectron: boolean;- isStandalone: boolean;- isMobileApp: boolean;- syncServerHost: string | null | undefined;-}): ShareScope {- if (syncServerHost) {- return "public";- }-- if (isMobileApp) {- return "export-only";- }-- if (isStandalone) {- return "preview";- }-- return isElectron ? "local" : "public";-}--export type ShareScope = "public" | "local" | "preview" | "export-only";--const SCOPE_MESSAGES: Record<ShareScope, string> = {- public: "shared_info.shared_publicly",- local: "shared_info.shared_locally",- preview: "shared_info.shared_preview",- "export-only": "shared_info.shared_export_only"-};--export function buildShareLinkHtml(link: string) {- const escapedLink = escapeHtml(link);-- return `<a href="${escapedLink}" class="external tn-link">${escapedLink}</a>`;-}--function getShareId(note: FNote) {- if (note.hasOwnedLabel("shareRoot")) {- return "";- }-- return note.getOwnedLabelValue("shareAlias") || note.noteId;-}