mirror of
https://github.com/ccmdi/obsidian-map-plus.git
synced 2026-07-22 06:43:14 +00:00
refactor: remove hardcoded styles / remove unnecessary async
This commit is contained in:
parent
1b3ad1df3a
commit
c73c7dd9ca
4 changed files with 21 additions and 13 deletions
|
|
@ -404,7 +404,7 @@ export function updateMapPoints(deck: Deck<MapViewType[]>, points: MapPoint[], c
|
|||
}
|
||||
}
|
||||
|
||||
export async function createMapRenderer(config: MapRendererOptions): Promise<Deck<MapViewType[]>> {
|
||||
export function createMapRenderer(config: MapRendererOptions): Deck<MapViewType[]> {
|
||||
const { containerEl, points, app, settings, tagSettings, options } = config;
|
||||
containerEl.addClass('map-container');
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ export class MapBasesView extends BasesView {
|
|||
if (!boundsStr || typeof boundsStr !== 'string') return undefined;
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const parsed = JSON.parse(boundsStr);
|
||||
if (Array.isArray(parsed) && parsed.length === 2 &&
|
||||
Array.isArray(parsed[0]) && parsed[0].length === 2 &&
|
||||
|
|
@ -191,7 +192,7 @@ export class MapBasesView extends BasesView {
|
|||
}
|
||||
}
|
||||
|
||||
protected async renderMap(): Promise<void> {
|
||||
protected renderMap(): void {
|
||||
if (!this.data) {
|
||||
this.containerEl.removeClass('is-loading');
|
||||
return;
|
||||
|
|
@ -269,7 +270,7 @@ export class MapBasesView extends BasesView {
|
|||
zoomToUse = this.getDefaultZoom();
|
||||
}
|
||||
|
||||
this.deck = await createMapRenderer({
|
||||
this.deck = createMapRenderer({
|
||||
containerEl: this.mapEl,
|
||||
points,
|
||||
app: this.app,
|
||||
|
|
|
|||
|
|
@ -321,11 +321,9 @@ export class MapTimelineBasesView extends MapBasesView {
|
|||
let offsetX = 0;
|
||||
let offsetY = 0;
|
||||
|
||||
// Add drag handle cursor hint
|
||||
element.style.cursor = 'move';
|
||||
element.addClass('map-draggable');
|
||||
|
||||
const onMouseDown = (e: MouseEvent) => {
|
||||
// Only start drag on container itself, not on inputs/buttons/slider
|
||||
const target = e.target as HTMLElement;
|
||||
if (target.tagName === 'INPUT' || target.tagName === 'SELECT' || target.tagName === 'BUTTON') {
|
||||
return;
|
||||
|
|
@ -333,13 +331,11 @@ export class MapTimelineBasesView extends MapBasesView {
|
|||
|
||||
isDragging = true;
|
||||
const rect = element.getBoundingClientRect();
|
||||
const containerRect = this.mapEl.getBoundingClientRect();
|
||||
|
||||
offsetX = e.clientX - rect.left;
|
||||
offsetY = e.clientY - rect.top;
|
||||
|
||||
element.style.position = 'absolute';
|
||||
element.style.zIndex = '1000';
|
||||
element.addClass('dragging');
|
||||
|
||||
e.preventDefault();
|
||||
};
|
||||
|
|
@ -357,10 +353,9 @@ export class MapTimelineBasesView extends MapBasesView {
|
|||
x = Math.max(0, Math.min(x, containerRect.width - elementRect.width));
|
||||
y = Math.max(0, Math.min(y, containerRect.height - elementRect.height));
|
||||
|
||||
element.style.left = `${x}px`;
|
||||
element.style.top = `${y}px`;
|
||||
element.style.bottom = 'auto';
|
||||
element.style.right = 'auto';
|
||||
element.setCssProps({'left': `${x}px`});
|
||||
element.setCssProps({'top': `${y}px`});
|
||||
element.addClass('move');
|
||||
};
|
||||
|
||||
const onMouseUp = () => {
|
||||
|
|
|
|||
12
styles.css
12
styles.css
|
|
@ -546,4 +546,16 @@
|
|||
color: var(--text-normal);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.map-draggable {
|
||||
cursor: move;
|
||||
& .dragging {
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
}
|
||||
& .move {
|
||||
bottom: auto;
|
||||
right: auto;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue