Пример #1
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (baseModule == null)
            {
                baseModule = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", BasePath);
            }
            if (firstRender)
            {
                Rectangle?windowRect = await baseModule !.InvokeAsync <Rectangle>("getWindowRect");
                foreach (object?item in Enum.GetValues(typeof(ResponsiveMode)))
                {
                    if (windowRect.Width <= ResponsiveModeUtils.RESPONSIVE_MAX_CONSTRAINT[(int)item])
                    {
                        CurrentMode = (ResponsiveMode)item;
                        break;
                    }
                }
                _resizeEventGuid = Guid.NewGuid().ToString().Replace("-", "");
                selfReference    = DotNetObjectReference.Create(this);
                await baseModule.InvokeVoidAsync("registerResizeEvent", selfReference, "OnResizedAsync", _resizeEventGuid);

                StateHasChanged();  // we will never have window size until after first render, so re-render after this to update the component with ResponsiveMode info.
            }
            await base.OnAfterRenderAsync(firstRender);
        }
        protected virtual async Task OnMouseDownAsync(ElementReference sender, MouseEventArgs e, IGraphElement?element)
        {
            if (element == null || element is not INodeViewModel)
            {
                return;
            }
            if (element is StartNodeViewModel || element is EndNodeViewModel)
            {
                return;
            }
            if (this._nodeGhostModule == null)
            {
                this._nodeGhostModule = await _jSRuntime.InvokeAsync <IJSInProcessObjectReference>("import", "./js/node-ghost.js");
            }
            if (this._nodeGhostModule == null)
            {
                throw new NullReferenceException("Unable to load JS module './js/node-ghost.js'");
            }
            this._nodeGhost = await this._nodeGhostModule.InvokeAsync <IJSObjectReference>("createNodeGhost", sender);

            if (this._nodeGhost == null)
            {
                throw new NullReferenceException("Unable to create new ghost node");
            }
            this._source    = element as INodeViewModel;
            this._previousX = e.ClientX;
            this._previousY = e.ClientY;
        }
Пример #3
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            baseModule = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", BasePath);

            if (firstRender)
            {
                isFirstRendered = true;
                if (!addedToHost)
                {
                    if (HostId == null)
                    {
                        LayerHost = LayerHostService.GetDefaultHost();
                    }
                    else
                    {
                        LayerHost = LayerHostService.GetHost(HostId);
                    }

                    if (LayerHost != null)
                    {
                        LayerHost.AddOrUpdateHostedContentAsync(id, ChildContent);
                        addedToHost = true;
                        StateHasChanged();
                    }
                }

                await baseModule !.InvokeVoidAsync("addOrUpdateVirtualParent", _element);
            }
            await base.OnAfterRenderAsync(firstRender);
        }
Пример #4
0
 protected override async Task OnAfterRenderAsync(bool firstRender)
 {
     baseModule = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", BasePath);
     if (firstRender)
     {
         await baseModule !.InvokeVoidAsync("disableBodyScroll");
     }
 }
Пример #5
0
 /// <inheritdoc />
 protected override async Task OnAfterRenderAsync(bool firstRender)
 {
     scriptModule = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", scriptPath);
     if (firstRender)
     {
         _selfReference = DotNetObjectReference.Create(this);
         _listId        = await scriptModule.InvokeAsync <int>("initialize", _selfReference, _spacerBefore, _spacerAfter);
     }
 }
Пример #6
0
 protected override async Task OnAfterRenderAsync(bool firstRender)
 {
     baseModule = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", BasePath);
     if (firstRender)
     {
         _handleToLastFocusedElement = await baseModule !.InvokeAsync <string>("storeLastFocusedElement");
     }
     await base.OnAfterRenderAsync(firstRender);
 }
Пример #7
0
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            _glider = await JSRuntime.InvokeAsync <IJSObjectReference>("import", "https://unpkg.com/@glidejs/[email protected]/dist/glide.min.js").AsTask();
        }
        await JSRuntime.InvokeVoidAsync($"createGlideInstance");

        await base.OnAfterRenderAsync(firstRender);
    }
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                module = await jsRuntime.InvokeAsync <IJSObjectReference>("import", "./_content/MathJaxBlazor/mathJaxBlazor.js");
            }
            await module.InvokeVoidAsync("typesetPromise");

            await base.OnAfterRenderAsync(firstRender);
        }
Пример #9
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            baseModule = await JSRuntime.InvokeAsync <IJSObjectReference>("import", BasePath);

            if (!ScopedStatics.FocusRectsInitialized)
            {
                ScopedStatics.FocusRectsInitialized = true;
                await baseModule !.InvokeVoidAsync("initializeFocusRects");
            }
            await base.OnAfterRenderAsync(firstRender);
        }
