refactor(editor): merge get surface util (#9371)

This commit is contained in:
Saul-Mirone
2024-12-27 09:42:13 +00:00
parent 6977b0a948
commit 6da10f9a93
15 changed files with 47 additions and 54 deletions
@@ -7,7 +7,6 @@ import type {
EdgelessRootService,
MindmapElementModel,
ShapeElementModel,
SurfaceBlockModel,
} from '@blocksuite/affine/blocks';
import {
addImages,
@@ -17,6 +16,7 @@ import {
EDGELESS_TEXT_BLOCK_MIN_WIDTH,
EdgelessTextBlockModel,
fitContent,
getSurfaceBlock,
ImageBlockModel,
InsertBelowIcon,
LightLoadingIcon,
@@ -363,9 +363,8 @@ function responseToCreateImage(host: EditorHost) {
}
export function responseToExpandMindmap(host: EditorHost, ctx: AIContext) {
const [surface] = host.doc.getBlockByFlavour(
'affine:surface'
) as SurfaceBlockModel[];
const surface = getSurfaceBlock(host.doc);
if (!surface) return;
const elements = ctx.get().selectedElements;
const mindmapNode = ctx.get().node;
@@ -414,9 +413,8 @@ function responseToBrainstormMindmap(host: EditorHost, ctx: AIContext) {
const edgelessService = getEdgelessService(host);
const edgelessCopilot = getEdgelessCopilotWidget(host);
const selectionRect = edgelessCopilot.selectionModelRect;
const [surface] = host.doc.getBlockByFlavour(
'affine:surface'
) as SurfaceBlockModel[];
const surface = getSurfaceBlock(host.doc);
if (!surface) return;
const { node, style, selectedElements } = ctx.get();
if (!node) return;
@@ -478,9 +476,8 @@ function responseToMakeItReal(host: EditorHost, ctx: AIContext) {
html = preprocessHtml(html);
const edgelessCopilot = getEdgelessCopilotWidget(host);
const [surface] = host.doc.getBlockByFlavour(
'affine:surface'
) as SurfaceBlockModel[];
const surface = getSurfaceBlock(host.doc);
if (!surface) return;
const data = ctx.get();
const bounds = edgelessCopilot.determineInsertionBounds(