mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 22:18:54 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { EmbedSyncedDocBlockSchema } from '@blocksuite/affine-model';
|
|
import {
|
|
BlockPlainTextAdapterExtension,
|
|
type BlockPlainTextAdapterMatcher,
|
|
} from '@blocksuite/affine-shared/adapters';
|
|
|
|
export const embedSyncedDocBlockPlainTextAdapterMatcher: BlockPlainTextAdapterMatcher =
|
|
{
|
|
flavour: EmbedSyncedDocBlockSchema.model.flavour,
|
|
toMatch: () => false,
|
|
fromMatch: o => o.node.flavour === EmbedSyncedDocBlockSchema.model.flavour,
|
|
toBlockSnapshot: {},
|
|
fromBlockSnapshot: {
|
|
enter: async (o, context) => {
|
|
const { configs, walker, walkerContext, job, textBuffer } = context;
|
|
const type = configs.get('embedSyncedDocExportType');
|
|
|
|
// this context is used for nested sync block
|
|
if (
|
|
walkerContext.getGlobalContext('embed-synced-doc-counter') ===
|
|
undefined
|
|
) {
|
|
walkerContext.setGlobalContext('embed-synced-doc-counter', 0);
|
|
}
|
|
let counter = walkerContext.getGlobalContext(
|
|
'embed-synced-doc-counter'
|
|
) as number;
|
|
walkerContext.setGlobalContext('embed-synced-doc-counter', ++counter);
|
|
|
|
let buffer = '';
|
|
|
|
if (type === 'content') {
|
|
const syncedDocId = o.node.props.pageId as string;
|
|
const syncedDoc = job.docCRUD.get(syncedDocId);
|
|
if (!syncedDoc) return;
|
|
|
|
if (counter === 1) {
|
|
const syncedSnapshot = job.docToSnapshot(syncedDoc);
|
|
if (syncedSnapshot) {
|
|
await walker.walkONode(syncedSnapshot.blocks);
|
|
}
|
|
} else {
|
|
buffer = syncedDoc.meta?.title ?? '';
|
|
if (buffer) {
|
|
buffer += '\n';
|
|
}
|
|
}
|
|
}
|
|
textBuffer.content += buffer;
|
|
},
|
|
leave: (_, context) => {
|
|
const { walkerContext } = context;
|
|
const counter = walkerContext.getGlobalContext(
|
|
'embed-synced-doc-counter'
|
|
) as number;
|
|
walkerContext.setGlobalContext('embed-synced-doc-counter', counter - 1);
|
|
},
|
|
},
|
|
};
|
|
|
|
export const EmbedSyncedDocBlockPlainTextAdapterExtension =
|
|
BlockPlainTextAdapterExtension(embedSyncedDocBlockPlainTextAdapterMatcher);
|