@univerjs/docs-drawing 1.0.0-alpha.8 → 1.0.0-beta.1
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 +14 -16
- package/lib/cjs/index.js +44 -95
- package/lib/es/facade.js +14 -16
- package/lib/es/index.js +45 -96
- package/lib/facade.js +14 -16
- package/lib/index.js +45 -96
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +6 -2
- package/lib/types/facade/f-document-image.d.ts +1 -1
- package/lib/types/facade/f-document.d.ts +2 -2
- package/lib/types/facade/f-enum.d.ts +5 -4
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/facade.js
CHANGED
|
@@ -97,8 +97,8 @@ var FDocumentImage = class {
|
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
99
|
getSize() {
|
|
100
|
-
var _this$
|
|
101
|
-
return (
|
|
100
|
+
var _this$getImageData3;
|
|
101
|
+
return ((_this$getImageData3 = this.getImageData()) === null || _this$getImageData3 === void 0 ? void 0 : _this$getImageData3.docTransform.size) ?? null;
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Gets the current clockwise rotation angle.
|
|
@@ -131,8 +131,8 @@ var FDocumentImage = class {
|
|
|
131
131
|
* ```
|
|
132
132
|
*/
|
|
133
133
|
getPositionH() {
|
|
134
|
-
var _this$
|
|
135
|
-
return (
|
|
134
|
+
var _this$getImageData5;
|
|
135
|
+
return ((_this$getImageData5 = this.getImageData()) === null || _this$getImageData5 === void 0 ? void 0 : _this$getImageData5.docTransform.positionH) ?? null;
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Gets the current vertical position.
|
|
@@ -148,8 +148,8 @@ var FDocumentImage = class {
|
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
getPositionV() {
|
|
151
|
-
var _this$
|
|
152
|
-
return (
|
|
151
|
+
var _this$getImageData6;
|
|
152
|
+
return ((_this$getImageData6 = this.getImageData()) === null || _this$getImageData6 === void 0 ? void 0 : _this$getImageData6.docTransform.positionV) ?? null;
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Gets the current raw document image data.
|
|
@@ -273,7 +273,7 @@ var FDocumentImage = class {
|
|
|
273
273
|
*
|
|
274
274
|
* if (image) {
|
|
275
275
|
* // Float the image beside body text without covering it.
|
|
276
|
-
* const success = image.setWrappingStyle(univerAPI.Enum.
|
|
276
|
+
* const success = image.setWrappingStyle(univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE);
|
|
277
277
|
* console.log(success);
|
|
278
278
|
* }
|
|
279
279
|
* ```
|
|
@@ -438,7 +438,6 @@ var FDocumentImage = class {
|
|
|
438
438
|
//#region src/facade/f-document.ts
|
|
439
439
|
var FDocumentImageMixin = class extends _univerjs_docs_facade.FDocument {
|
|
440
440
|
async insertImage(options) {
|
|
441
|
-
var _options$wrappingStyl, _options$angle, _options$positionH, _options$positionV;
|
|
442
441
|
const unitId = this.getId();
|
|
443
442
|
const imageId = (0, _univerjs_core.generateRandomId)(6);
|
|
444
443
|
const size = options.width != null && options.height != null ? {
|
|
@@ -446,12 +445,12 @@ var FDocumentImageMixin = class extends _univerjs_docs_facade.FDocument {
|
|
|
446
445
|
height: options.height
|
|
447
446
|
} : resolveImageSize(await this._getIntrinsicSize(options.source, options.imageSourceType), options);
|
|
448
447
|
const defaultTransform = (0, _univerjs_docs.buildDocTransform)(size.width, size.height);
|
|
449
|
-
const wrappingStyle =
|
|
448
|
+
const wrappingStyle = options.wrappingStyle ?? _univerjs_docs_drawing.TextWrappingStyle.INLINE;
|
|
450
449
|
const docTransform = {
|
|
451
450
|
...defaultTransform,
|
|
452
|
-
angle:
|
|
453
|
-
positionH:
|
|
454
|
-
positionV:
|
|
451
|
+
angle: options.angle ?? defaultTransform.angle,
|
|
452
|
+
positionH: options.positionH ?? defaultTransform.positionH,
|
|
453
|
+
positionV: options.positionV ?? defaultTransform.positionV
|
|
455
454
|
};
|
|
456
455
|
const transform = (0, _univerjs_docs.docDrawingPositionToTransform)(docTransform);
|
|
457
456
|
const drawing = {
|
|
@@ -487,10 +486,9 @@ var FDocumentImageMixin = class extends _univerjs_docs_facade.FDocument {
|
|
|
487
486
|
return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
|
|
488
487
|
}
|
|
489
488
|
getImages() {
|
|
490
|
-
var _documentDataModel$ge, _documentDataModel$ge2;
|
|
491
489
|
const documentDataModel = this.getDocumentDataModel();
|
|
492
|
-
const drawings =
|
|
493
|
-
return (
|
|
490
|
+
const drawings = documentDataModel.getDrawings() ?? {};
|
|
491
|
+
return (documentDataModel.getDrawingsOrder() ?? Object.keys(drawings)).filter((drawingId) => {
|
|
494
492
|
var _drawings$drawingId;
|
|
495
493
|
return ((_drawings$drawingId = drawings[drawingId]) === null || _drawings$drawingId === void 0 ? void 0 : _drawings$drawingId.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE;
|
|
496
494
|
}).map((drawingId) => this._injector.createInstance(FDocumentImage, this, drawingId, this._injector));
|
|
@@ -552,7 +550,7 @@ _univerjs_docs_facade.FDocument.extend(FDocumentImageMixin);
|
|
|
552
550
|
* limitations under the License.
|
|
553
551
|
*/
|
|
554
552
|
var FDocumentImageEnumMixin = class extends _univerjs_core_facade.FEnum {
|
|
555
|
-
get
|
|
553
|
+
get TextWrappingStyle() {
|
|
556
554
|
return _univerjs_docs_drawing.TextWrappingStyle;
|
|
557
555
|
}
|
|
558
556
|
get DocsImageRelativeFromH() {
|
package/lib/cjs/index.js
CHANGED
|
@@ -11,81 +11,29 @@ const InsertDocDrawingCommand = {
|
|
|
11
11
|
id: "doc.command.insert-doc-image",
|
|
12
12
|
type: _univerjs_core.CommandType.COMMAND,
|
|
13
13
|
handler: (accessor, params) => {
|
|
14
|
-
var _documentDataModel$ge, _snapshot$headers, _snapshot$footers
|
|
14
|
+
var _documentDataModel$ge, _snapshot$headers, _snapshot$footers;
|
|
15
15
|
if (!params) return false;
|
|
16
16
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
17
17
|
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
18
18
|
const { unitId, drawings, textRange } = params;
|
|
19
19
|
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
20
20
|
if (!documentDataModel) return false;
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
if (!body) return false;
|
|
26
|
-
const textX = new _univerjs_core.TextX();
|
|
27
|
-
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
28
|
-
const rawActions = [];
|
|
21
|
+
const resolvedTextRange = resolveDocDrawingInsertTextRange(accessor, unitId, textRange);
|
|
22
|
+
if (!resolvedTextRange) return false;
|
|
23
|
+
const { segmentId = "" } = resolvedTextRange;
|
|
24
|
+
if (!((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody())) return false;
|
|
29
25
|
const snapshot = documentDataModel.getSnapshot();
|
|
30
|
-
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) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let removeDrawingLen = 0;
|
|
40
|
-
if (collapsed) {
|
|
41
|
-
if (startOffset > 0) textX.push({
|
|
42
|
-
t: _univerjs_core.TextXActionType.RETAIN,
|
|
43
|
-
len: startOffset
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
var _documentDataModel$ge2, _documentDataModel$ge3;
|
|
47
|
-
const dos = _univerjs_core.BuildTextUtils.selection.delete([targetTextRange], body, 0, null, false);
|
|
48
|
-
textX.push(...dos);
|
|
49
|
-
const removedCustomBlockIds = (0, _univerjs_core.getCustomBlockIdsInSelections)(body, [targetTextRange]);
|
|
50
|
-
const drawings = (_documentDataModel$ge2 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge2 !== void 0 ? _documentDataModel$ge2 : {};
|
|
51
|
-
const drawingOrder = (_documentDataModel$ge3 = documentDataModel.getDrawingsOrder()) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : [];
|
|
52
|
-
const sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => {
|
|
53
|
-
if (drawingOrder.indexOf(a) > drawingOrder.indexOf(b)) return -1;
|
|
54
|
-
else if (drawingOrder.indexOf(a) < drawingOrder.indexOf(b)) return 1;
|
|
55
|
-
return 0;
|
|
56
|
-
});
|
|
57
|
-
if (sortedRemovedCustomBlockIds.length > 0) for (const blockId of sortedRemovedCustomBlockIds) {
|
|
58
|
-
const drawing = drawings[blockId];
|
|
59
|
-
const drawingIndex = drawingOrder.indexOf(blockId);
|
|
60
|
-
if (drawing == null || drawingIndex < 0) continue;
|
|
61
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing);
|
|
62
|
-
const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
63
|
-
rawActions.push(removeDrawingAction);
|
|
64
|
-
rawActions.push(removeDrawingOrderAction);
|
|
65
|
-
removeDrawingLen++;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
textX.push({
|
|
69
|
-
t: _univerjs_core.TextXActionType.INSERT,
|
|
70
|
-
body: {
|
|
71
|
-
dataStream: "\b".repeat(targetDrawings.length),
|
|
72
|
-
customBlocks: targetDrawings.map((drawing, i) => ({
|
|
73
|
-
startIndex: i,
|
|
74
|
-
blockId: drawing.drawingId
|
|
75
|
-
}))
|
|
76
|
-
},
|
|
77
|
-
len: targetDrawings.length
|
|
26
|
+
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) => ({
|
|
27
|
+
...drawing,
|
|
28
|
+
isMultiTransform: _univerjs_core.BooleanNumber.TRUE,
|
|
29
|
+
transforms: drawing.transforms ?? (drawing.transform ? [drawing.transform] : null)
|
|
30
|
+
})) : drawings;
|
|
31
|
+
const actions = _univerjs_core.BuildTextUtils.drawing.add({
|
|
32
|
+
selection: resolvedTextRange,
|
|
33
|
+
documentDataModel,
|
|
34
|
+
drawings: targetDrawings
|
|
78
35
|
});
|
|
79
|
-
|
|
80
|
-
const placeHolderAction = jsonX.editOp(textX.serialize(), path);
|
|
81
|
-
rawActions.push(placeHolderAction);
|
|
82
|
-
for (const drawing of targetDrawings) {
|
|
83
|
-
const { drawingId } = drawing;
|
|
84
|
-
const addDrawingAction = jsonX.insertOp(["drawings", drawingId], drawing);
|
|
85
|
-
const addDrawingOrderAction = jsonX.insertOp(["drawingsOrder", drawingOrderLength - removeDrawingLen], drawingId);
|
|
86
|
-
rawActions.push(addDrawingAction);
|
|
87
|
-
rawActions.push(addDrawingOrderAction);
|
|
88
|
-
}
|
|
36
|
+
if (!actions) return false;
|
|
89
37
|
const doMutation = {
|
|
90
38
|
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
91
39
|
params: {
|
|
@@ -94,25 +42,21 @@ const InsertDocDrawingCommand = {
|
|
|
94
42
|
textRanges: []
|
|
95
43
|
}
|
|
96
44
|
};
|
|
97
|
-
doMutation.params.actions =
|
|
98
|
-
return _univerjs_core.JSONX.compose(acc, cur);
|
|
99
|
-
}, null);
|
|
45
|
+
doMutation.params.actions = actions;
|
|
100
46
|
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
101
47
|
return Boolean(result);
|
|
102
48
|
}
|
|
103
49
|
};
|
|
104
50
|
function resolveDocDrawingInsertTextRange(accessor, unitId, textRange) {
|
|
105
|
-
var _ref, _contentInsertRange$s;
|
|
106
51
|
const activeTextRange = accessor.get(_univerjs_docs.DocSelectionManagerService).getActiveTextRange();
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
if (!contentInsertRange) return activeTextRange !== null && activeTextRange !== void 0 ? activeTextRange : null;
|
|
52
|
+
const contentInsertRange = (textRange ? (0, _univerjs_docs.normalizeTextRange)(textRange) : null) ?? (0, _univerjs_docs.getContentInsertRange)(accessor, unitId);
|
|
53
|
+
if (!contentInsertRange) return activeTextRange ?? null;
|
|
110
54
|
return {
|
|
111
55
|
...activeTextRange,
|
|
112
56
|
startOffset: contentInsertRange.startOffset,
|
|
113
57
|
endOffset: contentInsertRange.endOffset,
|
|
114
58
|
collapsed: contentInsertRange.startOffset === contentInsertRange.endOffset,
|
|
115
|
-
segmentId:
|
|
59
|
+
segmentId: contentInsertRange.segmentId ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? ""
|
|
116
60
|
};
|
|
117
61
|
}
|
|
118
62
|
|
|
@@ -202,7 +146,7 @@ const RemoveDocDrawingCommand = {
|
|
|
202
146
|
id: "doc.command.remove-doc-image",
|
|
203
147
|
type: _univerjs_core.CommandType.COMMAND,
|
|
204
148
|
handler: (accessor, params) => {
|
|
205
|
-
var
|
|
149
|
+
var _documentDataModel$ge;
|
|
206
150
|
if (!params) return false;
|
|
207
151
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
208
152
|
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
@@ -213,29 +157,27 @@ const RemoveDocDrawingCommand = {
|
|
|
213
157
|
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
214
158
|
if (!documentDataModel || removeDrawings.length === 0) return false;
|
|
215
159
|
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
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 : "";
|
|
160
|
+
const contentInsertRange = (!textRange ? null : (0, _univerjs_docs.normalizeTextRange)(textRange)) ?? (0, _univerjs_docs.getContentInsertRange)(accessor, unitId);
|
|
161
|
+
const segmentId = (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? "";
|
|
219
162
|
const textX = new _univerjs_core.TextX();
|
|
220
163
|
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
221
|
-
const customBlocks = (_documentDataModel$ge =
|
|
164
|
+
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) ?? [];
|
|
222
165
|
const removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1);
|
|
223
166
|
if (removeCustomBlocks.length === 0) return false;
|
|
224
|
-
const drawings =
|
|
167
|
+
const drawings = documentDataModel.getDrawings() ?? {};
|
|
225
168
|
const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
|
|
226
169
|
const removeDrawingSnapshots = removeCustomBlocks.map((block) => drawings[block.blockId]).filter((drawing) => drawing != null);
|
|
227
170
|
const resourceRedoMutations = [];
|
|
228
171
|
const resourceUndoMutations = [];
|
|
229
172
|
const resourceMutationGroups = [];
|
|
230
173
|
for (const block of removeCustomBlocks) {
|
|
231
|
-
var _removeDrawingParam$s;
|
|
232
174
|
const { blockId } = block;
|
|
233
175
|
const drawing = drawings[blockId];
|
|
234
176
|
if (drawing == null) continue;
|
|
235
177
|
const removeDrawingParam = removeDrawingParamById.get(blockId);
|
|
236
178
|
const mutationInfos = drawingAdapterService.getRemoveDrawingMutationInfos({
|
|
237
179
|
unitId,
|
|
238
|
-
subUnitId: (
|
|
180
|
+
subUnitId: (removeDrawingParam === null || removeDrawingParam === void 0 ? void 0 : removeDrawingParam.subUnitId) ?? unitId,
|
|
239
181
|
drawing,
|
|
240
182
|
removeDrawings: removeDrawingSnapshots
|
|
241
183
|
});
|
|
@@ -342,6 +284,16 @@ function getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType) {
|
|
|
342
284
|
}
|
|
343
285
|
return arrangedDrawingOrder;
|
|
344
286
|
}
|
|
287
|
+
function getDrawingOrderAtIndex(drawingOrder, drawingIds, zOrder) {
|
|
288
|
+
if (drawingIds.length !== 1) return [...drawingOrder];
|
|
289
|
+
const arrangedDrawingOrder = [...drawingOrder];
|
|
290
|
+
const currentIndex = arrangedDrawingOrder.indexOf(drawingIds[0]);
|
|
291
|
+
if (currentIndex < 0) return arrangedDrawingOrder;
|
|
292
|
+
const [drawingId] = arrangedDrawingOrder.splice(currentIndex, 1);
|
|
293
|
+
const targetIndex = (0, _univerjs_core.normalizeDrawingOrderIndex)(zOrder, drawingOrder.length);
|
|
294
|
+
arrangedDrawingOrder.splice(targetIndex, 0, drawingId);
|
|
295
|
+
return arrangedDrawingOrder;
|
|
296
|
+
}
|
|
345
297
|
/**
|
|
346
298
|
* Converts the target order into granular JSONX move operations. This avoids replacing
|
|
347
299
|
* the entire drawingsOrder array and keeps collaboration conflicts scoped to moved items.
|
|
@@ -370,11 +322,11 @@ const SetDocDrawingArrangeCommand = {
|
|
|
370
322
|
handler: (accessor, params) => {
|
|
371
323
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
372
324
|
if (params == null) return false;
|
|
373
|
-
const { unitId, drawingIds
|
|
325
|
+
const { unitId, drawingIds } = params;
|
|
374
326
|
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
375
327
|
const drawingOrder = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDrawingsOrder();
|
|
376
328
|
if (!drawingOrder) return false;
|
|
377
|
-
const actions = createDrawingOrderActions(drawingOrder, getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType));
|
|
329
|
+
const actions = createDrawingOrderActions(drawingOrder, params.zOrder !== void 0 ? getDrawingOrderAtIndex(drawingOrder, drawingIds, params.zOrder) : getArrangedDrawingOrder(drawingOrder, drawingIds, params.arrangeType));
|
|
378
330
|
if (_univerjs_core.JSONX.isNoop(actions)) return false;
|
|
379
331
|
const result = commandService.syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
|
|
380
332
|
unitId,
|
|
@@ -391,14 +343,13 @@ const UpdateDrawingDocTransformCommand = {
|
|
|
391
343
|
id: "doc.command.update-drawing-doc-transform",
|
|
392
344
|
type: _univerjs_core.CommandType.COMMAND,
|
|
393
345
|
handler: (accessor, params) => {
|
|
394
|
-
var _documentDataModel$ge;
|
|
395
346
|
if (!params) return false;
|
|
396
347
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
397
348
|
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
398
349
|
const { unitId, drawings } = params;
|
|
399
350
|
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
400
351
|
if (!documentDataModel) return false;
|
|
401
|
-
const oldDrawings =
|
|
352
|
+
const oldDrawings = documentDataModel.getSnapshot().drawings ?? {};
|
|
402
353
|
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
403
354
|
const actions = [];
|
|
404
355
|
for (const { drawingId, key, value } of drawings) {
|
|
@@ -479,13 +430,12 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
479
430
|
id: "doc.command.update-doc-drawing-wrapping-style",
|
|
480
431
|
type: _univerjs_core.CommandType.COMMAND,
|
|
481
432
|
handler: (accessor, params) => {
|
|
482
|
-
var _documentDataModel$ge;
|
|
483
433
|
if (!params) return false;
|
|
484
434
|
const { drawings, wrappingStyle, unitId } = params;
|
|
485
435
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
486
436
|
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
487
437
|
if (!documentDataModel) return false;
|
|
488
|
-
const oldDrawings =
|
|
438
|
+
const oldDrawings = documentDataModel.getDrawings() ?? {};
|
|
489
439
|
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
490
440
|
const rawActions = [];
|
|
491
441
|
for (const drawing of drawings) {
|
|
@@ -588,8 +538,8 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
588
538
|
const drawings = doc.getSnapshot().drawings;
|
|
589
539
|
const drawingOrder = doc.getSnapshot().drawingsOrder;
|
|
590
540
|
return JSON.stringify({
|
|
591
|
-
data: drawings
|
|
592
|
-
order: drawingOrder
|
|
541
|
+
data: drawings ?? {},
|
|
542
|
+
order: drawingOrder ?? []
|
|
593
543
|
});
|
|
594
544
|
}
|
|
595
545
|
return "";
|
|
@@ -620,10 +570,9 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
620
570
|
});
|
|
621
571
|
},
|
|
622
572
|
onLoad: (unitId, value) => {
|
|
623
|
-
var _value$data, _value$order;
|
|
624
573
|
this._setDrawingDataForUnit(unitId, {
|
|
625
|
-
data:
|
|
626
|
-
order:
|
|
574
|
+
data: value.data ?? {},
|
|
575
|
+
order: value.order ?? []
|
|
627
576
|
});
|
|
628
577
|
}
|
|
629
578
|
}));
|
|
@@ -676,7 +625,7 @@ DocDrawingController = __decorate([
|
|
|
676
625
|
//#endregion
|
|
677
626
|
//#region package.json
|
|
678
627
|
var name = "@univerjs/docs-drawing";
|
|
679
|
-
var version = "1.0.0-
|
|
628
|
+
var version = "1.0.0-beta.1";
|
|
680
629
|
|
|
681
630
|
//#endregion
|
|
682
631
|
//#region src/config/config.ts
|
package/lib/es/facade.js
CHANGED
|
@@ -96,8 +96,8 @@ var FDocumentImage = class {
|
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
getSize() {
|
|
99
|
-
var _this$
|
|
100
|
-
return (
|
|
99
|
+
var _this$getImageData3;
|
|
100
|
+
return ((_this$getImageData3 = this.getImageData()) === null || _this$getImageData3 === void 0 ? void 0 : _this$getImageData3.docTransform.size) ?? null;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Gets the current clockwise rotation angle.
|
|
@@ -130,8 +130,8 @@ var FDocumentImage = class {
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
getPositionH() {
|
|
133
|
-
var _this$
|
|
134
|
-
return (
|
|
133
|
+
var _this$getImageData5;
|
|
134
|
+
return ((_this$getImageData5 = this.getImageData()) === null || _this$getImageData5 === void 0 ? void 0 : _this$getImageData5.docTransform.positionH) ?? null;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Gets the current vertical position.
|
|
@@ -147,8 +147,8 @@ var FDocumentImage = class {
|
|
|
147
147
|
* ```
|
|
148
148
|
*/
|
|
149
149
|
getPositionV() {
|
|
150
|
-
var _this$
|
|
151
|
-
return (
|
|
150
|
+
var _this$getImageData6;
|
|
151
|
+
return ((_this$getImageData6 = this.getImageData()) === null || _this$getImageData6 === void 0 ? void 0 : _this$getImageData6.docTransform.positionV) ?? null;
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Gets the current raw document image data.
|
|
@@ -272,7 +272,7 @@ var FDocumentImage = class {
|
|
|
272
272
|
*
|
|
273
273
|
* if (image) {
|
|
274
274
|
* // Float the image beside body text without covering it.
|
|
275
|
-
* const success = image.setWrappingStyle(univerAPI.Enum.
|
|
275
|
+
* const success = image.setWrappingStyle(univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE);
|
|
276
276
|
* console.log(success);
|
|
277
277
|
* }
|
|
278
278
|
* ```
|
|
@@ -437,7 +437,6 @@ var FDocumentImage = class {
|
|
|
437
437
|
//#region src/facade/f-document.ts
|
|
438
438
|
var FDocumentImageMixin = class extends FDocument {
|
|
439
439
|
async insertImage(options) {
|
|
440
|
-
var _options$wrappingStyl, _options$angle, _options$positionH, _options$positionV;
|
|
441
440
|
const unitId = this.getId();
|
|
442
441
|
const imageId = generateRandomId(6);
|
|
443
442
|
const size = options.width != null && options.height != null ? {
|
|
@@ -445,12 +444,12 @@ var FDocumentImageMixin = class extends FDocument {
|
|
|
445
444
|
height: options.height
|
|
446
445
|
} : resolveImageSize(await this._getIntrinsicSize(options.source, options.imageSourceType), options);
|
|
447
446
|
const defaultTransform = buildDocTransform(size.width, size.height);
|
|
448
|
-
const wrappingStyle =
|
|
447
|
+
const wrappingStyle = options.wrappingStyle ?? TextWrappingStyle.INLINE;
|
|
449
448
|
const docTransform = {
|
|
450
449
|
...defaultTransform,
|
|
451
|
-
angle:
|
|
452
|
-
positionH:
|
|
453
|
-
positionV:
|
|
450
|
+
angle: options.angle ?? defaultTransform.angle,
|
|
451
|
+
positionH: options.positionH ?? defaultTransform.positionH,
|
|
452
|
+
positionV: options.positionV ?? defaultTransform.positionV
|
|
454
453
|
};
|
|
455
454
|
const transform = docDrawingPositionToTransform(docTransform);
|
|
456
455
|
const drawing = {
|
|
@@ -486,10 +485,9 @@ var FDocumentImageMixin = class extends FDocument {
|
|
|
486
485
|
return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
|
|
487
486
|
}
|
|
488
487
|
getImages() {
|
|
489
|
-
var _documentDataModel$ge, _documentDataModel$ge2;
|
|
490
488
|
const documentDataModel = this.getDocumentDataModel();
|
|
491
|
-
const drawings =
|
|
492
|
-
return (
|
|
489
|
+
const drawings = documentDataModel.getDrawings() ?? {};
|
|
490
|
+
return (documentDataModel.getDrawingsOrder() ?? Object.keys(drawings)).filter((drawingId) => {
|
|
493
491
|
var _drawings$drawingId;
|
|
494
492
|
return ((_drawings$drawingId = drawings[drawingId]) === null || _drawings$drawingId === void 0 ? void 0 : _drawings$drawingId.drawingType) === DrawingTypeEnum.DRAWING_IMAGE;
|
|
495
493
|
}).map((drawingId) => this._injector.createInstance(FDocumentImage, this, drawingId, this._injector));
|
|
@@ -551,7 +549,7 @@ FDocument.extend(FDocumentImageMixin);
|
|
|
551
549
|
* limitations under the License.
|
|
552
550
|
*/
|
|
553
551
|
var FDocumentImageEnumMixin = class extends FEnum {
|
|
554
|
-
get
|
|
552
|
+
get TextWrappingStyle() {
|
|
555
553
|
return TextWrappingStyle;
|
|
556
554
|
}
|
|
557
555
|
get DocsImageRelativeFromH() {
|