Skip to content

Commit 81bc19e

Browse files
Added members from EventInProcess to ProgressEventInProces.
1 parent f92b946 commit 81bc19e

1 file changed

Lines changed: 106 additions & 3 deletions

File tree

src/KristofferStrube.Blazor.FileAPI/ProgressEvent.InProcess.cs

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using KristofferStrube.Blazor.WebIDL;
1+
using KristofferStrube.Blazor.DOM;
2+
using KristofferStrube.Blazor.WebIDL;
23
using Microsoft.JSInterop;
34

45
namespace KristofferStrube.Blazor.FileAPI;
@@ -25,8 +26,8 @@ public static async Task<ProgressEventInProcess> CreateAsync(IJSRuntime jSRuntim
2526
/// <inheritdoc/>
2627
public static async Task<ProgressEventInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, CreationOptions options)
2728
{
28-
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync();
29-
return new ProgressEventInProcess(jSRuntime, inProcessHelper, jSReference, options);
29+
IJSInProcessObjectReference InProcessHelper = await jSRuntime.GetInProcessHelperAsync();
30+
return new ProgressEventInProcess(jSRuntime, InProcessHelper, jSReference, options);
3031
}
3132

3233
/// <inheritdoc cref="CreateAsync(IJSRuntime, IJSInProcessObjectReference, CreationOptions)"/>
@@ -54,6 +55,108 @@ protected internal ProgressEventInProcess(IJSRuntime jSRuntime, IJSInProcessObje
5455
/// <returns>The total length of the read.</returns>
5556
public ulong Total => InProcessHelper.Invoke<ulong>("getAttribute", JSReference, "total");
5657

58+
#region inherited from the the in-process event
59+
60+
/// <summary>
61+
/// Returns the type of this <see cref="Event"/>
62+
/// </summary>
63+
public string Type => InProcessHelper.Invoke<string>("getAttribute", JSReference, "type");
64+
65+
/// <summary>
66+
/// Gets the target of this <see cref="Event"/>.
67+
/// </summary>
68+
public new async Task<EventTargetInProcess?> GetTargetAsync()
69+
{
70+
IJSInProcessObjectReference? jSInstance = await InProcessHelper.InvokeAsync<IJSInProcessObjectReference?>("getAttribute", JSReference, "target");
71+
return jSInstance is null ? null : await EventTargetInProcess.CreateAsync(JSRuntime, jSInstance, new() { DisposesJSReference = true });
72+
}
73+
74+
/// <summary>
75+
/// Gets the current target of this <see cref="Event"/>.
76+
/// </summary>
77+
/// <returns>The object whose event listener’s callback is currently being invoked.</returns>
78+
public new async Task<EventTargetInProcess?> GetCurrentTargetAsync()
79+
{
80+
IJSInProcessObjectReference? jSInstance = await InProcessHelper.InvokeAsync<IJSInProcessObjectReference?>("getAttribute", JSReference, "currentTarget");
81+
return jSInstance is null ? null : await EventTargetInProcess.CreateAsync(JSRuntime, jSInstance, new() { DisposesJSReference = true });
82+
}
83+
84+
/// <summary>
85+
/// Returns the invocation target objects of event’s path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root’s mode is "closed" that are not reachable from event’s currentTarget.
86+
/// </summary>
87+
/// <returns>An array of <see cref="EventTargetInProcess"/>s</returns>
88+
public new async Task<EventTargetInProcess[]> ComposedPathAsync()
89+
{
90+
IJSObjectReference jSArray = await JSReference.InvokeAsync<IJSObjectReference>("composedPath");
91+
int length = await InProcessHelper.InvokeAsync<int>("getAttribute", jSArray, "length");
92+
return (await Task.WhenAll(Enumerable
93+
.Range(0, length)
94+
.Select(async i => await EventTargetInProcess.CreateAsync(JSRuntime, await InProcessHelper.InvokeAsync<IJSInProcessObjectReference>("getAttribute", jSArray, i)))))
95+
.ToArray();
96+
}
97+
98+
/// <summary>
99+
/// Returns the <see cref="Event"/>'s phase.
100+
/// </summary>
101+
public EventPhase EventPhase => InProcessHelper.Invoke<EventPhase>("getAttribute", JSReference, "eventPhase");
102+
103+
/// <summary>
104+
/// When dispatched in a tree, invoking this method prevents the event from reaching any objects other than the current object.
105+
/// </summary>
106+
/// <returns></returns>
107+
public void StopPropagation()
108+
{
109+
JSReference.InvokeVoid("stopPropagation");
110+
}
111+
112+
/// <summary>
113+
/// Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
114+
/// </summary>
115+
public void StopImmediatePropagation()
116+
{
117+
JSReference.InvokeVoid("stopImmediatePropagation");
118+
}
119+
120+
/// <summary>
121+
/// Returns <see langword="true"/> if the event goes through its target’s ancestors in reverse tree order; otherwise <see langword="false"/>.
122+
/// </summary>
123+
public bool Bubbles => InProcessHelper.Invoke<bool>("getAttribute", JSReference, "bubbles");
124+
125+
/// <summary>
126+
/// Its value does not always carry meaning, but <see langword="true"/> can indicate that part of the operation during which event was dispatched,can be canceled by invoking the <see cref="PreventDefault"/> method.
127+
/// </summary>
128+
public bool Cancelable => InProcessHelper.Invoke<bool>("getAttribute", JSReference, "cancelable");
129+
130+
/// <summary>
131+
/// If invoked when the cancelable attribute value is <see langword="true"/>, and while executing a listener for the event with passive set to <see langword="false"/>, then it signals to the operation that caused event to be dispatched that it needs to be canceled.
132+
/// </summary>
133+
public void PreventDefault()
134+
{
135+
JSReference.InvokeVoid("preventDefault");
136+
}
137+
138+
/// <summary>
139+
/// Returns <see langword="true"/> if <see cref="PreventDefault"/> was invoked successfully to indicate cancelation; otherwise <see langword="false"/>.
140+
/// </summary>
141+
public bool DefaultPrevented => InProcessHelper.Invoke<bool>("getAttribute", JSReference, "defaultPrevented");
142+
143+
/// <summary>
144+
/// Returns <see langword="true"/> if the event invokes listeners past a ShadowRoot node that is the root of its target; otherwise <see langword="false"/>.
145+
/// </summary>
146+
public bool Composed => InProcessHelper.Invoke<bool>("getAttribute", JSReference, "composed");
147+
148+
/// <summary>
149+
/// Returns <see langword="true"/> if the event was dispatched by the user agent, and <see langword="false"/> otherwise.
150+
/// </summary>
151+
public bool IsTrusted => InProcessHelper.Invoke<bool>("getAttribute", JSReference, "isTrusted");
152+
153+
/// <summary>
154+
/// Returns the event’s timestamp as the number of milliseconds measured relative to the <see href="https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp">time origin</see>.
155+
/// </summary>
156+
public double TimeStamp => InProcessHelper.Invoke<double>("getAttribute", JSReference, "timeStamp");
157+
158+
#endregion
159+
57160
/// <inheritdoc/>
58161
public new async ValueTask DisposeAsync()
59162
{

0 commit comments

Comments
 (0)