feat:移除无用的UNO封装代码

This commit is contained in:
PingChuan
2025-11-25 18:58:58 +08:00
parent 08ebcf1935
commit ba83796a44
6 changed files with 116 additions and 235 deletions
+71 -72
View File
@@ -9,23 +9,22 @@
* @encoding UTF-8
*/
import { RefObject, useCallback, useEffect, useState, useMemo } from 'react';
import { useFetcher } from '@remix-run/react';
import { toastService } from '../ui/Toast';
import type { CollaboraConfig } from './types';
import {
unoSearchText,
unoReplaceText,
unoHighlightText,
unoRemoveHighlight,
unoEscape,
unoScrollToTop,
unoSave,
unoZoomPlus,
unoZoomMinus,
unoSetZoom,
} from './lib';
import { RefObject, useCallback, useEffect, useMemo, useState } from 'react';
import { COLLABORA_URL } from '~/config/api-config';
import { toastService } from '../ui/Toast';
import {
unoEscape,
// unoHighlightText,
unoReplaceText,
unoSave,
unoScrollToTop,
unoSearchText,
unoSetZoom,
unoZoomMinus,
unoZoomPlus,
} from './lib';
import type { CollaboraConfig } from './types';
// ==================== 1. 配置加载 ====================
@@ -142,32 +141,32 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
[iframeRef]
);
/**
* 定位文本(搜索 + 立即取消选中)
* 用于"只看不改"的场景,避免蓝色选中背景
*/
const locateText = useCallback(
async (text: string) => {
if (!iframeRef.current?.contentWindow) {
console.warn('[UNO] iframe 不可用');
return;
}
// /**
// * 定位文本(搜索 + 立即取消选中)
// * 用于"只看不改"的场景,避免蓝色选中背景
// */
// const locateText = useCallback(
// async (text: string) => {
// if (!iframeRef.current?.contentWindow) {
// console.warn('[UNO] iframe 不可用');
// return;
// }
console.log(`[UNO] 定位文本(无选中): "${text}"`);
// console.log(`[UNO] 定位文本(无选中): "${text}"`);
// 1. 执行搜索(滚动到目标并选中)
await searchText(text);
// // 1. 执行搜索(滚动到目标并选中)
// await searchText(text);
// 2. 等待渲染完成
await new Promise((resolve) => setTimeout(resolve, 50));
// // 2. 等待渲染完成
// await new Promise((resolve) => setTimeout(resolve, 50));
// 3. 取消选中(去除蓝色背景,保留视图位置)
unoEscape(iframeRef.current.contentWindow);
// // 3. 取消选中(去除蓝色背景,保留视图位置)
// unoEscape(iframeRef.current.contentWindow);
console.log(`[UNO] 定位完成,已取消选中`);
},
[searchText, iframeRef]
);
// console.log(`[UNO] 定位完成,已取消选中`);
// },
// [searchText, iframeRef]
// );
/**
* 替换文本(ReplaceAll
@@ -185,37 +184,37 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
[iframeRef]
);
/**
* 高亮文本
*/
const highlightText = useCallback(
async (text: string, color?: number) => {
if (!iframeRef.current?.contentWindow) {
console.warn('[UNO] iframe 不可用');
return;
}
console.log(`[UNO] 高亮文本: "${text}"`);
await unoHighlightText(iframeRef.current.contentWindow, text, color);
await new Promise((resolve) => setTimeout(resolve, 200));
},
[iframeRef]
);
// /**
// * 高亮文本
// */
// const highlightText = useCallback(
// async (text: string, color?: number) => {
// if (!iframeRef.current?.contentWindow) {
// console.warn('[UNO] iframe 不可用');
// return;
// }
// console.log(`[UNO] 高亮文本: "${text}"`);
// await unoHighlightText(iframeRef.current.contentWindow, text, color);
// await new Promise((resolve) => setTimeout(resolve, 200));
// },
// [iframeRef]
// );
/**
* 移除高亮
*/
const removeHighlight = useCallback(
async (text: string) => {
if (!iframeRef.current?.contentWindow) {
console.warn('[UNO] iframe 不可用');
return;
}
console.log(`[UNO] 移除高亮: "${text}"`);
await unoRemoveHighlight(iframeRef.current.contentWindow, text);
await new Promise((resolve) => setTimeout(resolve, 200));
},
[iframeRef]
);
// /**
// * 移除高亮
// */
// const removeHighlight = useCallback(
// async (text: string) => {
// if (!iframeRef.current?.contentWindow) {
// console.warn('[UNO] iframe 不可用');
// return;
// }
// console.log(`[UNO] 移除高亮: "${text}"`);
// await unoRemoveHighlight(iframeRef.current.contentWindow, text);
// await new Promise((resolve) => setTimeout(resolve, 200));
// },
// [iframeRef]
// );
/**
* 取消选中(Escape
@@ -309,10 +308,10 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
return useMemo(
() => ({
searchText,
locateText,
// locateText,
replaceText,
highlightText,
removeHighlight,
// highlightText,
// removeHighlight,
escapeSelection,
scrollToTop,
saveDocument,
@@ -322,10 +321,10 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
}),
[
searchText,
locateText,
// locateText,
replaceText,
highlightText,
removeHighlight,
// highlightText,
// removeHighlight,
escapeSelection,
scrollToTop,
saveDocument,