mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-25 13:42:57 +00:00
Merge branch 'master' into defang-script-546
This commit is contained in:
@@ -41,7 +41,6 @@ const BrewPage = (props)=>{
|
|||||||
props = {
|
props = {
|
||||||
contents : '',
|
contents : '',
|
||||||
index : 0,
|
index : 0,
|
||||||
hoisted : false,
|
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
const pageRef = useRef(null);
|
const pageRef = useRef(null);
|
||||||
@@ -96,7 +95,6 @@ const BrewRenderer = (props)=>{
|
|||||||
lang : '',
|
lang : '',
|
||||||
errors : [],
|
errors : [],
|
||||||
currentEditorCursorPageNum : 1,
|
currentEditorCursorPageNum : 1,
|
||||||
currentBrewRendererPageNum : 1,
|
|
||||||
themeBundle : {},
|
themeBundle : {},
|
||||||
onPageChange : ()=>{},
|
onPageChange : ()=>{},
|
||||||
...props
|
...props
|
||||||
@@ -154,17 +152,16 @@ const BrewRenderer = (props)=>{
|
|||||||
if(index == props.currentEditorCursorPageNum - 1) //Already rendered before this step
|
if(index == props.currentEditorCursorPageNum - 1) //Already rendered before this step
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(Math.abs(index - props.currentBrewRendererPageNum - 1) <= 3)
|
if(Math.abs(index - centerPage - 1) <= 3)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderDummyPage = (index)=>{
|
const renderDummyPage = (index)=>
|
||||||
return <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>;
|
||||||
};
|
|
||||||
|
|
||||||
const renderStyle = ()=>{
|
const renderStyle = ()=>{
|
||||||
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
||||||
@@ -222,9 +219,8 @@ const BrewRenderer = (props)=>{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderPages = (checkHoists = false)=>{
|
const renderPages = ()=>{
|
||||||
|
if(props.errors?.length)
|
||||||
if(props.errors && props.errors.length)
|
|
||||||
return renderedPages;
|
return renderedPages;
|
||||||
|
|
||||||
if(rawPages.length != renderedPages.length) { // Re-render all pages when page count changes
|
if(rawPages.length != renderedPages.length) { // Re-render all pages when page count changes
|
||||||
@@ -237,16 +233,10 @@ const BrewRenderer = (props)=>{
|
|||||||
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)=>{
|
||||||
const varsOnPageRegex = /([!$]?)\[((?!\s*\])(?:\\.|[^\[\]\\])+)\]/g; // Find out if there are any vars on the page.
|
if((isInView(index) || !renderedPages[index]) && typeof window !== 'undefined'){
|
||||||
const forceRender = checkHoists &&
|
|
||||||
!props.hoisted &&
|
|
||||||
(page.match(varsOnPageRegex)); // forceRender forces pages outside of the PPR range to render if true.
|
|
||||||
// This is necessary on the first load to fully populate the variable table.
|
|
||||||
if((isInView(index) || !renderedPages[index] || forceRender) && typeof window !== 'undefined'){
|
|
||||||
renderedPages[index] = renderPage(page, index); // Render any page not yet rendered, but only re-render those in PPR range
|
renderedPages[index] = renderPage(page, index); // Render any page not yet rendered, but only re-render those in PPR range
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!props.hoisted) { props.hoisted = true; } // Only fully hoist once.
|
|
||||||
return renderedPages;
|
return renderedPages;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -285,8 +275,8 @@ const BrewRenderer = (props)=>{
|
|||||||
|
|
||||||
window.addEventListener('hashchange', ()=>scrollToHash(window.location.hash));
|
window.addEventListener('hashchange', ()=>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(true); //Make sure page is renderable before showing
|
renderPages(); //Make sure page is renderable before showing
|
||||||
setState((prevState)=>({
|
setState((prevState)=>({
|
||||||
...prevState,
|
...prevState,
|
||||||
isMounted : true,
|
isMounted : true,
|
||||||
@@ -337,7 +327,7 @@ const BrewRenderer = (props)=>{
|
|||||||
<Frame id='BrewRenderer' title='Rendered Brew Content' initialContent={INITIAL_CONTENT}
|
<Frame id='BrewRenderer' title='Rendered Brew Content' 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}
|
||||||
sandbox='allow-same-origin allow-modals allow-top-navigation'
|
sandbox='allow-same-origin allow-modals allow-top-navigation'
|
||||||
>
|
>
|
||||||
<div className='brewRenderer'
|
<div className='brewRenderer'
|
||||||
|
|||||||
@@ -294,7 +294,6 @@ const EditPage = (props)=>{
|
|||||||
lang={currentBrew.lang}
|
lang={currentBrew.lang}
|
||||||
onPageChange={setCurrentBrewRendererPageNum}
|
onPageChange={setCurrentBrewRendererPageNum}
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
allowPrint={true}
|
allowPrint={true}
|
||||||
/>
|
/>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ const HomePage =(props)=>{
|
|||||||
themeBundle={themeBundle}
|
themeBundle={themeBundle}
|
||||||
onPageChange={setCurrentBrewRendererPageNum}
|
onPageChange={setCurrentBrewRendererPageNum}
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
/>
|
/>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ const NewPage = (props)=>{
|
|||||||
lang={currentBrew.lang}
|
lang={currentBrew.lang}
|
||||||
onPageChange={setCurrentBrewRendererPageNum}
|
onPageChange={setCurrentBrewRendererPageNum}
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
allowPrint={true}
|
allowPrint={true}
|
||||||
/>
|
/>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ const SharePage = (props)=>{
|
|||||||
theme={currentBrew.theme}
|
theme={currentBrew.theme}
|
||||||
themeBundle={themeBundle}
|
themeBundle={themeBundle}
|
||||||
onPageChange={handleBrewRendererPageChange}
|
onPageChange={handleBrewRendererPageChange}
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
allowPrint={true}
|
allowPrint={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user