@univerjs/preset-docs-core 0.6.10-nightly.202504251607 → 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.
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/umd/index.js
CHANGED
|
@@ -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.
|
|
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.
|
|
61
|
-
"@univerjs/docs": "0.6.10-nightly.
|
|
62
|
-
"@univerjs/docs-ui": "0.6.10-nightly.
|
|
63
|
-
"@univerjs/engine-formula": "0.6.10-nightly.
|
|
64
|
-
"@univerjs/engine-render": "0.6.10-nightly.
|
|
65
|
-
"@univerjs/network": "0.6.10-nightly.
|
|
66
|
-
"@univerjs/ui": "0.6.10-nightly.
|
|
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.
|
|
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",
|