mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
205cd7a86d
Closes: BS-2946
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import {
|
|
DividerBlockModel,
|
|
ParagraphBlockModel,
|
|
} from '@blocksuite/affine-model';
|
|
import { matchModels } from '@blocksuite/affine-shared/utils';
|
|
import type { BlockStdScope } from '@blocksuite/std';
|
|
import type { BlockModel } from '@blocksuite/store';
|
|
|
|
import { focusTextModel } from '../dom.js';
|
|
import { beforeConvert } from './utils.js';
|
|
|
|
export function toDivider(
|
|
std: BlockStdScope,
|
|
model: BlockModel,
|
|
prefix: string
|
|
) {
|
|
const { store: doc } = std;
|
|
if (
|
|
matchModels(model, [DividerBlockModel]) ||
|
|
(matchModels(model, [ParagraphBlockModel]) && model.props.type === 'quote')
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const parent = doc.getParent(model);
|
|
if (!parent) return;
|
|
|
|
const index = parent.children.indexOf(model);
|
|
beforeConvert(std, model, prefix.length);
|
|
const blockProps = {
|
|
children: model.children,
|
|
};
|
|
doc.addBlock('affine:divider', blockProps, parent, index);
|
|
|
|
const nextBlock = parent.children[index + 1];
|
|
let id = nextBlock?.id;
|
|
if (!id) {
|
|
id = doc.addBlock('affine:paragraph', {}, parent);
|
|
}
|
|
focusTextModel(std, id);
|
|
return id;
|
|
}
|