feat: Kh component library, record pages and profile security (M3, part 2)
Adds the building blocks every later screen uses, so modules are built from one set of components instead of ad hoc markup: - Form components (KhForm, KhTextBox, KhNumberBox, KhDateBox, KhSelect, KhCheck, KhSwitch, KhHotlink) with Italian number and date input, inline calculation (=10*3), field messages plus a summary that focuses the field, and service errors added by field name. - Display and window components (panels, tiles, badges, chips, money, tabs with Alt+1..9, steps, dialog, side drawer and DrawerService). - KhIconToolbar that keeps one line and moves less used commands into the "..." menu, KhDocHead, and the RecordPage/DocumentPage/MasterDataPage bases with standard commands, shortcuts and save/cancel/delete flow (#27, #29). - Development-only component catalog and sample document page. - Profile: personal data, password change that ends other sessions, TOTP enable/disable and recovery codes through ProfileService (#31). Refs #27 #29 #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf6f849cc1
commit
d958e7372d
57 files changed
+5249
-12
No files matched your search
@@ -106,3 +106,53 @@ public sealed class DialogService
|
||||
pending?.TrySetResult(confirmed);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A side panel opened from code (SPEC §10.7 <c>DrawerService</c>).</summary>
|
||||
/// <param name="Title">The title.</param>
|
||||
/// <param name="Icon">The icon.</param>
|
||||
/// <param name="Content">The content.</param>
|
||||
/// <param name="Footer">The buttons, or <see langword="null"/>.</param>
|
||||
/// <param name="Wide">A wider panel.</param>
|
||||
public sealed record DrawerRequest(string Title, string? Icon, Microsoft.AspNetCore.Components.RenderFragment Content,
|
||||
Microsoft.AspNetCore.Components.RenderFragment? Footer = null, bool Wide = false);
|
||||
|
||||
/// <summary>
|
||||
/// Opens one side panel at a time from code; <c>KhDrawerHost</c> in the layout shows it. A page that owns its panel
|
||||
/// can also write <c><KhDrawer Open="..."></c> directly.
|
||||
/// </summary>
|
||||
public sealed class DrawerService
|
||||
{
|
||||
private TaskCompletionSource? _closed;
|
||||
|
||||
/// <summary>Raised when the panel opens, closes or must be drawn again.</summary>
|
||||
public event Action? Changed;
|
||||
|
||||
/// <summary>The panel shown, or <see langword="null"/>.</summary>
|
||||
public DrawerRequest? Current { get; private set; }
|
||||
|
||||
/// <summary>Shows a panel, closing the previous one.</summary>
|
||||
/// <param name="request">The panel.</param>
|
||||
/// <returns>A task that ends when the panel is closed.</returns>
|
||||
public Task ShowAsync(DrawerRequest request)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
_closed?.TrySetResult();
|
||||
_closed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
Current = request;
|
||||
Changed?.Invoke();
|
||||
return _closed.Task;
|
||||
}
|
||||
|
||||
/// <summary>Closes the panel.</summary>
|
||||
public void Close()
|
||||
{
|
||||
var closed = _closed;
|
||||
_closed = null;
|
||||
Current = null;
|
||||
Changed?.Invoke();
|
||||
closed?.TrySetResult();
|
||||
}
|
||||
|
||||
/// <summary>Draws the panel again after its data changed.</summary>
|
||||
public void Refresh() => Changed?.Invoke();
|
||||
}
|
||||
@@ -17,7 +17,11 @@ public enum ShortcutScope
|
||||
/// <param name="Keys">The combinations, as the browser script writes them (<c>Ctrl+S</c>, <c>F9</c>, <c>Alt+W</c>).</param>
|
||||
/// <param name="TextKey">The text key of the description.</param>
|
||||
/// <param name="Scope">Who handles it.</param>
|
||||
public sealed record Shortcut(string Id, IReadOnlyList<string> Keys, string TextKey, ShortcutScope Scope);
|
||||
public sealed record Shortcut(string Id, IReadOnlyList<string> Keys, string TextKey, ShortcutScope Scope)
|
||||
{
|
||||
/// <summary>How the keys are shown when they are a series (<c>Alt+1...9</c>); <see langword="null"/> shows <see cref="Keys"/>.</summary>
|
||||
public string? Display { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The shortcut table of SPEC §10.5.7. Browsers keep some combinations for themselves (Ctrl+W, Ctrl+Tab, Ctrl+N
|
||||
@@ -75,6 +79,9 @@ public static class KeyboardShortcuts
|
||||
|
||||
/// <summary>Delete.</summary>
|
||||
public const string Delete = "page.delete";
|
||||
|
||||
/// <summary>Alt+1..9: the tab of the page by position; the page receives <c>page.tab.N</c>.</summary>
|
||||
public const string PageTab = "page.tab";
|
||||
}
|
||||
|
||||
/// <summary>The table.</summary>
|
||||
@@ -95,6 +102,10 @@ public static class KeyboardShortcuts
|
||||
new(Commands.PreviousRecord, ["Ctrl+ArrowUp"], "Shell.Shortcuts.PreviousRecord", ShortcutScope.Page),
|
||||
new(Commands.NextRecord, ["Ctrl+ArrowDown"], "Shell.Shortcuts.NextRecord", ShortcutScope.Page),
|
||||
new(Commands.Balance, ["Ctrl+D"], "Shell.Shortcuts.Balance", ShortcutScope.Page),
|
||||
new(Commands.PageTab, [.. Enumerable.Range(1, 9).Select(n => "Alt+" + n.ToString(System.Globalization.CultureInfo.InvariantCulture))], "Shell.Shortcuts.PageTab", ShortcutScope.Page)
|
||||
{
|
||||
Display = "Alt+1...9",
|
||||
},
|
||||
];
|
||||
|
||||
/// <summary>The shortcut of a command.</summary>
|
||||
@@ -102,10 +113,32 @@ public static class KeyboardShortcuts
|
||||
/// <returns>The shortcut, or <see langword="null"/>.</returns>
|
||||
public static Shortcut? Find(string id) => All.FirstOrDefault(s => s.Id == id);
|
||||
|
||||
/// <summary>Reads the tab number of a <c>page.tab.N</c> command.</summary>
|
||||
/// <param name="command">The command received.</param>
|
||||
/// <param name="number">The tab number, 1 to 9.</param>
|
||||
/// <returns>Whether the command picks a tab.</returns>
|
||||
public static bool TryGetTabNumber(string command, out int number)
|
||||
{
|
||||
number = 0;
|
||||
return command is not null && command.StartsWith(Commands.PageTab + ".", StringComparison.Ordinal)
|
||||
&& int.TryParse(command.AsSpan(Commands.PageTab.Length + 1), System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out number)
|
||||
&& number is >= 1 and <= 9;
|
||||
}
|
||||
|
||||
/// <summary>The first combination of a command, for tooltips (<c>Ctrl+S</c>).</summary>
|
||||
/// <param name="id">The command.</param>
|
||||
/// <returns>The combination, or an empty string.</returns>
|
||||
public static string KeysOf(string id) => Find(id)?.Keys[0] ?? string.Empty;
|
||||
|
||||
/// <summary>A combination as shown to people: arrows as symbols, <c>Escape</c> as <c>Esc</c>.</summary>
|
||||
/// <param name="combo">The combination, as in <see cref="Shortcut.Keys"/>.</param>
|
||||
/// <returns>The text to show.</returns>
|
||||
public static string Pretty(string? combo) => combo is null ? string.Empty : combo
|
||||
.Replace("ArrowUp", "↑", StringComparison.Ordinal)
|
||||
.Replace("ArrowDown", "↓", StringComparison.Ordinal)
|
||||
.Replace("ArrowLeft", "←", StringComparison.Ordinal)
|
||||
.Replace("ArrowRight", "→", StringComparison.Ordinal)
|
||||
.Replace("Escape", "Esc", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,7 +180,9 @@ public sealed class KeyboardShortcutService(IJSRuntime js) : IAsyncDisposable
|
||||
var handler = shortcut.Scope == ShortcutScope.Shell ? ShellPressed : PagePressed;
|
||||
if (handler is not null)
|
||||
{
|
||||
await handler(shortcut.Id).ConfigureAwait(false);
|
||||
// The tab shortcuts tell the page which tab: page.tab.3 for Alt+3.
|
||||
var command = shortcut.Id == KeyboardShortcuts.Commands.PageTab ? shortcut.Id + "." + combo[^1] : shortcut.Id;
|
||||
await handler(command).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,17 @@ public sealed class ShellSession(
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>Shows a new name in the shell after the user changed it from the profile.</summary>
|
||||
/// <param name="displayName">The new name.</param>
|
||||
public void SetDisplayName(string? displayName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(displayName) && displayName != DisplayName)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Changed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Saves one setting of the user (open tabs, layouts...).</summary>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="value">The value, or <see langword="null"/> to remove it.</param>
|
||||
|
||||
@@ -33,6 +33,9 @@ public sealed class KhTab
|
||||
/// <summary>The icon set by the page; <see langword="null"/> uses the menu icon.</summary>
|
||||
public string? Icon { get; private set; }
|
||||
|
||||
/// <summary>Whether the tab is the one shown: page shortcuts act only there.</summary>
|
||||
public bool IsActive => ReferenceEquals(_owner.Active, this);
|
||||
|
||||
/// <summary>Whether the page has unsaved changes (orange dot, warning on close).</summary>
|
||||
public bool IsModified { get; private set; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user