mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 23:37:15 +08:00
refactor(editor): remove global types in model (#10082)
Closes: [BS-2249](https://linear.app/affine-design/issue/BS-2249/remove-global-types-in-model) ```ts // before matchFlavours(model, ['affine:page']); // after matchFlavours(model, [PageBlockModel]); ```
This commit is contained in:
@@ -3,6 +3,11 @@ import {
|
||||
focusTextModel,
|
||||
onModelTextUpdated,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import {
|
||||
CodeBlockModel,
|
||||
ListBlockModel,
|
||||
ParagraphBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import {
|
||||
getBlockSelectionsCommand,
|
||||
getSelectedBlocksCommand,
|
||||
@@ -196,9 +201,9 @@ export const updateBlockType: Command<
|
||||
blockModels.forEach(model => {
|
||||
if (
|
||||
!matchFlavours(model, [
|
||||
'affine:paragraph',
|
||||
'affine:list',
|
||||
'affine:code',
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
])
|
||||
) {
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
@@ -10,7 +10,7 @@ export const changeNoteDisplayMode: Command<{
|
||||
const { std, noteId, mode, stopCapture } = ctx;
|
||||
|
||||
const noteBlockModel = std.store.getBlock(noteId)?.model;
|
||||
if (!noteBlockModel || !matchFlavours(noteBlockModel, ['affine:note']))
|
||||
if (!noteBlockModel || !matchFlavours(noteBlockModel, [NoteBlockModel]))
|
||||
return;
|
||||
|
||||
const currentMode = noteBlockModel.displayMode;
|
||||
@@ -27,7 +27,7 @@ export const changeNoteDisplayMode: Command<{
|
||||
const parent = std.store.getParent(noteBlockModel);
|
||||
if (parent) {
|
||||
const notes = parent.children.filter(child =>
|
||||
matchFlavours(child, ['affine:note'])
|
||||
matchFlavours(child, [NoteBlockModel])
|
||||
);
|
||||
const firstEdgelessOnlyNote = notes.find(
|
||||
note => note.displayMode === NoteDisplayMode.EdgelessOnly
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { NoteBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
@@ -20,7 +21,7 @@ export const dedentBlockToRoot: Command<{
|
||||
|
||||
let parent = store.getParent(model);
|
||||
let changed = false;
|
||||
while (parent && !matchFlavours(parent, ['affine:note'])) {
|
||||
while (parent && !matchFlavours(parent, [NoteBlockModel])) {
|
||||
if (!changed) {
|
||||
if (stopCapture) store.captureSync();
|
||||
changed = true;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
@@ -45,7 +46,7 @@ export const dedentBlock: Command<{
|
||||
if (stopCapture) store.captureSync();
|
||||
|
||||
if (
|
||||
matchFlavours(model, ['affine:paragraph']) &&
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { NoteBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
@@ -30,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, ['affine:note'])) {
|
||||
if (parent && !matchFlavours(parent, [NoteBlockModel])) {
|
||||
std.command.exec(dedentBlockToRoot, {
|
||||
blockId: model,
|
||||
stopCapture: false,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
@@ -57,7 +58,7 @@ export const dedentBlocks: Command<{
|
||||
const model = store.getBlock(id)?.model;
|
||||
if (!model) return;
|
||||
if (
|
||||
matchFlavours(model, ['affine:paragraph']) &&
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import { ListBlockModel, ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
@@ -50,7 +50,7 @@ export const indentBlock: Command<{
|
||||
if (stopCapture) store.captureSync();
|
||||
|
||||
if (
|
||||
matchFlavours(model, ['affine:paragraph']) &&
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
@@ -62,12 +62,12 @@ export const indentBlock: Command<{
|
||||
|
||||
// update collapsed state of affine list
|
||||
if (
|
||||
matchFlavours(previousSibling, ['affine:list']) &&
|
||||
matchFlavours(previousSibling, [ListBlockModel]) &&
|
||||
previousSibling.collapsed
|
||||
) {
|
||||
store.updateBlock(previousSibling, {
|
||||
collapsed: false,
|
||||
} as Partial<ListBlockModel>);
|
||||
});
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
getNearestHeadingBefore,
|
||||
@@ -58,7 +59,7 @@ export const indentBlocks: Command<{
|
||||
const model = store.getBlock(id)?.model;
|
||||
if (!model) return;
|
||||
if (
|
||||
matchFlavours(model, ['affine:paragraph']) &&
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
@@ -83,12 +84,10 @@ export const indentBlocks: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(firstModel);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, ['affine:paragraph']) &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, {
|
||||
collapsed: false,
|
||||
});
|
||||
store.updateBlock(nearestHeading, { collapsed: false });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,12 +105,10 @@ export const indentBlocks: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(firstModel);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, ['affine:paragraph']) &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, {
|
||||
collapsed: false,
|
||||
});
|
||||
store.updateBlock(nearestHeading, { collapsed: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user