feat:移除无用的UNO封装代码
This commit is contained in:
@@ -9,23 +9,22 @@
|
|||||||
* @encoding UTF-8
|
* @encoding UTF-8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { RefObject, useCallback, useEffect, useState, useMemo } from 'react';
|
|
||||||
import { useFetcher } from '@remix-run/react';
|
import { useFetcher } from '@remix-run/react';
|
||||||
import { toastService } from '../ui/Toast';
|
import { RefObject, useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import type { CollaboraConfig } from './types';
|
|
||||||
import {
|
|
||||||
unoSearchText,
|
|
||||||
unoReplaceText,
|
|
||||||
unoHighlightText,
|
|
||||||
unoRemoveHighlight,
|
|
||||||
unoEscape,
|
|
||||||
unoScrollToTop,
|
|
||||||
unoSave,
|
|
||||||
unoZoomPlus,
|
|
||||||
unoZoomMinus,
|
|
||||||
unoSetZoom,
|
|
||||||
} from './lib';
|
|
||||||
import { COLLABORA_URL } from '~/config/api-config';
|
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. 配置加载 ====================
|
// ==================== 1. 配置加载 ====================
|
||||||
|
|
||||||
@@ -142,32 +141,32 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
|
|||||||
[iframeRef]
|
[iframeRef]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 定位文本(搜索 + 立即取消选中)
|
// * 定位文本(搜索 + 立即取消选中)
|
||||||
* 用于"只看不改"的场景,避免蓝色选中背景
|
// * 用于"只看不改"的场景,避免蓝色选中背景
|
||||||
*/
|
// */
|
||||||
const locateText = useCallback(
|
// const locateText = useCallback(
|
||||||
async (text: string) => {
|
// async (text: string) => {
|
||||||
if (!iframeRef.current?.contentWindow) {
|
// if (!iframeRef.current?.contentWindow) {
|
||||||
console.warn('[UNO] iframe 不可用');
|
// console.warn('[UNO] iframe 不可用');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
console.log(`[UNO] 定位文本(无选中): "${text}"`);
|
// console.log(`[UNO] 定位文本(无选中): "${text}"`);
|
||||||
|
|
||||||
// 1. 执行搜索(滚动到目标并选中)
|
// // 1. 执行搜索(滚动到目标并选中)
|
||||||
await searchText(text);
|
// await searchText(text);
|
||||||
|
|
||||||
// 2. 等待渲染完成
|
// // 2. 等待渲染完成
|
||||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
// await new Promise((resolve) => setTimeout(resolve, 50));
|
||||||
|
|
||||||
// 3. 取消选中(去除蓝色背景,保留视图位置)
|
// // 3. 取消选中(去除蓝色背景,保留视图位置)
|
||||||
unoEscape(iframeRef.current.contentWindow);
|
// unoEscape(iframeRef.current.contentWindow);
|
||||||
|
|
||||||
console.log(`[UNO] 定位完成,已取消选中`);
|
// console.log(`[UNO] 定位完成,已取消选中`);
|
||||||
},
|
// },
|
||||||
[searchText, iframeRef]
|
// [searchText, iframeRef]
|
||||||
);
|
// );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 替换文本(ReplaceAll)
|
* 替换文本(ReplaceAll)
|
||||||
@@ -185,37 +184,37 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
|
|||||||
[iframeRef]
|
[iframeRef]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 高亮文本
|
// * 高亮文本
|
||||||
*/
|
// */
|
||||||
const highlightText = useCallback(
|
// const highlightText = useCallback(
|
||||||
async (text: string, color?: number) => {
|
// async (text: string, color?: number) => {
|
||||||
if (!iframeRef.current?.contentWindow) {
|
// if (!iframeRef.current?.contentWindow) {
|
||||||
console.warn('[UNO] iframe 不可用');
|
// console.warn('[UNO] iframe 不可用');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
console.log(`[UNO] 高亮文本: "${text}"`);
|
// console.log(`[UNO] 高亮文本: "${text}"`);
|
||||||
await unoHighlightText(iframeRef.current.contentWindow, text, color);
|
// await unoHighlightText(iframeRef.current.contentWindow, text, color);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
// await new Promise((resolve) => setTimeout(resolve, 200));
|
||||||
},
|
// },
|
||||||
[iframeRef]
|
// [iframeRef]
|
||||||
);
|
// );
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 移除高亮
|
// * 移除高亮
|
||||||
*/
|
// */
|
||||||
const removeHighlight = useCallback(
|
// const removeHighlight = useCallback(
|
||||||
async (text: string) => {
|
// async (text: string) => {
|
||||||
if (!iframeRef.current?.contentWindow) {
|
// if (!iframeRef.current?.contentWindow) {
|
||||||
console.warn('[UNO] iframe 不可用');
|
// console.warn('[UNO] iframe 不可用');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
console.log(`[UNO] 移除高亮: "${text}"`);
|
// console.log(`[UNO] 移除高亮: "${text}"`);
|
||||||
await unoRemoveHighlight(iframeRef.current.contentWindow, text);
|
// await unoRemoveHighlight(iframeRef.current.contentWindow, text);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
// await new Promise((resolve) => setTimeout(resolve, 200));
|
||||||
},
|
// },
|
||||||
[iframeRef]
|
// [iframeRef]
|
||||||
);
|
// );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消选中(Escape)
|
* 取消选中(Escape)
|
||||||
@@ -309,10 +308,10 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
|
|||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
searchText,
|
searchText,
|
||||||
locateText,
|
// locateText,
|
||||||
replaceText,
|
replaceText,
|
||||||
highlightText,
|
// highlightText,
|
||||||
removeHighlight,
|
// removeHighlight,
|
||||||
escapeSelection,
|
escapeSelection,
|
||||||
scrollToTop,
|
scrollToTop,
|
||||||
saveDocument,
|
saveDocument,
|
||||||
@@ -322,10 +321,10 @@ export function useCollaboraUnoCommands(iframeRef: RefObject<HTMLIFrameElement>)
|
|||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
searchText,
|
searchText,
|
||||||
locateText,
|
// locateText,
|
||||||
replaceText,
|
replaceText,
|
||||||
highlightText,
|
// highlightText,
|
||||||
removeHighlight,
|
// removeHighlight,
|
||||||
escapeSelection,
|
escapeSelection,
|
||||||
scrollToTop,
|
scrollToTop,
|
||||||
saveDocument,
|
saveDocument,
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/**
|
|
||||||
* Collabora 高亮功能模块
|
|
||||||
*
|
|
||||||
* @encoding UTF-8
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { sendUnoCommand } from '../Uno';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 高亮文本
|
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
|
||||||
* @param text - 要高亮的文本
|
|
||||||
* @param color - 高亮颜色,默认 16776960 = 黄色
|
|
||||||
*/
|
|
||||||
export function unoHighlightText(
|
|
||||||
iframeWindow: Window,
|
|
||||||
text: string,
|
|
||||||
color: number = 16776960
|
|
||||||
): void {
|
|
||||||
// 1. 查找所有
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:ExecuteSearch', {
|
|
||||||
'SearchItem.SearchString': { type: 'string', value: text },
|
|
||||||
'SearchItem.Command': { type: 'long', value: 1 }, // 1 = FindAll
|
|
||||||
'SearchItem.SearchFlags': { type: 'long', value: 0 },
|
|
||||||
'SearchItem.AlgorithmType': { type: 'short', value: 0 },
|
|
||||||
'SearchItem.Backward': { type: 'boolean', value: false },
|
|
||||||
'Quiet': { type: 'boolean', value: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2. 设置背景色
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:BackColor', {
|
|
||||||
BackColor: { type: 'long', value: color },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 移除高亮
|
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
|
||||||
* @param text - 要移除高亮的文本
|
|
||||||
*/
|
|
||||||
export function unoRemoveHighlight(iframeWindow: Window, text: string): void {
|
|
||||||
// 1. 查找所有
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:ExecuteSearch', {
|
|
||||||
'SearchItem.SearchString': { type: 'string', value: text },
|
|
||||||
'SearchItem.Command': { type: 'long', value: 1 }, // 1 = FindAll
|
|
||||||
'SearchItem.SearchFlags': { type: 'long', value: 0 },
|
|
||||||
'SearchItem.AlgorithmType': { type: 'short', value: 0 },
|
|
||||||
'SearchItem.Backward': { type: 'boolean', value: false },
|
|
||||||
'Quiet': { type: 'boolean', value: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2. 移除背景色 -1 = 无色
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:BackColor', {
|
|
||||||
BackColor: { type: 'long', value: -1 },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消 - Escape
|
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
|
||||||
*/
|
|
||||||
export function unoEscape(iframeWindow: Window): void {
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:Escape', {});
|
|
||||||
}
|
|
||||||
@@ -4,22 +4,23 @@
|
|||||||
* @encoding UTF-8
|
* @encoding UTF-8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 搜索功能
|
// // 搜索功能
|
||||||
export { unoSearchText } from './search';
|
// export { unoSearchText } from './search';
|
||||||
|
|
||||||
// 替换功能
|
// // 替换功能
|
||||||
export { unoReplaceText } from './replace';
|
// export { unoReplaceText } from './replace';
|
||||||
|
|
||||||
// 高亮功能
|
|
||||||
export { unoHighlightText, unoRemoveHighlight, unoEscape } from './highlight';
|
// 高亮,已经封装好了
|
||||||
|
export { switchHighlight } from './Highlightselecttext';
|
||||||
|
|
||||||
// 导航/跳转功能
|
// 导航/跳转功能
|
||||||
export {
|
export {
|
||||||
unoScrollToTop,
|
unoScrollToTop
|
||||||
} from './navigation';
|
} from './navigation';
|
||||||
|
|
||||||
// 缩放功能
|
// 缩放功能
|
||||||
export { unoZoomPlus, unoZoomMinus, unoSetZoom } from './zoom';
|
// export { unoSetZoom, unoZoomMinus, unoZoomPlus } from './zoom';
|
||||||
|
|
||||||
// 文档操作
|
// 文档操作
|
||||||
export { unoSave } from './document';
|
export { unoSave } from './document';
|
||||||
@@ -27,11 +28,12 @@ export { unoSave } from './document';
|
|||||||
// 页数信息
|
// 页数信息
|
||||||
export {
|
export {
|
||||||
requestPageInfo,
|
requestPageInfo,
|
||||||
type PageInfo,
|
type PageInfo
|
||||||
} from './pageInfo';
|
} from './pageInfo';
|
||||||
|
|
||||||
// 自定义页面跳转功能
|
// 自定义页面跳转功能
|
||||||
export {
|
export {
|
||||||
customGotoPage,
|
customGotoPage,
|
||||||
type GotoPageResponse,
|
type GotoPageResponse
|
||||||
} from './gotoPage';
|
} from './gotoPage';
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* Collabora 替换功能模块
|
|
||||||
*
|
|
||||||
* @encoding UTF-8
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { sendUnoCommand } from '../Uno';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 替换文本
|
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
|
||||||
* @param searchText - 要搜索的文本
|
|
||||||
* @param replaceText - 替换后的文本
|
|
||||||
*/
|
|
||||||
export function unoReplaceText(
|
|
||||||
iframeWindow: Window,
|
|
||||||
searchText: string,
|
|
||||||
replaceText: string
|
|
||||||
): void {
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:ExecuteSearch', {
|
|
||||||
'SearchItem.SearchString': { type: 'string', value: searchText },
|
|
||||||
'SearchItem.ReplaceString': { type: 'string', value: replaceText },
|
|
||||||
'SearchItem.Command': { type: 'long', value: 3 }, // 3 = ReplaceAll
|
|
||||||
'SearchItem.AlgorithmType': { type: 'short', value: 0 },
|
|
||||||
'SearchItem.SearchFlags': { type: 'long', value: 0 },
|
|
||||||
'SearchItem.Backward': { type: 'boolean', value: false },
|
|
||||||
'Quiet': { type: 'boolean', value: true },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Collabora 搜索功能模块
|
|
||||||
*
|
|
||||||
* @encoding UTF-8
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { sendUnoCommand } from '../Uno';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 搜索文本
|
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
|
||||||
* @param text - 要搜索的文本
|
|
||||||
*/
|
|
||||||
export function unoSearchText(iframeWindow: Window, text: string): void {
|
|
||||||
sendUnoCommand(iframeWindow, '.uno:ExecuteSearch', {
|
|
||||||
'SearchItem.SearchString': { type: 'string', value: text },
|
|
||||||
'SearchItem.Command': { type: 'long', value: 1 }, // 1 = Search Next (搜索下一个)
|
|
||||||
'SearchItem.Backward': { type: 'boolean', value: false },
|
|
||||||
'SearchItem.Pattern': { type: 'boolean', value: false },
|
|
||||||
'SearchItem.Content': { type: 'boolean', value: false },
|
|
||||||
'SearchItem.AsianOptions': { type: 'boolean', value: false },
|
|
||||||
'SearchItem.AlgorithmType': { type: 'short', value: 0 }, // 普通搜索
|
|
||||||
'SearchItem.SearchFlags': { type: 'long', value: 0 },
|
|
||||||
'SearchItem.Start': { type: 'boolean', value: true }, // 从头开始搜索
|
|
||||||
'SearchItem.Quiet': { type: 'boolean', value: true }, // 静默模式
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,37 +1,37 @@
|
|||||||
/**
|
// /**
|
||||||
* Collabora 缩放功能模块
|
// * Collabora 缩放功能模块
|
||||||
*
|
// *
|
||||||
* @encoding UTF-8
|
// * @encoding UTF-8
|
||||||
*/
|
// */
|
||||||
|
|
||||||
import { sendUnoCommand } from '../Uno';
|
// import { sendUnoCommand } from '../Uno';
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 放大文档(固定步长)
|
// * 放大文档(固定步长)
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
// * @param iframeWindow - iframe 的 contentWindow
|
||||||
*/
|
// */
|
||||||
export function unoZoomPlus(iframeWindow: Window): void {
|
// export function unoZoomPlus(iframeWindow: Window): void {
|
||||||
sendUnoCommand(iframeWindow, '.uno:ZoomPlus', {});
|
// sendUnoCommand(iframeWindow, '.uno:ZoomPlus', {});
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 缩小文档(固定步长)
|
// * 缩小文档(固定步长)
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
// * @param iframeWindow - iframe 的 contentWindow
|
||||||
*/
|
// */
|
||||||
export function unoZoomMinus(iframeWindow: Window): void {
|
// export function unoZoomMinus(iframeWindow: Window): void {
|
||||||
sendUnoCommand(iframeWindow, '.uno:ZoomMinus', {});
|
// sendUnoCommand(iframeWindow, '.uno:ZoomMinus', {});
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 设置文档缩放比例
|
// * 设置文档缩放比例
|
||||||
* @param iframeWindow - iframe 的 contentWindow
|
// * @param iframeWindow - iframe 的 contentWindow
|
||||||
* @param percentage - 缩放百分比(例如:100 表示 100%)
|
// * @param percentage - 缩放百分比(例如:100 表示 100%)
|
||||||
*/
|
// */
|
||||||
export function unoSetZoom(iframeWindow: Window, percentage: number): void {
|
// export function unoSetZoom(iframeWindow: Window, percentage: number): void {
|
||||||
sendUnoCommand(iframeWindow, '.uno:Zoom', {
|
// sendUnoCommand(iframeWindow, '.uno:Zoom', {
|
||||||
Zoom: {
|
// Zoom: {
|
||||||
type: 'short',
|
// type: 'short',
|
||||||
value: percentage,
|
// value: percentage,
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user