From 4f240bf1100c46fca948b00899d71a2db2bb4205 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 2 Nov 2024 22:30:18 -0500 Subject: [PATCH] WIP --- client/homebrew/editor/editor.jsx | 2 +- .../homebrew/editor/snippetbar/snippetbar.jsx | 21 ++++++++++++------- server/homebrew.api.js | 4 +--- server/homebrew.api.spec.js | 2 -- shared/helpers.js | 7 +++++-- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 9fef72cbb..27737fcba 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -499,7 +499,7 @@ const Editor = createClass({ historySize={this.historySize()} currentEditorTheme={this.state.editorTheme} updateEditorTheme={this.updateEditorTheme} - snippetBundle={this.props.snippetBundle} + themeBundle={this.props.themeBundle} cursorPos={this.codeEditor.current?.getCursorPosition() || {}} updateBrew={this.props.updateBrew} /> diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index 1f786fd93..111b4fd38 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -41,7 +41,6 @@ const Snippetbar = createClass({ unfoldCode : ()=>{}, updateEditorTheme : ()=>{}, cursorPos : {}, - snippetBundle : [], updateBrew : ()=>{} }; }, @@ -102,20 +101,26 @@ const Snippetbar = createClass({ }, compileSnippets : function() { + console.log('compileSnippets'); let compiledSnippets = []; let oldSnippets = _.keyBy(compiledSnippets, 'groupName'); - for (let snippets of this.props.snippetBundle) { - if(typeof(snippets) == 'string') // load staticThemes as needed; they were sent as just a file name - snippets = ThemeSnippets[snippets]; + console.log(this.props.themesBundle); - const newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName'); - compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, this.mergeCustomizer)); + if( this.props.themesBundle) { + for (let snippets of this.props?.themesBundle?.snippets) { + if(typeof(snippets) == 'string') // load staticThemes as needed; they were sent as just a file name + snippets = ThemeSnippets[snippets]; - oldSnippets = _.keyBy(compiledSnippets, 'groupName'); + const newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName'); + compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, this.mergeCustomizer)); + + oldSnippets = _.keyBy(compiledSnippets, 'groupName'); + } } - const userSnippetsasJSON = brewSnippetsToJSON(this.props.brew.title, this.props.brew.snippets, this.props.snippetsBundle); + console.log(this.props.themesBundle); + const userSnippetsasJSON = brewSnippetsToJSON(this.props.brew.title, this.props.brew.snippets, this.props?.themesBundle?.snippets); compiledSnippets.push(userSnippetsasJSON); return compiledSnippets; diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 2abbf9485..685415c14 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -296,7 +296,7 @@ const api = { splitTextStyleAndMetadata(currentTheme); // If there is anything in the snippets or style members, append them to the appropriate array - if(currentTheme?.snippets) completeSnippets.push(JSON.parse(currentTheme.snippets)); + if(currentTheme?.snippets) completeSnippets.push({ name: currentTheme.title, snippets: currentTheme.snippets }); if(currentTheme?.style) completeStyles.push(`/* From Brew: ${req.protocol}://${req.get('host')}/share/${req.params.id} */\n\n${currentTheme.style}`); req.params.id = currentTheme.theme; @@ -304,9 +304,7 @@ const api = { } //=== Static Themes ===// else { - const localSnippets = `${req.params.renderer}_${req.params.id}`; // Just log the name for loading on client const localStyle = `@import url(\"/themes/${req.params.renderer}/${req.params.id}/style.css\");`; - completeSnippets.push(localSnippets); completeStyles.push(`/* From Theme ${req.params.id} */\n\n${localStyle}`); req.params.id = Themes[req.params.renderer][req.params.id].baseTheme; diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index a1222cb57..3c86e4208 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -627,8 +627,6 @@ brew`); `/* From Theme 5ePHB */\n\n@import url("/themes/V3/5ePHB/style.css");` ], snippets : [ - 'V3_Blank', - 'V3_5ePHB' ] }); }); diff --git a/shared/helpers.js b/shared/helpers.js index b84cb0332..d5a4512a6 100644 --- a/shared/helpers.js +++ b/shared/helpers.js @@ -8,9 +8,12 @@ const brewSnippetsToJSON = (menuTitle, userBrewSnippets, themeBundleSnippets)=>{ const textSplit = /^\\page/gm; const mpAsSnippets = []; // Snippets from Themes first. + //console.log(themeBundleSnippets); if(themeBundleSnippets) { + console.log('Looping!'); for (let themes of themeBundleSnippets) { const userSnippets = []; + console.log(themes); for (let snips of themes.snippets.split(textSplit)) { const name = snips.split('\n')[0]; if(name.length != 0) { @@ -80,9 +83,9 @@ const splitTextStyleAndMetadata = (brew)=>{ brew.style = brew.text.slice(7, index - 1); brew.text = brew.text.slice(index + 5); } - // if(!brew?.snippets) { + if(!brew?.snippets) { brew.snippets = `\\snippet Example\nI am an example user snippet\n`; - // } + } }; const printCurrentBrew = ()=>{