From 0d6fd4e3ece921d0d1b6755445be5efe1101054b Mon Sep 17 00:00:00 2001 From: MarsLuay <70299537+MarsLuay@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:23:42 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20refactor:=20break=20down=20DocxL?= =?UTF-8?q?iveVerifyApp=20into=20focused=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docx-ime-live-verify-entry.tsx | 73 ++++++++++++++++++------------ 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/src/docx-ime-live-verify-entry.tsx b/src/docx-ime-live-verify-entry.tsx index 1dfa363..4e28fd4 100644 --- a/src/docx-ime-live-verify-entry.tsx +++ b/src/docx-ime-live-verify-entry.tsx @@ -154,19 +154,32 @@ function collectMetrics( }; } -function DocxLiveVerifyApp({ - scenarioName, - initialZoom, - showOutline, -}: { - scenarioName: string; - initialZoom: number; - showOutline: boolean; -}) { - const [hostEl, setHostEl] = useState(null); - const editorRef = useRef(null); - const renderedDomContextRef = useRef(null); +function publishMetrics(metrics: LiveVerifyMetrics): void { + window.document.body.dataset.metrics = encodeURIComponent(JSON.stringify(metrics)); + console.log('LIVE_VERIFY_RESULT:' + JSON.stringify(metrics)); +} +function publishVerificationError(scenarioName: string, errorMessage: string): void { + publishMetrics({ + name: scenarioName, + error: errorMessage, + wrapper: null, + transformAncestorsOnCaret: -1, + editableFound: false, + hiddenImeRootFound: false, + hiddenImeAnchored: false, + hiddenCaretDelta: null, + compositionStartAnchored: false, + passed: false, + }); +} + +function useDocxImeNeutralizerVerification( + hostEl: HTMLDivElement | null, + scenarioName: string, + editorRef: React.RefObject, + renderedDomContextRef: React.RefObject, +): void { useEffect(() => { if (!hostEl) { return; @@ -212,8 +225,7 @@ function DocxLiveVerifyApp({ compositionStartAnchored, () => renderedDomContextRef.current, ); - window.document.body.dataset.metrics = encodeURIComponent(JSON.stringify(metrics)); - console.log('LIVE_VERIFY_RESULT:' + JSON.stringify(metrics)); + publishMetrics(metrics); }, 50); }, 50); }; @@ -234,7 +246,23 @@ function DocxLiveVerifyApp({ } detachNeutralizer?.(); }; - }, [hostEl, scenarioName]); + }, [hostEl, scenarioName, editorRef, renderedDomContextRef]); +} + +function DocxLiveVerifyApp({ + scenarioName, + initialZoom, + showOutline, +}: { + scenarioName: string; + initialZoom: number; + showOutline: boolean; +}) { + const [hostEl, setHostEl] = useState(null); + const editorRef = useRef(null); + const renderedDomContextRef = useRef(null); + + useDocxImeNeutralizerVerification(hostEl, scenarioName, editorRef, renderedDomContextRef); return (
@@ -253,20 +281,7 @@ function DocxLiveVerifyApp({ }} onFontsLoaded={() => undefined} onError={(error) => { - const payload: LiveVerifyMetrics = { - name: scenarioName, - error: error.message, - wrapper: null, - transformAncestorsOnCaret: -1, - editableFound: false, - hiddenImeRootFound: false, - hiddenImeAnchored: false, - hiddenCaretDelta: null, - compositionStartAnchored: false, - passed: false, - }; - window.document.body.dataset.metrics = encodeURIComponent(JSON.stringify(payload)); - console.log('LIVE_VERIFY_RESULT:' + JSON.stringify(payload)); + publishVerificationError(scenarioName, error.message); }} />