@univerjs/drawing-ui 0.25.0 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -4,10 +4,10 @@ let _univerjs_drawing = require("@univerjs/drawing");
4
4
  let _univerjs_engine_render = require("@univerjs/engine-render");
5
5
  let _univerjs_icons = require("@univerjs/icons");
6
6
  let _univerjs_ui = require("@univerjs/ui");
7
- let rxjs = require("rxjs");
8
7
  let _univerjs_design = require("@univerjs/design");
9
8
  let react = require("react");
10
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ let rxjs = require("rxjs");
11
11
 
12
12
  //#region src/commands/operations/drawing-align.operation.ts
13
13
  /**
@@ -322,7 +322,7 @@ function getCurrentUnitInfo(currentUniverService, propUnitId) {
322
322
  //#endregion
323
323
  //#region package.json
324
324
  var name = "@univerjs/drawing-ui";
325
- var version = "0.25.0";
325
+ var version = "1.0.0-alpha.0";
326
326
 
327
327
  //#endregion
328
328
  //#region src/config/config.ts
@@ -331,269 +331,258 @@ const configSymbol = Symbol(DRAWING_UI_PLUGIN_CONFIG_KEY);
331
331
  const defaultPluginConfig = {};
332
332
 
333
333
  //#endregion
334
- //#region src/menu/align.menu.ts
335
- const getMenuStateByDrawingFocusChangedObservable$$1 = (accessor) => {
336
- const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
337
- return new rxjs.Observable((subscriber) => {
338
- const update = (drawings) => {
339
- if (!drawings || drawings.length === 0) return subscriber.next(true);
340
- if (drawings.length < 2) return subscriber.next(true);
341
- subscriber.next(false);
342
- };
343
- const subscription = drawingManagerService.focus$.subscribe((drawings) => {
344
- if (!drawings || drawings.length === 0) return subscriber.next(true);
345
- update(drawings);
346
- });
347
- update(drawingManagerService.getFocusDrawings());
348
- return () => subscription.unsubscribe();
334
+ //#region src/views/image-popup-menu/component-name.ts
335
+ /**
336
+ * Copyright 2023-present DreamNum Co., Ltd.
337
+ *
338
+ * Licensed under the Apache License, Version 2.0 (the "License");
339
+ * you may not use this file except in compliance with the License.
340
+ * You may obtain a copy of the License at
341
+ *
342
+ * http://www.apache.org/licenses/LICENSE-2.0
343
+ *
344
+ * Unless required by applicable law or agreed to in writing, software
345
+ * distributed under the License is distributed on an "AS IS" BASIS,
346
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
347
+ * See the License for the specific language governing permissions and
348
+ * limitations under the License.
349
+ */
350
+ const COMPONENT_IMAGE_POPUP_MENU = "COMPONENT_IMAGE_POPUP_MENU";
351
+
352
+ //#endregion
353
+ //#region src/views/image-popup-menu/ImagePopupMenu.tsx
354
+ function ImagePopupMenu(props) {
355
+ var _popup$extraProps, _popup$extraProps2;
356
+ const { popup } = props;
357
+ const menuItems = popup === null || popup === void 0 || (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.menuItems;
358
+ if (!menuItems) return null;
359
+ 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, {
360
+ menuItems,
361
+ unitId: popup.extraProps.unitId,
362
+ subUnitId: popup.extraProps.subUnitId,
363
+ drawingId: popup.extraProps.drawingId
349
364
  });
350
- };
351
- const DRAWING_ALIGN_CONTEXT_MENU_ID = "contextMenu.drawing-align";
352
- function DrawingAlignContextMenuItemFactory(accessor) {
353
- return {
354
- id: DRAWING_ALIGN_CONTEXT_MENU_ID,
355
- type: _univerjs_ui.MenuItemType.SUBITEMS,
356
- icon: "HorizontallyIcon",
357
- title: "drawing-ui.image-panel.align.title",
358
- hidden$: getMenuStateByDrawingFocusChangedObservable$$1(accessor)
359
- };
360
- }
361
- function SetDrawingAlignLeftMenuItemFactory() {
362
- return {
363
- id: SetDrawingAlignLeftOperation.id,
364
- type: _univerjs_ui.MenuItemType.BUTTON,
365
- icon: "LeftJustifyingIcon",
366
- title: "drawing-ui.image-panel.align.left"
365
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
366
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
367
+ const [visible, setVisible] = (0, react.useState)(false);
368
+ const [isHovered, setHovered] = (0, react.useState)(false);
369
+ const handleMouseEnter = () => {
370
+ setHovered(true);
367
371
  };
368
- }
369
- function SetDrawingAlignCenterMenuItemFactory() {
370
- return {
371
- id: SetDrawingAlignCenterOperation.id,
372
- type: _univerjs_ui.MenuItemType.BUTTON,
373
- icon: "HorizontallyIcon",
374
- title: "drawing-ui.image-panel.align.center"
372
+ const handleMouseLeave = () => {
373
+ setHovered(false);
375
374
  };
376
- }
377
- function SetDrawingAlignRightMenuItemFactory() {
378
- return {
379
- id: SetDrawingAlignRightOperation.id,
380
- type: _univerjs_ui.MenuItemType.BUTTON,
381
- icon: "RightJustifyingIcon",
382
- title: "drawing-ui.image-panel.align.right"
375
+ const onVisibleChange = (visible) => {
376
+ setVisible(visible);
383
377
  };
384
- }
385
- function SetDrawingAlignTopMenuItemFactory() {
386
- return {
387
- id: SetDrawingAlignTopOperation.id,
388
- type: _univerjs_ui.MenuItemType.BUTTON,
389
- icon: "AlignTopIcon",
390
- title: "drawing-ui.image-panel.align.top"
378
+ const handleClick = (item) => {
379
+ commandService.executeCommand(item.commandId, item.commandParams);
380
+ setVisible(false);
391
381
  };
382
+ const showMore = visible || isHovered;
383
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
384
+ onMouseEnter: handleMouseEnter,
385
+ onMouseLeave: handleMouseLeave,
386
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
387
+ align: "start",
388
+ items: menuItems.map((item) => ({
389
+ type: "item",
390
+ children: localeService.t(item.label),
391
+ disabled: item.disable,
392
+ onSelect: () => handleClick(item)
393
+ })),
394
+ open: visible,
395
+ onOpenChange: onVisibleChange,
396
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
397
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", _univerjs_design.borderClassName, {
398
+ "univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
399
+ "univer-bg-white dark:!univer-bg-gray-900": !visible
400
+ }),
401
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
402
+ })
403
+ })
404
+ });
392
405
  }
393
- function SetDrawingAlignMiddleMenuItemFactory() {
394
- return {
395
- id: SetDrawingAlignMiddleOperation.id,
396
- type: _univerjs_ui.MenuItemType.BUTTON,
397
- icon: "VerticalCenterIcon",
398
- title: "drawing-ui.image-panel.align.middle"
399
- };
406
+ const UPDATE_DOC_DRAWING_WRAPPING_STYLE_COMMAND_ID = "doc.command.update-doc-drawing-wrapping-style";
407
+ function getWrappingStyle(documentDataModel, drawingId) {
408
+ var _documentDataModel$ge;
409
+ const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingId];
410
+ if (!drawing) return "inline";
411
+ if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) return drawing.behindDoc === _univerjs_core.BooleanNumber.TRUE ? "behindText" : "inFrontOfText";
412
+ if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE) return "wrapSquare";
413
+ if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) return "wrapTopAndBottom";
414
+ return "inline";
400
415
  }
401
- function SetDrawingAlignBottomMenuItemFactory() {
402
- return {
403
- id: SetDrawingAlignBottomOperation.id,
404
- type: _univerjs_ui.MenuItemType.BUTTON,
405
- icon: "AlignBottomIcon",
406
- title: "drawing-ui.image-panel.align.bottom"
407
- };
416
+ function ToolbarGroup(props) {
417
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
418
+ className: "univer-flex univer-h-7 univer-items-center univer-gap-1 univer-px-1",
419
+ children: props.children
420
+ });
408
421
  }
409
- function SetDrawingAlignHorizonMenuItemFactory() {
410
- return {
411
- id: SetDrawingAlignHorizonOperation.id,
412
- type: _univerjs_ui.MenuItemType.BUTTON,
413
- icon: "HorizontallyIcon",
414
- title: "drawing-ui.image-panel.align.horizon"
415
- };
422
+ function ToolbarButton(props) {
423
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
424
+ title: props.title,
425
+ placement: "bottom",
426
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
427
+ type: "button",
428
+ disabled: props.disabled,
429
+ onClick: props.onClick,
430
+ className: (0, _univerjs_design.clsx)("univer-flex univer-h-6 univer-w-6 univer-items-center univer-justify-center univer-rounded-md univer-border-none univer-bg-transparent univer-p-0 univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 disabled:univer-cursor-not-allowed disabled:univer-opacity-40 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-bg-gray-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-300": props.active }),
431
+ children: props.children
432
+ })
433
+ });
416
434
  }
417
- function SetDrawingAlignVerticalMenuItemFactory() {
418
- return {
419
- id: SetDrawingAlignVerticalOperation.id,
420
- type: _univerjs_ui.MenuItemType.BUTTON,
421
- icon: "VerticalCenterIcon",
422
- title: "drawing-ui.image-panel.align.vertical"
423
- };
435
+ function ToolbarDropdownButton(props) {
436
+ var _props$options$find;
437
+ const [open, setOpen] = (0, react.useState)(false);
438
+ const activeOption = (_props$options$find = props.options.find((option) => option.value === props.value)) !== null && _props$options$find !== void 0 ? _props$options$find : props.options[0];
439
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
440
+ open,
441
+ onOpenChange: setOpen,
442
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
443
+ className: "univer-min-w-32 univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-white univer-p-1 univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
444
+ children: props.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
445
+ type: "button",
446
+ onClick: () => {
447
+ props.onChange(option.value);
448
+ setOpen(false);
449
+ },
450
+ className: (0, _univerjs_design.clsx)("univer-flex univer-h-8 univer-w-full univer-items-center univer-gap-2 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-800", { "univer-bg-primary-50 univer-text-primary-600 dark:!univer-bg-gray-800 dark:!univer-text-primary-300": option.value === props.value }),
451
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
452
+ className: "univer-flex univer-size-4 univer-items-center univer-justify-center",
453
+ children: option.icon
454
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
455
+ className: "univer-flex-1",
456
+ children: option.label
457
+ })]
458
+ }, option.value))
459
+ }),
460
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
461
+ title: props.title,
462
+ placement: "bottom",
463
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
464
+ type: "button",
465
+ className: (0, _univerjs_design.clsx)("univer-flex univer-h-6 univer-min-w-9 univer-items-center univer-justify-center univer-gap-1 univer-rounded-md univer-border-none univer-bg-transparent univer-px-1.5 univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-bg-gray-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-300": open }),
466
+ children: [activeOption.icon, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-text-xs" })]
467
+ })
468
+ }) })
469
+ });
424
470
  }
425
-
426
- //#endregion
427
- //#region src/menu/arrange.menu.ts
428
- const DRAWING_ARRANGE_CONTEXT_MENU_ID = "contextMenu.drawing-arrange";
429
- function DrawingArrangeContextMenuItemFactory() {
430
- return {
431
- id: DRAWING_ARRANGE_CONTEXT_MENU_ID,
432
- type: _univerjs_ui.MenuItemType.SUBITEMS,
433
- icon: "TopmostIcon",
434
- title: "drawing-ui.image-panel.arrange.title"
471
+ function DocImageFloatingToolbar(props) {
472
+ var _univerInstanceServic, _wrappingStyleOptions, _wrappingStyleOptions2;
473
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
474
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
475
+ 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;
476
+ const [wrappingStyle, setWrappingStyle] = (0, react.useState)(() => getWrappingStyle(documentDataModel, props.drawingId));
477
+ const [hidden, setHidden] = (0, react.useState)(false);
478
+ const getMenuItem = (label) => props.menuItems.find((item) => item.label === label);
479
+ const editItem = getMenuItem("drawing-ui.image-popup.edit");
480
+ const cropItem = getMenuItem("drawing-ui.image-popup.crop");
481
+ const deleteItem = getMenuItem("drawing-ui.image-popup.delete");
482
+ const wrappingStyleOptions = [
483
+ {
484
+ label: localeService.t("drawing-ui.image-text-wrap.inline"),
485
+ value: "inline",
486
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.TextWrapShapeIcon, {})
487
+ },
488
+ {
489
+ label: localeService.t("drawing-ui.image-text-wrap.square"),
490
+ value: "wrapSquare",
491
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.TextWrapShapeIcon, {})
492
+ },
493
+ {
494
+ label: localeService.t("drawing-ui.image-text-wrap.topAndBottom"),
495
+ value: "wrapTopAndBottom",
496
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.TextWrapShapeIcon, {})
497
+ },
498
+ {
499
+ label: localeService.t("drawing-ui.image-text-wrap.behindText"),
500
+ value: "behindText",
501
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.TextWrapShapeIcon, {})
502
+ },
503
+ {
504
+ label: localeService.t("drawing-ui.image-text-wrap.inFrontText"),
505
+ value: "inFrontOfText",
506
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.TextWrapShapeIcon, {})
507
+ }
508
+ ];
509
+ const executeMenuItem = (item) => {
510
+ if (!item || item.disable) return;
511
+ commandService.executeCommand(item.commandId, item.commandParams);
435
512
  };
