예제 #1
0
 protected override void BuildRenderTree(RenderTreeBuilder builder)
 {
     builder.OpenElement(0, Port.Parent.Layer == RenderLayer.HTML ? "div" : "g");
     builder.AddAttribute(1, "class", "port" + " " + (Port.Alignment.ToString().ToLower()) + " " + (Port.Links.Count > 0 ? "has-links" : "") + " " + (Class));
     builder.AddAttribute(2, "data-port-id", Port.Id);
     builder.AddAttribute(3, "onmousedown", EventCallback.Factory.Create <MouseEventArgs>(this, OnMouseDown));
     builder.AddEventStopPropagationAttribute(4, "onmousedown", true);
     builder.AddAttribute(5, "onmouseup", EventCallback.Factory.Create <MouseEventArgs>(this, OnMouseUp));
     builder.AddEventStopPropagationAttribute(6, "onmouseup", true);
     builder.AddAttribute(7, "ontouchstart", EventCallback.Factory.Create <TouchEventArgs>(this, OnTouchStart));
     builder.AddEventStopPropagationAttribute(8, "ontouchstart", true);
     builder.AddAttribute(9, "ontouchend", EventCallback.Factory.Create <TouchEventArgs>(this, OnTouchEnd));
     builder.AddEventStopPropagationAttribute(10, "ontouchend", true);
     builder.AddEventPreventDefaultAttribute(11, "ontouchend", true);
     builder.AddElementReferenceCapture(12, (__value) => { _element = __value; });
     builder.AddContent(13, ChildContent);
     builder.CloseElement();
 }
예제 #2
0
        protected override void AddContent(RenderTreeBuilder builder, string buttonClassName)
        {
            builder.OpenElement(21, "button");

            builder.AddAttribute(23, "class", $"mediumFont ms-Button {buttonClassName} {(Disabled ? "is-disabled" : "")} {(isChecked ? "is-checked" : "")} {this.ClassName}");
            builder.AddAttribute(24, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, this.ClickHandler));
            builder.AddAttribute(25, "disabled", this.Disabled && !this.AllowDisabledFocus);
            builder.AddAttribute(26, "data-is-focusable", this.Disabled || this.Split ? false : true);
            builder.AddAttribute(27, "style", this.Style);

            builder.AddAttribute(28, "aria-selected", this.AriaSelected);
            builder.AddAttribute(29, "aria-label", this.AriaLabel);

            builder.AddElementReferenceCapture(30, (elementRef) => { RootElementReference = elementRef; });

            //skipping KeytipData component
            builder.OpenElement(40, "div");
            builder.AddAttribute(41, "class", "ms-Button-flexContainer");

            if (this.Text != null)
            {
                builder.OpenElement(51, "div");
                builder.AddAttribute(52, "class", "ms-Button-textContainer");
                builder.OpenElement(53, "div");
                builder.AddAttribute(54, "class", "ms-Button-label");
                builder.AddContent(55, this.Text);
                builder.CloseElement();
                builder.CloseElement();
            }
            if (this.AriaDescripton != null)
            {
                builder.OpenElement(71, "span");
                builder.AddAttribute(72, "class", "ms-Button-screenReaderText");
                builder.AddContent(73, this.AriaDescripton);
                builder.CloseElement();
            }
            //if (this.Text == null && this.ChildContent != null)
            //{
            //    builder.AddContent(81, this.ChildContent);
            //}

            builder.CloseElement();
            builder.CloseElement();
        }
예제 #3
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            int seq = -1;

            builder.OpenElement(seq++, "li");
            builder.AddAttribute(seq++, "id", Id);
            builder.AddAttribute(seq++, "onclick", BindMethods.GetEventHandlerValue <UIMouseEventArgs>((e) => OnClickInternal(e)));
            builder.AddAttribute(seq++, "class", "blazor-context-menu__item " + ClassCalc);
            builder.AddAttribute(seq++, "style", Visible ? "display:block;" : "display:none;");
            builder.AddAttribute(seq++, "item-enabled", Enabled.ToString().ToLower());
            builder.AddAttribute(seq++, "onmouseover", Enabled ? $"blazorContextMenu.OnMenuItemMouseOver(event, {SubmenuXOffset ?? BlazorContextMenuDefaults.SubMenuXPositionPixelsOffset}, this);" : "");
            builder.AddAttribute(seq++, "onmouseout", Enabled ? "blazorContextMenu.OnMenuItemMouseOut(event);" : "");

            builder.AddElementReferenceCapture(seq++, (reference) => MenuItemElement = reference);
            builder.AddContent(seq++, ChildContent);
            builder.CloseElement();

            base.BuildRenderTree(builder);
        }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            /*
             *  <div @attributes="Attributes"
             *       onclick="@(MouseButtonTrigger == MouseButtonTrigger.Left || MouseButtonTrigger == MouseButtonTrigger.Both ? $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'","\\'")}'); " : "")"
             *       ondblclick="@(MouseButtonTrigger == MouseButtonTrigger.DoubleClick ? $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'","\\'")}'); " : "")"
             *       oncontextmenu="@(MouseButtonTrigger == MouseButtonTrigger.Right || MouseButtonTrigger == MouseButtonTrigger.Both ? $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'","\\'")}');": "")"
             *       class="@CssClass">
             *      @ChildContent
             *  </div>
             */

            builder.OpenElement(0, WrapperTag);

            builder.AddMultipleAttributes(1, Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck <global::System.Collections.Generic.IEnumerable <global::System.Collections.Generic.KeyValuePair <string, object> > >(Attributes));

            if (MouseButtonTrigger == MouseButtonTrigger.Left || MouseButtonTrigger == MouseButtonTrigger.Both)
            {
                builder.AddAttribute(2, "onclick", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}', {StopPropagation.ToString().ToLower()});");
            }

            if (MouseButtonTrigger == MouseButtonTrigger.Right || MouseButtonTrigger == MouseButtonTrigger.Both)
            {
                builder.AddAttribute(3, "oncontextmenu", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}', {StopPropagation.ToString().ToLower()});");
            }

            if (MouseButtonTrigger == MouseButtonTrigger.DoubleClick)
            {
                builder.AddAttribute(4, "ondblclick", $"blazorContextMenu.OnContextMenu(event, '{MenuId.Replace("'", "\\'")}', {StopPropagation.ToString().ToLower()});");
            }

            if (!string.IsNullOrWhiteSpace(CssClass))
            {
                builder.AddAttribute(5, "class", CssClass);
            }
            builder.AddAttribute(6, "id", Id);
            builder.AddContent(7, ChildContent);
            builder.AddElementReferenceCapture(8, (__value) =>
            {
                contextMenuTriggerElementRef = __value;
            });
            builder.CloseElement();
        }
예제 #5
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            builder.OpenElement(0, "canvas");

            if (Width != default)
            {
                builder.AddAttribute(0, "width", Width);
            }

            if (Height != default)
            {
                builder.AddAttribute(0, "height", Height);
            }

            builder.AddElementReferenceCapture(0, el => CanvasElement = el);
            builder.CloseElement();
        }
예제 #6
0
            protected override void BuildRenderTree(RenderTreeBuilder builder)
            {
                base.BuildRenderTree(builder);

                builder.OpenElement(0, "button");
                builder.AddAttribute(1, "type", "button");

                if (OnClick.HasDelegate)
                {
                    builder.AddAttribute(2, "onclick", EventCallback.Factory.Create(this, OnClick));
                    builder.AddEventStopPropagationAttribute(3, "onclick", OnClickStopPropagation);
                    builder.AddEventPreventDefaultAttribute(4, "onclick", OnClickPreventDefault);
                }

                builder.AddElementReferenceCapture(6, elmRef => ButtomElmRef = elmRef);

                builder.AddContent(6, "Click me!");

                builder.CloseElement();
            }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            if (!Disable)
            {
                builder.OpenElement(0, Component);
                builder.AddAttribute(1, "style", "display: none;");
                builder.AddContent(2, ChildContent.Invoke(Context));
                builder.AddElementReferenceCapture(3, (refx) =>
                {
                    SourceRef.Current = refx;
                });
                builder.CloseElement();
            }
            else
            {
                builder.AddContent(4, ChildContent.Invoke(Context));
            }
        }
