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 });

View File

@@ -9,7 +9,7 @@ import { ThemeProvider } from '@blocksuite/affine-shared/services';
import {
getClosestBlockComponentByPoint,
handleNativeRangeAtPoint,
matchFlavours,
matchModels,
stopPropagation,
} from '@blocksuite/affine-shared/utils';
import {
@@ -100,10 +100,10 @@ export class EdgelessNoteBackground extends SignalWatcher(
if (
(!nearestModel.text ||
!matchFlavours(nearestModel, [ParagraphBlockModel, ListBlockModel])) &&
!matchModels(nearestModel, [ParagraphBlockModel, ListBlockModel])) &&
(!siblingModel ||
!siblingModel.text ||
!matchFlavours(siblingModel, [ParagraphBlockModel, ListBlockModel]))
!matchModels(siblingModel, [ParagraphBlockModel, ListBlockModel]))
) {
const [pId] = this.doc.addSiblingBlocks(
nearestModel,

View File

@@ -12,7 +12,7 @@ import {
getPrevBlockCommand,
getTextSelectionCommand,
} from '@blocksuite/affine-shared/commands';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import {
type BlockComponent,
BlockSelection,
@@ -155,7 +155,7 @@ export class NoteBlockService extends BlockService {
const doc = this._std.store;
let parent = doc.getBlock(blockId)?.model ?? null;
while (parent) {
if (matchFlavours(parent, [NoteBlockModel])) {
if (matchModels(parent, [NoteBlockModel])) {
return parent;
}
parent = doc.getParent(parent);
@@ -194,7 +194,7 @@ export class NoteBlockService extends BlockService {
}
if (
!matchFlavours(nextBlock.model, [
!matchModels(nextBlock.model, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,
@@ -230,7 +230,7 @@ export class NoteBlockService extends BlockService {
event.preventDefault();
if (
matchFlavours(nextBlock.model, [
matchModels(nextBlock.model, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,
@@ -284,7 +284,7 @@ export class NoteBlockService extends BlockService {
}
if (
!matchFlavours(prevBlock.model, [
!matchModels(prevBlock.model, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,
@@ -318,7 +318,7 @@ export class NoteBlockService extends BlockService {
}
if (
matchFlavours(prevBlock.model, [
matchModels(prevBlock.model, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,

View File

@@ -1,6 +1,6 @@
import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import type { BlockStdScope } from '@blocksuite/block-std';
/**
@@ -11,7 +11,7 @@ export function isPageBlock(std: BlockStdScope, note: NoteBlockModel) {
std.get(FeatureFlagService).getFlag('enable_page_block') &&
note.parent?.children.find(
child =>
matchFlavours(child, [NoteBlockModel]) &&
matchModels(child, [NoteBlockModel]) &&
child.displayMode !== NoteDisplayMode.EdgelessOnly
) === note
);