@univerjs/sheets-drawing-ui 0.4.1 → 0.4.2-nightly.202410291606

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, IUndoRedoService, LocaleService, IUniverInstanceService, useDependency, Inject, Injector, IContextService, RxDisposable, UniverInstanceType, connectInjector, toDisposable, FOCUSING_COMMON_DRAWINGS, Disposable, Direction, FOCUSING_FX_BAR_EDITOR, EDITOR_ACTIVATED, Tools, UserManagerService, IPermissionService, Rectangle, DisposableCollection, generateRandomId, DependentOn, Plugin, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
5
+ import { CommandType, ICommandService, IUndoRedoService, LocaleService, IUniverInstanceService, useDependency, Inject, Injector, IContextService, RxDisposable, UniverInstanceType, connectInjector, toDisposable, FOCUSING_COMMON_DRAWINGS, Disposable, Direction, FOCUSING_FX_BAR_EDITOR, EDITOR_ACTIVATED, Tools, UserManagerService, IPermissionService, Rectangle, LifecycleService, LifecycleStages, DisposableCollection, fromEventSubject, generateRandomId, DependentOn, Plugin, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
6
6
  import { IDrawingManagerService, IImageIoService, DrawingTypeEnum, ArrangeTypeEnum, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, getDrawingShapeKeyByDrawingSearch, UniverDrawingPlugin } from "@univerjs/drawing";
7
7
  import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, DrawingRenderService, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
8
- import { IRenderManagerService, precisionTo, getGroupState, transformObjectOutOfGroup, RENDER_CLASS_TYPE, Rect, DRAWING_OBJECT_LAYER_INDEX, SHEET_VIEWPORT_KEY } from "@univerjs/engine-render";
8
+ import { IRenderManagerService, precisionTo, getGroupState, transformObjectOutOfGroup, RENDER_CLASS_TYPE, Rect, ObjectType, DRAWING_OBJECT_LAYER_INDEX, SHEET_VIEWPORT_KEY } from "@univerjs/engine-render";
9
9
  import { ISheetDrawingService, SetDrawingApplyMutation, DrawingApplyType, SheetDrawingAnchorType, UniverSheetsDrawingPlugin } from "@univerjs/sheets-drawing";
10
- import { SheetCanvasPopManagerService, attachRangeWithCoord, ISheetSelectionRenderService, SheetSkeletonManagerService, getCurrentRangeDisable$, COPY_TYPE, PREDEFINED_HOOK_NAME, virtualizeDiscreteRanges, ISheetClipboardService, SheetPrintInterceptorService, SetScrollOperation, SetZoomRatioOperation } from "@univerjs/sheets-ui";
10
+ import { SheetCanvasPopManagerService, attachRangeWithCoord, ISheetSelectionRenderService, SheetSkeletonManagerService, getCurrentRangeDisable$, COPY_TYPE, PREDEFINED_HOOK_NAME, virtualizeDiscreteRanges, ISheetClipboardService, SheetPrintInterceptorService, VIEWPORT_KEY, SetZoomRatioOperation } from "@univerjs/sheets-ui";
11
11
  import { ISidebarService, IUIPartsService, BuiltInUIPart, ILocalFileService, IMessageService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, KeyCode, ComponentManager, IMenuManagerService, IShortcutService, CanvasFloatDomService } from "@univerjs/ui";
12
- import { takeUntil, combineLatest, map, filter, distinctUntilChanged, Subject, BehaviorSubject } from "rxjs";
12
+ import { takeUntil, combineLatest, map, filter, distinctUntilChanged, Subject, take, BehaviorSubject, switchMap } from "rxjs";
13
13
  import { getSheetCommandTarget, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, RangeProtectionPermissionEditPoint, WorkbookViewPermission, WorksheetViewPermission, InsertRowCommand, InsertColCommand, RemoveRowCommand, RemoveColCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, DeltaRowHeightCommand, SetRowHeightCommand, DeltaColumnWidthCommand, SetColWidthCommand, SetRowHiddenCommand, SetSpecificRowsVisibleCommand, SetSpecificColsVisibleCommand, SetColHiddenCommand, MoveColsCommand, MoveRowsCommand, MoveRangeCommand, SetRowVisibleMutation, SetRowHiddenMutation, SetColVisibleMutation, SetColHiddenMutation, SetWorksheetRowHeightMutation, SetWorksheetColWidthMutation, SheetInterceptorService, SetWorksheetActiveOperation, SetFrozenMutation } from "@univerjs/sheets";
14
14
  import React, { useEffect, forwardRef, useRef, createElement, useState } from "react";
15
15
  import { MessageType, RadioGroup, Radio } from "@univerjs/design";
@@ -2182,16 +2182,23 @@ const calcPosition = /* @__PURE__ */ __name((targetObject, currentRender, skelet
2182
2182
  }, "calcPosition");
2183
2183
  var _a9;
2184
2184
  let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
2185
- constructor(_renderManagerService, _univerInstanceService, _commandService, _drawingManagerService, _canvasFloatDomService, _sheetDrawingService) {
2185
+ constructor(_renderManagerService, _univerInstanceService, _commandService, _drawingManagerService, _canvasFloatDomService, _sheetDrawingService, _lifecycleService) {
2186
2186
  super();
2187
2187
  __publicField(this, "_domLayerMap", /* @__PURE__ */ new Map());
2188
2188
  __publicField(this, "_domLayerInfoMap", /* @__PURE__ */ new Map());
2189
2189
  __publicField(this, "_transformChange$", new Subject());
2190
2190
  __publicField(this, "transformChange$", this._transformChange$.asObservable());
2191
+ __publicField(this, "_add$", new Subject());
2192
+ __publicField(this, "add$", this._add$.asObservable());
2191
2193
  __publicField(this, "_remove$", new Subject());
2192
2194
  __publicField(this, "remove$", this._remove$.asObservable());
2193
2195
  __publicField(this, "_hooks", []);
2194
- this._renderManagerService = _renderManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._drawingManagerService = _drawingManagerService, this._canvasFloatDomService = _canvasFloatDomService, this._sheetDrawingService = _sheetDrawingService, this._drawingAddListener(), this._scrollUpdateListener(), this._featureUpdateListener(), this._deleteListener();
2196
+ this._renderManagerService = _renderManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._drawingManagerService = _drawingManagerService, this._canvasFloatDomService = _canvasFloatDomService, this._sheetDrawingService = _sheetDrawingService, this._lifecycleService = _lifecycleService, this._drawingAddListener(), this._featureUpdateListener(), this._deleteListener(), this._bindScrollEvent();
2197
+ }
2198
+ _bindScrollEvent() {
2199
+ this._lifecycleService.lifecycle$.pipe(filter((s) => s === LifecycleStages.Rendered), take(1)).subscribe(() => {
2200
+ this._scrollUpdateListener();
2201
+ });
2195
2202
  }
2196
2203
  _ensureMap(unitId, subUnitId) {
2197
2204
  let unitMap = this._domLayerMap.get(unitId);
@@ -2199,6 +2206,9 @@ let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
2199
2206
  let subUnitMap = unitMap.get(subUnitId);
2200
2207
  return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
2201
2208
  }
2209
+ getFloatDomInfo(id) {
2210
+ return this._domLayerInfoMap.get(id);
2211
+ }
2202
2212
  _getSceneAndTransformerByDrawingSearch(unitId) {
2203
2213
  if (unitId == null)
2204
2214
  return;
@@ -2247,10 +2257,10 @@ let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
2247
2257
  width,
2248
2258
  height,
2249
2259
  zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1
2250
- };
2251
- drawingType === DrawingTypeEnum.DRAWING_CHART && (imageConfig.fill = "white", imageConfig.rotateEnabled = !1);
2260
+ }, isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
2261
+ isChart && (imageConfig.fill = "white", imageConfig.rotateEnabled = !1, data && data.border && (imageConfig.stroke = data.border), imageConfig.paintFirst = "stroke", imageConfig.strokeWidth = 1, imageConfig.borderEnabled = !1);
2252
2262
  const rect = new Rect(rectShapeKey, imageConfig);
2253
- scene.addObject(rect, DRAWING_OBJECT_LAYER_INDEX), floatDomParam.allowTransform !== !1 && scene.attachTransformerTo(rect);
2263
+ isChart && rect.setObjectType(ObjectType.CHART), scene.addObject(rect, DRAWING_OBJECT_LAYER_INDEX), floatDomParam.allowTransform !== !1 && scene.attachTransformerTo(rect);
2254
2264
  const map2 = this._ensureMap(unitId, subUnitId), disposableCollection = new DisposableCollection(), initPosition = calcPosition(rect, renderObject.renderObject, skeleton.skeleton, target.worksheet), position$ = new BehaviorSubject(initPosition), info = {
2255
2265
  dispose: disposableCollection,
2256
2266
  rect,
@@ -2291,26 +2301,47 @@ let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
2291
2301
  });
