@univerjs/docs-drawing-ui 0.2.6 → 0.2.7

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
@@ -2,14 +2,14 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, ICommandService, IUniverInstanceService, TextX, JSONX, MemoryCursor, TextXActionType, LocaleService, RxDisposable, UniverInstanceType, toDisposable, FOCUSING_COMMON_DRAWINGS, OnLifecycle, LifecycleStages, Inject, IContextService, useDependency, PositionedObjectLayoutType, BooleanNumber, ObjectRelativeFromH, ObjectRelativeFromV, Tools, WrapTextType, Direction, IUndoRedoService, FOCUSING_UNIVER_EDITOR, Disposable, Injector, UndoCommand, RedoCommand, throttle, COLORS, Plugin, DependentOn } from "@univerjs/core";
5
+ import { CommandType, ICommandService, IUniverInstanceService, TextX, JSONX, MemoryCursor, TextXActionType, LocaleService, RxDisposable, UniverInstanceType, toDisposable, FOCUSING_COMMON_DRAWINGS, OnLifecycle, LifecycleStages, Inject, IContextService, useDependency, PositionedObjectLayoutType, BooleanNumber, ObjectRelativeFromH, ObjectRelativeFromV, Tools, WrapTextType, Direction, IUndoRedoService, FOCUSING_UNIVER_EDITOR, Disposable, Injector, fromEventSubject, LifecycleService, UndoCommand, RedoCommand, throttle, COLORS, Plugin, DependentOn } from "@univerjs/core";
6
6
  import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
7
7
  import { IDrawingManagerService, DRAWING_IMAGE_ALLOW_IMAGE_LIST, ArrangeTypeEnum, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, IImageIoService, UniverDrawingPlugin } from "@univerjs/drawing";
8
8
  import { IDocDrawingService, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
9
- import { ITextSelectionRenderManager, IRenderManagerService, DocumentEditArea, Liquid, PageLayoutType, NodePositionConvertToCursor, getOneTextSelectionRange, DocumentSkeletonPageType, Vector2, getAnchorBounding, Rect, getColor, TEXT_RANGE_LAYER_INDEX } from "@univerjs/engine-render";
10
- import { takeUntil, BehaviorSubject } from "rxjs";
9
+ import { ITextSelectionRenderManager, IRenderManagerService, DocumentEditArea, Liquid, TRANSFORM_CHANGE_OBSERVABLE_TYPE, PageLayoutType, NodePositionConvertToCursor, getOneTextSelectionRange, DocumentSkeletonPageType, Vector2, getAnchorBounding, Rect, getColor, TEXT_RANGE_LAYER_INDEX } from "@univerjs/engine-render";
10
+ import { takeUntil, Observable, BehaviorSubject, filter, debounceTime, first } from "rxjs";
11
11
  import { DocCanvasPopManagerService, docDrawingPositionToTransform } from "@univerjs/docs-ui";
12
- import { RichTextEditingMutation, getRichTextEditPath, DocSkeletonManagerService, TextSelectionManagerService, getRetainAndDeleteFromReplace, SetDocZoomRatioOperation, getDocObject } from "@univerjs/docs";
12
+ import { RichTextEditingMutation, getRichTextEditPath, TextSelectionManagerService, DocSkeletonManagerService, getRetainAndDeleteFromReplace, SetDocZoomRatioOperation, getDocObject } from "@univerjs/docs";
13
13
  import { ISidebarService, MenuItemType, MenuPosition, MenuGroup, getMenuHiddenObservable, KeyCode, ComponentManager, IMenuService, IShortcutService, IMessageService, IEditorService } from "@univerjs/ui";
14
14
  import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
15
15
  import clsx from "clsx";
@@ -307,7 +307,30 @@ const InsertDocImageOperation = {
307
307
  multiple: !0
308
308
  }
309
309
  ));
