How aisuda/amis-editor-demo works
This project is a React-based single‐page demo for the AMIS visual editor. In essence, the system provides a rich, extensible interface where end users can visually edit AMIS JSON schemas and see a live preview of the resulting UI. In addition, the repository maintains multiple built demo versions (with versioned “demo-…” directories) so that historical or beta versions can be previewed online.
Overall Architecture and Main Components
• Frontend Application (SPA): At its core, the project runs as a React-based single-page application. The entry point is defined in the “src/index.tsx” along with “src/index.html” – these bootstraps the editor and routing system.
• Editor & Renderer Modules:
– The “src/editor” folder contains code for editor plugins (for example “DisabledEditorPlugin.tsx” and “MyRenderer.tsx”) that extend the AMIS editor.
– The “src/component” folder holds key UI components such as “AMISRenderer.tsx” (which likely renders the AMIS JSON configuration), and “AddPageModal.tsx” for managing the UI channels.
– The “src/renderer” directory shows additional custom renderers, which are integrated with the editor.
• Routing and Pages:
– The “src/route” folder defines different routes like “Editor.tsx”, “Preview.tsx”, and “NotFound.tsx”. This allows a clear separation between the editor view, preview mode, and error handling.
• Global State Management:
– The “src/store” folder houses state management files (e.g., “Page.ts”, “index.ts”). This part likely uses Redux or React’s Context to keep the AMIS JSON schema and editor state in sync.
• Styling and Assets:
– “src/scss” contains the main stylesheet.
• TypeScript Configuration:
– “tsconfig.json” and “package.json” denote a strongly typed codebase with defined dependencies.
Demos and Historical Versions
• A large set of “demo-…” directories (e.g. demo-6.11.0, demo-6.7.0, etc.) represent prebuilt artifacts of various released versions. Each demo directory is a self-contained, static version with its own index.html, JavaScript workers (e.g. for CSS, HTML, JSON, TypeScript), fonts, css, and images.
• These directories reflect how the project bundles and deploys different revisions – serving as both a historical record and as distinct deployment targets.
Architectural Patterns and Design Principles
• Modular and Extensible Plugin System: The editor is built to allow custom renderers and extension via plugins (as detailed in the readme under “扩充自定义编辑器”). The system design should highlight how plugins are registered (via registerEditorPlugin or by injecting them as properties) and how they hook into the editing lifecycle.
• Separation of Concerns: The application clearly separates presentation (components and renderers), routing (managed in the “route” directory), state management (in the “store”), and configuration (pages.json and scaffold definitions within plugins).
• Versioning and Build Artifacts: The use of multiple “demo-…” folders demonstrates a design choice where the build process generates fully self-contained outputs for each version. This should be depicted as a parallel “build” or “deployment” pipeline that archives historical builds.
• Client-Side Rendering and Worker Scripts: Many demo directories include worker scripts (like css.worker.js, html.worker.js, ts.worker.js), suggesting that the application offloads some code processing (e.g. syntax highlighting or language services) to web workers. It is important to capture the browsers’ multi-threading model in the design.
Interactions and Data Flow
• When a user interacts with the editor (for example, changing an AMIS JSON configuration), the change flows from the editor’s UI components in “src/editor” and “src/component” to the state management layer (“src/store”). The updated state is then re-rendered via the “AMISRenderer” component.
• The routing layer handles navigation between the editor, preview mode, and error pages.
• Plugin events (active, beforeInsert, afterInsert, beforeUpdate, etc.) are dispatched during component configuration; these events are integrated using the plugin system’s event listeners and affect the behavior of the editor.