From 8596e44c7f5b08c63c8ee09a89be8d3122819008 Mon Sep 17 00:00:00 2001 From: SecPan Date: Fri, 10 Jul 2026 08:23:31 -0700 Subject: [PATCH] Extract editor-session lifecycle from App.vue App.vue owned the Muya editor instance and all of its low-level runtime machinery directly: the module-scope editor variable and init token, the host-element ref, initialization with stale-init protection, the destroy/remount cycle behind opening a document, Markdown snapshots and document-state sync, post-open focus release, and the input/selection diagnostic hooks. That machinery now lives in a dedicated editor-session factory (createEditorSession in src/features/editor/editorSession.ts), and App.vue reaches the editor only through the session accessors. The session deliberately does not become a second application controller: status text policy, autosave scheduling, toolbar and link/image business actions, navigation, persistence, and Android workflows all stay in App.vue and are reached through injected collaborators (syncMarkdown, focus/blur handlers, selection-lifecycle functions, autosave timer handles), following the same factory-with-injected-options pattern as the existing selection lifecycle, autosave scheduler, and persistence modules. Everything moved verbatim; the only equivalence rewrites are syncMarkdown reusing the extracted syncDocumentFromEditor (same guard, normalization, and update call) and the init-complete log reading documentState stats directly instead of through App computeds that resolve to the same fields. Initialization ordering, token-based stale protection, cleanup on destroy and unmount, suppression reasons, and diagnostics semantics are unchanged. editorRuntime now exports CreateMuyaEditorOptions so the session can type the injected factory. New editorSession tests cover open/ready wiring, missing host element, stale-init supersession, the remount-through-home cycle, snapshot and sync behavior, destroy/teardown, repeated open/close cycles, init failure, input-diagnostics install/teardown and late enabling, focus release, and input-state description. --- src/App.vue | 376 +++++--------------- src/features/editor/editorRuntime.ts | 2 +- src/features/editor/editorSession.test.ts | 395 ++++++++++++++++++++++ src/features/editor/editorSession.ts | 349 +++++++++++++++++++ 4 files changed, 832 insertions(+), 290 deletions(-) create mode 100644 src/features/editor/editorSession.test.ts create mode 100644 src/features/editor/editorSession.ts diff --git a/src/App.vue b/src/App.vue index 0c821ad..f552dd0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,5 @@