@univerjs/drawing-ui 1.0.0-alpha.1 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ArrangeTypeEnum, BooleanNumber, CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IURLImageService, IUniverInstanceService, ImageSourceType, Inject, Injector, LocaleService, Plugin, PositionedObjectLayoutType, UniverInstanceType, checkIfMove, debounce, generateRandomId, merge, toDisposable } from "@univerjs/core";
2
- import { IDrawingManagerService, IImageIoService, ImageSourceType as ImageSourceType$1, SetDrawingSelectedOperation, getDrawingShapeKeyByDrawingSearch } from "@univerjs/drawing";
2
+ import { DRAWING_GROUPABLE_TYPES, IDrawingManagerService, IImageIoService, ImageSourceType as ImageSourceType$1, SetDrawingSelectedOperation, getDrawingShapeKeyByDrawingSearch, isGroupableDrawingType, resolveDrawingRotateEnabled } from "@univerjs/drawing";
3
3
  import { CURSOR_TYPE, Canvas, DRAWING_OBJECT_LAYER_INDEX, DrawingGroupObject, Group, IRenderManagerService, Image, RENDER_CLASS_TYPE, Rect, Shape, Vector2, degToRad, getGroupState, precisionTo, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { AutofillDoubleIcon, BottomIcon, CreateCopyIcon, CropIcon, DeleteIcon, DocSettingIcon, GroupIcon, MoreDownIcon, MoveDownIcon, MoveUpIcon, TextWrapShapeIcon, TopmostIcon, UngroupIcon } from "@univerjs/icons";
5
5
  import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, IGalleryService, IMenuManagerService, IMessageService, IconManager, MenuItemType, useDependency, useObservable } from "@univerjs/ui";
