mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
refactor(editor): remove block models global type (#10086)
This commit is contained in:
@@ -8,7 +8,7 @@ type ModelList<T> =
|
||||
: never
|
||||
: never;
|
||||
|
||||
export function matchFlavours<
|
||||
export function matchModels<
|
||||
const Model extends ConstructorType<BlockModel>[],
|
||||
U extends ModelList<Model>[number] = ModelList<Model>[number],
|
||||
>(model: unknown, expected: Model): model is U {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { DocModeProvider } from '../../services/doc-mode-service.js';
|
||||
import { matchFlavours } from './checker.js';
|
||||
import { matchModels } from './checker.js';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -74,7 +74,7 @@ export function getPrevContentBlock(
|
||||
|
||||
const prev = getPrev(model);
|
||||
if (prev) {
|
||||
if (prev.role === 'content' && !matchFlavours(prev, [FrameBlockModel])) {
|
||||
if (prev.role === 'content' && !matchModels(prev, [FrameBlockModel])) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from './checker.js';
|
||||
import { matchModels } from './checker.js';
|
||||
|
||||
export function findAncestorModel(
|
||||
model: BlockModel,
|
||||
@@ -37,7 +37,7 @@ export async function asyncGetBlockComponent(
|
||||
|
||||
export function findNoteBlockModel(model: BlockModel) {
|
||||
return findAncestorModel(model, m =>
|
||||
matchFlavours(m, [NoteBlockModel])
|
||||
matchModels(m, [NoteBlockModel])
|
||||
) as NoteBlockModel | null;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function getLastNoteBlock(doc: Store) {
|
||||
for (let i = children.length - 1; i >= 0; i--) {
|
||||
const child = children[i];
|
||||
if (
|
||||
matchFlavours(child, [NoteBlockModel]) &&
|
||||
matchModels(child, [NoteBlockModel]) &&
|
||||
child.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
) {
|
||||
note = child as NoteBlockModel;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from './checker.js';
|
||||
import { matchModels } from './checker.js';
|
||||
|
||||
/**
|
||||
* Pass in a list model, and this function will look forward to find continuous sibling numbered lists,
|
||||
@@ -23,7 +23,7 @@ export function getNextContinuousNumberedLists(
|
||||
const firstNotNumberedListIndex = parent.children.findIndex(
|
||||
(model, i) =>
|
||||
i > modelIndex &&
|
||||
(!matchFlavours(model, [ListBlockModel]) || model.type !== 'numbered')
|
||||
(!matchModels(model, [ListBlockModel]) || model.type !== 'numbered')
|
||||
);
|
||||
const newContinuousLists = parent.children.slice(
|
||||
modelIndex + 1,
|
||||
@@ -31,8 +31,7 @@ export function getNextContinuousNumberedLists(
|
||||
);
|
||||
if (
|
||||
!newContinuousLists.every(
|
||||
model =>
|
||||
matchFlavours(model, [ListBlockModel]) && model.type === 'numbered'
|
||||
model => matchModels(model, [ListBlockModel]) && model.type === 'numbered'
|
||||
)
|
||||
)
|
||||
return [];
|
||||
@@ -56,7 +55,7 @@ export function toNumberedList(
|
||||
// if there is a numbered list before, the order continues from the previous list
|
||||
if (
|
||||
prevSibling &&
|
||||
matchFlavours(prevSibling, [ListBlockModel]) &&
|
||||
matchModels(prevSibling, [ListBlockModel]) &&
|
||||
prevSibling.type === 'numbered'
|
||||
) {
|
||||
doc.transact(() => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { BlockModel, Store, Text } from '@blocksuite/store';
|
||||
|
||||
export function transformModel(
|
||||
model: BlockModel,
|
||||
flavour: BlockSuite.Flavour,
|
||||
flavour: string,
|
||||
props?: Parameters<Store['addBlock']>[1]
|
||||
) {
|
||||
const doc = model.doc;
|
||||
|
||||
Reference in New Issue
Block a user