ea6c49f046
支持全部页面分页/多选/删除/分享,删除时可选移除广场帖并清理工作区附件;修复并发同步重复创建页面,并补齐预览下载链接重写与 iframe 下载权限。 Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { useEffect, useRef, useState } from 'react';
|
|
import { bindIframeDocumentHeightSync } from '../utils/iframeContentHeight';
|
|
|
|
export function PagePreviewFrame({
|
|
src,
|
|
title,
|
|
reloadKey = 0,
|
|
minHeight = 680,
|
|
maxHeight = 12000,
|
|
className = 'mindspace-page-preview-frame',
|
|
}: {
|
|
src: string;
|
|
title: string;
|
|
reloadKey?: number;
|
|
minHeight?: number;
|
|
maxHeight?: number;
|
|
className?: string;
|
|
}) {
|
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
const [height, setHeight] = useState(minHeight);
|
|
|
|
useEffect(() => {
|
|
setHeight(minHeight);
|
|
}, [src, reloadKey, minHeight]);
|
|
|
|
useEffect(() => {
|
|
const iframe = iframeRef.current;
|
|
if (!iframe) return;
|
|
return bindIframeDocumentHeightSync(iframe, {
|
|
minHeight,
|
|
maxHeight,
|
|
onHeight: setHeight,
|
|
});
|
|
}, [maxHeight, minHeight, src, reloadKey]);
|
|
|
|
return (
|
|
<iframe
|
|
ref={iframeRef}
|
|
key={`${src}:${reloadKey}`}
|
|
title={title}
|
|
src={src}
|
|
sandbox="allow-same-origin allow-downloads"
|
|
className={className}
|
|
style={{ height: `${height}px` }}
|
|
/>
|
|
);
|
|
}
|