/
WidgetsView.vue
68 lines (60 loc) · 1.9 KB
/
WidgetsView.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
<SnappingGrid v-if="store.showGrid && store.editingMode" :grid-interval="store.gridInterval" class="snapping-grid" />
<div class="widgets-view">
<div v-for="view in store.viewsToShow" :key="view.hash" class="widget-view">
<template v-for="widget in view.widgets.slice().reverse()" :key="widget">
<WidgetHugger
v-if="Object.values(WidgetType).includes(widget.component)"
:widget="widget"
:allow-moving="widget.managerVars.allowMoving"
:allow-resizing="store.editingMode"
>
<component :is="componentFromType(widget.component)" :widget="widget" />
</WidgetHugger>
</template>
<div class="w-full h-full bg-slate-500" />
</div>
</div>
</template>
<script setup lang="ts">
import { type AsyncComponentLoader, defineAsyncComponent } from 'vue'
import { useWidgetManagerStore } from '@/stores/widgetManager'
import { WidgetType } from '@/types/widgets'
import SnappingGrid from '../components/SnappingGrid.vue'
import WidgetHugger from '../components/WidgetHugger.vue'
const store = useWidgetManagerStore()
const componentCache: Record<string, AsyncComponentLoader> = {}
const componentFromType = (componentType: WidgetType): AsyncComponentLoader => {
if (componentCache[componentType] === undefined) {
componentCache[componentType] = defineAsyncComponent(
() => import(`../components/widgets/${componentType}.vue`)
)
}
return componentCache[componentType]
}
</script>
<style scoped>
.widgets-view {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.snapping-grid {
z-index: 40;
}
.widget-view {
position: absolute;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
background-color: rgb(122, 25, 25);
z-index: 50;
}
</style>