@univerjs/docs-drawing 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.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 ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  | Package | UMD global | CSS | Locales | Facade entry |
12
12
  | --- | --- | :---: | :---: | :---: |
13
- | `@univerjs/docs-drawing` | `UniverDocsDrawing` | No | No | No |
13
+ | `@univerjs/docs-drawing` | `UniverDocsDrawing` | No | No | Yes |
14
14
 
15
15
  ## Installation
16
16
 
@@ -35,4 +35,3 @@ univer.registerPlugin(UniverDocsDrawingPlugin);
35
35
  - [Documentation](https://docs.univer.ai)
36
36
  - [NPM package](https://npmjs.com/package/@univerjs/docs-drawing)
37
37
  - [GitHub repository](https://github.com/dream-num/univer)
38
-
package/lib/cjs/facade.js CHANGED
@@ -11,8 +11,9 @@ let _univerjs_core_facade = require("@univerjs/core/facade");
11
11
  * Facade API for an image in a document.
12
12
  * @hideconstructor
13
13
  */
14
- var FDocumentImage = class {
14
+ var FDocumentImage = class extends _univerjs_core_facade.FBase {
15
15
  constructor(_document, _imageId, _injector) {
16
+ super();
16
17
  this._document = _document;
17
18
  this._imageId = _imageId;
18
19
  this._injector = _injector;
@@ -165,8 +166,8 @@ var FDocumentImage = class {
165
166
  * ```
166
167
  */
167
168
  getImageData() {
168
- var _this$_document$getDo;
169
- const drawing = (_this$_document$getDo = this._document.getDocumentDataModel().getDrawings()) === null || _this$_document$getDo === void 0 ? void 0 : _this$_document$getDo[this._imageId];
169
+ var _findDocDrawing;
170
+ const drawing = (_findDocDrawing = (0, _univerjs_docs_drawing.findDocDrawing)(this._document.getDocumentDataModel().getSnapshot(), this._imageId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing;
170
171
  if (!drawing || drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return null;
171
172
  return drawing;
172
173
  }
@@ -405,7 +406,7 @@ var FDocumentImage = class {
405
406
  });
406
407
  }
407
408
  _getTextRange() {
408
- const { body, headers = {}, footers = {} } = this._document.getDocumentDataModel().getSnapshot();
409
+ const { body, headers = {}, footers = {}, notes = {} } = this._document.getDocumentDataModel().getSnapshot();
409
410
  const segments = [
410
411
  {
411
412
  segmentId: "",
@@ -418,6 +419,10 @@ var FDocumentImage = class {
418
419
  ...Object.entries(footers).map(([segmentId, footer]) => ({
419
420
  segmentId,
420
421
  body: footer.body
422
+ })),
423
+ ...Object.entries(notes).map(([segmentId, note]) => ({
424
+ segmentId,
425
+ body: note.body
421
426
  }))
422
427
  ];
423
428
  for (const { segmentId, body } of segments) {
@@ -480,15 +485,14 @@ var FDocumentImageMixin = class extends _univerjs_docs_facade.FDocument {
480
485
  return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
481
486
  }
482
487
  getImage(imageId) {
483
- var _this$getDocumentData;
484
- const drawing = (_this$getDocumentData = this.getDocumentDataModel().getDrawings()) === null || _this$getDocumentData === void 0 ? void 0 : _this$getDocumentData[imageId];
488
+ var _findDocDrawing;
489
+ const drawing = (_findDocDrawing = (0, _univerjs_docs_drawing.findDocDrawing)(this.getDocumentDataModel().getSnapshot(), imageId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing;
485
490
  if (!drawing || drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return null;
486
491
  return this._injector.createInstance(FDocumentImage, this, imageId, this._injector);
487
492
  }
488
493
  getImages() {
489
- const documentDataModel = this.getDocumentDataModel();
490
- const drawings = documentDataModel.getDrawings() ?? {};
491
- return (documentDataModel.getDrawingsOrder() ?? Object.keys(drawings)).filter((drawingId) => {
494
+ const { drawings, drawingsOrder: drawingIds } = (0, _univerjs_docs_drawing.collectDocDrawings)(this.getDocumentDataModel().getSnapshot());
495
+ return drawingIds.filter((drawingId) => {
492
496
  var _drawings$drawingId;
493
497
  return ((_drawings$drawingId = drawings[drawingId]) === null || _drawings$drawingId === void 0 ? void 0 : _drawings$drawingId.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE;
494
498
  }).map((drawingId) => this._injector.createInstance(FDocumentImage, this, drawingId, this._injector));
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 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
+ 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
  }
@@ -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,13 +212,22 @@ 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 segmentId = (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) ?? (activeTextRange === null || activeTextRange === void 0 ? void 0 : activeTextRange.segmentId) ?? "";
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 = documentDataModel.getDrawings() ?? {};
230
+ const drawings = source.drawings ?? {};
168
231
  const removeDrawingParamById = new Map(removeDrawings.map((drawing) => [drawing.drawingId, drawing]));
169
232
  const removeDrawingSnapshots = removeCustomBlocks.map((block) => drawings[block.blockId]).filter((drawing) => drawing != null);
170
233
  const resourceRedoMutations = [];
@@ -204,12 +267,15 @@ const RemoveDocDrawingCommand = {
204
267
  startOffset: cursorIndex,
205
268
  endOffset: cursorIndex
206
269
  }];
270
+ const historyActions = getHistoryActions(removeDrawings);
207
271
  const doMutation = {
208
272
  id: _univerjs_docs.RichTextEditingMutation.id,
209
273
  params: {
210
274
  unitId,
275
+ segmentId,
211
276
  actions: [],
212
- textRanges
277
+ textRanges,
278
+ historyActions
213
279
  }
214
280
  };
215
281
  const rawActions = [];
@@ -226,11 +292,21 @@ const RemoveDocDrawingCommand = {
226
292
  memoryCursor.moveCursorTo(startIndex + 1);
227
293
  }
228
294
  rawActions.push(jsonX.editOp(textX.serialize(), (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId)));
229
- for (const block of removeCustomBlocks) {
295
+ const drawingOrder = source.drawingsOrder ?? [];
296
+ const resourceBlocks = [...removeCustomBlocks].sort((left, right) => drawingOrder.indexOf(right.blockId) - drawingOrder.indexOf(left.blockId));
297
+ for (const block of resourceBlocks) {
230
298
  const { blockId } = block;
231
- const drawingIndex = documentDataModel.getDrawingsOrder().indexOf(blockId);
232
- rawActions.push(jsonX.removeOp(["drawings", blockId], drawings[blockId]));
233
- rawActions.push(jsonX.removeOp(["drawingsOrder", drawingIndex], blockId));
299
+ const drawingIndex = drawingOrder.indexOf(blockId);
300
+ if (drawings[blockId]) rawActions.push(jsonX.removeOp([
301
+ ...prefix,
302
+ "drawings",
303
+ blockId
304
+ ], drawings[blockId]));
305
+ if (drawingIndex >= 0) rawActions.push(jsonX.removeOp([
306
+ ...prefix,
307
+ "drawingsOrder",
308
+ drawingIndex
309
+ ], blockId));
234
310
  }
235
311
  doMutation.params.actions = rawActions.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur), null);
236
312
  const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
@@ -243,6 +319,17 @@ const RemoveDocDrawingCommand = {
243
319
  return Boolean(result);
244
320
  }
245
321
  };
322
+ function getHistoryActions(drawings) {
323
+ const historyActions = drawings.flatMap((drawing) => {
324
+ switch (drawing.drawingType) {
325
+ case _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE: return [_univerjs_docs.DocHistoryAction.DeleteImage];
326
+ case _univerjs_core.DrawingTypeEnum.DRAWING_SHAPE: return [_univerjs_docs.DocHistoryAction.DeleteShape];
327
+ case _univerjs_core.DrawingTypeEnum.DRAWING_CHART: return [_univerjs_docs.DocHistoryAction.DeleteChart];
328
+ default: return [];
329
+ }
330
+ });
331
+ return [...new Set(historyActions)];
332
+ }
246
333
  function executeResourceMutationGroups(mutationGroups, commandService) {
247
334
  const executedUndoGroups = [];
248
335
  for (const mutationGroup of mutationGroups) {
@@ -284,6 +371,16 @@ function getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType) {
284
371
  }
285
372
  return arrangedDrawingOrder;
286
373
  }
374
+ function getDrawingOrderAtIndex(drawingOrder, drawingIds, zOrder) {
375
+ if (drawingIds.length !== 1) return [...drawingOrder];
376
+ const arrangedDrawingOrder = [...drawingOrder];
377
+ const currentIndex = arrangedDrawingOrder.indexOf(drawingIds[0]);
378
+ if (currentIndex < 0) return arrangedDrawingOrder;
379
+ const [drawingId] = arrangedDrawingOrder.splice(currentIndex, 1);
380
+ const targetIndex = (0, _univerjs_core.normalizeDrawingOrderIndex)(zOrder, drawingOrder.length);
381
+ arrangedDrawingOrder.splice(targetIndex, 0, drawingId);
382
+ return arrangedDrawingOrder;
383
+ }
287
384
  /**
288
385
  * Converts the target order into granular JSONX move operations. This avoids replacing
289
386
  * the entire drawingsOrder array and keeps collaboration conflicts scoped to moved items.
@@ -312,11 +409,11 @@ const SetDocDrawingArrangeCommand = {
312
409
  handler: (accessor, params) => {
313
410
  const commandService = accessor.get(_univerjs_core.ICommandService);
314
411
  if (params == null) return false;
315
- const { unitId, drawingIds, arrangeType } = params;
412
+ const { unitId, drawingIds } = params;
316
413
  const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
317
414
  const drawingOrder = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDrawingsOrder();
318
415
  if (!drawingOrder) return false;
319
- const actions = createDrawingOrderActions(drawingOrder, getArrangedDrawingOrder(drawingOrder, drawingIds, arrangeType));
416
+ const actions = createDrawingOrderActions(drawingOrder, params.zOrder !== void 0 ? getDrawingOrderAtIndex(drawingOrder, drawingIds, params.zOrder) : getArrangedDrawingOrder(drawingOrder, drawingIds, params.arrangeType));
320
417
  if (_univerjs_core.JSONX.isNoop(actions)) return false;
321
418
  const result = commandService.syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
322
419
  unitId,
@@ -339,16 +436,22 @@ const UpdateDrawingDocTransformCommand = {
339
436
  const { unitId, drawings } = params;
340
437
  const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
341
438
  if (!documentDataModel) return false;
342
- const oldDrawings = documentDataModel.getSnapshot().drawings ?? {};
439
+ const snapshot = documentDataModel.getSnapshot();
440
+ const historyAction = drawings.length > 0 && drawings.every(({ drawingId }) => {
441
+ var _findDocDrawing;
442
+ return ((_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.drawing.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE;
443
+ }) ? _univerjs_docs.DocHistoryAction.UpdateImage : void 0;
343
444
  const jsonX = _univerjs_core.JSONX.getInstance();
344
445
  const actions = [];
345
446
  for (const { drawingId, key, value } of drawings) {
346
- var _oldDrawings$drawingI;
347
- 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];
447
+ var _oldDrawing$docTransf;
448
+ const source = findDocDrawing(snapshot, drawingId);
449
+ if (!source) return false;
450
+ const oldDrawing = source.drawing;
451
+ const oldValue = key === "srcRect" ? oldDrawing === null || oldDrawing === void 0 ? void 0 : oldDrawing.srcRect : oldDrawing === null || oldDrawing === void 0 || (_oldDrawing$docTransf = oldDrawing.docTransform) === null || _oldDrawing$docTransf === void 0 ? void 0 : _oldDrawing$docTransf[key];
348
452
  if (!_univerjs_core.Tools.diffValue(oldValue, value)) {
349
- const path = [
350
- "drawings",
351
- drawingId,
453
+ const path = key === "srcRect" ? [...source.path, key] : [
454
+ ...source.path,
352
455
  "docTransform",
353
456
  key
354
457
  ];
@@ -357,6 +460,7 @@ const UpdateDrawingDocTransformCommand = {
357
460
  }
358
461
  return Boolean(commandService.syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
359
462
  unitId,
463
+ historyAction,
360
464
  actions: actions.reduce((acc, action) => _univerjs_core.JSONX.compose(acc, action), null),
361
465
  textRanges: null,
362
466
  debounce: true
@@ -425,33 +529,33 @@ const UpdateDocDrawingWrappingStyleCommand = {
425
529
  const commandService = accessor.get(_univerjs_core.ICommandService);
426
530
  const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
427
531
  if (!documentDataModel) return false;
428
- const oldDrawings = documentDataModel.getDrawings() ?? {};
532
+ const snapshot = documentDataModel.getSnapshot();
533
+ if (wrappingStyle !== "inline" && drawings.some(({ drawingId }) => {
534
+ var _findDocDrawing;
535
+ return (_findDocDrawing = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing === void 0 ? void 0 : _findDocDrawing.segmentId;
536
+ })) return false;
537
+ const historyAction = drawings.length > 0 && drawings.every(({ drawingId }) => {
538
+ var _findDocDrawing2;
539
+ return ((_findDocDrawing2 = findDocDrawing(snapshot, drawingId)) === null || _findDocDrawing2 === void 0 ? void 0 : _findDocDrawing2.drawing.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE;
540
+ }) ? _univerjs_docs.DocHistoryAction.UpdateImage : void 0;
429
541
  const jsonX = _univerjs_core.JSONX.getInstance();
430
542
  const rawActions = [];
431
543
  for (const drawing of drawings) {
432
- const oldDrawing = oldDrawings[drawing.drawingId];
433
- if (!oldDrawing) continue;
544
+ const source = findDocDrawing(snapshot, drawing.drawingId);
545
+ const oldDrawing = source === null || source === void 0 ? void 0 : source.drawing;
546
+ if (!oldDrawing || !source) continue;
434
547
  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));
548
+ if (oldDrawing.layoutType !== layoutType) rawActions.push(jsonX.replaceOp([...source.path, "layoutType"], oldDrawing.layoutType, layoutType));
440
549
  if (wrappingStyle === "behindText" || wrappingStyle === "inFrontOfText") {
441
550
  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));
551
+ if (oldDrawing.behindDoc !== behindDoc) rawActions.push(jsonX.replaceOp([...source.path, "behindDoc"], oldDrawing.behindDoc, behindDoc));
447
552
  }
448
553
  if (wrappingStyle !== "inline") for (const key of ["positionH", "positionV"]) {
449
554
  var _drawing$docTransform;
450
555
  const value = (_drawing$docTransform = drawing.docTransform) === null || _drawing$docTransform === void 0 ? void 0 : _drawing$docTransform[key];
451
556
  const oldValue = oldDrawing.docTransform[key];
452
557
  if (value && !_univerjs_core.Tools.diffValue(oldValue, value)) rawActions.push(jsonX.replaceOp([
453
- "drawings",
454
- drawing.drawingId,
558
+ ...source.path,
455
559
  "docTransform",
456
560
  key
457
561
  ], oldValue, value));
@@ -461,6 +565,7 @@ const UpdateDocDrawingWrappingStyleCommand = {
461
565
  id: _univerjs_docs.RichTextEditingMutation.id,
462
566
  params: {
463
567
  unitId,
568
+ historyAction,
464
569
  actions: rawActions.reduce((actions, action) => _univerjs_core.JSONX.compose(actions, action), null),
465
570
  textRanges: null
466
571
  }
@@ -541,7 +646,7 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
541
646
  };
542
647
  try {
543
648
  return JSON.parse(json);
544
- } catch (err) {
649
+ } catch {
545
650
  return {
546
651
  data: {},
547
652
  order: []
@@ -554,10 +659,7 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
554
659
  toJson: (unitId) => toJson(unitId),
555
660
  parseJson: (json) => parseJson(json),
556
661
  onUnLoad: (unitId) => {
557
- this._setDrawingDataForUnit(unitId, {
558
- data: {},
559
- order: []
560
- });
662
+ this._unloadDrawingDataForUnit(unitId);
561
663
  },
562
664
  onLoad: (unitId, value) => {
563
665
  this._setDrawingDataForUnit(unitId, {
@@ -567,6 +669,12 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
567
669
  }
568
670
  }));
569
671
  }
672
+ _unloadDrawingDataForUnit(unitId) {
673
+ const documentDataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
674
+ documentDataModel === null || documentDataModel === void 0 || documentDataModel.resetDrawing({}, []);
675
+ this._docDrawingService.removeDrawingDataForUnit(unitId);
676
+ this._drawingManagerService.removeDrawingDataForUnit(unitId);
677
+ }
570
678
  _setDrawingDataForUnit(unitId, drawingMapItem) {
571
679
  const documentDataModel = this._univerInstanceService.getUnit(unitId);
572
680
  if (documentDataModel == null) return;
@@ -577,17 +685,28 @@ let DocDrawingController = class DocDrawingController extends _univerjs_core.Dis
577
685
  const dataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
578
686
  if (!dataModel) return false;
579
687
  const subUnitId = unitId;
580
- const drawingDataModels = dataModel.getDrawings();
581
- const drawingOrderModel = dataModel.getDrawingsOrder();
688
+ const { drawings: drawingDataModels, drawingsOrder: drawingOrderModel } = collectDocDrawings(dataModel.getSnapshot());
582
689
  if (!drawingDataModels || !drawingOrderModel) return false;
690
+ const normalizedDrawingData = {};
691
+ for (const [drawingId, drawing] of Object.entries(drawingDataModels)) normalizedDrawingData[drawingId] = drawing.unitId === unitId && drawing.subUnitId === subUnitId ? drawing : {
692
+ ...drawing,
693
+ unitId,
694
+ subUnitId
695
+ };
583
696
  const subDrawings = { [subUnitId]: {
584
697
  unitId,
585
698
  subUnitId,
586
- data: drawingDataModels,
699
+ data: normalizedDrawingData,
587
700
  order: drawingOrderModel
588
701
  } };
702
+ const renderDrawingData = {};
703
+ for (const [drawingId, drawing] of Object.entries(normalizedDrawingData)) renderDrawingData[drawingId] = {
704
+ ...drawing,
705
+ hidden: true
706
+ };
589
707
  const renderSubDrawings = { [subUnitId]: {
590
708
  ...subDrawings[subUnitId],
709
+ data: renderDrawingData,
591
710
  order: getDocDrawingRenderOrder(drawingOrderModel, drawingDataModels)
592
711
  } };
593
712
  this._docDrawingService.registerDrawingData(unitId, subDrawings);
@@ -615,7 +734,7 @@ DocDrawingController = __decorate([
615
734
  //#endregion
616
735
  //#region package.json
617
736
  var name = "@univerjs/docs-drawing";
618
- var version = "1.0.0-insiders.20260809-70eefdd";
737
+ var version = "1.0.0-rc.0";
619
738
 
620
739
  //#endregion
621
740
  //#region src/config/config.ts
@@ -695,4 +814,6 @@ Object.defineProperty(exports, 'UniverDocsDrawingPlugin', {
695
814
  exports.UpdateDocDrawingWrappingStyleCommand = UpdateDocDrawingWrappingStyleCommand;
696
815
  exports.UpdateDrawingDocTransformCommand = UpdateDrawingDocTransformCommand;
697
816
  exports.WRAPPING_STYLE_TO_LAYOUT_TYPE = WRAPPING_STYLE_TO_LAYOUT_TYPE;
817
+ exports.collectDocDrawings = collectDocDrawings;
818
+ exports.findDocDrawing = findDocDrawing;
698
819
  exports.getDocDrawingRenderOrder = getDocDrawingRenderOrder;