mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 03:52:40 +00:00
Woh, it is working
This commit is contained in:
@@ -1,97 +1,110 @@
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var cx = require('classnames');
|
var cx = require('classnames');
|
||||||
|
|
||||||
var Markdown = require('marked');
|
var Markdown = require('marked');
|
||||||
|
var renderer = new Markdown.Renderer();
|
||||||
var PAGE_HEIGHT = 1056 + 30;
|
|
||||||
|
//Processes the markdown within an HTML block if it's just a class-wrapper
|
||||||
var BrewRenderer = React.createClass({
|
renderer.html = function (html) {
|
||||||
getDefaultProps: function() {
|
if(_.startsWith(html, '<div class=') && _.endsWith(_.trim(html), '</div>')){
|
||||||
return {
|
var openTag = html.substring(0, html.indexOf('>'));
|
||||||
text : ''
|
html = html.substring(html.indexOf('>')+1);
|
||||||
};
|
html = html.substring(0, html.lastIndexOf('</div>'));
|
||||||
},
|
return `${openTag} ${Markdown(html)} </div>`;
|
||||||
getInitialState: function() {
|
}
|
||||||
return {
|
return html;
|
||||||
viewablePageNumber: 0,
|
}
|
||||||
height : 0,
|
|
||||||
isMounted : false
|
|
||||||
};
|
var PAGE_HEIGHT = 1056 + 30;
|
||||||
},
|
|
||||||
totalPages : 0,
|
var BrewRenderer = React.createClass({
|
||||||
height : 0,
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
componentDidMount: function() {
|
text : ''
|
||||||
this.setState({
|
};
|
||||||
height : this.refs.main.parentNode.clientHeight,
|
},
|
||||||
isMounted : true
|
getInitialState: function() {
|
||||||
});
|
return {
|
||||||
},
|
viewablePageNumber: 0,
|
||||||
handleScroll : function(e){
|
height : 0,
|
||||||
this.setState({
|
isMounted : false
|
||||||
viewablePageNumber : Math.floor(e.target.scrollTop / PAGE_HEIGHT)
|
};
|
||||||
});
|
},
|
||||||
},
|
totalPages : 0,
|
||||||
//Implement later
|
height : 0,
|
||||||
scrollToPage : function(pageNumber){
|
|
||||||
},
|
componentDidMount: function() {
|
||||||
|
this.setState({
|
||||||
shouldRender : function(pageText, index){
|
height : this.refs.main.parentNode.clientHeight,
|
||||||
if(!this.state.isMounted) return false;
|
isMounted : true
|
||||||
|
});
|
||||||
var viewIndex = this.state.viewablePageNumber;
|
},
|
||||||
if(index == viewIndex - 1) return true;
|
handleScroll : function(e){
|
||||||
if(index == viewIndex) return true;
|
this.setState({
|
||||||
if(index == viewIndex + 1) return true;
|
viewablePageNumber : Math.floor(e.target.scrollTop / PAGE_HEIGHT)
|
||||||
|
});
|
||||||
//Check for style tages
|
},
|
||||||
if(pageText.indexOf('<style>') !== -1) return true;
|
//Implement later
|
||||||
|
scrollToPage : function(pageNumber){
|
||||||
return false;
|
},
|
||||||
},
|
|
||||||
|
shouldRender : function(pageText, index){
|
||||||
renderPageInfo : function(){
|
if(!this.state.isMounted) return false;
|
||||||
return <div className='pageInfo'>
|
|
||||||
{this.state.viewablePageNumber + 1} / {this.totalPages}
|
var viewIndex = this.state.viewablePageNumber;
|
||||||
</div>
|
if(index == viewIndex - 1) return true;
|
||||||
},
|
if(index == viewIndex) return true;
|
||||||
|
if(index == viewIndex + 1) return true;
|
||||||
renderDummyPage : function(key){
|
|
||||||
return <div className='phb' key={key}>
|
//Check for style tages
|
||||||
<i className='fa fa-spinner fa-spin' />
|
if(pageText.indexOf('<style>') !== -1) return true;
|
||||||
</div>
|
|
||||||
},
|
return false;
|
||||||
|
},
|
||||||
renderPage : function(pageText, index){
|
|
||||||
return <div className='phb' dangerouslySetInnerHTML={{__html:Markdown(pageText)}} key={index} />
|
renderPageInfo : function(){
|
||||||
},
|
return <div className='pageInfo'>
|
||||||
|
{this.state.viewablePageNumber + 1} / {this.totalPages}
|
||||||
renderPages : function(){
|
</div>
|
||||||
var pages = this.props.text.split('\\page');
|
},
|
||||||
this.totalPages = pages.length;
|
|
||||||
|
renderDummyPage : function(key){
|
||||||
return _.map(pages, (page, index)=>{
|
return <div className='phb' key={key}>
|
||||||
if(this.shouldRender(page, index)){
|
<i className='fa fa-spinner fa-spin' />
|
||||||
return this.renderPage(page, index);
|
</div>
|
||||||
}else{
|
},
|
||||||
return this.renderDummyPage(index);
|
|
||||||
}
|
renderPage : function(pageText, index){
|
||||||
});
|
return <div className='phb' dangerouslySetInnerHTML={{__html:Markdown(pageText, {renderer : renderer})}} key={index} />
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function(){
|
renderPages : function(){
|
||||||
return <div className='brewRenderer'
|
var pages = this.props.text.split('\\page');
|
||||||
onScroll={this.handleScroll}
|
this.totalPages = pages.length;
|
||||||
ref='main'
|
|
||||||
style={{height : this.state.height}}>
|
return _.map(pages, (page, index)=>{
|
||||||
|
if(this.shouldRender(page, index)){
|
||||||
<div className='pages'>
|
return this.renderPage(page, index);
|
||||||
{this.renderPages()}
|
}else{
|
||||||
</div>
|
return this.renderDummyPage(index);
|
||||||
{this.renderPageInfo()}
|
}
|
||||||
</div>
|
});
|
||||||
}
|
},
|
||||||
});
|
|
||||||
|
render : function(){
|
||||||
module.exports = BrewRenderer;
|
return <div className='brewRenderer'
|
||||||
|
onScroll={this.handleScroll}
|
||||||
|
ref='main'
|
||||||
|
style={{height : this.state.height}}>
|
||||||
|
|
||||||
|
<div className='pages'>
|
||||||
|
{this.renderPages()}
|
||||||
|
</div>
|
||||||
|
{this.renderPageInfo()}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = BrewRenderer;
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
||||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
||||||
|
|
||||||
(function(mod) {
|
|
||||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
||||||
mod(require("../../lib/codemirror"));
|
|
||||||
else if (typeof define == "function" && define.amd) // AMD
|
|
||||||
define(["../../lib/codemirror"], mod);
|
|
||||||
else // Plain browser env
|
|
||||||
mod(CodeMirror);
|
|
||||||
})(function(CodeMirror) {
|
|
||||||
var modes = ["clike", "css", "javascript"];
|
|
||||||
|
|
||||||
for (var i = 0; i < modes.length; ++i)
|
|
||||||
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
|
|
||||||
|
|
||||||
function continueComment(cm) {
|
|
||||||
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
|
||||||
var ranges = cm.listSelections(), mode, inserts = [];
|
|
||||||
for (var i = 0; i < ranges.length; i++) {
|
|
||||||
var pos = ranges[i].head, token = cm.getTokenAt(pos);
|
|
||||||
if (token.type != "comment") return CodeMirror.Pass;
|
|
||||||
var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode;
|
|
||||||
if (!mode) mode = modeHere;
|
|
||||||
else if (mode != modeHere) return CodeMirror.Pass;
|
|
||||||
|
|
||||||
var insert = null;
|
|
||||||
if (mode.blockCommentStart && mode.blockCommentContinue) {
|
|
||||||
var end = token.string.indexOf(mode.blockCommentEnd);
|
|
||||||
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
|
|
||||||
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) {
|
|
||||||
// Comment ended, don't continue it
|
|
||||||
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
|
|
||||||
insert = full.slice(0, token.start);
|
|
||||||
if (!/^\s*$/.test(insert)) {
|
|
||||||
insert = "";
|
|
||||||
for (var j = 0; j < token.start; ++j) insert += " ";
|
|
||||||
}
|
|
||||||
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
|
|
||||||
found + mode.blockCommentContinue.length > token.start &&
|
|
||||||
/^\s*$/.test(full.slice(0, found))) {
|
|
||||||
insert = full.slice(0, found);
|
|
||||||
}
|
|
||||||
if (insert != null) insert += mode.blockCommentContinue;
|
|
||||||
}
|
|
||||||
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
|
|
||||||
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
|
|
||||||
if (found > -1) {
|
|
||||||
insert = line.slice(0, found);
|
|
||||||
if (/\S/.test(insert)) insert = null;
|
|
||||||
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (insert == null) return CodeMirror.Pass;
|
|
||||||
inserts[i] = "\n" + insert;
|
|
||||||
}
|
|
||||||
|
|
||||||
cm.operation(function() {
|
|
||||||
for (var i = ranges.length - 1; i >= 0; i--)
|
|
||||||
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function continueLineCommentEnabled(cm) {
|
|
||||||
var opt = cm.getOption("continueComments");
|
|
||||||
if (opt && typeof opt == "object")
|
|
||||||
return opt.continueLineComment !== false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
|
|
||||||
if (prev && prev != CodeMirror.Init)
|
|
||||||
cm.removeKeyMap("continueComment");
|
|
||||||
if (val) {
|
|
||||||
var key = "Enter";
|
|
||||||
if (typeof val == "string")
|
|
||||||
key = val;
|
|
||||||
else if (typeof val == "object" && val.key)
|
|
||||||
key = val.key;
|
|
||||||
var map = {name: "continueComment"};
|
|
||||||
map[key] = continueComment;
|
|
||||||
cm.addKeyMap(map);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
32
shared/codemirror/addon/dialog/dialog.css
vendored
32
shared/codemirror/addon/dialog/dialog.css
vendored
@@ -1,32 +0,0 @@
|
|||||||
.CodeMirror-dialog {
|
|
||||||
position: absolute;
|
|
||||||
left: 0; right: 0;
|
|
||||||
background: inherit;
|
|
||||||
z-index: 15;
|
|
||||||
padding: .1em .8em;
|
|
||||||
overflow: hidden;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CodeMirror-dialog-top {
|
|
||||||
border-bottom: 1px solid #eee;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CodeMirror-dialog-bottom {
|
|
||||||
border-top: 1px solid #eee;
|
|
||||||
bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CodeMirror-dialog input {
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
background: transparent;
|
|
||||||
width: 20em;
|
|
||||||
color: inherit;
|
|
||||||
font-family: monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CodeMirror-dialog button {
|
|
||||||
font-size: 70%;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user