• Stars
    star
    1,341
  • Rank 33,816 (Top 0.7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Design websites in your browser. A smart web editor!

Gaea Editor · CircleCI Status npm version code coverage Total alerts Language grade: JavaScript

gaea-editor

Help develops build a scalable website visualization builder.

Try it online.

Requirement

  • Node > 8.0
  • Typescript 3.0

Quick start

npm i gaea-editor --save

And then, it's easy to use:

import Editor from 'gaea-editor';

ReactDOM.render(
  <div style={{ width: '100vw', height: '100vh' }}>
    <Editor />
  </div>,
  document.getElementById('react-root')
);

Add custom component to the drag menu

You can add any react components to the drag menu, through the following line of code:

import BasicComponents from 'gaea-basic-components';
<Editor componentClasses={[...BasicComponents, CustomComponent1, CustomComponent2]} />;

BasicComponents support container, button, icon, select, switch. And there must be at least one component to set isContainer=true that can be used as outer container.

Generally speaking, with BasicComponents concat is ok, because the component container BasicComponents offered is a container.

Add editSetting to each component props, to let the editor know how to edit it visualizations:

defaultProps = {
  editSetting: {
    key: 'my-custom-key', // Unique key.
    name: 'Custom one', // The name shown in drag menu.
    isContainer: false, // Can be dragged in.
    editors: [
      {
        field: 'title',
        text: 'Text',
        type: 'string'
      }
    ] // Tell gaea-editor, which props can be edited and how to edit it.
  }
};

More about editors

gaea-editor provides several built-in type editing props. If you need to expand it, you can refer to custom plugin.

common field:

  • field: which props to edit. EX: value visible style.backgroundColor.
  • text: If exist, will appear in the form label to prompt the user.

The following are the built-in types:

string

Suitable for any string editing scene.

{
    type: 'string',
    text: 'Text',
    field: 'value'
}

number

Suitable for any number editing scene.

In many cases, it is suggested that inputRange and outputRange be set to the same value.

{
    type: 'number',
    text: 'Text',
    field: 'value',
    data: {
        useSlider: true,
        step: 1,
        inputRange: [0, 100],
        outputRange: [0, 1]
    }
}

boolean

Suitable for any boolean editing scene.

{
    type: 'boolean',
    text: 'Checked',
    field: 'value'
}

select

Suitable for enumable editing scene.

{
    type: 'select',
    text: 'Text',
    field: 'value',
    data: [{
        text: 'Default',
        value: 0
    }, {
        text: 'Small',
        value: 1
    }, {
        text: 'Large',
        value: 2
    }]
}

color

Suitable for color picker editing scene.

{
    type: 'color',
    text: 'Text',
    field: 'style.backgroundColor',
}

display

Suitable for layout editing scene.

Because this type will edit multiple props properties, such as style.display style.flexDirection, so don't need to specify the field field.

{
    type: 'display',
    text: 'Text'
}

box-editor

Suitable for margin-padding editing scene.

Because this type will edit multiple props properties, such as margin padding, so don't need to specify the field field.

{
    type: 'box-editor',
    text: 'Text'
}

array

Super type, allow visualizations to edit an array type props.

{
    type: 'array',
    text: 'values',
    data: 'string'
}

You can change string to boolean, than it can edit boolean array:

object array

Super type, allow visualizations to edit an array type props.

Each field in data describes how the key should be edited in the object in array.

Each field in data is a editor type. You can even nested array or object type inside.

{
    type: 'array',
    text: 'Options',
    data: [{
        field: "value",
        type: "string",
        text: "Value"
    }, {
        field: "text",
        type: "string",
        text: "Text"
    }, {
        field: "disabled",
        type: "boolean",
        text: "Disabled"
    }]
}

object

Super type, allow visualizations to edit a object type props.

Each field in data describes how the key should be edited in this object.

Each field in data is a editor type. You can even nested array or object type inside.

{
    type: 'object',
    text: 'Text',
    data: [{
        field: "name",
        type: "string",
        text: "Name"
    }, {
        field: "age",
        type: "number",
        text: "Age"
    }]
}

Options

You can add custom components, custom plugins, save callback, and read saved data.

Props Type Description
onSave (info?: string) => void When you click the Save button, feed back to you to save the information
defaultValue object Editor initial value, you can pass the value of the onSave callback and resume the draft
componentClasses Array<React.ComponentClass<IGaeaProps>> React classes. Any react component is supported, but you need some configuration information to tell the editor how to edit it. see custom-component-config
plugins IPlugin[] Advanced usage for custom editor functionality.
locale string zh or cn
ViewportRender React.ReactElement<any> You can rewrite viewport element.
disableBuiltInPlugin string[] Disable built in plugins.
preComponents Array<{ gaeaKey: string; components: IPreComponent[]; }> See docs/basic.tsx

Parameter: onSave

export function renderGaeaEditor() {
  return (
    <Editor
      onSave={value => {
        // send the value data to your server.
      }}
    />
  );
}

Parameter: defaultValue

The defaultValue came from onSave.

export function renderGaeaEditor() {
  return <Editor defaultValue={value} />;
}

Parameter: componentClasses

class MyInput extends React.Component {
  render() {
    return <input />;
  }
}

export function renderGaeaEditor() {
  return <Editor componentClasses={[MyInput]} />;
}

LiveDemo

Read more in custom-component-config.

Parameter: plugins

First you should install dob-react.

npm i dob-react
import { Connect } from 'dob-react'

@Connect
class Plugin extends React.Component {
  render() {
  	return 'plugin'
  }
}

const plugin {
  position: "mainToolEditorTypeShow",
  class: ShowEditor
}

export function renderGaeaEditor() {
    return (
        <Editor plugins={[ Plugin ]}/>
    )
}

CustomEditTypeLiveDemo

What is position? What can i do with plugin? See more in custom-plugin

Communication

Talk to us about gaea-editor using DingDing.

Local development run

git clone https://github.com/ascoders/gaea-editor.git
cd gaea-editor
npm i
npm run docs

Will automatically open the default browser.

Unfortunately, source debugging is not support windows. Here is way

Deploy

Step 1, get value by onSave method in gaea-editor:

import Editor from 'gaea-editor';

ReactDOM.render(<Editor onSave={value => saveToServer(value)} />, document.getElementById('react-root'));

step 2, install gaea-render, and pass value to it:

npm i gaea-render
import Render from 'gaea-render';

const value = getValueFromServer(); // <Editor onSave={value => // From here. } />

ReactDOM.render(<Render value={value} />, document.getElementById('react-root'));

Custom component

By default, both gaea-editor and gaea-render using gaea-basic-components. You can overwrite it by these code:

import Editor from 'gaea-editor';
import Render from 'gaea-render';

ReactDOM.render(<Editor componentClasses={myCustomComponents} />, document.getElementById('react-editor'));
ReactDOM.render(<Render componentClasses={myCustomComponents} />, document.getElementById('react-render'));

Or concat gaea-basic-components:

import Editor from 'gaea-editor';
import Render from 'gaea-render';
import BasicComponents from 'gaea-basic-components';

ReactDOM.render(
  <Editor componentClasses={[...BasicComponents, myCustomComponents]} />,
  document.getElementById('react-editor')
);
ReactDOM.render(
  <Render componentClasses={[...BasicComponents, myCustomComponents]} />,
  document.getElementById('react-render')
);

More Repositories

1

weekly

前端精读周刊。帮你理解最前沿、实用的技术。
JavaScript
27,747
star
2

react-native-image-viewer

🚀 tiny & fast lib for react native image viewer pan and zoom
TypeScript
2,435
star
3

react-native-image-zoom

react native image pan and zoom
TypeScript
632
star
4

syntax-parser

Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added!
TypeScript
460
star
5

alipay

golang SDK for alipay
Go
458
star
6

blog

博客
263
star
7

avatar

avalon开源中文社区
JavaScript
41
star
8

isomorphic-react-redux-app

react react-hot-loader redux redux-devtools react-router-redux immutable isomorphic
JavaScript
16
star
9

inject-instance

powerful inject instance
TypeScript
12
star
10

dependency-inject

Powerful dependency injection tool
TypeScript
10
star
11

as

基于 martini 的 go语言框架
Go
10
star
12

gaea-render

Render engine for gaea-editor
TypeScript
8
star
13

egg-typeorm

egg plugin for typeorm
JavaScript
8
star
14

woku

我酷官网~
JavaScript
5
star
15

run-react

Integrate webpack
TypeScript
5
star
16

gaea-basic-components

gaea-basic-components
TypeScript
4
star
17

client-ssr

JavaScript
3
star
18

kingdoms

三国军争服务端源代码
Go
3
star
19

gaea-web-components

Gaea 网页端基础组件
TypeScript
3
star
20

vscode-medusa

medusa plugin for vscode
TypeScript
2
star
21

woku-react

我酷科技
JavaScript
2
star
22

rc-stream

react reactive stream
TypeScript
2
star
23

woku_old

我酷旧版
JavaScript
2
star
24

machine-learning

Demos of machine learning
TypeScript
2
star
25

typed-store

Typed React bindings for Redux
TypeScript
2
star
26

shallow-eq

shallow equal
TypeScript
1
star
27

bi-designer

TypeScript
1
star
28

ascoders-tslint-config

ascoders-tslint-config
1
star
29

monaco-editor-commonjs

commonjs monaco-editor
JavaScript
1
star