const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); const Markdown = require('naturalcrit/markdown.js'); const ErrorBar = require('./errorBar/errorBar.jsx'); //TODO: move to the brew renderer const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx'); const PAGE_HEIGHT = 1056; const PPR_THRESHOLD = 50; const BrewRenderer = createClass({ getDefaultProps : function() { return { text : '', errors : [] }; }, getInitialState : function() { const pages = this.props.text.split('\\page'); return { viewablePageNumber : 0, height : 0, isMounted : false, usePPR : true, pages : pages, usePPR : pages.length >= PPR_THRESHOLD, errors : [] }; }, height : 0, pageHeight : PAGE_HEIGHT, lastRender :
, componentDidMount : function() { this.updateSize(); window.addEventListener('resize', this.updateSize); }, componentWillUnmount : function() { window.removeEventListener('resize', this.updateSize); }, componentWillReceiveProps : function(nextProps) { if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight; const pages = nextProps.text.split('\\page'); this.setState({ pages : pages, usePPR : pages.length >= PPR_THRESHOLD }); }, updateSize : function() { setTimeout(()=>{ if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight; }, 1); this.setState({ height : this.refs.main.parentNode.clientHeight, isMounted : true }); }, handleScroll : function(e){ this.setState({ viewablePageNumber : Math.floor(e.target.scrollTop / this.pageHeight) }); }, shouldRender : function(pageText, index){ if(!this.state.isMounted) return false; const viewIndex = this.state.viewablePageNumber; if(index == viewIndex - 3) return true; if(index == viewIndex - 2) return true; if(index == viewIndex - 1) return true; if(index == viewIndex) return true; if(index == viewIndex + 1) return true; if(index == viewIndex + 2) return true; if(index == viewIndex + 3) return true; //Check for style tages if(pageText.indexOf('