From a475000df58a3e4406160fdcea7282828697d6b6 Mon Sep 17 00:00:00 2001 From: PingChuan <1259732256@qq.com> Date: Tue, 25 Nov 2025 14:38:54 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E6=88=90=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E8=87=AA=E5=AE=9A=E4=B9=89Collabora=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/collabora/CollaboraViewer.tsx | 45 +++--- app/components/collabora/Uno.ts | 3 +- app/components/collabora/hooks.ts | 57 +------ app/components/collabora/lib/README.md | 15 +- app/components/collabora/lib/gotoPage.ts | 151 +++++++++++++++++++ app/components/collabora/lib/index.ts | 9 +- app/components/collabora/lib/navigation.ts | 29 ---- app/components/collabora/lib/pageInfo.ts | 21 --- app/components/collabora/types.ts | 3 - app/components/reviews/FilePreview.tsx | 19 ++- 10 files changed, 205 insertions(+), 147 deletions(-) create mode 100644 app/components/collabora/lib/gotoPage.ts diff --git a/app/components/collabora/CollaboraViewer.tsx b/app/components/collabora/CollaboraViewer.tsx index a899e7f..b5f9f3c 100644 --- a/app/components/collabora/CollaboraViewer.tsx +++ b/app/components/collabora/CollaboraViewer.tsx @@ -10,7 +10,7 @@ * @encoding UTF-8 */ -import { useRef, forwardRef, useImperativeHandle, useState, useEffect } from 'react'; +import { useRef, forwardRef, useImperativeHandle, useState } from 'react'; import type { CollaboraViewerProps, CollaboraViewerHandle } from './types'; import { useCollaboraConfig, useDocumentReady, useCollaboraUnoCommands } from './hooks'; import { sendUnoCommand } from './Uno'; @@ -54,20 +54,6 @@ export const CollaboraViewer = forwardRef iframeRef.current?.contentWindow || null, }), [unoCommands, isDocumentLoaded, mode]); - // 5. 将 sendUnoCommand 挂载到 window 对象,供调试面板和控制台使用 - useEffect(() => { - if (iframeRef.current?.contentWindow) { - (window as any).sendUno = (cmd: string, args: any = {}) => { - if (iframeRef.current?.contentWindow) { - sendUnoCommand(iframeRef.current.contentWindow, cmd, args); - } - }; - } - - return () => { - delete (window as any).sendUno; - }; - }, [isDocumentLoaded]); // 加载中状态 if (loading) { @@ -101,20 +87,15 @@ export const CollaboraViewer = forwardRef = {}; const raw = (unoArgs || '').trim(); if (raw !== '') { try { - args = JSON.parse(raw); + args = JSON.parse(raw) as Record; } catch (err) { try { // fallback: replace single quotes with double quotes and parse - args = JSON.parse(raw.replace(/'(.*?)'/g, '"$1"')); + args = JSON.parse(raw.replace(/'(.*?)'/g, '"$1"')) as Record; } catch (err2) { console.error('解析 UNO Args 失败:', err2); setUnoResult('Args 解析失败,请使用有效 JSON'); @@ -122,12 +103,22 @@ export const CollaboraViewer = forwardRef {/* UNO 命令测试面板 */} - {/*
+
{unoResult && {unoResult}} -
*/} +
{/* 文档加载提示 */} {!isDocumentLoaded && ( @@ -162,7 +153,8 @@ export const CollaboraViewer = forwardRef )} - {/* Collabora iframe */} + {/* Collabora iframe - tabIndex is needed for keyboard navigation */} + {/* eslint-disable jsx-a11y/no-noninteractive-tabindex */}