Skip to content
This repository was archived by the owner on Jul 8, 2026. It is now read-only.

Commit 683252a

Browse files
committed
feat: add enum widget support and enhance schema handling
- Introduced a new `enum-widget.js` to facilitate the creation of dropdowns for enum values in the property tree. - Enhanced the `resolveRowWidgetType` function to recognize schema enum fields, improving widget resolution based on schema definitions. - Added `isSchemaEnumField` function to the suggestions module for better schema validation. - Updated `index.html` to include the new enum widget script, ensuring it is loaded during initialization. These changes aim to improve the user experience by providing a more dynamic and responsive property editing interface.
1 parent 9497580 commit 683252a

4 files changed

Lines changed: 463 additions & 13 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
<script src="src/widgets/bool.js" defer></script>
212212
<script src="src/widgets/number.js" defer></script>
213213
<script src="src/widgets/string.js" defer></script>
214+
<script src="src/widgets/enum-widget.js" defer></script>
214215
<script src="src/widgets/components.js" defer></script>
215216
<script src="src/performance-monitor.js" defer></script>
216217
<script src="src/startup-profiler.js" defer></script>

src/modes/suggestions.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@
156156
return outSchema.concat(outDoc);
157157
}
158158

159+
function isSchemaEnumField(key, context) {
160+
const ctx = context || {};
161+
const flat = resolveSchema(ctx);
162+
const def = flat[key];
163+
if (!def) return false;
164+
if (Array.isArray(def.enum) && def.enum.length > 0) return true;
165+
if (
166+
def.enumWidgetId &&
167+
typeof def.enumWidgetId === 'string' &&
168+
window.SchemaDB &&
169+
typeof window.SchemaDB.getEnumValuesForWidgetId === 'function'
170+
) {
171+
const vals = window.SchemaDB.getEnumValuesForWidgetId(def.enumWidgetId);
172+
return Array.isArray(vals) && vals.length > 0;
173+
}
174+
return false;
175+
}
176+
159177
function getSuggestedValues(key, context) {
160178
const ctx = context || {};
161179
const flat = resolveSchema(ctx);
@@ -276,6 +294,7 @@
276294
initSchemas,
277295
refreshSchemasAdvanced,
278296
getSuggestedKeys,
297+
isSchemaEnumField,
279298
getSuggestedValues,
280299
getWidgetType,
281300
inferTypeFromKeyName,

0 commit comments

Comments
 (0)