@univerjs/docs-drawing 1.0.0-insiders.20260813-7c9aa50 → 1.0.0
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/LICENSE +176 -0
- package/README.md +1 -2
- package/lib/cjs/facade.js +13 -8
- package/lib/cjs/index.js +180 -53
- package/lib/es/facade.js +15 -10
- package/lib/es/index.js +181 -56
- package/lib/facade.js +15 -10
- package/lib/index.js +181 -56
- package/lib/types/commands/commands/remove-doc-drawing.command.d.ts +2 -1
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +6 -2
- package/lib/types/commands/commands/update-doc-drawing-transform.command.d.ts +4 -3
- package/lib/types/commands/commands/update-doc-drawing-wrapping-style.command.d.ts +0 -6
- package/lib/types/controllers/doc-drawing.controller.d.ts +1 -0
- package/lib/types/facade/f-document-image.d.ts +3 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/services/doc-drawing-source.d.ts +27 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArrangeTypeEnum, BooleanNumber, BuildTextUtils, CommandType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSONX, MemoryCursor, Plugin, PositionedObjectLayoutType, TextX, TextXActionType, Tools, UniverInstanceType, createIdentifier, getRichTextEditPath, merge, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
|
-
import { DocSelectionManagerService, RichTextEditingMutation, UniverDocsPlugin, getContentInsertRange, normalizeTextRange } from "@univerjs/docs";
|
|
1
|
+
import { ArrangeTypeEnum, BooleanNumber, BuildTextUtils, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSONX, MemoryCursor, Plugin, PositionedObjectLayoutType, TextX, TextXActionType, Tools, UniverInstanceType, createIdentifier, getRichTextEditPath, merge, normalizeDrawingOrderIndex, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
|
+
import { DocHistoryAction, DocSelectionManagerService, RichTextEditingMutation, UniverDocsPlugin, getContentInsertRange, normalizeTextRange } from "@univerjs/docs";
|
|
3
3
|
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin } from "@univerjs/drawing";
|
|
4
4
|
|
|
5
5
|
//#region src/commands/commands/insert-doc-drawing.command.ts
|
|
@@ -10,7 +10,7 @@ const InsertDocDrawingCommand = {
|
|
|
10
10
|
id: "doc.command.insert-doc-image",
|
|
11
11
|
type: CommandType.COMMAND,
|
|
12
12
|
handler: (accessor, params) => {
|
|
13
|
-
var _documentDataModel$ge, _snapshot$headers, _snapshot$footers;
|
|
13
|
+
var _documentDataModel$ge, _snapshot$notes, _snapshot$headers, _snapshot$footers;
|
|
14
14
|
if (!params) return false;
|
|
15
15
|
const commandService = accessor.get(ICommandService);
|
|
16
16
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
@@ -22,11 +22,17 @@ const InsertDocDrawingCommand = {
|
|
|
22
22
|
const { segmentId = "" } = resolvedTextRange;
|
|
23
23
|
if (!((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody())) return false;
|
|
24
24
|
const snapshot = documentDataModel.getSnapshot();
|
|
25
|
-
const
|
|
25
|
+
const isFootnote = !!((_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId]);
|
|
26
|
+
if (isFootnote && drawings.some((drawing) => drawing.drawingType !== DrawingTypeEnum.DRAWING_IMAGE)) return false;
|
|
27
|
+
let targetDrawings = !!((_snapshot$headers = snapshot.headers) === null || _snapshot$headers === void 0 ? void 0 : _snapshot$headers[segmentId]) || !!((_snapshot$footers = snapshot.footers) === null || _snapshot$footers === void 0 ? void 0 : _snapshot$footers[segmentId]) ? drawings.map((drawing) => ({
|
|
26
28
|
...drawing,
|
|
27
29
|
isMultiTransform: BooleanNumber.TRUE,
|
|
28
30
|
transforms: drawing.transforms ?? (drawing.transform ? [drawing.transform] : null)
|
|
29
31
|
})) : drawings;
|
|
32
|
+
if (isFootnote) targetDrawings = drawings.map((drawing) => ({
|
|
33
|
+
...drawing,
|
|
34
|
+
layoutType: PositionedObjectLayoutType.INLINE
|
|
35
|
+
}));
|
|
30
36
|
const actions = BuildTextUtils.drawing.add({
|
|
31
37
|
selection: resolvedTextRange,
|
|
32
38
|
documentDataModel,
|
|
@@ -37,6 +43,7 @@ const InsertDocDrawingCommand = {
|
|
|
37
43
|
id: RichTextEditingMutation.id,
|
|
38
44
|
params: {
|
|
39
45
|
unitId,
|
|
46
|
+
segmentId,
|
|
40
47
|
actions: [],
|
|
41
48
|
textRanges: []
|
|
42
49
|
}
|
|
@@ -60,7 +67,7 @@ function resolveDocDrawingInsertTextRange(accessor, unitId, textRange) {
|
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
//#endregion
|
|
63
|
-
//#region \0@oxc-project+runtime@0.
|
|
70
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
64
71
|
function _typeof(o) {
|
|
65
72
|
"@babel/helpers - typeof";
|
|
66
73
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -71,7 +78,7 @@ function _typeof(o) {
|
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
//#endregion
|
|
74
|
-
//#region \0@oxc-project+runtime@0.
|
|
81
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
75
82
|
function toPrimitive(t, r) {
|
|
76
83
|
if ("object" != _typeof(t) || !t) return t;
|
|
77
84
|
var e = t[Symbol.toPrimitive];
|
|
@@ -84,14 +91,14 @@ function toPrimitive(t, r) {
|
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
//#endregion
|
|
87
|
-
//#region \0@oxc-project+runtime@0.
|
|
94
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
88
95
|
function toPropertyKey(t) {
|
|
89
96
|
var i = toPrimitive(t, "string");
|
|
90
97
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
//#endregion
|
|
94
|
-
//#region \0@oxc-project+runtime@0.
|
|
101
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
95
102
|
function _defineProperty(e, r, t) {
|
|
96
103
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
97
104
|
value: t,
|
|
@@ -139,13 +146,60 @@ var DocDrawingAdapterService = class {
|
|
|
139
146
|
}
|
|
140
147
|
};
|
|
141
148
|
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/services/doc-drawing-source.ts
|
|
151
|
+
/** Resolve persisted drawing ownership independently of the current text selection. */
|
|
152
|
+
function findDocDrawing(snapshot, drawingId) {
|
|
153
|
+
var _snapshot$drawings;
|
|
154
|
+
const drawing = (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingId];
|
|
155
|
+
if (drawing) return {
|
|
156
|
+
drawing,
|
|
157
|
+
path: ["drawings", drawingId],
|
|
158
|
+
segmentId: ""
|
|
159
|
+
};
|
|
160
|
+
for (const [segmentId, note] of Object.entries(snapshot.notes ?? {})) {
|
|
161
|
+
var _note$drawings;
|
|
162
|
+
const drawing = (_note$drawings = note.drawings) === null || _note$drawings === void 0 ? void 0 : _note$drawings[drawingId];
|
|
163
|
+
if (drawing) return {
|
|
164
|
+
drawing,
|
|
165
|
+
path: [
|
|
166
|
+
"notes",
|
|
167
|
+
segmentId,
|
|
168
|
+
"drawings",
|
|
169
|
+
drawingId
|
|
170
|
+
],
|
|
171
|
+
segmentId
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** The render registry is flat; persisted note resources retain their own scope. */
|
|
176
|
+
function collectDocDrawings(snapshot) {
|
|
177
|
+
let drawings = snapshot.drawings ?? {};
|
|
178
|
+
let drawingsOrder = snapshot.drawingsOrder ?? Object.keys(drawings);
|
|
179
|
+
let copied = false;
|
|
180
|
+
for (const note of Object.values(snapshot.notes ?? {})) {
|
|
181
|
+
if (!note.drawings || Object.keys(note.drawings).length === 0) continue;
|
|
182
|
+
if (!copied) {
|
|
183
|
+
drawings = { ...drawings };
|
|
184
|
+
drawingsOrder = [...drawingsOrder];
|
|
185
|
+
copied = true;
|
|
186
|
+
}
|
|
187
|
+
Object.assign(drawings, note.drawings);
|
|
188
|
+
drawingsOrder.push(...note.drawingsOrder ?? Object.keys(note.drawings));
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
drawings,
|
|
192
|
+
drawingsOrder
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
142
196
|
//#endregion
|
|
143
197
|
//#region src/commands/commands/remove-doc-drawing.command.ts
|
|
144
198
|
const RemoveDocDrawingCommand = {
|
|
145
199
|
id: "doc.command.remove-doc-image",
|
|
146
200
|
type: CommandType.COMMAND,
|
|
147
201
|
handler: (accessor, params) => {
|
|
148
|
-
var _documentDataModel$ge;
|
|
202
|
+
var _snapshot$notes, _documentDataModel$ge;
|
|
149
203
|
if (!params) return false;
|
|
150
204
|
const commandService = accessor.get(ICommandService);
|
|
151
205
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -157,20 +211,34 @@ const RemoveDocDrawingCommand = {
|
|
|
157
211
|
if (!documentDataModel || removeDrawings.length === 0) return false;
|
|
158
212
|
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
159
213
|
const contentInsertRange = (!textRange ? null : normalizeTextRange(textRange)) ?? getContentInsertRange(accessor, unitId);
|
|
160
|
-
const
|
|
214
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
215
|
+
const noteSegments = removeDrawings.map(({ drawingId }) => {
|
|
216
|
+
var _findDocDrawing;
|
|
217
|
+
return ((_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.segmentId) ?? "";
|
|
218
|
+
});
|
|
219
|
+
if (noteSegments.some((id) => id !== noteSegments[0])) return false;
|
|
220
|
+
const segmentId = noteSegments[0] || ((contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? "");
|
|
221
|
+
const footnote = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
|
|
222
|
+
const source = footnote ?? snapshot;
|
|
223
|
+
const prefix = footnote ? ["notes", segmentId] : [];
|
|
161
224
|
const textX = new TextX();
|
|
162
225
|
const jsonX = JSONX.getInstance();
|
|
163
226
|
const customBlocks = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.customBlocks) ?? [];
|
|
164
227
|
const removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1);
|
|
165
228
|
if (removeCustomBlocks.length === 0) return false;
|
|
166
|
-
const drawings =
|
|
229
|
+
const drawings = source.drawings ?? {};
|
|
167
230
|
const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
|
|
168
|
-
const
|
|
231
|
+
const removeIds = new Set(removeCustomBlocks.map((block) => block.blockId));
|
|
232
|
+
let previousSize = -1;
|
|
233
|
+
while (previousSize !== removeIds.size) {
|
|
234
|
+
previousSize = removeIds.size;
|
|
235
|
+
for (const drawing of Object.values(drawings)) if (drawing.groupId && removeIds.has(drawing.groupId)) removeIds.add(drawing.drawingId);
|
|
236
|
+
}
|
|
237
|
+
const removeDrawingSnapshots = [...removeIds].map((id) => drawings[id]).filter((drawing) => drawing != null);
|
|
169
238
|
const resourceRedoMutations = [];
|
|
170
239
|
const resourceUndoMutations = [];
|
|
171
240
|
const resourceMutationGroups = [];
|
|
172
|
-
for (const
|
|
173
|
-
const { blockId } = block;
|
|
241
|
+
for (const blockId of removeIds) {
|
|
174
242
|
const drawing = drawings[blockId];
|
|
175
243
|
if (drawing == null) continue;
|
|
176
244
|
const removeDrawingParam = removeDrawingParamById.get(blockId);
|
|
@@ -203,12 +271,15 @@ const RemoveDocDrawingCommand = {
|
|
|
203
271
|
startOffset: cursorIndex,
|
|
204
272
|
endOffset: cursorIndex
|
|
205
273
|
}];
|
|
274
|
+
const historyActions = getHistoryActions(removeDrawings);
|
|
206
275
|
const doMutation = {
|
|
207
276
|
id: RichTextEditingMutation.id,
|
|
208
277
|
params: {
|
|
209
278
|
unitId,
|
|
279
|
+
segmentId,
|
|
210
280
|
actions: [],
|
|
211
|
-
textRanges
|
|
281
|
+
textRanges,
|
|
282
|
+
historyActions
|
|
212
283
|
}
|
|
213
284
|
};
|
|
214
285
|
const rawActions = [];
|
|
@@ -225,11 +296,20 @@ const RemoveDocDrawingCommand = {
|
|
|
225
296
|
memoryCursor.moveCursorTo(startIndex + 1);
|
|
226
297
|
}
|
|
227
298
|
rawActions.push(jsonX.editOp(textX.serialize(), getRichTextEditPath(documentDataModel, segmentId)));
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
rawActions.push(jsonX.removeOp([
|
|
299
|
+
const drawingOrder = source.drawingsOrder ?? [];
|
|
300
|
+
const resourceIds = [...removeIds].sort((left, right) => drawingOrder.indexOf(right) - drawingOrder.indexOf(left));
|
|
301
|
+
for (const blockId of resourceIds) {
|
|
302
|
+
const drawingIndex = drawingOrder.indexOf(blockId);
|
|
303
|
+
if (drawings[blockId]) rawActions.push(jsonX.removeOp([
|
|
304
|
+
...prefix,
|
|
305
|
+
"drawings",
|
|
306
|
+
blockId
|
|
307
|
+
], drawings[blockId]));
|
|
308
|
+
if (drawingIndex >= 0) rawActions.push(jsonX.removeOp([
|
|
309
|
+
...prefix,
|
|
310
|
+
"drawingsOrder",
|
|
311
|
+
drawingIndex
|
|
312
|
+
], blockId));
|
|
233
313
|
}
|
|
234
314
|
doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
235
315
|
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
@@ -242,6 +322,17 @@ const RemoveDocDrawingCommand = {
|
|
|
242
322
|
return Boolean(result);
|
|
243
323
|
}
|
|
244
324
|
};
|
|
325
|
+
function getHistoryActions(drawings) {
|
|
326
|
+
const historyActions = drawings.flatMap((drawing) => {
|
|
327
|
+
switch (drawing.drawingType) {
|
|
328
|
+
case DrawingTypeEnum.DRAWING_IMAGE: return [DocHistoryAction.DeleteImage];
|
|
329
|
+
case DrawingTypeEnum.DRAWING_SHAPE: return [DocHistoryAction.DeleteShape];
|
|
330
|
+
case DrawingTypeEnum.DRAWING_CHART: return [DocHistoryAction.DeleteChart];
|
|
331
|
+
default: return [];
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
return [...new Set(historyActions)];
|
|
335
|
+
}
|
|
245
336
|
function executeResourceMutationGroups(mutationGroups, commandService) {
|
|
246
337
|
const executedUndoGroups = [];
|
|
247
338
|
for (const mutationGroup of mutationGroups) {
|
|
@@ -283,6 +374,16 @@ function getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType) {
|
|
|
283
374
|
}
|
|
284
375
|
return arrangedDrawingOrder;
|
|
285
376
|
}
|
|
377
|
+
function getDrawingOrderAtIndex(drawingOrder, drawingIds, zOrder) {
|
|
378
|
+
if (drawingIds.length !== 1) return [...drawingOrder];
|
|
379
|
+
const arrangedDrawingOrder = [...drawingOrder];
|
|
380
|
+
const currentIndex = arrangedDrawingOrder.indexOf(drawingIds[0]);
|
|
381
|
+
if (currentIndex < 0) return arrangedDrawingOrder;
|
|
382
|
+
const [drawingId] = arrangedDrawingOrder.splice(currentIndex, 1);
|
|
383
|
+
const targetIndex = normalizeDrawingOrderIndex(zOrder, drawingOrder.length);
|
|
384
|
+
arrangedDrawingOrder.splice(targetIndex, 0, drawingId);
|
|
385
|
+
return arrangedDrawingOrder;
|
|
386
|
+
}
|
|
286
387
|
/**
|
|
287
388
|
* Converts the target order into granular JSONX move operations. This avoids replacing
|
|
288
389
|
* the entire drawingsOrder array and keeps collaboration conflicts scoped to moved items.
|
|
@@ -311,11 +412,11 @@ const SetDocDrawingArrangeCommand = {
|
|
|
311
412
|
handler: (accessor, params) => {
|
|
312
413
|
const commandService = accessor.get(ICommandService);
|
|
313
414
|
if (params == null) return false;
|
|
314
|
-
const { unitId, drawingIds
|
|
415
|
+
const { unitId, drawingIds } = params;
|
|
315
416
|
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
316
417
|
const drawingOrder = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDrawingsOrder();
|
|
317
418
|
if (!drawingOrder) return false;
|
|
318
|
-
const actions = createDrawingOrderActions(drawingOrder, getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType));
|
|
419
|
+
const actions = createDrawingOrderActions(drawingOrder, params.zOrder !== void 0 ? getDrawingOrderAtIndex(drawingOrder, drawingIds, params.zOrder) : getArrangedDrawingOrder(drawingOrder, drawingIds, params.arrangeType));
|
|
319
420
|
if (JSONX.isNoop(actions)) return false;
|
|
320
421
|
const result = commandService.syncExecuteCommand(RichTextEditingMutation.id, {
|
|
321
422
|
unitId,
|
|
@@ -338,24 +439,33 @@ const UpdateDrawingDocTransformCommand = {
|
|
|
338
439
|
const { unitId, drawings } = params;
|
|
339
440
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
340
441
|
if (!documentDataModel) return false;
|
|
341
|
-
const
|
|
442
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
443
|
+
const historyAction = drawings.length > 0 && drawings.every(({ drawingId }) => {
|
|
444
|
+
var _findDocDrawing;
|
|
445
|
+
return ((_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing.drawingType) === DrawingTypeEnum.DRAWING_IMAGE;
|
|
446
|
+
}) ? DocHistoryAction.UpdateImage : void 0;
|
|
342
447
|
const jsonX = JSONX.getInstance();
|
|
343
448
|
const actions = [];
|
|
344
449
|
for (const { drawingId, key, value } of drawings) {
|
|
345
|
-
var
|
|
346
|
-
const
|
|
450
|
+
var _oldDrawing$docTransf;
|
|
451
|
+
const source = findDocDrawing(snapshot, drawingId);
|
|
452
|
+
if (!source) return false;
|
|
453
|
+
const oldDrawing = source.drawing;
|
|
454
|
+
const isImageProperty = key === "srcRect" || key === "prstGeom" || key === "adjustValues";
|
|
455
|
+
const oldValue = isImageProperty ? key in oldDrawing ? Reflect.get(oldDrawing, key) : void 0 : oldDrawing === null || oldDrawing === void 0 || (_oldDrawing$docTransf = oldDrawing.docTransform) === null || _oldDrawing$docTransf === void 0 ? void 0 : _oldDrawing$docTransf[key];
|
|
347
456
|
if (!Tools.diffValue(oldValue, value)) {
|
|
348
|
-
const path = [
|
|
349
|
-
|
|
350
|
-
drawingId,
|
|
457
|
+
const path = isImageProperty ? [...source.path, key] : [
|
|
458
|
+
...source.path,
|
|
351
459
|
"docTransform",
|
|
352
460
|
key
|
|
353
461
|
];
|
|
354
|
-
|
|
462
|
+
const action = oldValue === void 0 ? jsonX.insertOp(path, value) : jsonX.replaceOp(path, oldValue, value);
|
|
463
|
+
actions.push(action);
|
|
355
464
|
}
|
|
356
465
|
}
|
|
357
466
|
return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
|
|
358
467
|
unitId,
|
|
468
|
+
historyAction,
|
|
359
469
|
actions: actions.reduce((acc, action) => JSONX.compose(acc, action), null),
|
|
360
470
|
textRanges: null,
|
|
361
471
|
debounce: true
|
|
@@ -424,33 +534,33 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
424
534
|
const commandService = accessor.get(ICommandService);
|
|
425
535
|
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
426
536
|
if (!documentDataModel) return false;
|
|
427
|
-
const
|
|
537
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
538
|
+
if (wrappingStyle !== "inline" && drawings.some(({ drawingId }) => {
|
|
539
|
+
var _findDocDrawing;
|
|
540
|
+
return (_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.segmentId;
|
|
541
|
+
})) return false;
|
|
542
|
+
const historyAction = drawings.length > 0 && drawings.every(({ drawingId }) => {
|
|
543
|
+
var _findDocDrawing2;
|
|
544
|
+
return ((_findDocDrawing2 = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing2 === void 0 ? void 0 : _findDocDrawing2.drawing.drawingType) === DrawingTypeEnum.DRAWING_IMAGE;
|
|
545
|
+
}) ? DocHistoryAction.UpdateImage : void 0;
|
|
428
546
|
const jsonX = JSONX.getInstance();
|
|
429
547
|
const rawActions = [];
|
|
430
548
|
for (const drawing of drawings) {
|
|
431
|
-
const
|
|
432
|
-
|
|
549
|
+
const source = findDocDrawing(snapshot, drawing.drawingId);
|
|
550
|
+
const oldDrawing = source === null || source === void 0 ? void 0 : source.drawing;
|
|
551
|
+
if (!oldDrawing || !source) continue;
|
|
433
552
|
const layoutType = WRAPPING_STYLE_TO_LAYOUT_TYPE[wrappingStyle];
|
|
434
|
-
if (oldDrawing.layoutType !== layoutType) rawActions.push(jsonX.replaceOp([
|
|
435
|
-
"drawings",
|
|
436
|
-
drawing.drawingId,
|
|
437
|
-
"layoutType"
|
|
438
|
-
], oldDrawing.layoutType, layoutType));
|
|
553
|
+
if (oldDrawing.layoutType !== layoutType) rawActions.push(jsonX.replaceOp([...source.path, "layoutType"], oldDrawing.layoutType, layoutType));
|
|
439
554
|
if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
|
|
440
555
|
const behindDoc = wrappingStyle === "behindText" ? BooleanNumber.TRUE : BooleanNumber.FALSE;
|
|
441
|
-
if (oldDrawing.behindDoc !== behindDoc) rawActions.push(jsonX.replaceOp([
|
|
442
|
-
"drawings",
|
|
443
|
-
drawing.drawingId,
|
|
444
|
-
"behindDoc"
|
|
445
|
-
], oldDrawing.behindDoc, behindDoc));
|
|
556
|
+
if (oldDrawing.behindDoc !== behindDoc) rawActions.push(jsonX.replaceOp([...source.path, "behindDoc"], oldDrawing.behindDoc, behindDoc));
|
|
446
557
|
}
|
|
447
558
|
if (wrappingStyle !== "inline") for (const key of ["positionH", "positionV"]) {
|
|
448
559
|
var _drawing$docTransform;
|
|
449
560
|
const value = (_drawing$docTransform = drawing.docTransform) === null || _drawing$docTransform === void 0 ? void 0 : _drawing$docTransform[key];
|
|
450
561
|
const oldValue = oldDrawing.docTransform[key];
|
|
451
562
|
if (value && !Tools.diffValue(oldValue, value)) rawActions.push(jsonX.replaceOp([
|
|
452
|
-
|
|
453
|
-
drawing.drawingId,
|
|
563
|
+
...source.path,
|
|
454
564
|
"docTransform",
|
|
455
565
|
key
|
|
456
566
|
], oldValue, value));
|
|
@@ -460,6 +570,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
460
570
|
id: RichTextEditingMutation.id,
|
|
461
571
|
params: {
|
|
462
572
|
unitId,
|
|
573
|
+
historyAction,
|
|
463
574
|
actions: rawActions.reduce((actions, action) => JSONX.compose(actions, action), null),
|
|
464
575
|
textRanges: null
|
|
465
576
|
}
|
|
@@ -474,7 +585,7 @@ var DocDrawingService = class extends UnitDrawingService {};
|
|
|
474
585
|
const IDocDrawingService = createIdentifier("univer.doc.plugin.doc-drawing.service");
|
|
475
586
|
|
|
476
587
|
//#endregion
|
|
477
|
-
//#region \0@oxc-project+runtime@0.
|
|
588
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
478
589
|
function __decorateParam(paramIndex, decorator) {
|
|
479
590
|
return function(target, key) {
|
|
480
591
|
decorator(target, key, paramIndex);
|
|
@@ -482,7 +593,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
482
593
|
}
|
|
483
594
|
|
|
484
595
|
//#endregion
|
|
485
|
-
//#region \0@oxc-project+runtime@0.
|
|
596
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
486
597
|
function __decorate(decorators, target, key, desc) {
|
|
487
598
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
488
599
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -540,7 +651,7 @@ let DocDrawingController = class DocDrawingController extends Disposable {
|
|
|
540
651
|
};
|
|
541
652
|
try {
|
|
542
653
|
return JSON.parse(json);
|
|
543
|
-
} catch
|
|
654
|
+
} catch {
|
|
544
655
|
return {
|
|
545
656
|
data: {},
|
|
546
657
|
order: []
|
|
@@ -553,10 +664,7 @@ let DocDrawingController = class DocDrawingController extends Disposable {
|
|
|
553
664
|
toJson: (unitId) => toJson(unitId),
|
|
554
665
|
parseJson: (json) => parseJson(json),
|
|
555
666
|
onUnLoad: (unitId) => {
|
|
556
|
-
this.
|
|
557
|
-
data: {},
|
|
558
|
-
order: []
|
|
559
|
-
});
|
|
667
|
+
this._unloadDrawingDataForUnit(unitId);
|
|
560
668
|
},
|
|
561
669
|
onLoad: (unitId, value) => {
|
|
562
670
|
this._setDrawingDataForUnit(unitId, {
|
|
@@ -566,6 +674,12 @@ let DocDrawingController = class DocDrawingController extends Disposable {
|
|
|
566
674
|
}
|
|
567
675
|
}));
|
|
568
676
|
}
|
|
677
|
+
_unloadDrawingDataForUnit(unitId) {
|
|
678
|
+
const documentDataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
679
|
+
documentDataModel === null || documentDataModel === void 0 || documentDataModel.resetDrawing({}, []);
|
|
680
|
+
this._docDrawingService.removeDrawingDataForUnit(unitId);
|
|
681
|
+
this._drawingManagerService.removeDrawingDataForUnit(unitId);
|
|
682
|
+
}
|
|
569
683
|
_setDrawingDataForUnit(unitId, drawingMapItem) {
|
|
570
684
|
const documentDataModel = this._univerInstanceService.getUnit(unitId);
|
|
571
685
|
if (documentDataModel == null) return;
|
|
@@ -576,17 +690,28 @@ let DocDrawingController = class DocDrawingController extends Disposable {
|
|
|
576
690
|
const dataModel = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
577
691
|
if (!dataModel) return false;
|
|
578
692
|
const subUnitId = unitId;
|
|
579
|
-
const drawingDataModels = dataModel.
|
|
580
|
-
const drawingOrderModel = dataModel.getDrawingsOrder();
|
|
693
|
+
const { drawings: drawingDataModels, drawingsOrder: drawingOrderModel } = collectDocDrawings(dataModel.getSnapshot());
|
|
581
694
|
if (!drawingDataModels || !drawingOrderModel) return false;
|
|
695
|
+
const normalizedDrawingData = {};
|
|
696
|
+
for (const [drawingId, drawing] of Object.entries(drawingDataModels)) normalizedDrawingData[drawingId] = drawing.unitId === unitId && drawing.subUnitId === subUnitId ? drawing : {
|
|
697
|
+
...drawing,
|
|
698
|
+
unitId,
|
|
699
|
+
subUnitId
|
|
700
|
+
};
|
|
582
701
|
const subDrawings = { [subUnitId]: {
|
|
583
702
|
unitId,
|
|
584
703
|
subUnitId,
|
|
585
|
-
data:
|
|
704
|
+
data: normalizedDrawingData,
|
|
586
705
|
order: drawingOrderModel
|
|
587
706
|
} };
|
|
707
|
+
const renderDrawingData = {};
|
|
708
|
+
for (const [drawingId, drawing] of Object.entries(normalizedDrawingData)) renderDrawingData[drawingId] = {
|
|
709
|
+
...drawing,
|
|
710
|
+
hidden: true
|
|
711
|
+
};
|
|
588
712
|
const renderSubDrawings = { [subUnitId]: {
|
|
589
713
|
...subDrawings[subUnitId],
|
|
714
|
+
data: renderDrawingData,
|
|
590
715
|
order: getDocDrawingRenderOrder(drawingOrderModel, drawingDataModels)
|
|
591
716
|
} };
|
|
592
717
|
this._docDrawingService.registerDrawingData(unitId, subDrawings);
|
|
@@ -614,7 +739,7 @@ DocDrawingController = __decorate([
|
|
|
614
739
|
//#endregion
|
|
615
740
|
//#region package.json
|
|
616
741
|
var name = "@univerjs/docs-drawing";
|
|
617
|
-
var version = "1.0.0
|
|
742
|
+
var version = "1.0.0";
|
|
618
743
|
|
|
619
744
|
//#endregion
|
|
620
745
|
//#region src/config/config.ts
|
|
@@ -670,4 +795,4 @@ UniverDocsDrawingPlugin = __decorate([
|
|
|
670
795
|
], UniverDocsDrawingPlugin);
|
|
671
796
|
|
|
672
797
|
//#endregion
|
|
673
|
-
export { DOCS_DRAWING_PLUGIN, DocDrawingAdapterService, DocDrawingController, DocDrawingService, IDocDrawingAdapterService, IDocDrawingService, InsertDocDrawingCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, TextWrappingStyle, UniverDocsDrawingPlugin, UpdateDocDrawingWrappingStyleCommand, UpdateDrawingDocTransformCommand, WRAPPING_STYLE_TO_LAYOUT_TYPE, getDocDrawingRenderOrder };
|
|
798
|
+
export { DOCS_DRAWING_PLUGIN, DocDrawingAdapterService, DocDrawingController, DocDrawingService, IDocDrawingAdapterService, IDocDrawingService, InsertDocDrawingCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, TextWrappingStyle, UniverDocsDrawingPlugin, UpdateDocDrawingWrappingStyleCommand, UpdateDrawingDocTransformCommand, WRAPPING_STYLE_TO_LAYOUT_TYPE, collectDocDrawings, findDocDrawing, getDocDrawingRenderOrder };
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type {
|
|
16
|
+
import type { ICommand, ITextRangeParam } from '@univerjs/core';
|
|
17
|
+
import { DrawingTypeEnum } from '@univerjs/core';
|
|
17
18
|
export interface IRemoveDocDrawingCommandParam {
|
|
18
19
|
unitId: string;
|
|
19
20
|
subUnitId: string;
|
|
@@ -16,9 +16,13 @@
|
|
|
16
16
|
import type { ICommand } from '@univerjs/core';
|
|
17
17
|
import type { IDrawingOrderMapParam } from '@univerjs/drawing';
|
|
18
18
|
import { ArrangeTypeEnum } from '@univerjs/core';
|
|
19
|
-
export
|
|
19
|
+
export type ISetDocDrawingArrangeCommandParams = IDrawingOrderMapParam & ({
|
|
20
20
|
arrangeType: ArrangeTypeEnum;
|
|
21
|
-
|
|
21
|
+
zOrder?: never;
|
|
22
|
+
} | {
|
|
23
|
+
arrangeType?: never;
|
|
24
|
+
zOrder: number;
|
|
25
|
+
});
|
|
22
26
|
/**
|
|
23
27
|
* The command to arrange drawings.
|
|
24
28
|
*/
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { ICommand, IObjectPositionH, IObjectPositionV, ISize } from '@univerjs/core';
|
|
16
|
+
import type { ICommand, IObjectPositionH, IObjectPositionV, ISize, ISrcRect, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { IDocImage } from '../../services/doc-drawing.service';
|
|
17
18
|
export interface IDrawingDocTransform {
|
|
18
19
|
drawingId: string;
|
|
19
|
-
key: 'size' | 'angle' | 'positionH' | 'positionV' | 'flipX' | 'flipY';
|
|
20
|
-
value: ISize | number | boolean | IObjectPositionH | IObjectPositionV;
|
|
20
|
+
key: 'size' | 'angle' | 'positionH' | 'positionV' | 'flipX' | 'flipY' | 'srcRect' | 'prstGeom' | 'adjustValues';
|
|
21
|
+
value: ISize | number | boolean | IObjectPositionH | IObjectPositionV | Nullable<ISrcRect> | IDocImage['prstGeom'] | IDocImage['adjustValues'];
|
|
21
22
|
}
|
|
22
23
|
export interface IUpdateDrawingDocTransformCommandParams {
|
|
23
24
|
unitId: string;
|
|
@@ -16,12 +16,6 @@
|
|
|
16
16
|
import type { ICommand } from '@univerjs/core';
|
|
17
17
|
import type { IDocDrawing } from '../../services/doc-drawing.service';
|
|
18
18
|
import { PositionedObjectLayoutType } from '@univerjs/core';
|
|
19
|
-
/**
|
|
20
|
-
* Controls how a document drawing participates in text layout.
|
|
21
|
-
*
|
|
22
|
-
* `INLINE`, `WRAP_SQUARE`, and `WRAP_TOP_AND_BOTTOM` participate in text layout and can cause text to reflow.
|
|
23
|
-
* `BEHIND_TEXT` and `IN_FRONT_OF_TEXT` are overlay styles and do not cause text to reflow.
|
|
24
|
-
*/
|
|
25
19
|
export declare enum TextWrappingStyle {
|
|
26
20
|
/**
|
|
27
21
|
* Places the drawing in the text flow like a character.
|
|
@@ -32,6 +32,7 @@ export declare class DocDrawingController extends Disposable {
|
|
|
32
32
|
constructor(_docDrawingService: IDocDrawingService, _drawingManagerService: IDrawingManagerService, _resourceManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService);
|
|
33
33
|
private _init;
|
|
34
34
|
private _initSnapshot;
|
|
35
|
+
private _unloadDrawingDataForUnit;
|
|
35
36
|
private _setDrawingDataForUnit;
|
|
36
37
|
loadDrawingDataForUnit(unitId: string): boolean;
|
|
37
38
|
private _initCommands;
|
|
@@ -16,14 +16,15 @@
|
|
|
16
16
|
import type { ImageSourceType, Injector, IObjectPositionH, IObjectPositionV, ISize } from '@univerjs/core';
|
|
17
17
|
import type { IDocImage, TextWrappingStyle } from '@univerjs/docs-drawing';
|
|
18
18
|
import type { FDocument } from '@univerjs/docs/facade';
|
|
19
|
+
import { FBase } from '@univerjs/core/facade';
|
|
19
20
|
/**
|
|
20
21
|
* Facade API for an image in a document.
|
|
21
22
|
* @hideconstructor
|
|
22
23
|
*/
|
|
23
|
-
export declare class FDocumentImage {
|
|
24
|
+
export declare class FDocumentImage extends FBase {
|
|
24
25
|
private readonly _document;
|
|
25
26
|
private readonly _imageId;
|
|
26
|
-
|
|
27
|
+
protected readonly _injector: Injector;
|
|
27
28
|
constructor(_document: FDocument, _imageId: string, _injector: Injector);
|
|
28
29
|
/**
|
|
29
30
|
* Gets the id of the document containing the image.
|
package/lib/types/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { DocDrawingController } from './controllers/doc-drawing.controller';
|
|
|
30
30
|
export { UniverDocsDrawingPlugin } from './plugin';
|
|
31
31
|
export { DocDrawingAdapterService, IDocDrawingAdapterService } from './services/doc-drawing-adapter.service';
|
|
32
32
|
export type { IDocDrawingAdapter, IDocDrawingMutationInfos, IDocDrawingRemoveMutationInfoParams, } from './services/doc-drawing-adapter.service';
|
|
33
|
+
export { collectDocDrawings, findDocDrawing } from './services/doc-drawing-source';
|
|
33
34
|
export { DocDrawingService, IDocDrawingService } from './services/doc-drawing.service';
|
|
34
35
|
export type { IDocDrawing, IDocImage } from './services/doc-drawing.service';
|
|
35
36
|
export { type IDocFloatDom } from './services/doc-drawing.service';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IDocumentData, IDrawings } from '@univerjs/core';
|
|
17
|
+
/** Resolve persisted drawing ownership independently of the current text selection. */
|
|
18
|
+
export declare function findDocDrawing(snapshot: IDocumentData, drawingId: string): {
|
|
19
|
+
drawing: IDrawings[string];
|
|
20
|
+
path: string[];
|
|
21
|
+
segmentId: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
/** The render registry is flat; persisted note resources retain their own scope. */
|
|
24
|
+
export declare function collectDocDrawings(snapshot: IDocumentData): {
|
|
25
|
+
drawings: IDrawings;
|
|
26
|
+
drawingsOrder: string[];
|
|
27
|
+
};
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-drawing"),require("@univerjs/docs/facade"),require("@univerjs/drawing"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-drawing`,`@univerjs/docs/facade`,`@univerjs/drawing`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsDrawingFacade={},e.UniverCore,e.UniverDocs,e.UniverDocsDrawing,e.UniverDocsFacade,e.UniverDrawing,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=class{constructor(e,t,n){this._document=e,this._imageId=t,this._injector=n}getUnitId(){return this._document.getId()}getId(){return this._imageId}getSource(){var e;return(e=this.getImageData())==null?void 0:e.source}getSourceType(){var e;return(e=this.getImageData())==null?void 0:e.imageSourceType}getSize(){var e;return((e=this.getImageData())==null?void 0:e.docTransform.size)??null}getAngle(){var e;return(e=this.getImageData())==null?void 0:e.docTransform.angle}getPositionH(){var e;return((e=this.getImageData())==null?void 0:e.docTransform.positionH)??null}getPositionV(){var e;return((e=this.getImageData())==null?void 0:e.docTransform.positionV)??null}getImageData(){var e;let n=(e=this._document.getDocumentDataModel().
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-drawing"),require("@univerjs/docs/facade"),require("@univerjs/drawing"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-drawing`,`@univerjs/docs/facade`,`@univerjs/drawing`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsDrawingFacade={},e.UniverCore,e.UniverDocs,e.UniverDocsDrawing,e.UniverDocsFacade,e.UniverDrawing,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=class extends o.FBase{constructor(e,t,n){super(),this._document=e,this._imageId=t,this._injector=n}getUnitId(){return this._document.getId()}getId(){return this._imageId}getSource(){var e;return(e=this.getImageData())==null?void 0:e.source}getSourceType(){var e;return(e=this.getImageData())==null?void 0:e.imageSourceType}getSize(){var e;return((e=this.getImageData())==null?void 0:e.docTransform.size)??null}getAngle(){var e;return(e=this.getImageData())==null?void 0:e.docTransform.angle}getPositionH(){var e;return((e=this.getImageData())==null?void 0:e.docTransform.positionH)??null}getPositionV(){var e;return((e=this.getImageData())==null?void 0:e.docTransform.positionV)??null}getImageData(){var e;let n=(e=(0,r.findDocDrawing)(this._document.getDocumentDataModel().getSnapshot(),this._imageId))==null?void 0:e.drawing;return!n||n.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE?null:n}setSize(e,t){return this._updateTransform(`size`,{width:e,height:t})}setRotate(e){return this._updateTransform(`angle`,e)}setPositionH(e){return this._updateTransform(`positionH`,e)}setPositionV(e){return this._updateTransform(`positionV`,e)}setWrappingStyle(e){let n=this.getImageData();return n?this._injector.get(t.ICommandService).syncExecuteCommand(r.UpdateDocDrawingWrappingStyleCommand.id,{unitId:this.getUnitId(),subUnitId:this.getUnitId(),drawings:[n],wrappingStyle:e}):!1}setForward(){return this._arrange(t.ArrangeTypeEnum.forward)}setBackward(){return this._arrange(t.ArrangeTypeEnum.backward)}setBack(){return this._arrange(t.ArrangeTypeEnum.back)}setFront(){return this._arrange(t.ArrangeTypeEnum.front)}remove(){let e=this.getImageData(),n=this._getTextRange();return!e||!n?!1:this._injector.get(t.ICommandService).syncExecuteCommand(r.RemoveDocDrawingCommand.id,{unitId:this.getUnitId(),drawings:[{unitId:this.getUnitId(),subUnitId:this.getUnitId(),drawingId:this._imageId,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE}],textRange:n})}_updateTransform(e,n){return this._injector.get(t.ICommandService).syncExecuteCommand(r.UpdateDrawingDocTransformCommand.id,{unitId:this.getUnitId(),subUnitId:this.getUnitId(),drawings:[{drawingId:this._imageId,key:e,value:n}]})}_arrange(e){return this._injector.get(t.ICommandService).syncExecuteCommand(r.SetDocDrawingArrangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getUnitId(),drawingIds:[this._imageId],arrangeType:e})}_getTextRange(){let{body:e,headers:t={},footers:n={},notes:r={}}=this._document.getDocumentDataModel().getSnapshot(),i=[{segmentId:``,body:e},...Object.entries(t).map(([e,t])=>({segmentId:e,body:t.body})),...Object.entries(n).map(([e,t])=>({segmentId:e,body:t.body})),...Object.entries(r).map(([e,t])=>({segmentId:e,body:t.body}))];for(let{segmentId:e,body:t}of i){var a;let n=t==null||(a=t.customBlocks)==null?void 0:a.find(e=>e.blockId===this._imageId);if(n)return{startOffset:n.startIndex,endOffset:n.startIndex,collapsed:!0,segmentId:e}}return null}},c=class extends i.FDocument{async insertImage(e){let i=this.getId(),a=(0,t.generateRandomId)(6),o=e.width!=null&&e.height!=null?{width:e.width,height:e.height}:l(await this._getIntrinsicSize(e.source,e.imageSourceType),e),c=(0,n.buildDocTransform)(o.width,o.height),u=e.wrappingStyle??r.TextWrappingStyle.INLINE,d={...c,angle:e.angle??c.angle,positionH:e.positionH??c.positionH,positionV:e.positionV??c.positionV},f=(0,n.docDrawingPositionToTransform)(d),p={unitId:i,subUnitId:i,drawingId:a,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:e.imageSourceType,source:e.source,transform:f,docTransform:d,behindDoc:u===r.TextWrappingStyle.BEHIND_TEXT?t.BooleanNumber.TRUE:t.BooleanNumber.FALSE,title:``,description:``,layoutType:r.WRAPPING_STYLE_TO_LAYOUT_TYPE[u],wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0};return this._injector.get(t.ICommandService).syncExecuteCommand(r.InsertDocDrawingCommand.id,{unitId:i,drawings:[p],textRange:e.textRange})?this._injector.createInstance(s,this,a,this._injector):null}getImage(e){var n;let i=(n=(0,r.findDocDrawing)(this.getDocumentDataModel().getSnapshot(),e))==null?void 0:n.drawing;return!i||i.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE?null:this._injector.createInstance(s,this,e,this._injector)}getImages(){let e=this.getDocumentDataModel(),{drawings:n,drawingsOrder:i}=(0,r.collectDocDrawings)(e.getSnapshot());return i.filter(e=>{var r;return((r=n[e])==null?void 0:r.drawingType)===t.DrawingTypeEnum.DRAWING_IMAGE}).map(e=>this._injector.createInstance(s,this,e,this._injector))}async _getIntrinsicSize(e,n){let r=this._injector.has(t.IImageIoService)?this._injector.get(t.IImageIoService):null,i=e;if(n===t.ImageSourceType.UUID&&r)i=await r.getImage(e);else if(n===t.ImageSourceType.URL&&this._injector.has(t.IURLImageService))try{i=await this._injector.get(t.IURLImageService).getImage(e)}catch{i=e}let{width:o,height:s,image:c}=await(0,a.getImageSize)(i);return r==null||r.addImageSourceCache(e,n,c),{width:o,height:s}}};function l(e,t){let{width:n,height:r}=e;if(t.width!=null&&t.height!=null)return{width:t.width,height:t.height};if(t.width!=null)return{width:t.width,height:r*t.width/n};if(t.height!=null)return{width:n*t.height/r,height:t.height};let i=Math.min(1,a.DRAWING_IMAGE_WIDTH_LIMIT/n,a.DRAWING_IMAGE_HEIGHT_LIMIT/r);return{width:n*i,height:r*i}}i.FDocument.extend(c);var u=class extends o.FEnum{get TextWrappingStyle(){return r.TextWrappingStyle}get DocsImageRelativeFromH(){return t.ObjectRelativeFromH}get DocsImageRelativeFromV(){return t.ObjectRelativeFromV}};o.FEnum.extend(u),e.FDocumentImage=s});
|