2019-03-18 15:45:53 +00:00
|
|
|
import React, { Component } from "react"
|
2019-08-26 12:41:21 +00:00
|
|
|
import { connect } from "react-redux"
|
2019-08-20 13:19:19 +00:00
|
|
|
import styled from "styled-components"
|
2019-02-07 05:07:09 +00:00
|
|
|
import Canvas from "./Canvas"
|
2019-08-26 12:41:21 +00:00
|
|
|
import { IWidgetCardProps, IWidgetProps } from '../../widgets/BaseWidget'
|
|
|
|
|
import { AppState } from "../../reducers"
|
|
|
|
|
import { EditorReduxState } from "../../reducers/uiReducers/editorReducer"
|
2019-08-21 12:49:16 +00:00
|
|
|
import WidgetCardsPane from "./WidgetCardsPane"
|
2019-08-20 13:19:19 +00:00
|
|
|
import EditorHeader from "./EditorHeader"
|
2019-08-26 12:41:21 +00:00
|
|
|
import { WidgetType } from "../../constants/WidgetConstants"
|
|
|
|
|
import CanvasWidgetsNormalizer from "../../normalizers/CanvasWidgetsNormalizer"
|
|
|
|
|
import { fetchWidgetCards } from "../../actions/widgetCardsPaneActions"
|
2019-08-29 11:22:09 +00:00
|
|
|
import { ContainerWidgetProps } from "../../widgets/ContainerWidget"
|
2019-08-26 12:41:21 +00:00
|
|
|
import { fetchPage, addWidget } from "../../actions/pageActions"
|
|
|
|
|
import { RenderModes } from "../../constants/WidgetConstants"
|
2019-08-29 11:22:09 +00:00
|
|
|
// import EditorDragLayer from "./EditorDragLayer"
|
2019-08-20 13:19:19 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
const CanvasContainer = styled.section`
|
2019-08-20 13:19:19 +00:00
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
position: relative;
|
|
|
|
|
overflow-x: hidden;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
margin: 0px 10px;
|
2019-08-26 12:41:21 +00:00
|
|
|
&:before {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0; right: 0; bottom: 0; left: 0;
|
|
|
|
|
z-index: 1000;
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
2019-08-20 13:19:19 +00:00
|
|
|
`;
|
2019-02-07 05:07:09 +00:00
|
|
|
|
2019-08-26 12:41:21 +00:00
|
|
|
const EditorWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
width: 100vw;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
height: calc(100vh - 60px);
|
2019-08-29 11:22:09 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
type EditorProps = {
|
|
|
|
|
pageWidget: ContainerWidgetProps<any> | any;
|
|
|
|
|
fetchCanvasWidgets: Function;
|
|
|
|
|
fetchWidgetCardsPane: Function;
|
|
|
|
|
cards: { [id: string]: IWidgetCardProps[] } | any;
|
|
|
|
|
addPageWidget: Function;
|
|
|
|
|
}
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
class Editor extends Component<EditorProps> {
|
2019-08-26 12:41:21 +00:00
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.fetchWidgetCardsPane()
|
|
|
|
|
this.props.fetchCanvasWidgets("1")
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
addWidgetToCanvas = (widgetType: WidgetType, key: string): void => {
|
|
|
|
|
console.log(widgetType);
|
2019-08-26 12:41:21 +00:00
|
|
|
this.props.addPageWidget("1", {
|
2019-08-29 11:22:09 +00:00
|
|
|
key: key,
|
2019-08-26 12:41:21 +00:00
|
|
|
bottomRow: 9,
|
|
|
|
|
leftColumn: 1,
|
|
|
|
|
parentColumnSpace: 90,
|
|
|
|
|
parentRowSpace: 50,
|
|
|
|
|
renderMode: RenderModes.CANVAS,
|
|
|
|
|
rightColumn: 3,
|
|
|
|
|
snapColumns: 20,
|
|
|
|
|
snapRows: 20,
|
|
|
|
|
children: [],
|
|
|
|
|
topRow: 1,
|
2019-08-29 11:22:09 +00:00
|
|
|
widgetId: key,
|
2019-08-26 12:41:21 +00:00
|
|
|
widgetType: widgetType
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
// removeWidgetFromCanvas = (widgetId: string): null => {
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
// }
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
public render() {
|
2019-02-07 05:07:09 +00:00
|
|
|
return (
|
2019-08-26 12:41:21 +00:00
|
|
|
<React.Fragment>
|
2019-08-20 13:19:19 +00:00
|
|
|
<EditorHeader></EditorHeader>
|
2019-08-26 12:41:21 +00:00
|
|
|
<EditorWrapper>
|
|
|
|
|
<WidgetCardsPane cards={this.props.cards} />
|
2019-08-29 11:22:09 +00:00
|
|
|
<CanvasContainer>
|
|
|
|
|
<Canvas pageWidget={this.props.pageWidget} addWidget={this.addWidgetToCanvas} />
|
|
|
|
|
</CanvasContainer>
|
2019-08-26 12:41:21 +00:00
|
|
|
</EditorWrapper>
|
|
|
|
|
</React.Fragment>
|
2019-03-18 15:45:53 +00:00
|
|
|
)
|
2019-02-07 05:07:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
const mapStateToProps = (state: AppState, props: EditorProps): EditorReduxState => {
|
2019-08-26 12:41:21 +00:00
|
|
|
const pageWidget = CanvasWidgetsNormalizer.denormalize(
|
|
|
|
|
state.ui.canvas.pageWidgetId,
|
|
|
|
|
state.entities
|
|
|
|
|
)
|
|
|
|
|
return {
|
|
|
|
|
cards: state.ui.widgetCardsPane.cards,
|
|
|
|
|
pageWidget,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
|
|
|
|
return {
|
|
|
|
|
fetchCanvasWidgets: (pageId: string) => dispatch(fetchPage(pageId, RenderModes.CANVAS)),
|
|
|
|
|
fetchWidgetCardsPane: () => dispatch(fetchWidgetCards()),
|
2019-08-29 11:22:09 +00:00
|
|
|
addPageWidget: (pageId: string, widgetProps: IWidgetProps) => dispatch(addWidget(pageId, widgetProps))
|
2019-08-26 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(Editor)
|