@univerjs/drawing-ui 0.25.1 → 1.0.0-alpha.1

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.1";
325
+ var version = "1.0.0-alpha.1";
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,317 @@ 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
+ const { docxHeaderFooterDrawing, layoutType } = imageParam;
738
+ if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
739
+ if (!this._drawingManagerService.getDrawingVisible()) return;
740
+ if (this._univerInstanceService.getUnitType(unitId) === _univerjs_core.UniverInstanceType.UNIVER_SHEET && subUnitId !== this._getActiveSheetId()) return;
741
+ if (singleTransform == null) return;
742
+ const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
743
+ const images = [];
744
+ for (const transform of transforms) {
745
+ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
746
+ const index = transforms.indexOf(transform);
747
+ const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
748
+ unitId,
749
+ subUnitId,
750
+ drawingId
751
+ }, isMultiTransform ? index : void 0);
752
+ const imageShape = scene.getObject(imageShapeKey);
753
+ if (imageShape != null) {
754
+ var _setClipBounds;
755
+ imageShape.transformByState({
756
+ left,
757
+ top,
758
+ width,
759
+ height,
760
+ angle,
761
+ flipX,
762
+ flipY,
763
+ skewX,
764
+ skewY
765
+ });
766
+ (_setClipBounds = imageShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(imageShape, transform.clipBounds);
767
+ if ("hidden" in imageParam) hidden ? imageShape.hide() : imageShape.show();
768
+ ensureDrawingRenderLayer(scene, imageShape, imageParam);
769
+ continue;
770
+ }
771
+ const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
772
+ const zIndex = orders.indexOf(drawingId);
773
+ const imageConfig = {
774
+ ...transform,
775
+ zIndex: zIndex === -1 ? orders.length - 1 : zIndex
776
+ };
777
+ const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
778
+ let shouldBeCache = false;
779
+ if (isRenderableImageCache(imageNativeCache)) imageConfig.image = imageNativeCache;
780
+ else if (imageSourceType === _univerjs_drawing.ImageSourceType.UUID) try {
781
+ imageConfig.url = await this._imageIoService.getImage(source);
782
+ } catch (error) {
783
+ console.error(error);
784
+ continue;
785
+ }
786
+ else if (imageSourceType === _univerjs_drawing.ImageSourceType.URL) {
787
+ try {
788
+ imageConfig.url = await this._urlImageService.getImage(source);
789
+ } catch (error) {
790
+ console.error(error);
791
+ imageConfig.url = source;
792
+ }
793
+ shouldBeCache = true;
794
+ } else {
795
+ imageConfig.url = source;
796
+ shouldBeCache = true;
797
+ }
798
+ const shouldWaitForInlineTransform = docxHeaderFooterDrawing === true && layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE;
799
+ if (hidden || shouldWaitForInlineTransform) imageConfig.visible = false;
800
+ if (scene.getObject(imageShapeKey)) continue;
801
+ imageConfig.printable = true;
802
+ const image = new _univerjs_engine_render.Image(imageShapeKey, imageConfig);
803
+ image.setClipService(this._drawingImageClipService);
804
+ if (shouldBeCache) this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
805
+ scene.addObject(image, getDrawingRenderLayerIndex(imageParam));
806
+ if (this._drawingManagerService.getDrawingEditable()) scene.attachTransformerTo(image);
807
+ groupId && insertGroupObject({
808
+ drawingId: groupId,
809
+ unitId,
810
+ subUnitId
811
+ }, image, scene, this._drawingManagerService);
812
+ if (prstGeom != null) image.setPrstGeom(prstGeom);
813
+ if (adjustValues != null) image.setPrstGeomAdjValues(adjustValues);
814
+ if (srcRect != null) image.setSrcRect(srcRect);
815
+ images.push(image);
816
+ }
817
+ return images;
818
+ }
819
+ _getActiveSheetId() {
820
+ var _this$_univerInstance;
821
+ 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();
822
+ }
823
+ renderFloatDom(param, scene) {
824
+ const { transform: singleTransform, drawingType, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms } = param;
825
+ if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_DOM) return;
826
+ if (!this._drawingManagerService.getDrawingVisible()) return;
827
+ if (singleTransform == null) return;
828
+ const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
829
+ const rects = [];
830
+ for (const transform of transforms) {
831
+ const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
832
+ const index = transforms.indexOf(transform);
833
+ const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
834
+ unitId,
835
+ subUnitId,
836
+ drawingId
837
+ }, isMultiTransform ? index : void 0);
838
+ const imageShape = scene.getObject(imageShapeKey);
839
+ if (imageShape != null) {
840
+ imageShape.transformByState({
841
+ left,
842
+ top,
843
+ width,
844
+ height,
845
+ angle,
846
+ flipX,
847
+ flipY,
848
+ skewX,
849
+ skewY
850
+ });
851
+ continue;
852
+ }
853
+ const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
854
+ const zIndex = orders.indexOf(drawingId);
855
+ const rectConfig = {
856
+ ...transform,
857
+ zIndex: zIndex === -1 ? orders.length - 1 : zIndex
858
+ };
859
+ if (scene.getObject(imageShapeKey)) continue;
860
+ rectConfig.printable = false;
861
+ const rect = new _univerjs_engine_render.Rect(imageShapeKey, rectConfig);
862
+ if (!this._drawingManagerService.getDrawingVisible()) continue;
863
+ scene.addObject(rect, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX);
864
+ if (this._drawingManagerService.getDrawingEditable() && param.allowTransform !== false) scene.attachTransformerTo(rect);
865
+ groupId && insertGroupObject({
866
+ drawingId: groupId,
867
+ unitId,
868
+ subUnitId
869
+ }, rect, scene, this._drawingManagerService);
870
+ rects.push(rect);
871
+ }
872
+ return rects;
873
+ }
874
+ renderDrawing(param, scene) {
875
+ const drawingParam = this._drawingManagerService.getDrawingByParam(param);
876
+ if (drawingParam == null) return;
877
+ switch (drawingParam.drawingType) {
878
+ case _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE: return this.renderImages(drawingParam, scene);
879
+ default:
880
+ }
881
+ }
882
+ previewImage(key, src, width, height) {
883
+ this._galleryService.open({
884
+ images: [src],
885
+ onOpenChange: (open) => {
886
+ if (!open) this._galleryService.close();
887
+ }
1001
888
  });
1002
889
  }
