Skip to content

Commit 5c2bd81

Browse files
committed
refactor(kit): refactor components
1 parent 4566e7f commit 5c2bd81

File tree

14 files changed

+143
-138
lines changed

14 files changed

+143
-138
lines changed

packages/core/src/client/standalone/App.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script setup lang="ts">
2-
import type { DevToolsDockState } from '../webcomponents/components/DockProps'
2+
import type { DevToolsDockState } from '../webcomponents/types/DockProps'
33
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
44
import { useLocalStorage } from '@vueuse/core'
5-
import { computed, markRaw, ref, shallowRef, useTemplateRef, watchEffect } from 'vue'
5+
import { computed, markRaw, ref, shallowRef, useTemplateRef } from 'vue'
66
import DockEntries from '../webcomponents/components/DockEntries.vue'
77
import VitePlus from '../webcomponents/components/icons/VitePlus.vue'
8-
import { IframeManager } from '../webcomponents/components/IframeManager'
98
import ViewEntry from '../webcomponents/components/ViewEntry.vue'
109
import { useStateHandlers } from '../webcomponents/state/state'
10+
import { PresistedDomViewsManager } from '../webcomponents/utils/PresistedDomViewsManager'
1111
1212
const { rpc } = await getDevToolsRpcClient()
1313
@@ -32,12 +32,8 @@ const state = useLocalStorage<DevToolsDockState>(
3232
{ mergeDefaults: true },
3333
)
3434
35-
const iframes = markRaw(new IframeManager())
36-
const iframesContainer = useTemplateRef<HTMLDivElement>('iframesContainer')
37-
38-
watchEffect(() => {
39-
iframes.setContainer(iframesContainer.value!)
40-
}, { flush: 'sync' })
35+
const viewsContainer = useTemplateRef<HTMLElement>('viewsContainer')
36+
const presistedDoms = markRaw(new PresistedDomViewsManager(viewsContainer))
4137
4238
const isDragging = ref(false)
4339
const entry = computed(() => state.value.dockEntry || docks.value[0])
@@ -60,15 +56,15 @@ const { selectDockEntry } = useStateHandlers(state, docks, rpc, 'standalone')
6056
/>
6157
</div>
6258
<div>
63-
<div id="iframes-container" ref="iframesContainer" />
59+
<div id="vite-devtools-views-container" ref="viewsContainer" />
6460
<ViewEntry
65-
v-if="entry && iframesContainer"
61+
v-if="entry && viewsContainer"
6662
:key="entry.id"
6763
:state="state"
6864
:entry="entry"
6965
:is-dragging="isDragging"
7066
:is-resizing="false"
71-
:iframes="iframes"
67+
:presisted-doms="presistedDoms"
7268
/>
7369
</div>
7470
</div>

packages/core/src/client/webcomponents/components/Dock.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { DockProps } from './DockProps'
2+
import type { DockProps } from '../types/DockProps'
33
import { useEventListener, useScreenSafeArea } from '@vueuse/core'
44
import { computed, onMounted, reactive, ref, toRefs, useTemplateRef, watchEffect } from 'vue'
55
import { useStateHandlers } from '../state/state'

packages/core/src/client/webcomponents/components/DockEmbedded.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { VueElementConstructor } from 'vue'
2-
import type { DockProps } from './DockProps'
2+
import type { DockProps } from '../types/DockProps'
33
import { defineCustomElement } from 'vue'
44
import css from '../.generated/css'
55
import Component from './DockEmbedded.vue'

packages/core/src/client/webcomponents/components/DockEmbedded.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
33
import type { DevToolsRpcClient } from '@vitejs/devtools-kit/client'
4-
import type { DevToolsDockState } from './DockProps'
4+
import type { DevToolsDockState } from '../types/DockProps'
55
import Dock from './Dock.vue'
66
import DockPanel from './DockPanel.vue'
77
import FloatingTooltip from './FloatingTooltip.vue'

