Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
AddEdit dynamic field structure scaffolding (#1404)
Leendert de Borstfd7ab980072a
diff --git a/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor b/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razornew file mode 100644index 000000000..c6bf2a02f--- /dev/null+++ b/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor@@ -0,0 +1,283 @@+@using AliasClientDb.Models+@using Microsoft.Extensions.Localization++@inject IStringLocalizerFactory LocalizerFactory++<div class="relative">+ <button type="button"+ @onclick="ToggleMenu"+ @onclick:preventDefault="true"+ class="w-full px-4 py-2 border-2 border-dashed border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-400 rounded-md hover:border-primary-500 hover:text-primary-600 dark:hover:text-primary-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 transition-colors flex items-center justify-center gap-2">+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />+ </svg>+ </button>++ @if (IsOpen)+ {+ <div class="fixed inset-0 z-10 bg-black bg-opacity-50" @onclick="CloseMenu"></div>+ <div class="absolute bottom-full left-0 right-0 mb-1 z-20 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg overflow-hidden max-h-64 overflow-y-auto">+ @* Optional system fields that are not currently visible *@+ @foreach (var field in OptionalSystemFields.Where(f => !VisibleFieldKeys.Contains(f.FieldKey)))+ {+ <button type="button"+ @onclick="() => HandleAddSystemField(field.FieldKey)"+ @onclick:preventDefault="true"+ class="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300">+ <span class="text-gray-500 dark:text-gray-400">+ @GetFieldIcon(field.Category)+ </span>+ <span>@GetFieldLabel(field.FieldKey)</span>+ </button>+ }++ @* Optional sections (2FA, Attachments) *@+ @if (!Show2FA && HasLoginFields)+ {+ <button type="button"+ @onclick="HandleAdd2FA"+ @onclick:preventDefault="true"+ class="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300">+ <span class="text-gray-500 dark:text-gray-400">+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />+ </svg>+ </span>+ <span>@Localizer["TwoFactorAuthentication"]</span>+ </button>+ }++ @if (!ShowAttachments)+ {+ <button type="button"+ @onclick="HandleAddAttachments"+ @onclick:preventDefault="true"+ class="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300">+ <span class="text-gray-500 dark:text-gray-400">+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" />+ </svg>+ </span>+ <span>@Localizer["Attachments"]</span>+ </button>+ }++ @* Custom field option - always available *@+ <button type="button"+ @onclick="OpenCustomFieldModal"+ @onclick:preventDefault="true"+ class="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300">+ <span class="text-gray-500 dark:text-gray-400">+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />+ </svg>+ </span>+ <span>@Localizer["AddCustomField"]</span>+ </button>+ </div>+ }+</div>++@* Custom Field Modal *@+@if (ShowCustomFieldModal)+{+ <div class="fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full mx-4">+ <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700">+ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">@Localizer["AddCustomField"]</h3>+ </div>+ <div class="px-6 py-4 space-y-4">+ <div>+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ @Localizer["FieldLabel"]+ </label>+ <input type="text"+ @bind="CustomFieldLabel"+ class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"+ placeholder="@Localizer["EnterFieldName"]" />+ </div>+ <div>+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ @Localizer["FieldType"]+ </label>+ <select @bind="CustomFieldType"+ class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white">+ <option value="Text">@Localizer["FieldTypeText"]</option>+ <option value="Hidden">@Localizer["FieldTypeHidden"]</option>+ <option value="Email">@Localizer["FieldTypeEmail"]</option>+ <option value="URL">@Localizer["FieldTypeUrl"]</option>+ <option value="Phone">@Localizer["FieldTypePhone"]</option>+ <option value="Number">@Localizer["FieldTypeNumber"]</option>+ <option value="Date">@Localizer["FieldTypeDate"]</option>+ <option value="TextArea">@Localizer["FieldTypeTextArea"]</option>+ </select>+ </div>+ </div>+ <div class="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex gap-3">+ <button type="button"+ @onclick="HandleAddCustomField"+ @onclick:preventDefault="true"+ disabled="@string.IsNullOrWhiteSpace(CustomFieldLabel)"+ class="flex-1 px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed">+ @Localizer["Add"]+ </button>+ <button type="button"+ @onclick="CloseCustomFieldModal"+ @onclick:preventDefault="true"+ class="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500">+ @Localizer["Cancel"]+ </button>+ </div>+ </div>+ </div>+}++@code {+ private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Items.AddFieldMenu", "AliasVault.Client");++ /// <summary>+ /// Optional system fields for the current item type.+ /// </summary>+ [Parameter]+ public IEnumerable<SystemFieldDefinition> OptionalSystemFields { get; set; } = [];++ /// <summary>+ /// Field keys that are currently visible.+ /// </summary>+ [Parameter]+ public HashSet<string> VisibleFieldKeys { get; set; } = [];++ /// <summary>+ /// Whether the 2FA section is currently visible.+ /// </summary>+ [Parameter]+ public bool Show2FA { get; set; }++ /// <summary>+ /// Whether the attachments section is currently visible.+ /// </summary>+ [Parameter]+ public bool ShowAttachments { get; set; }++ /// <summary>+ /// Whether the current item type has login fields (determines if 2FA option is shown).+ /// </summary>+ [Parameter]+ public bool HasLoginFields { get; set; }++ /// <summary>+ /// Callback when a system field is added.+ /// </summary>+ [Parameter]+ public EventCallback<string> OnAddSystemField { get; set; }++ /// <summary>+ /// Callback when a custom field is added. Parameters: (label, fieldType).+ /// </summary>+ [Parameter]+ public EventCallback<(string Label, string FieldType)> OnAddCustomField { get; set; }++ /// <summary>+ /// Callback when 2FA section is added.+ /// </summary>+ [Parameter]+ public EventCallback OnAdd2FA { get; set; }++ /// <summary>+ /// Callback when attachments section is added.+ /// </summary>+ [Parameter]+ public EventCallback OnAddAttachments { get; set; }++ private bool IsOpen { get; set; }+ private bool ShowCustomFieldModal { get; set; }+ private string CustomFieldLabel { get; set; } = string.Empty;+ private string CustomFieldType { get; set; } = "Text";++ private void ToggleMenu()+ {+ IsOpen = !IsOpen;+ }++ private void CloseMenu()+ {+ IsOpen = false;+ }++ private async Task HandleAddSystemField(string fieldKey)+ {+ await OnAddSystemField.InvokeAsync(fieldKey);+ CloseMenu();+ }++ private async Task HandleAdd2FA()+ {+ await OnAdd2FA.InvokeAsync();+ CloseMenu();+ }++ private async Task HandleAddAttachments()+ {+ await OnAddAttachments.InvokeAsync();+ CloseMenu();+ }++ private void OpenCustomFieldModal()+ {+ ShowCustomFieldModal = true;+ CustomFieldLabel = string.Empty;+ CustomFieldType = "Text";+ CloseMenu();+ }++ private void CloseCustomFieldModal()+ {+ ShowCustomFieldModal = false;+ CustomFieldLabel = string.Empty;+ CustomFieldType = "Text";+ }++ private async Task HandleAddCustomField()+ {+ if (!string.IsNullOrWhiteSpace(CustomFieldLabel))+ {+ await OnAddCustomField.InvokeAsync((CustomFieldLabel.Trim(), CustomFieldType));+ CloseCustomFieldModal();+ }+ }++ private string GetFieldLabel(string fieldKey)+ {+ // Map field keys to localized labels+ return fieldKey switch+ {+ FieldKey.LoginUsername => Localizer["FieldLoginUsername"],+ FieldKey.LoginPassword => Localizer["FieldLoginPassword"],+ FieldKey.LoginEmail => Localizer["FieldLoginEmail"],+ FieldKey.LoginUrl => Localizer["FieldLoginUrl"],+ FieldKey.AliasFirstName => Localizer["FieldAliasFirstName"],+ FieldKey.AliasLastName => Localizer["FieldAliasLastName"],+ FieldKey.AliasGender => Localizer["FieldAliasGender"],+ FieldKey.AliasBirthdate => Localizer["FieldAliasBirthdate"],+ FieldKey.CardNumber => Localizer["FieldCardNumber"],+ FieldKey.CardCardholderName => Localizer["FieldCardCardholderName"],+ FieldKey.CardExpiryMonth => Localizer["FieldCardExpiryMonth"],+ FieldKey.CardExpiryYear => Localizer["FieldCardExpiryYear"],+ FieldKey.CardCvv => Localizer["FieldCardCvv"],+ FieldKey.CardPin => Localizer["FieldCardPin"],+ FieldKey.NotesContent => Localizer["FieldNotesContent"],+ _ => fieldKey+ };+ }++ private static MarkupString GetFieldIcon(FieldCategory category)+ {+ var svg = category switch+ {+ FieldCategory.Notes => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>""",+ FieldCategory.Card => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" /></svg>""",+ _ => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" /></svg>"""+ };+ return new MarkupString(svg);+ }+}diff --git a/apps/server/AliasVault.Client/Main/Components/Items/ItemTypeSelector.razor b/apps/server/AliasVault.Client/Main/Components/Items/ItemTypeSelector.razornew file mode 100644index 000000000..98ee97574--- /dev/null+++ b/apps/server/AliasVault.Client/Main/Components/Items/ItemTypeSelector.razor@@ -0,0 +1,158 @@+@using AliasVault.Client.Main.Models+@using Microsoft.Extensions.Localization++@inject IStringLocalizerFactory LocalizerFactory++<div class="relative mb-4">+ <div class="w-full px-4 py-3 bg-primary-50 dark:bg-primary-900/20 border border-primary-200 dark:border-primary-800 rounded-lg flex items-center gap-2">+ <button type="button"+ @onclick="ToggleDropdown"+ @onclick:preventDefault="true"+ class="flex-1 flex items-center justify-between hover:opacity-80 transition-opacity">+ <div class="flex items-center gap-2">+ <span class="text-primary-600 dark:text-primary-400">+ @GetTypeIcon(SelectedType)+ </span>+ <span class="text-primary-700 dark:text-primary-300 font-medium text-sm">+ @(IsEditMode ? Localizer["Editing"] : Localizer["Creating"]) @GetTypeDisplayName(SelectedType)+ </span>+ </div>+ <svg class="w-4 h-4 text-primary-500 transition-transform @(ShowDropdown ? "rotate-180" : "")"+ fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />+ </svg>+ </button>+ @if (SelectedType == ItemTypes.Alias && !IsEditMode && OnRegenerateAlias.HasDelegate)+ {+ <button type="button"+ @onclick="HandleRegenerate"+ @onclick:preventDefault="true"+ class="flex-shrink-0 p-1.5 text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/40 rounded transition-colors"+ title="@Localizer["RegenerateAlias"]">+ <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M23 4v6h-6"/>+ <path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>+ </svg>+ </button>+ }+ </div>++ @if (ShowDropdown)+ {+ <div class="fixed inset-0 z-10" @onclick="CloseDropdown"></div>+ <div class="absolute z-20 mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg overflow-hidden">+ @foreach (var itemType in ItemTypes.All)+ {+ <button type="button"+ @onclick="() => SelectType(itemType)"+ @onclick:preventDefault="true"+ class="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 @(SelectedType == itemType ? "bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300" : "text-gray-900 dark:text-white")">+ <span class="@(SelectedType == itemType ? "text-primary-600 dark:text-primary-400" : "text-gray-500 dark:text-gray-400")">+ @GetTypeIcon(itemType)+ </span>+ <span class="font-medium">+ @GetTypeDisplayName(itemType)+ </span>+ @if (SelectedType == itemType)+ {+ <svg class="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">+ <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />+ </svg>+ }+ </button>+ }+ </div>+ }+</div>++@code {+ private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Items.ItemTypeSelector", "AliasVault.Client");++ /// <summary>+ /// The currently selected item type.+ /// </summary>+ [Parameter]+ public string SelectedType { get; set; } = ItemTypes.Login;++ /// <summary>+ /// Callback when item type changes.+ /// </summary>+ [Parameter]+ public EventCallback<string> SelectedTypeChanged { get; set; }++ /// <summary>+ /// Whether we are in edit mode (disables type switching).+ /// </summary>+ [Parameter]+ public bool IsEditMode { get; set; }++ /// <summary>+ /// Whether the dropdown is currently shown.+ /// </summary>+ [Parameter]+ public bool ShowDropdown { get; set; }++ /// <summary>+ /// Callback when dropdown visibility changes.+ /// </summary>+ [Parameter]+ public EventCallback<bool> ShowDropdownChanged { get; set; }++ /// <summary>+ /// Callback when regenerate alias button is clicked.+ /// </summary>+ [Parameter]+ public EventCallback OnRegenerateAlias { get; set; }++ private async Task ToggleDropdown()+ {+ ShowDropdown = !ShowDropdown;+ await ShowDropdownChanged.InvokeAsync(ShowDropdown);+ }++ private async Task CloseDropdown()+ {+ ShowDropdown = false;+ await ShowDropdownChanged.InvokeAsync(false);+ }++ private async Task SelectType(string itemType)+ {+ if (SelectedType != itemType)+ {+ SelectedType = itemType;+ await SelectedTypeChanged.InvokeAsync(itemType);+ }+ await CloseDropdown();+ }++ private async Task HandleRegenerate()+ {+ await OnRegenerateAlias.InvokeAsync();+ }++ private string GetTypeDisplayName(string itemType)+ {+ return itemType switch+ {+ ItemTypes.Login => Localizer["TypeLogin"],+ ItemTypes.Alias => Localizer["TypeAlias"],+ ItemTypes.CreditCard => Localizer["TypeCreditCard"],+ ItemTypes.Note => Localizer["TypeNote"],+ _ => itemType+ };+ }++ private static MarkupString GetTypeIcon(string itemType)+ {+ var svg = itemType switch+ {+ ItemTypes.Login => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" /></svg>""",+ ItemTypes.Alias => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" /></svg>""",+ ItemTypes.CreditCard => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" /></svg>""",+ ItemTypes.Note => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>""",+ _ => """<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>"""+ };+ return new MarkupString(svg);+ }+}diff --git a/apps/server/AliasVault.Client/Main/Models/CustomFieldEdit.cs b/apps/server/AliasVault.Client/Main/Models/CustomFieldEdit.csnew file mode 100644index 000000000..9a8e71c93--- /dev/null+++ b/apps/server/AliasVault.Client/Main/Models/CustomFieldEdit.cs@@ -0,0 +1,51 @@+//-----------------------------------------------------------------------+// <copyright file="CustomFieldEdit.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Client.Main.Models;++using System;++/// <summary>+/// Model for custom field editing.+/// </summary>+public sealed class CustomFieldEdit+{+ /// <summary>+ /// Gets or sets the field value ID (for existing fields).+ /// </summary>+ public Guid Id { get; set; }++ /// <summary>+ /// Gets or sets the field definition ID.+ /// </summary>+ public Guid FieldDefinitionId { get; set; }++ /// <summary>+ /// Gets or sets the temporary ID for new custom fields (format: custom_{uuid}).+ /// </summary>+ public string? TempId { get; set; }++ /// <summary>+ /// Gets or sets the field label.+ /// </summary>+ public string Label { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the field type.+ /// </summary>+ public string FieldType { get; set; } = "Text";++ /// <summary>+ /// Gets or sets the field value.+ /// </summary>+ public string Value { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets a value indicating whether the field is hidden/masked.+ /// </summary>+ public bool IsHidden { get; set; }+}diff --git a/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs b/apps/server/AliasVault.Client/Main/Models/ItemEdit.csindex 91f96c88a..ee45f6124 100644--- a/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs+++ b/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs@@ -96,6 +96,36 @@ public sealed class ItemEdit[StringDateFormat("yyyy-MM-dd", AllowEmpty = true)]public string AliasBirthDate { get; set; } = string.Empty;+ /// <summary>+ /// Gets or sets the credit card number.+ /// </summary>+ public string CardNumber { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the credit card cardholder name.+ /// </summary>+ public string CardCardholderName { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the credit card expiry month.+ /// </summary>+ public string CardExpiryMonth { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the credit card expiry year.+ /// </summary>+ public string CardExpiryYear { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the credit card CVV.+ /// </summary>+ public string CardCvv { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the credit card PIN.+ /// </summary>+ public string CardPin { get; set; } = string.Empty;+/// <summary>/// Gets or sets the create date./// </summary>@@ -121,6 +151,11 @@ public sealed class ItemEdit/// </summary>public List<Passkey> Passkeys { get; set; } = [];+ /// <summary>+ /// Gets or sets the custom fields.+ /// </summary>+ public List<CustomFieldEdit> CustomFields { get; set; } = [];+/// <summary>/// Creates an ItemEdit instance from an Item entity./// </summary>@@ -130,7 +165,7 @@ public sealed class ItemEdit{var birthDate = ItemService.GetFieldValue(item, FieldKey.AliasBirthdate);- return new ItemEdit+ var edit = new ItemEdit{Id = item.Id,ItemType = item.ItemType,@@ -146,12 +181,34 @@ public sealed class ItemEditAliasLastName = ItemService.GetFieldValue(item, FieldKey.AliasLastName) ?? string.Empty,AliasGender = ItemService.GetFieldValue(item, FieldKey.AliasGender) ?? string.Empty,AliasBirthDate = birthDate ?? string.Empty,+ CardNumber = ItemService.GetFieldValue(item, FieldKey.CardNumber) ?? string.Empty,+ CardCardholderName = ItemService.GetFieldValue(item, FieldKey.CardCardholderName) ?? string.Empty,+ CardExpiryMonth = ItemService.GetFieldValue(item, FieldKey.CardExpiryMonth) ?? string.Empty,+ CardExpiryYear = ItemService.GetFieldValue(item, FieldKey.CardExpiryYear) ?? string.Empty,+ CardCvv = ItemService.GetFieldValue(item, FieldKey.CardCvv) ?? string.Empty,+ CardPin = ItemService.GetFieldValue(item, FieldKey.CardPin) ?? string.Empty,Attachments = item.Attachments.Where(a => !a.IsDeleted).ToList(),TotpCodes = item.TotpCodes.Where(t => !t.IsDeleted).ToList(),Passkeys = item.Passkeys.Where(p => !p.IsDeleted).ToList(),CreateDate = item.CreatedAt,LastUpdate = item.UpdatedAt,};++ // Extract custom fields (non-system fields that have FieldDefinitionId set)+ foreach (var fv in item.FieldValues.Where(f => !f.IsDeleted && f.FieldDefinitionId != null))+ {+ edit.CustomFields.Add(new CustomFieldEdit+ {+ Id = fv.Id,+ FieldDefinitionId = fv.FieldDefinitionId!.Value,+ Label = fv.FieldDefinition?.Label ?? "Custom Field",+ FieldType = fv.FieldDefinition?.FieldType ?? "Text",+ Value = fv.Value ?? string.Empty,+ IsHidden = fv.FieldDefinition?.IsHidden ?? false,+ });+ }++ return edit;}/// <summary>@@ -217,6 +274,179 @@ public sealed class ItemEditItemService.SetFieldValue(item, FieldKey.AliasBirthdate, AliasBirthDate);}+ // Add card fields+ if (!string.IsNullOrEmpty(CardNumber))+ {+ ItemService.SetFieldValue(item, FieldKey.CardNumber, CardNumber);+ }++ if (!string.IsNullOrEmpty(CardCardholderName))+ {+ ItemService.SetFieldValue(item, FieldKey.CardCardholderName, CardCardholderName);+ }++ if (!string.IsNullOrEmpty(CardExpiryMonth))+ {+ ItemService.SetFieldValue(item, FieldKey.CardExpiryMonth, CardExpiryMonth);+ }++ if (!string.IsNullOrEmpty(CardExpiryYear))+ {+ ItemService.SetFieldValue(item, FieldKey.CardExpiryYear, CardExpiryYear);+ }++ if (!string.IsNullOrEmpty(CardCvv))+ {+ ItemService.SetFieldValue(item, FieldKey.CardCvv, CardCvv);+ }++ if (!string.IsNullOrEmpty(CardPin))+ {+ ItemService.SetFieldValue(item, FieldKey.CardPin, CardPin);+ }++ // Add custom fields+ foreach (var customField in CustomFields.Where(cf => !string.IsNullOrEmpty(cf.Value)))+ {+ // For new custom fields (TempId set, FieldDefinitionId is empty), create a new FieldDefinition+ if (customField.FieldDefinitionId == Guid.Empty && !string.IsNullOrEmpty(customField.TempId))+ {+ var now = DateTime.UtcNow;+ var fieldDefinitionId = Guid.NewGuid();+ var fieldDefinition = new FieldDefinition+ {+ Id = fieldDefinitionId,+ FieldType = customField.FieldType,+ Label = customField.Label,+ IsHidden = customField.IsHidden,+ IsMultiValue = false,+ EnableHistory = false,+ Weight = 0,+ CreatedAt = now,+ UpdatedAt = now,+ };++ item.FieldValues.Add(new FieldValue+ {+ Id = Guid.NewGuid(),+ ItemId = item.Id,+ FieldDefinitionId = fieldDefinitionId,+ FieldDefinition = fieldDefinition,+ FieldKey = null,+ Value = customField.Value,+ Weight = 0,+ });+ }+ else+ {+ // Existing custom field - update value+ item.FieldValues.Add(new FieldValue+ {+ Id = customField.Id != Guid.Empty ? customField.Id : Guid.NewGuid(),+ ItemId = item.Id,+ FieldDefinitionId = customField.FieldDefinitionId,+ FieldKey = null,+ Value = customField.Value,+ Weight = 0,+ });+ }+ }+return item;}++ /// <summary>+ /// Gets the value of a system field by its field key.+ /// </summary>+ /// <param name="fieldKey">The field key.</param>+ /// <returns>The field value or empty string.</returns>+ public string GetFieldValue(string fieldKey)+ {+ return fieldKey switch+ {+ FieldKey.LoginUrl => ServiceUrl ?? string.Empty,+ FieldKey.LoginUsername => Username,+ FieldKey.LoginPassword => Password,+ FieldKey.LoginEmail => Email,+ FieldKey.NotesContent => Notes,+ FieldKey.AliasFirstName => AliasFirstName,+ FieldKey.AliasLastName => AliasLastName,+ FieldKey.AliasGender => AliasGender,+ FieldKey.AliasBirthdate => AliasBirthDate,+ FieldKey.CardNumber => CardNumber,+ FieldKey.CardCardholderName => CardCardholderName,+ FieldKey.CardExpiryMonth => CardExpiryMonth,+ FieldKey.CardExpiryYear => CardExpiryYear,+ FieldKey.CardCvv => CardCvv,+ FieldKey.CardPin => CardPin,+ _ => string.Empty,+ };+ }++ /// <summary>+ /// Sets the value of a system field by its field key.+ /// </summary>+ /// <param name="fieldKey">The field key.</param>+ /// <param name="value">The value to set.</param>+ public void SetFieldValue(string fieldKey, string value)+ {+ switch (fieldKey)+ {+ case FieldKey.LoginUrl:+ ServiceUrl = value;+ break;+ case FieldKey.LoginUsername:+ Username = value;+ break;+ case FieldKey.LoginPassword:+ Password = value;+ break;+ case FieldKey.LoginEmail:+ Email = value;+ break;+ case FieldKey.NotesContent:+ Notes = value;+ break;+ case FieldKey.AliasFirstName:+ AliasFirstName = value;+ break;+ case FieldKey.AliasLastName:+ AliasLastName = value;+ break;+ case FieldKey.AliasGender:+ AliasGender = value;+ break;+ case FieldKey.AliasBirthdate:+ AliasBirthDate = value;+ break;+ case FieldKey.CardNumber:+ CardNumber = value;+ break;+ case FieldKey.CardCardholderName:+ CardCardholderName = value;+ break;+ case FieldKey.CardExpiryMonth:+ CardExpiryMonth = value;+ break;+ case FieldKey.CardExpiryYear:+ CardExpiryYear = value;+ break;+ case FieldKey.CardCvv:+ CardCvv = value;+ break;+ case FieldKey.CardPin:+ CardPin = value;+ break;+ }+ }++ /// <summary>+ /// Checks if a field has a non-empty value.+ /// </summary>+ /// <param name="fieldKey">The field key.</param>+ /// <returns>True if the field has a value.</returns>+ public bool HasFieldValue(string fieldKey)+ {+ return !string.IsNullOrEmpty(GetFieldValue(fieldKey));+ }}diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razorindex f3fd6d32c..bfd407ec4 100644--- a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor@@ -5,6 +5,7 @@@inject IJSRuntime JSRuntime@inject AliasVault.Client.Services.QuickCreateStateService QuickCreateStateService@using AliasVault.Client.Services.JsInterop.Models+@using AliasVault.Client.Main.Components.Items@using Microsoft.Extensions.Localization@using AliasClientDb@using AliasClientDb.Models@@ -30,201 +31,353 @@ else<DataAnnotationsValidator /><div class="grid grid-cols-1 px-4 pt-6 md:grid-cols-2 lg:grid-cols-3 md:gap-4 dark:bg-gray-900"><div class="col-span-1 md:col-span-1 lg:col-span-1">+ @* Item Type Selector *@+ <ItemTypeSelector+ SelectedType="@Obj.ItemType"+ SelectedTypeChanged="HandleItemTypeChange"+ IsEditMode="@EditMode"+ ShowDropdown="@ShowTypeDropdown"+ ShowDropdownChanged="@((show) => ShowTypeDropdown = show)"+ OnRegenerateAlias="@GenerateRandomAlias" />++ @* Service/Name Section - Always shown *@<div class="p-4 mb-4 bg-white border-2 border-primary-600 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">- <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["ServiceSectionHeader"]</h3>+ <h3 class="mb-4 text-xl font-semibold dark:text-white">@GetNameSectionTitle()</h3><div class="grid gap-6"><div class="col-span-6 sm:col-span-3"><EditFormRow Id="service-name" Label="@Localizer["ServiceNameLabel"]" Placeholder="@Localizer["ServiceNamePlaceholder"]" @bind-Value="Obj.ServiceName"></EditFormRow><ValidationMessage For="() => Obj.ServiceName"/></div>- <div class="col-span-6 sm:col-span-3">- <EditFormRow Id="service-url" OnFocus="OnFocusUrlInput" Label="@Localizer["ServiceUrlLabel"]" @bind-Value="Obj.ServiceUrl"></EditFormRow>- </div>+ @* URL field - only for Login and Alias types *@+ @if (ShouldShowField(FieldKey.LoginUrl))+ {+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Id="service-url" OnFocus="OnFocusUrlInput" Label="@Localizer["ServiceUrlLabel"]" @bind-Value="Obj.ServiceUrl"></EditFormRow>+ </div>+ }</div></div>- @if (EditMode && Id.HasValue)+ @* TOTP Codes Section - Only for Login/Alias types when visible *@+ @if (Show2FA && HasLoginFields()){<div class="col-span-1 md:col-span-1 lg:col-span-1"><TotpCodes TotpCodeList="@Obj.TotpCodes" TotpCodesChanged="HandleTotpCodesChanged" /></div>}- else++ @* Notes Section - When visible *@+ @if (ShouldShowField(FieldKey.NotesContent)){<div class="col-span-1 md:col-span-1 lg:col-span-1">- <TotpCodes TotpCodeList="@Obj.TotpCodes" TotpCodesChanged="HandleTotpCodesChanged" />- </div>- }-- <div class="col-span-1 md:col-span-1 lg:col-span-1">- <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">- <div class="grid gap-6">- <div class="col-span-6 sm:col-span-3">- <EditFormRow Type="textarea" Id="notes" Label="@Localizer["NotesLabel"]" LabelStyle="EditFormRow.FormLabelStyle.Header" @bind-Value="Obj.Notes"></EditFormRow>+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800 relative">+ <div class="grid gap-6">+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Type="textarea" Id="notes" Label="@Localizer["NotesLabel"]" LabelStyle="EditFormRow.FormLabelStyle.Header" @bind-Value="Obj.Notes"></EditFormRow>+ </div></div>+ @if (CanRemoveField(FieldKey.NotesContent))+ {+ <button type="button" @onclick="() => RemoveOptionalField(FieldKey.NotesContent)" @onclick:preventDefault="true"+ class="absolute top-3 right-3 text-gray-400 hover:text-red-500 transition-colors" title="@Localizer["RemoveField"]">+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />+ </svg>+ </button>+ }</div></div>- </div>+ }- <div class="col-span-1 md:col-span-1 lg:col-span-1">- <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">- <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["AttachmentsSectionHeader"]</h3>- <div class="grid gap-6">- <div class="col-span-6 sm:col-span-3">- <AttachmentUploader- Attachments="@Obj.Attachments"- AttachmentsChanged="@HandleAttachmentsChanged" />+ @* Attachments Section - When visible *@+ @if (ShowAttachments)+ {+ <div class="col-span-1 md:col-span-1 lg:col-span-1">+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["AttachmentsSectionHeader"]</h3>+ <div class="grid gap-6">+ <div class="col-span-6 sm:col-span-3">+ <AttachmentUploader+ Attachments="@Obj.Attachments"+ AttachmentsChanged="@HandleAttachmentsChanged" />+ </div></div></div></div>- </div>+ }</div>+<div class="col-span-1 md:col-span-1 lg:col-span-2">- <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">- <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["LoginDetailsSectionHeader"]</h3>- <div class="grid gap-6">- @if (EditMode && Obj.Passkeys != null && Obj.Passkeys.Any())- {- var passkey = Obj.Passkeys.First();- @* With passkey: Username, Passkey, Email, Password *@- <div class="col-span-6">- <EditUsernameFormRow Id="username" Label="@Localizer["UsernameLabel"]" @bind-Value="Obj.Username" OnGenerateNewUsername="GenerateRandomUsername"></EditUsernameFormRow>- </div>- @if (!PasskeyMarkedForDeletion)+ @* Login Details Section - For Login and Alias types *@+ @if (HasLoginFields())+ {+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["LoginDetailsSectionHeader"]</h3>+ <div class="grid gap-6">+ @if (EditMode && Obj.Passkeys != null && Obj.Passkeys.Any()){+ var passkey = Obj.Passkeys.First();+ @* With passkey: Username, Passkey, Email, Password *@<div class="col-span-6">- <div class="p-3 rounded-lg bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700">- <div class="flex items-start gap-3">- <svg class="w-5 h-5 text-gray-600 dark:text-gray-400 mt-0.5 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">- <path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4" />- </svg>- <div class="flex-1">- <div class="mb-1 flex items-center justify-between">- <span class="text-sm font-semibold text-gray-900 dark:text-white">@Localizer["PasskeyLabel"]</span>- <button type="button" @onclick="MarkPasskeyForDeletion" class="text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300" title="@Localizer["DeletePasskeyButton"]">- <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">- <polyline points="3 6 5 6 21 6" />- <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />- <line x1="10" y1="11" x2="10" y2="17" />- <line x1="14" y1="11" x2="14" y2="17" />- </svg>- </button>+ <EditUsernameFormRow Id="username" Label="@Localizer["UsernameLabel"]" @bind-Value="Obj.Username" OnGenerateNewUsername="GenerateRandomUsername"></EditUsernameFormRow>+ </div>+ @if (!PasskeyMarkedForDeletion)+ {+ <div class="col-span-6">+ <div class="p-3 rounded-lg bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700">+ <div class="flex items-start gap-3">+ <svg class="w-5 h-5 text-gray-600 dark:text-gray-400 mt-0.5 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4" />+ </svg>+ <div class="flex-1">+ <div class="mb-1 flex items-center justify-between">+ <span class="text-sm font-semibold text-gray-900 dark:text-white">@Localizer["PasskeyLabel"]</span>+ <button type="button" @onclick="MarkPasskeyForDeletion" class="text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300" title="@Localizer["DeletePasskeyButton"]">+ <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <polyline points="3 6 5 6 21 6" />+ <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />+ <line x1="10" y1="11" x2="10" y2="17" />+ <line x1="14" y1="11" x2="14" y2="17" />+ </svg>+ </button>+ </div>+ <div class="space-y-1 mb-2">+ @if (!string.IsNullOrWhiteSpace(passkey.RpId))+ {+ <div>+ <span class="text-xs text-gray-500 dark:text-gray-400">@Localizer["PasskeySiteLabel"]: </span>+ <span class="text-sm text-gray-900 dark:text-white">@passkey.RpId</span>+ </div>+ }+ @if (!string.IsNullOrWhiteSpace(passkey.DisplayName))+ {+ <div>+ <span class="text-xs text-gray-500 dark:text-gray-400">@Localizer["PasskeyDisplayNameLabel"]: </span>+ <span class="text-sm text-gray-900 dark:text-white">@passkey.DisplayName</span>+ </div>+ }+ </div>+ <p class="text-xs text-gray-600 dark:text-gray-400">+ @Localizer["PasskeyHelpText"]+ </p></div>- <div class="space-y-1 mb-2">- @if (!string.IsNullOrWhiteSpace(passkey.RpId))- {- <div>- <span class="text-xs text-gray-500 dark:text-gray-400">@Localizer["PasskeySiteLabel"]: </span>- <span class="text-sm text-gray-900 dark:text-white">@passkey.RpId</span>- </div>- }- @if (!string.IsNullOrWhiteSpace(passkey.DisplayName))- {- <div>- <span class="text-xs text-gray-500 dark:text-gray-400">@Localizer["PasskeyDisplayNameLabel"]: </span>- <span class="text-sm text-gray-900 dark:text-white">@passkey.DisplayName</span>- </div>- }+ </div>+ </div>+ </div>+ }+ else+ {+ <div class="col-span-6">+ <div class="p-3 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800">+ <div class="flex items-start gap-3">+ <svg class="w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4" />+ </svg>+ <div class="flex-1">+ <div class="mb-1 flex items-center justify-between">+ <span class="text-sm font-semibold text-red-900 dark:text-red-100">@Localizer["PasskeyMarkedForDeletion"]</span>+ <button type="button" @onclick="UndoPasskeyDeletion" class="text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300" title="@Localizer["UndoButton"]">+ <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M3 7v6h6" />+ <path d="M21 17a9 9 0 00-9-9 9 9 0 00-6 2.3L3 13" />+ </svg>+ </button>+ </div>+ <p class="text-xs text-red-800 dark:text-red-200">+ @Localizer["PasskeyWillBeDeleted"]+ </p></div>- <p class="text-xs text-gray-600 dark:text-gray-400">- @Localizer["PasskeyHelpText"]- </p></div></div></div>+ }+ <div class="col-span-6">+ <EditEmailFormRow Id="email" Label="@Localizer["EmailLabel"]" @bind-Value="Obj.Email"></EditEmailFormRow>+ </div>+ <div class="col-span-6">+ <EditPasswordFormRow Id="password" Label="@Localizer["PasswordLabel"]" @bind-Value="Obj.Password" ShowPassword="IsPasswordVisible"></EditPasswordFormRow></div>}else{- <div class="col-span-6">- <div class="p-3 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800">- <div class="flex items-start gap-3">- <svg class="w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">- <path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4" />+ @* Without passkey: Email (optional add for Login), Username, Password *@+ @if (ShouldShowField(FieldKey.LoginEmail))+ {+ <div class="col-span-6 relative">+ <EditEmailFormRow Id="email" Label="@Localizer["EmailLabel"]" @bind-Value="Obj.Email"></EditEmailFormRow>+ @if (CanRemoveField(FieldKey.LoginEmail))+ {+ <button type="button" @onclick="() => RemoveOptionalField(FieldKey.LoginEmail)" @onclick:preventDefault="true"+ class="absolute top-0 right-0 text-gray-400 hover:text-red-500 transition-colors" title="@Localizer["RemoveField"]">+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />+ </svg>+ </button>+ }+ </div>+ }+ else if (Obj.ItemType == ItemTypes.Login && !ManuallyAddedFields.Contains(FieldKey.LoginEmail))+ {+ @* Show + Email button for Login type when email is not visible *@+ <div class="col-span-6">+ <button type="button" @onclick="() => AddOptionalField(FieldKey.LoginEmail)" @onclick:preventDefault="true"+ class="text-sm text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 flex items-center gap-1">+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" /></svg>- <div class="flex-1">- <div class="mb-1 flex items-center justify-between">- <span class="text-sm font-semibold text-red-900 dark:text-red-100">@Localizer["PasskeyMarkedForDeletion"]</span>- <button type="button" @onclick="UndoPasskeyDeletion" class="text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300" title="@Localizer["UndoButton"]">- <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">- <path d="M3 7v6h6" />- <path d="M21 17a9 9 0 00-9-9 9 9 0 00-6 2.3L3 13" />- </svg>- </button>- </div>- <p class="text-xs text-red-800 dark:text-red-200">- @Localizer["PasskeyWillBeDeleted"]- </p>- </div>- </div>+ @Localizer["AddEmailField"]+ </button></div>+ }++ <div class="col-span-6">+ <EditUsernameFormRow Id="username" Label="@Localizer["UsernameLabel"]" @bind-Value="Obj.Username" OnGenerateNewUsername="GenerateRandomUsername"></EditUsernameFormRow>+ </div>+ <div class="col-span-6">+ <EditPasswordFormRow Id="password" Label="@Localizer["PasswordLabel"]" @bind-Value="Obj.Password" ShowPassword="IsPasswordVisible"></EditPasswordFormRow></div>}- <div class="col-span-6">- <EditEmailFormRow Id="email" Label="@Localizer["EmailLabel"]" @bind-Value="Obj.Email"></EditEmailFormRow>- </div>- <div class="col-span-6">- <EditPasswordFormRow Id="password" Label="@Localizer["PasswordLabel"]" @bind-Value="Obj.Password" ShowPassword="IsPasswordVisible"></EditPasswordFormRow>- </div>- }- else- {- @* Without passkey: Email, Username, Password *@- <div class="col-span-6">- <EditEmailFormRow Id="email" Label="@Localizer["EmailLabel"]" @bind-Value="Obj.Email"></EditEmailFormRow>- </div>- <div class="col-span-6">- <EditUsernameFormRow Id="username" Label="@Localizer["UsernameLabel"]" @bind-Value="Obj.Username" OnGenerateNewUsername="GenerateRandomUsername"></EditUsernameFormRow>- </div>- <div class="col-span-6">- <EditPasswordFormRow Id="password" Label="@Localizer["PasswordLabel"]" @bind-Value="Obj.Password" ShowPassword="IsPasswordVisible"></EditPasswordFormRow>- </div>- }+ </div></div>- </div>+ }- <div class="col-span-1 md:col-span-1 lg:col-span-2">- <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">- <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["AliasSectionHeader"]</h3>- <div class="mb-4">- <Button OnClick="HandleGenerateOrClearAlias" Color="@(HasAliasValues() ? "secondary" : "primary")" AdditionalClasses="@GetToggleButtonClasses()">- <svg class='w-5 h-5 inline-block' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">- @if (HasAliasValues())- {- <path d="M18 6L6 18M6 6l12 12"/>- }- else- {- <rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>- <circle cx="8" cy="8" r="1"/>- <circle cx="16" cy="8" r="1"/>- <circle cx="12" cy="12" r="1"/>- <circle cx="8" cy="16" r="1"/>- <circle cx="16" cy="16" r="1"/>- }- </svg>- @(HasAliasValues() ? Localizer["ClearAliasFieldsButton"] : Localizer["GenerateRandomAliasButton"])- </Button>- </div>- <div class="grid gap-6">- <div class="col-span-6 sm:col-span-3">- <EditFormRow Id="first-name" Label="@Localizer["FirstNameLabel"]" @bind-Value="Obj.AliasFirstName"></EditFormRow>- </div>- <div class="col-span-6 sm:col-span-3">- <EditFormRow Id="last-name" Label="@Localizer["LastNameLabel"]" @bind-Value="Obj.AliasLastName"></EditFormRow>+ @* Alias Identity Section - For Alias type *@+ @if (Obj.ItemType == ItemTypes.Alias)+ {+ <div class="col-span-1 md:col-span-1 lg:col-span-2">+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["AliasSectionHeader"]</h3>+ <div class="mb-4">+ <Button OnClick="HandleGenerateOrClearAlias" Color="@(HasAliasValues() ? "secondary" : "primary")" AdditionalClasses="@GetToggleButtonClasses()">+ <svg class='w-5 h-5 inline-block' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">+ @if (HasAliasValues())+ {+ <path d="M18 6L6 18M6 6l12 12"/>+ }+ else+ {+ <rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>+ <circle cx="8" cy="8" r="1"/>+ <circle cx="16" cy="8" r="1"/>+ <circle cx="12" cy="12" r="1"/>+ <circle cx="8" cy="16" r="1"/>+ <circle cx="16" cy="16" r="1"/>+ }+ </svg>+ @(HasAliasValues() ? Localizer["ClearAliasFieldsButton"] : Localizer["GenerateRandomAliasButton"])+ </Button></div>- <div class="col-span-6 sm:col-span-3">- <EditFormRow Id="nickname" Label="@Localizer["NickNameLabel"]" @bind-Value="Obj.Username"></EditFormRow>+ <div class="grid gap-6">+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Id="first-name" Label="@Localizer["FirstNameLabel"]" @bind-Value="Obj.AliasFirstName"></EditFormRow>+ </div>+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Id="last-name" Label="@Localizer["LastNameLabel"]" @bind-Value="Obj.AliasLastName"></EditFormRow>+ </div>+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Id="nickname" Label="@Localizer["NickNameLabel"]" @bind-Value="Obj.Username"></EditFormRow>+ </div>+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Id="gender" Label="@Localizer["GenderLabel"]" @bind-Value="Obj.AliasGender"></EditFormRow>+ </div>+ <div class="col-span-6 sm:col-span-3">+ <EditFormRow Id="birthdate" Label="@Localizer["BirthDateLabel"]" @bind-Value="Obj.AliasBirthDate"></EditFormRow>+ <ValidationMessage For="() => Obj.AliasBirthDate"/>+ </div></div>- <div class="col-span-6 sm:col-span-3">- <EditFormRow Id="gender" Label="@Localizer["GenderLabel"]" @bind-Value="Obj.AliasGender"></EditFormRow>+ </div>+ </div>+ }++ @* Credit Card Section - For CreditCard type *@+ @if (Obj.ItemType == ItemTypes.CreditCard)+ {+ <div class="col-span-1 md:col-span-1 lg:col-span-2">+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["CardDetailsSectionHeader"]</h3>+ <div class="grid gap-6">+ <div class="col-span-6">+ <EditFormRow Id="cardholder-name" Label="@Localizer["CardholderNameLabel"]" @bind-Value="Obj.CardCardholderName"></EditFormRow>+ </div>+ <div class="col-span-6">+ <EditPasswordFormRow Id="card-number" Label="@Localizer["CardNumberLabel"]" @bind-Value="Obj.CardNumber" ShowPassword="false"></EditPasswordFormRow>+ </div>+ <div class="col-span-3">+ <EditFormRow Id="expiry-month" Label="@Localizer["ExpiryMonthLabel"]" Placeholder="MM" @bind-Value="Obj.CardExpiryMonth"></EditFormRow>+ </div>+ <div class="col-span-3">+ <EditFormRow Id="expiry-year" Label="@Localizer["ExpiryYearLabel"]" Placeholder="YYYY" @bind-Value="Obj.CardExpiryYear"></EditFormRow>+ </div>+ <div class="col-span-6 sm:col-span-3">+ <EditPasswordFormRow Id="card-cvv" Label="@Localizer["CardCvvLabel"]" @bind-Value="Obj.CardCvv" ShowPassword="false"></EditPasswordFormRow>+ </div>+ @if (ShouldShowField(FieldKey.CardPin))+ {+ <div class="col-span-6 sm:col-span-3 relative">+ <EditPasswordFormRow Id="card-pin" Label="@Localizer["CardPinLabel"]" @bind-Value="Obj.CardPin" ShowPassword="false"></EditPasswordFormRow>+ @if (CanRemoveField(FieldKey.CardPin))+ {+ <button type="button" @onclick="() => RemoveOptionalField(FieldKey.CardPin)" @onclick:preventDefault="true"+ class="absolute top-0 right-0 text-gray-400 hover:text-red-500 transition-colors" title="@Localizer["RemoveField"]">+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />+ </svg>+ </button>+ }+ </div>+ }</div>- <div class="col-span-6 sm:col-span-3">- <EditFormRow Id="birthdate" Label="@Localizer["BirthDateLabel"]" @bind-Value="Obj.AliasBirthDate"></EditFormRow>- <ValidationMessage For="() => Obj.AliasBirthDate"/>+ </div>+ </div>+ }++ @* Custom Fields Section *@+ @if (Obj.CustomFields.Any())+ {+ <div class="col-span-1 md:col-span-1 lg:col-span-2">+ <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-xl font-semibold dark:text-white">@Localizer["CustomFieldsSectionHeader"]</h3>+ <div class="grid gap-6">+ @foreach (var customField in Obj.CustomFields)+ {+ <div class="col-span-6 relative">+ @if (customField.FieldType == "TextArea")+ {+ <EditFormRow Type="textarea" Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="@customField.Label" @bind-Value="customField.Value"></EditFormRow>+ }+ else if (customField.IsHidden || customField.FieldType == "Hidden" || customField.FieldType == "Password")+ {+ <EditPasswordFormRow Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="@customField.Label" @bind-Value="customField.Value" ShowPassword="false"></EditPasswordFormRow>+ }+ else+ {+ <EditFormRow Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="@customField.Label" @bind-Value="customField.Value"></EditFormRow>+ }+ <button type="button" @onclick="() => RemoveCustomField(customField)" @onclick:preventDefault="true"+ class="absolute top-0 right-0 text-gray-400 hover:text-red-500 transition-colors" title="@Localizer["RemoveField"]">+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />+ </svg>+ </button>+ </div>+ }</div></div></div>+ }++ @* Add Field Menu *@+ <div class="col-span-1 md:col-span-1 lg:col-span-2 mb-4">+ <AddFieldMenu+ OptionalSystemFields="@GetOptionalSystemFields()"+ VisibleFieldKeys="@GetVisibleFieldKeys()"+ Show2FA="@Show2FA"+ ShowAttachments="@ShowAttachments"+ HasLoginFields="@HasLoginFields()"+ OnAddSystemField="AddOptionalField"+ OnAddCustomField="AddCustomField"+ OnAdd2FA="() => Show2FA = true"+ OnAddAttachments="() => ShowAttachments = true" /></div></div></div>@@ -246,9 +399,22 @@ elseprivate bool Loading { get; set; } = true;private bool IsPasswordVisible { get; set; } = false;private bool PasskeyMarkedForDeletion { get; set; } = false;+ private bool ShowTypeDropdown { get; set; } = false;+ private bool Show2FA { get; set; } = false;+ private bool ShowAttachments { get; set; } = false;private ItemEdit Obj { get; set; } = new();private IJSObjectReference? Module;+ /// <summary>+ /// Fields that were manually added via the + menu.+ /// </summary>+ private HashSet<string> ManuallyAddedFields { get; set; } = [];++ /// <summary>+ /// Fields that initially had values when loaded (for edit mode).+ /// </summary>+ private HashSet<string> InitiallyVisibleFields { get; set; } = [];+// Track last generated values to protect manual entriesprivate string? LastGeneratedUsername { get; set; }private string? LastGeneratedPassword { get; set; }@@ -269,12 +435,10 @@ else{if (Id.HasValue){- // Edit modeEditMode = true;}else{- // Add modeEditMode = false;}}@@ -331,12 +495,202 @@ elseif (!EditMode){- // When creating a new alias: start with focus on the service name input.await JsInteropService.FocusElementById("service-name");}}}+ /// <summary>+ /// Gets the title for the name/service section based on item type.+ /// </summary>+ private string GetNameSectionTitle()+ {+ return Obj.ItemType switch+ {+ ItemTypes.CreditCard => Localizer["CardNameSectionHeader"],+ ItemTypes.Note => Localizer["NoteTitleSectionHeader"],+ _ => Localizer["ServiceSectionHeader"]+ };+ }++ /// <summary>+ /// Checks if the current item type has login-related fields.+ /// </summary>+ private bool HasLoginFields()+ {+ return Obj.ItemType == ItemTypes.Login || Obj.ItemType == ItemTypes.Alias;+ }++ /// <summary>+ /// Determines if a field should be shown based on item type and visibility rules.+ /// </summary>+ private bool ShouldShowField(string fieldKey)+ {+ // Check if field applies to current item type+ var fieldDef = SystemFieldRegistry.GetSystemField(fieldKey);+ if (fieldDef == null || !SystemFieldRegistry.FieldAppliesToType(fieldDef, Obj.ItemType))+ {+ return false;+ }++ // Check if manually added+ if (ManuallyAddedFields.Contains(fieldKey))+ {+ return true;+ }++ // Check if initially visible (edit mode)+ if (InitiallyVisibleFields.Contains(fieldKey))+ {+ return true;+ }++ // Check if it has a value+ if (Obj.HasFieldValue(fieldKey))+ {+ return true;+ }++ // Check if shown by default for this item type+ var config = fieldDef.ApplicableToTypes.GetValueOrDefault(Obj.ItemType);+ return config?.ShowByDefault ?? false;+ }++ /// <summary>+ /// Determines if a field can be removed (was manually added).+ /// </summary>+ private bool CanRemoveField(string fieldKey)+ {+ // A field can be removed if it was manually added via the + menu+ return ManuallyAddedFields.Contains(fieldKey);+ }++ /// <summary>+ /// Gets the optional system fields for the current item type.+ /// </summary>+ private IEnumerable<SystemFieldDefinition> GetOptionalSystemFields()+ {+ return SystemFieldRegistry.GetOptionalFieldsForItemType(Obj.ItemType);+ }++ /// <summary>+ /// Gets the currently visible field keys.+ /// </summary>+ private HashSet<string> GetVisibleFieldKeys()+ {+ var keys = new HashSet<string>();++ foreach (var field in SystemFieldRegistry.GetFieldsForItemType(Obj.ItemType))+ {+ if (ShouldShowField(field.FieldKey))+ {+ keys.Add(field.FieldKey);+ }+ }++ return keys;+ }++ /// <summary>+ /// Adds an optional field.+ /// </summary>+ private void AddOptionalField(string fieldKey)+ {+ ManuallyAddedFields.Add(fieldKey);+ StateHasChanged();+ }++ /// <summary>+ /// Removes an optional field.+ /// </summary>+ private void RemoveOptionalField(string fieldKey)+ {+ ManuallyAddedFields.Remove(fieldKey);+ Obj.SetFieldValue(fieldKey, string.Empty);+ StateHasChanged();+ }++ /// <summary>+ /// Adds a custom field.+ /// </summary>+ private void AddCustomField((string Label, string FieldType) args)+ {+ var tempId = $"custom_{Guid.NewGuid()}";+ Obj.CustomFields.Add(new CustomFieldEdit+ {+ TempId = tempId,+ Label = args.Label,+ FieldType = args.FieldType,+ IsHidden = args.FieldType == "Hidden" || args.FieldType == "Password",+ Value = string.Empty+ });+ StateHasChanged();+ }++ /// <summary>+ /// Removes a custom field.+ /// </summary>+ private void RemoveCustomField(CustomFieldEdit field)+ {+ Obj.CustomFields.Remove(field);+ StateHasChanged();+ }++ /// <summary>+ /// Handles item type change.+ /// </summary>+ private async Task HandleItemTypeChange(string newType)+ {+ if (Obj.ItemType == newType)+ {+ return;+ }++ var oldType = Obj.ItemType;+ Obj.ItemType = newType;++ // Clear fields that don't apply to the new type+ if (oldType == ItemTypes.Alias && newType != ItemTypes.Alias)+ {+ // Clear alias fields when switching away from Alias+ Obj.AliasFirstName = string.Empty;+ Obj.AliasLastName = string.Empty;+ Obj.AliasGender = string.Empty;+ Obj.AliasBirthDate = string.Empty;+ }++ if (oldType == ItemTypes.CreditCard && newType != ItemTypes.CreditCard)+ {+ // Clear card fields when switching away from CreditCard+ Obj.CardNumber = string.Empty;+ Obj.CardCardholderName = string.Empty;+ Obj.CardExpiryMonth = string.Empty;+ Obj.CardExpiryYear = string.Empty;+ Obj.CardCvv = string.Empty;+ Obj.CardPin = string.Empty;+ }++ // Clear manually added fields that don't apply to new type+ var fieldsToRemove = ManuallyAddedFields+ .Where(fk => {+ var def = SystemFieldRegistry.GetSystemField(fk);+ return def != null && !SystemFieldRegistry.FieldAppliesToType(def, newType);+ })+ .ToList();+ foreach (var fk in fieldsToRemove)+ {+ ManuallyAddedFields.Remove(fk);+ }++ // Generate alias for Alias type in create mode+ if (newType == ItemTypes.Alias && !EditMode && !HasAliasValues())+ {+ await GenerateRandomAlias();+ }++ StateHasChanged();+ }+/// <summary>/// Loads an existing credential for editing./// </summary>@@ -348,7 +702,6 @@ elsereturn;}- // Load existing Obj, retrieve from servicevar item = await ItemService.LoadEntryAsync(Id.Value);if (item is null){@@ -358,6 +711,19 @@ elseObj = ItemEdit.FromEntity(item);+ // Track initially visible fields+ foreach (var fieldDef in SystemFieldRegistry.GetFieldsForItemType(Obj.ItemType))+ {+ if (Obj.HasFieldValue(fieldDef.FieldKey))+ {+ InitiallyVisibleFields.Add(fieldDef.FieldKey);+ }+ }++ // Show sections that have content+ Show2FA = Obj.TotpCodes.Any();+ ShowAttachments = Obj.Attachments.Any();+if (Obj.ServiceUrl is null){Obj.ServiceUrl = ItemService.DefaultServiceUrl;@@ -404,7 +770,7 @@ else}/// <summary>- /// When the URL input is focused, place cursor at the end of the default URL to allow for easy typing.+ /// When the URL input is focused, place cursor at the end of the default URL./// </summary>private void OnFocusUrlInput(FocusEventArgs e){@@ -413,7 +779,6 @@ elsereturn;}- // Use a small delay to ensure the focus is set after the browser's default behavior.Task.Delay(1).ContinueWith(_ =>{JSRuntime.InvokeVoidAsync("eval", $"document.getElementById('service-url').setSelectionRange({ItemService.DefaultServiceUrl.Length}, {ItemService.DefaultServiceUrl.Length})");@@ -474,34 +839,28 @@ elseprivate async Task GenerateRandomAlias(){- // Store current values BEFORE generating, as the service might modify themstring currentUsername = Obj.Username ?? string.Empty;string currentPassword = Obj.Password ?? string.Empty;string currentEmail = Obj.Email ?? string.Empty;- // Generate random identityvar generatedItem = await ItemService.GenerateRandomIdentityAsync(Obj.ToEntity());var generatedObj = ItemEdit.FromEntity(generatedItem);- // Restore the original values to prevent service calls above from modifying themObj.Username = currentUsername;Obj.Password = currentPassword;Obj.Email = currentEmail;- // Apply generated values, respecting manual entriesObj.AliasFirstName = generatedObj.AliasFirstName;Obj.AliasLastName = generatedObj.AliasLastName;Obj.AliasGender = generatedObj.AliasGender;Obj.AliasBirthDate = generatedObj.AliasBirthDate;- // Only overwrite username if it's empty or matches the last generated valueif (string.IsNullOrWhiteSpace(currentUsername) || currentUsername == LastGeneratedUsername){Obj.Username = generatedObj.Username;LastGeneratedUsername = generatedObj.Username;}- // Only overwrite password if it's empty or matches the last generated valueif (string.IsNullOrWhiteSpace(currentPassword) || currentPassword == LastGeneratedPassword){Obj.Password = generatedObj.Password;@@ -509,7 +868,6 @@ elseIsPasswordVisible = true;}- // Only overwrite email if it's empty or (for new credentials) matches the last generated value or starts with @ which is the default email patternif (string.IsNullOrWhiteSpace(currentEmail) || currentEmail == LastGeneratedEmail || currentEmail.StartsWith("@")){Obj.Email = generatedObj.Email;@@ -520,16 +878,13 @@ else}/// <summary>- /// Generate a new random username based on existing identity, or if no identity is present,- /// generate a new random identity.+ /// Generate a new random username./// </summary>private async Task GenerateRandomUsername(){- // If current object is null, then we create a new random identity.AliasVaultIdentity identity;if (string.IsNullOrWhiteSpace(Obj.AliasFirstName) && string.IsNullOrWhiteSpace(Obj.AliasLastName) && string.IsNullOrWhiteSpace(Obj.AliasBirthDate)){- // Create new Item object to avoid modifying the original objectvar randomIdentity = await ItemService.GenerateRandomIdentityAsync(CreateNewItemObject());var randomIdentityEdit = ItemEdit.FromEntity(randomIdentity);@@ -544,7 +899,6 @@ else}else{- // Assemble identity model with the current valuesidentity = new AliasVaultIdentity{FirstName = Obj.AliasFirstName ?? string.Empty,@@ -559,7 +913,7 @@ else}/// <summary>- /// Cancel the edit operation and navigate back to the credentials view.+ /// Cancel the edit operation./// </summary>private void Cancel(){@@ -633,12 +987,10 @@ elseif (Id is null || Id == Guid.Empty){- // Error saving.GlobalNotificationService.AddErrorMessage(Localizer["ErrorSavingItem"], true);return;}- // No error, add success message.if (EditMode){GlobalNotificationService.AddSuccessMessage(Localizer["ItemUpdatedSuccess"]);diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor b/apps/server/AliasVault.Client/Main/Pages/Items/Home.razorindex f0cb2c943..da1bb3aaa 100644--- a/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor@@ -703,9 +703,13 @@ else{await LoadItemsAsync();- // Set up IntersectionObserver for infinite scroll+ // Set up IntersectionObserver for infinite scroll (only if there are more items to load).+ // The sentinel element only exists when HasMoreItems is true._dotNetRef = DotNetObjectReference.Create(this);- await JsInteropService.SetupInfiniteScroll(_scrollSentinel, _dotNetRef);+ if (HasMoreItems)+ {+ await JsInteropService.SetupInfiniteScroll(_scrollSentinel, _dotNetRef);+ }}}diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resxnew file mode 100644index 000000000..032ff4b2a--- /dev/null+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resx@@ -0,0 +1,154 @@+<?xml version="1.0" encoding="utf-8"?>+<root>+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">+ <xsd:element name="root" msdata:IsDataSet="true">+ <xsd:complexType>+ <xsd:choice maxOccurs="unbounded">+ <xsd:element name="data">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" />+ <xsd:element name="comment" type="xsd:string" minOccurs="0" />+ </xsd:sequence>+ <xsd:attribute name="name" type="xsd:string" />+ <xsd:attribute name="type" type="xsd:string" />+ <xsd:attribute name="mimetype" type="xsd:string" />+ </xsd:complexType>+ </xsd:element>+ </xsd:choice>+ </xsd:complexType>+ </xsd:element>+ </xsd:schema>++ <!-- Section options -->+ <data name="TwoFactorAuthentication">+ <value>Two-Factor Authentication</value>+ <comment>Option to add 2FA section</comment>+ </data>+ <data name="Attachments">+ <value>Attachments</value>+ <comment>Option to add attachments section</comment>+ </data>+ <data name="AddCustomField">+ <value>Add Custom Field</value>+ <comment>Option to add a custom field</comment>+ </data>++ <!-- Field labels -->+ <data name="FieldLoginUsername">+ <value>Username</value>+ <comment>Username field label</comment>+ </data>+ <data name="FieldLoginPassword">+ <value>Password</value>+ <comment>Password field label</comment>+ </data>+ <data name="FieldLoginEmail">+ <value>Email</value>+ <comment>Email field label</comment>+ </data>+ <data name="FieldLoginUrl">+ <value>URL</value>+ <comment>URL field label</comment>+ </data>+ <data name="FieldAliasFirstName">+ <value>First Name</value>+ <comment>First name field label</comment>+ </data>+ <data name="FieldAliasLastName">+ <value>Last Name</value>+ <comment>Last name field label</comment>+ </data>+ <data name="FieldAliasGender">+ <value>Gender</value>+ <comment>Gender field label</comment>+ </data>+ <data name="FieldAliasBirthdate">+ <value>Birth Date</value>+ <comment>Birth date field label</comment>+ </data>+ <data name="FieldCardNumber">+ <value>Card Number</value>+ <comment>Card number field label</comment>+ </data>+ <data name="FieldCardCardholderName">+ <value>Cardholder Name</value>+ <comment>Cardholder name field label</comment>+ </data>+ <data name="FieldCardExpiryMonth">+ <value>Expiry Month</value>+ <comment>Expiry month field label</comment>+ </data>+ <data name="FieldCardExpiryYear">+ <value>Expiry Year</value>+ <comment>Expiry year field label</comment>+ </data>+ <data name="FieldCardCvv">+ <value>CVV</value>+ <comment>CVV field label</comment>+ </data>+ <data name="FieldCardPin">+ <value>PIN</value>+ <comment>PIN field label</comment>+ </data>+ <data name="FieldNotesContent">+ <value>Notes</value>+ <comment>Notes field label</comment>+ </data>++ <!-- Custom field modal -->+ <data name="FieldLabel">+ <value>Field Label</value>+ <comment>Label for field label input</comment>+ </data>+ <data name="EnterFieldName">+ <value>Enter field name</value>+ <comment>Placeholder for field name input</comment>+ </data>+ <data name="FieldType">+ <value>Field Type</value>+ <comment>Label for field type selector</comment>+ </data>+ <data name="FieldTypeText">+ <value>Text</value>+ <comment>Text field type option</comment>+ </data>+ <data name="FieldTypeHidden">+ <value>Hidden</value>+ <comment>Hidden field type option</comment>+ </data>+ <data name="FieldTypeEmail">+ <value>Email</value>+ <comment>Email field type option</comment>+ </data>+ <data name="FieldTypeUrl">+ <value>URL</value>+ <comment>URL field type option</comment>+ </data>+ <data name="FieldTypePhone">+ <value>Phone</value>+ <comment>Phone field type option</comment>+ </data>+ <data name="FieldTypeNumber">+ <value>Number</value>+ <comment>Number field type option</comment>+ </data>+ <data name="FieldTypeDate">+ <value>Date</value>+ <comment>Date field type option</comment>+ </data>+ <data name="FieldTypeTextArea">+ <value>Text Area</value>+ <comment>Text area field type option</comment>+ </data>++ <!-- Buttons -->+ <data name="Add">+ <value>Add</value>+ <comment>Add button text</comment>+ </data>+ <data name="Cancel">+ <value>Cancel</value>+ <comment>Cancel button text</comment>+ </data>+</root>diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Items/ItemTypeSelector.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Items/ItemTypeSelector.en.resxnew file mode 100644index 000000000..6ad9dd209--- /dev/null+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Items/ItemTypeSelector.en.resx@@ -0,0 +1,56 @@+<?xml version="1.0" encoding="utf-8"?>+<root>+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">+ <xsd:element name="root" msdata:IsDataSet="true">+ <xsd:complexType>+ <xsd:choice maxOccurs="unbounded">+ <xsd:element name="data">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" />+ <xsd:element name="comment" type="xsd:string" minOccurs="0" />+ </xsd:sequence>+ <xsd:attribute name="name" type="xsd:string" />+ <xsd:attribute name="type" type="xsd:string" />+ <xsd:attribute name="mimetype" type="xsd:string" />+ </xsd:complexType>+ </xsd:element>+ </xsd:choice>+ </xsd:complexType>+ </xsd:element>+ </xsd:schema>++ <!-- Type names -->+ <data name="TypeLogin">+ <value>Login</value>+ <comment>Login item type name</comment>+ </data>+ <data name="TypeAlias">+ <value>Alias</value>+ <comment>Alias item type name</comment>+ </data>+ <data name="TypeCreditCard">+ <value>Credit Card</value>+ <comment>Credit Card item type name</comment>+ </data>+ <data name="TypeNote">+ <value>Secure Note</value>+ <comment>Secure Note item type name</comment>+ </data>++ <!-- Status text -->+ <data name="Creating">+ <value>Creating</value>+ <comment>Status text when creating a new item</comment>+ </data>+ <data name="Editing">+ <value>Editing</value>+ <comment>Status text when editing an existing item</comment>+ </data>++ <!-- Buttons -->+ <data name="RegenerateAlias">+ <value>Regenerate Alias</value>+ <comment>Tooltip for regenerate alias button</comment>+ </data>+</root>diff --git a/apps/server/AliasVault.Client/Resources/Pages/Main/Items/AddEdit.en.resx b/apps/server/AliasVault.Client/Resources/Pages/Main/Items/AddEdit.en.resxindex 161bcf3ff..b64d6a28e 100644--- a/apps/server/AliasVault.Client/Resources/Pages/Main/Items/AddEdit.en.resx+++ b/apps/server/AliasVault.Client/Resources/Pages/Main/Items/AddEdit.en.resx@@ -207,4 +207,56 @@<value>Undo</value><comment>Button to undo passkey deletion</comment></data>++ <!-- Card section fields -->+ <data name="CardDetailsSectionHeader">+ <value>Card Details</value>+ <comment>Header for the credit card details section</comment>+ </data>+ <data name="CardNameSectionHeader">+ <value>Card</value>+ <comment>Header for the card name section</comment>+ </data>+ <data name="NoteTitleSectionHeader">+ <value>Note</value>+ <comment>Header for the note title section</comment>+ </data>+ <data name="CardholderNameLabel">+ <value>Cardholder Name</value>+ <comment>Label for cardholder name input</comment>+ </data>+ <data name="CardNumberLabel">+ <value>Card Number</value>+ <comment>Label for card number input</comment>+ </data>+ <data name="ExpiryMonthLabel">+ <value>Expiry Month</value>+ <comment>Label for expiry month input</comment>+ </data>+ <data name="ExpiryYearLabel">+ <value>Expiry Year</value>+ <comment>Label for expiry year input</comment>+ </data>+ <data name="CardCvvLabel">+ <value>CVV</value>+ <comment>Label for CVV input</comment>+ </data>+ <data name="CardPinLabel">+ <value>PIN</value>+ <comment>Label for PIN input</comment>+ </data>++ <!-- Custom fields section -->+ <data name="CustomFieldsSectionHeader">+ <value>Custom Fields</value>+ <comment>Header for the custom fields section</comment>+ </data>+ <data name="RemoveField">+ <value>Remove field</value>+ <comment>Tooltip for removing a field</comment>+ </data>+ <data name="AddEmailField">+ <value>Add Email</value>+ <comment>Button text for adding email field</comment>+ </data></root>\ No newline at end of filediff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.csindex a78db5a7e..8820200ce 100644--- a/apps/server/AliasVault.Client/Services/ItemService.cs+++ b/apps/server/AliasVault.Client/Services/ItemService.cs@@ -176,13 +176,30 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Confitem.CreatedAt = currentDateTime;item.UpdatedAt = currentDateTime;- // Set timestamps on all field values+ // Set timestamps on all field values and their FieldDefinitionsforeach (var fv in item.FieldValues){fv.Id = Guid.NewGuid();fv.ItemId = item.Id;fv.CreatedAt = currentDateTime;fv.UpdatedAt = currentDateTime;++ // If this field value has a new FieldDefinition (custom field), ensure its timestamps are set+ if (fv.FieldDefinition != null)+ {+ if (fv.FieldDefinition.CreatedAt == default)+ {+ fv.FieldDefinition.CreatedAt = currentDateTime;+ }++ if (fv.FieldDefinition.UpdatedAt == default)+ {+ fv.FieldDefinition.UpdatedAt = currentDateTime;+ }++ // Add the FieldDefinition explicitly to ensure it's tracked+ context.FieldDefinitions.Add(fv.FieldDefinition);+ }}// Set timestamps on attachments@@ -574,50 +591,108 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf// Get existing field valuesvar existingFields = existingItem.FieldValues.Where(fv => !fv.IsDeleted).ToList();- // Track which fields we've processed+ // Track which fields we've processed (by FieldKey for system fields, by FieldDefinitionId for custom fields)var processedFieldKeys = new HashSet<string>();+ var processedFieldDefinitionIds = new HashSet<Guid>();// Process new field valuesforeach (var newField in newItem.FieldValues.Where(fv => !fv.IsDeleted)){- var fieldKey = newField.FieldKey;- if (fieldKey == null)+ // Handle system fields (those with FieldKey)+ if (newField.FieldKey != null){- continue;- }+ processedFieldKeys.Add(newField.FieldKey);- processedFieldKeys.Add(fieldKey);-- var existingField = existingFields.FirstOrDefault(fv => fv.FieldKey == fieldKey);- if (existingField != null)- {- // Update existing field- if (existingField.Value != newField.Value)+ var existingField = existingFields.FirstOrDefault(fv => fv.FieldKey == newField.FieldKey);+ if (existingField != null)+ {+ // Update existing field+ if (existingField.Value != newField.Value)+ {+ existingField.Value = newField.Value;+ existingField.UpdatedAt = updateDateTime;+ }+ }+ else{- existingField.Value = newField.Value;- existingField.UpdatedAt = updateDateTime;+ // Add new field+ existingItem.FieldValues.Add(new FieldValue+ {+ Id = Guid.NewGuid(),+ ItemId = existingItem.Id,+ FieldKey = newField.FieldKey,+ Value = newField.Value,+ Weight = newField.Weight,+ CreatedAt = updateDateTime,+ UpdatedAt = updateDateTime,+ });}}- else+ else if (newField.FieldDefinitionId != null){- // Add new field- existingItem.FieldValues.Add(new FieldValue+ // Handle custom fields (those with FieldDefinitionId)+ processedFieldDefinitionIds.Add(newField.FieldDefinitionId.Value);++ var existingField = existingFields.FirstOrDefault(fv => fv.FieldDefinitionId == newField.FieldDefinitionId);+ if (existingField != null){- Id = Guid.NewGuid(),- ItemId = existingItem.Id,- FieldKey = fieldKey,- Value = newField.Value,- Weight = newField.Weight,- CreatedAt = updateDateTime,- UpdatedAt = updateDateTime,- });+ // Update existing field+ if (existingField.Value != newField.Value)+ {+ existingField.Value = newField.Value;+ existingField.UpdatedAt = updateDateTime;+ }+ }+ else+ {+ // Add new custom field - must also add FieldDefinition if it's new+ if (newField.FieldDefinition != null)+ {+ // Ensure timestamps are set on the FieldDefinition+ if (newField.FieldDefinition.CreatedAt == default)+ {+ newField.FieldDefinition.CreatedAt = updateDateTime;+ }++ if (newField.FieldDefinition.UpdatedAt == default)+ {+ newField.FieldDefinition.UpdatedAt = updateDateTime;+ }++ // Add the FieldDefinition to the context+ context.Set<FieldDefinition>().Add(newField.FieldDefinition);+ }++ existingItem.FieldValues.Add(new FieldValue+ {+ Id = Guid.NewGuid(),+ ItemId = existingItem.Id,+ FieldKey = null,+ FieldDefinitionId = newField.FieldDefinitionId,+ FieldDefinition = newField.FieldDefinition,+ Value = newField.Value,+ Weight = newField.Weight,+ CreatedAt = updateDateTime,+ UpdatedAt = updateDateTime,+ });+ }+ }+ }++ // Soft-delete removed system fields+ foreach (var existingField in existingFields.Where(f => f.FieldKey != null))+ {+ if (!processedFieldKeys.Contains(existingField.FieldKey!))+ {+ existingField.IsDeleted = true;+ existingField.UpdatedAt = updateDateTime;}}- // Soft-delete removed fields- foreach (var existingField in existingFields)+ // Soft-delete removed custom fields+ foreach (var existingField in existingFields.Where(f => f.FieldDefinitionId != null)){- if (existingField.FieldKey != null && !processedFieldKeys.Contains(existingField.FieldKey))+ if (!processedFieldDefinitionIds.Contains(existingField.FieldDefinitionId!.Value)){existingField.IsDeleted = true;existingField.UpdatedAt = updateDateTime;diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.cssindex 935a20cdd..82c7a7361 100644--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css@@ -690,6 +690,18 @@ video {top: 100%;}+.bottom-full {+ bottom: 100%;+}++.right-3 {+ right: 0.75rem;+}++.top-3 {+ top: 0.75rem;+}+.-z-10 {z-index: -10;}@@ -710,6 +722,10 @@ video {z-index: 1000;}+.z-20 {+ z-index: 20;+}+.col-span-1 {grid-column: span 1 / span 1;}@@ -722,6 +738,10 @@ video {grid-column: 1 / -1;}+.col-span-3 {+ grid-column: span 3 / span 3;+}+.float-left {float: left;}@@ -1023,6 +1043,10 @@ video {max-height: 90vh;}+.max-h-64 {+ max-height: 16rem;+}+.min-h-\[250px\] {min-height: 250px;}@@ -1969,6 +1993,14 @@ video {padding: 2rem;}+.p-1 {+ padding: 0.25rem;+}++.p-1\.5 {+ padding: 0.375rem;+}+.px-2 {padding-left: 0.5rem;padding-right: 0.5rem;@@ -2609,6 +2641,10 @@ video {color: rgb(156 163 175 / var(--tw-text-opacity));}+.last\:border-b-0:last-child {+ border-bottom-width: 0px;+}+.hover\:scale-105:hover {--tw-scale-x: 1.05;--tw-scale-y: 1.05;@@ -2625,6 +2661,11 @@ video {border-color: rgb(252 165 165 / var(--tw-border-opacity));}+.hover\:border-primary-500:hover {+ --tw-border-opacity: 1;+ border-color: rgb(244 149 65 / var(--tw-border-opacity));+}+.hover\:bg-blue-600:hover {--tw-bg-opacity: 1;background-color: rgb(37 99 235 / var(--tw-bg-opacity));@@ -2825,10 +2866,19 @@ video {color: rgb(255 255 255 / var(--tw-text-opacity));}+.hover\:text-red-500:hover {+ --tw-text-opacity: 1;+ color: rgb(239 68 68 / var(--tw-text-opacity));+}+.hover\:underline:hover {text-decoration-line: underline;}+.hover\:opacity-80:hover {+ opacity: 0.8;+}+.hover\:file\:bg-primary-100::file-selector-button:hover {--tw-bg-opacity: 1;background-color: rgb(253 222 133 / var(--tw-bg-opacity));@@ -3413,6 +3463,11 @@ video {color: rgb(250 204 21 / var(--tw-text-opacity));}+.dark\:text-primary-300:is(.dark *) {+ --tw-text-opacity: 1;+ color: rgb(248 185 99 / var(--tw-text-opacity));+}+.dark\:placeholder-gray-400:is(.dark *)::-moz-placeholder {--tw-placeholder-opacity: 1;color: rgb(156 163 175 / var(--tw-placeholder-opacity));@@ -3545,6 +3600,10 @@ video {background-color: rgb(127 29 29 / 0.3);}+.dark\:hover\:bg-primary-900\/40:hover:is(.dark *) {+ background-color: rgb(123 74 30 / 0.4);+}+.dark\:hover\:from-primary-500:hover:is(.dark *) {--tw-gradient-from: #f49541 var(--tw-gradient-from-position);--tw-gradient-to: rgb(244 149 65 / 0) var(--tw-gradient-to-position);diff --git a/apps/server/AliasVault.Client/wwwroot/js/utilities.js b/apps/server/AliasVault.Client/wwwroot/js/utilities.jsindex 0d298ee8a..45e680cac 100644--- a/apps/server/AliasVault.Client/wwwroot/js/utilities.js+++ b/apps/server/AliasVault.Client/wwwroot/js/utilities.js@@ -533,7 +533,9 @@ const infiniteScrollObservers = new Map();* @param {any} dotnetHelper - The DotNetObjectReference to call back to.*/window.setupInfiniteScroll = function (element, dotnetHelper) {- if (!element) {+ // Element reference from Blazor may be an empty object if the element doesn't exist in DOM.+ // Check if element is a valid DOM Element.+ if (!element || !(element instanceof Element)) {return;}@@ -563,6 +565,11 @@ window.setupInfiniteScroll = function (element, dotnetHelper) {* @param {Element} element - The sentinel element that was being observed.*/window.teardownInfiniteScroll = function (element) {+ // Element reference from Blazor may be an empty object if the element doesn't exist in DOM.+ if (!element || !(element instanceof Element)) {+ return;+ }+const observer = infiniteScrollObservers.get(element);if (observer) {