@univerjs/docs-drawing 1.0.0-alpha.7 → 1.0.0-beta.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/lib/cjs/facade.js +24 -17
- package/lib/cjs/index.js +129 -136
- package/lib/es/facade.js +24 -17
- package/lib/es/index.js +132 -139
- package/lib/facade.js +24 -17
- package/lib/index.js +132 -139
- package/lib/types/commands/commands/update-doc-drawing-wrapping-style.command.d.ts +32 -0
- package/lib/types/facade/f-document-image.d.ts +7 -1
- package/lib/types/facade/f-document.d.ts +14 -2
- package/lib/types/facade/f-enum.d.ts +9 -4
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArrangeTypeEnum, BooleanNumber, BuildTextUtils, CommandType, Disposable, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSONX, MemoryCursor, Plugin, PositionedObjectLayoutType, TextX, TextXActionType, Tools, UniverInstanceType, createIdentifier,
|
|
2
|
-
import { DocSelectionManagerService, RichTextEditingMutation, getContentInsertRange, normalizeTextRange } from "@univerjs/docs";
|
|
3
|
-
import { IDrawingManagerService, UnitDrawingService } from "@univerjs/drawing";
|
|
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";
|
|
3
|
+
import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin } from "@univerjs/drawing";
|
|
4
4
|
|
|
5
5
|
//#region src/commands/commands/insert-doc-drawing.command.ts
|
|
6
6
|
/**
|
|
@@ -10,81 +10,29 @@ 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$headers, _snapshot$footers;
|
|
14
14
|
if (!params) return false;
|
|
15
15
|
const commandService = accessor.get(ICommandService);
|
|
16
16
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
17
17
|
const { unitId, drawings, textRange } = params;
|
|
18
18
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
19
19
|
if (!documentDataModel) return false;
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
if (!body) return false;
|
|
25
|
-
const textX = new TextX();
|
|
26
|
-
const jsonX = JSONX.getInstance();
|
|
27
|
-
const rawActions = [];
|
|
20
|
+
const resolvedTextRange = resolveDocDrawingInsertTextRange(accessor, unitId, textRange);
|
|
21
|
+
if (!resolvedTextRange) return false;
|
|
22
|
+
const { segmentId = "" } = resolvedTextRange;
|
|
23
|
+
if (!((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody())) return false;
|
|
28
24
|
const snapshot = documentDataModel.getSnapshot();
|
|
29
|
-
const 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) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let removeDrawingLen = 0;
|
|
39
|
-
if (collapsed) {
|
|
40
|
-
if (startOffset > 0) textX.push({
|
|
41
|
-
t: TextXActionType.RETAIN,
|
|
42
|
-
len: startOffset
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
var _documentDataModel$ge2, _documentDataModel$ge3;
|
|
46
|
-
const dos = BuildTextUtils.selection.delete([targetTextRange], body, 0, null, false);
|
|
47
|
-
textX.push(...dos);
|
|
48
|
-
const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [targetTextRange]);
|
|
49
|
-
const drawings = (_documentDataModel$ge2 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge2 !== void 0 ? _documentDataModel$ge2 : {};
|
|
50
|
-
const drawingOrder = (_documentDataModel$ge3 = documentDataModel.getDrawingsOrder()) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : [];
|
|
51
|
-
const sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => {
|
|
52
|
-
if (drawingOrder.indexOf(a) > drawingOrder.indexOf(b)) return -1;
|
|
53
|
-
else if (drawingOrder.indexOf(a) < drawingOrder.indexOf(b)) return 1;
|
|
54
|
-
return 0;
|
|
55
|
-
});
|
|
56
|
-
if (sortedRemovedCustomBlockIds.length > 0) for (const blockId of sortedRemovedCustomBlockIds) {
|
|
57
|
-
const drawing = drawings[blockId];
|
|
58
|
-
const drawingIndex = drawingOrder.indexOf(blockId);
|
|
59
|
-
if (drawing == null || drawingIndex < 0) continue;
|
|
60
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing);
|
|
61
|
-
const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
62
|
-
rawActions.push(removeDrawingAction);
|
|
63
|
-
rawActions.push(removeDrawingOrderAction);
|
|
64
|
-
removeDrawingLen++;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
textX.push({
|
|
68
|
-
t: TextXActionType.INSERT,
|
|
69
|
-
body: {
|
|
70
|
-
dataStream: "\b".repeat(targetDrawings.length),
|
|
71
|
-
customBlocks: targetDrawings.map((drawing, i) => ({
|
|
72
|
-
startIndex: i,
|
|
73
|
-
blockId: drawing.drawingId
|
|
74
|
-
}))
|
|
75
|
-
},
|
|
76
|
-
len: targetDrawings.length
|
|
25
|
+
const 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
|
+
...drawing,
|
|
27
|
+
isMultiTransform: BooleanNumber.TRUE,
|
|
28
|
+
transforms: drawing.transforms ?? (drawing.transform ? [drawing.transform] : null)
|
|
29
|
+
})) : drawings;
|
|
30
|
+
const actions = BuildTextUtils.drawing.add({
|
|
31
|
+
selection: resolvedTextRange,
|
|
32
|
+
documentDataModel,
|
|
33
|
+
drawings: targetDrawings
|
|
77
34
|
});
|
|
78
|
-
|
|
79
|
-
const placeHolderAction = jsonX.editOp(textX.serialize(), path);
|
|
80
|
-
rawActions.push(placeHolderAction);
|
|
81
|
-
for (const drawing of targetDrawings) {
|
|
82
|
-
const { drawingId } = drawing;
|
|
83
|
-
const addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing);
|
|
84
|
-
const addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
|
|
85
|
-
rawActions.push(addDrawingAction);
|
|
86
|
-
rawActions.push(addDrawingOrderAction);
|
|
87
|
-
}
|
|
35
|
+
if (!actions) return false;
|
|
88
36
|
const doMutation = {
|
|
89
37
|
id: RichTextEditingMutation.id,
|
|
90
38
|
params: {
|
|
@@ -93,30 +41,26 @@ const InsertDocDrawingCommand = {
|
|
|
93
41
|
textRanges: []
|
|
94
42
|
}
|
|
95
43
|
};
|
|
96
|
-
doMutation.params.actions =
|
|
97
|
-
return JSONX.compose(acc, cur);
|
|
98
|
-
}, null);
|
|
44
|
+
doMutation.params.actions = actions;
|
|
99
45
|
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
100
46
|
return Boolean(result);
|
|
101
47
|
}
|
|
102
48
|
};
|
|
103
49
|
function resolveDocDrawingInsertTextRange(accessor, unitId, textRange) {
|
|
104
|
-
var _ref, _contentInsertRange$s;
|
|
105
50
|
const activeTextRange = accessor.get(DocSelectionManagerService).getActiveTextRange();
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
if (!contentInsertRange) return activeTextRange !== null && activeTextRange !== void 0 ? activeTextRange : null;
|
|
51
|
+
const contentInsertRange = (textRange ? normalizeTextRange(textRange) : null) ?? getContentInsertRange(accessor, unitId);
|
|
52
|
+
if (!contentInsertRange) return activeTextRange ?? null;
|
|
109
53
|
return {
|
|
110
54
|
...activeTextRange,
|
|
111
55
|
startOffset: contentInsertRange.startOffset,
|
|
112
56
|
endOffset: contentInsertRange.endOffset,
|
|
113
57
|
collapsed: contentInsertRange.startOffset === contentInsertRange.endOffset,
|
|
114
|
-
segmentId:
|
|
58
|
+
segmentId: contentInsertRange.segmentId ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? ""
|
|
115
59
|
};
|
|
116
60
|
}
|
|
117
61
|
|
|
118
62
|
//#endregion
|
|
119
|
-
//#region \0@oxc-project+runtime@0.
|
|
63
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
|
|
120
64
|
function _typeof(o) {
|
|
121
65
|
"@babel/helpers - typeof";
|
|
122
66
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -127,7 +71,7 @@ function _typeof(o) {
|
|
|
127
71
|
}
|
|
128
72
|
|
|
129
73
|
//#endregion
|
|
130
|
-
//#region \0@oxc-project+runtime@0.
|
|
74
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
|
|
131
75
|
function toPrimitive(t, r) {
|
|
132
76
|
if ("object" != _typeof(t) || !t) return t;
|
|
133
77
|
var e = t[Symbol.toPrimitive];
|
|
@@ -140,14 +84,14 @@ function toPrimitive(t, r) {
|
|
|
140
84
|
}
|
|
141
85
|
|
|
142
86
|
//#endregion
|
|
143
|
-
//#region \0@oxc-project+runtime@0.
|
|
87
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
|
|
144
88
|
function toPropertyKey(t) {
|
|
145
89
|
var i = toPrimitive(t, "string");
|
|
146
90
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
147
91
|
}
|
|
148
92
|
|
|
149
93
|
//#endregion
|
|
150
|
-
//#region \0@oxc-project+runtime@0.
|
|
94
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
|
|
151
95
|
function _defineProperty(e, r, t) {
|
|
152
96
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
153
97
|
value: t,
|
|
@@ -201,7 +145,7 @@ const RemoveDocDrawingCommand = {
|
|
|
201
145
|
id: "doc.command.remove-doc-image",
|
|
202
146
|
type: CommandType.COMMAND,
|
|
203
147
|
handler: (accessor, params) => {
|
|
204
|
-
var
|
|
148
|
+
var _documentDataModel$ge;
|
|
205
149
|
if (!params) return false;
|
|
206
150
|
const commandService = accessor.get(ICommandService);
|
|
207
151
|
const undoRedoService = accessor.get(IUndoRedoService);
|
|
@@ -212,29 +156,27 @@ const RemoveDocDrawingCommand = {
|
|
|
212
156
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
213
157
|
if (!documentDataModel || removeDrawings.length === 0) return false;
|
|
214
158
|
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const segmentId = (_ref = (_contentInsertRange$s = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) !== null && _contentInsertRange$s !== void 0 ? _contentInsertRange$s : activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) !== null && _ref !== void 0 ? _ref : "";
|
|
159
|
+
const contentInsertRange = (!textRange ? null : normalizeTextRange(textRange)) ?? getContentInsertRange(accessor, unitId);
|
|
160
|
+
const segmentId = (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? "";
|
|
218
161
|
const textX = new TextX();
|
|
219
162
|
const jsonX = JSONX.getInstance();
|
|
220
|
-
const customBlocks = (_documentDataModel$ge =
|
|
163
|
+
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) ?? [];
|
|
221
164
|
const removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1);
|
|
222
165
|
if (removeCustomBlocks.length === 0) return false;
|
|
223
|
-
const drawings =
|
|
166
|
+
const drawings = documentDataModel.getDrawings() ?? {};
|
|
224
167
|
const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
|
|
225
168
|
const removeDrawingSnapshots = removeCustomBlocks.map((block) => drawings[block.blockId]).filter((drawing) => drawing != null);
|
|
226
169
|
const resourceRedoMutations = [];
|
|
227
170
|
const resourceUndoMutations = [];
|
|
228
171
|
const resourceMutationGroups = [];
|
|
229
172
|
for (const block of removeCustomBlocks) {
|
|
230
|
-
var _removeDrawingParam$s;
|
|
231
173
|
const { blockId } = block;
|
|
232
174
|
const drawing = drawings[blockId];
|
|
233
175
|
if (drawing == null) continue;
|
|
234
176
|
const removeDrawingParam = removeDrawingParamById.get(blockId);
|
|
235
177
|
const mutationInfos = drawingAdapterService.getRemoveDrawingMutationInfos({
|
|
236
178
|
unitId,
|
|
237
|
-
subUnitId: (
|
|
179
|
+
subUnitId: (removeDrawingParam === null || removeDrawingParam === void 0 ? void 0 : removeDrawingParam.subUnitId) ?? unitId,
|
|
238
180
|
drawing,
|
|
239
181
|
removeDrawings: removeDrawingSnapshots
|
|
240
182
|
});
|
|
@@ -319,13 +261,47 @@ function executeMutations(mutations, commandService) {
|
|
|
319
261
|
return true;
|
|
320
262
|
}
|
|
321
263
|
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/services/doc-drawing.service.ts
|
|
324
|
-
var DocDrawingService = class extends UnitDrawingService {};
|
|
325
|
-
const IDocDrawingService = createIdentifier("univer.doc.plugin.doc-drawing.service");
|
|
326
|
-
|
|
327
264
|
//#endregion
|
|
328
265
|
//#region src/commands/commands/set-drawing-arrange.command.ts
|
|
266
|
+
const DRAWINGS_ORDER_KEY = "drawingsOrder";
|
|
267
|
+
/**
|
|
268
|
+
* Calculates the target model order. Adjacent moves treat selected drawings as a group,
|
|
269
|
+
* so selected drawings keep their relative order instead of crossing each other.
|
|
270
|
+
*/
|
|
271
|
+
function getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType) {
|
|
272
|
+
const selectedDrawingIds = new Set(drawingIds.filter((drawingId) => drawingOrder.includes(drawingId)));
|
|
273
|
+
const arrangedDrawingOrder = [...drawingOrder];
|
|
274
|
+
if (selectedDrawingIds.size === 0) return arrangedDrawingOrder;
|
|
275
|
+
if (arrangeType === ArrangeTypeEnum.forward) {
|
|
276
|
+
for (let index = arrangedDrawingOrder.length - 2; index >= 0; index--) if (selectedDrawingIds.has(arrangedDrawingOrder[index]) && !selectedDrawingIds.has(arrangedDrawingOrder[index + 1])) [arrangedDrawingOrder[index], arrangedDrawingOrder[index + 1]] = [arrangedDrawingOrder[index + 1], arrangedDrawingOrder[index]];
|
|
277
|
+
} else if (arrangeType === ArrangeTypeEnum.backward) {
|
|
278
|
+
for (let index = 1; index < arrangedDrawingOrder.length; index++) if (selectedDrawingIds.has(arrangedDrawingOrder[index]) && !selectedDrawingIds.has(arrangedDrawingOrder[index - 1])) [arrangedDrawingOrder[index], arrangedDrawingOrder[index - 1]] = [arrangedDrawingOrder[index - 1], arrangedDrawingOrder[index]];
|
|
279
|
+
} else if (arrangeType === ArrangeTypeEnum.front || arrangeType === ArrangeTypeEnum.back) {
|
|
280
|
+
const selected = arrangedDrawingOrder.filter((drawingId) => selectedDrawingIds.has(drawingId));
|
|
281
|
+
const unselected = arrangedDrawingOrder.filter((drawingId) => !selectedDrawingIds.has(drawingId));
|
|
282
|
+
return arrangeType === ArrangeTypeEnum.front ? [...unselected, ...selected] : [...selected, ...unselected];
|
|
283
|
+
}
|
|
284
|
+
return arrangedDrawingOrder;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Converts the target order into granular JSONX move operations. This avoids replacing
|
|
288
|
+
* the entire drawingsOrder array and keeps collaboration conflicts scoped to moved items.
|
|
289
|
+
*/
|
|
290
|
+
function createDrawingOrderActions(drawingOrder, arrangedDrawingOrder) {
|
|
291
|
+
const jsonX = JSONX.getInstance();
|
|
292
|
+
const workingDrawingOrder = [...drawingOrder];
|
|
293
|
+
const rawActions = [];
|
|
294
|
+
for (let targetIndex = 0; targetIndex < arrangedDrawingOrder.length; targetIndex++) {
|
|
295
|
+
const drawingId = arrangedDrawingOrder[targetIndex];
|
|
296
|
+
const currentIndex = workingDrawingOrder.indexOf(drawingId);
|
|
297
|
+
if (currentIndex < 0 || currentIndex === targetIndex) continue;
|
|
298
|
+
const action = jsonX.moveOp([DRAWINGS_ORDER_KEY, currentIndex], [DRAWINGS_ORDER_KEY, targetIndex]);
|
|
299
|
+
if (action) rawActions.push(action);
|
|
300
|
+
workingDrawingOrder.splice(currentIndex, 1);
|
|
301
|
+
workingDrawingOrder.splice(targetIndex, 0, drawingId);
|
|
302
|
+
}
|
|
303
|
+
return rawActions.reduce((actions, action) => JSONX.compose(actions, action), null);
|
|
304
|
+
}
|
|
329
305
|
/**
|
|
330
306
|
* The command to arrange drawings.
|
|
331
307
|
*/
|
|
@@ -334,39 +310,18 @@ const SetDocDrawingArrangeCommand = {
|
|
|
334
310
|
type: CommandType.COMMAND,
|
|
335
311
|
handler: (accessor, params) => {
|
|
336
312
|
const commandService = accessor.get(ICommandService);
|
|
337
|
-
const docDrawingService = accessor.get(IDocDrawingService);
|
|
338
313
|
if (params == null) return false;
|
|
339
|
-
const { unitId,
|
|
340
|
-
const
|
|
314
|
+
const { unitId, drawingIds, arrangeType } = params;
|
|
315
|
+
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
316
|
+
const drawingOrder = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDrawingsOrder();
|
|
317
|
+
if (!drawingOrder) return false;
|
|
318
|
+
const actions = createDrawingOrderActions(drawingOrder, getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType));
|
|
319
|
+
if (JSONX.isNoop(actions)) return false;
|
|
320
|
+
const result = commandService.syncExecuteCommand(RichTextEditingMutation.id, {
|
|
341
321
|
unitId,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
};
|
|
345
|
-
let jsonOp;
|
|
346
|
-
if (arrangeType === ArrangeTypeEnum.forward) jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
|
|
347
|
-
else if (arrangeType === ArrangeTypeEnum.backward) jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
|
|
348
|
-
else if (arrangeType === ArrangeTypeEnum.front) jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
|
|
349
|
-
else if (arrangeType === ArrangeTypeEnum.back) jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam);
|
|
350
|
-
if (jsonOp == null) return false;
|
|
351
|
-
const { redo } = jsonOp;
|
|
352
|
-
if (redo == null) return false;
|
|
353
|
-
const rawActions = [];
|
|
354
|
-
let redoCopy = Tools.deepClone(redo);
|
|
355
|
-
redoCopy = redoCopy.slice(3);
|
|
356
|
-
redoCopy.unshift("drawingsOrder");
|
|
357
|
-
rawActions.push(redoCopy);
|
|
358
|
-
const doMutation = {
|
|
359
|
-
id: RichTextEditingMutation.id,
|
|
360
|
-
params: {
|
|
361
|
-
unitId,
|
|
362
|
-
actions: [],
|
|
363
|
-
textRanges: null
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
367
|
-
return JSONX.compose(acc, cur);
|
|
368
|
-
}, null);
|
|
369
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
322
|
+
actions,
|
|
323
|
+
textRanges: null
|
|
324
|
+
});
|
|
370
325
|
return Boolean(result);
|
|
371
326
|
}
|
|
372
327
|
};
|
|
@@ -377,14 +332,13 @@ const UpdateDrawingDocTransformCommand = {
|
|
|
377
332
|
id: "doc.command.update-drawing-doc-transform",
|
|
378
333
|
type: CommandType.COMMAND,
|
|
379
334
|
handler: (accessor, params) => {
|
|
380
|
-
var _documentDataModel$ge;
|
|
381
335
|
if (!params) return false;
|
|
382
336
|
const commandService = accessor.get(ICommandService);
|
|
383
337
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
384
338
|
const { unitId, drawings } = params;
|
|
385
339
|
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
386
340
|
if (!documentDataModel) return false;
|
|
387
|
-
const oldDrawings =
|
|
341
|
+
const oldDrawings = documentDataModel.getSnapshot().drawings ?? {};
|
|
388
342
|
const jsonX = JSONX.getInstance();
|
|
389
343
|
const actions = [];
|
|
390
344
|
for (const { drawingId, key, value } of drawings) {
|
|
@@ -411,11 +365,43 @@ const UpdateDrawingDocTransformCommand = {
|
|
|
411
365
|
|
|
412
366
|
//#endregion
|
|
413
367
|
//#region src/commands/commands/update-doc-drawing-wrapping-style.command.ts
|
|
368
|
+
/**
|
|
369
|
+
* Controls how a document drawing participates in text layout.
|
|
370
|
+
*
|
|
371
|
+
* `INLINE`, `WRAP_SQUARE`, and `WRAP_TOP_AND_BOTTOM` participate in text layout and can cause text to reflow.
|
|
372
|
+
* `BEHIND_TEXT` and `IN_FRONT_OF_TEXT` are overlay styles and do not cause text to reflow.
|
|
373
|
+
*/
|
|
414
374
|
let TextWrappingStyle = /* @__PURE__ */ function(TextWrappingStyle) {
|
|
375
|
+
/**
|
|
376
|
+
* Places the drawing in the text flow like a character.
|
|
377
|
+
*
|
|
378
|
+
* The drawing occupies layout space and does not overlap surrounding text. Its position is determined by its
|
|
379
|
+
* document range, so floating position settings have no visible effect.
|
|
380
|
+
*/
|
|
415
381
|
TextWrappingStyle["INLINE"] = "inline";
|
|
382
|
+
/**
|
|
383
|
+
* Floats the drawing behind document text without causing the text to reflow.
|
|
384
|
+
*
|
|
385
|
+
* Use this style for backgrounds or watermarks. Text can overlap the drawing, so ensure that it remains readable.
|
|
386
|
+
*/
|
|
416
387
|
TextWrappingStyle["BEHIND_TEXT"] = "behindText";
|
|
388
|
+
/**
|
|
389
|
+
* Floats the drawing in front of document text without causing the text to reflow.
|
|
390
|
+
*
|
|
391
|
+
* The drawing can cover overlapping text. Use this style only when an overlay is intentional.
|
|
392
|
+
*/
|
|
417
393
|
TextWrappingStyle["IN_FRONT_OF_TEXT"] = "inFrontOfText";
|
|
394
|
+
/**
|
|
395
|
+
* Floats the drawing and wraps text around its rectangular bounds.
|
|
396
|
+
*
|
|
397
|
+
* Use this style for images that should appear beside body text, such as portraits or illustrations.
|
|
398
|
+
*/
|
|
418
399
|
TextWrappingStyle["WRAP_SQUARE"] = "wrapSquare";
|
|
400
|
+
/**
|
|
401
|
+
* Floats the drawing in a horizontal band, with text only above and below it.
|
|
402
|
+
*
|
|
403
|
+
* Use this style for wide figures or standalone illustrations that should not have text beside them.
|
|
404
|
+
*/
|
|
419
405
|
TextWrappingStyle["WRAP_TOP_AND_BOTTOM"] = "wrapTopAndBottom";
|
|
420
406
|
return TextWrappingStyle;
|
|
421
407
|
}({});
|
|
@@ -433,13 +419,12 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
433
419
|
id: "doc.command.update-doc-drawing-wrapping-style",
|
|
434
420
|
type: CommandType.COMMAND,
|
|
435
421
|
handler: (accessor, params) => {
|
|
436
|
-
var _documentDataModel$ge;
|
|
437
422
|
if (!params) return false;
|
|
438
423
|
const { drawings, wrappingStyle, unitId } = params;
|
|
439
424
|
const commandService = accessor.get(ICommandService);
|
|
440
425
|
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
441
426
|
if (!documentDataModel) return false;
|
|
442
|
-
const oldDrawings =
|
|
427
|
+
const oldDrawings = documentDataModel.getDrawings() ?? {};
|
|
443
428
|
const jsonX = JSONX.getInstance();
|
|
444
429
|
const rawActions = [];
|
|
445
430
|
for (const drawing of drawings) {
|
|
@@ -484,7 +469,12 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
484
469
|
};
|
|
485
470
|
|
|
486
471
|
//#endregion
|
|
487
|
-
//#region
|
|
472
|
+
//#region src/services/doc-drawing.service.ts
|
|
473
|
+
var DocDrawingService = class extends UnitDrawingService {};
|
|
474
|
+
const IDocDrawingService = createIdentifier("univer.doc.plugin.doc-drawing.service");
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
|
|
488
478
|
function __decorateParam(paramIndex, decorator) {
|
|
489
479
|
return function(target, key) {
|
|
490
480
|
decorator(target, key, paramIndex);
|
|
@@ -492,7 +482,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
492
482
|
}
|
|
493
483
|
|
|
494
484
|
//#endregion
|
|
495
|
-
//#region \0@oxc-project+runtime@0.
|
|
485
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
|
|
496
486
|
function __decorate(decorators, target, key, desc) {
|
|
497
487
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
498
488
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -537,8 +527,8 @@ let DocDrawingController = class DocDrawingController extends Disposable {
|
|
|
537
527
|
const drawings = doc.getSnapshot().drawings;
|
|
538
528
|
const drawingOrder = doc.getSnapshot().drawingsOrder;
|
|
539
529
|
return JSON.stringify({
|
|
540
|
-
data: drawings
|
|
541
|
-
order: drawingOrder
|
|
530
|
+
data: drawings ?? {},
|
|
531
|
+
order: drawingOrder ?? []
|
|
542
532
|
});
|
|
543
533
|
}
|
|
544
534
|
return "";
|
|
@@ -569,10 +559,9 @@ let DocDrawingController = class DocDrawingController extends Disposable {
|
|
|
569
559
|
});
|
|
570
560
|
},
|
|
571
561
|
onLoad: (unitId, value) => {
|
|
572
|
-
var _value$data, _value$order;
|
|
573
562
|
this._setDrawingDataForUnit(unitId, {
|
|
574
|
-
data:
|
|
575
|
-
order:
|
|
563
|
+
data: value.data ?? {},
|
|
564
|
+
order: value.order ?? []
|
|
576
565
|
});
|
|
577
566
|
}
|
|
578
567
|
}));
|
|
@@ -625,7 +614,7 @@ DocDrawingController = __decorate([
|
|
|
625
614
|
//#endregion
|
|
626
615
|
//#region package.json
|
|
627
616
|
var name = "@univerjs/docs-drawing";
|
|
628
|
-
var version = "1.0.0-
|
|
617
|
+
var version = "1.0.0-beta.0";
|
|
629
618
|
|
|
630
619
|
//#endregion
|
|
631
620
|
//#region src/config/config.ts
|
|
@@ -674,7 +663,11 @@ _defineProperty(UniverDocsDrawingPlugin, "pluginName", DOCS_DRAWING_PLUGIN);
|
|
|
674
663
|
_defineProperty(UniverDocsDrawingPlugin, "packageName", name);
|
|
675
664
|
_defineProperty(UniverDocsDrawingPlugin, "version", version);
|
|
676
665
|
_defineProperty(UniverDocsDrawingPlugin, "type", UniverInstanceType.UNIVER_DOC);
|
|
677
|
-
UniverDocsDrawingPlugin = __decorate([
|
|
666
|
+
UniverDocsDrawingPlugin = __decorate([
|
|
667
|
+
DependentOn(UniverDocsPlugin, UniverDrawingPlugin),
|
|
668
|
+
__decorateParam(1, Inject(Injector)),
|
|
669
|
+
__decorateParam(2, IConfigService)
|
|
670
|
+
], UniverDocsDrawingPlugin);
|
|
678
671
|
|
|
679
672
|
//#endregion
|
|
680
673
|
export { DOCS_DRAWING_PLUGIN, DocDrawingAdapterService, DocDrawingController, DocDrawingService, IDocDrawingAdapterService, IDocDrawingService, InsertDocDrawingCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, TextWrappingStyle, UniverDocsDrawingPlugin, UpdateDocDrawingWrappingStyleCommand, UpdateDrawingDocTransformCommand, WRAPPING_STYLE_TO_LAYOUT_TYPE, getDocDrawingRenderOrder };
|
|
@@ -16,11 +16,43 @@
|
|
|
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
|
+
*/
|
|
19
25
|
export declare enum TextWrappingStyle {
|
|
26
|
+
/**
|
|
27
|
+
* Places the drawing in the text flow like a character.
|
|
28
|
+
*
|
|
29
|
+
* The drawing occupies layout space and does not overlap surrounding text. Its position is determined by its
|
|
30
|
+
* document range, so floating position settings have no visible effect.
|
|
31
|
+
*/
|
|
20
32
|
INLINE = "inline",
|
|
33
|
+
/**
|
|
34
|
+
* Floats the drawing behind document text without causing the text to reflow.
|
|
35
|
+
*
|
|
36
|
+
* Use this style for backgrounds or watermarks. Text can overlap the drawing, so ensure that it remains readable.
|
|
37
|
+
*/
|
|
21
38
|
BEHIND_TEXT = "behindText",
|
|
39
|
+
/**
|
|
40
|
+
* Floats the drawing in front of document text without causing the text to reflow.
|
|
41
|
+
*
|
|
42
|
+
* The drawing can cover overlapping text. Use this style only when an overlay is intentional.
|
|
43
|
+
*/
|
|
22
44
|
IN_FRONT_OF_TEXT = "inFrontOfText",
|
|
45
|
+
/**
|
|
46
|
+
* Floats the drawing and wraps text around its rectangular bounds.
|
|
47
|
+
*
|
|
48
|
+
* Use this style for images that should appear beside body text, such as portraits or illustrations.
|
|
49
|
+
*/
|
|
23
50
|
WRAP_SQUARE = "wrapSquare",
|
|
51
|
+
/**
|
|
52
|
+
* Floats the drawing in a horizontal band, with text only above and below it.
|
|
53
|
+
*
|
|
54
|
+
* Use this style for wide figures or standalone illustrations that should not have text beside them.
|
|
55
|
+
*/
|
|
24
56
|
WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom"
|
|
25
57
|
}
|
|
26
58
|
export declare const WRAPPING_STYLE_TO_LAYOUT_TYPE: Record<TextWrappingStyle, PositionedObjectLayoutType>;
|
|
@@ -228,6 +228,11 @@ export declare class FDocumentImage {
|
|
|
228
228
|
setPositionV(positionV: IObjectPositionV): boolean;
|
|
229
229
|
/**
|
|
230
230
|
* Sets the image wrapping style.
|
|
231
|
+
*
|
|
232
|
+
* Use `INLINE` to place the image in the text flow, `WRAP_SQUARE` to flow text beside it, or
|
|
233
|
+
* `WRAP_TOP_AND_BOTTOM` to keep text above and below it. `BEHIND_TEXT` and `IN_FRONT_OF_TEXT` do not reserve space
|
|
234
|
+
* in the text layout and can overlap text.
|
|
235
|
+
*
|
|
231
236
|
* When switching from inline to a floating style in a UI environment, the current visual position is preserved.
|
|
232
237
|
* @param {TextWrappingStyle} wrappingStyle The wrapping style to apply.
|
|
233
238
|
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
@@ -237,7 +242,8 @@ export declare class FDocumentImage {
|
|
|
237
242
|
* const image = fDocument.getImages()[0];
|
|
238
243
|
*
|
|
239
244
|
* if (image) {
|
|
240
|
-
*
|
|
245
|
+
* // Float the image beside body text without covering it.
|
|
246
|
+
* const success = image.setWrappingStyle(univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE);
|
|
241
247
|
* console.log(success);
|
|
242
248
|
* }
|
|
243
249
|
* ```
|
|
@@ -40,7 +40,13 @@ export interface IFDocumentInsertImageOptions {
|
|
|
40
40
|
* It has a visible positioning effect only when `wrappingStyle` is not `INLINE`.
|
|
41
41
|
*/
|
|
42
42
|
positionV?: IObjectPositionV;
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* The image wrapping style. Defaults to `TextWrappingStyle.INLINE`.
|
|
45
|
+
*
|
|
46
|
+
* Use `INLINE` to place the image in the text flow, `WRAP_SQUARE` to flow text beside it, or
|
|
47
|
+
* `WRAP_TOP_AND_BOTTOM` to keep text above and below it. `BEHIND_TEXT` and `IN_FRONT_OF_TEXT` are overlay styles:
|
|
48
|
+
* they do not reserve space in the text layout, so text and the image can overlap.
|
|
49
|
+
*/
|
|
44
50
|
wrappingStyle?: TextWrappingStyle;
|
|
45
51
|
/** The document range at which to insert the image. The current selection is used when omitted. */
|
|
46
52
|
textRange?: ITextRangeParam;
|
|
@@ -51,6 +57,9 @@ export interface IFDocumentImageMixin {
|
|
|
51
57
|
* Inserts an image into the document.
|
|
52
58
|
*
|
|
53
59
|
* When width and height are both omitted, the intrinsic size is proportionally limited to 500 by 500 pixels.
|
|
60
|
+
* For ordinary content, prefer `INLINE`, `WRAP_SQUARE`, or `WRAP_TOP_AND_BOTTOM`. Use `BEHIND_TEXT` for
|
|
61
|
+
* backgrounds or watermarks and `IN_FRONT_OF_TEXT` only for intentional overlays, because these two styles do not
|
|
62
|
+
* cause text to reflow.
|
|
54
63
|
*
|
|
55
64
|
* @param {IFDocumentInsertImageOptions} options The image source, optional transform, and insertion range.
|
|
56
65
|
* @returns {Promise<FDocumentImage | null>} The inserted image facade, or `null` when the insertion command fails.
|
|
@@ -61,6 +70,8 @@ export interface IFDocumentImageMixin {
|
|
|
61
70
|
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
62
71
|
* imageSourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
63
72
|
* width: 320,
|
|
73
|
+
* // Keep the image in the text flow so it cannot cover surrounding text.
|
|
74
|
+
* wrappingStyle: univerAPI.Enum.TextWrappingStyle.INLINE,
|
|
64
75
|
* textRange: {
|
|
65
76
|
* startOffset: 30,
|
|
66
77
|
* },
|
|
@@ -75,7 +86,8 @@ export interface IFDocumentImageMixin {
|
|
|
75
86
|
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
76
87
|
* imageSourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
77
88
|
* width: 320,
|
|
78
|
-
*
|
|
89
|
+
* // Float the image and let body text flow beside its rectangular bounds.
|
|
90
|
+
* wrappingStyle: univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE,
|
|
79
91
|
* textRange: {
|
|
80
92
|
* startOffset: 30,
|
|
81
93
|
* },
|
|
@@ -21,7 +21,11 @@ import { TextWrappingStyle } from '@univerjs/docs-drawing';
|
|
|
21
21
|
*/
|
|
22
22
|
export interface IFDocumentImageEnumMixin {
|
|
23
23
|
/**
|
|
24
|
-
* Represents the wrapping styles used by
|
|
24
|
+
* Represents the text wrapping styles used by document drawings, including images and Shapes.
|
|
25
|
+
*
|
|
26
|
+
* Prefer `INLINE`, `WRAP_SQUARE`, or `WRAP_TOP_AND_BOTTOM` for ordinary document content.
|
|
27
|
+
* `BEHIND_TEXT` and `IN_FRONT_OF_TEXT` are overlay styles that do not cause text to reflow.
|
|
28
|
+
* Use this property whenever a Facade signature references `TextWrappingStyle`.
|
|
25
29
|
* @example
|
|
26
30
|
* ```ts
|
|
27
31
|
* const fDocument = univerAPI.getActiveDocument();
|
|
@@ -29,7 +33,8 @@ export interface IFDocumentImageEnumMixin {
|
|
|
29
33
|
* source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
|
|
30
34
|
* imageSourceType: univerAPI.Enum.ImageSourceType.URL,
|
|
31
35
|
* width: 320,
|
|
32
|
-
*
|
|
36
|
+
* // Float the image and wrap body text around its rectangular bounds.
|
|
37
|
+
* wrappingStyle: univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE,
|
|
33
38
|
* textRange: {
|
|
34
39
|
* startOffset: 30,
|
|
35
40
|
* },
|
|
@@ -37,7 +42,7 @@ export interface IFDocumentImageEnumMixin {
|
|
|
37
42
|
* console.log(image);
|
|
38
43
|
* ```
|
|
39
44
|
*/
|
|
40
|
-
|
|
45
|
+
TextWrappingStyle: typeof TextWrappingStyle;
|
|
41
46
|
/**
|
|
42
47
|
* Represents the horizontal position types used by docs image operations.
|
|
43
48
|
* @example
|
|
@@ -74,7 +79,7 @@ export interface IFDocumentImageEnumMixin {
|
|
|
74
79
|
DocsImageRelativeFromV: typeof ObjectRelativeFromV;
|
|
75
80
|
}
|
|
76
81
|
export declare class FDocumentImageEnumMixin extends FEnum implements IFDocumentImageEnumMixin {
|
|
77
|
-
get
|
|
82
|
+
get TextWrappingStyle(): typeof TextWrappingStyle;
|
|
78
83
|
get DocsImageRelativeFromH(): typeof ObjectRelativeFromH;
|
|
79
84
|
get DocsImageRelativeFromV(): typeof ObjectRelativeFromV;
|
|
80
85
|
}
|
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
|
|
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().getDrawings())==null?void 0:e[this._imageId];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={}}=this._document.getDocumentDataModel().getSnapshot(),r=[{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}))];for(let{segmentId:e,body:t}of r){var i;let n=t==null||(i=t.customBlocks)==null?void 0:i.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 r=(n=this.getDocumentDataModel().getDrawings())==null?void 0:n[e];return!r||r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE?null:this._injector.createInstance(s,this,e,this._injector)}getImages(){let e=this.getDocumentDataModel(),n=e.getDrawings()??{};return(e.getDrawingsOrder()??Object.keys(n)).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});
|