@univerjs/sheets-drawing-ui 0.1.13
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 +16 -0
- package/lib/cjs/index.js +1 -0
- package/lib/es/index.js +2054 -0
- package/lib/index.css +1 -0
- package/lib/locale/en-US.json +31 -0
- package/lib/locale/ru-RU.json +31 -0
- package/lib/locale/zh-CN.json +31 -0
- package/lib/types/basics/transform-position.d.ts +6 -0
- package/lib/types/commands/commands/delete-drawings.command.d.ts +3 -0
- package/lib/types/commands/commands/group-sheet-drawing.command.d.ts +6 -0
- package/lib/types/commands/commands/insert-sheet-drawing.command.d.ts +6 -0
- package/lib/types/commands/commands/interfaces.d.ts +21 -0
- package/lib/types/commands/commands/move-drawings.command.d.ts +6 -0
- package/lib/types/commands/commands/remove-sheet-drawing.command.d.ts +6 -0
- package/lib/types/commands/commands/set-drawing-arrange.command.d.ts +10 -0
- package/lib/types/commands/commands/set-sheet-drawing.command.d.ts +6 -0
- package/lib/types/commands/commands/ungroup-sheet-drawing.command.d.ts +6 -0
- package/lib/types/commands/commands/utils.d.ts +4 -0
- package/lib/types/commands/operations/clear-drawing-transformer.operation.d.ts +3 -0
- package/lib/types/commands/operations/edit-sheet-drawing.operation.d.ts +4 -0
- package/lib/types/commands/operations/insert-image.operation.d.ts +7 -0
- package/lib/types/commands/operations/open-drawing-panel.operation.d.ts +6 -0
- package/lib/types/controllers/drawing-popup-menu.controller.d.ts +24 -0
- package/lib/types/controllers/sheet-drawing-transform-affected.controller.d.ts +34 -0
- package/lib/types/controllers/sheet-drawing-update.controller.d.ts +35 -0
- package/lib/types/controllers/sheet-drawing.controller.d.ts +23 -0
- package/lib/types/controllers/shortcuts/drawing.shortcut.d.ts +10 -0
- package/lib/types/index.d.ts +17 -0
- package/lib/types/locale/en-US.d.ts +4 -0
- package/lib/types/locale/ru-RU.d.ts +4 -0
- package/lib/types/locale/zh-CN.d.ts +47 -0
- package/lib/types/plugin.d.ts +14 -0
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +60 -0
- package/lib/types/views/menu/image.menu.d.ts +7 -0
- package/lib/types/views/sheet-image-panel/SheetDrawingAnchor.d.ts +7 -0
- package/lib/types/views/sheet-image-panel/SheetDrawingPanel.d.ts +3 -0
- package/lib/types/views/sheet-image-panel/component-name.d.ts +16 -0
- package/lib/types/views/upload-component/UploadFile.d.ts +9 -0
- package/lib/types/views/upload-component/component-name.d.ts +20 -0
- package/lib/types/views/upload-loading/UploadLoading.d.ts +3 -0
- package/lib/umd/index.js +1 -0
- package/package.json +99 -0
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
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @univerjs/sheets-drawing-ui
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/packages/@univerjs/sheets-drawing-ui)
|
|
4
|
+
[](https://img.shields.io/npm/l/@univerjs/sheets-drawing-ui)
|
|
5
|
+
|
|
6
|
+
## Introduction
|
|
7
|
+
|
|
8
|
+
> TODO: Introduction
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
npm i @univerjs/sheets-drawing-ui
|
|
16
|
+
```
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var je=Object.defineProperty;var Le=(i,n,e)=>n in i?je(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var H=(i,n,e)=>(Le(i,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@univerjs/core"),B=require("@wendellhu/redi"),x=require("@univerjs/engine-render"),te=require("@univerjs/drawing-ui"),z=require("@univerjs/sheets-ui"),ne=require("rxjs"),E=require("@univerjs/drawing"),W=require("@univerjs/ui"),k=require("@wendellhu/redi/react-bindings"),m=require("@univerjs/sheets-drawing"),C=require("@univerjs/sheets"),A=require("react"),J=require("@univerjs/design"),se=require("clsx"),L={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,n)=>{const e=i.get(x.IRenderManagerService);return n.forEach(t=>{var r,o;(o=(r=e.getRenderById(t))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},we={id:"sheet.command.remove-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(w=>{const{unitId:f}=w;s.push(f)});const a=r.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:l,redo:d,objects:h}=a;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:h,type:m.DrawingApplyType.INSERT}},{id:L.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.REMOVE}},{id:L.id,params:s}]}),!0):!1}},De="COMPONENT_SHEET_DRAWING_PANEL",Ie={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,n)=>{const e=i.get(W.ISidebarService),t=i.get(p.LocaleService),r=i.get(p.IUniverInstanceService),o=i.get(E.IDrawingManagerService);if(!C.getSheetCommandTarget(r))return!1;switch(n.value){case"open":e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:De},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:e.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,n)=>{const e=i.get(E.IDrawingManagerService),t=i.get(p.ICommandService);return n==null?!1:(e.focusDrawing([n]),t.executeCommand(Ie.id,{value:"open"}),!0)}},We="univer-upload-loading",Ge="univer-upload-loading-body",Be="univer-upload-loading-body-animation",xe="univer-UniverCircleAnimation",Fe="univer-upload-loading-body-text",ae={uploadLoading:We,uploadLoadingBody:Ge,uploadLoadingBodyAnimation:Be,univerCircleAnimation:xe,uploadLoadingBodyText:Fe},Ve=()=>{const i=k.useDependency(E.IImageIoService),n=k.useDependency(p.LocaleService),[e,t]=A.useState(0);return A.useEffect(()=>{const r=i.change$.subscribe(o=>{t(o)});return()=>{r.unsubscribe()}},[i]),A.createElement("div",{style:{display:e>0?"block":"none"},className:ae.uploadLoading},A.createElement("div",{className:ae.uploadLoadingBody},A.createElement("div",{className:ae.uploadLoadingBodyAnimation}),A.createElement("div",{className:ae.uploadLoadingBodyText},`${n.t("uploadLoading.loading")}: ${e}`)))};var $e=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ye=(i,n,e,t)=>{for(var r=t>1?void 0:t?He(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&$e(n,e,r),r},Z=(i,n)=>(e,t)=>n(e,t,i);let le=class extends p.RxDisposable{constructor(n,e,t,r,o,s,a){super();H(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=e,this._canvasPopManagerService=t,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(ne.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(ne.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(W.BuiltInUIPart.CONTENT,()=>k.connectInjector(Ve,this._injector))}_dispose(n){const e=n.getUnitId();this._renderManagerService.removeRender(e)}_create(n){if(!n)return;const e=n.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(n){const e=n.getAllObjects();for(const t of e)if(t instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const e=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!e)return;const t=e.getTransformerByCreate();if(!t)return;const r=[];this.disposeWithMe(p.toDisposable(t.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=t.getSelectedObjectMap();if(s.size>1){r.forEach(g=>g.dispose());return}const a=s.values().next().value;if(!a)return;const c=a.oKey,u=this._drawingManagerService.getDrawingOKey(c);if(!u)return;const{unitId:l,subUnitId:d,drawingId:h}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,d,h)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:d,drawingId:h}])}))),this.disposeWithMe(p.toDisposable(t.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(p.toDisposable(t.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,e,t){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:n,subUnitId:e,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:we.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:e,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:e,drawingId:t}],disable:!1}]}};le=Ye([p.OnLifecycle(p.LifecycleStages.Steady,le),Z(0,B.Inject(B.Injector)),Z(1,E.IDrawingManagerService),Z(2,B.Inject(z.SheetCanvasPopManagerService)),Z(3,x.IRenderManagerService),Z(4,p.IUniverInstanceService),Z(5,p.IContextService),Z(6,B.Inject(W.IUIPartsService))],le);const he={id:"sheet.operation.insert-float-image",type:p.CommandType.OPERATION,handler:(i,n)=>!0},me={id:"sheet.operation.insert-cell-image",type:p.CommandType.OPERATION,handler:(i,n)=>!0},Se={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(w=>w.unitId),a=r.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:l,redo:d,objects:h}=a;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}},{id:L.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},{id:L.id,params:s}]}),!0):!1}},pe={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:a,subUnitId:c,undo:u,redo:l,objects:d}=s;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:c,op:l,objects:d,type:m.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:l,objects:d,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[a]}]}),!0):!1}},Re={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService);if(!n)return!1;const r=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=n,u={unitId:o,subUnitId:s,drawingIds:a};let l;if(c===E.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):c===E.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):c===E.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):c===E.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:d,redo:h,undo:g}=l;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}};function Xe(i){const n=[];return i.forEach(e=>{const{parent:t,children:r}=e,{unitId:o,subUnitId:s,drawingId:a}=t,c=x.getGroupState(0,0,r.map(d=>d.transform||{})),u=r.map(d=>{const h=d.transform||{left:0,top:0},{unitId:g,subUnitId:w,drawingId:f}=d;return{unitId:g,subUnitId:w,drawingId:f,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:a}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:c};n.push({parent:l,children:u})}),n}function ke(i){const n=[];return i.forEach(e=>{const{parent:t,children:r}=e,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=t;if(c==null)return;const u=r.map(d=>{const{transform:h}=d,{unitId:g,subUnitId:w,drawingId:f}=d,_=x.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:g,subUnitId:w,drawingId:f,transform:_,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:u})}),n}const Me={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:g,children:w})=>{o.push(g.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:l,objects:d}=s;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:ke(d),type:m.DrawingApplyType.UNGROUP}},{id:L.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.GROUP}},{id:L.id,params:o}]}),!0):!1}},Te={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:g,children:w})=>{o.push(g.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:l,objects:d}=s;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:Xe(d),type:m.DrawingApplyType.GROUP}},{id:L.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:L.id,params:o}]}),!0):!1}};function V(i,n){const{from:e,to:t}=i,{column:r,columnOffset:o,row:s,rowOffset:a}=e,{column:c,columnOffset:u,row:l,rowOffset:d}=t,h=n.attachRangeWithCoord({startColumn:r,endColumn:r,startRow:s,endRow:s});if(h==null)return;const g=n.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:l,endRow:l});if(g==null)return;const{startX:w,startY:f}=h,{startX:_,startY:M}=g,I=x.precisionTo(w+o,1),D=x.precisionTo(f+a,1);let R=x.precisionTo(_+u-I,1),v=x.precisionTo(M+d-D,1);return h.startX===g.endX&&(R=0),h.startY===g.endY&&(v=0),{left:I,top:D,width:R,height:v}}function j(i,n){const{left:e=0,top:t=0,width:r=0,height:o=0}=i,s=n.getSelectionCellByPosition(e,t);if(s==null)return;const a={column:s.actualColumn,columnOffset:x.precisionTo(e-s.startX,1),row:s.actualRow,rowOffset:x.precisionTo(t-s.startY,1)},c=n.getSelectionCellByPosition(e+r,t+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:x.precisionTo(e+r-c.startX,1),row:c.actualRow,rowOffset:x.precisionTo(t+o-c.startY,1)};return{from:a,to:u}}var ze=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&ze(n,e,r),r},Y=(i,n)=>(e,t)=>n(e,t,i);let de=class extends p.Disposable{constructor(i,n,e,t,r,o,s,a,c,u,l){super(),this._commandService=i,this._univerInstanceService=n,this._selectionManagerService=e,this._selectionRenderService=t,this._imageIoService=r,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=a,this._messageService=c,this._localeService=u,this._renderManagerService=l,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===me.id||i.id===he.id){const n=i.params;if(n.files==null)return;const e=n.files.length;if(e>E.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(e),i.id===me.id?n.files.forEach(async t=>{await this._insertCellImage(t)}):n.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const D=I.message;D===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo();if(e==null)return;const{unitId:t,subUnitId:r}=e,{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:u,height:l,image:d}=await E.getImageSize(c||""),h=this._renderManagerService.getRenderById(t);if(h==null)return;const{width:g,height:w}=h.scene;this._imageIoService.addImageSourceCache(a,s,d);let f=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||l>E.DRAWING_IMAGE_HEIGHT_LIMIT){const I=E.DRAWING_IMAGE_WIDTH_LIMIT/u,D=E.DRAWING_IMAGE_HEIGHT_LIMIT/l;f=Math.max(I,D)}const _=this._getImagePosition(u*f,l*f,g,w);if(_==null)return;const M={unitId:t,subUnitId:r,drawingId:o,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:V(_,this._selectionRenderService),sheetTransform:_};this._commandService.executeCommand(Se.id,{unitId:t,drawings:[M]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const n=i.getActiveSheet();if(n==null)return;const e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const r=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};r&&r.length>0&&(o=r[r.length-1].range);const s=this._selectionRenderService.attachRangeWithCoord(o);if(s==null)return;let{startColumn:a,startRow:c,startX:u,startY:l}=s,d=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),d=!0),l+n>t&&(l=t-n,l<0&&(l=0,n=t),d=!0),d){const f=this._selectionRenderService.getSelectionCellByPosition(u,l);if(f==null)return;u=f.startX,l=f.startY,a=f.actualColumn,c=f.actualRow}const h={column:a,columnOffset:0,row:c,rowOffset:0},g=this._selectionRenderService.getSelectionCellByPosition(u+i,l+n);if(g==null)return;const w={column:g.actualColumn,columnOffset:u+i-g.startX,row:g.actualRow,rowOffset:l+n-g.startY};return{from:h,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:r}=i;this._commandService.executeCommand(Re.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:r})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:r,drawingId:o,drawingType:s,transform:a}=e;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:r,drawingId:o});if(c==null)return;const u=j({...c.transform,...a},this._selectionRenderService);if(u==null)return;const l={...e,transform:{...c.transform,...a,...V(u,this._selectionRenderService)},sheetTransform:{...u}};n.push(l)}),n.length>0&&this._commandService.executeCommand(pe.id,{unitId:i[0].unitId,drawings:n}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Me.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Te.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};de=qe([p.OnLifecycle(p.LifecycleStages.Rendered,de),Y(0,p.ICommandService),Y(1,p.IUniverInstanceService),Y(2,B.Inject(C.SelectionManagerService)),Y(3,z.ISelectionRenderService),Y(4,E.IImageIoService),Y(5,m.ISheetDrawingService),Y(6,E.IDrawingManagerService),Y(7,p.IContextService),Y(8,W.IMessageService),Y(9,B.Inject(p.LocaleService)),Y(10,x.IRenderManagerService)],de);var $=function(){return $=Object.assign||function(i){for(var n,e=1,t=arguments.length;e<t;e++){n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(i[r]=n[r])}return i},$.apply(this,arguments)},Je=function(i,n){var e={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&n.indexOf(t)<0&&(e[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(i);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(i,t[r])&&(e[t[r]]=i[t[r]]);return e},Oe=A.forwardRef(function(i,n){var e=i.icon,t=i.id,r=i.className,o=i.extend,s=Je(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),c=A.useRef("_".concat(et()));return Ae(e,"".concat(t),{defIds:e.defIds,idSuffix:c.current},$({ref:n,className:a},s),o)});function Ae(i,n,e,t,r){return A.createElement(i.tag,$($({key:n},Ze(i,e,r)),t),(Qe(i,e).children||[]).map(function(o,s){return Ae(o,"".concat(n,"-").concat(i.tag,"-").concat(s),e,void 0,r)}))}function Ze(i,n,e){var t=$({},i.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var r=n.defIds;return!r||r.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(t[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function Qe(i,n){var e,t=n.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?$($({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?$($({},r),{attrs:$($({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):i}function et(){return Math.random().toString(36).substring(2,8)}Oe.displayName="UniverIcon";var tt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},be=A.forwardRef(function(i,n){return A.createElement(Oe,Object.assign({},i,{id:"add-image-single",ref:n,icon:tt}))});be.displayName="AddImageSingle";const nt="univer-upload-file-menu",rt="univer-upload-file-menu-input",_e={uploadFileMenu:nt,uploadFileMenuInput:rt},Ee="COMPONENT_UPLOAD_FILE_MENU";var ge=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(ge||{});const it=i=>{const{type:n}=i,e=k.useDependency(p.ICommandService),t=A.useRef(null),r=()=>{var a;(a=t.current)==null||a.click()},o=E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const c=a.target.files;if(c==null)return;const u=Array.from(c);n===ge.floatImage?e.executeCommand(he.id,{files:u}):n===ge.cellImage&&e.executeCommand(me.id,{files:u}),t.current&&(t.current.value="")};return A.createElement("div",{onClick:r,className:_e.uploadFileMenu},A.createElement("input",{type:"file",className:_e.uploadFileMenuInput,ref:t,onChange:s,accept:o,multiple:!0}))},Pe="addition-and-subtraction-single",Ue="sheet.menu.image";function ot(i){return{id:Ue,type:W.MenuItemType.SUBITEMS,positions:[W.MenuPosition.TOOLBAR_START],group:W.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Pe,tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET)}}function st(i){return{id:he.id,title:"sheetImage.upload.float",type:W.MenuItemType.SELECTOR,label:{name:Ee,props:{type:ge.floatImage}},positions:[Ue],hidden$:W.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET)}}const at="univer-image-common-panel",ct="univer-image-common-panel-grid",lt="univer-image-common-panel-border",dt="univer-image-common-panel-title",ut="univer-image-common-panel-row",mt="univer-image-common-panel-row-vertical",gt="univer-image-common-panel-column",ht="univer-image-common-panel-column-center",pt="univer-image-common-panel-inline",ft="univer-image-common-panel-span2",wt="univer-image-common-panel-span3",St="univer-image-common-panel-input",vt="univer-sheet-image-menu",_t="univer-sheet-image-menu-input",q={imageCommonPanel:at,imageCommonPanelGrid:ct,imageCommonPanelBorder:lt,imageCommonPanelTitle:dt,imageCommonPanelRow:ut,imageCommonPanelRowVertical:mt,imageCommonPanelColumn:gt,imageCommonPanelColumnCenter:ht,imageCommonPanelInline:pt,imageCommonPanelSpan2:ft,imageCommonPanelSpan3:wt,imageCommonPanelInput:St,sheetImageMenu:vt,sheetImageMenuInput:_t},Ct=i=>{var D;const n=k.useDependency(p.ICommandService),e=k.useDependency(p.LocaleService),t=k.useDependency(E.IDrawingManagerService),r=k.useDependency(x.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,c=r.getRenderById(a),u=c==null?void 0:c.scene;if(u==null)return;const l=u.getTransformerByCreate(),[d,h]=A.useState(!0),g=(D=s.anchorType)!=null?D:m.SheetDrawingAnchorType.Position,[w,f]=A.useState(g);function _(R,v){const O=[];return R.forEach(S=>{const{oKey:U}=S,T=v.getDrawingOKey(U);if(T==null)return O.push(null),!0;const{unitId:G,subUnitId:P,drawingId:b,drawingType:y,anchorType:N,sheetTransform:X}=T;O.push({unitId:G,subUnitId:P,drawingId:b,anchorType:N,sheetTransform:X,drawingType:y})}),O}A.useEffect(()=>{const R=l.onClearControlObservable.add(O=>{O===!0&&h(!1)}),v=l.onChangeStartObservable.add(O=>{var T;const{objects:S}=O,U=_(S,t);if(U.length===0)h(!1);else if(U.length>=1){h(!0);const G=((T=U[0])==null?void 0:T.anchorType)||m.SheetDrawingAnchorType.Position;f(G)}});return()=>{v==null||v.dispose(),R==null||R.dispose()}},[]);function M(R){f(R);const v=t.getFocusDrawings();if(v.length===0)return;const O=v.map(S=>({unitId:S.unitId,subUnitId:S.subUnitId,drawingId:S.drawingId,anchorType:R}));n.executeCommand(pe.id,{unitId:v[0].unitId,drawings:O})}const I=R=>R?"block":"none";return A.createElement("div",{className:se(q.imageCommonPanelGrid,q.imageCommonPanelBorder),style:{display:I(d)}},A.createElement("div",{className:q.imageCommonPanelRow},A.createElement("div",{className:se(q.imageCommonPanelColumn,q.imageCommonPanelTitle)},A.createElement("div",null,e.t("drawing-anchor.title")))),A.createElement("div",{className:se(q.imageCommonPanelRow)},A.createElement("div",{className:se(q.imageCommonPanelColumn)},A.createElement(J.RadioGroup,{value:w,onChange:M,direction:"vertical"},A.createElement(J.Radio,{value:m.SheetDrawingAnchorType.Both},e.t("drawing-anchor.both")),A.createElement(J.Radio,{value:m.SheetDrawingAnchorType.Position},e.t("drawing-anchor.position")),A.createElement(J.Radio,{value:m.SheetDrawingAnchorType.None},e.t("drawing-anchor.none"))))))},Dt=()=>{const i=k.useDependency(E.IDrawingManagerService),n=i.getFocusDrawings();if(n==null||n.length===0)return;const[e,t]=A.useState(n);return A.useEffect(()=>{const r=i.focus$.subscribe(o=>{t(o)});return()=>{r.unsubscribe()}},[]),A.createElement("div",{className:q.imageCommonPanel},A.createElement(te.DrawingCommonPanel,{drawings:e}),A.createElement(Ct,{drawings:e}))},ie={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(m.ISheetDrawingService),r=i.get(z.ISelectionRenderService),{direction:o}=n,s=t.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,c=s.map(l=>{const{transform:d}=l;if(d==null)return null;const h={...d},{left:g=0,top:w=0}=d;return o===p.Direction.UP?h.top=w-1:o===p.Direction.DOWN?h.top=w+1:o===p.Direction.LEFT?h.left=g-1:o===p.Direction.RIGHT&&(h.left=g+1),{...l,transform:h,sheetTransform:j(h,r)}}).filter(l=>l!=null);return e.syncExecuteCommand(pe.id,{unitId:a,drawings:c})?(e.syncExecuteCommand(L.id,[a]),!0):!1}},Ne={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:i=>{const n=i.get(p.ICommandService),t=i.get(m.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const r=t[0].unitId,o=t.map(s=>{const{unitId:a,subUnitId:c,drawingId:u,drawingType:l}=s;return{unitId:a,subUnitId:c,drawingId:u,drawingType:l}});return n.executeCommand(we.id,{unitId:r,drawings:o})}};function oe(i){return!i.getContextValue(p.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const It={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.DOWN}},yt={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.UP}},Rt={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.LEFT}},Mt={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.RIGHT}},Tt={id:Ne.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:oe,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Ot=Object.defineProperty,At=Object.getOwnPropertyDescriptor,bt=(i,n,e,t)=>{for(var r=t>1?void 0:t?At(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Ot(n,e,r),r},ee=(i,n)=>(e,t)=>n(e,t,i);const Et={};let re=class extends p.Disposable{constructor(i,n,e,t,r,o){super(),this._config=i,this._injector=n,this._componentManager=e,this._menuService=t,this._commandService=r,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Pe,be)),this.disposeWithMe(i.register(Ee,it)),this.disposeWithMe(i.register(De,Dt))}_initMenus(){const{menu:i={}}=this._config;[ot,st].forEach(n=>{this._menuService.addMenuItem(n(this._injector),i)})}_initCommands(){[he,me,Se,we,pe,Ie,L,ye,Me,Te,ie,Ne,Re].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[It,yt,Rt,Mt,Tt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};re=bt([p.OnLifecycle(p.LifecycleStages.Rendered,re),ee(1,B.Inject(B.Injector)),ee(2,B.Inject(W.ComponentManager)),ee(3,W.IMenuService),ee(4,p.ICommandService),ee(5,W.IShortcutService)],re);var Pt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Nt=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ut(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Pt(n,e,r),r},Q=(i,n)=>(e,t)=>n(e,t,i);const jt=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id],Lt=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let ue=class extends p.Disposable{constructor(i,n,e,t,r,o){super(),this._commandService=i,this._sheetInterceptorService=n,this._sheetDrawingService=e,this._drawingManagerService=t,this._selectionRenderService=r,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!jt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(n===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===C.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(n===C.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(n===C.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(n===C.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(n===C.SetRowHiddenCommand.id||n===C.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForRowVisible(t,r,o)}else if(n===C.SetSpecificColsVisibleCommand.id||n===C.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForColVisible(t,r,o)}else if(n===C.DeltaRowHeightCommand.id||n===C.SetRowHeightCommand.id||n===C.DeltaColumnWidthCommand.id||n===C.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:r,ranges:o}=e,s=n===C.DeltaRowHeightCommand.id||n===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,r,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const e=C.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,r=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(t,r),c=[],u=[];if(Object.keys(a).forEach(l=>{const d=a[l],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,n,d);c.push(...h),u.push(...g)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:h,objects:g}=l;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:h,objects:g,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:d,objects:g,type:m.DrawingApplyType.UPDATE}})}if(u.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(u),d=l.undo,h=l.redo,g=l.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:h,objects:g,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:d,objects:g,type:m.DrawingApplyType.INSERT}})}return o.push({id:L.id,params:[t]}),s.push({id:L.id,params:[t]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,n,e){const t=[],r=[],{sheetTransform:o,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:u,drawingId:l}=e,{from:d,to:h}=o,{row:g,column:w}=d,{row:f,column:_}=h;if(o==null||a==null)return{updateDrawings:t,deleteDrawings:r};const{startRow:M,endRow:I,startColumn:D,endColumn:R}=i;let v=null,O=null;if(n===0&&g>=M&&f<=I)if(w>=D&&_<=R)r.push({unitId:c,subUnitId:u,drawingId:l});else{const S=this._shrinkCol(o,a,D,R,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(n===1&&w>=D&&_<=R)if(g>=M&&f<=I)r.push({unitId:c,subUnitId:u,drawingId:l});else{const S=this._shrinkRow(o,a,M,I,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(n===2){const S=this._expandRow(o,a,M,I,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(n===3){const S=this._expandCol(o,a,D,R,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}if(v!=null&&O!=null){const S=V(v,this._selectionRenderService);t.push({...e,sheetTransform:v,transform:S})}return{updateDrawings:t,deleteDrawings:r}}_remainDrawingSize(i,n,e){const t=j({...i},this._selectionRenderService);t!=null&&n.push({...e,sheetTransform:t})}_getDrawingUndoForColVisible(i,n,e){const t=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(t).forEach(l=>{const d=t[l],{sheetTransform:h,transform:g,anchorType:w=m.SheetDrawingAnchorType.Position}=d;if(w===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,r,d);else{const{from:f,to:_}=h,{row:M,column:I}=f,{row:D,column:R}=_;for(let v=0;v<e.length;v++){const O=e[v],{startRow:S,endRow:U,startColumn:T,endColumn:G}=O;if(R<T)continue;if(w===m.SheetDrawingAnchorType.Position){let y=null,N=null;if(I>=T&&I<=G){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:I,endColumn:G,startRow:f.row,endRow:_.row});if(X==null)return;N={...g,left:X.startX}}if(N!=null&&(y=j(N,this._selectionRenderService),y!=null&&N!=null)){r.push({...d,sheetTransform:y,transform:N});break}this._remainDrawingSize(g,r,d);continue}if(I>=T&&R<=G)continue;let P=null,b=null;if(I>=T&&I<=G){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:I,endColumn:G,startRow:f.row,endRow:_.row});if(y==null)return;b={...g,left:(y==null?void 0:y.startX)||0,width:((g==null?void 0:g.width)||0)-y.endX+y.startX}}else if(R>=T&&R<=G){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:R,startRow:f.row,endRow:_.row});if(y==null)return;b={...g,left:y.startX-((g==null?void 0:g.width)||0)}}else{const y=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:G,startRow:f.row,endRow:_.row});if(y==null)return;if(b={...g,width:((g==null?void 0:g.width)||0)-y.endX+y.startX},P=j(b,this._selectionRenderService),P!=null&&b!=null){o.push({...d,sheetTransform:P,transform:b});break}}if(b!=null&&(P=j(b,this._selectionRenderService)),b!=null&&P!=null){r.push({...d,sheetTransform:P,transform:b});break}else this._remainDrawingSize(g,r,d)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,n,r),c=[],u=[];if(o.length>0){const{redos:l,undos:d}=this._createUndoAndRedoMutation(i,n,o);c.push(...l),u.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(i,n,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:r,redo:o,objects:s}=t,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:s,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[i]}],c=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:r,objects:s,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[i]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(i,n,e){const t=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(t).forEach(l=>{const d=t[l],{sheetTransform:h,transform:g,anchorType:w=m.SheetDrawingAnchorType.Position}=d;if(w===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,r,d);else{const{from:f,to:_}=h,{row:M,column:I}=f,{row:D,column:R}=_;for(let v=0;v<e.length;v++){const O=e[v],{startRow:S,endRow:U,startColumn:T,endColumn:G}=O;if(D<S)continue;if(w===m.SheetDrawingAnchorType.Position){let y=null,N=null;if(M>=S&&M<=U){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:M,endRow:U});if(X==null)return;N={...g,top:X.startY}}if(N!=null&&(y=j(N,this._selectionRenderService),y!=null&&N!=null)){r.push({...d,sheetTransform:y,transform:N});break}this._remainDrawingSize(g,r,d);continue}if(M>=S&&D<=U)continue;let P=null,b=null;if(M>=S&&M<=U){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:M,endRow:U});if(y==null)return;b={...g,top:(y==null?void 0:y.startY)||0,height:((g==null?void 0:g.height)||0)-y.endY+y.startY}}else if(D>=S&&D<=U){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:S,endRow:D});if(y==null)return;b={...g,top:y.startY-((g==null?void 0:g.height)||0)}}else{const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:S,endRow:U});if(y==null)return;if(b={...g,height:((g==null?void 0:g.height)||0)-y.endY+y.startY},P=j(b,this._selectionRenderService),P!=null&&b!=null){o.push({...d,sheetTransform:P,transform:b});break}}if(b!=null&&(P=j(b,this._selectionRenderService)),b!=null&&P!=null){r.push({...d,sheetTransform:P,transform:b});break}else this._remainDrawingSize(g,r,d)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,n,r),c=[],u=[];if(o.length>0){const{redos:l,undos:d}=this._createUndoAndRedoMutation(i,n,o);c.push(...l),u.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(i,n,e,t){const r=this._drawingManagerService.getDrawingData(i,n),o=[];return Object.keys(r).forEach(s=>{const a=r[s],{sheetTransform:c,transform:u,anchorType:l=m.SheetDrawingAnchorType.Position}=a;if(l===m.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,a);else{const{from:d,to:h}=c,{row:g,column:w}=d,{row:f,column:_}=h;for(let M=0;M<e.length;M++){const I=e[M],{startRow:D,endRow:R,startColumn:v,endColumn:O}=I;if(f<D||_<v)continue;if(l===m.SheetDrawingAnchorType.Position&&(g<=D&&f>=R||w<=v&&_>=O)){this._remainDrawingSize(u,o,a);continue}const S=V({...c},this._selectionRenderService);if(S!=null){o.push({...a,transform:S});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,n,o)}_getUnitIdAndSubUnitId(i,n){let e,t;if(n==="insert")e=i.unitId,t=i.subUnitId;else{const r=C.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;e=r.unitId,t=r.subUnitId}return{unitId:e,subUnitId:t}}_moveRowInterceptor(i,n){const e=this._getUnitIdAndSubUnitId(i,n);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:r}=e,{range:o}=i,s=o.startRow,a=o.endRow,c=[],u=[],l=this._sheetDrawingService.getDrawingData(t,r),d=[],h=[];if(Object.keys(l).forEach(g=>{const w=l[g],{sheetTransform:f,transform:_,anchorType:M=m.SheetDrawingAnchorType.Position}=w;if(f==null||_==null)return;let I,D;if(n==="insert"){const v=this._expandRow(f,_,s,a,M);I=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else{const{from:v,to:O}=f,{row:S}=v,{row:U}=O;if(S>=s&&U<=a)h.push({unitId:t,subUnitId:r,drawingId:g});else{const T=this._shrinkRow(f,_,s,a,M);I=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!I||!D)return;const R={unitId:t,subUnitId:r,drawingId:g,transform:D,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:w,redo:f,objects:_}=g;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.UPDATE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),w=g.undo,f=g.redo,_=g.objects;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.REMOVE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[t]}),u.push({id:L.id,params:[t]}),{redos:c,undos:u}}_moveColInterceptor(i,n){const e=this._getUnitIdAndSubUnitId(i,n);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:r}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,c=[],u=[],l=this._sheetDrawingService.getDrawingData(t,r),d=[],h=[];if(Object.keys(l).forEach(g=>{const w=l[g],{sheetTransform:f,transform:_,anchorType:M=m.SheetDrawingAnchorType.Position}=w;if(f==null||_==null)return;let I,D;if(n==="insert"){const v=this._expandCol(f,_,s,a,M);I=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else{const{from:v,to:O}=f,{column:S}=v,{column:U}=O;if(S>=s&&U<=a)h.push({unitId:t,subUnitId:r,drawingId:g});else{const T=this._shrinkCol(f,_,s,a,M);I=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!I||!D)return;const R={unitId:t,subUnitId:r,drawingId:g,transform:D,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:w,redo:f,objects:_}=g;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.UPDATE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),w=g.undo,f=g.redo,_=g.objects;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.REMOVE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[t]}),u.push({id:L.id,params:[t]}),{redos:c,undos:u}}_expandCol(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:s.row,endRow:a.row});if(h==null)return;d={...n,left:(n.left||0)+h.endX-h.startX},l=j(d,this._selectionRenderService)}else if(u>=t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u+o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_shrinkCol(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>t)l={from:{...s,column:c-o},to:{...a,column:u-o}},d=V(l,this._selectionRenderService);else{if(c>=e&&u<=t)return null;if(c<e&&u>t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u-o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};else if(c>=e&&c<=t){if(c===e)d={...n,left:(n.left||0)-i.from.columnOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:s.row,endRow:a.row});if(h==null)return;d={...n,left:(n.left||0)-h.endX+h.startX-i.from.columnOffset}}l=j(d,this._selectionRenderService)}else if(u>=e&&u<=t&&r===m.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(h==null)return;l={from:{...s},to:{...a,column:e-1,columnOffset:h.endX-h.startX}},d=V(l,this._selectionRenderService)}}return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_expandRow(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...n,top:(n.top||0)+h.endY-h.startY},l=j(d,this._selectionRenderService)}else if(u>=t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u+o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_shrinkRow(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>t)l={from:{...s,row:c-o},to:{...a,row:u-o}},d=V(l,this._selectionRenderService);else{if(c>=e&&u<=t)return null;if(c<e&&u>t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u-o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};else if(c>=e&&c<=t){if(c===e)d={...n,top:(n.top||0)-i.from.rowOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...n,top:(n.top||0)-h.endY+h.startY-i.from.rowOffset}}l=j(d,this._selectionRenderService)}else if(u>=e&&u<=t&&r===m.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(h==null)return;l={from:{...s},to:{...a,row:e-1,rowOffset:h.endY-h.startY}},d=V(l,this._selectionRenderService)}}return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const n=i.params,{unitId:e,subUnitId:t}=n,r=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(r).forEach(a=>{const c=r[a];Object.keys(c).forEach(u=>{const l=c[u].data;l!=null&&Object.keys(l).forEach(d=>{a===e&&u===t?o.push(l[d]):s.push(l[d])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Lt.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:e,subUnitId:t,ranges:r}=n;this._refreshDrawingTransform(e,t,r)})}))}_refreshDrawingTransform(i,n,e){const t=this._drawingManagerService.getDrawingData(i,n),r=[];Object.keys(t).forEach(o=>{const s=t[o],{sheetTransform:a,anchorType:c=m.SheetDrawingAnchorType.Position}=s;if(c===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:l}=a,{row:d,column:h}=u,{row:g,column:w}=l;for(let f=0;f<e.length;f++){const _=e[f],{startRow:M,endRow:I,startColumn:D,endColumn:R}=_;if(p.Rectangle.intersects({startRow:M,endRow:I,startColumn:D,endColumn:R},{startRow:d,endRow:g,startColumn:h,endColumn:w})||d>I||h>R){r.push({...s,transform:V(a,this._selectionRenderService)});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(L.id,[i]))}};ue=Nt([p.OnLifecycle(p.LifecycleStages.Rendered,ue),Q(0,p.ICommandService),Q(1,B.Inject(C.SheetInterceptorService)),Q(2,m.ISheetDrawingService),Q(3,E.IDrawingManagerService),Q(4,z.ISelectionRenderService),Q(5,p.IUniverInstanceService)],ue);var Wt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Bt=(i,n,e,t)=>{for(var r=t>1?void 0:t?Gt(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Wt(n,e,r),r},K=(i,n)=>(e,t)=>n(e,t,i);function xt(i,n,e,t){const{scaleX:r,scaleY:o}=n.getAncestorScale(),s=n.getViewport(z.VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...i,absolute:a};const{left:c,right:u,top:l,bottom:d}=i,h=t.getFreeze(),{startColumn:g,startRow:w,xSplit:f,ySplit:_}=h,M=e.getNoMergeCellPositionByIndexWithNoHeader(w-_,g-f),I=e.getNoMergeCellPositionByIndexWithNoHeader(w,g),{rowHeaderWidth:D,columnHeaderHeight:R}=e,v=I.startX-M.startX,O=I.startY-M.startY,{top:S,left:U,viewportScrollX:T,viewportScrollY:G}=s;let P,b;c<U?(a.left=!0,P=(v+D+(c-U))*r,b=Math.max(Math.min((v+D+(u-U))*r,(v+D)*r),(u-T)*r)):(a.left=!1,P=Math.max((c-T)*r,(v+D)*r),b=Math.max((u-T)*r,(v+D)*r));let y,N;return l<S?(a.top=!0,y=(O+R+(l-S))*o,N=Math.max(Math.min((O+R+(u-S))*o,(O+R)*o),(d-G)*o)):(a.top=!1,y=Math.max((l-G)*o,(O+R)*o),N=Math.max((d-G)*o,(O+R)*o)),{left:P,right:b,top:y,bottom:N,absolute:a}}const fe=(i,n,e,t)=>{const{scene:r}=n,{left:o,top:s,width:a,height:c,angle:u}=i,l={left:o,right:o+a,top:s,bottom:s+c},d=xt(l,r,e,t);return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:u,width:a,height:c,absolute:d.absolute}};exports.SheetCanvasFloatDomManagerService=class extends p.Disposable{constructor(e,t,r,o,s,a,c,u){super();H(this,"_domLayerMap",new Map);H(this,"_domLayerInfoMap",new Map);H(this,"_transformChange$",new ne.Subject);H(this,"transformChange$",this._transformChange$.asObservable());H(this,"_remove$",new ne.Subject);H(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,this._sheetSkeletonManagerService=r,this._commandService=o,this._drawingManagerService=s,this._selectionRenderService=a,this._canvasFloatDomService=c,this._sheetDrawingService=u,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(e,t){let r=this._domLayerMap.get(e);r||(r=new Map,this._domLayerMap.set(e,r));let o=r.get(t);return o||(o=new Map,r.set(t,o)),o}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const t=this._renderManagerService.getRenderById(e),r=t==null?void 0:t.scene;if(t==null||r==null)return null;const o=r.getTransformerByCreate(),s=t.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:t,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{const{unitId:r,subUnitId:o,drawingId:s}=t,a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(t),u=this._sheetSkeletonManagerService.getUnitSkeleton(r,o);if(c==null||a==null||u==null)return;const{transform:l,drawingType:d}=c;if(d!==p.DrawingTypeEnum.DRAWING_DOM)return;const h=this._getSceneAndTransformerByDrawingSearch(r);if(h==null)return;const{scene:g,canvas:w}=h;if(l==null)return!0;const{left:f,top:_,width:M,height:I,angle:D,flipX:R,flipY:v,skewX:O,skewY:S}=l,U=E.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),T=g.getObject(U);if(T!=null){T.transformByState({left:f,top:_,width:M,height:I,angle:D,flipX:R,flipY:v,skewX:O,skewY:S});return}const G={left:f,top:_,width:M,height:I,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},P=new x.Rect(U,G);g.addObject(P,x.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(P);const b=new p.DisposableCollection,y=fe(P,h.renderObject,u.skeleton,a.worksheet),N=new ne.BehaviorSubject(y),X={dispose:b,rect:P,position$:N,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:N,id:s,componentKey:c.componentKey,onPointerDown:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{w.dispatchEvent(new WheelEvent(F.type,F))}});const ve=P.onTransformChangeObservable.add(()=>{const F=fe(P,h.renderObject,u.skeleton,a.worksheet);N.next(F)});b.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ve&&b.add(ve),this._domLayerInfoMap.set(s,X)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;const t=(s,a)=>{const c=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),l=Array.from(u.keys()),d=C.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),h=this._sheetSkeletonManagerService.getUnitSkeleton(s,a);!c||!d||!h||l.forEach(g=>{const w=this._domLayerInfoMap.get(g);if(w){const f=fe(w.rect,c.renderObject,h.skeleton,d.worksheet);w.position$.next(f)}})};if(e.id===z.SetScrollOperation.id){const s=e.params,{unitId:a,sheetId:c}=s;t(a,c)}else if(e.id===z.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(r=this._domLayerMap.get(a))==null?void 0:r.keys())!=null?o:[]).forEach(u=>{t(a,u)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;t(s,a)}}))}_getPosition(e){const{startX:t,endX:r,startY:o,endY:s}=e,a=this._selectionRenderService.getSelectionCellByPosition(t,o);if(a==null)return;const c={column:a.actualColumn,columnOffset:t-a.startX,row:a.actualRow,rowOffset:o-a.startY},u=this._selectionRenderService.getSelectionCellByPosition(r,s);if(u==null)return;const l={column:u.actualColumn,columnOffset:r-u.startX,row:u.actualRow,rowOffset:s-u.startY};return{from:c,to:l}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const r=this._drawingManagerService.getDrawingByParam(t);if(!r||r.drawingType!==p.DrawingTypeEnum.DRAWING_DOM)return;const o={...r.transform};this._transformChange$.next({id:t.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e){const t=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:r,subUnitId:o}=t,{initPosition:s,componentKey:a}=e,c=p.Tools.generateRandomId(),u=this._getPosition(s);if(u==null)return;const l={unitId:r,subUnitId:o,drawingId:c,drawingType:p.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:u,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY}};return this._commandService.executeCommand(Se.id,{unitId:r,drawings:[l]}),this._ensureMap(r,o).set(c,e),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(e,t=!1){const r=this._domLayerInfoMap.get(e);if(!r)return;const{unitId:o,subUnitId:s}=r,a=this._ensureMap(o,s);this._domLayerInfoMap.delete(e),a.delete(e),r.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(r.rect),t){const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!u)return;const l=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:d,objects:h}=l;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:d,objects:h,type:m.DrawingApplyType.REMOVE})}}};exports.SheetCanvasFloatDomManagerService=Bt([K(0,B.Inject(x.IRenderManagerService)),K(1,p.IUniverInstanceService),K(2,B.Inject(z.SheetSkeletonManagerService)),K(3,B.Inject(p.ICommandService)),K(4,E.IDrawingManagerService),K(5,z.ISelectionRenderService),K(6,B.Inject(W.CanvasFloatDomService)),K(7,m.ISheetDrawingService)],exports.SheetCanvasFloatDomManagerService);var Ft=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,$t=(i,n,e,t)=>{for(var r=t>1?void 0:t?Vt(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Ft(n,e,r),r},Ce=(i,n)=>(e,t)=>n(e,t,i);const Ht="SHEETS_IMAGE_UI_PLUGIN";var ce;exports.UniverSheetsDrawingUIPlugin=(ce=class extends p.Plugin{constructor(e={},t,r){super();H(this,"_pluginConfig");this._injector=t,this._localeService=r,this._pluginConfig=p.Tools.deepMerge({},Et,e)}onStarting(e){super.onStarting(e),this._initDependencies(e)}_initDependencies(e){[[exports.SheetCanvasFloatDomManagerService],[re,{useFactory:()=>this._injector.createInstance(re,this._pluginConfig)}],[de],[le],[ue]].forEach(r=>e.add(r))}},H(ce,"type",p.UniverInstanceType.UNIVER_SHEET),H(ce,"pluginName",Ht),ce);exports.UniverSheetsDrawingUIPlugin=$t([Ce(1,B.Inject(B.Injector)),Ce(2,B.Inject(p.LocaleService))],exports.UniverSheetsDrawingUIPlugin);
|