@univerjs/docs-drawing-ui 0.2.8 → 0.2.10

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
@@ -9,7 +9,7 @@ import { IDocDrawingService, UniverDocsDrawingPlugin } from "@univerjs/docs-draw
9
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
10
  import { takeUntil, Observable, BehaviorSubject, filter, debounceTime } from "rxjs";
11
11
  import { DocCanvasPopManagerService, docDrawingPositionToTransform } from "@univerjs/docs-ui";
12
- import { RichTextEditingMutation, getRichTextEditPath, TextSelectionManagerService, DocSkeletonManagerService, getRetainAndDeleteFromReplace, SetDocZoomRatioOperation, getDocObject } from "@univerjs/docs";
12
+ import { RichTextEditingMutation, getRichTextEditPath, TextSelectionManagerService, DocSkeletonManagerService, getRetainAndDeleteFromReplace, getCustomBlockIdsInSelections, 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";
@@ -1276,7 +1276,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
1276
1276
  type: CommandType.COMMAND,
1277
1277
  // eslint-disable-next-line max-lines-per-function
1278
1278
  handler: /* @__PURE__ */ __name((accessor, params) => {
1279
- var _a8, _b;
1279
+ var _a8, _b, _c, _d;
1280
1280
  if (params == null)
1281
1281
  return !1;
1282
1282
  const commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
@@ -1286,6 +1286,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
1286
1286
  if (body == null)
1287
1287
  return !1;
1288
1288
  const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], drawingOrderLength = (_b = (_a8 = documentDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _a8.length) != null ? _b : 0;
1289
+ let removeDrawingLen = 0;
1289
1290
  if (collapsed)
1290
1291
  startOffset > 0 && textX.push({
1291
1292
  t: TextXActionType.RETAIN,
@@ -1295,6 +1296,15 @@ const UpdateDocDrawingWrappingStyleCommand = {
1295
1296
  else {
1296
1297
  const { dos } = getRetainAndDeleteFromReplace(activeTextRange, segmentId, 0, body);
1297
1298
  textX.push(...dos);
1299
+ const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [activeTextRange]), drawings2 = (_c = documentDataModel.getDrawings()) != null ? _c : {}, drawingOrder = (_d = documentDataModel.getDrawingsOrder()) != null ? _d : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
1300
+ if (sortedRemovedCustomBlockIds.length > 0)
1301
+ for (const blockId of sortedRemovedCustomBlockIds) {
1302
+ const drawing = drawings2[blockId], drawingIndex = drawingOrder.indexOf(blockId);
1303
+ if (drawing == null || drawingIndex < 0)
1304
+ continue;
1305
+ const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
1306
+ rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction), removeDrawingLen++;
1307
+ }
1298
1308
  }
1299
1309
  textX.push({
1300
1310
  t: TextXActionType.INSERT,
@@ -1312,7 +1322,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
1312
1322
  const path = getRichTextEditPath(documentDataModel, segmentId), placeHolderAction = jsonX.editOp(textX.serialize(), path);
1313
1323
  rawActions.push(placeHolderAction);
1314
1324
  for (const drawing of drawings) {
1315
- const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength], drawingId);
1325
+ const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
1316
1326
  rawActions.push(addDrawingAction), rawActions.push(addDrawingOrderAction);
1317
1327
  }
1318
1328
  const doMutation = {