refactor(editor): remove global types in edgeless (#10092)

Closes: [BS-2553](https://linear.app/affine-design/issue/BS-2553/remove-global-types-in-edgeless)
This commit is contained in:
Saul-Mirone
2025-02-11 12:09:44 +00:00
parent 3062bd0771
commit dbf0f9dc20
45 changed files with 126 additions and 329 deletions
@@ -1,3 +1,4 @@
import type { SurfaceElementModelMap } from '@blocksuite/affine-model';
import { EditPropsStore } from '@blocksuite/affine-shared/services';
import { type BlockStdScope, StdIdentifier } from '@blocksuite/block-std';
import {
@@ -62,13 +63,13 @@ export class EdgelessCRUDExtension extends Extension {
};
addBlock = (
flavour: BlockSuite.EdgelessModelKeys | string,
flavour: string,
props: Record<string, unknown>,
parentId?: string | BlockModel,
parentIndex?: number
) => {
const gfx = this.std.get(GfxControllerIdentifier);
const key = getLastPropsKey(flavour as BlockSuite.EdgelessModelKeys, props);
const key = getLastPropsKey(flavour, props);
if (key) {
props = this.std.get(EditPropsStore).applyLastProps(key, props);
}
@@ -94,7 +95,7 @@ export class EdgelessCRUDExtension extends Extension {
}
const gfx = this.std.get(GfxControllerIdentifier);
const key = getLastPropsKey(type as BlockSuite.EdgelessModelKeys, props);
const key = getLastPropsKey(type, props);
if (key) {
props = this.std.get(EditPropsStore).applyLastProps(key, props) as T;
}
@@ -117,10 +118,10 @@ export class EdgelessCRUDExtension extends Extension {
const element = this._surface.getElementById(id);
if (element) {
const key = getLastPropsKey(
element.type as BlockSuite.EdgelessModelKeys,
{ ...element.yMap.toJSON(), ...props }
);
const key = getLastPropsKey(element.type, {
...element.yMap.toJSON(),
...props,
});
key && this.std.get(EditPropsStore).recordLastProps(key, props);
this._surface.updateElement(id, props);
return;
@@ -128,10 +129,10 @@ export class EdgelessCRUDExtension extends Extension {
const block = this.std.store.getBlockById(id);
if (block) {
const key = getLastPropsKey(
block.flavour as BlockSuite.EdgelessModelKeys,
{ ...block.yBlock.toJSON(), ...props }
);
const key = getLastPropsKey(block.flavour, {
...block.yBlock.toJSON(),
...props,
});
key && this.std.get(EditPropsStore).recordLastProps(key, props);
this.std.store.updateBlock(block, props);
}
@@ -142,17 +143,13 @@ export class EdgelessCRUDExtension extends Extension {
if (!surface) {
return null;
}
const el =
surface.getElementById(id) ??
(this.std.store.getBlockById(
id
) as BlockSuite.EdgelessBlockModelType | null);
return el;
const el = surface.getElementById(id) ?? this.std.store.getBlockById(id);
return el as GfxModel | null;
}
getElementsByType<K extends keyof BlockSuite.SurfaceElementModelMap>(
getElementsByType<K extends keyof SurfaceElementModelMap>(
type: K
): BlockSuite.SurfaceElementModelMap[K][] {
): SurfaceElementModelMap[K][] {
if (!this._surface) {
return [];
}
@@ -7,7 +7,11 @@ import {
type LocalConnectorElementModel,
} from '@blocksuite/affine-model';
import { ThemeProvider } from '@blocksuite/affine-shared/services';
import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx';
import type {
GfxController,
GfxLocalElementModel,
GfxModel,
} from '@blocksuite/block-std/gfx';
import type { IBound, IVec, IVec3 } from '@blocksuite/global/utils';
import {
almostEqual,
@@ -70,9 +74,7 @@ export const ConnectorEndpointLocationsOnTriangle: IVec[] = [
[0.25, 0.5],
];
export function isConnectorWithLabel(
model: GfxModel | BlockSuite.SurfaceLocalModel
) {
export function isConnectorWithLabel(model: GfxModel | GfxLocalElementModel) {
return model instanceof ConnectorElementModel && model.hasLabel();
}
@@ -1,6 +1,7 @@
import type { GfxPrimitiveElementModel } from '@blocksuite/block-std/gfx';
import type { IBound } from '@blocksuite/global/utils';
import type { RoughCanvas, SurfaceElementModel } from '../../index.js';
import type { RoughCanvas } from '../../index.js';
import type { CanvasRenderer } from '../canvas-renderer.js';
import { brush } from './brush/index.js';
import { connector } from './connector/index.js';
@@ -11,7 +12,7 @@ import { text } from './text/index.js';
export { normalizeShapeBound } from './shape/utils.js';
export type ElementRenderer<
T extends BlockSuite.SurfaceElementModel = SurfaceElementModel,
T extends GfxPrimitiveElementModel = GfxPrimitiveElementModel,
> = (
model: T,
ctx: CanvasRenderingContext2D,
@@ -1,4 +1,7 @@
import type { ConnectorElementModel } from '@blocksuite/affine-model';
import type {
ConnectorElementModel,
SurfaceElementModelMap,
} from '@blocksuite/affine-model';
import type { SurfaceBlockProps } from '@blocksuite/block-std/gfx';
import { SurfaceBlockModel as BaseSurfaceModel } from '@blocksuite/block-std/gfx';
import { DisposableGroup } from '@blocksuite/global/utils';
@@ -55,11 +58,9 @@ export class SurfaceBlockModel extends BaseSurfaceModel {
);
}
override getElementsByType<K extends keyof BlockSuite.SurfaceElementModelMap>(
override getElementsByType<K extends keyof SurfaceElementModelMap>(
type: K
): BlockSuite.SurfaceElementModelMap[K][] {
return super.getElementsByType(
type
) as BlockSuite.SurfaceElementModelMap[K][];
): SurfaceElementModelMap[K][] {
return super.getElementsByType(type) as SurfaceElementModelMap[K][];
}
}
@@ -10,7 +10,10 @@ import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
import { handleNativeRangeAtPoint } from '@blocksuite/affine-shared/utils';
import type { BlockStdScope } from '@blocksuite/block-std';
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
import {
type GfxBlockElementModel,
GfxControllerIdentifier,
} from '@blocksuite/block-std/gfx';
import {
type IPoint,
type Point,
@@ -117,7 +120,7 @@ export function addNote(
const blocks =
(doc.root?.children.filter(
child => child.flavour === 'affine:note'
) as BlockSuite.EdgelessBlockModelType[]) ?? [];
) as GfxBlockElementModel[]) ?? [];
const element = blocks.find(b => b.id === noteId);
if (element) {
gfx.selection.set({
@@ -8,7 +8,7 @@ import { NodePropsSchema } from '@blocksuite/affine-shared/utils';
const LastPropsSchema = NodePropsSchema;
export function getLastPropsKey(
modelType: BlockSuite.EdgelessModelKeys,
modelType: string,
modelProps: Partial<LastProps[LastPropsKey]>
): LastPropsKey | null {
if (modelType === 'shape') {
@@ -88,11 +88,3 @@ export const AttachmentBlockSchema = defineBlockSchema({
export class AttachmentBlockModel
extends GfxCompatible<AttachmentBlockProps>(BlockModel)
implements GfxElementGeometry {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:attachment': AttachmentBlockModel;
}
}
}
@@ -57,11 +57,3 @@ export const BookmarkBlockSchema = defineBlockSchema({
export class BookmarkBlockModel
extends GfxCompatible<BookmarkBlockProps>(BlockModel)
implements GfxElementGeometry {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:bookmark': BookmarkBlockModel;
}
}
}
@@ -79,15 +79,3 @@ export const EdgelessTextBlockSchema = defineBlockSchema({
export class EdgelessTextBlockModel
extends GfxCompatible<EdgelessTextProps>(BlockModel)
implements GfxElementGeometry {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:edgeless-text': EdgelessTextBlockModel;
}
interface EdgelessTextModelMap {
'edgeless-text': EdgelessTextBlockModel;
}
}
}
@@ -19,11 +19,3 @@ export type EmbedFigmaBlockProps = {
export class EmbedFigmaModel extends defineEmbedModel<EmbedFigmaBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-figma': EmbedFigmaModel;
}
}
}
@@ -33,11 +33,3 @@ export type EmbedGithubBlockProps = {
export class EmbedGithubModel extends defineEmbedModel<EmbedGithubBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-github': EmbedGithubModel;
}
}
}
@@ -15,11 +15,3 @@ export type EmbedHtmlBlockProps = {
export class EmbedHtmlModel extends defineEmbedModel<EmbedHtmlBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-html': EmbedHtmlModel;
}
}
}
@@ -20,11 +20,3 @@ export type EmbedLinkedDocBlockProps = {
export class EmbedLinkedDocModel extends defineEmbedModel<EmbedLinkedDocBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-linked-doc': EmbedLinkedDocModel;
}
}
}
@@ -21,11 +21,3 @@ export type EmbedLoomBlockProps = {
export class EmbedLoomModel extends defineEmbedModel<EmbedLoomBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-loom': EmbedLoomModel;
}
}
}
@@ -15,11 +15,3 @@ export type EmbedSyncedDocBlockProps = {
export class EmbedSyncedDocModel extends defineEmbedModel<EmbedSyncedDocBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-synced-doc': EmbedSyncedDocModel;
}
}
}
@@ -24,11 +24,3 @@ export type EmbedYoutubeBlockProps = {
export class EmbedYoutubeModel extends defineEmbedModel<EmbedYoutubeBlockProps>(
BlockModel
) {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-youtube': EmbedYoutubeModel;
}
}
}
@@ -144,11 +144,3 @@ export class FrameBlockModel
});
}
}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:frame': FrameBlockModel;
}
}
}
@@ -42,11 +42,3 @@ export const ImageBlockSchema = defineBlockSchema({
export class ImageBlockModel
extends GfxCompatible<ImageBlockProps>(BlockModel)
implements GfxElementGeometry {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:image': ImageBlockModel;
}
}
}
@@ -37,11 +37,3 @@ export const LatexBlockSchema = defineBlockSchema({
export class LatexBlockModel
extends GfxCompatible<LatexProps>(BlockModel)
implements GfxElementGeometry {}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:latex': LatexBlockModel;
}
}
}
@@ -155,11 +155,3 @@ export class NoteBlockModel
return false;
}
}
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:note': NoteBlockModel;
}
}
}
@@ -224,11 +224,3 @@ export class BrushElementModel extends GfxPrimitiveElementModel<BrushProps> {
}
type Instance = GfxPrimitiveElementModel<BrushProps> & BrushProps;
declare global {
namespace BlockSuite {
interface SurfaceElementModelMap {
brush: BrushElementModel;
}
}
}
@@ -508,14 +508,3 @@ export class ConnectorElementModel extends GfxPrimitiveElementModel<ConnectorEle
@local()
accessor xywh: SerializedXYWH = '[0,0,0,0]';
}
declare global {
namespace BlockSuite {
interface SurfaceElementModelMap {
connector: ConnectorElementModel;
}
interface EdgelessTextModelMap {
connector: ConnectorElementModel;
}
}
}
@@ -56,11 +56,3 @@ export class LocalConnectorElementModel extends GfxLocalElementModel {
return 'connector';
}
}
declare global {
namespace BlockSuite {
interface SurfaceLocalModelMap {
connector: LocalConnectorElementModel;
}
}
}
@@ -119,15 +119,3 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
@field()
accessor title: Y.Text = new Y.Text();
}
declare global {
namespace BlockSuite {
interface SurfaceGroupLikeModelMap {
group: GroupElementModel;
}
interface SurfaceElementModelMap {
group: GroupElementModel;
}
}
}
@@ -1,6 +1,32 @@
import type { EdgelessTextBlockModel } from '../blocks/edgeless-text/edgeless-text-model.js';
import type { BrushElementModel } from './brush/index.js';
import type { ConnectorElementModel } from './connector/index.js';
import type { GroupElementModel } from './group/index.js';
import type { MindmapElementModel } from './mindmap/index.js';
import type { ShapeElementModel } from './shape/index.js';
import type { TextElementModel } from './text/index.js';
export * from './brush/index.js';
export * from './connector/index.js';
export * from './group/index.js';
export * from './mindmap/index.js';
export * from './shape/index.js';
export * from './text/index.js';
export type SurfaceElementModelMap = {
brush: BrushElementModel;
connector: ConnectorElementModel;
group: GroupElementModel;
mindmap: MindmapElementModel;
shape: ShapeElementModel;
text: TextElementModel;
};
export type SurfaceTextModelMap = {
text: TextElementModel;
connector: ConnectorElementModel;
shape: ShapeElementModel;
'edgeless-text': EdgelessTextBlockModel;
};
export type SurfaceTextModel = SurfaceTextModelMap[keyof SurfaceTextModelMap];
@@ -1,6 +1,7 @@
import type {
BaseElementProps,
GfxModel,
GfxPrimitiveElementModel,
PointTestOptions,
SerializedElement,
} from '@blocksuite/block-std/gfx';
@@ -44,7 +45,7 @@ export type MindmapNode = {
id: string;
detail: NodeDetail;
element: BlockSuite.SurfaceElementModel;
element: GfxPrimitiveElementModel;
children: MindmapNode[];
parent: MindmapNode | null;
@@ -836,7 +837,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
return;
}
const stashed = new Set<BlockSuite.SurfaceElementModel>();
const stashed = new Set<GfxPrimitiveElementModel>();
const traverse = (node: MindmapNode) => {
node.element.stash('xywh');
stashed.add(node.element);
@@ -975,11 +976,3 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
@field()
accessor style: MindmapStyle = MindmapStyle.ONE;
}
declare global {
namespace BlockSuite {
interface SurfaceGroupLikeModelMap {
mindmap: MindmapElementModel;
}
}
}
@@ -261,15 +261,3 @@ export class LocalShapeElementModel extends GfxLocalElementModel {
@prop()
accessor textVerticalAlign: TextVerticalAlign = TextVerticalAlign.Center;
}
declare global {
namespace BlockSuite {
interface SurfaceElementModelMap {
shape: ShapeElementModel;
}
interface EdgelessTextModelMap {
shape: ShapeElementModel;
}
}
}
@@ -90,15 +90,3 @@ export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps>
@field()
accessor xywh: SerializedXYWH = '[0,0,16,16]';
}
declare global {
namespace BlockSuite {
interface SurfaceElementModelMap {
text: TextElementModel;
}
interface EdgelessTextModelMap {
text: TextElementModel;
}
}
}
@@ -1,46 +0,0 @@
import type {
GfxBlockElementModel,
GfxGroupLikeElementModel,
GfxLocalElementModel,
GfxPrimitiveElementModel,
} from '@blocksuite/block-std/gfx';
declare global {
namespace BlockSuite {
interface EdgelessBlockModelMap {}
type EdgelessBlockModelKeyType = keyof EdgelessBlockModelMap;
type EdgelessBlockModelType =
| EdgelessBlockModelMap[EdgelessBlockModelKeyType]
| GfxBlockElementModel;
interface EdgelessTextModelMap {}
type EdgelessTextModelKeyType = keyof EdgelessTextModelMap;
type EdgelessTextModelType = EdgelessTextModelMap[EdgelessTextModelKeyType];
interface SurfaceElementModelMap {}
type SurfaceElementModelKeys = keyof SurfaceElementModelMap;
type SurfaceElementModel =
| SurfaceElementModelMap[SurfaceElementModelKeys]
| GfxPrimitiveElementModel;
interface SurfaceGroupLikeModelMap {}
type SurfaceGroupLikeModelKeys = keyof SurfaceGroupLikeModelMap;
type SurfaceGroupLikeModel =
| SurfaceGroupLikeModelMap[SurfaceGroupLikeModelKeys]
| GfxGroupLikeElementModel;
interface SurfaceLocalModelMap {}
type SurfaceLocalModelKeys = keyof SurfaceLocalModelMap;
type SurfaceLocalModel =
| SurfaceLocalModelMap[SurfaceLocalModelKeys]
| GfxLocalElementModel;
// not include local model
type SurfaceModel = SurfaceElementModel | SurfaceGroupLikeModel;
type SurfaceModelKeyType =
| SurfaceElementModelKeys
| SurfaceGroupLikeModelKeys;
type EdgelessModelKeys = EdgelessBlockModelKeyType | SurfaceModelKeyType;
}
}
@@ -1,4 +1,3 @@
export * from './enum.js';
export * from './global.js';
export * from './helper.js';
export * from './types.js';
@@ -22,7 +22,10 @@ import {
type EditorHost,
StdIdentifier,
} from '@blocksuite/block-std';
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
import type {
GfxBlockElementModel,
GfxPrimitiveElementModel,
} from '@blocksuite/block-std/gfx';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { IBound } from '@blocksuite/global/utils';
import { Bound } from '@blocksuite/global/utils';
@@ -410,7 +413,7 @@ export class ExportManager {
bound: IBound,
edgeless?: EdgelessRootBlockComponent,
nodes?: GfxBlockElementModel[],
surfaces?: BlockSuite.SurfaceElementModel[],
surfaces?: GfxPrimitiveElementModel[],
edgelessBackground?: {
zoom: number;
}
@@ -6,7 +6,7 @@ import {
SurfaceGroupLikeModel,
TextUtils,
} from '@blocksuite/affine-block-surface';
import type { Connection } from '@blocksuite/affine-model';
import type { Connection, ShapeElementModel } from '@blocksuite/affine-model';
import {
BookmarkStyles,
DEFAULT_NOTE_HEIGHT,
@@ -40,8 +40,10 @@ import type {
} from '@blocksuite/block-std';
import {
compareLayer,
type GfxBlockElementModel,
type GfxCompatibleProps,
type GfxModel,
type GfxPrimitiveElementModel,
type SerializedElement,
SortOrder,
} from '@blocksuite/block-std/gfx';
@@ -313,7 +315,7 @@ export class EdgelessClipboardController extends PageClipboard {
.get(EmbedOptionProvider)
.getEmbedBlockOptions(url);
if (embedOptions) {
flavour = embedOptions.flavour as BlockSuite.EdgelessModelKeys;
flavour = embedOptions.flavour;
style = embedOptions.styles[0];
}
}
@@ -605,7 +607,7 @@ export class EdgelessClipboardController extends PageClipboard {
segment: 'toolbar',
type: clipboardData.type as string,
});
const element = this.crud.getElementById(id) as BlockSuite.SurfaceModel;
const element = this.crud.getElementById(id) as GfxPrimitiveElementModel;
assertExists(element);
return element;
}
@@ -882,8 +884,8 @@ export class EdgelessClipboardController extends PageClipboard {
private async _edgelessToCanvas(
edgeless: EdgelessRootBlockComponent,
bound: IBound,
nodes?: BlockSuite.EdgelessBlockModelType[],
canvasElements: BlockSuite.SurfaceModel[] = [],
nodes?: GfxBlockElementModel[],
canvasElements: GfxPrimitiveElementModel[] = [],
{
background,
padding = IMAGE_PADDING,
@@ -961,7 +963,7 @@ export class EdgelessClipboardController extends PageClipboard {
};
const _drawTopLevelBlock = async (
block: BlockSuite.EdgelessBlockModelType,
block: GfxBlockElementModel,
isInFrame = false
) => {
const blockComponent = this.std.view.getBlock(block.id);
@@ -992,19 +994,19 @@ export class EdgelessClipboardController extends PageClipboard {
nodes ??
(edgeless.service.gfx.getElementsByBound(bound, {
type: 'block',
}) as BlockSuite.EdgelessBlockModelType[]);
}) as GfxBlockElementModel[]);
for (const nodeElement of nodeElements) {
await _drawTopLevelBlock(nodeElement);
if (matchModels(nodeElement, [FrameBlockModel])) {
const blocksInsideFrame: BlockSuite.EdgelessBlockModelType[] = [];
const blocksInsideFrame: GfxBlockElementModel[] = [];
this.edgeless.service.frame
.getElementsInFrameBound(nodeElement, false)
.forEach(ele => {
if (isTopLevelBlock(ele)) {
blocksInsideFrame.push(ele as BlockSuite.EdgelessBlockModelType);
blocksInsideFrame.push(ele as GfxBlockElementModel);
} else {
canvasElements.push(ele as BlockSuite.SurfaceModel);
canvasElements.push(ele as GfxPrimitiveElementModel);
}
});
@@ -1245,8 +1247,8 @@ export class EdgelessClipboardController extends PageClipboard {
),
};
const blockModels: BlockSuite.EdgelessBlockModelType[] = [];
const canvasElements: BlockSuite.SurfaceModel[] = [];
const blockModels: GfxBlockElementModel[] = [];
const canvasElements: GfxPrimitiveElementModel[] = [];
const allElements: GfxModel[] = [];
for (const data of elementsRawData) {
@@ -1283,7 +1285,7 @@ export class EdgelessClipboardController extends PageClipboard {
const block = this.doc.getBlock(newId);
if (!block) continue;
assertType<BlockSuite.EdgelessBlockModelType>(block.model);
assertType<GfxBlockElementModel>(block.model);
blockModels.push(block.model);
allElements.push(block.model);
context.oldToNewIdMap.set(oldId, newId);
@@ -1343,8 +1345,8 @@ export class EdgelessClipboardController extends PageClipboard {
}
async toCanvas(
blocks: BlockSuite.EdgelessBlockModelType[],
shapes: BlockSuite.SurfaceModel[],
blocks: GfxBlockElementModel[],
shapes: ShapeElementModel[],
options?: CanvasExportOptions
) {
blocks.sort(compareLayer);
@@ -43,6 +43,7 @@ import {
GfxControllerIdentifier,
GfxExtensionIdentifier,
type GfxModel,
type GfxPrimitiveElementModel,
} from '@blocksuite/block-std/gfx';
import type {
Disposable,
@@ -891,7 +892,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
areAllConnectors = false;
areAllShapes = false;
} else {
assertType<BlockSuite.SurfaceElementModel>(element);
assertType<GfxPrimitiveElementModel>(element);
if (element.type === CanvasElementType.CONNECTOR) {
const connector = element as ConnectorElementModel;
areAllIndependentConnectors &&= !(
@@ -23,6 +23,7 @@ import { matchModels } from '@blocksuite/affine-shared/utils';
import { SurfaceSelection, TextSelection } from '@blocksuite/block-std';
import {
GfxBlockElementModel,
type GfxPrimitiveElementModel,
type GfxToolsMap,
type GfxToolsOption,
isGfxGroupCompatibleModel,
@@ -573,7 +574,7 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
const node = mindmapNodes[0];
const mindmap = node.group as MindmapElementModel;
const nodeDirection = mindmap.getLayoutDir(node.id);
let targetNode: BlockSuite.SurfaceElementModel | null = null;
let targetNode: GfxPrimitiveElementModel | null = null;
switch (key) {
case 'ArrowUp':
@@ -491,11 +491,7 @@ export function getBlocksInFrameBound(
if (!surface) return [];
return (
getNotesInFrameBound(
doc,
model,
fullyContained
) as BlockSuite.EdgelessBlockModelType[]
getNotesInFrameBound(doc, model, fullyContained) as GfxBlockElementModel[]
).concat(
surface.children.filter(ele => {
if (ele.id === model.id) return false;
@@ -507,6 +503,6 @@ export function getBlocksInFrameBound(
}
return false;
}) as BlockSuite.EdgelessBlockModelType[]
}) as GfxBlockElementModel[]
);
}
@@ -14,6 +14,7 @@ import {
import type { PointerEventState } from '@blocksuite/block-std';
import {
type GfxModel,
type GfxPrimitiveElementModel,
isGfxGroupCompatibleModel,
} from '@blocksuite/block-std/gfx';
import type { Bound, IVec } from '@blocksuite/global/utils';
@@ -352,7 +353,7 @@ export class MindMapExt extends DefaultToolExt {
) {
const OPACITY = 0.3;
const updatedNodes = new Set<
BlockSuite.SurfaceElementModel | LocalConnectorElementModel
GfxPrimitiveElementModel | LocalConnectorElementModel
>();
const traverse = (node: MindmapNode, parent: MindmapNode | null) => {
node.element.opacity = OPACITY;
@@ -11,7 +11,7 @@ export class EditPropsMiddlewareBuilder extends SurfaceMiddlewareBuilder {
middleware: SurfaceMiddleware = ctx => {
if (ctx.type === 'beforeAdd') {
const { type, props } = ctx.payload;
const key = getLastPropsKey(type as BlockSuite.EdgelessModelKeys, props);
const key = getLastPropsKey(type, props);
const nProps = key
? this.std.get(EditPropsStore).applyLastProps(key, ctx.payload.props)
: null;
@@ -6,6 +6,7 @@ import type {
FrameBlockProps,
ImageBlockModel,
NoteBlockModel,
ShapeElementModel,
} from '@blocksuite/affine-model';
import { getElementsWithoutGroup } from '@blocksuite/affine-shared/utils';
import {
@@ -72,7 +73,7 @@ export const splitElements = (elements: GfxModel[]) => {
return 'shapes';
}) as {
notes: NoteBlockModel[];
shapes: BlockSuite.SurfaceModel[];
shapes: ShapeElementModel[];
frames: FrameBlockModel[];
images: ImageBlockModel[];
edgelessTexts: EdgelessTextBlockModel[];
@@ -15,6 +15,7 @@ import {
getTopElements,
GfxBlockElementModel,
type GfxModel,
type GfxPrimitiveElementModel,
isGfxGroupCompatibleModel,
type SerializedElement,
} from '@blocksuite/block-std/gfx';
@@ -225,7 +226,7 @@ export function mapMindmapIds(
}
export function getElementProps(
element: BlockSuite.SurfaceModel,
element: GfxPrimitiveElementModel,
ids: Map<string, string>
) {
if (element instanceof ConnectorElementModel) {
@@ -29,6 +29,8 @@ import {
FontWeight,
resolveColor,
ShapeElementModel,
type SurfaceTextModel,
type SurfaceTextModelMap,
TextAlign,
TextElementModel,
type TextStyleProps,
@@ -76,14 +78,14 @@ const TEXT_ALIGN_CHOOSE: [TextAlign, () => TemplateResult<1>][] = [
] as const;
function countByField<K extends keyof Omit<TextStyleProps, 'color'>>(
elements: BlockSuite.EdgelessTextModelType[],
elements: SurfaceTextModel[],
field: K
) {
return countBy(elements, element => extractField(element, field));
}
function extractField<K extends keyof Omit<TextStyleProps, 'color'>>(
element: BlockSuite.EdgelessTextModelType,
element: SurfaceTextModel,
field: K
) {
//TODO: It's not a very good handling method.
@@ -101,23 +103,23 @@ function extractField<K extends keyof Omit<TextStyleProps, 'color'>>(
}
function getMostCommonValue<K extends keyof Omit<TextStyleProps, 'color'>>(
elements: BlockSuite.EdgelessTextModelType[],
elements: SurfaceTextModel[],
field: K
) {
const values = countByField(elements, field);
return maxBy(Object.entries(values), ([_k, count]) => count);
}
function getMostCommonAlign(elements: BlockSuite.EdgelessTextModelType[]) {
function getMostCommonAlign(elements: SurfaceTextModel[]) {
const max = getMostCommonValue(elements, 'textAlign');
return max ? (max[0] as TextAlign) : TextAlign.Left;
}
function getMostCommonColor(
elements: BlockSuite.EdgelessTextModelType[],
elements: SurfaceTextModel[],
colorScheme: ColorScheme
): string {
const colors = countBy(elements, (ele: BlockSuite.EdgelessTextModelType) => {
const colors = countBy(elements, (ele: SurfaceTextModel) => {
const color =
ele instanceof ConnectorElementModel ? ele.labelStyle.color : ele.color;
return resolveColor(color, colorScheme);
@@ -128,28 +130,28 @@ function getMostCommonColor(
: resolveColor(DefaultTheme.textColor, colorScheme);
}
function getMostCommonFontFamily(elements: BlockSuite.EdgelessTextModelType[]) {
function getMostCommonFontFamily(elements: SurfaceTextModel[]) {
const max = getMostCommonValue(elements, 'fontFamily');
return max ? (max[0] as FontFamily) : FontFamily.Inter;
}
function getMostCommonFontSize(elements: BlockSuite.EdgelessTextModelType[]) {
function getMostCommonFontSize(elements: SurfaceTextModel[]) {
const max = getMostCommonValue(elements, 'fontSize');
return max ? Number(max[0]) : FONT_SIZE_LIST[0].value;
}
function getMostCommonFontStyle(elements: BlockSuite.EdgelessTextModelType[]) {
function getMostCommonFontStyle(elements: SurfaceTextModel[]) {
const max = getMostCommonValue(elements, 'fontStyle');
return max ? (max[0] as FontStyle) : FontStyle.Normal;
}
function getMostCommonFontWeight(elements: BlockSuite.EdgelessTextModelType[]) {
function getMostCommonFontWeight(elements: SurfaceTextModel[]) {
const max = getMostCommonValue(elements, 'fontWeight');
return max ? (max[0] as FontWeight) : FontWeight.Regular;
}
function buildProps(
element: BlockSuite.EdgelessTextModelType,
element: SurfaceTextModel,
props: { [K in keyof TextStyleProps]?: TextStyleProps[K] }
) {
if (element instanceof ConnectorElementModel) {
@@ -236,9 +238,7 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) {
});
};
private readonly _updateElementBound = (
element: BlockSuite.EdgelessTextModelType
) => {
private readonly _updateElementBound = (element: SurfaceTextModel) => {
const elementType = this.elementType;
if (elementType === 'text' && element instanceof TextElementModel) {
// the change of font family will change the bound of the text
@@ -506,10 +506,10 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) {
accessor edgeless!: EdgelessRootBlockComponent;
@property({ attribute: false })
accessor elements!: BlockSuite.EdgelessTextModelType[];
accessor elements!: SurfaceTextModel[];
@property({ attribute: false })
accessor elementType!: BlockSuite.EdgelessTextModelKeyType;
accessor elementType!: keyof SurfaceTextModelMap;
@query('edgeless-color-picker-button.text-color')
accessor textColorButton!: EdgelessColorPickerButton;
@@ -178,7 +178,7 @@ export class EdgelessElementToolbarWidget extends WidgetComponent<
return 'edgelessText';
}
return (model as BlockSuite.SurfaceElementModel).type;
return model.type;
});
return result as CategorizedElements;
}
@@ -4,6 +4,7 @@ import type {
EdgelessRootBlockComponent,
GroupElementModel,
NoteBlockModel,
SurfaceElementModel,
} from '@blocksuite/blocks';
import type { BlockModel, Store } from '@blocksuite/store';
import { beforeEach, describe, expect, test } from 'vitest';
@@ -852,7 +853,7 @@ test('the actual rendering z-index should satisfy the logic order of their index
});
describe('index generator', () => {
let preinsertedShape: BlockSuite.SurfaceElementModel;
let preinsertedShape: SurfaceElementModel;
let preinsertedNote: NoteBlockModel;
beforeEach(() => {
@@ -863,7 +864,7 @@ describe('index generator', () => {
preinsertedShape = service.crud.getElementById(
shapeId
)! as BlockSuite.SurfaceElementModel;
)! as SurfaceElementModel;
preinsertedNote = service.crud.getElementById(noteId)! as NoteBlockModel;
});
@@ -34,12 +34,3 @@ export const AIChatBlockSchema = defineBlockSchema({
});
export class AIChatBlockModel extends GfxCompatible<AIChatProps>(BlockModel) {}
declare global {
// oxlint-disable-next-line @typescript-eslint/no-namespace
namespace BlockSuite {
interface EdgelessBlockModelMap {
'affine:embed-ai-chat': AIChatBlockModel;
}
}
}
@@ -1,5 +1,6 @@
import type { getCopilotHistoriesQuery, RequestOptions } from '@affine/graphql';
import type { EditorHost } from '@blocksuite/affine/block-std';
import type { GfxModel } from '@blocksuite/affine/block-std/gfx';
import type { BlockModel } from '@blocksuite/affine/store';
import type { DocContext } from '../chat-panel/chat-context';
@@ -72,7 +73,7 @@ declare global {
// internal context
host: EditorHost;
models?: (BlockModel | BlockSuite.SurfaceElementModel)[];
models?: (BlockModel | GfxModel)[];
control: TrackerControl;
where: TrackerWhere;
}
@@ -1,10 +1,11 @@
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
import { mixpanel, track } from '@affine/track';
import type { EditorHost } from '@blocksuite/affine/block-std';
import type { GfxPrimitiveElementModel } from '@blocksuite/affine/block-std/gfx';
import type { BlockModel } from '@blocksuite/affine/store';
import { lowerCase, omit } from 'lodash-es';
type ElementModel = BlockSuite.SurfaceElementModel;
type ElementModel = GfxPrimitiveElementModel;
type AIActionEventName =
| 'AI action invoked'