refactor(touch_bar): move geomap to parent typewidget

This commit is contained in:
Elian Doran 2025-03-08 23:00:05 +02:00
parent 5961e983c7
commit 323f42873f
No known key found for this signature in database
2 changed files with 24 additions and 25 deletions

View File

@ -1,7 +1,6 @@
import type { Map } from "leaflet";
import library_loader from "../services/library_loader.js";
import NoteContextAwareWidget from "./note_context_aware_widget.js";
import type { CommandListenerData } from "../components/app_context.js";
const TPL = `\
<div class="geo-map-widget">
@ -62,27 +61,4 @@ export default class GeoMapWidget extends NoteContextAwareWidget {
});
}
buildTouchBarCommand({ TouchBar }: CommandListenerData<"buildTouchBar">) {
const map = this.map;
if (!map) {
return;
}
return [
new TouchBar.TouchBarSlider({
label: "Zoom",
value: map.getZoom(),
minValue: map.getMinZoom(),
maxValue: map.getMaxZoom(),
change(newValue) {
map.setZoom(newValue);
},
}),
new TouchBar.TouchBarButton({
label: "New geo note",
click: () => this.parent?.triggerEvent("geoMapCreateChildNote", { ntxId: this.ntxId })
})
];
}
}

View File

@ -5,7 +5,7 @@ import TypeWidget from "./type_widget.js";
import server from "../../services/server.js";
import toastService from "../../services/toast.js";
import dialogService from "../../services/dialog.js";
import type { EventData } from "../../components/app_context.js";
import type { CommandListenerData, EventData } from "../../components/app_context.js";
import { t } from "../../services/i18n.js";
import attributes from "../../services/attributes.js";
import asset_path from "../../../../services/asset_path.js";
@ -381,4 +381,27 @@ export default class GeoMapTypeWidget extends TypeWidget {
this.moveMarker(noteId, null);
}
buildTouchBarCommand({ TouchBar }: CommandListenerData<"buildTouchBar">) {
const map = this.geoMapWidget.map;
if (!map) {
return;
}
return [
new TouchBar.TouchBarSlider({
label: "Zoom",
value: map.getZoom(),
minValue: map.getMinZoom(),
maxValue: map.getMaxZoom(),
change(newValue) {
map.setZoom(newValue);
},
}),
new TouchBar.TouchBarButton({
label: "New geo note",
click: () => this.triggerCommand("geoMapCreateChildNote", { ntxId: this.ntxId })
})
];
}
}