@univerjs/docs 0.1.13 → 0.1.15
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.
|
@@ -8,6 +8,7 @@ export interface IInsertCommandParams {
|
|
|
8
8
|
textRanges: ITextRangeWithStyle[];
|
|
9
9
|
segmentId?: string;
|
|
10
10
|
}
|
|
11
|
+
export declare const EditorInsertTextCommandId = "doc.command.insert-text";
|
|
11
12
|
/**
|
|
12
13
|
* The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
|
|
13
14
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -17,11 +17,11 @@ export type { IDocObjectParam } from './basics/component-tools';
|
|
|
17
17
|
export { getDocObject, getDocObjectById } from './basics/component-tools';
|
|
18
18
|
export * from './basics/docs-view-key';
|
|
19
19
|
export { BreakLineCommand } from './commands/commands/break-line.command';
|
|
20
|
-
export { DeleteCommand, type ICoverCommandParams, type IDeleteCommandParams, type IInsertCommandParams, InsertCommand, type IUpdateCommandParams, UpdateCommand, } from './commands/commands/core-editing.command';
|
|
20
|
+
export { DeleteCommand, type ICoverCommandParams, type IDeleteCommandParams, type IInsertCommandParams, InsertCommand, type IUpdateCommandParams, UpdateCommand, EditorInsertTextCommandId, } from './commands/commands/core-editing.command';
|
|
21
21
|
export { DeleteLeftCommand, DeleteRightCommand } from './commands/commands/delete.command';
|
|
22
22
|
export { type IIMEInputCommandParams, IMEInputCommand } from './commands/commands/ime-input.command';
|
|
23
23
|
export { SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextBackgroundColorCommand, } from './commands/commands/inline-format.command';
|
|
24
|
-
export { AlignOperationCommand, AlignLeftCommand, AlignCenterCommand, AlignRightCommand, AlignJustifyCommand } from './commands/commands/paragraph-align.command';
|
|
24
|
+
export { AlignOperationCommand, AlignLeftCommand, AlignCenterCommand, AlignRightCommand, AlignJustifyCommand, } from './commands/commands/paragraph-align.command';
|
|
25
25
|
export { BulletListCommand, OrderListCommand } from './commands/commands/list.command';
|
|
26
26
|
export { CoverContentCommand, ReplaceContentCommand } from './commands/commands/replace-content.command';
|
|
27
27
|
export { type IRichTextEditingMutationParams, RichTextEditingMutation, } from './commands/mutations/core-editing.mutation';
|
|
@@ -26,7 +26,6 @@ export declare class DocSkeletonManagerService extends RxDisposable {
|
|
|
26
26
|
private _init;
|
|
27
27
|
getCurrent(): Nullable<IDocSkeletonManagerParam>;
|
|
28
28
|
getAllSkeleton(): Map<string, IDocSkeletonManagerParam>;
|
|
29
|
-
makeDirtyCurrent(state?: boolean): void;
|
|
30
29
|
makeDirty(unitId: string, state?: boolean): void;
|
|
31
30
|
getSkeletonByUnitId(unitId: string): Nullable<IDocSkeletonManagerParam>;
|
|
32
31
|
private _setCurrent;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,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):(l=typeof globalThis<"u"?globalThis:l||self,n(l.UniverDocs={},l.UniverCore,l.UniverEngineRender,l.rxjs,l["@wendellhu/redi"]))})(this,function(l,n,O,w,L){"use strict";var Kt=Object.defineProperty;var qt=(l,n,O)=>n in l?Kt(l,n,{enumerable:!0,configurable:!0,writable:!0,value:O}):l[n]=O;var y=(l,n,O)=>(qt(l,typeof n!="symbol"?n+"":n,O),O);var Se;var q=(o=>(o.MAIN="__Document_Render_Main__",o.BACKGROUND="__Document_Render_Background__",o))(q||{}),xe=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(xe||{});const ct=0,lt=2,dt=4,ut=10,mt="normalTextSelectionPluginName";function Ee(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:c,components:d}=a,u=s,m=d.get(q.BACKGROUND);return{document:u,docBackground:m,scene:r,engine:c}}function gt(o,i){const e=i.getRenderById(o);if(e==null)return;const{mainComponent:t,scene:a,engine:s,components:r}=e,c=t,d=r.get(q.BACKGROUND);return{document:c,docBackground:d,scene:a,engine:s}}const fe={id:"doc.operation.set-selections",type:n.CommandType.OPERATION,handler:(o,i)=>!0};var St=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,ht=(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&&St(i,e,a),a},Ae=(o,i)=>(e,t)=>i(e,t,o);function $(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}l.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}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(a=>a.isActive())}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:c,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:S,direction:g}=r;return c==null||d==null?null:{startOffset:c,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:S,direction:g,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:c,textRanges:d,isEditing:u}=t;this._commandService.executeCommand(fe.id,{unitId:a,subUnitId:s,segmentId:r,style:c,isEditing:u,ranges:d.map($)})}_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($))}_replaceByParam(e){const{unitId:t,subUnitId:a,style:s,segmentId:r,textRanges:c,isEditing:d}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(a,{textRanges:c,style:s,segmentId:r,isEditing:d})}_addByParam(e){const{unitId:t,subUnitId:a,textRanges:s,style:r,segmentId:c,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:c,isEditing:d})}},l.TextSelectionManagerService=ht([Ae(0,O.ITextSelectionRenderManager),Ae(1,n.ICommandService)],l.TextSelectionManagerService);function he(o,i="",e=0){const{startOffset:t,endOffset:a}=o,s=[],r=t-e,c=a-e;return r>0&&s.push({t:n.TextXActionType.RETAIN,len:r,segmentId:i}),s.push({t:n.TextXActionType.DELETE,len:c-r,line:0,segmentId:i}),s}var pt=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,It=(o,i,e,t)=>{for(var a=t>1?void 0:t?vt(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},Ct=(o,i)=>(e,t)=>i(e,t,o);l.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)}},l.DocViewModelManagerService=It([Ct(0,n.IUniverInstanceService)],l.DocViewModelManagerService);var _t=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,Tt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Mt(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},pe=(o,i)=>(e,t)=>i(e,t,o);const yt=300;l.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===J.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(a)},yt)):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,c=a[0],d=a[s-1],u={unitId:e,actions:a.reduce((S,g)=>n.JSONX.compose(S,g.redoState.actions),null),textRanges:d.redoState.textRanges},m={unitId:e,actions:a.reverse().reduce((S,g)=>n.JSONX.compose(S,g.undoState.actions),null),textRanges:c.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:m}],redoMutations:[{id:r,params:u}]}),a.length=0}},l.DocStateChangeManagerService=Tt([pe(0,L.Inject(n.IUndoRedoService)),pe(1,n.ICommandService),pe(2,n.IUniverInstanceService)],l.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.JSONX.compose(a,s.actions),null),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((a,s)=>n.JSONX.compose(a,s.actions),null),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 b;const{unitId:e,segmentId:t="",actions:a,textRanges:s,prevTextRanges:r,trigger:c,noHistory:d,isCompositionEnd:u,noNeedSetTextRange:m}=i,g=o.get(n.IUniverInstanceService).getUniverDocInstance(e),I=o.get(l.DocViewModelManagerService).getViewModel(e),h=o.get(l.TextSelectionManagerService),C=((b=h.getSelections())!=null?b:[]).map($),v=o.get(l.DocStateChangeManagerService),T=o.get(G);if(g==null||I==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const M=!!g.getSnapshot().disabled;if(n.JSONX.isNoop(a)||a&&a.length===0||M)return{unitId:e,actions:[],textRanges:C};const _=n.JSONX.invertWithDoc(a,g.getSnapshot());g.apply(a);const x=g.getSelfOrHeaderFooterModel(t);I.getSelfOrHeaderFooterViewModel(t).reset(x),!m&&s&&c!=null&&queueMicrotask(()=>{h.replaceTextRanges(s)});const E={commandId:Ne,unitId:e,segmentId:t,trigger:c,noHistory:d,redoState:{actions:a,textRanges:s},undoState:{actions:_,textRanges:r!=null?r:C}};if(u){const R=T.fetchComposedUndoRedoMutationParams();if(R==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:A,redoMutationParams:U,previousActiveRange:k}=R;E.redoState.actions=U.actions,E.undoState.actions=A.actions,E.undoState.textRanges=[k]}return v.setChangeState(E),{unitId:e,actions:_,textRanges:C}}},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:c}=i,{startOffset:d,collapsed:u}=t,m={id:N.id,params:{unitId:r,actions:[],textRanges:c}},S=new n.TextX,g=n.JSONX.getInstance();return u?d>0&&S.push({t:n.TextXActionType.RETAIN,len:d,segmentId:a}):S.push(...he(t,a)),S.push({t:n.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:a}),m.params.actions=g.editOp(S.serialize()),!!e.syncExecuteCommand(m.id,m.params)}};var F=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(F||{});const J={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:c,len:d=1}=i,{startOffset:u}=t,m={id:N.id,params:{unitId:s,actions:[],textRanges:c}},S=new n.TextX,g=n.JSONX.getInstance();return u>0&&S.push({t:n.TextXActionType.RETAIN,len:r===0?u-d:u,segmentId:a}),S.push({t:n.TextXActionType.DELETE,len:d,line:0,segmentId:a}),m.params.actions=g.editOp(S.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:c}=i,d=o.get(n.ICommandService),u={id:N.id,params:{unitId:r,actions:[],textRanges:c}},m=new n.TextX,S=n.JSONX.getInstance(),{startOffset:g,endOffset:f}=e;return m.push({t:n.TextXActionType.RETAIN,len:g,segmentId:t}),m.push({t:n.TextXActionType.RETAIN,body:a,len:f-g,segmentId:t,coverType:s}),u.params.actions=S.editOp(m.serialize()),!!d.syncExecuteCommand(u.id,u.params)}};function Ot(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 I,h;const i=o.get(l.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:c,segmentId:d,style:u}=a,m=[{startOffset:c+1,endOffset:c+1,style:u}],g=((h=(I=s.getBody())==null?void 0:I.paragraphs)!=null?h:[]).find(p=>p.startIndex>=c);return await t.executeCommand(H.id,{unitId:r,body:{dataStream:n.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Ot(n.DataStreamTreeTokenType.PARAGRAPH,g)},range:a,textRanges:m,segmentId:d})}};var Rt=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,xt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Dt(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&&Rt(i,e,a),a},Ie=(o,i)=>(e,t)=>i(e,t,o);l.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)}},l.DocSkeletonManagerService=xt([Ie(0,L.Inject(n.LocaleService)),Ie(1,L.Inject(l.DocViewModelManagerService)),Ie(2,n.IUniverInstanceService)],l.DocSkeletonManagerService);const Et={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(l.TextSelectionManagerService),c=o.get(n.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=c.getCurrentUniverDocInstance();if(!u)return!1;const m=u.getUnitId(),S={id:N.id,params:{unitId:m,actions:[],textRanges:a}},g=new n.MemoryCursor;g.reset();const f=new n.TextX,I=n.JSONX.getInstance();for(const p of d){const{startOffset:C,endOffset:v,collapsed:T}=p,M=C-g.cursor;T?f.push({t:n.TextXActionType.RETAIN,len:M,segmentId:e}):f.push(...he(p,e,g.cursor)),f.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(v)}return S.params.actions=I.editOp(f.serialize()),!!s.syncExecuteCommand(S.id,S.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(l.TextSelectionManagerService),r=o.get(n.IUniverInstanceService),c=s.getSelections();if(!Array.isArray(c)||c.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.getSnapshot(),e);if(m==null)return!1;const S={id:N.id,params:{unitId:d,actions:[],textRanges:t}},g=new n.MemoryCursor;g.reset();const f=new n.TextX,I=n.JSONX.getInstance();for(const C of c){const{startOffset:v,endOffset:T,collapsed:M}=C,_=v-g.cursor;M?f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}):f.push(...At(C,m,e,g.cursor)),g.reset(),g.moveCursor(T)}return S.params.actions=I.editOp(f.serialize()),!!a.syncExecuteCommand(S.id,S.params)}};function At(o,i,e="",t=0){const{startOffset:a,endOffset:s}=o,r=[],{paragraphs:c=[]}=i,d=a-t,u=s-t,m=c==null?void 0:c.find(S=>S.startIndex-t>=d&&S.startIndex-t<=u);if(d>0&&r.push({t:n.TextXActionType.RETAIN,len:d,segmentId:e}),m&&m.startIndex-t>d){const S=m.startIndex-t;r.push({t:n.TextXActionType.DELETE,len:S-d,line:0,segmentId:e}),r.push({t:n.TextXActionType.RETAIN,len:1,segmentId:e}),u>S+1&&r.push({t:n.TextXActionType.DELETE,len:u-S-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 M;const i=o.get(l.TextSelectionManagerService),e=o.get(l.DocSkeletonManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(M=e.getCurrent())==null?void 0:M.skeleton;let d=!0;if(s==null||c==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:S,segmentId:g,style:f}=s,I=c.findNodeByCharIndex(m),h=O.hasListGlyph(I),p=O.isIndentByGlyph(I,u.getBody());let C=m;const v=c.findNodeByCharIndex(m-1);if(O.isFirstGlyph(I)&&v!==I&&(h===!0||p===!0)&&S){const _=O.getParagraphByGlyph(I,u.getBody());if(_==null)return!1;const x=_==null?void 0:_.startIndex,D={startIndex:0},E=_.paragraphStyle;if(h===!0){const R=_.paragraphStyle;if(R){D.paragraphStyle=R;const{hanging:A}=R;A&&(D.paragraphStyle.indentStart=A,D.paragraphStyle.hanging=void 0)}}else if(p===!0){const R=_.bullet;R&&(D.bullet=R),E!=null&&(D.paragraphStyle={...E},delete D.paragraphStyle.hanging,delete D.paragraphStyle.indentStart)}const b=[{startOffset:C,endOffset:C,style:f}];d=await a.executeCommand(ve.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...D}]},range:{startOffset:x,endOffset:x+1},textRanges:b,coverType:n.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(S===!0){if(v==null)return!0;if(v.content==="\r")d=await a.executeCommand(_e.id,{direction:F.LEFT,range:s});else{C-=v.count;const _=[{startOffset:C,endOffset:C,style:f}];d=await a.executeCommand(J.id,{unitId:u.getUnitId(),range:s,segmentId:g,direction:F.LEFT,len:v.count,textRanges:_})}}else{const _=we(s,r);d=await a.executeCommand(Ce.id,{segmentId:g,textRanges:_})}return d}},Pe={id:"doc.command.delete-right",type:n.CommandType.COMMAND,handler:async o=>{var I;const i=o.get(l.TextSelectionManagerService),e=o.get(l.DocSkeletonManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),s=i.getActiveRange(),r=i.getSelections(),c=(I=e.getCurrent())==null?void 0:I.skeleton;let d;if(s==null||c==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:S,segmentId:g,style:f}=s;if(m===u.getBody().dataStream.length-2&&S)return!0;if(S===!0){const h=c.findNodeByCharIndex(m);if(h.content==="\r")d=await a.executeCommand(_e.id,{direction:F.RIGHT,range:s});else{const p=[{startOffset:m,endOffset:m,style:f}];d=await a.executeCommand(J.id,{unitId:u.getUnitId(),range:s,segmentId:g,direction:F.RIGHT,textRanges:p,len:h.count})}}else{const h=we(s,r);d=await a.executeCommand(Ce.id,{segmentId:g,textRanges:h})}return d}},_e={id:"doc.command.merge-two-paragraph",type:n.CommandType.COMMAND,handler:async(o,i)=>{var E,b,R;const e=o.get(l.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{direction:s,range:r}=i,c=e.getActiveRange(),d=e.getSelections();if(c==null||d==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:S,segmentId:g,style:f}=c;if(!S)return!1;const I=s===F.LEFT?m:m+1,h=(R=(b=(E=u.getBody())==null?void 0:E.paragraphs)==null?void 0:b.find(A=>A.startIndex>=I))==null?void 0:R.startIndex,p=Nt(u.getBody(),I,h),C=s===F.LEFT?m-1:m,v=u.getUnitId(),T=[{startOffset:C,endOffset:C,style:f}],M={id:N.id,params:{unitId:v,actions:[],textRanges:T,prevTextRanges:[r]}},_=new n.TextX,x=n.JSONX.getInstance();return _.push({t:n.TextXActionType.RETAIN,len:s===F.LEFT?m-1:m,segmentId:g}),p.dataStream.length&&_.push({t:n.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:g}),_.push({t:n.TextXActionType.RETAIN,len:1,segmentId:g}),_.push({t:n.TextXActionType.DELETE,len:h+1-I,line:0,segmentId:g}),M.params.actions=x.editOp(_.serialize()),!!a.syncExecuteCommand(M.id,M.params)}};function Nt(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:c,ed:d}=r;d<=i||c>=e||(c<i?s.push({...r,st:0,ed:d-i}):d>e?s.push({...r,st:c-i,ed:e-i}):s.push({...r,st:c-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,c=o.get(n.ICommandService),d=o.get(G),u=d.getActiveRange();if(u==null)return!1;const{startOffset:m,style:S,segmentId:g}=u,f=t.length,I=[{startOffset:m+f,endOffset:m+f,collapsed:!0,style:S}],h={id:N.id,params:{unitId:e,actions:[],textRanges:I}},p=new n.TextX,C=n.JSONX.getInstance();!u.collapsed&&r?p.push(...he(u,g)):p.push({t:n.TextXActionType.RETAIN,len:m,segmentId:g}),a>0&&p.push({t:n.TextXActionType.DELETE,len:a,line:0,segmentId:g}),p.push({t:n.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),h.params.actions=C.editOp(p.serialize()),h.params.noHistory=!s,h.params.isCompositionEnd=s;const v=c.syncExecuteCommand(h.id,h.params);return d.pushUndoRedoMutationParams(v,h.params),!!v}};function P(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",Q={id:Le,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(l.TextSelectionManagerService);return P(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(l.TextSelectionManagerService);return P(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(l.TextSelectionManagerService);return P(Fe,i,t,e)}},Xe="doc.command.set-inline-format-strikethrough",ne={id:Xe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(l.TextSelectionManagerService);return P(Xe,i,t,e)}},$e="doc.command.set-inline-format-subscript",j={id:$e,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(l.TextSelectionManagerService);return P($e,i,t,e)}},ke="doc.command.set-inline-format-superscript",ie={id:ke,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(l.TextSelectionManagerService);return P(ke,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(l.TextSelectionManagerService);return P(Ve,i,t,e)}},je="doc.command.set-inline-format-font-family",oe={id:je,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(l.TextSelectionManagerService);return P(je,i,t,e)}},ze="doc.command.set-inline-format-text-color",se={id:ze,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(l.TextSelectionManagerService);return P(ze,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(l.TextSelectionManagerService);return P(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(l.TextSelectionManagerService);return P(He,i,t,e)}},Je={[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",[j.id]:"va",[ie.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(l.TextSelectionManagerService),c=o.get(n.IUniverInstanceService),d=r.getSelections();if(!Array.isArray(d)||d.length===0)return!1;let u=c.getCurrentUniverDocInstance();if(!u)return!1;let m=u.getUnitId();m===n.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=c.getUniverDocInstance(n.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),m=u.getUnitId());let S;switch(a){case Q.id:case ee.id:case te.id:case ne.id:case j.id:case ie.id:{S=bt(u.getBody().textRuns,a,d);break}case ae.id:case oe.id:{S=t;break}case se.id:case re.id:{S={rgb:t};break}case ce.id:{S={rgb:null};break}default:throw new Error(`Unknown command: ${a} in handleInlineFormat`)}const g={id:N.id,params:{unitId:m,actions:[],textRanges:d.map($)}},f=new n.TextX,I=n.JSONX.getInstance(),h=new n.MemoryCursor;h.reset();for(const C of d){const{startOffset:v,endOffset:T}=C,M={dataStream:"",textRuns:[{st:0,ed:T-v,ts:{[Je[a]]:S}}]},_=v-h.cursor;_!==0&&f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}),f.push({t:n.TextXActionType.RETAIN,body:M,len:T-v,segmentId:e}),h.reset(),h.moveCursor(T)}return g.params.actions=I.editOp(f.serialize()),!!s.syncExecuteCommand(g.id,g.params)}};function Ut(o){return o!==null&&typeof o=="object"}function bt(o,i,e){let t=0,a=0;const s=Je[i];for(;t!==o.length&&a!==e.length;){const{startOffset:r,endOffset:c}=e[a],{st:d,ed:u,ts:m}=o[t];if(c<=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 Ut(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===j.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===j.id?n.BaselineOffset.SUBSCRIPT:n.BaselineOffset.SUPERSCRIPT}const ye={id:"doc.command.list-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var A,U,k,st;const e=o.get(l.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{listType:s}=i,r=t.getCurrentUniverDocInstance();if(!r)return!1;const c=e.getActiveRange(),d=(A=e.getSelections())!=null?A:[],u=(U=r.getBody())==null?void 0:U.paragraphs,m=d.map($);if(c==null||u==null)return!1;const S=Ze(c,u),{segmentId:g}=c,f=r.getUnitId(),I=S.every(V=>{var B;return((B=V.bullet)==null?void 0:B.listType)===s});let p=n.Tools.generateRandomId(6);if(S.length===1){const V=u.indexOf(S[0]),B=u[V-1],X=u[V+1];B&&B.bullet&&B.bullet.listType===s?p=B.bullet.listId:X&&X.bullet&&X.bullet.listType===s&&(p=X.bullet.listId)}const C={id:N.id,params:{unitId:f,actions:[],textRanges:m}},v=new n.MemoryCursor;v.reset();const T=new n.TextX,M=n.JSONX.getInstance(),_=(k=r.getSnapshot().lists)!=null?k:{},x={...n.PRESET_LIST_TYPE,..._},{charSpace:D,defaultTabStop:E=36,gridType:b}=r.getSnapshot().documentStyle;for(const V of S){const{startIndex:B,paragraphStyle:X={}}=V,{indentFirstLine:Wt=0,snapToGrid:Zt,indentStart:Oe=0}=X,{hanging:Re,indentStart:rt}=x[s].nestingLevel[0],De=O.getCharSpaceApply(D,E,b,Zt);T.push({t:n.TextXActionType.RETAIN,len:B-v.cursor,segmentId:g}),T.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[I?{paragraphStyle:{...X,hanging:void 0,indentStart:Oe?Math.max(0,O.getNumberUnitValue(Oe,De)+Re-rt):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...X,indentFirstLine:void 0,hanging:Re,indentStart:rt-Re+O.getNumberUnitValue(Wt,De)+O.getNumberUnitValue(Oe,De)},bullet:{...(st=V.bullet)!=null?st:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:p}}]},segmentId:g,coverType:n.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(B+1)}return C.params.actions=M.editOp(T.serialize()),!!a.syncExecuteCommand(C.id,C.params)}},Ye={id:"doc.command.bullet-list",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(ye.id,{listType:n.PresetListType.BULLET_LIST})},We={id:"doc.command.order-list",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(ye.id,{listType:n.PresetListType.ORDER_LIST})};function Ze(o,i){const{startOffset:e,endOffset:t}=o,a=[];let s=-1;for(const r of i){const{startIndex:c}=r;(e>s&&e<=c||t>s&&t<=c||c>=e&&c<=t)&&a.push(r),s=c}return a}const z={id:"doc.command.align-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var M,_;const e=o.get(l.TextSelectionManagerService),t=o.get(n.IUniverInstanceService),a=o.get(n.ICommandService),{alignType:s}=i,r=t.getCurrentUniverDocInstance();if(!r)return!1;const c=e.getActiveRange(),d=(M=e.getSelections())!=null?M:[],u=(_=r.getBody())==null?void 0:_.paragraphs,m=d.map($);if(c==null||u==null)return!1;const S=Ze(c,u),{segmentId:g}=c,f=r.getUnitId(),I=S.every(x=>{var D;return((D=x.paragraphStyle)==null?void 0:D.horizontalAlign)===s}),h={id:N.id,params:{unitId:f,actions:[],textRanges:m}},p=new n.MemoryCursor;p.reset();const C=new n.TextX,v=n.JSONX.getInstance();for(const x of S){const{startIndex:D}=x;C.push({t:n.TextXActionType.RETAIN,len:D-p.cursor,segmentId:g});const E={...x.paragraphStyle,horizontalAlign:I?n.HorizontalAlign.UNSPECIFIED:s};C.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...x,paragraphStyle:E,startIndex:0}]},segmentId:g,coverType:n.UpdateDocsAttributeType.REPLACE}),p.moveCursorTo(D+1)}return h.params.actions=v.editOp(C.serialize()),!!a.syncExecuteCommand(h.id,h.params)}},Ke={id:"doc.command.align-left",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.LEFT})},qe={id:"doc.command.align-center",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.CENTER})},Qe={id:"doc.command.align-right",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.RIGHT})},et={id:"doc.command.align-justify",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.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),c=o.get(n.ICommandService),d=o.get(l.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 S=it(e,s,u,t);return S.params.textRanges=a,!!c.syncExecuteCommand(S.id,S.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),c=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),c.clearUndoRedo(e),!0}};function it(o,i,e,t){const a={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new n.TextX,r=n.JSONX.getInstance(),c=(e==null?void 0:e.dataStream.length)-2;return c>0&&s.push({t:n.TextXActionType.DELETE,len:c,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=r.editOp(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},Pt=(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}},Y={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 S,g,f;const e=o.get(n.ICommandService),t=o.get(n.IUndoRedoService),a=o.get(n.IUniverInstanceService);let s=(S=a.getCurrentUniverDocInstance())==null?void 0:S.getUnitId();if(!s)return!1;let r=1;if(i&&(s=(g=i.documentId)!=null?g:s,r=(f=i.zoomRatio)!=null?f:r),!a.getUniverDocInstance(s))return!1;const d={zoomRatio:r,unitId:s},u=Pt(o,d);return e.syncExecuteCommand(Y.id,d)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:Y.id,params:u}],redoMutations:[{id:Y.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(l.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 wt=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,Bt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Lt(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&&wt(i,e,a),a},W=(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(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)}};ue=Bt([n.OnLifecycle(n.LifecycleStages.Rendered,ue),W(0,L.Inject(l.DocSkeletonManagerService)),W(1,n.IUniverInstanceService),W(2,O.ITextSelectionRenderManager),W(3,L.Inject(G)),W(4,n.ICommandService)],ue);var Ft=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,$t=(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&&Ft(i,e,a),a},Z=(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._commandExecutedListener()}dispose(){var i;super.dispose(),(i=this._onInputSubscription)==null||i.unsubscribe()}_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 h,p,C;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return;const s=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:m,direction:S}=e;if(t.length>1){let v=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const M of t)v=Math.min(v,M.startOffset),T=Math.max(T,M.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===n.Direction.LEFT||i===n.Direction.UP?T:v,endOffset:i===n.Direction.LEFT||i===n.Direction.UP?v:T,style:u}],!1);return}const g=m||S===O.RANGE_DIRECTION.FORWARD?c:d;let f=m||S===O.RANGE_DIRECTION.FORWARD?d:c;const I=(p=a.getBody().dataStream.length)!=null?p:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){const v=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===n.Direction.RIGHT?f+T.count:f-((C=v==null?void 0:v.count)!=null?C:0),f=Math.min(I-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:f,style:u}],!1)}else{const v=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),M=this._getTopOrBottomPosition(s,v,i===n.Direction.DOWN);if(M==null){const x=i===n.Direction.UP?0:I-2;if(x===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:x,style:u}],!1);return}const _=new O.NodePositionConvertToCursor(T,s).getRangePointData(M,M).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:_.endOffset,style:u}],!1)}}_handleMoveCursor(i){var g,f,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return!1;const s=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:m}=e,S=(f=a.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){let h;if(!e.collapsed||t.length>1){let p=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY;for(const v of t)p=Math.min(p,v.startOffset),C=Math.max(C,v.endOffset);h=i===n.Direction.LEFT?p:C}else{const p=s.findNodeByCharIndex(c-1),C=s.findNodeByCharIndex(c);i===n.Direction.LEFT?h=Math.max(0,c-((I=p==null?void 0:p.count)!=null?I:0)):h=Math.min(S-2,d+C.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:h,style:u}],!1)}else{const h=s.findNodeByCharIndex(c),p=s.findNodeByCharIndex(d),C=r.document.getOffsetConfig(),v=this._getTopOrBottomPosition(s,i===n.Direction.UP?h:p,i===n.Direction.DOWN);if(v==null){let M;m?M=i===n.Direction.UP?0:S-2:M=i===n.Direction.UP?c:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:M,endOffset:M,style:u}],!1);return}const T=new O.NodePositionConvertToCursor(C,s).getRangePointData(v,v).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 c of s.glyphGroup){const{left:d}=c,u=r+d,m=Math.abs(t-u);m<a.distance&&(a.glyph=c,a.distance=m)}}if(a.glyph!=null)return i.findPositionByGlyph(a.glyph)}_getNextOrPrevLine(i,e){var I,h,p,C,v,T,M,_,x,D,E,b;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 c;if(e===!0?c=s.lines[r+1]:c=s.lines[r-1],c!=null)return c;const d=s.parent;if(d==null)return;const u=d.columns.indexOf(s);if(u===-1)return;if(e===!0)c=(I=d.columns[u+1])==null?void 0:I.lines[0];else{const R=(p=(h=d.columns)==null?void 0:h[u-1])==null?void 0:p.lines;c=R==null?void 0:R[R.length-1]}if(c!=null)return c;const m=d.parent;if(m==null)return;const S=m.sections.indexOf(d);if(S===-1)return;if(e===!0)c=(v=(C=m.sections[S-1])==null?void 0:C.columns[0])==null?void 0:v.lines[0];else{const R=(M=(T=m.sections)==null?void 0:T[S-1])==null?void 0:M.columns,A=R==null?void 0:R[R.length-1],U=A==null?void 0:A.lines;c=U==null?void 0:U[U.length-1]}if(c!=null)return c;const g=m.parent;if(g==null)return;const f=g.pages.indexOf(m);if(f!==-1){if(e===!0)c=(D=(x=(_=g.pages[f+1])==null?void 0:_.sections[0])==null?void 0:x.columns[0])==null?void 0:D.lines[0];else{const R=(E=g.pages[f-1])==null?void 0:E.sections;if(R==null)return;const A=(b=R[R.length-1])==null?void 0:b.columns,U=A[A.length-1],k=U==null?void 0:U.lines;c=k[k.length-1]}if(c!=null)return c}}_getDocObject(){return Ee(this._univerInstanceService,this._renderManagerService)}};me=$t([n.OnLifecycle(n.LifecycleStages.Rendered,me),Z(0,L.Inject(l.DocSkeletonManagerService)),Z(1,n.IUniverInstanceService),Z(2,O.IRenderManagerService),Z(3,L.Inject(l.TextSelectionManagerService)),Z(4,n.ICommandService)],me);var kt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,jt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Vt(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},K=(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._init()}dispose(){var i;super.dispose(),(i=this._onInputSubscription)==null||i.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var I;if(i==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.getUnitId(),{event:a,content:s="",activeRange:r}=i,c=a,d=(I=this._docSkeletonManagerService.getCurrent())==null?void 0:I.skeleton;if(c.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:m,style:S}=r,g=s.length,f=[{startOffset:u+g,endOffset:u+g,style:S}];await this._commandService.executeCommand(H.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:m})})}};ge=jt([n.OnLifecycle(n.LifecycleStages.Rendered,ge),K(0,L.Inject(l.DocSkeletonManagerService)),K(1,n.IUniverInstanceService),K(2,O.IRenderManagerService),K(3,O.ITextSelectionRenderManager),K(4,n.ICommandService)],ge);var zt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Ht=(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&&zt(i,e,a),a},Jt=(o,i)=>(e,t)=>i(e,t,o);const Yt="docs";l.UniverDocsPlugin=(Se=class extends n.Plugin{constructor(i={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[le,de,be,Pe,Q,ee,te,ne,j,ie,ae,oe,se,ce,re,Te,Ue,H,J,ve,Me,_e,N,tt,nt,at,Y,fe,ot,We,Ye,ye,Ke,qe,Qe,z,et].forEach(i=>{this._injector.get(n.ICommandService).registerCommand(i)})}_initializeDependencies(i){[[l.DocSkeletonManagerService],[l.DocViewModelManagerService],[l.DocStateChangeManagerService],[G],[O.ITextSelectionRenderManager,{useClass:O.TextSelectionRenderManager}],[l.TextSelectionManagerService],[ge],[ue],[me]].forEach(e=>i.add(e))}},y(Se,"pluginName",Yt),y(Se,"type",n.UniverInstanceType.UNIVER_DOC),Se),l.UniverDocsPlugin=Ht([Jt(1,L.Inject(L.Injector))],l.UniverDocsPlugin),l.AlignCenterCommand=qe,l.AlignJustifyCommand=et,l.AlignLeftCommand=Ke,l.AlignOperationCommand=z,l.AlignRightCommand=Qe,l.BreakLineCommand=Ue,l.BulletListCommand=Ye,l.CoverContentCommand=nt,l.CutContentCommand=Ce,l.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=ct,l.DOCS_COMPONENT_DEFAULT_Z_INDEX=ut,l.DOCS_COMPONENT_HEADER_LAYER_INDEX=dt,l.DOCS_COMPONENT_MAIN_LAYER_INDEX=lt,l.DOCS_VIEW_KEY=q,l.DeleteCommand=J,l.DeleteLeftCommand=be,l.DeleteRightCommand=Pe,l.IMEInputCommand=Me,l.IMEInputManagerService=G,l.InnerPasteCommand=Et,l.InsertCommand=H,l.MoveCursorOperation=le,l.MoveSelectionOperation=de,l.NORMAL_TEXT_SELECTION_PLUGIN_NAME=mt,l.OrderListCommand=We,l.ReplaceContentCommand=tt,l.ResetInlineFormatTextBackgroundColorCommand=ce,l.RichTextEditingMutation=N,l.SelectAllOperation=ot,l.SetDocZoomRatioCommand=at,l.SetDocZoomRatioOperation=Y,l.SetInlineFormatBoldCommand=Q,l.SetInlineFormatCommand=Te,l.SetInlineFormatFontFamilyCommand=oe,l.SetInlineFormatFontSizeCommand=ae,l.SetInlineFormatItalicCommand=ee,l.SetInlineFormatStrikethroughCommand=ne,l.SetInlineFormatSubscriptCommand=j,l.SetInlineFormatSuperscriptCommand=ie,l.SetInlineFormatTextBackgroundColorCommand=re,l.SetInlineFormatTextColorCommand=se,l.SetInlineFormatUnderlineCommand=te,l.SetTextSelectionsOperation=fe,l.UpdateCommand=ve,l.VIEWPORT_KEY=xe,l.getDocObject=Ee,l.getDocObjectById=gt,l.serializeTextRange=$,Object.defineProperty(l,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,B){"use strict";var Kt=Object.defineProperty;var Qt=(c,n,O)=>n in c?Kt(c,n,{enumerable:!0,configurable:!0,writable:!0,value:O}):c[n]=O;var y=(c,n,O)=>(Qt(c,typeof n!="symbol"?n+"":n,O),O);var Se;var K=(o=>(o.MAIN="__Document_Render_Main__",o.BACKGROUND="__Document_Render_Background__",o))(K||{}),De=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(De||{});const lt=0,dt=2,ut=4,mt=10,gt="normalTextSelectionPluginName";function Ee(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(K.BACKGROUND);return{document:u,docBackground:m,scene:r,engine:l}}function St(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(K.BACKGROUND);return{document:l,docBackground:d,scene:a,engine:s}}const fe={id:"doc.operation.set-selections",type:n.CommandType.OPERATION,handler:(o,i)=>!0};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},Ae=(o,i)=>(e,t)=>i(e,t,o);function $(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}getActiveTextRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:t}=e;return t.find(a=>a.isActive())}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:S,direction:g}=r;return l==null||d==null?null:{startOffset:l,endOffset:d,collapsed:u,startNodePosition:m,endNodePosition:S,direction:g,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(fe.id,{unitId:a,subUnitId:s,segmentId:r,style:l,isEditing:u,ranges:d.map($)})}_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($))}_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=pt([Ae(0,O.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 vt=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Ct=(o,i,e,t)=>{for(var a=t>1?void 0:t?It(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},_t=(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=Ct([_t(0,n.IUniverInstanceService)],c.DocViewModelManagerService);var Mt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Tt(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},pe=(o,i)=>(e,t)=>i(e,t,o);const Ot=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===J.id?(this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._pushHistory(a)},Ot)):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((S,g)=>n.JSONX.compose(S,g.redoState.actions),null),textRanges:d.redoState.textRanges},m={unitId:e,actions:a.reverse().reduce((S,g)=>n.JSONX.compose(S,g.undoState.actions),null),textRanges:l.undoState.textRanges};t.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:m}],redoMutations:[{id:r,params:u}]}),a.length=0}},c.DocStateChangeManagerService=yt([pe(0,B.Inject(n.IUndoRedoService)),pe(1,n.ICommandService),pe(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.JSONX.compose(a,s.actions),null),textRanges:[]};return{redoMutationParams:{unitId:i,actions:this._redoMutationParamsCache.reduce((a,s)=>n.JSONX.compose(a,s.actions),null),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 b;const{unitId:e,segmentId:t="",actions:a,textRanges:s,prevTextRanges:r,trigger:l,noHistory:d,isCompositionEnd:u,noNeedSetTextRange:m}=i,g=o.get(n.IUniverInstanceService).getUniverDocInstance(e),I=o.get(c.DocViewModelManagerService).getViewModel(e),h=o.get(c.TextSelectionManagerService),C=((b=h.getSelections())!=null?b:[]).map($),v=o.get(c.DocStateChangeManagerService),T=o.get(G);if(g==null||I==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const M=!!g.getSnapshot().disabled;if(n.JSONX.isNoop(a)||a&&a.length===0||M)return{unitId:e,actions:[],textRanges:C};const _=n.JSONX.invertWithDoc(a,g.getSnapshot());g.apply(a);const D=g.getSelfOrHeaderFooterModel(t);I.getSelfOrHeaderFooterViewModel(t).reset(D),!m&&s&&l!=null&&queueMicrotask(()=>{h.replaceTextRanges(s)});const E={commandId:Ne,unitId:e,segmentId:t,trigger:l,noHistory:d,redoState:{actions:a,textRanges:s},undoState:{actions:_,textRanges:r!=null?r:C}};if(u){const R=T.fetchComposedUndoRedoMutationParams();if(R==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:A,redoMutationParams:U,previousActiveRange:k}=R;E.redoState.actions=U.actions,E.undoState.actions=A.actions,E.undoState.textRanges=[k]}return v.setChangeState(E),{unitId:e,actions:_,textRanges:C}}},Ue="doc.command.insert-text",H={id:Ue,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}},S=new n.TextX,g=n.JSONX.getInstance();return u?d>0&&S.push({t:n.TextXActionType.RETAIN,len:d,segmentId:a}):S.push(...he(t,a)),S.push({t:n.TextXActionType.INSERT,body:s,len:s.dataStream.length,line:0,segmentId:a}),m.params.actions=g.editOp(S.serialize()),!!e.syncExecuteCommand(m.id,m.params)}};var F=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(F||{});const J={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}},S=new n.TextX,g=n.JSONX.getInstance();return u>0&&S.push({t:n.TextXActionType.RETAIN,len:r===0?u-d:u,segmentId:a}),S.push({t:n.TextXActionType.DELETE,len:d,line:0,segmentId:a}),m.params.actions=g.editOp(S.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,S=n.JSONX.getInstance(),{startOffset:g,endOffset:f}=e;return m.push({t:n.TextXActionType.RETAIN,len:g,segmentId:t}),m.push({t:n.TextXActionType.RETAIN,body:a,len:f-g,segmentId:t,coverType:s}),u.params.actions=S.editOp(m.serialize()),!!d.syncExecuteCommand(u.id,u.params)}};function Rt(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 be={id:"doc.command.break-line",type:n.CommandType.COMMAND,handler:async o=>{var I,h;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}],g=((h=(I=s.getBody())==null?void 0:I.paragraphs)!=null?h:[]).find(p=>p.startIndex>=l);return await t.executeCommand(H.id,{unitId:r,body:{dataStream:n.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Rt(n.DataStreamTreeTokenType.PARAGRAPH,g)},range:a,textRanges:m,segmentId:d})}};var xt=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Et=(o,i,e,t)=>{for(var a=t>1?void 0:t?Dt(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&&xt(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}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=Et([Ie(0,B.Inject(n.LocaleService)),Ie(1,B.Inject(c.DocViewModelManagerService)),Ie(2,n.IUniverInstanceService)],c.DocSkeletonManagerService);const At={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(),S={id:N.id,params:{unitId:m,actions:[],textRanges:a}},g=new n.MemoryCursor;g.reset();const f=new n.TextX,I=n.JSONX.getInstance();for(const p of d){const{startOffset:C,endOffset:v,collapsed:T}=p,M=C-g.cursor;T?f.push({t:n.TextXActionType.RETAIN,len:M,segmentId:e}):f.push(...he(p,e,g.cursor)),f.push({t:n.TextXActionType.INSERT,body:t,len:t.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(v)}return S.params.actions=I.editOp(f.serialize()),!!s.syncExecuteCommand(S.id,S.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.getSnapshot(),e);if(m==null)return!1;const S={id:N.id,params:{unitId:d,actions:[],textRanges:t}},g=new n.MemoryCursor;g.reset();const f=new n.TextX,I=n.JSONX.getInstance();for(const C of l){const{startOffset:v,endOffset:T,collapsed:M}=C,_=v-g.cursor;M?f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}):f.push(...Nt(C,m,e,g.cursor)),g.reset(),g.moveCursor(T)}return S.params.actions=I.editOp(f.serialize()),!!a.syncExecuteCommand(S.id,S.params)}};function Nt(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(S=>S.startIndex-t>=d&&S.startIndex-t<=u);if(d>0&&r.push({t:n.TextXActionType.RETAIN,len:d,segmentId:e}),m&&m.startIndex-t>d){const S=m.startIndex-t;r.push({t:n.TextXActionType.DELETE,len:S-d,line:0,segmentId:e}),r.push({t:n.TextXActionType.RETAIN,len:1,segmentId:e}),u>S+1&&r.push({t:n.TextXActionType.DELETE,len:u-S-1,line:0,segmentId:e})}else r.push({t:n.TextXActionType.DELETE,len:u-d,line:0,segmentId:e});return r}const Pe={id:"doc.command.delete-left",type:n.CommandType.COMMAND,handler:async o=>{var M;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=(M=e.getCurrent())==null?void 0:M.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:S,segmentId:g,style:f}=s,I=l.findNodeByCharIndex(m),h=O.hasListGlyph(I),p=O.isIndentByGlyph(I,u.getBody());let C=m;const v=l.findNodeByCharIndex(m-1);if(O.isFirstGlyph(I)&&v!==I&&(h===!0||p===!0)&&S){const _=O.getParagraphByGlyph(I,u.getBody());if(_==null)return!1;const D=_==null?void 0:_.startIndex,x={startIndex:0},E=_.paragraphStyle;if(h===!0){const R=_.paragraphStyle;if(R){x.paragraphStyle=R;const{hanging:A}=R;A&&(x.paragraphStyle.indentStart=A,x.paragraphStyle.hanging=void 0)}}else if(p===!0){const R=_.bullet;R&&(x.bullet=R),E!=null&&(x.paragraphStyle={...E},delete x.paragraphStyle.hanging,delete x.paragraphStyle.indentStart)}const b=[{startOffset:C,endOffset:C,style:f}];d=await a.executeCommand(ve.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...x}]},range:{startOffset:D,endOffset:D+1},textRanges:b,coverType:n.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(S===!0){if(v==null)return!0;if(v.content==="\r")d=await a.executeCommand(_e.id,{direction:F.LEFT,range:s});else{C-=v.count;const _=[{startOffset:C,endOffset:C,style:f}];d=await a.executeCommand(J.id,{unitId:u.getUnitId(),range:s,segmentId:g,direction:F.LEFT,len:v.count,textRanges:_})}}else{const _=Be(s,r);d=await a.executeCommand(Ce.id,{segmentId:g,textRanges:_})}return d}},we={id:"doc.command.delete-right",type:n.CommandType.COMMAND,handler:async o=>{var I;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=(I=e.getCurrent())==null?void 0:I.skeleton;let d;if(s==null||l==null||r==null)return!1;const u=t.getCurrentUniverDocInstance();if(!u)return!1;const{startOffset:m,collapsed:S,segmentId:g,style:f}=s;if(m===u.getBody().dataStream.length-2&&S)return!0;if(S===!0){const h=l.findNodeByCharIndex(m);if(h.content==="\r")d=await a.executeCommand(_e.id,{direction:F.RIGHT,range:s});else{const p=[{startOffset:m,endOffset:m,style:f}];d=await a.executeCommand(J.id,{unitId:u.getUnitId(),range:s,segmentId:g,direction:F.RIGHT,textRanges:p,len:h.count})}}else{const h=Be(s,r);d=await a.executeCommand(Ce.id,{segmentId:g,textRanges:h})}return d}},_e={id:"doc.command.merge-two-paragraph",type:n.CommandType.COMMAND,handler:async(o,i)=>{var E,b,R;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:S,segmentId:g,style:f}=l;if(!S)return!1;const I=s===F.LEFT?m:m+1,h=(R=(b=(E=u.getBody())==null?void 0:E.paragraphs)==null?void 0:b.find(A=>A.startIndex>=I))==null?void 0:R.startIndex,p=Ut(u.getBody(),I,h),C=s===F.LEFT?m-1:m,v=u.getUnitId(),T=[{startOffset:C,endOffset:C,style:f}],M={id:N.id,params:{unitId:v,actions:[],textRanges:T,prevTextRanges:[r]}},_=new n.TextX,D=n.JSONX.getInstance();return _.push({t:n.TextXActionType.RETAIN,len:s===F.LEFT?m-1:m,segmentId:g}),p.dataStream.length&&_.push({t:n.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:g}),_.push({t:n.TextXActionType.RETAIN,len:1,segmentId:g}),_.push({t:n.TextXActionType.DELETE,len:h+1-I,line:0,segmentId:g}),M.params.actions=D.editOp(_.serialize()),!!a.syncExecuteCommand(M.id,M.params)}};function Ut(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 Be(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(G),u=d.getActiveRange();if(u==null)return!1;const{startOffset:m,style:S,segmentId:g}=u,f=t.length,I=[{startOffset:m+f,endOffset:m+f,collapsed:!0,style:S}],h={id:N.id,params:{unitId:e,actions:[],textRanges:I}},p=new n.TextX,C=n.JSONX.getInstance();!u.collapsed&&r?p.push(...he(u,g)):p.push({t:n.TextXActionType.RETAIN,len:m,segmentId:g}),a>0&&p.push({t:n.TextXActionType.DELETE,len:a,line:0,segmentId:g}),p.push({t:n.TextXActionType.INSERT,body:{dataStream:t},len:t.length,line:0,segmentId:g}),h.params.actions=C.editOp(p.serialize()),h.params.noHistory=!s,h.params.isCompositionEnd=s;const v=l.syncExecuteCommand(h.id,h.params);return d.pushUndoRedoMutationParams(v,h.params),!!v}};function P(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",Q={id:Le,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(Le,i,t,e)}},Fe="doc.command.set-inline-format-italic",ee={id:Fe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(Fe,i,t,e)}},Xe="doc.command.set-inline-format-underline",te={id:Xe,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(Xe,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 P($e,i,t,e)}},ke="doc.command.set-inline-format-subscript",j={id:ke,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(ke,i,t,e)}},Ve="doc.command.set-inline-format-superscript",ie={id:Ve,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(Ve,i,t,e)}},je="doc.command.set-inline-format-fontsize",ae={id:je,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(je,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 P(ze,i,t,e)}},Ge="doc.command.set-inline-format-text-color",se={id:Ge,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(Ge,i,t,e)}},He="doc.command.set-inline-format-text-background-color",re={id:He,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(He,i,t,e)}},Je="doc.command.reset-inline-format-text-background-color",ce={id:Je,type:n.CommandType.COMMAND,handler:async(o,i)=>{const e=o.get(n.ICommandService),t=o.get(c.TextSelectionManagerService);return P(Je,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",[j.id]:"va",[ie.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;const u=l.getCurrentUniverDocInstance();if(!u)return!1;const m=u.getUnitId();let S;switch(a){case Q.id:case ee.id:case te.id:case ne.id:case j.id:case ie.id:{S=Pt(u.getBody().textRuns,a,d);break}case ae.id:case oe.id:{S=t;break}case se.id:case re.id:{S={rgb:t};break}case ce.id:{S={rgb:null};break}default:throw new Error(`Unknown command: ${a} in handleInlineFormat`)}const g={id:N.id,params:{unitId:m,actions:[],textRanges:d.map($)}},f=new n.TextX,I=n.JSONX.getInstance(),h=new n.MemoryCursor;h.reset();for(const C of d){const{startOffset:v,endOffset:T}=C,M={dataStream:"",textRuns:[{st:0,ed:T-v,ts:{[Ye[a]]:S}}]},_=v-h.cursor;_!==0&&f.push({t:n.TextXActionType.RETAIN,len:_,segmentId:e}),f.push({t:n.TextXActionType.RETAIN,body:M,len:T-v,segmentId:e}),h.reset(),h.moveCursor(T)}return g.params.actions=I.editOp(f.serialize()),!!s.syncExecuteCommand(g.id,g.params)}};function bt(o){return o!==null&&typeof o=="object"}function Pt(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 bt(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===j.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===j.id?n.BaselineOffset.SUBSCRIPT:n.BaselineOffset.SUPERSCRIPT}const ye={id:"doc.command.list-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var A,U,k,rt;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=(A=e.getSelections())!=null?A:[],u=(U=r.getBody())==null?void 0:U.paragraphs,m=d.map($);if(l==null||u==null)return!1;const S=qe(l,u),{segmentId:g}=l,f=r.getUnitId(),I=S.every(V=>{var L;return((L=V.bullet)==null?void 0:L.listType)===s});let p=n.Tools.generateRandomId(6);if(S.length===1){const V=u.indexOf(S[0]),L=u[V-1],X=u[V+1];L&&L.bullet&&L.bullet.listType===s?p=L.bullet.listId:X&&X.bullet&&X.bullet.listType===s&&(p=X.bullet.listId)}const C={id:N.id,params:{unitId:f,actions:[],textRanges:m}},v=new n.MemoryCursor;v.reset();const T=new n.TextX,M=n.JSONX.getInstance(),_=(k=r.getSnapshot().lists)!=null?k:{},D={...n.PRESET_LIST_TYPE,..._},{charSpace:x,defaultTabStop:E=36,gridType:b}=r.getSnapshot().documentStyle;for(const V of S){const{startIndex:L,paragraphStyle:X={}}=V,{indentFirstLine:Zt=0,snapToGrid:qt,indentStart:Oe=0}=X,{hanging:Re,indentStart:ct}=D[s].nestingLevel[0],xe=O.getCharSpaceApply(x,E,b,qt);T.push({t:n.TextXActionType.RETAIN,len:L-v.cursor,segmentId:g}),T.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[I?{paragraphStyle:{...X,hanging:void 0,indentStart:Oe?Math.max(0,O.getNumberUnitValue(Oe,xe)+Re-ct):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...X,indentFirstLine:void 0,hanging:Re,indentStart:ct-Re+O.getNumberUnitValue(Zt,xe)+O.getNumberUnitValue(Oe,xe)},bullet:{...(rt=V.bullet)!=null?rt:{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:p}}]},segmentId:g,coverType:n.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(L+1)}return C.params.actions=M.editOp(T.serialize()),!!a.syncExecuteCommand(C.id,C.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 z={id:"doc.command.align-operation",type:n.CommandType.COMMAND,handler:(o,i)=>{var M,_;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=(M=e.getSelections())!=null?M:[],u=(_=r.getBody())==null?void 0:_.paragraphs,m=d.map($);if(l==null||u==null)return!1;const S=qe(l,u),{segmentId:g}=l,f=r.getUnitId(),I=S.every(D=>{var x;return((x=D.paragraphStyle)==null?void 0:x.horizontalAlign)===s}),h={id:N.id,params:{unitId:f,actions:[],textRanges:m}},p=new n.MemoryCursor;p.reset();const C=new n.TextX,v=n.JSONX.getInstance();for(const D of S){const{startIndex:x}=D;C.push({t:n.TextXActionType.RETAIN,len:x-p.cursor,segmentId:g});const E={...D.paragraphStyle,horizontalAlign:I?n.HorizontalAlign.UNSPECIFIED:s};C.push({t:n.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...D,paragraphStyle:E,startIndex:0}]},segmentId:g,coverType:n.UpdateDocsAttributeType.REPLACE}),p.moveCursorTo(x+1)}return h.params.actions=v.editOp(C.serialize()),!!a.syncExecuteCommand(h.id,h.params)}},Ke={id:"doc.command.align-left",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.LEFT})},Qe={id:"doc.command.align-center",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.CENTER})},et={id:"doc.command.align-right",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.RIGHT})},tt={id:"doc.command.align-justify",type:n.CommandType.COMMAND,handler:o=>o.get(n.ICommandService).syncExecuteCommand(z.id,{alignType:n.HorizontalAlign.JUSTIFIED})},nt={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 S=at(e,s,u,t);return S.params.textRanges=a,!!l.syncExecuteCommand(S.id,S.params)}},it={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=at(e,a,d,t);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,r.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function at(o,i,e,t){const a={id:N.id,params:{unitId:o,actions:[],textRanges:[]}},s=new n.TextX,r=n.JSONX.getInstance(),l=(e==null?void 0:e.dataStream.length)-2;return l>0&&s.push({t:n.TextXActionType.DELETE,len:l,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=r.editOp(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},wt=(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}},Y={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}},ot={type:n.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,i)=>{var S,g,f;const e=o.get(n.ICommandService),t=o.get(n.IUndoRedoService),a=o.get(n.IUniverInstanceService);let s=(S=a.getCurrentUniverDocInstance())==null?void 0:S.getUnitId();if(!s)return!1;let r=1;if(i&&(s=(g=i.documentId)!=null?g:s,r=(f=i.zoomRatio)!=null?f:r),!a.getUniverDocInstance(s))return!1;const d={zoomRatio:r,unitId:s},u=wt(o,d);return e.syncExecuteCommand(Y.id,d)?(t.pushUndoRedo({unitID:s,undoMutations:[{id:Y.id,params:u}],redoMutations:[{id:Y.id,params:d}]}),!0):!1}},st={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,Lt=Object.getOwnPropertyDescriptor,Ft=(o,i,e,t)=>{for(var a=t>1?void 0:t?Lt(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},W=(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(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)}};ue=Ft([n.OnLifecycle(n.LifecycleStages.Rendered,ue),W(0,B.Inject(c.DocSkeletonManagerService)),W(1,n.IUniverInstanceService),W(2,O.ITextSelectionRenderManager),W(3,B.Inject(G)),W(4,n.ICommandService)],ue);var Xt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,kt=(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&&Xt(i,e,a),a},Z=(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._commandExecutedListener()}dispose(){var i;super.dispose(),(i=this._onInputSubscription)==null||i.unsubscribe()}_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 h,p,C;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return;const s=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton,r=this._getDocObject();if(e==null||s==null||r==null)return;const{startOffset:l,endOffset:d,style:u,collapsed:m,direction:S}=e;if(t.length>1){let v=Number.POSITIVE_INFINITY,T=Number.NEGATIVE_INFINITY;for(const M of t)v=Math.min(v,M.startOffset),T=Math.max(T,M.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:i===n.Direction.LEFT||i===n.Direction.UP?T:v,endOffset:i===n.Direction.LEFT||i===n.Direction.UP?v:T,style:u}],!1);return}const g=m||S===O.RANGE_DIRECTION.FORWARD?l:d;let f=m||S===O.RANGE_DIRECTION.FORWARD?d:l;const I=(p=a.getBody().dataStream.length)!=null?p:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){const v=s.findNodeByCharIndex(f-1),T=s.findNodeByCharIndex(f);f=i===n.Direction.RIGHT?f+T.count:f-((C=v==null?void 0:v.count)!=null?C:0),f=Math.min(I-2,Math.max(0,f)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:f,style:u}],!1)}else{const v=s.findNodeByCharIndex(f),T=r.document.getOffsetConfig(),M=this._getTopOrBottomPosition(s,v,i===n.Direction.DOWN);if(M==null){const D=i===n.Direction.UP?0:I-2;if(D===f)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:D,style:u}],!1);return}const _=new O.NodePositionConvertToCursor(T,s).getRangePointData(M,M).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:_.endOffset,style:u}],!1)}}_handleMoveCursor(i){var g,f,I;const e=this._textSelectionManagerService.getActiveRange(),t=this._textSelectionManagerService.getSelections(),a=this._univerInstanceService.getCurrentUniverDocInstance();if(!a)return!1;const s=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,r=this._getDocObject();if(e==null||s==null||r==null||t==null)return;const{startOffset:l,endOffset:d,style:u,collapsed:m}=e,S=(f=a.getBody().dataStream.length)!=null?f:Number.POSITIVE_INFINITY;if(i===n.Direction.LEFT||i===n.Direction.RIGHT){let h;if(!e.collapsed||t.length>1){let p=Number.POSITIVE_INFINITY,C=Number.NEGATIVE_INFINITY;for(const v of t)p=Math.min(p,v.startOffset),C=Math.max(C,v.endOffset);h=i===n.Direction.LEFT?p:C}else{const p=s.findNodeByCharIndex(l-1),C=s.findNodeByCharIndex(l);i===n.Direction.LEFT?h=Math.max(0,l-((I=p==null?void 0:p.count)!=null?I:0)):h=Math.min(S-2,d+C.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:h,style:u}],!1)}else{const h=s.findNodeByCharIndex(l),p=s.findNodeByCharIndex(d),C=r.document.getOffsetConfig(),v=this._getTopOrBottomPosition(s,i===n.Direction.UP?h:p,i===n.Direction.DOWN);if(v==null){let M;m?M=i===n.Direction.UP?0:S-2:M=i===n.Direction.UP?l:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:M,endOffset:M,style:u}],!1);return}const T=new O.NodePositionConvertToCursor(C,s).getRangePointData(v,v).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 I,h,p,C,v,T,M,_,D,x,E,b;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=(I=d.columns[u+1])==null?void 0:I.lines[0];else{const R=(p=(h=d.columns)==null?void 0:h[u-1])==null?void 0:p.lines;l=R==null?void 0:R[R.length-1]}if(l!=null)return l;const m=d.parent;if(m==null)return;const S=m.sections.indexOf(d);if(S===-1)return;if(e===!0)l=(v=(C=m.sections[S-1])==null?void 0:C.columns[0])==null?void 0:v.lines[0];else{const R=(M=(T=m.sections)==null?void 0:T[S-1])==null?void 0:M.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 g=m.parent;if(g==null)return;const f=g.pages.indexOf(m);if(f!==-1){if(e===!0)l=(x=(D=(_=g.pages[f+1])==null?void 0:_.sections[0])==null?void 0:D.columns[0])==null?void 0:x.lines[0];else{const R=(E=g.pages[f-1])==null?void 0:E.sections;if(R==null)return;const A=(b=R[R.length-1])==null?void 0:b.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 Ee(this._univerInstanceService,this._renderManagerService)}};me=kt([n.OnLifecycle(n.LifecycleStages.Rendered,me),Z(0,B.Inject(c.DocSkeletonManagerService)),Z(1,n.IUniverInstanceService),Z(2,O.IRenderManagerService),Z(3,B.Inject(c.TextSelectionManagerService)),Z(4,n.ICommandService)],me);var Vt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,zt=(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&&Vt(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._init()}dispose(){var i;super.dispose(),(i=this._onInputSubscription)==null||i.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async i=>{var I;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=(I=this._docSkeletonManagerService.getCurrent())==null?void 0:I.skeleton;if(l.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:m,style:S}=r,g=s.length,f=[{startOffset:u+g,endOffset:u+g,style:S}];await this._commandService.executeCommand(H.id,{unitId:t,body:{dataStream:s},range:r,textRanges:f,segmentId:m})})}};ge=zt([n.OnLifecycle(n.LifecycleStages.Rendered,ge),q(0,B.Inject(c.DocSkeletonManagerService)),q(1,n.IUniverInstanceService),q(2,O.IRenderManagerService),q(3,O.ITextSelectionRenderManager),q(4,n.ICommandService)],ge);var Gt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Jt=(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&&Gt(i,e,a),a},Yt=(o,i)=>(e,t)=>i(e,t,o);const Wt="docs";c.UniverDocsPlugin=(Se=class extends n.Plugin{constructor(i={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[le,de,Pe,we,Q,ee,te,ne,j,ie,ae,oe,se,ce,re,Te,be,H,J,ve,Me,_e,N,nt,it,ot,Y,fe,st,Ze,We,ye,Ke,Qe,et,z,tt].forEach(i=>{this._injector.get(n.ICommandService).registerCommand(i)})}_initializeDependencies(i){[[c.DocSkeletonManagerService],[c.DocViewModelManagerService],[c.DocStateChangeManagerService],[G],[O.ITextSelectionRenderManager,{useClass:O.TextSelectionRenderManager}],[c.TextSelectionManagerService],[ge],[ue],[me]].forEach(e=>i.add(e))}},y(Se,"pluginName",Wt),y(Se,"type",n.UniverInstanceType.UNIVER_DOC),Se),c.UniverDocsPlugin=Jt([Yt(1,B.Inject(B.Injector))],c.UniverDocsPlugin),c.AlignCenterCommand=Qe,c.AlignJustifyCommand=tt,c.AlignLeftCommand=Ke,c.AlignOperationCommand=z,c.AlignRightCommand=et,c.BreakLineCommand=be,c.BulletListCommand=We,c.CoverContentCommand=it,c.CutContentCommand=Ce,c.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=lt,c.DOCS_COMPONENT_DEFAULT_Z_INDEX=mt,c.DOCS_COMPONENT_HEADER_LAYER_INDEX=ut,c.DOCS_COMPONENT_MAIN_LAYER_INDEX=dt,c.DOCS_VIEW_KEY=K,c.DeleteCommand=J,c.DeleteLeftCommand=Pe,c.DeleteRightCommand=we,c.EditorInsertTextCommandId=Ue,c.IMEInputCommand=Me,c.IMEInputManagerService=G,c.InnerPasteCommand=At,c.InsertCommand=H,c.MoveCursorOperation=le,c.MoveSelectionOperation=de,c.NORMAL_TEXT_SELECTION_PLUGIN_NAME=gt,c.OrderListCommand=Ze,c.ReplaceContentCommand=nt,c.ResetInlineFormatTextBackgroundColorCommand=ce,c.RichTextEditingMutation=N,c.SelectAllOperation=st,c.SetDocZoomRatioCommand=ot,c.SetDocZoomRatioOperation=Y,c.SetInlineFormatBoldCommand=Q,c.SetInlineFormatCommand=Te,c.SetInlineFormatFontFamilyCommand=oe,c.SetInlineFormatFontSizeCommand=ae,c.SetInlineFormatItalicCommand=ee,c.SetInlineFormatStrikethroughCommand=ne,c.SetInlineFormatSubscriptCommand=j,c.SetInlineFormatSuperscriptCommand=ie,c.SetInlineFormatTextBackgroundColorCommand=re,c.SetInlineFormatTextColorCommand=se,c.SetInlineFormatUnderlineCommand=te,c.SetTextSelectionsOperation=fe,c.UpdateCommand=ve,c.VIEWPORT_KEY=De,c.getDocObject=Ee,c.getDocObjectById=St,c.serializeTextRange=$,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.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -45,31 +45,41 @@
|
|
|
45
45
|
"files": [
|
|
46
46
|
"lib"
|
|
47
47
|
],
|
|
48
|
-
"engines": {
|
|
49
|
-
"node": ">=16.0.0",
|
|
50
|
-
"npm": ">=8.0.0"
|
|
51
|
-
},
|
|
52
48
|
"peerDependencies": {
|
|
53
|
-
"@wendellhu/redi": "0.15.
|
|
49
|
+
"@wendellhu/redi": "0.15.4",
|
|
54
50
|
"rxjs": ">=7.0.0",
|
|
55
|
-
"@univerjs/core": "0.1.
|
|
56
|
-
"@univerjs/engine-render": "0.1.
|
|
51
|
+
"@univerjs/core": "0.1.15",
|
|
52
|
+
"@univerjs/engine-render": "0.1.15"
|
|
57
53
|
},
|
|
58
54
|
"devDependencies": {
|
|
59
|
-
"@wendellhu/redi": "0.15.
|
|
55
|
+
"@wendellhu/redi": "0.15.4",
|
|
60
56
|
"rxjs": "^7.8.1",
|
|
61
57
|
"typescript": "^5.4.5",
|
|
62
|
-
"vite": "^5.2.
|
|
58
|
+
"vite": "^5.2.13",
|
|
63
59
|
"vitest": "^1.6.0",
|
|
64
|
-
"@univerjs/core": "0.1.
|
|
65
|
-
"@univerjs/engine-render": "0.1.
|
|
66
|
-
"@univerjs/shared": "0.1.
|
|
60
|
+
"@univerjs/core": "0.1.15",
|
|
61
|
+
"@univerjs/engine-render": "0.1.15",
|
|
62
|
+
"@univerjs/shared": "0.1.15"
|
|
63
|
+
},
|
|
64
|
+
"univerSpace": {
|
|
65
|
+
".": {
|
|
66
|
+
"import": "./lib/es/index.js",
|
|
67
|
+
"require": "./lib/cjs/index.js",
|
|
68
|
+
"types": "./lib/types/index.d.ts"
|
|
69
|
+
},
|
|
70
|
+
"./*": {
|
|
71
|
+
"import": "./lib/es/*",
|
|
72
|
+
"require": "./lib/cjs/*",
|
|
73
|
+
"types": "./lib/types/index.d.ts"
|
|
74
|
+
},
|
|
75
|
+
"./lib/*": "./lib/*"
|
|
67
76
|
},
|
|
68
77
|
"scripts": {
|
|
69
78
|
"test": "vitest run",
|
|
70
79
|
"test:watch": "vitest",
|
|
71
80
|
"coverage": "vitest run --coverage",
|
|
72
81
|
"lint:types": "tsc --noEmit",
|
|
73
|
-
"build": "tsc && vite build"
|
|
82
|
+
"build": "tsc && vite build",
|
|
83
|
+
"sync:cnpm": "cnpm sync"
|
|
74
84
|
}
|
|
75
85
|
}
|