mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
chore: merge blocksuite source code (#9213)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { BlockModel, Doc, DraftModel } from '@blocksuite/store';
|
||||
import { minimatch } from 'minimatch';
|
||||
|
||||
export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
|
||||
model: DraftModel | null,
|
||||
expected: Key
|
||||
): model is BlockSuite.BlockModels[Key[number]] {
|
||||
return (
|
||||
!!model &&
|
||||
expected.some(key =>
|
||||
minimatch(model.flavour as keyof BlockSuite.BlockModels, key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function isInsideBlockByFlavour(
|
||||
doc: Doc,
|
||||
block: BlockModel | string,
|
||||
flavour: string
|
||||
): boolean {
|
||||
const parent = doc.getParent(block);
|
||||
if (parent === null) {
|
||||
return false;
|
||||
}
|
||||
if (flavour === parent.flavour) {
|
||||
return true;
|
||||
}
|
||||
return isInsideBlockByFlavour(doc, parent, flavour);
|
||||
}
|
||||
Reference in New Issue
Block a user