@univerjs/drawing-ui 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { ArrangeTypeEnum, BooleanNumber, CommandType, DependentOn, Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, IUniverInstanceService, ImageSourceType, Inject, Injector, LocaleService, Plugin, PositionedObjectLayoutType, ThemeService, UniverInstanceType, checkIfMove, debounce, generateRandomId, merge, toDisposable } from "@univerjs/core";
2
- import { DRAWING_GROUPABLE_TYPES, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingShapeKeyByDrawingSearch, isGroupableDrawingType, resolveDrawingRotateEnabled } from "@univerjs/drawing";
2
+ import { DRAWING_GROUPABLE_TYPES, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingShapeKeyByDrawingSearch, isGroupableDrawingType, normalizeImageOpacity, resolveDrawingRotateEnabled } from "@univerjs/drawing";
3
3
  import { CURSOR_TYPE, Canvas, DRAWING_OBJECT_LAYER_INDEX, DrawingGroupObject, Group, IRenderManagerService, Image as Image$1, RENDER_CLASS_TYPE, Rect, Shape, UniverRenderEnginePlugin, Vector2, degToRad, getGroupState, precisionTo, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { BuiltInUIPart, ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, IGalleryService, ILayoutService, IMenuManagerService, IMessageService, IShortcutService, IUIPartsService, IconManager, KeyCode, MenuItemType, MobileMenu, connectInjector, useDependency, useObservable } from "@univerjs/ui";
5
5
  import { BehaviorSubject, Observable, bufferTime, combineLatest, filter, map, merge as merge$1, of, startWith, switchMap } from "rxjs";
6
6
  import { ArrowDownIcon, ArrowUpIcon, AutofillDoubleIcon, BottomIcon, ChartIcon, CheckMarkIcon, CloseIcon, CreateCopyIcon, CropIcon, DeleteIcon, DocSettingIcon, ExpandIcon, EyeIcon, EyelashIcon, GroupIcon, LocateFixedIcon, LockIcon, MoreDownIcon, MoveDownIcon, MoveUpIcon, TextWrapShapeIcon, TopmostIcon, UngroupIcon, UnlockIcon } from "@univerjs/icons";
7
- import { Button, Checkbox, Dropdown, DropdownMenu, Input, InputNumber, MessageType, MobileActionRow, MobileSelect, Select, Separator, StateIconButton, Tooltip, borderClassName, clsx, render, unmount } from "@univerjs/design";
7
+ import { Button, Checkbox, Dropdown, DropdownMenu, Input, InputNumber, MessageType, MobileActionRow, MobileSelect, Select, Separator, StateIconButton, Textarea, Tooltip, borderClassName, clsx, render, unmount } from "@univerjs/design";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { createElement, useEffect, useMemo, useRef, useState } from "react";
10
10
 
@@ -650,7 +650,7 @@ const menuSchema = { [ContextMenuPosition.DRAWING]: { [ContextMenuGroup.OTHERS]:
650
650
  //#endregion
651
651
  //#region package.json
652
652
  var name = "@univerjs/drawing-ui";
653
- var version = "1.0.3";
653
+ var version = "1.1.0";
654
654
 
655
655
  //#endregion
656
656
  //#region src/config/config.ts
@@ -659,7 +659,7 @@ const configSymbol = Symbol(DRAWING_UI_PLUGIN_CONFIG_KEY);
659
659
  const defaultPluginConfig = {};
660
660
 
661
661
  //#endregion
662
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
662
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
663
663
  function _typeof(o) {
664
664
  "@babel/helpers - typeof";
665
665
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -670,7 +670,7 @@ function _typeof(o) {
670
670
  }
671
671
 
672
672
  //#endregion
673
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
673
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
674
674
  function toPrimitive(t, r) {
675
675
  if ("object" != _typeof(t) || !t) return t;
676
676
  var e = t[Symbol.toPrimitive];
@@ -683,14 +683,14 @@ function toPrimitive(t, r) {
683
683
  }
684
684
 
685
685
  //#endregion
686
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
686
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
687
687
  function toPropertyKey(t) {
688
688
  var i = toPrimitive(t, "string");
689
689
  return "symbol" == _typeof(i) ? i : i + "";
690
690
  }
691
691
 
692
692
  //#endregion
693
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
693
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
694
694
  function _defineProperty(e, r, t) {
695
695
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
696
696
  value: t,
@@ -743,7 +743,7 @@ var DrawingImageClipService = class extends Disposable {
743
743
  };
744
744
 
745
745
  //#endregion
746
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
746
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
747
747
  function __decorateParam(paramIndex, decorator) {
748
748
  return function(target, key) {
749
749
  decorator(target, key, paramIndex);
@@ -751,7 +751,7 @@ function __decorateParam(paramIndex, decorator) {
751
751
  }
752
752
 
753
753
  //#endregion
754
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
754
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
755
755
  function __decorate(decorators, target, key, desc) {
756
756
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
757
757
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -784,7 +784,7 @@ let DrawingRenderService = class DrawingRenderService {
784
784
  this._drawingImageClipService = _drawingImageClipService;
785
785
  }
786
786
  async renderImages(imageParam, scene, options) {
787
- const { transform: singleTransform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms, adjustValues, hidden } = imageParam;
787
+ const { transform: singleTransform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms, adjustValues, hidden, opacity } = imageParam;
788
788
  const { docxHeaderFooterDrawing, layoutType } = imageParam;
789
789
  if (drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return;
790
790
  if (!this._drawingManagerService.getDrawingVisible()) return;
@@ -815,6 +815,7 @@ let DrawingRenderService = class DrawingRenderService {
815
815
  skewY
816
816
  });
817
817
  (_setClipBounds = imageShape.setClipBounds) === null || _setClipBounds === void 0 || _setClipBounds.call(imageShape, transform.clipBounds);
818
+ if (this._univerInstanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET || opacity !== void 0) imageShape.setOpacity(normalizeImageOpacity(opacity));
818
819
  if ("hidden" in imageParam) hidden ? imageShape.hide() : imageShape.show();
819
820
  ensureDrawingRenderLayer(scene, imageShape, imageParam);
820
821
  continue;
@@ -823,6 +824,7 @@ let DrawingRenderService = class DrawingRenderService {
823
824
  const zIndex = orders.indexOf(drawingId);
824
825
  const imageConfig = {
825
826
  ...transform,
827
+ opacity: normalizeImageOpacity(opacity),
826
828
  zIndex: zIndex === -1 ? orders.length - 1 : zIndex
827
829
  };
828
830
  const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
@@ -1297,12 +1299,12 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1297
1299
  subUnitId,
1298
1300
  drawingId
1299
1301
  });
1300
- const drawingShapes = scene.fuzzyMathObjects(oKey, true);
1301
- if (drawingShapes == null || drawingShapes.length === 0) return;
1302
+ const drawingObjects = scene.fuzzyMathObjects(oKey, true);
1303
+ if (drawingObjects.length === 0) return;
1302
1304
  const index = this._drawingManagerService.getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
1303
- for (const shape of drawingShapes) {
1304
- shape.setProps({ zIndex: index });
1305
- shape.makeDirty();
1305
+ for (const object of drawingObjects) {
1306
+ object.zIndex = index;
1307
+ object.makeDirty();
1306
1308
  }
1307
1309
  });
1308
1310
  }
@@ -1337,6 +1339,14 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1337
1339
  if (disposeDrawingRenderObject(scene, param)) {
1338
1340
  var _scene$getTransformer2;
1339
1341
  (_scene$getTransformer2 = scene.getTransformer()) === null || _scene$getTransformer2 === void 0 || _scene$getTransformer2.clearSelectedObjects();
1342
+ } else {
1343
+ const transformer = scene.getTransformer();
1344
+ const key = getDrawingShapeKeyByDrawingSearch(param);
1345
+ const selectedKeys = [...(transformer === null || transformer === void 0 ? void 0 : transformer.getSelectedObjectMap().keys()) ?? []].filter((selectedKey) => selectedKey === key || selectedKey.startsWith(`${key}#-#`));
1346
+ if (selectedKeys.length > 0) {
1347
+ if (selectedKeys.length === (transformer === null || transformer === void 0 ? void 0 : transformer.getSelectedObjectMap().size)) transformer.clearSelectedObjects();
1348
+ else transformer === null || transformer === void 0 || transformer.clearControlByIds(selectedKeys);
1349
+ }
1340
1350
  }
1341
1351
  });
1342
1352
  }));
@@ -1383,7 +1393,6 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1383
1393
  _drawingRefreshListener() {
1384
1394
  this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe((params) => {
1385
1395
  params.forEach((param) => {
1386
- var _setClipBounds2;
1387
1396
  const { unitId, subUnitId, drawingId } = param;
1388
1397
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
1389
1398
  if (renderObject == null) return;
@@ -1392,38 +1401,44 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1392
1401
  const { transform } = drawingParam;
1393
1402
  const { scene } = renderObject;
1394
1403
  if (transform == null) return true;
1395
- const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
1396
- unitId,
1397
- subUnitId,
1398
- drawingId
1399
- });
1400
- const drawingShape = scene.getObjectIncludeInGroup(drawingShapeKey);
1401
1404
  const drawingParamWithRefreshMetadata = mergeRefreshMetadata(drawingParam, param);
1402
- if (drawingShape == null) {
1403
- if (drawingParamWithRefreshMetadata.hidden === true) return true;
1404
- this._drawingManagerService.addNotification([{
1405
+ const isMultiTransform = drawingParam.isMultiTransform === BooleanNumber.TRUE;
1406
+ const transforms = isMultiTransform ? drawingParam.transforms ?? [] : [transform];
1407
+ let hasMissingShape = false;
1408
+ transforms.forEach((instanceTransform, index) => {
1409
+ var _setClipBounds2;
1410
+ const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
1405
1411
  unitId,
1406
1412
  subUnitId,
1407
1413
  drawingId
1408
- }]);
1409
- return true;
1410
- }
1411
- const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
1412
- drawingShape.transformByState({
1413
- left,
1414
- top,
1415
- width,
1416
- height,
1417
- angle,
1418
- flipX,
1419
- flipY,
1420
- skewX,
1421
- skewY
1414
+ }, isMultiTransform ? index : void 0);
1415
+ const drawingShape = scene.getObjectIncludeInGroup(drawingShapeKey);
1416
+ if (drawingShape == null) {
1417
+ hasMissingShape = true;
1418
+ return;
1419
+ }
1420
+ const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = instanceTransform;
1421
+ drawingShape.transformByState({
1422
+ left,
1423
+ top,
1424
+ width,
1425
+ height,
1426
+ angle,
1427
+ flipX,
1428
+ flipY,
1429
+ skewX,
1430
+ skewY
1431
+ });
1432
+ (_setClipBounds2 = drawingShape.setClipBounds) === null || _setClipBounds2 === void 0 || _setClipBounds2.call(drawingShape, instanceTransform.clipBounds);
1433
+ syncDrawingHiddenState(drawingShape, drawingParamWithRefreshMetadata);
1434
+ syncDrawingSelectableState(drawingShape, drawingParamWithRefreshMetadata, scene, this._drawingManagerService);
1435
+ ensureDrawingRenderLayer(scene, drawingShape, drawingParamWithRefreshMetadata);
1422
1436
  });
1423
- (_setClipBounds2 = drawingShape.setClipBounds) === null || _setClipBounds2 === void 0 || _setClipBounds2.call(drawingShape, transform.clipBounds);
1424
- syncDrawingHiddenState(drawingShape, drawingParamWithRefreshMetadata);
1425
- syncDrawingSelectableState(drawingShape, drawingParamWithRefreshMetadata, scene, this._drawingManagerService);
1426
- ensureDrawingRenderLayer(scene, drawingShape, drawingParamWithRefreshMetadata);
1437
+ if (hasMissingShape && drawingParamWithRefreshMetadata.hidden !== true) this._drawingManagerService.addNotification([{
1438
+ unitId,
1439
+ subUnitId,
1440
+ drawingId
1441
+ }]);
1427
1442
  });
1428
1443
  }));
