@apollo-office/drawing-ui 1.0.0
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/LICENSE +176 -0
- package/MODIFICATIONS.md +26 -0
- package/NOTICE +14 -0
- package/README.md +42 -0
- package/lib/cjs/index.js +3146 -0
- package/lib/cjs/locale/ar-SA.js +74 -0
- package/lib/cjs/locale/ca-ES.js +74 -0
- package/lib/cjs/locale/de-DE.js +74 -0
- package/lib/cjs/locale/en-US.js +89 -0
- package/lib/cjs/locale/es-ES.js +74 -0
- package/lib/cjs/locale/fa-IR.js +74 -0
- package/lib/cjs/locale/fr-FR.js +74 -0
- package/lib/cjs/locale/id-ID.js +74 -0
- package/lib/cjs/locale/it-IT.js +74 -0
- package/lib/cjs/locale/ja-JP.js +74 -0
- package/lib/cjs/locale/ko-KR.js +74 -0
- package/lib/cjs/locale/pl-PL.js +74 -0
- package/lib/cjs/locale/pt-BR.js +74 -0
- package/lib/cjs/locale/ru-RU.js +74 -0
- package/lib/cjs/locale/sk-SK.js +74 -0
- package/lib/cjs/locale/vi-VN.js +74 -0
- package/lib/cjs/locale/zh-CN.js +74 -0
- package/lib/cjs/locale/zh-HK.js +74 -0
- package/lib/cjs/locale/zh-TW.js +74 -0
- package/lib/es/index.js +3116 -0
- package/lib/es/locale/ar-SA.js +73 -0
- package/lib/es/locale/ca-ES.js +73 -0
- package/lib/es/locale/de-DE.js +73 -0
- package/lib/es/locale/en-US.js +88 -0
- package/lib/es/locale/es-ES.js +73 -0
- package/lib/es/locale/fa-IR.js +73 -0
- package/lib/es/locale/fr-FR.js +73 -0
- package/lib/es/locale/id-ID.js +73 -0
- package/lib/es/locale/it-IT.js +73 -0
- package/lib/es/locale/ja-JP.js +73 -0
- package/lib/es/locale/ko-KR.js +73 -0
- package/lib/es/locale/pl-PL.js +73 -0
- package/lib/es/locale/pt-BR.js +73 -0
- package/lib/es/locale/ru-RU.js +73 -0
- package/lib/es/locale/sk-SK.js +73 -0
- package/lib/es/locale/vi-VN.js +73 -0
- package/lib/es/locale/zh-CN.js +73 -0
- package/lib/es/locale/zh-HK.js +73 -0
- package/lib/es/locale/zh-TW.js +73 -0
- package/lib/index.css +311 -0
- package/lib/index.js +3116 -0
- package/lib/locale/ar-SA.js +73 -0
- package/lib/locale/ca-ES.js +73 -0
- package/lib/locale/de-DE.js +73 -0
- package/lib/locale/en-US.js +88 -0
- package/lib/locale/es-ES.js +73 -0
- package/lib/locale/fa-IR.js +73 -0
- package/lib/locale/fr-FR.js +73 -0
- package/lib/locale/id-ID.js +73 -0
- package/lib/locale/it-IT.js +73 -0
- package/lib/locale/ja-JP.js +73 -0
- package/lib/locale/ko-KR.js +73 -0
- package/lib/locale/pl-PL.js +73 -0
- package/lib/locale/pt-BR.js +73 -0
- package/lib/locale/ru-RU.js +73 -0
- package/lib/locale/sk-SK.js +73 -0
- package/lib/locale/vi-VN.js +73 -0
- package/lib/locale/zh-CN.js +73 -0
- package/lib/locale/zh-HK.js +73 -0
- package/lib/locale/zh-TW.js +73 -0
- package/lib/types/commands/operations/drawing-align.operation.d.ts +43 -0
- package/lib/types/commands/operations/drawing-arrange.operation.d.ts +29 -0
- package/lib/types/commands/operations/drawing-group.operation.d.ts +35 -0
- package/lib/types/commands/operations/image-crop.operation.d.ts +36 -0
- package/lib/types/commands/operations/image-reset-size.operation.d.ts +17 -0
- package/lib/types/config/config.d.ts +22 -0
- package/lib/types/controllers/drawing-ui.controller.d.ts +27 -0
- package/lib/types/controllers/drawing-update.controller.d.ts +49 -0
- package/lib/types/controllers/image-cropper.controller.d.ts +41 -0
- package/lib/types/controllers/image-update.controller.d.ts +40 -0
- package/lib/types/controllers/utils.d.ts +25 -0
- package/lib/types/index.d.ts +32 -0
- package/lib/types/locale/ar-SA.d.ts +18 -0
- package/lib/types/locale/ca-ES.d.ts +18 -0
- package/lib/types/locale/de-DE.d.ts +18 -0
- package/lib/types/locale/en-US.d.ts +89 -0
- package/lib/types/locale/es-ES.d.ts +18 -0
- package/lib/types/locale/fa-IR.d.ts +18 -0
- package/lib/types/locale/fr-FR.d.ts +18 -0
- package/lib/types/locale/id-ID.d.ts +18 -0
- package/lib/types/locale/it-IT.d.ts +18 -0
- package/lib/types/locale/ja-JP.d.ts +18 -0
- package/lib/types/locale/ko-KR.d.ts +18 -0
- package/lib/types/locale/pl-PL.d.ts +18 -0
- package/lib/types/locale/pt-BR.d.ts +18 -0
- package/lib/types/locale/ru-RU.d.ts +18 -0
- package/lib/types/locale/sk-SK.d.ts +18 -0
- package/lib/types/locale/vi-VN.d.ts +18 -0
- package/lib/types/locale/zh-CN.d.ts +18 -0
- package/lib/types/locale/zh-HK.d.ts +18 -0
- package/lib/types/locale/zh-TW.d.ts +18 -0
- package/lib/types/menu/align.menu.d.ts +27 -0
- package/lib/types/menu/arrange.menu.d.ts +22 -0
- package/lib/types/menu/group.menu.d.ts +21 -0
- package/lib/types/menu/schema.d.ts +17 -0
- package/lib/types/plugin.d.ts +29 -0
- package/lib/types/services/drawing-image-clip.service.d.ts +48 -0
- package/lib/types/services/drawing-render.service.d.ts +38 -0
- package/lib/types/utils/config.d.ts +18 -0
- package/lib/types/utils/get-update-params.d.ts +19 -0
- package/lib/types/views/crop/image-cropper-object.d.ts +49 -0
- package/lib/types/views/image-popup-menu/ImagePopupMenu.d.ts +35 -0
- package/lib/types/views/image-popup-menu/component-name.d.ts +16 -0
- package/lib/types/views/panel/DrawingAlign.d.ts +21 -0
- package/lib/types/views/panel/DrawingArrange.d.ts +21 -0
- package/lib/types/views/panel/DrawingCommonPanel.d.ts +25 -0
- package/lib/types/views/panel/DrawingGroup.d.ts +21 -0
- package/lib/types/views/panel/DrawingTransform.d.ts +21 -0
- package/lib/types/views/panel/ImageCropper.d.ts +21 -0
- package/lib/umd/index.js +4 -0
- package/lib/umd/locale/ar-SA.js +1 -0
- package/lib/umd/locale/ca-ES.js +1 -0
- package/lib/umd/locale/de-DE.js +1 -0
- package/lib/umd/locale/en-US.js +1 -0
- package/lib/umd/locale/es-ES.js +1 -0
- package/lib/umd/locale/fa-IR.js +1 -0
- package/lib/umd/locale/fr-FR.js +1 -0
- package/lib/umd/locale/id-ID.js +1 -0
- package/lib/umd/locale/it-IT.js +1 -0
- package/lib/umd/locale/ja-JP.js +1 -0
- package/lib/umd/locale/ko-KR.js +1 -0
- package/lib/umd/locale/pl-PL.js +1 -0
- package/lib/umd/locale/pt-BR.js +1 -0
- package/lib/umd/locale/ru-RU.js +1 -0
- package/lib/umd/locale/sk-SK.js +1 -0
- package/lib/umd/locale/vi-VN.js +1 -0
- package/lib/umd/locale/zh-CN.js +1 -0
- package/lib/umd/locale/zh-HK.js +1 -0
- package/lib/umd/locale/zh-TW.js +1 -0
- package/package.json +74 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,3116 @@
|
|
|
1
|
+
import { ArrangeTypeEnum, BooleanNumber, CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IURLImageService, IUniverInstanceService, ImageSourceType, Inject, Injector, LocaleService, Plugin, PositionedObjectLayoutType, UniverInstanceType, checkIfMove, debounce, generateRandomId, merge, toDisposable } from "@apollo-office/core";
|
|
2
|
+
import { IDrawingManagerService, IImageIoService, ImageSourceType as ImageSourceType$1, SetDrawingSelectedOperation, getDrawingShapeKeyByDrawingSearch } from "@apollo-office/drawing";
|
|
3
|
+
import { CURSOR_TYPE, Canvas, DRAWING_OBJECT_LAYER_INDEX, DrawingGroupObject, Group, IRenderManagerService, Image, RENDER_CLASS_TYPE, Rect, Shape, Vector2, degToRad, getGroupState, precisionTo, transformObjectOutOfGroup } from "@apollo-office/engine-render";
|
|
4
|
+
import { AutofillDoubleIcon, BottomIcon, CreateCopyIcon, DeleteIcon, DocSettingIcon, GroupIcon, MoreDownIcon, MoveDownIcon, MoveUpIcon, TopmostIcon, UngroupIcon } from "@univerjs/icons";
|
|
5
|
+
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, IGalleryService, IMenuManagerService, IMessageService, MenuItemType, useDependency, useObservable } from "@apollo-office/ui";
|
|
6
|
+
import { BehaviorSubject, Observable, bufferTime, filter, map, of, switchMap } from "rxjs";
|
|
7
|
+
import { Button, Checkbox, Dropdown, DropdownMenu, InputNumber, MessageType, Select, Tooltip, borderClassName, clsx } from "@apollo-office/design";
|
|
8
|
+
import { useEffect, useRef, useState } from "react";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
//#region src/commands/operations/drawing-align.operation.ts
|
|
12
|
+
/**
|
|
13
|
+
* Set drawing align operation, including left, center, right, top, middle, bottom, horizon and vertical align.
|
|
14
|
+
*/
|
|
15
|
+
const SetDrawingAlignOperation = {
|
|
16
|
+
id: "sheet.operation.set-image-align",
|
|
17
|
+
type: CommandType.OPERATION,
|
|
18
|
+
handler: (accessor, params) => {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const SetDrawingAlignLeftOperation = {
|
|
23
|
+
id: "sheet.operation.set-drawing-align-left",
|
|
24
|
+
type: CommandType.OPERATION,
|
|
25
|
+
handler: (accessor) => {
|
|
26
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "1" });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const SetDrawingAlignCenterOperation = {
|
|
30
|
+
id: "sheet.operation.set-drawing-align-center",
|
|
31
|
+
type: CommandType.OPERATION,
|
|
32
|
+
handler: (accessor) => {
|
|
33
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "2" });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const SetDrawingAlignRightOperation = {
|
|
37
|
+
id: "sheet.operation.set-drawing-align-right",
|
|
38
|
+
type: CommandType.OPERATION,
|
|
39
|
+
handler: (accessor) => {
|
|
40
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "3" });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const SetDrawingAlignTopOperation = {
|
|
44
|
+
id: "sheet.operation.set-drawing-align-top",
|
|
45
|
+
type: CommandType.OPERATION,
|
|
46
|
+
handler: (accessor) => {
|
|
47
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "4" });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const SetDrawingAlignMiddleOperation = {
|
|
51
|
+
id: "sheet.operation.set-drawing-align-middle",
|
|
52
|
+
type: CommandType.OPERATION,
|
|
53
|
+
handler: (accessor) => {
|
|
54
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "5" });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const SetDrawingAlignBottomOperation = {
|
|
58
|
+
id: "sheet.operation.set-drawing-align-bottom",
|
|
59
|
+
type: CommandType.OPERATION,
|
|
60
|
+
handler: (accessor) => {
|
|
61
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "6" });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const SetDrawingAlignHorizonOperation = {
|
|
65
|
+
id: "sheet.operation.set-drawing-align-horizon",
|
|
66
|
+
type: CommandType.OPERATION,
|
|
67
|
+
handler: (accessor) => {
|
|
68
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "7" });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const SetDrawingAlignVerticalOperation = {
|
|
72
|
+
id: "sheet.operation.set-drawing-align-vertical",
|
|
73
|
+
type: CommandType.OPERATION,
|
|
74
|
+
handler: (accessor) => {
|
|
75
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "8" });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/commands/operations/drawing-arrange.operation.ts
|
|
81
|
+
/**
|
|
82
|
+
* Set the layer of the drawing, including forward, backward, front, and back
|
|
83
|
+
*/
|
|
84
|
+
const SetDrawingArrangeOperation = {
|
|
85
|
+
id: "drawing.operation.set-drawing-arrange",
|
|
86
|
+
type: CommandType.OPERATION,
|
|
87
|
+
handler: (accessor, params) => {
|
|
88
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
89
|
+
const { arrangeType } = params;
|
|
90
|
+
const drawings = params.drawings || drawingManagerService.getFocusDrawings();
|
|
91
|
+
const { unitId, subUnitId } = drawings[0];
|
|
92
|
+
const drawingIds = drawings.map((drawing) => drawing.drawingId);
|
|
93
|
+
drawingManagerService.featurePluginOrderUpdateNotification({
|
|
94
|
+
unitId,
|
|
95
|
+
subUnitId,
|
|
96
|
+
drawingIds,
|
|
97
|
+
arrangeType
|
|
98
|
+
});
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const SetDrawingArrangeFrontOperation = {
|
|
103
|
+
id: "drawing.operation.set-drawing-arrange-front",
|
|
104
|
+
type: CommandType.OPERATION,
|
|
105
|
+
handler: (accessor) => {
|
|
106
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.front });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const SetDrawingArrangeForwardOperation = {
|
|
110
|
+
id: "drawing.operation.set-drawing-arrange-forward",
|
|
111
|
+
type: CommandType.OPERATION,
|
|
112
|
+
handler: (accessor) => {
|
|
113
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.forward });
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const SetDrawingArrangeBackOperation = {
|
|
117
|
+
id: "drawing.operation.set-drawing-arrange-back",
|
|
118
|
+
type: CommandType.OPERATION,
|
|
119
|
+
handler: (accessor) => {
|
|
120
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.back });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const SetDrawingArrangeBackwardOperation = {
|
|
124
|
+
id: "drawing.operation.set-drawing-arrange-backward",
|
|
125
|
+
type: CommandType.OPERATION,
|
|
126
|
+
handler: (accessor) => {
|
|
127
|
+
return accessor.get(ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: ArrangeTypeEnum.backward });
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/commands/operations/drawing-group.operation.ts
|
|
133
|
+
/**
|
|
134
|
+
* Now only support grouping images, shapes, and groups.
|
|
135
|
+
*/
|
|
136
|
+
const DRAWING_GROUP_TYPES = [
|
|
137
|
+
DrawingTypeEnum.DRAWING_IMAGE,
|
|
138
|
+
DrawingTypeEnum.DRAWING_SHAPE,
|
|
139
|
+
DrawingTypeEnum.DRAWING_GROUP
|
|
140
|
+
];
|
|
141
|
+
/**
|
|
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.
|
|
143
|
+
*/
|
|
144
|
+
const SetDrawingGroupOperation = {
|
|
145
|
+
id: "drawing.operation.set-drawing-group",
|
|
146
|
+
type: CommandType.OPERATION,
|
|
147
|
+
handler: (accessor, params) => {
|
|
148
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
149
|
+
const drawings = params.drawings || drawingManagerService.getFocusDrawings();
|
|
150
|
+
if (drawings.length < 2) return false;
|
|
151
|
+
if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return false;
|
|
152
|
+
const { unitId, subUnitId } = drawings[0];
|
|
153
|
+
const groupId = generateRandomId(10);
|
|
154
|
+
const groupTransform = getGroupState(0, 0, drawings.map((o) => o.transform || {}));
|
|
155
|
+
const groupParam = {
|
|
156
|
+
unitId,
|
|
157
|
+
subUnitId,
|
|
158
|
+
drawingId: groupId,
|
|
159
|
+
drawingType: DrawingTypeEnum.DRAWING_GROUP,
|
|
160
|
+
transform: groupTransform,
|
|
161
|
+
groupBaseBound: {
|
|
162
|
+
left: groupTransform.left,
|
|
163
|
+
top: groupTransform.top,
|
|
164
|
+
width: groupTransform.width,
|
|
165
|
+
height: groupTransform.height
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const children = drawings.map((drawing) => {
|
|
169
|
+
const transform = drawing.transform || {
|
|
170
|
+
left: 0,
|
|
171
|
+
top: 0
|
|
172
|
+
};
|
|
173
|
+
const { unitId, subUnitId, drawingId } = drawing;
|
|
174
|
+
return {
|
|
175
|
+
unitId,
|
|
176
|
+
subUnitId,
|
|
177
|
+
drawingId,
|
|
178
|
+
transform: { ...transform },
|
|
179
|
+
groupId
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
drawingManagerService.featurePluginGroupUpdateNotification([{
|
|
183
|
+
parent: groupParam,
|
|
184
|
+
children
|
|
185
|
+
}]);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Ungroup the selected groups. The selected drawings must be at least 1 group selected.
|
|
191
|
+
*/
|
|
192
|
+
const CancelDrawingGroupOperation = {
|
|
193
|
+
id: "drawing.operation.cancel-drawing-group",
|
|
194
|
+
type: CommandType.OPERATION,
|
|
195
|
+
handler: (accessor, params) => {
|
|
196
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
197
|
+
const groupParams = (params.drawings || drawingManagerService.getFocusDrawings()).map((drawing) => {
|
|
198
|
+
if (drawing.drawingType !== DrawingTypeEnum.DRAWING_GROUP) return null;
|
|
199
|
+
const { unitId, subUnitId, drawingId, transform: groupTransform = {
|
|
200
|
+
width: 0,
|
|
201
|
+
height: 0
|
|
202
|
+
}, groupBaseBound } = drawing;
|
|
203
|
+
if (groupTransform === null) return null;
|
|
204
|
+
const objects = drawingManagerService.getDrawingsByGroup({
|
|
205
|
+
unitId,
|
|
206
|
+
subUnitId,
|
|
207
|
+
drawingId
|
|
208
|
+
});
|
|
209
|
+
if (objects.length === 0) return null;
|
|
210
|
+
return {
|
|
211
|
+
parent: drawing,
|
|
212
|
+
children: objects.map((object) => {
|
|
213
|
+
const { transform } = object;
|
|
214
|
+
const { unitId, subUnitId, drawingId } = object;
|
|
215
|
+
const newTransform = transformObjectOutOfGroup(transform || {}, groupTransform, groupTransform.width || 0, groupTransform.height || 0, groupBaseBound);
|
|
216
|
+
return {
|
|
217
|
+
unitId,
|
|
218
|
+
subUnitId,
|
|
219
|
+
drawingId,
|
|
220
|
+
transform: {
|
|
221
|
+
...transform,
|
|
222
|
+
...newTransform
|
|
223
|
+
},
|
|
224
|
+
groupId: void 0
|
|
225
|
+
};
|
|
226
|
+
})
|
|
227
|
+
};
|
|
228
|
+
}).filter((o) => o !== null);
|
|
229
|
+
if (groupParams.length === 0) return false;
|
|
230
|
+
drawingManagerService.featurePluginUngroupUpdateNotification(groupParams);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/commands/operations/image-crop.operation.ts
|
|
237
|
+
const OpenImageCropOperation = {
|
|
238
|
+
id: "sheet.operation.open-image-crop",
|
|
239
|
+
type: CommandType.OPERATION,
|
|
240
|
+
handler: (accessor, params) => {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const CloseImageCropOperation = {
|
|
245
|
+
id: "sheet.operation.close-image-crop",
|
|
246
|
+
type: CommandType.OPERATION,
|
|
247
|
+
handler: (accessor, params) => {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const AutoImageCropOperation = {
|
|
252
|
+
id: "sheet.operation.Auto-image-crop",
|
|
253
|
+
type: CommandType.OPERATION,
|
|
254
|
+
handler: (accessor, params) => {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/commands/operations/image-reset-size.operation.ts
|
|
261
|
+
const ImageResetSizeOperation = {
|
|
262
|
+
id: "sheet.operation.image-reset-size",
|
|
263
|
+
type: CommandType.OPERATION,
|
|
264
|
+
handler: (accessor, params) => {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/controllers/utils.ts
|
|
271
|
+
function insertGroupObject(objectParam, object, scene, drawingManagerService) {
|
|
272
|
+
const groupParam = drawingManagerService.getDrawingByParam(objectParam);
|
|
273
|
+
if (groupParam == null) return;
|
|
274
|
+
const groupKey = getDrawingShapeKeyByDrawingSearch(objectParam);
|
|
275
|
+
const groupObject = scene.getObjectIncludeInGroup(groupKey);
|
|
276
|
+
if (groupObject && !(groupObject instanceof Group)) return;
|
|
277
|
+
if (groupObject != null) {
|
|
278
|
+
const objects = groupObject.getObjects();
|
|
279
|
+
for (const obj of objects) if (obj.oKey === object.oKey) return;
|
|
280
|
+
groupObject.addObject(object);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const group = new DrawingGroupObject(groupKey);
|
|
284
|
+
scene.addObject(group, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
|
|
285
|
+
group.addObject(object);
|
|
286
|
+
const { transform, groupBaseBound } = groupParam;
|
|
287
|
+
if (groupBaseBound) group.setBaseBound(groupBaseBound);
|
|
288
|
+
if (groupParam.groupId) {
|
|
289
|
+
group.isInGroup = true;
|
|
290
|
+
insertGroupObject({
|
|
291
|
+
drawingId: groupParam.groupId,
|
|
292
|
+
unitId: objectParam.unitId,
|
|
293
|
+
subUnitId: objectParam.subUnitId
|
|
294
|
+
}, group, scene, drawingManagerService);
|
|
295
|
+
}
|
|
296
|
+
transform && group.transformByState({
|
|
297
|
+
left: transform.left,
|
|
298
|
+
top: transform.top,
|
|
299
|
+
angle: transform.angle,
|
|
300
|
+
width: transform.width,
|
|
301
|
+
height: transform.height
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function getCurrentUnitInfo(currentUniverService, propUnitId) {
|
|
305
|
+
const current = propUnitId ? currentUniverService.getUnit(propUnitId) : currentUniverService.getFocusedUnit();
|
|
306
|
+
if (current == null) return;
|
|
307
|
+
const unitId = current.getUnitId();
|
|
308
|
+
let subUnitId;
|
|
309
|
+
if (current.type === UniverInstanceType.UNIVER_SHEET) {
|
|
310
|
+
var _getActiveSheet;
|
|
311
|
+
subUnitId = (_getActiveSheet = current.getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId();
|
|
312
|
+
} else if (current.type === UniverInstanceType.UNIVER_DOC) subUnitId = unitId;
|
|
313
|
+
else if (current.type === UniverInstanceType.UNIVER_SLIDE) subUnitId = unitId;
|
|
314
|
+
return {
|
|
315
|
+
unitId,
|
|
316
|
+
subUnitId,
|
|
317
|
+
current
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region package.json
|
|
323
|
+
var name = "@apollo-office/drawing-ui";
|
|
324
|
+
var version = "0.25.1";
|
|
325
|
+
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/config/config.ts
|
|
328
|
+
const DRAWING_UI_PLUGIN_CONFIG_KEY = "drawing-ui.config";
|
|
329
|
+
const configSymbol = Symbol(DRAWING_UI_PLUGIN_CONFIG_KEY);
|
|
330
|
+
const defaultPluginConfig = {};
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/menu/align.menu.ts
|
|
334
|
+
const getMenuStateByDrawingFocusChangedObservable$$1 = (accessor) => {
|
|
335
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
336
|
+
return new Observable((subscriber) => {
|
|
337
|
+
const update = (drawings) => {
|
|
338
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
339
|
+
if (drawings.length < 2) return subscriber.next(true);
|
|
340
|
+
subscriber.next(false);
|
|
341
|
+
};
|
|
342
|
+
const subscription = drawingManagerService.focus$.subscribe((drawings) => {
|
|
343
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
344
|
+
update(drawings);
|
|
345
|
+
});
|
|
346
|
+
update(drawingManagerService.getFocusDrawings());
|
|
347
|
+
return () => subscription.unsubscribe();
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
const DRAWING_ALIGN_CONTEXT_MENU_ID = "contextMenu.drawing-align";
|
|
351
|
+
function DrawingAlignContextMenuItemFactory(accessor) {
|
|
352
|
+
return {
|
|
353
|
+
id: DRAWING_ALIGN_CONTEXT_MENU_ID,
|
|
354
|
+
type: MenuItemType.SUBITEMS,
|
|
355
|
+
icon: "HorizontallyIcon",
|
|
356
|
+
title: "drawing-ui.image-panel.align.title",
|
|
357
|
+
hidden$: getMenuStateByDrawingFocusChangedObservable$$1(accessor)
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function SetDrawingAlignLeftMenuItemFactory() {
|
|
361
|
+
return {
|
|
362
|
+
id: SetDrawingAlignLeftOperation.id,
|
|
363
|
+
type: MenuItemType.BUTTON,
|
|
364
|
+
icon: "LeftJustifyingIcon",
|
|
365
|
+
title: "drawing-ui.image-panel.align.left"
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function SetDrawingAlignCenterMenuItemFactory() {
|
|
369
|
+
return {
|
|
370
|
+
id: SetDrawingAlignCenterOperation.id,
|
|
371
|
+
type: MenuItemType.BUTTON,
|
|
372
|
+
icon: "HorizontallyIcon",
|
|
373
|
+
title: "drawing-ui.image-panel.align.center"
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function SetDrawingAlignRightMenuItemFactory() {
|
|
377
|
+
return {
|
|
378
|
+
id: SetDrawingAlignRightOperation.id,
|
|
379
|
+
type: MenuItemType.BUTTON,
|
|
380
|
+
icon: "RightJustifyingIcon",
|
|
381
|
+
title: "drawing-ui.image-panel.align.right"
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function SetDrawingAlignTopMenuItemFactory() {
|
|
385
|
+
return {
|
|
386
|
+
id: SetDrawingAlignTopOperation.id,
|
|
387
|
+
type: MenuItemType.BUTTON,
|
|
388
|
+
icon: "AlignTopIcon",
|
|
389
|
+
title: "drawing-ui.image-panel.align.top"
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function SetDrawingAlignMiddleMenuItemFactory() {
|
|
393
|
+
return {
|
|
394
|
+
id: SetDrawingAlignMiddleOperation.id,
|
|
395
|
+
type: MenuItemType.BUTTON,
|
|
396
|
+
icon: "VerticalCenterIcon",
|
|
397
|
+
title: "drawing-ui.image-panel.align.middle"
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function SetDrawingAlignBottomMenuItemFactory() {
|
|
401
|
+
return {
|
|
402
|
+
id: SetDrawingAlignBottomOperation.id,
|
|
403
|
+
type: MenuItemType.BUTTON,
|
|
404
|
+
icon: "AlignBottomIcon",
|
|
405
|
+
title: "drawing-ui.image-panel.align.bottom"
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function SetDrawingAlignHorizonMenuItemFactory() {
|
|
409
|
+
return {
|
|
410
|
+
id: SetDrawingAlignHorizonOperation.id,
|
|
411
|
+
type: MenuItemType.BUTTON,
|
|
412
|
+
icon: "HorizontallyIcon",
|
|
413
|
+
title: "drawing-ui.image-panel.align.horizon"
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function SetDrawingAlignVerticalMenuItemFactory() {
|
|
417
|
+
return {
|
|
418
|
+
id: SetDrawingAlignVerticalOperation.id,
|
|
419
|
+
type: MenuItemType.BUTTON,
|
|
420
|
+
icon: "VerticalCenterIcon",
|
|
421
|
+
title: "drawing-ui.image-panel.align.vertical"
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region src/menu/arrange.menu.ts
|
|
427
|
+
const DRAWING_ARRANGE_CONTEXT_MENU_ID = "contextMenu.drawing-arrange";
|
|
428
|
+
function DrawingArrangeContextMenuItemFactory() {
|
|
429
|
+
return {
|
|
430
|
+
id: DRAWING_ARRANGE_CONTEXT_MENU_ID,
|
|
431
|
+
type: MenuItemType.SUBITEMS,
|
|
432
|
+
icon: "TopmostIcon",
|
|
433
|
+
title: "drawing-ui.image-panel.arrange.title"
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function SetDrawingArrangeFrontMenuItemFactory() {
|
|
437
|
+
return {
|
|
438
|
+
id: SetDrawingArrangeFrontOperation.id,
|
|
439
|
+
type: MenuItemType.BUTTON,
|
|
440
|
+
icon: "TopmostIcon",
|
|
441
|
+
title: "drawing-ui.image-panel.arrange.front"
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function SetDrawingArrangeForwardMenuItemFactory() {
|
|
445
|
+
return {
|
|
446
|
+
id: SetDrawingArrangeForwardOperation.id,
|
|
447
|
+
type: MenuItemType.BUTTON,
|
|
448
|
+
icon: "MoveUpIcon",
|
|
449
|
+
title: "drawing-ui.image-panel.arrange.forward"
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
function SetDrawingArrangeBackMenuItemFactory() {
|
|
453
|
+
return {
|
|
454
|
+
id: SetDrawingArrangeBackOperation.id,
|
|
455
|
+
type: MenuItemType.BUTTON,
|
|
456
|
+
icon: "BottomIcon",
|
|
457
|
+
title: "drawing-ui.image-panel.arrange.back"
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function SetDrawingArrangeBackwardMenuItemFactory() {
|
|
461
|
+
return {
|
|
462
|
+
id: SetDrawingArrangeBackwardOperation.id,
|
|
463
|
+
type: MenuItemType.BUTTON,
|
|
464
|
+
icon: "MoveDownIcon",
|
|
465
|
+
title: "drawing-ui.image-panel.arrange.backward"
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/menu/group.menu.ts
|
|
471
|
+
const getMenuStateByDrawingFocusChangedObservable$ = (accessor, type) => {
|
|
472
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
473
|
+
return new Observable((subscriber) => {
|
|
474
|
+
const update = (drawings) => {
|
|
475
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
476
|
+
if (type === "group") {
|
|
477
|
+
if (drawings.length < 2) return subscriber.next(true);
|
|
478
|
+
if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
|
|
479
|
+
} else if (type === "unGroup") {
|
|
480
|
+
if (drawings.filter((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_GROUP).length === 0) return subscriber.next(true);
|
|
481
|
+
} else if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
|
|
482
|
+
subscriber.next(false);
|
|
483
|
+
};
|
|
484
|
+
const subscription = drawingManagerService.focus$.subscribe((drawings) => {
|
|
485
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
486
|
+
update(drawings);
|
|
487
|
+
});
|
|
488
|
+
update(drawingManagerService.getFocusDrawings());
|
|
489
|
+
return () => subscription.unsubscribe();
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
const DRAWING_GROUP_CONTEXT_MENU_ID = "contextMenu.drawing-group";
|
|
493
|
+
function DrawingGroupContextMenuItemFactory(accessor) {
|
|
494
|
+
return {
|
|
495
|
+
id: DRAWING_GROUP_CONTEXT_MENU_ID,
|
|
496
|
+
type: MenuItemType.SUBITEMS,
|
|
497
|
+
icon: "GroupIcon",
|
|
498
|
+
title: "drawing-ui.image-panel.group.title",
|
|
499
|
+
hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor)
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function SetDrawingGroupMenuItemFactory(accessor) {
|
|
503
|
+
return {
|
|
504
|
+
id: SetDrawingGroupOperation.id,
|
|
505
|
+
type: MenuItemType.BUTTON,
|
|
506
|
+
icon: "GroupIcon",
|
|
507
|
+
title: "drawing-ui.image-panel.group.group",
|
|
508
|
+
disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "group")
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function CancelDrawingGroupMenuItemFactory(accessor) {
|
|
512
|
+
return {
|
|
513
|
+
id: CancelDrawingGroupOperation.id,
|
|
514
|
+
type: MenuItemType.BUTTON,
|
|
515
|
+
icon: "UngroupIcon",
|
|
516
|
+
title: "drawing-ui.image-panel.group.unGroup",
|
|
517
|
+
disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "unGroup")
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/menu/schema.ts
|
|
523
|
+
const menuSchema = { [ContextMenuPosition.DRAWING]: { [ContextMenuGroup.OTHERS]: {
|
|
524
|
+
[DRAWING_GROUP_CONTEXT_MENU_ID]: {
|
|
525
|
+
order: 1,
|
|
526
|
+
menuItemFactory: DrawingGroupContextMenuItemFactory,
|
|
527
|
+
[SetDrawingGroupOperation.id]: {
|
|
528
|
+
order: 0,
|
|
529
|
+
menuItemFactory: SetDrawingGroupMenuItemFactory
|
|
530
|
+
},
|
|
531
|
+
[CancelDrawingGroupOperation.id]: {
|
|
532
|
+
order: 1,
|
|
533
|
+
menuItemFactory: CancelDrawingGroupMenuItemFactory
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
[DRAWING_ARRANGE_CONTEXT_MENU_ID]: {
|
|
537
|
+
order: 2,
|
|
538
|
+
menuItemFactory: DrawingArrangeContextMenuItemFactory,
|
|
539
|
+
[SetDrawingArrangeFrontOperation.id]: {
|
|
540
|
+
order: 0,
|
|
541
|
+
menuItemFactory: SetDrawingArrangeFrontMenuItemFactory
|
|
542
|
+
},
|
|
543
|
+
[SetDrawingArrangeForwardOperation.id]: {
|
|
544
|
+
order: 1,
|
|
545
|
+
menuItemFactory: SetDrawingArrangeForwardMenuItemFactory
|
|
546
|
+
},
|
|
547
|
+
[SetDrawingArrangeBackOperation.id]: {
|
|
548
|
+
order: 2,
|
|
549
|
+
menuItemFactory: SetDrawingArrangeBackMenuItemFactory
|
|
550
|
+
},
|
|
551
|
+
[SetDrawingArrangeBackwardOperation.id]: {
|
|
552
|
+
order: 3,
|
|
553
|
+
menuItemFactory: SetDrawingArrangeBackwardMenuItemFactory
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
[DRAWING_ALIGN_CONTEXT_MENU_ID]: {
|
|
557
|
+
order: 3,
|
|
558
|
+
menuItemFactory: DrawingAlignContextMenuItemFactory,
|
|
559
|
+
[SetDrawingAlignLeftOperation.id]: {
|
|
560
|
+
order: 0,
|
|
561
|
+
menuItemFactory: SetDrawingAlignLeftMenuItemFactory
|
|
562
|
+
},
|
|
563
|
+
[SetDrawingAlignCenterOperation.id]: {
|
|
564
|
+
order: 1,
|
|
565
|
+
menuItemFactory: SetDrawingAlignCenterMenuItemFactory
|
|
566
|
+
},
|
|
567
|
+
[SetDrawingAlignRightOperation.id]: {
|
|
568
|
+
order: 2,
|
|
569
|
+
menuItemFactory: SetDrawingAlignRightMenuItemFactory
|
|
570
|
+
},
|
|
571
|
+
[SetDrawingAlignTopOperation.id]: {
|
|
572
|
+
order: 3,
|
|
573
|
+
menuItemFactory: SetDrawingAlignTopMenuItemFactory
|
|
574
|
+
},
|
|
575
|
+
[SetDrawingAlignMiddleOperation.id]: {
|
|
576
|
+
order: 4,
|
|
577
|
+
menuItemFactory: SetDrawingAlignMiddleMenuItemFactory
|
|
578
|
+
},
|
|
579
|
+
[SetDrawingAlignBottomOperation.id]: {
|
|
580
|
+
order: 5,
|
|
581
|
+
menuItemFactory: SetDrawingAlignBottomMenuItemFactory
|
|
582
|
+
},
|
|
583
|
+
[SetDrawingAlignHorizonOperation.id]: {
|
|
584
|
+
order: 6,
|
|
585
|
+
menuItemFactory: SetDrawingAlignHorizonMenuItemFactory
|
|
586
|
+
},
|
|
587
|
+
[SetDrawingAlignVerticalOperation.id]: {
|
|
588
|
+
order: 7,
|
|
589
|
+
menuItemFactory: SetDrawingAlignVerticalMenuItemFactory
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
} } };
|
|
593
|
+
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/views/image-popup-menu/component-name.ts
|
|
596
|
+
/**
|
|
597
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
598
|
+
*
|
|
599
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
600
|
+
* you may not use this file except in compliance with the License.
|
|
601
|
+
* You may obtain a copy of the License at
|
|
602
|
+
*
|
|
603
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
604
|
+
*
|
|
605
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
606
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
607
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
608
|
+
* See the License for the specific language governing permissions and
|
|
609
|
+
* limitations under the License.
|
|
610
|
+
*/
|
|
611
|
+
const COMPONENT_IMAGE_POPUP_MENU = "COMPONENT_IMAGE_POPUP_MENU";
|
|
612
|
+
|
|
613
|
+
//#endregion
|
|
614
|
+
//#region src/views/image-popup-menu/ImagePopupMenu.tsx
|
|
615
|
+
function ImagePopupMenu(props) {
|
|
616
|
+
var _popup$extraProps, _popup$extraProps2;
|
|
617
|
+
const { popup } = props;
|
|
618
|
+
const menuItems = popup === null || popup === void 0 || (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.menuItems;
|
|
619
|
+
if (!menuItems) return null;
|
|
620
|
+
if (((_popup$extraProps2 = popup.extraProps) === null || _popup$extraProps2 === void 0 ? void 0 : _popup$extraProps2.variant) === "doc-floating-toolbar" && popup.extraProps.unitId && popup.extraProps.subUnitId && popup.extraProps.drawingId) return /* @__PURE__ */ jsx(DocImageFloatingToolbar, {
|
|
621
|
+
menuItems,
|
|
622
|
+
unitId: popup.extraProps.unitId,
|
|
623
|
+
subUnitId: popup.extraProps.subUnitId,
|
|
624
|
+
drawingId: popup.extraProps.drawingId
|
|
625
|
+
});
|
|
626
|
+
const commandService = useDependency(ICommandService);
|
|
627
|
+
const localeService = useDependency(LocaleService);
|
|
628
|
+
const [visible, setVisible] = useState(false);
|
|
629
|
+
const [isHovered, setHovered] = useState(false);
|
|
630
|
+
const handleMouseEnter = () => {
|
|
631
|
+
setHovered(true);
|
|
632
|
+
};
|
|
633
|
+
const handleMouseLeave = () => {
|
|
634
|
+
setHovered(false);
|
|
635
|
+
};
|
|
636
|
+
const onVisibleChange = (visible) => {
|
|
637
|
+
setVisible(visible);
|
|
638
|
+
};
|
|
639
|
+
const handleClick = (item) => {
|
|
640
|
+
commandService.executeCommand(item.commandId, item.commandParams);
|
|
641
|
+
setVisible(false);
|
|
642
|
+
};
|
|
643
|
+
const showMore = visible || isHovered;
|
|
644
|
+
return /* @__PURE__ */ jsx("div", {
|
|
645
|
+
onMouseEnter: handleMouseEnter,
|
|
646
|
+
onMouseLeave: handleMouseLeave,
|
|
647
|
+
children: /* @__PURE__ */ jsx(DropdownMenu, {
|
|
648
|
+
align: "start",
|
|
649
|
+
items: menuItems.map((item) => ({
|
|
650
|
+
type: "item",
|
|
651
|
+
children: localeService.t(item.label),
|
|
652
|
+
disabled: item.disable,
|
|
653
|
+
onSelect: () => handleClick(item)
|
|
654
|
+
})),
|
|
655
|
+
open: visible,
|
|
656
|
+
onOpenChange: onVisibleChange,
|
|
657
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
658
|
+
className: clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", borderClassName, {
|
|
659
|
+
"univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
|
|
660
|
+
"univer-bg-white dark:!univer-bg-gray-900": !visible
|
|
661
|
+
}),
|
|
662
|
+
children: [/* @__PURE__ */ jsx(AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ jsx(MoreDownIcon, { className: "dark:!univer-text-white" })]
|
|
663
|
+
})
|
|
664
|
+
})
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
const UPDATE_DOC_DRAWING_WRAPPING_STYLE_COMMAND_ID = "doc.command.update-doc-drawing-wrapping-style";
|
|
668
|
+
function getWrappingStyle(documentDataModel, drawingId) {
|
|
669
|
+
var _documentDataModel$ge;
|
|
670
|
+
const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingId];
|
|
671
|
+
if (!drawing) return "inline";
|
|
672
|
+
if (drawing.layoutType === PositionedObjectLayoutType.WRAP_NONE) return drawing.behindDoc === BooleanNumber.TRUE ? "behindText" : "inFrontOfText";
|
|
673
|
+
if (drawing.layoutType === PositionedObjectLayoutType.WRAP_SQUARE) return "wrapSquare";
|
|
674
|
+
if (drawing.layoutType === PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) return "wrapTopAndBottom";
|
|
675
|
+
return "inline";
|
|
676
|
+
}
|
|
677
|
+
function Divider() {
|
|
678
|
+
return /* @__PURE__ */ jsx("span", { className: "\r\n univer-h-5 univer-w-px univer-bg-gray-200\r\n dark:!univer-bg-gray-700\r\n " });
|
|
679
|
+
}
|
|
680
|
+
function ToolbarGroup(props) {
|
|
681
|
+
return /* @__PURE__ */ jsx("div", {
|
|
682
|
+
className: "univer-flex univer-h-7 univer-items-center univer-gap-1 univer-px-1",
|
|
683
|
+
children: props.children
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
function ToolbarButton(props) {
|
|
687
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
688
|
+
title: props.title,
|
|
689
|
+
placement: "bottom",
|
|
690
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
691
|
+
type: "button",
|
|
692
|
+
disabled: props.disabled,
|
|
693
|
+
onClick: props.onClick,
|
|
694
|
+
className: clsx("univer-flex univer-h-6 univer-w-6 univer-items-center univer-justify-center univer-rounded-md univer-border-none univer-bg-transparent univer-p-0 univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 disabled:univer-cursor-not-allowed disabled:univer-opacity-40 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-bg-gray-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-300": props.active }),
|
|
695
|
+
children: props.children
|
|
696
|
+
})
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
function TextWrapShapeIcon() {
|
|
700
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
701
|
+
viewBox: "0 0 20 20",
|
|
702
|
+
width: "1em",
|
|
703
|
+
height: "1em",
|
|
704
|
+
fill: "none",
|
|
705
|
+
"aria-hidden": "true",
|
|
706
|
+
children: [
|
|
707
|
+
/* @__PURE__ */ jsx("path", {
|
|
708
|
+
d: "M2.5 4.5H8.2",
|
|
709
|
+
stroke: "currentColor",
|
|
710
|
+
strokeWidth: "1.4",
|
|
711
|
+
strokeLinecap: "round"
|
|
712
|
+
}),
|
|
713
|
+
/* @__PURE__ */ jsx("path", {
|
|
714
|
+
d: "M11.8 4.5H17.5",
|
|
715
|
+
stroke: "currentColor",
|
|
716
|
+
strokeWidth: "1.4",
|
|
717
|
+
strokeLinecap: "round"
|
|
718
|
+
}),
|
|
719
|
+
/* @__PURE__ */ jsx("path", {
|
|
720
|
+
d: "M2.5 10H5.7",
|
|
721
|
+
stroke: "currentColor",
|
|
722
|
+
strokeWidth: "1.4",
|
|
723
|
+
strokeLinecap: "round"
|
|
724
|
+
}),
|
|
725
|
+
/* @__PURE__ */ jsx("path", {
|
|
726
|
+
d: "M14.3 10H17.5",
|
|
727
|
+
stroke: "currentColor",
|
|
728
|
+
strokeWidth: "1.4",
|
|
729
|
+
strokeLinecap: "round"
|
|
730
|
+
}),
|
|
731
|
+
/* @__PURE__ */ jsx("path", {
|
|
732
|
+
d: "M2.5 15.5H8.2",
|
|
733
|
+
stroke: "currentColor",
|
|
734
|
+
strokeWidth: "1.4",
|
|
735
|
+
strokeLinecap: "round"
|
|
736
|
+
}),
|
|
737
|
+
/* @__PURE__ */ jsx("path", {
|
|
738
|
+
d: "M11.8 15.5H17.5",
|
|
739
|
+
stroke: "currentColor",
|
|
740
|
+
strokeWidth: "1.4",
|
|
741
|
+
strokeLinecap: "round"
|
|
742
|
+
}),
|
|
743
|
+
/* @__PURE__ */ jsx("rect", {
|
|
744
|
+
x: "6.8",
|
|
745
|
+
y: "7",
|
|
746
|
+
width: "6.4",
|
|
747
|
+
height: "6",
|
|
748
|
+
rx: "1",
|
|
749
|
+
stroke: "currentColor",
|
|
750
|
+
strokeWidth: "1.4"
|
|
751
|
+
})
|
|
752
|
+
]
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
function CropIcon() {
|
|
756
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
757
|
+
viewBox: "0 0 20 20",
|
|
758
|
+
width: "1em",
|
|
759
|
+
height: "1em",
|
|
760
|
+
fill: "none",
|
|
761
|
+
"aria-hidden": "true",
|
|
762
|
+
children: [
|
|
763
|
+
/* @__PURE__ */ jsx("path", {
|
|
764
|
+
d: "M5 2.8V12.5C5 13.9 6.1 15 7.5 15H17.2",
|
|
765
|
+
stroke: "currentColor",
|
|
766
|
+
strokeWidth: "1.5",
|
|
767
|
+
strokeLinecap: "round"
|
|
768
|
+
}),
|
|
769
|
+
/* @__PURE__ */ jsx("path", {
|
|
770
|
+
d: "M2.8 5H12.5C13.9 5 15 6.1 15 7.5V17.2",
|
|
771
|
+
stroke: "currentColor",
|
|
772
|
+
strokeWidth: "1.5",
|
|
773
|
+
strokeLinecap: "round"
|
|
774
|
+
}),
|
|
775
|
+
/* @__PURE__ */ jsx("path", {
|
|
776
|
+
d: "M8.3 8.3H11.7V11.7H8.3V8.3Z",
|
|
777
|
+
stroke: "currentColor",
|
|
778
|
+
strokeWidth: "1.2"
|
|
779
|
+
})
|
|
780
|
+
]
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
function ToolbarDropdownButton(props) {
|
|
784
|
+
var _props$options$find;
|
|
785
|
+
const [open, setOpen] = useState(false);
|
|
786
|
+
const activeOption = (_props$options$find = props.options.find((option) => option.value === props.value)) !== null && _props$options$find !== void 0 ? _props$options$find : props.options[0];
|
|
787
|
+
return /* @__PURE__ */ jsx(Dropdown, {
|
|
788
|
+
open,
|
|
789
|
+
onOpenChange: setOpen,
|
|
790
|
+
overlay: /* @__PURE__ */ jsx("div", {
|
|
791
|
+
className: "univer-min-w-32 univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-white univer-p-1 univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
|
|
792
|
+
children: props.options.map((option) => /* @__PURE__ */ jsxs("button", {
|
|
793
|
+
type: "button",
|
|
794
|
+
onClick: () => {
|
|
795
|
+
props.onChange(option.value);
|
|
796
|
+
setOpen(false);
|
|
797
|
+
},
|
|
798
|
+
className: clsx("univer-flex univer-h-8 univer-w-full univer-items-center univer-gap-2 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-800", { "univer-bg-primary-50 univer-text-primary-600 dark:!univer-bg-gray-800 dark:!univer-text-primary-300": option.value === props.value }),
|
|
799
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
800
|
+
className: "univer-flex univer-size-4 univer-items-center univer-justify-center",
|
|
801
|
+
children: option.icon
|
|
802
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
803
|
+
className: "univer-flex-1",
|
|
804
|
+
children: option.label
|
|
805
|
+
})]
|
|
806
|
+
}, option.value))
|
|
807
|
+
}),
|
|
808
|
+
children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(Tooltip, {
|
|
809
|
+
title: props.title,
|
|
810
|
+
placement: "bottom",
|
|
811
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
812
|
+
type: "button",
|
|
813
|
+
className: clsx("univer-flex univer-h-6 univer-min-w-9 univer-items-center univer-justify-center univer-gap-1 univer-rounded-md univer-border-none univer-bg-transparent univer-px-1.5 univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-bg-gray-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-300": open }),
|
|
814
|
+
children: [activeOption.icon, /* @__PURE__ */ jsx(MoreDownIcon, { className: "univer-text-xs" })]
|
|
815
|
+
})
|
|
816
|
+
}) })
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
function DocImageFloatingToolbar(props) {
|
|
820
|
+
var _univerInstanceServic, _wrappingStyleOptions, _wrappingStyleOptions2;
|
|
821
|
+
const commandService = useDependency(ICommandService);
|
|
822
|
+
const localeService = useDependency(LocaleService);
|
|
823
|
+
const documentDataModel = (_univerInstanceServic = useDependency(IUniverInstanceService).getUnit(props.unitId, UniverInstanceType.UNIVER_DOC)) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : void 0;
|
|
824
|
+
const [wrappingStyle, setWrappingStyle] = useState(() => getWrappingStyle(documentDataModel, props.drawingId));
|
|
825
|
+
const [hidden, setHidden] = useState(false);
|
|
826
|
+
const getMenuItem = (label) => props.menuItems.find((item) => item.label === label);
|
|
827
|
+
const editItem = getMenuItem("drawing-ui.image-popup.edit");
|
|
828
|
+
const cropItem = getMenuItem("drawing-ui.image-popup.crop");
|
|
829
|
+
const deleteItem = getMenuItem("drawing-ui.image-popup.delete");
|
|
830
|
+
const wrappingStyleOptions = [
|
|
831
|
+
{
|
|
832
|
+
label: localeService.t("drawing-ui.image-text-wrap.inline"),
|
|
833
|
+
value: "inline",
|
|
834
|
+
icon: /* @__PURE__ */ jsx(TextWrapShapeIcon, {})
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
label: localeService.t("drawing-ui.image-text-wrap.square"),
|
|
838
|
+
value: "wrapSquare",
|
|
839
|
+
icon: /* @__PURE__ */ jsx(TextWrapShapeIcon, {})
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
label: localeService.t("drawing-ui.image-text-wrap.topAndBottom"),
|
|
843
|
+
value: "wrapTopAndBottom",
|
|
844
|
+
icon: /* @__PURE__ */ jsx(TextWrapShapeIcon, {})
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
label: localeService.t("drawing-ui.image-text-wrap.behindText"),
|
|
848
|
+
value: "behindText",
|
|
849
|
+
icon: /* @__PURE__ */ jsx(TextWrapShapeIcon, {})
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
label: localeService.t("drawing-ui.image-text-wrap.inFrontText"),
|
|
853
|
+
value: "inFrontOfText",
|
|
854
|
+
icon: /* @__PURE__ */ jsx(TextWrapShapeIcon, {})
|
|
855
|
+
}
|
|
856
|
+
];
|
|
857
|
+
const executeMenuItem = (item) => {
|
|
858
|
+
if (!item || item.disable) return;
|
|
859
|
+
commandService.executeCommand(item.commandId, item.commandParams);
|
|
860
|
+
};
|
|
861
|
+
const updateWrappingStyle = (value) => {
|
|
862
|
+
setWrappingStyle(value);
|
|
863
|
+
commandService.executeCommand(UPDATE_DOC_DRAWING_WRAPPING_STYLE_COMMAND_ID, {
|
|
864
|
+
unitId: props.unitId,
|
|
865
|
+
subUnitId: props.subUnitId,
|
|
866
|
+
drawings: [{
|
|
867
|
+
unitId: props.unitId,
|
|
868
|
+
subUnitId: props.subUnitId,
|
|
869
|
+
drawingId: props.drawingId
|
|
870
|
+
}],
|
|
871
|
+
wrappingStyle: value
|
|
872
|
+
});
|
|
873
|
+
};
|
|
874
|
+
if (hidden) return null;
|
|
875
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
876
|
+
"data-u-comp": "doc-image-floating-toolbar",
|
|
877
|
+
onMouseDown: (event) => {
|
|
878
|
+
event.stopPropagation();
|
|
879
|
+
event.preventDefault();
|
|
880
|
+
},
|
|
881
|
+
className: clsx("univer-box-border univer-flex univer-items-center univer-rounded univer-bg-white univer-px-1 univer-py-1 univer-shadow-sm dark:!univer-border-gray-700 dark:!univer-bg-gray-900", borderClassName),
|
|
882
|
+
children: [
|
|
883
|
+
/* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(ToolbarDropdownButton, {
|
|
884
|
+
title: (_wrappingStyleOptions = (_wrappingStyleOptions2 = wrappingStyleOptions.find((option) => option.value === wrappingStyle)) === null || _wrappingStyleOptions2 === void 0 ? void 0 : _wrappingStyleOptions2.label) !== null && _wrappingStyleOptions !== void 0 ? _wrappingStyleOptions : localeService.t("drawing-ui.image-text-wrap.inline"),
|
|
885
|
+
value: wrappingStyle,
|
|
886
|
+
options: wrappingStyleOptions,
|
|
887
|
+
onChange: updateWrappingStyle
|
|
888
|
+
}) }),
|
|
889
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
890
|
+
/* @__PURE__ */ jsxs(ToolbarGroup, { children: [/* @__PURE__ */ jsx(ToolbarButton, {
|
|
891
|
+
title: editItem ? localeService.t(editItem.label) : localeService.t("drawing-ui.image-popup.edit"),
|
|
892
|
+
disabled: !editItem || editItem.disable,
|
|
893
|
+
onClick: () => {
|
|
894
|
+
setHidden(true);
|
|
895
|
+
executeMenuItem(editItem);
|
|
896
|
+
},
|
|
897
|
+
children: /* @__PURE__ */ jsx(DocSettingIcon, {})
|
|
898
|
+
}), /* @__PURE__ */ jsx(ToolbarButton, {
|
|
899
|
+
title: cropItem ? localeService.t(cropItem.label) : localeService.t("drawing-ui.image-popup.crop"),
|
|
900
|
+
disabled: !cropItem || cropItem.disable,
|
|
901
|
+
onClick: () => executeMenuItem(cropItem),
|
|
902
|
+
children: /* @__PURE__ */ jsx(CropIcon, {})
|
|
903
|
+
})] }),
|
|
904
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
905
|
+
/* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(ToolbarButton, {
|
|
906
|
+
title: deleteItem ? localeService.t(deleteItem.label) : localeService.t("drawing-ui.image-popup.delete"),
|
|
907
|
+
disabled: !deleteItem || deleteItem.disable,
|
|
908
|
+
onClick: () => executeMenuItem(deleteItem),
|
|
909
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
910
|
+
}) })
|
|
911
|
+
]
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
917
|
+
function __decorateParam(paramIndex, decorator) {
|
|
918
|
+
return function(target, key) {
|
|
919
|
+
decorator(target, key, paramIndex);
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
|
|
925
|
+
function __decorate(decorators, target, key, desc) {
|
|
926
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
927
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
928
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
929
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
//#endregion
|
|
933
|
+
//#region src/controllers/drawing-ui.controller.ts
|
|
934
|
+
/**
|
|
935
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
936
|
+
*
|
|
937
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
938
|
+
* you may not use this file except in compliance with the License.
|
|
939
|
+
* You may obtain a copy of the License at
|
|
940
|
+
*
|
|
941
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
942
|
+
*
|
|
943
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
944
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
945
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
946
|
+
* See the License for the specific language governing permissions and
|
|
947
|
+
* limitations under the License.
|
|
948
|
+
*/
|
|
949
|
+
let DrawingUIController = class DrawingUIController extends Disposable {
|
|
950
|
+
constructor(_componentManager, _commandService, _menuManagerService) {
|
|
951
|
+
super();
|
|
952
|
+
this._componentManager = _componentManager;
|
|
953
|
+
this._commandService = _commandService;
|
|
954
|
+
this._menuManagerService = _menuManagerService;
|
|
955
|
+
this._init();
|
|
956
|
+
}
|
|
957
|
+
_init() {
|
|
958
|
+
this._initMenus();
|
|
959
|
+
this._initCommands();
|
|
960
|
+
this._initComponents();
|
|
961
|
+
}
|
|
962
|
+
_initMenus() {
|
|
963
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
964
|
+
}
|
|
965
|
+
_initCommands() {
|
|
966
|
+
[
|
|
967
|
+
OpenImageCropOperation,
|
|
968
|
+
CloseImageCropOperation,
|
|
969
|
+
ImageResetSizeOperation,
|
|
970
|
+
SetDrawingAlignOperation,
|
|
971
|
+
SetDrawingAlignLeftOperation,
|
|
972
|
+
SetDrawingAlignCenterOperation,
|
|
973
|
+
SetDrawingAlignRightOperation,
|
|
974
|
+
SetDrawingAlignTopOperation,
|
|
975
|
+
SetDrawingAlignMiddleOperation,
|
|
976
|
+
SetDrawingAlignBottomOperation,
|
|
977
|
+
SetDrawingAlignHorizonOperation,
|
|
978
|
+
SetDrawingAlignVerticalOperation,
|
|
979
|
+
AutoImageCropOperation,
|
|
980
|
+
SetDrawingGroupOperation,
|
|
981
|
+
CancelDrawingGroupOperation,
|
|
982
|
+
SetDrawingArrangeOperation,
|
|
983
|
+
SetDrawingArrangeFrontOperation,
|
|
984
|
+
SetDrawingArrangeForwardOperation,
|
|
985
|
+
SetDrawingArrangeBackOperation,
|
|
986
|
+
SetDrawingArrangeBackwardOperation
|
|
987
|
+
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
988
|
+
}
|
|
989
|
+
_initComponents() {
|
|
990
|
+
[
|
|
991
|
+
[COMPONENT_IMAGE_POPUP_MENU, ImagePopupMenu],
|
|
992
|
+
["BottomIcon", BottomIcon],
|
|
993
|
+
["GroupIcon", GroupIcon],
|
|
994
|
+
["MoveDownIcon", MoveDownIcon],
|
|
995
|
+
["MoveUpIcon", MoveUpIcon],
|
|
996
|
+
["TopmostIcon", TopmostIcon],
|
|
997
|
+
["UngroupIcon", UngroupIcon]
|
|
998
|
+
].forEach(([key, component]) => {
|
|
999
|
+
this.disposeWithMe(this._componentManager.register(key, component));
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
DrawingUIController = __decorate([
|
|
1004
|
+
__decorateParam(0, Inject(ComponentManager)),
|
|
1005
|
+
__decorateParam(1, ICommandService),
|
|
1006
|
+
__decorateParam(2, IMenuManagerService)
|
|
1007
|
+
], DrawingUIController);
|
|
1008
|
+
|
|
1009
|
+
//#endregion
|
|
1010
|
+
//#region src/utils/get-update-params.ts
|
|
1011
|
+
function getUpdateParams(objects, drawingManagerService) {
|
|
1012
|
+
const params = [];
|
|
1013
|
+
objects.forEach((object) => {
|
|
1014
|
+
const { oKey, left, top, height, width, angle } = object;
|
|
1015
|
+
const searchParam = drawingManagerService.getDrawingOKey(oKey);
|
|
1016
|
+
if (searchParam == null) {
|
|
1017
|
+
params.push(null);
|
|
1018
|
+
return true;
|
|
1019
|
+
}
|
|
1020
|
+
const { unitId, subUnitId, drawingId, drawingType } = searchParam;
|
|
1021
|
+
const param = {
|
|
1022
|
+
unitId,
|
|
1023
|
+
subUnitId,
|
|
1024
|
+
drawingId,
|
|
1025
|
+
drawingType,
|
|
1026
|
+
transform: {
|
|
1027
|
+
left,
|
|
1028
|
+
top,
|
|
1029
|
+
height,
|
|
1030
|
+
width,
|
|
1031
|
+
angle
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
if (drawingType === DrawingTypeEnum.DRAWING_IMAGE) param.srcRect = object.srcRect;
|
|
1035
|
+
params.push(param);
|
|
1036
|
+
});
|
|
1037
|
+
return params;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
1042
|
+
function _typeof(o) {
|
|
1043
|
+
"@babel/helpers - typeof";
|
|
1044
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
1045
|
+
return typeof o;
|
|
1046
|
+
} : function(o) {
|
|
1047
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
1048
|
+
}, _typeof(o);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
//#endregion
|
|
1052
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
1053
|
+
function toPrimitive(t, r) {
|
|
1054
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
1055
|
+
var e = t[Symbol.toPrimitive];
|
|
1056
|
+
if (void 0 !== e) {
|
|
1057
|
+
var i = e.call(t, r || "default");
|
|
1058
|
+
if ("object" != _typeof(i)) return i;
|
|
1059
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1060
|
+
}
|
|
1061
|
+
return ("string" === r ? String : Number)(t);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
//#endregion
|
|
1065
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
1066
|
+
function toPropertyKey(t) {
|
|
1067
|
+
var i = toPrimitive(t, "string");
|
|
1068
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
1073
|
+
function _defineProperty(e, r, t) {
|
|
1074
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1075
|
+
value: t,
|
|
1076
|
+
enumerable: !0,
|
|
1077
|
+
configurable: !0,
|
|
1078
|
+
writable: !0
|
|
1079
|
+
}) : e[r] = t, e;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
//#endregion
|
|
1083
|
+
//#region src/controllers/drawing-update.controller.ts
|
|
1084
|
+
let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
1085
|
+
constructor(_currentUniverService, _commandService, _renderManagerService, _drawingManagerService) {
|
|
1086
|
+
super();
|
|
1087
|
+
this._currentUniverService = _currentUniverService;
|
|
1088
|
+
this._commandService = _commandService;
|
|
1089
|
+
this._renderManagerService = _renderManagerService;
|
|
1090
|
+
this._drawingManagerService = _drawingManagerService;
|
|
1091
|
+
_defineProperty(this, "_sceneListenerOnDrawingMap", /* @__PURE__ */ new WeakSet());
|
|
1092
|
+
this._initialize();
|
|
1093
|
+
}
|
|
1094
|
+
dispose() {
|
|
1095
|
+
super.dispose();
|
|
1096
|
+
}
|
|
1097
|
+
_initialize() {
|
|
1098
|
+
this._recoveryImages();
|
|
1099
|
+
this._drawingAddListener();
|
|
1100
|
+
this._drawingRemoveListener();
|
|
1101
|
+
this._drawingUpdateListener();
|
|
1102
|
+
this._commandExecutedListener();
|
|
1103
|
+
this._drawingArrangeListener();
|
|
1104
|
+
this._drawingGroupListener();
|
|
1105
|
+
this._drawingRefreshListener();
|
|
1106
|
+
this._drawingVisibleListener();
|
|
1107
|
+
}
|
|
1108
|
+
_recoveryImages() {
|
|
1109
|
+
const drawingList = this._drawingManagerService.drawingManagerData;
|
|
1110
|
+
const info = getCurrentUnitInfo(this._currentUniverService);
|
|
1111
|
+
if (info == null) return;
|
|
1112
|
+
const { unitId: currentUnitId, subUnitId: currentSubUnitId } = info;
|
|
1113
|
+
Object.keys(drawingList).forEach((unitId) => {
|
|
1114
|
+
Object.keys(drawingList[unitId]).forEach((subUnitId) => {
|
|
1115
|
+
const drawingMap = drawingList[unitId][subUnitId].data;
|
|
1116
|
+
if (drawingMap == null || unitId !== currentUnitId || subUnitId !== currentSubUnitId) return;
|
|
1117
|
+
Object.keys(drawingMap).forEach((drawingId) => {
|
|
1118
|
+
if (drawingMap[drawingId]) this._insertDrawing([{
|
|
1119
|
+
unitId,
|
|
1120
|
+
subUnitId,
|
|
1121
|
+
drawingId
|
|
1122
|
+
}]);
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
_commandExecutedListener() {
|
|
1128
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1129
|
+
if (command.id === SetDrawingAlignOperation.id) {
|
|
1130
|
+
const params = command.params;
|
|
1131
|
+
if (params == null) return;
|
|
1132
|
+
this._drawingAlign(params);
|
|
1133
|
+
}
|
|
1134
|
+
}));
|
|
1135
|
+
}
|
|
1136
|
+
_drawingGroupListener() {
|
|
1137
|
+
this.disposeWithMe(this._drawingManagerService.group$.subscribe((params) => {
|
|
1138
|
+
this._groupDrawings(params);
|
|
1139
|
+
}));
|
|
1140
|
+
this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe((params) => {
|
|
1141
|
+
this._ungroupDrawings(params);
|
|
1142
|
+
}));
|
|
1143
|
+
}
|
|
1144
|
+
_getSceneAndTransformerByDrawingSearch(unitId) {
|
|
1145
|
+
if (unitId == null) return;
|
|
1146
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1147
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1148
|
+
if (scene == null) return null;
|
|
1149
|
+
return {
|
|
1150
|
+
scene,
|
|
1151
|
+
transformer: scene.getTransformerByCreate()
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
_groupDrawings(drawings) {
|
|
1155
|
+
drawings.forEach((drawing) => {
|
|
1156
|
+
this._groupDrawing(drawing);
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
_groupDrawing(params) {
|
|
1160
|
+
const { parent, children } = params;
|
|
1161
|
+
const { unitId, subUnitId, drawingId } = parent;
|
|
1162
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(parent.unitId);
|
|
1163
|
+
if (renderObject == null) return;
|
|
1164
|
+
const { scene, transformer } = renderObject;
|
|
1165
|
+
this._commandService.syncExecuteCommand(CloseImageCropOperation.id);
|
|
1166
|
+
const objects = [];
|
|
1167
|
+
children.forEach((drawing) => {
|
|
1168
|
+
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch(drawing);
|
|
1169
|
+
const object = scene.getObjectIncludeInGroup(drawingShapeKey);
|
|
1170
|
+
if (object == null || objects.includes(object)) return;
|
|
1171
|
+
objects.push(object);
|
|
1172
|
+
const { transform } = drawing;
|
|
1173
|
+
if (transform == null) return;
|
|
1174
|
+
if (object.classType === RENDER_CLASS_TYPE.GROUP) object.transformByState({
|
|
1175
|
+
left: transform.left,
|
|
1176
|
+
top: transform.top
|
|
1177
|
+
});
|
|
1178
|
+
else object.transformByState(transform);
|
|
1179
|
+
});
|
|
1180
|
+
if (objects.length === 0) return;
|
|
1181
|
+
const group = new DrawingGroupObject(getDrawingShapeKeyByDrawingSearch({
|
|
1182
|
+
unitId,
|
|
1183
|
+
subUnitId,
|
|
1184
|
+
drawingId
|
|
1185
|
+
}));
|
|
1186
|
+
scene.addObject(group, DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
|
|
1187
|
+
group.addObjects(...objects);
|
|
1188
|
+
if (parent.groupBaseBound) group.setBaseBound(parent.groupBaseBound);
|
|
1189
|
+
if (parent.groupId) {
|
|
1190
|
+
group.isInGroup = true;
|
|
1191
|
+
insertGroupObject({
|
|
1192
|
+
drawingId: parent.groupId,
|
|
1193
|
+
unitId,
|
|
1194
|
+
subUnitId
|
|
1195
|
+
}, group, scene, this._drawingManagerService);
|
|
1196
|
+
}
|
|
1197
|
+
parent.transform && group.transformByState({
|
|
1198
|
+
left: parent.transform.left,
|
|
1199
|
+
top: parent.transform.top,
|
|
1200
|
+
width: parent.transform.width,
|
|
1201
|
+
height: parent.transform.height,
|
|
1202
|
+
angle: parent.transform.angle
|
|
1203
|
+
});
|
|
1204
|
+
transformer.clearSelectedObjects();
|
|
1205
|
+
transformer.setSelectedControl(group);
|
|
1206
|
+
}
|
|
1207
|
+
_ungroupDrawings(drawings) {
|
|
1208
|
+
drawings.forEach((drawing) => {
|
|
1209
|
+
this._ungroupDrawing(drawing);
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
_ungroupDrawing(drawing) {
|
|
1213
|
+
const { parent, children } = drawing;
|
|
1214
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(parent.unitId);
|
|
1215
|
+
if (renderObject == null) return;
|
|
1216
|
+
const { scene, transformer } = renderObject;
|
|
1217
|
+
children.forEach((drawing) => {
|
|
1218
|
+
const drawingKey = getDrawingShapeKeyByDrawingSearch(drawing);
|
|
1219
|
+
const object = scene.getObjectIncludeInGroup(drawingKey);
|
|
1220
|
+
if (object == null) return true;
|
|
1221
|
+
if (object == null) return;
|
|
1222
|
+
const { transform } = drawing;
|
|
1223
|
+
if (transform == null) return;
|
|
1224
|
+
if (object.classType === RENDER_CLASS_TYPE.GROUP) object.transformByState({
|
|
1225
|
+
left: transform.left,
|
|
1226
|
+
top: transform.top
|
|
1227
|
+
});
|
|
1228
|
+
else object.transformByState(transform);
|
|
1229
|
+
});
|
|
1230
|
+
const groupKey = getDrawingShapeKeyByDrawingSearch(parent);
|
|
1231
|
+
const group = scene.getObject(groupKey);
|
|
1232
|
+
const { width, height } = group;
|
|
1233
|
+
group.getObjects().forEach((object) => {
|
|
1234
|
+
group.removeSelfObjectAndTransform(object.oKey, width, height);
|
|
1235
|
+
});
|
|
1236
|
+
group.dispose();
|
|
1237
|
+
transformer.clearSelectedObjects();
|
|
1238
|
+
}
|
|
1239
|
+
_drawingAlign(params) {
|
|
1240
|
+
const { alignType } = params;
|
|
1241
|
+
const drawings = params.drawings || this._drawingManagerService.getFocusDrawings();
|
|
1242
|
+
if (alignType === "0") return;
|
|
1243
|
+
const drawingTransformCaches = [];
|
|
1244
|
+
let minLeft = Number.POSITIVE_INFINITY;
|
|
1245
|
+
let minTop = Number.POSITIVE_INFINITY;
|
|
1246
|
+
let maxRight = Number.NEGATIVE_INFINITY;
|
|
1247
|
+
let maxBottom = Number.NEGATIVE_INFINITY;
|
|
1248
|
+
let drawingCount = 0;
|
|
1249
|
+
drawings.forEach((drawing) => {
|
|
1250
|
+
const { unitId, subUnitId, drawingId, drawingType } = drawing;
|
|
1251
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam({
|
|
1252
|
+
unitId,
|
|
1253
|
+
subUnitId,
|
|
1254
|
+
drawingId
|
|
1255
|
+
});
|
|
1256
|
+
if (drawingParam == null || drawingParam.transform == null) return;
|
|
1257
|
+
drawingTransformCaches.push({
|
|
1258
|
+
unitId,
|
|
1259
|
+
subUnitId,
|
|
1260
|
+
drawingId,
|
|
1261
|
+
drawingType,
|
|
1262
|
+
transform: drawingParam.transform
|
|
1263
|
+
});
|
|
1264
|
+
const { left = 0, top = 0, width = 0, height = 0 } = drawingParam.transform;
|
|
1265
|
+
minLeft = Math.min(minLeft, left);
|
|
1266
|
+
minTop = Math.min(minTop, top);
|
|
1267
|
+
maxRight = Math.max(maxRight, left + width);
|
|
1268
|
+
maxBottom = Math.max(maxBottom, top + height);
|
|
1269
|
+
drawingCount++;
|
|
1270
|
+
});
|
|
1271
|
+
if (drawingCount === 0) return;
|
|
1272
|
+
this._sortDrawingTransform(drawingTransformCaches, alignType);
|
|
1273
|
+
this._applyAlignType(drawingTransformCaches, alignType, minLeft, minTop, maxRight, maxBottom, drawingCount);
|
|
1274
|
+
}
|
|
1275
|
+
_applyAlignType(drawingTransformCaches, alignType, minLeft, minTop, maxRight, maxBottom, drawingCount) {
|
|
1276
|
+
const averageHorizon = Math.round((maxRight - minLeft) / drawingCount * 10) / 10;
|
|
1277
|
+
const averageVertical = Math.round((maxBottom - minTop) / drawingCount * 10) / 10;
|
|
1278
|
+
const updateParams = [];
|
|
1279
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(drawingTransformCaches[0].unitId);
|
|
1280
|
+
if (renderObject == null) return;
|
|
1281
|
+
const { scene, transformer } = renderObject;
|
|
1282
|
+
drawingTransformCaches.forEach((drawingTransformCache, index) => {
|
|
1283
|
+
const { unitId, subUnitId, drawingId, transform, drawingType } = drawingTransformCache;
|
|
1284
|
+
const { left = 0, top = 0, width = 0, height = 0 } = transform;
|
|
1285
|
+
let newLeft = left;
|
|
1286
|
+
let newTop = top;
|
|
1287
|
+
switch (alignType) {
|
|
1288
|
+
case "1":
|
|
1289
|
+
newLeft = minLeft;
|
|
1290
|
+
break;
|
|
1291
|
+
case "2":
|
|
1292
|
+
newLeft = minLeft + (maxRight - minLeft) / 2 - width / 2;
|
|
1293
|
+
break;
|
|
1294
|
+
case "3":
|
|
1295
|
+
newLeft = maxRight - width;
|
|
1296
|
+
break;
|
|
1297
|
+
case "4":
|
|
1298
|
+
newTop = minTop;
|
|
1299
|
+
break;
|
|
1300
|
+
case "5":
|
|
1301
|
+
newTop = minTop + (maxBottom - minTop) / 2 - height / 2;
|
|
1302
|
+
break;
|
|
1303
|
+
case "6":
|
|
1304
|
+
newTop = maxBottom - height;
|
|
1305
|
+
break;
|
|
1306
|
+
case "7":
|
|
1307
|
+
newLeft = minLeft + averageHorizon * index;
|
|
1308
|
+
break;
|
|
1309
|
+
case "8":
|
|
1310
|
+
newTop = minTop + averageVertical * index;
|
|
1311
|
+
break;
|
|
1312
|
+
default: break;
|
|
1313
|
+
}
|
|
1314
|
+
if (newLeft !== left || newTop !== top) updateParams.push({
|
|
1315
|
+
unitId,
|
|
1316
|
+
subUnitId,
|
|
1317
|
+
drawingId,
|
|
1318
|
+
drawingType,
|
|
1319
|
+
transform: {
|
|
1320
|
+
left: newLeft,
|
|
1321
|
+
top: newTop
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
this._drawingManagerService.featurePluginUpdateNotification(updateParams);
|
|
1326
|
+
transformer.refreshControls().changeNotification();
|
|
1327
|
+
}
|
|
1328
|
+
_sortDrawingTransform(drawingTransformCaches, alignType) {
|
|
1329
|
+
drawingTransformCaches.sort((a, b) => {
|
|
1330
|
+
const aTransform = a.transform;
|
|
1331
|
+
const bTransform = b.transform;
|
|
1332
|
+
const { left: aLeft = 0, top: aTop = 0, width: aWidth = 0, height: aHeight = 0 } = aTransform;
|
|
1333
|
+
const { left: bLeft = 0, top: bTop = 0, width: bWidth = 0, height: bHeight = 0 } = bTransform;
|
|
1334
|
+
switch (alignType) {
|
|
1335
|
+
case "1": return aLeft - bLeft;
|
|
1336
|
+
case "2": return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
|
|
1337
|
+
case "3": return aLeft + aWidth - (bLeft + bWidth);
|
|
1338
|
+
case "4": return aTop - bTop;
|
|
1339
|
+
case "5": return aTop + aHeight / 2 - (bTop + bHeight / 2);
|
|
1340
|
+
case "6": return aTop + aHeight - (bTop + bHeight);
|
|
1341
|
+
case "7": return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
|
|
1342
|
+
case "8": return aTop + aHeight / 2 - (bTop + bHeight / 2);
|
|
1343
|
+
default: return 0;
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
_drawingArrangeListener() {
|
|
1348
|
+
this.disposeWithMe(this._drawingManagerService.order$.subscribe((params) => {
|
|
1349
|
+
this._drawingArrange(params);
|
|
1350
|
+
}));
|
|
1351
|
+
}
|
|
1352
|
+
_drawingArrange(params) {
|
|
1353
|
+
const { unitId, subUnitId, drawingIds } = params;
|
|
1354
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1355
|
+
if (renderObject == null) return;
|
|
1356
|
+
const { scene } = renderObject;
|
|
1357
|
+
drawingIds.forEach((drawingId) => {
|
|
1358
|
+
const oKey = getDrawingShapeKeyByDrawingSearch({
|
|
1359
|
+
unitId,
|
|
1360
|
+
subUnitId,
|
|
1361
|
+
drawingId
|
|
1362
|
+
});
|
|
1363
|
+
const drawingShapes = scene.fuzzyMathObjects(oKey, true);
|
|
1364
|
+
if (drawingShapes == null || drawingShapes.length === 0) return;
|
|
1365
|
+
const index = this._drawingManagerService.getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
|
|
1366
|
+
for (const shape of drawingShapes) {
|
|
1367
|
+
shape.setProps({ zIndex: index });
|
|
1368
|
+
shape.makeDirty();
|
|
1369
|
+
}
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
_drawingAddListener() {
|
|
1373
|
+
this.disposeWithMe(this._drawingManagerService.add$.subscribe((params) => {
|
|
1374
|
+
this._insertDrawing(params);
|
|
1375
|
+
}));
|
|
1376
|
+
}
|
|
1377
|
+
_insertDrawing(params) {
|
|
1378
|
+
const sceneList = [];
|
|
1379
|
+
params.forEach((param) => {
|
|
1380
|
+
const { unitId } = param;
|
|
1381
|
+
if (this._drawingManagerService.getDrawingByParam(param) == null) return;
|
|
1382
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1383
|
+
if (renderObject == null) return;
|
|
1384
|
+
const { scene } = renderObject;
|
|
1385
|
+
if (!sceneList.includes(scene)) sceneList.push(scene);
|
|
1386
|
+
});
|
|
1387
|
+
sceneList.forEach((scene) => {
|
|
1388
|
+
if (this._sceneListenerOnDrawingMap.has(scene)) return;
|
|
1389
|
+
this._addListenerOnDrawing(scene);
|
|
1390
|
+
this._sceneListenerOnDrawingMap.add(scene);
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
_drawingRemoveListener() {
|
|
1394
|
+
this.disposeWithMe(this._drawingManagerService.remove$.subscribe((params) => {
|
|
1395
|
+
params.forEach((param) => {
|
|
1396
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
1397
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1398
|
+
if (renderObject == null) return;
|
|
1399
|
+
const { scene } = renderObject;
|
|
1400
|
+
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
1401
|
+
unitId,
|
|
1402
|
+
subUnitId,
|
|
1403
|
+
drawingId
|
|
1404
|
+
});
|
|
1405
|
+
const drawingShapes = scene.fuzzyMathObjects(drawingShapeKey, true);
|
|
1406
|
+
if (drawingShapes.length > 0) {
|
|
1407
|
+
var _scene$getTransformer;
|
|
1408
|
+
for (const drawingShape of drawingShapes) drawingShape.dispose();
|
|
1409
|
+
(_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.clearSelectedObjects();
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
}));
|
|
1413
|
+
}
|
|
1414
|
+
_drawingUpdateListener() {
|
|
1415
|
+
this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
|
|
1416
|
+
params.forEach((param) => {
|
|
1417
|
+
var _scene$getTransformer2;
|
|
1418
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
1419
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
1420
|
+
if (drawingParam == null) return;
|
|
1421
|
+
const { transform, drawingType } = drawingParam;
|
|
1422
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1423
|
+
if (renderObject == null) return;
|
|
1424
|
+
const { scene, transformer } = renderObject;
|
|
1425
|
+
if (transform == null) return true;
|
|
1426
|
+
const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
|
|
1427
|
+
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
1428
|
+
unitId,
|
|
1429
|
+
subUnitId,
|
|
1430
|
+
drawingId
|
|
1431
|
+
});
|
|
1432
|
+
const drawingShape = scene.getObject(drawingShapeKey);
|
|
1433
|
+
if (drawingShape == null) return true;
|
|
1434
|
+
drawingShape.transformByState({
|
|
1435
|
+
left,
|
|
1436
|
+
top,
|
|
1437
|
+
width,
|
|
1438
|
+
height,
|
|
1439
|
+
angle,
|
|
1440
|
+
flipX,
|
|
1441
|
+
flipY,
|
|
1442
|
+
skewX,
|
|
1443
|
+
skewY
|
|
1444
|
+
});
|
|
1445
|
+
(_scene$getTransformer2 = scene.getTransformer()) === null || _scene$getTransformer2 === void 0 || _scene$getTransformer2.debounceRefreshControls();
|
|
1446
|
+
});
|
|
1447
|
+
}));
|
|
1448
|
+
}
|
|
1449
|
+
_drawingRefreshListener() {
|
|
1450
|
+
this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe((params) => {
|
|
1451
|
+
params.forEach((param) => {
|
|
1452
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
1453
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1454
|
+
if (renderObject == null) return;
|
|
1455
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
1456
|
+
if (drawingParam == null) return;
|
|
1457
|
+
const { transform } = drawingParam;
|
|
1458
|
+
const { scene } = renderObject;
|
|
1459
|
+
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
1460
|
+
unitId,
|
|
1461
|
+
subUnitId,
|
|
1462
|
+
drawingId
|
|
1463
|
+
});
|
|
1464
|
+
const drawingShape = scene.getObject(drawingShapeKey);
|
|
1465
|
+
if (drawingShape == null || transform == null) return true;
|
|
1466
|
+
const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
|
|
1467
|
+
drawingShape.transformByState({
|
|
1468
|
+
left,
|
|
1469
|
+
top,
|
|
1470
|
+
width,
|
|
1471
|
+
height,
|
|
1472
|
+
angle,
|
|
1473
|
+
flipX,
|
|
1474
|
+
flipY,
|
|
1475
|
+
skewX,
|
|
1476
|
+
skewY
|
|
1477
|
+
});
|
|
1478
|
+
});
|
|
1479
|
+
}));
|
|
1480
|
+
}
|
|
1481
|
+
_drawingVisibleListener() {
|
|
1482
|
+
this.disposeWithMe(this._drawingManagerService.visible$.subscribe((params) => {
|
|
1483
|
+
params.forEach((param) => {
|
|
1484
|
+
const { unitId, subUnitId, drawingId, visible } = param;
|
|
1485
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1486
|
+
if (renderObject == null) return;
|
|
1487
|
+
const { scene } = renderObject;
|
|
1488
|
+
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
1489
|
+
unitId,
|
|
1490
|
+
subUnitId,
|
|
1491
|
+
drawingId
|
|
1492
|
+
});
|
|
1493
|
+
const drawingShape = scene.getObject(drawingShapeKey);
|
|
1494
|
+
if (drawingShape == null) return true;
|
|
1495
|
+
if (visible) drawingShape.show();
|
|
1496
|
+
else drawingShape.hide();
|
|
1497
|
+
});
|
|
1498
|
+
}));
|
|
1499
|
+
}
|
|
1500
|
+
_filterUpdateParams(params, startTransforms) {
|
|
1501
|
+
return params.filter((param, index) => {
|
|
1502
|
+
if (param == null) return false;
|
|
1503
|
+
const { transform } = param;
|
|
1504
|
+
return checkIfMove(transform, startTransforms === null || startTransforms === void 0 ? void 0 : startTransforms[index]);
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
_addListenerOnDrawing(scene) {
|
|
1508
|
+
const transformer = scene.getTransformerByCreate();
|
|
1509
|
+
let startTransforms = null;
|
|
1510
|
+
this.disposeWithMe(toDisposable(transformer.changeStart$.subscribe((state) => {
|
|
1511
|
+
const { objects } = state;
|
|
1512
|
+
const objectArray = Array.from(objects.values());
|
|
1513
|
+
const drawings = [];
|
|
1514
|
+
startTransforms = objectArray.map((object) => {
|
|
1515
|
+
const { left, top, height, width, angle, oKey, isInGroup } = object;
|
|
1516
|
+
const drawing = this._drawingManagerService.getDrawingOKey(oKey);
|
|
1517
|
+
if (isInGroup || object instanceof Group) {
|
|
1518
|
+
let group = object.ancestorGroup;
|
|
1519
|
+
if (group == null && object instanceof Group) group = object;
|
|
1520
|
+
if (group == null) return null;
|
|
1521
|
+
const groupDrawing = this._drawingManagerService.getDrawingOKey(group.oKey);
|
|
1522
|
+
if (groupDrawing) {
|
|
1523
|
+
const { unitId, subUnitId, drawingId } = groupDrawing;
|
|
1524
|
+
drawings.push({
|
|
1525
|
+
unitId,
|
|
1526
|
+
subUnitId,
|
|
1527
|
+
drawingId
|
|
1528
|
+
});
|
|
1529
|
+
const { left, top, height, width, angle } = group;
|
|
1530
|
+
return {
|
|
1531
|
+
left,
|
|
1532
|
+
top,
|
|
1533
|
+
height,
|
|
1534
|
+
width,
|
|
1535
|
+
angle
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
} else if (drawing != null) {
|
|
1539
|
+
const { unitId, subUnitId, drawingId } = drawing;
|
|
1540
|
+
drawings.push({
|
|
1541
|
+
unitId,
|
|
1542
|
+
subUnitId,
|
|
1543
|
+
drawingId
|
|
1544
|
+
});
|
|
1545
|
+
return {
|
|
1546
|
+
left,
|
|
1547
|
+
top,
|
|
1548
|
+
height,
|
|
1549
|
+
width,
|
|
1550
|
+
angle
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
return null;
|
|
1554
|
+
}).filter((transform) => transform != null);
|
|
1555
|
+
if (drawings.length > 0) this._commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, drawings);
|
|
1556
|
+
else this._commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, []);
|
|
1557
|
+
})));
|
|
1558
|
+
this.disposeWithMe(toDisposable(transformer.changeEnd$.subscribe((state) => {
|
|
1559
|
+
const { objects } = state;
|
|
1560
|
+
const params = this._filterUpdateParams(getUpdateParams(objects, this._drawingManagerService), startTransforms);
|
|
1561
|
+
if (params.length > 0) this._drawingManagerService.featurePluginUpdateNotification(params);
|
|
1562
|
+
})));
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
DrawingUpdateController = __decorate([
|
|
1566
|
+
__decorateParam(0, IUniverInstanceService),
|
|
1567
|
+
__decorateParam(1, ICommandService),
|
|
1568
|
+
__decorateParam(2, IRenderManagerService),
|
|
1569
|
+
__decorateParam(3, IDrawingManagerService)
|
|
1570
|
+
], DrawingUpdateController);
|
|
1571
|
+
|
|
1572
|
+
//#endregion
|
|
1573
|
+
//#region src/views/crop/image-cropper-object.ts
|
|
1574
|
+
var ImageCropperObject = class extends Shape {
|
|
1575
|
+
constructor(key, props) {
|
|
1576
|
+
if (props == null) props = {};
|
|
1577
|
+
props.transformerConfig = {
|
|
1578
|
+
keepRatio: false,
|
|
1579
|
+
isCropper: true,
|
|
1580
|
+
anchorFill: "rgb(0, 0, 0)",
|
|
1581
|
+
anchorStroke: "rgb(255, 255, 255)",
|
|
1582
|
+
anchorSize: 24
|
|
1583
|
+
};
|
|
1584
|
+
super(key, props);
|
|
1585
|
+
_defineProperty(this, "_srcRect", void 0);
|
|
1586
|
+
_defineProperty(this, "_prstGeom", void 0);
|
|
1587
|
+
_defineProperty(this, "_applyTransform", void 0);
|
|
1588
|
+
_defineProperty(this, "_dragPadding", 8);
|
|
1589
|
+
_defineProperty(this, "_cacheCanvas", void 0);
|
|
1590
|
+
if (props === null || props === void 0 ? void 0 : props.srcRect) this._srcRect = props.srcRect;
|
|
1591
|
+
if (props === null || props === void 0 ? void 0 : props.prstGeom) this._prstGeom = props.prstGeom;
|
|
1592
|
+
if (props === null || props === void 0 ? void 0 : props.applyTransform) this._applyTransform = props.applyTransform;
|
|
1593
|
+
if (props === null || props === void 0 ? void 0 : props.dragPadding) this._dragPadding = props.dragPadding;
|
|
1594
|
+
this._applyProps();
|
|
1595
|
+
}
|
|
1596
|
+
refreshSrcRect(value, transform) {
|
|
1597
|
+
this._srcRect = value;
|
|
1598
|
+
this._applyTransform = transform;
|
|
1599
|
+
this._applyProps();
|
|
1600
|
+
}
|
|
1601
|
+
get srcRect() {
|
|
1602
|
+
return this._srcRect;
|
|
1603
|
+
}
|
|
1604
|
+
dispose() {
|
|
1605
|
+
var _this$_cacheCanvas;
|
|
1606
|
+
super.dispose();
|
|
1607
|
+
(_this$_cacheCanvas = this._cacheCanvas) === null || _this$_cacheCanvas === void 0 || _this$_cacheCanvas.dispose();
|
|
1608
|
+
this._srcRect = null;
|
|
1609
|
+
}
|
|
1610
|
+
isHit(coord) {
|
|
1611
|
+
const oCoord = this.getInverseCoord(coord);
|
|
1612
|
+
if (oCoord.x >= -this.strokeWidth / 2 && oCoord.x <= this.width + this.strokeWidth / 2 && oCoord.y >= -this.strokeWidth / 2 && oCoord.y <= this.height + this.strokeWidth / 2 && !this._inSurround(oCoord)) return true;
|
|
1613
|
+
return false;
|
|
1614
|
+
}
|
|
1615
|
+
_inSurround(oCoord) {
|
|
1616
|
+
const padding = this._dragPadding;
|
|
1617
|
+
if (oCoord.x >= padding - this.strokeWidth / 2 && oCoord.x <= this.width + this.strokeWidth / 2 - padding && oCoord.y >= padding - this.strokeWidth / 2 && oCoord.y <= this.height + this.strokeWidth / 2 - padding) return true;
|
|
1618
|
+
return false;
|
|
1619
|
+
}
|
|
1620
|
+
render(mainCtx, bounds) {
|
|
1621
|
+
if (!this.visible) {
|
|
1622
|
+
this.makeDirty(false);
|
|
1623
|
+
return this;
|
|
1624
|
+
}
|
|
1625
|
+
mainCtx.save();
|
|
1626
|
+
this._draw(mainCtx);
|
|
1627
|
+
mainCtx.restore();
|
|
1628
|
+
this.makeDirty(false);
|
|
1629
|
+
return this;
|
|
1630
|
+
}
|
|
1631
|
+
_draw(ctx) {
|
|
1632
|
+
var _this$_cacheCanvas2, _this$_cacheCanvas3;
|
|
1633
|
+
const { width: engineWidth, height: engineHeight } = this.getScene().getEngine();
|
|
1634
|
+
this._initialCacheCanvas();
|
|
1635
|
+
(_this$_cacheCanvas2 = this._cacheCanvas) === null || _this$_cacheCanvas2 === void 0 || _this$_cacheCanvas2.clear();
|
|
1636
|
+
const cacheCtx = (_this$_cacheCanvas3 = this._cacheCanvas) === null || _this$_cacheCanvas3 === void 0 ? void 0 : _this$_cacheCanvas3.getContext();
|
|
1637
|
+
if (cacheCtx == null) return;
|
|
1638
|
+
cacheCtx.save();
|
|
1639
|
+
Rect.drawWith(cacheCtx, {
|
|
1640
|
+
left: 0,
|
|
1641
|
+
top: 0,
|
|
1642
|
+
width: engineWidth,
|
|
1643
|
+
height: engineHeight,
|
|
1644
|
+
fill: "rgba(0, 0, 0, 0.5)"
|
|
1645
|
+
});
|
|
1646
|
+
cacheCtx.setTransform(ctx.getTransform());
|
|
1647
|
+
this._clipForApplyObject(cacheCtx);
|
|
1648
|
+
this._applyCache(ctx);
|
|
1649
|
+
cacheCtx.restore();
|
|
1650
|
+
}
|
|
1651
|
+
_clipForApplyObject(cacheCtx) {
|
|
1652
|
+
let objectType = 0;
|
|
1653
|
+
if (this._prstGeom != null) objectType = 1;
|
|
1654
|
+
cacheCtx.globalCompositeOperation = "destination-out";
|
|
1655
|
+
cacheCtx.beginPath();
|
|
1656
|
+
if (objectType === 0) {
|
|
1657
|
+
const m = this.transform.getMatrix();
|
|
1658
|
+
cacheCtx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
1659
|
+
cacheCtx.rect(0, 0, this.width, this.height);
|
|
1660
|
+
cacheCtx.fill();
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
_applyProps() {
|
|
1664
|
+
if (this._applyTransform == null) return;
|
|
1665
|
+
let cropLeft = 0;
|
|
1666
|
+
let cropTop = 0;
|
|
1667
|
+
let cropRight = 0;
|
|
1668
|
+
let cropBottom = 0;
|
|
1669
|
+
const { left: applyLeft = 0, top: applyTop = 0, width: applyWidth = 0, height: applyHeight = 0, angle } = this._applyTransform;
|
|
1670
|
+
if (this._srcRect != null) {
|
|
1671
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = this._srcRect;
|
|
1672
|
+
cropLeft = left;
|
|
1673
|
+
cropTop = top;
|
|
1674
|
+
cropRight = right;
|
|
1675
|
+
cropBottom = bottom;
|
|
1676
|
+
}
|
|
1677
|
+
const left = applyLeft + cropLeft;
|
|
1678
|
+
const top = applyTop + cropTop;
|
|
1679
|
+
this.transformByState({
|
|
1680
|
+
left,
|
|
1681
|
+
top,
|
|
1682
|
+
width: applyLeft + applyWidth - cropRight - left,
|
|
1683
|
+
height: applyTop + applyHeight - cropBottom - top,
|
|
1684
|
+
angle
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
_applyCache(ctx) {
|
|
1688
|
+
if (!ctx || this._cacheCanvas == null) return;
|
|
1689
|
+
const cacheCtx = this._cacheCanvas.getContext();
|
|
1690
|
+
cacheCtx.save();
|
|
1691
|
+
ctx.save();
|
|
1692
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1693
|
+
cacheCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1694
|
+
ctx.drawImage(this._cacheCanvas.getCanvasEle(), 0, 0);
|
|
1695
|
+
ctx.restore();
|
|
1696
|
+
cacheCtx.restore();
|
|
1697
|
+
}
|
|
1698
|
+
_initialCacheCanvas() {
|
|
1699
|
+
if (this._cacheCanvas != null) return;
|
|
1700
|
+
const scene = this.getScene();
|
|
1701
|
+
if (scene == null) return;
|
|
1702
|
+
this._cacheCanvas = new Canvas();
|
|
1703
|
+
const engine = scene.getEngine();
|
|
1704
|
+
this._cacheCanvas.setSize(engine.width, engine.height);
|
|
1705
|
+
engine.onTransformChange$.subscribeEvent(() => {
|
|
1706
|
+
var _this$_cacheCanvas4;
|
|
1707
|
+
(_this$_cacheCanvas4 = this._cacheCanvas) === null || _this$_cacheCanvas4 === void 0 || _this$_cacheCanvas4.setSize(engine.width, engine.height);
|
|
1708
|
+
this.makeDirty(true);
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
//#endregion
|
|
1714
|
+
//#region src/controllers/image-cropper.controller.ts
|
|
1715
|
+
let ImageCropperController = class ImageCropperController extends Disposable {
|
|
1716
|
+
constructor(_commandService, _drawingManagerService, _renderManagerService, _univerInstanceService, _messageService, _localeService) {
|
|
1717
|
+
super();
|
|
1718
|
+
this._commandService = _commandService;
|
|
1719
|
+
this._drawingManagerService = _drawingManagerService;
|
|
1720
|
+
this._renderManagerService = _renderManagerService;
|
|
1721
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1722
|
+
this._messageService = _messageService;
|
|
1723
|
+
this._localeService = _localeService;
|
|
1724
|
+
_defineProperty(this, "_sceneListenerOnImageMap", /* @__PURE__ */ new WeakSet());
|
|
1725
|
+
this._init();
|
|
1726
|
+
}
|
|
1727
|
+
_init() {
|
|
1728
|
+
this._initOpenCrop();
|
|
1729
|
+
this._initCloseCrop();
|
|
1730
|
+
this._initAutoCrop();
|
|
1731
|
+
}
|
|
1732
|
+
_initAutoCrop() {
|
|
1733
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1734
|
+
if (command.id !== AutoImageCropOperation.id) return;
|
|
1735
|
+
const params = command.params;
|
|
1736
|
+
if (params == null) return;
|
|
1737
|
+
const { cropType } = params;
|
|
1738
|
+
const drawingParams = this._drawingManagerService.getFocusDrawings();
|
|
1739
|
+
if (drawingParams.length !== 1) return;
|
|
1740
|
+
const { unitId, subUnitId, drawingId } = drawingParams[0];
|
|
1741
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1742
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1743
|
+
if (scene == null) return true;
|
|
1744
|
+
if (this._searchCropObject(scene) != null) this._commandService.syncExecuteCommand(CloseImageCropOperation.id, { isAuto: true });
|
|
1745
|
+
const imageShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
1746
|
+
unitId,
|
|
1747
|
+
subUnitId,
|
|
1748
|
+
drawingId
|
|
1749
|
+
});
|
|
1750
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
1751
|
+
if (!(imageShape instanceof Image)) {
|
|
1752
|
+
this._messageService.show({
|
|
1753
|
+
type: MessageType.Error,
|
|
1754
|
+
content: this._localeService.t("drawing-ui.image-cropper.error")
|
|
1755
|
+
});
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
if (imageShape == null) return;
|
|
1759
|
+
this._updateCropperObject(cropType, imageShape);
|
|
1760
|
+
this._commandService.executeCommand(OpenImageCropOperation.id, {
|
|
1761
|
+
unitId,
|
|
1762
|
+
subUnitId,
|
|
1763
|
+
drawingId
|
|
1764
|
+
});
|
|
1765
|
+
}));
|
|
1766
|
+
}
|
|
1767
|
+
_calculateSrcRectByRatio(left, top, width, height, numerator, denominator) {
|
|
1768
|
+
const srcRatio = width / height;
|
|
1769
|
+
const ratio = numerator / denominator;
|
|
1770
|
+
let newWidth = width;
|
|
1771
|
+
let newHeight = height;
|
|
1772
|
+
if (srcRatio > ratio) newWidth = height * ratio;
|
|
1773
|
+
else newHeight = width / ratio;
|
|
1774
|
+
const newLeft = (width - newWidth) / 2;
|
|
1775
|
+
const newTop = (height - newHeight) / 2;
|
|
1776
|
+
return {
|
|
1777
|
+
left: precisionTo(newLeft, 1),
|
|
1778
|
+
top: precisionTo(newTop, 1),
|
|
1779
|
+
right: precisionTo(width - (newLeft + newWidth), 1),
|
|
1780
|
+
bottom: precisionTo(height - (newTop + newHeight), 1)
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
_updateCropperObject(cropType, imageShape) {
|
|
1784
|
+
const { left, top, width, height } = imageShape.calculateTransformWithSrcRect();
|
|
1785
|
+
let newSrcRect;
|
|
1786
|
+
switch (cropType) {
|
|
1787
|
+
case "1":
|
|
1788
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 1, 1);
|
|
1789
|
+
break;
|
|
1790
|
+
case "2":
|
|
1791
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 16, 9);
|
|
1792
|
+
break;
|
|
1793
|
+
case "3":
|
|
1794
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 9, 16);
|
|
1795
|
+
break;
|
|
1796
|
+
case "4":
|
|
1797
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 5, 4);
|
|
1798
|
+
break;
|
|
1799
|
+
case "5":
|
|
1800
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 4, 5);
|
|
1801
|
+
break;
|
|
1802
|
+
case "6":
|
|
1803
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 4, 3);
|
|
1804
|
+
break;
|
|
1805
|
+
case "7":
|
|
1806
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 3, 4);
|
|
1807
|
+
break;
|
|
1808
|
+
case "8":
|
|
1809
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 3, 2);
|
|
1810
|
+
break;
|
|
1811
|
+
case "9":
|
|
1812
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 2, 3);
|
|
1813
|
+
break;
|
|
1814
|
+
case "0":
|
|
1815
|
+
default: break;
|
|
1816
|
+
}
|
|
1817
|
+
if (newSrcRect == null) return;
|
|
1818
|
+
imageShape.setSrcRect(newSrcRect);
|
|
1819
|
+
const { left: newLeft = 0, top: newTop = 0, bottom: newBottom = 0, right: newRight = 0 } = newSrcRect;
|
|
1820
|
+
imageShape.transformByStateCloseCropper({
|
|
1821
|
+
left: left + newLeft,
|
|
1822
|
+
top: top + newTop,
|
|
1823
|
+
width: width - newRight - newLeft,
|
|
1824
|
+
height: height - newBottom - newTop
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
_initOpenCrop() {
|
|
1828
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1829
|
+
if (command.id !== OpenImageCropOperation.id) return;
|
|
1830
|
+
const params = command.params;
|
|
1831
|
+
if (params == null) return;
|
|
1832
|
+
const { unitId, subUnitId, drawingId } = params;
|
|
1833
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1834
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1835
|
+
if (scene == null) return true;
|
|
1836
|
+
if (!this._sceneListenerOnImageMap.has(scene)) {
|
|
1837
|
+
this._addListenerOnImage(scene);
|
|
1838
|
+
this._sceneListenerOnImageMap.add(scene);
|
|
1839
|
+
}
|
|
1840
|
+
if (this._drawingManagerService.getDrawingByParam({
|
|
1841
|
+
unitId,
|
|
1842
|
+
subUnitId,
|
|
1843
|
+
drawingId
|
|
1844
|
+
}) == null) return;
|
|
1845
|
+
const imageShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
1846
|
+
unitId,
|
|
1847
|
+
subUnitId,
|
|
1848
|
+
drawingId
|
|
1849
|
+
});
|
|
1850
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
1851
|
+
if (imageShape == null) return;
|
|
1852
|
+
if (!(imageShape instanceof Image)) {
|
|
1853
|
+
this._messageService.show({
|
|
1854
|
+
type: MessageType.Error,
|
|
1855
|
+
content: this._localeService.t("drawing-ui.image-cropper.error")
|
|
1856
|
+
});
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
const transformer = scene.getTransformer();
|
|
1860
|
+
transformer === null || transformer === void 0 || transformer.clearControls();
|
|
1861
|
+
const imageCropperObject = new ImageCropperObject(`${imageShapeKey}-crop`, {
|
|
1862
|
+
srcRect: imageShape.srcRect,
|
|
1863
|
+
prstGeom: imageShape.prstGeom,
|
|
1864
|
+
applyTransform: imageShape.calculateTransformWithSrcRect()
|
|
1865
|
+
});
|
|
1866
|
+
scene.addObject(imageCropperObject, imageShape.getLayerIndex() + 1).attachTransformerTo(imageCropperObject);
|
|
1867
|
+
transformer === null || transformer === void 0 || transformer.createControlForCopper(imageCropperObject);
|
|
1868
|
+
this._addHoverForImageCopper(imageCropperObject);
|
|
1869
|
+
imageShape.openRenderByCropper();
|
|
1870
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
1871
|
+
imageCropperObject.makeDirty(true);
|
|
1872
|
+
this._commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, [{
|
|
1873
|
+
unitId,
|
|
1874
|
+
subUnitId,
|
|
1875
|
+
drawingId
|
|
1876
|
+
}]);
|
|
1877
|
+
}));
|
|
1878
|
+
}
|
|
1879
|
+
_searchCropObject(scene) {
|
|
1880
|
+
const objects = scene.getAllObjectsByOrder();
|
|
1881
|
+
for (const object of objects) if (object instanceof ImageCropperObject) return object;
|
|
1882
|
+
}
|
|
1883
|
+
_initCloseCrop() {
|
|
1884
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1885
|
+
if (command.id !== CloseImageCropOperation.id) return;
|
|
1886
|
+
const currentUnit = this._univerInstanceService.getFocusedUnit();
|
|
1887
|
+
if (currentUnit == null) return;
|
|
1888
|
+
const unitId = currentUnit.getUnitId();
|
|
1889
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1890
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1891
|
+
if (scene == null) return true;
|
|
1892
|
+
const imageCropperObject = this._searchCropObject(scene);
|
|
1893
|
+
if (imageCropperObject == null) return;
|
|
1894
|
+
const imageShape = this._getApplyObjectByCropObject(imageCropperObject);
|
|
1895
|
+
if (imageShape == null) return;
|
|
1896
|
+
const transformer = scene.getTransformerByCreate();
|
|
1897
|
+
transformer.detachFrom(imageCropperObject);
|
|
1898
|
+
transformer.clearCopperControl();
|
|
1899
|
+
const srcRect = this._getSrcRectByTransformState(imageShape, imageCropperObject);
|
|
1900
|
+
const drawingParam = this._drawingManagerService.getDrawingOKey(imageShape.oKey);
|
|
1901
|
+
if (drawingParam != null) {
|
|
1902
|
+
const { left, top, height, width } = imageCropperObject;
|
|
1903
|
+
this._drawingManagerService.featurePluginUpdateNotification([{
|
|
1904
|
+
...drawingParam,
|
|
1905
|
+
transform: {
|
|
1906
|
+
...drawingParam.transform,
|
|
1907
|
+
left,
|
|
1908
|
+
top,
|
|
1909
|
+
height,
|
|
1910
|
+
width
|
|
1911
|
+
},
|
|
1912
|
+
srcRect: srcRect.srcRectAngle
|
|
1913
|
+
}]);
|
|
1914
|
+
}
|
|
1915
|
+
imageShape.setSrcRect({ ...srcRect.srcRectAngle });
|
|
1916
|
+
imageShape.closeRenderByCropper();
|
|
1917
|
+
imageShape.makeDirty(true);
|
|
1918
|
+
imageCropperObject === null || imageCropperObject === void 0 || imageCropperObject.dispose();
|
|
1919
|
+
}));
|
|
1920
|
+
const sheetUnit$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(switchMap((workbook) => workbook ? workbook.activeSheet$ : of(null)));
|
|
1921
|
+
this.disposeWithMe(sheetUnit$.subscribe(() => {
|
|
1922
|
+
this._commandService.syncExecuteCommand(CloseImageCropOperation.id);
|
|
1923
|
+
}));
|
|
1924
|
+
}
|
|
1925
|
+
_getApplyObjectByCropObject(cropObject) {
|
|
1926
|
+
const cropOKey = cropObject.oKey;
|
|
1927
|
+
const applyOKey = cropOKey.slice(0, cropOKey.length - 5);
|
|
1928
|
+
const scene = cropObject.getScene();
|
|
1929
|
+
if (!scene) return null;
|
|
1930
|
+
const applyObject = scene.getObject(applyOKey);
|
|
1931
|
+
if (applyObject == null) return null;
|
|
1932
|
+
return applyObject;
|
|
1933
|
+
}
|
|
1934
|
+
_addListenerOnImage(scene) {
|
|
1935
|
+
const transformer = scene.getTransformerByCreate();
|
|
1936
|
+
let startTransform = null;
|
|
1937
|
+
this.disposeWithMe(transformer.changeStart$.subscribe((state) => {
|
|
1938
|
+
const { objects } = state;
|
|
1939
|
+
const cropObject = objects.values().next().value;
|
|
1940
|
+
if (cropObject == null || !(cropObject instanceof ImageCropperObject)) return;
|
|
1941
|
+
const { left, top, height, width, angle } = cropObject;
|
|
1942
|
+
startTransform = {
|
|
1943
|
+
left,
|
|
1944
|
+
top,
|
|
1945
|
+
height,
|
|
1946
|
+
width,
|
|
1947
|
+
angle
|
|
1948
|
+
};
|
|
1949
|
+
transformer.clearCopperControl();
|
|
1950
|
+
}));
|
|
1951
|
+
this.disposeWithMe(transformer.changeEnd$.subscribe((state) => {
|
|
1952
|
+
const { objects } = state;
|
|
1953
|
+
const cropObject = objects.values().next().value;
|
|
1954
|
+
if (cropObject == null || !(cropObject instanceof ImageCropperObject)) return;
|
|
1955
|
+
const { left, top, height, width, angle } = cropObject;
|
|
1956
|
+
if (!checkIfMove({
|
|
1957
|
+
left,
|
|
1958
|
+
top,
|
|
1959
|
+
height,
|
|
1960
|
+
width,
|
|
1961
|
+
angle
|
|
1962
|
+
}, startTransform)) return;
|
|
1963
|
+
const applyObject = this._getApplyObjectByCropObject(cropObject);
|
|
1964
|
+
if (applyObject == null) return;
|
|
1965
|
+
const srcRect = this._getSrcRectByTransformState(applyObject, cropObject);
|
|
1966
|
+
cropObject.refreshSrcRect(srcRect.srcRect, applyObject.getState());
|
|
1967
|
+
transformer.createControlForCopper(cropObject);
|
|
1968
|
+
}));
|
|
1969
|
+
this._endCropListener(scene);
|
|
1970
|
+
}
|
|
1971
|
+
_addHoverForImageCopper(o) {
|
|
1972
|
+
this.disposeWithMe(o.onPointerEnter$.subscribeEvent(() => {
|
|
1973
|
+
o.cursor = CURSOR_TYPE.MOVE;
|
|
1974
|
+
}));
|
|
1975
|
+
this.disposeWithMe(o.onPointerLeave$.subscribeEvent(() => {
|
|
1976
|
+
o.cursor = CURSOR_TYPE.DEFAULT;
|
|
1977
|
+
}));
|
|
1978
|
+
}
|
|
1979
|
+
_endCropListener(scene) {
|
|
1980
|
+
const transformer = scene.getTransformerByCreate();
|
|
1981
|
+
this.disposeWithMe(transformer.clearControl$.subscribe((changeSelf) => {
|
|
1982
|
+
if (changeSelf === true) this._commandService.syncExecuteCommand(CloseImageCropOperation.id);
|
|
1983
|
+
}));
|
|
1984
|
+
}
|
|
1985
|
+
_getSrcRectByTransformState(applyObject, imageCropperObject) {
|
|
1986
|
+
const { left, top, height, width, strokeWidth, angle: copperAngle } = imageCropperObject;
|
|
1987
|
+
const { left: applyLeft, top: applyTop, width: applyWidth, height: applyHeight, angle: applyAngle, strokeWidth: applyStrokeWidth } = applyObject;
|
|
1988
|
+
const newLeft = left - applyLeft;
|
|
1989
|
+
const newTop = top - applyTop;
|
|
1990
|
+
const srcRect = {
|
|
1991
|
+
left: newLeft,
|
|
1992
|
+
top: newTop,
|
|
1993
|
+
right: applyWidth - newLeft - width,
|
|
1994
|
+
bottom: applyHeight - newTop - height
|
|
1995
|
+
};
|
|
1996
|
+
const srcRectAngle = { ...srcRect };
|
|
1997
|
+
if (applyAngle !== 0) {
|
|
1998
|
+
const centerPoint = new Vector2(left + width / 2, top + height / 2);
|
|
1999
|
+
const newCenterPoint = new Vector2(applyWidth / 2 + applyLeft, applyHeight / 2 + applyTop);
|
|
2000
|
+
const vertexPoint = new Vector2(applyLeft, applyTop);
|
|
2001
|
+
vertexPoint.rotateByPoint(degToRad(applyAngle), newCenterPoint);
|
|
2002
|
+
const applyFinalPoint = vertexPoint.clone();
|
|
2003
|
+
applyFinalPoint.rotateByPoint(degToRad(-applyAngle), centerPoint);
|
|
2004
|
+
const newAngleLeft = left - applyFinalPoint.x;
|
|
2005
|
+
const newAngleTop = top - applyFinalPoint.y;
|
|
2006
|
+
srcRectAngle.left = newAngleLeft;
|
|
2007
|
+
srcRectAngle.top = newAngleTop;
|
|
2008
|
+
srcRectAngle.right = applyWidth - newAngleLeft - width;
|
|
2009
|
+
srcRectAngle.bottom = applyHeight - newAngleTop - height;
|
|
2010
|
+
}
|
|
2011
|
+
return {
|
|
2012
|
+
srcRect,
|
|
2013
|
+
srcRectAngle
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
ImageCropperController = __decorate([
|
|
2018
|
+
__decorateParam(0, ICommandService),
|
|
2019
|
+
__decorateParam(1, IDrawingManagerService),
|
|
2020
|
+
__decorateParam(2, IRenderManagerService),
|
|
2021
|
+
__decorateParam(3, IUniverInstanceService),
|
|
2022
|
+
__decorateParam(4, IMessageService),
|
|
2023
|
+
__decorateParam(5, Inject(LocaleService))
|
|
2024
|
+
], ImageCropperController);
|
|
2025
|
+
|
|
2026
|
+
//#endregion
|
|
2027
|
+
//#region src/services/drawing-image-clip.service.ts
|
|
2028
|
+
const IMAGE_CLIP_SHAPE_PICKER_COMPONENT = "sheet.image-clip.shape.picker.component";
|
|
2029
|
+
/**
|
|
2030
|
+
* Bridge service that enables shape-based image clipping.
|
|
2031
|
+
* This service lives in the open-source drawing-ui package and delegates
|
|
2032
|
+
* to a registered clip implementation (provided by pro engine-shape package).
|
|
2033
|
+
*
|
|
2034
|
+
* When no delegate is registered, applyShapeClip returns false and images render normally without shape clipping.
|
|
2035
|
+
*/
|
|
2036
|
+
var DrawingImageClipService = class extends Disposable {
|
|
2037
|
+
constructor() {
|
|
2038
|
+
super();
|
|
2039
|
+
_defineProperty(this, "_clipDelegate", null);
|
|
2040
|
+
_defineProperty(this, "_canUseShapeClip$", new BehaviorSubject(false));
|
|
2041
|
+
_defineProperty(this, "canUseShapeClip$", this._canUseShapeClip$.asObservable());
|
|
2042
|
+
}
|
|
2043
|
+
setCanUseShapeClip(canUse) {
|
|
2044
|
+
this._canUseShapeClip$.next(canUse);
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Register a clip delegate that knows how to build shape clip paths.
|
|
2048
|
+
* Typically called by the pro-side plugin with a ShapeModel-based implementation.
|
|
2049
|
+
* @returns IDisposable to unregister the delegate
|
|
2050
|
+
*/
|
|
2051
|
+
registerClipDelegate(delegate) {
|
|
2052
|
+
this._clipDelegate = delegate;
|
|
2053
|
+
return toDisposable(() => {
|
|
2054
|
+
if (this._clipDelegate === delegate) this._clipDelegate = null;
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
applyShapeClip(ctx, prstGeom, width, height, adjustValues) {
|
|
2058
|
+
if (this._clipDelegate) return this._clipDelegate(ctx, prstGeom, width, height, adjustValues);
|
|
2059
|
+
return false;
|
|
2060
|
+
}
|
|
2061
|
+
dispose() {
|
|
2062
|
+
this._clipDelegate = null;
|
|
2063
|
+
this._canUseShapeClip$.complete();
|
|
2064
|
+
super.dispose();
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
|
|
2068
|
+
//#endregion
|
|
2069
|
+
//#region src/services/drawing-render.service.ts
|
|
2070
|
+
let DrawingRenderService = class DrawingRenderService {
|
|
2071
|
+
constructor(_drawingManagerService, _imageIoService, _galleryService, _urlImageService, _univerInstanceService, _drawingImageClipService) {
|
|
2072
|
+
this._drawingManagerService = _drawingManagerService;
|
|
2073
|
+
this._imageIoService = _imageIoService;
|
|
2074
|
+
this._galleryService = _galleryService;
|
|
2075
|
+
this._urlImageService = _urlImageService;
|
|
2076
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2077
|
+
this._drawingImageClipService = _drawingImageClipService;
|
|
2078
|
+
}
|
|
2079
|
+
async renderImages(imageParam, scene) {
|
|
2080
|
+
const { transform: singleTransform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms, adjustValues, hidden } = imageParam;
|
|
2081
|
+
if (drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return;
|
|
2082
|
+
if (!this._drawingManagerService.getDrawingVisible()) return;
|
|
2083
|
+
if (this._univerInstanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET && subUnitId !== this._getActiveSheetId()) return;
|
|
2084
|
+
if (singleTransform == null) return;
|
|
2085
|
+
const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
|
|
2086
|
+
const images = [];
|
|
2087
|
+
for (const transform of transforms) {
|
|
2088
|
+
const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
|
|
2089
|
+
const index = transforms.indexOf(transform);
|
|
2090
|
+
const imageShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
2091
|
+
unitId,
|
|
2092
|
+
subUnitId,
|
|
2093
|
+
drawingId
|
|
2094
|
+
}, isMultiTransform ? index : void 0);
|
|
2095
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
2096
|
+
if (imageShape != null) {
|
|
2097
|
+
imageShape.transformByState({
|
|
2098
|
+
left,
|
|
2099
|
+
top,
|
|
2100
|
+
width,
|
|
2101
|
+
height,
|
|
2102
|
+
angle,
|
|
2103
|
+
flipX,
|
|
2104
|
+
flipY,
|
|
2105
|
+
skewX,
|
|
2106
|
+
skewY
|
|
2107
|
+
});
|
|
2108
|
+
continue;
|
|
2109
|
+
}
|
|
2110
|
+
const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
|
|
2111
|
+
const zIndex = orders.indexOf(drawingId);
|
|
2112
|
+
const imageConfig = {
|
|
2113
|
+
...transform,
|
|
2114
|
+
zIndex: zIndex === -1 ? orders.length - 1 : zIndex
|
|
2115
|
+
};
|
|
2116
|
+
const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
|
|
2117
|
+
let shouldBeCache = false;
|
|
2118
|
+
if (imageNativeCache != null) imageConfig.image = imageNativeCache;
|
|
2119
|
+
else if (imageSourceType === ImageSourceType$1.UUID) try {
|
|
2120
|
+
imageConfig.url = await this._imageIoService.getImage(source);
|
|
2121
|
+
} catch (error) {
|
|
2122
|
+
console.error(error);
|
|
2123
|
+
continue;
|
|
2124
|
+
}
|
|
2125
|
+
else if (imageSourceType === ImageSourceType$1.URL) {
|
|
2126
|
+
try {
|
|
2127
|
+
imageConfig.url = await this._urlImageService.getImage(source);
|
|
2128
|
+
} catch (error) {
|
|
2129
|
+
console.error(error);
|
|
2130
|
+
imageConfig.url = source;
|
|
2131
|
+
}
|
|
2132
|
+
shouldBeCache = true;
|
|
2133
|
+
} else {
|
|
2134
|
+
imageConfig.url = source;
|
|
2135
|
+
shouldBeCache = true;
|
|
2136
|
+
}
|
|
2137
|
+
if (hidden) imageConfig.visible = false;
|
|
2138
|
+
if (scene.getObject(imageShapeKey)) continue;
|
|
2139
|
+
imageConfig.printable = true;
|
|
2140
|
+
const image = new Image(imageShapeKey, imageConfig);
|
|
2141
|
+
image.setClipService(this._drawingImageClipService);
|
|
2142
|
+
if (shouldBeCache) this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
|
|
2143
|
+
scene.addObject(image, DRAWING_OBJECT_LAYER_INDEX);
|
|
2144
|
+
if (this._drawingManagerService.getDrawingEditable()) scene.attachTransformerTo(image);
|
|
2145
|
+
groupId && insertGroupObject({
|
|
2146
|
+
drawingId: groupId,
|
|
2147
|
+
unitId,
|
|
2148
|
+
subUnitId
|
|
2149
|
+
}, image, scene, this._drawingManagerService);
|
|
2150
|
+
if (prstGeom != null) image.setPrstGeom(prstGeom);
|
|
2151
|
+
if (adjustValues != null) image.setPrstGeomAdjValues(adjustValues);
|
|
2152
|
+
if (srcRect != null) image.setSrcRect(srcRect);
|
|
2153
|
+
images.push(image);
|
|
2154
|
+
}
|
|
2155
|
+
return images;
|
|
2156
|
+
}
|
|
2157
|
+
_getActiveSheetId() {
|
|
2158
|
+
var _this$_univerInstance;
|
|
2159
|
+
return (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getActiveSheet()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetId();
|
|
2160
|
+
}
|
|
2161
|
+
renderFloatDom(param, scene) {
|
|
2162
|
+
const { transform: singleTransform, drawingType, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms } = param;
|
|
2163
|
+
if (drawingType !== DrawingTypeEnum.DRAWING_DOM) return;
|
|
2164
|
+
if (!this._drawingManagerService.getDrawingVisible()) return;
|
|
2165
|
+
if (singleTransform == null) return;
|
|
2166
|
+
const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
|
|
2167
|
+
const rects = [];
|
|
2168
|
+
for (const transform of transforms) {
|
|
2169
|
+
const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
|
|
2170
|
+
const index = transforms.indexOf(transform);
|
|
2171
|
+
const imageShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
2172
|
+
unitId,
|
|
2173
|
+
subUnitId,
|
|
2174
|
+
drawingId
|
|
2175
|
+
}, isMultiTransform ? index : void 0);
|
|
2176
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
2177
|
+
if (imageShape != null) {
|
|
2178
|
+
imageShape.transformByState({
|
|
2179
|
+
left,
|
|
2180
|
+
top,
|
|
2181
|
+
width,
|
|
2182
|
+
height,
|
|
2183
|
+
angle,
|
|
2184
|
+
flipX,
|
|
2185
|
+
flipY,
|
|
2186
|
+
skewX,
|
|
2187
|
+
skewY
|
|
2188
|
+
});
|
|
2189
|
+
continue;
|
|
2190
|
+
}
|
|
2191
|
+
const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
|
|
2192
|
+
const zIndex = orders.indexOf(drawingId);
|
|
2193
|
+
const rectConfig = {
|
|
2194
|
+
...transform,
|
|
2195
|
+
zIndex: zIndex === -1 ? orders.length - 1 : zIndex
|
|
2196
|
+
};
|
|
2197
|
+
if (scene.getObject(imageShapeKey)) continue;
|
|
2198
|
+
rectConfig.printable = false;
|
|
2199
|
+
const rect = new Rect(imageShapeKey, rectConfig);
|
|
2200
|
+
if (!this._drawingManagerService.getDrawingVisible()) continue;
|
|
2201
|
+
scene.addObject(rect, DRAWING_OBJECT_LAYER_INDEX);
|
|
2202
|
+
if (this._drawingManagerService.getDrawingEditable() && param.allowTransform !== false) scene.attachTransformerTo(rect);
|
|
2203
|
+
groupId && insertGroupObject({
|
|
2204
|
+
drawingId: groupId,
|
|
2205
|
+
unitId,
|
|
2206
|
+
subUnitId
|
|
2207
|
+
}, rect, scene, this._drawingManagerService);
|
|
2208
|
+
rects.push(rect);
|
|
2209
|
+
}
|
|
2210
|
+
return rects;
|
|
2211
|
+
}
|
|
2212
|
+
renderDrawing(param, scene) {
|
|
2213
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2214
|
+
if (drawingParam == null) return;
|
|
2215
|
+
switch (drawingParam.drawingType) {
|
|
2216
|
+
case DrawingTypeEnum.DRAWING_IMAGE: return this.renderImages(drawingParam, scene);
|
|
2217
|
+
default:
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
previewImage(key, src, width, height) {
|
|
2221
|
+
this._galleryService.open({
|
|
2222
|
+
images: [src],
|
|
2223
|
+
onOpenChange: (open) => {
|
|
2224
|
+
if (!open) this._galleryService.close();
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
_adjustImageSize(nativeWidth, nativeHeight, screenWidth, screenHeight) {
|
|
2229
|
+
if (nativeWidth <= screenWidth && nativeHeight <= screenHeight) return {
|
|
2230
|
+
width: nativeWidth,
|
|
2231
|
+
height: nativeHeight
|
|
2232
|
+
};
|
|
2233
|
+
const widthRatio = screenWidth / nativeWidth;
|
|
2234
|
+
const heightRatio = screenHeight / nativeHeight;
|
|
2235
|
+
const scale = Math.min(widthRatio, heightRatio);
|
|
2236
|
+
return {
|
|
2237
|
+
width: Math.floor(nativeWidth * scale),
|
|
2238
|
+
height: Math.floor(nativeHeight * scale)
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
DrawingRenderService = __decorate([
|
|
2243
|
+
__decorateParam(0, IDrawingManagerService),
|
|
2244
|
+
__decorateParam(1, IImageIoService),
|
|
2245
|
+
__decorateParam(2, IGalleryService),
|
|
2246
|
+
__decorateParam(3, IURLImageService),
|
|
2247
|
+
__decorateParam(4, IUniverInstanceService),
|
|
2248
|
+
__decorateParam(5, Inject(DrawingImageClipService))
|
|
2249
|
+
], DrawingRenderService);
|
|
2250
|
+
|
|
2251
|
+
//#endregion
|
|
2252
|
+
//#region src/controllers/image-update.controller.ts
|
|
2253
|
+
let ImageUpdateController = class ImageUpdateController extends Disposable {
|
|
2254
|
+
constructor(_commandService, _renderManagerService, _drawingManagerService, _dialogService, _imageIoService, _currentUniverService, _drawingRenderService) {
|
|
2255
|
+
super();
|
|
2256
|
+
this._commandService = _commandService;
|
|
2257
|
+
this._renderManagerService = _renderManagerService;
|
|
2258
|
+
this._drawingManagerService = _drawingManagerService;
|
|
2259
|
+
this._dialogService = _dialogService;
|
|
2260
|
+
this._imageIoService = _imageIoService;
|
|
2261
|
+
this._currentUniverService = _currentUniverService;
|
|
2262
|
+
this._drawingRenderService = _drawingRenderService;
|
|
2263
|
+
this._initialize();
|
|
2264
|
+
}
|
|
2265
|
+
dispose() {
|
|
2266
|
+
super.dispose();
|
|
2267
|
+
}
|
|
2268
|
+
_initialize() {
|
|
2269
|
+
this._drawingAddListener();
|
|
2270
|
+
this._commandExecutedListener();
|
|
2271
|
+
this._imageUpdateListener();
|
|
2272
|
+
}
|
|
2273
|
+
_commandExecutedListener() {
|
|
2274
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2275
|
+
if (command.id === ImageResetSizeOperation.id) {
|
|
2276
|
+
const params = command.params;
|
|
2277
|
+
if (params == null) return;
|
|
2278
|
+
this._resetImageSize(params);
|
|
2279
|
+
}
|
|
2280
|
+
}));
|
|
2281
|
+
}
|
|
2282
|
+
_getSceneAndTransformerByDrawingSearch(unitId) {
|
|
2283
|
+
if (unitId == null) return;
|
|
2284
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
2285
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2286
|
+
if (scene == null) return null;
|
|
2287
|
+
return {
|
|
2288
|
+
scene,
|
|
2289
|
+
transformer: scene.getTransformerByCreate()
|
|
2290
|
+
};
|
|
2291
|
+
}
|
|
2292
|
+
_resetImageSize(params) {
|
|
2293
|
+
const updateParams = [];
|
|
2294
|
+
const sceneList = [];
|
|
2295
|
+
params.forEach((param) => {
|
|
2296
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
2297
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
2298
|
+
if (renderObject == null) return;
|
|
2299
|
+
const { scene } = renderObject;
|
|
2300
|
+
const imageShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
2301
|
+
unitId,
|
|
2302
|
+
subUnitId,
|
|
2303
|
+
drawingId
|
|
2304
|
+
});
|
|
2305
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
2306
|
+
if (imageShape == null) return true;
|
|
2307
|
+
const imageData = this._drawingManagerService.getDrawingByParam(param);
|
|
2308
|
+
if (imageData == null) return true;
|
|
2309
|
+
if (imageData.drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return;
|
|
2310
|
+
imageShape.resetSize();
|
|
2311
|
+
const { width, height } = imageShape.getNativeSize();
|
|
2312
|
+
if (sceneList.includes(scene) === false) sceneList.push(scene);
|
|
2313
|
+
updateParams.push({
|
|
2314
|
+
...imageData,
|
|
2315
|
+
transform: {
|
|
2316
|
+
...imageData.transform,
|
|
2317
|
+
height,
|
|
2318
|
+
width,
|
|
2319
|
+
angle: 0
|
|
2320
|
+
},
|
|
2321
|
+
srcRect: null,
|
|
2322
|
+
prstGeom: null
|
|
2323
|
+
});
|
|
2324
|
+
});
|
|
2325
|
+
this._drawingManagerService.featurePluginUpdateNotification(updateParams);
|
|
2326
|
+
sceneList.forEach((scene) => {
|
|
2327
|
+
scene.getTransformerByCreate().refreshControls().changeNotification();
|
|
2328
|
+
});
|
|
2329
|
+
this._commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, params);
|
|
2330
|
+
}
|
|
2331
|
+
_drawingAddListener() {
|
|
2332
|
+
this.disposeWithMe(this._drawingManagerService.add$.pipe(bufferTime(33), filter((batches) => batches.length > 0), map((batches) => batches.flat()), map((items) => {
|
|
2333
|
+
const map = /* @__PURE__ */ new Map();
|
|
2334
|
+
for (const it of items) map.set(`${it.unitId}|${it.subUnitId}|${it.drawingId}`, it);
|
|
2335
|
+
return [...map.values()];
|
|
2336
|
+
}), filter((items) => items.length > 0)).subscribe((uniqueParams) => {
|
|
2337
|
+
this._insertImages(uniqueParams);
|
|
2338
|
+
}));
|
|
2339
|
+
}
|
|
2340
|
+
_insertImages(params) {
|
|
2341
|
+
params.forEach(async (param) => {
|
|
2342
|
+
var _getCurrentUnitInfo;
|
|
2343
|
+
const { unitId, subUnitId } = param;
|
|
2344
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
2345
|
+
const currentSubUnitId = (_getCurrentUnitInfo = getCurrentUnitInfo(this._currentUniverService, unitId)) === null || _getCurrentUnitInfo === void 0 ? void 0 : _getCurrentUnitInfo.subUnitId;
|
|
2346
|
+
if (renderObject == null || currentSubUnitId !== subUnitId) return;
|
|
2347
|
+
const imageParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2348
|
+
if (imageParam == null) return;
|
|
2349
|
+
const images = await this._drawingRenderService.renderImages(imageParam, renderObject.scene);
|
|
2350
|
+
this._drawingManagerService.refreshTransform([imageParam]);
|
|
2351
|
+
if (images == null || images.length === 0) return;
|
|
2352
|
+
for (const image of images) {
|
|
2353
|
+
this._addHoverForImage(image);
|
|
2354
|
+
this._addDialogForImage(image);
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
_imageUpdateListener() {
|
|
2359
|
+
this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
|
|
2360
|
+
params.forEach((param) => {
|
|
2361
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
2362
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2363
|
+
if (drawingParam == null) return;
|
|
2364
|
+
const { transform, drawingType, srcRect, prstGeom, source, imageSourceType } = drawingParam;
|
|
2365
|
+
if (drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return;
|
|
2366
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
2367
|
+
if (renderObject == null) return;
|
|
2368
|
+
const { scene, transformer } = renderObject;
|
|
2369
|
+
if (transform == null) return true;
|
|
2370
|
+
const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
|
|
2371
|
+
unitId,
|
|
2372
|
+
subUnitId,
|
|
2373
|
+
drawingId
|
|
2374
|
+
});
|
|
2375
|
+
const imageShape = scene.getObject(drawingShapeKey);
|
|
2376
|
+
if (imageShape == null) return true;
|
|
2377
|
+
imageShape.setSrcRect(srcRect);
|
|
2378
|
+
imageShape.setPrstGeom(prstGeom);
|
|
2379
|
+
if (source != null && source.length > 0 && (imageSourceType === ImageSourceType.BASE64 || imageSourceType === ImageSourceType.URL)) imageShape.changeSource(source);
|
|
2380
|
+
});
|
|
2381
|
+
}));
|
|
2382
|
+
}
|
|
2383
|
+
_addHoverForImage(o) {
|
|
2384
|
+
this.disposeWithMe(toDisposable(o.onPointerEnter$.subscribeEvent(() => {
|
|
2385
|
+
o.cursor = CURSOR_TYPE.GRAB;
|
|
2386
|
+
})));
|
|
2387
|
+
this.disposeWithMe(toDisposable(o.onPointerLeave$.subscribeEvent(() => {
|
|
2388
|
+
o.cursor = CURSOR_TYPE.DEFAULT;
|
|
2389
|
+
})));
|
|
2390
|
+
}
|
|
2391
|
+
_addDialogForImage(o) {
|
|
2392
|
+
this.disposeWithMe(toDisposable(o.onDblclick$.subscribeEvent(() => {
|
|
2393
|
+
const dialogId = `${o.oKey}-viewer-dialog`;
|
|
2394
|
+
this._drawingRenderService.previewImage(dialogId, o.getNative().src, o.getNativeSize().width, o.getNativeSize().height);
|
|
2395
|
+
})));
|
|
2396
|
+
}
|
|
2397
|
+
};
|
|
2398
|
+
ImageUpdateController = __decorate([
|
|
2399
|
+
__decorateParam(0, ICommandService),
|
|
2400
|
+
__decorateParam(1, IRenderManagerService),
|
|
2401
|
+
__decorateParam(2, IDrawingManagerService),
|
|
2402
|
+
__decorateParam(3, IDialogService),
|
|
2403
|
+
__decorateParam(4, IImageIoService),
|
|
2404
|
+
__decorateParam(5, IUniverInstanceService),
|
|
2405
|
+
__decorateParam(6, Inject(DrawingRenderService))
|
|
2406
|
+
], ImageUpdateController);
|
|
2407
|
+
|
|
2408
|
+
//#endregion
|
|
2409
|
+
//#region src/plugin.ts
|
|
2410
|
+
let UniverDrawingUIPlugin = class UniverDrawingUIPlugin extends Plugin {
|
|
2411
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
2412
|
+
super();
|
|
2413
|
+
this._config = _config;
|
|
2414
|
+
this._injector = _injector;
|
|
2415
|
+
this._configService = _configService;
|
|
2416
|
+
const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
2417
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
2418
|
+
this._configService.setConfig(DRAWING_UI_PLUGIN_CONFIG_KEY, rest);
|
|
2419
|
+
}
|
|
2420
|
+
onStarting() {
|
|
2421
|
+
this._initDependencies();
|
|
2422
|
+
}
|
|
2423
|
+
onRendered() {
|
|
2424
|
+
this._injector.get(DrawingUpdateController);
|
|
2425
|
+
this._injector.get(DrawingUIController);
|
|
2426
|
+
this._injector.get(ImageCropperController);
|
|
2427
|
+
this._injector.get(ImageUpdateController);
|
|
2428
|
+
}
|
|
2429
|
+
_initDependencies() {
|
|
2430
|
+
[
|
|
2431
|
+
[DrawingImageClipService],
|
|
2432
|
+
[DrawingRenderService],
|
|
2433
|
+
[DrawingUpdateController],
|
|
2434
|
+
[DrawingUIController],
|
|
2435
|
+
[ImageCropperController],
|
|
2436
|
+
[ImageUpdateController]
|
|
2437
|
+
].forEach((dependency) => this._injector.add(dependency));
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
_defineProperty(UniverDrawingUIPlugin, "pluginName", "UNIVER_DRAWING_UI_PLUGIN");
|
|
2441
|
+
_defineProperty(UniverDrawingUIPlugin, "packageName", name);
|
|
2442
|
+
_defineProperty(UniverDrawingUIPlugin, "version", version);
|
|
2443
|
+
UniverDrawingUIPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverDrawingUIPlugin);
|
|
2444
|
+
|
|
2445
|
+
//#endregion
|
|
2446
|
+
//#region src/views/panel/DrawingAlign.tsx
|
|
2447
|
+
const DrawingAlign = (props) => {
|
|
2448
|
+
const commandService = useDependency(ICommandService);
|
|
2449
|
+
const localeService = useDependency(LocaleService);
|
|
2450
|
+
const { drawings, alignShow } = props;
|
|
2451
|
+
const [alignValue, setAlignValue] = useState("0");
|
|
2452
|
+
const alignOptions = [
|
|
2453
|
+
{
|
|
2454
|
+
label: localeService.t("drawing-ui.image-panel.align.default"),
|
|
2455
|
+
value: "0"
|
|
2456
|
+
},
|
|
2457
|
+
{ options: [
|
|
2458
|
+
{
|
|
2459
|
+
label: localeService.t("drawing-ui.image-panel.align.left"),
|
|
2460
|
+
value: "1"
|
|
2461
|
+
},
|
|
2462
|
+
{
|
|
2463
|
+
label: localeService.t("drawing-ui.image-panel.align.center"),
|
|
2464
|
+
value: "2"
|
|
2465
|
+
},
|
|
2466
|
+
{
|
|
2467
|
+
label: localeService.t("drawing-ui.image-panel.align.right"),
|
|
2468
|
+
value: "3"
|
|
2469
|
+
}
|
|
2470
|
+
] },
|
|
2471
|
+
{ options: [
|
|
2472
|
+
{
|
|
2473
|
+
label: localeService.t("drawing-ui.image-panel.align.top"),
|
|
2474
|
+
value: "4"
|
|
2475
|
+
},
|
|
2476
|
+
{
|
|
2477
|
+
label: localeService.t("drawing-ui.image-panel.align.middle"),
|
|
2478
|
+
value: "5"
|
|
2479
|
+
},
|
|
2480
|
+
{
|
|
2481
|
+
label: localeService.t("drawing-ui.image-panel.align.bottom"),
|
|
2482
|
+
value: "6"
|
|
2483
|
+
}
|
|
2484
|
+
] },
|
|
2485
|
+
{ options: [{
|
|
2486
|
+
label: localeService.t("drawing-ui.image-panel.align.horizon"),
|
|
2487
|
+
value: "7"
|
|
2488
|
+
}, {
|
|
2489
|
+
label: localeService.t("drawing-ui.image-panel.align.vertical"),
|
|
2490
|
+
value: "8"
|
|
2491
|
+
}] }
|
|
2492
|
+
];
|
|
2493
|
+
function handleAlignChange(value) {
|
|
2494
|
+
setAlignValue(value);
|
|
2495
|
+
commandService.executeCommand(SetDrawingAlignOperation.id, {
|
|
2496
|
+
alignType: value,
|
|
2497
|
+
drawings
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2501
|
+
className: clsx("univer-relative univer-w-full", { "univer-hidden": !alignShow }),
|
|
2502
|
+
children: [/* @__PURE__ */ jsx("header", {
|
|
2503
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2504
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("drawing-ui.image-panel.align.title") })
|
|
2505
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2506
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
2507
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2508
|
+
className: "univer-w-full univer-text-gray-900 dark:!univer-text-white",
|
|
2509
|
+
children: /* @__PURE__ */ jsx(Select, {
|
|
2510
|
+
value: alignValue,
|
|
2511
|
+
options: alignOptions,
|
|
2512
|
+
onChange: handleAlignChange
|
|
2513
|
+
})
|
|
2514
|
+
})
|
|
2515
|
+
})]
|
|
2516
|
+
});
|
|
2517
|
+
};
|
|
2518
|
+
|
|
2519
|
+
//#endregion
|
|
2520
|
+
//#region src/views/panel/DrawingArrange.tsx
|
|
2521
|
+
const DrawingArrange = (props) => {
|
|
2522
|
+
const { arrangeShow, drawings: focusDrawings } = props;
|
|
2523
|
+
const localeService = useDependency(LocaleService);
|
|
2524
|
+
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2525
|
+
const commandService = useDependency(ICommandService);
|
|
2526
|
+
const componentManager = useDependency(ComponentManager);
|
|
2527
|
+
const MoveUpIcon = componentManager.get("MoveUpIcon");
|
|
2528
|
+
const MoveDownIcon = componentManager.get("MoveDownIcon");
|
|
2529
|
+
const TopmostIcon = componentManager.get("TopmostIcon");
|
|
2530
|
+
const BottomIcon = componentManager.get("BottomIcon");
|
|
2531
|
+
const [drawings, setDrawings] = useState(focusDrawings);
|
|
2532
|
+
useEffect(() => {
|
|
2533
|
+
const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
|
|
2534
|
+
setDrawings(drawings);
|
|
2535
|
+
});
|
|
2536
|
+
return () => {
|
|
2537
|
+
focusDispose.unsubscribe();
|
|
2538
|
+
};
|
|
2539
|
+
}, []);
|
|
2540
|
+
const onArrangeBtnClick = (arrangeType) => {
|
|
2541
|
+
commandService.syncExecuteCommand(SetDrawingArrangeOperation.id, {
|
|
2542
|
+
arrangeType,
|
|
2543
|
+
drawings
|
|
2544
|
+
});
|
|
2545
|
+
};
|
|
2546
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2547
|
+
className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !arrangeShow }),
|
|
2548
|
+
children: [/* @__PURE__ */ jsx("header", {
|
|
2549
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2550
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("drawing-ui.image-panel.arrange.title") })
|
|
2551
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
2552
|
+
className: "univer-grid univer-grid-cols-2 univer-gap-2",
|
|
2553
|
+
children: [
|
|
2554
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
2555
|
+
onClick: () => {
|
|
2556
|
+
onArrangeBtnClick(ArrangeTypeEnum.forward);
|
|
2557
|
+
},
|
|
2558
|
+
children: [/* @__PURE__ */ jsx(MoveUpIcon, {}), localeService.t("drawing-ui.image-panel.arrange.forward")]
|
|
2559
|
+
}),
|
|
2560
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
2561
|
+
onClick: () => {
|
|
2562
|
+
onArrangeBtnClick(ArrangeTypeEnum.backward);
|
|
2563
|
+
},
|
|
2564
|
+
children: [/* @__PURE__ */ jsx(MoveDownIcon, {}), localeService.t("drawing-ui.image-panel.arrange.backward")]
|
|
2565
|
+
}),
|
|
2566
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
2567
|
+
onClick: () => {
|
|
2568
|
+
onArrangeBtnClick(ArrangeTypeEnum.front);
|
|
2569
|
+
},
|
|
2570
|
+
children: [/* @__PURE__ */ jsx(TopmostIcon, {}), localeService.t("drawing-ui.image-panel.arrange.front")]
|
|
2571
|
+
}),
|
|
2572
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
2573
|
+
onClick: () => {
|
|
2574
|
+
onArrangeBtnClick(ArrangeTypeEnum.back);
|
|
2575
|
+
},
|
|
2576
|
+
children: [/* @__PURE__ */ jsx(BottomIcon, {}), localeService.t("drawing-ui.image-panel.arrange.back")]
|
|
2577
|
+
})
|
|
2578
|
+
]
|
|
2579
|
+
})]
|
|
2580
|
+
});
|
|
2581
|
+
};
|
|
2582
|
+
|
|
2583
|
+
//#endregion
|
|
2584
|
+
//#region src/views/panel/DrawingGroup.tsx
|
|
2585
|
+
const DrawingGroup = (props) => {
|
|
2586
|
+
const localeService = useDependency(LocaleService);
|
|
2587
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
2588
|
+
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2589
|
+
const commandService = useDependency(ICommandService);
|
|
2590
|
+
const componentManager = useDependency(ComponentManager);
|
|
2591
|
+
const { hasGroup, drawings } = props;
|
|
2592
|
+
const GroupIcon = componentManager.get("GroupIcon");
|
|
2593
|
+
const UngroupIcon = componentManager.get("UngroupIcon");
|
|
2594
|
+
const [groupShow, setGroupShow] = useState(false);
|
|
2595
|
+
const [groupBtnShow, setGroupBtnShow] = useState(true);
|
|
2596
|
+
const [ungroupBtnShow, setUngroupBtnShow] = useState(true);
|
|
2597
|
+
const onGroupBtnClick = () => {
|
|
2598
|
+
commandService.syncExecuteCommand(SetDrawingGroupOperation.id, { drawings });
|
|
2599
|
+
};
|
|
2600
|
+
const onUngroupBtnClick = () => {
|
|
2601
|
+
commandService.syncExecuteCommand(CancelDrawingGroupOperation.id, { drawings });
|
|
2602
|
+
};
|
|
2603
|
+
useEffect(() => {
|
|
2604
|
+
const drawingParam = drawings[0];
|
|
2605
|
+
if (drawingParam == null) return;
|
|
2606
|
+
const { unitId } = drawingParam;
|
|
2607
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
2608
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2609
|
+
if (scene == null) return;
|
|
2610
|
+
const transformer = scene.getTransformerByCreate();
|
|
2611
|
+
const onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
|
|
2612
|
+
if (changeSelf === true) setGroupShow(false);
|
|
2613
|
+
});
|
|
2614
|
+
const onChangeStartObserver = transformer.changeStart$.subscribe((state) => {
|
|
2615
|
+
const { objects } = state;
|
|
2616
|
+
const params = getUpdateParams(objects, drawingManagerService);
|
|
2617
|
+
const groupParams = params.filter((o) => (o === null || o === void 0 ? void 0 : o.drawingType) === DrawingTypeEnum.DRAWING_GROUP);
|
|
2618
|
+
let groupBtnShow = false;
|
|
2619
|
+
let ungroupBtnShow = false;
|
|
2620
|
+
if (params.length > 1) groupBtnShow = true;
|
|
2621
|
+
if (groupParams.length > 0) ungroupBtnShow = true;
|
|
2622
|
+
setGroupShow(groupBtnShow || ungroupBtnShow);
|
|
2623
|
+
setGroupBtnShow(groupBtnShow);
|
|
2624
|
+
setUngroupBtnShow(ungroupBtnShow);
|
|
2625
|
+
});
|
|
2626
|
+
return () => {
|
|
2627
|
+
onChangeStartObserver.unsubscribe();
|
|
2628
|
+
onClearControlObserver.unsubscribe();
|
|
2629
|
+
};
|
|
2630
|
+
}, []);
|
|
2631
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2632
|
+
className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": hasGroup === true && groupShow === false || hasGroup === false }),
|
|
2633
|
+
children: [/* @__PURE__ */ jsx("header", {
|
|
2634
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2635
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("drawing-ui.image-panel.group.title") })
|
|
2636
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
2637
|
+
className: "univer-flex univer-items-center univer-justify-center univer-gap-2",
|
|
2638
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
2639
|
+
className: clsx({ "univer-hidden": !groupBtnShow }),
|
|
2640
|
+
onClick: onGroupBtnClick,
|
|
2641
|
+
children: [/* @__PURE__ */ jsx(GroupIcon, {}), localeService.t("drawing-ui.image-panel.group.group")]
|
|
2642
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
2643
|
+
className: clsx({ "univer-hidden": !ungroupBtnShow }),
|
|
2644
|
+
onClick: onUngroupBtnClick,
|
|
2645
|
+
children: [/* @__PURE__ */ jsx(UngroupIcon, {}), localeService.t("drawing-ui.image-panel.group.unGroup")]
|
|
2646
|
+
})]
|
|
2647
|
+
})]
|
|
2648
|
+
});
|
|
2649
|
+
};
|
|
2650
|
+
|
|
2651
|
+
//#endregion
|
|
2652
|
+
//#region src/utils/config.ts
|
|
2653
|
+
const RANGE_DRAWING_ROTATION_LIMIT = [-360, 360];
|
|
2654
|
+
|
|
2655
|
+
//#endregion
|
|
2656
|
+
//#region src/views/panel/DrawingTransform.tsx
|
|
2657
|
+
const INPUT_DEBOUNCE_TIME = 300;
|
|
2658
|
+
const DrawingTransform = (props) => {
|
|
2659
|
+
var _scene$getEngine;
|
|
2660
|
+
const localeService = useDependency(LocaleService);
|
|
2661
|
+
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
2662
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
2663
|
+
const { drawings, transformShow } = props;
|
|
2664
|
+
const drawingParam = drawings[0];
|
|
2665
|
+
if (drawingParam == null) return;
|
|
2666
|
+
const transform = drawingParam.transform;
|
|
2667
|
+
if (transform == null) return;
|
|
2668
|
+
const { unitId, subUnitId, drawingId, drawingType } = drawingParam;
|
|
2669
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
2670
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2671
|
+
if (scene == null) return;
|
|
2672
|
+
const topScene = (_scene$getEngine = scene.getEngine()) === null || _scene$getEngine === void 0 ? void 0 : _scene$getEngine.activeScene;
|
|
2673
|
+
if (topScene == null) return;
|
|
2674
|
+
const transformer = scene.getTransformerByCreate();
|
|
2675
|
+
const { width: originWidth = 0, height: originHeight = 0, left: originX = 0, top: originY = 0, angle: originRotation = 0 } = transform;
|
|
2676
|
+
const [width, setWidth] = useState(originWidth);
|
|
2677
|
+
const [height, setHeight] = useState(originHeight);
|
|
2678
|
+
const [xPosition, setXPosition] = useState(originX);
|
|
2679
|
+
const [yPosition, setYPosition] = useState(originY);
|
|
2680
|
+
const [rotation, setRotation] = useState(originRotation);
|
|
2681
|
+
const [lockRatio, setLockRatio] = useState(transformer.keepRatio);
|
|
2682
|
+
const checkMoveBoundary = (left, top, width, height) => {
|
|
2683
|
+
const { width: topSceneWidth, height: topSceneHeight } = topScene;
|
|
2684
|
+
const { ancestorLeft, ancestorTop } = scene;
|
|
2685
|
+
let limitLeft = left;
|
|
2686
|
+
let limitTop = top;
|
|
2687
|
+
let limitWidth = width;
|
|
2688
|
+
let limitHeight = height;
|
|
2689
|
+
if (left + ancestorLeft < 0) limitLeft = -ancestorLeft;
|
|
2690
|
+
if (top + ancestorTop < 0) limitTop = -ancestorTop;
|
|
2691
|
+
limitWidth = topSceneWidth - limitLeft - ancestorLeft;
|
|
2692
|
+
if (limitWidth < 20) limitWidth = 20;
|
|
2693
|
+
limitHeight = topSceneHeight - limitTop - ancestorTop;
|
|
2694
|
+
if (limitHeight < 20) limitHeight = 20;
|
|
2695
|
+
if (left + limitWidth + ancestorLeft > topSceneWidth) limitLeft = topSceneWidth - width - ancestorLeft;
|
|
2696
|
+
if (top + limitHeight + ancestorTop > topSceneHeight) limitTop = topSceneHeight - height - ancestorTop;
|
|
2697
|
+
return {
|
|
2698
|
+
limitLeft,
|
|
2699
|
+
limitTop,
|
|
2700
|
+
limitWidth,
|
|
2701
|
+
limitHeight
|
|
2702
|
+
};
|
|
2703
|
+
};
|
|
2704
|
+
const changeObs = (state) => {
|
|
2705
|
+
const { objects } = state;
|
|
2706
|
+
const params = getUpdateParams(objects, drawingManagerService);
|
|
2707
|
+
if (params.length !== 1) return;
|
|
2708
|
+
const drawingParam = params[0];
|
|
2709
|
+
if (drawingParam == null) return;
|
|
2710
|
+
const { transform } = drawingParam;
|
|
2711
|
+
if (transform == null) return;
|
|
2712
|
+
const { width: originWidth, height: originHeight, left: originX, top: originY, angle: originRotation } = transform;
|
|
2713
|
+
if (originWidth != null) setWidth(originWidth);
|
|
2714
|
+
if (originHeight != null) setHeight(originHeight);
|
|
2715
|
+
if (originX != null) setXPosition(originX);
|
|
2716
|
+
if (originY != null) setYPosition(originY);
|
|
2717
|
+
if (originRotation != null) setRotation(originRotation);
|
|
2718
|
+
};
|
|
2719
|
+
useEffect(() => {
|
|
2720
|
+
const subscriptions = [
|
|
2721
|
+
transformer.changeStart$.subscribe((state) => {
|
|
2722
|
+
changeObs(state);
|
|
2723
|
+
}),
|
|
2724
|
+
transformer.changing$.subscribe((state) => {
|
|
2725
|
+
changeObs(state);
|
|
2726
|
+
}),
|
|
2727
|
+
transformer.changeEnd$.subscribe((state) => {
|
|
2728
|
+
changeObs(state);
|
|
2729
|
+
}),
|
|
2730
|
+
drawingManagerService.focus$.subscribe((drawings) => {
|
|
2731
|
+
if (drawings.length !== 1) return;
|
|
2732
|
+
const drawingParam = drawingManagerService.getDrawingByParam(drawings[0]);
|
|
2733
|
+
if (drawingParam == null) return;
|
|
2734
|
+
const transform = drawingParam.transform;
|
|
2735
|
+
if (transform == null) return;
|
|
2736
|
+
const { width: originWidth, height: originHeight, left: originX, top: originY, angle: originRotation } = transform;
|
|
2737
|
+
if (originWidth != null) setWidth(originWidth);
|
|
2738
|
+
if (originHeight != null) setHeight(originHeight);
|
|
2739
|
+
if (originX != null) setXPosition(originX);
|
|
2740
|
+
if (originY != null) setYPosition(originY);
|
|
2741
|
+
if (originRotation != null) setRotation(originRotation);
|
|
2742
|
+
})
|
|
2743
|
+
];
|
|
2744
|
+
return () => {
|
|
2745
|
+
subscriptions.forEach((sub) => sub.unsubscribe());
|
|
2746
|
+
};
|
|
2747
|
+
}, []);
|
|
2748
|
+
const handleWidthChange = debounce((val) => {
|
|
2749
|
+
if (val == null) return;
|
|
2750
|
+
const { limitWidth, limitHeight } = checkMoveBoundary(xPosition, yPosition, val, height);
|
|
2751
|
+
val = Math.min(val, limitWidth);
|
|
2752
|
+
const updateParam = {
|
|
2753
|
+
unitId,
|
|
2754
|
+
subUnitId,
|
|
2755
|
+
drawingId,
|
|
2756
|
+
drawingType,
|
|
2757
|
+
transform: { width: val }
|
|
2758
|
+
};
|
|
2759
|
+
if (lockRatio) {
|
|
2760
|
+
let heightFix = val / width * height;
|
|
2761
|
+
heightFix = Math.max(heightFix, 20);
|
|
2762
|
+
if (heightFix > limitHeight) return;
|
|
2763
|
+
setHeight(heightFix);
|
|
2764
|
+
updateParam.transform.height = heightFix;
|
|
2765
|
+
}
|
|
2766
|
+
setWidth(val);
|
|
2767
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2768
|
+
transformer.refreshControls().changeNotification();
|
|
2769
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2770
|
+
const handleHeightChange = debounce((val) => {
|
|
2771
|
+
if (val == null) return;
|
|
2772
|
+
const { limitHeight, limitWidth } = checkMoveBoundary(xPosition, yPosition, width, val);
|
|
2773
|
+
val = Math.min(val, limitHeight);
|
|
2774
|
+
const updateParam = {
|
|
2775
|
+
unitId,
|
|
2776
|
+
subUnitId,
|
|
2777
|
+
drawingId,
|
|
2778
|
+
drawingType,
|
|
2779
|
+
transform: { height: val }
|
|
2780
|
+
};
|
|
2781
|
+
if (lockRatio) {
|
|
2782
|
+
let widthFix = val / height * width;
|
|
2783
|
+
widthFix = Math.max(widthFix, 20);
|
|
2784
|
+
if (widthFix > limitWidth) return;
|
|
2785
|
+
setWidth(widthFix);
|
|
2786
|
+
updateParam.transform.width = widthFix;
|
|
2787
|
+
}
|
|
2788
|
+
setHeight(val);
|
|
2789
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2790
|
+
transformer.refreshControls().changeNotification();
|
|
2791
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2792
|
+
const handleXChange = debounce((val) => {
|
|
2793
|
+
if (val == null) return;
|
|
2794
|
+
const { limitLeft } = checkMoveBoundary(val, yPosition, width, height);
|
|
2795
|
+
val = limitLeft;
|
|
2796
|
+
const updateParam = {
|
|
2797
|
+
unitId,
|
|
2798
|
+
subUnitId,
|
|
2799
|
+
drawingId,
|
|
2800
|
+
drawingType,
|
|
2801
|
+
transform: { left: val }
|
|
2802
|
+
};
|
|
2803
|
+
setXPosition(val);
|
|
2804
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2805
|
+
transformer.refreshControls().changeNotification();
|
|
2806
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2807
|
+
const handleYChange = debounce((val) => {
|
|
2808
|
+
if (val == null) return;
|
|
2809
|
+
const { limitTop } = checkMoveBoundary(xPosition, val, width, height);
|
|
2810
|
+
val = limitTop;
|
|
2811
|
+
const updateParam = {
|
|
2812
|
+
unitId,
|
|
2813
|
+
subUnitId,
|
|
2814
|
+
drawingId,
|
|
2815
|
+
drawingType,
|
|
2816
|
+
transform: { top: val }
|
|
2817
|
+
};
|
|
2818
|
+
setYPosition(val);
|
|
2819
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2820
|
+
transformer.refreshControls().changeNotification();
|
|
2821
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2822
|
+
const handleRotationChange = (val) => {
|
|
2823
|
+
if (val == null) return;
|
|
2824
|
+
const updateParam = {
|
|
2825
|
+
unitId,
|
|
2826
|
+
subUnitId,
|
|
2827
|
+
drawingId,
|
|
2828
|
+
drawingType,
|
|
2829
|
+
transform: { angle: val }
|
|
2830
|
+
};
|
|
2831
|
+
setRotation(val);
|
|
2832
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2833
|
+
transformer.refreshControls().changeNotification();
|
|
2834
|
+
};
|
|
2835
|
+
const handleLockRatioChange = (val) => {
|
|
2836
|
+
setLockRatio(val);
|
|
2837
|
+
transformer.keepRatio = val;
|
|
2838
|
+
};
|
|
2839
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2840
|
+
className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !transformShow }),
|
|
2841
|
+
children: [
|
|
2842
|
+
/* @__PURE__ */ jsx("header", {
|
|
2843
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2844
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("drawing-ui.image-panel.transform.title") })
|
|
2845
|
+
}),
|
|
2846
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2847
|
+
className: "univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
2848
|
+
children: [
|
|
2849
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.transform.width") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2850
|
+
precision: 1,
|
|
2851
|
+
value: width,
|
|
2852
|
+
min: 20,
|
|
2853
|
+
onChange: (val) => {
|
|
2854
|
+
handleWidthChange(val);
|
|
2855
|
+
}
|
|
2856
|
+
})] }),
|
|
2857
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.transform.height") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2858
|
+
precision: 1,
|
|
2859
|
+
value: height,
|
|
2860
|
+
min: 20,
|
|
2861
|
+
onChange: (val) => {
|
|
2862
|
+
handleHeightChange(val);
|
|
2863
|
+
}
|
|
2864
|
+
})] }),
|
|
2865
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.transform.lock") }), /* @__PURE__ */ jsx("div", {
|
|
2866
|
+
className: "univer-text-center",
|
|
2867
|
+
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
2868
|
+
checked: lockRatio,
|
|
2869
|
+
onChange: handleLockRatioChange
|
|
2870
|
+
})
|
|
2871
|
+
})] })
|
|
2872
|
+
]
|
|
2873
|
+
}),
|
|
2874
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2875
|
+
className: "univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
2876
|
+
children: [
|
|
2877
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.transform.x") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2878
|
+
precision: 1,
|
|
2879
|
+
value: xPosition,
|
|
2880
|
+
onChange: (val) => {
|
|
2881
|
+
handleXChange(val);
|
|
2882
|
+
}
|
|
2883
|
+
})] }),
|
|
2884
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.transform.y") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2885
|
+
precision: 1,
|
|
2886
|
+
value: yPosition,
|
|
2887
|
+
onChange: (val) => {
|
|
2888
|
+
handleYChange(val);
|
|
2889
|
+
}
|
|
2890
|
+
})] }),
|
|
2891
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.transform.rotate") }), /* @__PURE__ */ jsx(InputNumber, {
|
|
2892
|
+
precision: 1,
|
|
2893
|
+
value: rotation,
|
|
2894
|
+
min: RANGE_DRAWING_ROTATION_LIMIT[0],
|
|
2895
|
+
max: RANGE_DRAWING_ROTATION_LIMIT[1],
|
|
2896
|
+
onChange: handleRotationChange
|
|
2897
|
+
})] })
|
|
2898
|
+
]
|
|
2899
|
+
})
|
|
2900
|
+
]
|
|
2901
|
+
});
|
|
2902
|
+
};
|
|
2903
|
+
|
|
2904
|
+
//#endregion
|
|
2905
|
+
//#region src/views/panel/ImageCropper.tsx
|
|
2906
|
+
const ImageCropper = (props) => {
|
|
2907
|
+
const commandService = useDependency(ICommandService);
|
|
2908
|
+
const localeService = useDependency(LocaleService);
|
|
2909
|
+
const clipService = useDependency(DrawingImageClipService);
|
|
2910
|
+
const componentManager = useDependency(ComponentManager);
|
|
2911
|
+
const canUseShapeClip = useObservable(clipService.canUseShapeClip$, false);
|
|
2912
|
+
const { drawings, cropperShow } = props;
|
|
2913
|
+
if (drawings[0] == null) return;
|
|
2914
|
+
const [cropValue, setCropValue] = useState("0");
|
|
2915
|
+
const cropStateRef = useRef(false);
|
|
2916
|
+
const cropOptions = [
|
|
2917
|
+
{
|
|
2918
|
+
label: localeService.t("drawing-ui.image-panel.crop.mode"),
|
|
2919
|
+
value: "0"
|
|
2920
|
+
},
|
|
2921
|
+
{
|
|
2922
|
+
label: "1:1",
|
|
2923
|
+
value: "1"
|
|
2924
|
+
},
|
|
2925
|
+
{
|
|
2926
|
+
label: "16:9",
|
|
2927
|
+
value: "2"
|
|
2928
|
+
},
|
|
2929
|
+
{
|
|
2930
|
+
label: "9:16",
|
|
2931
|
+
value: "3"
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
label: "5:4",
|
|
2935
|
+
value: "4"
|
|
2936
|
+
},
|
|
2937
|
+
{
|
|
2938
|
+
label: "4:5",
|
|
2939
|
+
value: "5"
|
|
2940
|
+
},
|
|
2941
|
+
{
|
|
2942
|
+
label: "4:3",
|
|
2943
|
+
value: "6"
|
|
2944
|
+
},
|
|
2945
|
+
{
|
|
2946
|
+
label: "3:4",
|
|
2947
|
+
value: "7"
|
|
2948
|
+
},
|
|
2949
|
+
{
|
|
2950
|
+
label: "3:2",
|
|
2951
|
+
value: "8"
|
|
2952
|
+
},
|
|
2953
|
+
{
|
|
2954
|
+
label: "2:3",
|
|
2955
|
+
value: "9"
|
|
2956
|
+
}
|
|
2957
|
+
];
|
|
2958
|
+
useEffect(() => {
|
|
2959
|
+
const onChangeStartObserver = commandService.onCommandExecuted((command) => {
|
|
2960
|
+
if (command.id === CloseImageCropOperation.id) {
|
|
2961
|
+
const params = command.params;
|
|
2962
|
+
if (!(params === null || params === void 0 ? void 0 : params.isAuto)) cropStateRef.current = false;
|
|
2963
|
+
}
|
|
2964
|
+
});
|
|
2965
|
+
return () => {
|
|
2966
|
+
onChangeStartObserver === null || onChangeStartObserver === void 0 || onChangeStartObserver.dispose();
|
|
2967
|
+
};
|
|
2968
|
+
}, []);
|
|
2969
|
+
function handleCropChange(value) {
|
|
2970
|
+
setCropValue(value);
|
|
2971
|
+
if (cropStateRef.current) commandService.executeCommand(AutoImageCropOperation.id, { cropType: value });
|
|
2972
|
+
}
|
|
2973
|
+
const onCropperBtnClick = (val) => {
|
|
2974
|
+
commandService.executeCommand(AutoImageCropOperation.id, { cropType: val });
|
|
2975
|
+
cropStateRef.current = true;
|
|
2976
|
+
};
|
|
2977
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2978
|
+
className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !cropperShow }),
|
|
2979
|
+
children: [
|
|
2980
|
+
/* @__PURE__ */ jsx("header", {
|
|
2981
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2982
|
+
children: /* @__PURE__ */ jsx("div", { children: localeService.t("drawing-ui.image-panel.crop.title") })
|
|
2983
|
+
}),
|
|
2984
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2985
|
+
className: "univer-flex univer-items-center univer-justify-center univer-gap-2",
|
|
2986
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
2987
|
+
onClick: () => {
|
|
2988
|
+
onCropperBtnClick(cropValue);
|
|
2989
|
+
},
|
|
2990
|
+
children: [/* @__PURE__ */ jsx(CreateCopyIcon, {}), localeService.t("drawing-ui.image-panel.crop.start")]
|
|
2991
|
+
}), /* @__PURE__ */ jsx(Select, {
|
|
2992
|
+
value: cropValue,
|
|
2993
|
+
options: cropOptions,
|
|
2994
|
+
onChange: handleCropChange
|
|
2995
|
+
})]
|
|
2996
|
+
}),
|
|
2997
|
+
canUseShapeClip && (() => {
|
|
2998
|
+
const ShapeClipPicker = componentManager.get("sheet.image-clip.shape.picker.component");
|
|
2999
|
+
return ShapeClipPicker ? /* @__PURE__ */ jsx(ShapeClipPicker, {}) : null;
|
|
3000
|
+
})()
|
|
3001
|
+
]
|
|
3002
|
+
});
|
|
3003
|
+
};
|
|
3004
|
+
|
|
3005
|
+
//#endregion
|
|
3006
|
+
//#region src/views/panel/DrawingCommonPanel.tsx
|
|
3007
|
+
const DrawingCommonPanel = (props) => {
|
|
3008
|
+
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
3009
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
3010
|
+
const localeService = useDependency(LocaleService);
|
|
3011
|
+
const { drawings, hasArrange = true, hasTransform = true, hasAlign = true, hasCropper = true, hasGroup = true } = props;
|
|
3012
|
+
const drawingParam = drawings[0];
|
|
3013
|
+
if (drawingParam == null) return;
|
|
3014
|
+
const { unitId } = drawingParam;
|
|
3015
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
3016
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
3017
|
+
if (scene == null) return;
|
|
3018
|
+
const transformer = scene.getTransformerByCreate();
|
|
3019
|
+
const [arrangeShow, setArrangeShow] = useState(true);
|
|
3020
|
+
const [transformShow, setTransformShow] = useState(true);
|
|
3021
|
+
const [alignShow, setAlignShow] = useState(false);
|
|
3022
|
+
const [cropperShow, setCropperShow] = useState(true);
|
|
3023
|
+
const [nullShow, setNullShow] = useState(false);
|
|
3024
|
+
useEffect(() => {
|
|
3025
|
+
const clearControlSub = transformer.clearControl$.subscribe((changeSelf) => {
|
|
3026
|
+
if (changeSelf === true) {
|
|
3027
|
+
setArrangeShow(false);
|
|
3028
|
+
setTransformShow(false);
|
|
3029
|
+
setAlignShow(false);
|
|
3030
|
+
setCropperShow(false);
|
|
3031
|
+
setNullShow(true);
|
|
3032
|
+
}
|
|
3033
|
+
});
|
|
3034
|
+
const changeStartSub = transformer.changeStart$.subscribe((state) => {
|
|
3035
|
+
const { objects } = state;
|
|
3036
|
+
const params = getUpdateParams(objects, drawingManagerService);
|
|
3037
|
+
if (params.length === 0) {
|
|
3038
|
+
setArrangeShow(false);
|
|
3039
|
+
setTransformShow(false);
|
|
3040
|
+
setAlignShow(false);
|
|
3041
|
+
setCropperShow(false);
|
|
3042
|
+
setNullShow(true);
|
|
3043
|
+
} else if (params.length === 1) {
|
|
3044
|
+
setArrangeShow(true);
|
|
3045
|
+
setTransformShow(true);
|
|
3046
|
+
setAlignShow(false);
|
|
3047
|
+
setCropperShow(true);
|
|
3048
|
+
setNullShow(false);
|
|
3049
|
+
} else {
|
|
3050
|
+
setArrangeShow(true);
|
|
3051
|
+
setTransformShow(false);
|
|
3052
|
+
setAlignShow(true);
|
|
3053
|
+
setCropperShow(false);
|
|
3054
|
+
setNullShow(false);
|
|
3055
|
+
}
|
|
3056
|
+
});
|
|
3057
|
+
const focusSub = drawingManagerService.focus$.subscribe((drawings) => {
|
|
3058
|
+
if (drawings.length === 0) {
|
|
3059
|
+
setArrangeShow(false);
|
|
3060
|
+
setTransformShow(false);
|
|
3061
|
+
setAlignShow(false);
|
|
3062
|
+
setCropperShow(false);
|
|
3063
|
+
setNullShow(true);
|
|
3064
|
+
} else if (drawings.length === 1) {
|
|
3065
|
+
setArrangeShow(true);
|
|
3066
|
+
setTransformShow(true);
|
|
3067
|
+
setAlignShow(false);
|
|
3068
|
+
setCropperShow(true);
|
|
3069
|
+
setNullShow(false);
|
|
3070
|
+
} else {
|
|
3071
|
+
setArrangeShow(true);
|
|
3072
|
+
setTransformShow(false);
|
|
3073
|
+
setAlignShow(true);
|
|
3074
|
+
setCropperShow(false);
|
|
3075
|
+
setNullShow(false);
|
|
3076
|
+
}
|
|
3077
|
+
});
|
|
3078
|
+
return () => {
|
|
3079
|
+
changeStartSub.unsubscribe();
|
|
3080
|
+
clearControlSub.unsubscribe();
|
|
3081
|
+
focusSub.unsubscribe();
|
|
3082
|
+
};
|
|
3083
|
+
}, []);
|
|
3084
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3085
|
+
/* @__PURE__ */ jsx("div", {
|
|
3086
|
+
className: clsx("univer-h-full", { "univer-hidden": !nullShow }),
|
|
3087
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
3088
|
+
className: "univer-flex univer-h-full univer-items-center univer-justify-center",
|
|
3089
|
+
children: /* @__PURE__ */ jsx("span", { children: localeService.t("drawing-ui.image-panel.null") })
|
|
3090
|
+
})
|
|
3091
|
+
}),
|
|
3092
|
+
/* @__PURE__ */ jsx(DrawingArrange, {
|
|
3093
|
+
arrangeShow: hasArrange === true ? arrangeShow : false,
|
|
3094
|
+
drawings
|
|
3095
|
+
}),
|
|
3096
|
+
/* @__PURE__ */ jsx(DrawingTransform, {
|
|
3097
|
+
transformShow: hasTransform === true ? transformShow : false,
|
|
3098
|
+
drawings
|
|
3099
|
+
}),
|
|
3100
|
+
/* @__PURE__ */ jsx(DrawingAlign, {
|
|
3101
|
+
alignShow: hasAlign === true ? alignShow : false,
|
|
3102
|
+
drawings
|
|
3103
|
+
}),
|
|
3104
|
+
/* @__PURE__ */ jsx(ImageCropper, {
|
|
3105
|
+
cropperShow: hasCropper === true ? cropperShow : false,
|
|
3106
|
+
drawings
|
|
3107
|
+
}),
|
|
3108
|
+
/* @__PURE__ */ jsx(DrawingGroup, {
|
|
3109
|
+
hasGroup,
|
|
3110
|
+
drawings
|
|
3111
|
+
})
|
|
3112
|
+
] });
|
|
3113
|
+
};
|
|
3114
|
+
|
|
3115
|
+
//#endregion
|
|
3116
|
+
export { AutoImageCropOperation, COMPONENT_IMAGE_POPUP_MENU, CancelDrawingGroupOperation, CloseImageCropOperation, DRAWING_GROUP_TYPES, DrawingCommonPanel, DrawingImageClipService, DrawingRenderService, IMAGE_CLIP_SHAPE_PICKER_COMPONENT, ImageCropperObject, ImagePopupMenu, ImageResetSizeOperation, OpenImageCropOperation, SetDrawingAlignOperation, SetDrawingArrangeOperation, SetDrawingGroupOperation, UniverDrawingUIPlugin, getCurrentUnitInfo, getUpdateParams, insertGroupObject };
|