@univerjs/drawing-ui 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -4,9 +4,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
5
  import { getDrawingShapeKeyByDrawingSearch, DrawingTypeEnum, ImageSourceType, IDrawingManagerService, IImageIoService, ArrangeTypeEnum } from "@univerjs/drawing";
6
6
  import { Group, DRAWING_OBJECT_LAYER_INDEX, Image, IRenderManagerService, getGroupState, transformObjectOutOfGroup, RENDER_CLASS_TYPE, Shape, Rect, Canvas, precisionTo, CURSOR_TYPE, Vector2, degToRad } from "@univerjs/engine-render";
7
- import { UniverInstanceType, useDependency, LocaleService, debounce, CommandType, ICommandService, Tools, Inject, Disposable, checkIfMove, toDisposable, IUniverInstanceService, Injector, Plugin, IConfigService } from "@univerjs/core";
8
- import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
9
- import { Button, InputNumber, Checkbox, Select, Dropdown, MessageType } from "@univerjs/design";
7
+ import { UniverInstanceType, CommandType, useDependency, ICommandService, LocaleService, Tools, debounce, Inject, Disposable, checkIfMove, toDisposable, IUniverInstanceService, Injector, Plugin, IConfigService } from "@univerjs/core";
8
+ import React, { useState, forwardRef, useRef, createElement, useEffect } from "react";
9
+ import { Select, Button, InputNumber, Checkbox, Dropdown, MessageType } from "@univerjs/design";
10
10
  import { ComponentManager, IMessageService, IDialogService } from "@univerjs/ui";
11
11
  import { filter, switchMap } from "rxjs";
12
12
  function insertGroupObject(objectParam, object, scene, drawingManagerService) {
@@ -139,6 +139,100 @@ function getUpdateParams(objects, drawingManagerService) {
139
139
  }), params;
140
140
  }
141
141
  __name(getUpdateParams, "getUpdateParams");
