mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08:00
refactor(editor): move connector overlay to connector package (#11944)
This commit is contained in:
+4
-2
@@ -1,7 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
CanvasElementType,
|
CanvasElementType,
|
||||||
type ConnectionOverlay,
|
|
||||||
ConnectorPathGenerator,
|
|
||||||
EdgelessCRUDIdentifier,
|
EdgelessCRUDIdentifier,
|
||||||
getSurfaceBlock,
|
getSurfaceBlock,
|
||||||
getSurfaceComponent,
|
getSurfaceComponent,
|
||||||
@@ -10,6 +8,10 @@ import {
|
|||||||
OverlayIdentifier,
|
OverlayIdentifier,
|
||||||
type RoughCanvas,
|
type RoughCanvas,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
|
import {
|
||||||
|
type ConnectionOverlay,
|
||||||
|
ConnectorPathGenerator,
|
||||||
|
} from '@blocksuite/affine-gfx-connector';
|
||||||
import { mountShapeTextEditor } from '@blocksuite/affine-gfx-shape';
|
import { mountShapeTextEditor } from '@blocksuite/affine-gfx-shape';
|
||||||
import type {
|
import type {
|
||||||
Connection,
|
Connection,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { ConnectionOverlay } from '@blocksuite/affine-block-surface';
|
|
||||||
import type * as BrushEffect from '@blocksuite/affine-gfx-brush';
|
import type * as BrushEffect from '@blocksuite/affine-gfx-brush';
|
||||||
import type * as NoteEffect from '@blocksuite/affine-gfx-note';
|
import type * as NoteEffect from '@blocksuite/affine-gfx-note';
|
||||||
import type * as ShapeEffect from '@blocksuite/affine-gfx-shape';
|
import type * as ShapeEffect from '@blocksuite/affine-gfx-shape';
|
||||||
@@ -36,7 +35,6 @@ export const EdgelessEditExtensions: ExtensionType[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const EdgelessBuiltInManager: ExtensionType[] = [
|
export const EdgelessBuiltInManager: ExtensionType[] = [
|
||||||
ConnectionOverlay,
|
|
||||||
SnapOverlay,
|
SnapOverlay,
|
||||||
AltCloneExtension,
|
AltCloneExtension,
|
||||||
EditPropsMiddlewareBuilder,
|
EditPropsMiddlewareBuilder,
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ export * from './element-renderer';
|
|||||||
export * from './export-manager';
|
export * from './export-manager';
|
||||||
export * from './legacy-slot-extension';
|
export * from './legacy-slot-extension';
|
||||||
export * from './query';
|
export * from './query';
|
||||||
|
export * from './surface-middleware';
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import type { NoteBlockModel } from '@blocksuite/affine-model';
|
import type { Connectable, NoteBlockModel } from '@blocksuite/affine-model';
|
||||||
import type { GfxModel } from '@blocksuite/std/gfx';
|
import type { GfxModel } from '@blocksuite/std/gfx';
|
||||||
import type { BlockModel } from '@blocksuite/store';
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
|
|
||||||
import type { Connectable } from '../managers/connector-manager';
|
|
||||||
|
|
||||||
export function isConnectable(
|
export function isConnectable(
|
||||||
element: GfxModel | null
|
element: GfxModel | null
|
||||||
): element is Connectable {
|
): element is Connectable {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { createIdentifier } from '@blocksuite/global/di';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
|
import type { SurfaceBlockModel } from '../surface-model';
|
||||||
|
|
||||||
|
export type SurfaceMiddleware = (surface: SurfaceBlockModel) => () => void;
|
||||||
|
|
||||||
|
export const surfaceMiddlewareIdentifier = createIdentifier<{
|
||||||
|
middleware: SurfaceMiddleware;
|
||||||
|
}>('surface-middleware');
|
||||||
|
|
||||||
|
export function surfaceMiddlewareExtension(
|
||||||
|
id: string,
|
||||||
|
middleware: SurfaceMiddleware
|
||||||
|
): ExtensionType {
|
||||||
|
return {
|
||||||
|
setup: di => {
|
||||||
|
di.addImpl(surfaceMiddlewareIdentifier(id), {
|
||||||
|
middleware,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -7,18 +7,6 @@ export {
|
|||||||
SurfaceGroupLikeModel,
|
SurfaceGroupLikeModel,
|
||||||
} from './element-model/base.js';
|
} from './element-model/base.js';
|
||||||
export { CanvasElementType } from './element-model/index.js';
|
export { CanvasElementType } from './element-model/index.js';
|
||||||
import {
|
|
||||||
isConnectorAndBindingsAllSelected,
|
|
||||||
isConnectorWithLabel,
|
|
||||||
} from './managers/connector-manager.js';
|
|
||||||
export {
|
|
||||||
calculateNearestLocation,
|
|
||||||
ConnectionOverlay,
|
|
||||||
ConnectorEndpointLocations,
|
|
||||||
ConnectorEndpointLocationsOnTriangle,
|
|
||||||
ConnectorPathGenerator,
|
|
||||||
PathGenerator,
|
|
||||||
} from './managers/connector-manager.js';
|
|
||||||
export { CanvasRenderer } from './renderer/canvas-renderer.js';
|
export { CanvasRenderer } from './renderer/canvas-renderer.js';
|
||||||
export type { ElementRenderer } from './renderer/elements/index.js';
|
export type { ElementRenderer } from './renderer/elements/index.js';
|
||||||
export * from './renderer/elements/type.js';
|
export * from './renderer/elements/type.js';
|
||||||
@@ -60,11 +48,6 @@ export type { Options } from './utils/rough/core';
|
|||||||
export { sortIndex } from './utils/sort';
|
export { sortIndex } from './utils/sort';
|
||||||
export { updateXYWH } from './utils/update-xywh.js';
|
export { updateXYWH } from './utils/update-xywh.js';
|
||||||
|
|
||||||
export const ConnectorUtils = {
|
|
||||||
isConnectorAndBindingsAllSelected,
|
|
||||||
isConnectorWithLabel,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const TextUtils = {
|
export const TextUtils = {
|
||||||
wrapFontFamily,
|
wrapFontFamily,
|
||||||
getFontFaces,
|
getFontFaces,
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import { BlockSchemaExtension, defineBlockSchema } from '@blocksuite/store';
|
|||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { elementsCtorMap } from './element-model/index.js';
|
import { elementsCtorMap } from './element-model/index.js';
|
||||||
|
import { surfaceMiddlewareIdentifier } from './extensions/surface-middleware.js';
|
||||||
import { SurfaceBlockTransformer } from './surface-transformer.js';
|
import { SurfaceBlockTransformer } from './surface-transformer.js';
|
||||||
import { connectorWatcher } from './watchers/connector.js';
|
|
||||||
import { groupRelationWatcher } from './watchers/group.js';
|
import { groupRelationWatcher } from './watchers/group.js';
|
||||||
|
|
||||||
export const SurfaceBlockSchema = defineBlockSchema({
|
export const SurfaceBlockSchema = defineBlockSchema({
|
||||||
@@ -39,15 +39,19 @@ export const SurfaceBlockSchema = defineBlockSchema({
|
|||||||
export const SurfaceBlockSchemaExtension =
|
export const SurfaceBlockSchemaExtension =
|
||||||
BlockSchemaExtension(SurfaceBlockSchema);
|
BlockSchemaExtension(SurfaceBlockSchema);
|
||||||
|
|
||||||
export type SurfaceMiddleware = (surface: SurfaceBlockModel) => () => void;
|
|
||||||
|
|
||||||
export class SurfaceBlockModel extends BaseSurfaceModel {
|
export class SurfaceBlockModel extends BaseSurfaceModel {
|
||||||
private readonly _disposables: DisposableGroup = new DisposableGroup();
|
private readonly _disposables: DisposableGroup = new DisposableGroup();
|
||||||
|
|
||||||
override _init() {
|
override _init() {
|
||||||
this._extendElement(elementsCtorMap);
|
this._extendElement(elementsCtorMap);
|
||||||
super._init();
|
super._init();
|
||||||
[connectorWatcher(this), groupRelationWatcher(this)].forEach(disposable =>
|
this.doc.provider
|
||||||
|
.getAll(surfaceMiddlewareIdentifier)
|
||||||
|
.forEach(({ middleware }) => {
|
||||||
|
this._disposables.add(middleware(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
[groupRelationWatcher(this)].forEach(disposable =>
|
||||||
this._disposables.add(disposable)
|
this._disposables.add(disposable)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { SurfaceGroupLikeModel } from '../element-model/base.js';
|
import { SurfaceGroupLikeModel } from '../element-model/base.js';
|
||||||
import type { SurfaceBlockModel, SurfaceMiddleware } from '../surface-model.js';
|
import type { SurfaceMiddleware } from '../extensions/surface-middleware.js';
|
||||||
|
import type { SurfaceBlockModel } from '../surface-model.js';
|
||||||
|
|
||||||
export const groupRelationWatcher: SurfaceMiddleware = (
|
export const groupRelationWatcher: SurfaceMiddleware = (
|
||||||
surface: SurfaceBlockModel
|
surface: SurfaceBlockModel
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
type ConnectionOverlay,
|
|
||||||
EdgelessLegacySlotIdentifier,
|
EdgelessLegacySlotIdentifier,
|
||||||
OverlayIdentifier,
|
OverlayIdentifier,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
@@ -20,6 +19,8 @@ import { css, html, LitElement } from 'lit';
|
|||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
|
import type { ConnectionOverlay } from '../connector-manager';
|
||||||
|
|
||||||
const SIZE = 12;
|
const SIZE = 12;
|
||||||
const HALF_SIZE = SIZE / 2;
|
const HALF_SIZE = SIZE / 2;
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -1,3 +1,4 @@
|
|||||||
|
import { AStarRunner, Overlay } from '@blocksuite/affine-block-surface';
|
||||||
import {
|
import {
|
||||||
type BrushElementModel,
|
type BrushElementModel,
|
||||||
type Connection,
|
type Connection,
|
||||||
@@ -35,9 +36,6 @@ import type {
|
|||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
import last from 'lodash-es/last';
|
import last from 'lodash-es/last';
|
||||||
|
|
||||||
import { Overlay } from '../renderer/overlay.js';
|
|
||||||
import { AStarRunner } from '../utils/a-star.js';
|
|
||||||
|
|
||||||
export type Connectable = Exclude<
|
export type Connectable = Exclude<
|
||||||
GfxModel,
|
GfxModel,
|
||||||
ConnectorElementModel | BrushElementModel | GroupElementModel
|
ConnectorElementModel | BrushElementModel | GroupElementModel
|
||||||
@@ -850,7 +848,6 @@ function renderRect(
|
|||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(@mirone): move to connector package
|
|
||||||
export class ConnectionOverlay extends Overlay {
|
export class ConnectionOverlay extends Overlay {
|
||||||
static override overlayName = 'connection';
|
static override overlayName = 'connection';
|
||||||
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
calculateNearestLocation,
|
|
||||||
CanvasElementType,
|
CanvasElementType,
|
||||||
type ConnectionOverlay,
|
|
||||||
ConnectorEndpointLocations,
|
|
||||||
ConnectorEndpointLocationsOnTriangle,
|
|
||||||
OverlayIdentifier,
|
OverlayIdentifier,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
import type {
|
import type {
|
||||||
@@ -22,6 +18,13 @@ import { Bound } from '@blocksuite/global/gfx';
|
|||||||
import type { PointerEventState } from '@blocksuite/std';
|
import type { PointerEventState } from '@blocksuite/std';
|
||||||
import { BaseTool, type GfxModel } from '@blocksuite/std/gfx';
|
import { BaseTool, type GfxModel } from '@blocksuite/std/gfx';
|
||||||
|
|
||||||
|
import {
|
||||||
|
calculateNearestLocation,
|
||||||
|
type ConnectionOverlay,
|
||||||
|
ConnectorEndpointLocations,
|
||||||
|
ConnectorEndpointLocationsOnTriangle,
|
||||||
|
} from './connector-manager';
|
||||||
|
|
||||||
enum ConnectorToolMode {
|
enum ConnectorToolMode {
|
||||||
// Dragging connect
|
// Dragging connect
|
||||||
Dragging,
|
Dragging,
|
||||||
|
|||||||
+11
-2
@@ -1,8 +1,12 @@
|
|||||||
|
import {
|
||||||
|
type SurfaceBlockModel,
|
||||||
|
type SurfaceMiddleware,
|
||||||
|
surfaceMiddlewareExtension,
|
||||||
|
} from '@blocksuite/affine-block-surface';
|
||||||
import type { ConnectorElementModel } from '@blocksuite/affine-model';
|
import type { ConnectorElementModel } from '@blocksuite/affine-model';
|
||||||
import type { GfxModel } from '@blocksuite/std/gfx';
|
import type { GfxModel } from '@blocksuite/std/gfx';
|
||||||
|
|
||||||
import { ConnectorPathGenerator } from '../managers/connector-manager.js';
|
import { ConnectorPathGenerator } from './connector-manager';
|
||||||
import type { SurfaceBlockModel, SurfaceMiddleware } from '../surface-model.js';
|
|
||||||
|
|
||||||
export const connectorWatcher: SurfaceMiddleware = (
|
export const connectorWatcher: SurfaceMiddleware = (
|
||||||
surface: SurfaceBlockModel
|
surface: SurfaceBlockModel
|
||||||
@@ -86,3 +90,8 @@ export const connectorWatcher: SurfaceMiddleware = (
|
|||||||
disposables.forEach(d => d.unsubscribe());
|
disposables.forEach(d => d.unsubscribe());
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const connectorWatcherExtension = surfaceMiddlewareExtension(
|
||||||
|
'connector-watcher',
|
||||||
|
connectorWatcher
|
||||||
|
);
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
type CanvasRenderer,
|
type CanvasRenderer,
|
||||||
ConnectorUtils,
|
|
||||||
type ElementRenderer,
|
type ElementRenderer,
|
||||||
ElementRendererExtension,
|
ElementRendererExtension,
|
||||||
type RoughCanvas,
|
type RoughCanvas,
|
||||||
@@ -26,6 +25,7 @@ import {
|
|||||||
} from '@blocksuite/global/gfx';
|
} from '@blocksuite/global/gfx';
|
||||||
import { deltaInsertsToChunks } from '@blocksuite/std/inline';
|
import { deltaInsertsToChunks } from '@blocksuite/std/inline';
|
||||||
|
|
||||||
|
import { isConnectorWithLabel } from '../connector-manager.js';
|
||||||
import {
|
import {
|
||||||
DEFAULT_ARROW_SIZE,
|
DEFAULT_ARROW_SIZE,
|
||||||
getArrowOptions,
|
getArrowOptions,
|
||||||
@@ -55,7 +55,7 @@ export const connector: ElementRenderer<
|
|||||||
|
|
||||||
ctx.setTransform(matrix);
|
ctx.setTransform(matrix);
|
||||||
|
|
||||||
const hasLabel = ConnectorUtils.isConnectorWithLabel(model);
|
const hasLabel = isConnectorWithLabel(model);
|
||||||
let dx = 0;
|
let dx = 0;
|
||||||
let dy = 0;
|
let dy = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './adapter';
|
export * from './adapter';
|
||||||
|
export * from './connector-manager';
|
||||||
export * from './connector-tool';
|
export * from './connector-tool';
|
||||||
export * from './element-renderer';
|
export * from './element-renderer';
|
||||||
export * from './element-transform';
|
export * from './element-transform';
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
connectorToMarkdownAdapterMatcher,
|
connectorToMarkdownAdapterMatcher,
|
||||||
connectorToPlainTextAdapterMatcher,
|
connectorToPlainTextAdapterMatcher,
|
||||||
} from './adapter';
|
} from './adapter';
|
||||||
|
import { connectorWatcherExtension } from './connector-watcher';
|
||||||
|
|
||||||
export class ConnectorStoreExtension extends StoreExtensionProvider {
|
export class ConnectorStoreExtension extends StoreExtensionProvider {
|
||||||
override name = 'affine-connector-gfx';
|
override name = 'affine-connector-gfx';
|
||||||
@@ -15,5 +16,6 @@ export class ConnectorStoreExtension extends StoreExtensionProvider {
|
|||||||
super.setup(context);
|
super.setup(context);
|
||||||
context.register(connectorToPlainTextAdapterMatcher);
|
context.register(connectorToPlainTextAdapterMatcher);
|
||||||
context.register(connectorToMarkdownAdapterMatcher);
|
context.register(connectorToMarkdownAdapterMatcher);
|
||||||
|
context.register(connectorWatcherExtension);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
ConnectorUtils,
|
|
||||||
EdgelessCRUDIdentifier,
|
|
||||||
} from '@blocksuite/affine-block-surface';
|
|
||||||
import {
|
import {
|
||||||
packColor,
|
packColor,
|
||||||
type PickColorEvent,
|
type PickColorEvent,
|
||||||
@@ -61,6 +58,7 @@ import { BlockFlavourIdentifier } from '@blocksuite/std';
|
|||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
|
import { isConnectorWithLabel } from '../connector-manager';
|
||||||
import { mountConnectorLabelEditor } from '../text';
|
import { mountConnectorLabelEditor } from '../text';
|
||||||
|
|
||||||
const FRONT_ENDPOINT_STYLE_LIST = [
|
const FRONT_ENDPOINT_STYLE_LIST = [
|
||||||
@@ -350,7 +348,7 @@ export const connectorToolbarConfig = {
|
|||||||
ConnectorElementModel,
|
ConnectorElementModel,
|
||||||
'connector',
|
'connector',
|
||||||
(ctx, model, props) => {
|
(ctx, model, props) => {
|
||||||
if (!ConnectorUtils.isConnectorWithLabel(model)) return;
|
if (!isConnectorWithLabel(model)) return;
|
||||||
|
|
||||||
const labelStyle = { ...model.labelStyle, ...props };
|
const labelStyle = { ...model.labelStyle, ...props };
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
ViewExtensionProvider,
|
ViewExtensionProvider,
|
||||||
} from '@blocksuite/affine-ext-loader';
|
} from '@blocksuite/affine-ext-loader';
|
||||||
|
|
||||||
|
import { ConnectionOverlay } from './connector-manager';
|
||||||
import { ConnectorTool } from './connector-tool';
|
import { ConnectorTool } from './connector-tool';
|
||||||
import { effects } from './effects';
|
import { effects } from './effects';
|
||||||
import { ConnectorFilter } from './element-transform';
|
import { ConnectorFilter } from './element-transform';
|
||||||
@@ -24,6 +25,7 @@ export class ConnectorViewExtension extends ViewExtensionProvider {
|
|||||||
context.register(ConnectorFilter);
|
context.register(ConnectorFilter);
|
||||||
context.register(connectorQuickTool);
|
context.register(connectorQuickTool);
|
||||||
context.register(connectorToolbarExtension);
|
context.register(connectorToolbarExtension);
|
||||||
|
context.register(ConnectionOverlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
ConnectorPathGenerator,
|
|
||||||
type ElementRenderer,
|
type ElementRenderer,
|
||||||
ElementRendererExtension,
|
ElementRendererExtension,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
import { connector as renderConnector } from '@blocksuite/affine-gfx-connector';
|
import {
|
||||||
|
connector as renderConnector,
|
||||||
|
ConnectorPathGenerator,
|
||||||
|
} from '@blocksuite/affine-gfx-connector';
|
||||||
import type {
|
import type {
|
||||||
MindmapElementModel,
|
MindmapElementModel,
|
||||||
MindmapNode,
|
MindmapNode,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Overlay, PathGenerator } from '@blocksuite/affine-block-surface';
|
import { Overlay } from '@blocksuite/affine-block-surface';
|
||||||
|
import { PathGenerator } from '@blocksuite/affine-gfx-connector';
|
||||||
import {
|
import {
|
||||||
ConnectorMode,
|
ConnectorMode,
|
||||||
LayoutType,
|
LayoutType,
|
||||||
|
|||||||
Reference in New Issue
Block a user