import { Directive, DirectiveBinding } from 'vue'; export const vStudio: Directive = { mounted(el: HTMLElement, binding: DirectiveBinding) { // binding.value should be the path string e.g. "elements.0.title" // We use a data attribute to store the path for debugging/logic el.dataset.studioPath = binding.value; // Hover Effect el.addEventListener('mouseenter', () => { // Only if studio mode is enabled? // We can check a global class on body or just always emit and let parent decide. // Better: check if a specific class exists on a parent, or use a store if possible (hard in directive). // For now, let's just add a class that we can style in CSS only when .studio-mode is active. el.classList.add('studio-hover'); }); el.addEventListener('mouseleave', () => { el.classList.remove('studio-hover'); }); // Click Handler el.addEventListener('click', (e) => { // We want to stop propagation so we select the most specific element e.stopPropagation(); const rect = el.getBoundingClientRect(); const event = new CustomEvent('studio-select', { bubbles: true, detail: { path: binding.value, rect: rect } }); el.dispatchEvent(event); }); }, updated(el: HTMLElement, binding: DirectiveBinding) { el.dataset.studioPath = binding.value; } };