mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-27 22:33:07 +00:00
Compare commits
357 Commits
reduceTypi
...
v3.16.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
add088c2a9 | ||
|
|
6d8415bfeb | ||
|
|
decb334808 | ||
|
|
66f71972eb | ||
|
|
ebe8e1067c | ||
|
|
9807cf762b | ||
|
|
b58563cb42 | ||
|
|
7c3f3b87af | ||
|
|
e7daad592c | ||
|
|
992359e239 | ||
|
|
b2546f3458 | ||
|
|
6f016bf5b6 | ||
|
|
7cd3c69fbd | ||
|
|
9b1507d4f5 | ||
|
|
2e49bf4fa8 | ||
|
|
e5624434d6 | ||
|
|
1850173f87 | ||
|
|
fb9148ada5 | ||
|
|
b857a91ab8 | ||
|
|
b7c49218ae | ||
|
|
f4d4334a75 | ||
|
|
38b4c285a3 | ||
|
|
cf46a975aa | ||
|
|
9f693547f7 | ||
|
|
a69dd998f5 | ||
|
|
f141515446 | ||
|
|
f749706cb3 | ||
|
|
b22f3d041c | ||
|
|
dd8692d82b | ||
|
|
0d2dfe66bc | ||
|
|
0437635861 | ||
|
|
a5f12ca0b4 | ||
|
|
07e0a7c1b5 | ||
|
|
2e9c7b1d9b | ||
|
|
0ddc3ae5b9 | ||
|
|
8c6c8f861d | ||
|
|
107aa34ee4 | ||
|
|
e006826e3e | ||
|
|
4e4463fe4d | ||
|
|
1a56c393ab | ||
|
|
9bc4b1fb56 | ||
|
|
234d484a74 | ||
|
|
dc1d40512b | ||
|
|
2dafbf2080 | ||
|
|
033b7fa44f | ||
|
|
2c4f705072 | ||
|
|
ee811e94e1 | ||
|
|
fcae147723 | ||
|
|
b3793a3330 | ||
|
|
952b67aed3 | ||
|
|
27f14b042b | ||
|
|
49d30007d3 | ||
|
|
bd26f02ddb | ||
|
|
ccc37fc0d5 | ||
|
|
9973999e86 | ||
|
|
2aec54748a | ||
|
|
5585c27cb8 | ||
|
|
52ae343309 | ||
|
|
f8d60fc4da | ||
|
|
69e827a663 | ||
|
|
d1d73023a2 | ||
|
|
f4af19ed81 | ||
|
|
bc5a9c9039 | ||
|
|
f7dfedcd44 | ||
|
|
b7b1981bde | ||
|
|
2e8368d08c | ||
|
|
c6b0b6a0ea | ||
|
|
7c7326b42a | ||
|
|
d0cf6eebbb | ||
|
|
0ba838f5ae | ||
|
|
172a3eaadf | ||
|
|
b868ba9406 | ||
|
|
89a16956b9 | ||
|
|
b098d28407 | ||
|
|
1be1b3b747 | ||
|
|
f63d2de8f4 | ||
|
|
626b602a61 | ||
|
|
3d7d90104b | ||
|
|
422fd7bb57 | ||
|
|
c7c8dafb18 | ||
|
|
ea25ae625a | ||
|
|
ebf900ba24 | ||
|
|
0037c91cc5 | ||
|
|
8a8bf883e6 | ||
|
|
17539cb80b | ||
|
|
bb057ba057 | ||
|
|
99ad865311 | ||
|
|
48baaa33e2 | ||
|
|
6f07d25101 | ||
|
|
fec904b4c6 | ||
|
|
a29aca32e7 | ||
|
|
6fed42198d | ||
|
|
446406758f | ||
|
|
2d9da23c25 | ||
|
|
b24c9daa08 | ||
|
|
f5bc490380 | ||
|
|
4673303bc2 | ||
|
|
e550ab4046 | ||
|
|
be4ba06081 | ||
|
|
0fda0673b2 | ||
|
|
9edf65c252 | ||
|
|
3f8ec30f89 | ||
|
|
f1bebe3895 | ||
|
|
f5954b03f2 | ||
|
|
a265723c57 | ||
|
|
ca90e1804a | ||
|
|
e7c0cdae3d | ||
|
|
db75e0dd66 | ||
|
|
56d024a2e6 | ||
|
|
f6ed348824 | ||
|
|
a4406d953a | ||
|
|
1a41252d70 | ||
|
|
97371be26a | ||
|
|
994fbd197a | ||
|
|
4995aebb93 | ||
|
|
782fa3a2a0 | ||
|
|
5f71d2902b | ||
|
|
391d0a0bfe | ||
|
|
782ee7a4ad | ||
|
|
987063422d | ||
|
|
26afb67f61 | ||
|
|
d2f6bc03db | ||
|
|
547bedb5f9 | ||
|
|
1b4d41fc19 | ||
|
|
6f2252635a | ||
|
|
46eac41021 | ||
|
|
43441f3185 | ||
|
|
f2765650f7 | ||
|
|
a017c28b02 | ||
|
|
ef1e0f1faa | ||
|
|
5dc961505b | ||
|
|
b129ec1469 | ||
|
|
adcbd7c4c8 | ||
|
|
843aa6d769 | ||
|
|
8ab9b842fc | ||
|
|
f8b5a8133e | ||
|
|
478a541d62 | ||
|
|
eb852b8045 | ||
|
|
07e7f3e70c | ||
|
|
fea8f157a7 | ||
|
|
898be28af3 | ||
|
|
63f6f6d3c6 | ||
|
|
ac2de613c5 | ||
|
|
948f03b5b8 | ||
|
|
28894adeab | ||
|
|
9770fea3fd | ||
|
|
422257743e | ||
|
|
e3619bb1fc | ||
|
|
db1fdca3ab | ||
|
|
c2f56833f3 | ||
|
|
d3cc5c890b | ||
|
|
8eac8eff4b | ||
|
|
8bede8f0ee | ||
|
|
c7894499b1 | ||
|
|
55a50ce261 | ||
|
|
5b675918ad | ||
|
|
70046e00f8 | ||
|
|
e129eb2f5d | ||
|
|
56c9413ab5 | ||
|
|
671044ca3a | ||
|
|
04baabc27d | ||
|
|
4add67086d | ||
|
|
66451a3b1e | ||
|
|
785041dcd1 | ||
|
|
40bb823efa | ||
|
|
0dd5b262f7 | ||
|
|
2ed6aad6f7 | ||
|
|
41cbb67155 | ||
|
|
1ab6ef078e | ||
|
|
25a7af5b70 | ||
|
|
5f41decdb6 | ||
|
|
3a1053ad70 | ||
|
|
d768a41746 | ||
|
|
f5f22fe0e9 | ||
|
|
27c5f86205 | ||
|
|
361d1c1aff | ||
|
|
88e5f26dd8 | ||
|
|
ddfccba822 | ||
|
|
069d054e30 | ||
|
|
1f7ff4386b | ||
|
|
6373c398bc | ||
|
|
7a78408415 | ||
|
|
52311f989d | ||
|
|
b9bf9c7e70 | ||
|
|
45ada35a11 | ||
|
|
9d2a305f03 | ||
|
|
9cc7799d5c | ||
|
|
c235695f04 | ||
|
|
999a96b5ce | ||
|
|
ef5e3ddf4c | ||
|
|
d5f498cbf9 | ||
|
|
5040b9528f | ||
|
|
83a48b8d0c | ||
|
|
9fbdd24d01 | ||
|
|
5b136f651c | ||
|
|
effeef0d67 | ||
|
|
cf3d5df582 | ||
|
|
71cdbf1079 | ||
|
|
712db7dfa7 | ||
|
|
ed48c6664b | ||
|
|
917f20cdd5 | ||
|
|
0c98f832bb | ||
|
|
41a60e6312 | ||
|
|
5994e0d0b3 | ||
|
|
c723f820f7 | ||
|
|
0e9021049c | ||
|
|
1d663ef38d | ||
|
|
d3e11ead54 | ||
|
|
79e1f4caf7 | ||
|
|
59e397a65a | ||
|
|
6b066c3fd3 | ||
|
|
b7413714be | ||
|
|
ec49d5e526 | ||
|
|
d53a271c9f | ||
|
|
9d81f50b60 | ||
|
|
ac766f3b37 | ||
|
|
cd09408aa8 | ||
|
|
631ef795b7 | ||
|
|
01c4e3ec1f | ||
|
|
5a75182aff | ||
|
|
8538ccabe6 | ||
|
|
8ef88a4799 | ||
|
|
189625c79b | ||
|
|
d872a496a7 | ||
|
|
a1d2b5314b | ||
|
|
9a4473526a | ||
|
|
5077fda3f6 | ||
|
|
397ae31f56 | ||
|
|
f2f06b23fd | ||
|
|
87915ef0ef | ||
|
|
c9240c7023 | ||
|
|
e54d237a19 | ||
|
|
ccfd5578cf | ||
|
|
618e865e52 | ||
|
|
4dd07a3c11 | ||
|
|
7888bfa878 | ||
|
|
154ee06fc4 | ||
|
|
810c2140c9 | ||
|
|
c4fbc8d827 | ||
|
|
96ae07a456 | ||
|
|
0d1291a713 | ||
|
|
3c66907a86 | ||
|
|
0663e82fa1 | ||
|
|
6e241c5bcd | ||
|
|
ebe5dca7a9 | ||
|
|
b33d9264d3 | ||
|
|
0855c5c181 | ||
|
|
1741abc3fe | ||
|
|
63f4104f81 | ||
|
|
6bc865144a | ||
|
|
ccafee7a21 | ||
|
|
033a089fd8 | ||
|
|
27f471791d | ||
|
|
ae11da2bc7 | ||
|
|
b58b9ca8f0 | ||
|
|
ba0b3e7d93 | ||
|
|
6fca21b6ed | ||
|
|
a3dbaf9e6a | ||
|
|
835305bcf6 | ||
|
|
395f2d16fa | ||
|
|
6cabdc0a67 | ||
|
|
f64e7d3fd7 | ||
|
|
cdbb2fa26a | ||
|
|
bec830c3b8 | ||
|
|
e80588b234 | ||
|
|
73504a3386 | ||
|
|
9c4b936ddd | ||
|
|
222d49bdca | ||
|
|
f386be3494 | ||
|
|
c4074d67f5 | ||
|
|
9506be6b65 | ||
|
|
1aabb84731 | ||
|
|
b2c3d620a4 | ||
|
|
2d8874acaf | ||
|
|
001bf4a605 | ||
|
|
2b6e166e86 | ||
|
|
f8c995e59e | ||
|
|
656c9399ef | ||
|
|
55b5c1e713 | ||
|
|
6456c22c61 | ||
|
|
e396a51ad5 | ||
|
|
68c75fbfd2 | ||
|
|
d6d6cc1e29 | ||
|
|
9fce94af63 | ||
|
|
41f390b305 | ||
|
|
8115b1504e | ||
|
|
34fa724fdd | ||
|
|
24544e713e | ||
|
|
06a806e260 | ||
|
|
4259931b67 | ||
|
|
a96ff6ecb3 | ||
|
|
5af45f16b0 | ||
|
|
a9b6d5ff38 | ||
|
|
433f016c25 | ||
|
|
10a9bc2906 | ||
|
|
b585e85f0f | ||
|
|
8a67e1eccd | ||
|
|
7ea1696065 | ||
|
|
5b4a7c168f | ||
|
|
a54adc1e4b | ||
|
|
c1288ce4bb | ||
|
|
c65210b3ed | ||
|
|
70a3cb9ef9 | ||
|
|
d1686c4c8f | ||
|
|
c5033db336 | ||
|
|
36aa4ea508 | ||
|
|
d5c5b4315b | ||
|
|
d505e4e24c | ||
|
|
ea7f18e3b0 | ||
|
|
e8e16f4d66 | ||
|
|
2e5ebb861e | ||
|
|
1b577c4030 | ||
|
|
e92c169e71 | ||
|
|
e213eb0a78 | ||
|
|
422829cbd8 | ||
|
|
3360b4e829 | ||
|
|
9e1a532105 | ||
|
|
2b79583e8c | ||
|
|
609b40e84c | ||
|
|
07c574fa42 | ||
|
|
960ecae861 | ||
|
|
49a4daa8f6 | ||
|
|
1f41745d2b | ||
|
|
1602f0af37 | ||
|
|
375c54016c | ||
|
|
de20311299 | ||
|
|
5fede97fa5 | ||
|
|
cc76ff1478 | ||
|
|
bbe56bf443 | ||
|
|
f449132b4c | ||
|
|
b99c0382f6 | ||
|
|
e3586f0734 | ||
|
|
8d49422061 | ||
|
|
59790bd005 | ||
|
|
24c950227a | ||
|
|
b55db94822 | ||
|
|
c17f976385 | ||
|
|
e83e6567af | ||
|
|
b638cca547 | ||
|
|
2fc5bcabb8 | ||
|
|
52658d6e44 | ||
|
|
9f3a4dc6bb | ||
|
|
acb10d7695 | ||
|
|
fa4ced0592 | ||
|
|
3f1d6a5459 | ||
|
|
d60d902e27 | ||
|
|
e1c1e32a4b | ||
|
|
5c2f603860 | ||
|
|
47b78510df | ||
|
|
fdbec6d789 | ||
|
|
90b504d67d | ||
|
|
8efea112b4 | ||
|
|
acbdd1b801 | ||
|
|
d012a09346 | ||
|
|
3cca38302a | ||
|
|
f9352a94c6 | ||
|
|
1add97b1b2 |
@@ -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
|
||||||
|
|||||||
10
babel.config.json
Normal file
10
babel.config.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"@babel/plugin-transform-runtime",
|
||||||
|
"babel-plugin-transform-import-meta"
|
||||||
|
]
|
||||||
|
}
|
||||||
46
changelog.md
46
changelog.md
@@ -85,6 +85,52 @@ 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).
|
||||||
|
|
||||||
|
### Wednesday 11/27/2024 - v3.16.1
|
||||||
|
|
||||||
|
{{taskList
|
||||||
|
##### 5e-Cleric
|
||||||
|
|
||||||
|
* [x] Allow linking to specific HTML IDs via `#ID` at the end of the URL, e.g.: `homebrewery.naturalcrit.com/share/share/a6RCXwaDS58i#p4` to link to Page 4 directly
|
||||||
|
|
||||||
|
Fixes issues [#2820](https://github.com/naturalcrit/homebrewery/issues/2820), [#3505](https://github.com/naturalcrit/homebrewery/issues/3505)
|
||||||
|
|
||||||
|
* [x] Fix generation of link to certain Google Drive brews
|
||||||
|
|
||||||
|
Fixes issue [#3776](https://github.com/naturalcrit/homebrewery/issues/3776)
|
||||||
|
|
||||||
|
##### abquintic
|
||||||
|
|
||||||
|
* [x] Fix blank pages appearing when pasting text
|
||||||
|
|
||||||
|
Fixes issue [#3718](https://github.com/naturalcrit/homebrewery/issues/3718)
|
||||||
|
|
||||||
|
##### Gazook89
|
||||||
|
|
||||||
|
* [x] Add new brew viewing options to the view toolbar
|
||||||
|
- {{fac,single-spread}} {{openSans **SINGLE PAGE**}}
|
||||||
|
- {{fac,facing-spread}} {{openSans **TWO PAGE**}}
|
||||||
|
- {{fac,flow-spread}} {{openSans **GRID**}}
|
||||||
|
|
||||||
|
Fixes issue [#1379](https://github.com/naturalcrit/homebrewery/issues/1379)
|
||||||
|
|
||||||
|
* [x] Updates to tag input boxes
|
||||||
|
|
||||||
|
##### G-Ambatte
|
||||||
|
|
||||||
|
* [x] Admin tools to fix certain corrupted documents
|
||||||
|
|
||||||
|
Fixes issue [#3801](https://github.com/naturalcrit/homebrewery/issues/3801)
|
||||||
|
|
||||||
|
* [x] Fix print window being affected by document zoom
|
||||||
|
|
||||||
|
Fixes issue [#3744](https://github.com/naturalcrit/homebrewery/issues/3744)
|
||||||
|
|
||||||
|
|
||||||
|
##### calculuschild, 5e-Cleric, G-Ambatte, Gazook89, abquintic
|
||||||
|
|
||||||
|
* [x] Multiple code refactors, cleanups, and security fixes
|
||||||
|
}}
|
||||||
|
|
||||||
### Saturday 10/12/2024 - v3.16.0
|
### Saturday 10/12/2024 - v3.16.0
|
||||||
|
|
||||||
{{taskList
|
{{taskList
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
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');
|
||||||
@@ -15,19 +17,40 @@ const BrewLookup = createClass({
|
|||||||
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(){
|
||||||
@@ -46,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%;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,7 +66,7 @@ const NotificationAdd = ()=>{
|
|||||||
<label className='field'>
|
<label className='field'>
|
||||||
Dismiss Key:
|
Dismiss Key:
|
||||||
<input className='fieldInput' type='text' ref={dismissKeyRef} required
|
<input className='fieldInput' type='text' ref={dismissKeyRef} required
|
||||||
placeholder='GOOGLEDRIVENOTIF'
|
placeholder='dismiss_notif_drive'
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ const NotificationDetail = ({ notification, onDelete })=>(
|
|||||||
<dt>Title</dt>
|
<dt>Title</dt>
|
||||||
<dd>{notification.title || 'No Title'}</dd>
|
<dd>{notification.title || 'No Title'}</dd>
|
||||||
|
|
||||||
<dt>Text</dt>
|
|
||||||
<dd>{notification.text || 'No Text'}</dd>
|
|
||||||
|
|
||||||
<dt>Created</dt>
|
<dt>Created</dt>
|
||||||
<dd>{Moment(notification.createdAt).format('LLLL')}</dd>
|
<dd>{Moment(notification.createdAt).format('LLLL')}</dd>
|
||||||
|
|
||||||
@@ -25,6 +22,9 @@ const NotificationDetail = ({ notification, onDelete })=>(
|
|||||||
|
|
||||||
<dt>Stop</dt>
|
<dt>Stop</dt>
|
||||||
<dd>{Moment(notification.stopAt).format('LLLL') || 'No End Time'}</dd>
|
<dd>{Moment(notification.stopAt).format('LLLL') || 'No End Time'}</dd>
|
||||||
|
|
||||||
|
<dt>Text</dt>
|
||||||
|
<dd>{notification.text || 'No Text'}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<button onClick={()=>onDelete(notification.dismissKey)}>DELETE</button>
|
<button onClick={()=>onDelete(notification.dismissKey)}>DELETE</button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
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,18 +1,22 @@
|
|||||||
// 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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const { useState, useRef, useCallback, useMemo } = React;
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
const ErrorBar = require('./errorBar/errorBar.jsx');
|
const ErrorBar = require('./errorBar/errorBar.jsx');
|
||||||
const ToolBar = require('./toolBar/toolBar.jsx');
|
const ToolBar = require('./toolBar/toolBar.jsx');
|
||||||
|
|
||||||
@@ -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,8 +36,8 @@ 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>;
|
||||||
};
|
};
|
||||||
@@ -65,8 +65,14 @@ const BrewRenderer = (props)=>{
|
|||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
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);
|
||||||
@@ -77,6 +83,26 @@ const BrewRenderer = (props)=>{
|
|||||||
rawPages = props.text.split(/^\\page$/gm);
|
rawPages = props.text.split(/^\\page$/gm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scrollToHash = (hash)=>{
|
||||||
|
if(!hash) return;
|
||||||
|
|
||||||
|
const iframeDoc = document.getElementById('BrewRenderer').contentDocument;
|
||||||
|
let anchor = iframeDoc.querySelector(hash);
|
||||||
|
|
||||||
|
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)=>{
|
||||||
const { scrollTop, clientHeight, scrollHeight } = e.target;
|
const { scrollTop, clientHeight, scrollHeight } = e.target;
|
||||||
const totalScrollableHeight = scrollHeight - clientHeight;
|
const totalScrollableHeight = scrollHeight - clientHeight;
|
||||||
@@ -105,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 ?? '@import url("/themes/V3/Blank/style.css");';
|
const cleanStyle = safeHTML(`${themeStyles} \n\n <style> ${props.style} </style>`);
|
||||||
return `${themeStyles}\n\n${cleanStyle}`;
|
return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: cleanStyle }} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderPage = (pageText, index)=>{
|
const renderPage = (pageText, index)=>{
|
||||||
@@ -117,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} />;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,6 +161,7 @@ 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
|
||||||
|
if(rawPages.length > props.currentEditorCursorPageNum -1)
|
||||||
renderedPages[props.currentEditorCursorPageNum - 1] = renderPage(rawPages[props.currentEditorCursorPageNum - 1], props.currentEditorCursorPageNum - 1);
|
renderedPages[props.currentEditorCursorPageNum - 1] = renderPage(rawPages[props.currentEditorCursorPageNum - 1], props.currentEditorCursorPageNum - 1);
|
||||||
|
|
||||||
_.forEach(rawPages, (page, index)=>{
|
_.forEach(rawPages, (page, index)=>{
|
||||||
@@ -150,6 +183,8 @@ 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
|
||||||
renderPages(); //Make sure page is renderable before showing
|
renderPages(); //Make sure page is renderable before showing
|
||||||
setState((prevState)=>({
|
setState((prevState)=>({
|
||||||
@@ -165,22 +200,24 @@ 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 = {};
|
const styleObject = {};
|
||||||
|
|
||||||
if(global.config.deployment) {
|
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='white' font-size='20'>${global.config.deployment}</text></svg>")`;
|
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?.length, props.themeBundle]);
|
const renderedStyle = useMemo(()=>renderStyle(), [props.style, props.themeBundle]);
|
||||||
renderedPages = useMemo(() => renderPages(), [props.text?.length]);
|
renderedPages = useMemo(()=>renderPages(), [props.text]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -199,10 +236,10 @@ 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} head={<style>{renderedStyle}</style>}
|
<Frame id='BrewRenderer' initialContent={INITIAL_CONTENT}
|
||||||
style={{ width: '100%', height: '100%', visibility: state.visibility }}
|
style={{ width: '100%', height: '100%', visibility: state.visibility }}
|
||||||
contentDidMount={frameDidMount}
|
contentDidMount={frameDidMount}
|
||||||
onClick={()=>{emitClick();}}
|
onClick={()=>{emitClick();}}
|
||||||
@@ -217,7 +254,9 @@ const BrewRenderer = (props)=>{
|
|||||||
{state.isMounted
|
{state.isMounted
|
||||||
&&
|
&&
|
||||||
<>
|
<>
|
||||||
<div className='pages' lang={`${props.lang || 'en'}`} style={{ zoom: `${state.zoom}%` }}>
|
{renderedStyle}
|
||||||
|
<div lang={`${props.lang || 'en'}`} style={pagesStyle} className={
|
||||||
|
`pages ${displayOptions.startOnRight ? 'recto' : 'verso'} ${displayOptions.spread}` } >
|
||||||
{renderedPages}
|
{renderedPages}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -3,13 +3,45 @@
|
|||||||
.brewRenderer {
|
.brewRenderer {
|
||||||
overflow-y : scroll;
|
overflow-y : scroll;
|
||||||
will-change : transform;
|
will-change : transform;
|
||||||
padding-top : 30px;
|
padding-top : 60px;
|
||||||
height : 100vh;
|
height : 100vh;
|
||||||
|
&:has(.facing, .flow) {
|
||||||
|
padding : 60px 30px;
|
||||||
|
}
|
||||||
&.deployment {
|
&.deployment {
|
||||||
background-color: darkred;
|
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;
|
||||||
@@ -18,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;
|
||||||
|
|||||||
@@ -1,44 +1,62 @@
|
|||||||
require('./notificationPopup.less');
|
require('./notificationPopup.less');
|
||||||
const React = require('react');
|
import React, { useEffect, useState } from 'react';
|
||||||
const _ = require('lodash');
|
import request from '../../utils/request-middleware.js';
|
||||||
|
|
||||||
import Dialog from '../../../components/dialog.jsx';
|
import Dialog from '../../../components/dialog.jsx';
|
||||||
|
|
||||||
const DISMISS_KEY = 'dismiss_notification01-10-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;
|
|
||||||
transition: all .3s ease;
|
|
||||||
flex-wrap : nowrap;
|
flex-wrap : nowrap;
|
||||||
|
width : 32px;
|
||||||
overflow : hidden;
|
overflow : hidden;
|
||||||
background-color : unset;
|
background-color : unset;
|
||||||
opacity: .5;
|
opacity : 0.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;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ const React = require('react');
|
|||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
const Markdown = require('../../../shared/naturalcrit/markdown.js');
|
import Markdown from '../../../shared/naturalcrit/markdown.js';
|
||||||
|
|
||||||
const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
|
const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
|
||||||
const SnippetBar = require('./snippetbar/snippetbar.jsx');
|
const SnippetBar = require('./snippetbar/snippetbar.jsx');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
.editor {
|
.editor {
|
||||||
position : relative;
|
position : relative;
|
||||||
width : 100%;
|
width : 100%;
|
||||||
|
container: editor / inline-size;
|
||||||
|
|
||||||
.codeEditor {
|
.codeEditor {
|
||||||
height : 100%;
|
height : 100%;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ require('./metadataEditor.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 request = require('../../utils/request-middleware.js');
|
import request from '../../utils/request-middleware.js';
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Combobox = require('client/components/combobox.jsx');
|
const Combobox = require('client/components/combobox.jsx');
|
||||||
const StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx');
|
const TagInput = require('../tagInput/tagInput.jsx');
|
||||||
|
|
||||||
|
|
||||||
const Themes = require('themes/themes.json');
|
const Themes = require('themes/themes.json');
|
||||||
@@ -341,10 +341,11 @@ const MetadataEditor = createClass({
|
|||||||
{this.renderThumbnail()}
|
{this.renderThumbnail()}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<StringArrayEditor label='tags' valuePatterns={[/^(?:(?:group|meta|system|type):)?[A-Za-z0-9][A-Za-z0-9 \/.\-]{0,40}$/]}
|
<TagInput label='tags' valuePatterns={[/^(?:(?:group|meta|system|type):)?[A-Za-z0-9][A-Za-z0-9 \/.\-]{0,40}$/]}
|
||||||
placeholder='add tag' unique={true}
|
placeholder='add tag' unique={true}
|
||||||
values={this.props.metadata.tags}
|
values={this.props.metadata.tags}
|
||||||
onChange={(e)=>this.handleFieldChange('tags', e)}/>
|
onChange={(e)=>this.handleFieldChange('tags', e)}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className='field systems'>
|
<div className='field systems'>
|
||||||
<label>systems</label>
|
<label>systems</label>
|
||||||
@@ -363,12 +364,13 @@ const MetadataEditor = createClass({
|
|||||||
|
|
||||||
{this.renderAuthors()}
|
{this.renderAuthors()}
|
||||||
|
|
||||||
<StringArrayEditor label='invited authors' valuePatterns={[/.+/]}
|
<TagInput label='invited authors' valuePatterns={[/.+/]}
|
||||||
validators={[(v)=>!this.props.metadata.authors?.includes(v)]}
|
validators={[(v)=>!this.props.metadata.authors?.includes(v)]}
|
||||||
placeholder='invite author' unique={true}
|
placeholder='invite author' unique={true}
|
||||||
values={this.props.metadata.invitedAuthors}
|
values={this.props.metadata.invitedAuthors}
|
||||||
notes={['Invited author usernames are case sensitive.', 'After adding an invited author, send them the edit link. There, they can choose to accept or decline the invitation.']}
|
notes={['Invited author usernames are case sensitive.', 'After adding an invited author, send them the edit link. There, they can choose to accept or decline the invitation.']}
|
||||||
onChange={(e)=>this.handleFieldChange('invitedAuthors', e)}/>
|
onChange={(e)=>this.handleFieldChange('invitedAuthors', e)}
|
||||||
|
/>
|
||||||
|
|
||||||
<h2>Privacy</h2>
|
<h2>Privacy</h2>
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -271,7 +272,7 @@
|
|||||||
&:last-child { border-radius : 0 0.5em 0.5em 0; }
|
&:last-child { border-radius : 0 0.5em 0.5em 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge {
|
.tag {
|
||||||
padding : 0.3em;
|
padding : 0.3em;
|
||||||
margin : 2px;
|
margin : 2px;
|
||||||
font-size : 0.9em;
|
font-size : 0.9em;
|
||||||
|
|||||||
@@ -150,8 +150,10 @@ 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'>
|
||||||
|
{_.map(snippets, (snippetGroup)=>{
|
||||||
return <SnippetGroup
|
return <SnippetGroup
|
||||||
brew={this.props.brew}
|
brew={this.props.brew}
|
||||||
groupName={snippetGroup.groupName}
|
groupName={snippetGroup.groupName}
|
||||||
@@ -161,7 +163,9 @@ const Snippetbar = createClass({
|
|||||||
onSnippetClick={this.handleSnippetClick}
|
onSnippetClick={this.handleSnippetClick}
|
||||||
cursorPos={this.props.cursorPos}
|
cursorPos={this.props.cursorPos}
|
||||||
/>;
|
/>;
|
||||||
});
|
})
|
||||||
|
}
|
||||||
|
</div>;
|
||||||
},
|
},
|
||||||
|
|
||||||
replaceContent : function(item){
|
replaceContent : function(item){
|
||||||
@@ -203,23 +207,19 @@ 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 =
|
|
||||||
<>
|
|
||||||
<div className={`editorTool foldAll ${this.props.foldCode ? 'active' : ''}`}
|
|
||||||
onClick={this.props.foldCode} >
|
onClick={this.props.foldCode} >
|
||||||
<i className='fas fa-compress-alt' />
|
<i className='fas fa-compress-alt' />
|
||||||
</div>
|
</div>
|
||||||
<div className={`editorTool unfoldAll ${this.props.unfoldCode ? 'active' : ''}`}
|
<div className={`editorTool unfoldAll ${this.props.view !== 'meta' && this.props.unfoldCode ? 'active' : ''}`}
|
||||||
onClick={this.props.unfoldCode} >
|
onClick={this.props.unfoldCode} >
|
||||||
<i className='fas fa-expand-alt' />
|
<i className='fas fa-expand-alt' />
|
||||||
</div>
|
</div>
|
||||||
</>;
|
</>;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div className='editors'>
|
return <div className='editors'>
|
||||||
|
<div className='historyTools'>
|
||||||
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
||||||
onClick={this.toggleHistoryMenu} >
|
onClick={this.toggleHistoryMenu} >
|
||||||
<i className='fas fa-clock-rotate-left' />
|
<i className='fas fa-clock-rotate-left' />
|
||||||
@@ -233,15 +233,18 @@ const Snippetbar = createClass({
|
|||||||
onClick={this.props.redo} >
|
onClick={this.props.redo} >
|
||||||
<i className='fas fa-redo' />
|
<i className='fas fa-redo' />
|
||||||
</div>
|
</div>
|
||||||
<div className='divider'></div>
|
</div>
|
||||||
|
<div className='codeTools'>
|
||||||
{foldButtons}
|
{foldButtons}
|
||||||
<div className={`editorTool editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
<div className={`editorTool editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
||||||
onClick={this.toggleThemeSelector} >
|
onClick={this.toggleThemeSelector} >
|
||||||
<i className='fas fa-palette' />
|
<i className='fas fa-palette' />
|
||||||
{this.state.themeSelector && this.renderThemeSelector()}
|
{this.state.themeSelector && this.renderThemeSelector()}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='divider'></div>
|
|
||||||
|
<div className='tabs'>
|
||||||
<div className={cx('text', { selected: this.props.view === 'text' })}
|
<div className={cx('text', { selected: this.props.view === 'text' })}
|
||||||
onClick={()=>this.props.onViewChange('text')}>
|
onClick={()=>this.props.onViewChange('text')}>
|
||||||
<i className='fa fa-beer' />
|
<i className='fa fa-beer' />
|
||||||
@@ -254,6 +257,8 @@ const Snippetbar = createClass({
|
|||||||
onClick={()=>this.props.onViewChange('meta')}>
|
onClick={()=>this.props.onViewChange('meta')}>
|
||||||
<i className='fas fa-info-circle' />
|
<i className='fas fa-info-circle' />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>;
|
</div>;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -291,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,18 +4,35 @@
|
|||||||
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editors {
|
||||||
|
display : flex;
|
||||||
|
justify-content : flex-end;
|
||||||
|
min-width : 225px;
|
||||||
|
|
||||||
|
&:only-child { margin-left : auto; }
|
||||||
|
|
||||||
|
>div {
|
||||||
|
display : flex;
|
||||||
|
flex : 1;
|
||||||
|
justify-content : space-around;
|
||||||
|
|
||||||
|
&:first-child { border-left : none; }
|
||||||
|
|
||||||
& > div {
|
& > div {
|
||||||
|
position : relative;
|
||||||
width : @menuHeight;
|
width : @menuHeight;
|
||||||
height : @menuHeight;
|
height : @menuHeight;
|
||||||
line-height : @menuHeight;
|
line-height : @menuHeight;
|
||||||
@@ -46,26 +63,25 @@
|
|||||||
&.foldAll {
|
&.foldAll {
|
||||||
.tooltipLeft('Fold All');
|
.tooltipLeft('Fold All');
|
||||||
font-size : 0.75em;
|
font-size : 0.75em;
|
||||||
color : inherit;
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
}
|
}
|
||||||
&.unfoldAll {
|
&.unfoldAll {
|
||||||
.tooltipLeft('Unfold All');
|
.tooltipLeft('Unfold All');
|
||||||
font-size : 0.75em;
|
font-size : 0.75em;
|
||||||
color : inherit;
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
}
|
}
|
||||||
&.history {
|
&.history {
|
||||||
.tooltipLeft('History');
|
.tooltipLeft('History');
|
||||||
|
position : relative;
|
||||||
font-size : 0.75em;
|
font-size : 0.75em;
|
||||||
color : grey;
|
color : grey;
|
||||||
position : relative;
|
border : none;
|
||||||
&.active {
|
&.active { color : inherit; }
|
||||||
color : inherit;
|
|
||||||
}
|
|
||||||
& > .dropdown {
|
& > .dropdown {
|
||||||
right : -1px;
|
right : -1px;
|
||||||
&>.snippet{
|
& > .snippet { padding-right : 10px; }
|
||||||
padding-right : 10px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.editorTheme {
|
&.editorTheme {
|
||||||
@@ -96,6 +112,7 @@
|
|||||||
background-color : inherit;
|
background-color : inherit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.snippetBarButton {
|
.snippetBarButton {
|
||||||
display : inline-block;
|
display : inline-block;
|
||||||
height : @menuHeight;
|
height : @menuHeight;
|
||||||
@@ -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,10 +160,10 @@
|
|||||||
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;
|
||||||
@@ -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,149 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
const StringArrayEditor = createClass({
|
|
||||||
displayName : 'StringArrayEditor',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
label : '',
|
|
||||||
values : [],
|
|
||||||
valuePatterns : null,
|
|
||||||
validators : [],
|
|
||||||
placeholder : '',
|
|
||||||
notes : [],
|
|
||||||
unique : false,
|
|
||||||
cannotEdit : [],
|
|
||||||
onChange : ()=>{}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
|
||||||
return {
|
|
||||||
valueContext : !!this.props.values ? this.props.values.map((value)=>({
|
|
||||||
value,
|
|
||||||
editing : false
|
|
||||||
})) : [],
|
|
||||||
temporaryValue : '',
|
|
||||||
updateValue : ''
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidUpdate : function(prevProps) {
|
|
||||||
if(!_.eq(this.props.values, prevProps.values)) {
|
|
||||||
this.setState({
|
|
||||||
valueContext : this.props.values ? this.props.values.map((newValue)=>({
|
|
||||||
value : newValue,
|
|
||||||
editing : this.state.valueContext.find(({ value })=>value === newValue)?.editing || false
|
|
||||||
})) : []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleChange : function(value) {
|
|
||||||
this.props.onChange({
|
|
||||||
target : {
|
|
||||||
value
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
addValue : function(value){
|
|
||||||
this.handleChange(_.uniq([...this.props.values, value]));
|
|
||||||
this.setState({
|
|
||||||
temporaryValue : ''
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
removeValue : function(index){
|
|
||||||
this.handleChange(this.props.values.filter((_, i)=>i !== index));
|
|
||||||
},
|
|
||||||
|
|
||||||
updateValue : function(value, index){
|
|
||||||
const valueContext = this.state.valueContext;
|
|
||||||
valueContext[index].value = value;
|
|
||||||
valueContext[index].editing = false;
|
|
||||||
this.handleChange(valueContext.map((context)=>context.value));
|
|
||||||
this.setState({ valueContext, updateValue: '' });
|
|
||||||
},
|
|
||||||
|
|
||||||
editValue : function(index){
|
|
||||||
if(!!this.props.cannotEdit && this.props.cannotEdit.includes(this.props.values[index])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const valueContext = this.state.valueContext.map((context, i)=>{
|
|
||||||
context.editing = index === i;
|
|
||||||
return context;
|
|
||||||
});
|
|
||||||
this.setState({ valueContext, updateValue: this.props.values[index] });
|
|
||||||
},
|
|
||||||
|
|
||||||
valueIsValid : function(value, index) {
|
|
||||||
const values = _.clone(this.props.values);
|
|
||||||
if(index !== undefined) {
|
|
||||||
values.splice(index, 1);
|
|
||||||
}
|
|
||||||
const matchesPatterns = !this.props.valuePatterns || this.props.valuePatterns.some((pattern)=>!!(value || '').match(pattern));
|
|
||||||
const uniqueIfSet = !this.props.unique || !values.includes(value);
|
|
||||||
const passesValidators = !this.props.validators || this.props.validators.every((validator)=>validator(value));
|
|
||||||
return matchesPatterns && uniqueIfSet && passesValidators;
|
|
||||||
},
|
|
||||||
|
|
||||||
handleValueInputKeyDown : function(event, index) {
|
|
||||||
if(event.key === 'Enter') {
|
|
||||||
if(this.valueIsValid(event.target.value, index)) {
|
|
||||||
if(index !== undefined) {
|
|
||||||
this.updateValue(event.target.value, index);
|
|
||||||
} else {
|
|
||||||
this.addValue(event.target.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(event.key === 'Escape') {
|
|
||||||
this.closeEditInput(index);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
closeEditInput : function(index) {
|
|
||||||
const valueContext = this.state.valueContext;
|
|
||||||
valueContext[index].editing = false;
|
|
||||||
this.setState({ valueContext, updateValue: '' });
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function() {
|
|
||||||
const valueElements = Object.values(this.state.valueContext).map((context, i)=>context.editing
|
|
||||||
? <React.Fragment key={i}>
|
|
||||||
<div className='input-group'>
|
|
||||||
<input type='text' className={`value ${this.valueIsValid(this.state.updateValue, i) ? '' : 'invalid'}`} autoFocus placeholder={this.props.placeholder}
|
|
||||||
value={this.state.updateValue}
|
|
||||||
onKeyDown={(e)=>this.handleValueInputKeyDown(e, i)}
|
|
||||||
onChange={(e)=>this.setState({ updateValue: e.target.value })}/>
|
|
||||||
{<div className='icon steel' onClick={(e)=>{ e.stopPropagation(); this.closeEditInput(i); }}><i className='fa fa-undo fa-fw'/></div>}
|
|
||||||
{this.valueIsValid(this.state.updateValue, i) ? <div className='icon steel' onClick={(e)=>{ e.stopPropagation(); this.updateValue(this.state.updateValue, i); }}><i className='fa fa-check fa-fw'/></div> : null}
|
|
||||||
</div>
|
|
||||||
</React.Fragment>
|
|
||||||
: <div className='badge' key={i} onClick={()=>this.editValue(i)}>{context.value}
|
|
||||||
{!!this.props.cannotEdit && this.props.cannotEdit.includes(context.value) ? null : <div className='icon steel' onClick={(e)=>{ e.stopPropagation(); this.removeValue(i); }}><i className='fa fa-times fa-fw'/></div>}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <div className='field'>
|
|
||||||
<label>{this.props.label}</label>
|
|
||||||
<div style={{ flex: '1 0' }} className='value'>
|
|
||||||
<div className='list'>
|
|
||||||
{valueElements}
|
|
||||||
<div className='input-group'>
|
|
||||||
<input type='text' className={`value ${this.valueIsValid(this.state.temporaryValue) ? '' : 'invalid'}`} placeholder={this.props.placeholder}
|
|
||||||
value={this.state.temporaryValue}
|
|
||||||
onKeyDown={(e)=>this.handleValueInputKeyDown(e)}
|
|
||||||
onChange={(e)=>this.setState({ temporaryValue: e.target.value })}/>
|
|
||||||
{this.valueIsValid(this.state.temporaryValue) ? <div className='icon steel' onClick={(e)=>{ e.stopPropagation(); this.addValue(this.state.temporaryValue); }}><i className='fa fa-check fa-fw'/></div> : null}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{this.props.notes ? this.props.notes.map((n, index)=><p key={index}><small>{n}</small></p>) : null}
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = StringArrayEditor;
|
|
||||||
105
client/homebrew/editor/tagInput/tagInput.jsx
Normal file
105
client/homebrew/editor/tagInput/tagInput.jsx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
require('./tagInput.less');
|
||||||
|
const React = require('react');
|
||||||
|
const { useState, useEffect } = React;
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const TagInput = ({ unique = true, values = [], ...props }) => {
|
||||||
|
const [tempInputText, setTempInputText] = useState('');
|
||||||
|
const [tagList, setTagList] = useState(values.map((value) => ({ value, editing: false })));
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
handleChange(tagList.map((context)=>context.value))
|
||||||
|
}, [tagList])
|
||||||
|
|
||||||
|
const handleChange = (value)=>{
|
||||||
|
props.onChange({
|
||||||
|
target : { value }
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputKeyDown = ({ evt, value, index, options = {} }) => {
|
||||||
|
if (_.includes(['Enter', ','], evt.key)) {
|
||||||
|
evt.preventDefault();
|
||||||
|
submitTag(evt.target.value, value, index);
|
||||||
|
if (options.clear) {
|
||||||
|
setTempInputText('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitTag = (newValue, originalValue, index) => {
|
||||||
|
setTagList((prevContext) => {
|
||||||
|
// remove existing tag
|
||||||
|
if(newValue === null){
|
||||||
|
return [...prevContext].filter((context, i)=>i !== index);
|
||||||
|
}
|
||||||
|
// add new tag
|
||||||
|
if(originalValue === null){
|
||||||
|
return [...prevContext, { value: newValue, editing: false }]
|
||||||
|
}
|
||||||
|
// update existing tag
|
||||||
|
return prevContext.map((context, i) => {
|
||||||
|
if (i === index) {
|
||||||
|
return { ...context, value: newValue, editing: false };
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const editTag = (index) => {
|
||||||
|
setTagList((prevContext) => {
|
||||||
|
return prevContext.map((context, i) => {
|
||||||
|
if (i === index) {
|
||||||
|
return { ...context, editing: true };
|
||||||
|
}
|
||||||
|
return { ...context, editing: false };
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderReadTag = (context, index) => {
|
||||||
|
return (
|
||||||
|
<li key={index}
|
||||||
|
data-value={context.value}
|
||||||
|
className='tag'
|
||||||
|
onClick={() => editTag(index)}>
|
||||||
|
{context.value}
|
||||||
|
<button onClick={(evt)=>{evt.stopPropagation(); submitTag(null, context.value, index)}}><i className='fa fa-times fa-fw'/></button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderWriteTag = (context, index) => {
|
||||||
|
return (
|
||||||
|
<input type='text'
|
||||||
|
key={index}
|
||||||
|
defaultValue={context.value}
|
||||||
|
onKeyDown={(evt) => handleInputKeyDown({evt, value: context.value, index: index})}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='field'>
|
||||||
|
<label>{props.label}</label>
|
||||||
|
<div className='value'>
|
||||||
|
<ul className='list'>
|
||||||
|
{tagList.map((context, index) => { return context.editing ? renderWriteTag(context, index) : renderReadTag(context, index); })}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
className='value'
|
||||||
|
placeholder={props.placeholder}
|
||||||
|
value={tempInputText}
|
||||||
|
onChange={(e) => setTempInputText(e.target.value)}
|
||||||
|
onKeyDown={(evt) => handleInputKeyDown({ evt, value: null, options: { clear: true } })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = TagInput;
|
||||||
0
client/homebrew/editor/tagInput/tagInput.less
Normal file
0
client/homebrew/editor/tagInput/tagInput.less
Normal file
@@ -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;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require('./brewItem.less');
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const request = require('../../../../utils/request-middleware.js');
|
import request from '../../../../utils/request-middleware.js';
|
||||||
|
|
||||||
const googleDriveIcon = require('../../../../googleDrive.svg');
|
const googleDriveIcon = require('../../../../googleDrive.svg');
|
||||||
const homebreweryIcon = require('../../../../thumbnail.png');
|
const homebreweryIcon = require('../../../../thumbnail.png');
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const React = require('react');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
|
|
||||||
const request = require('../../utils/request-middleware.js');
|
import request from '../../utils/request-middleware.js';
|
||||||
const { Meta } = require('vitreum/headtags');
|
const { Meta } = require('vitreum/headtags');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
@@ -23,7 +23,7 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
|||||||
|
|
||||||
const LockNotification = require('./lockNotification/lockNotification.jsx');
|
const LockNotification = require('./lockNotification/lockNotification.jsx');
|
||||||
|
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
const { DEFAULT_BREW_LOAD } = require('../../../../server/brewDefaults.js');
|
const { DEFAULT_BREW_LOAD } = require('../../../../server/brewDefaults.js');
|
||||||
const { printCurrentBrew, fetchThemeBundle } = require('../../../../shared/helpers.js');
|
const { printCurrentBrew, fetchThemeBundle } = require('../../../../shared/helpers.js');
|
||||||
@@ -228,8 +228,8 @@ const EditPage = createClass({
|
|||||||
htmlErrors : Markdown.validate(prevState.brew.text)
|
htmlErrors : Markdown.validate(prevState.brew.text)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await updateHistory(this.state.brew);
|
await updateHistory(this.state.brew).catch(console.error);
|
||||||
await 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,8 +429,8 @@ 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}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require('./errorPage.less');
|
require('./errorPage.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const UIPage = require('../basePages/uiPage/uiPage.jsx');
|
const UIPage = require('../basePages/uiPage/uiPage.jsx');
|
||||||
const Markdown = require('../../../../shared/naturalcrit/markdown.js');
|
import Markdown from '../../../../shared/naturalcrit/markdown.js';
|
||||||
const ErrorIndex = require('./errors/errorIndex.js');
|
const ErrorIndex = require('./errors/errorIndex.js');
|
||||||
|
|
||||||
const ErrorPage = ({ brew })=>{
|
const ErrorPage = ({ brew })=>{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require('./homePage.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');
|
||||||
const request = require('../../utils/request-middleware.js');
|
import request from '../../utils/request-middleware.js';
|
||||||
const { Meta } = require('vitreum/headtags');
|
const { Meta } = require('vitreum/headtags');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
@@ -100,8 +100,7 @@ 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}
|
||||||
@@ -128,7 +127,6 @@ const HomePage = createClass({
|
|||||||
/>
|
/>
|
||||||
</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.
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
require('./newPage.less');
|
require('./newPage.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const request = require('../../utils/request-middleware.js');
|
import request from '../../utils/request-middleware.js';
|
||||||
|
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const PrintNavItem = require('../../navbar/print.navitem.jsx');
|
const PrintNavItem = require('../../navbar/print.navitem.jsx');
|
||||||
@@ -223,7 +223,7 @@ 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}
|
||||||
|
|||||||
@@ -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() {
|
|
||||||
return {
|
|
||||||
username : '',
|
username : '',
|
||||||
brews : [],
|
brews : [],
|
||||||
query : '',
|
query : '',
|
||||||
error : null
|
...props
|
||||||
};
|
};
|
||||||
},
|
|
||||||
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 usernameWithS = props.username + (props.username.endsWith('s') ? `’` : `’s`);
|
||||||
|
const groupedBrews = _.groupBy(props.brews, (brew)=>brew.published ? 'published' : 'private');
|
||||||
|
|
||||||
const brewCollection = [
|
const brewCollection = [
|
||||||
{
|
{
|
||||||
title : `${usernameWithS} published brews`,
|
title : `${usernameWithS} published brews`,
|
||||||
class : 'published',
|
class : 'published',
|
||||||
brews : brews.published
|
brews : groupedBrews.published || []
|
||||||
}
|
},
|
||||||
];
|
...(props.username === global.account?.username ? [{
|
||||||
if(this.props.username == global.account?.username){
|
|
||||||
brewCollection.push(
|
|
||||||
{
|
|
||||||
title : `${usernameWithS} unpublished brews`,
|
title : `${usernameWithS} unpublished brews`,
|
||||||
class : 'unpublished',
|
class : 'unpublished',
|
||||||
brews : brews.private
|
brews : groupedBrews.private || []
|
||||||
}
|
}] : [])
|
||||||
);
|
];
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
const navItems = (
|
||||||
brewCollection : brewCollection
|
<Navbar>
|
||||||
};
|
|
||||||
},
|
|
||||||
errorReported : function(error) {
|
|
||||||
this.setState({
|
|
||||||
error
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
navItems : function() {
|
|
||||||
return <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;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx');
|
|||||||
const SplitPane = require('../../../../shared/naturalcrit/splitPane/splitPane.jsx');
|
const SplitPane = require('../../../../shared/naturalcrit/splitPane/splitPane.jsx');
|
||||||
const ErrorIndex = require('../errorPage/errors/errorIndex.js');
|
const ErrorIndex = require('../errorPage/errors/errorIndex.js');
|
||||||
|
|
||||||
const request = require('../../utils/request-middleware.js');
|
import request from '../../utils/request-middleware.js';
|
||||||
|
|
||||||
const VaultPage = (props)=>{
|
const VaultPage = (props)=>{
|
||||||
const [pageState, setPageState] = useState(parseInt(props.query.page) || 1);
|
const [pageState, setPageState] = useState(parseInt(props.query.page) || 1);
|
||||||
@@ -411,14 +411,13 @@ 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()}
|
||||||
|
|||||||
@@ -5,11 +5,7 @@
|
|||||||
|
|
||||||
*:not(input) { user-select : none; }
|
*:not(input) { user-select : none; }
|
||||||
|
|
||||||
.content {
|
.content .dataGroup {
|
||||||
height : 100%;
|
|
||||||
background : #2C3E50;
|
|
||||||
|
|
||||||
.dataGroup {
|
|
||||||
width : 100%;
|
width : 100%;
|
||||||
height : 100%;
|
height : 100%;
|
||||||
background : white;
|
background : white;
|
||||||
@@ -371,7 +367,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,4 +1,4 @@
|
|||||||
const request = require('superagent');
|
import request from 'superagent';
|
||||||
|
|
||||||
const addHeader = (request)=>request.set('Homebrewery-Version', global.version);
|
const addHeader = (request)=>request.set('Homebrewery-Version', global.version);
|
||||||
|
|
||||||
@@ -9,4 +9,4 @@ const requestMiddleware = {
|
|||||||
delete : (path)=>addHeader(request.delete(path)),
|
delete : (path)=>addHeader(request.delete(path)),
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = requestMiddleware;
|
export default requestMiddleware;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as IDB from 'idb-keyval/dist/index.js';
|
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;
|
||||||
@@ -21,13 +21,15 @@ const HISTORY_SAVE_DELAYS = {
|
|||||||
// '5' : 5
|
// '5' : 5
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const HB_DB = 'HOMEBREWERY-DB';
|
|
||||||
const HB_STORE = 'HISTORY';
|
|
||||||
|
|
||||||
const GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
|
const GARBAGE_COLLECT_DELAY = 28 * 24 * 60;
|
||||||
// const GARBAGE_COLLECT_DELAY = 10;
|
// const GARBAGE_COLLECT_DELAY = 10;
|
||||||
|
|
||||||
|
|
||||||
|
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 a string representing the key for this brew and history slot
|
||||||
return `${HISTORY_PREFIX}-${brew.shareId}-${slot}`;
|
return `${HISTORY_PREFIX}-${brew.shareId}-${slot}`;
|
||||||
@@ -53,11 +55,6 @@ function parseBrewForStorage(brew, slot = 0) {
|
|||||||
return [key, archiveBrew];
|
return [key, archiveBrew];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a custom IDB store
|
|
||||||
async function createHBStore(){
|
|
||||||
return await IDB.createStore(HB_DB, HB_STORE);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadHistory(brew){
|
export async function loadHistory(brew){
|
||||||
const DEFAULT_HISTORY_ITEM = { expireAt: '2000-01-01T00:00:00.000Z', shareId: brew.shareId, noData: true };
|
const DEFAULT_HISTORY_ITEM = { expireAt: '2000-01-01T00:00:00.000Z', shareId: brew.shareId, noData: true };
|
||||||
|
|
||||||
@@ -69,7 +66,7 @@ export async function loadHistory(brew){
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Load all keys from IDB at once
|
// Load all keys from IDB at once
|
||||||
const dataArray = await IDB.getMany(historyKeys, await createHBStore());
|
const dataArray = await IDB.getMany(historyKeys);
|
||||||
return dataArray.map((data)=>{ return data ?? DEFAULT_HISTORY_ITEM; });
|
return dataArray.map((data)=>{ return data ?? DEFAULT_HISTORY_ITEM; });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +94,7 @@ export async function updateHistory(brew) {
|
|||||||
// Update the most recent brew
|
// Update the most recent brew
|
||||||
historyUpdate.push(parseBrewForStorage(brew, 1));
|
historyUpdate.push(parseBrewForStorage(brew, 1));
|
||||||
|
|
||||||
await IDB.setMany(historyUpdate, await createHBStore());
|
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;
|
||||||
@@ -106,14 +103,17 @@ export async function updateHistory(brew) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function versionHistoryGarbageCollection(){
|
export async function versionHistoryGarbageCollection(){
|
||||||
|
const entries = await IDB.entries();
|
||||||
|
|
||||||
const entries = await IDB.entries(await createHBStore());
|
const expiredKeys = [];
|
||||||
|
|
||||||
for (const [key, value] of entries){
|
for (const [key, value] of entries){
|
||||||
const expireAt = new Date(value.savedAt);
|
const expireAt = new Date(value.savedAt);
|
||||||
expireAt.setMinutes(expireAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
expireAt.setMinutes(expireAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
||||||
if(new Date() > expireAt){
|
if(new Date() > expireAt){
|
||||||
await IDB.del(key, await createHBStore());
|
expiredKeys.push(key);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
if(expiredKeys.length > 0){
|
||||||
|
await IDB.delMany(expiredKeys);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -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 |
@@ -8,6 +8,8 @@ const template = async function(name, title='', props = {}){
|
|||||||
});
|
});
|
||||||
const ogMetaTags = ogTags.join('\n');
|
const ogMetaTags = ogTags.join('\n');
|
||||||
|
|
||||||
|
const ssrModule = await import(`../build/${name}/ssr.cjs`);
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@@ -21,7 +23,7 @@ const template = async function(name, title='', props = {}){
|
|||||||
<title>${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'}</title>
|
<title>${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main id="reactRoot">${require(`../build/${name}/ssr.js`)(props)}</main>
|
<main id="reactRoot">${ssrModule.default(props)}</main>
|
||||||
<script src=${`/${name}/bundle.js`}></script>
|
<script src=${`/${name}/bundle.js`}></script>
|
||||||
<script>start_app(${JSON.stringify(props)})</script>
|
<script>start_app(${JSON.stringify(props)})</script>
|
||||||
</body>
|
</body>
|
||||||
@@ -29,4 +31,4 @@ const template = async function(name, title='', props = {}){
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = template;
|
export default template;
|
||||||
1899
package-lock.json
generated
1899
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"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.16.0",
|
"version": "3.16.1",
|
||||||
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
"npm": "^10.2.x",
|
"npm": "^10.2.x",
|
||||||
"node": "^20.17.x"
|
"node": "^20.18.x"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
"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",
|
||||||
|
"test:safehtml": "jest tests/html/safeHTML.test.js --verbose",
|
||||||
"phb": "node --experimental-require-module scripts/phb.js",
|
"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",
|
||||||
@@ -55,6 +57,9 @@
|
|||||||
"shared",
|
"shared",
|
||||||
"server"
|
"server"
|
||||||
],
|
],
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"node_modules/(?!nanoid/).*"
|
||||||
|
],
|
||||||
"coveragePathIgnorePatterns": [
|
"coveragePathIgnorePatterns": [
|
||||||
"build/*"
|
"build/*"
|
||||||
],
|
],
|
||||||
@@ -76,20 +81,11 @@
|
|||||||
"jest-expect-message"
|
"jest-expect-message"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"babel": {
|
|
||||||
"presets": [
|
|
||||||
"@babel/preset-env",
|
|
||||||
"@babel/preset-react"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"@babel/plugin-transform-runtime"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.25.8",
|
"@babel/core": "^7.26.0",
|
||||||
"@babel/plugin-transform-runtime": "^7.25.7",
|
"@babel/plugin-transform-runtime": "^7.25.9",
|
||||||
"@babel/preset-env": "^7.25.8",
|
"@babel/preset-env": "^7.26.0",
|
||||||
"@babel/preset-react": "^7.25.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",
|
||||||
@@ -97,11 +93,11 @@
|
|||||||
"cookie-parser": "^1.4.7",
|
"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.7",
|
"dompurify": "^3.2.1",
|
||||||
"expr-eval": "^2.0.2",
|
"expr-eval": "^2.0.2",
|
||||||
"express": "^4.21.1",
|
"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",
|
"idb-keyval": "^6.2.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
@@ -109,31 +105,33 @@
|
|||||||
"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.7.1",
|
"mongoose": "^8.8.2",
|
||||||
"nanoid": "3.3.4",
|
"nanoid": "5.0.8",
|
||||||
"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.27.0",
|
"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.1.1",
|
"@stylistic/stylelint-plugin": "^3.1.1",
|
||||||
"eslint": "^9.12.0",
|
"babel-plugin-transform-import-meta": "^2.2.1",
|
||||||
"eslint-plugin-jest": "^28.8.3",
|
"eslint": "^9.15.0",
|
||||||
"eslint-plugin-react": "^7.37.1",
|
"eslint-plugin-jest": "^28.9.0",
|
||||||
"globals": "^15.11.0",
|
"eslint-plugin-react": "^7.37.2",
|
||||||
|
"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.10.0",
|
"stylelint": "^16.10.0",
|
||||||
"stylelint-config-recess-order": "^5.1.1",
|
"stylelint-config-recess-order": "^5.1.1",
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
const fs = require('fs-extra');
|
|
||||||
const Proj = require('./project.json');
|
|
||||||
|
|
||||||
const { pack } = require('vitreum');
|
import fs from 'fs-extra';
|
||||||
|
import Proj from './project.json' with { type: 'json' };
|
||||||
|
import vitreum from 'vitreum';
|
||||||
|
const { pack } = vitreum;
|
||||||
|
|
||||||
|
import lessTransform from 'vitreum/transforms/less.js';
|
||||||
|
import assetTransform from 'vitreum/transforms/asset.js';
|
||||||
|
|
||||||
const isDev = !!process.argv.find((arg)=>arg=='--dev');
|
const isDev = !!process.argv.find((arg)=>arg=='--dev');
|
||||||
|
|
||||||
const lessTransform = require('vitreum/transforms/less.js');
|
|
||||||
const assetTransform = require('vitreum/transforms/asset.js');
|
|
||||||
//const Meta = require('vitreum/headtags');
|
|
||||||
|
|
||||||
const transforms = {
|
const transforms = {
|
||||||
'.less' : lessTransform,
|
'.less' : lessTransform,
|
||||||
'*' : assetTransform('./build')
|
'*' : assetTransform('./build')
|
||||||
@@ -17,7 +18,7 @@ const build = async ({ bundle, render, ssr })=>{
|
|||||||
const css = await lessTransform.generate({ paths: './shared' });
|
const css = await lessTransform.generate({ paths: './shared' });
|
||||||
await fs.outputFile('./build/admin/bundle.css', css);
|
await fs.outputFile('./build/admin/bundle.css', css);
|
||||||
await fs.outputFile('./build/admin/bundle.js', bundle);
|
await fs.outputFile('./build/admin/bundle.js', bundle);
|
||||||
await fs.outputFile('./build/admin/ssr.js', ssr);
|
await fs.outputFile('./build/admin/ssr.cjs', ssr);
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.emptyDirSync('./build/admin');
|
fs.emptyDirSync('./build/admin');
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
const fs = require('fs-extra');
|
import fs from 'fs-extra';
|
||||||
const zlib = require('zlib');
|
import zlib from 'zlib';
|
||||||
const Proj = require('./project.json');
|
import Proj from './project.json' with { type: 'json' };
|
||||||
|
import vitreum from 'vitreum';
|
||||||
|
const { pack, watchFile, livereload } = vitreum;
|
||||||
|
|
||||||
const { pack, watchFile, livereload } = require('vitreum');
|
import lessTransform from 'vitreum/transforms/less.js';
|
||||||
const isDev = !!process.argv.find((arg)=>arg=='--dev');
|
import assetTransform from 'vitreum/transforms/asset.js';
|
||||||
|
import babel from '@babel/core';
|
||||||
|
import less from 'less';
|
||||||
|
|
||||||
const lessTransform = require('vitreum/transforms/less.js');
|
const isDev = !!process.argv.find((arg) => arg === '--dev');
|
||||||
const assetTransform = require('vitreum/transforms/asset.js');
|
|
||||||
const babel = require('@babel/core');
|
|
||||||
const less = require('less');
|
|
||||||
|
|
||||||
const babelify = async (code)=>(await babel.transformAsync(code, { presets: [['@babel/preset-env', { 'exclude': ['proposal-dynamic-import'] }], '@babel/preset-react'], plugins: ['@babel/plugin-transform-runtime'] })).code;
|
const babelify = async (code)=>(await babel.transformAsync(code, { presets: [['@babel/preset-env', { 'exclude': ['proposal-dynamic-import'] }], '@babel/preset-react'], plugins: ['@babel/plugin-transform-runtime'] })).code;
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ const build = async ({ bundle, render, ssr })=>{
|
|||||||
//css = `@layer bundle {\n${css}\n}`;
|
//css = `@layer bundle {\n${css}\n}`;
|
||||||
await fs.outputFile('./build/homebrew/bundle.css', css);
|
await fs.outputFile('./build/homebrew/bundle.css', css);
|
||||||
await fs.outputFile('./build/homebrew/bundle.js', bundle);
|
await fs.outputFile('./build/homebrew/bundle.js', bundle);
|
||||||
await fs.outputFile('./build/homebrew/ssr.js', ssr);
|
await fs.outputFile('./build/homebrew/ssr.cjs', ssr);
|
||||||
|
|
||||||
await fs.copy('./client/homebrew/favicon.ico', './build/assets/favicon.ico');
|
await fs.copy('./client/homebrew/favicon.ico', './build/assets/favicon.ico');
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ fs.emptyDirSync('./build');
|
|||||||
const themes = { Legacy: {}, V3: {} };
|
const themes = { Legacy: {}, V3: {} };
|
||||||
|
|
||||||
let themeFiles = fs.readdirSync('./themes/Legacy');
|
let themeFiles = fs.readdirSync('./themes/Legacy');
|
||||||
for (dir of themeFiles) {
|
for (let dir of themeFiles) {
|
||||||
const themeData = JSON.parse(fs.readFileSync(`./themes/Legacy/${dir}/settings.json`).toString());
|
const themeData = JSON.parse(fs.readFileSync(`./themes/Legacy/${dir}/settings.json`).toString());
|
||||||
themeData.path = dir;
|
themeData.path = dir;
|
||||||
themes.Legacy[dir] = (themeData);
|
themes.Legacy[dir] = (themeData);
|
||||||
@@ -68,7 +69,7 @@ fs.emptyDirSync('./build');
|
|||||||
}
|
}
|
||||||
|
|
||||||
themeFiles = fs.readdirSync('./themes/V3');
|
themeFiles = fs.readdirSync('./themes/V3');
|
||||||
for (dir of themeFiles) {
|
for (let dir of themeFiles) {
|
||||||
const themeData = JSON.parse(fs.readFileSync(`./themes/V3/${dir}/settings.json`).toString());
|
const themeData = JSON.parse(fs.readFileSync(`./themes/V3/${dir}/settings.json`).toString());
|
||||||
themeData.path = dir;
|
themeData.path = dir;
|
||||||
themes.V3[dir] = (themeData);
|
themes.V3[dir] = (themeData);
|
||||||
@@ -104,14 +105,14 @@ fs.emptyDirSync('./build');
|
|||||||
const editorThemesBuildDir = './build/homebrew/cm-themes';
|
const editorThemesBuildDir = './build/homebrew/cm-themes';
|
||||||
await fs.copy('./node_modules/codemirror/theme', editorThemesBuildDir);
|
await fs.copy('./node_modules/codemirror/theme', editorThemesBuildDir);
|
||||||
await fs.copy('./themes/codeMirror/customThemes', editorThemesBuildDir);
|
await fs.copy('./themes/codeMirror/customThemes', editorThemesBuildDir);
|
||||||
editorThemeFiles = fs.readdirSync(editorThemesBuildDir);
|
const editorThemeFiles = fs.readdirSync(editorThemesBuildDir);
|
||||||
|
|
||||||
const editorThemeFile = './themes/codeMirror/editorThemes.json';
|
const editorThemeFile = './themes/codeMirror/editorThemes.json';
|
||||||
if(fs.existsSync(editorThemeFile)) fs.rmSync(editorThemeFile);
|
if(fs.existsSync(editorThemeFile)) fs.rmSync(editorThemeFile);
|
||||||
const stream = fs.createWriteStream(editorThemeFile, { flags: 'a' });
|
const stream = fs.createWriteStream(editorThemeFile, { flags: 'a' });
|
||||||
stream.write('[\n"default"');
|
stream.write('[\n"default"');
|
||||||
|
|
||||||
for (themeFile of editorThemeFiles) {
|
for (let themeFile of editorThemeFiles) {
|
||||||
stream.write(`,\n"${themeFile.slice(0, -4)}"`);
|
stream.write(`,\n"${themeFile.slice(0, -4)}"`);
|
||||||
}
|
}
|
||||||
stream.write('\n]\n');
|
stream.write('\n]\n');
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
const DB = require('./server/db.js');
|
import DB from './server/db.js';
|
||||||
const server = require('./server/app.js');
|
import server from './server/app.js';
|
||||||
const config = require('./server/config.js');
|
import config from './server/config.js';
|
||||||
|
|
||||||
DB.connect(config).then(()=>{
|
DB.connect(config).then(()=>{
|
||||||
// Ensure that we have successfully connected to the database
|
// Ensure that we have successfully connected to the database
|
||||||
// before launching server
|
// before launching server
|
||||||
const PORT = process.env.PORT || config.get('web_port') || 8000;
|
const PORT = process.env.PORT || config.get('web_port') || 8000;
|
||||||
server.app.listen(PORT, ()=>{
|
server.listen(PORT, ()=>{
|
||||||
const reset = '\x1b[0m'; // Reset to default style
|
const reset = '\x1b[0m'; // Reset to default style
|
||||||
const bright = '\x1b[1m'; // Bright (bold) style
|
const bright = '\x1b[1m'; // Bright (bold) style
|
||||||
const cyan = '\x1b[36m'; // Cyan color
|
const cyan = '\x1b[36m'; // Cyan color
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
const HomebrewModel = require('./homebrew.model.js').model;
|
import {model as HomebrewModel } from './homebrew.model.js';
|
||||||
const NotificationModel = require('./notifications.model.js').model;
|
import {model as NotificationModel } from './notifications.model.js';
|
||||||
const router = require('express').Router();
|
import express from 'express';
|
||||||
const Moment = require('moment');
|
import Moment from 'moment';
|
||||||
const templateFn = require('../client/template.js');
|
import zlib from 'zlib';
|
||||||
const zlib = require('zlib');
|
import templateFn from '../client/template.js';
|
||||||
|
|
||||||
|
import HomebrewAPI from './homebrew.api.js';
|
||||||
|
import asyncHandler from 'express-async-handler';
|
||||||
|
import { splitTextStyleAndMetadata } from '../shared/helpers.js';
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
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';
|
||||||
@@ -66,23 +72,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 +91,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)=>{
|
||||||
@@ -144,6 +154,7 @@ router.get('/admin/notification/all', async (req, res, next)=>{
|
|||||||
try {
|
try {
|
||||||
const notifications = await NotificationModel.getAll();
|
const notifications = await NotificationModel.getAll();
|
||||||
return res.json(notifications);
|
return res.json(notifications);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error getting all notifications: ', error.message);
|
console.log('Error getting all notifications: ', error.message);
|
||||||
return res.status(500).json({ message: error.message });
|
return res.status(500).json({ message: error.message });
|
||||||
@@ -151,7 +162,6 @@ router.get('/admin/notification/all', async (req, res, next)=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/admin/notification/add', mw.adminOnly, async (req, res, next)=>{
|
router.post('/admin/notification/add', mw.adminOnly, async (req, res, next)=>{
|
||||||
console.table(req.body);
|
|
||||||
try {
|
try {
|
||||||
const notification = await NotificationModel.addNotification(req.body);
|
const notification = await NotificationModel.addNotification(req.body);
|
||||||
return res.status(201).json(notification);
|
return res.status(201).json(notification);
|
||||||
@@ -182,4 +192,4 @@ router.get('/admin', mw.adminOnly, (req, res)=>{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
export default router;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
const supertest = require('supertest');
|
import supertest from 'supertest';
|
||||||
|
import HBApp from './app.js';
|
||||||
|
import {model as NotificationModel } from './notifications.model.js';
|
||||||
|
|
||||||
const app = supertest.agent(require('app.js').app)
|
|
||||||
.set('X-Forwarded-Proto', 'https');
|
|
||||||
|
|
||||||
const NotificationModel = require('./notifications.model.js').model;
|
// Mimic https responses to avoid being redirected all the time
|
||||||
|
const app = supertest.agent(HBApp).set('X-Forwarded-Proto', 'https');
|
||||||
|
|
||||||
describe('Tests for admin api', ()=>{
|
describe('Tests for admin api', ()=>{
|
||||||
afterEach(()=>{
|
afterEach(()=>{
|
||||||
|
|||||||
@@ -1,25 +1,41 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
// Set working directory to project root
|
// Set working directory to project root
|
||||||
|
import { dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import packageJSON from './../package.json' with { type: "json" };
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
process.chdir(`${__dirname}/..`);
|
process.chdir(`${__dirname}/..`);
|
||||||
|
const version = packageJSON.version;
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
import jwt from 'jwt-simple';
|
||||||
|
import express from 'express';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
import config from './config.js';
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
const _ = require('lodash');
|
|
||||||
const jwt = require('jwt-simple');
|
|
||||||
const express = require('express');
|
|
||||||
const yaml = require('js-yaml');
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const config = require('./config.js');
|
|
||||||
const fs = require('fs-extra');
|
|
||||||
|
|
||||||
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
import api from './homebrew.api.js';
|
||||||
const GoogleActions = require('./googleActions.js');
|
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = api;
|
||||||
const serveCompressedStaticAssets = require('./static-assets.mv.js');
|
import adminApi from './admin.api.js';
|
||||||
const sanitizeFilename = require('sanitize-filename');
|
import vaultApi from './vault.api.js';
|
||||||
const asyncHandler = require('express-async-handler');
|
import GoogleActions from './googleActions.js';
|
||||||
const templateFn = require('./../client/template.js');
|
import serveCompressedStaticAssets from './static-assets.mv.js';
|
||||||
|
import sanitizeFilename from 'sanitize-filename';
|
||||||
|
import asyncHandler from 'express-async-handler';
|
||||||
|
import templateFn from '../client/template.js';
|
||||||
|
import {model as HomebrewModel } from './homebrew.model.js';
|
||||||
|
|
||||||
const { DEFAULT_BREW } = require('./brewDefaults.js');
|
import { DEFAULT_BREW } from './brewDefaults.js';
|
||||||
|
import { splitTextStyleAndMetadata } from '../shared/helpers.js';
|
||||||
|
|
||||||
const { splitTextStyleAndMetadata } = require('../shared/helpers.js');
|
//==== Middleware Imports ====//
|
||||||
|
import contentNegotiation from './middleware/content-negotiation.js';
|
||||||
|
import bodyParser from 'body-parser';
|
||||||
|
import cookieParser from 'cookie-parser';
|
||||||
|
import forceSSL from './forcessl.mw.js';
|
||||||
|
|
||||||
|
|
||||||
const sanitizeBrew = (brew, accessType)=>{
|
const sanitizeBrew = (brew, accessType)=>{
|
||||||
@@ -34,10 +50,10 @@ const sanitizeBrew = (brew, accessType)=>{
|
|||||||
app.set('trust proxy', 1 /* number of proxies between user and server */)
|
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(contentNegotiation);
|
||||||
app.use(require('body-parser').json({ limit: '25mb' }));
|
app.use(bodyParser.json({ limit: '25mb' }));
|
||||||
app.use(require('cookie-parser')());
|
app.use(cookieParser());
|
||||||
app.use(require('./forcessl.mw.js'));
|
app.use(forceSSL);
|
||||||
|
|
||||||
//Account Middleware
|
//Account Middleware
|
||||||
app.use((req, res, next)=>{
|
app.use((req, res, next)=>{
|
||||||
@@ -57,15 +73,14 @@ app.use((req, res, next)=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use(homebrewApi);
|
app.use(homebrewApi);
|
||||||
app.use(require('./admin.api.js'));
|
app.use(adminApi);
|
||||||
app.use(require('./vault.api.js'));
|
app.use(vaultApi);
|
||||||
|
|
||||||
const HomebrewModel = require('./homebrew.model.js').model;
|
const welcomeText = fs.readFileSync('client/homebrew/pages/homePage/welcome_msg.md', 'utf8');
|
||||||
const welcomeText = require('fs').readFileSync('client/homebrew/pages/homePage/welcome_msg.md', 'utf8');
|
const welcomeTextLegacy = fs.readFileSync('client/homebrew/pages/homePage/welcome_msg_legacy.md', 'utf8');
|
||||||
const welcomeTextLegacy = require('fs').readFileSync('client/homebrew/pages/homePage/welcome_msg_legacy.md', 'utf8');
|
const migrateText = fs.readFileSync('client/homebrew/pages/homePage/migrate.md', 'utf8');
|
||||||
const migrateText = require('fs').readFileSync('client/homebrew/pages/homePage/migrate.md', 'utf8');
|
const changelogText = fs.readFileSync('changelog.md', 'utf8');
|
||||||
const changelogText = require('fs').readFileSync('changelog.md', 'utf8');
|
const faqText = fs.readFileSync('faq.md', 'utf8');
|
||||||
const faqText = require('fs').readFileSync('faq.md', 'utf8');
|
|
||||||
|
|
||||||
String.prototype.replaceAll = function(s, r){return this.split(s).join(r);};
|
String.prototype.replaceAll = function(s, r){return this.split(s).join(r);};
|
||||||
|
|
||||||
@@ -479,7 +494,7 @@ const renderPage = async (req, res)=>{
|
|||||||
deployment : config.get('heroku_app_name') ?? ''
|
deployment : config.get('heroku_app_name') ?? ''
|
||||||
};
|
};
|
||||||
const props = {
|
const props = {
|
||||||
version : require('./../package.json').version,
|
version : version,
|
||||||
url : req.customUrl || req.originalUrl,
|
url : req.customUrl || req.originalUrl,
|
||||||
brew : req.brew,
|
brew : req.brew,
|
||||||
brews : req.brews,
|
brews : req.brews,
|
||||||
@@ -556,6 +571,4 @@ app.use((req, res)=>{
|
|||||||
});
|
});
|
||||||
//^=====--------------------------------------=====^//
|
//^=====--------------------------------------=====^//
|
||||||
|
|
||||||
module.exports = {
|
export default app;
|
||||||
app : app
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
|
|
||||||
// Default properties for newly-created brews
|
// Default properties for newly-created brews
|
||||||
const DEFAULT_BREW = {
|
const DEFAULT_BREW = {
|
||||||
@@ -32,7 +32,7 @@ const DEFAULT_BREW_LOAD = _.defaults(
|
|||||||
},
|
},
|
||||||
DEFAULT_BREW);
|
DEFAULT_BREW);
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
DEFAULT_BREW,
|
DEFAULT_BREW,
|
||||||
DEFAULT_BREW_LOAD
|
DEFAULT_BREW_LOAD
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
module.exports = require('nconf')
|
import nconf from 'nconf';
|
||||||
|
|
||||||
|
export default nconf
|
||||||
.argv()
|
.argv()
|
||||||
.env({ lowerCase: true })
|
.env({ lowerCase: true })
|
||||||
.file('environment', { file: `config/${process.env.NODE_ENV}.json` })
|
.file('environment', { file: `config/${process.env.NODE_ENV}.json` })
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// reused by both the main application and all tests which require database
|
// reused by both the main application and all tests which require database
|
||||||
// connection.
|
// connection.
|
||||||
|
|
||||||
const Mongoose = require('mongoose');
|
import Mongoose from 'mongoose';
|
||||||
|
|
||||||
const getMongoDBURL = (config)=>{
|
const getMongoDBURL = (config)=>{
|
||||||
return config.get('mongodb_uri') ||
|
return config.get('mongodb_uri') ||
|
||||||
@@ -31,7 +31,7 @@ const connect = async (config)=>{
|
|||||||
.catch((error)=>handleConnectionError(error));
|
.catch((error)=>handleConnectionError(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
connect : connect,
|
connect,
|
||||||
disconnect : disconnect
|
disconnect
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = (req, res, next)=>{
|
export default (req, res, next)=>{
|
||||||
if(process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'docker') return next();
|
if(process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'docker') return next();
|
||||||
if(req.header('x-forwarded-proto') !== 'https') {
|
if(req.header('x-forwarded-proto') !== 'https') {
|
||||||
return res.redirect(302, `https://${req.get('Host')}${req.url}`);
|
return res.redirect(302, `https://${req.get('Host')}${req.url}`);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
const googleDrive = require('@googleapis/drive');
|
import googleDrive from '@googleapis/drive';
|
||||||
const { nanoid } = require('nanoid');
|
import { nanoid } from 'nanoid';
|
||||||
const token = require('./token.js');
|
import token from './token.js';
|
||||||
const config = require('./config.js');
|
import config from './config.js';
|
||||||
|
|
||||||
|
|
||||||
let serviceAuth;
|
let serviceAuth;
|
||||||
if(!config.get('service_account')){
|
if(!config.get('service_account')){
|
||||||
@@ -59,7 +60,7 @@ const GoogleActions = {
|
|||||||
account.googleRefreshToken = tokens.refresh_token;
|
account.googleRefreshToken = tokens.refresh_token;
|
||||||
}
|
}
|
||||||
account.googleAccessToken = tokens.access_token;
|
account.googleAccessToken = tokens.access_token;
|
||||||
const JWTToken = token.generateAccessToken(account);
|
const JWTToken = token(account);
|
||||||
|
|
||||||
//Save updated token to cookie
|
//Save updated token to cookie
|
||||||
//res.cookie('nc_session', JWTToken, { maxAge: 1000*60*60*24*365, path: '/', sameSite: 'lax' });
|
//res.cookie('nc_session', JWTToken, { maxAge: 1000*60*60*24*365, path: '/', sameSite: 'lax' });
|
||||||
@@ -72,7 +73,7 @@ const GoogleActions = {
|
|||||||
getGoogleFolder : async (auth)=>{
|
getGoogleFolder : async (auth)=>{
|
||||||
const drive = googleDrive.drive({ version: 'v3', auth });
|
const drive = googleDrive.drive({ version: 'v3', auth });
|
||||||
|
|
||||||
fileMetadata = {
|
const fileMetadata = {
|
||||||
'name' : 'Homebrewery',
|
'name' : 'Homebrewery',
|
||||||
'mimeType' : 'application/vnd.google-apps.folder'
|
'mimeType' : 'application/vnd.google-apps.folder'
|
||||||
};
|
};
|
||||||
@@ -344,4 +345,4 @@ const GoogleActions = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = GoogleActions;
|
export default GoogleActions;
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const HomebrewModel = require('./homebrew.model.js').model;
|
import {model as HomebrewModel} from './homebrew.model.js';
|
||||||
const router = require('express').Router();
|
import express from 'express';
|
||||||
const zlib = require('zlib');
|
import zlib from 'zlib';
|
||||||
const GoogleActions = require('./googleActions.js');
|
import GoogleActions from './googleActions.js';
|
||||||
const Markdown = require('../shared/naturalcrit/markdown.js');
|
import Markdown from '../shared/naturalcrit/markdown.js';
|
||||||
const yaml = require('js-yaml');
|
import yaml from 'js-yaml';
|
||||||
const asyncHandler = require('express-async-handler');
|
import asyncHandler from 'express-async-handler';
|
||||||
const { nanoid } = require('nanoid');
|
import { nanoid } from 'nanoid';
|
||||||
const { splitTextStyleAndMetadata } = require('../shared/helpers.js');
|
import { splitTextStyleAndMetadata } from '../shared/helpers.js';
|
||||||
|
import checkClientVersion from './middleware/check-client-version.js';
|
||||||
|
|
||||||
const { DEFAULT_BREW, DEFAULT_BREW_LOAD } = require('./brewDefaults.js');
|
const router = express.Router();
|
||||||
|
|
||||||
const Themes = require('../themes/themes.json');
|
import { DEFAULT_BREW, DEFAULT_BREW_LOAD } from './brewDefaults.js';
|
||||||
|
import Themes from '../themes/themes.json' with { type: 'json' };
|
||||||
|
|
||||||
const isStaticTheme = (renderer, themeName)=>{
|
const isStaticTheme = (renderer, themeName)=>{
|
||||||
return Themes[renderer]?.[themeName] !== undefined;
|
return Themes[renderer]?.[themeName] !== undefined;
|
||||||
@@ -87,8 +89,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}`);
|
||||||
@@ -295,9 +307,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);
|
||||||
@@ -464,7 +475,7 @@ const api = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
router.use('/api', require('./middleware/check-client-version.js'));
|
router.use('/api', checkClientVersion);
|
||||||
router.post('/api', asyncHandler(api.newBrew));
|
router.post('/api', asyncHandler(api.newBrew));
|
||||||
router.put('/api/:id', asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
router.put('/api/:id', asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
||||||
router.put('/api/update/:id', asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
router.put('/api/update/:id', asyncHandler(api.getBrew('edit', true)), asyncHandler(api.updateBrew));
|
||||||
@@ -472,4 +483,4 @@ router.delete('/api/:id', asyncHandler(api.deleteBrew));
|
|||||||
router.get('/api/remove/:id', asyncHandler(api.deleteBrew));
|
router.get('/api/remove/:id', asyncHandler(api.deleteBrew));
|
||||||
router.get('/api/theme/:renderer/:id', asyncHandler(api.getThemeBundle));
|
router.get('/api/theme/:renderer/:id', asyncHandler(api.getThemeBundle));
|
||||||
|
|
||||||
module.exports = api;
|
export default api;
|
||||||
@@ -36,8 +36,9 @@ describe('Tests for api', ()=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
google = require('./googleActions.js');
|
google = require('./googleActions.js').default;
|
||||||
model = require('./homebrew.model.js').model;
|
model = require('./homebrew.model.js').model;
|
||||||
|
api = require('./homebrew.api').default;
|
||||||
|
|
||||||
jest.mock('./googleActions.js');
|
jest.mock('./googleActions.js');
|
||||||
google.authCheck = jest.fn(()=>'client');
|
google.authCheck = jest.fn(()=>'client');
|
||||||
@@ -54,8 +55,6 @@ describe('Tests for api', ()=>{
|
|||||||
setHeader : jest.fn(()=>{})
|
setHeader : jest.fn(()=>{})
|
||||||
};
|
};
|
||||||
|
|
||||||
api = require('./homebrew.api');
|
|
||||||
|
|
||||||
hbBrew = {
|
hbBrew = {
|
||||||
text : `brew text`,
|
text : `brew text`,
|
||||||
style : 'hello yes i am css',
|
style : 'hello yes i am css',
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const mongoose = require('mongoose');
|
import mongoose from 'mongoose';
|
||||||
const { nanoid } = require('nanoid');
|
import { nanoid } from 'nanoid';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const zlib = require('zlib');
|
import zlib from 'zlib';
|
||||||
|
|
||||||
|
|
||||||
const HomebrewSchema = mongoose.Schema({
|
const HomebrewSchema = mongoose.Schema({
|
||||||
shareId : { type: String, default: ()=>{return nanoid(12);}, index: { unique: true } },
|
shareId : { type: String, default: ()=>{return nanoid(12);}, index: { unique: true } },
|
||||||
@@ -44,7 +45,7 @@ HomebrewSchema.statics.get = async function(query, fields=null){
|
|||||||
const brew = await Homebrew.findOne(query, fields).orFail()
|
const brew = await Homebrew.findOne(query, fields).orFail()
|
||||||
.catch((error)=>{throw 'Can not find brew';});
|
.catch((error)=>{throw 'Can not find brew';});
|
||||||
if(!_.isNil(brew.textBin)) { // Uncompress zipped text field
|
if(!_.isNil(brew.textBin)) { // Uncompress zipped text field
|
||||||
unzipped = zlib.inflateRawSync(brew.textBin);
|
const unzipped = zlib.inflateRawSync(brew.textBin);
|
||||||
brew.text = unzipped.toString();
|
brew.text = unzipped.toString();
|
||||||
}
|
}
|
||||||
return brew;
|
return brew;
|
||||||
@@ -62,7 +63,7 @@ HomebrewSchema.statics.getByUser = async function(username, allowAccess=false, f
|
|||||||
|
|
||||||
const Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
const Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
schema : HomebrewSchema,
|
HomebrewSchema as schema,
|
||||||
model : Homebrew,
|
Homebrew as model
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
module.exports = (req, res, next)=>{
|
import packageJSON from '../../package.json' with { type: "json" };
|
||||||
|
const version = packageJSON.version;
|
||||||
|
|
||||||
|
export default (req, res, next)=>{
|
||||||
const userVersion = req.get('Homebrewery-Version');
|
const userVersion = req.get('Homebrewery-Version');
|
||||||
const version = require('../../package.json').version;
|
|
||||||
|
|
||||||
if(userVersion != version) {
|
if(userVersion != version) {
|
||||||
return res.status(412).send({
|
return res.status(412).send({
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const config = require('../config.js');
|
import config from '../config.js';
|
||||||
const nodeEnv = config.get('node_env');
|
const nodeEnv = config.get('node_env');
|
||||||
const isLocalEnvironment = config.get('local_environments').includes(nodeEnv);
|
const isLocalEnvironment = config.get('local_environments').includes(nodeEnv);
|
||||||
|
|
||||||
module.exports = (req, res, next)=>{
|
export default (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));
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
const contentNegotiationMiddleware = require('./content-negotiation.js');
|
|
||||||
|
|
||||||
describe('content-negotiation-middleware', ()=>{
|
|
||||||
let request;
|
|
||||||
let response;
|
|
||||||
let next;
|
|
||||||
|
|
||||||
beforeEach(()=>{
|
|
||||||
request = {
|
|
||||||
get : function(key) {
|
|
||||||
return this[key];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
response = {
|
|
||||||
status : jest.fn(()=>response),
|
|
||||||
send : jest.fn(()=>{})
|
|
||||||
};
|
|
||||||
next = jest.fn();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return 406 on image request', ()=>{
|
|
||||||
contentNegotiationMiddleware({
|
|
||||||
Accept : 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
|
|
||||||
...request
|
|
||||||
}, response);
|
|
||||||
|
|
||||||
expect(response.status).toHaveBeenLastCalledWith(406);
|
|
||||||
expect(response.send).toHaveBeenCalledWith({
|
|
||||||
message : 'Request for image at this URL is not supported'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call next on non-image request', ()=>{
|
|
||||||
contentNegotiationMiddleware({
|
|
||||||
Accept : 'text,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
|
|
||||||
...request
|
|
||||||
}, response, next);
|
|
||||||
|
|
||||||
expect(next).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const mongoose = require('mongoose');
|
import mongoose from 'mongoose';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
|
|
||||||
const NotificationSchema = new mongoose.Schema({
|
const NotificationSchema = new mongoose.Schema({
|
||||||
dismissKey : { type: String, unique: true, required: true },
|
dismissKey : { type: String, unique: true, required: true },
|
||||||
@@ -56,7 +56,7 @@ NotificationSchema.statics.getAll = async function() {
|
|||||||
|
|
||||||
const Notification = mongoose.model('Notification', NotificationSchema);
|
const Notification = mongoose.model('Notification', NotificationSchema);
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
schema : NotificationSchema,
|
NotificationSchema as schema,
|
||||||
model : Notification,
|
Notification as model
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const expressStaticGzip = require('express-static-gzip');
|
import expressStaticGzip from 'express-static-gzip';
|
||||||
|
|
||||||
// Serve brotli-compressed static files if available
|
// Serve brotli-compressed static files if available
|
||||||
const customCacheControlHandler=(response, path)=>{
|
const customCacheControlHandler=(response, path)=>{
|
||||||
@@ -28,4 +28,4 @@ const init=(pathToAssets)=>{
|
|||||||
} });
|
} });
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = init;
|
export default init;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
const jwt = require('jwt-simple');
|
import jwt from 'jwt-simple';
|
||||||
|
import config from './config.js';
|
||||||
// Load configuration values
|
|
||||||
const config = require('./config.js');
|
|
||||||
|
|
||||||
// Generate an Access Token for the given User ID
|
// Generate an Access Token for the given User ID
|
||||||
const generateAccessToken = (account)=>{
|
const generateAccessToken = (account)=>{
|
||||||
@@ -24,6 +22,4 @@ const generateAccessToken = (account)=>{
|
|||||||
return token;
|
return token;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export default generateAccessToken;
|
||||||
generateAccessToken : generateAccessToken
|
|
||||||
};
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const express = require('express');
|
import express from 'express';
|
||||||
const asyncHandler = require('express-async-handler');
|
import asyncHandler from 'express-async-handler';
|
||||||
const HomebrewModel = require('./homebrew.model.js').model;
|
import {model as HomebrewModel } from './homebrew.model.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -106,4 +106,4 @@ const findTotal = async (req, res)=>{
|
|||||||
router.get('/api/vault/total', asyncHandler(findTotal));
|
router.get('/api/vault/total', asyncHandler(findTotal));
|
||||||
router.get('/api/vault', asyncHandler(findBrews));
|
router.get('/api/vault', asyncHandler(findBrews));
|
||||||
|
|
||||||
module.exports = router;
|
export default router;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const yaml = require('js-yaml');
|
import yaml from 'js-yaml';
|
||||||
const request = require('../client/homebrew/utils/request-middleware.js');
|
import request from '../client/homebrew/utils/request-middleware.js';
|
||||||
|
|
||||||
const splitTextStyleAndMetadata = (brew)=>{
|
const splitTextStyleAndMetadata = (brew)=>{
|
||||||
brew.text = brew.text.replaceAll('\r\n', '\n');
|
brew.text = brew.text.replaceAll('\r\n', '\n');
|
||||||
@@ -44,14 +44,14 @@ const fetchThemeBundle = async (obj, renderer, theme)=>{
|
|||||||
if(!res) return;
|
if(!res) return;
|
||||||
|
|
||||||
const themeBundle = res.body;
|
const themeBundle = res.body;
|
||||||
themeBundle.joinedStyles = themeBundle.styles.map((style)=>`${style}`).join('\n\n');
|
themeBundle.joinedStyles = themeBundle.styles.map((style)=>`<style>${style}</style>`).join('\n\n');
|
||||||
obj.setState((prevState)=>({
|
obj.setState((prevState)=>({
|
||||||
...prevState,
|
...prevState,
|
||||||
themeBundle : themeBundle
|
themeBundle : themeBundle
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
splitTextStyleAndMetadata,
|
splitTextStyleAndMetadata,
|
||||||
printCurrentBrew,
|
printCurrentBrew,
|
||||||
fetchThemeBundle,
|
fetchThemeBundle,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const diceFont = require('../../../themes/fonts/iconFonts/diceFont.js');
|
import diceFont from '../../../themes/fonts/iconFonts/diceFont.js';
|
||||||
const elderberryInn = require('../../../themes/fonts/iconFonts/elderberryInn.js');
|
import elderberryInn from '../../../themes/fonts/iconFonts/elderberryInn.js';
|
||||||
const fontAwesome = require('../../../themes/fonts/iconFonts/fontAwesome.js');
|
import fontAwesome from '../../../themes/fonts/iconFonts/fontAwesome.js';
|
||||||
const gameIcons = require('../../../themes/fonts/iconFonts/gameIcons.js');
|
import gameIcons from '../../../themes/fonts/iconFonts/gameIcons.js';
|
||||||
|
|
||||||
const emojis = {
|
const emojis = {
|
||||||
...diceFont,
|
...diceFont,
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const Marked = require('marked');
|
import { Parser as MathParser } from 'expr-eval';
|
||||||
const MarkedExtendedTables = require('marked-extended-tables');
|
import { marked as Marked } from 'marked';
|
||||||
const { markedSmartypantsLite: MarkedSmartypantsLite } = require('marked-smartypants-lite');
|
import MarkedExtendedTables from 'marked-extended-tables';
|
||||||
const { gfmHeadingId: MarkedGFMHeadingId, resetHeadings: MarkedGFMResetHeadingIDs } = require('marked-gfm-heading-id');
|
import { markedSmartypantsLite as MarkedSmartypantsLite } from 'marked-smartypants-lite';
|
||||||
const { markedEmoji: MarkedEmojis } = require('marked-emoji');
|
import { gfmHeadingId as MarkedGFMHeadingId, resetHeadings as MarkedGFMResetHeadingIDs } from 'marked-gfm-heading-id';
|
||||||
|
import { markedEmoji as MarkedEmojis } from 'marked-emoji';
|
||||||
|
|
||||||
//Icon fonts included so they can appear in emoji autosuggest dropdown
|
//Icon fonts included so they can appear in emoji autosuggest dropdown
|
||||||
const diceFont = require('../../themes/fonts/iconFonts/diceFont.js');
|
import diceFont from '../../themes/fonts/iconFonts/diceFont.js';
|
||||||
const elderberryInn = require('../../themes/fonts/iconFonts/elderberryInn.js');
|
import elderberryInn from '../../themes/fonts/iconFonts/elderberryInn.js';
|
||||||
const fontAwesome = require('../../themes/fonts/iconFonts/fontAwesome.js');
|
import gameIcons from '../../themes/fonts/iconFonts/gameIcons.js';
|
||||||
const gameIcons = require('../../themes/fonts/iconFonts/gameIcons.js');
|
import fontAwesome from '../../themes/fonts/iconFonts/fontAwesome.js';
|
||||||
|
|
||||||
const MathParser = require('expr-eval').Parser;
|
|
||||||
const renderer = new Marked.Renderer();
|
const renderer = new Marked.Renderer();
|
||||||
const tokenizer = new Marked.Tokenizer();
|
const tokenizer = new Marked.Tokenizer();
|
||||||
|
|
||||||
@@ -854,7 +854,7 @@ const globalVarsList = {};
|
|||||||
let varsQueue = [];
|
let varsQueue = [];
|
||||||
let globalPageNumber = 0;
|
let globalPageNumber = 0;
|
||||||
|
|
||||||
module.exports = {
|
const Markdown = {
|
||||||
marked : Marked,
|
marked : Marked,
|
||||||
render : (rawBrewText, pageNumber=0)=>{
|
render : (rawBrewText, pageNumber=0)=>{
|
||||||
globalVarsList[pageNumber] = {}; //Reset global links for current page, to ensure values are parsed in order
|
globalVarsList[pageNumber] = {}; //Reset global links for current page, to ensure values are parsed in order
|
||||||
@@ -865,6 +865,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n<div class='columnSplit'></div>\n`);
|
rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n<div class='columnSplit'></div>\n`);
|
||||||
|
|
||||||
const opts = Marked.defaults;
|
const opts = Marked.defaults;
|
||||||
|
|
||||||
rawBrewText = opts.hooks.preprocess(rawBrewText);
|
rawBrewText = opts.hooks.preprocess(rawBrewText);
|
||||||
@@ -935,3 +936,6 @@ module.exports = {
|
|||||||
return errors;
|
return errors;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default Markdown;
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ 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>;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -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() {
|
const SplitPane = (props)=>{
|
||||||
return {
|
const {
|
||||||
storageKey : 'naturalcrit-pane-split',
|
onDragFinish = ()=>{},
|
||||||
onDragFinish : function(){}, //fires when dragging
|
showDividerButtons = true
|
||||||
showDividerButtons : true
|
} = props;
|
||||||
|
|
||||||
|
const [isDragging, setIsDragging] = useState(false);
|
||||||
|
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);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
const savedPos = window.localStorage.getItem(storageKey);
|
||||||
|
setDividerPos(savedPos ? limitPosition(savedPos, 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) : window.innerWidth / 2);
|
||||||
|
setLiveScroll(window.localStorage.getItem('liveScroll') === 'true');
|
||||||
|
|
||||||
|
window.addEventListener('resize', handleResize);
|
||||||
|
return ()=>window.removeEventListener('resize', handleResize);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const limitPosition = (x, min = 1, max = window.innerWidth - 13)=>Math.round(Math.min(max, Math.max(min, x)));
|
||||||
|
|
||||||
|
//when resizing, the divider should grow smaller if less space is given, then grow back if the space is restored, to the original position
|
||||||
|
const handleResize = () =>setDividerPos(limitPosition(window.localStorage.getItem(storageKey), 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)));
|
||||||
|
|
||||||
|
const handleUp =(e)=>{
|
||||||
|
e.preventDefault();
|
||||||
|
if(isDragging) {
|
||||||
|
onDragFinish(dividerPos);
|
||||||
|
window.localStorage.setItem(storageKey, dividerPos);
|
||||||
|
}
|
||||||
|
setIsDragging(false);
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
const handleDown = (e)=>{
|
||||||
return {
|
e.preventDefault();
|
||||||
currentDividerPos : null,
|
setIsDragging(true);
|
||||||
windowWidth : 0,
|
|
||||||
isDragging : false,
|
|
||||||
moveSource : false,
|
|
||||||
moveBrew : false,
|
|
||||||
showMoveArrows : true
|
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
pane1 : React.createRef(null),
|
const handleMove = (e)=>{
|
||||||
pane2 : React.createRef(null),
|
if(!isDragging) return;
|
||||||
|
|
||||||
componentDidMount : function() {
|
|
||||||
const dividerPos = window.localStorage.getItem(this.props.storageKey);
|
|
||||||
if(dividerPos){
|
|
||||||
this.setState({
|
|
||||||
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.
|
|
||||||
const loadLiveScroll = window.localStorage.getItem('liveScroll') === 'true';
|
|
||||||
this.setState({ liveScroll: loadLiveScroll });
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount : function() {
|
|
||||||
window.removeEventListener('resize', this.handleWindowResize);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleWindowResize : function() {
|
|
||||||
// Allow divider to increase in size to last user-set position
|
|
||||||
// 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({
|
|
||||||
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){
|
setDividerPos(limitPosition(e.pageX));
|
||||||
this.props.onDragFinish(this.state.currentDividerPos);
|
};
|
||||||
window.localStorage.setItem(this.props.storageKey, this.state.currentDividerPos);
|
|
||||||
}
|
|
||||||
this.setState({ isDragging: false });
|
|
||||||
},
|
|
||||||
|
|
||||||
handleDown : function(e){
|
const liveScrollToggle = ()=>{
|
||||||
e.preventDefault();
|
window.localStorage.setItem('liveScroll', String(!liveScroll));
|
||||||
this.setState({ isDragging: true });
|
setLiveScroll(!liveScroll);
|
||||||
//this.unFocus()
|
};
|
||||||
},
|
|
||||||
|
|
||||||
handleMove : function(e){
|
const renderMoveArrows = (showMoveArrows &&
|
||||||
if(!this.state.isDragging) return;
|
<>
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
const newSize = this.limitPosition(e.pageX);
|
|
||||||
this.setState({
|
|
||||||
currentDividerPos : newSize,
|
|
||||||
userSetDividerPos : newSize
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
liveScrollToggle : function() {
|
|
||||||
window.localStorage.setItem('liveScroll', String(!this.state.liveScroll));
|
|
||||||
this.setState({ liveScroll: !this.state.liveScroll });
|
|
||||||
},
|
|
||||||
/*
|
|
||||||
unFocus : function() {
|
|
||||||
if(document.selection){
|
|
||||||
document.selection.empty();
|
|
||||||
}else{
|
|
||||||
window.getSelection().removeAllRanges();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
|
|
||||||
setMoveArrows : function(newState) {
|
|
||||||
if(this.state.showMoveArrows != newState){
|
|
||||||
this.setState({
|
|
||||||
showMoveArrows : newState
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
renderMoveArrows : function(){
|
|
||||||
if(this.state.showMoveArrows) {
|
|
||||||
return <>
|
|
||||||
<div className='arrow left'
|
<div className='arrow left'
|
||||||
style={{ left: this.state.currentDividerPos-4 }}
|
onClick={()=>setMoveSource(!moveSource)} >
|
||||||
onClick={()=>this.setState({ moveSource: !this.state.moveSource })} >
|
|
||||||
<i className='fas fa-arrow-left' />
|
<i className='fas fa-arrow-left' />
|
||||||
</div>
|
</div>
|
||||||
<div className='arrow right'
|
<div className='arrow right'
|
||||||
style={{ left: this.state.currentDividerPos-4 }}
|
onClick={()=>setMoveBrew(!moveBrew)} >
|
||||||
onClick={()=>this.setState({ moveBrew: !this.state.moveBrew })} >
|
|
||||||
<i className='fas fa-arrow-right' />
|
<i className='fas fa-arrow-right' />
|
||||||
</div>
|
</div>
|
||||||
<div id='scrollToggleDiv' className={this.state.liveScroll ? 'arrow lock' : 'arrow unlock'}
|
<div id='scrollToggleDiv' className={liveScroll ? 'arrow lock' : 'arrow unlock'}
|
||||||
style={{ left: this.state.currentDividerPos-4 }}
|
onClick={liveScrollToggle} >
|
||||||
onClick={this.liveScrollToggle} >
|
<i id='scrollToggle' className={liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
||||||
<i id='scrollToggle' className={this.state.liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
|
||||||
</div>
|
</div>
|
||||||
</>;
|
</>
|
||||||
}
|
);
|
||||||
},
|
|
||||||
|
|
||||||
renderDivider : function(){
|
const renderDivider = (
|
||||||
return <>
|
<div className={`divider ${isDragging && 'dragging'}`} onPointerDown={handleDown}>
|
||||||
{this.props.showDividerButtons && this.renderMoveArrows()}
|
{showDividerButtons && renderMoveArrows}
|
||||||
<div className='divider' onPointerDown={this.handleDown} >
|
|
||||||
<div className='dots'>
|
<div className='dots'>
|
||||||
<i className='fas fa-circle' />
|
<i className='fas fa-circle' />
|
||||||
<i className='fas fa-circle' />
|
<i className='fas fa-circle' />
|
||||||
<i className='fas fa-circle' />
|
<i className='fas fa-circle' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>;
|
);
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
return (
|
||||||
return <div className='splitPane' onPointerMove={this.handleMove} onPointerUp={this.handleUp}>
|
<div className='splitPane' onPointerMove={handleMove} onPointerUp={handleUp}>
|
||||||
<Pane
|
<Pane width={dividerPos} moveBrew={moveBrew} moveSource={moveSource} liveScroll={liveScroll} setMoveArrows={setShowMoveArrows}>
|
||||||
width={this.state.currentDividerPos}
|
{props.children[0]}
|
||||||
>
|
|
||||||
{React.cloneElement(this.props.children[0], {
|
|
||||||
...(this.props.showDividerButtons && {
|
|
||||||
moveBrew : this.state.moveBrew,
|
|
||||||
moveSource : this.state.moveSource,
|
|
||||||
liveScroll : this.state.liveScroll,
|
|
||||||
setMoveArrows : this.setMoveArrows,
|
|
||||||
}),
|
|
||||||
})}
|
|
||||||
</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;
|
||||||
|
|||||||
@@ -2,49 +2,50 @@
|
|||||||
.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;
|
||||||
|
touch-action : none;
|
||||||
|
cursor : ew-resize;
|
||||||
|
background-color : #BBBBBB;
|
||||||
.dots {
|
.dots {
|
||||||
display : table-cell;
|
display : table-cell;
|
||||||
vertical-align : middle;
|
|
||||||
text-align : center;
|
text-align : center;
|
||||||
|
vertical-align : middle;
|
||||||
i {
|
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;
|
||||||
|
box-shadow : 0 4px 5px #0000007F;
|
||||||
|
translate : -50%;
|
||||||
&.left {
|
&.left {
|
||||||
.tooltipLeft('Jump to location in Editor');
|
.tooltipLeft('Jump to location in Editor');
|
||||||
top : 30px;
|
top : 30px;
|
||||||
@@ -56,14 +57,12 @@
|
|||||||
&.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>');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
test('Processes the markdown within an HTML block if its just a class wrapper', function() {
|
test('Processes the markdown within an HTML block if its just a class wrapper', function() {
|
||||||
const source = '<div>*Bold text*</div>';
|
const source = '<div>*Bold text*</div>';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
describe('Inline Definition Lists', ()=>{
|
describe('Inline Definition Lists', ()=>{
|
||||||
test('No Term 1 Definition', function() {
|
test('No Term 1 Definition', function() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
// Marked.js adds line returns after closing tags on some default tokens.
|
// Marked.js adds line returns after closing tags on some default tokens.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
describe('Hard Breaks', ()=>{
|
describe('Hard Breaks', ()=>{
|
||||||
test('Single Break', function() {
|
test('Single Break', function() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
// Marked.js adds line returns after closing tags on some default tokens.
|
// Marked.js adds line returns after closing tags on some default tokens.
|
||||||
// This removes those line returns for comparison sake.
|
// This removes those line returns for comparison sake.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
const Markdown = require('naturalcrit/markdown.js');
|
import Markdown from 'naturalcrit/markdown.js';
|
||||||
|
|
||||||
// Marked.js adds line returns after closing tags on some default tokens.
|
// Marked.js adds line returns after closing tags on some default tokens.
|
||||||
// This removes those line returns for comparison sake.
|
// This removes those line returns for comparison sake.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const supertest = require('supertest');
|
import supertest from 'supertest';
|
||||||
|
import HBApp from 'app.js';
|
||||||
|
|
||||||
// Mimic https responses to avoid being redirected all the time
|
// Mimic https responses to avoid being redirected all the time
|
||||||
const app = supertest.agent(require('app.js').app)
|
const app = supertest.agent(HBApp).set('X-Forwarded-Proto', 'https');
|
||||||
.set('X-Forwarded-Proto', 'https');
|
|
||||||
|
|
||||||
describe('Tests for static pages', ()=>{
|
describe('Tests for static pages', ()=>{
|
||||||
it('Home page works', ()=>{
|
it('Home page works', ()=>{
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const Markdown = require('../../../../shared/naturalcrit/markdown.js');
|
import Markdown from '../../../../shared/naturalcrit/markdown.js';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createFooterFunc : function(headerSize=1){
|
createFooterFunc : function(headerSize=1){
|
||||||
|
|||||||
@@ -93,4 +93,4 @@ const diceFont = {
|
|||||||
'df_solid_small_dot_d6_6' : 'df solid-small-dot-d6-6'
|
'df_solid_small_dot_d6_6' : 'df solid-small-dot-d6-6'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = diceFont;
|
export default diceFont;
|
||||||
@@ -206,4 +206,4 @@ const elderberryInn = {
|
|||||||
'ei_wish' : 'ei wish'
|
'ei_wish' : 'ei wish'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = elderberryInn;
|
export default elderberryInn;
|
||||||
@@ -2051,4 +2051,4 @@ const fontAwesome = {
|
|||||||
'fab_zhihu' : 'fab fa-zhihu'
|
'fab_zhihu' : 'fab fa-zhihu'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = fontAwesome;
|
export default fontAwesome;
|
||||||
@@ -506,4 +506,4 @@ const gameIcons = {
|
|||||||
'gi_acid' : 'gi acid'
|
'gi_acid' : 'gi acid'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = gameIcons;
|
export default gameIcons;
|
||||||
Reference in New Issue
Block a user