Skip to content

Commit e5f8c81

Browse files
committed
Clean up.
1 parent 71bde5d commit e5f8c81

File tree

1 file changed

+40
-55
lines changed

1 file changed

+40
-55
lines changed

devtools/panel/panel.js

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
/* global chrome */
22

3-
// Store the state of our inspector
3+
// --- Utility Functions ---
4+
function getObjectIcon(obj) {
5+
if (obj.isScene) return '🌍';
6+
if (obj.isCamera) return '📷';
7+
if (obj.isLight) return '💡';
8+
if (obj.isInstancedMesh) return '🔸';
9+
if (obj.isMesh) return '🔷';
10+
if (obj.type === 'Group') return '📁';
11+
return '📦';
12+
}
13+
14+
function createPropertyRow(label, value) {
15+
const row = document.createElement('div');
16+
row.className = 'property-row';
17+
row.style.display = 'flex';
18+
row.style.justifyContent = 'space-between';
19+
row.style.marginBottom = '2px';
20+
21+
const labelSpan = document.createElement('span');
22+
labelSpan.className = 'property-label';
23+
labelSpan.textContent = `${label}:`;
24+
labelSpan.style.marginRight = '10px';
25+
labelSpan.style.whiteSpace = 'nowrap';
26+
27+
const valueSpan = document.createElement('span');
28+
valueSpan.className = 'property-value';
29+
const displayValue = (value === undefined || value === null)
30+
? '–'
31+
: (typeof value === 'number' ? value.toLocaleString() : value);
32+
valueSpan.textContent = displayValue;
33+
valueSpan.style.textAlign = 'right';
34+
35+
row.appendChild(labelSpan);
36+
row.appendChild(valueSpan);
37+
return row;
38+
}
39+
40+
// --- State ---
441
const state = {
542
revision: null,
643
scenes: new Map(),
@@ -82,7 +119,6 @@ function handleThreeEvent( message ) {
82119

83120
case 'register':
84121
state.revision = message.detail.revision;
85-
updateUI();
86122
break;
87123

88124
// Handle individual renderer observation
@@ -106,8 +142,6 @@ function handleThreeEvent( message ) {
106142
// rebuilds the entire renderer element anyway, using the updated data
107143
// from state.renderers and the persisted open/closed state.
108144

109-
updateUI(); // Call updateUI to rebuild based on the new state
110-
111145
break;
112146

113147
// Handle a batch of objects for a specific scene
@@ -173,8 +207,6 @@ function handleThreeEvent( message ) {
173207

174208
} );
175209

176-
// Update UI once after processing the entire batch
177-
updateUI();
178210
break;
179211

180212
case 'committed':
@@ -184,18 +216,7 @@ function handleThreeEvent( message ) {
184216

185217
}
186218

187-
}
188-
189-
// Function to get an object icon based on its type
190-
function getObjectIcon( obj ) {
191-
192-
if ( obj.isScene ) return '🌍';
193-
if ( obj.isCamera ) return '📷';
194-
if ( obj.isLight ) return '💡';
195-
if ( obj.isInstancedMesh ) return '🔸';
196-
if ( obj.isMesh ) return '🔷';
197-
if ( obj.type === 'Group' ) return '📁';
198-
return '📦';
219+
updateUI();
199220

200221
}
201222

@@ -207,13 +228,7 @@ function renderRenderer( obj, container ) {
207228
detailsElement.setAttribute( 'data-uuid', obj.uuid );
208229

209230
// Set initial state
210-
detailsElement.open = false;
211-
212-
if ( rendererCollapsedState.has( obj.uuid ) ) {
213-
214-
detailsElement.open = rendererCollapsedState.get( obj.uuid );
215-
216-
}
231+
detailsElement.open = rendererCollapsedState.get( obj.uuid ) || false;
217232

218233
// Add toggle listener to save state
219234
detailsElement.addEventListener( 'toggle', () => {
@@ -479,33 +494,3 @@ function updateUI() {
479494
// Initial UI update
480495
clearState();
481496
updateUI();
482-
483-
// Helper function to create a property row (Label: Value)
484-
function createPropertyRow( label, value ) {
485-
486-
const row = document.createElement( 'div' );
487-
row.className = 'property-row'; // Add class for potential styling
488-
row.style.display = 'flex';
489-
row.style.justifyContent = 'space-between'; // Align label left, value right
490-
row.style.marginBottom = '2px'; // Small gap between rows
491-
492-
const labelSpan = document.createElement( 'span' );
493-
labelSpan.className = 'property-label';
494-
labelSpan.textContent = `${label}:`;
495-
labelSpan.style.marginRight = '10px'; // Space between label and value
496-
labelSpan.style.whiteSpace = 'nowrap'; // Prevent label wrapping
497-
498-
const valueSpan = document.createElement( 'span' );
499-
valueSpan.className = 'property-value';
500-
// Format numbers nicely, handle undefined/null with '–'
501-
const displayValue = ( value === undefined || value === null )
502-
? '–'
503-
: ( typeof value === 'number' ? value.toLocaleString() : value );
504-
valueSpan.textContent = displayValue;
505-
valueSpan.style.textAlign = 'right'; // Align value text to the right
506-
507-
row.appendChild( labelSpan );
508-
row.appendChild( valueSpan );
509-
return row;
510-
511-
}

0 commit comments

Comments
 (0)