142
+ function r(e) {
143
+ var t, f, n = "";
144
+ if (typeof e == "string" || typeof e == "number") n += e;
145
+ else if (typeof e == "object") if (Array.isArray(e)) {
146
+ var o = e.length;
147
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
148
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
149
+ return n;
150
+ }
151
+ __name(r, "r");
152
+ function clsx() {
153
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
154
+ return n;
155
+ }
156
+ __name(clsx, "clsx");
157
+ var AlignType = /* @__PURE__ */ ((AlignType2) => (AlignType2.default = "0", AlignType2.left = "1", AlignType2.center = "2", AlignType2.right = "3", AlignType2.top = "4", AlignType2.middle = "5", AlignType2.bottom = "6", AlignType2.horizon = "7", AlignType2.vertical = "8", AlignType2))(AlignType || {});
158
+ const SetDrawingAlignOperation = {
159
+ id: "sheet.operation.set-image-align",
160
+ type: CommandType.OPERATION,
161
+ handler: /* @__PURE__ */ __name((accessor, params) => !0, "handler")
162
+ }, imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "univer-image-common-panel-grid", imageCommonPanelBorder = "univer-image-common-panel-border", imageCommonPanelTitle = "univer-image-common-panel-title", imageCommonPanelSubtitle = "univer-image-common-panel-subtitle", imageCommonPanelRow = "univer-image-common-panel-row", imageCommonPanelRowVertical = "univer-image-common-panel-row-vertical", imageCommonPanelColumn = "univer-image-common-panel-column", imageCommonPanelColumnCenter = "univer-image-common-panel-column-center", imageCommonPanelInline = "univer-image-common-panel-inline", imageCommonPanelSpan2 = "univer-image-common-panel-span2", imageCommonPanelSpan3 = "univer-image-common-panel-span3", imageCommonPanelInput = "univer-image-common-panel-input", styles$1 = {
163
+ imageCommonPanel,
164
+ imageCommonPanelGrid,
165
+ imageCommonPanelBorder,
166
+ imageCommonPanelTitle,
167
+ imageCommonPanelSubtitle,
168
+ imageCommonPanelRow,
169
+ imageCommonPanelRowVertical,
170
+ imageCommonPanelColumn,
171
+ imageCommonPanelColumnCenter,
172
+ imageCommonPanelInline,
173
+ imageCommonPanelSpan2,
174
+ imageCommonPanelSpan3,
175
+ imageCommonPanelInput
176
+ }, DrawingAlign = /* @__PURE__ */ __name((props) => {
177
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), { alignShow } = props, [alignValue, setAlignValue] = useState(AlignType.default), alignOptions = [
178
+ {
179
+ label: localeService.t("image-panel.align.default"),
180
+ value: AlignType.default
181
+ },
182
+ {
183
+ options: [
184
+ {
185
+ label: localeService.t("image-panel.align.left"),
186
+ value: AlignType.left
187
+ },
188
+ {
189
+ label: localeService.t("image-panel.align.center"),
190
+ value: AlignType.center
191
+ },
192
+ {
193
+ label: localeService.t("image-panel.align.right"),
194
+ value: AlignType.right
195
+ }
196
+ ]
197
+ },
198
+ {
199
+ options: [
200
+ {
201
+ label: localeService.t("image-panel.align.top"),
202
+ value: AlignType.top
203
+ },
204
+ {
205
+ label: localeService.t("image-panel.align.middle"),
206
+ value: AlignType.middle
207
+ },
208
+ {
209
+ label: localeService.t("image-panel.align.bottom"),
210
+ value: AlignType.bottom
211
+ }
212
+ ]
213
+ },
214
+ {
215
+ options: [
216
+ {
217
+ label: localeService.t("image-panel.align.horizon"),
218
+ value: AlignType.horizon
219
+ },
220
+ {
221
+ label: localeService.t("image-panel.align.vertical"),
222
+ value: AlignType.vertical
223
+ }
224
+ ]
225
+ }
226
+ ];
227
+ function handleAlignChange(value) {
228
+ setAlignValue(value), commandService.executeCommand(SetDrawingAlignOperation.id, {
229
+ alignType: value
230
+ });
231
+ }
232
+ __name(handleAlignChange, "handleAlignChange");
233
+ const gridDisplay = /* @__PURE__ */ __name((isShow) => isShow ? "block" : "none", "gridDisplay");
234
+ return /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelGrid, styles$1.imageCommonPanelBorder), style: { display: gridDisplay(alignShow) } }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-panel.align.title")))), /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn) }, /* @__PURE__ */ React.createElement(Select, { value: alignValue, options: alignOptions, onChange: handleAlignChange }))));
235
+ }, "DrawingAlign");
142
236
  var __assign = function() {
143
237
  return __assign = Object.assign || function(t) {
144
238
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -258,36 +352,7 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width:
258
352
  }));
259
353
  });
260
354
  UngroupSingle.displayName = "UngroupSingle";