예제 #8
0
        public void CanAddElementReferenceCaptureInsideElement()
        {
            // Arrange
            var builder = new RenderTreeBuilder(new TestRenderer());
            Action <ElementRef> referenceCaptureAction = elementRef => { };

            // Act
            builder.OpenElement(0, "myelement");                           //  0: <myelement
            builder.AddAttribute(1, "attribute2", 123);                    //  1:     attribute2=intExpression123>
            builder.AddElementReferenceCapture(2, referenceCaptureAction); //  2:     # capture: referenceCaptureAction
            builder.AddContent(3, "some text");                            //  3:     some text
            builder.CloseElement();                                        //     </myelement>

            // Assert
            Assert.Collection(builder.GetFrames(),
                              frame => AssertFrame.Element(frame, "myelement", 4, 0),
                              frame => AssertFrame.Attribute(frame, "attribute2", "123", 1),
                              frame => AssertFrame.ElementReferenceCapture(frame, referenceCaptureAction, 2),
                              frame => AssertFrame.Text(frame, "some text", 3));
        }
예제 #9
0
        /// <inheritdoc />
        protected override void BuildRenderInput(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, "input");
            BuildRenderInput_AddCommonAttributes(builder, "text");

            var inputMode = this.InputModeEffective;

            if ((inputMode is null) && (DecimalsEffective == 0))
            {
                inputMode = Web.InputMode.Numeric;
            }
            if (inputMode is not null)
            {
                builder.AddAttribute(1001, "inputmode", inputMode.Value.ToString("f").ToLower());
            }

            builder.AddAttribute(1002, "onfocus", "this.select();");             // source: https://stackoverflow.com/questions/4067469/selecting-all-text-in-html-text-input-when-clicked
            builder.AddAttribute(1003, "onchange", EventCallback.Factory.CreateBinder <string>(this, value => CurrentValueAsString = value, CurrentValueAsString));
            builder.AddEventStopPropagationAttribute(1004, "onclick", true);

            // The counting sequence values violate all general recommendations.
            // We want the value of the HxInputNumber to be updated (rerendered) when the user input changes, even if FormatValueAsString(Value) hasn't changed.
            // The reason for this is that if a value such as "1.00" is displayed and a user modifies it to "1.0", FormatValueAsString(Value) isn't going to change,
            // the attribute is not rerendered, so the user input stays at "1.0".
            // To solve this issue, we will use the sequence values 1005, 1006, 1007, ... That way, we force Blazor to update the value anyway (because of the sequence change).
            // However, we adjust the sequence only if we want to enforce the rerendering. Otherwise, the component would update all the time.
            // (Originally, we wanted to use the sequences 1000 and 1001, which we would toggle.
            // However, this doesn't work - Blazor probably realizes that it should add the value (sequence 1000) and then remove the value (sequence 1001), resulting in a missing value of the input.)
            checked
            {
                if (forceRenderValue)
                {
                    valueSequenceOffset++;
                    forceRenderValue = false;
                }
                builder.AddAttribute(1006 + valueSequenceOffset, "value", FormatValueAsString(Value));
            }
            builder.AddElementReferenceCapture(Int32.MaxValue, elementReferece => InputElement = elementReferece);

            builder.CloseElement();
        }
예제 #10
0
파일: LxTransition.cs 프로젝트: Ieeax/web
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (!_renderContent ||
                _jsReference == null)    // Prevent rendering content until js module is loaded
            {
                return;
            }

            if (Target != null)
            {
                builder.AddContent(0, ChildContent);
            }
            else
            {
                builder.OpenElement(1, "div");
                builder.AddAttribute(2, "class", ClassNameWrapper);
                builder.AddElementReferenceCapture(3, @ref => _target = @ref);
                builder.AddContent(4, ChildContent);
                builder.CloseElement();
            }
        }
예제 #11
0
        /// <inheritdoc />
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, "select");
            builder.AddMultipleAttributes(1, AdditionalAttributes);
            builder.AddAttributeIfNotNullOrEmpty(2, "class", CssClass);
            builder.AddAttribute(3, "multiple", _isMultipleSelect);

            if (_isMultipleSelect)
            {
                builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValue)?.ToString());
                builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder <string?[]?>(this, SetCurrentValueAsStringArray, default));
            }
            else
            {
                builder.AddAttribute(6, "value", CurrentValueAsString);
                builder.AddAttribute(7, "onchange", EventCallback.Factory.CreateBinder <string?>(this, __value => CurrentValueAsString = __value, default));
            }

            builder.AddElementReferenceCapture(8, __selectReference => Element = __selectReference);
            builder.AddContent(9, ChildContent);
            builder.CloseElement();
        }
예제 #12
0
        protected override void RenderTextAddition(RenderTreeBuilder builder, ref int seq)
        {
            builder.OpenElement(seq++, "rect");
            builder.AddAttribute(seq++, "x", "0");
            builder.AddAttribute(seq++, "y", "0");
            //builder.AddAttribute(seq++, "class", "text-background blaze-rect");
            this.BuildClassAttribute(builder, ref seq);

            this.HookMouseDown(builder, ref seq);

            if (this.TextDescriptor.Editable)
            {
                this.HookDoubleClick(builder, ref seq);
            }

            builder.AddElementReferenceCapture(seq++, eref =>
            {
                this.TextBackgroundReference = eref;
            });

            builder.CloseElement();
        }
예제 #13
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (!_isVisible)
            {
                return;
            }

            var componentType = Diagram.GetComponentForModel(Node) ??
                                Diagram.Options.DefaultNodeComponent ??
                                (Node.Layer == RenderLayer.HTML ? typeof(NodeWidget) : typeof(SvgNodeWidget));

            builder.OpenElement(0, Node.Layer == RenderLayer.HTML ? "div" : "g");
            builder.AddAttribute(1, "class", $"node{(Node.Locked ? " locked" : string.Empty)}");
            builder.AddAttribute(2, "data-node-id", Node.Id);

            if (Node.Layer == RenderLayer.HTML)
            {
                builder.AddAttribute(3, "style", $"top: {Node.Position.Y.ToInvariantString()}px; left: {Node.Position.X.ToInvariantString()}px");
            }
            else
            {
                builder.AddAttribute(3, "transform", $"translate({Node.Position.X.ToInvariantString()} {Node.Position.Y.ToInvariantString()})");
            }

            builder.AddAttribute(4, "onmousedown", EventCallback.Factory.Create <MouseEventArgs>(this, OnMouseDown));
            builder.AddEventStopPropagationAttribute(5, "onmousedown", true);
            builder.AddAttribute(6, "onmouseup", EventCallback.Factory.Create <MouseEventArgs>(this, OnMouseUp));
            builder.AddEventStopPropagationAttribute(7, "onmouseup", true);
            builder.AddAttribute(8, "ontouchstart", EventCallback.Factory.Create <TouchEventArgs>(this, OnTouchStart));
            builder.AddEventStopPropagationAttribute(9, "ontouchstart", true);
            builder.AddAttribute(10, "ontouchend", EventCallback.Factory.Create <TouchEventArgs>(this, OnTouchEnd));
            builder.AddEventStopPropagationAttribute(11, "ontouchend", true);
            builder.AddEventPreventDefaultAttribute(12, "ontouchend", true);
            builder.AddElementReferenceCapture(13, value => _element = value);
            builder.OpenComponent(14, componentType);
            builder.AddAttribute(15, "Node", Node);
            builder.CloseComponent();
            builder.CloseElement();
        }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, "script");
            builder.AddAttribute(1, "skclusive", "");

            if (RootRef != null)
            {
                builder.AddElementReferenceCapture(2, elementRef => RootRef.Current = elementRef);
            }

            var providers = ScriptProviders.Distinct().OrderByDescending(provider => provider.Priority.HasValue).ThenBy(provider => provider.Priority);

            var content = new StringBuilder();

            foreach (var provider in providers)
            {
                content.AppendLine($"{Environment.NewLine}/* priority: {provider.Priority?.ToString() ?? "default"} source: {provider.GetType().Name} */");
                foreach (var script in provider.Scripts)
                {
                    var instance = Activator.CreateInstance(script);
                    if (instance is ScriptBase _script)
                    {
                        content.AppendLine(_script.GetScript());
                    }
                }
            }

            if (RenderContext.IsServer && RenderContext.IsPreRendering)
            {
                builder.AddContent(3, new MarkupString(content.ToString()));
            }
            else
            {
                builder.AddContent(4, content.ToString());
            }

            builder.CloseElement();
        }
