mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 05:07:06 +08:00
091bac1047
Close [BS-3624](https://linear.app/affine-design/issue/BS-3624/page模式单选图片的时候希望有comment-按钮) #### PR Dependency Tree * **PR #13304** 👈 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** * Added a comment button to the image and surface reference block toolbars for easier commenting. * **Refactor** * Simplified array flattening operations across multiple components and utilities by replacing `.map(...).flat()` with `.flatMap(...)`, improving code readability and maintainability. * **Bug Fixes** * Improved comment creation logic to allow adding comments even when selections exist. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import {
|
|
NoteBlockModel,
|
|
NoteDisplayMode,
|
|
ParagraphBlockModel,
|
|
RootBlockModel,
|
|
} from '@blocksuite/affine-model';
|
|
import { matchModels } from '@blocksuite/affine-shared/utils';
|
|
import type { BlockModel, Store } from '@blocksuite/store';
|
|
|
|
import { headingKeys } from '../config.js';
|
|
|
|
export function getNotesFromStore(
|
|
store: Store,
|
|
modes: NoteDisplayMode[] = [
|
|
NoteDisplayMode.DocAndEdgeless,
|
|
NoteDisplayMode.DocOnly,
|
|
NoteDisplayMode.EdgelessOnly,
|
|
]
|
|
) {
|
|
const rootModel = store.root;
|
|
if (!rootModel) return [];
|
|
|
|
const notes: NoteBlockModel[] = [];
|
|
|
|
rootModel.children.forEach(block => {
|
|
if (!matchModels(block, [NoteBlockModel])) return;
|
|
|
|
if (modes.includes(block.props.displayMode$.value)) {
|
|
notes.push(block);
|
|
}
|
|
});
|
|
|
|
return notes;
|
|
}
|
|
|
|
export function isRootBlock(block: BlockModel): block is RootBlockModel {
|
|
return matchModels(block, [RootBlockModel]);
|
|
}
|
|
|
|
export function isHeadingBlock(
|
|
block: BlockModel
|
|
): block is ParagraphBlockModel {
|
|
return (
|
|
matchModels(block, [ParagraphBlockModel]) &&
|
|
headingKeys.has(block.props.type$.value)
|
|
);
|
|
}
|
|
|
|
export function getHeadingBlocksFromNote(
|
|
note: NoteBlockModel,
|
|
ignoreEmpty = false
|
|
) {
|
|
const models = note.children.filter(block => {
|
|
const empty = block.text && block.text.length > 0;
|
|
return isHeadingBlock(block) && (!ignoreEmpty || empty);
|
|
});
|
|
|
|
return models;
|
|
}
|
|
|
|
export function getHeadingBlocksFromDoc(
|
|
store: Store,
|
|
modes: NoteDisplayMode[] = [
|
|
NoteDisplayMode.DocAndEdgeless,
|
|
NoteDisplayMode.DocOnly,
|
|
NoteDisplayMode.EdgelessOnly,
|
|
],
|
|
ignoreEmpty = false
|
|
) {
|
|
const notes = getNotesFromStore(store, modes);
|
|
return notes.flatMap(note => getHeadingBlocksFromNote(note, ignoreEmpty));
|
|
}
|