@univerjs/drawing-ui 1.0.0-alpha.3 → 1.0.0-alpha.4
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 +105 -184
- package/lib/es/index.js +106 -185
- package/lib/index.js +106 -185
- package/lib/types/views/image-popup-menu/ImagePopupMenu.d.ts +1 -0
- package/lib/types/views/panel/DrawingCommonPanel.d.ts +1 -1
- package/lib/types/views/panel/DrawingTransform.d.ts +1 -1
- package/lib/types/views/panel/ImageCropper.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +9 -9
package/lib/es/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ArrangeTypeEnum, BooleanNumber, CommandType, Disposable, DrawingTypeEnu
|
|
|
2
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
4
|
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, IGalleryService, IMenuManagerService, IMessageService, IconManager, MenuItemType, useDependency, useObservable } from "@univerjs/ui";
|
|
5
|
-
import { BehaviorSubject, Observable, bufferTime, filter, map, of, switchMap } from "rxjs";
|
|
5
|
+
import { BehaviorSubject, Observable, bufferTime, filter, map, merge as merge$1, of, switchMap } from "rxjs";
|
|
6
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
7
|
import { Button, Checkbox, Dropdown, DropdownMenu, Input, InputNumber, MessageType, Select, Separator, Tooltip, borderClassName, clsx } from "@univerjs/design";
|
|
8
8
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -624,7 +624,7 @@ const menuSchema = { [ContextMenuPosition.DRAWING]: { [ContextMenuGroup.OTHERS]:
|
|
|
624
624
|
//#endregion
|
|
625
625
|
//#region package.json
|
|
626
626
|
var name = "@univerjs/drawing-ui";
|
|
627
|
-
var version = "1.0.0-alpha.
|
|
627
|
+
var version = "1.0.0-alpha.4";
|
|
628
628
|
|
|
629
629
|
//#endregion
|
|
630
630
|
//#region src/config/config.ts
|
|
@@ -657,6 +657,10 @@ function ImagePopupMenu(props) {
|
|
|
657
657
|
var _popup$extraProps, _popup$extraProps2, _popup$extraProps3;
|
|
658
658
|
const { popup } = props;
|
|
659
659
|
const menuItems = popup === null || popup === void 0 || (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.menuItems;
|
|
660
|
+
const commandService = useDependency(ICommandService);
|
|
661
|
+
const localeService = useDependency(LocaleService);
|
|
662
|
+
const [visible, setVisible] = useState(false);
|
|
663
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
660
664
|
if (!menuItems) return null;
|
|
661
665
|
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
666
|
menuItems,
|
|
@@ -665,15 +669,11 @@ function ImagePopupMenu(props) {
|
|
|
665
669
|
drawingId: popup.extraProps.drawingId
|
|
666
670
|
});
|
|
667
671
|
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
672
|
const handleMouseEnter = () => {
|
|
673
|
-
|
|
673
|
+
setIsHovered(true);
|
|
674
674
|
};
|
|
675
675
|
const handleMouseLeave = () => {
|
|
676
|
-
|
|
676
|
+
setIsHovered(false);
|
|
677
677
|
};
|
|
678
678
|
const onVisibleChange = (visible) => {
|
|
679
679
|
setVisible(visible);
|
|
@@ -772,16 +772,14 @@ function ToolbarDropdownButton(props) {
|
|
|
772
772
|
});
|
|
773
773
|
}
|
|
774
774
|
function DocImageFloatingToolbar(props) {
|
|
775
|
-
var _univerInstanceServic, _wrappingStyleOptions, _wrappingStyleOptions2
|
|
775
|
+
var _univerInstanceServic, _wrappingStyleOptions, _wrappingStyleOptions2;
|
|
776
776
|
const commandService = useDependency(ICommandService);
|
|
777
|
+
const iconManager = useDependency(IconManager);
|
|
777
778
|
const localeService = useDependency(LocaleService);
|
|
778
779
|
const documentDataModel = (_univerInstanceServic = useDependency(IUniverInstanceService).getUnit(props.unitId, UniverInstanceType.UNIVER_DOC)) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : void 0;
|
|
779
780
|
const [wrappingStyle, setWrappingStyle] = useState(() => getWrappingStyle(documentDataModel, props.drawingId));
|
|
780
781
|
const [hidden, setHidden] = useState(false);
|
|
781
|
-
const
|
|
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");
|
|
782
|
+
const actionItems = props.menuItems.filter((item) => item.type !== "select" && item.icon).sort((a, b) => a.index - b.index);
|
|
785
783
|
const wrappingStyleOptions = [
|
|
786
784
|
{
|
|
787
785
|
label: localeService.t("drawing-ui.image-text-wrap.inline"),
|
|
@@ -811,6 +809,7 @@ function DocImageFloatingToolbar(props) {
|
|
|
811
809
|
];
|
|
812
810
|
const executeMenuItem = (item) => {
|
|
813
811
|
if (!item || item.disable) return;
|
|
812
|
+
if (item.hideOnClick) setHidden(true);
|
|
814
813
|
commandService.executeCommand(item.commandId, item.commandParams);
|
|
815
814
|
};
|
|
816
815
|
const updateWrappingStyle = (value) => {
|
|
@@ -834,45 +833,30 @@ function DocImageFloatingToolbar(props) {
|
|
|
834
833
|
event.preventDefault();
|
|
835
834
|
},
|
|
836
835
|
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
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
/* @__PURE__ */ jsx(
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
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
|
-
]
|
|
836
|
+
children: [/* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(ToolbarDropdownButton, {
|
|
837
|
+
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"),
|
|
838
|
+
value: wrappingStyle,
|
|
839
|
+
options: wrappingStyleOptions,
|
|
840
|
+
onChange: updateWrappingStyle
|
|
841
|
+
}) }), actionItems.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Separator, { orientation: "vertical" }), /* @__PURE__ */ jsx(ToolbarGroup, { children: actionItems.map((item) => {
|
|
842
|
+
const Icon = iconManager.get(item.icon);
|
|
843
|
+
return /* @__PURE__ */ jsx(ToolbarButton, {
|
|
844
|
+
titleKey: item.label,
|
|
845
|
+
disabled: item.disable,
|
|
846
|
+
onClick: () => executeMenuItem(item),
|
|
847
|
+
children: /* @__PURE__ */ jsx(Icon, {})
|
|
848
|
+
}, `${item.commandId}-${item.index}`);
|
|
849
|
+
}) })] })]
|
|
867
850
|
});
|
|
868
851
|
}
|
|
869
852
|
function DocChartFloatingToolbar(props) {
|
|
870
853
|
var _chartTypeItem$option, _ref, _chartTypeItem$value, _chartTypeOptions$;
|
|
871
854
|
const commandService = useDependency(ICommandService);
|
|
855
|
+
const iconManager = useDependency(IconManager);
|
|
872
856
|
const localeService = useDependency(LocaleService);
|
|
857
|
+
const [hidden, setHidden] = useState(false);
|
|
873
858
|
const chartTypeItem = props.menuItems.find((item) => item.type === "select");
|
|
874
|
-
const
|
|
875
|
-
const deleteItem = props.menuItems.find((item) => item.icon === "delete");
|
|
859
|
+
const actionItems = props.menuItems.filter((item) => item.type !== "select" && item.icon).sort((a, b) => a.index - b.index);
|
|
876
860
|
const chartTypeOptions = ((_chartTypeItem$option = chartTypeItem === null || chartTypeItem === void 0 ? void 0 : chartTypeItem.options) !== null && _chartTypeItem$option !== void 0 ? _chartTypeItem$option : []).map((option) => ({
|
|
877
861
|
label: String(option.label),
|
|
878
862
|
value: option.value,
|
|
@@ -880,8 +864,10 @@ function DocChartFloatingToolbar(props) {
|
|
|
880
864
|
}));
|
|
881
865
|
const executeMenuItem = (item) => {
|
|
882
866
|
if (!item || item.disable) return;
|
|
867
|
+
if (item.hideOnClick) setHidden(true);
|
|
883
868
|
commandService.executeCommand(item.commandId, item.commandParams);
|
|
884
869
|
};
|
|
870
|
+
if (hidden) return null;
|
|
885
871
|
return /* @__PURE__ */ jsxs("div", {
|
|
886
872
|
"data-u-comp": "doc-chart-floating-toolbar",
|
|
887
873
|
onMouseDown: (event) => {
|
|
@@ -899,17 +885,15 @@ function DocChartFloatingToolbar(props) {
|
|
|
899
885
|
commandService.executeCommand(chartTypeItem.commandId, (_chartTypeItem$comman = chartTypeItem.commandParamsFactory) === null || _chartTypeItem$comman === void 0 ? void 0 : _chartTypeItem$comman.call(chartTypeItem, value));
|
|
900
886
|
}
|
|
901
887
|
}
|
|
902
|
-
}) }),
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
children: /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
912
|
-
})] })]
|
|
888
|
+
}) }), actionItems.length > 0 && /* @__PURE__ */ jsx(Separator, { orientation: "vertical" })] }), actionItems.length > 0 && /* @__PURE__ */ jsx(ToolbarGroup, { children: actionItems.map((item) => {
|
|
889
|
+
const Icon = iconManager.get(item.icon);
|
|
890
|
+
return /* @__PURE__ */ jsx(ToolbarButton, {
|
|
891
|
+
titleKey: item.label,
|
|
892
|
+
disabled: item.disable,
|
|
893
|
+
onClick: () => executeMenuItem(item),
|
|
894
|
+
children: /* @__PURE__ */ jsx(Icon, {})
|
|
895
|
+
}, `${item.commandId}-${item.index}`);
|
|
896
|
+
}) })]
|
|
913
897
|
});
|
|
914
898
|
}
|
|
915
899
|
|
|
@@ -963,6 +947,9 @@ let ComponentsController = class ComponentsController extends Disposable {
|
|
|
963
947
|
_registerIcons() {
|
|
964
948
|
this.disposeWithMe(this._iconManager.register({
|
|
965
949
|
BottomIcon,
|
|
950
|
+
DrawingCropIcon: CropIcon,
|
|
951
|
+
DrawingDeleteIcon: DeleteIcon,
|
|
952
|
+
DrawingEditIcon: DocSettingIcon,
|
|
966
953
|
GroupIcon,
|
|
967
954
|
MoveDownIcon,
|
|
968
955
|
MoveUpIcon,
|
|
@@ -1293,12 +1280,24 @@ function getUpdateParams(objects, drawingManagerService) {
|
|
|
1293
1280
|
//#endregion
|
|
1294
1281
|
//#region src/controllers/drawing-update.controller.ts
|
|
1295
1282
|
function hasRefreshMetadata(refreshParam) {
|
|
1296
|
-
return "hidden" in refreshParam || "behindText" in refreshParam;
|
|
1283
|
+
return "hidden" in refreshParam || "behindText" in refreshParam || "selectable" in refreshParam;
|
|
1297
1284
|
}
|
|
1298
1285
|
function syncDrawingHiddenState(shape, drawingParam) {
|
|
1299
1286
|
if (!("hidden" in drawingParam)) return;
|
|
1300
1287
|
drawingParam.hidden === true ? shape.hide() : shape.show();
|
|
1301
1288
|
}
|
|
1289
|
+
function syncDrawingSelectableState(shape, drawingParam, scene, drawingManagerService) {
|
|
1290
|
+
var _scene$getTransformer;
|
|
1291
|
+
const previousDrawing = drawingManagerService.getOldDrawingByParam(drawingParam);
|
|
1292
|
+
if (!("selectable" in drawingParam) && (!previousDrawing || !("selectable" in previousDrawing))) return;
|
|
1293
|
+
const selectable = drawingParam.selectable !== false;
|
|
1294
|
+
shape.evented = selectable;
|
|
1295
|
+
if (selectable) return;
|
|
1296
|
+
(_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.clearControlByIds([shape.oKey]);
|
|
1297
|
+
const focusedDrawings = drawingManagerService.getFocusDrawings();
|
|
1298
|
+
const remainingDrawings = focusedDrawings.filter(({ unitId, subUnitId, drawingId }) => unitId !== drawingParam.unitId || subUnitId !== drawingParam.subUnitId || drawingId !== drawingParam.drawingId);
|
|
1299
|
+
if (remainingDrawings.length !== focusedDrawings.length) drawingManagerService.focusDrawing(remainingDrawings);
|
|
1300
|
+
}
|
|
1302
1301
|
function mergeRefreshMetadata(drawingParam, refreshParam) {
|
|
1303
1302
|
if (!hasRefreshMetadata(refreshParam)) return drawingParam;
|
|
1304
1303
|
return {
|
|
@@ -1628,8 +1627,8 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
|
1628
1627
|
subUnitId,
|
|
1629
1628
|
drawingId
|
|
1630
1629
|
})) {
|
|
1631
|
-
var _scene$
|
|
1632
|
-
(_scene$
|
|
1630
|
+
var _scene$getTransformer2;
|
|
1631
|
+
(_scene$getTransformer2 = scene.getTransformer()) === null || _scene$getTransformer2 === void 0 || _scene$getTransformer2.clearSelectedObjects();
|
|
1633
1632
|
}
|
|
1634
1633
|
});
|
|
1635
1634
|
}));
|
|
@@ -1637,7 +1636,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
|
1637
1636
|
_drawingUpdateListener() {
|
|
1638
1637
|
this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
|
|
1639
1638
|
params.forEach((param) => {
|
|
1640
|
-
var _setClipBounds, _scene$
|
|
1639
|
+
var _setClipBounds, _scene$getTransformer3;
|
|
1641
1640
|
const { unitId, subUnitId, drawingId } = param;
|
|
1642
1641
|
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
1643
1642
|
if (drawingParam == null) return;
|
|
@@ -1652,7 +1651,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
|
1652
1651
|
subUnitId,
|
|
1653
1652
|
drawingId
|
|
1654
1653
|
});
|
|
1655
|
-
const drawingShape = scene.
|
|
1654
|
+
const drawingShape = scene.getObjectIncludeInGroup(drawingShapeKey);
|
|
1656
1655
|
if (drawingShape == null) return true;
|
|
1657
1656
|
drawingShape.transformByState({
|
|
1658
1657
|
left,
|
|
@@ -1667,8 +1666,9 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
|
1667
1666
|
});
|
|
1668
1667
|
(_setClipBounds = drawingShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(drawingShape, transform.clipBounds);
|
|
1669
1668
|
syncDrawingHiddenState(drawingShape, drawingParam);
|
|
1669
|
+
syncDrawingSelectableState(drawingShape, drawingParam, scene, this._drawingManagerService);
|
|
1670
1670
|
ensureDrawingRenderLayer(scene, drawingShape, drawingParam);
|
|
1671
|
-
(_scene$
|
|
1671
|
+
(_scene$getTransformer3 = scene.getTransformer()) === null || _scene$getTransformer3 === void 0 || _scene$getTransformer3.debounceRefreshControls();
|
|
1672
1672
|
});
|
|
1673
1673
|
}));
|
|
1674
1674
|
}
|
|
@@ -1714,6 +1714,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
|
1714
1714
|
});
|
|
1715
1715
|
(_setClipBounds2 = drawingShape.setClipBounds) === null || _setClipBounds2 === void 0 || _setClipBounds2.call(drawingShape, transform.clipBounds);
|
|
1716
1716
|
syncDrawingHiddenState(drawingShape, drawingParamWithRefreshMetadata);
|
|
1717
|
+
syncDrawingSelectableState(drawingShape, drawingParamWithRefreshMetadata, scene, this._drawingManagerService);
|
|
1717
1718
|
ensureDrawingRenderLayer(scene, drawingShape, drawingParamWithRefreshMetadata);
|
|
1718
1719
|
});
|
|
1719
1720
|
}));
|
|
@@ -1730,7 +1731,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
|
|
|
1730
1731
|
subUnitId,
|
|
1731
1732
|
drawingId
|
|
1732
1733
|
});
|
|
1733
|
-
const drawingShape = scene.
|
|
1734
|
+
const drawingShape = scene.getObjectIncludeInGroup(drawingShapeKey);
|
|
1734
1735
|
if (drawingShape == null) return true;
|
|
1735
1736
|
if (visible) drawingShape.show();
|
|
1736
1737
|
else drawingShape.hide();
|
|
@@ -2362,7 +2363,8 @@ let ImageUpdateController = class ImageUpdateController extends Disposable {
|
|
|
2362
2363
|
const imageParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2363
2364
|
if (imageParam == null) return;
|
|
2364
2365
|
const images = await this._drawingRenderService.renderImages(imageParam, renderObject.scene);
|
|
2365
|
-
this._drawingManagerService.
|
|
2366
|
+
const currentImageParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2367
|
+
if (currentImageParam) this._drawingManagerService.refreshTransform([currentImageParam]);
|
|
2366
2368
|
if (images == null || images.length === 0) return;
|
|
2367
2369
|
for (const image of images) {
|
|
2368
2370
|
this._addHoverForImage(image);
|
|
@@ -3083,15 +3085,7 @@ const DrawingArrange = (props) => {
|
|
|
3083
3085
|
const MoveDownIcon = iconManager.get("MoveDownIcon");
|
|
3084
3086
|
const TopmostIcon = iconManager.get("TopmostIcon");
|
|
3085
3087
|
const BottomIcon = iconManager.get("BottomIcon");
|
|
3086
|
-
const
|
|
3087
|
-
useEffect(() => {
|
|
3088
|
-
const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
|
|
3089
|
-
setDrawings(drawings);
|
|
3090
|
-
});
|
|
3091
|
-
return () => {
|
|
3092
|
-
focusDispose.unsubscribe();
|
|
3093
|
-
};
|
|
3094
|
-
}, []);
|
|
3088
|
+
const drawings = useObservable(() => drawingManagerService.focus$, focusDrawings, false, [drawingManagerService]);
|
|
3095
3089
|
const onArrangeBtnClick = (arrangeType) => {
|
|
3096
3090
|
commandService.syncExecuteCommand(SetDrawingArrangeOperation.id, {
|
|
3097
3091
|
arrangeType,
|
|
@@ -3138,6 +3132,7 @@ const DrawingArrange = (props) => {
|
|
|
3138
3132
|
//#endregion
|
|
3139
3133
|
//#region src/views/panel/DrawingGroup.tsx
|
|
3140
3134
|
const DrawingGroup = (props) => {
|
|
3135
|
+
var _renderManagerService;
|
|
3141
3136
|
const localeService = useDependency(LocaleService);
|
|
3142
3137
|
const renderManagerService = useDependency(IRenderManagerService);
|
|
3143
3138
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
@@ -3146,43 +3141,32 @@ const DrawingGroup = (props) => {
|
|
|
3146
3141
|
const { hasGroup, drawings } = props;
|
|
3147
3142
|
const GroupIcon = iconManager.get("GroupIcon");
|
|
3148
3143
|
const UngroupIcon = iconManager.get("UngroupIcon");
|
|
3149
|
-
const
|
|
3150
|
-
const
|
|
3151
|
-
const
|
|
3144
|
+
const drawingParam = drawings[0];
|
|
3145
|
+
const transformer = drawingParam ? (_renderManagerService = renderManagerService.getRenderById(drawingParam.unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.getTransformerByCreate() : void 0;
|
|
3146
|
+
const { groupShow, groupBtnShow, ungroupBtnShow } = useObservable(transformer ? () => merge$1(transformer.clearControl$.pipe(filter((changeSelf) => changeSelf === true), map(() => ({
|
|
3147
|
+
groupShow: false,
|
|
3148
|
+
groupBtnShow: false,
|
|
3149
|
+
ungroupBtnShow: false
|
|
3150
|
+
}))), transformer.changeStart$.pipe(map((state) => {
|
|
3151
|
+
const params = getUpdateParams(state.objects, drawingManagerService);
|
|
3152
|
+
const groupBtnShow = params.length > 1;
|
|
3153
|
+
const ungroupBtnShow = params.some((item) => (item === null || item === void 0 ? void 0 : item.drawingType) === DrawingTypeEnum.DRAWING_GROUP);
|
|
3154
|
+
return {
|
|
3155
|
+
groupShow: groupBtnShow || ungroupBtnShow,
|
|
3156
|
+
groupBtnShow,
|
|
3157
|
+
ungroupBtnShow
|
|
3158
|
+
};
|
|
3159
|
+
}))) : null, {
|
|
3160
|
+
groupShow: false,
|
|
3161
|
+
groupBtnShow: true,
|
|
3162
|
+
ungroupBtnShow: true
|
|
3163
|
+
}, false, [drawingManagerService, transformer]);
|
|
3152
3164
|
const onGroupBtnClick = () => {
|
|
3153
3165
|
commandService.syncExecuteCommand(SetDrawingGroupOperation.id, { drawings });
|
|
3154
3166
|
};
|
|
3155
3167
|
const onUngroupBtnClick = () => {
|
|
3156
3168
|
commandService.syncExecuteCommand(CancelDrawingGroupOperation.id, { drawings });
|
|
3157
3169
|
};
|
|
3158
|
-
useEffect(() => {
|
|
3159
|
-
const drawingParam = drawings[0];
|
|
3160
|
-
if (drawingParam == null) return;
|
|
3161
|
-
const { unitId } = drawingParam;
|
|
3162
|
-
const renderObject = renderManagerService.getRenderById(unitId);
|
|
3163
|
-
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
3164
|
-
if (scene == null) return;
|
|
3165
|
-
const transformer = scene.getTransformerByCreate();
|
|
3166
|
-
const onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
|
|
3167
|
-
if (changeSelf === true) setGroupShow(false);
|
|
3168
|
-
});
|
|
3169
|
-
const onChangeStartObserver = transformer.changeStart$.subscribe((state) => {
|
|
3170
|
-
const { objects } = state;
|
|
3171
|
-
const params = getUpdateParams(objects, drawingManagerService);
|
|
3172
|
-
const groupParams = params.filter((o) => (o === null || o === void 0 ? void 0 : o.drawingType) === DrawingTypeEnum.DRAWING_GROUP);
|
|
3173
|
-
let groupBtnShow = false;
|
|
3174
|
-
let ungroupBtnShow = false;
|
|
3175
|
-
if (params.length > 1) groupBtnShow = true;
|
|
3176
|
-
if (groupParams.length > 0) ungroupBtnShow = true;
|
|
3177
|
-
setGroupShow(groupBtnShow || ungroupBtnShow);
|
|
3178
|
-
setGroupBtnShow(groupBtnShow);
|
|
3179
|
-
setUngroupBtnShow(ungroupBtnShow);
|
|
3180
|
-
});
|
|
3181
|
-
return () => {
|
|
3182
|
-
onChangeStartObserver.unsubscribe();
|
|
3183
|
-
onClearControlObserver.unsubscribe();
|
|
3184
|
-
};
|
|
3185
|
-
}, []);
|
|
3186
3170
|
return /* @__PURE__ */ jsxs("div", {
|
|
3187
3171
|
className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": hasGroup === true && groupShow === false || hasGroup === false }),
|
|
3188
3172
|
children: [/* @__PURE__ */ jsx("header", {
|
|
@@ -3234,21 +3218,24 @@ function createDrawingTransformRotationChangeHandler(options) {
|
|
|
3234
3218
|
//#region src/views/panel/DrawingTransform.tsx
|
|
3235
3219
|
const INPUT_DEBOUNCE_TIME = 300;
|
|
3236
3220
|
const DrawingTransform = (props) => {
|
|
3237
|
-
var _scene$getEngine;
|
|
3221
|
+
var _renderManagerService, _scene$getEngine;
|
|
3222
|
+
const renderManagerService = useDependency(IRenderManagerService);
|
|
3223
|
+
const drawingParam = props.drawings[0];
|
|
3224
|
+
const scene = drawingParam ? (_renderManagerService = renderManagerService.getRenderById(drawingParam.unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.scene : void 0;
|
|
3225
|
+
const topScene = scene === null || scene === void 0 || (_scene$getEngine = scene.getEngine()) === null || _scene$getEngine === void 0 ? void 0 : _scene$getEngine.activeScene;
|
|
3226
|
+
if (!(drawingParam === null || drawingParam === void 0 ? void 0 : drawingParam.transform) || !scene || !topScene) return null;
|
|
3227
|
+
return /* @__PURE__ */ jsx(DrawingTransformContent, { ...props });
|
|
3228
|
+
};
|
|
3229
|
+
function DrawingTransformContent(props) {
|
|
3238
3230
|
const localeService = useDependency(LocaleService);
|
|
3239
3231
|
const drawingManagerService = useDependency(IDrawingManagerService);
|
|
3240
3232
|
const renderManagerService = useDependency(IRenderManagerService);
|
|
3241
3233
|
const { drawings, transformShow } = props;
|
|
3242
3234
|
const drawingParam = drawings[0];
|
|
3243
|
-
if (drawingParam == null) return;
|
|
3244
3235
|
const transform = drawingParam.transform;
|
|
3245
|
-
if (transform == null) return;
|
|
3246
3236
|
const { unitId, subUnitId, drawingId, drawingType } = drawingParam;
|
|
3247
|
-
const
|
|
3248
|
-
const
|
|
3249
|
-
if (scene == null) return;
|
|
3250
|
-
const topScene = (_scene$getEngine = scene.getEngine()) === null || _scene$getEngine === void 0 ? void 0 : _scene$getEngine.activeScene;
|
|
3251
|
-
if (topScene == null) return;
|
|
3237
|
+
const scene = renderManagerService.getRenderById(unitId).scene;
|
|
3238
|
+
const topScene = scene.getEngine().activeScene;
|
|
3252
3239
|
const transformer = scene.getTransformerByCreate();
|
|
3253
3240
|
const { width: originWidth = 0, height: originHeight = 0, left: originX = 0, top: originY = 0, angle: originRotation = 0 } = transform;
|
|
3254
3241
|
const [width, setWidth] = useState(originWidth);
|
|
@@ -3479,7 +3466,7 @@ const DrawingTransform = (props) => {
|
|
|
3479
3466
|
})
|
|
3480
3467
|
]
|
|
3481
3468
|
});
|
|
3482
|
-
}
|
|
3469
|
+
}
|
|
3483
3470
|
|
|
3484
3471
|
//#endregion
|
|
3485
3472
|
//#region src/views/panel/ImageCropper.tsx
|
|
@@ -3490,7 +3477,7 @@ const ImageCropper = (props) => {
|
|
|
3490
3477
|
const componentManager = useDependency(ComponentManager);
|
|
3491
3478
|
const canUseShapeClip = useObservable(clipService.canUseShapeClip$, false);
|
|
3492
3479
|
const { drawings, cropperShow } = props;
|
|
3493
|
-
|
|
3480
|
+
const drawingParam = drawings[0];
|
|
3494
3481
|
const [cropValue, setCropValue] = useState("0");
|
|
3495
3482
|
const cropStateRef = useRef(false);
|
|
3496
3483
|
const cropOptions = [
|
|
@@ -3546,6 +3533,7 @@ const ImageCropper = (props) => {
|
|
|
3546
3533
|
onChangeStartObserver === null || onChangeStartObserver === void 0 || onChangeStartObserver.dispose();
|
|
3547
3534
|
};
|
|
3548
3535
|
}, []);
|
|
3536
|
+
if (drawingParam == null) return null;
|
|
3549
3537
|
function handleCropChange(value) {
|
|
3550
3538
|
setCropValue(value);
|
|
3551
3539
|
if (cropStateRef.current) commandService.executeCommand(AutoImageCropOperation.id, { cropType: value });
|
|
@@ -3613,78 +3601,11 @@ const DrawingCommonPanel = (props) => {
|
|
|
3613
3601
|
const localeService = useDependency(LocaleService);
|
|
3614
3602
|
const { drawings, hasArrange = true, hasTransform = true, hasAlign = true, hasCropper = true, hasGroup = true } = props;
|
|
3615
3603
|
const drawingParam = drawings[0];
|
|
3616
|
-
|
|
3617
|
-
const { unitId } = drawingParam;
|
|
3618
|
-
const renderObject = renderManagerService.getRenderById(unitId);
|
|
3604
|
+
const renderObject = drawingParam ? renderManagerService.getRenderById(drawingParam.unitId) : void 0;
|
|
3619
3605
|
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
3620
|
-
|
|
3621
|
-
const
|
|
3622
|
-
|
|
3623
|
-
const [arrangeShow, setArrangeShow] = useState(initialShowState.arrangeShow);
|
|
3624
|
-
const [transformShow, setTransformShow] = useState(initialShowState.transformShow);
|
|
3625
|
-
const [alignShow, setAlignShow] = useState(initialShowState.alignShow);
|
|
3626
|
-
const [cropperShow, setCropperShow] = useState(initialShowState.cropperShow);
|
|
3627
|
-
const [nullShow, setNullShow] = useState(initialShowState.nullShow);
|
|
3628
|
-
useEffect(() => {
|
|
3629
|
-
const clearControlSub = transformer.clearControl$.subscribe((changeSelf) => {
|
|
3630
|
-
if (changeSelf === true) {
|
|
3631
|
-
setArrangeShow(false);
|
|
3632
|
-
setTransformShow(false);
|
|
3633
|
-
setAlignShow(false);
|
|
3634
|
-
setCropperShow(false);
|
|
3635
|
-
setNullShow(true);
|
|
3636
|
-
}
|
|
3637
|
-
});
|
|
3638
|
-
const changeStartSub = transformer.changeStart$.subscribe((state) => {
|
|
3639
|
-
const { objects } = state;
|
|
3640
|
-
const params = getUpdateParams(objects, drawingManagerService);
|
|
3641
|
-
if (params.length === 0) {
|
|
3642
|
-
setArrangeShow(false);
|
|
3643
|
-
setTransformShow(false);
|
|
3644
|
-
setAlignShow(false);
|
|
3645
|
-
setCropperShow(false);
|
|
3646
|
-
setNullShow(true);
|
|
3647
|
-
} else if (params.length === 1) {
|
|
3648
|
-
setArrangeShow(true);
|
|
3649
|
-
setTransformShow(true);
|
|
3650
|
-
setAlignShow(false);
|
|
3651
|
-
setCropperShow(true);
|
|
3652
|
-
setNullShow(false);
|
|
3653
|
-
} else {
|
|
3654
|
-
setArrangeShow(true);
|
|
3655
|
-
setTransformShow(false);
|
|
3656
|
-
setAlignShow(true);
|
|
3657
|
-
setCropperShow(false);
|
|
3658
|
-
setNullShow(false);
|
|
3659
|
-
}
|
|
3660
|
-
});
|
|
3661
|
-
const focusSub = drawingManagerService.focus$.subscribe((drawings) => {
|
|
3662
|
-
if (drawings.length === 0) {
|
|
3663
|
-
setArrangeShow(false);
|
|
3664
|
-
setTransformShow(false);
|
|
3665
|
-
setAlignShow(false);
|
|
3666
|
-
setCropperShow(false);
|
|
3667
|
-
setNullShow(true);
|
|
3668
|
-
} else if (drawings.length === 1) {
|
|
3669
|
-
setArrangeShow(true);
|
|
3670
|
-
setTransformShow(true);
|
|
3671
|
-
setAlignShow(false);
|
|
3672
|
-
setCropperShow(true);
|
|
3673
|
-
setNullShow(false);
|
|
3674
|
-
} else {
|
|
3675
|
-
setArrangeShow(true);
|
|
3676
|
-
setTransformShow(false);
|
|
3677
|
-
setAlignShow(true);
|
|
3678
|
-
setCropperShow(false);
|
|
3679
|
-
setNullShow(false);
|
|
3680
|
-
}
|
|
3681
|
-
});
|
|
3682
|
-
return () => {
|
|
3683
|
-
changeStartSub.unsubscribe();
|
|
3684
|
-
clearControlSub.unsubscribe();
|
|
3685
|
-
focusSub.unsubscribe();
|
|
3686
|
-
};
|
|
3687
|
-
}, []);
|
|
3606
|
+
const transformer = scene === null || scene === void 0 ? void 0 : scene.getTransformerByCreate();
|
|
3607
|
+
const { arrangeShow, transformShow, alignShow, cropperShow, nullShow } = useObservable(() => merge$1(drawingManagerService.focus$.pipe(map(getPanelShowState)), ...transformer ? [transformer.clearControl$.pipe(filter((changeSelf) => changeSelf === true), map(() => getPanelShowState([]))), transformer.changeStart$.pipe(map((state) => getPanelShowState(getUpdateParams(state.objects, drawingManagerService))))] : []), getPanelShowState(drawings), false, [drawingManagerService, transformer]);
|
|
3608
|
+
if (!drawingParam || !scene || !transformer) return null;
|
|
3688
3609
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3689
3610
|
/* @__PURE__ */ jsx("div", {
|
|
3690
3611
|
className: clsx("univer-h-full", { "univer-hidden": !nullShow }),
|