Sunmao is a low-code framework. You can use Sunmao's Cloud version, or you can deploy a Sunmao application yourself.
Sunmao has two packages, runtime and editor. The runtime is the package used to run Sunmao applications, and the editor is used to run the Sunmao editor. The developer selects the corresponding package according to the needs of the scenario. If you are experiencing Sunmao for the first time, it is recommended to choose the editor.
No matter whether you choose runtime or editor, you need to install react, because Sunmao runs based on react.
yarn add @sunmao-ui/runtime
yarn add react
yarn add react-dom
yarn add @sunmao-ui/editor
yarn add react
yarn add react-dom
The runtime and editor are started in roughly the same way, but with different method names and parameters.
import { initSunmaoUI } from "@sunmao-ui/runtime";
import React from "react";
import ReactDOM from "react-dom";
const { App } = initSunmaoUIEditor({});
ReactDOM.render(<App />, document.getElementById("root"));
import { initSunmaoUIEditor } from "@sunmao-ui/editor";
import React from "react";
import ReactDOM from "react-dom";
const { Editor } = initSunmaoUIEditor({});
ReactDOM.render(<Editor />, document.getElementById("root"));
Sunmao Lib is a data structure composed of customized Sunmao Component, Trait, Module, and UtilMethod, and is an interface for developers to import custom component libraries.
const lib = {
components: [],
traits: [],
modules: [],
utilMethods: [],
};
When importing, just pass lib to initSunmaoUI
.
const { App } = initSunmaoUIEditor({ libs: [lib] });
For how to encapsulate custom Component, etc., you can refer to the Component development documentation.
Sunmao's initialization function accepts some parameters. These parameters are optional and are used to implement some custom logic.
Name | Type | Introduction |
---|---|---|
dependencies | Record<string, any> | Dependencies that can be used when the expression is evaluated, can be any JS variable. |
hooks | { didMount?: () => void; didUpdate?: () => void; didDomUpdate?: () => void; } |
Sunmao Application lifecycle hooks. |
libs | SunmaoLib[] | Used to load custom Component, Trait, Module, UtilMethod. |
Name | Type | Introduction |
---|---|---|
App | React Component | The React component that renders the Sunmao app. |
Registry | Registry | Register custom Component, Trait. |
Name | Type | Introduction |
---|---|---|
App | React Component | The React component that renders the Sunmao app. |
widgets | ImplementedWidget[] | Custom editor widget. |
storageHandler | { onSaveApp?: (app: Application) => void, onSaveModules?: (module: Module[]) => void } |
callback function for persistent storage of Application and Module. |
defaultApplication | Application | Default Application Schema. |
defaultModules | Module[] | Default Module. |
runtimeProps | Sunmao Runtime Props | Same as initSunmaoUI parameter |
Same as the return result of initSunmaoUI
.
Name | Type | Introduction |
---|---|---|
options | Application | Application Schema for Sunmao applications. |