@univerjs/docs-drawing-ui 0.2.5 → 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
@@ -1,1979 +1,2058 @@
1
- var vt = Object.defineProperty;
2
- var It = (i, e, n) => e in i ? vt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
3
- var _e = (i, e, n) => It(i, typeof e != "symbol" ? e + "" : e, n);
4
- import { CommandType as Y, ICommandService as $, IUniverInstanceService as ne, TextX as hn, JSONX as X, MemoryCursor as _t, TextXActionType as Z, LocaleService as an, RxDisposable as Ct, UniverInstanceType as be, toDisposable as ye, FOCUSING_COMMON_DRAWINGS as rn, OnLifecycle as sn, LifecycleStages as cn, Inject as pe, IContextService as Fn, useDependency as re, PositionedObjectLayoutType as k, BooleanNumber as oe, ObjectRelativeFromH as ee, ObjectRelativeFromV as V, Tools as Pe, WrapTextType as je, Direction as ge, IUndoRedoService as kn, FOCUSING_UNIVER_EDITOR as St, Disposable as qe, Injector as Hn, UndoCommand as Dt, RedoCommand as Et, throttle as Sn, COLORS as Pt, Plugin as Ot, DependentOn as Tt } from "@univerjs/core";
5
- import { ImageCropperObject as Mt, COMPONENT_IMAGE_POPUP_MENU as yt, OpenImageCropOperation as bt, ImageResetSizeOperation as Rt, DrawingCommonPanel as Nt, UniverDrawingUIPlugin as At } from "@univerjs/drawing-ui";
6
- import { IDrawingManagerService as he, DRAWING_IMAGE_ALLOW_IMAGE_LIST as xt, ArrangeTypeEnum as Ye, DRAWING_IMAGE_COUNT_LIMIT as Dn, ImageUploadStatusType as gn, DRAWING_IMAGE_ALLOW_SIZE as Lt, getImageSize as Ut, DrawingTypeEnum as Bt, getDrawingShapeKeyByDrawingSearch as Ft, DRAWING_IMAGE_WIDTH_LIMIT as En, DRAWING_IMAGE_HEIGHT_LIMIT as Pn, IImageIoService as kt, UniverDrawingPlugin as Ht } from "@univerjs/drawing";
7
- import { IDocDrawingService as Re, UniverDocsDrawingPlugin as Wt } from "@univerjs/docs-drawing";
8
- import { ITextSelectionRenderManager as Ue, IRenderManagerService as se, DocumentEditArea as xe, Liquid as Wn, PageLayoutType as On, NodePositionConvertToCursor as Tn, getOneTextSelectionRange as Mn, DocumentSkeletonPageType as yn, Vector2 as Gt, getAnchorBounding as Vt, Rect as jt, getColor as $t, TEXT_RANGE_LAYER_INDEX as zt } from "@univerjs/engine-render";
9
- import { takeUntil as bn, BehaviorSubject as qt } from "rxjs";
10
- import { DocCanvasPopManagerService as Xt, docDrawingPositionToTransform as Kt } from "@univerjs/docs-ui";
11
- import { RichTextEditingMutation as Q, getRichTextEditPath as $e, DocSkeletonManagerService as ae, TextSelectionManagerService as un, getRetainAndDeleteFromReplace as Yt, SetDocZoomRatioOperation as Zt, getDocObject as Qt } from "@univerjs/docs";
12
- import { ISidebarService as Jt, MenuItemType as Gn, MenuPosition as ei, MenuGroup as ni, getMenuHiddenObservable as Vn, KeyCode as Le, ComponentManager as ti, IMenuService as ii, IShortcutService as ri, IMessageService as oi, IEditorService as ai } from "@univerjs/ui";
13
- import d, { forwardRef as jn, useRef as $n, createElement as zn, useState as ie, useEffect as wn } from "react";
14
- import j from "clsx";
15
- import { RadioGroup as Rn, Radio as Ee, InputNumber as Ae, Select as Nn, Checkbox as si, MessageType as An } from "@univerjs/design";
16
- const vn = {
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
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, fromEventSubject, LifecycleService, UndoCommand, RedoCommand, throttle, COLORS, Plugin, DependentOn } from "@univerjs/core";
6
+ import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
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
+ import { IDocDrawingService, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
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
+ import { DocCanvasPopManagerService, docDrawingPositionToTransform } from "@univerjs/docs-ui";
12
+ import { RichTextEditingMutation, getRichTextEditPath, TextSelectionManagerService, DocSkeletonManagerService, getRetainAndDeleteFromReplace, SetDocZoomRatioOperation, getDocObject } from "@univerjs/docs";
13
+ import { ISidebarService, MenuItemType, MenuPosition, MenuGroup, getMenuHiddenObservable, KeyCode, ComponentManager, IMenuService, IShortcutService, IMessageService, IEditorService } from "@univerjs/ui";
14
+ import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
15
+ import clsx from "clsx";
16
+ import { RadioGroup, Radio, InputNumber, Select, Checkbox, MessageType } from "@univerjs/design";
17
+ const RemoveDocDrawingCommand = {
17
18
  id: "doc.command.remove-doc-image",
18
- type: Y.COMMAND,
19
+ type: CommandType.COMMAND,
19
20
  // eslint-disable-next-line max-lines-per-function
20
- handler: (i, e) => {
21
- var C, O, y, T;
22
- const n = i.get($), t = i.get(ne), r = i.get(Ue), o = t.getCurrentUniverDocInstance();
23
- if (e == null || o == null)
21
+ handler: /* @__PURE__ */ __name((accessor, params) => {
22
+ var _a8, _b, _c, _d;
23
+ const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), textSelectionRenderManager = accessor.get(ITextSelectionRenderManager), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
24
+ if (params == null || documentDataModel == null)
24
25
  return !1;
25
- const { drawings: a } = e, s = (C = r.getSegment()) != null ? C : "", l = new hn(), c = X.getInstance(), m = (y = (O = o.getSelfOrHeaderFooterModel(s).getBody()) == null ? void 0 : O.customBlocks) != null ? y : [], u = a.map((N) => m.find((R) => R.blockId === N.drawingId)).filter((N) => !!N).sort((N, R) => N.startIndex > R.startIndex ? 1 : -1), f = a[0].unitId, h = new _t();
26
- h.reset();
27
- const p = u[0].startIndex, w = [
26
+ const { drawings: removeDrawings } = params, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", textX = new TextX(), jsonX = JSONX.getInstance(), customBlocks = (_c = (_b = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.customBlocks) != null ? _c : [], removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1), unitId = removeDrawings[0].unitId, memoryCursor = new MemoryCursor();
27
+ memoryCursor.reset();
28
+ const cursorIndex = removeCustomBlocks[0].startIndex, textRanges = [
28
29
  {
29
- startOffset: p,
30
- endOffset: p
30
+ startOffset: cursorIndex,
31
+ endOffset: cursorIndex
31
32
  }
32
- ], v = {
33
- id: Q.id,
33
+ ], doMutation = {
34
+ id: RichTextEditingMutation.id,
34
35
  params: {
35
- unitId: f,
36
+ unitId,
36
37
  actions: [],
37
- textRanges: w
38
+ textRanges
38
39
  }
39
- }, I = [];
40
- for (const N of u) {
41
- const { startIndex: R } = N;
42
- R > h.cursor && l.push({
43
- t: Z.RETAIN,
44
- len: R - h.cursor,
40
+ }, rawActions = [];
41
+ for (const block of removeCustomBlocks) {
42
+ const { startIndex } = block;
43
+ startIndex > memoryCursor.cursor && textX.push({
44
+ t: TextXActionType.RETAIN,
45
+ len: startIndex - memoryCursor.cursor,
45
46
  segmentId: ""
46
- }), l.push({
47
- t: Z.DELETE,
47
+ }), textX.push({
48
+ t: TextXActionType.DELETE,
48
49
  len: 1,
49
50
  line: 0,
50
51
  segmentId: ""
51
- }), h.moveCursorTo(R + 1);
52
+ }), memoryCursor.moveCursorTo(startIndex + 1);
52
53
  }
53
- const D = $e(o, s);
54
- I.push(c.editOp(l.serialize(), D));
55
- for (const N of u) {
56
- const { blockId: R } = N, E = ((T = o.getDrawings()) != null ? T : {})[R], z = o.getDrawingsOrder().indexOf(R), U = c.removeOp(["drawings", R], E), B = c.removeOp(["drawingsOrder", z], R);
57
- I.push(U), I.push(B);
54
+ const path = getRichTextEditPath(documentDataModel, segmentId);
55
+ rawActions.push(jsonX.editOp(textX.serialize(), path));
56
+ for (const block of removeCustomBlocks) {
57
+ const { blockId } = block, drawing = ((_d = documentDataModel.getDrawings()) != null ? _d : {})[blockId], drawingIndex = documentDataModel.getDrawingsOrder().indexOf(blockId), removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
58
+ rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction);
58
59
  }
59
- return v.params.actions = I.reduce((N, R) => X.compose(N, R), null), !!n.syncExecuteCommand(v.id, v.params);
60
- }
61
- }, qn = "COMPONENT_DOC_DRAWING_PANEL", Xn = {
60
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
61
+ }, "handler")
62
+ }, COMPONENT_DOC_DRAWING_PANEL = "COMPONENT_DOC_DRAWING_PANEL", SidebarDocDrawingOperation = {
62
63
  id: "sidebar.operation.doc-image",
63
- type: Y.COMMAND,
64
- handler: async (i, e) => {
65
- const n = i.get(Jt), t = i.get(an), r = i.get(he);
66
- switch (e.value) {
64
+ type: CommandType.COMMAND,
65
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
66
+ const sidebarService = accessor.get(ISidebarService), localeService = accessor.get(LocaleService), drawingManagerService = accessor.get(IDrawingManagerService);
67
+ switch (params.value) {
67
68
  case "open":
68
- n.open({
69
- header: { title: t.t("docImage.panel.title") },
70
- children: { label: qn },
71
- onClose: () => {
72
- r.focusDrawing(null);
73
- },
69
+ sidebarService.open({
70
+ header: { title: localeService.t("docImage.panel.title") },
71
+ children: { label: COMPONENT_DOC_DRAWING_PANEL },
72
+ onClose: /* @__PURE__ */ __name(() => {
73
+ drawingManagerService.focusDrawing(null);
74
+ }, "onClose"),
74
75
  width: 360
75
76
  });
76
77
  break;
77
78
  case "close":
78
79
  default:
79
- n.close();
80
+ sidebarService.close();
80
81
  break;
81
82
  }
82
83
  return !0;
83
- }
84
- }, Kn = {
84
+ }, "handler")
85
+ }, EditDocDrawingOperation = {
85
86
  id: "doc.operation.edit-doc-image",
86
- type: Y.OPERATION,
87
- handler: (i, e) => {
88
- const n = i.get(he), t = i.get($);
89
- return e == null ? !1 : (n.focusDrawing([e]), t.executeCommand(Xn.id, { value: "open" }), !0);
90
- }
87
+ type: CommandType.OPERATION,
88
+ handler: /* @__PURE__ */ __name((accessor, params) => {
89
+ const drawingManagerService = accessor.get(IDrawingManagerService), commandService = accessor.get(ICommandService);
90
+ return params == null ? !1 : (drawingManagerService.focusDrawing([params]), commandService.executeCommand(SidebarDocDrawingOperation.id, { value: "open" }), !0);
91
+ }, "handler")
91
92
  };
92
- var ci = Object.defineProperty, li = Object.getOwnPropertyDescriptor, di = (i, e, n, t) => {
93
- for (var r = t > 1 ? void 0 : t ? li(e, n) : e, o = i.length - 1, a; o >= 0; o--)
94
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
95
- return t && r && ci(e, n, r), r;
96
- }, ke = (i, e) => (n, t) => e(n, t, i);
97
- let Je = class extends Ct {
98
- constructor(e, n, t, r, o) {
93
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
94
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
95
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
96
+ return kind && result && __defProp$6(target, key, result), result;
97
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a;
98
+ let DocDrawingPopupMenuController = (_a = class extends RxDisposable {
99
+ constructor(_drawingManagerService, _canvasPopManagerService, _renderManagerService, _univerInstanceService, _contextService) {
99
100
  super();
100
- _e(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
101
- this._drawingManagerService = e, this._canvasPopManagerService = n, this._renderManagerService = t, this._univerInstanceService = r, this._contextService = o, this._init();
101
+ __publicField(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
102
+ this._drawingManagerService = _drawingManagerService, this._canvasPopManagerService = _canvasPopManagerService, this._renderManagerService = _renderManagerService, this._univerInstanceService = _univerInstanceService, this._contextService = _contextService, this._init();
102
103
  }
103
104
  _init() {
104
- this._univerInstanceService.getCurrentTypeOfUnit$(be.UNIVER_DOC).pipe(bn(this.dispose$)).subscribe((e) => this._create(e)), this._univerInstanceService.getTypeOfUnitDisposed$(be.UNIVER_DOC).pipe(bn(this.dispose$)).subscribe((e) => this._dispose(e)), this._univerInstanceService.getAllUnitsForType(be.UNIVER_DOC).forEach((e) => this._create(e));
105
+ this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentDataModel) => this._create(documentDataModel)), this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentDataModel) => this._dispose(documentDataModel)), this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_DOC).forEach((documentDataModel) => this._create(documentDataModel));
105
106
  }
106
- _dispose(e) {
107
- const n = e.getUnitId();
108
- this._renderManagerService.removeRender(n);
107
+ _dispose(documentDataModel) {
108
+ const unitId = documentDataModel.getUnitId();
109
+ this._renderManagerService.removeRender(unitId);
109
110
  }
110
- _create(e) {
111
- if (!e)
111
+ _create(documentDataModel) {
112
+ if (!documentDataModel)
112
113
  return;
113
- const n = e.getUnitId();
114
- this._renderManagerService.has(n) && !this._initImagePopupMenu.has(n) && (this._popupMenuListener(n), this._initImagePopupMenu.add(n));
114
+ const unitId = documentDataModel.getUnitId();
115
+ this._renderManagerService.has(unitId) && !this._initImagePopupMenu.has(unitId) && (this._popupMenuListener(unitId), this._initImagePopupMenu.add(unitId));
115
116
  }
116
- _hasCropObject(e) {
117
- const n = e.getAllObjects();
118
- for (const t of n)
119
- if (t instanceof Mt)
117
+ _hasCropObject(scene) {
118
+ const objects = scene.getAllObjects();
119
+ for (const object of objects)
120
+ if (object instanceof ImageCropperObject)
120
121
  return !0;
121
122
  return !1;
122
123
  }
123
124
  // eslint-disable-next-line max-lines-per-function
124
- _popupMenuListener(e) {
125
- var o;
126
- const n = (o = this._renderManagerService.getRenderById(e)) == null ? void 0 : o.scene;
127
- if (!n)
125
+ _popupMenuListener(unitId) {
126
+ var _a8;
127
+ const scene = (_a8 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a8.scene;
128
+ if (!scene)
128
129
  return;
129
- const t = n.getTransformerByCreate();
130
- if (!t)
130
+ const transformer = scene.getTransformerByCreate();
131
+ if (!transformer)
131
132
  return;
132
- const r = [];
133
+ const disposePopups = [];
133
134
  this.disposeWithMe(
134
- ye(
135
- t.createControl$.subscribe(() => {
136
- if (this._hasCropObject(n))
135
+ toDisposable(
136
+ transformer.createControl$.subscribe(() => {
137
+ if (this._hasCropObject(scene))
137
138
  return;
138
- const a = t.getSelectedObjectMap();
139
- if (r.forEach((w) => w.dispose()), r.length = 0, a.size > 1)
139
+ const selectedObjects = transformer.getSelectedObjectMap();
140
+ if (disposePopups.forEach((dispose) => dispose.dispose()), disposePopups.length = 0, selectedObjects.size > 1)
140
141
  return;
141
- const s = a.values().next().value;
142
- if (!s)
142
+ const object = selectedObjects.values().next().value;
143
+ if (!object)
143
144
  return;
144
- const l = s.oKey, c = this._drawingManagerService.getDrawingOKey(l);
145
- if (!c)
145
+ const oKey = object.oKey, drawingParam = this._drawingManagerService.getDrawingOKey(oKey);
146
+ if (!drawingParam)
146
147
  return;
147
- const { unitId: m, subUnitId: u, drawingId: f } = c;
148
- r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s, {
149
- componentKey: yt,
148
+ const { unitId: unitId2, subUnitId, drawingId } = drawingParam;
149
+ disposePopups.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {
150
+ componentKey: COMPONENT_IMAGE_POPUP_MENU,
150
151
  direction: "horizontal",
151
152
  offset: [2, 0],
152
153
  extraProps: {
153
- menuItems: this._getImageMenuItems(m, u, f)
154
+ menuItems: this._getImageMenuItems(unitId2, subUnitId, drawingId)
154
155
  }
155
- }))), !this._drawingManagerService.getFocusDrawings().find((w) => w.unitId === m && w.subUnitId === u && w.drawingId === f) && this._drawingManagerService.focusDrawing([{
156
- unitId: m,
157
- subUnitId: u,
158
- drawingId: f
156
+ }))), !this._drawingManagerService.getFocusDrawings().find((drawing) => drawing.unitId === unitId2 && drawing.subUnitId === subUnitId && drawing.drawingId === drawingId) && this._drawingManagerService.focusDrawing([{
157
+ unitId: unitId2,
158
+ subUnitId,
159
+ drawingId
159
160
  }]);
160
161
  })
161
162
  )
162
163
  ), this.disposeWithMe(
163
- ye(
164
- t.clearControl$.subscribe(() => {
165
- r.forEach((a) => a.dispose()), r.length = 0, this._contextService.setContextValue(rn, !1), this._drawingManagerService.focusDrawing(null);
164
+ toDisposable(
165
+ transformer.clearControl$.subscribe(() => {
166
+ disposePopups.forEach((dispose) => dispose.dispose()), disposePopups.length = 0, this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !1), this._drawingManagerService.focusDrawing(null);
166
167
  })
167
168
  )
168
169
  ), this.disposeWithMe(
169
- ye(
170
- t.changing$.subscribe(() => {
171
- r.forEach((a) => a.dispose()), r.length = 0;
170
+ toDisposable(
171
+ transformer.changing$.subscribe(() => {
172
+ disposePopups.forEach((dispose) => dispose.dispose()), disposePopups.length = 0;
172
173
  })
173
174
  )
174
175
  ), this.disposeWithMe(
175
- ye(
176
- t.changeStart$.subscribe(() => {
177
- r.forEach((a) => a.dispose()), r.length = 0;
176
+ toDisposable(
177
+ transformer.changeStart$.subscribe(() => {
178
+ disposePopups.forEach((dispose) => dispose.dispose()), disposePopups.length = 0;
178
179
  })
179
180
  )
180
181
  );
181
182
  }
182
- _getImageMenuItems(e, n, t) {
183
+ _getImageMenuItems(unitId, subUnitId, drawingId) {
183
184
  return [
184
185
  {
185
186
  label: "image-popup.edit",
186
187
  index: 0,
187
- commandId: Kn.id,
188
- commandParams: { unitId: e, subUnitId: n, drawingId: t },
188
+ commandId: EditDocDrawingOperation.id,
189
+ commandParams: { unitId, subUnitId, drawingId },
189
190
  disable: !1
190
191
  },
191
192
  {
192
193
  label: "image-popup.delete",
193
194
  index: 1,
194
- commandId: vn.id,
195
- commandParams: { unitId: e, drawings: [{ unitId: e, subUnitId: n, drawingId: t }] },
195
+ commandId: RemoveDocDrawingCommand.id,
196
+ commandParams: { unitId, drawings: [{ unitId, subUnitId, drawingId }] },
196
197
  disable: !1
197
198
  },
198
199
  {
199
200
  label: "image-popup.crop",
200
201
  index: 2,
201
- commandId: bt.id,
202
- commandParams: { unitId: e, subUnitId: n, drawingId: t },
202
+ commandId: OpenImageCropOperation.id,
203
+ commandParams: { unitId, subUnitId, drawingId },
203
204
  disable: !0
204
205
  // TODO: @JOCS, feature is not ready.
205
206
  },
206
207
  {
207
208
  label: "image-popup.reset",
208
209
  index: 3,
209
- commandId: Rt.id,
210
- commandParams: [{ unitId: e, subUnitId: n, drawingId: t }],
210
+ commandId: ImageResetSizeOperation.id,
211
+ commandParams: [{ unitId, subUnitId, drawingId }],
211
212
  disable: !0
212
213
  // TODO: @JOCS, feature is not ready.
213
214
  }
214
215
  ];
215
216
  }
216
- };
217
- Je = di([
218
- sn(cn.Rendered, Je),
219
- ke(0, he),
220
- ke(1, pe(Xt)),
221
- ke(2, se),
222
- ke(3, ne),
223
- ke(4, Fn)
224
- ], Je);
225
- var ue = function() {
226
- return ue = Object.assign || function(i) {
227
- for (var e, n = 1, t = arguments.length; n < t; n++) {
228
- e = arguments[n];
229
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (i[r] = e[r]);
217
+ }, __name(_a, "DocDrawingPopupMenuController"), _a);
218
+ DocDrawingPopupMenuController = __decorateClass$6([
219
+ OnLifecycle(LifecycleStages.Rendered, DocDrawingPopupMenuController),
220
+ __decorateParam$6(0, IDrawingManagerService),
221
+ __decorateParam$6(1, Inject(DocCanvasPopManagerService)),
222
+ __decorateParam$6(2, IRenderManagerService),
223
+ __decorateParam$6(3, IUniverInstanceService),
224
+ __decorateParam$6(4, IContextService)
225
+ ], DocDrawingPopupMenuController);
226
+ var __assign = function() {
227
+ return __assign = Object.assign || function(t) {
228
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
229
+ s = arguments[i];
230
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
230
231
  }
231
- return i;
232
- }, ue.apply(this, arguments);
233
- }, mi = function(i, e) {
234
- var n = {};
235
- for (var t in i) Object.prototype.hasOwnProperty.call(i, t) && e.indexOf(t) < 0 && (n[t] = i[t]);
236
- if (i != null && typeof Object.getOwnPropertySymbols == "function")
237
- for (var r = 0, t = Object.getOwnPropertySymbols(i); r < t.length; r++)
238
- e.indexOf(t[r]) < 0 && Object.prototype.propertyIsEnumerable.call(i, t[r]) && (n[t[r]] = i[t[r]]);
239
- return n;
240
- }, Yn = jn(function(i, e) {
241
- var n = i.icon, t = i.id, r = i.className, o = i.extend, a = mi(i, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(t, " ").concat(r || "").trim(), l = $n("_".concat(fi()));
242
- return Zn(n, "".concat(t), { defIds: n.defIds, idSuffix: l.current }, ue({ ref: e, className: s }, a), o);
232
+ return t;
233
+ }, __assign.apply(this, arguments);
234
+ }, __rest = function(s, e) {
235
+ var t = {};
236
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
237
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
238
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
239
+ e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
240
+ return t;
241
+ }, IconBase = forwardRef(function(props, ref) {
242
+ var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
243
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
243
244
  });
244
- function Zn(i, e, n, t, r) {
245
- return zn(i.tag, ue(ue({ key: e }, gi(i, n, r)), t), (ui(i, n).children || []).map(function(o, a) {
246
- return Zn(o, "".concat(e, "-").concat(i.tag, "-").concat(a), n, void 0, r);
245
+ function render(node, id, runtimeProps, rootProps, extend) {
246
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
247
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
247
248
  }));
248
249
  }
249
- function gi(i, e, n) {
250
- var t = ue({}, i.attrs);
251
- n != null && n.colorChannel1 && t.fill === "colorChannel1" && (t.fill = n.colorChannel1);
252
- var r = e.defIds;
253
- return !r || r.length === 0 || (i.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + e.idSuffix), Object.entries(t).forEach(function(o) {
254
- var a = o[0], s = o[1];
255
- typeof s == "string" && (t[a] = s.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
256
- })), t;
250
+ __name(render, "render");
251
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
252
+ var attrs = __assign({}, node.attrs);
253
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
254
+ var defIds = runtimeProps.defIds;
255
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a8) {
256
+ var key = _a8[0], value = _a8[1];
257
+ typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
258
+ })), attrs;
257
259
  }
258
- function ui(i, e) {
259
- var n, t = e.defIds;
260
- return !t || t.length === 0 ? i : i.tag === "defs" && (!((n = i.children) === null || n === void 0) && n.length) ? ue(ue({}, i), { children: i.children.map(function(r) {
261
- return typeof r.attrs.id == "string" && t && t.indexOf(r.attrs.id) > -1 ? ue(ue({}, r), { attrs: ue(ue({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
262
- }) }) : i;
260
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
261
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
262
+ var _a8, defIds = runtimeProps.defIds;
263
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a8 = node.children) === null || _a8 === void 0) && _a8.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
264
+ return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
265
+ }) }) : node;
263
266
  }
264
- function fi() {
267
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
268
+ function generateShortUuid() {
265
269
  return Math.random().toString(36).substring(2, 8);
266
270
  }
267
- Yn.displayName = "UniverIcon";
268
- var pi = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, Qn = jn(function(i, e) {
269
- return zn(Yn, Object.assign({}, i, {
271
+ __name(generateShortUuid, "generateShortUuid");
272
+ IconBase.displayName = "UniverIcon";
273
+ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, AddImageSingle = forwardRef(function(props, ref) {
274
+ return createElement(IconBase, Object.assign({}, props, {
270
275
  id: "add-image-single",
271
- ref: e,
272
- icon: pi
276
+ ref,
277
+ icon: element
273
278
  }));
274
279
  });
275
- Qn.displayName = "AddImageSingle";
276
- const In = {
280
+ AddImageSingle.displayName = "AddImageSingle";
281
+ const InsertDocImageOperation = {
277
282
  id: "doc.operation.insert-float-image",
278
- type: Y.OPERATION,
279
- handler: () => !0
280
- }, hi = "univer-upload-file-menu", wi = "univer-upload-file-menu-input", xn = {
281
- uploadFileMenu: hi,
282
- uploadFileMenuInput: wi
283
- }, vi = () => {
284
- const i = re($), e = $n(null), n = () => {
285
- var o;
286
- (o = e.current) == null || o.click();
287
- }, t = xt.map((o) => `.${o.replace("image/", "")}`).join(","), r = (o) => {
288
- const a = o.target.files;
289
- if (a == null)
283
+ type: CommandType.OPERATION,
284
+ handler: /* @__PURE__ */ __name(() => !0, "handler")
285
+ }, uploadFileMenu = "univer-upload-file-menu", uploadFileMenuInput = "univer-upload-file-menu-input", styles$1 = {
286
+ uploadFileMenu,
287
+ uploadFileMenuInput
288
+ }, UploadFileMenu = /* @__PURE__ */ __name(() => {
289
+ const commandService = useDependency(ICommandService), fileInputRef = useRef(null), handleButtonClick = /* @__PURE__ */ __name(() => {
290
+ var _a8;
291
+ (_a8 = fileInputRef.current) == null || _a8.click();
292
+ }, "handleButtonClick"), imageAccept = DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(","), handleFileChange = /* @__PURE__ */ __name((event) => {
293
+ const fileList = event.target.files;
294
+ if (fileList == null)
290
295
  return;
291
- const s = Array.from(a);
292
- i.executeCommand(In.id, { files: s }), e.current && (e.current.value = "");
293
- };
294
- return /* @__PURE__ */ d.createElement("div", { onClick: n, className: xn.uploadFileMenu }, /* @__PURE__ */ d.createElement(
296
+ const files = Array.from(fileList);
297
+ commandService.executeCommand(InsertDocImageOperation.id, { files }), fileInputRef.current && (fileInputRef.current.value = "");
298
+ }, "handleFileChange");
299
+ return /* @__PURE__ */ React.createElement("div", { onClick: handleButtonClick, className: styles$1.uploadFileMenu }, /* @__PURE__ */ React.createElement(
295
300
  "input",
296
301
  {
297
302
  type: "file",
298
- className: xn.uploadFileMenuInput,
299
- ref: e,
300
- onChange: r,
301
- accept: t,
303
+ className: styles$1.uploadFileMenuInput,
304
+ ref: fileInputRef,
305
+ onChange: handleFileChange,
306
+ accept: imageAccept,
302
307
  multiple: !0
303
308
  }
304
309
  ));
305
- }, Jn = "COMPONENT_DOC_UPLOAD_FILE_MENU", et = "addition-and-subtraction-single", nt = "doc.menu.image", Ii = "doc.menu.image.upload.float";
306
- function _i(i) {
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");
334
+ function ImageMenuFactory(accessor) {
307
335
  return {
308
- id: nt,
309
- type: Gn.SUBITEMS,
310
- positions: [ei.TOOLBAR_START],
311
- group: ni.TOOLBAR_LAYOUT,
312
- icon: et,
336
+ id: IMAGE_MENU_ID,
337
+ type: MenuItemType.SUBITEMS,
338
+ positions: [MenuPosition.TOOLBAR_START],
339
+ group: MenuGroup.TOOLBAR_LAYOUT,
340
+ icon: ImageUploadIcon,
313
341
  tooltip: "docImage.title",
314
- hidden$: Vn(i, be.UNIVER_DOC)
342
+ disabled$: getDisableWhenSelectionInTableObservable(accessor),
343
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
315
344
  };
316
345
  }
317
- function Ci(i) {
346
+ __name(ImageMenuFactory, "ImageMenuFactory");
347
+ function UploadFloatImageMenuFactory(_accessor) {
318
348
  return {
319
- id: Ii,
349
+ id: IMAGE_MENU_UPLOAD_FLOAT_ID,
320
350
  title: "docImage.upload.float",
321
- type: Gn.SELECTOR,
351
+ type: MenuItemType.SELECTOR,
322
352
  label: {
323
- name: Jn
353
+ name: COMPONENT_DOC_UPLOAD_FILE_MENU
324
354
  },
325
- positions: [nt],
326
- hidden$: Vn(i, be.UNIVER_DOC)
355
+ positions: [IMAGE_MENU_ID],
356
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC)
327
357
  };
328
358
  }
329
- const Si = "univer-image-common-panel", Di = "univer-image-common-panel-grid", Ei = "univer-image-common-panel-border", Pi = "univer-image-common-panel-title", Oi = "univer-image-common-panel-subtitle", Ti = "univer-image-common-panel-row", Mi = "univer-image-common-panel-row-vertical", yi = "univer-image-common-panel-column", bi = "univer-image-common-panel-column-center", Ri = "univer-image-common-panel-inline", Ni = "univer-image-common-panel-span2", Ai = "univer-image-common-panel-span3", xi = "univer-image-common-panel-input", Li = "univer-sheet-image-menu", Ui = "univer-sheet-image-menu-input", g = {
330
- imageCommonPanel: Si,
331
- imageCommonPanelGrid: Di,
332
- imageCommonPanelBorder: Ei,
333
- imageCommonPanelTitle: Pi,
334
- imageCommonPanelSubtitle: Oi,
335
- imageCommonPanelRow: Ti,
336
- imageCommonPanelRowVertical: Mi,
337
- imageCommonPanelColumn: yi,
338
- imageCommonPanelColumnCenter: bi,
339
- imageCommonPanelInline: Ri,
340
- imageCommonPanelSpan2: Ni,
341
- imageCommonPanelSpan3: Ai,
342
- imageCommonPanelInput: xi,
343
- sheetImageMenu: Li,
344
- sheetImageMenuInput: Ui
345
- };
346
- class ln {
359
+ __name(UploadFloatImageMenuFactory, "UploadFloatImageMenuFactory");
360
+ const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "univer-image-common-panel-grid", imageCommonPanelBorder = "univer-image-common-panel-border", imageCommonPanelTitle = "univer-image-common-panel-title", imageCommonPanelSubtitle = "univer-image-common-panel-subtitle", imageCommonPanelRow = "univer-image-common-panel-row", imageCommonPanelRowVertical = "univer-image-common-panel-row-vertical", imageCommonPanelColumn = "univer-image-common-panel-column", imageCommonPanelColumnCenter = "univer-image-common-panel-column-center", imageCommonPanelInline = "univer-image-common-panel-inline", imageCommonPanelSpan2 = "univer-image-common-panel-span2", imageCommonPanelSpan3 = "univer-image-common-panel-span3", imageCommonPanelInput = "univer-image-common-panel-input", sheetImageMenu = "univer-sheet-image-menu", sheetImageMenuInput = "univer-sheet-image-menu-input", styles = {
361
+ imageCommonPanel,
362
+ imageCommonPanelGrid,
363
+ imageCommonPanelBorder,
364
+ imageCommonPanelTitle,
365
+ imageCommonPanelSubtitle,
366
+ imageCommonPanelRow,
367
+ imageCommonPanelRowVertical,
368
+ imageCommonPanelColumn,
369
+ imageCommonPanelColumnCenter,
370
+ imageCommonPanelInline,
371
+ imageCommonPanelSpan2,
372
+ imageCommonPanelSpan3,
373
+ imageCommonPanelInput,
374
+ sheetImageMenu,
375
+ sheetImageMenuInput
376
+ }, _DocRefreshDrawingsService = class _DocRefreshDrawingsService {
347
377
  constructor() {
348
- _e(this, "_refreshDrawings$", new qt(null));
349
- _e(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
378
+ __publicField(this, "_refreshDrawings$", new BehaviorSubject(null));
379
+ __publicField(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
350
380
  }
351
- refreshDrawings(e) {
352
- this._refreshDrawings$.next(e);
381
+ refreshDrawings(skeleton) {
382
+ this._refreshDrawings$.next(skeleton);
353
383
  }
354
- }
355
- var me = /* @__PURE__ */ ((i) => (i.INLINE = "inline", i.BEHIND_TEXT = "behindText", i.IN_FRONT_OF_TEXT = "inFrontOfText", i.WRAP_SQUARE = "wrapSquare", i.WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom", i))(me || {});
356
- const Bi = {
357
- inline: k.INLINE,
358
- wrapSquare: k.WRAP_SQUARE,
359
- wrapTopAndBottom: k.WRAP_TOP_AND_BOTTOM,
360
- inFrontOfText: k.WRAP_NONE,
361
- behindText: k.WRAP_NONE
362
384
  };
363
- function tt(i, e, n, t, r, o, a) {
364
- var h, p;
365
- const s = new hn(), l = X.getInstance(), c = [], m = o.getSelfOrHeaderFooterModel(e).getBody(), u = o.getSelfOrHeaderFooterModel(i).getBody();
366
- if (m == null || u == null)
385
+ __name(_DocRefreshDrawingsService, "DocRefreshDrawingsService");
386
+ let DocRefreshDrawingsService = _DocRefreshDrawingsService;
387
+ var TextWrappingStyle = /* @__PURE__ */ ((TextWrappingStyle2) => (TextWrappingStyle2.INLINE = "inline", TextWrappingStyle2.BEHIND_TEXT = "behindText", TextWrappingStyle2.IN_FRONT_OF_TEXT = "inFrontOfText", TextWrappingStyle2.WRAP_SQUARE = "wrapSquare", TextWrappingStyle2.WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom", TextWrappingStyle2))(TextWrappingStyle || {});
388
+ const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
389
+ inline: PositionedObjectLayoutType.INLINE,
390
+ wrapSquare: PositionedObjectLayoutType.WRAP_SQUARE,
391
+ wrapTopAndBottom: PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,
392
+ inFrontOfText: PositionedObjectLayoutType.WRAP_NONE,
393
+ behindText: PositionedObjectLayoutType.WRAP_NONE
394
+ };
395
+ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel, textSelectionRenderManager) {
396
+ var _a8, _b;
397
+ const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], oldBody = documentDataModel.getSelfOrHeaderFooterModel(oldSegmentId).getBody(), body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
398
+ if (oldBody == null || body == null)
367
399
  return;
368
- const f = (p = (h = m.customBlocks) == null ? void 0 : h.find((w) => w.blockId === r)) == null ? void 0 : p.startIndex;
369
- if (f != null) {
370
- if (t = Math.min(u.dataStream.length - 2, t), i === e) {
371
- if (t < f ? (t > 0 && s.push({
372
- t: Z.RETAIN,
373
- len: t,
374
- segmentId: e
375
- }), s.push({
376
- t: Z.INSERT,
400
+ const oldOffset = (_b = (_a8 = oldBody.customBlocks) == null ? void 0 : _a8.find((block) => block.blockId === drawingId)) == null ? void 0 : _b.startIndex;
401
+ if (oldOffset != null) {
402
+ if (offset = Math.min(body.dataStream.length - 2, offset), segmentId === oldSegmentId) {
403
+ if (offset < oldOffset ? (offset > 0 && textX.push({
404
+ t: TextXActionType.RETAIN,
405
+ len: offset,
406
+ segmentId: oldSegmentId
407
+ }), textX.push({
408
+ t: TextXActionType.INSERT,
377
409
  body: {
378
410
  dataStream: "\b",
379
411
  customBlocks: [{
380
412
  startIndex: 0,
381
- blockId: r
413
+ blockId: drawingId
382
414
  }]
383
415
  },
384
416
  len: 1,
385
417
  line: 0,
386
- segmentId: e
387
- }), s.push({
388
- t: Z.RETAIN,
389
- len: f - t,
390
- segmentId: e
391
- }), s.push({
392
- t: Z.DELETE,
418
+ segmentId: oldSegmentId
419
+ }), textX.push({
420
+ t: TextXActionType.RETAIN,
421
+ len: oldOffset - offset,
422
+ segmentId: oldSegmentId
423
+ }), textX.push({
424
+ t: TextXActionType.DELETE,
393
425
  len: 1,
394
426
  line: 0,
395
427
  segmentId: ""
396
- })) : (f > 0 && s.push({
397
- t: Z.RETAIN,
398
- len: f,
399
- segmentId: e
400
- }), s.push({
401
- t: Z.DELETE,
428
+ })) : (oldOffset > 0 && textX.push({
429
+ t: TextXActionType.RETAIN,
430
+ len: oldOffset,
431
+ segmentId: oldSegmentId
432
+ }), textX.push({
433
+ t: TextXActionType.DELETE,
402
434
  len: 1,
403
435
  line: 0,
404
436
  segmentId: ""
405
- }), t - f - 1 > 0 && s.push({
406
- t: Z.RETAIN,
407
- len: t - f - 1,
408
- segmentId: e
409
- }), s.push({
410
- t: Z.INSERT,
437
+ }), offset - oldOffset - 1 > 0 && textX.push({
438
+ t: TextXActionType.RETAIN,
439
+ len: offset - oldOffset - 1,
440
+ segmentId: oldSegmentId
441
+ }), textX.push({
442
+ t: TextXActionType.INSERT,
411
443
  body: {
412
444
  dataStream: "\b",
413
445
  customBlocks: [{
414
446
  startIndex: 0,
415
- blockId: r
447
+ blockId: drawingId
416
448
  }]
417
449
  },
418
450
  len: 1,
419
451
  line: 0,
420
- segmentId: e
421
- })), t !== f) {
422
- const w = $e(o, e), v = l.editOp(s.serialize(), w);
423
- c.push(v);
452
+ segmentId: oldSegmentId
453
+ })), offset !== oldOffset) {
454
+ const path = getRichTextEditPath(documentDataModel, oldSegmentId), action = jsonX.editOp(textX.serialize(), path);
455
+ rawActions.push(action);
424
456
  }
425
457
  } else {
426
- f > 0 && s.push({
427
- t: Z.RETAIN,
428
- len: f,
429
- segmentId: e
430
- }), s.push({
431
- t: Z.DELETE,
458
+ oldOffset > 0 && textX.push({
459
+ t: TextXActionType.RETAIN,
460
+ len: oldOffset,
461
+ segmentId: oldSegmentId
462
+ }), textX.push({
463
+ t: TextXActionType.DELETE,
432
464
  len: 1,
433
465
  line: 0,
434
466
  segmentId: ""
435
467
  });
436
- let w = $e(o, e), v = l.editOp(s.serialize(), w);
437
- c.push(v), s.empty(), t > 0 && s.push({
438
- t: Z.RETAIN,
439
- len: t,
440
- segmentId: i
441
- }), s.push({
442
- t: Z.INSERT,
468
+ let path = getRichTextEditPath(documentDataModel, oldSegmentId), action = jsonX.editOp(textX.serialize(), path);
469
+ rawActions.push(action), textX.empty(), offset > 0 && textX.push({
470
+ t: TextXActionType.RETAIN,
471
+ len: offset,
472
+ segmentId
473
+ }), textX.push({
474
+ t: TextXActionType.INSERT,
443
475
  body: {
444
476
  dataStream: "\b",
445
477
  customBlocks: [{
446
478
  startIndex: 0,
447
- blockId: r
479
+ blockId: drawingId
448
480
  }]
449
481
  },
450
482
  len: 1,
451
483
  line: 0,
452
- segmentId: i
453
- }), w = $e(o, i), v = l.editOp(s.serialize(), w), c.push(v), a.setSegment(i), a.setSegmentPage(n);
484
+ segmentId
485
+ }), path = getRichTextEditPath(documentDataModel, segmentId), action = jsonX.editOp(textX.serialize(), path), rawActions.push(action), textSelectionRenderManager.setSegment(segmentId), textSelectionRenderManager.setSegmentPage(segmentPage);
454
486
  }
455
- return c;
487
+ return rawActions;
456
488
  }
457
489
  }
458
- const it = {
490
+ __name(getDeleteAndInsertCustomBlockActions, "getDeleteAndInsertCustomBlockActions");
491
+ const UpdateDocDrawingWrappingStyleCommand = {
459
492
  id: "doc.command.update-doc-drawing-wrapping-style",
460
- type: Y.COMMAND,
493
+ type: CommandType.COMMAND,
461
494
  // eslint-disable-next-line max-lines-per-function, complexity
462
- handler: (i, e) => {
463
- var T, N;
464
- if (e == null)
495
+ handler: /* @__PURE__ */ __name((accessor, params) => {
496
+ var _a8, _b;
497
+ if (params == null)
465
498
  return !1;
466
- const { drawings: n, wrappingStyle: t, unitId: r } = e, o = i.get($), a = i.get(ne), l = i.get(se).getRenderById(r), c = l == null ? void 0 : l.with(ae).getSkeleton().getSkeletonData(), m = l == null ? void 0 : l.with(ae).getViewModel(), u = l == null ? void 0 : l.scene, f = a.getCurrentUniverDocInstance();
467
- if (f == null || c == null || u == null || m == null)
499
+ const { drawings, wrappingStyle, unitId } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderObject = accessor.get(IRenderManagerService).getRenderById(unitId), skeletonData = renderObject == null ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton().getSkeletonData(), viewModel = renderObject == null ? void 0 : renderObject.with(DocSkeletonManagerService).getViewModel(), scene = renderObject == null ? void 0 : renderObject.scene, documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
500
+ if (documentDataModel == null || skeletonData == null || scene == null || viewModel == null)
468
501
  return !1;
469
- const h = m.getEditArea(), p = u.getTransformerByCreate(), { pages: w, skeHeaders: v, skeFooters: I } = c, D = X.getInstance(), _ = [], { drawings: C = {} } = f.getSnapshot();
470
- for (const R of n) {
471
- const { drawingId: E } = R, H = C[E].layoutType, z = Bi[t];
472
- if (H !== z) {
473
- const S = D.replaceOp(["drawings", E, "layoutType"], H, z);
474
- _.push(S);
502
+ const editArea = viewModel.getEditArea(), transformer = scene.getTransformerByCreate(), { pages, skeHeaders, skeFooters } = skeletonData, jsonX = JSONX.getInstance(), rawActions = [], { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
503
+ for (const drawing of drawings) {
504
+ const { drawingId } = drawing, oldLayoutType = oldDrawings[drawingId].layoutType, newLayoutType = WRAPPING_STYLE_TO_LAYOUT_TYPE[wrappingStyle];
505
+ if (oldLayoutType !== newLayoutType) {
506
+ const updateLayoutTypeAction = jsonX.replaceOp(["drawings", drawingId, "layoutType"], oldLayoutType, newLayoutType);
507
+ rawActions.push(updateLayoutTypeAction);
475
508
  }
476
- if (t === "behindText" || t === "inFrontOfText") {
477
- const S = C[E].behindDoc, A = t === "behindText" ? oe.TRUE : oe.FALSE;
478
- if (S !== A) {
479
- const P = D.replaceOp(["drawings", E, "behindDoc"], S, A);
480
- _.push(P);
509
+ if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
510
+ const oldBehindDoc = oldDrawings[drawingId].behindDoc, newBehindDoc = wrappingStyle === "behindText" ? BooleanNumber.TRUE : BooleanNumber.FALSE;
511
+ if (oldBehindDoc !== newBehindDoc) {
512
+ const updateBehindDocAction = jsonX.replaceOp(["drawings", drawingId, "behindDoc"], oldBehindDoc, newBehindDoc);
513
+ rawActions.push(updateBehindDocAction);
481
514
  }
482
515
  }
483
- if (t === "inline")
516
+ if (wrappingStyle === "inline")
484
517
  continue;
485
- let U = null, B = 0, b = 0;
486
- for (const S of w) {
487
- const { headerId: A, footerId: P, marginTop: L, marginLeft: x, marginBottom: M, pageWidth: W, pageHeight: G } = S;
488
- switch (h) {
489
- case xe.HEADER: {
490
- const F = (T = v.get(A)) == null ? void 0 : T.get(W);
491
- F != null && F.skeDrawings.has(E) && (U = F.skeDrawings.get(E), B = F.marginTop, b = x);
518
+ let skeDrawing = null, pageMarginTop = 0, pageMarginLeft = 0;
519
+ for (const page of pages) {
520
+ const { headerId, footerId, marginTop, marginLeft, marginBottom, pageWidth, pageHeight } = page;
521
+ switch (editArea) {
522
+ case DocumentEditArea.HEADER: {
523
+ const headerSke = (_a8 = skeHeaders.get(headerId)) == null ? void 0 : _a8.get(pageWidth);
524
+ headerSke != null && headerSke.skeDrawings.has(drawingId) && (skeDrawing = headerSke.skeDrawings.get(drawingId), pageMarginTop = headerSke.marginTop, pageMarginLeft = marginLeft);
492
525
  break;
493
526
  }
494
- case xe.FOOTER: {
495
- const F = (N = I.get(P)) == null ? void 0 : N.get(W);
496
- F != null && F.skeDrawings.has(E) && (U = F.skeDrawings.get(E), B = G - M + F.marginTop, b = x);
527
+ case DocumentEditArea.FOOTER: {
528
+ const footerSke = (_b = skeFooters.get(footerId)) == null ? void 0 : _b.get(pageWidth);
529
+ footerSke != null && footerSke.skeDrawings.has(drawingId) && (skeDrawing = footerSke.skeDrawings.get(drawingId), pageMarginTop = pageHeight - marginBottom + footerSke.marginTop, pageMarginLeft = marginLeft);
497
530
  break;
498
531
  }
499
- case xe.BODY: {
500
- S.skeDrawings.has(E) && (U = S.skeDrawings.get(E), B = L, b = x);
532
+ case DocumentEditArea.BODY: {
533
+ page.skeDrawings.has(drawingId) && (skeDrawing = page.skeDrawings.get(drawingId), pageMarginTop = marginTop, pageMarginLeft = marginLeft);
501
534
  break;
502
535
  }
503
536
  }
504
- if (U != null)
537
+ if (skeDrawing != null)
505
538
  break;
506
539
  }
507
- if (U != null) {
508
- const { aTop: S, aLeft: A } = U, P = C[E].docTransform.positionH;
509
- let L = A;
510
- P.relativeFrom === ee.MARGIN ? L -= b : P.relativeFrom === ee.COLUMN && (L -= U.columnLeft);
511
- const x = {
512
- relativeFrom: P.relativeFrom,
513
- posOffset: L
540
+ if (skeDrawing != null) {
541
+ const { aTop, aLeft } = skeDrawing, oldPositionH = oldDrawings[drawingId].docTransform.positionH;
542
+ let posOffsetH = aLeft;
543
+ oldPositionH.relativeFrom === ObjectRelativeFromH.MARGIN ? posOffsetH -= pageMarginLeft : oldPositionH.relativeFrom === ObjectRelativeFromH.COLUMN && (posOffsetH -= skeDrawing.columnLeft);
544
+ const newPositionH = {
545
+ relativeFrom: oldPositionH.relativeFrom,
546
+ posOffset: posOffsetH
514
547
  };
515
- if (P.posOffset !== x.posOffset) {
516
- const F = D.replaceOp(["drawings", E, "docTransform", "positionH"], P, x);
517
- _.push(F);
548
+ if (oldPositionH.posOffset !== newPositionH.posOffset) {
549
+ const action = jsonX.replaceOp(["drawings", drawingId, "docTransform", "positionH"], oldPositionH, newPositionH);
550
+ rawActions.push(action);
518
551
  }
519
- const M = C[E].docTransform.positionV;
520
- let W = S;
521
- M.relativeFrom === V.PAGE ? W += B : M.relativeFrom === V.LINE ? W -= U.lineTop : M.relativeFrom === V.PARAGRAPH && (W -= U.blockAnchorTop);
522
- const G = {
523
- relativeFrom: M.relativeFrom,
524
- posOffset: W
552
+ const oldPositionV = oldDrawings[drawingId].docTransform.positionV;
553
+ let posOffsetV = aTop;
554
+ oldPositionV.relativeFrom === ObjectRelativeFromV.PAGE ? posOffsetV += pageMarginTop : oldPositionV.relativeFrom === ObjectRelativeFromV.LINE ? posOffsetV -= skeDrawing.lineTop : oldPositionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH && (posOffsetV -= skeDrawing.blockAnchorTop);
555
+ const newPositionV = {
556
+ relativeFrom: oldPositionV.relativeFrom,
557
+ posOffset: posOffsetV
525
558
  };
526
- if (M.posOffset !== G.posOffset) {
527
- const F = D.replaceOp(["drawings", E, "docTransform", "positionV"], M, G);
528
- _.push(F);
559
+ if (oldPositionV.posOffset !== newPositionV.posOffset) {
560
+ const action = jsonX.replaceOp(["drawings", drawingId, "docTransform", "positionV"], oldPositionV, newPositionV);
561
+ rawActions.push(action);
529
562
  }
530
563
  }
531
564
  }
532
- const O = {
533
- id: Q.id,
565
+ const doMutation = {
566
+ id: RichTextEditingMutation.id,
534
567
  params: {
535
- unitId: r,
568
+ unitId,
536
569
  actions: [],
537
570
  textRanges: null
538
571
  }
539
572
  };
540
- O.params.actions = _.reduce((R, E) => X.compose(R, E), null);
541
- const y = o.syncExecuteCommand(O.id, O.params);
542
- return p.refreshControls(), !!y;
543
- }
544
- }, rt = {
573
+ doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
574
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
575
+ return transformer.refreshControls(), !!result;
576
+ }, "handler")
577
+ }, UpdateDocDrawingDistanceCommand = {
545
578
  id: "doc.command.update-doc-drawing-distance",
546
- type: Y.COMMAND,
547
- handler: (i, e) => {
548
- if (e == null)
579
+ type: CommandType.COMMAND,
580
+ handler: /* @__PURE__ */ __name((accessor, params) => {
581
+ if (params == null)
549
582
  return !1;
550
- const n = i.get($), r = i.get(ne).getCurrentUniverDocInstance();
551
- if (r == null)
583
+ const commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
584
+ if (documentDataModel == null)
552
585
  return !1;
553
- const { drawings: o, dist: a, unitId: s } = e, l = X.getInstance(), c = [], { drawings: m = {} } = r.getSnapshot();
554
- for (const h of o) {
555
- const { drawingId: p } = h;
556
- for (const [w, v] of Object.entries(a)) {
557
- const I = m[p][w];
558
- if (I !== v) {
559
- const D = l.replaceOp(["drawings", p, w], I, v);
560
- c.push(D);
586
+ const { drawings, dist, unitId } = params, jsonX = JSONX.getInstance(), rawActions = [], { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
587
+ for (const drawing of drawings) {
588
+ const { drawingId } = drawing;
589
+ for (const [key, value] of Object.entries(dist)) {
590
+ const oldValue = oldDrawings[drawingId][key];
591
+ if (oldValue !== value) {
592
+ const action = jsonX.replaceOp(["drawings", drawingId, key], oldValue, value);
593
+ rawActions.push(action);
561
594
  }
562
595
  }
563
596
  }
564
- const u = {
565
- id: Q.id,
597
+ const doMutation = {
598
+ id: RichTextEditingMutation.id,
566
599
  params: {
567
- unitId: s,
600
+ unitId,
568
601
  actions: [],
569
602
  textRanges: null
570
603
  }
571
604
  };
572
- return u.params.actions = c.reduce((h, p) => X.compose(h, p), null), !!n.syncExecuteCommand(u.id, u.params);
573
- }
574
- }, ot = {
605
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
606
+ }, "handler")
607
+ }, UpdateDocDrawingWrapTextCommand = {
575
608
  id: "doc.command.update-doc-drawing-wrap-text",
576
- type: Y.COMMAND,
577
- handler: (i, e) => {
578
- if (e == null)
609
+ type: CommandType.COMMAND,
610
+ handler: /* @__PURE__ */ __name((accessor, params) => {
611
+ if (params == null)
579
612
  return !1;
580
- const n = i.get($), r = i.get(ne).getCurrentUniverDocInstance();
581
- if (r == null)
613
+ const commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
614
+ if (documentDataModel == null)
582
615
  return !1;
583
- const { drawings: o, wrapText: a, unitId: s } = e, l = X.getInstance(), c = [], { drawings: m = {} } = r.getSnapshot();
584
- for (const h of o) {
585
- const { drawingId: p } = h, w = m[p].wrapText;
586
- if (w !== a) {
587
- const v = l.replaceOp(["drawings", p, "wrapText"], w, a);
588
- c.push(v);
616
+ const { drawings, wrapText, unitId } = params, jsonX = JSONX.getInstance(), rawActions = [], { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
617
+ for (const drawing of drawings) {
618
+ const { drawingId } = drawing, oldWrapText = oldDrawings[drawingId].wrapText;
619
+ if (oldWrapText !== wrapText) {
620
+ const action = jsonX.replaceOp(["drawings", drawingId, "wrapText"], oldWrapText, wrapText);
621
+ rawActions.push(action);
589
622
  }
590
623
  }
591
- const u = {
592
- id: Q.id,
624
+ const doMutation = {
625
+ id: RichTextEditingMutation.id,
593
626
  params: {
594
- unitId: s,
627
+ unitId,
595
628
  actions: [],
596
629
  textRanges: null
597
630
  }
598
631
  };
599
- return u.params.actions = c.reduce((h, p) => X.compose(h, p), null), !!n.syncExecuteCommand(u.id, u.params);
600
- }
601
- }, ze = {
632
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
633
+ }, "handler")
634
+ }, UpdateDrawingDocTransformCommand = {
602
635
  id: "doc.command.update-drawing-doc-transform",
603
- type: Y.COMMAND,
604
- handler: (i, e) => {
605
- if (e == null)
636
+ type: CommandType.COMMAND,
637
+ handler: /* @__PURE__ */ __name((accessor, params) => {
638
+ if (params == null)
606
639
  return !1;
607
- const n = i.get($), t = i.get(ne), o = i.get(se).getRenderById(e.unitId), a = o == null ? void 0 : o.scene;
608
- if (a == null)
640
+ const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderObject = accessor.get(IRenderManagerService).getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene;
641
+ if (scene == null)
609
642
  return !1;
610
- const s = a.getTransformerByCreate(), l = t.getCurrentUniverDocInstance();
611
- if (l == null)
643
+ const transformer = scene.getTransformerByCreate(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
644
+ if (documentDataModel == null)
612
645
  return !1;
613
- const { drawings: c, unitId: m } = e, u = X.getInstance(), f = [], { drawings: h = {} } = l.getSnapshot();
614
- for (const v of c) {
615
- const { drawingId: I, key: D, value: _ } = v, C = h[I].docTransform[D];
616
- if (!Pe.diffValue(C, _)) {
617
- const O = u.replaceOp(["drawings", I, "docTransform", D], C, _);
618
- f.push(O);
646
+ const { drawings, unitId } = params, jsonX = JSONX.getInstance(), rawActions = [], { drawings: oldDrawings = {} } = documentDataModel.getSnapshot();
647
+ for (const drawing of drawings) {
648
+ const { drawingId, key, value } = drawing, oldValue = oldDrawings[drawingId].docTransform[key];
649
+ if (!Tools.diffValue(oldValue, value)) {
650
+ const action = jsonX.replaceOp(["drawings", drawingId, "docTransform", key], oldValue, value);
651
+ rawActions.push(action);
619
652
  }
620
653
  }
621
- const p = {
622
- id: Q.id,
654
+ const doMutation = {
655
+ id: RichTextEditingMutation.id,
623
656
  params: {
624
- unitId: m,
657
+ unitId,
625
658
  actions: [],
626
659
  textRanges: null,
627
660
  debounce: !0
628
661
  }
629
662
  };
630
- p.params.actions = f.reduce((v, I) => X.compose(v, I), null);
631
- const w = n.syncExecuteCommand(p.id, p.params);
632
- return s.refreshControls(), !!w;
633
- }
634
- }, at = {
663
+ doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
664
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
665
+ return transformer.refreshControls(), !!result;
666
+ }, "handler")
667
+ }, IMoveInlineDrawingCommand = {
635
668
  id: "doc.command.move-inline-drawing",
636
- type: Y.COMMAND,
637
- handler: (i, e) => {
638
- var T;
639
- if (e == null)
669
+ type: CommandType.COMMAND,
670
+ handler: /* @__PURE__ */ __name((accessor, params) => {
671
+ var _a8;
672
+ if (params == null)
640
673
  return !1;
641
- const n = i.get(se), t = i.get(Ue), r = i.get(ln), o = n.getRenderById(e.unitId), a = o == null ? void 0 : o.scene, s = o == null ? void 0 : o.with(ae).getSkeleton();
642
- if (a == null)
674
+ const renderManagerService = accessor.get(IRenderManagerService), textSelectionRenderManager = accessor.get(ITextSelectionRenderManager), docRefreshDrawingsService = accessor.get(DocRefreshDrawingsService), renderObject = renderManagerService.getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene, skeleton = renderObject == null ? void 0 : renderObject.with(DocSkeletonManagerService).getSkeleton();
675
+ if (scene == null)
643
676
  return !1;
644
- const l = a.getTransformerByCreate(), c = i.get($), u = i.get(ne).getCurrentUniverDocInstance();
645
- if (u == null)
677
+ const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
678
+ if (documentDataModel == null)
646
679
  return !1;
647
- const { drawing: f, unitId: h, offset: p, segmentId: w, segmentPage: v } = e, I = [], { drawingId: D } = f, _ = (T = t.getSegment()) != null ? T : "", C = tt(
648
- w,
649
- _,
650
- v,
651
- p,
652
- D,
653
- u,
654
- t
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(
684
+ newSegmentId,
685
+ segmentId,
686
+ segmentPage,
687
+ offset,
688
+ drawingId,
689
+ documentDataModel,
690
+ textSelectionRenderManager
655
691
  );
656
- if (C == null || C.length === 0)
657
- return r.refreshDrawings(s), l.refreshControls(), !1;
658
- I.push(...C);
659
- const O = {
660
- id: Q.id,
692
+ if (actions == null || actions.length === 0)
693
+ return docRefreshDrawingsService.refreshDrawings(skeleton), transformer.refreshControls(), !1;
694
+ rawActions.push(...actions);
695
+ const doMutation = {
696
+ id: RichTextEditingMutation.id,
661
697
  params: {
662
- unitId: h,
698
+ unitId,
663
699
  actions: [],
664
700
  textRanges: null
665
701
  }
666
702
  };
667
- O.params.actions = I.reduce((N, R) => X.compose(N, R), null);
668
- const y = c.syncExecuteCommand(O.id, O.params);
669
- return l.refreshControls(), !!y;
670
- }
671
- }, st = {
703
+ doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
704
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
705
+ return transformer.refreshControls(), !!result;
706
+ }, "handler")
707
+ }, ITransformNonInlineDrawingCommand = {
672
708
  id: "doc.command.transform-non-inline-drawing",
673
- type: Y.COMMAND,
709
+ type: CommandType.COMMAND,
674
710
  // eslint-disable-next-line max-lines-per-function
675
- handler: (i, e) => {
676
- var U;
677
- if (e == null)
711
+ handler: /* @__PURE__ */ __name((accessor, params) => {
712
+ var _a8;
713
+ if (params == null)
678
714
  return !1;
679
- const n = i.get(Ue), r = i.get(se).getRenderById(e.unitId), o = r == null ? void 0 : r.scene;
680
- if (o == null)
715
+ const textSelectionRenderManager = accessor.get(ITextSelectionRenderManager), renderObject = accessor.get(IRenderManagerService).getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene;
716
+ if (scene == null)
681
717
  return !1;
682
- const a = o.getTransformerByCreate(), s = i.get($), c = i.get(ne).getCurrentUniverDocInstance();
683
- if (c == null)
718
+ const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
719
+ if (documentDataModel == null)
684
720
  return !1;
685
- const { drawing: m, unitId: u, offset: f, docTransform: h, segmentId: p, segmentPage: w } = e, v = [], { drawingId: I } = m, D = (U = n.getSegment()) != null ? U : "", _ = tt(
686
- p,
687
- D,
688
- w,
689
- f,
690
- I,
691
- c,
692
- n
721
+ const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params, rawActions = [], { drawingId } = drawing, segmentId = (_a8 = textSelectionRenderManager.getSegment()) != null ? _a8 : "", actions = getDeleteAndInsertCustomBlockActions(
722
+ newSegmentId,
723
+ segmentId,
724
+ segmentPage,
725
+ offset,
726
+ drawingId,
727
+ documentDataModel,
728
+ textSelectionRenderManager
693
729
  );
694
- if (_ == null)
730
+ if (actions == null)
695
731
  return !1;
696
- _.length > 0 && v.push(..._);
697
- const C = X.getInstance(), { drawings: O = {} } = c.getSnapshot(), y = O[I].docTransform, { positionH: T, positionV: N, size: R, angle: E } = y;
698
- if (!Pe.diffValue(T, h.positionH)) {
699
- const B = C.replaceOp(["drawings", I, "docTransform", "positionH"], T, h.positionH);
700
- v.push(B);
732
+ actions.length > 0 && rawActions.push(...actions);
733
+ const jsonX = JSONX.getInstance(), { drawings: oldDrawings = {} } = documentDataModel.getSnapshot(), oldDocTransform = oldDrawings[drawingId].docTransform, { positionH: oldPositionH, positionV: oldPositionV, size: oldSize, angle: oldAngle } = oldDocTransform;
734
+ if (!Tools.diffValue(oldPositionH, docTransform.positionH)) {
735
+ const updateAction = jsonX.replaceOp(["drawings", drawingId, "docTransform", "positionH"], oldPositionH, docTransform.positionH);
736
+ rawActions.push(updateAction);
701
737
  }
702
- if (!Pe.diffValue(N, h.positionV)) {
703
- const B = C.replaceOp(["drawings", I, "docTransform", "positionV"], N, h.positionV);
704
- v.push(B);
738
+ if (!Tools.diffValue(oldPositionV, docTransform.positionV)) {
739
+ const updateAction = jsonX.replaceOp(["drawings", drawingId, "docTransform", "positionV"], oldPositionV, docTransform.positionV);
740
+ rawActions.push(updateAction);
705
741
  }
706
- if (!Pe.diffValue(R, h.size)) {
707
- const B = C.replaceOp(["drawings", I, "docTransform", "size"], R, h.size);
708
- v.push(B);
742
+ if (!Tools.diffValue(oldSize, docTransform.size)) {
743
+ const updateAction = jsonX.replaceOp(["drawings", drawingId, "docTransform", "size"], oldSize, docTransform.size);
744
+ rawActions.push(updateAction);
709
745
  }
710
- if (!Pe.diffValue(E, h.angle)) {
711
- const B = C.replaceOp(["drawings", I, "docTransform", "angle"], E, h.angle);
712
- v.push(B);
746
+ if (!Tools.diffValue(oldAngle, docTransform.angle)) {
747
+ const updateAction = jsonX.replaceOp(["drawings", drawingId, "docTransform", "angle"], oldAngle, docTransform.angle);
748
+ rawActions.push(updateAction);
713
749
  }
714
- const H = {
715
- id: Q.id,
750
+ const doMutation = {
751
+ id: RichTextEditingMutation.id,
716
752
  params: {
717
- unitId: u,
753
+ unitId,
718
754
  actions: [],
719
755
  textRanges: null,
720
756
  debounce: !0
721
757
  }
722
758
  };
723
- H.params.actions = v.reduce((B, b) => X.compose(B, b), null);
724
- const z = s.syncExecuteCommand(H.id, H.params);
725
- return a.refreshControls(), !!z;
726
- }
727
- }, Ze = 0, Qe = 100, Fi = (i) => {
728
- const e = re($), n = re(an), t = re(he), r = re(se), o = re(ne), { drawings: a } = i, s = a[0];
729
- if (s == null)
759
+ doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
760
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
761
+ return transformer.refreshControls(), !!result;
762
+ }, "handler")
763
+ }, MIN_MARGIN = 0, MAX_MARGIN = 100, DocDrawingTextWrap = /* @__PURE__ */ __name((props) => {
764
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), univerInstanceService = useDependency(IUniverInstanceService), { drawings } = props, drawingParam = drawings[0];
765
+ if (drawingParam == null)
730
766
  return null;
731
- const { unitId: l } = s, c = o.getUniverDocInstance(l), m = r.getRenderById(l);
732
- if ((m == null ? void 0 : m.scene) == null)
767
+ const { unitId } = drawingParam, documentDataModel = univerInstanceService.getUniverDocInstance(unitId), renderObject = renderManagerService.getRenderById(unitId);
768
+ if ((renderObject == null ? void 0 : renderObject.scene) == null)
733
769
  return null;
734
- const [f, h] = ie(!0), [p, w] = ie(!0), [v, I] = ie(!0), [D, _] = ie(me.INLINE), [C, O] = ie(""), [y, T] = ie({
770
+ const [disableWrapText, setDisableWrapText] = useState(!0), [disableDistTB, setDisableDistTB] = useState(!0), [disableDistLR, setDisableDistLR] = useState(!0), [wrappingStyle, setWrappingStyle] = useState(TextWrappingStyle.INLINE), [wrapText, setWrapText] = useState(""), [distToText, setDistToText] = useState({
735
771
  distT: 0,
736
772
  distL: 0,
737
773
  distB: 0,
738
774
  distR: 0
739
- }), [N, R] = ie(!0);
740
- function E(b) {
741
- _(b);
742
- const S = t.getFocusDrawings();
743
- if (S.length === 0)
775
+ }), [showPanel, setShowPanel] = useState(!0);
776
+ function handleWrappingStyleChange(value) {
777
+ setWrappingStyle(value);
778
+ const focusDrawings = drawingManagerService.getFocusDrawings();
779
+ if (focusDrawings.length === 0)
744
780
  return;
745
- const { unitId: A, subUnitId: P } = S[0], L = S.map(({ unitId: x, subUnitId: M, drawingId: W }) => ({
746
- unitId: x,
747
- subUnitId: M,
748
- drawingId: W
781
+ const { unitId: unitId2, subUnitId } = focusDrawings[0], drawings2 = focusDrawings.map(({ unitId: unitId3, subUnitId: subUnitId2, drawingId }) => ({
782
+ unitId: unitId3,
783
+ subUnitId: subUnitId2,
784
+ drawingId
749
785
  }));
750
- e.executeCommand(it.id, {
751
- unitId: A,
752
- subUnitId: P,
753
- drawings: L,
754
- wrappingStyle: b
786
+ commandService.executeCommand(UpdateDocDrawingWrappingStyleCommand.id, {
787
+ unitId: unitId2,
788
+ subUnitId,
789
+ drawings: drawings2,
790
+ wrappingStyle: value
755
791
  });
756
792
  }
757
- function H(b) {
758
- O(b);
759
- const S = t.getFocusDrawings();
760
- if (S.length === 0)
793
+ __name(handleWrappingStyleChange, "handleWrappingStyleChange");
794
+ function handleWrapTextChange(value) {
795
+ setWrapText(value);
796
+ const focusDrawings = drawingManagerService.getFocusDrawings();
797
+ if (focusDrawings.length === 0)
761
798
  return;
762
- const A = S.map((P) => ({
763
- unitId: P.unitId,
764
- subUnitId: P.subUnitId,
765
- drawingId: P.drawingId
799
+ const drawings2 = focusDrawings.map((drawing) => ({
800
+ unitId: drawing.unitId,
801
+ subUnitId: drawing.subUnitId,
802
+ drawingId: drawing.drawingId
766
803
  }));
767
- e.executeCommand(ot.id, {
768
- unitId: S[0].unitId,
769
- subUnitId: S[0].unitId,
770
- drawings: A,
771
- wrapText: b
804
+ commandService.executeCommand(UpdateDocDrawingWrapTextCommand.id, {
805
+ unitId: focusDrawings[0].unitId,
806
+ subUnitId: focusDrawings[0].unitId,
807
+ drawings: drawings2,
808
+ wrapText: value
772
809
  });
773
810
  }
774
- function z(b, S) {
775
- if (b == null)
811
+ __name(handleWrapTextChange, "handleWrapTextChange");
812
+ function handleDistToTextChange(value, direction) {
813
+ if (value == null)
776
814
  return;
777
- const A = { ...y, [S]: b };
778
- T(A);
779
- const P = t.getFocusDrawings();
780
- if (P.length === 0)
815
+ const newDistToText = { ...distToText, [direction]: value };
816
+ setDistToText(newDistToText);
817
+ const focusDrawings = drawingManagerService.getFocusDrawings();
818
+ if (focusDrawings.length === 0)
781
819
  return;
782
- const L = P.map((x) => ({
783
- unitId: x.unitId,
784
- subUnitId: x.subUnitId,
785
- drawingId: x.drawingId
820
+ const drawings2 = focusDrawings.map((drawing) => ({
821
+ unitId: drawing.unitId,
822
+ subUnitId: drawing.subUnitId,
823
+ drawingId: drawing.drawingId
786
824
  }));
787
- e.executeCommand(rt.id, {
788
- unitId: P[0].unitId,
789
- subUnitId: P[0].unitId,
790
- drawings: L,
825
+ commandService.executeCommand(UpdateDocDrawingDistanceCommand.id, {
826
+ unitId: focusDrawings[0].unitId,
827
+ subUnitId: focusDrawings[0].unitId,
828
+ drawings: drawings2,
791
829
  dist: {
792
- [S]: b
830
+ [direction]: value
793
831
  }
794
832
  });
795
833
  }
796
- function U() {
797
- const b = t.getFocusDrawings();
798
- b.length !== 0 && B(b[0]);
834
+ __name(handleDistToTextChange, "handleDistToTextChange");
835
+ function updateFocusDrawingState() {
836
+ const focusDrawings = drawingManagerService.getFocusDrawings();
837
+ focusDrawings.length !== 0 && updateState(focusDrawings[0]);
799
838
  }
800
- function B(b) {
801
- var ce, fe;
802
- const S = (fe = (ce = c == null ? void 0 : c.getSnapshot()) == null ? void 0 : ce.drawings) == null ? void 0 : fe[b.drawingId];
803
- if (S == null)
839
+ __name(updateFocusDrawingState, "updateFocusDrawingState");
840
+ function updateState(drawingParam2) {
841
+ var _a8, _b;
842
+ const drawing = (_b = (_a8 = documentDataModel == null ? void 0 : documentDataModel.getSnapshot()) == null ? void 0 : _a8.drawings) == null ? void 0 : _b[drawingParam2.drawingId];
843
+ if (drawing == null)
804
844
  return;
805
845
  const {
806
- distT: A = 0,
807
- distL: P = 0,
808
- distB: L = 0,
809
- distR: x = 0,
810
- layoutType: M = k.INLINE,
811
- behindDoc: W = oe.FALSE,
812
- wrapText: G = je.BOTH_SIDES
813
- } = S;
814
- if (T({
815
- distT: A,
816
- distL: P,
817
- distB: L,
818
- distR: x
819
- }), O(G), h(M !== k.WRAP_SQUARE), M === k.WRAP_NONE || M === k.INLINE ? w(!0) : w(!1), M === k.WRAP_NONE || M === k.INLINE || M === k.WRAP_TOP_AND_BOTTOM ? I(!0) : I(!1), M === k.WRAP_NONE)
820
- W === oe.TRUE ? _(me.BEHIND_TEXT) : _(me.IN_FRONT_OF_TEXT);
846
+ distT = 0,
847
+ distL = 0,
848
+ distB = 0,
849
+ distR = 0,
850
+ layoutType = PositionedObjectLayoutType.INLINE,
851
+ behindDoc = BooleanNumber.FALSE,
852
+ wrapText: wrapText2 = WrapTextType.BOTH_SIDES
853
+ } = drawing;
854
+ if (setDistToText({
855
+ distT,
856
+ distL,
857
+ distB,
858
+ distR
859
+ }), setWrapText(wrapText2), setDisableWrapText(layoutType !== PositionedObjectLayoutType.WRAP_SQUARE), layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE ? setDisableDistTB(!0) : setDisableDistTB(!1), layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE || layoutType === PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM ? setDisableDistLR(!0) : setDisableDistLR(!1), layoutType === PositionedObjectLayoutType.WRAP_NONE)
860
+ behindDoc === BooleanNumber.TRUE ? setWrappingStyle(TextWrappingStyle.BEHIND_TEXT) : setWrappingStyle(TextWrappingStyle.IN_FRONT_OF_TEXT);
821
861
  else
822
- switch (M) {
823
- case k.INLINE:
824
- _(me.INLINE);
862
+ switch (layoutType) {
863
+ case PositionedObjectLayoutType.INLINE:
864
+ setWrappingStyle(TextWrappingStyle.INLINE);
825
865
  break;
826
- case k.WRAP_SQUARE:
827
- _(me.WRAP_SQUARE);
866
+ case PositionedObjectLayoutType.WRAP_SQUARE:
867
+ setWrappingStyle(TextWrappingStyle.WRAP_SQUARE);
828
868
  break;
829
- case k.WRAP_TOP_AND_BOTTOM:
830
- _(me.WRAP_TOP_AND_BOTTOM);
869
+ case PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
870
+ setWrappingStyle(TextWrappingStyle.WRAP_TOP_AND_BOTTOM);
831
871
  break;
832
872
  default:
833
- throw new Error(`Unsupported layout type: ${M}`);
873
+ throw new Error(`Unsupported layout type: ${layoutType}`);
834
874
  }
835
875
  }
836
- return wn(() => {
837
- U();
838
- const b = t.focus$.subscribe((A) => {
839
- if (A.length === 0) {
840
- R(!1);
876
+ return __name(updateState, "updateState"), useEffect(() => {
877
+ updateFocusDrawingState();
878
+ const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
879
+ if (drawingParams.length === 0) {
880
+ setShowPanel(!1);
841
881
  return;
842
882
  }
843
- R(!0), B(A[0]);
844
- }), S = e.onCommandExecuted(async (A) => {
845
- A.id === Q.id && U();
883
+ setShowPanel(!0), updateState(drawingParams[0]);
884
+ }), mutationListener = commandService.onCommandExecuted(async (command) => {
885
+ command.id === RichTextEditingMutation.id && updateFocusDrawingState();
846
886
  });
847
887
  return () => {
848
- b.unsubscribe(), S.dispose();
888
+ subscription.unsubscribe(), mutationListener.dispose();
849
889
  };
850
- }, []), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelGrid, g.imageCommonPanelBorder), style: { display: N ? "block" : "none" } }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelTitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.title")))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.wrappingStyle")))), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelRow) }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn) }, /* @__PURE__ */ d.createElement(Rn, { value: D, onChange: E, direction: "vertical" }, /* @__PURE__ */ d.createElement(Ee, { value: me.INLINE }, n.t("image-text-wrap.inline")), /* @__PURE__ */ d.createElement(Ee, { value: me.WRAP_SQUARE }, n.t("image-text-wrap.square")), /* @__PURE__ */ d.createElement(Ee, { value: me.WRAP_TOP_AND_BOTTOM }, n.t("image-text-wrap.topAndBottom")), /* @__PURE__ */ d.createElement(Ee, { value: me.BEHIND_TEXT }, n.t("image-text-wrap.behindText")), /* @__PURE__ */ d.createElement(Ee, { value: me.IN_FRONT_OF_TEXT }, n.t("image-text-wrap.inFrontText"))))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.wrapText")))), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelRow) }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn) }, /* @__PURE__ */ d.createElement(Rn, { disabled: f, value: C, onChange: H, direction: "horizontal" }, /* @__PURE__ */ d.createElement(Ee, { value: je.BOTH_SIDES }, n.t("image-text-wrap.bothSide")), /* @__PURE__ */ d.createElement(Ee, { value: je.LEFT }, n.t("image-text-wrap.leftOnly")), /* @__PURE__ */ d.createElement(Ee, { value: je.RIGHT }, n.t("image-text-wrap.rightOnly"))))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-text-wrap.distanceFromText")))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-text-wrap.top"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
851
- Ae,
890
+ }, []), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelGrid, styles.imageCommonPanelBorder), style: { display: showPanel ? "block" : "none" } }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-text-wrap.title")))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSubtitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-text-wrap.wrappingStyle")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelRow) }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn) }, /* @__PURE__ */ React.createElement(RadioGroup, { value: wrappingStyle, onChange: handleWrappingStyleChange, direction: "vertical" }, /* @__PURE__ */ React.createElement(Radio, { value: TextWrappingStyle.INLINE }, localeService.t("image-text-wrap.inline")), /* @__PURE__ */ React.createElement(Radio, { value: TextWrappingStyle.WRAP_SQUARE }, localeService.t("image-text-wrap.square")), /* @__PURE__ */ React.createElement(Radio, { value: TextWrappingStyle.WRAP_TOP_AND_BOTTOM }, localeService.t("image-text-wrap.topAndBottom")), /* @__PURE__ */ React.createElement(Radio, { value: TextWrappingStyle.BEHIND_TEXT }, localeService.t("image-text-wrap.behindText")), /* @__PURE__ */ React.createElement(Radio, { value: TextWrappingStyle.IN_FRONT_OF_TEXT }, localeService.t("image-text-wrap.inFrontText"))))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSubtitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-text-wrap.wrapText")))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelRow) }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn) }, /* @__PURE__ */ React.createElement(RadioGroup, { disabled: disableWrapText, value: wrapText, onChange: handleWrapTextChange, direction: "horizontal" }, /* @__PURE__ */ React.createElement(Radio, { value: WrapTextType.BOTH_SIDES }, localeService.t("image-text-wrap.bothSide")), /* @__PURE__ */ React.createElement(Radio, { value: WrapTextType.LEFT }, localeService.t("image-text-wrap.leftOnly")), /* @__PURE__ */ React.createElement(Radio, { value: WrapTextType.RIGHT }, localeService.t("image-text-wrap.rightOnly"))))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSubtitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-text-wrap.distanceFromText")))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-text-wrap.top"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
891
+ InputNumber,
852
892
  {
853
- min: Ze,
854
- max: Qe,
855
- disabled: p,
893
+ min: MIN_MARGIN,
894
+ max: MAX_MARGIN,
895
+ disabled: disableDistTB,
856
896
  precision: 1,
857
- value: y.distT,
858
- onChange: (b) => {
859
- z(b, "distT");
860
- },
861
- className: g.imageCommonPanelInput
897
+ value: distToText.distT,
898
+ onChange: /* @__PURE__ */ __name((val) => {
899
+ handleDistToTextChange(val, "distT");
900
+ }, "onChange"),
901
+ className: styles.imageCommonPanelInput
862
902
  }
863
- ))))), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-text-wrap.left"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
864
- Ae,
903
+ ))))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-text-wrap.left"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
904
+ InputNumber,
865
905
  {
866
- min: Ze,
867
- max: Qe,
868
- disabled: v,
906
+ min: MIN_MARGIN,
907
+ max: MAX_MARGIN,
908
+ disabled: disableDistLR,
869
909
  precision: 1,
870
- value: y.distL,
871
- onChange: (b) => {
872
- z(b, "distL");
873
- },
874
- className: g.imageCommonPanelInput
910
+ value: distToText.distL,
911
+ onChange: /* @__PURE__ */ __name((val) => {
912
+ handleDistToTextChange(val, "distL");
913
+ }, "onChange"),
914
+ className: styles.imageCommonPanelInput
875
915
  }
876
- )))))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-text-wrap.bottom"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
877
- Ae,
916
+ )))))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-text-wrap.bottom"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
917
+ InputNumber,
878
918
  {
879
- min: Ze,
880
- max: Qe,
881
- disabled: p,
919
+ min: MIN_MARGIN,
920
+ max: MAX_MARGIN,
921
+ disabled: disableDistTB,
882
922
  precision: 1,
883
- value: y.distB,
884
- onChange: (b) => {
885
- z(b, "distB");
886
- },
887
- className: g.imageCommonPanelInput
923
+ value: distToText.distB,
924
+ onChange: /* @__PURE__ */ __name((val) => {
925
+ handleDistToTextChange(val, "distB");
926
+ }, "onChange"),
927
+ className: styles.imageCommonPanelInput
888
928
  }
889
- ))))), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-text-wrap.right"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
890
- Ae,
929
+ ))))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-text-wrap.right"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
930
+ InputNumber,
891
931
  {
892
- min: Ze,
893
- max: Qe,
894
- disabled: v,
932
+ min: MIN_MARGIN,
933
+ max: MAX_MARGIN,
934
+ disabled: disableDistLR,
895
935
  precision: 1,
896
- value: y.distR,
897
- onChange: (b) => {
898
- z(b, "distR");
899
- },
900
- className: g.imageCommonPanelInput
936
+ value: distToText.distR,
937
+ onChange: /* @__PURE__ */ __name((val) => {
938
+ handleDistToTextChange(val, "distR");
939
+ }, "onChange"),
940
+ className: styles.imageCommonPanelInput
901
941
  }
902
942
  )))))));
903
- }, Ln = -1e3, Un = 1e3, ki = (i) => {
904
- const e = re($), n = re(an), t = re(he), r = re(se), o = re(ne), a = re(Ue), { drawings: s } = i, l = s[0];
905
- if (l == null)
943
+ }, "DocDrawingTextWrap"), MIN_OFFSET = -1e3, MAX_OFFSET = 1e3, DocDrawingPosition = /* @__PURE__ */ __name((props) => {
944
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), univerInstanceService = useDependency(IUniverInstanceService), textSelectionRenderService = useDependency(ITextSelectionRenderManager), { drawings } = props, drawingParam = drawings[0];
945
+ if (drawingParam == null)
906
946
  return;
907
- const { unitId: c } = l, m = o.getUniverDocInstance(c), u = r.getRenderById(c), f = u == null ? void 0 : u.scene;
908
- if (f == null)
947
+ const { unitId } = drawingParam, documentDataModel = univerInstanceService.getUniverDocInstance(unitId), renderObject = renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
948
+ if (scene == null)
909
949
  return;
910
- const h = f.getTransformerByCreate(), p = [{
911
- label: n.t("image-position.column"),
912
- value: String(ee.COLUMN)
950
+ const transformer = scene.getTransformerByCreate(), HORIZONTAL_RELATIVE_FROM = [{
951
+ label: localeService.t("image-position.column"),
952
+ value: String(ObjectRelativeFromH.COLUMN)
913
953
  }, {
914
- label: n.t("image-position.page"),
915
- value: String(ee.PAGE)
954
+ label: localeService.t("image-position.page"),
955
+ value: String(ObjectRelativeFromH.PAGE)
916
956
  }, {
917
- label: n.t("image-position.margin"),
918
- value: String(ee.MARGIN)
919
- }], w = [{
920
- label: n.t("image-position.line"),
921
- value: String(V.LINE)
957
+ label: localeService.t("image-position.margin"),
958
+ value: String(ObjectRelativeFromH.MARGIN)
959
+ }], VERTICAL_RELATIVE_FROM = [{
960
+ label: localeService.t("image-position.line"),
961
+ value: String(ObjectRelativeFromV.LINE)
922
962
  }, {
923
- label: n.t("image-position.page"),
924
- value: String(V.PAGE)
963
+ label: localeService.t("image-position.page"),
964
+ value: String(ObjectRelativeFromV.PAGE)
925
965
  }, {
926
- label: n.t("image-position.margin"),
927
- value: String(V.MARGIN)
966
+ label: localeService.t("image-position.margin"),
967
+ value: String(ObjectRelativeFromV.MARGIN)
928
968
  }, {
929
- label: n.t("image-position.paragraph"),
930
- value: String(V.PARAGRAPH)
931
- }], [v, I] = ie(!0), [D, _] = ie({
932
- relativeFrom: ee.PAGE,
969
+ label: localeService.t("image-position.paragraph"),
970
+ value: String(ObjectRelativeFromV.PARAGRAPH)
971
+ }], [disabled, setDisabled] = useState(!0), [hPosition, setHPosition] = useState({
972
+ relativeFrom: ObjectRelativeFromH.PAGE,
933
973
  posOffset: 0
934
- }), [C, O] = ie({
935
- relativeFrom: V.PAGE,
974
+ }), [vPosition, setVPosition] = useState({
975
+ relativeFrom: ObjectRelativeFromV.PAGE,
936
976
  posOffset: 0
937
- }), [y, T] = ie(!0), [N, R] = ie(!0);
938
- function E(S, A) {
939
- S === "positionH" ? _(A) : O(A);
940
- const P = t.getFocusDrawings();
941
- if (P.length === 0)
977
+ }), [followTextMove, setFollowTextMove] = useState(!0), [showPanel, setShowPanel] = useState(!0);
978
+ function handlePositionChange(direction, value) {
979
+ direction === "positionH" ? setHPosition(value) : setVPosition(value);
980
+ const focusDrawings = drawingManagerService.getFocusDrawings();
981
+ if (focusDrawings.length === 0)
942
982
  return;
943
- const L = P.map((x) => ({
944
- unitId: x.unitId,
945
- subUnitId: x.subUnitId,
946
- drawingId: x.drawingId
983
+ const drawings2 = focusDrawings.map((drawing) => ({
984
+ unitId: drawing.unitId,
985
+ subUnitId: drawing.subUnitId,
986
+ drawingId: drawing.drawingId
947
987
  }));
948
- e.executeCommand(ze.id, {
949
- unitId: P[0].unitId,
950
- subUnitId: P[0].unitId,
951
- drawings: L.map((x) => ({
952
- drawingId: x.drawingId,
953
- key: S,
954
- value: A
988
+ commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
989
+ unitId: focusDrawings[0].unitId,
990
+ subUnitId: focusDrawings[0].unitId,
991
+ drawings: drawings2.map((drawing) => ({
992
+ drawingId: drawing.drawingId,
993
+ key: direction,
994
+ value
955
995
  }))
956
- }), a.blur(), h.refreshControls();
996
+ }), textSelectionRenderService.blur(), transformer.refreshControls();
957
997
  }
958
- function H(S) {
959
- var we, ve, te;
960
- const A = D.relativeFrom, P = D.posOffset, L = Number(S);
961
- if (A === L)
998
+ __name(handlePositionChange, "handlePositionChange");
999
+ function handleHorizontalRelativeFromChange(value) {
1000
+ var _a8, _b, _c;
1001
+ const prevRelativeFrom = hPosition.relativeFrom, prevPosOffset = hPosition.posOffset, relativeFrom = Number(value);
1002
+ if (prevRelativeFrom === relativeFrom)
962
1003
  return;
963
- const x = t.getFocusDrawings();
964
- if (x.length === 0)
1004
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1005
+ if (focusDrawings.length === 0)
965
1006
  return;
966
- const M = x[0].drawingId, W = x[0].unitId;
967
- let G = null, F = 0;
968
- const ce = (we = r.getRenderById(W)) == null ? void 0 : we.with(ae).getSkeleton(), fe = ce == null ? void 0 : ce.getSkeletonData();
969
- if (fe == null)
1007
+ const drawingId = focusDrawings[0].drawingId, unitId2 = focusDrawings[0].unitId;
1008
+ let drawing = null, pageMarginLeft = 0;
1009
+ const skeleton = (_a8 = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getSkeleton(), skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData();
1010
+ if (skeletonData == null)
970
1011
  return;
971
- const { pages: Oe, skeHeaders: Be, skeFooters: Ce } = fe;
972
- for (const Ne of Oe) {
973
- const { marginLeft: Ie, skeDrawings: Se, headerId: Te, footerId: Me, pageWidth: De } = Ne;
974
- if (Se.has(M)) {
975
- G = Se.get(M), F = Ie;
1012
+ const { pages, skeHeaders, skeFooters } = skeletonData;
1013
+ for (const page of pages) {
1014
+ const { marginLeft, skeDrawings, headerId, footerId, pageWidth } = page;
1015
+ if (skeDrawings.has(drawingId)) {
1016
+ drawing = skeDrawings.get(drawingId), pageMarginLeft = marginLeft;
976
1017
  break;
977
1018
  }
978
- const J = (ve = Be.get(Te)) == null ? void 0 : ve.get(De);
979
- if (J != null && J.skeDrawings.has(M)) {
980
- G = J == null ? void 0 : J.skeDrawings.get(M), F = Ie;
1019
+ const headerPage = (_b = skeHeaders.get(headerId)) == null ? void 0 : _b.get(pageWidth);
1020
+ if (headerPage != null && headerPage.skeDrawings.has(drawingId)) {
1021
+ drawing = headerPage == null ? void 0 : headerPage.skeDrawings.get(drawingId), pageMarginLeft = marginLeft;
981
1022
  break;
982
1023
  }
983
- const q = (te = Ce.get(Me)) == null ? void 0 : te.get(De);
984
- if (q != null && q.skeDrawings.has(M)) {
985
- G = q == null ? void 0 : q.skeDrawings.get(M), F = Ie;
1024
+ const footerPage = (_c = skeFooters.get(footerId)) == null ? void 0 : _c.get(pageWidth);
1025
+ if (footerPage != null && footerPage.skeDrawings.has(drawingId)) {
1026
+ drawing = footerPage == null ? void 0 : footerPage.skeDrawings.get(drawingId), pageMarginLeft = marginLeft;
986
1027
  break;
987
1028
  }
988
1029
  }
989
- if (G == null)
1030
+ if (drawing == null)
990
1031
  return;
991
- let K = 0;
992
- A === ee.COLUMN ? K -= G.columnLeft : A === ee.MARGIN && (K -= F), L === ee.COLUMN ? K += G.columnLeft : L === ee.MARGIN ? K += F : ee.PAGE;
993
- const le = {
994
- relativeFrom: L,
995
- posOffset: (P != null ? P : 0) - K
1032
+ let delta = 0;
1033
+ prevRelativeFrom === ObjectRelativeFromH.COLUMN ? delta -= drawing.columnLeft : prevRelativeFrom === ObjectRelativeFromH.MARGIN && (delta -= pageMarginLeft), relativeFrom === ObjectRelativeFromH.COLUMN ? delta += drawing.columnLeft : relativeFrom === ObjectRelativeFromH.MARGIN ? delta += pageMarginLeft : ObjectRelativeFromH.PAGE;
1034
+ const newPositionH = {
1035
+ relativeFrom,
1036
+ posOffset: (prevPosOffset != null ? prevPosOffset : 0) - delta
996
1037
  };
997
- E("positionH", le);
1038
+ handlePositionChange("positionH", newPositionH);
998
1039
  }
999
- function z(S) {
1000
- var Ie, Se, Te, Me, De;
1001
- const A = C.relativeFrom, P = C.posOffset, L = Number(S);
1002
- if (A === L)
1040
+ __name(handleHorizontalRelativeFromChange, "handleHorizontalRelativeFromChange");
1041
+ function handleVerticalRelativeFromChange(value) {
1042
+ var _a8, _b, _c, _d, _e;
1043
+ const prevRelativeFrom = vPosition.relativeFrom, prevPosOffset = vPosition.posOffset, relativeFrom = Number(value);
1044
+ if (prevRelativeFrom === relativeFrom)
1003
1045
  return;
1004
- const x = t.getFocusDrawings();
1005
- if (x.length === 0)
1046
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1047
+ if (focusDrawings.length === 0)
1006
1048
  return;
1007
- const { drawingId: M, unitId: W } = x[0], G = o.getUniverDocInstance(W), F = (Ie = r.getRenderById(W)) == null ? void 0 : Ie.with(ae).getSkeleton(), ce = a.getSegment(), fe = a.getSegmentPage(), Oe = (Te = (Se = G == null ? void 0 : G.getSelfOrHeaderFooterModel(ce).getBody()) == null ? void 0 : Se.customBlocks) == null ? void 0 : Te.find((J) => J.blockId === M);
1008
- if (Oe == null || F == null)
1049
+ const { drawingId, unitId: unitId2 } = focusDrawings[0], documentDataModel2 = univerInstanceService.getUniverDocInstance(unitId2), skeleton = (_a8 = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getSkeleton(), segmentId = textSelectionRenderService.getSegment(), segmentPage = textSelectionRenderService.getSegmentPage(), drawing = (_c = (_b = documentDataModel2 == null ? void 0 : documentDataModel2.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.customBlocks) == null ? void 0 : _c.find((c) => c.blockId === drawingId);
1050
+ if (drawing == null || skeleton == null)
1009
1051
  return;
1010
- const { startIndex: Be } = Oe, Ce = F.findNodeByCharIndex(Be, ce, fe), K = (Me = Ce == null ? void 0 : Ce.parent) == null ? void 0 : Me.parent, le = K == null ? void 0 : K.parent, we = le == null ? void 0 : le.lines.find((J) => J.paragraphIndex === (K == null ? void 0 : K.paragraphIndex) && J.paragraphStart), ve = (De = le == null ? void 0 : le.parent) == null ? void 0 : De.parent;
1011
- if (Ce == null || K == null || we == null || le == null || ve == null)
1052
+ const { startIndex } = drawing, glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage), line = (_d = glyph == null ? void 0 : glyph.parent) == null ? void 0 : _d.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart), page = (_e = column == null ? void 0 : column.parent) == null ? void 0 : _e.parent;
1053
+ if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null)
1012
1054
  return;
1013
- let te = 0;
1014
- A === V.PARAGRAPH ? te -= we.top : A === V.LINE ? te -= K.top : A === V.PAGE && (te += ve.marginTop), L === V.PARAGRAPH ? te += we.top : L === V.LINE ? te += K.top : L === V.PAGE && (te -= ve.marginTop);
1015
- const Ne = {
1016
- relativeFrom: L,
1017
- posOffset: (P != null ? P : 0) - te
1055
+ let delta = 0;
1056
+ prevRelativeFrom === ObjectRelativeFromV.PARAGRAPH ? delta -= paragraphStartLine.top : prevRelativeFrom === ObjectRelativeFromV.LINE ? delta -= line.top : prevRelativeFrom === ObjectRelativeFromV.PAGE && (delta += page.marginTop), relativeFrom === ObjectRelativeFromV.PARAGRAPH ? delta += paragraphStartLine.top : relativeFrom === ObjectRelativeFromV.LINE ? delta += line.top : relativeFrom === ObjectRelativeFromV.PAGE && (delta -= page.marginTop);
1057
+ const newPositionV = {
1058
+ relativeFrom,
1059
+ posOffset: (prevPosOffset != null ? prevPosOffset : 0) - delta
1018
1060
  };
1019
- E("positionV", Ne);
1061
+ handlePositionChange("positionV", newPositionV);
1020
1062
  }
1021
- function U(S) {
1022
- var W;
1023
- const A = m == null ? void 0 : m.getSnapshot(), P = (W = A == null ? void 0 : A.drawings) == null ? void 0 : W[S.drawingId];
1024
- if (P == null)
1063
+ __name(handleVerticalRelativeFromChange, "handleVerticalRelativeFromChange");
1064
+ function updateState(drawingParam2) {
1065
+ var _a8;
1066
+ const snapshot = documentDataModel == null ? void 0 : documentDataModel.getSnapshot(), drawing = (_a8 = snapshot == null ? void 0 : snapshot.drawings) == null ? void 0 : _a8[drawingParam2.drawingId];
1067
+ if (drawing == null)
1025
1068
  return;
1026
- const { layoutType: L } = P, {
1027
- positionH: x,
1028
- positionV: M
1029
- } = P.docTransform;
1030
- _(x), O(M), I(L === k.INLINE), T(M.relativeFrom === V.PARAGRAPH || M.relativeFrom === V.LINE);
1031
- }
1032
- function B() {
1033
- const S = t.getFocusDrawings();
1034
- S.length !== 0 && U(S[0]);
1035
- }
1036
- function b(S) {
1037
- T(S), z(String(S ? V.PARAGRAPH : V.PAGE));
1038
- }
1039
- return wn(() => {
1040
- B();
1041
- const S = t.focus$.subscribe((P) => {
1042
- if (P.length === 0) {
1043
- R(!1);
1069
+ const { layoutType } = drawing, {
1070
+ positionH,
1071
+ positionV
1072
+ } = drawing.docTransform;
1073
+ setHPosition(positionH), setVPosition(positionV), setDisabled(layoutType === PositionedObjectLayoutType.INLINE), setFollowTextMove(positionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === ObjectRelativeFromV.LINE);
1074
+ }
1075
+ __name(updateState, "updateState");
1076
+ function updateFocusDrawingState() {
1077
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1078
+ focusDrawings.length !== 0 && updateState(focusDrawings[0]);
1079
+ }
1080
+ __name(updateFocusDrawingState, "updateFocusDrawingState");
1081
+ function handleFollowTextMoveCheck(val) {
1082
+ setFollowTextMove(val), handleVerticalRelativeFromChange(String(val ? ObjectRelativeFromV.PARAGRAPH : ObjectRelativeFromV.PAGE));
1083
+ }
1084
+ return __name(handleFollowTextMoveCheck, "handleFollowTextMoveCheck"), useEffect(() => {
1085
+ updateFocusDrawingState();
1086
+ const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
1087
+ if (drawingParams.length === 0) {
1088
+ setShowPanel(!1);
1044
1089
  return;
1045
1090
  }
1046
- R(!0), U(P[0]);
1047
- }), A = e.onCommandExecuted(async (P) => {
1048
- P.id === Q.id && B();
1091
+ setShowPanel(!0), updateState(drawingParams[0]);
1092
+ }), mutationListener = commandService.onCommandExecuted(async (command) => {
1093
+ command.id === RichTextEditingMutation.id && updateFocusDrawingState();
1049
1094
  });
1050
1095
  return () => {
1051
- S.unsubscribe(), A.dispose();
1096
+ subscription.unsubscribe(), mutationListener.dispose();
1052
1097
  };
1053
- }, []), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelGrid, g.imageCommonPanelBorder), style: { display: N ? "block" : "none" } }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelTitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.title")))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.horizontal")))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-position.absolutePosition"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1054
- Ae,
1098
+ }, []), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelGrid, styles.imageCommonPanelBorder), style: { display: showPanel ? "block" : "none" } }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelTitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-position.title")))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSubtitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-position.horizontal")))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-position.absolutePosition"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
1099
+ InputNumber,
1055
1100
  {
1056
- min: Ln,
1057
- max: Un,
1101
+ min: MIN_OFFSET,
1102
+ max: MAX_OFFSET,
1058
1103
  precision: 1,
1059
- disabled: v,
1060
- value: D.posOffset,
1061
- onChange: (S) => {
1062
- E("positionH", {
1063
- relativeFrom: D.relativeFrom,
1064
- posOffset: S
1104
+ disabled,
1105
+ value: hPosition.posOffset,
1106
+ onChange: /* @__PURE__ */ __name((val) => {
1107
+ handlePositionChange("positionH", {
1108
+ relativeFrom: hPosition.relativeFrom,
1109
+ posOffset: val
1065
1110
  });
1066
- },
1067
- className: g.imageCommonPanelInput
1111
+ }, "onChange"),
1112
+ className: styles.imageCommonPanelInput
1068
1113
  }
1069
- ))))), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-position.toTheRightOf"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1070
- Nn,
1114
+ ))))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-position.toTheRightOf"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
1115
+ Select,
1071
1116
  {
1072
- value: String(D.relativeFrom),
1073
- disabled: v,
1074
- options: p,
1075
- onChange: H
1117
+ value: String(hPosition.relativeFrom),
1118
+ disabled,
1119
+ options: HORIZONTAL_RELATIVE_FROM,
1120
+ onChange: handleHorizontalRelativeFromChange
1076
1121
  }
1077
- )))))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.vertical")))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-position.absolutePosition"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1078
- Ae,
1122
+ )))))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSubtitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-position.vertical")))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-position.absolutePosition"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
1123
+ InputNumber,
1079
1124
  {
1080
- min: Ln,
1081
- max: Un,
1125
+ min: MIN_OFFSET,
1126
+ max: MAX_OFFSET,
1082
1127
  precision: 1,
1083
- disabled: v,
1084
- value: C.posOffset,
1085
- onChange: (S) => {
1086
- E("positionV", {
1087
- relativeFrom: C.relativeFrom,
1088
- posOffset: S
1128
+ disabled,
1129
+ value: vPosition.posOffset,
1130
+ onChange: /* @__PURE__ */ __name((val) => {
1131
+ handlePositionChange("positionV", {
1132
+ relativeFrom: vPosition.relativeFrom,
1133
+ posOffset: val
1089
1134
  });
1090
- },
1091
- className: g.imageCommonPanelInput
1135
+ }, "onChange"),
1136
+ className: styles.imageCommonPanelInput
1092
1137
  }
1093
- ))))), /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSpan2) }, /* @__PURE__ */ d.createElement("label", null, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, n.t("image-position.bellow"))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(
1094
- Nn,
1138
+ ))))), /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSpan2) }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, localeService.t("image-position.bellow"))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(
1139
+ Select,
1095
1140
  {
1096
- disabled: v,
1097
- value: String(C.relativeFrom),
1098
- options: w,
1099
- onChange: z
1141
+ disabled,
1142
+ value: String(vPosition.relativeFrom),
1143
+ options: VERTICAL_RELATIVE_FROM,
1144
+ onChange: handleVerticalRelativeFromChange
1100
1145
  }
1101
- )))))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow }, /* @__PURE__ */ d.createElement("div", { className: j(g.imageCommonPanelColumn, g.imageCommonPanelSubtitle) }, /* @__PURE__ */ d.createElement("div", null, n.t("image-position.options")))), /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelRow, style: { marginBottom: "50px" } }, /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanelColumn }, /* @__PURE__ */ d.createElement(si, { disabled: v, checked: y, onChange: b }, n.t("image-position.moveObjectWithText")))));
1102
- }, Hi = () => {
1103
- const i = re(he), e = i.getFocusDrawings(), [n, t] = ie(e);
1104
- return wn(() => {
1105
- const r = i.focus$.subscribe((o) => {
1106
- t(o);
1146
+ )))))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow }, /* @__PURE__ */ React.createElement("div", { className: clsx(styles.imageCommonPanelColumn, styles.imageCommonPanelSubtitle) }, /* @__PURE__ */ React.createElement("div", null, localeService.t("image-position.options")))), /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelRow, style: { marginBottom: "50px" } }, /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanelColumn }, /* @__PURE__ */ React.createElement(Checkbox, { disabled, checked: followTextMove, onChange: handleFollowTextMoveCheck }, localeService.t("image-position.moveObjectWithText")))));
1147
+ }, "DocDrawingPosition"), DocDrawingPanel = /* @__PURE__ */ __name(() => {
1148
+ const drawingManagerService = useDependency(IDrawingManagerService), focusDrawings = drawingManagerService.getFocusDrawings(), [drawings, setDrawings] = useState(focusDrawings);
1149
+ return useEffect(() => {
1150
+ const focusDispose = drawingManagerService.focus$.subscribe((drawings2) => {
1151
+ setDrawings(drawings2);
1107
1152
  });
1108
1153
  return () => {
1109
- r.unsubscribe();
1154
+ focusDispose.unsubscribe();
1110
1155
  };
1111
- }, []), !!(n != null && n.length) && /* @__PURE__ */ d.createElement("div", { className: g.imageCommonPanel }, /* @__PURE__ */ d.createElement(Nt, { drawings: n, hasAlign: !1, hasCropper: !1, hasGroup: !1, hasTransform: !1 }), /* @__PURE__ */ d.createElement(Fi, { drawings: n }), /* @__PURE__ */ d.createElement(ki, { drawings: n }));
1112
- }, Wi = {
1156
+ }, []), !!(drawings != null && drawings.length) && /* @__PURE__ */ React.createElement("div", { className: styles.imageCommonPanel }, /* @__PURE__ */ React.createElement(DrawingCommonPanel, { drawings, hasAlign: !1, hasCropper: !1, hasGroup: !1, hasTransform: !1 }), /* @__PURE__ */ React.createElement(DocDrawingTextWrap, { drawings }), /* @__PURE__ */ React.createElement(DocDrawingPosition, { drawings }));
1157
+ }, "DocDrawingPanel"), ClearDocDrawingTransformerOperation = {
1113
1158
  id: "doc.operation.clear-drawing-transformer",
1114
- type: Y.MUTATION,
1115
- handler: (i, e) => {
1116
- const n = i.get(se);
1117
- return e.forEach((t) => {
1118
- var r, o;
1119
- (o = (r = n.getRenderById(t)) == null ? void 0 : r.scene.getTransformer()) == null || o.debounceRefreshControls();
1159
+ type: CommandType.MUTATION,
1160
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1161
+ const renderManagerService = accessor.get(IRenderManagerService);
1162
+ return params.forEach((unitId) => {
1163
+ var _a8, _b;
1164
+ (_b = (_a8 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a8.scene.getTransformer()) == null || _b.debounceRefreshControls();
1120
1165
  }), !0;
1121
- }
1122
- }, Xe = {
1166
+ }, "handler")
1167
+ }, MoveDocDrawingsCommand = {
1123
1168
  id: "doc.command.move-drawing",
1124
- type: Y.COMMAND,
1125
- handler: (i, e) => {
1126
- const n = i.get($), t = i.get(Re), r = i.get(ne), o = i.get(se), { direction: a } = e, s = t.getFocusDrawings();
1127
- if (s.length === 0)
1169
+ type: CommandType.COMMAND,
1170
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1171
+ const commandService = accessor.get(ICommandService), docDrawingService = accessor.get(IDocDrawingService), univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), { direction } = params, drawings = docDrawingService.getFocusDrawings();
1172
+ if (drawings.length === 0)
1128
1173
  return !1;
1129
- const l = s[0].unitId, c = o.getRenderById(l), m = c == null ? void 0 : c.scene;
1130
- if (m == null)
1174
+ const unitId = drawings[0].unitId, renderObject = renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
1175
+ if (scene == null)
1131
1176
  return !1;
1132
- const u = m.getTransformerByCreate(), f = r.getUniverDocInstance(l), h = s.map((w) => {
1133
- var y, T, N, R, E;
1134
- const { drawingId: v } = w, I = (y = f == null ? void 0 : f.getSnapshot().drawings) == null ? void 0 : y[v];
1135
- if (I == null || I.layoutType === k.INLINE)
1177
+ const transformer = scene.getTransformerByCreate(), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), newDrawings = drawings.map((drawing) => {
1178
+ var _a8, _b, _c, _d, _e;
1179
+ const { drawingId } = drawing, drawingData = (_a8 = documentDataModel == null ? void 0 : documentDataModel.getSnapshot().drawings) == null ? void 0 : _a8[drawingId];
1180
+ if (drawingData == null || drawingData.layoutType === PositionedObjectLayoutType.INLINE)
1136
1181
  return null;
1137
- const { positionH: D, positionV: _ } = I.docTransform, C = { ...D }, O = { ..._ };
1138
- return a === ge.UP ? O.posOffset = ((T = O.posOffset) != null ? T : 0) - 2 : a === ge.DOWN ? O.posOffset = ((N = O.posOffset) != null ? N : 0) + 2 : a === ge.LEFT ? C.posOffset = ((R = C.posOffset) != null ? R : 0) - 2 : a === ge.RIGHT && (C.posOffset = ((E = C.posOffset) != null ? E : 0) + 2), {
1139
- drawingId: v,
1140
- key: a === ge.UP || a === ge.DOWN ? "positionV" : "positionH",
1141
- value: a === ge.UP || a === ge.DOWN ? O : C
1182
+ const { positionH, positionV } = drawingData.docTransform, newPositionH = { ...positionH }, newPositionV = { ...positionV };
1183
+ return direction === Direction.UP ? newPositionV.posOffset = ((_b = newPositionV.posOffset) != null ? _b : 0) - 2 : direction === Direction.DOWN ? newPositionV.posOffset = ((_c = newPositionV.posOffset) != null ? _c : 0) + 2 : direction === Direction.LEFT ? newPositionH.posOffset = ((_d = newPositionH.posOffset) != null ? _d : 0) - 2 : direction === Direction.RIGHT && (newPositionH.posOffset = ((_e = newPositionH.posOffset) != null ? _e : 0) + 2), {
1184
+ drawingId,
1185
+ key: direction === Direction.UP || direction === Direction.DOWN ? "positionV" : "positionH",
1186
+ value: direction === Direction.UP || direction === Direction.DOWN ? newPositionV : newPositionH
1142
1187
  };
1143
- }).filter((w) => w != null);
1144
- if (h.length === 0)
1188
+ }).filter((drawing) => drawing != null);
1189
+ if (newDrawings.length === 0)
1145
1190
  return !1;
1146
- const p = n.syncExecuteCommand(ze.id, {
1147
- unitId: l,
1148
- subUnitId: l,
1149
- drawings: h
1191
+ const result = commandService.syncExecuteCommand(UpdateDrawingDocTransformCommand.id, {
1192
+ unitId,
1193
+ subUnitId: unitId,
1194
+ drawings: newDrawings
1150
1195
  });
1151
- return u.refreshControls(), !!p;
1152
- }
1153
- }, ct = {
1196
+ return transformer.refreshControls(), !!result;
1197
+ }, "handler")
1198
+ }, DeleteDocDrawingsCommand = {
1154
1199
  id: "doc.command.delete-drawing",
1155
- type: Y.COMMAND,
1156
- handler: (i) => {
1157
- const e = i.get($), t = i.get(Re).getFocusDrawings();
1158
- if (t.length === 0)
1200
+ type: CommandType.COMMAND,
1201
+ handler: /* @__PURE__ */ __name((accessor) => {
1202
+ const commandService = accessor.get(ICommandService), drawings = accessor.get(IDocDrawingService).getFocusDrawings();
1203
+ if (drawings.length === 0)
1159
1204
  return !1;
1160
- const { unitId: r } = t[0], o = t.map((a) => {
1161
- const { unitId: s, subUnitId: l, drawingId: c, drawingType: m } = a;
1205
+ const { unitId } = drawings[0], newDrawings = drawings.map((drawing) => {
1206
+ const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
1162
1207
  return {
1163
- unitId: s,
1164
- subUnitId: l,
1165
- drawingId: c,
1166
- drawingType: m
1208
+ unitId: unitId2,
1209
+ subUnitId,
1210
+ drawingId,
1211
+ drawingType
1167
1212
  };
1168
1213
  });
1169
- return e.executeCommand(vn.id, {
1170
- unitId: r,
1171
- drawings: o
1214
+ return commandService.executeCommand(RemoveDocDrawingCommand.id, {
1215
+ unitId,
1216
+ drawings: newDrawings
1172
1217
  });
1173
- }
1174
- }, lt = {
1218
+ }, "handler")
1219
+ }, SetDocDrawingArrangeCommand = {
1175
1220
  id: "doc.command.set-drawing-arrange",
1176
- type: Y.COMMAND,
1177
- handler: (i, e) => {
1178
- const n = i.get($), t = i.get(Re);
1179
- if (e == null)
1221
+ type: CommandType.COMMAND,
1222
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1223
+ const commandService = accessor.get(ICommandService), docDrawingService = accessor.get(IDocDrawingService);
1224
+ if (params == null)
1180
1225
  return !1;
1181
- const { unitId: r, subUnitId: o, drawingIds: a, arrangeType: s } = e, l = { unitId: r, subUnitId: o, drawingIds: a };
1182
- let c;
1183
- if (s === Ye.forward ? c = t.getForwardDrawingsOp(l) : s === Ye.backward ? c = t.getBackwardDrawingOp(l) : s === Ye.front ? c = t.getFrontDrawingsOp(l) : s === Ye.back && (c = t.getBackDrawingsOp(l)), c == null)
1226
+ const { unitId, subUnitId, drawingIds, arrangeType } = params, drawingOrderMapParam = { unitId, subUnitId, drawingIds };
1227
+ let jsonOp;
1228
+ if (arrangeType === ArrangeTypeEnum.forward ? jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.backward ? jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.front ? jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam) : arrangeType === ArrangeTypeEnum.back && (jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam)), jsonOp == null)
1184
1229
  return !1;
1185
- const { redo: m } = c;
1186
- if (m == null)
1230
+ const { redo } = jsonOp;
1231
+ if (redo == null)
1187
1232
  return !1;
1188
- const u = [];
1189
- let f = Pe.deepClone(m);
1190
- f = f.slice(3), f.unshift("drawingsOrder"), u.push(f);
1191
- const h = {
1192
- id: Q.id,
1233
+ const rawActions = [];
1234
+ let redoCopy = Tools.deepClone(redo);
1235
+ redoCopy = redoCopy.slice(3), redoCopy.unshift("drawingsOrder"), rawActions.push(redoCopy);
1236
+ const doMutation = {
1237
+ id: RichTextEditingMutation.id,
1193
1238
  params: {
1194
- unitId: r,
1239
+ unitId,
1195
1240
  actions: [],
1196
1241
  textRanges: null
1197
1242
  }
1198
1243
  };
1199
- return h.params.actions = u.reduce((w, v) => X.compose(w, v), null), !!n.syncExecuteCommand(h.id, h.params);
1200
- }
1201
- }, dt = {
1244
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1245
+ }, "handler")
1246
+ }, UngroupDocDrawingCommand = {
1202
1247
  id: "doc.command.ungroup-doc-image",
1203
- type: Y.COMMAND,
1204
- handler: (i, e) => {
1205
- i.get($), i.get(kn);
1206
- const n = i.get(Re);
1207
- if (!e) return !1;
1208
- const t = [];
1209
- return e.forEach(({ parent: r, children: o }) => {
1210
- t.push(r.unitId), o.forEach((a) => {
1211
- t.push(a.unitId);
1248
+ type: CommandType.COMMAND,
1249
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1250
+ accessor.get(ICommandService), accessor.get(IUndoRedoService);
1251
+ const docDrawingService = accessor.get(IDocDrawingService);
1252
+ if (!params) return !1;
1253
+ const unitIds = [];
1254
+ return params.forEach(({ parent, children }) => {
1255
+ unitIds.push(parent.unitId), children.forEach((child) => {
1256
+ unitIds.push(child.unitId);
1212
1257
  });
1213
- }), n.getUngroupDrawingOp(e), !1;
1214
- }
1215
- }, mt = {
1258
+ }), docDrawingService.getUngroupDrawingOp(params), !1;
1259
+ }, "handler")
1260
+ }, GroupDocDrawingCommand = {
1216
1261
  id: "doc.command.group-doc-image",
1217
- type: Y.COMMAND,
1218
- handler: (i, e) => {
1219
- i.get($), i.get(kn);
1220
- const n = i.get(Re);
1221
- if (!e) return !1;
1222
- const t = [];
1223
- return e.forEach(({ parent: r, children: o }) => {
1224
- t.push(r.unitId), o.forEach((a) => {
1225
- t.push(a.unitId);
1262
+ type: CommandType.COMMAND,
1263
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1264
+ accessor.get(ICommandService), accessor.get(IUndoRedoService);
1265
+ const docDrawingService = accessor.get(IDocDrawingService);
1266
+ if (!params) return !1;
1267
+ const unitIds = [];
1268
+ return params.forEach(({ parent, children }) => {
1269
+ unitIds.push(parent.unitId), children.forEach((child) => {
1270
+ unitIds.push(child.unitId);
1226
1271
  });
1227
- }), n.getGroupDrawingOp(e), !1;
1228
- }
1229
- }, gt = {
1272
+ }), docDrawingService.getGroupDrawingOp(params), !1;
1273
+ }, "handler")
1274
+ }, InsertDocDrawingCommand = {
1230
1275
  id: "doc.command.insert-doc-image",
1231
- type: Y.COMMAND,
1276
+ type: CommandType.COMMAND,
1232
1277
  // eslint-disable-next-line max-lines-per-function
1233
- handler: (i, e) => {
1234
- var O, y;
1235
- if (e == null)
1278
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1279
+ var _a8, _b;
1280
+ if (params == null)
1236
1281
  return !1;
1237
- const n = i.get($), t = i.get(un), r = i.get(ne), o = t.getActiveRange(), a = r.getCurrentUniverDocInstance();
1238
- if (o == null || a == null)
1282
+ const commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
1283
+ if (activeTextRange == null || documentDataModel == null)
1239
1284
  return !1;
1240
- const s = a.getUnitId(), { drawings: l } = e, { collapsed: c, startOffset: m, segmentId: u } = o, f = a.getSelfOrHeaderFooterModel(u).getBody();
1241
- if (f == null)
1285
+ const unitId = documentDataModel.getUnitId(), { drawings } = params, { collapsed, startOffset, segmentId } = activeTextRange, body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1286
+ if (body == null)
1242
1287
  return !1;
1243
- const h = new hn(), p = X.getInstance(), w = [], v = (y = (O = a.getSnapshot().drawingsOrder) == null ? void 0 : O.length) != null ? y : 0;
1244
- if (c)
1245
- m > 0 && h.push({
1246
- t: Z.RETAIN,
1247
- len: m,
1248
- segmentId: u
1288
+ const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], drawingOrderLength = (_b = (_a8 = documentDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _a8.length) != null ? _b : 0;
1289
+ if (collapsed)
1290
+ startOffset > 0 && textX.push({
1291
+ t: TextXActionType.RETAIN,
1292
+ len: startOffset,
1293
+ segmentId
1249
1294
  });
1250
1295
  else {
1251
- const { dos: T } = Yt(o, u, 0, f);
1252
- h.push(...T);
1296
+ const { dos } = getRetainAndDeleteFromReplace(activeTextRange, segmentId, 0, body);
1297
+ textX.push(...dos);
1253
1298
  }
1254
- h.push({
1255
- t: Z.INSERT,
1299
+ textX.push({
1300
+ t: TextXActionType.INSERT,
1256
1301
  body: {
1257
- dataStream: "\b".repeat(l.length),
1258
- customBlocks: l.map((T, N) => ({
1259
- startIndex: N,
1260
- blockId: T.drawingId
1302
+ dataStream: "\b".repeat(drawings.length),
1303
+ customBlocks: drawings.map((drawing, i) => ({
1304
+ startIndex: i,
1305
+ blockId: drawing.drawingId
1261
1306
  }))
1262
1307
  },
1263
- len: l.length,
1308
+ len: drawings.length,
1264
1309
  line: 0,
1265
- segmentId: u
1310
+ segmentId
1266
1311
  });
1267
- const I = $e(a, u), D = p.editOp(h.serialize(), I);
1268
- w.push(D);
1269
- for (const T of l) {
1270
- const { drawingId: N } = T, R = p.insertOp(["drawings", N], T), E = p.insertOp(["drawingsOrder", v], N);
1271
- w.push(R), w.push(E);
1312
+ const path = getRichTextEditPath(documentDataModel, segmentId), placeHolderAction = jsonX.editOp(textX.serialize(), path);
1313
+ rawActions.push(placeHolderAction);
1314
+ for (const drawing of drawings) {
1315
+ const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength], drawingId);
1316
+ rawActions.push(addDrawingAction), rawActions.push(addDrawingOrderAction);
1272
1317
  }
1273
- const _ = {
1274
- id: Q.id,
1318
+ const doMutation = {
1319
+ id: RichTextEditingMutation.id,
1275
1320
  params: {
1276
- unitId: s,
1321
+ unitId,
1277
1322
  actions: [],
1278
1323
  textRanges: []
1279
1324
  }
1280
1325
  };
1281
- return _.params.actions = w.reduce((T, N) => X.compose(T, N), null), !!n.syncExecuteCommand(_.id, _.params);
1282
- }
1326
+ return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1327
+ }, "handler")
1283
1328
  };
1284
- function Ke(i) {
1285
- return i.getContextValue(St) && i.getContextValue(rn);
1329
+ function whenDocDrawingFocused(contextService) {
1330
+ return contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && contextService.getContextValue(FOCUSING_COMMON_DRAWINGS);
1286
1331
  }
1287
- const Gi = {
1288
- id: Xe.id,
1332
+ __name(whenDocDrawingFocused, "whenDocDrawingFocused");
1333
+ const MoveDrawingDownShortcutItem = {
1334
+ id: MoveDocDrawingsCommand.id,
1289
1335
  description: "shortcut.doc.drawing-move-down",
1290
1336
  group: "4_doc-drawing-view",
1291
- binding: Le.ARROW_DOWN,
1337
+ binding: KeyCode.ARROW_DOWN,
1292
1338
  priority: 100,
1293
- preconditions: Ke,
1339
+ preconditions: whenDocDrawingFocused,
1294
1340
  staticParameters: {
1295
- direction: ge.DOWN
1341
+ direction: Direction.DOWN
1296
1342
  }
1297
- }, Vi = {
1298
- id: Xe.id,
1343
+ }, MoveDrawingUpShortcutItem = {
1344
+ id: MoveDocDrawingsCommand.id,
1299
1345
  description: "shortcut.doc.drawing-move-up",
1300
1346
  group: "4_doc-drawing-view",
1301
- binding: Le.ARROW_UP,
1347
+ binding: KeyCode.ARROW_UP,
1302
1348
  priority: 100,
1303
- preconditions: Ke,
1349
+ preconditions: whenDocDrawingFocused,
1304
1350
  staticParameters: {
1305
- direction: ge.UP
1351
+ direction: Direction.UP
1306
1352
  }
1307
- }, ji = {
1308
- id: Xe.id,
1353
+ }, MoveDrawingLeftShortcutItem = {
1354
+ id: MoveDocDrawingsCommand.id,
1309
1355
  description: "shortcut.doc.drawing-move-left",
1310
1356
  group: "4_doc-drawing-view",
1311
- binding: Le.ARROW_LEFT,
1357
+ binding: KeyCode.ARROW_LEFT,
1312
1358
  priority: 100,
1313
- preconditions: Ke,
1359
+ preconditions: whenDocDrawingFocused,
1314
1360
  staticParameters: {
1315
- direction: ge.LEFT
1361
+ direction: Direction.LEFT
1316
1362
  }
1317
- }, $i = {
1318
- id: Xe.id,
1363
+ }, MoveDrawingRightShortcutItem = {
1364
+ id: MoveDocDrawingsCommand.id,
1319
1365
  description: "shortcut.doc.drawing-move-right",
1320
1366
  group: "4_doc-drawing-view",
1321
- binding: Le.ARROW_RIGHT,
1367
+ binding: KeyCode.ARROW_RIGHT,
1322
1368
  priority: 100,
1323
- preconditions: Ke,
1369
+ preconditions: whenDocDrawingFocused,
1324
1370
  staticParameters: {
1325
- direction: ge.RIGHT
1371
+ direction: Direction.RIGHT
1326
1372
  }
1327
- }, zi = {
1328
- id: ct.id,
1373
+ }, DeleteDrawingsShortcutItem = {
1374
+ id: DeleteDocDrawingsCommand.id,
1329
1375
  description: "shortcut.doc.drawing-delete",
1330
1376
  group: "4_doc-drawing-view",
1331
1377
  // when focusing on any other input tag do not trigger this shortcut
1332
- preconditions: Ke,
1333
- binding: Le.DELETE,
1334
- mac: Le.BACKSPACE
1378
+ preconditions: whenDocDrawingFocused,
1379
+ binding: KeyCode.DELETE,
1380
+ mac: KeyCode.BACKSPACE
1335
1381
  };
1336
- var qi = Object.defineProperty, Xi = Object.getOwnPropertyDescriptor, Ki = (i, e, n, t) => {
1337
- for (var r = t > 1 ? void 0 : t ? Xi(e, n) : e, o = i.length - 1, a; o >= 0; o--)
1338
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
1339
- return t && r && qi(e, n, r), r;
1340
- }, He = (i, e) => (n, t) => e(n, t, i);
1341
- let en = class extends qe {
1342
- constructor(i, e, n, t, r) {
1343
- super(), this._injector = i, this._componentManager = e, this._menuService = n, this._commandService = t, this._shortcutService = r, this._init();
1382
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1383
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1384
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1385
+ return kind && result && __defProp$5(target, key, result), result;
1386
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a2;
1387
+ let DocDrawingUIController = (_a2 = class extends Disposable {
1388
+ constructor(_injector, _componentManager, _menuService, _commandService, _shortcutService) {
1389
+ super(), this._injector = _injector, this._componentManager = _componentManager, this._menuService = _menuService, this._commandService = _commandService, this._shortcutService = _shortcutService, this._init();
1344
1390
  }
1345
1391
  _initCustomComponents() {
1346
- const i = this._componentManager;
1347
- this.disposeWithMe(i.register(et, Qn)), this.disposeWithMe(i.register(Jn, vi)), this.disposeWithMe(i.register(qn, Hi));
1392
+ const componentManager = this._componentManager;
1393
+ this.disposeWithMe(componentManager.register(ImageUploadIcon, AddImageSingle)), this.disposeWithMe(componentManager.register(COMPONENT_DOC_UPLOAD_FILE_MENU, UploadFileMenu)), this.disposeWithMe(componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
1348
1394
  }
1349
1395
  _initMenus() {
1350
1396
  [
1351
- _i,
1352
- Ci
1353
- ].forEach((i) => {
1354
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i), {}));
1397
+ ImageMenuFactory,
1398
+ UploadFloatImageMenuFactory
1399
+ ].forEach((factory) => {
1400
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
1355
1401
  });
1356
1402
  }
1357
1403
  _initCommands() {
1358
1404
  [
1359
- In,
1360
- gt,
1361
- it,
1362
- rt,
1363
- ot,
1364
- ze,
1365
- at,
1366
- st,
1367
- vn,
1368
- Xn,
1369
- Wi,
1370
- Kn,
1371
- mt,
1372
- dt,
1373
- Xe,
1374
- ct,
1375
- lt
1376
- ].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i)));
1405
+ InsertDocImageOperation,
1406
+ InsertDocDrawingCommand,
1407
+ UpdateDocDrawingWrappingStyleCommand,
1408
+ UpdateDocDrawingDistanceCommand,
1409
+ UpdateDocDrawingWrapTextCommand,
1410
+ UpdateDrawingDocTransformCommand,
1411
+ IMoveInlineDrawingCommand,
1412
+ ITransformNonInlineDrawingCommand,
1413
+ RemoveDocDrawingCommand,
1414
+ SidebarDocDrawingOperation,
1415
+ ClearDocDrawingTransformerOperation,
1416
+ EditDocDrawingOperation,
1417
+ GroupDocDrawingCommand,
1418
+ UngroupDocDrawingCommand,
1419
+ MoveDocDrawingsCommand,
1420
+ DeleteDocDrawingsCommand,
1421
+ SetDocDrawingArrangeCommand
1422
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
1377
1423
  }
1378
1424
  _initShortcuts() {
1379
1425
  [
1380
1426
  // sheet drawing shortcuts
1381
- Gi,
1382
- Vi,
1383
- ji,
1384
- $i,
1385
- zi
1386
- ].forEach((i) => {
1387
- this.disposeWithMe(this._shortcutService.registerShortcut(i));
1427
+ MoveDrawingDownShortcutItem,
1428
+ MoveDrawingUpShortcutItem,
1429
+ MoveDrawingLeftShortcutItem,
1430
+ MoveDrawingRightShortcutItem,
1431
+ DeleteDrawingsShortcutItem
1432
+ ].forEach((item) => {
1433
+ this.disposeWithMe(this._shortcutService.registerShortcut(item));
1388
1434
  });
1389
1435
  }
1390
1436
  _init() {
1391
1437
  this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
1392
1438
  }
1393
- };
1394
- en = Ki([
1395
- sn(cn.Ready, en),
1396
- He(0, pe(Hn)),
1397
- He(1, pe(ti)),
1398
- He(2, ii),
1399
- He(3, $),
1400
- He(4, ri)
1401
- ], en);
1402
- var Yi = Object.defineProperty, Zi = Object.getOwnPropertyDescriptor, Qi = (i, e, n, t) => {
1403
- for (var r = t > 1 ? void 0 : t ? Zi(e, n) : e, o = i.length - 1, a; o >= 0; o--)
1404
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
1405
- return t && r && Yi(e, n, r), r;
1406
- }, de = (i, e) => (n, t) => e(n, t, i);
1407
- let fn = class extends qe {
1408
- constructor(i, e, n, t, r, o, a, s, l, c, m, u, f) {
1409
- super(), this._context = i, this._commandService = e, this._textSelectionManagerService = n, this._renderManagerSrv = t, this._imageIoService = r, this._docDrawingService = o, this._drawingManagerService = a, this._contextService = s, this._messageService = l, this._localeService = c, this._textSelectionManager = m, this._textSelectionRenderManager = u, this._docRefreshDrawingsService = f, this._initCommandListeners(), this._updateDrawingListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._editAreaChangeListener();
1439
+ }, __name(_a2, "DocDrawingUIController"), _a2);
1440
+ DocDrawingUIController = __decorateClass$5([
1441
+ OnLifecycle(LifecycleStages.Ready, DocDrawingUIController),
1442
+ __decorateParam$5(0, Inject(Injector)),
1443
+ __decorateParam$5(1, Inject(ComponentManager)),
1444
+ __decorateParam$5(2, IMenuService),
1445
+ __decorateParam$5(3, ICommandService),
1446
+ __decorateParam$5(4, IShortcutService)
1447
+ ], DocDrawingUIController);
1448
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1449
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1450
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1451
+ return kind && result && __defProp$4(target, key, result), result;
1452
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a3;
1453
+ let DocDrawingUpdateRenderController = (_a3 = class extends Disposable {
1454
+ constructor(_context, _commandService, _textSelectionManagerService, _renderManagerSrv, _imageIoService, _docDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, _textSelectionManager, _textSelectionRenderManager, _docRefreshDrawingsService) {
1455
+ super(), this._context = _context, this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._renderManagerSrv = _renderManagerSrv, this._imageIoService = _imageIoService, this._docDrawingService = _docDrawingService, this._drawingManagerService = _drawingManagerService, this._contextService = _contextService, this._messageService = _messageService, this._localeService = _localeService, this._textSelectionManager = _textSelectionManager, this._textSelectionRenderManager = _textSelectionRenderManager, this._docRefreshDrawingsService = _docRefreshDrawingsService, this._initCommandListeners(), this._updateDrawingListener(), this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._editAreaChangeListener();
1410
1456
  }
1411
1457
  /**
1412
1458
  * Upload image to cell or float image
1413
1459
  */
1414
1460
  _initCommandListeners() {
1415
1461
  this.disposeWithMe(
1416
- this._commandService.onCommandExecuted(async (i) => {
1417
- if (i.id === In.id) {
1418
- const e = i.params;
1419
- if (e.files == null)
1462
+ this._commandService.onCommandExecuted(async (command) => {
1463
+ if (command.id === InsertDocImageOperation.id) {
1464
+ const params = command.params;
1465
+ if (params.files == null)
1420
1466
  return;
1421
- const n = e.files.length;
1422
- if (n > Dn) {
1467
+ const fileLength = params.files.length;
1468
+ if (fileLength > DRAWING_IMAGE_COUNT_LIMIT) {
1423
1469
  this._messageService.show({
1424
- type: An.Error,
1425
- content: this._localeService.t("update-status.exceedMaxCount", String(Dn))
1470
+ type: MessageType.Error,
1471
+ content: this._localeService.t("update-status.exceedMaxCount", String(DRAWING_IMAGE_COUNT_LIMIT))
1426
1472
  });
1427
1473
  return;
1428
1474
  }
1429
- this._imageIoService.setWaitCount(n), await this._insertFloatImages(e.files);
1475
+ this._imageIoService.setWaitCount(fileLength), await this._insertFloatImages(params.files);
1430
1476
  }
1431
1477
  })
1432
1478
  );
1433
1479
  }
1434
1480
  // eslint-disable-next-line max-lines-per-function
1435
- async _insertFloatImages(i) {
1436
- let e = [];
1481
+ async _insertFloatImages(files) {
1482
+ let imageParams = [];
1437
1483
  try {
1438
- e = await Promise.all(i.map((r) => this._imageIoService.saveImage(r)));
1439
- } catch (r) {
1440
- const o = r.message;
1441
- let a = "";
1442
- switch (o) {
1443
- case gn.ERROR_EXCEED_SIZE:
1444
- a = this._localeService.t("update-status.exceedMaxSize", String(Lt / (1024 * 1024)));
1484
+ imageParams = await Promise.all(files.map((file) => this._imageIoService.saveImage(file)));
1485
+ } catch (error) {
1486
+ const type = error.message;
1487
+ let content = "";
1488
+ switch (type) {
1489
+ case ImageUploadStatusType.ERROR_EXCEED_SIZE:
1490
+ content = this._localeService.t("update-status.exceedMaxSize", String(DRAWING_IMAGE_ALLOW_SIZE / (1024 * 1024)));
1445
1491
  break;
1446
- case gn.ERROR_IMAGE_TYPE:
1447
- a = this._localeService.t("update-status.invalidImageType");
1492
+ case ImageUploadStatusType.ERROR_IMAGE_TYPE:
1493
+ content = this._localeService.t("update-status.invalidImageType");
1448
1494
  break;
1449
- case gn.ERROR_IMAGE:
1450
- a = this._localeService.t("update-status.invalidImage");
1495
+ case ImageUploadStatusType.ERROR_IMAGE:
1496
+ content = this._localeService.t("update-status.invalidImage");
1451
1497
  break;
1452
1498
  }
1453
1499
  this._messageService.show({
1454
- type: An.Error,
1455
- content: a
1500
+ type: MessageType.Error,
1501
+ content
1456
1502
  });
1457
1503
  }
1458
- if (e.length === 0)
1504
+ if (imageParams.length === 0)
1459
1505
  return;
1460
- const { unitId: n } = this._context, t = [];
1461
- for (const r of e) {
1462
- if (r == null)
1506
+ const { unitId } = this._context, docDrawingParams = [];
1507
+ for (const imageParam of imageParams) {
1508
+ if (imageParam == null)
1463
1509
  continue;
1464
- const { imageId: o, imageSourceType: a, source: s, base64Cache: l } = r, { width: c, height: m, image: u } = await Ut(l || "");
1465
- this._imageIoService.addImageSourceCache(o, a, u);
1466
- let f = 1;
1467
- if (c > En || m > Pn) {
1468
- const v = En / c, I = Pn / m;
1469
- f = Math.min(v, I);
1510
+ const { imageId, imageSourceType, source, base64Cache } = imageParam, { width, height, image } = await getImageSize(base64Cache || "");
1511
+ this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);
1512
+ let scale = 1;
1513
+ if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
1514
+ const scaleWidth = DRAWING_IMAGE_WIDTH_LIMIT / width, scaleHeight = DRAWING_IMAGE_HEIGHT_LIMIT / height;
1515
+ scale = Math.min(scaleWidth, scaleHeight);
1470
1516
  }
1471
- const h = this._getImagePosition(c * f, m * f);
1472
- if (h == null)
1517
+ const docTransform = this._getImagePosition(width * scale, height * scale);
1518
+ if (docTransform == null)
1473
1519
  return;
1474
- const p = {
1475
- unitId: n,
1476
- subUnitId: n,
1477
- drawingId: o,
1478
- drawingType: Bt.DRAWING_IMAGE,
1479
- imageSourceType: a,
1480
- source: s,
1481
- transform: Kt(h),
1482
- docTransform: h,
1483
- behindDoc: oe.FALSE,
1520
+ const docDrawingParam = {
1521
+ unitId,
1522
+ subUnitId: unitId,
1523
+ drawingId: imageId,
1524
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
1525
+ imageSourceType,
1526
+ source,
1527
+ transform: docDrawingPositionToTransform(docTransform),
1528
+ docTransform,
1529
+ behindDoc: BooleanNumber.FALSE,
1484
1530
  title: "",
1485
1531
  description: "",
1486
- layoutType: k.INLINE,
1532
+ layoutType: PositionedObjectLayoutType.INLINE,
1487
1533
  // Insert inline drawing by default.
1488
- wrapText: je.BOTH_SIDES,
1534
+ wrapText: WrapTextType.BOTH_SIDES,
1489
1535
  distB: 0,
1490
1536
  distL: 0,
1491
1537
  distR: 0,
1492
1538
  distT: 0
1493
1539
  };
1494
- this._isInsertInHeaderFooter() && (p.isMultiTransform = oe.TRUE, p.transforms = p.transform ? [p.transform] : null), t.push(p);
1540
+ this._isInsertInHeaderFooter() && (docDrawingParam.isMultiTransform = BooleanNumber.TRUE, docDrawingParam.transforms = docDrawingParam.transform ? [docDrawingParam.transform] : null), docDrawingParams.push(docDrawingParam);
1495
1541
  }
1496
- this._commandService.executeCommand(gt.id, {
1497
- unitId: n,
1498
- drawings: t
1542
+ this._commandService.executeCommand(InsertDocDrawingCommand.id, {
1543
+ unitId,
1544
+ drawings: docDrawingParams
1499
1545
  });
1500
1546
  }
1501
1547
  _isInsertInHeaderFooter() {
1502
- var t;
1503
- const { unitId: i } = this._context, e = (t = this._renderManagerSrv.getRenderById(i)) == null ? void 0 : t.with(ae).getViewModel(), n = e == null ? void 0 : e.getEditArea();
1504
- return n === xe.HEADER || n === xe.FOOTER;
1548
+ var _a8;
1549
+ const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel(), editArea = viewModel == null ? void 0 : viewModel.getEditArea();
1550
+ return editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER;
1505
1551
  }
1506
- _getImagePosition(i, e) {
1507
- const n = this._textSelectionManagerService.getActiveTextRange(), t = (n == null ? void 0 : n.getAbsolutePosition()) || {
1552
+ _getImagePosition(imageWidth, imageHeight) {
1553
+ const activeTextRange = this._textSelectionManagerService.getActiveTextRange(), position = (activeTextRange == null ? void 0 : activeTextRange.getAbsolutePosition()) || {
1508
1554
  left: 0,
1509
1555
  top: 0
1510
1556
  };
1511
1557
  return {
1512
1558
  size: {
1513
- width: i,
1514
- height: e
1559
+ width: imageWidth,
1560
+ height: imageHeight
1515
1561
  },
1516
1562
  positionH: {
1517
- relativeFrom: ee.PAGE,
1518
- posOffset: t.left
1563
+ relativeFrom: ObjectRelativeFromH.PAGE,
1564
+ posOffset: position.left
1519
1565
  },
1520
1566
  positionV: {
1521
- relativeFrom: V.MARGIN,
1522
- posOffset: t.top
1567
+ relativeFrom: ObjectRelativeFromV.MARGIN,
1568
+ posOffset: position.top
1523
1569
  },
1524
1570
  angle: 0
1525
1571
  };
1526
1572
  }
1527
1573
  _updateOrderListener() {
1528
- this._drawingManagerService.featurePluginOrderUpdate$.subscribe((i) => {
1529
- const { unitId: e, subUnitId: n, drawingIds: t, arrangeType: r } = i;
1530
- this._commandService.executeCommand(lt.id, {
1531
- unitId: e,
1532
- subUnitId: n,
1533
- drawingIds: t,
1534
- arrangeType: r
1574
+ this._drawingManagerService.featurePluginOrderUpdate$.subscribe((params) => {
1575
+ const { unitId, subUnitId, drawingIds, arrangeType } = params;
1576
+ this._commandService.executeCommand(SetDocDrawingArrangeCommand.id, {
1577
+ unitId,
1578
+ subUnitId,
1579
+ drawingIds,
1580
+ arrangeType
1535
1581
  });
1536
1582
  });
1537
1583
  }
1538
1584
  _updateDrawingListener() {
1539
- this._drawingManagerService.featurePluginUpdate$.subscribe((i) => {
1585
+ this._drawingManagerService.featurePluginUpdate$.subscribe((params) => {
1540
1586
  });
1541
1587
  }
1542
1588
  _groupDrawingListener() {
1543
- this._drawingManagerService.featurePluginGroupUpdate$.subscribe((i) => {
1544
- this._commandService.executeCommand(mt.id, i);
1545
- }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((i) => {
1546
- this._commandService.executeCommand(dt.id, i);
1589
+ this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
1590
+ this._commandService.executeCommand(GroupDocDrawingCommand.id, params);
1591
+ }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((params) => {
1592
+ this._commandService.executeCommand(UngroupDocDrawingCommand.id, params);
1547
1593
  });
1548
1594
  }
1549
1595
  _getCurrentSceneAndTransformer() {
1550
- const { scene: i, mainComponent: e } = this._context;
1551
- if (i == null || e == null)
1596
+ const { scene, mainComponent } = this._context;
1597
+ if (scene == null || mainComponent == null)
1552
1598
  return;
1553
- const n = i.getTransformerByCreate(), { docsLeft: t, docsTop: r } = e.getOffsetConfig();
1554
- return { scene: i, transformer: n, docsLeft: t, docsTop: r };
1599
+ const transformer = scene.getTransformerByCreate(), { docsLeft, docsTop } = mainComponent.getOffsetConfig();
1600
+ return { scene, transformer, docsLeft, docsTop };
1555
1601
  }
1556
1602
  _focusDrawingListener() {
1557
1603
  this.disposeWithMe(
1558
- this._drawingManagerService.focus$.subscribe((i) => {
1559
- var r;
1560
- const { transformer: e, docsLeft: n, docsTop: t } = (r = this._getCurrentSceneAndTransformer()) != null ? r : {};
1561
- if (i == null || i.length === 0)
1562
- this._contextService.setContextValue(rn, !1), this._docDrawingService.focusDrawing([]), e && e.resetProps({
1604
+ this._drawingManagerService.focus$.subscribe((params) => {
1605
+ var _a8;
1606
+ const { transformer, docsLeft, docsTop } = (_a8 = this._getCurrentSceneAndTransformer()) != null ? _a8 : {};
1607
+ if (params == null || params.length === 0)
1608
+ this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !1), this._docDrawingService.focusDrawing([]), transformer && transformer.resetProps({
1563
1609
  zeroTop: 0,
1564
1610
  zeroLeft: 0
1565
1611
  });
1566
1612
  else {
1567
- this._contextService.setContextValue(rn, !0), this._docDrawingService.focusDrawing(i), this._textSelectionManager.getActiveTextRange() && this._textSelectionManager.replaceTextRanges([]);
1568
- const a = this._textSelectionRenderManager.getSegment(), s = this._findSegmentIdByDrawingId(i[0].drawingId);
1569
- a !== s && this._textSelectionRenderManager.setSegment(s), e && e.resetProps({
1570
- zeroTop: t,
1571
- zeroLeft: n
1613
+ this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !0), this._docDrawingService.focusDrawing(params), this._textSelectionManager.getActiveTextRange() && this._textSelectionManager.replaceTextRanges([]);
1614
+ const prevSegmentId = this._textSelectionRenderManager.getSegment(), segmentId = this._findSegmentIdByDrawingId(params[0].drawingId);
1615
+ prevSegmentId !== segmentId && this._textSelectionRenderManager.setSegment(segmentId), transformer && transformer.resetProps({
1616
+ zeroTop: docsTop,
1617
+ zeroLeft: docsLeft
1572
1618
  });
1573
1619
  }
1574
1620
  })
1575
1621
  );
1576
1622
  }
1577
- _findSegmentIdByDrawingId(i) {
1578
- var a, s, l;
1579
- const { unit: e } = this._context, { body: n, headers: t = {}, footers: r = {} } = e.getSnapshot();
1580
- if (((a = n == null ? void 0 : n.customBlocks) != null ? a : []).some((c) => c.blockId === i))
1623
+ _findSegmentIdByDrawingId(drawingId) {
1624
+ var _a8, _b, _c;
1625
+ const { unit: DocDataModel } = this._context, { body, headers = {}, footers = {} } = DocDataModel.getSnapshot();
1626
+ if (((_a8 = body == null ? void 0 : body.customBlocks) != null ? _a8 : []).some((b) => b.blockId === drawingId))
1581
1627
  return "";
1582
- for (const c of Object.keys(t))
1583
- if ((s = t[c].body.customBlocks) != null && s.some((m) => m.blockId === i))
1584
- return c;
1585
- for (const c of Object.keys(r))
1586
- if ((l = r[c].body.customBlocks) != null && l.some((m) => m.blockId === i))
1587
- return c;
1628
+ for (const headerId of Object.keys(headers))
1629
+ if ((_b = headers[headerId].body.customBlocks) != null && _b.some((b) => b.blockId === drawingId))
1630
+ return headerId;
1631
+ for (const footerId of Object.keys(footers))
1632
+ if ((_c = footers[footerId].body.customBlocks) != null && _c.some((b) => b.blockId === drawingId))
1633
+ return footerId;
1588
1634
  return "";
1589
1635
  }
1590
1636
  // Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
1591
1637
  _updateDrawingsEditStatus() {
1592
- var s;
1593
- const { unit: i, scene: e, unitId: n } = this._context, t = (s = this._renderManagerSrv.getRenderById(n)) == null ? void 0 : s.with(ae).getViewModel();
1594
- if (t == null || i == null)
1638
+ var _a8;
1639
+ const { unit: docDataModel, scene, unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
1640
+ if (viewModel == null || docDataModel == null)
1595
1641
  return;
1596
- const r = i.getSnapshot(), { drawings: o = {} } = r, a = t.getEditArea() === xe.BODY;
1597
- for (const l of Object.keys(o)) {
1598
- const c = o[l], m = Ft({ unitId: n, drawingId: c.drawingId, subUnitId: n }), u = e.fuzzyMathObjects(m, !0);
1599
- if (u.length)
1600
- for (const f of u)
1601
- e.detachTransformerFrom(f), f.setOpacity(0.5), (a && c.isMultiTransform !== oe.TRUE || !a && c.isMultiTransform === oe.TRUE) && (e.attachTransformerTo(f), f.setOpacity(1));
1642
+ const snapshot = docDataModel.getSnapshot(), { drawings = {} } = snapshot, isEditBody = viewModel.getEditArea() === DocumentEditArea.BODY;
1643
+ for (const key of Object.keys(drawings)) {
1644
+ const drawing = drawings[key], objectKey = getDrawingShapeKeyByDrawingSearch({ unitId, drawingId: drawing.drawingId, subUnitId: unitId }), drawingShapes = scene.fuzzyMathObjects(objectKey, !0);
1645
+ if (drawingShapes.length)
1646
+ for (const shape of drawingShapes)
1647
+ scene.detachTransformerFrom(shape), shape.setOpacity(0.5), (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) && (scene.attachTransformerTo(shape), shape.setOpacity(1));
1602
1648
  }
1603
1649
  }
1604
1650
  _editAreaChangeListener() {
1605
- var n;
1606
- const { unitId: i } = this._context, e = (n = this._renderManagerSrv.getRenderById(i)) == null ? void 0 : n.with(ae).getViewModel();
1607
- e != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
1608
- e.editAreaChange$.subscribe(() => {
1651
+ var _a8;
1652
+ const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
1653
+ viewModel != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
1654
+ viewModel.editAreaChange$.subscribe(() => {
1609
1655
  this._updateDrawingsEditStatus();
1610
1656
  })
1611
- ), this._docRefreshDrawingsService.refreshDrawings$.subscribe((t) => {
1612
- t != null && queueMicrotask(() => {
1657
+ ), this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
1658
+ skeleton != null && queueMicrotask(() => {
1613
1659
  this._updateDrawingsEditStatus();
1614
1660
  });
1615
1661
  }), this.disposeWithMe(
1616
- this._commandService.onCommandExecuted(async (t) => {
1617
- t.id === Q.id && queueMicrotask(() => {
1662
+ this._commandService.onCommandExecuted(async (command) => {
1663
+ command.id === RichTextEditingMutation.id && queueMicrotask(() => {
1618
1664
  this._updateDrawingsEditStatus();
1619
1665
  });
1620
1666
  })
1621
1667
  ));
1622
1668
  }
1623
- };
1624
- fn = Qi([
1625
- de(1, $),
1626
- de(2, pe(un)),
1627
- de(3, se),
1628
- de(4, kt),
1629
- de(5, Re),
1630
- de(6, he),
1631
- de(7, Fn),
1632
- de(8, oi),
1633
- de(9, pe(an)),
1634
- de(10, pe(un)),
1635
- de(11, Ue),
1636
- de(12, pe(ln))
1637
- ], fn);
1638
- var Ji = Object.defineProperty, er = Object.getOwnPropertyDescriptor, nr = (i, e, n, t) => {
1639
- for (var r = t > 1 ? void 0 : t ? er(e, n) : e, o = i.length - 1, a; o >= 0; o--)
1640
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
1641
- return t && r && Ji(e, n, r), r;
1642
- }, We = (i, e) => (n, t) => e(n, t, i);
1643
- let pn = class extends qe {
1644
- constructor(e, n, t, r, o, a) {
1669
+ }, __name(_a3, "DocDrawingUpdateRenderController"), _a3);
1670
+ DocDrawingUpdateRenderController = __decorateClass$4([
1671
+ __decorateParam$4(1, ICommandService),
1672
+ __decorateParam$4(2, Inject(TextSelectionManagerService)),
1673
+ __decorateParam$4(3, IRenderManagerService),
1674
+ __decorateParam$4(4, IImageIoService),
1675
+ __decorateParam$4(5, IDocDrawingService),
1676
+ __decorateParam$4(6, IDrawingManagerService),
1677
+ __decorateParam$4(7, IContextService),
1678
+ __decorateParam$4(8, IMessageService),
1679
+ __decorateParam$4(9, Inject(LocaleService)),
1680
+ __decorateParam$4(10, Inject(TextSelectionManagerService)),
1681
+ __decorateParam$4(11, ITextSelectionRenderManager),
1682
+ __decorateParam$4(12, Inject(DocRefreshDrawingsService))
1683
+ ], DocDrawingUpdateRenderController);
1684
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1685
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1686
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1687
+ return kind && result && __defProp$3(target, key, result), result;
1688
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a4;
1689
+ let DocDrawingTransformUpdateController = (_a4 = class extends Disposable {
1690
+ constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
1645
1691
  super();
1646
- _e(this, "_liquid", new Wn());
1647
- this._context = e, this._docSkeletonManagerService = n, this._commandService = t, this._editorService = r, this._drawingManagerService = o, this._docRefreshDrawingsService = a, this._initialize(), this._commandExecutedListener();
1692
+ __publicField(this, "_liquid", new Liquid());
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();
1648
1694
  }
1649
1695
  _initialize() {
1650
- this._initialRenderRefresh();
1696
+ this._initialRenderRefresh(), this._drawingInitializeListener(), this._initResize();
1651
1697
  }
1652
1698
  _initialRenderRefresh() {
1653
- this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
1654
- e != null && this._refreshDrawing(e);
1655
- }), this._docRefreshDrawingsService.refreshDrawings$.subscribe((e) => {
1656
- e != null && this._refreshDrawing(e);
1699
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
1700
+ documentSkeleton != null && this._refreshDrawing(documentSkeleton);
1701
+ }), this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
1702
+ skeleton != null && this._refreshDrawing(skeleton);
1657
1703
  });
1658
1704
  }
1659
1705
  _commandExecutedListener() {
1660
- const e = [Q.id, Zt.id];
1706
+ const updateCommandList = [RichTextEditingMutation.id, SetDocZoomRatioOperation.id];
1661
1707
  this.disposeWithMe(
1662
- this._commandService.onCommandExecuted((n) => {
1663
- if (e.includes(n.id)) {
1664
- const t = n.params, { unitId: r } = t, { unitId: o, mainComponent: a } = this._context;
1665
- if (r !== o)
1708
+ this._commandService.onCommandExecuted((command) => {
1709
+ if (updateCommandList.includes(command.id)) {
1710
+ const params = command.params, { unitId: commandUnitId } = params, { unitId, mainComponent } = this._context;
1711
+ if (commandUnitId !== unitId)
1666
1712
  return;
1667
- const s = this._docSkeletonManagerService.getSkeleton();
1668
- if (s == null)
1713
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
1714
+ if (skeleton == null)
1669
1715
  return;
1670
- if (this._editorService.isEditor(o)) {
1671
- a == null || a.makeDirty();
1716
+ if (this._editorService.isEditor(unitId)) {
1717
+ mainComponent == null || mainComponent.makeDirty();
1672
1718
  return;
1673
1719
  }
1674
- this._refreshDrawing(s);
1720
+ this._refreshDrawing(skeleton);
1675
1721
  }
1676
1722
  })
1677
1723
  );
1678
1724
  }
1679
- _refreshDrawing(e) {
1680
- var D, _;
1681
- const n = e == null ? void 0 : e.getSkeletonData(), { mainComponent: t, unitId: r } = this._context, o = t;
1682
- if (!n)
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
+ }
1737
+ _refreshDrawing(skeleton) {
1738
+ var _a8, _b;
1739
+ const skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData(), { mainComponent, unitId } = this._context, documentComponent = mainComponent;
1740
+ if (!skeletonData)
1683
1741
  return;
1684
- const { left: a, top: s, pageLayoutType: l, pageMarginLeft: c, pageMarginTop: m } = o, { pages: u, skeHeaders: f, skeFooters: h } = n, p = {};
1742
+ const { left: docsLeft, top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent, { pages, skeHeaders, skeFooters } = skeletonData, updateDrawingMap = {};
1685
1743
  this._liquid.reset();
1686
- for (let C = 0, O = u.length; C < O; C++) {
1687
- const y = u[C], { headerId: T, footerId: N, pageWidth: R } = y;
1688
- if (T) {
1689
- const E = (D = f.get(T)) == null ? void 0 : D.get(R);
1690
- E && this._calculateDrawingPosition(
1691
- r,
1692
- E,
1693
- a,
1694
- s,
1695
- p,
1696
- E.marginTop,
1697
- y.marginLeft
1744
+ for (let i = 0, len = pages.length; i < len; i++) {
1745
+ const page = pages[i], { headerId, footerId, pageWidth } = page;
1746
+ if (headerId) {
1747
+ const headerPage = (_a8 = skeHeaders.get(headerId)) == null ? void 0 : _a8.get(pageWidth);
1748
+ headerPage && this._calculateDrawingPosition(
1749
+ unitId,
1750
+ headerPage,
1751
+ docsLeft,
1752
+ docsTop,
1753
+ updateDrawingMap,
1754
+ headerPage.marginTop,
1755
+ page.marginLeft
1698
1756
  );
1699
1757
  }
1700
- if (N) {
1701
- const E = (_ = h.get(N)) == null ? void 0 : _.get(R);
1702
- E && this._calculateDrawingPosition(
1703
- r,
1704
- E,
1705
- a,
1706
- s,
1707
- p,
1708
- y.pageHeight - y.marginBottom + E.marginTop,
1709
- y.marginLeft
1758
+ if (footerId) {
1759
+ const footerPage = (_b = skeFooters.get(footerId)) == null ? void 0 : _b.get(pageWidth);
1760
+ footerPage && this._calculateDrawingPosition(
1761
+ unitId,
1762
+ footerPage,
1763
+ docsLeft,
1764
+ docsTop,
1765
+ updateDrawingMap,
1766
+ page.pageHeight - page.marginBottom + footerPage.marginTop,
1767
+ page.marginLeft
1710
1768
  );
1711
1769
  }
1712
- this._calculateDrawingPosition(r, y, a, s, p, y.marginTop, y.marginLeft), this._liquid.translatePage(y, l, c, m);
1770
+ this._calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft), this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
1713
1771
  }
1714
- const w = Object.values(p), v = w.filter((C) => !C.isMultiTransform), I = w.filter((C) => C.isMultiTransform);
1715
- v.length > 0 && this._drawingManagerService.refreshTransform(v), I.length > 0 && this._handleMultiDrawingsTransform(I);
1716
- }
1717
- _handleMultiDrawingsTransform(e) {
1718
- const { scene: n, unitId: t } = this._context, r = n.getTransformerByCreate();
1719
- e.forEach((l) => {
1720
- const c = this._drawingManagerService.getDrawingByParam(l);
1721
- c != null && (c.transform = l.transform, c.transforms = l.transforms, c.isMultiTransform = l.isMultiTransform);
1772
+ const updateDrawings = Object.values(updateDrawingMap), nonMultiDrawings = updateDrawings.filter((drawing) => !drawing.isMultiTransform), multiDrawings = updateDrawings.filter((drawing) => drawing.isMultiTransform);
1773
+ nonMultiDrawings.length > 0 && this._drawingManagerService.refreshTransform(nonMultiDrawings), multiDrawings.length > 0 && this._handleMultiDrawingsTransform(multiDrawings);
1774
+ }
1775
+ _handleMultiDrawingsTransform(multiDrawings) {
1776
+ const { scene, unitId } = this._context, transformer = scene.getTransformerByCreate();
1777
+ multiDrawings.forEach((updateParam) => {
1778
+ const param = this._drawingManagerService.getDrawingByParam(updateParam);
1779
+ param != null && (param.transform = updateParam.transform, param.transforms = updateParam.transforms, param.isMultiTransform = updateParam.isMultiTransform);
1722
1780
  });
1723
- const a = [...r.getSelectedObjectMap().keys()], s = Object.values(this._drawingManagerService.getDrawingData(t, t)).filter((l) => l.isMultiTransform === oe.TRUE);
1724
- this._drawingManagerService.removeNotification(s), this._drawingManagerService.addNotification(e);
1725
- for (const l of a) {
1726
- const c = n.getObject(l);
1727
- c && r.setSelectedControl(c);
1781
+ const selectedObjectKeys = [...transformer.getSelectedObjectMap().keys()], allMultiDrawings = Object.values(this._drawingManagerService.getDrawingData(unitId, unitId)).filter((drawing) => drawing.isMultiTransform === BooleanNumber.TRUE);
1782
+ this._drawingManagerService.removeNotification(allMultiDrawings), this._drawingManagerService.addNotification(multiDrawings);
1783
+ for (const key of selectedObjectKeys) {
1784
+ const drawingShape = scene.getObject(key);
1785
+ drawingShape && transformer.setSelectedControl(drawingShape);
1728
1786
  }
1729
1787
  }
1730
- _calculateDrawingPosition(e, n, t, r, o, a, s) {
1731
- const { skeDrawings: l } = n;
1788
+ _calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft) {
1789
+ const { skeDrawings } = page;
1732
1790
  this._liquid.translatePagePadding({
1733
- marginTop: a,
1734
- marginLeft: s
1735
- }), l.forEach((c) => {
1736
- const { aLeft: m, aTop: u, height: f, width: h, angle: p, drawingId: w, drawingOrigin: v } = c, I = v.layoutType === k.WRAP_NONE && v.behindDoc === oe.TRUE, { isMultiTransform: D = oe.FALSE } = v, _ = {
1737
- left: m + t + this._liquid.x,
1738
- top: u + r + this._liquid.y,
1739
- width: h,
1740
- height: f,
1741
- angle: p
1791
+ marginTop,
1792
+ marginLeft
1793
+ }), skeDrawings.forEach((drawing) => {
1794
+ const { aLeft, aTop, height, width, angle, drawingId, drawingOrigin } = drawing, behindText = drawingOrigin.layoutType === PositionedObjectLayoutType.WRAP_NONE && drawingOrigin.behindDoc === BooleanNumber.TRUE, { isMultiTransform = BooleanNumber.FALSE } = drawingOrigin, transform = {
1795
+ left: aLeft + docsLeft + this._liquid.x,
1796
+ top: aTop + docsTop + this._liquid.y,
1797
+ width,
1798
+ height,
1799
+ angle
1742
1800
  };
1743
- o[w] == null ? o[w] = {
1744
- unitId: e,
1745
- subUnitId: e,
1746
- drawingId: w,
1747
- behindText: I,
1748
- transform: _,
1749
- transforms: [_],
1750
- isMultiTransform: D
1751
- } : D === oe.TRUE && o[w].transforms.push(_);
1801
+ updateDrawingMap[drawingId] == null ? updateDrawingMap[drawingId] = {
1802
+ unitId,
1803
+ subUnitId: unitId,
1804
+ drawingId,
1805
+ behindText,
1806
+ transform,
1807
+ transforms: [transform],
1808
+ isMultiTransform
1809
+ } : isMultiTransform === BooleanNumber.TRUE && updateDrawingMap[drawingId].transforms.push(transform);
1752
1810
  }), this._liquid.restorePagePadding({
1753
- marginTop: a,
1754
- marginLeft: s
1811
+ marginTop,
1812
+ marginLeft
1755
1813
  });
1756
1814
  }
1757
- };
1758
- pn = nr([
1759
- We(1, pe(ae)),
1760
- We(2, $),
1761
- We(3, ai),
1762
- We(4, he),
1763
- We(5, pe(ln))
1764
- ], pn);
1765
- var tr = Object.defineProperty, ir = Object.getOwnPropertyDescriptor, rr = (i, e, n, t) => {
1766
- for (var r = t > 1 ? void 0 : t ? ir(e, n) : e, o = i.length - 1, a; o >= 0; o--)
1767
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
1768
- return t && r && tr(e, n, r), r;
1769
- }, Ge = (i, e) => (n, t) => e(n, t, i);
1770
- function or(i) {
1771
- var t, r, o, a;
1772
- if (X.isNoop(i) || !Array.isArray(i))
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
+ }
1825
+ }, __name(_a4, "DocDrawingTransformUpdateController"), _a4);
1826
+ DocDrawingTransformUpdateController = __decorateClass$3([
1827
+ __decorateParam$3(1, Inject(DocSkeletonManagerService)),
1828
+ __decorateParam$3(2, ICommandService),
1829
+ __decorateParam$3(3, IEditorService),
1830
+ __decorateParam$3(4, IDrawingManagerService),
1831
+ __decorateParam$3(5, Inject(DocRefreshDrawingsService)),
1832
+ __decorateParam$3(6, IUniverInstanceService),
1833
+ __decorateParam$3(7, Inject(LifecycleService))
1834
+ ], DocDrawingTransformUpdateController);
1835
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1836
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1837
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1838
+ return kind && result && __defProp$2(target, key, result), result;
1839
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
1840
+ function getAddOrRemoveDrawings(actions) {
1841
+ var _a8, _b, _c, _d;
1842
+ if (JSONX.isNoop(actions) || !Array.isArray(actions))
1773
1843
  return null;
1774
- const e = i.find((s) => Array.isArray(s) && (s == null ? void 0 : s[0]) === "drawings");
1775
- if (e == null || !Array.isArray(e) || e.length < 3 || typeof e[1] == "string" && typeof e[2] != "object" || Array.isArray(e[1]) && typeof e[1][1] != "object")
1844
+ const drawingsOp = actions.find((action) => Array.isArray(action) && (action == null ? void 0 : action[0]) === "drawings");
1845
+ if (drawingsOp == null || !Array.isArray(drawingsOp) || drawingsOp.length < 3 || typeof drawingsOp[1] == "string" && typeof drawingsOp[2] != "object" || Array.isArray(drawingsOp[1]) && typeof drawingsOp[1][1] != "object")
1776
1846
  return null;
1777
- const n = [];
1778
- if (Array.isArray(e == null ? void 0 : e[1]))
1779
- for (const s of e)
1780
- Array.isArray(s) && n.push({
1781
- type: (t = s == null ? void 0 : s[1]) != null && t.i ? "add" : "remove",
1782
- drawingId: s == null ? void 0 : s[0],
1783
- drawing: (r = s == null ? void 0 : s[1]) == null ? void 0 : r.i
1847
+ const drawings = [];
1848
+ if (Array.isArray(drawingsOp == null ? void 0 : drawingsOp[1]))
1849
+ for (const op of drawingsOp)
1850
+ Array.isArray(op) && drawings.push({
1851
+ type: (_a8 = op == null ? void 0 : op[1]) != null && _a8.i ? "add" : "remove",
1852
+ drawingId: op == null ? void 0 : op[0],
1853
+ drawing: (_b = op == null ? void 0 : op[1]) == null ? void 0 : _b.i
1784
1854
  });
1785
1855
  else
1786
- n.push({
1787
- type: (o = e[2]) != null && o.i ? "add" : "remove",
1788
- drawingId: e[1],
1789
- drawing: (a = e[2]) == null ? void 0 : a.i
1856
+ drawings.push({
1857
+ type: (_c = drawingsOp[2]) != null && _c.i ? "add" : "remove",
1858
+ drawingId: drawingsOp[1],
1859
+ drawing: (_d = drawingsOp[2]) == null ? void 0 : _d.i
1790
1860
  });
1791
- return n;
1861
+ return drawings;
1792
1862
  }
1793
- function ar(i) {
1794
- if (!Array.isArray(i) || i.length < 3 || i[0] !== "drawingsOrder")
1863
+ __name(getAddOrRemoveDrawings, "getAddOrRemoveDrawings");
1864
+ function getReOrderedDrawings(actions) {
1865
+ if (!Array.isArray(actions) || actions.length < 3 || actions[0] !== "drawingsOrder")
1795
1866
  return [];
1796
- const e = [];
1797
- for (let n = 1; n < i.length; n++) {
1798
- const t = i[n];
1799
- if (Array.isArray(t) && typeof t[0] == "number" && typeof t[1] == "object")
1800
- e.push(t[0]);
1867
+ const drawingIndexes = [];
1868
+ for (let i = 1; i < actions.length; i++) {
1869
+ const action = actions[i];
1870
+ if (Array.isArray(action) && typeof action[0] == "number" && typeof action[1] == "object")
1871
+ drawingIndexes.push(action[0]);
1801
1872
  else {
1802
- e.length = 0;
1873
+ drawingIndexes.length = 0;
1803
1874
  break;
1804
1875
  }
1805
1876
  }
1806
- return e;
1877
+ return drawingIndexes;
1807
1878
  }
1808
- let nn = class extends qe {
1809
- constructor(i, e, n, t, r) {
1810
- super(), this._univerInstanceService = i, this._commandService = e, this._drawingManagerService = n, this._docDrawingService = t, this._renderManagerService = r, this._initialize();
1879
+ __name(getReOrderedDrawings, "getReOrderedDrawings");
1880
+ var _a5;
1881
+ let DocDrawingAddRemoveController = (_a5 = class extends Disposable {
1882
+ constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
1883
+ super(), this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._drawingManagerService = _drawingManagerService, this._docDrawingService = _docDrawingService, this._renderManagerService = _renderManagerService, this._initialize();
1811
1884
  }
1812
1885
  _initialize() {
1813
1886
  this._commandExecutedListener();
1814
1887
  }
1815
1888
  _commandExecutedListener() {
1816
1889
  this.disposeWithMe(
1817
- this._commandService.beforeCommandExecuted((i) => {
1818
- if (i.id !== Q.id)
1890
+ this._commandService.beforeCommandExecuted((command) => {
1891
+ if (command.id !== RichTextEditingMutation.id)
1819
1892
  return;
1820
- const e = i.params, { unitId: n, actions: t } = e, r = or(t);
1821
- if (r != null)
1822
- for (const { type: o, drawingId: a, drawing: s } of r)
1823
- o === "add" ? this._addDrawings(n, [s]) : this._removeDrawings(n, [a]);
1893
+ const params = command.params, { unitId, actions } = params, addOrRemoveDrawings = getAddOrRemoveDrawings(actions);
1894
+ if (addOrRemoveDrawings != null)
1895
+ for (const { type, drawingId, drawing } of addOrRemoveDrawings)
1896
+ type === "add" ? this._addDrawings(unitId, [drawing]) : this._removeDrawings(unitId, [drawingId]);
1824
1897
  })
1825
1898
  ), this.disposeWithMe(
1826
- this._commandService.onCommandExecuted((i) => {
1827
- if (i.id !== Q.id)
1899
+ this._commandService.onCommandExecuted((command) => {
1900
+ if (command.id !== RichTextEditingMutation.id)
1828
1901
  return;
1829
- const e = i.params, { unitId: n, actions: t } = e;
1830
- ar(t).length > 0 && this._updateDrawingsOrder(n);
1902
+ const params = command.params, { unitId, actions } = params;
1903
+ getReOrderedDrawings(actions).length > 0 && this._updateDrawingsOrder(unitId);
1831
1904
  })
1832
1905
  ), this.disposeWithMe(
1833
- this._commandService.onCommandExecuted((i) => {
1834
- var a;
1835
- if (i.id !== Dt.id && i.id !== Et.id)
1906
+ this._commandService.onCommandExecuted((command) => {
1907
+ var _a8;
1908
+ if (command.id !== UndoCommand.id && command.id !== RedoCommand.id)
1836
1909
  return;
1837
- const e = (a = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : a.getUnitId(), n = this._drawingManagerService.getFocusDrawings();
1838
- if (e == null || n.length === 0)
1910
+ const unitId = (_a8 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a8.getUnitId(), focusedDrawings = this._drawingManagerService.getFocusDrawings();
1911
+ if (unitId == null || focusedDrawings.length === 0)
1839
1912
  return;
1840
- const t = this._renderManagerService.getRenderById(e), r = t == null ? void 0 : t.scene;
1841
- if (r == null)
1913
+ const renderObject = this._renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
1914
+ if (scene == null)
1842
1915
  return !1;
1843
- r.getTransformerByCreate().refreshControls();
1916
+ scene.getTransformerByCreate().refreshControls();
1844
1917
  })
1845
1918
  );
1846
1919
  }
1847
- _addDrawings(i, e) {
1848
- const n = this._drawingManagerService, t = this._docDrawingService, r = this._docDrawingService.getBatchAddOp(e), { subUnitId: o, redo: a, objects: s } = r;
1849
- n.applyJson1(i, o, a), t.applyJson1(i, o, a), n.addNotification(s), t.addNotification(s);
1850
- }
1851
- _removeDrawings(i, e) {
1852
- const n = this._drawingManagerService, t = this._docDrawingService, r = this._docDrawingService.getBatchRemoveOp(e.map((l) => ({
1853
- unitId: i,
1854
- subUnitId: i,
1855
- drawingId: l
1856
- }))), { subUnitId: o, redo: a, objects: s } = r;
1857
- n.applyJson1(i, o, a), t.applyJson1(i, o, a), n.removeNotification(s), t.removeNotification(s);
1858
- }
1859
- _updateDrawingsOrder(i) {
1860
- const e = this._univerInstanceService.getUniverDocInstance(i);
1861
- if (e == null)
1920
+ _addDrawings(unitId, drawings) {
1921
+ const drawingManagerService = this._drawingManagerService, docDrawingService = this._docDrawingService, jsonOp = this._docDrawingService.getBatchAddOp(drawings), { subUnitId, redo: op, objects } = jsonOp;
1922
+ drawingManagerService.applyJson1(unitId, subUnitId, op), docDrawingService.applyJson1(unitId, subUnitId, op), drawingManagerService.addNotification(objects), docDrawingService.addNotification(objects);
1923
+ }
1924
+ _removeDrawings(unitId, drawingIds) {
1925
+ const drawingManagerService = this._drawingManagerService, docDrawingService = this._docDrawingService, jsonOp = this._docDrawingService.getBatchRemoveOp(drawingIds.map((drawingId) => ({
1926
+ unitId,
1927
+ subUnitId: unitId,
1928
+ drawingId
1929
+ }))), { subUnitId, redo: op, objects } = jsonOp;
1930
+ drawingManagerService.applyJson1(unitId, subUnitId, op), docDrawingService.applyJson1(unitId, subUnitId, op), drawingManagerService.removeNotification(objects), docDrawingService.removeNotification(objects);
1931
+ }
1932
+ _updateDrawingsOrder(unitId) {
1933
+ const documentDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
1934
+ if (documentDataModel == null)
1862
1935
  return;
1863
- const n = e.getSnapshot().drawingsOrder;
1864
- if (n == null)
1936
+ const drawingsOrder = documentDataModel.getSnapshot().drawingsOrder;
1937
+ if (drawingsOrder == null)
1865
1938
  return;
1866
- const t = this._drawingManagerService, r = this._docDrawingService;
1867
- t.setDrawingOrder(i, i, n), r.setDrawingOrder(i, i, n);
1868
- const o = {
1869
- unitId: i,
1870
- subUnitId: i,
1871
- drawingIds: n
1939
+ const drawingManagerService = this._drawingManagerService, docDrawingService = this._docDrawingService;
1940
+ drawingManagerService.setDrawingOrder(unitId, unitId, drawingsOrder), docDrawingService.setDrawingOrder(unitId, unitId, drawingsOrder);
1941
+ const objects = {
1942
+ unitId,
1943
+ subUnitId: unitId,
1944
+ drawingIds: drawingsOrder
1872
1945
  };
1873
- t.orderNotification(o), r.orderNotification(o);
1874
- }
1875
- };
1876
- nn = rr([
1877
- sn(cn.Steady, nn),
1878
- Ge(0, ne),
1879
- Ge(1, $),
1880
- Ge(2, he),
1881
- Ge(3, Re),
1882
- Ge(4, se)
1883
- ], nn);
1884
- var sr = Object.defineProperty, cr = Object.getOwnPropertyDescriptor, lr = (i, e, n, t) => {
1885
- for (var r = t > 1 ? void 0 : t ? cr(e, n) : e, o = i.length - 1, a; o >= 0; o--)
1886
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
1887
- return t && r && sr(e, n, r), r;
1888
- }, Ve = (i, e) => (n, t) => e(n, t, i);
1889
- const dr = "__InlineDrawingAnchor__";
1890
- let tn = class extends qe {
1891
- constructor(e, n, t, r, o) {
1946
+ drawingManagerService.orderNotification(objects), docDrawingService.orderNotification(objects);
1947
+ }
1948
+ }, __name(_a5, "DocDrawingAddRemoveController"), _a5);
1949
+ DocDrawingAddRemoveController = __decorateClass$2([
1950
+ OnLifecycle(LifecycleStages.Ready, DocDrawingAddRemoveController),
1951
+ __decorateParam$2(0, IUniverInstanceService),
1952
+ __decorateParam$2(1, ICommandService),
1953
+ __decorateParam$2(2, IDrawingManagerService),
1954
+ __decorateParam$2(3, IDocDrawingService),
1955
+ __decorateParam$2(4, IRenderManagerService)
1956
+ ], DocDrawingAddRemoveController);
1957
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1958
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1959
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1960
+ return kind && result && __defProp$1(target, key, result), result;
1961
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
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");
1968
+ var _a6;
1969
+ let DocDrawingTransformerController = (_a6 = class extends Disposable {
1970
+ constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService, _textSelectionRenderManager) {
1892
1971
  super();
1893
- _e(this, "_liquid", new Wn());
1894
- _e(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
1972
+ __publicField(this, "_liquid", new Liquid());
1973
+ __publicField(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
1895
1974
  // Use to cache the drawings is under transforming or scaling.
1896
- _e(this, "_transformerCache", /* @__PURE__ */ new Map());
1897
- _e(this, "_anchorShape");
1898
- this._commandService = e, this._univerInstanceService = n, this._drawingManagerService = t, this._renderManagerService = r, this._textSelectionRenderManager = o, this._init();
1975
+ __publicField(this, "_transformerCache", /* @__PURE__ */ new Map());
1976
+ __publicField(this, "_anchorShape");
1977
+ this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._textSelectionRenderManager = _textSelectionRenderManager, this._init();
1899
1978
  }
1900
1979
  _init() {
1901
1980
  this._listenDrawingFocus();
1902
1981
  }
1903
1982
  _listenDrawingFocus() {
1904
1983
  this.disposeWithMe(
1905
- this._drawingManagerService.add$.subscribe((e) => {
1906
- if (e.length !== 0)
1907
- for (const n of e) {
1908
- const { unitId: t } = n;
1909
- this._listenerOnImageMap.has(t) || (this._listenTransformerChange(t), this._listenerOnImageMap.add(t));
1984
+ this._drawingManagerService.add$.subscribe((drawingParams) => {
1985
+ if (drawingParams.length !== 0)
1986
+ for (const drawingParam of drawingParams) {
1987
+ const { unitId } = drawingParam;
1988
+ this._listenerOnImageMap.has(unitId) || (this._listenTransformerChange(unitId), this._listenerOnImageMap.add(unitId));
1910
1989
  }
1911
1990
  })
1912
1991
  );
1913
1992
  }
1914
1993
  // Only handle one drawing transformer change.
1915
1994
  // eslint-disable-next-line max-lines-per-function
1916
- _listenTransformerChange(e) {
1917
- var r;
1918
- const n = (r = this._getSceneAndTransformerByDrawingSearch(e)) == null ? void 0 : r.transformer;
1919
- if (n == null)
1995
+ _listenTransformerChange(unitId) {
1996
+ var _a8;
1997
+ const transformer = (_a8 = this._getSceneAndTransformerByDrawingSearch(unitId)) == null ? void 0 : _a8.transformer;
1998
+ if (transformer == null)
1920
1999
  return;
1921
2000
  this.disposeWithMe(
1922
- ye(
1923
- n.changeStart$.subscribe((o) => {
1924
- var s;
2001
+ toDisposable(
2002
+ transformer.changeStart$.subscribe((state) => {
2003
+ var _a9;
1925
2004
  this._transformerCache.clear();
1926
- const { objects: a } = o;
1927
- for (const l of a.values()) {
1928
- const { oKey: c, width: m, height: u, left: f, top: h, angle: p } = l, w = this._drawingManagerService.getDrawingOKey(c);
1929
- if (w == null)
2005
+ const { objects } = state;
2006
+ for (const object of objects.values()) {
2007
+ const { oKey, width, height, left, top, angle } = object, drawing = this._drawingManagerService.getDrawingOKey(oKey);
2008
+ if (drawing == null)
1930
2009
  continue;
1931
- const v = this._univerInstanceService.getUniverDocInstance(w.unitId), I = (s = v == null ? void 0 : v.getSnapshot().drawings) == null ? void 0 : s[w.drawingId];
1932
- (I == null ? void 0 : I.layoutType) === k.INLINE && l.setOpacity(0.2), I != null && this._transformerCache.set(w.drawingId, {
1933
- drawing: I,
1934
- top: h,
1935
- left: f,
1936
- width: m,
1937
- height: u,
1938
- angle: p
2010
+ const documentDataModel = this._univerInstanceService.getUniverDocInstance(drawing.unitId), drawingData = (_a9 = documentDataModel == null ? void 0 : documentDataModel.getSnapshot().drawings) == null ? void 0 : _a9[drawing.drawingId];
2011
+ (drawingData == null ? void 0 : drawingData.layoutType) === PositionedObjectLayoutType.INLINE && object.setOpacity(0.2), drawingData != null && this._transformerCache.set(drawing.drawingId, {
2012
+ drawing: drawingData,
2013
+ top,
2014
+ left,
2015
+ width,
2016
+ height,
2017
+ angle
1939
2018
  });
1940
2019
  }
1941
2020
  })
1942
2021
  )
1943
2022
  );
1944
- const t = Sn(this._updateMultipleDrawingDocTransform.bind(this), 50);
1945
- Sn(this._nonInlineDrawingTransform.bind(this), 50), this.disposeWithMe(
1946
- ye(
1947
- n.changing$.subscribe((o) => {
1948
- const { objects: a, offsetX: s, offsetY: l } = o;
1949
- if (a.size > 1)
1950
- t(a);
1951
- else if (a.size === 1) {
1952
- const c = this._transformerCache.values().next().value, m = a.values().next().value, { width: u, height: f, top: h, left: p, angle: w } = m;
1953
- if (u === c.width && f === c.height && h === c.top && p === c.left && w === c.angle)
2023
+ const throttleMultipleDrawingUpdate = throttle(this._updateMultipleDrawingDocTransform.bind(this), 50);
2024
+ throttle(this._nonInlineDrawingTransform.bind(this), 50), this.disposeWithMe(
2025
+ toDisposable(
2026
+ transformer.changing$.subscribe((state) => {
2027
+ const { objects, offsetX, offsetY } = state;
2028
+ if (objects.size > 1)
2029
+ throttleMultipleDrawingUpdate(objects);
2030
+ else if (objects.size === 1) {
2031
+ const drawingCache = this._transformerCache.values().next().value, object = objects.values().next().value, { width, height, top, left, angle } = object;
2032
+ if (width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle)
1954
2033
  return;
1955
- c && (c.drawing.layoutType, k.INLINE), c && c.drawing.layoutType === k.INLINE && s != null && l != null && this._updateInlineDrawingAnchor(c.drawing, s, l);
2034
+ drawingCache && (drawingCache.drawing.layoutType, PositionedObjectLayoutType.INLINE), drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null && this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
1956
2035
  }
1957
2036
  })
1958
2037
  )
1959
2038
  ), this.disposeWithMe(
1960
- ye(
1961
- n.changeEnd$.subscribe((o) => {
1962
- const { objects: a, offsetX: s, offsetY: l } = o;
1963
- for (const c of a.values()) {
1964
- const m = this._drawingManagerService.getDrawingOKey(c.oKey);
1965
- if (m == null)
2039
+ toDisposable(
2040
+ transformer.changeEnd$.subscribe((state) => {
2041
+ const { objects, offsetX, offsetY } = state;
2042
+ for (const object of objects.values()) {
2043
+ const drawing = this._drawingManagerService.getDrawingOKey(object.oKey);
2044
+ if (drawing == null)
1966
2045
  continue;
1967
- const u = this._transformerCache.get(m == null ? void 0 : m.drawingId);
1968
- (u == null ? void 0 : u.drawing.layoutType) === k.INLINE && c.setOpacity(1);
2046
+ const drawingCache = this._transformerCache.get(drawing == null ? void 0 : drawing.drawingId);
2047
+ (drawingCache == null ? void 0 : drawingCache.drawing.layoutType) === PositionedObjectLayoutType.INLINE && object.setOpacity(1);
1969
2048
  }
1970
- if (this._anchorShape && this._anchorShape.hide(), a.size > 1)
1971
- this._updateMultipleDrawingDocTransform(a);
1972
- else if (a.size === 1) {
1973
- const c = this._transformerCache.values().next().value, m = a.values().next().value, { width: u, height: f, top: h, left: p, angle: w } = m;
1974
- if (u === c.width && f === c.height && h === c.top && p === c.left && w === c.angle)
2049
+ if (this._anchorShape && this._anchorShape.hide(), objects.size > 1)
2050
+ this._updateMultipleDrawingDocTransform(objects);
2051
+ else if (objects.size === 1) {
2052
+ const drawingCache = this._transformerCache.values().next().value, object = objects.values().next().value, { width, height, top, left, angle } = object;
2053
+ if (width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle)
1975
2054
  return;
1976
- c && c.drawing.layoutType === k.INLINE ? u !== c.width || f !== c.height || w !== c.angle ? this._updateDrawingSize(c, m) : s != null && l != null && this._moveInlineDrawing(c.drawing, s, l) : c && this._nonInlineDrawingTransform(c.drawing, m);
2055
+ drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE ? width !== drawingCache.width || height !== drawingCache.height || angle !== drawingCache.angle ? this._updateDrawingSize(drawingCache, object) : offsetX != null && offsetY != null && this._moveInlineDrawing(drawingCache.drawing, offsetX, offsetY) : drawingCache && this._nonInlineDrawingTransform(drawingCache.drawing, object);
1977
2056
  }
1978
2057
  this._transformerCache.clear();
1979
2058
  })
@@ -1981,171 +2060,171 @@ let tn = class extends qe {
1981
2060
  );
1982
2061
  }
1983
2062
  // eslint-disable-next-line max-lines-per-function
1984
- _updateMultipleDrawingDocTransform(e) {
1985
- if (e.size < 1)
2063
+ _updateMultipleDrawingDocTransform(objects) {
2064
+ if (objects.size < 1)
1986
2065
  return;
1987
- const n = [];
1988
- let t, r;
1989
- for (const o of e.values()) {
1990
- const { oKey: a, left: s, top: l, angle: c } = o;
1991
- let { width: m, height: u } = o;
1992
- const f = this._drawingManagerService.getDrawingOKey(a);
1993
- if (f == null)
2066
+ const drawings = [];
2067
+ let unitId, subUnitId;
2068
+ for (const object of objects.values()) {
2069
+ const { oKey, left, top, angle } = object;
2070
+ let { width, height } = object;
2071
+ const drawing = this._drawingManagerService.getDrawingOKey(oKey);
2072
+ if (drawing == null)
1994
2073
  continue;
1995
- t == null && (t = f.unitId), r == null && (r = f.subUnitId);
1996
- const h = this._transformerCache.get(f.drawingId);
1997
- if (h == null)
2074
+ unitId == null && (unitId = drawing.unitId), subUnitId == null && (subUnitId = drawing.subUnitId);
2075
+ const drawingCache = this._transformerCache.get(drawing.drawingId);
2076
+ if (drawingCache == null)
1998
2077
  continue;
1999
- const { drawing: p, top: w, left: v, width: I, height: D, angle: _ } = h, { width: C, height: O } = this._getPageContentSize(p);
2000
- if (m = Math.min(m, C), u = Math.min(u, O), (I !== m || D !== u) && n.push({
2001
- drawingId: f.drawingId,
2078
+ const { drawing: drawingData, top: oldTop, left: oldLeft, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache, { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawingData);
2079
+ if (width = Math.min(width, maxWidth), height = Math.min(height, maxHeight), (oldWidth !== width || oldHeight !== height) && drawings.push({
2080
+ drawingId: drawing.drawingId,
2002
2081
  key: "size",
2003
2082
  value: {
2004
- width: m,
2005
- height: u
2083
+ width,
2084
+ height
2006
2085
  }
2007
- }), _ !== c && n.push({
2008
- drawingId: f.drawingId,
2086
+ }), oldAngle !== angle && drawings.push({
2087
+ drawingId: drawing.drawingId,
2009
2088
  key: "angle",
2010
- value: c
2011
- }), w !== l || v !== s) {
2012
- const y = l - w, T = s - v;
2013
- y !== 0 && n.push({
2014
- drawingId: f.drawingId,
2089
+ value: angle
2090
+ }), oldTop !== top || oldLeft !== left) {
2091
+ const verticalDelta = top - oldTop, horizontalDelta = left - oldLeft;
2092
+ verticalDelta !== 0 && drawings.push({
2093
+ drawingId: drawing.drawingId,
2015
2094
  key: "positionV",
2016
2095
  value: {
2017
- relativeFrom: p.docTransform.positionV.relativeFrom,
2018
- posOffset: p.docTransform.positionV.posOffset + y
2096
+ relativeFrom: drawingData.docTransform.positionV.relativeFrom,
2097
+ posOffset: drawingData.docTransform.positionV.posOffset + verticalDelta
2019
2098
  }
2020
- }), T !== 0 && n.push({
2021
- drawingId: f.drawingId,
2099
+ }), horizontalDelta !== 0 && drawings.push({
2100
+ drawingId: drawing.drawingId,
2022
2101
  key: "positionH",
2023
2102
  value: {
2024
- relativeFrom: p.docTransform.positionH.relativeFrom,
2025
- posOffset: p.docTransform.positionH.posOffset + T
2103
+ relativeFrom: drawingData.docTransform.positionH.relativeFrom,
2104
+ posOffset: drawingData.docTransform.positionH.posOffset + horizontalDelta
2026
2105
  }
2027
2106
  });
2028
2107
  }
2029
2108
  }
2030
- n.length > 0 && t && r && this._commandService.executeCommand(ze.id, {
2031
- unitId: t,
2032
- subUnitId: r,
2033
- drawings: n
2109
+ drawings.length > 0 && unitId && subUnitId && this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2110
+ unitId,
2111
+ subUnitId,
2112
+ drawings
2034
2113
  });
2035
2114
  }
2036
2115
  // TODO: @JOCS, Use to draw and update the drawing anchor.
2037
- _updateDrawingAnchor(e) {
2116
+ _updateDrawingAnchor(objects) {
2038
2117
  if (this._transformerCache.size !== 1)
2039
2118
  return;
2040
- const n = this._transformerCache.values().next().value, t = e.values().next().value;
2041
- this._getDrawingAnchor(n.drawing, t);
2119
+ const drawingCache = this._transformerCache.values().next().value, object = objects.values().next().value;
2120
+ this._getDrawingAnchor(drawingCache.drawing, object);
2042
2121
  }
2043
- _updateInlineDrawingAnchor(e, n, t) {
2044
- var o;
2122
+ _updateInlineDrawingAnchor(drawing, offsetX, offsetY) {
2123
+ var _a8;
2045
2124
  if (this._transformerCache.size !== 1)
2046
2125
  return;
2047
- const { contentBoxPointGroup: r } = (o = this._getInlineDrawingAnchor(e, n, t)) != null ? o : {};
2048
- r != null && this._createOrUpdateInlineAnchor(e.unitId, r);
2126
+ const { contentBoxPointGroup } = (_a8 = this._getInlineDrawingAnchor(drawing, offsetX, offsetY)) != null ? _a8 : {};
2127
+ contentBoxPointGroup != null && this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
2049
2128
  }
2050
- _getInlineDrawingAnchor(e, n, t) {
2051
- var z;
2052
- const r = this._renderManagerService.getRenderById(e.unitId), o = r == null ? void 0 : r.with(ae).getSkeleton();
2053
- if (r == null)
2129
+ _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
2130
+ var _a8;
2131
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
2132
+ if (currentRender == null)
2054
2133
  return;
2055
- const { mainComponent: a, scene: s } = r, l = a, c = s.getViewports()[0], {
2056
- pageLayoutType: m = On.VERTICAL,
2057
- pageMarginLeft: u,
2058
- pageMarginTop: f
2059
- } = l.getOffsetConfig();
2060
- let h = null, p = !1, w = -1, v = "";
2061
- const I = 0.5, D = this._getTransformCoordForDocumentOffset(l, c, n, t);
2062
- if (D == null)
2134
+ const { mainComponent, scene } = currentRender, documentComponent = mainComponent, activeViewport = scene.getViewports()[0], {
2135
+ pageLayoutType = PageLayoutType.VERTICAL,
2136
+ pageMarginLeft,
2137
+ pageMarginTop
2138
+ } = documentComponent.getOffsetConfig();
2139
+ let glyphAnchor = null, isBack = !1, segmentPageIndex = -1, segmentId = "";
2140
+ const HALF = 0.5, coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
2141
+ if (coord == null)
2063
2142
  return;
2064
- const _ = o == null ? void 0 : o.findNodeByCoord(
2065
- D,
2066
- m,
2067
- u,
2068
- f,
2143
+ const nodeInfo = skeleton == null ? void 0 : skeleton.findNodeByCoord(
2144
+ coord,
2145
+ pageLayoutType,
2146
+ pageMarginLeft,
2147
+ pageMarginTop,
2069
2148
  {
2070
2149
  strict: !1,
2071
2150
  segmentId: this._textSelectionRenderManager.getSegment(),
2072
2151
  segmentPage: this._textSelectionRenderManager.getSegmentPage()
2073
2152
  }
2074
2153
  );
2075
- if (_) {
2076
- const { node: U, ratioX: B, segmentPage: b, segmentId: S } = _;
2077
- p = B < I, h = U, w = b, v = S;
2154
+ if (nodeInfo) {
2155
+ const { node, ratioX, segmentPage, segmentId: nodeSegmentId } = nodeInfo;
2156
+ isBack = ratioX < HALF, glyphAnchor = node, segmentPageIndex = segmentPage, segmentId = nodeSegmentId;
2078
2157
  }
2079
- if (h == null)
2158
+ if (glyphAnchor == null)
2080
2159
  return;
2081
- const C = o == null ? void 0 : o.findPositionByGlyph(h, w), O = this._getDocObject();
2082
- if (C == null || o == null || O == null)
2160
+ const nodePosition = skeleton == null ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex), docObject = this._getDocObject();
2161
+ if (nodePosition == null || skeleton == null || docObject == null || isInTableCell(nodePosition))
2083
2162
  return;
2084
- const y = {
2085
- ...C,
2086
- isBack: p
2087
- }, T = O.document.getOffsetConfig(), N = new Tn(T, o), { cursorList: R, contentBoxPointGroup: E } = N.getRangePointData(y, y), { startOffset: H } = (z = Mn(R)) != null ? z : {};
2088
- if (H != null)
2089
- return { offset: H, contentBoxPointGroup: E, segmentId: v, segmentPage: w };
2163
+ const positionWithIsBack = {
2164
+ ...nodePosition,
2165
+ isBack
2166
+ }, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList, contentBoxPointGroup } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_a8 = getOneTextSelectionRange(cursorList)) != null ? _a8 : {};
2167
+ if (startOffset != null)
2168
+ return { offset: startOffset, contentBoxPointGroup, segmentId, segmentPage: segmentPageIndex };
2090
2169
  }
2091
2170
  // eslint-disable-next-line max-lines-per-function, complexity
2092
- _getDrawingAnchor(e, n) {
2093
- var we, ve, te, Ne, Ie, Se, Te, Me, De, J;
2094
- const t = this._renderManagerService.getRenderById(e.unitId), r = t == null ? void 0 : t.with(ae).getSkeleton(), o = r == null ? void 0 : r.getSkeletonData();
2095
- if (o == null || t == null)
2171
+ _getDrawingAnchor(drawing, object) {
2172
+ var _a8, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2173
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton(), skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData();
2174
+ if (skeletonData == null || currentRender == null)
2096
2175
  return;
2097
- const { pages: a, skeHeaders: s, skeFooters: l } = o, { mainComponent: c, scene: m } = t, u = c, f = m.getViewports()[0], { pageLayoutType: h = On.VERTICAL, pageMarginLeft: p, pageMarginTop: w, docsLeft: v, docsTop: I } = u.getOffsetConfig(), { left: D, top: _, angle: C } = n;
2098
- let { width: O, height: y } = n;
2099
- const { positionV: T, positionH: N } = e.docTransform, { width: R, height: E } = this._getPageContentSize(e);
2100
- O = Math.min(O, R), y = Math.min(y, E);
2101
- let H = null, z = "", U = -1;
2102
- const B = !1, b = {
2103
- ...e.docTransform,
2176
+ const { pages, skeHeaders, skeFooters } = skeletonData, { mainComponent, scene } = currentRender, documentComponent = mainComponent, activeViewport = scene.getViewports()[0], { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig(), { left, top, angle } = object;
2177
+ let { width, height } = object;
2178
+ const { positionV, positionH } = drawing.docTransform, { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
2179
+ width = Math.min(width, maxWidth), height = Math.min(height, maxHeight);
2180
+ let glyphAnchor = null, segmentId = "", segmentPage = -1;
2181
+ const isBack = !1, docTransform = {
2182
+ ...drawing.docTransform,
2104
2183
  size: {
2105
- width: O,
2106
- height: y
2184
+ width,
2185
+ height
2107
2186
  },
2108
- angle: C
2109
- }, { x: S, y: A } = m.getViewportScrollXY(f), P = this._getTransformCoordForDocumentOffset(u, f, D - S, _ - A);
2110
- if (P == null)
2187
+ angle
2188
+ }, { x, y } = scene.getViewportScrollXY(activeViewport), coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
2189
+ if (coord == null)
2111
2190
  return;
2112
- const L = r == null ? void 0 : r.findNodeByCoord(P, h, p, w, {
2191
+ const nodeInfo = skeleton == null ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
2113
2192
  strict: !1,
2114
2193
  segmentId: this._textSelectionRenderManager.getSegment(),
2115
2194
  segmentPage: this._textSelectionRenderManager.getSegmentPage()
2116
2195
  });
2117
- if (L) {
2118
- const { node: q, segmentPage: dn, segmentId: mn } = L;
2119
- H = q, U = dn, z = mn;
2196
+ if (nodeInfo) {
2197
+ const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
2198
+ glyphAnchor = node, segmentPage = segmentPageIndex, segmentId = nodeSegmentId;
2120
2199
  }
2121
- if (H == null)
2200
+ if (glyphAnchor == null)
2122
2201
  return;
2123
- const x = (we = H.parent) == null ? void 0 : we.parent, M = x == null ? void 0 : x.parent, W = (ve = M == null ? void 0 : M.lines.find((q) => q.paragraphIndex === (x == null ? void 0 : x.paragraphIndex) && q.paragraphStart)) != null ? ve : M == null ? void 0 : M.lines[0], G = (te = M == null ? void 0 : M.parent) == null ? void 0 : te.parent;
2124
- if (x == null || M == null || W == null || G == null)
2202
+ const line = (_a8 = glyphAnchor.parent) == null ? void 0 : _a8.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = (_b = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart)) != null ? _b : column == null ? void 0 : column.lines[0], page = (_c = column == null ? void 0 : column.parent) == null ? void 0 : _c.parent;
2203
+ if (line == null || column == null || paragraphStartLine == null || page == null)
2125
2204
  return;
2126
2205
  this._liquid.reset();
2127
- const F = G.type;
2128
- for (const q of a) {
2129
- const { headerId: dn, footerId: mn, pageHeight: pt, pageWidth: _n, marginLeft: Cn, marginBottom: ht } = q, wt = a.indexOf(q);
2130
- if (U > -1 && wt === U) {
2131
- switch (F) {
2132
- case yn.HEADER: {
2133
- const Fe = (Ne = s.get(dn)) == null ? void 0 : Ne.get(_n);
2134
- if (Fe)
2206
+ const pageType = page.type;
2207
+ for (const p of pages) {
2208
+ const { headerId, footerId, pageHeight, pageWidth, marginLeft, marginBottom } = p, pIndex = pages.indexOf(p);
2209
+ if (segmentPage > -1 && pIndex === segmentPage) {
2210
+ switch (pageType) {
2211
+ case DocumentSkeletonPageType.HEADER: {
2212
+ const headerSke = (_d = skeHeaders.get(headerId)) == null ? void 0 : _d.get(pageWidth);
2213
+ if (headerSke)
2135
2214
  this._liquid.translatePagePadding({
2136
- marginTop: Fe.marginTop,
2137
- marginLeft: Cn
2215
+ marginTop: headerSke.marginTop,
2216
+ marginLeft
2138
2217
  });
2139
2218
  else
2140
2219
  throw new Error("header skeleton not found");
2141
2220
  break;
2142
2221
  }
2143
- case yn.FOOTER: {
2144
- const Fe = (Ie = l.get(mn)) == null ? void 0 : Ie.get(_n);
2145
- if (Fe)
2222
+ case DocumentSkeletonPageType.FOOTER: {
2223
+ const footerSke = (_e = skeFooters.get(footerId)) == null ? void 0 : _e.get(pageWidth);
2224
+ if (footerSke)
2146
2225
  this._liquid.translatePagePadding({
2147
- marginTop: pt - ht + Fe.marginTop,
2148
- marginLeft: Cn
2226
+ marginTop: pageHeight - marginBottom + footerSke.marginTop,
2227
+ marginLeft
2149
2228
  });
2150
2229
  else
2151
2230
  throw new Error("footer skeleton not found");
@@ -2154,260 +2233,263 @@ let tn = class extends qe {
2154
2233
  }
2155
2234
  break;
2156
2235
  }
2157
- if (this._liquid.translatePagePadding(q), q === G)
2236
+ if (this._liquid.translatePagePadding(p), p === page)
2158
2237
  break;
2159
- this._liquid.restorePagePadding(q), this._liquid.translatePage(q, h, p, w);
2238
+ this._liquid.restorePagePadding(p), this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
2160
2239
  }
2161
- switch (T.relativeFrom === V.LINE ? H = x.divides[0].glyphGroup[0] : H = (De = (Me = (Te = (Se = W.divides) == null ? void 0 : Se[0]) == null ? void 0 : Te.glyphGroup) == null ? void 0 : Me[0]) != null ? De : H, b.positionH = {
2162
- relativeFrom: N.relativeFrom,
2163
- posOffset: D - this._liquid.x - v
2164
- }, N.relativeFrom) {
2165
- case ee.MARGIN: {
2166
- b.positionH.posOffset = D - this._liquid.x - v - G.marginLeft;
2240
+ switch (positionV.relativeFrom === ObjectRelativeFromV.LINE ? glyphAnchor = line.divides[0].glyphGroup[0] : glyphAnchor = (_i = (_h = (_g = (_f = paragraphStartLine.divides) == null ? void 0 : _f[0]) == null ? void 0 : _g.glyphGroup) == null ? void 0 : _h[0]) != null ? _i : glyphAnchor, docTransform.positionH = {
2241
+ relativeFrom: positionH.relativeFrom,
2242
+ posOffset: left - this._liquid.x - docsLeft
2243
+ }, positionH.relativeFrom) {
2244
+ case ObjectRelativeFromH.MARGIN: {
2245
+ docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - page.marginLeft;
2167
2246
  break;
2168
2247
  }
2169
- case ee.COLUMN: {
2170
- b.positionH.posOffset = D - this._liquid.x - v - M.left;
2248
+ case ObjectRelativeFromH.COLUMN: {
2249
+ docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - column.left;
2171
2250
  break;
2172
2251
  }
2173
2252
  }
2174
- switch (b.positionV = {
2175
- relativeFrom: T.relativeFrom,
2176
- posOffset: _ - this._liquid.y - I
2177
- }, T.relativeFrom) {
2178
- case V.PAGE: {
2179
- b.positionV.posOffset = _ - this._liquid.y - I - G.marginTop;
2253
+ switch (docTransform.positionV = {
2254
+ relativeFrom: positionV.relativeFrom,
2255
+ posOffset: top - this._liquid.y - docsTop
2256
+ }, positionV.relativeFrom) {
2257
+ case ObjectRelativeFromV.PAGE: {
2258
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - page.marginTop;
2180
2259
  break;
2181
2260
  }
2182
- case V.LINE: {
2183
- b.positionV.posOffset = _ - this._liquid.y - I - x.top;
2261
+ case ObjectRelativeFromV.LINE: {
2262
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - line.top;
2184
2263
  break;
2185
2264
  }
2186
- case V.PARAGRAPH: {
2187
- b.positionV.posOffset = _ - this._liquid.y - I - W.top;
2265
+ case ObjectRelativeFromV.PARAGRAPH: {
2266
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - paragraphStartLine.top;
2188
2267
  break;
2189
2268
  }
2190
2269
  }
2191
- if (H == null)
2270
+ if (glyphAnchor == null)
2192
2271
  return;
2193
- const ce = r == null ? void 0 : r.findPositionByGlyph(H, U), fe = this._getDocObject();
2194
- if (ce == null || r == null || fe == null)
2272
+ const nodePosition = skeleton == null ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage), docObject = this._getDocObject();
2273
+ if (nodePosition == null || skeleton == null || docObject == null || isInTableCell(nodePosition))
2195
2274
  return;
2196
- const Oe = {
2197
- ...ce,
2198
- isBack: B
2199
- }, Be = fe.document.getOffsetConfig(), Ce = new Tn(Be, r), { cursorList: K } = Ce.getRangePointData(Oe, Oe), { startOffset: le } = (J = Mn(K)) != null ? J : {};
2200
- if (le != null)
2201
- return { offset: le, docTransform: b, segmentId: z, segmentPage: U };
2275
+ const positionWithIsBack = {
2276
+ ...nodePosition,
2277
+ isBack
2278
+ }, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_j = getOneTextSelectionRange(cursorList)) != null ? _j : {};
2279
+ if (startOffset != null)
2280
+ return { offset: startOffset, docTransform, segmentId, segmentPage };
2202
2281
  }
2203
2282
  // Update drawing when use transformer to resize it.
2204
- _updateDrawingSize(e, n) {
2205
- const t = [], { drawing: r, width: o, height: a, angle: s } = e, { unitId: l, subUnitId: c } = r;
2206
- let { width: m, height: u, angle: f } = n;
2207
- const { width: h, height: p } = this._getPageContentSize(r);
2208
- m = Math.min(h, m), u = Math.min(p, u), (m !== o || u !== a) && t.push({
2209
- drawingId: r.drawingId,
2283
+ _updateDrawingSize(drawingCache, object) {
2284
+ const drawings = [], { drawing, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache, { unitId, subUnitId } = drawing;
2285
+ let { width, height, angle } = object;
2286
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
2287
+ width = Math.min(maxWidth, width), height = Math.min(maxHeight, height), (width !== oldWidth || height !== oldHeight) && drawings.push({
2288
+ drawingId: drawing.drawingId,
2210
2289
  key: "size",
2211
2290
  value: {
2212
- width: m,
2213
- height: u
2291
+ width,
2292
+ height
2214
2293
  }
2215
- }), f !== s && t.push({
2216
- drawingId: r.drawingId,
2294
+ }), angle !== oldAngle && drawings.push({
2295
+ drawingId: drawing.drawingId,
2217
2296
  key: "angle",
2218
- value: f
2219
- }), t.length > 0 && l && c && this._commandService.executeCommand(ze.id, {
2220
- unitId: l,
2221
- subUnitId: c,
2222
- drawings: t
2297
+ value: angle
2298
+ }), drawings.length > 0 && unitId && subUnitId && this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2299
+ unitId,
2300
+ subUnitId,
2301
+ drawings
2223
2302
  });
2224
2303
  }
2225
2304
  // Update inline drawing when use transformer to move it.
2226
- _moveInlineDrawing(e, n, t) {
2227
- const r = this._getInlineDrawingAnchor(e, n, t), { offset: o, segmentId: a, segmentPage: s } = r != null ? r : {};
2228
- if (o != null)
2229
- return this._commandService.executeCommand(at.id, {
2230
- unitId: e.unitId,
2231
- subUnitId: e.unitId,
2232
- drawing: e,
2233
- offset: o,
2234
- segmentId: a,
2235
- segmentPage: s
2236
- });
2305
+ _moveInlineDrawing(drawing, offsetX, offsetY) {
2306
+ const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY), { offset, segmentId, segmentPage } = anchor != null ? anchor : {};
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
+ });
2237
2316
  }
2238
2317
  // Limit the drawing to the page area, mainly in the vertical direction,
2239
2318
  // and the upper and lower limits cannot exceed the page margin area.
2240
- _limitDrawingInPage(e, n) {
2241
- const t = this._renderManagerService.getRenderById(e.unitId), { left: r, top: o, width: a, height: s, angle: l } = n, c = t == null ? void 0 : t.with(ae).getSkeleton(), m = c == null ? void 0 : c.getSkeletonData(), { pages: u } = m != null ? m : {};
2242
- if (m == null || t == null || u == null)
2319
+ _limitDrawingInPage(drawing, object) {
2320
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId), { left, top, width, height, angle } = object, skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton(), skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData(), { pages } = skeletonData != null ? skeletonData : {};
2321
+ if (skeletonData == null || currentRender == null || pages == null)
2243
2322
  return {
2244
- left: r,
2245
- top: o,
2246
- width: a,
2247
- height: s,
2248
- angle: l
2323
+ left,
2324
+ top,
2325
+ width,
2326
+ height,
2327
+ angle
2249
2328
  };
2250
- const { mainComponent: f } = t, h = f, { top: p, pageLayoutType: w, pageMarginLeft: v, pageMarginTop: I } = h;
2251
- let D = o;
2329
+ const { mainComponent } = currentRender, documentComponent = mainComponent, { top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent;
2330
+ let newTop = top;
2252
2331
  this._liquid.reset();
2253
- for (const _ of u) {
2254
- const { marginBottom: C, pageHeight: O } = _, y = u.indexOf(_), T = u[y + 1];
2255
- if (T == null)
2332
+ for (const page of pages) {
2333
+ const { marginBottom, pageHeight } = page, index = pages.indexOf(page), nextPage = pages[index + 1];
2334
+ if (nextPage == null)
2256
2335
  continue;
2257
- if (Pe.hasIntersectionBetweenTwoRanges(
2258
- o,
2259
- o + s,
2260
- this._liquid.y + p + O - C,
2261
- this._liquid.y + p + O + I + T.marginTop
2336
+ if (Tools.hasIntersectionBetweenTwoRanges(
2337
+ top,
2338
+ top + height,
2339
+ this._liquid.y + docsTop + pageHeight - marginBottom,
2340
+ this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop
2262
2341
  )) {
2263
- const R = o + s / 2, E = this._liquid.y + p + O + I / 2;
2264
- R < E ? D = Math.min(o, this._liquid.y + p + O - C - s) : D = Math.max(o, this._liquid.y + p + O + I + T.marginTop);
2342
+ const drawingVMiddle = top + height / 2, pagesMiddle = this._liquid.y + docsTop + pageHeight + pageMarginTop / 2;
2343
+ drawingVMiddle < pagesMiddle ? newTop = Math.min(top, this._liquid.y + docsTop + pageHeight - marginBottom - height) : newTop = Math.max(top, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop);
2265
2344
  }
2266
- this._liquid.translatePage(_, w, v, I);
2345
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2267
2346
  }
2268
2347
  return {
2269
- left: r,
2270
- top: D,
2271
- width: a,
2272
- height: s,
2273
- angle: l
2348
+ left,
2349
+ top: newTop,
2350
+ width,
2351
+ height,
2352
+ angle
2274
2353
  };
2275
2354
  }
2276
- _nonInlineDrawingTransform(e, n, t = !1) {
2277
- const r = e.isMultiTransform === oe.TRUE ? n : this._limitDrawingInPage(e, n);
2278
- if (t && r.top !== n.top)
2355
+ _nonInlineDrawingTransform(drawing, object, isMoving = !1) {
2356
+ const objectPosition = drawing.isMultiTransform === BooleanNumber.TRUE ? object : this._limitDrawingInPage(drawing, object);
2357
+ if (isMoving && objectPosition.top !== object.top)
2279
2358
  return;
2280
- const o = this._getDrawingAnchor(e, r), { offset: a, docTransform: s, segmentId: l, segmentPage: c } = o != null ? o : {};
2281
- return a == null || s == null ? this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[e.drawingId, n]])) : this._commandService.executeCommand(st.id, {
2282
- unitId: e.unitId,
2283
- subUnitId: e.unitId,
2284
- drawing: e,
2285
- offset: a,
2286
- docTransform: s,
2287
- segmentId: l,
2288
- segmentPage: c
2359
+ const anchor = this._getDrawingAnchor(drawing, objectPosition), { offset, docTransform, segmentId, segmentPage } = anchor != null ? anchor : {};
2360
+ return offset == null || docTransform == null ? this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[drawing.drawingId, object]])) : this._commandService.executeCommand(ITransformNonInlineDrawingCommand.id, {
2361
+ unitId: drawing.unitId,
2362
+ subUnitId: drawing.unitId,
2363
+ drawing,
2364
+ offset,
2365
+ docTransform,
2366
+ segmentId,
2367
+ segmentPage
2289
2368
  });
2290
2369
  }
2291
- _getSceneAndTransformerByDrawingSearch(e) {
2292
- if (e == null)
2370
+ _getSceneAndTransformerByDrawingSearch(unitId) {
2371
+ if (unitId == null)
2293
2372
  return;
2294
- const n = this._renderManagerService.getRenderById(e), t = n == null ? void 0 : n.scene;
2295
- if (t == null)
2373
+ const renderObject = this._renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
2374
+ if (scene == null)
2296
2375
  return;
2297
- const r = t.getTransformerByCreate();
2298
- return { scene: t, transformer: r };
2376
+ const transformer = scene.getTransformerByCreate();
2377
+ return { scene, transformer };
2299
2378
  }
2300
- _getTransformCoordForDocumentOffset(e, n, t, r) {
2301
- const { documentTransform: o } = e.getOffsetConfig(), a = n.transformVector2SceneCoord(Gt.FromArray([t, r]));
2302
- if (a)
2303
- return o.clone().invert().applyPoint(a);
2379
+ _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
2380
+ const { documentTransform } = document.getOffsetConfig(), originCoord = viewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
2381
+ if (originCoord)
2382
+ return documentTransform.clone().invert().applyPoint(originCoord);
2304
2383
  }
2305
- _createOrUpdateInlineAnchor(e, n) {
2306
- const t = this._renderManagerService.getRenderById(e);
2307
- if (t == null)
2384
+ _createOrUpdateInlineAnchor(unitId, pointsGroup) {
2385
+ const currentRender = this._renderManagerService.getRenderById(unitId);
2386
+ if (currentRender == null)
2308
2387
  return;
2309
- const { mainComponent: r, scene: o } = t, a = r, {
2310
- docsLeft: s,
2311
- docsTop: l
2312
- } = a.getOffsetConfig(), c = Vt(n), { left: m, top: u, height: f } = c, h = m + s, p = u + l;
2388
+ const { mainComponent, scene } = currentRender, documentComponent = mainComponent, {
2389
+ docsLeft,
2390
+ docsTop
2391
+ } = documentComponent.getOffsetConfig(), bounding = getAnchorBounding(pointsGroup), { left: boundingLeft, top: boundingTop, height } = bounding, left = boundingLeft + docsLeft, top = boundingTop + docsTop;
2313
2392
  if (this._anchorShape) {
2314
- this._anchorShape.transformByState({ left: h, top: p, height: f }), this._anchorShape.show();
2393
+ this._anchorShape.transformByState({ left, top, height }), this._anchorShape.show();
2315
2394
  return;
2316
2395
  }
2317
- const w = 6, v = new jt(dr + Pe.generateRandomId(w), {
2318
- left: h,
2319
- top: p,
2320
- height: f,
2396
+ const ID_LENGTH = 6, anchor = new Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + Tools.generateRandomId(ID_LENGTH), {
2397
+ left,
2398
+ top,
2399
+ height,
2321
2400
  strokeWidth: 2,
2322
- stroke: $t(Pt.darkGray, 1),
2401
+ stroke: getColor(COLORS.darkGray, 1),
2323
2402
  evented: !1
2324
2403
  });
2325
- this._anchorShape = v, o.addObject(v, zt);
2404
+ this._anchorShape = anchor, scene.addObject(anchor, TEXT_RANGE_LAYER_INDEX);
2326
2405
  }
2327
2406
  _getDocObject() {
2328
- return Qt(this._univerInstanceService, this._renderManagerService);
2407
+ return getDocObject(this._univerInstanceService, this._renderManagerService);
2329
2408
  }
2330
- _getPageContentSize(e) {
2331
- const n = this._renderManagerService.getRenderById(e.unitId), t = n == null ? void 0 : n.with(ae).getSkeleton(), r = 500, o = 500, a = t == null ? void 0 : t.getSkeletonData();
2332
- if (a == null || n == null)
2409
+ _getPageContentSize(drawing) {
2410
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton(), MAX_WIDTH = 500, MAX_HEIGHT = 500, skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData();
2411
+ if (skeletonData == null || currentRender == null)
2333
2412
  return {
2334
- width: r,
2335
- height: o
2413
+ width: MAX_WIDTH,
2414
+ height: MAX_HEIGHT
2336
2415
  };
2337
- const { pages: s } = a;
2338
- let l = null;
2339
- for (const c of s) {
2340
- const { skeDrawings: m } = c;
2341
- if (m.has(e.drawingId)) {
2342
- l = c;
2416
+ const { pages } = skeletonData;
2417
+ let page = null;
2418
+ for (const p of pages) {
2419
+ const { skeDrawings } = p;
2420
+ if (skeDrawings.has(drawing.drawingId)) {
2421
+ page = p;
2343
2422
  break;
2344
2423
  }
2345
2424
  }
2346
- if (l) {
2347
- const { pageWidth: c, pageHeight: m, marginLeft: u, marginBottom: f, marginRight: h, marginTop: p } = l;
2425
+ if (page) {
2426
+ const { pageWidth, pageHeight, marginLeft, marginBottom, marginRight, marginTop } = page;
2348
2427
  return {
2349
- width: Math.max(r, c - u - h),
2350
- height: Math.max(o, m - p - f)
2428
+ width: Math.max(MAX_WIDTH, pageWidth - marginLeft - marginRight),
2429
+ height: Math.max(MAX_HEIGHT, pageHeight - marginTop - marginBottom)
2351
2430
  };
2352
2431
  } else
2353
2432
  return {
2354
- width: r,
2355
- height: o
2433
+ width: MAX_WIDTH,
2434
+ height: MAX_HEIGHT
2356
2435
  };
2357
2436
  }
2358
- };
2359
- tn = lr([
2360
- sn(cn.Rendered, tn),
2361
- Ve(0, $),
2362
- Ve(1, ne),
2363
- Ve(2, he),
2364
- Ve(3, se),
2365
- Ve(4, Ue)
2366
- ], tn);
2367
- var ut = Object.defineProperty, mr = Object.getOwnPropertyDescriptor, gr = (i, e, n) => e in i ? ut(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, ur = (i, e, n, t) => {
2368
- for (var r = t > 1 ? void 0 : t ? mr(e, n) : e, o = i.length - 1, a; o >= 0; o--)
2369
- (a = i[o]) && (r = (t ? a(e, n, r) : a(r)) || r);
2370
- return t && r && ut(e, n, r), r;
2371
- }, Bn = (i, e) => (n, t) => e(n, t, i), ft = (i, e, n) => gr(i, typeof e != "symbol" ? e + "" : e, n);
2372
- const fr = "DOCS_DRAWING_UI_PLUGIN";
2373
- let on = class extends Ot {
2374
- constructor(i, e, n) {
2375
- super(), this._injector = e, this._renderManagerSrv = n;
2376
- }
2377
- onStarting(i) {
2437
+ }, __name(_a6, "DocDrawingTransformerController"), _a6);
2438
+ DocDrawingTransformerController = __decorateClass$1([
2439
+ OnLifecycle(LifecycleStages.Rendered, DocDrawingTransformerController),
2440
+ __decorateParam$1(0, ICommandService),
2441
+ __decorateParam$1(1, IUniverInstanceService),
2442
+ __decorateParam$1(2, IDrawingManagerService),
2443
+ __decorateParam$1(3, IRenderManagerService),
2444
+ __decorateParam$1(4, ITextSelectionRenderManager)
2445
+ ], DocDrawingTransformerController);
2446
+ 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) => {
2447
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2448
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2449
+ return kind && result && __defProp2(target, key, result), result;
2450
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField");
2451
+ const PLUGIN_NAME = "DOCS_DRAWING_UI_PLUGIN";
2452
+ var _a7;
2453
+ let UniverDocsDrawingUIPlugin = (_a7 = class extends Plugin {
2454
+ constructor(_config, _injector, _renderManagerSrv) {
2455
+ super(), this._injector = _injector, this._renderManagerSrv = _renderManagerSrv;
2456
+ }
2457
+ onStarting() {
2378
2458
  [
2379
- [en],
2380
- [Je],
2381
- [tn],
2382
- [nn],
2383
- [ln]
2384
- ].forEach((n) => i.add(n));
2459
+ [DocDrawingUIController],
2460
+ [DocDrawingPopupMenuController],
2461
+ [DocDrawingTransformerController],
2462
+ [DocDrawingAddRemoveController],
2463
+ [DocRefreshDrawingsService]
2464
+ ].forEach((dependency) => this._injector.add(dependency));
2385
2465
  }
2386
2466
  onReady() {
2387
2467
  [
2388
- [fn],
2389
- [pn]
2390
- ].forEach((i) => this._renderManagerSrv.registerRenderModule(be.UNIVER_DOC, i));
2391
- }
2392
- };
2393
- ft(on, "type", be.UNIVER_DOC);
2394
- ft(on, "pluginName", fr);
2395
- on = ur([
2396
- Tt(At, Ht, Wt),
2397
- Bn(1, pe(Hn)),
2398
- Bn(2, se)
2399
- ], on);
2468
+ [DocDrawingUpdateRenderController],
2469
+ [DocDrawingTransformUpdateController]
2470
+ ].forEach((m) => this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, m));
2471
+ }
2472
+ }, __name(_a7, "UniverDocsDrawingUIPlugin"), _a7);
2473
+ __publicField2(UniverDocsDrawingUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
2474
+ __publicField2(UniverDocsDrawingUIPlugin, "pluginName", PLUGIN_NAME);
2475
+ UniverDocsDrawingUIPlugin = __decorateClass([
2476
+ DependentOn(UniverDrawingUIPlugin, UniverDrawingPlugin, UniverDocsDrawingPlugin),
2477
+ __decorateParam(1, Inject(Injector)),
2478
+ __decorateParam(2, IRenderManagerService)
2479
+ ], UniverDocsDrawingUIPlugin);
2400
2480
  export {
2401
- Wi as ClearDocDrawingTransformerOperation,
2402
- ct as DeleteDocDrawingsCommand,
2403
- Kn as EditDocDrawingOperation,
2404
- mt as GroupDocDrawingCommand,
2405
- gt as InsertDocDrawingCommand,
2406
- In as InsertDocImageOperation,
2407
- Xe as MoveDocDrawingsCommand,
2408
- vn as RemoveDocDrawingCommand,
2409
- lt as SetDocDrawingArrangeCommand,
2410
- Xn as SidebarDocDrawingOperation,
2411
- dt as UngroupDocDrawingCommand,
2412
- on as UniverDocsDrawingUIPlugin
2481
+ COMPONENT_DOC_UPLOAD_FILE_MENU,
2482
+ ClearDocDrawingTransformerOperation,
2483
+ DeleteDocDrawingsCommand,
2484
+ EditDocDrawingOperation,
2485
+ GroupDocDrawingCommand,
2486
+ IMAGE_MENU_ID,
2487
+ InsertDocDrawingCommand,
2488
+ InsertDocImageOperation,
2489
+ MoveDocDrawingsCommand,
2490
+ RemoveDocDrawingCommand,
2491
+ SetDocDrawingArrangeCommand,
2492
+ SidebarDocDrawingOperation,
2493
+ UngroupDocDrawingCommand,
2494
+ UniverDocsDrawingUIPlugin
2413
2495
  };