mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 01:32:47 +00:00
Fix merging snippets with base snippets.
This commit is contained in:
@@ -13,6 +13,7 @@ ThemeSnippets['Legacy_5ePHB'] = require('themes/Legacy/5ePHB/snippets.js');
|
|||||||
ThemeSnippets['V3_5ePHB'] = require('themes/V3/5ePHB/snippets.js');
|
ThemeSnippets['V3_5ePHB'] = require('themes/V3/5ePHB/snippets.js');
|
||||||
ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js');
|
ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js');
|
||||||
ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js');
|
ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js');
|
||||||
|
ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js');
|
||||||
|
|
||||||
const execute = function(val, brew){
|
const execute = function(val, brew){
|
||||||
if(_.isFunction(val)) return val(brew);
|
if(_.isFunction(val)) return val(brew);
|
||||||
@@ -46,7 +47,7 @@ const Snippetbar = createClass({
|
|||||||
componentDidMount : async function() {
|
componentDidMount : async function() {
|
||||||
const rendererPath = this.props.renderer == 'V3' ? 'V3' : 'Legacy';
|
const rendererPath = this.props.renderer == 'V3' ? 'V3' : 'Legacy';
|
||||||
const themePath = this.props.theme ?? '5ePHB';
|
const themePath = this.props.theme ?? '5ePHB';
|
||||||
let snippets = ThemeSnippets[`${rendererPath}_${themePath}`];
|
let snippets = _.cloneDeep(ThemeSnippets[`${rendererPath}_${themePath}`]);
|
||||||
snippets = this.compileSnippets(rendererPath, themePath, snippets);
|
snippets = this.compileSnippets(rendererPath, themePath, snippets);
|
||||||
this.setState({
|
this.setState({
|
||||||
snippets : snippets
|
snippets : snippets
|
||||||
@@ -57,8 +58,7 @@ const Snippetbar = createClass({
|
|||||||
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme) {
|
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme) {
|
||||||
const rendererPath = this.props.renderer == 'V3' ? 'V3' : 'Legacy';
|
const rendererPath = this.props.renderer == 'V3' ? 'V3' : 'Legacy';
|
||||||
const themePath = this.props.theme ?? '5ePHB';
|
const themePath = this.props.theme ?? '5ePHB';
|
||||||
console.log({ ThemeSnippets: ThemeSnippets });
|
let snippets = _.cloneDeep(ThemeSnippets[`${rendererPath}_${themePath}`]);
|
||||||
let snippets = ThemeSnippets[`${rendererPath}_${themePath}`];
|
|
||||||
snippets = this.compileSnippets(rendererPath, themePath, snippets);
|
snippets = this.compileSnippets(rendererPath, themePath, snippets);
|
||||||
this.setState({
|
this.setState({
|
||||||
snippets : snippets
|
snippets : snippets
|
||||||
@@ -66,9 +66,9 @@ const Snippetbar = createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mergeCustomizer : function(objValue, srcValue) {
|
mergeCustomizer : function(valueA, valueB, key) {
|
||||||
if(_.isArray(objValue)) {
|
if(key == "snippets") {
|
||||||
const result = _.unionBy(srcValue, objValue, 'name'); // Join snippets together, with preference for the current theme over the base theme
|
const result = _.unionBy(valueB, valueA, 'name'); // Join snippets together, with preference for the current theme over the base theme
|
||||||
return _.filter(result, 'gen'); //Only keep snippets with a 'gen' property.
|
return _.filter(result, 'gen'); //Only keep snippets with a 'gen' property.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -76,13 +76,16 @@ const Snippetbar = createClass({
|
|||||||
compileSnippets : function(rendererPath, themePath, snippets) {
|
compileSnippets : function(rendererPath, themePath, snippets) {
|
||||||
let compiledSnippets = snippets;
|
let compiledSnippets = snippets;
|
||||||
const baseSnippetsPath = Themes[rendererPath][themePath].baseSnippets;
|
const baseSnippetsPath = Themes[rendererPath][themePath].baseSnippets;
|
||||||
//console.log({ baseSnippets: ThemeSnippets[`${rendererPath}_${baseSnippetsPath}`] });
|
|
||||||
//console.log({ themeSnippets: compiledSnippets });
|
let objB = _.keyBy(compiledSnippets, 'groupName');
|
||||||
|
|
||||||
if(baseSnippetsPath) {
|
if(baseSnippetsPath) {
|
||||||
compiledSnippets = _.mergeWith([], ThemeSnippets[`${rendererPath}_${baseSnippetsPath}`], compiledSnippets, this.mergeCustomizer);
|
let objA = _.keyBy(_.cloneDeep(ThemeSnippets[`${rendererPath}_${baseSnippetsPath}`], 'groupName'));
|
||||||
console.log({ compiledSnippets: compiledSnippets });
|
compiledSnippets = _.values(_.mergeWith(objA, objB, this.mergeCustomizer));
|
||||||
//this.compileSnippets(rendererPath, themePath, compiledSnippets); (for nested baseSnippets)
|
}
|
||||||
|
else {
|
||||||
|
let objA = _.keyBy(_.cloneDeep(ThemeSnippets[`${rendererPath}_Blank`], 'groupName'));
|
||||||
|
compiledSnippets = _.values(_.mergeWith(objA, objB, this.mergeCustomizer));
|
||||||
}
|
}
|
||||||
return compiledSnippets;
|
return compiledSnippets;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const MonsterBlockGen = require('./snippets/monsterblock.gen.js');
|
|||||||
const ClassFeatureGen = require('./snippets/classfeature.gen.js');
|
const ClassFeatureGen = require('./snippets/classfeature.gen.js');
|
||||||
const CoverPageGen = require('./snippets/coverpage.gen.js');
|
const CoverPageGen = require('./snippets/coverpage.gen.js');
|
||||||
const TableOfContentsGen = require('./snippets/tableOfContents.gen.js');
|
const TableOfContentsGen = require('./snippets/tableOfContents.gen.js');
|
||||||
const WatercolorGen = require('./snippets/watercolor.gen.js');
|
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
|
|
||||||
@@ -18,48 +17,6 @@ module.exports = [
|
|||||||
icon : 'fas fa-pencil-alt',
|
icon : 'fas fa-pencil-alt',
|
||||||
view : 'text',
|
view : 'text',
|
||||||
snippets : [
|
snippets : [
|
||||||
{
|
|
||||||
name : 'Column Break',
|
|
||||||
icon : 'fas fa-columns',
|
|
||||||
gen : '\n\\column\n'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'New Page',
|
|
||||||
icon : 'fas fa-file-alt',
|
|
||||||
gen : '\n\\page\n'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Vertical Spacing',
|
|
||||||
icon : 'fas fa-arrows-alt-v',
|
|
||||||
gen : '\n::::\n'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Horizontal Spacing',
|
|
||||||
icon : 'fas fa-arrows-alt-h',
|
|
||||||
gen : ' {{width:100px}} '
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Wide Block',
|
|
||||||
icon : 'fas fa-window-maximize',
|
|
||||||
gen : dedent`\n
|
|
||||||
{{wide
|
|
||||||
Everything in here will be extra wide. Tables, text, everything!
|
|
||||||
Beware though, CSS columns can behave a bit weird sometimes. You may
|
|
||||||
have to manually place column breaks with \`\column\` to make the
|
|
||||||
surrounding text flow with this wide block the way you want.
|
|
||||||
}}
|
|
||||||
\n`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'QR Code',
|
|
||||||
icon : 'fas fa-qrcode',
|
|
||||||
gen : (brew)=>{
|
|
||||||
return `![]` +
|
|
||||||
`(https://api.qrserver.com/v1/create-qr-code/?data=` +
|
|
||||||
`https://homebrewery.naturalcrit.com${brew.shareId ? `/share/${brew.shareId}` : ''}` +
|
|
||||||
`&size=100x100) {width:100px;mix-blend-mode:multiply}`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name : 'Page Number',
|
name : 'Page Number',
|
||||||
icon : 'fas fa-bookmark',
|
icon : 'fas fa-bookmark',
|
||||||
@@ -70,21 +27,11 @@ module.exports = [
|
|||||||
icon : 'fas fa-sort-numeric-down',
|
icon : 'fas fa-sort-numeric-down',
|
||||||
gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n'
|
gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name : 'Link to page',
|
|
||||||
icon : 'fas fa-link',
|
|
||||||
gen : '[Click here](#p3) to go to page 3\n'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name : 'Table of Contents',
|
name : 'Table of Contents',
|
||||||
icon : 'fas fa-book',
|
icon : 'fas fa-book',
|
||||||
gen : TableOfContentsGen
|
gen : TableOfContentsGen
|
||||||
},
|
}
|
||||||
{
|
|
||||||
name : 'Add Comment',
|
|
||||||
icon : 'fas fa-code',
|
|
||||||
gen : '<!-- This is a comment that will not be rendered into your brew. Hotkey (Ctrl/Cmd + /). -->'
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -151,11 +98,6 @@ module.exports = [
|
|||||||
[naturalcrit](https://homebrew.naturalcrit.com)
|
[naturalcrit](https://homebrew.naturalcrit.com)
|
||||||
}}`
|
}}`
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name : 'Watercolor Splatter',
|
|
||||||
icon : 'fas fa-fill-drip',
|
|
||||||
gen : WatercolorGen,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name : 'Watermark',
|
name : 'Watermark',
|
||||||
icon : 'fas fa-id-card',
|
icon : 'fas fa-id-card',
|
||||||
|
|||||||
@@ -22,6 +22,13 @@
|
|||||||
"baseSnippets": false,
|
"baseSnippets": false,
|
||||||
"path": "5ePHB"
|
"path": "5ePHB"
|
||||||
},
|
},
|
||||||
|
"Blank": {
|
||||||
|
"name": "Blank",
|
||||||
|
"renderer": "V3",
|
||||||
|
"baseTheme": false,
|
||||||
|
"baseSnippets": false,
|
||||||
|
"path": "Blank"
|
||||||
|
},
|
||||||
"Journal": {
|
"Journal": {
|
||||||
"name": "Journal",
|
"name": "Journal",
|
||||||
"renderer": "V3",
|
"renderer": "V3",
|
||||||
|
|||||||
Reference in New Issue
Block a user