436
- }
437
- function SetDrawingArrangeFrontMenuItemFactory() {
438
- return {
439
- id: SetDrawingArrangeFrontOperation.id,
440
- type: _univerjs_ui.MenuItemType.BUTTON,
441
- icon: "TopmostIcon",
442
- title: "drawing-ui.image-panel.arrange.front"
443
- };
444
- }
445
- function SetDrawingArrangeForwardMenuItemFactory() {
446
- return {
447
- id: SetDrawingArrangeForwardOperation.id,
448
- type: _univerjs_ui.MenuItemType.BUTTON,
449
- icon: "MoveUpIcon",
450
- title: "drawing-ui.image-panel.arrange.forward"
451
- };
452
- }
453
- function SetDrawingArrangeBackMenuItemFactory() {
454
- return {
455
- id: SetDrawingArrangeBackOperation.id,
456
- type: _univerjs_ui.MenuItemType.BUTTON,
457
- icon: "BottomIcon",
458
- title: "drawing-ui.image-panel.arrange.back"
459
- };
460
- }
461
- function SetDrawingArrangeBackwardMenuItemFactory() {
462
- return {
463
- id: SetDrawingArrangeBackwardOperation.id,
464
- type: _univerjs_ui.MenuItemType.BUTTON,
465
- icon: "MoveDownIcon",
466
- title: "drawing-ui.image-panel.arrange.backward"
513
+ const updateWrappingStyle = (value) => {
514
+ setWrappingStyle(value);
515
+ commandService.executeCommand(UPDATE_DOC_DRAWING_WRAPPING_STYLE_COMMAND_ID, {
516
+ unitId: props.unitId,
517
+ subUnitId: props.subUnitId,
518
+ drawings: [{
519
+ unitId: props.unitId,
520
+ subUnitId: props.subUnitId,
521
+ drawingId: props.drawingId
522
+ }],
523
+ wrappingStyle: value
524
+ });
467
525
  };
526
+ if (hidden) return null;
527
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
528
+ "data-u-comp": "doc-image-floating-toolbar",
529
+ onMouseDown: (event) => {
530
+ event.stopPropagation();
531
+ event.preventDefault();
532
+ },
533
+ 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),
534
+ children: [
535
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarDropdownButton, {
536
+ 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"),
537
+ value: wrappingStyle,
538
+ options: wrappingStyleOptions,
539
+ onChange: updateWrappingStyle
540
+ }) }),
541
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Separator, { orientation: "vertical" }),
542
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarGroup, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
543
+ title: editItem ? localeService.t(editItem.label) : localeService.t("drawing-ui.image-popup.edit"),
544
+ disabled: !editItem || editItem.disable,
545
+ onClick: () => {
546
+ setHidden(true);
547
+ executeMenuItem(editItem);
548
+ },
549
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DocSettingIcon, {})
550
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
551
+ title: cropItem ? localeService.t(cropItem.label) : localeService.t("drawing-ui.image-popup.crop"),
552
+ disabled: !cropItem || cropItem.disable,
553
+ onClick: () => executeMenuItem(cropItem),
554
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CropIcon, {})
555
+ })] }),
556
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Separator, { orientation: "vertical" }),
557
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
558
+ title: deleteItem ? localeService.t(deleteItem.label) : localeService.t("drawing-ui.image-popup.delete"),
559
+ disabled: !deleteItem || deleteItem.disable,
560
+ onClick: () => executeMenuItem(deleteItem),
561
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
562
+ }) })
563
+ ]
564
+ });
468
565
  }
469
566
 
470
567
  //#endregion
471
- //#region src/menu/group.menu.ts
472
- const getMenuStateByDrawingFocusChangedObservable$ = (accessor, type) => {
473
- const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
474
- return new rxjs.Observable((subscriber) => {
475
- const update = (drawings) => {
476
- if (!drawings || drawings.length === 0) return subscriber.next(true);
477
- if (type === "group") {
478
- if (drawings.length < 2) return subscriber.next(true);
479
- if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
480
- } else if (type === "unGroup") {
481
- if (drawings.filter((drawing) => drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP).length === 0) return subscriber.next(true);
482
- } else if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
483
- subscriber.next(false);
484
- };
485
- const subscription = drawingManagerService.focus$.subscribe((drawings) => {
486
- if (!drawings || drawings.length === 0) return subscriber.next(true);
487
- update(drawings);
488
- });
489
- update(drawingManagerService.getFocusDrawings());
490
- return () => subscription.unsubscribe();
491
- });
492
- };
493
- const DRAWING_GROUP_CONTEXT_MENU_ID = "contextMenu.drawing-group";
494
- function DrawingGroupContextMenuItemFactory(accessor) {
495
- return {
496
- id: DRAWING_GROUP_CONTEXT_MENU_ID,
497
- type: _univerjs_ui.MenuItemType.SUBITEMS,
498
- icon: "GroupIcon",
499
- title: "drawing-ui.image-panel.group.title",
500
- hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor)
501
- };
502
- }
503
- function SetDrawingGroupMenuItemFactory(accessor) {
504
- return {
505
- id: SetDrawingGroupOperation.id,
506
- type: _univerjs_ui.MenuItemType.BUTTON,
507
- icon: "GroupIcon",
508
- title: "drawing-ui.image-panel.group.group",
509
- disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "group")
510
- };
511
- }
512
- function CancelDrawingGroupMenuItemFactory(accessor) {
513
- return {
514
- id: CancelDrawingGroupOperation.id,
515
- type: _univerjs_ui.MenuItemType.BUTTON,
516
- icon: "UngroupIcon",
517
- title: "drawing-ui.image-panel.group.unGroup",
518
- disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "unGroup")
568
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
569
+ function __decorateParam(paramIndex, decorator) {
570
+ return function(target, key) {
571
+ decorator(target, key, paramIndex);
519
572
  };
520
573
  }
521
574
 
522
575
  //#endregion
523
- //#region src/menu/schema.ts
524
- const menuSchema = { [_univerjs_ui.ContextMenuPosition.DRAWING]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
525
- [DRAWING_GROUP_CONTEXT_MENU_ID]: {
526
- order: 1,
527
- menuItemFactory: DrawingGroupContextMenuItemFactory,
528
- [SetDrawingGroupOperation.id]: {
529
- order: 0,
530
- menuItemFactory: SetDrawingGroupMenuItemFactory
531
- },
532
- [CancelDrawingGroupOperation.id]: {
533
- order: 1,
534
- menuItemFactory: CancelDrawingGroupMenuItemFactory
535
- }
536
- },
537
- [DRAWING_ARRANGE_CONTEXT_MENU_ID]: {
538
- order: 2,
539
- menuItemFactory: DrawingArrangeContextMenuItemFactory,
540
- [SetDrawingArrangeFrontOperation.id]: {
541
- order: 0,
542
- menuItemFactory: SetDrawingArrangeFrontMenuItemFactory
543
- },
544
- [SetDrawingArrangeForwardOperation.id]: {
545
- order: 1,
546
- menuItemFactory: SetDrawingArrangeForwardMenuItemFactory
547
- },
548
- [SetDrawingArrangeBackOperation.id]: {
549
- order: 2,
550
- menuItemFactory: SetDrawingArrangeBackMenuItemFactory
551
- },
552
- [SetDrawingArrangeBackwardOperation.id]: {
553
- order: 3,
554
- menuItemFactory: SetDrawingArrangeBackwardMenuItemFactory
555
- }
556
- },
557
- [DRAWING_ALIGN_CONTEXT_MENU_ID]: {
558
- order: 3,
559
- menuItemFactory: DrawingAlignContextMenuItemFactory,
560
- [SetDrawingAlignLeftOperation.id]: {
561
- order: 0,
562
- menuItemFactory: SetDrawingAlignLeftMenuItemFactory
563
- },
564
- [SetDrawingAlignCenterOperation.id]: {
565
- order: 1,
566
- menuItemFactory: SetDrawingAlignCenterMenuItemFactory
567
- },
568
- [SetDrawingAlignRightOperation.id]: {
569
- order: 2,
570
- menuItemFactory: SetDrawingAlignRightMenuItemFactory
571
- },
572
- [SetDrawingAlignTopOperation.id]: {
573
- order: 3,
574
- menuItemFactory: SetDrawingAlignTopMenuItemFactory
575
- },
576
- [SetDrawingAlignMiddleOperation.id]: {
577
- order: 4,
578
- menuItemFactory: SetDrawingAlignMiddleMenuItemFactory
579
- },
580
- [SetDrawingAlignBottomOperation.id]: {
581
- order: 5,
582
- menuItemFactory: SetDrawingAlignBottomMenuItemFactory
583
- },
584
- [SetDrawingAlignHorizonOperation.id]: {
585
- order: 6,
586
- menuItemFactory: SetDrawingAlignHorizonMenuItemFactory
587
- },
588
- [SetDrawingAlignVerticalOperation.id]: {
589
- order: 7,
590
- menuItemFactory: SetDrawingAlignVerticalMenuItemFactory
591
- }
592
- }
593
- } } };
576
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
577
+ function __decorate(decorators, target, key, desc) {
578
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
579
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
580
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
581
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
582
+ }
594
583
 
595
584
  //#endregion
596
- //#region src/views/image-popup-menu/component-name.ts
585
+ //#region src/controllers/components.controller.ts
597
586
  /**
598
587
  * Copyright 2023-present DreamNum Co., Ltd.
599
588
  *
@@ -609,403 +598,315 @@ const menuSchema = { [_univerjs_ui.ContextMenuPosition.DRAWING]: { [_univerjs_ui
609
598
  * See the License for the specific language governing permissions and
610
599
  * limitations under the License.
611
600
  */
612
- const COMPONENT_IMAGE_POPUP_MENU = "COMPONENT_IMAGE_POPUP_MENU";
601
+ let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
602
+ constructor(_componentManager, _iconManager) {
603
+ super();
604
+ this._componentManager = _componentManager;
605
+ this._iconManager = _iconManager;
606
+ this._registerComponents();
607
+ this._registerIcons();
608
+ }
609
+ _registerComponents() {
610
+ [[COMPONENT_IMAGE_POPUP_MENU, ImagePopupMenu]].forEach(([key, component]) => {
611
+ this.disposeWithMe(this._componentManager.register(key, component));
612
+ });
613
+ }
614
+ _registerIcons() {
615
+ this.disposeWithMe(this._iconManager.register({
616
+ BottomIcon: _univerjs_icons.BottomIcon,
617
+ GroupIcon: _univerjs_icons.GroupIcon,
618
+ MoveDownIcon: _univerjs_icons.MoveDownIcon,
619
+ MoveUpIcon: _univerjs_icons.MoveUpIcon,
620
+ TopmostIcon: _univerjs_icons.TopmostIcon,
621
+ UngroupIcon: _univerjs_icons.UngroupIcon
622
+ }));
623
+ }
624
+ };
625
+ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
613
626
 
614
627
  //#endregion
