feat(editor): group gfx extension (#11950)
Closes: BS-3208 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new group view extension, enhancing how group elements are handled and displayed. - Added new store and view modules for group-related features, improving modularity and integration. - **Refactor** - Updated the group element architecture to use extension-based registration for views, toolbars, and effects. - Simplified and reorganized exports for group and text modules. - **Chores** - Updated dependencies and project references to improve build consistency and compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,12 +1,4 @@
|
||||
import { FileDropExtension } from '@blocksuite/affine-components/drop-indicator';
|
||||
import {
|
||||
ConnectorElementRendererExtension,
|
||||
ConnectorElementView,
|
||||
} from '@blocksuite/affine-gfx-connector';
|
||||
import {
|
||||
GroupElementRendererExtension,
|
||||
GroupElementView,
|
||||
} from '@blocksuite/affine-gfx-group';
|
||||
import {
|
||||
TextElementRendererExtension,
|
||||
TextElementView,
|
||||
@@ -42,16 +34,10 @@ import { viewportOverlayWidget } from './widgets';
|
||||
* Because in some cases we need to create edgeless elements in page mode.
|
||||
* And these view may contain some logic when elements initialize.
|
||||
*/
|
||||
const EdgelessElementViews = [
|
||||
ConnectorElementView,
|
||||
GroupElementView,
|
||||
TextElementView,
|
||||
];
|
||||
const EdgelessElementViews = [TextElementView];
|
||||
|
||||
export const EdgelessElementRendererExtension: ExtensionType[] = [
|
||||
TextElementRendererExtension,
|
||||
ConnectorElementRendererExtension,
|
||||
GroupElementRendererExtension,
|
||||
];
|
||||
|
||||
export const CommonSpecs: ExtensionType[] = [
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { groupToolbarExtension } from '@blocksuite/affine-gfx-group';
|
||||
import { textToolbarExtension } from '@blocksuite/affine-gfx-text';
|
||||
import { ToolbarModuleExtension } from '@blocksuite/affine-shared/services';
|
||||
import { BlockFlavourIdentifier } from '@blocksuite/std';
|
||||
@@ -7,8 +6,6 @@ import type { ExtensionType } from '@blocksuite/store';
|
||||
import { builtinLockedToolbarConfig, builtinMiscToolbarConfig } from './misc';
|
||||
|
||||
export const EdgelessElementToolbarExtension: ExtensionType[] = [
|
||||
groupToolbarExtension,
|
||||
|
||||
textToolbarExtension,
|
||||
|
||||
ToolbarModuleExtension({
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { effects as gfxGroupEffects } from '@blocksuite/affine-gfx-group/effects';
|
||||
import { effects as gfxCanvasTextEffects } from '@blocksuite/affine-gfx-text/effects';
|
||||
import { effects as widgetEdgelessToolbarEffects } from '@blocksuite/affine-widget-edgeless-toolbar/effects';
|
||||
import { effects as widgetMobileToolbarEffects } from '@blocksuite/affine-widget-keyboard-toolbar/effects';
|
||||
@@ -73,7 +72,6 @@ function registerRootComponents() {
|
||||
|
||||
function registerGfxEffects() {
|
||||
gfxCanvasTextEffects();
|
||||
gfxGroupEffects();
|
||||
}
|
||||
|
||||
function registerWidgets() {
|
||||
|
||||
@@ -11,7 +11,6 @@ import * as Y from 'yjs';
|
||||
import { elementsCtorMap } from './element-model/index.js';
|
||||
import { surfaceMiddlewareIdentifier } from './extensions/surface-middleware.js';
|
||||
import { SurfaceBlockTransformer } from './surface-transformer.js';
|
||||
import { groupRelationWatcher } from './watchers/group.js';
|
||||
|
||||
export const SurfaceBlockSchema = defineBlockSchema({
|
||||
flavour: 'affine:surface',
|
||||
@@ -50,10 +49,6 @@ export class SurfaceBlockModel extends BaseSurfaceModel {
|
||||
.forEach(({ middleware }) => {
|
||||
this._disposables.add(middleware(this));
|
||||
});
|
||||
|
||||
[groupRelationWatcher(this)].forEach(disposable =>
|
||||
this._disposables.add(disposable)
|
||||
);
|
||||
}
|
||||
|
||||
getConnectors(id: string) {
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { SurfaceGroupLikeModel } from '../element-model/base.js';
|
||||
import type { SurfaceMiddleware } from '../extensions/surface-middleware.js';
|
||||
import type { SurfaceBlockModel } from '../surface-model.js';
|
||||
|
||||
export const groupRelationWatcher: SurfaceMiddleware = (
|
||||
surface: SurfaceBlockModel
|
||||
) => {
|
||||
const disposables = [
|
||||
surface.elementUpdated.subscribe(({ id, props, local }) => {
|
||||
if (!local) return;
|
||||
|
||||
const element = surface.getElementById(id)!;
|
||||
|
||||
// remove the group if it has no children
|
||||
if (
|
||||
element instanceof SurfaceGroupLikeModel &&
|
||||
props['childIds'] &&
|
||||
element.childIds.length === 0
|
||||
) {
|
||||
surface.deleteElement(id);
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
return () => {
|
||||
disposables.forEach(d => d.unsubscribe());
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user