advanced layout: added MudItem, MudPaper, MudStack and MudGrid as new layout components

This commit is contained in:
krut_ni 2026-03-10 17:55:26 +01:00
parent 4f836e2dfb
commit 5106800399
No known key found for this signature in database
GPG Key ID: A5C0151B4DDB172C
8 changed files with 306 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using AIStudio.Tools.PluginSystem.Assistants.DataModel; using AIStudio.Tools.PluginSystem.Assistants.DataModel;
using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout;
namespace AIStudio.Tools.PluginSystem.Assistants; namespace AIStudio.Tools.PluginSystem.Assistants;
@ -43,6 +44,14 @@ public class AssistantComponentFactory
return new AssistantImage { Props = props, Children = children }; return new AssistantImage { Props = props, Children = children };
case AssistantComponentType.COLOR_PICKER: case AssistantComponentType.COLOR_PICKER:
return new AssistantColorPicker { Props = props, Children = children }; return new AssistantColorPicker { Props = props, Children = children };
case AssistantComponentType.LAYOUT_ITEM:
return new AssistantItem { Props = props, Children = children };
case AssistantComponentType.LAYOUT_GRID:
return new AssistantGrid { Props = props, Children = children };
case AssistantComponentType.LAYOUT_PAPER:
return new AssistantPaper { Props = props, Children = children };
case AssistantComponentType.LAYOUT_STACK:
return new AssistantStack { Props = props, Children = children };
default: default:
LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type"); LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type");
throw new Exception($"Unknown assistant component type: {type}"); throw new Exception($"Unknown assistant component type: {type}");

View File

@ -63,4 +63,9 @@ internal static class AssistantComponentPropHelper
public static MudBlazor.Color GetColor(string value, Color fallback) => Enum.TryParse<MudBlazor.Color>(value, out var color) ? color : fallback; public static MudBlazor.Color GetColor(string value, Color fallback) => Enum.TryParse<MudBlazor.Color>(value, out var color) ? color : fallback;
public static string GetIconSvg(string value) => MudBlazorIconRegistry.TryGetSvg(value, out var svg) ? svg : string.Empty; public static string GetIconSvg(string value) => MudBlazorIconRegistry.TryGetSvg(value, out var svg) ? svg : string.Empty;
public static Size GetComponentSize(string value, Size fallback) => Enum.TryParse<Size>(value, out var size) ? size : fallback; public static Size GetComponentSize(string value, Size fallback) => Enum.TryParse<Size>(value, out var size) ? size : fallback;
public static Justify? GetJustify(string value) => Enum.TryParse<Justify>(value, out var justify) ? justify : null;
public static AlignItems? GetAlignment(string value) => Enum.TryParse<AlignItems>(value, out var alignment) ? alignment : null;
public static Wrap? GetWrap(string value) => Enum.TryParse<Wrap>(value, out var wrap) ? wrap : null;
public static StretchItems? GetStretching(string value) => Enum.TryParse<StretchItems>(value, out var stretch) ? stretch : null;
public static Breakpoint GetBreakpoint(string value, Breakpoint fallback) => Enum.TryParse<Breakpoint>(value, out var breakpoint) ? breakpoint : fallback;
} }

View File

@ -17,4 +17,8 @@ public enum AssistantComponentType
FILE_CONTENT_READER, FILE_CONTENT_READER,
IMAGE, IMAGE,
COLOR_PICKER, COLOR_PICKER,
LAYOUT_ITEM,
LAYOUT_GRID,
LAYOUT_PAPER,
LAYOUT_STACK,
} }

View File

@ -73,7 +73,32 @@ public static class ComponentPropSpecs
), ),
[AssistantComponentType.COLOR_PICKER] = new( [AssistantComponentType.COLOR_PICKER] = new(
required: ["Name", "Label"], required: ["Name", "Label"],
optional: ["Placeholder", "ShowAlpha", "ShowToolbar", "ShowModeSwitch", "PickerVariant", "UserPrompt", "Class", "Style"] optional: [
"Placeholder", "ShowAlpha", "ShowToolbar", "ShowModeSwitch",
"PickerVariant", "UserPrompt", "Class", "Style"
]
),
[AssistantComponentType.LAYOUT_ITEM] = new(
required: ["Name"],
optional: ["Xs", "Sm", "Md", "Lg", "Xl", "Xxl", "Class", "Style"]
),
[AssistantComponentType.LAYOUT_GRID] = new(
required: ["Name"],
optional: ["Justify", "Spacing", "Class", "Style"]
),
[AssistantComponentType.LAYOUT_PAPER] = new(
required: ["Name"],
optional: [
"Height", "MaxHeight", "MinHeight", "Width", "MaxWidth", "MinWidth",
"IsOutlined", "IsSquare", "Class", "Style"
]
),
[AssistantComponentType.LAYOUT_STACK] = new(
required: ["Name"],
optional: [
"IsRow", "IsReverse", "Breakpoint", "Align", "Justify", "Stretch",
"Wrap", "Spacing", "Class", "Style",
]
), ),
}; };
} }

View File

