# chenxingshuang/react-sortable-hoc architecture

> Architecture diagram of the GitHub repository chenxingshuang/react-sortable-hoc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chenxingshuang/react-sortable-hoc
- Repository: https://github.com/chenxingshuang/react-sortable-hoc

## Overview

##### Main Components Identification
- Library API Components: At the heart of the system are the core HOCs – SortableContainer, SortableElement, and SortableHandle. These are the primary building blocks that enable sortable functionality in a React application.
- Supporting Modules: Additional components and utility modules like AutoScroller (for smooth auto-scroll behaviour), Manager (for overseeing interactions and coordinating state), and helper modules (like defaultGetHelperDimensions and defaultShouldCancelStart) are key parts.
- Storybook and Examples: The .storybook directory and examples folder indicate that there are interactive demos and documentation components that serve to illustrate usage and verify behavior.
- Type Definitions: The types folder provides TypeScript declarations to ensure type safety and improve the developer experience.

##### Relationships and Interactions
- HOC Integration: The SortableContainer wraps a list component and provides the container level logic, whereas SortableElement wraps individual list items to inject sortable behavior. SortableHandle can be used to designate specific parts of an element that, when interacted with (like dragging), trigger the sort action.

##### Architectural Patterns and Design Principles
- Higher-Order Component Pattern: Emphasize how the library uses HOCs to inject functionality into pre-existing components without modifying them directly.
- Reusability and Extensibility: The use of configuration props (e.g., axis, lockAxis, pressDelay, distance) indicates that the system has been built to be widely customizable, enhancing flexibility.

##### Relevant Technologies and Libraries
- React and React-DOM as core peer dependencies.
- Configuration and development tooling such as Storybook for UI documentation and examples.
- Supporting modules like invariants for enforcing constraints.
- Build tools (rollup, eslint/prettier) reflected in the configuration files.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Higher-Order Components
    subgraph "Core HOCs"
        SC["SortableContainer\n(manages drag events and coordinates sorting)"]:::hoc
        SE["SortableElement\n(enhances individual list items)"]:::hoc
        SH["SortableHandle\n(enables touch-friendly drag initiation)"]:::hoc
    end

    %% Supporting Utility Modules
    subgraph "Supporting Modules"
        AC["AutoScroller\n(provides smooth auto-scroll behavior)"]:::utility
        MG["Manager\n(oversees interactions and state coordination)"]:::utility
    end

    %% Documentation and Interactive Examples
    subgraph "Documentation & Examples"
        ST["Storybook\n(UI documentation and demos)"]:::external
        EX["Examples\n(interactive demos and usage samples)"]:::external
    end

    %% External Dependencies and Type Definitions
    subgraph "External Dependencies & Types"
        R["React/React-DOM\n(core peer dependencies)"]:::external
        TD["Type Definitions\n(TypeScript declarations)"]:::ts
    end

    %% Relationships: HOC Composition
    SC -->|"wraps"| SE
    SE -->|"integrates onSortStart,onSortEnd,etc."| MG
    SC -->|"triggers callbacks"| MG
    MG -->|"initiates auto-scroll"| AC

    %% Relationships: External Interactions
    R -->|"used by"| SC
    R -->|"used by"| SE
    R -->|"used by"| SH
    ST -->|"demonstrates usage of"| SC
    ST -->|"demonstrates usage of"| SE
    ST -->|"demonstrates usage of"| SH
    EX -->|"provides interactive examples for"| SC
    EX -->|"provides interactive examples for"| SE
    EX -->|"provides interactive examples for"| SH
    SC -->|"ensures type safety"| TD
    SE -->|"ensures type safety"| TD
    SH -->|"ensures type safety"| TD

    %% Styling
    classDef hoc fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef utility fill:#87CEFA,stroke:#1E90FF,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#32CD32,stroke-width:2px;
    classDef ts fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;

    %% Click Events for Component Mapping
    click SC "https://github.com/chenxingshuang/react-sortable-hoc/tree/master/src/SortableContainer"
    click SE "https://github.com/chenxingshuang/react-sortable-hoc/tree/master/src/SortableElement"
    click SH "https://github.com/chenxingshuang/react-sortable-hoc/tree/master/src/SortableHandle"
    click AC "https://github.com/chenxingshuang/react-sortable-hoc/tree/master/src/AutoScroller"
    click MG "https://github.com/chenxingshuang/react-sortable-hoc/tree/master/src/Manager"
    click ST "https://github.com/chenxingshuang/react-sortable-hoc/blob/master/.storybook"
    click EX "https://github.com/chenxingshuang/react-sortable-hoc/tree/master/examples"
    click TD "https://github.com/chenxingshuang/react-sortable-hoc/blob/master/types/index.d.ts"
```
