@univerjs/docs-drawing-ui 0.2.11 → 0.2.13
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/cjs/index.js +1 -1
- package/lib/es/index.js +484 -508
- package/lib/index.css +1 -1
- package/lib/types/commands/commands/insert-image.command.d.ts +5 -0
- package/lib/types/{views/upload-component/component-name.d.ts → controllers/config.schema.d.ts} +5 -1
- package/lib/types/controllers/doc-drawing-transformer-update.controller.d.ts +2 -3
- package/lib/types/controllers/doc-drawing.controller.d.ts +4 -5
- package/lib/types/controllers/menu.schema.d.ts +2 -0
- package/lib/types/controllers/render-controllers/doc-drawing-transform-update.controller.d.ts +2 -2
- package/lib/types/controllers/render-controllers/doc-drawing-update.render-controller.d.ts +11 -14
- package/lib/types/index.d.ts +1 -2
- package/lib/types/plugin.d.ts +5 -2
- package/lib/types/views/doc-image-panel/DocDrawingPosition.d.ts +1 -1
- package/lib/types/views/menu/image.menu.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +24 -25
- package/lib/types/commands/operations/insert-image.operation.d.ts +0 -8
- package/lib/types/views/upload-component/UploadFile.d.ts +0 -2
package/lib/es/index.js
CHANGED
|
@@ -2,28 +2,28 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import { CommandType, ICommandService, IUniverInstanceService, TextX, JSONX, MemoryCursor, TextXActionType, LocaleService, RxDisposable, UniverInstanceType, toDisposable, FOCUSING_COMMON_DRAWINGS, OnLifecycle, LifecycleStages, Inject, IContextService,
|
|
5
|
+
import { CommandType, ICommandService, IUniverInstanceService, TextX, JSONX, MemoryCursor, TextXActionType, LocaleService, RxDisposable, UniverInstanceType, toDisposable, FOCUSING_COMMON_DRAWINGS, OnLifecycle, LifecycleStages, Inject, IContextService, IUndoRedoService, BuildTextUtils, Tools, Disposable, BooleanNumber, PositionedObjectLayoutType, WrapTextType, ObjectRelativeFromH, ObjectRelativeFromV, useDependency, Direction, FOCUSING_UNIVER_EDITOR, fromEventSubject, LifecycleService, UndoCommand, RedoCommand, throttle, COLORS, Plugin, DependentOn, Injector, IConfigService } from "@univerjs/core";
|
|
6
6
|
import { ImageCropperObject, COMPONENT_IMAGE_POPUP_MENU, OpenImageCropOperation, ImageResetSizeOperation, DrawingCommonPanel, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
|
|
7
|
-
import { IDrawingManagerService,
|
|
7
|
+
import { IDrawingManagerService, ArrangeTypeEnum, DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, ImageUploadStatusType, DRAWING_IMAGE_ALLOW_SIZE, getImageSize, DrawingTypeEnum, getDrawingShapeKeyByDrawingSearch, DRAWING_IMAGE_WIDTH_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, IImageIoService, UniverDrawingPlugin } from "@univerjs/drawing";
|
|
8
8
|
import { IDocDrawingService, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
|
|
9
|
-
import {
|
|
10
|
-
import { takeUntil,
|
|
11
|
-
import { DocCanvasPopManagerService, docDrawingPositionToTransform } from "@univerjs/docs-ui";
|
|
12
|
-
import { RichTextEditingMutation,
|
|
13
|
-
import { ISidebarService,
|
|
9
|
+
import { IRenderManagerService, DocumentEditArea, Liquid, TRANSFORM_CHANGE_OBSERVABLE_TYPE, PageLayoutType, DocumentSkeletonPageType, Vector2, Rect, getColor } from "@univerjs/engine-render";
|
|
10
|
+
import { takeUntil, BehaviorSubject, Observable, filter, debounceTime } from "rxjs";
|
|
11
|
+
import { DocSelectionRenderService, getRichTextEditPath, DocCanvasPopManagerService, getCustomBlockIdsInSelections, docDrawingPositionToTransform, SetDocZoomRatioOperation, NodePositionConvertToCursor, getOneTextSelectionRange, getAnchorBounding, TEXT_RANGE_LAYER_INDEX, getDocObject } from "@univerjs/docs-ui";
|
|
12
|
+
import { RichTextEditingMutation, DocSelectionManagerService, DocSkeletonManagerService } from "@univerjs/docs";
|
|
13
|
+
import { ISidebarService, IMessageService, ILocalFileService, MenuItemType, getMenuHiddenObservable, KeyCode, RibbonStartGroup, ComponentManager, IMenuManagerService, IShortcutService, IEditorService } from "@univerjs/ui";
|
|
14
|
+
import { MessageType, RadioGroup, Radio, InputNumber, Select, Checkbox } from "@univerjs/design";
|
|
14
15
|
import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
|
|
15
16
|
import clsx from "clsx";
|
|
16
|
-
import { RadioGroup, Radio, InputNumber, Select, Checkbox, MessageType } from "@univerjs/design";
|
|
17
17
|
const RemoveDocDrawingCommand = {
|
|
18
18
|
id: "doc.command.remove-doc-image",
|
|
19
19
|
type: CommandType.COMMAND,
|
|
20
20
|
// eslint-disable-next-line max-lines-per-function
|
|
21
21
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
22
22
|
var _a8, _b, _c, _d;
|
|
23
|
-
const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService),
|
|
23
|
+
const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
24
24
|
if (params == null || documentDataModel == null)
|
|
25
25
|
return !1;
|
|
26
|
-
const { drawings: removeDrawings } = params, segmentId = (_a8 =
|
|
26
|
+
const docSelectionRenderService = renderManagerService.getRenderById(params.unitId).with(DocSelectionRenderService), { drawings: removeDrawings } = params, segmentId = (_a8 = docSelectionRenderService.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
27
|
memoryCursor.reset();
|
|
28
28
|
const cursorIndex = removeCustomBlocks[0].startIndex, textRanges = [
|
|
29
29
|
{
|
|
@@ -145,15 +145,19 @@ let DocDrawingPopupMenuController = (_a = class extends RxDisposable {
|
|
|
145
145
|
const oKey = object.oKey, drawingParam = this._drawingManagerService.getDrawingOKey(oKey);
|
|
146
146
|
if (!drawingParam)
|
|
147
147
|
return;
|
|
148
|
-
const { unitId: unitId2, subUnitId, drawingId } = drawingParam
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
const { unitId: unitId2, subUnitId, drawingId } = drawingParam, popup = this._canvasPopManagerService.attachPopupToObject(
|
|
149
|
+
object,
|
|
150
|
+
{
|
|
151
|
+
componentKey: COMPONENT_IMAGE_POPUP_MENU,
|
|
152
|
+
direction: "horizontal",
|
|
153
|
+
offset: [2, 0],
|
|
154
|
+
extraProps: {
|
|
155
|
+
menuItems: this._getImageMenuItems(unitId2, subUnitId, drawingId)
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
unitId2
|
|
159
|
+
);
|
|
160
|
+
disposePopups.push(this.disposeWithMe(popup)), !this._drawingManagerService.getFocusDrawings().find((drawing) => drawing.unitId === unitId2 && drawing.subUnitId === subUnitId && drawing.drawingId === drawingId) && this._drawingManagerService.focusDrawing([{
|
|
157
161
|
unitId: unitId2,
|
|
158
162
|
subUnitId,
|
|
159
163
|
drawingId
|
|
@@ -278,41 +282,368 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width:
|
|
|
278
282
|
}));
|
|
279
283
|
});
|
|
280
284
|
AddImageSingle.displayName = "AddImageSingle";
|
|
281
|
-
const
|
|
282
|
-
id: "doc.
|
|
283
|
-
type: CommandType.
|
|
284
|
-
handler: /* @__PURE__ */ __name(() =>
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
285
|
+
const GroupDocDrawingCommand = {
|
|
286
|
+
id: "doc.command.group-doc-image",
|
|
287
|
+
type: CommandType.COMMAND,
|
|
288
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
289
|
+
accessor.get(ICommandService), accessor.get(IUndoRedoService);
|
|
290
|
+
const docDrawingService = accessor.get(IDocDrawingService);
|
|
291
|
+
if (!params) return !1;
|
|
292
|
+
const unitIds = [];
|
|
293
|
+
return params.forEach(({ parent, children }) => {
|
|
294
|
+
unitIds.push(parent.unitId), children.forEach((child) => {
|
|
295
|
+
unitIds.push(child.unitId);
|
|
296
|
+
});
|
|
297
|
+
}), docDrawingService.getGroupDrawingOp(params), !1;
|
|
298
|
+
}, "handler")
|
|
299
|
+
}, InsertDocDrawingCommand = {
|
|
300
|
+
id: "doc.command.insert-doc-image",
|
|
301
|
+
type: CommandType.COMMAND,
|
|
302
|
+
// eslint-disable-next-line max-lines-per-function
|
|
303
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
304
|
+
var _a8, _b, _c, _d;
|
|
305
|
+
if (params == null)
|
|
306
|
+
return !1;
|
|
307
|
+
const commandService = accessor.get(ICommandService), docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeTextRange = docSelectionManagerService.getActiveTextRange(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
308
|
+
if (activeTextRange == null || documentDataModel == null)
|
|
309
|
+
return !1;
|
|
310
|
+
const unitId = documentDataModel.getUnitId(), { drawings } = params, { collapsed, startOffset, segmentId } = activeTextRange, body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
311
|
+
if (body == null)
|
|
312
|
+
return !1;
|
|
313
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], drawingOrderLength = (_b = (_a8 = documentDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _a8.length) != null ? _b : 0;
|
|
314
|
+
let removeDrawingLen = 0;
|
|
315
|
+
if (collapsed)
|
|
316
|
+
startOffset > 0 && textX.push({
|
|
317
|
+
t: TextXActionType.RETAIN,
|
|
318
|
+
len: startOffset,
|
|
319
|
+
segmentId
|
|
320
|
+
});
|
|
321
|
+
else {
|
|
322
|
+
const { dos } = BuildTextUtils.selection.getDeleteActions(activeTextRange, segmentId, 0, body);
|
|
323
|
+
textX.push(...dos);
|
|
324
|
+
const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [activeTextRange]), drawings2 = (_c = documentDataModel.getDrawings()) != null ? _c : {}, drawingOrder = (_d = documentDataModel.getDrawingsOrder()) != null ? _d : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
|
|
325
|
+
if (sortedRemovedCustomBlockIds.length > 0)
|
|
326
|
+
for (const blockId of sortedRemovedCustomBlockIds) {
|
|
327
|
+
const drawing = drawings2[blockId], drawingIndex = drawingOrder.indexOf(blockId);
|
|
328
|
+
if (drawing == null || drawingIndex < 0)
|
|
329
|
+
continue;
|
|
330
|
+
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
331
|
+
rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction), removeDrawingLen++;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
textX.push({
|
|
335
|
+
t: TextXActionType.INSERT,
|
|
336
|
+
body: {
|
|
337
|
+
dataStream: "\b".repeat(drawings.length),
|
|
338
|
+
customBlocks: drawings.map((drawing, i) => ({
|
|
339
|
+
startIndex: i,
|
|
340
|
+
blockId: drawing.drawingId
|
|
341
|
+
}))
|
|
342
|
+
},
|
|
343
|
+
len: drawings.length,
|
|
344
|
+
line: 0,
|
|
345
|
+
segmentId
|
|
346
|
+
});
|
|
347
|
+
const path = getRichTextEditPath(documentDataModel, segmentId), placeHolderAction = jsonX.editOp(textX.serialize(), path);
|
|
348
|
+
rawActions.push(placeHolderAction);
|
|
349
|
+
for (const drawing of drawings) {
|
|
350
|
+
const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
|
|
351
|
+
rawActions.push(addDrawingAction), rawActions.push(addDrawingOrderAction);
|
|
352
|
+
}
|
|
353
|
+
const doMutation = {
|
|
354
|
+
id: RichTextEditingMutation.id,
|
|
355
|
+
params: {
|
|
356
|
+
unitId,
|
|
357
|
+
actions: [],
|
|
358
|
+
textRanges: []
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
362
|
+
}, "handler")
|
|
363
|
+
}, SetDocDrawingArrangeCommand = {
|
|
364
|
+
id: "doc.command.set-drawing-arrange",
|
|
365
|
+
type: CommandType.COMMAND,
|
|
366
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
367
|
+
const commandService = accessor.get(ICommandService), docDrawingService = accessor.get(IDocDrawingService);
|
|
368
|
+
if (params == null)
|
|
369
|
+
return !1;
|
|
370
|
+
const { unitId, subUnitId, drawingIds, arrangeType } = params, drawingOrderMapParam = { unitId, subUnitId, drawingIds };
|
|
371
|
+
let jsonOp;
|
|
372
|
+
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)
|
|
373
|
+
return !1;
|
|
374
|
+
const { redo } = jsonOp;
|
|
375
|
+
if (redo == null)
|
|
376
|
+
return !1;
|
|
377
|
+
const rawActions = [];
|
|
378
|
+
let redoCopy = Tools.deepClone(redo);
|
|
379
|
+
redoCopy = redoCopy.slice(3), redoCopy.unshift("drawingsOrder"), rawActions.push(redoCopy);
|
|
380
|
+
const doMutation = {
|
|
381
|
+
id: RichTextEditingMutation.id,
|
|
382
|
+
params: {
|
|
383
|
+
unitId,
|
|
384
|
+
actions: [],
|
|
385
|
+
textRanges: null
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
389
|
+
}, "handler")
|
|
390
|
+
}, UngroupDocDrawingCommand = {
|
|
391
|
+
id: "doc.command.ungroup-doc-image",
|
|
392
|
+
type: CommandType.COMMAND,
|
|
393
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
394
|
+
accessor.get(ICommandService), accessor.get(IUndoRedoService);
|
|
395
|
+
const docDrawingService = accessor.get(IDocDrawingService);
|
|
396
|
+
if (!params) return !1;
|
|
397
|
+
const unitIds = [];
|
|
398
|
+
return params.forEach(({ parent, children }) => {
|
|
399
|
+
unitIds.push(parent.unitId), children.forEach((child) => {
|
|
400
|
+
unitIds.push(child.unitId);
|
|
401
|
+
});
|
|
402
|
+
}), docDrawingService.getUngroupDrawingOp(params), !1;
|
|
403
|
+
}, "handler")
|
|
404
|
+
}, _DocRefreshDrawingsService = class _DocRefreshDrawingsService {
|
|
405
|
+
constructor() {
|
|
406
|
+
__publicField(this, "_refreshDrawings$", new BehaviorSubject(null));
|
|
407
|
+
__publicField(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
|
|
408
|
+
}
|
|
409
|
+
refreshDrawings(skeleton) {
|
|
410
|
+
this._refreshDrawings$.next(skeleton);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
__name(_DocRefreshDrawingsService, "DocRefreshDrawingsService");
|
|
414
|
+
let DocRefreshDrawingsService = _DocRefreshDrawingsService;
|
|
415
|
+
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
416
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
417
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
418
|
+
return kind && result && __defProp$5(target, key, result), result;
|
|
419
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a2;
|
|
420
|
+
let DocDrawingUpdateRenderController = (_a2 = class extends Disposable {
|
|
421
|
+
constructor(_context, _commandService, _docSelectionManagerService, _renderManagerSrv, _imageIoService, _docDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, _docSelectionRenderService, _docRefreshDrawingsService, _fileOpenerService) {
|
|
422
|
+
super(), this._context = _context, this._commandService = _commandService, this._docSelectionManagerService = _docSelectionManagerService, this._renderManagerSrv = _renderManagerSrv, this._imageIoService = _imageIoService, this._docDrawingService = _docDrawingService, this._drawingManagerService = _drawingManagerService, this._contextService = _contextService, this._messageService = _messageService, this._localeService = _localeService, this._docSelectionRenderService = _docSelectionRenderService, this._docRefreshDrawingsService = _docRefreshDrawingsService, this._fileOpenerService = _fileOpenerService, this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._editAreaChangeListener();
|
|
423
|
+
}
|
|
424
|
+
async insertDocImage() {
|
|
425
|
+
const files = await this._fileOpenerService.openFile({
|
|
426
|
+
multiple: !0,
|
|
427
|
+
accept: DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
|
|
428
|
+
}), fileLength = files.length;
|
|
429
|
+
return fileLength > DRAWING_IMAGE_COUNT_LIMIT ? (this._messageService.show({
|
|
430
|
+
type: MessageType.Error,
|
|
431
|
+
content: this._localeService.t("update-status.exceedMaxCount", String(DRAWING_IMAGE_COUNT_LIMIT))
|
|
432
|
+
}), !1) : fileLength === 0 ? !1 : (await this._insertFloatImages(files), !0);
|
|
433
|
+
}
|
|
434
|
+
// eslint-disable-next-line max-lines-per-function
|
|
435
|
+
async _insertFloatImages(files) {
|
|
436
|
+
let imageParams = [];
|
|
437
|
+
try {
|
|
438
|
+
imageParams = await Promise.all(files.map((file) => this._imageIoService.saveImage(file)));
|
|
439
|
+
} catch (error) {
|
|
440
|
+
const type = error.message;
|
|
441
|
+
let content = "";
|
|
442
|
+
switch (type) {
|
|
443
|
+
case ImageUploadStatusType.ERROR_EXCEED_SIZE:
|
|
444
|
+
content = this._localeService.t("update-status.exceedMaxSize", String(DRAWING_IMAGE_ALLOW_SIZE / (1024 * 1024)));
|
|
445
|
+
break;
|
|
446
|
+
case ImageUploadStatusType.ERROR_IMAGE_TYPE:
|
|
447
|
+
content = this._localeService.t("update-status.invalidImageType");
|
|
448
|
+
break;
|
|
449
|
+
case ImageUploadStatusType.ERROR_IMAGE:
|
|
450
|
+
content = this._localeService.t("update-status.invalidImage");
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
this._messageService.show({
|
|
454
|
+
type: MessageType.Error,
|
|
455
|
+
content
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
if (imageParams.length === 0)
|
|
459
|
+
return;
|
|
460
|
+
const { unitId } = this._context, docDrawingParams = [];
|
|
461
|
+
for (const imageParam of imageParams) {
|
|
462
|
+
if (imageParam == null)
|
|
463
|
+
continue;
|
|
464
|
+
const { imageId, imageSourceType, source, base64Cache } = imageParam, { width, height, image } = await getImageSize(base64Cache || "");
|
|
465
|
+
this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);
|
|
466
|
+
let scale = 1;
|
|
467
|
+
if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
|
|
468
|
+
const scaleWidth = DRAWING_IMAGE_WIDTH_LIMIT / width, scaleHeight = DRAWING_IMAGE_HEIGHT_LIMIT / height;
|
|
469
|
+
scale = Math.min(scaleWidth, scaleHeight);
|
|
470
|
+
}
|
|
471
|
+
const docTransform = this._getImagePosition(width * scale, height * scale);
|
|
472
|
+
if (docTransform == null)
|
|
473
|
+
return;
|
|
474
|
+
const docDrawingParam = {
|
|
475
|
+
unitId,
|
|
476
|
+
subUnitId: unitId,
|
|
477
|
+
drawingId: imageId,
|
|
478
|
+
drawingType: DrawingTypeEnum.DRAWING_IMAGE,
|
|
479
|
+
imageSourceType,
|
|
480
|
+
source,
|
|
481
|
+
transform: docDrawingPositionToTransform(docTransform),
|
|
482
|
+
docTransform,
|
|
483
|
+
behindDoc: BooleanNumber.FALSE,
|
|
484
|
+
title: "",
|
|
485
|
+
description: "",
|
|
486
|
+
layoutType: PositionedObjectLayoutType.INLINE,
|
|
487
|
+
// Insert inline drawing by default.
|
|
488
|
+
wrapText: WrapTextType.BOTH_SIDES,
|
|
489
|
+
distB: 0,
|
|
490
|
+
distL: 0,
|
|
491
|
+
distR: 0,
|
|
492
|
+
distT: 0
|
|
493
|
+
};
|
|
494
|
+
this._isInsertInHeaderFooter() && (docDrawingParam.isMultiTransform = BooleanNumber.TRUE, docDrawingParam.transforms = docDrawingParam.transform ? [docDrawingParam.transform] : null), docDrawingParams.push(docDrawingParam);
|
|
495
|
+
}
|
|
496
|
+
this._commandService.executeCommand(InsertDocDrawingCommand.id, {
|
|
497
|
+
unitId,
|
|
498
|
+
drawings: docDrawingParams
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
_isInsertInHeaderFooter() {
|
|
290
502
|
var _a8;
|
|
291
|
-
(_a8 =
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
503
|
+
const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel(), editArea = viewModel == null ? void 0 : viewModel.getEditArea();
|
|
504
|
+
return editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER;
|
|
505
|
+
}
|
|
506
|
+
_getImagePosition(imageWidth, imageHeight) {
|
|
507
|
+
const activeTextRange = this._docSelectionRenderService.getActiveTextRange(), position = (activeTextRange == null ? void 0 : activeTextRange.getAbsolutePosition()) || {
|
|
508
|
+
left: 0,
|
|
509
|
+
top: 0
|
|
510
|
+
};
|
|
511
|
+
return {
|
|
512
|
+
size: {
|
|
513
|
+
width: imageWidth,
|
|
514
|
+
height: imageHeight
|
|
515
|
+
},
|
|
516
|
+
positionH: {
|
|
517
|
+
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
518
|
+
posOffset: position.left
|
|
519
|
+
},
|
|
520
|
+
positionV: {
|
|
521
|
+
relativeFrom: ObjectRelativeFromV.MARGIN,
|
|
522
|
+
posOffset: position.top
|
|
523
|
+
},
|
|
524
|
+
angle: 0
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
_updateOrderListener() {
|
|
528
|
+
this._drawingManagerService.featurePluginOrderUpdate$.subscribe((params) => {
|
|
529
|
+
const { unitId, subUnitId, drawingIds, arrangeType } = params;
|
|
530
|
+
this._commandService.executeCommand(SetDocDrawingArrangeCommand.id, {
|
|
531
|
+
unitId,
|
|
532
|
+
subUnitId,
|
|
533
|
+
drawingIds,
|
|
534
|
+
arrangeType
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
_groupDrawingListener() {
|
|
539
|
+
this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
|
|
540
|
+
this._commandService.executeCommand(GroupDocDrawingCommand.id, params);
|
|
541
|
+
}), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((params) => {
|
|
542
|
+
this._commandService.executeCommand(UngroupDocDrawingCommand.id, params);
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
_getCurrentSceneAndTransformer() {
|
|
546
|
+
const { scene, mainComponent } = this._context;
|
|
547
|
+
if (scene == null || mainComponent == null)
|
|
295
548
|
return;
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
549
|
+
const transformer = scene.getTransformerByCreate(), { docsLeft, docsTop } = mainComponent.getOffsetConfig();
|
|
550
|
+
return { scene, transformer, docsLeft, docsTop };
|
|
551
|
+
}
|
|
552
|
+
_focusDrawingListener() {
|
|
553
|
+
this.disposeWithMe(
|
|
554
|
+
this._drawingManagerService.focus$.subscribe((params) => {
|
|
555
|
+
var _a8;
|
|
556
|
+
const { transformer, docsLeft, docsTop } = (_a8 = this._getCurrentSceneAndTransformer()) != null ? _a8 : {};
|
|
557
|
+
if (params == null || params.length === 0)
|
|
558
|
+
this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !1), this._docDrawingService.focusDrawing([]), transformer && transformer.resetProps({
|
|
559
|
+
zeroTop: 0,
|
|
560
|
+
zeroLeft: 0
|
|
561
|
+
});
|
|
562
|
+
else {
|
|
563
|
+
this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !0), this._docDrawingService.focusDrawing(params), this._docSelectionManagerService.getActiveTextRange() && this._docSelectionManagerService.replaceTextRanges([]);
|
|
564
|
+
const prevSegmentId = this._docSelectionRenderService.getSegment(), segmentId = this._findSegmentIdByDrawingId(params[0].drawingId);
|
|
565
|
+
prevSegmentId !== segmentId && this._docSelectionRenderService.setSegment(segmentId), transformer && transformer.resetProps({
|
|
566
|
+
zeroTop: docsTop,
|
|
567
|
+
zeroLeft: docsLeft
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
})
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
_findSegmentIdByDrawingId(drawingId) {
|
|
574
|
+
var _a8, _b, _c;
|
|
575
|
+
const { unit: DocDataModel } = this._context, { body, headers = {}, footers = {} } = DocDataModel.getSnapshot();
|
|
576
|
+
if (((_a8 = body == null ? void 0 : body.customBlocks) != null ? _a8 : []).some((b) => b.blockId === drawingId))
|
|
577
|
+
return "";
|
|
578
|
+
for (const headerId of Object.keys(headers))
|
|
579
|
+
if ((_b = headers[headerId].body.customBlocks) != null && _b.some((b) => b.blockId === drawingId))
|
|
580
|
+
return headerId;
|
|
581
|
+
for (const footerId of Object.keys(footers))
|
|
582
|
+
if ((_c = footers[footerId].body.customBlocks) != null && _c.some((b) => b.blockId === drawingId))
|
|
583
|
+
return footerId;
|
|
584
|
+
return "";
|
|
585
|
+
}
|
|
586
|
+
// Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
|
|
587
|
+
_updateDrawingsEditStatus() {
|
|
588
|
+
var _a8;
|
|
589
|
+
const { unit: docDataModel, scene, unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
|
|
590
|
+
if (viewModel == null || docDataModel == null)
|
|
591
|
+
return;
|
|
592
|
+
const snapshot = docDataModel.getSnapshot(), { drawings = {} } = snapshot, isEditBody = viewModel.getEditArea() === DocumentEditArea.BODY;
|
|
593
|
+
for (const key of Object.keys(drawings)) {
|
|
594
|
+
const drawing = drawings[key], objectKey = getDrawingShapeKeyByDrawingSearch({ unitId, drawingId: drawing.drawingId, subUnitId: unitId }), drawingShapes = scene.fuzzyMathObjects(objectKey, !0);
|
|
595
|
+
if (drawingShapes.length)
|
|
596
|
+
for (const shape of drawingShapes)
|
|
597
|
+
scene.detachTransformerFrom(shape), shape.setOpacity(0.5), (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) && (scene.attachTransformerTo(shape), shape.setOpacity(1));
|
|
308
598
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
599
|
+
}
|
|
600
|
+
_editAreaChangeListener() {
|
|
601
|
+
var _a8;
|
|
602
|
+
const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
|
|
603
|
+
viewModel != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
|
|
604
|
+
viewModel.editAreaChange$.subscribe(() => {
|
|
605
|
+
this._updateDrawingsEditStatus();
|
|
606
|
+
})
|
|
607
|
+
), this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
|
|
608
|
+
skeleton != null && queueMicrotask(() => {
|
|
609
|
+
this._updateDrawingsEditStatus();
|
|
610
|
+
});
|
|
611
|
+
}), this.disposeWithMe(
|
|
612
|
+
this._commandService.onCommandExecuted(async (command) => {
|
|
613
|
+
command.id === RichTextEditingMutation.id && queueMicrotask(() => {
|
|
614
|
+
this._updateDrawingsEditStatus();
|
|
615
|
+
});
|
|
616
|
+
})
|
|
617
|
+
));
|
|
618
|
+
}
|
|
619
|
+
}, __name(_a2, "DocDrawingUpdateRenderController"), _a2);
|
|
620
|
+
DocDrawingUpdateRenderController = __decorateClass$5([
|
|
621
|
+
__decorateParam$5(1, ICommandService),
|
|
622
|
+
__decorateParam$5(2, Inject(DocSelectionManagerService)),
|
|
623
|
+
__decorateParam$5(3, IRenderManagerService),
|
|
624
|
+
__decorateParam$5(4, IImageIoService),
|
|
625
|
+
__decorateParam$5(5, IDocDrawingService),
|
|
626
|
+
__decorateParam$5(6, IDrawingManagerService),
|
|
627
|
+
__decorateParam$5(7, IContextService),
|
|
628
|
+
__decorateParam$5(8, IMessageService),
|
|
629
|
+
__decorateParam$5(9, Inject(LocaleService)),
|
|
630
|
+
__decorateParam$5(10, Inject(DocSelectionRenderService)),
|
|
631
|
+
__decorateParam$5(11, Inject(DocRefreshDrawingsService)),
|
|
632
|
+
__decorateParam$5(12, ILocalFileService)
|
|
633
|
+
], DocDrawingUpdateRenderController);
|
|
634
|
+
const InsertDocImageCommand = {
|
|
635
|
+
id: "doc.command.insert-float-image",
|
|
636
|
+
type: CommandType.COMMAND,
|
|
637
|
+
handler: /* @__PURE__ */ __name((accessor) => {
|
|
638
|
+
var _a8, _b;
|
|
639
|
+
return (_b = (_a8 = accessor.get(IRenderManagerService).getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a8.with(DocDrawingUpdateRenderController).insertDocImage()) != null ? _b : !1;
|
|
640
|
+
}, "handler")
|
|
641
|
+
}, ImageUploadIcon = "addition-and-subtraction-single", IMAGE_MENU_ID = "doc.menu.image", IMAGE_MENU_UPLOAD_FLOAT_ID = InsertDocImageCommand.id, getDisableWhenSelectionInTableObservable = /* @__PURE__ */ __name((accessor) => {
|
|
642
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
|
|
312
643
|
return new Observable((subscriber) => {
|
|
313
|
-
const observable =
|
|
644
|
+
const observable = docSelectionManagerService.textSelection$.subscribe(() => {
|
|
314
645
|
var _a8;
|
|
315
|
-
const activeRange =
|
|
646
|
+
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
316
647
|
if (activeRange) {
|
|
317
648
|
const { segmentId, startOffset, endOffset } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), tables = (_a8 = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a8.tables;
|
|
318
649
|
if (tables && tables.length && tables.some((table) => {
|
|
@@ -335,8 +666,6 @@ function ImageMenuFactory(accessor) {
|
|
|
335
666
|
return {
|
|
336
667
|
id: IMAGE_MENU_ID,
|
|
337
668
|
type: MenuItemType.SUBITEMS,
|
|
338
|
-
positions: [MenuPosition.TOOLBAR_START],
|
|
339
|
-
group: MenuGroup.TOOLBAR_LAYOUT,
|
|
340
669
|
icon: ImageUploadIcon,
|
|
341
670
|
tooltip: "docImage.title",
|
|
342
671
|
disabled$: getDisableWhenSelectionInTableObservable(accessor),
|
|
@@ -348,11 +677,7 @@ function UploadFloatImageMenuFactory(_accessor) {
|
|
|
348
677
|
return {
|
|
349
678
|
id: IMAGE_MENU_UPLOAD_FLOAT_ID,
|
|
350
679
|
title: "docImage.upload.float",
|
|
351
|
-
type: MenuItemType.
|
|
352
|
-
label: {
|
|
353
|
-
name: COMPONENT_DOC_UPLOAD_FILE_MENU
|
|
354
|
-
},
|
|
355
|
-
positions: [IMAGE_MENU_ID],
|
|
680
|
+
type: MenuItemType.BUTTON,
|
|
356
681
|
hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC)
|
|
357
682
|
};
|
|
358
683
|
}
|
|
@@ -373,17 +698,7 @@ const imageCommonPanel = "univer-image-common-panel", imageCommonPanelGrid = "un
|
|
|
373
698
|
imageCommonPanelInput,
|
|
374
699
|
sheetImageMenu,
|
|
375
700
|
sheetImageMenuInput
|
|
376
|
-
}, _DocRefreshDrawingsService = class _DocRefreshDrawingsService {
|
|
377
|
-
constructor() {
|
|
378
|
-
__publicField(this, "_refreshDrawings$", new BehaviorSubject(null));
|
|
379
|
-
__publicField(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
|
|
380
|
-
}
|
|
381
|
-
refreshDrawings(skeleton) {
|
|
382
|
-
this._refreshDrawings$.next(skeleton);
|
|
383
|
-
}
|
|
384
701
|
};
|
|
385
|
-
__name(_DocRefreshDrawingsService, "DocRefreshDrawingsService");
|
|
386
|
-
let DocRefreshDrawingsService = _DocRefreshDrawingsService;
|
|
387
702
|
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
703
|
const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
|
|
389
704
|
inline: PositionedObjectLayoutType.INLINE,
|
|
@@ -392,7 +707,7 @@ const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
|
|
|
392
707
|
inFrontOfText: PositionedObjectLayoutType.WRAP_NONE,
|
|
393
708
|
behindText: PositionedObjectLayoutType.WRAP_NONE
|
|
394
709
|
};
|
|
395
|
-
function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel,
|
|
710
|
+
function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPage, offset, drawingId, documentDataModel, docSelectionRenderManager) {
|
|
396
711
|
var _a8, _b;
|
|
397
712
|
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], oldBody = documentDataModel.getSelfOrHeaderFooterModel(oldSegmentId).getBody(), body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
398
713
|
if (oldBody == null || body == null)
|
|
@@ -482,7 +797,7 @@ function getDeleteAndInsertCustomBlockActions(segmentId, oldSegmentId, segmentPa
|
|
|
482
797
|
len: 1,
|
|
483
798
|
line: 0,
|
|
484
799
|
segmentId
|
|
485
|
-
}), path = getRichTextEditPath(documentDataModel, segmentId), action = jsonX.editOp(textX.serialize(), path), rawActions.push(action),
|
|
800
|
+
}), path = getRichTextEditPath(documentDataModel, segmentId), action = jsonX.editOp(textX.serialize(), path), rawActions.push(action), docSelectionRenderManager.setSegment(segmentId), docSelectionRenderManager.setSegmentPage(segmentPage);
|
|
486
801
|
}
|
|
487
802
|
return rawActions;
|
|
488
803
|
}
|
|
@@ -668,11 +983,11 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
668
983
|
id: "doc.command.move-inline-drawing",
|
|
669
984
|
type: CommandType.COMMAND,
|
|
670
985
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
671
|
-
var _a8;
|
|
986
|
+
var _a8, _b;
|
|
672
987
|
if (params == null)
|
|
673
988
|
return !1;
|
|
674
|
-
const renderManagerService = accessor.get(IRenderManagerService),
|
|
675
|
-
if (scene == null)
|
|
989
|
+
const renderManagerService = accessor.get(IRenderManagerService), docSelectionRenderService = (_a8 = renderManagerService.getRenderById(params.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService), 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();
|
|
990
|
+
if (scene == null || docSelectionRenderService == null)
|
|
676
991
|
return !1;
|
|
677
992
|
const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
678
993
|
if (documentDataModel == null)
|
|
@@ -680,14 +995,14 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
680
995
|
const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
|
|
681
996
|
if (needRefreshDrawings)
|
|
682
997
|
return docRefreshDrawingsService.refreshDrawings(skeleton), transformer.refreshControls(), !0;
|
|
683
|
-
const rawActions = [], { drawingId } = drawing, segmentId = (
|
|
998
|
+
const rawActions = [], { drawingId } = drawing, segmentId = (_b = docSelectionRenderService.getSegment()) != null ? _b : "", actions = getDeleteAndInsertCustomBlockActions(
|
|
684
999
|
newSegmentId,
|
|
685
1000
|
segmentId,
|
|
686
1001
|
segmentPage,
|
|
687
1002
|
offset,
|
|
688
1003
|
drawingId,
|
|
689
1004
|
documentDataModel,
|
|
690
|
-
|
|
1005
|
+
docSelectionRenderService
|
|
691
1006
|
);
|
|
692
1007
|
if (actions == null || actions.length === 0)
|
|
693
1008
|
return docRefreshDrawingsService.refreshDrawings(skeleton), transformer.refreshControls(), !1;
|
|
@@ -709,23 +1024,23 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
709
1024
|
type: CommandType.COMMAND,
|
|
710
1025
|
// eslint-disable-next-line max-lines-per-function
|
|
711
1026
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
712
|
-
var _a8;
|
|
1027
|
+
var _a8, _b;
|
|
713
1028
|
if (params == null)
|
|
714
1029
|
return !1;
|
|
715
|
-
const
|
|
716
|
-
if (scene == null)
|
|
1030
|
+
const renderManagerService = accessor.get(IRenderManagerService), docSelectionRenderService = (_a8 = renderManagerService.getRenderById(params.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService), renderObject = renderManagerService.getRenderById(params.unitId), scene = renderObject == null ? void 0 : renderObject.scene;
|
|
1031
|
+
if (scene == null || docSelectionRenderService == null)
|
|
717
1032
|
return !1;
|
|
718
1033
|
const transformer = scene.getTransformerByCreate(), commandService = accessor.get(ICommandService), documentDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
719
1034
|
if (documentDataModel == null)
|
|
720
1035
|
return !1;
|
|
721
|
-
const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params, rawActions = [], { drawingId } = drawing, segmentId = (
|
|
1036
|
+
const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params, rawActions = [], { drawingId } = drawing, segmentId = (_b = docSelectionRenderService.getSegment()) != null ? _b : "", actions = getDeleteAndInsertCustomBlockActions(
|
|
722
1037
|
newSegmentId,
|
|
723
1038
|
segmentId,
|
|
724
1039
|
segmentPage,
|
|
725
1040
|
offset,
|
|
726
1041
|
drawingId,
|
|
727
1042
|
documentDataModel,
|
|
728
|
-
|
|
1043
|
+
docSelectionRenderService
|
|
729
1044
|
);
|
|
730
1045
|
if (actions == null)
|
|
731
1046
|
return !1;
|
|
@@ -941,7 +1256,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
941
1256
|
}
|
|
942
1257
|
)))))));
|
|
943
1258
|
}, "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),
|
|
1259
|
+
const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), drawingManagerService = useDependency(IDrawingManagerService), renderManagerService = useDependency(IRenderManagerService), univerInstanceService = useDependency(IUniverInstanceService), { drawings } = props, drawingParam = drawings[0];
|
|
945
1260
|
if (drawingParam == null)
|
|
946
1261
|
return;
|
|
947
1262
|
const { unitId } = drawingParam, documentDataModel = univerInstanceService.getUniverDocInstance(unitId), renderObject = renderManagerService.getRenderById(unitId), scene = renderObject == null ? void 0 : renderObject.scene;
|
|
@@ -976,6 +1291,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
976
1291
|
posOffset: 0
|
|
977
1292
|
}), [followTextMove, setFollowTextMove] = useState(!0), [showPanel, setShowPanel] = useState(!0);
|
|
978
1293
|
function handlePositionChange(direction, value) {
|
|
1294
|
+
var _a8;
|
|
979
1295
|
direction === "positionH" ? setHPosition(value) : setVPosition(value);
|
|
980
1296
|
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
981
1297
|
if (focusDrawings.length === 0)
|
|
@@ -993,7 +1309,9 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
993
1309
|
key: direction,
|
|
994
1310
|
value
|
|
995
1311
|
}))
|
|
996
|
-
})
|
|
1312
|
+
});
|
|
1313
|
+
const docSelectionRenderService = (_a8 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService);
|
|
1314
|
+
docSelectionRenderService && docSelectionRenderService.blur(), transformer.refreshControls();
|
|
997
1315
|
}
|
|
998
1316
|
__name(handlePositionChange, "handlePositionChange");
|
|
999
1317
|
function handleHorizontalRelativeFromChange(value) {
|
|
@@ -1039,17 +1357,17 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
1039
1357
|
}
|
|
1040
1358
|
__name(handleHorizontalRelativeFromChange, "handleHorizontalRelativeFromChange");
|
|
1041
1359
|
function handleVerticalRelativeFromChange(value) {
|
|
1042
|
-
var _a8, _b, _c, _d, _e;
|
|
1360
|
+
var _a8, _b, _c, _d, _e, _f;
|
|
1043
1361
|
const prevRelativeFrom = vPosition.relativeFrom, prevPosOffset = vPosition.posOffset, relativeFrom = Number(value);
|
|
1044
1362
|
if (prevRelativeFrom === relativeFrom)
|
|
1045
1363
|
return;
|
|
1046
1364
|
const focusDrawings = drawingManagerService.getFocusDrawings();
|
|
1047
1365
|
if (focusDrawings.length === 0)
|
|
1048
1366
|
return;
|
|
1049
|
-
const { drawingId, unitId: unitId2 } = focusDrawings[0], documentDataModel2 = univerInstanceService.getUniverDocInstance(unitId2), skeleton = (_a8 = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getSkeleton(), segmentId =
|
|
1050
|
-
if (drawing == null || skeleton == null)
|
|
1367
|
+
const { drawingId, unitId: unitId2 } = focusDrawings[0], documentDataModel2 = univerInstanceService.getUniverDocInstance(unitId2), skeleton = (_a8 = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getSkeleton(), docSelectionRenderService = (_b = renderManagerService.getRenderById(unitId2)) == null ? void 0 : _b.with(DocSelectionRenderService), segmentId = docSelectionRenderService == null ? void 0 : docSelectionRenderService.getSegment(), segmentPage = docSelectionRenderService == null ? void 0 : docSelectionRenderService.getSegmentPage(), drawing = (_d = (_c = documentDataModel2 == null ? void 0 : documentDataModel2.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.customBlocks) == null ? void 0 : _d.find((c) => c.blockId === drawingId);
|
|
1368
|
+
if (drawing == null || skeleton == null || docSelectionRenderService == null)
|
|
1051
1369
|
return;
|
|
1052
|
-
const { startIndex } = drawing, glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage), line = (
|
|
1370
|
+
const { startIndex } = drawing, glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage), line = (_e = glyph == null ? void 0 : glyph.parent) == null ? void 0 : _e.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 = (_f = column == null ? void 0 : column.parent) == null ? void 0 : _f.parent;
|
|
1053
1371
|
if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null)
|
|
1054
1372
|
return;
|
|
1055
1373
|
let delta = 0;
|
|
@@ -1189,151 +1507,32 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
1189
1507
|
if (newDrawings.length === 0)
|
|
1190
1508
|
return !1;
|
|
1191
1509
|
const result = commandService.syncExecuteCommand(UpdateDrawingDocTransformCommand.id, {
|
|
1192
|
-
unitId,
|
|
1193
|
-
subUnitId: unitId,
|
|
1194
|
-
drawings: newDrawings
|
|
1195
|
-
});
|
|
1196
|
-
return transformer.refreshControls(), !!result;
|
|
1197
|
-
}, "handler")
|
|
1198
|
-
}, DeleteDocDrawingsCommand = {
|
|
1199
|
-
id: "doc.command.delete-drawing",
|
|
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)
|
|
1204
|
-
return !1;
|
|
1205
|
-
const { unitId } = drawings[0], newDrawings = drawings.map((drawing) => {
|
|
1206
|
-
const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
|
|
1207
|
-
return {
|
|
1208
|
-
unitId: unitId2,
|
|
1209
|
-
subUnitId,
|
|
1210
|
-
drawingId,
|
|
1211
|
-
drawingType
|
|
1212
|
-
};
|
|
1213
|
-
});
|
|
1214
|
-
return commandService.executeCommand(RemoveDocDrawingCommand.id, {
|
|
1215
|
-
unitId,
|
|
1216
|
-
drawings: newDrawings
|
|
1217
|
-
});
|
|
1218
|
-
}, "handler")
|
|
1219
|
-
}, SetDocDrawingArrangeCommand = {
|
|
1220
|
-
id: "doc.command.set-drawing-arrange",
|
|
1221
|
-
type: CommandType.COMMAND,
|
|
1222
|
-
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
1223
|
-
const commandService = accessor.get(ICommandService), docDrawingService = accessor.get(IDocDrawingService);
|
|
1224
|
-
if (params == null)
|
|
1225
|
-
return !1;
|
|
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)
|
|
1229
|
-
return !1;
|
|
1230
|
-
const { redo } = jsonOp;
|
|
1231
|
-
if (redo == null)
|
|
1232
|
-
return !1;
|
|
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,
|
|
1238
|
-
params: {
|
|
1239
|
-
unitId,
|
|
1240
|
-
actions: [],
|
|
1241
|
-
textRanges: null
|
|
1242
|
-
}
|
|
1243
|
-
};
|
|
1244
|
-
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1245
|
-
}, "handler")
|
|
1246
|
-
}, UngroupDocDrawingCommand = {
|
|
1247
|
-
id: "doc.command.ungroup-doc-image",
|
|
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);
|
|
1257
|
-
});
|
|
1258
|
-
}), docDrawingService.getUngroupDrawingOp(params), !1;
|
|
1259
|
-
}, "handler")
|
|
1260
|
-
}, GroupDocDrawingCommand = {
|
|
1261
|
-
id: "doc.command.group-doc-image",
|
|
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);
|
|
1271
|
-
});
|
|
1272
|
-
}), docDrawingService.getGroupDrawingOp(params), !1;
|
|
1273
|
-
}, "handler")
|
|
1274
|
-
}, InsertDocDrawingCommand = {
|
|
1275
|
-
id: "doc.command.insert-doc-image",
|
|
1276
|
-
type: CommandType.COMMAND,
|
|
1277
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1278
|
-
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
1279
|
-
var _a8, _b, _c, _d;
|
|
1280
|
-
if (params == null)
|
|
1281
|
-
return !1;
|
|
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)
|
|
1284
|
-
return !1;
|
|
1285
|
-
const unitId = documentDataModel.getUnitId(), { drawings } = params, { collapsed, startOffset, segmentId } = activeTextRange, body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
1286
|
-
if (body == null)
|
|
1287
|
-
return !1;
|
|
1288
|
-
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], drawingOrderLength = (_b = (_a8 = documentDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _a8.length) != null ? _b : 0;
|
|
1289
|
-
let removeDrawingLen = 0;
|
|
1290
|
-
if (collapsed)
|
|
1291
|
-
startOffset > 0 && textX.push({
|
|
1292
|
-
t: TextXActionType.RETAIN,
|
|
1293
|
-
len: startOffset,
|
|
1294
|
-
segmentId
|
|
1295
|
-
});
|
|
1296
|
-
else {
|
|
1297
|
-
const { dos } = getRetainAndDeleteFromReplace(activeTextRange, segmentId, 0, body);
|
|
1298
|
-
textX.push(...dos);
|
|
1299
|
-
const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [activeTextRange]), drawings2 = (_c = documentDataModel.getDrawings()) != null ? _c : {}, drawingOrder = (_d = documentDataModel.getDrawingsOrder()) != null ? _d : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
|
|
1300
|
-
if (sortedRemovedCustomBlockIds.length > 0)
|
|
1301
|
-
for (const blockId of sortedRemovedCustomBlockIds) {
|
|
1302
|
-
const drawing = drawings2[blockId], drawingIndex = drawingOrder.indexOf(blockId);
|
|
1303
|
-
if (drawing == null || drawingIndex < 0)
|
|
1304
|
-
continue;
|
|
1305
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
1306
|
-
rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction), removeDrawingLen++;
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
textX.push({
|
|
1310
|
-
t: TextXActionType.INSERT,
|
|
1311
|
-
body: {
|
|
1312
|
-
dataStream: "\b".repeat(drawings.length),
|
|
1313
|
-
customBlocks: drawings.map((drawing, i) => ({
|
|
1314
|
-
startIndex: i,
|
|
1315
|
-
blockId: drawing.drawingId
|
|
1316
|
-
}))
|
|
1317
|
-
},
|
|
1318
|
-
len: drawings.length,
|
|
1319
|
-
line: 0,
|
|
1320
|
-
segmentId
|
|
1510
|
+
unitId,
|
|
1511
|
+
subUnitId: unitId,
|
|
1512
|
+
drawings: newDrawings
|
|
1513
|
+
});
|
|
1514
|
+
return transformer.refreshControls(), !!result;
|
|
1515
|
+
}, "handler")
|
|
1516
|
+
}, DeleteDocDrawingsCommand = {
|
|
1517
|
+
id: "doc.command.delete-drawing",
|
|
1518
|
+
type: CommandType.COMMAND,
|
|
1519
|
+
handler: /* @__PURE__ */ __name((accessor) => {
|
|
1520
|
+
const commandService = accessor.get(ICommandService), drawings = accessor.get(IDocDrawingService).getFocusDrawings();
|
|
1521
|
+
if (drawings.length === 0)
|
|
1522
|
+
return !1;
|
|
1523
|
+
const { unitId } = drawings[0], newDrawings = drawings.map((drawing) => {
|
|
1524
|
+
const { unitId: unitId2, subUnitId, drawingId, drawingType } = drawing;
|
|
1525
|
+
return {
|
|
1526
|
+
unitId: unitId2,
|
|
1527
|
+
subUnitId,
|
|
1528
|
+
drawingId,
|
|
1529
|
+
drawingType
|
|
1530
|
+
};
|
|
1531
|
+
});
|
|
1532
|
+
return commandService.executeCommand(RemoveDocDrawingCommand.id, {
|
|
1533
|
+
unitId,
|
|
1534
|
+
drawings: newDrawings
|
|
1321
1535
|
});
|
|
1322
|
-
const path = getRichTextEditPath(documentDataModel, segmentId), placeHolderAction = jsonX.editOp(textX.serialize(), path);
|
|
1323
|
-
rawActions.push(placeHolderAction);
|
|
1324
|
-
for (const drawing of drawings) {
|
|
1325
|
-
const { drawingId } = drawing, addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing), addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
|
|
1326
|
-
rawActions.push(addDrawingAction), rawActions.push(addDrawingOrderAction);
|
|
1327
|
-
}
|
|
1328
|
-
const doMutation = {
|
|
1329
|
-
id: RichTextEditingMutation.id,
|
|
1330
|
-
params: {
|
|
1331
|
-
unitId,
|
|
1332
|
-
actions: [],
|
|
1333
|
-
textRanges: []
|
|
1334
|
-
}
|
|
1335
|
-
};
|
|
1336
|
-
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1337
1536
|
}, "handler")
|
|
1338
1537
|
};
|
|
1339
1538
|
function whenDocDrawingFocused(contextService) {
|
|
@@ -1388,31 +1587,37 @@ const MoveDrawingDownShortcutItem = {
|
|
|
1388
1587
|
preconditions: whenDocDrawingFocused,
|
|
1389
1588
|
binding: KeyCode.DELETE,
|
|
1390
1589
|
mac: KeyCode.BACKSPACE
|
|
1590
|
+
}, menuSchema = {
|
|
1591
|
+
[RibbonStartGroup.LAYOUT]: {
|
|
1592
|
+
[IMAGE_MENU_ID]: {
|
|
1593
|
+
order: 0,
|
|
1594
|
+
menuItemFactory: ImageMenuFactory,
|
|
1595
|
+
[IMAGE_MENU_UPLOAD_FLOAT_ID]: {
|
|
1596
|
+
order: 0,
|
|
1597
|
+
menuItemFactory: UploadFloatImageMenuFactory
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1391
1601
|
};
|
|
1392
|
-
var __defProp$
|
|
1393
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
1602
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1603
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1394
1604
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1395
|
-
return kind && result && __defProp$
|
|
1396
|
-
}, "__decorateClass$
|
|
1397
|
-
let DocDrawingUIController = (
|
|
1398
|
-
constructor(
|
|
1399
|
-
super(), this.
|
|
1605
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
1606
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a3;
|
|
1607
|
+
let DocDrawingUIController = (_a3 = class extends Disposable {
|
|
1608
|
+
constructor(_componentManager, _menuManagerService, _commandService, _shortcutService) {
|
|
1609
|
+
super(), this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._commandService = _commandService, this._shortcutService = _shortcutService, this._init();
|
|
1400
1610
|
}
|
|
1401
1611
|
_initCustomComponents() {
|
|
1402
1612
|
const componentManager = this._componentManager;
|
|
1403
|
-
this.disposeWithMe(componentManager.register(ImageUploadIcon, AddImageSingle)), this.disposeWithMe(componentManager.register(
|
|
1613
|
+
this.disposeWithMe(componentManager.register(ImageUploadIcon, AddImageSingle)), this.disposeWithMe(componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
|
|
1404
1614
|
}
|
|
1405
1615
|
_initMenus() {
|
|
1406
|
-
|
|
1407
|
-
ImageMenuFactory,
|
|
1408
|
-
UploadFloatImageMenuFactory
|
|
1409
|
-
].forEach((factory) => {
|
|
1410
|
-
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
|
|
1411
|
-
});
|
|
1616
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
1412
1617
|
}
|
|
1413
1618
|
_initCommands() {
|
|
1414
1619
|
[
|
|
1415
|
-
|
|
1620
|
+
InsertDocImageCommand,
|
|
1416
1621
|
InsertDocDrawingCommand,
|
|
1417
1622
|
UpdateDocDrawingWrappingStyleCommand,
|
|
1418
1623
|
UpdateDocDrawingDistanceCommand,
|
|
@@ -1446,251 +1651,14 @@ let DocDrawingUIController = (_a2 = class extends Disposable {
|
|
|
1446
1651
|
_init() {
|
|
1447
1652
|
this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
|
|
1448
1653
|
}
|
|
1449
|
-
}, __name(
|
|
1450
|
-
DocDrawingUIController = __decorateClass$
|
|
1654
|
+
}, __name(_a3, "DocDrawingUIController"), _a3);
|
|
1655
|
+
DocDrawingUIController = __decorateClass$4([
|
|
1451
1656
|
OnLifecycle(LifecycleStages.Ready, DocDrawingUIController),
|
|
1452
|
-
__decorateParam$
|
|
1453
|
-
__decorateParam$
|
|
1454
|
-
__decorateParam$
|
|
1455
|
-
__decorateParam$
|
|
1456
|
-
__decorateParam$5(4, IShortcutService)
|
|
1657
|
+
__decorateParam$4(0, Inject(ComponentManager)),
|
|
1658
|
+
__decorateParam$4(1, IMenuManagerService),
|
|
1659
|
+
__decorateParam$4(2, ICommandService),
|
|
1660
|
+
__decorateParam$4(3, IShortcutService)
|
|
1457
1661
|
], DocDrawingUIController);
|
|
1458
|
-
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1459
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1460
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1461
|
-
return kind && result && __defProp$4(target, key, result), result;
|
|
1462
|
-
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a3;
|
|
1463
|
-
let DocDrawingUpdateRenderController = (_a3 = class extends Disposable {
|
|
1464
|
-
constructor(_context, _commandService, _textSelectionManagerService, _renderManagerSrv, _imageIoService, _docDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, _textSelectionManager, _textSelectionRenderManager, _docRefreshDrawingsService) {
|
|
1465
|
-
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();
|
|
1466
|
-
}
|
|
1467
|
-
/**
|
|
1468
|
-
* Upload image to cell or float image
|
|
1469
|
-
*/
|
|
1470
|
-
_initCommandListeners() {
|
|
1471
|
-
this.disposeWithMe(
|
|
1472
|
-
this._commandService.onCommandExecuted(async (command) => {
|
|
1473
|
-
if (command.id === InsertDocImageOperation.id) {
|
|
1474
|
-
const params = command.params;
|
|
1475
|
-
if (params.files == null)
|
|
1476
|
-
return;
|
|
1477
|
-
const fileLength = params.files.length;
|
|
1478
|
-
if (fileLength > DRAWING_IMAGE_COUNT_LIMIT) {
|
|
1479
|
-
this._messageService.show({
|
|
1480
|
-
type: MessageType.Error,
|
|
1481
|
-
content: this._localeService.t("update-status.exceedMaxCount", String(DRAWING_IMAGE_COUNT_LIMIT))
|
|
1482
|
-
});
|
|
1483
|
-
return;
|
|
1484
|
-
}
|
|
1485
|
-
this._imageIoService.setWaitCount(fileLength), await this._insertFloatImages(params.files);
|
|
1486
|
-
}
|
|
1487
|
-
})
|
|
1488
|
-
);
|
|
1489
|
-
}
|
|
1490
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1491
|
-
async _insertFloatImages(files) {
|
|
1492
|
-
let imageParams = [];
|
|
1493
|
-
try {
|
|
1494
|
-
imageParams = await Promise.all(files.map((file) => this._imageIoService.saveImage(file)));
|
|
1495
|
-
} catch (error) {
|
|
1496
|
-
const type = error.message;
|
|
1497
|
-
let content = "";
|
|
1498
|
-
switch (type) {
|
|
1499
|
-
case ImageUploadStatusType.ERROR_EXCEED_SIZE:
|
|
1500
|
-
content = this._localeService.t("update-status.exceedMaxSize", String(DRAWING_IMAGE_ALLOW_SIZE / (1024 * 1024)));
|
|
1501
|
-
break;
|
|
1502
|
-
case ImageUploadStatusType.ERROR_IMAGE_TYPE:
|
|
1503
|
-
content = this._localeService.t("update-status.invalidImageType");
|
|
1504
|
-
break;
|
|
1505
|
-
case ImageUploadStatusType.ERROR_IMAGE:
|
|
1506
|
-
content = this._localeService.t("update-status.invalidImage");
|
|
1507
|
-
break;
|
|
1508
|
-
}
|
|
1509
|
-
this._messageService.show({
|
|
1510
|
-
type: MessageType.Error,
|
|
1511
|
-
content
|
|
1512
|
-
});
|
|
1513
|
-
}
|
|
1514
|
-
if (imageParams.length === 0)
|
|
1515
|
-
return;
|
|
1516
|
-
const { unitId } = this._context, docDrawingParams = [];
|
|
1517
|
-
for (const imageParam of imageParams) {
|
|
1518
|
-
if (imageParam == null)
|
|
1519
|
-
continue;
|
|
1520
|
-
const { imageId, imageSourceType, source, base64Cache } = imageParam, { width, height, image } = await getImageSize(base64Cache || "");
|
|
1521
|
-
this._imageIoService.addImageSourceCache(imageId, imageSourceType, image);
|
|
1522
|
-
let scale = 1;
|
|
1523
|
-
if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
|
|
1524
|
-
const scaleWidth = DRAWING_IMAGE_WIDTH_LIMIT / width, scaleHeight = DRAWING_IMAGE_HEIGHT_LIMIT / height;
|
|
1525
|
-
scale = Math.min(scaleWidth, scaleHeight);
|
|
1526
|
-
}
|
|
1527
|
-
const docTransform = this._getImagePosition(width * scale, height * scale);
|
|
1528
|
-
if (docTransform == null)
|
|
1529
|
-
return;
|
|
1530
|
-
const docDrawingParam = {
|
|
1531
|
-
unitId,
|
|
1532
|
-
subUnitId: unitId,
|
|
1533
|
-
drawingId: imageId,
|
|
1534
|
-
drawingType: DrawingTypeEnum.DRAWING_IMAGE,
|
|
1535
|
-
imageSourceType,
|
|
1536
|
-
source,
|
|
1537
|
-
transform: docDrawingPositionToTransform(docTransform),
|
|
1538
|
-
docTransform,
|
|
1539
|
-
behindDoc: BooleanNumber.FALSE,
|
|
1540
|
-
title: "",
|
|
1541
|
-
description: "",
|
|
1542
|
-
layoutType: PositionedObjectLayoutType.INLINE,
|
|
1543
|
-
// Insert inline drawing by default.
|
|
1544
|
-
wrapText: WrapTextType.BOTH_SIDES,
|
|
1545
|
-
distB: 0,
|
|
1546
|
-
distL: 0,
|
|
1547
|
-
distR: 0,
|
|
1548
|
-
distT: 0
|
|
1549
|
-
};
|
|
1550
|
-
this._isInsertInHeaderFooter() && (docDrawingParam.isMultiTransform = BooleanNumber.TRUE, docDrawingParam.transforms = docDrawingParam.transform ? [docDrawingParam.transform] : null), docDrawingParams.push(docDrawingParam);
|
|
1551
|
-
}
|
|
1552
|
-
this._commandService.executeCommand(InsertDocDrawingCommand.id, {
|
|
1553
|
-
unitId,
|
|
1554
|
-
drawings: docDrawingParams
|
|
1555
|
-
});
|
|
1556
|
-
}
|
|
1557
|
-
_isInsertInHeaderFooter() {
|
|
1558
|
-
var _a8;
|
|
1559
|
-
const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel(), editArea = viewModel == null ? void 0 : viewModel.getEditArea();
|
|
1560
|
-
return editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER;
|
|
1561
|
-
}
|
|
1562
|
-
_getImagePosition(imageWidth, imageHeight) {
|
|
1563
|
-
const activeTextRange = this._textSelectionManagerService.getActiveTextRange(), position = (activeTextRange == null ? void 0 : activeTextRange.getAbsolutePosition()) || {
|
|
1564
|
-
left: 0,
|
|
1565
|
-
top: 0
|
|
1566
|
-
};
|
|
1567
|
-
return {
|
|
1568
|
-
size: {
|
|
1569
|
-
width: imageWidth,
|
|
1570
|
-
height: imageHeight
|
|
1571
|
-
},
|
|
1572
|
-
positionH: {
|
|
1573
|
-
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
1574
|
-
posOffset: position.left
|
|
1575
|
-
},
|
|
1576
|
-
positionV: {
|
|
1577
|
-
relativeFrom: ObjectRelativeFromV.MARGIN,
|
|
1578
|
-
posOffset: position.top
|
|
1579
|
-
},
|
|
1580
|
-
angle: 0
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
_updateOrderListener() {
|
|
1584
|
-
this._drawingManagerService.featurePluginOrderUpdate$.subscribe((params) => {
|
|
1585
|
-
const { unitId, subUnitId, drawingIds, arrangeType } = params;
|
|
1586
|
-
this._commandService.executeCommand(SetDocDrawingArrangeCommand.id, {
|
|
1587
|
-
unitId,
|
|
1588
|
-
subUnitId,
|
|
1589
|
-
drawingIds,
|
|
1590
|
-
arrangeType
|
|
1591
|
-
});
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
|
-
_updateDrawingListener() {
|
|
1595
|
-
this._drawingManagerService.featurePluginUpdate$.subscribe((params) => {
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
_groupDrawingListener() {
|
|
1599
|
-
this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
|
|
1600
|
-
this._commandService.executeCommand(GroupDocDrawingCommand.id, params);
|
|
1601
|
-
}), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((params) => {
|
|
1602
|
-
this._commandService.executeCommand(UngroupDocDrawingCommand.id, params);
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
_getCurrentSceneAndTransformer() {
|
|
1606
|
-
const { scene, mainComponent } = this._context;
|
|
1607
|
-
if (scene == null || mainComponent == null)
|
|
1608
|
-
return;
|
|
1609
|
-
const transformer = scene.getTransformerByCreate(), { docsLeft, docsTop } = mainComponent.getOffsetConfig();
|
|
1610
|
-
return { scene, transformer, docsLeft, docsTop };
|
|
1611
|
-
}
|
|
1612
|
-
_focusDrawingListener() {
|
|
1613
|
-
this.disposeWithMe(
|
|
1614
|
-
this._drawingManagerService.focus$.subscribe((params) => {
|
|
1615
|
-
var _a8;
|
|
1616
|
-
const { transformer, docsLeft, docsTop } = (_a8 = this._getCurrentSceneAndTransformer()) != null ? _a8 : {};
|
|
1617
|
-
if (params == null || params.length === 0)
|
|
1618
|
-
this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !1), this._docDrawingService.focusDrawing([]), transformer && transformer.resetProps({
|
|
1619
|
-
zeroTop: 0,
|
|
1620
|
-
zeroLeft: 0
|
|
1621
|
-
});
|
|
1622
|
-
else {
|
|
1623
|
-
this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, !0), this._docDrawingService.focusDrawing(params), this._textSelectionManager.getActiveTextRange() && this._textSelectionManager.replaceTextRanges([]);
|
|
1624
|
-
const prevSegmentId = this._textSelectionRenderManager.getSegment(), segmentId = this._findSegmentIdByDrawingId(params[0].drawingId);
|
|
1625
|
-
prevSegmentId !== segmentId && this._textSelectionRenderManager.setSegment(segmentId), transformer && transformer.resetProps({
|
|
1626
|
-
zeroTop: docsTop,
|
|
1627
|
-
zeroLeft: docsLeft
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
|
-
})
|
|
1631
|
-
);
|
|
1632
|
-
}
|
|
1633
|
-
_findSegmentIdByDrawingId(drawingId) {
|
|
1634
|
-
var _a8, _b, _c;
|
|
1635
|
-
const { unit: DocDataModel } = this._context, { body, headers = {}, footers = {} } = DocDataModel.getSnapshot();
|
|
1636
|
-
if (((_a8 = body == null ? void 0 : body.customBlocks) != null ? _a8 : []).some((b) => b.blockId === drawingId))
|
|
1637
|
-
return "";
|
|
1638
|
-
for (const headerId of Object.keys(headers))
|
|
1639
|
-
if ((_b = headers[headerId].body.customBlocks) != null && _b.some((b) => b.blockId === drawingId))
|
|
1640
|
-
return headerId;
|
|
1641
|
-
for (const footerId of Object.keys(footers))
|
|
1642
|
-
if ((_c = footers[footerId].body.customBlocks) != null && _c.some((b) => b.blockId === drawingId))
|
|
1643
|
-
return footerId;
|
|
1644
|
-
return "";
|
|
1645
|
-
}
|
|
1646
|
-
// Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
|
|
1647
|
-
_updateDrawingsEditStatus() {
|
|
1648
|
-
var _a8;
|
|
1649
|
-
const { unit: docDataModel, scene, unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
|
|
1650
|
-
if (viewModel == null || docDataModel == null)
|
|
1651
|
-
return;
|
|
1652
|
-
const snapshot = docDataModel.getSnapshot(), { drawings = {} } = snapshot, isEditBody = viewModel.getEditArea() === DocumentEditArea.BODY;
|
|
1653
|
-
for (const key of Object.keys(drawings)) {
|
|
1654
|
-
const drawing = drawings[key], objectKey = getDrawingShapeKeyByDrawingSearch({ unitId, drawingId: drawing.drawingId, subUnitId: unitId }), drawingShapes = scene.fuzzyMathObjects(objectKey, !0);
|
|
1655
|
-
if (drawingShapes.length)
|
|
1656
|
-
for (const shape of drawingShapes)
|
|
1657
|
-
scene.detachTransformerFrom(shape), shape.setOpacity(0.5), (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) && (scene.attachTransformerTo(shape), shape.setOpacity(1));
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
_editAreaChangeListener() {
|
|
1661
|
-
var _a8;
|
|
1662
|
-
const { unitId } = this._context, viewModel = (_a8 = this._renderManagerSrv.getRenderById(unitId)) == null ? void 0 : _a8.with(DocSkeletonManagerService).getViewModel();
|
|
1663
|
-
viewModel != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
|
|
1664
|
-
viewModel.editAreaChange$.subscribe(() => {
|
|
1665
|
-
this._updateDrawingsEditStatus();
|
|
1666
|
-
})
|
|
1667
|
-
), this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
|
|
1668
|
-
skeleton != null && queueMicrotask(() => {
|
|
1669
|
-
this._updateDrawingsEditStatus();
|
|
1670
|
-
});
|
|
1671
|
-
}), this.disposeWithMe(
|
|
1672
|
-
this._commandService.onCommandExecuted(async (command) => {
|
|
1673
|
-
command.id === RichTextEditingMutation.id && queueMicrotask(() => {
|
|
1674
|
-
this._updateDrawingsEditStatus();
|
|
1675
|
-
});
|
|
1676
|
-
})
|
|
1677
|
-
));
|
|
1678
|
-
}
|
|
1679
|
-
}, __name(_a3, "DocDrawingUpdateRenderController"), _a3);
|
|
1680
|
-
DocDrawingUpdateRenderController = __decorateClass$4([
|
|
1681
|
-
__decorateParam$4(1, ICommandService),
|
|
1682
|
-
__decorateParam$4(2, Inject(TextSelectionManagerService)),
|
|
1683
|
-
__decorateParam$4(3, IRenderManagerService),
|
|
1684
|
-
__decorateParam$4(4, IImageIoService),
|
|
1685
|
-
__decorateParam$4(5, IDocDrawingService),
|
|
1686
|
-
__decorateParam$4(6, IDrawingManagerService),
|
|
1687
|
-
__decorateParam$4(7, IContextService),
|
|
1688
|
-
__decorateParam$4(8, IMessageService),
|
|
1689
|
-
__decorateParam$4(9, Inject(LocaleService)),
|
|
1690
|
-
__decorateParam$4(10, Inject(TextSelectionManagerService)),
|
|
1691
|
-
__decorateParam$4(11, ITextSelectionRenderManager),
|
|
1692
|
-
__decorateParam$4(12, Inject(DocRefreshDrawingsService))
|
|
1693
|
-
], DocDrawingUpdateRenderController);
|
|
1694
1662
|
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1695
1663
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1696
1664
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
@@ -1976,14 +1944,14 @@ function isInTableCell(nodePosition) {
|
|
|
1976
1944
|
__name(isInTableCell, "isInTableCell");
|
|
1977
1945
|
var _a6;
|
|
1978
1946
|
let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
1979
|
-
constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService
|
|
1947
|
+
constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
|
|
1980
1948
|
super();
|
|
1981
1949
|
__publicField(this, "_liquid", new Liquid());
|
|
1982
1950
|
__publicField(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
|
|
1983
1951
|
// Use to cache the drawings is under transforming or scaling.
|
|
1984
1952
|
__publicField(this, "_transformerCache", /* @__PURE__ */ new Map());
|
|
1985
1953
|
__publicField(this, "_anchorShape");
|
|
1986
|
-
this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this.
|
|
1954
|
+
this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._drawingManagerService = _drawingManagerService, this._renderManagerService = _renderManagerService, this._init();
|
|
1987
1955
|
}
|
|
1988
1956
|
_init() {
|
|
1989
1957
|
this._listenDrawingFocus();
|
|
@@ -2137,7 +2105,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2137
2105
|
contentBoxPointGroup != null && this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
|
|
2138
2106
|
}
|
|
2139
2107
|
_getInlineDrawingAnchor(drawing, offsetX, offsetY) {
|
|
2140
|
-
var _a8;
|
|
2108
|
+
var _a8, _b;
|
|
2141
2109
|
const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
|
|
2142
2110
|
if (currentRender == null)
|
|
2143
2111
|
return;
|
|
@@ -2150,6 +2118,9 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2150
2118
|
const HALF = 0.5, coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
|
|
2151
2119
|
if (coord == null)
|
|
2152
2120
|
return;
|
|
2121
|
+
const docSelectionRenderService = (_a8 = this._renderManagerService.getRenderById(drawing.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService);
|
|
2122
|
+
if (docSelectionRenderService == null)
|
|
2123
|
+
return;
|
|
2153
2124
|
const nodeInfo = skeleton == null ? void 0 : skeleton.findNodeByCoord(
|
|
2154
2125
|
coord,
|
|
2155
2126
|
pageLayoutType,
|
|
@@ -2157,8 +2128,8 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2157
2128
|
pageMarginTop,
|
|
2158
2129
|
{
|
|
2159
2130
|
strict: !1,
|
|
2160
|
-
segmentId:
|
|
2161
|
-
segmentPage:
|
|
2131
|
+
segmentId: docSelectionRenderService.getSegment(),
|
|
2132
|
+
segmentPage: docSelectionRenderService.getSegmentPage()
|
|
2162
2133
|
}
|
|
2163
2134
|
);
|
|
2164
2135
|
if (nodeInfo) {
|
|
@@ -2173,13 +2144,13 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2173
2144
|
const positionWithIsBack = {
|
|
2174
2145
|
...nodePosition,
|
|
2175
2146
|
isBack
|
|
2176
|
-
}, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList, contentBoxPointGroup } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (
|
|
2147
|
+
}, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList, contentBoxPointGroup } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_b = getOneTextSelectionRange(cursorList)) != null ? _b : {};
|
|
2177
2148
|
if (startOffset != null)
|
|
2178
2149
|
return { offset: startOffset, contentBoxPointGroup, segmentId, segmentPage: segmentPageIndex };
|
|
2179
2150
|
}
|
|
2180
2151
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
2181
2152
|
_getDrawingAnchor(drawing, object) {
|
|
2182
|
-
var _a8, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2153
|
+
var _a8, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2183
2154
|
const currentRender = this._renderManagerService.getRenderById(drawing.unitId), skeleton = currentRender == null ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton(), skeletonData = skeleton == null ? void 0 : skeleton.getSkeletonData();
|
|
2184
2155
|
if (skeletonData == null || currentRender == null)
|
|
2185
2156
|
return;
|
|
@@ -2198,10 +2169,13 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2198
2169
|
}, { x, y } = scene.getViewportScrollXY(activeViewport), coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
|
|
2199
2170
|
if (coord == null)
|
|
2200
2171
|
return;
|
|
2172
|
+
const docSelectionRenderService = (_a8 = this._renderManagerService.getRenderById(drawing.unitId)) == null ? void 0 : _a8.with(DocSelectionRenderService);
|
|
2173
|
+
if (docSelectionRenderService == null)
|
|
2174
|
+
return;
|
|
2201
2175
|
const nodeInfo = skeleton == null ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
|
|
2202
2176
|
strict: !1,
|
|
2203
|
-
segmentId:
|
|
2204
|
-
segmentPage:
|
|
2177
|
+
segmentId: docSelectionRenderService.getSegment(),
|
|
2178
|
+
segmentPage: docSelectionRenderService.getSegmentPage()
|
|
2205
2179
|
});
|
|
2206
2180
|
if (nodeInfo) {
|
|
2207
2181
|
const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
|
|
@@ -2209,7 +2183,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2209
2183
|
}
|
|
2210
2184
|
if (glyphAnchor == null)
|
|
2211
2185
|
return;
|
|
2212
|
-
const line = (
|
|
2186
|
+
const line = (_b = glyphAnchor.parent) == null ? void 0 : _b.parent, column = line == null ? void 0 : line.parent, paragraphStartLine = (_c = column == null ? void 0 : column.lines.find((l) => l.paragraphIndex === (line == null ? void 0 : line.paragraphIndex) && l.paragraphStart)) != null ? _c : column == null ? void 0 : column.lines[0], page = (_d = column == null ? void 0 : column.parent) == null ? void 0 : _d.parent;
|
|
2213
2187
|
if (line == null || column == null || paragraphStartLine == null || page == null)
|
|
2214
2188
|
return;
|
|
2215
2189
|
this._liquid.reset();
|
|
@@ -2219,7 +2193,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2219
2193
|
if (segmentPage > -1 && pIndex === segmentPage) {
|
|
2220
2194
|
switch (pageType) {
|
|
2221
2195
|
case DocumentSkeletonPageType.HEADER: {
|
|
2222
|
-
const headerSke = (
|
|
2196
|
+
const headerSke = (_e = skeHeaders.get(headerId)) == null ? void 0 : _e.get(pageWidth);
|
|
2223
2197
|
if (headerSke)
|
|
2224
2198
|
this._liquid.translatePagePadding({
|
|
2225
2199
|
marginTop: headerSke.marginTop,
|
|
@@ -2230,7 +2204,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2230
2204
|
break;
|
|
2231
2205
|
}
|
|
2232
2206
|
case DocumentSkeletonPageType.FOOTER: {
|
|
2233
|
-
const footerSke = (
|
|
2207
|
+
const footerSke = (_f = skeFooters.get(footerId)) == null ? void 0 : _f.get(pageWidth);
|
|
2234
2208
|
if (footerSke)
|
|
2235
2209
|
this._liquid.translatePagePadding({
|
|
2236
2210
|
marginTop: pageHeight - marginBottom + footerSke.marginTop,
|
|
@@ -2247,7 +2221,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2247
2221
|
break;
|
|
2248
2222
|
this._liquid.restorePagePadding(p), this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
|
|
2249
2223
|
}
|
|
2250
|
-
switch (positionV.relativeFrom === ObjectRelativeFromV.LINE ? glyphAnchor = line.divides[0].glyphGroup[0] : glyphAnchor = (
|
|
2224
|
+
switch (positionV.relativeFrom === ObjectRelativeFromV.LINE ? glyphAnchor = line.divides[0].glyphGroup[0] : glyphAnchor = (_j = (_i = (_h = (_g = paragraphStartLine.divides) == null ? void 0 : _g[0]) == null ? void 0 : _h.glyphGroup) == null ? void 0 : _i[0]) != null ? _j : glyphAnchor, docTransform.positionH = {
|
|
2251
2225
|
relativeFrom: positionH.relativeFrom,
|
|
2252
2226
|
posOffset: left - this._liquid.x - docsLeft
|
|
2253
2227
|
}, positionH.relativeFrom) {
|
|
@@ -2285,7 +2259,7 @@ let DocDrawingTransformerController = (_a6 = class extends Disposable {
|
|
|
2285
2259
|
const positionWithIsBack = {
|
|
2286
2260
|
...nodePosition,
|
|
2287
2261
|
isBack
|
|
2288
|
-
}, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (
|
|
2262
|
+
}, documentOffsetConfig = docObject.document.getOffsetConfig(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { cursorList } = convertor.getRangePointData(positionWithIsBack, positionWithIsBack), { startOffset } = (_k = getOneTextSelectionRange(cursorList)) != null ? _k : {};
|
|
2289
2263
|
if (startOffset != null)
|
|
2290
2264
|
return { offset: startOffset, docTransform, segmentId, segmentPage };
|
|
2291
2265
|
}
|
|
@@ -2450,19 +2424,21 @@ DocDrawingTransformerController = __decorateClass$1([
|
|
|
2450
2424
|
__decorateParam$1(0, ICommandService),
|
|
2451
2425
|
__decorateParam$1(1, IUniverInstanceService),
|
|
2452
2426
|
__decorateParam$1(2, IDrawingManagerService),
|
|
2453
|
-
__decorateParam$1(3, IRenderManagerService)
|
|
2454
|
-
__decorateParam$1(4, ITextSelectionRenderManager)
|
|
2427
|
+
__decorateParam$1(3, IRenderManagerService)
|
|
2455
2428
|
], DocDrawingTransformerController);
|
|
2429
|
+
const PLUGIN_CONFIG_KEY = "docs-drawing-ui.config", defaultPluginConfig = {};
|
|
2456
2430
|
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) => {
|
|
2457
2431
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2458
2432
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2459
2433
|
return kind && result && __defProp2(target, key, result), result;
|
|
2460
2434
|
}, "__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");
|
|
2461
|
-
const PLUGIN_NAME = "
|
|
2435
|
+
const PLUGIN_NAME = "DOC_DRAWING_UI_PLUGIN";
|
|
2462
2436
|
var _a7;
|
|
2463
2437
|
let UniverDocsDrawingUIPlugin = (_a7 = class extends Plugin {
|
|
2464
|
-
constructor(_config, _injector, _renderManagerSrv) {
|
|
2465
|
-
super(), this._injector = _injector, this._renderManagerSrv = _renderManagerSrv;
|
|
2438
|
+
constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
|
|
2439
|
+
super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._configService = _configService;
|
|
2440
|
+
const { ...rest } = this._config;
|
|
2441
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
2466
2442
|
}
|
|
2467
2443
|
onStarting() {
|
|
2468
2444
|
[
|
|
@@ -2485,17 +2461,17 @@ __publicField2(UniverDocsDrawingUIPlugin, "pluginName", PLUGIN_NAME);
|
|
|
2485
2461
|
UniverDocsDrawingUIPlugin = __decorateClass([
|
|
2486
2462
|
DependentOn(UniverDrawingUIPlugin, UniverDrawingPlugin, UniverDocsDrawingPlugin),
|
|
2487
2463
|
__decorateParam(1, Inject(Injector)),
|
|
2488
|
-
__decorateParam(2, IRenderManagerService)
|
|
2464
|
+
__decorateParam(2, IRenderManagerService),
|
|
2465
|
+
__decorateParam(3, IConfigService)
|
|
2489
2466
|
], UniverDocsDrawingUIPlugin);
|
|
2490
2467
|
export {
|
|
2491
|
-
COMPONENT_DOC_UPLOAD_FILE_MENU,
|
|
2492
2468
|
ClearDocDrawingTransformerOperation,
|
|
2493
2469
|
DeleteDocDrawingsCommand,
|
|
2494
2470
|
EditDocDrawingOperation,
|
|
2495
2471
|
GroupDocDrawingCommand,
|
|
2496
2472
|
IMAGE_MENU_ID,
|
|
2497
2473
|
InsertDocDrawingCommand,
|
|
2498
|
-
|
|
2474
|
+
InsertDocImageCommand,
|
|
2499
2475
|
MoveDocDrawingsCommand,
|
|
2500
2476
|
RemoveDocDrawingCommand,
|
|
2501
2477
|
SetDocDrawingArrangeCommand,
|