mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 09:22:38 +00:00
Add QR-Code as snippet under Editor (#539)
* Add snippet for QR-code * Add snippet for QR-code * Refactor to expose metadata to snippets * Lint Co-authored-by: Rasmus Bækgaard <git@bakgaard.net> Co-authored-by: Trevor Buckner <calculuschild@gmail.com>
This commit is contained in:
@@ -18,10 +18,9 @@ const SNIPPETBAR_HEIGHT = 25;
|
|||||||
const Editor = createClass({
|
const Editor = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
value : '',
|
brew : {},
|
||||||
onChange : ()=>{},
|
onChange : ()=>{},
|
||||||
|
|
||||||
metadata : {},
|
|
||||||
onMetadataChange : ()=>{},
|
onMetadataChange : ()=>{},
|
||||||
showMetaButton : true,
|
showMetaButton : true,
|
||||||
renderer : 'legacy'
|
renderer : 'legacy'
|
||||||
@@ -59,7 +58,7 @@ const Editor = createClass({
|
|||||||
this.cursorPosition = curpos;
|
this.cursorPosition = curpos;
|
||||||
},
|
},
|
||||||
handleInject : function(injectText){
|
handleInject : function(injectText){
|
||||||
const lines = this.props.value.split('\n');
|
const lines = this.props.brew.text.split('\n');
|
||||||
lines[this.cursorPosition.line] = splice(lines[this.cursorPosition.line], this.cursorPosition.ch, injectText);
|
lines[this.cursorPosition.line] = splice(lines[this.cursorPosition.line], this.cursorPosition.ch, injectText);
|
||||||
|
|
||||||
this.handleTextChange(lines.join('\n'));
|
this.handleTextChange(lines.join('\n'));
|
||||||
@@ -72,7 +71,7 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getCurrentPage : function(){
|
getCurrentPage : function(){
|
||||||
const lines = this.props.value.split('\n').slice(0, this.cursorPosition.line + 1);
|
const lines = this.props.brew.text.split('\n').slice(0, this.cursorPosition.line + 1);
|
||||||
return _.reduce(lines, (r, line)=>{
|
return _.reduce(lines, (r, line)=>{
|
||||||
if(line.indexOf('\\page') !== -1) r++;
|
if(line.indexOf('\\page') !== -1) r++;
|
||||||
return r;
|
return r;
|
||||||
@@ -87,7 +86,7 @@ const Editor = createClass({
|
|||||||
const customHighlights = codeMirror.getAllMarks();
|
const customHighlights = codeMirror.getAllMarks();
|
||||||
for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear();
|
for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear();
|
||||||
|
|
||||||
const lineNumbers = _.reduce(this.props.value.split('\n'), (r, line, lineNumber)=>{
|
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{
|
||||||
|
|
||||||
//reset custom line styles
|
//reset custom line styles
|
||||||
codeMirror.removeLineClass(lineNumber, 'background');
|
codeMirror.removeLineClass(lineNumber, 'background');
|
||||||
@@ -159,7 +158,7 @@ const Editor = createClass({
|
|||||||
renderMetadataEditor : function(){
|
renderMetadataEditor : function(){
|
||||||
if(!this.state.showMetadataEditor) return;
|
if(!this.state.showMetadataEditor) return;
|
||||||
return <MetadataEditor
|
return <MetadataEditor
|
||||||
metadata={this.props.metadata}
|
metadata={this.props.brew}
|
||||||
onChange={this.props.onMetadataChange}
|
onChange={this.props.onMetadataChange}
|
||||||
/>;
|
/>;
|
||||||
},
|
},
|
||||||
@@ -169,7 +168,7 @@ const Editor = createClass({
|
|||||||
return (
|
return (
|
||||||
<div className='editor' ref='main'>
|
<div className='editor' ref='main'>
|
||||||
<SnippetBar
|
<SnippetBar
|
||||||
brew={this.props.value}
|
brew={this.props.brew}
|
||||||
onInject={this.handleInject}
|
onInject={this.handleInject}
|
||||||
onToggle={this.handgleToggle}
|
onToggle={this.handgleToggle}
|
||||||
showmeta={this.state.showMetadataEditor}
|
showmeta={this.state.showMetadataEditor}
|
||||||
@@ -180,7 +179,7 @@ const Editor = createClass({
|
|||||||
ref='codeEditor'
|
ref='codeEditor'
|
||||||
wrap={true}
|
wrap={true}
|
||||||
language='gfm'
|
language='gfm'
|
||||||
value={this.props.value}
|
value={this.props.brew.text}
|
||||||
onChange={this.handleTextChange}
|
onChange={this.handleTextChange}
|
||||||
onCursorActivity={this.handleCursorActivty} />
|
onCursorActivity={this.handleCursorActivty} />
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const execute = function(val, brew){
|
|||||||
const Snippetbar = createClass({
|
const Snippetbar = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
brew : '',
|
brew : {},
|
||||||
onInject : ()=>{},
|
onInject : ()=>{},
|
||||||
onToggle : ()=>{},
|
onToggle : ()=>{},
|
||||||
showmeta : false,
|
showmeta : false,
|
||||||
@@ -80,7 +80,7 @@ module.exports = Snippetbar;
|
|||||||
const SnippetGroup = createClass({
|
const SnippetGroup = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
brew : '',
|
brew : {},
|
||||||
groupName : '',
|
groupName : '',
|
||||||
icon : 'fas fa-rocket',
|
icon : 'fas fa-rocket',
|
||||||
snippets : [],
|
snippets : [],
|
||||||
|
|||||||
@@ -41,8 +41,21 @@ module.exports = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'Background Image',
|
name : 'Background Image',
|
||||||
icon : 'fas fa-times-circle',
|
icon : 'fas fa-tree',
|
||||||
gen : ''
|
gen : `<img src='http://i.imgur.com/hMna6G0.png' ` +
|
||||||
|
`style='position:absolute; top:50px; right:30px; width:280px'/>`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name : 'QR Code',
|
||||||
|
icon : 'fas fa-qrcode',
|
||||||
|
gen : (brew)=>{
|
||||||
|
return `<img ` +
|
||||||
|
`src='https://api.qrserver.com/v1/create-qr-code/?data=` +
|
||||||
|
`https://homebrewery.naturalcrit.com/share/${brew.shareId}` +
|
||||||
|
`&size=100x100' ` +
|
||||||
|
`style='width:100px;mix-blend-mode:multiply'/>`;
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'Page Number',
|
name : 'Page Number',
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const getTOC = (pages)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(brew){
|
module.exports = function(brew){
|
||||||
const pages = brew.split('\\page');
|
const pages = brew.text.split('\\page');
|
||||||
const TOC = getTOC(pages);
|
const TOC = getTOC(pages);
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const getTOC = (pages)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(brew){
|
module.exports = function(brew){
|
||||||
const pages = brew.split('\\page');
|
const pages = brew.text.split('\\page');
|
||||||
const TOC = getTOC(pages);
|
const TOC = getTOC(pages);
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
||||||
|
|||||||
@@ -392,9 +392,8 @@ const EditPage = createClass({
|
|||||||
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||||
<Editor
|
<Editor
|
||||||
ref='editor'
|
ref='editor'
|
||||||
value={this.state.brew.text}
|
brew={this.state.brew}
|
||||||
onChange={this.handleTextChange}
|
onChange={this.handleTextChange}
|
||||||
metadata={this.state.brew}
|
|
||||||
onMetadataChange={this.handleMetadataChange}
|
onMetadataChange={this.handleMetadataChange}
|
||||||
renderer={this.state.brew.renderer}
|
renderer={this.state.brew.renderer}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user