Files
AFFiNE-Mirror/blocksuite/affine/blocks/root/src/root-service.ts
T
Saul-Mirone 1f45cc5dec refactor(editor): unify directories naming (#11516)
**Directory Structure Changes**

- Renamed multiple block-related directories by removing the "block-" prefix:
  - `block-attachment` → `attachment`
  - `block-bookmark` → `bookmark`
  - `block-callout` → `callout`
  - `block-code` → `code`
  - `block-data-view` → `data-view`
  - `block-database` → `database`
  - `block-divider` → `divider`
  - `block-edgeless-text` → `edgeless-text`
  - `block-embed` → `embed`
2025-04-07 12:34:40 +00:00

49 lines
1.4 KiB
TypeScript

import { RootBlockSchema } from '@blocksuite/affine-model';
import {
getBlockSelectionsCommand,
getImageSelectionsCommand,
getSelectedBlocksCommand,
getTextSelectionCommand,
} from '@blocksuite/affine-shared/commands';
import type { BlockComponent } from '@blocksuite/std';
import { BlockService } from '@blocksuite/std';
import type { RootBlockComponent } from './types.js';
export abstract class RootService extends BlockService {
static override readonly flavour = RootBlockSchema.model.flavour;
get selectedBlocks() {
let result: BlockComponent[] = [];
this.std.command
.chain()
.tryAll(chain => [
chain.pipe(getTextSelectionCommand),
chain.pipe(getImageSelectionsCommand),
chain.pipe(getBlockSelectionsCommand),
])
.pipe(getSelectedBlocksCommand)
.pipe(({ selectedBlocks }) => {
if (!selectedBlocks) return;
result = selectedBlocks;
})
.run();
return result;
}
get selectedModels() {
return this.selectedBlocks.map(block => block.model);
}
get viewportElement() {
const rootId = this.std.store.root?.id;
if (!rootId) return null;
const rootComponent = this.std.view.getBlock(
rootId
) as RootBlockComponent | null;
if (!rootComponent) return null;
const viewportElement = rootComponent.viewportElement;
return viewportElement;
}
}