feat(geomap): create geomap note type

This commit is contained in:
Elian Doran 2025-01-20 18:45:56 +02:00
parent 7f15f8a7de
commit e1952fe6b8
No known key found for this signature in database
10 changed files with 76 additions and 18 deletions

View File

@ -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];

View File

@ -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"
};
/**

View File

@ -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");

View File

@ -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));

View File

@ -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)
}
}

View File

@ -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/2522
this.$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>
`,

View File

@ -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());

View File

@ -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();
}
}

View File

@ -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",

View File

@ -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) {