File size: 4,852 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<script lang="ts">
import PluginSourceIcon from '@front/features/plugin/PluginSourceIcon.vue'

import type { PropType } from 'vue'
import { computed, defineComponent } from 'vue'
import { useDarkMode } from '@front/util/theme'
import { boostColor, dimColor, toStrHex } from '@front/util/color'
import type { Layer } from './composable'

export default defineComponent({
  components: {
    PluginSourceIcon,
  },

  props: {
    layer: {
      type: Object as PropType<Layer>,
      required: true,
    },

    hover: {
      type: Boolean,
      default: false,
    },

    selected: {
      type: Boolean,
      default: false,
    },
  },
  emits: ['select', 'hide'],
  setup(props, { emit }) {
    function select() {
      emit('select')
    }

    const { darkMode } = useDarkMode()

    const color = computed(() => toStrHex(props.layer.color))
    const dimmedColor = computed(() => toStrHex(dimColor(props.layer.color, darkMode.value)))
    const boostedColot = computed(() => toStrHex(boostColor(props.layer.color, darkMode.value)))

    return {
      select,
      color,
      dimmedColor,
      boostedColot,
    }
  },
})
</script>

<template>
  <div
    class="relative group cursor-pointer"
    @click="select()"
  >
    <div
      class="border-b border-gray-200 dark:border-gray-700"
      :style="{
        height: `${(layer.height + 1) * 16}px`,
      }"
    >
      <div class="flex items-center space-x-2 px-2 py-1">
        <div
          class="flex-none w-3 h-3 relative"
          :class="{
            'opacity-50': layer.id === 'performance' && !$shared.performanceMonitoringEnabled,
          }"
        >
          <div
            class="absolute inset-0 rounded-full transition-colors duration-300 ease-in-out"
            :style="{
              backgroundColor: `#${selected ? boostedColot : color}`,
            }"
          />
          <transition
            enter-active-class="transform transition-transform duration-300 ease-in-out"
            leave-active-class="transform transition-transform duration-300 ease-in-out"
            enter-class="scale-0"
            leave-to-class="scale-0"
          >
            <div
              v-if="selected"
              class="absolute inset-0.5 rounded-full z-10"
              :style="{
                backgroundColor: `#${dimmedColor}`,
              }"
            />
          </transition>
        </div>

        <div class="flex-1 overflow-hidden flex items-center space-x-2">
          <span
            class="truncate text-sm"
            :class="{
              'opacity-50': (
                layer.id === 'component-event' && !$shared.componentEventsEnabled
                || layer.id === 'performance' && !$shared.performanceMonitoringEnabled
              ),
            }"
            :style="{
              color: selected ? `#${color}` : undefined,
            }"
          >{{ layer.label }}</span>

          <PluginSourceIcon
            v-if="layer.pluginId"
            :plugin-id="layer.pluginId"
            @click.stop
          />
        </div>

        <div
          v-if="hover"
          class="flex items-center space-x-1"
        >
          <VueButton
            v-if="layer.id === 'component-event'"
            class="text-xs px-1 py-0 h-5 hover:opacity-80"
            :style="{
              backgroundColor: `#${color}28`,
            }"
            @click.stop="$shared.componentEventsEnabled = !$shared.componentEventsEnabled"
          >
            {{ $shared.componentEventsEnabled ? 'Disable' : 'Enable' }}
          </VueButton>

          <VueButton
            v-if="layer.id === 'performance'"
            class="text-xs px-1 py-0 h-5 hover:opacity-80"
            :style="{
              backgroundColor: `#${color}28`,
            }"
            @click.stop="$shared.performanceMonitoringEnabled = !$shared.performanceMonitoringEnabled"
          >
            {{ $shared.performanceMonitoringEnabled ? 'Disable' : 'Enable' }}
          </VueButton>

          <VueButton
            class="text-xs px-1 py-0 h-5 hover:opacity-80"
            :style="{
              backgroundColor: `#${color}28`,
            }"
          >
            Select
          </VueButton>

          <VueButton
            v-tooltip="'Hide layer'"
            class="leading-[0] p-0 w-5 h-5 hover:opacity-80"
            :style="{
              backgroundColor: `#${color}28`,
            }"
            @click.stop="$emit('hide')"
          >
            <VueIcon
              icon="visibility_off"
              class="w-3 h-3"
            />
          </VueButton>
        </div>
      </div>
    </div>

    <div
      v-if="hover || selected"
      class="absolute inset-0 pointer-events-none"
      :style="{
        backgroundColor: `#${color}`,
        opacity: hover ? 0.1 : 0.05,
      }"
    />
  </div>
</template>