-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(DriverJs): add OverlayClickBehavior support #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -67,7 +67,7 @@ public async Task Start(int? index = 0) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| string? ret = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Config?.OnDestroyStartedAsync != null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Config is { OnDestroyStartedAsync: not null }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ret = await Config.OnDestroyStartedAsync(Config, index); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -81,12 +81,25 @@ public async Task Start(int? index = 0) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| [JSInvokable] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task OnDestroyed() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Config?.OnDestroyedAsync != null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Config is { OnDestroyedAsync: not null }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await Config.OnDestroyedAsync(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
81
to
88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Consider handling exceptions in OnDestroyed to avoid unhandled errors. Because OnDestroyed is called from JavaScript, exceptions here may propagate unexpectedly. Use a try-catch around the await to handle errors and improve robustness.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// 点击组件这招回调方法由 JavaScript 调用 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// 点击组件这招回调方法由 JavaScript 调用 | |
| /// 点击组件遮罩回调方法由 JavaScript 调用 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider handling exceptions in OnOverlayClicked to avoid unhandled errors.
Because this method is called from JavaScript, unhandled exceptions may cause unpredictable behavior. Use a try-catch around the await call to handle errors and improve reliability.
| public async Task OnOverlayClicked(int index) | |
| { | |
| if (Config is { OnOverlayClickedAsync: not null }) | |
| { | |
| await Config.OnOverlayClickedAsync(this, Config, index); | |
| } | |
| } | |
| public async Task OnOverlayClicked(int index) | |
| { | |
| if (Config is { OnOverlayClickedAsync: not null }) | |
| { | |
| try | |
| { | |
| await Config.OnOverlayClickedAsync(this, Config, index); | |
| } | |
| catch (Exception ex) | |
| { | |
| // TODO: Replace with your logging mechanism if available | |
| Console.Error.WriteLine($"Error in OnOverlayClicked: {ex}"); | |
| } | |
| } | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| import { driver } from "../driver.js" | ||||||
| import { driver } from "../driver.js.mjs" | ||||||
| import { addLink } from '../../BootstrapBlazor/modules/utility.js' | ||||||
| import Data from "../../BootstrapBlazor/modules/data.js" | ||||||
|
|
||||||
|
|
@@ -18,7 +18,7 @@ export function start(id, options, config) { | |||||
| if (d) { | ||||||
| d.config = config; | ||||||
| const { index } = config; | ||||||
| const { hookDestroyStarted, hookDestroyed } = options; | ||||||
| const { hookDestroyStarted, hookDestroyed, overlayClickBehavior } = options; | ||||||
| if (hookDestroyStarted) { | ||||||
| delete options.hookDestroyStarted; | ||||||
| options.onDestroyStarted = async (el, step, { state }) => { | ||||||
|
|
@@ -34,6 +34,12 @@ export function start(id, options, config) { | |||||
| d.invoke.invokeMethodAsync("OnDestroyed"); | ||||||
| }; | ||||||
| } | ||||||
| if (overlayClickBehavior === "function") { | ||||||
| options.overlayClickBehavior = async (el, step, { state }) => { | ||||||
| await d.invoke.invokeMethodAsync("OnOverlayClicked", state.activeIndex) | ||||||
|
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: The overlayClickBehavior check for "function" is string-based; consider aligning with a more robust type or value check. Using a constant or enum for 'function' will help prevent typos and make future updates safer. Suggested implementation: const OVERLAY_CLICK_BEHAVIOR_FUNCTION = "function";
d.config = config;
const { index } = config;
const { hookDestroyStarted, hookDestroyed, overlayClickBehavior } = options; if (overlayClickBehavior === OVERLAY_CLICK_BEHAVIOR_FUNCTION) {
options.overlayClickBehavior = async (el, step, { state }) => {
await d.invoke.invokeMethodAsync("OnOverlayClicked", state.activeIndex)
};
}
|
||||||
| await d.invoke.invokeMethodAsync("OnOverlayClicked", state.activeIndex) | |
| await d.invoke.invokeMethodAsync("OnOverlayClicked", state.activeIndex); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||||||
| // Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. | ||||||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||||||
|
|
||||||
|
|
@@ -142,4 +142,19 @@ public class DriverJsConfig | |||||
| /// </summary> | ||||||
| [JsonIgnore] | ||||||
| public Func<Task>? OnDestroyedAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 点击遮罩行为 close nextStep function 默认 close | ||||||
| /// </summary> | ||||||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||||||
| public string? OverlayClickBehavior { get; set; } | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: OverlayClickBehavior is a string; consider using an enum for clarity and type safety. Strings are prone to errors and complicate future changes; enums improve safety and code clarity. Suggested implementation: /// <summary>
/// 获得/设置 点击遮罩行为,默认 Close。可选值: Close, NextStep, Function
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public OverlayClickBehaviorType? OverlayClickBehavior { get; set; }
/// <summary>
/// 点击遮罩行为枚举
/// </summary>
public enum OverlayClickBehaviorType
{
Close,
NextStep,
Function
}If this property is serialized/deserialized elsewhere, you may need to update those usages to handle the enum type instead of string. If you use this property in other files, update their references to use the enum values (e.g., |
||||||
|
|
||||||
| [JsonInclude] | ||||||
| private string OverlayClickCallbackMethod => nameof(OnOverlayClickedAsync); | ||||||
|
Comment on lines
+152
to
+153
|
||||||
| [JsonInclude] | |
| private string OverlayClickCallbackMethod => nameof(OnOverlayClickedAsync); |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comment "获得/设置 组件销毁前回调方法名称" (Gets/sets the method name before component destruction) is incorrect. This property is for overlay click callback, not destruction callback. The comment should describe that this is the callback method for handling overlay click events.
| /// 获得/设置 组件销毁前回调方法名称 | |
| /// 获得/设置 点击遮罩时的回调方法 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
RootNamespaceproperty was removed in this change. All other components in the repository (e.g., BootstrapBlazor.Chart, BootstrapBlazor.Authenticator, BootstrapBlazor.BaiduOcr) maintain<RootNamespace>BootstrapBlazor.Components</RootNamespace>in their project files. Unless this removal is intentional, the property should be retained for consistency across the codebase.