Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: inspector UX improvements for user components

esengine1fdde54a4ae6
diff --git a/editor/src/globals.d.ts b/editor/src/globals.d.ts
index 99dd779a9..f1ce35168 100644
--- a/editor/src/globals.d.ts
+++ b/editor/src/globals.d.ts
@@ -1,6 +1,7 @@
interface Window {
__ESENGINE_EDITOR__?: Record<string, unknown>;
__esengine_registerComponent?: (name: string, defaults: Record<string, unknown>, isTag: boolean) => void;
+ __esengine_componentSourceMap?: Map<string, string>;
showSaveFilePicker?: (options?: {
suggestedName?: string;
types?: Array<{
diff --git a/editor/src/panels/InspectorPanel.ts b/editor/src/panels/InspectorPanel.ts
index f46588529..fdf7a213a 100644
--- a/editor/src/panels/InspectorPanel.ts
+++ b/editor/src/panels/InspectorPanel.ts
@@ -376,6 +376,12 @@ export class InspectorPanel {
}
private renderComponent(entity: Entity, component: ComponentData): void {
+ const schema = getComponentSchema(component.type);
+ if (schema?.category === 'tag') {
+ this.renderTagComponent(entity, component);
+ return;
+ }
+
const section = document.createElement('div');
section.className = 'es-component-section es-collapsible es-expanded';
@@ -403,9 +409,20 @@ export class InspectorPanel {
section.classList.toggle('es-expanded');
});
+ if (schema?.category === 'script') {
+ header.addEventListener('dblclick', () => {
+ const sourceMap = window.__esengine_componentSourceMap;
+ const scriptPath = sourceMap?.get(component.type);
+ if (!scriptPath) return;
+ const projectDir = this.getProjectDir();
+ if (projectDir) {
+ getEditorContext().shell?.openInEditor(projectDir, scriptPath);
+ }
+ });
+ }
+
section.appendChild(header);
- const schema = getComponentSchema(component.type);
if (schema) {
const propsContainer = document.createElement('div');
propsContainer.className = 'es-component-properties es-collapsible-content';
@@ -421,7 +438,11 @@ export class InspectorPanel {
const editorContainer = document.createElement('div');
editorContainer.className = 'es-property-editor';
- const currentValue = component.data[propMeta.name];
+ let currentValue = component.data[propMeta.name];
+ if (currentValue === undefined) {
+ const defaults = getDefaultComponentData(component.type);
+ currentValue = defaults[propMeta.name];
+ }
const editor = createPropertyEditor(editorContainer, {
value: currentValue,
meta: propMeta,
@@ -462,6 +483,23 @@ export class InspectorPanel {
this.contentContainer_.appendChild(section);
}
+ private renderTagComponent(entity: Entity, component: ComponentData): void {
+ const row = document.createElement('div');
+ row.className = 'es-component-section es-component-tag-row';
+ row.innerHTML = `
+ <span class="es-component-icon">${icons.tag(14)}</span>
+ <span class="es-component-title">${component.type}</span>
+ <button class="es-btn es-btn-icon es-btn-remove">${icons.x(12)}</button>
+ `;
+
+ const removeBtn = row.querySelector('.es-btn-remove');
+ removeBtn?.addEventListener('click', () => {
+ this.store_.removeComponent(entity, component.type);
+ });
+
+ this.contentContainer_.appendChild(row);
+ }
+
private renderAddComponentButton(entity: Entity, existingComponents: ComponentData[]): void {
const wrapper = document.createElement('div');
wrapper.className = 'es-add-component-wrapper';
@@ -502,7 +540,11 @@ export class InspectorPanel {
for (const info of this.editors_) {
const component = entityData.components.find(c => c.type === info.componentType);
if (component) {
- const value = component.data[info.propertyName];
+ let value = component.data[info.propertyName];
+ if (value === undefined) {
+ const defaults = getDefaultComponentData(component.type);
+ value = defaults[info.propertyName];
+ }
info.editor.update(value);
}
}
diff --git a/editor/src/styles/editor.css b/editor/src/styles/editor.css
index bb74f02a2..292cf3a84 100644
--- a/editor/src/styles/editor.css
+++ b/editor/src/styles/editor.css
@@ -660,6 +660,22 @@ svg {
border: 1px solid var(--es-border);
}
+.es-component-tag-row {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 4px 8px;
+ background: var(--es-bg-tertiary);
+}
+
+.es-component-tag-row .es-component-title {
+ flex: 1;
+}
+
+.es-component-tag-row:hover {
+ background: var(--es-bg-hover);
+}
+
.es-component-header {
display: flex;
align-items: center;