@univerjs/preset-docs-core 0.6.10-nightly.202504241607 → 0.6.10-nightly.202504261606

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.
Files changed (2) hide show
  1. package/lib/umd/index.js +2 -2
  2. package/package.json +9 -9
package/lib/umd/index.js CHANGED
@@ -21,7 +21,7 @@
21
21
  `,children:a.items.map(l=>C.jsxs("li",{className:`
22
22
  univer-flex univer-h-10 univer-items-center univer-justify-between univer-text-[13px]
23
23
  last:univer-border-b-0
24
- `,children:[C.jsx("span",{className:"univer-line-clamp-1",children:l.title}),l.shortcut&&C.jsx(R.KBD,{keyboard:l.shortcut})]},`${l.title}-${l.shortcut}`))})]},a.name))})}var H4=Object.getOwnPropertyDescriptor,I4=(e,t,n,r)=>{for(var i=r>1?void 0:r?H4(t,n):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},De=(e,t)=>(n,r)=>t(n,r,e);const O4={id:Oe.id,binding:S1.CTRL_COMMAND|re.BACK_SLASH,description:"shortcut.shortcut-panel",group:"10_global-shortcut"};h.ShortcutPanelController=class extends m.Disposable{constructor(t,n,r,i,o){super(),this._menuManagerService=i,this.disposeWithMe(n.register(Zr,E4)),this.disposeWithMe(o.registerCommand(Oe)),this.disposeWithMe(r.registerShortcut(O4))}},h.ShortcutPanelController=I4([De(0,m.Inject(m.Injector)),De(1,m.Inject(T1)),De(2,Ce),De(3,q1),De(4,m.ICommandService)],h.ShortcutPanelController);const Te=m.createIdentifier("univer.ui.ui-controller");var d1=(e=>(e.GLOBAL="global",e.HEADER="header",e.HEADER_MENU="header-menu",e.CONTENT="content",e.FOOTER="footer",e.LEFT_SIDEBAR="left-sidebar",e.FLOATING="floating",e.UNIT="unit",e.CUSTOM_HEADER="custom-header",e.CUSTOM_LEFT="custom-left",e.CUSTOM_RIGHT="custom-right",e.CUSTOM_FOOTER="custom-footer",e.TOOLBAR="toolbar",e))(d1||{});const F1=m.createIdentifier("ui.parts.service");class Et extends m.Disposable{constructor(){super(...arguments);J(this,"_componentsByPart",new Map);J(this,"_componentRegistered$",new X.Subject);J(this,"componentRegistered$",this._componentRegistered$.asObservable());J(this,"_uiVisible",new Map);J(this,"_uiVisibleChange$",new X.Subject);J(this,"uiVisibleChange$",this._uiVisibleChange$.asObservable())}dispose(){super.dispose(),this._componentRegistered$.complete()}setUIVisible(n,r){this._uiVisible.set(n,r),this._uiVisibleChange$.next({ui:n,visible:r})}isUIVisible(n){var r;return(r=this._uiVisible.get(n))!=null?r:!0}registerComponent(n,r){const i=r(),o=(this._componentsByPart.get(n)||this._componentsByPart.set(n,new Set).get(n)).add(i);return this._componentRegistered$.next(n),m.toDisposable(()=>{o.delete(i),o.size===0&&this._componentsByPart.delete(n),this._componentRegistered$.next(n)})}getComponents(n){return new Set([...this._componentsByPart.get(n)||new Set])}}class Re{constructor(){J(this,"_domLayerMap",new Map);J(this,"_domLayers$",new X.BehaviorSubject([]));J(this,"domLayers$",this._domLayers$.asObservable())}get domLayers(){return Array.from(this._domLayerMap.entries())}_notice(){this._domLayers$.next(Array.from(this._domLayerMap.entries()))}addFloatDom(t){this._domLayerMap.set(t.id,t),this._notice()}removeFloatDom(t){this._domLayerMap.delete(t)&&this._notice()}removeAll(){this._domLayerMap.clear(),this._notice()}}const n9=s.memo(e=>{var D,k;const{layer:t,id:n}=e,r=s.useMemo(()=>t.position$.pipe(X.distinctUntilChanged((I,N)=>I.absolute.left===N.absolute.left&&I.absolute.top===N.absolute.top&&I.endX-I.startX===N.endX-N.startX&&I.endY-I.startY===N.endY-N.startY)),[t.position$]),i=B.useDependency(m.IUniverInstanceService),o=B.useObservable(s.useMemo(()=>t.position$.pipe(X.first()),[t.position$])),a=s.useRef(null),l=s.useRef(null),f=s.useRef(`transform: rotate(${o==null?void 0:o.rotate}deg) translate(${o==null?void 0:o.startX}px, ${o==null?void 0:o.startY}px)`),v=s.useRef((D=o==null?void 0:o.startY)!=null?D:0),b=s.useRef((k=o==null?void 0:o.startX)!=null?k:0),u=s.useRef({}),p=typeof t.componentKey=="string"?B.useDependency(T1).get(t.componentKey):t.componentKey,L=s.useMemo(()=>({data:t.data,...t.props}),[t.data,t.props]);s.useEffect(()=>{const I=t.position$.subscribe(w=>{var O;f.current=`rotate(${w.rotate}deg)`,v.current=w.startY,b.current=w.startX,a.current&&(a.current.style.transform=f.current,a.current.style.top=`${v.current}px`,a.current.style.left=`${b.current}px`,a.current.style.opacity=`${(O=w.opacity)!=null?O:1}`)}),N=r.subscribe(w=>{if(a.current&&(a.current.style.width=`${Math.max(w.endX-w.startX-2,0)}px`,a.current.style.height=`${Math.max(w.endY-w.startY-2,0)}px`),l.current){const O={width:`${w.width-4}px`,height:`${w.height-4}px`,left:`${w.absolute.left?0:"auto"}`,top:`${w.absolute.top?0:"auto"}`,right:`${w.absolute.left?"auto":0}`,bottom:`${w.absolute.top?"auto":0}`};l.current.style.width=O.width,l.current.style.height=O.height,l.current.style.left=O.left,l.current.style.top=O.top,l.current.style.right=O.right,l.current.style.bottom=O.bottom,u.current=O}});return()=>{I.unsubscribe(),N.unsubscribe()}},[t.position$,r]);const E=i.getUnit(t.unitId),H=E instanceof m.DocumentDataModel?E.getDisabled():void 0,g=s.useMemo(()=>p?C.jsx(p,{...L,unitId:t.unitId,unit:E,floatDomId:t.id,context:{docDisabled:H,root:l}}):null,[p,L]);return o?C.jsx("div",{ref:a,className:"univer-z-10",style:{position:"absolute",top:v.current,left:b.current,width:Math.max(o.endX-o.startX-2,0),height:Math.max(o.endY-o.startY-2,0),transform:f.current,overflow:"hidden",transformOrigin:"center center"},onPointerMove:I=>{t.onPointerMove(I.nativeEvent)},onPointerDown:I=>{t.onPointerDown(I.nativeEvent)},onPointerUp:I=>{t.onPointerUp(I.nativeEvent)},onWheel:I=>{t.onWheel(I.nativeEvent)},children:C.jsx("div",{id:n,ref:l,className:"univer-overflow-hidden",style:{position:"absolute",...u.current},children:g})}):null}),Ht=({unitId:e})=>{var o,a;const t=B.useDependency(m.IUniverInstanceService),n=B.useDependency(Re),r=B.useObservable(n.domLayers$),i=e||((o=t.getFocusedUnit())==null?void 0:o.getUnitId());return(a=r==null?void 0:r.filter(l=>l[1].unitId===i))==null?void 0:a.map(l=>C.jsx(n9,{id:l[0],layer:l[1]},l[0]))},We=m.createIdentifier("ui.popup.service");class It extends m.Disposable{constructor(){super(...arguments);J(this,"_popupMap",new Map);J(this,"_popups$",new X.BehaviorSubject([]));J(this,"popups$",this._popups$.asObservable());J(this,"_activePopupId",null)}get popups(){return Array.from(this._popupMap.entries())}get activePopupId(){return this._activePopupId}_update(){this._popups$.next(Array.from(this._popupMap.entries()))}dispose(){super.dispose(),this._popups$.next([]),this._popups$.complete(),this._popupMap.clear()}addPopup(n){const r=m.Tools.generateRandomId();return this._popupMap.set(r,{...n,onActiveChange:i=>{i?this._activePopupId=r:this._activePopupId===r&&(this._activePopupId=null)}}),this._update(),r}removePopup(n){this._popupMap.delete(n)&&this._update()}removeAll(){this._popupMap.clear(),this._update()}}const D4=({popup:e,children:t})=>{const[n,r]=s.useState(!1),i=s.useMemo(()=>e.anchorRect$.pipe(X.throttleTime(0,X.animationFrameScheduler),X.map(u=>{var k;const{bottom:p,left:L,right:E,top:H}=u,[g=0,D=0]=(k=e.offset)!=null?k:[];return{left:L-g,right:E+g,top:H-D,bottom:p+D}})),[e.anchorRect$,e.offset]),o=s.useMemo(()=>{var u,p;return(p=(u=e.hiddenRects$)==null?void 0:u.pipe(X.throttleTime(0,X.animationFrameScheduler)))!=null?p:X.of([])},[e.hiddenRects$]),a=s.useMemo(()=>{var u;return(u=e.excludeRects$)==null?void 0:u.pipe(X.throttleTime(0,X.animationFrameScheduler))},[e.excludeRects$]),l=wr(a,e.excludeRects),{canvasElement:f,hideOnInvisible:v=!0,hiddenType:b="destroy"}=e;return s.useEffect(()=>{if(!v)return;const u=X.combineLatest([i,o]).subscribe(([p,L])=>{const E=f.getBoundingClientRect(),{top:H,left:g,bottom:D,right:k}=E,I=p.bottom-p.top,N=p.right-p.left,w=L.some(O=>p.top>=O.top-.5*I&&p.bottom<=O.bottom+.5*I&&p.left>=O.left-.5*N&&p.right<=O.right+.5*N);p.bottom<H||p.top>D||p.right<g||p.left>k||w?r(!0):r(!1)});return()=>u.unsubscribe()},[f,v,i,o]),n&&b==="destroy"?null:C.jsx(Be,{...e,hidden:n,anchorRect$:i,direction:e.direction,onClickOutside:e.onClickOutside,excludeOutside:e.excludeOutside,excludeRects:l,...e.customActive?null:{onPointerEnter:()=>{var u;return(u=e.onActiveChange)==null?void 0:u.call(e,!0)},onPointerLeave:()=>{var u;return(u=e.onActiveChange)==null?void 0:u.call(e,!1)}},onClick:e.onClick,onContextMenu:e.onContextMenu,children:t})};function Ot(){const e=B.useDependency(We),t=B.useDependency(T1);return B.useObservable(e.popups$,void 0,!0).map(r=>{const[i,o]=r,a=t.get(o.componentKey);return C.jsx(D4,{popup:o,children:a?C.jsx(a,{popup:o}):null},i)})}function E1(e){const{components:t,fallback:n,sharedProps:r}=e;return!t||t.size===0?n!=null?n:null:Array.from(t.values()).map((i,o)=>{var a;return s.createElement(i,{key:`${(a=i.displayName)!=null?a:o}`,...r})})}function H1(e,t){var l;const n=(l=t==null?void 0:t.get(F1))!=null?l:B.useDependency(F1),r=s.useMemo(()=>n.uiVisibleChange$.pipe(X.filter(f=>f.ui===e)),[e,n]),i=B.useObservable(r),o=s.useRef(0),a=B.useObservable(()=>n.componentRegistered$.pipe(X.filter(f=>f===e),X.debounceTime(200),X.map(()=>o.current+=1),X.startWith(o.current+=1)),void 0,void 0,[n,e,i]);return s.useMemo(()=>n.isUIVisible(e)?n.getComponents(e):new Set,[a])}function Dt(e){const{children:t,className:n,style:r,disabled:i=!1,active:o=!1,noIcon:a,onClick:l,onDoubleClick:f,...v}=e,b=p=>{if(i){p.preventDefault();return}l&&l(p)},u=p=>{if(i){p.preventDefault();return}f&&f(p)};return C.jsx("button",{type:"button",className:R.clsx(`
24
+ `,children:[C.jsx("span",{className:"univer-line-clamp-1",children:l.title}),l.shortcut&&C.jsx(R.KBD,{keyboard:l.shortcut})]},`${l.title}-${l.shortcut}`))})]},a.name))})}var H4=Object.getOwnPropertyDescriptor,I4=(e,t,n,r)=>{for(var i=r>1?void 0:r?H4(t,n):t,o=e.length-1,a;o>=0;o--)(a=e[o])&&(i=a(i)||i);return i},De=(e,t)=>(n,r)=>t(n,r,e);const O4={id:Oe.id,binding:S1.CTRL_COMMAND|re.BACK_SLASH,description:"shortcut.shortcut-panel",group:"10_global-shortcut"};h.ShortcutPanelController=class extends m.Disposable{constructor(t,n,r,i,o){super(),this._menuManagerService=i,this.disposeWithMe(n.register(Zr,E4)),this.disposeWithMe(o.registerCommand(Oe)),this.disposeWithMe(r.registerShortcut(O4))}},h.ShortcutPanelController=I4([De(0,m.Inject(m.Injector)),De(1,m.Inject(T1)),De(2,Ce),De(3,q1),De(4,m.ICommandService)],h.ShortcutPanelController);const Te=m.createIdentifier("univer.ui.ui-controller");var d1=(e=>(e.GLOBAL="global",e.HEADER="header",e.HEADER_MENU="header-menu",e.CONTENT="content",e.FOOTER="footer",e.LEFT_SIDEBAR="left-sidebar",e.FLOATING="floating",e.UNIT="unit",e.CUSTOM_HEADER="custom-header",e.CUSTOM_LEFT="custom-left",e.CUSTOM_RIGHT="custom-right",e.CUSTOM_FOOTER="custom-footer",e.TOOLBAR="toolbar",e))(d1||{});const F1=m.createIdentifier("ui.parts.service");class Et extends m.Disposable{constructor(){super(...arguments);J(this,"_componentsByPart",new Map);J(this,"_componentRegistered$",new X.Subject);J(this,"componentRegistered$",this._componentRegistered$.asObservable());J(this,"_uiVisible",new Map);J(this,"_uiVisibleChange$",new X.Subject);J(this,"uiVisibleChange$",this._uiVisibleChange$.asObservable())}dispose(){super.dispose(),this._componentRegistered$.complete()}setUIVisible(n,r){this._uiVisible.set(n,r),this._uiVisibleChange$.next({ui:n,visible:r})}isUIVisible(n){var r;return(r=this._uiVisible.get(n))!=null?r:!0}registerComponent(n,r){const i=r(),o=(this._componentsByPart.get(n)||this._componentsByPart.set(n,new Set).get(n)).add(i);return this._componentRegistered$.next(n),m.toDisposable(()=>{o.delete(i),o.size===0&&this._componentsByPart.delete(n),this._componentRegistered$.next(n)})}getComponents(n){return new Set([...this._componentsByPart.get(n)||new Set])}}class Re{constructor(){J(this,"_domLayerMap",new Map);J(this,"_domLayers$",new X.BehaviorSubject([]));J(this,"domLayers$",this._domLayers$.asObservable())}get domLayers(){return Array.from(this._domLayerMap.entries())}_notice(){this._domLayers$.next(Array.from(this._domLayerMap.entries()))}addFloatDom(t){this._domLayerMap.set(t.id,t),this._notice()}removeFloatDom(t){this._domLayerMap.delete(t)&&this._notice()}removeAll(){this._domLayerMap.clear(),this._notice()}}const n9=s.memo(e=>{var D,k;const{layer:t,id:n}=e,r=s.useMemo(()=>t.position$.pipe(X.distinctUntilChanged((I,N)=>I.absolute.left===N.absolute.left&&I.absolute.top===N.absolute.top&&I.endX-I.startX===N.endX-N.startX&&I.endY-I.startY===N.endY-N.startY)),[t.position$]),i=B.useDependency(m.IUniverInstanceService),o=B.useObservable(s.useMemo(()=>t.position$.pipe(X.first()),[t.position$])),a=s.useRef(null),l=s.useRef(null),f=s.useRef(`transform: rotate(${o==null?void 0:o.rotate}deg) translate(${o==null?void 0:o.startX}px, ${o==null?void 0:o.startY}px)`),v=s.useRef((D=o==null?void 0:o.startY)!=null?D:0),b=s.useRef((k=o==null?void 0:o.startX)!=null?k:0),u=s.useRef({}),p=typeof t.componentKey=="string"?B.useDependency(T1).get(t.componentKey):t.componentKey,L=s.useMemo(()=>({data:t.data,...t.props}),[t.data,t.props]);s.useEffect(()=>{const I=t.position$.subscribe(w=>{var O;f.current=`rotate(${w.rotate}deg)`,v.current=w.startY,b.current=w.startX,a.current&&(a.current.style.transform=f.current,a.current.style.top=`${v.current}px`,a.current.style.left=`${b.current}px`,a.current.style.opacity=`${(O=w.opacity)!=null?O:1}`)}),N=r.subscribe(w=>{if(a.current&&(a.current.style.width=`${Math.max(w.endX-w.startX-2,0)}px`,a.current.style.height=`${Math.max(w.endY-w.startY-2,0)}px`),l.current){const O={width:`${w.width-4}px`,height:`${w.height-4}px`,left:`${w.absolute.left?0:"auto"}`,top:`${w.absolute.top?0:"auto"}`,right:`${w.absolute.left?"auto":0}`,bottom:`${w.absolute.top?"auto":0}`};l.current.style.width=O.width,l.current.style.height=O.height,l.current.style.left=O.left,l.current.style.top=O.top,l.current.style.right=O.right,l.current.style.bottom=O.bottom,u.current=O}});return()=>{I.unsubscribe(),N.unsubscribe()}},[t.position$,r]);const E=i.getUnit(t.unitId),H=E instanceof m.DocumentDataModel?E.getDisabled():void 0,g=s.useMemo(()=>p?C.jsx(p,{...L,unitId:t.unitId,unit:E,floatDomId:t.id,context:{docDisabled:H,root:l}}):null,[p,L]);return o?C.jsx("div",{ref:a,className:"univer-z-10",style:{position:"absolute",top:v.current,left:b.current,width:Math.max(o.endX-o.startX-2,0),height:Math.max(o.endY-o.startY-2,0),transform:f.current,overflow:"hidden",transformOrigin:"center center"},onPointerMove:I=>{t.onPointerMove(I.nativeEvent)},onPointerDown:I=>{t.onPointerDown(I.nativeEvent)},onPointerUp:I=>{t.onPointerUp(I.nativeEvent)},onWheel:I=>{t.onWheel(I.nativeEvent)},children:C.jsx("div",{id:n,ref:l,className:"univer-overflow-hidden",style:{position:"absolute",...u.current},children:g})}):null}),Ht=({unitId:e})=>{var a;const t=B.useDependency(m.IUniverInstanceService),n=B.useDependency(Re),r=B.useObservable(n.domLayers$),i=B.useObservable(t.focused$),o=e||i;return(a=r==null?void 0:r.filter(l=>l[1].unitId===o))==null?void 0:a.map(l=>C.jsx(n9,{id:l[0],layer:l[1]},l[0]))},We=m.createIdentifier("ui.popup.service");class It extends m.Disposable{constructor(){super(...arguments);J(this,"_popupMap",new Map);J(this,"_popups$",new X.BehaviorSubject([]));J(this,"popups$",this._popups$.asObservable());J(this,"_activePopupId",null)}get popups(){return Array.from(this._popupMap.entries())}get activePopupId(){return this._activePopupId}_update(){this._popups$.next(Array.from(this._popupMap.entries()))}dispose(){super.dispose(),this._popups$.next([]),this._popups$.complete(),this._popupMap.clear()}addPopup(n){const r=m.Tools.generateRandomId();return this._popupMap.set(r,{...n,onActiveChange:i=>{i?this._activePopupId=r:this._activePopupId===r&&(this._activePopupId=null)}}),this._update(),r}removePopup(n){this._popupMap.delete(n)&&this._update()}removeAll(){this._popupMap.clear(),this._update()}}const D4=({popup:e,children:t})=>{const[n,r]=s.useState(!1),i=s.useMemo(()=>e.anchorRect$.pipe(X.throttleTime(0,X.animationFrameScheduler),X.map(u=>{var k;const{bottom:p,left:L,right:E,top:H}=u,[g=0,D=0]=(k=e.offset)!=null?k:[];return{left:L-g,right:E+g,top:H-D,bottom:p+D}})),[e.anchorRect$,e.offset]),o=s.useMemo(()=>{var u,p;return(p=(u=e.hiddenRects$)==null?void 0:u.pipe(X.throttleTime(0,X.animationFrameScheduler)))!=null?p:X.of([])},[e.hiddenRects$]),a=s.useMemo(()=>{var u;return(u=e.excludeRects$)==null?void 0:u.pipe(X.throttleTime(0,X.animationFrameScheduler))},[e.excludeRects$]),l=wr(a,e.excludeRects),{canvasElement:f,hideOnInvisible:v=!0,hiddenType:b="destroy"}=e;return s.useEffect(()=>{if(!v)return;const u=X.combineLatest([i,o]).subscribe(([p,L])=>{const E=f.getBoundingClientRect(),{top:H,left:g,bottom:D,right:k}=E,I=p.bottom-p.top,N=p.right-p.left,w=L.some(O=>p.top>=O.top-.5*I&&p.bottom<=O.bottom+.5*I&&p.left>=O.left-.5*N&&p.right<=O.right+.5*N);p.bottom<H||p.top>D||p.right<g||p.left>k||w?r(!0):r(!1)});return()=>u.unsubscribe()},[f,v,i,o]),n&&b==="destroy"?null:C.jsx(Be,{...e,hidden:n,anchorRect$:i,direction:e.direction,onClickOutside:e.onClickOutside,excludeOutside:e.excludeOutside,excludeRects:l,...e.customActive?null:{onPointerEnter:()=>{var u;return(u=e.onActiveChange)==null?void 0:u.call(e,!0)},onPointerLeave:()=>{var u;return(u=e.onActiveChange)==null?void 0:u.call(e,!1)}},onClick:e.onClick,onContextMenu:e.onContextMenu,children:t})};function Ot(){const e=B.useDependency(We),t=B.useDependency(T1);return B.useObservable(e.popups$,void 0,!0).map(r=>{const[i,o]=r,a=t.get(o.componentKey);return C.jsx(D4,{popup:o,children:a?C.jsx(a,{popup:o}):null},i)})}function E1(e){const{components:t,fallback:n,sharedProps:r}=e;return!t||t.size===0?n!=null?n:null:Array.from(t.values()).map((i,o)=>{var a;return s.createElement(i,{key:`${(a=i.displayName)!=null?a:o}`,...r})})}function H1(e,t){var l;const n=(l=t==null?void 0:t.get(F1))!=null?l:B.useDependency(F1),r=s.useMemo(()=>n.uiVisibleChange$.pipe(X.filter(f=>f.ui===e)),[e,n]),i=B.useObservable(r),o=s.useRef(0),a=B.useObservable(()=>n.componentRegistered$.pipe(X.filter(f=>f===e),X.debounceTime(200),X.map(()=>o.current+=1),X.startWith(o.current+=1)),void 0,void 0,[n,e,i]);return s.useMemo(()=>n.isUIVisible(e)?n.getComponents(e):new Set,[a])}function Dt(e){const{children:t,className:n,style:r,disabled:i=!1,active:o=!1,noIcon:a,onClick:l,onDoubleClick:f,...v}=e,b=p=>{if(i){p.preventDefault();return}l&&l(p)},u=p=>{if(i){p.preventDefault();return}f&&f(p)};return C.jsx("button",{type:"button",className:R.clsx(`
25
25
  univer-flex univer-h-6 univer-min-w-6 univer-cursor-pointer univer-items-center univer-justify-center
