@univerjs/docs-drawing-ui 1.0.0-beta.0 → 1.0.0-beta.2

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.
Files changed (86) hide show
  1. package/lib/cjs/index.js +187 -72
  2. package/lib/cjs/locale/ar-SA.js +0 -3
  3. package/lib/cjs/locale/ca-ES.js +0 -3
  4. package/lib/cjs/locale/de-DE.js +0 -3
  5. package/lib/cjs/locale/en-US.js +0 -3
  6. package/lib/cjs/locale/es-ES.js +0 -3
  7. package/lib/cjs/locale/fa-IR.js +0 -3
  8. package/lib/cjs/locale/fr-FR.js +0 -3
  9. package/lib/cjs/locale/id-ID.js +0 -3
  10. package/lib/cjs/locale/it-IT.js +0 -3
  11. package/lib/cjs/locale/ja-JP.js +0 -3
  12. package/lib/cjs/locale/ko-KR.js +0 -3
  13. package/lib/cjs/locale/pl-PL.js +0 -3
  14. package/lib/cjs/locale/pt-BR.js +0 -3
  15. package/lib/cjs/locale/ru-RU.js +0 -3
  16. package/lib/cjs/locale/sk-SK.js +0 -3
  17. package/lib/cjs/locale/vi-VN.js +0 -3
  18. package/lib/cjs/locale/zh-CN.js +0 -3
  19. package/lib/cjs/locale/zh-HK.js +0 -3
  20. package/lib/cjs/locale/zh-TW.js +0 -3
  21. package/lib/es/index.js +187 -72
  22. package/lib/es/locale/ar-SA.js +0 -3
  23. package/lib/es/locale/ca-ES.js +0 -3
  24. package/lib/es/locale/de-DE.js +0 -3
  25. package/lib/es/locale/en-US.js +0 -3
  26. package/lib/es/locale/es-ES.js +0 -3
  27. package/lib/es/locale/fa-IR.js +0 -3
  28. package/lib/es/locale/fr-FR.js +0 -3
  29. package/lib/es/locale/id-ID.js +0 -3
  30. package/lib/es/locale/it-IT.js +0 -3
  31. package/lib/es/locale/ja-JP.js +0 -3
  32. package/lib/es/locale/ko-KR.js +0 -3
  33. package/lib/es/locale/pl-PL.js +0 -3
  34. package/lib/es/locale/pt-BR.js +0 -3
  35. package/lib/es/locale/ru-RU.js +0 -3
  36. package/lib/es/locale/sk-SK.js +0 -3
  37. package/lib/es/locale/vi-VN.js +0 -3
  38. package/lib/es/locale/zh-CN.js +0 -3
  39. package/lib/es/locale/zh-HK.js +0 -3
  40. package/lib/es/locale/zh-TW.js +0 -3
  41. package/lib/index.js +187 -72
  42. package/lib/locale/ar-SA.js +0 -3
  43. package/lib/locale/ca-ES.js +0 -3
  44. package/lib/locale/de-DE.js +0 -3
  45. package/lib/locale/en-US.js +0 -3
  46. package/lib/locale/es-ES.js +0 -3
  47. package/lib/locale/fa-IR.js +0 -3
  48. package/lib/locale/fr-FR.js +0 -3
  49. package/lib/locale/id-ID.js +0 -3
  50. package/lib/locale/it-IT.js +0 -3
  51. package/lib/locale/ja-JP.js +0 -3
  52. package/lib/locale/ko-KR.js +0 -3
  53. package/lib/locale/pl-PL.js +0 -3
  54. package/lib/locale/pt-BR.js +0 -3
  55. package/lib/locale/ru-RU.js +0 -3
  56. package/lib/locale/sk-SK.js +0 -3
  57. package/lib/locale/vi-VN.js +0 -3
  58. package/lib/locale/zh-CN.js +0 -3
  59. package/lib/locale/zh-HK.js +0 -3
  60. package/lib/locale/zh-TW.js +0 -3
  61. package/lib/types/controllers/render-controllers/doc-drawing-transform-update.controller.d.ts +3 -0
  62. package/lib/types/controllers/render-controllers/doc-drawing-update.render-controller.d.ts +4 -0
  63. package/lib/types/locale/en-US.d.ts +0 -3
  64. package/lib/types/menu/drawing-popup-menu.controller.d.ts +3 -0
  65. package/lib/types/services/doc-drawing-floating-toolbar-adapter.service.d.ts +1 -0
  66. package/lib/umd/index.js +1 -1
  67. package/lib/umd/locale/ar-SA.js +1 -1
  68. package/lib/umd/locale/ca-ES.js +1 -1
  69. package/lib/umd/locale/de-DE.js +1 -1
  70. package/lib/umd/locale/en-US.js +1 -1
  71. package/lib/umd/locale/es-ES.js +1 -1
  72. package/lib/umd/locale/fa-IR.js +1 -1
  73. package/lib/umd/locale/fr-FR.js +1 -1
  74. package/lib/umd/locale/id-ID.js +1 -1
  75. package/lib/umd/locale/it-IT.js +1 -1
  76. package/lib/umd/locale/ja-JP.js +1 -1
  77. package/lib/umd/locale/ko-KR.js +1 -1
  78. package/lib/umd/locale/pl-PL.js +1 -1
  79. package/lib/umd/locale/pt-BR.js +1 -1
  80. package/lib/umd/locale/ru-RU.js +1 -1
  81. package/lib/umd/locale/sk-SK.js +1 -1
  82. package/lib/umd/locale/vi-VN.js +1 -1
  83. package/lib/umd/locale/zh-CN.js +1 -1
  84. package/lib/umd/locale/zh-HK.js +1 -1
  85. package/lib/umd/locale/zh-TW.js +1 -1
  86. package/package.json +11 -11
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Edit Gambar" },
11
11
  "image-popup": {
12
- replace: "Ganti",
13
12
  delete: "Hapus",
14
13
  edit: "Edit",
15
14
  crop: "Pangkas",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "Horizontal",
39
38
  vertical: "Vertikal",
40
39
  absolutePosition: "Posisi Absolut(px)",
41
- relativePosition: "Posisi Relatif",
42
40
  toTheRightOf: "di sebelah kanan",
43
- relativeTo: "relatif terhadap",
44
41
  bellow: "di bawah",
45
42
  options: "Opsi",
46
43
  moveObjectWithText: "Pindahkan objek dengan teks",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Modifica immagine" },
11
11
  "image-popup": {
12
- replace: "Sostituisci",
13
12
  delete: "Elimina",
14
13
  edit: "Modifica",
15
14
  crop: "Ritaglia",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "Orizzontale",
39
38
  vertical: "Verticale",
40
39
  absolutePosition: "Posizione assoluta(px)",
41
- relativePosition: "Posizione relativa",
42
40
  toTheRightOf: "a destra di",
43
- relativeTo: "relativo a",
44
41
  bellow: "sotto",
45
42
  options: "Opzioni",
46
43
  moveObjectWithText: "Sposta oggetto con il testo",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "画像の編集" },
11
11
  "image-popup": {
12
- replace: "置換",
13
12
  delete: "削除",
14
13
  edit: "編集",
15
14
  crop: "トリミング",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "水平方向",
39
38
  vertical: "垂直方向",
40
39
  absolutePosition: "絶対位置(px)",
41
- relativePosition: "相対位置",
42
40
  toTheRightOf: "右側に",
43
- relativeTo: "基準に対して",
44
41
  bellow: "下に",
45
42
  options: "オプション",
46
43
  moveObjectWithText: "文字列と一緒にオブジェクトを移動",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "이미지 편집" },
11
11
  "image-popup": {
12
- replace: "교체",
13
12
  delete: "삭제",
14
13
  edit: "편집",
15
14
  crop: "자르기",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "수평",
39
38
  vertical: "수직",
40
39
  absolutePosition: "절대 위치(px)",
41
- relativePosition: "상대 위치",
42
40
  toTheRightOf: "우측에",
43
- relativeTo: "상대적으로",
44
41
  bellow: "아래에",
45
42
  options: "옵션",
46
43
  moveObjectWithText: "텍스트와 함께 객체 이동",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Edytuj obraz" },
11
11
  "image-popup": {
12
- replace: "Zamień",
13
12
  delete: "Usuń",
14
13
  edit: "Edytuj",
15
14
  crop: "Przytnij",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "Pozioma",
39
38
  vertical: "Pionowa",
40
39
  absolutePosition: "Pozycja bezwzględna(px)",
41
- relativePosition: "Pozycja względna",
42
40
  toTheRightOf: "po prawej stronie",
43
- relativeTo: "względem",
44
41
  bellow: "poniżej",
45
42
  options: "Opcje",
46
43
  moveObjectWithText: "Przesuwaj obiekt razem z tekstem",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Editar imagem" },
11
11
  "image-popup": {
12
- replace: "Substituir",
13
12
  delete: "Excluir",
14
13
  edit: "Editar",
15
14
  crop: "Cortar",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "Horizontal",
39
38
  vertical: "Vertical",
40
39
  absolutePosition: "Posição absoluta(px)",
41
- relativePosition: "Posição relativa",
42
40
  toTheRightOf: "à direita de",
43
- relativeTo: "relativo a",
44
41
  bellow: "abaixo",
45
42
  options: "Opções",
46
43
  moveObjectWithText: "Mover objeto com o texto",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Редактировать изображение" },
11
11
  "image-popup": {
12
- replace: "Заменить",
13
12
  delete: "Удалить",
14
13
  edit: "Редактировать",
15
14
  crop: "Обрезать",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "По горизонтали",
39
38
  vertical: "По вертикали",
40
39
  absolutePosition: "Абсолютное положение (px)",
41
- relativePosition: "Относительное положение",
42
40
  toTheRightOf: "справа от",
43
- relativeTo: "относительно",
44
41
  bellow: "снизу",
45
42
  options: "Параметры",
46
43
  moveObjectWithText: "Перемещать объект с текстом",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Upraviť obrázok" },
11
11
  "image-popup": {
12
- replace: "Nahradiť",
13
12
  delete: "Odstrániť",
14
13
  edit: "Upraviť",
15
14
  crop: "Orezať",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "Vodorovne",
39
38
  vertical: "Zvisle",
40
39
  absolutePosition: "Absolútna pozícia (px)",
41
- relativePosition: "Relatívna pozícia",
42
40
  toTheRightOf: "vpravo od",
43
- relativeTo: "vzhľadom na",
44
41
  bellow: "pod",
45
42
  options: "Možnosti",
46
43
  moveObjectWithText: "Presunúť objekt s textom",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "Chỉnh sửa hình ảnh" },
11
11
  "image-popup": {
12
- replace: "Thay thế",
13
12
  delete: "Xóa",
14
13
  edit: "Chỉnh sửa",
15
14
  crop: "Cắt",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "Ngang",
39
38
  vertical: "Dọc",
40
39
  absolutePosition: "Vị trí tuyệt đối (px)",
41
- relativePosition: "Vị trí tương đối",
42
40
  toTheRightOf: "ở bên phải",
43
- relativeTo: "tương đối với",
44
41
  bellow: "bên dưới",
45
42
  options: "Tùy chọn",
46
43
  moveObjectWithText: "Di chuyển đối tượng cùng văn bản",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "编辑图片" },
11
11
  "image-popup": {
12
- replace: "替换",
13
12
  delete: "删除",
14
13
  edit: "编辑",
15
14
  crop: "裁剪",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "水平",
39
38
  vertical: "垂直",
40
39
  absolutePosition: "绝对位置(px)",
41
- relativePosition: "相对位置",
42
40
  toTheRightOf: "右侧",
43
- relativeTo: "相对于",
44
41
  bellow: "下方",
45
42
  options: "选项",
46
43
  moveObjectWithText: "对象随文字移动",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "編圖" },
11
11
  "image-popup": {
12
- replace: "替換",
13
12
  delete: "刪除",
14
13
  edit: "編輯",
15
14
  crop: "裁切",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "水平",
39
38
  vertical: "垂直",
40
39
  absolutePosition: "絕對位置(px)",
41
- relativePosition: "相對位置",
42
40
  toTheRightOf: "右側",
43
- relativeTo: "相對於",
44
41
  bellow: "下方",
45
42
  options: "選項",
46
43
  moveObjectWithText: "物件隨文字移動",
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "編圖" },
11
11
  "image-popup": {
12
- replace: "替換",
13
12
  delete: "刪除",
14
13
  edit: "編輯",
15
14
  crop: "裁切",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "水平",
39
38
  vertical: "垂直",
40
39
  absolutePosition: "絕對位置(px)",
41
- relativePosition: "相對位置",
42
40
  toTheRightOf: "右側",
43
- relativeTo: "相對於",
44
41
  bellow: "下方",
45
42
  options: "選項",
46
43
  moveObjectWithText: "物件隨文字移動",
package/lib/index.js CHANGED
@@ -162,6 +162,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
162
162
  this._docRefreshDrawingsService = _docRefreshDrawingsService;
163
163
  this._fileOpenerService = _fileOpenerService;
164
164
  this._updateOrderListener();
165
+ this._updateImageCropListener();
165
166
  this._groupDrawingListener();
166
167
  this._focusDrawingListener();
167
168
  this._transformDrawingListener();
@@ -173,10 +174,12 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
173
174
  }
174
175
  async insertDocImage() {
175
176
  const insertPosition = this._getCurrentImageInsertPosition();
177
+ const textRange = this._getCurrentImageInsertTextRange();
176
178
  const files = await this._fileOpenerService.openFile({
177
179
  multiple: true,
178
180
  accept: DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
179
181
  });
182
+ if (this._disposed) return false;
180
183
  const fileLength = files.length;
181
184
  if (fileLength > DRAWING_IMAGE_COUNT_LIMIT) {
182
185
  this._messageService.show({
@@ -185,10 +188,9 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
185
188
  });
186
189
  return false;
187
190
  } else if (fileLength === 0) return false;
188
- await this._insertFloatImages(files, insertPosition);
189
- return true;
191
+ return await this._insertFloatImages(files, insertPosition, textRange);
190
192
  }
191
- async _insertFloatImages(files, insertPosition) {
193
+ async _insertFloatImages(files, insertPosition, textRange) {
192
194
  let imageParams = [];
193
195
  try {
194
196
  imageParams = await Promise.all(files.map((file) => this._imageIoService.saveImage(file)));
@@ -212,13 +214,14 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
212
214
  content
213
215
  });
214
216
  }
215
- if (imageParams.length === 0) return;
217
+ if (this._disposed || imageParams.length === 0) return false;
216
218
  const { unitId } = this._context;
217
219
  const docDrawingParams = [];
218
220
  for (const imageParam of imageParams) {
219
221
  if (imageParam == null) continue;
220
222
  const { imageId, imageSourceType, source, base64Cache } = imageParam;
221
223
  const { width, height, image } = await getImageSize(base64Cache || "");
224
+ if (this._disposed) return false;
222
225
  this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);
223
226
  let scale = 1;
224
227
  if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
@@ -228,7 +231,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
228
231
  }
229
232
  const imagePosition = insertPosition ?? this._getCurrentImageInsertPosition();
230
233
  const docTransform = this._getImagePosition(width * scale, height * scale, imagePosition);
231
- if (docTransform == null) return;
234
+ if (docTransform == null) return false;
232
235
  const transform = docDrawingPositionToTransform(docTransform);
233
236
  if (transform != null && imagePosition != null) transform.top = imagePosition.top;
234
237
  const docDrawingParam = {
@@ -256,9 +259,10 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
256
259
  }
257
260
  docDrawingParams.push(docDrawingParam);
258
261
  }
259
- this._commandService.executeCommand(InsertDocDrawingCommand.id, {
262
+ return await this._commandService.executeCommand(InsertDocDrawingCommand.id, {
260
263
  unitId,
261
- drawings: docDrawingParams
264
+ drawings: docDrawingParams,
265
+ textRange: textRange ?? void 0
262
266
  });
263
267
  }
264
268
  _isInsertInHeaderFooter() {
@@ -283,6 +287,9 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
283
287
  top: position.top
284
288
  };
285
289
  }
290
+ _getCurrentImageInsertTextRange() {
291
+ return this._docSelectionRenderService.getAllTextRanges().find((range) => range.isActive) ?? this._docSelectionManagerService.getActiveTextRange();
292
+ }
286
293
  _updateOrderListener() {
287
294
  this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe((params) => {
288
295
  const { unitId, subUnitId, drawingIds, arrangeType } = params;
@@ -294,6 +301,73 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
294
301
  });
295
302
  }));
296
303
  }