1429
1444
  }
@@ -3274,14 +3289,20 @@ function ToolbarGroup(props) {
3274
3289
  });
3275
3290
  }
3276
3291
  function ToolbarButton(props) {
3292
+ const [tooltipVisible, setTooltipVisible] = useState(false);
3277
3293
  return /* @__PURE__ */ jsx(Tooltip, {
3278
3294
  className: "univer-fill-mode-backwards univer-delay-100",
3279
3295
  title: props.title,
3280
3296
  placement: "bottom",
3297
+ visible: tooltipVisible,
3298
+ onVisibleChange: setTooltipVisible,
3281
3299
  children: /* @__PURE__ */ jsx("button", {
3282
3300
  type: "button",
3283
3301
  disabled: props.disabled,
3284
- onClick: props.onClick,
3302
+ onClick: () => {
3303
+ setTooltipVisible(false);
3304
+ props.onClick();
3305
+ },
3285
3306
  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 }),
3286
3307
  children: props.children
3287
3308
  })
@@ -3289,10 +3310,14 @@ function ToolbarButton(props) {
3289
3310
  }
3290
3311
  function ToolbarDropdownButton(props) {
3291
3312
  const [open, setOpen] = useState(false);
3313
+ const [tooltipVisible, setTooltipVisible] = useState(false);
3292
3314
  const activeOption = props.options.find((option) => option.value === props.value) ?? props.options[0];
3293
3315
  return /* @__PURE__ */ jsx(Dropdown, {
3294
3316
  open,
3295
- onOpenChange: setOpen,
3317
+ onOpenChange: (open) => {
3318
+ setOpen(open);
3319
+ if (open) setTooltipVisible(false);
3320
+ },
3296
3321
  overlay: /* @__PURE__ */ jsx("div", {
3297
3322
  className: "univer-min-w-32 univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-p-1 univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
3298
3323
  children: props.options.map((option) => /* @__PURE__ */ jsxs("button", {
@@ -3315,6 +3340,8 @@ function ToolbarDropdownButton(props) {
3315
3340
  className: "univer-fill-mode-backwards univer-delay-100",
3316
3341
  title: props.title,
3317
3342
  placement: "bottom",
3343
+ visible: tooltipVisible && !open,
3344
+ onVisibleChange: (visible) => setTooltipVisible(visible && !open),
3318
3345
  children: /* @__PURE__ */ jsxs("button", {
3319
3346
  type: "button",
3320
3347
  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 }),
@@ -4438,7 +4465,7 @@ let ImageUpdateController = class ImageUpdateController extends Disposable {
4438
4465
  const { unitId, subUnitId, drawingId } = param;
4439
4466
  const drawingParam = this._drawingManagerService.getDrawingByParam(param);
4440
4467
  if (drawingParam == null) return;
4441
- const { transform, drawingType, srcRect, prstGeom, source, imageSourceType } = drawingParam;
4468
+ const { transform, drawingType, srcRect, prstGeom, source, imageSourceType, opacity } = drawingParam;
4442
4469
  if (drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return;
4443
4470
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
4444
4471
  if (renderObject == null) return;
@@ -4467,6 +4494,7 @@ let ImageUpdateController = class ImageUpdateController extends Disposable {
4467
4494
  ensureDrawingRenderLayer(scene, imageShape, drawingParam);
4468
4495
  imageShape.setSrcRect(srcRect);
4469
4496
  imageShape.setPrstGeom(prstGeom);
4497
+ syncImageOpacity(imageShape, opacity, this._currentUniverService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET);
4470
4498
  if (source != null && source.length > 0 && (imageSourceType === ImageSourceType.BASE64 || imageSourceType === ImageSourceType.URL)) imageShape.changeSource(source);
4471
4499
  });
4472
4500
  }));
@@ -4494,6 +4522,9 @@ ImageUpdateController = __decorate([
4494
4522
  __decorateParam(3, IUniverInstanceService),
4495
4523
  __decorateParam(4, Inject(DrawingRenderService))
4496
4524
  ], ImageUpdateController);
4525
+ function syncImageOpacity(image, opacity, isSheet) {
4526
+ if (isSheet || opacity !== void 0) image.setOpacity(normalizeImageOpacity(opacity));
4527
+ }
4497
4528
 
4498
4529
  //#endregion
4499
4530
  //#region src/controllers/ui.controller.ts
@@ -5249,8 +5280,8 @@ function ObjectDetailsEditor(props) {
5249
5280
  children: [/* @__PURE__ */ jsx("span", {
5250
5281
  className: "univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",
5251
5282
  children: labels.description
5252
- }), /* @__PURE__ */ jsx("textarea", {
5253
- className: clsx(descriptionClassName, "univer-box-border univer-min-h-16 univer-w-full univer-resize-none univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-p-2 univer-text-sm univer-text-gray-900 univer-outline-none focus:univer-border-primary-500 focus:univer-ring-1 focus:univer-ring-primary-100 disabled:univer-cursor-not-allowed disabled:univer-opacity-70 dark:!univer-border-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-gray-100 dark:focus:!univer-ring-primary-900"),
5283
+ }), /* @__PURE__ */ jsx(Textarea, {
5284
+ className: clsx("univer-min-h-16 univer-resize-none univer-text-sm", descriptionClassName),
5254
5285
  value: draftDescription,
5255
5286
  disabled,
5256
5287
  placeholder: labels.descriptionPlaceholder,
@@ -34,7 +34,7 @@ export { getUpdateParams } from './utils/get-update-params';
34
34
  export { getImageCropRect } from './utils/image-crop-transform';
35
35
  export { ImageCropperObject } from './views/crop/image-cropper-object';
36
36
  export { COMPONENT_IMAGE_POPUP_MENU, COMPONENT_MOBILE_IMAGE_POPUP_MENU, } from './views/image-popup-menu/component-name';
37
- export type { IImagePopupMenuItem } from './views/image-popup-menu/ImagePopupMenu';
37
+ export type { IImagePopupMenuItem, IImagePopupMenuProps } from './views/image-popup-menu/ImagePopupMenu';
38
38
  export { MobileObjectListPanel } from './views/object-list-panel/MobileObjectListPanel';
39
39
  export { getObjectListPanelSectionIdForDrawingType, isFloatingObjectListDrawingType, OBJECT_LIST_CANVAS_SECTION_ID, OBJECT_LIST_FLOATING_SECTION_ID, } from './views/object-list-panel/object-list-panel-layer';
40
40
  export type { ObjectListPanelSectionId } from './views/object-list-panel/object-list-panel-layer';