# tinymce/tinymce-vue architecture

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

- Interactive diagram: https://gitdiagram.com/tinymce/tinymce-vue
- Repository: https://github.com/tinymce/tinymce-vue

## Overview

##### Project Type and Purpose
- The project is an official Vue wrapper for TinyMCE, which is a rich text editor. Its primary purpose is to simplify the use and integration of TinyMCE in Vue applications, particularly Vue 3.
- The README clarifies that this version (v4.0) caters to Vue 3 while earlier versions support Vue 2.x. It provides links to detailed documentation, quick start guides, technical references, and demos (via Storybook).

##### File Structure
- Notice multiple directories that indicate a modular design:
- The “src/main/ts” directory holds the core implementation. You find key files like:
- ScriptLoader.ts: Likely responsible for asynchronously loading TinyMCE scripts.
- TinyMCE.ts: Handles integration details with the TinyMCE library.
- Components like Editor.ts and EditorPropTypes.ts, which encapsulate the Vue component logic.
- The “src/demo” folder contains demo Vue components (Demo.vue and various view components) for showcasing the wrapper’s capabilities.
- The “src/test” folder contains different testing setups, ensuring various parts of the application (atomic, browser, alien) are validated.
- Additionally, Storybook files and configuration files (e.g., package.json, rollup build, tsconfig files, and Vite config) support development, testing, and build processes.
- The presence of detailed configuration and CI/CD files (GitHub workflows, Jenkinsfile) indicates emphasis on code quality, maintainability, and continuous integration.

##### README for Additional Insights
- The README outlines the integration details, external links to TinyMCE’s documentation, and instructions regarding version compatibility with Vue 3.

a. Main Components:
- Vue Wrapper Core:
- Core integration layers in “src/main/ts” including the Editor component and related helper modules (TinyMCE and ScriptLoader).
- Demo Application:
- Vue-based demo and views in “src/demo” that illustrate how the editor and its configuration are used.
- Testing & Storybook:
- “src/test” (unit tests, browser integration tests, and alien tests) ensuring system reliability.
- “.storybook” and “stories” folders that help build and display interactive UI examples.
- Build & CI/CD:
- Build scripts (rollup.build.js, vite.config.js) and configuration files (tsconfig.json, etc.) which manage compilation and bundling.
- External Integration:
- Direct reference to TinyMCE (via external TinyMCE docs and possibly loading the remote script using ScriptLoader).

b. Relationships and Interactions:
- The Vue application (demos, story examples) interacts with the core Vue wrapper component – which in turn initializes TinyMCE through the ScriptLoader and TinyMCE modules.
- Initialization (see Level 3 details below) occurs when the editor component is mounted, triggering the sequence of script loading, configuration, and editor instantiation.
- Testing components validate these interactions across different scenarios (atomic, browser, alien tests).
- Continuous integration and storybook are used during development to ensure robustness.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: Clear separation between demonstration code, core integration logic, and test suites.
- Modular Design: Components for script loading, integration with TinyMCE, and Vue wrapping are isolated in their own modules.
- Initialization Model (Level 3 Details): Multi-level initialization approach:
Level 1: The Vue component (Editor.vue / Editor component in Editor.ts) initializes when mounted.
Level 2: The Editor then calls an initialization routine—involving TinyMCE.ts—to set up configuration parameters and integration hooks.
Level 3 (detailed initialization): Within TinyMCE.ts, you observe:
- ScriptLoader.ts being invoked to asynchronously load the TinyMCE script.
- Post-loading, the actual 初始化 of TinyMCE is performed (options are set, events bound, and the editor instance is created).
- Utility functions in Utils.ts may also be used to support dynamic configuration or error handling.
- These levels should be illustrated as cascading initialization steps with dependencies/flow from the Vue component to the underlying integration and utility modules.

d. Technologies, Frameworks, and Libraries:
- Vue (for the wrapper component).
- TinyMCE (the external rich text editor library).
- Storybook (for UI demonstrations).
- Testing frameworks indicated by the ts test files (which likely use Jest, Mocha, or similar).
- Build tools: Vite, Rollup, and TypeScript (as indicated by tsconfig files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Vue Editor Component"]:::core
    B["TinyMCE Initialization Module"]:::core
    subgraph "Level 3: Detailed Initialization"
        direction TB
        C["ScriptLoader"]:::core
        D["Configuration & Instantiation"]:::core
        E["Utility Functions"]:::core
    end
    I["External TinyMCE Library"]:::external

    subgraph "Demo/Storybook UI"
        direction TB
        F1["Demo UI"]:::ui
        F2["Storybook UI"]:::ui
    end

    G["Testing Suites"]:::testing
    H["CI/CD & Build Pipeline"]:::build

    %% Core initialization flow
    A -->|"initiate"| B
    B --> C
    C -->|"loadScript"| D
    E -->|"support"| D
    D -->|"configures"| I

    %% UI and Testing relationships
    F1 -->|"uses"| A
    F2 -->|"uses"| A
    G -->|"tests"| A
    H -->|"builds"| F1
    H -->|"builds"| F2
    H -->|"runsTests"| G

    %% Click Events
    click A "https://github.com/tinymce/tinymce-vue/blob/main/src/main/ts/components/Editor.ts"
    click B "https://github.com/tinymce/tinymce-vue/blob/main/src/main/ts/TinyMCE.ts"
    click C "https://github.com/tinymce/tinymce-vue/blob/main/src/main/ts/ScriptLoader.ts"
    click E "https://github.com/tinymce/tinymce-vue/blob/main/src/main/ts/Utils.ts"
    click F1 "https://github.com/tinymce/tinymce-vue/tree/main/src/demo"
    click F2 "https://github.com/tinymce/tinymce-vue/blob/main/.storybook"
    click G "https://github.com/tinymce/tinymce-vue/tree/main/src/test"
    click H "https://github.com/tinymce/tinymce-vue/tree/main/Jenkinsfile"
    click H "https://github.com/tinymce/tinymce-vue/blob/main/rollup.build.js"
    click H "https://github.com/tinymce/tinymce-vue/blob/main/vite.config.js"

    %% Styles
    classDef core fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef ui fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef testing fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb6c1,stroke:#333,stroke-width:2px;
```