304
+ _updateImageCropListener() {
305
+ this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe((params) => {
306
+ const drawings = params.flatMap((param) => this._getImageCropUpdates(param));
307
+ if (drawings.length > 0) {
308
+ const { unitId } = this._context;
309
+ this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
310
+ unitId,
311
+ subUnitId: unitId,
312
+ drawings
313
+ });
314
+ }
315
+ }));
316
+ }
317
+ _getImageCropUpdates(param) {
318
+ const { unitId, subUnitId, drawingId, transform } = param;
319
+ if ([unitId, subUnitId].some((id) => id !== this._context.unitId)) return [];
320
+ if (transform == null || !Object.prototype.hasOwnProperty.call(param, "srcRect")) return [];
321
+ const docDrawing = this._getDocDrawing(drawingId);
322
+ const renderDrawing = this._drawingManagerService.getDrawingByParam({
323
+ unitId,
324
+ subUnitId,
325
+ drawingId
326
+ });
327
+ if ((docDrawing === null || docDrawing === void 0 ? void 0 : docDrawing.drawingType) !== DrawingTypeEnum.DRAWING_IMAGE || (renderDrawing === null || renderDrawing === void 0 ? void 0 : renderDrawing.transform) == null) return [];
328
+ const nextTransform = {
329
+ ...renderDrawing.transform,
330
+ ...transform
331
+ };
332
+ const drawings = [{
333
+ drawingId,
334
+ key: "srcRect",
335
+ value: param.srcRect
336
+ }];
337
+ if (nextTransform.width != null && nextTransform.height != null) drawings.push({
338
+ drawingId,
339
+ key: "size",
340
+ value: {
341
+ width: nextTransform.width,
342
+ height: nextTransform.height
343
+ }
344
+ });
345
+ if (docDrawing.layoutType === PositionedObjectLayoutType.INLINE || renderDrawing.isMultiTransform === BooleanNumber.TRUE) return drawings;
346
+ const horizontalDelta = (nextTransform.left ?? 0) - (renderDrawing.transform.left ?? 0);
347
+ const verticalDelta = (nextTransform.top ?? 0) - (renderDrawing.transform.top ?? 0);
348
+ const { positionH, positionV } = docDrawing.docTransform;
349
+ if (horizontalDelta !== 0 && positionH.posOffset != null) drawings.push({
350
+ drawingId,
351
+ key: "positionH",
352
+ value: {
353
+ relativeFrom: positionH.relativeFrom,
354
+ posOffset: positionH.posOffset + horizontalDelta
355
+ }
356
+ });
357
+ if (verticalDelta !== 0 && positionV.posOffset != null) drawings.push({
358
+ drawingId,
359
+ key: "positionV",
360
+ value: {
361
+ relativeFrom: positionV.relativeFrom,
362
+ posOffset: positionV.posOffset + verticalDelta
363
+ }
364
+ });
365
+ return drawings;
366
+ }
367
+ _getDocDrawing(drawingId) {
368
+ var _this$_context$unit$g;
369
+ return (_this$_context$unit$g = this._context.unit.getDrawings()) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g[drawingId];
370
+ }
297
371
  _groupDrawingListener() {
298
372
  this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
299
373
  this._commandService.executeCommand(GroupDocDrawingCommand.id, params);
@@ -316,7 +390,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
316
390
  }
