From 157c1d40d55854c47b5fdddfe1c8f1e3757cec5a Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Mon, 14 Jul 2025 16:40:26 +0800 Subject: [PATCH] Refactor service drag-and-drop to use SortableJS Replaces custom drag-and-drop logic in ServicesManager with SortableJS for improved reliability and cross-browser support. Updates UI to use a dedicated drag handle, removes legacy drag styles, and adds new CSS for SortableJS integration. Also removes redundant version comments from source files. --- index.html | 3 + src/scripts/app.js | 1 - src/scripts/components/OutputManager.js | 1 - .../components/ServiceConfigGenerator.js | 1 - src/scripts/components/ServicesManager.js | 331 +++++------------- src/scripts/components/ThemeManager.js | 1 - src/styles/main.css | 199 +++++------ src/templates/meta-template.js | 1 - 8 files changed, 177 insertions(+), 361 deletions(-) diff --git a/index.html b/index.html index e626b25..8a4338a 100644 --- a/index.html +++ b/index.html @@ -56,6 +56,9 @@ href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet" /> + + + diff --git a/src/scripts/app.js b/src/scripts/app.js index 41385fe..db7021b 100644 --- a/src/scripts/app.js +++ b/src/scripts/app.js @@ -13,7 +13,6 @@ * * @author xixu-me * @license GPL-3.0 - * @version 2.0.0 */ import { OutputManager } from "./components/OutputManager.js"; diff --git a/src/scripts/components/OutputManager.js b/src/scripts/components/OutputManager.js index 8168436..5cc884e 100644 --- a/src/scripts/components/OutputManager.js +++ b/src/scripts/components/OutputManager.js @@ -9,7 +9,6 @@ * * @author xixu-me * @license GPL-3.0 - * @version 2.0.0 */ export class OutputManager { diff --git a/src/scripts/components/ServiceConfigGenerator.js b/src/scripts/components/ServiceConfigGenerator.js index 65b0dbd..9cd2258 100644 --- a/src/scripts/components/ServiceConfigGenerator.js +++ b/src/scripts/components/ServiceConfigGenerator.js @@ -7,7 +7,6 @@ * * @author xixu-me * @license GPL-3.0 - * @version 2.0.0 */ export class ServiceConfigGenerator { diff --git a/src/scripts/components/ServicesManager.js b/src/scripts/components/ServicesManager.js index 777efd7..5543edc 100644 --- a/src/scripts/components/ServicesManager.js +++ b/src/scripts/components/ServicesManager.js @@ -9,7 +9,6 @@ * * @author xixu-me * @license GPL-3.0 - * @version 2.0.0 */ export class ServicesManager { @@ -21,19 +20,9 @@ export class ServicesManager { this.allServices = []; this.selectedServices = new Set(); - this.selectedServicesOrder = []; // Track order for drag functionality + this.selectedServicesOrder = []; this.searchTimeout = null; - - // Drag state - this.dragState = { - isDragging: false, - draggedElement: null, - draggedIndex: -1, - placeholder: null, - initialMouseY: 0, - initialElementY: 0, - mouseOffset: 0, - }; + this.sortable = null; // SortableJS instance this.elements = { searchInput: document.getElementById("search-input"), @@ -127,26 +116,6 @@ export class ServicesManager { this.elements.selectedServices.addEventListener("click", (e) => { this.handleSelectedServiceClick(e); }); - - // Handle drag events - this.setupDragListeners(); - } - - /** - * Set up drag and drop event listeners - */ - setupDragListeners() { - this.elements.selectedServices.addEventListener("mousedown", (e) => { - this.handleDragStart(e); - }); - - document.addEventListener("mousemove", (e) => { - this.handleDragMove(e); - }); - - document.addEventListener("mouseup", (e) => { - this.handleDragEnd(e); - }); } /** @@ -299,6 +268,7 @@ export class ServicesManager {

Search for services above to get started

`; + this.destroySortable(); return; } @@ -306,9 +276,11 @@ export class ServicesManager { this.elements.selectedServices.innerHTML = this.selectedServicesOrder .map( (serviceName, index) => ` -
+
+
+ +
- ${serviceName}