615
- //#region src/views/image-popup-menu/ImagePopupMenu.tsx
616
- function ImagePopupMenu(props) {
617
- var _popup$extraProps, _popup$extraProps2;
618
- const { popup } = props;
619
- const menuItems = popup === null || popup === void 0 || (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.menuItems;
620
- if (!menuItems) return null;
621
- 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, {
622
- menuItems,
623
- unitId: popup.extraProps.unitId,
624
- subUnitId: popup.extraProps.subUnitId,
625
- drawingId: popup.extraProps.drawingId
626
- });
627
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
628
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
629
- const [visible, setVisible] = (0, react.useState)(false);
630
- const [isHovered, setHovered] = (0, react.useState)(false);
631
- const handleMouseEnter = () => {
632
- setHovered(true);
633
- };
634
- const handleMouseLeave = () => {
635
- setHovered(false);
636
- };
637
- const onVisibleChange = (visible) => {
638
- setVisible(visible);
639
- };
640
- const handleClick = (item) => {
641
- commandService.executeCommand(item.commandId, item.commandParams);
642
- setVisible(false);
643
- };
644
- const showMore = visible || isHovered;
645
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
646
- onMouseEnter: handleMouseEnter,
647
- onMouseLeave: handleMouseLeave,
648
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
649
- align: "start",
650
- items: menuItems.map((item) => ({
651
- type: "item",
652
- children: localeService.t(item.label),
653
- disabled: item.disable,
654
- onSelect: () => handleClick(item)
655
- })),
656
- open: visible,
657
- onOpenChange: onVisibleChange,
658
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
659
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", _univerjs_design.borderClassName, {
660
- "univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
661
- "univer-bg-white dark:!univer-bg-gray-900": !visible
662
- }),
663
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
664
- })
665
- })
666
- });
667
- }
668
- const UPDATE_DOC_DRAWING_WRAPPING_STYLE_COMMAND_ID = "doc.command.update-doc-drawing-wrapping-style";
669
- function getWrappingStyle(documentDataModel, drawingId) {
670
- var _documentDataModel$ge;
671
- const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingId];
672
- if (!drawing) return "inline";
673
- if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) return drawing.behindDoc === _univerjs_core.BooleanNumber.TRUE ? "behindText" : "inFrontOfText";
674
- if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE) return "wrapSquare";
675
- if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) return "wrapTopAndBottom";
676
- return "inline";
677
- }
678
- function Divider() {
679
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "\n univer-h-5 univer-w-px univer-bg-gray-200\n dark:!univer-bg-gray-700\n " });
680
- }
681
- function ToolbarGroup(props) {
682
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
683
- className: "univer-flex univer-h-7 univer-items-center univer-gap-1 univer-px-1",
684
- children: props.children
685
- });
686
- }
687
- function ToolbarButton(props) {
688
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
689
- title: props.title,
690
- placement: "bottom",
691
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
692
- type: "button",
693
- disabled: props.disabled,
694
- onClick: props.onClick,
695
- className: (0, _univerjs_design.clsx)("univer-flex univer-h-6 univer-w-6 univer-items-center univer-justify-center univer-rounded-md univer-border-none univer-bg-transparent univer-p-0 univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 disabled:univer-cursor-not-allowed disabled:univer-opacity-40 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-bg-gray-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-300": props.active }),
696
- children: props.children
697
- })
698
- });
699
- }
700
- function TextWrapShapeIcon() {
701
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
702
- viewBox: "0 0 20 20",
703
- width: "1em",
704
- height: "1em",
705
- fill: "none",
706
- "aria-hidden": "true",
707
- children: [
708
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
709
- d: "M2.5 4.5H8.2",
710
- stroke: "currentColor",
711
- strokeWidth: "1.4",
712
- strokeLinecap: "round"
713
- }),
714
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
715
- d: "M11.8 4.5H17.5",
716
- stroke: "currentColor",
717
- strokeWidth: "1.4",
718
- strokeLinecap: "round"
719
- }),
720
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
721
- d: "M2.5 10H5.7",
722
- stroke: "currentColor",
723
- strokeWidth: "1.4",
724
- strokeLinecap: "round"
725
- }),
726
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
727
- d: "M14.3 10H17.5",
728
- stroke: "currentColor",
729
- strokeWidth: "1.4",
730
- strokeLinecap: "round"
731
- }),
732
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
733
- d: "M2.5 15.5H8.2",
734
- stroke: "currentColor",
735
- strokeWidth: "1.4",
736
- strokeLinecap: "round"
737
- }),
738
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
739
- d: "M11.8 15.5H17.5",
740
- stroke: "currentColor",
741
- strokeWidth: "1.4",
742
- strokeLinecap: "round"
743
- }),
744
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
745
- x: "6.8",
746
- y: "7",
747
- width: "6.4",
748
- height: "6",
749
- rx: "1",
750
- stroke: "currentColor",
751
- strokeWidth: "1.4"
752
- })
753
- ]
754
- });
755
- }
756
- function CropIcon() {
757
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
758
- viewBox: "0 0 20 20",
759
- width: "1em",
760
- height: "1em",
761
- fill: "none",
762
- "aria-hidden": "true",
763
- children: [
764
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
765
- d: "M5 2.8V12.5C5 13.9 6.1 15 7.5 15H17.2",
766
- stroke: "currentColor",
767
- strokeWidth: "1.5",
768
- strokeLinecap: "round"
769
- }),
770
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
771
- d: "M2.8 5H12.5C13.9 5 15 6.1 15 7.5V17.2",
772
- stroke: "currentColor",
773
- strokeWidth: "1.5",
774
- strokeLinecap: "round"
775
- }),
776
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
777
- d: "M8.3 8.3H11.7V11.7H8.3V8.3Z",
778
- stroke: "currentColor",
779
- strokeWidth: "1.2"
780
- })
781
- ]
782
- });
783
- }
784
- function ToolbarDropdownButton(props) {
785
- var _props$options$find;
786
- const [open, setOpen] = (0, react.useState)(false);
787
- const activeOption = (_props$options$find = props.options.find((option) => option.value === props.value)) !== null && _props$options$find !== void 0 ? _props$options$find : props.options[0];
788
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
789
- open,
790
- onOpenChange: setOpen,
791
- overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
792
- className: "univer-min-w-32 univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-white univer-p-1 univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
793
- children: props.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
794
- type: "button",
795
- onClick: () => {
796
- props.onChange(option.value);
797
- setOpen(false);
798
- },
799
- className: (0, _univerjs_design.clsx)("univer-flex univer-h-8 univer-w-full univer-items-center univer-gap-2 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-800", { "univer-bg-primary-50 univer-text-primary-600 dark:!univer-bg-gray-800 dark:!univer-text-primary-300": option.value === props.value }),
800
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
801
- className: "univer-flex univer-size-4 univer-items-center univer-justify-center",
802
- children: option.icon
803
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
804
- className: "univer-flex-1",
805
- children: option.label
806
- })]
807
- }, option.value))
808
- }),
809
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
810
- title: props.title,
811
- placement: "bottom",
812
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
813
- type: "button",
814
- className: (0, _univerjs_design.clsx)("univer-flex univer-h-6 univer-min-w-9 univer-items-center univer-justify-center univer-gap-1 univer-rounded-md univer-border-none univer-bg-transparent univer-px-1.5 univer-text-sm univer-text-gray-700 univer-transition-colors hover:univer-bg-gray-100 dark:!univer-text-gray-100 dark:hover:!univer-bg-gray-700", { "univer-bg-gray-100 univer-text-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-primary-300": open }),
815
- children: [activeOption.icon, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-text-xs" })]
816
- })
817
- }) })
818
- });
628
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
629
+ function _typeof(o) {
630
+ "@babel/helpers - typeof";
631
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
632
+ return typeof o;
633
+ } : function(o) {
634
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
635
+ }, _typeof(o);
819
636
  }
820
- function DocImageFloatingToolbar(props) {
821
- var _univerInstanceServic, _wrappingStyleOptions, _wrappingStyleOptions2;
822
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
823
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
824
- 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;
825
- const [wrappingStyle, setWrappingStyle] = (0, react.useState)(() => getWrappingStyle(documentDataModel, props.drawingId));
826
- const [hidden, setHidden] = (0, react.useState)(false);
827
- const getMenuItem = (label) => props.menuItems.find((item) => item.label === label);
828
- const editItem = getMenuItem("drawing-ui.image-popup.edit");
829
- const cropItem = getMenuItem("drawing-ui.image-popup.crop");
830
- const deleteItem = getMenuItem("drawing-ui.image-popup.delete");
831
- const wrappingStyleOptions = [
832
- {
833
- label: localeService.t("drawing-ui.image-text-wrap.inline"),
834
- value: "inline",
835
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextWrapShapeIcon, {})
836
- },
837
- {
838
- label: localeService.t("drawing-ui.image-text-wrap.square"),
839
- value: "wrapSquare",
840
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextWrapShapeIcon, {})
841
- },
842
- {
843
- label: localeService.t("drawing-ui.image-text-wrap.topAndBottom"),
844
- value: "wrapTopAndBottom",
845
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextWrapShapeIcon, {})
846
- },
847
- {
848
- label: localeService.t("drawing-ui.image-text-wrap.behindText"),
849
- value: "behindText",
850
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextWrapShapeIcon, {})
851
- },
852
- {
853
- label: localeService.t("drawing-ui.image-text-wrap.inFrontText"),
854
- value: "inFrontOfText",
855
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextWrapShapeIcon, {})
856
- }
857
- ];
858
- const executeMenuItem = (item) => {
859
- if (!item || item.disable) return;
860
- commandService.executeCommand(item.commandId, item.commandParams);
861
- };
862
- const updateWrappingStyle = (value) => {
863
- setWrappingStyle(value);
864
- commandService.executeCommand(UPDATE_DOC_DRAWING_WRAPPING_STYLE_COMMAND_ID, {
865
- unitId: props.unitId,
866
- subUnitId: props.subUnitId,
867
- drawings: [{
868
- unitId: props.unitId,
869
- subUnitId: props.subUnitId,
870
- drawingId: props.drawingId
871
- }],
872
- wrappingStyle: value
873
- });
874
- };
875
- if (hidden) return null;
876
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
877
- "data-u-comp": "doc-image-floating-toolbar",
878
- onMouseDown: (event) => {
879
- event.stopPropagation();
880
- event.preventDefault();
881
- },
882
- 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),
883
- children: [
884
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarDropdownButton, {
885
- 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"),
886
- value: wrappingStyle,
887
- options: wrappingStyleOptions,
888
- onChange: updateWrappingStyle
889
- }) }),
890
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Divider, {}),
891
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarGroup, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
892
- title: editItem ? localeService.t(editItem.label) : localeService.t("drawing-ui.image-popup.edit"),
893
- disabled: !editItem || editItem.disable,
894
- onClick: () => {
895
- setHidden(true);
896
- executeMenuItem(editItem);
897
- },
898
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DocSettingIcon, {})
899
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
900
- title: cropItem ? localeService.t(cropItem.label) : localeService.t("drawing-ui.image-popup.crop"),
901
- disabled: !cropItem || cropItem.disable,
902
- onClick: () => executeMenuItem(cropItem),
903
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CropIcon, {})
904
- })] }),
905
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Divider, {}),
906
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarGroup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
907
- title: deleteItem ? localeService.t(deleteItem.label) : localeService.t("drawing-ui.image-popup.delete"),
908
- disabled: !deleteItem || deleteItem.disable,
909
- onClick: () => executeMenuItem(deleteItem),
910
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
911
- }) })
912
- ]
913
- });
637
+
638
+ //#endregion
639
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
640
+ function toPrimitive(t, r) {
641
+ if ("object" != _typeof(t) || !t) return t;
642
+ var e = t[Symbol.toPrimitive];
643
+ if (void 0 !== e) {
644
+ var i = e.call(t, r || "default");
645
+ if ("object" != _typeof(i)) return i;
646
+ throw new TypeError("@@toPrimitive must return a primitive value.");
647
+ }
648
+ return ("string" === r ? String : Number)(t);
914
649
  }
915
650
 
916
651
  //#endregion
917
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
918
- function __decorateParam(paramIndex, decorator) {
919
- return function(target, key) {
920
- decorator(target, key, paramIndex);
921
- };
652
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
653
+ function toPropertyKey(t) {
654
+ var i = toPrimitive(t, "string");
655
+ return "symbol" == _typeof(i) ? i : i + "";
922
656
  }
923
657
 
924
658
  //#endregion
925
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
926
- function __decorate(decorators, target, key, desc) {
927
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
928
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
929
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
930
- return c > 3 && r && Object.defineProperty(target, key, r), r;
659
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
660
+ function _defineProperty(e, r, t) {
661
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
662
+ value: t,
663
+ enumerable: !0,
664
+ configurable: !0,
665
+ writable: !0
666
+ }) : e[r] = t, e;
931
667
  }
932
668
 
933
669
  //#endregion
