# pradeep241094/react-wysiwyg-editor architecture

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

- Interactive diagram: https://gitdiagram.com/pradeep241094/react-wysiwyg-editor
- Repository: https://github.com/pradeep241094/react-wysiwyg-editor

## Overview

##### Project Type and Purpose
- This repository is an open-source React + TypeScript library (NPM package) providing a WYSIWYG editor component with dual-mode editing (HTML/Markdown), advanced media handling, toolbar configuration, sanitization, and accessory modals.
- It also contains supporting demo applications (demo-app, test-installation) and build/deployment scripts for CI/CD, packaging, and publishing.

##### File Structure Analysis
- Top-level
- src/             → Core library source: components, utils, types, styles
- dist/            → Compiled outputs (CJS + ES + .css + TypeScript definitions)
- demo-app/        → Standalone Vite-based demo application showcasing the editor
- test-installation/→ Minimal app to verify npm installation
- scripts/         → Build, publish, test-installation helper scripts
- README.md, configs → Documentation and build/deployment configuration
- Patterns
- Component hierarchy under src/components (WYSIWYGEditor, Toolbar, modals, EditableArea) follows a UI-centric modular design.
- Utility functions under src/utils handle command execution, selection management, content sanitization, toolbar configuration resolution.
- Build outputs under dist mirror the src structure (components/, utils/, types/) indicating a straightforward compile pipeline.
- Demo apps import the built library or source directly via TypeScript path or NPM package.

##### Core Components and Interactions
- WYSIWYGEditor (root UI component)
↳ uses EditableArea for contentEditable region
↳ uses Toolbar or AdvancedToolbar (preset or custom via ToolbarConfigResolver)
↳ orchestrates modals: FileUploadModal, ImageCropModal, LinkPreviewPopup, FindReplaceModal, NotificationModal, SpecialCharModal, TableInsertModal, UrlInputModal
- CommandExecutor (singleton)
↔ invoked by toolbar buttons, modals, or programmatically to execute document.execCommand or custom commands
- contentSanitizer
↔ invoked on paste or before output to clean unsafe HTML
- selectionUtils
↔ capture/restore selections when opening/closing modals
- ToolbarConfigResolver
↔ merges preset/include/exclude/order rules into final enabledButtons list for Toolbar
- External integration
↔ Demo-app/test-installation import WYSIWYGEditor + styles from the built package
↔ Consumers import from @prmargas/react-wysiwyg-editor via NPM