261
- function r(e) {
262
- var t, f, n = "";
263
- if (typeof e == "string" || typeof e == "number") n += e;
264
- else if (typeof e == "object") if (Array.isArray(e)) {
265
- var o = e.length;
266
- for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
267
- } else for (f in e) e[f] && (n && (n += " "), n += f);
268
- return n;
269
- }
270
- __name(r, "r");
271
- function clsx() {
272
- for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
273
- return n;
274
- }
275
- __name(clsx, "clsx");
276
- const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "univer-image-common-panel-grid", imageCommonPanelBorder = "univer-image-common-panel-border", imageCommonPanelTitle = "univer-image-common-panel-title", imageCommonPanelSubtitle = "univer-image-common-panel-subtitle", imageCommonPanelRow = "univer-image-common-panel-row", imageCommonPanelRowVertical = "univer-image-common-panel-row-vertical", imageCommonPanelColumn = "univer-image-common-panel-column", imageCommonPanelColumnCenter = "univer-image-common-panel-column-center", imageCommonPanelInline = "univer-image-common-panel-inline", imageCommonPanelSpan2 = "univer-image-common-panel-span2", imageCommonPanelSpan3 = "univer-image-common-panel-span3", imageCommonPanelInput = "univer-image-common-panel-input", styles$1 = {
277
- imageCommonPanel,
278
- imageCommonPanelGrid,
279
- imageCommonPanelBorder,
280
- imageCommonPanelTitle,
281
- imageCommonPanelSubtitle,
282
- imageCommonPanelRow,
283
- imageCommonPanelRowVertical,
284
- imageCommonPanelColumn,
285
- imageCommonPanelColumnCenter,
286
- imageCommonPanelInline,
287
- imageCommonPanelSpan2,
288
- imageCommonPanelSpan3,
289
- imageCommonPanelInput
290
- }, DrawingArrange = /* @__PURE__ */ __name((props) => {
355
+ const DrawingArrange = /* @__PURE__ */ __name((props) => {
291
356
  const { arrangeShow, drawings: focusDrawings } = props, localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), gridDisplay = /* @__PURE__ */ __name((isShow) => isShow ? "block" : "none", "gridDisplay"), [drawings, setDrawings] = useState(focusDrawings);
292
357
  useEffect(() => {
293
358
  const focusDispose = drawingManagerService.focus$.subscribe((drawings2) => {
@@ -310,7 +375,87 @@ const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "un
310
375
  }, "onClick") }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(TopmostSingle, null), localeService.t("image-panel.arrange.front")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement(Button, { size: "small", onClick: /* @__PURE__ */ __name(() => {
311
376
  onArrangeBtnClick(ArrangeTypeEnum.back);
312
377
  }, "onClick") }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(BottomSingle, null), localeService.t("image-panel.arrange.back"))))));