예제 #15
0
 protected override void BuildRenderTree(RenderTreeBuilder builder)
 {
     base.BuildRenderTree(builder);
     builder.OpenElement(0, _Component);
     builder.AddAttribute(1, "class", _Class);
     builder.AddAttribute(2, "style", _Style);
     if (OnClick.HasDelegate)
     {
         builder.AddAttribute(3, "onclick", EventCallback.Factory.Create(this, HandleClick));
     }
     if (OnMouseLeave.HasDelegate)
     {
         builder.AddAttribute(4, "onmouseleave", EventCallback.Factory.Create(this, HandleMouseLeaveAsync));
     }
     if (OnMouseEnter.HasDelegate)
     {
         builder.AddAttribute(5, "onmouseenter", EventCallback.Factory.Create(this, HandleMouseEnterAsync));
     }
     if (OnFocus.HasDelegate)
     {
         builder.AddAttribute(6, "onfocus", EventCallback.Factory.Create <FocusEventArgs>(this, HandleFocusAsync));
     }
     if (OnBlur.HasDelegate)
     {
         builder.AddAttribute(7, "onblur", EventCallback.Factory.Create <FocusEventArgs>(this, HandleBlurAsync));
     }
     if (!string.IsNullOrWhiteSpace(Id))
     {
         builder.AddAttribute(8, "id", Id);
     }
     builder.AddMultipleAttributes(9, Attributes);
     builder.AddContent(8, ChildContent);
     builder.AddElementReferenceCapture(10, (__value) => {
         RootRef.Current = (ElementReference)__value;
     });
     builder.CloseElement();
 }
예제 #16
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, "style");
            builder.AddAttribute(1, "skclusive", "");

            if (RootRef != null)
            {
                builder.AddElementReferenceCapture(2, elementRef => RootRef.Current = elementRef);
            }

            var providers = StyleProviders.Distinct().OrderByDescending(provider => provider.Priority.HasValue).ThenBy(provider => provider.Priority);

            var index = 2;

            foreach (var provider in providers)
            {
                var priority = $"{Environment.NewLine}/* priority: {provider.Priority?.ToString() ?? "default"} source: {provider.GetType().Name} */";

                if (RenderContext.IsServer && RenderContext.IsPreRendering)
                {
                    builder.AddContent(index++, new MarkupString(priority));
                }
                else
                {
                    builder.AddContent(index++, priority);
                }

                foreach (var style in provider.Styles)
                {
                    builder.OpenComponent(index++, style);
                    builder.CloseComponent();
                }
            }

            builder.CloseElement();
        }
예제 #17
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            /*
             * __builder.OpenElement(0, "input");
             * __builder.AddMultipleAttributes(1, AdditionalAttributes);
             * __builder.AddAttribute(2, "type", "number");
             * __builder.AddAttribute(3, "class", CssClass);
             * __builder.AddAttribute(4, "value", stringValue);
             * __builder.AddAttribute(5, "oninput", EventCallback.Factory.Create<ChangeEventArgs>(this, OnInput));
             * __builder.AddAttribute(6, "onblur", EventCallback.Factory.Create<FocusEventArgs>(this, OnBlur));
             * __builder.CloseElement();
             */

            builder.OpenElement(0, "input");
            builder.AddAttribute(1, "step", _stepAttributeValue);
            builder.AddMultipleAttributes(2, AdditionalAttributes);
            builder.AddAttribute(3, "type", "number");

            if (!string.IsNullOrEmpty(CssClass))
            {
                builder.AddAttribute(4, "class", CssClass);
            }

            //   builder.AddAttribute(5, "value", BindConverter.FormatValue(CurrentValueAsString));
            //   builder.AddAttribute(6, "onchange", EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));

            builder.AddAttribute(5, "value", stringValue);
            builder.AddAttribute(6, "oninput", EventCallback.Factory.Create <ChangeEventArgs>(this, OnInput));
            builder.AddAttribute(7, "onblur", EventCallback.Factory.Create <FocusEventArgs>(this, OnBlur));

#if NET6_0_OR_GREATER
            builder.AddElementReferenceCapture(8, __inputReference => this.Element = __inputReference);
#endif

            builder.CloseElement();
        }
