mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 09:21:24 +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:
@@ -1,3 +1,4 @@
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
@@ -53,7 +54,7 @@ export const canDedentListCommand: Command<
|
||||
* ccc
|
||||
*/
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, ['affine:list'])) {
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ListBlockModel, ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
getNearestHeadingBefore,
|
||||
@@ -54,7 +55,7 @@ export const canIndentListCommand: Command<
|
||||
* ccc
|
||||
*/
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, ['affine:list'])) {
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) {
|
||||
return;
|
||||
}
|
||||
const schema = std.store.schema;
|
||||
@@ -125,7 +126,7 @@ export const indentListCommand: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(model);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, ['affine:paragraph']) &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { focusTextModel } from '@blocksuite/affine-components/rich-text';
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
@@ -16,7 +17,7 @@ export const listToParagraphCommand: Command<
|
||||
const doc = std.store;
|
||||
const model = doc.getBlock(id)?.model;
|
||||
|
||||
if (!model || !matchFlavours(model, ['affine:list'])) return false;
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) return false;
|
||||
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) return false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { focusTextModel } from '@blocksuite/affine-components/rich-text';
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
getNextContinuousNumberedLists,
|
||||
matchFlavours,
|
||||
@@ -17,7 +18,7 @@ export const splitListCommand: Command<{
|
||||
const doc = host.doc;
|
||||
|
||||
const model = doc.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, ['affine:list'])) {
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) {
|
||||
console.error(`block ${blockId} is not a list block`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
getNextContinuousNumberedLists,
|
||||
matchFlavours,
|
||||
@@ -22,7 +22,7 @@ export function correctNumberedListsOrderToPrev(
|
||||
if (!model) return;
|
||||
|
||||
if (
|
||||
!matchFlavours(model, ['affine:list']) ||
|
||||
!matchFlavours(model, [ListBlockModel]) ||
|
||||
model.type$.value !== 'numbered'
|
||||
) {
|
||||
return;
|
||||
@@ -33,7 +33,7 @@ export function correctNumberedListsOrderToPrev(
|
||||
const previousSibling = doc.getPrev(model);
|
||||
if (
|
||||
previousSibling &&
|
||||
matchFlavours(previousSibling, ['affine:list']) &&
|
||||
matchFlavours(previousSibling, [ListBlockModel]) &&
|
||||
previousSibling.type === 'numbered'
|
||||
) {
|
||||
if (!previousSibling.order) previousSibling.order = 1;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
getNextContentBlock,
|
||||
matchFlavours,
|
||||
@@ -25,7 +26,7 @@ export function forwardDelete(std: BlockStdScope): true | undefined {
|
||||
const isCollapsed = text.isCollapsed();
|
||||
const doc = std.store;
|
||||
const model = doc.getBlock(text.from.blockId)?.model;
|
||||
if (!model || !matchFlavours(model, ['affine:list'])) return;
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) return;
|
||||
const isEnd = isCollapsed && text.from.index === model.text.length;
|
||||
if (!isEnd) return;
|
||||
// Has children in list
|
||||
|
||||
Reference in New Issue
Block a user