310
- }, "UploadFileMenu"), COMPONENT_DOC_UPLOAD_FILE_MENU = "COMPONENT_DOC_UPLOAD_FILE_MENU", ImageUploadIcon = "addition-and-subtraction-single", IMAGE_MENU_ID = "doc.menu.image", IMAGE_MENU_UPLOAD_FLOAT_ID = "doc.menu.image.upload.float";
310
+ }, "UploadFileMenu"), COMPONENT_DOC_UPLOAD_FILE_MENU = "COMPONENT_DOC_UPLOAD_FILE_MENU", ImageUploadIcon = "addition-and-subtraction-single", IMAGE_MENU_ID = "doc.menu.image", IMAGE_MENU_UPLOAD_FLOAT_ID = "doc.menu.image.upload.float", getDisableWhenSelectionInTableObservable = /* @__PURE__ */ __name((accessor) => {
311
+ const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
312
+ return new Observable((subscriber) => {
313
+ const observable = textSelectionManagerService.textSelection$.subscribe(() => {
314
+ var _a8;
315
+ const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
316
+ if (activeRange) {
317
+ const { segmentId, startOffset, endOffset } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), tables = (_a8 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a8.tables;
318
+ if (tables && tables.length && tables.some((table) => {
319
+ const { startIndex, endIndex } = table;
320
+ return startOffset >= startIndex && startOffset <= endIndex || endOffset >= startIndex && endOffset <= endIndex;
321
+ })) {
322
+ subscriber.next(!0);
323
+ return;
324
+ }
325
+ } else {
326
+ subscriber.next(!0);
327
+ return;
328
+ }
329
+ subscriber.next(!1);
330
+ });
331
+ return () => observable.unsubscribe();
332
+ });
333
+ }, "getDisableWhenSelectionInTableObservable");
311
334
  function ImageMenuFactory(accessor) {
312
335
  return {
313
336
  id: IMAGE_MENU_ID,
@@ -316,6 +339,7 @@ function ImageMenuFactory(accessor) {
316
339
  group: MenuGroup.TOOLBAR_LAYOUT,
317
340
  icon: ImageUploadIcon,
318
341
  tooltip: "docImage.title",
342
+ disabled$: getDisableWhenSelectionInTableObservable(accessor),
319
343
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
320
344
  };
321
345
  }
@@ -653,7 +677,10 @@ const UpdateDocDrawingWrappingStyleCommand = {
653
677
  const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
654
678
  if (documentDataModel == null)
655
679
  return !1;
656
- const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage } = params, rawActions = [], { drawingId } = drawing, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", actions = getDeleteAndInsertCustomBlockActions(
680
+ const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
681
+ if (needRefreshDrawings)
682
+ return docRefreshDrawingsService.refreshDrawings(skeleton), transformer.refreshControls(), !0;
683
+ const rawActions = [], { drawingId } = drawing, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", actions = getDeleteAndInsertCustomBlockActions(
657
684
  newSegmentId,
658
685
  segmentId,
659
686
  segmentPage,
@@ -1252,7 +1279,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
1252
1279
  var _a8, _b;
1253
1280
  if (params == null)
1254
1281
  return !1;
1255
- const commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = textSelectionManagerService.getActiveRange(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
1282
+ const commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
1256
1283
  if (activeTextRange == null || documentDataModel == null)
1257
1284
  return !1;
1258
1285
  const unitId = documentDataModel.getUnitId(), { drawings } = params, { collapsed, startOffset, segmentId } = activeTextRange, body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
@@ -1660,13 +1687,13 @@ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPrope
1660
1687
  return kind && result && __defProp$3(target, key, result), result;
1661
1688
  }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a4;
1662
1689
  let DocDrawingTransformUpdateController = (_a4 = class extends Disposable {
1663
- constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService) {
1690
+ constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
1664
1691
  super();
1665
1692
  __publicField(this, "_liquid", new Liquid());
1666
- this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService, this._commandService = _commandService, this._editorService = _editorService, this._drawingManagerService = _drawingManagerService, this._docRefreshDrawingsService = _docRefreshDrawingsService, this._initialize(), this._commandExecutedListener();
1693
+ this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService, this._commandService = _commandService, this._editorService = _editorService, this._drawingManagerService = _drawingManagerService, this._docRefreshDrawingsService = _docRefreshDrawingsService, this._univerInstanceService = _univerInstanceService, this._lifecycleService = _lifecycleService, this._initialize(), this._commandExecutedListener();
1667
1694
  }
1668
1695
  _initialize() {
1669
- this._initialRenderRefresh();
1696
+ this._initialRenderRefresh(), this._drawingInitializeListener(), this._initResize();
1670
1697
  }
1671
1698
  _initialRenderRefresh() {
1672
1699
  this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
@@ -1695,6 +1722,18 @@ let DocDrawingTransformUpdateController = (_a4 = class extends Disposable {
1695
1722
  })
1696
1723
  );
1697
1724
  }
1725
+ _initResize() {
1726
+ this.disposeWithMe(
1727
+ fromEventSubject(this._context.engine.onTransformChange$).pipe(
1728
+ filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),
1729
+ debounceTime(16)
1730
+ ).subscribe(() => {
1731
+ var _a8;
1732
+ const skeleton = this._docSkeletonManagerService.getSkeleton(), { scene } = this._context;
1733
+ (_a8 = scene.getTransformer()) == null || _a8.refreshControls(), this._refreshDrawing(skeleton);
1734
+ })
1735
+ );
1736
+ }
1698
1737
  _refreshDrawing(skeleton) {
1699
1738
  var _a8, _b;
1700
1739
  const skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData(), { mainComponent, unitId } = this._context, documentComponent = mainComponent;
@@ -1773,13 +1812,25 @@ let DocDrawingTransformUpdateController = (_a4 = class extends Disposable {
1773
1812
  marginLeft
1774
1813
  });
1775
1814
  }
