public IWidget BuildWidget(BaseField field, TField LayoutField) { var widgetContext = new WidgetContext(this.FormContext); widgetContext.Build(field, LayoutField); IWidget widget; if (CustomWidgetFactory.HasKey(LayoutField.WidgetType)) { widget = CustomWidgetFactory.Get(LayoutField.WidgetType).Invoke(widgetContext, LayoutField); } else { if (field != null && field.IsComputed) { widgetContext.WidgetType = FormControlType.Label; } widget = WidgetFactory.Create(widgetContext); } widget.OnCompile(); if (field != null) { ProcessEntityField(widgetContext, field, widget, LayoutField); } WidgetFeatureBuilder.Build(widgetContext, widget, field, LayoutField); return(widget); }
public static WidgetDoc Load(string path, CustomWidgetFactory customFactory = null) { var json = Tig.FS.ReadBinaryFile(path); using var root = JsonDocument.Parse(json); try { var loader = new WidgetDocLoader(path); if (customFactory != null) { loader.CustomFactory = customFactory; } var rootWidget = loader.LoadWidgetTree(root.RootElement); return(new WidgetDoc(path, rootWidget, loader.Registry, loader.ContentRegistry)); } catch (Exception e) { throw new Exception($"Unable to load widget doc '{path}'.", e); } }