布局总览

未命名文件 (1).png
gaea-editor 将页面分成

  1. navbarLeft
  2. navbarRight
  3. leftbarTop
  4. leftBarBottom
  5. toolContainerLeft
  6. tooContainerRight
  7. viewport
  8. bottomBar
  9. mainTool

总共9个
在编写插件的时候 最主要的是告诉gaea-editor你的插件是要放在什么位置,因此在导出的时候,有position,与class两个主要信息

  1. export default {
  2. position: 'leftBarTop',
  3. class: DragMenuButton1,
  4. };

其中5:toolContainerLeft,6:tooContainerRight,是公用位置,定义插件名需要添加上你插件的名字,
如:export default {
position: ‘toolContainerLeftSettingPages’,
class: SettingPages
};

需要显示都提供了专门的接口
1、toolContainerLeft, this.props.actions.ApplicationAction.setLeftTool(‘SettingPages’);
2、toolContainerRight, this.props.actions.ApplicationAction.setRightTool(‘SettingPageItem’)

自定义数据

在编辑插件的时候,难免需要自行保存一些数据,这时候 gaea-editor 给了我们一个将数据放入顶层props的方法
在导出插件的时候,添加两个属性actions,与stores,gaea-editor 会将这两注册成全局仓库与动作,

  1. // index.jsx
  2. import { Connect } from 'dob-react';
  3. import * as React from 'react';
  4. import * as ReactDOM from 'react-dom';
  5. import { Icon } from 'antd'
  6. import * as Styled from './index.style';
  7. import { Props, State } from './index.type';
  8. import { PagesStore } from './store'
  9. import { PagesAction } from './action'
  10. @Connect // 需要装饰调用,才能拿到全局的props
  11. class SettingPages extends React.Component {
  12. addPage = () => {
  13. this.props.actions.PagesAction.addPage()
  14. }
  15. render() {
  16. return <div>
  17. <div>
  18. <div onClick={this.addPage}>
  19. <Icon type="file-add" />
  20. </div>
  21. </div>
  22. <div>
  23. {this.props.stores.PagesStore.list.map((item, idx) => {
  24. return <div onClick={this.switchRightTool} key={idx}>
  25. {item.name}oo
  26. </div>
  27. })}
  28. </div>
  29. </div>
  30. }
  31. }
  32. export default {
  33. position: 'toolContainerLeftSettingPages',
  34. class: SettingPages,
  35. actions: {
  36. PagesAction
  37. },
  38. stores: {
  39. PagesStore
  40. },
  41. };

源码操作 源码地址
111.png

官方建议我们使用 dob,来进行数据注册,需要更新渲染的时候 需要使用dob-react,进行连接组件,才能时页面根据action 的操作进行跟新渲染,
action的用法

  1. // action.js
  2. import { Action, inject } from 'dob';
  3. import { PagesStore } from './store'
  4. export class PagesAction {
  5. @inject(PagesStore) pagesStore
  6. @Action
  7. addPage() {
  8. this.pagesStore.list.push({name: '新添加的页面'})
  9. }
  10. }

注意store的注册,必须引入 observable,并进行装饰调用,数据跟新后才能触发渲染

  1. // store.js
  2. import { observable } from "dob";
  3. @observable
  4. export class PagesStore {
  5. list = [
  6. {
  7. name: '首页',
  8. path: '/',
  9. default: true,
  10. isUse: true,
  11. pageData: null
  12. }
  13. ]
  14. }

;