mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(editor): extract root block (#10356)
Closes: [BS-2207](https://linear.app/affine-design/issue/BS-2207/move-root-block-to-affineblock-root)
This commit is contained in:
@@ -8,11 +8,11 @@ import {
|
||||
import { GfxControllerIdentifier } from '@blocksuite/affine/block-std/gfx';
|
||||
import type { DocMode, ImageSelection } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
BlocksUtils,
|
||||
DocModeProvider,
|
||||
EdgelessCRUDIdentifier,
|
||||
EditPropsStore,
|
||||
getSelectedBlocksCommand,
|
||||
matchModels,
|
||||
NoteDisplayMode,
|
||||
NotificationProvider,
|
||||
ParagraphBlockModel,
|
||||
@@ -34,8 +34,6 @@ import { reportResponse } from '../utils/action-reporter';
|
||||
import { insertBelow, replace } from '../utils/editor-actions';
|
||||
import { BlockIcon, CreateIcon, InsertBelowIcon, ReplaceIcon } from './icons';
|
||||
|
||||
const { matchModels } = BlocksUtils;
|
||||
|
||||
type Selections = {
|
||||
text?: TextSelection;
|
||||
blocks?: BlockSelection[];
|
||||
|
||||
@@ -9,13 +9,14 @@ import type {
|
||||
EdgelessCopilotWidget,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
BlocksUtils,
|
||||
CodeBlockModel,
|
||||
EdgelessTextBlockModel,
|
||||
EmbedSyncedDocModel,
|
||||
ImageBlockModel,
|
||||
matchModels,
|
||||
NoteBlockModel,
|
||||
ShapeElementModel,
|
||||
splitElements,
|
||||
TextElementModel,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||
@@ -431,7 +432,7 @@ export function actionToHandler<T extends keyof BlockSuitePresets.AIActions>(
|
||||
togglePanel = async () => {
|
||||
if (isEmpty) return true;
|
||||
const { notes, shapes, images, edgelessTexts, embedSyncedDocs } =
|
||||
BlocksUtils.splitElements(selectedElements);
|
||||
splitElements(selectedElements);
|
||||
const blocks = [
|
||||
...notes,
|
||||
...shapes,
|
||||
@@ -489,7 +490,7 @@ export function noteWithCodeBlockShowWen(
|
||||
return (
|
||||
selected[0] instanceof NoteBlockModel &&
|
||||
selected[0].children.length === 1 &&
|
||||
BlocksUtils.matchModels(selected[0].children[0], [CodeBlockModel])
|
||||
matchModels(selected[0].children[0], [CodeBlockModel])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
type AIItemGroupConfig,
|
||||
AIStarIconWithAnimation,
|
||||
BlocksUtils,
|
||||
MindmapElementModel,
|
||||
ShapeElementModel,
|
||||
splitElements,
|
||||
TextElementModel,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
|
||||
@@ -293,7 +293,7 @@ const generateGroup: AIItemGroupConfig = {
|
||||
shapes,
|
||||
notes: _,
|
||||
frames: __,
|
||||
} = BlocksUtils.splitElements(selectedElements);
|
||||
} = splitElements(selectedElements);
|
||||
|
||||
const pureShapes = shapes.filter(
|
||||
e =>
|
||||
@@ -412,7 +412,7 @@ const generateGroup: AIItemGroupConfig = {
|
||||
}
|
||||
|
||||
const { notes, frames, shapes, images, edgelessTexts } =
|
||||
BlocksUtils.splitElements(selectedElements);
|
||||
splitElements(selectedElements);
|
||||
const f = frames.length;
|
||||
const i = images.length;
|
||||
const n = notes.length;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
BlocksUtils,
|
||||
DatabaseBlockModel,
|
||||
DocModeProvider,
|
||||
embedSyncedDocMiddleware,
|
||||
@@ -9,6 +8,7 @@ import {
|
||||
ImageBlockModel,
|
||||
isInsideEdgelessEditor,
|
||||
MarkdownAdapter,
|
||||
matchModels,
|
||||
type NoteBlockModel,
|
||||
NoteDisplayMode,
|
||||
titleMiddleware,
|
||||
@@ -163,8 +163,7 @@ export async function extractMarkdownFromDoc(
|
||||
const adapter = new MarkdownAdapter(transformer, provider);
|
||||
const blockModels = getNoteBlockModels(doc);
|
||||
const textModels = blockModels.filter(
|
||||
model =>
|
||||
!BlocksUtils.matchModels(model, [ImageBlockModel, DatabaseBlockModel])
|
||||
model => !matchModels(model, [ImageBlockModel, DatabaseBlockModel])
|
||||
);
|
||||
const drafts = textModels.map(toDraftModel);
|
||||
const slice = Slice.fromModels(doc, drafts);
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
type GfxModel,
|
||||
} from '@blocksuite/affine/block-std/gfx';
|
||||
import {
|
||||
BlocksUtils,
|
||||
type CopilotTool,
|
||||
DatabaseBlockModel,
|
||||
type FrameBlockModel,
|
||||
@@ -14,6 +13,9 @@ import {
|
||||
getSelectedModelsCommand,
|
||||
getTextSelectionCommand,
|
||||
ImageBlockModel,
|
||||
isCanvasElement,
|
||||
matchModels,
|
||||
splitElements,
|
||||
type SurfaceBlockComponent,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
@@ -51,7 +53,7 @@ export async function allToCanvas(host: EditorHost) {
|
||||
export async function elementsToCanvas(host: EditorHost, elements: GfxModel[]) {
|
||||
const edgelessRoot = getEdgelessRootFromEditor(host);
|
||||
const { notes, frames, shapes, images, edgelessTexts, embedSyncedDocs } =
|
||||
BlocksUtils.splitElements(elements);
|
||||
splitElements(elements);
|
||||
|
||||
const blockElements = [
|
||||
...notes,
|
||||
@@ -119,8 +121,7 @@ export async function getTextContentFromBlockModels(
|
||||
) {
|
||||
// Currently only filter out images and databases
|
||||
const selectedTextModels = models.filter(
|
||||
model =>
|
||||
!BlocksUtils.matchModels(model, [ImageBlockModel, DatabaseBlockModel])
|
||||
model => !matchModels(model, [ImageBlockModel, DatabaseBlockModel])
|
||||
);
|
||||
const drafts = selectedTextModels.map(toDraftModel);
|
||||
drafts.forEach(draft => traverse(draft, drafts));
|
||||
@@ -218,7 +219,7 @@ export const getFirstImageInFrame = (
|
||||
false
|
||||
);
|
||||
const image = elements.find(ele => {
|
||||
if (!BlocksUtils.isCanvasElement(ele)) {
|
||||
if (!isCanvasElement(ele)) {
|
||||
return ele.flavour === 'affine:image';
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user