-
-
Notifications
You must be signed in to change notification settings - Fork 267
Apply Butil improvements (#12393) #12419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
msynk
wants to merge
12
commits into
bitfoundation:develop
Choose a base branch
from
msynk:12393-butil-improvements
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
086d490
apply Butil improvements
msynk 452dfc7
resolve review comments
msynk a005bf3
Merge branch 'develop' into 12393-butil-improvements
msynk 24850e9
improve page titles
msynk 8ef7bcc
resolve review comments II
msynk 98b719a
resolve review comments III
msynk 903cc89
add missing demos
msynk 323520e
resolve review comments IV
msynk 73f0f2e
resolve local review comments
msynk 353e8e8
resolve local review findings
msynk d7451e6
Merge branch 'develop' into 12393-butil-improvements
msynk 686e236
resolve local review findings II
msynk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
src/Butil/Bit.Butil/Internals/BroadcastChannel/BroadcastChannelListenersManager.cs
This file contains hidden or 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,40 @@ | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using Microsoft.JSInterop; | ||
|
|
||
| namespace Bit.Butil; | ||
|
|
||
| public static class BroadcastChannelListenersManager | ||
| { | ||
| internal const string MessageMethodName = "InvokeBroadcastChannelMessage"; | ||
| internal const string ErrorMethodName = "InvokeBroadcastChannelError"; | ||
|
|
||
| private static readonly ConcurrentDictionary<Guid, Listener> Listeners = []; | ||
|
|
||
| internal static Guid AddListener(Action<System.Text.Json.JsonElement>? onMessage, Action? onError) | ||
| { | ||
| var id = Guid.NewGuid(); | ||
| Listeners.TryAdd(id, new Listener { OnMessage = onMessage, OnError = onError }); | ||
| return id; | ||
| } | ||
|
|
||
| internal static void RemoveListener(Guid id) => Listeners.TryRemove(id, out _); | ||
|
|
||
| [JSInvokable(MessageMethodName)] | ||
| public static void InvokeMessage(Guid id, System.Text.Json.JsonElement data) | ||
| { | ||
| if (Listeners.TryGetValue(id, out var listener)) listener.OnMessage?.Invoke(data); | ||
| } | ||
|
|
||
| [JSInvokable(ErrorMethodName)] | ||
| public static void InvokeError(Guid id) | ||
| { | ||
| if (Listeners.TryGetValue(id, out var listener)) listener.OnError?.Invoke(); | ||
| } | ||
|
|
||
| private class Listener | ||
| { | ||
| public Action<System.Text.Json.JsonElement>? OnMessage { get; set; } | ||
| public Action? OnError { get; set; } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Butil/Bit.Butil/Internals/Events/DomClipboardEventListenersManager.cs
This file contains hidden or 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,44 @@ | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Linq; | ||
| using Microsoft.JSInterop; | ||
|
|
||
| namespace Bit.Butil; | ||
|
|
||
| public static class DomClipboardEventListenersManager | ||
| { | ||
| internal const string InvokeMethodName = "InvokeClipboardEvent"; | ||
|
|
||
| private static readonly ConcurrentDictionary<Guid, Listener> Listeners = []; | ||
|
|
||
| internal static Guid SetListener(Action<ButilClipboardEventArgs> action, string element, object options) | ||
| { | ||
| var id = Guid.NewGuid(); | ||
| Listeners.TryAdd(id, new Listener { Action = action, Element = element, Options = options }); | ||
| return id; | ||
| } | ||
|
|
||
| internal static Guid[] RemoveListener(Action<ButilClipboardEventArgs> action, string element, object options) | ||
| { | ||
| var toRemove = Listeners | ||
| .Where(l => l.Value.Action == action && l.Value.Element == element && l.Value.Options == options) | ||
| .ToArray(); | ||
|
|
||
| return toRemove.Select(l => { Listeners.TryRemove(l.Key, out _); return l.Key; }).ToArray(); | ||
| } | ||
| internal static void RemoveById(Guid id) => Listeners.TryRemove(id, out _); | ||
|
|
||
|
|
||
| [JSInvokable(InvokeMethodName)] | ||
| public static void Invoke(Guid id, ButilClipboardEventArgs args) | ||
| { | ||
| if (Listeners.TryGetValue(id, out var listener)) listener.Action.Invoke(args); | ||
| } | ||
|
|
||
| private class Listener | ||
| { | ||
| public string Element { get; set; } = string.Empty; | ||
| public object Options { get; set; } = default!; | ||
| public Action<ButilClipboardEventArgs> Action { get; set; } = default!; | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Butil/Bit.Butil/Internals/Events/DomCompositionEventListenersManager.cs
This file contains hidden or 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,44 @@ | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Linq; | ||
| using Microsoft.JSInterop; | ||
|
|
||
| namespace Bit.Butil; | ||
|
|
||
| public static class DomCompositionEventListenersManager | ||
| { | ||
| internal const string InvokeMethodName = "InvokeCompositionEvent"; | ||
|
|
||
| private static readonly ConcurrentDictionary<Guid, Listener> Listeners = []; | ||
|
|
||
| internal static Guid SetListener(Action<ButilCompositionEventArgs> action, string element, object options) | ||
| { | ||
| var id = Guid.NewGuid(); | ||
| Listeners.TryAdd(id, new Listener { Action = action, Element = element, Options = options }); | ||
| return id; | ||
| } | ||
|
|
||
| internal static Guid[] RemoveListener(Action<ButilCompositionEventArgs> action, string element, object options) | ||
| { | ||
| var toRemove = Listeners | ||
| .Where(l => l.Value.Action == action && l.Value.Element == element && l.Value.Options == options) | ||
| .ToArray(); | ||
|
|
||
| return toRemove.Select(l => { Listeners.TryRemove(l.Key, out _); return l.Key; }).ToArray(); | ||
| } | ||
| internal static void RemoveById(Guid id) => Listeners.TryRemove(id, out _); | ||
|
|
||
|
|
||
| [JSInvokable(InvokeMethodName)] | ||
| public static void Invoke(Guid id, ButilCompositionEventArgs args) | ||
| { | ||
| if (Listeners.TryGetValue(id, out var listener)) listener.Action.Invoke(args); | ||
| } | ||
|
|
||
| private class Listener | ||
| { | ||
| public string Element { get; set; } = string.Empty; | ||
| public object Options { get; set; } = default!; | ||
| public Action<ButilCompositionEventArgs> Action { get; set; } = default!; | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Butil/Bit.Butil/Internals/Events/DomDragEventListenersManager.cs
This file contains hidden or 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,44 @@ | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Linq; | ||
| using Microsoft.JSInterop; | ||
|
|
||
| namespace Bit.Butil; | ||
|
|
||
| public static class DomDragEventListenersManager | ||
| { | ||
| internal const string InvokeMethodName = "InvokeDragEvent"; | ||
|
|
||
| private static readonly ConcurrentDictionary<Guid, Listener> Listeners = []; | ||
|
|
||
| internal static Guid SetListener(Action<ButilDragEventArgs> action, string element, object options) | ||
| { | ||
| var id = Guid.NewGuid(); | ||
| Listeners.TryAdd(id, new Listener { Action = action, Element = element, Options = options }); | ||
| return id; | ||
| } | ||
|
|
||
| internal static Guid[] RemoveListener(Action<ButilDragEventArgs> action, string element, object options) | ||
| { | ||
| var toRemove = Listeners | ||
| .Where(l => l.Value.Action == action && l.Value.Element == element && l.Value.Options == options) | ||
| .ToArray(); | ||
|
|
||
| return toRemove.Select(l => { Listeners.TryRemove(l.Key, out _); return l.Key; }).ToArray(); | ||
| } | ||
| internal static void RemoveById(Guid id) => Listeners.TryRemove(id, out _); | ||
|
|
||
|
|
||
| [JSInvokable(InvokeMethodName)] | ||
| public static void Invoke(Guid id, ButilDragEventArgs args) | ||
| { | ||
| if (Listeners.TryGetValue(id, out var listener)) listener.Action.Invoke(args); | ||
| } | ||
|
|
||
| private class Listener | ||
| { | ||
| public string Element { get; set; } = string.Empty; | ||
| public object Options { get; set; } = default!; | ||
| public Action<ButilDragEventArgs> Action { get; set; } = default!; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.