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