From a188ec7b6e9cb6558fde757f486cab5cde5e3b90 Mon Sep 17 00:00:00 2001 From: elioat Date: Sun, 22 Dec 2024 17:24:42 -0500 Subject: * --- html/file-system/index.html | 227 +++++++++++++++++++++++++++----------------- 1 file changed, 141 insertions(+), 86 deletions(-) (limited to 'html/file-system') diff --git a/html/file-system/index.html b/html/file-system/index.html index 6743b8a..8e05088 100644 --- a/html/file-system/index.html +++ b/html/file-system/index.html @@ -293,6 +293,107 @@ .resize-handle:hover { background-color: #e0e0e0; } + + /* Update the inchworm styles */ + .inchworm { + position: absolute; + top: -16px; + left: 0; + font-size: 22px; + animation: inch 18s infinite linear; + transform-origin: center; + color: green; + } + + @keyframes inch { + /* Going forward */ + 0% { + left: 0; + transform: scaleX(1) scaleY(1); + } + 5% { + left: 0; + transform: scaleX(0.4) scaleY(1.4); + } + 10% { + left: 30px; + transform: scaleX(1.3) scaleY(0.7); + } + 15% { + left: 30px; + transform: scaleX(0.4) scaleY(1.4); + } + 20% { + left: 60px; + transform: scaleX(1.3) scaleY(0.7); + } + 25% { + left: 60px; + transform: scaleX(0.4) scaleY(1.4); + } + 30% { + left: 90px; + transform: scaleX(1.3) scaleY(0.7); + } + 35% { + left: 90px; + transform: scaleX(0.4) scaleY(1.4); + } + 40% { + left: 120px; + transform: scaleX(1.3) scaleY(0.7); + } + + /* Pause at end */ + 42% { + left: 120px; + transform: scaleX(1) scaleY(1); + } + + /* Going back */ + 45% { + left: 120px; + transform: scaleX(0.4) scaleY(1.4); + } + 50% { + left: 90px; + transform: scaleX(1.3) scaleY(0.7); + } + 55% { + left: 90px; + transform: scaleX(0.4) scaleY(1.4); + } + 60% { + left: 60px; + transform: scaleX(1.3) scaleY(0.7); + } + 65% { + left: 60px; + transform: scaleX(0.4) scaleY(1.4); + } + 70% { + left: 30px; + transform: scaleX(1.3) scaleY(0.7); + } + 75% { + left: 30px; + transform: scaleX(0.4) scaleY(1.4); + } + 80% { + left: 0; + transform: scaleX(1.3) scaleY(0.7); + } + + /* Pause at start */ + 85% { + left: 0; + transform: scaleX(1) scaleY(1); + } + 100% { + left: 0; + transform: scaleX(1) scaleY(1); + } + } @@ -326,11 +427,8 @@ +
O
-
-
-
-
@@ -395,6 +493,16 @@ const addFolder = (path, name, folderData, fileSystem) => { }; const deleteFolder = (path, fileSystem) => { + if (path === 'root') { + return fileSystem; + } + + if (!path.includes('/')) { + const newFileSystem = clone(fileSystem); + delete newFileSystem.root.children[path]; + return newFileSystem; + } + const [parentPath, folderName] = path.split(/\/([^\/]+)$/); return updateFolder(fileSystem, parentPath, (folder) => { delete folder.children[folderName]; @@ -431,26 +539,39 @@ const createFolder = (path, name) => { }; const deleteItem = () => { - if (state.currentFolderPath === 'root') return alert("Can't delete the root!"); - - const folderToDelete = getFolder(state.currentFolderPath); - if (!folderToDelete) return alert("Folder not found!"); + // Don't do anything if no folder is selected + if (!state.currentFolderPath) return; - const hasNestedFolders = Object.keys(folderToDelete.children).length > 0; + // Check if trying to delete root + if (state.currentFolderPath === 'root') { + alert("Can't delete the root folder!"); + return; + } - if (hasNestedFolders) { - const confirmDelete = confirm(`The folder contains nested folders. Do you really wanna delete them too?`); - if (!confirmDelete) { - return; - } + // For top-level folders (direct children of root) + if (!state.currentFolderPath.includes('/')) { + const newFileSystem = clone(state.fileSystem); + delete newFileSystem.root.children[state.currentFolderPath]; + updateFileSystem(newFileSystem); + state.currentFolderPath = 'root'; + document.getElementById('editor').style.display = 'none'; + render(); + return; } - const updatedFileSystem = deleteFolder(state.currentFolderPath, state.fileSystem); - if (updatedFileSystem) { - const parts = state.currentFolderPath.split('/'); - parts.pop(); - state.currentFolderPath = parts.join('/') || 'root'; - updateFileSystem(updatedFileSystem); + // For nested folders + const pathParts = state.currentFolderPath.split('/'); + const folderToDelete = pathParts.pop(); // Get the folder name to delete + const parentPath = pathParts.join('/'); // Get the parent path + + const newFileSystem = clone(state.fileSystem); + const parentFolder = getFolder(parentPath, newFileSystem); + + if (parentFolder && parentFolder.children) { + delete parentFolder.children[folderToDelete]; + updateFileSystem(newFileSystem); + state.currentFolderPath = parentPath; + document.getElementById('editor').style.display = 'none'; render(); } }; @@ -683,9 +804,6 @@ let initialX; let initialY; let xOffset = 0; let yOffset = 0; -let isResizing = false; -let currentHandle = null; -let startWidth, startHeight, startX, startY; const dragStart = (e) => { if (e.target.closest('#closeEditor') || e.target.classList.contains('resize-handle')) return; @@ -745,63 +863,6 @@ editorHeader.addEventListener("mousedown", dragStart, false); document.addEventListener("mousemove", drag, false); document.addEventListener("mouseup", dragEnd, false); -// Add resize functionality -const initResize = (e) => { - if (e.target.classList.contains('resize-handle')) { - isResizing = true; - currentHandle = e.target; - - startWidth = editor.offsetWidth; - startHeight = editor.offsetHeight; - startX = e.clientX; - startY = e.clientY; - - e.preventDefault(); - e.stopPropagation(); - } -}; - -const doResize = (e) => { - if (!isResizing) return; - - const deltaX = e.clientX - startX; - const deltaY = e.clientY - startY; - - let newWidth = startWidth; - let newHeight = startHeight; - - if (currentHandle.classList.contains('se') || currentHandle.classList.contains('ne')) { - newWidth = startWidth + deltaX; - } else if (currentHandle.classList.contains('sw') || currentHandle.classList.contains('nw')) { - newWidth = startWidth - deltaX; - editor.style.left = `${editor.offsetLeft + deltaX}px`; - } - - if (currentHandle.classList.contains('se') || currentHandle.classList.contains('sw')) { - newHeight = startHeight + deltaY; - } else if (currentHandle.classList.contains('ne') || currentHandle.classList.contains('nw')) { - newHeight = startHeight - deltaY; - editor.style.top = `${editor.offsetTop + deltaY}px`; - } - - // Apply minimum dimensions - newWidth = Math.max(200, newWidth); - newHeight = Math.max(150, newHeight); - - editor.style.width = `${newWidth}px`; - editor.style.height = `${newHeight}px`; -}; - -const stopResize = () => { - isResizing = false; - currentHandle = null; -}; - -// Add event listeners for resize -document.addEventListener('mousedown', initResize); -document.addEventListener('mousemove', doResize); -document.addEventListener('mouseup', stopResize); - const setEditorSize = (mode, editorElement = editor) => { // Reset any existing transforms and positioning editorElement.style.transform = 'none'; @@ -864,12 +925,6 @@ const setEditorSize = (mode, editorElement = editor) => { xOffset = 0; yOffset = 0; - // Remove resize handles when not in normal mode - const resizeHandles = editorElement.querySelectorAll('.resize-handle'); - resizeHandles.forEach(handle => { - handle.style.display = mode === 'normal' ? 'block' : 'none'; - }); - // Ensure the editor is visible editorElement.style.display = 'block'; }; -- cgit 1.4.1-2-gfad0