Skip to content

Commit a6bbeea

Browse files
bteasxzz
andauthored
feat: show view size while dragging split pane (#253)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
1 parent be42087 commit a6bbeea

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

src/Repl.vue

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ provide('clear-console', toRef(props, 'clearConsole'))
7575
provide('preview-options', props.previewOptions)
7676
provide('theme', toRef(props, 'theme'))
7777
provide('preview-theme', toRef(props, 'previewTheme'))
78+
provide('preview-ref', () => outputRef.value?.previewRef?.container)
79+
7880
/**
7981
* Reload the preview iframe
8082
*/

src/SplitPane.vue

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<script setup lang="ts">
2-
import { computed, inject, reactive, ref, toRef } from 'vue'
2+
import {
3+
type MaybeRefOrGetter,
4+
computed,
5+
inject,
6+
reactive,
7+
ref,
8+
toRef,
9+
toValue,
10+
} from 'vue'
311
import { injectKeyStore } from './types'
412
513
const props = defineProps<{ layout?: 'horizontal' | 'vertical' }>()
614
const isVertical = computed(() => props.layout === 'vertical')
715
816
const container = ref()
17+
const previewRef = inject<MaybeRefOrGetter<HTMLDivElement>>('preview-ref')!
918
1019
// mobile only
1120
const store = inject(injectKeyStore)!
@@ -14,6 +23,8 @@ const showOutput = toRef(store, 'showOutput')
1423
const state = reactive({
1524
dragging: false,
1625
split: 50,
26+
viewHeight: 0,
27+
viewWidth: 0,
1728
})
1829
1930
const boundSplit = computed(() => {
@@ -28,6 +39,8 @@ function dragStart(e: MouseEvent) {
2839
state.dragging = true
2940
startPosition = isVertical.value ? e.pageY : e.pageX
3041
startSplit = boundSplit.value
42+
43+
changeViewSize()
3144
}
3245
3346
function dragMove(e: MouseEvent) {
@@ -38,12 +51,24 @@ function dragMove(e: MouseEvent) {
3851
: container.value.offsetWidth
3952
const dp = position - startPosition
4053
state.split = startSplit + +((dp / totalSize) * 100).toFixed(2)
54+
55+
changeViewSize()
4156
}
4257
}
4358
4459
function dragEnd() {
4560
state.dragging = false
4661
}
62+
63+
function changeViewSize() {
64+
const el = toValue(previewRef)
65+
state.viewHeight = el.offsetHeight
66+
state.viewWidth = el.offsetWidth
67+
}
68+
69+
defineExpose({
70+
changeViewSize,
71+
})
4772
</script>
4873

4974
<template>
@@ -70,6 +95,9 @@ function dragEnd() {
7095
class="right"
7196
:style="{ [isVertical ? 'height' : 'width']: 100 - boundSplit + '%' }"
7297
>
98+
<div class="view-size" v-show="state.dragging">
99+
{{ `${state.viewWidth}px x ${state.viewHeight}px` }}
100+
</div>
73101
<slot name="right" />
74102
</div>
75103

@@ -97,6 +125,14 @@ function dragEnd() {
97125
position: relative;
98126
height: 100%;
99127
}
128+
.view-size {
129+
position: absolute;
130+
top: 40px;
131+
left: 10px;
132+
font-size: 12px;
133+
color: var(--text-light);
134+
z-index: 100;
135+
}
100136
.left {
101137
border-right: 1px solid var(--border);
102138
}

src/output/Output.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function reload() {
3737
previewRef.value?.reload()
3838
}
3939
40-
defineExpose({ reload })
40+
defineExpose({ reload, previewRef })
4141
</script>
4242

4343
<template>

src/output/Preview.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function reload() {
286286
sandbox.contentWindow?.location.reload()
287287
}
288288
289-
defineExpose({ reload })
289+
defineExpose({ reload, container })
290290
</script>
291291

292292
<template>

0 commit comments

Comments
 (0)