<script setup> import DragGrid from "../../src/DragGrid.vue"; </script> <template> <div> <div class="row"> <div> <label> Lesson 1 has length: {{ lesson1Length }} <input type="range" v-model="lesson1Length" min="1" max="5" step="1" /> </label> <label for="lesson1">Text of Lesson 1:</label> <input id="lesson1" type="text" v-model="lessonData.lesson1" /> </div> <div> <label> Lesson grid has width: {{ lesson1Cols }} <input type="range" v-model="lesson1Cols" min="2" max="5" step="1" /> </label> <label for="lesson2">Text of Lesson 2:</label> <input id="lesson2" type="text" v-model="lessonData.lesson2" /> </div> <div> <label> Lesson grid has height: {{ lesson1Rows }} <input type="range" v-model="lesson1Rows" min="6" max="10" step="1" /> </label> <label for="lesson3">Texts of Lesson 3:</label> <input id="lesson3" type="text" v-model="lessonData.lesson3.inside" /> <input type="text" v-model="lessonData.lesson3.outside" /> </div> </div> <div class="row"> <drag-grid :value="lessons1" :cols="parseInt(lesson1Cols)" :rows="parseInt(lesson1Rows)" class="bordered" context="lesson" grid-id="lesson-plan" @itemChanged="handleLessonMoved" > <template #item="item"> <div class="container">{{ item }}</div> </template> </drag-grid> <drag-grid :value="lessons1" :cols="1" :rows="10" context="lesson" grid-id="lesson-storage" @itemChanged="handleLessonDropInContainer" no-highlight class="bordered" > <template #item="item"> <div class="container">{{ item }}</div> </template> </drag-grid> </div> </div> </template> <script> export default { name: "Example4Lessons", data() { return { lesson1Length: 1, lesson1Cols: 4, lesson1Rows: 6, lesson1X: 1, lesson1Y: 1, lesson2X: 2, lesson2Y: 1, lesson3X: -1, lesson3Y: -1, lesson3inPlan: false, lessonData: { lesson1: "Nothing", lesson2: "Hallo", lesson3: { inside: "This is lesson 3 inside the plan", outside: "This is lesson3 outside of the plan", }, }, }; }, methods: { logInput(input) { console.log("New movement detected:", input); }, handleLessonMoved(lesson) { this.logInput(lesson); switch (lesson.key) { case "lesson1": this.lesson1X = lesson.x; this.lesson1Y = lesson.y; break; case "lesson2": this.lesson2X = lesson.x; this.lesson2Y = lesson.y; break; case "lesson3": this.lesson3X = lesson.x; this.lesson3Y = lesson.y; this.lesson3inPlan = true; break; default: console.error("Something is wrong here!"); } }, handleLessonDropInContainer(lesson) { if (lesson.key === "lesson3") this.lesson3inPlan = false; }, }, computed: { lessons1() { return [ { x: (grid) => { return grid.gridId === "lesson-plan" ? this.lesson1X : 0; }, y: (grid) => { return grid.gridId === "lesson-plan" ? this.lesson1Y : 0; }, w: 1, h: this.lesson1Length, key: "lesson1", data: { text: this.lessonData.lesson1, }, }, { x: (grid) => { return grid.gridId === "lesson-plan" ? this.lesson2X : 0; }, y: (grid) => { return grid.gridId === "lesson-plan" ? this.lesson2Y : 0; }, w: 1, h: parseInt(this.lesson1Length) + 1, key: "lesson2", data: { text: this.lessonData.lesson2, }, }, { x: (grid) => { if (this.lesson3inPlan) { return grid.gridId === "lesson-plan" ? this.lesson3X : -1; } return grid.gridId === "lesson-plan" ? -1 : 0; }, y: (grid) => { if (this.lesson3inPlan) { return grid.gridId === "lesson-plan" ? this.lesson3Y : -1; } return grid.gridId === "lesson-plan" ? -1 : 0; }, w: 1, h: parseInt(this.lesson1Length) + 1, key: "lesson3", data: (grid) => { return { text: grid.gridId === "lesson-storage" ? this.lessonData.lesson3.outside : this.lessonData.lesson3.inside, }; }, }, ]; }, }, }; </script> <style scoped> .row { display: flex; justify-content: space-between; } .row > div:not(.bordered) { display: flex; flex-direction: column; gap: 3px; } .bordered { border: 2px solid grey; } .container { background: lightcoral; width: 100%; height: 100%; } </style>