934
- //#region src/controllers/drawing-ui.controller.ts
670
+ //#region src/services/drawing-image-clip.service.ts
671
+ const IMAGE_CLIP_SHAPE_PICKER_COMPONENT = "sheet.image-clip.shape.picker.component";
935
672
  /**
936
- * Copyright 2023-present DreamNum Co., Ltd.
937
- *
938
- * Licensed under the Apache License, Version 2.0 (the "License");
939
- * you may not use this file except in compliance with the License.
940
- * You may obtain a copy of the License at
941
- *
942
- * http://www.apache.org/licenses/LICENSE-2.0
673
+ * Bridge service that enables shape-based image clipping.
674
+ * This service lives in the open-source drawing-ui package and delegates
675
+ * to a registered clip implementation (provided by pro engine-shape package).
943
676
  *
944
- * Unless required by applicable law or agreed to in writing, software
945
- * distributed under the License is distributed on an "AS IS" BASIS,
946
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
947
- * See the License for the specific language governing permissions and
948
- * limitations under the License.
677
+ * When no delegate is registered, applyShapeClip returns false and images render normally without shape clipping.
949
678
  */
950
- let DrawingUIController = class DrawingUIController extends _univerjs_core.Disposable {
951
- constructor(_componentManager, _commandService, _menuManagerService) {
679
+ var DrawingImageClipService = class extends _univerjs_core.Disposable {
680
+ constructor() {
952
681
  super();
953
- this._componentManager = _componentManager;
954
- this._commandService = _commandService;
955
- this._menuManagerService = _menuManagerService;
956
- this._init();
957
- }
958
- _init() {
959
- this._initMenus();
960
- this._initCommands();
961
- this._initComponents();
682
+ _defineProperty(this, "_clipDelegate", null);
683
+ _defineProperty(this, "_canUseShapeClip$", new rxjs.BehaviorSubject(false));
684
+ _defineProperty(this, "canUseShapeClip$", this._canUseShapeClip$.asObservable());
962
685
  }
963
- _initMenus() {
964
- this._menuManagerService.mergeMenu(menuSchema);
686
+ setCanUseShapeClip(canUse) {
687
+ this._canUseShapeClip$.next(canUse);
965
688
  }
966
- _initCommands() {
967
- [
968
- OpenImageCropOperation,
969
- CloseImageCropOperation,
970
- ImageResetSizeOperation,
971
- SetDrawingAlignOperation,
972
- SetDrawingAlignLeftOperation,
973
- SetDrawingAlignCenterOperation,
974
- SetDrawingAlignRightOperation,
975
- SetDrawingAlignTopOperation,
976
- SetDrawingAlignMiddleOperation,
977
- SetDrawingAlignBottomOperation,
978
- SetDrawingAlignHorizonOperation,
979
- SetDrawingAlignVerticalOperation,
980
- AutoImageCropOperation,
981
- SetDrawingGroupOperation,
982
- CancelDrawingGroupOperation,
983
- SetDrawingArrangeOperation,
984
- SetDrawingArrangeFrontOperation,
985
- SetDrawingArrangeForwardOperation,
986
- SetDrawingArrangeBackOperation,
987
- SetDrawingArrangeBackwardOperation
988
- ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
689
+ /**
690
+ * Register a clip delegate that knows how to build shape clip paths.
691
+ * Typically called by the pro-side plugin with a ShapeModel-based implementation.
692
+ * @returns IDisposable to unregister the delegate
693
+ */
694
+ registerClipDelegate(delegate) {
695
+ this._clipDelegate = delegate;
696
+ return (0, _univerjs_core.toDisposable)(() => {
697
+ if (this._clipDelegate === delegate) this._clipDelegate = null;
698
+ });
989
699
  }
990
- _initComponents() {
991
- [
992
- [COMPONENT_IMAGE_POPUP_MENU, ImagePopupMenu],
993
- ["BottomIcon", _univerjs_icons.BottomIcon],
994
- ["GroupIcon", _univerjs_icons.GroupIcon],
995
- ["MoveDownIcon", _univerjs_icons.MoveDownIcon],
996
- ["MoveUpIcon", _univerjs_icons.MoveUpIcon],
997
- ["TopmostIcon", _univerjs_icons.TopmostIcon],
998
- ["UngroupIcon", _univerjs_icons.UngroupIcon]
999
- ].forEach(([key, component]) => {
1000
- this.disposeWithMe(this._componentManager.register(key, component));
700
+ applyShapeClip(ctx, prstGeom, width, height, adjustValues) {
701
+ if (this._clipDelegate) return this._clipDelegate(ctx, prstGeom, width, height, adjustValues);
702
+ return false;
703
+ }
704
+ dispose() {
705
+ this._clipDelegate = null;
706
+ this._canUseShapeClip$.complete();
707
+ super.dispose();
708
+ }
709
+ };
710
+
711
+ //#endregion
712
+ //#region src/services/drawing-render.service.ts
713
+ const DOC_DRAWING_BEHIND_TEXT_LAYER_INDEX = 1;
714
+ function getDrawingRenderLayerIndex(param) {
715
+ return param.behindText === true || param.behindText === _univerjs_core.BooleanNumber.TRUE ? 1 : _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX;
716
+ }
717
+ function ensureDrawingRenderLayer(scene, object, param) {
718
+ const layerIndex = getDrawingRenderLayerIndex(param);
719
+ if (object.layer == null || object.layer.zIndex === layerIndex) return;
720
+ scene.removeObject(object);
721
+ scene.addObject(object, layerIndex);
722
+ }
723
+ function isRenderableImageCache(image) {
724
+ return (image === null || image === void 0 ? void 0 : image.complete) === true && image.naturalWidth > 0 && image.naturalHeight > 0;
725
+ }
726
+ let DrawingRenderService = class DrawingRenderService {
727
+ constructor(_drawingManagerService, _imageIoService, _galleryService, _urlImageService, _univerInstanceService, _drawingImageClipService) {
728
+ this._drawingManagerService = _drawingManagerService;
729
+ this._imageIoService = _imageIoService;
730
+ this._galleryService = _galleryService;
731
+ this._urlImageService = _urlImageService;
732
+ this._univerInstanceService = _univerInstanceService;
733
+ this._drawingImageClipService = _drawingImageClipService;
734
+ }
735
+ async renderImages(imageParam, scene) {
736
+ const { transform: singleTransform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms, adjustValues, hidden } = imageParam;
737
+ if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
738
+ if (!this._drawingManagerService.getDrawingVisible()) return;
739
+ if (this._univerInstanceService.getUnitType(unitId) === _univerjs_core.UniverInstanceType.UNIVER_SHEET && subUnitId !== this._getActiveSheetId()) return;
740
+ if (singleTransform == null) return;
741
+ const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
742
+ const images = [];
743
+ for (const transform of transforms) {
744
+ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
745
+ const index = transforms.indexOf(transform);
746
+ const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
747
+ unitId,
748
+ subUnitId,
749
+ drawingId
750
+ }, isMultiTransform ? index : void 0);
751
+ const imageShape = scene.getObject(imageShapeKey);
752
+ if (imageShape != null) {
753
+ var _setClipBounds;
754
+ imageShape.transformByState({
755
+ left,
756
+ top,
757
+ width,
758
+ height,
759
+ angle,
760
+ flipX,
761
+ flipY,
762
+ skewX,
763
+ skewY
764
+ });
765
+ (_setClipBounds = imageShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(imageShape, transform.clipBounds);
766
+ if ("hidden" in imageParam) hidden ? imageShape.hide() : imageShape.show();
767
+ ensureDrawingRenderLayer(scene, imageShape, imageParam);
768
+ continue;
769
+ }
770
+ const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
771
+ const zIndex = orders.indexOf(drawingId);
772
+ const imageConfig = {
773
+ ...transform,
774
+ zIndex: zIndex === -1 ? orders.length - 1 : zIndex
775
+ };
776
+ const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
777
+ let shouldBeCache = false;
778
+ if (isRenderableImageCache(imageNativeCache)) imageConfig.image = imageNativeCache;
779
+ else if (imageSourceType === _univerjs_drawing.ImageSourceType.UUID) try {
780
+ imageConfig.url = await this._imageIoService.getImage(source);
781
+ } catch (error) {
782
+ console.error(error);
783
+ continue;
784
+ }
785
+ else if (imageSourceType === _univerjs_drawing.ImageSourceType.URL) {
786
+ try {
787
+ imageConfig.url = await this._urlImageService.getImage(source);
788
+ } catch (error) {
789
+ console.error(error);
790
+ imageConfig.url = source;
791
+ }
792
+ shouldBeCache = true;
793
+ } else {
794
+ imageConfig.url = source;
795
+ shouldBeCache = true;
796
+ }
797
+ if (hidden) imageConfig.visible = false;
798
+ if (scene.getObject(imageShapeKey)) continue;
799
+ imageConfig.printable = true;
800
+ const image = new _univerjs_engine_render.Image(imageShapeKey, imageConfig);
801
+ image.setClipService(this._drawingImageClipService);
802
+ if (shouldBeCache) this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
803
+ scene.addObject(image, getDrawingRenderLayerIndex(imageParam));
804
+ if (this._drawingManagerService.getDrawingEditable()) scene.attachTransformerTo(image);
805
+ groupId && insertGroupObject({
806
+ drawingId: groupId,
807
+ unitId,
808
+ subUnitId
809
+ }, image, scene, this._drawingManagerService);
810
+ if (prstGeom != null) image.setPrstGeom(prstGeom);
811
+ if (adjustValues != null) image.setPrstGeomAdjValues(adjustValues);
812
+ if (srcRect != null) image.setSrcRect(srcRect);
813
+ images.push(image);
814
+ }
815
+ return images;
816
+ }
817
+ _getActiveSheetId() {
818
+ var _this$_univerInstance;
819
+ return (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getActiveSheet()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetId();
820
+ }
821
+ renderFloatDom(param, scene) {
822
+ const { transform: singleTransform, drawingType, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms } = param;
823
+ if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_DOM) return;
824
+ if (!this._drawingManagerService.getDrawingVisible()) return;
825
+ if (singleTransform == null) return;
826
+ const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
827
+ const rects = [];
828
+ for (const transform of transforms) {
829
+ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
830
+ const index = transforms.indexOf(transform);
831
+ const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
832
+ unitId,
833
+ subUnitId,
834
+ drawingId
835
+ }, isMultiTransform ? index : void 0);
836
+ const imageShape = scene.getObject(imageShapeKey);
837
+ if (imageShape != null) {
838
+ imageShape.transformByState({
839
+ left,
840
+ top,
841
+ width,
842
+ height,
843
+ angle,
844
+ flipX,
845
+ flipY,
846
+ skewX,
847
+ skewY
848
+ });
849
+ continue;
850
+ }
851
+ const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
852
+ const zIndex = orders.indexOf(drawingId);
853
+ const rectConfig = {
854
+ ...transform,
855
+ zIndex: zIndex === -1 ? orders.length - 1 : zIndex
856
+ };
857
+ if (scene.getObject(imageShapeKey)) continue;
858
+ rectConfig.printable = false;
859
+ const rect = new _univerjs_engine_render.Rect(imageShapeKey, rectConfig);
860
+ if (!this._drawingManagerService.getDrawingVisible()) continue;
861
+ scene.addObject(rect, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX);
862
+ if (this._drawingManagerService.getDrawingEditable() && param.allowTransform !== false) scene.attachTransformerTo(rect);
863
+ groupId && insertGroupObject({
864
+ drawingId: groupId,
865
+ unitId,
866
+ subUnitId
867
+ }, rect, scene, this._drawingManagerService);
868
+ rects.push(rect);
869
+ }
870
+ return rects;
871
+ }
872
+ renderDrawing(param, scene) {
873
+ const drawingParam = this._drawingManagerService.getDrawingByParam(param);
874
+ if (drawingParam == null) return;
875
+ switch (drawingParam.drawingType) {
876
+ case _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE: return this.renderImages(drawingParam, scene);
877
+ default:
878
+ }
879
+ }
880
+ previewImage(key, src, width, height) {
881
+ this._galleryService.open({
882
+ images: [src],
883
+ onOpenChange: (open) => {
884
+ if (!open) this._galleryService.close();
885
+ }
1001
886
  });
1002
887
  }
888
+ _adjustImageSize(nativeWidth, nativeHeight, screenWidth, screenHeight) {
889
+ if (nativeWidth <= screenWidth && nativeHeight <= screenHeight) return {
890
+ width: nativeWidth,
891
+ height: nativeHeight
892
+ };
893
+ const widthRatio = screenWidth / nativeWidth;
894
+ const heightRatio = screenHeight / nativeHeight;
895
+ const scale = Math.min(widthRatio, heightRatio);
896
+ return {
897
+ width: Math.floor(nativeWidth * scale),
898
+ height: Math.floor(nativeHeight * scale)
899
+ };
900
+ }
1003
901
  };
1004
- DrawingUIController = __decorate([
1005
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
1006
- __decorateParam(1, _univerjs_core.ICommandService),
1007
- __decorateParam(2, _univerjs_ui.IMenuManagerService)
1008
- ], DrawingUIController);
902
+ DrawingRenderService = __decorate([
903
+ __decorateParam(0, _univerjs_drawing.IDrawingManagerService),
904
+ __decorateParam(1, _univerjs_drawing.IImageIoService),
905
+ __decorateParam(2, _univerjs_ui.IGalleryService),
906
+ __decorateParam(3, _univerjs_core.IURLImageService),
907
+ __decorateParam(4, _univerjs_core.IUniverInstanceService),
908
+ __decorateParam(5, (0, _univerjs_core.Inject)(DrawingImageClipService))
909
+ ], DrawingRenderService);
1009
910
 
1010
911
  //#endregion
1011
912
  //#region src/utils/get-update-params.ts
@@ -1039,49 +940,19 @@ function getUpdateParams(objects, drawingManagerService) {
1039
940
  }
1040
941
 
1041
942
  //#endregion
1042
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
1043
- function _typeof(o) {
1044
- "@babel/helpers - typeof";
1045
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
1046
- return typeof o;
1047
- } : function(o) {
1048
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1049
- }, _typeof(o);
1050
- }
1051
-
1052
- //#endregion
1053
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
1054
- function toPrimitive(t, r) {
1055
- if ("object" != _typeof(t) || !t) return t;
1056
- var e = t[Symbol.toPrimitive];
1057
- if (void 0 !== e) {
1058
- var i = e.call(t, r || "default");
1059
- if ("object" != _typeof(i)) return i;
1060
- throw new TypeError("@@toPrimitive must return a primitive value.");
1061
- }
1062
- return ("string" === r ? String : Number)(t);
943
+ //#region src/controllers/drawing-update.controller.ts
944
+ function syncDrawingHiddenState(shape, drawingParam) {
945
+ if (!("hidden" in drawingParam)) return;
946
+ drawingParam.hidden === true ? shape.hide() : shape.show();
1063
947
  }
1064
-
1065
- //#endregion
1066
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
1067
- function toPropertyKey(t) {
1068
- var i = toPrimitive(t, "string");
1069
- return "symbol" == _typeof(i) ? i : i + "";
948
+ function mergeRefreshMetadata(drawingParam, refreshParam) {
949
+ const metadata = refreshParam;
950
+ if (!("hidden" in metadata) && !("behindText" in metadata)) return drawingParam;
951
+ return {
952
+ ...drawingParam,
953
+ ...metadata
954
+ };
1070
955
  }
1071
-
1072
- //#endregion
1073
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
1074
- function _defineProperty(e, r, t) {
1075
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1076
- value: t,
1077
- enumerable: !0,
1078
- configurable: !0,
1079
- writable: !0
1080
- }) : e[r] = t, e;
1081
- }
1082
-
1083
- //#endregion
1084
- //#region src/controllers/drawing-update.controller.ts
1085
956
  let DrawingUpdateController = class DrawingUpdateController extends _univerjs_core.Disposable {
1086
957
  constructor(_currentUniverService, _commandService, _renderManagerService, _drawingManagerService) {
1087
958
  super();
@@ -1415,7 +1286,7 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1415
1286
  _drawingUpdateListener() {
1416
1287
  this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
1417
1288
  params.forEach((param) => {
1418
- var _scene$getTransformer2;
1289
+ var _setClipBounds, _scene$getTransformer2;
1419
1290
  const { unitId, subUnitId, drawingId } = param;
1420
1291
  const drawingParam = this._drawingManagerService.getDrawingByParam(param);
1421
1292
  if (drawingParam == null) return;
@@ -1443,6 +1314,9 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1443
1314
  skewX,
1444
1315
  skewY
1445
1316
  });
1317
+ (_setClipBounds = drawingShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(drawingShape, transform.clipBounds);
1318
+ syncDrawingHiddenState(drawingShape, drawingParam);
1319
+ ensureDrawingRenderLayer(scene, drawingShape, drawingParam);
1446
1320
  (_scene$getTransformer2 = scene.getTransformer()) === null || _scene$getTransformer2 === void 0 || _scene$getTransformer2.debounceRefreshControls();
1447
1321
  });
1448
1322
  }));
@@ -1450,6 +1324,7 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1450
1324
  _drawingRefreshListener() {
1451
1325
  this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe((params) => {
1452
1326
  params.forEach((param) => {
1327
+ var _setClipBounds2;
1453
1328
  const { unitId, subUnitId, drawingId } = param;
1454
1329
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
1455
1330
  if (renderObject == null) return;
@@ -1457,13 +1332,23 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1457
1332
  if (drawingParam == null) return;
1458
1333
  const { transform } = drawingParam;
1459
1334
  const { scene } = renderObject;
1335
+ if (transform == null) return true;
1460
1336
  const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
1461
1337
  unitId,
1462
1338
  subUnitId,
1463
1339
  drawingId
1464
1340
  });
1465
1341
  const drawingShape = scene.getObject(drawingShapeKey);
1466
- if (drawingShape == null || transform == null) return true;
1342
+ const drawingParamWithRefreshMetadata = mergeRefreshMetadata(drawingParam, param);
1343
+ if (drawingShape == null) {
1344
+ if (drawingParamWithRefreshMetadata.hidden === true) return true;
1345
+ this._drawingManagerService.addNotification([{
1346
+ unitId,
1347
+ subUnitId,
1348
+ drawingId
1349
+ }]);
1350
+ return true;
1351
+ }
1467
1352
  const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
1468
1353
  drawingShape.transformByState({
1469
1354
  left,
@@ -1476,6 +1361,9 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1476
1361
  skewX,
1477
1362
  skewY
1478
1363
  });
1364
+ (_setClipBounds2 = drawingShape.setClipBounds) === null || _setClipBounds2 === void 0 || _setClipBounds2.call(drawingShape, transform.clipBounds);
1365
+ syncDrawingHiddenState(drawingShape, drawingParamWithRefreshMetadata);
1366
+ ensureDrawingRenderLayer(scene, drawingShape, drawingParamWithRefreshMetadata);
1479
1367
  });
1480
1368
  }));
1481
1369
  }
