mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 05:05:52 +08:00
refactor(editor): extract database block (#9435)
Part of: [BS-2269](https://linear.app/affine-design/issue/BS-2269/%E8%BF%81%E7%A7%BB-database-block-%E5%88%B0-affine-%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%8B%E5%B9%B6%E5%BC%80%E5%90%AF-nouncheckedindexedaccess)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import type { DeltaOperation, Text } from '@blocksuite/store';
|
||||
|
||||
export const getSingleDocIdFromText = (text?: Text) => {
|
||||
const deltas = text?.deltas$.value;
|
||||
if (!deltas) return;
|
||||
let linkedDocId: string | undefined = undefined;
|
||||
for (const delta of deltas) {
|
||||
if (isLinkedDoc(delta)) {
|
||||
if (linkedDocId) {
|
||||
return;
|
||||
}
|
||||
linkedDocId = delta.attributes?.reference?.pageId as string;
|
||||
} else if (delta.insert) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return linkedDocId;
|
||||
};
|
||||
|
||||
export const isLinkedDoc = (delta: DeltaOperation) => {
|
||||
const attributes: AffineTextAttributes | undefined = delta.attributes;
|
||||
return attributes?.reference?.type === 'LinkedPage';
|
||||
};
|
||||
|
||||
export const isPureText = (text?: Text): boolean => {
|
||||
const deltas = text?.deltas$.value;
|
||||
if (!deltas) return true;
|
||||
return deltas.every(v => !isLinkedDoc(v));
|
||||
};
|
||||
Reference in New Issue
Block a user