Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(drawing): fix dependencies (#2386)

Wenzhao Hu2689c1d19d20
diff --git a/packages/core/src/docs/data-model/subdocument.ts b/packages/core/src/docs/data-model/subdocument.ts
new file mode 100644
index 0000000000..5be305626a
--- /dev/null
+++ b/packages/core/src/docs/data-model/subdocument.ts
@@ -0,0 +1,17 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export const DEFAULT_DOCUMENT_SUB_COMPONENT_ID = '__default_document_sub_component_id20231101__';
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index b9a0db69f0..64a37c2653 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -16,6 +16,7 @@
import { installShims } from './common/shims';
+export { DEFAULT_DOCUMENT_SUB_COMPONENT_ID } from './docs/data-model/subdocument';
export { type UnitType, UnitModel, UniverInstanceType } from './common/unit';
export { Registry, RegistryAsMap } from './common/registry';
export { Univer } from './univer';
@@ -77,26 +78,6 @@ export { IConfigService } from './services/config/config.service';
export * from './services/context/context';
export { ContextService, IContextService } from './services/context/context.service';
export { ErrorService, type IError } from './services/error/error.service';
-export type { IOffset, IScale, ISize, ITransformState, IRotationSkewFlipTransform, IAbsoluteTransform, ISrcRect } from './services/drawing/drawing-interfaces';
-export {
- DEFAULT_DOCUMENT_SUB_COMPONENT_ID,
- type DrawingType,
- DrawingTypeEnum,
- type IDrawingSearch,
- type IDrawingSpace,
- type IDrawingParam,
- IDrawingManagerService,
- type IDrawingOrderUpdateParam,
- type IUnitDrawingService,
- type IDrawingMap,
- type IDrawingSubunitMap,
- type IDrawingOrderMapParam,
- type IDrawingGroupUpdateParam,
- type IDrawingVisibleParam,
- type IDrawingMapItemData,
- type IDrawingMapItem,
- ArrangeTypeEnum,
-} from './services/drawing/drawing-manager.service';
export { IUniverInstanceService } from './services/instance/instance.service';
export { LifecycleStages, OnLifecycle, runOnLifecycle } from './services/lifecycle/lifecycle';
export { LifecycleService } from './services/lifecycle/lifecycle.service';
diff --git a/packages/core/src/services/drawing/drawing-manager.service.ts b/packages/core/src/services/drawing/drawing-manager.service.ts
deleted file mode 100644
index 2871ae3427..0000000000
--- a/packages/core/src/services/drawing/drawing-manager.service.ts
+++ /dev/null
@@ -1,200 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { IDisposable } from '@wendellhu/redi';
-import { createIdentifier } from '@wendellhu/redi';
-import type { Observable } from 'rxjs';
-import type { Nullable } from '../../common/type-util';
-import type { ITransformState } from './drawing-interfaces';
-
-export const DEFAULT_DOCUMENT_SUB_COMPONENT_ID = '__default_document_sub_component_id20231101__';
-
-export enum ArrangeTypeEnum {
- forward,
- backward,
- front,
- back,
-}
-
-export enum DrawingTypeEnum {
- UNRECOGNIZED = -1,
- DRAWING_IMAGE = 0,
- DRAWING_SHAPE = 1,
- DRAWING_CHART = 2,
- DRAWING_TABLE = 3,
- DRAWING_SMART_ART = 4,
- DRAWING_VIDEO = 5,
- DRAWING_GROUP = 6,
- DRAWING_UNIT = 7,
- DRAWING_DOM = 8,
-}
-
-export type DrawingType = DrawingTypeEnum | number;
-
-export interface IDrawingSpace {
- unitId: string;
- subUnitId: string; //sheetId, pageId and so on, it has a default name in doc business
-}
-
-export interface IDrawingSearch extends IDrawingSpace {
- drawingId: string;
-}
-
-export interface IDrawingParam extends IDrawingSearch {
- drawingType: DrawingType;
- transform?: Nullable<ITransformState>;
- groupId?: string;
-}
-
-export interface IDrawingMap<T extends IDrawingParam> {
- [unitId: string]: IDrawingSubunitMap<T>;
-}
-
-export interface IDrawingSubunitMap<T extends IDrawingParam> {
- [subUnitId: string]: IDrawingMapItem<T>;
-}
-
-export interface IDrawingMapItemData<T> {
- [drawingId: string]: T;
-}
-export interface IDrawingMapItem<T extends IDrawingParam> {
- data: IDrawingMapItemData<T>;
- order: string[];
-}
-
-export interface IDrawingOrderMapParam {
- unitId: string;
- subUnitId: string;
- drawingIds: string[];
-}
-
-export interface IDrawingOrderUpdateParam extends IDrawingOrderMapParam {
- arrangeType: ArrangeTypeEnum;
-}
-
-export interface IDrawingGroupUpdateParam {
- parent: IDrawingParam;
- children: IDrawingParam[];
-}
-
-export interface IDrawingVisibleParam extends IDrawingSearch {
- visible: boolean;
-}
-
-/**
- * Responsible for operations related to drawing additions, deletions, and modifications,
- * including observers, events, broadcasting, and generating operations.
- */
-export interface IUnitNormalDrawingService<T extends IDrawingParam> {
- readonly remove$: Observable<IDrawingSearch[]>;
- readonly add$: Observable<IDrawingSearch[]>;
- readonly update$: Observable<IDrawingSearch[]>;
-
- readonly refreshTransform$: Observable<T[]>;
- readonly visible$: Observable<IDrawingVisibleParam[]>;
-
- readonly featurePluginUpdate$: Observable<T[]>;
-
- refreshTransform(updateParams: T[]): void;
-
- removeNotification(removeParams: IDrawingSearch[]): void;
- addNotification(insertParams: IDrawingSearch[]): void;
- updateNotification(updateParams: IDrawingSearch[]): void;
-
- refreshTransformNotification(refreshParams: T[]): void;
- visibleNotification(visibleParams: IDrawingVisibleParam[]): void;
-
- getBatchAddOp(insertParams: T[]): unknown;
- getBatchRemoveOp(removeParams: IDrawingSearch[]): unknown;
- getBatchUpdateOp(updateParams: T[]): unknown;
-
- featurePluginUpdateNotification(updateParams: T[]): void;
-}
-
-/**
- * Responsible for operations related to drawing focus, including observers,broadcasting
- */
-export interface IUnitFocusDrawingService {
- readonly focus$: Observable<IDrawingParam[]>;
-
- focusDrawing(params: Nullable<IDrawingSearch[]>): void;
- getFocusDrawings(): IDrawingParam[];
-}
-
-/**
- * Responsible for operations related to drawing grouping, including observers,broadcasting, and generating operations.
- */
-export interface IUnitGroupDrawingService {
- readonly group$: Observable<IDrawingGroupUpdateParam[]>;
- readonly ungroup$: Observable<IDrawingGroupUpdateParam[]>;
-
- readonly featurePluginGroupUpdate$: Observable<IDrawingGroupUpdateParam[]>;
- readonly featurePluginUngroupUpdate$: Observable<IDrawingGroupUpdateParam[]>;
-
- getGroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): unknown;
- getUngroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): unknown;
- groupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
- ungroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
- getDrawingsByGroup(groupParam: IDrawingSearch): IDrawingParam[];
-
- featurePluginGroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
- featurePluginUngroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
-}
-
-/**
- * Responsible for operations related to drawing order, including observers,broadcasting, and generating operations.
- */
-export interface IUnitOrderDrawingService {
-
- readonly order$: Observable<IDrawingOrderMapParam>;
-
- readonly featurePluginOrderUpdate$: Observable<IDrawingOrderUpdateParam>;
-
- orderNotification(orderParams: IDrawingOrderMapParam): void;
-
- getForwardDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
- getBackwardDrawingOp(orderParams: IDrawingOrderMapParam): unknown;
- getFrontDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
- getBackDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
- // replaceDrawingOrder(unitId: string, subUnitId: string, drawingIds: string[]): void;
- getDrawingOrder(unitId: string, subUnitId: string): string[];
- orderUpdateNotification(orderParams: IDrawingOrderMapParam): void;
-
- featurePluginOrderUpdateNotification(drawingOrderUpdateParam: IDrawingOrderUpdateParam): void;
-}
-
-export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNormalDrawingService<T>, IUnitFocusDrawingService, IUnitGroupDrawingService, IUnitOrderDrawingService, IDisposable {
- drawingManagerData: IDrawingMap<T>;
-
- dispose(): void;
-
- getDrawingDataForUnit(unitId: string): IDrawingSubunitMap<T>;
- removeDrawingDataForUnit(unitId: string): void;
- registerDrawingData(unitId: string, data: IDrawingSubunitMap<T>): void;
-
- getDrawingData(unitId: string, subUnitId: string): IDrawingMapItemData<T>;
-
- getDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T>;
- getOldDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T>;
-
- getDrawingOKey(oKey: string): Nullable<T>;
-
- applyJson1(unitId: string, subUnitId: string, jsonOp: unknown): void;
-}
-
-export interface IDrawingManagerService extends IUnitDrawingService<IDrawingParam> {}
-
-export const IDrawingManagerService = createIdentifier<IUnitDrawingService<IDrawingParam>>('univer.drawing-manager.service');
diff --git a/packages/core/src/shared/check-if-move.ts b/packages/core/src/shared/check-if-move.ts
index f7bfc47f37..53f445d7c3 100644
--- a/packages/core/src/shared/check-if-move.ts
+++ b/packages/core/src/shared/check-if-move.ts
@@ -15,7 +15,7 @@
*/
import type { Nullable } from '../common/type-util';
-import type { ITransformState } from '../services/drawing/drawing-interfaces';
+import type { ITransformState } from '../types/interfaces/i-document-data';
export const MOVE_BUFFER_VALUE = 2;
diff --git a/packages/core/src/shared/index.ts b/packages/core/src/shared/index.ts
index 8e9e4f261e..32bdc2dfe7 100644
--- a/packages/core/src/shared/index.ts
+++ b/packages/core/src/shared/index.ts
@@ -34,6 +34,7 @@ export { RefAlias } from './ref-alias';
export * from './row-col-iter';
export * from './sequence';
export * from './sort-rules';
+export * from './shape';
export * from './tools';
export * from './types';
export * from './debounce';
diff --git a/packages/core/src/services/drawing/drawing-interfaces.ts b/packages/core/src/shared/shape.ts
similarity index 79%
rename from packages/core/src/services/drawing/drawing-interfaces.ts
rename to packages/core/src/shared/shape.ts
index 89309ed282..9a8a71c021 100644
--- a/packages/core/src/services/drawing/drawing-interfaces.ts
+++ b/packages/core/src/shared/shape.ts
@@ -29,23 +29,9 @@ export interface IOffset {
top?: number;
}
-export interface IRotationSkewFlipTransform {
- angle?: number;
- skewX?: number;
- skewY?: number;
- flipX?: boolean;
- flipY?: boolean;
-}
-
export interface ISrcRect extends IOffset {
right?: number;
bottom?: number;
}
-export interface IAbsoluteTransform extends ISize, IOffset, IScale {
-
-}
-
-export interface ITransformState extends IAbsoluteTransform, IRotationSkewFlipTransform {
-
-}
+export interface IAbsoluteTransform extends ISize, IOffset, IScale {}
diff --git a/packages/core/src/types/enum/prst-geom-type.ts b/packages/core/src/types/enum/prst-geom-type.ts
index 0b706f0f4b..b32a9a39c1 100644
--- a/packages/core/src/types/enum/prst-geom-type.ts
+++ b/packages/core/src/types/enum/prst-geom-type.ts
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+// TODO@Jocs: should be moved out of core.
+
export enum BasicShapes {
Line = 'line',
LineInv = 'lineInv',
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.ts
index 938a52f309..96fa8381c0 100644
--- a/packages/core/src/types/interfaces/i-document-data.ts
+++ b/packages/core/src/types/interfaces/i-document-data.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import type { ISize } from '../../services/drawing/drawing-interfaces';
-import type { IDrawingParam } from '../../services/drawing/drawing-manager.service';
+import type { Nullable } from '../../common/type-util';
+import type { IAbsoluteTransform, ISize } from '../../shared/shape';
import type { BooleanNumber, CellValueType, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../enum';
import type { IExtraModelData } from './i-extra-model-data';
import type { IColorStyle, IStyleBase } from './i-style-data';
@@ -881,3 +881,65 @@ export enum PageOrientType {
PORTRAIT,
LANDSCAPE,
}
+
+// #region - tech dept
+
+// TODO@Jocs: these types are here because of drawing coupled into the core of the document's model, which
+// is an anti-pattern. After fixing the problem, these types should be removed.
+
+/** @deprecated */
+export enum ArrangeTypeEnum {
+ forward,
+ backward,
+ front,
+ back,
+}
+
+/** @deprecated */
+export enum DrawingTypeEnum {
+ UNRECOGNIZED = -1,
+ DRAWING_IMAGE = 0,
+ DRAWING_SHAPE = 1,
+ DRAWING_CHART = 2,
+ DRAWING_TABLE = 3,
+ DRAWING_SMART_ART = 4,
+ DRAWING_VIDEO = 5,
+ DRAWING_GROUP = 6,
+ DRAWING_UNIT = 7,
+ DRAWING_DOM = 8,
+}
+
+/** @deprecated */
+export type DrawingType = DrawingTypeEnum | number;
+
+/** @deprecated */
+export interface IDrawingSpace {
+ unitId: string;
+ subUnitId: string; //sheetId, pageId and so on, it has a default name in doc business
+}
+
+/** @deprecated */
+export interface IDrawingSearch extends IDrawingSpace {
+ drawingId: string;
+}
+
+/** @deprecated */
+export interface IRotationSkewFlipTransform {
+ angle?: number;
+ skewX?: number;
+ skewY?: number;
+ flipX?: boolean;
+ flipY?: boolean;
+}
+
+/** @deprecated */
+export interface ITransformState extends IAbsoluteTransform, IRotationSkewFlipTransform {}
+
+/** @deprecated */
+export interface IDrawingParam extends IDrawingSearch {
+ drawingType: DrawingType;
+ transform?: Nullable<ITransformState>;
+ groupId?: string;
+}
+
+// #endregion
diff --git a/packages/core/src/types/interfaces/i-image-io-service.ts b/packages/core/src/types/interfaces/i-image-io-service.ts
deleted file mode 100644
index 507f2378fc..0000000000
--- a/packages/core/src/types/interfaces/i-image-io-service.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { createIdentifier } from '@wendellhu/redi';
-import type { Observable } from 'rxjs';
-import type { Nullable } from '../../shared';
-
-export enum ImageSourceType {
- URL = 'URL',
- UUID = 'UUID',
- BASE64 = 'BASE64',
-}
-
-export enum ImageUploadStatusType {
- SUCCUSS = '0',
- ERROR_EXCEED_SIZE = '1',
- ERROR_IMAGE_TYPE = '2',
- ERROR_UPLOAD_COUNT_LIMIT = '3',
- ERROR_IMAGE = '4',
-}
-
-export interface IImageIoServiceParam {
- imageId: string;
- imageSourceType: ImageSourceType;
- source: string;
- base64Cache: string;
- status: ImageUploadStatusType;
-}
-
-export interface IImageIoService {
- change$: Observable<number>;
- setWaitCount(count: number): void;
-
- getImage(imageId: string): Promise<string>;
-
- saveImage(imageFile: File): Promise<Nullable<IImageIoServiceParam>>;
-
- getImageSourceCache(source: string, imageSourceType: ImageSourceType): Nullable<HTMLImageElement>;
- addImageSourceCache(source: string, imageSourceType: ImageSourceType, imageSource: Nullable<HTMLImageElement>): void;
-}
-
-export const IImageIoService = createIdentifier<IImageIoService>('core.image-io.service');
diff --git a/packages/core/src/types/interfaces/i-slide-data.ts b/packages/core/src/types/interfaces/i-slide-data.ts
index 9b5009a495..779ec9468c 100644
--- a/packages/core/src/types/interfaces/i-slide-data.ts
+++ b/packages/core/src/types/interfaces/i-slide-data.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { ISize, ITransformState } from '../../services/drawing/drawing-interfaces';
+import type { ISize } from '../../shared/shape';
import type { IKeyType, Nullable } from '../../shared/types';
import type { LocaleType, ThemeColorType } from '../enum';
import type { ShapeType } from '../enum/prst-geom-type';
-import type { ICustomBlock, IDocumentData, ILists } from './i-document-data';
+import type { ICustomBlock, IDocumentData, ILists, ITransformState } from './i-document-data';
import type { IExtraModelData } from './i-extra-model-data';
import type { IImageProperties } from './i-image-properties';
import type { IPlaceholder } from './i-placeholder';
diff --git a/packages/core/src/types/interfaces/index.ts b/packages/core/src/types/interfaces/index.ts
index 655ab8b08a..95ced0c1c7 100644
--- a/packages/core/src/types/interfaces/index.ts
+++ b/packages/core/src/types/interfaces/index.ts
@@ -31,4 +31,3 @@ export * from './i-univer-data';
export * from './i-workbook-data';
export * from './i-worksheet-data';
export * from './i-worksheet-order-data';
-export * from './i-image-io-service';
diff --git a/packages/docs-drawing-ui/src/commands/commands/group-doc-drawing.command.ts b/packages/docs-drawing-ui/src/commands/commands/group-doc-drawing.command.ts
index 366ca9f8b3..ef514df9c2 100644
--- a/packages/docs-drawing-ui/src/commands/commands/group-doc-drawing.command.ts
+++ b/packages/docs-drawing-ui/src/commands/commands/group-doc-drawing.command.ts
@@ -14,15 +14,14 @@
* limitations under the License.
*/
-import type { ICommand, IDrawingGroupUpdateParam } from '@univerjs/core';
+import type { ICommand } from '@univerjs/core';
import {
CommandType,
ICommandService,
IUndoRedoService,
} from '@univerjs/core';
-
import type { IAccessor } from '@wendellhu/redi';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import type { IDrawingGroupUpdateParam, IDrawingJsonUndo1 } from '@univerjs/drawing';
import { DocDrawingApplyType, IDocDrawingService, SetDocDrawingApplyMutation } from '@univerjs/docs-drawing';
import { ClearDocDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation';
import { groupToUngroup } from './utils';
diff --git a/packages/docs-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts b/packages/docs-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts
index 524fcdca4d..10ddd79c9f 100644
--- a/packages/docs-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts
+++ b/packages/docs-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts
@@ -14,14 +14,15 @@
* limitations under the License.
*/
-import type { ICommand, IDrawingOrderMapParam, Nullable } from '@univerjs/core';
-import { ArrangeTypeEnum,
+import type { ICommand, Nullable } from '@univerjs/core';
+import {
CommandType,
ICommandService,
IUndoRedoService,
} from '@univerjs/core';
import { DocDrawingApplyType, IDocDrawingService, SetDocDrawingApplyMutation } from '@univerjs/docs-drawing';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import type { IDrawingJsonUndo1, IDrawingOrderMapParam } from '@univerjs/drawing';
+import { ArrangeTypeEnum } from '@univerjs/drawing';
import type { IAccessor } from '@wendellhu/redi';
export interface ISetDrawingArrangeCommandParams extends IDrawingOrderMapParam {
diff --git a/packages/docs-drawing-ui/src/commands/commands/ungroup-doc-drawing.command.ts b/packages/docs-drawing-ui/src/commands/commands/ungroup-doc-drawing.command.ts
index 0db5e4d1ca..db6cf8c07f 100644
--- a/packages/docs-drawing-ui/src/commands/commands/ungroup-doc-drawing.command.ts
+++ b/packages/docs-drawing-ui/src/commands/commands/ungroup-doc-drawing.command.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { ICommand, IDrawingGroupUpdateParam } from '@univerjs/core';
+import type { ICommand } from '@univerjs/core';
import {
CommandType,
ICommandService,
@@ -22,7 +22,7 @@ import {
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import type { IDrawingGroupUpdateParam, IDrawingJsonUndo1 } from '@univerjs/drawing';
import { DocDrawingApplyType, IDocDrawingService, SetDocDrawingApplyMutation } from '@univerjs/docs-drawing';
import { ClearDocDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation';
import { ungroupToGroup } from './utils';
diff --git a/packages/docs-drawing-ui/src/commands/commands/utils.ts b/packages/docs-drawing-ui/src/commands/commands/utils.ts
index f7860ab2fe..a6db7d3da5 100644
--- a/packages/docs-drawing-ui/src/commands/commands/utils.ts
+++ b/packages/docs-drawing-ui/src/commands/commands/utils.ts
@@ -14,7 +14,8 @@
* limitations under the License.
*/
-import { DrawingTypeEnum, type IDrawingGroupUpdateParam, type IDrawingParam } from '@univerjs/core';
+import type { IDrawingGroupUpdateParam, IDrawingParam } from '@univerjs/drawing';
+import { DrawingTypeEnum } from '@univerjs/drawing';
import { getGroupState, transformObjectOutOfGroup } from '@univerjs/engine-render';
export function ungroupToGroup(ungroupParams: IDrawingGroupUpdateParam[]) {
diff --git a/packages/docs-drawing-ui/src/commands/operations/edit-doc-drawing.operation.ts b/packages/docs-drawing-ui/src/commands/operations/edit-doc-drawing.operation.ts
index e102320fb5..24aaa14c62 100644
--- a/packages/docs-drawing-ui/src/commands/operations/edit-doc-drawing.operation.ts
+++ b/packages/docs-drawing-ui/src/commands/operations/edit-doc-drawing.operation.ts
@@ -14,14 +14,15 @@
* limitations under the License.
*/
-import type { IDrawingSearch, IOperation } from '@univerjs/core';
+import type { IOperation } from '@univerjs/core';
import {
CommandType,
ICommandService,
- IDrawingManagerService,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
+import type { IDrawingSearch } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { SidebarDocDrawingOperation } from './open-drawing-panel.operation';
export const EditDocDrawingOperation: IOperation<IDrawingSearch> = {
diff --git a/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts b/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
index 1c002f4cff..c2ce2a8fb1 100644
--- a/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
+++ b/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
@@ -15,9 +15,10 @@
*/
import type { ICommand } from '@univerjs/core';
-import { CommandType, IDrawingManagerService, LocaleService } from '@univerjs/core';
+import { CommandType, LocaleService } from '@univerjs/core';
import { ISidebarService } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { COMPONENT_DOC_DRAWING_PANEL } from '../../views/doc-image-panel/component-name';
export interface IUIComponentCommandParams {
diff --git a/packages/docs-drawing-ui/src/controllers/doc-drawing-update.controller.ts b/packages/docs-drawing-ui/src/controllers/doc-drawing-update.controller.ts
index 2c3292ad96..014fc87952 100644
--- a/packages/docs-drawing-ui/src/controllers/doc-drawing-update.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/doc-drawing-update.controller.ts
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-import type { DocumentDataModel, ICommandInfo, IDocDrawingPosition, IImageIoServiceParam, Nullable } from '@univerjs/core';
-import { Disposable, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, IDrawingManagerService, IImageIoService, ImageUploadStatusType, IUniverInstanceService, LifecycleStages, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, OnLifecycle, PositionedObjectLayoutType, UniverInstanceType } from '@univerjs/core';
+import type { DocumentDataModel, ICommandInfo, IDocDrawingPosition, Nullable } from '@univerjs/core';
+import { Disposable, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, IUniverInstanceService, LifecycleStages, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, OnLifecycle, PositionedObjectLayoutType, UniverInstanceType } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
-import { DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, getImageSize } from '@univerjs/drawing';
+import type { IImageIoServiceParam } from '@univerjs/drawing';
+import { DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, DrawingTypeEnum, getImageSize, IDrawingManagerService, IImageIoService, ImageUploadStatusType } from '@univerjs/drawing';
import { IMessageService } from '@univerjs/ui';
import { MessageType } from '@univerjs/design';
import type { IDocDrawing } from '@univerjs/docs-drawing';
@@ -25,7 +26,7 @@ import { IDocDrawingService } from '@univerjs/docs-drawing';
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
import { docDrawingPositionToTransform, transformToDocDrawingPosition } from '@univerjs/docs-ui';
import type { Documents } from '@univerjs/engine-render';
-import { IRenderManagerService, ITextSelectionRenderManager, Liquid } from '@univerjs/engine-render';
+import { IRenderManagerService, Liquid } from '@univerjs/engine-render';
import type { IInsertImageOperationParams } from '../commands/operations/insert-image.operation';
import { InsertDocImageOperation } from '../commands/operations/insert-image.operation';
import type { IInsertDrawingCommandParams, ISetDrawingCommandParams } from '../commands/commands/interfaces';
@@ -41,7 +42,6 @@ export class DocDrawingUpdateController extends Disposable {
@ICommandService private readonly _commandService: ICommandService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
- @ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager,
@IImageIoService private readonly _imageIoService: IImageIoService,
@IDocDrawingService private readonly _sheetDrawingService: IDocDrawingService,
@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
diff --git a/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts b/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
index 95762e0b99..3adeb1db30 100644
--- a/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
@@ -15,14 +15,15 @@
*/
import type { DocumentDataModel, Nullable } from '@univerjs/core';
-import { FOCUSING_COMMON_DRAWINGS, IContextService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
+import { FOCUSING_COMMON_DRAWINGS, IContextService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';
-import { Inject, Injector } from '@wendellhu/redi';
+import { Inject } from '@wendellhu/redi';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';
import { takeUntil } from 'rxjs';
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { RemoveDocDrawingCommand } from '../commands/commands/remove-doc-drawing.command';
import { EditDocDrawingOperation } from '../commands/operations/edit-doc-drawing.operation';
@@ -31,7 +32,6 @@ export class DocDrawingPopupMenuController extends RxDisposable {
private _initImagePopupMenu = new Set<string>();
constructor(
- @Inject(Injector) private readonly _injector: Injector,
@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
@Inject(DocCanvasPopManagerService) private readonly _canvasPopManagerService: DocCanvasPopManagerService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
diff --git a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingAnchor.tsx b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingAnchor.tsx
index 1e453a9a4d..12451a2061 100644
--- a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingAnchor.tsx
+++ b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingAnchor.tsx
@@ -14,14 +14,15 @@
* limitations under the License.
*/
-import type { IDrawingParam, Nullable } from '@univerjs/core';
-import { ICommandService, IDrawingManagerService, LocaleService } from '@univerjs/core';
+import type { Nullable } from '@univerjs/core';
+import { ICommandService, LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import clsx from 'clsx';
import type { BaseObject } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { IDocDrawing } from '@univerjs/docs-drawing';
+import { IDrawingManagerService, type IDrawingParam } from '@univerjs/drawing';
import { SetDocDrawingCommand } from '../../commands/commands/set-doc-drawing.command';
import styles from './index.module.less';
diff --git a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx
index ded26e17f1..def4eed9fa 100644
--- a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx
+++ b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { IDrawingParam } from '@univerjs/core';
-import { IDrawingManagerService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { DrawingCommonPanel } from '@univerjs/drawing-ui';
+import type { IDrawingParam } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import styles from './index.module.less';
import { DocDrawingAnchor } from './DocDrawingAnchor';
diff --git a/packages/docs-drawing/src/commands/mutations/set-drawing-apply.mutation.ts b/packages/docs-drawing/src/commands/mutations/set-drawing-apply.mutation.ts
index d7e6c51bb7..73643f0882 100644
--- a/packages/docs-drawing/src/commands/mutations/set-drawing-apply.mutation.ts
+++ b/packages/docs-drawing/src/commands/mutations/set-drawing-apply.mutation.ts
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-import type { DocumentDataModel, IDrawingGroupUpdateParam, IDrawingOrderMapParam, IDrawings, IDrawingSearch, IMutation } from '@univerjs/core';
-import { CommandType, IDrawingManagerService, IUniverInstanceService } from '@univerjs/core';
-import type { IDrawingJson1Type } from '@univerjs/drawing';
+import type { DocumentDataModel, IDrawings, IMutation } from '@univerjs/core';
+import { CommandType, IUniverInstanceService } from '@univerjs/core';
+import type { IDrawingGroupUpdateParam, IDrawingJson1Type, IDrawingOrderMapParam, IDrawingSearch } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { IDocDrawingService } from '../../services/doc-drawing.service';
export enum DocDrawingApplyType {
diff --git a/packages/docs-drawing/src/controllers/doc-drawing.controller.ts b/packages/docs-drawing/src/controllers/doc-drawing.controller.ts
index e6aee6d1cb..942a55bc15 100644
--- a/packages/docs-drawing/src/controllers/doc-drawing.controller.ts
+++ b/packages/docs-drawing/src/controllers/doc-drawing.controller.ts
@@ -14,10 +14,12 @@
* limitations under the License.
*/
-import type { DocumentDataModel, IDrawingMapItem, IDrawingMapItemData, IDrawingSubunitMap } from '@univerjs/core';
-import { Disposable, ICommandService, IDrawingManagerService, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
+import type { DocumentDataModel } from '@univerjs/core';
+import { Disposable, ICommandService, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
import { docDrawingPositionToTransform } from '@univerjs/docs-ui';
+import type { IDrawingMapItem, IDrawingMapItemData, IDrawingSubunitMap } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { type IDocDrawing, IDocDrawingService } from '../services/doc-drawing.service';
import { SetDocDrawingApplyMutation } from '../commands/mutations/set-drawing-apply.mutation';
diff --git a/packages/docs-drawing/src/services/doc-drawing.service.ts b/packages/docs-drawing/src/services/doc-drawing.service.ts
index 3f2d3d7f7d..3f6ab1b291 100644
--- a/packages/docs-drawing/src/services/doc-drawing.service.ts
+++ b/packages/docs-drawing/src/services/doc-drawing.service.ts
@@ -14,20 +14,16 @@
* limitations under the License.
*/
-import type { IDocDrawingBase, IUnitDrawingService } from '@univerjs/core';
+import type { IDocDrawingBase } from '@univerjs/core';
import { createIdentifier } from '@wendellhu/redi';
-import { type IImageData, UnitDrawingService } from '@univerjs/drawing';
+import { type IImageData, type IUnitDrawingService, UnitDrawingService } from '@univerjs/drawing';
-export interface IDocImage extends IImageData, IDocDrawingBase {
-
-}
+export interface IDocImage extends IImageData, IDocDrawingBase {}
/**
* test type
*/
-export interface IDocShape extends IDocDrawingBase {
-
-}
+export interface IDocShape extends IDocDrawingBase {}
export type IDocDrawing = IDocImage | IDocShape;
diff --git a/packages/drawing-ui/src/controllers/drawing-update.controller.ts b/packages/drawing-ui/src/controllers/drawing-update.controller.ts
index 5bb9bf57a0..88765a5dfb 100644
--- a/packages/drawing-ui/src/controllers/drawing-update.controller.ts
+++ b/packages/drawing-ui/src/controllers/drawing-update.controller.ts
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-import type { DrawingTypeEnum, ICommandInfo, IDrawingGroupUpdateParam, IDrawingOrderMapParam, IDrawingParam, IDrawingSearch, ITransformState,
- Nullable } from '@univerjs/core';
+import type {
+ ICommandInfo,
+ Nullable,
+} from '@univerjs/core';
import {
checkIfMove,
Disposable,
ICommandService,
- IDrawingManagerService,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
@@ -28,7 +29,8 @@ import {
} from '@univerjs/core';
import type { BaseObject, IShapeProps, Scene, Shape } from '@univerjs/engine-render';
import { DRAWING_OBJECT_LAYER_INDEX, Group, IRenderManagerService, RENDER_CLASS_TYPE } from '@univerjs/engine-render';
-import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
+import type { DrawingTypeEnum, IDrawingGroupUpdateParam, IDrawingOrderMapParam, IDrawingParam, IDrawingSearch, ITransformState } from '@univerjs/drawing';
+import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import type { ISetDrawingAlignOperationParams } from '../commands/operations/drawing-align.operation';
import { AlignType, SetDrawingAlignOperation } from '../commands/operations/drawing-align.operation';
import { CloseImageCropOperation } from '../commands/operations/image-crop.operation';
diff --git a/packages/drawing-ui/src/controllers/image-cropper.controller.ts b/packages/drawing-ui/src/controllers/image-cropper.controller.ts
index 7ca79baeea..b608a4022d 100644
--- a/packages/drawing-ui/src/controllers/image-cropper.controller.ts
+++ b/packages/drawing-ui/src/controllers/image-cropper.controller.ts
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-import type { ICommandInfo, IDrawingSearch, ISrcRect, ITransformState, Nullable } from '@univerjs/core';
-import { checkIfMove, Disposable, ICommandService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, toDisposable } from '@univerjs/core';
-import type { IImageData } from '@univerjs/drawing';
-import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
+import type { ICommandInfo, ISrcRect, Nullable } from '@univerjs/core';
+import { checkIfMove, Disposable, ICommandService, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, toDisposable } from '@univerjs/core';
+import type { IDrawingSearch, IImageData, ITransformState } from '@univerjs/drawing';
+import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import { CURSOR_TYPE, degToRad, Image, IRenderManagerService, precisionTo, Vector2 } from '@univerjs/engine-render';
import { IMessageService } from '@univerjs/ui';
diff --git a/packages/drawing-ui/src/controllers/image-update.controller.ts b/packages/drawing-ui/src/controllers/image-update.controller.ts
index e7c6bd7182..8c89c57aaf 100644
--- a/packages/drawing-ui/src/controllers/image-update.controller.ts
+++ b/packages/drawing-ui/src/controllers/image-update.controller.ts
@@ -14,13 +14,9 @@
* limitations under the License.
*/
-import type { ICommandInfo, IDrawingSearch, Nullable } from '@univerjs/core';
+import type { ICommandInfo, Nullable } from '@univerjs/core';
import { Disposable,
- DrawingTypeEnum,
ICommandService,
- IDrawingManagerService,
- IImageIoService,
- ImageSourceType,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
@@ -28,8 +24,8 @@ import { Disposable,
} from '@univerjs/core';
import type { IImageProps, Scene } from '@univerjs/engine-render';
import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, Image, IRenderManagerService } from '@univerjs/engine-render';
-import type { IImageData } from '@univerjs/drawing';
-import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
+import type { IDrawingSearch, IImageData } from '@univerjs/drawing';
+import { DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, IImageIoService, ImageSourceType } from '@univerjs/drawing';
import { IDialogService } from '@univerjs/ui';
import { COMPONENT_IMAGE_VIEWER } from '../views/image-viewer/component-name';
import { ImageResetSizeOperation } from '../commands/operations/image-reset-size.operation';
diff --git a/packages/drawing-ui/src/controllers/utils.ts b/packages/drawing-ui/src/controllers/utils.ts
index 85061c19d2..bb303a9983 100644
--- a/packages/drawing-ui/src/controllers/utils.ts
+++ b/packages/drawing-ui/src/controllers/utils.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import type { IDrawingManagerService, IDrawingSearch, IUniverInstanceService, Nullable, Workbook } from '@univerjs/core';
+import type { IUniverInstanceService, Nullable, Workbook } from '@univerjs/core';
import { UniverInstanceType } from '@univerjs/core';
+import type { IDrawingManagerService, IDrawingSearch } from '@univerjs/drawing';
import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import { DRAWING_OBJECT_LAYER_INDEX, Group } from '@univerjs/engine-render';
diff --git a/packages/drawing-ui/src/utils/get-update-params.ts b/packages/drawing-ui/src/utils/get-update-params.ts
index 709b68ebd0..d29557de08 100644
--- a/packages/drawing-ui/src/utils/get-update-params.ts
+++ b/packages/drawing-ui/src/utils/get-update-params.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import { DrawingTypeEnum, type IDrawingManagerService, type IDrawingParam, type Nullable } from '@univerjs/core';
-import type { IImageData } from '@univerjs/drawing';
+import type { Nullable } from '@univerjs/core';
+import { DrawingTypeEnum, type IDrawingManagerService, type IDrawingParam, type IImageData } from '@univerjs/drawing';
import type { BaseObject, Image } from '@univerjs/engine-render';
export function getUpdateParams(objects: Map<string, BaseObject>, drawingManagerService: IDrawingManagerService): Nullable<IDrawingParam>[] {
diff --git a/packages/drawing-ui/src/views/panel/DrawingArrange.tsx b/packages/drawing-ui/src/views/panel/DrawingArrange.tsx
index acc8c42d56..7185bdbc3a 100644
--- a/packages/drawing-ui/src/views/panel/DrawingArrange.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingArrange.tsx
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-import type { IDrawingParam } from '@univerjs/core';
-import { ArrangeTypeEnum, ICommandService, IDrawingManagerService, LocaleService } from '@univerjs/core';
+import { LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { BottomSingle, MoveDownSingle, MoveUpSingle, TopmostSingle } from '@univerjs/icons';
import { Button } from '@univerjs/design';
import clsx from 'clsx';
+import type { IDrawingParam } from '@univerjs/drawing';
+import { ArrangeTypeEnum, IDrawingManagerService } from '@univerjs/drawing';
import styles from './index.module.less';
export interface IDrawingArrangeProps {
@@ -31,7 +32,6 @@ export interface IDrawingArrangeProps {
export const DrawingArrange = (props: IDrawingArrangeProps) => {
const { arrangeShow, drawings: focusDrawings } = props;
- const commandService = useDependency(ICommandService);
const localeService = useDependency(LocaleService);
const drawingManagerService = useDependency(IDrawingManagerService);
diff --git a/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx b/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
index d8cb6a1ab5..4b1c511672 100644
--- a/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { IDrawingParam } from '@univerjs/core';
-import { IDrawingManagerService, LocaleService } from '@univerjs/core';
+import { LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { IRenderManagerService } from '@univerjs/engine-render';
+import { IDrawingManagerService, type IDrawingParam } from '@univerjs/drawing';
import { getUpdateParams } from '../../utils/get-update-params';
import { DrawingArrange } from './DrawingArrange';
import { DrawingTransform } from './DrawingTransform';
diff --git a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
index 6107921c84..3cab56dfec 100644
--- a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
@@ -14,15 +14,17 @@
* limitations under the License.
*/
-import type { IDrawingGroupUpdateParam, IDrawingParam } from '@univerjs/core';
-import { DrawingTypeEnum, ICommandService, IDrawingManagerService, LocaleService, Tools } from '@univerjs/core';
+import { LocaleService, Tools } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { GroupSingle, UngroupSingle } from '@univerjs/icons';
import { Button } from '@univerjs/design';
import clsx from 'clsx';
import { getGroupState, IRenderManagerService, transformObjectOutOfGroup } from '@univerjs/engine-render';
+import type { IDrawingGroupUpdateParam, IDrawingParam } from '@univerjs/drawing';
+import { DrawingTypeEnum, IDrawingManagerService } from '@univerjs/drawing';
import { getUpdateParams } from '../../utils/get-update-params';
+
import styles from './index.module.less';
export interface IDrawingGroupProps {
@@ -31,7 +33,6 @@ export interface IDrawingGroupProps {
}
export const DrawingGroup = (props: IDrawingGroupProps) => {
- const commandService = useDependency(ICommandService);
const localeService = useDependency(LocaleService);
const renderManagerService = useDependency(IRenderManagerService);
const drawingManagerService = useDependency(IDrawingManagerService);
diff --git a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
index d4c1cc1005..f686e665eb 100644
--- a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
@@ -14,14 +14,16 @@
* limitations under the License.
*/
-import type { IDrawingParam, Nullable } from '@univerjs/core';
-import { debounce, ICommandService, IDrawingManagerService, LocaleService } from '@univerjs/core';
+import type { Nullable } from '@univerjs/core';
+import { debounce, LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { Checkbox, InputNumber } from '@univerjs/design';
import clsx from 'clsx';
import type { IChangeObserverConfig, Scene } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
+import type { IDrawingParam } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { getUpdateParams } from '../../utils/get-update-params';
import { MIN_DRAWING_HEIGHT_LIMIT, MIN_DRAWING_WIDTH_LIMIT, RANGE_DRAWING_ROTATION_LIMIT } from '../../utils/config';
import styles from './index.module.less';
@@ -34,7 +36,6 @@ export interface IDrawingTransformProps {
const INPUT_DEBOUNCE_TIME = 300;
export const DrawingTransform = (props: IDrawingTransformProps) => {
- const commandService = useDependency(ICommandService);
const localeService = useDependency(LocaleService);
const drawingManagerService = useDependency(IDrawingManagerService);
const renderManagerService = useDependency(IRenderManagerService);
diff --git a/packages/drawing/src/index.ts b/packages/drawing/src/index.ts
index 2a897298a4..2045879a0c 100644
--- a/packages/drawing/src/index.ts
+++ b/packages/drawing/src/index.ts
@@ -15,9 +15,30 @@
*/
export { DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_ALLOW_IMAGE_LIST } from './basics/config';
-export { DrawingManagerService, UnitDrawingService, type IDrawingJson1Type, type IDrawingJsonUndo1 } from './services/drawing-manager.service';
+export { DrawingManagerService, UnitDrawingService, type IDrawingJson1Type, type IDrawingJsonUndo1 } from './services/drawing-manager-impl.service';
export { getDrawingShapeKeyByDrawingSearch } from './utils/get-image-shape-key';
export { getImageSize } from './utils/get-image-size';
export { UniverDrawingPlugin } from './plugin';
export { type IImageData } from './models/image-model-interface';
-
+export { IImageIoService, type IImageIoServiceParam, ImageSourceType, ImageUploadStatusType } from './services/image-io.service';
+export { ImageIoService } from './services/image-io-impl.service';
+export type { ITransformState, IRotationSkewFlipTransform, ISrcRect } from './services/interface';
+export {
+ DEFAULT_DOCUMENT_SUB_COMPONENT_ID,
+ type DrawingType,
+ DrawingTypeEnum,
+ type IDrawingSearch,
+ type IDrawingSpace,
+ type IDrawingParam,
+ IDrawingManagerService,
+ type IDrawingOrderUpdateParam,
+ type IUnitDrawingService,
+ type IDrawingMap,
+ type IDrawingSubunitMap,
+ type IDrawingOrderMapParam,
+ type IDrawingGroupUpdateParam,
+ type IDrawingVisibleParam,
+ type IDrawingMapItemData,
+ type IDrawingMapItem,
+ ArrangeTypeEnum,
+} from './services/drawing-manager.service';
diff --git a/packages/drawing/src/models/image-model-interface.ts b/packages/drawing/src/models/image-model-interface.ts
index efc6d05cde..b1b61f3ab5 100644
--- a/packages/drawing/src/models/image-model-interface.ts
+++ b/packages/drawing/src/models/image-model-interface.ts
@@ -14,7 +14,10 @@
* limitations under the License.
*/
-import type { IDrawingParam, ImageSourceType, ISrcRect, Nullable, PresetGeometryType } from '@univerjs/core';
+import type { Nullable, PresetGeometryType } from '@univerjs/core';
+import type { IDrawingParam } from '../services/drawing-manager.service';
+import type { ImageSourceType } from '../services/image-io.service';
+import type { ISrcRect } from '../services/interface';
export interface IImageData extends IDrawingParam {
imageSourceType: ImageSourceType;
diff --git a/packages/drawing/src/plugin.ts b/packages/drawing/src/plugin.ts
index dd54731588..83b9e4e926 100644
--- a/packages/drawing/src/plugin.ts
+++ b/packages/drawing/src/plugin.ts
@@ -15,12 +15,14 @@
*/
import type { DependencyOverride } from '@univerjs/core';
-import { IDrawingManagerService, IImageIoService, LocaleService, mergeOverrideWithDependencies, Plugin } from '@univerjs/core';
+import { mergeOverrideWithDependencies, Plugin } from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
-import { ImageIoService } from './services/image-io.service';
-import { DrawingManagerService } from './services/drawing-manager.service';
+import { ImageIoService } from './services/image-io-impl.service';
+import { DrawingManagerService } from './services/drawing-manager-impl.service';
+import { IImageIoService } from './services/image-io.service';
+import { IDrawingManagerService } from './services/drawing-manager.service';
const PLUGIN_NAME = 'DRAWING_PLUGIN';
@@ -28,11 +30,8 @@ export class UniverDrawingPlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
- private _config: {
- override?: DependencyOverride;
- },
- @Inject(Injector) protected _injector: Injector,
- @Inject(LocaleService) private readonly _localeService: LocaleService
+ private _config: { override?: DependencyOverride },
+ @Inject(Injector) protected _injector: Injector
) {
super();
}
@@ -43,16 +42,11 @@ export class UniverDrawingPlugin extends Plugin {
private _initDependencies(injector: Injector): void {
const dependencies: Dependency[] = [
- // services
[IImageIoService, { useClass: ImageIoService }],
[IDrawingManagerService, { useClass: DrawingManagerService }],
- // controllers
- // [ImageController],
];
const dependency = mergeOverrideWithDependencies(dependencies, this._config?.override);
- dependency.forEach((d) => {
- this._injector.add(d);
- });
+ dependency.forEach((d) => injector.add(d));
}
}
diff --git a/packages/drawing/src/services/drawing-manager-impl.service.ts b/packages/drawing/src/services/drawing-manager-impl.service.ts
new file mode 100644
index 0000000000..6ac4ce38de
--- /dev/null
+++ b/packages/drawing/src/services/drawing-manager-impl.service.ts
@@ -0,0 +1,748 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { type Observable, Subject } from 'rxjs';
+import type { Nullable } from '@univerjs/core';
+import { sortRules, sortRulesByDesc } from '@univerjs/core';
+import type { JSONOp, JSONOpList } from 'ot-json1';
+import * as json1 from 'ot-json1';
+import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingParam, IDrawingSearch, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService } from './drawing-manager.service';
+
+export interface IDrawingJsonUndo1 {
+ undo: JSONOp;
+ redo: JSONOp;
+ unitId: string;
+ subUnitId: string;
+ objects: IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[];
+}
+
+export interface IDrawingJson1Type {
+ op: JSONOp | JSONOpList;
+ unitId: string;
+ subUnitId: string;
+ objects: IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[];
+}
+
+enum DrawingMapItemType {
+ data = 'data',
+ order = 'order',
+}
+
+/**
+ * unitId -> subUnitId -> drawingId -> drawingParam
+ */
+export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawingService<T> {
+ drawingManagerData: IDrawingMap<T> = {};
+
+ private _oldDrawingManagerData: IDrawingMap<T> = {};
+
+ private _focusDrawings: T[] = [];
+
+ private readonly _remove$ = new Subject<IDrawingSearch[]>();
+ readonly remove$ = this._remove$.asObservable();
+
+ private readonly _add$ = new Subject<IDrawingSearch[]>();
+ readonly add$ = this._add$.asObservable();
+
+ private readonly _update$ = new Subject<IDrawingSearch[]>();
+ readonly update$ = this._update$.asObservable();
+
+ private _order$ = new Subject<IDrawingOrderMapParam>();
+ readonly order$ = this._order$.asObservable();
+
+ private _group$ = new Subject<IDrawingGroupUpdateParam[]>();
+ readonly group$ = this._group$.asObservable();
+
+ private _ungroup$ = new Subject<IDrawingGroupUpdateParam[]>();
+ readonly ungroup$ = this._ungroup$.asObservable();
+
+ private _refreshTransform$ = new Subject<T[]>();
+ readonly refreshTransform$ = this._refreshTransform$.asObservable();
+
+ private _visible$ = new Subject<IDrawingVisibleParam[]>();
+ readonly visible$ = this._visible$.asObservable();
+
+ // private readonly _externalUpdate$ = new Subject<T[]>();
+ // readonly externalUpdate$ = this._externalUpdate$.asObservable();
+
+ private _focus$ = new Subject<T[]>();
+ focus$: Observable<T[]> = this._focus$.asObservable();
+
+ private readonly _featurePluginUpdate$ = new Subject<T[]>();
+ readonly featurePluginUpdate$: Observable<T[]> = this._featurePluginUpdate$.asObservable();
+
+ private readonly _featurePluginAdd$ = new Subject<T[]>();
+ readonly featurePluginAdd$: Observable<T[]> = this._featurePluginAdd$.asObservable();
+
+ private readonly _featurePluginRemove$ = new Subject<IDrawingSearch[]>();
+ readonly featurePluginRemove$: Observable<IDrawingSearch[]> = this._featurePluginRemove$.asObservable();
+
+ private readonly _featurePluginOrderUpdate$ = new Subject<IDrawingOrderUpdateParam>();
+ readonly featurePluginOrderUpdate$: Observable<IDrawingOrderUpdateParam> = this._featurePluginOrderUpdate$.asObservable();
+
+ private readonly _featurePluginGroupUpdate$ = new Subject<IDrawingGroupUpdateParam[]>();
+ readonly featurePluginGroupUpdate$: Observable<IDrawingGroupUpdateParam[]> = this._featurePluginGroupUpdate$.asObservable();
+
+ private readonly _featurePluginUngroupUpdate$ = new Subject<IDrawingGroupUpdateParam[]>();
+ readonly featurePluginUngroupUpdate$: Observable<IDrawingGroupUpdateParam[]> = this._featurePluginUngroupUpdate$.asObservable();
+
+ dispose(): void {
+ this._remove$.complete();
+ this._add$.complete();
+ this._update$.complete();
+ this._order$.complete();
+ this._focus$.complete();
+ this._featurePluginUpdate$.complete();
+ this._featurePluginAdd$.complete();
+ this._featurePluginRemove$.complete();
+ this._featurePluginOrderUpdate$.complete();
+
+ this.drawingManagerData = {};
+ this._oldDrawingManagerData = {};
+ }
+
+ visibleNotification(visibleParams: IDrawingVisibleParam[]) {
+ this._visible$.next(visibleParams);
+ }
+
+ refreshTransform(updateParams: T[]) {
+ updateParams.forEach((updateParam) => {
+ const drawing = this.getDrawingByParam(updateParam);
+ if (drawing == null) {
+ return;
+ }
+ const param = this._getCurrentBySearch(updateParam);
+ if (param == null) {
+ return;
+ }
+
+ param.transform = updateParam.transform;
+ });
+
+ this.refreshTransformNotification(updateParams);
+ }
+
+ getDrawingDataForUnit(unitId: string) {
+ return this.drawingManagerData[unitId];
+ }
+
+ removeDrawingDataForUnit(unitId: string) {
+ const subUnits = this.drawingManagerData[unitId];
+
+ if (subUnits == null) {
+ return;
+ }
+
+ delete this.drawingManagerData[unitId];
+
+ const drawings: IDrawingSearch[] = [];
+
+ Object.keys(subUnits).forEach((subUnitId) => {
+ const subUnit = subUnits[subUnitId];
+ if (subUnit?.data == null) {
+ return;
+ }
+ Object.keys(subUnit.data).forEach((drawingId) => {
+ drawings.push({ unitId, subUnitId, drawingId });
+ });
+ });
+ if (drawings.length > 0) {
+ this.removeNotification(drawings);
+ }
+ }
+
+ registerDrawingData(unitId: string, data: IDrawingSubunitMap<T>) {
+ this.drawingManagerData[unitId] = data;
+ const drawings: T[] = [];
+ Object.keys(data).forEach((subUnitId) => {
+ this._establishDrawingMap(unitId, subUnitId);
+
+ const subUnitData = data[subUnitId];
+
+ Object.keys(subUnitData.data).forEach((drawingId) => {
+ const drawing = subUnitData.data[drawingId];
+ drawings.push(drawing);
+ });
+ });
+
+ if (drawings.length > 0) {
+ this.addNotification(drawings);
+ }
+ }
+
+ getDrawingData(unitId: string, subUnitId: string) {
+ return this._getDrawingData(unitId, subUnitId);
+ }
+
+ getBatchAddOp(insertParams: T[]): IDrawingJsonUndo1 {
+ const objects: IDrawingSearch[] = [];
+ const ops: JSONOp[] = [];
+ const invertOps: JSONOp[] = [];
+ insertParams.forEach((insertParam) => {
+ const { op, invertOp } = this._addByParam(insertParam);
+ objects.push({ unitId: insertParam.unitId, subUnitId: insertParam.subUnitId, drawingId: insertParam.drawingId });
+ ops.push(op);
+ invertOps.push(invertOp);
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = invertOps.reduce(json1.type.compose, null);
+
+ // this._add$.next(objects);
+
+ const { unitId, subUnitId } = insertParams[0];
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects };
+ }
+
+ getBatchRemoveOp(removeParams: IDrawingSearch[]): IDrawingJsonUndo1 {
+ const ops: JSONOp[] = [];
+ const invertOps: JSONOp[] = [];
+ removeParams.forEach((removeParam) => {
+ const { op, invertOp } = this._removeByParam(removeParam);
+ ops.push(op);
+ invertOps.push(invertOp);
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = invertOps.reduce(json1.type.compose, null);
+
+ // this._remove$.next(objects);
+
+ const { unitId, subUnitId } = removeParams[0];
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: removeParams };
+ }
+
+ getBatchUpdateOp(updateParams: T[]): IDrawingJsonUndo1 {
+ const objects: IDrawingSearch[] = [];
+ const ops: JSONOp[] = [];
+ const invertOps: JSONOp[] = [];
+ updateParams.forEach((updateParam) => {
+ const { op, invertOp } = this._updateByParam(updateParam);
+ objects.push({ unitId: updateParam.unitId, subUnitId: updateParam.subUnitId, drawingId: updateParam.drawingId });
+ ops.push(op);
+ invertOps.push(invertOp);
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = invertOps.reduce(json1.type.compose, null);
+
+ // this._update$.next(objects);
+
+ const { unitId, subUnitId } = updateParams[0];
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects };
+ }
+
+ removeNotification(removeParams: IDrawingSearch[]) {
+ this._remove$.next(removeParams);
+ }
+
+ addNotification(insertParams: IDrawingSearch[]) {
+ this._add$.next(insertParams);
+ }
+
+ updateNotification(updateParams: IDrawingSearch[]) {
+ this._update$.next(updateParams);
+ }
+
+ orderNotification(orderParams: IDrawingOrderMapParam) {
+ this._order$.next(orderParams);
+ }
+
+ groupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void {
+ this._group$.next(groupParams);
+ }
+
+ ungroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void {
+ this._ungroup$.next(groupParams);
+ }
+
+ refreshTransformNotification(refreshParams: T[]) {
+ this._refreshTransform$.next(refreshParams);
+ }
+
+ getGroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): IDrawingJsonUndo1 {
+ const ops: JSONOp[] = [];
+ const { unitId, subUnitId } = groupParams[0].parent;
+ groupParams.forEach((groupParam) => {
+ ops.push(this._getGroupDrawingOp(groupParam));
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: groupParams };
+ }
+
+ getUngroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): IDrawingJsonUndo1 {
+ const ops: JSONOp[] = [];
+ const { unitId, subUnitId } = groupParams[0].parent;
+ groupParams.forEach((groupParam) => {
+ ops.push(this._getUngroupDrawingOp(groupParam));
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: groupParams };
+ }
+
+ getDrawingsByGroup(groupParam: IDrawingSearch): IDrawingParam[] {
+ const { unitId, subUnitId, drawingId } = groupParam;
+ const group = this.getDrawingByParam({ unitId, subUnitId, drawingId });
+
+ if (group == null) {
+ return [];
+ }
+
+ const drawings = this._getDrawingData(unitId, subUnitId);
+
+ const children: IDrawingParam[] = [];
+ Object.keys(drawings).forEach((key) => {
+ const drawing = drawings[key];
+ if (drawing.groupId === drawingId) {
+ children.push(drawing);
+ }
+ });
+
+ return children;
+ }
+
+ private _getGroupDrawingOp(groupParam: IDrawingGroupUpdateParam): JSONOp {
+ const { parent, children } = groupParam;
+ const { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent;
+
+ const ops: JSONOp[] = [];
+
+ ops.push(
+ json1.insertOp([groupUnitId, groupSubUnitId, DrawingMapItemType.data, groupDrawingId], parent as unknown as json1.Doc)
+ );
+ let maxChildIndex = Number.NEGATIVE_INFINITY;
+ children.forEach((child) => {
+ const { unitId, subUnitId, drawingId } = child;
+ const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
+ maxChildIndex = Math.max(maxChildIndex, index);
+ ops.push(
+ ...this._getUpdateParamCompareOp(child as T, this.getDrawingByParam({ unitId, subUnitId, drawingId }) as T)
+ );
+ });
+
+ if (maxChildIndex === Number.NEGATIVE_INFINITY) {
+ maxChildIndex = this._getDrawingOrder(groupUnitId, groupSubUnitId).length;
+ }
+
+ ops.push(
+ json1.insertOp([groupUnitId, groupSubUnitId, DrawingMapItemType.order, maxChildIndex], groupDrawingId)
+ );
+
+ return ops.reduce(json1.type.compose, null);
+ }
+
+ private _getUngroupDrawingOp(groupParam: IDrawingGroupUpdateParam): JSONOp {
+ const { parent, children } = groupParam;
+
+ const { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent;
+
+ const ops: JSONOp[] = [];
+ children.forEach((child) => {
+ const { unitId, subUnitId, drawingId } = child;
+ ops.push(
+ ...this._getUpdateParamCompareOp(child as T, this.getDrawingByParam({ unitId, subUnitId, drawingId }) as T)
+ );
+ });
+ ops.push(
+ json1.removeOp([groupUnitId, groupSubUnitId, DrawingMapItemType.data, groupDrawingId], true)
+ );
+ ops.push(
+ json1.removeOp([groupUnitId, groupSubUnitId, DrawingMapItemType.order, this._getDrawingOrder(groupUnitId, groupSubUnitId).indexOf(groupDrawingId)], true)
+ );
+
+ return ops.reduce(json1.type.compose, null);
+ }
+
+ applyJson1(unitId: string, subUnitId: string, jsonOp: JSONOp) {
+ this._establishDrawingMap(unitId, subUnitId);
+ // this._fillMissingFields(jsonOp);
+ this._oldDrawingManagerData = { ...this.drawingManagerData };
+ this.drawingManagerData = json1.type.apply(this.drawingManagerData as unknown as json1.Doc, jsonOp) as unknown as IDrawingMap<T>;
+ }
+
+ // private _fillMissingFields(jsonOp: JSONOp) {
+ // if (jsonOp == null) {
+ // return;
+ // }
+
+ // let object: { [key: string]: {} } = this.drawingManagerData;
+ // for (let i = 0; i < jsonOp.length; i++) {
+ // const op = jsonOp[i];
+ // if (Array.isArray(op)) {
+ // const opKey = op[0] as string;
+ // if (!(opKey in object)) {
+ // object[opKey] = null as unknown as never;
+ // }
+ // } else if (typeof op === 'string') {
+ // object = object[op];
+ // if (object == null) {
+ // break;
+ // }
+ // }
+ // }
+ // }
+
+ featurePluginUpdateNotification(updateParams: T[]) {
+ this._featurePluginUpdate$.next(updateParams);
+ }
+
+ featurePluginOrderUpdateNotification(drawingOrderUpdateParam: IDrawingOrderUpdateParam) {
+ this._featurePluginOrderUpdate$.next(drawingOrderUpdateParam);
+ }
+
+ featurePluginAddNotification(insertParams: T[]) {
+ this._featurePluginAdd$.next(insertParams);
+ }
+
+ featurePluginRemoveNotification(removeParams: IDrawingSearch[]) {
+ this._featurePluginRemove$.next(removeParams);
+ }
+
+ featurePluginGroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]) {
+ this._featurePluginGroupUpdate$.next(groupParams);
+ }
+
+ featurePluginUngroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]) {
+ this._featurePluginUngroupUpdate$.next(groupParams);
+ }
+
+ getDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T> {
+ return this._getCurrentBySearch(param);
+ }
+
+ getOldDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T> {
+ return this._getOldBySearch(param);
+ }
+
+ getDrawingOKey(oKey: string): Nullable<T> {
+ const [unitId, subUnitId, drawingId] = oKey.split('#-#');
+ return this._getCurrentBySearch({ unitId, subUnitId, drawingId });
+ }
+
+ focusDrawing(params: Nullable<IDrawingSearch[]>): void {
+ if (params == null) {
+ this._focusDrawings = [];
+ this._focus$.next([]);
+ return;
+ }
+
+ const drawingParams: T[] = [];
+ params.forEach((param) => {
+ const { unitId, subUnitId, drawingId } = param;
+ const item = this._getDrawingData(unitId, subUnitId)?.[drawingId];
+ if (item != null) {
+ drawingParams.push(item);
+ }
+ });
+
+ if (drawingParams.length > 0) {
+ this._focusDrawings = drawingParams;
+ this._focus$.next(drawingParams);
+ }
+ }
+
+ getFocusDrawings() {
+ const drawingParams: T[] = [];
+ this._focusDrawings.forEach((param) => {
+ const { unitId, subUnitId, drawingId } = param;
+ const item = this._getDrawingData(unitId, subUnitId)?.[drawingId];
+ if (item != null) {
+ drawingParams.push(item);
+ }
+ });
+ return drawingParams;
+ }
+
+ getDrawingOrder(unitId: string, subUnitId: string) {
+ return this._getDrawingOrder(unitId, subUnitId);
+ }
+
+ orderUpdateNotification(orderParams: IDrawingOrderMapParam) {
+ this._order$.next(orderParams);
+ }
+
+ getForwardDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
+ const { unitId, subUnitId, drawingIds } = orderParams;
+ const ops: JSONOp[] = [];
+ const orders = this.getDrawingOrder(unitId, subUnitId);
+ const newIds = [...drawingIds];
+ drawingIds.forEach((drawingId) => {
+ const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
+ if (index === -1 || index === orders.length - 1) {
+ return;
+ }
+ const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, index], [unitId, subUnitId, DrawingMapItemType.order, index + 1]);
+ ops.push(op);
+ if (!newIds.includes(orders[index + 1])) {
+ newIds.push(orders[index + 1]);
+ }
+ // this._moveDrawingOrder(unitId, subUnitId, drawingId, index + 1);
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ // this._order$.next({ unitId, subUnitId, drawingIds: this.getDrawingOrder(unitId, subUnitId) });
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
+ }
+
+ getBackwardDrawingOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
+ const { unitId, subUnitId, drawingIds } = orderParams;
+ const ops: JSONOp[] = [];
+ const orders = this.getDrawingOrder(unitId, subUnitId);
+ const newIds = [...drawingIds];
+ drawingIds.forEach((drawingId) => {
+ const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
+ if (index === -1 || index === 0) {
+ return;
+ }
+ // this._moveDrawingOrder(unitId, subUnitId, drawingId, index - 1);
+ const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, index], [unitId, subUnitId, DrawingMapItemType.order, index - 1]);
+ ops.push(op);
+ if (!newIds.includes(orders[index - 1])) {
+ newIds.push(orders[index - 1]);
+ }
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ // this._order$.next({ unitId, subUnitId, drawingIds: this.getDrawingOrder(unitId, subUnitId) });
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
+ }
+
+ getFrontDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
+ const { unitId, subUnitId, drawingIds } = orderParams;
+ const orderDrawingIds = this._getOrderFromSearchParams(unitId, subUnitId, drawingIds);
+ const newIds = [...drawingIds];
+ const orders = this.getDrawingOrder(unitId, subUnitId);
+ const ops: JSONOp[] = [];
+ orderDrawingIds.forEach((orderDrawingId) => {
+ const { drawingId } = orderDrawingId;
+ const index = this._getDrawingCount(unitId, subUnitId) - 1;
+
+ const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], [unitId, subUnitId, DrawingMapItemType.order, index]);
+ ops.push(op);
+ if (!newIds.includes(orders[index])) {
+ newIds.push(orders[index]);
+ }
+ // this._moveDrawingOrder(unitId, subUnitId, drawingId, index + 1);
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
+ }
+
+ getBackDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
+ const { unitId, subUnitId, drawingIds } = orderParams;
+ const orderSearchParams = this._getOrderFromSearchParams(unitId, subUnitId, drawingIds, true);
+ const newIds = [...drawingIds];
+ const orders = this.getDrawingOrder(unitId, subUnitId);
+ const ops: JSONOp[] = [];
+ orderSearchParams.forEach((orderSearchParam) => {
+ const { drawingId } = orderSearchParam;
+
+ const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], [unitId, subUnitId, DrawingMapItemType.order, 0]);
+ ops.push(op);
+
+ if (!newIds.includes(orders[0])) {
+ newIds.push(orders[0]);
+ }
+ });
+
+ const op = ops.reduce(json1.type.compose, null);
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
+ }
+
+ private _getDrawingCount(unitId: string, subUnitId: string) {
+ return this.getDrawingOrder(unitId, subUnitId).length || 0;
+ }
+
+ private _getOrderFromSearchParams(unitId: string, subUnitId: string, drawingIds: string[], isDesc = false) {
+ return drawingIds.map((drawingId) => {
+ const zIndex = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
+ return { drawingId, zIndex };
+ }).sort(isDesc === false ? sortRules : sortRulesByDesc);
+ }
+
+ private _hasDrawingOrder(searchParam: Nullable<IDrawingSearch>) {
+ if (searchParam == null) {
+ return -1;
+ }
+
+ const { unitId, subUnitId, drawingId } = searchParam;
+
+ this._establishDrawingMap(unitId, subUnitId);
+
+ return this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
+ }
+
+ private _getCurrentBySearch(searchParam: Nullable<IDrawingSearch>): Nullable<T> {
+ if (searchParam == null) {
+ return;
+ }
+ const { unitId, subUnitId, drawingId } = searchParam;
+ return this.drawingManagerData[unitId]?.[subUnitId]?.data?.[drawingId] as T;
+ }
+
+ private _getOldBySearch(searchParam: Nullable<IDrawingSearch>): Nullable<T> {
+ if (searchParam == null) {
+ return;
+ }
+ const { unitId, subUnitId, drawingId } = searchParam;
+ return this._oldDrawingManagerData[unitId]?.[subUnitId]?.data?.[drawingId] as T;
+ }
+
+ private _establishDrawingMap(unitId: string, subUnitId: string, drawingId?: string) {
+ if (!this.drawingManagerData[unitId]) {
+ this.drawingManagerData[unitId] = {};
+ }
+
+ if (!this.drawingManagerData[unitId][subUnitId]) {
+ this.drawingManagerData[unitId][subUnitId] = {
+ data: {},
+ order: [],
+ };
+ }
+
+ if (drawingId == null) {
+ return null;
+ }
+ return this.drawingManagerData[unitId][subUnitId].data?.[drawingId];
+ }
+
+ private _addByParam(insertParam: T): { op: JSONOp; invertOp: JSONOp } {
+ const { unitId, subUnitId, drawingId } = insertParam;
+
+ this._establishDrawingMap(unitId, subUnitId, drawingId);
+
+ // this.drawingManagerInfo[unitId][subUnitId][drawingId] = insertParam;
+
+ // this._insertDrawingOrder({ unitId, subUnitId, drawingId });
+
+ const op1 = json1.insertOp([unitId, subUnitId, DrawingMapItemType.data, drawingId], insertParam as unknown as json1.Doc);
+ const op2 = json1.insertOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).length], drawingId);
+ const op = [op1, op2].reduce(json1.type.compose, null);
+
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { op, invertOp };
+ }
+
+ private _removeByParam(searchParam: Nullable<IDrawingSearch>): { op: JSONOp; invertOp: JSONOp } {
+ if (searchParam == null) {
+ return { op: [], invertOp: [] };
+ }
+ const { unitId, subUnitId, drawingId } = searchParam;
+
+ const object = this._establishDrawingMap(unitId, subUnitId, drawingId);
+
+ if (object == null) {
+ return { op: [], invertOp: [] };
+ }
+
+ // delete this.drawingManagerInfo[unitId][subUnitId][drawingId];
+
+ // this._removeDrawingOrder({ unitId, subUnitId, drawingId });
+
+ const op1 = json1.removeOp([unitId, subUnitId, DrawingMapItemType.data, drawingId], true);
+ const op2 = json1.removeOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], true);
+ const op = [op1, op2].reduce(json1.type.compose, null);
+
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { op, invertOp };
+ }
+
+ private _updateByParam(updateParam: T): { op: JSONOp; invertOp: JSONOp } {
+ const { unitId, subUnitId, drawingId } = updateParam;
+
+ const object = this._establishDrawingMap(unitId, subUnitId, drawingId);
+
+ if (object == null) {
+ return { op: [], invertOp: [] };
+ }
+
+ // const oldParam = this._getCurrentBySearch({ unitId, subUnitId, drawingId });
+ // if (oldParam) {
+ // this._initializeDrawingData(updateParam, oldParam);
+ // }
+
+ const ops: JSONOp[] = this._getUpdateParamCompareOp(updateParam, object as T);
+
+ // this.drawingManagerInfo[unitId][subUnitId][drawingId] = newObject;
+
+ const op = ops.reduce(json1.type.compose, null);
+
+ const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+
+ return { op, invertOp };
+ }
+
+ // private _initializeDrawingData(updateParam: T, oldParam: T) {
+ // Object.keys(updateParam).forEach((key) => {
+ // if (!(key in oldParam)) {
+ // oldParam[key as keyof IDrawingParam] = null as unknown as never;
+ // }
+ // });
+ // }
+
+ private _getUpdateParamCompareOp(newParam: T, oldParam: T) {
+ const { unitId, subUnitId, drawingId } = newParam;
+ const ops: JSONOp[] = [];
+ Object.keys(newParam as IDrawingParam).forEach((key) => {
+ const newVal = newParam[key as keyof IDrawingParam];
+
+ const oldVal = oldParam[key as keyof IDrawingParam];
+
+ if (oldVal === newVal) {
+ return;
+ }
+
+ ops.push(
+ json1.replaceOp([unitId, subUnitId, DrawingMapItemType.data, drawingId, key], oldVal as unknown as json1.Doc, newVal as unknown as json1.Doc)
+ );
+ });
+ return ops;
+ }
+
+ private _getDrawingData(unitId: string, subUnitId: string) {
+ return this.drawingManagerData[unitId]?.[subUnitId]?.data || {};
+ }
+
+ private _getDrawingOrder(unitId: string, subUnitId: string) {
+ return this.drawingManagerData[unitId]?.[subUnitId]?.order || [];
+ }
+}
+
+export class DrawingManagerService extends UnitDrawingService<IDrawingParam> {}
diff --git a/packages/drawing/src/services/drawing-manager.service.ts b/packages/drawing/src/services/drawing-manager.service.ts
index 40171b483d..776f5600f0 100644
--- a/packages/drawing/src/services/drawing-manager.service.ts
+++ b/packages/drawing/src/services/drawing-manager.service.ts
@@ -14,734 +14,187 @@
* limitations under the License.
*/
-import { type Observable, Subject } from 'rxjs';
-import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingParam, IDrawingSearch, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService, Nullable } from '@univerjs/core';
-import { sortRules, sortRulesByDesc } from '@univerjs/core';
-import type { JSONOp, JSONOpList } from 'ot-json1';
-import * as json1 from 'ot-json1';
-
-export interface IDrawingJsonUndo1 {
- undo: JSONOp;
- redo: JSONOp;
- unitId: string;
- subUnitId: string;
- objects: IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[];
+import type { IDisposable } from '@wendellhu/redi';
+import { createIdentifier } from '@wendellhu/redi';
+import type { Observable } from 'rxjs';
+import type { Nullable } from '@univerjs/core';
+import type { ITransformState } from './interface';
+
+export const DEFAULT_DOCUMENT_SUB_COMPONENT_ID = '__default_document_sub_component_id20231101__';
+
+export enum ArrangeTypeEnum {
+ forward,
+ backward,
+ front,
+ back,
}
-export interface IDrawingJson1Type {
- op: JSONOp | JSONOpList;
- unitId: string;
- subUnitId: string;
- objects: IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[];
+export enum DrawingTypeEnum {
+ UNRECOGNIZED = -1,
+ DRAWING_IMAGE = 0,
+ DRAWING_SHAPE = 1,
+ DRAWING_CHART = 2,
+ DRAWING_TABLE = 3,
+ DRAWING_SMART_ART = 4,
+ DRAWING_VIDEO = 5,
+ DRAWING_GROUP = 6,
+ DRAWING_UNIT = 7,
+ DRAWING_DOM = 8,
}
-enum DrawingMapItemType {
- data = 'data',
- order = 'order',
-}
-
-/**
- * unitId -> subUnitId -> drawingId -> drawingParam
- */
-export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawingService<T> {
- drawingManagerData: IDrawingMap<T> = {};
-
- private _oldDrawingManagerData: IDrawingMap<T> = {};
-
- private _focusDrawings: T[] = [];
-
- private readonly _remove$ = new Subject<IDrawingSearch[]>();
- readonly remove$ = this._remove$.asObservable();
-
- private readonly _add$ = new Subject<IDrawingSearch[]>();
- readonly add$ = this._add$.asObservable();
-
- private readonly _update$ = new Subject<IDrawingSearch[]>();
- readonly update$ = this._update$.asObservable();
+export type DrawingType = DrawingTypeEnum | number;
- private _order$ = new Subject<IDrawingOrderMapParam>();
- readonly order$ = this._order$.asObservable();
-
- private _group$ = new Subject<IDrawingGroupUpdateParam[]>();
- readonly group$ = this._group$.asObservable();
-
- private _ungroup$ = new Subject<IDrawingGroupUpdateParam[]>();
- readonly ungroup$ = this._ungroup$.asObservable();
-
- private _refreshTransform$ = new Subject<T[]>();
- readonly refreshTransform$ = this._refreshTransform$.asObservable();
-
- private _visible$ = new Subject<IDrawingVisibleParam[]>();
- readonly visible$ = this._visible$.asObservable();
-
- // private readonly _externalUpdate$ = new Subject<T[]>();
- // readonly externalUpdate$ = this._externalUpdate$.asObservable();
-
- private _focus$ = new Subject<T[]>();
- focus$: Observable<T[]> = this._focus$.asObservable();
-
- private readonly _featurePluginUpdate$ = new Subject<T[]>();
- readonly featurePluginUpdate$: Observable<T[]> = this._featurePluginUpdate$.asObservable();
-
- private readonly _featurePluginAdd$ = new Subject<T[]>();
- readonly featurePluginAdd$: Observable<T[]> = this._featurePluginAdd$.asObservable();
-
- private readonly _featurePluginRemove$ = new Subject<IDrawingSearch[]>();
- readonly featurePluginRemove$: Observable<IDrawingSearch[]> = this._featurePluginRemove$.asObservable();
-
- private readonly _featurePluginOrderUpdate$ = new Subject<IDrawingOrderUpdateParam>();
- readonly featurePluginOrderUpdate$: Observable<IDrawingOrderUpdateParam> = this._featurePluginOrderUpdate$.asObservable();
-
- private readonly _featurePluginGroupUpdate$ = new Subject<IDrawingGroupUpdateParam[]>();
- readonly featurePluginGroupUpdate$: Observable<IDrawingGroupUpdateParam[]> = this._featurePluginGroupUpdate$.asObservable();
-
- private readonly _featurePluginUngroupUpdate$ = new Subject<IDrawingGroupUpdateParam[]>();
- readonly featurePluginUngroupUpdate$: Observable<IDrawingGroupUpdateParam[]> = this._featurePluginUngroupUpdate$.asObservable();
-
- dispose(): void {
- this._remove$.complete();
- this._add$.complete();
- this._update$.complete();
- this._order$.complete();
- this._focus$.complete();
- this._featurePluginUpdate$.complete();
- this._featurePluginAdd$.complete();
- this._featurePluginRemove$.complete();
- this._featurePluginOrderUpdate$.complete();
-
- this.drawingManagerData = {};
- this._oldDrawingManagerData = {};
- }
-
- visibleNotification(visibleParams: IDrawingVisibleParam[]) {
- this._visible$.next(visibleParams);
- }
-
- refreshTransform(updateParams: T[]) {
- updateParams.forEach((updateParam) => {
- const drawing = this.getDrawingByParam(updateParam);
- if (drawing == null) {
- return;
- }
- const param = this._getCurrentBySearch(updateParam);
- if (param == null) {
- return;
- }
+export interface IDrawingSpace {
+ unitId: string;
+ subUnitId: string; //sheetId, pageId and so on, it has a default name in doc business
+}
- param.transform = updateParam.transform;
- });
-
- this.refreshTransformNotification(updateParams);
- }
-
- getDrawingDataForUnit(unitId: string) {
- return this.drawingManagerData[unitId];
- }
-
- removeDrawingDataForUnit(unitId: string) {
- const subUnits = this.drawingManagerData[unitId];
-
- if (subUnits == null) {
- return;
- }
+export interface IDrawingSearch extends IDrawingSpace {
+ drawingId: string;
+}
- delete this.drawingManagerData[unitId];
+export interface IDrawingParam extends IDrawingSearch {
+ drawingType: DrawingType;
+ transform?: Nullable<ITransformState>;
+ groupId?: string;
+}
- const drawings: IDrawingSearch[] = [];
-
- Object.keys(subUnits).forEach((subUnitId) => {
- const subUnit = subUnits[subUnitId];
- if (subUnit?.data == null) {
- return;
- }
- Object.keys(subUnit.data).forEach((drawingId) => {
- drawings.push({ unitId, subUnitId, drawingId });
- });
- });
- if (drawings.length > 0) {
- this.removeNotification(drawings);
- }
- }
-
- registerDrawingData(unitId: string, data: IDrawingSubunitMap<T>) {
- this.drawingManagerData[unitId] = data;
- const drawings: T[] = [];
- Object.keys(data).forEach((subUnitId) => {
- this._establishDrawingMap(unitId, subUnitId);
-
- const subUnitData = data[subUnitId];
-
- Object.keys(subUnitData.data).forEach((drawingId) => {
- const drawing = subUnitData.data[drawingId];
- drawings.push(drawing);
- });
- });
-
- if (drawings.length > 0) {
- this.addNotification(drawings);
- }
- }
-
- getDrawingData(unitId: string, subUnitId: string) {
- return this._getDrawingData(unitId, subUnitId);
- }
-
- getBatchAddOp(insertParams: T[]): IDrawingJsonUndo1 {
- const objects: IDrawingSearch[] = [];
- const ops: JSONOp[] = [];
- const invertOps: JSONOp[] = [];
- insertParams.forEach((insertParam) => {
- const { op, invertOp } = this._addByParam(insertParam);
- objects.push({ unitId: insertParam.unitId, subUnitId: insertParam.subUnitId, drawingId: insertParam.drawingId });
- ops.push(op);
- invertOps.push(invertOp);
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = invertOps.reduce(json1.type.compose, null);
-
- // this._add$.next(objects);
-
- const { unitId, subUnitId } = insertParams[0];
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects };
- }
-
- getBatchRemoveOp(removeParams: IDrawingSearch[]): IDrawingJsonUndo1 {
- const ops: JSONOp[] = [];
- const invertOps: JSONOp[] = [];
- removeParams.forEach((removeParam) => {
- const { op, invertOp } = this._removeByParam(removeParam);
- ops.push(op);
- invertOps.push(invertOp);
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = invertOps.reduce(json1.type.compose, null);
-
- // this._remove$.next(objects);
-
- const { unitId, subUnitId } = removeParams[0];
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: removeParams };
- }
-
- getBatchUpdateOp(updateParams: T[]): IDrawingJsonUndo1 {
- const objects: IDrawingSearch[] = [];
- const ops: JSONOp[] = [];
- const invertOps: JSONOp[] = [];
- updateParams.forEach((updateParam) => {
- const { op, invertOp } = this._updateByParam(updateParam);
- objects.push({ unitId: updateParam.unitId, subUnitId: updateParam.subUnitId, drawingId: updateParam.drawingId });
- ops.push(op);
- invertOps.push(invertOp);
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = invertOps.reduce(json1.type.compose, null);
-
- // this._update$.next(objects);
-
- const { unitId, subUnitId } = updateParams[0];
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects };
- }
-
- removeNotification(removeParams: IDrawingSearch[]) {
- this._remove$.next(removeParams);
- }
-
- addNotification(insertParams: IDrawingSearch[]) {
- this._add$.next(insertParams);
- }
-
- updateNotification(updateParams: IDrawingSearch[]) {
- this._update$.next(updateParams);
- }
-
- orderNotification(orderParams: IDrawingOrderMapParam) {
- this._order$.next(orderParams);
- }
-
- groupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void {
- this._group$.next(groupParams);
- }
-
- ungroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void {
- this._ungroup$.next(groupParams);
- }
-
- refreshTransformNotification(refreshParams: T[]) {
- this._refreshTransform$.next(refreshParams);
- }
-
- getGroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): IDrawingJsonUndo1 {
- const ops: JSONOp[] = [];
- const { unitId, subUnitId } = groupParams[0].parent;
- groupParams.forEach((groupParam) => {
- ops.push(this._getGroupDrawingOp(groupParam));
- });
-
- const op = ops.reduce(json1.type.compose, null);
-
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: groupParams };
- }
-
- getUngroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): IDrawingJsonUndo1 {
- const ops: JSONOp[] = [];
- const { unitId, subUnitId } = groupParams[0].parent;
- groupParams.forEach((groupParam) => {
- ops.push(this._getUngroupDrawingOp(groupParam));
- });
-
- const op = ops.reduce(json1.type.compose, null);
-
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: groupParams };
- }
-
- getDrawingsByGroup(groupParam: IDrawingSearch): IDrawingParam[] {
- const { unitId, subUnitId, drawingId } = groupParam;
- const group = this.getDrawingByParam({ unitId, subUnitId, drawingId });
-
- if (group == null) {
- return [];
- }
-
- const drawings = this._getDrawingData(unitId, subUnitId);
-
- const children: IDrawingParam[] = [];
- Object.keys(drawings).forEach((key) => {
- const drawing = drawings[key];
- if (drawing.groupId === drawingId) {
- children.push(drawing);
- }
- });
-
- return children;
- }
-
- private _getGroupDrawingOp(groupParam: IDrawingGroupUpdateParam): JSONOp {
- const { parent, children } = groupParam;
- const { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent;
-
- const ops: JSONOp[] = [];
-
- ops.push(
- json1.insertOp([groupUnitId, groupSubUnitId, DrawingMapItemType.data, groupDrawingId], parent as unknown as json1.Doc)
- );
- let maxChildIndex = Number.NEGATIVE_INFINITY;
- children.forEach((child) => {
- const { unitId, subUnitId, drawingId } = child;
- const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
- maxChildIndex = Math.max(maxChildIndex, index);
- ops.push(
- ...this._getUpdateParamCompareOp(child as T, this.getDrawingByParam({ unitId, subUnitId, drawingId }) as T)
- );
- });
-
- if (maxChildIndex === Number.NEGATIVE_INFINITY) {
- maxChildIndex = this._getDrawingOrder(groupUnitId, groupSubUnitId).length;
- }
-
- ops.push(
- json1.insertOp([groupUnitId, groupSubUnitId, DrawingMapItemType.order, maxChildIndex], groupDrawingId)
- );
-
- return ops.reduce(json1.type.compose, null);
- }
-
- private _getUngroupDrawingOp(groupParam: IDrawingGroupUpdateParam): JSONOp {
- const { parent, children } = groupParam;
-
- const { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent;
-
- const ops: JSONOp[] = [];
- children.forEach((child) => {
- const { unitId, subUnitId, drawingId } = child;
- ops.push(
- ...this._getUpdateParamCompareOp(child as T, this.getDrawingByParam({ unitId, subUnitId, drawingId }) as T)
- );
- });
- ops.push(
- json1.removeOp([groupUnitId, groupSubUnitId, DrawingMapItemType.data, groupDrawingId], true)
- );
- ops.push(
- json1.removeOp([groupUnitId, groupSubUnitId, DrawingMapItemType.order, this._getDrawingOrder(groupUnitId, groupSubUnitId).indexOf(groupDrawingId)], true)
- );
-
- return ops.reduce(json1.type.compose, null);
- }
-
- applyJson1(unitId: string, subUnitId: string, jsonOp: JSONOp) {
- this._establishDrawingMap(unitId, subUnitId);
- // this._fillMissingFields(jsonOp);
- this._oldDrawingManagerData = { ...this.drawingManagerData };
- this.drawingManagerData = json1.type.apply(this.drawingManagerData as unknown as json1.Doc, jsonOp) as unknown as IDrawingMap<T>;
- }
-
- // private _fillMissingFields(jsonOp: JSONOp) {
- // if (jsonOp == null) {
- // return;
- // }
-
- // let object: { [key: string]: {} } = this.drawingManagerData;
- // for (let i = 0; i < jsonOp.length; i++) {
- // const op = jsonOp[i];
- // if (Array.isArray(op)) {
- // const opKey = op[0] as string;
- // if (!(opKey in object)) {
- // object[opKey] = null as unknown as never;
- // }
- // } else if (typeof op === 'string') {
- // object = object[op];
- // if (object == null) {
- // break;
- // }
- // }
- // }
- // }
-
- featurePluginUpdateNotification(updateParams: T[]) {
- this._featurePluginUpdate$.next(updateParams);
- }
-
- featurePluginOrderUpdateNotification(drawingOrderUpdateParam: IDrawingOrderUpdateParam) {
- this._featurePluginOrderUpdate$.next(drawingOrderUpdateParam);
- }
-
- featurePluginAddNotification(insertParams: T[]) {
- this._featurePluginAdd$.next(insertParams);
- }
-
- featurePluginRemoveNotification(removeParams: IDrawingSearch[]) {
- this._featurePluginRemove$.next(removeParams);
- }
-
- featurePluginGroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]) {
- this._featurePluginGroupUpdate$.next(groupParams);
- }
-
- featurePluginUngroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]) {
- this._featurePluginUngroupUpdate$.next(groupParams);
- }
-
- getDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T> {
- return this._getCurrentBySearch(param);
- }
-
- getOldDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T> {
- return this._getOldBySearch(param);
- }
-
- getDrawingOKey(oKey: string): Nullable<T> {
- const [unitId, subUnitId, drawingId] = oKey.split('#-#');
- return this._getCurrentBySearch({ unitId, subUnitId, drawingId });
- }
-
- focusDrawing(params: Nullable<IDrawingSearch[]>): void {
- if (params == null) {
- this._focusDrawings = [];
- this._focus$.next([]);
- return;
- }
-
- const drawingParams: T[] = [];
- params.forEach((param) => {
- const { unitId, subUnitId, drawingId } = param;
- const item = this._getDrawingData(unitId, subUnitId)?.[drawingId];
- if (item != null) {
- drawingParams.push(item);
- }
- });
-
- if (drawingParams.length > 0) {
- this._focusDrawings = drawingParams;
- this._focus$.next(drawingParams);
- }
- }
-
- getFocusDrawings() {
- const drawingParams: T[] = [];
- this._focusDrawings.forEach((param) => {
- const { unitId, subUnitId, drawingId } = param;
- const item = this._getDrawingData(unitId, subUnitId)?.[drawingId];
- if (item != null) {
- drawingParams.push(item);
- }
- });
- return drawingParams;
- }
-
- getDrawingOrder(unitId: string, subUnitId: string) {
- return this._getDrawingOrder(unitId, subUnitId);
- }
-
- orderUpdateNotification(orderParams: IDrawingOrderMapParam) {
- this._order$.next(orderParams);
- }
-
- getForwardDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
- const { unitId, subUnitId, drawingIds } = orderParams;
- const ops: JSONOp[] = [];
- const orders = this.getDrawingOrder(unitId, subUnitId);
- const newIds = [...drawingIds];
- drawingIds.forEach((drawingId) => {
- const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
- if (index === -1 || index === orders.length - 1) {
- return;
- }
- const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, index], [unitId, subUnitId, DrawingMapItemType.order, index + 1]);
- ops.push(op);
- if (!newIds.includes(orders[index + 1])) {
- newIds.push(orders[index + 1]);
- }
- // this._moveDrawingOrder(unitId, subUnitId, drawingId, index + 1);
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
-
- // this._order$.next({ unitId, subUnitId, drawingIds: this.getDrawingOrder(unitId, subUnitId) });
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
- }
-
- getBackwardDrawingOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
- const { unitId, subUnitId, drawingIds } = orderParams;
- const ops: JSONOp[] = [];
- const orders = this.getDrawingOrder(unitId, subUnitId);
- const newIds = [...drawingIds];
- drawingIds.forEach((drawingId) => {
- const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
- if (index === -1 || index === 0) {
- return;
- }
- // this._moveDrawingOrder(unitId, subUnitId, drawingId, index - 1);
- const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, index], [unitId, subUnitId, DrawingMapItemType.order, index - 1]);
- ops.push(op);
- if (!newIds.includes(orders[index - 1])) {
- newIds.push(orders[index - 1]);
- }
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
-
- // this._order$.next({ unitId, subUnitId, drawingIds: this.getDrawingOrder(unitId, subUnitId) });
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
- }
-
- getFrontDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
- const { unitId, subUnitId, drawingIds } = orderParams;
- const orderDrawingIds = this._getOrderFromSearchParams(unitId, subUnitId, drawingIds);
- const newIds = [...drawingIds];
- const orders = this.getDrawingOrder(unitId, subUnitId);
- const ops: JSONOp[] = [];
- orderDrawingIds.forEach((orderDrawingId) => {
- const { drawingId } = orderDrawingId;
- const index = this._getDrawingCount(unitId, subUnitId) - 1;
-
- const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], [unitId, subUnitId, DrawingMapItemType.order, index]);
- ops.push(op);
- if (!newIds.includes(orders[index])) {
- newIds.push(orders[index]);
- }
- // this._moveDrawingOrder(unitId, subUnitId, drawingId, index + 1);
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
- }
-
- getBackDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1 {
- const { unitId, subUnitId, drawingIds } = orderParams;
- const orderSearchParams = this._getOrderFromSearchParams(unitId, subUnitId, drawingIds, true);
- const newIds = [...drawingIds];
- const orders = this.getDrawingOrder(unitId, subUnitId);
- const ops: JSONOp[] = [];
- orderSearchParams.forEach((orderSearchParam) => {
- const { drawingId } = orderSearchParam;
-
- const op = json1.moveOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], [unitId, subUnitId, DrawingMapItemType.order, 0]);
- ops.push(op);
-
- if (!newIds.includes(orders[0])) {
- newIds.push(orders[0]);
- }
- });
-
- const op = ops.reduce(json1.type.compose, null);
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
-
- return { undo: invertOp, redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
- }
-
- private _getDrawingCount(unitId: string, subUnitId: string) {
- return this.getDrawingOrder(unitId, subUnitId).length || 0;
- }
-
- private _getOrderFromSearchParams(unitId: string, subUnitId: string, drawingIds: string[], isDesc = false) {
- return drawingIds.map((drawingId) => {
- const zIndex = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
- return { drawingId, zIndex };
- }).sort(isDesc === false ? sortRules : sortRulesByDesc);
- }
-
- private _hasDrawingOrder(searchParam: Nullable<IDrawingSearch>) {
- if (searchParam == null) {
- return -1;
- }
-
- const { unitId, subUnitId, drawingId } = searchParam;
-
- this._establishDrawingMap(unitId, subUnitId);
-
- return this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
- }
-
- private _getCurrentBySearch(searchParam: Nullable<IDrawingSearch>): Nullable<T> {
- if (searchParam == null) {
- return;
- }
- const { unitId, subUnitId, drawingId } = searchParam;
- return this.drawingManagerData[unitId]?.[subUnitId]?.data?.[drawingId] as T;
- }
-
- private _getOldBySearch(searchParam: Nullable<IDrawingSearch>): Nullable<T> {
- if (searchParam == null) {
- return;
- }
- const { unitId, subUnitId, drawingId } = searchParam;
- return this._oldDrawingManagerData[unitId]?.[subUnitId]?.data?.[drawingId] as T;
- }
+export interface IDrawingMap<T extends IDrawingParam> {
+ [unitId: string]: IDrawingSubunitMap<T>;
+}
- private _establishDrawingMap(unitId: string, subUnitId: string, drawingId?: string) {
- if (!this.drawingManagerData[unitId]) {
- this.drawingManagerData[unitId] = {};
- }
+export interface IDrawingSubunitMap<T extends IDrawingParam> {
+ [subUnitId: string]: IDrawingMapItem<T>;
+}
- if (!this.drawingManagerData[unitId][subUnitId]) {
- this.drawingManagerData[unitId][subUnitId] = {
- data: {},
- order: [],
- };
- }
-
- if (drawingId == null) {
- return null;
- }
- return this.drawingManagerData[unitId][subUnitId].data?.[drawingId];
- }
+export interface IDrawingMapItemData<T> {
+ [drawingId: string]: T;
+}
+export interface IDrawingMapItem<T extends IDrawingParam> {
+ data: IDrawingMapItemData<T>;
+ order: string[];
+}
- private _addByParam(insertParam: T): { op: JSONOp; invertOp: JSONOp } {
- const { unitId, subUnitId, drawingId } = insertParam;
+export interface IDrawingOrderMapParam {
+ unitId: string;
+ subUnitId: string;
+ drawingIds: string[];
+}
- this._establishDrawingMap(unitId, subUnitId, drawingId);
+export interface IDrawingOrderUpdateParam extends IDrawingOrderMapParam {
+ arrangeType: ArrangeTypeEnum;
+}
- // this.drawingManagerInfo[unitId][subUnitId][drawingId] = insertParam;
+export interface IDrawingGroupUpdateParam {
+ parent: IDrawingParam;
+ children: IDrawingParam[];
+}
- // this._insertDrawingOrder({ unitId, subUnitId, drawingId });
+export interface IDrawingVisibleParam extends IDrawingSearch {
+ visible: boolean;
+}
- const op1 = json1.insertOp([unitId, subUnitId, DrawingMapItemType.data, drawingId], insertParam as unknown as json1.Doc);
- const op2 = json1.insertOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).length], drawingId);
- const op = [op1, op2].reduce(json1.type.compose, null);
+/**
+ * Responsible for operations related to drawing additions, deletions, and modifications,
+ * including observers, events, broadcasting, and generating operations.
+ */
+export interface IUnitNormalDrawingService<T extends IDrawingParam> {
+ readonly remove$: Observable<IDrawingSearch[]>;
+ readonly add$: Observable<IDrawingSearch[]>;
+ readonly update$: Observable<IDrawingSearch[]>;
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+ readonly refreshTransform$: Observable<T[]>;
+ readonly visible$: Observable<IDrawingVisibleParam[]>;
- return { op, invertOp };
- }
+ readonly featurePluginUpdate$: Observable<T[]>;
- private _removeByParam(searchParam: Nullable<IDrawingSearch>): { op: JSONOp; invertOp: JSONOp } {
- if (searchParam == null) {
- return { op: [], invertOp: [] };
- }
- const { unitId, subUnitId, drawingId } = searchParam;
+ refreshTransform(updateParams: T[]): void;
- const object = this._establishDrawingMap(unitId, subUnitId, drawingId);
+ removeNotification(removeParams: IDrawingSearch[]): void;
+ addNotification(insertParams: IDrawingSearch[]): void;
+ updateNotification(updateParams: IDrawingSearch[]): void;
- if (object == null) {
- return { op: [], invertOp: [] };
- }
+ refreshTransformNotification(refreshParams: T[]): void;
+ visibleNotification(visibleParams: IDrawingVisibleParam[]): void;
- // delete this.drawingManagerInfo[unitId][subUnitId][drawingId];
+ getBatchAddOp(insertParams: T[]): unknown;
+ getBatchRemoveOp(removeParams: IDrawingSearch[]): unknown;
+ getBatchUpdateOp(updateParams: T[]): unknown;
- // this._removeDrawingOrder({ unitId, subUnitId, drawingId });
+ featurePluginUpdateNotification(updateParams: T[]): void;
+}
- const op1 = json1.removeOp([unitId, subUnitId, DrawingMapItemType.data, drawingId], true);
- const op2 = json1.removeOp([unitId, subUnitId, DrawingMapItemType.order, this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], true);
- const op = [op1, op2].reduce(json1.type.compose, null);
+/**
+ * Responsible for operations related to drawing focus, including observers,broadcasting
+ */
+export interface IUnitFocusDrawingService {
+ readonly focus$: Observable<IDrawingParam[]>;
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+ focusDrawing(params: Nullable<IDrawingSearch[]>): void;
+ getFocusDrawings(): IDrawingParam[];
+}
- return { op, invertOp };
- }
+/**
+ * Responsible for operations related to drawing grouping, including observers,broadcasting, and generating operations.
+ */
+export interface IUnitGroupDrawingService {
+ readonly group$: Observable<IDrawingGroupUpdateParam[]>;
+ readonly ungroup$: Observable<IDrawingGroupUpdateParam[]>;
- private _updateByParam(updateParam: T): { op: JSONOp; invertOp: JSONOp } {
- const { unitId, subUnitId, drawingId } = updateParam;
+ readonly featurePluginGroupUpdate$: Observable<IDrawingGroupUpdateParam[]>;
+ readonly featurePluginUngroupUpdate$: Observable<IDrawingGroupUpdateParam[]>;
- const object = this._establishDrawingMap(unitId, subUnitId, drawingId);
+ getGroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): unknown;
+ getUngroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): unknown;
+ groupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
+ ungroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
+ getDrawingsByGroup(groupParam: IDrawingSearch): IDrawingParam[];
- if (object == null) {
- return { op: [], invertOp: [] };
- }
+ featurePluginGroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
+ featurePluginUngroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
+}
- // const oldParam = this._getCurrentBySearch({ unitId, subUnitId, drawingId });
- // if (oldParam) {
- // this._initializeDrawingData(updateParam, oldParam);
- // }
+/**
+ * Responsible for operations related to drawing order, including observers,broadcasting, and generating operations.
+ */
+export interface IUnitOrderDrawingService {
- const ops: JSONOp[] = this._getUpdateParamCompareOp(updateParam, object as T);
+ readonly order$: Observable<IDrawingOrderMapParam>;
- // this.drawingManagerInfo[unitId][subUnitId][drawingId] = newObject;
+ readonly featurePluginOrderUpdate$: Observable<IDrawingOrderUpdateParam>;
- const op = ops.reduce(json1.type.compose, null);
+ orderNotification(orderParams: IDrawingOrderMapParam): void;
- const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData as unknown as json1.Doc);
+ getForwardDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
+ getBackwardDrawingOp(orderParams: IDrawingOrderMapParam): unknown;
+ getFrontDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
+ getBackDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
+ // replaceDrawingOrder(unitId: string, subUnitId: string, drawingIds: string[]): void;
+ getDrawingOrder(unitId: string, subUnitId: string): string[];
+ orderUpdateNotification(orderParams: IDrawingOrderMapParam): void;
- return { op, invertOp };
- }
+ featurePluginOrderUpdateNotification(drawingOrderUpdateParam: IDrawingOrderUpdateParam): void;
+}
- // private _initializeDrawingData(updateParam: T, oldParam: T) {
- // Object.keys(updateParam).forEach((key) => {
- // if (!(key in oldParam)) {
- // oldParam[key as keyof IDrawingParam] = null as unknown as never;
- // }
- // });
- // }
+export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNormalDrawingService<T>, IUnitFocusDrawingService, IUnitGroupDrawingService, IUnitOrderDrawingService, IDisposable {
+ drawingManagerData: IDrawingMap<T>;
- private _getUpdateParamCompareOp(newParam: T, oldParam: T) {
- const { unitId, subUnitId, drawingId } = newParam;
- const ops: JSONOp[] = [];
- Object.keys(newParam as IDrawingParam).forEach((key) => {
- const newVal = newParam[key as keyof IDrawingParam];
+ dispose(): void;
- const oldVal = oldParam[key as keyof IDrawingParam];
+ getDrawingDataForUnit(unitId: string): IDrawingSubunitMap<T>;
+ removeDrawingDataForUnit(unitId: string): void;
+ registerDrawingData(unitId: string, data: IDrawingSubunitMap<T>): void;
- if (oldVal === newVal) {
- return;
- }
+ getDrawingData(unitId: string, subUnitId: string): IDrawingMapItemData<T>;
- ops.push(
- json1.replaceOp([unitId, subUnitId, DrawingMapItemType.data, drawingId, key], oldVal as unknown as json1.Doc, newVal as unknown as json1.Doc)
- );
- });
- return ops;
- }
+ getDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T>;
+ getOldDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T>;
- private _getDrawingData(unitId: string, subUnitId: string) {
- return this.drawingManagerData[unitId]?.[subUnitId]?.data || {};
- }
+ getDrawingOKey(oKey: string): Nullable<T>;
- private _getDrawingOrder(unitId: string, subUnitId: string) {
- return this.drawingManagerData[unitId]?.[subUnitId]?.order || [];
- }
+ applyJson1(unitId: string, subUnitId: string, jsonOp: unknown): void;
}
-export class DrawingManagerService extends UnitDrawingService<IDrawingParam> {}
+export interface IDrawingManagerService extends IUnitDrawingService<IDrawingParam> {}
+
+export const IDrawingManagerService = createIdentifier<IUnitDrawingService<IDrawingParam>>('univer.drawing-manager.service');
diff --git a/packages/drawing/src/services/image-io-impl.service.ts b/packages/drawing/src/services/image-io-impl.service.ts
new file mode 100644
index 0000000000..e8c7542294
--- /dev/null
+++ b/packages/drawing/src/services/image-io-impl.service.ts
@@ -0,0 +1,99 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Nullable } from '@univerjs/core';
+import { Tools } from '@univerjs/core';
+import type { Observable } from 'rxjs';
+import { Subject } from 'rxjs';
+import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_ALLOW_SIZE } from '../basics/config';
+import type { IImageIoService, IImageIoServiceParam } from './image-io.service';
+import { ImageSourceType, ImageUploadStatusType } from './image-io.service';
+
+export class ImageIoService implements IImageIoService {
+ private _waitCount = 0;
+
+ private _change$ = new Subject<number>();
+ change$ = this._change$ as Observable<number>;
+
+ setWaitCount(count: number) {
+ this._waitCount = count;
+ this._change$.next(count);
+ }
+
+ private _imageSourceCache: Map<string, HTMLImageElement> = new Map();
+ getImageSourceCache(source: string, imageSourceType: ImageSourceType) {
+ if (imageSourceType === ImageSourceType.BASE64) {
+ const image = new Image();
+ image.src = source;
+ return image;
+ }
+ return this._imageSourceCache.get(source);
+ }
+
+ addImageSourceCache(source: string, imageSourceType: ImageSourceType, imageSource: Nullable<HTMLImageElement>) {
+ if (imageSourceType === ImageSourceType.BASE64 || imageSource == null) {
+ return;
+ }
+ this._imageSourceCache.set(source, imageSource);
+ }
+
+ async getImage(imageId: string): Promise<string> {
+ return Promise.resolve(imageId);
+ }
+
+ async saveImage(imageFile: File): Promise<Nullable<IImageIoServiceParam>> {
+ return new Promise((resolve, reject) => {
+ if (!DRAWING_IMAGE_ALLOW_IMAGE_LIST.includes(imageFile.type)) {
+ reject(new Error(ImageUploadStatusType.ERROR_IMAGE_TYPE));
+ this._decreaseWaiting();
+ return;
+ }
+ if (imageFile.size > DRAWING_IMAGE_ALLOW_SIZE) {
+ reject(new Error(ImageUploadStatusType.ERROR_EXCEED_SIZE));
+ this._decreaseWaiting();
+ return;
+ }
+ // 获取上传的图片的宽高
+ const reader = new FileReader();
+ reader.readAsDataURL(imageFile);
+ reader.onload = (evt) => {
+ const replaceSrc = evt.target?.result as string;
+ if (replaceSrc == null) {
+ reject(new Error(ImageUploadStatusType.ERROR_IMAGE));
+ this._decreaseWaiting();
+ return;
+ }
+
+ const imageId = Tools.generateRandomId(6);
+ resolve({
+ imageId,
+ imageSourceType: ImageSourceType.BASE64,
+ source: replaceSrc,
+ base64Cache: replaceSrc,
+ status: ImageUploadStatusType.SUCCUSS,
+ });
+
+ this._decreaseWaiting();
+ };
+ });
+ }
+
+ private _decreaseWaiting() {
+ this._waitCount -= 1;
+ this._change$.next(this._waitCount);
+ }
+}
+
diff --git a/packages/drawing/src/services/image-io.service.ts b/packages/drawing/src/services/image-io.service.ts
index 4a9308a2e6..9260504287 100644
--- a/packages/drawing/src/services/image-io.service.ts
+++ b/packages/drawing/src/services/image-io.service.ts
@@ -14,84 +14,42 @@
* limitations under the License.
*/
-import type { IImageIoService, IImageIoServiceParam, Nullable } from '@univerjs/core';
-import { ImageSourceType, ImageUploadStatusType, Tools } from '@univerjs/core';
+import type { Nullable } from '@univerjs/core';
+import { createIdentifier } from '@wendellhu/redi';
import type { Observable } from 'rxjs';
-import { Subject } from 'rxjs';
-import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_ALLOW_SIZE } from '../basics/config';
-export class ImageIoService implements IImageIoService {
- private _waitCount = 0;
-
- private _change$ = new Subject<number>();
- change$ = this._change$ as Observable<number>;
-
- setWaitCount(count: number) {
- this._waitCount = count;
- this._change$.next(count);
- }
-
- private _imageSourceCache: Map<string, HTMLImageElement> = new Map();
- getImageSourceCache(source: string, imageSourceType: ImageSourceType) {
- if (imageSourceType === ImageSourceType.BASE64) {
- const image = new Image();
- image.src = source;
- return image;
- }
- return this._imageSourceCache.get(source);
- }
+export enum ImageSourceType {
+ URL = 'URL',
+ UUID = 'UUID',
+ BASE64 = 'BASE64',
+}
- addImageSourceCache(source: string, imageSourceType: ImageSourceType, imageSource: Nullable<HTMLImageElement>) {
- if (imageSourceType === ImageSourceType.BASE64 || imageSource == null) {
- return;
- }
- this._imageSourceCache.set(source, imageSource);
- }
+export enum ImageUploadStatusType {
+ SUCCUSS = '0',
+ ERROR_EXCEED_SIZE = '1',
+ ERROR_IMAGE_TYPE = '2',
+ ERROR_UPLOAD_COUNT_LIMIT = '3',
+ ERROR_IMAGE = '4',
+}
- async getImage(imageId: string): Promise<string> {
- return Promise.resolve(imageId);
- }
+export interface IImageIoServiceParam {
+ imageId: string;
+ imageSourceType: ImageSourceType;
+ source: string;
+ base64Cache: string;
+ status: ImageUploadStatusType;
+}
- async saveImage(imageFile: File): Promise<Nullable<IImageIoServiceParam>> {
- return new Promise((resolve, reject) => {
- if (!DRAWING_IMAGE_ALLOW_IMAGE_LIST.includes(imageFile.type)) {
- reject(new Error(ImageUploadStatusType.ERROR_IMAGE_TYPE));
- this._decreaseWaiting();
- return;
- }
- if (imageFile.size > DRAWING_IMAGE_ALLOW_SIZE) {
- reject(new Error(ImageUploadStatusType.ERROR_EXCEED_SIZE));
- this._decreaseWaiting();
- return;
- }
- // 获取上传的图片的宽高
- const reader = new FileReader();
- reader.readAsDataURL(imageFile);
- reader.onload = (evt) => {
- const replaceSrc = evt.target?.result as string;
- if (replaceSrc == null) {
- reject(new Error(ImageUploadStatusType.ERROR_IMAGE));
- this._decreaseWaiting();
- return;
- }
+export interface IImageIoService {
+ change$: Observable<number>;
+ setWaitCount(count: number): void;
- const imageId = Tools.generateRandomId(6);
- resolve({
- imageId,
- imageSourceType: ImageSourceType.BASE64,
- source: replaceSrc,
- base64Cache: replaceSrc,
- status: ImageUploadStatusType.SUCCUSS,
- });
+ getImage(imageId: string): Promise<string>;
- this._decreaseWaiting();
- };
- });
- }
+ saveImage(imageFile: File): Promise<Nullable<IImageIoServiceParam>>;
- private _decreaseWaiting() {
- this._waitCount -= 1;
- this._change$.next(this._waitCount);
- }
+ getImageSourceCache(source: string, imageSourceType: ImageSourceType): Nullable<HTMLImageElement>;
+ addImageSourceCache(source: string, imageSourceType: ImageSourceType, imageSource: Nullable<HTMLImageElement>): void;
}
+export const IImageIoService = createIdentifier<IImageIoService>('core.image-io.service');
diff --git a/packages/drawing/src/services/interface.ts b/packages/drawing/src/services/interface.ts
new file mode 100644
index 0000000000..93c38326b6
--- /dev/null
+++ b/packages/drawing/src/services/interface.ts
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IAbsoluteTransform, IOffset } from '@univerjs/core';
+
+export interface IRotationSkewFlipTransform {
+ angle?: number;
+ skewX?: number;
+ skewY?: number;
+ flipX?: boolean;
+ flipY?: boolean;
+}
+
+export interface ISrcRect extends IOffset {
+ right?: number;
+ bottom?: number;
+}
+
+export interface ITransformState extends IAbsoluteTransform, IRotationSkewFlipTransform {}
diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts
index 0abd5e193b..ea392b6770 100644
--- a/packages/engine-formula/src/services/current-data.service.ts
+++ b/packages/engine-formula/src/services/current-data.service.ts
@@ -35,8 +35,6 @@ import type {
} from '../basics/common';
import { convertUnitDataToRuntime } from '../basics/runtime';
-export const DEFAULT_DOCUMENT_SUB_COMPONENT_ID = '__default_document_sub_component_id20231101__';
-
export interface IFormulaCurrentConfigService {
load(config: IFormulaDatasetConfig): void;
diff --git a/packages/sheets-drawing-ui/src/commands/commands/group-sheet-drawing.command.ts b/packages/sheets-drawing-ui/src/commands/commands/group-sheet-drawing.command.ts
index f0660fedb0..7f5eb486e4 100644
--- a/packages/sheets-drawing-ui/src/commands/commands/group-sheet-drawing.command.ts
+++ b/packages/sheets-drawing-ui/src/commands/commands/group-sheet-drawing.command.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { ICommand, IDrawingGroupUpdateParam } from '@univerjs/core';
+import type { ICommand } from '@univerjs/core';
import {
CommandType,
ICommandService,
@@ -23,7 +23,7 @@ import {
import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';
import type { IAccessor } from '@wendellhu/redi';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import type { IDrawingGroupUpdateParam, IDrawingJsonUndo1 } from '@univerjs/drawing';
import { ClearSheetDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation';
import { groupToUngroup } from './utils';
diff --git a/packages/sheets-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts b/packages/sheets-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts
index 89cd48b941..e607364b4e 100644
--- a/packages/sheets-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts
+++ b/packages/sheets-drawing-ui/src/commands/commands/set-drawing-arrange.command.ts
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-import type { ICommand, IDrawingOrderMapParam, Nullable } from '@univerjs/core';
-import { ArrangeTypeEnum,
+import type { ICommand, Nullable } from '@univerjs/core';
+import {
CommandType,
ICommandService,
IUndoRedoService,
} from '@univerjs/core';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import type { IDrawingJsonUndo1, IDrawingOrderMapParam } from '@univerjs/drawing';
+import { ArrangeTypeEnum } from '@univerjs/drawing';
import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';
import type { IAccessor } from '@wendellhu/redi';
diff --git a/packages/sheets-drawing-ui/src/commands/commands/ungroup-sheet-drawing.command.ts b/packages/sheets-drawing-ui/src/commands/commands/ungroup-sheet-drawing.command.ts
index bda5b09973..1f92d41e1e 100644
--- a/packages/sheets-drawing-ui/src/commands/commands/ungroup-sheet-drawing.command.ts
+++ b/packages/sheets-drawing-ui/src/commands/commands/ungroup-sheet-drawing.command.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { ICommand, IDrawingGroupUpdateParam } from '@univerjs/core';
+import type { ICommand } from '@univerjs/core';
import {
CommandType,
ICommandService,
@@ -23,7 +23,7 @@ import {
import { DrawingApplyType, ISheetDrawingService, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';
import type { IAccessor } from '@wendellhu/redi';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import type { IDrawingGroupUpdateParam, IDrawingJsonUndo1 } from '@univerjs/drawing';
import { ClearSheetDrawingTransformerOperation } from '../operations/clear-drawing-transformer.operation';
import { ungroupToGroup } from './utils';
diff --git a/packages/sheets-drawing-ui/src/commands/commands/utils.ts b/packages/sheets-drawing-ui/src/commands/commands/utils.ts
index f7860ab2fe..c240613861 100644
--- a/packages/sheets-drawing-ui/src/commands/commands/utils.ts
+++ b/packages/sheets-drawing-ui/src/commands/commands/utils.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { DrawingTypeEnum, type IDrawingGroupUpdateParam, type IDrawingParam } from '@univerjs/core';
+import { DrawingTypeEnum, type IDrawingGroupUpdateParam, type IDrawingParam } from '@univerjs/drawing';
import { getGroupState, transformObjectOutOfGroup } from '@univerjs/engine-render';
export function ungroupToGroup(ungroupParams: IDrawingGroupUpdateParam[]) {
diff --git a/packages/sheets-drawing-ui/src/commands/operations/edit-sheet-drawing.operation.ts b/packages/sheets-drawing-ui/src/commands/operations/edit-sheet-drawing.operation.ts
index db1153741e..44a08157e6 100644
--- a/packages/sheets-drawing-ui/src/commands/operations/edit-sheet-drawing.operation.ts
+++ b/packages/sheets-drawing-ui/src/commands/operations/edit-sheet-drawing.operation.ts
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-import type { IDrawingSearch, IOperation } from '@univerjs/core';
+import type { IOperation } from '@univerjs/core';
import {
CommandType,
ICommandService,
- IDrawingManagerService,
-
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
+import type { IDrawingSearch } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { SidebarSheetDrawingOperation } from './open-drawing-panel.operation';
export const EditSheetDrawingOperation: IOperation<IDrawingSearch> = {
diff --git a/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts b/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
index beb649f6bc..9ccd62f365 100644
--- a/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
+++ b/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
@@ -15,10 +15,11 @@
*/
import type { ICommand } from '@univerjs/core';
-import { CommandType, IDrawingManagerService, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import { CommandType, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { ISidebarService } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
import { getSheetCommandTarget } from '@univerjs/sheets';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { COMPONENT_SHEET_DRAWING_PANEL } from '../../views/sheet-image-panel/component-name';
export interface IUIComponentCommandParams {
diff --git a/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts b/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
index b8679e15e1..e4cd692e3c 100644
--- a/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
@@ -15,7 +15,7 @@
*/
import type { Nullable, Workbook } from '@univerjs/core';
-import { FOCUSING_COMMON_DRAWINGS, IContextService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
+import { FOCUSING_COMMON_DRAWINGS, IContextService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import type { BaseObject, Scene } from '@univerjs/engine-render';
@@ -23,21 +23,26 @@ import { IRenderManagerService } from '@univerjs/engine-render';
import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';
import { SheetCanvasPopManagerService } from '@univerjs/sheets-ui';
import { takeUntil } from 'rxjs';
+import { IDrawingManagerService } from '@univerjs/drawing';
+import { BuiltInUIPart, IUIPartsService } from '@univerjs/ui';
+import { connectInjector } from '@wendellhu/redi/react-bindings';
+
import { RemoveSheetDrawingCommand } from '../commands/commands/remove-sheet-drawing.command';
import { EditSheetDrawingOperation } from '../commands/operations/edit-sheet-drawing.operation';
+import { UploadLoading } from '../views/upload-loading/UploadLoading';
@OnLifecycle(LifecycleStages.Steady, DrawingPopupMenuController)
export class DrawingPopupMenuController extends RxDisposable {
private _initImagePopupMenu = new Set<string>();
constructor(
- @Inject(Injector) private readonly _injector: Injector,
+ @Inject(Injector) private _injector: Injector,
@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
@Inject(SheetCanvasPopManagerService) private readonly _canvasPopManagerService: SheetCanvasPopManagerService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
- @IContextService private readonly _contextService: IContextService
-
+ @IContextService private readonly _contextService: IContextService,
+ @Inject(IUIPartsService) private readonly _uiPartsService: IUIPartsService
) {
super();
@@ -48,6 +53,8 @@ export class DrawingPopupMenuController extends RxDisposable {
this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => this._create(workbook));
this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => this._dispose(workbook));
this._univerInstanceService.getAllUnitsForType<Workbook>(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => this._create(workbook));
+
+ this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(UploadLoading, this._injector));
}
private _dispose(workbook: Workbook) {
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts
index 0eb5f60592..8f7dc97648 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-transform-affected.controller.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { ICommandInfo, IDrawingParam, IMutationInfo, IRange, ITransformState, Nullable } from '@univerjs/core';
-import { Disposable, ICommandService, IDrawingManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, Rectangle } from '@univerjs/core';
+import type { ICommandInfo, IMutationInfo, IRange, Nullable } from '@univerjs/core';
+import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle, Rectangle } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
import { ISelectionRenderService } from '@univerjs/sheets-ui';
-import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
+import { type IDrawingJsonUndo1, IDrawingManagerService, type IDrawingParam, type ITransformState } from '@univerjs/drawing';
import type { IInsertColCommandParams, IInsertRowCommandParams, IRemoveRowColCommandParams, ISetColHiddenMutationParams, ISetColVisibleMutationParams, ISetRowHiddenMutationParams, ISetRowVisibleMutationParams, ISetSpecificColsVisibleCommandParams, ISetSpecificRowsVisibleCommandParams, ISetWorksheetActiveOperationParams, ISetWorksheetColWidthMutationParams, ISetWorksheetRowHeightMutationParams, ISetWorksheetRowIsAutoHeightMutationParams } from '@univerjs/sheets';
import { DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, getSheetCommandTarget, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, RemoveColCommand, RemoveRowCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetActiveOperation, SetWorksheetColWidthMutation, SetWorksheetRowHeightMutation, SheetInterceptorService } from '@univerjs/sheets';
import type { ISheetDrawing, ISheetDrawingPosition } from '@univerjs/sheets-drawing';
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
index b3ca1149ce..d788568ddc 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { ICommandInfo, IImageIoServiceParam, IRange, Nullable, Workbook } from '@univerjs/core';
-import { Disposable, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, IDrawingManagerService, IImageIoService, ImageUploadStatusType, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, UniverInstanceType } from '@univerjs/core';
+import type { ICommandInfo, IRange, Nullable, Workbook } from '@univerjs/core';
+import { Disposable, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
-import type { IImageData } from '@univerjs/drawing';
-import { DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, getImageSize } from '@univerjs/drawing';
+import type { IImageData, IImageIoServiceParam } from '@univerjs/drawing';
+import { DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, DrawingTypeEnum, getImageSize, IDrawingManagerService, IImageIoService, ImageUploadStatusType } from '@univerjs/drawing';
import type { ISheetDrawing, ISheetDrawingPosition } from '@univerjs/sheets-drawing';
import { ISheetDrawingService } from '@univerjs/sheets-drawing';
import { SelectionManagerService } from '@univerjs/sheets';
diff --git a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
index 80cac36d84..5ffb08f1e5 100644
--- a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
+++ b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
@@ -15,7 +15,7 @@
*/
import type { IPosition, ITransformState, Nullable, Worksheet } from '@univerjs/core';
-import { Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IDrawingManagerService, IUniverInstanceService, Tools } from '@univerjs/core';
+import { Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IUniverInstanceService, Tools } from '@univerjs/core';
import type { BaseObject, IBoundRectNoAngle, IRectProps, IRender, Scene, SpreadsheetSkeleton } from '@univerjs/engine-render';
import { DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Rect } from '@univerjs/engine-render';
import type { IFloatDomLayout } from '@univerjs/ui';
@@ -24,7 +24,7 @@ import type { IDisposable } from '@wendellhu/redi';
import { Inject } from '@wendellhu/redi';
import { BehaviorSubject, Subject } from 'rxjs';
import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
-import { getDrawingShapeKeyByDrawingSearch } from '@univerjs/drawing';
+import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService } from '@univerjs/drawing';
import { ISelectionRenderService, SetScrollOperation, SetZoomRatioOperation, SheetSkeletonManagerService, VIEWPORT_KEY } from '@univerjs/sheets-ui';
import type { ISetFrozenMutationParams } from '@univerjs/sheets';
import { getSheetCommandTarget, SetFrozenMutation } from '@univerjs/sheets';
diff --git a/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx b/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx
index 4bf995bead..e7834ccfa2 100644
--- a/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx
+++ b/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import type { IDrawingParam, Nullable } from '@univerjs/core';
-import { ICommandService, IDrawingManagerService, LocaleService } from '@univerjs/core';
+import type { Nullable } from '@univerjs/core';
+import { ICommandService, LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { Radio, RadioGroup } from '@univerjs/design';
@@ -24,6 +24,7 @@ import type { ISheetDrawing } from '@univerjs/sheets-drawing';
import { SheetDrawingAnchorType } from '@univerjs/sheets-drawing';
import type { BaseObject } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
+import { IDrawingManagerService, type IDrawingParam } from '@univerjs/drawing';
import { SetSheetDrawingCommand } from '../../commands/commands/set-sheet-drawing.command';
import styles from './index.module.less';
diff --git a/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingPanel.tsx b/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingPanel.tsx
index 603afbcbbf..0d3852d970 100644
--- a/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingPanel.tsx
+++ b/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingPanel.tsx
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { IDrawingParam } from '@univerjs/core';
-import { IDrawingManagerService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
import { DrawingCommonPanel } from '@univerjs/drawing-ui';
+import type { IDrawingParam } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import styles from './index.module.less';
import { SheetDrawingAnchor } from './SheetDrawingAnchor';
diff --git a/packages/sheets-ui/src/views/upload-loading/UploadLoading.tsx b/packages/sheets-drawing-ui/src/views/upload-loading/UploadLoading.tsx
similarity index 94%
rename from packages/sheets-ui/src/views/upload-loading/UploadLoading.tsx
rename to packages/sheets-drawing-ui/src/views/upload-loading/UploadLoading.tsx
index c3844d51f9..b284bfadc7 100644
--- a/packages/sheets-ui/src/views/upload-loading/UploadLoading.tsx
+++ b/packages/sheets-drawing-ui/src/views/upload-loading/UploadLoading.tsx
@@ -14,9 +14,11 @@
* limitations under the License.
*/
-import { IImageIoService, LocaleService } from '@univerjs/core';
+import { LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect } from 'react';
+import { IImageIoService } from '@univerjs/drawing';
+
import styles from './index.module.less';
export const UploadLoading = () => {
diff --git a/packages/sheets-ui/src/views/upload-loading/index.module.less b/packages/sheets-drawing-ui/src/views/upload-loading/index.module.less
similarity index 100%
rename from packages/sheets-ui/src/views/upload-loading/index.module.less
rename to packages/sheets-drawing-ui/src/views/upload-loading/index.module.less
diff --git a/packages/sheets-drawing/src/commands/mutations/set-drawing-apply.mutation.ts b/packages/sheets-drawing/src/commands/mutations/set-drawing-apply.mutation.ts
index c82f735ed0..9b35da1abf 100644
--- a/packages/sheets-drawing/src/commands/mutations/set-drawing-apply.mutation.ts
+++ b/packages/sheets-drawing/src/commands/mutations/set-drawing-apply.mutation.ts
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-import type { IDrawingGroupUpdateParam, IDrawingOrderMapParam, IDrawingSearch, IMutation } from '@univerjs/core';
-import { CommandType, IDrawingManagerService } from '@univerjs/core';
-import type { IDrawingJson1Type } from '@univerjs/drawing';
+import type { IDrawingSearch, IMutation } from '@univerjs/core';
+import { CommandType } from '@univerjs/core';
+import type { IDrawingGroupUpdateParam, IDrawingJson1Type, IDrawingOrderMapParam } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import { ISheetDrawingService } from '../../services/sheet-drawing.service';
export enum DrawingApplyType {
diff --git a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
index 1e7a34910b..81f6260f8f 100644
--- a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
+++ b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-import type { IDrawingSubunitMap } from '@univerjs/core';
-import { Disposable, ICommandService, IDrawingManagerService, IResourceManagerService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
+import { Disposable, ICommandService, IResourceManagerService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
+import type { IDrawingSubunitMap } from '@univerjs/drawing';
+import { IDrawingManagerService } from '@univerjs/drawing';
import type { ISheetDrawing } from '../services/sheet-drawing.service';
import { ISheetDrawingService } from '../services/sheet-drawing.service';
import { SetDrawingApplyMutation } from '../commands/mutations/set-drawing-apply.mutation';
diff --git a/packages/sheets-drawing/src/services/sheet-drawing.service.ts b/packages/sheets-drawing/src/services/sheet-drawing.service.ts
index 69814c217d..ae6d5bc1ac 100644
--- a/packages/sheets-drawing/src/services/sheet-drawing.service.ts
+++ b/packages/sheets-drawing/src/services/sheet-drawing.service.ts
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import type { IDrawingParam, IRotationSkewFlipTransform, IUnitDrawingService } from '@univerjs/core';
+import { type IDrawingParam, type IImageData, type IRotationSkewFlipTransform, type IUnitDrawingService, UnitDrawingService } from '@univerjs/drawing';
import { createIdentifier } from '@wendellhu/redi';
-import { type IImageData, UnitDrawingService } from '@univerjs/drawing';
interface ICellPosition {
column: number; // column number
diff --git a/packages/sheets-ui/package.json b/packages/sheets-ui/package.json
index c5cfdc5b12..239814e7fb 100644
--- a/packages/sheets-ui/package.json
+++ b/packages/sheets-ui/package.json
@@ -91,7 +91,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/drawing": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-numfmt": "workspace:*",
"@univerjs/engine-render": "workspace:*",
diff --git a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
index bab7818058..c7b86d60db 100644
--- a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
+++ b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
@@ -26,7 +26,6 @@ import { FormulaBar } from '../formula-bar/FormulaBar';
import { OperateContainer } from '../operate-container/OperateContainer';
import { SheetBar } from '../sheet-bar/SheetBar';
import { StatusBar } from '../status-bar/StatusBar';
-import { UploadLoading } from '../upload-loading/UploadLoading';
import styles from './index.module.less';
export function RenderSheetFooter() {
@@ -53,6 +52,9 @@ export function RenderSheetHeader() {
);
}
+/**
+ * @deprecated We should not write into this component anymore.
+ */
export function RenderSheetContent() {
const univerInstanceService = useDependency(IUniverInstanceService);
const workbook = useObservable(() => univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET), null, false, []);
@@ -62,7 +64,6 @@ export function RenderSheetContent() {
<>
<EditorContainer />
<OperateContainer />
- <UploadLoading />
</>
);
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 67d28b7df3..1133be3033 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1849,9 +1849,6 @@ importers:
'@univerjs/docs':
specifier: workspace:*
version: link:../docs
- '@univerjs/drawing':
- specifier: workspace:*
- version: link:../drawing
'@univerjs/engine-formula':
specifier: workspace:*
version: link:../engine-formula