@@ -2025,386 +1913,485 @@ ImageCropperController = __decorate([
2025
1913
  ], ImageCropperController);
2026
1914
 
2027
1915
  //#endregion
2028
- //#region src/services/drawing-image-clip.service.ts
2029
- const IMAGE_CLIP_SHAPE_PICKER_COMPONENT = "sheet.image-clip.shape.picker.component";
2030
- /**
2031
- * Bridge service that enables shape-based image clipping.
2032
- * This service lives in the open-source drawing-ui package and delegates
2033
- * to a registered clip implementation (provided by pro engine-shape package).
2034
- *
2035
- * When no delegate is registered, applyShapeClip returns false and images render normally without shape clipping.
2036
- */
2037
- var DrawingImageClipService = class extends _univerjs_core.Disposable {
2038
- constructor() {
1916
+ //#region src/controllers/image-update.controller.ts
1917
+ let ImageUpdateController = class ImageUpdateController extends _univerjs_core.Disposable {
1918
+ constructor(_commandService, _renderManagerService, _drawingManagerService, _dialogService, _imageIoService, _currentUniverService, _drawingRenderService) {
2039
1919
  super();
2040
- _defineProperty(this, "_clipDelegate", null);
2041
- _defineProperty(this, "_canUseShapeClip$", new rxjs.BehaviorSubject(false));
2042
- _defineProperty(this, "canUseShapeClip$", this._canUseShapeClip$.asObservable());
2043
- }
2044
- setCanUseShapeClip(canUse) {
2045
- this._canUseShapeClip$.next(canUse);
2046
- }
2047
- /**
2048
- * Register a clip delegate that knows how to build shape clip paths.
2049
- * Typically called by the pro-side plugin with a ShapeModel-based implementation.
2050
- * @returns IDisposable to unregister the delegate
2051
- */
2052
- registerClipDelegate(delegate) {
2053
- this._clipDelegate = delegate;
2054
- return (0, _univerjs_core.toDisposable)(() => {
2055
- if (this._clipDelegate === delegate) this._clipDelegate = null;
2056
- });
2057
- }
2058
- applyShapeClip(ctx, prstGeom, width, height, adjustValues) {
2059
- if (this._clipDelegate) return this._clipDelegate(ctx, prstGeom, width, height, adjustValues);
2060
- return false;
1920
+ this._commandService = _commandService;
1921
+ this._renderManagerService = _renderManagerService;
1922
+ this._drawingManagerService = _drawingManagerService;
1923
+ this._dialogService = _dialogService;
1924
+ this._imageIoService = _imageIoService;
1925
+ this._currentUniverService = _currentUniverService;
1926
+ this._drawingRenderService = _drawingRenderService;
1927
+ this._initialize();
2061
1928
  }
2062
1929
  dispose() {
2063
- this._clipDelegate = null;
2064
- this._canUseShapeClip$.complete();
2065
1930
  super.dispose();
2066
1931
  }
2067
- };
2068
-
2069
- //#endregion
2070
- //#region src/services/drawing-render.service.ts
2071
- let DrawingRenderService = class DrawingRenderService {
2072
- constructor(_drawingManagerService, _imageIoService, _galleryService, _urlImageService, _univerInstanceService, _drawingImageClipService) {
2073
- this._drawingManagerService = _drawingManagerService;
2074
- this._imageIoService = _imageIoService;
2075
- this._galleryService = _galleryService;
2076
- this._urlImageService = _urlImageService;
2077
- this._univerInstanceService = _univerInstanceService;
2078
- this._drawingImageClipService = _drawingImageClipService;
1932
+ _initialize() {
1933
+ this._drawingAddListener();
1934
+ this._commandExecutedListener();
1935
+ this._imageUpdateListener();
2079
1936
  }
2080
- async renderImages(imageParam, scene) {
2081
- const { transform: singleTransform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms, adjustValues, hidden } = imageParam;
2082
- if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
2083
- if (!this._drawingManagerService.getDrawingVisible()) return;
2084
- if (this._univerInstanceService.getUnitType(unitId) === _univerjs_core.UniverInstanceType.UNIVER_SHEET && subUnitId !== this._getActiveSheetId()) return;
2085
- if (singleTransform == null) return;
2086
- const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
2087
- const images = [];
2088
- for (const transform of transforms) {
2089
- const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
2090
- const index = transforms.indexOf(transform);
2091
- const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2092
- unitId,
2093
- subUnitId,
2094
- drawingId
2095
- }, isMultiTransform ? index : void 0);
2096
- const imageShape = scene.getObject(imageShapeKey);
2097
- if (imageShape != null) {
2098
- imageShape.transformByState({
2099
- left,
2100
- top,
2101
- width,
2102
- height,
2103
- angle,
2104
- flipX,
2105
- flipY,
2106
- skewX,
2107
- skewY
2108
- });
2109
- continue;
2110
- }
2111
- const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
2112
- const zIndex = orders.indexOf(drawingId);
2113
- const imageConfig = {
2114
- ...transform,
2115
- zIndex: zIndex === -1 ? orders.length - 1 : zIndex
2116
- };
2117
- const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
2118
- let shouldBeCache = false;
2119
- if (imageNativeCache != null) imageConfig.image = imageNativeCache;
2120
- else if (imageSourceType === _univerjs_drawing.ImageSourceType.UUID) try {
2121
- imageConfig.url = await this._imageIoService.getImage(source);
2122
- } catch (error) {
2123
- console.error(error);
2124
- continue;
2125
- }
2126
- else if (imageSourceType === _univerjs_drawing.ImageSourceType.URL) {
2127
- try {
2128
- imageConfig.url = await this._urlImageService.getImage(source);
2129
- } catch (error) {
2130
- console.error(error);
2131
- imageConfig.url = source;
2132
- }
2133
- shouldBeCache = true;
2134
- } else {
2135
- imageConfig.url = source;
2136
- shouldBeCache = true;
1937
+ _commandExecutedListener() {
1938
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1939
+ if (command.id === ImageResetSizeOperation.id) {
1940
+ const params = command.params;
1941
+ if (params == null) return;
1942
+ this._resetImageSize(params);
2137
1943
  }
2138
- if (hidden) imageConfig.visible = false;
2139
- if (scene.getObject(imageShapeKey)) continue;
2140
- imageConfig.printable = true;
2141
- const image = new _univerjs_engine_render.Image(imageShapeKey, imageConfig);
2142
- image.setClipService(this._drawingImageClipService);
2143
- if (shouldBeCache) this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
2144
- scene.addObject(image, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX);
2145
- if (this._drawingManagerService.getDrawingEditable()) scene.attachTransformerTo(image);
2146
- groupId && insertGroupObject({
2147
- drawingId: groupId,
2148
- unitId,
2149
- subUnitId
2150
- }, image, scene, this._drawingManagerService);
2151
- if (prstGeom != null) image.setPrstGeom(prstGeom);
2152
- if (adjustValues != null) image.setPrstGeomAdjValues(adjustValues);
2153
- if (srcRect != null) image.setSrcRect(srcRect);
2154
- images.push(image);
2155
- }
2156
- return images;
1944
+ }));
2157
1945
  }
2158
- _getActiveSheetId() {
2159
- var _this$_univerInstance;
2160
- return (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getActiveSheet()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetId();
1946
+ _getSceneAndTransformerByDrawingSearch(unitId) {
1947
+ if (unitId == null) return;
1948
+ const renderObject = this._renderManagerService.getRenderById(unitId);
1949
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
1950
+ if (scene == null) return null;
1951
+ return {
1952
+ scene,
1953
+ transformer: scene.getTransformerByCreate()
1954
+ };
2161
1955
  }
2162
- renderFloatDom(param, scene) {
2163
- const { transform: singleTransform, drawingType, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms } = param;
2164
- if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_DOM) return;
2165
- if (!this._drawingManagerService.getDrawingVisible()) return;
2166
- if (singleTransform == null) return;
2167
- const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
2168
- const rects = [];
2169
- for (const transform of transforms) {
2170
- const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
2171
- const index = transforms.indexOf(transform);
1956
+ _resetImageSize(params) {
1957
+ const updateParams = [];
1958
+ const sceneList = [];
1959
+ params.forEach((param) => {
1960
+ const { unitId, subUnitId, drawingId } = param;
1961
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
1962
+ if (renderObject == null) return;
1963
+ const { scene } = renderObject;
2172
1964
  const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2173
1965
  unitId,
2174
1966
  subUnitId,
2175
1967
  drawingId
2176
- }, isMultiTransform ? index : void 0);
1968
+ });
2177
1969
  const imageShape = scene.getObject(imageShapeKey);
2178
- if (imageShape != null) {
2179
- imageShape.transformByState({
2180
- left,
2181
- top,
2182
- width,
1970
+ if (imageShape == null) return true;
1971
+ const imageData = this._drawingManagerService.getDrawingByParam(param);
1972
+ if (imageData == null) return true;
1973
+ if (imageData.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
1974
+ imageShape.resetSize();
1975
+ const { width, height } = imageShape.getNativeSize();
1976
+ if (sceneList.includes(scene) === false) sceneList.push(scene);
1977
+ updateParams.push({
1978
+ ...imageData,
1979
+ transform: {
1980
+ ...imageData.transform,
2183
1981
  height,
2184
- angle,
2185
- flipX,
2186
- flipY,
2187
- skewX,
2188
- skewY
2189
- });
2190
- continue;
2191
- }
2192
- const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
2193
- const zIndex = orders.indexOf(drawingId);
2194
- const rectConfig = {
2195
- ...transform,
2196
- zIndex: zIndex === -1 ? orders.length - 1 : zIndex
2197
- };
2198
- if (scene.getObject(imageShapeKey)) continue;
2199
- rectConfig.printable = false;
2200
- const rect = new _univerjs_engine_render.Rect(imageShapeKey, rectConfig);
2201
- if (!this._drawingManagerService.getDrawingVisible()) continue;
2202
- scene.addObject(rect, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX);
2203
- if (this._drawingManagerService.getDrawingEditable() && param.allowTransform !== false) scene.attachTransformerTo(rect);
2204
- groupId && insertGroupObject({
2205
- drawingId: groupId,
2206
- unitId,
2207
- subUnitId
2208
- }, rect, scene, this._drawingManagerService);
2209
- rects.push(rect);
2210
- }
2211
- return rects;
1982
+ width,
1983
+ angle: 0
1984
+ },
1985
+ srcRect: null,
1986
+ prstGeom: null
1987
+ });
1988
+ });
1989
+ this._drawingManagerService.featurePluginUpdateNotification(updateParams);
1990
+ sceneList.forEach((scene) => {
1991
+ scene.getTransformerByCreate().refreshControls().changeNotification();
1992
+ });
1993
+ this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, params);
2212
1994
  }
