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

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