@@ -47,6 +47,8 @@ function isEnabled() {
47
47
return tmp === null || tmp === 'true' ;
48
48
}
49
49
class TypePanel {
50
+ /** @type {HTMLDivElement | null } */
51
+ static divAll = null ;
50
52
div = document . createElement ( 'div' ) ;
51
53
inputEnable = document . createElement ( 'input' ) ;
52
54
spanErrors = document . createElement ( 'span' ) ;
@@ -60,15 +62,19 @@ class TypePanel {
60
62
buttonSaveState = document . createElement ( 'button' ) ;
61
63
buttonClear = document . createElement ( 'button' ) ;
62
64
warnedTable = createTable ( ) ;
65
+ /** @type {Record<string, import('./Warning.js').Warning> } */
66
+ warnings = { } ;
63
67
constructor ( ) {
64
68
const {
65
69
div, inputEnable, spanErrors, span, select, option_spam, option_once, option_never,
66
70
buttonHide, buttonLoadState, buttonSaveState, buttonClear, warnedTable,
67
71
} = this ;
68
- div . style . position = "absolute" ;
69
- div . style . bottom = "0px" ;
70
- div . style . right = "0px" ;
71
- div . style . zIndex = "10" ;
72
+ TypePanel . divAll ??= document . createElement ( 'div' ) ;
73
+ const { divAll} = TypePanel ;
74
+ divAll . style . position = "absolute" ;
75
+ divAll . style . bottom = "0px" ;
76
+ divAll . style . right = "0px" ;
77
+ divAll . style . zIndex = "10" ;
72
78
niceDiv ( div ) ;
73
79
inputEnable . checked = isEnabled ( ) ;
74
80
inputEnable . type = "checkbox" ;
@@ -111,7 +117,8 @@ class TypePanel {
111
117
div . append ( inputEnable , spanErrors , span , select , buttonHide , buttonLoadState , buttonSaveState , buttonClear , warnedTable ) ;
112
118
div . style . maxHeight = '200px' ;
113
119
div . style . overflow = 'scroll' ;
114
- const finalFunc = ( ) => document . body . append ( div ) ;
120
+ divAll . append ( div ) ;
121
+ const finalFunc = ( ) => document . body . append ( divAll ) ;
115
122
// Add our <div> to <body> when possible
116
123
if ( document . readyState === "complete" ) {
117
124
finalFunc ( ) ;
@@ -150,6 +157,9 @@ class TypePanel {
150
157
localStorage . setItem ( 'rti-enabled' , 'true' ) ;
151
158
this . sendEnabledDisabledStateToWorker ( ) ;
152
159
}
160
+ report ( ) {
161
+ console . table ( this . warnings ) ;
162
+ }
153
163
lastKnownCountWithStatus = '0-true' ;
154
164
sendEnabledDisabledStateToWorker ( ) {
155
165
// Problem: First time the worker may not even have started and `this.eventSources.size === 0`
@@ -171,11 +181,11 @@ class TypePanel {
171
181
} ) ;
172
182
}
173
183
clear ( ) {
174
- const { warned } = options ;
175
- for ( const key in warned ) {
176
- const warning = warned [ key ] ;
184
+ const { warnings } = this ;
185
+ for ( const key in warnings ) {
186
+ const warning = warnings [ key ] ;
177
187
warning . tr . remove ( ) ;
178
- delete warned [ key ] ;
188
+ delete warnings [ key ] ;
179
189
}
180
190
}
181
191
get state ( ) {
@@ -184,8 +194,8 @@ class TypePanel {
184
194
/**
185
195
* @todo I would rather save loc/name because it's less likely to change in future... to keep state URL's alive
186
196
*/
187
- for ( const key in options . warned ) {
188
- const e = options . warned [ key ] ;
197
+ for ( const key in this . warnings ) {
198
+ const e = this . warnings [ key ] ;
189
199
const { state} = e ;
190
200
if ( state ) {
191
201
const { loc, name} = e ;
@@ -210,12 +220,13 @@ class TypePanel {
210
220
if ( ! json ) {
211
221
return false ;
212
222
}
223
+ const { warnings} = this ;
213
224
for ( const e of json ) {
214
225
const { loc, name, state} = e ;
215
226
/** @type {Warning|undefined } */
216
227
let foundWarning ;
217
- for ( const key in options . warned ) {
218
- const warning = options . warned [ key ] ;
228
+ for ( const key in warnings ) {
229
+ const warning = warnings [ key ] ;
219
230
if ( warning . loc === loc && warning . name === name ) {
220
231
foundWarning = warning ;
221
232
break ;
@@ -225,7 +236,7 @@ class TypePanel {
225
236
if ( ! foundWarning ) {
226
237
foundWarning = new Warning ( 'msg' , 'value' , 'expect' , loc , name ) ;
227
238
this . warnedTable ?. append ( foundWarning . tr ) ;
228
- options . warned [ `${ loc } -${ name } ` ] = foundWarning ;
239
+ warnings [ `${ loc } -${ name } ` ] = foundWarning ;
229
240
}
230
241
foundWarning . state = state ;
231
242
}
@@ -244,8 +255,9 @@ class TypePanel {
244
255
get eventSources ( ) {
245
256
/** @type {Set<EventTarget | MessageEventSource> } */
246
257
const eventSources = new Set ( ) ;
247
- for ( const key in options . warned ) {
248
- const warning = options . warned [ key ] ;
258
+ const { warnings} = this ;
259
+ for ( const key in warnings ) {
260
+ const warning = warnings [ key ] ;
249
261
if ( warning . eventSource ) {
250
262
eventSources . add ( warning . eventSource ) ;
251
263
}
@@ -259,11 +271,11 @@ class TypePanel {
259
271
const { value, expect, loc, name, valueToString, strings, extras = [ ] , key} = event . data ;
260
272
const msg = `${ loc } > The '${ name } ' argument has an invalid type. ${ strings . join ( ' ' ) } ` . trim ( ) ;
261
273
this . updateErrorCount ( ) ;
262
- let warnObj = options . warned [ key ] ;
274
+ let warnObj = this . warnings [ key ] ;
263
275
if ( ! warnObj ) {
264
276
warnObj = new Warning ( msg , value , expect , loc , name ) ;
265
277
this . warnedTable ?. append ( warnObj . tr ) ;
266
- options . warned [ key ] = warnObj ;
278
+ this . warnings [ key ] = warnObj ;
267
279
}
268
280
warnObj . event = event ;
269
281
warnObj . hits ++ ;
@@ -278,7 +290,7 @@ class TypePanel {
278
290
*/
279
291
deleteBreakpoint ( event ) {
280
292
const { key} = event . data ;
281
- const warnObj = options . warned [ key ] ;
293
+ const warnObj = this . warnings [ key ] ;
282
294
if ( ! warnObj ) {
283
295
console . warn ( "warnObj doesn't exist" , { key} ) ;
284
296
return ;
@@ -301,10 +313,4 @@ class TypePanel {
301
313
this . sendEnabledDisabledStateToWorker ( ) ;
302
314
}
303
315
}
304
- /** @type {TypePanel | undefined } */
305
- let typePanel ;
306
- // @todo create UI explicitly programmatically inside e.g. src/index.rti.js of the projects using it.
307
- if ( typeof importScripts === 'undefined' ) {
308
- typePanel = new TypePanel ( ) ;
309
- }
310
- export { niceDiv , TypePanel , typePanel } ;
316
+ export { niceDiv , TypePanel } ;
0 commit comments