Update app.py
Browse files
app.py
CHANGED
|
@@ -76,49 +76,46 @@ with gr.Blocks() as gaia:
|
|
| 76 |
fn=inject_js,
|
| 77 |
js="""
|
| 78 |
() => {
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
function setupAutoExpand() {
|
| 85 |
-
const
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
textareas.forEach(textarea => {
|
| 89 |
if (textarea.dataset.autoExpandSetup) return;
|
| 90 |
textarea.dataset.autoExpandSetup = 'true';
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
textarea.
|
| 94 |
-
textarea.
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
textarea.style.height = '42px';
|
| 99 |
-
const newHeight = Math.min(textarea.scrollHeight, 240);
|
| 100 |
-
textarea.style.height = newHeight + 'px';
|
| 101 |
-
console.log('Set height to:', newHeight);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
textarea.addEventListener('input', resize);
|
| 105 |
-
textarea.addEventListener('change', resize);
|
| 106 |
-
resize();
|
| 107 |
-
|
| 108 |
-
const observer = new MutationObserver(resize);
|
| 109 |
-
observer.observe(textarea, {
|
| 110 |
-
attributes: true,
|
| 111 |
-
childList: true,
|
| 112 |
-
characterData: true,
|
| 113 |
-
subtree: true
|
| 114 |
-
});
|
| 115 |
});
|
| 116 |
}
|
| 117 |
-
|
| 118 |
setupAutoExpand();
|
| 119 |
-
|
| 120 |
-
setTimeout(setupAutoExpand,
|
| 121 |
-
|
| 122 |
const docObserver = new MutationObserver(setupAutoExpand);
|
| 123 |
docObserver.observe(document.body, { childList: true, subtree: true });
|
| 124 |
}
|
|
|
|
| 76 |
fn=inject_js,
|
| 77 |
js="""
|
| 78 |
() => {
|
| 79 |
+
const STYLE_ID = 'auto-expand-style';
|
| 80 |
+
if (!document.getElementById(STYLE_ID)) {
|
| 81 |
+
const style = document.createElement('style');
|
| 82 |
+
style.id = STYLE_ID;
|
| 83 |
+
style.textContent = '.auto-expand textarea { overflow-y: hidden !important; resize: none !important; min-height: 48px !important; }';
|
| 84 |
+
document.head.appendChild(style);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
function resize(textarea) {
|
| 88 |
+
if (!textarea) return;
|
| 89 |
+
textarea.style.setProperty('height', '48px', 'important');
|
| 90 |
+
const maxHeight = 10 * 24;
|
| 91 |
+
const newHeight = Math.min(textarea.scrollHeight, maxHeight);
|
| 92 |
+
textarea.style.setProperty('height', newHeight + 'px', 'important');
|
| 93 |
+
if (textarea.scrollHeight > maxHeight) {
|
| 94 |
+
textarea.style.setProperty('overflow-y', 'auto', 'important');
|
| 95 |
+
} else {
|
| 96 |
+
textarea.style.setProperty('overflow-y', 'hidden', 'important');
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
function setupAutoExpand() {
|
| 101 |
+
const wrappers = document.querySelectorAll('.auto-expand textarea');
|
| 102 |
+
wrappers.forEach(textarea => {
|
|
|
|
|
|
|
| 103 |
if (textarea.dataset.autoExpandSetup) return;
|
| 104 |
textarea.dataset.autoExpandSetup = 'true';
|
| 105 |
+
|
| 106 |
+
resize(textarea);
|
| 107 |
+
textarea.addEventListener('input', () => resize(textarea));
|
| 108 |
+
textarea.addEventListener('change', () => resize(textarea));
|
| 109 |
+
|
| 110 |
+
const observer = new MutationObserver(() => resize(textarea));
|
| 111 |
+
observer.observe(textarea, { attributes: true, childList: true, characterData: true, subtree: true });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
});
|
| 113 |
}
|
| 114 |
+
|
| 115 |
setupAutoExpand();
|
| 116 |
+
const intervals = [100, 500, 1000, 2000];
|
| 117 |
+
intervals.forEach(delay => setTimeout(setupAutoExpand, delay));
|
| 118 |
+
|
| 119 |
const docObserver = new MutationObserver(setupAutoExpand);
|
| 120 |
docObserver.observe(document.body, { childList: true, subtree: true });
|
| 121 |
}
|