@univerjs/docs-drawing-ui 0.1.15 → 0.1.16
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 +1 -1
- package/lib/es/index.js +11 -22
- package/lib/types/views/doc-image-panel/DocDrawingPanel.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +22 -22
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var fe=Object.defineProperty;var Ie=(e,n,t)=>n in e?fe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var W=(e,n,t)=>(Ie(e,typeof n!="symbol"?n+"":n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),O=require("@wendellhu/redi"),P=require("@univerjs/engine-render"),L=require("@univerjs/drawing-ui"),Z=require("rxjs"),G=require("@univerjs/docs-ui"),I=require("@univerjs/drawing"),m=require("@univerjs/docs-drawing"),w=require("@univerjs/ui"),b=require("@wendellhu/redi/react-bindings"),v=require("react"),F=require("clsx"),V=require("@univerjs/design"),Y=require("@univerjs/docs"),y={id:"sheet.operation.clear-drawing-transformer",type:a.CommandType.MUTATION,handler:(e,n)=>{const t=e.get(P.IRenderManagerService);return n.forEach(i=>{var r,o;(o=(r=t.getRenderById(i))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},k={id:"doc.command.remove-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(h=>{const{unitId:D}=h;s.push(D)});const c=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:l,redo:g,objects:p}=c;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:g,objects:p,type:m.DocDrawingApplyType.REMOVE})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:p,type:m.DocDrawingApplyType.INSERT}},{id:y.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:g,objects:p,type:m.DocDrawingApplyType.REMOVE}},{id:y.id,params:s}]}),!0):!1}},J="COMPONENT_DOC_DRAWING_PANEL",ee={id:"sidebar.operation.doc-image",type:a.CommandType.COMMAND,handler:async(e,n)=>{const t=e.get(w.ISidebarService),i=e.get(a.LocaleService),r=e.get(I.IDrawingManagerService);switch(n.value){case"open":t.open({header:{title:i.t("docImage.panel.title")},children:{label:J},onClose:()=>{r.focusDrawing(null)},width:360});break;case"close":default:t.close();break}return!0}},ne={id:"sheet.operation.edit-sheet-image",type:a.CommandType.OPERATION,handler:(e,n)=>{const t=e.get(I.IDrawingManagerService),i=e.get(a.ICommandService);return n==null?!1:(t.focusDrawing([n]),i.executeCommand(ee.id,{value:"open"}),!0)}};var he=Object.defineProperty,De=Object.getOwnPropertyDescriptor,ve=(e,n,t,i)=>{for(var r=i>1?void 0:i?De(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&he(n,t,r),r},U=(e,n)=>(t,i)=>n(t,i,e);let B=class extends a.RxDisposable{constructor(n,t,i,r,o){super();W(this,"_initImagePopupMenu",new Set);this._drawingManagerService=n,this._canvasPopManagerService=t,this._renderManagerService=i,this._univerInstanceService=r,this._contextService=o,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(Z.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(Z.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(n=>this._create(n))}_dispose(n){const t=n.getUnitId();this._renderManagerService.removeRender(t)}_create(n){if(!n)return;const t=n.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(n){const t=n.getAllObjects();for(const i of t)if(i instanceof L.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const t=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!t)return;const i=t.getTransformerByCreate();if(!i)return;const r=[];this.disposeWithMe(a.toDisposable(i.onCreateControlObservable.add(()=>{if(this._hasCropObject(t))return;const s=i.getSelectedObjectMap();if(s.size>1){r.forEach(f=>f.dispose());return}const c=s.values().next().value;if(!c)return;const d=c.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:l,subUnitId:g,drawingId:p}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:L.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,g,p)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:g,drawingId:p}])}))),this.disposeWithMe(a.toDisposable(i.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(a.toDisposable(i.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,t,i){return[{label:"image-popup.edit",index:0,commandId:ne.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.delete",index:1,commandId:k.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:t,drawingId:i}]},disable:!1},{label:"image-popup.crop",index:2,commandId:L.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.reset",index:3,commandId:L.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:t,drawingId:i}],disable:!1}]}};B=ve([a.OnLifecycle(a.LifecycleStages.Rendered,B),U(0,I.IDrawingManagerService),U(1,O.Inject(G.DocCanvasPopManagerService)),U(2,P.IRenderManagerService),U(3,a.IUniverInstanceService),U(4,a.IContextService)],B);var _=function(){return _=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_.apply(this,arguments)},we=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)n.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(t[i[r]]=e[i[r]]);return t},te=v.forwardRef(function(e,n){var t=e.icon,i=e.id,r=e.className,o=e.extend,s=we(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),d=v.useRef("_".concat(ye()));return ie(t,"".concat(i),{defIds:t.defIds,idSuffix:d.current},_({ref:n,className:c},s),o)});function ie(e,n,t,i,r){return v.createElement(e.tag,_(_({key:n},Se(e,t,r)),i),(_e(e,t).children||[]).map(function(o,s){return ie(o,"".concat(n,"-").concat(e.tag,"-").concat(s),t,void 0,r)}))}function Se(e,n,t){var i=_({},e.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(i[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),i}function _e(e,n){var t,i=n.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?_(_({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?_(_({},r),{attrs:_(_({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function ye(){return Math.random().toString(36).substring(2,8)}te.displayName="UniverIcon";var Ce={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"}}]},re=v.forwardRef(function(e,n){return v.createElement(te,Object.assign({},e,{id:"add-image-single",ref:n,icon:Ce}))});re.displayName="AddImageSingle";const K={id:"doc.operation.insert-float-image",type:a.CommandType.OPERATION,handler:(e,n)=>!0},Me="univer-upload-file-menu",Oe="univer-upload-file-menu-input",Q={uploadFileMenu:Me,uploadFileMenuInput:Oe},Te=()=>{const e=b.useDependency(a.ICommandService),n=v.useRef(null),t=()=>{var o;(o=n.current)==null||o.click()},i=I.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(o=>`.${o.replace("image/","")}`).join(","),r=o=>{const s=o.target.files;if(s==null)return;const c=Array.from(s);e.executeCommand(K.id,{files:c}),n.current&&(n.current.value="")};return v.createElement("div",{onClick:t,className:Q.uploadFileMenu},v.createElement("input",{type:"file",className:Q.uploadFileMenuInput,ref:n,onChange:r,accept:i,multiple:!0}))},oe="COMPONENT_DOC_UPLOAD_FILE_MENU",ae="addition-and-subtraction-single",se="doc.menu.image";function Pe(e){return{id:se,type:w.MenuItemType.SUBITEMS,positions:[w.MenuPosition.TOOLBAR_START],group:w.MenuGroup.TOOLBAR_LAYOUT,icon:ae,tooltip:"docImage.title",hidden$:w.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}function Ee(e){return{id:K.id,title:"docImage.upload.float",type:w.MenuItemType.SELECTOR,label:{name:oe},positions:[se],hidden$:w.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}const Re="univer-image-common-panel",be="univer-image-common-panel-grid",Ae="univer-image-common-panel-border",Ue="univer-image-common-panel-title",Ne="univer-image-common-panel-row",Le="univer-image-common-panel-row-vertical",Ge="univer-image-common-panel-column",je="univer-image-common-panel-column-center",xe="univer-image-common-panel-inline",We="univer-image-common-panel-span2",Fe="univer-image-common-panel-span3",Ve="univer-image-common-panel-input",$e="univer-sheet-image-menu",Be="univer-sheet-image-menu-input",T={imageCommonPanel:Re,imageCommonPanelGrid:be,imageCommonPanelBorder:Ae,imageCommonPanelTitle:Ue,imageCommonPanelRow:Ne,imageCommonPanelRowVertical:Le,imageCommonPanelColumn:Ge,imageCommonPanelColumnCenter:je,imageCommonPanelInline:xe,imageCommonPanelSpan2:We,imageCommonPanelSpan3:Fe,imageCommonPanelInput:Ve,sheetImageMenu:$e,sheetImageMenuInput:Be},z={id:"doc.command.set-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:g,type:m.DocDrawingApplyType.UPDATE})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:u,objects:g,type:m.DocDrawingApplyType.UPDATE}},{id:y.id,params:[c]}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:g,type:m.DocDrawingApplyType.UPDATE}},{id:y.id,params:[c]}]}),!0):!1}},He=e=>{b.useDependency(a.ICommandService);const n=b.useDependency(a.LocaleService),t=b.useDependency(I.IDrawingManagerService),i=b.useDependency(P.IRenderManagerService),{drawings:r}=e,o=r[0];if(o==null)return;const{unitId:s}=o,c=i.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;const u=d.getTransformerByCreate(),[l,g]=v.useState(!0);v.useState("");function p(h,D){const S=[];return h.forEach(M=>{const{oKey:E}=M;if(D.getDrawingOKey(E)==null)return S.push(null),!0}),S}v.useEffect(()=>{const h=u.onClearControlObservable.add(S=>{S===!0&&g(!1)}),D=u.onChangeStartObservable.add(S=>{const{objects:M}=S;p(M,t)});return()=>{D==null||D.dispose(),h==null||h.dispose()}},[]);const f=h=>h?"block":"none";return v.createElement("div",{className:F(T.imageCommonPanelGrid,T.imageCommonPanelBorder),style:{display:f(l)}},v.createElement("div",{className:T.imageCommonPanelRow},v.createElement("div",{className:F(T.imageCommonPanelColumn,T.imageCommonPanelTitle)},v.createElement("div",null,n.t("drawing-anchor.title")))),v.createElement("div",{className:F(T.imageCommonPanelRow)},v.createElement("div",{className:F(T.imageCommonPanelColumn)})))},qe=()=>{const e=b.useDependency(I.IDrawingManagerService),n=e.getFocusDrawings();if(n==null||n.length===0)return;const[t,i]=v.useState(n);return v.useEffect(()=>{const r=e.focus$.subscribe(o=>{i(o)});return()=>{r.unsubscribe()}},[]),v.createElement("div",{className:T.imageCommonPanel},v.createElement(L.DrawingCommonPanel,{drawings:t}),v.createElement(He,{drawings:t}))},j={id:"doc.command.move-drawing",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(m.IDocDrawingService),{direction:r}=n,o=i.getFocusDrawings();if(o.length===0)return!1;const s=o[0].unitId,c=o.map(u=>{const{transform:l}=u;if(l==null)return null;const g={...l},{left:p=0,top:f=0}=l;return r===a.Direction.UP?g.top=f-1:r===a.Direction.DOWN?g.top=f+1:r===a.Direction.LEFT?g.left=p-1:r===a.Direction.RIGHT&&(g.left=p+1),{...u,transform:g,docTransform:G.transformToDocDrawingPosition(g)}}).filter(u=>u!=null);return t.syncExecuteCommand(z.id,{unitId:s,drawings:c})?(t.syncExecuteCommand(y.id,[s]),!0):!1}},ce={id:"doc.command.delete-drawing",type:a.CommandType.COMMAND,handler:e=>{const n=e.get(a.ICommandService),i=e.get(m.IDocDrawingService).getFocusDrawings();if(i.length===0)return!1;const r=i[0].unitId,o=i.map(s=>{const{unitId:c,subUnitId:d,drawingId:u,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:u,drawingType:l}});return n.executeCommand(k.id,{unitId:r,drawings:o})}},de={id:"doc.command.set-drawing-arrange",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService);if(!n)return!1;const r=e.get(m.IDocDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,u={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===I.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):d===I.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):d===I.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):d===I.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:g,redo:p,undo:f}=l;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:f,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE}}]}),!0):!1}};function Ke(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:s,drawingId:c}=i,d=P.getGroupState(0,0,r.map(g=>g.transform||{})),u=r.map(g=>{const p=g.transform||{left:0,top:0},{unitId:f,subUnitId:h,drawingId:D}=g;return{unitId:f,subUnitId:h,drawingId:D,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:u})}),n}function ke(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=i;if(d==null)return;const u=r.map(g=>{const{transform:p}=g,{unitId:f,subUnitId:h,drawingId:D}=g,S=P.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:f,subUnitId:h,drawingId:D,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:u})}),n}const ue={id:"doc.command.ungroup-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:f,children:h})=>{o.push(f.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.UNGROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Ke(g),type:m.DocDrawingApplyType.GROUP}},{id:y.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.UNGROUP}},{id:y.id,params:o}]}),!0):!1}},ge={id:"doc.command.group-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:f,children:h})=>{o.push(f.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.GROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:ke(g),type:m.DocDrawingApplyType.UNGROUP}},{id:y.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.GROUP}},{id:y.id,params:o}]}),!0):!1}},me={id:"doc.command.insert-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(h=>h.unitId),c=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:l,redo:g,objects:p}=c;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:g,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.INSERT})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.REMOVE}},{id:y.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:g,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.INSERT}},{id:y.id,params:s}]}),!0):!1}};function x(e){return!e.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const ze={id:j.id,description:"shortcut.doc.drawing-move-down",group:"4_doc-drawing-view",binding:w.KeyCode.ARROW_DOWN,priority:100,preconditions:x,staticParameters:{direction:a.Direction.DOWN}},Ze={id:j.id,description:"shortcut.doc.drawing-move-up",group:"4_doc-drawing-view",binding:w.KeyCode.ARROW_UP,priority:100,preconditions:x,staticParameters:{direction:a.Direction.UP}},Ye={id:j.id,description:"shortcut.doc.drawing-move-left",group:"4_doc-drawing-view",binding:w.KeyCode.ARROW_LEFT,priority:100,preconditions:x,staticParameters:{direction:a.Direction.LEFT}},Qe={id:j.id,description:"shortcut.doc.drawing-move-right",group:"4_doc-drawing-view",binding:w.KeyCode.ARROW_RIGHT,priority:100,preconditions:x,staticParameters:{direction:a.Direction.RIGHT}},Xe={id:ce.id,description:"shortcut.doc.drawing-delete",group:"4_doc-drawing-view",preconditions:x,binding:w.KeyCode.DELETE,mac:w.KeyCode.BACKSPACE};var Je=Object.defineProperty,en=Object.getOwnPropertyDescriptor,nn=(e,n,t,i)=>{for(var r=i>1?void 0:i?en(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Je(n,t,r),r},N=(e,n)=>(t,i)=>n(t,i,e);let H=class extends a.Disposable{constructor(e,n,t,i,r){super(),this._injector=e,this._componentManager=n,this._menuService=t,this._commandService=i,this._shortcutService=r,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(ae,re)),this.disposeWithMe(e.register(oe,Te)),this.disposeWithMe(e.register(J,qe))}_initMenus(){[Pe,Ee].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),{}))})}_initCommands(){[K,me,k,z,ee,y,ne,ge,ue,j,ce,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[ze,Ze,Ye,Qe,Xe].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};H=nn([a.OnLifecycle(a.LifecycleStages.Ready,H),N(0,O.Inject(O.Injector)),N(1,O.Inject(w.ComponentManager)),N(2,w.IMenuService),N(3,a.ICommandService),N(4,w.IShortcutService)],H);var tn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(e,n,t,i)=>{for(var r=i>1?void 0:i?rn(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&tn(n,t,r),r},C=(e,n)=>(t,i)=>n(t,i,e);let q=class extends a.Disposable{constructor(e,n,t,i,r,o,s,c,d,u,l){super(),this._commandService=e,this._univerInstanceService=n,this._textSelectionManagerService=t,this._imageIoService=i,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=c,this._localeService=d,this._docSkeletonManagerService=u,this._renderManagerService=l,this._init()}_init(){this._initCommandListeners(),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===K.id){const n=e.params;if(n.files==null)return;const t=n.files.length;if(t>I.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(I.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(t),n.files.forEach(async i=>{await this._insertFloatImage(i)})}}))}async _insertFloatImage(e){var E;let n;try{n=await this._imageIoService.saveImage(e)}catch(A){const R=A.message;R===I.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(I.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===I.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===I.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const t=this._getUnitInfo();if(t==null)return;const{unitId:i,subUnitId:r}=t,{imageId:o,imageSourceType:s,source:c,base64Cache:d}=n,{width:u,height:l,image:g}=await I.getImageSize(d||""),p=this._renderManagerService.getRenderById(i);if(p==null)return;const{width:f,height:h}=p.scene;this._imageIoService.addImageSourceCache(o,s,g);let D=1;if(u>I.DRAWING_IMAGE_WIDTH_LIMIT||l>I.DRAWING_IMAGE_HEIGHT_LIMIT){const A=I.DRAWING_IMAGE_WIDTH_LIMIT/u,R=I.DRAWING_IMAGE_HEIGHT_LIMIT/l;D=Math.max(A,R)}const S=this._getImagePosition(u*D,l*D,f,h);if(S==null)return;const M={unitId:i,subUnitId:r,drawingId:o,drawingType:I.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:G.docDrawingPositionToTransform(S),docTransform:S,title:"",description:"",layoutType:a.PositionedObjectLayoutType.WRAP_SQUARE};this._commandService.executeCommand(me.id,{unitId:i,drawings:[M]}),(E=this._docSkeletonManagerService.getCurrent())==null||E.skeleton.calculate()}_getUnitInfo(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(e==null)return;const n=e.getUnitId();return{unitId:n,subUnitId:n}}_getImagePosition(e,n,t,i){const r=this._textSelectionManagerService.getActiveTextRange(),o=(r==null?void 0:r.getAbsolutePosition())||{left:0,top:0};return{size:{width:e,height:n},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:o.left},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:o.top},angle:0}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r}=e;this._commandService.executeCommand(de.id,{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r})})}_updateDrawingListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const n=[];e.length!==0&&(e.forEach(t=>{const{unitId:i,subUnitId:r,drawingId:o,drawingType:s,transform:c}=t;if(c==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:r,drawingId:o});if(d==null)return;const u=G.transformToDocDrawingPosition({...d.transform,...c});if(u==null)return;const l={...t,transform:{...c,...G.docDrawingPositionToTransform(u)},docTransform:{...u}};n.push(l)}),n.length>0&&(this._commandService.syncExecuteCommand(z.id,{unitId:e[0].unitId,drawings:n}),this._refreshDocSkeleton()))})}_getDocsOffsetInfo(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{unitId:n,skeleton:t}=e,i=this._renderManagerService.getRenderById(n),r=t==null?void 0:t.getSkeletonData();if(i==null||!r)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{mainComponent:o}=i,s=o,{left:c,top:d,pageLayoutType:u,pageMarginLeft:l,pageMarginTop:g}=s,{pages:p}=r,f=new P.Liquid,h=new Map;for(let D=0,S=p.length;D<S;D++){const M=p[D],{skeDrawings:E,marginLeft:A,marginTop:R}=M;f.translatePagePadding(M),E.forEach(le=>{const{aLeft:un,aTop:gn,height:mn,width:ln,drawingId:pe,drawingOrigin:pn}=le;h.set(pe,{marginLeft:f.x,marginTop:f.y})}),f.restorePagePadding(M),f.translatePage(M,u,l,g)}return{pageMarginCache:h,docsLeft:c,docsTop:d}}_refreshDocSkeleton(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:t}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:r}=i;t==null||t.calculate(),r==null||r.makeDirty()}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ge.id,e)}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ue.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};q=on([a.OnLifecycle(a.LifecycleStages.Rendered,q),C(0,a.ICommandService),C(1,a.IUniverInstanceService),C(2,O.Inject(Y.TextSelectionManagerService)),C(3,I.IImageIoService),C(4,m.IDocDrawingService),C(5,I.IDrawingManagerService),C(6,a.IContextService),C(7,w.IMessageService),C(8,O.Inject(a.LocaleService)),C(9,O.Inject(Y.DocSkeletonManagerService)),C(10,P.IRenderManagerService)],q);var an=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,cn=(e,n,t,i)=>{for(var r=i>1?void 0:i?sn(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&an(n,t,r),r},X=(e,n)=>(t,i)=>n(t,i,e);const dn="Docs_Drawing_UI_PLUGIN";var $;exports.UniverDocsDrawingUIPlugin=($=class extends a.Plugin{constructor(n,t,i){super(),this._injector=t,this._localeService=i}onStarting(n){this._initDependencies(n)}_initDependencies(n){[[H],[q],[B]].forEach(i=>n.add(i))}},W($,"type",a.UniverInstanceType.UNIVER_DOC),W($,"pluginName",dn),$);exports.UniverDocsDrawingUIPlugin=cn([X(1,O.Inject(O.Injector)),X(2,O.Inject(a.LocaleService))],exports.UniverDocsDrawingUIPlugin);
|
|
1
|
+
"use strict";var fe=Object.defineProperty;var Ie=(e,n,t)=>n in e?fe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var W=(e,n,t)=>Ie(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),O=require("@wendellhu/redi"),P=require("@univerjs/engine-render"),L=require("@univerjs/drawing-ui"),Z=require("rxjs"),G=require("@univerjs/docs-ui"),I=require("@univerjs/drawing"),m=require("@univerjs/docs-drawing"),S=require("@univerjs/ui"),b=require("@wendellhu/redi/react-bindings"),v=require("react"),F=require("clsx"),V=require("@univerjs/design"),Y=require("@univerjs/docs"),y={id:"sheet.operation.clear-drawing-transformer",type:a.CommandType.MUTATION,handler:(e,n)=>{const t=e.get(P.IRenderManagerService);return n.forEach(i=>{var r,o;(o=(r=t.getRenderById(i))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},k={id:"doc.command.remove-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(h=>{const{unitId:D}=h;s.push(D)});const c=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:l,redo:g,objects:p}=c;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:g,objects:p,type:m.DocDrawingApplyType.REMOVE})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:p,type:m.DocDrawingApplyType.INSERT}},{id:y.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:g,objects:p,type:m.DocDrawingApplyType.REMOVE}},{id:y.id,params:s}]}),!0):!1}},J="COMPONENT_DOC_DRAWING_PANEL",ee={id:"sidebar.operation.doc-image",type:a.CommandType.COMMAND,handler:async(e,n)=>{const t=e.get(S.ISidebarService),i=e.get(a.LocaleService),r=e.get(I.IDrawingManagerService);switch(n.value){case"open":t.open({header:{title:i.t("docImage.panel.title")},children:{label:J},onClose:()=>{r.focusDrawing(null)},width:360});break;case"close":default:t.close();break}return!0}},ne={id:"sheet.operation.edit-sheet-image",type:a.CommandType.OPERATION,handler:(e,n)=>{const t=e.get(I.IDrawingManagerService),i=e.get(a.ICommandService);return n==null?!1:(t.focusDrawing([n]),i.executeCommand(ee.id,{value:"open"}),!0)}};var he=Object.defineProperty,De=Object.getOwnPropertyDescriptor,ve=(e,n,t,i)=>{for(var r=i>1?void 0:i?De(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&he(n,t,r),r},U=(e,n)=>(t,i)=>n(t,i,e);let B=class extends a.RxDisposable{constructor(n,t,i,r,o){super();W(this,"_initImagePopupMenu",new Set);this._drawingManagerService=n,this._canvasPopManagerService=t,this._renderManagerService=i,this._univerInstanceService=r,this._contextService=o,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(Z.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(Z.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(n=>this._create(n))}_dispose(n){const t=n.getUnitId();this._renderManagerService.removeRender(t)}_create(n){if(!n)return;const t=n.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(n){const t=n.getAllObjects();for(const i of t)if(i instanceof L.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const t=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!t)return;const i=t.getTransformerByCreate();if(!i)return;const r=[];this.disposeWithMe(a.toDisposable(i.onCreateControlObservable.add(()=>{if(this._hasCropObject(t))return;const s=i.getSelectedObjectMap();if(s.size>1){r.forEach(f=>f.dispose());return}const c=s.values().next().value;if(!c)return;const d=c.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:l,subUnitId:g,drawingId:p}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:L.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,g,p)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:g,drawingId:p}])}))),this.disposeWithMe(a.toDisposable(i.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(a.toDisposable(i.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,t,i){return[{label:"image-popup.edit",index:0,commandId:ne.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.delete",index:1,commandId:k.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:t,drawingId:i}]},disable:!1},{label:"image-popup.crop",index:2,commandId:L.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.reset",index:3,commandId:L.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:t,drawingId:i}],disable:!1}]}};B=ve([a.OnLifecycle(a.LifecycleStages.Rendered,B),U(0,I.IDrawingManagerService),U(1,O.Inject(G.DocCanvasPopManagerService)),U(2,P.IRenderManagerService),U(3,a.IUniverInstanceService),U(4,a.IContextService)],B);var _=function(){return _=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_.apply(this,arguments)},Se=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)n.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(t[i[r]]=e[i[r]]);return t},te=v.forwardRef(function(e,n){var t=e.icon,i=e.id,r=e.className,o=e.extend,s=Se(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),d=v.useRef("_".concat(ye()));return ie(t,"".concat(i),{defIds:t.defIds,idSuffix:d.current},_({ref:n,className:c},s),o)});function ie(e,n,t,i,r){return v.createElement(e.tag,_(_({key:n},we(e,t,r)),i),(_e(e,t).children||[]).map(function(o,s){return ie(o,"".concat(n,"-").concat(e.tag,"-").concat(s),t,void 0,r)}))}function we(e,n,t){var i=_({},e.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(i[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),i}function _e(e,n){var t,i=n.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?_(_({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?_(_({},r),{attrs:_(_({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function ye(){return Math.random().toString(36).substring(2,8)}te.displayName="UniverIcon";var Ce={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"}}]},re=v.forwardRef(function(e,n){return v.createElement(te,Object.assign({},e,{id:"add-image-single",ref:n,icon:Ce}))});re.displayName="AddImageSingle";const K={id:"doc.operation.insert-float-image",type:a.CommandType.OPERATION,handler:(e,n)=>!0},Me="univer-upload-file-menu",Oe="univer-upload-file-menu-input",Q={uploadFileMenu:Me,uploadFileMenuInput:Oe},Te=()=>{const e=b.useDependency(a.ICommandService),n=v.useRef(null),t=()=>{var o;(o=n.current)==null||o.click()},i=I.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(o=>`.${o.replace("image/","")}`).join(","),r=o=>{const s=o.target.files;if(s==null)return;const c=Array.from(s);e.executeCommand(K.id,{files:c}),n.current&&(n.current.value="")};return v.createElement("div",{onClick:t,className:Q.uploadFileMenu},v.createElement("input",{type:"file",className:Q.uploadFileMenuInput,ref:n,onChange:r,accept:i,multiple:!0}))},oe="COMPONENT_DOC_UPLOAD_FILE_MENU",ae="addition-and-subtraction-single",se="doc.menu.image";function Pe(e){return{id:se,type:S.MenuItemType.SUBITEMS,positions:[S.MenuPosition.TOOLBAR_START],group:S.MenuGroup.TOOLBAR_LAYOUT,icon:ae,tooltip:"docImage.title",hidden$:S.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}function Ee(e){return{id:K.id,title:"docImage.upload.float",type:S.MenuItemType.SELECTOR,label:{name:oe},positions:[se],hidden$:S.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}const Re="univer-image-common-panel",be="univer-image-common-panel-grid",Ae="univer-image-common-panel-border",Ue="univer-image-common-panel-title",Ne="univer-image-common-panel-row",Le="univer-image-common-panel-row-vertical",Ge="univer-image-common-panel-column",je="univer-image-common-panel-column-center",xe="univer-image-common-panel-inline",We="univer-image-common-panel-span2",Fe="univer-image-common-panel-span3",Ve="univer-image-common-panel-input",$e="univer-sheet-image-menu",Be="univer-sheet-image-menu-input",T={imageCommonPanel:Re,imageCommonPanelGrid:be,imageCommonPanelBorder:Ae,imageCommonPanelTitle:Ue,imageCommonPanelRow:Ne,imageCommonPanelRowVertical:Le,imageCommonPanelColumn:Ge,imageCommonPanelColumnCenter:je,imageCommonPanelInline:xe,imageCommonPanelSpan2:We,imageCommonPanelSpan3:Fe,imageCommonPanelInput:Ve,sheetImageMenu:$e,sheetImageMenuInput:Be},z={id:"doc.command.set-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:g,type:m.DocDrawingApplyType.UPDATE})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:u,objects:g,type:m.DocDrawingApplyType.UPDATE}},{id:y.id,params:[c]}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:g,type:m.DocDrawingApplyType.UPDATE}},{id:y.id,params:[c]}]}),!0):!1}},He=e=>{b.useDependency(a.ICommandService);const n=b.useDependency(a.LocaleService),t=b.useDependency(I.IDrawingManagerService),i=b.useDependency(P.IRenderManagerService),{drawings:r}=e,o=r[0];if(o==null)return;const{unitId:s}=o,c=i.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;const u=d.getTransformerByCreate(),[l,g]=v.useState(!0);v.useState("");function p(h,D){const w=[];return h.forEach(M=>{const{oKey:E}=M;if(D.getDrawingOKey(E)==null)return w.push(null),!0}),w}v.useEffect(()=>{const h=u.onClearControlObservable.add(w=>{w===!0&&g(!1)}),D=u.onChangeStartObservable.add(w=>{const{objects:M}=w;p(M,t)});return()=>{D==null||D.dispose(),h==null||h.dispose()}},[]);const f=h=>h?"block":"none";return v.createElement("div",{className:F(T.imageCommonPanelGrid,T.imageCommonPanelBorder),style:{display:f(l)}},v.createElement("div",{className:T.imageCommonPanelRow},v.createElement("div",{className:F(T.imageCommonPanelColumn,T.imageCommonPanelTitle)},v.createElement("div",null,n.t("drawing-anchor.title")))),v.createElement("div",{className:F(T.imageCommonPanelRow)},v.createElement("div",{className:F(T.imageCommonPanelColumn)})))},qe=()=>{const e=b.useDependency(I.IDrawingManagerService),n=e.getFocusDrawings(),[t,i]=v.useState(n);return v.useEffect(()=>{const r=e.focus$.subscribe(o=>{i(o)});return()=>{r.unsubscribe()}},[]),!!(t!=null&&t.length)&&v.createElement("div",{className:T.imageCommonPanel},v.createElement(L.DrawingCommonPanel,{drawings:t}),v.createElement(He,{drawings:t}))},j={id:"doc.command.move-drawing",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(m.IDocDrawingService),{direction:r}=n,o=i.getFocusDrawings();if(o.length===0)return!1;const s=o[0].unitId,c=o.map(u=>{const{transform:l}=u;if(l==null)return null;const g={...l},{left:p=0,top:f=0}=l;return r===a.Direction.UP?g.top=f-1:r===a.Direction.DOWN?g.top=f+1:r===a.Direction.LEFT?g.left=p-1:r===a.Direction.RIGHT&&(g.left=p+1),{...u,transform:g,docTransform:G.transformToDocDrawingPosition(g)}}).filter(u=>u!=null);return t.syncExecuteCommand(z.id,{unitId:s,drawings:c})?(t.syncExecuteCommand(y.id,[s]),!0):!1}},ce={id:"doc.command.delete-drawing",type:a.CommandType.COMMAND,handler:e=>{const n=e.get(a.ICommandService),i=e.get(m.IDocDrawingService).getFocusDrawings();if(i.length===0)return!1;const r=i[0].unitId,o=i.map(s=>{const{unitId:c,subUnitId:d,drawingId:u,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:u,drawingType:l}});return n.executeCommand(k.id,{unitId:r,drawings:o})}},de={id:"doc.command.set-drawing-arrange",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService);if(!n)return!1;const r=e.get(m.IDocDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,u={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===I.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):d===I.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):d===I.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):d===I.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:g,redo:p,undo:f}=l;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:f,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE}}]}),!0):!1}};function Ke(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:s,drawingId:c}=i,d=P.getGroupState(0,0,r.map(g=>g.transform||{})),u=r.map(g=>{const p=g.transform||{left:0,top:0},{unitId:f,subUnitId:h,drawingId:D}=g;return{unitId:f,subUnitId:h,drawingId:D,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:u})}),n}function ke(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=i;if(d==null)return;const u=r.map(g=>{const{transform:p}=g,{unitId:f,subUnitId:h,drawingId:D}=g,w=P.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:f,subUnitId:h,drawingId:D,transform:w,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:u})}),n}const ue={id:"doc.command.ungroup-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:f,children:h})=>{o.push(f.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.UNGROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Ke(g),type:m.DocDrawingApplyType.GROUP}},{id:y.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.UNGROUP}},{id:y.id,params:o}]}),!0):!1}},ge={id:"doc.command.group-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:f,children:h})=>{o.push(f.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.GROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:ke(g),type:m.DocDrawingApplyType.UNGROUP}},{id:y.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.GROUP}},{id:y.id,params:o}]}),!0):!1}},me={id:"doc.command.insert-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(h=>h.unitId),c=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:l,redo:g,objects:p}=c;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:g,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.INSERT})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.REMOVE}},{id:y.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:g,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.INSERT}},{id:y.id,params:s}]}),!0):!1}};function x(e){return!e.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const ze={id:j.id,description:"shortcut.doc.drawing-move-down",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_DOWN,priority:100,preconditions:x,staticParameters:{direction:a.Direction.DOWN}},Ze={id:j.id,description:"shortcut.doc.drawing-move-up",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_UP,priority:100,preconditions:x,staticParameters:{direction:a.Direction.UP}},Ye={id:j.id,description:"shortcut.doc.drawing-move-left",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_LEFT,priority:100,preconditions:x,staticParameters:{direction:a.Direction.LEFT}},Qe={id:j.id,description:"shortcut.doc.drawing-move-right",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_RIGHT,priority:100,preconditions:x,staticParameters:{direction:a.Direction.RIGHT}},Xe={id:ce.id,description:"shortcut.doc.drawing-delete",group:"4_doc-drawing-view",preconditions:x,binding:S.KeyCode.DELETE,mac:S.KeyCode.BACKSPACE};var Je=Object.defineProperty,en=Object.getOwnPropertyDescriptor,nn=(e,n,t,i)=>{for(var r=i>1?void 0:i?en(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Je(n,t,r),r},N=(e,n)=>(t,i)=>n(t,i,e);let H=class extends a.Disposable{constructor(e,n,t,i,r){super(),this._injector=e,this._componentManager=n,this._menuService=t,this._commandService=i,this._shortcutService=r,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(ae,re)),this.disposeWithMe(e.register(oe,Te)),this.disposeWithMe(e.register(J,qe))}_initMenus(){[Pe,Ee].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),{}))})}_initCommands(){[K,me,k,z,ee,y,ne,ge,ue,j,ce,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[ze,Ze,Ye,Qe,Xe].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};H=nn([a.OnLifecycle(a.LifecycleStages.Ready,H),N(0,O.Inject(O.Injector)),N(1,O.Inject(S.ComponentManager)),N(2,S.IMenuService),N(3,a.ICommandService),N(4,S.IShortcutService)],H);var tn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(e,n,t,i)=>{for(var r=i>1?void 0:i?rn(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&tn(n,t,r),r},C=(e,n)=>(t,i)=>n(t,i,e);let q=class extends a.Disposable{constructor(e,n,t,i,r,o,s,c,d,u,l){super(),this._commandService=e,this._univerInstanceService=n,this._textSelectionManagerService=t,this._imageIoService=i,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=c,this._localeService=d,this._docSkeletonManagerService=u,this._renderManagerService=l,this._init()}_init(){this._initCommandListeners(),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===K.id){const n=e.params;if(n.files==null)return;const t=n.files.length;if(t>I.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(I.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(t),n.files.forEach(async i=>{await this._insertFloatImage(i)})}}))}async _insertFloatImage(e){var E;let n;try{n=await this._imageIoService.saveImage(e)}catch(A){const R=A.message;R===I.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(I.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===I.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===I.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const t=this._getUnitInfo();if(t==null)return;const{unitId:i,subUnitId:r}=t,{imageId:o,imageSourceType:s,source:c,base64Cache:d}=n,{width:u,height:l,image:g}=await I.getImageSize(d||""),p=this._renderManagerService.getRenderById(i);if(p==null)return;const{width:f,height:h}=p.scene;this._imageIoService.addImageSourceCache(o,s,g);let D=1;if(u>I.DRAWING_IMAGE_WIDTH_LIMIT||l>I.DRAWING_IMAGE_HEIGHT_LIMIT){const A=I.DRAWING_IMAGE_WIDTH_LIMIT/u,R=I.DRAWING_IMAGE_HEIGHT_LIMIT/l;D=Math.max(A,R)}const w=this._getImagePosition(u*D,l*D,f,h);if(w==null)return;const M={unitId:i,subUnitId:r,drawingId:o,drawingType:I.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:G.docDrawingPositionToTransform(w),docTransform:w,title:"",description:"",layoutType:a.PositionedObjectLayoutType.WRAP_SQUARE};this._commandService.executeCommand(me.id,{unitId:i,drawings:[M]}),(E=this._docSkeletonManagerService.getCurrent())==null||E.skeleton.calculate()}_getUnitInfo(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(e==null)return;const n=e.getUnitId();return{unitId:n,subUnitId:n}}_getImagePosition(e,n,t,i){const r=this._textSelectionManagerService.getActiveTextRange(),o=(r==null?void 0:r.getAbsolutePosition())||{left:0,top:0};return{size:{width:e,height:n},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:o.left},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:o.top},angle:0}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r}=e;this._commandService.executeCommand(de.id,{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r})})}_updateDrawingListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const n=[];e.length!==0&&(e.forEach(t=>{const{unitId:i,subUnitId:r,drawingId:o,drawingType:s,transform:c}=t;if(c==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:r,drawingId:o});if(d==null)return;const u=G.transformToDocDrawingPosition({...d.transform,...c});if(u==null)return;const l={...t,transform:{...c,...G.docDrawingPositionToTransform(u)},docTransform:{...u}};n.push(l)}),n.length>0&&(this._commandService.syncExecuteCommand(z.id,{unitId:e[0].unitId,drawings:n}),this._refreshDocSkeleton()))})}_getDocsOffsetInfo(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{unitId:n,skeleton:t}=e,i=this._renderManagerService.getRenderById(n),r=t==null?void 0:t.getSkeletonData();if(i==null||!r)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{mainComponent:o}=i,s=o,{left:c,top:d,pageLayoutType:u,pageMarginLeft:l,pageMarginTop:g}=s,{pages:p}=r,f=new P.Liquid,h=new Map;for(let D=0,w=p.length;D<w;D++){const M=p[D],{skeDrawings:E,marginLeft:A,marginTop:R}=M;f.translatePagePadding(M),E.forEach(le=>{const{aLeft:un,aTop:gn,height:mn,width:ln,drawingId:pe,drawingOrigin:pn}=le;h.set(pe,{marginLeft:f.x,marginTop:f.y})}),f.restorePagePadding(M),f.translatePage(M,u,l,g)}return{pageMarginCache:h,docsLeft:c,docsTop:d}}_refreshDocSkeleton(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:t}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:r}=i;t==null||t.calculate(),r==null||r.makeDirty()}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ge.id,e)}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ue.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};q=on([a.OnLifecycle(a.LifecycleStages.Rendered,q),C(0,a.ICommandService),C(1,a.IUniverInstanceService),C(2,O.Inject(Y.TextSelectionManagerService)),C(3,I.IImageIoService),C(4,m.IDocDrawingService),C(5,I.IDrawingManagerService),C(6,a.IContextService),C(7,S.IMessageService),C(8,O.Inject(a.LocaleService)),C(9,O.Inject(Y.DocSkeletonManagerService)),C(10,P.IRenderManagerService)],q);var an=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,cn=(e,n,t,i)=>{for(var r=i>1?void 0:i?sn(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&an(n,t,r),r},X=(e,n)=>(t,i)=>n(t,i,e);const dn="Docs_Drawing_UI_PLUGIN";var $;exports.UniverDocsDrawingUIPlugin=($=class extends a.Plugin{constructor(n,t,i){super(),this._injector=t,this._localeService=i}onStarting(n){this._initDependencies(n)}_initDependencies(n){[[H],[q],[B]].forEach(i=>n.add(i))}},W($,"type",a.UniverInstanceType.UNIVER_DOC),W($,"pluginName",dn),$);exports.UniverDocsDrawingUIPlugin=cn([X(1,O.Inject(O.Injector)),X(2,O.Inject(a.LocaleService))],exports.UniverDocsDrawingUIPlugin);
|
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var Be = Object.defineProperty;
|
|
2
2
|
var He = (e, n, t) => n in e ? Be(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
|
|
3
|
-
var $ = (e, n, t) =>
|
|
3
|
+
var $ = (e, n, t) => He(e, typeof n != "symbol" ? n + "" : n, t);
|
|
4
4
|
import { CommandType as C, ICommandService as _, IUndoRedoService as x, LocaleService as Q, RxDisposable as ke, UniverInstanceType as R, toDisposable as ee, FOCUSING_COMMON_DRAWINGS as Y, OnLifecycle as re, LifecycleStages as ie, IUniverInstanceService as he, IContextService as Ie, Direction as E, FOCUSING_UNIVER_EDITOR as Ke, Disposable as ve, PositionedObjectLayoutType as ze, ObjectRelativeFromH as Ze, ObjectRelativeFromV as qe, Plugin as Ye } from "@univerjs/core";
|
|
5
5
|
import { Inject as b, Injector as _e } from "@wendellhu/redi";
|
|
6
6
|
import { IRenderManagerService as X, getGroupState as Qe, transformObjectOutOfGroup as Xe, Liquid as Je } from "@univerjs/engine-render";
|
|
@@ -30,8 +30,7 @@ const S = {
|
|
|
30
30
|
type: C.COMMAND,
|
|
31
31
|
handler: (e, n) => {
|
|
32
32
|
const t = e.get(_), r = e.get(x), i = e.get(P);
|
|
33
|
-
if (!n)
|
|
34
|
-
return !1;
|
|
33
|
+
if (!n) return !1;
|
|
35
34
|
const { drawings: o } = n, a = [];
|
|
36
35
|
o.forEach((p) => {
|
|
37
36
|
const { unitId: f } = p;
|
|
@@ -211,15 +210,13 @@ var w = function() {
|
|
|
211
210
|
return w = Object.assign || function(e) {
|
|
212
211
|
for (var n, t = 1, r = arguments.length; t < r; t++) {
|
|
213
212
|
n = arguments[t];
|
|
214
|
-
for (var i in n)
|
|
215
|
-
Object.prototype.hasOwnProperty.call(n, i) && (e[i] = n[i]);
|
|
213
|
+
for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (e[i] = n[i]);
|
|
216
214
|
}
|
|
217
215
|
return e;
|
|
218
216
|
}, w.apply(this, arguments);
|
|
219
217
|
}, Dn = function(e, n) {
|
|
220
218
|
var t = {};
|
|
221
|
-
for (var r in e)
|
|
222
|
-
Object.prototype.hasOwnProperty.call(e, r) && n.indexOf(r) < 0 && (t[r] = e[r]);
|
|
219
|
+
for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && n.indexOf(r) < 0 && (t[r] = e[r]);
|
|
223
220
|
if (e != null && typeof Object.getOwnPropertySymbols == "function")
|
|
224
221
|
for (var i = 0, r = Object.getOwnPropertySymbols(e); i < r.length; i++)
|
|
225
222
|
n.indexOf(r[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[i]) && (t[r[i]] = e[r[i]]);
|
|
@@ -333,8 +330,7 @@ const Nn = "univer-image-common-panel", An = "univer-image-common-panel-grid", x
|
|
|
333
330
|
type: C.COMMAND,
|
|
334
331
|
handler: (e, n) => {
|
|
335
332
|
const t = e.get(_), r = e.get(x), i = e.get(P);
|
|
336
|
-
if (!n)
|
|
337
|
-
return !1;
|
|
333
|
+
if (!n) return !1;
|
|
338
334
|
const { drawings: o } = n, a = i.getBatchUpdateOp(o), { unitId: s, subUnitId: c, undo: d, redo: m, objects: u } = a;
|
|
339
335
|
return t.syncExecuteCommand(h.id, { unitId: s, subUnitId: c, op: m, objects: u, type: I.UPDATE }) ? (r.pushUndoRedo({
|
|
340
336
|
unitID: s,
|
|
@@ -380,10 +376,7 @@ const Nn = "univer-image-common-panel", An = "univer-image-common-panel-grid", x
|
|
|
380
376
|
const g = (p) => p ? "block" : "none";
|
|
381
377
|
return /* @__PURE__ */ M.createElement("div", { className: H(y.imageCommonPanelGrid, y.imageCommonPanelBorder), style: { display: g(m) } }, /* @__PURE__ */ M.createElement("div", { className: y.imageCommonPanelRow }, /* @__PURE__ */ M.createElement("div", { className: H(y.imageCommonPanelColumn, y.imageCommonPanelTitle) }, /* @__PURE__ */ M.createElement("div", null, n.t("drawing-anchor.title")))), /* @__PURE__ */ M.createElement("div", { className: H(y.imageCommonPanelRow) }, /* @__PURE__ */ M.createElement("div", { className: H(y.imageCommonPanelColumn) })));
|
|
382
378
|
}, Zn = () => {
|
|
383
|
-
const e = N(L), n = e.getFocusDrawings();
|
|
384
|
-
if (n == null || n.length === 0)
|
|
385
|
-
return;
|
|
386
|
-
const [t, r] = te(n);
|
|
379
|
+
const e = N(L), n = e.getFocusDrawings(), [t, r] = te(n);
|
|
387
380
|
return Pe(() => {
|
|
388
381
|
const i = e.focus$.subscribe((o) => {
|
|
389
382
|
r(o);
|
|
@@ -391,7 +384,7 @@ const Nn = "univer-image-common-panel", An = "univer-image-common-panel-grid", x
|
|
|
391
384
|
return () => {
|
|
392
385
|
i.unsubscribe();
|
|
393
386
|
};
|
|
394
|
-
}, []), /* @__PURE__ */ M.createElement("div", { className: y.imageCommonPanel }, /* @__PURE__ */ M.createElement(on, { drawings: t }), /* @__PURE__ */ M.createElement(zn, { drawings: t }));
|
|
387
|
+
}, []), !!(t != null && t.length) && /* @__PURE__ */ M.createElement("div", { className: y.imageCommonPanel }, /* @__PURE__ */ M.createElement(on, { drawings: t }), /* @__PURE__ */ M.createElement(zn, { drawings: t }));
|
|
395
388
|
}, F = {
|
|
396
389
|
id: "doc.command.move-drawing",
|
|
397
390
|
type: C.COMMAND,
|
|
@@ -441,8 +434,7 @@ const Nn = "univer-image-common-panel", An = "univer-image-common-panel-grid", x
|
|
|
441
434
|
type: C.COMMAND,
|
|
442
435
|
handler: (e, n) => {
|
|
443
436
|
const t = e.get(_), r = e.get(x);
|
|
444
|
-
if (!n)
|
|
445
|
-
return !1;
|
|
437
|
+
if (!n) return !1;
|
|
446
438
|
const i = e.get(P), { unitId: o, subUnitId: a, drawingIds: s, arrangeType: c } = n, d = { unitId: o, subUnitId: a, drawingIds: s };
|
|
447
439
|
let m;
|
|
448
440
|
if (c === B.forward ? m = i.getForwardDrawingsOp(d) : c === B.backward ? m = i.getBackwardDrawingOp(d) : c === B.front ? m = i.getFrontDrawingsOp(d) : c === B.back && (m = i.getBackDrawingsOp(d)), m == null)
|
|
@@ -524,8 +516,7 @@ const je = {
|
|
|
524
516
|
type: C.COMMAND,
|
|
525
517
|
handler: (e, n) => {
|
|
526
518
|
const t = e.get(_), r = e.get(x), i = e.get(P);
|
|
527
|
-
if (!n)
|
|
528
|
-
return !1;
|
|
519
|
+
if (!n) return !1;
|
|
529
520
|
const o = [];
|
|
530
521
|
n.forEach(({ parent: g, children: p }) => {
|
|
531
522
|
o.push(g.unitId), p.forEach((f) => {
|
|
@@ -550,8 +541,7 @@ const je = {
|
|
|
550
541
|
type: C.COMMAND,
|
|
551
542
|
handler: (e, n) => {
|
|
552
543
|
const t = e.get(_), r = e.get(x), i = e.get(P);
|
|
553
|
-
if (!n)
|
|
554
|
-
return !1;
|
|
544
|
+
if (!n) return !1;
|
|
555
545
|
const o = [];
|
|
556
546
|
n.forEach(({ parent: g, children: p }) => {
|
|
557
547
|
o.push(g.unitId), p.forEach((f) => {
|
|
@@ -576,8 +566,7 @@ const je = {
|
|
|
576
566
|
type: C.COMMAND,
|
|
577
567
|
handler: (e, n) => {
|
|
578
568
|
const t = e.get(_), r = e.get(x), i = e.get(P);
|
|
579
|
-
if (!n)
|
|
580
|
-
return !1;
|
|
569
|
+
if (!n) return !1;
|
|
581
570
|
const o = n.drawings, a = o.map((p) => p.unitId), s = i.getBatchAddOp(o), { unitId: c, subUnitId: d, undo: m, redo: u, objects: l } = s;
|
|
582
571
|
return t.syncExecuteCommand(h.id, { op: u, unitId: c, subUnitId: d, objects: l, type: I.INSERT }) ? (r.pushUndoRedo({
|
|
583
572
|
unitID: c,
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/engine-render"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/docs-drawing"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("react"),require("clsx"),require("@univerjs/design"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/engine-render","@univerjs/drawing-ui","rxjs","@univerjs/docs-ui","@univerjs/drawing","@univerjs/docs-drawing","@univerjs/ui","@wendellhu/redi/react-bindings","react","clsx","@univerjs/design","@univerjs/docs"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f.UniverDocsDrawingUi={},f.UniverCore,f["@wendellhu/redi"],f.UniverEngineRender,f.UniverDrawingUi,f.rxjs,f.UniverDocsUi,f.UniverDrawing,f.UniverDocsDrawing,f.UniverUi,f["@wendellhu/redi/react-bindings"],f.React,f.clsx,f.UniverDesign,f.UniverDocs))})(this,function(f,a,C,E,R,Y,N,I,m,_,U,S,F,V,Q){"use strict";var Ke=Object.defineProperty;var ke=(f,a,C)=>a in f?Ke(f,a,{enumerable:!0,configurable:!0,writable:!0,value:C}):f[a]=C;var k=(f,a,C)=>(ke(f,typeof a!="symbol"?a+"":a,C),C);var K;const M={id:"sheet.operation.clear-drawing-transformer",type:a.CommandType.MUTATION,handler:(e,n)=>{const i=e.get(E.IRenderManagerService);return n.forEach(t=>{var r,o;(o=(r=i.getRenderById(t))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},z={id:"doc.command.remove-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(h=>{const{unitId:D}=h;s.push(D)});const c=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:p,redo:l,objects:g}=c;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:l,objects:g,type:m.DocDrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:p,objects:g,type:m.DocDrawingApplyType.INSERT}},{id:M.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:g,type:m.DocDrawingApplyType.REMOVE}},{id:M.id,params:s}]}),!0):!1}},X="COMPONENT_DOC_DRAWING_PANEL",J={id:"sidebar.operation.doc-image",type:a.CommandType.COMMAND,handler:async(e,n)=>{const i=e.get(_.ISidebarService),t=e.get(a.LocaleService),r=e.get(I.IDrawingManagerService);switch(n.value){case"open":i.open({header:{title:t.t("docImage.panel.title")},children:{label:X},onClose:()=>{r.focusDrawing(null)},width:360});break;case"close":default:i.close();break}return!0}},ee={id:"sheet.operation.edit-sheet-image",type:a.CommandType.OPERATION,handler:(e,n)=>{const i=e.get(I.IDrawingManagerService),t=e.get(a.ICommandService);return n==null?!1:(i.focusDrawing([n]),t.executeCommand(J.id,{value:"open"}),!0)}};var ge=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,Ie=(e,n,i,t)=>{for(var r=t>1?void 0:t?fe(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&ge(n,i,r),r},j=(e,n)=>(i,t)=>n(i,t,e);let $=class extends a.RxDisposable{constructor(n,i,t,r,o){super();k(this,"_initImagePopupMenu",new Set);this._drawingManagerService=n,this._canvasPopManagerService=i,this._renderManagerService=t,this._univerInstanceService=r,this._contextService=o,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(Y.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(Y.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(n=>this._create(n))}_dispose(n){const i=n.getUnitId();this._renderManagerService.removeRender(i)}_create(n){if(!n)return;const i=n.getUnitId();this._renderManagerService.has(i)&&!this._initImagePopupMenu.has(i)&&(this._popupMenuListener(i),this._initImagePopupMenu.add(i))}_hasCropObject(n){const i=n.getAllObjects();for(const t of i)if(t instanceof R.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const i=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!i)return;const t=i.getTransformerByCreate();if(!t)return;const r=[];this.disposeWithMe(a.toDisposable(t.onCreateControlObservable.add(()=>{if(this._hasCropObject(i))return;const s=t.getSelectedObjectMap();if(s.size>1){r.forEach(v=>v.dispose());return}const c=s.values().next().value;if(!c)return;const d=c.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:p,subUnitId:l,drawingId:g}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:R.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(p,l,g)}}))),this._drawingManagerService.focusDrawing([{unitId:p,subUnitId:l,drawingId:g}])}))),this.disposeWithMe(a.toDisposable(t.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(a.toDisposable(t.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,i,t){return[{label:"image-popup.edit",index:0,commandId:ee.id,commandParams:{unitId:n,subUnitId:i,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:z.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:i,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:R.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:i,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:R.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:i,drawingId:t}],disable:!1}]}};$=Ie([a.OnLifecycle(a.LifecycleStages.Rendered,$),j(0,I.IDrawingManagerService),j(1,C.Inject(N.DocCanvasPopManagerService)),j(2,E.IRenderManagerService),j(3,a.IUniverInstanceService),j(4,a.IContextService)],$);var w=function(){return w=Object.assign||function(e){for(var n,i=1,t=arguments.length;i<t;i++){n=arguments[i];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},w.apply(this,arguments)},ve=function(e,n){var i={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(i[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(e);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(e,t[r])&&(i[t[r]]=e[t[r]]);return i},ne=S.forwardRef(function(e,n){var i=e.icon,t=e.id,r=e.className,o=e.extend,s=ve(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),d=S.useRef("_".concat(Se()));return te(i,"".concat(t),{defIds:i.defIds,idSuffix:d.current},w({ref:n,className:c},s),o)});function te(e,n,i,t,r){return S.createElement(e.tag,w(w({key:n},he(e,i,r)),t),(De(e,i).children||[]).map(function(o,s){return te(o,"".concat(n,"-").concat(e.tag,"-").concat(s),i,void 0,r)}))}function he(e,n,i){var t=w({},e.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(t[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function De(e,n){var i,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((i=e.children)===null||i===void 0)&&i.length)?w(w({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?w(w({},r),{attrs:w(w({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function Se(){return Math.random().toString(36).substring(2,8)}ne.displayName="UniverIcon";var _e={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"}}]},ie=S.forwardRef(function(e,n){return S.createElement(ne,Object.assign({},e,{id:"add-image-single",ref:n,icon:_e}))});ie.displayName="AddImageSingle";const H={id:"doc.operation.insert-float-image",type:a.CommandType.OPERATION,handler:(e,n)=>!0},re={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ce=()=>{const e=U.useDependency(a.ICommandService),n=S.useRef(null),i=()=>{var o;(o=n.current)==null||o.click()},t=I.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(o=>`.${o.replace("image/","")}`).join(","),r=o=>{const s=o.target.files;if(s==null)return;const c=Array.from(s);e.executeCommand(H.id,{files:c}),n.current&&(n.current.value="")};return S.createElement("div",{onClick:i,className:re.uploadFileMenu},S.createElement("input",{type:"file",className:re.uploadFileMenuInput,ref:n,onChange:r,accept:t,multiple:!0}))},oe="COMPONENT_DOC_UPLOAD_FILE_MENU",ae="addition-and-subtraction-single",se="doc.menu.image";function ye(e){return{id:se,type:_.MenuItemType.SUBITEMS,positions:[_.MenuPosition.TOOLBAR_START],group:_.MenuGroup.TOOLBAR_LAYOUT,icon:ae,tooltip:"docImage.title",hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}function Me(e){return{id:H.id,title:"docImage.upload.float",type:_.MenuItemType.SELECTOR,label:{name:oe},positions:[se],hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}const T={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},Z={id:"doc.command.set-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:u,redo:p,objects:l}=s;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:p,objects:l,type:m.DocDrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:u,objects:l,type:m.DocDrawingApplyType.UPDATE}},{id:M.id,params:[c]}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:p,objects:l,type:m.DocDrawingApplyType.UPDATE}},{id:M.id,params:[c]}]}),!0):!1}},we=e=>{U.useDependency(a.ICommandService);const n=U.useDependency(a.LocaleService),i=U.useDependency(I.IDrawingManagerService),t=U.useDependency(E.IRenderManagerService),{drawings:r}=e,o=r[0];if(o==null)return;const{unitId:s}=o,c=t.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;const u=d.getTransformerByCreate(),[p,l]=S.useState(!0);S.useState("");function g(h,D){const y=[];return h.forEach(P=>{const{oKey:A}=P;if(D.getDrawingOKey(A)==null)return y.push(null),!0}),y}S.useEffect(()=>{const h=u.onClearControlObservable.add(y=>{y===!0&&l(!1)}),D=u.onChangeStartObservable.add(y=>{const{objects:P}=y;g(P,i)});return()=>{D==null||D.dispose(),h==null||h.dispose()}},[]);const v=h=>h?"block":"none";return S.createElement("div",{className:F(T.imageCommonPanelGrid,T.imageCommonPanelBorder),style:{display:v(p)}},S.createElement("div",{className:T.imageCommonPanelRow},S.createElement("div",{className:F(T.imageCommonPanelColumn,T.imageCommonPanelTitle)},S.createElement("div",null,n.t("drawing-anchor.title")))),S.createElement("div",{className:F(T.imageCommonPanelRow)},S.createElement("div",{className:F(T.imageCommonPanelColumn)})))},Oe=()=>{const e=U.useDependency(I.IDrawingManagerService),n=e.getFocusDrawings();if(n==null||n.length===0)return;const[i,t]=S.useState(n);return S.useEffect(()=>{const r=e.focus$.subscribe(o=>{t(o)});return()=>{r.unsubscribe()}},[]),S.createElement("div",{className:T.imageCommonPanel},S.createElement(R.DrawingCommonPanel,{drawings:i}),S.createElement(we,{drawings:i}))},L={id:"doc.command.move-drawing",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(m.IDocDrawingService),{direction:r}=n,o=t.getFocusDrawings();if(o.length===0)return!1;const s=o[0].unitId,c=o.map(u=>{const{transform:p}=u;if(p==null)return null;const l={...p},{left:g=0,top:v=0}=p;return r===a.Direction.UP?l.top=v-1:r===a.Direction.DOWN?l.top=v+1:r===a.Direction.LEFT?l.left=g-1:r===a.Direction.RIGHT&&(l.left=g+1),{...u,transform:l,docTransform:N.transformToDocDrawingPosition(l)}}).filter(u=>u!=null);return i.syncExecuteCommand(Z.id,{unitId:s,drawings:c})?(i.syncExecuteCommand(M.id,[s]),!0):!1}},ce={id:"doc.command.delete-drawing",type:a.CommandType.COMMAND,handler:e=>{const n=e.get(a.ICommandService),t=e.get(m.IDocDrawingService).getFocusDrawings();if(t.length===0)return!1;const r=t[0].unitId,o=t.map(s=>{const{unitId:c,subUnitId:d,drawingId:u,drawingType:p}=s;return{unitId:c,subUnitId:d,drawingId:u,drawingType:p}});return n.executeCommand(z.id,{unitId:r,drawings:o})}},de={id:"doc.command.set-drawing-arrange",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService);if(!n)return!1;const r=e.get(m.IDocDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,u={unitId:o,subUnitId:s,drawingIds:c};let p;if(d===I.ArrangeTypeEnum.forward?p=r.getForwardDrawingsOp(u):d===I.ArrangeTypeEnum.backward?p=r.getBackwardDrawingOp(u):d===I.ArrangeTypeEnum.front?p=r.getFrontDrawingsOp(u):d===I.ArrangeTypeEnum.back&&(p=r.getBackDrawingsOp(u)),p==null)return!1;const{objects:l,redo:g,undo:v}=p;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:l,type:m.DocDrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:v,unitId:o,subUnitId:s,objects:l,type:m.DocDrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:l,type:m.DocDrawingApplyType.ARRANGE}}]}),!0):!1}};function Pe(e){const n=[];return e.forEach(i=>{const{parent:t,children:r}=i,{unitId:o,subUnitId:s,drawingId:c}=t,d=E.getGroupState(0,0,r.map(l=>l.transform||{})),u=r.map(l=>{const g=l.transform||{left:0,top:0},{unitId:v,subUnitId:h,drawingId:D}=l;return{unitId:v,subUnitId:h,drawingId:D,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:c}}),p={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:p,children:u})}),n}function Te(e){const n=[];return e.forEach(i=>{const{parent:t,children:r}=i,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=t;if(d==null)return;const u=r.map(l=>{const{transform:g}=l,{unitId:v,subUnitId:h,drawingId:D}=l,y=E.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:v,subUnitId:h,drawingId:D,transform:y,groupId:void 0}}),p={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:p,children:u})}),n}const ue={id:"doc.command.ungroup-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:v,children:h})=>{o.push(v.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:p,objects:l}=s;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Pe(l),type:m.DocDrawingApplyType.GROUP}},{id:M.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.UNGROUP}},{id:M.id,params:o}]}),!0):!1}},me={id:"doc.command.group-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:v,children:h})=>{o.push(v.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:p,objects:l}=s;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Te(l),type:m.DocDrawingApplyType.UNGROUP}},{id:M.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.GROUP}},{id:M.id,params:o}]}),!0):!1}},le={id:"doc.command.insert-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(h=>h.unitId),c=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:p,redo:l,objects:g}=c;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:d,subUnitId:u,objects:g,type:m.DocDrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:d,subUnitId:u,objects:g,type:m.DocDrawingApplyType.REMOVE}},{id:M.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:g,type:m.DocDrawingApplyType.INSERT}},{id:M.id,params:s}]}),!0):!1}};function G(e){return!e.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const Ee={id:L.id,description:"shortcut.doc.drawing-move-down",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_DOWN,priority:100,preconditions:G,staticParameters:{direction:a.Direction.DOWN}},Ue={id:L.id,description:"shortcut.doc.drawing-move-up",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_UP,priority:100,preconditions:G,staticParameters:{direction:a.Direction.UP}},Ae={id:L.id,description:"shortcut.doc.drawing-move-left",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_LEFT,priority:100,preconditions:G,staticParameters:{direction:a.Direction.LEFT}},be={id:L.id,description:"shortcut.doc.drawing-move-right",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_RIGHT,priority:100,preconditions:G,staticParameters:{direction:a.Direction.RIGHT}},Re={id:ce.id,description:"shortcut.doc.drawing-delete",group:"4_doc-drawing-view",preconditions:G,binding:_.KeyCode.DELETE,mac:_.KeyCode.BACKSPACE};var Ne=Object.defineProperty,je=Object.getOwnPropertyDescriptor,Le=(e,n,i,t)=>{for(var r=t>1?void 0:t?je(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&Ne(n,i,r),r},x=(e,n)=>(i,t)=>n(i,t,e);let B=class extends a.Disposable{constructor(e,n,i,t,r){super(),this._injector=e,this._componentManager=n,this._menuService=i,this._commandService=t,this._shortcutService=r,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(ae,ie)),this.disposeWithMe(e.register(oe,Ce)),this.disposeWithMe(e.register(X,Oe))}_initMenus(){[ye,Me].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),{}))})}_initCommands(){[H,le,z,Z,J,M,ee,me,ue,L,ce,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Ee,Ue,Ae,be,Re].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};B=Le([a.OnLifecycle(a.LifecycleStages.Ready,B),x(0,C.Inject(C.Injector)),x(1,C.Inject(_.ComponentManager)),x(2,_.IMenuService),x(3,a.ICommandService),x(4,_.IShortcutService)],B);var Ge=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(e,n,i,t)=>{for(var r=t>1?void 0:t?xe(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&Ge(n,i,r),r},O=(e,n)=>(i,t)=>n(i,t,e);let q=class extends a.Disposable{constructor(e,n,i,t,r,o,s,c,d,u,p){super(),this._commandService=e,this._univerInstanceService=n,this._textSelectionManagerService=i,this._imageIoService=t,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=c,this._localeService=d,this._docSkeletonManagerService=u,this._renderManagerService=p,this._init()}_init(){this._initCommandListeners(),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===H.id){const n=e.params;if(n.files==null)return;const i=n.files.length;if(i>I.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(I.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(i),n.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertFloatImage(e){var A;let n;try{n=await this._imageIoService.saveImage(e)}catch(W){const b=W.message;b===I.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(I.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):b===I.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):b===I.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const i=this._getUnitInfo();if(i==null)return;const{unitId:t,subUnitId:r}=i,{imageId:o,imageSourceType:s,source:c,base64Cache:d}=n,{width:u,height:p,image:l}=await I.getImageSize(d||""),g=this._renderManagerService.getRenderById(t);if(g==null)return;const{width:v,height:h}=g.scene;this._imageIoService.addImageSourceCache(o,s,l);let D=1;if(u>I.DRAWING_IMAGE_WIDTH_LIMIT||p>I.DRAWING_IMAGE_HEIGHT_LIMIT){const W=I.DRAWING_IMAGE_WIDTH_LIMIT/u,b=I.DRAWING_IMAGE_HEIGHT_LIMIT/p;D=Math.max(W,b)}const y=this._getImagePosition(u*D,p*D,v,h);if(y==null)return;const P={unitId:t,subUnitId:r,drawingId:o,drawingType:I.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:N.docDrawingPositionToTransform(y),docTransform:y,title:"",description:"",layoutType:a.PositionedObjectLayoutType.WRAP_SQUARE};this._commandService.executeCommand(le.id,{unitId:t,drawings:[P]}),(A=this._docSkeletonManagerService.getCurrent())==null||A.skeleton.calculate()}_getUnitInfo(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(e==null)return;const n=e.getUnitId();return{unitId:n,subUnitId:n}}_getImagePosition(e,n,i,t){const r=this._textSelectionManagerService.getActiveTextRange(),o=(r==null?void 0:r.getAbsolutePosition())||{left:0,top:0};return{size:{width:e,height:n},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:o.left},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:o.top},angle:0}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:n,subUnitId:i,drawingIds:t,arrangeType:r}=e;this._commandService.executeCommand(de.id,{unitId:n,subUnitId:i,drawingIds:t,arrangeType:r})})}_updateDrawingListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const n=[];e.length!==0&&(e.forEach(i=>{const{unitId:t,subUnitId:r,drawingId:o,drawingType:s,transform:c}=i;if(c==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:r,drawingId:o});if(d==null)return;const u=N.transformToDocDrawingPosition({...d.transform,...c});if(u==null)return;const p={...i,transform:{...c,...N.docDrawingPositionToTransform(u)},docTransform:{...u}};n.push(p)}),n.length>0&&(this._commandService.syncExecuteCommand(Z.id,{unitId:e[0].unitId,drawings:n}),this._refreshDocSkeleton()))})}_getDocsOffsetInfo(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{unitId:n,skeleton:i}=e,t=this._renderManagerService.getRenderById(n),r=i==null?void 0:i.getSkeletonData();if(t==null||!r)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{mainComponent:o}=t,s=o,{left:c,top:d,pageLayoutType:u,pageMarginLeft:p,pageMarginTop:l}=s,{pages:g}=r,v=new E.Liquid,h=new Map;for(let D=0,y=g.length;D<y;D++){const P=g[D],{skeDrawings:A,marginLeft:W,marginTop:b}=P;v.translatePagePadding(P),A.forEach(Be=>{const{aLeft:mn,aTop:ln,height:pn,width:gn,drawingId:qe,drawingOrigin:fn}=Be;h.set(qe,{marginLeft:v.x,marginTop:v.y})}),v.restorePagePadding(P),v.translatePage(P,u,p,l)}return{pageMarginCache:h,docsLeft:c,docsTop:d}}_refreshDocSkeleton(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:i}=e,t=this._renderManagerService.getRenderById(n);if(t==null)return;const{mainComponent:r}=t;i==null||i.calculate(),r==null||r.makeDirty()}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(me.id,e)}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ue.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};q=We([a.OnLifecycle(a.LifecycleStages.Rendered,q),O(0,a.ICommandService),O(1,a.IUniverInstanceService),O(2,C.Inject(Q.TextSelectionManagerService)),O(3,I.IImageIoService),O(4,m.IDocDrawingService),O(5,I.IDrawingManagerService),O(6,a.IContextService),O(7,_.IMessageService),O(8,C.Inject(a.LocaleService)),O(9,C.Inject(Q.DocSkeletonManagerService)),O(10,E.IRenderManagerService)],q);var Fe=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(e,n,i,t)=>{for(var r=t>1?void 0:t?Ve(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&Fe(n,i,r),r},pe=(e,n)=>(i,t)=>n(i,t,e);const He="Docs_Drawing_UI_PLUGIN";f.UniverDocsDrawingUIPlugin=(K=class extends a.Plugin{constructor(n,i,t){super(),this._injector=i,this._localeService=t}onStarting(n){this._initDependencies(n)}_initDependencies(n){[[B],[q],[$]].forEach(t=>n.add(t))}},k(K,"type",a.UniverInstanceType.UNIVER_DOC),k(K,"pluginName",He),K),f.UniverDocsDrawingUIPlugin=$e([pe(1,C.Inject(C.Injector)),pe(2,C.Inject(a.LocaleService))],f.UniverDocsDrawingUIPlugin),Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(f,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/engine-render"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/docs-drawing"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("react"),require("clsx"),require("@univerjs/design"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/engine-render","@univerjs/drawing-ui","rxjs","@univerjs/docs-ui","@univerjs/drawing","@univerjs/docs-drawing","@univerjs/ui","@wendellhu/redi/react-bindings","react","clsx","@univerjs/design","@univerjs/docs"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f.UniverDocsDrawingUi={},f.UniverCore,f["@wendellhu/redi"],f.UniverEngineRender,f.UniverDrawingUi,f.rxjs,f.UniverDocsUi,f.UniverDrawing,f.UniverDocsDrawing,f.UniverUi,f["@wendellhu/redi/react-bindings"],f.React,f.clsx,f.UniverDesign,f.UniverDocs))})(this,function(f,a,C,E,R,Y,N,I,m,_,U,S,F,V,Q){"use strict";var Ke=Object.defineProperty;var ke=(f,a,C)=>a in f?Ke(f,a,{enumerable:!0,configurable:!0,writable:!0,value:C}):f[a]=C;var k=(f,a,C)=>ke(f,typeof a!="symbol"?a+"":a,C);var K;const M={id:"sheet.operation.clear-drawing-transformer",type:a.CommandType.MUTATION,handler:(e,n)=>{const i=e.get(E.IRenderManagerService);return n.forEach(t=>{var r,o;(o=(r=i.getRenderById(t))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},z={id:"doc.command.remove-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(h=>{const{unitId:D}=h;s.push(D)});const c=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:p,redo:l,objects:g}=c;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:l,objects:g,type:m.DocDrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:p,objects:g,type:m.DocDrawingApplyType.INSERT}},{id:M.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:g,type:m.DocDrawingApplyType.REMOVE}},{id:M.id,params:s}]}),!0):!1}},X="COMPONENT_DOC_DRAWING_PANEL",J={id:"sidebar.operation.doc-image",type:a.CommandType.COMMAND,handler:async(e,n)=>{const i=e.get(_.ISidebarService),t=e.get(a.LocaleService),r=e.get(I.IDrawingManagerService);switch(n.value){case"open":i.open({header:{title:t.t("docImage.panel.title")},children:{label:X},onClose:()=>{r.focusDrawing(null)},width:360});break;case"close":default:i.close();break}return!0}},ee={id:"sheet.operation.edit-sheet-image",type:a.CommandType.OPERATION,handler:(e,n)=>{const i=e.get(I.IDrawingManagerService),t=e.get(a.ICommandService);return n==null?!1:(i.focusDrawing([n]),t.executeCommand(J.id,{value:"open"}),!0)}};var ge=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,Ie=(e,n,i,t)=>{for(var r=t>1?void 0:t?fe(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&ge(n,i,r),r},j=(e,n)=>(i,t)=>n(i,t,e);let $=class extends a.RxDisposable{constructor(n,i,t,r,o){super();k(this,"_initImagePopupMenu",new Set);this._drawingManagerService=n,this._canvasPopManagerService=i,this._renderManagerService=t,this._univerInstanceService=r,this._contextService=o,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(Y.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(Y.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(n=>this._create(n))}_dispose(n){const i=n.getUnitId();this._renderManagerService.removeRender(i)}_create(n){if(!n)return;const i=n.getUnitId();this._renderManagerService.has(i)&&!this._initImagePopupMenu.has(i)&&(this._popupMenuListener(i),this._initImagePopupMenu.add(i))}_hasCropObject(n){const i=n.getAllObjects();for(const t of i)if(t instanceof R.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const i=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!i)return;const t=i.getTransformerByCreate();if(!t)return;const r=[];this.disposeWithMe(a.toDisposable(t.onCreateControlObservable.add(()=>{if(this._hasCropObject(i))return;const s=t.getSelectedObjectMap();if(s.size>1){r.forEach(v=>v.dispose());return}const c=s.values().next().value;if(!c)return;const d=c.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:p,subUnitId:l,drawingId:g}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:R.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(p,l,g)}}))),this._drawingManagerService.focusDrawing([{unitId:p,subUnitId:l,drawingId:g}])}))),this.disposeWithMe(a.toDisposable(t.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(a.toDisposable(t.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,i,t){return[{label:"image-popup.edit",index:0,commandId:ee.id,commandParams:{unitId:n,subUnitId:i,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:z.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:i,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:R.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:i,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:R.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:i,drawingId:t}],disable:!1}]}};$=Ie([a.OnLifecycle(a.LifecycleStages.Rendered,$),j(0,I.IDrawingManagerService),j(1,C.Inject(N.DocCanvasPopManagerService)),j(2,E.IRenderManagerService),j(3,a.IUniverInstanceService),j(4,a.IContextService)],$);var w=function(){return w=Object.assign||function(e){for(var n,i=1,t=arguments.length;i<t;i++){n=arguments[i];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},w.apply(this,arguments)},ve=function(e,n){var i={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(i[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(e);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(e,t[r])&&(i[t[r]]=e[t[r]]);return i},ne=S.forwardRef(function(e,n){var i=e.icon,t=e.id,r=e.className,o=e.extend,s=ve(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),d=S.useRef("_".concat(Se()));return te(i,"".concat(t),{defIds:i.defIds,idSuffix:d.current},w({ref:n,className:c},s),o)});function te(e,n,i,t,r){return S.createElement(e.tag,w(w({key:n},he(e,i,r)),t),(De(e,i).children||[]).map(function(o,s){return te(o,"".concat(n,"-").concat(e.tag,"-").concat(s),i,void 0,r)}))}function he(e,n,i){var t=w({},e.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(t[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function De(e,n){var i,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((i=e.children)===null||i===void 0)&&i.length)?w(w({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?w(w({},r),{attrs:w(w({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function Se(){return Math.random().toString(36).substring(2,8)}ne.displayName="UniverIcon";var _e={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"}}]},ie=S.forwardRef(function(e,n){return S.createElement(ne,Object.assign({},e,{id:"add-image-single",ref:n,icon:_e}))});ie.displayName="AddImageSingle";const H={id:"doc.operation.insert-float-image",type:a.CommandType.OPERATION,handler:(e,n)=>!0},re={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ce=()=>{const e=U.useDependency(a.ICommandService),n=S.useRef(null),i=()=>{var o;(o=n.current)==null||o.click()},t=I.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(o=>`.${o.replace("image/","")}`).join(","),r=o=>{const s=o.target.files;if(s==null)return;const c=Array.from(s);e.executeCommand(H.id,{files:c}),n.current&&(n.current.value="")};return S.createElement("div",{onClick:i,className:re.uploadFileMenu},S.createElement("input",{type:"file",className:re.uploadFileMenuInput,ref:n,onChange:r,accept:t,multiple:!0}))},oe="COMPONENT_DOC_UPLOAD_FILE_MENU",ae="addition-and-subtraction-single",se="doc.menu.image";function ye(e){return{id:se,type:_.MenuItemType.SUBITEMS,positions:[_.MenuPosition.TOOLBAR_START],group:_.MenuGroup.TOOLBAR_LAYOUT,icon:ae,tooltip:"docImage.title",hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}function Me(e){return{id:H.id,title:"docImage.upload.float",type:_.MenuItemType.SELECTOR,label:{name:oe},positions:[se],hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}const T={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},Z={id:"doc.command.set-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:u,redo:p,objects:l}=s;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:p,objects:l,type:m.DocDrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:u,objects:l,type:m.DocDrawingApplyType.UPDATE}},{id:M.id,params:[c]}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:p,objects:l,type:m.DocDrawingApplyType.UPDATE}},{id:M.id,params:[c]}]}),!0):!1}},we=e=>{U.useDependency(a.ICommandService);const n=U.useDependency(a.LocaleService),i=U.useDependency(I.IDrawingManagerService),t=U.useDependency(E.IRenderManagerService),{drawings:r}=e,o=r[0];if(o==null)return;const{unitId:s}=o,c=t.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;const u=d.getTransformerByCreate(),[p,l]=S.useState(!0);S.useState("");function g(h,D){const y=[];return h.forEach(P=>{const{oKey:A}=P;if(D.getDrawingOKey(A)==null)return y.push(null),!0}),y}S.useEffect(()=>{const h=u.onClearControlObservable.add(y=>{y===!0&&l(!1)}),D=u.onChangeStartObservable.add(y=>{const{objects:P}=y;g(P,i)});return()=>{D==null||D.dispose(),h==null||h.dispose()}},[]);const v=h=>h?"block":"none";return S.createElement("div",{className:F(T.imageCommonPanelGrid,T.imageCommonPanelBorder),style:{display:v(p)}},S.createElement("div",{className:T.imageCommonPanelRow},S.createElement("div",{className:F(T.imageCommonPanelColumn,T.imageCommonPanelTitle)},S.createElement("div",null,n.t("drawing-anchor.title")))),S.createElement("div",{className:F(T.imageCommonPanelRow)},S.createElement("div",{className:F(T.imageCommonPanelColumn)})))},Oe=()=>{const e=U.useDependency(I.IDrawingManagerService),n=e.getFocusDrawings(),[i,t]=S.useState(n);return S.useEffect(()=>{const r=e.focus$.subscribe(o=>{t(o)});return()=>{r.unsubscribe()}},[]),!!(i!=null&&i.length)&&S.createElement("div",{className:T.imageCommonPanel},S.createElement(R.DrawingCommonPanel,{drawings:i}),S.createElement(we,{drawings:i}))},L={id:"doc.command.move-drawing",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(m.IDocDrawingService),{direction:r}=n,o=t.getFocusDrawings();if(o.length===0)return!1;const s=o[0].unitId,c=o.map(u=>{const{transform:p}=u;if(p==null)return null;const l={...p},{left:g=0,top:v=0}=p;return r===a.Direction.UP?l.top=v-1:r===a.Direction.DOWN?l.top=v+1:r===a.Direction.LEFT?l.left=g-1:r===a.Direction.RIGHT&&(l.left=g+1),{...u,transform:l,docTransform:N.transformToDocDrawingPosition(l)}}).filter(u=>u!=null);return i.syncExecuteCommand(Z.id,{unitId:s,drawings:c})?(i.syncExecuteCommand(M.id,[s]),!0):!1}},ce={id:"doc.command.delete-drawing",type:a.CommandType.COMMAND,handler:e=>{const n=e.get(a.ICommandService),t=e.get(m.IDocDrawingService).getFocusDrawings();if(t.length===0)return!1;const r=t[0].unitId,o=t.map(s=>{const{unitId:c,subUnitId:d,drawingId:u,drawingType:p}=s;return{unitId:c,subUnitId:d,drawingId:u,drawingType:p}});return n.executeCommand(z.id,{unitId:r,drawings:o})}},de={id:"doc.command.set-drawing-arrange",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService);if(!n)return!1;const r=e.get(m.IDocDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,u={unitId:o,subUnitId:s,drawingIds:c};let p;if(d===I.ArrangeTypeEnum.forward?p=r.getForwardDrawingsOp(u):d===I.ArrangeTypeEnum.backward?p=r.getBackwardDrawingOp(u):d===I.ArrangeTypeEnum.front?p=r.getFrontDrawingsOp(u):d===I.ArrangeTypeEnum.back&&(p=r.getBackDrawingsOp(u)),p==null)return!1;const{objects:l,redo:g,undo:v}=p;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:l,type:m.DocDrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:v,unitId:o,subUnitId:s,objects:l,type:m.DocDrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:l,type:m.DocDrawingApplyType.ARRANGE}}]}),!0):!1}};function Pe(e){const n=[];return e.forEach(i=>{const{parent:t,children:r}=i,{unitId:o,subUnitId:s,drawingId:c}=t,d=E.getGroupState(0,0,r.map(l=>l.transform||{})),u=r.map(l=>{const g=l.transform||{left:0,top:0},{unitId:v,subUnitId:h,drawingId:D}=l;return{unitId:v,subUnitId:h,drawingId:D,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:c}}),p={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:p,children:u})}),n}function Te(e){const n=[];return e.forEach(i=>{const{parent:t,children:r}=i,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=t;if(d==null)return;const u=r.map(l=>{const{transform:g}=l,{unitId:v,subUnitId:h,drawingId:D}=l,y=E.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:v,subUnitId:h,drawingId:D,transform:y,groupId:void 0}}),p={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:p,children:u})}),n}const ue={id:"doc.command.ungroup-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:v,children:h})=>{o.push(v.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:p,objects:l}=s;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Pe(l),type:m.DocDrawingApplyType.GROUP}},{id:M.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.UNGROUP}},{id:M.id,params:o}]}),!0):!1}},me={id:"doc.command.group-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:v,children:h})=>{o.push(v.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:p,objects:l}=s;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Te(l),type:m.DocDrawingApplyType.UNGROUP}},{id:M.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:c,subUnitId:d,objects:l,type:m.DocDrawingApplyType.GROUP}},{id:M.id,params:o}]}),!0):!1}},le={id:"doc.command.insert-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const i=e.get(a.ICommandService),t=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(h=>h.unitId),c=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:p,redo:l,objects:g}=c;return i.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:d,subUnitId:u,objects:g,type:m.DocDrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:d,subUnitId:u,objects:g,type:m.DocDrawingApplyType.REMOVE}},{id:M.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:g,type:m.DocDrawingApplyType.INSERT}},{id:M.id,params:s}]}),!0):!1}};function G(e){return!e.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const Ee={id:L.id,description:"shortcut.doc.drawing-move-down",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_DOWN,priority:100,preconditions:G,staticParameters:{direction:a.Direction.DOWN}},Ue={id:L.id,description:"shortcut.doc.drawing-move-up",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_UP,priority:100,preconditions:G,staticParameters:{direction:a.Direction.UP}},Ae={id:L.id,description:"shortcut.doc.drawing-move-left",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_LEFT,priority:100,preconditions:G,staticParameters:{direction:a.Direction.LEFT}},be={id:L.id,description:"shortcut.doc.drawing-move-right",group:"4_doc-drawing-view",binding:_.KeyCode.ARROW_RIGHT,priority:100,preconditions:G,staticParameters:{direction:a.Direction.RIGHT}},Re={id:ce.id,description:"shortcut.doc.drawing-delete",group:"4_doc-drawing-view",preconditions:G,binding:_.KeyCode.DELETE,mac:_.KeyCode.BACKSPACE};var Ne=Object.defineProperty,je=Object.getOwnPropertyDescriptor,Le=(e,n,i,t)=>{for(var r=t>1?void 0:t?je(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&Ne(n,i,r),r},x=(e,n)=>(i,t)=>n(i,t,e);let B=class extends a.Disposable{constructor(e,n,i,t,r){super(),this._injector=e,this._componentManager=n,this._menuService=i,this._commandService=t,this._shortcutService=r,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(ae,ie)),this.disposeWithMe(e.register(oe,Ce)),this.disposeWithMe(e.register(X,Oe))}_initMenus(){[ye,Me].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),{}))})}_initCommands(){[H,le,z,Z,J,M,ee,me,ue,L,ce,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Ee,Ue,Ae,be,Re].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};B=Le([a.OnLifecycle(a.LifecycleStages.Ready,B),x(0,C.Inject(C.Injector)),x(1,C.Inject(_.ComponentManager)),x(2,_.IMenuService),x(3,a.ICommandService),x(4,_.IShortcutService)],B);var Ge=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(e,n,i,t)=>{for(var r=t>1?void 0:t?xe(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&Ge(n,i,r),r},O=(e,n)=>(i,t)=>n(i,t,e);let q=class extends a.Disposable{constructor(e,n,i,t,r,o,s,c,d,u,p){super(),this._commandService=e,this._univerInstanceService=n,this._textSelectionManagerService=i,this._imageIoService=t,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=c,this._localeService=d,this._docSkeletonManagerService=u,this._renderManagerService=p,this._init()}_init(){this._initCommandListeners(),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===H.id){const n=e.params;if(n.files==null)return;const i=n.files.length;if(i>I.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(I.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(i),n.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertFloatImage(e){var A;let n;try{n=await this._imageIoService.saveImage(e)}catch(W){const b=W.message;b===I.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(I.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):b===I.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):b===I.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const i=this._getUnitInfo();if(i==null)return;const{unitId:t,subUnitId:r}=i,{imageId:o,imageSourceType:s,source:c,base64Cache:d}=n,{width:u,height:p,image:l}=await I.getImageSize(d||""),g=this._renderManagerService.getRenderById(t);if(g==null)return;const{width:v,height:h}=g.scene;this._imageIoService.addImageSourceCache(o,s,l);let D=1;if(u>I.DRAWING_IMAGE_WIDTH_LIMIT||p>I.DRAWING_IMAGE_HEIGHT_LIMIT){const W=I.DRAWING_IMAGE_WIDTH_LIMIT/u,b=I.DRAWING_IMAGE_HEIGHT_LIMIT/p;D=Math.max(W,b)}const y=this._getImagePosition(u*D,p*D,v,h);if(y==null)return;const P={unitId:t,subUnitId:r,drawingId:o,drawingType:I.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:N.docDrawingPositionToTransform(y),docTransform:y,title:"",description:"",layoutType:a.PositionedObjectLayoutType.WRAP_SQUARE};this._commandService.executeCommand(le.id,{unitId:t,drawings:[P]}),(A=this._docSkeletonManagerService.getCurrent())==null||A.skeleton.calculate()}_getUnitInfo(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(e==null)return;const n=e.getUnitId();return{unitId:n,subUnitId:n}}_getImagePosition(e,n,i,t){const r=this._textSelectionManagerService.getActiveTextRange(),o=(r==null?void 0:r.getAbsolutePosition())||{left:0,top:0};return{size:{width:e,height:n},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:o.left},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:o.top},angle:0}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:n,subUnitId:i,drawingIds:t,arrangeType:r}=e;this._commandService.executeCommand(de.id,{unitId:n,subUnitId:i,drawingIds:t,arrangeType:r})})}_updateDrawingListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const n=[];e.length!==0&&(e.forEach(i=>{const{unitId:t,subUnitId:r,drawingId:o,drawingType:s,transform:c}=i;if(c==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:r,drawingId:o});if(d==null)return;const u=N.transformToDocDrawingPosition({...d.transform,...c});if(u==null)return;const p={...i,transform:{...c,...N.docDrawingPositionToTransform(u)},docTransform:{...u}};n.push(p)}),n.length>0&&(this._commandService.syncExecuteCommand(Z.id,{unitId:e[0].unitId,drawings:n}),this._refreshDocSkeleton()))})}_getDocsOffsetInfo(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{unitId:n,skeleton:i}=e,t=this._renderManagerService.getRenderById(n),r=i==null?void 0:i.getSkeletonData();if(t==null||!r)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{mainComponent:o}=t,s=o,{left:c,top:d,pageLayoutType:u,pageMarginLeft:p,pageMarginTop:l}=s,{pages:g}=r,v=new E.Liquid,h=new Map;for(let D=0,y=g.length;D<y;D++){const P=g[D],{skeDrawings:A,marginLeft:W,marginTop:b}=P;v.translatePagePadding(P),A.forEach(Be=>{const{aLeft:mn,aTop:ln,height:pn,width:gn,drawingId:qe,drawingOrigin:fn}=Be;h.set(qe,{marginLeft:v.x,marginTop:v.y})}),v.restorePagePadding(P),v.translatePage(P,u,p,l)}return{pageMarginCache:h,docsLeft:c,docsTop:d}}_refreshDocSkeleton(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:i}=e,t=this._renderManagerService.getRenderById(n);if(t==null)return;const{mainComponent:r}=t;i==null||i.calculate(),r==null||r.makeDirty()}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(me.id,e)}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ue.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};q=We([a.OnLifecycle(a.LifecycleStages.Rendered,q),O(0,a.ICommandService),O(1,a.IUniverInstanceService),O(2,C.Inject(Q.TextSelectionManagerService)),O(3,I.IImageIoService),O(4,m.IDocDrawingService),O(5,I.IDrawingManagerService),O(6,a.IContextService),O(7,_.IMessageService),O(8,C.Inject(a.LocaleService)),O(9,C.Inject(Q.DocSkeletonManagerService)),O(10,E.IRenderManagerService)],q);var Fe=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(e,n,i,t)=>{for(var r=t>1?void 0:t?Ve(n,i):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(t?s(n,i,r):s(r))||r);return t&&r&&Fe(n,i,r),r},pe=(e,n)=>(i,t)=>n(i,t,e);const He="Docs_Drawing_UI_PLUGIN";f.UniverDocsDrawingUIPlugin=(K=class extends a.Plugin{constructor(n,i,t){super(),this._injector=i,this._localeService=t}onStarting(n){this._initDependencies(n)}_initDependencies(n){[[B],[q],[$]].forEach(t=>n.add(t))}},k(K,"type",a.UniverInstanceType.UNIVER_DOC),k(K,"pluginName",He),K),f.UniverDocsDrawingUIPlugin=$e([pe(1,C.Inject(C.Injector)),pe(2,C.Inject(a.LocaleService))],f.UniverDocsDrawingUIPlugin),Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-drawing-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"clsx": ">=2.0.0",
|
|
53
53
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
54
54
|
"rxjs": ">=7.0.0",
|
|
55
|
-
"@univerjs/core": "0.1.
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/docs-drawing": "0.1.
|
|
58
|
-
"@univerjs/docs-ui": "0.1.
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/drawing-ui": "0.1.
|
|
62
|
-
"@univerjs/engine-render": "0.1.
|
|
63
|
-
"@univerjs/ui": "0.1.
|
|
55
|
+
"@univerjs/core": "0.1.16",
|
|
56
|
+
"@univerjs/design": "0.1.16",
|
|
57
|
+
"@univerjs/docs-drawing": "0.1.16",
|
|
58
|
+
"@univerjs/docs-ui": "0.1.16",
|
|
59
|
+
"@univerjs/drawing": "0.1.16",
|
|
60
|
+
"@univerjs/docs": "0.1.16",
|
|
61
|
+
"@univerjs/drawing-ui": "0.1.16",
|
|
62
|
+
"@univerjs/engine-render": "0.1.16",
|
|
63
|
+
"@univerjs/ui": "0.1.16"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@univerjs/icons": "^0.1.
|
|
66
|
+
"@univerjs/icons": "^0.1.57"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@wendellhu/redi": "0.15.4",
|
|
@@ -73,18 +73,18 @@
|
|
|
73
73
|
"react": "18.3.1",
|
|
74
74
|
"rxjs": "^7.8.1",
|
|
75
75
|
"typescript": "^5.4.5",
|
|
76
|
-
"vite": "^5.
|
|
76
|
+
"vite": "^5.3.1",
|
|
77
77
|
"vitest": "^1.6.0",
|
|
78
|
-
"@univerjs/core": "0.1.
|
|
79
|
-
"@univerjs/design": "0.1.
|
|
80
|
-
"@univerjs/docs-drawing": "0.1.
|
|
81
|
-
"@univerjs/docs
|
|
82
|
-
"@univerjs/drawing": "0.1.
|
|
83
|
-
"@univerjs/
|
|
84
|
-
"@univerjs/
|
|
85
|
-
"@univerjs/
|
|
86
|
-
"@univerjs/
|
|
87
|
-
"@univerjs/
|
|
78
|
+
"@univerjs/core": "0.1.16",
|
|
79
|
+
"@univerjs/design": "0.1.16",
|
|
80
|
+
"@univerjs/docs-drawing": "0.1.16",
|
|
81
|
+
"@univerjs/docs": "0.1.16",
|
|
82
|
+
"@univerjs/drawing": "0.1.16",
|
|
83
|
+
"@univerjs/drawing-ui": "0.1.16",
|
|
84
|
+
"@univerjs/docs-ui": "0.1.16",
|
|
85
|
+
"@univerjs/ui": "0.1.16",
|
|
86
|
+
"@univerjs/engine-render": "0.1.16",
|
|
87
|
+
"@univerjs/shared": "0.1.16"
|
|
88
88
|
},
|
|
89
89
|
"univerSpace": {
|
|
90
90
|
".": {
|