mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
e8965eb369
* feat(module: table): add a method to get query model (#1202) * feat(module: table): add OnExpand event (#1208) * feat(module: table): add summary (#1218) * feat(module: table): add summary row * feat: add fixed summary cell * feat(module: InputNumber): Add long-click and keyboard operation (#1235) * feat(module: InputNumber): Add long click and keyboard event 1. When hold mouse down button will always trigger the increase or decrease 2. Add event listener to "ArrowUp" and "ArrowDown" key * feat(module: InputNumber): Add long click and keyboard event 1. When hold mouse down button will always trigger the increase or decrease 2. Add event listener to "ArrowUp" and "ArrowDown" key * fix null reference exception Co-authored-by: ElderJames <shunjiey@hotmail.com> * refactor(module: pagination): cover the apis of react (#1220) * feat(module: config-provider): support RTL (#1238) * feat(module: config-provider): support RTL * add rtl for each component * fix rtl for pagination * add rtl for overlay * chore: sync ant-design v4.14.0 (#1249) * feat(module: tag): add closing event (#1268) * tag add onclosing event * clean code * translate the comment * translation Co-authored-by: James Yeung <shunjiey@hotmail.com> * chore: sync ant-design v4.15.0 (#1281) * feat: add built-in themes (#1286) * feat: add themes * add docs theming styles * fix the RTL for FixedWidgets * fix aliyun theme * fix docs style * feat(module: form): Form lable supports left alignment (#1292) * feat: Form lable supports left alignment * Update and rename components/grid/Col.razor.cs to 组件/格网/Col.razor.cs * Delete Col.razor.cs * no message * PR:1292 * typo LabelAlign * add the property in Col instead FormItem * clean code Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: upload): missing and new event (#1302) * feat(module:upload): missing and new event * docs(module:upload): new events (missing Chinese) Co-authored-by: James Yeung <shunjiey@hotmail.com> * refactor: unified use of FeedbackComponent for modal comfirm and drawer (#1263) * refactor: support to use the same template for confirm and modal * refactor: support to use the same template for drawer * refactor: separate interface IOkCancelRef * chore: modify EventUtil class summary Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: alert): add message template and loop banner demo (#1250) * feat(Alert): added alert loop component * fix: move cmp into main * feat: add parameters for looping text * feat: add new messages loop * fix: create new internal looptext cmp * doc: add demo * doc: add demo markdown * doc: update alert api * doc: update cn docs * fix: add missing dependency * fix: update param name * impleement loop text with css * fix the document Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: table): add support for Display attribute (#1310) feat(module:table): add support for Display attribute Display attribute is widely used to specify display text for entity properties. Table component should get column names from Display attribute instances. Closes #1278 * test: add TestKit for public tests (#1248) * test: change folder structure and add new TestKit csproj for public testing of AntDesign-based applications * docs: added CN and EN docs about TestKit * fix doc translate * change the directory structure Co-authored-by: Patryk Grzelak <pgrzelak@mutate.app> Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: space): add wrap, split and size array (#1314) * fix(module: datepicker): incorrect in RTL mode (#1300) * fix(module: dropdown): default PlacementType is incorrect in RTL mode * fix(module: datepicker): not correct in RTL mode * fix(module: datepicker): styles is incorrect when switch to LTR from RTL Co-authored-by: James Yeung <shunjiey@hotmail.com> * docs: fix default css link (#1318) * fix(module: table): bring PR1208 to PR1303 merge master into feature (#1326) * feat(module: pagination): add TotalBoundaryShowSizeChanger parameter (#1325) * feat(module: pagination): add TotalBoundaryShowSizeChanger * docs(module: pagination): update API Co-authored-by: James Yeung <shunjiey@hotmail.com> * docs: dynamic primary color changing (#1332) * feat(docs): change color dynamically * docs: dynamic primary color changing * fix file path * delete the script * feat(module: table): add build-in filters (#1267) * tablefilter-moreoptions * tablefilter-moreoptions * tablefilter-moreoptions * tablefilter-moreoptions * tablefilter-moreoptions * fix demo and docs Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: tooltip): wrong popup direction (#1348) * fix merge conflicts Co-authored-by: Andrzej Bakun <andrzej@neelyc.com.cy> Co-authored-by: LingDev <lingjing0921@live.com> Co-authored-by: Zonciu Liang <zonciu@zonciu.com> Co-authored-by: TimChen <TimChen44@users.noreply.github.com> Co-authored-by: unsung189 <52531536+unsung189@users.noreply.github.com> Co-authored-by: zxyao <zxyao145@gmail.com> Co-authored-by: Patrick <42546986+MutatePat@users.noreply.github.com> Co-authored-by: anranruye <54608128+anranruye@users.noreply.github.com> Co-authored-by: Patryk Grzelak <pgrzelak@mutate.app> Co-authored-by: 笨木头 <musicvs@163.com> Co-authored-by: Magehernan <magehernan@gmail.com> Co-authored-by: ldsenow <ldsenow@gmail.com> Co-authored-by: Leishi <lluo@octet.com> Co-authored-by: YMohd <31305504+YMohd@users.noreply.github.com>
263 lines
8.4 KiB
C#
263 lines
8.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Runtime.CompilerServices;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using AntDesign.JsInterop;
|
||
using Microsoft.AspNetCore.Components;
|
||
using Microsoft.AspNetCore.Components.Web;
|
||
using Microsoft.JSInterop;
|
||
using OneOf;
|
||
|
||
namespace AntDesign
|
||
{
|
||
public partial class Mentions
|
||
{
|
||
[Parameter] public bool AutoFocus { get; set; }
|
||
[Parameter] public bool Disable { get; set; }
|
||
[Parameter] public bool Readonly { get; set; }
|
||
[Parameter] public string Prefix { get; set; } = "@,#"; //“@,#”
|
||
[Parameter] public string Split { get; set; } = " ";
|
||
[Parameter] public string DefaultValue { get; set; }
|
||
[Parameter] public string Placeholder { get; set; }
|
||
[Parameter] public string Value { get; set; }
|
||
[Parameter] public string Placement { get; set; } = "bottom";
|
||
[Parameter] public int Rows { get; set; } = 1;
|
||
[Parameter] public bool Loading { get; set; } = false;
|
||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||
[Parameter] public EventCallback<string> ValueChange { get; set; }
|
||
[Parameter] public EventCallback<FocusEventArgs> OnFocus { get; set; }
|
||
[Parameter] public EventCallback<FocusEventArgs> OnBlur { get; set; }
|
||
[Parameter] public EventCallback<EventArgs> OnSearch { get; set; }
|
||
|
||
[Parameter] public RenderFragment NoFoundContent { get; set; }
|
||
|
||
public Dictionary<string, object> Attributes { get; set; }
|
||
|
||
[Inject] private DomEventService DomEventService { get; set; }
|
||
internal List<MentionsOption> LstOriginalOptions { get; set; } = new List<MentionsOption>();
|
||
|
||
private string DropdownStyle { get; set; }
|
||
private bool Focused { get; set; }
|
||
private bool ShowSuggestions { get; set; }
|
||
|
||
private void SetClassMap()
|
||
{
|
||
var prefixCls = "ant-mentions";
|
||
this.ClassMapper.Clear()
|
||
.Add(prefixCls)
|
||
.If($"{prefixCls}-disable", () => this.Disable)
|
||
.If($"{prefixCls}-focused", () => this.Focused)
|
||
.If($"{prefixCls}-rtl", () => RTL)
|
||
;
|
||
}
|
||
|
||
protected override void OnInitialized()
|
||
{
|
||
base.OnInitialized();
|
||
|
||
SetClassMap();
|
||
if (string.IsNullOrEmpty(Value))
|
||
{
|
||
Value = DefaultValue;
|
||
}
|
||
|
||
//DomEventService.AddEventListener(Ref, "keyup", OnTextAreaKeyup);
|
||
// DomEventService.AddEventListener(Ref, "onmouseup", OnTextAreaMouseUp);
|
||
}
|
||
|
||
internal bool FirstTime { get; set; } = true;
|
||
|
||
protected override Task OnFirstAfterRenderAsync()
|
||
{
|
||
base.OnFirstAfterRenderAsync();
|
||
FirstTime = false;
|
||
return Task.CompletedTask;
|
||
}
|
||
|
||
/// <summary>
|
||
/// After Press keyUP, if a key is prefix, to popup the suggestion
|
||
/// </summary>
|
||
/// <param name="args"></param>
|
||
/// <returns></returns>
|
||
private async Task OnKeyUp(KeyboardEventArgs args)
|
||
{
|
||
if (args == null) return;
|
||
if (Prefix.Contains(args.Key, StringComparison.Ordinal))
|
||
{
|
||
await SetDropdownStyle();
|
||
ShowSuggestions = Prefix.Contains(args.Key, StringComparison.Ordinal);
|
||
await InvokeStateHasChangedAsync();
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(Value))
|
||
{
|
||
var suggestions = this.Value.Split(Split);
|
||
}
|
||
|
||
await ValueChange.InvokeAsync(this.Value);
|
||
}
|
||
|
||
private async Task OnKeyDown(KeyboardEventArgs args)
|
||
{
|
||
await InvokeStateHasChangedAsync();
|
||
}
|
||
|
||
private DotNetObjectReference<Mentions> _reference;
|
||
private const string ReferenceName = "mentions";
|
||
|
||
protected async Task SetDropdownStyle()
|
||
{
|
||
if (_reference == null)
|
||
{
|
||
_reference = DotNetObjectReference.Create<Mentions>(this);
|
||
}
|
||
//get current dom element infomation
|
||
var domRect = await JsInvokeAsync<double[]>(JSInteropConstants.GetCursorXY, Ref, _reference);
|
||
|
||
var left = Math.Round(domRect[0]);
|
||
var top = Math.Round(domRect[1]);
|
||
//DropdownStyle = $"display:inline-flex;position:fixed;top:{top}px;left:{left}px;transform:translate({cursorPoint.x}px, {cursorPoint.y}0px);";
|
||
DropdownStyle = $"display:inline-flex;position:fixed;top:{top}px;left:{left}px;transform:translate(0px, 0px);";
|
||
}
|
||
|
||
/// <summary>
|
||
/// open or close the list of Suggestion
|
||
/// </summary>
|
||
/// <param name="show"></param>
|
||
/// <returns></returns>
|
||
internal async Task ShowSuggestion(bool show)
|
||
{
|
||
ShowSuggestions = show;
|
||
await InvokeStateHasChangedAsync();
|
||
}
|
||
|
||
internal async Task GetSuggestion()
|
||
{
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="opt"></param>
|
||
/// <returns></returns>
|
||
internal async Task OnOptionClick(MentionsOption opt)
|
||
{
|
||
// update to status of all of suggestion to un-selected state
|
||
foreach (var item in LstOriginalOptions)
|
||
{
|
||
item.Selected = false;
|
||
}
|
||
|
||
// when the suggestion clicked is not null and enable, then change the value of textarea.
|
||
if (opt != null && !opt.Disable)
|
||
{
|
||
if (string.IsNullOrEmpty(this.Value))
|
||
{
|
||
this.Value = opt.Value + this.Split;
|
||
}
|
||
else
|
||
{
|
||
this.Value = this.Value + opt.Value + this.Split;
|
||
}
|
||
}
|
||
|
||
ShowSuggestions = false;
|
||
|
||
await InvokeStateHasChangedAsync();
|
||
}
|
||
|
||
private void OnKeyPress(KeyboardEventArgs args)
|
||
{
|
||
Console.WriteLine(args.Key);
|
||
|
||
if (args == null) return;
|
||
if (ValueChange.HasDelegate)
|
||
ValueChange.InvokeAsync(args.Code);
|
||
|
||
return;
|
||
}
|
||
|
||
protected override Task OnParametersSetAsync()
|
||
{
|
||
return base.OnParametersSetAsync();
|
||
}
|
||
|
||
/// <summary>
|
||
/// return a new list of mentionsOption, when all item included the specificed text
|
||
/// </summary>
|
||
/// <param name="textValue"></param>
|
||
/// <returns></returns>
|
||
private List<MentionsOption> IsIncluded(string textValue)
|
||
{
|
||
if (string.IsNullOrEmpty(textValue))
|
||
{
|
||
return LstOriginalOptions;
|
||
}
|
||
|
||
List<MentionsOption> lst = new List<MentionsOption>();
|
||
foreach (var item in LstOriginalOptions)
|
||
{
|
||
if (item.Value.Contains(textValue, StringComparison.Ordinal))
|
||
{
|
||
lst.Add(item);
|
||
}
|
||
}
|
||
return lst;
|
||
}
|
||
|
||
public void RemoveOption(MentionsOption option)
|
||
{
|
||
LstOriginalOptions.Remove(option);
|
||
}
|
||
|
||
public void AddOption(MentionsOption option)
|
||
{
|
||
if (option == null) return;
|
||
var opt = LstOriginalOptions.Find(x => x.Value == option.Value);
|
||
if (opt == null)
|
||
{
|
||
LstOriginalOptions.Add(option);
|
||
}
|
||
}
|
||
|
||
internal async void Onfocus(FocusEventArgs args)
|
||
{
|
||
if (args == null) return;
|
||
|
||
Focused = true;
|
||
if (OnFocus.HasDelegate)
|
||
await OnFocus.InvokeAsync(args);
|
||
|
||
await FocusAsync(Ref);
|
||
StateHasChanged();
|
||
}
|
||
|
||
internal async void Onblur(FocusEventArgs args)
|
||
{
|
||
if (args == null) return;
|
||
Focused = false;
|
||
if (OnBlur.HasDelegate)
|
||
await OnBlur.InvokeAsync(args);
|
||
await JsInvokeAsync(JSInteropConstants.Blur, Ref);
|
||
StateHasChanged();
|
||
}
|
||
|
||
[JSInvokable]
|
||
public void CloseMentionsDropDown()
|
||
{
|
||
ShowSuggestions = false;
|
||
StateHasChanged();
|
||
}
|
||
|
||
protected override void Dispose(bool disposing)
|
||
{
|
||
_reference = null;
|
||
_ = JsInvokeAsync(JSInteropConstants.DisposeObj, ReferenceName);
|
||
base.Dispose(disposing);
|
||
}
|
||
}
|
||
}
|