From d1853f51f4b0ac38410afb17dd015bfc71f92ea7 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 8 Jan 2026 19:05:33 -0500 Subject: [PATCH] Refactor Journal Entry view: Extract Header and clean up Editor bindings --- .../journals/JournalEntry_Editor.svelte | 4 +- .../ae_comp__journal_entry_obj_id_view.svelte | 1302 ++--------------- 2 files changed, 139 insertions(+), 1167 deletions(-) diff --git a/src/routes/journals/JournalEntry_Editor.svelte b/src/routes/journals/JournalEntry_Editor.svelte index cb50b42e..4eb41fca 100644 --- a/src/routes/journals/JournalEntry_Editor.svelte +++ b/src/routes/journals/JournalEntry_Editor.svelte @@ -42,7 +42,7 @@ readonly={true} content={tmp_entry_obj?.content ?? ''} bind:new_content={tmp_entry_obj.content} - bind:theme_mode={$ae_loc.theme_mode} + theme_mode={$ae_loc.theme_mode} placeholder="No content..." class="p-2 preset-outlined-success-400-600 shadow-lg rounded-lg w-full max-w-6xl" /> @@ -87,7 +87,7 @@ content={tmp_entry_obj?.content ?? ''} bind:new_content={tmp_entry_obj.content} bind:editorView - bind:theme_mode={$ae_loc.theme_mode} + theme_mode={$ae_loc.theme_mode} placeholder="Write using Markdown..." class="p-2 preset-outlined-warning-300-700 shadow-lg rounded-lg w-full max-w-6xl bg-surface-50 dark:bg-surface-800" /> diff --git a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte index e992e3e8..42f05020 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte @@ -5,43 +5,7 @@ import { goto } from '$app/navigation'; // *** Import secondary libraries - import { - ArrowDown10, - BookHeart, - Bot, - BriefcaseBusiness, - Clock, - CodeXml, - Copy, - Eye, - EyeOff, - FileDown, - FileX, - Fingerprint, - Flag, - Globe, - History, - LockKeyhole, - LockKeyholeOpen, - MessageSquareWarning, - Menu, - Minus, - NotepadTextDashed, - Pencil, - PenLine, - Plus, - RemoveFormatting, - Save, - Shapes, - ShieldCheck, - Siren, - Skull, - SquareLibrary, - Tags, - Trash2, - TypeOutline, - X - } from '@lucide/svelte'; + import { marked } from 'marked'; // *** Import Aether components and helpers import E_app_codemirror_v5 from '$lib/app_components/e_app_codemirror_v5.svelte'; @@ -66,6 +30,7 @@ import AE_ObjectFlags from '$lib/ae_elements/AE_ObjectFlags.svelte'; import AE_MetadataFooter from '$lib/ae_elements/AE_MetadataFooter.svelte'; import JournalEntry_Editor from './JournalEntry_Editor.svelte'; + import JournalEntry_Header from './JournalEntry_Header.svelte'; // *** Props interface Props { @@ -122,55 +87,61 @@ return !obj || typeof obj !== 'object' || Object.keys(obj).length === 0; } - $effect(async () => { - if ($lq__journal_entry_obj && $lq__journal_entry_obj?.updated_on) { - if (log_lvl) console.log(`Journal Entry updated:`, $lq__journal_entry_obj); + $effect(() => { + (async () => { + if ($lq__journal_entry_obj && $lq__journal_entry_obj?.updated_on) { + if (log_lvl) console.log(`Journal Entry updated:`, $lq__journal_entry_obj); - orig_entry_obj = { ...$lq__journal_entry_obj }; - tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {}; + orig_entry_obj = { ...$lq__journal_entry_obj }; + tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {}; - tmp_entry_obj_changed = false; - updated_idb = false; - } else if (updated_obj && (await $lq__journal_entry_obj)) { - if (log_lvl) console.log(`Journal Entry forced update:`, $lq__journal_entry_obj); - updated_obj = false; - orig_entry_obj = { ...$lq__journal_entry_obj }; - tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {}; + tmp_entry_obj_changed = false; + updated_idb = false; + } else if (updated_obj && (await $lq__journal_entry_obj)) { + if (log_lvl) console.log(`Journal Entry forced update:`, $lq__journal_entry_obj); + updated_obj = false; + orig_entry_obj = { ...$lq__journal_entry_obj }; + tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {}; - if ($journals_loc?.entry?.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id]) { - let decrypt_key = $lq__journal_obj.combined_passcode; + if ($journals_loc?.entry?.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id]) { + let decrypt_key = $lq__journal_obj.combined_passcode; - if (!tmp_entry_obj?.content && tmp_entry_obj?.content_encrypted) { - tmp_entry_obj.content = await ae_util.decrypt_wrapper( - tmp_entry_obj?.content_encrypted, - decrypt_key - ); - tmp_entry_obj.content_md_html = handle_marked(tmp_entry_obj?.content); + if (!tmp_entry_obj?.content && tmp_entry_obj?.content_encrypted) { + tmp_entry_obj.content = await ae_util.decrypt_wrapper( + tmp_entry_obj?.content_encrypted, + decrypt_key + ); + tmp_entry_obj.content_md_html = handle_marked(tmp_entry_obj?.content); - orig_entry_obj.content = await ae_util.decrypt_wrapper( - orig_entry_obj?.content_encrypted, - decrypt_key - ); - orig_entry_obj.content_md_html = handle_marked(orig_entry_obj?.content); + if (orig_entry_obj) { + orig_entry_obj.content = await ae_util.decrypt_wrapper( + orig_entry_obj?.content_encrypted, + decrypt_key + ); + orig_entry_obj.content_md_html = handle_marked(orig_entry_obj?.content); + } + } + if (!tmp_entry_obj?.history && tmp_entry_obj?.history_encrypted) { + tmp_entry_obj.history = await ae_util.decrypt_wrapper( + tmp_entry_obj?.history_encrypted, + decrypt_key + ); + tmp_entry_obj.history_md_html = handle_marked(tmp_entry_obj?.history); + + if (orig_entry_obj) { + orig_entry_obj.history = await ae_util.decrypt_wrapper( + orig_entry_obj?.history_encrypted, + decrypt_key + ); + orig_entry_obj.history_md_html = handle_marked(orig_entry_obj?.history); + } + } } - if (!tmp_entry_obj?.history && tmp_entry_obj?.history_encrypted) { - tmp_entry_obj.history = await ae_util.decrypt_wrapper( - tmp_entry_obj?.history_encrypted, - decrypt_key - ); - tmp_entry_obj.history_md_html = handle_marked(tmp_entry_obj?.history); - orig_entry_obj.history = await ae_util.decrypt_wrapper( - orig_entry_obj?.history_encrypted, - decrypt_key - ); - orig_entry_obj.history_md_html = handle_marked(orig_entry_obj?.history); - } + tmp_entry_obj_changed = false; + updated_idb = false; } - - tmp_entry_obj_changed = false; - updated_idb = false; - } + })(); }); $effect(() => { @@ -196,13 +167,12 @@ $journals_sess?.journal_kv[$lq__journal_obj?.journal_id]?.journal_passcode_verified && !$journals_sess?.journal_kv[$lq__journal_obj?.journal_id]?.journal_passcode_decrypted ) { + let journal_key = null; if ( $journals_sess.journal_kv[$lq__journal_obj?.journal_id]?.typed_journal_passcode ?.length ) { - journal_key = ae_util.derive_key_from_passcode( - $journals_sess.journal_kv[$lq__journal_obj?.journal_id]?.typed_journal_passcode - ); + journal_key = $journals_sess.journal_kv[$lq__journal_obj?.journal_id]?.typed_journal_passcode; } else { journal_key = $lq__journal_obj?.private_passcode; } @@ -217,21 +187,79 @@ $journals_sess.journal_kv[$lq__journal_obj?.journal_id].journal_passcode_decrypted = 'processing'; - content_decrypted = ae_util.decrypt_wrapper( - $lq__journal_entry_obj?.content_encrypted, - journal_key - ); - console.log('TEST: Decrypted content:', content_decrypted); + (async () => { + let result = await ae_util.decrypt_wrapper( + $lq__journal_entry_obj?.content_encrypted, + journal_key + ); + content_decrypted = typeof result === 'string' ? result : ''; + console.log('TEST: Decrypted content:', content_decrypted); - $journals_sess.journal_kv[$lq__journal_obj?.journal_id].journal_passcode_decrypted = - true; + $journals_sess.journal_kv[$lq__journal_obj?.journal_id].journal_passcode_decrypted = + true; - // $journals_slct.journal_entry_obj.content_decrypted = content_decrypted; - tmp_entry_obj.content = content_decrypted; - tmp_entry_obj.content_md_html = handle_marked(content_decrypted); + tmp_entry_obj.content = content_decrypted; + tmp_entry_obj.content_md_html = handle_marked(content_decrypted); + })(); } }); + async function handle_content_decryption() { + if ( + tmp_entry_obj?.private && + $lq__journal_obj?.combined_passcode && + tmp_entry_obj?.content_encrypted + ) { + if (!tmp_entry_obj?.content) { + let result = await ae_util.decrypt_wrapper( + tmp_entry_obj?.content_encrypted, + $lq__journal_obj?.combined_passcode + ); + tmp_entry_obj.content = typeof result === 'string' ? result : ''; + tmp_entry_obj.content_md_html = await handle_marked(tmp_entry_obj?.content); + + // Also decrypt history if present + if (tmp_entry_obj?.history_encrypted) { + let h_result = await ae_util.decrypt_wrapper( + tmp_entry_obj?.history_encrypted, + $lq__journal_obj?.combined_passcode + ); + tmp_entry_obj.history = typeof h_result === 'string' ? h_result : ''; + tmp_entry_obj.history_md_html = await handle_marked(tmp_entry_obj?.history); + } + + $journals_sess.entry.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id] = true; + } else { + // Clear + tmp_entry_obj.content = null; + tmp_entry_obj.content_md_html = null; + tmp_entry_obj.history = null; + tmp_entry_obj.history_md_html = null; + $journals_sess.entry.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id] = false; + } + } + } + + async function handle_history_decryption() { + if (tmp_entry_obj?.history_encrypted) { + // Determine key + let key = $lq__journal_obj?.private_passcode; + if ( + $journals_sess.journal_kv[$lq__journal_obj?.journal_id]?.typed_journal_passcode + ?.length + ) { + key = + $journals_sess.journal_kv[$lq__journal_obj?.journal_id]?.typed_journal_passcode; + } + if (!key) key = $lq__journal_obj?.combined_passcode; + + let result = await ae_util.decrypt_wrapper(tmp_entry_obj?.history_encrypted, key); + decrypted_history = typeof result === 'string' ? result : ''; + tmp_entry_obj.history = decrypted_history; + tmp_entry_obj.history_md_html = await handle_marked(decrypted_history); + } + } + async function update_journal_entry() { if (!$ae_loc.trusted_access) { alert('You do not have permission to update this journal entry.'); @@ -281,7 +309,7 @@ tmp_entry_obj?.content_encrypted, decrypt_key ); - data_kv.content = decrypted_content; + data_kv.content = typeof decrypted_content === 'string' ? decrypted_content : ''; } else { data_kv.content = ''; } @@ -319,10 +347,11 @@ tmp_entry_obj.content = null; if (tmp_entry_obj?.history_encrypted) { - decrypted_history = await ae_util.decrypt_wrapper( + let result = await ae_util.decrypt_wrapper( tmp_entry_obj?.history_encrypted, decrypt_key ); + decrypted_history = typeof result === 'string' ? result : ''; tmp_entry_obj.history = decrypted_history; } @@ -470,1058 +499,19 @@ bind:clientHeight={$ae_loc.iframe_height_modal_body} > {#if $lq__journal_entry_obj} -
-
- - - -