Пример #10
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                module = await jsRuntime.InvokeAsync <IJSObjectReference>("import", "./_content/MathJaxBlazor/mathJaxBlazor.js");
                await ApplySettingsAsync();

                hasRendered = true;
            }
            await base.OnAfterRenderAsync(firstRender);
        }
Пример #11
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            module = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", FocusPath);

            if (firstRender)
            {
                RegisterFocusTrapZone();
            }

            await base.OnAfterRenderAsync(firstRender);
        }
Пример #12
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            baseModule = await JSRuntime !.InvokeAsync <IJSObjectReference>("import", BasePath);
            if (firstRender)
            {
                // 27 is Escape code
                selfReference        = DotNetObjectReference.Create(this);
                _keydownRegistration = await baseModule.InvokeAsync <string>("registerWindowKeyDownEvent", selfReference, "27", "ProcessKeyDown");
            }

            await base.OnAfterRenderAsync(firstRender);
        }
    public static async Task <bool> GetLocalStorageThemeAsync(this IJSObjectReference?jsObjRef)
    {
        string value = await jsObjRef.GetLocalStorageAsync(ThemeKey);

        if (string.IsNullOrEmpty(value))
        {
            bool IsDarkTheme = await jsObjRef.IsMediaDarkThemeAsync();

            await jsObjRef.SetLocalStorageThemeAsync(IsDarkTheme).ConfigureAwait(false);

            return(IsDarkTheme);
        }

        return(value.Equals(DarkThemeValue));
    }
Пример #14
0
 /// <summary>
 /// Dispose 方法
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual async ValueTask DisposeAsyncCore(bool disposing)
 {
     if (disposing)
     {
         if (Module != null)
         {
             // TODO: 微软的代码这里加上 await 就会线程死锁
             try
             {
                 await Module.DisposeAsync().AsTask();
             }
             catch { }
             Module = null;
         }
     }
 }
Пример #15
0
 public async Task <Rectangle> GetBoundsAsync(ElementReference elementReference)
 {
     try
     {
         if (baseModule == null)
         {
             baseModule = await JSRuntime.InvokeAsync <IJSObjectReference>("import", BasePath);
         }
         Rectangle?rectangle = await baseModule !.InvokeAsync <Rectangle>("measureElementRect", elementReference);
         return(rectangle);
     }
     catch (JSException)
     {
         return(new Rectangle());
     }
 }
        protected virtual async Task OnMouseUpAsync(ElementReference sender, MouseEventArgs e, IGraphElement?element)
        {
            if (this._nodeGhost == null)
            {
                return;
            }
            await this.UpdatedPosition();

            await this._nodeGhost.InvokeVoidAsync("dispose");

            this._nodeGhost = null;
            this._source    = null;
            if (this._destination != null)
            {
                this._destination.CssClass = (this._destination.CssClass ?? "").Replace(" drop-destination", "");
                this._destination          = null;
            }
        }
Пример #17
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            baseModule = await JSRuntime.InvokeAsync<IJSObjectReference>("import", BasePath);

            if (firstRender)
            {
                await OnRowDidMount.InvokeAsync(this);
            }

            if (columnMeasureInfo != null && columnMeasureInfo.Index >= 0 && cellMeasurer.Id != null)
            {
                Action<double>? method = columnMeasureInfo.OnMeasureDone;
                Rectangle? size = await baseModule.InvokeAsync<Rectangle>("measureElementRect", cellMeasurer);
                method?.Invoke(size.Width);
                columnMeasureInfo = null;
                await InvokeAsync(StateHasChanged);
            }

            await base.OnAfterRenderAsync(firstRender);
        }
Пример #18
0
        private async ValueTask <ScriptInvoker <T>?> EnsureScriptEnabledAsync <T>()
        {
            if (!this.ScriptLoaded)
            {
                await this.Syncer.WaitAsync();

                try
                {
                    if (!this.ScriptLoaded)
                    {
                        var version    = this.GetVersionText();
                        var scriptPath = "./_content/" + Namespace + "/script.module.min.js?v=" + version;
                        this.JSModule = await this.JSRuntime.InvokeAsync <IJSObjectReference>("import", scriptPath);

                        this.ScriptLoaded = true;
                    }
                }
                catch { }
                finally { this.Syncer.Release(); }
            }

            return(this.JSModule == null ? default(ScriptInvoker <T>) : this.JSModule.InvokeAsync <T>);
        }
