Skip to content

Commit

Permalink
feat(blazorui): add runtime type check to all JS calls #8620 (#8621)
Browse files Browse the repository at this point in the history
  • Loading branch information
msynk authored Sep 14, 2024
1 parent cae6dbb commit c24fb14
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static ValueTask<BitFileInfo[]> BitFileUploadReset(this IJSRuntime jsRu
string uploadAddress,
IReadOnlyDictionary<string, string> uploadRequestHttpHeaders)
{
return jsRuntime.InvokeAsync<BitFileInfo[]>("BitBlazorUI.FileUpload.reset", id, dotnetObjectReference, element, uploadAddress, uploadRequestHttpHeaders);
return jsRuntime.Invoke<BitFileInfo[]>("BitBlazorUI.FileUpload.reset", id, dotnetObjectReference, element, uploadAddress, uploadRequestHttpHeaders);
}

internal static ValueTask BitFileUploadUpload(this IJSRuntime jsRuntime,
Expand All @@ -23,29 +23,29 @@ internal static ValueTask BitFileUploadUpload(this IJSRuntime jsRuntime,
string? uploadUrl,
IReadOnlyDictionary<string, string>? httpHeaders)
{
return (httpHeaders is null ? jsRuntime.InvokeVoidAsync("BitBlazorUI.FileUpload.upload", id, from, to, index, uploadUrl)
: jsRuntime.InvokeVoidAsync("BitBlazorUI.FileUpload.upload", id, from, to, index, uploadUrl, httpHeaders));
return (httpHeaders is null ? jsRuntime.InvokeVoid("BitBlazorUI.FileUpload.upload", id, from, to, index, uploadUrl)
: jsRuntime.InvokeVoid("BitBlazorUI.FileUpload.upload", id, from, to, index, uploadUrl, httpHeaders));
}

internal static ValueTask BitFileUploadPause(this IJSRuntime jsRuntime, string id, int index = -1)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.FileUpload.pause", id, index);
return jsRuntime.InvokeVoid("BitBlazorUI.FileUpload.pause", id, index);
}

internal static ValueTask<IJSObjectReference> BitFileUploadSetupDragDrop(this IJSRuntime jsRuntime,
ElementReference dragDropZoneElement,
ElementReference inputFileElement)
{
return jsRuntime.InvokeAsync<IJSObjectReference>("BitBlazorUI.FileUpload.setupDragDrop", dragDropZoneElement, inputFileElement);
return jsRuntime.Invoke<IJSObjectReference>("BitBlazorUI.FileUpload.setupDragDrop", dragDropZoneElement, inputFileElement);
}

internal static ValueTask BitFileUploadBrowse(this IJSRuntime jsRuntime, ElementReference inputFileElement)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.FileUpload.browse", inputFileElement);
return jsRuntime.InvokeVoid("BitBlazorUI.FileUpload.browse", inputFileElement);
}

internal static ValueTask BitFileUploadDispose(this IJSRuntime jsRuntime, string id)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.FileUpload.dispose", id);
return jsRuntime.InvokeVoid("BitBlazorUI.FileUpload.dispose", id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ internal static class BitOtpInputJsRuntimeExtensions
{
internal static ValueTask BitOtpInputSetup(this IJSRuntime jsRuntime, DotNetObjectReference<BitOtpInput> obj, ElementReference input)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.OtpInput.setup", obj, input);
return jsRuntime.InvokeVoid("BitBlazorUI.OtpInput.setup", obj, input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ internal static class BitSearchBoxJsRuntimeExtensions
{
internal static ValueTask BitSearchBoxMoveCursorToEnd(this IJSRuntime jsRuntime, ElementReference input)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.SearchBox.moveCursorToEnd", input);
return jsRuntime.InvokeVoid("BitBlazorUI.SearchBox.moveCursorToEnd", input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ internal static class BitCircularTimePickerJsRuntimeExtensions
{
internal static ValueTask<string> BitCircularTimePickerRegisterPointerUp(this IJSRuntime js, DotNetObjectReference<BitCircularTimePicker> obj, string methodName)
{
return js.InvokeAsync<string>("BitBlazorUI.CircularTimePicker.registerEvent", "pointerup", obj, methodName);
return js.Invoke<string>("BitBlazorUI.CircularTimePicker.registerEvent", "pointerup", obj, methodName);
}

internal static ValueTask<string> BitCircularTimePickerRegisterPointerMove(this IJSRuntime js, DotNetObjectReference<BitCircularTimePicker> obj, string methodName)
{
return js.InvokeAsync<string>("BitBlazorUI.CircularTimePicker.registerEvent", "pointermove", obj, methodName);
return js.Invoke<string>("BitBlazorUI.CircularTimePicker.registerEvent", "pointermove", obj, methodName);
}

internal static ValueTask BitCircularTimePickerAbort(this IJSRuntime jSRuntime, string? abortControllerId, bool dispose = false)
{
return jSRuntime.InvokeVoidAsync("BitBlazorUI.CircularTimePicker.abort", abortControllerId, dispose);
return jSRuntime.InvokeVoid("BitBlazorUI.CircularTimePicker.abort", abortControllerId, dispose);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ internal static class BitColorPickerJsRuntimeExtensions
{
internal static ValueTask<string> BitColorPickerRegisterPointerUp(this IJSRuntime js, DotNetObjectReference<BitColorPicker> obj, string methodName)
{
return js.InvokeAsync<string>("BitBlazorUI.ColorPicker.registerEvent", "pointerup", obj, methodName);
return js.Invoke<string>("BitBlazorUI.ColorPicker.registerEvent", "pointerup", obj, methodName);
}

internal static ValueTask<string> BitColorPickerRegisterPointerMove(this IJSRuntime js, DotNetObjectReference<BitColorPicker> obj, string methodName)
{
return js.InvokeAsync<string>("BitBlazorUI.ColorPicker.registerEvent", "pointermove", obj, methodName);
return js.Invoke<string>("BitBlazorUI.ColorPicker.registerEvent", "pointermove", obj, methodName);
}

internal static ValueTask BitColorPickerAbort(this IJSRuntime jSRuntime, string? abortControllerId, bool dispose = false)
{
return jSRuntime.InvokeVoidAsync("BitBlazorUI.ColorPicker.abort", abortControllerId, dispose);
return jSRuntime.InvokeVoid("BitBlazorUI.ColorPicker.abort", abortControllerId, dispose);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ internal static class BitSwiperJsRuntimeExtensions
{
internal static ValueTask<SwiperDimensions> BitSwiperGetDimensions(this IJSRuntime jsRuntime, ElementReference root, ElementReference swiper)
{
return jsRuntime.InvokeAsync<SwiperDimensions>("BitBlazorUI.Swiper.getDimensions", root, swiper);
return jsRuntime.Invoke<SwiperDimensions>("BitBlazorUI.Swiper.getDimensions", root, swiper);
}

internal static ValueTask BitSwiperRegisterPointerLeave(this IJSRuntime jsRuntime, ElementReference root, DotNetObjectReference<BitSwiper> dotnetObj)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.Swiper.registerPointerLeave", root, dotnetObj);
return jsRuntime.InvokeVoid("BitBlazorUI.Swiper.registerPointerLeave", root, dotnetObj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ internal static class BitModalJsRuntimeExtensions
{
internal static ValueTask BitModalSetupDragDrop(this IJSRuntime js, string id, string dragElementSelector)
{
return js.InvokeVoidAsync("BitBlazorUI.Modal.setupDragDrop", id, dragElementSelector);
return js.InvokeVoid("BitBlazorUI.Modal.setupDragDrop", id, dragElementSelector);
}

internal static ValueTask BitModalRemoveDragDrop(this IJSRuntime js, string id, string dragElementSelector)
{
return js.InvokeVoidAsync("BitBlazorUI.Modal.removeDragDrop", id, dragElementSelector);
return js.InvokeVoid("BitBlazorUI.Modal.removeDragDrop", id, dragElementSelector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ protected override void RegisterCssStyles()

private async Task ResetPaneDimensions()
{
await _js.InvokeVoidAsync("BitSplitter.resetPaneDimensions", _firstPanelRef);
await _js.InvokeVoidAsync("BitSplitter.resetPaneDimensions", _secondPanelRef);
await _js.BitSplitterResetPaneDimensions(_firstPanelRef);
await _js.BitSplitterResetPaneDimensions(_secondPanelRef);
}

private async Task OnDraggingStart(double position)
Expand All @@ -122,11 +122,11 @@ private async Task OnDraggingStart(double position)

_initialPosition = position;

_initialFirstPanelWidth = await _js.InvokeAsync<double>("BitSplitter.getSplitterWidth", _firstPanelRef);
_initialSecondPanelWidth = await _js.InvokeAsync<double>("BitSplitter.getSplitterWidth", _secondPanelRef);
_initialFirstPanelWidth = await _js.BitSplitterGetSplitterWidth(_firstPanelRef);
_initialSecondPanelWidth = await _js.BitSplitterGetSplitterWidth(_secondPanelRef);

_initialFirstPanelHeight = await _js.InvokeAsync<double>("BitSplitter.getSplitterHeight", _firstPanelRef);
_initialSecondPanelHeight = await _js.InvokeAsync<double>("BitSplitter.getSplitterHeight", _secondPanelRef);
_initialFirstPanelHeight = await _js.BitSplitterGetSplitterHeight(_firstPanelRef);
_initialSecondPanelHeight = await _js.BitSplitterGetSplitterHeight(_secondPanelRef);
}

private async Task OnDragging(double position)
Expand All @@ -139,15 +139,15 @@ private async Task OnDragging(double position)
{
var newPrimaryHeight = _initialFirstPanelHeight + delta;
var newSecondaryHeight = _initialSecondPanelHeight - delta;
await _js.InvokeVoidAsync("BitSplitter.setSplitterHeight", _firstPanelRef, newPrimaryHeight);
await _js.InvokeVoidAsync("BitSplitter.setSplitterHeight", _secondPanelRef, newSecondaryHeight);
await _js.BitSplitterSetSplitterHeight(_firstPanelRef, newPrimaryHeight);
await _js.BitSplitterSetSplitterHeight(_secondPanelRef, newSecondaryHeight);
}
else
{
var newPrimaryWidth = _initialFirstPanelWidth + delta;
var newSecondaryWidth = _initialSecondPanelWidth - delta;
await _js.InvokeVoidAsync("BitSplitter.setSplitterWidth", _firstPanelRef, newPrimaryWidth);
await _js.InvokeVoidAsync("BitSplitter.setSplitterWidth", _secondPanelRef, newSecondaryWidth);
await _js.BitSplitterSetSplitterWidth(_firstPanelRef, newPrimaryWidth);
await _js.BitSplitterSetSplitterWidth(_secondPanelRef, newSecondaryWidth);
}
}
}
Expand All @@ -157,7 +157,7 @@ private async Task OnDraggingEnd()
_isDragging = false;
ClassBuilder.Reset();

await _js.InvokeVoidAsync("BitSplitter.handleSplitterDraggingEnd");
await _js.BitSplitterHandleSplitterDraggingEnd();
}

private async Task OnPointerDown(PointerEventArgs e)
Expand All @@ -172,7 +172,7 @@ private async Task OnPointerMove(PointerEventArgs e)

private async Task OnTouchStart(TouchEventArgs e)
{
await _js.InvokeVoidAsync("BitSplitter.handleSplitterDragging", e);
await _js.BitSplitterHandleSplitterDragging(e);

await OnDraggingStart(Vertical ? e.Touches[0].ClientY : e.Touches[0].ClientX);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
class BitSplitter {
public static handleSplitterDragging(event: TouchEvent) {
document.body.style.overscrollBehavior = 'none';
};
namespace BitBlazorUI {
export class Splitter {
public static handleSplitterDragging(event: TouchEvent) {
document.body.style.overscrollBehavior = 'none';
};

public static handleSplitterDraggingEnd() {
document.body.style.overscrollBehavior = '';
};
public static handleSplitterDraggingEnd() {
document.body.style.overscrollBehavior = '';
};

public static getSplitterWidth(element: HTMLElement) {
return element.getBoundingClientRect().width;
};
public static getSplitterWidth(element: HTMLElement) {
return element.getBoundingClientRect().width;
};

public static setSplitterWidth(element: HTMLElement, width: number) {
element.style.width = width + 'px';
};
public static setSplitterWidth(element: HTMLElement, width: number) {
element.style.width = width + 'px';
};

public static getSplitterHeight(element: HTMLElement) {
return element.getBoundingClientRect().height;
};
public static getSplitterHeight(element: HTMLElement) {
return element.getBoundingClientRect().height;
};

public static setSplitterHeight(element: HTMLElement, height: number) {
element.style.height = height + 'px';
};

public static resetPaneDimensions(element: HTMLElement) {
element.style.width = '';
element.style.height = '';
};
}
public static setSplitterHeight(element: HTMLElement, height: number) {
element.style.height = height + 'px';
};

public static resetPaneDimensions(element: HTMLElement) {
element.style.width = '';
element.style.height = '';
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Bit.BlazorUI;

internal static class BitSplitterJsRuntimeExtensions
{
internal static ValueTask BitSplitterResetPaneDimensions(this IJSRuntime js, ElementReference element)
{
return js.InvokeVoid("BitBlazorUI.Splitter.resetPaneDimensions", element);
}

internal static ValueTask<double> BitSplitterGetSplitterWidth(this IJSRuntime js, ElementReference element)
{
return js.Invoke<double>("BitBlazorUI.Splitter.getSplitterWidth", element);
}

internal static ValueTask BitSplitterSetSplitterWidth(this IJSRuntime js, ElementReference element, double value)
{
return js.InvokeVoid("BitBlazorUI.Splitter.setSplitterWidth", element, value);
}

internal static ValueTask<double> BitSplitterGetSplitterHeight(this IJSRuntime js, ElementReference element)
{
return js.Invoke<double>("BitBlazorUI.Splitter.getSplitterHeight", element);
}

internal static ValueTask BitSplitterSetSplitterHeight(this IJSRuntime js, ElementReference element, double value)
{
return js.InvokeVoid("BitBlazorUI.Splitter.setSplitterHeight", element, value);
}

internal static ValueTask BitSplitterHandleSplitterDragging(this IJSRuntime js, TouchEventArgs e)
{
return js.InvokeVoid("BitBlazorUI.Splitter.handleSplitterDragging", e);
}

internal static ValueTask BitSplitterHandleSplitterDraggingEnd(this IJSRuntime js)
{
return js.InvokeVoid("BitBlazorUI.Splitter.handleSplitterDraggingEnd");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ internal static class BitOverlayJsRuntimeExtensions
{
internal static ValueTask<int> BitOverlayToggleScroll(this IJSRuntime jsRuntime, string scrollerSelector, bool isOpen)
{
return jsRuntime.InvokeAsync<int>("BitBlazorUI.Overlay.toggleScroll", scrollerSelector, isOpen);
return jsRuntime.Invoke<int>("BitBlazorUI.Overlay.toggleScroll", scrollerSelector, isOpen);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ internal static class CalloutsJsRuntimeExtensions
bool setCalloutWidth,
string rootCssClass) where T : class
{
return jsRuntime.InvokeAsync<bool>("BitBlazorUI.Callouts.toggle",
dotnetObj,
componentId,
component,
calloutId,
callout,
isCalloutOpen,
responsiveMode,
dropDirection,
isRtl,
scrollContainerId,
scrollOffset,
headerId,
footerId,
setCalloutWidth,
rootCssClass);
return jsRuntime.Invoke<bool>("BitBlazorUI.Callouts.toggle",
dotnetObj,
componentId,
component,
calloutId,
callout,
isCalloutOpen,
responsiveMode,
dropDirection,
isRtl,
scrollContainerId,
scrollOffset,
headerId,
footerId,
setCalloutWidth,
rootCssClass);
}

internal static ValueTask ClearCallout(this IJSRuntime jsRuntime, string calloutId)
{
return jsRuntime.InvokeVoidAsync("BitBlazorUI.Callouts.clear", calloutId);
return jsRuntime.InvokeVoid("BitBlazorUI.Callouts.clear", calloutId);
}
}
Loading

0 comments on commit c24fb14

Please sign in to comment.