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

View File

@@ -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;

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';

View File

@@ -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';

View File

@@ -1,8 +1,8 @@
/* oxlint-disable @typescript-eslint/triple-slash-reference */
/// <reference path="./effects.ts" />
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import { deserializeXYWH, Point } from '@blocksuite/global/utils';
import { matchFlavours } from './_common/utils/index.js';
import { splitElements } from './root-block/edgeless/utils/clipboard-utils.js';
import { isCanvasElement } from './root-block/edgeless/utils/query.js';

View File

@@ -1 +0,0 @@
export { GfxBlockElementModel as GfxBlockModel } from '@blocksuite/block-std/gfx';

View File

@@ -1,11 +1,10 @@
import type { EmbedCardStyle } from '@blocksuite/affine-model';
import { WithDisposable } from '@blocksuite/global/utils';
import { css, html, LitElement, nothing, type TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { repeat } from 'lit/directives/repeat.js';
import type { EmbedCardStyle } from '../../../../_common/types.js';
export class CardStylePanel extends WithDisposable(LitElement) {
static override styles = css`
:host {

View File

@@ -3,8 +3,8 @@ import {
LassoFreeHandIcon,
LassoPolygonalIcon,
} from '@blocksuite/affine-components/icons';
import { LassoMode } from '@blocksuite/affine-shared/types';
import { LassoMode } from '../../../../../_common/types.js';
import type { DenseMenuBuilder } from '../common/type.js';
export const buildLassoDenseMenu: DenseMenuBuilder = edgeless => {

View File

@@ -3,13 +3,13 @@ import {
LassoFreeHandIcon,
LassoPolygonalIcon,
} from '@blocksuite/affine-components/icons';
import { LassoMode } from '@blocksuite/affine-shared/types';
import { WithDisposable } from '@blocksuite/global/utils';
import { effect } from '@preact/signals-core';
import { css, html, LitElement } from 'lit';
import { query, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { LassoMode } from '../../../../../_common/types.js';
import { getTooltipWithShortcut } from '../../utils.js';
import { QuickToolMixin } from '../mixins/quick-tool.mixin.js';

View File

@@ -13,10 +13,9 @@ import {
QuoteIcon,
TextIcon,
} from '@blocksuite/affine-components/icons';
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
import type { TemplateResult } from 'lit';
import type { NoteChildrenFlavour } from '../../../../../_common/utils/index.js';
export const BUTTON_GROUP_LENGTH = 10;
export type NoteMenuItem = {

View File

@@ -3,17 +3,17 @@ import { addImages, LoadedImageIcon } from '@blocksuite/affine-block-image';
import { AttachmentIcon, LinkIcon } from '@blocksuite/affine-components/icons';
import { MAX_IMAGE_WIDTH } from '@blocksuite/affine-model';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
import {
getImageFilesFromLocal,
openFileOrFiles,
} from '@blocksuite/affine-shared/utils';
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
import { effect } from '@preact/signals-core';
import { css, html, LitElement } from 'lit';
import { property, state } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import {
getImageFilesFromLocal,
type NoteChildrenFlavour,
openFileOrFiles,
} from '../../../../../_common/utils/index.js';
import type { NoteToolOption } from '../../../gfx-tool/note-tool.js';
import { getTooltipWithShortcut } from '../../utils.js';
import { EdgelessToolbarToolMixin } from '../mixins/tool.mixin.js';

View File

@@ -13,8 +13,10 @@ import {
EditPropsStore,
TelemetryProvider,
} from '@blocksuite/affine-shared/services';
import { LassoMode } from '@blocksuite/affine-shared/types';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import {
GfxBlockElementModel,
type GfxToolsMap,
type GfxToolsOption,
isGfxGroupCompatibleModel,
@@ -27,9 +29,7 @@ import {
isElementOutsideViewport,
isSingleMindMapNode,
} from '../../_common/edgeless/mindmap/index.js';
import { LassoMode } from '../../_common/types.js';
import { PageKeyboardManager } from '../keyboard/keyboard-manager.js';
import { GfxBlockModel } from './block-model.js';
import type { EdgelessRootBlockComponent } from './edgeless-root-block.js';
import { CopilotTool } from './gfx-tool/copilot-tool.js';
import { LassoTool } from './gfx-tool/lasso-tool.js';
@@ -115,8 +115,8 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
if (
selection.selectedElements.length === 1 &&
selection.firstElement instanceof GfxBlockModel &&
matchFlavours(selection.firstElement as GfxBlockModel, [
selection.firstElement instanceof GfxBlockElementModel &&
matchFlavours(selection.firstElement as GfxBlockElementModel, [
'affine:note',
])
) {

View File

@@ -15,6 +15,7 @@ import {
FontLoaderService,
ThemeProvider,
} from '@blocksuite/affine-shared/services';
import type { Viewport } from '@blocksuite/affine-shared/types';
import {
isTouchPadPinchEvent,
requestConnectedFrame,
@@ -38,7 +39,6 @@ import { query } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import { isSingleMindMapNode } from '../../_common/edgeless/mindmap/index.js';
import type { Viewport } from '../../_common/utils/index.js';
import type { EdgelessRootBlockWidgetName } from '../types.js';
import { EdgelessClipboardController } from './clipboard/clipboard.js';
import type { EdgelessSelectedRectWidget } from './components/rects/edgeless-selected-rect.js';

View File

@@ -7,6 +7,7 @@ import {
FontLoaderService,
ThemeProvider,
} from '@blocksuite/affine-shared/services';
import { requestThrottledConnectedFrame } from '@blocksuite/affine-shared/utils';
import type {
GfxBlockComponent,
SurfaceSelection,
@@ -17,7 +18,6 @@ import { assertExists } from '@blocksuite/global/utils';
import { css, html } from 'lit';
import { query, state } from 'lit/decorators.js';
import { requestThrottledConnectedFrame } from '../../_common/utils/index.js';
import type { EdgelessRootBlockWidgetName } from '../types.js';
import type { EdgelessRootService } from './edgeless-root-service.js';
import { getBackgroundGrid, isCanvasElement } from './utils/query.js';

View File

@@ -23,6 +23,7 @@ import type {
ReorderingDirection,
} from '@blocksuite/block-std/gfx';
import {
GfxBlockElementModel,
GfxControllerIdentifier,
GfxExtensionIdentifier,
isGfxGroupCompatibleModel,
@@ -32,7 +33,6 @@ import { Bound, getCommonBound } from '@blocksuite/global/utils';
import { effect } from '@preact/signals-core';
import { RootService } from '../root-service.js';
import { GfxBlockModel } from './block-model.js';
import type { EdgelessFrameManager } from './frame-manager.js';
import { TemplateJob } from './services/template.js';
import {
@@ -60,7 +60,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
TemplateJob = TemplateJob;
get blocks(): GfxBlockModel[] {
get blocks(): GfxBlockElementModel[] {
return this.layer.blocks;
}
@@ -358,7 +358,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
});
}
if (el instanceof GfxBlockModel) {
if (el instanceof GfxBlockElementModel) {
this.doc.deleteBlock(el);
return;
}
@@ -376,7 +376,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
const index = this.layer.getReorderedIndex(element, direction);
// block should be updated in transaction
if (element instanceof GfxBlockModel) {
if (element instanceof GfxBlockElementModel) {
this.doc.transact(() => {
element.index = index;
});

View File

@@ -3,6 +3,7 @@ import { Overlay } from '@blocksuite/affine-block-surface';
import {
generateKeyBetweenV2,
getTopElements,
GfxBlockElementModel,
type GfxController,
GfxExtension,
GfxExtensionIdentifier,
@@ -22,7 +23,6 @@ import type { Doc } from '@blocksuite/store';
import { DocCollection, Text } from '@blocksuite/store';
import type { FrameBlockModel, NoteBlockModel } from '../../index.js';
import { GfxBlockModel } from './block-model.js';
import { areSetsEqual } from './utils/misc.js';
import { isFrameBlock } from './utils/query.js';
@@ -254,7 +254,7 @@ export class EdgelessFrameManager extends GfxExtension {
doc.slots.blockUpdated.on(payload => {
if (
payload.type === 'add' &&
payload.model instanceof GfxBlockModel &&
payload.model instanceof GfxBlockElementModel &&
renderableInEdgeless(doc, surfaceModel, payload.model)
) {
const frame = this.getFrameFromPoint(
@@ -454,7 +454,7 @@ export class EdgelessFrameManager extends GfxExtension {
removeFromParentFrame(element: GfxModel) {
const parentFrame = this.getParentFrame(element);
// eslint-disable-next-line unicorn/prefer-dom-node-remove
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
parentFrame?.removeChild(element);
}
@@ -499,7 +499,7 @@ export function getBlocksInFrameBound(
).concat(
surface.children.filter(ele => {
if (ele.id === model.id) return false;
if (ele instanceof GfxBlockModel) {
if (ele instanceof GfxBlockElementModel) {
const blockBound = Bound.deserialize(ele.xywh);
return fullyContained
? bound.contains(blockBound)

View File

@@ -25,6 +25,7 @@ import type { PointerEventState } from '@blocksuite/block-std';
import {
BaseTool,
getTopElements,
type GfxBlockElementModel,
GfxExtensionIdentifier,
type GfxModel,
type GfxPrimitiveElementModel,
@@ -43,7 +44,6 @@ import {
import { effect } from '@preact/signals-core';
import { isSingleMindMapNode } from '../../../_common/edgeless/mindmap/index.js';
import type { GfxBlockModel } from '../block-model.js';
import type { EdgelessRootBlockComponent } from '../edgeless-root-block.js';
import type { EdgelessFrameManager, FrameOverlay } from '../frame-manager.js';
import { prepareCloneData } from '../utils/clone-utils.js';
@@ -116,8 +116,8 @@ export class DefaultTool extends BaseTool {
};
private readonly _pendingUpdates = new Map<
GfxBlockModel | GfxPrimitiveElementModel,
Partial<GfxBlockModel>
GfxBlockElementModel | GfxPrimitiveElementModel,
Partial<GfxBlockElementModel>
>();
private _rafId: number | null = null;
@@ -544,8 +544,8 @@ export class DefaultTool extends BaseTool {
}
private _scheduleUpdate(
element: GfxBlockModel | GfxPrimitiveElementModel,
updates: Partial<GfxBlockModel>
element: GfxBlockElementModel | GfxPrimitiveElementModel,
updates: Partial<GfxBlockElementModel>
) {
this._pendingUpdates.set(element, updates);

View File

@@ -4,6 +4,7 @@ import {
type SurfaceBlockComponent,
} from '@blocksuite/affine-block-surface';
import { ThemeProvider } from '@blocksuite/affine-shared/services';
import { LassoMode } from '@blocksuite/affine-shared/types';
import type { PointerEventState } from '@blocksuite/block-std';
import { BaseTool } from '@blocksuite/block-std/gfx';
import type { IPoint, IVec } from '@blocksuite/global/utils';
@@ -17,8 +18,6 @@ import {
Vec,
} from '@blocksuite/global/utils';
import { LassoMode } from '../../../_common/types.js';
class LassoOverlay extends Overlay {
d = '';

View File

@@ -4,15 +4,13 @@ import {
DEFAULT_NOTE_WIDTH,
} from '@blocksuite/affine-model';
import { EditPropsStore } from '@blocksuite/affine-shared/services';
import type { NoteChildrenFlavour } from '@blocksuite/affine-shared/types';
import type { PointerEventState } from '@blocksuite/block-std';
import { BaseTool } from '@blocksuite/block-std/gfx';
import { Point } from '@blocksuite/global/utils';
import { effect } from '@preact/signals-core';
import {
hasClassNameInList,
type NoteChildrenFlavour,
} from '../../../_common/utils/index.js';
import { hasClassNameInList } from '../../../_common/utils/index.js';
import { addNote } from '../utils/common.js';
import { EXCLUDING_MOUSE_OUT_CLASS_LIST } from '../utils/consts.js';
import { DraggingNoteOverlay, NoteOverlay } from '../utils/tool-overlay.js';

View File

@@ -1,4 +1,3 @@
export { GfxBlockModel as EdgelessBlockModel } from './block-model.js';
export { FramePreview } from './components/frame/frame-preview.js';
export * from './edgeless-root-block.js';
export { EdgelessRootService } from './edgeless-root-service.js';

View File

@@ -13,14 +13,13 @@ import {
import type { BlockStdScope } from '@blocksuite/block-std';
import {
getTopElements,
GfxBlockElementModel,
type GfxModel,
isGfxGroupCompatibleModel,
type SerializedElement,
} from '@blocksuite/block-std/gfx';
import { type BlockSnapshot, Job } from '@blocksuite/store';
import { GfxBlockModel } from '../block-model.js';
/**
* return all elements in the tree of the elements
*/
@@ -55,7 +54,7 @@ export function serializeElement(
elements: GfxModel[],
job: Job
) {
if (element instanceof GfxBlockModel) {
if (element instanceof GfxBlockElementModel) {
const snapshot = job.blockToSnapshot(element);
if (!snapshot) {
return;

View File

@@ -1,8 +1,7 @@
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
import { deserializeXYWH } from '@blocksuite/global/utils';
import type { GfxBlockModel } from '../block-model.js';
export function xywhArrayToObject(element: GfxBlockModel) {
export function xywhArrayToObject(element: GfxBlockElementModel) {
const [x, y, w, h] = deserializeXYWH(element.xywh);
return { x, y, w, h };
}

View File

@@ -25,6 +25,7 @@ import {
TextElementModel,
} from '@blocksuite/affine-model';
import type {
GfxBlockElementModel,
GfxModel,
GfxPrimitiveElementModel,
GfxToolsFullOptionValue,
@@ -39,20 +40,19 @@ import {
import type { BlockModel } from '@blocksuite/store';
import type { Connectable } from '../../../_common/utils/index.js';
import type { GfxBlockModel } from '../block-model.js';
import { getElementsWithoutGroup } from './group.js';
const { clamp } = CommonUtils;
export function isMindmapNode(
element: GfxBlockModel | BlockSuite.EdgelessModel | null
element: GfxBlockElementModel | BlockSuite.EdgelessModel | null
) {
return element?.group instanceof MindmapElementModel;
}
export function isTopLevelBlock(
selectable: BlockModel | BlockSuite.EdgelessModel | null
): selectable is GfxBlockModel {
): selectable is GfxBlockElementModel {
return !!selectable && 'flavour' in selectable;
}

View File

@@ -1,7 +1,7 @@
import { RootBlockSchema } from '@blocksuite/affine-model';
import type { Viewport } from '@blocksuite/affine-shared/types';
import { Slot } from '@blocksuite/store';
import type { Viewport } from '../../_common/utils/index.js';
import { RootService } from '../root-service.js';
export class PageRootService extends RootService {

View File

@@ -9,7 +9,10 @@ import {
PaletteIcon,
} from '@blocksuite/affine-components/icons';
import { renderToolbarSeparator } from '@blocksuite/affine-components/toolbar';
import type { AttachmentBlockModel } from '@blocksuite/affine-model';
import type {
AttachmentBlockModel,
EmbedCardStyle,
} from '@blocksuite/affine-model';
import {
EMBED_CARD_HEIGHT,
EMBED_CARD_WIDTH,
@@ -21,7 +24,6 @@ import { html, LitElement, nothing } from 'lit';
import { property } from 'lit/decorators.js';
import { join } from 'lit/directives/join.js';
import type { EmbedCardStyle } from '../../../_common/types.js';
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
export class EdgelessChangeAttachmentButton extends WithDisposable(LitElement) {

View File

@@ -28,7 +28,11 @@ import {
type MenuItem,
renderToolbarSeparator,
} from '@blocksuite/affine-components/toolbar';
import { type AliasInfo, BookmarkStyles } from '@blocksuite/affine-model';
import {
type AliasInfo,
BookmarkStyles,
type EmbedCardStyle,
} from '@blocksuite/affine-model';
import {
EMBED_CARD_HEIGHT,
EMBED_CARD_WIDTH,
@@ -52,7 +56,6 @@ import { ifDefined } from 'lit/directives/if-defined.js';
import { join } from 'lit/directives/join.js';
import { repeat } from 'lit/directives/repeat.js';
import type { EmbedCardStyle } from '../../../_common/types.js';
import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js';
import {
isBookmarkBlock,

View File

@@ -30,15 +30,15 @@ import {
ResetIcon,
} from '@blocksuite/icons/lit';
import {
createLinkedDocFromEdgelessElements,
createLinkedDocFromNote,
} from '../../../../_common/utils/render-linked-doc.js';
import { duplicate } from '../../../edgeless/utils/clipboard-utils.js';
import { getSortedCloneElements } from '../../../edgeless/utils/clone-utils.js';
import { moveConnectors } from '../../../edgeless/utils/connector.js';
import { deleteElements } from '../../../edgeless/utils/crud.js';
import type { ElementToolbarMoreMenuContext } from './context.js';
import {
createLinkedDocFromEdgelessElements,
createLinkedDocFromNote,
} from './render-linked-doc.js';
type EmbedLinkBlockComponent =
| EmbedGithubBlockComponent

View File

@@ -4,24 +4,17 @@ 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 { 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';
} from '../../../edgeless/utils/clone-utils.js';
import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js';
export function addBlocksToDoc(
targetDoc: Doc,
model: BlockModel,
parentId: string
) {
function addBlocksToDoc(targetDoc: Doc, model: BlockModel, parentId: string) {
// Add current block to linked doc
const blockProps = getBlockProps(model);
const newModelId = targetDoc.addBlock(
@@ -87,7 +80,7 @@ export function createLinkedDocFromEdgelessElements(
const ids = new Map<string, string>();
sortedElements.forEach(model => {
let newId = model.id;
if (model instanceof GfxBlockModel) {
if (model instanceof GfxBlockElementModel) {
const blockProps = getBlockProps(model);
if (isNoteBlock(model)) {
newId = linkedDoc.addBlock('affine:note', blockProps, rootId);

View File

@@ -6,6 +6,7 @@ import {
NewIcon,
NotionIcon,
} from '@blocksuite/affine-components/icons';
import { openFileOrFiles } from '@blocksuite/affine-shared/utils';
import { WithDisposable } from '@blocksuite/global/utils';
import type { DocCollection } from '@blocksuite/store';
import { html, LitElement, type PropertyValues } from 'lit';
@@ -14,7 +15,6 @@ import { query, state } from 'lit/decorators.js';
import { HtmlTransformer } from '../../../../_common/transformers/html.js';
import { MarkdownTransformer } from '../../../../_common/transformers/markdown.js';
import { NotionHtmlTransformer } from '../../../../_common/transformers/notion-html.js';
import { openFileOrFiles } from '../../../../_common/utils/index.js';
import { styles } from './styles.js';
export type OnSuccessHandler = (