SSR fixes
This commit is contained in:
@@ -10,13 +10,18 @@ let isDragging = false
|
||||
|
||||
const slots = useSlots()
|
||||
let luaCode = ''
|
||||
|
||||
onMounted(() => {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
luaCode = (slots.default?.() || [])
|
||||
.map(vnode => typeof vnode.children === 'string' ? vnode.children : '')
|
||||
.join('\n')
|
||||
})
|
||||
|
||||
async function startDemo() {
|
||||
if (typeof window === 'undefined' || typeof document === 'undefined') return
|
||||
|
||||
showDemo.value = true
|
||||
|
||||
const basalt = await fetch(
|
||||
@@ -47,6 +52,8 @@ function closeDemo() {
|
||||
}
|
||||
|
||||
function startDrag(e) {
|
||||
if (typeof document === 'undefined') return
|
||||
|
||||
isDragging = true
|
||||
offset.x = e.clientX - position.x
|
||||
offset.y = e.clientY - position.y
|
||||
@@ -55,32 +62,30 @@ function startDrag(e) {
|
||||
}
|
||||
|
||||
function onDrag(e) {
|
||||
if (isDragging) {
|
||||
// Containergröße ermitteln
|
||||
const containerEl = container.value?.parentElement
|
||||
const contW = containerEl?.offsetWidth || 0
|
||||
const contH = containerEl?.offsetHeight || 0
|
||||
if (!isDragging || typeof window === 'undefined') return
|
||||
|
||||
const containerEl = container.value?.parentElement
|
||||
const contW = containerEl?.offsetWidth || 0
|
||||
const contH = containerEl?.offsetHeight || 0
|
||||
|
||||
// Maximal erlaubte Positionen
|
||||
const maxX = window.innerWidth - contW
|
||||
const maxY = window.innerHeight - contH
|
||||
const maxX = window.innerWidth - contW
|
||||
const maxY = window.innerHeight - contH
|
||||
|
||||
// Neue Position berechnen
|
||||
let newX = e.clientX - offset.x
|
||||
let newY = e.clientY - offset.y
|
||||
let newX = e.clientX - offset.x
|
||||
let newY = e.clientY - offset.y
|
||||
|
||||
// Begrenzen (clampen)
|
||||
if (newX < 0) newX = 0
|
||||
if (newY < 0) newY = 0
|
||||
if (newX > maxX) newX = maxX
|
||||
if (newY > maxY) newY = maxY
|
||||
if (newX < 0) newX = 0
|
||||
if (newY < 0) newY = 0
|
||||
if (newX > maxX) newX = maxX
|
||||
if (newY > maxY) newY = maxY
|
||||
|
||||
position.x = newX
|
||||
position.y = newY
|
||||
}
|
||||
position.x = newX
|
||||
position.y = newY
|
||||
}
|
||||
|
||||
function stopDrag() {
|
||||
if (typeof document === 'undefined') return
|
||||
|
||||
isDragging = false
|
||||
document.removeEventListener('mousemove', onDrag)
|
||||
document.removeEventListener('mouseup', stopDrag)
|
||||
@@ -175,4 +180,4 @@ function stopDrag() {
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
@@ -40,7 +40,6 @@ function extractText(nodes) {
|
||||
|
||||
const luaCode = computed(() => extractText(slots.default?.() ?? []))
|
||||
|
||||
|
||||
const highlightedCode = computed(() => {
|
||||
let code = luaCode.value
|
||||
|
||||
@@ -61,6 +60,7 @@ const highlightedCode = computed(() => {
|
||||
})
|
||||
|
||||
async function startDemo() {
|
||||
if (typeof window === 'undefined') return
|
||||
if (isLoading.value || showDemo.value) return
|
||||
|
||||
isLoading.value = true
|
||||
@@ -133,6 +133,8 @@ function closeDemo() {
|
||||
}
|
||||
|
||||
function centerWindow() {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
const windowWidth = window.innerWidth
|
||||
const windowHeight = window.innerHeight
|
||||
position.x = Math.max(0, (windowWidth - 650) / 2)
|
||||
@@ -140,6 +142,8 @@ function centerWindow() {
|
||||
}
|
||||
|
||||
function startDrag(e) {
|
||||
if (typeof document === 'undefined') return
|
||||
|
||||
if (e.target.closest('button')) return
|
||||
isDragging = true
|
||||
offset.x = e.clientX - position.x
|
||||
@@ -150,7 +154,8 @@ function startDrag(e) {
|
||||
}
|
||||
|
||||
function onDrag(e) {
|
||||
if (!isDragging) return
|
||||
if (!isDragging || typeof window === 'undefined') return
|
||||
|
||||
const maxX = window.innerWidth - 650
|
||||
const maxY = window.innerHeight - 480
|
||||
|
||||
@@ -159,6 +164,8 @@ function onDrag(e) {
|
||||
}
|
||||
|
||||
function stopDrag() {
|
||||
if (typeof document === 'undefined') return
|
||||
|
||||
isDragging = false
|
||||
document.removeEventListener('mousemove', onDrag)
|
||||
document.removeEventListener('mouseup', stopDrag)
|
||||
@@ -171,11 +178,17 @@ function handleKeydown(e) {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('keydown', handleKeydown)
|
||||
// SSR Guard - nur im Browser Event Listener hinzufügen
|
||||
if (typeof document !== 'undefined') {
|
||||
document.addEventListener('keydown', handleKeydown)
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('keydown', handleKeydown)
|
||||
// SSR Guard
|
||||
if (typeof document !== 'undefined') {
|
||||
document.removeEventListener('keydown', handleKeydown)
|
||||
}
|
||||
closeDemo()
|
||||
})
|
||||
</script>
|
||||
@@ -197,13 +210,12 @@ onUnmounted(() => {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Code Block with Syntax Highlighting -->
|
||||
<div class="code-block">
|
||||
<pre><code v-html="highlightedCode"></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Teleport to="body">
|
||||
<Teleport v-if="typeof document !== 'undefined'" to="body">
|
||||
<div
|
||||
v-if="showDemo"
|
||||
ref="wrapperRef"
|
||||
|
||||
Reference in New Issue
Block a user