import React, { Component, PropTypes } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import SplitPane from 'react-split-pane'; import Button from 'react-toolbox/lib/button'; import { ScrollSync, ScrollSyncPane } from '../ScrollSync'; import ControlPane from '../ControlPanel/ControlPane'; import PreviewPane from '../PreviewPane/PreviewPane'; import Toolbar from './EntryEditorToolbar'; import styles from './EntryEditor.css'; import stickyStyles from '../UI/Sticky/Sticky.css'; const PREVIEW_VISIBLE = 'cms.preview-visible'; class EntryEditor extends Component { state = { showEventBlocker: false, previewVisible: localStorage.getItem(PREVIEW_VISIBLE) !== "false", }; handleSplitPaneDragStart = () => { this.setState({ showEventBlocker: true }); }; handleSplitPaneDragFinished = () => { this.setState({ showEventBlocker: false }); }; handleOnPersist = () => { this.controlPaneRef.validate(); this.props.onPersist(); }; handleTogglePreview = () => { const newPreviewVisible = !this.state.previewVisible; this.setState({ previewVisible: newPreviewVisible }); localStorage.setItem(PREVIEW_VISIBLE, newPreviewVisible); }; setSticky = (contextTop, containerRect, sticky) => { if (contextTop >= containerRect.top) { if (contextTop < containerRect.bottom - 60) { sticky.classList.add(stickyStyles.top); sticky.classList.remove(stickyStyles.bottom); } else if (contextTop >= containerRect.bottom - 60) { sticky.classList.remove(stickyStyles.top); sticky.classList.add(stickyStyles.bottom); } } else { sticky.classList.remove(stickyStyles.top); sticky.classList.remove(stickyStyles.bottom); } }; handleControlPaneRef = (ref) => { const sticky = ref.querySelector('.cms__index__editorControlBar'); const stickyContainer = ref.querySelector('.stickyContainer'); stickyContainer.style.paddingTop = `${ sticky.offsetHeight }px`; sticky.style.position = 'absolute'; sticky.style.top = `${ -sticky.offsetHeight }px`; sticky.style.width = `${ stickyContainer.getBoundingClientRect().width }px`; ref && ref.addEventListener('scroll', (e) => { const contextTop = e.target.getBoundingClientRect().top; this.setSticky(contextTop, stickyContainer.getBoundingClientRect(), sticky); }); }; render() { const { collection, entry, fields, fieldsMetaData, fieldsErrors, getAsset, onChange, onValidate, onAddAsset, onRemoveAsset, onCancelEdit, } = this.props; const controlClassName = `${ styles.controlPane } ${ this.state.showEventBlocker && styles.blocker }`; const previewClassName = `${ styles.previewPane } ${ this.state.showEventBlocker && styles.blocker }`; const collectionPreviewEnabled = collection.getIn(['editor', 'preview'], true); const togglePreviewButton = ( ); const editor = (