mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +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:
@@ -98,7 +98,7 @@ export class DocDatabaseBacklinksService extends Service {
|
||||
doc: docRef.doc,
|
||||
docId: backlink.docId,
|
||||
databaseId: dbModel.id,
|
||||
databaseName: dbModel.title.yText.toString(),
|
||||
databaseName: dbModel.props.title.yText.toString(),
|
||||
dataSource: dataSource,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -90,8 +90,8 @@ export class Doc extends Entity {
|
||||
?.model as RootBlockModel | undefined;
|
||||
if (pageBlock) {
|
||||
this.blockSuiteDoc.transact(() => {
|
||||
pageBlock.title.delete(0, pageBlock.title.length);
|
||||
pageBlock.title.insert(newTitle, 0);
|
||||
pageBlock.props.title.delete(0, pageBlock.props.title.length);
|
||||
pageBlock.props.title.insert(newTitle, 0);
|
||||
});
|
||||
this.record.setMeta({ title: newTitle });
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ function generateMarkdownPreviewBuilder(
|
||||
);
|
||||
|
||||
return {
|
||||
...props,
|
||||
props,
|
||||
id: yblock.get('sys:id') as string,
|
||||
flavour,
|
||||
children: [],
|
||||
@@ -147,7 +147,7 @@ function generateMarkdownPreviewBuilder(
|
||||
keys: Array.from(yblock.keys())
|
||||
.filter(key => key.startsWith('prop:'))
|
||||
.map(key => key.substring(5)),
|
||||
} as DraftModel;
|
||||
} as unknown as DraftModel;
|
||||
}
|
||||
|
||||
const titleMiddleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
@@ -300,12 +300,12 @@ function generateMarkdownPreviewBuilder(
|
||||
|
||||
const info = ['an image block'];
|
||||
|
||||
if (model.sourceId) {
|
||||
info.push(`file id ${model.sourceId}`);
|
||||
if (model.props.sourceId) {
|
||||
info.push(`file id ${model.props.sourceId}`);
|
||||
}
|
||||
|
||||
if (model.caption) {
|
||||
info.push(`with caption ${model.caption}`);
|
||||
if (model.props.caption) {
|
||||
info.push(`with caption ${model.props.caption}`);
|
||||
}
|
||||
|
||||
return info.join(', ') + '\n';
|
||||
@@ -353,8 +353,8 @@ function generateMarkdownPreviewBuilder(
|
||||
if (!isBookmarkModel(draftModel)) {
|
||||
return null;
|
||||
}
|
||||
const title = draftModel.title;
|
||||
const url = draftModel.url;
|
||||
const title = draftModel.props.title;
|
||||
const url = draftModel.props.url;
|
||||
return `[${title}](${url})\n`;
|
||||
};
|
||||
|
||||
@@ -370,7 +370,7 @@ function generateMarkdownPreviewBuilder(
|
||||
return null;
|
||||
}
|
||||
|
||||
return `[${draftModel.name}](${draftModel.sourceId})\n`;
|
||||
return `[${draftModel.props.name}](${draftModel.props.sourceId})\n`;
|
||||
};
|
||||
|
||||
const generateTableMarkdownPreview = (block: BlockDocumentInfo) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { AttachmentBlockModel } from '@blocksuite/affine/model';
|
||||
|
||||
export async function downloadBlobToBuffer(model: AttachmentBlockModel) {
|
||||
const sourceId = model.sourceId;
|
||||
const sourceId = model.props.sourceId;
|
||||
if (!sourceId) {
|
||||
throw new Error('Attachment not found');
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
isEmbedLinkedDocModel(blockModel) ||
|
||||
isEmbedSyncedDocModel(blockModel)
|
||||
) {
|
||||
const { pageId: docId, params } = blockModel;
|
||||
const { pageId: docId, params } = blockModel.props;
|
||||
const info: DocPeekViewInfo = {
|
||||
type: 'doc',
|
||||
docRef: { docId, ...params },
|
||||
@@ -174,7 +174,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
blockIds: [blockModel.id],
|
||||
filetype: blockModel.type,
|
||||
filetype: blockModel.props.type,
|
||||
},
|
||||
};
|
||||
} else if (isImageBlockModel(blockModel)) {
|
||||
|
||||
@@ -75,7 +75,9 @@ function useImageBlob(
|
||||
return null;
|
||||
}
|
||||
const blockModel = block.model as ImageBlockModel;
|
||||
return await docCollection.blobSync.get(blockModel.sourceId as string);
|
||||
return await docCollection.blobSync.get(
|
||||
blockModel.props.sourceId as string
|
||||
);
|
||||
},
|
||||
suspense: false,
|
||||
}
|
||||
@@ -154,8 +156,8 @@ const ImagePreviewModalImpl = ({
|
||||
return block.model as ImageBlockModel;
|
||||
}, [blockId, blocksuiteDoc]);
|
||||
const caption = useMemo(() => {
|
||||
return blockModel?.caption ?? '';
|
||||
}, [blockModel?.caption]);
|
||||
return blockModel?.props.caption ?? '';
|
||||
}, [blockModel?.props.caption]);
|
||||
const [blocks, setBlocks] = useState<ImageBlockModel[]>([]);
|
||||
const [cursor, setCursor] = useState(0);
|
||||
const zoomRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
Reference in New Issue
Block a user