26
26
  univer-rounded univer-border-none univer-bg-transparent univer-p-0 univer-text-base univer-text-gray-900
27
27
  univer-outline-none univer-transition-colors univer-animate-in univer-fade-in
@@ -160,7 +160,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
160
160
  caret-color: transparent;
161
161
  white-space: pre-wrap;
162
162
  user-select: text;
163
- `}_getNodePosition(e){if(e==null)return;const{node:n,ratioX:o,segmentPage:a}=e,c=this._docSkeletonManagerService.getSkeleton().findPositionByGlyph(n,a);if(c==null)return;let A=o<.5;return n.glyphType===B.GlyphType.LIST&&(A=!0),{...c,isBack:A}}_interactTextRanges(e){const n=[];for(const o of this._rangeList){if(e.some(a=>a.isIntersection(o))){o.dispose();continue}n.push(o)}this._rangeList=n}_interactRectRanges(e){const n=[];for(const o of this._rectRangeList){if(e.some(a=>a.isIntersection(o))){o.dispose();continue}n.push(o)}this._rectRangeList=n}_removeAllRanges(){this._removeAllTextRanges(),this._removeAllRectRanges()}_removeAllCacheRanges(){this._rangeListCache.forEach(e=>{e.dispose()}),this._rectRangeListCache.forEach(e=>{e.dispose()}),this._rangeListCache=[],this._rectRangeListCache=[]}_removeAllTextRanges(){this._rangeList.forEach(e=>{e.dispose()}),this._rangeList=[]}_removeAllRectRanges(){this._rectRangeList.forEach(e=>{e.dispose()}),this._rectRangeList=[]}_removeAllCollapsedTextRanges(){for(const e of this._rangeList)e.collapsed&&e.dispose()}_deactivateAllTextRanges(){this._rangeList.forEach(e=>{e.deactivate()})}_deactivateAllRectRanges(){this._rectRangeList.forEach(e=>{e.deactivate()})}_addTextRangesToCache(e){this._rangeListCache.push(...e)}_addTextRange(e){this._deactivateAllTextRanges(),e.activate(),this._rangeList.push(e)}_addRectRangesToCache(e){this._rectRangeListCache.push(...e)}_addRectRanges(e){e.length!==0&&(this._deactivateAllRectRanges(),e[e.length-1].activate(),this._rectRangeList.push(...e))}_createTextRangeByAnchorPosition(e){this._removeAllRanges();const{scene:n,mainComponent:o}=this._context,a=this._docSkeletonManagerService.getSkeleton(),r=new He(n,o,a,e,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(r)}_updateActiveRangePosition(e){const n=this._getActiveRangeInstance();if(n==null||n.anchorNodePosition==null){this._logService.error("[DocSelectionRenderService] _updateActiveRangeFocusPosition: active range has no anchor");return}this._removeAllRanges(),this._anchorNodePosition=n.anchorNodePosition,this._focusNodePosition=e;const{scene:o,mainComponent:a}=this._context,r=this._docSkeletonManagerService.getSkeleton(),{_anchorNodePosition:c,_focusNodePosition:l,_selectionStyle:A,_currentSegmentId:d,_currentSegmentPage:u}=this;if(c==null||l==null||a==null)return;const m=Gn(c,l,o,a,r,A,d,u);if(m==null)return;const{textRanges:h,rectRanges:g}=m;this._addTextRangesToCache(h),this._addRectRangesToCache(g),this.deactivate()}_isEmpty(){return this._rangeList.length===0&&this._rectRangeList.length===0}_getCanvasOffset(){var n;const e=(n=this._context.scene)==null?void 0:n.getEngine();return Eo(e)}_updateInputPosition(e=!1){const n=this._getActiveRangeInstance(),o=n==null?void 0:n.getAnchor();if(!o||o&&!o.visible||this.activeViewPort==null){this.focus();return}const{left:a,top:r}=o,c=this.activeViewPort.getAbsoluteVector(B.Vector2.FromArray([a,r])),{x:l,y:A}=c;let{left:d,top:u}=this._getCanvasOffset();d+=l,u+=A,this.activate(d,u,e)}_moving(e,n){var v,C;const{_currentSegmentId:o,_currentSegmentPage:a}=this,r=this._findNodeByCoord(e,n,{strict:!0,segmentId:o,segmentPage:a}),c=this._getNodePosition(r);if(c==null||r==null)return;const l=r==null?void 0:r.node.parent,A=l==null?void 0:l.glyphGroup[l.glyphGroup.indexOf(r.node)+1];(r==null?void 0:r.node.streamType)===s.DataStreamTreeTokenType.PARAGRAPH&&(A==null?void 0:A.streamType)===s.DataStreamTreeTokenType.SECTION_BREAK&&(c.isBack=!0),this._focusNodePosition=c,this._removeAllCacheRanges();const{_anchorNodePosition:d,_selectionStyle:u}=this,{scene:m,mainComponent:h}=this._context,g=this._docSkeletonManagerService.getSkeleton();if(d==null||h==null)return;const f=Gn(d,c,m,h,g,u,o,a);if(f==null)return;const{textRanges:p,rectRanges:S}=f;this._rangeList.length>0&&p.length>0&&this._interactTextRanges(p),this._rectRangeList.length>0&&S.length>0&&this._interactRectRanges(S),this._addTextRangesToCache(p),this._addRectRangesToCache(S),this.deactivate(),(C=(v=this._context.scene)==null?void 0:v.getEngine())==null||C.setCapture()}__attachScrollEvent(){const e=this.activeViewPort;if(!e)return;const{unitId:n}=this._context;if(this._viewPortObserverMap.has(n))return;const o=e.onScrollAfter$.subscribeEvent(r=>{if(!r.viewport)return;const l=this._getActiveRangeInstance();l==null||l.activeStatic()}),a=e.onScrollEnd$.subscribeEvent(r=>{const c=r.viewport;if(!c)return;const l=c.getBounding(),A=this._getActiveRangeInstance(),d=A==null?void 0:A.getAnchor();if(!(!d||d&&!d.visible)){if(l){const{left:u,top:m,right:h,bottom:g}=l.viewBound;if(d.left<u||d.left>h||d.top<m||d.top>g){A==null||A.deactivateStatic();return}}this._updateInputPosition()}});this._viewPortObserverMap.set(n,{scrollBefore:o,scrollStop:a})}_initInputEvents(){this.disposeWithMe(w.fromEvent(this._input,"keydown").subscribe(e=>{this._isIMEInputApply||this._eventHandle(e,n=>{this._onKeydown$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"input").subscribe(e=>{if(!(e.inputType==="historyUndo"||e.inputType==="historyRedo")){if(this._rectRangeList.length>0)return e.stopPropagation(),e.preventDefault();this._isIMEInputApply||this._eventHandle(e,n=>{this._onInputBefore$.next(n),this._onInput$.next(n)})}})),this.disposeWithMe(w.fromEvent(this._input,"compositionstart").subscribe(e=>{if(this._rectRangeList.length>0)return e.stopPropagation(),e.preventDefault();this._isIMEInputApply=!0,this._eventHandle(e,n=>{this._onCompositionstart$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"compositionend").subscribe(e=>{this._isIMEInputApply=!1,this._eventHandle(e,n=>{this._onCompositionend$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"compositionupdate").subscribe(e=>{this._eventHandle(e,n=>{this._onInputBefore$.next(n),this._onCompositionupdate$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"paste").subscribe(e=>{this._eventHandle(e,n=>{this._onPaste$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"focus").subscribe(e=>{this._eventHandle(e,n=>{this._onFocus$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"blur").subscribe(e=>{this._eventHandle(e,n=>{this._onBlur$.next(n)})}))}_eventHandle(e,n){const o=this._input.textContent||"";this._input.innerHTML="";const a=this._getActiveRange(),r=this._getAllTextRanges();n({event:e,content:o,activeRange:a,rangeList:r})}_getTransformCoordForDocumentOffset(e,n){const o=this._context.mainComponent,{documentTransform:a}=o.getOffsetConfig();if(this.activeViewPort==null||a==null)return;const r=this.activeViewPort.transformVector2SceneCoord(B.Vector2.FromArray([e,n]));if(r)return a.clone().invert().applyPoint(r)}_findNodeByCoord(e,n,o){const a=this._getTransformCoordForDocumentOffset(e,n);if(a==null)return;const r=this._context.mainComponent,c=this._docSkeletonManagerService.getSkeleton(),{pageLayoutType:l=B.PageLayoutType.VERTICAL,pageMarginLeft:A,pageMarginTop:d}=r.getOffsetConfig();return c.findNodeByCoord(a,l,A,d,o)}_detachEvent(){this._onInputBefore$.complete(),this._onKeydown$.complete(),this._onInput$.complete(),this._onCompositionstart$.complete(),this._onCompositionupdate$.complete(),this._onCompositionend$.complete(),this._onSelectionStart$.complete(),this._textSelectionInner$.complete(),this._onPaste$.complete(),this._onFocus$.complete(),this._onBlur$.complete(),this._onPointerDown$.complete()}},y.DocSelectionRenderService=Ua([Vt(1,I.ILayoutService),Vt(2,s.ILogService),Vt(3,s.IUniverInstanceService),Vt(4,s.Inject(D.DocSkeletonManagerService))],y.DocSelectionRenderService);class To extends s.Disposable{constructor(e,n,o,a,r,c){super();_(this,"_change$",new w.Subject);_(this,"change$",this._change$.asObservable());_(this,"_input$",new w.Subject);_(this,"input$",this._input$.asObservable());_(this,"_paste$",new w.Subject);_(this,"paste$",this._paste$.asObservable());_(this,"_focus$",new w.Subject);_(this,"focus$",this._focus$.asObservable());_(this,"_blur$",new w.Subject);_(this,"blur$",this._blur$.asObservable());_(this,"_selectionChange$",new w.Subject);_(this,"selectionChange$",this._selectionChange$.asObservable());this._param=e,this._univerInstanceService=n,this._docSelectionManagerService=o,this._commandService=a,this._undoRedoService=r,this._injector=c,this._listenSelection()}get docSelectionRenderService(){return this._param.render.with(y.DocSelectionRenderService)}_listenSelection(){const e=this._param.render.with(y.DocSelectionRenderService);this.disposeWithMe(e.onBlur$.subscribe(n=>{this._blur$.next(n);const o=this.getDocumentData();this._change$.next({target:this,data:o})})),this.disposeWithMe(e.onFocus$.subscribe(n=>{this._focus$.next(n)})),this.disposeWithMe(e.onPaste$.subscribe(n=>{this._paste$.next(n)})),this.disposeWithMe(w.merge(e.onInput$,e.onKeydown$.pipe(At.filter(n=>{const o=n.event;return o.ctrlKey||o.metaKey?[I.KeyCode.X,I.KeyCode.V].includes(o.keyCode):[I.KeyCode.BACKSPACE].includes(o.keyCode)})),e.onCompositionupdate$,e.onCompositionend$,e.onPaste$).subscribe(n=>{if(n==null)return;const{content:o=""}=n,a=this.getDocumentData();this._input$.next({target:this,content:o,data:a,isComposing:n.event.type==="compositionupdate"})})),this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(n=>{if(n==null)return;const{unitId:o,subUnitId:a,...r}=n,c=this.getEditorId();o===c&&this._selectionChange$.next(r)}))}isFocus(){const e=this._param.render.with(y.DocSelectionRenderService);return e.isFocusing&&!!e.getActiveTextRange()}focus(){const e=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),n=this.getEditorId();(e==null||e.getUnitId()!==n)&&this._univerInstanceService.setCurrentUnitForType(n),this._param.render.with(y.DocSelectionRenderService).focus()}blur(){this._param.render.with(y.DocSelectionRenderService).blur()}select(){const e=this.getDocumentData();return this.setSelectionRanges([{startOffset:0,endOffset:e.body?e.body.dataStream.length-2:0}])}setSelectionRanges(e,n=!0){const o=this.getEditorId(),a={unitId:o,subUnitId:o};return this._docSelectionManagerService.replaceDocRanges(e,a,!1,{shouldFocus:n})}getSelectionRanges(){const e=this.getEditorId(),n={unitId:e,subUnitId:e};return this._docSelectionManagerService.getDocRanges(n)}getCursorPosition(){var n,o;return(o=(n=this.getSelectionRanges().find(a=>a.collapsed))==null?void 0:n.startOffset)!=null?o:-1}getEditorId(){return this._getEditorId()}getDocumentData(){return this._getDocDataModel().getSnapshot()}getDocumentDataModel(){return this._getDocDataModel()}setDocumentData(e,n){const{id:o}=e;this._commandService.syncExecuteCommand(Pn.id,{unitId:o,snapshot:e,textRanges:n})}replaceText(e,n=!0){const o=this.getDocumentData();this.setDocumentData({...o,body:{dataStream:`${e}\r
163
+ `}_getNodePosition(e){if(e==null)return;const{node:n,ratioX:o,segmentPage:a}=e,c=this._docSkeletonManagerService.getSkeleton().findPositionByGlyph(n,a);if(c==null)return;let A=o<.5;return n.glyphType===B.GlyphType.LIST&&(A=!0),{...c,isBack:A}}_interactTextRanges(e){const n=[];for(const o of this._rangeList){if(e.some(a=>a.isIntersection(o))){o.dispose();continue}n.push(o)}this._rangeList=n}_interactRectRanges(e){const n=[];for(const o of this._rectRangeList){if(e.some(a=>a.isIntersection(o))){o.dispose();continue}n.push(o)}this._rectRangeList=n}_removeAllRanges(){this._removeAllTextRanges(),this._removeAllRectRanges()}_removeAllCacheRanges(){this._rangeListCache.forEach(e=>{e.dispose()}),this._rectRangeListCache.forEach(e=>{e.dispose()}),this._rangeListCache=[],this._rectRangeListCache=[]}_removeAllTextRanges(){this._rangeList.forEach(e=>{e.dispose()}),this._rangeList=[]}_removeAllRectRanges(){this._rectRangeList.forEach(e=>{e.dispose()}),this._rectRangeList=[]}_removeAllCollapsedTextRanges(){for(const e of this._rangeList)e.collapsed&&e.dispose()}_deactivateAllTextRanges(){this._rangeList.forEach(e=>{e.deactivate()})}_deactivateAllRectRanges(){this._rectRangeList.forEach(e=>{e.deactivate()})}_addTextRangesToCache(e){this._rangeListCache.push(...e)}_addTextRange(e){this._deactivateAllTextRanges(),e.activate(),this._rangeList.push(e)}_addRectRangesToCache(e){this._rectRangeListCache.push(...e)}_addRectRanges(e){e.length!==0&&(this._deactivateAllRectRanges(),e[e.length-1].activate(),this._rectRangeList.push(...e))}_createTextRangeByAnchorPosition(e){this._removeAllRanges();const{scene:n,mainComponent:o}=this._context,a=this._docSkeletonManagerService.getSkeleton(),r=new He(n,o,a,e,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(r)}_updateActiveRangePosition(e){const n=this._getActiveRangeInstance();if(n==null||n.anchorNodePosition==null){this._logService.error("[DocSelectionRenderService] _updateActiveRangeFocusPosition: active range has no anchor");return}this._removeAllRanges(),this._anchorNodePosition=n.anchorNodePosition,this._focusNodePosition=e;const{scene:o,mainComponent:a}=this._context,r=this._docSkeletonManagerService.getSkeleton(),{_anchorNodePosition:c,_focusNodePosition:l,_selectionStyle:A,_currentSegmentId:d,_currentSegmentPage:u}=this;if(c==null||l==null||a==null)return;const m=Gn(c,l,o,a,r,A,d,u);if(m==null)return;const{textRanges:h,rectRanges:g}=m;this._addTextRangesToCache(h),this._addRectRangesToCache(g),this.deactivate()}_isEmpty(){return this._rangeList.length===0&&this._rectRangeList.length===0}_getCanvasOffset(){var n;const e=(n=this._context.scene)==null?void 0:n.getEngine();return Eo(e)}_updateInputPosition(e=!1){const n=this._getActiveRangeInstance(),o=n==null?void 0:n.getAnchor();if(!o||o&&!o.visible||this.activeViewPort==null){this.focus();return}const{left:a,top:r}=o,c=this.activeViewPort.getAbsoluteVector(B.Vector2.FromArray([a,r])),{x:l,y:A}=c;let{left:d,top:u}=this._getCanvasOffset();d+=l,u+=A,this.activate(d,u,e)}_moving(e,n){var v,C;const{_currentSegmentId:o,_currentSegmentPage:a}=this,r=this._findNodeByCoord(e,n,{strict:!0,segmentId:o,segmentPage:a}),c=this._getNodePosition(r);if(c==null||r==null)return;const l=r==null?void 0:r.node.parent,A=l==null?void 0:l.glyphGroup[l.glyphGroup.indexOf(r.node)+1];(r==null?void 0:r.node.streamType)===s.DataStreamTreeTokenType.PARAGRAPH&&(A==null?void 0:A.streamType)===s.DataStreamTreeTokenType.SECTION_BREAK&&(c.isBack=!0),this._focusNodePosition=c,this._removeAllCacheRanges();const{_anchorNodePosition:d,_selectionStyle:u}=this,{scene:m,mainComponent:h}=this._context,g=this._docSkeletonManagerService.getSkeleton();if(d==null||h==null)return;const f=Gn(d,c,m,h,g,u,o,a);if(f==null)return;const{textRanges:p,rectRanges:S}=f;this._rangeList.length>0&&p.length>0&&this._interactTextRanges(p),this._rectRangeList.length>0&&S.length>0&&this._interactRectRanges(S),this._addTextRangesToCache(p),this._addRectRangesToCache(S),this.deactivate(),(C=(v=this._context.scene)==null?void 0:v.getEngine())==null||C.setCapture()}__attachScrollEvent(){const e=this.activeViewPort;if(!e)return;const{unitId:n}=this._context;if(this._viewPortObserverMap.has(n))return;const o=e.onScrollAfter$.subscribeEvent(r=>{if(!r.viewport)return;const l=this._getActiveRangeInstance();l==null||l.activeStatic()}),a=e.onScrollEnd$.subscribeEvent(r=>{const c=r.viewport;if(!c)return;const l=c.getBounding(),A=this._getActiveRangeInstance(),d=A==null?void 0:A.getAnchor();if(!(!d||d&&!d.visible)){if(l){const{left:u,top:m,right:h,bottom:g}=l.viewBound;if(d.left<u||d.left>h||d.top<m||d.top>g){A==null||A.deactivateStatic();return}}this._updateInputPosition()}});this._viewPortObserverMap.set(n,{scrollBefore:o,scrollStop:a})}_initInputEvents(){this.disposeWithMe(w.fromEvent(this._input,"keydown").subscribe(e=>{this._isIMEInputApply||this._eventHandle(e,n=>{this._onKeydown$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"input").subscribe(e=>{if(!(e.inputType==="historyUndo"||e.inputType==="historyRedo")){if(this._rectRangeList.length>0)return e.stopPropagation(),e.preventDefault();this._isIMEInputApply||this._eventHandle(e,n=>{this._onInputBefore$.next(n),this._onInput$.next(n)})}})),this.disposeWithMe(w.fromEvent(this._input,"compositionstart").subscribe(e=>{if(this._rectRangeList.length>0)return e.stopPropagation(),e.preventDefault();this._isIMEInputApply=!0,this._eventHandle(e,n=>{this._onCompositionstart$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"compositionend").subscribe(e=>{this._isIMEInputApply=!1,this._eventHandle(e,n=>{this._onCompositionend$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"compositionupdate").subscribe(e=>{this._eventHandle(e,n=>{this._onInputBefore$.next(n),this._onCompositionupdate$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"paste").subscribe(e=>{this._eventHandle(e,n=>{this._onPaste$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"focus").subscribe(e=>{this._eventHandle(e,n=>{this._onFocus$.next(n)})})),this.disposeWithMe(w.fromEvent(this._input,"blur").subscribe(e=>{this._eventHandle(e,n=>{this._onBlur$.next(n)})}))}_eventHandle(e,n){const o=this._input.textContent||"";this._input.innerHTML="";const a=this._getActiveRange(),r=this._getAllTextRanges();n({event:e,content:o,activeRange:a,rangeList:r})}_getTransformCoordForDocumentOffset(e,n){const o=this._context.mainComponent,{documentTransform:a}=o.getOffsetConfig();if(this.activeViewPort==null||a==null)return;const r=this.activeViewPort.transformVector2SceneCoord(B.Vector2.FromArray([e,n]));if(r)return a.clone().invert().applyPoint(r)}_findNodeByCoord(e,n,o){const a=this._getTransformCoordForDocumentOffset(e,n);if(a==null)return;const r=this._context.mainComponent,c=this._docSkeletonManagerService.getSkeleton(),{pageLayoutType:l=B.PageLayoutType.VERTICAL,pageMarginLeft:A,pageMarginTop:d}=r.getOffsetConfig();return c.findNodeByCoord(a,l,A,d,o)}_detachEvent(){this._onInputBefore$.complete(),this._onKeydown$.complete(),this._onInput$.complete(),this._onCompositionstart$.complete(),this._onCompositionupdate$.complete(),this._onCompositionend$.complete(),this._onSelectionStart$.complete(),this._textSelectionInner$.complete(),this._onPaste$.complete(),this._onFocus$.complete(),this._onBlur$.complete(),this._onPointerDown$.complete()}},y.DocSelectionRenderService=Ua([Vt(1,I.ILayoutService),Vt(2,s.ILogService),Vt(3,s.IUniverInstanceService),Vt(4,s.Inject(D.DocSkeletonManagerService))],y.DocSelectionRenderService);class To extends s.Disposable{constructor(e,n,o,a,r,c){super();_(this,"_change$",new w.Subject);_(this,"change$",this._change$.asObservable());_(this,"_input$",new w.Subject);_(this,"input$",this._input$.asObservable());_(this,"_paste$",new w.Subject);_(this,"paste$",this._paste$.asObservable());_(this,"_focus$",new w.Subject);_(this,"focus$",this._focus$.asObservable());_(this,"_blur$",new w.Subject);_(this,"blur$",this._blur$.asObservable());_(this,"_selectionChange$",new w.Subject);_(this,"selectionChange$",this._selectionChange$.asObservable());this._param=e,this._univerInstanceService=n,this._docSelectionManagerService=o,this._commandService=a,this._undoRedoService=r,this._injector=c,this._listenSelection()}get docSelectionRenderService(){return this._param.render.with(y.DocSelectionRenderService)}_listenSelection(){const e=this._param.render.with(y.DocSelectionRenderService);this.disposeWithMe(e.onBlur$.subscribe(n=>{this._blur$.next(n);const o=this.getDocumentData();this._change$.next({target:this,data:o})})),this.disposeWithMe(e.onFocus$.subscribe(n=>{this._focus$.next(n)})),this.disposeWithMe(e.onPaste$.subscribe(n=>{this._paste$.next(n)})),this.disposeWithMe(w.merge(e.onInput$,e.onKeydown$.pipe(At.filter(n=>{const o=n.event;return o.ctrlKey||o.metaKey?[I.KeyCode.X,I.KeyCode.V].includes(o.keyCode):[I.KeyCode.BACKSPACE].includes(o.keyCode)})),e.onCompositionupdate$,e.onCompositionend$,e.onPaste$).subscribe(n=>{if(n==null)return;const{content:o=""}=n,a=this.getDocumentData();this._input$.next({target:this,content:o,data:a,isComposing:n.event.type==="compositionupdate"})})),this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(n=>{if(n==null)return;const{unitId:o,subUnitId:a,...r}=n,c=this.getEditorId();o===c&&this._selectionChange$.next(r)}))}isFocus(){const e=this._param.render.with(y.DocSelectionRenderService);return e.isFocusing&&!!e.getActiveTextRange()}focus(){const e=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),n=this.getEditorId();(e==null||e.getUnitId()!==n)&&this._univerInstanceService.setCurrentUnitForType(n),this._param.render.with(y.DocSelectionRenderService).focus()}blur(){this._param.render.with(y.DocSelectionRenderService).blur()}select(){const e=this.getDocumentData();return this.setSelectionRanges([{startOffset:0,endOffset:e.body?e.body.dataStream.length-2:0}])}setSelectionRanges(e,n=!0){const o=this.getEditorId(),a={unitId:o,subUnitId:o};return this._docSelectionManagerService.replaceDocRanges(e,a,!1,{shouldFocus:n})}getSelectionRanges(){const e=this.getEditorId(),n={unitId:e,subUnitId:e};return this._docSelectionManagerService.getDocRanges(n)}getCursorPosition(){var n,o;return(o=(n=this.getSelectionRanges().find(a=>a.collapsed))==null?void 0:n.startOffset)!=null?o:-1}getEditorId(){return this._getEditorId()}getDocumentData(){return this._getDocDataModel().getSnapshot()}getDocumentDataModel(){return this._getDocDataModel()}setDocumentData(e,n){this._commandService.syncExecuteCommand(Pn.id,{unitId:this.getEditorId(),snapshot:e,textRanges:n})}replaceText(e,n=!0){const o=this.getDocumentData();this.setDocumentData({...o,body:{dataStream:`${e}\r
164
164
  `,paragraphs:[{startIndex:0}],customRanges:[],sectionBreaks:[],tables:[],textRuns:[]}},typeof n=="object"?n:n?[{startOffset:e.length,endOffset:e.length,collapsed:!0}]:null)}clearUndoRedoHistory(){const e=this.getEditorId();return this._undoRedoService.clearUndoRedo(e)}dispose(){this._getDocDataModel().dispose()}get editorUnitId(){return this._param.editorUnitId}get params(){return this._param}get cancelDefaultResizeListener(){return this._param.cancelDefaultResizeListener}get render(){return this._param.render}isReadOnly(){return this._param.readonly===!0}getBoundingClientRect(){return this._param.editorDom.getBoundingClientRect()}get editorDOM(){return this._param.editorDom}isVisible(){return this._param.visible}getSkeleton(){var n;return(n=this._injector.get(B.IRenderManagerService).getRenderById(this._getEditorId()))==null?void 0:n.with(D.DocSkeletonManagerService).getSkeleton()}isSheetEditor(){return s.isInternalEditorID(this._getEditorId())}getValue(){var o;return(((o=this._getDocDataModel().getBody())==null?void 0:o.dataStream)||"").replace(/\r\n/g,"").replace(/\n/g,"").replace(/\n/g,"")}getBody(){return this._getDocDataModel().getBody()}update(e){this._param={...this._param,...e}}updateCanvasStyle(){var o;const e=this._getDocDataModel();if(e==null)return;const n={};(o=this._param.canvasStyle)!=null&&o.fontSize&&(n.textStyle==null&&(n.textStyle={}),n.textStyle.fs=this._param.canvasStyle.fontSize),e.updateDocumentStyle(n)}_getDocDataModel(){const e=this._getEditorId();return this._univerInstanceService.getUnit(e,s.UniverInstanceType.UNIVER_DOC)}_getEditorId(){var e;return((e=this._param.initialSnapshot)==null?void 0:e.id)||this._param.editorUnitId||""}}var wa=Object.getOwnPropertyDescriptor,La=(i,t,e,n)=>{for(var o=n>1?void 0:n?wa(t,e):t,a=i.length-1,r;a>=0;a--)(r=i[a])&&(o=r(o)||o);return o},ke=(i,t)=>(e,n)=>t(e,n,i);const Qa=["editor","render-canvas"];y.EditorService=class extends s.Disposable{constructor(e,n,o,a,r,c,l){super();_(this,"_editors",new Map);_(this,"_focusEditorUnitId");_(this,"_blur$",new w.Subject);_(this,"blur$",this._blur$.asObservable());_(this,"_focus$",new w.Subject);_(this,"focus$",this._focus$.asObservable());this._univerInstanceService=e,this._renderManagerService=n,this._docSelectionManagerService=o,this._contextService=a,this._commandService=r,this._undoRedoService=c,this._injector=l,this._initUniverFocusListener()}_initUniverFocusListener(){this.disposeWithMe(w.fromEvent(window,"focusin").subscribe(e=>{const n=e.target;this._blurSheetEditor(n)}))}_blurSheetEditor(e){if(Qa.some(o=>e.dataset.uComp===o))return;const n=this.getFocusEditor();n&&n.isSheetEditor()!==!0&&this.blur()}_setFocusId(e){this._focusEditorUnitId=e}getFocusId(){return this._focusEditorUnitId}getFocusEditor(){if(this._focusEditorUnitId)return this.getEditor(this._focusEditorUnitId)}isEditor(e){return this._editors.has(e)}isSheetEditor(e){const n=this._editors.get(e);return!!(n&&n.isSheetEditor())}blur(e){const n=this.getFocusEditor();e&&(n==null||n.setSelectionRanges([])),n==null||n.blur(),this._contextService.setContextValue(s.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(s.FOCUSING_EDITOR_STANDALONE,!1),this._setFocusId(null),this._blur$.next(null)}focus(e){if(e===this._focusEditorUnitId||(this._focusEditorUnitId&&this.blur(),e==null))return;const n=this.getEditor(e);if(n==null)return;this._univerInstanceService.setCurrentUnitForType(e);const o=n.getValue().length;this._contextService.setContextValue(s.EDITOR_ACTIVATED,!0),s.isInternalEditorID(e)||this._contextService.setContextValue(s.FOCUSING_EDITOR_STANDALONE,!0),n.focus(),this._setFocusId(e),this._focus$.next({startOffset:o,endOffset:o})}dispose(){this._editors.clear(),super.dispose()}getEditor(e=this._getCurrentEditorUnitId()){return this._editors.get(e)}getAllEditor(){return this._editors}register(e,n){var A,d,u,m;const{initialSnapshot:o,canvasStyle:a={}}=e,r=o.id;this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_DOC)==null&&this._univerInstanceService.createUnit(s.UniverInstanceType.UNIVER_DOC,o||this._getBlank(r),{makeCurrent:!1});let l=this._renderManagerService.getRenderById(r);if(l==null&&(this._renderManagerService.create(r),l=this._renderManagerService.getRenderById(r)),l){l.engine.setContainer(n);const h=new To({...e,render:l,editorDom:n,canvasStyle:a},this._univerInstanceService,this._docSelectionManagerService,this._commandService,this._undoRedoService,this._injector);this._editors.set(r,h),e.scrollBar||(m=(u=(d=(A=l.mainComponent)==null?void 0:A.getScene())==null?void 0:d.getViewports())==null?void 0:u[0].getScrollBar())==null||m.dispose()}return s.toDisposable(()=>{this._unRegister(r)})}_unRegister(e){const n=this._editors.get(e);n!=null&&(this._renderManagerService.removeRender(e),n.dispose(),this._editors.delete(e),this._univerInstanceService.disposeUnit(e))}_getCurrentEditorUnitId(){return this._univerInstanceService.getCurrentUniverDocInstance().getUnitId()}_getBlank(e){return{id:e,body:{dataStream:`${s.DEFAULT_EMPTY_DOCUMENT_VALUE}`,textRuns:[],paragraphs:[{startIndex:0}]},documentStyle:{renderConfig:{verticalAlign:s.VerticalAlign.TOP,horizontalAlign:s.HorizontalAlign.LEFT},marginLeft:3,marginTop:0,marginRight:3}}}},y.EditorService=La([ke(0,s.IUniverInstanceService),ke(1,B.IRenderManagerService),ke(2,s.Inject(D.DocSelectionManagerService)),ke(3,s.IContextService),ke(4,s.ICommandService),ke(5,s.IUndoRedoService),ke(6,s.Inject(s.Injector))],y.EditorService);const ce=s.createIdentifier("univer.editor.service");function Fa(i){const{editorId:t,initialValue:e,container:n,autoFocus:o,isSingle:a}=i,r=U.useMemo(()=>o!=null?o:!1,[]),[c,l]=U.useState(),A=I.useDependency(ce);return U.useLayoutEffect(()=>{var d,u;if(n.current){const m=typeof e=="string"?void 0:s.Tools.deepClone(e),h={body:{dataStream:typeof e=="string"?`${e}\r
