@univerjs/docs-drawing 1.0.0-alpha.2 → 1.0.0-alpha.4
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 +559 -0
- package/lib/cjs/index.js +504 -45
- package/lib/es/facade.js +558 -0
- package/lib/es/index.js +497 -47
- package/lib/facade.js +558 -0
- package/lib/index.js +497 -47
- package/lib/types/commands/commands/insert-doc-drawing.command.d.ts +26 -0
- package/lib/types/commands/commands/remove-doc-drawing.command.d.ts +28 -0
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +25 -0
- package/lib/types/commands/commands/update-doc-drawing-transform.command.d.ts +27 -0
- package/lib/types/commands/commands/update-doc-drawing-wrapping-style.command.d.ts +36 -0
- package/lib/types/controllers/doc-drawing.controller.d.ts +4 -2
- package/lib/types/facade/f-document-image.d.ts +324 -0
- package/lib/types/facade/f-document.d.ts +120 -0
- package/lib/types/facade/f-enum.d.ts +84 -0
- package/lib/types/facade/index.d.ts +19 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/services/doc-drawing-adapter.service.d.ts +54 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +17 -5
package/lib/cjs/index.js
CHANGED
|
@@ -1,11 +1,489 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_docs = require("@univerjs/docs");
|
|
3
4
|
let _univerjs_drawing = require("@univerjs/drawing");
|
|
4
5
|
|
|
6
|
+
//#region src/commands/commands/insert-doc-drawing.command.ts
|
|
7
|
+
/**
|
|
8
|
+
* The command to insert new drawings
|
|
9
|
+
*/
|
|
10
|
+
const InsertDocDrawingCommand = {
|
|
11
|
+
id: "doc.command.insert-doc-image",
|
|
12
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
13
|
+
handler: (accessor, params) => {
|
|
14
|
+
var _documentDataModel$ge, _snapshot$headers, _snapshot$footers, _snapshot$drawingsOrd, _snapshot$drawingsOrd2;
|
|
15
|
+
if (!params) return false;
|
|
16
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
17
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
18
|
+
const { unitId, drawings, textRange } = params;
|
|
19
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
20
|
+
if (!documentDataModel) return false;
|
|
21
|
+
const targetTextRange = resolveDocDrawingInsertTextRange(accessor, unitId, textRange);
|
|
22
|
+
if (!targetTextRange) return false;
|
|
23
|
+
const { collapsed, startOffset, segmentId = "" } = targetTextRange;
|
|
24
|
+
const body = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
25
|
+
if (!body) return false;
|
|
26
|
+
const textX = new _univerjs_core.TextX();
|
|
27
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
28
|
+
const rawActions = [];
|
|
29
|
+
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
|
+
var _drawing$transforms;
|
|
32
|
+
return {
|
|
33
|
+
...drawing,
|
|
34
|
+
isMultiTransform: _univerjs_core.BooleanNumber.TRUE,
|
|
35
|
+
transforms: (_drawing$transforms = drawing.transforms) !== null && _drawing$transforms !== void 0 ? _drawing$transforms : drawing.transform ? [drawing.transform] : null
|
|
36
|
+
};
|
|
37
|
+
}) : drawings;
|
|
38
|
+
const drawingOrderLength = (_snapshot$drawingsOrd = (_snapshot$drawingsOrd2 = snapshot.drawingsOrder) === null || _snapshot$drawingsOrd2 === void 0 ? void 0 : _snapshot$drawingsOrd2.length) !== null && _snapshot$drawingsOrd !== void 0 ? _snapshot$drawingsOrd : 0;
|
|
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
|
|
78
|
+
});
|
|
79
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
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
|
+
}
|
|
89
|
+
const doMutation = {
|
|
90
|
+
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
91
|
+
params: {
|
|
92
|
+
unitId,
|
|
93
|
+
actions: [],
|
|
94
|
+
textRanges: []
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
98
|
+
return _univerjs_core.JSONX.compose(acc, cur);
|
|
99
|
+
}, null);
|
|
100
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
101
|
+
return Boolean(result);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function resolveDocDrawingInsertTextRange(accessor, unitId, textRange) {
|
|
105
|
+
var _ref, _contentInsertRange$s;
|
|
106
|
+
const activeTextRange = accessor.get(_univerjs_docs.DocSelectionManagerService).getActiveTextRange();
|
|
107
|
+
const explicitTextRange = textRange ? (0, _univerjs_docs.normalizeTextRange)(textRange) : null;
|
|
108
|
+
const contentInsertRange = explicitTextRange !== null && explicitTextRange !== void 0 ? explicitTextRange : (0, _univerjs_docs.getContentInsertRange)(accessor, unitId);
|
|
109
|
+
if (!contentInsertRange) return activeTextRange !== null && activeTextRange !== void 0 ? activeTextRange : null;
|
|
110
|
+
return {
|
|
111
|
+
...activeTextRange,
|
|
112
|
+
startOffset: contentInsertRange.startOffset,
|
|
113
|
+
endOffset: contentInsertRange.endOffset,
|
|
114
|
+
collapsed: contentInsertRange.startOffset === contentInsertRange.endOffset,
|
|
115
|
+
segmentId: (_ref = (_contentInsertRange$s = contentInsertRange.segmentId) !== null && _contentInsertRange$s !== void 0 ? _contentInsertRange$s : activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) !== null && _ref !== void 0 ? _ref : ""
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
121
|
+
function _typeof(o) {
|
|
122
|
+
"@babel/helpers - typeof";
|
|
123
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
124
|
+
return typeof o;
|
|
125
|
+
} : function(o) {
|
|
126
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
127
|
+
}, _typeof(o);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
132
|
+
function toPrimitive(t, r) {
|
|
133
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
134
|
+
var e = t[Symbol.toPrimitive];
|
|
135
|
+
if (void 0 !== e) {
|
|
136
|
+
var i = e.call(t, r || "default");
|
|
137
|
+
if ("object" != _typeof(i)) return i;
|
|
138
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
139
|
+
}
|
|
140
|
+
return ("string" === r ? String : Number)(t);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
145
|
+
function toPropertyKey(t) {
|
|
146
|
+
var i = toPrimitive(t, "string");
|
|
147
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
152
|
+
function _defineProperty(e, r, t) {
|
|
153
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
154
|
+
value: t,
|
|
155
|
+
enumerable: !0,
|
|
156
|
+
configurable: !0,
|
|
157
|
+
writable: !0
|
|
158
|
+
}) : e[r] = t, e;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/services/doc-drawing-adapter.service.ts
|
|
163
|
+
const IDocDrawingAdapterService = (0, _univerjs_core.createIdentifier)("doc.drawing-adapter.service");
|
|
164
|
+
var DocDrawingAdapterService = class {
|
|
165
|
+
constructor() {
|
|
166
|
+
_defineProperty(this, "_adapters", []);
|
|
167
|
+
}
|
|
168
|
+
registerAdapter(adapter) {
|
|
169
|
+
this._adapters.push(adapter);
|
|
170
|
+
return (0, _univerjs_core.toDisposable)(() => {
|
|
171
|
+
const index = this._adapters.indexOf(adapter);
|
|
172
|
+
if (index >= 0) this._adapters.splice(index, 1);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getRemoveDrawingMutationInfos(params) {
|
|
176
|
+
const mutationInfos = {
|
|
177
|
+
redoMutations: [],
|
|
178
|
+
undoMutations: []
|
|
179
|
+
};
|
|
180
|
+
for (const adapter of this._adapters) {
|
|
181
|
+
var _adapter$getRemoveDra;
|
|
182
|
+
const nextMutationInfos = (_adapter$getRemoveDra = adapter.getRemoveDrawingMutationInfos) === null || _adapter$getRemoveDra === void 0 ? void 0 : _adapter$getRemoveDra.call(adapter, params);
|
|
183
|
+
if (!nextMutationInfos) continue;
|
|
184
|
+
mutationInfos.redoMutations.push(...nextMutationInfos.redoMutations);
|
|
185
|
+
mutationInfos.undoMutations.push(...nextMutationInfos.undoMutations);
|
|
186
|
+
}
|
|
187
|
+
return mutationInfos;
|
|
188
|
+
}
|
|
189
|
+
getEditDrawingCommandInfo(params) {
|
|
190
|
+
for (const adapter of this._adapters) {
|
|
191
|
+
var _adapter$getEditDrawi;
|
|
192
|
+
const commandInfo = (_adapter$getEditDrawi = adapter.getEditDrawingCommandInfo) === null || _adapter$getEditDrawi === void 0 ? void 0 : _adapter$getEditDrawi.call(adapter, params);
|
|
193
|
+
if (commandInfo) return commandInfo;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/commands/commands/remove-doc-drawing.command.ts
|
|
201
|
+
const RemoveDocDrawingCommand = {
|
|
202
|
+
id: "doc.command.remove-doc-image",
|
|
203
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
204
|
+
handler: (accessor, params) => {
|
|
205
|
+
var _ref, _contentInsertRange$s, _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3;
|
|
206
|
+
if (!params) return false;
|
|
207
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
208
|
+
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
209
|
+
const drawingAdapterService = accessor.get(IDocDrawingAdapterService);
|
|
210
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
211
|
+
const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
|
|
212
|
+
const { unitId, drawings: removeDrawings, textRange } = params;
|
|
213
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
214
|
+
if (!documentDataModel || removeDrawings.length === 0) return false;
|
|
215
|
+
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
216
|
+
const explicitTextRange = !textRange ? null : (0, _univerjs_docs.normalizeTextRange)(textRange);
|
|
217
|
+
const contentInsertRange = explicitTextRange !== null && explicitTextRange !== void 0 ? explicitTextRange : (0, _univerjs_docs.getContentInsertRange)(accessor, unitId);
|
|
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 : "";
|
|
219
|
+
const textX = new _univerjs_core.TextX();
|
|
220
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
221
|
+
const customBlocks = (_documentDataModel$ge = (_documentDataModel$ge2 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.customBlocks) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : [];
|
|
222
|
+
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
|
+
if (removeCustomBlocks.length === 0) return false;
|
|
224
|
+
const drawings = (_documentDataModel$ge3 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : {};
|
|
225
|
+
const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
|
|
226
|
+
const removeDrawingSnapshots = removeCustomBlocks.map((block) => drawings[block.blockId]).filter((drawing) => drawing != null);
|
|
227
|
+
const resourceRedoMutations = [];
|
|
228
|
+
const resourceUndoMutations = [];
|
|
229
|
+
const resourceMutationGroups = [];
|
|
230
|
+
for (const block of removeCustomBlocks) {
|
|
231
|
+
var _removeDrawingParam$s;
|
|
232
|
+
const { blockId } = block;
|
|
233
|
+
const drawing = drawings[blockId];
|
|
234
|
+
if (drawing == null) continue;
|
|
235
|
+
const removeDrawingParam = removeDrawingParamById.get(blockId);
|
|
236
|
+
const mutationInfos = drawingAdapterService.getRemoveDrawingMutationInfos({
|
|
237
|
+
unitId,
|
|
238
|
+
subUnitId: (_removeDrawingParam$s = removeDrawingParam === null || removeDrawingParam === void 0 ? void 0 : removeDrawingParam.subUnitId) !== null && _removeDrawingParam$s !== void 0 ? _removeDrawingParam$s : unitId,
|
|
239
|
+
drawing,
|
|
240
|
+
removeDrawings: removeDrawingSnapshots
|
|
241
|
+
});
|
|
242
|
+
if (mutationInfos.redoMutations.length === 0 && mutationInfos.undoMutations.length === 0) continue;
|
|
243
|
+
resourceRedoMutations.push(...mutationInfos.redoMutations);
|
|
244
|
+
resourceUndoMutations.push(...mutationInfos.undoMutations);
|
|
245
|
+
resourceMutationGroups.push(mutationInfos);
|
|
246
|
+
}
|
|
247
|
+
if (!executeResourceMutationGroups(resourceMutationGroups, commandService)) return false;
|
|
248
|
+
const historyId = `doc-drawing-remove-resource:${unitId}:${removeCustomBlocks.map((block) => block.blockId).join(",")}`;
|
|
249
|
+
let batchingDisposable = null;
|
|
250
|
+
if (resourceRedoMutations.length > 0 || resourceUndoMutations.length > 0) {
|
|
251
|
+
batchingDisposable = undoRedoService.__tempBatchingUndoRedo(unitId);
|
|
252
|
+
undoRedoService.pushUndoRedo({
|
|
253
|
+
unitID: unitId,
|
|
254
|
+
redoMutations: resourceRedoMutations,
|
|
255
|
+
undoMutations: resourceUndoMutations,
|
|
256
|
+
id: historyId
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
const memoryCursor = new _univerjs_core.MemoryCursor();
|
|
260
|
+
const cursorIndex = removeCustomBlocks[0].startIndex;
|
|
261
|
+
const textRanges = [{
|
|
262
|
+
startOffset: cursorIndex,
|
|
263
|
+
endOffset: cursorIndex
|
|
264
|
+
}];
|
|
265
|
+
const doMutation = {
|
|
266
|
+
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
267
|
+
params: {
|
|
268
|
+
unitId,
|
|
269
|
+
actions: [],
|
|
270
|
+
textRanges
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const rawActions = [];
|
|
274
|
+
for (const block of removeCustomBlocks) {
|
|
275
|
+
const { startIndex } = block;
|
|
276
|
+
if (startIndex > memoryCursor.cursor) textX.push({
|
|
277
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
278
|
+
len: startIndex - memoryCursor.cursor
|
|
279
|
+
});
|
|
280
|
+
textX.push({
|
|
281
|
+
t: _univerjs_core.TextXActionType.DELETE,
|
|
282
|
+
len: 1
|
|
283
|
+
});
|
|
284
|
+
memoryCursor.moveCursorTo(startIndex + 1);
|
|
285
|
+
}
|
|
286
|
+
rawActions.push(jsonX.editOp(textX.serialize(), (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId)));
|
|
287
|
+
for (const block of removeCustomBlocks) {
|
|
288
|
+
const { blockId } = block;
|
|
289
|
+
const drawingIndex = documentDataModel.getDrawingsOrder().indexOf(blockId);
|
|
290
|
+
rawActions.push(jsonX.removeOp(["drawings", blockId], drawings[blockId]));
|
|
291
|
+
rawActions.push(jsonX.removeOp(["drawingsOrder", drawingIndex], blockId));
|
|
292
|
+
}
|
|
293
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur), null);
|
|
294
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
295
|
+
if (!result && batchingDisposable != null) {
|
|
296
|
+
batchingDisposable.dispose();
|
|
297
|
+
undoRedoService.rollback(historyId, unitId);
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
batchingDisposable === null || batchingDisposable === void 0 || batchingDisposable.dispose();
|
|
301
|
+
return Boolean(result);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
function executeResourceMutationGroups(mutationGroups, commandService) {
|
|
305
|
+
const executedUndoGroups = [];
|
|
306
|
+
for (const mutationGroup of mutationGroups) {
|
|
307
|
+
if (!executeMutations(mutationGroup.redoMutations, commandService)) {
|
|
308
|
+
executeMutationGroups([...executedUndoGroups].reverse(), commandService);
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
executedUndoGroups.push(mutationGroup.undoMutations);
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
function executeMutationGroups(mutationGroups, commandService) {
|
|
316
|
+
mutationGroups.forEach((mutations) => executeMutations(mutations, commandService));
|
|
317
|
+
}
|
|
318
|
+
function executeMutations(mutations, commandService) {
|
|
319
|
+
for (const mutation of mutations) if (!commandService.syncExecuteCommand(mutation.id, mutation.params)) return false;
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
//#endregion
|
|
5
324
|
//#region src/services/doc-drawing.service.ts
|
|
6
325
|
var DocDrawingService = class extends _univerjs_drawing.UnitDrawingService {};
|
|
7
326
|
const IDocDrawingService = (0, _univerjs_core.createIdentifier)("univer.doc.plugin.doc-drawing.service");
|
|
8
327
|
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/commands/commands/set-drawing-arrange.command.ts
|
|
330
|
+
/**
|
|
331
|
+
* The command to arrange drawings.
|
|
332
|
+
*/
|
|
333
|
+
const SetDocDrawingArrangeCommand = {
|
|
334
|
+
id: "doc.command.set-drawing-arrange",
|
|
335
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
336
|
+
handler: (accessor, params) => {
|
|
337
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
338
|
+
const docDrawingService = accessor.get(IDocDrawingService);
|
|
339
|
+
if (params == null) return false;
|
|
340
|
+
const { unitId, subUnitId, drawingIds, arrangeType } = params;
|
|
341
|
+
const drawingOrderMapParam = {
|
|
342
|
+
unitId,
|
|
343
|
+
subUnitId,
|
|
344
|
+
drawingIds
|
|
345
|
+
};
|
|
346
|
+
let jsonOp;
|
|
347
|
+
if (arrangeType === _univerjs_core.ArrangeTypeEnum.forward) jsonOp = docDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
|
|
348
|
+
else if (arrangeType === _univerjs_core.ArrangeTypeEnum.backward) jsonOp = docDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
|
|
349
|
+
else if (arrangeType === _univerjs_core.ArrangeTypeEnum.front) jsonOp = docDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
|
|
350
|
+
else if (arrangeType === _univerjs_core.ArrangeTypeEnum.back) jsonOp = docDrawingService.getBackDrawingsOp(drawingOrderMapParam);
|
|
351
|
+
if (jsonOp == null) return false;
|
|
352
|
+
const { redo } = jsonOp;
|
|
353
|
+
if (redo == null) return false;
|
|
354
|
+
const rawActions = [];
|
|
355
|
+
let redoCopy = _univerjs_core.Tools.deepClone(redo);
|
|
356
|
+
redoCopy = redoCopy.slice(3);
|
|
357
|
+
redoCopy.unshift("drawingsOrder");
|
|
358
|
+
rawActions.push(redoCopy);
|
|
359
|
+
const doMutation = {
|
|
360
|
+
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
361
|
+
params: {
|
|
362
|
+
unitId,
|
|
363
|
+
actions: [],
|
|
364
|
+
textRanges: null
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
doMutation.params.actions = rawActions.reduce((acc, cur) => {
|
|
368
|
+
return _univerjs_core.JSONX.compose(acc, cur);
|
|
369
|
+
}, null);
|
|
370
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
371
|
+
return Boolean(result);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/commands/commands/update-doc-drawing-transform.command.ts
|
|
377
|
+
const UpdateDrawingDocTransformCommand = {
|
|
378
|
+
id: "doc.command.update-drawing-doc-transform",
|
|
379
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
380
|
+
handler: (accessor, params) => {
|
|
381
|
+
var _documentDataModel$ge;
|
|
382
|
+
if (!params) return false;
|
|
383
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
384
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
385
|
+
const { unitId, drawings } = params;
|
|
386
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
387
|
+
if (!documentDataModel) return false;
|
|
388
|
+
const oldDrawings = (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : {};
|
|
389
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
390
|
+
const actions = [];
|
|
391
|
+
for (const { drawingId, key, value } of drawings) {
|
|
392
|
+
var _oldDrawings$drawingI;
|
|
393
|
+
const oldValue = (_oldDrawings$drawingI = oldDrawings[drawingId]) === null || _oldDrawings$drawingI === void 0 || (_oldDrawings$drawingI = _oldDrawings$drawingI.docTransform) === null || _oldDrawings$drawingI === void 0 ? void 0 : _oldDrawings$drawingI[key];
|
|
394
|
+
if (!_univerjs_core.Tools.diffValue(oldValue, value)) {
|
|
395
|
+
const path = [
|
|
396
|
+
"drawings",
|
|
397
|
+
drawingId,
|
|
398
|
+
"docTransform",
|
|
399
|
+
key
|
|
400
|
+
];
|
|
401
|
+
actions.push(oldValue === void 0 ? jsonX.insertOp(path, value) : jsonX.replaceOp(path, oldValue, value));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return Boolean(commandService.syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
|
|
405
|
+
unitId,
|
|
406
|
+
actions: actions.reduce((acc, action) => _univerjs_core.JSONX.compose(acc, action), null),
|
|
407
|
+
textRanges: null,
|
|
408
|
+
debounce: true
|
|
409
|
+
}));
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/commands/commands/update-doc-drawing-wrapping-style.command.ts
|
|
415
|
+
let TextWrappingStyle = /* @__PURE__ */ function(TextWrappingStyle) {
|
|
416
|
+
TextWrappingStyle["INLINE"] = "inline";
|
|
417
|
+
TextWrappingStyle["BEHIND_TEXT"] = "behindText";
|
|
418
|
+
TextWrappingStyle["IN_FRONT_OF_TEXT"] = "inFrontOfText";
|
|
419
|
+
TextWrappingStyle["WRAP_SQUARE"] = "wrapSquare";
|
|
420
|
+
TextWrappingStyle["WRAP_TOP_AND_BOTTOM"] = "wrapTopAndBottom";
|
|
421
|
+
return TextWrappingStyle;
|
|
422
|
+
}({});
|
|
423
|
+
const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
|
|
424
|
+
["inline"]: _univerjs_core.PositionedObjectLayoutType.INLINE,
|
|
425
|
+
["wrapSquare"]: _univerjs_core.PositionedObjectLayoutType.WRAP_SQUARE,
|
|
426
|
+
["wrapTopAndBottom"]: _univerjs_core.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,
|
|
427
|
+
["inFrontOfText"]: _univerjs_core.PositionedObjectLayoutType.WRAP_NONE,
|
|
428
|
+
["behindText"]: _univerjs_core.PositionedObjectLayoutType.WRAP_NONE
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Updates document drawing wrapping styles and optional persisted positions.
|
|
432
|
+
*/
|
|
433
|
+
const UpdateDocDrawingWrappingStyleCommand = {
|
|
434
|
+
id: "doc.command.update-doc-drawing-wrapping-style",
|
|
435
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
436
|
+
handler: (accessor, params) => {
|
|
437
|
+
var _documentDataModel$ge;
|
|
438
|
+
if (!params) return false;
|
|
439
|
+
const { drawings, wrappingStyle, unitId } = params;
|
|
440
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
441
|
+
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
442
|
+
if (!documentDataModel) return false;
|
|
443
|
+
const oldDrawings = (_documentDataModel$ge = documentDataModel.getDrawings()) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : {};
|
|
444
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
445
|
+
const rawActions = [];
|
|
446
|
+
for (const drawing of drawings) {
|
|
447
|
+
const oldDrawing = oldDrawings[drawing.drawingId];
|
|
448
|
+
if (!oldDrawing) continue;
|
|
449
|
+
const layoutType = WRAPPING_STYLE_TO_LAYOUT_TYPE[wrappingStyle];
|
|
450
|
+
if (oldDrawing.layoutType !== layoutType) rawActions.push(jsonX.replaceOp([
|
|
451
|
+
"drawings",
|
|
452
|
+
drawing.drawingId,
|
|
453
|
+
"layoutType"
|
|
454
|
+
], oldDrawing.layoutType, layoutType));
|
|
455
|
+
if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
|
|
456
|
+
const behindDoc = wrappingStyle === "behindText" ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE;
|
|
457
|
+
if (oldDrawing.behindDoc !== behindDoc) rawActions.push(jsonX.replaceOp([
|
|
458
|
+
"drawings",
|
|
459
|
+
drawing.drawingId,
|
|
460
|
+
"behindDoc"
|
|
461
|
+
], oldDrawing.behindDoc, behindDoc));
|
|
462
|
+
}
|
|
463
|
+
if (wrappingStyle !== "inline") for (const key of ["positionH", "positionV"]) {
|
|
464
|
+
var _drawing$docTransform;
|
|
465
|
+
const value = (_drawing$docTransform = drawing.docTransform) === null || _drawing$docTransform === void 0 ? void 0 : _drawing$docTransform[key];
|
|
466
|
+
const oldValue = oldDrawing.docTransform[key];
|
|
467
|
+
if (value && !_univerjs_core.Tools.diffValue(oldValue, value)) rawActions.push(jsonX.replaceOp([
|
|
468
|
+
"drawings",
|
|
469
|
+
drawing.drawingId,
|
|
470
|
+
"docTransform",
|
|
471
|
+
key
|
|
472
|
+
], oldValue, value));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const mutation = {
|
|
476
|
+
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
477
|
+
params: {
|
|
478
|
+
unitId,
|
|
479
|
+
actions: rawActions.reduce((actions, action) => _univerjs_core.JSONX.compose(actions, action), null),
|
|
480
|
+
textRanges: null
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
9
487
|
//#endregion
|
|
10
488
|
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
11
489
|
function __decorateParam(paramIndex, decorator) {
|
|
@@ -40,16 +518,18 @@ function isDocDrawingBehindText(drawing) {
|
|
|
40
518
|
return (drawing === null || drawing === void 0 ? void 0 : drawing.layoutType) === _univerjs_core.PositionedObjectLayoutType.WRAP_NONE && drawing.behindDoc === _univerjs_core.BooleanNumber.TRUE;
|
|
41
519
|
}
|
|
42
520
|
let DocDrawingController = class DocDrawingController extends _univerjs_core.Disposable {
|
|
43
|
-
constructor(_docDrawingService, _drawingManagerService, _resourceManagerService, _univerInstanceService) {
|
|
521
|
+
constructor(_docDrawingService, _drawingManagerService, _resourceManagerService, _univerInstanceService, _commandService) {
|
|
44
522
|
super();
|
|
45
523
|
this._docDrawingService = _docDrawingService;
|
|
46
524
|
this._drawingManagerService = _drawingManagerService;
|
|
47
525
|
this._resourceManagerService = _resourceManagerService;
|
|
48
526
|
this._univerInstanceService = _univerInstanceService;
|
|
527
|
+
this._commandService = _commandService;
|
|
49
528
|
this._init();
|
|
50
529
|
}
|
|
51
530
|
_init() {
|
|
52
531
|
this._initSnapshot();
|
|
532
|
+
this._initCommands();
|
|
53
533
|
}
|
|
54
534
|
_initSnapshot() {
|
|
55
535
|
const toJson = (unitId) => {
|
|
@@ -125,18 +605,28 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
125
605
|
this._drawingManagerService.registerDrawingData(unitId, renderSubDrawings);
|
|
126
606
|
return true;
|
|
127
607
|
}
|
|
608
|
+
_initCommands() {
|
|
609
|
+
[
|
|
610
|
+
InsertDocDrawingCommand,
|
|
611
|
+
RemoveDocDrawingCommand,
|
|
612
|
+
UpdateDrawingDocTransformCommand,
|
|
613
|
+
UpdateDocDrawingWrappingStyleCommand,
|
|
614
|
+
SetDocDrawingArrangeCommand
|
|
615
|
+
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
616
|
+
}
|
|
128
617
|
};
|
|
129
618
|
DocDrawingController = __decorate([
|
|
130
619
|
__decorateParam(0, IDocDrawingService),
|
|
131
620
|
__decorateParam(1, _univerjs_drawing.IDrawingManagerService),
|
|
132
621
|
__decorateParam(2, _univerjs_core.IResourceManagerService),
|
|
133
|
-
__decorateParam(3, _univerjs_core.IUniverInstanceService)
|
|
622
|
+
__decorateParam(3, _univerjs_core.IUniverInstanceService),
|
|
623
|
+
__decorateParam(4, _univerjs_core.ICommandService)
|
|
134
624
|
], DocDrawingController);
|
|
135
625
|
|
|
136
626
|
//#endregion
|
|
137
627
|
//#region package.json
|
|
138
628
|
var name = "@univerjs/docs-drawing";
|
|
139
|
-
var version = "1.0.0-alpha.
|
|
629
|
+
var version = "1.0.0-alpha.4";
|
|
140
630
|
|
|
141
631
|
//#endregion
|
|
142
632
|
//#region src/config/config.ts
|
|
@@ -159,48 +649,6 @@ const DOCS_DRAWING_PLUGIN_CONFIG_KEY = "docs-drawing.config";
|
|
|
159
649
|
const configSymbol = Symbol(DOCS_DRAWING_PLUGIN_CONFIG_KEY);
|
|
160
650
|
const defaultPluginConfig = {};
|
|
161
651
|
|
|
162
|
-
//#endregion
|
|
163
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
164
|
-
function _typeof(o) {
|
|
165
|
-
"@babel/helpers - typeof";
|
|
166
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
167
|
-
return typeof o;
|
|
168
|
-
} : function(o) {
|
|
169
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
170
|
-
}, _typeof(o);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
175
|
-
function toPrimitive(t, r) {
|
|
176
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
177
|
-
var e = t[Symbol.toPrimitive];
|
|
178
|
-
if (void 0 !== e) {
|
|
179
|
-
var i = e.call(t, r || "default");
|
|
180
|
-
if ("object" != _typeof(i)) return i;
|
|
181
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
182
|
-
}
|
|
183
|
-
return ("string" === r ? String : Number)(t);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
188
|
-
function toPropertyKey(t) {
|
|
189
|
-
var i = toPrimitive(t, "string");
|
|
190
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
//#endregion
|
|
194
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
195
|
-
function _defineProperty(e, r, t) {
|
|
196
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
197
|
-
value: t,
|
|
198
|
-
enumerable: !0,
|
|
199
|
-
configurable: !0,
|
|
200
|
-
writable: !0
|
|
201
|
-
}) : e[r] = t, e;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
652
|
//#endregion
|
|
205
653
|
//#region src/plugin.ts
|
|
206
654
|
let UniverDocsDrawingPlugin = class UniverDocsDrawingPlugin extends _univerjs_core.Plugin {
|
|
@@ -215,6 +663,8 @@ let UniverDocsDrawingPlugin = class UniverDocsDrawingPlugin extends _univerjs_co
|
|
|
215
663
|
onStarting() {
|
|
216
664
|
[
|
|
217
665
|
[DocDrawingController],
|
|
666
|
+
[DocDrawingAdapterService],
|
|
667
|
+
[IDocDrawingAdapterService, { useClass: DocDrawingAdapterService }],
|
|
218
668
|
[DocDrawingService],
|
|
219
669
|
[IDocDrawingService, { useClass: DocDrawingService }]
|
|
220
670
|
].forEach((dependency) => this._injector.add(dependency));
|
|
@@ -229,6 +679,7 @@ UniverDocsDrawingPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inje
|
|
|
229
679
|
|
|
230
680
|
//#endregion
|
|
231
681
|
exports.DOCS_DRAWING_PLUGIN = DOCS_DRAWING_PLUGIN;
|
|
682
|
+
exports.DocDrawingAdapterService = DocDrawingAdapterService;
|
|
232
683
|
Object.defineProperty(exports, 'DocDrawingController', {
|
|
233
684
|
enumerable: true,
|
|
234
685
|
get: function () {
|
|
@@ -236,11 +687,19 @@ Object.defineProperty(exports, 'DocDrawingController', {
|
|
|
236
687
|
}
|
|
237
688
|
});
|
|
238
689
|
exports.DocDrawingService = DocDrawingService;
|
|
690
|
+
exports.IDocDrawingAdapterService = IDocDrawingAdapterService;
|
|
239
691
|
exports.IDocDrawingService = IDocDrawingService;
|
|
692
|
+
exports.InsertDocDrawingCommand = InsertDocDrawingCommand;
|
|
693
|
+
exports.RemoveDocDrawingCommand = RemoveDocDrawingCommand;
|
|
694
|
+
exports.SetDocDrawingArrangeCommand = SetDocDrawingArrangeCommand;
|
|
695
|
+
exports.TextWrappingStyle = TextWrappingStyle;
|
|
240
696
|
Object.defineProperty(exports, 'UniverDocsDrawingPlugin', {
|
|
241
697
|
enumerable: true,
|
|
242
698
|
get: function () {
|
|
243
699
|
return UniverDocsDrawingPlugin;
|
|
244
700
|
}
|
|
245
701
|
});
|
|
702
|
+
exports.UpdateDocDrawingWrappingStyleCommand = UpdateDocDrawingWrappingStyleCommand;
|
|
703
|
+
exports.UpdateDrawingDocTransformCommand = UpdateDrawingDocTransformCommand;
|
|
704
|
+
exports.WRAPPING_STYLE_TO_LAYOUT_TYPE = WRAPPING_STYLE_TO_LAYOUT_TYPE;
|
|
246
705
|
exports.getDocDrawingRenderOrder = getDocDrawingRenderOrder;
|