890
+ _adjustImageSize(nativeWidth, nativeHeight, screenWidth, screenHeight) {
891
+ if (nativeWidth <= screenWidth && nativeHeight <= screenHeight) return {
892
+ width: nativeWidth,
893
+ height: nativeHeight
894
+ };
895
+ const widthRatio = screenWidth / nativeWidth;
896
+ const heightRatio = screenHeight / nativeHeight;
897
+ const scale = Math.min(widthRatio, heightRatio);
898
+ return {
899
+ width: Math.floor(nativeWidth * scale),
900
+ height: Math.floor(nativeHeight * scale)
901
+ };
902
+ }
1003
903
  };
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);
904
+ DrawingRenderService = __decorate([
905
+ __decorateParam(0, _univerjs_drawing.IDrawingManagerService),
906
+ __decorateParam(1, _univerjs_drawing.IImageIoService),
907
+ __decorateParam(2, _univerjs_ui.IGalleryService),
908
+ __decorateParam(3, _univerjs_core.IURLImageService),
909
+ __decorateParam(4, _univerjs_core.IUniverInstanceService),
910
+ __decorateParam(5, (0, _univerjs_core.Inject)(DrawingImageClipService))
911
+ ], DrawingRenderService);
1009
912
 
1010
913
  //#endregion
1011
914
  //#region src/utils/get-update-params.ts
@@ -1039,49 +942,19 @@ function getUpdateParams(objects, drawingManagerService) {
1039
942
  }
1040
943
 
1041
944
  //#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);
945
+ //#region src/controllers/drawing-update.controller.ts
946
+ function syncDrawingHiddenState(shape, drawingParam) {
947
+ if (!("hidden" in drawingParam)) return;
948
+ drawingParam.hidden === true ? shape.hide() : shape.show();
1063
949
  }
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 + "";
950
+ function mergeRefreshMetadata(drawingParam, refreshParam) {
951
+ const metadata = refreshParam;
952
+ if (!("hidden" in metadata) && !("behindText" in metadata)) return drawingParam;
953
+ return {
954
+ ...drawingParam,
955
+ ...metadata
956
+ };
1070
957
  }
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
958
  let DrawingUpdateController = class DrawingUpdateController extends _univerjs_core.Disposable {
1086
959
  constructor(_currentUniverService, _commandService, _renderManagerService, _drawingManagerService) {
1087
960
  super();
@@ -1415,7 +1288,7 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1415
1288
  _drawingUpdateListener() {
1416
1289
  this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
1417
1290
  params.forEach((param) => {
1418
- var _scene$getTransformer2;
1291
+ var _setClipBounds, _scene$getTransformer2;
1419
1292
  const { unitId, subUnitId, drawingId } = param;
1420
1293
  const drawingParam = this._drawingManagerService.getDrawingByParam(param);
1421
1294
  if (drawingParam == null) return;
@@ -1443,6 +1316,9 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1443
1316
  skewX,
1444
1317
  skewY
1445
1318
  });
1319
+ (_setClipBounds = drawingShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(drawingShape, transform.clipBounds);
1320
+ syncDrawingHiddenState(drawingShape, drawingParam);
1321
+ ensureDrawingRenderLayer(scene, drawingShape, drawingParam);
1446
1322
  (_scene$getTransformer2 = scene.getTransformer()) === null || _scene$getTransformer2 === void 0 || _scene$getTransformer2.debounceRefreshControls();
1447
1323
  });
1448
1324
  }));
@@ -1450,6 +1326,7 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1450
1326
  _drawingRefreshListener() {
1451
1327
  this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe((params) => {
1452
1328
  params.forEach((param) => {
1329
+ var _setClipBounds2;
1453
1330
  const { unitId, subUnitId, drawingId } = param;
1454
1331
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
1455
1332
  if (renderObject == null) return;
@@ -1457,13 +1334,23 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1457
1334
  if (drawingParam == null) return;
1458
1335
  const { transform } = drawingParam;
1459
1336
  const { scene } = renderObject;
1337
+ if (transform == null) return true;
1460
1338
  const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
1461
1339
  unitId,
1462
1340
  subUnitId,
1463
1341
  drawingId
1464
1342
  });
1465
1343
  const drawingShape = scene.getObject(drawingShapeKey);
1466
- if (drawingShape == null || transform == null) return true;
1344
+ const drawingParamWithRefreshMetadata = mergeRefreshMetadata(drawingParam, param);
1345
+ if (drawingShape == null) {
1346
+ if (drawingParamWithRefreshMetadata.hidden === true) return true;
1347
+ this._drawingManagerService.addNotification([{
1348
+ unitId,
1349
+ subUnitId,
1350
+ drawingId
1351
+ }]);
1352
+ return true;
1353
+ }
1467
1354
  const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
1468
1355
  drawingShape.transformByState({
1469
1356
  left,
@@ -1476,6 +1363,9 @@ let DrawingUpdateController = class DrawingUpdateController extends _univerjs_co
1476
1363
  skewX,
1477
1364
  skewY
1478
1365
  });
1366
+ (_setClipBounds2 = drawingShape.setClipBounds) === null || _setClipBounds2 === void 0 || _setClipBounds2.call(drawingShape, transform.clipBounds);
1367
+ syncDrawingHiddenState(drawingShape, drawingParamWithRefreshMetadata);
1368
+ ensureDrawingRenderLayer(scene, drawingShape, drawingParamWithRefreshMetadata);
1479
1369
  });
1480
1370
  }));
1481
1371
  }
@@ -2025,386 +1915,485 @@ ImageCropperController = __decorate([
2025
1915
  ], ImageCropperController);
2026
1916
 
2027
1917
  //#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() {
1918
+ //#region src/controllers/image-update.controller.ts
1919
+ let ImageUpdateController = class ImageUpdateController extends _univerjs_core.Disposable {
1920
+ constructor(_commandService, _renderManagerService, _drawingManagerService, _dialogService, _imageIoService, _currentUniverService, _drawingRenderService) {
2039
1921
  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;
1922
+ this._commandService = _commandService;
1923
+ this._renderManagerService = _renderManagerService;
1924
+ this._drawingManagerService = _drawingManagerService;
1925
+ this._dialogService = _dialogService;
1926
+ this._imageIoService = _imageIoService;
1927
+ this._currentUniverService = _currentUniverService;
1928
+ this._drawingRenderService = _drawingRenderService;
1929
+ this._initialize();
2061
1930
  }
2062
1931
  dispose() {
2063
- this._clipDelegate = null;
2064
- this._canUseShapeClip$.complete();
2065
1932
  super.dispose();
2066
1933
  }
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;
1934
+ _initialize() {
1935
+ this._drawingAddListener();
1936
+ this._commandExecutedListener();
1937
+ this._imageUpdateListener();
2079
1938
  }
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;
1939
+ _commandExecutedListener() {
1940
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1941
+ if (command.id === ImageResetSizeOperation.id) {
1942
+ const params = command.params;
1943
+ if (params == null) return;
1944
+ this._resetImageSize(params);
2137
1945
  }
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;
1946
+ }));
2157
1947
  }
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();
1948
+ _getSceneAndTransformerByDrawingSearch(unitId) {
1949
+ if (unitId == null) return;
1950
+ const renderObject = this._renderManagerService.getRenderById(unitId);
1951
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
1952
+ if (scene == null) return null;
1953
+ return {
1954
+ scene,
1955
+ transformer: scene.getTransformerByCreate()
1956
+ };
2161
1957
  }
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);
1958
+ _resetImageSize(params) {
1959
+ const updateParams = [];
1960
+ const sceneList = [];
1961
+ params.forEach((param) => {
1962
+ const { unitId, subUnitId, drawingId } = param;
1963
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
1964
+ if (renderObject == null) return;
1965
+ const { scene } = renderObject;
2172
1966
  const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2173
1967
  unitId,
2174
1968
  subUnitId,
2175
1969
  drawingId
2176
- }, isMultiTransform ? index : void 0);
1970
+ });
2177
1971
  const imageShape = scene.getObject(imageShapeKey);
2178
- if (imageShape != null) {
2179
- imageShape.transformByState({
2180
- left,
2181
- top,
2182
- width,
1972
+ if (imageShape == null) return true;
1973
+ const imageData = this._drawingManagerService.getDrawingByParam(param);
1974
+ if (imageData == null) return true;
1975
+ if (imageData.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
1976
+ imageShape.resetSize();
1977
+ const { width, height } = imageShape.getNativeSize();
1978
+ if (sceneList.includes(scene) === false) sceneList.push(scene);
1979
+ updateParams.push({
1980
+ ...imageData,
1981
+ transform: {
1982
+ ...imageData.transform,
2183
1983
  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;
1984
+ width,
1985
+ angle: 0
1986
+ },
1987
+ srcRect: null,
1988
+ prstGeom: null
1989
+ });
1990
+ });
1991
+ this._drawingManagerService.featurePluginUpdateNotification(updateParams);
1992
+ sceneList.forEach((scene) => {
1993
+ scene.getTransformerByCreate().refreshControls().changeNotification();
1994
+ });
1995
+ this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, params);
2212
1996
  }
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:
1997
+ _drawingAddListener() {
1998
+ 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) => {
1999
+ const map = /* @__PURE__ */ new Map();
2000
+ for (const it of items) map.set(`${it.unitId}|${it.subUnitId}|${it.drawingId}`, it);
2001
+ return [...map.values()];
2002
+ }), (0, rxjs.filter)((items) => items.length > 0)).subscribe((uniqueParams) => {
2003
+ this._insertImages(uniqueParams);
2004
+ }));
2005
+ }
2006
+ _insertImages(params) {
2007
+ params.forEach(async (param) => {
2008
+ var _getCurrentUnitInfo;
2009
+ const { unitId, subUnitId } = param;
2010
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2011
+ const currentSubUnitId = (_getCurrentUnitInfo = getCurrentUnitInfo(this._currentUniverService, unitId)) === null || _getCurrentUnitInfo === void 0 ? void 0 : _getCurrentUnitInfo.subUnitId;
2012
+ if (renderObject == null || currentSubUnitId !== subUnitId) return;
2013
+ const imageParam = this._drawingManagerService.getDrawingByParam(param);
2014
+ if (imageParam == null) return;
2015
+ const images = await this._drawingRenderService.renderImages(imageParam, renderObject.scene);
2016
+ this._drawingManagerService.refreshTransform([imageParam]);
2017
+ if (images == null || images.length === 0) return;
2018
+ for (const image of images) {
2019
+ this._addHoverForImage(image);
2020
+ this._addDialogForImage(image);
2021
+ }
2022
+ });
2023
+ }
2024
+ _imageUpdateListener() {
2025
+ this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
2026
+ params.forEach((param) => {
2027
+ var _setClipBounds;
2028
+ const { unitId, subUnitId, drawingId } = param;
2029
+ const drawingParam = this._drawingManagerService.getDrawingByParam(param);
2030
+ if (drawingParam == null) return;
2031
+ const { transform, drawingType, srcRect, prstGeom, source, imageSourceType } = drawingParam;
2032
+ if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
2033
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2034
+ if (renderObject == null) return;
2035
+ const { scene, transformer } = renderObject;
2036
+ if (transform == null) return true;
2037
+ const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
2038
+ unitId,
2039
+ subUnitId,
2040
+ drawingId
2041
+ });
2042
+ const imageShape = scene.getObject(drawingShapeKey);
2043
+ if (imageShape == null) return true;
2044
+ imageShape.transformByState(transform);
2045
+ (_setClipBounds = imageShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(imageShape, transform.clipBounds);
2046
+ ensureDrawingRenderLayer(scene, imageShape, drawingParam);
2047
+ imageShape.setSrcRect(srcRect);
2048
+ imageShape.setPrstGeom(prstGeom);
2049
+ if (source != null && source.length > 0 && (imageSourceType === _univerjs_core.ImageSourceType.BASE64 || imageSourceType === _univerjs_core.ImageSourceType.URL)) imageShape.changeSource(source);
2050
+ });
2051
+ }));
2052
+ }
2053
+ _addHoverForImage(o) {
2054
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerEnter$.subscribeEvent(() => {
2055
+ o.cursor = _univerjs_engine_render.CURSOR_TYPE.GRAB;
2056
+ })));
2057
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerLeave$.subscribeEvent(() => {
2058
+ o.cursor = _univerjs_engine_render.CURSOR_TYPE.DEFAULT;
2059
+ })));
2060
+ }
2061
+ _addDialogForImage(o) {
2062
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onDblclick$.subscribeEvent(() => {
2063
+ const dialogId = `${o.oKey}-viewer-dialog`;
2064
+ this._drawingRenderService.previewImage(dialogId, o.getNative().src, o.getNativeSize().width, o.getNativeSize().height);
2065
+ })));
2066
+ }
2067
+ };
2068
+ ImageUpdateController = __decorate([
2069
+ __decorateParam(0, _univerjs_core.ICommandService),
2070
+ __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
2071
+ __decorateParam(2, _univerjs_drawing.IDrawingManagerService),
2072
+ __decorateParam(3, _univerjs_ui.IDialogService),
2073
+ __decorateParam(4, _univerjs_drawing.IImageIoService),
2074
+ __decorateParam(5, _univerjs_core.IUniverInstanceService),
2075
+ __decorateParam(6, (0, _univerjs_core.Inject)(DrawingRenderService))
2076
+ ], ImageUpdateController);
2077
+
2078
+ //#endregion
2079
+ //#region src/menu/align.menu.ts
2080
+ const getMenuStateByDrawingFocusChangedObservable$$1 = (accessor) => {
2081
+ const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
2082
+ return new rxjs.Observable((subscriber) => {
2083
+ const update = (drawings) => {
2084
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2085
+ if (drawings.length < 2) return subscriber.next(true);
2086
+ subscriber.next(false);
2087
+ };
2088
+ const subscription = drawingManagerService.focus$.subscribe((drawings) => {
2089
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2090
+ update(drawings);
2091
+ });
2092
+ update(drawingManagerService.getFocusDrawings());
2093
+ return () => subscription.unsubscribe();
2094
+ });
2095
+ };
2096
+ const DRAWING_ALIGN_CONTEXT_MENU_ID = "contextMenu.drawing-align";
2097
+ function DrawingAlignContextMenuItemFactory(accessor) {
2098
+ return {
2099
+ id: DRAWING_ALIGN_CONTEXT_MENU_ID,
2100
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
2101
+ icon: "HorizontallyIcon",
2102
+ title: "drawing-ui.image-panel.align.title",
2103
+ hidden$: getMenuStateByDrawingFocusChangedObservable$$1(accessor)
2104
+ };
2105
+ }
2106
+ function SetDrawingAlignLeftMenuItemFactory() {
2107
+ return {
2108
+ id: SetDrawingAlignLeftOperation.id,
2109
+ type: _univerjs_ui.MenuItemType.BUTTON,
2110
+ icon: "LeftJustifyingIcon",
2111
+ title: "drawing-ui.image-panel.align.left"
2112
+ };
2113
+ }
2114
+ function SetDrawingAlignCenterMenuItemFactory() {
2115
+ return {
2116
+ id: SetDrawingAlignCenterOperation.id,
2117
+ type: _univerjs_ui.MenuItemType.BUTTON,
2118
+ icon: "HorizontallyIcon",
2119
+ title: "drawing-ui.image-panel.align.center"
2120
+ };
2121
+ }
2122
+ function SetDrawingAlignRightMenuItemFactory() {
2123
+ return {
2124
+ id: SetDrawingAlignRightOperation.id,
2125
+ type: _univerjs_ui.MenuItemType.BUTTON,
2126
+ icon: "RightJustifyingIcon",
2127
+ title: "drawing-ui.image-panel.align.right"
2128
+ };
2129
+ }
2130
+ function SetDrawingAlignTopMenuItemFactory() {
2131
+ return {
2132
+ id: SetDrawingAlignTopOperation.id,
2133
+ type: _univerjs_ui.MenuItemType.BUTTON,
2134
+ icon: "AlignTopIcon",
2135
+ title: "drawing-ui.image-panel.align.top"
2136
+ };
2137
+ }
2138
+ function SetDrawingAlignMiddleMenuItemFactory() {
2139
+ return {
2140
+ id: SetDrawingAlignMiddleOperation.id,
2141
+ type: _univerjs_ui.MenuItemType.BUTTON,
2142
+ icon: "VerticalCenterIcon",
2143
+ title: "drawing-ui.image-panel.align.middle"
2144
+ };
2145
+ }
2146
+ function SetDrawingAlignBottomMenuItemFactory() {
2147
+ return {
2148
+ id: SetDrawingAlignBottomOperation.id,
2149
+ type: _univerjs_ui.MenuItemType.BUTTON,
2150
+ icon: "AlignBottomIcon",
2151
+ title: "drawing-ui.image-panel.align.bottom"
2152
+ };
2153
+ }
2154
+ function SetDrawingAlignHorizonMenuItemFactory() {
2155
+ return {
2156
+ id: SetDrawingAlignHorizonOperation.id,
2157
+ type: _univerjs_ui.MenuItemType.BUTTON,
2158
+ icon: "HorizontallyIcon",
2159
+ title: "drawing-ui.image-panel.align.horizon"
2160
+ };
2161
+ }
2162
+ function SetDrawingAlignVerticalMenuItemFactory() {
2163
+ return {
2164
+ id: SetDrawingAlignVerticalOperation.id,
2165
+ type: _univerjs_ui.MenuItemType.BUTTON,
2166
+ icon: "VerticalCenterIcon",
2167
+ title: "drawing-ui.image-panel.align.vertical"
2168
+ };
2169
+ }
2170
+
2171
+ //#endregion
2172
+ //#region src/menu/arrange.menu.ts
2173
+ const DRAWING_ARRANGE_CONTEXT_MENU_ID = "contextMenu.drawing-arrange";
2174
+ function DrawingArrangeContextMenuItemFactory() {
2175
+ return {
2176
+ id: DRAWING_ARRANGE_CONTEXT_MENU_ID,
2177
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
2178
+ icon: "TopmostIcon",
2179
+ title: "drawing-ui.image-panel.arrange.title"
2180
+ };
2181
+ }
2182
+ function SetDrawingArrangeFrontMenuItemFactory() {
2183
+ return {
2184
+ id: SetDrawingArrangeFrontOperation.id,
2185
+ type: _univerjs_ui.MenuItemType.BUTTON,
2186
+ icon: "TopmostIcon",
2187
+ title: "drawing-ui.image-panel.arrange.front"
2188
+ };
2189
+ }
2190
+ function SetDrawingArrangeForwardMenuItemFactory() {
2191
+ return {
2192
+ id: SetDrawingArrangeForwardOperation.id,
2193
+ type: _univerjs_ui.MenuItemType.BUTTON,
2194
+ icon: "MoveUpIcon",
2195
+ title: "drawing-ui.image-panel.arrange.forward"
2196
+ };
2197
+ }
2198
+ function SetDrawingArrangeBackMenuItemFactory() {
2199
+ return {
2200
+ id: SetDrawingArrangeBackOperation.id,
2201
+ type: _univerjs_ui.MenuItemType.BUTTON,
2202
+ icon: "BottomIcon",
2203
+ title: "drawing-ui.image-panel.arrange.back"
2204
+ };
2205
+ }
2206
+ function SetDrawingArrangeBackwardMenuItemFactory() {
2207
+ return {
2208
+ id: SetDrawingArrangeBackwardOperation.id,
2209
+ type: _univerjs_ui.MenuItemType.BUTTON,
2210
+ icon: "MoveDownIcon",
2211
+ title: "drawing-ui.image-panel.arrange.backward"
2212
+ };
2213
+ }
2214
+
2215
+ //#endregion
2216
+ //#region src/menu/group.menu.ts
2217
+ function getMenuStateByDrawingFocusChangedObservable$(accessor, type) {
2218
+ const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
2219
+ return new rxjs.Observable((subscriber) => {
2220
+ const update = (drawings) => {
2221
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2222
+ if (type === "group") {
2223
+ if (drawings.length < 2) return subscriber.next(true);
2224
+ if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
2225
+ } else if (type === "unGroup") {
2226
+ if (drawings.filter((drawing) => drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP).length === 0) return subscriber.next(true);
2227
+ } else if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
2228
+ subscriber.next(false);
2229
+ };
2230
+ const subscription = drawingManagerService.focus$.subscribe((drawings) => {
2231
+ if (!drawings || drawings.length === 0) return subscriber.next(true);
2232
+ update(drawings);
2233
+ });
2234
+ update(drawingManagerService.getFocusDrawings());
2235
+ return () => subscription.unsubscribe();
2236
+ });
2237
+ }
2238
+ const DRAWING_GROUP_CONTEXT_MENU_ID = "contextMenu.drawing-group";
2239
+ function DrawingGroupContextMenuItemFactory(accessor) {
2240
+ return {
2241
+ id: DRAWING_GROUP_CONTEXT_MENU_ID,
2242
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
2243
+ icon: "GroupIcon",
2244
+ title: "drawing-ui.image-panel.group.title",
2245
+ hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor)
2246
+ };
2247
+ }
2248
+ function SetDrawingGroupMenuItemFactory(accessor) {
2249
+ return {
2250
+ id: SetDrawingGroupOperation.id,
2251
+ type: _univerjs_ui.MenuItemType.BUTTON,
2252
+ icon: "GroupIcon",
2253
+ title: "drawing-ui.image-panel.group.group",
2254
+ disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "group")
2255
+ };
2256
+ }
2257
+ function CancelDrawingGroupMenuItemFactory(accessor) {
2258
+ return {
2259
+ id: CancelDrawingGroupOperation.id,
2260
+ type: _univerjs_ui.MenuItemType.BUTTON,
2261
+ icon: "UngroupIcon",
2262
+ title: "drawing-ui.image-panel.group.unGroup",
2263
+ disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "unGroup")
2264
+ };
2265
+ }
2266
+
2267
+ //#endregion
2268
+ //#region src/menu/schema.ts
2269
+ const menuSchema = { [_univerjs_ui.ContextMenuPosition.DRAWING]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
2270
+ [DRAWING_GROUP_CONTEXT_MENU_ID]: {
2271
+ order: 1,
2272
+ menuItemFactory: DrawingGroupContextMenuItemFactory,
2273
+ [SetDrawingGroupOperation.id]: {
2274
+ order: 0,
2275
+ menuItemFactory: SetDrawingGroupMenuItemFactory
2276
+ },
2277
+ [CancelDrawingGroupOperation.id]: {
2278
+ order: 1,
2279
+ menuItemFactory: CancelDrawingGroupMenuItemFactory
2280
+ }
2281
+ },
2282
+ [DRAWING_ARRANGE_CONTEXT_MENU_ID]: {
2283
+ order: 2,
2284
+ menuItemFactory: DrawingArrangeContextMenuItemFactory,
2285
+ [SetDrawingArrangeFrontOperation.id]: {
2286
+ order: 0,
2287
+ menuItemFactory: SetDrawingArrangeFrontMenuItemFactory
2288
+ },
2289
+ [SetDrawingArrangeForwardOperation.id]: {
2290
+ order: 1,
2291
+ menuItemFactory: SetDrawingArrangeForwardMenuItemFactory
2292
+ },
2293
+ [SetDrawingArrangeBackOperation.id]: {
2294
+ order: 2,
2295
+ menuItemFactory: SetDrawingArrangeBackMenuItemFactory
2296
+ },
2297
+ [SetDrawingArrangeBackwardOperation.id]: {
2298
+ order: 3,
2299
+ menuItemFactory: SetDrawingArrangeBackwardMenuItemFactory
2300
+ }
2301
+ },
2302
+ [DRAWING_ALIGN_CONTEXT_MENU_ID]: {
2303
+ order: 3,
2304
+ menuItemFactory: DrawingAlignContextMenuItemFactory,
2305
+ [SetDrawingAlignLeftOperation.id]: {
2306
+ order: 0,
2307
+ menuItemFactory: SetDrawingAlignLeftMenuItemFactory
2308
+ },
2309
+ [SetDrawingAlignCenterOperation.id]: {
2310
+ order: 1,
2311
+ menuItemFactory: SetDrawingAlignCenterMenuItemFactory
2312
+ },
2313
+ [SetDrawingAlignRightOperation.id]: {
2314
+ order: 2,
2315
+ menuItemFactory: SetDrawingAlignRightMenuItemFactory
2316
+ },
2317
+ [SetDrawingAlignTopOperation.id]: {
2318
+ order: 3,
2319
+ menuItemFactory: SetDrawingAlignTopMenuItemFactory
2320
+ },
2321
+ [SetDrawingAlignMiddleOperation.id]: {
2322
+ order: 4,
2323
+ menuItemFactory: SetDrawingAlignMiddleMenuItemFactory
2324
+ },
2325
+ [SetDrawingAlignBottomOperation.id]: {
2326
+ order: 5,
2327
+ menuItemFactory: SetDrawingAlignBottomMenuItemFactory
2328
+ },
2329
+ [SetDrawingAlignHorizonOperation.id]: {
2330
+ order: 6,
2331
+ menuItemFactory: SetDrawingAlignHorizonMenuItemFactory
2332
+ },
2333
+ [SetDrawingAlignVerticalOperation.id]: {
2334
+ order: 7,
2335
+ menuItemFactory: SetDrawingAlignVerticalMenuItemFactory
2219
2336
  }
2220
2337
  }
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);
2338
+ } } };
2251
2339
 
