bstraehle commited on
Commit
9a34b97
·
verified ·
1 Parent(s): 6baf519

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -37
app.py CHANGED
@@ -76,49 +76,46 @@ with gr.Blocks() as gaia:
76
  fn=inject_js,
77
  js="""
78
  () => {
79
- // Inject CSS
80
- const style = document.createElement('style');
81
- style.textContent = '.auto-expand textarea { overflow-y: hidden !important; min-height: 42px !important; }';
82
- document.head.appendChild(style);
83
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  function setupAutoExpand() {
85
- const textareas = document.querySelectorAll('.auto-expand textarea');
86
- console.log('Found textareas:', textareas.length);
87
-
88
- textareas.forEach(textarea => {
89
  if (textarea.dataset.autoExpandSetup) return;
90
  textarea.dataset.autoExpandSetup = 'true';
91
-
92
- // Force CSS overrides
93
- textarea.style.overflowY = 'hidden';
94
- textarea.style.minHeight = '42px';
95
-
96
- function resize() {
97
- console.log('Resizing, scrollHeight:', textarea.scrollHeight);
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
- setTimeout(setupAutoExpand, 500);
120
- setTimeout(setupAutoExpand, 1000);
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
  }