@univerjs/docs 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +409 -404
- package/lib/types/basics/component-tools.d.ts +2 -1
- package/lib/types/basics/docs-view-key.d.ts +5 -3
- package/lib/types/commands/commands/set-floating-object-transform.command.d.ts +3 -3
- package/lib/types/commands/mutations/set-floating-object.mutation.d.ts +3 -3
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Documents, Engine, IRenderManagerService, Scene } from '@univerjs/engine-render';
|
|
1
|
+
import { DocBackground, Documents, Engine, IRenderManagerService, Scene } from '@univerjs/engine-render';
|
|
2
2
|
import { IUniverInstanceService, Nullable } from '@univerjs/core';
|
|
3
3
|
|
|
4
4
|
export interface IDocObjectParam {
|
|
5
5
|
document: Documents;
|
|
6
|
+
docBackground: DocBackground;
|
|
6
7
|
scene: Scene;
|
|
7
8
|
engine: Engine;
|
|
8
9
|
}
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export declare enum DOCS_VIEW_KEY {
|
|
17
|
-
MAIN = "__Document_Render_Main__"
|
|
17
|
+
MAIN = "__Document_Render_Main__",
|
|
18
|
+
BACKGROUND = "__Document_Render_Background__"
|
|
18
19
|
}
|
|
19
20
|
export declare enum VIEWPORT_KEY {
|
|
20
21
|
VIEW_MAIN = "viewMain",
|
|
@@ -22,7 +23,8 @@ export declare enum VIEWPORT_KEY {
|
|
|
22
23
|
VIEW_LEFT = "viewLeft",
|
|
23
24
|
VIEW_LEFT_TOP = "viewLeftTop"
|
|
24
25
|
}
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const DOCS_COMPONENT_BACKGROUND_LAYER_INDEX = 0;
|
|
27
|
+
export declare const DOCS_COMPONENT_MAIN_LAYER_INDEX = 2;
|
|
28
|
+
export declare const DOCS_COMPONENT_HEADER_LAYER_INDEX = 4;
|
|
27
29
|
export declare const DOCS_COMPONENT_DEFAULT_Z_INDEX = 10;
|
|
28
30
|
export declare const NORMAL_TEXT_SELECTION_PLUGIN_NAME = "normalTextSelectionPluginName";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICommand,
|
|
1
|
+
import { ICommand, IObjectPositionH, IObjectPositionV, ISize } from '@univerjs/core';
|
|
2
2
|
|
|
3
3
|
export interface ISetDrawingSizeCommandParams {
|
|
4
4
|
documentId: string;
|
|
@@ -9,7 +9,7 @@ export declare const SetDrawingSizeCommand: ICommand;
|
|
|
9
9
|
export interface ISetDrawingPositionCommandParams {
|
|
10
10
|
documentId: string;
|
|
11
11
|
objectId: string;
|
|
12
|
-
positionH:
|
|
13
|
-
positionV:
|
|
12
|
+
positionH: IObjectPositionH;
|
|
13
|
+
positionV: IObjectPositionV;
|
|
14
14
|
}
|
|
15
15
|
export declare const SetDrawingPositionCommand: ICommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAccessor } from '@wendellhu/redi';
|
|
2
|
-
import { BooleanNumber, IMutation,
|
|
2
|
+
import { BooleanNumber, IMutation, IObjectPositionH, IObjectPositionV, ISize, PositionedObjectLayoutType, WrapTextType } from '@univerjs/core';
|
|
3
3
|
|
|
4
4
|
export interface ISeachDrawingMutation {
|
|
5
5
|
documentId: string;
|
|
@@ -7,8 +7,8 @@ export interface ISeachDrawingMutation {
|
|
|
7
7
|
}
|
|
8
8
|
export interface IDrawingTransformMutation extends ISeachDrawingMutation {
|
|
9
9
|
size?: ISize;
|
|
10
|
-
positionH?:
|
|
11
|
-
positionV?:
|
|
10
|
+
positionH?: IObjectPositionH;
|
|
11
|
+
positionV?: IObjectPositionV;
|
|
12
12
|
angle?: number;
|
|
13
13
|
}
|
|
14
14
|
export declare const SetDrawingTransformMutationFactory: (accessor: IAccessor, params: IDrawingTransformMutation) => IDrawingTransformMutation;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],n):(c=typeof globalThis<"u"?globalThis:c||self,n(c.UniverDocs={},c.UniverCore,c.UniverEngineRender,c.rxjs,c["@wendellhu/redi"]))})(this,function(c,n,R,w,L){"use strict";var qt=Object.defineProperty;var Jt=(c,n,R)=>n in c?qt(c,n,{enumerable:!0,configurable:!0,writable:!0,value:R}):c[n]=R;var y=(c,n,R)=>(Jt(c,typeof n!="symbol"?n+"":n,R),R);var ge;function Se(o,i){const e=o.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC);if(!e)return null;const t=e.getUnitId(),a=i.getRenderById(t);if(a==null)return;const{mainComponent:s,scene:r,engine:l}=a;return{document:s,scene:r,engine:l}}function rt(o,i){const e=i.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:a,engine:s}=e;return{document:t,scene:a,engine:s}}var De=(o=>(o.MAIN="__Document_Render_Main__",o))(De||{}),Ee=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(Ee||{});const ct=0,lt=2,dt=10,ut="normalTextSelectionPluginName",fe={id:"doc.operation.set-selections",type:n.CommandType.OPERATION,handler:(o,i)=>!0};var mt=Object.defineProperty,gt=Object.getOwnPropertyDescriptor,St=(o,i,e,t)=>{for(var a=t>1?void 0:t?gt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&mt(i,e,a),a},Ae=(o,i)=>(e,t)=>i(e,t,o);function X(o){const{startOffset:i,endOffset:e,collapsed:t}=o,a={startOffset:i,endOffset:e,collapsed:t};return typeof o.isActive=="function"&&(a.isActive=o.isActive()),a}c.TextSelectionManagerService=class extends n.RxDisposable{constructor(e,t){super();y(this,"_currentSelection",null);y(this,"_textSelectionInfo",new Map);y(this,"_textSelection$",new w.BehaviorSubject(null));y(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:a,style:s}=e,r=t.find(f=>f.isActive());if(r==null)return null;const{startOffset:l,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:g,direction:S}=r;return l==null||d==null?null:{startOffset:l,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:g,direction:S,segmentId:a,style:s}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:R.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:a,subUnitId:s,segmentId:r,style:l,textRanges:d,isEditing:u}=t;this._commandService.executeCommand(fe.id,{unitId:a,subUnitId:s,segmentId:r,style:l,isEditing:u,ranges:d.map(X)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:t,subUnitId:a=""}=e;return(s=this._textSelectionInfo.get(t))==null?void 0:s.get(a)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(X))}_replaceByParam(e){const{unitId:t,subUnitId:a,style:s,segmentId:r,textRanges:l,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(a,{textRanges:l,style:s,segmentId:r,isEditing:d})}_addByParam(e){const{unitId:t,subUnitId:a,textRanges:s,style:r,segmentId:l,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const u=this._textSelectionInfo.get(t);u.has(a)?u.get(a).textRanges.push(...s):u.set(a,{textRanges:s,style:r,segmentId:l,isEditing:d})}},c.TextSelectionManagerService=St([Ae(0,R.ITextSelectionRenderManager),Ae(1,n.ICommandService)],c.TextSelectionManagerService);function he(o,i="",e=0){const{startOffset:t,endOffset:a}=o,s=[],r=t-e,l=a-e;return r>0&&s.push({t:n.TextXActionType.RETAIN,len:r,segmentId:i}),s.push({t:n.TextXActionType.DELETE,len:l-r,line:0,segmentId:i}),s}var ft=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(o,i,e,t)=>{for(var a=t>1?void 0:t?ht(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&ft(i,e,a),a},vt=(o,i)=>(e,t)=>i(e,t,o);c.DocViewModelManagerService=class extends n.RxDisposable{constructor(e){super();y(this,"_docViewModelMap",new Map);y(this,"_currentDocViewModel$",new w.BehaviorSubject(null));y(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._univerInstanceService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(n.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._univerInstanceService.getAllUnitsForType(n.UniverInstanceType.UNIVER_DOC).forEach(e=>{this._create(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(n.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var a;const t=this._univerInstanceService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const s=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===n.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(a=this._docViewModelMap.get(e))==null?void 0:a.docViewModel;if(s==null)return;s.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new R.DocumentViewModel(e)}},c.DocViewModelManagerService=pt([vt(0,n.IUniverInstanceService)],c.DocViewModelManagerService);var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,_t=(o,i,e,t)=>{for(var a=t>1?void 0:t?Ct(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&It(i,e,a),a},pe=(o,i)=>(e,t)=>i(e,t,o);const Mt=300;c.DocStateChangeManagerService=class extends n.RxDisposable{constructor(e,t,a){super();y(this,"_docStateChange$",new w.BehaviorSubject(null));y(this,"docStateChange$",this._docStateChange$.asObservable());y(this,"_stateCache",new Map);y(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=a,this._initialize()}setChangeState(e){const{trigger:t,noHistory:a}=e;t!=null&&(this._cacheChangeState(e),a||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===n.UndoCommandId||e.id===n.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const a=t.getUnitId();this._pushHistory(a)}}))}_cacheChangeState(e){const{trigger:t,unitId:a,noHistory:s}=e;if(!(t===n.RedoCommandId||t===n.UndoCommandId||s)){if(this._stateCache.has(a)){const r=this._stateCache.get(a);r==null||r.push(e)}else this._stateCache.set(a,[e]);t===G.id||t===Y.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(a)},Mt)):this._pushHistory(a)}}_pushHistory(e){const t=this._undoRedoService,a=this._stateCache.get(e);if(!Array.isArray(a)||a.length===0)return;const s=a.length,r=a[0].commandId,l=a[0],d=a[s-1],u={unitId:e,actions:a.reduce((g,S)=>n.TextX.compose(g,S.redoState.actions),[]),textRanges:d.redoState.textRanges},m={unitId:e,actions:a.reverse().reduce((g,S)=>n.TextX.compose(g,S.undoState.actions),[]),textRanges:l.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:m}],redoMutations:[{id:r,params:u}]}),a.length=0}},c.DocStateChangeManagerService=_t([pe(0,L.Inject(n.IUndoRedoService)),pe(1,n.ICommandService),pe(2,n.IUniverInstanceService)],c.DocStateChangeManagerService);class H{constructor(){y(this,"_previousActiveRange",null);y(this,"_undoMutationParamsCache",[]);y(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:i=[],redoCache:e=[]}){this._undoMutationParamsCache=i,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(i){this._previousActiveRange=i}pushUndoRedoMutationParams(i,e){this._undoMutationParamsCache.push(i),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:i}=this._undoMutationParamsCache[0],e={unitId:i,actions:this._undoMutationParamsCache.reverse().reduce((a,s)=>n.TextX.compose(a,s.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((a,s)=>n.TextX.compose(a,s.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ne="doc.mutation.rich-text-editing",N={id:Ne,type:n.CommandType.MUTATION,handler:(o,i)=>{var P;const{unitId:e,actions:t,textRanges:a,prevTextRanges:s,trigger:r,noHistory:l,isCompositionEnd:d,noNeedSetTextRange:u}=i,g=o.get(n.IUniverInstanceService).getUniverDocInstance(e),f=o.get(c.DocViewModelManagerService).getViewModel(e),v=o.get(c.TextSelectionManagerService),h=((P=v.getSelections())!=null?P:[]).map(X),I=o.get(c.DocStateChangeManagerService),C=o.get(H);if(g==null||f==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const T=!!g.getSnapshot().disabled;if(t.length===0||T)return{unitId:e,actions:[],textRanges:h};const _=g.apply(t),{segmentId:M}=t[0],x=g.getSelfOrHeaderFooterModel(M);f.getSelfOrHeaderFooterViewModel(M).reset(x),!u&&a&&r!=null&&queueMicrotask(()=>{v.replaceTextRanges(a)});const E={commandId:Ne,unitId:e,trigger:r,noHistory:l,redoState:{actions:t,textRanges:a},undoState:{actions:_,textRanges:s!=null?s:h}};if(d){const O=C.fetchComposedUndoRedoMutationParams();if(O==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:A,redoMutationParams:U,previousActiveRange:k}=O;E.redoState.actions=U.actions,E.undoState.actions=A.actions,E.undoState.textRanges=[k]}return I.setChangeState(E),{unitId:e,actions:_,textRanges:h}}},G={id:"doc.command.insert-text",type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),{range:t,segmentId:a,body:s,unitId:r,textRanges:l}=i,{startOffset:d,collapsed:u}=t,m={id:N.id,params:{unitId:r,actions:[],textRanges:l}},g=new n.TextX;return u?d>0&&g.push({t:n.TextXActionType.RETAIN,len:d,segmentId:a}):g.push(...he(t,a)),g.push({t:n.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:a}),m.params.actions=g.serialize(),!!e.syncExecuteCommand(m.id,m.params)}};var F=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(F||{});const Y={id:"doc.command.delete-text",type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),{range:t,segmentId:a,unitId:s,direction:r,textRanges:l,len:d=1}=i,{startOffset:u}=t,m={id:N.id,params:{unitId:s,actions:[],textRanges:l}},g=new n.TextX;return u>0&&g.push({t:n.TextXActionType.RETAIN,len:r===0?u-d:u,segmentId:a}),g.push({t:n.TextXActionType.DELETE,len:d,line:0,segmentId:a}),m.params.actions=g.serialize(),!!e.syncExecuteCommand(m.id,m.params)}},ve={id:"doc.command.update-text",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{range:e,segmentId:t,updateBody:a,coverType:s,unitId:r,textRanges:l}=i,d=o.get(n.ICommandService),u={id:N.id,params:{unitId:r,actions:[],textRanges:l}},m=new n.TextX,{startOffset:g,endOffset:S}=e;return m.push({t:n.TextXActionType.RETAIN,len:g,segmentId:t}),m.push({t:n.TextXActionType.RETAIN,body:a,len:S-g,segmentId:t,coverType:s}),u.params.actions=m.serialize(),!!d.syncExecuteCommand(u.id,u.params)}};function Tt(o,i){const e=[];for(let t=0,a=o.length;t<a;t++)o[t]===n.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(i)for(const t of e)i.bullet&&(t.bullet=n.Tools.deepClone(i.bullet)),i.paragraphStyle&&(t.paragraphStyle=n.Tools.deepClone(i.paragraphStyle));return e}const Ue={id:"doc.command.break-line",type:n.CommandType.COMMAND,handler:async o=>{var v,p;const i=o.get(c.TextSelectionManagerService),e=o.get(n.IUniverInstanceService),t=o.get(n.ICommandService),a=i.getActiveRange();if(a==null)return!1;const s=e.getCurrentUniverDocInstance();if(!s)return!1;const r=s.getUnitId(),{startOffset:l,segmentId:d,style:u}=a,m=[{startOffset:l+1,endOffset:l+1,style:u}],S=((p=(v=s.getBody())==null?void 0:v.paragraphs)!=null?p:[]).find(h=>h.startIndex>=l);return await t.executeCommand(G.id,{unitId:r,body:{dataStream:n.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Tt(n.DataStreamTreeTokenType.PARAGRAPH,S)},range:a,textRanges:m,segmentId:d})}};var yt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Ot=(o,i,e,t)=>{for(var a=t>1?void 0:t?Rt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&yt(i,e,a),a},Ie=(o,i)=>(e,t)=>i(e,t,o);c.DocSkeletonManagerService=class extends n.RxDisposable{constructor(e,t,a){super();y(this,"_currentSkeletonUnitId","");y(this,"_docSkeletonMap",new Map);y(this,"_currentSkeleton$",new w.BehaviorSubject(null));y(this,"currentSkeleton$",this._currentSkeleton$.asObservable());y(this,"_currentSkeletonBefore$",new w.BehaviorSubject(null));y(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._univerInstanceService=a,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(n.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{var t,a;this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=(a=(t=this._univerInstanceService.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC))==null?void 0:t.getUnitId())!=null?a:""})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const a=this.getSkeletonByUnitId(e);a!=null&&(a.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const a=this.getSkeletonByUnitId(t);a.skeleton.calculate(),a.dirty=!0}else{const a=this._buildSkeleton(e.docViewModel);a.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:a,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return R.DocumentSkeleton.create(e,this._localeService)}},c.DocSkeletonManagerService=Ot([Ie(0,L.Inject(n.LocaleService)),Ie(1,L.Inject(c.DocViewModelManagerService)),Ie(2,n.IUniverInstanceService)],c.DocSkeletonManagerService);const xt={id:"doc.command.inner-paste",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,body:t,textRanges:a}=i,s=o.get(n.ICommandService),r=o.get(c.TextSelectionManagerService),l=o.get(n.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=l.getCurrentUniverDocInstance();if(!u)return!1;const m=u.getUnitId(),g={id:N.id,params:{unitId:m,actions:[],textRanges:a}},S=new n.MemoryCursor;S.reset();const f=new n.TextX;for(const p of d){const{startOffset:h,endOffset:I,collapsed:C}=p,T=h-S.cursor;C?f.push({t:n.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...he(p,e,S.cursor)),f.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!s.syncExecuteCommand(g.id,g.params)}},Ce={id:"doc.command.inner-cut",type:n.CommandType.COMMAND,handler:async(o,i)=>{var p;const{segmentId:e,textRanges:t}=i,a=o.get(n.ICommandService),s=o.get(c.TextSelectionManagerService),r=o.get(n.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=(p=r.getCurrentUniverDocInstance())==null?void 0:p.getUnitId();if(!d)return!1;const u=r.getUniverDocInstance(d),m=n.getDocsUpdateBody(u.snapshot,e);if(m==null)return!1;const g={id:N.id,params:{unitId:d,actions:[],textRanges:t}},S=new n.MemoryCursor;S.reset();const f=new n.TextX;for(const h of l){const{startOffset:I,endOffset:C,collapsed:T}=h,_=I-S.cursor;T?f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}):f.push(...Dt(h,m,e,S.cursor)),S.reset(),S.moveCursor(C)}return g.params.actions=f.serialize(),!!a.syncExecuteCommand(g.id,g.params)}};function Dt(o,i,e="",t=0){const{startOffset:a,endOffset:s}=o,r=[],{paragraphs:l=[]}=i,d=a-t,u=s-t,m=l==null?void 0:l.find(g=>g.startIndex-t>=d&&g.startIndex-t<=u);if(d>0&&r.push({t:n.TextXActionType.RETAIN,len:d,segmentId:e}),m&&m.startIndex-t>d){const g=m.startIndex-t;r.push({t:n.TextXActionType.DELETE,len:g-d,line:0,segmentId:e}),r.push({t:n.TextXActionType.RETAIN,len:1,segmentId:e}),u>g+1&&r.push({t:n.TextXActionType.DELETE,len:u-g-1,line:0,segmentId:e})}else r.push({t:n.TextXActionType.DELETE,len:u-d,line:0,segmentId:e});return r}const be={id:"doc.command.delete-left",type:n.CommandType.COMMAND,handler:async o=>{var _;const i=o.get(c.TextSelectionManagerService),e=o.get(c.DocSkeletonManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),s=i.getActiveRange(),r=i.getSelections(),l=(_=e.getCurrent())==null?void 0:_.skeleton;let d=!0;if(s==null||l==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:g,segmentId:S,style:f}=s,v=l.findNodeByCharIndex(m),p=R.hasListGlyph(v),h=R.isIndentByGlyph(v,u.getBody());let I=m;const C=l.findNodeByCharIndex(m-1);if(R.isFirstGlyph(v)&&C!==v&&(p===!0||h===!0)){const M=R.getParagraphByGlyph(v,u.getBody());if(M==null)return!1;const x=M==null?void 0:M.startIndex,D={startIndex:0},E=M.paragraphStyle;if(p===!0){const O=M.paragraphStyle;if(O){D.paragraphStyle=O;const{hanging:A}=O;A&&(D.paragraphStyle.indentStart=A,D.paragraphStyle.hanging=void 0)}}else if(h===!0){const O=M.bullet;O&&(D.bullet=O),E!=null&&(D.paragraphStyle={...E},delete D.paragraphStyle.hanging,delete D.paragraphStyle.indentStart)}const P=[{startOffset:I,endOffset:I,style:f}];d=await a.executeCommand(ve.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...D}]},range:{startOffset:x,endOffset:x+1},textRanges:P,coverType:n.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(g===!0){if(C==null)return!0;if(C.content==="\r")d=await a.executeCommand(_e.id,{direction:F.LEFT,range:s});else{I-=C.count;const M=[{startOffset:I,endOffset:I,style:f}];d=await a.executeCommand(Y.id,{unitId:u.getUnitId(),range:s,segmentId:S,direction:F.LEFT,len:C.count,textRanges:M})}}else{const M=we(s,r);d=await a.executeCommand(Ce.id,{segmentId:S,textRanges:M})}return d}},Pe={id:"doc.command.delete-right",type:n.CommandType.COMMAND,handler:async o=>{var v;const i=o.get(c.TextSelectionManagerService),e=o.get(c.DocSkeletonManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),s=i.getActiveRange(),r=i.getSelections(),l=(v=e.getCurrent())==null?void 0:v.skeleton;let d;if(s==null||l==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:g,segmentId:S,style:f}=s;if(m===u.getBody().dataStream.length-2&&g)return!0;if(g===!0){const p=l.findNodeByCharIndex(m);if(p.content==="\r")d=await a.executeCommand(_e.id,{direction:F.RIGHT,range:s});else{const h=[{startOffset:m,endOffset:m,style:f}];d=await a.executeCommand(Y.id,{unitId:u.getUnitId(),range:s,segmentId:S,direction:F.RIGHT,textRanges:h,len:p.count})}}else{const p=we(s,r);d=await a.executeCommand(Ce.id,{segmentId:S,textRanges:p})}return d}},_e={id:"doc.command.merge-two-paragraph",type:n.CommandType.COMMAND,handler:async(o,i)=>{var D,E,P;const e=o.get(c.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{direction:s,range:r}=i,l=e.getActiveRange(),d=e.getSelections();if(l==null||d==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:g,segmentId:S,style:f}=l;if(!g)return!1;const v=s===F.LEFT?m:m+1,p=(P=(E=(D=u.getBody())==null?void 0:D.paragraphs)==null?void 0:E.find(O=>O.startIndex>=v))==null?void 0:P.startIndex,h=Et(u.getBody(),v,p),I=s===F.LEFT?m-1:m,C=u.getUnitId(),T=[{startOffset:I,endOffset:I,style:f}],_={id:N.id,params:{unitId:C,actions:[],textRanges:T,prevTextRanges:[r]}},M=new n.TextX;return M.push({t:n.TextXActionType.RETAIN,len:s===F.LEFT?m-1:m,segmentId:S}),h.dataStream.length&&M.push({t:n.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:S}),M.push({t:n.TextXActionType.RETAIN,len:1,segmentId:S}),M.push({t:n.TextXActionType.DELETE,len:p+1-v,line:0,segmentId:S}),_.params.actions=M.serialize(),!!a.syncExecuteCommand(_.id,_.params)}};function Et(o,i,e){const{textRuns:t}=o,a=o.dataStream.substring(i,e);if(t==null)return{dataStream:a};const s=[];for(const r of t){const{st:l,ed:d}=r;d<=i||l>=e||(l<i?s.push({...r,st:0,ed:d-i}):d>e?s.push({...r,st:l-i,ed:e-i}):s.push({...r,st:l-i,ed:d-i}))}return{dataStream:a,textRuns:s}}function we(o,i){let e=o.endOffset;for(const a of i){const{startOffset:s,endOffset:r}=a;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const Me={id:"doc.command.ime-input",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{unitId:e,newText:t,oldTextLen:a,isCompositionEnd:s,isCompositionStart:r}=i,l=o.get(n.ICommandService),d=o.get(H),u=d.getActiveRange();if(u==null)return!1;const{startOffset:m,style:g,segmentId:S}=u,f=t.length,v=[{startOffset:m+f,endOffset:m+f,collapsed:!0,style:g}],p={id:N.id,params:{unitId:e,actions:[],textRanges:v}},h=new n.TextX;!u.collapsed&&r?h.push(...he(u,S)):h.push({t:n.TextXActionType.RETAIN,len:m,segmentId:S}),a>0&&h.push({t:n.TextXActionType.DELETE,len:a,line:0,segmentId:S}),h.push({t:n.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S}),p.params.actions=h.serialize(),p.params.noHistory=!s,p.params.isCompositionEnd=s;const I=l.syncExecuteCommand(p.id,p.params);return d.pushUndoRedoMutationParams(I,p.params),!!I}};function b(o,i,e,t){var s;const{segmentId:a}=(s=e.getActiveRange())!=null?s:{};return a==null?!1:t.executeCommand(Te.id,{segmentId:a,preCommandId:o,...i!=null?i:{}})}const Le="doc.command.set-inline-format-bold",K={id:Le,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Le,i,t,e)}},Be="doc.command.set-inline-format-italic",Q={id:Be,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Be,i,t,e)}},Fe="doc.command.set-inline-format-underline",ee={id:Fe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Fe,i,t,e)}},$e="doc.command.set-inline-format-strikethrough",te={id:$e,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b($e,i,t,e)}},Xe="doc.command.set-inline-format-subscript",z={id:Xe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Xe,i,t,e)}},ke="doc.command.set-inline-format-superscript",ne={id:ke,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(ke,i,t,e)}},Ve="doc.command.set-inline-format-fontsize",ie={id:Ve,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Ve,i,t,e)}},ze="doc.command.set-inline-format-font-family",ae={id:ze,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(ze,i,t,e)}},je="doc.command.set-inline-format-text-color",oe={id:je,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(je,i,t,e)}},He="doc.command.set-inline-format-text-background-color",se={id:He,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(He,i,t,e)}},Ge="doc.command.reset-inline-format-text-background-color",re={id:Ge,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Ge,i,t,e)}},Ye={[K.id]:"bl",[Q.id]:"it",[ee.id]:"ul",[te.id]:"st",[ie.id]:"fs",[ae.id]:"ff",[oe.id]:"cl",[se.id]:"bg",[re.id]:"bg",[z.id]:"va",[ne.id]:"va"},Te={id:"doc.command.set-inline-format",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,value:t,preCommandId:a}=i,s=o.get(n.ICommandService),r=o.get(c.TextSelectionManagerService),l=o.get(n.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;let u=l.getCurrentUniverDocInstance();if(!u)return!1;let m=u.getUnitId();m===n.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=l.getUniverDocInstance(n.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),m=u.getUnitId());let g;switch(a){case K.id:case Q.id:case ee.id:case te.id:case z.id:case ne.id:{g=Nt(u.getBody().textRuns,a,d);break}case ie.id:case ae.id:{g=t;break}case oe.id:case se.id:{g={rgb:t};break}case re.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${a} in handleInlineFormat`)}const S={id:N.id,params:{unitId:m,actions:[],textRanges:d.map(X)}},f=new n.TextX,v=new n.MemoryCursor;v.reset();for(const h of d){const{startOffset:I,endOffset:C}=h,T={dataStream:"",textRuns:[{st:0,ed:C-I,ts:{[Ye[a]]:g}}]},_=I-v.cursor;_!==0&&f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}),f.push({t:n.TextXActionType.RETAIN,body:T,len:C-I,segmentId:e}),v.reset(),v.moveCursor(C)}return S.params.actions=f.serialize(),!!s.syncExecuteCommand(S.id,S.params)}};function At(o){return o!==null&&typeof o=="object"}function Nt(o,i,e){let t=0,a=0;const s=Ye[i];for(;t!==o.length&&a!==e.length;){const{startOffset:r,endOffset:l}=e[a],{st:d,ed:u,ts:m}=o[t];if(l<=d)a++;else if(u<=r)t++;else{if(/bl|it/.test(s))return(m==null?void 0:m[s])===n.BooleanNumber.TRUE?n.BooleanNumber.FALSE:n.BooleanNumber.TRUE;if(/ul|st/.test(s))return At(m==null?void 0:m[s])&&(m==null?void 0:m[s]).s===n.BooleanNumber.TRUE?{s:n.BooleanNumber.FALSE}:{s:n.BooleanNumber.TRUE};if(/va/.test(s))return i===z.id?(m==null?void 0:m[s])===n.BaselineOffset.SUBSCRIPT?n.BaselineOffset.NORMAL:n.BaselineOffset.SUBSCRIPT:(m==null?void 0:m[s])===n.BaselineOffset.SUPERSCRIPT?n.BaselineOffset.NORMAL:n.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(s)?n.BooleanNumber.TRUE:/ul|st/.test(s)?{s:n.BooleanNumber.TRUE}:i===z.id?n.BaselineOffset.SUBSCRIPT:n.BaselineOffset.SUPERSCRIPT}const ye={id:"doc.command.list-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var O,A,U,k;const e=o.get(c.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{listType:s}=i,r=t.getCurrentUniverDocInstance();if(!r)return!1;const l=e.getActiveRange(),d=(O=e.getSelections())!=null?O:[],u=(A=r.getBody())==null?void 0:A.paragraphs,m=d.map(X);if(l==null||u==null)return!1;const g=qe(l,u),{segmentId:S}=l,f=r.getUnitId(),v=g.every(V=>{var B;return((B=V.bullet)==null?void 0:B.listType)===s});let h=n.Tools.generateRandomId(6);if(g.length===1){const V=u.indexOf(g[0]),B=u[V-1],$=u[V+1];B&&B.bullet&&B.bullet.listType===s?h=B.bullet.listId:$&&$.bullet&&$.bullet.listType===s&&(h=$.bullet.listId)}const I={id:N.id,params:{unitId:f,actions:[],textRanges:m}},C=new n.MemoryCursor;C.reset();const T=new n.TextX,_=(U=r.getSnapshot().lists)!=null?U:{},M={...n.PRESET_LIST_TYPE,..._},{charSpace:x,defaultTabStop:D=36,gridType:E}=r.getSnapshot().documentStyle;for(const V of g){const{startIndex:B,paragraphStyle:$={}}=V,{indentFirstLine:Wt=0,snapToGrid:Zt,indentStart:Re=0}=$,{hanging:Oe,indentStart:st}=M[s].nestingLevel[0],xe=R.getCharSpaceApply(x,D,E,Zt);T.push({t:n.TextXActionType.RETAIN,len:B-C.cursor,segmentId:S}),T.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[v?{paragraphStyle:{...$,hanging:void 0,indentStart:Re?Math.max(0,R.getNumberUnitValue(Re,xe)+Oe-st):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...$,indentFirstLine:void 0,hanging:Oe,indentStart:st-Oe+R.getNumberUnitValue(Wt,xe)+R.getNumberUnitValue(Re,xe)},bullet:{...(k=V.bullet)!=null?k:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:h}}]},segmentId:S,coverType:n.UpdateDocsAttributeType.REPLACE}),C.moveCursorTo(B+1)}return I.params.actions=T.serialize(),!!a.syncExecuteCommand(I.id,I.params)}},We={id:"doc.command.bullet-list",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(ye.id,{listType:n.PresetListType.BULLET_LIST})},Ze={id:"doc.command.order-list",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(ye.id,{listType:n.PresetListType.ORDER_LIST})};function qe(o,i){const{startOffset:e,endOffset:t}=o,a=[];let s=-1;for(const r of i){const{startIndex:l}=r;(e>s&&e<=l||t>s&&t<=l||l>=e&&l<=t)&&a.push(r),s=l}return a}const j={id:"doc.command.align-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var T,_;const e=o.get(c.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{alignType:s}=i,r=t.getCurrentUniverDocInstance();if(!r)return!1;const l=e.getActiveRange(),d=(T=e.getSelections())!=null?T:[],u=(_=r.getBody())==null?void 0:_.paragraphs,m=d.map(X);if(l==null||u==null)return!1;const g=qe(l,u),{segmentId:S}=l,f=r.getUnitId(),v=g.every(M=>{var x;return((x=M.paragraphStyle)==null?void 0:x.horizontalAlign)===s}),p={id:N.id,params:{unitId:f,actions:[],textRanges:m}},h=new n.MemoryCursor;h.reset();const I=new n.TextX;for(const M of g){const{startIndex:x}=M;I.push({t:n.TextXActionType.RETAIN,len:x-h.cursor,segmentId:S});const D={...M.paragraphStyle,horizontalAlign:v?n.HorizontalAlign.UNSPECIFIED:s};I.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...M,paragraphStyle:D,startIndex:0}]},segmentId:S,coverType:n.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(x+1)}return p.params.actions=I.serialize(),!!a.syncExecuteCommand(p.id,p.params)}},Je={id:"doc.command.align-left",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.LEFT})},Ke={id:"doc.command.align-center",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.CENTER})},Qe={id:"doc.command.align-right",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.RIGHT})},et={id:"doc.command.align-justify",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.JUSTIFIED})},tt={id:"doc.command-replace-content",type:n.CommandType.COMMAND,handler:async(o,i)=>{var f;const{unitId:e,body:t,textRanges:a,segmentId:s=""}=i,r=o.get(n.IUniverInstanceService),l=o.get(n.ICommandService),d=o.get(c.TextSelectionManagerService),u=(f=r.getUniverDocInstance(e))==null?void 0:f.getSnapshot().body,m=d.getSelections();if(u==null||!Array.isArray(m)||m.length===0)return!1;const g=it(e,s,u,t);return g.params.textRanges=a,!!l.syncExecuteCommand(g.id,g.params)}},nt={id:"doc.command-cover-content",type:n.CommandType.COMMAND,handler:async(o,i)=>{var m;const{unitId:e,body:t,segmentId:a=""}=i,s=o.get(n.IUniverInstanceService),r=o.get(n.ICommandService),l=o.get(n.IUndoRedoService),d=(m=s.getUniverDocInstance(e))==null?void 0:m.getSnapshot().body;if(d==null)return!1;const u=it(e,a,d,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,r.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function it(o,i,e,t){const a={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new n.TextX,r=(e==null?void 0:e.dataStream.length)-2;return r>0&&s.push({t:n.TextXActionType.DELETE,len:r,line:0,segmentId:i}),t.dataStream.length>0&&s.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:i}),a.params.actions=s.serialize(),a}const ce={id:"doc.operation.move-cursor",type:n.CommandType.OPERATION,handler:(o,i)=>!!i},le={id:"doc.operation.move-selection",type:n.CommandType.OPERATION,handler:(o,i)=>!!i},Ut=(o,i)=>{const e=o.get(n.IUniverInstanceService).getUniverDocInstance(i.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...n.Tools.deepClone(i),zoomRatio:t}},W={id:"doc.operation.set-zoom-ratio",type:n.CommandType.OPERATION,handler:(o,i)=>{const e=o.get(n.IUniverInstanceService).getUniverDocInstance(i.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:i.zoomRatio}:t.settings.zoomRatio=i.zoomRatio,!0}},at={type:n.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,i)=>{var g,S,f;const e=o.get(n.ICommandService),t=o.get(n.IUndoRedoService),a=o.get(n.IUniverInstanceService);let s=(g=a.getCurrentUniverDocInstance())==null?void 0:g.getUnitId();if(!s)return!1;let r=1;if(i&&(s=(S=i.documentId)!=null?S:s,r=(f=i.zoomRatio)!=null?f:r),!a.getUniverDocInstance(s))return!1;const d={zoomRatio:r,unitId:s},u=Ut(o,d);return e.syncExecuteCommand(W.id,d)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:W.id,params:u}],redoMutations:[{id:W.id,params:d}]}),!0):!1}},ot={id:"doc.operation.select-all",type:n.CommandType.COMMAND,handler:async o=>{const i=o.get(n.IUniverInstanceService),e=o.get(c.TextSelectionManagerService),t=i.getCurrentUniverDocInstance();if(!t)return!1;const a=t.getSnapshot().body;if(a==null)return!1;const s=[{startOffset:0,endOffset:a.dataStream.length-2}];return e.replaceTextRanges(s,!1),!0}};var bt=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,wt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Pt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&bt(i,e,a),a},Z=(o,i)=>(e,t)=>i(e,t,o);let de=class extends n.Disposable{constructor(i,e,t,a,s){super();y(this,"_previousIMEContent","");y(this,"_isCompositionStart",!0);y(this,"_onStartSubscription");y(this,"_onUpdateSubscription");y(this,"_onEndSubscription");this._docSkeletonManagerService=i,this._univerInstanceService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=a,this._commandService=s,this._initialize()}dispose(){var i,e,t;(i=this._onStartSubscription)==null||i.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(i=>{if(i==null)return;this._resetIME();const{activeRange:e}=i;e!=null&&this._imeInputManagerService.setActiveRange(n.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async i=>{this._updateContent(i,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(i=>{this._updateContent(i,!1)})}async _updateContent(i,e){var u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(i==null||t==null)return;const a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return;const{event:s,activeRange:r}=i;if(t==null||r==null)return;const d=s.data;d===this._previousIMEContent&&e||(await this._commandService.executeCommand(Me.id,{unitId:a.getUnitId(),newText:d,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=d):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};de=wt([n.OnLifecycle(n.LifecycleStages.Rendered,de),Z(0,L.Inject(c.DocSkeletonManagerService)),Z(1,n.IUniverInstanceService),Z(2,R.ITextSelectionRenderManager),Z(3,L.Inject(H)),Z(4,n.ICommandService)],de);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Ft=(o,i,e,t)=>{for(var a=t>1?void 0:t?Bt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&Lt(i,e,a),a},q=(o,i)=>(e,t)=>i(e,t,o);let ue=class extends n.Disposable{constructor(i,e,t,a,s){super();y(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionManagerService=a,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){}_commandExecutedListener(){const i=[ce.id,le.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!i.includes(e.id))return;const t=e.params;switch(e.id){case ce.id:return this._handleMoveCursor(t.direction);case le.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(i){var p,h,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return;const s=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:l,endOffset:d,style:u,collapsed:m,direction:g}=e;if(t.length>1){let C=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const _ of t)C=Math.min(C,_.startOffset),T=Math.max(T,_.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===n.Direction.LEFT||i===n.Direction.UP?T:C,endOffset:i===n.Direction.LEFT||i===n.Direction.UP?C:T,style:u}],!1);return}const S=m||g===R.RANGE_DIRECTION.FORWARD?l:d;let f=m||g===R.RANGE_DIRECTION.FORWARD?d:l;const v=(h=a.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){const C=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===n.Direction.RIGHT?f+T.count:f-((I=C==null?void 0:C.count)!=null?I:0),f=Math.min(v-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:f,style:u}],!1)}else{const C=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,C,i===n.Direction.DOWN);if(_==null){const x=i===n.Direction.UP?0:v-2;if(x===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:x,style:u}],!1);return}const M=new R.NodePositionConvertToCursor(T,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:M.endOffset,style:u}],!1)}}_handleMoveCursor(i){var S,f,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return!1;const s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:l,endOffset:d,style:u,collapsed:m}=e,g=(f=a.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const C of t)h=Math.min(h,C.startOffset),I=Math.max(I,C.endOffset);p=i===n.Direction.LEFT?h:I}else{const h=s.findNodeByCharIndex(l-1),I=s.findNodeByCharIndex(l);i===n.Direction.LEFT?p=Math.max(0,l-((v=h==null?void 0:h.count)!=null?v:0)):p=Math.min(g-2,d+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:u}],!1)}else{const p=s.findNodeByCharIndex(l),h=s.findNodeByCharIndex(d),I=r.document.getOffsetConfig(),C=this._getTopOrBottomPosition(s,i===n.Direction.UP?p:h,i===n.Direction.DOWN);if(C==null){let _;m?_=i===n.Direction.UP?0:g-2:_=i===n.Direction.UP?l:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:u}],!1);return}const T=new R.NodePositionConvertToCursor(I,s).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...T,style:u}],!1)}}_getTopOrBottomPosition(i,e,t){if(e==null)return;const a=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,t);if(s==null)return;const r=this._matchPositionByLeftOffset(i,s,a);if(r!=null)return{...r,isBack:!0}}_getSpanLeftOffsetInLine(i){const e=i.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:a}=i;return t+a}_matchPositionByLeftOffset(i,e,t){const a={distance:Number.POSITIVE_INFINITY};for(const s of e.divides){const r=s.left;for(const l of s.glyphGroup){const{left:d}=l,u=r+d,m=Math.abs(t-u);m<a.distance&&(a.glyph=l,a.distance=m)}}if(a.glyph!=null)return i.findPositionByGlyph(a.glyph)}_getNextOrPrevLine(i,e){var v,p,h,I,C,T,_,M,x,D,E,P;const t=i.parent;if(t==null)return;const a=t.parent;if(a==null)return;const s=a.parent;if(s==null)return;const r=s.lines.indexOf(a);if(r===-1)return;let l;if(e===!0?l=s.lines[r+1]:l=s.lines[r-1],l!=null)return l;const d=s.parent;if(d==null)return;const u=d.columns.indexOf(s);if(u===-1)return;if(e===!0)l=(v=d.columns[u+1])==null?void 0:v.lines[0];else{const O=(h=(p=d.columns)==null?void 0:p[u-1])==null?void 0:h.lines;l=O==null?void 0:O[O.length-1]}if(l!=null)return l;const m=d.parent;if(m==null)return;const g=m.sections.indexOf(d);if(g===-1)return;if(e===!0)l=(C=(I=m.sections[g-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const O=(_=(T=m.sections)==null?void 0:T[g-1])==null?void 0:_.columns,A=O==null?void 0:O[O.length-1],U=A==null?void 0:A.lines;l=U==null?void 0:U[U.length-1]}if(l!=null)return l;const S=m.parent;if(S==null)return;const f=S.pages.indexOf(m);if(f!==-1){if(e===!0)l=(D=(x=(M=S.pages[f+1])==null?void 0:M.sections[0])==null?void 0:x.columns[0])==null?void 0:D.lines[0];else{const O=(E=S.pages[f-1])==null?void 0:E.sections;if(O==null)return;const A=(P=O[O.length-1])==null?void 0:P.columns,U=A[A.length-1],k=U==null?void 0:U.lines;l=k[k.length-1]}if(l!=null)return l}}_getDocObject(){return Se(this._univerInstanceService,this._renderManagerService)}};ue=Ft([n.OnLifecycle(n.LifecycleStages.Rendered,ue),q(0,L.Inject(c.DocSkeletonManagerService)),q(1,n.IUniverInstanceService),q(2,R.IRenderManagerService),q(3,L.Inject(c.TextSelectionManagerService)),q(4,n.ICommandService)],ue);var $t=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,kt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Xt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&$t(i,e,a),a},J=(o,i)=>(e,t)=>i(e,t,o);let me=class extends n.Disposable{constructor(i,e,t,a,s){super();y(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionRenderManager=a,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var v;if(i==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.getUnitId(),{event:a,content:s="",activeRange:r}=i,l=a,d=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(l.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:m,style:g}=r,S=s.length,f=[{startOffset:u+S,endOffset:u+S,style:g}];await this._commandService.executeCommand(G.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:m})})}_commandExecutedListener(){}_getDocObject(){return Se(this._univerInstanceService,this._renderManagerService)}};me=kt([n.OnLifecycle(n.LifecycleStages.Rendered,me),J(0,L.Inject(c.DocSkeletonManagerService)),J(1,n.IUniverInstanceService),J(2,R.IRenderManagerService),J(3,R.ITextSelectionRenderManager),J(4,n.ICommandService)],me);var Vt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,jt=(o,i,e,t)=>{for(var a=t>1?void 0:t?zt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&Vt(i,e,a),a},Ht=(o,i)=>(e,t)=>i(e,t,o);const Gt={hasScroll:!0},Yt="docs";c.UniverDocsPlugin=(ge=class extends n.Plugin{constructor(e={},t){super();y(this,"_config");this._injector=t,this._config=Object.assign(Gt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[ce,le,be,Pe,K,Q,ee,te,z,ne,ie,ae,oe,re,se,Te,Ue,G,Y,ve,Me,_e,N,tt,nt,at,W,fe,ot,Ze,We,ye,Je,Ke,Qe,j,et].forEach(e=>{this._injector.get(n.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[c.DocSkeletonManagerService],[c.DocViewModelManagerService],[c.DocStateChangeManagerService],[H],[R.ITextSelectionRenderManager,{useClass:R.TextSelectionRenderManager}],[c.TextSelectionManagerService],[me],[de],[ue]].forEach(t=>e.add(t))}},y(ge,"pluginName",Yt),y(ge,"type",n.UniverInstanceType.UNIVER_DOC),ge),c.UniverDocsPlugin=jt([Ht(1,L.Inject(L.Injector))],c.UniverDocsPlugin),c.AlignCenterCommand=Ke,c.AlignJustifyCommand=et,c.AlignLeftCommand=Je,c.AlignOperationCommand=j,c.AlignRightCommand=Qe,c.BreakLineCommand=Ue,c.BulletListCommand=We,c.CoverContentCommand=nt,c.CutContentCommand=Ce,c.DOCS_COMPONENT_DEFAULT_Z_INDEX=dt,c.DOCS_COMPONENT_HEADER_LAYER_INDEX=lt,c.DOCS_COMPONENT_MAIN_LAYER_INDEX=ct,c.DOCS_VIEW_KEY=De,c.DeleteCommand=Y,c.DeleteLeftCommand=be,c.DeleteRightCommand=Pe,c.IMEInputCommand=Me,c.IMEInputManagerService=H,c.InnerPasteCommand=xt,c.InsertCommand=G,c.MoveCursorOperation=ce,c.MoveSelectionOperation=le,c.NORMAL_TEXT_SELECTION_PLUGIN_NAME=ut,c.OrderListCommand=Ze,c.ReplaceContentCommand=tt,c.ResetInlineFormatTextBackgroundColorCommand=re,c.RichTextEditingMutation=N,c.SelectAllOperation=ot,c.SetDocZoomRatioCommand=at,c.SetDocZoomRatioOperation=W,c.SetInlineFormatBoldCommand=K,c.SetInlineFormatCommand=Te,c.SetInlineFormatFontFamilyCommand=ae,c.SetInlineFormatFontSizeCommand=ie,c.SetInlineFormatItalicCommand=Q,c.SetInlineFormatStrikethroughCommand=te,c.SetInlineFormatSubscriptCommand=z,c.SetInlineFormatSuperscriptCommand=ne,c.SetInlineFormatTextBackgroundColorCommand=se,c.SetInlineFormatTextColorCommand=oe,c.SetInlineFormatUnderlineCommand=ee,c.SetTextSelectionsOperation=fe,c.UpdateCommand=ve,c.VIEWPORT_KEY=Ee,c.getDocObject=Se,c.getDocObjectById=rt,c.serializeTextRange=X,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(c,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@wendellhu/redi"],n):(c=typeof globalThis<"u"?globalThis:c||self,n(c.UniverDocs={},c.UniverCore,c.UniverEngineRender,c.rxjs,c["@wendellhu/redi"]))})(this,function(c,n,O,w,L){"use strict";var qt=Object.defineProperty;var Jt=(c,n,O)=>n in c?qt(c,n,{enumerable:!0,configurable:!0,writable:!0,value:O}):c[n]=O;var y=(c,n,O)=>(Jt(c,typeof n!="symbol"?n+"":n,O),O);var Se;var J=(o=>(o.MAIN="__Document_Render_Main__",o.BACKGROUND="__Document_Render_Background__",o))(J||{}),Ee=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(Ee||{});const rt=0,ct=2,lt=4,dt=10,ut="normalTextSelectionPluginName";function fe(o,i){const e=o.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC);if(!e)return null;const t=e.getUnitId(),a=i.getRenderById(t);if(a==null)return;const{mainComponent:s,scene:r,engine:l,components:d}=a,u=s,m=d.get(J.BACKGROUND);return{document:u,docBackground:m,scene:r,engine:l}}function mt(o,i){const e=i.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:a,engine:s,components:r}=e,l=t,d=r.get(J.BACKGROUND);return{document:l,docBackground:d,scene:a,engine:s}}const he={id:"doc.operation.set-selections",type:n.CommandType.OPERATION,handler:(o,i)=>!0};var gt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,ft=(o,i,e,t)=>{for(var a=t>1?void 0:t?St(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&>(i,e,a),a},Ae=(o,i)=>(e,t)=>i(e,t,o);function k(o){const{startOffset:i,endOffset:e,collapsed:t}=o,a={startOffset:i,endOffset:e,collapsed:t};return typeof o.isActive=="function"&&(a.isActive=o.isActive()),a}c.TextSelectionManagerService=class extends n.RxDisposable{constructor(e,t){super();y(this,"_currentSelection",null);y(this,"_textSelectionInfo",new Map);y(this,"_textSelection$",new w.BehaviorSubject(null));y(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=t,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t,segmentId:a,style:s}=e,r=t.find(f=>f.isActive());if(r==null)return null;const{startOffset:l,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:g,direction:S}=r;return l==null||d==null?null:{startOffset:l,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:g,direction:S,segmentId:a,style:s}}add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",isEditing:t,style:O.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const t={...this._currentSelection,...e};this._replaceByParam(t),this._textSelection$.next(t);const{unitId:a,subUnitId:s,segmentId:r,style:l,textRanges:d,isEditing:u}=t;this._commandService.executeCommand(he.id,{unitId:a,subUnitId:s,segmentId:r,style:l,isEditing:u,ranges:d.map(k)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:t,subUnitId:a=""}=e;return(s=this._textSelectionInfo.get(t))==null?void 0:s.get(a)}_refresh(e){const t=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),t&&Array.isArray(t.textRanges)&&t.textRanges.length&&this._textSelectionRenderManager.addTextRanges(t.textRanges.map(k))}_replaceByParam(e){const{unitId:t,subUnitId:a,style:s,segmentId:r,textRanges:l,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(a,{textRanges:l,style:s,segmentId:r,isEditing:d})}_addByParam(e){const{unitId:t,subUnitId:a,textRanges:s,style:r,segmentId:l,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const u=this._textSelectionInfo.get(t);u.has(a)?u.get(a).textRanges.push(...s):u.set(a,{textRanges:s,style:r,segmentId:l,isEditing:d})}},c.TextSelectionManagerService=ft([Ae(0,O.ITextSelectionRenderManager),Ae(1,n.ICommandService)],c.TextSelectionManagerService);function pe(o,i="",e=0){const{startOffset:t,endOffset:a}=o,s=[],r=t-e,l=a-e;return r>0&&s.push({t:n.TextXActionType.RETAIN,len:r,segmentId:i}),s.push({t:n.TextXActionType.DELETE,len:l-r,line:0,segmentId:i}),s}var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,vt=(o,i,e,t)=>{for(var a=t>1?void 0:t?pt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&ht(i,e,a),a},It=(o,i)=>(e,t)=>i(e,t,o);c.DocViewModelManagerService=class extends n.RxDisposable{constructor(e){super();y(this,"_docViewModelMap",new Map);y(this,"_currentDocViewModel$",new w.BehaviorSubject(null));y(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._univerInstanceService=e,this._initialize()}_initialize(){this._init()}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(n.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._univerInstanceService.getAllUnitsForType(n.UniverInstanceType.UNIVER_DOC).forEach(e=>{this._create(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(n.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{this._docViewModelMap.delete(e.getUnitId())})}_create(e){if(e==null)return;const t=e.getUnitId();this._setCurrent(t)}getAllModel(){return this._docViewModelMap}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}_setCurrent(e){var a;const t=this._univerInstanceService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const s=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:s})}if(e===n.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const s=(a=this._docViewModelMap.get(e))==null?void 0:a.docViewModel;if(s==null)return;s.reset(t)}this._currentDocViewModel$.next(this._docViewModelMap.get(e))}}_buildDocViewModel(e){return new O.DocumentViewModel(e)}},c.DocViewModelManagerService=vt([It(0,n.IUniverInstanceService)],c.DocViewModelManagerService);var Ct=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,Mt=(o,i,e,t)=>{for(var a=t>1?void 0:t?_t(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&Ct(i,e,a),a},ve=(o,i)=>(e,t)=>i(e,t,o);const Tt=300;c.DocStateChangeManagerService=class extends n.RxDisposable{constructor(e,t,a){super();y(this,"_docStateChange$",new w.BehaviorSubject(null));y(this,"docStateChange$",this._docStateChange$.asObservable());y(this,"_stateCache",new Map);y(this,"_timer",null);this._undoRedoService=e,this._commandService=t,this._univerInstanceService=a,this._initialize()}setChangeState(e){const{trigger:t,noHistory:a}=e;t!=null&&(this._cacheChangeState(e),a||this._docStateChange$.next(e))}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===n.UndoCommandId||e.id===n.RedoCommandId){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(t==null)return;const a=t.getUnitId();this._pushHistory(a)}}))}_cacheChangeState(e){const{trigger:t,unitId:a,noHistory:s}=e;if(!(t===n.RedoCommandId||t===n.UndoCommandId||s)){if(this._stateCache.has(a)){const r=this._stateCache.get(a);r==null||r.push(e)}else this._stateCache.set(a,[e]);t===H.id||t===Y.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(a)},Tt)):this._pushHistory(a)}}_pushHistory(e){const t=this._undoRedoService,a=this._stateCache.get(e);if(!Array.isArray(a)||a.length===0)return;const s=a.length,r=a[0].commandId,l=a[0],d=a[s-1],u={unitId:e,actions:a.reduce((g,S)=>n.TextX.compose(g,S.redoState.actions),[]),textRanges:d.redoState.textRanges},m={unitId:e,actions:a.reverse().reduce((g,S)=>n.TextX.compose(g,S.undoState.actions),[]),textRanges:l.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:m}],redoMutations:[{id:r,params:u}]}),a.length=0}},c.DocStateChangeManagerService=Mt([ve(0,L.Inject(n.IUndoRedoService)),ve(1,n.ICommandService),ve(2,n.IUniverInstanceService)],c.DocStateChangeManagerService);class G{constructor(){y(this,"_previousActiveRange",null);y(this,"_undoMutationParamsCache",[]);y(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:i=[],redoCache:e=[]}){this._undoMutationParamsCache=i,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(i){this._previousActiveRange=i}pushUndoRedoMutationParams(i,e){this._undoMutationParamsCache.push(i),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:i}=this._undoMutationParamsCache[0],e={unitId:i,actions:this._undoMutationParamsCache.reverse().reduce((a,s)=>n.TextX.compose(a,s.actions),[]),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((a,s)=>n.TextX.compose(a,s.actions),[]),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ne="doc.mutation.rich-text-editing",N={id:Ne,type:n.CommandType.MUTATION,handler:(o,i)=>{var P;const{unitId:e,actions:t,textRanges:a,prevTextRanges:s,trigger:r,noHistory:l,isCompositionEnd:d,noNeedSetTextRange:u}=i,g=o.get(n.IUniverInstanceService).getUniverDocInstance(e),f=o.get(c.DocViewModelManagerService).getViewModel(e),v=o.get(c.TextSelectionManagerService),h=((P=v.getSelections())!=null?P:[]).map(k),I=o.get(c.DocStateChangeManagerService),C=o.get(G);if(g==null||f==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const T=!!g.getSnapshot().disabled;if(t.length===0||T)return{unitId:e,actions:[],textRanges:h};const _=g.apply(t),{segmentId:M}=t[0],x=g.getSelfOrHeaderFooterModel(M);f.getSelfOrHeaderFooterViewModel(M).reset(x),!u&&a&&r!=null&&queueMicrotask(()=>{v.replaceTextRanges(a)});const E={commandId:Ne,unitId:e,trigger:r,noHistory:l,redoState:{actions:t,textRanges:a},undoState:{actions:_,textRanges:s!=null?s:h}};if(d){const R=C.fetchComposedUndoRedoMutationParams();if(R==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:A,redoMutationParams:U,previousActiveRange:X}=R;E.redoState.actions=U.actions,E.undoState.actions=A.actions,E.undoState.textRanges=[X]}return I.setChangeState(E),{unitId:e,actions:_,textRanges:h}}},H={id:"doc.command.insert-text",type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),{range:t,segmentId:a,body:s,unitId:r,textRanges:l}=i,{startOffset:d,collapsed:u}=t,m={id:N.id,params:{unitId:r,actions:[],textRanges:l}},g=new n.TextX;return u?d>0&&g.push({t:n.TextXActionType.RETAIN,len:d,segmentId:a}):g.push(...pe(t,a)),g.push({t:n.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:a}),m.params.actions=g.serialize(),!!e.syncExecuteCommand(m.id,m.params)}};var F=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(F||{});const Y={id:"doc.command.delete-text",type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),{range:t,segmentId:a,unitId:s,direction:r,textRanges:l,len:d=1}=i,{startOffset:u}=t,m={id:N.id,params:{unitId:s,actions:[],textRanges:l}},g=new n.TextX;return u>0&&g.push({t:n.TextXActionType.RETAIN,len:r===0?u-d:u,segmentId:a}),g.push({t:n.TextXActionType.DELETE,len:d,line:0,segmentId:a}),m.params.actions=g.serialize(),!!e.syncExecuteCommand(m.id,m.params)}},Ie={id:"doc.command.update-text",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{range:e,segmentId:t,updateBody:a,coverType:s,unitId:r,textRanges:l}=i,d=o.get(n.ICommandService),u={id:N.id,params:{unitId:r,actions:[],textRanges:l}},m=new n.TextX,{startOffset:g,endOffset:S}=e;return m.push({t:n.TextXActionType.RETAIN,len:g,segmentId:t}),m.push({t:n.TextXActionType.RETAIN,body:a,len:S-g,segmentId:t,coverType:s}),u.params.actions=m.serialize(),!!d.syncExecuteCommand(u.id,u.params)}};function yt(o,i){const e=[];for(let t=0,a=o.length;t<a;t++)o[t]===n.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});if(i)for(const t of e)i.bullet&&(t.bullet=n.Tools.deepClone(i.bullet)),i.paragraphStyle&&(t.paragraphStyle=n.Tools.deepClone(i.paragraphStyle));return e}const Ue={id:"doc.command.break-line",type:n.CommandType.COMMAND,handler:async o=>{var v,p;const i=o.get(c.TextSelectionManagerService),e=o.get(n.IUniverInstanceService),t=o.get(n.ICommandService),a=i.getActiveRange();if(a==null)return!1;const s=e.getCurrentUniverDocInstance();if(!s)return!1;const r=s.getUnitId(),{startOffset:l,segmentId:d,style:u}=a,m=[{startOffset:l+1,endOffset:l+1,style:u}],S=((p=(v=s.getBody())==null?void 0:v.paragraphs)!=null?p:[]).find(h=>h.startIndex>=l);return await t.executeCommand(H.id,{unitId:r,body:{dataStream:n.DataStreamTreeTokenType.PARAGRAPH,paragraphs:yt(n.DataStreamTreeTokenType.PARAGRAPH,S)},range:a,textRanges:m,segmentId:d})}};var Ot=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,xt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Rt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&Ot(i,e,a),a},Ce=(o,i)=>(e,t)=>i(e,t,o);c.DocSkeletonManagerService=class extends n.RxDisposable{constructor(e,t,a){super();y(this,"_currentSkeletonUnitId","");y(this,"_docSkeletonMap",new Map);y(this,"_currentSkeleton$",new w.BehaviorSubject(null));y(this,"currentSkeleton$",this._currentSkeleton$.asObservable());y(this,"_currentSkeletonBefore$",new w.BehaviorSubject(null));y(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this._univerInstanceService=a,this._initialize()}_initialize(){this._init()}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}_init(){this._docViewModelManagerService.currentDocViewModel$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)}),this._docViewModelManagerService.getAllModel().forEach(e=>{e!=null&&this._setCurrent(e)}),this._univerInstanceService.getTypeOfUnitDisposed$(n.UniverInstanceType.UNIVER_DOC).pipe(w.takeUntil(this.dispose$)).subscribe(e=>{var t,a;this._docSkeletonMap.delete(e.getUnitId()),this._currentSkeletonUnitId=(a=(t=this._univerInstanceService.getCurrentUnitForType(n.UniverInstanceType.UNIVER_DOC))==null?void 0:t.getUnitId())!=null?a:""})}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}getAllSkeleton(){return this._docSkeletonMap}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const a=this.getSkeletonByUnitId(e);a!=null&&(a.dirty=t)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const a=this.getSkeletonByUnitId(t);a.skeleton.calculate(),a.dirty=!0}else{const a=this._buildSkeleton(e.docViewModel);a.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:a,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return O.DocumentSkeleton.create(e,this._localeService)}},c.DocSkeletonManagerService=xt([Ce(0,L.Inject(n.LocaleService)),Ce(1,L.Inject(c.DocViewModelManagerService)),Ce(2,n.IUniverInstanceService)],c.DocSkeletonManagerService);const Dt={id:"doc.command.inner-paste",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,body:t,textRanges:a}=i,s=o.get(n.ICommandService),r=o.get(c.TextSelectionManagerService),l=o.get(n.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=l.getCurrentUniverDocInstance();if(!u)return!1;const m=u.getUnitId(),g={id:N.id,params:{unitId:m,actions:[],textRanges:a}},S=new n.MemoryCursor;S.reset();const f=new n.TextX;for(const p of d){const{startOffset:h,endOffset:I,collapsed:C}=p,T=h-S.cursor;C?f.push({t:n.TextXActionType.RETAIN,len:T,segmentId:e}):f.push(...pe(p,e,S.cursor)),f.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),S.reset(),S.moveCursor(I)}return g.params.actions=f.serialize(),!!s.syncExecuteCommand(g.id,g.params)}},_e={id:"doc.command.inner-cut",type:n.CommandType.COMMAND,handler:async(o,i)=>{var p;const{segmentId:e,textRanges:t}=i,a=o.get(n.ICommandService),s=o.get(c.TextSelectionManagerService),r=o.get(n.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=(p=r.getCurrentUniverDocInstance())==null?void 0:p.getUnitId();if(!d)return!1;const u=r.getUniverDocInstance(d),m=n.getDocsUpdateBody(u.snapshot,e);if(m==null)return!1;const g={id:N.id,params:{unitId:d,actions:[],textRanges:t}},S=new n.MemoryCursor;S.reset();const f=new n.TextX;for(const h of l){const{startOffset:I,endOffset:C,collapsed:T}=h,_=I-S.cursor;T?f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}):f.push(...Et(h,m,e,S.cursor)),S.reset(),S.moveCursor(C)}return g.params.actions=f.serialize(),!!a.syncExecuteCommand(g.id,g.params)}};function Et(o,i,e="",t=0){const{startOffset:a,endOffset:s}=o,r=[],{paragraphs:l=[]}=i,d=a-t,u=s-t,m=l==null?void 0:l.find(g=>g.startIndex-t>=d&&g.startIndex-t<=u);if(d>0&&r.push({t:n.TextXActionType.RETAIN,len:d,segmentId:e}),m&&m.startIndex-t>d){const g=m.startIndex-t;r.push({t:n.TextXActionType.DELETE,len:g-d,line:0,segmentId:e}),r.push({t:n.TextXActionType.RETAIN,len:1,segmentId:e}),u>g+1&&r.push({t:n.TextXActionType.DELETE,len:u-g-1,line:0,segmentId:e})}else r.push({t:n.TextXActionType.DELETE,len:u-d,line:0,segmentId:e});return r}const be={id:"doc.command.delete-left",type:n.CommandType.COMMAND,handler:async o=>{var _;const i=o.get(c.TextSelectionManagerService),e=o.get(c.DocSkeletonManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),s=i.getActiveRange(),r=i.getSelections(),l=(_=e.getCurrent())==null?void 0:_.skeleton;let d=!0;if(s==null||l==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:g,segmentId:S,style:f}=s,v=l.findNodeByCharIndex(m),p=O.hasListGlyph(v),h=O.isIndentByGlyph(v,u.getBody());let I=m;const C=l.findNodeByCharIndex(m-1);if(O.isFirstGlyph(v)&&C!==v&&(p===!0||h===!0)){const M=O.getParagraphByGlyph(v,u.getBody());if(M==null)return!1;const x=M==null?void 0:M.startIndex,D={startIndex:0},E=M.paragraphStyle;if(p===!0){const R=M.paragraphStyle;if(R){D.paragraphStyle=R;const{hanging:A}=R;A&&(D.paragraphStyle.indentStart=A,D.paragraphStyle.hanging=void 0)}}else if(h===!0){const R=M.bullet;R&&(D.bullet=R),E!=null&&(D.paragraphStyle={...E},delete D.paragraphStyle.hanging,delete D.paragraphStyle.indentStart)}const P=[{startOffset:I,endOffset:I,style:f}];d=await a.executeCommand(Ie.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...D}]},range:{startOffset:x,endOffset:x+1},textRanges:P,coverType:n.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(g===!0){if(C==null)return!0;if(C.content==="\r")d=await a.executeCommand(Me.id,{direction:F.LEFT,range:s});else{I-=C.count;const M=[{startOffset:I,endOffset:I,style:f}];d=await a.executeCommand(Y.id,{unitId:u.getUnitId(),range:s,segmentId:S,direction:F.LEFT,len:C.count,textRanges:M})}}else{const M=we(s,r);d=await a.executeCommand(_e.id,{segmentId:S,textRanges:M})}return d}},Pe={id:"doc.command.delete-right",type:n.CommandType.COMMAND,handler:async o=>{var v;const i=o.get(c.TextSelectionManagerService),e=o.get(c.DocSkeletonManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),s=i.getActiveRange(),r=i.getSelections(),l=(v=e.getCurrent())==null?void 0:v.skeleton;let d;if(s==null||l==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:g,segmentId:S,style:f}=s;if(m===u.getBody().dataStream.length-2&&g)return!0;if(g===!0){const p=l.findNodeByCharIndex(m);if(p.content==="\r")d=await a.executeCommand(Me.id,{direction:F.RIGHT,range:s});else{const h=[{startOffset:m,endOffset:m,style:f}];d=await a.executeCommand(Y.id,{unitId:u.getUnitId(),range:s,segmentId:S,direction:F.RIGHT,textRanges:h,len:p.count})}}else{const p=we(s,r);d=await a.executeCommand(_e.id,{segmentId:S,textRanges:p})}return d}},Me={id:"doc.command.merge-two-paragraph",type:n.CommandType.COMMAND,handler:async(o,i)=>{var D,E,P;const e=o.get(c.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{direction:s,range:r}=i,l=e.getActiveRange(),d=e.getSelections();if(l==null||d==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:g,segmentId:S,style:f}=l;if(!g)return!1;const v=s===F.LEFT?m:m+1,p=(P=(E=(D=u.getBody())==null?void 0:D.paragraphs)==null?void 0:E.find(R=>R.startIndex>=v))==null?void 0:P.startIndex,h=At(u.getBody(),v,p),I=s===F.LEFT?m-1:m,C=u.getUnitId(),T=[{startOffset:I,endOffset:I,style:f}],_={id:N.id,params:{unitId:C,actions:[],textRanges:T,prevTextRanges:[r]}},M=new n.TextX;return M.push({t:n.TextXActionType.RETAIN,len:s===F.LEFT?m-1:m,segmentId:S}),h.dataStream.length&&M.push({t:n.TextXActionType.INSERT,body:h,len:h.dataStream.length,line:0,segmentId:S}),M.push({t:n.TextXActionType.RETAIN,len:1,segmentId:S}),M.push({t:n.TextXActionType.DELETE,len:p+1-v,line:0,segmentId:S}),_.params.actions=M.serialize(),!!a.syncExecuteCommand(_.id,_.params)}};function At(o,i,e){const{textRuns:t}=o,a=o.dataStream.substring(i,e);if(t==null)return{dataStream:a};const s=[];for(const r of t){const{st:l,ed:d}=r;d<=i||l>=e||(l<i?s.push({...r,st:0,ed:d-i}):d>e?s.push({...r,st:l-i,ed:e-i}):s.push({...r,st:l-i,ed:d-i}))}return{dataStream:a,textRuns:s}}function we(o,i){let e=o.endOffset;for(const a of i){const{startOffset:s,endOffset:r}=a;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const Te={id:"doc.command.ime-input",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{unitId:e,newText:t,oldTextLen:a,isCompositionEnd:s,isCompositionStart:r}=i,l=o.get(n.ICommandService),d=o.get(G),u=d.getActiveRange();if(u==null)return!1;const{startOffset:m,style:g,segmentId:S}=u,f=t.length,v=[{startOffset:m+f,endOffset:m+f,collapsed:!0,style:g}],p={id:N.id,params:{unitId:e,actions:[],textRanges:v}},h=new n.TextX;!u.collapsed&&r?h.push(...pe(u,S)):h.push({t:n.TextXActionType.RETAIN,len:m,segmentId:S}),a>0&&h.push({t:n.TextXActionType.DELETE,len:a,line:0,segmentId:S}),h.push({t:n.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:S}),p.params.actions=h.serialize(),p.params.noHistory=!s,p.params.isCompositionEnd=s;const I=l.syncExecuteCommand(p.id,p.params);return d.pushUndoRedoMutationParams(I,p.params),!!I}};function b(o,i,e,t){var s;const{segmentId:a}=(s=e.getActiveRange())!=null?s:{};return a==null?!1:t.executeCommand(ye.id,{segmentId:a,preCommandId:o,...i!=null?i:{}})}const Le="doc.command.set-inline-format-bold",Q={id:Le,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Le,i,t,e)}},Be="doc.command.set-inline-format-italic",ee={id:Be,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Be,i,t,e)}},Fe="doc.command.set-inline-format-underline",te={id:Fe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Fe,i,t,e)}},$e="doc.command.set-inline-format-strikethrough",ne={id:$e,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b($e,i,t,e)}},ke="doc.command.set-inline-format-subscript",z={id:ke,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(ke,i,t,e)}},Xe="doc.command.set-inline-format-superscript",ie={id:Xe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Xe,i,t,e)}},Ve="doc.command.set-inline-format-fontsize",ae={id:Ve,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Ve,i,t,e)}},ze="doc.command.set-inline-format-font-family",oe={id:ze,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(ze,i,t,e)}},je="doc.command.set-inline-format-text-color",se={id:je,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(je,i,t,e)}},Ge="doc.command.set-inline-format-text-background-color",re={id:Ge,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(Ge,i,t,e)}},He="doc.command.reset-inline-format-text-background-color",ce={id:He,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return b(He,i,t,e)}},Ye={[Q.id]:"bl",[ee.id]:"it",[te.id]:"ul",[ne.id]:"st",[ae.id]:"fs",[oe.id]:"ff",[se.id]:"cl",[re.id]:"bg",[ce.id]:"bg",[z.id]:"va",[ie.id]:"va"},ye={id:"doc.command.set-inline-format",type:n.CommandType.COMMAND,handler:async(o,i)=>{const{segmentId:e,value:t,preCommandId:a}=i,s=o.get(n.ICommandService),r=o.get(c.TextSelectionManagerService),l=o.get(n.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;let u=l.getCurrentUniverDocInstance();if(!u)return!1;let m=u.getUnitId();m===n.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=l.getUniverDocInstance(n.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),m=u.getUnitId());let g;switch(a){case Q.id:case ee.id:case te.id:case ne.id:case z.id:case ie.id:{g=Ut(u.getBody().textRuns,a,d);break}case ae.id:case oe.id:{g=t;break}case se.id:case re.id:{g={rgb:t};break}case ce.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${a} in handleInlineFormat`)}const S={id:N.id,params:{unitId:m,actions:[],textRanges:d.map(k)}},f=new n.TextX,v=new n.MemoryCursor;v.reset();for(const h of d){const{startOffset:I,endOffset:C}=h,T={dataStream:"",textRuns:[{st:0,ed:C-I,ts:{[Ye[a]]:g}}]},_=I-v.cursor;_!==0&&f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}),f.push({t:n.TextXActionType.RETAIN,body:T,len:C-I,segmentId:e}),v.reset(),v.moveCursor(C)}return S.params.actions=f.serialize(),!!s.syncExecuteCommand(S.id,S.params)}};function Nt(o){return o!==null&&typeof o=="object"}function Ut(o,i,e){let t=0,a=0;const s=Ye[i];for(;t!==o.length&&a!==e.length;){const{startOffset:r,endOffset:l}=e[a],{st:d,ed:u,ts:m}=o[t];if(l<=d)a++;else if(u<=r)t++;else{if(/bl|it/.test(s))return(m==null?void 0:m[s])===n.BooleanNumber.TRUE?n.BooleanNumber.FALSE:n.BooleanNumber.TRUE;if(/ul|st/.test(s))return Nt(m==null?void 0:m[s])&&(m==null?void 0:m[s]).s===n.BooleanNumber.TRUE?{s:n.BooleanNumber.FALSE}:{s:n.BooleanNumber.TRUE};if(/va/.test(s))return i===z.id?(m==null?void 0:m[s])===n.BaselineOffset.SUBSCRIPT?n.BaselineOffset.NORMAL:n.BaselineOffset.SUBSCRIPT:(m==null?void 0:m[s])===n.BaselineOffset.SUPERSCRIPT?n.BaselineOffset.NORMAL:n.BaselineOffset.SUPERSCRIPT;t++}}return/bl|it/.test(s)?n.BooleanNumber.TRUE:/ul|st/.test(s)?{s:n.BooleanNumber.TRUE}:i===z.id?n.BaselineOffset.SUBSCRIPT:n.BaselineOffset.SUPERSCRIPT}const Oe={id:"doc.command.list-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var R,A,U,X;const e=o.get(c.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{listType:s}=i,r=t.getCurrentUniverDocInstance();if(!r)return!1;const l=e.getActiveRange(),d=(R=e.getSelections())!=null?R:[],u=(A=r.getBody())==null?void 0:A.paragraphs,m=d.map(k);if(l==null||u==null)return!1;const g=Ke(l,u),{segmentId:S}=l,f=r.getUnitId(),v=g.every(V=>{var B;return((B=V.bullet)==null?void 0:B.listType)===s});let h=n.Tools.generateRandomId(6);if(g.length===1){const V=u.indexOf(g[0]),B=u[V-1],$=u[V+1];B&&B.bullet&&B.bullet.listType===s?h=B.bullet.listId:$&&$.bullet&&$.bullet.listType===s&&(h=$.bullet.listId)}const I={id:N.id,params:{unitId:f,actions:[],textRanges:m}},C=new n.MemoryCursor;C.reset();const T=new n.TextX,_=(U=r.getSnapshot().lists)!=null?U:{},M={...n.PRESET_LIST_TYPE,..._},{charSpace:x,defaultTabStop:D=36,gridType:E}=r.getSnapshot().documentStyle;for(const V of g){const{startIndex:B,paragraphStyle:$={}}=V,{indentFirstLine:Zt=0,snapToGrid:Kt,indentStart:Re=0}=$,{hanging:xe,indentStart:st}=M[s].nestingLevel[0],De=O.getCharSpaceApply(x,D,E,Kt);T.push({t:n.TextXActionType.RETAIN,len:B-C.cursor,segmentId:S}),T.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[v?{paragraphStyle:{...$,hanging:void 0,indentStart:Re?Math.max(0,O.getNumberUnitValue(Re,De)+xe-st):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...$,indentFirstLine:void 0,hanging:xe,indentStart:st-xe+O.getNumberUnitValue(Zt,De)+O.getNumberUnitValue(Re,De)},bullet:{...(X=V.bullet)!=null?X:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:h}}]},segmentId:S,coverType:n.UpdateDocsAttributeType.REPLACE}),C.moveCursorTo(B+1)}return I.params.actions=T.serialize(),!!a.syncExecuteCommand(I.id,I.params)}},We={id:"doc.command.bullet-list",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(Oe.id,{listType:n.PresetListType.BULLET_LIST})},Ze={id:"doc.command.order-list",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(Oe.id,{listType:n.PresetListType.ORDER_LIST})};function Ke(o,i){const{startOffset:e,endOffset:t}=o,a=[];let s=-1;for(const r of i){const{startIndex:l}=r;(e>s&&e<=l||t>s&&t<=l||l>=e&&l<=t)&&a.push(r),s=l}return a}const j={id:"doc.command.align-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var T,_;const e=o.get(c.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{alignType:s}=i,r=t.getCurrentUniverDocInstance();if(!r)return!1;const l=e.getActiveRange(),d=(T=e.getSelections())!=null?T:[],u=(_=r.getBody())==null?void 0:_.paragraphs,m=d.map(k);if(l==null||u==null)return!1;const g=Ke(l,u),{segmentId:S}=l,f=r.getUnitId(),v=g.every(M=>{var x;return((x=M.paragraphStyle)==null?void 0:x.horizontalAlign)===s}),p={id:N.id,params:{unitId:f,actions:[],textRanges:m}},h=new n.MemoryCursor;h.reset();const I=new n.TextX;for(const M of g){const{startIndex:x}=M;I.push({t:n.TextXActionType.RETAIN,len:x-h.cursor,segmentId:S});const D={...M.paragraphStyle,horizontalAlign:v?n.HorizontalAlign.UNSPECIFIED:s};I.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...M,paragraphStyle:D,startIndex:0}]},segmentId:S,coverType:n.UpdateDocsAttributeType.REPLACE}),h.moveCursorTo(x+1)}return p.params.actions=I.serialize(),!!a.syncExecuteCommand(p.id,p.params)}},qe={id:"doc.command.align-left",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.LEFT})},Je={id:"doc.command.align-center",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.CENTER})},Qe={id:"doc.command.align-right",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.RIGHT})},et={id:"doc.command.align-justify",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(j.id,{alignType:n.HorizontalAlign.JUSTIFIED})},tt={id:"doc.command-replace-content",type:n.CommandType.COMMAND,handler:async(o,i)=>{var f;const{unitId:e,body:t,textRanges:a,segmentId:s=""}=i,r=o.get(n.IUniverInstanceService),l=o.get(n.ICommandService),d=o.get(c.TextSelectionManagerService),u=(f=r.getUniverDocInstance(e))==null?void 0:f.getSnapshot().body,m=d.getSelections();if(u==null||!Array.isArray(m)||m.length===0)return!1;const g=it(e,s,u,t);return g.params.textRanges=a,!!l.syncExecuteCommand(g.id,g.params)}},nt={id:"doc.command-cover-content",type:n.CommandType.COMMAND,handler:async(o,i)=>{var m;const{unitId:e,body:t,segmentId:a=""}=i,s=o.get(n.IUniverInstanceService),r=o.get(n.ICommandService),l=o.get(n.IUndoRedoService),d=(m=s.getUniverDocInstance(e))==null?void 0:m.getSnapshot().body;if(d==null)return!1;const u=it(e,a,d,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,r.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function it(o,i,e,t){const a={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new n.TextX,r=(e==null?void 0:e.dataStream.length)-2;return r>0&&s.push({t:n.TextXActionType.DELETE,len:r,line:0,segmentId:i}),t.dataStream.length>0&&s.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:i}),a.params.actions=s.serialize(),a}const le={id:"doc.operation.move-cursor",type:n.CommandType.OPERATION,handler:(o,i)=>!!i},de={id:"doc.operation.move-selection",type:n.CommandType.OPERATION,handler:(o,i)=>!!i},bt=(o,i)=>{const e=o.get(n.IUniverInstanceService).getUniverDocInstance(i.unitId),t=(e==null?void 0:e.zoomRatio)||1;return{...n.Tools.deepClone(i),zoomRatio:t}},W={id:"doc.operation.set-zoom-ratio",type:n.CommandType.OPERATION,handler:(o,i)=>{const e=o.get(n.IUniverInstanceService).getUniverDocInstance(i.unitId);if(!e)return!1;const t=e.getSnapshot();return t.settings==null?t.settings={zoomRatio:i.zoomRatio}:t.settings.zoomRatio=i.zoomRatio,!0}},at={type:n.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,i)=>{var g,S,f;const e=o.get(n.ICommandService),t=o.get(n.IUndoRedoService),a=o.get(n.IUniverInstanceService);let s=(g=a.getCurrentUniverDocInstance())==null?void 0:g.getUnitId();if(!s)return!1;let r=1;if(i&&(s=(S=i.documentId)!=null?S:s,r=(f=i.zoomRatio)!=null?f:r),!a.getUniverDocInstance(s))return!1;const d={zoomRatio:r,unitId:s},u=bt(o,d);return e.syncExecuteCommand(W.id,d)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:W.id,params:u}],redoMutations:[{id:W.id,params:d}]}),!0):!1}},ot={id:"doc.operation.select-all",type:n.CommandType.COMMAND,handler:async o=>{const i=o.get(n.IUniverInstanceService),e=o.get(c.TextSelectionManagerService),t=i.getCurrentUniverDocInstance();if(!t)return!1;const a=t.getSnapshot().body;if(a==null)return!1;const s=[{startOffset:0,endOffset:a.dataStream.length-2}];return e.replaceTextRanges(s,!1),!0}};var Pt=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,Lt=(o,i,e,t)=>{for(var a=t>1?void 0:t?wt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&Pt(i,e,a),a},Z=(o,i)=>(e,t)=>i(e,t,o);let ue=class extends n.Disposable{constructor(i,e,t,a,s){super();y(this,"_previousIMEContent","");y(this,"_isCompositionStart",!0);y(this,"_onStartSubscription");y(this,"_onUpdateSubscription");y(this,"_onEndSubscription");this._docSkeletonManagerService=i,this._univerInstanceService=e,this._textSelectionRenderManager=t,this._imeInputManagerService=a,this._commandService=s,this._initialize()}dispose(){var i,e,t;(i=this._onStartSubscription)==null||i.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(t=this._onEndSubscription)==null||t.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(i=>{if(i==null)return;this._resetIME();const{activeRange:e}=i;e!=null&&this._imeInputManagerService.setActiveRange(n.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async i=>{this._updateContent(i,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(i=>{this._updateContent(i,!1)})}async _updateContent(i,e){var u;const t=(u=this._docSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(i==null||t==null)return;const a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return;const{event:s,activeRange:r}=i;if(t==null||r==null)return;const d=s.data;d===this._previousIMEContent&&e||(await this._commandService.executeCommand(Te.id,{unitId:a.getUnitId(),newText:d,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=d):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};ue=Lt([n.OnLifecycle(n.LifecycleStages.Rendered,ue),Z(0,L.Inject(c.DocSkeletonManagerService)),Z(1,n.IUniverInstanceService),Z(2,O.ITextSelectionRenderManager),Z(3,L.Inject(G)),Z(4,n.ICommandService)],ue);var Bt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,$t=(o,i,e,t)=>{for(var a=t>1?void 0:t?Ft(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&Bt(i,e,a),a},K=(o,i)=>(e,t)=>i(e,t,o);let me=class extends n.Disposable{constructor(i,e,t,a,s){super();y(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionManagerService=a,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){}_commandExecutedListener(){const i=[le.id,de.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!i.includes(e.id))return;const t=e.params;switch(e.id){case le.id:return this._handleMoveCursor(t.direction);case de.id:return this._handleShiftMoveSelection(t.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(i){var p,h,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return;const s=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:l,endOffset:d,style:u,collapsed:m,direction:g}=e;if(t.length>1){let C=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const _ of t)C=Math.min(C,_.startOffset),T=Math.max(T,_.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===n.Direction.LEFT||i===n.Direction.UP?T:C,endOffset:i===n.Direction.LEFT||i===n.Direction.UP?C:T,style:u}],!1);return}const S=m||g===O.RANGE_DIRECTION.FORWARD?l:d;let f=m||g===O.RANGE_DIRECTION.FORWARD?d:l;const v=(h=a.getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){const C=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===n.Direction.RIGHT?f+T.count:f-((I=C==null?void 0:C.count)!=null?I:0),f=Math.min(v-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:f,style:u}],!1)}else{const C=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,C,i===n.Direction.DOWN);if(_==null){const x=i===n.Direction.UP?0:v-2;if(x===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:x,style:u}],!1);return}const M=new O.NodePositionConvertToCursor(T,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:S,endOffset:M.endOffset,style:u}],!1)}}_handleMoveCursor(i){var S,f,v;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return!1;const s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:l,endOffset:d,style:u,collapsed:m}=e,g=(f=a.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){let p;if(!e.collapsed||t.length>1){let h=Number.POSITIVE_INFINITY,I=Number.NEGATIVE_INFINITY;for(const C of t)h=Math.min(h,C.startOffset),I=Math.max(I,C.endOffset);p=i===n.Direction.LEFT?h:I}else{const h=s.findNodeByCharIndex(l-1),I=s.findNodeByCharIndex(l);i===n.Direction.LEFT?p=Math.max(0,l-((v=h==null?void 0:h.count)!=null?v:0)):p=Math.min(g-2,d+I.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:p,style:u}],!1)}else{const p=s.findNodeByCharIndex(l),h=s.findNodeByCharIndex(d),I=r.document.getOffsetConfig(),C=this._getTopOrBottomPosition(s,i===n.Direction.UP?p:h,i===n.Direction.DOWN);if(C==null){let _;m?_=i===n.Direction.UP?0:g-2:_=i===n.Direction.UP?l:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:u}],!1);return}const T=new O.NodePositionConvertToCursor(I,s).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...T,style:u}],!1)}}_getTopOrBottomPosition(i,e,t){if(e==null)return;const a=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,t);if(s==null)return;const r=this._matchPositionByLeftOffset(i,s,a);if(r!=null)return{...r,isBack:!0}}_getSpanLeftOffsetInLine(i){const e=i.parent;if(e==null)return Number.NEGATIVE_INFINITY;const t=e.left,{left:a}=i;return t+a}_matchPositionByLeftOffset(i,e,t){const a={distance:Number.POSITIVE_INFINITY};for(const s of e.divides){const r=s.left;for(const l of s.glyphGroup){const{left:d}=l,u=r+d,m=Math.abs(t-u);m<a.distance&&(a.glyph=l,a.distance=m)}}if(a.glyph!=null)return i.findPositionByGlyph(a.glyph)}_getNextOrPrevLine(i,e){var v,p,h,I,C,T,_,M,x,D,E,P;const t=i.parent;if(t==null)return;const a=t.parent;if(a==null)return;const s=a.parent;if(s==null)return;const r=s.lines.indexOf(a);if(r===-1)return;let l;if(e===!0?l=s.lines[r+1]:l=s.lines[r-1],l!=null)return l;const d=s.parent;if(d==null)return;const u=d.columns.indexOf(s);if(u===-1)return;if(e===!0)l=(v=d.columns[u+1])==null?void 0:v.lines[0];else{const R=(h=(p=d.columns)==null?void 0:p[u-1])==null?void 0:h.lines;l=R==null?void 0:R[R.length-1]}if(l!=null)return l;const m=d.parent;if(m==null)return;const g=m.sections.indexOf(d);if(g===-1)return;if(e===!0)l=(C=(I=m.sections[g-1])==null?void 0:I.columns[0])==null?void 0:C.lines[0];else{const R=(_=(T=m.sections)==null?void 0:T[g-1])==null?void 0:_.columns,A=R==null?void 0:R[R.length-1],U=A==null?void 0:A.lines;l=U==null?void 0:U[U.length-1]}if(l!=null)return l;const S=m.parent;if(S==null)return;const f=S.pages.indexOf(m);if(f!==-1){if(e===!0)l=(D=(x=(M=S.pages[f+1])==null?void 0:M.sections[0])==null?void 0:x.columns[0])==null?void 0:D.lines[0];else{const R=(E=S.pages[f-1])==null?void 0:E.sections;if(R==null)return;const A=(P=R[R.length-1])==null?void 0:P.columns,U=A[A.length-1],X=U==null?void 0:U.lines;l=X[X.length-1]}if(l!=null)return l}}_getDocObject(){return fe(this._univerInstanceService,this._renderManagerService)}};me=$t([n.OnLifecycle(n.LifecycleStages.Rendered,me),K(0,L.Inject(c.DocSkeletonManagerService)),K(1,n.IUniverInstanceService),K(2,O.IRenderManagerService),K(3,L.Inject(c.TextSelectionManagerService)),K(4,n.ICommandService)],me);var kt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,Vt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Xt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&kt(i,e,a),a},q=(o,i)=>(e,t)=>i(e,t,o);let ge=class extends n.Disposable{constructor(i,e,t,a,s){super();y(this,"_onInputSubscription");this._docSkeletonManagerService=i,this._univerInstanceService=e,this._renderManagerService=t,this._textSelectionRenderManager=a,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var i;(i=this._onInputSubscription)==null||i.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var v;if(i==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.getUnitId(),{event:a,content:s="",activeRange:r}=i,l=a,d=(v=this._docSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(l.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:m,style:g}=r,S=s.length,f=[{startOffset:u+S,endOffset:u+S,style:g}];await this._commandService.executeCommand(H.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:m})})}_commandExecutedListener(){}_getDocObject(){return fe(this._univerInstanceService,this._renderManagerService)}};ge=Vt([n.OnLifecycle(n.LifecycleStages.Rendered,ge),q(0,L.Inject(c.DocSkeletonManagerService)),q(1,n.IUniverInstanceService),q(2,O.IRenderManagerService),q(3,O.ITextSelectionRenderManager),q(4,n.ICommandService)],ge);var zt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Gt=(o,i,e,t)=>{for(var a=t>1?void 0:t?jt(i,e):i,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(t?r(i,e,a):r(a))||a);return t&&a&&zt(i,e,a),a},Ht=(o,i)=>(e,t)=>i(e,t,o);const Yt={hasScroll:!0},Wt="docs";c.UniverDocsPlugin=(Se=class extends n.Plugin{constructor(e={},t){super();y(this,"_config");this._injector=t,this._config=Object.assign(Yt,e),this._initializeDependencies(t),this._initializeCommands()}initialize(){}_initializeCommands(){[le,de,be,Pe,Q,ee,te,ne,z,ie,ae,oe,se,ce,re,ye,Ue,H,Y,Ie,Te,Me,N,tt,nt,at,W,he,ot,Ze,We,Oe,qe,Je,Qe,j,et].forEach(e=>{this._injector.get(n.ICommandService).registerCommand(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[c.DocSkeletonManagerService],[c.DocViewModelManagerService],[c.DocStateChangeManagerService],[G],[O.ITextSelectionRenderManager,{useClass:O.TextSelectionRenderManager}],[c.TextSelectionManagerService],[ge],[ue],[me]].forEach(t=>e.add(t))}},y(Se,"pluginName",Wt),y(Se,"type",n.UniverInstanceType.UNIVER_DOC),Se),c.UniverDocsPlugin=Gt([Ht(1,L.Inject(L.Injector))],c.UniverDocsPlugin),c.AlignCenterCommand=Je,c.AlignJustifyCommand=et,c.AlignLeftCommand=qe,c.AlignOperationCommand=j,c.AlignRightCommand=Qe,c.BreakLineCommand=Ue,c.BulletListCommand=We,c.CoverContentCommand=nt,c.CutContentCommand=_e,c.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=rt,c.DOCS_COMPONENT_DEFAULT_Z_INDEX=dt,c.DOCS_COMPONENT_HEADER_LAYER_INDEX=lt,c.DOCS_COMPONENT_MAIN_LAYER_INDEX=ct,c.DOCS_VIEW_KEY=J,c.DeleteCommand=Y,c.DeleteLeftCommand=be,c.DeleteRightCommand=Pe,c.IMEInputCommand=Te,c.IMEInputManagerService=G,c.InnerPasteCommand=Dt,c.InsertCommand=H,c.MoveCursorOperation=le,c.MoveSelectionOperation=de,c.NORMAL_TEXT_SELECTION_PLUGIN_NAME=ut,c.OrderListCommand=Ze,c.ReplaceContentCommand=tt,c.ResetInlineFormatTextBackgroundColorCommand=ce,c.RichTextEditingMutation=N,c.SelectAllOperation=ot,c.SetDocZoomRatioCommand=at,c.SetDocZoomRatioOperation=W,c.SetInlineFormatBoldCommand=Q,c.SetInlineFormatCommand=ye,c.SetInlineFormatFontFamilyCommand=oe,c.SetInlineFormatFontSizeCommand=ae,c.SetInlineFormatItalicCommand=ee,c.SetInlineFormatStrikethroughCommand=ne,c.SetInlineFormatSubscriptCommand=z,c.SetInlineFormatSuperscriptCommand=ie,c.SetInlineFormatTextBackgroundColorCommand=re,c.SetInlineFormatTextColorCommand=se,c.SetInlineFormatUnderlineCommand=te,c.SetTextSelectionsOperation=he,c.UpdateCommand=Ie,c.VIEWPORT_KEY=Ee,c.getDocObject=fe,c.getDocObjectById=mt,c.serializeTextRange=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@wendellhu/redi": "^0.13.3",
|
|
54
54
|
"rxjs": ">=7.0.0",
|
|
55
|
-
"@univerjs/core": "0.1.
|
|
56
|
-
"@univerjs/engine-render": "0.1.
|
|
55
|
+
"@univerjs/core": "0.1.10",
|
|
56
|
+
"@univerjs/engine-render": "0.1.10"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@wendellhu/redi": "^0.13.3",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"typescript": "^5.4.5",
|
|
62
62
|
"vite": "^5.2.10",
|
|
63
63
|
"vitest": "^1.5.0",
|
|
64
|
-
"@univerjs/core": "0.1.
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/
|
|
64
|
+
"@univerjs/core": "0.1.10",
|
|
65
|
+
"@univerjs/engine-render": "0.1.10",
|
|
66
|
+
"@univerjs/shared": "0.1.10"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"test": "vitest run",
|