-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This closes #5
- Loading branch information
Showing
10 changed files
with
127 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,50 @@ | ||
<script lang="ts" setup> | ||
const { data, isLoading, error } = useBoardLayoutsQuery(); | ||
const container = ref<HTMLDivElement>(); | ||
const { scale, resetZoom, zoomIn, zoomOut } = usePanZoom(container); | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-col dots-bg"> | ||
<p v-if="error">{{ error }}</p> | ||
<template v-else-if="data"> | ||
<p | ||
v-if="data.layouts.length === 0" | ||
class="m-auto bg-gray-900 shadow-2xl shadow-gray-900 p-4" | ||
> | ||
No board layouts found | ||
</p> | ||
<LayoutList v-else :layouts="data.layouts" /> | ||
</template> | ||
<div> | ||
<!-- Cutlist Preview --> | ||
<div class="absolute inset-0 overflow-none"> | ||
<p v-if="error" class="m-auto">{{ error }}</p> | ||
|
||
<template v-else-if="data"> | ||
<p | ||
v-if="data.layouts.length === 0" | ||
class="m-auto bg-gray-900 shadow-2xl shadow-gray-900 p-4" | ||
> | ||
No board layouts found | ||
</p> | ||
<div v-else ref="container"> | ||
<div class="flex flex-col"> | ||
<LayoutList :layouts="data.layouts" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<div v-else-if="isLoading" class="m-auto flex items-center space-x-4"> | ||
<USkeleton class="h-12 w-12" :ui="{ rounded: 'rounded-full' }" /> | ||
<div class="space-y-2"> | ||
<USkeleton class="h-4 w-[250px]" /> | ||
<USkeleton class="h-4 w-[200px]" /> | ||
<div v-else-if="isLoading" class="m-auto flex items-center space-x-4"> | ||
<USkeleton class="h-12 w-12" :ui="{ rounded: 'rounded-full' }" /> | ||
<div class="space-y-2"> | ||
<USkeleton class="h-4 w-[250px]" /> | ||
<USkeleton class="h-4 w-[200px]" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Controlls --> | ||
<div class="absolute bottom-4 right-4 flex gap-4 print:hidden z-10"> | ||
<ScaleController | ||
v-if="scale != null" | ||
class="bg-white rounded shadow-2xl" | ||
:scale="scale" | ||
@reset-zoom="resetZoom" | ||
@zoom-in="zoomIn" | ||
@zoom-out="zoomOut" | ||
/> | ||
<FitController class="bg-white rounded shadow-2xl" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.dots-bg { | ||
background-size: 40px 40px; | ||
background-image: radial-gradient( | ||
circle, | ||
rgba(255, 255, 255, 20%) 2px, | ||
rgba(255, 255, 255, 0) 1px | ||
); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export default function () { | ||
const scale = useScale(); | ||
return (value: number) => `${value * 500 * scale.value}px`; | ||
return (value: number) => `${value * 500}px`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { PanZoom } from 'panzoom'; | ||
import panzoom from 'panzoom'; | ||
|
||
export default function (container: Ref<HTMLElement | undefined>) { | ||
let instance = ref<PanZoom>(); | ||
const scale = ref<number>(); | ||
|
||
whenever(container, (container) => { | ||
instance.value = panzoom(container, { | ||
autocenter: true, | ||
minZoom: 0.2, | ||
maxZoom: 10, | ||
}); | ||
scale.value = instance.value.getTransform().scale; | ||
instance.value.on('zoom', () => { | ||
scale.value = instance.value?.getTransform().scale; | ||
}); | ||
}); | ||
whenever( | ||
() => !container.value, | ||
() => { | ||
instance.value?.dispose(); | ||
}, | ||
); | ||
onUnmounted(() => { | ||
instance.value?.dispose(); | ||
}); | ||
|
||
const setZoom = (cb: (scale: number) => number, x?: number, y?: number) => { | ||
if (instance.value == null) return; | ||
const current = instance.value.getTransform(); | ||
const currentScale = current.scale; | ||
const newScale = cb(current.scale); | ||
instance.value?.smoothZoom( | ||
x ?? current.x, | ||
y ?? current.y, | ||
newScale / currentScale, | ||
); | ||
}; | ||
const zoomBy = (increment: number) => setZoom((scale) => scale + increment); | ||
|
||
return { | ||
scale, | ||
zoomIn: () => zoomBy(0.1), | ||
zoomOut: () => zoomBy(-0.1), | ||
resetZoom: () => { | ||
setZoom(() => 1); | ||
instance.value?.smoothMoveTo(0, 0); | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters