Skip to content

Commit

Permalink
Merge pull request #9626 from bitfoundation/develop
Browse files Browse the repository at this point in the history
Version 9.2.1 (#9615)
  • Loading branch information
msynk authored Jan 5, 2025
2 parents 5e527dc + 33ecf63 commit 261dfba
Show file tree
Hide file tree
Showing 76 changed files with 831 additions and 345 deletions.
2 changes: 1 addition & 1 deletion src/Besql/Bit.Besql/wwwroot/bit-besql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var BitBesql = window.BitBesql || {};
BitBesql.version = window['bit-besql version'] = '9.2.0';
BitBesql.version = window['bit-besql version'] = '9.2.1';

BitBesql.init = async function init(fileName) {
const sqliteFilePath = `/${fileName}`;
Expand Down
2 changes: 1 addition & 1 deletion src/Bit.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageProjectUrl>https://github.com/bitfoundation/bitplatform</PackageProjectUrl>

<!-- Version -->
<ReleaseVersion>9.2.0</ReleaseVersion>
<ReleaseVersion>9.2.1</ReleaseVersion>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageReleaseNotes>https://github.com/bitfoundation/bitplatform/releases/tag/v-$(ReleaseVersion)</PackageReleaseNotes>
<Version Condition=" '$(Configuration)' == 'Release' ">$([System.String]::Copy($(ReleaseVersion)).Replace('-pre-', '.'))</Version>
Expand Down
68 changes: 49 additions & 19 deletions src/BlazorUI/Bit.BlazorUI/Components/Inputs/BitInputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Bit.BlazorUI;
/// integrates with an <see cref="Microsoft.AspNetCore.Components.Forms.EditContext"/>, which must be supplied
/// as a cascading parameter.
/// </summary>
public abstract class BitInputBase<TValue> : BitComponentBase, IDisposable
public abstract class BitInputBase<TValue> : BitComponentBase, IDisposable, IAsyncDisposable
{
protected bool IsDisposed;
protected bool ValueHasBeenSet;
Expand Down Expand Up @@ -63,6 +63,11 @@ protected BitInputBase()
/// </summary>
[Parameter] public string? Name { get; set; }

/// <summary>
/// Disables the validation of the input.
/// </summary>
[Parameter] public bool NoValidate { get; set; }

/// <summary>
/// Callback for when the input value changes.
/// </summary>
Expand Down Expand Up @@ -141,6 +146,11 @@ public override Task SetParametersAsync(ParameterView parameters)
{
switch (parameter.Key)
{
case nameof(NoValidate):
NoValidate = (bool)parameter.Value;
parametersDictionary.Remove(parameter.Key);
break;

case nameof(CascadedEditContext):
CascadedEditContext = (EditContext?)parameter.Value;
parametersDictionary.Remove(parameter.Key);
Expand Down Expand Up @@ -198,26 +208,29 @@ public override Task SetParametersAsync(ParameterView parameters)
}
}

if (_hasInitializedParameters is false)
if (NoValidate is false)
{
// This is the first run
// Could put this logic in OnInit, but its nice to avoid forcing people who override OnInitialized to call base.OnInitialized()
if (_hasInitializedParameters is false)
{
// This is the first run
// Could put this logic in OnInitialized, but its nice to avoid forcing people who override OnInitialized to call base.OnInitialized()

CreateFieldIdentifier();
CreateFieldIdentifier();

_hasInitializedParameters = true;
}
else if (CascadedEditContext != EditContext)
{
// Not the first run
_hasInitializedParameters = true;
}
else if (CascadedEditContext != EditContext)
{
// Not the first run

// We don't support changing EditContext because it's messy to be clearing up state and event
// handlers for the previous one, and there's no strong use case. If a strong use case
// emerges, we can consider changing this.
throw new InvalidOperationException($"{GetType()} does not support changing the {nameof(EditContext)} dynamically.");
}
// We don't support changing EditContext because it's messy to be clearing up state and event
// handlers for the previous one, and there's no strong use case. If a strong use case
// emerges, we can consider changing this.
throw new InvalidOperationException($"{GetType()} does not support changing the {nameof(EditContext)} dynamically.");
}

UpdateValidationAttributes();
UpdateValidationAttributes();
}

// For derived components, retain the usual lifecycle with OnInit/OnParametersSet/etc.
return base.SetParametersAsync(ParameterView.FromDictionary(parametersDictionary!));
Expand Down Expand Up @@ -334,7 +347,7 @@ protected async Task SetCurrentValueAsStringAsync(string? value, bool bypass = f
await SetCurrentValueAsync(parsedValue);
}
}
else
else if (NoValidate is false)
{
_parsingFailed = true;

Expand All @@ -348,6 +361,10 @@ protected async Task SetCurrentValueAsStringAsync(string? value, bool bypass = f
EditContext.NotifyFieldChanged(FieldIdentifier);
}
}
else
{
_parsingFailed = false;
}

// We can skip the validation notification if we were previously valid and still are
if (_parsingFailed || _previousParsingAttemptFailed)
Expand All @@ -365,7 +382,10 @@ protected async Task SetCurrentValueAsync(TValue? value)

await ValueChanged.InvokeAsync(value);

EditContext?.NotifyFieldChanged(FieldIdentifier);
if (EditContext is not null && NoValidate is false)
{
EditContext.NotifyFieldChanged(FieldIdentifier);
}

await OnChange.InvokeAsync(value);
}
Expand All @@ -388,7 +408,7 @@ private void OnValidateStateChanged(object? sender, ValidationStateChangedEventA

private void UpdateValidationAttributes()
{
if (EditContext is null) return;
if (EditContext is null || NoValidate) return;

var hasAriaInvalidAttribute = InputHtmlAttributes is not null && InputHtmlAttributes.ContainsKey("aria-invalid");

Expand Down Expand Up @@ -476,5 +496,15 @@ public void Dispose()
GC.SuppressFinalize(this);
}

public ValueTask DisposeAsync()
{
if (IsDisposed) return ValueTask.CompletedTask;

Dispose();
return DisposeAsync(true);
}

protected virtual void Dispose(bool disposing) { }

protected virtual ValueTask DisposeAsync(bool disposing) { return ValueTask.CompletedTask; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Bit.BlazorUI;

public partial class BitOtpInput : BitInputBase<string?>, IDisposable
public partial class BitOtpInput : BitInputBase<string?>
{
private string _labelId = default!;
private string?[] _inputIds = default!;
Expand Down Expand Up @@ -116,14 +116,16 @@ public partial class BitOtpInput : BitInputBase<string?>, IDisposable
/// </summary>
public ValueTask FocusAsync(int index = 0) => _inputRefs[index].FocusAsync();

[JSInvokable]
public async Task SetPastedData(string pastedValue)


[JSInvokable("SetValue")]
public async Task _SetValue(string value)
{
if (IsEnabled is false || InvalidValueBinding()) return;
if (pastedValue.HasNoValue()) return;
if (Type is BitInputType.Number && int.TryParse(pastedValue, out _) is false) return;
if (value.HasNoValue()) return;
if (Type is BitInputType.Number && int.TryParse(value, out _) is false) return;

SetInputsValue(pastedValue);
SetInputsValue(value);

CurrentValueAsString = string.Join(string.Empty, _inputValues);

Expand Down Expand Up @@ -195,7 +197,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

foreach (var inputRef in _inputRefs)
{
await _js.BitOtpInputSetup(_dotnetObj, inputRef);
await _js.BitOtpInputSetup(_Id, _dotnetObj, inputRef);
}
}

Expand All @@ -206,11 +208,12 @@ protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(fa
return true;
}

protected override void Dispose(bool disposing)
protected override async ValueTask DisposeAsync(bool disposing)
{
if (disposing)
{
_dotnetObj?.Dispose();
await _js.BitOtpInputDispose(_Id);
}

base.Dispose(disposing);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
namespace BitBlazorUI {
export class OtpInput {
public static setup(dotnetReference: DotNetObject, input: HTMLInputElement) {
private static abortControllers: { [key: string]: AbortController } = {};

public static setup(id: string, dotnetObj: DotNetObject, input: HTMLInputElement) {
input.addEventListener('focus', (e: any) => {
e.target?.select();
});

input.addEventListener('paste', async e => {
e.preventDefault();
let pastedValue = e.clipboardData?.getData('Text');
await dotnetReference.invokeMethodAsync("SetPastedData", pastedValue);
await dotnetObj.invokeMethodAsync("SetValue", pastedValue);
});

OtpInput.setupSmsAutofill(id, dotnetObj);
}

public static dispose(id: string) {
const ac = OtpInput.abortControllers[id];
if (!ac) return;

ac.abort();
delete OtpInput.abortControllers[id];
}

private static setupSmsAutofill(id: string, dotnetObj: DotNetObject) {
if (!('OTPCredential' in window)) return;

const abortCtrl = new AbortController();
OtpInput.abortControllers[id] = abortCtrl;

navigator.credentials.get({
otp: { transport: ['sms'] },
signal: abortCtrl.signal
} as any).then(async (otp: any) => {
await dotnetObj.invokeMethodAsync("SetValue", otp.code);
abortCtrl.abort();
delete OtpInput.abortControllers[id];
}).catch(async (err: any) => {
abortCtrl.abort();
delete OtpInput.abortControllers[id];
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

internal static class BitOtpInputJsRuntimeExtensions
{
internal static ValueTask BitOtpInputSetup(this IJSRuntime jsRuntime, DotNetObjectReference<BitOtpInput> obj, ElementReference input)
internal static ValueTask BitOtpInputSetup(this IJSRuntime jsRuntime, string id, DotNetObjectReference<BitOtpInput> obj, ElementReference input)
{
return jsRuntime.InvokeVoid("BitBlazorUI.OtpInput.setup", obj, input);
return jsRuntime.InvokeVoid("BitBlazorUI.OtpInput.setup", id, obj, input);
}

internal static ValueTask BitOtpInputDispose(this IJSRuntime jsRuntime, string id)
{
return jsRuntime.InvokeVoid("BitBlazorUI.OtpInput.dispose", id);
}
}
2 changes: 1 addition & 1 deletion src/BlazorUI/Bit.BlazorUI/Scripts/general.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(BitBlazorUI as any).version = (window as any)['bit-blazorui version'] = '9.2.0';
(BitBlazorUI as any).version = (window as any)['bit-blazorui version'] = '9.2.1';

interface DotNetObject {
invokeMethod<T>(methodIdentifier: string, ...args: any[]): T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bit.CodeAnalyzers" Version="9.2.0">
<PackageReference Include="Bit.CodeAnalyzers" Version="9.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="9.2.0">
<PackageReference Include="Bit.SourceGenerators" Version="9.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bit.CodeAnalyzers" Version="9.2.0">
<PackageReference Include="Bit.CodeAnalyzers" Version="9.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="9.2.0">
<PackageReference Include="Bit.SourceGenerators" Version="9.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<Content Remove="appsettings.json" />
<EmbeddedResource Include="appsettings.json" />

<PackageReference Include="Bit.CodeAnalyzers" Version="9.2.0">
<PackageReference Include="Bit.CodeAnalyzers" Version="9.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Bit.SourceGenerators" Version="9.2.0">
<PackageReference Include="Bit.SourceGenerators" Version="9.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ public partial class ComponentDemo
Description = "Gets or sets the name of the element. Allows access by name from the associated form.",
},
new()
{
Name = "NoValidate",
Type = "bool",
DefaultValue = "false",
Description = "Disables the validation of the input.",
},
new()
{
Name = "OnChange",
Type = "EventCallback<TValue?>",
Expand Down
Loading

0 comments on commit 261dfba

Please sign in to comment.