mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 14:28:51 +08:00
refactor(editor): remove page root service (#12048)
This commit is contained in:
@@ -78,8 +78,7 @@ export class ImageResizeManager {
|
|||||||
const rootComponent = getClosestRootBlockComponent(this._activeComponent);
|
const rootComponent = getClosestRootBlockComponent(this._activeComponent);
|
||||||
if (
|
if (
|
||||||
rootComponent &&
|
rootComponent &&
|
||||||
rootComponent.service.std.get(DocModeProvider).getEditorMode() ===
|
rootComponent.std.get(DocModeProvider).getEditorMode() === 'edgeless'
|
||||||
'edgeless'
|
|
||||||
) {
|
) {
|
||||||
const viewport = rootComponent.std.get(GfxControllerIdentifier).viewport;
|
const viewport = rootComponent.std.get(GfxControllerIdentifier).viewport;
|
||||||
this._zoom = viewport.zoom;
|
this._zoom = viewport.zoom;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
RootBlockSchema,
|
RootBlockSchema,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import type { BlockStdScope } from '@blocksuite/std';
|
import { BlockService, type BlockStdScope } from '@blocksuite/std';
|
||||||
import type {
|
import type {
|
||||||
GfxController,
|
GfxController,
|
||||||
GfxModel,
|
GfxModel,
|
||||||
@@ -30,10 +30,12 @@ import {
|
|||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
import clamp from 'lodash-es/clamp';
|
import clamp from 'lodash-es/clamp';
|
||||||
|
|
||||||
import { RootService } from '../root-service.js';
|
|
||||||
import { getCursorMode } from './utils/query.js';
|
import { getCursorMode } from './utils/query.js';
|
||||||
|
|
||||||
export class EdgelessRootService extends RootService implements SurfaceContext {
|
export class EdgelessRootService
|
||||||
|
extends BlockService
|
||||||
|
implements SurfaceContext
|
||||||
|
{
|
||||||
static override readonly flavour = RootBlockSchema.model.flavour;
|
static override readonly flavour = RootBlockSchema.model.flavour;
|
||||||
|
|
||||||
private readonly _surface: SurfaceBlockModel;
|
private readonly _surface: SurfaceBlockModel;
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ export * from './edgeless/edgeless-builtin-spec.js';
|
|||||||
export * from './edgeless/edgeless-root-spec.js';
|
export * from './edgeless/edgeless-root-spec.js';
|
||||||
export * from './edgeless/index.js';
|
export * from './edgeless/index.js';
|
||||||
export * from './page/page-root-block.js';
|
export * from './page/page-root-block.js';
|
||||||
export { PageRootService } from './page/page-root-service.js';
|
|
||||||
export * from './page/page-root-spec.js';
|
export * from './page/page-root-spec.js';
|
||||||
export * from './preview/preview-root-block.js';
|
export * from './preview/preview-root-block.js';
|
||||||
export { RootService } from './root-service.js';
|
|
||||||
export * from './types.js';
|
export * from './types.js';
|
||||||
export * from './utils/index.js';
|
export * from './utils/index.js';
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import { query } from 'lit/decorators.js';
|
|||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
|
|
||||||
import { PageKeyboardManager } from '../keyboard/keyboard-manager.js';
|
import { PageKeyboardManager } from '../keyboard/keyboard-manager.js';
|
||||||
import type { PageRootService } from './page-root-service.js';
|
|
||||||
|
|
||||||
const DOC_BLOCK_CHILD_PADDING = 24;
|
const DOC_BLOCK_CHILD_PADDING = 24;
|
||||||
const DOC_BOTTOM_PADDING = 32;
|
const DOC_BOTTOM_PADDING = 32;
|
||||||
@@ -49,10 +48,7 @@ function testClickOnBlankArea(
|
|||||||
return state.raw.clientX < blankLeft || state.raw.clientX > blankRight;
|
return state.raw.clientX < blankLeft || state.raw.clientX > blankRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageRootBlockComponent extends BlockComponent<
|
export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
||||||
RootBlockModel,
|
|
||||||
PageRootService
|
|
||||||
> {
|
|
||||||
static override styles = css`
|
static override styles = css`
|
||||||
editor-host:has(> affine-page-root, * > affine-page-root) {
|
editor-host:has(> affine-page-root, * > affine-page-root) {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import { RootBlockSchema } from '@blocksuite/affine-model';
|
|
||||||
|
|
||||||
import { RootService } from '../root-service.js';
|
|
||||||
|
|
||||||
export class PageRootService extends RootService {
|
|
||||||
static override readonly flavour = RootBlockSchema.model.flavour;
|
|
||||||
}
|
|
||||||
@@ -5,11 +5,9 @@ import { literal } from 'lit/static-html.js';
|
|||||||
|
|
||||||
import { PageClipboard } from '../clipboard/page-clipboard.js';
|
import { PageClipboard } from '../clipboard/page-clipboard.js';
|
||||||
import { CommonSpecs } from '../common-specs/index.js';
|
import { CommonSpecs } from '../common-specs/index.js';
|
||||||
import { PageRootService } from './page-root-service.js';
|
|
||||||
|
|
||||||
const PageCommonExtension: ExtensionType[] = [
|
const PageCommonExtension: ExtensionType[] = [
|
||||||
CommonSpecs,
|
CommonSpecs,
|
||||||
PageRootService,
|
|
||||||
ViewportElementExtension('.affine-page-viewport'),
|
ViewportElementExtension('.affine-page-viewport'),
|
||||||
].flat();
|
].flat();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import { RootBlockSchema } from '@blocksuite/affine-model';
|
|
||||||
import { BlockService } from '@blocksuite/std';
|
|
||||||
|
|
||||||
export abstract class RootService extends BlockService {
|
|
||||||
static override readonly flavour = RootBlockSchema.model.flavour;
|
|
||||||
}
|
|
||||||
@@ -270,12 +270,8 @@ import snapshot from '../snapshots/edgeless/surface-ref.spec.ts/surface-ref.json
|
|||||||
describe('clipboard', () => {
|
describe('clipboard', () => {
|
||||||
test('import surface-ref snapshot should render content correctly', async () => {
|
test('import surface-ref snapshot should render content correctly', async () => {
|
||||||
await setupEditor('page');
|
await setupEditor('page');
|
||||||
|
|
||||||
const pageRoot = getDocRootBlock(doc, editor, 'page');
|
|
||||||
const pageRootService = pageRoot.service;
|
|
||||||
|
|
||||||
const newDoc = await importFromSnapshot(
|
const newDoc = await importFromSnapshot(
|
||||||
pageRootService.collection,
|
doc.workspace,
|
||||||
snapshot as DocSnapshot
|
snapshot as DocSnapshot
|
||||||
);
|
);
|
||||||
expect(newDoc).toBeTruthy();
|
expect(newDoc).toBeTruthy();
|
||||||
|
|||||||
Reference in New Issue
Block a user