How woai3c/visual-drag-demo works
Main Components
• Application Shell – This includes the main Vue application (src/main.js) with the global configuration and initialization.
• Editor Interface – The central “Editor” module (under src/components/Editor) that encompasses several subcomponents, such as:
• Canvas/Preview
• Grid
• Custom Components Library – Located under src/custom-component, which contains different types of user-defined components (e.g., CircleShape, RectShape, VText, VButton, and SVG components). This can be treated as a plugin-like architecture to extend the available components.
• State Management – Vuex store modules (src/store directory) that manage various aspects such as alignment, animation, event handling, layering, and snapshots (undo/redo features).
• Routing – The vue-router in src/router that handles different views and navigation, e.g., Home view in src/views.
• Utility Functions – A set of shared utilities located under src/utils that support functionalities like animation, coordinate calculations, and event bus management.
• Public Files & Configurations – The public directory (with index.html) and configuration files including babel, eslint, prettier, etc., that manage development and build configurations.
Relationship and Interactions Between Components
• The Application Shell loads the main Vue instance, which sets up the Routing (src/router) and the Global State (src/store).
• The Editor view (src/views/Home.vue) is central; it integrates various subcomponents such as the toolbar, component list (both built-in and custom), and the drag-and-drop canvas.
• When a user drags a component from the Component List (or Custom Component List) onto the canvas, interactions are managed via the central state store and utilities that calculate positions, sizes, and events.
• Editor components (like the context menu, grid, and preview modules) communicate with each other using event buses (as seen in src/utils/eventBus.js) and Vuex actions/mutations.
• Custom Components are built with a standardized “Component” and “Attr” structure for each type (such as Button, Text, etc.), ensuring consistency. Common shared functionalities (linkage, events, requests) exist under src/custom-component/common.
• The style and assets modules ensure that all components maintain a consistent UI/UX, with additional styles and themes distinguished in src/styles.
Architectural Patterns and Design Principles
• MVC/MVVM Patterns: The project separates the view layers (Vue components) from state management (Vuex) and business logic (utility functions, component modules).
• Modular Components: The Editor and custom components are organized as self-contained modules, which promotes extensibility (e.g., adding more custom components is simply a folder addition under src/custom-component).
• Event-driven Communication: Use of eventBus and Vuex for communication between layers is central to handling interactions (such as drag-and-drop, component attribute changes, or undo/redo operations).
Relevant Technologies and Frameworks
• Vue.js, including Vue Router and Vuex.
• ESLint, Prettier, and Babel for code quality and compatibility.
• Modern JavaScript utilities and libraries to handle animations, component positioning, and drag-and-drop functionalities.
• CSS/SCSS and Component-specific styling to ensure modular styling.