This commit is contained in:
Víctor Losada Hernández
2026-09-28 17:34:12 +02:00
parent 5b7efa9f1f
commit 8a372c1454
21 changed files with 191 additions and 193 deletions
@@ -109,7 +109,7 @@ const BrewCleanup = ({})=>{
<td style={{ width: '200px' }}>{Moment(brew.updatedAt).fromNow()}</td> <td style={{ width: '200px' }}>{Moment(brew.updatedAt).fromNow()}</td>
<td>{brew.lastViewed ? Moment(brew.lastViewed).fromNow() : 'No last viewed date'}</td> <td>{brew.lastViewed ? Moment(brew.lastViewed).fromNow() : 'No last viewed date'}</td>
<td>{brew.googleId ? 'Google' : 'Homebrewery'}</td> <td>{brew.googleId ? 'Google' : 'Homebrewery'}</td>
</tr> </tr>;
})} })}
</tbody> </tbody>
</table> </table>
@@ -120,7 +120,7 @@ const BrewCleanup = ({})=>{
return <div className='result'> return <div className='result'>
{deleteButton && <button onClick={()=>cleanup(type)} className='remove'> {deleteButton && <button onClick={()=>cleanup(type)} className='remove'>
{pendingLost && type === "lost" || pendingJunk && type === "junk" {pendingLost && type === 'lost' || pendingJunk && type === 'junk'
? <i className='fas fa-spin fa-spinner' /> ? <i className='fas fa-spin fa-spinner' />
: <span><i className='fas fa-times' /> Remove</span> : <span><i className='fas fa-times' /> Remove</span>
} }
+1 -1
View File
@@ -46,7 +46,7 @@ const settingsCompartment = new Compartment();
import { generalKeymap, markdownKeymap, cssKeymap, formatCSS } from './extensions/customKeyMaps.js'; import { generalKeymap, markdownKeymap, cssKeymap, formatCSS } from './extensions/customKeyMaps.js';
import foldOnPages from './extensions/customFolding.js'; import foldOnPages from './extensions/customFolding.js';
import { customHighlightStyle , customHighlightPlugin } from './extensions/customHighlight.js'; import { customHighlightStyle, customHighlightPlugin } from './extensions/customHighlight.js';
import { legacyCustomHighlightStyle } from './extensions/legacyCustomHighlight.js'; import { legacyCustomHighlightStyle } from './extensions/legacyCustomHighlight.js';
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m; const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
@@ -14,25 +14,24 @@ export async function formatCSS(view) {
const code = empty ? fullDoc : selection; const code = empty ? fullDoc : selection;
let formatted = await prettier.format(code, { let formatted = await prettier.format(code, {
parser: 'css', parser : 'css',
plugins: [postcssPlugin], plugins : [postcssPlugin],
// formatting options // formatting options
tabWidth: 2, tabWidth : 2,
useTabs: false, useTabs : false,
printWidth: 100, printWidth : 100,
singleQuote: false, singleQuote : false,
trailingComma: 'all', trailingComma : 'all',
bracketSpacing: true, bracketSpacing : true,
endOfLine: 'lf' endOfLine : 'lf'
}); });
//format manually single declaration rules to span one line. //format manually single declaration rules to span one line.
//Prettier can't do it by default, this is crude but it works //Prettier can't do it by default, this is crude but it works
formatted = formatted.replace( formatted = formatted.replace(
/([^{]+)\{\s*\n\s*([^;\n]+:[^;\n]+;)\s*\n\s*\}(\s*)/g, /([^{]+)\{\s*\n\s*([^;\n]+:[^;\n]+;)\s*\n\s*\}(\s*)/g,
(_, selector, decl, whitespace) => (_, selector, decl, whitespace)=>`${selector} { ${decl.trim()} }${whitespace}`
`${selector} { ${decl.trim()} }${whitespace}`
); );
if(formatted === code) return true; if(formatted === code) return true;
@@ -103,8 +103,8 @@ const BrewRenderer = (props)=>{
const pagesRef = useRef(null); const pagesRef = useRef(null);
const [visiblePages, setVisiblePages] = useState([]); const [visiblePages, setVisiblePages] = useState([]);
const [centerPage , setCenterPage ] = useState(1); const [centerPage, setCenterPage] = useState(1);
const [headerState , setHeaderState ] = useState(false); const [headerState, setHeaderState] = useState(false);
const [state, setState] = useState({ const [state, setState] = useState({
isMounted : false, isMounted : false,
@@ -158,8 +158,7 @@ const BrewRenderer = (props)=>{
return false; return false;
}; };
const renderDummyPage = (index)=> const renderDummyPage = (index)=><div className='phb page' id={`p${index + 1}`} key={index}>
<div className='phb page' id={`p${index + 1}`} key={index}>
<i className='fas fa-spinner fa-spin' /> <i className='fas fa-spinner fa-spin' />
</div>; </div>;
+1 -1
View File
@@ -12,7 +12,7 @@ export default function(){
return ()=>{ return ()=>{
document.removeEventListener('print:startprep', handlePrintStartPrep); document.removeEventListener('print:startprep', handlePrintStartPrep);
document.removeEventListener('print:finishedprep', handlePrintPrepFinished); document.removeEventListener('print:finishedprep', handlePrintPrepFinished);
} };
}, []); }, []);
const handlePrintStartPrep = ()=>{ setPrinting(true); }; const handlePrintStartPrep = ()=>{ setPrinting(true); };
+1 -1
View File
@@ -9,7 +9,7 @@ import _ from 'lodash';
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js'; import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx' import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx';
import SplitPane from '@components/splitPane/splitPane.jsx'; import SplitPane from '@components/splitPane/splitPane.jsx';
import Editor from '../../editor/editor.jsx'; import Editor from '../../editor/editor.jsx';
+1 -1
View File
@@ -9,7 +9,7 @@ import _ from 'lodash';
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js'; import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx' import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx';
import SplitPane from '@components/splitPane/splitPane.jsx'; import SplitPane from '@components/splitPane/splitPane.jsx';
import Editor from '../../editor/editor.jsx'; import Editor from '../../editor/editor.jsx';
+2 -2
View File
@@ -1,4 +1,4 @@
/* eslint-disable max-lines */
import './newPage.less'; import './newPage.less';
// Common imports // Common imports
@@ -10,7 +10,7 @@ import _ from 'lodash';
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js'; import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '@shared/helpers.js'; import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '@shared/helpers.js';
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx' import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx';
import SplitPane from '@components/splitPane/splitPane.jsx'; import SplitPane from '@components/splitPane/splitPane.jsx';
import Editor from '../../editor/editor.jsx'; import Editor from '../../editor/editor.jsx';
@@ -30,11 +30,11 @@ export default function useCommonEditPageFunctions(dependencies) {
save, save,
} = dependencies; } = dependencies;
const [isSaving , setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
const [lastSavedTime , setLastSavedTime] = useState(new Date()); const [lastSavedTime, setLastSavedTime] = useState(new Date());
const [autoSaveEnabled , setAutoSaveEnabled] = useState(!sandbox); const [autoSaveEnabled, setAutoSaveEnabled] = useState(!sandbox);
const [warnUnsavedChanges, setWarnUnsavedChanges] = useState(true); const [warnUnsavedChanges, setWarnUnsavedChanges] = useState(true);
const [unsavedChanges , setUnsavedChanges] = useState(false); const [unsavedChanges, setUnsavedChanges] = useState(false);
const unsavedChangesRef = useRef(unsavedChanges); // onBeforeUnload lives outside React and needs ref to unsavedChanges const unsavedChangesRef = useRef(unsavedChanges); // onBeforeUnload lives outside React and needs ref to unsavedChanges
const warnUnsavedTimeout = useRef(null); // timers live outside React and need ref to consistently track time const warnUnsavedTimeout = useRef(null); // timers live outside React and need ref to consistently track time
@@ -180,5 +180,5 @@ export default function useCommonEditPageFunctions(dependencies) {
renderSaveButton, renderSaveButton,
autoSaveEnabled, autoSaveEnabled,
unsavedChanges, unsavedChanges,
} };
} }
+8 -8
View File
@@ -44,7 +44,7 @@ export default function createAdminApi(vite) {
updatedAt : { $lt: Moment().subtract(30, 'days').toDate() }, updatedAt : { $lt: Moment().subtract(30, 'days').toDate() },
lastViewed : { $lt: Moment().subtract(30, 'days').toDate() } lastViewed : { $lt: Moment().subtract(30, 'days').toDate() }
} }, } },
{ $project: { _id: 1, textBinSize: { $binarySize: '$textBin' }, updatedAt: 1, lastViewed: 1} }, { $project: { _id: 1, textBinSize: { $binarySize: '$textBin' }, updatedAt: 1, lastViewed: 1 } },
{ $match: { textBinSize: { $lt: 140 } } }, { $match: { textBinSize: { $lt: 140 } } },
{ $limit: 300 } { $limit: 300 }
]; ];
@@ -52,14 +52,14 @@ export default function createAdminApi(vite) {
// Search for up to 500 unauthored brews that have not been viewed or updated in two years // Search for up to 500 unauthored brews that have not been viewed or updated in two years
const lostBrewsPipeline = [ const lostBrewsPipeline = [
{ {
$match: { $match : {
authors: [], authors : [],
updatedAt: { $lt: Moment().subtract(2, 'years').toDate() }, updatedAt : { $lt: Moment().subtract(2, 'years').toDate() },
lastViewed: { $lt: Moment().subtract(2, 'years').toDate() } lastViewed : { $lt: Moment().subtract(2, 'years').toDate() }
} }
}, },
{ {
$limit: 500 $limit : 500
} }
]; ];
@@ -70,7 +70,7 @@ export default function createAdminApi(vite) {
router.get('/admin/cleanupJunk', mw.adminOnly, (req, res)=>{ router.get('/admin/cleanupJunk', mw.adminOnly, (req, res)=>{
HomebrewModel.aggregate(junkBrewsPipeline).option({ maxTimeMS: 60000 }) HomebrewModel.aggregate(junkBrewsPipeline).option({ maxTimeMS: 60000 })
.then((objs)=>res.json({ count: objs.length, brewCollection : objs })) .then((objs)=>res.json({ count: objs.length, brewCollection: objs }))
.catch((error)=>{ .catch((error)=>{
console.error(error); console.error(error);
res.status(500).json({ error: 'Internal Server Error' }); res.status(500).json({ error: 'Internal Server Error' });
@@ -93,7 +93,7 @@ export default function createAdminApi(vite) {
router.get('/admin/cleanupLost', mw.adminOnly, (req, res)=>{ router.get('/admin/cleanupLost', mw.adminOnly, (req, res)=>{
HomebrewModel.aggregate(lostBrewsPipeline).option({ maxTimeMS: 60000 }) HomebrewModel.aggregate(lostBrewsPipeline).option({ maxTimeMS: 60000 })
.then((objs)=>res.json({ count: objs.length, brewCollection : objs })) .then((objs)=>res.json({ count: objs.length, brewCollection: objs }))
.catch((error)=>{ .catch((error)=>{
console.error(error); console.error(error);
res.status(500).json({ error: 'Internal Server Error' }); res.status(500).json({ error: 'Internal Server Error' });
+4 -4
View File
@@ -137,7 +137,7 @@ export default async function createApp(vite) {
return res.sendFile(`robots.txt`, { root: process.cwd() }); return res.sendFile(`robots.txt`, { root: process.cwd() });
}); });
//serve brew for sharepage rerender //serve brew for sharepage rerender
app.get('/api/fetch/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, res) => { app.get('/api/fetch/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, res)=>{
const { brew } = req; const { brew } = req;
brew.authors.includes(req.account?.username) brew.authors.includes(req.account?.username)
? sanitizeBrew(brew, 'shareAuthor') ? sanitizeBrew(brew, 'shareAuthor')
@@ -285,9 +285,9 @@ export default async function createApp(vite) {
'<head>', '<head>',
`<head>\n` `<head>\n`
+ `<script id="props">` + `<script id="props">`
+ `window.__INITIAL_PROPS__ = ` + safeProps + `window.__INITIAL_PROPS__ = ${safeProps
+ `</script>\n` }</script>\n${
+ ogMetaTags ogMetaTags}`
); );
return html; return html;
+85 -85
View File
@@ -360,25 +360,25 @@ describe('Tests for api', ()=>{
trashed : false, trashed : false,
updatedAt : undefined, updatedAt : undefined,
views : 0, views : 0,
bleedSize: { bleedSize : {
top: '.125in', top : '.125in',
bottom: '.125in', bottom : '.125in',
inner: '.125in', inner : '.125in',
outer: '.125in', outer : '.125in',
}, },
columns: '2', columns : '2',
columnGutter: '.125in', columnGutter : '.125in',
legalAuthors: '', legalAuthors : '',
license: 'None', license : 'None',
safetySpace: { safetySpace : {
top: '.25in', top : '.25in',
bottom: '.25in', bottom : '.25in',
outer: '.25in', outer : '.25in',
inner: '.5in', inner : '.5in',
}, },
trimSize: { trimSize : {
width: '8.5in', width : '8.5in',
height: '11in', height : '11in',
}, },
}); });
expect(next).toHaveBeenCalled(); expect(next).toHaveBeenCalled();
@@ -471,25 +471,25 @@ describe('Tests for api', ()=>{
renderer : 'v3', renderer : 'v3',
theme : 'phb', theme : 'phb',
googleId : '12345', googleId : '12345',
bleedSize: { bleedSize : {
top: '.125in', top : '.125in',
bottom: '.125in', bottom : '.125in',
inner: '.125in', inner : '.125in',
outer: '.125in', outer : '.125in',
}, },
columns: '2', columns : '2',
columnGutter: '.125in', columnGutter : '.125in',
legalAuthors: '', legalAuthors : '',
license: 'None', license : 'None',
safetySpace: { safetySpace : {
top: '.25in', top : '.25in',
bottom: '.25in', bottom : '.25in',
outer: '.25in', outer : '.25in',
inner: '.5in', inner : '.5in',
}, },
trimSize: { trimSize : {
width: '8.5in', width : '8.5in',
height: '11in', height : '11in',
}, },
}); });
@@ -534,25 +534,25 @@ brew`);
renderer : 'v3', renderer : 'v3',
theme : 'phb', theme : 'phb',
googleId : '12345', googleId : '12345',
bleedSize: { bleedSize : {
top: '.125in', top : '.125in',
bottom: '.125in', bottom : '.125in',
inner: '.125in', inner : '.125in',
outer: '.125in', outer : '.125in',
}, },
columns: '2', columns : '2',
columnGutter: '.125in', columnGutter : '.125in',
legalAuthors: '', legalAuthors : '',
license: 'None', license : 'None',
safetySpace: { safetySpace : {
top: '.25in', top : '.25in',
bottom: '.25in', bottom : '.25in',
outer: '.25in', outer : '.25in',
inner: '.5in', inner : '.5in',
}, },
trimSize: { trimSize : {
width: '8.5in', width : '8.5in',
height: '11in', height : '11in',
}, },
}); });
@@ -708,25 +708,25 @@ brew`);
trashed : false, trashed : false,
updatedAt : undefined, updatedAt : undefined,
views : 0, views : 0,
bleedSize: { bleedSize : {
top: '.125in', top : '.125in',
bottom: '.125in', bottom : '.125in',
inner: '.125in', inner : '.125in',
outer: '.125in', outer : '.125in',
}, },
columns: '2', columns : '2',
columnGutter: '.125in', columnGutter : '.125in',
legalAuthors: '', legalAuthors : '',
license: 'None', license : 'None',
safetySpace: { safetySpace : {
top: '.25in', top : '.25in',
bottom: '.25in', bottom : '.25in',
outer: '.25in', outer : '.25in',
inner: '.5in', inner : '.5in',
}, },
trimSize: { trimSize : {
width: '8.5in', width : '8.5in',
height: '11in', height : '11in',
}, },
}); });
}); });
@@ -767,14 +767,14 @@ brew`);
expect(res.send).toHaveBeenCalledWith({ expect(res.send).toHaveBeenCalledWith({
_id : '1', _id : '1',
authors : ['test user'], authors : ['test user'],
bleedSize: { bleedSize : {
top: '.125in', top : '.125in',
bottom: '.125in', bottom : '.125in',
inner: '.125in', inner : '.125in',
outer: '.125in', outer : '.125in',
}, },
columns: '2', columns : '2',
columnGutter: '.125in', columnGutter : '.125in',
createdAt : undefined, createdAt : undefined,
description : '', description : '',
editId : expect.any(String), editId : expect.any(String),
@@ -784,13 +784,13 @@ brew`);
renderer : 'V3', renderer : 'V3',
lang : 'en', lang : 'en',
shareId : expect.any(String), shareId : expect.any(String),
legalAuthors: '', legalAuthors : '',
license: 'None', license : 'None',
safetySpace: { safetySpace : {
top: '.25in', top : '.25in',
bottom: '.25in', bottom : '.25in',
outer: '.25in', outer : '.25in',
inner: '.5in', inner : '.5in',
}, },
googleId : expect.any(String), googleId : expect.any(String),
style : undefined, style : undefined,
@@ -801,9 +801,9 @@ brew`);
thumbnail : '', thumbnail : '',
title : 'asdf', title : 'asdf',
trashed : false, trashed : false,
trimSize: { trimSize : {
width: '8.5in', width : '8.5in',
height: '11in', height : '11in',
}, },
updatedAt : undefined, updatedAt : undefined,
views : 0 views : 0
+6 -6
View File
@@ -48,9 +48,9 @@ describe(`brewSnippetsToJSON`, ()=>{
name : 'First Brew Snippet' name : 'First Brew Snippet'
}, { }, {
gen : 'I am the second brew Snippet!', gen : 'I am the second brew Snippet!',
name: 'Second Brew Snippet' name : 'Second Brew Snippet'
} }
]}] ] }]
}; };
const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, null, true); const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, null, true);
expect(rendered).toStrictEqual(testMenuObject); expect(rendered).toStrictEqual(testMenuObject);
@@ -76,7 +76,7 @@ describe(`brewSnippetsToJSON`, ()=>{
icon : '', icon : '',
name : 'Second Theme Snippet', name : 'Second Theme Snippet',
}, },
]}, ] },
{ {
name : 'Test Snippets JSON with theme snippets', name : 'Test Snippets JSON with theme snippets',
subsnippets : [ subsnippets : [
@@ -86,10 +86,10 @@ describe(`brewSnippetsToJSON`, ()=>{
}, },
{ {
gen : 'I am the second brew Snippet!', gen : 'I am the second brew Snippet!',
name: 'Second Brew Snippet' name : 'Second Brew Snippet'
} }
] ]
}]}; }] };
const rendered = brewSnippetsToJSON(`Test Snippets JSON with theme snippets`, brewSnippetsBrewTest, brewSnippetsThemeTest, true); const rendered = brewSnippetsToJSON(`Test Snippets JSON with theme snippets`, brewSnippetsBrewTest, brewSnippetsThemeTest, true);
expect(rendered).toStrictEqual(testMenuObject); expect(rendered).toStrictEqual(testMenuObject);
}); });
@@ -104,7 +104,7 @@ describe(`YAMLSnippetsToText`, ()=>{
name : 'First Brew Snippet' name : 'First Brew Snippet'
}, { }, {
gen : 'I am the second brew Snippet!', gen : 'I am the second brew Snippet!',
name: 'Second Brew Snippet' name : 'Second Brew Snippet'
} }
] ]
}]; }];
+1 -1
View File
@@ -1,6 +1,6 @@
import {hbfm} from 'marked-hbfm'; import { hbfm } from 'marked-hbfm';
describe('Non-Breaking Spaces Interactions', ()=>{ describe('Non-Breaking Spaces Interactions', ()=>{
test('I am actually a single-line definition list!', function() { test('I am actually a single-line definition list!', function() {