@ -0,0 +1,40 @@
using Lua;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout;
public sealed class AssistantGrid : AssistantComponentBase
{
public override AssistantComponentType Type => AssistantComponentType.LAYOUT_GRID;
public override Dictionary<string, object> Props { get; set; } = new();
public override List<IAssistantComponent> Children { get; set; } = new();
public string Name
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Name));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Name), value);
}
public string Justify
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Justify));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Justify), value);
}
public int Spacing
{
get => AssistantComponentPropHelper.ReadInt(this.Props, nameof(this.Spacing), 6);
set => AssistantComponentPropHelper.WriteInt(this.Props, nameof(this.Spacing), value);
}
public string Class
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Class));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Class), value);
}
public string Style
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Style));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Style), value);
}
}

View File

@ -0,0 +1,64 @@
using Lua;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout;
public sealed class AssistantItem : AssistantComponentBase
{
public override AssistantComponentType Type => AssistantComponentType.LAYOUT_ITEM;
public override Dictionary<string, object> Props { get; set; } = new();
public override List<IAssistantComponent> Children { get; set; } = new();
public string Name
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Name));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Name), value);
}
public int? Xs
{
get => AssistantComponentPropHelper.ReadNullableInt(this.Props, nameof(this.Xs));
set => AssistantComponentPropHelper.WriteNullableInt(this.Props, nameof(this.Xs), value);
}
public int? Sm
{
get => AssistantComponentPropHelper.ReadNullableInt(this.Props, nameof(this.Sm));
set => AssistantComponentPropHelper.WriteNullableInt(this.Props, nameof(this.Sm), value);
}
public int? Md
{
get => AssistantComponentPropHelper.ReadNullableInt(this.Props, nameof(this.Md));
set => AssistantComponentPropHelper.WriteNullableInt(this.Props, nameof(this.Md), value);
}
public int? Lg
{
get => AssistantComponentPropHelper.ReadNullableInt(this.Props, nameof(this.Lg));
set => AssistantComponentPropHelper.WriteNullableInt(this.Props, nameof(this.Lg), value);
}
public int? Xl
{
get => AssistantComponentPropHelper.ReadNullableInt(this.Props, nameof(this.Xl));
set => AssistantComponentPropHelper.WriteNullableInt(this.Props, nameof(this.Xl), value);
}
public int? Xxl
{
get => AssistantComponentPropHelper.ReadNullableInt(this.Props, nameof(this.Xxl));
set => AssistantComponentPropHelper.WriteNullableInt(this.Props, nameof(this.Xxl), value);
}
public string Class
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Class));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Class), value);
}
public string Style
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Style));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Style), value);
}
}

View File

@ -0,0 +1,82 @@
using Lua;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout;
public sealed class AssistantPaper : AssistantComponentBase
{
public override AssistantComponentType Type => AssistantComponentType.LAYOUT_PAPER;
public override Dictionary<string, object> Props { get; set; } = new();
public override List<IAssistantComponent> Children { get; set; } = new();
public string Name
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Name));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Name), value);
}
public int Elevation
{
get => AssistantComponentPropHelper.ReadInt(this.Props, nameof(this.Elevation), 1);
set => AssistantComponentPropHelper.WriteInt(this.Props, nameof(this.Elevation), value);
}
public string Height
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Height));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Height), value);
}
public string MaxHeight
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.MaxHeight));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.MaxHeight), value);
}
public string MinHeight
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.MinHeight));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.MinHeight), value);
}
public string Width
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Width));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Width), value);
}
public string MaxWidth
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.MaxWidth));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.MaxWidth), value);
}
public string MinWidth
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.MinWidth));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.MinWidth), value);
}
public bool IsOutlined
{
get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsOutlined), false);
set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsOutlined), value);
}
public bool IsSquare
{
get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSquare), false);
set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSquare), value);
}
public string Class
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Class));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Class), value);
}
public string Style
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Style));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Style), value);
}
}

View File

@ -0,0 +1,76 @@
using Lua;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout;
public sealed class AssistantStack : AssistantComponentBase
{
public override AssistantComponentType Type => AssistantComponentType.LAYOUT_STACK;
public override Dictionary<string, object> Props { get; set; } = new();
public override List<IAssistantComponent> Children { get; set; } = new();
public string Name
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Name));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Name), value);
}
public bool IsRow
{
get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsRow), false);
set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsRow), value);
}
public bool IsReverse
{
get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsReverse), false);
set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsReverse), value);
}
public string Breakpoint
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Breakpoint));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Breakpoint), value);
}
public string Align
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Align));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Align), value);
}
public string Justify
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Justify));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Justify), value);
}
public string Stretch
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Stretch));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Stretch), value);
}
public string Wrap
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Wrap));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Wrap), value);
}
public int Spacing
{
get => AssistantComponentPropHelper.ReadInt(this.Props, nameof(this.Spacing), 3);
set => AssistantComponentPropHelper.WriteInt(this.Props, nameof(this.Spacing), value);
}
public string Class
{
get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Class));
set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Class), value);
}
public int Style
{
get => AssistantComponentPropHelper.ReadInt(this.Props, nameof(this.Style), 3);
set => AssistantComponentPropHelper.WriteInt(this.Props, nameof(this.Style), value);
}
}