How tencent/tmagic-editor works
This project is a monorepo for a visual page builder known as “TMagic”. Its primary purpose is to allow developers to quickly set up a visual (low-code) editor for building mobile H5 pages. The core functionality is encapsulated in the editor packages (especially packages/editor) with additional support provided by runtime projects (offering Vue2, Vue3, and React renderers), UI components, forms, and other helper libraries. In essence, TMagic is a visual construction platform that uses a DSL to describe pages and offers both an editor and runtime renderers.
Main Components Identification
a. Editor Module:
• Located under packages/editor.
• Provides the core visual editor (with components, services, hooks, layouts, and utility code).
• Interacts with other packages (e.g., core, design, data-source, stage, table) to facilitate editing, undo/redo, event handling, and UI updates.
b. UI and Design System:
• Found in packages/ui, packages/design and the vue/react-components subdirectories.
c. Form and Data Management:
• packages/form supplies form rendering and configuration.
• packages/data-source handles data integration and observed data patterns.
d. Runtime/Rendering Environment:
• The runtime directory contains the actual page rendering projects (Vue2, Vue3, React variations) that use the DSL produced by the editor to display pages.
• playground demonstrates an integrated example, showing how the editor outputs DSL and how the runtime consumes it to render pages.
e. Supporting Libraries:
• Additional packages like packages/core, packages/schema, packages/dep, packages/stage, and packages/table provide low-level support for event management, dependency resolution, node operations, stage layout, drag-resize behaviors, and table components.
f. CLI and Build Tools:
• packages/cli supplies developer tools to bootstrap or manage the project.
• Scripts, configuration files (pnpm-workspace.yaml, tsconfig, eslint configurations) and GitHub workflows help maintain code quality and continuous integration.
Architectural Relationships and Interactions
• The Editor (packages/editor) is the hub and produces a DSL (domain-specific language) representing the page configuration.
• UI component libraries (from packages/ui/design and the framework-specific component folders for Vue and React) are referenced by both the Editor and the Runtime projects.
• DataSource and Form packages integrate into the Editor to enable dynamic configuration of components and forms.
• The Runtime projects in the runtime directory load the DSL generated by the Editor to render the final pages. They might, for example, load runtime configurations for Vue (Vue2/Vue3) or React.
• The CLI is used for bootstrapping, building, and possibly releasing individual packages.
• Testing and documentation (present in docs and tests folders) support the overall health and knowledge sharing.
Architectural Patterns and Design Principles
• Modular Monorepo: The project is divided into many npm packages, each handling separate responsibilities (editor, UI, form, runtime).
• Component-based Architecture: Both the editor and the UI are built using Vue components (and their React counterparts), emphasizing reusability and isolation.
• DSL-driven Workflow: The editor generates a DSL which is then consumed by runtime renderers to produce the final UI.
• Separation of Concerns: There’s a clear split between the authoring tools (Editor/CLI) and the presentation layer (Runtime).
• Ecosystem Integration: With support for Vue 3 Composition API and TypeScript across packages, the project uses modern JavaScript/TypeScript patterns.
Relevant Technologies and Frameworks
• Vue 3.0 (via Composition API) is a key technology for the editor.
• TypeScript is used across packages for strong typing.
• Supporting frameworks include elements from Element-UI (notably in the form packages), along with adapters for Element Plus and TDesign in Vue and React.
• Build and tooling setups with pnpm, Vite, Rollup, ESLint, and Husky for commits and pre-push hook configurations.