Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

fix: improve fullscreen mode #217

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/client/components/FullscreenButton.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script setup lang="ts">
import { useDevToolsClient } from '../logic/client'

const isFullscreen = ref(false)
const { viewMode } = useFrameState()
const client = useDevToolsClient()

const isFullscreen = computed(() => viewMode.value === 'fullscreen')
function toggleFullscreen() {
client.value.panel?.toggleViewMode(isFullscreen.value ? 'default' : 'fullscreen')
isFullscreen.value = !isFullscreen.value
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions packages/client/composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface DevToolsFrameState {
isFirstVisit: boolean
closeOnOutsideClick: boolean
minimizePanelInactive: number
viewMode: ViewMode
}

const frameState = useLocalStorage<DevToolsFrameState>(FRAME_STATE_STORAGE_KEY, {
Expand All @@ -25,6 +26,7 @@ const frameState = useLocalStorage<DevToolsFrameState>(FRAME_STATE_STORAGE_KEY,
isFirstVisit: true,
closeOnOutsideClick: false,
minimizePanelInactive: 5000,
viewMode: 'default',
}, { mergeDefaults: true })

const frameStateRefs = toRefs(frameState)
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/views/FrameBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const props = defineProps<{
disable: () => void
} | undefined
}
viewMode: 'xs' | 'default' | 'fullscreen'
viewMode: ViewMode
}>()

const container = ref<HTMLElement>()
Expand Down
16 changes: 5 additions & 11 deletions packages/node/src/views/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import vueDevToolsOptions from 'virtual:vue-devtools-options'
import { DevToolsHooks, collectDevToolsHookBuffer } from '@vite-plugin-vue-devtools/core'
import Frame from './FrameBox.vue'
import ComponentInspector from './ComponentInspector.vue'
import { useHighlightComponent, useIframe, useInspector, usePanelVisible, usePiPMode, usePosition, useRerenderHighlight } from './composables'
import { useHighlightComponent, useIframe, useInspector, usePanelState, usePanelVisible, usePiPMode, usePosition, useRerenderHighlight } from './composables'
import { checkIsSafari, useColorScheme, usePreferredColorScheme, warn } from './utils'
import RerenderIndicator from './RerenderIndicator.vue'

Expand All @@ -22,15 +22,11 @@ const hook = props.hook
const { hookBuffer, collect } = collectDevToolsHookBuffer()

let isAppCreated = false
const panelState = ref<{
viewMode: ViewMode
}>({
viewMode: 'default',
})

const { togglePanelVisible, closePanel, panelVisible } = usePanelVisible()
const panelEl = ref<HTMLDivElement>()
const { onPointerDown, bringUp, anchorStyle, iframeStyle, isDragging, isVertical, isHidden, panelStyle } = usePosition(panelEl)
const { viewMode, toggleViewMode } = usePanelState()
const vars = computed(() => {
const colorScheme = useColorScheme()
const dark = colorScheme.value === 'auto'
Expand Down Expand Up @@ -91,9 +87,7 @@ async function setupClient(iframe: HTMLIFrameElement) {
hook,
hookBuffer,
panel: {
toggleViewMode: (mode?: ViewMode) => {
panelState.value.viewMode = mode ?? 'default'
},
toggleViewMode,
toggle: togglePanelVisible,
popup,
},
Expand Down Expand Up @@ -237,7 +231,7 @@ collectHookBuffer()
:class="{
'vue-devtools-vertical': isVertical,
'vue-devtools-hide': isHidden,
'fullscreen': panelState.viewMode === 'fullscreen',
'fullscreen': viewMode === 'fullscreen',
}"
@mousemove="bringUp"
>
Expand Down Expand Up @@ -284,7 +278,7 @@ collectHookBuffer()
},
getIFrame: getIframe,
}"
:view-mode="panelState.viewMode"
:view-mode="viewMode"
/>
</div>
<!-- component inspector -->
Expand Down
25 changes: 25 additions & 0 deletions packages/node/src/views/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface DevToolsFrameState {
isFirstVisit: boolean
closeOnOutsideClick: boolean
minimizePanelInactive: number
viewMode: ViewMode
}

interface ComponentInspectorBounds {
Expand Down Expand Up @@ -41,6 +42,7 @@ export const state = useObjectStorage<DevToolsFrameState>('__vue-devtools-frame-
isFirstVisit: true,
closeOnOutsideClick: false,
minimizePanelInactive: 5000,
viewMode: 'default',
})

// ---- useIframe ----
Expand Down Expand Up @@ -501,6 +503,29 @@ export function usePosition(panelEl: Ref<HTMLElement | undefined>) {
}
}

// ---- usePanelState ----
export function usePanelState() {
const viewMode = computed({
get() {
return state.value.viewMode
},
set(value) {
state.value.viewMode = value
},
})
let perViewMode = viewMode.value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preViewMode? Looks like a typo here.


function toggleViewMode(mode: ViewMode) {
const newMode = mode ?? perViewMode
setTimeout(() => {
Copy link
Contributor Author

@OneGIl OneGIl Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用setTimeout是因为在eyedropper里close方法里会同时修改client和node中的frameState,这会赋给viewMode错误的值。暂时没找到合适的解决方法。所以在这里用了setTimeout。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以针对 eyeDropper 这种 viewMode 是 xs 的单独写一个判断逻辑

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢建议,这部分我会再考虑一下~

perViewMode = viewMode.value
viewMode.value = newMode
}, 0)
}

return { viewMode, toggleViewMode }
}

// ---- useHighlightComponent ----

export function useHighlightComponent() {
Expand Down