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

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