예제 #18
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);
            //Open
            builder.OpenElement(0, HtmlTag);

            //splatted attributes
            builder.AddMultipleAttributes(1, UserAttributes);
            //Class
            builder.AddAttribute(2, "class", Class);
            //Style
            builder.AddAttribute(3, "style", Style);

            // StopPropagation
            //the order matters. This has to be before content is added
            if (HtmlTag == "button")
            {
                builder.AddEventStopPropagationAttribute(5, "onclick", true);
            }

            //Reference capture
            if (Ref != null)
            {
                builder.AddElementReferenceCapture(6, async capturedRef =>
                {
                    Ref = capturedRef;
                    await RefChanged.InvokeAsync(Ref.Value);
                });
            }

            //Content
            builder.AddContent(10, ChildContent);

            //Close
            builder.CloseElement();
        }
        protected virtual void AddContent(RenderTreeBuilder builder, string buttonClassName)
        {
            if (this.Href == null)
            {
                builder.OpenElement(25, "button");
            }
            else
            {
                builder.OpenElement(25, "a");
                builder.AddAttribute(26, "href", this.Href);
            }

            if (Primary)
            {
                buttonClassName += " ms-Button--primary";
            }
            else
            {
                buttonClassName += " ms-Button--default";
            }
            if (isSplitButton)
            {
                builder.AddAttribute(27, "class", $"ms-Button {buttonClassName} {this.ClassName} {(Disabled || PrimaryDisabled || commandDisabled ? "is-disabled" : "")} {(isChecked ? "is-checked" : "")}");
                builder.AddAttribute(28, "disabled", (Disabled || PrimaryDisabled || commandDisabled) && !this.AllowDisabledFocus);
            }
            else
            {
                builder.AddAttribute(27, "class", $"ms-Button {buttonClassName} {this.ClassName} {(Disabled || commandDisabled ? " is-disabled" : "")}{(isChecked ? " is-checked" : "")}{(contextMenuShown ? " is-expanded" : "")}");
                builder.AddAttribute(28, "disabled", (this.Disabled || commandDisabled) && !this.AllowDisabledFocus);
            }
            builder.AddAttribute(29, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, this.ClickHandler));
            builder.AddAttribute(30, "onkeydown", EventCallback.Factory.Create <KeyboardEventArgs>(this, this.KeyDownHandler));

            builder.AddAttribute(31, "data-is-focusable", this.Disabled || PrimaryDisabled || commandDisabled || isSplitButton ? false : true);
            builder.AddAttribute(32, "style", this.Style);
            builder.AddMultipleAttributes(33, UnknownProperties);

            builder.AddElementReferenceCapture(34, (elementRef) => { RootElementReference = elementRef; });

            builder.OpenElement(35, "span");
            builder.AddAttribute(36, "class", "ms-Button-flexContainer");

            if (IconName != null | IconSrc != null)
            {
                builder.OpenComponent <BFUIcon>(40);
                builder.AddAttribute(41, "ClassName", "ms-Button-icon");
                builder.AddAttribute(42, "IconName", IconName);
                builder.AddAttribute(42, "IconSrc", IconSrc);
                builder.CloseComponent(); //closes Icon 40
            }
            if (this.Text != null || (isCompoundButton && SecondaryText != null))
            {
                builder.OpenElement(51, "span");
                builder.AddAttribute(52, "class", "ms-Button-textContainer");

                builder.OpenElement(53, "span");
                builder.AddAttribute(54, "class", "ms-Button-label");
                builder.AddContent(55, this.Text ?? "");
                builder.CloseElement();  //closes span (53)

                if (isCompoundButton && SecondaryText != null)
                {
                    builder.OpenElement(61, "span");
                    builder.AddAttribute(62, "class", "ms-Button-description");
                    builder.AddContent(63, SecondaryText);
                    builder.CloseElement(); //closes div 61
                }
                builder.CloseElement();     //closes div (51)
            }
            if (this.AriaDescripton != null)
            {
                builder.OpenElement(71, "span");
                builder.AddAttribute(72, "class", "ms-Button-screenReaderText");
                builder.AddContent(73, this.AriaDescripton);
                builder.CloseElement(); //closes span 71
            }
            if (this.Text == null && this.ContentTemplate != null)
            {
                builder.AddContent(81, this.ContentTemplate);
            }
            if (!isSplitButton && this.MenuItems != null && !this.HideChevron)
            {
                builder.OpenComponent <BFUIcon>(90);
                builder.AddAttribute(91, "IconName", "ChevronDown");
                builder.AddAttribute(92, "IconSrc", "IconSrc");
                builder.AddAttribute(92, "ClassName", "ms-Button-menuIcon");
                builder.CloseComponent(); //closes Icon 90
            }
            if (MenuItems != null && contextMenuShown)
            {
                builder.OpenComponent <BFUContextualMenu>(100);
                builder.AddAttribute(101, "FabricComponentTarget", this);
                builder.AddAttribute(102, "ShouldFocusOnMount", _menuShouldFocusOnMount);
                builder.AddAttribute(103, "OnDismiss", EventCallback.Factory.Create <bool>(this, (isDismissed) =>
                {
                    contextMenuShown = false;
                }));
                builder.AddAttribute(104, "Items", MenuItems);
                builder.AddAttribute(105, "DirectionalHint", DirectionalHint.BottomLeftEdge);
                builder.AddAttribute(106, "ItemTemplate", MenuItemTemplate);
                builder.AddAttribute(107, "SubordinateItemTemplate", SubordinateItemTemplate);

                builder.CloseComponent();  //closes ContextualMenu 100
            }

            builder.CloseElement(); //closes span 35

            //if (false)
            //{
            //    //render Menu, donotlayer,  not yet made
            //}
            //if (false) // menu causes inline-block div
            //{
            //    builder.CloseElement();
            //}

            builder.CloseElement();  // closing button or a
        }
예제 #20
0
        /// <inheritdoc />
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (_refreshException != null)
            {
                Exception?oldRefreshException = _refreshException;
                _refreshException = null;

                throw oldRefreshException;
            }
            builder.OpenElement(0, "div");

            if (UseGridFlexLayout)
            {
                builder.AddAttribute(1, "style", "display:flex;flex-flow: row wrap;");
            }

            builder.OpenElement(2, "div");
            builder.AddAttribute(3, "style", GetSpacerStyle(_itemsBefore));
            builder.AddElementReferenceCapture(4, elementReference => _spacerBefore = elementReference);
            builder.CloseElement();



            int lastItemIndex           = Math.Min(_itemsBefore + _visibleItemCapacity, _itemCount);
            int renderIndex             = _itemsBefore;
            int placeholdersBeforeCount = Math.Min(_loadedItemsStartIndex, lastItemIndex);

            builder.OpenRegion(5);

            // Render placeholders before the loaded items.
            for (; renderIndex < placeholdersBeforeCount; renderIndex++)
            {
                // This is a rare case where it's valid for the sequence number to be programmatically incremented.
                // This is only true because we know for certain that no other content will be alongside it.
                builder.AddContent(renderIndex, _placeholder, new PlaceholderContext(renderIndex, _itemSize));
            }

            builder.CloseRegion();

            _lastRenderedItemCount = 0;

            // Render the loaded items.
            if (_loadedItems != null && _itemTemplate != null)
            {
                IEnumerable <TItem>?itemsToShow = _loadedItems
                                                  .Skip(_itemsBefore - _loadedItemsStartIndex)
                                                  .Take(lastItemIndex - _loadedItemsStartIndex);

                builder.OpenRegion(6);



                foreach (TItem?item in itemsToShow)
                {
                    builder.OpenElement(11, "div");
                    builder.SetKey(item);
                    //builder.AddAttribute(8, "data-selection-index", _lastRenderedItemCount + _itemsBefore - _loadedItemsStartIndex + StartIndex);
                    _itemTemplate(new IndexedItem <TItem> {
                        Item = item, Index = renderIndex + _lastRenderedItemCount + StartIndex
                    })(builder);
                    _lastRenderedItemCount++;

                    builder.CloseElement();
                }

                renderIndex += _lastRenderedItemCount;

                builder.CloseRegion();
            }

            _lastRenderedPlaceholderCount = Math.Max(0, lastItemIndex - _itemsBefore - _lastRenderedItemCount);

            builder.OpenRegion(12);

            // Render the placeholders after the loaded items.
            for (; renderIndex < lastItemIndex; renderIndex++)
            {
                builder.AddContent(renderIndex, _placeholder, new PlaceholderContext(renderIndex, _itemSize));
            }

            builder.CloseRegion();

            int itemsAfter = Math.Max(0, _itemCount - _visibleItemCapacity - _itemsBefore);

            builder.OpenElement(13, "div");
            builder.AddAttribute(14, "style", GetSpacerStyle(itemsAfter));
            builder.AddElementReferenceCapture(15, elementReference => _spacerAfter = elementReference);

            builder.CloseElement();

            //builder.AddElementReferenceCapture(13, elemRef => RootElementReference = elemRef);
            builder.CloseElement();
        }
