refactor: separate components into folders
This commit is contained in:
@@ -0,0 +1,154 @@
|
|||||||
|
# Component Organization Guide
|
||||||
|
|
||||||
|
This document describes the organized folder structure for the Svelte components in the Twitch Panels Creator project.
|
||||||
|
|
||||||
|
## 📁 Folder Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
src/components/
|
||||||
|
├── layout/ # Application layout components
|
||||||
|
├── image/ # Image-related components
|
||||||
|
├── text/ # Text management components
|
||||||
|
├── panel/ # Panel display and management
|
||||||
|
├── feedback/ # User feedback components
|
||||||
|
└── ui/ # Reusable UI components (from lib)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🏗️ Layout Components
|
||||||
|
|
||||||
|
**Location**: `src/components/layout/`
|
||||||
|
|
||||||
|
Components that define the overall application structure and layout:
|
||||||
|
|
||||||
|
- **AppContainer.svelte** - Main application wrapper and coordinator
|
||||||
|
- **AppHeader.svelte** - Application header with title and actions
|
||||||
|
- **AppContent.svelte** - Main content area container
|
||||||
|
- **MainSection.svelte** - Primary workspace section
|
||||||
|
- **Sidebar.svelte** - Side panel for previews and controls
|
||||||
|
|
||||||
|
## 🖼️ Image Components
|
||||||
|
|
||||||
|
**Location**: `src/components/image/`
|
||||||
|
|
||||||
|
Components related to image upload, processing, and display:
|
||||||
|
|
||||||
|
- **ImageManager.svelte** - Orchestrates image upload and cropping workflow
|
||||||
|
- **ImageUpload.svelte** - Handles drag-drop, paste, and URL image upload
|
||||||
|
- **ImageCropper.svelte** - Provides image cropping interface with cropperjs
|
||||||
|
- **BackgroundPreview.svelte** - Displays the background image preview
|
||||||
|
|
||||||
|
## 📝 Text Components
|
||||||
|
|
||||||
|
**Location**: `src/components/text/`
|
||||||
|
|
||||||
|
Components for text management and display:
|
||||||
|
|
||||||
|
- **TextManager.svelte** - Main text input and settings management
|
||||||
|
- **TextSection.svelte** - Text management section wrapper
|
||||||
|
- **TextPreview.svelte** - Preview of text styling and positioning
|
||||||
|
|
||||||
|
## 🎨 Panel Components
|
||||||
|
|
||||||
|
**Location**: `src/components/panel/`
|
||||||
|
|
||||||
|
Components for panel creation, preview, and management:
|
||||||
|
|
||||||
|
- **PanelPreview.svelte** - Individual panel preview with canvas rendering
|
||||||
|
- **PanelsList.svelte** - List of all created panels
|
||||||
|
- **PanelList.svelte** - Alternative panel list implementation
|
||||||
|
|
||||||
|
## 💬 Feedback Components
|
||||||
|
|
||||||
|
**Location**: `src/components/feedback/`
|
||||||
|
|
||||||
|
Components for user feedback and error handling:
|
||||||
|
|
||||||
|
- **ErrorMessage.svelte** - Displays error messages to users
|
||||||
|
|
||||||
|
## 🧩 UI Components
|
||||||
|
|
||||||
|
**Location**: `src/components/ui/` (from lib)
|
||||||
|
|
||||||
|
Reusable UI components:
|
||||||
|
|
||||||
|
- **Button.svelte** - Standard button component
|
||||||
|
- **IconButton.svelte** - Button with icon support
|
||||||
|
|
||||||
|
## 🔧 Import Conventions
|
||||||
|
|
||||||
|
When importing components, follow these patterns:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Layout components
|
||||||
|
import AppContainer from "../components/layout/AppContainer.svelte";
|
||||||
|
import AppHeader from "../components/layout/AppHeader.svelte";
|
||||||
|
|
||||||
|
// Image components
|
||||||
|
import ImageManager from "../components/image/ImageManager.svelte";
|
||||||
|
import ImageUpload from "../components/image/ImageUpload.svelte";
|
||||||
|
|
||||||
|
// Text components
|
||||||
|
import TextManager from "../components/text/TextManager.svelte";
|
||||||
|
import TextSection from "../components/text/TextSection.svelte";
|
||||||
|
|
||||||
|
// Panel components
|
||||||
|
import PanelPreview from "../components/panel/PanelPreview.svelte";
|
||||||
|
import PanelsList from "../components/panel/PanelsList.svelte";
|
||||||
|
|
||||||
|
// Feedback components
|
||||||
|
import ErrorMessage from "../components/feedback/ErrorMessage.svelte";
|
||||||
|
|
||||||
|
// UI components
|
||||||
|
import { Button } from "../lib/components/ui";
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🎯 Benefits of This Organization
|
||||||
|
|
||||||
|
1. **Logical Grouping**: Components are grouped by functionality, making them easy to find
|
||||||
|
2. **Maintainability**: Related components are co-located, reducing cognitive load
|
||||||
|
3. **Scalability**: Easy to add new components to appropriate categories
|
||||||
|
4. **Import Clarity**: Clear import paths that reflect component purpose
|
||||||
|
5. **Team Collaboration**: Consistent structure that team members can follow
|
||||||
|
|
||||||
|
## 📋 Component Responsibilities
|
||||||
|
|
||||||
|
### Layout Components
|
||||||
|
|
||||||
|
- Handle application-wide structure and navigation
|
||||||
|
- Manage high-level state and data flow
|
||||||
|
- Provide containers for functional components
|
||||||
|
|
||||||
|
### Image Components
|
||||||
|
|
||||||
|
- Handle all image-related operations (upload, crop, preview)
|
||||||
|
- Manage image state and validation
|
||||||
|
- Provide image processing functionality
|
||||||
|
|
||||||
|
### Text Components
|
||||||
|
|
||||||
|
- Manage text input, editing, and styling
|
||||||
|
- Handle text validation and state
|
||||||
|
- Provide text preview functionality
|
||||||
|
|
||||||
|
### Panel Components
|
||||||
|
|
||||||
|
- Handle panel creation and management
|
||||||
|
- Provide panel preview and export functionality
|
||||||
|
- Manage panel state and interactions
|
||||||
|
|
||||||
|
### Feedback Components
|
||||||
|
|
||||||
|
- Display user feedback and error messages
|
||||||
|
- Handle user notifications and alerts
|
||||||
|
- Provide consistent error handling UI
|
||||||
|
|
||||||
|
## 🔄 Future Considerations
|
||||||
|
|
||||||
|
As the project grows, consider:
|
||||||
|
|
||||||
|
1. **Sub-categorization**: Further divide categories if they become too large
|
||||||
|
2. **Feature-based organization**: Group by feature rather than type for larger applications
|
||||||
|
3. **Component documentation**: Add individual component documentation
|
||||||
|
4. **Storybook integration**: Use Storybook for component development and testing
|
||||||
|
|
||||||
|
This organization provides a solid foundation for the current project while remaining flexible for future expansion.
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
backgroundImage?: string | undefined;
|
backgroundImage?: string | undefined;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import CropperJS from "cropperjs";
|
import CropperJS from "cropperjs";
|
||||||
import type { ImageCropResult } from "../lib/types/panel";
|
import type { ImageCropResult } from "$lib/types/panel";
|
||||||
import { ImageService } from "../lib/services/imageService";
|
import { ImageService } from "$lib/services/imageService";
|
||||||
import { uiStore, setLoading } from "../stores/uiStore";
|
import { uiStore, setLoading } from "../../stores/uiStore";
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
imageSrc: string;
|
imageSrc: string;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { uiStore, setLoading, clearError, setCurrentStep } from "../stores/uiStore";
|
import { uiStore, setLoading, clearError, setCurrentStep } from "../../stores/uiStore";
|
||||||
import { panelStore } from "../stores/panelStore";
|
import { panelStore } from "../../stores/panelStore";
|
||||||
import { ImageService } from "../lib/services/imageService";
|
import { ImageService } from "$lib/services/imageService";
|
||||||
import { handleError } from "../lib/utils/errorHandler";
|
import { handleError } from "$lib/utils/errorHandler";
|
||||||
import type { ImageUploadResult } from "../lib/types/panel";
|
import type { ImageUploadResult } from "$lib/types/panel";
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
let imageService = new ImageService();
|
let imageService = new ImageService();
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import AppHeader from "./AppHeader.svelte";
|
import AppHeader from "./AppHeader.svelte";
|
||||||
import ErrorMessage from "./ErrorMessage.svelte";
|
import ErrorMessage from "../feedback/ErrorMessage.svelte";
|
||||||
import AppContent from "./AppContent.svelte";
|
import AppContent from "./AppContent.svelte";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onUploadNewImage?: () => void;
|
onUploadNewImage?: () => void;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { uiStore } from "../stores/uiStore";
|
import { uiStore } from "../../stores/uiStore";
|
||||||
import ImageManager from "./ImageManager.svelte";
|
import ImageManager from "../image/ImageManager.svelte";
|
||||||
import TextSection from "./TextSection.svelte";
|
import TextSection from "../text/TextSection.svelte";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
uploadedImage: string | undefined;
|
uploadedImage: string | undefined;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { uiStore } from "../stores/uiStore";
|
import { uiStore } from "../../stores/uiStore";
|
||||||
import BackgroundPreview from "./BackgroundPreview.svelte";
|
import BackgroundPreview from "../image/BackgroundPreview.svelte";
|
||||||
import PanelsList from "./PanelsList.svelte";
|
import PanelsList from "../panel/PanelsList.svelte";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
backgroundImage: string | undefined;
|
backgroundImage: string | undefined;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { panelStore } from "../stores/panelStore";
|
import { panelStore } from "../../stores/panelStore";
|
||||||
import { panelStorage } from "../lib/utils/panelStorage";
|
import { panelStorage } from "$lib/utils/panelStorage";
|
||||||
import type { Panel } from "../lib/types/panel";
|
import type { Panel } from "$lib/types/panel";
|
||||||
import { IconButton } from "../lib/components/ui";
|
import { IconButton } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onPanelSelect: (panel: Panel) => void;
|
onPanelSelect: (panel: Panel) => void;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { uiStore, setCurrentStep } from "../stores/uiStore";
|
import { uiStore, setCurrentStep } from "../../stores/uiStore";
|
||||||
import type { Panel } from "../lib/types/panel";
|
import type { Panel } from "$lib/types/panel";
|
||||||
|
|
||||||
type TextItem = Panel["texts"][0];
|
type TextItem = Panel["texts"][0];
|
||||||
import { Stage, Layer, Image, Text } from "svelte-konva";
|
import { Stage, Layer, Image, Text } from "svelte-konva";
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
panel: Panel;
|
panel: Panel;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Panel } from "../lib/types/panel";
|
import type { Panel } from "$lib/types/panel";
|
||||||
import PanelPreview from "./PanelPreview.svelte";
|
import PanelPreview from "./PanelPreview.svelte";
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
panels: Panel[];
|
panels: Panel[];
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button } from "$lib/components/ui";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onTextAdd: (text: string) => void;
|
onTextAdd: (text: string) => void;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { TextItem } from "../lib/types/panel";
|
import type { TextItem } from "$lib/types/panel";
|
||||||
import { panelStore } from "../stores/panelStore";
|
import { panelStore } from "../../stores/panelStore";
|
||||||
import { Stage, Layer, Image, Text } from "svelte-konva";
|
import { Stage, Layer, Image, Text } from "svelte-konva";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -4,9 +4,9 @@
|
|||||||
import { imageService } from "../services/imageService";
|
import { imageService } from "../services/imageService";
|
||||||
import { panelService } from "../services/panelService";
|
import { panelService } from "../services/panelService";
|
||||||
import { exportService } from "../services/exportService";
|
import { exportService } from "../services/exportService";
|
||||||
import type { Panel } from "../lib/types/panel";
|
import type { Panel } from "$lib/types/panel";
|
||||||
|
|
||||||
import AppContainer from "../components/AppContainer.svelte";
|
import AppContainer from "../components/layout/AppContainer.svelte";
|
||||||
|
|
||||||
let uploadedImage = $state<string | undefined>(undefined);
|
let uploadedImage = $state<string | undefined>(undefined);
|
||||||
let panels = $state<Panel[]>([]);
|
let panels = $state<Panel[]>([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user