317
391
  _transformDrawingListener() {
318
392
  const res = this._getCurrentSceneAndTransformer();
319
- if (res && res.transformer) this.disposeWithMe(res.transformer.changeEnd$.pipe(debounceTime(30)).subscribe((params) => {
393
+ if (res && res.transformer) this.disposeWithMe(res.transformer.changeEnd$.pipe(debounceTime(30)).subscribe(() => {
320
394
  this._docSelectionManagerService.refreshSelection();
321
395
  }));
322
396
  else throw new Error("transformer is not init");
@@ -381,13 +455,13 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
381
455
  scene.detachTransformerFrom(shape);
382
456
  try {
383
457
  shape.setOpacity(isDocInputFocusing ? .5 : 1);
384
- } catch (e) {}
458
+ } catch {}
385
459
  if (!isDocInputFocusing) continue;
386
460
  if (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) {
387
461
  if (drawing.allowTransform !== false) scene.attachTransformerTo(shape);
388
462
  try {
389
463
  shape.setOpacity(1);
390
- } catch (e) {}
464
+ } catch {}
391
465
  }
392
466
  }
393
467
  }
@@ -1033,7 +1107,8 @@ const getDisableWhenSelectionInTableObservable = (accessor) => {
1033
1107
  function ImageMenuFactory(accessor) {
1034
1108
  return {
1035
1109
  id: DOCS_IMAGE_MENU_ID,
1036
- type: MenuItemType.SUBITEMS,
1110
+ commandId: IMAGE_MENU_UPLOAD_FLOAT_ID,
1111
+ type: MenuItemType.BUTTON,
1037
1112
  icon: "AddImageIcon",
1038
1113
  tooltip: "docs-drawing-ui.title",
1039
1114
  disabled$: getDisableWhenSelectionInTableObservable(accessor),
@@ -1127,11 +1202,7 @@ function InsertEllipseShapeBelowMenuFactory(accessor) {
1127
1202
  const menuSchema = {
1128
1203
  [RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
1129
1204
  order: 0,
1130
- menuItemFactory: ImageMenuFactory,
1131
- [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
1132
- order: 0,
1133
- menuItemFactory: UploadFloatImageMenuFactory
1134
- }
1205
+ menuItemFactory: ImageMenuFactory
1135
1206
  } },
1136
1207
  [ContextMenuPosition.PARAGRAPH]: {
1137
1208
  [ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
@@ -1194,7 +1265,7 @@ const menuSchema = {
1194
1265
  //#endregion
1195
1266
  //#region package.json
1196
1267
  var name = "@univerjs/docs-drawing-ui";
1197
- var version = "1.0.0-beta.0";
1268
+ var version = "1.0.0-beta.2";
1198
1269
 
1199
1270
  //#endregion
1200
1271
  //#region src/config/config.ts
@@ -2607,6 +2678,7 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
2607
2678
  this._univerInstanceService = _univerInstanceService;
2608
2679
  this._lifecycleService = _lifecycleService;
2609
2680
  _defineProperty(this, "_liquid", new Liquid());
2681
+ _defineProperty(this, "_changesetDrawingRefreshScheduled", false);
2610
2682
  this._initialize();
2611
2683
  this._commandExecutedListener();
2612
2684
  }
@@ -2627,21 +2699,40 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
2627
2699
  }
2628
2700
  _commandExecutedListener() {
2629
2701
  const updateCommandList = [RichTextEditingMutation.id, SetDocZoomRatioOperation.id];
2630
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2702
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
2631
2703
  if (updateCommandList.includes(command.id)) {
2632
2704
  const { unitId: commandUnitId } = command.params;
2633
- const { unitId, mainComponent } = this._context;
2705
+ const { unitId } = this._context;
2634
2706
  if (commandUnitId !== unitId) return;
2635
- const skeleton = this._docSkeletonManagerService.getSkeleton();
2636
- if (skeleton == null) return;
2637
- if (this._editorService.isEditor(unitId)) {
2638
- mainComponent === null || mainComponent === void 0 || mainComponent.makeDirty();
2707
+ if (command.id === RichTextEditingMutation.id && (options === null || options === void 0 ? void 0 : options.fromChangeset)) {
2708
+ this._scheduleChangesetDrawingRefresh();
2639
2709
  return;
2640
2710
  }
2641
- this._refreshDrawing(skeleton);
2711
+ this._refreshCurrentDrawing();
2642
2712
  }
2643
2713
  }));
2644
2714
  }
2715
+ _scheduleChangesetDrawingRefresh() {
2716
+ if (this._changesetDrawingRefreshScheduled) return;
2717
+ this._changesetDrawingRefreshScheduled = true;
2718
+ queueMicrotask(() => {
2719
+ queueMicrotask(() => {
2720
+ this._changesetDrawingRefreshScheduled = false;
2721
+ if (this._disposed) return;
2722
+ this._refreshCurrentDrawing();
2723
+ });
2724
+ });
2725
+ }
2726
+ _refreshCurrentDrawing() {
2727
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2728
+ if (skeleton == null) return;
2729
+ const { unitId, mainComponent } = this._context;
2730
+ if (this._editorService.isEditor(unitId)) {
2731
+ mainComponent === null || mainComponent === void 0 || mainComponent.makeDirty();
2732
+ return;
2733
+ }
2734
+ this._refreshDrawing(skeleton);
2735
+ }
2645
2736
  _initTransformRefresh() {
2646
2737
  this.disposeWithMe(merge$1(fromEventSubject(this._context.engine.onTransformChange$).pipe(filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)), fromEventSubject(this._context.scene.onTransformChange$).pipe(filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale))).pipe(debounceTime(16)).subscribe(() => {
2647
2738
  var _scene$getTransformer;
@@ -3585,6 +3676,8 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3585
3676
  this._floatingToolbarAdapterService = _floatingToolbarAdapterService;
3586
3677
  this._commandService = _commandService;
3587
3678
  _defineProperty(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
3679
+ _defineProperty(this, "_embeddedRenderUnits", /* @__PURE__ */ new Set());
3680
+ _defineProperty(this, "_popupMenuListeners", /* @__PURE__ */ new Map());
3588
3681
  _defineProperty(this, "_disposePopups", []);
3589
3682
  _defineProperty(this, "_isDrawingPanelOpen", false);
3590
3683
  this._init();
@@ -3606,11 +3699,21 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3606
3699
  }));
3607
3700
  this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentDataModel) => this._create(documentDataModel)));
