forked from Kholid060/inspect-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppProperties.vue
More file actions
82 lines (71 loc) · 2.18 KB
/
AppProperties.vue
File metadata and controls
82 lines (71 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<template>
<div
class="bg-gray-900 rounded-lg p-4 shadow-2xl"
style="width: 300px; z-index: 99999"
ref="container"
>
<ui-element-properties
:properties="state.properties"
v-if="state.properties !== null"
></ui-element-properties>
</div>
</template>
<script>
import {
ref, onMounted, reactive, onUnmounted,
} from 'vue';
import { generateGetBoundingClientRect } from '@/utils/helper';
import GetElementProperties from '@/utils/getElementProperties';
import createPopper from '@/utils/createPopper';
export default {
setup() {
const container = ref(null);
const state = reactive({
properties: null,
popper: null,
});
const virtualElement = {
getBoundingClientRect: generateGetBoundingClientRect(),
};
function mouseMoveHandler({ target, clientX, clientY }) {
const isPaused = document.body.classList.contains('pause');
const isMatchExtensionEl = target.classList.contains('inspect-css');
if (isPaused || isMatchExtensionEl) return container.value.classList.add('hidden');
container.value.classList.remove('hidden');
virtualElement.getBoundingClientRect = generateGetBoundingClientRect(clientX, clientY);
state.popper.update();
if (!target.matches('.hover-element,.inspect-css')) {
const properties = new GetElementProperties(target);
state.properties = properties.getAll();
const element = document.querySelector('.hover-element');
if (element) element.classList.remove('hover-element');
target.classList.add('hover-element');
target.addEventListener(
'mouseleave',
() => {
target.classList.remove('hover-element');
},
{ once: true },
);
}
}
onMounted(() => {
state.popper = createPopper({
container: virtualElement,
content: container.value,
options: {
placement: 'right-end',
},
});
window.addEventListener('mousemove', mouseMoveHandler);
});
onUnmounted(() => {
window.removeEventListener('mousemove', mouseMoveHandler);
});
return {
container,
state,
};
},
};
</script>