@univerjs/docs-drawing 1.0.0-insiders.20260813-7c9aa50 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +1 -2
- package/lib/cjs/facade.js +13 -8
- package/lib/cjs/index.js +180 -53
- package/lib/es/facade.js +15 -10
- package/lib/es/index.js +181 -56
- package/lib/facade.js +15 -10
- package/lib/index.js +181 -56
- package/lib/types/commands/commands/remove-doc-drawing.command.d.ts +2 -1
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +6 -2
- package/lib/types/commands/commands/update-doc-drawing-transform.command.d.ts +4 -3
- package/lib/types/commands/commands/update-doc-drawing-wrapping-style.command.d.ts +0 -6
- package/lib/types/controllers/doc-drawing.controller.d.ts +1 -0
- package/lib/types/facade/f-document-image.d.ts +3 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/services/doc-drawing-source.d.ts +27 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/index.js
CHANGED
|
@@ -11,7 +11,7 @@ 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$notes, _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);
|
|
@@ -23,11 +23,17 @@ const InsertDocDrawingCommand = {
|
|
|
23
23
|
const { segmentId = "" } = resolvedTextRange;
|
|
24
24
|
if (!((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody())) return false;
|
|
25
25
|
const snapshot = documentDataModel.getSnapshot();
|
|
26
|
-
const
|
|
26
|
+
const isFootnote = !!((_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId]);
|
|
27
|
+
if (isFootnote && drawings.some((drawing) => drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE)) return false;
|
|
28
|
+
let targetDrawings = !!((_snapshot$headers = snapshot.headers) === null || _snapshot$headers === void 0 ? void 0 : _snapshot$headers[segmentId]) || !!((_snapshot$footers = snapshot.footers) === null || _snapshot$footers === void 0 ? void 0 : _snapshot$footers[segmentId]) ? drawings.map((drawing) => ({
|
|
27
29
|
...drawing,
|
|
28
30
|
isMultiTransform: _univerjs_core.BooleanNumber.TRUE,
|
|
29
31
|
transforms: drawing.transforms ?? (drawing.transform ? [drawing.transform] : null)
|
|
30
32
|
})) : drawings;
|
|
33
|
+
if (isFootnote) targetDrawings = drawings.map((drawing) => ({
|
|
34
|
+
...drawing,
|
|
35
|
+
layoutType: _univerjs_core.PositionedObjectLayoutType.INLINE
|
|
36
|
+
}));
|
|
31
37
|
const actions = _univerjs_core.BuildTextUtils.drawing.add({
|
|
32
38
|
selection: resolvedTextRange,
|
|
33
39
|
documentDataModel,
|
|
@@ -38,6 +44,7 @@ const InsertDocDrawingCommand = {
|
|
|
38
44
|
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
39
45
|
params: {
|
|
40
46
|
unitId,
|
|
47
|
+
segmentId,
|
|
41
48
|
actions: [],
|
|
42
49
|
textRanges: []
|
|
43
50
|
}
|
|
@@ -61,7 +68,7 @@ function resolveDocDrawingInsertTextRange(accessor, unitId, textRange) {
|
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
//#endregion
|
|
64
|
-
//#region \0@oxc-project+runtime@0.
|
|
71
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
65
72
|
function _typeof(o) {
|
|
66
73
|
"@babel/helpers - typeof";
|
|
67
74
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -72,7 +79,7 @@ function _typeof(o) {
|
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
//#endregion
|
|
75
|
-
//#region \0@oxc-project+runtime@0.
|
|
82
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
76
83
|
function toPrimitive(t, r) {
|
|
77
84
|
if ("object" != _typeof(t) || !t) return t;
|
|
78
85
|
var e = t[Symbol.toPrimitive];
|
|
@@ -85,14 +92,14 @@ function toPrimitive(t, r) {
|
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
//#endregion
|
|
88
|
-
//#region \0@oxc-project+runtime@0.
|
|
95
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
89
96
|
function toPropertyKey(t) {
|
|
90
97
|
var i = toPrimitive(t, "string");
|
|
91
98
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
//#endregion
|
|
95
|
-
//#region \0@oxc-project+runtime@0.
|
|
102
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
96
103
|
function _defineProperty(e, r, t) {
|
|
97
104
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
98
105
|
value: t,
|
|
@@ -140,13 +147,60 @@ var DocDrawingAdapterService = class {
|
|
|
140
147
|
}
|
|
141
148
|
};
|
|
142
149
|
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/services/doc-drawing-source.ts
|
|
152
|
+
/** Resolve persisted drawing ownership independently of the current text selection. */
|
|
153
|
+
function findDocDrawing(snapshot, drawingId) {
|
|
154
|
+
var _snapshot$drawings;
|
|
155
|
+
const drawing = (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingId];
|
|
156
|
+
if (drawing) return {
|
|
157
|
+
drawing,
|
|
158
|
+
path: ["drawings", drawingId],
|
|
159
|
+
segmentId: ""
|
|
160
|
+
};
|
|
161
|
+
for (const [segmentId, note] of Object.entries(snapshot.notes ?? {})) {
|
|
162
|
+
var _note$drawings;
|
|
163
|
+
const drawing = (_note$drawings = note.drawings) === null || _note$drawings === void 0 ? void 0 : _note$drawings[drawingId];
|
|
164
|
+
if (drawing) return {
|
|
165
|
+
drawing,
|
|
166
|
+
path: [
|
|
167
|
+
"notes",
|
|
168
|
+
segmentId,
|
|
169
|
+
"drawings",
|
|
170
|
+
drawingId
|
|
171
|
+
],
|
|
172
|
+
segmentId
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** The render registry is flat; persisted note resources retain their own scope. */
|
|
177
|
+
function collectDocDrawings(snapshot) {
|
|
178
|
+
let drawings = snapshot.drawings ?? {};
|
|
179
|
+
let drawingsOrder = snapshot.drawingsOrder ?? Object.keys(drawings);
|
|
180
|
+
let copied = false;
|
|
181
|
+
for (const note of Object.values(snapshot.notes ?? {})) {
|
|
182
|
+
if (!note.drawings || Object.keys(note.drawings).length === 0) continue;
|
|
183
|
+
if (!copied) {
|
|
184
|
+
drawings = { ...drawings };
|
|
185
|
+
drawingsOrder = [...drawingsOrder];
|
|
186
|
+
copied = true;
|
|
187
|
+
}
|
|
188
|
+
Object.assign(drawings, note.drawings);
|
|
189
|
+
drawingsOrder.push(...note.drawingsOrder ?? Object.keys(note.drawings));
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
drawings,
|
|
193
|
+
drawingsOrder
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
143
197
|
//#endregion
|
|
144
198
|
//#region src/commands/commands/remove-doc-drawing.command.ts
|
|
145
199
|
const RemoveDocDrawingCommand = {
|
|
146
200
|
id: "doc.command.remove-doc-image",
|
|
147
201
|
type: _univerjs_core.CommandType.COMMAND,
|
|
148
202
|
handler: (accessor, params) => {
|
|
149
|
-
var _documentDataModel$ge;
|
|
203
|
+
var _snapshot$notes, _documentDataModel$ge;
|
|
150
204
|
if (!params) return false;
|
|
151
205
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
152
206
|
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
@@ -158,20 +212,34 @@ const RemoveDocDrawingCommand = {
|
|
|
158
212
|
if (!documentDataModel || removeDrawings.length === 0) return false;
|
|
159
213
|
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
160
214
|
const contentInsertRange = (!textRange ? null : (0, _univerjs_docs.normalizeTextRange)(textRange)) ?? (0, _univerjs_docs.getContentInsertRange)(accessor, unitId);
|
|
161
|
-
const
|
|
215
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
216
|
+
const noteSegments = removeDrawings.map(({ drawingId }) => {
|
|
217
|
+
var _findDocDrawing;
|
|
218
|
+
return ((_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.segmentId) ?? "";
|
|
219
|
+
});
|
|
220
|
+
if (noteSegments.some((id) => id !== noteSegments[0])) return false;
|
|
221
|
+
const segmentId = noteSegments[0] || ((contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? "");
|
|
222
|
+
const footnote = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
|
|
223
|
+
const source = footnote ?? snapshot;
|
|
224
|
+
const prefix = footnote ? ["notes", segmentId] : [];
|
|
162
225
|
const textX = new _univerjs_core.TextX();
|
|
163
226
|
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
164
227
|
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) ?? [];
|
|
165
228
|
const removeCustomBlocks = removeDrawings.map((drawing) => customBlocks.find((customBlock) => customBlock.blockId === drawing.drawingId)).filter((block) => !!block).sort((a, b) => a.startIndex > b.startIndex ? 1 : -1);
|
|
166
229
|
if (removeCustomBlocks.length === 0) return false;
|
|
167
|
-
const drawings =
|
|
230
|
+
const drawings = source.drawings ?? {};
|
|
168
231
|
const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
|
|
169
|
-
const
|
|
232
|
+
const removeIds = new Set(removeCustomBlocks.map((block) => block.blockId));
|
|
233
|
+
let previousSize = -1;
|
|
234
|
+
while (previousSize !== removeIds.size) {
|
|
235
|
+
previousSize = removeIds.size;
|
|
236
|
+
for (const drawing of Object.values(drawings)) if (drawing.groupId && removeIds.has(drawing.groupId)) removeIds.add(drawing.drawingId);
|
|
237
|
+
}
|
|
238
|
+
const removeDrawingSnapshots = [...removeIds].map((id) => drawings[id]).filter((drawing) => drawing != null);
|
|
170
239
|
const resourceRedoMutations = [];
|
|
171
240
|
const resourceUndoMutations = [];
|
|
172
241
|
const resourceMutationGroups = [];
|
|
173
|
-
for (const
|
|
174
|
-
const { blockId } = block;
|
|
242
|
+
for (const blockId of removeIds) {
|
|
175
243
|
const drawing = drawings[blockId];
|
|
176
244
|
if (drawing == null) continue;
|
|
177
245
|
const removeDrawingParam = removeDrawingParamById.get(blockId);
|
|
@@ -204,12 +272,15 @@ const RemoveDocDrawingCommand = {
|
|
|
204
272
|
startOffset: cursorIndex,
|
|
205
273
|
endOffset: cursorIndex
|
|
206
274
|
}];
|
|
275
|
+
const historyActions = getHistoryActions(removeDrawings);
|
|
207
276
|
const doMutation = {
|
|
208
277
|
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
209
278
|
params: {
|
|
210
279
|
unitId,
|
|
280
|
+
segmentId,
|
|
211
281
|
actions: [],
|
|
212
|
-
textRanges
|
|
282
|
+
textRanges,
|
|
283
|
+
historyActions
|
|
213
284
|
}
|
|
214
285
|
};
|
|
215
286
|
const rawActions = [];
|
|
@@ -226,11 +297,20 @@ const RemoveDocDrawingCommand = {
|
|
|
226
297
|
memoryCursor.moveCursorTo(startIndex + 1);
|
|
227
298
|
}
|
|
228
299
|
rawActions.push(jsonX.editOp(textX.serialize(), (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId)));
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
rawActions.push(jsonX.removeOp([
|
|
300
|
+
const drawingOrder = source.drawingsOrder ?? [];
|
|
301
|
+
const resourceIds = [...removeIds].sort((left, right) => drawingOrder.indexOf(right) - drawingOrder.indexOf(left));
|
|
302
|
+
for (const blockId of resourceIds) {
|
|
303
|
+
const drawingIndex = drawingOrder.indexOf(blockId);
|
|
304
|
+
if (drawings[blockId]) rawActions.push(jsonX.removeOp([
|
|
305
|
+
...prefix,
|
|
306
|
+
"drawings",
|
|
307
|
+
blockId
|
|
308
|
+
], drawings[blockId]));
|
|
309
|
+
if (drawingIndex >= 0) rawActions.push(jsonX.removeOp([
|
|
310
|
+
...prefix,
|
|
311
|
+
"drawingsOrder",
|
|
312
|
+
drawingIndex
|
|
313
|
+
], blockId));
|
|
234
314
|
}
|
|
235
315
|
doMutation.params.actions = rawActions.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur), null);
|
|
236
316
|
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
@@ -243,6 +323,17 @@ const RemoveDocDrawingCommand = {
|
|
|
243
323
|
return Boolean(result);
|
|
244
324
|
}
|
|
245
325
|
};
|
|
326
|
+
function getHistoryActions(drawings) {
|
|
327
|
+
const historyActions = drawings.flatMap((drawing) => {
|
|
328
|
+
switch (drawing.drawingType) {
|
|
329
|
+
case _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE: return [_univerjs_docs.DocHistoryAction.DeleteImage];
|
|
330
|
+
case _univerjs_core.DrawingTypeEnum.DRAWING_SHAPE: return [_univerjs_docs.DocHistoryAction.DeleteShape];
|
|
331
|
+
case _univerjs_core.DrawingTypeEnum.DRAWING_CHART: return [_univerjs_docs.DocHistoryAction.DeleteChart];
|
|
332
|
+
default: return [];
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
return [...new Set(historyActions)];
|
|
336
|
+
}
|
|
246
337
|
function executeResourceMutationGroups(mutationGroups, commandService) {
|
|
247
338
|
const executedUndoGroups = [];
|
|
248
339
|
for (const mutationGroup of mutationGroups) {
|
|
@@ -284,6 +375,16 @@ function getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType) {
|
|
|
284
375
|
}
|
|
285
376
|
return arrangedDrawingOrder;
|
|
286
377
|
}
|
|
378
|
+
function getDrawingOrderAtIndex(drawingOrder, drawingIds, zOrder) {
|
|
379
|
+
if (drawingIds.length !== 1) return [...drawingOrder];
|
|
380
|
+
const arrangedDrawingOrder = [...drawingOrder];
|
|
381
|
+
const currentIndex = arrangedDrawingOrder.indexOf(drawingIds[0]);
|
|
382
|
+
if (currentIndex < 0) return arrangedDrawingOrder;
|
|
383
|
+
const [drawingId] = arrangedDrawingOrder.splice(currentIndex, 1);
|
|
384
|
+
const targetIndex = (0, _univerjs_core.normalizeDrawingOrderIndex)(zOrder, drawingOrder.length);
|
|
385
|
+
arrangedDrawingOrder.splice(targetIndex, 0, drawingId);
|
|
386
|
+
return arrangedDrawingOrder;
|
|
387
|
+
}
|
|
287
388
|
/**
|
|
288
389
|
* Converts the target order into granular JSONX move operations. This avoids replacing
|
|
289
390
|
* the entire drawingsOrder array and keeps collaboration conflicts scoped to moved items.
|
|
@@ -312,11 +413,11 @@ const SetDocDrawingArrangeCommand = {
|
|
|
312
413
|
handler: (accessor, params) => {
|
|
313
414
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
314
415
|
if (params == null) return false;
|
|
315
|
-
const { unitId, drawingIds
|
|
416
|
+
const { unitId, drawingIds } = params;
|
|
316
417
|
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
317
418
|
const drawingOrder = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDrawingsOrder();
|
|
318
419
|
if (!drawingOrder) return false;
|
|
319
|
-
const actions = createDrawingOrderActions(drawingOrder, getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType));
|
|
420
|
+
const actions = createDrawingOrderActions(drawingOrder, params.zOrder !== void 0 ? getDrawingOrderAtIndex(drawingOrder, drawingIds, params.zOrder) : getArrangedDrawingOrder(drawingOrder, drawingIds, params.arrangeType));
|
|
320
421
|
if (_univerjs_core.JSONX.isNoop(actions)) return false;
|
|
321
422
|
const result = commandService.syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
|
|
322
423
|
unitId,
|
|
@@ -339,24 +440,33 @@ const UpdateDrawingDocTransformCommand = {
|
|
|
339
440
|
const { unitId, drawings } = params;
|
|
340
441
|
const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
341
442
|
if (!documentDataModel) return false;
|
|
342
|
-
const
|
|
443
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
444
|
+
const historyAction = drawings.length > 0 && drawings.every(({ drawingId }) => {
|
|
445
|
+
var _findDocDrawing;
|
|
446
|
+
return ((_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE;
|
|
447
|
+
}) ? _univerjs_docs.DocHistoryAction.UpdateImage : void 0;
|
|
343
448
|
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
344
449
|
const actions = [];
|
|
345
450
|
for (const { drawingId, key, value } of drawings) {
|
|
346
|
-
var
|
|
347
|
-
const
|
|
451
|
+
var _oldDrawing$docTransf;
|
|
452
|
+
const source = findDocDrawing(snapshot, drawingId);
|
|
453
|
+
if (!source) return false;
|
|
454
|
+
const oldDrawing = source.drawing;
|
|
455
|
+
const isImageProperty = key === "srcRect" || key === "prstGeom" || key === "adjustValues";
|
|
456
|
+
const oldValue = isImageProperty ? key in oldDrawing ? Reflect.get(oldDrawing, key) : void 0 : oldDrawing === null || oldDrawing === void 0 || (_oldDrawing$docTransf = oldDrawing.docTransform) === null || _oldDrawing$docTransf === void 0 ? void 0 : _oldDrawing$docTransf[key];
|
|
348
457
|
if (!_univerjs_core.Tools.diffValue(oldValue, value)) {
|
|
349
|
-
const path = [
|
|
350
|
-
|
|
351
|
-
drawingId,
|
|
458
|
+
const path = isImageProperty ? [...source.path, key] : [
|
|
459
|
+
...source.path,
|
|
352
460
|
"docTransform",
|
|
353
461
|
key
|
|
354
462
|
];
|
|
355
|
-
|
|
463
|
+
const action = oldValue === void 0 ? jsonX.insertOp(path, value) : jsonX.replaceOp(path, oldValue, value);
|
|
464
|
+
actions.push(action);
|
|
356
465
|
}
|
|
357
466
|
}
|
|
358
467
|
return Boolean(commandService.syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
|
|
359
468
|
unitId,
|
|
469
|
+
historyAction,
|
|
360
470
|
actions: actions.reduce((acc, action) => _univerjs_core.JSONX.compose(acc, action), null),
|
|
361
471
|
textRanges: null,
|
|
362
472
|
debounce: true
|
|
@@ -425,33 +535,33 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
425
535
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
426
536
|
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
427
537
|
if (!documentDataModel) return false;
|
|
428
|
-
const
|
|
538
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
539
|
+
if (wrappingStyle !== "inline" && drawings.some(({ drawingId }) => {
|
|
540
|
+
var _findDocDrawing;
|
|
541
|
+
return (_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.segmentId;
|
|
542
|
+
})) return false;
|
|
543
|
+
const historyAction = drawings.length > 0 && drawings.every(({ drawingId }) => {
|
|
544
|
+
var _findDocDrawing2;
|
|
545
|
+
return ((_findDocDrawing2 = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing2 === void 0 ? void 0 : _findDocDrawing2.drawing.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE;
|
|
546
|
+
}) ? _univerjs_docs.DocHistoryAction.UpdateImage : void 0;
|
|
429
547
|
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
430
548
|
const rawActions = [];
|
|
431
549
|
for (const drawing of drawings) {
|
|
432
|
-
const
|
|
433
|
-
|
|
550
|
+
const source = findDocDrawing(snapshot, drawing.drawingId);
|
|
551
|
+
const oldDrawing = source === null || source === void 0 ? void 0 : source.drawing;
|
|
552
|
+
if (!oldDrawing || !source) continue;
|
|
434
553
|
const layoutType = WRAPPING_STYLE_TO_LAYOUT_TYPE[wrappingStyle];
|
|
435
|
-
if (oldDrawing.layoutType !== layoutType) rawActions.push(jsonX.replaceOp([
|
|
436
|
-
"drawings",
|
|
437
|
-
drawing.drawingId,
|
|
438
|
-
"layoutType"
|
|
439
|
-
], oldDrawing.layoutType, layoutType));
|
|
554
|
+
if (oldDrawing.layoutType !== layoutType) rawActions.push(jsonX.replaceOp([...source.path, "layoutType"], oldDrawing.layoutType, layoutType));
|
|
440
555
|
if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
|
|
441
556
|
const behindDoc = wrappingStyle === "behindText" ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE;
|
|
442
|
-
if (oldDrawing.behindDoc !== behindDoc) rawActions.push(jsonX.replaceOp([
|
|
443
|
-
"drawings",
|
|
444
|
-
drawing.drawingId,
|
|
445
|
-
"behindDoc"
|
|
446
|
-
], oldDrawing.behindDoc, behindDoc));
|
|
557
|
+
if (oldDrawing.behindDoc !== behindDoc) rawActions.push(jsonX.replaceOp([...source.path, "behindDoc"], oldDrawing.behindDoc, behindDoc));
|
|
447
558
|
}
|
|
448
559
|
if (wrappingStyle !== "inline") for (const key of ["positionH", "positionV"]) {
|
|
449
560
|
var _drawing$docTransform;
|
|
450
561
|
const value = (_drawing$docTransform = drawing.docTransform) === null || _drawing$docTransform === void 0 ? void 0 : _drawing$docTransform[key];
|
|
451
562
|
const oldValue = oldDrawing.docTransform[key];
|
|
452
563
|
if (value && !_univerjs_core.Tools.diffValue(oldValue, value)) rawActions.push(jsonX.replaceOp([
|
|
453
|
-
|
|
454
|
-
drawing.drawingId,
|
|
564
|
+
...source.path,
|
|
455
565
|
"docTransform",
|
|
456
566
|
key
|
|
457
567
|
], oldValue, value));
|
|
@@ -461,6 +571,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
|
|
|
461
571
|
id: _univerjs_docs.RichTextEditingMutation.id,
|
|
462
572
|
params: {
|
|
463
573
|
unitId,
|
|
574
|
+
historyAction,
|
|
464
575
|
actions: rawActions.reduce((actions, action) => _univerjs_core.JSONX.compose(actions, action), null),
|
|
465
576
|
textRanges: null
|
|
466
577
|
}
|
|
@@ -475,7 +586,7 @@ var DocDrawingService = class extends _univerjs_drawing.UnitDrawingService {};
|
|
|
475
586
|
const IDocDrawingService = (0, _univerjs_core.createIdentifier)("univer.doc.plugin.doc-drawing.service");
|
|
476
587
|
|
|
477
588
|
//#endregion
|
|
478
|
-
//#region \0@oxc-project+runtime@0.
|
|
589
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
479
590
|
function __decorateParam(paramIndex, decorator) {
|
|
480
591
|
return function(target, key) {
|
|
481
592
|
decorator(target, key, paramIndex);
|
|
@@ -483,7 +594,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
483
594
|
}
|
|
484
595
|
|
|
485
596
|
//#endregion
|
|
486
|
-
//#region \0@oxc-project+runtime@0.
|
|
597
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
487
598
|
function __decorate(decorators, target, key, desc) {
|
|
488
599
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
489
600
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -541,7 +652,7 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
541
652
|
};
|
|
542
653
|
try {
|
|
543
654
|
return JSON.parse(json);
|
|
544
|
-
} catch
|
|
655
|
+
} catch {
|
|
545
656
|
return {
|
|
546
657
|
data: {},
|
|
547
658
|
order: []
|
|
@@ -554,10 +665,7 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
554
665
|
toJson: (unitId) => toJson(unitId),
|
|
555
666
|
parseJson: (json) => parseJson(json),
|
|
556
667
|
onUnLoad: (unitId) => {
|
|
557
|
-
this.
|
|
558
|
-
data: {},
|
|
559
|
-
order: []
|
|
560
|
-
});
|
|
668
|
+
this._unloadDrawingDataForUnit(unitId);
|
|
561
669
|
},
|
|
562
670
|
onLoad: (unitId, value) => {
|
|
563
671
|
this._setDrawingDataForUnit(unitId, {
|
|
@@ -567,6 +675,12 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
567
675
|
}
|
|
568
676
|
}));
|
|
569
677
|
}
|
|
678
|
+
_unloadDrawingDataForUnit(unitId) {
|
|
679
|
+
const documentDataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
680
|
+
documentDataModel === null || documentDataModel === void 0 || documentDataModel.resetDrawing({}, []);
|
|
681
|
+
this._docDrawingService.removeDrawingDataForUnit(unitId);
|
|
682
|
+
this._drawingManagerService.removeDrawingDataForUnit(unitId);
|
|
683
|
+
}
|
|
570
684
|
_setDrawingDataForUnit(unitId, drawingMapItem) {
|
|
571
685
|
const documentDataModel = this._univerInstanceService.getUnit(unitId);
|
|
572
686
|
if (documentDataModel == null) return;
|
|
@@ -577,17 +691,28 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
|
|
|
577
691
|
const dataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
578
692
|
if (!dataModel) return false;
|
|
579
693
|
const subUnitId = unitId;
|
|
580
|
-
const drawingDataModels = dataModel.
|
|
581
|
-
const drawingOrderModel = dataModel.getDrawingsOrder();
|
|
694
|
+
const { drawings: drawingDataModels, drawingsOrder: drawingOrderModel } = collectDocDrawings(dataModel.getSnapshot());
|
|
582
695
|
if (!drawingDataModels || !drawingOrderModel) return false;
|
|
696
|
+
const normalizedDrawingData = {};
|
|
697
|
+
for (const [drawingId, drawing] of Object.entries(drawingDataModels)) normalizedDrawingData[drawingId] = drawing.unitId === unitId && drawing.subUnitId === subUnitId ? drawing : {
|
|
698
|
+
...drawing,
|
|
699
|
+
unitId,
|
|
700
|
+
subUnitId
|
|
701
|
+
};
|
|
583
702
|
const subDrawings = { [subUnitId]: {
|
|
584
703
|
unitId,
|
|
585
704
|
subUnitId,
|
|
586
|
-
data:
|
|
705
|
+
data: normalizedDrawingData,
|
|
587
706
|
order: drawingOrderModel
|
|
588
707
|
} };
|
|
708
|
+
const renderDrawingData = {};
|
|
709
|
+
for (const [drawingId, drawing] of Object.entries(normalizedDrawingData)) renderDrawingData[drawingId] = {
|
|
710
|
+
...drawing,
|
|
711
|
+
hidden: true
|
|
712
|
+
};
|
|
589
713
|
const renderSubDrawings = { [subUnitId]: {
|
|
590
714
|
...subDrawings[subUnitId],
|
|
715
|
+
data: renderDrawingData,
|
|
591
716
|
order: getDocDrawingRenderOrder(drawingOrderModel, drawingDataModels)
|
|
592
717
|
} };
|
|
593
718
|
this._docDrawingService.registerDrawingData(unitId, subDrawings);
|
|
@@ -615,7 +740,7 @@ DocDrawingController = __decorate([
|
|
|
615
740
|
//#endregion
|
|
616
741
|
//#region package.json
|
|
617
742
|
var name = "@univerjs/docs-drawing";
|
|
618
|
-
var version = "1.0.0
|
|
743
|
+
var version = "1.0.0";
|
|
619
744
|
|
|
620
745
|
//#endregion
|
|
621
746
|
//#region src/config/config.ts
|
|
@@ -695,4 +820,6 @@ Object.defineProperty(exports, 'UniverDocsDrawingPlugin', {
|
|
|
695
820
|
exports.UpdateDocDrawingWrappingStyleCommand = UpdateDocDrawingWrappingStyleCommand;
|
|
696
821
|
exports.UpdateDrawingDocTransformCommand = UpdateDrawingDocTransformCommand;
|
|
697
822
|
exports.WRAPPING_STYLE_TO_LAYOUT_TYPE = WRAPPING_STYLE_TO_LAYOUT_TYPE;
|
|
823
|
+
exports.collectDocDrawings = collectDocDrawings;
|
|
824
|
+
exports.findDocDrawing = findDocDrawing;
|
|
698
825
|
exports.getDocDrawingRenderOrder = getDocDrawingRenderOrder;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { ArrangeTypeEnum, BooleanNumber, DrawingTypeEnum, ICommandService, IImageIoService, IURLImageService, ImageSourceType, ObjectRelativeFromH, ObjectRelativeFromV, WrapTextType, generateRandomId } from "@univerjs/core";
|
|
2
2
|
import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
|
|
3
|
-
import { InsertDocDrawingCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, TextWrappingStyle, UpdateDocDrawingWrappingStyleCommand, UpdateDrawingDocTransformCommand, WRAPPING_STYLE_TO_LAYOUT_TYPE } from "@univerjs/docs-drawing";
|
|
3
|
+
import { InsertDocDrawingCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, TextWrappingStyle, UpdateDocDrawingWrappingStyleCommand, UpdateDrawingDocTransformCommand, WRAPPING_STYLE_TO_LAYOUT_TYPE, collectDocDrawings, findDocDrawing } from "@univerjs/docs-drawing";
|
|
4
4
|
import { FDocument } from "@univerjs/docs/facade";
|
|
5
5
|
import { DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, getImageSize } from "@univerjs/drawing";
|
|
6
|
-
import { FEnum } from "@univerjs/core/facade";
|
|
6
|
+
import { FBase, FEnum } from "@univerjs/core/facade";
|
|
7
7
|
|
|
8
8
|
//#region src/facade/f-document-image.ts
|
|
9
9
|
/**
|
|
10
10
|
* Facade API for an image in a document.
|
|
11
11
|
* @hideconstructor
|
|
12
12
|
*/
|
|
13
|
-
var FDocumentImage = class {
|
|
13
|
+
var FDocumentImage = class extends FBase {
|
|
14
14
|
constructor(_document, _imageId, _injector) {
|
|
15
|
+
super();
|
|
15
16
|
this._document = _document;
|
|
16
17
|
this._imageId = _imageId;
|
|
17
18
|
this._injector = _injector;
|
|
@@ -164,8 +165,8 @@ var FDocumentImage = class {
|
|
|
164
165
|
* ```
|
|
165
166
|
*/
|
|
166
167
|
getImageData() {
|
|
167
|
-
var
|
|
168
|
-
const drawing = (
|
|
168
|
+
var _findDocDrawing;
|
|
169
|
+
const drawing = (_findDocDrawing = findDocDrawing(this._document.getDocumentDataModel().getSnapshot(), this._imageId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing;
|
|
169
170
|
if (!drawing || drawing.drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return null;
|
|
170
171
|
return drawing;
|
|
171
172
|
}
|
|
@@ -404,7 +405,7 @@ var FDocumentImage = class {
|
|
|
404
405
|
});
|
|
405
406
|
}
|
|
406
407
|
_getTextRange() {
|
|
407
|
-
const { body, headers = {}, footers = {} } = this._document.getDocumentDataModel().getSnapshot();
|
|
408
|
+
const { body, headers = {}, footers = {}, notes = {} } = this._document.getDocumentDataModel().getSnapshot();
|
|
408
409
|
const segments = [
|
|
409
410
|
{
|
|
410
411
|
segmentId: "",
|
|
@@ -417,6 +418,10 @@ var FDocumentImage = class {
|
|
|
417
418
|
...Object.entries(footers).map(([segmentId, footer]) => ({
|
|
418
419
|
segmentId,
|
|
419
420
|
body: footer.body
|
|
421
|
+
})),
|
|
422
|
+
...Object.entries(notes).map(([segmentId, note]) => ({
|
|
423
|
+
segmentId,
|
|
424
|
+
body: note.body
|
|
420
425
|
}))
|
|
421
426
|
];
|
|
422
427
|
for (const { segmentId, body } of segments) {
|
|
@@ -479,15 +484,15 @@ var FDocumentImageMixin = class extends FDocument {
|
|
|
479
484
|
return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
|
|
480
485
|
}
|
|
481
486
|
getImage(imageId) {
|
|
482
|
-
var
|
|
483
|
-
const drawing = (
|
|
487
|
+
var _findDocDrawing;
|
|
488
|
+
const drawing = (_findDocDrawing = findDocDrawing(this.getDocumentDataModel().getSnapshot(), imageId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing;
|
|
484
489
|
if (!drawing || drawing.drawingType !== DrawingTypeEnum.DRAWING_IMAGE) return null;
|
|
485
490
|
return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
|
|
486
491
|
}
|
|
487
492
|
getImages() {
|
|
488
493
|
const documentDataModel = this.getDocumentDataModel();
|
|
489
|
-
const drawings = documentDataModel.
|
|
490
|
-
return
|
|
494
|
+
const { drawings, drawingsOrder: drawingIds } = collectDocDrawings(documentDataModel.getSnapshot());
|
|
495
|
+
return drawingIds.filter((drawingId) => {
|
|
491
496
|
var _drawings$drawingId;
|
|
492
497
|
return ((_drawings$drawingId = drawings[drawingId]) === null || _drawings$drawingId === void 0 ? void 0 : _drawings$drawingId.drawingType) === DrawingTypeEnum.DRAWING_IMAGE;
|
|
493
498
|
}).map((drawingId) => this._injector.createInstance(FDocumentImage, this, drawingId, this._injector));
|