import type { VaultEntry } from '../types' import { parseFrontmatter } from '../utils/frontmatter' import { frontmatterToEntryPatch } from './frontmatterOps' function createRawEditorEntryState(): Partial { return { aliases: [], archived: false, belongsTo: [], color: null, favorite: false, favoriteIndex: null, icon: null, isA: null, listPropertiesDisplay: [], order: null, organized: false, properties: {}, relatedTo: [], relationships: {}, sidebarLabel: null, sort: null, status: null, template: null, view: null, visible: null, } } function mergeRelationships(target: Record, source: Record | null): void { if (!source) return for (const [key, value] of Object.entries(source)) { if (Array.isArray(value) && value.length > 0) target[key] = value } } function mergeProperties( target: Record, source: Record | null, ): void { if (!source) return for (const [key, value] of Object.entries(source)) { if (value !== null) target[key] = value } } export function deriveRawEditorEntryState(content: string): Partial { const derived = createRawEditorEntryState() const properties: Record = {} const relationships: Record = {} for (const [key, value] of Object.entries(parseFrontmatter(content))) { const { patch, relationshipPatch, propertiesPatch } = frontmatterToEntryPatch('update', key, value) Object.assign(derived, patch) mergeRelationships(relationships, relationshipPatch) mergeProperties(properties, propertiesPatch) } derived.properties = properties derived.relationships = relationships return derived }