Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Tweak AddEdit UI for all types (#1404)

Leendert de Borst48d17081dc55
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
index dd35beaa7..7684da038 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
@@ -17,7 +17,7 @@ import { useVaultMutate } from '@/entrypoints/popup/hooks/useVaultMutate';
import { IdentityHelperUtils, CreateIdentityGenerator, convertAgeRangeToBirthdateOptions } from '@/utils/dist/shared/identity-generator';
import type { Item, ItemField, ItemType, FieldType } from '@/utils/dist/shared/models/vault';
-import { getSystemFieldsForItemType } from '@/utils/dist/shared/models/vault';
+import { getSystemFieldsForItemType, isFieldShownByDefault, getOptionalFieldsForItemType } from '@/utils/dist/shared/models/vault';
import { CreatePasswordGenerator } from '@/utils/dist/shared/password-generator';
// Valid item types from the shared model
@@ -152,14 +152,15 @@ const ItemAddEdit: React.FC = () => {
}, [item]);
/**
- * Fields that should be shown inline with service name (like login.url).
- * These are Login category fields that start with "login." but aren't username/password.
+ * Get optional fields that are not shown by default for the current item type.
+ * These can be added via the "+" menu.
*/
- const serviceInlineFields = useMemo(() => {
- return applicableSystemFields.filter(field =>
- field.FieldKey === 'login.url'
- );
- }, [applicableSystemFields]);
+ const optionalFields = useMemo(() => {
+ if (!item) {
+ return [];
+ }
+ return getOptionalFieldsForItemType(item.ItemType);
+ }, [item]);
/**
* The notes field (login.notes) - handled separately for collapsible UI.
@@ -168,16 +169,30 @@ const ItemAddEdit: React.FC = () => {
return applicableSystemFields.find(field => field.FieldKey === 'login.notes');
}, [applicableSystemFields]);
+ /**
+ * Check if a field should be shown by default for the current item type.
+ */
+ const shouldShowFieldByDefault = useCallback((field: { FieldKey: string }) => {
+ if (!item) {
+ return false;
+ }
+ const systemField = applicableSystemFields.find(f => f.FieldKey === field.FieldKey);
+ if (!systemField) {
+ return true; // Custom fields are always shown
+ }
+ return isFieldShownByDefault(systemField, item.ItemType);
+ }, [item, applicableSystemFields]);
+
/**
* Group system fields by category for organized rendering.
- * Excludes service inline fields (login.url) and notes field.
+ * Excludes metadata fields (notes) which are handled separately.
*/
const groupedSystemFields = useMemo(() => {
const groups: Record<string, typeof applicableSystemFields> = {};
applicableSystemFields.forEach(field => {
- // Skip fields handled separately
- if (field.FieldKey === 'login.url' || field.FieldKey === 'login.notes') {
+ // Skip metadata fields (notes) - handled separately
+ if (field.Category === 'Metadata') {
return;
}
@@ -214,6 +229,13 @@ const ItemAddEdit: React.FC = () => {
UpdatedAt: new Date().toISOString()
});
+ // Check if notes should be shown by default for this type
+ const typeFields = getSystemFieldsForItemType(effectiveType);
+ const notesFieldDef = typeFields.find(f => f.FieldKey === 'login.notes');
+ if (notesFieldDef && isFieldShownByDefault(notesFieldDef, effectiveType)) {
+ setShowNotes(true);
+ }
+
// Load folders
if (dbContext?.sqliteClient) {
const allFolders = dbContext.sqliteClient.getAllFolders();
@@ -430,7 +452,12 @@ const ItemAddEdit: React.FC = () => {
setFieldValues({});
setCustomFields([]);
setShowAliasFields(false);
- setShowNotes(false);
+
+ // Check if notes should be shown by default for the new type
+ const newTypeFields = getSystemFieldsForItemType(newType);
+ const newNotesField = newTypeFields.find(f => f.FieldKey === 'login.notes');
+ const notesShownByDefault = newNotesField ? isFieldShownByDefault(newNotesField, newType) : false;
+ setShowNotes(notesShownByDefault);
setItem({
...item,
@@ -574,8 +601,9 @@ const ItemAddEdit: React.FC = () => {
action: () => void;
}> = [];
- // Notes option (when not shown and no value)
- if (notesField && !showNotes && !fieldValues['login.notes'] && !isEditMode) {
+ // Notes option - show when notes field exists, is optional (not shown by default), not yet shown, and has no value
+ const notesIsOptional = notesField && !shouldShowFieldByDefault(notesField);
+ if (notesField && notesIsOptional && !showNotes && !fieldValues['login.notes'] && !isEditMode) {
options.push({
key: 'notes',
label: t('credentials.notes'),
@@ -601,14 +629,20 @@ const ItemAddEdit: React.FC = () => {
});
return options;
- }, [showNotes, notesField, fieldValues, isEditMode, t, handleAddNotesFromMenu, handleAddCustomFieldFromMenu]);
+ }, [showNotes, notesField, fieldValues, isEditMode, t, handleAddNotesFromMenu, handleAddCustomFieldFromMenu, shouldShowFieldByDefault]);
/**
- * Whether to show the dedicated "Add alias" button (for Login type in create mode when alias not shown).
+ * Whether to show the dedicated "Add alias" button.
+ * Show when alias fields exist as optional (not shown by default) and not yet added.
*/
const showAddAliasButton = useMemo(() => {
- return item?.ItemType === 'Login' && !showAliasFields && !isEditMode;
- }, [item?.ItemType, showAliasFields, isEditMode]);
+ if (!item || isEditMode) {
+ return false;
+ }
+ // Check if there are any alias fields that are optional (not shown by default)
+ const hasOptionalAliasFields = optionalFields.some(f => f.Category === 'Alias');
+ return hasOptionalAliasFields && !showAliasFields;
+ }, [item, optionalFields, showAliasFields, isEditMode]);
// Set header buttons
useEffect(() => {
@@ -812,71 +846,55 @@ const ItemAddEdit: React.FC = () => {
</div>
)}
- {/* Service Section - Name and URL */}
+ {/* Item Name - Central prominent field */}
<div className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700">
- <h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white">{t('credentials.service')}</h2>
- <div className="space-y-4">
- {/* Service Name with Folder Button */}
- <div>
- <label htmlFor="itemName" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
- {t('credentials.serviceName')} <span className="text-red-500">*</span>
- </label>
- <div className="relative">
- <input
- id="itemName"
- type="text"
- value={item.Name || ''}
- onChange={(e) => setItem({ ...item, Name: e.target.value })}
- placeholder={t('credentials.serviceName')}
- className={`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 ${folders.length > 0 ? 'pr-28' : ''}`}
- required
- />
- {/* Folder Button inside input */}
- {folders.length > 0 && (
- <button
- type="button"
- onClick={() => setShowFolderModal(true)}
- className={`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-1 px-2 py-1 rounded transition-colors text-xs ${
- item.FolderId
- ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50'
- : 'text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600'
- }`}
- title={item.FolderId ? folders.find(f => f.Id === item.FolderId)?.Name || t('items.folder') : t('items.noFolder')}
- >
- <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
- </svg>
- {item.FolderId && (
- <span className="max-w-16 truncate">
- {folders.find(f => f.Id === item.FolderId)?.Name}
- </span>
- )}
- </button>
- )}
- </div>
- </div>
- {/* Service inline fields (login.url) - shown without header */}
- {serviceInlineFields.map(field => (
- <div key={field.FieldKey}>
- {renderFieldInput(
- field.FieldKey,
- field.Label,
- field.FieldType,
- field.IsHidden,
- field.IsMultiValue
+ <label htmlFor="itemName" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
+ {t('credentials.itemName')} <span className="text-red-500">*</span>
+ </label>
+ <div className="relative">
+ <input
+ id="itemName"
+ type="text"
+ value={item.Name || ''}
+ onChange={(e) => setItem({ ...item, Name: e.target.value })}
+ placeholder={t('credentials.itemName')}
+ className={`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 ${folders.length > 0 ? 'pr-28' : ''}`}
+ required
+ />
+ {/* Folder Button inside input */}
+ {folders.length > 0 && (
+ <button
+ type="button"
+ onClick={() => setShowFolderModal(true)}
+ className={`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-1 px-2 py-1 rounded transition-colors text-xs ${
+ item.FolderId
+ ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50'
+ : 'text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600'
+ }`}
+ title={item.FolderId ? folders.find(f => f.Id === item.FolderId)?.Name || t('items.folder') : t('items.noFolder')}
+ >
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
+ </svg>
+ {item.FolderId && (
+ <span className="max-w-16 truncate">
+ {folders.find(f => f.Id === item.FolderId)?.Name}
+ </span>
)}
- </div>
- ))}
+ </button>
+ )}
</div>
</div>
{/* Render fields grouped by category */}
{Object.keys(groupedSystemFields).map(category => {
- // Special handling for Alias category in Login type (create mode only)
- const isAliasInLoginCreate = category === 'Alias' && item.ItemType === 'Login' && !isEditMode;
+ // Check if this category has any fields that are optional (not shown by default)
+ const categoryFields = groupedSystemFields[category];
+ const allFieldsOptional = categoryFields.every(f => !shouldShowFieldByDefault(f));
+ const isOptionalCategory = category === 'Alias' && allFieldsOptional && !isEditMode;
- // If alias in login create mode and not shown, skip rendering (will be available via + menu)
- if (isAliasInLoginCreate && !showAliasFields) {
+ // If this is an optional category and not shown, skip rendering (will be available via + button)
+ if (isOptionalCategory && !showAliasFields) {
return null;
}
@@ -884,15 +902,15 @@ const ItemAddEdit: React.FC = () => {
<div key={category} className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700">
<h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white flex items-center justify-between">
<span>
- {category === 'Login' && t('credentials.loginCredentials')}
+ {category === 'Login' && t('common.credentials')}
{category === 'Alias' && t('credentials.alias')}
{category === 'Card' && t('credentials.cardInformation')}
{category === 'Identity' && t('credentials.identityInformation')}
{category !== 'Login' && category !== 'Alias' && category !== 'Card' && category !== 'Identity' && category}
</span>
- {/* Show action buttons for Alias section in Login create mode */}
- {isAliasInLoginCreate && showAliasFields && (
+ {/* Show action buttons for optional Alias section in create mode */}
+ {isOptionalCategory && showAliasFields && (
<div className="flex items-center gap-2">
{/* Regenerate button */}
<button
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemDetails.tsx b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemDetails.tsx
index b21282c59..0123deae7 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemDetails.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemDetails.tsx
@@ -181,7 +181,7 @@ const ItemDetails: React.FC = (): React.ReactElement => {
{groupedFields.Login && groupedFields.Login.length > 0 && (
<div className="space-y-2">
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">
- {t('credentials.loginCredentials')}
+ {t('common.credentials')}
</h2>
{groupedFields.Login.map((field) => (
<FieldBlock key={field.FieldKey} field={field} itemId={item.Id} />
diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.json
index 75de7acbe..2598353ce 100644
--- a/apps/browser-extension/src/i18n/locales/en.json
+++ b/apps/browser-extension/src/i18n/locales/en.json
@@ -80,6 +80,7 @@
"settings": "Settings",
"recentEmails": "Recent emails",
"loginCredentials": "Login credentials",
+ "credentials": "Credentials",
"customFields": "Custom",
"twoFactorAuthentication": "Two-factor authentication",
"alias": "Alias",
@@ -191,6 +192,7 @@
"deleteCredential": "Delete Credential",
"credentialDetails": "Credential Details",
"serviceName": "Service Name",
+ "itemName": "Name",
"notes": "Notes",
"totp": "Two-Factor Authentication",
"totpCode": "TOTP Code",
@@ -245,6 +247,7 @@
"validation": {
"required": "This field is required",
"serviceNameRequired": "Service name is required",
+ "nameRequired": "Name is required",
"invalidEmail": "Invalid email format",
"invalidDateFormat": "Date must be in YYYY-MM-DD format"
},
diff --git a/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts b/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts
index c3900b676..55c7c461e 100644
--- a/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts
@@ -397,6 +397,14 @@ declare function groupFieldsByCategory(item: Item): Record<string, ItemField[]>;
*/
declare function itemToCredential(item: Item): Credential;
+/**
+ * Per-item-type configuration for a system field.
+ * Allows specifying different behavior for each item type the field applies to.
+ */
+type ItemTypeFieldConfig = {
+ /** Whether this field is shown by default in create mode (vs. hidden behind an "add" button) */
+ ShowByDefault: boolean;
+};
/**
* System field definition with metadata.
* System fields are predefined fields with immutable keys like 'login.username'.
@@ -413,12 +421,15 @@ type SystemFieldDefinition = {
IsHidden: boolean;
/** Whether field supports multiple values */
IsMultiValue: boolean;
- /** Item types this field applies to */
- ApplicableToTypes: ItemType[];
+ /**
+ * Item types this field applies to, with per-type configuration.
+ * Key is ItemType, value is the configuration for that type.
+ */
+ ApplicableToTypes: Partial<Record<ItemType, ItemTypeFieldConfig>>;
/** Whether to track field value history */
EnableHistory: boolean;
/** Category for grouping in UI */
- Category: 'Login' | 'Alias' | 'Card' | 'Identity' | 'API' | 'Note';
+ Category: 'Login' | 'Alias' | 'Card' | 'Identity' | 'API' | 'Metadata';
/** Default display order within category (lower = first) */
DefaultDisplayOrder: number;
};
@@ -437,11 +448,36 @@ declare function getSystemField(fieldKey: string): SystemFieldDefinition | undef
* Check if a field key represents a system field.
*/
declare function isSystemField(fieldKey: string): boolean;
+/**
+ * Check if a field applies to a specific item type.
+ */
+declare function fieldAppliesToType(field: SystemFieldDefinition, itemType: ItemType): boolean;
+/**
+ * Get the per-type configuration for a field and item type.
+ * Returns undefined if the field doesn't apply to that item type.
+ */
+declare function getFieldConfigForType(field: SystemFieldDefinition, itemType: ItemType): ItemTypeFieldConfig | undefined;
+/**
+ * Check if a field should be shown by default for a specific item type.
+ * Returns false if the field doesn't apply to that item type.
+ */
+declare function isFieldShownByDefault(field: SystemFieldDefinition, itemType: ItemType): boolean;
/**
* Get all system fields applicable to a specific item type.
* Results are sorted by DefaultDisplayOrder.
*/
declare function getSystemFieldsForItemType(itemType: ItemType): SystemFieldDefinition[];
+/**
+ * Get system fields that should be shown by default for a specific item type.
+ * Results are sorted by DefaultDisplayOrder.
+ */
+declare function getDefaultFieldsForItemType(itemType: ItemType): SystemFieldDefinition[];
+/**
+ * Get system fields that are NOT shown by default for a specific item type.
+ * These are the fields that can be added via an "add field" button.
+ * Results are sorted by DefaultDisplayOrder.
+ */
+declare function getOptionalFieldsForItemType(itemType: ItemType): SystemFieldDefinition[];
/**
* Get all system field keys.
*/
@@ -478,4 +514,4 @@ type FieldHistory = {
*/
declare const MAX_FIELD_HISTORY_RECORDS = 10;
-export { type Alias, type Attachment, type Credential, type EncryptionKey, type FieldHistory, FieldKey, type FieldKeyValue, type FieldType, type Item, type ItemField, type ItemTag, type ItemTagRef, type ItemType, MAX_FIELD_HISTORY_RECORDS, type Passkey, type PasswordSettings, type SystemFieldDefinition, SystemFieldRegistry, type Tag, type TotpCode, getAllSystemFieldKeys, getFieldValue, getFieldValues, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isSystemField, isSystemFieldPrefix, itemToCredential };
+export { type Alias, type Attachment, type Credential, type EncryptionKey, type FieldHistory, FieldKey, type FieldKeyValue, type FieldType, type Item, type ItemField, type ItemTag, type ItemTagRef, type ItemType, type ItemTypeFieldConfig, MAX_FIELD_HISTORY_RECORDS, type Passkey, type PasswordSettings, type SystemFieldDefinition, SystemFieldRegistry, type Tag, type TotpCode, fieldAppliesToType, getAllSystemFieldKeys, getDefaultFieldsForItemType, getFieldConfigForType, getFieldValue, getFieldValues, getOptionalFieldsForItemType, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isFieldShownByDefault, isSystemField, isSystemFieldPrefix, itemToCredential };
diff --git a/apps/browser-extension/src/utils/dist/shared/models/vault/index.js b/apps/browser-extension/src/utils/dist/shared/models/vault/index.js
index c8b416787..350b1bba6 100644
--- a/apps/browser-extension/src/utils/dist/shared/models/vault/index.js
+++ b/apps/browser-extension/src/utils/dist/shared/models/vault/index.js
@@ -232,7 +232,9 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: true,
Category: "Login",
DefaultDisplayOrder: 10
@@ -243,31 +245,41 @@ var SystemFieldRegistry = {
FieldType: "Password",
IsHidden: true,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: true,
Category: "Login",
DefaultDisplayOrder: 20
},
"login.url": {
FieldKey: "login.url",
- Label: "Website",
+ Label: "URL",
FieldType: "URL",
IsHidden: false,
IsMultiValue: true,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Login",
DefaultDisplayOrder: 30
},
+ // Metadata Fields
"login.notes": {
FieldKey: "login.notes",
Label: "Notes",
FieldType: "TextArea",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "CreditCard", "Identity", "Note"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ CreditCard: { ShowByDefault: false },
+ Identity: { ShowByDefault: false },
+ Note: { ShowByDefault: true }
+ },
EnableHistory: false,
- Category: "Login",
+ Category: "Metadata",
DefaultDisplayOrder: 100
},
// Alias Fields
@@ -277,7 +289,9 @@ var SystemFieldRegistry = {
FieldType: "Email",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false }
+ },
EnableHistory: true,
Category: "Alias",
DefaultDisplayOrder: 10
@@ -288,7 +302,10 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 20
@@ -299,7 +316,10 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 30
@@ -310,7 +330,9 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 40
@@ -321,7 +343,10 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 50
@@ -332,7 +357,10 @@ var SystemFieldRegistry = {
FieldType: "Date",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 60
@@ -351,19 +379,35 @@ function getSystemField(fieldKey) {
function isSystemField(fieldKey) {
return fieldKey in SystemFieldRegistry;
}
+function fieldAppliesToType(field, itemType) {
+ return itemType in field.ApplicableToTypes;
+}
+function getFieldConfigForType(field, itemType) {
+ return field.ApplicableToTypes[itemType];
+}
+function isFieldShownByDefault(field, itemType) {
+ const config = field.ApplicableToTypes[itemType];
+ return config?.ShowByDefault ?? false;
+}
function getSystemFieldsForItemType(itemType) {
- return Object.values(SystemFieldRegistry).filter((field) => field.ApplicableToTypes.includes(itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+ return Object.values(SystemFieldRegistry).filter((field) => fieldAppliesToType(field, itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+}
+function getDefaultFieldsForItemType(itemType) {
+ return Object.values(SystemFieldRegistry).filter((field) => isFieldShownByDefault(field, itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+}
+function getOptionalFieldsForItemType(itemType) {
+ return Object.values(SystemFieldRegistry).filter((field) => fieldAppliesToType(field, itemType) && !isFieldShownByDefault(field, itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
}
function getAllSystemFieldKeys() {
return Object.keys(SystemFieldRegistry);
}
function isSystemFieldPrefix(fieldKey) {
- return fieldKey.startsWith("login.") || fieldKey.startsWith("alias.") || fieldKey.startsWith("card.") || fieldKey.startsWith("identity.") || fieldKey.startsWith("api.") || fieldKey.startsWith("note.");
+ return fieldKey.startsWith("login.") || fieldKey.startsWith("alias.") || fieldKey.startsWith("card.") || fieldKey.startsWith("identity.") || fieldKey.startsWith("api.") || fieldKey.startsWith("note.") || fieldKey.startsWith("metadata.");
}
// src/vault/FieldHistory.ts
var MAX_FIELD_HISTORY_RECORDS = 10;
-export { FieldKey, MAX_FIELD_HISTORY_RECORDS, SystemFieldRegistry, getAllSystemFieldKeys, getFieldValue, getFieldValues, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isSystemField, isSystemFieldPrefix, itemToCredential };
+export { FieldKey, MAX_FIELD_HISTORY_RECORDS, SystemFieldRegistry, fieldAppliesToType, getAllSystemFieldKeys, getDefaultFieldsForItemType, getFieldConfigForType, getFieldValue, getFieldValues, getOptionalFieldsForItemType, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isFieldShownByDefault, isSystemField, isSystemFieldPrefix, itemToCredential };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts b/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts
index c3900b676..55c7c461e 100644
--- a/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts
+++ b/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts
@@ -397,6 +397,14 @@ declare function groupFieldsByCategory(item: Item): Record<string, ItemField[]>;
*/
declare function itemToCredential(item: Item): Credential;
+/**
+ * Per-item-type configuration for a system field.
+ * Allows specifying different behavior for each item type the field applies to.
+ */
+type ItemTypeFieldConfig = {
+ /** Whether this field is shown by default in create mode (vs. hidden behind an "add" button) */
+ ShowByDefault: boolean;
+};
/**
* System field definition with metadata.
* System fields are predefined fields with immutable keys like 'login.username'.
@@ -413,12 +421,15 @@ type SystemFieldDefinition = {
IsHidden: boolean;
/** Whether field supports multiple values */
IsMultiValue: boolean;
- /** Item types this field applies to */
- ApplicableToTypes: ItemType[];
+ /**
+ * Item types this field applies to, with per-type configuration.
+ * Key is ItemType, value is the configuration for that type.
+ */
+ ApplicableToTypes: Partial<Record<ItemType, ItemTypeFieldConfig>>;
/** Whether to track field value history */
EnableHistory: boolean;
/** Category for grouping in UI */
- Category: 'Login' | 'Alias' | 'Card' | 'Identity' | 'API' | 'Note';
+ Category: 'Login' | 'Alias' | 'Card' | 'Identity' | 'API' | 'Metadata';
/** Default display order within category (lower = first) */
DefaultDisplayOrder: number;
};
@@ -437,11 +448,36 @@ declare function getSystemField(fieldKey: string): SystemFieldDefinition | undef
* Check if a field key represents a system field.
*/
declare function isSystemField(fieldKey: string): boolean;
+/**
+ * Check if a field applies to a specific item type.
+ */
+declare function fieldAppliesToType(field: SystemFieldDefinition, itemType: ItemType): boolean;
+/**
+ * Get the per-type configuration for a field and item type.
+ * Returns undefined if the field doesn't apply to that item type.
+ */
+declare function getFieldConfigForType(field: SystemFieldDefinition, itemType: ItemType): ItemTypeFieldConfig | undefined;
+/**
+ * Check if a field should be shown by default for a specific item type.
+ * Returns false if the field doesn't apply to that item type.
+ */
+declare function isFieldShownByDefault(field: SystemFieldDefinition, itemType: ItemType): boolean;
/**
* Get all system fields applicable to a specific item type.
* Results are sorted by DefaultDisplayOrder.
*/
declare function getSystemFieldsForItemType(itemType: ItemType): SystemFieldDefinition[];
+/**
+ * Get system fields that should be shown by default for a specific item type.
+ * Results are sorted by DefaultDisplayOrder.
+ */
+declare function getDefaultFieldsForItemType(itemType: ItemType): SystemFieldDefinition[];
+/**
+ * Get system fields that are NOT shown by default for a specific item type.
+ * These are the fields that can be added via an "add field" button.
+ * Results are sorted by DefaultDisplayOrder.
+ */
+declare function getOptionalFieldsForItemType(itemType: ItemType): SystemFieldDefinition[];
/**
* Get all system field keys.
*/
@@ -478,4 +514,4 @@ type FieldHistory = {
*/
declare const MAX_FIELD_HISTORY_RECORDS = 10;
-export { type Alias, type Attachment, type Credential, type EncryptionKey, type FieldHistory, FieldKey, type FieldKeyValue, type FieldType, type Item, type ItemField, type ItemTag, type ItemTagRef, type ItemType, MAX_FIELD_HISTORY_RECORDS, type Passkey, type PasswordSettings, type SystemFieldDefinition, SystemFieldRegistry, type Tag, type TotpCode, getAllSystemFieldKeys, getFieldValue, getFieldValues, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isSystemField, isSystemFieldPrefix, itemToCredential };
+export { type Alias, type Attachment, type Credential, type EncryptionKey, type FieldHistory, FieldKey, type FieldKeyValue, type FieldType, type Item, type ItemField, type ItemTag, type ItemTagRef, type ItemType, type ItemTypeFieldConfig, MAX_FIELD_HISTORY_RECORDS, type Passkey, type PasswordSettings, type SystemFieldDefinition, SystemFieldRegistry, type Tag, type TotpCode, fieldAppliesToType, getAllSystemFieldKeys, getDefaultFieldsForItemType, getFieldConfigForType, getFieldValue, getFieldValues, getOptionalFieldsForItemType, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isFieldShownByDefault, isSystemField, isSystemFieldPrefix, itemToCredential };
diff --git a/apps/mobile-app/utils/dist/shared/models/vault/index.js b/apps/mobile-app/utils/dist/shared/models/vault/index.js
index c8b416787..350b1bba6 100644
--- a/apps/mobile-app/utils/dist/shared/models/vault/index.js
+++ b/apps/mobile-app/utils/dist/shared/models/vault/index.js
@@ -232,7 +232,9 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: true,
Category: "Login",
DefaultDisplayOrder: 10
@@ -243,31 +245,41 @@ var SystemFieldRegistry = {
FieldType: "Password",
IsHidden: true,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: true,
Category: "Login",
DefaultDisplayOrder: 20
},
"login.url": {
FieldKey: "login.url",
- Label: "Website",
+ Label: "URL",
FieldType: "URL",
IsHidden: false,
IsMultiValue: true,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Login",
DefaultDisplayOrder: 30
},
+ // Metadata Fields
"login.notes": {
FieldKey: "login.notes",
Label: "Notes",
FieldType: "TextArea",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "CreditCard", "Identity", "Note"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ CreditCard: { ShowByDefault: false },
+ Identity: { ShowByDefault: false },
+ Note: { ShowByDefault: true }
+ },
EnableHistory: false,
- Category: "Login",
+ Category: "Metadata",
DefaultDisplayOrder: 100
},
// Alias Fields
@@ -277,7 +289,9 @@ var SystemFieldRegistry = {
FieldType: "Email",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false }
+ },
EnableHistory: true,
Category: "Alias",
DefaultDisplayOrder: 10
@@ -288,7 +302,10 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 20
@@ -299,7 +316,10 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 30
@@ -310,7 +330,9 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 40
@@ -321,7 +343,10 @@ var SystemFieldRegistry = {
FieldType: "Text",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 50
@@ -332,7 +357,10 @@ var SystemFieldRegistry = {
FieldType: "Date",
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ["Login", "Identity"],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: "Alias",
DefaultDisplayOrder: 60
@@ -351,19 +379,35 @@ function getSystemField(fieldKey) {
function isSystemField(fieldKey) {
return fieldKey in SystemFieldRegistry;
}
+function fieldAppliesToType(field, itemType) {
+ return itemType in field.ApplicableToTypes;
+}
+function getFieldConfigForType(field, itemType) {
+ return field.ApplicableToTypes[itemType];
+}
+function isFieldShownByDefault(field, itemType) {
+ const config = field.ApplicableToTypes[itemType];
+ return config?.ShowByDefault ?? false;
+}
function getSystemFieldsForItemType(itemType) {
- return Object.values(SystemFieldRegistry).filter((field) => field.ApplicableToTypes.includes(itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+ return Object.values(SystemFieldRegistry).filter((field) => fieldAppliesToType(field, itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+}
+function getDefaultFieldsForItemType(itemType) {
+ return Object.values(SystemFieldRegistry).filter((field) => isFieldShownByDefault(field, itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+}
+function getOptionalFieldsForItemType(itemType) {
+ return Object.values(SystemFieldRegistry).filter((field) => fieldAppliesToType(field, itemType) && !isFieldShownByDefault(field, itemType)).sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
}
function getAllSystemFieldKeys() {
return Object.keys(SystemFieldRegistry);
}
function isSystemFieldPrefix(fieldKey) {
- return fieldKey.startsWith("login.") || fieldKey.startsWith("alias.") || fieldKey.startsWith("card.") || fieldKey.startsWith("identity.") || fieldKey.startsWith("api.") || fieldKey.startsWith("note.");
+ return fieldKey.startsWith("login.") || fieldKey.startsWith("alias.") || fieldKey.startsWith("card.") || fieldKey.startsWith("identity.") || fieldKey.startsWith("api.") || fieldKey.startsWith("note.") || fieldKey.startsWith("metadata.");
}
// src/vault/FieldHistory.ts
var MAX_FIELD_HISTORY_RECORDS = 10;
-export { FieldKey, MAX_FIELD_HISTORY_RECORDS, SystemFieldRegistry, getAllSystemFieldKeys, getFieldValue, getFieldValues, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isSystemField, isSystemFieldPrefix, itemToCredential };
+export { FieldKey, MAX_FIELD_HISTORY_RECORDS, SystemFieldRegistry, fieldAppliesToType, getAllSystemFieldKeys, getDefaultFieldsForItemType, getFieldConfigForType, getFieldValue, getFieldValues, getOptionalFieldsForItemType, getSystemField, getSystemFieldsForItemType, groupFields, groupFieldsByCategory, hasField, isFieldShownByDefault, isSystemField, isSystemFieldPrefix, itemToCredential };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/shared/models/src/vault/SystemFieldRegistry.ts b/shared/models/src/vault/SystemFieldRegistry.ts
index 72e3b0e09..902888078 100644
--- a/shared/models/src/vault/SystemFieldRegistry.ts
+++ b/shared/models/src/vault/SystemFieldRegistry.ts
@@ -1,5 +1,14 @@
import type { FieldType, ItemType } from './Item';
+/**
+ * Per-item-type configuration for a system field.
+ * Allows specifying different behavior for each item type the field applies to.
+ */
+export type ItemTypeFieldConfig = {
+ /** Whether this field is shown by default in create mode (vs. hidden behind an "add" button) */
+ ShowByDefault: boolean;
+};
+
/**
* System field definition with metadata.
* System fields are predefined fields with immutable keys like 'login.username'.
@@ -16,12 +25,15 @@ export type SystemFieldDefinition = {
IsHidden: boolean;
/** Whether field supports multiple values */
IsMultiValue: boolean;
- /** Item types this field applies to */
- ApplicableToTypes: ItemType[];
+ /**
+ * Item types this field applies to, with per-type configuration.
+ * Key is ItemType, value is the configuration for that type.
+ */
+ ApplicableToTypes: Partial<Record<ItemType, ItemTypeFieldConfig>>;
/** Whether to track field value history */
EnableHistory: boolean;
/** Category for grouping in UI */
- Category: 'Login' | 'Alias' | 'Card' | 'Identity' | 'API' | 'Note';
+ Category: 'Login' | 'Alias' | 'Card' | 'Identity' | 'API' | 'Metadata';
/** Default display order within category (lower = first) */
DefaultDisplayOrder: number;
};
@@ -39,7 +51,9 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Text',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: true,
Category: 'Login',
DefaultDisplayOrder: 10
@@ -50,31 +64,42 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Password',
IsHidden: true,
IsMultiValue: false,
- ApplicableToTypes: ['Login'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: true,
Category: 'Login',
DefaultDisplayOrder: 20
},
'login.url': {
FieldKey: 'login.url',
- Label: 'Website',
+ Label: 'URL',
FieldType: 'URL',
IsHidden: false,
IsMultiValue: true,
- ApplicableToTypes: ['Login'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: 'Login',
DefaultDisplayOrder: 30
},
+
+ // Metadata Fields
'login.notes': {
FieldKey: 'login.notes',
Label: 'Notes',
FieldType: 'TextArea',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login', 'CreditCard', 'Identity', 'Note'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ CreditCard: { ShowByDefault: false },
+ Identity: { ShowByDefault: false },
+ Note: { ShowByDefault: true }
+ },
EnableHistory: false,
- Category: 'Login',
+ Category: 'Metadata',
DefaultDisplayOrder: 100
},
@@ -85,7 +110,9 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Email',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false }
+ },
EnableHistory: true,
Category: 'Alias',
DefaultDisplayOrder: 10
@@ -96,7 +123,10 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Text',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login', 'Identity'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: 'Alias',
DefaultDisplayOrder: 20
@@ -107,7 +137,10 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Text',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login', 'Identity'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: 'Alias',
DefaultDisplayOrder: 30
@@ -118,7 +151,9 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Text',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false }
+ },
EnableHistory: false,
Category: 'Alias',
DefaultDisplayOrder: 40
@@ -129,7 +164,10 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Text',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login', 'Identity'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: 'Alias',
DefaultDisplayOrder: 50
@@ -140,7 +178,10 @@ export const SystemFieldRegistry: Record<string, SystemFieldDefinition> = {
FieldType: 'Date',
IsHidden: false,
IsMultiValue: false,
- ApplicableToTypes: ['Login', 'Identity'],
+ ApplicableToTypes: {
+ Login: { ShowByDefault: false },
+ Identity: { ShowByDefault: true }
+ },
EnableHistory: false,
Category: 'Alias',
DefaultDisplayOrder: 60
@@ -170,13 +211,58 @@ export function isSystemField(fieldKey: string): boolean {
return fieldKey in SystemFieldRegistry;
}
+/**
+ * Check if a field applies to a specific item type.
+ */
+export function fieldAppliesToType(field: SystemFieldDefinition, itemType: ItemType): boolean {
+ return itemType in field.ApplicableToTypes;
+}
+
+/**
+ * Get the per-type configuration for a field and item type.
+ * Returns undefined if the field doesn't apply to that item type.
+ */
+export function getFieldConfigForType(field: SystemFieldDefinition, itemType: ItemType): ItemTypeFieldConfig | undefined {
+ return field.ApplicableToTypes[itemType];
+}
+
+/**
+ * Check if a field should be shown by default for a specific item type.
+ * Returns false if the field doesn't apply to that item type.
+ */
+export function isFieldShownByDefault(field: SystemFieldDefinition, itemType: ItemType): boolean {
+ const config = field.ApplicableToTypes[itemType];
+ return config?.ShowByDefault ?? false;
+}
+
/**
* Get all system fields applicable to a specific item type.
* Results are sorted by DefaultDisplayOrder.
*/
export function getSystemFieldsForItemType(itemType: ItemType): SystemFieldDefinition[] {
return Object.values(SystemFieldRegistry)
- .filter(field => field.ApplicableToTypes.includes(itemType))
+ .filter(field => fieldAppliesToType(field, itemType))
+ .sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+}
+
+/**
+ * Get system fields that should be shown by default for a specific item type.
+ * Results are sorted by DefaultDisplayOrder.
+ */
+export function getDefaultFieldsForItemType(itemType: ItemType): SystemFieldDefinition[] {
+ return Object.values(SystemFieldRegistry)
+ .filter(field => isFieldShownByDefault(field, itemType))
+ .sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
+}
+
+/**
+ * Get system fields that are NOT shown by default for a specific item type.
+ * These are the fields that can be added via an "add field" button.
+ * Results are sorted by DefaultDisplayOrder.
+ */
+export function getOptionalFieldsForItemType(itemType: ItemType): SystemFieldDefinition[] {
+ return Object.values(SystemFieldRegistry)
+ .filter(field => fieldAppliesToType(field, itemType) && !isFieldShownByDefault(field, itemType))
.sort((a, b) => a.DefaultDisplayOrder - b.DefaultDisplayOrder);
}
@@ -197,5 +283,6 @@ export function isSystemFieldPrefix(fieldKey: string): boolean {
fieldKey.startsWith('card.') ||
fieldKey.startsWith('identity.') ||
fieldKey.startsWith('api.') ||
- fieldKey.startsWith('note.');
+ fieldKey.startsWith('note.') ||
+ fieldKey.startsWith('metadata.');
}