refactor(core): minimize comment editor (#12995)

#### PR Dependency Tree


* **PR #12995** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Introduced a new clipboard module, making clipboard-related
functionality available for external use.
* Added a comprehensive extension system for the comment editor,
supporting rich text features, widgets, and configurable options.

* **Bug Fixes**
* Improved stability by ensuring comment highlighting features and
toolbar event subscriptions handle missing dependencies gracefully,
preventing potential runtime errors.

* **Refactor**
* Simplified comment editor view manager setup for easier configuration
and maintenance.

* **Chores**
* Updated package exports to expose new clipboard modules and
configurations.
* Removed confirm modal and portal-related logic from the comment editor
component.
* Adjusted temporary store creation to omit adding an extra surface
block under the root page.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
L-Sun
2025-07-03 12:21:28 +08:00
committed by GitHub
parent 5d8ee51e8c
commit 32c40bbf09
17 changed files with 238 additions and 67 deletions
+1
View File
@@ -285,6 +285,7 @@
"./sync": "./src/sync/index.ts",
"./extensions/store": "./src/extensions/store.ts",
"./extensions/view": "./src/extensions/view.ts",
"./foundation/clipboard": "./src/foundation/clipboard.ts",
"./foundation/store": "./src/foundation/store.ts",
"./foundation/view": "./src/foundation/view.ts"
},
@@ -0,0 +1 @@
export * from '@blocksuite/affine-foundation/clipboard';
@@ -94,9 +94,11 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
convertTo = () => {
@@ -130,9 +130,11 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
handleClick = (event: MouseEvent) => {
@@ -392,9 +392,11 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
override async getUpdateComplete() {
@@ -313,9 +313,11 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBloc
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
override get topContenteditableElement() {
@@ -63,9 +63,11 @@ export class EmbedBlockComponent<
protected embedContainerStyle: StyleInfo = {};
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
renderEmbed = (content: () => TemplateResult) => {
@@ -69,9 +69,11 @@ export class ImageBlockComponent extends CaptionedBlockComponent<ImageBlockModel
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
private _handleClick(event: MouseEvent) {
@@ -109,9 +109,11 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
override get topContenteditableElement() {
@@ -20,6 +20,10 @@ import {
isFormatSupported,
textFormatConfigs,
} from '@blocksuite/affine-inline-preset';
import {
EmbedLinkedDocBlockSchema,
EmbedSyncedDocBlockSchema,
} from '@blocksuite/affine-model';
import { textConversionConfigs } from '@blocksuite/affine-rich-text';
import {
copySelectedModelsCommand,
@@ -50,7 +54,11 @@ import {
DuplicateIcon,
LinkedPageIcon,
} from '@blocksuite/icons/lit';
import { type BlockComponent, BlockSelection } from '@blocksuite/std';
import {
type BlockComponent,
BlockSelection,
BlockViewIdentifier,
} from '@blocksuite/std';
import { toDraftModel } from '@blocksuite/store';
import { html } from 'lit';
import { repeat } from 'lit/directives/repeat.js';
@@ -214,7 +222,18 @@ const turnIntoLinkedDoc = {
id: 'f.convert-to-linked-doc',
tooltip: 'Create Linked Doc',
icon: LinkedPageIcon(),
when({ chain }) {
when({ chain, std }) {
const supportFlavours = [
EmbedLinkedDocBlockSchema,
EmbedSyncedDocBlockSchema,
].map(schema => schema.model.flavour);
if (
supportFlavours.some(
flavour => !std.getOptional(BlockViewIdentifier(flavour))
)
)
return false;
const [ok, { selectedModels }] = chain
.pipe(getSelectedModelsCommand, {
types: ['block', 'text'],
@@ -143,9 +143,11 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
}
get isCommentHighlighted() {
return this.std
.get(BlockCommentManager)
.isBlockCommentHighlighted(this.model);
return (
this.std
.getOptional(BlockCommentManager)
?.isBlockCommentHighlighted(this.model) ?? false
);
}
private readonly _handleClick = () => {
@@ -32,6 +32,7 @@
},
"exports": {
".": "./src/index.ts",
"./clipboard": "./src/clipboard.ts",
"./store": "./src/store.ts",
"./view": "./src/view.ts"
},
@@ -43,7 +43,7 @@ const imageClipboardConfigs = [
});
});
const PlainTextClipboardConfig = ClipboardAdapterConfigExtension({
export const PlainTextClipboardConfig = ClipboardAdapterConfigExtension({
mimeType: 'text/plain',
adapter: MixTextAdapter,
priority: 70,
@@ -579,9 +579,11 @@ export class AffineToolbarWidget extends WidgetComponent {
);
// Handles elements when resizing
const edgelessSlots = std.get(EdgelessLegacySlotIdentifier);
disposables.add(edgelessSlots.elementResizeStart.subscribe(dragStart));
disposables.add(edgelessSlots.elementResizeEnd.subscribe(dragEnd));
const edgelessSlots = std.getOptional(EdgelessLegacySlotIdentifier);
if (edgelessSlots) {
disposables.add(edgelessSlots.elementResizeStart.subscribe(dragStart));
disposables.add(edgelessSlots.elementResizeEnd.subscribe(dragEnd));
}
// Handles elements when hovering
disposables.add(