2252
2340
  //#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) {
2341
+ //#region src/controllers/ui.controller.ts
2342
+ /**
2343
+ * Copyright 2023-present DreamNum Co., Ltd.
2344
+ *
2345
+ * Licensed under the Apache License, Version 2.0 (the "License");
2346
+ * you may not use this file except in compliance with the License.
2347
+ * You may obtain a copy of the License at
2348
+ *
2349
+ * http://www.apache.org/licenses/LICENSE-2.0
2350
+ *
2351
+ * Unless required by applicable law or agreed to in writing, software
2352
+ * distributed under the License is distributed on an "AS IS" BASIS,
2353
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2354
+ * See the License for the specific language governing permissions and
2355
+ * limitations under the License.
2356
+ */
2357
+ let DrawingUIController = class DrawingUIController extends _univerjs_core.Disposable {
2358
+ constructor(_commandService, _menuManagerService) {
2256
2359
  super();
2257
2360
  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
- });
2361
+ this._menuManagerService = _menuManagerService;
2362
+ this._init();
2358
2363
  }
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
- }));
2364
+ _init() {
2365
+ this._initMenus();
2366
+ this._initCommands();
2383
2367
  }
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
- })));
2368
+ _initMenus() {
2369
+ this._menuManagerService.mergeMenu(menuSchema);
2391
2370
  }
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
- })));
2371
+ _initCommands() {
2372
+ [
2373
+ OpenImageCropOperation,
2374
+ CloseImageCropOperation,
2375
+ ImageResetSizeOperation,
2376
+ SetDrawingAlignOperation,
2377
+ SetDrawingAlignLeftOperation,
2378
+ SetDrawingAlignCenterOperation,
2379
+ SetDrawingAlignRightOperation,
2380
+ SetDrawingAlignTopOperation,
2381
+ SetDrawingAlignMiddleOperation,
2382
+ SetDrawingAlignBottomOperation,
2383
+ SetDrawingAlignHorizonOperation,
2384
+ SetDrawingAlignVerticalOperation,
2385
+ AutoImageCropOperation,
2386
+ SetDrawingGroupOperation,
2387
+ CancelDrawingGroupOperation,
2388
+ SetDrawingArrangeOperation,
2389
+ SetDrawingArrangeFrontOperation,
2390
+ SetDrawingArrangeForwardOperation,
2391
+ SetDrawingArrangeBackOperation,
2392
+ SetDrawingArrangeBackwardOperation
2393
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
2397
2394
  }
2398
2395
  };
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);
2396
+ DrawingUIController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, _univerjs_ui.IMenuManagerService)], DrawingUIController);
2408
2397
 
