-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDriverJs.razor.cs
More file actions
240 lines (207 loc) · 6.77 KB
/
DriverJs.razor.cs
File metadata and controls
240 lines (207 loc) · 6.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// 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/
namespace BootstrapBlazor.Components;
/// <summary>
/// FocusGuide 组件
/// </summary>
public partial class DriverJs
{
/// <summary>
/// 获得/设置 是否自动开始向导 默认 true
/// </summary>
[Parameter]
[Obsolete("已弃用,删除即可;Deprecated, just delete it")]
[ExcludeFromCodeCoverage]
public bool AutoDrive { get; set; } = true;
/// <summary>
/// 获得/设置 组件配置 <see cref="DriverJsConfig"/> 实例 默认 null
/// </summary>
[Parameter]
public DriverJsConfig? Config { get; set; }
/// <summary>
/// 获得/设置 子组件内容
/// </summary>
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Inject, NotNull]
private IStringLocalizer<DriverJs>? Localizer { get; set; }
private readonly List<DriverJsStep> _steps = [];
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop);
/// <summary>
/// 开始方法
/// </summary>
/// <returns></returns>
public async Task Start(int? index = 0)
{
Config ??= new();
Config.Steps = _steps;
Config.ProgressText ??= Localizer[nameof(Config.ProgressText)];
Config.PrevBtnText ??= Localizer[nameof(Config.PrevBtnText)];
Config.NextBtnText ??= Localizer[nameof(Config.NextBtnText)];
Config.DoneBtnText ??= Localizer[nameof(Config.DoneBtnText)];
await InvokeVoidAsync("start", Id, Config, new
{
Index = index
});
}
/// <summary>
/// 组件销毁前回调方法由 JavaScript 调用 返回 非空字符串时客户端 confirm 确认弹窗
/// </summary>
[JSInvokable]
public async Task<string?> OnBeforeDestroy(int index)
{
string? ret = null;
if (Config is { OnDestroyStartedAsync: not null })
{
ret = await Config.OnDestroyStartedAsync(Config, index);
}
return ret;
}
/// <summary>
/// 组件销毁后回调方法由 JavaScript 调用
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task OnDestroyed()
{
if (Config is { OnDestroyedAsync: not null })
{
await Config.OnDestroyedAsync();
}
}
/// <summary>
/// 点击组件这招回调方法由 JavaScript 调用
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task OnOverlayClicked(int index)
{
if (Config is { OnOverlayClickedAsync: not null })
{
await Config.OnOverlayClickedAsync(this, Config, index);
}
}
/// <summary>
/// Starts at step 0
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public Task Drive(int? index) => InvokeVoidAsync("drive", Id, index);
/// <summary>
/// Move to the next step
/// </summary>
/// <returns></returns>
public Task MoveNext() => InvokeVoidAsync("moveNext", Id);
/// <summary>
/// Move to the previous step
/// </summary>
/// <returns></returns>
public Task MovePrevious() => InvokeVoidAsync("movePrevious", Id);
/// <summary>
/// Move to the step
/// </summary>
/// <returns></returns>
public Task MoveTo(int index) => InvokeVoidAsync("moveTo", Id, index);
/// <summary>
/// Is there a next step
/// </summary>
/// <returns></returns>
public Task<bool> HasNextStep() => InvokeAsync<bool>("hasNextStep", Id);
/// <summary>
/// Is there a previous step
/// </summary>
/// <returns></returns>
public Task<bool> HasPreviousStep() => InvokeAsync<bool>("hasPreviousStep", Id);
/// <summary>
/// Is the current step the first step
/// </summary>
/// <returns></returns>
public Task<bool> IsFirstStep() => InvokeAsync<bool>("isFirstStep", Id);
/// <summary>
/// Is the current step the last step
/// </summary>
/// <returns></returns>
public Task<bool> IsLastStep() => InvokeAsync<bool>("isLastStep", Id);
/// <summary>
/// Gets the active step index
/// </summary>
/// <returns></returns>
public Task<int> GetActiveIndex() => InvokeAsync<int>("getActiveIndex", Id);
/// <summary>
/// Gets the active step index
/// </summary>
/// <returns></returns>
public Task Destroy() => InvokeVoidAsync("destroy", Id);
/// <summary>
/// Gets the active step configuration
/// </summary>
/// <returns></returns>
public async Task<DriverJsStep?> GetActiveStep()
{
DriverJsStep? step = null;
if (Config != null)
{
var index = await GetActiveIndex();
step = Config.Steps.ElementAtOrDefault(index + 1);
}
return step;
}
/// <summary>
/// Gets the previous step configuration
/// </summary>
/// <returns></returns>
public async Task<DriverJsStep?> GetPreviousStep()
{
DriverJsStep? step = null;
if (Config != null)
{
var index = await GetActiveIndex();
step = Config.Steps.ElementAtOrDefault(index - 1);
}
return step;
}
/// <summary>
/// Is the tour or highlight currently active
/// </summary>
/// <returns></returns>
public Task<bool> IsActive() => InvokeAsync<bool>("isActive", Id);
/// <summary>
/// Recalculate and redraw the highlight
/// </summary>
/// <returns></returns>
public Task Refresh() => InvokeVoidAsync("refresh", Id);
/// <summary>
/// Look at the DriveStep section of configuration for format of the step
/// </summary>
/// <param name="config"><see cref="DriverJsConfig"/> 实例</param>
/// <param name="selector">target selector</param>
/// <param name="popover"><see cref="DriverJsHighlightPopover"/> 实例</param>
/// <returns></returns>
public async Task Highlight(DriverJsConfig config, string? selector, DriverJsHighlightPopover popover)
{
config ??= new();
config.ProgressText ??= Localizer[nameof(Config.ProgressText)];
await InvokeVoidAsync("highlight", Id, config, new { element = selector, popover });
}
/// <summary>
/// 添加步骤方法
/// </summary>
/// <param name="step"></param>
public void AddStep(DriverJsStep step)
{
_steps.Add(step);
}
/// <summary>
/// 移除步骤方法
/// </summary>
/// <param name="step"></param>
public void RemoveStep(DriverJsStep step)
{
_steps.Remove(step);
}
}