3608
3701
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentDataModel) => this._dispose(documentDataModel)));
3702
+ this.disposeWithMe(this._renderManagerService.created$.pipe(takeUntil(this.dispose$)).subscribe((render) => {
3703
+ if (render.type !== UniverInstanceType.UNIVER_DOC || render.isMainScene) return;
3704
+ this._embeddedRenderUnits.add(render.unitId);
3705
+ this._create(this._univerInstanceService.getUnit(render.unitId, UniverInstanceType.UNIVER_DOC));
3706
+ }));
3707
+ this.disposeWithMe(this._renderManagerService.disposed$.pipe(takeUntil(this.dispose$)).subscribe((unitId) => {
3708
+ if (!this._embeddedRenderUnits.delete(unitId)) return;
3709
+ this._disposePopupMenuListener(unitId);
3710
+ }));
3609
3711
  this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_DOC).forEach((documentDataModel) => this._create(documentDataModel));
3610
3712
  }
3611
3713
  _dispose(documentDataModel) {
3612
3714
  const unitId = documentDataModel.getUnitId();
3613
3715
  this._clearPopups();
3716
+ this._disposePopupMenuListener(unitId);
3614
3717
  this._renderManagerService.removeRender(unitId);
3615
3718
  }
3616
3719
  _clearPopups() {
@@ -3622,10 +3725,20 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3622
3725
  const unitId = documentDataModel.getUnitId();
3623
3726
  if (isInternalEditorID(unitId)) return;
3624
3727
  if (this._renderManagerService.has(unitId) && !this._initImagePopupMenu.has(unitId)) {
3625
- this._popupMenuListener(unitId);
3626
- this._initImagePopupMenu.add(unitId);
3728
+ const listener = this._popupMenuListener(unitId);
3729
+ if (listener) {
3730
+ this._popupMenuListeners.set(unitId, listener);
3731
+ this._initImagePopupMenu.add(unitId);
3732
+ }
3627
3733
  }
3628
3734
  }