packages/core/src/client/webcomponents/components/DockPanel.vue

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
22
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
33
import type { CSSProperties } from 'vue'
4-
import type { DevToolsDockState } from './DockProps'
4+
import type { DevToolsDockState } from '../types/DockProps'
55
import { useElementBounding, useWindowSize } from '@vueuse/core'
6-
import { computed, markRaw, onMounted, reactive, ref, toRefs, useTemplateRef, watchEffect } from 'vue'
6+
import { computed, markRaw, onMounted, reactive, ref, toRefs, useTemplateRef } from 'vue'
7+
import { PresistedDomViewsManager } from '../utils/PresistedDomViewsManager'
78
import DockPanelResizer from './DockPanelResizer.vue'
8-
import { IframeManager } from './IframeManager'
99
import ViewEntry from './ViewEntry.vue'
1010
1111
const props = defineProps<{
@@ -23,13 +23,8 @@ const isDragging = defineModel<boolean>('isDragging', { default: false })
2323
const mousePosition = reactive({ x: 0, y: 0 })
2424
2525
const dockPanel = useTemplateRef<HTMLDivElement>('dockPanel')
26-
const iframesContainer = useTemplateRef<HTMLDivElement>('iframesContainer')
27-
28-
const iframes = markRaw(new IframeManager())
29-
30-
watchEffect(() => {
31-
iframes.setContainer(iframesContainer.value!)
32-
}, { flush: 'sync' })
26+
const viewsContainer = useTemplateRef<HTMLElement>('viewsContainer')
27+
const presistedDoms = markRaw(new PresistedDomViewsManager(viewsContainer))
3328
3429
function clamp(value: number, min: number, max: number) {
3530
return Math.min(Math.max(value, min), max)
@@ -174,22 +169,22 @@ onMounted(() => {
174169
:entry
175170
/>
176171
<ViewEntry
177-
v-if="entry && iframesContainer"
172+
v-if="entry && viewsContainer"
178173
:key="entry.id"
179174
:state="state"
180175
:is-dragging="isDragging"
181176
:is-resizing="isResizing"
182177
:entry="entry"
183-
:iframes="iframes"
178+
:presisted-doms="presistedDoms"
184179
:iframe-style="{
185180
border: '1px solid #8883',
186181
borderRadius: '0.5rem',
187182
}"
188183
rounded
189184
/>
190185
<div
191-
id="vite-devtools-iframe-container"
192-
ref="iframesContainer"
186+
id="vite-devtools-views-container"
187+
ref="viewsContainer"
193188
class="absolute inset-0"
194189
/>
195190
</div>

packages/core/src/client/webcomponents/components/DockPanelResizer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { DevToolsDockState } from './DockProps'
2+
import type { DevToolsDockState } from '../types/DockProps'
33
import { toRefs, useEventListener } from '@vueuse/core'
44
import { ref, watch } from 'vue'
55

packages/core/src/client/webcomponents/components/IframeManager.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

packages/core/src/client/webcomponents/components/ViewEntry.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<script setup lang="ts">
22
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
33
import type { CSSProperties } from 'vue'
4-
import type { DevToolsDockState } from './DockProps'
5-
import type { IframeManager } from './IframeManager'
4+
import type { DevToolsDockState } from '../types/DockProps'
5+
import type { PresistedDomViewsManager } from '../utils/PresistedDomViewsManager'
66
import ViewIframe from './ViewIframe.vue'
77
88
defineProps<{
99
state?: DevToolsDockState
1010
isDragging: boolean
1111
isResizing: boolean
1212
entry: DevToolsDockEntry
13-
iframes: IframeManager
13+
presistedDoms: PresistedDomViewsManager
1414
iframeStyle?: CSSProperties
1515
}>()
1616
</script>
@@ -22,7 +22,7 @@ defineProps<{
2222
:is-dragging="isDragging"
2323
:is-resizing="isResizing"
2424
:entry="entry"
25-
:iframes="iframes"
25+
:presisted-doms="presistedDoms"
2626
:iframe-style="iframeStyle"
2727
/>
2828
<div v-else>

packages/core/src/client/webcomponents/components/ViewIframe.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
<script setup lang="ts">
22
import type { DevToolsViewIframe } from '@vitejs/devtools-kit'
33
import type { CSSProperties } from 'vue'
4-
import type { DevToolsDockState } from './DockProps'
5-
import type { IframeManager } from './IframeManager'
4+
import type { DevToolsDockState } from '../types/DockProps'
5+
import type { PresistedDomViewsManager } from '../utils/PresistedDomViewsManager'
66
import { nextTick, onMounted, onUnmounted, ref, useTemplateRef, watch, watchEffect } from 'vue'
77
88
const props = defineProps<{
99
state?: DevToolsDockState
1010
isDragging: boolean
1111
isResizing: boolean
1212
entry: DevToolsViewIframe
13-
iframes: IframeManager
13+
presistedDoms: PresistedDomViewsManager
1414
iframeStyle?: CSSProperties
1515
}>()
1616
1717
const isLoading = ref(true)
1818
const viewFrame = useTemplateRef<HTMLDivElement>('viewFrame')
1919
2020
onMounted(() => {
21-
const holder = props.iframes.getIframeHolder(props.entry.id)
22-
holder.iframe.style.boxShadow = 'none'
23-
holder.iframe.style.outline = 'none'
24-
Object.assign(holder.iframe.style, props.iframeStyle)
21+
const holder = props.presistedDoms.getOrCreateHolder(props.entry.id, 'iframe')
22+
holder.element.style.boxShadow = 'none'
23+
holder.element.style.outline = 'none'
24+
Object.assign(holder.element.style, props.iframeStyle)
2525
26-
if (!holder.iframe.src)
27-
holder.iframe.src = props.entry.url
26+
if (!holder.element.src)
27+
holder.element.src = props.entry.url
2828
2929
holder.mount(viewFrame.value!)
3030
isLoading.value = false
@@ -42,15 +42,15 @@ onMounted(() => {
4242
4343
watchEffect(
4444
() => {
45-
holder.iframe.style.pointerEvents = (props.isDragging || props.isResizing) ? 'none' : 'auto'
45+
holder.element.style.pointerEvents = (props.isDragging || props.isResizing) ? 'none' : 'auto'
4646
},
4747
{ flush: 'sync' },
4848
)
4949
})
5050
5151
onUnmounted(() => {
52-
const iframe = props.iframes.getIframeHolder(props.entry.id)
53-
iframe.unmount()
52+
const holder = props.presistedDoms.getHolder(props.entry.id, 'iframe')
53+
holder?.unmount()
5454
})
5555
</script>
5656

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './components/DockEmbedded'
2-
export * from './components/DockProps'
3-
export * from './components/IframeManager'
2+
export * from './types/DockProps'
3+
export * from './utils/PresistedDomViewsManager'

0 commit comments

Comments
 (0)