1815
+ _drawingInitializeListener() {
1816
+ this._lifecycleService.lifecycle$.pipe(filter((stage) => stage === LifecycleStages.Steady), first()).subscribe((stage) => {
1817
+ var _a8;
1818
+ const unitId = (_a8 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a8.getUnitId();
1819
+ if (!unitId)
1820
+ return;
1821
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
1822
+ skeleton != null && (this._refreshDrawing(skeleton), this._drawingManagerService.initializeNotification(unitId));
1823
+ });
1824
+ }
1776
1825
  }, __name(_a4, "DocDrawingTransformUpdateController"), _a4);
1777
1826
  DocDrawingTransformUpdateController = __decorateClass$3([
1778
1827
  __decorateParam$3(1, Inject(DocSkeletonManagerService)),
1779
1828
  __decorateParam$3(2, ICommandService),
1780
1829
  __decorateParam$3(3, IEditorService),
1781
1830
  __decorateParam$3(4, IDrawingManagerService),
1782
- __decorateParam$3(5, Inject(DocRefreshDrawingsService))
1831
+ __decorateParam$3(5, Inject(DocRefreshDrawingsService)),
1832
+ __decorateParam$3(6, IUniverInstanceService),
1833
+ __decorateParam$3(7, Inject(LifecycleService))
1783
1834
  ], DocDrawingTransformUpdateController);
1784
1835
  var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1785
1836
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -1909,6 +1960,11 @@ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPrope
1909
1960
  return kind && result && __defProp$1(target, key, result), result;
1910
1961
  }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
1911
1962
  const INLINE_DRAWING_ANCHOR_KEY_PREFIX = "__InlineDrawingAnchor__";
1963
+ function isInTableCell(nodePosition) {
1964
+ const { path } = nodePosition;
1965
+ return path.some((p) => p === "cells");
1966
+ }
1967
+ __name(isInTableCell, "isInTableCell");
1912
1968
  var _a6;
1913
1969
  let DocDrawingTransformerController = (_a6 = class extends Disposable {
1914
1970
  constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService, _textSelectionRenderManager) {
@@ -2102,7 +2158,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2102
2158
  if (glyphAnchor == null)
2103
2159
  return;
2104
2160
  const nodePosition = skeleton == null ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex), docObject = this._getDocObject();
2105
- if (nodePosition == null || skeleton == null || docObject == null)
2161
+ if (nodePosition == null || skeleton == null || docObject == null || isInTableCell(nodePosition))
2106
2162
  return;
2107
2163
  const positionWithIsBack = {
2108
2164
  ...nodePosition,
@@ -2214,7 +2270,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2214
2270
  if (glyphAnchor == null)
2215
2271
  return;
2216
2272
  const nodePosition = skeleton == null ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage), docObject = this._getDocObject();
2217
- if (nodePosition == null || skeleton == null || docObject == null)
2273
+ if (nodePosition == null || skeleton == null || docObject == null || isInTableCell(nodePosition))
2218
2274
  return;
2219
2275
  const positionWithIsBack = {
2220
2276
  ...nodePosition,
@@ -2248,15 +2304,15 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
2248
2304
  // Update inline drawing when use transformer to move it.
2249
2305
  _moveInlineDrawing(drawing, offsetX, offsetY) {
2250
2306
  const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY), { offset, segmentId, segmentPage } = anchor != null ? anchor : {};
2251
- if (offset != null)
2252
- return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
2253
- unitId: drawing.unitId,
2254
- subUnitId: drawing.unitId,
2255
- drawing,
2256
- offset,
2257
- segmentId,
2258
- segmentPage
2259
- });
2307
+ return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
2308
+ unitId: drawing.unitId,
2309
+ subUnitId: drawing.unitId,
2310
+ drawing,
2311
+ offset,
2312
+ segmentId,
2313
+ segmentPage,
2314
+ needRefreshDrawings: offset == null
2315
+ });
2260
2316
  }
