mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 20:57:08 +08:00
c28f918527
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)
31 lines
925 B
TypeScript
31 lines
925 B
TypeScript
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));
|
|
};
|