예제 #21
0
        public void Cmd_Render <T>(T _Item, int k, RenderTreeBuilder builder, int Par_ID = 0)
        {
            builder.OpenRegion(k++);

            bool   CaptureRef = false;
            string _value_id  = string.Empty;

            if (_Item.GetType().GetProperties().Any(x => x.Name == "CaptureRef"))
            {
                PropertyInfo pi_captureref = _Item.GetType().GetProperty("CaptureRef");
                if ((bool)pi_captureref.GetValue(_Item, null))
                {
                    if (_Item.GetType().GetProperties().Any(x => x.Name == "id"))
                    {
                        PropertyInfo pi_id = _Item.GetType().GetProperty("id");
                        _value_id = pi_id.GetValue(_Item, null).ToString();

                        CaptureRef = _value_id != null && !string.IsNullOrEmpty(_value_id.ToString());
                    }
                }
            }



            object _value;
            string _attrName = string.Empty;

            bool IsAllowed = true;


            builder.OpenElement(k++, _Item.GetType().Name);



            foreach (PropertyInfo pi in _Item.GetType().GetProperties().Where(x => !x.PropertyType.Name.Contains("ICollection") && !x.PropertyType.Name.Contains("CaptureRef")))
            {
                //list can't filter captureref??????
                if (pi.Name != "CaptureRef")
                {
                    IsAllowed = true;

                    _value = pi.GetValue(_Item, null);

                    if (pi.PropertyType == typeof(double))
                    {
                        if (double.IsNaN((double)_value))
                        {
                            IsAllowed = false;
                        }
                        else
                        {
                            _value = Math.Round((double)_value, 2);
                        }
                    }

                    if (IsAllowed)
                    {
                        IsAllowed = _value != null && !string.IsNullOrEmpty(_value.ToString());
                    }


                    if (IsAllowed)
                    {
                        if (pi.Name == "stroke_linecap")
                        {
                            IsAllowed = (strokeLinecap)_value != strokeLinecap.none;
                        }
                    }


                    if (IsAllowed)
                    {
                        _attrName = pi.Name;

                        if (_attrName.Equals("onclick"))
                        {
                            if ((BoolOptionsEnum)_value == BoolOptionsEnum.Yes)
                            {
                                builder.AddAttribute(1, _attrName, EventCallback.Factory.Create(this, e => Cmd_Clicked(e, Par_ID)));
                            }
                        }
                        else if (_attrName.ToLower().Equals("stoppropagation"))
                        {
                            if ((BoolOptionsEnum)_value == BoolOptionsEnum.Yes)
                            {
                                builder.AddEventStopPropagationAttribute(2, "onclick", true);
                            }
                        }
                        else
                        {
                            if (_attrName.Equals("content"))
                            {
                                builder.AddContent(3, _value.ToString());
                            }
                            else
                            {
                                if (_attrName.Contains("_"))
                                {
                                    _attrName = _attrName.Replace("_", "-");
                                }

                                builder.AddAttribute(4, _attrName, _value.ToString());
                            }
                        }
                    }
                }
            }


            PropertyInfo pi_Children = _Item.GetType().GetProperty("Children");

            if (pi_Children != null)
            {
                List <object> children = pi_Children.GetValue(_Item) as List <object>;

                foreach (object item in children)
                {
                    Cmd_Render(item, k++, builder, Par_ID);;
                }
            }



            if (CaptureRef)
            {
                builder.AddElementReferenceCapture(5, (elementReference) =>
                {
                    Elementreferences_Dictionary.Add(_value_id, elementReference);
                });
            }

            builder.CloseElement();

            builder.CloseRegion();
        }
예제 #22
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (builder != null)
            {
                base.BuildRenderTree(builder);
                // According to Ant-Design 4.0, Fallback to 1 if level is invalid.

                builder.OpenElement(1, "a");
                builder.AddAttribute(2, "class", this.ClassMapper.Class);
                builder.AddAttribute(3, "style", Style);
                if (Mark)
                {
                    builder.OpenElement(4, "mark");
                }
                if (Delete)
                {
                    builder.OpenElement(5, "del");
                }
                if (Underline)
                {
                    builder.OpenElement(6, "u");
                }
                if (Code)
                {
                    builder.OpenElement(7, "code");
                }
                if (Keyboard)
                {
                    builder.OpenElement(8, "kbd");
                }
                if (Strong)
                {
                    builder.OpenElement(9, "strong");
                }
                builder.AddContent(10, ChildContent);
                if (Strong)
                {
                    builder.CloseElement();
                }
                if (Code)
                {
                    builder.CloseElement();
                }
                if (Keyboard)
                {
                    builder.CloseElement();
                }
                if (Underline)
                {
                    builder.CloseElement();
                }
                if (Delete)
                {
                    builder.CloseElement();
                }
                if (Mark)
                {
                    builder.CloseElement();
                }
                if (Copyable)
                {
                    builder.OpenElement(11, "a");
                    builder.AddAttribute(12, "onclick", (Action)(async() => await Copy()));
                    builder.OpenComponent <Icon>(13);
                    builder.AddAttribute(14, "Type", "copy");
                    builder.AddAttribute(15, "Theme", IconThemeType.Outline);
                    builder.CloseComponent();
                    builder.CloseElement();
                }
                builder.AddElementReferenceCapture(16, r => Ref = r);
                builder.CloseElement();
            }
        }
예제 #23
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (builder != null)
            {
                base.BuildRenderTree(builder);

                string container = "input";

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    container = "groupWrapper";
                    builder.OpenElement(1, "span");
                    builder.AddAttribute(2, "class", GroupWrapperClass);
                    builder.AddAttribute(3, "style", Style);
                    builder.OpenElement(4, "span");
                    builder.AddAttribute(5, "class", $"{PrefixCls}-wrapper {PrefixCls}-group");
                }

                if (AddOnBefore != null)
                {
                    // addOnBefore
                    builder.OpenElement(11, "span");
                    builder.AddAttribute(12, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(13, AddOnBefore);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.OpenElement(21, "span");
                    builder.AddAttribute(22, "class", AffixWrapperClass);
                    if (container == "input")
                    {
                        container = "affixWrapper";
                        builder.AddAttribute(23, "style", Style);
                    }
                }

                if (Prefix != null)
                {
                    // prefix
                    builder.OpenElement(31, "span");
                    builder.AddAttribute(32, "class", $"{PrefixCls}-prefix");
                    builder.AddContent(33, Prefix);
                    builder.CloseElement();
                }

                // input
                builder.OpenElement(41, "input");
                builder.AddAttribute(42, "class", ClassMapper.Class);
                if (container == "input")
                {
                    builder.AddAttribute(43, "style", Style);
                }

                if (Attributes != null)
                {
                    builder.AddMultipleAttributes(44, Attributes);
                }

                if (AdditionalAttributes != null)
                {
                    builder.AddMultipleAttributes(45, AdditionalAttributes);
                }

                builder.AddAttribute(50, "Id", Id);
                builder.AddAttribute(51, "type", Type);
                builder.AddAttribute(60, "placeholder", Placeholder);
                builder.AddAttribute(61, "value", CurrentValue);

                // onchange 和 onblur 事件会导致点击 OnSearch 按钮时不触发 Click 事件,暂时取消这两个事件
                if (!IgnoreOnChangeAndBlur)
                {
                    builder.AddAttribute(62, "onchange", CallbackFactory.Create(this, OnChangeAsync));
                    builder.AddAttribute(65, "onblur", CallbackFactory.Create(this, OnBlurAsync));
                }

                builder.AddAttribute(63, "onkeypress", CallbackFactory.Create(this, OnKeyPressAsync));
                builder.AddAttribute(63, "onkeydown", CallbackFactory.Create(this, OnkeyDownAsync));
                builder.AddAttribute(63, "onkeyup", CallbackFactory.Create(this, OnKeyUpAsync));
                builder.AddAttribute(64, "oninput", CallbackFactory.Create(this, OnInputAsync));
                builder.AddAttribute(66, "onfocus", CallbackFactory.Create(this, OnFocusAsync));
                builder.AddAttribute(67, "onmouseup", CallbackFactory.Create(this, OnMouseUpAsync));
                builder.AddElementReferenceCapture(68, r => Ref = r);
                builder.CloseElement();

                if (Suffix != null)
                {
                    // suffix
                    builder.OpenElement(71, "span");
                    builder.AddAttribute(72, "class", $"{PrefixCls}-suffix");
                    builder.AddContent(73, Suffix);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.CloseElement();
                }

                if (AddOnAfter != null)
                {
                    // addOnAfter
                    builder.OpenElement(81, "span");
                    builder.AddAttribute(82, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(83, AddOnAfter);
                    builder.CloseElement();
                }

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    builder.CloseElement();
                    builder.CloseElement();
                }
            }
        }
