Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Components/Pages/Coms.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="coms-search">
<div class="row">
<div class="col-12">
<Search @bind-Value="@SearchText" PlaceHolder="@Localizer["Search"]" IsTriggerSearchByInput="true" IsAutoFocus="true" OnSearch="@OnSearch"></Search>
<Search @bind-Value="@SearchText" PlaceHolder="@Localizer["Search"]" OnSearch="@OnSearch"></Search>
</div>
</div>
<div class="coms-search-filter">
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.2.3</Version>
<Version>9.2.4-beta01</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 21 additions & 7 deletions src/BootstrapBlazor/Components/Select/Select.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ export function init(id, invoke, options) {
const menu = popover.toggleMenu;
const key = e.key;
if (key === "Enter" || key === 'NumpadEnter') {
menu.classList.remove('show')
let index = indexOf(el, activeItem)
if (popover.isPopover) {
popover.hide();
}
else {
menu.classList.remove('show');
}
const activeItem = menu.querySelector('.active');
let index = indexOf(menu, activeItem)
invoke.invokeMethodAsync(confirmMethodCallback, index)
}
else if (key === 'ArrowUp' || key === 'ArrowDown') {
Expand Down Expand Up @@ -64,7 +70,9 @@ export function init(id, invoke, options) {
}

EventHandler.on(el, 'shown.bs.dropdown', shown);
EventHandler.on(el, 'keydown', keydown)

const input = el.querySelector(`#${id}_input`);
EventHandler.on(input, 'keydown', keydown)

const onSearch = debounce(async v => {
search.parentElement.classList.add('l');
Expand All @@ -73,6 +81,7 @@ export function init(id, invoke, options) {
});
if (search) {
Input.composition(search, onSearch);
EventHandler.on(search, 'keydown', keydown);
}

const select = {
Expand Down Expand Up @@ -123,10 +132,15 @@ export function dispose(id) {
Data.remove(id)

if (select) {
EventHandler.off(select.el, 'shown.bs.dropdown')
EventHandler.off(select.el, 'keydown');
Popover.dispose(select.popover)
Input.dispose(select.search);
const { el, popover, search } = select
EventHandler.off(el, 'shown.bs.dropdown')
EventHandler.off(el, 'keydown');
Popover.dispose(popover);

if (search) {
Input.dispose(search);
EventHandler.off(search, 'keydown');
}
}
}

Expand Down
42 changes: 16 additions & 26 deletions src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,17 @@ public override LocalizedString this[string name]
{
get
{
var value = SafeFormat();
return new LocalizedString(name, value ?? name, resourceNotFound: value == null, searchedLocation: typeName);

string? SafeFormat()
string? value = null;
try
{
var format = GetStringSafely(name);
value = string.Format(CultureInfo.CurrentCulture, format ?? name, arguments);
}
catch (Exception ex)
{
string? ret = null;
try
{
var format = GetStringSafely(name);
ret = string.Format(CultureInfo.CurrentCulture, format ?? name, arguments);
}
catch (Exception ex)
{
Logger.LogError(ex, "{JsonStringLocalizerName} searched for '{Name}' in '{typeName}' with culture '{CultureName}' throw exception.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name);
}
return ret;
Logger.LogError(ex, "{JsonStringLocalizerName} searched for '{Name}' in '{typeName}' with culture '{CultureName}' throw exception.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name);
}
return new LocalizedString(name, value ?? name, resourceNotFound: value == null, searchedLocation: typeName);
}
}

Expand Down Expand Up @@ -104,7 +98,13 @@ public override LocalizedString this[string name]
var cacheKey = $"{nameof(GetValueFromCache)}&name={name}&{Assembly.GetUniqueName()}&type={typeName}&culture={cultureName}";
if (!CacheManager.GetMissingLocalizerByKey(cacheKey))
{
var l = GetLocalizedString();
LocalizedString? localizer = null;
if (localizerStrings != null)
{
// perf: 性能问题,这里需要优化
localizer = localizerStrings.FirstOrDefault(i => i.Name == name);
}
var l = localizer ?? CacheManager.GetAllStringsFromResolve().FirstOrDefault(i => i.Name == name);
if (l is { ResourceNotFound: false })
{
ret = l.Value;
Expand All @@ -116,16 +116,6 @@ public override LocalizedString this[string name]
}
}
return ret;

LocalizedString? GetLocalizedString()
{
LocalizedString? localizer = null;
if (localizerStrings != null)
{
localizer = localizerStrings.FirstOrDefault(i => i.Name == name);
}
return localizer ?? CacheManager.GetAllStringsFromResolve().FirstOrDefault(i => i.Name == name);
}
}

private string? GetLocalizerValueFromCache(IStringLocalizer localizer, string name)
Expand Down
Loading