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
feat(geomap): create geomap note type
Elian Dorane1952fe6b8d3
diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.tsindex d2d327541a..89fa369538 100644--- a/src/becca/entities/rows.ts+++ b/src/becca/entities/rows.ts@@ -116,7 +116,8 @@ export const ALLOWED_NOTE_TYPES = ["book","webView","code",- "mindMap"+ "mindMap",+ "geoMap"] as const;export type NoteType = (typeof ALLOWED_NOTE_TYPES)[number];diff --git a/src/public/app/entities/fnote.ts b/src/public/app/entities/fnote.tsindex 4da479d16c..1071ce1a48 100644--- a/src/public/app/entities/fnote.ts+++ b/src/public/app/entities/fnote.ts@@ -27,7 +27,8 @@ const NOTE_TYPE_ICONS = {launcher: "bx bx-link",doc: "bx bxs-file-doc",contentWidget: "bx bxs-widget",- mindMap: "bx bx-sitemap"+ mindMap: "bx bx-sitemap",+ geoMap: "bx bx-map-alt"};/**diff --git a/src/public/app/services/note_types.ts b/src/public/app/services/note_types.tsindex 433931ae0d..7aebd48ffb 100644--- a/src/public/app/services/note_types.ts+++ b/src/public/app/services/note_types.ts@@ -18,7 +18,8 @@ async function getNoteTypeItems(command?: NoteTypeCommandNames) {{ title: t("note_types.mermaid-diagram"), command, type: "mermaid", uiIcon: "bx bx-selection" },{ title: t("note_types.canvas"), command, type: "canvas", uiIcon: "bx bx-pen" },{ title: t("note_types.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" },- { title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" }+ { title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" },+ { title: t("note_types.geo-map"), command, type: "geoMap", uiIcon: "bx bx-map-alt" },];const templateNoteIds = await server.get<string[]>("search-templates");diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.jsindex e2efce0348..c5c1587ad5 100644--- a/src/public/app/widgets/buttons/note_actions.js+++ b/src/public/app/widgets/buttons/note_actions.js@@ -42,7 +42,7 @@ const TPL = `<li data-trigger-command="convertNoteIntoAttachment" class="dropdown-item"><span class="bx bx-paperclip"></span> ${t("note_actions.convert_into_attachment")}</li>-+<li data-trigger-command="renderActiveNote" class="dropdown-item render-note-button"><span class="bx bx-extension"></span> ${t("note_actions.re_render_note")}<kbd data-command="renderActiveNote"></kbd></li>@@ -54,15 +54,15 @@ const TPL = `<li data-trigger-command="printActiveNote" class="dropdown-item print-active-note-button"><span class="bx bx-printer"></span> ${t("note_actions.print_note")}<kbd data-command="printActiveNote"></kbd></li>-+<div class="dropdown-divider"></div>-+<li class="dropdown-item import-files-button"><span class="bx bx-import"></span> ${t("note_actions.import_files")}</li><li class="dropdown-item export-note-button"><span class="bx bx-export"></span> ${t("note_actions.export_note")}</li>-+<div class="dropdown-divider"></div>@@ -79,7 +79,7 @@ const TPL = `<span class="bx bx-code"></span> ${t("note_actions.note_source")}<kbd data-command="showNoteSource"></kbd></li>-+<div class="dropdown-divider"></div>@@ -89,10 +89,10 @@ const TPL = `<li class="dropdown-item delete-note-button"><span class="bx bx-trash destructive-action-icon"></span> ${t("note_actions.delete_note")}</li>-+<div class="dropdown-divider"></div>-+<li data-trigger-command="showAttachments" class="dropdown-item show-attachments-button"><span class="bx bx-paperclip"></span> ${t("note_actions.note_attachments")}<kbd data-command="showAttachments"></kbd></li>@@ -154,7 +154,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {this.toggleDisabled(this.$findInTextButton, ["text", "code", "book"].includes(note.type));this.toggleDisabled(this.$showAttachmentsButton, !isInOptions);- this.toggleDisabled(this.$showSourceButton, ["text", "code", "relationMap", "mermaid", "canvas", "mindMap"].includes(note.type));+ this.toggleDisabled(this.$showSourceButton, ["text", "code", "relationMap", "mermaid", "canvas", "mindMap", "geoMap"].includes(note.type));this.toggleDisabled(this.$printActiveNoteButton, ["text", "code"].includes(note.type));diff --git a/src/public/app/widgets/geo_map.ts b/src/public/app/widgets/geo_map.tsnew file mode 100644index 0000000000..32b6db6b11--- /dev/null+++ b/src/public/app/widgets/geo_map.ts@@ -0,0 +1,18 @@+import NoteContextAwareWidget from "./note_context_aware_widget.js";++const TPL = `\+<div class="geo-map-widget">+ Map goes here.+</div>`++export default class GeoMapWidget extends NoteContextAwareWidget {++ constructor(widgetMode: "type") {+ super();+ }++ doRender() {+ this.$widget = $(TPL)+ }++}diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.jsindex 22850c35e5..6ffed4514f 100644--- a/src/public/app/widgets/note_detail.js+++ b/src/public/app/widgets/note_detail.js@@ -31,6 +31,7 @@ import AttachmentListTypeWidget from "./type_widgets/attachment_list.js";import AttachmentDetailTypeWidget from "./type_widgets/attachment_detail.js";import MindMapWidget from "./type_widgets/mind_map.js";import { getStylesheetUrl, isSyntaxHighlightEnabled } from "../services/syntax_highlight.js";+import GeoMapTypeWidget from "./type_widgets/geo_map.js";const TPL = `<div class="note-detail">@@ -39,7 +40,7 @@ const TPL = `font-family: var(--detail-font-family);font-size: var(--detail-font-size);}-+.note-detail.full-height {height: 100%;}@@ -67,7 +68,8 @@ const typeWidgetClasses = {contentWidget: ContentWidgetTypeWidget,attachmentDetail: AttachmentDetailTypeWidget,attachmentList: AttachmentListTypeWidget,- mindMap: MindMapWidget+ mindMap: MindMapWidget,+ geoMap: GeoMapTypeWidget};export default class NoteDetailWidget extends NoteContextAwareWidget {@@ -147,7 +149,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {// https://github.com/zadam/trilium/issues/2522this.$widget.toggleClass("full-height",- (!this.noteContext.hasNoteList() && ["canvas", "webView", "noteMap", "mindMap"].includes(this.type) && this.mime !== "text/x-sqlite;schema=trilium") ||+ (!this.noteContext.hasNoteList() && ["canvas", "webView", "noteMap", "mindMap", "geoMap"].includes(this.type) && this.mime !== "text/x-sqlite;schema=trilium") ||this.noteContext.viewScope.viewMode === "attachments");}@@ -276,7 +278,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {<script src="${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js"></script><script>document.body.className += ' ck-content printed-content';-+renderMathInElement(document.body, {trust: true});</script>`,diff --git a/src/public/app/widgets/note_wrapper.js b/src/public/app/widgets/note_wrapper.jsindex baf444e617..9f045675c0 100644--- a/src/public/app/widgets/note_wrapper.js+++ b/src/public/app/widgets/note_wrapper.js@@ -41,7 +41,7 @@ export default class NoteWrapperWidget extends FlexContainer {return;}- this.$widget.toggleClass("full-content-width", ["image", "mermaid", "book", "render", "canvas", "webView", "mindMap"].includes(note.type) || !!note?.isLabelTruthy("fullContentWidth"));+ this.$widget.toggleClass("full-content-width", ["image", "mermaid", "book", "render", "canvas", "webView", "mindMap", "geoMap"].includes(note.type) || !!note?.isLabelTruthy("fullContentWidth"));this.$widget.addClass(note.getCssClass());diff --git a/src/public/app/widgets/type_widgets/geo_map.ts b/src/public/app/widgets/type_widgets/geo_map.tsnew file mode 100644index 0000000000..f52a7a8e09--- /dev/null+++ b/src/public/app/widgets/type_widgets/geo_map.ts@@ -0,0 +1,33 @@+import type FNote from "../../entities/fnote.js";+import GeoMapWidget from "../geo_map.js";+import TypeWidget from "./type_widget.js"++const TPL = `<div class="note-detail-geo-map note-detail-printable"></div>`;++export default class GeoMapTypeWidget extends TypeWidget {++ private geoMapWidget: GeoMapWidget;++ static getType() {+ return "geoMap";+ }++ constructor() {+ super();++ this.geoMapWidget = new GeoMapWidget("type");+ this.child(this.geoMapWidget);+ }++ doRender() {+ this.$widget = $(TPL);+ this.$widget.append(this.geoMapWidget.render());++ super.doRender();+ }++ async doRefresh(note: FNote) {+ await this.geoMapWidget.refresh();+ }++}diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.jsonindex 1c65b78fab..4a24da87a1 100644--- a/src/public/translations/en/translation.json+++ b/src/public/translations/en/translation.json@@ -1409,7 +1409,8 @@"launcher": "Launcher","doc": "Doc","widget": "Widget",- "confirm-change": "It is not recommended to change note type when note content is not empty. Do you want to continue anyway?"+ "confirm-change": "It is not recommended to change note type when note content is not empty. Do you want to continue anyway?",+ "geo-map": "Geo Map (beta)"},"protect_note": {"toggle-on": "Protect the note",diff --git a/src/services/note_types.ts b/src/services/note_types.tsindex 4a810b6a2c..3e086acf4f 100644--- a/src/services/note_types.ts+++ b/src/services/note_types.ts@@ -14,7 +14,8 @@ const noteTypes = [{ type: "launcher", defaultMime: "" },{ type: "doc", defaultMime: "" },{ type: "contentWidget", defaultMime: "" },- { type: "mindMap", defaultMime: "application/json" }+ { type: "mindMap", defaultMime: "application/json" },+ { type: "geoMap", defaultMime: "application/json" }];function getDefaultMimeForNoteType(typeName: string) {