313
- }, "DrawingArrange"), MIN_DRAWING_WIDTH_LIMIT = 20, MIN_DRAWING_HEIGHT_LIMIT = 20, RANGE_DRAWING_ROTATION_LIMIT = [-3600, 3600], INPUT_DEBOUNCE_TIME = 300, DrawingTransform = /* @__PURE__ */ __name((props) => {
378
+ }, "DrawingArrange"), DrawingGroup = /* @__PURE__ */ __name((props) => {
379
+ const localeService = useDependency(LocaleService), renderManagerService = useDependency(IRenderManagerService), drawingManagerService = useDependency(IDrawingManagerService), { hasGroup, drawings } = props, [groupShow, setGroupShow] = useState(!1), [groupBtnShow, setGroupBtnShow] = useState(!0), [ungroupBtnShow, setUngroupBtnShow] = useState(!0), gridDisplay = /* @__PURE__ */ __name((isShow) => isShow ? "block" : "none", "gridDisplay"), onGroupBtnClick = /* @__PURE__ */ __name(() => {
380
+ const focusDrawings = drawingManagerService.getFocusDrawings(), { unitId, subUnitId } = focusDrawings[0], groupId = Tools.generateRandomId(10), groupTransform = getGroupState(0, 0, focusDrawings.map((o) => o.transform || {})), groupParam = {
381
+ unitId,
382
+ subUnitId,
383
+ drawingId: groupId,
384
+ drawingType: DrawingTypeEnum.DRAWING_GROUP,
385
+ transform: groupTransform
386
+ }, children = focusDrawings.map((drawing) => {
387
+ const transform = drawing.transform || { left: 0, top: 0 }, { unitId: unitId2, subUnitId: subUnitId2, drawingId } = drawing;
388
+ return {
389
+ unitId: unitId2,
390
+ subUnitId: subUnitId2,
391
+ drawingId,
392
+ transform: {
393
+ ...transform,
394
+ left: transform.left - groupTransform.left,
395
+ top: transform.top - groupTransform.top
396
+ },
397
+ groupId
398
+ };
399
+ });
400
+ drawingManagerService.featurePluginGroupUpdateNotification([{
401
+ parent: groupParam,
402
+ children
403
+ }]);
404
+ }, "onGroupBtnClick"), ungroup = /* @__PURE__ */ __name((param) => {
405
+ if (param.drawingType !== DrawingTypeEnum.DRAWING_GROUP)
406
+ return;
407
+ const { unitId, subUnitId, drawingId, transform: groupTransform = { width: 0, height: 0 } } = param;
408
+ if (groupTransform == null)
409
+ return;
410
+ const objects = drawingManagerService.getDrawingsByGroup({ unitId, subUnitId, drawingId });
411
+ if (objects.length === 0)
412
+ return;
413
+ const children = objects.map((object) => {
414
+ const { transform } = object, { unitId: unitId2, subUnitId: subUnitId2, drawingId: drawingId2 } = object, newTransform = transformObjectOutOfGroup(transform || {}, groupTransform, groupTransform.width || 0, groupTransform.height || 0);
415
+ return {
416
+ unitId: unitId2,
417
+ subUnitId: subUnitId2,
418
+ drawingId: drawingId2,
419
+ transform: {
420
+ ...transform,
421
+ ...newTransform
422
+ },
423
+ groupId: void 0
424
+ };
425
+ });
426
+ return {
427
+ parent: param,
428
+ children
429
+ };
430
+ }, "ungroup"), onUngroupBtnClick = /* @__PURE__ */ __name(() => {
431
+ const params = drawingManagerService.getFocusDrawings().map(
432
+ (drawing) => ungroup(drawing)
433
+ ).filter((o) => o != null);
434
+ params.length !== 0 && drawingManagerService.featurePluginUngroupUpdateNotification(params);
435
+ }, "onUngroupBtnClick");
436
+ return useEffect(() => {
437
+ const drawingParam = drawings[0];
438
+ if (drawingParam == null)
439
+ return;
440
+ const { unitId } = drawingParam, renderObject = renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
441
+ if (scene == null)
442
+ return;
443
+ const transformer = scene.getTransformerByCreate(), onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
444
+ changeSelf === !0 && setGroupShow(!1);
445
+ }), onChangeStartObserver = transformer.changeStart$.subscribe((state) => {
446
+ const { objects } = state, params = getUpdateParams(objects, drawingManagerService), groupParams = params.filter((o) => (o == null ? void 0 : o.drawingType) === DrawingTypeEnum.DRAWING_GROUP);
447
+ let groupBtnShow2 = !1, ungroupBtnShow2 = !1;
448
+ params.length > 1 && (groupBtnShow2 = !0), groupParams.length > 0 && (ungroupBtnShow2 = !0), setGroupShow(groupBtnShow2 || ungroupBtnShow2), setGroupBtnShow(groupBtnShow2), setUngroupBtnShow(ungroupBtnShow2);
449
+ });
450
+ return () => {
451
+ onChangeStartObserver.unsubscribe(), onClearControlObserver.unsubscribe();
452
+ };
453
+ }, []), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelGrid, styles$1.imageCommonPanelBorder), style: { display: gridDisplay(hasGroup === !0 ? groupShow : !1) } }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-panel.group.title")))), /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2, styles$1.imageCommonPanelColumnCenter) }, /* @__PURE__ */ React.createElement(Button, { size: "small", onClick: /* @__PURE__ */ __name(() => {
454
+ onGroupBtnClick();
455
+ }, "onClick"), style: { display: gridDisplay(groupBtnShow) } }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(GroupSingle, null), localeService.t("image-panel.group.group")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2, styles$1.imageCommonPanelColumnCenter) }, /* @__PURE__ */ React.createElement(Button, { size: "small", onClick: /* @__PURE__ */ __name(() => {
456
+ onUngroupBtnClick();
457
+ }, "onClick"), style: { display: gridDisplay(ungroupBtnShow) } }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(UngroupSingle, null), localeService.t("image-panel.group.unGroup"))))));
458
+ }, "DrawingGroup"), MIN_DRAWING_WIDTH_LIMIT = 20, MIN_DRAWING_HEIGHT_LIMIT = 20, RANGE_DRAWING_ROTATION_LIMIT = [-3600, 3600], INPUT_DEBOUNCE_TIME = 300, DrawingTransform = /* @__PURE__ */ __name((props) => {
314
459
  var _a7;
315
460
  const localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), { drawings, transformShow } = props, drawingParam = drawings[0];
316
461
  if (drawingParam == null)
@@ -453,72 +598,7 @@ const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "un
453
598
  }, "onChange"), className: styles$1.imageCommonPanelInput }))))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan3) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelColumn }, localeService.t("image-panel.transform.y"))), /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(InputNumber, { precision: 1, value: yPosition, onChange: /* @__PURE__ */ __name((val) => {
454
599
  handleYChange(val);
455
600
  }, "onChange"), className: styles$1.imageCommonPanelInput }))))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan3) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelColumn }, localeService.t("image-panel.transform.rotate"))), /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(InputNumber, { precision: 1, value: rotation, onChange: handleRotationChange, className: styles$1.imageCommonPanelInput })))))));
