From 009a11a9f5372ce293997ca3bb3a2f7f2518fd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20B=C3=A6kgaard?= Date: Sat, 20 Feb 2021 05:39:29 +0100 Subject: [PATCH] Add QR-Code as snippet under Editor (#539) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add snippet for QR-code * Add snippet for QR-code * Refactor to expose metadata to snippets * Lint Co-authored-by: Rasmus Bækgaard Co-authored-by: Trevor Buckner --- client/homebrew/editor/editor.jsx | 15 +++++++-------- .../homebrew/editor/snippetbar/snippetbar.jsx | 4 ++-- .../editor/snippetbar/snippets/snippets.js | 17 +++++++++++++++-- .../snippetbar/snippets/tableOfContents.gen.js | 4 ++-- .../snippetsLegacy/tableOfContents.gen.js | 4 ++-- client/homebrew/pages/editPage/editPage.jsx | 3 +-- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index dd93b8aa..78dec5d8 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -18,10 +18,9 @@ const SNIPPETBAR_HEIGHT = 25; const Editor = createClass({ getDefaultProps : function() { return { - value : '', + brew : {}, onChange : ()=>{}, - metadata : {}, onMetadataChange : ()=>{}, showMetaButton : true, renderer : 'legacy' @@ -59,7 +58,7 @@ const Editor = createClass({ this.cursorPosition = curpos; }, 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); this.handleTextChange(lines.join('\n')); @@ -72,7 +71,7 @@ const Editor = createClass({ }, 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)=>{ if(line.indexOf('\\page') !== -1) r++; return r; @@ -87,7 +86,7 @@ const Editor = createClass({ const customHighlights = codeMirror.getAllMarks(); for (let i=0;i{ + const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{ //reset custom line styles codeMirror.removeLineClass(lineNumber, 'background'); @@ -159,7 +158,7 @@ const Editor = createClass({ renderMetadataEditor : function(){ if(!this.state.showMetadataEditor) return; return ; }, @@ -169,7 +168,7 @@ const Editor = createClass({ return (
diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index 65c08c22..c42e899d 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -16,7 +16,7 @@ const execute = function(val, brew){ const Snippetbar = createClass({ getDefaultProps : function() { return { - brew : '', + brew : {}, onInject : ()=>{}, onToggle : ()=>{}, showmeta : false, @@ -80,7 +80,7 @@ module.exports = Snippetbar; const SnippetGroup = createClass({ getDefaultProps : function() { return { - brew : '', + brew : {}, groupName : '', icon : 'fas fa-rocket', snippets : [], diff --git a/client/homebrew/editor/snippetbar/snippets/snippets.js b/client/homebrew/editor/snippetbar/snippets/snippets.js index 8cf19885..fc7393aa 100644 --- a/client/homebrew/editor/snippetbar/snippets/snippets.js +++ b/client/homebrew/editor/snippetbar/snippets/snippets.js @@ -41,8 +41,21 @@ module.exports = [ }, { name : 'Background Image', - icon : 'fas fa-times-circle', - gen : '' + icon : 'fas fa-tree', + gen : `` + }, + { + name : 'QR Code', + icon : 'fas fa-qrcode', + gen : (brew)=>{ + return ``; + } + }, { name : 'Page Number', diff --git a/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js b/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js index ca49526d..8a03b053 100644 --- a/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js +++ b/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js @@ -48,7 +48,7 @@ const getTOC = (pages)=>{ }; module.exports = function(brew){ - const pages = brew.split('\\page'); + const pages = brew.text.split('\\page'); const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`); @@ -69,4 +69,4 @@ module.exports = function(brew){ ##### Table Of Contents ${markdown}
\n`; -}; \ No newline at end of file +}; diff --git a/client/homebrew/editor/snippetbar/snippetsLegacy/tableOfContents.gen.js b/client/homebrew/editor/snippetbar/snippetsLegacy/tableOfContents.gen.js index ca49526d..8a03b053 100644 --- a/client/homebrew/editor/snippetbar/snippetsLegacy/tableOfContents.gen.js +++ b/client/homebrew/editor/snippetbar/snippetsLegacy/tableOfContents.gen.js @@ -48,7 +48,7 @@ const getTOC = (pages)=>{ }; module.exports = function(brew){ - const pages = brew.split('\\page'); + const pages = brew.text.split('\\page'); const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`); @@ -69,4 +69,4 @@ module.exports = function(brew){ ##### Table Of Contents ${markdown} \n`; -}; \ No newline at end of file +}; diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx index 4e58e9f1..99ba583b 100644 --- a/client/homebrew/pages/editPage/editPage.jsx +++ b/client/homebrew/pages/editPage/editPage.jsx @@ -392,9 +392,8 @@ const EditPage = createClass({