##### Architectural Patterns and Principles
- Modular UI components (each modal or toolbar section is its own component)
- Singleton command system for centralized command execution
- Functional separation: UI (components) vs. logic (utils) vs. configuration (types + resolver)
- Publishable library with dual‐module output (CJS + ES) and full TypeScript declarations
- Demo and test harnesses to validate integration and cross-browser compatibility

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Library Package"
        direction TB
        subgraph "UI Layer"
            direction TB
            WYSIWYGEditor["WYSIWYGEditor"]:::ui
            EditableArea["EditableArea"]:::ui
            Toolbar["Toolbar"]:::ui
            AdvancedToolbar["AdvancedToolbar"]:::ui
            FileUploadModal["FileUploadModal"]:::ui
            ImageCropModal["ImageCropModal"]:::ui
            LinkPreviewPopup["LinkPreviewPopup"]:::ui
            FindReplaceModal["FindReplaceModal"]:::ui
            NotificationModal["NotificationModal"]:::ui
            SpecialCharModal["SpecialCharModal"]:::ui
            TableInsertModal["TableInsertModal"]:::ui
            UrlInputModal["UrlInputModal"]:::ui
        end
        subgraph "Logic Layer"
            direction TB
            CommandExecutor["CommandExecutor"]:::logic
            contentSanitizer["contentSanitizer"]:::logic
            selectionUtils["selectionUtils"]:::logic
            ToolbarConfigResolver["ToolbarConfigResolver"]:::logic
        end
        subgraph "Types & Styles"
            direction TB
            Types["Type Declarations"]:::types
            Styles["editor.css"]:::styles
        end
    end

    subgraph "Build & Publish Pipeline"
        direction TB
        Scripts["scripts/*"]:::ci
        CI["publish.yml"]:::ci
        Dist["dist/"]:::output
    end

    subgraph "Consumer Applications"
        direction TB
        DemoApp["demo-app"]:::consumer
        TestApp["test-installation"]:::consumer
    end

    subgraph "External Systems"
        direction TB
        NPM["NPM Registry"]:::external
        Browser["Browser (DOM)"]:::external
    end

    %% UI interactions
    WYSIWYGEditor -->|uses| EditableArea
    WYSIWYGEditor -->|uses| Toolbar
    WYSIWYGEditor -->|opens| FileUploadModal
    WYSIWYGEditor -->|opens| ImageCropModal
    WYSIWYGEditor -->|opens| LinkPreviewPopup
    WYSIWYGEditor -->|opens| FindReplaceModal
    WYSIWYGEditor -->|opens| NotificationModal
    WYSIWYGEditor -->|opens| SpecialCharModal
    WYSIWYGEditor -->|opens| TableInsertModal
    WYSIWYGEditor -->|opens| UrlInputModal

    %% Logic flows
    Toolbar -->|triggers| CommandExecutor
    FileUploadModal -->|captures| selectionUtils
    ImageCropModal -->|captures| selectionUtils
    contentSanitizer -->|sanitizes| EditableArea
    selectionUtils -->|restores| EditableArea
    ToolbarConfigResolver -->|resolves| Toolbar
    CommandExecutor -->|executes| Browser

    %% Consumer integration
    DemoApp -->|imports| WYSIWYGEditor
    DemoApp -->|imports| Styles
    TestApp -->|imports| WYSIWYGEditor

    %% Build & publish
    Scripts -->|produces| Dist
    CI -->|publishes| Dist
    Dist -->|consumed by| DemoApp
    Dist -->|consumed by| TestApp
    Dist -->|publishes to| NPM

    %% Class Definitions
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef types fill:#DDA0DD,stroke:#333,stroke-width:1px;
    classDef styles fill:#FFB6C1,stroke:#333,stroke-width:1px;
    classDef ci fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef output fill:#FFFACD,stroke:#333,stroke-width:1px;
    classDef consumer fill:#E6E6FA,stroke:#333,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;

    %% Click Events
    click WYSIWYGEditor "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/WYSIWYGEditor.tsx"
    click EditableArea "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/EditableArea.tsx"
    click Toolbar "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/Toolbar.tsx"
    click AdvancedToolbar "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/AdvancedToolbar.tsx"
    click FileUploadModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/FileUploadModal.tsx"
    click ImageCropModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/ImageCropModal.tsx"
    click LinkPreviewPopup "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/LinkPreviewPopup.tsx"
    click FindReplaceModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/FindReplaceModal.tsx"
    click NotificationModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/NotificationModal.tsx"
    click SpecialCharModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/SpecialCharModal.tsx"
    click TableInsertModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/TableInsertModal.tsx"
    click UrlInputModal "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/components/UrlInputModal.tsx"
    click CommandExecutor "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/utils/commandSystem.ts"
    click contentSanitizer "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/utils/contentSanitizer.ts"
    click selectionUtils "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/utils/selectionUtils.ts"
    click ToolbarConfigResolver "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/utils/toolbarConfigResolver.ts"
    click DemoApp "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/demo-app/src/App.tsx"
    click TestApp "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/test-installation/App.tsx"
    click Scripts "https://github.com/pradeep241094/react-wysiwyg-editor/tree/main/scripts/"
    click CI "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/ .github/workflows/publish.yml"
    click Dist "https://github.com/pradeep241094/react-wysiwyg-editor/tree/main/dist/"
    click Types "https://github.com/pradeep241094/react-wysiwyg-editor/tree/main/dist/types/components/"
    click Types "https://github.com/pradeep241094/react-wysiwyg-editor/tree/main/dist/types/utils/"
    click Styles "https://github.com/pradeep241094/react-wysiwyg-editor/blob/main/src/styles/editor.css"
```
