Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): show shared table collections with the app's table view

Elian Dorane5c83394f590
diff --git a/packages/share-theme/src/content/app_host.tsx b/packages/share-theme/src/content/app_host.tsx
index cff7ca6a53..e338af69ae 100644
--- a/packages/share-theme/src/content/app_host.tsx
+++ b/packages/share-theme/src/content/app_host.tsx
@@ -4,6 +4,7 @@ import TabManager from "@triliumnext/client/src/components/tab_manager.js";
import type FNote from "@triliumnext/client/src/entities/fnote.js";
import linkContextMenu from "@triliumnext/client/src/menus/link_context_menu.js";
import froca from "@triliumnext/client/src/services/froca.js";
+import { parseNavigationStateFromUrl } from "@triliumnext/client/src/services/link.js";
import options, { type OptionValue } from "@triliumnext/client/src/services/options.js";
import { ParentComponent } from "@triliumnext/client/src/widgets/react/react_utils.js";
import type { ComponentChildren } from "preact";
@@ -27,6 +28,8 @@ export interface HostedApp {
parentNoteId: string | null;
/** Opens a note on its shared page, in place of the app's own way. */
openNote(noteId: string): void;
+ /** Whether the note has a shared page to open. */
+ hasLink(noteId: string): boolean;
}
interface ShareAppHostProps {
@@ -39,7 +42,8 @@ interface ShareAppHostProps {
* Hosts app views on a shared page: fills `options` and froca from `payload`, has froca read any
* other note from the share, marks the note `#readOnly` so the views leave out their editing
* controls, starts the part of `appContext` the views rely on and mounts them under a component of
- * their own, as the app mounts every view.
+ * their own, as the app mounts every view. A click on a link into the note tree the views render,
+ * which the app's link handler opens in the app, opens the note's shared page.
*/
export default function ShareAppHost({ noteId, payload, children }: ShareAppHostProps) {
const [ app ] = useState(() => loadPayload(noteId, payload));
@@ -51,6 +55,15 @@ export default function ShareAppHost({ noteId, payload, children }: ShareAppHost
return () => appContext.removeChild(component);
}, [ component ]);
+ useLayoutEffect(() => {
+ if (!app) {
+ return;
+ }
+ const onClick = (event: MouseEvent) => openNoteLink(event, app);
+ document.addEventListener("click", onClick);
+ return () => document.removeEventListener("click", onClick);
+ }, [ app ]);
+
return app && (
<ParentComponent.Provider value={component}>
{children(app)}
@@ -91,10 +104,25 @@ function loadPayload(noteId: string, payload: AppPayload): HostedApp | null {
if (link) {
window.location.href = link;
}
- }
+ },
+ hasLink: (linkedNoteId) => !!links[linkedNoteId]
};
}
+/**
+ * Opens the shared page of the note a clicked link into the note tree names, such as a table's
+ * `.reference-link[data-href="#root/…"]` cell. A link to a note the share does not hold is left alone.
+ */
+function openNoteLink(event: MouseEvent, app: HostedApp) {
+ const link = (event.target as Element | null)?.closest("[data-href], a[href^='#']");
+ const href = link?.getAttribute("data-href") ?? link?.getAttribute("href") ?? undefined;
+ const noteId = parseNavigationStateFromUrl(href).notePath?.split("/").at(-1);
+ if (noteId && app.hasLink(noteId)) {
+ event.preventDefault();
+ app.openNote(noteId);
+ }
+}
+
/**
* Gives `appContext` the part of `start()` the views rely on, a `TabManager` for the note contexts
* their panes register. The app's layout, commands and shortcuts are left out.
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index b91fedc86b..7816cfb1c6 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -964,7 +964,7 @@ function hostInAppView(result: Result, note: SNote, container: string) {
}
/** The view types of the collections the share theme shows with the app's own view. */
-const HOSTED_VIEW_TYPES = new Set([ "board", "calendar", "geoMap" ]);
+const HOSTED_VIEW_TYPES = new Set([ "board", "calendar", "geoMap", "table" ]);
/**
* The options the app's views read to draw a note as the app does, which a shared page receives. Only