예제 #24
0
        /// <inheritdoc />
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenRegion(0);
            base.BuildRenderTree(builder);
            builder.CloseRegion();

            bool renderHeader  = !String.IsNullOrEmpty(HeaderText) || (HeaderTemplate != null) || (HeaderIcon != null);
            bool renderContent = !String.IsNullOrEmpty(ContentText) || (ContentTemplate != null) || (ShowCloseButton && !renderHeader);

            builder.OpenElement(100, "div");
            builder.AddAttribute(101, "role", "alert");
            builder.AddAttribute(102, "aria-live", "assertive");
            builder.AddAttribute(103, "aria-atomic", "true");
            builder.AddAttribute(104, "class", CssClassHelper.Combine("toast", CssClass));

            if (AutohideDelay != null)
            {
                builder.AddAttribute(110, "data-bs-delay", AutohideDelay);
            }
            else
            {
                builder.AddAttribute(111, "data-bs-autohide", "false");
            }
            builder.AddElementReferenceCapture(120, referenceCapture => toastElement = referenceCapture);

            if (renderHeader)
            {
                builder.OpenElement(200, "div");
                builder.AddAttribute(201, "class", "toast-header");

                if (HeaderIcon != null)
                {
                    builder.OpenComponent(202, typeof(HxIcon));
                    builder.AddAttribute(203, nameof(HxIcon.Icon), HeaderIcon);
                    builder.AddAttribute(204, nameof(HxIcon.CssClass), "me-2");
                    builder.CloseComponent();
                }

                if (!String.IsNullOrWhiteSpace(HeaderText))
                {
                    builder.OpenElement(205, "strong");
                    builder.AddAttribute(206, "class", "me-auto");
                    builder.AddContent(207, HeaderText);
                    builder.CloseElement();                     // strong
                }
                builder.AddContent(208, HeaderTemplate);

                if (ShowCloseButton)
                {
                    builder.OpenRegion(209);
                    BuildRenderTree_CloseButton(builder, "ms-auto");
                    builder.CloseRegion();
                }
                builder.CloseElement();                 // toast-header
            }

            if (renderContent)
            {
                builder.OpenElement(300, "div");
                if (!renderHeader && ShowCloseButton)
                {
                    builder.AddAttribute(301, "class", "d-flex");
                }
                builder.OpenElement(302, "div");
                builder.AddAttribute(303, "class", "toast-body");
                builder.AddContent(304, ContentText);
                builder.AddContent(305, ContentTemplate);
                builder.CloseElement();                 // toast-body

                if (!renderHeader && ShowCloseButton)
                {
                    builder.OpenRegion(306);
                    builder.OpenElement(307, "div");
                    builder.AddAttribute(308, "class", "me-2 m-auto");
                    BuildRenderTree_CloseButton(builder, null);
                    builder.CloseElement();
                    builder.CloseRegion();
                }

                builder.CloseElement();
            }

            builder.CloseElement();             // toast
        }
예제 #25
0
        public void Cmd_Render <T>(T _Item, int k, RenderTreeBuilder builder, int Par_ID = 0)
        {
            Action <MouseEventArgs> act1 = new Action <MouseEventArgs>((s) =>
            {
                Cmd_Clicked(s);
            });


            bool   CaptureRef = false;
            string _value_id  = string.Empty;

            if (_Item.GetType().GetProperties().Any(x => x.Name == "CaptureRef"))
            {
                PropertyInfo pi_captureref = _Item.GetType().GetProperty("CaptureRef");
                if ((bool)pi_captureref.GetValue(_Item, null))
                {
                    if (_Item.GetType().GetProperties().Any(x => x.Name == "id"))
                    {
                        PropertyInfo pi_id = _Item.GetType().GetProperty("id");
                        _value_id = pi_id.GetValue(_Item, null).ToString();

                        CaptureRef = _value_id != null && !string.IsNullOrEmpty(_value_id.ToString());
                    }
                }
            }



            object _value;
            string _attrName = string.Empty;

            bool IsAllowed = true;


            builder.OpenElement(k++, _Item.GetType().Name);



            foreach (PropertyInfo pi in _Item.GetType().GetProperties().Where(x => !x.PropertyType.Name.Contains("ICollection") && !x.PropertyType.Name.Contains("CaptureRef")))
            {
                //list can't filter captureref??????
                if (pi.Name != "CaptureRef")
                {
                    IsAllowed = true;

                    _value = pi.GetValue(_Item, null);

                    if (pi.PropertyType == typeof(double))
                    {
                        if (double.IsNaN((double)_value))
                        {
                            IsAllowed = false;
                        }
                        else
                        {
                            _value = Math.Round((double)_value, 2);
                        }
                    }

                    if (IsAllowed)
                    {
                        IsAllowed = _value != null && !string.IsNullOrEmpty(_value.ToString());
                    }


                    if (IsAllowed)
                    {
                        if (pi.Name == "stroke_linecap")
                        {
                            IsAllowed = (strokeLinecap)_value != strokeLinecap.none;
                        }
                    }


                    if (IsAllowed)
                    {
                        _attrName = pi.Name;

                        if (_attrName.Equals("onclick"))
                        {
                            if (Par_ID == 0)
                            {
                                builder.AddAttribute(k++, _attrName, act1);
                            }
                            else
                            {
                                // builder.AddAttribute(k++, _attrName, e => ActionSelected?.Invoke(Par_ID));
                            }
                        }
                        else
                        {
                            if (_attrName.Equals("content"))
                            {
                                builder.AddContent(k++, _value.ToString());
                            }
                            else
                            {
                                if (_attrName.Contains("_"))
                                {
                                    _attrName = _attrName.Replace("_", "-");
                                }

                                builder.AddAttribute(k++, _attrName, _value.ToString());
                            }
                        }
                    }
                }
            }


            PropertyInfo pi_Children = _Item.GetType().GetProperty("Children");

            if (pi_Children != null)
            {
                List <object> children = pi_Children.GetValue(_Item) as List <object>;

                foreach (object item in children)
                {
                    Cmd_Render(item, k, builder, Par_ID);
                }
            }



            if (CaptureRef)
            {
                builder.AddElementReferenceCapture(k++, (elementReference) =>
                {
                    Elementreferences_Dictionary.Add(_value_id, elementReference);
                });
            }

            builder.CloseElement();
        }