2213
- renderDrawing(param, scene) {
2214
- const drawingParam = this._drawingManagerService.getDrawingByParam(param);
2215
- if (drawingParam == null) return;
2216
- switch (drawingParam.drawingType) {
2217
- case _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE: return this.renderImages(drawingParam, scene);
2218
- default:
1995
+ _drawingAddListener() {
1996
+ this.disposeWithMe(this._drawingManagerService.add$.pipe((0, rxjs.bufferTime)(33), (0, rxjs.filter)((batches) => batches.length > 0), (0, rxjs.map)((batches) => batches.flat()), (0, rxjs.map)((items) => {
1997
+ const map = /* @__PURE__ */ new Map();
1998
+ for (const it of items) map.set(`${it.unitId}|${it.subUnitId}|${it.drawingId}`, it);
1999
+ return [...map.values()];
2000
+ }), (0, rxjs.filter)((items) => items.length > 0)).subscribe((uniqueParams) => {
2001
+ this._insertImages(uniqueParams);
2002
+ }));
2003
+ }
2004
+ _insertImages(params) {
2005
+ params.forEach(async (param) => {
2006
+ var _getCurrentUnitInfo;
2007
+ const { unitId, subUnitId } = param;
2008
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2009
+ const currentSubUnitId = (_getCurrentUnitInfo = getCurrentUnitInfo(this._currentUniverService, unitId)) === null || _getCurrentUnitInfo === void 0 ? void 0 : _getCurrentUnitInfo.subUnitId;
2010
+ if (renderObject == null || currentSubUnitId !== subUnitId) return;
2011
+ const imageParam = this._drawingManagerService.getDrawingByParam(param);
2012
+ if (imageParam == null) return;
2013
+ const images = await this._drawingRenderService.renderImages(imageParam, renderObject.scene);
2014
+ this._drawingManagerService.refreshTransform([imageParam]);
2015
+ if (images == null || images.length === 0) return;
2016
+ for (const image of images) {
2017
+ this._addHoverForImage(image);
2018
+ this._addDialogForImage(image);
2019
+ }
2020
+ });
2021
+ }
2022
+ _imageUpdateListener() {
2023
+ this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
2024
+ params.forEach((param) => {
2025
+ var _setClipBounds;
2026
+ const { unitId, subUnitId, drawingId } = param;
2027
+ const drawingParam = this._drawingManagerService.getDrawingByParam(param);
2028
+ if (drawingParam == null) return;
2029
+ const { transform, drawingType, srcRect, prstGeom, source, imageSourceType } = drawingParam;
2030
+ if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
2031
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2032
+ if (renderObject == null) return;
2033
+ const { scene, transformer } = renderObject;
2034
+ if (transform == null) return true;
2035
+ const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2036
+ unitId,
2037
+ subUnitId,
2038
+ drawingId
2039
+ });
2040
+ const imageShape = scene.getObject(drawingShapeKey);
2041
+ if (imageShape == null) return true;
2042
+ imageShape.transformByState(transform);
2043
+ (_setClipBounds = imageShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(imageShape, transform.clipBounds);
2044
+ ensureDrawingRenderLayer(scene, imageShape, drawingParam);
2045
+ imageShape.setSrcRect(srcRect);
2046
+ imageShape.setPrstGeom(prstGeom);
2047
+ if (source != null && source.length > 0 && (imageSourceType === _univerjs_core.ImageSourceType.BASE64 || imageSourceType === _univerjs_core.ImageSourceType.URL)) imageShape.changeSource(source);
2048
+ });
2049
+ }));
2050
+ }
2051
+ _addHoverForImage(o) {
2052
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerEnter$.subscribeEvent(() => {
2053
+ o.cursor = _univerjs_engine_render.CURSOR_TYPE.GRAB;
2054
+ })));
2055
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerLeave$.subscribeEvent(() => {
2056
+ o.cursor = _univerjs_engine_render.CURSOR_TYPE.DEFAULT;
2057
+ })));
2058
+ }
2059
+ _addDialogForImage(o) {
2060
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onDblclick$.subscribeEvent(() => {
2061
+ const dialogId = `${o.oKey}-viewer-dialog`;
2062
+ this._drawingRenderService.previewImage(dialogId, o.getNative().src, o.getNativeSize().width, o.getNativeSize().height);
2063
+ })));
2064
+ }
2065
+ };
2066
+ ImageUpdateController = __decorate([
2067
+ __decorateParam(0, _univerjs_core.ICommandService),
2068
+ __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
2069
+ __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
2070
+ __decorateParam(3, _univerjs_ui.IDialogService),
2071
+ __decorateParam(4, _univerjs_drawing.IImageIoService),
2072
+ __decorateParam(5, _univerjs_core.IUniverInstanceService),
2073
+ __decorateParam(6, (0, _univerjs_core.Inject)(DrawingRenderService))
2074
+ ], ImageUpdateController);
2075
+
2076
+ //#endregion
2077
+ //#region src/menu/align.menu.ts
2078
+ const getMenuStateByDrawingFocusChangedObservable$$1 = (accessor) => {
2079
+ const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
2080
+ return new rxjs.Observable((subscriber) => {
2081
+ const update = (drawings) => {
2082
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2083
+ if (drawings.length < 2) return subscriber.next(true);
2084
+ subscriber.next(false);
2085
+ };
2086
+ const subscription = drawingManagerService.focus$.subscribe((drawings) => {
2087
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2088
+ update(drawings);
2089
+ });
2090
+ update(drawingManagerService.getFocusDrawings());
2091
+ return () => subscription.unsubscribe();
2092
+ });
2093
+ };
2094
+ const DRAWING_ALIGN_CONTEXT_MENU_ID = "contextMenu.drawing-align";
2095
+ function DrawingAlignContextMenuItemFactory(accessor) {
2096
+ return {
2097
+ id: DRAWING_ALIGN_CONTEXT_MENU_ID,
2098
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
2099
+ icon: "HorizontallyIcon",
2100
+ title: "drawing-ui.image-panel.align.title",
2101
+ hidden$: getMenuStateByDrawingFocusChangedObservable$$1(accessor)
2102
+ };
2103
+ }
2104
+ function SetDrawingAlignLeftMenuItemFactory() {
2105
+ return {
2106
+ id: SetDrawingAlignLeftOperation.id,
2107
+ type: _univerjs_ui.MenuItemType.BUTTON,
2108
+ icon: "LeftJustifyingIcon",
2109
+ title: "drawing-ui.image-panel.align.left"
2110
+ };
2111
+ }
2112
+ function SetDrawingAlignCenterMenuItemFactory() {
2113
+ return {
2114
+ id: SetDrawingAlignCenterOperation.id,
2115
+ type: _univerjs_ui.MenuItemType.BUTTON,
2116
+ icon: "HorizontallyIcon",
2117
+ title: "drawing-ui.image-panel.align.center"
2118
+ };
2119
+ }
2120
+ function SetDrawingAlignRightMenuItemFactory() {
2121
+ return {
2122
+ id: SetDrawingAlignRightOperation.id,
2123
+ type: _univerjs_ui.MenuItemType.BUTTON,
2124
+ icon: "RightJustifyingIcon",
2125
+ title: "drawing-ui.image-panel.align.right"
2126
+ };
2127
+ }
2128
+ function SetDrawingAlignTopMenuItemFactory() {
2129
+ return {
2130
+ id: SetDrawingAlignTopOperation.id,
2131
+ type: _univerjs_ui.MenuItemType.BUTTON,
2132
+ icon: "AlignTopIcon",
2133
+ title: "drawing-ui.image-panel.align.top"
2134
+ };
2135
+ }
2136
+ function SetDrawingAlignMiddleMenuItemFactory() {
2137
+ return {
2138
+ id: SetDrawingAlignMiddleOperation.id,
2139
+ type: _univerjs_ui.MenuItemType.BUTTON,
2140
+ icon: "VerticalCenterIcon",
2141
+ title: "drawing-ui.image-panel.align.middle"
2142
+ };
2143
+ }
2144
+ function SetDrawingAlignBottomMenuItemFactory() {
2145
+ return {
2146
+ id: SetDrawingAlignBottomOperation.id,
2147
+ type: _univerjs_ui.MenuItemType.BUTTON,
2148
+ icon: "AlignBottomIcon",
2149
+ title: "drawing-ui.image-panel.align.bottom"
2150
+ };
2151
+ }
2152
+ function SetDrawingAlignHorizonMenuItemFactory() {
2153
+ return {
2154
+ id: SetDrawingAlignHorizonOperation.id,
2155
+ type: _univerjs_ui.MenuItemType.BUTTON,
2156
+ icon: "HorizontallyIcon",
2157
+ title: "drawing-ui.image-panel.align.horizon"
2158
+ };
2159
+ }
2160
+ function SetDrawingAlignVerticalMenuItemFactory() {
2161
+ return {
2162
+ id: SetDrawingAlignVerticalOperation.id,
2163
+ type: _univerjs_ui.MenuItemType.BUTTON,
2164
+ icon: "VerticalCenterIcon",
2165
+ title: "drawing-ui.image-panel.align.vertical"
2166
+ };
2167
+ }
2168
+
2169
+ //#endregion
2170
+ //#region src/menu/arrange.menu.ts
2171
+ const DRAWING_ARRANGE_CONTEXT_MENU_ID = "contextMenu.drawing-arrange";
2172
+ function DrawingArrangeContextMenuItemFactory() {
2173
+ return {
2174
+ id: DRAWING_ARRANGE_CONTEXT_MENU_ID,
2175
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
2176
+ icon: "TopmostIcon",
2177
+ title: "drawing-ui.image-panel.arrange.title"
2178
+ };
2179
+ }
2180
+ function SetDrawingArrangeFrontMenuItemFactory() {
2181
+ return {
2182
+ id: SetDrawingArrangeFrontOperation.id,
2183
+ type: _univerjs_ui.MenuItemType.BUTTON,
2184
+ icon: "TopmostIcon",
2185
+ title: "drawing-ui.image-panel.arrange.front"
2186
+ };
2187
+ }
2188
+ function SetDrawingArrangeForwardMenuItemFactory() {
2189
+ return {
2190
+ id: SetDrawingArrangeForwardOperation.id,
2191
+ type: _univerjs_ui.MenuItemType.BUTTON,
2192
+ icon: "MoveUpIcon",
2193
+ title: "drawing-ui.image-panel.arrange.forward"
2194
+ };
2195
+ }
2196
+ function SetDrawingArrangeBackMenuItemFactory() {
2197
+ return {
2198
+ id: SetDrawingArrangeBackOperation.id,
2199
+ type: _univerjs_ui.MenuItemType.BUTTON,
2200
+ icon: "BottomIcon",
2201
+ title: "drawing-ui.image-panel.arrange.back"
2202
+ };
2203
+ }
2204
+ function SetDrawingArrangeBackwardMenuItemFactory() {
2205
+ return {
2206
+ id: SetDrawingArrangeBackwardOperation.id,
2207
+ type: _univerjs_ui.MenuItemType.BUTTON,
2208
+ icon: "MoveDownIcon",
2209
+ title: "drawing-ui.image-panel.arrange.backward"
2210
+ };
2211
+ }
2212
+
2213
+ //#endregion
2214
+ //#region src/menu/group.menu.ts
2215
+ function getMenuStateByDrawingFocusChangedObservable$(accessor, type) {
2216
+ const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
2217
+ return new rxjs.Observable((subscriber) => {
2218
+ const update = (drawings) => {
2219
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2220
+ if (type === "group") {
2221
+ if (drawings.length < 2) return subscriber.next(true);
2222
+ if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
2223
+ } else if (type === "unGroup") {
2224
+ if (drawings.filter((drawing) => drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP).length === 0) return subscriber.next(true);
2225
+ } else if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
2226
+ subscriber.next(false);
2227
+ };
2228
+ const subscription = drawingManagerService.focus$.subscribe((drawings) => {
2229
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2230
+ update(drawings);
2231
+ });
2232
+ update(drawingManagerService.getFocusDrawings());
2233
+ return () => subscription.unsubscribe();
2234
+ });
2235
+ }
2236
+ const DRAWING_GROUP_CONTEXT_MENU_ID = "contextMenu.drawing-group";
2237
+ function DrawingGroupContextMenuItemFactory(accessor) {
2238
+ return {
2239
+ id: DRAWING_GROUP_CONTEXT_MENU_ID,
2240
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
2241
+ icon: "GroupIcon",
2242
+ title: "drawing-ui.image-panel.group.title",
2243
+ hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor)
2244
+ };
2245
+ }
2246
+ function SetDrawingGroupMenuItemFactory(accessor) {
2247
+ return {
2248
+ id: SetDrawingGroupOperation.id,
2249
+ type: _univerjs_ui.MenuItemType.BUTTON,
2250
+ icon: "GroupIcon",
2251
+ title: "drawing-ui.image-panel.group.group",
2252
+ disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "group")
2253
+ };
2254
+ }
2255
+ function CancelDrawingGroupMenuItemFactory(accessor) {
2256
+ return {
2257
+ id: CancelDrawingGroupOperation.id,
2258
+ type: _univerjs_ui.MenuItemType.BUTTON,
2259
+ icon: "UngroupIcon",
2260
+ title: "drawing-ui.image-panel.group.unGroup",
2261
+ disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "unGroup")
2262
+ };
2263
+ }
2264
+
2265
+ //#endregion
2266
+ //#region src/menu/schema.ts
2267
+ const menuSchema = { [_univerjs_ui.ContextMenuPosition.DRAWING]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
2268
+ [DRAWING_GROUP_CONTEXT_MENU_ID]: {
2269
+ order: 1,
2270
+ menuItemFactory: DrawingGroupContextMenuItemFactory,
2271
+ [SetDrawingGroupOperation.id]: {
2272
+ order: 0,
2273
+ menuItemFactory: SetDrawingGroupMenuItemFactory
2274
+ },
2275
+ [CancelDrawingGroupOperation.id]: {
2276
+ order: 1,
2277
+ menuItemFactory: CancelDrawingGroupMenuItemFactory
2278
+ }
2279
+ },
2280
+ [DRAWING_ARRANGE_CONTEXT_MENU_ID]: {
2281
+ order: 2,
2282
+ menuItemFactory: DrawingArrangeContextMenuItemFactory,
2283
+ [SetDrawingArrangeFrontOperation.id]: {
2284
+ order: 0,
2285
+ menuItemFactory: SetDrawingArrangeFrontMenuItemFactory
2286
+ },
2287
+ [SetDrawingArrangeForwardOperation.id]: {
2288
+ order: 1,
2289
+ menuItemFactory: SetDrawingArrangeForwardMenuItemFactory
2290
+ },
2291
+ [SetDrawingArrangeBackOperation.id]: {
2292
+ order: 2,
2293
+ menuItemFactory: SetDrawingArrangeBackMenuItemFactory
2294
+ },
2295
+ [SetDrawingArrangeBackwardOperation.id]: {
2296
+ order: 3,
2297
+ menuItemFactory: SetDrawingArrangeBackwardMenuItemFactory
2298
+ }
2299
+ },
2300
+ [DRAWING_ALIGN_CONTEXT_MENU_ID]: {
2301
+ order: 3,
2302
+ menuItemFactory: DrawingAlignContextMenuItemFactory,
2303
+ [SetDrawingAlignLeftOperation.id]: {
2304
+ order: 0,
2305
+ menuItemFactory: SetDrawingAlignLeftMenuItemFactory
2306
+ },
2307
+ [SetDrawingAlignCenterOperation.id]: {
2308
+ order: 1,
2309
+ menuItemFactory: SetDrawingAlignCenterMenuItemFactory
2310
+ },
2311
+ [SetDrawingAlignRightOperation.id]: {
2312
+ order: 2,
2313
+ menuItemFactory: SetDrawingAlignRightMenuItemFactory
2314
+ },
2315
+ [SetDrawingAlignTopOperation.id]: {
2316
+ order: 3,
2317
+ menuItemFactory: SetDrawingAlignTopMenuItemFactory
2318
+ },
2319
+ [SetDrawingAlignMiddleOperation.id]: {
2320
+ order: 4,
2321
+ menuItemFactory: SetDrawingAlignMiddleMenuItemFactory
2322
+ },
2323
+ [SetDrawingAlignBottomOperation.id]: {
2324
+ order: 5,
2325
+ menuItemFactory: SetDrawingAlignBottomMenuItemFactory
2326
+ },
2327
+ [SetDrawingAlignHorizonOperation.id]: {
2328
+ order: 6,
2329
+ menuItemFactory: SetDrawingAlignHorizonMenuItemFactory
2330
+ },
2331
+ [SetDrawingAlignVerticalOperation.id]: {
2332
+ order: 7,
2333
+ menuItemFactory: SetDrawingAlignVerticalMenuItemFactory
2219
2334
  }
2220
2335
  }
2221
- previewImage(key, src, width, height) {
2222
- this._galleryService.open({
2223
- images: [src],
2224
- onOpenChange: (open) => {
2225
- if (!open) this._galleryService.close();
2226
- }
2227
- });
2228
- }
2229
- _adjustImageSize(nativeWidth, nativeHeight, screenWidth, screenHeight) {
2230
- if (nativeWidth <= screenWidth && nativeHeight <= screenHeight) return {
2231
- width: nativeWidth,
2232
- height: nativeHeight
2233
- };
2234
- const widthRatio = screenWidth / nativeWidth;
2235
- const heightRatio = screenHeight / nativeHeight;
2236
- const scale = Math.min(widthRatio, heightRatio);
2237
- return {
2238
- width: Math.floor(nativeWidth * scale),
2239
- height: Math.floor(nativeHeight * scale)
2240
- };
2241
- }
2242
- };
2243
- DrawingRenderService = __decorate([
2244
- __decorateParam(0, _univerjs_drawing.IDrawingManagerService),
2245
- __decorateParam(1, _univerjs_drawing.IImageIoService),
2246
- __decorateParam(2, _univerjs_ui.IGalleryService),
2247
- __decorateParam(3, _univerjs_core.IURLImageService),
2248
- __decorateParam(4, _univerjs_core.IUniverInstanceService),
2249
- __decorateParam(5, (0, _univerjs_core.Inject)(DrawingImageClipService))
2250
- ], DrawingRenderService);
2336
+ } } };
2251
2337
 
