Path: redb/redb.PropsEditor/Components/NestedArrayEditor.razor Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.PropsEditor/Components/NestedArrayEditor.razor ---- @using redb.PropsEditor.Services @using Microsoft.FluentUI.AspNetCore.Components @inject PropsMetadataService MetadataService @* Renders an array of objects with expandable items *@
@(isExpanded ? "▼" : "▶") @(ElementType.Name)[] (@GetCount() items) @if (!IsReadOnly) { + Add }
@if (isExpanded && items != null) {
@for (var i = 0; i < items.Count; i++) { var index = i; var item = items[index];
[@index]
@if (!IsReadOnly) { X }
}
}
@code { /// /// The element type of the array. /// [Parameter, EditorRequired] public required Type ElementType { get; set; } /// /// The current array value. /// [Parameter] public Array? Value { get; set; } /// /// Called when the value changes. /// [Parameter] public EventCallback OnValueChanged { get; set; } /// /// Whether the editor is read-only. /// [Parameter] public bool IsReadOnly { get; set; } private bool isExpanded = false; private List? items; protected override void OnParametersSet() { if (Value != null) { items = new List(); foreach (var item in Value) { items.Add(item); } } else { items = null; } } private int GetCount() { return items?.Count ?? 0; } private async Task AddItem() { items ??= new List(); try { var newItem = Activator.CreateInstance(ElementType); items.Add(newItem); await NotifyChanged(); } catch { // Cannot create instance } } private async Task RemoveItem(int index) { if (items != null && index >= 0 && index < items.Count) { items.RemoveAt(index); await NotifyChanged(); } } private async Task UpdateItem(int index, object? value) { if (items != null && index >= 0 && index < items.Count) { items[index] = value; await NotifyChanged(); } } private async Task NotifyChanged() { if (items != null) { var array = Array.CreateInstance(ElementType, items.Count); for (var i = 0; i < items.Count; i++) { array.SetValue(items[i], i); } await OnValueChanged.InvokeAsync(array); } else { await OnValueChanged.InvokeAsync(null); } } }