예제 #26
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (builder != null)
            {
                base.BuildRenderTree(builder);

                string container = "input";
                int    i         = 0;

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    container = "groupWrapper";
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", GroupWrapperClass);
                    builder.AddAttribute(i++, "style", Style);
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-wrapper {PrefixCls}-group");
                }

                if (AddOnBefore != null)
                {
                    // addOnBefore
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(i++, AddOnBefore);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", AffixWrapperClass);
                    if (container == "input")
                    {
                        container = "affixWrapper";
                        builder.AddAttribute(i++, "style", Style);
                    }
                }

                if (Prefix != null)
                {
                    // prefix
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-prefix");
                    builder.AddContent(i++, Prefix);
                    builder.CloseElement();
                }

                // input
                builder.OpenElement(i++, "input");
                builder.AddAttribute(i++, "class", ClassMapper.Class);
                if (container == "input")
                {
                    builder.AddAttribute(i++, "style", Style);
                }

                if (Attributes != null)
                {
                    builder.AddMultipleAttributes(i++, Attributes);
                }

                if (AdditionalAttributes != null)
                {
                    builder.AddMultipleAttributes(i++, AdditionalAttributes);
                }

                builder.AddAttribute(i++, "Id", Id);
                if (Type != "number")
                {
                    builder.AddAttribute(i++, "type", Type);
                }

                builder.AddAttribute(i++, "placeholder", Placeholder);
                builder.AddAttribute(i++, "value", CurrentValueAsString);
                builder.AddAttribute(i++, "onchange", CallbackFactory.Create(this, OnChangeAsync));
                builder.AddAttribute(i++, "onkeypress", CallbackFactory.Create(this, OnPressEnterAsync));
                builder.AddAttribute(i++, "oninput", CallbackFactory.Create(this, OnInputAsync));
                builder.AddAttribute(i++, "onblur", CallbackFactory.Create(this, OnBlurAsync));
                builder.AddAttribute(i++, "onfocus", CallbackFactory.Create(this, OnFocus));
                builder.AddAttribute(i++, "onkeyup", CallbackFactory.Create(this, OnKeyUp));
                builder.AddElementReferenceCapture(i++, r => Ref = r);
                builder.CloseElement();

                if (Suffix != null)
                {
                    // suffix
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-suffix");
                    builder.AddContent(i++, Suffix);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.CloseElement();
                }

                if (AddOnAfter != null)
                {
                    // addOnAfter
                    builder.OpenElement(i++, "span");
                    builder.AddAttribute(i++, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(i++, AddOnAfter);
                    builder.CloseElement();
                }

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    builder.CloseElement();
                    builder.CloseElement();
                }
            }
        }
        public static RenderTreeBuilder ElementReferenceCapture(this RenderTreeBuilder builder, Action <ElementReference> action, [CallerLineNumber] int line = 0)
        {
            builder.AddElementReferenceCapture(GetSequence(line), action);

            return(builder);
        }
