Improve canvas editor modal open/close logic

Refactored the canvas editor modal to allow toggling open and close with the same button. Updated button text and title to reflect the editor state, removed the separate close button, and improved state management for better user experience.
This commit is contained in:
Dariusz L
2025-06-24 19:16:14 +02:00
parent d5e35f4cfc
commit ec3e07f4c4

View File

@@ -670,39 +670,52 @@ async function createCanvasWidget(node, widget, app) {
node.size = [500, 500]; node.size = [500, 500];
const openEditorBtn = controlPanel.querySelector(`#open-editor-btn-${node.id}`); const openEditorBtn = controlPanel.querySelector(`#open-editor-btn-${node.id}`);
openEditorBtn.onclick = () => { let backdrop = null;
const originalParent = mainContainer.parentNode; let modalContent = null;
if (!originalParent) { let originalParent = null;
console.error("Could not find original parent of the canvas container!"); let isEditorOpen = false;
return;
}
const backdrop = $el("div.painter-modal-backdrop");
const modalContent = $el("div.painter-modal-content");
modalContent.appendChild(mainContainer); const closeEditor = () => {
backdrop.appendChild(modalContent); originalParent.appendChild(mainContainer);
document.body.appendChild(backdrop); document.body.removeChild(backdrop);
openEditorBtn.disabled = true;
isEditorOpen = false;
openEditorBtn.textContent = "⛶";
openEditorBtn.title = "Open in Editor";
canvas.render(); canvas.render();
if (node.onResize) { if (node.onResize) {
node.onResize(); node.onResize();
} }
};
const closeButton = $el("button", { openEditorBtn.onclick = () => {
textContent: "Close", if (isEditorOpen) {
style: { position: 'absolute', top: '10px', right: '10px', zIndex: 100 }, closeEditor();
onclick: () => { return;
originalParent.appendChild(mainContainer); }
document.body.removeChild(backdrop);
openEditorBtn.disabled = false; originalParent = mainContainer.parentNode;
canvas.render(); if (!originalParent) {
if (node.onResize) { console.error("Could not find original parent of the canvas container!");
node.onResize(); return;
} }
}
}); backdrop = $el("div.painter-modal-backdrop");
modalContent.appendChild(closeButton); modalContent = $el("div.painter-modal-content");
modalContent.appendChild(mainContainer);
backdrop.appendChild(modalContent);
document.body.appendChild(backdrop);
isEditorOpen = true;
openEditorBtn.textContent = "X";
openEditorBtn.title = "Close Editor";
canvas.render();
if (node.onResize) {
node.onResize();
}
}; };
api.addEventListener("execution_start", async () => { api.addEventListener("execution_start", async () => {