mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 02:52:38 +00:00
Merge branch 'master' into Functional-Tag-Editor
This commit is contained in:
@@ -10,7 +10,7 @@ orbs:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:20.8.0
|
- image: cimg/node:20.17.0
|
||||||
- image: mongo:4.4
|
- image: mongo:4.4
|
||||||
|
|
||||||
working_directory: ~/homebrewery
|
working_directory: ~/homebrewery
|
||||||
@@ -27,7 +27,7 @@ jobs:
|
|||||||
# fallback to using the latest cache if no exact match is found
|
# fallback to using the latest cache if no exact match is found
|
||||||
- v1-dependencies-
|
- v1-dependencies-
|
||||||
|
|
||||||
- run: sudo npm install -g npm@10.2.0
|
- run: sudo npm install -g npm@10.8.2
|
||||||
- node/install-packages:
|
- node/install-packages:
|
||||||
app-dir: ~/homebrewery
|
app-dir: ~/homebrewery
|
||||||
cache-path: node_modules
|
cache-path: node_modules
|
||||||
@@ -45,7 +45,7 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:20.8.0
|
- image: cimg/node:20.17.0
|
||||||
|
|
||||||
working_directory: ~/homebrewery
|
working_directory: ~/homebrewery
|
||||||
parallelism: 1
|
parallelism: 1
|
||||||
@@ -76,6 +76,9 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
name: Test - Routes
|
name: Test - Routes
|
||||||
command: npm run test:route
|
command: npm run test:route
|
||||||
|
- run:
|
||||||
|
name: Test - HTML sanitization
|
||||||
|
command: npm run test:safehtml
|
||||||
- run:
|
- run:
|
||||||
name: Test - Coverage
|
name: Test - Coverage
|
||||||
command: npm run test:coverage
|
command: npm run test:coverage
|
||||||
|
|||||||
76
changelog.md
76
changelog.md
@@ -81,9 +81,85 @@ pre {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## changelog
|
## changelog
|
||||||
For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery).
|
For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery).
|
||||||
|
|
||||||
|
### Saturday 10/12/2024 - v3.16.0
|
||||||
|
|
||||||
|
{{taskList
|
||||||
|
##### 5e-Cleric
|
||||||
|
|
||||||
|
* [x] Added a new API endpoint `/metadata/:shareId` to fetch metadata about individual brews
|
||||||
|
|
||||||
|
Fixes issue [#2638](https://github.com/naturalcrit/homebrewery/issues/2638)
|
||||||
|
|
||||||
|
* [x] Added A3, A5, and Card page size snippets under {{openSans **:fas_paintbrush: STYLE TAB :fas_arrow_right: :fas_print: PRINT**}}
|
||||||
|
|
||||||
|
* [x] Adjust navbar styling for very long titles
|
||||||
|
|
||||||
|
Fixes issue [#2071](https://github.com/naturalcrit/homebrewery/issues/2071)
|
||||||
|
|
||||||
|
* [x] Added some sorting options to the {{openSans **VAULT** {{fas,fa-dungeon}}}} page
|
||||||
|
|
||||||
|
* [x] Fix `language` property not working in share page
|
||||||
|
|
||||||
|
Fixes issue [#3776](https://github.com/naturalcrit/homebrewery/issues/3776)
|
||||||
|
|
||||||
|
##### abquintic
|
||||||
|
|
||||||
|
* [x] New {{openSans **:fas_pencil: TEXT EDITOR :fas_arrow_right: :fas_bookmark: PAGE NUMBER :fas_arrow_right:**}}
|
||||||
|
{{openSans **:fas_xmark: SKIP PAGE NUMBER**}} and {{openSans **:fas_arrow_rotate_left: RESTART PAGE NUMBER**}} snippets for more control over automatic page numbering.
|
||||||
|
|
||||||
|
Fixes issue [#513](https://github.com/naturalcrit/homebrewery/issues/513)
|
||||||
|
|
||||||
|
* [x] New Table of Contents control options via {{openSans **:fas_pencil: TEXT EDITOR :fas_arrow_right: :fas_book: TABLE OF CONTENTS**}} submenus. By default, H1-H3 is included in the ToC generation, but the new options allow marking `{{blocks}}` to include or exclude specific or ranges of contained headers. Also, a global option to increase the default range of H1-H3 to H1-H4/5/6. After applying these markers, you must regenerate the Table of Contents to see the changes.
|
||||||
|
|
||||||
|
* [x] Added a ":fas_lock: SYNC VIEWS" button onto the divider bar. When locked, scrolling on either panel will sync the other panel to the same page.
|
||||||
|
|
||||||
|
Fixes issue [#241](https://github.com/naturalcrit/homebrewery/issues/241)
|
||||||
|
|
||||||
|
##### Gazook89
|
||||||
|
|
||||||
|
* [x] Added a :fas_glasses: HIDE button to the page navigation bar
|
||||||
|
|
||||||
|
##### G-Ambatte
|
||||||
|
|
||||||
|
* [x] Automatic local backups of your files, in case of accidental data loss. Stores up to 5 snapshots of each brew edited in your browser, incrementing from a few minutes old to a maximum of several days. Restore a backup by clicking an entry in the new {{openSans **:fas_clock_rotate_left: HISTORY**}} button in the snippet bar.
|
||||||
|
|
||||||
|
Fixes issue [#3070](https://github.com/naturalcrit/homebrewery/issues/3070)
|
||||||
|
|
||||||
|
* [x] Fix issue with legacy brews breaking on Share page
|
||||||
|
|
||||||
|
Fixes issue [#3764](https://github.com/naturalcrit/homebrewery/issues/3764)
|
||||||
|
|
||||||
|
* [x] Fix print size when printing a zoomed document
|
||||||
|
|
||||||
|
Fixes issue [#3744](https://github.com/naturalcrit/homebrewery/issues/3744)
|
||||||
|
|
||||||
|
##### All
|
||||||
|
|
||||||
|
* [x] Background code cleanup, security fixes, dev tool improvements, dependency updates, prep for upcoming features, etc.
|
||||||
|
}}
|
||||||
|
|
||||||
|
### Wednesday 9/25/2024 - v3.15.1
|
||||||
|
|
||||||
|
{{taskList
|
||||||
|
##### calculuschild
|
||||||
|
|
||||||
|
* [x] Background fixes to handle Google Drive issues
|
||||||
|
|
||||||
|
* [x] Remove duplicate error logging
|
||||||
|
|
||||||
|
##### calculuschild, 5e-Cleric
|
||||||
|
|
||||||
|
* [x] Fix links in {{openSans **RECENT BREWS :fas_clock_rotate_left:**}} and user {{openSans **BREWS :fas_beer_mug_empty:**}} pointing to trashed Google Drive files after transferring from Google to Homebrewery storage
|
||||||
|
|
||||||
|
Fixes issue [#3776](https://github.com/naturalcrit/homebrewery/issues/3776)
|
||||||
|
}}
|
||||||
|
|
||||||
|
\page
|
||||||
|
|
||||||
### Wednesday 9/04/2024 - v3.15.0
|
### Wednesday 9/04/2024 - v3.15.0
|
||||||
|
|
||||||
{{taskList
|
{{taskList
|
||||||
|
|||||||
@@ -2,35 +2,44 @@ require('./admin.less');
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
|
|
||||||
|
const BrewUtils = require('./brewUtils/brewUtils.jsx');
|
||||||
|
const NotificationUtils = require('./notificationUtils/notificationUtils.jsx');
|
||||||
|
|
||||||
const BrewCleanup = require('./brewCleanup/brewCleanup.jsx');
|
const tabGroups = ['brew', 'notifications'];
|
||||||
const BrewLookup = require('./brewLookup/brewLookup.jsx');
|
|
||||||
const BrewCompress = require ('./brewCompress/brewCompress.jsx');
|
|
||||||
const Stats = require('./stats/stats.jsx');
|
|
||||||
|
|
||||||
const Admin = createClass({
|
const Admin = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState : function(){
|
||||||
|
return ({
|
||||||
|
currentTab : 'brew'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleClick : function(newTab){
|
||||||
|
if(this.state.currentTab === newTab) return;
|
||||||
|
this.setState({
|
||||||
|
currentTab : newTab
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='admin'>
|
return <div className='admin'>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<div className='container'>
|
<div className='container'>
|
||||||
<i className='fas fa-rocket' />
|
<i className='fas fa-rocket' />
|
||||||
homebrewery admin
|
homebrewery admin
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div className='container'>
|
<main className='container'>
|
||||||
<Stats />
|
<nav className='tabs'>
|
||||||
<hr />
|
{tabGroups.map((tab, idx)=>{ return <button className={tab===this.state.currentTab ? 'active' : ''} key={idx} onClick={()=>{ return this.handleClick(tab); }}>{tab.toUpperCase()}</button>; })}
|
||||||
<BrewLookup />
|
</nav>
|
||||||
<hr />
|
{this.state.currentTab==='brew' && <BrewUtils />}
|
||||||
<BrewCleanup />
|
{this.state.currentTab==='notifications' && <NotificationUtils />}
|
||||||
<hr />
|
</main>
|
||||||
<BrewCompress />
|
|
||||||
</div>
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,39 +6,95 @@
|
|||||||
|
|
||||||
@import 'font-awesome/css/font-awesome.css';
|
@import 'font-awesome/css/font-awesome.css';
|
||||||
|
|
||||||
html,body, #reactContainer, .naturalCrit{
|
html,body, #reactContainer, .naturalCrit { min-height : 100%; }
|
||||||
min-height : 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@sidebarWidth : 250px;
|
@sidebarWidth : 250px;
|
||||||
|
|
||||||
body{
|
body {
|
||||||
background-color : #eee;
|
height : 100%;
|
||||||
font-family : 'Open Sans', sans-serif;
|
|
||||||
color : #4b5055;
|
|
||||||
font-weight : 100;
|
|
||||||
text-rendering : optimizeLegibility;
|
|
||||||
margin : 0;
|
|
||||||
padding : 0;
|
padding : 0;
|
||||||
height : 100%;
|
margin : 0;
|
||||||
|
font-family : 'Open Sans', sans-serif;
|
||||||
|
font-weight : 100;
|
||||||
|
color : #4B5055;
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
text-rendering : optimizeLegibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin{
|
:where(.admin) {
|
||||||
|
|
||||||
header{
|
header {
|
||||||
|
padding : 20px 0px;
|
||||||
|
margin-bottom : 30px;
|
||||||
|
font-size : 2em;
|
||||||
|
color : white;
|
||||||
background-color : @red;
|
background-color : @red;
|
||||||
font-size: 2em;
|
i { margin-right : 30px; }
|
||||||
padding : 20px 0px;
|
}
|
||||||
color : white;
|
|
||||||
margin-bottom: 30px;
|
hr { margin : 30px 0px; }
|
||||||
i{
|
|
||||||
margin-right: 30px;
|
:where(.container) {
|
||||||
|
input {
|
||||||
|
height : 33px;
|
||||||
|
padding : 0px 10px;
|
||||||
|
margin-bottom : 20px;
|
||||||
|
font-family : monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
height : 37px;
|
||||||
|
vertical-align : middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl {
|
||||||
|
@maxItemWidth : 132px;
|
||||||
|
dt {
|
||||||
|
float : left;
|
||||||
|
width : @maxItemWidth;
|
||||||
|
clear : left;
|
||||||
|
text-align : right;
|
||||||
|
&::after { content : ' : '; }
|
||||||
|
}
|
||||||
|
dd {
|
||||||
|
height : 1em;
|
||||||
|
padding : 0 0 0.5em 0;
|
||||||
|
margin-left : @maxItemWidth + 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button {
|
||||||
|
margin-right : 3px;
|
||||||
|
margin-left : 3px;
|
||||||
|
color : black;
|
||||||
|
background-color : #EEEEEE;
|
||||||
|
border : 1px solid #444444;
|
||||||
|
border-radius : 5px;
|
||||||
|
&:hover {
|
||||||
|
color : #EEEEEE;
|
||||||
|
background-color : #444444;
|
||||||
|
}
|
||||||
|
&.active {
|
||||||
|
margin-right : 2px;
|
||||||
|
margin-left : 2px;
|
||||||
|
text-decoration : underline;
|
||||||
|
background-color : #CCCCCC;
|
||||||
|
border : 2px solid #444444;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.notificationUtils {
|
||||||
|
display : flex;
|
||||||
|
gap : 50px;
|
||||||
|
justify-content : space-between;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hr{
|
.error {
|
||||||
margin : 30px 0px;
|
background: rgb(178, 54, 54);
|
||||||
|
color:white;
|
||||||
|
font-weight: 900;
|
||||||
|
margin-block:10px;
|
||||||
|
padding:10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
.BrewCleanup{
|
|
||||||
.removeBox{
|
|
||||||
margin-top: 20px;
|
|
||||||
button{
|
|
||||||
background-color: @red;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
.BrewCompress{
|
|
||||||
.removeBox{
|
|
||||||
margin-top: 20px;
|
|
||||||
button{
|
|
||||||
background-color: @red;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
.brewLookup{
|
|
||||||
input{
|
|
||||||
height : 33px;
|
|
||||||
margin-bottom : 20px;
|
|
||||||
padding : 0px 10px;
|
|
||||||
font-family : monospace;
|
|
||||||
}
|
|
||||||
button{
|
|
||||||
vertical-align : middle;
|
|
||||||
height : 37px;
|
|
||||||
}
|
|
||||||
dl{
|
|
||||||
@maxItemWidth : 132px;
|
|
||||||
dt{
|
|
||||||
float : left;
|
|
||||||
clear : left;
|
|
||||||
width : @maxItemWidth;
|
|
||||||
text-align : right;
|
|
||||||
&::after {
|
|
||||||
content: " : ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dd{
|
|
||||||
height : 1em;
|
|
||||||
margin-left : @maxItemWidth + 6px;
|
|
||||||
padding : 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
9
client/admin/brewUtils/brewCleanup/brewCleanup.less
Normal file
9
client/admin/brewUtils/brewCleanup/brewCleanup.less
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.BrewCleanup {
|
||||||
|
.removeBox {
|
||||||
|
margin-top : 20px;
|
||||||
|
button {
|
||||||
|
margin-right : 10px;
|
||||||
|
background-color : @red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
client/admin/brewUtils/brewCompress/brewCompress.less
Normal file
9
client/admin/brewUtils/brewCompress/brewCompress.less
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.BrewCompress {
|
||||||
|
.removeBox {
|
||||||
|
margin-top : 20px;
|
||||||
|
button {
|
||||||
|
margin-right : 10px;
|
||||||
|
background-color : @red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
require('./brewLookup.less');
|
require('./brewLookup.less');
|
||||||
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
@@ -13,22 +14,43 @@ const BrewLookup = createClass({
|
|||||||
},
|
},
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
query : '',
|
query : '',
|
||||||
foundBrew : null,
|
foundBrew : null,
|
||||||
searching : false,
|
searching : false,
|
||||||
error : null
|
error : null,
|
||||||
|
scriptCount : 0
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleChange(e){
|
handleChange(e){
|
||||||
this.setState({ query: e.target.value });
|
this.setState({ query: e.target.value });
|
||||||
},
|
},
|
||||||
lookup(){
|
lookup(){
|
||||||
this.setState({ searching: true, error: null });
|
this.setState({ searching: true, error: null, scriptCount: 0 });
|
||||||
|
|
||||||
request.get(`/admin/lookup/${this.state.query}`)
|
request.get(`/admin/lookup/${this.state.query}`)
|
||||||
.then((res)=>this.setState({ foundBrew: res.body }))
|
.then((res)=>{
|
||||||
|
const foundBrew = res.body;
|
||||||
|
const scriptCheck = foundBrew?.text.match(/(<\/?s)cript/g);
|
||||||
|
this.setState({
|
||||||
|
foundBrew : foundBrew,
|
||||||
|
scriptCount : scriptCheck?.length || 0,
|
||||||
|
});
|
||||||
|
})
|
||||||
.catch((err)=>this.setState({ error: err }))
|
.catch((err)=>this.setState({ error: err }))
|
||||||
.finally(()=>this.setState({ searching: false }));
|
.finally(()=>{
|
||||||
|
this.setState({
|
||||||
|
searching : false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async cleanScript(){
|
||||||
|
if(!this.state.foundBrew?.shareId) return;
|
||||||
|
|
||||||
|
await request.put(`/admin/clean/script/${this.state.foundBrew.shareId}`)
|
||||||
|
.catch((err)=>{ this.setState({ error: err }); return; });
|
||||||
|
|
||||||
|
this.lookup();
|
||||||
},
|
},
|
||||||
|
|
||||||
renderFoundBrew(){
|
renderFoundBrew(){
|
||||||
@@ -47,12 +69,23 @@ const BrewLookup = createClass({
|
|||||||
<dt>Share Link</dt>
|
<dt>Share Link</dt>
|
||||||
<dd><a href={`/share/${brew.shareId}`} target='_blank' rel='noopener noreferrer'>/share/{brew.shareId}</a></dd>
|
<dd><a href={`/share/${brew.shareId}`} target='_blank' rel='noopener noreferrer'>/share/{brew.shareId}</a></dd>
|
||||||
|
|
||||||
|
<dt>Created Time</dt>
|
||||||
|
<dd>{brew.createdAt ? Moment(brew.createdAt).toLocaleString() : 'No creation date'}</dd>
|
||||||
|
|
||||||
<dt>Last Updated</dt>
|
<dt>Last Updated</dt>
|
||||||
<dd>{Moment(brew.updatedAt).fromNow()}</dd>
|
<dd>{Moment(brew.updatedAt).fromNow()}</dd>
|
||||||
|
|
||||||
<dt>Num of Views</dt>
|
<dt>Num of Views</dt>
|
||||||
<dd>{brew.views}</dd>
|
<dd>{brew.views}</dd>
|
||||||
|
|
||||||
|
<dt>SCRIPT tags detected</dt>
|
||||||
|
<dd>{this.state.scriptCount}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
{this.state.scriptCount > 0 &&
|
||||||
|
<div className='cleanButton'>
|
||||||
|
<button onClick={this.cleanScript}>CLEAN BREW</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>;
|
</div>;
|
||||||
},
|
},
|
||||||
|
|
||||||
6
client/admin/brewUtils/brewLookup/brewLookup.less
Normal file
6
client/admin/brewUtils/brewLookup/brewLookup.less
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.brewLookup {
|
||||||
|
.cleanButton {
|
||||||
|
display : inline-block;
|
||||||
|
width : 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
client/admin/brewUtils/brewUtils.jsx
Normal file
24
client/admin/brewUtils/brewUtils.jsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const React = require('react');
|
||||||
|
const createClass = require('create-react-class');
|
||||||
|
|
||||||
|
|
||||||
|
const BrewCleanup = require('./brewCleanup/brewCleanup.jsx');
|
||||||
|
const BrewLookup = require('./brewLookup/brewLookup.jsx');
|
||||||
|
const BrewCompress = require ('./brewCompress/brewCompress.jsx');
|
||||||
|
const Stats = require('./stats/stats.jsx');
|
||||||
|
|
||||||
|
const BrewUtils = createClass({
|
||||||
|
render : function(){
|
||||||
|
return <>
|
||||||
|
<Stats />
|
||||||
|
<hr />
|
||||||
|
<BrewLookup />
|
||||||
|
<hr />
|
||||||
|
<BrewCleanup />
|
||||||
|
<hr />
|
||||||
|
<BrewCompress />
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = BrewUtils;
|
||||||
13
client/admin/brewUtils/stats/stats.less
Normal file
13
client/admin/brewUtils/stats/stats.less
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
.Stats {
|
||||||
|
position : relative;
|
||||||
|
|
||||||
|
.pending {
|
||||||
|
position : absolute;
|
||||||
|
top : 0px;
|
||||||
|
left : 0px;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
background-color : rgba(238,238,238, 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
require('./notificationAdd.less');
|
||||||
|
const React = require('react');
|
||||||
|
const { useState, useRef } = require('react');
|
||||||
|
const request = require('superagent');
|
||||||
|
|
||||||
|
const NotificationAdd = ()=>{
|
||||||
|
const [notificationResult, setNotificationResult] = useState(null);
|
||||||
|
const [searching, setSearching] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const dismissKeyRef = useRef(null);
|
||||||
|
const titleRef = useRef(null);
|
||||||
|
const textRef = useRef(null);
|
||||||
|
const startAtRef = useRef(null);
|
||||||
|
const stopAtRef = useRef(null);
|
||||||
|
|
||||||
|
const saveNotification = async ()=>{
|
||||||
|
const dismissKey = dismissKeyRef.current.value;
|
||||||
|
const title = titleRef.current.value;
|
||||||
|
const text = textRef.current.value;
|
||||||
|
const startAt = new Date(startAtRef.current.value);
|
||||||
|
const stopAt = new Date(stopAtRef.current.value);
|
||||||
|
|
||||||
|
// Basic validation
|
||||||
|
if(!dismissKey || !title || !text || isNaN(startAt.getTime()) || isNaN(stopAt.getTime())) {
|
||||||
|
setError('All fields are required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(startAt >= stopAt) {
|
||||||
|
setError('End date must be after the start date!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
dismissKey,
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
startAt : startAt?.toISOString() ?? '',
|
||||||
|
stopAt : stopAt?.toISOString() ?? '',
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
setSearching(true);
|
||||||
|
setError(null);
|
||||||
|
const response = await request.post('/admin/notification/add').send(data);
|
||||||
|
console.log(response.body);
|
||||||
|
|
||||||
|
// Reset form fields
|
||||||
|
dismissKeyRef.current.value = '';
|
||||||
|
titleRef.current.value = '';
|
||||||
|
textRef.current.value = '';
|
||||||
|
|
||||||
|
setNotificationResult('Notification successfully created.');
|
||||||
|
setSearching(false);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err.response.body.message);
|
||||||
|
setError(`Error saving notification: ${err.response.body.message}`);
|
||||||
|
setSearching(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='notificationAdd'>
|
||||||
|
<h2>Add Notification</h2>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Dismiss Key:
|
||||||
|
<input className='fieldInput' type='text' ref={dismissKeyRef} required
|
||||||
|
placeholder='dismiss_notif_drive'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Title:
|
||||||
|
<input className='fieldInput' type='text' ref={titleRef} required
|
||||||
|
placeholder='Stop using Google Drive as image host'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Text:
|
||||||
|
<textarea className='fieldInput' type='text' ref={textRef} required
|
||||||
|
placeholder='Google Drive is not an image hosting site, you should not use it as such.'
|
||||||
|
>
|
||||||
|
</textarea>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
Start Date:
|
||||||
|
<input type='date' className='fieldInput' ref={startAtRef} required/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className='field'>
|
||||||
|
End Date:
|
||||||
|
<input type='date' className='fieldInput' ref={stopAtRef} required/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className='notificationResult'>{notificationResult}</div>
|
||||||
|
|
||||||
|
<button className='notificationSave' onClick={saveNotification} disabled={searching}>
|
||||||
|
<i className={`fas ${searching ? 'fa-spin fa-spinner' : 'fa-save'}`}/>
|
||||||
|
Save Notification
|
||||||
|
</button>
|
||||||
|
{error && <div className='error'>{error}</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NotificationAdd;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
.notificationAdd {
|
||||||
|
position : relative;
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
width : 500px;
|
||||||
|
|
||||||
|
.field {
|
||||||
|
display : grid;
|
||||||
|
grid-template-columns : 120px 150px;
|
||||||
|
align-items : center;
|
||||||
|
justify-items : stretch;
|
||||||
|
width : 100%;
|
||||||
|
margin-bottom : 20px;
|
||||||
|
|
||||||
|
|
||||||
|
input {
|
||||||
|
height : 33px;
|
||||||
|
padding : 0px 10px;
|
||||||
|
margin-bottom : unset;
|
||||||
|
font-family : monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width : 50ch;
|
||||||
|
min-height : 7em;
|
||||||
|
max-height : 20em;
|
||||||
|
resize : vertical;
|
||||||
|
padding : 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 200px;
|
||||||
|
|
||||||
|
i { margin-right : 10px; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
require('./notificationLookup.less');
|
||||||
|
|
||||||
|
const React = require('react');
|
||||||
|
const { useState } = require('react');
|
||||||
|
const request = require('superagent');
|
||||||
|
const Moment = require('moment');
|
||||||
|
|
||||||
|
const NotificationDetail = ({ notification, onDelete })=>(
|
||||||
|
<>
|
||||||
|
<dl>
|
||||||
|
<dt>Key</dt>
|
||||||
|
<dd>{notification.dismissKey}</dd>
|
||||||
|
|
||||||
|
<dt>Title</dt>
|
||||||
|
<dd>{notification.title || 'No Title'}</dd>
|
||||||
|
|
||||||
|
<dt>Created</dt>
|
||||||
|
<dd>{Moment(notification.createdAt).format('LLLL')}</dd>
|
||||||
|
|
||||||
|
<dt>Start</dt>
|
||||||
|
<dd>{Moment(notification.startAt).format('LLLL') || 'No Start Time'}</dd>
|
||||||
|
|
||||||
|
<dt>Stop</dt>
|
||||||
|
<dd>{Moment(notification.stopAt).format('LLLL') || 'No End Time'}</dd>
|
||||||
|
|
||||||
|
<dt>Text</dt>
|
||||||
|
<dd>{notification.text || 'No Text'}</dd>
|
||||||
|
</dl>
|
||||||
|
<button onClick={()=>onDelete(notification.dismissKey)}>DELETE</button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const NotificationLookup = ()=>{
|
||||||
|
const [searching, setSearching] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const [notifications, setNotifications] = useState([]);
|
||||||
|
|
||||||
|
const lookupAll = async ()=>{
|
||||||
|
setSearching(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await request.get('/admin/notification/all');
|
||||||
|
setNotifications(res.body || []);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setError(`Error looking up notifications: ${err.response.body.message}`);
|
||||||
|
} finally {
|
||||||
|
setSearching(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteNotification = async (dismissKey)=>{
|
||||||
|
if(!dismissKey) return;
|
||||||
|
|
||||||
|
const confirmed = window.confirm(
|
||||||
|
`Really delete notification ${dismissKey}?`
|
||||||
|
);
|
||||||
|
if(!confirmed) {
|
||||||
|
console.log('Delete notification cancelled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Delete notification confirm');
|
||||||
|
try {
|
||||||
|
await request.delete(`/admin/notification/delete/${dismissKey}`);
|
||||||
|
lookupAll();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setError(`Error deleting notification: ${err.response.body.message}`);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderNotificationsList = ()=>{
|
||||||
|
if(error)
|
||||||
|
return <div className='error'>{error}</div>;
|
||||||
|
|
||||||
|
if(notifications.length === 0)
|
||||||
|
return <div className='noNotification'>No notifications available.</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ul className='notificationList'>
|
||||||
|
{notifications.map((notification)=>(
|
||||||
|
<li key={notification.dismissKey} >
|
||||||
|
<details>
|
||||||
|
<summary>{notification.title || 'No Title'}</summary>
|
||||||
|
<NotificationDetail notification={notification} onDelete={deleteNotification} />
|
||||||
|
</details>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='notificationLookup'>
|
||||||
|
<h2>Check all Notifications</h2>
|
||||||
|
<button onClick={lookupAll}>
|
||||||
|
<i className={`fas ${searching ? 'fa-spin fa-spinner' : 'fa-search'}`} />
|
||||||
|
</button>
|
||||||
|
{renderNotificationsList()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NotificationLookup;
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
.notificationLookup {
|
||||||
|
width : 450px;
|
||||||
|
height : fit-content;
|
||||||
|
|
||||||
|
.notificationList {
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
max-height : 500px;
|
||||||
|
margin-block : 20px;
|
||||||
|
overflow : auto;
|
||||||
|
border : 1px solid;
|
||||||
|
border-radius : 5px;
|
||||||
|
|
||||||
|
li {
|
||||||
|
padding : 10px;
|
||||||
|
background : #CCCCCC;
|
||||||
|
|
||||||
|
&:nth-child(even) { background : #DDDDDD; }
|
||||||
|
&:first-child {
|
||||||
|
border-top-left-radius : 5px;
|
||||||
|
border-top-right-radius : 5px;
|
||||||
|
}
|
||||||
|
&:last-child {
|
||||||
|
border-bottom-right-radius : 5px;
|
||||||
|
border-bottom-left-radius : 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
font-size : 20px;
|
||||||
|
font-weight : 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl dt{
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.noNotification { margin-block : 20px; }
|
||||||
|
}
|
||||||
15
client/admin/notificationUtils/notificationUtils.jsx
Normal file
15
client/admin/notificationUtils/notificationUtils.jsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const React = require('react');
|
||||||
|
|
||||||
|
const NotificationLookup = require('./notificationLookup/notificationLookup.jsx');
|
||||||
|
const NotificationAdd = require('./notificationAdd/notificationAdd.jsx');
|
||||||
|
|
||||||
|
const NotificationUtils = ()=>{
|
||||||
|
return (
|
||||||
|
<section className='notificationUtils'>
|
||||||
|
<NotificationAdd />
|
||||||
|
<NotificationLookup />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NotificationUtils;
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
.Stats{
|
|
||||||
position : relative;
|
|
||||||
.pending{
|
|
||||||
position : absolute;
|
|
||||||
top : 0px;
|
|
||||||
left : 0px;
|
|
||||||
height : 100%;
|
|
||||||
width : 100%;
|
|
||||||
background-color : rgba(238,238,238, 0.5);
|
|
||||||
}
|
|
||||||
dl{
|
|
||||||
@maxItemWidth : 132px;
|
|
||||||
dt{
|
|
||||||
float : left;
|
|
||||||
clear : left;
|
|
||||||
width : @maxItemWidth;
|
|
||||||
text-align : right;
|
|
||||||
&::after {
|
|
||||||
content: " : ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dd{
|
|
||||||
margin : 0 0 0 @maxItemWidth + 10px;
|
|
||||||
padding : 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
91
client/components/Anchored.jsx
Normal file
91
client/components/Anchored.jsx
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import React, { useState, useRef, forwardRef, useEffect, cloneElement, Children } from 'react';
|
||||||
|
import './Anchored.less';
|
||||||
|
|
||||||
|
// Anchored is a wrapper component that must have as children an <AnchoredTrigger> and a <AnchoredBox> component.
|
||||||
|
// AnchoredTrigger must have a unique `id` prop, which is passed up to Anchored, saved in state on mount, and
|
||||||
|
// then passed down through props into AnchoredBox. The `id` is used for the CSS Anchor Positioning properties.
|
||||||
|
// **The Anchor Positioning API is not available in Firefox yet**
|
||||||
|
// So in Firefox the positioning isn't perfect but is likely sufficient, and FF team seems to be working on the API quickly.
|
||||||
|
|
||||||
|
|
||||||
|
const Anchored = ({ children })=>{
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const [anchorId, setAnchorId] = useState(null);
|
||||||
|
const boxRef = useRef(null);
|
||||||
|
const triggerRef = useRef(null);
|
||||||
|
|
||||||
|
// promote trigger id to Anchored id (to pass it back down to the box as "anchorId")
|
||||||
|
useEffect(()=>{
|
||||||
|
if(triggerRef.current){
|
||||||
|
setAnchorId(triggerRef.current.id);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// close box on outside click or Escape key
|
||||||
|
useEffect(()=>{
|
||||||
|
const handleClickOutside = (evt)=>{
|
||||||
|
if(
|
||||||
|
boxRef.current &&
|
||||||
|
!boxRef.current.contains(evt.target) &&
|
||||||
|
triggerRef.current &&
|
||||||
|
!triggerRef.current.contains(evt.target)
|
||||||
|
) {
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEscapeKey = (evt)=>{
|
||||||
|
if(evt.key === 'Escape') setVisible(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('click', handleClickOutside);
|
||||||
|
window.addEventListener('keydown', handleEscapeKey);
|
||||||
|
|
||||||
|
return ()=>{
|
||||||
|
window.removeEventListener('click', handleClickOutside);
|
||||||
|
window.removeEventListener('keydown', handleEscapeKey);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const toggleVisibility = ()=>setVisible((prev)=>!prev);
|
||||||
|
|
||||||
|
// Map children to inject necessary props
|
||||||
|
const mappedChildren = Children.map(children, (child)=>{
|
||||||
|
if(child.type === AnchoredTrigger) {
|
||||||
|
return cloneElement(child, { ref: triggerRef, toggleVisibility, visible });
|
||||||
|
}
|
||||||
|
if(child.type === AnchoredBox) {
|
||||||
|
return cloneElement(child, { ref: boxRef, visible, anchorId });
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
});
|
||||||
|
|
||||||
|
return <>{mappedChildren}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
// forward ref for AnchoredTrigger
|
||||||
|
const AnchoredTrigger = forwardRef(({ toggleVisibility, visible, children, className, ...props }, ref)=>(
|
||||||
|
<button
|
||||||
|
ref={ref}
|
||||||
|
className={`anchored-trigger${visible ? ' active' : ''} ${className}`}
|
||||||
|
onClick={toggleVisibility}
|
||||||
|
style={{ anchorName: `--${props.id}` }} // setting anchor properties here allows greater recyclability.
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
));
|
||||||
|
|
||||||
|
// forward ref for AnchoredBox
|
||||||
|
const AnchoredBox = forwardRef(({ visible, children, className, anchorId, ...props }, ref)=>(
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className={`anchored-box${visible ? ' active' : ''} ${className}`}
|
||||||
|
style={{ positionAnchor: `--${anchorId}` }} // setting anchor properties here allows greater recyclability.
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
|
||||||
|
export { Anchored, AnchoredTrigger, AnchoredBox };
|
||||||
13
client/components/Anchored.less
Normal file
13
client/components/Anchored.less
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
.anchored-box {
|
||||||
|
position:absolute;
|
||||||
|
@supports (inset-block-start: anchor(bottom)){
|
||||||
|
inset-block-start: anchor(bottom);
|
||||||
|
}
|
||||||
|
justify-self: anchor-center;
|
||||||
|
visibility: hidden;
|
||||||
|
&.active {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,26 @@
|
|||||||
// Dialog box, for popups and modal blocking messages
|
// Dialog box, for popups and modal blocking messages
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const { useRef, useEffect } = React;
|
const { useRef, useEffect } = React;
|
||||||
|
|
||||||
function Dialog({ dismissKey, closeText = 'Close', blocking = false, ...rest }) {
|
function Dialog({ dismisskeys = [], closeText = 'Close', blocking = false, ...rest }) {
|
||||||
const dialogRef = useRef(null);
|
const dialogRef = useRef(null);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if(!dismissKey || !localStorage.getItem(dismissKey)) {
|
if(dismisskeys.length !== 0) {
|
||||||
blocking ? dialogRef.current?.showModal() : dialogRef.current?.show();
|
blocking ? dialogRef.current?.showModal() : dialogRef.current?.show();
|
||||||
}
|
}
|
||||||
}, []);
|
}, [dialogRef.current, dismisskeys]);
|
||||||
|
|
||||||
const dismiss = ()=>{
|
const dismiss = ()=>{
|
||||||
dismissKey && localStorage.setItem(dismissKey, true);
|
dismisskeys.forEach((key)=>{
|
||||||
|
if(key) {
|
||||||
|
localStorage.setItem(key, 'true');
|
||||||
|
}
|
||||||
|
});
|
||||||
dialogRef.current?.close();
|
dialogRef.current?.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<dialog ref={dialogRef} onCancel={dismiss} {...rest}>
|
<dialog ref={dialogRef} onCancel={dismiss} {...rest}>
|
||||||
{rest.children}
|
{rest.children}
|
||||||
<button className='dismiss' onClick={dismiss}>
|
<button className='dismiss' onClick={dismiss}>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./brewRenderer.less');
|
require('./brewRenderer.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const { useState, useRef, useEffect, useCallback } = React;
|
const { useState, useRef, useCallback, useMemo } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
||||||
@@ -16,8 +16,7 @@ const Frame = require('react-frame-component').default;
|
|||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
const { printCurrentBrew } = require('../../../shared/helpers.js');
|
const { printCurrentBrew } = require('../../../shared/helpers.js');
|
||||||
|
|
||||||
const DOMPurify = require('dompurify');
|
import { safeHTML } from './safeHTML.js';
|
||||||
const purifyConfig = { FORCE_BODY: true, SANITIZE_DOM: false };
|
|
||||||
|
|
||||||
const PAGE_HEIGHT = 1056;
|
const PAGE_HEIGHT = 1056;
|
||||||
|
|
||||||
@@ -29,6 +28,7 @@ const INITIAL_CONTENT = dedent`
|
|||||||
<base target=_blank>
|
<base target=_blank>
|
||||||
</head><body style='overflow: hidden'><div></div></body></html>`;
|
</head><body style='overflow: hidden'><div></div></body></html>`;
|
||||||
|
|
||||||
|
|
||||||
//v=====----------------------< Brew Page Component >---------------------=====v//
|
//v=====----------------------< Brew Page Component >---------------------=====v//
|
||||||
const BrewPage = (props)=>{
|
const BrewPage = (props)=>{
|
||||||
props = {
|
props = {
|
||||||
@@ -36,15 +36,15 @@ const BrewPage = (props)=>{
|
|||||||
index : 0,
|
index : 0,
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
const cleanText = props.contents; //DOMPurify.sanitize(props.contents, purifyConfig);
|
const cleanText = safeHTML(props.contents);
|
||||||
return <div className={props.className} id={`p${props.index + 1}`} >
|
return <div className={props.className} id={`p${props.index + 1}`} style={props.style}>
|
||||||
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
|
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//v=====--------------------< Brew Renderer Component >-------------------=====v//
|
//v=====--------------------< Brew Renderer Component >-------------------=====v//
|
||||||
const renderedPages = [];
|
let renderedPages = [];
|
||||||
let rawPages = [];
|
let rawPages = [];
|
||||||
|
|
||||||
const BrewRenderer = (props)=>{
|
const BrewRenderer = (props)=>{
|
||||||
@@ -55,19 +55,24 @@ const BrewRenderer = (props)=>{
|
|||||||
theme : '5ePHB',
|
theme : '5ePHB',
|
||||||
lang : '',
|
lang : '',
|
||||||
errors : [],
|
errors : [],
|
||||||
currentEditorCursorPageNum : 0,
|
currentEditorCursorPageNum : 1,
|
||||||
currentEditorViewPageNum : 0,
|
currentEditorViewPageNum : 1,
|
||||||
currentBrewRendererPageNum : 0,
|
currentBrewRendererPageNum : 1,
|
||||||
themeBundle : {},
|
themeBundle : {},
|
||||||
onPageChange : ()=>{},
|
onPageChange : ()=>{},
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
height : PAGE_HEIGHT,
|
|
||||||
isMounted : false,
|
isMounted : false,
|
||||||
visibility : 'hidden',
|
visibility : 'hidden'
|
||||||
zoom : 100
|
});
|
||||||
|
|
||||||
|
const [displayOptions, setDisplayOptions] = useState({
|
||||||
|
zoomLevel : 100,
|
||||||
|
spread : 'single',
|
||||||
|
startOnRight : true,
|
||||||
|
pageShadows : true
|
||||||
});
|
});
|
||||||
|
|
||||||
const mainRef = useRef(null);
|
const mainRef = useRef(null);
|
||||||
@@ -78,15 +83,24 @@ const BrewRenderer = (props)=>{
|
|||||||
rawPages = props.text.split(/^\\page$/gm);
|
rawPages = props.text.split(/^\\page$/gm);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(()=>{ // Unmounting steps
|
const scrollToHash = (hash)=>{
|
||||||
return ()=>{window.removeEventListener('resize', updateSize);};
|
if(!hash) return;
|
||||||
}, []);
|
|
||||||
|
|
||||||
const updateSize = ()=>{
|
const iframeDoc = document.getElementById('BrewRenderer').contentDocument;
|
||||||
setState((prevState)=>({
|
let anchor = iframeDoc.querySelector(hash);
|
||||||
...prevState,
|
|
||||||
height : mainRef.current.parentNode.clientHeight,
|
if(anchor) {
|
||||||
}));
|
anchor.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
} else {
|
||||||
|
// Use MutationObserver to wait for the element if it's not immediately available
|
||||||
|
new MutationObserver((mutations, obs)=>{
|
||||||
|
anchor = iframeDoc.querySelector(hash);
|
||||||
|
if(anchor) {
|
||||||
|
anchor.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
obs.disconnect();
|
||||||
|
}
|
||||||
|
}).observe(iframeDoc, { childList: true, subtree: true });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateCurrentPage = useCallback(_.throttle((e)=>{
|
const updateCurrentPage = useCallback(_.throttle((e)=>{
|
||||||
@@ -117,9 +131,9 @@ const BrewRenderer = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderStyle = ()=>{
|
const renderStyle = ()=>{
|
||||||
const cleanStyle = props.style; //DOMPurify.sanitize(props.style, purifyConfig);
|
|
||||||
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
||||||
return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: `${themeStyles} \n\n <style> ${cleanStyle} </style>` }} />;
|
const cleanStyle = safeHTML(`${themeStyles} \n\n <style> ${props.style} </style>`);
|
||||||
|
return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: cleanStyle }} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderPage = (pageText, index)=>{
|
const renderPage = (pageText, index)=>{
|
||||||
@@ -129,7 +143,13 @@ const BrewRenderer = (props)=>{
|
|||||||
} else {
|
} else {
|
||||||
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
||||||
const html = Markdown.render(pageText, index);
|
const html = Markdown.render(pageText, index);
|
||||||
return <BrewPage className='page' index={index} key={index} contents={html} />;
|
|
||||||
|
const styles = {
|
||||||
|
...(!displayOptions.pageShadows ? { boxShadow: 'none' } : {})
|
||||||
|
// Add more conditions as needed
|
||||||
|
};
|
||||||
|
|
||||||
|
return <BrewPage className='page' index={index} key={index} contents={html} style={styles} />;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -141,7 +161,8 @@ const BrewRenderer = (props)=>{
|
|||||||
renderedPages.length = 0;
|
renderedPages.length = 0;
|
||||||
|
|
||||||
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
||||||
renderedPages[props.currentEditorCursorPageNum - 1] = renderPage(rawPages[props.currentEditorCursorPageNum - 1], props.currentEditorCursorPageNum - 1);
|
if(rawPages.length > props.currentEditorCursorPageNum -1)
|
||||||
|
renderedPages[props.currentEditorCursorPageNum - 1] = renderPage(rawPages[props.currentEditorCursorPageNum - 1], props.currentEditorCursorPageNum - 1);
|
||||||
|
|
||||||
_.forEach(rawPages, (page, index)=>{
|
_.forEach(rawPages, (page, index)=>{
|
||||||
if((isInView(index) || !renderedPages[index]) && typeof window !== 'undefined'){
|
if((isInView(index) || !renderedPages[index]) && typeof window !== 'undefined'){
|
||||||
@@ -162,9 +183,9 @@ const BrewRenderer = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
||||||
|
scrollToHash(window.location.hash);
|
||||||
|
|
||||||
setTimeout(()=>{ //We still see a flicker where the style isn't applied yet, so wait 100ms before showing iFrame
|
setTimeout(()=>{ //We still see a flicker where the style isn't applied yet, so wait 100ms before showing iFrame
|
||||||
updateSize();
|
|
||||||
window.addEventListener('resize', updateSize);
|
|
||||||
renderPages(); //Make sure page is renderable before showing
|
renderPages(); //Make sure page is renderable before showing
|
||||||
setState((prevState)=>({
|
setState((prevState)=>({
|
||||||
...prevState,
|
...prevState,
|
||||||
@@ -179,14 +200,25 @@ const BrewRenderer = (props)=>{
|
|||||||
document.dispatchEvent(new MouseEvent('click'));
|
document.dispatchEvent(new MouseEvent('click'));
|
||||||
};
|
};
|
||||||
|
|
||||||
//Toolbar settings:
|
const handleDisplayOptionsChange = (newDisplayOptions)=>{
|
||||||
const handleZoom = (newZoom)=>{
|
setDisplayOptions(newDisplayOptions);
|
||||||
setState((prevState)=>({
|
|
||||||
...prevState,
|
|
||||||
zoom : newZoom
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pagesStyle = {
|
||||||
|
zoom : `${displayOptions.zoomLevel}%`,
|
||||||
|
columnGap : `${displayOptions.columnGap}px`,
|
||||||
|
rowGap : `${displayOptions.rowGap}px`
|
||||||
|
};
|
||||||
|
|
||||||
|
const styleObject = {};
|
||||||
|
|
||||||
|
if(global.config.deployment) {
|
||||||
|
styleObject.backgroundImage = `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='40px' width='200px'><text x='0' y='15' fill='%23fff7' font-size='20'>${global.config.deployment}</text></svg>")`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderedStyle = useMemo(()=>renderStyle(), [props.style, props.themeBundle]);
|
||||||
|
renderedPages = useMemo(()=>renderPages(), [props.text]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/*render dummy page while iFrame is mounting.*/}
|
{/*render dummy page while iFrame is mounting.*/}
|
||||||
@@ -204,7 +236,7 @@ const BrewRenderer = (props)=>{
|
|||||||
<NotificationPopup />
|
<NotificationPopup />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ToolBar onZoomChange={handleZoom} currentPage={props.currentBrewRendererPageNum} totalPages={rawPages.length}/>
|
<ToolBar displayOptions={displayOptions} currentPage={props.currentBrewRendererPageNum} totalPages={rawPages.length} onDisplayOptionsChange={handleDisplayOptionsChange} />
|
||||||
|
|
||||||
{/*render in iFrame so broken code doesn't crash the site.*/}
|
{/*render in iFrame so broken code doesn't crash the site.*/}
|
||||||
<Frame id='BrewRenderer' initialContent={INITIAL_CONTENT}
|
<Frame id='BrewRenderer' initialContent={INITIAL_CONTENT}
|
||||||
@@ -212,19 +244,20 @@ const BrewRenderer = (props)=>{
|
|||||||
contentDidMount={frameDidMount}
|
contentDidMount={frameDidMount}
|
||||||
onClick={()=>{emitClick();}}
|
onClick={()=>{emitClick();}}
|
||||||
>
|
>
|
||||||
<div className={'brewRenderer'}
|
<div className={`brewRenderer ${global.config.deployment && 'deployment'}`}
|
||||||
onScroll={updateCurrentPage}
|
onScroll={updateCurrentPage}
|
||||||
onKeyDown={handleControlKeys}
|
onKeyDown={handleControlKeys}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
style={{ height: state.height }}>
|
style={ styleObject }>
|
||||||
|
|
||||||
{/* Apply CSS from Style tab and render pages from Markdown tab */}
|
{/* Apply CSS from Style tab and render pages from Markdown tab */}
|
||||||
{state.isMounted
|
{state.isMounted
|
||||||
&&
|
&&
|
||||||
<>
|
<>
|
||||||
{renderStyle()}
|
{renderedStyle}
|
||||||
<div className='pages' lang={`${props.lang || 'en'}`} style={{ zoom: `${state.zoom}%` }}>
|
<div lang={`${props.lang || 'en'}`} style={pagesStyle} className={
|
||||||
{renderPages()}
|
`pages ${displayOptions.startOnRight ? 'recto' : 'verso'} ${displayOptions.spread}` } >
|
||||||
|
{renderedPages}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,45 @@
|
|||||||
.brewRenderer {
|
.brewRenderer {
|
||||||
overflow-y : scroll;
|
overflow-y : scroll;
|
||||||
will-change : transform;
|
will-change : transform;
|
||||||
padding-top : 30px;
|
padding-top : 60px;
|
||||||
|
height : 100vh;
|
||||||
|
&:has(.facing, .flow) {
|
||||||
|
padding : 60px 30px;
|
||||||
|
}
|
||||||
|
&.deployment {
|
||||||
|
background-color: darkred;
|
||||||
|
}
|
||||||
:where(.pages) {
|
:where(.pages) {
|
||||||
margin : 30px 0px;
|
&.facing {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, auto);
|
||||||
|
grid-template-rows: repeat(3, auto);
|
||||||
|
gap: 10px 10px;
|
||||||
|
justify-content: center;
|
||||||
|
&.recto .page:first-child {
|
||||||
|
// sets first page on 'right' ('recto') of the preview, as if for a Cover page.
|
||||||
|
// todo: add a checkbox to toggle this setting
|
||||||
|
grid-column-start: 2;
|
||||||
|
}
|
||||||
|
& :where(.page) {
|
||||||
|
margin-left: unset !important;
|
||||||
|
margin-right: unset !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.flow {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
justify-content: flex-start;
|
||||||
|
& :where(.page) {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-left: unset !important;
|
||||||
|
margin-right: unset !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
& > :where(.page) {
|
& > :where(.page) {
|
||||||
width : 215.9mm;
|
width : 215.9mm;
|
||||||
height : 279.4mm;
|
height : 279.4mm;
|
||||||
@@ -14,6 +50,9 @@
|
|||||||
margin-left : auto;
|
margin-left : auto;
|
||||||
box-shadow : 1px 4px 14px #000000;
|
box-shadow : 1px 4px 14px #000000;
|
||||||
}
|
}
|
||||||
|
*[id] {
|
||||||
|
scroll-margin-top:100px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&::-webkit-scrollbar {
|
&::-webkit-scrollbar {
|
||||||
width : 20px;
|
width : 20px;
|
||||||
@@ -39,6 +78,7 @@
|
|||||||
overflow-y : unset;
|
overflow-y : unset;
|
||||||
.pages {
|
.pages {
|
||||||
margin : 0px;
|
margin : 0px;
|
||||||
|
zoom: 100% !important;
|
||||||
& > .page { box-shadow : unset; }
|
& > .page { box-shadow : unset; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,62 @@
|
|||||||
require('./notificationPopup.less');
|
require('./notificationPopup.less');
|
||||||
const React = require('react');
|
import React, { useEffect, useState } from 'react';
|
||||||
const _ = require('lodash');
|
const request = require('../../utils/request-middleware.js');
|
||||||
|
|
||||||
import Dialog from '../../../components/dialog.jsx';
|
import Dialog from '../../../components/dialog.jsx';
|
||||||
|
|
||||||
const DISMISS_KEY = 'dismiss_notification04-09-24';
|
|
||||||
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
||||||
|
|
||||||
const NotificationPopup = ()=>{
|
const NotificationPopup = ()=>{
|
||||||
return <Dialog className='notificationPopup' dismissKey={DISMISS_KEY} closeText={DISMISS_BUTTON} >
|
const [notifications, setNotifications] = useState([]);
|
||||||
|
const [dissmissKeyList, setDismissKeyList] = useState([]);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
getNotifications();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getNotifications = async ()=>{
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await request.get('/admin/notification/all');
|
||||||
|
pickActiveNotifications(res.body || []);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setError(`Error looking up notifications: ${err?.response?.body?.message || err.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const pickActiveNotifications = (notifs)=>{
|
||||||
|
const now = new Date();
|
||||||
|
const filteredNotifications = notifs.filter((notification)=>{
|
||||||
|
const startDate = new Date(notification.startAt);
|
||||||
|
const stopDate = new Date(notification.stopAt);
|
||||||
|
const dismissed = localStorage.getItem(notification.dismissKey) ? true : false;
|
||||||
|
return now >= startDate && now <= stopDate && !dismissed;
|
||||||
|
});
|
||||||
|
setNotifications(filteredNotifications);
|
||||||
|
setDismissKeyList(filteredNotifications.map((notif)=>notif.dismissKey));
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderNotificationsList = ()=>{
|
||||||
|
if(error) return <div className='error'>{error}</div>;
|
||||||
|
|
||||||
|
return notifications.map((notification)=>(
|
||||||
|
<li key={notification.dismissKey} >
|
||||||
|
<em>{notification.title}</em><br />
|
||||||
|
<p dangerouslySetInnerHTML={{ __html: notification.text }}></p>
|
||||||
|
</li>
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
return <Dialog className='notificationPopup' dismisskeys={dissmissKeyList} closeText={DISMISS_BUTTON} >
|
||||||
<div className='header'>
|
<div className='header'>
|
||||||
<i className='fas fa-info-circle info'></i>
|
<i className='fas fa-info-circle info'></i>
|
||||||
<h3>Notice</h3>
|
<h3>Notice</h3>
|
||||||
<small>This website is always improving and we are still adding new features and squashing bugs. Keep the following in mind:</small>
|
<small>This website is always improving and we are still adding new features and squashing bugs. Keep the following in mind:</small>
|
||||||
</div>
|
</div>
|
||||||
<ul>
|
<ul>
|
||||||
<li key='Vault'>
|
{renderNotificationsList()}
|
||||||
<em>Search brews with our new page!</em><br />
|
|
||||||
We have been working very hard in making this possible, now you can share your work and look at it in the new <a href='/vault'>Vault</a> page!
|
|
||||||
All PUBLISHED brews will be available to anyone searching there, by title or author, and filtering by renderer.
|
|
||||||
|
|
||||||
More features will be coming.
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li key='googleDriveFolder'>
|
|
||||||
<em>Don't delete your Homebrewery folder on Google Drive!</em> <br />
|
|
||||||
We have had several reports of users losing their brews, not realizing
|
|
||||||
that they had deleted the files on their Google Drive. If you have a Homebrewery folder
|
|
||||||
on your Google Drive with *.txt files inside, <em>do not delete it</em>!
|
|
||||||
We cannot help you recover files that you have deleted from your own
|
|
||||||
Google Drive.
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li key='faq'>
|
|
||||||
<em>Protect your work! </em> <br />
|
|
||||||
If you opt not to use your Google Drive, keep in mind that we do not save a history of your projects. Please make frequent backups of your brews!
|
|
||||||
<a target='_blank' href='https://www.reddit.com/r/homebrewery/comments/adh6lh/faqs_psas_announcements/'>
|
|
||||||
See the FAQ
|
|
||||||
</a> to learn how to avoid losing your work!
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</Dialog>;
|
</Dialog>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,7 +55,10 @@
|
|||||||
margin-top : 1.4em;
|
margin-top : 1.4em;
|
||||||
font-size : 0.8em;
|
font-size : 0.8em;
|
||||||
line-height : 1.4em;
|
line-height : 1.4em;
|
||||||
em { font-weight : 800; }
|
em {
|
||||||
|
text-transform:capitalize;
|
||||||
|
font-weight : 800;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
client/homebrew/brewRenderer/safeHTML.js
Normal file
46
client/homebrew/brewRenderer/safeHTML.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// Derived from the vue-html-secure package, customized for Homebrewery
|
||||||
|
|
||||||
|
let doc = null;
|
||||||
|
let div = null;
|
||||||
|
|
||||||
|
function safeHTML(htmlString) {
|
||||||
|
// If the Document interface doesn't exist, exit
|
||||||
|
if(typeof document == 'undefined') return null;
|
||||||
|
// If the test document and div don't exist, create them
|
||||||
|
if(!doc) doc = document.implementation.createHTMLDocument('');
|
||||||
|
if(!div) div = doc.createElement('div');
|
||||||
|
|
||||||
|
// Set the test div contents to the evaluation string
|
||||||
|
div.innerHTML = htmlString;
|
||||||
|
// Grab all nodes from the test div
|
||||||
|
const elements = div.querySelectorAll('*');
|
||||||
|
|
||||||
|
// Blacklisted tags
|
||||||
|
const blacklistTags = ['script', 'noscript', 'noembed'];
|
||||||
|
// Tests to remove attributes
|
||||||
|
const blacklistAttrs = [
|
||||||
|
(test)=>{return test.localName.indexOf('on') == 0;},
|
||||||
|
(test)=>{return test.localName.indexOf('type') == 0 && test.value.match(/submit/i);},
|
||||||
|
(test)=>{return test.value.replace(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g, '').toLowerCase().trim().indexOf('javascript:') == 0;}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
elements.forEach((element)=>{
|
||||||
|
// Check each element for blacklisted type
|
||||||
|
if(blacklistTags.includes(element?.localName?.toLowerCase())) {
|
||||||
|
element.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Check remaining elements for blacklisted attributes
|
||||||
|
for (const attribute of element.attributes){
|
||||||
|
if(blacklistAttrs.some((test)=>{return test(attribute);})) {
|
||||||
|
element.removeAttribute(attribute.localName);
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return div.innerHTML;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.safeHTML = safeHTML;
|
||||||
@@ -3,26 +3,28 @@ const React = require('react');
|
|||||||
const { useState, useEffect } = React;
|
const { useState, useEffect } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
import { Anchored, AnchoredBox, AnchoredTrigger } from '../../../components/Anchored.jsx';
|
||||||
|
// import * as ZoomIcons from '../../../icons/icon-components/zoomIcons.jsx';
|
||||||
|
|
||||||
const MAX_ZOOM = 300;
|
const MAX_ZOOM = 300;
|
||||||
const MIN_ZOOM = 10;
|
const MIN_ZOOM = 10;
|
||||||
|
|
||||||
const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
const ToolBar = ({ displayOptions, currentPage, totalPages, onDisplayOptionsChange })=>{
|
||||||
|
|
||||||
const [zoomLevel, setZoomLevel] = useState(100);
|
const [pageNum, setPageNum] = useState(currentPage);
|
||||||
const [pageNum, setPageNum] = useState(currentPage);
|
|
||||||
const [toolsVisible, setToolsVisible] = useState(true);
|
const [toolsVisible, setToolsVisible] = useState(true);
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
onZoomChange(zoomLevel);
|
|
||||||
}, [zoomLevel]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
setPageNum(currentPage);
|
setPageNum(currentPage);
|
||||||
}, [currentPage]);
|
}, [currentPage]);
|
||||||
|
|
||||||
const handleZoomButton = (zoom)=>{
|
const handleZoomButton = (zoom)=>{
|
||||||
setZoomLevel(_.round(_.clamp(zoom, MIN_ZOOM, MAX_ZOOM)));
|
handleOptionChange('zoomLevel', _.round(_.clamp(zoom, MIN_ZOOM, MAX_ZOOM)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOptionChange = (optionKey, newValue)=>{
|
||||||
|
//setDisplayOptions(prevOptions => ({ ...prevOptions, [optionKey]: newValue }));
|
||||||
|
onDisplayOptionsChange({ ...displayOptions, [optionKey]: newValue });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePageInput = (pageInput)=>{
|
const handlePageInput = (pageInput)=>{
|
||||||
@@ -63,47 +65,51 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|||||||
|
|
||||||
const margin = 5; // extra space so page isn't edge to edge (not truly "to fill")
|
const margin = 5; // extra space so page isn't edge to edge (not truly "to fill")
|
||||||
|
|
||||||
const deltaZoom = (desiredZoom - zoomLevel) - margin;
|
const deltaZoom = (desiredZoom - displayOptions.zoomLevel) - margin;
|
||||||
return deltaZoom;
|
return deltaZoom;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`toolBar ${toolsVisible ? 'visible' : 'hidden'}`}>
|
<div id='preview-toolbar' className={`toolBar ${toolsVisible ? 'visible' : 'hidden'}`} role='toolbar'>
|
||||||
<button className='toggleButton' title={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`} onClick={()=>{setToolsVisible(!toolsVisible);}}><i className='fas fa-glasses' /></button>
|
<button className='toggleButton' title={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`} onClick={()=>{setToolsVisible(!toolsVisible);}}><i className='fas fa-glasses' /></button>
|
||||||
{/*v=====----------------------< Zoom Controls >---------------------=====v*/}
|
{/*v=====----------------------< Zoom Controls >---------------------=====v*/}
|
||||||
<div className='group'>
|
<div className='group' role='group' aria-label='Zoom' aria-hidden={!toolsVisible}>
|
||||||
<button
|
<button
|
||||||
id='fill-width'
|
id='fill-width'
|
||||||
className='tool'
|
className='tool'
|
||||||
onClick={()=>handleZoomButton(zoomLevel + calculateChange('fill'))}
|
title='Set zoom to fill preview with one page'
|
||||||
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel + calculateChange('fill'))}
|
||||||
>
|
>
|
||||||
<i className='fac fit-width' />
|
<i className='fac fit-width' />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
id='zoom-to-fit'
|
id='zoom-to-fit'
|
||||||
className='tool'
|
className='tool'
|
||||||
onClick={()=>handleZoomButton(zoomLevel + calculateChange('fit'))}
|
title='Set zoom to fit entire page in preview'
|
||||||
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel + calculateChange('fit'))}
|
||||||
>
|
>
|
||||||
<i className='fac zoom-to-fit' />
|
<i className='fac zoom-to-fit' />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
id='zoom-out'
|
id='zoom-out'
|
||||||
className='tool'
|
className='tool'
|
||||||
onClick={()=>handleZoomButton(zoomLevel - 20)}
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel - 20)}
|
||||||
disabled={zoomLevel <= MIN_ZOOM}
|
disabled={displayOptions.zoomLevel <= MIN_ZOOM}
|
||||||
|
title='Zoom Out'
|
||||||
>
|
>
|
||||||
<i className='fas fa-magnifying-glass-minus' />
|
<i className='fas fa-magnifying-glass-minus' />
|
||||||
</button>
|
</button>
|
||||||
<input
|
<input
|
||||||
id='zoom-slider'
|
id='zoom-slider'
|
||||||
className='range-input tool'
|
className='range-input tool hover-tooltip'
|
||||||
type='range'
|
type='range'
|
||||||
name='zoom'
|
name='zoom'
|
||||||
|
title='Set Zoom'
|
||||||
list='zoomLevels'
|
list='zoomLevels'
|
||||||
min={MIN_ZOOM}
|
min={MIN_ZOOM}
|
||||||
max={MAX_ZOOM}
|
max={MAX_ZOOM}
|
||||||
step='1'
|
step='1'
|
||||||
value={zoomLevel}
|
value={displayOptions.zoomLevel}
|
||||||
onChange={(e)=>handleZoomButton(parseInt(e.target.value))}
|
onChange={(e)=>handleZoomButton(parseInt(e.target.value))}
|
||||||
/>
|
/>
|
||||||
<datalist id='zoomLevels'>
|
<datalist id='zoomLevels'>
|
||||||
@@ -113,18 +119,72 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|||||||
<button
|
<button
|
||||||
id='zoom-in'
|
id='zoom-in'
|
||||||
className='tool'
|
className='tool'
|
||||||
onClick={()=>handleZoomButton(zoomLevel + 20)}
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel + 20)}
|
||||||
disabled={zoomLevel >= MAX_ZOOM}
|
disabled={displayOptions.zoomLevel >= MAX_ZOOM}
|
||||||
|
title='Zoom In'
|
||||||
>
|
>
|
||||||
<i className='fas fa-magnifying-glass-plus' />
|
<i className='fas fa-magnifying-glass-plus' />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/*v=====----------------------< Spread Controls >---------------------=====v*/}
|
||||||
|
<div className='group' role='group' aria-label='Spread' aria-hidden={!toolsVisible}>
|
||||||
|
<div className='radio-group' role='radiogroup'>
|
||||||
|
<button role='radio'
|
||||||
|
id='single-spread'
|
||||||
|
className='tool'
|
||||||
|
title='Single Page'
|
||||||
|
onClick={()=>{handleOptionChange('spread', 'active');}}
|
||||||
|
aria-checked={displayOptions.spread === 'single'}
|
||||||
|
><i className='fac single-spread' /></button>
|
||||||
|
<button role='radio'
|
||||||
|
id='facing-spread'
|
||||||
|
className='tool'
|
||||||
|
title='Facing Pages'
|
||||||
|
onClick={()=>{handleOptionChange('spread', 'facing');}}
|
||||||
|
aria-checked={displayOptions.spread === 'facing'}
|
||||||
|
><i className='fac facing-spread' /></button>
|
||||||
|
<button role='radio'
|
||||||
|
id='flow-spread'
|
||||||
|
className='tool'
|
||||||
|
title='Flow Pages'
|
||||||
|
onClick={()=>{handleOptionChange('spread', 'flow');}}
|
||||||
|
aria-checked={displayOptions.spread === 'flow'}
|
||||||
|
><i className='fac flow-spread' /></button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<Anchored>
|
||||||
|
<AnchoredTrigger id='spread-settings' className='tool' title='Spread options'><i className='fas fa-gear' /></AnchoredTrigger>
|
||||||
|
<AnchoredBox title='Options'>
|
||||||
|
<h1>Options</h1>
|
||||||
|
<label title='Modify the horizontal space between pages.'>
|
||||||
|
Column gap
|
||||||
|
<input type='range' min={0} max={200} defaultValue={10} className='range-input' onChange={(evt)=>handleOptionChange('columnGap', evt.target.value)} />
|
||||||
|
</label>
|
||||||
|
<label title='Modify the vertical space between rows of pages.'>
|
||||||
|
Row gap
|
||||||
|
<input type='range' min={0} max={200} defaultValue={10} className='range-input' onChange={(evt)=>handleOptionChange('rowGap', evt.target.value)} />
|
||||||
|
</label>
|
||||||
|
<label title='Start 1st page on the right side, such as if you have cover page.'>
|
||||||
|
Start on right
|
||||||
|
<input type='checkbox' checked={displayOptions.startOnRight} onChange={()=>{handleOptionChange('startOnRight', !displayOptions.startOnRight);}}
|
||||||
|
title={displayOptions.spread !== 'facing' ? 'Switch to Facing to enable toggle.' : null} />
|
||||||
|
</label>
|
||||||
|
<label title='Toggle the page shadow on every page.'>
|
||||||
|
Page shadows
|
||||||
|
<input type='checkbox' checked={displayOptions.pageShadows} onChange={()=>{handleOptionChange('pageShadows', !displayOptions.pageShadows);}} />
|
||||||
|
</label>
|
||||||
|
</AnchoredBox>
|
||||||
|
</Anchored>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/*v=====----------------------< Page Controls >---------------------=====v*/}
|
{/*v=====----------------------< Page Controls >---------------------=====v*/}
|
||||||
<div className='group'>
|
<div className='group' role='group' aria-label='Pages' aria-hidden={!toolsVisible}>
|
||||||
<button
|
<button
|
||||||
id='previous-page'
|
id='previous-page'
|
||||||
className='previousPage tool'
|
className='previousPage tool'
|
||||||
|
type='button'
|
||||||
|
title='Previous Page(s)'
|
||||||
onClick={()=>scrollToPage(pageNum - 1)}
|
onClick={()=>scrollToPage(pageNum - 1)}
|
||||||
disabled={pageNum <= 1}
|
disabled={pageNum <= 1}
|
||||||
>
|
>
|
||||||
@@ -137,6 +197,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|||||||
className='text-input'
|
className='text-input'
|
||||||
type='text'
|
type='text'
|
||||||
name='page'
|
name='page'
|
||||||
|
title='Current page(s) in view'
|
||||||
inputMode='numeric'
|
inputMode='numeric'
|
||||||
pattern='[0-9]'
|
pattern='[0-9]'
|
||||||
value={pageNum}
|
value={pageNum}
|
||||||
@@ -145,12 +206,14 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
|||||||
onBlur={()=>scrollToPage(pageNum)}
|
onBlur={()=>scrollToPage(pageNum)}
|
||||||
onKeyDown={(e)=>e.key == 'Enter' && scrollToPage(pageNum)}
|
onKeyDown={(e)=>e.key == 'Enter' && scrollToPage(pageNum)}
|
||||||
/>
|
/>
|
||||||
<span id='page-count'>/ {totalPages}</span>
|
<span id='page-count' title='Total Page Count'>/ {totalPages}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
id='next-page'
|
id='next-page'
|
||||||
className='tool'
|
className='tool'
|
||||||
|
type='button'
|
||||||
|
title='Next Page(s)'
|
||||||
onClick={()=>scrollToPage(pageNum + 1)}
|
onClick={()=>scrollToPage(pageNum + 1)}
|
||||||
disabled={pageNum >= totalPages}
|
disabled={pageNum >= totalPages}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -13,11 +13,12 @@
|
|||||||
height : auto;
|
height : auto;
|
||||||
padding : 2px 0;
|
padding : 2px 0;
|
||||||
font-family : 'Open Sans', sans-serif;
|
font-family : 'Open Sans', sans-serif;
|
||||||
|
font-size : 13px;
|
||||||
color : #CCCCCC;
|
color : #CCCCCC;
|
||||||
background-color : #555555;
|
background-color : #555555;
|
||||||
& > *:not(.toggleButton) {
|
& > *:not(.toggleButton) {
|
||||||
opacity: 1;
|
opacity : 1;
|
||||||
transition: all .2s ease;
|
transition : all 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.group {
|
.group {
|
||||||
@@ -34,6 +35,70 @@
|
|||||||
align-items : center;
|
align-items : center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.active, [aria-checked='true'] { background-color : #444444; }
|
||||||
|
|
||||||
|
.anchored-trigger {
|
||||||
|
&.active { background-color : #444444; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.anchored-box {
|
||||||
|
--box-color : #555555;
|
||||||
|
top : 30px;
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
gap : 5px;
|
||||||
|
padding : 15px;
|
||||||
|
margin-top : 10px;
|
||||||
|
font-size : 0.8em;
|
||||||
|
color : #CCCCCC;
|
||||||
|
background-color : var(--box-color);
|
||||||
|
border-radius : 5px;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
padding-bottom : 0.3em;
|
||||||
|
margin-bottom : 0.5em;
|
||||||
|
border-bottom : 1px solid currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
padding-bottom : 0.3em;
|
||||||
|
margin : 1em 0 0.5em 0;
|
||||||
|
color : lightgray;
|
||||||
|
border-bottom : 1px solid currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display : flex;
|
||||||
|
gap : 6px;
|
||||||
|
align-items : center;
|
||||||
|
justify-content : space-between;
|
||||||
|
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
height : unset;
|
||||||
|
&[type='range'] { padding : 0; }
|
||||||
|
}
|
||||||
|
&::before {
|
||||||
|
position : absolute;
|
||||||
|
top : -20px;
|
||||||
|
left : 50%;
|
||||||
|
width : 0px;
|
||||||
|
height : 0px;
|
||||||
|
pointer-events : none;
|
||||||
|
content : '';
|
||||||
|
border : 10px solid transparent;
|
||||||
|
border-bottom : 10px solid var(--box-color);
|
||||||
|
transform : translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-group:has(button[role='radio']) {
|
||||||
|
display : flex;
|
||||||
|
height : 100%;
|
||||||
|
border : 1px solid #333333;
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
position : relative;
|
position : relative;
|
||||||
height : 1.5em;
|
height : 1.5em;
|
||||||
@@ -57,7 +122,7 @@
|
|||||||
outline : none;
|
outline : none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover::after {
|
&.hover-tooltip[value]:hover::after {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
bottom : -30px;
|
bottom : -30px;
|
||||||
left : 50%;
|
left : 50%;
|
||||||
@@ -83,46 +148,40 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
box-sizing : content-box;
|
box-sizing : border-box;
|
||||||
display : flex;
|
display : flex;
|
||||||
align-items : center;
|
align-items : center;
|
||||||
justify-content : center;
|
justify-content : center;
|
||||||
width : auto;
|
width : auto;
|
||||||
min-width : 46px;
|
min-width : 46px;
|
||||||
height : 100%;
|
height : 100%;
|
||||||
padding : 0 0px;
|
|
||||||
font-weight : unset;
|
|
||||||
color : inherit;
|
|
||||||
background-color : unset;
|
|
||||||
&:hover { background-color : #444444; }
|
&:hover { background-color : #444444; }
|
||||||
&:focus { outline : 1px solid #D3D3D3; }
|
&:focus { border : 1px solid #D3D3D3;outline : none;}
|
||||||
&:disabled {
|
&:disabled {
|
||||||
color : #777777;
|
color : #777777;
|
||||||
background-color : unset !important;
|
background-color : unset !important;
|
||||||
}
|
}
|
||||||
i {
|
i { font-size : 1.2em; }
|
||||||
font-size:1.2em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.hidden {
|
&.hidden {
|
||||||
width: 32px;
|
flex-wrap : nowrap;
|
||||||
transition: all .3s ease;
|
width : 32px;
|
||||||
flex-wrap:nowrap;
|
overflow : hidden;
|
||||||
overflow: hidden;
|
background-color : unset;
|
||||||
background-color: unset;
|
opacity : 0.5;
|
||||||
opacity: .5;
|
transition : all 0.3s ease;
|
||||||
& > *:not(.toggleButton) {
|
& > *:not(.toggleButton) {
|
||||||
opacity: 0;
|
opacity : 0;
|
||||||
transition: all .2s ease;
|
transition : all 0.2s ease;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button.toggleButton {
|
button.toggleButton {
|
||||||
z-index : 5;
|
position : absolute;
|
||||||
position:absolute;
|
left : 0;
|
||||||
left: 0;
|
z-index : 5;
|
||||||
width: 32px;
|
width : 32px;
|
||||||
min-width: unset;
|
min-width : unset;
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
brewJump : function(targetPage=this.props.currentEditorCursorPageNum, smooth=true){
|
brewJump : function(targetPage=this.props.currentEditorCursorPageNum, smooth=true){
|
||||||
if(!window || isJumping)
|
if(!window || !this.isText() || isJumping)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get current brewRenderer scroll position and calculate target position
|
// Get current brewRenderer scroll position and calculate target position
|
||||||
@@ -355,7 +355,7 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){
|
sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){
|
||||||
if(!this.isText || isJumping)
|
if(!this.isText() || isJumping)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const textSplit = this.props.renderer == 'V3' ? /^\\page$/gm : /\\page/;
|
const textSplit = this.props.renderer == 'V3' ? /^\\page$/gm : /\\page/;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
.editor {
|
.editor {
|
||||||
position : relative;
|
position : relative;
|
||||||
width : 100%;
|
width : 100%;
|
||||||
|
container: editor / inline-size;
|
||||||
|
|
||||||
.codeEditor {
|
.codeEditor {
|
||||||
height : 100%;
|
height : 100%;
|
||||||
|
|||||||
@@ -79,6 +79,7 @@
|
|||||||
text-overflow : ellipsis;
|
text-overflow : ellipsis;
|
||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
|
.colorButton();
|
||||||
padding : 0px 5px;
|
padding : 0px 5px;
|
||||||
color : white;
|
color : white;
|
||||||
background-color : black;
|
background-color : black;
|
||||||
@@ -138,16 +139,16 @@
|
|||||||
margin-bottom : 15px;
|
margin-bottom : 15px;
|
||||||
button { width : 100%; }
|
button { width : 100%; }
|
||||||
button.publish {
|
button.publish {
|
||||||
.button(@blueLight);
|
.colorButton(@blueLight);
|
||||||
}
|
}
|
||||||
button.unpublish {
|
button.unpublish {
|
||||||
.button(@silver);
|
.colorButton(@silver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete.field .value {
|
.delete.field .value {
|
||||||
button {
|
button {
|
||||||
.button(@red);
|
.colorButton(@red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.authors.field .value {
|
.authors.field .value {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 250, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./snippetbar.less');
|
require('./snippetbar.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
import { getHistoryItems, historyExists } from '../../utils/versionHistory.js';
|
import { loadHistory } from '../../utils/versionHistory.js';
|
||||||
|
|
||||||
//Import all themes
|
//Import all themes
|
||||||
const ThemeSnippets = {};
|
const ThemeSnippets = {};
|
||||||
@@ -50,30 +50,47 @@ const Snippetbar = createClass({
|
|||||||
renderer : this.props.renderer,
|
renderer : this.props.renderer,
|
||||||
themeSelector : false,
|
themeSelector : false,
|
||||||
snippets : [],
|
snippets : [],
|
||||||
historyExists : false
|
showHistory : false,
|
||||||
|
historyExists : false,
|
||||||
|
historyItems : []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount : async function() {
|
componentDidMount : async function(prevState) {
|
||||||
const snippets = this.compileSnippets();
|
const snippets = this.compileSnippets();
|
||||||
this.setState({
|
this.setState({
|
||||||
snippets : snippets
|
snippets : snippets
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate : async function(prevProps) {
|
componentDidUpdate : async function(prevProps, prevState) {
|
||||||
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme || prevProps.snippetBundle != this.props.snippetBundle) {
|
if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme || prevProps.snippetBundle != this.props.snippetBundle) {
|
||||||
this.setState({
|
this.setState({
|
||||||
snippets : this.compileSnippets()
|
snippets : this.compileSnippets()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if(historyExists(this.props.brew) != this.state.historyExists){
|
// Update history list if it has changed
|
||||||
this.setState({
|
const checkHistoryItems = await loadHistory(this.props.brew);
|
||||||
historyExists : !this.state.historyExists
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// If all items have the noData property, there is no saved data
|
||||||
|
const checkHistoryExists = !checkHistoryItems.every((historyItem)=>{
|
||||||
|
return historyItem?.noData;
|
||||||
|
});
|
||||||
|
if(prevState.historyExists != checkHistoryExists){
|
||||||
|
this.setState({
|
||||||
|
historyExists : checkHistoryExists
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If any history items have changed, update the list
|
||||||
|
if(checkHistoryExists && checkHistoryItems.some((historyItem, index)=>{
|
||||||
|
return index >= prevState.historyItems.length || !_.isEqual(historyItem, prevState.historyItems[index]);
|
||||||
|
})){
|
||||||
|
this.setState({
|
||||||
|
historyItems : checkHistoryItems
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mergeCustomizer : function(oldValue, newValue, key) {
|
mergeCustomizer : function(oldValue, newValue, key) {
|
||||||
@@ -133,30 +150,40 @@ const Snippetbar = createClass({
|
|||||||
|
|
||||||
renderSnippetGroups : function(){
|
renderSnippetGroups : function(){
|
||||||
const snippets = this.state.snippets.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
const snippets = this.state.snippets.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
||||||
|
if(snippets.length === 0) return null;
|
||||||
|
|
||||||
return _.map(snippets, (snippetGroup)=>{
|
return <div className='snippets'>
|
||||||
return <SnippetGroup
|
{_.map(snippets, (snippetGroup)=>{
|
||||||
brew={this.props.brew}
|
return <SnippetGroup
|
||||||
groupName={snippetGroup.groupName}
|
brew={this.props.brew}
|
||||||
icon={snippetGroup.icon}
|
groupName={snippetGroup.groupName}
|
||||||
snippets={snippetGroup.snippets}
|
icon={snippetGroup.icon}
|
||||||
key={snippetGroup.groupName}
|
snippets={snippetGroup.snippets}
|
||||||
onSnippetClick={this.handleSnippetClick}
|
key={snippetGroup.groupName}
|
||||||
cursorPos={this.props.cursorPos}
|
onSnippetClick={this.handleSnippetClick}
|
||||||
/>;
|
cursorPos={this.props.cursorPos}
|
||||||
});
|
/>;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>;
|
||||||
},
|
},
|
||||||
|
|
||||||
replaceContent : function(item){
|
replaceContent : function(item){
|
||||||
return this.props.updateBrew(item);
|
return this.props.updateBrew(item);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggleHistoryMenu : function(){
|
||||||
|
this.setState({
|
||||||
|
showHistory : !this.state.showHistory
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
renderHistoryItems : function() {
|
renderHistoryItems : function() {
|
||||||
const historyItems = getHistoryItems(this.props.brew);
|
if(!this.state.historyExists) return;
|
||||||
|
|
||||||
return <div className='dropdown'>
|
return <div className='dropdown'>
|
||||||
{_.map(historyItems, (item, index)=>{
|
{_.map(this.state.historyItems, (item, index)=>{
|
||||||
if(!item.savedAt) return;
|
if(item.noData || !item.savedAt) return;
|
||||||
|
|
||||||
const saveTime = new Date(item.savedAt);
|
const saveTime = new Date(item.savedAt);
|
||||||
const diffMs = new Date() - saveTime;
|
const diffMs = new Date() - saveTime;
|
||||||
@@ -180,56 +207,58 @@ const Snippetbar = createClass({
|
|||||||
renderEditorButtons : function(){
|
renderEditorButtons : function(){
|
||||||
if(!this.props.showEditButtons) return;
|
if(!this.props.showEditButtons) return;
|
||||||
|
|
||||||
let foldButtons;
|
const foldButtons = <>
|
||||||
if(this.props.view == 'text'){
|
<div className={`editorTool foldAll ${this.props.view !== 'meta' && this.props.foldCode ? 'active' : ''}`}
|
||||||
foldButtons =
|
onClick={this.props.foldCode} >
|
||||||
<>
|
<i className='fas fa-compress-alt' />
|
||||||
<div className={`editorTool foldAll ${this.props.foldCode ? 'active' : ''}`}
|
</div>
|
||||||
onClick={this.props.foldCode} >
|
<div className={`editorTool unfoldAll ${this.props.view !== 'meta' && this.props.unfoldCode ? 'active' : ''}`}
|
||||||
<i className='fas fa-compress-alt' />
|
onClick={this.props.unfoldCode} >
|
||||||
</div>
|
<i className='fas fa-expand-alt' />
|
||||||
<div className={`editorTool unfoldAll ${this.props.unfoldCode ? 'active' : ''}`}
|
</div>
|
||||||
onClick={this.props.unfoldCode} >
|
</>;
|
||||||
<i className='fas fa-expand-alt' />
|
|
||||||
</div>
|
|
||||||
</>;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div className='editors'>
|
return <div className='editors'>
|
||||||
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`} >
|
<div className='historyTools'>
|
||||||
<i className='fas fa-clock-rotate-left' />
|
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
||||||
{this.state.historyExists && this.renderHistoryItems() }
|
onClick={this.toggleHistoryMenu} >
|
||||||
|
<i className='fas fa-clock-rotate-left' />
|
||||||
|
{ this.state.showHistory && this.renderHistoryItems() }
|
||||||
|
</div>
|
||||||
|
<div className={`editorTool undo ${this.props.historySize.undo ? 'active' : ''}`}
|
||||||
|
onClick={this.props.undo} >
|
||||||
|
<i className='fas fa-undo' />
|
||||||
|
</div>
|
||||||
|
<div className={`editorTool redo ${this.props.historySize.redo ? 'active' : ''}`}
|
||||||
|
onClick={this.props.redo} >
|
||||||
|
<i className='fas fa-redo' />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={`editorTool undo ${this.props.historySize.undo ? 'active' : ''}`}
|
<div className='codeTools'>
|
||||||
onClick={this.props.undo} >
|
{foldButtons}
|
||||||
<i className='fas fa-undo' />
|
<div className={`editorTool editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
||||||
</div>
|
onClick={this.toggleThemeSelector} >
|
||||||
<div className={`editorTool redo ${this.props.historySize.redo ? 'active' : ''}`}
|
<i className='fas fa-palette' />
|
||||||
onClick={this.props.redo} >
|
{this.state.themeSelector && this.renderThemeSelector()}
|
||||||
<i className='fas fa-redo' />
|
</div>
|
||||||
</div>
|
|
||||||
<div className='divider'></div>
|
|
||||||
{foldButtons}
|
|
||||||
<div className={`editorTool editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
|
||||||
onClick={this.toggleThemeSelector} >
|
|
||||||
<i className='fas fa-palette' />
|
|
||||||
{this.state.themeSelector && this.renderThemeSelector()}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='divider'></div>
|
|
||||||
<div className={cx('text', { selected: this.props.view === 'text' })}
|
<div className='tabs'>
|
||||||
onClick={()=>this.props.onViewChange('text')}>
|
<div className={cx('text', { selected: this.props.view === 'text' })}
|
||||||
<i className='fa fa-beer' />
|
onClick={()=>this.props.onViewChange('text')}>
|
||||||
</div>
|
<i className='fa fa-beer' />
|
||||||
<div className={cx('style', { selected: this.props.view === 'style' })}
|
</div>
|
||||||
onClick={()=>this.props.onViewChange('style')}>
|
<div className={cx('style', { selected: this.props.view === 'style' })}
|
||||||
<i className='fa fa-paint-brush' />
|
onClick={()=>this.props.onViewChange('style')}>
|
||||||
</div>
|
<i className='fa fa-paint-brush' />
|
||||||
<div className={cx('meta', { selected: this.props.view === 'meta' })}
|
</div>
|
||||||
onClick={()=>this.props.onViewChange('meta')}>
|
<div className={cx('meta', { selected: this.props.view === 'meta' })}
|
||||||
<i className='fas fa-info-circle' />
|
onClick={()=>this.props.onViewChange('meta')}>
|
||||||
|
<i className='fas fa-info-circle' />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>;
|
</div>;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -267,8 +296,9 @@ const SnippetGroup = createClass({
|
|||||||
return _.map(snippets, (snippet)=>{
|
return _.map(snippets, (snippet)=>{
|
||||||
return <div className='snippet' key={snippet.name} onClick={(e)=>this.handleSnippetClick(e, snippet)}>
|
return <div className='snippet' key={snippet.name} onClick={(e)=>this.handleSnippetClick(e, snippet)}>
|
||||||
<i className={snippet.icon} />
|
<i className={snippet.icon} />
|
||||||
<span className='name'title={snippet.name}>{snippet.name}</span>
|
<span className={`name${snippet.disabled ? ' disabled' : ''}`} title={snippet.name}>{snippet.name}</span>
|
||||||
{snippet.experimental && <span className='beta'>beta</span>}
|
{snippet.experimental && <span className='beta'>beta</span>}
|
||||||
|
{snippet.disabled && <span className='beta' title='temporarily disabled due to large slowdown; under re-design'>disabled</span>}
|
||||||
{snippet.subsnippets && <>
|
{snippet.subsnippets && <>
|
||||||
<i className='fas fa-caret-right'></i>
|
<i className='fas fa-caret-right'></i>
|
||||||
<div className='dropdown side'>
|
<div className='dropdown side'>
|
||||||
|
|||||||
@@ -4,97 +4,114 @@
|
|||||||
.snippetBar {
|
.snippetBar {
|
||||||
@menuHeight : 25px;
|
@menuHeight : 25px;
|
||||||
position : relative;
|
position : relative;
|
||||||
height : @menuHeight;
|
display : flex;
|
||||||
|
flex-wrap : wrap-reverse;
|
||||||
|
justify-content : space-between;
|
||||||
|
height : auto;
|
||||||
color : black;
|
color : black;
|
||||||
background-color : #DDDDDD;
|
background-color : #DDDDDD;
|
||||||
|
|
||||||
.editors {
|
.snippets {
|
||||||
position : absolute;
|
|
||||||
top : 0px;
|
|
||||||
right : 0px;
|
|
||||||
display : flex;
|
display : flex;
|
||||||
justify-content : space-between;
|
justify-content : flex-start;
|
||||||
height : @menuHeight;
|
min-width : 327.58px;
|
||||||
& > div {
|
}
|
||||||
width : @menuHeight;
|
|
||||||
height : @menuHeight;
|
.editors {
|
||||||
line-height : @menuHeight;
|
display : flex;
|
||||||
text-align : center;
|
justify-content : flex-end;
|
||||||
cursor : pointer;
|
min-width : 225px;
|
||||||
&:hover,&.selected { background-color : #999999; }
|
|
||||||
&.text {
|
&:only-child { margin-left : auto; }
|
||||||
.tooltipLeft('Brew Editor');
|
|
||||||
}
|
>div {
|
||||||
&.style {
|
display : flex;
|
||||||
.tooltipLeft('Style Editor');
|
flex : 1;
|
||||||
}
|
justify-content : space-around;
|
||||||
&.meta {
|
|
||||||
.tooltipLeft('Properties');
|
&:first-child { border-left : none; }
|
||||||
}
|
|
||||||
&.undo {
|
& > div {
|
||||||
.tooltipLeft('Undo');
|
position : relative;
|
||||||
font-size : 0.75em;
|
width : @menuHeight;
|
||||||
color : grey;
|
height : @menuHeight;
|
||||||
&.active { color : inherit; }
|
line-height : @menuHeight;
|
||||||
}
|
text-align : center;
|
||||||
&.redo {
|
cursor : pointer;
|
||||||
.tooltipLeft('Redo');
|
&:hover,&.selected { background-color : #999999; }
|
||||||
font-size : 0.75em;
|
&.text {
|
||||||
color : grey;
|
.tooltipLeft('Brew Editor');
|
||||||
&.active { color : inherit; }
|
|
||||||
}
|
|
||||||
&.foldAll {
|
|
||||||
.tooltipLeft('Fold All');
|
|
||||||
font-size : 0.75em;
|
|
||||||
color : inherit;
|
|
||||||
}
|
|
||||||
&.unfoldAll {
|
|
||||||
.tooltipLeft('Unfold All');
|
|
||||||
font-size : 0.75em;
|
|
||||||
color : inherit;
|
|
||||||
}
|
|
||||||
&.history {
|
|
||||||
.tooltipLeft('History');
|
|
||||||
font-size : 0.75em;
|
|
||||||
color : grey;
|
|
||||||
position : relative;
|
|
||||||
&.active {
|
|
||||||
color : inherit;
|
|
||||||
}
|
}
|
||||||
&>.dropdown{
|
&.style {
|
||||||
right : -1px;
|
.tooltipLeft('Style Editor');
|
||||||
&>.snippet{
|
}
|
||||||
padding-right : 10px;
|
&.meta {
|
||||||
|
.tooltipLeft('Properties');
|
||||||
|
}
|
||||||
|
&.undo {
|
||||||
|
.tooltipLeft('Undo');
|
||||||
|
font-size : 0.75em;
|
||||||
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
|
}
|
||||||
|
&.redo {
|
||||||
|
.tooltipLeft('Redo');
|
||||||
|
font-size : 0.75em;
|
||||||
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
|
}
|
||||||
|
&.foldAll {
|
||||||
|
.tooltipLeft('Fold All');
|
||||||
|
font-size : 0.75em;
|
||||||
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
|
}
|
||||||
|
&.unfoldAll {
|
||||||
|
.tooltipLeft('Unfold All');
|
||||||
|
font-size : 0.75em;
|
||||||
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
|
}
|
||||||
|
&.history {
|
||||||
|
.tooltipLeft('History');
|
||||||
|
position : relative;
|
||||||
|
font-size : 0.75em;
|
||||||
|
color : grey;
|
||||||
|
border : none;
|
||||||
|
&.active { color : inherit; }
|
||||||
|
& > .dropdown {
|
||||||
|
right : -1px;
|
||||||
|
& > .snippet { padding-right : 10px; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
&.editorTheme {
|
||||||
&.editorTheme {
|
.tooltipLeft('Editor Themes');
|
||||||
.tooltipLeft('Editor Themes');
|
font-size : 0.75em;
|
||||||
font-size : 0.75em;
|
color : black;
|
||||||
color : black;
|
&.active {
|
||||||
&.active {
|
position : relative;
|
||||||
position : relative;
|
background-color : #999999;
|
||||||
background-color : #999999;
|
}
|
||||||
|
}
|
||||||
|
&.divider {
|
||||||
|
width : 5px;
|
||||||
|
background : linear-gradient(currentColor, currentColor) no-repeat center/1px 100%;
|
||||||
|
&:hover { background-color : inherit; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.divider {
|
.themeSelector {
|
||||||
width : 5px;
|
position : absolute;
|
||||||
background : linear-gradient(currentColor, currentColor) no-repeat center/1px 100%;
|
top : 25px;
|
||||||
&:hover { background-color : inherit; }
|
right : 0;
|
||||||
|
z-index : 10;
|
||||||
|
display : flex;
|
||||||
|
align-items : center;
|
||||||
|
justify-content : center;
|
||||||
|
width : 170px;
|
||||||
|
height : inherit;
|
||||||
|
background-color : inherit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.themeSelector {
|
|
||||||
position : absolute;
|
|
||||||
top : 25px;
|
|
||||||
right : 0;
|
|
||||||
z-index : 10;
|
|
||||||
display : flex;
|
|
||||||
align-items : center;
|
|
||||||
justify-content : center;
|
|
||||||
width : 170px;
|
|
||||||
height : inherit;
|
|
||||||
background-color : inherit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.snippetBarButton {
|
.snippetBarButton {
|
||||||
display : inline-block;
|
display : inline-block;
|
||||||
@@ -104,6 +121,7 @@
|
|||||||
font-weight : 800;
|
font-weight : 800;
|
||||||
line-height : @menuHeight;
|
line-height : @menuHeight;
|
||||||
text-transform : uppercase;
|
text-transform : uppercase;
|
||||||
|
text-wrap : nowrap;
|
||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
&:hover, &.selected { background-color : #999999; }
|
&:hover, &.selected { background-color : #999999; }
|
||||||
i {
|
i {
|
||||||
@@ -120,7 +138,7 @@
|
|||||||
.tooltipLeft('Edit Brew Properties');
|
.tooltipLeft('Edit Brew Properties');
|
||||||
}
|
}
|
||||||
.snippetGroup {
|
.snippetGroup {
|
||||||
border-right : 1px solid currentColor;
|
|
||||||
&:hover {
|
&:hover {
|
||||||
& > .dropdown { visibility : visible; }
|
& > .dropdown { visibility : visible; }
|
||||||
}
|
}
|
||||||
@@ -142,11 +160,11 @@
|
|||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
.animate(background-color);
|
.animate(background-color);
|
||||||
i {
|
i {
|
||||||
|
min-width : 25px;
|
||||||
height : 1.2em;
|
height : 1.2em;
|
||||||
margin-right : 8px;
|
margin-right : 8px;
|
||||||
font-size : 1.2em;
|
font-size : 1.2em;
|
||||||
min-width: 25px;
|
text-align : center;
|
||||||
text-align: center;
|
|
||||||
& ~ i {
|
& ~ i {
|
||||||
margin-right : 0;
|
margin-right : 0;
|
||||||
margin-left : 5px;
|
margin-left : 5px;
|
||||||
@@ -179,6 +197,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.name { margin-right : auto; }
|
.name { margin-right : auto; }
|
||||||
|
.disabled { text-decoration : line-through; }
|
||||||
.beta {
|
.beta {
|
||||||
align-self : center;
|
align-self : center;
|
||||||
padding : 4px 6px;
|
padding : 4px 6px;
|
||||||
@@ -205,3 +224,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@container editor (width < 553px) {
|
||||||
|
.snippetBar {
|
||||||
|
.editors {
|
||||||
|
flex : 1;
|
||||||
|
justify-content : space-between;
|
||||||
|
border-bottom : 1px solid;
|
||||||
|
}
|
||||||
|
.snippets {
|
||||||
|
flex : 1;
|
||||||
|
justify-content : space-evenly;
|
||||||
|
}
|
||||||
|
.editors > div.history > .dropdown { right : unset; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const cx = require('classnames');
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
|
|
||||||
const MAX_TITLE_LENGTH = 50;
|
|
||||||
|
|
||||||
|
|
||||||
const EditTitle = createClass({
|
|
||||||
displayName : 'EditTitleNavItem',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
title : '',
|
|
||||||
onChange : function(){}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
handleChange : function(e){
|
|
||||||
if(e.target.value.length > MAX_TITLE_LENGTH) return;
|
|
||||||
this.props.onChange(e.target.value);
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
return <Nav.item className='editTitle'>
|
|
||||||
<input placeholder='Brew Title' type='text' value={this.props.title} onChange={this.handleChange} />
|
|
||||||
|
|
||||||
<div className={cx('charCount', { 'max': this.props.title.length >= MAX_TITLE_LENGTH })}>
|
|
||||||
{this.props.title.length}/{MAX_TITLE_LENGTH}
|
|
||||||
</div>
|
|
||||||
</Nav.item>;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = EditTitle;
|
|
||||||
@@ -25,12 +25,11 @@
|
|||||||
|
|
||||||
.homebrew nav {
|
.homebrew nav {
|
||||||
background-color : #333333;
|
background-color : #333333;
|
||||||
.navContent {
|
position : relative;
|
||||||
position : relative;
|
z-index : 2;
|
||||||
z-index : 2;
|
display : flex;
|
||||||
display : flex;
|
justify-content : space-between;
|
||||||
justify-content : space-between;
|
|
||||||
}
|
|
||||||
.navSection {
|
.navSection {
|
||||||
display : flex;
|
display : flex;
|
||||||
align-items : center;
|
align-items : center;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const RecentItems = createClass({
|
|||||||
//== Add current brew to appropriate recent items list (depending on storageKey) ==//
|
//== Add current brew to appropriate recent items list (depending on storageKey) ==//
|
||||||
if(this.props.storageKey == 'edit'){
|
if(this.props.storageKey == 'edit'){
|
||||||
let editId = this.props.brew.editId;
|
let editId = this.props.brew.editId;
|
||||||
if(this.props.brew.googleId){
|
if(this.props.brew.googleId && !this.props.brew.stubbed){
|
||||||
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
||||||
}
|
}
|
||||||
edited = _.filter(edited, (brew)=>{
|
edited = _.filter(edited, (brew)=>{
|
||||||
@@ -51,7 +51,7 @@ const RecentItems = createClass({
|
|||||||
}
|
}
|
||||||
if(this.props.storageKey == 'view'){
|
if(this.props.storageKey == 'view'){
|
||||||
let shareId = this.props.brew.shareId;
|
let shareId = this.props.brew.shareId;
|
||||||
if(this.props.brew.googleId){
|
if(this.props.brew.googleId && !this.props.brew.stubbed){
|
||||||
shareId = `${this.props.brew.googleId}${this.props.brew.shareId}`;
|
shareId = `${this.props.brew.googleId}${this.props.brew.shareId}`;
|
||||||
}
|
}
|
||||||
viewed = _.filter(viewed, (brew)=>{
|
viewed = _.filter(viewed, (brew)=>{
|
||||||
@@ -83,7 +83,7 @@ const RecentItems = createClass({
|
|||||||
let edited = JSON.parse(localStorage.getItem(EDIT_KEY) || '[]');
|
let edited = JSON.parse(localStorage.getItem(EDIT_KEY) || '[]');
|
||||||
if(this.props.storageKey == 'edit') {
|
if(this.props.storageKey == 'edit') {
|
||||||
let prevEditId = prevProps.brew.editId;
|
let prevEditId = prevProps.brew.editId;
|
||||||
if(prevProps.brew.googleId){
|
if(prevProps.brew.googleId && !this.props.brew.stubbed){
|
||||||
prevEditId = `${prevProps.brew.googleId}${prevProps.brew.editId}`;
|
prevEditId = `${prevProps.brew.googleId}${prevProps.brew.editId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ const RecentItems = createClass({
|
|||||||
return brew.id !== prevEditId;
|
return brew.id !== prevEditId;
|
||||||
});
|
});
|
||||||
let editId = this.props.brew.editId;
|
let editId = this.props.brew.editId;
|
||||||
if(this.props.brew.googleId){
|
if(this.props.brew.googleId && !this.props.brew.stubbed){
|
||||||
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
editId = `${this.props.brew.googleId}${this.props.brew.editId}`;
|
||||||
}
|
}
|
||||||
edited.unshift({
|
edited.unshift({
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
|
|
||||||
const MAIN_URL = 'https://www.reddit.com/r/UnearthedArcana/submit?selftext=true';
|
|
||||||
|
|
||||||
|
|
||||||
const RedditShare = createClass({
|
|
||||||
displayName : 'RedditShareNavItem',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
brew : {
|
|
||||||
title : '',
|
|
||||||
sharedId : '',
|
|
||||||
text : ''
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getText : function(){
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
handleClick : function(){
|
|
||||||
const url = [
|
|
||||||
MAIN_URL,
|
|
||||||
`title=${encodeURIComponent(this.props.brew.title ? this.props.brew.title : 'Check out my brew!')}`,
|
|
||||||
`text=${encodeURIComponent(this.props.brew.text)}`
|
|
||||||
].join('&');
|
|
||||||
|
|
||||||
window.open(url, '_blank');
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
return <Nav.item icon='fa-reddit-alien' color='red' onClick={this.handleClick}>
|
|
||||||
share on reddit
|
|
||||||
</Nav.item>;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = RedditShare;
|
|
||||||
@@ -32,7 +32,7 @@ import { updateHistory, versionHistoryGarbageCollection } from '../../utils/vers
|
|||||||
|
|
||||||
const googleDriveIcon = require('../../googleDrive.svg');
|
const googleDriveIcon = require('../../googleDrive.svg');
|
||||||
|
|
||||||
const SAVE_TIMEOUT = 3000;
|
const SAVE_TIMEOUT = 10000;
|
||||||
|
|
||||||
const EditPage = createClass({
|
const EditPage = createClass({
|
||||||
displayName : 'EditPage',
|
displayName : 'EditPage',
|
||||||
@@ -228,8 +228,8 @@ const EditPage = createClass({
|
|||||||
htmlErrors : Markdown.validate(prevState.brew.text)
|
htmlErrors : Markdown.validate(prevState.brew.text)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateHistory(this.state.brew);
|
await updateHistory(this.state.brew).catch(console.error);
|
||||||
versionHistoryGarbageCollection();
|
await versionHistoryGarbageCollection().catch(console.error);
|
||||||
|
|
||||||
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
|
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
|
||||||
|
|
||||||
@@ -429,41 +429,41 @@ const EditPage = createClass({
|
|||||||
<Meta name='robots' content='noindex, nofollow' />
|
<Meta name='robots' content='noindex, nofollow' />
|
||||||
{this.renderNavbar()}
|
{this.renderNavbar()}
|
||||||
|
|
||||||
<div className='content'>
|
{this.props.brew.lock && <LockNotification shareId={this.props.brew.shareId} message={this.props.brew.lock.editMessage} />}
|
||||||
{this.props.brew.lock && <LockNotification shareId={this.props.brew.shareId} message={this.props.brew.lock.editMessage} />}
|
<div className="content">
|
||||||
<SplitPane onDragFinish={this.handleSplitMove}>
|
<SplitPane onDragFinish={this.handleSplitMove}>
|
||||||
<Editor
|
<Editor
|
||||||
ref={this.editor}
|
ref={this.editor}
|
||||||
brew={this.state.brew}
|
brew={this.state.brew}
|
||||||
onTextChange={this.handleTextChange}
|
onTextChange={this.handleTextChange}
|
||||||
onStyleChange={this.handleStyleChange}
|
onStyleChange={this.handleStyleChange}
|
||||||
onMetaChange={this.handleMetaChange}
|
onMetaChange={this.handleMetaChange}
|
||||||
reportError={this.errorReported}
|
reportError={this.errorReported}
|
||||||
renderer={this.state.brew.renderer}
|
renderer={this.state.brew.renderer}
|
||||||
userThemes={this.props.userThemes}
|
userThemes={this.props.userThemes}
|
||||||
snippetBundle={this.state.themeBundle.snippets}
|
snippetBundle={this.state.themeBundle.snippets}
|
||||||
updateBrew={this.updateBrew}
|
updateBrew={this.updateBrew}
|
||||||
onCursorPageChange={this.handleEditorCursorPageChange}
|
onCursorPageChange={this.handleEditorCursorPageChange}
|
||||||
onViewPageChange={this.handleEditorViewPageChange}
|
onViewPageChange={this.handleEditorViewPageChange}
|
||||||
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
||||||
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
/>
|
/>
|
||||||
<BrewRenderer
|
<BrewRenderer
|
||||||
text={this.state.brew.text}
|
text={this.state.brew.text}
|
||||||
style={this.state.brew.style}
|
style={this.state.brew.style}
|
||||||
renderer={this.state.brew.renderer}
|
renderer={this.state.brew.renderer}
|
||||||
theme={this.state.brew.theme}
|
theme={this.state.brew.theme}
|
||||||
themeBundle={this.state.themeBundle}
|
themeBundle={this.state.themeBundle}
|
||||||
errors={this.state.htmlErrors}
|
errors={this.state.htmlErrors}
|
||||||
lang={this.state.brew.lang}
|
lang={this.state.brew.lang}
|
||||||
onPageChange={this.handleBrewRendererPageChange}
|
onPageChange={this.handleBrewRendererPageChange}
|
||||||
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
||||||
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
allowPrint={true}
|
allowPrint={true}
|
||||||
/>
|
/>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,11 @@ const errorIndex = (props)=>{
|
|||||||
|
|
||||||
**Brew Title:** ${props.brew.brewTitle}`,
|
**Brew Title:** ${props.brew.brewTitle}`,
|
||||||
|
|
||||||
|
// ####### Admin page error #######
|
||||||
|
'52': dedent`
|
||||||
|
## Access Denied
|
||||||
|
You need to provide correct administrator credentials to access this page.`,
|
||||||
|
|
||||||
'90' : dedent` An unexpected error occurred while looking for these brews.
|
'90' : dedent` An unexpected error occurred while looking for these brews.
|
||||||
Try again in a few minutes.`,
|
Try again in a few minutes.`,
|
||||||
|
|
||||||
|
|||||||
@@ -100,35 +100,33 @@ const HomePage = createClass({
|
|||||||
return <div className='homePage sitePage'>
|
return <div className='homePage sitePage'>
|
||||||
<Meta name='google-site-verification' content='NwnAQSSJZzAT7N-p5MY6ydQ7Njm67dtbu73ZSyE5Fy4' />
|
<Meta name='google-site-verification' content='NwnAQSSJZzAT7N-p5MY6ydQ7Njm67dtbu73ZSyE5Fy4' />
|
||||||
{this.renderNavbar()}
|
{this.renderNavbar()}
|
||||||
|
<div className="content">
|
||||||
<div className='content'>
|
<SplitPane onDragFinish={this.handleSplitMove}>
|
||||||
<SplitPane onDragFinish={this.handleSplitMove}>
|
<Editor
|
||||||
<Editor
|
ref={this.editor}
|
||||||
ref={this.editor}
|
brew={this.state.brew}
|
||||||
brew={this.state.brew}
|
onTextChange={this.handleTextChange}
|
||||||
onTextChange={this.handleTextChange}
|
renderer={this.state.brew.renderer}
|
||||||
renderer={this.state.brew.renderer}
|
showEditButtons={false}
|
||||||
showEditButtons={false}
|
snippetBundle={this.state.themeBundle.snippets}
|
||||||
snippetBundle={this.state.themeBundle.snippets}
|
onCursorPageChange={this.handleEditorCursorPageChange}
|
||||||
onCursorPageChange={this.handleEditorCursorPageChange}
|
onViewPageChange={this.handleEditorViewPageChange}
|
||||||
onViewPageChange={this.handleEditorViewPageChange}
|
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
||||||
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
||||||
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
/>
|
||||||
/>
|
<BrewRenderer
|
||||||
<BrewRenderer
|
text={this.state.brew.text}
|
||||||
text={this.state.brew.text}
|
style={this.state.brew.style}
|
||||||
style={this.state.brew.style}
|
renderer={this.state.brew.renderer}
|
||||||
renderer={this.state.brew.renderer}
|
onPageChange={this.handleBrewRendererPageChange}
|
||||||
onPageChange={this.handleBrewRendererPageChange}
|
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
||||||
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
||||||
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
themeBundle={this.state.themeBundle}
|
||||||
themeBundle={this.state.themeBundle}
|
/>
|
||||||
/>
|
</SplitPane>
|
||||||
</SplitPane>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={cx('floatingSaveButton', { show: this.state.welcomeText != this.state.brew.text })} onClick={this.handleSave}>
|
<div className={cx('floatingSaveButton', { show: this.state.welcomeText != this.state.brew.text })} onClick={this.handleSave}>
|
||||||
Save current <i className='fas fa-save' />
|
Save current <i className='fas fa-save' />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -91,13 +91,6 @@ If you are looking for more 5e Homebrew resources check out [r/UnearthedArcana](
|
|||||||
|
|
||||||
\page
|
\page
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Markdown+
|
## Markdown+
|
||||||
The Homebrewery aims to make homebrewing as simple as possible, providing a live editor with Markdown syntax that is more human-readable and faster to write with than raw HTML.
|
The Homebrewery aims to make homebrewing as simple as possible, providing a live editor with Markdown syntax that is more human-readable and faster to write with than raw HTML.
|
||||||
|
|
||||||
|
|||||||
@@ -223,38 +223,38 @@ const NewPage = createClass({
|
|||||||
render : function(){
|
render : function(){
|
||||||
return <div className='newPage sitePage'>
|
return <div className='newPage sitePage'>
|
||||||
{this.renderNavbar()}
|
{this.renderNavbar()}
|
||||||
<div className='content'>
|
<div className="content">
|
||||||
<SplitPane onDragFinish={this.handleSplitMove}>
|
<SplitPane onDragFinish={this.handleSplitMove}>
|
||||||
<Editor
|
<Editor
|
||||||
ref={this.editor}
|
ref={this.editor}
|
||||||
brew={this.state.brew}
|
brew={this.state.brew}
|
||||||
onTextChange={this.handleTextChange}
|
onTextChange={this.handleTextChange}
|
||||||
onStyleChange={this.handleStyleChange}
|
onStyleChange={this.handleStyleChange}
|
||||||
onMetaChange={this.handleMetaChange}
|
onMetaChange={this.handleMetaChange}
|
||||||
renderer={this.state.brew.renderer}
|
renderer={this.state.brew.renderer}
|
||||||
userThemes={this.props.userThemes}
|
userThemes={this.props.userThemes}
|
||||||
snippetBundle={this.state.themeBundle.snippets}
|
snippetBundle={this.state.themeBundle.snippets}
|
||||||
onCursorPageChange={this.handleEditorCursorPageChange}
|
onCursorPageChange={this.handleEditorCursorPageChange}
|
||||||
onViewPageChange={this.handleEditorViewPageChange}
|
onViewPageChange={this.handleEditorViewPageChange}
|
||||||
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
||||||
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
/>
|
/>
|
||||||
<BrewRenderer
|
<BrewRenderer
|
||||||
text={this.state.brew.text}
|
text={this.state.brew.text}
|
||||||
style={this.state.brew.style}
|
style={this.state.brew.style}
|
||||||
renderer={this.state.brew.renderer}
|
renderer={this.state.brew.renderer}
|
||||||
theme={this.state.brew.theme}
|
theme={this.state.brew.theme}
|
||||||
themeBundle={this.state.themeBundle}
|
themeBundle={this.state.themeBundle}
|
||||||
errors={this.state.htmlErrors}
|
errors={this.state.htmlErrors}
|
||||||
lang={this.state.brew.lang}
|
lang={this.state.brew.lang}
|
||||||
onPageChange={this.handleBrewRendererPageChange}
|
onPageChange={this.handleBrewRendererPageChange}
|
||||||
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
currentEditorViewPageNum={this.state.currentEditorViewPageNum}
|
||||||
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
currentEditorCursorPageNum={this.state.currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
allowPrint={true}
|
allowPrint={true}
|
||||||
/>
|
/>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ const SharePage = createClass({
|
|||||||
|
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
themeBundle : {}
|
themeBundle : {},
|
||||||
|
currentBrewRendererPageNum : 1
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -39,6 +40,10 @@ const SharePage = createClass({
|
|||||||
document.removeEventListener('keydown', this.handleControlKeys);
|
document.removeEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleBrewRendererPageChange : function(pageNumber){
|
||||||
|
this.setState({ currentBrewRendererPageNum: pageNumber });
|
||||||
|
},
|
||||||
|
|
||||||
handleControlKeys : function(e){
|
handleControlKeys : function(e){
|
||||||
if(!(e.ctrlKey || e.metaKey)) return;
|
if(!(e.ctrlKey || e.metaKey)) return;
|
||||||
const P_KEY = 80;
|
const P_KEY = 80;
|
||||||
@@ -114,9 +119,12 @@ const SharePage = createClass({
|
|||||||
<BrewRenderer
|
<BrewRenderer
|
||||||
text={this.props.brew.text}
|
text={this.props.brew.text}
|
||||||
style={this.props.brew.style}
|
style={this.props.brew.style}
|
||||||
|
lang={this.props.brew.lang}
|
||||||
renderer={this.props.brew.renderer}
|
renderer={this.props.brew.renderer}
|
||||||
theme={this.props.brew.theme}
|
theme={this.props.brew.theme}
|
||||||
themeBundle={this.state.themeBundle}
|
themeBundle={this.state.themeBundle}
|
||||||
|
onPageChange={this.handleBrewRendererPageChange}
|
||||||
|
currentBrewRendererPageNum={this.state.currentBrewRendererPageNum}
|
||||||
allowPrint={true}
|
allowPrint={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
.sharePage{
|
.sharePage{
|
||||||
.navContent .navSection.titleSection {
|
nav .navSection.titleSection {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const { useState } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const ListPage = require('../basePages/listPage/listPage.jsx');
|
const ListPage = require('../basePages/listPage/listPage.jsx');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Navbar = require('../../navbar/navbar.jsx');
|
const Navbar = require('../../navbar/navbar.jsx');
|
||||||
|
|
||||||
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
|
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
|
||||||
const Account = require('../../navbar/account.navitem.jsx');
|
const Account = require('../../navbar/account.navitem.jsx');
|
||||||
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
|
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
|
||||||
@@ -14,69 +13,48 @@ const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
|||||||
const ErrorNavItem = require('../../navbar/error-navitem.jsx');
|
const ErrorNavItem = require('../../navbar/error-navitem.jsx');
|
||||||
const VaultNavitem = require('../../navbar/vault.navitem.jsx');
|
const VaultNavitem = require('../../navbar/vault.navitem.jsx');
|
||||||
|
|
||||||
const UserPage = createClass({
|
const UserPage = (props)=>{
|
||||||
displayName : 'UserPage',
|
props = {
|
||||||
getDefaultProps : function() {
|
username : '',
|
||||||
return {
|
brews : [],
|
||||||
username : '',
|
query : '',
|
||||||
brews : [],
|
...props
|
||||||
query : '',
|
};
|
||||||
error : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState : function() {
|
|
||||||
const usernameWithS = this.props.username + (this.props.username.endsWith('s') ? `’` : `’s`);
|
|
||||||
|
|
||||||
const brews = _.groupBy(this.props.brews, (brew)=>{
|
const [error, setError] = useState(null);
|
||||||
return (brew.published ? 'published' : 'private');
|
|
||||||
});
|
|
||||||
|
|
||||||
const brewCollection = [
|
const usernameWithS = props.username + (props.username.endsWith('s') ? `’` : `’s`);
|
||||||
{
|
const groupedBrews = _.groupBy(props.brews, (brew)=>brew.published ? 'published' : 'private');
|
||||||
title : `${usernameWithS} published brews`,
|
|
||||||
class : 'published',
|
|
||||||
brews : brews.published
|
|
||||||
}
|
|
||||||
];
|
|
||||||
if(this.props.username == global.account?.username){
|
|
||||||
brewCollection.push(
|
|
||||||
{
|
|
||||||
title : `${usernameWithS} unpublished brews`,
|
|
||||||
class : 'unpublished',
|
|
||||||
brews : brews.private
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
const brewCollection = [
|
||||||
brewCollection : brewCollection
|
{
|
||||||
};
|
title : `${usernameWithS} published brews`,
|
||||||
},
|
class : 'published',
|
||||||
errorReported : function(error) {
|
brews : groupedBrews.published || []
|
||||||
this.setState({
|
},
|
||||||
error
|
...(props.username === global.account?.username ? [{
|
||||||
});
|
title : `${usernameWithS} unpublished brews`,
|
||||||
},
|
class : 'unpublished',
|
||||||
|
brews : groupedBrews.private || []
|
||||||
|
}] : [])
|
||||||
|
];
|
||||||
|
|
||||||
navItems : function() {
|
const navItems = (
|
||||||
return <Navbar>
|
<Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
{this.state.error ?
|
{error && (<ErrorNavItem error={error} parent={null}></ErrorNavItem>)}
|
||||||
<ErrorNavItem error={this.state.error} parent={this}></ErrorNavItem> :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
<NewBrew />
|
<NewBrew />
|
||||||
<HelpNavItem />
|
<HelpNavItem />
|
||||||
<VaultNavitem/>
|
<VaultNavitem />
|
||||||
<RecentNavItem />
|
<RecentNavItem />
|
||||||
<Account />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
</Navbar>;
|
</Navbar>
|
||||||
},
|
);
|
||||||
|
|
||||||
render : function(){
|
return (
|
||||||
return <ListPage brewCollection={this.state.brewCollection} navItems={this.navItems()} query={this.props.query} reportError={this.errorReported}></ListPage>;
|
<ListPage brewCollection={brewCollection} navItems={navItems} query={props.query} reportError={(err)=>setError(err)} />
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
module.exports = UserPage;
|
module.exports = UserPage;
|
||||||
|
|||||||
@@ -411,19 +411,18 @@ const VaultPage = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='vaultPage'>
|
<div className='sitePage vaultPage'>
|
||||||
<link href='/themes/V3/Blank/style.css' rel='stylesheet' />
|
<link href='/themes/V3/Blank/style.css' rel='stylesheet' />
|
||||||
<link href='/themes/V3/5ePHB/style.css' rel='stylesheet' />
|
<link href='/themes/V3/5ePHB/style.css' rel='stylesheet' />
|
||||||
{renderNavItems()}
|
{renderNavItems()}
|
||||||
<div className='content'>
|
<div className="content">
|
||||||
<SplitPane showDividerButtons={false}>
|
<SplitPane showDividerButtons={false}>
|
||||||
<div className='form dataGroup'>{renderForm()}</div>
|
<div className='form dataGroup'>{renderForm()}</div>
|
||||||
|
<div className='resultsContainer dataGroup'>
|
||||||
<div className='resultsContainer dataGroup'>
|
{renderSortBar()}
|
||||||
{renderSortBar()}
|
{renderFoundBrews()}
|
||||||
{renderFoundBrews()}
|
</div>
|
||||||
</div>
|
</SplitPane>
|
||||||
</SplitPane>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,373 +5,369 @@
|
|||||||
|
|
||||||
*:not(input) { user-select : none; }
|
*:not(input) { user-select : none; }
|
||||||
|
|
||||||
.content {
|
.content .dataGroup {
|
||||||
|
width : 100%;
|
||||||
height : 100%;
|
height : 100%;
|
||||||
background : #2C3E50;
|
background : white;
|
||||||
|
|
||||||
.dataGroup {
|
&.form .brewLookup {
|
||||||
width : 100%;
|
position : relative;
|
||||||
height : 100%;
|
padding : 50px clamp(20px, 4vw, 50px);
|
||||||
background : white;
|
|
||||||
|
|
||||||
&.form .brewLookup {
|
small {
|
||||||
position : relative;
|
font-size : 10pt;
|
||||||
padding : 50px clamp(20px, 4vw, 50px);
|
color : #555555;
|
||||||
|
|
||||||
small {
|
a { color : #333333; }
|
||||||
font-size : 10pt;
|
}
|
||||||
color : #555555;
|
|
||||||
|
|
||||||
a { color : #333333; }
|
code {
|
||||||
}
|
padding-inline : 5px;
|
||||||
|
font-family : monospace;
|
||||||
|
background : lightgrey;
|
||||||
|
border-radius : 5px;
|
||||||
|
}
|
||||||
|
|
||||||
code {
|
h1, h2, h3, h4 {
|
||||||
padding-inline : 5px;
|
font-family : 'CodeBold';
|
||||||
font-family : monospace;
|
letter-spacing : 2px;
|
||||||
background : lightgrey;
|
}
|
||||||
border-radius : 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1, h2, h3, h4 {
|
legend {
|
||||||
font-family : 'CodeBold';
|
h3 {
|
||||||
letter-spacing : 2px;
|
margin-block : 30px 20px;
|
||||||
}
|
font-size : 20px;
|
||||||
|
|
||||||
legend {
|
|
||||||
h3 {
|
|
||||||
margin-block : 30px 20px;
|
|
||||||
font-size : 20px;
|
|
||||||
text-align : center;
|
|
||||||
border-bottom : 2px solid;
|
|
||||||
}
|
|
||||||
ul {
|
|
||||||
padding-inline : 30px 10px;
|
|
||||||
li {
|
|
||||||
margin-block : 5px;
|
|
||||||
line-height : calc(1em + 5px);
|
|
||||||
list-style : disc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&::after {
|
|
||||||
position : absolute;
|
|
||||||
top : 0;
|
|
||||||
right : 0;
|
|
||||||
left : 0;
|
|
||||||
display : block;
|
|
||||||
padding : 10px;
|
|
||||||
font-weight : 900;
|
|
||||||
color : white;
|
|
||||||
white-space : pre-wrap;
|
|
||||||
content : 'Error:\A At least one renderer should be enabled to make a search';
|
|
||||||
background : rgb(255, 60, 60);
|
|
||||||
opacity : 0;
|
|
||||||
transition : opacity 0.5s;
|
|
||||||
}
|
|
||||||
&:not(:has(input[type='checkbox']:checked))::after { opacity : 1; }
|
|
||||||
|
|
||||||
.formTitle {
|
|
||||||
margin : 20px 0;
|
|
||||||
font-size : 30px;
|
|
||||||
color : black;
|
|
||||||
text-align : center;
|
text-align : center;
|
||||||
border-bottom : 2px solid;
|
border-bottom : 2px solid;
|
||||||
}
|
}
|
||||||
|
ul {
|
||||||
.formContents {
|
padding-inline : 30px 10px;
|
||||||
position : relative;
|
li {
|
||||||
display : flex;
|
margin-block : 5px;
|
||||||
flex-direction : column;
|
line-height : calc(1em + 5px);
|
||||||
|
list-style : disc;
|
||||||
label {
|
|
||||||
display : flex;
|
|
||||||
align-items : center;
|
|
||||||
margin : 10px 0;
|
|
||||||
}
|
|
||||||
select { margin : 0 10px; }
|
|
||||||
|
|
||||||
input {
|
|
||||||
margin : 0 10px;
|
|
||||||
|
|
||||||
&:invalid { background : rgb(255, 188, 181); }
|
|
||||||
|
|
||||||
&[type='checkbox'] {
|
|
||||||
position : relative;
|
|
||||||
display : inline-block;
|
|
||||||
width : 50px;
|
|
||||||
height : 30px;
|
|
||||||
font-family : 'WalterTurncoat';
|
|
||||||
font-size : 20px;
|
|
||||||
font-weight : 800;
|
|
||||||
color : white;
|
|
||||||
letter-spacing : 2px;
|
|
||||||
appearance : none;
|
|
||||||
background : red;
|
|
||||||
isolation : isolate;
|
|
||||||
border-radius : 5px;
|
|
||||||
|
|
||||||
&::before,&::after {
|
|
||||||
position : absolute;
|
|
||||||
inset : 0;
|
|
||||||
z-index : 5;
|
|
||||||
padding-top : 2px;
|
|
||||||
text-align : center;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
display : block;
|
|
||||||
content : 'No';
|
|
||||||
}
|
|
||||||
|
|
||||||
&::after {
|
|
||||||
display : none;
|
|
||||||
content : 'Yes';
|
|
||||||
}
|
|
||||||
|
|
||||||
&:checked {
|
|
||||||
background : green;
|
|
||||||
|
|
||||||
&::before { display : none; }
|
|
||||||
&::after { display : block; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#searchButton {
|
|
||||||
position : absolute;
|
|
||||||
right : 20px;
|
|
||||||
bottom : 0;
|
|
||||||
|
|
||||||
i {
|
|
||||||
margin-left : 10px;
|
|
||||||
animation-duration : 1000s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.resultsContainer {
|
&::after {
|
||||||
|
position : absolute;
|
||||||
|
top : 0;
|
||||||
|
right : 0;
|
||||||
|
left : 0;
|
||||||
|
display : block;
|
||||||
|
padding : 10px;
|
||||||
|
font-weight : 900;
|
||||||
|
color : white;
|
||||||
|
white-space : pre-wrap;
|
||||||
|
content : 'Error:\A At least one renderer should be enabled to make a search';
|
||||||
|
background : rgb(255, 60, 60);
|
||||||
|
opacity : 0;
|
||||||
|
transition : opacity 0.5s;
|
||||||
|
}
|
||||||
|
&:not(:has(input[type='checkbox']:checked))::after { opacity : 1; }
|
||||||
|
|
||||||
|
.formTitle {
|
||||||
|
margin : 20px 0;
|
||||||
|
font-size : 30px;
|
||||||
|
color : black;
|
||||||
|
text-align : center;
|
||||||
|
border-bottom : 2px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formContents {
|
||||||
|
position : relative;
|
||||||
display : flex;
|
display : flex;
|
||||||
flex-direction : column;
|
flex-direction : column;
|
||||||
height : 100%;
|
|
||||||
overflow-y : auto;
|
|
||||||
font-family : 'BookInsanityRemake';
|
|
||||||
font-size : 0.34cm;
|
|
||||||
|
|
||||||
h3 {
|
label {
|
||||||
font-family : 'Open Sans';
|
display : flex;
|
||||||
font-weight : 900;
|
align-items : center;
|
||||||
color : white;
|
margin : 10px 0;
|
||||||
}
|
}
|
||||||
|
select { margin : 0 10px; }
|
||||||
|
|
||||||
.sort-container {
|
input {
|
||||||
display : flex;
|
margin : 0 10px;
|
||||||
flex-wrap : wrap;
|
|
||||||
column-gap : 15px;
|
|
||||||
justify-content : center;
|
|
||||||
height : 30px;
|
|
||||||
color : white;
|
|
||||||
background-color : #555555;
|
|
||||||
border-top : 1px solid #666666;
|
|
||||||
border-bottom : 1px solid #666666;
|
|
||||||
|
|
||||||
.sort-option {
|
&:invalid { background : rgb(255, 188, 181); }
|
||||||
display : flex;
|
|
||||||
align-items : center;
|
|
||||||
padding : 0 8px;
|
|
||||||
|
|
||||||
&:hover { background-color : #444444; }
|
&[type='checkbox'] {
|
||||||
|
position : relative;
|
||||||
|
display : inline-block;
|
||||||
|
width : 50px;
|
||||||
|
height : 30px;
|
||||||
|
font-family : 'WalterTurncoat';
|
||||||
|
font-size : 20px;
|
||||||
|
font-weight : 800;
|
||||||
|
color : white;
|
||||||
|
letter-spacing : 2px;
|
||||||
|
appearance : none;
|
||||||
|
background : red;
|
||||||
|
isolation : isolate;
|
||||||
|
border-radius : 5px;
|
||||||
|
|
||||||
&.active {
|
&::before,&::after {
|
||||||
background-color : #333333;
|
position : absolute;
|
||||||
|
inset : 0;
|
||||||
button {
|
z-index : 5;
|
||||||
font-weight : 800;
|
padding-top : 2px;
|
||||||
color : white;
|
text-align : center;
|
||||||
|
|
||||||
& + .sortDir { padding-left : 5px; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
&::before {
|
||||||
padding : 0;
|
display : block;
|
||||||
font-size : 11px;
|
content : 'No';
|
||||||
font-weight : normal;
|
|
||||||
color : #CCCCCC;
|
|
||||||
text-transform : uppercase;
|
|
||||||
background-color : transparent;
|
|
||||||
|
|
||||||
&:hover { background : none; }
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.foundBrews {
|
|
||||||
position : relative;
|
|
||||||
width : 100%;
|
|
||||||
height : 100%;
|
|
||||||
max-height : 100%;
|
|
||||||
padding : 50px 50px 70px 50px;
|
|
||||||
overflow-y : scroll;
|
|
||||||
background-color : #2C3E50;
|
|
||||||
|
|
||||||
h3 { font-size : 25px; }
|
|
||||||
|
|
||||||
&.noBrews {
|
|
||||||
display : grid;
|
|
||||||
place-items : center;
|
|
||||||
color : white;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.searching {
|
|
||||||
display : grid;
|
|
||||||
place-items : center;
|
|
||||||
color : white;
|
|
||||||
|
|
||||||
h3 { position : relative; }
|
|
||||||
|
|
||||||
h3.searchAnim::after {
|
|
||||||
position : absolute;
|
|
||||||
top : 50%;
|
|
||||||
right : 0;
|
|
||||||
width : max-content;
|
|
||||||
height : 1em;
|
|
||||||
content : '';
|
|
||||||
translate : calc(100% + 5px) -50%;
|
|
||||||
animation : trailingDots 2s ease infinite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.totalBrews {
|
|
||||||
position : fixed;
|
|
||||||
right : 0;
|
|
||||||
bottom : 0;
|
|
||||||
z-index : 1000;
|
|
||||||
padding : 8px 10px;
|
|
||||||
font-family : 'Open Sans';
|
|
||||||
font-size : 11px;
|
|
||||||
font-weight : 800;
|
|
||||||
color : white;
|
|
||||||
background-color : #333333;
|
|
||||||
|
|
||||||
.searchAnim {
|
|
||||||
position : relative;
|
|
||||||
display : inline-block;
|
|
||||||
width : 3ch;
|
|
||||||
height : 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searchAnim::after {
|
|
||||||
position : absolute;
|
|
||||||
top : 50%;
|
|
||||||
right : 0;
|
|
||||||
width : max-content;
|
|
||||||
height : 1em;
|
|
||||||
content : '';
|
|
||||||
translate : -50% -50%;
|
|
||||||
animation : trailingDots 2s ease infinite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.brewItem {
|
|
||||||
width : 47%;
|
|
||||||
margin-right : 40px;
|
|
||||||
color : black;
|
|
||||||
isolation : isolate;
|
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
position : absolute;
|
display : none;
|
||||||
inset : 0;
|
content : 'Yes';
|
||||||
z-index : -2;
|
|
||||||
display : block;
|
|
||||||
content : '';
|
|
||||||
background-image : url('/assets/parchmentBackground.jpg');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&:nth-child(even of .brewItem) { margin-right : 0; }
|
&:checked {
|
||||||
|
background : green;
|
||||||
|
|
||||||
h2 {
|
&::before { display : none; }
|
||||||
font-family : 'MrEavesRemake';
|
&::after { display : block; }
|
||||||
font-size : 0.75cm;
|
|
||||||
font-weight : 800;
|
|
||||||
line-height : 0.988em;
|
|
||||||
color : var(--HB_Color_HeaderText);
|
|
||||||
}
|
}
|
||||||
.info {
|
|
||||||
position : relative;
|
|
||||||
z-index : 2;
|
|
||||||
font-family : 'ScalySansRemake';
|
|
||||||
font-size : 1.2em;
|
|
||||||
|
|
||||||
>span {
|
|
||||||
margin-right : 12px;
|
|
||||||
line-height : 1.5em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.links { z-index : 2; }
|
|
||||||
|
|
||||||
hr {
|
|
||||||
margin : 0px;
|
|
||||||
visibility : hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.thumbnail { z-index : -1; }
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.paginationControls {
|
#searchButton {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
left : 50%;
|
right : 20px;
|
||||||
display : grid;
|
bottom : 0;
|
||||||
grid-template-areas : 'previousPage currentPage nextPage';
|
|
||||||
grid-template-columns : 50px 1fr 50px;
|
|
||||||
place-items : center;
|
|
||||||
width : auto;
|
|
||||||
translate : -50%;
|
|
||||||
|
|
||||||
.pages {
|
|
||||||
display : flex;
|
|
||||||
grid-area : currentPage;
|
|
||||||
justify-content : space-evenly;
|
|
||||||
width : 100%;
|
|
||||||
height : 100%;
|
|
||||||
padding : 5px 8px;
|
|
||||||
text-align : center;
|
|
||||||
|
|
||||||
.pageNumber {
|
|
||||||
margin-inline : 1vw;
|
|
||||||
font-family : 'Open Sans';
|
|
||||||
font-weight : 900;
|
|
||||||
color : white;
|
|
||||||
text-underline-position : under;
|
|
||||||
text-wrap : nowrap;
|
|
||||||
cursor : pointer;
|
|
||||||
|
|
||||||
&.currentPage {
|
|
||||||
color : gold;
|
|
||||||
text-decoration : underline;
|
|
||||||
pointer-events : none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.firstPage { margin-right : -5px; }
|
|
||||||
|
|
||||||
&.lastPage { margin-left : -5px; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
width : max-content;
|
|
||||||
|
|
||||||
&.previousPage { grid-area : previousPage; }
|
|
||||||
|
|
||||||
&.nextPage { grid-area : nextPage; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
i {
|
||||||
|
margin-left : 10px;
|
||||||
|
animation-duration : 1000s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.resultsContainer {
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
height : 100%;
|
||||||
|
overflow-y : auto;
|
||||||
|
font-family : 'BookInsanityRemake';
|
||||||
|
font-size : 0.34cm;
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-family : 'Open Sans';
|
||||||
|
font-weight : 900;
|
||||||
|
color : white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sort-container {
|
||||||
|
display : flex;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
column-gap : 15px;
|
||||||
|
justify-content : center;
|
||||||
|
height : 30px;
|
||||||
|
color : white;
|
||||||
|
background-color : #555555;
|
||||||
|
border-top : 1px solid #666666;
|
||||||
|
border-bottom : 1px solid #666666;
|
||||||
|
|
||||||
|
.sort-option {
|
||||||
|
display : flex;
|
||||||
|
align-items : center;
|
||||||
|
padding : 0 8px;
|
||||||
|
|
||||||
|
&:hover { background-color : #444444; }
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background-color : #333333;
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-weight : 800;
|
||||||
|
color : white;
|
||||||
|
|
||||||
|
& + .sortDir { padding-left : 5px; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding : 0;
|
||||||
|
font-size : 11px;
|
||||||
|
font-weight : normal;
|
||||||
|
color : #CCCCCC;
|
||||||
|
text-transform : uppercase;
|
||||||
|
background-color : transparent;
|
||||||
|
|
||||||
|
&:hover { background : none; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.foundBrews {
|
||||||
|
position : relative;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
max-height : 100%;
|
||||||
|
padding : 50px 50px 70px 50px;
|
||||||
|
overflow-y : scroll;
|
||||||
|
background-color : #2C3E50;
|
||||||
|
|
||||||
|
h3 { font-size : 25px; }
|
||||||
|
|
||||||
|
&.noBrews {
|
||||||
|
display : grid;
|
||||||
|
place-items : center;
|
||||||
|
color : white;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.searching {
|
||||||
|
display : grid;
|
||||||
|
place-items : center;
|
||||||
|
color : white;
|
||||||
|
|
||||||
|
h3 { position : relative; }
|
||||||
|
|
||||||
|
h3.searchAnim::after {
|
||||||
|
position : absolute;
|
||||||
|
top : 50%;
|
||||||
|
right : 0;
|
||||||
|
width : max-content;
|
||||||
|
height : 1em;
|
||||||
|
content : '';
|
||||||
|
translate : calc(100% + 5px) -50%;
|
||||||
|
animation : trailingDots 2s ease infinite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.totalBrews {
|
||||||
|
position : fixed;
|
||||||
|
right : 0;
|
||||||
|
bottom : 0;
|
||||||
|
z-index : 1000;
|
||||||
|
padding : 8px 10px;
|
||||||
|
font-family : 'Open Sans';
|
||||||
|
font-size : 11px;
|
||||||
|
font-weight : 800;
|
||||||
|
color : white;
|
||||||
|
background-color : #333333;
|
||||||
|
|
||||||
|
.searchAnim {
|
||||||
|
position : relative;
|
||||||
|
display : inline-block;
|
||||||
|
width : 3ch;
|
||||||
|
height : 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.searchAnim::after {
|
||||||
|
position : absolute;
|
||||||
|
top : 50%;
|
||||||
|
right : 0;
|
||||||
|
width : max-content;
|
||||||
|
height : 1em;
|
||||||
|
content : '';
|
||||||
|
translate : -50% -50%;
|
||||||
|
animation : trailingDots 2s ease infinite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.brewItem {
|
||||||
|
width : 47%;
|
||||||
|
margin-right : 40px;
|
||||||
|
color : black;
|
||||||
|
isolation : isolate;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
position : absolute;
|
||||||
|
inset : 0;
|
||||||
|
z-index : -2;
|
||||||
|
display : block;
|
||||||
|
content : '';
|
||||||
|
background-image : url('/assets/parchmentBackground.jpg');
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-child(even of .brewItem) { margin-right : 0; }
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-family : 'MrEavesRemake';
|
||||||
|
font-size : 0.75cm;
|
||||||
|
font-weight : 800;
|
||||||
|
line-height : 0.988em;
|
||||||
|
color : var(--HB_Color_HeaderText);
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
position : relative;
|
||||||
|
z-index : 2;
|
||||||
|
font-family : 'ScalySansRemake';
|
||||||
|
font-size : 1.2em;
|
||||||
|
|
||||||
|
>span {
|
||||||
|
margin-right : 12px;
|
||||||
|
line-height : 1.5em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.links { z-index : 2; }
|
||||||
|
|
||||||
|
hr {
|
||||||
|
margin : 0px;
|
||||||
|
visibility : hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumbnail { z-index : -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginationControls {
|
||||||
|
position : absolute;
|
||||||
|
left : 50%;
|
||||||
|
display : grid;
|
||||||
|
grid-template-areas : 'previousPage currentPage nextPage';
|
||||||
|
grid-template-columns : 50px 1fr 50px;
|
||||||
|
place-items : center;
|
||||||
|
width : auto;
|
||||||
|
translate : -50%;
|
||||||
|
|
||||||
|
.pages {
|
||||||
|
display : flex;
|
||||||
|
grid-area : currentPage;
|
||||||
|
justify-content : space-evenly;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
padding : 5px 8px;
|
||||||
|
text-align : center;
|
||||||
|
|
||||||
|
.pageNumber {
|
||||||
|
margin-inline : 1vw;
|
||||||
|
font-family : 'Open Sans';
|
||||||
|
font-weight : 900;
|
||||||
|
color : white;
|
||||||
|
text-underline-position : under;
|
||||||
|
text-wrap : nowrap;
|
||||||
|
cursor : pointer;
|
||||||
|
|
||||||
|
&.currentPage {
|
||||||
|
color : gold;
|
||||||
|
text-decoration : underline;
|
||||||
|
pointer-events : none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.firstPage { margin-right : -5px; }
|
||||||
|
|
||||||
|
&.lastPage { margin-left : -5px; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
width : max-content;
|
||||||
|
|
||||||
|
&.previousPage { grid-area : previousPage; }
|
||||||
|
|
||||||
|
&.nextPage { grid-area : nextPage; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes trailingDots {
|
@keyframes trailingDots {
|
||||||
@@ -388,7 +384,7 @@
|
|||||||
|
|
||||||
// media query for when the page is smaller than 1079 px in width
|
// media query for when the page is smaller than 1079 px in width
|
||||||
@media screen and (max-width : 1079px) {
|
@media screen and (max-width : 1079px) {
|
||||||
.vaultPage .content {
|
.vaultPage {
|
||||||
|
|
||||||
.dataGroup.form .brewLookup { padding : 1px 20px 20px 10px; }
|
.dataGroup.form .brewLookup { padding : 1px 20px 20px 10px; }
|
||||||
|
|
||||||
|
|||||||
19
client/homebrew/utils/customIDBStore.js
Normal file
19
client/homebrew/utils/customIDBStore.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import * as IDB from 'idb-keyval/dist/index.js';
|
||||||
|
|
||||||
|
export function initCustomStore(db, store){
|
||||||
|
const createCustomStore = async ()=>IDB.createStore(db, store);
|
||||||
|
|
||||||
|
return {
|
||||||
|
entries : async ()=>IDB.entries(await createCustomStore()),
|
||||||
|
keys : async ()=>IDB.keys(await createCustomStore()),
|
||||||
|
values : async ()=>IDB.values(await createCustomStore()),
|
||||||
|
clear : async ()=>IDB.clear(await createCustomStore),
|
||||||
|
get : async (key)=>IDB.get(key, await createCustomStore()),
|
||||||
|
getMany : async (keys)=>IDB.getMany(keys, await createCustomStore()),
|
||||||
|
set : async (key, value)=>IDB.set(key, value, await createCustomStore()),
|
||||||
|
setMany : async (entries)=>IDB.setMany(entries, await createCustomStore()),
|
||||||
|
update : async (key, updateFn)=>IDB.update(key, updateFn, await createCustomStore()),
|
||||||
|
del : async (key)=>IDB.del(key, await createCustomStore()),
|
||||||
|
delMany : async (keys)=>IDB.delMany(keys, await createCustomStore())
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import { initCustomStore } from './customIDBStore.js';
|
||||||
|
|
||||||
export const HISTORY_PREFIX = 'HOMEBREWERY-HISTORY';
|
export const HISTORY_PREFIX = 'HOMEBREWERY-HISTORY';
|
||||||
export const HISTORY_SLOTS = 5;
|
export const HISTORY_SLOTS = 5;
|
||||||
|
|
||||||
// History values in minutes
|
// History values in minutes
|
||||||
const DEFAULT_HISTORY_SAVE_DELAYS = {
|
const HISTORY_SAVE_DELAYS = {
|
||||||
'0' : 0,
|
'0' : 0,
|
||||||
'1' : 2,
|
'1' : 2,
|
||||||
'2' : 10,
|
'2' : 10,
|
||||||
@@ -10,29 +12,32 @@ const DEFAULT_HISTORY_SAVE_DELAYS = {
|
|||||||
'4' : 12 * 60,
|
'4' : 12 * 60,
|
||||||
'5' : 2 * 24 * 60
|
'5' : 2 * 24 * 60
|
||||||
};
|
};
|
||||||
|
// const HISTORY_SAVE_DELAYS = {
|
||||||
|
// '0' : 0,
|
||||||
|
// '1' : 1,
|
||||||
|
// '2' : 2,
|
||||||
|
// '3' : 3,
|
||||||
|
// '4' : 4,
|
||||||
|
// '5' : 5
|
||||||
|
// };
|
||||||
|
|
||||||
const DEFAULT_GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
|
const GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
|
||||||
|
// const GARBAGE_COLLECT_DELAY = 10;
|
||||||
const HISTORY_SAVE_DELAYS = global.config?.historyData?.HISTORY_SAVE_DELAYS ?? DEFAULT_HISTORY_SAVE_DELAYS;
|
|
||||||
const GARBAGE_COLLECT_DELAY = global.config?.historyData?.GARBAGE_COLLECT_DELAY ?? DEFAULT_GARBAGE_COLLECT_DELAY;
|
|
||||||
|
|
||||||
|
|
||||||
|
const HB_DB = 'HOMEBREWERY-DB';
|
||||||
|
const HB_STORE = 'HISTORY';
|
||||||
|
|
||||||
|
const IDB = initCustomStore(HB_DB, HB_STORE);
|
||||||
|
|
||||||
function getKeyBySlot(brew, slot){
|
function getKeyBySlot(brew, slot){
|
||||||
|
// Return a string representing the key for this brew and history slot
|
||||||
return `${HISTORY_PREFIX}-${brew.shareId}-${slot}`;
|
return `${HISTORY_PREFIX}-${brew.shareId}-${slot}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getVersionBySlot(brew, slot){
|
function parseBrewForStorage(brew, slot = 0) {
|
||||||
// Read stored brew data
|
// Strip out unneeded object properties
|
||||||
// - If it exists, parse data to object
|
// Returns an array of [ key, brew ]
|
||||||
// - If it doesn't exist, pass default object
|
|
||||||
const key = getKeyBySlot(brew, slot);
|
|
||||||
const storedVersion = localStorage.getItem(key);
|
|
||||||
const output = storedVersion ? JSON.parse(storedVersion) : { expireAt: '2000-01-01T00:00:00.000Z', shareId: brew.shareId, noData: true };
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
function updateStoredBrew(brew, slot = 0) {
|
|
||||||
const archiveBrew = {
|
const archiveBrew = {
|
||||||
title : brew.title,
|
title : brew.title,
|
||||||
text : brew.text,
|
text : brew.text,
|
||||||
@@ -46,44 +51,50 @@ function updateStoredBrew(brew, slot = 0) {
|
|||||||
archiveBrew.expireAt.setMinutes(archiveBrew.expireAt.getMinutes() + HISTORY_SAVE_DELAYS[slot]);
|
archiveBrew.expireAt.setMinutes(archiveBrew.expireAt.getMinutes() + HISTORY_SAVE_DELAYS[slot]);
|
||||||
|
|
||||||
const key = getKeyBySlot(brew, slot);
|
const key = getKeyBySlot(brew, slot);
|
||||||
localStorage.setItem(key, JSON.stringify(archiveBrew));
|
|
||||||
|
return [key, archiveBrew];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function loadHistory(brew){
|
||||||
|
const DEFAULT_HISTORY_ITEM = { expireAt: '2000-01-01T00:00:00.000Z', shareId: brew.shareId, noData: true };
|
||||||
|
|
||||||
export function historyExists(brew){
|
const historyKeys = [];
|
||||||
return Object.keys(localStorage)
|
|
||||||
.some((key)=>{
|
|
||||||
return key.startsWith(`${HISTORY_PREFIX}-${brew.shareId}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function loadHistory(brew){
|
// Create array of all history keys
|
||||||
const history = {};
|
|
||||||
|
|
||||||
// Load data from local storage to History object
|
|
||||||
for (let i = 1; i <= HISTORY_SLOTS; i++){
|
for (let i = 1; i <= HISTORY_SLOTS; i++){
|
||||||
history[i] = getVersionBySlot(brew, i);
|
historyKeys.push(getKeyBySlot(brew, i));
|
||||||
};
|
};
|
||||||
|
|
||||||
return history;
|
// Load all keys from IDB at once
|
||||||
|
const dataArray = await IDB.getMany(historyKeys);
|
||||||
|
return dataArray.map((data)=>{ return data ?? DEFAULT_HISTORY_ITEM; });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateHistory(brew) {
|
export async function updateHistory(brew) {
|
||||||
const history = loadHistory(brew);
|
const history = await loadHistory(brew);
|
||||||
|
|
||||||
// Walk each version position
|
// Walk each version position
|
||||||
for (let slot = HISTORY_SLOTS; slot > 0; slot--){
|
for (let slot = HISTORY_SLOTS - 1; slot >= 0; slot--){
|
||||||
const storedVersion = history[slot];
|
const storedVersion = history[slot];
|
||||||
|
|
||||||
// If slot has expired, update all lower slots and break
|
// If slot has expired, update all lower slots and break
|
||||||
if(new Date() >= new Date(storedVersion.expireAt)){
|
if(new Date() >= new Date(storedVersion.expireAt)){
|
||||||
for (let updateSlot = slot - 1; updateSlot>0; updateSlot--){
|
|
||||||
|
// Create array of arrays : [ [key1, value1], [key2, value2], ..., [keyN, valueN] ]
|
||||||
|
// to pass to IDB.setMany
|
||||||
|
const historyUpdate = [];
|
||||||
|
|
||||||
|
for (let updateSlot = slot; updateSlot > 0; updateSlot--){
|
||||||
// Move data from updateSlot to updateSlot + 1
|
// Move data from updateSlot to updateSlot + 1
|
||||||
!history[updateSlot]?.noData && updateStoredBrew(history[updateSlot], updateSlot + 1);
|
if(!history[updateSlot - 1]?.noData) {
|
||||||
|
historyUpdate.push(parseBrewForStorage(history[updateSlot - 1], updateSlot + 1));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the most recent brew
|
// Update the most recent brew
|
||||||
updateStoredBrew(brew, 1);
|
historyUpdate.push(parseBrewForStorage(brew, 1));
|
||||||
|
|
||||||
|
await IDB.setMany(historyUpdate);
|
||||||
|
|
||||||
// Break out of data checks because we found an expired value
|
// Break out of data checks because we found an expired value
|
||||||
break;
|
break;
|
||||||
@@ -91,26 +102,18 @@ export function updateHistory(brew) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getHistoryItems(brew){
|
export async function versionHistoryGarbageCollection(){
|
||||||
const historyArray = [];
|
const entries = await IDB.entries();
|
||||||
|
|
||||||
for (let i = 1; i <= HISTORY_SLOTS; i++){
|
const expiredKeys = [];
|
||||||
historyArray.push(getVersionBySlot(brew, i));
|
for (const [key, value] of entries){
|
||||||
|
const expireAt = new Date(value.savedAt);
|
||||||
|
expireAt.setMinutes(expireAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
||||||
|
if(new Date() > expireAt){
|
||||||
|
expiredKeys.push(key);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
if(expiredKeys.length > 0){
|
||||||
|
await IDB.delMany(expiredKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
return historyArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function versionHistoryGarbageCollection(){
|
|
||||||
Object.keys(localStorage)
|
|
||||||
.filter((key)=>{
|
|
||||||
return key.startsWith(HISTORY_PREFIX);
|
|
||||||
})
|
|
||||||
.forEach((key)=>{
|
|
||||||
const collectAt = new Date(JSON.parse(localStorage.getItem(key)).savedAt);
|
|
||||||
collectAt.setMinutes(collectAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
|
||||||
if(new Date() > collectAt){
|
|
||||||
localStorage.removeItem(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
@@ -73,3 +73,12 @@
|
|||||||
.fit-width {
|
.fit-width {
|
||||||
mask-image: url('../icons/fit-width.svg');
|
mask-image: url('../icons/fit-width.svg');
|
||||||
}
|
}
|
||||||
|
.single-spread {
|
||||||
|
mask-image: url('../icons/single-spread.svg');
|
||||||
|
}
|
||||||
|
.facing-spread {
|
||||||
|
mask-image: url('../icons/facing-spread.svg');
|
||||||
|
}
|
||||||
|
.flow-spread {
|
||||||
|
mask-image: url('../icons/flow-spread.svg');
|
||||||
|
}
|
||||||
|
|||||||
10
client/icons/facing-spread.svg
Normal file
10
client/icons/facing-spread.svg
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
|
<g transform="matrix(0.979101,0,0,0.919064,-29.0748,1.98095)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.979101,0,0,0.919064,23.058,1.98095)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
24
client/icons/flow-spread.svg
Normal file
24
client/icons/flow-spread.svg
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
|
<g transform="matrix(1.0781,0,0,1.0781,-3.90545,-3.90502)">
|
||||||
|
<g transform="matrix(0.590052,0,0,0.553871,-13.8993,-2.19227)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.590052,0,0,0.553871,-13.8993,44.3152)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.590052,0,0,0.553871,17.5184,-2.19227)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.590052,0,0,0.553871,50.0095,-2.19227)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.590052,0,0,0.553871,17.5184,44.3152)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.590052,0,0,0.553871,50.0095,44.3152)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.5 KiB |
7
client/icons/single-spread.svg
Normal file
7
client/icons/single-spread.svg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
|
<g transform="matrix(1.41826,0,0,1.3313,-26.7845,-19.5573)">
|
||||||
|
<path d="M78.584,16.13C78.584,15.335 78.164,14.69 77.647,14.69L30.632,14.69C30.115,14.69 29.695,15.335 29.695,16.13L29.695,88.365C29.695,89.16 30.115,89.805 30.632,89.805L77.647,89.805C78.164,89.805 78.584,89.16 78.584,88.365L78.584,16.13Z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 777 B |
@@ -6,5 +6,7 @@
|
|||||||
"enable_v3" : true,
|
"enable_v3" : true,
|
||||||
"enable_themes" : true,
|
"enable_themes" : true,
|
||||||
"local_environments" : ["docker", "local"],
|
"local_environments" : ["docker", "local"],
|
||||||
"publicUrl" : "https://homebrewery.naturalcrit.com"
|
"publicUrl" : "https://homebrewery.naturalcrit.com",
|
||||||
|
"hb_images" : null,
|
||||||
|
"hb_fonts" : null
|
||||||
}
|
}
|
||||||
|
|||||||
2340
package-lock.json
generated
2340
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "homebrewery",
|
"name": "homebrewery",
|
||||||
"description": "Create authentic looking D&D homebrews using only markdown",
|
"description": "Create authentic looking D&D homebrews using only markdown",
|
||||||
"version": "3.15.0",
|
"version": "3.16.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"npm": "^10.2.x",
|
"npm": "^10.2.x",
|
||||||
"node": "^20.8.x"
|
"node": "^20.18.x"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/naturalcrit/homebrewery.git"
|
"url": "git://github.com/naturalcrit/homebrewery.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node --experimental-require-module scripts/dev.js",
|
||||||
"quick": "node scripts/quick.js",
|
"quick": "node --experimental-require-module scripts/quick.js",
|
||||||
"build": "node scripts/buildHomebrew.js && node scripts/buildAdmin.js",
|
"build": "node --experimental-require-module scripts/buildHomebrew.js && node --experimental-require-module scripts/buildAdmin.js",
|
||||||
"builddev": "node scripts/buildHomebrew.js --dev",
|
"builddev": "node --experimental-require-module scripts/buildHomebrew.js --dev",
|
||||||
"lint": "eslint --fix",
|
"lint": "eslint --fix",
|
||||||
"lint:dry": "eslint",
|
"lint:dry": "eslint",
|
||||||
"stylelint": "stylelint --fix **/*.{less}",
|
"stylelint": "stylelint --fix **/*.{less}",
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
"test:api-unit": "jest \"server/.*.spec.js\" --verbose",
|
"test:api-unit": "jest \"server/.*.spec.js\" --verbose",
|
||||||
"test:api-unit:themes": "jest \"server/.*.spec.js\" -t \"theme bundle\" --verbose",
|
"test:api-unit:themes": "jest \"server/.*.spec.js\" -t \"theme bundle\" --verbose",
|
||||||
"test:api-unit:css": "jest \"server/.*.spec.js\" -t \"Get CSS\" --verbose",
|
"test:api-unit:css": "jest \"server/.*.spec.js\" -t \"Get CSS\" --verbose",
|
||||||
|
"test:api-unit:notifications": "jest \"server/.*.spec.js\" -t \"Notifications\" --verbose",
|
||||||
"test:coverage": "jest --coverage --silent --runInBand",
|
"test:coverage": "jest --coverage --silent --runInBand",
|
||||||
"test:dev": "jest --verbose --watch",
|
"test:dev": "jest --verbose --watch",
|
||||||
"test:basic": "jest tests/markdown/basic.test.js --verbose",
|
"test:basic": "jest tests/markdown/basic.test.js --verbose",
|
||||||
@@ -37,10 +38,11 @@
|
|||||||
"test:hard-breaks": "jest tests/markdown/hard-breaks.test.js --verbose --noStackTrace",
|
"test:hard-breaks": "jest tests/markdown/hard-breaks.test.js --verbose --noStackTrace",
|
||||||
"test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace",
|
"test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace",
|
||||||
"test:route": "jest tests/routes/static-pages.test.js --verbose",
|
"test:route": "jest tests/routes/static-pages.test.js --verbose",
|
||||||
"phb": "node scripts/phb.js",
|
"test:safehtml": "jest tests/html/safeHTML.test.js --verbose",
|
||||||
|
"phb": "node --experimental-require-module scripts/phb.js",
|
||||||
"prod": "set NODE_ENV=production && npm run build",
|
"prod": "set NODE_ENV=production && npm run build",
|
||||||
"postinstall": "npm run build",
|
"postinstall": "npm run build",
|
||||||
"start": "node server.js"
|
"start": "node --experimental-require-module server.js"
|
||||||
},
|
},
|
||||||
"author": "stolksdorf",
|
"author": "stolksdorf",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -85,55 +87,57 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.25.2",
|
"@babel/core": "^7.26.0",
|
||||||
"@babel/plugin-transform-runtime": "^7.25.4",
|
"@babel/plugin-transform-runtime": "^7.25.9",
|
||||||
"@babel/preset-env": "^7.25.4",
|
"@babel/preset-env": "^7.26.0",
|
||||||
"@babel/preset-react": "^7.24.7",
|
"@babel/preset-react": "^7.25.9",
|
||||||
"@googleapis/drive": "^8.14.0",
|
"@googleapis/drive": "^8.14.0",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"codemirror": "^5.65.6",
|
"codemirror": "^5.65.6",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.7",
|
||||||
"create-react-class": "^15.7.0",
|
"create-react-class": "^15.7.0",
|
||||||
"dedent-tabs": "^0.10.3",
|
"dedent-tabs": "^0.10.3",
|
||||||
"dompurify": "^3.1.6",
|
"dompurify": "^3.2.0",
|
||||||
"expr-eval": "^2.0.2",
|
"expr-eval": "^2.0.2",
|
||||||
"express": "^4.21.0",
|
"express": "^4.21.1",
|
||||||
"express-async-handler": "^1.2.0",
|
"express-async-handler": "^1.2.0",
|
||||||
"express-static-gzip": "2.1.8",
|
"express-static-gzip": "2.2.0",
|
||||||
"fs-extra": "11.2.0",
|
"fs-extra": "11.2.0",
|
||||||
|
"idb-keyval": "^6.2.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jwt-simple": "^0.5.6",
|
"jwt-simple": "^0.5.6",
|
||||||
"less": "^3.13.1",
|
"less": "^3.13.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"marked": "11.2.0",
|
"marked": "11.2.0",
|
||||||
"marked-emoji": "^1.4.2",
|
"marked-emoji": "^1.4.3",
|
||||||
"marked-extended-tables": "^1.0.10",
|
"marked-extended-tables": "^1.0.10",
|
||||||
"marked-gfm-heading-id": "^3.2.0",
|
"marked-gfm-heading-id": "^3.2.0",
|
||||||
"marked-smartypants-lite": "^1.0.2",
|
"marked-smartypants-lite": "^1.0.2",
|
||||||
"markedLegacy": "npm:marked@^0.3.19",
|
"markedLegacy": "npm:marked@^0.3.19",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"mongoose": "^8.6.3",
|
"mongoose": "^8.8.1",
|
||||||
"nanoid": "3.3.4",
|
"nanoid": "3.3.4",
|
||||||
"nconf": "^0.12.1",
|
"nconf": "^0.12.1",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-frame-component": "^4.1.3",
|
"react-frame-component": "^4.1.3",
|
||||||
"react-router-dom": "6.26.2",
|
"react-router-dom": "6.28.0",
|
||||||
"sanitize-filename": "1.6.3",
|
"sanitize-filename": "1.6.3",
|
||||||
"superagent": "^10.1.0",
|
"superagent": "^10.1.1",
|
||||||
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git"
|
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@stylistic/stylelint-plugin": "^3.0.1",
|
"@stylistic/stylelint-plugin": "^3.1.1",
|
||||||
"eslint": "^9.11.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-plugin-jest": "^28.8.3",
|
"eslint-plugin-jest": "^28.9.0",
|
||||||
"eslint-plugin-react": "^7.36.1",
|
"eslint-plugin-react": "^7.37.2",
|
||||||
"globals": "^15.9.0",
|
"globals": "^15.12.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-expect-message": "^1.1.3",
|
"jest-expect-message": "^1.1.3",
|
||||||
|
"jsdom-global": "^3.0.2",
|
||||||
"postcss-less": "^6.0.0",
|
"postcss-less": "^6.0.0",
|
||||||
"stylelint": "^16.9.0",
|
"stylelint": "^16.10.0",
|
||||||
"stylelint-config-recess-order": "^5.1.1",
|
"stylelint-config-recess-order": "^5.1.1",
|
||||||
"stylelint-config-recommended": "^14.0.1",
|
"stylelint-config-recommended": "^14.0.1",
|
||||||
"supertest": "^7.0.0"
|
"supertest": "^7.0.0"
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
const HomebrewModel = require('./homebrew.model.js').model;
|
const HomebrewModel = require('./homebrew.model.js').model;
|
||||||
|
const NotificationModel = require('./notifications.model.js').model;
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
const Moment = require('moment');
|
const Moment = require('moment');
|
||||||
//const render = require('vitreum/steps/render');
|
|
||||||
const templateFn = require('../client/template.js');
|
const templateFn = require('../client/template.js');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
|
const HomebrewAPI = require('./homebrew.api.js');
|
||||||
|
const asyncHandler = require('express-async-handler');
|
||||||
|
const { splitTextStyleAndMetadata } = require('../shared/helpers.js');
|
||||||
|
|
||||||
process.env.ADMIN_USER = process.env.ADMIN_USER || 'admin';
|
process.env.ADMIN_USER = process.env.ADMIN_USER || 'admin';
|
||||||
process.env.ADMIN_PASS = process.env.ADMIN_PASS || 'password3';
|
process.env.ADMIN_PASS = process.env.ADMIN_PASS || 'password3';
|
||||||
|
|
||||||
@@ -22,7 +26,7 @@ const mw = {
|
|||||||
if(process.env.ADMIN_USER === username && process.env.ADMIN_PASS === password){
|
if(process.env.ADMIN_USER === username && process.env.ADMIN_PASS === password){
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
return res.status(401).send('Access denied');
|
throw { HBErrorCode: '52', code: 401, message: 'Access denied' };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,23 +70,8 @@ router.post('/admin/cleanup', mw.adminOnly, (req, res)=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* Searches for matching edit or share id, also attempts to partial match */
|
/* Searches for matching edit or share id, also attempts to partial match */
|
||||||
router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next)=>{
|
router.get('/admin/lookup/:id', mw.adminOnly, asyncHandler(HomebrewAPI.getBrew('admin', false)), async (req, res, next)=>{
|
||||||
HomebrewModel.findOne({
|
return res.json(req.brew);
|
||||||
$or : [
|
|
||||||
{ editId: { $regex: req.params.id, $options: 'i' } },
|
|
||||||
{ shareId: { $regex: req.params.id, $options: 'i' } },
|
|
||||||
]
|
|
||||||
}).exec()
|
|
||||||
.then((brew)=>{
|
|
||||||
if(!brew) // No document found
|
|
||||||
return res.status(404).json({ error: 'Document not found' });
|
|
||||||
else
|
|
||||||
return res.json(brew);
|
|
||||||
})
|
|
||||||
.catch((err)=>{
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: 'Internal Server Error' });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Find 50 brews that aren't compressed yet */
|
/* Find 50 brews that aren't compressed yet */
|
||||||
@@ -100,6 +89,25 @@ router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Cleans `<script` and `</script>` from the "text" field of a brew */
|
||||||
|
router.put('/admin/clean/script/:id', asyncHandler(HomebrewAPI.getBrew('admin', false)), async (req, res)=>{
|
||||||
|
console.log(`[ADMIN] Cleaning script tags from ShareID ${req.params.id}`);
|
||||||
|
|
||||||
|
function cleanText(text){return text.replaceAll(/(<\/?s)cript/gi, '');};
|
||||||
|
|
||||||
|
const brew = req.brew;
|
||||||
|
|
||||||
|
const properties = ['text', 'description', 'title'];
|
||||||
|
properties.forEach((property)=>{
|
||||||
|
brew[property] = cleanText(brew[property]);
|
||||||
|
});
|
||||||
|
|
||||||
|
splitTextStyleAndMetadata(brew);
|
||||||
|
|
||||||
|
req.body = brew;
|
||||||
|
|
||||||
|
return await HomebrewAPI.updateBrew(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
/* Compresses the "text" field of a brew to binary */
|
/* Compresses the "text" field of a brew to binary */
|
||||||
router.put('/admin/compress/:id', (req, res)=>{
|
router.put('/admin/compress/:id', (req, res)=>{
|
||||||
@@ -138,12 +146,48 @@ router.get('/admin/stats', mw.adminOnly, async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ####################### NOTIFICATIONS
|
||||||
|
|
||||||
|
router.get('/admin/notification/all', async (req, res, next)=>{
|
||||||
|
try {
|
||||||
|
const notifications = await NotificationModel.getAll();
|
||||||
|
return res.json(notifications);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error getting all notifications: ', error.message);
|
||||||
|
return res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/admin/notification/add', mw.adminOnly, async (req, res, next)=>{
|
||||||
|
try {
|
||||||
|
const notification = await NotificationModel.addNotification(req.body);
|
||||||
|
return res.status(201).json(notification);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error adding notification: ', error.message);
|
||||||
|
return res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete('/admin/notification/delete/:id', mw.adminOnly, async (req, res, next)=>{
|
||||||
|
try {
|
||||||
|
const notification = await NotificationModel.deleteNotification(req.params.id);
|
||||||
|
return res.json(notification);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting notification: { key: ', req.params.id, ' error: ', error.message, ' }');
|
||||||
|
return res.status(500).json({ message: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/admin', mw.adminOnly, (req, res)=>{
|
router.get('/admin', mw.adminOnly, (req, res)=>{
|
||||||
templateFn('admin', {
|
templateFn('admin', {
|
||||||
url : req.originalUrl
|
url : req.originalUrl
|
||||||
})
|
})
|
||||||
.then((page)=>res.send(page))
|
.then((page)=>res.send(page))
|
||||||
.catch((err)=>res.sendStatus(500));
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
res.sendStatus(500);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
116
server/admin.api.spec.js
Normal file
116
server/admin.api.spec.js
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
const supertest = require('supertest');
|
||||||
|
|
||||||
|
const app = supertest.agent(require('app.js').app)
|
||||||
|
.set('X-Forwarded-Proto', 'https');
|
||||||
|
|
||||||
|
const NotificationModel = require('./notifications.model.js').model;
|
||||||
|
|
||||||
|
describe('Tests for admin api', ()=>{
|
||||||
|
afterEach(()=>{
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Notifications', ()=>{
|
||||||
|
it('should return list of all notifications', async ()=>{
|
||||||
|
const testNotifications = ['a', 'b'];
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'find')
|
||||||
|
.mockImplementationOnce(() => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue(testNotifications) };
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.get('/admin/notification/all')
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toEqual(testNotifications);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add a new notification', async ()=>{
|
||||||
|
const inputNotification = {
|
||||||
|
title : 'Test Notification',
|
||||||
|
text : 'This is a test notification',
|
||||||
|
startAt : new Date().toISOString(),
|
||||||
|
stopAt : new Date().toISOString(),
|
||||||
|
dismissKey : 'testKey'
|
||||||
|
};
|
||||||
|
|
||||||
|
const savedNotification = {
|
||||||
|
...inputNotification,
|
||||||
|
_id : expect.any(String),
|
||||||
|
createdAt : expect.any(String),
|
||||||
|
startAt : inputNotification.startAt,
|
||||||
|
stopAt : inputNotification.stopAt,
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel.prototype, 'save')
|
||||||
|
.mockImplementationOnce(function() {
|
||||||
|
return Promise.resolve(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.post('/admin/notification/add')
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`)
|
||||||
|
.send(inputNotification);
|
||||||
|
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
expect(response.body).toEqual(savedNotification);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle error adding a notification without dismissKey', async () => {
|
||||||
|
const inputNotification = {
|
||||||
|
title : 'Test Notification',
|
||||||
|
text : 'This is a test notification',
|
||||||
|
startAt : new Date().toISOString(),
|
||||||
|
stopAt : new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
//Change 'save' function to just return itself instead of actually interacting with the database
|
||||||
|
jest.spyOn(NotificationModel.prototype, 'save')
|
||||||
|
.mockImplementationOnce(function() {
|
||||||
|
return Promise.resolve(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.post('/admin/notification/add')
|
||||||
|
.set('Authorization', 'Basic ' + Buffer.from('admin:password3').toString('base64'))
|
||||||
|
.send(inputNotification);
|
||||||
|
|
||||||
|
expect(response.status).toBe(500);
|
||||||
|
expect(response.body).toEqual({ message: 'Dismiss key is required!' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete a notification based on its dismiss key', async ()=>{
|
||||||
|
const dismissKey = 'testKey';
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'findOneAndDelete')
|
||||||
|
.mockImplementationOnce((key) => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue(key) };
|
||||||
|
});
|
||||||
|
const response = await app
|
||||||
|
.delete(`/admin/notification/delete/${dismissKey}`)
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'});
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toEqual({ dismissKey: 'testKey' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle error deleting a notification that doesnt exist', async ()=>{
|
||||||
|
const dismissKey = 'testKey';
|
||||||
|
|
||||||
|
jest.spyOn(NotificationModel, 'findOneAndDelete')
|
||||||
|
.mockImplementationOnce(() => {
|
||||||
|
return { exec: jest.fn().mockResolvedValue() };
|
||||||
|
});
|
||||||
|
const response = await app
|
||||||
|
.delete(`/admin/notification/delete/${dismissKey}`)
|
||||||
|
.set('Authorization', `Basic ${Buffer.from('admin:password3').toString('base64')}`);
|
||||||
|
|
||||||
|
expect(NotificationModel.findOneAndDelete).toHaveBeenCalledWith({'dismissKey': 'testKey'});
|
||||||
|
expect(response.status).toBe(500);
|
||||||
|
expect(response.body).toEqual({ message: 'Notification not found' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -8,6 +8,7 @@ const express = require('express');
|
|||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const app = express();
|
const app = express();
|
||||||
const config = require('./config.js');
|
const config = require('./config.js');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
||||||
const GoogleActions = require('./googleActions.js');
|
const GoogleActions = require('./googleActions.js');
|
||||||
@@ -30,6 +31,8 @@ const sanitizeBrew = (brew, accessType)=>{
|
|||||||
return brew;
|
return brew;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.set('trust proxy', 1 /* number of proxies between user and server */)
|
||||||
|
|
||||||
app.use('/', serveCompressedStaticAssets(`build`));
|
app.use('/', serveCompressedStaticAssets(`build`));
|
||||||
app.use(require('./middleware/content-negotiation.js'));
|
app.use(require('./middleware/content-negotiation.js'));
|
||||||
app.use(require('body-parser').json({ limit: '25mb' }));
|
app.use(require('body-parser').json({ limit: '25mb' }));
|
||||||
@@ -255,6 +258,8 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
brews.forEach(brew => brew.stubbed = true); //All brews from MongoDB are "stubbed"
|
||||||
|
|
||||||
if(ownAccount && req?.account?.googleId){
|
if(ownAccount && req?.account?.googleId){
|
||||||
const auth = await GoogleActions.authCheck(req.account, res);
|
const auth = await GoogleActions.authCheck(req.account, res);
|
||||||
let googleBrews = await GoogleActions.listGoogleBrews(auth)
|
let googleBrews = await GoogleActions.listGoogleBrews(auth)
|
||||||
@@ -262,12 +267,12 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If stub matches file from Google, use Google metadata over stub metadata
|
||||||
if(googleBrews && googleBrews.length > 0) {
|
if(googleBrews && googleBrews.length > 0) {
|
||||||
for (const brew of brews.filter((brew)=>brew.googleId)) {
|
for (const brew of brews.filter((brew)=>brew.googleId)) {
|
||||||
const match = googleBrews.findIndex((b)=>b.editId === brew.editId);
|
const match = googleBrews.findIndex((b)=>b.editId === brew.editId);
|
||||||
if(match !== -1) {
|
if(match !== -1) {
|
||||||
brew.googleId = googleBrews[match].googleId;
|
brew.googleId = googleBrews[match].googleId;
|
||||||
brew.stubbed = true;
|
|
||||||
brew.pageCount = googleBrews[match].pageCount;
|
brew.pageCount = googleBrews[match].pageCount;
|
||||||
brew.renderer = googleBrews[match].renderer;
|
brew.renderer = googleBrews[match].renderer;
|
||||||
brew.version = googleBrews[match].version;
|
brew.version = googleBrews[match].version;
|
||||||
@@ -276,6 +281,7 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Remaining unstubbed google brews display current user as author
|
||||||
googleBrews = googleBrews.map((brew)=>({ ...brew, authors: [req.account.username] }));
|
googleBrews = googleBrews.map((brew)=>({ ...brew, authors: [req.account.username] }));
|
||||||
brews = _.concat(brews, googleBrews);
|
brews = _.concat(brews, googleBrews);
|
||||||
}
|
}
|
||||||
@@ -392,22 +398,12 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
let googleCount = [];
|
let googleCount = [];
|
||||||
if(req.account) {
|
if(req.account) {
|
||||||
if(req.account.googleId) {
|
if(req.account.googleId) {
|
||||||
try {
|
auth = await GoogleActions.authCheck(req.account, res, false)
|
||||||
auth = await GoogleActions.authCheck(req.account, res, false);
|
|
||||||
} catch (e) {
|
googleCount = await GoogleActions.listGoogleBrews(auth)
|
||||||
auth = undefined;
|
.catch((err)=>{
|
||||||
console.log('Google auth check failed!');
|
console.error(err);
|
||||||
console.log(e);
|
});
|
||||||
}
|
|
||||||
if(auth.credentials.access_token) {
|
|
||||||
try {
|
|
||||||
googleCount = await GoogleActions.listGoogleBrews(auth);
|
|
||||||
} catch (e) {
|
|
||||||
googleCount = undefined;
|
|
||||||
console.log('List Google files failed!');
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = { authors: req.account.username, googleId: { $exists: false } };
|
const query = { authors: req.account.username, googleId: { $exists: false } };
|
||||||
@@ -421,7 +417,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
username : req.account.username,
|
username : req.account.username,
|
||||||
issued : req.account.issued,
|
issued : req.account.issued,
|
||||||
googleId : Boolean(req.account.googleId),
|
googleId : Boolean(req.account.googleId),
|
||||||
authCheck : Boolean(req.account.googleId && auth.credentials.access_token),
|
authCheck : Boolean(req.account.googleId && auth?.credentials.access_token),
|
||||||
mongoCount : mongoCount,
|
mongoCount : mongoCount,
|
||||||
googleCount : googleCount?.length
|
googleCount : googleCount?.length
|
||||||
};
|
};
|
||||||
@@ -451,6 +447,10 @@ if(isLocalEnvironment){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add Static Local Paths
|
||||||
|
app.use('/staticImages', express.static(config.get('hb_images') && fs.existsSync(config.get('hb_images')) ? config.get('hb_images') :'staticImages'));
|
||||||
|
app.use('/staticFonts', express.static(config.get('hb_fonts') && fs.existsSync(config.get('hb_fonts')) ? config.get('hb_fonts'):'staticFonts'));
|
||||||
|
|
||||||
//Vault Page
|
//Vault Page
|
||||||
app.get('/vault', asyncHandler(async(req, res, next)=>{
|
app.get('/vault', asyncHandler(async(req, res, next)=>{
|
||||||
req.ogMeta = { ...defaultMetaTags,
|
req.ogMeta = { ...defaultMetaTags,
|
||||||
@@ -462,7 +462,7 @@ app.get('/vault', asyncHandler(async(req, res, next)=>{
|
|||||||
|
|
||||||
//Send rendered page
|
//Send rendered page
|
||||||
app.use(asyncHandler(async (req, res, next)=>{
|
app.use(asyncHandler(async (req, res, next)=>{
|
||||||
if(!req.route) return res.redirect('/'); // Catch-all for invalid routes
|
if (!req.route) return res.redirect('/'); // Catch-all for invalid routes
|
||||||
|
|
||||||
const page = await renderPage(req, res);
|
const page = await renderPage(req, res);
|
||||||
if(!page) return;
|
if(!page) return;
|
||||||
@@ -476,7 +476,7 @@ const renderPage = async (req, res)=>{
|
|||||||
local : isLocalEnvironment,
|
local : isLocalEnvironment,
|
||||||
publicUrl : config.get('publicUrl') ?? '',
|
publicUrl : config.get('publicUrl') ?? '',
|
||||||
environment : nodeEnv,
|
environment : nodeEnv,
|
||||||
history : config.get('historyConfig') ?? {}
|
deployment : config.get('heroku_app_name') ?? ''
|
||||||
};
|
};
|
||||||
const props = {
|
const props = {
|
||||||
version : require('./../package.json').version,
|
version : require('./../package.json').version,
|
||||||
@@ -520,7 +520,7 @@ app.use(async (err, req, res, next)=>{
|
|||||||
err.originalUrl = req.originalUrl;
|
err.originalUrl = req.originalUrl;
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
if(err.originalUrl?.startsWith('/api/')) {
|
if(err.originalUrl?.startsWith('/api')) {
|
||||||
// console.log('API error');
|
// console.log('API error');
|
||||||
res.status(err.status || err.response?.status || 500).send(err);
|
res.status(err.status || err.response?.status || 500).send(err);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ if(!config.get('service_account')){
|
|||||||
|
|
||||||
const defaultAuth = serviceAuth || config.get('google_api_key');
|
const defaultAuth = serviceAuth || config.get('google_api_key');
|
||||||
|
|
||||||
|
const retryConfig = {
|
||||||
|
retry: 3, // Number of retry attempts
|
||||||
|
retryDelay: 100, // Initial delay in milliseconds
|
||||||
|
retryDelayMultiplier: 2, // Multiplier for exponential backoff
|
||||||
|
maxRetryDelay: 32000, // Maximum delay in milliseconds
|
||||||
|
httpMethodsToRetry: ['PATCH'], // Only retry PATCH requests
|
||||||
|
statusCodesToRetry: [[429, 429]], // Only retry on 429 status code
|
||||||
|
};
|
||||||
|
|
||||||
const GoogleActions = {
|
const GoogleActions = {
|
||||||
|
|
||||||
authCheck : (account, res, updateTokens=true)=>{
|
authCheck : (account, res, updateTokens=true)=>{
|
||||||
@@ -112,9 +121,7 @@ const GoogleActions = {
|
|||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log(`Error Listing Google Brews`);
|
console.log(`Error Listing Google Brews`);
|
||||||
console.error(err);
|
|
||||||
throw (err);
|
throw (err);
|
||||||
//TODO: Should break out here, but continues on for some reason.
|
|
||||||
});
|
});
|
||||||
fileList.push(...obj.data.files);
|
fileList.push(...obj.data.files);
|
||||||
NextPageToken = obj.data.nextPageToken;
|
NextPageToken = obj.data.nextPageToken;
|
||||||
@@ -147,7 +154,7 @@ const GoogleActions = {
|
|||||||
return brews;
|
return brews;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateGoogleBrew : async (brew)=>{
|
updateGoogleBrew : async (brew, userIp)=>{
|
||||||
const drive = googleDrive.drive({ version: 'v3', auth: defaultAuth });
|
const drive = googleDrive.drive({ version: 'v3', auth: defaultAuth });
|
||||||
|
|
||||||
await drive.files.update({
|
await drive.files.update({
|
||||||
@@ -168,11 +175,14 @@ const GoogleActions = {
|
|||||||
media : {
|
media : {
|
||||||
mimeType : 'text/plain',
|
mimeType : 'text/plain',
|
||||||
body : brew.text
|
body : brew.text
|
||||||
}
|
},
|
||||||
|
headers: {
|
||||||
|
'X-Forwarded-For': userIp, // Set the X-Forwarded-For header
|
||||||
|
},
|
||||||
|
retryConfig
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log('Error saving to google');
|
console.log('Error saving to google');
|
||||||
console.error(err);
|
|
||||||
throw (err);
|
throw (err);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -211,7 +221,6 @@ const GoogleActions = {
|
|||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log('Error while creating new Google brew');
|
console.log('Error while creating new Google brew');
|
||||||
console.error(err);
|
|
||||||
throw (err);
|
throw (err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,18 @@ const api = {
|
|||||||
// Get relevant IDs for the brew
|
// Get relevant IDs for the brew
|
||||||
const { id, googleId } = api.getId(req);
|
const { id, googleId } = api.getId(req);
|
||||||
|
|
||||||
|
const accessMap = {
|
||||||
|
edit : { editId: id },
|
||||||
|
share : { shareId: id },
|
||||||
|
admin : {
|
||||||
|
$or : [
|
||||||
|
{ editId: id },
|
||||||
|
{ shareId: id },
|
||||||
|
] }
|
||||||
|
};
|
||||||
|
|
||||||
// Try to find the document in the Homebrewery database -- if it doesn't exist, that's fine.
|
// Try to find the document in the Homebrewery database -- if it doesn't exist, that's fine.
|
||||||
let stub = await HomebrewModel.get(accessType === 'edit' ? { editId: id } : { shareId: id })
|
let stub = await HomebrewModel.get(accessMap[accessType])
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
if(googleId) {
|
if(googleId) {
|
||||||
console.warn(`Unable to find document stub for ${accessType}Id ${id}`);
|
console.warn(`Unable to find document stub for ${accessType}Id ${id}`);
|
||||||
@@ -242,11 +252,8 @@ const api = {
|
|||||||
|
|
||||||
let googleId, saved;
|
let googleId, saved;
|
||||||
if(saveToGoogle) {
|
if(saveToGoogle) {
|
||||||
googleId = await api.newGoogleBrew(req.account, newHomebrew, res)
|
googleId = await api.newGoogleBrew(req.account, newHomebrew, res);
|
||||||
.catch((err)=>{
|
|
||||||
console.error(err);
|
|
||||||
res.status(err?.status || err?.response?.status || 500).send(err?.message || err);
|
|
||||||
});
|
|
||||||
if(!googleId) return;
|
if(!googleId) return;
|
||||||
api.excludeStubProps(newHomebrew);
|
api.excludeStubProps(newHomebrew);
|
||||||
newHomebrew.googleId = googleId;
|
newHomebrew.googleId = googleId;
|
||||||
@@ -298,9 +305,8 @@ const api = {
|
|||||||
|
|
||||||
req.params.id = currentTheme.theme;
|
req.params.id = currentTheme.theme;
|
||||||
req.params.renderer = currentTheme.renderer;
|
req.params.renderer = currentTheme.renderer;
|
||||||
}
|
} else {
|
||||||
//=== Static Themes ===//
|
//=== Static Themes ===//
|
||||||
else {
|
|
||||||
const localSnippets = `${req.params.renderer}_${req.params.id}`; // Just log the name for loading on client
|
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\");`;
|
const localStyle = `@import url(\"/themes/${req.params.renderer}/${req.params.id}/style.css\");`;
|
||||||
completeSnippets.push(localSnippets);
|
completeSnippets.push(localSnippets);
|
||||||
@@ -351,19 +357,13 @@ const api = {
|
|||||||
brew.googleId = undefined;
|
brew.googleId = undefined;
|
||||||
} else if(!brew.googleId && saveToGoogle) {
|
} else if(!brew.googleId && saveToGoogle) {
|
||||||
// If we don't have a google id and the user wants to save to google, create the google brew and set the google id on the brew
|
// If we don't have a google id and the user wants to save to google, create the google brew and set the google id on the brew
|
||||||
brew.googleId = await api.newGoogleBrew(req.account, api.excludeGoogleProps(brew), res)
|
brew.googleId = await api.newGoogleBrew(req.account, api.excludeGoogleProps(brew), res);
|
||||||
.catch((err)=>{
|
|
||||||
console.error(err);
|
|
||||||
res.status(err.status || err.response.status).send(err.message || err);
|
|
||||||
});
|
|
||||||
if(!brew.googleId) return;
|
if(!brew.googleId) return;
|
||||||
} else if(brew.googleId) {
|
} else if(brew.googleId) {
|
||||||
// If the google id exists and no other actions are being performed, update the google brew
|
// If the google id exists and no other actions are being performed, update the google brew
|
||||||
const updated = await GoogleActions.updateGoogleBrew(api.excludeGoogleProps(brew))
|
const updated = await GoogleActions.updateGoogleBrew(api.excludeGoogleProps(brew), req.ip);
|
||||||
.catch((err)=>{
|
|
||||||
console.error(err);
|
|
||||||
res.status(err?.response?.status || 500).send(err);
|
|
||||||
});
|
|
||||||
if(!updated) return;
|
if(!updated) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -560,16 +560,6 @@ brew`);
|
|||||||
views : 0
|
views : 0
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle google error', async()=>{
|
|
||||||
google.newGoogleBrew = jest.fn(()=>{
|
|
||||||
throw 'err';
|
|
||||||
});
|
|
||||||
await api.newBrew({ body: { text: 'asdf', title: '' }, query: { saveToGoogle: true }, account: { username: 'test user' } }, res);
|
|
||||||
|
|
||||||
expect(res.status).toHaveBeenCalledWith(500);
|
|
||||||
expect(res.send).toHaveBeenCalledWith('err');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteGoogleBrew', ()=>{
|
describe('deleteGoogleBrew', ()=>{
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
const config = require('../config.js');
|
||||||
|
const nodeEnv = config.get('node_env');
|
||||||
|
const isLocalEnvironment = config.get('local_environments').includes(nodeEnv);
|
||||||
|
|
||||||
module.exports = (req, res, next)=>{
|
module.exports = (req, res, next)=>{
|
||||||
const isImageRequest = req.get('Accept')?.split(',')
|
const isImageRequest = req.get('Accept')?.split(',')
|
||||||
?.filter((h)=>!h.includes('q='))
|
?.filter((h)=>!h.includes('q='))
|
||||||
?.every((h)=>/image\/.*/.test(h));
|
?.every((h)=>/image\/.*/.test(h));
|
||||||
if(isImageRequest) {
|
if(isImageRequest && !isLocalEnvironment && !req.url?.startsWith('/staticImages')) {
|
||||||
return res.status(406).send({
|
return res.status(406).send({
|
||||||
message : 'Request for image at this URL is not supported'
|
message : 'Request for image at this URL is not supported'
|
||||||
});
|
});
|
||||||
|
|||||||
62
server/notifications.model.js
Normal file
62
server/notifications.model.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
const mongoose = require('mongoose');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const NotificationSchema = new mongoose.Schema({
|
||||||
|
dismissKey : { type: String, unique: true, required: true },
|
||||||
|
title : { type: String, default: '' },
|
||||||
|
text : { type: String, default: '' },
|
||||||
|
createdAt : { type: Date, default: Date.now },
|
||||||
|
startAt : { type: Date, default: Date.now },
|
||||||
|
stopAt : { type: Date, default: Date.now },
|
||||||
|
}, { versionKey: false });
|
||||||
|
|
||||||
|
NotificationSchema.statics.addNotification = async function(data) {
|
||||||
|
if(!data.dismissKey) throw { message: 'Dismiss key is required!' };
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
title : '',
|
||||||
|
text : '',
|
||||||
|
startAt : new Date(),
|
||||||
|
stopAt : new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const notificationData = _.defaults(data, defaults);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newNotification = new this(notificationData);
|
||||||
|
const savedNotification = await newNotification.save();
|
||||||
|
return savedNotification;
|
||||||
|
} catch (err) {
|
||||||
|
throw { message: err.message || 'Error saving notification' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationSchema.statics.deleteNotification = async function(dismissKey) {
|
||||||
|
if(!dismissKey) throw { message: 'Dismiss key is required!' };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deletedNotification = await this.findOneAndDelete({ dismissKey }).exec();
|
||||||
|
if(!deletedNotification) {
|
||||||
|
throw { message: 'Notification not found' };
|
||||||
|
}
|
||||||
|
return deletedNotification;
|
||||||
|
} catch (err) {
|
||||||
|
throw { message: err.message || 'Error deleting notification' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationSchema.statics.getAll = async function() {
|
||||||
|
try {
|
||||||
|
const notifications = await this.find().exec();
|
||||||
|
return notifications;
|
||||||
|
} catch (err) {
|
||||||
|
throw { message: err.message || 'Error retrieving notifications' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Notification = mongoose.model('Notification', NotificationSchema);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
schema : NotificationSchema,
|
||||||
|
model : Notification,
|
||||||
|
};
|
||||||
@@ -12,10 +12,8 @@ const Nav = {
|
|||||||
displayName : 'Nav.base',
|
displayName : 'Nav.base',
|
||||||
render : function(){
|
render : function(){
|
||||||
return <nav>
|
return <nav>
|
||||||
<div className='navContent'>
|
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</nav>;
|
||||||
</nav>;
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
logo : function(){
|
logo : function(){
|
||||||
|
|||||||
@@ -1,200 +1,110 @@
|
|||||||
require('./splitPane.less');
|
require('./splitPane.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const { useState, useEffect } = React;
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const SplitPane = createClass({
|
const storageKey = 'naturalcrit-pane-split';
|
||||||
displayName : 'SplitPane',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
storageKey : 'naturalcrit-pane-split',
|
|
||||||
onDragFinish : function(){}, //fires when dragging
|
|
||||||
showDividerButtons : true
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
const SplitPane = (props)=>{
|
||||||
return {
|
const {
|
||||||
currentDividerPos : null,
|
onDragFinish = ()=>{},
|
||||||
windowWidth : 0,
|
showDividerButtons = true
|
||||||
isDragging : false,
|
} = props;
|
||||||
moveSource : false,
|
|
||||||
moveBrew : false,
|
|
||||||
showMoveArrows : true
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
pane1 : React.createRef(null),
|
const [isDragging, setIsDragging] = useState(false);
|
||||||
pane2 : React.createRef(null),
|
const [dividerPos, setDividerPos] = useState(null);
|
||||||
|
const [moveSource, setMoveSource] = useState(false);
|
||||||
|
const [moveBrew, setMoveBrew] = useState(false);
|
||||||
|
const [showMoveArrows, setShowMoveArrows] = useState(true);
|
||||||
|
const [liveScroll, setLiveScroll] = useState(false);
|
||||||
|
|
||||||
componentDidMount : function() {
|
useEffect(()=>{
|
||||||
const dividerPos = window.localStorage.getItem(this.props.storageKey);
|
const savedPos = window.localStorage.getItem(storageKey);
|
||||||
if(dividerPos){
|
setDividerPos(savedPos ? limitPosition(savedPos, 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) : window.innerWidth / 2);
|
||||||
this.setState({
|
setLiveScroll(window.localStorage.getItem('liveScroll') === 'true');
|
||||||
currentDividerPos : this.limitPosition(dividerPos, 0.1*(window.innerWidth-13), 0.9*(window.innerWidth-13)),
|
|
||||||
userSetDividerPos : dividerPos,
|
|
||||||
windowWidth : window.innerWidth
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
currentDividerPos : window.innerWidth / 2,
|
|
||||||
userSetDividerPos : window.innerWidth / 2
|
|
||||||
});
|
|
||||||
}
|
|
||||||
window.addEventListener('resize', this.handleWindowResize);
|
|
||||||
|
|
||||||
// This lives here instead of in the initial render because you cannot touch localStorage until the componant mounts.
|
window.addEventListener('resize', handleResize);
|
||||||
const loadLiveScroll = window.localStorage.getItem('liveScroll') === 'true';
|
return ()=>window.removeEventListener('resize', handleResize);
|
||||||
this.setState({ liveScroll: loadLiveScroll });
|
}, []);
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount : function() {
|
const limitPosition = (x, min = 1, max = window.innerWidth - 13)=>Math.round(Math.min(max, Math.max(min, x)));
|
||||||
window.removeEventListener('resize', this.handleWindowResize);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleWindowResize : function() {
|
//when resizing, the divider should grow smaller if less space is given, then grow back if the space is restored, to the original position
|
||||||
// Allow divider to increase in size to last user-set position
|
const handleResize = () =>setDividerPos(limitPosition(window.localStorage.getItem(storageKey), 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)));
|
||||||
// Limit current position to between 10% and 90% of visible space
|
|
||||||
const newLoc = this.limitPosition(this.state.userSetDividerPos, 0.1*(window.innerWidth-13), 0.9*(window.innerWidth-13));
|
|
||||||
|
|
||||||
this.setState({
|
const handleUp =(e)=>{
|
||||||
currentDividerPos : newLoc,
|
|
||||||
windowWidth : window.innerWidth
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
limitPosition : function(x, min = 1, max = window.innerWidth - 13) {
|
|
||||||
const result = Math.round(Math.min(max, Math.max(min, x)));
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
handleUp : function(e){
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if(this.state.isDragging){
|
if(isDragging) {
|
||||||
this.props.onDragFinish(this.state.currentDividerPos);
|
onDragFinish(dividerPos);
|
||||||
window.localStorage.setItem(this.props.storageKey, this.state.currentDividerPos);
|
window.localStorage.setItem(storageKey, dividerPos);
|
||||||
}
|
}
|
||||||
this.setState({ isDragging: false });
|
setIsDragging(false);
|
||||||
},
|
};
|
||||||
|
|
||||||
handleDown : function(e){
|
const handleDown = (e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.setState({ isDragging: true });
|
setIsDragging(true);
|
||||||
//this.unFocus()
|
};
|
||||||
},
|
|
||||||
|
|
||||||
handleMove : function(e){
|
|
||||||
if(!this.state.isDragging) return;
|
|
||||||
|
|
||||||
|
const handleMove = (e)=>{
|
||||||
|
if(!isDragging) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const newSize = this.limitPosition(e.pageX);
|
setDividerPos(limitPosition(e.pageX));
|
||||||
this.setState({
|
};
|
||||||
currentDividerPos : newSize,
|
|
||||||
userSetDividerPos : newSize
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
liveScrollToggle : function() {
|
const liveScrollToggle = ()=>{
|
||||||
window.localStorage.setItem('liveScroll', String(!this.state.liveScroll));
|
window.localStorage.setItem('liveScroll', String(!liveScroll));
|
||||||
this.setState({ liveScroll: !this.state.liveScroll });
|
setLiveScroll(!liveScroll);
|
||||||
},
|
};
|
||||||
/*
|
|
||||||
unFocus : function() {
|
|
||||||
if(document.selection){
|
|
||||||
document.selection.empty();
|
|
||||||
}else{
|
|
||||||
window.getSelection().removeAllRanges();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
|
|
||||||
setMoveArrows : function(newState) {
|
const renderMoveArrows = (showMoveArrows &&
|
||||||
if(this.state.showMoveArrows != newState){
|
<>
|
||||||
this.setState({
|
<div className='arrow left'
|
||||||
showMoveArrows : newState
|
onClick={()=>setMoveSource(!moveSource)} >
|
||||||
});
|
<i className='fas fa-arrow-left' />
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
renderMoveArrows : function(){
|
|
||||||
if(this.state.showMoveArrows) {
|
|
||||||
return <>
|
|
||||||
<div className='arrow left'
|
|
||||||
style={{ left: this.state.currentDividerPos-4 }}
|
|
||||||
onClick={()=>this.setState({ moveSource: !this.state.moveSource })} >
|
|
||||||
<i className='fas fa-arrow-left' />
|
|
||||||
</div>
|
|
||||||
<div className='arrow right'
|
|
||||||
style={{ left: this.state.currentDividerPos-4 }}
|
|
||||||
onClick={()=>this.setState({ moveBrew: !this.state.moveBrew })} >
|
|
||||||
<i className='fas fa-arrow-right' />
|
|
||||||
</div>
|
|
||||||
<div id='scrollToggleDiv' className={this.state.liveScroll ? 'arrow lock' : 'arrow unlock'}
|
|
||||||
style={{ left: this.state.currentDividerPos-4 }}
|
|
||||||
onClick={this.liveScrollToggle} >
|
|
||||||
<i id='scrollToggle' className={this.state.liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
|
||||||
</div>
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
renderDivider : function(){
|
|
||||||
return <>
|
|
||||||
{this.props.showDividerButtons && this.renderMoveArrows()}
|
|
||||||
<div className='divider' onPointerDown={this.handleDown} >
|
|
||||||
<div className='dots'>
|
|
||||||
<i className='fas fa-circle' />
|
|
||||||
<i className='fas fa-circle' />
|
|
||||||
<i className='fas fa-circle' />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</>;
|
<div className='arrow right'
|
||||||
},
|
onClick={()=>setMoveBrew(!moveBrew)} >
|
||||||
|
<i className='fas fa-arrow-right' />
|
||||||
|
</div>
|
||||||
|
<div id='scrollToggleDiv' className={liveScroll ? 'arrow lock' : 'arrow unlock'}
|
||||||
|
onClick={liveScrollToggle} >
|
||||||
|
<i id='scrollToggle' className={liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
render : function(){
|
const renderDivider = (
|
||||||
return <div className='splitPane' onPointerMove={this.handleMove} onPointerUp={this.handleUp}>
|
<div className={`divider ${isDragging && 'dragging'}`} onPointerDown={handleDown}>
|
||||||
<Pane
|
{showDividerButtons && renderMoveArrows}
|
||||||
width={this.state.currentDividerPos}
|
<div className='dots'>
|
||||||
>
|
<i className='fas fa-circle' />
|
||||||
{React.cloneElement(this.props.children[0], {
|
<i className='fas fa-circle' />
|
||||||
...(this.props.showDividerButtons && {
|
<i className='fas fa-circle' />
|
||||||
moveBrew : this.state.moveBrew,
|
</div>
|
||||||
moveSource : this.state.moveSource,
|
</div>
|
||||||
liveScroll : this.state.liveScroll,
|
);
|
||||||
setMoveArrows : this.setMoveArrows,
|
|
||||||
}),
|
return (
|
||||||
})}
|
<div className='splitPane' onPointerMove={handleMove} onPointerUp={handleUp}>
|
||||||
|
<Pane width={dividerPos} moveBrew={moveBrew} moveSource={moveSource} liveScroll={liveScroll} setMoveArrows={setShowMoveArrows}>
|
||||||
|
{props.children[0]}
|
||||||
</Pane>
|
</Pane>
|
||||||
{this.renderDivider()}
|
{renderDivider}
|
||||||
<Pane isDragging={this.state.isDragging}>{this.props.children[1]}</Pane>
|
<Pane isDragging={isDragging}>{props.children[1]}</Pane>
|
||||||
</div>;
|
</div>
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
const Pane = createClass({
|
const Pane = ({ width, children, isDragging, moveBrew, moveSource, liveScroll, setMoveArrows })=>{
|
||||||
displayName : 'Pane',
|
const styles = width
|
||||||
getDefaultProps : function() {
|
? { flex: 'none', width: `${width}px` }
|
||||||
return {
|
: { pointerEvents: isDragging ? 'none' : 'auto' }; //Disable mouse capture in the right pane; else dragging into the iframe drops the divider
|
||||||
width : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
let styles = {};
|
|
||||||
if(this.props.width){
|
|
||||||
styles = {
|
|
||||||
flex : 'none',
|
|
||||||
width : `${this.props.width}px`
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
styles = {
|
|
||||||
pointerEvents : this.props.isDragging ? 'none' : 'auto' //Disable mouse capture in the rightmost pane; dragging into the iframe drops the divider otherwise
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div className={cx('pane', this.props.className)} style={styles}>
|
return (
|
||||||
{this.props.children}
|
<div className='pane' style={styles}>
|
||||||
</div>;
|
{React.cloneElement(children, { moveBrew, moveSource, liveScroll, setMoveArrows })}
|
||||||
}
|
</div>
|
||||||
});
|
);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = SplitPane;
|
module.exports = SplitPane;
|
||||||
|
|||||||
@@ -1,69 +1,68 @@
|
|||||||
|
|
||||||
.splitPane{
|
.splitPane {
|
||||||
position : relative;
|
position : relative;
|
||||||
display : flex;
|
display : flex;
|
||||||
|
flex-direction : row;
|
||||||
height : 100%;
|
height : 100%;
|
||||||
outline : none;
|
outline : none;
|
||||||
flex-direction : row;
|
.pane {
|
||||||
.pane{
|
flex : 1;
|
||||||
overflow-x : hidden;
|
overflow-x : hidden;
|
||||||
overflow-y : hidden;
|
overflow-y : hidden;
|
||||||
flex : 1;
|
|
||||||
}
|
}
|
||||||
.divider{
|
.divider {
|
||||||
touch-action : none;
|
position : relative;
|
||||||
display : table;
|
display : table;
|
||||||
height : 100%;
|
|
||||||
width : 15px;
|
width : 15px;
|
||||||
cursor : ew-resize;
|
height : 100%;
|
||||||
background-color : #bbb;
|
|
||||||
text-align : center;
|
text-align : center;
|
||||||
.dots{
|
touch-action : none;
|
||||||
|
cursor : ew-resize;
|
||||||
|
background-color : #BBBBBB;
|
||||||
|
.dots {
|
||||||
display : table-cell;
|
display : table-cell;
|
||||||
vertical-align : middle;
|
|
||||||
text-align : center;
|
text-align : center;
|
||||||
i{
|
vertical-align : middle;
|
||||||
|
i {
|
||||||
display : block !important;
|
display : block !important;
|
||||||
margin : 10px 0px;
|
margin : 10px 0px;
|
||||||
font-size : 6px;
|
font-size : 6px;
|
||||||
color : #666;
|
color : #666666;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&:hover{
|
&:hover,&.dragging { background-color : #999999; }
|
||||||
background-color: #999;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.arrow{
|
.arrow {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
|
left : 50%;
|
||||||
|
z-index : 999;
|
||||||
width : 25px;
|
width : 25px;
|
||||||
height : 25px;
|
height : 25px;
|
||||||
border : 2px solid #bbb;
|
|
||||||
border-radius : 15px;
|
|
||||||
text-align : center;
|
|
||||||
font-size : 1.2em;
|
font-size : 1.2em;
|
||||||
|
text-align : center;
|
||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
background-color : #ddd;
|
background-color : #DDDDDD;
|
||||||
z-index : 999;
|
border : 2px solid #BBBBBB;
|
||||||
box-shadow : 0 4px 5px #0000007f;
|
border-radius : 15px;
|
||||||
&.left{
|
box-shadow : 0 4px 5px #0000007F;
|
||||||
|
translate : -50%;
|
||||||
|
&.left {
|
||||||
.tooltipLeft('Jump to location in Editor');
|
.tooltipLeft('Jump to location in Editor');
|
||||||
top : 30px;
|
top : 30px;
|
||||||
}
|
}
|
||||||
&.right{
|
&.right {
|
||||||
.tooltipRight('Jump to location in Preview');
|
.tooltipRight('Jump to location in Preview');
|
||||||
top : 60px;
|
top : 60px;
|
||||||
}
|
}
|
||||||
&.lock{
|
&.lock {
|
||||||
.tooltipRight('De-sync Editor and Preview locations.');
|
.tooltipRight('De-sync Editor and Preview locations.');
|
||||||
top : 90px;
|
top : 90px;
|
||||||
background: #666;
|
background : #666666;
|
||||||
}
|
}
|
||||||
&.unlock{
|
&.unlock {
|
||||||
.tooltipRight('Sync Editor and Preview locations');
|
.tooltipRight('Sync Editor and Preview locations');
|
||||||
top : 90px;
|
top : 90px;
|
||||||
}
|
}
|
||||||
&:hover{
|
&:hover { background-color : #666666; }
|
||||||
background-color: #666;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ html,body, #reactRoot{
|
|||||||
*{
|
*{
|
||||||
box-sizing : border-box;
|
box-sizing : border-box;
|
||||||
}
|
}
|
||||||
button{
|
.colorButton(@backgroundColor : @green){
|
||||||
.button();
|
|
||||||
}
|
|
||||||
.button(@backgroundColor : @green){
|
|
||||||
.animate(background-color);
|
.animate(background-color);
|
||||||
display : inline-block;
|
display : inline-block;
|
||||||
padding : 0.6em 1.2em;
|
padding : 0.6em 1.2em;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
:where(html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video){
|
:where(html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,button,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video){
|
||||||
border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0
|
border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,3 +25,9 @@
|
|||||||
:where(table){
|
:where(table){
|
||||||
border-collapse:collapse;border-spacing:0
|
border-collapse:collapse;border-spacing:0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:where(button) {
|
||||||
|
background-color: unset;
|
||||||
|
text-transform: unset;
|
||||||
|
color: unset;
|
||||||
|
}
|
||||||
|
|||||||
50
tests/html/safeHTML.test.js
Normal file
50
tests/html/safeHTML.test.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
|
||||||
|
require('jsdom-global')();
|
||||||
|
|
||||||
|
import { safeHTML } from '../../client/homebrew/brewRenderer/safeHTML';
|
||||||
|
|
||||||
|
test('Javascript via href', function() {
|
||||||
|
const source = `<a href="javascript:alert('This is a JavaScript injection via href attribute')">Click me</a>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<a>Click me</a>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Javascript via src', function() {
|
||||||
|
const source = `<img src="javascript:alert('This is a JavaScript injection via src attribute')">`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<img>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Javascript via form submit action', function() {
|
||||||
|
const source = `<form action="javascript:alert('This is a JavaScript injection via action attribute')">\n<input type="submit" value="Submit">\n</form>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<form>\n<input value=\"Submit\">\n</form>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Javascript via inline event handler - onClick', function() {
|
||||||
|
const source = `<div style="background-color: red; color: white; width: 100px; height: 100px;" onclick="alert('This is a JavaScript injection via inline event handler')">\nClick me\n</div>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<div style=\"background-color: red; color: white; width: 100px; height: 100px;\">\nClick me\n</div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Javascript via inline event handler - onMouseOver', function() {
|
||||||
|
const source = `<div onmouseover="alert('This is a JavaScript injection via inline event handler')">Hover over me</div>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<div>Hover over me</div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Javascript via data attribute', function() {
|
||||||
|
const source = `<div data-code="javascript:alert('This is a JavaScript injection via data attribute')">Test</div>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<div>Test</div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Javascript via event delegation', function() {
|
||||||
|
const source = `<div id="parent"><button id="child">Click me</button></div><script>document.getElementById('parent').addEventListener('click', function(event) {if (event.target.id === 'child') {console.log('This is JavaScript executed via event delegation');}});</script>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<div id="parent"><button id="child">Click me</button></div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -154,28 +154,6 @@ module.exports = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
name : 'Table of Contents Toggles',
|
|
||||||
icon : 'fas fa-book',
|
|
||||||
gen : `{{tocGlobalH4}}\n\n`,
|
|
||||||
subsnippets : [
|
|
||||||
{
|
|
||||||
name : 'Enable H1-H4 all pages',
|
|
||||||
icon : 'fas fa-dice-four',
|
|
||||||
gen : `{{tocGlobalH4}}\n\n`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Enable H1-H5 all pages',
|
|
||||||
icon : 'fas fa-dice-five',
|
|
||||||
gen : `{{tocGlobalH5}}\n\n`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name : 'Enable H1-H6 all pages',
|
|
||||||
icon : 'fas fa-dice-six',
|
|
||||||
gen : `{{tocGlobalH6}}\n\n`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -214,6 +192,27 @@ module.exports = [
|
|||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
}\n\n`
|
}\n\n`
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name : 'Table of Contents Toggles',
|
||||||
|
icon : 'fas fa-book',
|
||||||
|
subsnippets : [
|
||||||
|
{
|
||||||
|
name : 'Enable H1-H4 all pages',
|
||||||
|
icon : 'fas fa-dice-four',
|
||||||
|
gen : `.page {\n\th4 {--TOC: include; }\n}\n\n`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name : 'Enable H1-H5 all pages',
|
||||||
|
icon : 'fas fa-dice-five',
|
||||||
|
gen : `.page {\n\th4, h5 {--TOC: include; }\n}\n\n`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name : 'Enable H1-H6 all pages',
|
||||||
|
icon : 'fas fa-dice-six',
|
||||||
|
gen : `.page {\n\th4, h5, h6 {--TOC: include; }\n}\n\n`,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -812,17 +812,8 @@ h6,
|
|||||||
|
|
||||||
// Brew level default inclusion changes.
|
// Brew level default inclusion changes.
|
||||||
// These add Headers 'back' to inclusion.
|
// These add Headers 'back' to inclusion.
|
||||||
.pages:has(.tocGlobalH4) {
|
|
||||||
h4 {--TOC: include; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.pages:has(.tocGlobalH5) {
|
//NOTE: DO NOT USE :HAS WITH .PAGES!!! EXTREMELY SLOW TO RENDER ON LARGE DOCS!
|
||||||
h4, h5 {--TOC: include; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.pages:has(.tocGlobalH6) {
|
|
||||||
h4, h5, h6 {--TOC: include; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Block level inclusion changes
|
// Block level inclusion changes
|
||||||
// These include either a single (include) or a range (depth)
|
// These include either a single (include) or a range (depth)
|
||||||
|
|||||||
Reference in New Issue
Block a user