This commit is contained in:
@@ -1,33 +1,9 @@
|
||||
import { ref } from 'vue'
|
||||
import { defWindows } from './WindowDefinitions';
|
||||
|
||||
const windows = ref([]);
|
||||
|
||||
import LoginWindow from '~/components/windows/LoginWindow.vue';
|
||||
import RegisterWindow from '~/components/windows/RegisterWindow.vue';
|
||||
import ExampleWindow from '~/components/windows/ExampleWindow.vue';
|
||||
|
||||
let windowMap = {
|
||||
login: LoginWindow,
|
||||
register: RegisterWindow,
|
||||
example: ExampleWindow
|
||||
};
|
||||
|
||||
// Presets
|
||||
const defValues = {
|
||||
'example': {
|
||||
id: "example",
|
||||
title: "Example",
|
||||
close: () => ClearWindow('example')
|
||||
},
|
||||
'login': {
|
||||
id: 'login',
|
||||
title: 'Login',
|
||||
},
|
||||
'register': {
|
||||
id: 'register',
|
||||
title: 'Register'
|
||||
}
|
||||
}
|
||||
const getComponent = (type) => defineAsyncComponent(defWindows[type]?.component)
|
||||
|
||||
const reload = ref(0);
|
||||
|
||||
@@ -36,11 +12,12 @@ let Windows = () => { return windows };
|
||||
let WindowMap = () => { return windowMap };
|
||||
|
||||
let currentIndex = 10;
|
||||
let currentId = 0;
|
||||
|
||||
function SetupHandle(id, handle) {
|
||||
|
||||
// Update window info with handle info
|
||||
|
||||
console.log(id);
|
||||
let win = GetWindowWithId(id);
|
||||
|
||||
let currentWindowId = "window-wrapper-" + id;
|
||||
@@ -68,7 +45,7 @@ function SetupHandle(id, handle) {
|
||||
|
||||
// Move window listeners
|
||||
handler.addEventListener("mousedown", (event) => {
|
||||
if(win.noMove) return;
|
||||
if(!win.movable) return;
|
||||
draggingWindow = true;
|
||||
|
||||
let windowRect = currentWindow.getBoundingClientRect();
|
||||
@@ -77,7 +54,7 @@ function SetupHandle(id, handle) {
|
||||
})
|
||||
|
||||
document.addEventListener("mousemove", (event) => {
|
||||
if(win.noMove) return;
|
||||
if(!win.movable) return;
|
||||
if (!draggingWindow) return;
|
||||
|
||||
if (event.clientX + offsetX < -currentWindow.getBoundingClientRect().width + 20) currentWindow.style.left = (-currentWindow.getBoundingClientRect().width + 20) + "px";
|
||||
@@ -90,7 +67,7 @@ function SetupHandle(id, handle) {
|
||||
})
|
||||
|
||||
document.addEventListener("mouseup", (event) => {
|
||||
if(win.noMove) return;
|
||||
if(!win.movable) return;
|
||||
draggingWindow = false;
|
||||
// ummm suposo que no pots tancar mentres mous?
|
||||
SaveWindowPos({ id, x: parseInt(currentWindow.style.left, 10), y: parseInt(currentWindow.style.top, 10) });
|
||||
@@ -128,6 +105,13 @@ function SetupHandle(id, handle) {
|
||||
win.height = parseInt(currentWindow.style.height, 10);
|
||||
});
|
||||
|
||||
// Should move eventually?
|
||||
window.addEventListener('resize', (event) => {
|
||||
if(!win.movable){
|
||||
ResetPosition(id, "center");
|
||||
}
|
||||
})
|
||||
|
||||
handle.value.setupHandle();
|
||||
}
|
||||
|
||||
@@ -138,7 +122,7 @@ function SetResizable(id, resizable) {
|
||||
|
||||
function SetMovable(id, movable) {
|
||||
let win = GetWindowWithId(id);
|
||||
win.noMove = !movable;
|
||||
win.movable = movable;
|
||||
}
|
||||
|
||||
function SetSize(id, size) {
|
||||
@@ -211,35 +195,38 @@ function ResetPosition(id, pos) {
|
||||
|
||||
function CreateWindow(type, data = {}) {
|
||||
|
||||
let finalData = { ...{ type }, ...defValues[type], ...data }
|
||||
let finalData = { ...{ type, id: currentId }, ...defWindows[type], ...data }
|
||||
console.log(finalData);
|
||||
|
||||
let contains = false;
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].id == finalData.id) {
|
||||
if (windows.value[i].type == finalData.type) {
|
||||
contains = true;
|
||||
console.log("It contains")
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) {
|
||||
windows.value.push(finalData);
|
||||
console.log("Pushed ", finalData.id);
|
||||
currentId++;
|
||||
console.log(finalData);
|
||||
console.log("Pushed ", finalData.type);
|
||||
// reload.value += 1;
|
||||
|
||||
console.log(windows.value);
|
||||
setTimeout(() => {
|
||||
SetOnTop(finalData.id);
|
||||
SetOnTop(finalData.type);
|
||||
if (finalData.create) finalData.create();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function CreateChildWindow(parentId, type, data = {}) {
|
||||
let finalData = { ...{ type }, ...defValues[type], ...data }
|
||||
let finalData = { ...{ type }, ...defWindows[type], ...data }
|
||||
|
||||
let parent = GetWindowWithId(parentId);
|
||||
if (parent.children) parent.children.push(finalData.id);
|
||||
else parent.children = [finalData.id];
|
||||
if (parent.children) parent.children.push(finalData.type);
|
||||
else parent.children = [finalData.type];
|
||||
CreateWindow(type, data);
|
||||
}
|
||||
|
||||
@@ -251,22 +238,23 @@ function ClearAll() {
|
||||
|
||||
function ClearWindows(data) {
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
ClearWindow(windows.value[i].id);
|
||||
ClearWindow(windows.value[i].type);
|
||||
}
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function ClearWindow(id) {
|
||||
let win = GetWindowWithId(id);
|
||||
console.log(win);
|
||||
if (!win) return;
|
||||
if (win.children) for (let i = 0; i < win.children.length; i++) ClearWindow(win.children[i]);
|
||||
windows.value = windows.value.filter((e) => { return e.id !== id });
|
||||
windows.value = windows.value.filter((e) => { return e.type !== id });
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function GetWindowWithId(id) {
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].id == id) {
|
||||
if (windows.value[i].type == id) {
|
||||
return windows.value[i];
|
||||
}
|
||||
}
|
||||
@@ -288,8 +276,10 @@ function SetOnTop(id) {
|
||||
let currentWindowId = "window-wrapper-" + id;
|
||||
let currentWindow = document.getElementById(currentWindowId);
|
||||
|
||||
currentIndex += 1;
|
||||
currentWindow.style.zIndex = currentIndex;
|
||||
try {
|
||||
currentIndex += 1;
|
||||
currentWindow.style.zIndex = currentIndex;
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -312,5 +302,6 @@ export {
|
||||
SaveWindowPos,
|
||||
GetPosition,
|
||||
ClearWindow,
|
||||
ClearAll
|
||||
ClearAll,
|
||||
getComponent
|
||||
}
|
||||
Reference in New Issue
Block a user