예제 #28
0
        public void RenderSvgTree <T>(T item, int k, RenderTreeBuilder builder)
        {
            //Console.WriteLine($"Open Region {k}");
            builder.OpenRegion(k++);

            bool   CaptureRef = false;
            string _value_id  = string.Empty;

            string _classID = string.Empty;

            if (item !.GetType().GetProperties().Any(x => x.Name == "CaptureRef"))
            {
                PropertyInfo pi_captureref = item.GetType().GetProperty("CaptureRef");
                if ((bool)pi_captureref.GetValue(item, null))
                {
                    if (item.GetType().GetProperties().Any(x => x.Name == "ID"))
                    {
                        PropertyInfo pi_id = item.GetType().GetProperty("ID");
                        _value_id = pi_id.GetValue(item, null).ToString();

                        CaptureRef = _value_id != null && !string.IsNullOrEmpty(_value_id.ToString());
                    }
                    if (item.GetType().GetProperties().Any(x => x.Name == "CssClass"))
                    {
                        PropertyInfo pi_id = item.GetType().GetProperty("CssClass");
                        _classID = pi_id.GetValue(item, null).ToString();
                    }
                }
            }



            object _value;
            string _attrName = string.Empty;

            bool IsAllowed = true;

            string tempName = FirstAndLastCharacterToLower(item.GetType().Name);

            //Console.WriteLine($"OpenElement {k}, {tempName}");
            builder.OpenElement(k++, tempName);



            CustomBasicList <PropertyInfo> properties = item.GetType().GetProperties().Where(x => !x.PropertyType.Name.Contains("CustomBasicList") && x.Name != "Content" && !x.PropertyType.Name.Contains("CaptureRef")).ToCustomBasicList();

            PropertyInfo property = item.GetType().GetProperties().Where(x => x.Name == "Content").SingleOrDefault();

            if (property != null)
            {
                properties.Add(property);
            }


            foreach (PropertyInfo pi in properties)
            {
                //list can't filter captureref??????
                if (pi.Name != "CaptureRef")
                {
                    IsAllowed = true;

                    _value = pi.GetValue(item, null);

                    if (pi.PropertyType == typeof(double))
                    {
                        if (double.IsNaN((double)_value))
                        {
                            IsAllowed = false;
                        }
                        else
                        {
                            _value = Math.Round((double)_value, 2);
                        }
                    }

                    //future:
                    //since only text obviously allows 0, then instead of setting the property, it will check to see if its text
                    //if text, then allow
                    //if not text, but shows 0, then not allowed.


                    if (IsAllowed)
                    {
                        IsAllowed = _value != null && !string.IsNullOrEmpty(_value.ToString());
                        if (IsAllowed && _value !.ToString() == "0" && Allow0 == false)
                        {
                            IsAllowed = false;
                        }
                        if (_value !.ToString() == "0" && Allow0 && item is Text == false)
                        {
                            IsAllowed = false; //try a different way.
                        }
                        //if (_value!.ToString() == "0" && Allow0 == true && item is Image)
                        //{
                        //    IsAllowed = false; //try this way.
                        //}
                        //if (_value!.ToString() == "0" && Allow0 == true && item is Path)
                        //{
                        //    IsAllowed = false;
                        //}
                        //if (Allow0 && _value!.ToString() == "0")
                        //{
                        //    IsAllowed = false; //for now
                        //}
                    }



                    if (IsAllowed)
                    {
                        _attrName = pi.Name;
                        if (_value is CustomEventClass custom)
                        {
                            if (custom.ActionClicked != null)
                            {
                                //if you don't have delegate set up, then ignore.
                                builder.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, e => ActionClicked(custom)));
                            }
                            if (custom.StopPropagation)
                            {
                                builder.AddEventStopPropagationAttribute(2, "onclick", true);
                            }
                        }
                        else
                        {
                            if (_attrName.Equals("Content"))
                            {
                                //Console.WriteLine($"Adding Content 3, {_value!.ToString()}");
                                builder.AddContent(3, _value !.ToString());
                            }
                            else if (_attrName.Equals("CssClass"))
                            {
                                builder.AddAttribute(4, "class", _value !.ToString());
                            }
                            else
                            {
                                if (_attrName.Contains("_"))
                                {
                                    _attrName = _attrName.Replace("_", "-");
                                }

                                _attrName = FirstAndLastCharacterToLower(_attrName);

                                //Console.WriteLine($"4, { _attrName}, {_value!.ToString()}");
                                builder.AddAttribute(4, _attrName, _value !.ToString());
                            }
                        }
                    }
                }
            }


            PropertyInfo pi_Children = item.GetType().GetProperty("Children");

            if (pi_Children != null)
            {
                CustomBasicList <object>?children = pi_Children.GetValue(item) as CustomBasicList <object>;

                foreach (object others in children !)
                {
                    RenderSvgTree(others, k++, builder);;
                }
            }



            if (CaptureRef)
            {
                //Console.WriteLine("Builder Add Element Reference Capture 5");
                builder.AddElementReferenceCapture(5, (elementReference) =>
                {
                    ElementReferences.Add(_value_id !, elementReference);
                });
예제 #29
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            this.Sequence = 0;
            builder.OpenElement(this.Sequence++, "svg");
            builder.AddAttribute(this.Sequence++, "class", "canvas");

            builder.AddAttribute(this.Sequence++, "onmousedown", EventCallback.Factory.Create(this, (e) =>
            {
                // broken event propag
                if (this.State.ComponentClicked)
                {
                    this.State.ComponentClicked = false;
                    return;
                }


                //this.State.Selector = new RectCard();
                //var pos = new Vector2f((float)e.ClientX, (float)e.ClientY);
                //pos.ToLocalFromClient(this.JSRuntime, this.CanvasReference).ContinueWith(t =>
                //{
                //    this.State.Selector.PositionBehavior.Position = pos;
                //});

                //this.State.Selector.SizeBehavior.Size = Vector2f.Zero;

                Console.WriteLine("canvas down...");
            }));

            builder.AddAttribute(this.Sequence++, "onmousemove", EventCallback.Factory.Create <MouseEventArgs>(this, async(e) =>
            {
                this.State.Mouse.OnMove(new Vector2f((int)e.ClientX, (int)e.ClientY));
            }));

            builder.AddAttribute(this.Sequence++, "onmouseup", EventCallback.Factory.Create <MouseEventArgs>(this, async(e) =>
            {
                this.State.Mouse.OnUp(new Vector2f((int)e.ClientX, (int)e.ClientY));
                this.State.Selected = null;
                this.State.Selector = null;
            }));



            builder.OpenElement(this.Sequence++, "g");
            builder.AddAttribute(this.Sequence++, "class", "canvas-zoom");

            builder.OpenElement(this.Sequence++, "g");
            builder.AddAttribute(this.Sequence++, "class", "canvas-graphics");

            foreach (var card in this.Cards)
            {
                //card.Render().Invoke(builder);
                builder.OpenComponent(this.Sequence++, card.GetComponentType());
                builder.AddAttribute(this.Sequence++, "Canvas", this);
                builder.AddAttribute(this.Sequence++, "Descriptor", card);
                builder.CloseComponent();
            }



            if (this.State.Selector != null)
            {
                builder.OpenComponent(this.Sequence++, this.State.Selector.GetComponentType());
                builder.AddAttribute(this.Sequence++, "Canvas", this);
                builder.AddAttribute(this.Sequence++, "Descriptor", this.State.Selector);
                builder.CloseComponent();
            }
            else
            {
                this.Sequence += 3;
            }


            builder.AddElementReferenceCapture(this.Sequence++, (eref) =>
            {
                this.CanvasReference = eref;
            });

            builder.CloseElement();
            builder.CloseElement();

            builder.CloseElement();
        }
        protected virtual void BuildElementRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, Tag);

            //foreach (var attribute in Attributes)
            //{
            //    builder.AddAttribute(1, attribute.Key, attribute.Value);
            //}

            builder.AddMultipleAttributes(1, Attributes);

            var _class = _Class;
            var _style = _Style;

            if (!string.IsNullOrWhiteSpace(Id))
            {
                builder.AddAttribute(2, "id", Id);
            }

            if (!string.IsNullOrWhiteSpace(_class))
            {
                builder.AddAttribute(3, "class", _class);
            }

            if (!string.IsNullOrWhiteSpace(_style))
            {
                builder.AddAttribute(4, "style", _style);
            }

            if (TabIndex.HasValue)
            {
                builder.AddAttribute(5, "tabindex", Disabled.HasValue && Disabled.Value ? -1 : TabIndex);
            }

            if (OnFocus.HasDelegate)
            {
                builder.AddAttribute(6, "onfocus", EventCallback.Factory.Create <FocusEventArgs>(this, HandleFocusAsync));
            }

            if (OnBlur.HasDelegate)
            {
                builder.AddAttribute(7, "onblur", EventCallback.Factory.Create <FocusEventArgs>(this, HandleBlurAsync));
            }

            if (OnKeyDown.HasDelegate)
            {
                builder.AddAttribute(8, "onkeydown", EventCallback.Factory.Create <KeyboardEventArgs>(this, HandleKeyDownAsync));
            }

            if (OnKeyUp.HasDelegate)
            {
                builder.AddAttribute(9, "onkeyup", EventCallback.Factory.Create <KeyboardEventArgs>(this, HandleKeyUpAsync));
            }

            if (OnMouseDown.HasDelegate)
            {
                builder.AddAttribute(10, "onmousedown", EventCallback.Factory.Create <MouseEventArgs>(this, HandleMouseDownAsync));
            }

            if (OnMouseUp.HasDelegate)
            {
                builder.AddAttribute(11, "onmouseup", EventCallback.Factory.Create <MouseEventArgs>(this, HandleMouseUpAsync));
            }

            if (OnMouseEnter.HasDelegate)
            {
                builder.AddAttribute(12, "onmouseenter", EventCallback.Factory.Create <EventArgs>(this, HandleMouseEnterAsync));
            }

            if (OnMouseLeave.HasDelegate)
            {
                builder.AddAttribute(13, "onmouseleave", EventCallback.Factory.Create <EventArgs>(this, HandleMouseLeaveAsync));
            }

            if (OnMouseOver.HasDelegate)
            {
                builder.AddAttribute(14, "onmouseover", EventCallback.Factory.Create <MouseEventArgs>(this, HandleMouseOverAsync));
            }

            if (OnMouseOut.HasDelegate)
            {
                builder.AddAttribute(15, "onmouseout", EventCallback.Factory.Create <MouseEventArgs>(this, HandleMouseOutAsync));
            }

            if (OnMouseMove.HasDelegate)
            {
                builder.AddAttribute(16, "onmousemove", EventCallback.Factory.Create <MouseEventArgs>(this, HandleMouseMoveAsync));
            }

            if (OnTouchStart.HasDelegate)
            {
                builder.AddAttribute(17, "ontouchstart", EventCallback.Factory.Create <TouchEventArgs>(this, HandleTouchStartAsync));
            }

            if (OnTouchMove.HasDelegate)
            {
                builder.AddAttribute(18, "ontouchmove", EventCallback.Factory.Create <TouchEventArgs>(this, HandleTouchMoveAsync));
            }

            if (OnTouchEnd.HasDelegate)
            {
                builder.AddAttribute(19, "ontouchend", EventCallback.Factory.Create <TouchEventArgs>(this, HandleTouchEndAsync));
            }

            if (OnClick.HasDelegate)
            {
                builder.AddAttribute(20, "onclick", EventCallback.Factory.Create <EventArgs>(this, HandleClickAsync));
            }

            if (OnDrag.HasDelegate)
            {
                builder.AddAttribute(21, "ondrag", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragAsync));
            }

            if (OnDrop.HasDelegate)
            {
                builder.AddAttribute(22, "ondrop", EventCallback.Factory.Create <DragEventArgs>(this, HandleDropAsync));
            }

            if (OnDragStart.HasDelegate)
            {
                builder.AddAttribute(23, "ondragstart", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragStartAsync));
            }

            if (OnDragEnd.HasDelegate)
            {
                builder.AddAttribute(24, "ondragend", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragEndAsync));
            }

            if (OnDragEnter.HasDelegate)
            {
                builder.AddAttribute(25, "ondragenter", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragEnterAsync));
            }

            if (OnDragExit.HasDelegate)
            {
                builder.AddAttribute(26, "ondragexit", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragExitAsync));
            }

            if (OnDragOver.HasDelegate)
            {
                builder.AddAttribute(27, "ondragover", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragOverAsync));
            }

            if (OnDragLeave.HasDelegate)
            {
                builder.AddAttribute(28, "ondragleave", EventCallback.Factory.Create <DragEventArgs>(this, HandleDragLeaveAsync));
            }

            if (!string.IsNullOrWhiteSpace(Role))
            {
                builder.AddAttribute(29, "role", Role);
            }

            if (Disabled.HasValue)
            {
                builder.AddAttribute(30, "disabled", Disabled.Value);
            }

            if (OnClickStop.HasValue)
            {
                builder.AddEventStopPropagationAttribute(31, "onclick", OnClickStop.Value);
            }

            if (OnClickPrevent.HasValue)
            {
                builder.AddEventPreventDefaultAttribute(32, "onclick", OnClickPrevent.Value);
            }

            if (OnKeyUpStop.HasValue)
            {
                builder.AddEventStopPropagationAttribute(33, "onkeyup", OnKeyUpStop.Value);
            }

            if (OnKeyUpPrevent.HasValue)
            {
                builder.AddEventPreventDefaultAttribute(34, "onkeyup", OnKeyUpPrevent.Value);
            }

            if (ChildContent != null)
            {
                builder.AddContent(35, ChildContent(Context));
            }

            builder.AddElementReferenceCapture(36, (__value) => {
                RootRef.Current = (ElementReference)__value;
            });

            builder.CloseElement();
        }