81 lines
2.4 KiB
Vue
81 lines
2.4 KiB
Vue
<script setup>
|
|
/**
|
|
* ResizablePanels.vue
|
|
*
|
|
* The sticky side-by-side layout: Source Document | drag handle |
|
|
* Transactions. Owns the resize-drag math and the panel's hidden/shown
|
|
* state (driven by uiStore.pdfColHidden, toggled from TransactionsTable's
|
|
* own header button since that's where it visually lives). Sticky on
|
|
* the GROUP, not the source-doc column alone - keeps both panels moving
|
|
* together as one unit while the page scrolls, instead of the source
|
|
* doc pinning in place while transactions scrolls past it underneath
|
|
* (they'd drift out of alignment).
|
|
*/
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
import { useUiStore } from '../stores/uiStore'
|
|
|
|
const uiStore = useUiStore()
|
|
const gridRef = ref(null)
|
|
const dragging = ref(false)
|
|
|
|
function setWidthFromX(clientX) {
|
|
const rect = gridRef.value.getBoundingClientRect()
|
|
let pct = ((clientX - rect.left) / rect.width) * 100
|
|
pct = Math.max(25, Math.min(75, pct))
|
|
uiStore.pdfColWidthPct = pct
|
|
}
|
|
|
|
function start(e) {
|
|
dragging.value = true
|
|
document.body.style.userSelect = 'none'
|
|
e.preventDefault()
|
|
}
|
|
|
|
function move(e) {
|
|
if (!dragging.value) return
|
|
const x = e.touches ? e.touches[0].clientX : e.clientX
|
|
setWidthFromX(x)
|
|
}
|
|
|
|
function end() {
|
|
if (!dragging.value) return
|
|
dragging.value = false
|
|
document.body.style.userSelect = ''
|
|
// Column width just changed - descriptions may rewrap at a different height.
|
|
uiStore.bumpLayout()
|
|
}
|
|
|
|
// Dragging continues even if the cursor leaves the resizer itself, so
|
|
// move/end listen on the window, not the handle - matching the original.
|
|
onMounted(() => {
|
|
window.addEventListener('mousemove', move)
|
|
window.addEventListener('mouseup', end)
|
|
window.addEventListener('touchmove', move, { passive: false })
|
|
window.addEventListener('touchend', end)
|
|
})
|
|
onUnmounted(() => {
|
|
window.removeEventListener('mousemove', move)
|
|
window.removeEventListener('mouseup', end)
|
|
window.removeEventListener('touchmove', move)
|
|
window.removeEventListener('touchend', end)
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div ref="gridRef" class="review-grid">
|
|
<div v-show="!uiStore.pdfColHidden" class="card pdf-col" :style="{ flexBasis: uiStore.pdfColWidthPct + '%' }">
|
|
<slot name="source" />
|
|
</div>
|
|
<div
|
|
v-show="!uiStore.pdfColHidden"
|
|
class="resizer"
|
|
:class="{ dragging }"
|
|
@mousedown="start"
|
|
@touchstart="start"
|
|
></div>
|
|
<div class="card txn-col">
|
|
<slot name="transactions" />
|
|
</div>
|
|
</div>
|
|
</template>
|