mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-30 11:02:38 +00:00
Merge branch 'add-notification-client-side' of https://github.com/5e-Cleric/homebrewery; branch 'master' of https://github.com/naturalcrit/homebrewery into add-notification-client-side
This commit is contained in:
@@ -77,6 +77,24 @@ const BrewRenderer = (props)=>{
|
||||
rawPages = props.text.split(/^\\page$/gm);
|
||||
}
|
||||
|
||||
const scrollToHash = (hash) => {
|
||||
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 { scrollTop, clientHeight, scrollHeight } = e.target;
|
||||
const totalScrollableHeight = scrollHeight - clientHeight;
|
||||
@@ -150,6 +168,8 @@ const BrewRenderer = (props)=>{
|
||||
};
|
||||
|
||||
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
|
||||
renderPages(); //Make sure page is renderable before showing
|
||||
setState((prevState)=>({
|
||||
@@ -179,8 +199,8 @@ const BrewRenderer = (props)=>{
|
||||
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]);
|
||||
renderedPages = useMemo(() => renderPages(), [props.text?.length]);
|
||||
const renderedStyle = useMemo(()=> renderStyle(), [props.style, props.themeBundle]);
|
||||
renderedPages = useMemo(() => renderPages(), [props.text]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
margin-left : auto;
|
||||
box-shadow : 1px 4px 14px #000000;
|
||||
}
|
||||
*[id] {
|
||||
scroll-margin-top:100px;
|
||||
}
|
||||
}
|
||||
&::-webkit-scrollbar {
|
||||
width : 20px;
|
||||
|
||||
Reference in New Issue
Block a user