@@ -19,6 +19,7 @@ interface CellInfo {
1919 error : string | null ;
2020 editor : EditorInstance | null ;
2121 errorDisplay : HTMLElement | null ;
22+ errorTimerId : number | null ;
2223}
2324
2425// ---------------------------------------------------------------------------
@@ -117,6 +118,7 @@ function gatherCells(): CellInfo[] {
117118 error : null ,
118119 editor : null ,
119120 errorDisplay : null ,
121+ errorTimerId : null ,
120122 } ) ;
121123 }
122124
@@ -246,14 +248,50 @@ async function applyEditors(
246248 }
247249}
248250
251+ const ERROR_DELAY_MS = 1000 ;
252+
253+ function clearError ( cell : CellInfo ) : void {
254+ if ( cell . errorTimerId !== null ) {
255+ clearTimeout ( cell . errorTimerId ) ;
256+ cell . errorTimerId = null ;
257+ }
258+ const el = cell . errorDisplay ! ;
259+ el . innerHTML = "" ;
260+ el . classList . remove ( "visible" , "collapsed" ) ;
261+ }
262+
263+ function showError ( cell : CellInfo , message : string ) : void {
264+ clearError ( cell ) ;
265+ cell . errorTimerId = window . setTimeout ( ( ) => {
266+ cell . errorTimerId = null ;
267+ const el = cell . errorDisplay ! ;
268+ el . innerHTML = "" ;
269+
270+ const toggle = document . createElement ( "span" ) ;
271+ toggle . className = "ggsql-error-toggle" ;
272+ toggle . textContent = "\u25B6" ;
273+
274+ const text = document . createElement ( "span" ) ;
275+ text . className = "ggsql-error-text" ;
276+ text . textContent = message ;
277+
278+ el . appendChild ( toggle ) ;
279+ el . appendChild ( text ) ;
280+ el . classList . add ( "visible" , "collapsed" ) ;
281+
282+ el . onclick = ( ) => {
283+ const isCollapsed = el . classList . toggle ( "collapsed" ) ;
284+ toggle . textContent = isCollapsed ? "\u25B6" : "\u25BC" ;
285+ } ;
286+ } , ERROR_DELAY_MS ) ;
287+ }
288+
249289async function executeCell (
250290 cell : CellInfo ,
251291 editorInst : EditorInstance ,
252292 ctx : WasmContextManager
253293) : Promise < void > {
254- const errorDisplay = cell . errorDisplay ! ;
255- errorDisplay . textContent = "" ;
256- errorDisplay . classList . remove ( "visible" ) ;
294+ clearError ( cell ) ;
257295
258296 const currentQuery = rewriteCsvRefs ( editorInst . getValue ( ) ) ;
259297
@@ -270,8 +308,7 @@ async function executeCell(
270308 ctx . executeSql ( currentQuery ) ;
271309 }
272310 } catch ( e : any ) {
273- errorDisplay . textContent = String ( e ) ;
274- errorDisplay . classList . add ( "visible" ) ;
311+ showError ( cell , String ( e ) ) ;
275312 }
276313}
277314
0 commit comments