2292
2302
  });
2293
2303
  })
2304
+ ), this.disposeWithMe(
2305
+ this._drawingManagerService.remove$.subscribe((params) => {
2306
+ params.forEach((param) => {
2307
+ const { unitId, subUnitId, drawingId } = param, rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }), renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2308
+ if (renderObject == null)
2309
+ return;
2310
+ const { transformer, scene } = renderObject, rectShape = scene.getObject(rectShapeKey);
2311
+ rectShape != null && rectShape.oKey && transformer.clearControlByIds([rectShape == null ? void 0 : rectShape.oKey]);
2312
+ });
2313
+ })
2294
2314
  );
2295
2315
  }
2296
2316
  _scrollUpdateListener() {
2297
- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2317
+ const updateSheet = /* @__PURE__ */ __name((unitId, subUnitId) => {
2318
+ var _a11;
2319
+ const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId), map2 = this._ensureMap(unitId, subUnitId), ids = Array.from(map2.keys()), target = getSheetCommandTarget(this._univerInstanceService, { unitId, subUnitId }), skeleton = (_a11 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
2320
+ !renderObject || !target || !skeleton || ids.forEach((id) => {
2321
+ const info = this._domLayerInfoMap.get(id);
2322
+ if (info) {
2323
+ const position = calcPosition(info.rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);
2324
+ info.position$.next(position);
2325
+ }
2326
+ });
2327
+ }, "updateSheet");
2328
+ this.disposeWithMe(
2329
+ this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
2330
+ filter((sheet) => !!sheet),
2331
+ map((sheet) => {
2332
+ const render2 = this._renderManagerService.getRenderById(sheet.getUnitId());
2333
+ return render2 ? { render: render2, unitId: sheet.getUnitId(), subUnitId: sheet.getActiveSheet().getSheetId() } : null;
2334
+ }),
2335
+ filter((render2) => !!render2),
2336
+ switchMap(
2337
+ (render2) => fromEventSubject(render2.render.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(map(() => ({ unitId: render2.unitId, subUnitId: render2.subUnitId })))
2338
+ )
2339
+ ).subscribe(({ unitId, subUnitId }) => {
2340
+ updateSheet(unitId, subUnitId);
2341
+ })
2342
+ ), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2298
2343
  var _a11, _b;
2299
- const updateSheet = /* @__PURE__ */ __name((unitId, subUnitId) => {
2300
- var _a12;
2301
- const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId), map2 = this._ensureMap(unitId, subUnitId), ids = Array.from(map2.keys()), target = getSheetCommandTarget(this._univerInstanceService, { unitId, subUnitId }), skeleton = (_a12 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a12.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
2302
- !renderObject || !target || !skeleton || ids.forEach((id) => {
2303
- const info = this._domLayerInfoMap.get(id);
2304
- if (info) {
2305
- const position = calcPosition(info.rect, renderObject.renderObject, skeleton.skeleton, target.worksheet);
2306
- info.position$.next(position);
2307
- }
2308
- });
2309
- }, "updateSheet");
2310
- if (commandInfo.id === SetScrollOperation.id) {
2311
- const params = commandInfo.params, { unitId, sheetId } = params;
2312
- updateSheet(unitId, sheetId);
2313
- } else if (commandInfo.id === SetZoomRatioOperation.id) {
2344
+ if (commandInfo.id === SetZoomRatioOperation.id) {
2314
2345
  const params = commandInfo.params, { unitId } = params;
2315
2346
  Array.from((_b = (_a11 = this._domLayerMap.get(unitId)) == null ? void 0 : _a11.keys()) != null ? _b : []).forEach((subUnitId) => {
2316
2347
  updateSheet(unitId, subUnitId);
@@ -2372,7 +2403,14 @@ let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
2372
2403
  })
2373
2404
  );
2374
2405
  }
2375
- addFloatDomToPosition(layer, propId) {
2406
+ updateFloatDomProps(unitId, subUnitId, id, props) {
2407
+ const info = this._domLayerInfoMap.get(id), renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
2408
+ if (info && renderObject) {
2409
+ const { scene } = renderObject, rectShapeKey = getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId: id }), rectShape = scene.getObject(rectShapeKey);
2410
+ rectShape && rectShape instanceof Rect && rectShape.setProps(props);
2411
+ }
2412
+ }
2413
+ addFloatDomToPosition(layer, propId, executeCommand = !0) {
2376
2414
  const target = getSheetCommandTarget(this._univerInstanceService, {
2377
2415
  unitId: layer.unitId,
2378
2416
  subUnitId: layer.subUnitId
@@ -2399,14 +2437,15 @@ let SheetCanvasFloatDomManagerService = (_a9 = class extends Disposable {
2399
2437
  data,
2400
2438
  allowTransform
2401
2439
  };
2402
- return this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
2440
+ return executeCommand && this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
2403
2441
  unitId,
2404
2442
  drawings: [sheetDrawingParam]
2405
- }), {
2443
+ }), this._add$.next({ unitId, subUnitId, id }), {
2406
2444
  id,
2407
2445
  dispose: /* @__PURE__ */ __name(() => {
2408
2446
  this._removeDom(id, !0);
2409
- }, "dispose")
2447
+ }, "dispose"),
2448
+ sheetDrawingParam
2410
2449
  };
