mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 19:46:32 +08:00
feat(editor): unify block props api (#10888)
Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
This commit is contained in:
@@ -90,7 +90,7 @@ interface ErrorProps {
|
||||
|
||||
export const Error = ({ model, ext }: ErrorProps) => {
|
||||
const t = useI18n();
|
||||
const Icon = FILE_ICONS[model.type] ?? FileIcon;
|
||||
const Icon = FILE_ICONS[model.props.type] ?? FileIcon;
|
||||
const title = t['com.affine.attachment.preview.error.title']();
|
||||
const subtitle = `.${ext} ${t['com.affine.attachment.preview.error.subtitle']()}`;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export const AttachmentViewerView = ({ model }: AttachmentViewerProps) => {
|
||||
};
|
||||
|
||||
const AttachmentViewerInner = (props: PDFViewerProps) => {
|
||||
return props.model.type.endsWith('pdf') ? (
|
||||
return props.model.props.type.endsWith('pdf') ? (
|
||||
<AttachmentPreviewErrorBoundary>
|
||||
<PDFViewer {...props} />
|
||||
</AttachmentPreviewErrorBoundary>
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ export function PDFViewerEmbeddedInner({ model }: PDFViewerProps) {
|
||||
useMemo(() => (pageEntity ? pageEntity.page.bitmap$ : null), [pageEntity])
|
||||
);
|
||||
|
||||
const [name, setName] = useState(model.name);
|
||||
const [name, setName] = useState(model.props.name);
|
||||
const [cursor, setCursor] = useState(0);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [visibility, setVisibility] = useState(false);
|
||||
@@ -108,7 +108,7 @@ export function PDFViewerEmbeddedInner({ model }: PDFViewerProps) {
|
||||
};
|
||||
}, [cursor, meta, peek]);
|
||||
|
||||
useEffect(() => model.name$.subscribe(val => setName(val)), [model]);
|
||||
useEffect(() => model.props.name$.subscribe(val => setName(val)), [model]);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { downloadBlob } from '../../utils/resource';
|
||||
import type { PDFViewerProps } from './types';
|
||||
|
||||
export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
||||
const sourceId = model.sourceId;
|
||||
const sourceId = model.props.sourceId;
|
||||
if (!sourceId) {
|
||||
return null;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
||||
let blob = await doc.blobSync.get(sourceId);
|
||||
|
||||
if (blob) {
|
||||
blob = new Blob([blob], { type: model.type });
|
||||
blob = new Blob([blob], { type: model.props.type });
|
||||
}
|
||||
|
||||
return blob;
|
||||
@@ -25,16 +25,16 @@ export async function download(model: AttachmentBlockModel) {
|
||||
const blob = await getAttachmentBlob(model);
|
||||
if (!blob) return;
|
||||
|
||||
await downloadBlob(blob, model.name);
|
||||
await downloadBlob(blob, model.props.name);
|
||||
}
|
||||
|
||||
export function buildAttachmentProps(
|
||||
model: AttachmentBlockModel
|
||||
): PDFViewerProps {
|
||||
const pieces = model.name.split('.');
|
||||
const pieces = model.props.name.split('.');
|
||||
const ext = pieces.pop() || '';
|
||||
const name = pieces.join('.');
|
||||
const size = filesize(model.size);
|
||||
const size = filesize(model.props.size);
|
||||
return { model, name, ext, size };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user