mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
9d90899344
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 -->
37 lines
859 B
TypeScript
37 lines
859 B
TypeScript
import {
|
|
type SurfaceBlockModel,
|
|
SurfaceGroupLikeModel,
|
|
type SurfaceMiddleware,
|
|
surfaceMiddlewareExtension,
|
|
} from '@blocksuite/affine-block-surface';
|
|
|
|
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());
|
|
};
|
|
};
|
|
|
|
export const groupRelationWatcherExtension = surfaceMiddlewareExtension(
|
|
'group-relation-watcher',
|
|
groupRelationWatcher
|
|
);
|