2409
2398
  //#endregion
2410
2399
  //#region src/plugin.ts
@@ -2419,6 +2408,8 @@ let UniverDrawingUIPlugin = class UniverDrawingUIPlugin extends _univerjs_core.P
2419
2408
  this._configService.setConfig(DRAWING_UI_PLUGIN_CONFIG_KEY, rest);
2420
2409
  }
2421
2410
  onStarting() {
2411
+ this._injector.add([ComponentsController]);
2412
+ this._injector.get(ComponentsController);
2422
2413
  this._initDependencies();
2423
2414
  }
2424
2415
  onRendered() {
@@ -2524,11 +2515,11 @@ const DrawingArrange = (props) => {
2524
2515
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2525
2516
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2526
2517
  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");
2518
+ const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
2519
+ const MoveUpIcon = iconManager.get("MoveUpIcon");
2520
+ const MoveDownIcon = iconManager.get("MoveDownIcon");
2521
+ const TopmostIcon = iconManager.get("TopmostIcon");
2522
+ const BottomIcon = iconManager.get("BottomIcon");
2532
2523
  const [drawings, setDrawings] = (0, react.useState)(focusDrawings);
2533
2524
  (0, react.useEffect)(() => {
2534
2525
  const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
@@ -2588,10 +2579,10 @@ const DrawingGroup = (props) => {
2588
2579
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2589
2580
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
2590
2581
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2591
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
2582
+ const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
2592
2583
  const { hasGroup, drawings } = props;
2593
- const GroupIcon = componentManager.get("GroupIcon");
2594
- const UngroupIcon = componentManager.get("UngroupIcon");
2584
+ const GroupIcon = iconManager.get("GroupIcon");
2585
+ const UngroupIcon = iconManager.get("UngroupIcon");
2595
2586
  const [groupShow, setGroupShow] = (0, react.useState)(false);
2596
2587
  const [groupBtnShow, setGroupBtnShow] = (0, react.useState)(true);
2597
2588
  const [ungroupBtnShow, setUngroupBtnShow] = (0, react.useState)(true);
@@ -3005,6 +2996,29 @@ const ImageCropper = (props) => {
3005
2996
 
3006
2997
  //#endregion
3007
2998
  //#region src/views/panel/DrawingCommonPanel.tsx
2999
+ function getPanelShowState(drawings) {
3000
+ if (drawings.length === 0) return {
3001
+ arrangeShow: false,
3002
+ transformShow: false,
3003
+ alignShow: false,
3004
+ cropperShow: false,
3005
+ nullShow: true
3006
+ };
3007
+ if (drawings.length === 1) return {
3008
+ arrangeShow: true,
3009
+ transformShow: true,
3010
+ alignShow: false,
3011
+ cropperShow: true,
3012
+ nullShow: false
3013
+ };
3014
+ return {
3015
+ arrangeShow: true,
3016
+ transformShow: false,
3017
+ alignShow: true,
3018
+ cropperShow: false,
3019
+ nullShow: false
3020
+ };
3021
+ }
3008
3022
  const DrawingCommonPanel = (props) => {
3009
3023
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
3010
3024
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
@@ -3017,11 +3031,12 @@ const DrawingCommonPanel = (props) => {
3017
3031
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3018
3032
  if (scene == null) return;
3019
3033
  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);
3034
+ const initialShowState = getPanelShowState(drawings);
3035
+ const [arrangeShow, setArrangeShow] = (0, react.useState)(initialShowState.arrangeShow);
3036
+ const [transformShow, setTransformShow] = (0, react.useState)(initialShowState.transformShow);
3037
+ const [alignShow, setAlignShow] = (0, react.useState)(initialShowState.alignShow);
3038
+ const [cropperShow, setCropperShow] = (0, react.useState)(initialShowState.cropperShow);
3039
+ const [nullShow, setNullShow] = (0, react.useState)(initialShowState.nullShow);
3025
3040
  (0, react.useEffect)(() => {
3026
3041
  const clearControlSub = transformer.clearControl$.subscribe((changeSelf) => {
3027
3042
  if (changeSelf === true) {
@@ -3129,7 +3144,6 @@ Object.defineProperty(exports, 'DrawingRenderService', {
3129
3144
  });
3130
3145
  exports.IMAGE_CLIP_SHAPE_PICKER_COMPONENT = IMAGE_CLIP_SHAPE_PICKER_COMPONENT;
3131
3146
  exports.ImageCropperObject = ImageCropperObject;
3132
- exports.ImagePopupMenu = ImagePopupMenu;
3133
3147
  exports.ImageResetSizeOperation = ImageResetSizeOperation;
3134
3148
  exports.OpenImageCropOperation = OpenImageCropOperation;
3135
3149
  exports.SetDrawingAlignOperation = SetDrawingAlignOperation;