Skip to content

Commit 7764719

Browse files
feat(Definitions): Highlight all instance when hovering a controller definition
1 parent beadcbf commit 7764719

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

src/client/Inspector.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function createHighlightBox(target: HTMLElement, title?: string) {
1616
highlightBox.style.height = `${targetBoundingClientRect.height}px`;
1717
highlightBox.style.backgroundColor = 'rgba(119, 232, 185, 0.5)';
1818
highlightBox.style.borderColor = 'rgba(119, 232, 185, 1)';
19-
highlightBox.style.borderWidth = '1px';
19+
highlightBox.style.borderWidth = '2px';
2020
highlightBox.style.borderStyle = 'dashed';
2121

2222
if (title) {
@@ -78,19 +78,21 @@ function createHighlightBox(target: HTMLElement, title?: string) {
7878
}
7979

8080
export class Inspector {
81-
highlightElement(args: any) {
82-
const { selector, title } = args;
83-
if (!selector) return;
81+
highlightElements(args: { elements: { selector: string; title?: string }[] }) {
82+
const { elements } = args;
83+
if (!elements?.length) return;
8484

85-
const highlightedElement = document.querySelector(selector) as HTMLElement;
86-
if (!highlightedElement) return;
85+
elements.forEach(element => {
86+
const highlightedElement = document.querySelector(element.selector) as HTMLElement;
87+
if (!highlightedElement) return;
8788

88-
const highlightBox = createHighlightBox(highlightedElement, title);
89+
const highlightBox = createHighlightBox(highlightedElement, element.title);
8990

90-
document.body.appendChild(highlightBox);
91+
document.body.appendChild(highlightBox);
92+
});
9193
}
9294

93-
stopHighlightElement() {
95+
stopHighlightElements() {
9496
const highlightBoxes = document.querySelectorAll('.stimulus-devtools-highlight');
9597
highlightBoxes.forEach(highlightBoxe => {
9698
highlightBoxe.remove();

src/components/stimulus/definition/StimulusControllerDefinitionsRow.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
class="group inline-flex min-w-full cursor-pointer items-center gap-x-3 border-b border-dashed px-3 py-2 text-sm hover:bg-muted/60 dark:border-b-neutral-900"
44
:class="{ 'is-selected !bg-muted': selectedDefinition?.identifier === definition.identifier }"
55
@click="selectDefinition(definition.identifier)"
6+
@mouseenter="
7+
executeAction(Action.HighlightElements, {
8+
elements: definition.instances.map(instance => ({ selector: instance.uidSelector })),
9+
})
10+
"
11+
@mouseleave="executeAction(Action.StopHighlightElements)"
612
>
713
<div
814
class="inline-flex shrink-0 items-center gap-x-1.5 opacity-70 group-hover:opacity-100 group-[.is-selected]:opacity-100"
@@ -38,6 +44,10 @@ import { computed } from 'vue';
3844
import { Zap } from 'lucide-vue-next';
3945
import { useControllerDefinitions } from '@/composables/stimulus/useControllerDefinitions.ts';
4046
import { ParsedStimulusControllerDefinition } from '@/types/stimulus.ts';
47+
import { Action } from '@/enum';
48+
import { useBridge } from '@/composables/useBridge.ts';
49+
50+
const { executeAction } = useBridge();
4151
4252
const { selectedDefinition, selectDefinition } = useControllerDefinitions();
4353

src/components/stimulus/instance/StimulusControllerInstancesRow.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
class="group relative z-0 inline-flex min-w-full cursor-pointer items-center px-3 py-0.5 hover:bg-accent/60"
44
:class="{ 'is-selected !bg-accent': selected }"
55
@click.prevent="$emit('select')"
6-
@mouseenter="executeAction(Action.HighlightElement, { selector: instance.uidSelector, title: instance.identifier })"
7-
@mouseleave="executeAction(Action.StopHighlightElement)"
6+
@mouseenter="
7+
executeAction(Action.HighlightElements, {
8+
elements: [{ selector: instance.uidSelector, title: instance.identifier }],
9+
})
10+
"
11+
@mouseleave="executeAction(Action.StopHighlightElements)"
812
>
913
<span v-show="selected" class="absolute inset-y-0 left-0 w-[1px] bg-primary" />
1014
<div class="flex w-full items-center opacity-70 group-hover:opacity-100 group-[.is-selected]:opacity-100">

src/components/stimulus/members/outlets/StimulusControllerOutletsRow.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ const toggle = () => {
108108
const canExpand = computed(() => !!props.outlet.references.length);
109109
110110
const handleItemMouseEnter = (item: StimulusControllerOutletReference) => {
111-
executeAction(Action.HighlightElement, { selector: item.uidSelector, title: props.outlet.name });
111+
executeAction(Action.HighlightElements, { elements: [{ selector: item.uidSelector, title: props.outlet.name }] });
112112
};
113113
114114
const handleItemMouseLeave = () => {
115-
executeAction(Action.StopHighlightElement);
115+
executeAction(Action.StopHighlightElements);
116116
};
117117
</script>

src/components/stimulus/members/targets/StimulusControllerTargetsRow.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ const toggle = () => {
8888
};
8989
9090
const handleItemMouseEnter = (element: StimulusControllerTargetElement) => {
91-
executeAction(Action.HighlightElement, { selector: element.uidSelector, title: props.target.name });
91+
executeAction(Action.HighlightElements, { elements: [{ selector: element.uidSelector, title: props.target.name }] });
9292
};
9393
9494
const handleItemMouseLeave = () => {
95-
executeAction(Action.StopHighlightElement);
95+
executeAction(Action.StopHighlightElements);
9696
};
9797
</script>

src/enum/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export enum Action {
2424
UpdateInstanceClasses = 'updateInstanceClasses',
2525
UpdateValue = 'updateValue',
2626

27-
HighlightElement = 'highlightElement',
28-
StopHighlightElement = 'stopHighlightElement',
27+
HighlightElements = 'highlightElements',
28+
StopHighlightElements = 'stopHighlightElements',
2929
}

0 commit comments

Comments
 (0)