@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/es/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 };
|
package/lib/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.
|
|
@@ -257,6 +257,11 @@ var FDocumentImage = class {
|
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
259
|
* Sets the image wrapping style.
|
|
260
|
+
*
|
|
261
|
+
* Use `INLINE` to place the image in the text flow, `WRAP_SQUARE` to flow text beside it, or
|
|
262
|
+
* `WRAP_TOP_AND_BOTTOM` to keep text above and below it. `BEHIND_TEXT` and `IN_FRONT_OF_TEXT` do not reserve space
|
|
263
|
+
* in the text layout and can overlap text.
|
|
264
|
+
*
|
|
260
265
|
* When switching from inline to a floating style in a UI environment, the current visual position is preserved.
|
|
261
266
|
* @param {TextWrappingStyle} wrappingStyle The wrapping style to apply.
|
|
262
267
|
* @returns {boolean} `true` when the update command succeeds; otherwise, `false`.
|
|
@@ -266,7 +271,8 @@ var FDocumentImage = class {
|
|
|
266
271
|
* const image = fDocument.getImages()[0];
|
|
267
272
|
*
|
|
268
273
|
* if (image) {
|
|
269
|
-
*
|
|
274
|
+
* // Float the image beside body text without covering it.
|
|
275
|
+
* const success = image.setWrappingStyle(univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE);
|
|
270
276
|
* console.log(success);
|
|
271
277
|
* }
|
|
272
278
|
* ```
|
|
@@ -431,17 +437,19 @@ var FDocumentImage = class {
|
|
|
431
437
|
//#region src/facade/f-document.ts
|
|
432
438
|
var FDocumentImageMixin = class extends FDocument {
|
|
433
439
|
async insertImage(options) {
|
|
434
|
-
var _options$wrappingStyl, _options$angle, _options$positionH, _options$positionV;
|
|
435
440
|
const unitId = this.getId();
|
|
436
441
|
const imageId = generateRandomId(6);
|
|
437
|
-
const size =
|
|
442
|
+
const size = options.width != null && options.height != null ? {
|
|
443
|
+
width: options.width,
|
|
444
|
+
height: options.height
|
|
445
|
+
} : resolveImageSize(await this._getIntrinsicSize(options.source, options.imageSourceType), options);
|
|
438
446
|
const defaultTransform = buildDocTransform(size.width, size.height);
|
|
439
|
-
const wrappingStyle =
|
|
447
|
+
const wrappingStyle = options.wrappingStyle ?? TextWrappingStyle.INLINE;
|
|
440
448
|
const docTransform = {
|
|
441
449
|
...defaultTransform,
|
|
442
|
-
angle:
|
|
443
|
-
positionH:
|
|
444
|
-
positionV:
|
|
450
|
+
angle: options.angle ?? defaultTransform.angle,
|
|
451
|
+
positionH: options.positionH ?? defaultTransform.positionH,
|
|
452
|
+
positionV: options.positionV ?? defaultTransform.positionV
|
|
445
453
|
};
|
|
446
454
|
const transform = docDrawingPositionToTransform(docTransform);
|
|
447
455
|
const drawing = {
|
|
@@ -477,10 +485,9 @@ var FDocumentImageMixin = class extends FDocument {
|
|
|
477
485
|
return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
|
|
478
486
|
}
|
|
479
487
|
getImages() {
|
|
480
|
-
var _documentDataModel$ge, _documentDataModel$ge2;
|
|
481
488
|
const documentDataModel = this.getDocumentDataModel();
|
|
482
|
-
const drawings =
|
|
483
|
-
return (
|
|
489
|
+
const drawings = documentDataModel.getDrawings() ?? {};
|
|
490
|
+
return (documentDataModel.getDrawingsOrder() ?? Object.keys(drawings)).filter((drawingId) => {
|
|
484
491
|
var _drawings$drawingId;
|
|
485
492
|
return ((_drawings$drawingId = drawings[drawingId]) === null || _drawings$drawingId === void 0 ? void 0 : _drawings$drawingId.drawingType) === DrawingTypeEnum.DRAWING_IMAGE;
|
|
486
493
|
}).map((drawingId) => this._injector.createInstance(FDocumentImage, this, drawingId, this._injector));
|
|
@@ -542,7 +549,7 @@ FDocument.extend(FDocumentImageMixin);
|
|
|
542
549
|
* limitations under the License.
|
|
543
550
|
*/
|
|
544
551
|
var FDocumentImageEnumMixin = class extends FEnum {
|
|
545
|
-
get
|
|
552
|
+
get TextWrappingStyle() {
|
|
546
553
|
return TextWrappingStyle;
|
|
547
554
|
}
|
|
548
555
|
get DocsImageRelativeFromH() {
|