Whatever ClearWindow needs to be in json
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 42s
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 42s
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import { ref } from 'vue'
|
||||
import { defWindows } from './WindowDefinitions';
|
||||
import { defineAsyncComponent } from 'vue'
|
||||
|
||||
const componentCache = {}
|
||||
|
||||
const getComponent = (type) => {
|
||||
if (!componentCache[type]) {
|
||||
componentCache[type] = defineAsyncComponent(
|
||||
defWindows[type].component
|
||||
)
|
||||
}
|
||||
|
||||
return componentCache[type]
|
||||
}
|
||||
|
||||
const windows = ref([]);
|
||||
|
||||
const getComponent = (type) => defineAsyncComponent(defWindows[type]?.component)
|
||||
|
||||
const reload = ref(0);
|
||||
|
||||
let ReloadRef = () => { return reload };
|
||||
let Windows = () => { return windows };
|
||||
let WindowMap = () => { return windowMap };
|
||||
|
||||
let currentIndex = 10;
|
||||
@@ -107,8 +113,9 @@ function SetupHandle(id, handle) {
|
||||
|
||||
// Should move eventually?
|
||||
window.addEventListener('resize', (event) => {
|
||||
if(!win.movable){
|
||||
ResetPosition(id, "center");
|
||||
for(const w of windows.value){
|
||||
if(w.movable) continue;
|
||||
ResetPosition(w.id, "center");
|
||||
}
|
||||
})
|
||||
|
||||
@@ -182,6 +189,7 @@ function GetPosition(id) {
|
||||
}
|
||||
|
||||
function ResetPosition(id, pos) {
|
||||
console.log("The id: ", id)
|
||||
let win = GetWindowWithId(id);
|
||||
let data = { x: win.x, y: win.y };
|
||||
|
||||
@@ -194,42 +202,48 @@ function ResetPosition(id, pos) {
|
||||
|
||||
|
||||
function CreateWindow(type, data = {}) {
|
||||
console.log("Creating window")
|
||||
console.log(windows.value);
|
||||
|
||||
let finalData = { ...{ type, id: currentId }, ...defWindows[type], ...data }
|
||||
console.log(finalData);
|
||||
|
||||
currentId++;
|
||||
|
||||
let contains = false;
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].type == finalData.type) {
|
||||
contains = true;
|
||||
console.log("It contains")
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) {
|
||||
windows.value.push(finalData);
|
||||
currentId++;
|
||||
console.log(finalData);
|
||||
console.log("Pushed ", finalData.type);
|
||||
// reload.value += 1;
|
||||
|
||||
console.log(windows.value);
|
||||
|
||||
console.log(windows.value)
|
||||
setTimeout(() => {
|
||||
SetOnTop(finalData.type);
|
||||
SetOnTop(finalData.id);
|
||||
if (finalData.create) finalData.create();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function CreateChildWindow(parentId, type, data = {}) {
|
||||
console.log("Creating child window")
|
||||
console.log(parentId, type, data);
|
||||
let finalData = { ...{ type }, ...defWindows[type], ...data }
|
||||
|
||||
let parent = GetWindowWithId(parentId);
|
||||
console.log(parent);
|
||||
if (parent.children) parent.children.push(finalData.type);
|
||||
else parent.children = [finalData.type];
|
||||
CreateWindow(type, data);
|
||||
}
|
||||
|
||||
function GetFirstWindowId(type) {
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].type == type) return windows.value[i].id;
|
||||
}
|
||||
}
|
||||
|
||||
function ClearAll() {
|
||||
Object.keys(windows).forEach((key) => {
|
||||
windows.value = [];
|
||||
@@ -243,21 +257,25 @@ function ClearWindows(data) {
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function ClearWindowsWithType(type) {
|
||||
const index = windows.value.findIndex(w => w.type === type);
|
||||
if (index !== -1) ClearWindow(windows.value[index].id)
|
||||
// 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.type !== id });
|
||||
if (win.children) for (let i = 0; i < win.children.length; i++) ClearWindow(win.children[i].id);
|
||||
const index = windows.value.findIndex(w => w.type === id)
|
||||
if (index !== -1) windows.value.splice(index, 1)
|
||||
// reload.value += 1;
|
||||
}
|
||||
|
||||
function GetWindowWithId(id) {
|
||||
for (let i = 0; i < windows.value.length; i++) {
|
||||
if (windows.value[i].type == id) {
|
||||
return windows.value[i];
|
||||
}
|
||||
}
|
||||
const index = windows.value.findIndex(w => w.id === id);
|
||||
if (index !== -1) return windows.value[index];
|
||||
}
|
||||
|
||||
function CallWindow(id, callableName, arg) {
|
||||
@@ -283,6 +301,7 @@ function SetOnTop(id) {
|
||||
}
|
||||
|
||||
export {
|
||||
windows,
|
||||
SetupHandle,
|
||||
SetSize,
|
||||
SetResizable,
|
||||
@@ -291,17 +310,17 @@ export {
|
||||
SetPosition,
|
||||
SetMovable,
|
||||
ResetPosition,
|
||||
Windows,
|
||||
WindowMap,
|
||||
ReloadRef,
|
||||
ClearWindows,
|
||||
CreateWindow,
|
||||
CreateChildWindow,
|
||||
GetFirstWindowId,
|
||||
CallWindow,
|
||||
GetWindowWithId,
|
||||
SaveWindowPos,
|
||||
GetPosition,
|
||||
ClearWindow,
|
||||
ClearWindowsWithType,
|
||||
ClearAll,
|
||||
getComponent
|
||||
}
|
||||
Reference in New Issue
Block a user