mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
refactor(editor): merge get surface util (#9371)
This commit is contained in:
@@ -104,7 +104,7 @@ import {
|
||||
tryMoveNode,
|
||||
} from './utils/mindmap/utils';
|
||||
export * from './extensions';
|
||||
export { getLastPropsKey } from './utils/get-last-props-key';
|
||||
export { getLastPropsKey, getSurfaceBlock } from './utils';
|
||||
export type { Options } from './utils/rough/core';
|
||||
export { sortIndex } from './utils/sort';
|
||||
export { updateXYWH } from './utils/update-xywh.js';
|
||||
|
||||
@@ -2,6 +2,7 @@ import { BlockService } from '@blocksuite/block-std';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
|
||||
import { type SurfaceBlockModel, SurfaceBlockSchema } from './surface-model.js';
|
||||
import { getSurfaceBlock } from './utils/get-surface-block.js';
|
||||
|
||||
export class SurfaceBlockService extends BlockService {
|
||||
static override readonly flavour = SurfaceBlockSchema.model.flavour;
|
||||
@@ -15,9 +16,10 @@ export class SurfaceBlockService extends BlockService {
|
||||
override mounted(): void {
|
||||
super.mounted();
|
||||
|
||||
this.surface = this.doc.getBlockByFlavour(
|
||||
'affine:surface'
|
||||
)[0] as SurfaceBlockModel;
|
||||
const surface = getSurfaceBlock(this.doc);
|
||||
|
||||
// FIXME: BS-2271
|
||||
this.surface = surface!;
|
||||
|
||||
if (!this.surface) {
|
||||
const disposable = this.doc.slots.blockUpdated.on(payload => {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
|
||||
import type { SurfaceBlockModel } from '../surface-model';
|
||||
|
||||
export function getSurfaceBlock(doc: Doc) {
|
||||
const blocks = doc.getBlocksByFlavour('affine:surface');
|
||||
return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null;
|
||||
}
|
||||
@@ -34,3 +34,4 @@ export function normalizeWheelDeltaY(delta: number, zoom = 1) {
|
||||
}
|
||||
|
||||
export { getLastPropsKey } from './get-last-props-key';
|
||||
export { getSurfaceBlock } from './get-surface-block';
|
||||
|
||||
Reference in New Issue
Block a user