Update pages/type_text.py
Browse files- pages/type_text.py +74 -71
pages/type_text.py
CHANGED
@@ -26,79 +26,82 @@ def make_spinner(text = "In progress..."):
|
|
26 |
|
27 |
|
28 |
def scrollToBottom():
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
//
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
68 |
}
|
69 |
-
}
|
70 |
-
|
71 |
-
// --- Logic for handling dynamically added content ---
|
72 |
-
|
73 |
-
// Create a MutationObserver instance.
|
74 |
-
// This observer will watch for changes in the DOM.
|
75 |
-
const observer = new MutationObserver(function(mutations) {
|
76 |
-
console.log("MutationObserver detected changes."); // Log when observer fires
|
77 |
-
// Use requestAnimationFrame to ensure the scroll happens after the browser
|
78 |
-
// has potentially rendered the new content.
|
79 |
-
requestAnimationFrame(scrollToBottom);
|
80 |
-
});
|
81 |
-
|
82 |
-
// Configure the observer to watch for changes to the child list of the body element.
|
83 |
-
// We keep observing the body because Streamlit adds content there,
|
84 |
-
// even if a child element is the one that scrolls.
|
85 |
-
const config = { childList: true, subtree: true };
|
86 |
-
|
87 |
-
console.log("Starting MutationObserver on document.body."); // Log when observer starts
|
88 |
-
// Start observing the document body for the configured mutations.
|
89 |
-
observer.observe(document.body, config);
|
90 |
-
|
91 |
-
// --- Initial scroll on page load ---
|
92 |
-
window.addEventListener('load', function() {
|
93 |
-
console.log("Window loaded. Initial scroll attempt."); // Log on window load
|
94 |
-
requestAnimationFrame(scrollToBottom);
|
95 |
-
});
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
|
104 |
def auto_scroll_to_bottom():
|
|
|
26 |
|
27 |
|
28 |
def scrollToBottom():
|
29 |
+
# JavaScript to scroll to bottom
|
30 |
+
JS_code = """
|
31 |
+
<script>
|
32 |
+
// Wrap the code in an Immediately Invoked Function Expression (IIFE)
|
33 |
+
// to create a private scope and potentially avoid conflicts.
|
34 |
+
(function() {
|
35 |
+
// Function to scroll to the bottom of a specific container
|
36 |
+
function scrollToBottom() {
|
37 |
+
console.log("Attempting to scroll container to bottom."); // Log when scroll function is called
|
38 |
+
|
39 |
+
// --- Identify the scrollable container ---
|
40 |
+
// Streamlit often uses a main container div. We'll try to find it.
|
41 |
+
// YOU NEED TO INSPECT YOUR DEPLOYED APP'S HTML TO FIND THE CORRECT SELECTOR
|
42 |
+
// FOR THE ELEMENT THAT ACTUALLY HAS THE SCROLLBAR.
|
43 |
+
//
|
44 |
+
// Common candidates based on Streamlit versions and structure:
|
45 |
+
// - '.stAppViewContainer'
|
46 |
+
// - '.main'
|
47 |
+
// - '.block-container'
|
48 |
+
// - Look for divs with class names starting with 'st-emotion-cache-' followed by random characters.
|
49 |
+
// - A div directly containing your dynamic content (check its class or ID)
|
50 |
+
|
51 |
+
// *** REPLACE THE SELECTOR BELOW with the correct one you found by inspecting your app's HTML ***
|
52 |
+
// Use document.querySelector('.your-class-name') for a class, or document.getElementById('your-id') for an ID.
|
53 |
+
const scrollableContainer = document.querySelector('.flex min-h-dvh flex-col'); // <--- REPLACE THIS ENTIRE LINE IF USING getElementById
|
54 |
+
|
55 |
+
if (scrollableContainer) {
|
56 |
+
console.log("Scrollable container found. Scrolling...");
|
57 |
+
// Scroll the found container to its bottom
|
58 |
+
scrollableContainer.scrollTo({
|
59 |
+
top: scrollableContainer.scrollHeight,
|
60 |
+
behavior: 'smooth'
|
61 |
+
});
|
62 |
+
} else {
|
63 |
+
console.warn("Scrollable container not found using the specified selector. Please inspect your app's HTML to find the correct class or ID.");
|
64 |
+
// Fallback to body scroll (less likely to work for Streamlit's main content area)
|
65 |
+
window.scrollTo({
|
66 |
+
top: document.body.scrollHeight,
|
67 |
+
behavior: 'smooth'
|
68 |
+
});
|
69 |
+
}
|
70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
// --- Logic for handling dynamically added content ---
|
73 |
+
|
74 |
+
// Create a MutationObserver instance.
|
75 |
+
// This observer will watch for changes in the DOM.
|
76 |
+
const observer = new MutationObserver(function(mutations) {
|
77 |
+
console.log("MutationObserver detected changes."); // Log when observer fires
|
78 |
+
// Use requestAnimationFrame to ensure the scroll happens after the browser
|
79 |
+
// has potentially rendered the new content.
|
80 |
+
requestAnimationFrame(scrollToBottom);
|
81 |
+
});
|
82 |
+
|
83 |
+
// Configure the observer to watch for changes to the child list of the body element.
|
84 |
+
// We keep observing the body because Streamlit adds content there,
|
85 |
+
// even if a child element is the one that scrolls.
|
86 |
+
const config = { childList: true, subtree: true };
|
87 |
+
|
88 |
+
console.log("Starting MutationObserver on document.body."); // Log when observer starts
|
89 |
+
// Start observing the document body for the configured mutations.
|
90 |
+
observer.observe(document.body, config);
|
91 |
+
|
92 |
+
// --- Initial scroll on page load ---
|
93 |
+
window.addEventListener('load', function() {
|
94 |
+
console.log("Window loaded. Initial scroll attempt."); // Log on window load
|
95 |
+
requestAnimationFrame(scrollToBottom);
|
96 |
+
});
|
97 |
+
|
98 |
+
})(); // End of IIFE
|
99 |
+
|
100 |
+
</script>
|
101 |
+
"""
|
102 |
+
# Render the JavaScript code
|
103 |
+
html = f'<div style="display:none">{JS_code}</div>'
|
104 |
+
st.components.v1.html(html, height=0, width=0)
|
105 |
|
106 |
|
107 |
def auto_scroll_to_bottom():
|