@univerjs/slides-ui 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2744 -1
- package/lib/cjs/locale/ca-ES.js +28 -1
- package/lib/cjs/locale/en-US.js +43 -1
- package/lib/cjs/locale/es-ES.js +28 -1
- package/lib/cjs/locale/fa-IR.js +28 -1
- package/lib/cjs/locale/fr-FR.js +28 -1
- package/lib/cjs/locale/ja-JP.js +28 -1
- package/lib/cjs/locale/ko-KR.js +28 -1
- package/lib/cjs/locale/ru-RU.js +47 -1
- package/lib/cjs/locale/sk-SK.js +28 -1
- package/lib/cjs/locale/vi-VN.js +47 -1
- package/lib/cjs/locale/zh-CN.js +28 -1
- package/lib/cjs/locale/zh-TW.js +47 -1
- package/lib/es/index.js +2701 -1
- package/lib/es/locale/ca-ES.js +27 -1
- package/lib/es/locale/en-US.js +42 -1
- package/lib/es/locale/es-ES.js +27 -1
- package/lib/es/locale/fa-IR.js +27 -1
- package/lib/es/locale/fr-FR.js +27 -1
- package/lib/es/locale/ja-JP.js +27 -1
- package/lib/es/locale/ko-KR.js +27 -1
- package/lib/es/locale/ru-RU.js +46 -1
- package/lib/es/locale/sk-SK.js +27 -1
- package/lib/es/locale/vi-VN.js +46 -1
- package/lib/es/locale/zh-CN.js +27 -1
- package/lib/es/locale/zh-TW.js +46 -1
- package/lib/index.js +2701 -1
- package/lib/locale/ca-ES.js +27 -1
- package/lib/locale/en-US.js +42 -1
- package/lib/locale/es-ES.js +27 -1
- package/lib/locale/fa-IR.js +27 -1
- package/lib/locale/fr-FR.js +27 -1
- package/lib/locale/ja-JP.js +27 -1
- package/lib/locale/ko-KR.js +27 -1
- package/lib/locale/ru-RU.js +46 -1
- package/lib/locale/sk-SK.js +27 -1
- package/lib/locale/vi-VN.js +46 -1
- package/lib/locale/zh-CN.js +27 -1
- package/lib/locale/zh-TW.js +46 -1
- package/lib/types/controllers/canvas-view.d.ts +3 -2
- package/lib/types/controllers/slide.render-controller.d.ts +4 -3
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,2744 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/slides`),r=require(`@univerjs/drawing`),i=require(`@univerjs/ui`),a=require(`@univerjs/design`),o=require(`@univerjs/icons`),s=require(`react/jsx-runtime`),c=require(`react`),l=require(`@univerjs/docs-ui`),u=require(`rxjs`),d=require(`@univerjs/docs`);function f(e){"@babel/helpers - typeof";return f=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let v=class extends e.RxDisposable{constructor(t,r,i,a){super(),this._renderContext=t,this._injector=r,this._univerInstanceService=i,this._renderManagerService=a,h(this,`_objectProvider`,null),h(this,`_refreshThumb`,(0,e.debounce)(()=>{this.createThumbs()},300)),this._objectProvider=this._injector.createInstance(n.ObjectProvider),this._addNewRender()}_addNewRender(){let{unitId:e,engine:r,scene:i}=this._renderContext,a=this._getCurrUnitModel();if(!a)return;let o=r.onTransformChange$.subscribeEvent(()=>{this._scrollToCenter(),o==null||o.unsubscribe()});r.onTransformChange$.subscribeEvent(()=>{setTimeout(()=>{this.createThumbs()},300)});let s=new t.Viewport(n.SLIDE_KEY.VIEW,i,{left:0,top:0,bottom:0,right:0,explicitViewportWidthSet:!1,explicitViewportHeightSet:!1,isWheelPreventDefaultX:!0});i.attachControl(),i.onMouseWheel$.subscribeEvent((e,t)=>{let n=e;if(n.ctrlKey){let e=Math.abs(n.deltaX),t=e<40?.2:e<80?.4:.2;t*=n.deltaY>0?-1:1,i.scaleX<1&&(t/=2),i.scaleX+t>4?i.scale(4,4):i.scaleX+t<.1?i.scale(.1,.1):(n.deltaY,n.preventDefault())}else s.onMouseWheel(n,t)}),i.onFileLoaded$.subscribeEvent(()=>{this._refreshThumb()}),t.ScrollBar.attachTo(s);let c=this._createSlide(i);this._renderContext.mainComponent=c,this._createSlidePages(a,c),this.createThumbs(),r.runRenderLoop(()=>{i.render()})}_scrollToCenter(){var e;let t=(e=this._currentRender())==null?void 0:e.scene,r=t==null?void 0:t.getViewport(n.SLIDE_KEY.VIEW),i=this._getCenterPositionViewPort(t);if(!r||!i)return;let{left:a,top:o}=i,{x:s,y:c}=r.transViewportScroll2ScrollValue(a,o);r.scrollToBarPos({x:s,y:c})}_currentRender(){return(0,t.getCurrentTypeOfRenderer)(e.UniverInstanceType.UNIVER_SLIDE,this._univerInstanceService,this._renderManagerService)}_createSlide(r){let i=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE),{width:a,height:o}=r,{width:s=100,height:c=100}=i.getPageSize(),l=new t.Slide(n.SLIDE_KEY.COMPONENT,{left:(a-s)/2,top:(o-c)/2,width:s,height:c,zIndex:10});return l.enableSelectedClipElement(),r.addObject(l),l}_addBackgroundRect(n,r){let{width:i=0,height:a=0}=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE).getPageSize(),o=new t.Rect(`canvas`,{left:0,top:0,width:i,height:a,strokeWidth:1,stroke:`rgba(198,198,198,1)`,fill:(0,e.getColorStyle)(r)||`rgba(255,255,255,1)`,zIndex:0,evented:!1});n.addObject(o,0)}_getCenterPositionViewPort(e){if(!e)return{left:0,top:0};let{width:t,height:n}=e,r=e.getEngine(),i=(r==null?void 0:r.width)||0,a=(r==null?void 0:r.height)||0;return{left:(t-i)/2,top:(n-a)/2}}_thumbSceneRender(e,t){let n=this._renderManagerService.getRenderById(e);if(n==null)return;let{engine:r}=n;if(r==null)return;let{width:i,height:a}=t,{width:o=i,height:s=a}=r,c=r.getCanvas().getContext();t.renderToThumb(c,e,o/i,s/a)}_createSlidePages(e,t){let n=e.getPages(),r=e.getPageOrder();if(!(!n||!r)&&r.length!==0){for(let e=0,t=r.length;e<t;e++){let t=r[e];this.createPageScene(t,n[t]),this._createThumb(t)}t.activeFirstPage()}}_createThumb(e){this._renderManagerService.createRender(e)}_getCurrUnitModel(){return this._renderContext.unit}activePage(e){let t=e,n=this._getCurrUnitModel(),r;if(t)r=n.getPage(t);else{let e=n.getPages(),i=n.getPageOrder();if(i==null||e==null)return;r=e[i[0]],t=r.id}let i=this._currentRender();if(r==null||i==null||i.mainComponent==null)return;let{id:a}=r,o=i.mainComponent;if(n.setActivePage(r),o!=null&&o.hasPage(a)){o.changePage(a);return}this.createPageScene(a,r)}createThumbs(){let e=this._getCurrUnitModel().getPageOrder(),t=this._currentRender();if(!(!e||!t)&&e.length!==0)for(let n=0,r=e.length;n<r;n++){let r=e[n];this._thumbSceneRender(r,t.mainComponent)}}createPageScene(e,n){let r=this._renderContext;if(!r||!this._objectProvider)return;let{scene:i,mainComponent:a}=r,o=a,{width:s,height:c}=o,l=new t.Scene(e,o,{width:s,height:c});new t.Viewport(`PageViewer_${e}`,l,{left:0,top:0,bottom:0,right:0,explicitViewportWidthSet:!1,explicitViewportHeightSet:!1}).closeClip();let{pageElements:u,pageBackgroundFill:d}=n,f=this._objectProvider.convertToRenderObjects(u,i);if(!f||!o)return;this._addBackgroundRect(l,d),l.addObjects(f),l.initTransformer(),f.forEach(e=>{l.attachTransformerTo(e)});let p=l.getTransformer();return p==null||p.changeEnd$.subscribe(()=>{this._thumbSceneRender(e,o)}),p==null||p.clearControl$.subscribe(()=>{this._thumbSceneRender(e,o)}),o.addPageScene(l),l}getPageRenderUnit(e){let t=this._renderContext.mainComponent.getSubScenes().get(e),{engine:n,unit:r}=this._renderContext;return{scene:t,engine:n,unit:r}}createObjectToPage(e,t){let{scene:n}=this.getPageRenderUnit(t);if(!n||!this._objectProvider)return;let r=this._objectProvider.convertToRenderObject(e,n);if(r)return n.addObject(r),n.attachTransformerTo(r),n.getLayer().makeDirty(),r}setObjectActiveByPage(e,t){let{scene:n}=this.getPageRenderUnit(t);if(!n)return;let r=n.getTransformer();r==null||r.activeAnObject(e)}removeObjectById(e,t){let{scene:n}=this.getPageRenderUnit(t);if(!n)return;n.removeObject(e);let r=n.getTransformer();r==null||r.clearControls()}appendPage(){let e=this._getCurrUnitModel(),t=e.getBlankPage(),n=this._currentRender();if(t==null||n==null||n.mainComponent==null)return;let{id:r}=t,i=n.mainComponent,a=this.createPageScene(r,t);i&&a&&i.addPageScene(a),e.appendPage(t),e.setActivePage(t)}};v=_([g(1,(0,e.Inject)(e.Injector)),g(2,e.IUniverInstanceService),g(3,t.IRenderManagerService)],v);let y=class extends e.RxDisposable{constructor(e){super(),this._renderManagerService=e}_getSlideRenderControllerFromRenderUnit(e){return this._renderManagerService.getRenderById(e).with(v)}createThumbs(e){this._getSlideRenderControllerFromRenderUnit(e).createThumbs()}activePage(e,t){this._getSlideRenderControllerFromRenderUnit(t).activePage(e)}getRenderUnitByPageId(e,t){return this._getSlideRenderControllerFromRenderUnit(t).getPageRenderUnit(e)}createObjectToPage(e,t,n){return this._getSlideRenderControllerFromRenderUnit(n).createObjectToPage(e,t)}setObjectActiveByPage(e,t,n){return this._getSlideRenderControllerFromRenderUnit(n).setObjectActiveByPage(e,t)}removeObjectById(e,t,n){this._getSlideRenderControllerFromRenderUnit(n).removeObjectById(e,t)}appendPage(e){this._getSlideRenderControllerFromRenderUnit(e).appendPage()}};y=_([g(0,t.IRenderManagerService)],y);const b={id:`slide.operation.activate-slide`,type:e.CommandType.OPERATION,handler:(t,n)=>{var r,i;let a=n.unitId,o=t.get(y),s=t.get(e.IUniverInstanceService).getUnit(a),c=s==null||(r=s.getActivePage())==null?void 0:r.id;if(!c)return!1;let l=o.getRenderUnitByPageId(c,a);if(!l)return!1;let u=(i=l.scene)==null?void 0:i.getTransformer();return u&&u.clearControls(),o.activePage(n.id,a),!0}},x={id:`slide.operation.append-slide`,type:e.CommandType.OPERATION,handler:(t,n)=>{let r=n.unitId;return t.get(e.IUniverInstanceService).getUnit(r)?(t.get(y).appendPage(r),!0):!1}},S={id:`slide.operation.delete-element`,type:e.CommandType.OPERATION,handler:(t,n)=>{if(!(n!=null&&n.id))return!1;let r=n.unitId,i=t.get(e.IUniverInstanceService).getUnit(r);if(!i)return!1;let a=i.getActivePage();return delete a.pageElements[n.id],i.updatePage(a.id,a),t.get(y).removeObjectById(n.id,a.id,r),!0}},C={id:`slide.command.insert-float-image`,type:e.CommandType.COMMAND,handler:async(t,n)=>{var a;let o=t.get(e.IUniverInstanceService),s=(a=o.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE))==null?void 0:a.getUnitId();if(!s)return!1;let c=await t.get(i.ILocalFileService).openFile({multiple:!0,accept:r.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)});if(c.length!==1)return!1;let l=await t.get(r.IImageIoService).saveImage(c[0]);if(!l)return!1;let{imageId:u,imageSourceType:d,source:f,base64Cache:p}=l,{width:m,height:h,image:g}=await(0,r.getImageSize)(p||``),_=o.getUnit(s);if(!_)return!1;let v=_.getActivePage(),b=Object.values(v.pageElements),x={id:u,zIndex:(b!=null&&b.length?Math.max(...b.map(e=>e.zIndex)):20)+1,left:0,top:0,width:m,height:h,title:``,description:``,type:e.PageElementType.IMAGE,image:{imageProperties:{contentUrl:p,imageSourceType:d,source:f,base64Cache:p,image:g}}};v.pageElements[u]=x,_.updatePage(v.id,v);let S=t.get(y),C=S.createObjectToPage(x,v.id,s);return C&&S.setObjectActiveByPage(C,v.id,s),!0}},w={id:`slide.operation.update-element`,type:e.CommandType.OPERATION,handler:(t,n)=>{let{oKey:r,props:i}=n,a=t.get(e.IUniverInstanceService),o=n==null?void 0:n.unitId,s=a.getUnit(o);if(!s)return!1;let c=s.getActivePage();return c.pageElements[r]=(0,e.merge)(c.pageElements[r],i),s.updatePage(c.id,c),!0}};var T=function(e){return e[e.forward=0]=`forward`,e[e.backward=1]=`backward`,e[e.front=2]=`front`,e[e.back=3]=`back`,e}(T||{});function E(t){let{pageId:n,unitId:r}=t,c=(0,i.useDependency)(e.LocaleService),l=(0,i.useDependency)(y),u=(0,i.useDependency)(e.ICommandService),d=l.getRenderUnitByPageId(n,r),f=d==null?void 0:d.scene;if(!f)return null;let p=f.getTransformer();if(!p)return null;let m=p.getSelectedObjectMap().values().next().value;if(!m)return null;let h=e=>{let[t,n]=f.getAllObjects().reduce(([e,t],n)=>{let r=n.zIndex;return[r<e?r:e,r>t?r:t]},[0,0]),i=m.zIndex;e===T.back?i=t-1:e===T.front?i=n+1:e===T.forward?i=m.zIndex+1:e===T.backward&&(i=m.zIndex-1),m.setProps({zIndex:i}),u.executeCommand(w.id,{unitId:r,oKey:m==null?void 0:m.oKey,props:{zIndex:i}})};return(0,s.jsxs)(`div`,{className:`univer-relative univer-w-full`,children:[(0,s.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,s.jsx)(`div`,{className:`univer-w-full univer-text-left univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,s.jsx)(`div`,{children:c.t(`image-panel.arrange.title`)})})}),(0,s.jsxs)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:[(0,s.jsx)(`div`,{className:`univer-w-1/2`,children:(0,s.jsx)(a.Button,{onClick:()=>{h(T.forward)},children:(0,s.jsxs)(`span`,{className:`univer-flex univer-items-center univer-gap-1`,children:[(0,s.jsx)(o.MoveUpIcon,{}),c.t(`image-panel.arrange.forward`)]})})}),(0,s.jsx)(`div`,{className:`univer-w-1/2`,children:(0,s.jsx)(a.Button,{onClick:()=>{h(T.backward)},children:(0,s.jsxs)(`span`,{className:`univer-flex univer-items-center univer-gap-1`,children:[(0,s.jsx)(o.MoveDownIcon,{}),c.t(`image-panel.arrange.backward`)]})})})]}),(0,s.jsxs)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:[(0,s.jsx)(`div`,{className:`univer-w-1/2`,children:(0,s.jsx)(a.Button,{onClick:()=>{h(T.front)},children:(0,s.jsxs)(`span`,{className:`univer-flex univer-items-center univer-gap-1`,children:[(0,s.jsx)(o.TopmostIcon,{}),c.t(`image-panel.arrange.front`)]})})}),(0,s.jsx)(`div`,{className:`univer-w-1/2`,children:(0,s.jsx)(a.Button,{onClick:()=>{h(T.back)},children:(0,s.jsxs)(`span`,{className:`univer-flex univer-items-center univer-gap-1`,children:[(0,s.jsx)(o.BottomIcon,{}),c.t(`image-panel.arrange.back`)]})})})]})]})}function D(t){var n,r;let{pageId:l,unitId:u}=t,d=(0,i.useDependency)(e.LocaleService),f=(0,i.useDependency)(y),p=(0,i.useDependency)(e.ICommandService),m=f.getRenderUnitByPageId(l,u),h=m==null?void 0:m.scene;if(!h)return null;let g=h.getTransformer();if(!g)return null;let _=g.getSelectedObjectMap().values().next().value;if(!_)return null;let[v,b]=(0,c.useState)((n=(r=_.fill)==null?void 0:r.toString())==null?``:n);function x(e){_==null||_.setProps({fill:e}),p.executeCommand(w.id,{unitId:u,oKey:_==null?void 0:_.oKey,props:{shape:{shapeProperties:{shapeBackgroundFill:{rgb:e}}}}}),b(e)}return(0,s.jsx)(`div`,{className:(0,a.clsx)(`univer-relative univer-bottom-0 univer-mt-5 univer-w-full`,a.borderTopClassName),children:(0,s.jsxs)(`div`,{className:`univer-relative univer-w-full`,children:[(0,s.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,s.jsx)(`div`,{className:`univer-w-full univer-text-left univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,s.jsx)(`div`,{children:d.t(`slide.panel.fill.title`)})})}),(0,s.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,s.jsx)(`div`,{className:`univer-w-1/2`,children:(0,s.jsx)(a.Dropdown,{overlay:(0,s.jsx)(`div`,{className:`univer-rounded-lg univer-p-4`,children:(0,s.jsx)(a.ColorPicker,{value:`#fff`,onChange:x})}),children:(0,s.jsxs)(`a`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-1`,children:[(0,s.jsx)(o.PaintBucketDoubleIcon,{className:`univer-fill-primary-600`}),(0,s.jsx)(o.MoreDownIcon,{})]})})})})]})})}function O(t){let{pageId:n,unitId:r}=t,o=(0,i.useDependency)(e.LocaleService),l=(0,i.useDependency)(y),u=(0,i.useDependency)(e.ICommandService),d=l.getRenderUnitByPageId(n,r),f=d==null?void 0:d.scene;if(!f)return null;let p=f.getTransformer();if(!p)return null;let m=p.getSelectedObjectMap().values().next().value;if(!m)return null;let{width:h=0,height:g=0,left:_=0,top:v=0,angle:b=0}=m,[x,S]=(0,c.useState)(h),[C,T]=(0,c.useState)(g),[E,D]=(0,c.useState)(_),[O,k]=(0,c.useState)(v),[A,j]=(0,c.useState)(b),M=e=>{let{objects:t}=e,{width:n=0,height:r=0,left:i=0,top:a=0,angle:o=0}=t.values().next().value;S(n),T(r),D(i),k(a),j(o)};(0,c.useEffect)(()=>{let e=p.changeStart$.subscribe(e=>{M(e)}),t=p.changing$.subscribe(e=>{M(e)});return()=>{t.unsubscribe(),e.unsubscribe()}},[]);function N(e){!e||!m||(u.executeCommand(w.id,{pageId:n,oKey:m.oKey,props:{width:e}}),m==null||m.resize(e,m.height),S(e),p==null||p.refreshControls())}function P(e){!e||!m||(u.executeCommand(w.id,{pageId:n,oKey:m.oKey,props:{height:e}}),m==null||m.resize(m.width,e),T(e),p==null||p.refreshControls())}function F(e){!e||!m||(u.executeCommand(w.id,{pageId:n,oKey:m.oKey,props:{left:e}}),m==null||m.translate(e,m.top),D(e),p==null||p.refreshControls())}function I(e){!e||!m||(u.executeCommand(w.id,{pageId:n,oKey:m.oKey,props:{right:e}}),m==null||m.translate(m.left,e),k(e),p==null||p.refreshControls())}function L(e){!e||!m||(u.executeCommand(w.id,{pageId:n,oKey:m.oKey,props:{angle:e}}),m==null||m.transformByState({angle:e}),j(e),p==null||p.refreshControls())}return(0,s.jsxs)(`div`,{className:(0,a.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,a.borderTopClassName),children:[(0,s.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,s.jsx)(`div`,{children:o.t(`image-panel.transform.title`)})}),(0,s.jsxs)(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{children:o.t(`image-panel.transform.width`)}),(0,s.jsx)(a.InputNumber,{min:1,value:x,onChange:e=>{N(e)}})]}),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{children:o.t(`image-panel.transform.height`)}),(0,s.jsx)(a.InputNumber,{min:1,value:C,onChange:e=>{P(e)}})]})]}),(0,s.jsxs)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{children:o.t(`image-panel.transform.x`)}),(0,s.jsx)(a.InputNumber,{min:0,precision:1,value:E,onChange:e=>{F(e)}})]}),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{children:o.t(`image-panel.transform.y`)}),(0,s.jsx)(a.InputNumber,{min:0,precision:1,value:O,onChange:e=>{I(e)}})]}),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`span`,{children:o.t(`image-panel.transform.rotate`)}),(0,s.jsx)(a.InputNumber,{precision:1,value:A,onChange:L})]})]})]})}const k=`COMPONENT_SLIDE_SIDEBAR`;function A(){var n,r,a;let o=(0,i.useDependency)(e.IUniverInstanceService),c=(0,i.useDependency)(y),l=o.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE),u=l==null||(n=l.getActivePage())==null?void 0:n.id,d=((r=o.getFocusedUnit())==null?void 0:r.getUnitId())||``;if(!u||!d)return null;let f=(a=c.getRenderUnitByPageId(u,d).scene)==null?void 0:a.getTransformer();if(!f)return null;let p=f.getSelectedObjectMap().values().next().value;return p?(0,s.jsxs)(`section`,{className:`univer-p-2 univer-text-center univer-text-sm`,children:[(0,s.jsx)(E,{pageId:u,unitId:d}),(0,s.jsx)(O,{pageId:u,unitId:d}),p.objectType===t.ObjectType.RECT&&(0,s.jsx)(D,{pageId:u,unitId:d})]}):null}const j={id:`slide.command.insert-float-shape.rectangle`,type:e.CommandType.COMMAND,handler:async t=>{var n;let r=t.get(e.ICommandService),i=(n=t.get(e.IUniverInstanceService).getFocusedUnit())==null?void 0:n.getUnitId();return r.executeCommand(M.id,{unitId:i})}},M={id:`slide.operation.insert-float-shape.rectangle`,type:e.CommandType.OPERATION,handler:async(t,n)=>{let r=(0,e.generateRandomId)(6),i=t.get(e.IUniverInstanceService),a=n.unitId,o=i.getUnit(a);if(!o)return!1;let s=o.getActivePage(),c=Object.values(s.pageElements),l={id:r,zIndex:(c!=null&&c.length?Math.max(...c.map(e=>e.zIndex)):20)+1,left:378,top:142,width:250,height:250,title:r,description:``,type:e.PageElementType.SHAPE,shape:{shapeType:e.BasicShapes.Rect,text:``,shapeProperties:{shapeBackgroundFill:{rgb:`rgb(0,0,255)`}}}};s.pageElements[r]=l,o.updatePage(s.id,s);let u=t.get(y),d=u.createObjectToPage(l,s.id,a);return d&&u.setObjectActiveByPage(d,s.id,a),!0}},N={id:`sidebar.operation.slide-shape`,type:e.CommandType.COMMAND,handler:async(n,r)=>{let{visible:a,objectType:o}=r,s=n.get(i.ISidebarService),c=n.get(e.LocaleService),l=``,u=``;return o===t.ObjectType.RECT?(l=`slide.sidebar.shape`,u=k):o===t.ObjectType.IMAGE?(l=`slide.sidebar.image`,u=k):o===t.ObjectType.RICH_TEXT&&(l=`slide.sidebar.text`,u=k),a?s.open({header:{title:c.t(l)},children:{label:u},onClose:()=>{},width:360}):s.close(),!0}},P={id:`slide.command.insert-float-shape.ellipse`,type:e.CommandType.COMMAND,handler:async t=>{var n;let r=t.get(e.ICommandService),i=(n=t.get(e.IUniverInstanceService).getFocusedUnit())==null?void 0:n.getUnitId();return r.executeCommand(F.id,{unitId:i})}},F={id:`slide.operation.insert-float-shape.ellipse`,type:e.CommandType.OPERATION,handler:async(t,n)=>{let r=(0,e.generateRandomId)(6),i=t.get(e.IUniverInstanceService),a=n.unitId,o=i.getUnit(a);if(!o)return!1;let s=o.getActivePage(),c=Object.values(s.pageElements),l={id:r,zIndex:(c!=null&&c.length?Math.max(...c.map(e=>e.zIndex)):20)+1,left:378,top:142,width:250,height:250,title:r,description:``,type:e.PageElementType.SHAPE,shape:{shapeType:e.BasicShapes.Ellipse,text:``,shapeProperties:{radius:100,shapeBackgroundFill:{rgb:`rgb(0,0,255)`}}}};s.pageElements[r]=l,o.updatePage(s.id,s);let u=t.get(y),d=u.createObjectToPage(l,s.id,a);return d&&u.setObjectActiveByPage(d,s.id,a),!0}},I={id:`slide.command.add-text`,type:e.CommandType.COMMAND,handler:async t=>{var n;let r=t.get(e.ICommandService),i=(n=t.get(e.IUniverInstanceService).getFocusedUnit())==null?void 0:n.getUnitId();return await r.executeCommand(L.id,{unitId:i})}},L={id:`slide.operation.add-text`,type:e.CommandType.OPERATION,handler:async(t,n)=>{let r=n.unitId,i=(0,e.generateRandomId)(6),a=(n==null?void 0:n.text)||`A New Text`,o=t.get(e.IUniverInstanceService).getUnit(r);if(!o)return!1;let s=o.getActivePage(),c=Object.values(s.pageElements),l={id:i,zIndex:(c!=null&&c.length?Math.max(...c.map(e=>e.zIndex)):21)+1,left:230,top:142,width:220,height:40,title:`text`,description:``,type:e.PageElementType.TEXT,richText:{text:a,fs:30,cl:{rgb:`rgb(51, 51, 51)`},bl:1}};s.pageElements[i]=l,o.updatePage(s.id,s);let u=t.get(y),d=u.createObjectToPage(l,s.id,r);return d&&u.setObjectActiveByPage(d,s.id,r),!0}},ee={id:`slide.operation.set-slide-page-thumb`,type:e.CommandType.OPERATION,handler:(e,t)=>(e.get(y).createThumbs(t.unitId),!0)};function te(){var n,r;let o=(0,i.useDependency)(e.IUniverInstanceService),l=(0,i.useDependency)(e.ICommandService),u=(0,i.useDependency)(t.IRenderManagerService),d=(0,i.useDependency)(e.LocaleService),f=(0,c.useRef)(null),p=o.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE),m=p==null?void 0:p.getPages(),h=p==null?void 0:p.getPageOrder();if(!m||!h)return null;let g=h.map(e=>m[e]),[_,v]=(0,c.useState)((n=p==null||(r=p.getActivePage())==null?void 0:r.id)==null?null:n),y=(0,c.useMemo)(()=>g.map(()=>(0,c.createRef)()),[g]);(0,c.useEffect)(()=>{let e=p==null?void 0:p.activePage$.subscribe(e=>{var t;let n=(t=e==null?void 0:e.id)==null?null:t;n&&v(n)});return()=>{e==null||e.unsubscribe()}},[]),(0,c.useEffect)(()=>{y.forEach((e,t)=>{if(e.current){var n;let r=g[t];(n=u.getRenderById(r.id))==null||n.engine.setContainer(e.current)}}),y.length>0&&l.syncExecuteCommand(ee.id,{unitId:p==null?void 0:p.getUnitId()})},[y,g,u,l,p]);let S=(0,c.useCallback)(e=>{l.syncExecuteCommand(b.id,{id:e,unitId:p==null?void 0:p.getUnitId()})},[l,p]),C=(0,c.useCallback)(()=>{l.syncExecuteCommand(x.id,{unitId:p==null?void 0:p.getUnitId()})},[l,p]);return(0,s.jsx)(`aside`,{ref:f,className:(0,a.clsx)(`univer-flex univer-h-full univer-w-64 univer-flex-col univer-overflow-y-auto univer-overflow-x-hidden`,a.scrollbarClassName),children:(0,s.jsxs)(`div`,{className:`univer-px-4`,children:[(0,s.jsx)(`header`,{className:`univer-flex univer-justify-center univer-pt-4`,children:(0,s.jsx)(`a`,{className:(0,a.clsx)(`univer-box-border univer-block univer-h-8 univer-w-full univer-cursor-pointer univer-rounded-md univer-bg-white univer-text-center univer-text-sm univer-leading-8 univer-transition-colors`,a.borderClassName),onClick:C,children:d.t(`slide.append`)})}),g.map((e,t)=>(0,s.jsxs)(`div`,{className:(0,a.clsx)(`univer-my-4 univer-flex univer-gap-2`,{"[&>div]:univer-border-primary-600 [&>span]:univer-text-primary-600":e.id===_}),onClick:()=>S(e.id),children:[(0,s.jsx)(`span`,{children:t+1}),(0,s.jsx)(`div`,{ref:y[t],className:(0,a.clsx)(`univer-relative univer-box-border univer-h-32 univer-w-52 univer-bg-white hover:univer-border-primary-600`,a.borderClassName)})]},e.id))]})})}const R=(0,e.createInternalEditorID)(`SLIDE_EDITOR`),z={id:`slide.operation.edit-arrow`,type:e.CommandType.OPERATION,handler:()=>!0},ne=`COMPONENT_SLIDE_IMAGE_POPUP_MENU`;function re(t){var n;let r=(n=t.popup)==null||(n=n.extraProps)==null?void 0:n.menuItems;if(!r)return null;let l=(0,i.useDependency)(e.ICommandService),u=(0,i.useDependency)(e.LocaleService),[d,f]=(0,c.useState)(!1),[p,m]=(0,c.useState)(!1),h=()=>{m(!0)},g=()=>{m(!1)},_=e=>{f(e)},v=e=>{l.executeCommand(e.commandId,e.commandParams),f(!1)},y=d||p,b=r.filter(e=>!e.disable);return(0,s.jsx)(`div`,{onMouseEnter:h,onMouseLeave:g,children:(0,s.jsx)(a.Dropdown,{align:`start`,overlay:(0,s.jsx)(`ul`,{className:(0,a.clsx)(`univer-m-0 univer-box-border univer-grid univer-list-none univer-items-center univer-gap-1 univer-rounded-lg univer-bg-white univer-p-1.5 univer-text-sm univer-shadow-lg`,a.borderClassName),children:b.map(e=>(0,s.jsx)(`li`,{className:`univer-relative univer-box-border univer-flex univer-h-8 univer-cursor-pointer univer-items-center univer-rounded univer-text-sm univer-transition-colors hover:univer-bg-gray-100`,onClick:()=>v(e),children:(0,s.jsx)(`span`,{className:`univer-px-2 univer-py-1.5 univer-align-middle`,children:u.t(e.label)})},e.index))}),open:d,onOpenChange:_,children:(0,s.jsxs)(`div`,{className:(0,a.clsx)(`univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800`,a.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":d,"univer-bg-white dark:!univer-bg-gray-900":!d}),children:[(0,s.jsx)(o.AutofillDoubleIcon,{className:`univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white`}),y&&(0,s.jsx)(o.MoreDownIcon,{className:`dark:!univer-text-white`})]})})})}const B=`slide.menu.image`;function ie(t){return{id:B,type:i.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`slide.image.insert.title`,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SLIDE)}}function ae(t){return{id:C.id,title:`slide.image.insert.float`,type:i.MenuItemType.BUTTON,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SLIDE)}}const V=`slide.menu.shape`;function oe(t){return{id:V,type:i.MenuItemType.SUBITEMS,icon:`GraphIcon`,tooltip:`slide.shape.insert.title`,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SLIDE)}}function se(t){return{id:j.id,title:`slide.shape.insert.rectangle`,type:i.MenuItemType.BUTTON,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SLIDE)}}function ce(t){return{id:P.id,title:`slide.shape.insert.ellipse`,type:i.MenuItemType.BUTTON,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SLIDE)}}function le(t){return{id:I.id,type:i.MenuItemType.BUTTON,icon:`TextIcon`,tooltip:`slide.text.insert.title`,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SLIDE)}}const ue={[i.RibbonStartGroup.FORMAT]:{[I.id]:{order:0,menuItemFactory:le},[B]:{order:0,menuItemFactory:ie,[C.id]:{order:0,menuItemFactory:ae}},[V]:{order:0,menuItemFactory:oe,[j.id]:{order:0,menuItemFactory:se},[P.id]:{order:0,menuItemFactory:ce}}}};var de=class{constructor(){h(this,`_state`,null),h(this,`_rect`,null),h(this,`_state$`,new u.BehaviorSubject(null)),h(this,`state$`,this._state$.asObservable()),h(this,`_rect$`,new u.BehaviorSubject(null)),h(this,`rect$`,this._rect$.asObservable()),h(this,`_focus`,!1),h(this,`_focus$`,new u.BehaviorSubject(this._focus)),h(this,`focus$`,this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(e){this._state=e,this._refresh(e)}getRect(){return this._rect}setRect(e){this._rect=e,this._rect$.next(e)}getState(){return this._state}setFocus(e=!1){this._focus=e,this._focus$.next(e)}_refresh(e){this._state$.next(e)}};const H=(0,e.createIdentifier)(`univer.slide-editor-manager.service`),U=-1e3,fe={width:0,height:0,top:U,left:U};function pe(){let[n,r]=(0,c.useState)({...fe}),o=(0,i.useDependency)(H),u=(0,i.useDependency)(l.IEditorService),d=(0,i.useDependency)(e.IContextService),f=(0,i.useObservable)(()=>d.subscribeContextValue$(i.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[d,i.DISABLE_AUTO_FOCUS_KEY]);return`${e.DEFAULT_EMPTY_DOCUMENT_VALUE}`,e.DocumentFlavor.UNSPECIFIED,(0,c.useEffect)(()=>{o.state$.subscribe(e=>{if(e==null)return;let{startX:n=U,startY:i=U,endX:a=0,endY:s=0,show:c=!1}=e;if(!c)r({...fe});else{r({width:a-n-t.FIX_ONE_PIXEL_BLUR_OFFSET+2,height:s-i-t.FIX_ONE_PIXEL_BLUR_OFFSET+2,left:n+t.FIX_ONE_PIXEL_BLUR_OFFSET,top:i+t.FIX_ONE_PIXEL_BLUR_OFFSET});let e=u.getEditor(R);if(e==null)return;let{left:c,top:l,width:d,height:f}=e.getBoundingClientRect();o.setRect({left:c,top:l,width:d,height:f})}})},[]),(0,c.useEffect)(()=>{f||o.setFocus(!0)},[f,n]),(0,s.jsx)(`div`,{className:(0,a.clsx)(`univer-absolute univer-z-10 univer-box-border univer-flex`,a.borderClassName),style:{left:n.left,top:n.top,width:n.width,height:n.height}})}function W(t){return t.getContextValue(e.FOCUSING_UNIVER_EDITOR)&&t.getContextValue(e.EDITOR_ACTIVATED)}function me(t){return t.getContextValue(e.FORMULA_EDITOR_ACTIVATED)&&t.getContextValue(e.FOCUSING_UNIVER_EDITOR)}const he=[i.KeyCode.ARROW_DOWN,i.KeyCode.ARROW_UP,i.KeyCode.ARROW_LEFT,i.KeyCode.ARROW_RIGHT];[i.KeyCode.ENTER,i.KeyCode.TAB,...he];function ge(){let e=[];for(let n of he)e.push({id:z.id,binding:n,preconditions:e=>W(e),staticParameters:{visible:!1,eventType:t.DeviceInputEventType.Keyboard,keycode:n,isShift:!1}}),e.push({id:z.id,binding:n|i.MetaKeys.SHIFT,preconditions:e=>W(e),staticParameters:{visible:!1,eventType:t.DeviceInputEventType.Keyboard,keycode:n,isShift:!0}});return e}const _e={id:l.DeleteLeftCommand.id,preconditions:e=>W(e)||me(e),binding:i.KeyCode.BACKSPACE};let G=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._injector=e,this._menuManagerService=t,this._componentManager=n,this._uiPartsService=r,this._commandService=i,this._shortcutService=a,this._initCommands(),this._initCustomComponents(),this._initUIComponents(),this._initMenus(),this._initShortcuts()}_initMenus(){this._menuManagerService.mergeMenu(ue)}_initCustomComponents(){let e=this._componentManager;this.disposeWithMe(e.register(`TextIcon`,o.TextIcon)),this.disposeWithMe(e.register(`GraphIcon`,o.GraphIcon)),this.disposeWithMe(e.register(ne,re)),this.disposeWithMe(e.register(k,A))}_initCommands(){[x,b,ee,C,L,I,P,F,M,j,N,S,w,z].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initUIComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(i.BuiltInUIPart.LEFT_SIDEBAR,()=>(0,i.connectInjector)(te,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(i.BuiltInUIPart.CONTENT,()=>(0,i.connectInjector)(pe,this._injector)))}_initShortcuts(){[_e,...ge()].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}};G=_([g(0,(0,e.Inject)(e.Injector)),g(1,i.IMenuManagerService),g(2,(0,e.Inject)(i.ComponentManager)),g(3,i.IUIPartsService),g(4,e.ICommandService),g(5,i.IShortcutService)],G);var ve=`@univerjs/slides-ui`,ye=`0.20.1`;const be=`slides-ui.config`;Symbol(be);const xe={},K=(0,e.createIdentifier)(`univer.slide-editor-bridge.service`);let q=class extends e.Disposable{constructor(e,n,r){super(),this._editorService=e,this._contextService=n,this._renderManagerService=r,h(this,`_editorUnitId`,R),h(this,`_isForceKeepVisible`,!1),h(this,`_editorIsDirty`,!1),h(this,`_currentEditRectState`,null),h(this,`_currentEditRectState$`,new u.BehaviorSubject(null)),h(this,`currentEditRectState$`,this._currentEditRectState$.asObservable()),h(this,`_visibleParam`,{visible:!1,eventType:t.DeviceInputEventType.Dblclick,unitId:``}),h(this,`_visible$`,new u.BehaviorSubject(this._visibleParam)),h(this,`visible$`,this._visible$.asObservable()),h(this,`_afterVisible$`,new u.BehaviorSubject(this._visibleParam)),h(this,`afterVisible$`,this._afterVisible$.asObservable()),h(this,`endEditing$`,new u.Subject),h(this,`_currentEditRectInfo`,void 0)}dispose(){super.dispose()}getEditorRect(){return this._currentEditRectInfo}setEditorRect(t){this._currentEditRectInfo=t,this._editorService.getFocusEditor()||(this._editorService.focus(R),this._contextService.setContextValue(e.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(e.FOCUSING_EDITOR_STANDALONE,!1),this._contextService.setContextValue(e.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE,!1));let n=this.getEditRectState();this._currentEditRectState=n,this._currentEditRectState$.next(n)}changeVisible(e){this._visibleParam=e,e.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visibleParam),this._afterVisible$.next(this._visibleParam)}getEditRectState(){let t=R,r=this._currentEditRectInfo,i=r.unitId,a=r.richTextObj.documentData;a.id=t,a.documentStyle={...a.documentStyle,pageSize:{width:r.richTextObj.width,height:1/0}};let o={documentModel:new e.DocumentDataModel(a),fontString:`document`,textRotation:{a:0,v:0},wrapStrategy:0,verticalAlign:e.VerticalAlign.TOP,horizontalAlign:e.HorizontalAlign.LEFT,paddingData:{t:0,b:1,l:2,r:2}},s=r.richTextObj.width,c=r.richTextObj.height,l=r.richTextObj.left,u=r.richTextObj.top,d={left:0,top:0},f=this._renderManagerService.getRenderById(i),p=f==null?void 0:f.scene,m=p==null?void 0:p.getViewport(n.SLIDE_KEY.VIEW),h=p==null?void 0:p.getObject(n.SLIDE_KEY.COMPONENT),g={x:(h==null?void 0:h.left)||0,y:(h==null?void 0:h.top)||0},_=(m==null?void 0:m.viewportScrollX)||0,v=(m==null?void 0:m.viewportScrollY)||0;return d.left=g.x-_,d.top=g.y-v,{position:{startX:l,startY:u,endX:l+s,endY:u+c},scaleX:1,scaleY:1,slideCardOffset:d,unitId:i,editorUnitId:t,documentLayoutObject:o}}changeEditorDirty(e){this._editorIsDirty=e}isVisible(){return this._visibleParam.visible}getEditorDirty(){return this._editorIsDirty}getCurrentEditorId(){return this._editorUnitId}genDocData(t){let n=this.getCurrentEditorId(),r=t.text,i=t.fs;return{id:n,body:{dataStream:`${r}\r\n`,textRuns:[{st:0,ed:r.length}],paragraphs:[{paragraphStyle:{},startIndex:r.length+1}],sectionBreaks:[{startIndex:r.length+2}]},documentStyle:{marginBottom:0,marginLeft:0,marginRight:0,marginTop:0,pageSize:{width:1/0,height:1/0},textStyle:{fs:i},renderConfig:{verticalAlign:e.VerticalAlign.MIDDLE,centerAngle:0,vertexAngle:0,wrapStrategy:0}},drawings:{},drawingsOrder:[],settings:{zoomRatio:1}}}};q=_([g(0,l.IEditorService),g(1,e.IContextService),g(2,t.IRenderManagerService)],q);let J=function(e){return e[e.InitialState=0]=`InitialState`,e[e.StartEditor=1]=`StartEditor`,e[e.CursorChange=2]=`CursorChange`,e}({});const Se=-1e3;let Y=class extends e.Disposable{constructor(n,r,a,o,s,c,l,u,d,f,p,m){super(),this._renderContext=n,this._layoutService=r,this._undoRedoService=a,this._contextService=o,this._instanceSrv=s,this._renderManagerService=c,this._editorBridgeService=l,this._cellEditorManagerService=u,this._textSelectionManagerService=d,this._commandService=f,this._localService=p,this._editorService=m,h(this,`_cursorChange`,J.InitialState),h(this,`_isUnitEditing`,!1),h(this,`_d`,void 0),this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SLIDE).subscribe(e=>{e&&e.getUnitId()===this._renderContext.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:t.DeviceInputEventType.Keyboard,keycode:i.KeyCode.ESC,unitId:this._renderContext.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){let t=new e.DisposableCollection;return this._subscribeToCurrentCell(t),this._initialKeyboardListener(t),this._initialCursorSync(t),this._listenEditorFocus(t),this._commandExecutedListener(t),setTimeout(()=>{this._cursorStateListener(t)},1e3),t}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){let t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{}))}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(d.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(d.DocSkeletonManagerService).getViewModel()}_initialCursorSync(n){n.add(this._cellEditorManagerService.focus$.pipe((0,u.filter)(e=>!!e)).subscribe(()=>{var n;(n=(0,t.getCurrentTypeOfRenderer)(e.UniverInstanceType.UNIVER_DOC,this._instanceSrv,this._renderManagerService))==null||n.with(l.DocSelectionRenderService).sync()}))}_subscribeToCurrentCell(n){n.add(this._editorBridgeService.currentEditRectState$.subscribe(n=>{var r;if(n==null||this._contextService.getContextValue(e.FOCUSING_EDITOR_STANDALONE)||this._contextService.getContextValue(e.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE))return;let{position:{startX:i,endX:a},documentLayoutObject:{textRotation:o,wrapStrategy:s,documentModel:c},scaleX:u,editorUnitId:d}=n,{vertexAngle:f}=(0,t.convertTextRotation)(o);c.updateDocumentId(d),s===e.WrapStrategy.WRAP&&f===0&&c.updateDocumentDataPageSize((a-i)/u),this._instanceSrv.changeDoc(d,c),this._contextService.setContextValue(e.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}]),(r=(0,t.getCurrentTypeOfRenderer)(e.UniverInstanceType.UNIVER_DOC,this._instanceSrv,this._renderManagerService))==null||r.with(l.DocSelectionRenderService).activate(Se,Se)}))}_fitTextSize(t,n,r,i,a=1,o=1){let{startX:s,startY:c,endX:l,endY:u}=t,d=i.documentModel;if(d==null)return;let{actualWidth:f,actualHeight:p}=this._predictingSize(t,n,r,i,a,o),{verticalAlign:m,paddingData:h,fill:g}=i,_=l-s,v=u-c;if(_<f&&(_=f),v<p)v=p,d.updateDocumentDataMargin(h);else{let t=0;t=m===e.VerticalAlign.MIDDLE?(v-p)/2/o:m===e.VerticalAlign.TOP?h.t||0:(v-p)/o-(h.b||0),t=t<(h.t||0)?h.t||0:t,d.updateDocumentDataMargin({t})}r.calculate(),this._editAreaProcessing(_,v,t,n,g,a,o)}_predictingSize(n,r,i,a,o=1,s=1){let{startX:c,endX:l}=n,{textRotation:u,wrapStrategy:d}=a,f=a.documentModel,{vertexAngle:p}=(0,t.convertTextRotation)(u),m=document.body.clientWidth;if(d===e.WrapStrategy.WRAP&&p===0){let{actualWidth:e,actualHeight:t}=i.getActualSize();return{actualWidth:e*o,actualHeight:t*s}}f==null||f.updateDocumentDataPageSize((m-c-r.left)/o),i.calculate();let h=i.getActualSize(),g=l-c;return g<h.actualWidth*o+5*o&&(g=h.actualWidth*o+5*o),f==null||f.updateDocumentDataPageSize(g/o),f==null||f.updateDocumentRenderConfig({horizontalAlign:e.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:g,actualHeight:h.actualHeight*s}}_editAreaProcessing(e,n,r,i,a,o=1,s=1){let c=this._getEditorObject();if(c==null)return;function u(e){return Number.parseInt(e.replace(`px`,``))}let d=this._renderContext.engine.getCanvasElement(),f=d.getBoundingClientRect(),p=u(d.style.width),{top:m,left:h,width:g}=f,_=g/p,{startX:v,startY:y}=r;v+=i.left,y+=i.top;let{document:b,scene:x,engine:S}=c,C=x.getViewport(l.VIEWPORT_KEY.VIEW_MAIN),w=document.body.clientHeight-y-i.top-4,T=document.body.clientWidth-v-i.left,E=n,D=C==null?void 0:C.getScrollBar();if(E>w)E=w,D==null?C&&new t.ScrollBar(C,{enableHorizontal:!1,barSize:8}):C==null||C.resetCanvasSizeAndUpdateScroll();else{var O;D=null,C==null||(O=C.getScrollBar())==null||O.dispose()}e+=(D==null?void 0:D.barSize)||0,e=Math.min(e,T),v-=t.FIX_ONE_PIXEL_BLUR_OFFSET,y-=t.FIX_ONE_PIXEL_BLUR_OFFSET,this._addBackground(x,e/o,n/s,a);let{scaleX:k,scaleY:A}=x.getPrecisionScale();x.transformByState({width:e*_/o,height:n*_/s,scaleX:o*_,scaleY:s*_}),b.resize(e/o,n/s),setTimeout(()=>{S.resizeBySize((0,t.fixLineWidthByScale)(e,k),(0,t.fixLineWidthByScale)(E,A))},0);let j=this._layoutService.getContentElement().getBoundingClientRect(),M=d.getBoundingClientRect();v=v*_+(M.left-j.left),y=y*_+(M.top-j.top),this._cellEditorManagerService.setState({startX:v,startY:y,endX:e*_+v,endY:E*_+y,show:!0})}_addBackground(e,n,r,i){let a=`_backgroundRectHelperColor_`,o=e.getObject(a);o==null&&i==null||(o==null?e.addObjects([new t.Rect(a,{width:n,height:r,fill:i,evented:!1})],l.DOCS_COMPONENT_MAIN_LAYER_INDEX):i==null?o.dispose():(o.setProps({fill:i}),o.transformByState({width:n,height:r})))}_handleEditorVisible(n){var r,i;let{eventType:a}=n;this._cursorChange=[t.DeviceInputEventType.PointerDown,t.DeviceInputEventType.Dblclick].includes(a)?J.CursorChange:J.StartEditor;let o=this._editorBridgeService.getEditRectState();if(o==null)return;let{position:s,documentLayoutObject:c,slideCardOffset:u,scaleX:d,scaleY:f,editorUnitId:p,unitId:m}=o,h=this._getEditorObject();if(h==null)return;let{scene:g}=h;this._contextService.setContextValue(e.EDITOR_ACTIVATED,!0);let{documentModel:_}=c,v=this._getEditorSkeleton(p);if(!v||!_)return;this._fitTextSize(s,u,v,c,d,f);let y=_.getBody().dataStream.length-2||0;(r=g.getViewport(l.VIEWPORT_KEY.VIEW_MAIN))==null||r.scrollToViewportPos({viewportScrollX:1/0}),this._textSelectionManagerService.replaceTextRanges([{startOffset:y,endOffset:y}]),(i=this._renderManagerService.getRenderById(m))==null||i.scene.resetCursor()}_resetBodyStyle(t,n=!1){t.dataStream=e.DEFAULT_EMPTY_DOCUMENT_VALUE,t.textRuns!=null&&(t.textRuns.length===1&&!n?(t.textRuns[0].st=0,t.textRuns[0].ed=1):t.textRuns=void 0),t.paragraphs!=null&&(t.paragraphs.length===1?t.paragraphs[0].startIndex=0:t.paragraphs=[{startIndex:0}]),t.sectionBreaks!=null&&(t.sectionBreaks=void 0),t.tables!=null&&(t.tables=void 0),t.customRanges!=null&&(t.customRanges=void 0),t.customBlocks!=null&&(t.customBlocks=void 0)}_initialKeyboardListener(e){}_showEditorByKeyboard(e){}_commandExecutedListener(e){let t=[z.id],n=[d.RichTextEditingMutation.id];e.add(this._commandService.onCommandExecuted(e=>{this._editorService.getFocusId()===R&&(t.includes(e.id)&&this._moveCursorCmdHandler(e),n.includes(e.id)&&this._editorBridgeService.isVisible()&&this._editingChangedHandler())}))}_moveCursorCmdHandler(e){let t=e.params,{keycode:n,isShift:r}=t;n!=null&&this._cursorChange===J.CursorChange?this._moveInEditor(n,r):this._editorBridgeService.changeVisible(t)}_editingChangedHandler(){let e=this._editorBridgeService.getEditorRect();if(!e)return;let t=e.richTextObj;t.refreshDocumentByDocData(),t.resizeToContentSize();let{unitId:n}=this._renderContext;this._handleEditorVisible({visible:!0,eventType:3,unitId:n})}_getEditorObject(){return Ce(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}async _handleEditorInvisible(e){let{keycode:t}=e;if(this._cursorChange=J.InitialState,this._exitInput(e),this._editorBridgeService.getEditRectState()!=null){if(this._editorBridgeService.getEditorDirty()===!1){this._moveCursor(t);return}this._moveCursor(t)}}_exitInput(t){this._contextService.setContextValue(e.EDITOR_ACTIVATED,!1),this._cellEditorManagerService.setState({show:t.visible});let n=this._editorBridgeService.getCurrentEditorId();n!=null&&this._undoRedoService.clearUndoRedo(n)}_moveCursor(t){if(t!=null)switch(e.Direction.LEFT,t){case i.KeyCode.ENTER:e.Direction.DOWN;break;case i.KeyCode.TAB:e.Direction.RIGHT;break;case i.KeyCode.ARROW_DOWN:e.Direction.DOWN;break;case i.KeyCode.ARROW_UP:e.Direction.UP;break;case i.KeyCode.ARROW_LEFT:e.Direction.LEFT;break;case i.KeyCode.ARROW_RIGHT:e.Direction.RIGHT;break}}_cursorStateListener(t){let n=this._getEditorObject();if(!n)return;let{document:r}=n;t.add((0,e.toDisposable)(r.onPointerDown$.subscribeEvent(()=>{this._cursorChange===J.StartEditor&&(this._cursorChange=J.CursorChange)})))}_moveInEditor(t,n){let r=e.Direction.LEFT;t===i.KeyCode.ARROW_DOWN?r=e.Direction.DOWN:t===i.KeyCode.ARROW_UP?r=e.Direction.UP:t===i.KeyCode.ARROW_RIGHT&&(r=e.Direction.RIGHT),n?this._commandService.executeCommand(l.MoveSelectionOperation.id,{direction:r}):this._commandService.executeCommand(l.MoveCursorOperation.id,{direction:r})}};Y=_([g(1,i.ILayoutService),g(2,e.IUndoRedoService),g(3,e.IContextService),g(4,e.IUniverInstanceService),g(5,t.IRenderManagerService),g(6,K),g(7,H),g(8,(0,e.Inject)(d.DocSelectionManagerService)),g(9,e.ICommandService),g(10,(0,e.Inject)(e.LocaleService)),g(11,l.IEditorService)],Y);function Ce(e,t){if(e==null)return;let n=t.getRenderById(e);if(n==null)return;let{mainComponent:r,scene:i,engine:a,components:o}=n;return{document:r,docBackground:o.get(l.DOCS_VIEW_KEY.BACKGROUND),scene:i,engine:a}}let we=class extends e.RxDisposable{constructor(t,n,r,i){super(),this._renderContext=t,this._instanceSrv=n,this._commandService=r,this._editorBridgeService=i,h(this,`setSlideTextEditor$`,new u.Subject),h(this,`_curRichText`,null),h(this,`_d`,void 0),this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SLIDE).subscribe(e=>{e&&e.getUnitId()===this._renderContext.unitId?this._d=this._init():this._disposeCurrent()}))}_init(){let t=new e.DisposableCollection;return this._initEventListener(t),t}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_setEditorRect(e,t){this._curRichText=t;let{scene:n,engine:r}=this._renderContext,i={scene:n,engine:r,unitId:this._renderContext.unitId,pageId:e,richTextObj:t};this._editorBridgeService.setEditorRect(i)}_initEventListener(e){let n=n=>{let r=n.getTransformer();r&&(e.add(r.clearControl$.subscribe(()=>{this.setEditorVisible(!1),this.pickOtherObjects()})),e.add(r.createControl$.subscribe(()=>{this.setEditorVisible(!1)})),e.add(n.onDblclick$.subscribeEvent(()=>{r.clearControls();let e=r.getSelectedObjectMap().values().next().value;e&&(e.objectType===t.ObjectType.RICH_TEXT?this.startEditing(n.sceneKey,e):this.pickOtherObjects())})),e.add(this._instanceSrv.focused$.subscribe(e=>{this.endEditing()})))},{mainComponent:r}=this._renderContext;r.subSceneChanged$.subscribeEvent(e=>{n(e)});let i=Array.from(r.getSubScenes().values());for(let e=0;e<i.length;e++){let t=i[e];n(t)}}pickOtherObjects(){this.endEditing()}endEditing(){var t;if(!this._curRichText)return;this.setEditorVisible(!1);let n=this._curRichText;if(!this._instanceSrv.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE))return!1;n.refreshDocumentByDocData(),n.resizeToContentSize(),this._editorBridgeService.endEditing$.next(n);let r={bl:1,fs:n.fs,text:n.text},i=(t=n.documentData.body)==null?void 0:t.textRuns;if(i&&i.length){let e=i[0].ts;r.cl=e==null?void 0:e.cl}this._commandService.executeCommand(w.id,{unitId:this._renderContext.unitId,oKey:n==null?void 0:n.oKey,props:{richText:r}}),this._curRichText=null}startEditing(e,t){this._setEditorRect(e,t),this.setEditorVisible(!0)}setEditorVisible(e){if(e){var n;(n=this._curRichText)==null||n.hide()}else{var r;(r=this._curRichText)==null||r.show()}let{unitId:i}=this._renderContext;this._editorBridgeService.changeVisible({visible:e,eventType:t.DeviceInputEventType.PointerDown,unitId:i})}};we=_([g(1,e.IUniverInstanceService),g(2,e.ICommandService),g(3,K)],we);function Te(e,t){let n=Ee(e.left,e.top,t),r=Ee(e.right,e.bottom,t);return{left:n.x,top:n.y,right:r.x,bottom:r.y}}function Ee(e,t,r){let{scaleX:i,scaleY:a}=r.getAncestorScale(),o=r.getViewport(n.SLIDE_KEY.VIEW);if(!o)return{x:e,y:t};let{viewportScrollX:s,viewportScrollY:c}=o;return{x:(e-s)*i,y:(t-c)*a}}let X=class extends e.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(n,r){let i=(()=>{var e,i,a,o;let{scene:s,engine:c}=r,{left:l,top:u,width:d,height:f}=n,p=(s.width-((e=(i=r.mainComponent)==null?void 0:i.width)==null?0:e))/2,m=(s.height-((a=(o=r.mainComponent)==null?void 0:o.height)==null?0:a))/2,h={left:l,right:l+d,top:u,bottom:u+f},g=c.getCanvasElement(),_=g.getBoundingClientRect(),v=(0,t.pxToNum)(g.style.width),{scaleX:y,scaleY:b}=s.getAncestorScale(),x=Te(h,s),{top:S,left:C,width:w}=_,T=w/v;return{left:x.left*T*y+C+p,right:x.right*T*y+C+p,top:x.top*T*b+S+m,bottom:x.bottom*T*b+S+m}})();return{position:i,position$:new u.BehaviorSubject(i),disposable:new e.DisposableCollection}}attachPopupToObject(t,n){let r=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE).getUnitId(),i=this._renderManagerService.getRenderById(r);if(!i)return{dispose:()=>{}};let{position:a,position$:o,disposable:s}=this._createObjectPositionObserver(t,i),c=this._globalPopupManagerService.addPopup({...n,unitId:r,subUnitId:`default`,anchorRect:a,anchorRect$:o,canvasElement:i.engine.getCanvasElement()});return{dispose:()=>{this._globalPopupManagerService.removePopup(c),o.complete(),s.dispose()}}}};X=_([g(0,(0,e.Inject)(i.ICanvasPopupService)),g(1,t.IRenderManagerService),g(2,e.IUniverInstanceService),g(3,e.ICommandService)],X);let Z=class extends e.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._contextService=r,this._canvasView=i,this._sidebarService=a,this._commandService=o,h(this,`_initImagePopupMenu`,new Set),this._init()}_init(){this._univerInstanceService.getAllUnitsForType(e.UniverInstanceType.UNIVER_SLIDE).forEach(e=>this._create(e))}_create(e){if(!e)return;let t=e.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(e){}_popupMenuListener(t){var n;let r=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE),i=(n=r==null?void 0:r.getPages())==null?{}:n;Object.keys(i).forEach(n=>{var r;let i=(r=this._canvasView.getRenderUnitByPageId(n,t).scene)==null?void 0:r.getTransformer();if(!i)return;let a;this.disposeWithMe((0,e.toDisposable)(i.createControl$.subscribe(()=>{let e=i.getSelectedObjectMap();if(e.size>1){a==null||a.dispose();return}let n=e.values().next().value;if(!n)return;let r=n.oKey;a==null||a.dispose(),a=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(n,{componentKey:ne,direction:`horizontal`,offset:[2,0],extraProps:{menuItems:this._getMenuItemsByObjectType(n.objectType,r,t)}})),this._sidebarService.visible&&this._commandService.executeCommand(N.id,{visible:!0,objectType:n.objectType})}))),this.disposeWithMe(i.clearControl$.subscribe(()=>{a==null||a.dispose(),this._contextService.setContextValue(e.FOCUSING_COMMON_DRAWINGS,!1)})),this.disposeWithMe(i.changing$.subscribe(()=>{a==null||a.dispose();let e=i.getSelectedObjectMap();if(e.size>1){a==null||a.dispose();return}let n=e.values().next().value;n&&this._commandService.executeCommand(w.id,{unitId:t,oKey:n.oKey,props:{width:n.width,height:n.height,left:n.left,top:n.top}})}))})}_getMenuItemsByObjectType(e,t,n){return[{label:`slide.popup.edit`,index:0,commandId:N.id,commandParams:{visible:!0,objectType:e},disable:!1},{label:`slide.popup.delete`,index:5,commandId:S.id,commandParams:{id:t,unitId:n},disable:!1}]}};Z=_([g(0,(0,e.Inject)(X)),g(1,t.IRenderManagerService),g(2,e.IUniverInstanceService),g(3,e.IContextService),g(4,(0,e.Inject)(y)),g(5,i.ISidebarService),g(6,e.ICommandService)],Z);let Q=class extends e.RxDisposable{constructor(e,t,n){super(),this._contextService=e,this._instanceSrv=t,this._renderManagerService=n,Promise.resolve().then(()=>this._init())}_init(){this._initSlideDataListener(),this._initContextListener()}_initSlideDataListener(){this._instanceSrv.getTypeOfUnitAdded$(e.UniverInstanceType.UNIVER_SLIDE).pipe((0,u.takeUntil)(this.dispose$)).subscribe(e=>{this._createRenderer(e==null?void 0:e.getUnitId())}),this._instanceSrv.getAllUnitsForType(e.UniverInstanceType.UNIVER_SLIDE).forEach(e=>{this._createRenderer(e.getUnitId())}),this._instanceSrv.getTypeOfUnitDisposed$(e.UniverInstanceType.UNIVER_SLIDE).pipe((0,u.takeUntil)(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(t){t!=null&&this._instanceSrv.getUnit(t,e.UniverInstanceType.UNIVER_SLIDE)!=null&&this._renderManagerService.createRender(t)}_disposeRenderer(e){let t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){}};Q=_([g(0,e.IContextService),g(1,e.IUniverInstanceService),g(2,t.IRenderManagerService)],Q);let $=class extends e.Plugin{constructor(t=xe,n,r,i,a){super(),this._config=t,this._injector=n,this._renderManagerService=r,this._univerInstanceService=i,this._configService=a;let{menu:o,...s}=(0,e.merge)({},xe,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(be,s)}onStarting(){(0,e.mergeOverrideWithDependencies)([[Q],[K,{useClass:q}],[H,{useClass:de}],[X]],this._config.override).forEach(e=>this._injector.add(e))}onReady(){[[v]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SLIDE,t))}),(0,e.mergeOverrideWithDependencies)([[y],[G],[v],[Z]],this._config.override).forEach(e=>{this._injector.add(e)}),this._injector.get(y),this._injector.get(Q)}onRendered(){[[we],[Y]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SLIDE,t))}),this._markSlideAsFocused(),this._injector.get(G)}onSteady(){this._injector.get(Z)}_markSlideAsFocused(){let t=this._univerInstanceService;try{let n=t.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SLIDE);t.focusUnit(n.getUnitId())}catch{}}};h($,`pluginName`,`UNIVER_SLIDES_UI_PLUGIN`),h($,`packageName`,ve),h($,`version`,ye),h($,`type`,e.UniverInstanceType.UNIVER_SLIDE),$=_([g(1,(0,e.Inject)(e.Injector)),g(2,t.IRenderManagerService),g(3,e.IUniverInstanceService),g(4,e.IConfigService)],$),exports.ActivateSlidePageOperation=b,exports.AppendSlideOperation=x,Object.defineProperty(exports,`CanvasView`,{enumerable:!0,get:function(){return y}}),exports.DeleteSlideElementOperation=S,exports.ISlideEditorBridgeService=K,exports.InsertSlideFloatImageCommand=C,exports.InsertSlideShapeEllipseCommand=P,exports.InsertSlideShapeEllipseOperation=F,exports.InsertSlideShapeRectangleCommand=j,exports.InsertSlideShapeRectangleOperation=M,exports.SHAPE_MENU_ID=V,exports.SLIDES_IMAGE_MENU_ID=B,exports.SLIDE_EDITOR_ID=R,exports.SetSlidePageThumbOperation=ee,exports.SlideAddTextCommand=I,exports.SlideAddTextOperation=L,Object.defineProperty(exports,`SlideCanvasPopMangerService`,{enumerable:!0,get:function(){return X}}),exports.SlideEditorContainer=pe,exports.SlideSideBar=te,Object.defineProperty(exports,`SlidesUIController`,{enumerable:!0,get:function(){return G}}),exports.SlidesUIMenuSchema=ue,Object.defineProperty(exports,`UniverSlidesUIPlugin`,{enumerable:!0,get:function(){return $}}),exports.UpdateSlideElementOperation=w;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
4
|
+
let _univerjs_slides = require("@univerjs/slides");
|
|
5
|
+
let _univerjs_drawing = require("@univerjs/drawing");
|
|
6
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
7
|
+
let _univerjs_design = require("@univerjs/design");
|
|
8
|
+
let _univerjs_icons = require("@univerjs/icons");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
let react = require("react");
|
|
11
|
+
let _univerjs_docs_ui = require("@univerjs/docs-ui");
|
|
12
|
+
let rxjs = require("rxjs");
|
|
13
|
+
let _univerjs_docs = require("@univerjs/docs");
|
|
14
|
+
|
|
15
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
16
|
+
function _typeof(o) {
|
|
17
|
+
"@babel/helpers - typeof";
|
|
18
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
19
|
+
return typeof o;
|
|
20
|
+
} : function(o) {
|
|
21
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
22
|
+
}, _typeof(o);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
27
|
+
function toPrimitive(t, r) {
|
|
28
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
29
|
+
var e = t[Symbol.toPrimitive];
|
|
30
|
+
if (void 0 !== e) {
|
|
31
|
+
var i = e.call(t, r || "default");
|
|
32
|
+
if ("object" != _typeof(i)) return i;
|
|
33
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
34
|
+
}
|
|
35
|
+
return ("string" === r ? String : Number)(t);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
40
|
+
function toPropertyKey(t) {
|
|
41
|
+
var i = toPrimitive(t, "string");
|
|
42
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
47
|
+
function _defineProperty(e, r, t) {
|
|
48
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
49
|
+
value: t,
|
|
50
|
+
enumerable: !0,
|
|
51
|
+
configurable: !0,
|
|
52
|
+
writable: !0
|
|
53
|
+
}) : e[r] = t, e;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
58
|
+
function __decorateParam(paramIndex, decorator) {
|
|
59
|
+
return function(target, key) {
|
|
60
|
+
decorator(target, key, paramIndex);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
66
|
+
function __decorate(decorators, target, key, desc) {
|
|
67
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
68
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
69
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
70
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/controllers/slide.render-controller.ts
|
|
75
|
+
let SlideRenderController = class SlideRenderController extends _univerjs_core.RxDisposable {
|
|
76
|
+
constructor(_renderContext, _injector, _univerInstanceService, _renderManagerService) {
|
|
77
|
+
super();
|
|
78
|
+
this._renderContext = _renderContext;
|
|
79
|
+
this._injector = _injector;
|
|
80
|
+
this._univerInstanceService = _univerInstanceService;
|
|
81
|
+
this._renderManagerService = _renderManagerService;
|
|
82
|
+
_defineProperty(this, "_objectProvider", null);
|
|
83
|
+
_defineProperty(this, "_refreshThumb", (0, _univerjs_core.debounce)(() => {
|
|
84
|
+
this.createThumbs();
|
|
85
|
+
}, 300));
|
|
86
|
+
this._objectProvider = this._injector.createInstance(_univerjs_slides.ObjectProvider);
|
|
87
|
+
this._addNewRender();
|
|
88
|
+
}
|
|
89
|
+
_addNewRender() {
|
|
90
|
+
const { unitId, engine, scene } = this._renderContext;
|
|
91
|
+
const slideDataModel = this._getCurrUnitModel();
|
|
92
|
+
if (!slideDataModel) return;
|
|
93
|
+
const observer = engine.onTransformChange$.subscribeEvent(() => {
|
|
94
|
+
this._scrollToCenter();
|
|
95
|
+
observer === null || observer === void 0 || observer.unsubscribe();
|
|
96
|
+
});
|
|
97
|
+
engine.onTransformChange$.subscribeEvent(() => {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
this.createThumbs();
|
|
100
|
+
}, 300);
|
|
101
|
+
});
|
|
102
|
+
const viewMain = new _univerjs_engine_render.Viewport(_univerjs_slides.SLIDE_KEY.VIEW, scene, {
|
|
103
|
+
left: 0,
|
|
104
|
+
top: 0,
|
|
105
|
+
bottom: 0,
|
|
106
|
+
right: 0,
|
|
107
|
+
explicitViewportWidthSet: false,
|
|
108
|
+
explicitViewportHeightSet: false,
|
|
109
|
+
isWheelPreventDefaultX: true
|
|
110
|
+
});
|
|
111
|
+
scene.attachControl();
|
|
112
|
+
scene.onMouseWheel$.subscribeEvent((evt, state) => {
|
|
113
|
+
const e = evt;
|
|
114
|
+
if (e.ctrlKey) {
|
|
115
|
+
const deltaFactor = Math.abs(e.deltaX);
|
|
116
|
+
let scrollNum = deltaFactor < 40 ? .2 : deltaFactor < 80 ? .4 : .2;
|
|
117
|
+
scrollNum *= e.deltaY > 0 ? -1 : 1;
|
|
118
|
+
if (scene.scaleX < 1) scrollNum /= 2;
|
|
119
|
+
if (scene.scaleX + scrollNum > 4) scene.scale(4, 4);
|
|
120
|
+
else if (scene.scaleX + scrollNum < .1) scene.scale(.1, .1);
|
|
121
|
+
else {
|
|
122
|
+
e.deltaY;
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
}
|
|
125
|
+
} else viewMain.onMouseWheel(e, state);
|
|
126
|
+
});
|
|
127
|
+
scene.onFileLoaded$.subscribeEvent(() => {
|
|
128
|
+
this._refreshThumb();
|
|
129
|
+
});
|
|
130
|
+
_univerjs_engine_render.ScrollBar.attachTo(viewMain);
|
|
131
|
+
const slide = this._createSlide(scene);
|
|
132
|
+
this._renderContext.mainComponent = slide;
|
|
133
|
+
this._createSlidePages(slideDataModel, slide);
|
|
134
|
+
this.createThumbs();
|
|
135
|
+
engine.runRenderLoop(() => {
|
|
136
|
+
scene.render();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
_scrollToCenter() {
|
|
140
|
+
var _this$_currentRender;
|
|
141
|
+
const mainScene = (_this$_currentRender = this._currentRender()) === null || _this$_currentRender === void 0 ? void 0 : _this$_currentRender.scene;
|
|
142
|
+
const viewMain = mainScene === null || mainScene === void 0 ? void 0 : mainScene.getViewport(_univerjs_slides.SLIDE_KEY.VIEW);
|
|
143
|
+
const getCenterPositionViewPort = this._getCenterPositionViewPort(mainScene);
|
|
144
|
+
if (!viewMain || !getCenterPositionViewPort) return;
|
|
145
|
+
const { left: viewPortLeft, top: viewPortTop } = getCenterPositionViewPort;
|
|
146
|
+
const { x, y } = viewMain.transViewportScroll2ScrollValue(viewPortLeft, viewPortTop);
|
|
147
|
+
viewMain.scrollToBarPos({
|
|
148
|
+
x,
|
|
149
|
+
y
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
_currentRender() {
|
|
153
|
+
return (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SLIDE, this._univerInstanceService, this._renderManagerService);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @param mainScene
|
|
157
|
+
*/
|
|
158
|
+
_createSlide(mainScene) {
|
|
159
|
+
const model = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE);
|
|
160
|
+
const { width: sceneWidth, height: sceneHeight } = mainScene;
|
|
161
|
+
const { width = 100, height = 100 } = model.getPageSize();
|
|
162
|
+
const slideComponent = new _univerjs_engine_render.Slide(_univerjs_slides.SLIDE_KEY.COMPONENT, {
|
|
163
|
+
left: (sceneWidth - width) / 2,
|
|
164
|
+
top: (sceneHeight - height) / 2,
|
|
165
|
+
width,
|
|
166
|
+
height,
|
|
167
|
+
zIndex: 10
|
|
168
|
+
});
|
|
169
|
+
slideComponent.enableSelectedClipElement();
|
|
170
|
+
mainScene.addObject(slideComponent);
|
|
171
|
+
return slideComponent;
|
|
172
|
+
}
|
|
173
|
+
_addBackgroundRect(scene, fill) {
|
|
174
|
+
const { width: pageWidth = 0, height: pageHeight = 0 } = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).getPageSize();
|
|
175
|
+
const page = new _univerjs_engine_render.Rect("canvas", {
|
|
176
|
+
left: 0,
|
|
177
|
+
top: 0,
|
|
178
|
+
width: pageWidth,
|
|
179
|
+
height: pageHeight,
|
|
180
|
+
strokeWidth: 1,
|
|
181
|
+
stroke: "rgba(198,198,198,1)",
|
|
182
|
+
fill: (0, _univerjs_core.getColorStyle)(fill) || "rgba(255,255,255,1)",
|
|
183
|
+
zIndex: 0,
|
|
184
|
+
evented: false
|
|
185
|
+
});
|
|
186
|
+
scene.addObject(page, 0);
|
|
187
|
+
}
|
|
188
|
+
_getCenterPositionViewPort(mainScene) {
|
|
189
|
+
if (!mainScene) return {
|
|
190
|
+
left: 0,
|
|
191
|
+
top: 0
|
|
192
|
+
};
|
|
193
|
+
const { width, height } = mainScene;
|
|
194
|
+
const engine = mainScene.getEngine();
|
|
195
|
+
const canvasWidth = (engine === null || engine === void 0 ? void 0 : engine.width) || 0;
|
|
196
|
+
const canvasHeight = (engine === null || engine === void 0 ? void 0 : engine.height) || 0;
|
|
197
|
+
return {
|
|
198
|
+
left: (width - canvasWidth) / 2,
|
|
199
|
+
top: (height - canvasHeight) / 2
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
_thumbSceneRender(pageId, slide) {
|
|
203
|
+
const render = this._renderManagerService.getRenderById(pageId);
|
|
204
|
+
if (render == null) return;
|
|
205
|
+
const { engine: thumbEngine } = render;
|
|
206
|
+
if (thumbEngine == null) return;
|
|
207
|
+
const { width, height } = slide;
|
|
208
|
+
const { width: pageWidth = width, height: pageHeight = height } = thumbEngine;
|
|
209
|
+
const thumbContext = thumbEngine.getCanvas().getContext();
|
|
210
|
+
slide.renderToThumb(thumbContext, pageId, pageWidth / width, pageHeight / height);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* CreateScene by pages, and activate first one.
|
|
214
|
+
* @param slideDataModel
|
|
215
|
+
* @param slide
|
|
216
|
+
*/
|
|
217
|
+
_createSlidePages(slideDataModel, slide) {
|
|
218
|
+
const pages = slideDataModel.getPages();
|
|
219
|
+
const pageOrder = slideDataModel.getPageOrder();
|
|
220
|
+
if (!pages || !pageOrder) return;
|
|
221
|
+
if (pageOrder.length === 0) return;
|
|
222
|
+
for (let i = 0, len = pageOrder.length; i < len; i++) {
|
|
223
|
+
const pageId = pageOrder[i];
|
|
224
|
+
this.createPageScene(pageId, pages[pageId]);
|
|
225
|
+
this._createThumb(pageId);
|
|
226
|
+
}
|
|
227
|
+
slide.activeFirstPage();
|
|
228
|
+
}
|
|
229
|
+
_createThumb(pageId) {
|
|
230
|
+
this._renderManagerService.createRender(pageId);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* SlideDataModel is UnitModel
|
|
234
|
+
*/
|
|
235
|
+
_getCurrUnitModel() {
|
|
236
|
+
return this._renderContext.unit;
|
|
237
|
+
}
|
|
238
|
+
activePage(_pageId) {
|
|
239
|
+
let pageId = _pageId;
|
|
240
|
+
const model = this._getCurrUnitModel();
|
|
241
|
+
let page;
|
|
242
|
+
if (pageId) page = model.getPage(pageId);
|
|
243
|
+
else {
|
|
244
|
+
const pageElements = model.getPages();
|
|
245
|
+
const pageOrder = model.getPageOrder();
|
|
246
|
+
if (pageOrder == null || pageElements == null) return;
|
|
247
|
+
page = pageElements[pageOrder[0]];
|
|
248
|
+
pageId = page.id;
|
|
249
|
+
}
|
|
250
|
+
const render = this._currentRender();
|
|
251
|
+
if (page == null || render == null || render.mainComponent == null) return;
|
|
252
|
+
const { id } = page;
|
|
253
|
+
const slide = render.mainComponent;
|
|
254
|
+
model.setActivePage(page);
|
|
255
|
+
if (slide === null || slide === void 0 ? void 0 : slide.hasPage(id)) {
|
|
256
|
+
slide.changePage(id);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this.createPageScene(id, page);
|
|
260
|
+
}
|
|
261
|
+
createThumbs() {
|
|
262
|
+
const pageOrder = this._getCurrUnitModel().getPageOrder();
|
|
263
|
+
const render = this._currentRender();
|
|
264
|
+
if (!pageOrder || !render) return;
|
|
265
|
+
if (pageOrder.length === 0) return;
|
|
266
|
+
for (let i = 0, len = pageOrder.length; i < len; i++) {
|
|
267
|
+
const pageId = pageOrder[i];
|
|
268
|
+
this._thumbSceneRender(pageId, render.mainComponent);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create scene by page and set to _sceneMap.
|
|
273
|
+
* @param pageId
|
|
274
|
+
* @param page
|
|
275
|
+
*/
|
|
276
|
+
createPageScene(pageId, page) {
|
|
277
|
+
const render = this._renderContext;
|
|
278
|
+
if (!render || !this._objectProvider) return;
|
|
279
|
+
const { scene: mainScene, mainComponent } = render;
|
|
280
|
+
const slide = mainComponent;
|
|
281
|
+
const { width, height } = slide;
|
|
282
|
+
const pageScene = new _univerjs_engine_render.Scene(pageId, slide, {
|
|
283
|
+
width,
|
|
284
|
+
height
|
|
285
|
+
});
|
|
286
|
+
new _univerjs_engine_render.Viewport(`PageViewer_${pageId}`, pageScene, {
|
|
287
|
+
left: 0,
|
|
288
|
+
top: 0,
|
|
289
|
+
bottom: 0,
|
|
290
|
+
right: 0,
|
|
291
|
+
explicitViewportWidthSet: false,
|
|
292
|
+
explicitViewportHeightSet: false
|
|
293
|
+
}).closeClip();
|
|
294
|
+
const { pageElements, pageBackgroundFill } = page;
|
|
295
|
+
const objects = this._objectProvider.convertToRenderObjects(pageElements, mainScene);
|
|
296
|
+
if (!objects || !slide) return;
|
|
297
|
+
this._addBackgroundRect(pageScene, pageBackgroundFill);
|
|
298
|
+
pageScene.addObjects(objects);
|
|
299
|
+
pageScene.initTransformer();
|
|
300
|
+
objects.forEach((object) => {
|
|
301
|
+
pageScene.attachTransformerTo(object);
|
|
302
|
+
});
|
|
303
|
+
const transformer = pageScene.getTransformer();
|
|
304
|
+
transformer === null || transformer === void 0 || transformer.changeEnd$.subscribe(() => {
|
|
305
|
+
this._thumbSceneRender(pageId, slide);
|
|
306
|
+
});
|
|
307
|
+
transformer === null || transformer === void 0 || transformer.clearControl$.subscribe(() => {
|
|
308
|
+
this._thumbSceneRender(pageId, slide);
|
|
309
|
+
});
|
|
310
|
+
slide.addPageScene(pageScene);
|
|
311
|
+
return pageScene;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get pageScene from Slide.
|
|
315
|
+
* @param pageId
|
|
316
|
+
* @returns {Scene, Engine, UnitModel} scene & engine & unit from renderContext
|
|
317
|
+
*/
|
|
318
|
+
getPageRenderUnit(pageId) {
|
|
319
|
+
const pageScene = this._renderContext.mainComponent.getSubScenes().get(pageId);
|
|
320
|
+
const { engine, unit } = this._renderContext;
|
|
321
|
+
return {
|
|
322
|
+
scene: pageScene,
|
|
323
|
+
engine,
|
|
324
|
+
unit
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
createObjectToPage(element, pageID) {
|
|
328
|
+
const { scene } = this.getPageRenderUnit(pageID);
|
|
329
|
+
if (!scene || !this._objectProvider) return;
|
|
330
|
+
const object = this._objectProvider.convertToRenderObject(element, scene);
|
|
331
|
+
if (object) {
|
|
332
|
+
scene.addObject(object);
|
|
333
|
+
scene.attachTransformerTo(object);
|
|
334
|
+
scene.getLayer().makeDirty();
|
|
335
|
+
return object;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
setObjectActiveByPage(obj, pageID) {
|
|
339
|
+
const { scene } = this.getPageRenderUnit(pageID);
|
|
340
|
+
if (!scene) return;
|
|
341
|
+
const transformer = scene.getTransformer();
|
|
342
|
+
transformer === null || transformer === void 0 || transformer.activeAnObject(obj);
|
|
343
|
+
}
|
|
344
|
+
removeObjectById(id, pageID) {
|
|
345
|
+
const { scene } = this.getPageRenderUnit(pageID);
|
|
346
|
+
if (!scene) return;
|
|
347
|
+
scene.removeObject(id);
|
|
348
|
+
const transformer = scene.getTransformer();
|
|
349
|
+
transformer === null || transformer === void 0 || transformer.clearControls();
|
|
350
|
+
}
|
|
351
|
+
appendPage() {
|
|
352
|
+
const model = this._getCurrUnitModel();
|
|
353
|
+
const page = model.getBlankPage();
|
|
354
|
+
const render = this._currentRender();
|
|
355
|
+
if (page == null || render == null || render.mainComponent == null) return;
|
|
356
|
+
const { id: pageId } = page;
|
|
357
|
+
const slide = render.mainComponent;
|
|
358
|
+
const scene = this.createPageScene(pageId, page);
|
|
359
|
+
if (slide && scene) slide.addPageScene(scene);
|
|
360
|
+
model.appendPage(page);
|
|
361
|
+
model.setActivePage(page);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
SlideRenderController = __decorate([
|
|
365
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
366
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
367
|
+
__decorateParam(3, _univerjs_engine_render.IRenderManagerService)
|
|
368
|
+
], SlideRenderController);
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/controllers/canvas-view.ts
|
|
372
|
+
let CanvasView = class CanvasView extends _univerjs_core.RxDisposable {
|
|
373
|
+
constructor(_renderManagerService) {
|
|
374
|
+
super();
|
|
375
|
+
this._renderManagerService = _renderManagerService;
|
|
376
|
+
}
|
|
377
|
+
_getSlideRenderControllerFromRenderUnit(unitId) {
|
|
378
|
+
return this._renderManagerService.getRenderById(unitId).with(SlideRenderController);
|
|
379
|
+
}
|
|
380
|
+
createThumbs(unitId) {
|
|
381
|
+
this._getSlideRenderControllerFromRenderUnit(unitId).createThumbs();
|
|
382
|
+
}
|
|
383
|
+
activePage(pageId, unitId) {
|
|
384
|
+
this._getSlideRenderControllerFromRenderUnit(unitId).activePage(pageId);
|
|
385
|
+
}
|
|
386
|
+
getRenderUnitByPageId(pageId, unitId) {
|
|
387
|
+
return this._getSlideRenderControllerFromRenderUnit(unitId).getPageRenderUnit(pageId);
|
|
388
|
+
}
|
|
389
|
+
createObjectToPage(element, pageID, unitId) {
|
|
390
|
+
return this._getSlideRenderControllerFromRenderUnit(unitId).createObjectToPage(element, pageID);
|
|
391
|
+
}
|
|
392
|
+
setObjectActiveByPage(obj, pageID, unitId) {
|
|
393
|
+
return this._getSlideRenderControllerFromRenderUnit(unitId).setObjectActiveByPage(obj, pageID);
|
|
394
|
+
}
|
|
395
|
+
removeObjectById(id, pageID, unitId) {
|
|
396
|
+
this._getSlideRenderControllerFromRenderUnit(unitId).removeObjectById(id, pageID);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* append blank page
|
|
400
|
+
*/
|
|
401
|
+
appendPage(unitId) {
|
|
402
|
+
this._getSlideRenderControllerFromRenderUnit(unitId).appendPage();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
CanvasView = __decorate([__decorateParam(0, _univerjs_engine_render.IRenderManagerService)], CanvasView);
|
|
406
|
+
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/commands/operations/activate.operation.ts
|
|
409
|
+
const ActivateSlidePageOperation = {
|
|
410
|
+
id: "slide.operation.activate-slide",
|
|
411
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
412
|
+
handler: (accessor, params) => {
|
|
413
|
+
var _model$getActivePage, _page$scene;
|
|
414
|
+
const unitId = params.unitId;
|
|
415
|
+
const canvasView = accessor.get(CanvasView);
|
|
416
|
+
const model = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
417
|
+
const pageId = model === null || model === void 0 || (_model$getActivePage = model.getActivePage()) === null || _model$getActivePage === void 0 ? void 0 : _model$getActivePage.id;
|
|
418
|
+
if (!pageId) return false;
|
|
419
|
+
const page = canvasView.getRenderUnitByPageId(pageId, unitId);
|
|
420
|
+
if (!page) return false;
|
|
421
|
+
const transformer = (_page$scene = page.scene) === null || _page$scene === void 0 ? void 0 : _page$scene.getTransformer();
|
|
422
|
+
if (transformer) transformer.clearControls();
|
|
423
|
+
canvasView.activePage(params.id, unitId);
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/commands/operations/append-slide.operation.ts
|
|
430
|
+
const AppendSlideOperation = {
|
|
431
|
+
id: "slide.operation.append-slide",
|
|
432
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
433
|
+
handler: (accessor, params) => {
|
|
434
|
+
const unitId = params.unitId;
|
|
435
|
+
if (!accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId)) return false;
|
|
436
|
+
accessor.get(CanvasView).appendPage(unitId);
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/commands/operations/delete-element.operation.ts
|
|
443
|
+
const DeleteSlideElementOperation = {
|
|
444
|
+
id: "slide.operation.delete-element",
|
|
445
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
446
|
+
handler: (accessor, params) => {
|
|
447
|
+
if (!(params === null || params === void 0 ? void 0 : params.id)) return false;
|
|
448
|
+
const unitId = params.unitId;
|
|
449
|
+
const slideData = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
450
|
+
if (!slideData) return false;
|
|
451
|
+
const activePage = slideData.getActivePage();
|
|
452
|
+
delete activePage.pageElements[params.id];
|
|
453
|
+
slideData.updatePage(activePage.id, activePage);
|
|
454
|
+
accessor.get(CanvasView).removeObjectById(params.id, activePage.id, unitId);
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/commands/operations/insert-image.operation.ts
|
|
461
|
+
const InsertSlideFloatImageCommand = {
|
|
462
|
+
id: "slide.command.insert-float-image",
|
|
463
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
464
|
+
handler: async (accessor, params) => {
|
|
465
|
+
var _univerInstanceServic;
|
|
466
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
467
|
+
const unitId = (_univerInstanceServic = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
|
|
468
|
+
if (!unitId) return false;
|
|
469
|
+
const files = await accessor.get(_univerjs_ui.ILocalFileService).openFile({
|
|
470
|
+
multiple: true,
|
|
471
|
+
accept: _univerjs_drawing.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
|
|
472
|
+
});
|
|
473
|
+
if (files.length !== 1) return false;
|
|
474
|
+
const imageParam = await accessor.get(_univerjs_drawing.IImageIoService).saveImage(files[0]);
|
|
475
|
+
if (!imageParam) return false;
|
|
476
|
+
const { imageId, imageSourceType, source, base64Cache } = imageParam;
|
|
477
|
+
const { width, height, image } = await (0, _univerjs_drawing.getImageSize)(base64Cache || "");
|
|
478
|
+
const slideData = univerInstanceService.getUnit(unitId);
|
|
479
|
+
if (!slideData) return false;
|
|
480
|
+
const activePage = slideData.getActivePage();
|
|
481
|
+
const elements = Object.values(activePage.pageElements);
|
|
482
|
+
const data = {
|
|
483
|
+
id: imageId,
|
|
484
|
+
zIndex: ((elements === null || elements === void 0 ? void 0 : elements.length) ? Math.max(...elements.map((element) => element.zIndex)) : 20) + 1,
|
|
485
|
+
left: 0,
|
|
486
|
+
top: 0,
|
|
487
|
+
width,
|
|
488
|
+
height,
|
|
489
|
+
title: "",
|
|
490
|
+
description: "",
|
|
491
|
+
type: _univerjs_slides.PageElementType.IMAGE,
|
|
492
|
+
image: { imageProperties: {
|
|
493
|
+
contentUrl: base64Cache,
|
|
494
|
+
imageSourceType,
|
|
495
|
+
source,
|
|
496
|
+
base64Cache,
|
|
497
|
+
image
|
|
498
|
+
} }
|
|
499
|
+
};
|
|
500
|
+
activePage.pageElements[imageId] = data;
|
|
501
|
+
slideData.updatePage(activePage.id, activePage);
|
|
502
|
+
const canvasView = accessor.get(CanvasView);
|
|
503
|
+
const sceneObject = canvasView.createObjectToPage(data, activePage.id, unitId);
|
|
504
|
+
if (sceneObject) canvasView.setObjectActiveByPage(sceneObject, activePage.id, unitId);
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/commands/operations/update-element.operation.ts
|
|
511
|
+
const UpdateSlideElementOperation = {
|
|
512
|
+
id: "slide.operation.update-element",
|
|
513
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
514
|
+
handler: (accessor, params) => {
|
|
515
|
+
const { oKey, props } = params;
|
|
516
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
517
|
+
const unitId = params === null || params === void 0 ? void 0 : params.unitId;
|
|
518
|
+
const slideData = univerInstanceService.getUnit(unitId);
|
|
519
|
+
if (!slideData) return false;
|
|
520
|
+
const activePage = slideData.getActivePage();
|
|
521
|
+
activePage.pageElements[oKey] = (0, _univerjs_core.merge)(activePage.pageElements[oKey], props);
|
|
522
|
+
slideData.updatePage(activePage.id, activePage);
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/components/panels/ArrangePanel.tsx
|
|
529
|
+
var ArrangeTypeEnum = /* @__PURE__ */ function(ArrangeTypeEnum) {
|
|
530
|
+
ArrangeTypeEnum[ArrangeTypeEnum["forward"] = 0] = "forward";
|
|
531
|
+
ArrangeTypeEnum[ArrangeTypeEnum["backward"] = 1] = "backward";
|
|
532
|
+
ArrangeTypeEnum[ArrangeTypeEnum["front"] = 2] = "front";
|
|
533
|
+
ArrangeTypeEnum[ArrangeTypeEnum["back"] = 3] = "back";
|
|
534
|
+
return ArrangeTypeEnum;
|
|
535
|
+
}(ArrangeTypeEnum || {});
|
|
536
|
+
function ArrangePanel$1(props) {
|
|
537
|
+
const { pageId, unitId } = props;
|
|
538
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
539
|
+
const canvasView = (0, _univerjs_ui.useDependency)(CanvasView);
|
|
540
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
541
|
+
const page = canvasView.getRenderUnitByPageId(pageId, unitId);
|
|
542
|
+
const scene = page === null || page === void 0 ? void 0 : page.scene;
|
|
543
|
+
if (!scene) return null;
|
|
544
|
+
const transformer = scene.getTransformer();
|
|
545
|
+
if (!transformer) return null;
|
|
546
|
+
const object = transformer.getSelectedObjectMap().values().next().value;
|
|
547
|
+
if (!object) return null;
|
|
548
|
+
const onArrangeBtnClick = (arrangeType) => {
|
|
549
|
+
const [minZIndex, maxZIndex] = scene.getAllObjects().reduce(([min, max], obj) => {
|
|
550
|
+
const zIndex = obj.zIndex;
|
|
551
|
+
return [zIndex < min ? zIndex : min, zIndex > max ? zIndex : max];
|
|
552
|
+
}, [0, 0]);
|
|
553
|
+
let zIndex = object.zIndex;
|
|
554
|
+
if (arrangeType === ArrangeTypeEnum.back) zIndex = minZIndex - 1;
|
|
555
|
+
else if (arrangeType === ArrangeTypeEnum.front) zIndex = maxZIndex + 1;
|
|
556
|
+
else if (arrangeType === ArrangeTypeEnum.forward) zIndex = object.zIndex + 1;
|
|
557
|
+
else if (arrangeType === ArrangeTypeEnum.backward) zIndex = object.zIndex - 1;
|
|
558
|
+
object.setProps({ zIndex });
|
|
559
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
560
|
+
unitId,
|
|
561
|
+
oKey: object === null || object === void 0 ? void 0 : object.oKey,
|
|
562
|
+
props: { zIndex }
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
566
|
+
className: "univer-relative univer-w-full",
|
|
567
|
+
children: [
|
|
568
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
569
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
570
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
571
|
+
className: "univer-w-full univer-text-left univer-text-gray-600 dark:!univer-text-gray-200",
|
|
572
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.arrange.title") })
|
|
573
|
+
})
|
|
574
|
+
}),
|
|
575
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
576
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
577
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
578
|
+
className: "univer-w-1/2",
|
|
579
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
580
|
+
onClick: () => {
|
|
581
|
+
onArrangeBtnClick(ArrangeTypeEnum.forward);
|
|
582
|
+
},
|
|
583
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
584
|
+
className: "univer-flex univer-items-center univer-gap-1",
|
|
585
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoveUpIcon, {}), localeService.t("image-panel.arrange.forward")]
|
|
586
|
+
})
|
|
587
|
+
})
|
|
588
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
589
|
+
className: "univer-w-1/2",
|
|
590
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
591
|
+
onClick: () => {
|
|
592
|
+
onArrangeBtnClick(ArrangeTypeEnum.backward);
|
|
593
|
+
},
|
|
594
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
595
|
+
className: "univer-flex univer-items-center univer-gap-1",
|
|
596
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoveDownIcon, {}), localeService.t("image-panel.arrange.backward")]
|
|
597
|
+
})
|
|
598
|
+
})
|
|
599
|
+
})]
|
|
600
|
+
}),
|
|
601
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
602
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
603
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
604
|
+
className: "univer-w-1/2",
|
|
605
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
606
|
+
onClick: () => {
|
|
607
|
+
onArrangeBtnClick(ArrangeTypeEnum.front);
|
|
608
|
+
},
|
|
609
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
610
|
+
className: "univer-flex univer-items-center univer-gap-1",
|
|
611
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.TopmostIcon, {}), localeService.t("image-panel.arrange.front")]
|
|
612
|
+
})
|
|
613
|
+
})
|
|
614
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
615
|
+
className: "univer-w-1/2",
|
|
616
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
617
|
+
onClick: () => {
|
|
618
|
+
onArrangeBtnClick(ArrangeTypeEnum.back);
|
|
619
|
+
},
|
|
620
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
621
|
+
className: "univer-flex univer-items-center univer-gap-1",
|
|
622
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.BottomIcon, {}), localeService.t("image-panel.arrange.back")]
|
|
623
|
+
})
|
|
624
|
+
})
|
|
625
|
+
})]
|
|
626
|
+
})
|
|
627
|
+
]
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/components/panels/FillPanel.tsx
|
|
633
|
+
/**
|
|
634
|
+
*
|
|
635
|
+
* @param props
|
|
636
|
+
*/
|
|
637
|
+
function ArrangePanel(props) {
|
|
638
|
+
var _object$fill$toString, _object$fill;
|
|
639
|
+
const { pageId, unitId } = props;
|
|
640
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
641
|
+
const canvasView = (0, _univerjs_ui.useDependency)(CanvasView);
|
|
642
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
643
|
+
const page = canvasView.getRenderUnitByPageId(pageId, unitId);
|
|
644
|
+
const scene = page === null || page === void 0 ? void 0 : page.scene;
|
|
645
|
+
if (!scene) return null;
|
|
646
|
+
const transformer = scene.getTransformer();
|
|
647
|
+
if (!transformer) return null;
|
|
648
|
+
const object = transformer.getSelectedObjectMap().values().next().value;
|
|
649
|
+
if (!object) return null;
|
|
650
|
+
const [color, setColor] = (0, react.useState)((_object$fill$toString = (_object$fill = object.fill) === null || _object$fill === void 0 ? void 0 : _object$fill.toString()) !== null && _object$fill$toString !== void 0 ? _object$fill$toString : "");
|
|
651
|
+
/**
|
|
652
|
+
*
|
|
653
|
+
* @param color
|
|
654
|
+
*/
|
|
655
|
+
function handleChangeColor(color) {
|
|
656
|
+
object === null || object === void 0 || object.setProps({ fill: color });
|
|
657
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
658
|
+
unitId,
|
|
659
|
+
oKey: object === null || object === void 0 ? void 0 : object.oKey,
|
|
660
|
+
props: { shape: { shapeProperties: { shapeBackgroundFill: { rgb: color } } } }
|
|
661
|
+
});
|
|
662
|
+
setColor(color);
|
|
663
|
+
}
|
|
664
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
665
|
+
className: (0, _univerjs_design.clsx)("univer-relative univer-bottom-0 univer-mt-5 univer-w-full", _univerjs_design.borderTopClassName),
|
|
666
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
667
|
+
className: "univer-relative univer-w-full",
|
|
668
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
669
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
670
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
671
|
+
className: "univer-w-full univer-text-left univer-text-gray-600 dark:!univer-text-gray-200",
|
|
672
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("slide.panel.fill.title") })
|
|
673
|
+
})
|
|
674
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
675
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
676
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
677
|
+
className: "univer-w-1/2",
|
|
678
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
679
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
680
|
+
className: "univer-rounded-lg univer-p-4",
|
|
681
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.ColorPicker, {
|
|
682
|
+
value: "#fff",
|
|
683
|
+
onChange: handleChangeColor
|
|
684
|
+
})
|
|
685
|
+
}),
|
|
686
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
|
|
687
|
+
className: "univer-flex univer-cursor-pointer univer-items-center univer-gap-1",
|
|
688
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PaintBucketDoubleIcon, { className: "univer-fill-primary-600" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
|
|
689
|
+
})
|
|
690
|
+
})
|
|
691
|
+
})
|
|
692
|
+
})]
|
|
693
|
+
})
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
//#endregion
|
|
698
|
+
//#region src/components/panels/TransformPanel.tsx
|
|
699
|
+
function TransformPanel(props) {
|
|
700
|
+
const { pageId, unitId } = props;
|
|
701
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
702
|
+
const canvasView = (0, _univerjs_ui.useDependency)(CanvasView);
|
|
703
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
704
|
+
const page = canvasView.getRenderUnitByPageId(pageId, unitId);
|
|
705
|
+
const scene = page === null || page === void 0 ? void 0 : page.scene;
|
|
706
|
+
if (!scene) return null;
|
|
707
|
+
const transformer = scene.getTransformer();
|
|
708
|
+
if (!transformer) return null;
|
|
709
|
+
const object = transformer.getSelectedObjectMap().values().next().value;
|
|
710
|
+
if (!object) return null;
|
|
711
|
+
const { width: originWidth = 0, height: originHeight = 0, left: originX = 0, top: originY = 0, angle: originRotation = 0 } = object;
|
|
712
|
+
const [width, setWidth] = (0, react.useState)(originWidth);
|
|
713
|
+
const [height, setHeight] = (0, react.useState)(originHeight);
|
|
714
|
+
const [xPosition, setXPosition] = (0, react.useState)(originX);
|
|
715
|
+
const [yPosition, setYPosition] = (0, react.useState)(originY);
|
|
716
|
+
const [rotation, setRotation] = (0, react.useState)(originRotation);
|
|
717
|
+
const changeObs = (state) => {
|
|
718
|
+
const { objects } = state;
|
|
719
|
+
const { width: originWidth = 0, height: originHeight = 0, left: originX = 0, top: originY = 0, angle: originRotation = 0 } = objects.values().next().value;
|
|
720
|
+
setWidth(originWidth);
|
|
721
|
+
setHeight(originHeight);
|
|
722
|
+
setXPosition(originX);
|
|
723
|
+
setYPosition(originY);
|
|
724
|
+
setRotation(originRotation);
|
|
725
|
+
};
|
|
726
|
+
(0, react.useEffect)(() => {
|
|
727
|
+
const changeStartSub = transformer.changeStart$.subscribe((state) => {
|
|
728
|
+
changeObs(state);
|
|
729
|
+
});
|
|
730
|
+
const changingSub = transformer.changing$.subscribe((state) => {
|
|
731
|
+
changeObs(state);
|
|
732
|
+
});
|
|
733
|
+
return () => {
|
|
734
|
+
changingSub.unsubscribe();
|
|
735
|
+
changeStartSub.unsubscribe();
|
|
736
|
+
};
|
|
737
|
+
}, []);
|
|
738
|
+
function handleWidthChange(val) {
|
|
739
|
+
if (!val || !object) return;
|
|
740
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
741
|
+
pageId,
|
|
742
|
+
oKey: object.oKey,
|
|
743
|
+
props: { width: val }
|
|
744
|
+
});
|
|
745
|
+
object === null || object === void 0 || object.resize(val, object.height);
|
|
746
|
+
setWidth(val);
|
|
747
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
748
|
+
}
|
|
749
|
+
function handleHeightChange(val) {
|
|
750
|
+
if (!val || !object) return;
|
|
751
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
752
|
+
pageId,
|
|
753
|
+
oKey: object.oKey,
|
|
754
|
+
props: { height: val }
|
|
755
|
+
});
|
|
756
|
+
object === null || object === void 0 || object.resize(object.width, val);
|
|
757
|
+
setHeight(val);
|
|
758
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
759
|
+
}
|
|
760
|
+
function handleXChange(val) {
|
|
761
|
+
if (!val || !object) return;
|
|
762
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
763
|
+
pageId,
|
|
764
|
+
oKey: object.oKey,
|
|
765
|
+
props: { left: val }
|
|
766
|
+
});
|
|
767
|
+
object === null || object === void 0 || object.translate(val, object.top);
|
|
768
|
+
setXPosition(val);
|
|
769
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
770
|
+
}
|
|
771
|
+
function handleYChange(val) {
|
|
772
|
+
if (!val || !object) return;
|
|
773
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
774
|
+
pageId,
|
|
775
|
+
oKey: object.oKey,
|
|
776
|
+
props: { right: val }
|
|
777
|
+
});
|
|
778
|
+
object === null || object === void 0 || object.translate(object.left, val);
|
|
779
|
+
setYPosition(val);
|
|
780
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
781
|
+
}
|
|
782
|
+
function handleChangeRotation(val) {
|
|
783
|
+
if (!val || !object) return;
|
|
784
|
+
commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
785
|
+
pageId,
|
|
786
|
+
oKey: object.oKey,
|
|
787
|
+
props: { angle: val }
|
|
788
|
+
});
|
|
789
|
+
object === null || object === void 0 || object.transformByState({ angle: val });
|
|
790
|
+
setRotation(val);
|
|
791
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
792
|
+
}
|
|
793
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
794
|
+
className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", _univerjs_design.borderTopClassName),
|
|
795
|
+
children: [
|
|
796
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
797
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
798
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.transform.title") })
|
|
799
|
+
}),
|
|
800
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
801
|
+
className: "univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
802
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.width") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
803
|
+
min: 1,
|
|
804
|
+
value: width,
|
|
805
|
+
onChange: (val) => {
|
|
806
|
+
handleWidthChange(val);
|
|
807
|
+
}
|
|
808
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.height") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
809
|
+
min: 1,
|
|
810
|
+
value: height,
|
|
811
|
+
onChange: (val) => {
|
|
812
|
+
handleHeightChange(val);
|
|
813
|
+
}
|
|
814
|
+
})] })]
|
|
815
|
+
}),
|
|
816
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
817
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
818
|
+
children: [
|
|
819
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.x") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
820
|
+
min: 0,
|
|
821
|
+
precision: 1,
|
|
822
|
+
value: xPosition,
|
|
823
|
+
onChange: (val) => {
|
|
824
|
+
handleXChange(val);
|
|
825
|
+
}
|
|
826
|
+
})] }),
|
|
827
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.y") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
828
|
+
min: 0,
|
|
829
|
+
precision: 1,
|
|
830
|
+
value: yPosition,
|
|
831
|
+
onChange: (val) => {
|
|
832
|
+
handleYChange(val);
|
|
833
|
+
}
|
|
834
|
+
})] }),
|
|
835
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.rotate") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
836
|
+
precision: 1,
|
|
837
|
+
value: rotation,
|
|
838
|
+
onChange: handleChangeRotation
|
|
839
|
+
})] })
|
|
840
|
+
]
|
|
841
|
+
})
|
|
842
|
+
]
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
//#endregion
|
|
847
|
+
//#region src/components/sidebar/Sidebar.tsx
|
|
848
|
+
const COMPONENT_SLIDE_SIDEBAR = "COMPONENT_SLIDE_SIDEBAR";
|
|
849
|
+
function RectSidebar() {
|
|
850
|
+
var _currentSlide$getActi, _univerInstanceServic, _page$scene;
|
|
851
|
+
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
852
|
+
const canvasView = (0, _univerjs_ui.useDependency)(CanvasView);
|
|
853
|
+
const currentSlide = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE);
|
|
854
|
+
const pageId = currentSlide === null || currentSlide === void 0 || (_currentSlide$getActi = currentSlide.getActivePage()) === null || _currentSlide$getActi === void 0 ? void 0 : _currentSlide$getActi.id;
|
|
855
|
+
const unitId = ((_univerInstanceServic = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId()) || "";
|
|
856
|
+
if (!pageId || !unitId) return null;
|
|
857
|
+
const transformer = (_page$scene = canvasView.getRenderUnitByPageId(pageId, unitId).scene) === null || _page$scene === void 0 ? void 0 : _page$scene.getTransformer();
|
|
858
|
+
if (!transformer) return null;
|
|
859
|
+
const object = transformer.getSelectedObjectMap().values().next().value;
|
|
860
|
+
if (!object) return null;
|
|
861
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
862
|
+
className: "univer-p-2 univer-text-center univer-text-sm",
|
|
863
|
+
children: [
|
|
864
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArrangePanel$1, {
|
|
865
|
+
pageId,
|
|
866
|
+
unitId
|
|
867
|
+
}),
|
|
868
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TransformPanel, {
|
|
869
|
+
pageId,
|
|
870
|
+
unitId
|
|
871
|
+
}),
|
|
872
|
+
object.objectType === _univerjs_engine_render.ObjectType.RECT && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArrangePanel, {
|
|
873
|
+
pageId,
|
|
874
|
+
unitId
|
|
875
|
+
})
|
|
876
|
+
]
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region src/commands/operations/insert-shape.operation.ts
|
|
882
|
+
const InsertSlideShapeRectangleCommand = {
|
|
883
|
+
id: "slide.command.insert-float-shape.rectangle",
|
|
884
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
885
|
+
handler: async (accessor) => {
|
|
886
|
+
var _instanceService$getF;
|
|
887
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
888
|
+
const unitId = (_instanceService$getF = accessor.get(_univerjs_core.IUniverInstanceService).getFocusedUnit()) === null || _instanceService$getF === void 0 ? void 0 : _instanceService$getF.getUnitId();
|
|
889
|
+
return commandService.executeCommand(InsertSlideShapeRectangleOperation.id, { unitId });
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
const InsertSlideShapeRectangleOperation = {
|
|
893
|
+
id: "slide.operation.insert-float-shape.rectangle",
|
|
894
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
895
|
+
handler: async (accessor, params) => {
|
|
896
|
+
const id = (0, _univerjs_core.generateRandomId)(6);
|
|
897
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
898
|
+
const unitId = params.unitId;
|
|
899
|
+
const slideData = univerInstanceService.getUnit(unitId);
|
|
900
|
+
if (!slideData) return false;
|
|
901
|
+
const activePage = slideData.getActivePage();
|
|
902
|
+
const elements = Object.values(activePage.pageElements);
|
|
903
|
+
const data = {
|
|
904
|
+
id,
|
|
905
|
+
zIndex: ((elements === null || elements === void 0 ? void 0 : elements.length) ? Math.max(...elements.map((element) => element.zIndex)) : 20) + 1,
|
|
906
|
+
left: 378,
|
|
907
|
+
top: 142,
|
|
908
|
+
width: 250,
|
|
909
|
+
height: 250,
|
|
910
|
+
title: id,
|
|
911
|
+
description: "",
|
|
912
|
+
type: _univerjs_slides.PageElementType.SHAPE,
|
|
913
|
+
shape: {
|
|
914
|
+
shapeType: _univerjs_slides.BasicShapes.Rect,
|
|
915
|
+
text: "",
|
|
916
|
+
shapeProperties: { shapeBackgroundFill: { rgb: "rgb(0,0,255)" } }
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
activePage.pageElements[id] = data;
|
|
920
|
+
slideData.updatePage(activePage.id, activePage);
|
|
921
|
+
const canvasview = accessor.get(CanvasView);
|
|
922
|
+
const sceneObject = canvasview.createObjectToPage(data, activePage.id, unitId);
|
|
923
|
+
if (sceneObject) canvasview.setObjectActiveByPage(sceneObject, activePage.id, unitId);
|
|
924
|
+
return true;
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
const ToggleSlideEditSidebarOperation = {
|
|
928
|
+
id: "sidebar.operation.slide-shape",
|
|
929
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
930
|
+
handler: async (accessor, params) => {
|
|
931
|
+
const { visible, objectType } = params;
|
|
932
|
+
const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
|
|
933
|
+
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
934
|
+
let title = "";
|
|
935
|
+
let children = "";
|
|
936
|
+
if (objectType === _univerjs_engine_render.ObjectType.RECT) {
|
|
937
|
+
title = "slide.sidebar.shape";
|
|
938
|
+
children = COMPONENT_SLIDE_SIDEBAR;
|
|
939
|
+
} else if (objectType === _univerjs_engine_render.ObjectType.IMAGE) {
|
|
940
|
+
title = "slide.sidebar.image";
|
|
941
|
+
children = COMPONENT_SLIDE_SIDEBAR;
|
|
942
|
+
} else if (objectType === _univerjs_engine_render.ObjectType.RICH_TEXT) {
|
|
943
|
+
title = "slide.sidebar.text";
|
|
944
|
+
children = COMPONENT_SLIDE_SIDEBAR;
|
|
945
|
+
}
|
|
946
|
+
if (visible) sidebarService.open({
|
|
947
|
+
header: { title: localeService.t(title) },
|
|
948
|
+
children: { label: children },
|
|
949
|
+
onClose: () => {},
|
|
950
|
+
width: 360
|
|
951
|
+
});
|
|
952
|
+
else sidebarService.close();
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
const InsertSlideShapeEllipseCommand = {
|
|
957
|
+
id: "slide.command.insert-float-shape.ellipse",
|
|
958
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
959
|
+
handler: async (accessor) => {
|
|
960
|
+
var _instanceService$getF2;
|
|
961
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
962
|
+
const unitId = (_instanceService$getF2 = accessor.get(_univerjs_core.IUniverInstanceService).getFocusedUnit()) === null || _instanceService$getF2 === void 0 ? void 0 : _instanceService$getF2.getUnitId();
|
|
963
|
+
return commandService.executeCommand(InsertSlideShapeEllipseOperation.id, { unitId });
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
const InsertSlideShapeEllipseOperation = {
|
|
967
|
+
id: "slide.operation.insert-float-shape.ellipse",
|
|
968
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
969
|
+
handler: async (accessor, params) => {
|
|
970
|
+
const id = (0, _univerjs_core.generateRandomId)(6);
|
|
971
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
972
|
+
const unitId = params.unitId;
|
|
973
|
+
const slideData = univerInstanceService.getUnit(unitId);
|
|
974
|
+
if (!slideData) return false;
|
|
975
|
+
const activePage = slideData.getActivePage();
|
|
976
|
+
const elements = Object.values(activePage.pageElements);
|
|
977
|
+
const data = {
|
|
978
|
+
id,
|
|
979
|
+
zIndex: ((elements === null || elements === void 0 ? void 0 : elements.length) ? Math.max(...elements.map((element) => element.zIndex)) : 20) + 1,
|
|
980
|
+
left: 378,
|
|
981
|
+
top: 142,
|
|
982
|
+
width: 250,
|
|
983
|
+
height: 250,
|
|
984
|
+
title: id,
|
|
985
|
+
description: "",
|
|
986
|
+
type: _univerjs_slides.PageElementType.SHAPE,
|
|
987
|
+
shape: {
|
|
988
|
+
shapeType: _univerjs_slides.BasicShapes.Ellipse,
|
|
989
|
+
text: "",
|
|
990
|
+
shapeProperties: {
|
|
991
|
+
radius: 100,
|
|
992
|
+
shapeBackgroundFill: { rgb: "rgb(0,0,255)" }
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
activePage.pageElements[id] = data;
|
|
997
|
+
slideData.updatePage(activePage.id, activePage);
|
|
998
|
+
const canvasview = accessor.get(CanvasView);
|
|
999
|
+
const sceneObject = canvasview.createObjectToPage(data, activePage.id, unitId);
|
|
1000
|
+
if (sceneObject) canvasview.setObjectActiveByPage(sceneObject, activePage.id, unitId);
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
//#endregion
|
|
1006
|
+
//#region src/commands/operations/insert-text.operation.ts
|
|
1007
|
+
const SlideAddTextCommand = {
|
|
1008
|
+
id: "slide.command.add-text",
|
|
1009
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
1010
|
+
handler: async (accessor) => {
|
|
1011
|
+
var _univerInstanceServic;
|
|
1012
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
1013
|
+
const unitId = (_univerInstanceServic = accessor.get(_univerjs_core.IUniverInstanceService).getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
|
|
1014
|
+
return await commandService.executeCommand(SlideAddTextOperation.id, { unitId });
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
const SlideAddTextOperation = {
|
|
1018
|
+
id: "slide.operation.add-text",
|
|
1019
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
1020
|
+
handler: async (accessor, params) => {
|
|
1021
|
+
const unitId = params.unitId;
|
|
1022
|
+
const elementId = (0, _univerjs_core.generateRandomId)(6);
|
|
1023
|
+
const defaultWidth = 220;
|
|
1024
|
+
const defaultheight = 40;
|
|
1025
|
+
const left = 230;
|
|
1026
|
+
const top = 142;
|
|
1027
|
+
const textContent = (params === null || params === void 0 ? void 0 : params.text) || "A New Text";
|
|
1028
|
+
const slideData = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
1029
|
+
if (!slideData) return false;
|
|
1030
|
+
const activePage = slideData.getActivePage();
|
|
1031
|
+
const elements = Object.values(activePage.pageElements);
|
|
1032
|
+
const elementData = {
|
|
1033
|
+
id: elementId,
|
|
1034
|
+
zIndex: ((elements === null || elements === void 0 ? void 0 : elements.length) ? Math.max(...elements.map((element) => element.zIndex)) : 21) + 1,
|
|
1035
|
+
left,
|
|
1036
|
+
top,
|
|
1037
|
+
width: defaultWidth,
|
|
1038
|
+
height: defaultheight,
|
|
1039
|
+
title: "text",
|
|
1040
|
+
description: "",
|
|
1041
|
+
type: _univerjs_slides.PageElementType.TEXT,
|
|
1042
|
+
richText: {
|
|
1043
|
+
text: textContent,
|
|
1044
|
+
fs: 30,
|
|
1045
|
+
cl: { rgb: "rgb(51, 51, 51)" },
|
|
1046
|
+
bl: 1
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
activePage.pageElements[elementId] = elementData;
|
|
1050
|
+
slideData.updatePage(activePage.id, activePage);
|
|
1051
|
+
const canvasview = accessor.get(CanvasView);
|
|
1052
|
+
const sceneObject = canvasview.createObjectToPage(elementData, activePage.id, unitId);
|
|
1053
|
+
if (sceneObject) canvasview.setObjectActiveByPage(sceneObject, activePage.id, unitId);
|
|
1054
|
+
return true;
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region src/commands/operations/set-thumb.operation.ts
|
|
1060
|
+
const SetSlidePageThumbOperation = {
|
|
1061
|
+
id: "slide.operation.set-slide-page-thumb",
|
|
1062
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
1063
|
+
handler: (accessor, params) => {
|
|
1064
|
+
accessor.get(CanvasView).createThumbs(params.unitId);
|
|
1065
|
+
return true;
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/components/slide-bar/SlideBar.tsx
|
|
1071
|
+
/**
|
|
1072
|
+
* This components works as the root component of the left Sidebar of Slide.
|
|
1073
|
+
*/
|
|
1074
|
+
function SlideSideBar() {
|
|
1075
|
+
var _currentSlide$getActi, _currentSlide$getActi2;
|
|
1076
|
+
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
1077
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
1078
|
+
const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
|
|
1079
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
1080
|
+
const slideBarRef = (0, react.useRef)(null);
|
|
1081
|
+
const currentSlide = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE);
|
|
1082
|
+
const pages = currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.getPages();
|
|
1083
|
+
const pageOrder = currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.getPageOrder();
|
|
1084
|
+
if (!pages || !pageOrder) return null;
|
|
1085
|
+
const slideList = pageOrder.map((id) => pages[id]);
|
|
1086
|
+
const [activatePageId, setActivatePageId] = (0, react.useState)((_currentSlide$getActi = currentSlide === null || currentSlide === void 0 || (_currentSlide$getActi2 = currentSlide.getActivePage()) === null || _currentSlide$getActi2 === void 0 ? void 0 : _currentSlide$getActi2.id) !== null && _currentSlide$getActi !== void 0 ? _currentSlide$getActi : null);
|
|
1087
|
+
const divRefs = (0, react.useMemo)(() => slideList.map(() => (0, react.createRef)()), [slideList]);
|
|
1088
|
+
(0, react.useEffect)(() => {
|
|
1089
|
+
const subscriber = currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.activePage$.subscribe((page) => {
|
|
1090
|
+
var _page$id;
|
|
1091
|
+
const id = (_page$id = page === null || page === void 0 ? void 0 : page.id) !== null && _page$id !== void 0 ? _page$id : null;
|
|
1092
|
+
id && setActivatePageId(id);
|
|
1093
|
+
});
|
|
1094
|
+
return () => {
|
|
1095
|
+
subscriber === null || subscriber === void 0 || subscriber.unsubscribe();
|
|
1096
|
+
};
|
|
1097
|
+
}, []);
|
|
1098
|
+
(0, react.useEffect)(() => {
|
|
1099
|
+
divRefs.forEach((ref, index) => {
|
|
1100
|
+
if (ref.current) {
|
|
1101
|
+
var _renderManagerService;
|
|
1102
|
+
const slide = slideList[index];
|
|
1103
|
+
(_renderManagerService = renderManagerService.getRenderById(slide.id)) === null || _renderManagerService === void 0 || _renderManagerService.engine.setContainer(ref.current);
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
if (divRefs.length > 0) commandService.syncExecuteCommand(SetSlidePageThumbOperation.id, { unitId: currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.getUnitId() });
|
|
1107
|
+
}, [
|
|
1108
|
+
divRefs,
|
|
1109
|
+
slideList,
|
|
1110
|
+
renderManagerService,
|
|
1111
|
+
commandService,
|
|
1112
|
+
currentSlide
|
|
1113
|
+
]);
|
|
1114
|
+
const activatePage = (0, react.useCallback)((page) => {
|
|
1115
|
+
commandService.syncExecuteCommand(ActivateSlidePageOperation.id, {
|
|
1116
|
+
id: page,
|
|
1117
|
+
unitId: currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.getUnitId()
|
|
1118
|
+
});
|
|
1119
|
+
}, [commandService, currentSlide]);
|
|
1120
|
+
const handleAppendSlide = (0, react.useCallback)(() => {
|
|
1121
|
+
commandService.syncExecuteCommand(AppendSlideOperation.id, { unitId: currentSlide === null || currentSlide === void 0 ? void 0 : currentSlide.getUnitId() });
|
|
1122
|
+
}, [commandService, currentSlide]);
|
|
1123
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("aside", {
|
|
1124
|
+
ref: slideBarRef,
|
|
1125
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-h-full univer-w-64 univer-flex-col univer-overflow-y-auto univer-overflow-x-hidden", _univerjs_design.scrollbarClassName),
|
|
1126
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1127
|
+
className: "univer-px-4",
|
|
1128
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
1129
|
+
className: "univer-flex univer-justify-center univer-pt-4",
|
|
1130
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1131
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-block univer-h-8 univer-w-full univer-cursor-pointer univer-rounded-md univer-bg-white univer-text-center univer-text-sm univer-leading-8 univer-transition-colors", _univerjs_design.borderClassName),
|
|
1132
|
+
onClick: handleAppendSlide,
|
|
1133
|
+
children: localeService.t("slide.append")
|
|
1134
|
+
})
|
|
1135
|
+
}), slideList.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1136
|
+
className: (0, _univerjs_design.clsx)("univer-my-4 univer-flex univer-gap-2", { "[&>div]:univer-border-primary-600 [&>span]:univer-text-primary-600": item.id === activatePageId }),
|
|
1137
|
+
onClick: () => activatePage(item.id),
|
|
1138
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: index + 1 }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1139
|
+
ref: divRefs[index],
|
|
1140
|
+
className: (0, _univerjs_design.clsx)("univer-relative univer-box-border univer-h-32 univer-w-52 univer-bg-white hover:univer-border-primary-600", _univerjs_design.borderClassName)
|
|
1141
|
+
})]
|
|
1142
|
+
}, item.id))]
|
|
1143
|
+
})
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/const.ts
|
|
1149
|
+
/**
|
|
1150
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1151
|
+
*
|
|
1152
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1153
|
+
* you may not use this file except in compliance with the License.
|
|
1154
|
+
* You may obtain a copy of the License at
|
|
1155
|
+
*
|
|
1156
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1157
|
+
*
|
|
1158
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1159
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1160
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1161
|
+
* See the License for the specific language governing permissions and
|
|
1162
|
+
* limitations under the License.
|
|
1163
|
+
*/
|
|
1164
|
+
const SLIDE_EDITOR_ID = (0, _univerjs_core.createInternalEditorID)("SLIDE_EDITOR");
|
|
1165
|
+
|
|
1166
|
+
//#endregion
|
|
1167
|
+
//#region src/commands/operations/text-edit.operation.ts
|
|
1168
|
+
const SetTextEditArrowOperation = {
|
|
1169
|
+
id: "slide.operation.edit-arrow",
|
|
1170
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
1171
|
+
handler: () => true
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
//#endregion
|
|
1175
|
+
//#region src/components/image-popup-menu/component-name.ts
|
|
1176
|
+
/**
|
|
1177
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1178
|
+
*
|
|
1179
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1180
|
+
* you may not use this file except in compliance with the License.
|
|
1181
|
+
* You may obtain a copy of the License at
|
|
1182
|
+
*
|
|
1183
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1184
|
+
*
|
|
1185
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1186
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1187
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1188
|
+
* See the License for the specific language governing permissions and
|
|
1189
|
+
* limitations under the License.
|
|
1190
|
+
*/
|
|
1191
|
+
const COMPONENT_SLIDE_IMAGE_POPUP_MENU = "COMPONENT_SLIDE_IMAGE_POPUP_MENU";
|
|
1192
|
+
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/components/image-popup-menu/ImagePopupMenu.tsx
|
|
1195
|
+
function SlideImagePopupMenu(props) {
|
|
1196
|
+
var _props$popup;
|
|
1197
|
+
const menuItems = (_props$popup = props.popup) === null || _props$popup === void 0 || (_props$popup = _props$popup.extraProps) === null || _props$popup === void 0 ? void 0 : _props$popup.menuItems;
|
|
1198
|
+
if (!menuItems) return null;
|
|
1199
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
1200
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
1201
|
+
const [visible, setVisible] = (0, react.useState)(false);
|
|
1202
|
+
const [isHovered, setHovered] = (0, react.useState)(false);
|
|
1203
|
+
const handleMouseEnter = () => {
|
|
1204
|
+
setHovered(true);
|
|
1205
|
+
};
|
|
1206
|
+
const handleMouseLeave = () => {
|
|
1207
|
+
setHovered(false);
|
|
1208
|
+
};
|
|
1209
|
+
const onVisibleChange = (visible) => {
|
|
1210
|
+
setVisible(visible);
|
|
1211
|
+
};
|
|
1212
|
+
const handleClick = (item) => {
|
|
1213
|
+
commandService.executeCommand(item.commandId, item.commandParams);
|
|
1214
|
+
setVisible(false);
|
|
1215
|
+
};
|
|
1216
|
+
const showMore = visible || isHovered;
|
|
1217
|
+
const availableMenu = menuItems.filter((item) => !item.disable);
|
|
1218
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1219
|
+
onMouseEnter: handleMouseEnter,
|
|
1220
|
+
onMouseLeave: handleMouseLeave,
|
|
1221
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
1222
|
+
align: "start",
|
|
1223
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
1224
|
+
className: (0, _univerjs_design.clsx)("univer-m-0 univer-box-border univer-grid univer-list-none univer-items-center univer-gap-1 univer-rounded-lg univer-bg-white univer-p-1.5 univer-text-sm univer-shadow-lg", _univerjs_design.borderClassName),
|
|
1225
|
+
children: availableMenu.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
1226
|
+
className: "univer-relative univer-box-border univer-flex univer-h-8 univer-cursor-pointer univer-items-center univer-rounded univer-text-sm univer-transition-colors hover:univer-bg-gray-100",
|
|
1227
|
+
onClick: () => handleClick(item),
|
|
1228
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1229
|
+
className: "univer-px-2 univer-py-1.5 univer-align-middle",
|
|
1230
|
+
children: localeService.t(item.label)
|
|
1231
|
+
})
|
|
1232
|
+
}, item.index))
|
|
1233
|
+
}),
|
|
1234
|
+
open: visible,
|
|
1235
|
+
onOpenChange: onVisibleChange,
|
|
1236
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1237
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", _univerjs_design.borderClassName, {
|
|
1238
|
+
"univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
|
|
1239
|
+
"univer-bg-white dark:!univer-bg-gray-900": !visible
|
|
1240
|
+
}),
|
|
1241
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
|
|
1242
|
+
})
|
|
1243
|
+
})
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
//#endregion
|
|
1248
|
+
//#region src/menu/image.menu.ts
|
|
1249
|
+
const SLIDES_IMAGE_MENU_ID = "slide.menu.image";
|
|
1250
|
+
function SlideImageMenuFactory(accessor) {
|
|
1251
|
+
return {
|
|
1252
|
+
id: SLIDES_IMAGE_MENU_ID,
|
|
1253
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
1254
|
+
icon: "AddImageIcon",
|
|
1255
|
+
tooltip: "slide.image.insert.title",
|
|
1256
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SLIDE)
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
function UploadSlideFloatImageMenuFactory(_accessor) {
|
|
1260
|
+
return {
|
|
1261
|
+
id: InsertSlideFloatImageCommand.id,
|
|
1262
|
+
title: "slide.image.insert.float",
|
|
1263
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1264
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(_accessor, _univerjs_core.UniverInstanceType.UNIVER_SLIDE)
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/menu/shape.menu.ts
|
|
1270
|
+
const SHAPE_MENU_ID = "slide.menu.shape";
|
|
1271
|
+
function SlideShapeMenuFactory(accessor) {
|
|
1272
|
+
return {
|
|
1273
|
+
id: SHAPE_MENU_ID,
|
|
1274
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
1275
|
+
icon: "GraphIcon",
|
|
1276
|
+
tooltip: "slide.shape.insert.title",
|
|
1277
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SLIDE)
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
function UploadSlideFloatRectangleShapeMenuFactory(_accessor) {
|
|
1281
|
+
return {
|
|
1282
|
+
id: InsertSlideShapeRectangleCommand.id,
|
|
1283
|
+
title: "slide.shape.insert.rectangle",
|
|
1284
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1285
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(_accessor, _univerjs_core.UniverInstanceType.UNIVER_SLIDE)
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
function UploadSlideFloatEllipseShapeMenuFactory(_accessor) {
|
|
1289
|
+
return {
|
|
1290
|
+
id: InsertSlideShapeEllipseCommand.id,
|
|
1291
|
+
title: "slide.shape.insert.ellipse",
|
|
1292
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1293
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(_accessor, _univerjs_core.UniverInstanceType.UNIVER_SLIDE)
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/menu/text.menu.ts
|
|
1299
|
+
function SlideAddTextMenuItemFactory(_accessor) {
|
|
1300
|
+
return {
|
|
1301
|
+
id: SlideAddTextCommand.id,
|
|
1302
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1303
|
+
icon: "TextIcon",
|
|
1304
|
+
tooltip: "slide.text.insert.title",
|
|
1305
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(_accessor, _univerjs_core.UniverInstanceType.UNIVER_SLIDE)
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
//#endregion
|
|
1310
|
+
//#region src/menu/schema.ts
|
|
1311
|
+
const menuSchema = { [_univerjs_ui.RibbonStartGroup.FORMAT]: {
|
|
1312
|
+
[SlideAddTextCommand.id]: {
|
|
1313
|
+
order: 0,
|
|
1314
|
+
menuItemFactory: SlideAddTextMenuItemFactory
|
|
1315
|
+
},
|
|
1316
|
+
[SLIDES_IMAGE_MENU_ID]: {
|
|
1317
|
+
order: 0,
|
|
1318
|
+
menuItemFactory: SlideImageMenuFactory,
|
|
1319
|
+
[InsertSlideFloatImageCommand.id]: {
|
|
1320
|
+
order: 0,
|
|
1321
|
+
menuItemFactory: UploadSlideFloatImageMenuFactory
|
|
1322
|
+
}
|
|
1323
|
+
},
|
|
1324
|
+
[SHAPE_MENU_ID]: {
|
|
1325
|
+
order: 0,
|
|
1326
|
+
menuItemFactory: SlideShapeMenuFactory,
|
|
1327
|
+
[InsertSlideShapeRectangleCommand.id]: {
|
|
1328
|
+
order: 0,
|
|
1329
|
+
menuItemFactory: UploadSlideFloatRectangleShapeMenuFactory
|
|
1330
|
+
},
|
|
1331
|
+
[InsertSlideShapeEllipseCommand.id]: {
|
|
1332
|
+
order: 0,
|
|
1333
|
+
menuItemFactory: UploadSlideFloatEllipseShapeMenuFactory
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
} };
|
|
1337
|
+
|
|
1338
|
+
//#endregion
|
|
1339
|
+
//#region src/services/slide-editor-manager.service.ts
|
|
1340
|
+
var SlideEditorManagerService = class {
|
|
1341
|
+
constructor() {
|
|
1342
|
+
_defineProperty(this, "_state", null);
|
|
1343
|
+
_defineProperty(this, "_rect", null);
|
|
1344
|
+
_defineProperty(this, "_state$", new rxjs.BehaviorSubject(null));
|
|
1345
|
+
_defineProperty(this, "state$", this._state$.asObservable());
|
|
1346
|
+
_defineProperty(this, "_rect$", new rxjs.BehaviorSubject(null));
|
|
1347
|
+
_defineProperty(this, "rect$", this._rect$.asObservable());
|
|
1348
|
+
_defineProperty(this, "_focus", false);
|
|
1349
|
+
_defineProperty(this, "_focus$", new rxjs.BehaviorSubject(this._focus));
|
|
1350
|
+
_defineProperty(this, "focus$", this._focus$.asObservable());
|
|
1351
|
+
}
|
|
1352
|
+
dispose() {
|
|
1353
|
+
this._state$.complete();
|
|
1354
|
+
this._state = null;
|
|
1355
|
+
this._rect$.complete();
|
|
1356
|
+
this._rect = null;
|
|
1357
|
+
}
|
|
1358
|
+
setState(param) {
|
|
1359
|
+
this._state = param;
|
|
1360
|
+
this._refresh(param);
|
|
1361
|
+
}
|
|
1362
|
+
getRect() {
|
|
1363
|
+
return this._rect;
|
|
1364
|
+
}
|
|
1365
|
+
setRect(param) {
|
|
1366
|
+
this._rect = param;
|
|
1367
|
+
this._rect$.next(param);
|
|
1368
|
+
}
|
|
1369
|
+
getState() {
|
|
1370
|
+
return this._state;
|
|
1371
|
+
}
|
|
1372
|
+
setFocus(param = false) {
|
|
1373
|
+
this._focus = param;
|
|
1374
|
+
this._focus$.next(param);
|
|
1375
|
+
}
|
|
1376
|
+
_refresh(param) {
|
|
1377
|
+
this._state$.next(param);
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
const ISlideEditorManagerService = (0, _univerjs_core.createIdentifier)("univer.slide-editor-manager.service");
|
|
1381
|
+
|
|
1382
|
+
//#endregion
|
|
1383
|
+
//#region src/views/editor-container/EditorContainer.tsx
|
|
1384
|
+
const HIDDEN_EDITOR_POSITION$1 = -1e3;
|
|
1385
|
+
const EDITOR_DEFAULT_POSITION = {
|
|
1386
|
+
width: 0,
|
|
1387
|
+
height: 0,
|
|
1388
|
+
top: HIDDEN_EDITOR_POSITION$1,
|
|
1389
|
+
left: HIDDEN_EDITOR_POSITION$1
|
|
1390
|
+
};
|
|
1391
|
+
/**
|
|
1392
|
+
* Floating editor's container.
|
|
1393
|
+
*/
|
|
1394
|
+
function SlideEditorContainer() {
|
|
1395
|
+
const [state, setState] = (0, react.useState)({ ...EDITOR_DEFAULT_POSITION });
|
|
1396
|
+
const slideEditorManagerService = (0, _univerjs_ui.useDependency)(ISlideEditorManagerService);
|
|
1397
|
+
const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
|
|
1398
|
+
const contextService = (0, _univerjs_ui.useDependency)(_univerjs_core.IContextService);
|
|
1399
|
+
const disableAutoFocus = (0, _univerjs_ui.useObservable)(() => contextService.subscribeContextValue$(_univerjs_ui.DISABLE_AUTO_FOCUS_KEY), false, void 0, [contextService, _univerjs_ui.DISABLE_AUTO_FOCUS_KEY]);
|
|
1400
|
+
`${_univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE}`, _univerjs_core.DocumentFlavor.UNSPECIFIED;
|
|
1401
|
+
(0, react.useEffect)(() => {
|
|
1402
|
+
slideEditorManagerService.state$.subscribe((param) => {
|
|
1403
|
+
if (param == null) return;
|
|
1404
|
+
const { startX = HIDDEN_EDITOR_POSITION$1, startY = HIDDEN_EDITOR_POSITION$1, endX = 0, endY = 0, show = false } = param;
|
|
1405
|
+
if (!show) setState({ ...EDITOR_DEFAULT_POSITION });
|
|
1406
|
+
else {
|
|
1407
|
+
setState({
|
|
1408
|
+
width: endX - startX - _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET + 2,
|
|
1409
|
+
height: endY - startY - _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET + 2,
|
|
1410
|
+
left: startX + _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET,
|
|
1411
|
+
top: startY + _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET
|
|
1412
|
+
});
|
|
1413
|
+
const editor = editorService.getEditor(SLIDE_EDITOR_ID);
|
|
1414
|
+
if (editor == null) return;
|
|
1415
|
+
const { left, top, width, height } = editor.getBoundingClientRect();
|
|
1416
|
+
slideEditorManagerService.setRect({
|
|
1417
|
+
left,
|
|
1418
|
+
top,
|
|
1419
|
+
width,
|
|
1420
|
+
height
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
}, []);
|
|
1425
|
+
(0, react.useEffect)(() => {
|
|
1426
|
+
if (!disableAutoFocus) slideEditorManagerService.setFocus(true);
|
|
1427
|
+
}, [disableAutoFocus, state]);
|
|
1428
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1429
|
+
className: (0, _univerjs_design.clsx)("univer-absolute univer-z-10 univer-box-border univer-flex", _univerjs_design.borderClassName),
|
|
1430
|
+
style: {
|
|
1431
|
+
left: state.left,
|
|
1432
|
+
top: state.top,
|
|
1433
|
+
width: state.width,
|
|
1434
|
+
height: state.height
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
//#endregion
|
|
1440
|
+
//#region src/controllers/shortcuts/utils.ts
|
|
1441
|
+
function whenEditorActivated(contextService) {
|
|
1442
|
+
return contextService.getContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR) && contextService.getContextValue(_univerjs_core.EDITOR_ACTIVATED);
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Requires the currently focused editor is a formula editor.
|
|
1446
|
+
* @param contextService
|
|
1447
|
+
* @returns If the formula editor is focused.
|
|
1448
|
+
*/
|
|
1449
|
+
function whenFormulaEditorFocused(contextService) {
|
|
1450
|
+
return contextService.getContextValue(_univerjs_core.FORMULA_EDITOR_ACTIVATED) && contextService.getContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
//#endregion
|
|
1454
|
+
//#region src/controllers/shortcuts/editor.shortcuts.ts
|
|
1455
|
+
const ARROW_SELECTION_KEYCODE_LIST = [
|
|
1456
|
+
_univerjs_ui.KeyCode.ARROW_DOWN,
|
|
1457
|
+
_univerjs_ui.KeyCode.ARROW_UP,
|
|
1458
|
+
_univerjs_ui.KeyCode.ARROW_LEFT,
|
|
1459
|
+
_univerjs_ui.KeyCode.ARROW_RIGHT
|
|
1460
|
+
];
|
|
1461
|
+
const MOVE_SELECTION_KEYCODE_LIST = [
|
|
1462
|
+
_univerjs_ui.KeyCode.ENTER,
|
|
1463
|
+
_univerjs_ui.KeyCode.TAB,
|
|
1464
|
+
...ARROW_SELECTION_KEYCODE_LIST
|
|
1465
|
+
];
|
|
1466
|
+
function generateArrowSelectionShortCutItem() {
|
|
1467
|
+
const shortcutList = [];
|
|
1468
|
+
for (const keycode of ARROW_SELECTION_KEYCODE_LIST) {
|
|
1469
|
+
shortcutList.push({
|
|
1470
|
+
id: SetTextEditArrowOperation.id,
|
|
1471
|
+
binding: keycode,
|
|
1472
|
+
preconditions: (contextService) => whenEditorActivated(contextService),
|
|
1473
|
+
staticParameters: {
|
|
1474
|
+
visible: false,
|
|
1475
|
+
eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
|
|
1476
|
+
keycode,
|
|
1477
|
+
isShift: false
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
shortcutList.push({
|
|
1481
|
+
id: SetTextEditArrowOperation.id,
|
|
1482
|
+
binding: keycode | _univerjs_ui.MetaKeys.SHIFT,
|
|
1483
|
+
preconditions: (contextService) => whenEditorActivated(contextService),
|
|
1484
|
+
staticParameters: {
|
|
1485
|
+
visible: false,
|
|
1486
|
+
eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
|
|
1487
|
+
keycode,
|
|
1488
|
+
isShift: true
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
return shortcutList;
|
|
1493
|
+
}
|
|
1494
|
+
const EditorDeleteLeftShortcut = {
|
|
1495
|
+
id: _univerjs_docs_ui.DeleteLeftCommand.id,
|
|
1496
|
+
preconditions: (contextService) => {
|
|
1497
|
+
return whenEditorActivated(contextService) || whenFormulaEditorFocused(contextService);
|
|
1498
|
+
},
|
|
1499
|
+
binding: _univerjs_ui.KeyCode.BACKSPACE
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
//#endregion
|
|
1503
|
+
//#region src/controllers/slide-ui.controller.ts
|
|
1504
|
+
/**
|
|
1505
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1506
|
+
*
|
|
1507
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1508
|
+
* you may not use this file except in compliance with the License.
|
|
1509
|
+
* You may obtain a copy of the License at
|
|
1510
|
+
*
|
|
1511
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1512
|
+
*
|
|
1513
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1514
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1515
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1516
|
+
* See the License for the specific language governing permissions and
|
|
1517
|
+
* limitations under the License.
|
|
1518
|
+
*/
|
|
1519
|
+
let SlidesUIController = class SlidesUIController extends _univerjs_core.Disposable {
|
|
1520
|
+
constructor(_injector, _menuManagerService, _componentManager, _uiPartsService, _commandService, _shortcutService) {
|
|
1521
|
+
super();
|
|
1522
|
+
this._injector = _injector;
|
|
1523
|
+
this._menuManagerService = _menuManagerService;
|
|
1524
|
+
this._componentManager = _componentManager;
|
|
1525
|
+
this._uiPartsService = _uiPartsService;
|
|
1526
|
+
this._commandService = _commandService;
|
|
1527
|
+
this._shortcutService = _shortcutService;
|
|
1528
|
+
this._initCommands();
|
|
1529
|
+
this._initCustomComponents();
|
|
1530
|
+
this._initUIComponents();
|
|
1531
|
+
this._initMenus();
|
|
1532
|
+
this._initShortcuts();
|
|
1533
|
+
}
|
|
1534
|
+
_initMenus() {
|
|
1535
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
1536
|
+
}
|
|
1537
|
+
_initCustomComponents() {
|
|
1538
|
+
const componentManager = this._componentManager;
|
|
1539
|
+
this.disposeWithMe(componentManager.register("TextIcon", _univerjs_icons.TextIcon));
|
|
1540
|
+
this.disposeWithMe(componentManager.register("GraphIcon", _univerjs_icons.GraphIcon));
|
|
1541
|
+
this.disposeWithMe(componentManager.register(COMPONENT_SLIDE_IMAGE_POPUP_MENU, SlideImagePopupMenu));
|
|
1542
|
+
this.disposeWithMe(componentManager.register(COMPONENT_SLIDE_SIDEBAR, RectSidebar));
|
|
1543
|
+
}
|
|
1544
|
+
_initCommands() {
|
|
1545
|
+
[
|
|
1546
|
+
AppendSlideOperation,
|
|
1547
|
+
ActivateSlidePageOperation,
|
|
1548
|
+
SetSlidePageThumbOperation,
|
|
1549
|
+
InsertSlideFloatImageCommand,
|
|
1550
|
+
SlideAddTextOperation,
|
|
1551
|
+
SlideAddTextCommand,
|
|
1552
|
+
InsertSlideShapeEllipseCommand,
|
|
1553
|
+
InsertSlideShapeEllipseOperation,
|
|
1554
|
+
InsertSlideShapeRectangleOperation,
|
|
1555
|
+
InsertSlideShapeRectangleCommand,
|
|
1556
|
+
ToggleSlideEditSidebarOperation,
|
|
1557
|
+
DeleteSlideElementOperation,
|
|
1558
|
+
UpdateSlideElementOperation,
|
|
1559
|
+
SetTextEditArrowOperation
|
|
1560
|
+
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
1561
|
+
}
|
|
1562
|
+
_initUIComponents() {
|
|
1563
|
+
this.disposeWithMe(this._uiPartsService.registerComponent(_univerjs_ui.BuiltInUIPart.LEFT_SIDEBAR, () => (0, _univerjs_ui.connectInjector)(SlideSideBar, this._injector)));
|
|
1564
|
+
this.disposeWithMe(this._uiPartsService.registerComponent(_univerjs_ui.BuiltInUIPart.CONTENT, () => (0, _univerjs_ui.connectInjector)(SlideEditorContainer, this._injector)));
|
|
1565
|
+
}
|
|
1566
|
+
_initShortcuts() {
|
|
1567
|
+
[EditorDeleteLeftShortcut, ...generateArrowSelectionShortCutItem()].forEach((item) => {
|
|
1568
|
+
this.disposeWithMe(this._shortcutService.registerShortcut(item));
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
SlidesUIController = __decorate([
|
|
1573
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1574
|
+
__decorateParam(1, _univerjs_ui.IMenuManagerService),
|
|
1575
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
|
|
1576
|
+
__decorateParam(3, _univerjs_ui.IUIPartsService),
|
|
1577
|
+
__decorateParam(4, _univerjs_core.ICommandService),
|
|
1578
|
+
__decorateParam(5, _univerjs_ui.IShortcutService)
|
|
1579
|
+
], SlidesUIController);
|
|
1580
|
+
|
|
1581
|
+
//#endregion
|
|
1582
|
+
//#region package.json
|
|
1583
|
+
var name = "@univerjs/slides-ui";
|
|
1584
|
+
var version = "0.21.0";
|
|
1585
|
+
|
|
1586
|
+
//#endregion
|
|
1587
|
+
//#region src/config/config.ts
|
|
1588
|
+
const SLIDES_UI_PLUGIN_CONFIG_KEY = "slides-ui.config";
|
|
1589
|
+
const configSymbol = Symbol(SLIDES_UI_PLUGIN_CONFIG_KEY);
|
|
1590
|
+
const defaultPluginConfig = {};
|
|
1591
|
+
|
|
1592
|
+
//#endregion
|
|
1593
|
+
//#region src/services/slide-editor-bridge.service.ts
|
|
1594
|
+
const ISlideEditorBridgeService = (0, _univerjs_core.createIdentifier)("univer.slide-editor-bridge.service");
|
|
1595
|
+
let SlideEditorBridgeService = class SlideEditorBridgeService extends _univerjs_core.Disposable {
|
|
1596
|
+
constructor(_editorService, _contextService, _renderManagerService) {
|
|
1597
|
+
super();
|
|
1598
|
+
this._editorService = _editorService;
|
|
1599
|
+
this._contextService = _contextService;
|
|
1600
|
+
this._renderManagerService = _renderManagerService;
|
|
1601
|
+
_defineProperty(this, "_editorUnitId", SLIDE_EDITOR_ID);
|
|
1602
|
+
_defineProperty(this, "_isForceKeepVisible", false);
|
|
1603
|
+
_defineProperty(this, "_editorIsDirty", false);
|
|
1604
|
+
_defineProperty(this, "_currentEditRectState", null);
|
|
1605
|
+
_defineProperty(this, "_currentEditRectState$", new rxjs.BehaviorSubject(null));
|
|
1606
|
+
_defineProperty(this, "currentEditRectState$", this._currentEditRectState$.asObservable());
|
|
1607
|
+
_defineProperty(this, "_visibleParam", {
|
|
1608
|
+
visible: false,
|
|
1609
|
+
eventType: _univerjs_engine_render.DeviceInputEventType.Dblclick,
|
|
1610
|
+
unitId: ""
|
|
1611
|
+
});
|
|
1612
|
+
_defineProperty(this, "_visible$", new rxjs.BehaviorSubject(this._visibleParam));
|
|
1613
|
+
_defineProperty(this, "visible$", this._visible$.asObservable());
|
|
1614
|
+
_defineProperty(this, "_afterVisible$", new rxjs.BehaviorSubject(this._visibleParam));
|
|
1615
|
+
_defineProperty(this, "afterVisible$", this._afterVisible$.asObservable());
|
|
1616
|
+
_defineProperty(this, "endEditing$", new rxjs.Subject());
|
|
1617
|
+
_defineProperty(this, "_currentEditRectInfo", void 0);
|
|
1618
|
+
}
|
|
1619
|
+
dispose() {
|
|
1620
|
+
super.dispose();
|
|
1621
|
+
}
|
|
1622
|
+
getEditorRect() {
|
|
1623
|
+
return this._currentEditRectInfo;
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* 1st part of startEditing.
|
|
1627
|
+
* @editorInfo editorInfo
|
|
1628
|
+
*/
|
|
1629
|
+
setEditorRect(editorInfo) {
|
|
1630
|
+
this._currentEditRectInfo = editorInfo;
|
|
1631
|
+
if (!this._editorService.getFocusEditor()) {
|
|
1632
|
+
this._editorService.focus(SLIDE_EDITOR_ID);
|
|
1633
|
+
this._contextService.setContextValue(_univerjs_core.EDITOR_ACTIVATED, false);
|
|
1634
|
+
this._contextService.setContextValue(_univerjs_core.FOCUSING_EDITOR_STANDALONE, false);
|
|
1635
|
+
this._contextService.setContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, false);
|
|
1636
|
+
}
|
|
1637
|
+
const editRectState = this.getEditRectState();
|
|
1638
|
+
this._currentEditRectState = editRectState;
|
|
1639
|
+
this._currentEditRectState$.next(editRectState);
|
|
1640
|
+
}
|
|
1641
|
+
changeVisible(param) {
|
|
1642
|
+
/**
|
|
1643
|
+
* Non-sheetEditor and formula selection mode,
|
|
1644
|
+
* double-clicking cannot activate the sheet editor.
|
|
1645
|
+
*/
|
|
1646
|
+
this._visibleParam = param;
|
|
1647
|
+
if (param.visible) this._editorIsDirty = false;
|
|
1648
|
+
this._visible$.next(this._visibleParam);
|
|
1649
|
+
this._afterVisible$.next(this._visibleParam);
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* get info from _currentEditRectInfo
|
|
1653
|
+
*
|
|
1654
|
+
* invoked by slide-editing.render-controller.ts@_handleEditorVisible
|
|
1655
|
+
* && this@setEditorRect
|
|
1656
|
+
*/
|
|
1657
|
+
getEditRectState() {
|
|
1658
|
+
const editorUnitId = SLIDE_EDITOR_ID;
|
|
1659
|
+
const editorRectInfo = this._currentEditRectInfo;
|
|
1660
|
+
const unitId = editorRectInfo.unitId;
|
|
1661
|
+
const docData = editorRectInfo.richTextObj.documentData;
|
|
1662
|
+
docData.id = editorUnitId;
|
|
1663
|
+
docData.documentStyle = {
|
|
1664
|
+
...docData.documentStyle,
|
|
1665
|
+
pageSize: {
|
|
1666
|
+
width: editorRectInfo.richTextObj.width,
|
|
1667
|
+
height: Infinity
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
const documentLayoutObject = {
|
|
1671
|
+
documentModel: new _univerjs_core.DocumentDataModel(docData),
|
|
1672
|
+
fontString: "document",
|
|
1673
|
+
textRotation: {
|
|
1674
|
+
a: 0,
|
|
1675
|
+
v: 0
|
|
1676
|
+
},
|
|
1677
|
+
wrapStrategy: 0,
|
|
1678
|
+
verticalAlign: _univerjs_core.VerticalAlign.TOP,
|
|
1679
|
+
horizontalAlign: _univerjs_core.HorizontalAlign.LEFT,
|
|
1680
|
+
paddingData: {
|
|
1681
|
+
t: 0,
|
|
1682
|
+
b: 1,
|
|
1683
|
+
l: 2,
|
|
1684
|
+
r: 2
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1687
|
+
const editorWidth = editorRectInfo.richTextObj.width;
|
|
1688
|
+
const editorHeight = editorRectInfo.richTextObj.height;
|
|
1689
|
+
const left = editorRectInfo.richTextObj.left;
|
|
1690
|
+
const top = editorRectInfo.richTextObj.top;
|
|
1691
|
+
const canvasOffset = {
|
|
1692
|
+
left: 0,
|
|
1693
|
+
top: 0
|
|
1694
|
+
};
|
|
1695
|
+
const renderUnit = this._renderManagerService.getRenderById(unitId);
|
|
1696
|
+
const mainScene = renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.scene;
|
|
1697
|
+
const mainViewport = mainScene === null || mainScene === void 0 ? void 0 : mainScene.getViewport(_univerjs_slides.SLIDE_KEY.VIEW);
|
|
1698
|
+
const slideMainRect = mainScene === null || mainScene === void 0 ? void 0 : mainScene.getObject(_univerjs_slides.SLIDE_KEY.COMPONENT);
|
|
1699
|
+
const slidePos = {
|
|
1700
|
+
x: (slideMainRect === null || slideMainRect === void 0 ? void 0 : slideMainRect.left) || 0,
|
|
1701
|
+
y: (slideMainRect === null || slideMainRect === void 0 ? void 0 : slideMainRect.top) || 0
|
|
1702
|
+
};
|
|
1703
|
+
const scrollX = (mainViewport === null || mainViewport === void 0 ? void 0 : mainViewport.viewportScrollX) || 0;
|
|
1704
|
+
const scrollY = (mainViewport === null || mainViewport === void 0 ? void 0 : mainViewport.viewportScrollY) || 0;
|
|
1705
|
+
canvasOffset.left = slidePos.x - scrollX;
|
|
1706
|
+
canvasOffset.top = slidePos.y - scrollY;
|
|
1707
|
+
return {
|
|
1708
|
+
position: {
|
|
1709
|
+
startX: left,
|
|
1710
|
+
startY: top,
|
|
1711
|
+
endX: left + editorWidth,
|
|
1712
|
+
endY: top + editorHeight
|
|
1713
|
+
},
|
|
1714
|
+
scaleX: 1,
|
|
1715
|
+
scaleY: 1,
|
|
1716
|
+
slideCardOffset: canvasOffset,
|
|
1717
|
+
unitId,
|
|
1718
|
+
editorUnitId,
|
|
1719
|
+
documentLayoutObject
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
changeEditorDirty(dirtyStatus) {
|
|
1723
|
+
this._editorIsDirty = dirtyStatus;
|
|
1724
|
+
}
|
|
1725
|
+
isVisible() {
|
|
1726
|
+
return this._visibleParam.visible;
|
|
1727
|
+
}
|
|
1728
|
+
getEditorDirty() {
|
|
1729
|
+
return this._editorIsDirty;
|
|
1730
|
+
}
|
|
1731
|
+
getCurrentEditorId() {
|
|
1732
|
+
return this._editorUnitId;
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* @deprecated
|
|
1736
|
+
*/
|
|
1737
|
+
genDocData(target) {
|
|
1738
|
+
const editorUnitId = this.getCurrentEditorId();
|
|
1739
|
+
const content = target.text;
|
|
1740
|
+
const fontSize = target.fs;
|
|
1741
|
+
return {
|
|
1742
|
+
id: editorUnitId,
|
|
1743
|
+
body: {
|
|
1744
|
+
dataStream: `${content}\r\n`,
|
|
1745
|
+
textRuns: [{
|
|
1746
|
+
st: 0,
|
|
1747
|
+
ed: content.length
|
|
1748
|
+
}],
|
|
1749
|
+
paragraphs: [{
|
|
1750
|
+
paragraphStyle: {},
|
|
1751
|
+
startIndex: content.length + 1
|
|
1752
|
+
}],
|
|
1753
|
+
sectionBreaks: [{ startIndex: content.length + 2 }]
|
|
1754
|
+
},
|
|
1755
|
+
documentStyle: {
|
|
1756
|
+
marginBottom: 0,
|
|
1757
|
+
marginLeft: 0,
|
|
1758
|
+
marginRight: 0,
|
|
1759
|
+
marginTop: 0,
|
|
1760
|
+
pageSize: {
|
|
1761
|
+
width: Infinity,
|
|
1762
|
+
height: Infinity
|
|
1763
|
+
},
|
|
1764
|
+
textStyle: { fs: fontSize },
|
|
1765
|
+
renderConfig: {
|
|
1766
|
+
verticalAlign: _univerjs_core.VerticalAlign.MIDDLE,
|
|
1767
|
+
centerAngle: 0,
|
|
1768
|
+
vertexAngle: 0,
|
|
1769
|
+
wrapStrategy: 0
|
|
1770
|
+
}
|
|
1771
|
+
},
|
|
1772
|
+
drawings: {},
|
|
1773
|
+
drawingsOrder: [],
|
|
1774
|
+
settings: { zoomRatio: 1 }
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
SlideEditorBridgeService = __decorate([
|
|
1779
|
+
__decorateParam(0, _univerjs_docs_ui.IEditorService),
|
|
1780
|
+
__decorateParam(1, _univerjs_core.IContextService),
|
|
1781
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService)
|
|
1782
|
+
], SlideEditorBridgeService);
|
|
1783
|
+
|
|
1784
|
+
//#endregion
|
|
1785
|
+
//#region src/type.ts
|
|
1786
|
+
let CursorChange = /* @__PURE__ */ function(CursorChange) {
|
|
1787
|
+
CursorChange[CursorChange["InitialState"] = 0] = "InitialState";
|
|
1788
|
+
CursorChange[CursorChange["StartEditor"] = 1] = "StartEditor";
|
|
1789
|
+
CursorChange[CursorChange["CursorChange"] = 2] = "CursorChange";
|
|
1790
|
+
return CursorChange;
|
|
1791
|
+
}({});
|
|
1792
|
+
|
|
1793
|
+
//#endregion
|
|
1794
|
+
//#region src/controllers/slide-editing.render-controller.ts
|
|
1795
|
+
const HIDDEN_EDITOR_POSITION = -1e3;
|
|
1796
|
+
const EDITOR_INPUT_SELF_EXTEND_GAP = 5;
|
|
1797
|
+
const EDITOR_BORDER_SIZE = 2;
|
|
1798
|
+
let SlideEditingRenderController = class SlideEditingRenderController extends _univerjs_core.Disposable {
|
|
1799
|
+
constructor(_renderContext, _layoutService, _undoRedoService, _contextService, _instanceSrv, _renderManagerService, _editorBridgeService, _cellEditorManagerService, _textSelectionManagerService, _commandService, _localService, _editorService) {
|
|
1800
|
+
super();
|
|
1801
|
+
this._renderContext = _renderContext;
|
|
1802
|
+
this._layoutService = _layoutService;
|
|
1803
|
+
this._undoRedoService = _undoRedoService;
|
|
1804
|
+
this._contextService = _contextService;
|
|
1805
|
+
this._instanceSrv = _instanceSrv;
|
|
1806
|
+
this._renderManagerService = _renderManagerService;
|
|
1807
|
+
this._editorBridgeService = _editorBridgeService;
|
|
1808
|
+
this._cellEditorManagerService = _cellEditorManagerService;
|
|
1809
|
+
this._textSelectionManagerService = _textSelectionManagerService;
|
|
1810
|
+
this._commandService = _commandService;
|
|
1811
|
+
this._localService = _localService;
|
|
1812
|
+
this._editorService = _editorService;
|
|
1813
|
+
_defineProperty(this, "_cursorChange", CursorChange.InitialState);
|
|
1814
|
+
_defineProperty(this, "_isUnitEditing", false);
|
|
1815
|
+
_defineProperty(this, "_d", void 0);
|
|
1816
|
+
this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).subscribe((slideDataModel) => {
|
|
1817
|
+
if (slideDataModel && slideDataModel.getUnitId() === this._renderContext.unitId) this._d = this._init();
|
|
1818
|
+
else {
|
|
1819
|
+
this._disposeCurrent();
|
|
1820
|
+
if (this._isUnitEditing) {
|
|
1821
|
+
this._handleEditorInvisible({
|
|
1822
|
+
visible: false,
|
|
1823
|
+
eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
|
|
1824
|
+
keycode: _univerjs_ui.KeyCode.ESC,
|
|
1825
|
+
unitId: this._renderContext.unitId
|
|
1826
|
+
});
|
|
1827
|
+
this._isUnitEditing = false;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
}));
|
|
1831
|
+
this._initEditorVisibilityListener();
|
|
1832
|
+
}
|
|
1833
|
+
dispose() {
|
|
1834
|
+
super.dispose();
|
|
1835
|
+
this._disposeCurrent();
|
|
1836
|
+
}
|
|
1837
|
+
_disposeCurrent() {
|
|
1838
|
+
var _this$_d;
|
|
1839
|
+
(_this$_d = this._d) === null || _this$_d === void 0 || _this$_d.dispose();
|
|
1840
|
+
this._d = null;
|
|
1841
|
+
}
|
|
1842
|
+
_init() {
|
|
1843
|
+
const d = new _univerjs_core.DisposableCollection();
|
|
1844
|
+
this._subscribeToCurrentCell(d);
|
|
1845
|
+
this._initialKeyboardListener(d);
|
|
1846
|
+
this._initialCursorSync(d);
|
|
1847
|
+
this._listenEditorFocus(d);
|
|
1848
|
+
this._commandExecutedListener(d);
|
|
1849
|
+
setTimeout(() => {
|
|
1850
|
+
this._cursorStateListener(d);
|
|
1851
|
+
}, 1e3);
|
|
1852
|
+
return d;
|
|
1853
|
+
}
|
|
1854
|
+
_initEditorVisibilityListener() {
|
|
1855
|
+
this.disposeWithMe(this._editorBridgeService.visible$.subscribe((param) => {
|
|
1856
|
+
if (param.visible) {
|
|
1857
|
+
this._isUnitEditing = true;
|
|
1858
|
+
this._handleEditorVisible(param);
|
|
1859
|
+
} else if (this._isUnitEditing) {
|
|
1860
|
+
this._handleEditorInvisible(param);
|
|
1861
|
+
this._isUnitEditing = false;
|
|
1862
|
+
}
|
|
1863
|
+
}));
|
|
1864
|
+
}
|
|
1865
|
+
_listenEditorFocus(d) {
|
|
1866
|
+
const renderConfig = this._getEditorObject();
|
|
1867
|
+
if (!renderConfig) return;
|
|
1868
|
+
d.add(renderConfig.document.onPointerDown$.subscribeEvent(() => {}));
|
|
1869
|
+
}
|
|
1870
|
+
_getEditorSkeleton(editorId) {
|
|
1871
|
+
var _this$_renderManagerS;
|
|
1872
|
+
return (_this$_renderManagerS = this._renderManagerService.getRenderById(editorId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
|
|
1873
|
+
}
|
|
1874
|
+
_getEditorViewModel(editorId) {
|
|
1875
|
+
var _this$_renderManagerS2;
|
|
1876
|
+
return (_this$_renderManagerS2 = this._renderManagerService.getRenderById(editorId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
|
|
1877
|
+
}
|
|
1878
|
+
_initialCursorSync(d) {
|
|
1879
|
+
d.add(this._cellEditorManagerService.focus$.pipe((0, rxjs.filter)((f) => !!f)).subscribe(() => {
|
|
1880
|
+
var _getCurrentTypeOfRend;
|
|
1881
|
+
(_getCurrentTypeOfRend = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_DOC, this._instanceSrv, this._renderManagerService)) === null || _getCurrentTypeOfRend === void 0 || _getCurrentTypeOfRend.with(_univerjs_docs_ui.DocSelectionRenderService).sync();
|
|
1882
|
+
}));
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Set editorUnitId to curr doc.
|
|
1886
|
+
* @param d DisposableCollection
|
|
1887
|
+
*/
|
|
1888
|
+
_subscribeToCurrentCell(d) {
|
|
1889
|
+
d.add(this._editorBridgeService.currentEditRectState$.subscribe((editCellState) => {
|
|
1890
|
+
var _getCurrentTypeOfRend2;
|
|
1891
|
+
if (editCellState == null) return;
|
|
1892
|
+
if (this._contextService.getContextValue(_univerjs_core.FOCUSING_EDITOR_STANDALONE) || this._contextService.getContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)) return;
|
|
1893
|
+
const { position: { startX, endX }, documentLayoutObject: { textRotation, wrapStrategy, documentModel }, scaleX, editorUnitId } = editCellState;
|
|
1894
|
+
const { vertexAngle: angle } = (0, _univerjs_engine_render.convertTextRotation)(textRotation);
|
|
1895
|
+
documentModel.updateDocumentId(editorUnitId);
|
|
1896
|
+
if (wrapStrategy === _univerjs_core.WrapStrategy.WRAP && angle === 0) documentModel.updateDocumentDataPageSize((endX - startX) / scaleX);
|
|
1897
|
+
this._instanceSrv.changeDoc(editorUnitId, documentModel);
|
|
1898
|
+
this._contextService.setContextValue(_univerjs_core.FOCUSING_EDITOR_BUT_HIDDEN, true);
|
|
1899
|
+
this._textSelectionManagerService.replaceTextRanges([{
|
|
1900
|
+
startOffset: 0,
|
|
1901
|
+
endOffset: 0
|
|
1902
|
+
}]);
|
|
1903
|
+
(_getCurrentTypeOfRend2 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_DOC, this._instanceSrv, this._renderManagerService)) === null || _getCurrentTypeOfRend2 === void 0 || _getCurrentTypeOfRend2.with(_univerjs_docs_ui.DocSelectionRenderService).activate(HIDDEN_EDITOR_POSITION, HIDDEN_EDITOR_POSITION);
|
|
1904
|
+
}));
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Set size and pos of editing area.
|
|
1908
|
+
* @param positionFromEditRectState
|
|
1909
|
+
* @param canvasOffset
|
|
1910
|
+
* @param documentSkeleton
|
|
1911
|
+
* @param documentLayoutObject
|
|
1912
|
+
* @param scaleX
|
|
1913
|
+
* @param scaleY
|
|
1914
|
+
*/
|
|
1915
|
+
_fitTextSize(positionFromEditRectState, canvasOffset, documentSkeleton, documentLayoutObject, scaleX = 1, scaleY = 1) {
|
|
1916
|
+
const { startX, startY, endX, endY } = positionFromEditRectState;
|
|
1917
|
+
const documentDataModel = documentLayoutObject.documentModel;
|
|
1918
|
+
if (documentDataModel == null) return;
|
|
1919
|
+
const { actualWidth, actualHeight } = this._predictingSize(positionFromEditRectState, canvasOffset, documentSkeleton, documentLayoutObject, scaleX, scaleY);
|
|
1920
|
+
const { verticalAlign, paddingData, fill } = documentLayoutObject;
|
|
1921
|
+
let editorWidth = endX - startX;
|
|
1922
|
+
let editorHeight = endY - startY;
|
|
1923
|
+
if (editorWidth < actualWidth) editorWidth = actualWidth;
|
|
1924
|
+
if (editorHeight < actualHeight) {
|
|
1925
|
+
editorHeight = actualHeight;
|
|
1926
|
+
documentDataModel.updateDocumentDataMargin(paddingData);
|
|
1927
|
+
} else {
|
|
1928
|
+
let offsetTop = 0;
|
|
1929
|
+
if (verticalAlign === _univerjs_core.VerticalAlign.MIDDLE) offsetTop = (editorHeight - actualHeight) / 2 / scaleY;
|
|
1930
|
+
else if (verticalAlign === _univerjs_core.VerticalAlign.TOP) offsetTop = paddingData.t || 0;
|
|
1931
|
+
else offsetTop = (editorHeight - actualHeight) / scaleY - (paddingData.b || 0);
|
|
1932
|
+
offsetTop = offsetTop < (paddingData.t || 0) ? paddingData.t || 0 : offsetTop;
|
|
1933
|
+
documentDataModel.updateDocumentDataMargin({ t: offsetTop });
|
|
1934
|
+
}
|
|
1935
|
+
documentSkeleton.calculate();
|
|
1936
|
+
this._editAreaProcessing(editorWidth, editorHeight, positionFromEditRectState, canvasOffset, fill, scaleX, scaleY);
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
* Mainly used to pre-calculate the width of the editor,
|
|
1940
|
+
* to determine whether it needs to be automatically widened.
|
|
1941
|
+
*/
|
|
1942
|
+
_predictingSize(actualRangeWithCoord, canvasOffset, documentSkeleton, documentLayoutObject, scaleX = 1, scaleY = 1) {
|
|
1943
|
+
const { startX, endX } = actualRangeWithCoord;
|
|
1944
|
+
const { textRotation, wrapStrategy } = documentLayoutObject;
|
|
1945
|
+
const documentDataModel = documentLayoutObject.documentModel;
|
|
1946
|
+
const { vertexAngle: angle } = (0, _univerjs_engine_render.convertTextRotation)(textRotation);
|
|
1947
|
+
const clientWidth = document.body.clientWidth;
|
|
1948
|
+
if (wrapStrategy === _univerjs_core.WrapStrategy.WRAP && angle === 0) {
|
|
1949
|
+
const { actualWidth, actualHeight } = documentSkeleton.getActualSize();
|
|
1950
|
+
return {
|
|
1951
|
+
actualWidth: actualWidth * scaleX,
|
|
1952
|
+
actualHeight: actualHeight * scaleY
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
documentDataModel === null || documentDataModel === void 0 || documentDataModel.updateDocumentDataPageSize((clientWidth - startX - canvasOffset.left) / scaleX);
|
|
1956
|
+
documentSkeleton.calculate();
|
|
1957
|
+
const size = documentSkeleton.getActualSize();
|
|
1958
|
+
let editorWidth = endX - startX;
|
|
1959
|
+
if (editorWidth < size.actualWidth * scaleX + EDITOR_INPUT_SELF_EXTEND_GAP * scaleX) editorWidth = size.actualWidth * scaleX + EDITOR_INPUT_SELF_EXTEND_GAP * scaleX;
|
|
1960
|
+
documentDataModel === null || documentDataModel === void 0 || documentDataModel.updateDocumentDataPageSize(editorWidth / scaleX);
|
|
1961
|
+
/**
|
|
1962
|
+
* Do not rely on cell layout logic, depend on the document's internal alignment logic.
|
|
1963
|
+
*/
|
|
1964
|
+
documentDataModel === null || documentDataModel === void 0 || documentDataModel.updateDocumentRenderConfig({
|
|
1965
|
+
horizontalAlign: _univerjs_core.HorizontalAlign.UNSPECIFIED,
|
|
1966
|
+
cellValueType: void 0
|
|
1967
|
+
});
|
|
1968
|
+
return {
|
|
1969
|
+
actualWidth: editorWidth,
|
|
1970
|
+
actualHeight: size.actualHeight * scaleY
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* control the size of editing area
|
|
1975
|
+
*/
|
|
1976
|
+
_editAreaProcessing(editorWidth, editorHeight, positionFromEditRectState, canvasOffset, fill, scaleX = 1, scaleY = 1) {
|
|
1977
|
+
const editorObject = this._getEditorObject();
|
|
1978
|
+
if (editorObject == null) return;
|
|
1979
|
+
function pxToNum(width) {
|
|
1980
|
+
return Number.parseInt(width.replace("px", ""));
|
|
1981
|
+
}
|
|
1982
|
+
const canvasElement = this._renderContext.engine.getCanvasElement();
|
|
1983
|
+
const canvasClientRect = canvasElement.getBoundingClientRect();
|
|
1984
|
+
const widthOfCanvas = pxToNum(canvasElement.style.width);
|
|
1985
|
+
const { top, left, width } = canvasClientRect;
|
|
1986
|
+
const scaleAdjust = width / widthOfCanvas;
|
|
1987
|
+
let { startX, startY } = positionFromEditRectState;
|
|
1988
|
+
startX += canvasOffset.left;
|
|
1989
|
+
startY += canvasOffset.top;
|
|
1990
|
+
const { document: documentComponent, scene: editorScene, engine: docEngine } = editorObject;
|
|
1991
|
+
const viewportMain = editorScene.getViewport(_univerjs_docs_ui.VIEWPORT_KEY.VIEW_MAIN);
|
|
1992
|
+
const clientHeight = document.body.clientHeight - startY - canvasOffset.top - EDITOR_BORDER_SIZE * 2;
|
|
1993
|
+
const clientWidth = document.body.clientWidth - startX - canvasOffset.left;
|
|
1994
|
+
let physicHeight = editorHeight;
|
|
1995
|
+
let scrollBar = viewportMain === null || viewportMain === void 0 ? void 0 : viewportMain.getScrollBar();
|
|
1996
|
+
if (physicHeight > clientHeight) {
|
|
1997
|
+
physicHeight = clientHeight;
|
|
1998
|
+
if (scrollBar == null) {
|
|
1999
|
+
if (viewportMain) new _univerjs_engine_render.ScrollBar(viewportMain, {
|
|
2000
|
+
enableHorizontal: false,
|
|
2001
|
+
barSize: 8
|
|
2002
|
+
});
|
|
2003
|
+
} else viewportMain === null || viewportMain === void 0 || viewportMain.resetCanvasSizeAndUpdateScroll();
|
|
2004
|
+
} else {
|
|
2005
|
+
var _viewportMain$getScro;
|
|
2006
|
+
scrollBar = null;
|
|
2007
|
+
viewportMain === null || viewportMain === void 0 || (_viewportMain$getScro = viewportMain.getScrollBar()) === null || _viewportMain$getScro === void 0 || _viewportMain$getScro.dispose();
|
|
2008
|
+
}
|
|
2009
|
+
editorWidth += (scrollBar === null || scrollBar === void 0 ? void 0 : scrollBar.barSize) || 0;
|
|
2010
|
+
editorWidth = Math.min(editorWidth, clientWidth);
|
|
2011
|
+
startX -= _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET;
|
|
2012
|
+
startY -= _univerjs_engine_render.FIX_ONE_PIXEL_BLUR_OFFSET;
|
|
2013
|
+
this._addBackground(editorScene, editorWidth / scaleX, editorHeight / scaleY, fill);
|
|
2014
|
+
const { scaleX: precisionScaleX, scaleY: precisionScaleY } = editorScene.getPrecisionScale();
|
|
2015
|
+
editorScene.transformByState({
|
|
2016
|
+
width: editorWidth * scaleAdjust / scaleX,
|
|
2017
|
+
height: editorHeight * scaleAdjust / scaleY,
|
|
2018
|
+
scaleX: scaleX * scaleAdjust,
|
|
2019
|
+
scaleY: scaleY * scaleAdjust
|
|
2020
|
+
});
|
|
2021
|
+
documentComponent.resize(editorWidth / scaleX, editorHeight / scaleY);
|
|
2022
|
+
/**
|
|
2023
|
+
* sometimes requestIdleCallback is invalid, so use setTimeout to ensure the successful execution of the resizeBySize method.
|
|
2024
|
+
* resize canvas
|
|
2025
|
+
* When modifying the selection area for a formula, it is necessary to add a setTimeout to ensure successful updating.
|
|
2026
|
+
*/
|
|
2027
|
+
setTimeout(() => {
|
|
2028
|
+
docEngine.resizeBySize((0, _univerjs_engine_render.fixLineWidthByScale)(editorWidth, precisionScaleX), (0, _univerjs_engine_render.fixLineWidthByScale)(physicHeight, precisionScaleY));
|
|
2029
|
+
}, 0);
|
|
2030
|
+
const contentBoundingRect = this._layoutService.getContentElement().getBoundingClientRect();
|
|
2031
|
+
const canvasBoundingRect = canvasElement.getBoundingClientRect();
|
|
2032
|
+
startX = startX * scaleAdjust + (canvasBoundingRect.left - contentBoundingRect.left);
|
|
2033
|
+
startY = startY * scaleAdjust + (canvasBoundingRect.top - contentBoundingRect.top);
|
|
2034
|
+
this._cellEditorManagerService.setState({
|
|
2035
|
+
startX,
|
|
2036
|
+
startY,
|
|
2037
|
+
endX: editorWidth * scaleAdjust + startX,
|
|
2038
|
+
endY: physicHeight * scaleAdjust + startY,
|
|
2039
|
+
show: true
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* Since the document does not support cell background color, an additional rect needs to be added.
|
|
2044
|
+
*/
|
|
2045
|
+
_addBackground(scene, editorWidth, editorHeight, fill) {
|
|
2046
|
+
const fillRectKey = "_backgroundRectHelperColor_";
|
|
2047
|
+
const rect = scene.getObject(fillRectKey);
|
|
2048
|
+
if (rect == null && fill == null) return;
|
|
2049
|
+
if (rect == null) scene.addObjects([new _univerjs_engine_render.Rect(fillRectKey, {
|
|
2050
|
+
width: editorWidth,
|
|
2051
|
+
height: editorHeight,
|
|
2052
|
+
fill,
|
|
2053
|
+
evented: false
|
|
2054
|
+
})], _univerjs_docs_ui.DOCS_COMPONENT_MAIN_LAYER_INDEX);
|
|
2055
|
+
else if (fill == null) rect.dispose();
|
|
2056
|
+
else {
|
|
2057
|
+
rect.setProps({ fill });
|
|
2058
|
+
rect.transformByState({
|
|
2059
|
+
width: editorWidth,
|
|
2060
|
+
height: editorHeight
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Show input area, resize input area and then place input to right place.
|
|
2066
|
+
* @TODO why do resize in show input area?
|
|
2067
|
+
* @param param
|
|
2068
|
+
*/
|
|
2069
|
+
_handleEditorVisible(param) {
|
|
2070
|
+
var _scene$getViewport, _this$_renderManagerS3;
|
|
2071
|
+
const { eventType } = param;
|
|
2072
|
+
this._cursorChange = [_univerjs_engine_render.DeviceInputEventType.PointerDown, _univerjs_engine_render.DeviceInputEventType.Dblclick].includes(eventType) ? CursorChange.CursorChange : CursorChange.StartEditor;
|
|
2073
|
+
const editCellState = this._editorBridgeService.getEditRectState();
|
|
2074
|
+
if (editCellState == null) return;
|
|
2075
|
+
const { position, documentLayoutObject, slideCardOffset: canvasOffset, scaleX, scaleY, editorUnitId, unitId } = editCellState;
|
|
2076
|
+
const editorObject = this._getEditorObject();
|
|
2077
|
+
if (editorObject == null) return;
|
|
2078
|
+
const { scene } = editorObject;
|
|
2079
|
+
this._contextService.setContextValue(_univerjs_core.EDITOR_ACTIVATED, true);
|
|
2080
|
+
const { documentModel: documentDataModel } = documentLayoutObject;
|
|
2081
|
+
const skeleton = this._getEditorSkeleton(editorUnitId);
|
|
2082
|
+
if (!skeleton || !documentDataModel) return;
|
|
2083
|
+
this._fitTextSize(position, canvasOffset, skeleton, documentLayoutObject, scaleX, scaleY);
|
|
2084
|
+
const cursor = documentDataModel.getBody().dataStream.length - 2 || 0;
|
|
2085
|
+
(_scene$getViewport = scene.getViewport(_univerjs_docs_ui.VIEWPORT_KEY.VIEW_MAIN)) === null || _scene$getViewport === void 0 || _scene$getViewport.scrollToViewportPos({ viewportScrollX: Number.POSITIVE_INFINITY });
|
|
2086
|
+
this._textSelectionManagerService.replaceTextRanges([{
|
|
2087
|
+
startOffset: cursor,
|
|
2088
|
+
endOffset: cursor
|
|
2089
|
+
}]);
|
|
2090
|
+
(_this$_renderManagerS3 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS3 === void 0 || _this$_renderManagerS3.scene.resetCursor();
|
|
2091
|
+
}
|
|
2092
|
+
_resetBodyStyle(body, removeStyle = false) {
|
|
2093
|
+
body.dataStream = _univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE;
|
|
2094
|
+
if (body.textRuns != null) if (body.textRuns.length === 1 && !removeStyle) {
|
|
2095
|
+
body.textRuns[0].st = 0;
|
|
2096
|
+
body.textRuns[0].ed = 1;
|
|
2097
|
+
} else body.textRuns = void 0;
|
|
2098
|
+
if (body.paragraphs != null) if (body.paragraphs.length === 1) body.paragraphs[0].startIndex = 0;
|
|
2099
|
+
else body.paragraphs = [{ startIndex: 0 }];
|
|
2100
|
+
if (body.sectionBreaks != null) body.sectionBreaks = void 0;
|
|
2101
|
+
if (body.tables != null) body.tables = void 0;
|
|
2102
|
+
if (body.customRanges != null) body.customRanges = void 0;
|
|
2103
|
+
if (body.customBlocks != null) body.customBlocks = void 0;
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Should activate the editor when the user inputs text.
|
|
2107
|
+
* @param d DisposableCollection
|
|
2108
|
+
*/
|
|
2109
|
+
_initialKeyboardListener(d) {}
|
|
2110
|
+
_showEditorByKeyboard(config) {
|
|
2111
|
+
if (config == null) {}
|
|
2112
|
+
}
|
|
2113
|
+
_commandExecutedListener(d) {
|
|
2114
|
+
const moveCursorOP = [SetTextEditArrowOperation.id];
|
|
2115
|
+
const editedMutations = [_univerjs_docs.RichTextEditingMutation.id];
|
|
2116
|
+
d.add(this._commandService.onCommandExecuted((command) => {
|
|
2117
|
+
if (this._editorService.getFocusId() !== SLIDE_EDITOR_ID) return;
|
|
2118
|
+
if (moveCursorOP.includes(command.id)) this._moveCursorCmdHandler(command);
|
|
2119
|
+
if (editedMutations.includes(command.id)) {
|
|
2120
|
+
if (this._editorBridgeService.isVisible()) this._editingChangedHandler();
|
|
2121
|
+
}
|
|
2122
|
+
}));
|
|
2123
|
+
}
|
|
2124
|
+
_moveCursorCmdHandler(command) {
|
|
2125
|
+
const params = command.params;
|
|
2126
|
+
const { keycode, isShift } = params;
|
|
2127
|
+
/**
|
|
2128
|
+
* After the user enters the editor and actively moves the editor selection area with the mouse,
|
|
2129
|
+
* the up, down, left, and right keys can no longer switch editing cells,
|
|
2130
|
+
* but move the cursor within the editor instead.
|
|
2131
|
+
*/
|
|
2132
|
+
if (keycode != null && this._cursorChange === CursorChange.CursorChange) this._moveInEditor(keycode, isShift);
|
|
2133
|
+
else this._editorBridgeService.changeVisible(params);
|
|
2134
|
+
}
|
|
2135
|
+
_editingChangedHandler() {
|
|
2136
|
+
const editRect = this._editorBridgeService.getEditorRect();
|
|
2137
|
+
if (!editRect) return;
|
|
2138
|
+
const editingRichText = editRect.richTextObj;
|
|
2139
|
+
editingRichText.refreshDocumentByDocData();
|
|
2140
|
+
editingRichText.resizeToContentSize();
|
|
2141
|
+
const { unitId } = this._renderContext;
|
|
2142
|
+
this._handleEditorVisible({
|
|
2143
|
+
visible: true,
|
|
2144
|
+
eventType: 3,
|
|
2145
|
+
unitId
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
_getEditorObject() {
|
|
2149
|
+
return getEditorObject(this._editorBridgeService.getCurrentEditorId(), this._renderManagerService);
|
|
2150
|
+
}
|
|
2151
|
+
async _handleEditorInvisible(param) {
|
|
2152
|
+
const { keycode } = param;
|
|
2153
|
+
this._cursorChange = CursorChange.InitialState;
|
|
2154
|
+
this._exitInput(param);
|
|
2155
|
+
if (this._editorBridgeService.getEditRectState() == null) return;
|
|
2156
|
+
if (this._editorBridgeService.getEditorDirty() === false) {
|
|
2157
|
+
this._moveCursor(keycode);
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
this._moveCursor(keycode);
|
|
2161
|
+
}
|
|
2162
|
+
_exitInput(param) {
|
|
2163
|
+
this._contextService.setContextValue(_univerjs_core.EDITOR_ACTIVATED, false);
|
|
2164
|
+
this._cellEditorManagerService.setState({ show: param.visible });
|
|
2165
|
+
const editorUnitId = this._editorBridgeService.getCurrentEditorId();
|
|
2166
|
+
if (editorUnitId == null) return;
|
|
2167
|
+
this._undoRedoService.clearUndoRedo(editorUnitId);
|
|
2168
|
+
}
|
|
2169
|
+
_moveCursor(keycode) {
|
|
2170
|
+
if (keycode == null) return;
|
|
2171
|
+
_univerjs_core.Direction.LEFT;
|
|
2172
|
+
switch (keycode) {
|
|
2173
|
+
case _univerjs_ui.KeyCode.ENTER:
|
|
2174
|
+
_univerjs_core.Direction.DOWN;
|
|
2175
|
+
break;
|
|
2176
|
+
case _univerjs_ui.KeyCode.TAB:
|
|
2177
|
+
_univerjs_core.Direction.RIGHT;
|
|
2178
|
+
break;
|
|
2179
|
+
case _univerjs_ui.KeyCode.ARROW_DOWN:
|
|
2180
|
+
_univerjs_core.Direction.DOWN;
|
|
2181
|
+
break;
|
|
2182
|
+
case _univerjs_ui.KeyCode.ARROW_UP:
|
|
2183
|
+
_univerjs_core.Direction.UP;
|
|
2184
|
+
break;
|
|
2185
|
+
case _univerjs_ui.KeyCode.ARROW_LEFT:
|
|
2186
|
+
_univerjs_core.Direction.LEFT;
|
|
2187
|
+
break;
|
|
2188
|
+
case _univerjs_ui.KeyCode.ARROW_RIGHT:
|
|
2189
|
+
_univerjs_core.Direction.RIGHT;
|
|
2190
|
+
break;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
/**
|
|
2194
|
+
* The user's operations follow the sequence of opening the editor and then moving the cursor.
|
|
2195
|
+
* The logic here predicts the user's first cursor movement behavior based on this rule
|
|
2196
|
+
*/
|
|
2197
|
+
_cursorStateListener(d) {
|
|
2198
|
+
const editorObject = this._getEditorObject();
|
|
2199
|
+
if (!editorObject) return;
|
|
2200
|
+
const { document: documentComponent } = editorObject;
|
|
2201
|
+
d.add((0, _univerjs_core.toDisposable)(documentComponent.onPointerDown$.subscribeEvent(() => {
|
|
2202
|
+
if (this._cursorChange === CursorChange.StartEditor) this._cursorChange = CursorChange.CursorChange;
|
|
2203
|
+
})));
|
|
2204
|
+
}
|
|
2205
|
+
_moveInEditor(keycode, isShift) {
|
|
2206
|
+
let direction = _univerjs_core.Direction.LEFT;
|
|
2207
|
+
if (keycode === _univerjs_ui.KeyCode.ARROW_DOWN) direction = _univerjs_core.Direction.DOWN;
|
|
2208
|
+
else if (keycode === _univerjs_ui.KeyCode.ARROW_UP) direction = _univerjs_core.Direction.UP;
|
|
2209
|
+
else if (keycode === _univerjs_ui.KeyCode.ARROW_RIGHT) direction = _univerjs_core.Direction.RIGHT;
|
|
2210
|
+
if (isShift) this._commandService.executeCommand(_univerjs_docs_ui.MoveSelectionOperation.id, { direction });
|
|
2211
|
+
else this._commandService.executeCommand(_univerjs_docs_ui.MoveCursorOperation.id, { direction });
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
SlideEditingRenderController = __decorate([
|
|
2215
|
+
__decorateParam(1, _univerjs_ui.ILayoutService),
|
|
2216
|
+
__decorateParam(2, _univerjs_core.IUndoRedoService),
|
|
2217
|
+
__decorateParam(3, _univerjs_core.IContextService),
|
|
2218
|
+
__decorateParam(4, _univerjs_core.IUniverInstanceService),
|
|
2219
|
+
__decorateParam(5, _univerjs_engine_render.IRenderManagerService),
|
|
2220
|
+
__decorateParam(6, ISlideEditorBridgeService),
|
|
2221
|
+
__decorateParam(7, ISlideEditorManagerService),
|
|
2222
|
+
__decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
|
|
2223
|
+
__decorateParam(9, _univerjs_core.ICommandService),
|
|
2224
|
+
__decorateParam(10, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
2225
|
+
__decorateParam(11, _univerjs_docs_ui.IEditorService)
|
|
2226
|
+
], SlideEditingRenderController);
|
|
2227
|
+
function getEditorObject(unitId, renderManagerService) {
|
|
2228
|
+
if (unitId == null) return;
|
|
2229
|
+
const currentRender = renderManagerService.getRenderById(unitId);
|
|
2230
|
+
if (currentRender == null) return;
|
|
2231
|
+
const { mainComponent, scene, engine, components } = currentRender;
|
|
2232
|
+
return {
|
|
2233
|
+
document: mainComponent,
|
|
2234
|
+
docBackground: components.get(_univerjs_docs_ui.DOCS_VIEW_KEY.BACKGROUND),
|
|
2235
|
+
scene,
|
|
2236
|
+
engine
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
//#endregion
|
|
2241
|
+
//#region src/controllers/slide-editor-bridge.render-controller.ts
|
|
2242
|
+
let SlideEditorBridgeRenderController = class SlideEditorBridgeRenderController extends _univerjs_core.RxDisposable {
|
|
2243
|
+
constructor(_renderContext, _instanceSrv, _commandService, _editorBridgeService) {
|
|
2244
|
+
super();
|
|
2245
|
+
this._renderContext = _renderContext;
|
|
2246
|
+
this._instanceSrv = _instanceSrv;
|
|
2247
|
+
this._commandService = _commandService;
|
|
2248
|
+
this._editorBridgeService = _editorBridgeService;
|
|
2249
|
+
_defineProperty(
|
|
2250
|
+
this,
|
|
2251
|
+
/**
|
|
2252
|
+
* It is used to distinguish whether the user has actively moved the cursor in the editor, mainly through mouse clicks.
|
|
2253
|
+
*/
|
|
2254
|
+
/** If the corresponding unit is active and prepared for editing. */
|
|
2255
|
+
"setSlideTextEditor$",
|
|
2256
|
+
new rxjs.Subject()
|
|
2257
|
+
);
|
|
2258
|
+
_defineProperty(this, "_curRichText", null);
|
|
2259
|
+
_defineProperty(this, "_d", void 0);
|
|
2260
|
+
this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).subscribe((slideDataModel) => {
|
|
2261
|
+
if (slideDataModel && slideDataModel.getUnitId() === this._renderContext.unitId) this._d = this._init();
|
|
2262
|
+
else this._disposeCurrent();
|
|
2263
|
+
}));
|
|
2264
|
+
}
|
|
2265
|
+
_init() {
|
|
2266
|
+
const d = new _univerjs_core.DisposableCollection();
|
|
2267
|
+
this._initEventListener(d);
|
|
2268
|
+
return d;
|
|
2269
|
+
}
|
|
2270
|
+
_disposeCurrent() {
|
|
2271
|
+
var _this$_d;
|
|
2272
|
+
(_this$_d = this._d) === null || _this$_d === void 0 || _this$_d.dispose();
|
|
2273
|
+
this._d = null;
|
|
2274
|
+
}
|
|
2275
|
+
_setEditorRect(pageId, targetObject) {
|
|
2276
|
+
this._curRichText = targetObject;
|
|
2277
|
+
const { scene, engine } = this._renderContext;
|
|
2278
|
+
const setEditorRect = {
|
|
2279
|
+
scene,
|
|
2280
|
+
engine,
|
|
2281
|
+
unitId: this._renderContext.unitId,
|
|
2282
|
+
pageId,
|
|
2283
|
+
richTextObj: targetObject
|
|
2284
|
+
};
|
|
2285
|
+
this._editorBridgeService.setEditorRect(setEditorRect);
|
|
2286
|
+
}
|
|
2287
|
+
_initEventListener(d) {
|
|
2288
|
+
const listenersForPageScene = (scene) => {
|
|
2289
|
+
const transformer = scene.getTransformer();
|
|
2290
|
+
if (!transformer) return;
|
|
2291
|
+
d.add(transformer.clearControl$.subscribe(() => {
|
|
2292
|
+
this.setEditorVisible(false);
|
|
2293
|
+
this.pickOtherObjects();
|
|
2294
|
+
}));
|
|
2295
|
+
d.add(transformer.createControl$.subscribe(() => {
|
|
2296
|
+
this.setEditorVisible(false);
|
|
2297
|
+
}));
|
|
2298
|
+
d.add(scene.onDblclick$.subscribeEvent(() => {
|
|
2299
|
+
transformer.clearControls();
|
|
2300
|
+
const object = transformer.getSelectedObjectMap().values().next().value;
|
|
2301
|
+
if (!object) return;
|
|
2302
|
+
if (object.objectType !== _univerjs_engine_render.ObjectType.RICH_TEXT) this.pickOtherObjects();
|
|
2303
|
+
else this.startEditing(scene.sceneKey, object);
|
|
2304
|
+
}));
|
|
2305
|
+
d.add(this._instanceSrv.focused$.subscribe((fc) => {
|
|
2306
|
+
this.endEditing();
|
|
2307
|
+
}));
|
|
2308
|
+
};
|
|
2309
|
+
const { mainComponent } = this._renderContext;
|
|
2310
|
+
mainComponent.subSceneChanged$.subscribeEvent((pageScene) => {
|
|
2311
|
+
listenersForPageScene(pageScene);
|
|
2312
|
+
});
|
|
2313
|
+
const pageSceneList = Array.from(mainComponent.getSubScenes().values());
|
|
2314
|
+
for (let i = 0; i < pageSceneList.length; i++) {
|
|
2315
|
+
const pageScene = pageSceneList[i];
|
|
2316
|
+
listenersForPageScene(pageScene);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
pickOtherObjects() {
|
|
2320
|
+
this.endEditing();
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* invoked when picking other object.
|
|
2324
|
+
*
|
|
2325
|
+
* save editing state to curr richText.
|
|
2326
|
+
*/
|
|
2327
|
+
endEditing() {
|
|
2328
|
+
var _curRichText$document;
|
|
2329
|
+
if (!this._curRichText) return;
|
|
2330
|
+
this.setEditorVisible(false);
|
|
2331
|
+
const curRichText = this._curRichText;
|
|
2332
|
+
if (!this._instanceSrv.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE)) return false;
|
|
2333
|
+
curRichText.refreshDocumentByDocData();
|
|
2334
|
+
curRichText.resizeToContentSize();
|
|
2335
|
+
this._editorBridgeService.endEditing$.next(curRichText);
|
|
2336
|
+
const richText = {
|
|
2337
|
+
bl: 1,
|
|
2338
|
+
fs: curRichText.fs,
|
|
2339
|
+
text: curRichText.text
|
|
2340
|
+
};
|
|
2341
|
+
const textRuns = (_curRichText$document = curRichText.documentData.body) === null || _curRichText$document === void 0 ? void 0 : _curRichText$document.textRuns;
|
|
2342
|
+
if (textRuns && textRuns.length) {
|
|
2343
|
+
const ts = textRuns[0].ts;
|
|
2344
|
+
richText.cl = ts === null || ts === void 0 ? void 0 : ts.cl;
|
|
2345
|
+
}
|
|
2346
|
+
this._commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
2347
|
+
unitId: this._renderContext.unitId,
|
|
2348
|
+
oKey: curRichText === null || curRichText === void 0 ? void 0 : curRichText.oKey,
|
|
2349
|
+
props: { richText }
|
|
2350
|
+
});
|
|
2351
|
+
this._curRichText = null;
|
|
2352
|
+
}
|
|
2353
|
+
/**
|
|
2354
|
+
* TODO calling twice ????
|
|
2355
|
+
* editingParam derives from RichText object.
|
|
2356
|
+
*
|
|
2357
|
+
* TODO @lumixraku need scale param
|
|
2358
|
+
* @param target
|
|
2359
|
+
*/
|
|
2360
|
+
startEditing(pageId, target) {
|
|
2361
|
+
this._setEditorRect(pageId, target);
|
|
2362
|
+
this.setEditorVisible(true);
|
|
2363
|
+
}
|
|
2364
|
+
setEditorVisible(visible) {
|
|
2365
|
+
if (visible) {
|
|
2366
|
+
var _this$_curRichText;
|
|
2367
|
+
(_this$_curRichText = this._curRichText) === null || _this$_curRichText === void 0 || _this$_curRichText.hide();
|
|
2368
|
+
} else {
|
|
2369
|
+
var _this$_curRichText2;
|
|
2370
|
+
(_this$_curRichText2 = this._curRichText) === null || _this$_curRichText2 === void 0 || _this$_curRichText2.show();
|
|
2371
|
+
}
|
|
2372
|
+
const { unitId } = this._renderContext;
|
|
2373
|
+
this._editorBridgeService.changeVisible({
|
|
2374
|
+
visible,
|
|
2375
|
+
eventType: _univerjs_engine_render.DeviceInputEventType.PointerDown,
|
|
2376
|
+
unitId
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
SlideEditorBridgeRenderController = __decorate([
|
|
2381
|
+
__decorateParam(1, _univerjs_core.IUniverInstanceService),
|
|
2382
|
+
__decorateParam(2, _univerjs_core.ICommandService),
|
|
2383
|
+
__decorateParam(3, ISlideEditorBridgeService)
|
|
2384
|
+
], SlideEditorBridgeRenderController);
|
|
2385
|
+
|
|
2386
|
+
//#endregion
|
|
2387
|
+
//#region src/services/slide-popup-manager.service.ts
|
|
2388
|
+
function transformBound2OffsetBound(originBound, scene) {
|
|
2389
|
+
const topLeft = transformPosition2Offset(originBound.left, originBound.top, scene);
|
|
2390
|
+
const bottomRight = transformPosition2Offset(originBound.right, originBound.bottom, scene);
|
|
2391
|
+
return {
|
|
2392
|
+
left: topLeft.x,
|
|
2393
|
+
top: topLeft.y,
|
|
2394
|
+
right: bottomRight.x,
|
|
2395
|
+
bottom: bottomRight.y
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
function transformPosition2Offset(x, y, scene) {
|
|
2399
|
+
const { scaleX, scaleY } = scene.getAncestorScale();
|
|
2400
|
+
const viewMain = scene.getViewport(_univerjs_slides.SLIDE_KEY.VIEW);
|
|
2401
|
+
if (!viewMain) return {
|
|
2402
|
+
x,
|
|
2403
|
+
y
|
|
2404
|
+
};
|
|
2405
|
+
const { viewportScrollX: actualScrollX, viewportScrollY: actualScrollY } = viewMain;
|
|
2406
|
+
return {
|
|
2407
|
+
x: (x - actualScrollX) * scaleX,
|
|
2408
|
+
y: (y - actualScrollY) * scaleY
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
let SlideCanvasPopMangerService = class SlideCanvasPopMangerService extends _univerjs_core.Disposable {
|
|
2412
|
+
constructor(_globalPopupManagerService, _renderManagerService, _univerInstanceService, _commandService) {
|
|
2413
|
+
super();
|
|
2414
|
+
this._globalPopupManagerService = _globalPopupManagerService;
|
|
2415
|
+
this._renderManagerService = _renderManagerService;
|
|
2416
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2417
|
+
this._commandService = _commandService;
|
|
2418
|
+
}
|
|
2419
|
+
_createObjectPositionObserver(targetObject, currentRender) {
|
|
2420
|
+
const calc = () => {
|
|
2421
|
+
var _currentRender$mainCo, _currentRender$mainCo2, _currentRender$mainCo3, _currentRender$mainCo4;
|
|
2422
|
+
const { scene, engine } = currentRender;
|
|
2423
|
+
const { left, top, width, height } = targetObject;
|
|
2424
|
+
const horizontalOffset = (scene.width - ((_currentRender$mainCo = (_currentRender$mainCo2 = currentRender.mainComponent) === null || _currentRender$mainCo2 === void 0 ? void 0 : _currentRender$mainCo2.width) !== null && _currentRender$mainCo !== void 0 ? _currentRender$mainCo : 0)) / 2;
|
|
2425
|
+
const verticalOffset = (scene.height - ((_currentRender$mainCo3 = (_currentRender$mainCo4 = currentRender.mainComponent) === null || _currentRender$mainCo4 === void 0 ? void 0 : _currentRender$mainCo4.height) !== null && _currentRender$mainCo3 !== void 0 ? _currentRender$mainCo3 : 0)) / 2;
|
|
2426
|
+
const bound = {
|
|
2427
|
+
left,
|
|
2428
|
+
right: left + width,
|
|
2429
|
+
top,
|
|
2430
|
+
bottom: top + height
|
|
2431
|
+
};
|
|
2432
|
+
const canvasElement = engine.getCanvasElement();
|
|
2433
|
+
const canvasClientRect = canvasElement.getBoundingClientRect();
|
|
2434
|
+
const widthOfCanvas = (0, _univerjs_engine_render.pxToNum)(canvasElement.style.width);
|
|
2435
|
+
const { scaleX, scaleY } = scene.getAncestorScale();
|
|
2436
|
+
const offsetBound = transformBound2OffsetBound(bound, scene);
|
|
2437
|
+
const { top: topOffset, left: leftOffset, width: domWidth } = canvasClientRect;
|
|
2438
|
+
const scaleAdjust = domWidth / widthOfCanvas;
|
|
2439
|
+
return {
|
|
2440
|
+
left: offsetBound.left * scaleAdjust * scaleX + leftOffset + horizontalOffset,
|
|
2441
|
+
right: offsetBound.right * scaleAdjust * scaleX + leftOffset + horizontalOffset,
|
|
2442
|
+
top: offsetBound.top * scaleAdjust * scaleY + topOffset + verticalOffset,
|
|
2443
|
+
bottom: offsetBound.bottom * scaleAdjust * scaleY + topOffset + verticalOffset
|
|
2444
|
+
};
|
|
2445
|
+
};
|
|
2446
|
+
const position = calc();
|
|
2447
|
+
return {
|
|
2448
|
+
position,
|
|
2449
|
+
position$: new rxjs.BehaviorSubject(position),
|
|
2450
|
+
disposable: new _univerjs_core.DisposableCollection()
|
|
2451
|
+
};
|
|
2452
|
+
}
|
|
2453
|
+
attachPopupToObject(targetObject, popup) {
|
|
2454
|
+
const unitId = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).getUnitId();
|
|
2455
|
+
const currentRender = this._renderManagerService.getRenderById(unitId);
|
|
2456
|
+
if (!currentRender) return { dispose: () => {} };
|
|
2457
|
+
const { position, position$, disposable } = this._createObjectPositionObserver(targetObject, currentRender);
|
|
2458
|
+
const id = this._globalPopupManagerService.addPopup({
|
|
2459
|
+
...popup,
|
|
2460
|
+
unitId,
|
|
2461
|
+
subUnitId: "default",
|
|
2462
|
+
anchorRect: position,
|
|
2463
|
+
anchorRect$: position$,
|
|
2464
|
+
canvasElement: currentRender.engine.getCanvasElement()
|
|
2465
|
+
});
|
|
2466
|
+
return { dispose: () => {
|
|
2467
|
+
this._globalPopupManagerService.removePopup(id);
|
|
2468
|
+
position$.complete();
|
|
2469
|
+
disposable.dispose();
|
|
2470
|
+
} };
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
SlideCanvasPopMangerService = __decorate([
|
|
2474
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ICanvasPopupService)),
|
|
2475
|
+
__decorateParam(1, _univerjs_engine_render.IRenderManagerService),
|
|
2476
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
2477
|
+
__decorateParam(3, _univerjs_core.ICommandService)
|
|
2478
|
+
], SlideCanvasPopMangerService);
|
|
2479
|
+
|
|
2480
|
+
//#endregion
|
|
2481
|
+
//#region src/menu/popup-menu.controller.ts
|
|
2482
|
+
let SlidePopupMenuController = class SlidePopupMenuController extends _univerjs_core.RxDisposable {
|
|
2483
|
+
constructor(_canvasPopManagerService, _renderManagerService, _univerInstanceService, _contextService, _canvasView, _sidebarService, _commandService) {
|
|
2484
|
+
super();
|
|
2485
|
+
this._canvasPopManagerService = _canvasPopManagerService;
|
|
2486
|
+
this._renderManagerService = _renderManagerService;
|
|
2487
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2488
|
+
this._contextService = _contextService;
|
|
2489
|
+
this._canvasView = _canvasView;
|
|
2490
|
+
this._sidebarService = _sidebarService;
|
|
2491
|
+
this._commandService = _commandService;
|
|
2492
|
+
_defineProperty(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
|
|
2493
|
+
this._init();
|
|
2494
|
+
}
|
|
2495
|
+
_init() {
|
|
2496
|
+
this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).forEach((slide) => this._create(slide));
|
|
2497
|
+
}
|
|
2498
|
+
_create(slide) {
|
|
2499
|
+
if (!slide) return;
|
|
2500
|
+
const unitId = slide.getUnitId();
|
|
2501
|
+
if (this._renderManagerService.has(unitId) && !this._initImagePopupMenu.has(unitId)) {
|
|
2502
|
+
this._popupMenuListener(unitId);
|
|
2503
|
+
this._initImagePopupMenu.add(unitId);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
_hasCropObject(scene) {}
|
|
2507
|
+
_popupMenuListener(unitId) {
|
|
2508
|
+
var _model$getPages;
|
|
2509
|
+
const model = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE);
|
|
2510
|
+
const pages = (_model$getPages = model === null || model === void 0 ? void 0 : model.getPages()) !== null && _model$getPages !== void 0 ? _model$getPages : {};
|
|
2511
|
+
Object.keys(pages).forEach((pageId) => {
|
|
2512
|
+
var _page$scene;
|
|
2513
|
+
const transformer = (_page$scene = this._canvasView.getRenderUnitByPageId(pageId, unitId).scene) === null || _page$scene === void 0 ? void 0 : _page$scene.getTransformer();
|
|
2514
|
+
if (!transformer) return;
|
|
2515
|
+
let singletonPopupDisposer;
|
|
2516
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.createControl$.subscribe(() => {
|
|
2517
|
+
const selectedObjects = transformer.getSelectedObjectMap();
|
|
2518
|
+
if (selectedObjects.size > 1) {
|
|
2519
|
+
singletonPopupDisposer === null || singletonPopupDisposer === void 0 || singletonPopupDisposer.dispose();
|
|
2520
|
+
return;
|
|
2521
|
+
}
|
|
2522
|
+
const object = selectedObjects.values().next().value;
|
|
2523
|
+
if (!object) return;
|
|
2524
|
+
const oKey = object.oKey;
|
|
2525
|
+
singletonPopupDisposer === null || singletonPopupDisposer === void 0 || singletonPopupDisposer.dispose();
|
|
2526
|
+
singletonPopupDisposer = this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {
|
|
2527
|
+
componentKey: COMPONENT_SLIDE_IMAGE_POPUP_MENU,
|
|
2528
|
+
direction: "horizontal",
|
|
2529
|
+
offset: [2, 0],
|
|
2530
|
+
extraProps: { menuItems: this._getMenuItemsByObjectType(object.objectType, oKey, unitId) }
|
|
2531
|
+
}));
|
|
2532
|
+
if (this._sidebarService.visible) this._commandService.executeCommand(ToggleSlideEditSidebarOperation.id, {
|
|
2533
|
+
visible: true,
|
|
2534
|
+
objectType: object.objectType
|
|
2535
|
+
});
|
|
2536
|
+
})));
|
|
2537
|
+
this.disposeWithMe(transformer.clearControl$.subscribe(() => {
|
|
2538
|
+
singletonPopupDisposer === null || singletonPopupDisposer === void 0 || singletonPopupDisposer.dispose();
|
|
2539
|
+
this._contextService.setContextValue(_univerjs_core.FOCUSING_COMMON_DRAWINGS, false);
|
|
2540
|
+
}));
|
|
2541
|
+
this.disposeWithMe(transformer.changing$.subscribe(() => {
|
|
2542
|
+
singletonPopupDisposer === null || singletonPopupDisposer === void 0 || singletonPopupDisposer.dispose();
|
|
2543
|
+
const selectedObjects = transformer.getSelectedObjectMap();
|
|
2544
|
+
if (selectedObjects.size > 1) {
|
|
2545
|
+
singletonPopupDisposer === null || singletonPopupDisposer === void 0 || singletonPopupDisposer.dispose();
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
const object = selectedObjects.values().next().value;
|
|
2549
|
+
if (!object) return;
|
|
2550
|
+
this._commandService.executeCommand(UpdateSlideElementOperation.id, {
|
|
2551
|
+
unitId,
|
|
2552
|
+
oKey: object.oKey,
|
|
2553
|
+
props: {
|
|
2554
|
+
width: object.width,
|
|
2555
|
+
height: object.height,
|
|
2556
|
+
left: object.left,
|
|
2557
|
+
top: object.top
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
}));
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
_getMenuItemsByObjectType(objectType, oKey, unitId) {
|
|
2564
|
+
return [{
|
|
2565
|
+
label: "slide.popup.edit",
|
|
2566
|
+
index: 0,
|
|
2567
|
+
commandId: ToggleSlideEditSidebarOperation.id,
|
|
2568
|
+
commandParams: {
|
|
2569
|
+
visible: true,
|
|
2570
|
+
objectType
|
|
2571
|
+
},
|
|
2572
|
+
disable: false
|
|
2573
|
+
}, {
|
|
2574
|
+
label: "slide.popup.delete",
|
|
2575
|
+
index: 5,
|
|
2576
|
+
commandId: DeleteSlideElementOperation.id,
|
|
2577
|
+
commandParams: {
|
|
2578
|
+
id: oKey,
|
|
2579
|
+
unitId
|
|
2580
|
+
},
|
|
2581
|
+
disable: false
|
|
2582
|
+
}];
|
|
2583
|
+
}
|
|
2584
|
+
};
|
|
2585
|
+
SlidePopupMenuController = __decorate([
|
|
2586
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(SlideCanvasPopMangerService)),
|
|
2587
|
+
__decorateParam(1, _univerjs_engine_render.IRenderManagerService),
|
|
2588
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
2589
|
+
__decorateParam(3, _univerjs_core.IContextService),
|
|
2590
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(CanvasView)),
|
|
2591
|
+
__decorateParam(5, _univerjs_ui.ISidebarService),
|
|
2592
|
+
__decorateParam(6, _univerjs_core.ICommandService)
|
|
2593
|
+
], SlidePopupMenuController);
|
|
2594
|
+
|
|
2595
|
+
//#endregion
|
|
2596
|
+
//#region src/services/slide-render.service.ts
|
|
2597
|
+
let SlideRenderService = class SlideRenderService extends _univerjs_core.RxDisposable {
|
|
2598
|
+
constructor(_contextService, _instanceSrv, _renderManagerService) {
|
|
2599
|
+
super();
|
|
2600
|
+
this._contextService = _contextService;
|
|
2601
|
+
this._instanceSrv = _instanceSrv;
|
|
2602
|
+
this._renderManagerService = _renderManagerService;
|
|
2603
|
+
Promise.resolve().then(() => this._init());
|
|
2604
|
+
}
|
|
2605
|
+
_init() {
|
|
2606
|
+
this._initSlideDataListener();
|
|
2607
|
+
this._initContextListener();
|
|
2608
|
+
}
|
|
2609
|
+
_initSlideDataListener() {
|
|
2610
|
+
this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((slideModel) => {
|
|
2611
|
+
this._createRenderer(slideModel === null || slideModel === void 0 ? void 0 : slideModel.getUnitId());
|
|
2612
|
+
});
|
|
2613
|
+
this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).forEach((slideModel) => {
|
|
2614
|
+
this._createRenderer(slideModel.getUnitId());
|
|
2615
|
+
});
|
|
2616
|
+
this._instanceSrv.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SLIDE).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((workbook) => this._disposeRenderer(workbook));
|
|
2617
|
+
}
|
|
2618
|
+
_createRenderer(unitId) {
|
|
2619
|
+
if (unitId == null) return;
|
|
2620
|
+
if (this._instanceSrv.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SLIDE) == null) return;
|
|
2621
|
+
this._renderManagerService.createRender(unitId);
|
|
2622
|
+
}
|
|
2623
|
+
_disposeRenderer(workbook) {
|
|
2624
|
+
const unitId = workbook.getUnitId();
|
|
2625
|
+
this._renderManagerService.removeRender(unitId);
|
|
2626
|
+
}
|
|
2627
|
+
_initContextListener() {}
|
|
2628
|
+
};
|
|
2629
|
+
SlideRenderService = __decorate([
|
|
2630
|
+
__decorateParam(0, _univerjs_core.IContextService),
|
|
2631
|
+
__decorateParam(1, _univerjs_core.IUniverInstanceService),
|
|
2632
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService)
|
|
2633
|
+
], SlideRenderService);
|
|
2634
|
+
|
|
2635
|
+
//#endregion
|
|
2636
|
+
//#region src/plugin.ts
|
|
2637
|
+
let UniverSlidesUIPlugin = class UniverSlidesUIPlugin extends _univerjs_core.Plugin {
|
|
2638
|
+
constructor(_config = defaultPluginConfig, _injector, _renderManagerService, _univerInstanceService, _configService) {
|
|
2639
|
+
super();
|
|
2640
|
+
this._config = _config;
|
|
2641
|
+
this._injector = _injector;
|
|
2642
|
+
this._renderManagerService = _renderManagerService;
|
|
2643
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2644
|
+
this._configService = _configService;
|
|
2645
|
+
const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
2646
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
2647
|
+
this._configService.setConfig(SLIDES_UI_PLUGIN_CONFIG_KEY, rest);
|
|
2648
|
+
}
|
|
2649
|
+
onStarting() {
|
|
2650
|
+
(0, _univerjs_core.mergeOverrideWithDependencies)([
|
|
2651
|
+
[SlideRenderService],
|
|
2652
|
+
[ISlideEditorBridgeService, { useClass: SlideEditorBridgeService }],
|
|
2653
|
+
[ISlideEditorManagerService, { useClass: SlideEditorManagerService }],
|
|
2654
|
+
[SlideCanvasPopMangerService]
|
|
2655
|
+
], this._config.override).forEach((d) => this._injector.add(d));
|
|
2656
|
+
}
|
|
2657
|
+
onReady() {
|
|
2658
|
+
[[SlideRenderController]].forEach((m) => {
|
|
2659
|
+
this.disposeWithMe(this._renderManagerService.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SLIDE, m));
|
|
2660
|
+
});
|
|
2661
|
+
(0, _univerjs_core.mergeOverrideWithDependencies)([
|
|
2662
|
+
[CanvasView],
|
|
2663
|
+
[SlidesUIController],
|
|
2664
|
+
[SlideRenderController],
|
|
2665
|
+
[SlidePopupMenuController]
|
|
2666
|
+
], this._config.override).forEach((m) => {
|
|
2667
|
+
this._injector.add(m);
|
|
2668
|
+
});
|
|
2669
|
+
this._injector.get(CanvasView);
|
|
2670
|
+
this._injector.get(SlideRenderService);
|
|
2671
|
+
}
|
|
2672
|
+
onRendered() {
|
|
2673
|
+
[[SlideEditorBridgeRenderController], [SlideEditingRenderController]].forEach((m) => {
|
|
2674
|
+
this.disposeWithMe(this._renderManagerService.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SLIDE, m));
|
|
2675
|
+
});
|
|
2676
|
+
this._markSlideAsFocused();
|
|
2677
|
+
this._injector.get(SlidesUIController);
|
|
2678
|
+
}
|
|
2679
|
+
onSteady() {
|
|
2680
|
+
this._injector.get(SlidePopupMenuController);
|
|
2681
|
+
}
|
|
2682
|
+
_markSlideAsFocused() {
|
|
2683
|
+
const currentService = this._univerInstanceService;
|
|
2684
|
+
try {
|
|
2685
|
+
const slideDataModel = currentService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SLIDE);
|
|
2686
|
+
currentService.focusUnit(slideDataModel.getUnitId());
|
|
2687
|
+
} catch (e) {}
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
_defineProperty(UniverSlidesUIPlugin, "pluginName", "UNIVER_SLIDES_UI_PLUGIN");
|
|
2691
|
+
_defineProperty(UniverSlidesUIPlugin, "packageName", name);
|
|
2692
|
+
_defineProperty(UniverSlidesUIPlugin, "version", version);
|
|
2693
|
+
_defineProperty(UniverSlidesUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SLIDE);
|
|
2694
|
+
UniverSlidesUIPlugin = __decorate([
|
|
2695
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
2696
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService),
|
|
2697
|
+
__decorateParam(3, _univerjs_core.IUniverInstanceService),
|
|
2698
|
+
__decorateParam(4, _univerjs_core.IConfigService)
|
|
2699
|
+
], UniverSlidesUIPlugin);
|
|
2700
|
+
|
|
2701
|
+
//#endregion
|
|
2702
|
+
exports.ActivateSlidePageOperation = ActivateSlidePageOperation;
|
|
2703
|
+
exports.AppendSlideOperation = AppendSlideOperation;
|
|
2704
|
+
Object.defineProperty(exports, 'CanvasView', {
|
|
2705
|
+
enumerable: true,
|
|
2706
|
+
get: function () {
|
|
2707
|
+
return CanvasView;
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
exports.DeleteSlideElementOperation = DeleteSlideElementOperation;
|
|
2711
|
+
exports.ISlideEditorBridgeService = ISlideEditorBridgeService;
|
|
2712
|
+
exports.InsertSlideFloatImageCommand = InsertSlideFloatImageCommand;
|
|
2713
|
+
exports.InsertSlideShapeEllipseCommand = InsertSlideShapeEllipseCommand;
|
|
2714
|
+
exports.InsertSlideShapeEllipseOperation = InsertSlideShapeEllipseOperation;
|
|
2715
|
+
exports.InsertSlideShapeRectangleCommand = InsertSlideShapeRectangleCommand;
|
|
2716
|
+
exports.InsertSlideShapeRectangleOperation = InsertSlideShapeRectangleOperation;
|
|
2717
|
+
exports.SHAPE_MENU_ID = SHAPE_MENU_ID;
|
|
2718
|
+
exports.SLIDES_IMAGE_MENU_ID = SLIDES_IMAGE_MENU_ID;
|
|
2719
|
+
exports.SLIDE_EDITOR_ID = SLIDE_EDITOR_ID;
|
|
2720
|
+
exports.SetSlidePageThumbOperation = SetSlidePageThumbOperation;
|
|
2721
|
+
exports.SlideAddTextCommand = SlideAddTextCommand;
|
|
2722
|
+
exports.SlideAddTextOperation = SlideAddTextOperation;
|
|
2723
|
+
Object.defineProperty(exports, 'SlideCanvasPopMangerService', {
|
|
2724
|
+
enumerable: true,
|
|
2725
|
+
get: function () {
|
|
2726
|
+
return SlideCanvasPopMangerService;
|
|
2727
|
+
}
|
|
2728
|
+
});
|
|
2729
|
+
exports.SlideEditorContainer = SlideEditorContainer;
|
|
2730
|
+
exports.SlideSideBar = SlideSideBar;
|
|
2731
|
+
Object.defineProperty(exports, 'SlidesUIController', {
|
|
2732
|
+
enumerable: true,
|
|
2733
|
+
get: function () {
|
|
2734
|
+
return SlidesUIController;
|
|
2735
|
+
}
|
|
2736
|
+
});
|
|
2737
|
+
exports.SlidesUIMenuSchema = menuSchema;
|
|
2738
|
+
Object.defineProperty(exports, 'UniverSlidesUIPlugin', {
|
|
2739
|
+
enumerable: true,
|
|
2740
|
+
get: function () {
|
|
2741
|
+
return UniverSlidesUIPlugin;
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
exports.UpdateSlideElementOperation = UpdateSlideElementOperation;
|