Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(ui): should not make clipboard util iframe visible (#1620)

Wenzhao Hu06760b5cda5f
diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
index fcf5bb7ef1..5cd3b80a79 100644
--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
@@ -64,6 +64,15 @@ interface IHtmlToUSMServiceProps {
getCurrentSkeleton: () => Nullable<ISheetSkeletonManagerParam>;
}
+function hideIframe(iframe: HTMLIFrameElement) {
+ iframe.style.display = 'none';
+ iframe.style.width = '0';
+ iframe.style.height = '0';
+ iframe.setAttribute('tabindex', '-1');
+ iframe.setAttribute('aria-hidden', 'true');
+ iframe.setAttribute('title', 'hidden iframe');
+}
+
export class HtmlToUSMService {
private static pluginList: IPasteExtension[] = [];
@@ -89,6 +98,7 @@ export class HtmlToUSMService {
this.getCurrentSkeleton = props.getCurrentSkeleton;
this.htmlElement = document.createElement('iframe');
document.body.appendChild(this.htmlElement);
+ hideIframe(this.htmlElement);
}
convert(html: string): IUniverSheetCopyDataModel {
@@ -97,6 +107,7 @@ export class HtmlToUSMService {
this.htmlElement.contentDocument.write(html);
this.htmlElement.contentDocument.close();
}
+
html = html.replace(/<!--[\s\S]*?-->/g, '');
const pastePlugin = HtmlToUSMService.pluginList.find((plugin) => plugin.checkPasteType(html));