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
10 changed files with 76 additions and 18 deletions

View File

@@ -116,7 +116,8 @@ export const ALLOWED_NOTE_TYPES = [
"book", "book",
"webView", "webView",
"code", "code",
"mindMap" "mindMap",
"geoMap"
] as const; ] as const;
export type NoteType = (typeof ALLOWED_NOTE_TYPES)[number]; export type NoteType = (typeof ALLOWED_NOTE_TYPES)[number];

View File

@@ -27,7 +27,8 @@ const NOTE_TYPE_ICONS = {
launcher: "bx bx-link", launcher: "bx bx-link",
doc: "bx bxs-file-doc", doc: "bx bxs-file-doc",
contentWidget: "bx bxs-widget", 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.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.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.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"); const templateNoteIds = await server.get<string[]>("search-templates");

View File

@@ -154,7 +154,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
this.toggleDisabled(this.$findInTextButton, ["text", "code", "book"].includes(note.type)); this.toggleDisabled(this.$findInTextButton, ["text", "code", "book"].includes(note.type));
this.toggleDisabled(this.$showAttachmentsButton, !isInOptions); 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)); 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 AttachmentDetailTypeWidget from "./type_widgets/attachment_detail.js";
import MindMapWidget from "./type_widgets/mind_map.js"; import MindMapWidget from "./type_widgets/mind_map.js";
import { getStylesheetUrl, isSyntaxHighlightEnabled } from "../services/syntax_highlight.js"; import { getStylesheetUrl, isSyntaxHighlightEnabled } from "../services/syntax_highlight.js";
import GeoMapTypeWidget from "./type_widgets/geo_map.js";
const TPL = ` const TPL = `
<div class="note-detail"> <div class="note-detail">
@@ -67,7 +68,8 @@ const typeWidgetClasses = {
contentWidget: ContentWidgetTypeWidget, contentWidget: ContentWidgetTypeWidget,
attachmentDetail: AttachmentDetailTypeWidget, attachmentDetail: AttachmentDetailTypeWidget,
attachmentList: AttachmentListTypeWidget, attachmentList: AttachmentListTypeWidget,
mindMap: MindMapWidget mindMap: MindMapWidget,
geoMap: GeoMapTypeWidget
}; };
export default class NoteDetailWidget extends NoteContextAwareWidget { export default class NoteDetailWidget extends NoteContextAwareWidget {
@@ -147,7 +149,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
// https://github.com/zadam/trilium/issues/2522 // https://github.com/zadam/trilium/issues/2522
this.$widget.toggleClass( this.$widget.toggleClass(
"full-height", "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" this.noteContext.viewScope.viewMode === "attachments"
); );
} }

View File

@@ -41,7 +41,7 @@ export default class NoteWrapperWidget extends FlexContainer {
return; 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()); 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", "launcher": "Launcher",
"doc": "Doc", "doc": "Doc",
"widget": "Widget", "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": { "protect_note": {
"toggle-on": "Protect the note", "toggle-on": "Protect the note",

View File

@@ -14,7 +14,8 @@ const noteTypes = [
{ type: "launcher", defaultMime: "" }, { type: "launcher", defaultMime: "" },
{ type: "doc", defaultMime: "" }, { type: "doc", defaultMime: "" },
{ type: "contentWidget", defaultMime: "" }, { type: "contentWidget", defaultMime: "" },
{ type: "mindMap", defaultMime: "application/json" } { type: "mindMap", defaultMime: "application/json" },
{ type: "geoMap", defaultMime: "application/json" }
]; ];
function getDefaultMimeForNoteType(typeName: string) { function getDefaultMimeForNoteType(typeName: string) {