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

@@ -29,7 +29,7 @@ import {
isInsidePageEditor,
isTopLevelBlock,
isUrlInClipboard,
matchFlavours,
matchModels,
referenceToNode,
} from '@blocksuite/affine-shared/utils';
import type {
@@ -41,6 +41,7 @@ import type {
import {
compareLayer,
type GfxCompatibleProps,
type GfxModel,
type SerializedElement,
SortOrder,
} from '@blocksuite/block-std/gfx';
@@ -995,7 +996,7 @@ export class EdgelessClipboardController extends PageClipboard {
for (const nodeElement of nodeElements) {
await _drawTopLevelBlock(nodeElement);
if (matchFlavours(nodeElement, [FrameBlockModel])) {
if (matchModels(nodeElement, [FrameBlockModel])) {
const blocksInsideFrame: BlockSuite.EdgelessBlockModelType[] = [];
this.edgeless.service.frame
.getElementsInFrameBound(nodeElement, false)
@@ -1153,21 +1154,21 @@ export class EdgelessClipboardController extends PageClipboard {
}
private _updatePastedElementsIndex(
elements: BlockSuite.EdgelessModel[],
elements: GfxModel[],
originalIndexes: Map<string, string>
) {
function compare(a: BlockSuite.EdgelessModel, b: BlockSuite.EdgelessModel) {
function compare(a: GfxModel, b: GfxModel) {
if (a instanceof SurfaceGroupLikeModel && a.hasDescendant(b)) {
return SortOrder.BEFORE;
} else if (b instanceof SurfaceGroupLikeModel && b.hasDescendant(a)) {
return SortOrder.AFTER;
} else {
const aGroups = a.groups as BlockSuite.SurfaceGroupLikeModel[];
const bGroups = b.groups as BlockSuite.SurfaceGroupLikeModel[];
const aGroups = a.groups as SurfaceGroupLikeModel[];
const bGroups = b.groups as SurfaceGroupLikeModel[];
let i = 1;
let aGroup: BlockSuite.EdgelessModel | undefined = nToLast(aGroups, i);
let bGroup: BlockSuite.EdgelessModel | undefined = nToLast(bGroups, i);
let aGroup: GfxModel | undefined = nToLast(aGroups, i);
let bGroup: GfxModel | undefined = nToLast(bGroups, i);
while (aGroup === bGroup && aGroup) {
++i;
@@ -1246,7 +1247,7 @@ export class EdgelessClipboardController extends PageClipboard {
const blockModels: BlockSuite.EdgelessBlockModelType[] = [];
const canvasElements: BlockSuite.SurfaceModel[] = [];
const allElements: BlockSuite.EdgelessModel[] = [];
const allElements: GfxModel[] = [];
for (const data of elementsRawData) {
const { data: blockSnapshot } = BlockSnapshotSchema.safeParse(data);
@@ -1371,7 +1372,7 @@ export class EdgelessClipboardController extends PageClipboard {
}
export async function prepareClipboardData(
selectedAll: BlockSuite.EdgelessModel[],
selectedAll: GfxModel[],
std: BlockStdScope
) {
const job = new Transformer({

View File

@@ -958,11 +958,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
* Related issue: https://linear.app/affine-design/issue/BS-1009/
* @deprecated
*/
#adjustAIChat(
element: BlockSuite.EdgelessModel,
bound: Bound,
direction: HandleDirection
) {
#adjustAIChat(element: GfxModel, bound: Bound, direction: HandleDirection) {
const curBound = Bound.deserialize(element.xywh);
let scale = 1;
@@ -1165,7 +1161,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
}
#adjustProportional(
element: BlockSuite.EdgelessModel,
element: GfxModel,
bound: Bound,
direction: HandleDirection
) {
@@ -1263,7 +1259,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
}
#adjustUseFallback(
element: BlockSuite.EdgelessModel,
element: GfxModel,
bound: Bound,
_direction: HandleDirection
) {
@@ -1293,7 +1289,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
);
}
private _isProportionalElement(element: BlockSuite.EdgelessModel) {
private _isProportionalElement(element: GfxModel) {
return (
isAttachmentBlock(element) ||
isImageBlock(element) ||
@@ -1306,7 +1302,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
);
}
private _shouldRenderSelection(elements?: BlockSuite.EdgelessModel[]) {
private _shouldRenderSelection(elements?: GfxModel[]) {
elements = elements ?? this.selection.selectedElements;
return elements.length > 0 && !this.selection.editing;
}

View File

@@ -19,7 +19,7 @@ import {
TelemetryProvider,
} from '@blocksuite/affine-shared/services';
import { LassoMode } from '@blocksuite/affine-shared/types';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import { SurfaceSelection, TextSelection } from '@blocksuite/block-std';
import {
GfxBlockElementModel,
@@ -134,7 +134,7 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
if (
selection.selectedElements.length === 1 &&
selection.firstElement instanceof GfxBlockElementModel &&
matchFlavours(selection.firstElement as GfxBlockElementModel, [
matchModels(selection.firstElement as GfxBlockElementModel, [
NoteBlockModel,
])
) {
@@ -260,7 +260,7 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
block =>
block.group === null &&
!(
matchFlavours(block, [NoteBlockModel]) &&
matchModels(block, [NoteBlockModel]) &&
block.displayMode === NoteDisplayMode.DocOnly
)
)

View File

@@ -24,7 +24,7 @@ import {
import type { Viewport } from '@blocksuite/affine-shared/types';
import {
isTouchPadPinchEvent,
matchFlavours,
matchModels,
requestConnectedFrame,
requestThrottledConnectedFrame,
} from '@blocksuite/affine-shared/utils';
@@ -350,7 +350,7 @@ export class EdgelessRootBlockComponent extends BlockComponent<
const primaryMode = std.get(DocModeProvider).getPrimaryMode(this.doc.id);
const note = this.model.children.find(
(child): child is NoteBlockModel =>
matchFlavours(child, [NoteBlockModel]) &&
matchModels(child, [NoteBlockModel]) &&
child.displayMode !== NoteDisplayMode.EdgelessOnly
);

View File

@@ -169,7 +169,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
);
}
createGroup(elements: BlockSuite.EdgelessModel[] | string[]) {
createGroup(elements: GfxModel[] | string[]) {
const groups = this.elements.filter(
el => el.type === 'group'
) as GroupElementModel[];
@@ -277,7 +277,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
return this.layer.generateIndex();
}
getConnectors(element: BlockSuite.EdgelessModel | string) {
getConnectors(element: GfxModel | string) {
const id = typeof element === 'string' ? element : element.id;
return this.surface.getConnectors(id) as ConnectorElementModel[];
@@ -298,11 +298,11 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
x: number,
y: number,
options?: PointTestOptions
): BlockSuite.EdgelessModel | null {
): GfxModel | null {
return this.gfx.getElementInGroup(x, y, options);
}
removeElement(id: string | BlockSuite.EdgelessModel) {
removeElement(id: string | GfxModel) {
id = typeof id === 'string' ? id : id.id;
const el = this.crud.getElementById(id);
@@ -323,10 +323,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
}
}
reorderElement(
element: BlockSuite.EdgelessModel,
direction: ReorderingDirection
) {
reorderElement(element: GfxModel, direction: ReorderingDirection) {
const index = this.layer.getReorderedIndex(element, direction);
// block should be updated in transaction

View File

@@ -390,7 +390,7 @@ export class EdgelessFrameManager extends GfxExtension {
.map(id => this.gfx.getElementById(id))
.filter(element => element !== null);
return childElements as BlockSuite.EdgelessModel[];
return childElements as GfxModel[];
}
/**

View File

@@ -18,7 +18,7 @@ import {
} from '@blocksuite/affine-model';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import type { PointerEventState } from '@blocksuite/block-std';
import { BaseTool } from '@blocksuite/block-std/gfx';
import { BaseTool, type GfxModel } from '@blocksuite/block-std/gfx';
import type { IBound, IVec } from '@blocksuite/global/utils';
import { Bound } from '@blocksuite/global/utils';
@@ -189,7 +189,7 @@ export class ConnectorTool extends BaseTool<ConnectorToolOptions> {
this._overlay?.clear();
}
quickConnect(point: IVec, element: BlockSuite.EdgelessModel) {
quickConnect(point: IVec, element: GfxModel) {
this._startPoint = this.gfx.viewport.toModelCoord(point[0], point[1]);
this._mode = ConnectorToolMode.Quick;
this._sourceBounds = Bound.deserialize(element.xywh);

View File

@@ -1,6 +1,10 @@
/* oxlint-disable @typescript-eslint/no-non-null-assertion */
import type { PointerEventState } from '@blocksuite/block-std';
import { BaseTool, MouseButton } from '@blocksuite/block-std/gfx';
import {
BaseTool,
type GfxModel,
MouseButton,
} from '@blocksuite/block-std/gfx';
import { IS_MAC } from '@blocksuite/global/env';
import {
Bound,
@@ -141,10 +145,7 @@ export class CopilotTool extends BaseTool {
this.gfx.tool.setTool('default');
}
updateDragPointsWith(
selectedElements: BlockSuite.EdgelessModel[],
padding = 0
) {
updateDragPointsWith(selectedElements: GfxModel[], padding = 0) {
const bounds = getCommonBoundWithRotation(selectedElements).expand(
padding / this.gfx.viewport.zoom
);
@@ -153,10 +154,7 @@ export class CopilotTool extends BaseTool {
this.dragLastPoint = bounds.br as [number, number];
}
updateSelectionWith(
selectedElements: BlockSuite.EdgelessModel[],
padding = 0
) {
updateSelectionWith(selectedElements: GfxModel[], padding = 0) {
const { selection } = this.gfx;
selection.clear();

View File

@@ -5,7 +5,7 @@ import {
} from '@blocksuite/affine-block-surface';
import { isTopLevelBlock } from '@blocksuite/affine-shared/utils';
import type { PointerEventState } from '@blocksuite/block-std';
import { BaseTool } from '@blocksuite/block-std/gfx';
import { BaseTool, type GfxModel } from '@blocksuite/block-std/gfx';
import {
Bound,
getStroke,
@@ -28,11 +28,11 @@ class EraserOverlay extends Overlay {
export class EraserTool extends BaseTool {
static override toolName = 'eraser';
private _erasable = new Set<BlockSuite.EdgelessModel>();
private _erasable = new Set<GfxModel>();
private _eraserPoints: IVec[] = [];
private readonly _eraseTargets = new Set<BlockSuite.EdgelessModel>();
private readonly _eraseTargets = new Set<GfxModel>();
private readonly _loop = () => {
const now = Date.now();

View File

@@ -211,7 +211,7 @@ export class TemplateJob {
assertExists(modelData);
doc.addBlock(
modelData.flavour as BlockSuite.Flavour,
modelData.flavour,
{
...modelData.props,
id: modelData.id,

View File

@@ -10,6 +10,7 @@ import type {
import { getElementsWithoutGroup } from '@blocksuite/affine-shared/utils';
import {
generateKeyBetweenV2,
type GfxModel,
type SerializedElement,
} from '@blocksuite/block-std/gfx';
import { getCommonBoundWithRotation, groupBy } from '@blocksuite/global/utils';
@@ -28,7 +29,7 @@ import {
const offset = 10;
export async function duplicate(
edgeless: EdgelessRootBlockComponent,
elements: BlockSuite.EdgelessModel[],
elements: GfxModel[],
select = true
) {
const { clipboardController } = edgeless;
@@ -54,7 +55,7 @@ export async function duplicate(
});
}
}
export const splitElements = (elements: BlockSuite.EdgelessModel[]) => {
export const splitElements = (elements: GfxModel[]) => {
const { notes, frames, shapes, images, edgelessTexts, embedSyncedDocs } =
groupBy(getElementsWithoutGroup(elements), element => {
if (isNoteBlock(element)) {

View File

@@ -1,4 +1,5 @@
import { isNoteBlock } from '@blocksuite/affine-block-surface';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import type { Connectable } from '../../../_common/utils/index.js';
import type { EdgelessRootBlockComponent } from '../index.js';
@@ -10,7 +11,7 @@ import { isConnectable } from './query.js';
*/
export function deleteElements(
edgeless: EdgelessRootBlockComponent,
elements: BlockSuite.EdgelessModel[]
elements: GfxModel[]
) {
const set = new Set(elements);
const { service } = edgeless;

View File

@@ -39,14 +39,12 @@ import type { BlockModel } from '@blocksuite/store';
import type { Connectable } from '../../../_common/utils/index.js';
export function isMindmapNode(
element: GfxBlockElementModel | BlockSuite.EdgelessModel | null
) {
export function isMindmapNode(element: GfxBlockElementModel | GfxModel | null) {
return element?.group instanceof MindmapElementModel;
}
export function isEdgelessTextBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EdgelessTextBlockModel {
return (
!!element &&
@@ -60,7 +58,7 @@ export function isFrameBlock(element: unknown): element is FrameBlockModel {
}
export function isImageBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is ImageBlockModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:image'
@@ -68,7 +66,7 @@ export function isImageBlock(
}
export function isAttachmentBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is AttachmentBlockModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:attachment'
@@ -76,7 +74,7 @@ export function isAttachmentBlock(
}
export function isBookmarkBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is BookmarkBlockModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:bookmark'
@@ -84,7 +82,7 @@ export function isBookmarkBlock(
}
export function isEmbeddedBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedBlockModel {
return (
!!element && 'flavour' in element && /affine:embed-*/.test(element.flavour)
@@ -98,9 +96,7 @@ export function isEmbeddedBlock(
* Related issue: https://linear.app/affine-design/issue/BS-1009/
* @deprecated
*/
export function isAIChatBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
) {
export function isAIChatBlock(element: BlockModel | GfxModel | null) {
return (
!!element &&
'flavour' in element &&
@@ -108,9 +104,7 @@ export function isAIChatBlock(
);
}
export function isEmbeddedLinkBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
) {
export function isEmbeddedLinkBlock(element: BlockModel | GfxModel | null) {
return (
isEmbeddedBlock(element) &&
!isEmbedSyncedDocBlock(element) &&
@@ -119,7 +113,7 @@ export function isEmbeddedLinkBlock(
}
export function isEmbedGithubBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedGithubModel {
return (
!!element &&
@@ -129,7 +123,7 @@ export function isEmbedGithubBlock(
}
export function isEmbedYoutubeBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedYoutubeModel {
return (
!!element &&
@@ -139,7 +133,7 @@ export function isEmbedYoutubeBlock(
}
export function isEmbedLoomBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedLoomModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:embed-loom'
@@ -147,7 +141,7 @@ export function isEmbedLoomBlock(
}
export function isEmbedFigmaBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedFigmaModel {
return (
!!element &&
@@ -157,7 +151,7 @@ export function isEmbedFigmaBlock(
}
export function isEmbedLinkedDocBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedLinkedDocModel {
return (
!!element &&
@@ -167,7 +161,7 @@ export function isEmbedLinkedDocBlock(
}
export function isEmbedSyncedDocBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedSyncedDocModel {
return (
!!element &&
@@ -177,7 +171,7 @@ export function isEmbedSyncedDocBlock(
}
export function isEmbedHtmlBlock(
element: BlockModel | BlockSuite.EdgelessModel | null
element: BlockModel | GfxModel | null
): element is EmbedHtmlModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:embed-html'
@@ -191,7 +185,7 @@ export function isCanvasElement(
}
export function isCanvasElementWithText(
element: BlockSuite.EdgelessModel
element: GfxModel
): element is CanvasElementWithText {
return (
element instanceof TextElementModel || element instanceof ShapeElementModel
@@ -199,7 +193,7 @@ export function isCanvasElementWithText(
}
export function isConnectable(
element: BlockSuite.EdgelessModel | null
element: GfxModel | null
): element is Connectable {
return !!element && element.connectable;
}
@@ -253,7 +247,7 @@ export type SelectableProps = {
};
export function getSelectableBounds(
selected: BlockSuite.EdgelessModel[]
selected: GfxModel[]
): Map<string, SelectableProps> {
const bounds = new Map();
getElementsWithoutGroup(selected).forEach(ele => {

View File

@@ -4,7 +4,7 @@ import type {
} from '@blocksuite/affine-block-surface';
import { getSurfaceBlock, Overlay } from '@blocksuite/affine-block-surface';
import type { ConnectorElementModel } from '@blocksuite/affine-model';
import type { GfxController } from '@blocksuite/block-std/gfx';
import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { Bound, Point } from '@blocksuite/global/utils';
@@ -413,10 +413,7 @@ export class EdgelessSnapManager extends Overlay {
});
}
setupAlignables(
alignables: BlockSuite.EdgelessModel[],
exclude: BlockSuite.EdgelessModel[] = []
): Bound {
setupAlignables(alignables: GfxModel[], exclude: GfxModel[] = []): Bound {
if (alignables.length === 0) return new Bound();
const connectors = alignables.filter(isConnectable).reduce((prev, el) => {
@@ -437,20 +434,17 @@ export class EdgelessSnapManager extends Overlay {
const canvasElements = this.gfx.layer.canvasElements;
const excludes = new Set([...alignables, ...exclude, ...connectors]);
this._alignableBounds = [];
(
[
...this.gfx.layer.blocks,
...canvasElements,
] as BlockSuite.EdgelessModel[]
).forEach(alignable => {
const bounds = alignable.elementBound;
if (
viewportBounds.isOverlapWithBound(bounds) &&
!excludes.has(alignable)
) {
this._alignableBounds.push(bounds);
([...this.gfx.layer.blocks, ...canvasElements] as GfxModel[]).forEach(
alignable => {
const bounds = alignable.elementBound;
if (
viewportBounds.isOverlapWithBound(bounds) &&
!excludes.has(alignable)
) {
this._alignableBounds.push(bounds);
}
}
});
);
return alignables.reduce((prev, element) => {
const bounds = element.elementBound;

View File

@@ -10,7 +10,7 @@ import {
draftSelectedModelsCommand,
getSelectedModelsCommand,
} from '@blocksuite/affine-shared/commands';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import {
type BlockComponent,
BlockSelection,
@@ -38,7 +38,7 @@ export class PageKeyboardManager {
const model = block.model;
if (
matchFlavours(model, [ParagraphBlockModel]) &&
matchModels(model, [ParagraphBlockModel]) &&
model.type.startsWith('h') &&
model.collapsed
) {
@@ -134,7 +134,7 @@ export class PageKeyboardManager {
const selectedModels = ctx.selectedModels?.filter(
block =>
!block.flavour.startsWith('affine:embed-') &&
matchFlavours(doc.getParent(block), [NoteBlockModel])
matchModels(doc.getParent(block), [NoteBlockModel])
);
const draftedModels = ctx.draftedModels;

View File

@@ -14,7 +14,7 @@ import {
getClosestBlockComponentByPoint,
getDocTitleInlineEditor,
getScrollContainer,
matchFlavours,
matchModels,
} from '@blocksuite/affine-shared/utils';
import type { PointerEventState } from '@blocksuite/block-std';
import {
@@ -128,11 +128,7 @@ export class PageRootBlockComponent extends BlockComponent<
focusFirstParagraph = (): { id: string; created: boolean } => {
const defaultNote = this._getDefaultNoteBlock();
const firstText = defaultNote?.children.find(block =>
matchFlavours(block, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,
])
matchModels(block, [ParagraphBlockModel, ListBlockModel, CodeBlockModel])
);
if (firstText) {
focusTextModel(this.std, firstText.id);
@@ -248,7 +244,7 @@ export class PageRootBlockComponent extends BlockComponent<
'Mod-a': () => {
const blocks = this.model.children
.filter(model => {
if (matchFlavours(model, [NoteBlockModel])) {
if (matchModels(model, [NoteBlockModel])) {
if (model.displayMode === NoteDisplayMode.EdgelessOnly)
return false;
@@ -394,7 +390,7 @@ export class PageRootBlockComponent extends BlockComponent<
.slice()
.reverse()
.find(child => {
const isNote = matchFlavours(child, [NoteBlockModel]);
const isNote = matchModels(child, [NoteBlockModel]);
if (!isNote) return false;
const displayOnDoc =
!!child.displayMode &&
@@ -410,9 +406,7 @@ export class PageRootBlockComponent extends BlockComponent<
const last = lastNote.children.at(-1);
if (
!last ||
!(
matchFlavours(last, [ParagraphBlockModel]) && last.text.length === 0
)
!(matchModels(last, [ParagraphBlockModel]) && last.text.length === 0)
) {
if (readonly) return;
const paragraphId = this.doc.addBlock(
@@ -452,7 +446,7 @@ export class PageRootBlockComponent extends BlockComponent<
override firstUpdated() {
this._initViewportResizeEffect();
const noteModels = this.model.children.filter(model =>
matchFlavours(model, [NoteBlockModel])
matchModels(model, [NoteBlockModel])
);
noteModels.forEach(note => {
this.disposables.add(
@@ -473,7 +467,7 @@ export class PageRootBlockComponent extends BlockComponent<
)}`;
const children = this.renderChildren(this.model, child => {
const isNote = matchFlavours(child, [NoteBlockModel]);
const isNote = matchModels(child, [NoteBlockModel]);
const note = child as NoteBlockModel;
const displayOnEdgeless =
!!note.displayMode && note.displayMode === NoteDisplayMode.EdgelessOnly;

View File

@@ -1,6 +1,7 @@
import { FrameIcon } from '@blocksuite/affine-components/icons';
import { MindmapElementModel } from '@blocksuite/affine-model';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import { Bound, WithDisposable } from '@blocksuite/global/utils';
import { css, html, LitElement, nothing } from 'lit';
import { property } from 'lit/decorators.js';
@@ -48,7 +49,7 @@ export class EdgelessAddFrameButton extends WithDisposable(LitElement) {
export function renderAddFrameButton(
edgeless: EdgelessRootBlockComponent,
elements: BlockSuite.EdgelessModel[]
elements: GfxModel[]
) {
if (elements.length < 2) return nothing;
if (elements.some(e => e.group instanceof MindmapElementModel))

View File

@@ -3,6 +3,7 @@ import {
GroupElementModel,
MindmapElementModel,
} from '@blocksuite/affine-model';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import { WithDisposable } from '@blocksuite/global/utils';
import { css, html, LitElement, nothing } from 'lit';
import { property } from 'lit/decorators.js';
@@ -39,7 +40,7 @@ export class EdgelessAddGroupButton extends WithDisposable(LitElement) {
export function renderAddGroupButton(
edgeless: EdgelessRootBlockComponent,
elements: BlockSuite.EdgelessModel[]
elements: GfxModel[]
) {
if (elements.length < 2) return nothing;
if (elements[0] instanceof GroupElementModel) return nothing;

View File

@@ -16,6 +16,7 @@ import {
SmallArrowDownIcon,
} from '@blocksuite/affine-components/icons';
import { MindmapElementModel } from '@blocksuite/affine-model';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import { Bound, WithDisposable } from '@blocksuite/global/utils';
import { AutoTidyUpIcon, ResizeTidyUpIcon } from '@blocksuite/icons/lit';
import { css, html, LitElement, nothing, type TemplateResult } from 'lit';
@@ -271,7 +272,7 @@ export class EdgelessAlignButton extends WithDisposable(LitElement) {
});
}
private _updateXYWH(ele: BlockSuite.EdgelessModel, bound: Bound) {
private _updateXYWH(ele: GfxModel, bound: Bound) {
const { updateElement } = this.edgeless.std.get(EdgelessCRUDIdentifier);
const { updateBlock } = this.edgeless.doc;
updateXYWH(ele, bound, updateElement, updateBlock);
@@ -333,7 +334,7 @@ export class EdgelessAlignButton extends WithDisposable(LitElement) {
export function renderAlignButton(
edgeless: EdgelessRootBlockComponent,
elements: BlockSuite.EdgelessModel[]
elements: GfxModel[]
) {
if (elements.length < 2) return nothing;
if (elements.some(e => e.group instanceof MindmapElementModel))

View File

@@ -25,7 +25,7 @@ import {
} from '@blocksuite/affine-model';
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
import type { ColorEvent } from '@blocksuite/affine-shared/utils';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import { GfxExtensionIdentifier } from '@blocksuite/block-std/gfx';
import {
countBy,
@@ -93,7 +93,7 @@ export class EdgelessChangeFrameButton extends WithDisposable(LitElement) {
const rootModel = this.edgeless.doc.root;
const notes = rootModel.children.filter(
model =>
matchFlavours(model, [NoteBlockModel]) &&
matchModels(model, [NoteBlockModel]) &&
model.displayMode !== NoteDisplayMode.EdgelessOnly
);
const lastNote = notes[notes.length - 1];

View File

@@ -11,7 +11,7 @@ import {
NoteBlockModel,
NoteDisplayMode,
} from '@blocksuite/affine-model';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import {
deserializeXYWH,
serializeXYWH,
@@ -31,7 +31,7 @@ export class EdgelessChangeGroupButton extends WithDisposable(LitElement) {
const rootModel = this.edgeless.doc.root;
const notes = rootModel.children.filter(
model =>
matchFlavours(model, [NoteBlockModel]) &&
matchModels(model, [NoteBlockModel]) &&
model.displayMode !== NoteDisplayMode.EdgelessOnly
);
const lastNote = notes[notes.length - 1];

View File

@@ -35,7 +35,7 @@ import {
SidebarExtensionIdentifier,
ThemeProvider,
} from '@blocksuite/affine-shared/services';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import {
Bound,
countBy,
@@ -158,7 +158,7 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {
this._pageBlockEnabled &&
this.notes.length === 1 &&
this.notes[0].parent?.children.find(child =>
matchFlavours(child, [NoteBlockModel])
matchModels(child, [NoteBlockModel])
) === this.notes[0]
);
}
@@ -340,7 +340,7 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {
const isFirstNote =
onlyOne &&
note.parent?.children.find(child =>
matchFlavours(child, [NoteBlockModel])
matchModels(child, [NoteBlockModel])
) === note;
const theme = this.edgeless.std.get(ThemeProvider).theme;
const buttons = [

View File

@@ -29,6 +29,7 @@ import {
import { ThemeProvider } from '@blocksuite/affine-shared/services';
import { requestConnectedFrame } from '@blocksuite/affine-shared/utils';
import { WidgetComponent } from '@blocksuite/block-std';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import {
atLeastNMatches,
clamp,
@@ -85,7 +86,7 @@ type CategorizedElements = {
type CustomEntry = {
render: (edgeless: EdgelessRootBlockComponent) => TemplateResult | null;
when: (model: BlockSuite.EdgelessModel[]) => boolean;
when: (model: GfxModel[]) => boolean;
};
export const EDGELESS_ELEMENT_TOOLBAR_WIDGET =
@@ -461,7 +462,7 @@ export class EdgelessElementToolbarWidget extends WidgetComponent<
@state()
private accessor _registeredEntries: {
render: (edgeless: EdgelessRootBlockComponent) => TemplateResult | null;
when: (model: BlockSuite.EdgelessModel[]) => boolean;
when: (model: GfxModel[]) => boolean;
}[] = [];
@property({ attribute: false })

View File

@@ -1,5 +1,6 @@
import type { MenuItemGroup } from '@blocksuite/affine-components/toolbar';
import { renderGroups } from '@blocksuite/affine-components/toolbar';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import { WithDisposable } from '@blocksuite/global/utils';
import { MoreHorizontalIcon, MoreVerticalIcon } from '@blocksuite/icons/lit';
import { html, LitElement } from 'lit';
@@ -39,7 +40,7 @@ export class EdgelessMoreButton extends WithDisposable(LitElement) {
accessor edgeless!: EdgelessRootBlockComponent;
@property({ attribute: false })
accessor elements: BlockSuite.EdgelessModel[] = [];
accessor elements: GfxModel[] = [];
@property({ attribute: false })
accessor groups!: MenuItemGroup<ElementToolbarMoreMenuContext>[];

View File

@@ -4,7 +4,7 @@ import { NoteDisplayMode } from '@blocksuite/affine-model';
import { DocModeProvider } from '@blocksuite/affine-shared/services';
import { getBlockProps } from '@blocksuite/affine-shared/utils';
import type { EditorHost } from '@blocksuite/block-std';
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
import { GfxBlockElementModel, type GfxModel } from '@blocksuite/block-std/gfx';
import { type BlockModel, type Store, Text } from '@blocksuite/store';
import {
@@ -17,11 +17,7 @@ import { isFrameBlock } from '../../../edgeless/utils/query.js';
function addBlocksToDoc(targetDoc: Store, model: BlockModel, parentId: string) {
// Add current block to linked doc
const blockProps = getBlockProps(model);
const newModelId = targetDoc.addBlock(
model.flavour as BlockSuite.Flavour,
blockProps,
parentId
);
const newModelId = targetDoc.addBlock(model.flavour, blockProps, parentId);
// Add children to linked doc, parent is the new model
const children = model.children;
if (children.length > 0) {
@@ -64,7 +60,7 @@ export function createLinkedDocFromNote(
export function createLinkedDocFromEdgelessElements(
host: EditorHost,
elements: BlockSuite.EdgelessModel[],
elements: GfxModel[],
docTitle?: string
) {
const linkedDoc = host.doc.workspace.createDoc({});
@@ -93,11 +89,7 @@ export function createLinkedDocFromEdgelessElements(
mapFrameIds(blockProps as unknown as FrameBlockModel, ids);
}
newId = linkedDoc.addBlock(
model.flavour as BlockSuite.Flavour,
blockProps,
surfaceId
);
newId = linkedDoc.addBlock(model.flavour, blockProps, surfaceId);
}
} else {
const props = getElementProps(model, ids);

View File

@@ -52,12 +52,7 @@ export const BUILT_IN_GROUPS: MenuItemGroup<EmbedCardToolbarContext>[] = [
const parent = doc.getParent(model);
const index = parent?.children.indexOf(model);
doc.addBlock(
model.flavour as BlockSuite.Flavour,
duplicateProps,
parent,
index
);
doc.addBlock(model.flavour, duplicateProps, parent, index);
close();
},
},

View File

@@ -21,7 +21,7 @@ import {
getTextSelectionCommand,
} from '@blocksuite/affine-shared/commands';
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { matchModels } from '@blocksuite/affine-shared/utils';
import {
type BlockComponent,
BlockSelection,
@@ -360,7 +360,7 @@ export class AffineFormatBarWidget extends WidgetComponent {
if (this.displayType === 'block' && this._selectedBlocks.length === 1) {
const selectedBlock = this._selectedBlocks[0];
if (
!matchFlavours(selectedBlock.model, [
!matchModels(selectedBlock.model, [
ParagraphBlockModel,
ListBlockModel,
CodeBlockModel,
@@ -421,7 +421,7 @@ export class AffineFormatBarWidget extends WidgetComponent {
}
addBlockTypeSwitch(config: {
flavour: BlockSuite.Flavour;
flavour: string;
icon: ParagraphActionConfigItem['icon'];
type?: string;
name?: string;

View File

@@ -27,7 +27,7 @@ export function duplicate(
const index = parent?.children.indexOf(model);
const duplicateId = doc.addBlock(
model.flavour as BlockSuite.Flavour,
model.flavour,
duplicateProps,
parent,
index + 1

View File

@@ -120,12 +120,7 @@ export class AffineLinkedDocWidget extends WidgetComponent<
const block = containerElement.closest<BlockComponent>(
`[${BLOCK_ID_ATTR}]`
);
if (
!block ||
this.config.ignoreBlockTypes.includes(
block.flavour as keyof BlockSuite.BlockModels
)
)
if (!block || this.config.ignoreBlockTypes.includes(block.flavour))
return;
const inlineRoot = containerElement.closest<InlineRootElement>(

View File

@@ -2,7 +2,7 @@ import { NoteBlockModel, RootBlockModel } from '@blocksuite/affine-model';
import {
autoScroll,
getScrollContainer,
matchFlavours,
matchModels,
} from '@blocksuite/affine-shared/utils';
import {
BLOCK_ID_ATTR,
@@ -445,7 +445,7 @@ function isDragArea(e: PointerEventState) {
const el = e.raw.target;
assertInstanceOf(el, Element);
const block = el.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
return block && matchFlavours(block.model, [RootBlockModel, NoteBlockModel]);
return block && matchModels(block.model, [RootBlockModel, NoteBlockModel]);
}
declare global {

View File

@@ -2,6 +2,7 @@ import type { CanvasRenderer } from '@blocksuite/affine-block-surface';
import type { SurfaceRefBlockComponent } from '@blocksuite/affine-block-surface-ref';
import { isTopLevelBlock } from '@blocksuite/affine-shared/utils';
import type { EditorHost } from '@blocksuite/block-std';
import type { GfxModel } from '@blocksuite/block-std/gfx';
import { assertExists, Bound } from '@blocksuite/global/utils';
import { ExportManager } from '../../../_common/export-manager/export-manager.js';
@@ -11,7 +12,7 @@ export const edgelessToBlob = async (
options: {
surfaceRefBlock: SurfaceRefBlockComponent;
surfaceRenderer: CanvasRenderer;
edgelessElement: BlockSuite.EdgelessModel;
edgelessElement: GfxModel;
}
): Promise<Blob> => {
const { edgelessElement } = options;