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