2252
2338
  //#endregion
2253
- //#region src/controllers/image-update.controller.ts
2254
- let ImageUpdateController = class ImageUpdateController extends _univerjs_core.Disposable {
2255
- constructor(_commandService, _renderManagerService, _drawingManagerService, _dialogService, _imageIoService, _currentUniverService, _drawingRenderService) {
2339
+ //#region src/controllers/ui.controller.ts
2340
+ /**
2341
+ * Copyright 2023-present DreamNum Co., Ltd.
2342
+ *
2343
+ * Licensed under the Apache License, Version 2.0 (the "License");
2344
+ * you may not use this file except in compliance with the License.
2345
+ * You may obtain a copy of the License at
2346
+ *
2347
+ * http://www.apache.org/licenses/LICENSE-2.0
2348
+ *
2349
+ * Unless required by applicable law or agreed to in writing, software
2350
+ * distributed under the License is distributed on an "AS IS" BASIS,
2351
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2352
+ * See the License for the specific language governing permissions and
2353
+ * limitations under the License.
2354
+ */
2355
+ let DrawingUIController = class DrawingUIController extends _univerjs_core.Disposable {
2356
+ constructor(_commandService, _menuManagerService) {
2256
2357
  super();
2257
2358
  this._commandService = _commandService;
2258
- this._renderManagerService = _renderManagerService;
2259
- this._drawingManagerService = _drawingManagerService;
2260
- this._dialogService = _dialogService;
2261
- this._imageIoService = _imageIoService;
2262
- this._currentUniverService = _currentUniverService;
2263
- this._drawingRenderService = _drawingRenderService;
2264
- this._initialize();
2265
- }
2266
- dispose() {
2267
- super.dispose();
2268
- }
2269
- _initialize() {
2270
- this._drawingAddListener();
2271
- this._commandExecutedListener();
2272
- this._imageUpdateListener();
2273
- }
2274
- _commandExecutedListener() {
2275
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2276
- if (command.id === ImageResetSizeOperation.id) {
2277
- const params = command.params;
2278
- if (params == null) return;
2279
- this._resetImageSize(params);
2280
- }
2281
- }));
2282
- }
2283
- _getSceneAndTransformerByDrawingSearch(unitId) {
2284
- if (unitId == null) return;
2285
- const renderObject = this._renderManagerService.getRenderById(unitId);
2286
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2287
- if (scene == null) return null;
2288
- return {
2289
- scene,
2290
- transformer: scene.getTransformerByCreate()
2291
- };
2292
- }
2293
- _resetImageSize(params) {
2294
- const updateParams = [];
2295
- const sceneList = [];
2296
- params.forEach((param) => {
2297
- const { unitId, subUnitId, drawingId } = param;
2298
- const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2299
- if (renderObject == null) return;
2300
- const { scene } = renderObject;
2301
- const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2302
- unitId,
2303
- subUnitId,
2304
- drawingId
2305
- });
2306
- const imageShape = scene.getObject(imageShapeKey);
2307
- if (imageShape == null) return true;
2308
- const imageData = this._drawingManagerService.getDrawingByParam(param);
2309
- if (imageData == null) return true;
2310
- if (imageData.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
2311
- imageShape.resetSize();
2312
- const { width, height } = imageShape.getNativeSize();
2313
- if (sceneList.includes(scene) === false) sceneList.push(scene);
2314
- updateParams.push({
2315
- ...imageData,
2316
- transform: {
2317
- ...imageData.transform,
2318
- height,
2319
- width,
2320
- angle: 0
2321
- },
2322
- srcRect: null,
2323
- prstGeom: null
2324
- });
2325
- });
2326
- this._drawingManagerService.featurePluginUpdateNotification(updateParams);
2327
- sceneList.forEach((scene) => {
2328
- scene.getTransformerByCreate().refreshControls().changeNotification();
2329
- });
2330
- this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, params);
2331
- }
2332
- _drawingAddListener() {
2333
- this.disposeWithMe(this._drawingManagerService.add$.pipe((0, rxjs.bufferTime)(33), (0, rxjs.filter)((batches) => batches.length > 0), (0, rxjs.map)((batches) => batches.flat()), (0, rxjs.map)((items) => {
2334
- const map = /* @__PURE__ */ new Map();
2335
- for (const it of items) map.set(`${it.unitId}|${it.subUnitId}|${it.drawingId}`, it);
2336
- return [...map.values()];
2337
- }), (0, rxjs.filter)((items) => items.length > 0)).subscribe((uniqueParams) => {
2338
- this._insertImages(uniqueParams);
2339
- }));
2340
- }
2341
- _insertImages(params) {
2342
- params.forEach(async (param) => {
2343
- var _getCurrentUnitInfo;
2344
- const { unitId, subUnitId } = param;
2345
- const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2346
- const currentSubUnitId = (_getCurrentUnitInfo = getCurrentUnitInfo(this._currentUniverService, unitId)) === null || _getCurrentUnitInfo === void 0 ? void 0 : _getCurrentUnitInfo.subUnitId;
2347
- if (renderObject == null || currentSubUnitId !== subUnitId) return;
2348
- const imageParam = this._drawingManagerService.getDrawingByParam(param);
2349
- if (imageParam == null) return;
2350
- const images = await this._drawingRenderService.renderImages(imageParam, renderObject.scene);
2351
- this._drawingManagerService.refreshTransform([imageParam]);
2352
- if (images == null || images.length === 0) return;
2353
- for (const image of images) {
2354
- this._addHoverForImage(image);
2355
- this._addDialogForImage(image);
2356
- }
2357
- });
2359
+ this._menuManagerService = _menuManagerService;
2360
+ this._init();
2358
2361
  }