165
165
  `:`\r
166
166
  `,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[],paragraphs:[{startIndex:0}]},...m,documentStyle:{...m==null?void 0:m.documentStyle,pageSize:{width:a?1/0:n.current.clientWidth,height:1/0}},id:t},g=A.register({autofocus:!0,editorUnitId:t,initialSnapshot:h},n.current),f=A.getEditor(t);if(l(f),r){f.focus();const p=((u=(d=h.body)==null?void 0:d.dataStream.length)!=null?u:2)-2;f.setSelectionRanges([{startOffset:p,endOffset:p}])}return()=>{g==null||g.dispose()}}},[]),c}const Ee={id:"doc.operation.move-cursor",type:s.CommandType.OPERATION,handler:(i,t)=>!!t},Ce={id:"doc.operation.move-selection",type:s.CommandType.OPERATION,handler:(i,t)=>!!t},Ha=(i,t,e,n)=>{const o=I.useDependency(s.ICommandService),a=I.useDependency(I.IShortcutService),r=U.useRef(t);r.current=t;const c=U.useRef(n);c.current=n,U.useEffect(()=>{if(!e||!i)return;const A=`sheet.formula-embedding-editor.${e.getEditorId()}`,d=new s.DisposableCollection,u=(h,g)=>{if(c.current){c.current(h,g);return}let f=s.Direction.LEFT;h===I.KeyCode.ARROW_DOWN?f=s.Direction.DOWN:h===I.KeyCode.ARROW_UP?f=s.Direction.UP:h===I.KeyCode.ARROW_RIGHT&&(f=s.Direction.RIGHT),g===I.MetaKeys.SHIFT?o.executeCommand(Ce.id,{direction:f}):o.executeCommand(Ee.id,{direction:f})};return d.add(o.registerCommand({id:A,type:s.CommandType.OPERATION,handler(h,g){const{keyCode:f}=g;u(f)}})),[{keyCode:I.KeyCode.ARROW_DOWN},{keyCode:I.KeyCode.ARROW_LEFT},{keyCode:I.KeyCode.ARROW_RIGHT},{keyCode:I.KeyCode.ARROW_UP},{keyCode:I.KeyCode.ARROW_DOWN,metaKey:I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_LEFT,metaKey:I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_RIGHT,metaKey:I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_UP,metaKey:I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_DOWN,metaKey:I.MetaKeys.CTRL_COMMAND},{keyCode:I.KeyCode.ARROW_LEFT,metaKey:I.MetaKeys.CTRL_COMMAND},{keyCode:I.KeyCode.ARROW_RIGHT,metaKey:I.MetaKeys.CTRL_COMMAND},{keyCode:I.KeyCode.ARROW_UP,metaKey:I.MetaKeys.CTRL_COMMAND},{keyCode:I.KeyCode.ARROW_DOWN,metaKey:I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_LEFT,metaKey:I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_RIGHT,metaKey:I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT},{keyCode:I.KeyCode.ARROW_UP,metaKey:I.MetaKeys.CTRL_COMMAND|I.MetaKeys.SHIFT}].map(({keyCode:h,metaKey:g})=>({id:A,binding:g?h|g:h,preconditions:()=>!0,priority:900,staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keyCode:h}})).forEach(h=>{d.add(a.registerShortcut(h))}),()=>{d.dispose()}},[o,e,i,a])};function ka(i,t){const e=I.useDependency(s.ICommandService);U.useEffect(()=>{if(!i)return;const n=e.onCommandExecuted(o=>{var a,r;if(o.id===D.RichTextEditingMutation.id){if(o.params.unitId!==i.getEditorId())return;const l=i.getDocumentData();t(l,s.getPlainText((r=(a=l.body)==null?void 0:a.dataStream)!=null?r:""))}});return()=>{n.dispose()}},[i,t,e])}const Va=i=>{var W;const{className:t,autoFocus:e,onFocusChange:n,initialValue:o,onClickOutside:a,keyboardEventConfig:r,moveCursor:c=!0,style:l,isSingle:A,editorId:d,onHeightChange:u,onChange:m,defaultHeight:h=32,maxHeight:g=32,icon:f,editorRef:p,placeholder:S}=i,v=I.useDependency(ce),C=I.useEvent(n),b=I.useEvent(a),[R,E]=U.useState(h),O=U.useRef(null),M=U.useMemo(()=>d!=null?d:s.createInternalEditorID(`RICH_TEXT_EDITOR-${s.generateRandomId(4)}`),[d]),T=Fa({editorId:M,initialValue:o,container:O,autoFocus:e,isSingle:A}),x=I.useDependency(B.IRenderManagerService).getRenderById(M),P=x==null?void 0:x.with(y.DocSelectionRenderService),H=I.useObservable(P==null?void 0:P.textSelectionInner$),V=!!((W=P==null?void 0:P.isFocusing)!=null&&W&&(H!=null&&H.textRanges.some(z=>z.collapsed))),F=U.useRef(null),[Q,j]=U.useState(()=>{var z,X;return!s.BuildTextUtils.transform.getPlainText((X=(z=T==null?void 0:T.getDocumentData().body)==null?void 0:z.dataStream)!=null?X:"")}),{checkScrollBar:G}=uo(T,A,!0,!0);U.useLayoutEffect(()=>{if(!(!p||!T)){if(typeof p=="function"){p(T);return}p.current=T}},[T]);const k=I.useEvent(z=>{var q,K;const X=x==null?void 0:x.with(D.DocSkeletonManagerService),Y=X==null?void 0:X.getSkeleton().getActualSize();Y&&(u==null||u(Y.actualHeight),E(Math.max(h,Math.min(Y.actualHeight+10,g)))),m==null||m(z,s.getPlainText((K=(q=z.body)==null?void 0:q.dataStream)!=null?K:"")),G()});return U.useEffect(()=>{var X,Y;j(!s.BuildTextUtils.transform.getPlainText((Y=(X=T==null?void 0:T.getDocumentData().body)==null?void 0:X.dataStream)!=null?Y:""));const z=T==null?void 0:T.selectionChange$.subscribe(()=>{var q,K;j(!s.BuildTextUtils.transform.getPlainText((K=(q=T==null?void 0:T.getDocumentData().body)==null?void 0:q.dataStream)!=null?K:""))});return()=>z==null?void 0:z.unsubscribe()},[T]),I.useObservable(T==null?void 0:T.blur$),I.useObservable(T==null?void 0:T.focus$),U.useEffect(()=>{var X,Y;const z=T==null?void 0:T.getDocumentData();C==null||C(V,s.getPlainText((Y=(X=z==null?void 0:z.body)==null?void 0:X.dataStream)!=null?Y:""))},[V,C]),U.useEffect(()=>{const z=Y=>{var K,Z;v.getFocusId()!==M||((Z=(K=Y.target)==null?void 0:K.dataset)==null?void 0:Z.editorid)===M||F.current&&!F.current.contains(Y.target)&&(b==null||b())},X=setTimeout(()=>{document.addEventListener("click",z)},100);return()=>{document.removeEventListener("click",z),clearTimeout(X)}},[T,M,v,b]),Ha(V&&c,!1,T),Ao(V,r,T),ka(T,k),L.jsx("div",{className:t,style:l,children:L.jsxs("div",{className:te.clsx(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-docs-core",
3
- "version": "0.6.10-nightly.202504241607",
3
+ "version": "0.6.10-nightly.202504261606",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,16 +57,16 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/design": "0.6.10-nightly.202504241607",
61
- "@univerjs/docs": "0.6.10-nightly.202504241607",
62
- "@univerjs/docs-ui": "0.6.10-nightly.202504241607",
63
- "@univerjs/engine-formula": "0.6.10-nightly.202504241607",
64
- "@univerjs/engine-render": "0.6.10-nightly.202504241607",
65
- "@univerjs/network": "0.6.10-nightly.202504241607",
66
- "@univerjs/ui": "0.6.10-nightly.202504241607"
60
+ "@univerjs/design": "0.6.10-nightly.202504261606",
61
+ "@univerjs/docs": "0.6.10-nightly.202504261606",
62
+ "@univerjs/docs-ui": "0.6.10-nightly.202504261606",
63
+ "@univerjs/engine-formula": "0.6.10-nightly.202504261606",
64
+ "@univerjs/engine-render": "0.6.10-nightly.202504261606",
65
+ "@univerjs/network": "0.6.10-nightly.202504261606",
66
+ "@univerjs/ui": "0.6.10-nightly.202504261606"
67
67
  },
68
68
  "devDependencies": {
69
- "@univerjs/core": "0.6.10-nightly.202504241607",
69
+ "@univerjs/core": "0.6.10-nightly.202504261606",
70
70
  "react": "18.3.1",
71
71
  "react-dom": "18.3.1",
72
72
  "typescript": "^5.8.2",