import React, { Component } from "react"; import { List, Map, is } from "immutable"; import { StoreProvider } from "plume2"; import { configOrderUtil } from "@qianmi/x-site-core"; import "./index.less"; import Editor from "./component/Editor"; import AppStore from "./store"; export { default as DataDialog } from "./component/dialog"; export type ConfigOrder = Map | List; export interface EditorProps { mode: string; // "dev" | "edit" | "view"; barInfos: any[]; configOrder: ConfigOrder; platform: string; // (尽量去除) editorType: string; //'pc'|'weixin' wrapper?: React.ReactNode; dialog?: React.ReactNode; outerStyle?: React.CSSProperties; header?: React.ReactNode; // (尽量去除) setting?: List; onChange?(configOrder: ConfigOrder): void; // 对外的回调函数 onChooseImage?(...args: any[]): Promise; // 图片弹框 // onChooseLink?(...args: any[]): Promise; // 链接弹框 loadBarList(key): Promise; // import or fetch getWidgetInfo(key): Promise; // import or fetch dataCenter: any; } /** * 建站编辑器 * 核心:ConfigOrder编辑 */ @StoreProvider(AppStore) export default class XSiteEditorApp extends Component { private store: AppStore; static defaultProps: Partial = { mode: "edit", setting: List(), }; constructor(props: EditorProps) { super(props); } componentDidMount() { //初始化添加组件框是否展示 FIXME: 特殊逻辑 this.store.onlyHeadOrFoot() && this.store.showSelectBox(); } async componentWillMount() { const { configOrder } = this.props; this.store.init(this.props); const widgetNameList = configOrderUtil.getWidgetNames(configOrder.toJS()); await this.props.loadBarList(widgetNameList); } shouldComponentUpdate(nextProps, nextState) { // FIXME: props/nextProps 不更新.why? const configOrder = this.store.state().get("configOrder"); // console.log("store", configOrder.get("children").size); // console.log("props", this.props.configOrder.get("children").size); // console.log("nextProps", nextProps.configOrder.get("children").size); return !is(nextProps.configOrder, configOrder); } componentWillUpdate(nextProps, nextState) { const { onChange } = this.props; const configOrder = this.store.state().get("configOrder"); typeof onChange === "function" && onChange(configOrder); } render() { return ; } }