456
- }, "DrawingTransform");
457
- var AlignType = /* @__PURE__ */ ((AlignType2) => (AlignType2.default = "0", AlignType2.left = "1", AlignType2.center = "2", AlignType2.right = "3", AlignType2.top = "4", AlignType2.middle = "5", AlignType2.bottom = "6", AlignType2.horizon = "7", AlignType2.vertical = "8", AlignType2))(AlignType || {});
458
- const SetDrawingAlignOperation = {
459
- id: "sheet.operation.set-image-align",
460
- type: CommandType.OPERATION,
461
- handler: /* @__PURE__ */ __name((accessor, params) => !0, "handler")
462
- }, DrawingAlign = /* @__PURE__ */ __name((props) => {
463
- const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), { alignShow } = props, [alignValue, setAlignValue] = useState(AlignType.default), alignOptions = [
464
- {
465
- label: localeService.t("image-panel.align.default"),
466
- value: AlignType.default
467
- },
468
- {
469
- options: [
470
- {
471
- label: localeService.t("image-panel.align.left"),
472
- value: AlignType.left
473
- },
474
- {
475
- label: localeService.t("image-panel.align.center"),
476
- value: AlignType.center
477
- },
478
- {
479
- label: localeService.t("image-panel.align.right"),
480
- value: AlignType.right
481
- }
482
- ]
483
- },
484
- {
485
- options: [
486
- {
487
- label: localeService.t("image-panel.align.top"),
488
- value: AlignType.top
489
- },
490
- {
491
- label: localeService.t("image-panel.align.middle"),
492
- value: AlignType.middle
493
- },
494
- {
495
- label: localeService.t("image-panel.align.bottom"),
496
- value: AlignType.bottom
497
- }
498
- ]
499
- },
500
- {
501
- options: [
502
- {
503
- label: localeService.t("image-panel.align.horizon"),
504
- value: AlignType.horizon
505
- },
506
- {
507
- label: localeService.t("image-panel.align.vertical"),
508
- value: AlignType.vertical
509
- }
510
- ]
511
- }
512
- ];
513
- function handleAlignChange(value) {
514
- setAlignValue(value), commandService.executeCommand(SetDrawingAlignOperation.id, {
515
- alignType: value
516
- });
517
- }
518
- __name(handleAlignChange, "handleAlignChange");
519
- const gridDisplay = /* @__PURE__ */ __name((isShow) => isShow ? "block" : "none", "gridDisplay");
520
- return /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelGrid, styles$1.imageCommonPanelBorder), style: { display: gridDisplay(alignShow) } }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-panel.align.title")))), /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn) }, /* @__PURE__ */ React.createElement(Select, { value: alignValue, options: alignOptions, onChange: handleAlignChange }))));
521
- }, "DrawingAlign"), OpenImageCropOperation = {
601
+ }, "DrawingTransform"), OpenImageCropOperation = {
522
602
  id: "sheet.operation.open-image-crop",
523
603
  type: CommandType.OPERATION,
524
604
  handler: /* @__PURE__ */ __name((accessor, params) => !0, "handler")
@@ -603,87 +683,7 @@ const AutoImageCropOperation = {
603
683
  return /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelGrid, styles$1.imageCommonPanelBorder), style: { display: gridDisplay(cropperShow) } }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-panel.crop.title")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelRow, styles$1.imageCommonPanelRowVertical) }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement(Button, { size: "small", onClick: /* @__PURE__ */ __name(() => {