- {#if $journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id] == 'current'} - - {:else} - - {#if $lq__journal_entry_obj?.name} - {@html $lq__journal_entry_obj?.name} - {:else} - {ae_util.iso_datetime_formatter( - $lq__journal_entry_obj?.created_on, - 'datetime_iso_12_no_seconds' - )} - {/if} - - {/if} -

-
- -
-
- - {#if $journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id] == 'current'} -
- - - - - - -
- {:else if $lq__journal_entry_obj.tags && $lq__journal_entry_obj.tags.length} -
- - - - - - - {#each $lq__journal_entry_obj.tags.split(',') as tag} - - {tag.trim()} - - {/each} -
- {/if} - - - {#if $lq__journal_entry_obj.category_code} -
- - - - - - {$lq__journal_entry_obj.category_code} - -
- {/if} - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - - - -
- - - - -
- - -
- - - - - - - update_journal_entry()} - hideAlert={$lq__journal_obj?.cfg_json?.hide_btn_alert} - hidePrivate={$lq__journal_obj?.cfg_json?.hide_btn_private} - hidePublic={$lq__journal_obj?.cfg_json?.hide_btn_public} - hidePersonal={$lq__journal_obj?.cfg_json?.hide_btn_personal} - hideProfessional={$lq__journal_obj?.cfg_json?.hide_btn_professional} - hideTemplate={$lq__journal_obj?.cfg_json?.hide_btn_template} - /> - - -
- - - - - - - - - - -
- - - - {#if $lq__journal_entry_obj?.history || $lq__journal_entry_obj?.history_encrypted} -
- - - -
- {/if} - - - - -
- - -
- - - - - - - - {#if $lq__journal_entry_obj?.sort} - {$lq__journal_entry_obj.sort} - {:else} - - - {/if} - - - - - - { - update_journal_entry(); - }} - class:hidden={!$ae_loc.edit_mode} - class="input input-sm input-bordered w-full mb-2" - title="Set group (for sorting) of this journal entry" - /> - - - - { - update_journal_entry(); - }} - class:hidden={!$ae_loc.edit_mode} - class="input input-sm input-bordered w-auto border-none" - title="Set archive on datetime for archiving this journal entry" - /> - - {#if $lq__journal_entry_obj?.archive_on} - - - {:else} - - - {/if} - - - - - - - - - - -
- - - {#if $ae_loc.edit_mode && $lq__journal_obj_li?.length} -
- - - - - - -
- {/if} -
-
-
-
+ +
@@ -1614,7 +586,7 @@