@univerjs/sheets-drawing 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1,697 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/sheets`),t=require(`@univerjs/core`),n=require(`@univerjs/drawing`),r=require(`@univerjs/engine-render`);function i(t,n){if(!n)return;let{unitId:r,sheetId:i,skeleton:a}=n,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=t,{left:p,top:m,width:h,height:g}=(0,e.convertPositionSheetOverGridToAbsolute)(r,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function a(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function o(e,t){let{left:n=0,top:r=0,width:i=0,height:o=0,angle:s=0}=e,c=(s%360+360)%360;return a(c>=45&&c<135||c>=225&&c<315?{...e,left:n+i/2-o/2,top:r+o/2-i/2,width:o,height:i}:e,t)}let s=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var c=class extends n.UnitDrawingService{};const l=(0,t.createIdentifier)(`sheets-drawing.sheet-drawing.service`);let u=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const d={id:`sheet.mutation.set-drawing-apply`,type:t.CommandType.MUTATION,handler:(e,t)=>{let r=e.get(n.IDrawingManagerService),i=e.get(l),{op:a,unitId:o,subUnitId:s,type:c,objects:d}=t;switch(r.applyJson1(o,s,a),i.applyJson1(o,s,a),c){case u.INSERT:r.addNotification(d),i.addNotification(d);break;case u.REMOVE:r.removeNotification(d),i.removeNotification(d);break;case u.UPDATE:r.updateNotification(d),i.updateNotification(d);break;case u.ARRANGE:r.orderNotification(d),i.orderNotification(d);break;case u.GROUP:r.groupUpdateNotification(d),i.groupUpdateNotification(d);break;case u.UNGROUP:r.ungroupUpdateNotification(d),i.ungroupUpdateNotification(d);break}return!0}},f={id:`sheet.operation.clear-drawing-transformer`,type:t.CommandType.MUTATION,handler:(e,t)=>{let n=e.get(r.IRenderManagerService);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},p={id:`sheet.command.insert-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(l),m=n.get(e.SheetInterceptorService),h=r.drawings,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchAddOp(h),x=m.onCommandExecute({id:p.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:u.INSERT}},{id:f.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:u.REMOVE}},{id:f.id,params:[g]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},m={id:`sheet.command.remove-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(e.SheetInterceptorService),p=n.get(l),{drawings:h}=r,{unitId:g,subUnitId:_,undo:v,redo:y,objects:b}=p.getBatchRemoveOp(h),x=c.onCommandExecute({id:m.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:g,subUnitId:_,op:y,objects:b,type:u.REMOVE}},{id:f.id,params:[g]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:g,subUnitId:_,op:v,objects:b,type:u.INSERT}},{id:f.id,params:[g]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:g,undoMutations:C,redoMutations:S}),!0):!1}},h={id:`sheet.command.set-drawing-arrange`,type:t.CommandType.COMMAND,handler:(e,n)=>{let r=e.get(t.ICommandService),i=e.get(t.IUndoRedoService);if(!n)return!1;let a=e.get(l),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:f}=n,p={unitId:o,subUnitId:s,drawingIds:c},m;if(f===t.ArrangeTypeEnum.forward?m=a.getForwardDrawingsOp(p):f===t.ArrangeTypeEnum.backward?m=a.getBackwardDrawingOp(p):f===t.ArrangeTypeEnum.front?m=a.getFrontDrawingsOp(p):f===t.ArrangeTypeEnum.back&&(m=a.getBackDrawingsOp(p)),m==null)return!1;let{objects:h,redo:g,undo:_}=m;return r.syncExecuteCommand(d.id,{op:g,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:d.id,params:{op:_,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE}}],redoMutations:[{id:d.id,params:{op:g,unitId:o,subUnitId:s,objects:h,type:u.ARRANGE}}]}),!0):!1}},g={id:`sheet.command.set-sheet-image`,type:t.CommandType.COMMAND,handler:(n,r)=>{var i,a;if(!r)return!1;let o=n.get(t.ICommandService),s=n.get(t.IUndoRedoService),c=n.get(l),p=n.get(e.SheetInterceptorService),{drawings:m}=r,{unitId:h,subUnitId:_,undo:v,redo:y,objects:b}=c.getBatchUpdateOp(m),x=p.onCommandExecute({id:g.id,params:r}),S=[...(i=x.preRedos)==null?[]:i,{id:d.id,params:{unitId:h,subUnitId:_,op:y,objects:b,type:u.UPDATE}},{id:f.id,params:[h]},...x.redos],C=[...(a=x.preUndos)==null?[]:a,{id:d.id,params:{unitId:h,subUnitId:_,op:v,objects:b,type:u.UPDATE}},{id:f.id,params:[h]},...x.undos];return(0,t.sequenceExecute)(S,o)?(s.pushUndoRedo({unitID:h,undoMutations:C,redoMutations:S}),!0):!1}};function _(e,t){return function(n,r){t(n,r,e)}}function v(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const y=`SHEET_DRAWING_PLUGIN`;let b=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(d))}_initCommands(){[g,p,m,h,f].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:y,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>n(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===e.RemoveSheetCommand.id){var r;let e=n.params,i=e.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetDrawingService.getDrawingData(i,a),s=Object.values(o).filter(e=>e.drawingType!==t.DrawingTypeEnum.DRAWING_CHART);if(s.length===0)return{redos:[],undos:[]};let{unitId:c,subUnitId:l,undo:f,redo:p,objects:m}=this._sheetDrawingService.getBatchRemoveOp(s);return{redos:[{id:d.id,params:{op:p,unitId:c,subUnitId:l,objects:m,type:u.REMOVE}}],undos:[{id:d.id,params:{op:f,unitId:c,subUnitId:l,objects:m,type:u.INSERT}}]}}else if(n.id===e.CopySheetCommand.id){let{unitId:e,subUnitId:r,targetSubUnitId:i}=n.params;if(!e||!r||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(e,r),o=Object.values(a).filter(e=>e.drawingType!==t.DrawingTypeEnum.DRAWING_CHART).map(e=>({...e,subUnitId:i,drawingId:(0,t.generateRandomId)(6)}));if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:c,undo:l,redo:f,objects:p}=this._sheetDrawingService.getBatchAddOp(o);return{redos:[{id:d.id,params:{op:f,unitId:s,subUnitId:c,objects:p,type:u.INSERT}}],undos:[{id:d.id,params:{op:l,unitId:s,subUnitId:c,objects:p,type:u.REMOVE}}]}}return{redos:[],undos:[]}}}))}};b=v([_(0,(0,t.Inject)(e.SheetInterceptorService)),_(1,(0,t.Inject)(t.IUniverInstanceService)),_(2,t.ICommandService),_(3,l),_(4,n.IDrawingManagerService),_(5,t.IResourceManagerService)],b);var x=`@univerjs/sheets-drawing`,S=`0.20.1`;const C=`sheets-drawing.config`;Symbol(C);const w={};function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=class extends t.Plugin{constructor(e=w,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},w,this._config);this._configService.setConfig(C,i)}onStarting(){[[b],[l,{useClass:c}]].forEach(e=>this._injector.add(e)),this._injector.get(b)}};O(k,`pluginName`,y),O(k,`packageName`,x),O(k,`version`,S),O(k,`type`,t.UniverInstanceType.UNIVER_SHEET),k=v([(0,t.DependentOn)(n.UniverDrawingPlugin),_(1,(0,t.Inject)(t.Injector)),_(2,t.IConfigService)],k),exports.ClearSheetDrawingTransformerOperation=f,exports.DrawingApplyType=u,exports.ISheetDrawingService=l,exports.InsertSheetDrawingCommand=p,exports.RemoveSheetDrawingCommand=m,exports.SHEET_DRAWING_PLUGIN=y,exports.SetDrawingApplyMutation=d,exports.SetDrawingArrangeCommand=h,exports.SetSheetDrawingCommand=g,exports.SheetDrawingAnchorType=s,Object.defineProperty(exports,`UniverSheetsDrawingPlugin`,{enumerable:!0,get:function(){return k}}),exports.drawingPositionToTransform=i,exports.transformToAxisAlignPosition=o,exports.transformToDrawingPosition=a;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_sheets = require("@univerjs/sheets");
3
+ let _univerjs_core = require("@univerjs/core");
4
+ let _univerjs_drawing = require("@univerjs/drawing");
5
+ let _univerjs_engine_render = require("@univerjs/engine-render");
6
+
7
+ //#region src/basics/transform-position.ts
8
+ function drawingPositionToTransform(position, sheetSkeletonParam) {
9
+ if (!sheetSkeletonParam) return;
10
+ const { unitId, sheetId, skeleton } = sheetSkeletonParam;
11
+ const { from, to, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = position;
12
+ let { left, top, width, height } = (0, _univerjs_sheets.convertPositionSheetOverGridToAbsolute)(unitId, sheetId, {
13
+ from,
14
+ to
15
+ }, skeleton);
16
+ const sheetWidth = skeleton.rowHeaderWidth + skeleton.columnTotalWidth;
17
+ const sheetHeight = skeleton.columnHeaderHeight + skeleton.rowTotalHeight;
18
+ if (left + width > sheetWidth) left = sheetWidth - width;
19
+ if (top + height > sheetHeight) top = sheetHeight - height;
20
+ return {
21
+ flipY,
22
+ flipX,
23
+ angle,
24
+ skewX,
25
+ skewY,
26
+ left,
27
+ top,
28
+ width,
29
+ height
30
+ };
31
+ }
32
+ function transformToDrawingPosition(transform, skeleton) {
33
+ const { left = 0, top = 0, width = 0, height = 0, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = transform;
34
+ return {
35
+ flipY,
36
+ flipX,
37
+ angle,
38
+ skewX,
39
+ skewY,
40
+ from: skeleton.getCellIndexAndOffsetByPosition(left, top),
41
+ to: skeleton.getCellIndexAndOffsetByPosition(left + width, top + height)
42
+ };
43
+ }
44
+ /**
45
+ * In excel, the basic drawing with rotate bound use major axis switch, axis-aligned bound will bu used.That means the position bound of drawing element will save as nearly axis-aligned rectangle.
46
+ * Here is the rule to convert transform to axis-aligned position:
47
+ * [-45°, 45°): use the original bound
48
+ * [45°, 135°): rotate the bound 90° clockwise,and the left, top, bottom,right will use the rotated bound.
49
+ * [135°, 225°): use the original bound
50
+ * [225°, 315°): rotate the bound 90° counterclockwise, and the left, top, bottom, right will use the rotated bound.
51
+ * @return The axis-aligned position of the drawing element.
52
+ */
53
+ function transformToAxisAlignPosition(transform, skeleton) {
54
+ const { left = 0, top = 0, width = 0, height = 0, angle = 0 } = transform;
55
+ const norm = (angle % 360 + 360) % 360;
56
+ if (!(norm >= 45 && norm < 135 || norm >= 225 && norm < 315)) return transformToDrawingPosition(transform, skeleton);
57
+ return transformToDrawingPosition({
58
+ ...transform,
59
+ left: left + width / 2 - height / 2,
60
+ top: top + height / 2 - width / 2,
61
+ width: height,
62
+ height: width
63
+ }, skeleton);
64
+ }
65
+
66
+ //#endregion
67
+ //#region src/services/sheet-drawing.service.ts
68
+ let SheetDrawingAnchorType = /* @__PURE__ */ function(SheetDrawingAnchorType) {
69
+ /**
70
+ * Only the position of the drawing follows the cell changes. When rows or columns are inserted or deleted, the position of the drawing changes, but the size remains the same.
71
+ */
72
+ SheetDrawingAnchorType["Position"] = "0";
73
+ /**
74
+ * The size and position of the drawing follow the cell changes. When rows or columns are inserted or deleted, the size and position of the drawing change accordingly.
75
+ */
76
+ SheetDrawingAnchorType["Both"] = "1";
77
+ /**
78
+ * The size and position of the drawing do not follow the cell changes. When rows or columns are inserted or deleted, the position and size of the drawing remain unchanged.
79
+ */
80
+ SheetDrawingAnchorType["None"] = "2";
81
+ return SheetDrawingAnchorType;
82
+ }({});
83
+ var SheetDrawingService = class extends _univerjs_drawing.UnitDrawingService {};
84
+ const ISheetDrawingService = (0, _univerjs_core.createIdentifier)("sheets-drawing.sheet-drawing.service");
85
+
86
+ //#endregion
87
+ //#region src/commands/mutations/set-drawing-apply.mutation.ts
88
+ let DrawingApplyType = /* @__PURE__ */ function(DrawingApplyType) {
89
+ DrawingApplyType[DrawingApplyType["INSERT"] = 0] = "INSERT";
90
+ DrawingApplyType[DrawingApplyType["REMOVE"] = 1] = "REMOVE";
91
+ DrawingApplyType[DrawingApplyType["UPDATE"] = 2] = "UPDATE";
92
+ DrawingApplyType[DrawingApplyType["ARRANGE"] = 3] = "ARRANGE";
93
+ DrawingApplyType[DrawingApplyType["GROUP"] = 4] = "GROUP";
94
+ DrawingApplyType[DrawingApplyType["UNGROUP"] = 5] = "UNGROUP";
95
+ return DrawingApplyType;
96
+ }({});
97
+ const SetDrawingApplyMutation = {
98
+ id: "sheet.mutation.set-drawing-apply",
99
+ type: _univerjs_core.CommandType.MUTATION,
100
+ handler: (accessor, params) => {
101
+ const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
102
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
103
+ const { op, unitId, subUnitId, type, objects } = params;
104
+ drawingManagerService.applyJson1(unitId, subUnitId, op);
105
+ sheetDrawingService.applyJson1(unitId, subUnitId, op);
106
+ switch (type) {
107
+ case DrawingApplyType.INSERT:
108
+ drawingManagerService.addNotification(objects);
109
+ sheetDrawingService.addNotification(objects);
110
+ break;
111
+ case DrawingApplyType.REMOVE:
112
+ drawingManagerService.removeNotification(objects);
113
+ sheetDrawingService.removeNotification(objects);
114
+ break;
115
+ case DrawingApplyType.UPDATE:
116
+ drawingManagerService.updateNotification(objects);
117
+ sheetDrawingService.updateNotification(objects);
118
+ break;
119
+ case DrawingApplyType.ARRANGE:
120
+ drawingManagerService.orderNotification(objects);
121
+ sheetDrawingService.orderNotification(objects);
122
+ break;
123
+ case DrawingApplyType.GROUP:
124
+ drawingManagerService.groupUpdateNotification(objects);
125
+ sheetDrawingService.groupUpdateNotification(objects);
126
+ break;
127
+ case DrawingApplyType.UNGROUP:
128
+ drawingManagerService.ungroupUpdateNotification(objects);
129
+ sheetDrawingService.ungroupUpdateNotification(objects);
130
+ break;
131
+ }
132
+ return true;
133
+ }
134
+ };
135
+
136
+ //#endregion
137
+ //#region src/commands/operations/clear-drawing-transformer.operation.ts
138
+ const ClearSheetDrawingTransformerOperation = {
139
+ id: "sheet.operation.clear-drawing-transformer",
140
+ type: _univerjs_core.CommandType.MUTATION,
141
+ handler: (accessor, params) => {
142
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
143
+ params.forEach((unitId) => {
144
+ var _renderManagerService;
145
+ (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
146
+ });
147
+ return true;
148
+ }
149
+ };
150
+
151
+ //#endregion
152
+ //#region src/commands/commands/insert-sheet-drawing.command.ts
153
+ const InsertSheetDrawingCommand = {
154
+ id: "sheet.command.insert-sheet-image",
155
+ type: _univerjs_core.CommandType.COMMAND,
156
+ handler: (accessor, params) => {
157
+ var _intercepted$preRedos, _intercepted$preUndos;
158
+ if (!params) return false;
159
+ const commandService = accessor.get(_univerjs_core.ICommandService);
160
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
161
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
162
+ const sheetInterceptorService = accessor.get(_univerjs_sheets.SheetInterceptorService);
163
+ const drawings = params.drawings;
164
+ const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchAddOp(drawings);
165
+ const intercepted = sheetInterceptorService.onCommandExecute({
166
+ id: InsertSheetDrawingCommand.id,
167
+ params
168
+ });
169
+ const redoMutations = [
170
+ ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
171
+ {
172
+ id: SetDrawingApplyMutation.id,
173
+ params: {
174
+ unitId,
175
+ subUnitId,
176
+ op: redo,
177
+ objects,
178
+ type: DrawingApplyType.INSERT
179
+ }
180
+ },
181
+ {
182
+ id: ClearSheetDrawingTransformerOperation.id,
183
+ params: [unitId]
184
+ },
185
+ ...intercepted.redos
186
+ ];
187
+ const undoMutations = [
188
+ ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
189
+ {
190
+ id: SetDrawingApplyMutation.id,
191
+ params: {
192
+ unitId,
193
+ subUnitId,
194
+ op: undo,
195
+ objects,
196
+ type: DrawingApplyType.REMOVE
197
+ }
198
+ },
199
+ {
200
+ id: ClearSheetDrawingTransformerOperation.id,
201
+ params: [unitId]
202
+ },
203
+ ...intercepted.undos
204
+ ];
205
+ if ((0, _univerjs_core.sequenceExecute)(redoMutations, commandService)) {
206
+ undoRedoService.pushUndoRedo({
207
+ unitID: unitId,
208
+ undoMutations,
209
+ redoMutations
210
+ });
211
+ return true;
212
+ }
213
+ return false;
214
+ }
215
+ };
216
+
217
+ //#endregion
218
+ //#region src/commands/commands/remove-sheet-drawing.command.ts
219
+ const RemoveSheetDrawingCommand = {
220
+ id: "sheet.command.remove-sheet-image",
221
+ type: _univerjs_core.CommandType.COMMAND,
222
+ handler: (accessor, params) => {
223
+ var _intercepted$preRedos, _intercepted$preUndos;
224
+ if (!params) return false;
225
+ const commandService = accessor.get(_univerjs_core.ICommandService);
226
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
227
+ const sheetInterceptorService = accessor.get(_univerjs_sheets.SheetInterceptorService);
228
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
229
+ const { drawings } = params;
230
+ const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(drawings);
231
+ const intercepted = sheetInterceptorService.onCommandExecute({
232
+ id: RemoveSheetDrawingCommand.id,
233
+ params
234
+ });
235
+ const redoMutations = [
236
+ ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
237
+ {
238
+ id: SetDrawingApplyMutation.id,
239
+ params: {
240
+ unitId,
241
+ subUnitId,
242
+ op: redo,
243
+ objects,
244
+ type: DrawingApplyType.REMOVE
245
+ }
246
+ },
247
+ {
248
+ id: ClearSheetDrawingTransformerOperation.id,
249
+ params: [unitId]
250
+ },
251
+ ...intercepted.redos
252
+ ];
253
+ const undoMutations = [
254
+ ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
255
+ {
256
+ id: SetDrawingApplyMutation.id,
257
+ params: {
258
+ unitId,
259
+ subUnitId,
260
+ op: undo,
261
+ objects,
262
+ type: DrawingApplyType.INSERT
263
+ }
264
+ },
265
+ {
266
+ id: ClearSheetDrawingTransformerOperation.id,
267
+ params: [unitId]
268
+ },
269
+ ...intercepted.undos
270
+ ];
271
+ if ((0, _univerjs_core.sequenceExecute)(redoMutations, commandService)) {
272
+ undoRedoService.pushUndoRedo({
273
+ unitID: unitId,
274
+ undoMutations,
275
+ redoMutations
276
+ });
277
+ return true;
278
+ }
279
+ return false;
280
+ }
281
+ };
282
+
283
+ //#endregion
284
+ //#region src/commands/commands/set-drawing-arrange.command.ts
285
+ const SetDrawingArrangeCommand = {
286
+ id: "sheet.command.set-drawing-arrange",
287
+ type: _univerjs_core.CommandType.COMMAND,
288
+ handler: (accessor, params) => {
289
+ const commandService = accessor.get(_univerjs_core.ICommandService);
290
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
291
+ if (!params) return false;
292
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
293
+ const { unitId, subUnitId, drawingIds, arrangeType } = params;
294
+ const drawingOrderMapParam = {
295
+ unitId,
296
+ subUnitId,
297
+ drawingIds
298
+ };
299
+ let jsonOp;
300
+ if (arrangeType === _univerjs_core.ArrangeTypeEnum.forward) jsonOp = sheetDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
301
+ else if (arrangeType === _univerjs_core.ArrangeTypeEnum.backward) jsonOp = sheetDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
302
+ else if (arrangeType === _univerjs_core.ArrangeTypeEnum.front) jsonOp = sheetDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
303
+ else if (arrangeType === _univerjs_core.ArrangeTypeEnum.back) jsonOp = sheetDrawingService.getBackDrawingsOp(drawingOrderMapParam);
304
+ if (jsonOp == null) return false;
305
+ const { objects, redo, undo } = jsonOp;
306
+ if (commandService.syncExecuteCommand(SetDrawingApplyMutation.id, {
307
+ op: redo,
308
+ unitId,
309
+ subUnitId,
310
+ objects,
311
+ type: DrawingApplyType.ARRANGE
312
+ })) {
313
+ undoRedoService.pushUndoRedo({
314
+ unitID: unitId,
315
+ undoMutations: [{
316
+ id: SetDrawingApplyMutation.id,
317
+ params: {
318
+ op: undo,
319
+ unitId,
320
+ subUnitId,
321
+ objects,
322
+ type: DrawingApplyType.ARRANGE
323
+ }
324
+ }],
325
+ redoMutations: [{
326
+ id: SetDrawingApplyMutation.id,
327
+ params: {
328
+ op: redo,
329
+ unitId,
330
+ subUnitId,
331
+ objects,
332
+ type: DrawingApplyType.ARRANGE
333
+ }
334
+ }]
335
+ });
336
+ return true;
337
+ }
338
+ return false;
339
+ }
340
+ };
341
+
342
+ //#endregion
343
+ //#region src/commands/commands/set-sheet-drawing.command.ts
344
+ const SetSheetDrawingCommand = {
345
+ id: "sheet.command.set-sheet-image",
346
+ type: _univerjs_core.CommandType.COMMAND,
347
+ handler: (accessor, params) => {
348
+ var _intercepted$preRedos, _intercepted$preUndos;
349
+ if (!params) return false;
350
+ const commandService = accessor.get(_univerjs_core.ICommandService);
351
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
352
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
353
+ const sheetInterceptorService = accessor.get(_univerjs_sheets.SheetInterceptorService);
354
+ const { drawings } = params;
355
+ const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(drawings);
356
+ const intercepted = sheetInterceptorService.onCommandExecute({
357
+ id: SetSheetDrawingCommand.id,
358
+ params
359
+ });
360
+ const redoMutations = [
361
+ ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
362
+ {
363
+ id: SetDrawingApplyMutation.id,
364
+ params: {
365
+ unitId,
366
+ subUnitId,
367
+ op: redo,
368
+ objects,
369
+ type: DrawingApplyType.UPDATE
370
+ }
371
+ },
372
+ {
373
+ id: ClearSheetDrawingTransformerOperation.id,
374
+ params: [unitId]
375
+ },
376
+ ...intercepted.redos
377
+ ];
378
+ const undoMutations = [
379
+ ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
380
+ {
381
+ id: SetDrawingApplyMutation.id,
382
+ params: {
383
+ unitId,
384
+ subUnitId,
385
+ op: undo,
386
+ objects,
387
+ type: DrawingApplyType.UPDATE
388
+ }
389
+ },
390
+ {
391
+ id: ClearSheetDrawingTransformerOperation.id,
392
+ params: [unitId]
393
+ },
394
+ ...intercepted.undos
395
+ ];
396
+ if ((0, _univerjs_core.sequenceExecute)(redoMutations, commandService)) {
397
+ undoRedoService.pushUndoRedo({
398
+ unitID: unitId,
399
+ undoMutations,
400
+ redoMutations
401
+ });
402
+ return true;
403
+ }
404
+ return false;
405
+ }
406
+ };
407
+
408
+ //#endregion
409
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
410
+ function __decorateParam(paramIndex, decorator) {
411
+ return function(target, key) {
412
+ decorator(target, key, paramIndex);
413
+ };
414
+ }
415
+
416
+ //#endregion
417
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
418
+ function __decorate(decorators, target, key, desc) {
419
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
420
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
421
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
422
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
423
+ }
424
+
425
+ //#endregion
426
+ //#region src/controllers/sheet-drawing.controller.ts
427
+ const SHEET_DRAWING_PLUGIN = "SHEET_DRAWING_PLUGIN";
428
+ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends _univerjs_core.Disposable {
429
+ constructor(_sheetInterceptorService, _univerInstanceService, _commandService, _sheetDrawingService, _drawingManagerService, _resourceManagerService) {
430
+ super();
431
+ this._sheetInterceptorService = _sheetInterceptorService;
432
+ this._univerInstanceService = _univerInstanceService;
433
+ this._commandService = _commandService;
434
+ this._sheetDrawingService = _sheetDrawingService;
435
+ this._drawingManagerService = _drawingManagerService;
436
+ this._resourceManagerService = _resourceManagerService;
437
+ this._initCommands();
438
+ this._initSnapshot();
439
+ this._initSheetChange();
440
+ this.disposeWithMe(this._commandService.registerCommand(SetDrawingApplyMutation));
441
+ }
442
+ _initCommands() {
443
+ [
444
+ SetSheetDrawingCommand,
445
+ InsertSheetDrawingCommand,
446
+ RemoveSheetDrawingCommand,
447
+ SetDrawingArrangeCommand,
448
+ ClearSheetDrawingTransformerOperation
449
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
450
+ }
451
+ _initSnapshot() {
452
+ const toJson = (unitId, model) => {
453
+ const map = model || this._sheetDrawingService.getDrawingDataForUnit(unitId);
454
+ if (map) return JSON.stringify(map);
455
+ return "";
456
+ };
457
+ const parseJson = (json) => {
458
+ if (!json) return {};
459
+ try {
460
+ return JSON.parse(json);
461
+ } catch {
462
+ return {};
463
+ }
464
+ };
465
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({
466
+ pluginName: SHEET_DRAWING_PLUGIN,
467
+ businesses: [_univerjs_core.UniverInstanceType.UNIVER_SHEET],
468
+ toJson: (unitId, model) => toJson(unitId, model),
469
+ parseJson: (json) => parseJson(json),
470
+ onUnLoad: (unitId) => {
471
+ this._sheetDrawingService.removeDrawingDataForUnit(unitId);
472
+ this._drawingManagerService.removeDrawingDataForUnit(unitId);
473
+ },
474
+ onLoad: (unitId, value) => {
475
+ this._sheetDrawingService.registerDrawingData(unitId, value);
476
+ this._drawingManagerService.registerDrawingData(unitId, value);
477
+ }
478
+ }));
479
+ }
480
+ _initSheetChange() {
481
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
482
+ if (commandInfo.id === _univerjs_sheets.RemoveSheetCommand.id) {
483
+ var _getActiveSheet;
484
+ const params = commandInfo.params;
485
+ const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getUnitId();
486
+ const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
487
+ if (!unitId || !subUnitId) return {
488
+ redos: [],
489
+ undos: []
490
+ };
491
+ const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
492
+ const drawings = Object.values(drawingData).filter((drawing) => {
493
+ if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART) return false;
494
+ return true;
495
+ });
496
+ if (drawings.length === 0) return {
497
+ redos: [],
498
+ undos: []
499
+ };
500
+ const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
501
+ return {
502
+ redos: [{
503
+ id: SetDrawingApplyMutation.id,
504
+ params: {
505
+ op: redo,
506
+ unitId: jsonOpUnitId,
507
+ subUnitId: jsonOpSubUnitId,
508
+ objects,
509
+ type: DrawingApplyType.REMOVE
510
+ }
511
+ }],
512
+ undos: [{
513
+ id: SetDrawingApplyMutation.id,
514
+ params: {
515
+ op: undo,
516
+ unitId: jsonOpUnitId,
517
+ subUnitId: jsonOpSubUnitId,
518
+ objects,
519
+ type: DrawingApplyType.INSERT
520
+ }
521
+ }]
522
+ };
523
+ } else if (commandInfo.id === _univerjs_sheets.CopySheetCommand.id) {
524
+ const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
525
+ if (!unitId || !subUnitId || !targetSubUnitId) return {
526
+ redos: [],
527
+ undos: []
528
+ };
529
+ const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
530
+ const drawings = Object.values(drawingData).filter((drawing) => {
531
+ if (drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_CHART) return false;
532
+ return true;
533
+ }).map((drawing) => {
534
+ return {
535
+ ...drawing,
536
+ subUnitId: targetSubUnitId,
537
+ drawingId: (0, _univerjs_core.generateRandomId)(6)
538
+ };
539
+ });
540
+ if (drawings.length === 0) return {
541
+ redos: [],
542
+ undos: []
543
+ };
544
+ const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchAddOp(drawings);
545
+ return {
546
+ redos: [{
547
+ id: SetDrawingApplyMutation.id,
548
+ params: {
549
+ op: redo,
550
+ unitId: jsonOpUnitId,
551
+ subUnitId: jsonOpSubUnitId,
552
+ objects,
553
+ type: DrawingApplyType.INSERT
554
+ }
555
+ }],
556
+ undos: [{
557
+ id: SetDrawingApplyMutation.id,
558
+ params: {
559
+ op: undo,
560
+ unitId: jsonOpUnitId,
561
+ subUnitId: jsonOpSubUnitId,
562
+ objects,
563
+ type: DrawingApplyType.REMOVE
564
+ }
565
+ }]
566
+ };
567
+ }
568
+ return {
569
+ redos: [],
570
+ undos: []
571
+ };
572
+ } }));
573
+ }
574
+ };
575
+ SheetsDrawingLoadController = __decorate([
576
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
577
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
578
+ __decorateParam(2, _univerjs_core.ICommandService),
579
+ __decorateParam(3, ISheetDrawingService),
580
+ __decorateParam(4, _univerjs_drawing.IDrawingManagerService),
581
+ __decorateParam(5, _univerjs_core.IResourceManagerService)
582
+ ], SheetsDrawingLoadController);
583
+
584
+ //#endregion
585
+ //#region package.json
586
+ var name = "@univerjs/sheets-drawing";
587
+ var version = "0.21.0";
588
+
589
+ //#endregion
590
+ //#region src/config/config.ts
591
+ /**
592
+ * Copyright 2023-present DreamNum Co., Ltd.
593
+ *
594
+ * Licensed under the Apache License, Version 2.0 (the "License");
595
+ * you may not use this file except in compliance with the License.
596
+ * You may obtain a copy of the License at
597
+ *
598
+ * http://www.apache.org/licenses/LICENSE-2.0
599
+ *
600
+ * Unless required by applicable law or agreed to in writing, software
601
+ * distributed under the License is distributed on an "AS IS" BASIS,
602
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
603
+ * See the License for the specific language governing permissions and
604
+ * limitations under the License.
605
+ */
606
+ const SHEETS_DRAWING_PLUGIN_CONFIG_KEY = "sheets-drawing.config";
607
+ const configSymbol = Symbol(SHEETS_DRAWING_PLUGIN_CONFIG_KEY);
608
+ const defaultPluginConfig = {};
609
+
610
+ //#endregion
611
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
612
+ function _typeof(o) {
613
+ "@babel/helpers - typeof";
614
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
615
+ return typeof o;
616
+ } : function(o) {
617
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
618
+ }, _typeof(o);
619
+ }
620
+
621
+ //#endregion
622
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
623
+ function toPrimitive(t, r) {
624
+ if ("object" != _typeof(t) || !t) return t;
625
+ var e = t[Symbol.toPrimitive];
626
+ if (void 0 !== e) {
627
+ var i = e.call(t, r || "default");
628
+ if ("object" != _typeof(i)) return i;
629
+ throw new TypeError("@@toPrimitive must return a primitive value.");
630
+ }
631
+ return ("string" === r ? String : Number)(t);
632
+ }
633
+
634
+ //#endregion
635
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
636
+ function toPropertyKey(t) {
637
+ var i = toPrimitive(t, "string");
638
+ return "symbol" == _typeof(i) ? i : i + "";
639
+ }
640
+
641
+ //#endregion
642
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
643
+ function _defineProperty(e, r, t) {
644
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
645
+ value: t,
646
+ enumerable: !0,
647
+ configurable: !0,
648
+ writable: !0
649
+ }) : e[r] = t, e;
650
+ }
651
+
652
+ //#endregion
653
+ //#region src/plugin.ts
654
+ let UniverSheetsDrawingPlugin = class UniverSheetsDrawingPlugin extends _univerjs_core.Plugin {
655
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
656
+ super();
657
+ this._config = _config;
658
+ this._injector = _injector;
659
+ this._configService = _configService;
660
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
661
+ this._configService.setConfig(SHEETS_DRAWING_PLUGIN_CONFIG_KEY, rest);
662
+ }
663
+ onStarting() {
664
+ [[SheetsDrawingLoadController], [ISheetDrawingService, { useClass: SheetDrawingService }]].forEach((dependency) => this._injector.add(dependency));
665
+ this._injector.get(SheetsDrawingLoadController);
666
+ }
667
+ };
668
+ _defineProperty(UniverSheetsDrawingPlugin, "pluginName", SHEET_DRAWING_PLUGIN);
669
+ _defineProperty(UniverSheetsDrawingPlugin, "packageName", name);
670
+ _defineProperty(UniverSheetsDrawingPlugin, "version", version);
671
+ _defineProperty(UniverSheetsDrawingPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
672
+ UniverSheetsDrawingPlugin = __decorate([
673
+ (0, _univerjs_core.DependentOn)(_univerjs_drawing.UniverDrawingPlugin),
674
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
675
+ __decorateParam(2, _univerjs_core.IConfigService)
676
+ ], UniverSheetsDrawingPlugin);
677
+
678
+ //#endregion
679
+ exports.ClearSheetDrawingTransformerOperation = ClearSheetDrawingTransformerOperation;
680
+ exports.DrawingApplyType = DrawingApplyType;
681
+ exports.ISheetDrawingService = ISheetDrawingService;
682
+ exports.InsertSheetDrawingCommand = InsertSheetDrawingCommand;
683
+ exports.RemoveSheetDrawingCommand = RemoveSheetDrawingCommand;
684
+ exports.SHEET_DRAWING_PLUGIN = SHEET_DRAWING_PLUGIN;
685
+ exports.SetDrawingApplyMutation = SetDrawingApplyMutation;
686
+ exports.SetDrawingArrangeCommand = SetDrawingArrangeCommand;
687
+ exports.SetSheetDrawingCommand = SetSheetDrawingCommand;
688
+ exports.SheetDrawingAnchorType = SheetDrawingAnchorType;
689
+ Object.defineProperty(exports, 'UniverSheetsDrawingPlugin', {
690
+ enumerable: true,
691
+ get: function () {
692
+ return UniverSheetsDrawingPlugin;
693
+ }
694
+ });
695
+ exports.drawingPositionToTransform = drawingPositionToTransform;
696
+ exports.transformToAxisAlignPosition = transformToAxisAlignPosition;
697
+ exports.transformToDrawingPosition = transformToDrawingPosition;