mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
refactor(editor): reduce getService (#10100)
This commit is contained in:
+4
-9
@@ -9,13 +9,10 @@ import { SettingRow } from '@affine/component/setting-components';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import type {
|
||||
EdgelessRootService,
|
||||
ShapeElementModel,
|
||||
ShapeName,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ShapeElementModel, ShapeName } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
DefaultTheme,
|
||||
EdgelessCRUDIdentifier,
|
||||
FontFamily,
|
||||
FontFamilyMap,
|
||||
FontStyle,
|
||||
@@ -354,18 +351,16 @@ export const ShapeSettings = () => {
|
||||
|
||||
const firstUpdate = useCallback(
|
||||
(doc: Store, editorHost: EditorHost) => {
|
||||
const edgelessService = editorHost.std.getService(
|
||||
'affine:page'
|
||||
) as EdgelessRootService;
|
||||
const surface = getSurfaceBlock(doc);
|
||||
if (!surface) return;
|
||||
const crud = editorHost.std.get(EdgelessCRUDIdentifier);
|
||||
doc.readonly = false;
|
||||
surface.getElementsByType('shape').forEach(node => {
|
||||
const shape = node as ShapeElementModel;
|
||||
const { shapeType, radius } = shape;
|
||||
const shapeName = getShapeName(shapeType, radius);
|
||||
const props = editorSetting.get(`shape:${shapeName}`);
|
||||
edgelessService.crud.updateElement(shape.id, props);
|
||||
crud.updateElement(shape.id, props);
|
||||
});
|
||||
doc.readonly = true;
|
||||
},
|
||||
|
||||
+14
-13
@@ -4,18 +4,20 @@ import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { AppThemeService } from '@affine/core/modules/theme';
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
BlockServiceIdentifier,
|
||||
BlockStdScope,
|
||||
LifeCycleWatcher,
|
||||
StdIdentifier,
|
||||
} from '@blocksuite/affine/block-std';
|
||||
import type { GfxPrimitiveElementModel } from '@blocksuite/affine/block-std/gfx';
|
||||
import type {
|
||||
EdgelessRootService,
|
||||
ThemeExtension,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
GfxControllerIdentifier,
|
||||
type GfxPrimitiveElementModel,
|
||||
} from '@blocksuite/affine/block-std/gfx';
|
||||
import type { ThemeExtension } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
ColorScheme,
|
||||
createSignalFromObservable,
|
||||
EdgelessCRUDIdentifier,
|
||||
SpecProvider,
|
||||
ThemeExtensionIdentifier,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
@@ -72,14 +74,12 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
const editorHost = editorHostRef.current;
|
||||
const doc = docRef.current;
|
||||
if (!editorHost || !doc) return;
|
||||
const edgelessService = editorHost.std.getService(
|
||||
'affine:page'
|
||||
) as EdgelessRootService;
|
||||
const crud = editorHost.std.get(EdgelessCRUDIdentifier);
|
||||
const elements = getElements(doc);
|
||||
const props = editorSetting.get(keyName) as any;
|
||||
doc.readonly = false;
|
||||
elements.forEach(element => {
|
||||
edgelessService.crud.updateElement(element.id, props);
|
||||
crud.updateElement(element.id, props);
|
||||
});
|
||||
doc.readonly = true;
|
||||
}, [editorSetting, getElements, keyName]);
|
||||
@@ -107,9 +107,10 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
}
|
||||
|
||||
// refresh viewport
|
||||
const edgelessService = editorHost.std.getService(
|
||||
'affine:page'
|
||||
) as EdgelessRootService;
|
||||
const edgelessService = editorHost.std.get(
|
||||
BlockServiceIdentifier('affine:page')
|
||||
);
|
||||
const gfx = editorHost.std.get(GfxControllerIdentifier);
|
||||
edgelessService.specSlots.viewConnected.once(({ component }) => {
|
||||
const edgelessBlock = component as any;
|
||||
doc.readonly = false;
|
||||
@@ -121,7 +122,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
doc.deleteBlock(frame);
|
||||
}
|
||||
const bound = boundMap.get(docName);
|
||||
bound && edgelessService.viewport.setViewportByBound(bound);
|
||||
bound && gfx.viewport.setViewportByBound(bound);
|
||||
doc.readonly = true;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user