Пример #19
0
        private async ValueTask <ScriptInvoker <T>?> EnsureScriptEnabledAsync <T>()
        {
            if (!this.ScriptLoaded)
            {
                await this.Syncer.WaitAsync();

                try
                {
                    if (!this.ScriptLoaded)
                    {
                        var scriptPath = "./_content/" + Namespace + "/script.module.min.js";//?v=" + version;

                        // Add version string for refresh token only navigator is online.
                        // (If the app runs on the offline mode, the module url with query parameters might cause the "resource not found" error.)
                        const string moduleScript = "export function isOnLine(){ return navigator.onLine; }";
                        await using var inlineJsModule = await this.JSRuntime.InvokeAsync <IJSObjectReference>("import", "data:text/javascript;charset=utf-8," + Uri.EscapeDataString(moduleScript));

                        var isOnLine = await inlineJsModule.InvokeAsync <bool>("isOnLine");

                        this._IsOnline = isOnLine;

                        if (isOnLine)
                        {
                            scriptPath += $"?v={this.GetVersionText()}";
                        }

                        this.JSModule = await this.JSRuntime.InvokeAsync <IJSObjectReference>("import", scriptPath);

                        this.ScriptLoaded = true;
                    }
                }
                catch { }
                finally { this.Syncer.Release(); }
            }

            return(this.JSModule == null ? default(ScriptInvoker <T>) : this.JSModule.InvokeAsync <T>);
        }
Пример #20
0
 public JSInvoker(IJSRuntime jSRuntime, IJSObjectReference?jsModule)
 {
     this.JSRuntime = jSRuntime;
     this.JSModule  = jsModule;
 }
 public static async Task <bool> IsMediaDarkThemeAsync(this IJSObjectReference?jsObjRef)
 => await jsObjRef !.InvokeAsync <bool>(JSIsDarkTheme, null).ConfigureAwait(false);
 public static async Task CreateMediaThemeListenerAsync(this IJSObjectReference?jsObjRef, DotNetObjectReference <ThemeService> DotNetInstance)
 => await jsObjRef !.InvokeVoidAsync(JSCreateThemeListener, DotNetInstance).ConfigureAwait(false);
 public static async Task <string> GetLocalStorageAsync(this IJSObjectReference?jsObjRef, string key)
 => await jsObjRef !.InvokeAsync <string>(JSGetLocalStorage, key).ConfigureAwait(false);
 public static async Task SetLocalStorageAsync(this IJSObjectReference?jsObjRef, string key, string value)
 => await jsObjRef !.InvokeVoidAsync(JSSetLocalStorage, key, value).ConfigureAwait(false);
 public static async Task SetLocalStorageThemeAsync(this IJSObjectReference?jsObjRef, bool IsDarkTheme)
 => await jsObjRef !.SetLocalStorageAsync(ThemeKey, IsDarkTheme ? DarkThemeValue : LightThemeValue).ConfigureAwait(false);
Пример #26
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="jSObjectReference"></param>
 public JSModule(IJSObjectReference?jSObjectReference)
 {
     Module = jSObjectReference ?? throw new ArgumentNullException(nameof(jSObjectReference));
 }
Пример #27
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                // Resolve (import) required javascript
                // Note: We want to use synchronous js calls whenever possible (for performance)
                if (JSRuntime is IJSInProcessRuntime)
                {
                    _jsInProcessReference = await JSRuntime.InvokeAsync <IJSInProcessObjectReference>("import", ModulePath);

                    _jsReference = _jsInProcessReference;
                }
                else
                {
                    _jsReference = await JSRuntime.InvokeAsync <IJSObjectReference>("import", ModulePath);
                }

                // Trigger re-render after javascript was resolved
                StateHasChanged();
                return;
            }

            // Ensure that reference was resolved (important!)
            // Lifecycle method could be called twice very fast:
            // If that's the case the second call (is not "firstRender") would
            // try to call a function on the js-object which is not yet resolved
            if (_jsReference == null)
            {
                return;
            }

            // When a target element was supplied we want to use it
            if (Target != null &&
                Target.HasValue)
            {
                _target = Target.Current;
            }

            // Check whether the target element exists in DOM
            if (_target.Id == null)
            {
                return;
            }

            if (_isActive)
            {
                // Check if we need to show the content
                if (_state == TransitionState.Leaving ||
                    _state == TransitionState.Left)
                {
                    _state = TransitionState.Entering; // Set correct state before registering js callback

                    // When possible use the synchronous js call
                    if (_jsInProcessReference != null)
                    {
                        RegisterCallback();
                    }
                    else
                    {
                        await RegisterCallbackAsync();
                    }

                    await StateChanged.InvokeAsync(_state);
                }

                return;
            }

            // Check if we need to hide the content
            if (_state == TransitionState.Entering ||
                _state == TransitionState.Entered)
            {
                _state = TransitionState.Leaving; // Set correct state before registering js callback

                // When possible use the synchronous js call
                if (_jsInProcessReference != null)
                {
                    RegisterCallback();
                }
                else
                {
                    await RegisterCallbackAsync();
                }

                await StateChanged.InvokeAsync(_state);
            }
        }