@@ -131,15 +131,13 @@ const SetDrawingArrangeBackwardOperation = {
131
131
  //#endregion
132
132
  //#region src/commands/operations/drawing-group.operation.ts
133
133
  /**
134
- * Now only support grouping images, shapes, and groups.
134
+ * Now only support grouping images, shapes, charts, and groups.
135
135
  */
136
- const DRAWING_GROUP_TYPES = [
137
- DrawingTypeEnum.DRAWING_IMAGE,
138
- DrawingTypeEnum.DRAWING_SHAPE,
139
- DrawingTypeEnum.DRAWING_GROUP
140
- ];
136
+ const DRAWING_GROUP_TYPES = DRAWING_GROUPABLE_TYPES;
141
137
  /**
142
- * Group the selected drawings into a new group. The selected drawings must be of type image, shape, or group, and there must be at least 2 drawings selected.
138
+ * Group the selected drawings into a new group. The selected drawings must be
139
+ * of type image, shape, chart, or group, and there must be at least 2 drawings
140
+ * selected.
143
141
  */
144
142
  const SetDrawingGroupOperation = {
145
143
  id: "drawing.operation.set-drawing-group",
@@ -148,7 +146,7 @@ const SetDrawingGroupOperation = {
148
146
  const drawingManagerService = accessor.get(IDrawingManagerService);
149
147
  const drawings = params.drawings || drawingManagerService.getFocusDrawings();
150
148
  if (drawings.length < 2) return false;
151
- if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return false;
149
+ if (!drawings.every((drawing) => isGroupableDrawingType(drawing.drawingType))) return false;
152
150
  const { unitId, subUnitId } = drawings[0];
153
151
  const groupId = generateRandomId(10);
154
152
  const groupTransform = getGroupState(0, 0, drawings.map((o) => o.transform || {}));
@@ -170,11 +168,12 @@ const SetDrawingGroupOperation = {
170
168
  left: 0,
171
169
  top: 0
172
170
  };
173
- const { unitId, subUnitId, drawingId } = drawing;
171
+ const { unitId, subUnitId, drawingId, drawingType } = drawing;
174
172
  return {
175
173
  unitId,
176
174
  subUnitId,
177
175
  drawingId,
176
+ drawingType,
178
177
  transform: { ...transform },
179
178
  groupId
180
179
  };
@@ -266,8 +265,48 @@ const ImageResetSizeOperation = {
266
265
  }
267
266
  };
268
267
 
268
+ //#endregion
269
+ //#region src/utils/rotate-enabled.ts
270
+ function isKnownDrawingUINonRotatableType(drawingType) {
271
+ return drawingType === DrawingTypeEnum.DRAWING_CHART;
272
+ }
273
+ function resolveDrawingUIRotateEnabled(drawing, options = {}) {
274
+ var _options$isKnownNonRo;
275
+ return resolveDrawingRotateEnabled(drawing, {
276
+ ...options,
277
+ isKnownNonRotatableType: (_options$isKnownNonRo = options.isKnownNonRotatableType) !== null && _options$isKnownNonRo !== void 0 ? _options$isKnownNonRo : isKnownDrawingUINonRotatableType
278
+ });
279
+ }
280
+
269
281
  //#endregion
270
282
  //#region src/controllers/utils.ts
283
+ function getDrawingRenderObject(scene, drawingSearch) {
284
+ var _scene$getObjectInclu;
285
+ const key = getDrawingShapeKeyByDrawingSearch(drawingSearch);
286
+ return (_scene$getObjectInclu = scene.getObjectIncludeInGroup(key)) !== null && _scene$getObjectInclu !== void 0 ? _scene$getObjectInclu : null;
287
+ }
288
+ function disposeDrawingRenderObject(scene, drawingSearch) {
289
+ const object = getDrawingRenderObject(scene, drawingSearch);
290
+ if (object == null) return false;
291
+ object.dispose();
292
+ return true;
293
+ }
294
+ function getRenderObjectForDrawing(scene, drawing) {
295
+ return getDrawingRenderObject(scene, drawing);
296
+ }
297
+ function syncGroupRotateEnabled(group, groupParam, scene, drawingManagerService, children) {
298
+ const rotateEnabled = resolveDrawingUIRotateEnabled(groupParam, {
299
+ getChildren: (drawing) => {
300
+ if (children && drawing.drawingId === groupParam.drawingId && drawing.unitId === groupParam.unitId && drawing.subUnitId === groupParam.subUnitId) return children;
301
+ return drawingManagerService.getDrawingsByGroup(drawing);
302
+ },
303
+ getRenderObject: (drawing) => getRenderObjectForDrawing(scene, drawing)
304
+ });
305
+ group.transformerConfig = {
306
+ ...group.transformerConfig,
307
+ rotateEnabled
308
+ };
309
+ }
271
310
  function insertGroupObject(objectParam, object, scene, drawingManagerService) {
272
311
  const groupParam = drawingManagerService.getDrawingByParam(objectParam);
273
312
  if (groupParam == null) return;
@@ -278,11 +317,13 @@ function insertGroupObject(objectParam, object, scene, drawingManagerService) {
278
317
  const objects = groupObject.getObjects();
279
318
  for (const obj of objects) if (obj.oKey === object.oKey) return;
280
319
  groupObject.addObject(object);
320
+ syncGroupRotateEnabled(groupObject, groupParam, scene, drawingManagerService);
281
321
  return;
282
322
  }
283
323
  const group = new DrawingGroupObject(groupKey);
284
324
  scene.addObject(group, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
285
325
  group.addObject(object);
326
+ syncGroupRotateEnabled(group, groupParam, scene, drawingManagerService);
286
327
  const { transform, groupBaseBound } = groupParam;
287
328
  if (groupBaseBound) group.setBaseBound(groupBaseBound);
288
329
  if (groupParam.groupId) {
@@ -321,7 +362,7 @@ function getCurrentUnitInfo(currentUniverService, propUnitId) {
321
362
  //#endregion
322
363
  //#region package.json
323
364
  var name = "@univerjs/drawing-ui";
324
- var version = "1.0.0-alpha.1";
365
+ var version = "1.0.0-alpha.2";
325
366
 
326
367
  //#endregion
327
368
  //#region src/config/config.ts
@@ -942,16 +983,18 @@ function getUpdateParams(objects, drawingManagerService) {
942
983
 
943
984
  //#endregion
944
985
  //#region src/controllers/drawing-update.controller.ts
986
+ function hasRefreshMetadata(refreshParam) {
987
+ return "hidden" in refreshParam || "behindText" in refreshParam;
988
+ }
945
989
  function syncDrawingHiddenState(shape, drawingParam) {
946
990
  if (!("hidden" in drawingParam)) return;
947
991
  drawingParam.hidden === true ? shape.hide() : shape.show();
948
992
  }
949
993
  function mergeRefreshMetadata(drawingParam, refreshParam) {
950
- const metadata = refreshParam;
951
- if (!("hidden" in metadata) && !("behindText" in metadata)) return drawingParam;
994
+ if (!hasRefreshMetadata(refreshParam)) return drawingParam;
952
995
  return {
953
996
  ...drawingParam,
954
- ...metadata
997
+ ...refreshParam
955
998
  };
956
999
  }
957
1000
  let DrawingUpdateController = class DrawingUpdateController extends Disposable {
@@ -1058,6 +1101,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1058
1101
  }));
1059
1102
  scene.addObject(group, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
1060
1103
  group.addObjects(...objects);
1104
+ syncGroupRotateEnabled(group, parent, scene, this._drawingManagerService, children);
1061
1105
  if (parent.groupBaseBound) group.setBaseBound(parent.groupBaseBound);
1062
1106
  if (parent.groupId) {
1063
1107
  group.isInGroup = true;
@@ -1270,15 +1314,12 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1270
1314
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
1271
1315
  if (renderObject == null) return;
1272
1316
  const { scene } = renderObject;
1273
- const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
1317
+ if (disposeDrawingRenderObject(scene, {
1274
1318
  unitId,
1275
1319
  subUnitId,
1276
1320
  drawingId
1277
- });
1278
- const drawingShapes = scene.fuzzyMathObjects(drawingShapeKey, true);
1279
- if (drawingShapes.length > 0) {
1321
+ })) {
1280
1322
  var _scene$getTransformer;
1281
- for (const drawingShape of drawingShapes) drawingShape.dispose();
1282
1323
  (_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.clearSelectedObjects();
1283
1324
  }
1284
1325
  });
@@ -1339,7 +1380,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1339
1380
  subUnitId,
1340
1381
  drawingId
1341
1382
  });
1342
- const drawingShape = scene.getObject(drawingShapeKey);
1383
+ const drawingShape = scene.getObjectIncludeInGroup(drawingShapeKey);
1343
1384
  const drawingParamWithRefreshMetadata = mergeRefreshMetadata(drawingParam, param);
1344
1385
  if (drawingShape == null) {
1345
1386
  if (drawingParamWithRefreshMetadata.hidden === true) return true;
@@ -2220,10 +2261,10 @@ function getMenuStateByDrawingFocusChangedObservable$(accessor, type) {
2220
2261
  if (!drawings || drawings.length === 0) return subscriber.next(true);
2221
2262
  if (type === "group") {
2222
2263
  if (drawings.length < 2) return subscriber.next(true);
2223
- if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
2264
+ if (!drawings.every((drawing) => isGroupableDrawingType(drawing.drawingType))) return subscriber.next(true);
2224
2265
  } else if (type === "unGroup") {
2225
2266
  if (drawings.filter((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP).length === 0) return subscriber.next(true);
2226
- } else if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
2267
+ } else if (!drawings.every((drawing) => isGroupableDrawingType(drawing.drawingType))) return subscriber.next(true);
2227
2268
  subscriber.next(false);
2228
2269
  };
2229
2270
  const subscription = drawingManagerService.focus$.subscribe((drawings) => {
@@ -2643,6 +2684,29 @@ const DrawingGroup = (props) => {
2643
2684
  //#region src/utils/config.ts
2644
2685
  const RANGE_DRAWING_ROTATION_LIMIT = [-360, 360];
2645
2686
 
2687
+ //#endregion
2688
+ //#region src/views/panel/drawing-transform-rotation.ts
2689
+ function isDrawingTransformRotationDisabled(rotateEnabled) {
2690
+ return !rotateEnabled;
2691
+ }
2692
+ function createDrawingTransformRotationChangeHandler(options) {
2693
+ return (val) => {
2694
+ if (isDrawingTransformRotationDisabled(options.rotateEnabled)) return;
2695
+ if (val == null) return;
2696
+ const { unitId, subUnitId, drawingId, drawingType } = options.drawingParam;
2697
+ const updateParam = {
2698
+ unitId,
2699
+ subUnitId,
2700
+ drawingId,
2701
+ drawingType,
2702
+ transform: { angle: val }
2703
+ };
2704
+ options.setRotation(val);
2705
+ options.emitUpdate([updateParam]);
2706
+ options.notifyChange();
2707
+ };
2708
+ }
2709
+
2646
2710
  //#endregion
2647
2711
  //#region src/views/panel/DrawingTransform.tsx
2648
2712
  const INPUT_DEBOUNCE_TIME = 300;
@@ -2670,6 +2734,8 @@ const DrawingTransform = (props) => {
2670
2734
  const [yPosition, setYPosition] = useState(originY);
2671
2735
  const [rotation, setRotation] = useState(originRotation);
2672
2736
  const [lockRatio, setLockRatio] = useState(transformer.keepRatio);
2737
+ const rotateEnabled = resolveDrawingUIRotateEnabled(drawingParam, { getChildren: (drawing) => drawingManagerService.getDrawingsByGroup(drawing) });
2738
+ const rotationDisabled = isDrawingTransformRotationDisabled(rotateEnabled);
2673
2739
  const checkMoveBoundary = (left, top, width, height) => {
2674
2740
  const { width: topSceneWidth, height: topSceneHeight } = topScene;
2675
2741
  const { ancestorLeft, ancestorTop } = scene;
@@ -2810,19 +2876,18 @@ const DrawingTransform = (props) => {
2810
2876
  drawingManagerService.featurePluginUpdateNotification([updateParam]);
2811
2877
  transformer.refreshControls().changeNotification();
2812
2878
  }, INPUT_DEBOUNCE_TIME);
2813
- const handleRotationChange = (val) => {
2814
- if (val == null) return;
2815
- const updateParam = {
2879
+ const handleRotationChange = createDrawingTransformRotationChangeHandler({
2880
+ rotateEnabled,
2881
+ drawingParam: {
2816
2882
  unitId,
2817
2883
  subUnitId,
2818
2884
  drawingId,
2819
- drawingType,
2820
- transform: { angle: val }
2821
- };
2822
- setRotation(val);
2823
- drawingManagerService.featurePluginUpdateNotification([updateParam]);
2824
- transformer.refreshControls().changeNotification();
2825
- };
2885
+ drawingType
2886
+ },
2887
+ setRotation,
2888
+ emitUpdate: (updateParams) => drawingManagerService.featurePluginUpdateNotification(updateParams),
2889
+ notifyChange: () => transformer.refreshControls().changeNotification()
2890
+ });
2826
2891
  const handleLockRatioChange = (val) => {
2827
2892
  setLockRatio(val);
2828
2893
  transformer.keepRatio = val;
@@ -2884,6 +2949,7 @@ const DrawingTransform = (props) => {
2884
2949
  value: rotation,
2885
2950
  min: RANGE_DRAWING_ROTATION_LIMIT[0],
2886
2951
  max: RANGE_DRAWING_ROTATION_LIMIT[1],
2952
+ disabled: rotationDisabled,
2887
2953
  onChange: handleRotationChange
2888
2954
  })] })
2889
2955
  ]
@@ -3128,4 +3194,4 @@ const DrawingCommonPanel = (props) => {
3128
3194
  };
3129
3195
 
3130
3196
  //#endregion
3131
- export { AutoImageCropOperation, COMPONENT_IMAGE_POPUP_MENU, CancelDrawingGroupOperation, CloseImageCropOperation, DRAWING_GROUP_TYPES, DrawingCommonPanel, DrawingImageClipService, DrawingRenderService, IMAGE_CLIP_SHAPE_PICKER_COMPONENT, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, SetDrawingAlignOperation, SetDrawingArrangeOperation, SetDrawingGroupOperation, UniverDrawingUIPlugin, getCurrentUnitInfo, getUpdateParams, insertGroupObject };
3197
+ export { AutoImageCropOperation, COMPONENT_IMAGE_POPUP_MENU, CancelDrawingGroupOperation, CloseImageCropOperation, DRAWING_GROUP_TYPES, DrawingCommonPanel, DrawingImageClipService, DrawingRenderService, IMAGE_CLIP_SHAPE_PICKER_COMPONENT, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, SetDrawingAlignOperation, SetDrawingArrangeOperation, SetDrawingGroupOperation, UniverDrawingUIPlugin, disposeDrawingRenderObject, getCurrentUnitInfo, getDrawingRenderObject, getUpdateParams, insertGroupObject };
@@ -16,14 +16,16 @@
16
16
  import type { IDrawingParam, IOperation } from '@univerjs/core';
17
17
  import { DrawingTypeEnum } from '@univerjs/core';
18
18
  /**
19
- * Now only support grouping images, shapes, and groups.
19
+ * Now only support grouping images, shapes, charts, and groups.
20
20
  */
21
- export declare const DRAWING_GROUP_TYPES: DrawingTypeEnum[];
21
+ export declare const DRAWING_GROUP_TYPES: readonly [DrawingTypeEnum.DRAWING_IMAGE, DrawingTypeEnum.DRAWING_SHAPE, DrawingTypeEnum.DRAWING_CHART, DrawingTypeEnum.DRAWING_GROUP];
22
22
  export interface IDrawingGroupOperationParams {
23
23
  drawings?: IDrawingParam[];
24
24
  }
25
25
  /**
26
- * Group the selected drawings into a new group. The selected drawings must be of type image, shape, or group, and there must be at least 2 drawings selected.
26
+ * Group the selected drawings into a new group. The selected drawings must be
27
+ * of type image, shape, chart, or group, and there must be at least 2 drawings
28
+ * selected.
27
29
  */
28
30
  export declare const SetDrawingGroupOperation: IOperation<IDrawingGroupOperationParams>;
29
31
  export interface ICancelDrawingGroupOperationParams {
@@ -13,10 +13,14 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IDrawingSearch, IUniverInstanceService, Nullable } from '@univerjs/core';
16
+ import type { IDrawingParam, IDrawingSearch, IUniverInstanceService, Nullable } from '@univerjs/core';
17
17
  import type { IDrawingManagerService } from '@univerjs/drawing';
18
18
  import type { BaseObject, Scene } from '@univerjs/engine-render';
19
19
  import { UniverInstanceType } from '@univerjs/core';
20
+ import { Group } from '@univerjs/engine-render';
21
+ export declare function getDrawingRenderObject(scene: Scene, drawingSearch: IDrawingSearch): BaseObject | null;
22
+ export declare function disposeDrawingRenderObject(scene: Scene, drawingSearch: IDrawingSearch): boolean;
23
+ export declare function syncGroupRotateEnabled(group: Group, groupParam: IDrawingParam, scene: Scene, drawingManagerService: IDrawingManagerService, children?: readonly IDrawingParam[]): void;
20
24
  export declare function insertGroupObject(objectParam: IDrawingSearch, object: BaseObject, scene: Scene, drawingManagerService: IDrawingManagerService): void;
21
25
  export declare function getCurrentUnitInfo(currentUniverService: IUniverInstanceService, propUnitId?: string): {
22
26
  unitId: string;
@@ -22,7 +22,7 @@ export type { ICancelDrawingGroupOperationParams, IDrawingGroupOperationParams,
22
22
  export { AutoImageCropOperation, CloseImageCropOperation, OpenImageCropOperation, } from './commands/operations/image-crop.operation';
23
23
  export { ImageResetSizeOperation } from './commands/operations/image-reset-size.operation';
24
24
  export type { IUniverDrawingUIConfig } from './config/config';
25
- export { getCurrentUnitInfo, insertGroupObject } from './controllers/utils';
25
+ export { disposeDrawingRenderObject, getCurrentUnitInfo, getDrawingRenderObject, insertGroupObject } from './controllers/utils';
26
26
  export { UniverDrawingUIPlugin } from './plugin';
27
27
  export { DrawingImageClipService, IMAGE_CLIP_SHAPE_PICKER_COMPONENT } from './services/drawing-image-clip.service';
28
28
  export type { ImageShapeClipDelegate } from './services/drawing-image-clip.service';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DrawingType, IDrawingParam } from '@univerjs/core';
17
+ import type { IDrawingRotateEnabledResolverOptions } from '@univerjs/drawing';
18
+ export declare function isKnownDrawingUINonRotatableType(drawingType: DrawingType): boolean;
19
+ export declare function resolveDrawingUIRotateEnabled(drawing: IDrawingParam, options?: IDrawingRotateEnabledResolverOptions): boolean;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDrawingParam } from '@univerjs/core';
17
+ interface IDrawingTransformRotationChangeHandlerOptions {
18
+ rotateEnabled: boolean;
19
+ drawingParam: Pick<IDrawingParam, 'unitId' | 'subUnitId' | 'drawingId' | 'drawingType'>;
20
+ setRotation: (rotation: number) => void;
21
+ emitUpdate: (updateParams: IDrawingParam[]) => void;
22
+ notifyChange: () => void;
23
+ }
24
+ export declare function isDrawingTransformRotationDisabled(rotateEnabled: boolean): boolean;
25
+ export declare function createDrawingTransformRotationChangeHandler(options: IDrawingTransformRotationChangeHandlerOptions): (val: number | null) => void;
26
+ export {};