refactor(editor): remove block models global type (#10086)

This commit is contained in:
Saul-Mirone
2025-02-11 11:00:57 +00:00
parent a725df6ebe
commit 39eb8625d6
157 changed files with 402 additions and 621 deletions

View File

@@ -14,7 +14,7 @@ import {
getTextSelectionCommand,
} from '@blocksuite/affine-shared/commands';
import {
matchFlavours,
matchModels,
mergeToCodeModel,
transformModel,
} from '@blocksuite/affine-shared/utils';
@@ -27,7 +27,7 @@ import {
import type { BlockModel } from '@blocksuite/store';
type UpdateBlockConfig = {
flavour: BlockSuite.Flavour;
flavour: string;
props?: Record<string, unknown>;
};
@@ -200,7 +200,7 @@ export const updateBlockType: Command<
const newModels: BlockModel[] = [];
blockModels.forEach(model => {
if (
!matchFlavours(model, [
!matchModels(model, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,

View File

@@ -1,5 +1,5 @@
import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
export const changeNoteDisplayMode: Command<{
@@ -10,8 +10,7 @@ export const changeNoteDisplayMode: Command<{
const { std, noteId, mode, stopCapture } = ctx;
const noteBlockModel = std.store.getBlock(noteId)?.model;
if (!noteBlockModel || !matchFlavours(noteBlockModel, [NoteBlockModel]))
return;
if (!noteBlockModel || !matchModels(noteBlockModel, [NoteBlockModel])) return;
const currentMode = noteBlockModel.displayMode;
if (currentMode === mode) return;
@@ -27,7 +26,7 @@ export const changeNoteDisplayMode: Command<{
const parent = std.store.getParent(noteBlockModel);
if (parent) {
const notes = parent.children.filter(child =>
matchFlavours(child, [NoteBlockModel])
matchModels(child, [NoteBlockModel])
);
const firstEdgelessOnlyNote = notes.find(
note => note.displayMode === NoteDisplayMode.EdgelessOnly

View File

@@ -1,5 +1,5 @@
import { NoteBlockModel } from '@blocksuite/affine-model';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
import { dedentBlock } from './dedent-block';
@@ -21,7 +21,7 @@ export const dedentBlockToRoot: Command<{
let parent = store.getParent(model);
let changed = false;
while (parent && !matchFlavours(parent, [NoteBlockModel])) {
while (parent && !matchModels(parent, [NoteBlockModel])) {
if (!changed) {
if (stopCapture) store.captureSync();
changed = true;

View File

@@ -1,7 +1,7 @@
import { ParagraphBlockModel } from '@blocksuite/affine-model';
import {
calculateCollapsedSiblings,
matchFlavours,
matchModels,
} from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
@@ -46,7 +46,7 @@ export const dedentBlock: Command<{
if (stopCapture) store.captureSync();
if (
matchFlavours(model, [ParagraphBlockModel]) &&
matchModels(model, [ParagraphBlockModel]) &&
model.type.startsWith('h') &&
model.collapsed
) {

View File

@@ -1,5 +1,5 @@
import { NoteBlockModel } from '@blocksuite/affine-model';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import { type Command, TextSelection } from '@blocksuite/block-std';
import { dedentBlockToRoot } from './dedent-block-to-root';
@@ -31,7 +31,7 @@ export const dedentBlocksToRoot: Command<{
for (let i = blockIds.length - 1; i >= 0; i--) {
const model = blockIds[i];
const parent = store.getParent(model);
if (parent && !matchFlavours(parent, [NoteBlockModel])) {
if (parent && !matchModels(parent, [NoteBlockModel])) {
std.command.exec(dedentBlockToRoot, {
blockId: model,
stopCapture: false,

View File

@@ -1,7 +1,7 @@
import { ParagraphBlockModel } from '@blocksuite/affine-model';
import {
calculateCollapsedSiblings,
matchFlavours,
matchModels,
} from '@blocksuite/affine-shared/utils';
import { type Command, TextSelection } from '@blocksuite/block-std';
@@ -58,7 +58,7 @@ export const dedentBlocks: Command<{
const model = store.getBlock(id)?.model;
if (!model) return;
if (
matchFlavours(model, [ParagraphBlockModel]) &&
matchModels(model, [ParagraphBlockModel]) &&
model.type.startsWith('h') &&
model.collapsed
) {

View File

@@ -1,7 +1,7 @@
import { ListBlockModel, ParagraphBlockModel } from '@blocksuite/affine-model';
import {
calculateCollapsedSiblings,
matchFlavours,
matchModels,
} from '@blocksuite/affine-shared/utils';
import type { Command } from '@blocksuite/block-std';
@@ -50,7 +50,7 @@ export const indentBlock: Command<{
if (stopCapture) store.captureSync();
if (
matchFlavours(model, [ParagraphBlockModel]) &&
matchModels(model, [ParagraphBlockModel]) &&
model.type.startsWith('h') &&
model.collapsed
) {
@@ -62,7 +62,7 @@ export const indentBlock: Command<{
// update collapsed state of affine list
if (
matchFlavours(previousSibling, [ListBlockModel]) &&
matchModels(previousSibling, [ListBlockModel]) &&
previousSibling.collapsed
) {
store.updateBlock(previousSibling, {

View File

@@ -2,7 +2,7 @@ import { ParagraphBlockModel } from '@blocksuite/affine-model';
import {
calculateCollapsedSiblings,
getNearestHeadingBefore,
matchFlavours,
matchModels,
} from '@blocksuite/affine-shared/utils';
import { type Command, TextSelection } from '@blocksuite/block-std';
@@ -59,7 +59,7 @@ export const indentBlocks: Command<{
const model = store.getBlock(id)?.model;
if (!model) return;
if (
matchFlavours(model, [ParagraphBlockModel]) &&
matchModels(model, [ParagraphBlockModel]) &&
model.type.startsWith('h') &&
model.collapsed
) {
@@ -84,7 +84,7 @@ export const indentBlocks: Command<{
const nearestHeading = getNearestHeadingBefore(firstModel);
if (
nearestHeading &&
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
matchModels(nearestHeading, [ParagraphBlockModel]) &&
nearestHeading.collapsed
) {
store.updateBlock(nearestHeading, { collapsed: false });
@@ -105,7 +105,7 @@ export const indentBlocks: Command<{
const nearestHeading = getNearestHeadingBefore(firstModel);
if (
nearestHeading &&
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
matchModels(nearestHeading, [ParagraphBlockModel]) &&
nearestHeading.collapsed
) {
store.updateBlock(nearestHeading, { collapsed: false });