-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from Jcparkyn/dev
Allow inline editing of the Output regex
- Loading branch information
Showing
11 changed files
with
316 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@inject IJSRuntime JS; | ||
|
||
<div @ref="divElement" | ||
class="@CssClass"></div> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public string Text { get; set; } | ||
|
||
[Parameter] | ||
public string CssClass { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<string> TextChanged { get; set; } | ||
|
||
ElementReference divElement; | ||
|
||
protected string textToDisplay; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
//Text = Text.Replace(Environment.NewLine, "<br />"); | ||
} | ||
|
||
//send initial text (if any) to javascript to place in the div | ||
protected override async Task OnAfterRenderAsync(bool firstRender) | ||
{ | ||
if (firstRender) | ||
{ | ||
await JS.InvokeVoidAsync("contentEditable.initContentEditable", divElement, DotNetObjectReference.Create(this), Text); | ||
} | ||
} | ||
|
||
//receive input text from javascript and invoke callback to parent component | ||
[JSInvokable] | ||
public async Task GetUpdatedTextFromJavascript(string textFromJavascript) | ||
{ | ||
Text = textFromJavascript; | ||
await TextChanged.InvokeAsync(textFromJavascript); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
<div @onkeypress="OnKeyPress" | ||
@onkeyup="OnKeyUp"> | ||
<ContentEditableDiv @bind-Text="expression" | ||
CssClass="output-regex-text"/> | ||
<div class="output-edit-prompt"> | ||
Input your own regular expression here to convert it to a node tree.<br /> | ||
<button @onclick="Submit">Confirm (Enter)</button> | ||
<button @onclick="Cancel">Cancel</button> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
|
||
string expression; | ||
|
||
[Parameter] public string StartExpression | ||
{ | ||
set => expression = value; | ||
} | ||
|
||
[Parameter] public EventCallback<string> OnSubmitted { get; set; } | ||
[Parameter] public EventCallback OnCanceled { get; set; } | ||
|
||
protected async Task OnKeyPress(KeyboardEventArgs e) | ||
{ | ||
if(e.Key == "Enter" && !e.ShiftKey) | ||
{ | ||
await Submit(); | ||
} | ||
} | ||
|
||
protected async Task OnKeyUp(KeyboardEventArgs e) | ||
{ | ||
if (e.Key == "Escape") | ||
{ | ||
await Cancel(); | ||
} | ||
} | ||
|
||
protected async Task Submit() | ||
{ | ||
await OnSubmitted.InvokeAsync(expression); | ||
} | ||
|
||
protected async Task Cancel() | ||
{ | ||
await OnCanceled.InvokeAsync(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@if (!string.IsNullOrEmpty(Info)) | ||
{ | ||
@Info | ||
} | ||
<button class="toast-button" @onclick="OnButtonClicked" disabled="@hasBeenPressed">@ButtonText</button> | ||
|
||
@code { | ||
[Parameter] public Action OnClick { get; set; } | ||
[Parameter] public string ButtonText { get; set; } | ||
[Parameter] public string Info { get; set; } | ||
|
||
private bool hasBeenPressed = false; | ||
|
||
private void OnButtonClicked() | ||
{ | ||
hasBeenPressed = true; | ||
OnClick?.Invoke(); | ||
} | ||
|
||
public static RenderFragment GetRenderFragment(Action onClick, string buttonText, string info = null) | ||
=> @<ToastButton OnClick="@onClick" ButtonText="@buttonText" Info="@info"/>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.