You've already forked obsidian-visualiser
Add edge dragging, autofocus on inputs and limit neighbor distance lookup during snap fetching
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="absolute overflow-visible">
|
||||
<input v-if="editing" @click="e => e.stopImmediatePropagation()" :style="{ transform: `${labelPos} translate(-50%, -50%)` }" class="relative bg-light-20 dark:bg-dark-20 border border-light-35 dark:border-dark-35 px-4 py-2 z-20" v-model="edge.label" />
|
||||
<div class="absolute overflow-visible group">
|
||||
<input v-autofocus v-if="editing" @click="e => e.stopImmediatePropagation()" :style="{ transform: `${labelPos} translate(-50%, -50%)` }" class="relative bg-light-20 dark:bg-dark-20 border border-light-35 dark:border-dark-35 px-4 py-2 z-20" v-model="edge.label" />
|
||||
<div v-else-if="edge.label" :style="{ transform: `${labelPos} translate(-50%, -50%)` }" class="relative bg-light-20 dark:bg-dark-20 border border-light-35 dark:border-dark-35 px-4 py-2 z-20" @click.left="select" @dblclick.left="edit">{{ edge.label }}</div>
|
||||
<svg ref="dom" class="absolute top-0 overflow-visible h-px w-px">
|
||||
<g :style="{'--canvas-color': edge.color?.hex}" class="z-0">
|
||||
@@ -10,7 +10,9 @@
|
||||
<path :style="`stroke-width: calc(${focusing ? 6 : 3}px * var(--zoom-multiplier));`" style="stroke-linecap: butt;" :class="style.stroke" class="transition-[stroke-width] fill-none stroke-[4px]" :d="path.path"></path>
|
||||
<path style="stroke-width: calc(22px * var(--zoom-multiplier));" class="fill-none transition-opacity z-30 opacity-0 hover:opacity-25" :class="[style.stroke, { 'opacity-25': focusing }]" :d="path.path" @click="select" @dblclick="edit"></path>
|
||||
</g>
|
||||
</svg>
|
||||
</svg>
|
||||
<span v-if="focusing && !editing" :style="`transform: translate(${path.from.x}px, ${path.from.y}px) translate(-50%, -50%) scale(var(--zoom-multiplier))`" @mousedown.left="(e) => dragEdge(e, 'from')" :class="style.fill" class="hidden group-hover:block z-[31] absolute rounded-full border-2 border-light-70 dark:border-dark-70 bg-light-30 dark:bg-dark-30 w-6 h-6"></span>
|
||||
<span v-if="focusing && !editing" :style="`transform: translate(${path.to.x}px, ${path.to.y}px) translate(-50%, -50%) scale(var(--zoom-multiplier))`" @mousedown.left="(e) => dragEdge(e, 'to')" :class="style.fill" class="hidden group-hover:block z-[31] absolute rounded-full border-2 border-light-70 dark:border-dark-70 bg-light-30 dark:bg-dark-30 w-6 h-6"></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -34,7 +36,7 @@ const { edge, nodes } = defineProps<{
|
||||
const emit = defineEmits<{
|
||||
(e: 'select', id: Element): void,
|
||||
(e: 'edit', id: Element): void,
|
||||
(e: 'move', id: string, from: string, to: string): void,
|
||||
(e: 'drag', id: string, _e: MouseEvent, origin: 'from' | 'to'): void,
|
||||
(e: 'input', id: string, text?: string): void,
|
||||
}>();
|
||||
|
||||
@@ -64,6 +66,11 @@ function edit(e: Event) {
|
||||
e.stopImmediatePropagation();
|
||||
emit('edit', { type: 'edge', id: edge.id });
|
||||
}
|
||||
function dragEdge(e: MouseEvent, origin: 'from' | 'to') {
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
emit('drag', edge.id, e, origin);
|
||||
}
|
||||
function unselect() {
|
||||
if(editing.value)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<Editor v-model="node.text" autofocus />
|
||||
</div>
|
||||
<div v-if="!editing && node.type === 'group' && node.label !== undefined" @click.left="(e) => selectNode(e)" @dblclick.left="(e) => editNode(e)" :class="style.border" style="max-width: 100%; font-size: calc(18px * var(--zoom-multiplier))" class="origin-bottom-left tracking-wider border-4 truncate inline-block text-light-100 dark:text-dark-100 absolute bottom-[100%] mb-2 px-2 py-1 font-thin">{{ node.label }}</div>
|
||||
<input v-else-if="editing && node.type === 'group'" v-model="node.label" @click="e => e.stopImmediatePropagation()" autofocus :class="[style.border, style.outline]" style="max-width: 100%; font-size: calc(18px * var(--zoom-multiplier))" class="origin-bottom-left tracking-wider border-4 truncate inline-block text-light-100 dark:text-dark-100 absolute bottom-[100%] appearance-none bg-transparent outline-4 mb-2 px-2 py-1 font-thin min-w-4" />
|
||||
<input v-else-if="editing && node.type === 'group'" v-model="node.label" @click="e => e.stopImmediatePropagation()" v-autofocus :class="[style.border, style.outline]" style="max-width: 100%; font-size: calc(18px * var(--zoom-multiplier))" class="origin-bottom-left tracking-wider border-4 truncate inline-block text-light-100 dark:text-dark-100 absolute bottom-[100%] appearance-none bg-transparent outline-4 mb-2 px-2 py-1 font-thin min-w-4" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -119,7 +119,7 @@ function resizeNode(e: MouseEvent, x: number, y: number, w: number, h: number) {
|
||||
window.addEventListener('mousemove', resizemove);
|
||||
window.addEventListener('mouseup', resizeend);
|
||||
}
|
||||
function dragEdge(e: Event, direction: Direction) {
|
||||
function dragEdge(e: MouseEvent, direction: Direction) {
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
emit('edge', node.id, e, direction)
|
||||
|
||||
Reference in New Issue
Block a user