2261
2317
  // Limit the drawing to the page area, mainly in the vertical direction,
2262
2318
  // and the upper and lower limits cannot exceed the page margin area.
@@ -2422,10 +2478,12 @@ UniverDocsDrawingUIPlugin = __decorateClass([
2422
2478
  __decorateParam(2, IRenderManagerService)
2423
2479
  ], UniverDocsDrawingUIPlugin);
2424
2480
  export {
2481
+ COMPONENT_DOC_UPLOAD_FILE_MENU,
2425
2482
  ClearDocDrawingTransformerOperation,
2426
2483
  DeleteDocDrawingsCommand,
2427
2484
  EditDocDrawingOperation,
2428
2485
  GroupDocDrawingCommand,
2486
+ IMAGE_MENU_ID,
2429
2487
  InsertDocDrawingCommand,
2430
2488
  InsertDocImageOperation,
2431
2489
  MoveDocDrawingsCommand,
@@ -40,6 +40,7 @@ export interface IMoveInlineDrawingParams {
40
40
  offset: number;
41
41
  segmentId: string;
42
42
  segmentPage: number;
43
+ needRefreshDrawings?: boolean;
43
44
  }
44
45
  /**
45
46
  * The command to move inline drawing.
@@ -1,4 +1,4 @@
1
- import { DocumentDataModel, Disposable, ICommandService } from '@univerjs/core';
1
+ import { DocumentDataModel, Disposable, ICommandService, IUniverInstanceService, LifecycleService } from '@univerjs/core';
2
2
  import { DocSkeletonManagerService } from '@univerjs/docs';
3
3
  import { IDrawingManagerService } from '@univerjs/drawing';
4
4
  import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
@@ -12,12 +12,16 @@ export declare class DocDrawingTransformUpdateController extends Disposable impl
12
12
  private readonly _editorService;
13
13
  private readonly _drawingManagerService;
14
14
  private readonly _docRefreshDrawingsService;
15
+ private _univerInstanceService;
16
+ private _lifecycleService;
15
17
  private _liquid;
16
- constructor(_context: IRenderContext<DocumentDataModel>, _docSkeletonManagerService: DocSkeletonManagerService, _commandService: ICommandService, _editorService: IEditorService, _drawingManagerService: IDrawingManagerService, _docRefreshDrawingsService: DocRefreshDrawingsService);
18
+ constructor(_context: IRenderContext<DocumentDataModel>, _docSkeletonManagerService: DocSkeletonManagerService, _commandService: ICommandService, _editorService: IEditorService, _drawingManagerService: IDrawingManagerService, _docRefreshDrawingsService: DocRefreshDrawingsService, _univerInstanceService: IUniverInstanceService, _lifecycleService: LifecycleService);
17
19
  private _initialize;
18
20
  private _initialRenderRefresh;
19
21
  private _commandExecutedListener;
22
+ private _initResize;
20
23
  private _refreshDrawing;
21
24
  private _handleMultiDrawingsTransform;
22
25
  private _calculateDrawingPosition;
26
+ private _drawingInitializeListener;
23
27
  }
@@ -25,3 +25,5 @@ export { ClearDocDrawingTransformerOperation } from './commands/operations/clear
25
25
  export { EditDocDrawingOperation } from './commands/operations/edit-doc-drawing.operation';
26
26
  export { InsertDocImageOperation } from './commands/operations/insert-image.operation';
27
27
  export { SidebarDocDrawingOperation } from './commands/operations/open-drawing-panel.operation';
28
+ export { IMAGE_MENU_ID } from './views/menu/image.menu';
29
+ export { COMPONENT_DOC_UPLOAD_FILE_MENU } from './views/upload-component/component-name';
@@ -2,5 +2,6 @@ import { IMenuItem } from '@univerjs/ui';
2
2
  import { IAccessor } from '@univerjs/core';
3
3
 
4
4
  export declare const ImageUploadIcon = "addition-and-subtraction-single";
5
+ export declare const IMAGE_MENU_ID = "doc.menu.image";
5
6
  export declare function ImageMenuFactory(accessor: IAccessor): IMenuItem;
6
7
  export declare function UploadFloatImageMenuFactory(_accessor: IAccessor): IMenuItem;