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