File size: 4,444 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
<script lang="ts">
import StateInspector from '@front/features/inspector/StateInspector.vue'
import EmptyPane from '@front/features/layout/EmptyPane.vue'

import { computed, defineComponent, ref, watch } from 'vue'
import { SharedData, copyToClipboard, getComponentDisplayName } from '@vue-devtools/shared-utils'
import { onKeyDown } from '@front/util/keyboard'
import RenderCode from './RenderCode.vue'
import { useSelectedComponent } from './composable'

export default defineComponent({
  components: {
    StateInspector,
    EmptyPane,
    RenderCode,
  },

  setup() {
    const selectedComponent = useSelectedComponent()
    const displayName = computed(() => getComponentDisplayName(selectedComponent.data.value?.name ?? '', SharedData.componentNameStyle))

    const showRenderCode = ref(false)

    // Auto scroll
    const { selectedComponentId } = selectedComponent
    const inspector = ref<typeof StateInspector>()
    watch(selectedComponentId, () => {
      if (inspector.value?.$el) {
        inspector.value.$el.scrollTop = 0
      }
    })

    // State filter
    const stateFilterInput = ref()
    onKeyDown((event) => {
      // ∂ - the result key in Mac with altKey pressed
      if ((event.key === 'd' || event.key === '∂') && event.altKey) {
        stateFilterInput.value.focus()
        return false
      }
    }, true)

    const sameApp = computed(() => selectedComponent.data.value?.id.split(':')[0] === selectedComponentId.value?.split(':')[0])

    // Copy component name
    const showCopiedName = ref(false)
    let copiedNameTimeout
    function copyName() {
      copyToClipboard(displayName.value)
      showCopiedName.value = true
      clearTimeout(copiedNameTimeout)
      copiedNameTimeout = setTimeout(() => {
        showCopiedName.value = false
      }, 1000)
    }

    return {
      ...selectedComponent,
      displayName,
      showRenderCode,
      inspector,
      stateFilterInput,
      sameApp,
      copyName,
      showCopiedName,
    }
  },
})
</script>

<template>
  <div
    v-if="data && sameApp"
    class="h-full flex flex-col relative"
  >
    <div class="px-2 h-8 box-content border-b border-gray-200 dark:border-gray-700 flex items-center flex-none">
      <VTooltip
        :shown="showCopiedName"
        :triggers="[]"
        :delay="0"
        class="flex items-baseline cursor-pointer"
        @click="copyName()"
      >
        <span class="text-gray-500">&lt;</span>
        <span class="text-green-500">
          {{ displayName }}
        </span>
        <span class="text-gray-500">&gt;</span>

        <template #popper>
          Copied!
        </template>
      </VTooltip>

      <VueInput
        ref="stateFilterInput"
        v-model="stateFilter"
        v-tooltip="{
          content: $t('StateInspector.filter.tooltip'),
          html: true,
        }"
        icon-left="search"
        placeholder="Filter state..."
        class="search flex-1 flat !min-w-0"
      />

      <VueButton
        v-tooltip="'Scroll to component'"
        icon-left="preview"
        class="flat icon-button flex-none"
        @click="scrollToComponent()"
      />

      <VueButton
        v-tooltip="'Show render code'"
        icon-left="code"
        class="flat icon-button flex-none"
        @click="showRenderCode = true"
      />

      <VueButton
        v-if="$isChrome"
        v-tooltip="'Inspect DOM'"
        icon-left="menu_open"
        class="flat icon-button flex-none"
        @click="inspectDOM()"
      />

      <VueButton
        v-if="fileIsPath"
        v-tooltip="{
          content: $t('ComponentInspector.openInEditor.tooltip', { file: data.file }),
          html: true,
        }"
        icon-left="launch"
        class="flat icon-button flex-none"
        @click="openFile()"
      />
    </div>

    <VueLoadingBar
      v-if="data && data.id !== selectedComponentId"
      unknown
      class="primary ghost"
    />

    <StateInspector
      ref="inspector"
      :state="state"
      class="flex-1 overflow-y-auto"
      :class="{
        grayscale: data && data.id !== selectedComponentId,
      }"
      @edit-state="editState"
    />

    <RenderCode
      v-if="showRenderCode"
      :instance-id="selectedComponentId"
      class="absolute inset-0 w-full h-full z-10"
      @close="showRenderCode = false"
    />
  </div>

  <EmptyPane
    v-else
    icon="device_hub"
  >
    Select a component
  </EmptyPane>
</template>