Skip to content

Commit d277f40

Browse files
committed
feat(components): update flashing, closes #862
1 parent fb6a2ac commit d277f40

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { DevtoolsBackend } from '@vue-devtools/app-backend-api'
2+
import { ComponentInstance } from '@vue/devtools-api'
3+
4+
export async function flashComponent (instance: ComponentInstance, backend: DevtoolsBackend) {
5+
const bounds = await backend.api.getComponentBounds(instance)
6+
if (bounds) {
7+
let overlay: HTMLDivElement = instance.__VUE_DEVTOOLS_FLASH
8+
if (!overlay) {
9+
overlay = document.createElement('div')
10+
instance.__VUE_DEVTOOLS_FLASH = overlay
11+
overlay.style.border = '2px rgba(65, 184, 131, 0.7) solid'
12+
overlay.style.position = 'fixed'
13+
overlay.style.zIndex = '99999999999998'
14+
overlay.style.pointerEvents = 'none'
15+
overlay.style.borderRadius = '3px'
16+
overlay.style.boxSizing = 'border-box'
17+
document.body.appendChild(overlay)
18+
}
19+
overlay.style.opacity = '1'
20+
overlay.style.transition = null
21+
overlay.style.width = Math.round(bounds.width) + 'px'
22+
overlay.style.height = Math.round(bounds.height) + 'px'
23+
overlay.style.left = Math.round(bounds.left) + 'px'
24+
overlay.style.top = Math.round(bounds.top) + 'px'
25+
requestAnimationFrame(() => {
26+
overlay.style.transition = 'opacity 1s'
27+
overlay.style.opacity = '0'
28+
})
29+
clearTimeout((overlay as any)._timer)
30+
;(overlay as any)._timer = setTimeout(() => {
31+
document.body.removeChild(overlay)
32+
instance.__VUE_DEVTOOLS_FLASH = null
33+
}, 1000)
34+
}
35+
}

packages/app-backend-core/src/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { showScreenshot } from './timeline-screenshot'
4343
import { performanceMarkEnd, performanceMarkStart } from './perf'
4444
import { initOnPageConfig } from './page-config'
4545
import { sendTimelineMarkers, addTimelineMarker } from './timeline-marker'
46+
import { flashComponent } from './flash.js'
4647

4748
let ctx: BackendContext = target.__vdevtools_ctx ?? null
4849
let connected = target.__vdevtools_connected ?? false
@@ -136,6 +137,10 @@ async function connect () {
136137
if (SharedData.trackUpdates) {
137138
sendComponentUpdateTracking(id, ctx)
138139
}
140+
141+
if (SharedData.flashUpdates) {
142+
flashComponent(component, appRecord.backend)
143+
}
139144
} catch (e) {
140145
if (SharedData.debugInfo) {
141146
console.error(e)
@@ -183,6 +188,10 @@ async function connect () {
183188
sendComponentUpdateTracking(id, ctx)
184189
}
185190

191+
if (SharedData.flashUpdates) {
192+
flashComponent(component, appRecord.backend)
193+
}
194+
186195
await refreshComponentTreeSearch(ctx)
187196
} catch (e) {
188197
if (SharedData.debugInfo) {

packages/app-backend-vue2/src/components/update-tracking.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DevtoolsApi } from '@vue-devtools/app-backend-api'
22
import { SharedData } from '@vue-devtools/shared-utils'
33
import { sendComponentUpdateTracking } from '@vue-devtools/app-backend-core/lib/component'
4+
import { flashComponent } from '@vue-devtools/app-backend-core/lib/flash'
45
import throttle from 'lodash/throttle'
56
import { getUniqueId } from './util.js'
67

@@ -31,6 +32,10 @@ export function applyTrackingUpdateHook (api: DevtoolsApi, vm) {
3132
sendComponentUpdateTracking(getUniqueId(parent), api.ctx)
3233
}
3334
}
35+
36+
if (SharedData.flashUpdates) {
37+
flashComponent(this, api.backend)
38+
}
3439
}, 100)
3540
for (const hook of COMPONENT_HOOKS) {
3641
const currentValue = vm.$options[hook]

packages/app-frontend/src/features/components/ComponentsInspector.vue

+13
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ export default defineComponent({
155155
</div>
156156
</div>
157157

158+
<div class="space-y-1 px-3 py-2 text-sm">
159+
<VueSwitch v-model="$shared.flashUpdates">
160+
Highlight updates
161+
</VueSwitch>
162+
<div class="flex items-center space-x-1 text-xs opacity-50">
163+
<VueIcon
164+
icon="warning"
165+
class="w-4 h-4 flex-none"
166+
/>
167+
<span>Don't enable if you are sensible to flashing</span>
168+
</div>
169+
</div>
170+
158171
<div class="border-t border-gray-200 dark:border-gray-800 my-1" />
159172
</portal>
160173

packages/shared-utils/src/shared-data.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const internalSharedData = {
2929
pageConfig: {} as any,
3030
legacyApps: false,
3131
trackUpdates: true,
32+
flashUpdates: false,
3233
debugInfo: false,
3334
}
3435

@@ -54,6 +55,7 @@ const persisted = [
5455
'performanceMonitoringEnabled',
5556
'componentEventsEnabled',
5657
'trackUpdates',
58+
'flashUpdates',
5759
'debugInfo',
5860
]
5961

0 commit comments

Comments
 (0)