Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager: add support for launcher widgets

Adorian Doran2be15113a130
diff --git a/apps/client/src/services/content_manager.spec.ts b/apps/client/src/services/content_manager.spec.ts
index f7055ec2b5..55de1d7eff 100644
--- a/apps/client/src/services/content_manager.spec.ts
+++ b/apps/client/src/services/content_manager.spec.ts
@@ -82,6 +82,7 @@ describe("CONTENT_CATEGORIES", () => {
"sharing",
"frontendScripts",
"widgets",
+ "launcherWidgets",
"renderNotes",
"eventHandlers",
"endpoints",
@@ -333,6 +334,26 @@ describe("setCategoryEnabled", () => {
expect(toggle).toHaveBeenCalledTimes(1);
});
+ it("keeps the two widget mechanisms apart, despite sharing the name", async () => {
+ // `#widget` marks the widget script; `~widget` sits on the launcher that mounts one.
+ const toggle = spyOnToggle();
+ const script = buildNote({ title: "Script", "#widget": "" });
+ const launcher = buildNote({ title: "Launcher", "~widget": "abc123" });
+
+ await setCategoryEnabled(launcher, categoryById("launcherWidgets"), false);
+ expect(toggle).toHaveBeenCalledExactlyOnceWith(launcher, "relation", "widget", false);
+
+ toggle.mockClear();
+ await setCategoryEnabled(script, categoryById("widgets"), false);
+ expect(toggle).toHaveBeenCalledExactlyOnceWith(script, "label", "widget", false);
+
+ // Neither note belongs to the other's category.
+ toggle.mockClear();
+ await setCategoryEnabled(script, categoryById("launcherWidgets"), false);
+ await setCategoryEnabled(launcher, categoryById("widgets"), false);
+ expect(toggle).not.toHaveBeenCalled();
+ });
+
it("does nothing when the note carries none of the category's triggers", async () => {
const toggle = spyOnToggle();
diff --git a/apps/client/src/services/content_manager.ts b/apps/client/src/services/content_manager.ts
index 0452668c32..c5cfa4bf05 100644
--- a/apps/client/src/services/content_manager.ts
+++ b/apps/client/src/services/content_manager.ts
@@ -143,8 +143,16 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [
{
id: "widgets",
titleKey: "content_manager.category_widgets",
+ // The widget script itself, dispatched to a parent widget by the object it returns.
filter: "#widget OR #disabled:widget"
},
+ {
+ id: "launcherWidgets",
+ titleKey: "content_manager.category_launcher_widgets",
+ // A separate mechanism: the relation sits on the launcher that mounts the widget, not on the
+ // widget script, so these rows are launchers rather than scripts.
+ filter: "~widget OR ~disabled:widget"
+ },
{
id: "renderNotes",
titleKey: "content_manager.category_render_notes",
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 05d36e6a5a..22c15f744f 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2603,6 +2603,7 @@
"category_backend_scripts": "Backend Scripts",
"category_frontend_scripts": "Front-end Scripts",
"category_widgets": "Custom Widgets",
+ "category_launcher_widgets": "Launcher Widgets",
"category_render_notes": "Render Notes",
"category_themes": "Custom Themes",
"category_custom_css": "Custom CSS",