refactor(editor): remove re-exports (#9406)

This commit is contained in:
Saul-Mirone
2024-12-28 06:51:41 +00:00
parent 1deed602c8
commit dc92d78895
28 changed files with 62 additions and 90 deletions
@@ -21,6 +21,7 @@ import {
type ExtensionType,
StdIdentifier,
} from '@blocksuite/block-std';
import type { GfxBlockElementModel } 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';
@@ -30,14 +31,13 @@ import {
getBlockComponentByModel,
getRootByEditorHost,
} from '../../_common/utils/index.js';
import type { GfxBlockModel } from '../../root-block/edgeless/block-model.js';
import type { EdgelessRootBlockComponent } from '../../root-block/edgeless/edgeless-root-block.js';
import { getBlocksInFrameBound } from '../../root-block/edgeless/frame-manager.js';
import { xywhArrayToObject } from '../../root-block/edgeless/utils/convert.js';
import { getBackgroundGrid } from '../../root-block/edgeless/utils/query.js';
import { FileExporter } from './file-exporter.js';
// eslint-disable-next-line
// oxlint-disable-next-line typescript/consistent-type-imports
type Html2CanvasFunction = typeof import('html2canvas').default;
export type ExportOptions = {
@@ -408,7 +408,7 @@ export class ExportManager {
surfaceRenderer: CanvasRenderer,
bound: IBound,
edgeless?: EdgelessRootBlockComponent,
nodes?: GfxBlockModel[],
nodes?: GfxBlockElementModel[],
surfaces?: BlockSuite.SurfaceElementModel[],
edgelessBackground?: {
zoom: number;
-3
View File
@@ -23,6 +23,3 @@ export type Connectable = Exclude<
BlockSuite.EdgelessModel,
ConnectorElementModel | BrushElementModel | GroupElementModel
>;
export type { EmbedCardStyle } from '@blocksuite/affine-model';
export * from '@blocksuite/affine-shared/types';
@@ -1,16 +1,2 @@
// Compat with SSR
export * from '../types.js';
export * from './query.js';
export {
createButtonPopper,
getBlockProps,
getImageFilesFromLocal,
isMiddleButtonPressed,
isRightButtonPressed,
isValidUrl,
matchFlavours,
on,
once,
openFileOrFiles,
requestThrottledConnectedFrame,
} from '@blocksuite/affine-shared/utils';
@@ -1,119 +0,0 @@
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
import type { FrameBlockModel, NoteBlockModel } from '@blocksuite/affine-model';
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 { type BlockModel, type Doc } from '@blocksuite/store';
import { GfxBlockModel } from '../../root-block/edgeless/block-model.js';
import {
getElementProps,
mapFrameIds,
sortEdgelessElements,
} from '../../root-block/edgeless/utils/clone-utils.js';
import {
isFrameBlock,
isNoteBlock,
} from '../../root-block/edgeless/utils/query.js';
export function addBlocksToDoc(
targetDoc: Doc,
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
);
// Add children to linked doc, parent is the new model
const children = model.children;
if (children.length > 0) {
children.forEach(child => {
addBlocksToDoc(targetDoc, child, newModelId);
});
}
}
export function createLinkedDocFromNote(
doc: Doc,
note: NoteBlockModel,
docTitle?: string
) {
const linkedDoc = doc.collection.createDoc({});
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new doc.Text(docTitle),
});
linkedDoc.addBlock('affine:surface', {}, rootId);
const blockProps = getBlockProps(note);
// keep note props & show in both mode
const noteId = linkedDoc.addBlock(
'affine:note',
{
...blockProps,
hidden: false,
displayMode: NoteDisplayMode.DocAndEdgeless,
},
rootId
);
// Add note to linked doc recursively
note.children.forEach(model => {
addBlocksToDoc(linkedDoc, model, noteId);
});
});
return linkedDoc;
}
export function createLinkedDocFromEdgelessElements(
host: EditorHost,
elements: BlockSuite.EdgelessModel[],
docTitle?: string
) {
const linkedDoc = host.doc.collection.createDoc({});
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new host.doc.Text(docTitle),
});
const surfaceId = linkedDoc.addBlock('affine:surface', {}, rootId);
const surface = getSurfaceBlock(linkedDoc);
if (!surface) return;
const sortedElements = sortEdgelessElements(elements);
const ids = new Map<string, string>();
sortedElements.forEach(model => {
let newId = model.id;
if (model instanceof GfxBlockModel) {
const blockProps = getBlockProps(model);
if (isNoteBlock(model)) {
newId = linkedDoc.addBlock('affine:note', blockProps, rootId);
// Add note children to linked doc recursively
model.children.forEach(model => {
addBlocksToDoc(linkedDoc, model, newId);
});
} else {
if (isFrameBlock(model)) {
mapFrameIds(blockProps as unknown as FrameBlockModel, ids);
}
newId = linkedDoc.addBlock(
model.flavour as BlockSuite.Flavour,
blockProps,
surfaceId
);
}
} else {
const props = getElementProps(model, ids);
newId = surface.addElement(props);
}
ids.set(model.id, newId);
});
});
host.std.get(DocModeProvider).setPrimaryMode('edgeless', linkedDoc.id);
return linkedDoc;
}