604
684
  onCropperBtnClick(cropValue);
605
685
  }, "onClick") }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(CreateCopySingle, null), localeService.t("image-panel.crop.start")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement(Select, { value: cropValue, options: cropOptions, onChange: handleCropChange }))));
606
- }, "ImageCropper"), DrawingGroup = /* @__PURE__ */ __name((props) => {
607
- const localeService = useDependency(LocaleService), renderManagerService = useDependency(IRenderManagerService), drawingManagerService = useDependency(IDrawingManagerService), { hasGroup, drawings } = props, [groupShow, setGroupShow] = useState(!1), [groupBtnShow, setGroupBtnShow] = useState(!0), [ungroupBtnShow, setUngroupBtnShow] = useState(!0), gridDisplay = /* @__PURE__ */ __name((isShow) => isShow ? "block" : "none", "gridDisplay"), onGroupBtnClick = /* @__PURE__ */ __name(() => {
608
- const focusDrawings = drawingManagerService.getFocusDrawings(), { unitId, subUnitId } = focusDrawings[0], groupId = Tools.generateRandomId(10), groupTransform = getGroupState(0, 0, focusDrawings.map((o) => o.transform || {})), groupParam = {
609
- unitId,
610
- subUnitId,
611
- drawingId: groupId,
612
- drawingType: DrawingTypeEnum.DRAWING_GROUP,
613
- transform: groupTransform
614
- }, children = focusDrawings.map((drawing) => {
615
- const transform = drawing.transform || { left: 0, top: 0 }, { unitId: unitId2, subUnitId: subUnitId2, drawingId } = drawing;
616
- return {
617
- unitId: unitId2,
618
- subUnitId: subUnitId2,
619
- drawingId,
620
- transform: {
621
- ...transform,
622
- left: transform.left - groupTransform.left,
623
- top: transform.top - groupTransform.top
624
- },
625
- groupId
626
- };
627
- });
628
- drawingManagerService.featurePluginGroupUpdateNotification([{
629
- parent: groupParam,
630
- children
631
- }]);
632
- }, "onGroupBtnClick"), ungroup = /* @__PURE__ */ __name((param) => {
633
- if (param.drawingType !== DrawingTypeEnum.DRAWING_GROUP)
634
- return;
635
- const { unitId, subUnitId, drawingId, transform: groupTransform = { width: 0, height: 0 } } = param;
636
- if (groupTransform == null)
637
- return;
638
- const objects = drawingManagerService.getDrawingsByGroup({ unitId, subUnitId, drawingId });
639
- if (objects.length === 0)
640
- return;
641
- const children = objects.map((object) => {
642
- const { transform } = object, { unitId: unitId2, subUnitId: subUnitId2, drawingId: drawingId2 } = object, newTransform = transformObjectOutOfGroup(transform || {}, groupTransform, groupTransform.width || 0, groupTransform.height || 0);
643
- return {
644
- unitId: unitId2,
645
- subUnitId: subUnitId2,
646
- drawingId: drawingId2,
647
- transform: {
648
- ...transform,
649
- ...newTransform
650
- },
651
- groupId: void 0
652
- };
653
- });
654
- return {
655
- parent: param,
656
- children
657
- };
658
- }, "ungroup"), onUngroupBtnClick = /* @__PURE__ */ __name(() => {
659
- const params = drawingManagerService.getFocusDrawings().map(
660
- (drawing) => ungroup(drawing)
661
- ).filter((o) => o != null);
662
- params.length !== 0 && drawingManagerService.featurePluginUngroupUpdateNotification(params);
663
- }, "onUngroupBtnClick");
664
- return useEffect(() => {
665
- const drawingParam = drawings[0];
666
- if (drawingParam == null)
667
- return;
668
- const { unitId } = drawingParam, renderObject = renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
669
- if (scene == null)
670
- return;
671
- const transformer = scene.getTransformerByCreate(), onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
672
- changeSelf === !0 && setGroupShow(!1);
673
- }), onChangeStartObserver = transformer.changeStart$.subscribe((state) => {
674
- const { objects } = state, params = getUpdateParams(objects, drawingManagerService), groupParams = params.filter((o) => (o == null ? void 0 : o.drawingType) === DrawingTypeEnum.DRAWING_GROUP);
675
- let groupBtnShow2 = !1, ungroupBtnShow2 = !1;
676
- params.length > 1 && (groupBtnShow2 = !0), groupParams.length > 0 && (ungroupBtnShow2 = !0), setGroupShow(groupBtnShow2 || ungroupBtnShow2), setGroupBtnShow(groupBtnShow2), setUngroupBtnShow(ungroupBtnShow2);
677
- });
678
- return () => {
679
- onChangeStartObserver.unsubscribe(), onClearControlObserver.unsubscribe();
680
- };
681
- }, []), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelGrid, styles$1.imageCommonPanelBorder), style: { display: gridDisplay(hasGroup === !0 ? groupShow : !1) } }, /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-panel.group.title")))), /* @__PURE__ */ React.createElement("div", { className: styles$1.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2, styles$1.imageCommonPanelColumnCenter) }, /* @__PURE__ */ React.createElement(Button, { size: "small", onClick: /* @__PURE__ */ __name(() => {
682
- onGroupBtnClick();
683
- }, "onClick"), style: { display: gridDisplay(groupBtnShow) } }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(GroupSingle, null), localeService.t("image-panel.group.group")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles$1.imageCommonPanelColumn, styles$1.imageCommonPanelSpan2, styles$1.imageCommonPanelColumnCenter) }, /* @__PURE__ */ React.createElement(Button, { size: "small", onClick: /* @__PURE__ */ __name(() => {
684
- onUngroupBtnClick();
685
- }, "onClick"), style: { display: gridDisplay(ungroupBtnShow) } }, /* @__PURE__ */ React.createElement("span", { className: styles$1.imageCommonPanelInline }, /* @__PURE__ */ React.createElement(UngroupSingle, null), localeService.t("image-panel.group.unGroup"))))));
686
- }, "DrawingGroup"), DrawingCommonPanel = /* @__PURE__ */ __name((props) => {
686
+ }, "ImageCropper"), DrawingCommonPanel = /* @__PURE__ */ __name((props) => {
687
687
  const drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), localeService = useDependency(LocaleService), { drawings, hasArrange = !0, hasTransform = !0, hasAlign = !0, hasCropper = !0, hasGroup = !0 } = props, drawingParam = drawings[0];
688
688
  if (drawingParam == null)
689
689
  return;
@@ -1,5 +1,5 @@
1
- import { default as React } from 'react';
2
1
  import { IDrawingParam } from '@univerjs/drawing';
2
+ import { default as React } from 'react';
3
3
  export interface IDrawingCommonPanelProps {
4
4
  drawings: IDrawingParam[];
5
5
  hasArrange?: boolean;