3735
+ _disposePopupMenuListener(unitId) {
3736
+ var _this$_popupMenuListe;
3737
+ (_this$_popupMenuListe = this._popupMenuListeners.get(unitId)) === null || _this$_popupMenuListe === void 0 || _this$_popupMenuListe.dispose();
3738
+ this._popupMenuListeners.delete(unitId);
3739
+ this._initImagePopupMenu.delete(unitId);
3740
+ this._clearPopups();
3741
+ }
3629
3742
  _hasCropObject(scene) {
3630
3743
  const objects = scene.getAllObjects();
3631
3744
  for (const object of objects) if (object instanceof ImageCropperObject) return true;
@@ -3638,55 +3751,57 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3638
3751
  const transformer = scene.getTransformerByCreate();
3639
3752
  if (!transformer) return;
3640
3753
  const disposePopups = this._disposePopups;
3641
- this.disposeWithMe(transformer.createControl$.subscribe(() => {
3642
- if (this._hasCropObject(scene)) return;
3643
- const selectedObjects = transformer.getSelectedObjectMap();
3644
- disposePopups.forEach((dispose) => dispose.dispose());
3645
- disposePopups.length = 0;
3646
- if (this._isDrawingPanelOpen) return;
3647
- if (selectedObjects.size > 1) return;
3648
- const object = selectedObjects.values().next().value;
3649
- if (!object) return;
3650
- const oKey = object.oKey;
3651
- const drawingParam = this._drawingManagerService.getDrawingOKey(oKey);
3652
- if (!drawingParam || drawingParam.drawingType === DrawingTypeEnum.DRAWING_DOM || drawingParam.drawingType === DrawingTypeEnum.DRAWING_SHAPE) return;
3653
- const { unitId, subUnitId, drawingId, drawingType } = drawingParam;
3654
- const isImage = drawingType === DrawingTypeEnum.DRAWING_IMAGE;
3655
- const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
3656
- const popup = this._canvasPopManagerService.attachPopupToObject(object, {
3657
- componentKey: COMPONENT_IMAGE_POPUP_MENU,
3658
- direction: isImage || isChart ? "top-center" : "horizontal",
3659
- offset: isImage || isChart ? [0, 8] : [2, 0],
3660
- extraProps: {
3661
- menuItems: this._getDrawingPopupMenuItems(unitId, subUnitId, drawingId, drawingType),
3662
- variant: isImage ? "doc-floating-toolbar" : isChart ? "doc-chart-floating-toolbar" : void 0,
3754
+ const subscriptions = [
3755
+ transformer.createControl$.subscribe(() => {
3756
+ if (this._hasCropObject(scene)) return;
3757
+ const selectedObjects = transformer.getSelectedObjectMap();
3758
+ disposePopups.forEach((dispose) => dispose.dispose());
3759
+ disposePopups.length = 0;
3760
+ if (this._isDrawingPanelOpen || selectedObjects.size > 1) return;
3761
+ const object = selectedObjects.values().next().value;
3762
+ if (!object) return;
3763
+ const drawingParam = this._drawingManagerService.getDrawingOKey(object.oKey);
3764
+ if (!drawingParam || drawingParam.drawingType === DrawingTypeEnum.DRAWING_DOM || drawingParam.drawingType === DrawingTypeEnum.DRAWING_SHAPE) return;
3765
+ const { unitId, subUnitId, drawingId, drawingType } = drawingParam;
3766
+ const isImage = drawingType === DrawingTypeEnum.DRAWING_IMAGE;
3767
+ const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
3768
+ const popup = this._canvasPopManagerService.attachPopupToObject(object, {
3769
+ componentKey: COMPONENT_IMAGE_POPUP_MENU,
3770
+ direction: isImage || isChart ? "top-center" : "horizontal",
3771
+ offset: isImage || isChart ? [0, 8] : [2, 0],
3772
+ extraProps: {
3773
+ menuItems: this._getDrawingPopupMenuItems(unitId, subUnitId, drawingId, drawingType),
3774
+ variant: isImage ? "doc-floating-toolbar" : isChart ? "doc-chart-floating-toolbar" : void 0,
3775
+ unitId,
3776
+ subUnitId,
3777
+ drawingId
3778
+ }
3779
+ }, unitId);
3780
+ disposePopups.push(this.disposeWithMe(popup));
3781
+ if (!this._drawingManagerService.getFocusDrawings().find((drawing) => drawing.unitId === unitId && drawing.subUnitId === subUnitId && drawing.drawingId === drawingId)) this._drawingManagerService.focusDrawing([{
3663
3782
  unitId,
3664
3783
  subUnitId,
3665
3784
  drawingId
3666
- }
3667
- }, unitId);
3668
- disposePopups.push(this.disposeWithMe(popup));
3669
- if (this._drawingManagerService.getFocusDrawings().find((drawing) => drawing.unitId === unitId && drawing.subUnitId === subUnitId && drawing.drawingId === drawingId)) return;
3670
- this._drawingManagerService.focusDrawing([{
3671
- unitId,
3672
- subUnitId,
3673
- drawingId
3674
- }]);
3675
- }));
3676
- this.disposeWithMe(transformer.clearControl$.subscribe(() => {
3677
- disposePopups.forEach((dispose) => dispose.dispose());
3678
- disposePopups.length = 0;
3679
- this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, false);
3680
- this._drawingManagerService.focusDrawing(null);
3681
- }));
3682
- this.disposeWithMe(transformer.changing$.subscribe(() => {
3683
- disposePopups.forEach((dispose) => dispose.dispose());
3684
- disposePopups.length = 0;
3685
- }));
3686
- this.disposeWithMe(transformer.changeStart$.subscribe(() => {
3687
- disposePopups.forEach((dispose) => dispose.dispose());
3688
- disposePopups.length = 0;
3689
- }));
3785
+ }]);
3786
+ }),
3787
+ transformer.clearControl$.subscribe(() => {
3788
+ disposePopups.forEach((dispose) => dispose.dispose());
3789
+ disposePopups.length = 0;
3790
+ this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, false);
3791
+ this._drawingManagerService.focusDrawing(null);
3792
+ }),
3793
+ transformer.changing$.subscribe(() => {
3794
+ disposePopups.forEach((dispose) => dispose.dispose());
3795
+ disposePopups.length = 0;
3796
+ }),
3797
+ transformer.changeStart$.subscribe(() => {
3798
+ disposePopups.forEach((dispose) => dispose.dispose());
3799
+ disposePopups.length = 0;
3800
+ })
3801
+ ];
3802
+ const disposable = toDisposable(() => subscriptions.forEach((subscription) => subscription.unsubscribe()));
3803
+ this.disposeWithMe(disposable);
3804
+ return disposable;
3690
3805
  }
3691
3806
  _getDrawingPopupMenuItems(unitId, subUnitId, drawingId, drawingType) {
3692
3807
  const drawing = this._drawingManagerService.getDrawingByParam({
@@ -9,7 +9,6 @@ const locale = { "docs-drawing-ui": {
9
9
  } },
10
10
  panel: { title: "تحرير الصورة" },
11
11
  "image-popup": {
12
- replace: "استبدال",
13
12
  delete: "حذف",
14
13
  edit: "تحرير",
15
14
  crop: "قص",
@@ -38,9 +37,7 @@ const locale = { "docs-drawing-ui": {
38
37
  horizontal: "أفقي",
39
38
  vertical: "عمودي",
40
39
  absolutePosition: "موضع مطلق(بكسل)",
41
- relativePosition: "موضع نسبي",
42
40
  toTheRightOf: "إلى يمين",
43
- relativeTo: "بالنسبة إلى",
44
41
  bellow: "أسفل",
45
42
  options: "خيارات",
46
43
  moveObjectWithText: "نقل الكائن مع النص",