2411
2450
  }
2412
2451
  _removeDom(id, removeDrawing = !1) {
@@ -2440,7 +2479,8 @@ SheetCanvasFloatDomManagerService = __decorateClass$1([
2440
2479
  __decorateParam$1(2, Inject(ICommandService)),
2441
2480
  __decorateParam$1(3, IDrawingManagerService),
2442
2481
  __decorateParam$1(4, Inject(CanvasFloatDomService)),
2443
- __decorateParam$1(5, ISheetDrawingService)
2482
+ __decorateParam$1(5, ISheetDrawingService),
2483
+ __decorateParam$1(6, Inject(LifecycleService))
2444
2484
  ], SheetCanvasFloatDomManagerService);
2445
2485
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2446
2486
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -1,8 +1,9 @@
1
- import { IDisposable, IPosition, ITransformState, Serializable, Worksheet, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
- import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService } from '@univerjs/engine-render';
1
+ import { IDisposable, IPosition, ITransformState, Serializable, Worksheet, Disposable, ICommandService, IUniverInstanceService, LifecycleService } from '@univerjs/core';
2
+ import { IBoundRectNoAngle, Scene, SpreadsheetSkeleton, IRenderManagerService, Rect } from '@univerjs/engine-render';
3
+ import { ISheetFloatDom, ISheetDrawingService } from '@univerjs/sheets-drawing';
4
+ import { IFloatDomLayout, CanvasFloatDomService } from '@univerjs/ui';
3
5
  import { DrawingTypeEnum, IDrawingManagerService } from '@univerjs/drawing';
4
- import { ISheetDrawingService } from '@univerjs/sheets-drawing';
5
- import { CanvasFloatDomService } from '@univerjs/ui';
6
+ import { BehaviorSubject } from 'rxjs';
6
7
  export interface ICanvasFloatDom {
7
8
  /**
8
9
  * whether allow transform float-dom
@@ -34,6 +35,13 @@ export interface ICanvasFloatDom {
34
35
  */
35
36
  type?: DrawingTypeEnum;
36
37
  }
38
+ interface ICanvasFloatDomInfo {
39
+ position$: BehaviorSubject<IFloatDomLayout>;
40
+ dispose: IDisposable;
41
+ rect: Rect;
42
+ unitId: string;
43
+ subUnitId: string;
44
+ }
37
45
  export declare function transformBound2DOMBound(originBound: IBoundRectNoAngle, scene: Scene, skeleton: SpreadsheetSkeleton, worksheet: Worksheet): {
38
46
  absolute: {
39
47
  left: boolean;
@@ -54,6 +62,7 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
54
62
  private _drawingManagerService;
55
63
  private readonly _canvasFloatDomService;
56
64
  private readonly _sheetDrawingService;
65
+ protected readonly _lifecycleService: LifecycleService;
57
66
  private _domLayerMap;
58
67
  private _domLayerInfoMap;
59
68
  private _transformChange$;
@@ -61,6 +70,13 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
61
70
  id: string;
62
71
  value: ITransformState;
63
72
  }>;
73
+ private _add$;
74
+ add$: import('rxjs').Observable<{
75
+ unitId: string;
76
+ subUnitId: string;
77
+ id: string;
78
+ data?: Record<string, any>;
79
+ }>;
64
80
  private _remove$;
65
81
  remove$: import('rxjs').Observable<{
66
82
  unitId: string;
@@ -68,8 +84,10 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
68
84
  id: string;
69
85
  }>;
70
86
  private _hooks;
71
- constructor(_renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _drawingManagerService: IDrawingManagerService, _canvasFloatDomService: CanvasFloatDomService, _sheetDrawingService: ISheetDrawingService);
87
+ constructor(_renderManagerService: IRenderManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _drawingManagerService: IDrawingManagerService, _canvasFloatDomService: CanvasFloatDomService, _sheetDrawingService: ISheetDrawingService, _lifecycleService: LifecycleService);
88
+ private _bindScrollEvent;
72
89
  private _ensureMap;
90
+ getFloatDomInfo(id: string): ICanvasFloatDomInfo | undefined;
73
91
  private _getSceneAndTransformerByDrawingSearch;
74
92
  private _getFloatDomProps;
75
93
  private _drawingAddListener;
@@ -77,10 +95,13 @@ export declare class SheetCanvasFloatDomManagerService extends Disposable {
77
95
  private _getPosition;
78
96
  private _featureUpdateListener;
79
97
  private _deleteListener;
80
- addFloatDomToPosition(layer: ICanvasFloatDom, propId?: string): {
98
+ updateFloatDomProps(unitId: string, subUnitId: string, id: string, props: Record<string, any>): void;
99
+ addFloatDomToPosition(layer: ICanvasFloatDom, propId?: string, executeCommand?: boolean): {
81
100
  id: string;
82
101
  dispose: () => void;
102
+ sheetDrawingParam: ISheetFloatDom;
83
103
  } | undefined;
84
104
  private _removeDom;
85
105
  addHook(hook: ISheetCanvasFloatDomHook): IDisposable;
86
106
  }
107
+ export {};