2359
- _imageUpdateListener() {
2360
- this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
2361
- params.forEach((param) => {
2362
- const { unitId, subUnitId, drawingId } = param;
2363
- const drawingParam = this._drawingManagerService.getDrawingByParam(param);
2364
- if (drawingParam == null) return;
2365
- const { transform, drawingType, srcRect, prstGeom, source, imageSourceType } = drawingParam;
2366
- if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
2367
- const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2368
- if (renderObject == null) return;
2369
- const { scene, transformer } = renderObject;
2370
- if (transform == null) return true;
2371
- const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2372
- unitId,
2373
- subUnitId,
2374
- drawingId
2375
- });
2376
- const imageShape = scene.getObject(drawingShapeKey);
2377
- if (imageShape == null) return true;
2378
- imageShape.setSrcRect(srcRect);
2379
- imageShape.setPrstGeom(prstGeom);
2380
- if (source != null && source.length > 0 && (imageSourceType === _univerjs_core.ImageSourceType.BASE64 || imageSourceType === _univerjs_core.ImageSourceType.URL)) imageShape.changeSource(source);
2381
- });
2382
- }));
2362
+ _init() {
2363
+ this._initMenus();
2364
+ this._initCommands();
2383
2365
  }
2384
- _addHoverForImage(o) {
2385
- this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerEnter$.subscribeEvent(() => {
2386
- o.cursor = _univerjs_engine_render.CURSOR_TYPE.GRAB;
2387
- })));
2388
- this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerLeave$.subscribeEvent(() => {
2389
- o.cursor = _univerjs_engine_render.CURSOR_TYPE.DEFAULT;
2390
- })));
2366
+ _initMenus() {
2367
+ this._menuManagerService.mergeMenu(menuSchema);
2391
2368
  }
2392
- _addDialogForImage(o) {
2393
- this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onDblclick$.subscribeEvent(() => {
2394
- const dialogId = `${o.oKey}-viewer-dialog`;
2395
- this._drawingRenderService.previewImage(dialogId, o.getNative().src, o.getNativeSize().width, o.getNativeSize().height);
2396
- })));
2369
+ _initCommands() {
2370
+ [
2371
+ OpenImageCropOperation,
2372
+ CloseImageCropOperation,
2373
+ ImageResetSizeOperation,
2374
+ SetDrawingAlignOperation,
2375
+ SetDrawingAlignLeftOperation,
2376
+ SetDrawingAlignCenterOperation,
2377
+ SetDrawingAlignRightOperation,
2378
+ SetDrawingAlignTopOperation,
2379
+ SetDrawingAlignMiddleOperation,
2380
+ SetDrawingAlignBottomOperation,
2381
+ SetDrawingAlignHorizonOperation,
2382
+ SetDrawingAlignVerticalOperation,
2383
+ AutoImageCropOperation,
2384
+ SetDrawingGroupOperation,
2385
+ CancelDrawingGroupOperation,
2386
+ SetDrawingArrangeOperation,
2387
+ SetDrawingArrangeFrontOperation,
2388
+ SetDrawingArrangeForwardOperation,
2389
+ SetDrawingArrangeBackOperation,
2390
+ SetDrawingArrangeBackwardOperation
2391
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
2397
2392
  }
2398
2393
  };
2399
- ImageUpdateController = __decorate([
2400
- __decorateParam(0, _univerjs_core.ICommandService),
2401
- __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
2402
- __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
2403
- __decorateParam(3, _univerjs_ui.IDialogService),
2404
- __decorateParam(4, _univerjs_drawing.IImageIoService),
2405
- __decorateParam(5, _univerjs_core.IUniverInstanceService),
2406
- __decorateParam(6, (0, _univerjs_core.Inject)(DrawingRenderService))
2407
- ], ImageUpdateController);
2394
+ DrawingUIController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, _univerjs_ui.IMenuManagerService)], DrawingUIController);
2408
2395
 
2409
2396
  //#endregion
2410
2397
  //#region src/plugin.ts
@@ -2419,6 +2406,8 @@ let UniverDrawingUIPlugin = class UniverDrawingUIPlugin extends _univerjs_core.P
2419
2406
  this._configService.setConfig(DRAWING_UI_PLUGIN_CONFIG_KEY, rest);
2420
2407
  }
2421
2408
  onStarting() {
2409
+ this._injector.add([ComponentsController]);
2410
+ this._injector.get(ComponentsController);
2422
2411
  this._initDependencies();
2423
2412
  }
2424
2413
  onRendered() {
@@ -2524,11 +2513,11 @@ const DrawingArrange = (props) => {
2524
2513
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2525
2514
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2526
2515
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2527
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
2528
- const MoveUpIcon = componentManager.get("MoveUpIcon");
2529
- const MoveDownIcon = componentManager.get("MoveDownIcon");
2530
- const TopmostIcon = componentManager.get("TopmostIcon");
2531
- const BottomIcon = componentManager.get("BottomIcon");
2516
+ const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
2517
+ const MoveUpIcon = iconManager.get("MoveUpIcon");
2518
+ const MoveDownIcon = iconManager.get("MoveDownIcon");
2519
+ const TopmostIcon = iconManager.get("TopmostIcon");
2520
+ const BottomIcon = iconManager.get("BottomIcon");
2532
2521
  const [drawings, setDrawings] = (0, react.useState)(focusDrawings);
2533
2522
  (0, react.useEffect)(() => {
2534
2523
  const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
@@ -2588,10 +2577,10 @@ const DrawingGroup = (props) => {
2588
2577
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2589
2578
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2590
2579
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2591
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
2580
+ const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
2592
2581
  const { hasGroup, drawings } = props;
2593
- const GroupIcon = componentManager.get("GroupIcon");
2594
- const UngroupIcon = componentManager.get("UngroupIcon");
2582
+ const GroupIcon = iconManager.get("GroupIcon");
2583
+ const UngroupIcon = iconManager.get("UngroupIcon");
2595
2584
  const [groupShow, setGroupShow] = (0, react.useState)(false);
2596
2585
  const [groupBtnShow, setGroupBtnShow] = (0, react.useState)(true);
2597
2586
  const [ungroupBtnShow, setUngroupBtnShow] = (0, react.useState)(true);
@@ -3005,6 +2994,29 @@ const ImageCropper = (props) => {
3005
2994
 
3006
2995
  //#endregion
3007
2996
  //#region src/views/panel/DrawingCommonPanel.tsx
2997
+ function getPanelShowState(drawings) {
2998
+ if (drawings.length === 0) return {
2999
+ arrangeShow: false,
3000
+ transformShow: false,
3001
+ alignShow: false,
3002
+ cropperShow: false,
3003
+ nullShow: true
3004
+ };
3005
+ if (drawings.length === 1) return {
3006
+ arrangeShow: true,
3007
+ transformShow: true,
3008
+ alignShow: false,
3009
+ cropperShow: true,
3010
+ nullShow: false
3011
+ };
3012
+ return {
3013
+ arrangeShow: true,
3014
+ transformShow: false,
3015
+ alignShow: true,
3016
+ cropperShow: false,
3017
+ nullShow: false
3018
+ };
3019
+ }
3008
3020
  const DrawingCommonPanel = (props) => {
3009
3021
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
3010
3022
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
@@ -3017,11 +3029,12 @@ const DrawingCommonPanel = (props) => {
3017
3029
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3018
3030
  if (scene == null) return;
3019
3031
  const transformer = scene.getTransformerByCreate();
3020
- const [arrangeShow, setArrangeShow] = (0, react.useState)(true);
3021
- const [transformShow, setTransformShow] = (0, react.useState)(true);
3022
- const [alignShow, setAlignShow] = (0, react.useState)(false);
3023
- const [cropperShow, setCropperShow] = (0, react.useState)(true);
3024
- const [nullShow, setNullShow] = (0, react.useState)(false);
3032
+ const initialShowState = getPanelShowState(drawings);
3033
+ const [arrangeShow, setArrangeShow] = (0, react.useState)(initialShowState.arrangeShow);
3034
+ const [transformShow, setTransformShow] = (0, react.useState)(initialShowState.transformShow);
3035
+ const [alignShow, setAlignShow] = (0, react.useState)(initialShowState.alignShow);
3036
+ const [cropperShow, setCropperShow] = (0, react.useState)(initialShowState.cropperShow);
3037
+ const [nullShow, setNullShow] = (0, react.useState)(initialShowState.nullShow);
3025
3038
  (0, react.useEffect)(() => {
3026
3039
  const clearControlSub = transformer.clearControl$.subscribe((changeSelf) => {
3027
3040
  if (changeSelf === true) {
@@ -3129,7 +3142,6 @@ Object.defineProperty(exports, 'DrawingRenderService', {
3129
3142
  });
3130
3143
  exports.IMAGE_CLIP_SHAPE_PICKER_COMPONENT = IMAGE_CLIP_SHAPE_PICKER_COMPONENT;
3131
3144
  exports.ImageCropperObject = ImageCropperObject;
3132
- exports.ImagePopupMenu = ImagePopupMenu;
3133
3145
  exports.ImageResetSizeOperation = ImageResetSizeOperation;
3134
3146
  exports.OpenImageCropOperation = OpenImageCropOperation;
3135
3147
  exports.SetDrawingAlignOperation = SetDrawingAlignOperation;