@univerjs/docs 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1223 -1085
- package/lib/types/commands/commands/delete.command.d.ts +7 -0
- package/lib/types/commands/commands/replace-content.command.d.ts +3 -0
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +3 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/types/services/text-selection-manager.service.d.ts +4 -2
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
|
@@ -2,6 +2,13 @@ import { ICommand } from '@univerjs/core';
|
|
|
2
2
|
import { IActiveTextRange } from '@univerjs/engine-render';
|
|
3
3
|
import { DeleteDirection } from './core-editing.command';
|
|
4
4
|
|
|
5
|
+
export interface IDeleteCustomBlockParams {
|
|
6
|
+
direction: DeleteDirection;
|
|
7
|
+
range: IActiveTextRange;
|
|
8
|
+
unitId: string;
|
|
9
|
+
drawingId: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const DeleteCustomBlockCommand: ICommand<IDeleteCustomBlockParams>;
|
|
5
12
|
interface IMergeTwoParagraphParams {
|
|
6
13
|
direction: DeleteDirection;
|
|
7
14
|
range: IActiveTextRange;
|
|
@@ -6,6 +6,9 @@ interface IReplaceContentCommandParams {
|
|
|
6
6
|
body: IDocumentBody;
|
|
7
7
|
textRanges: ITextRangeWithStyle[];
|
|
8
8
|
segmentId?: string;
|
|
9
|
+
options: {
|
|
10
|
+
[key: string]: boolean;
|
|
11
|
+
};
|
|
9
12
|
}
|
|
10
13
|
export declare const ReplaceContentCommand: ICommand<IReplaceContentCommandParams>;
|
|
11
14
|
interface ICoverContentCommandParams {
|
|
@@ -11,6 +11,9 @@ export interface IRichTextEditingMutationParams extends IMutationCommonParams {
|
|
|
11
11
|
isCompositionEnd?: boolean;
|
|
12
12
|
noHistory?: boolean;
|
|
13
13
|
debounce?: boolean;
|
|
14
|
+
options?: {
|
|
15
|
+
[key: string]: boolean;
|
|
16
|
+
};
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* The core mutator to change rich text actions. The execution result would be undo mutation params. Could be directly
|
package/lib/types/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export { DocCustomRangeService, type ICustomRangeHook } from './services/doc-cus
|
|
|
26
26
|
export { BreakLineCommand } from './commands/commands/break-line.command';
|
|
27
27
|
export { CutContentCommand, InnerPasteCommand } from './commands/commands/clipboard.inner.command';
|
|
28
28
|
export { InsertCommand, DeleteCommand, UpdateCommand, EditorInsertTextCommandId, type ICoverCommandParams, type IDeleteCommandParams, type IInsertCommandParams, type IUpdateCommandParams, } from './commands/commands/core-editing.command';
|
|
29
|
-
export { DeleteLeftCommand, DeleteRightCommand, MergeTwoParagraphCommand } from './commands/commands/delete.command';
|
|
29
|
+
export { DeleteLeftCommand, DeleteRightCommand, DeleteCustomBlockCommand, MergeTwoParagraphCommand, type IDeleteCustomBlockParams } from './commands/commands/delete.command';
|
|
30
30
|
export { IMEInputCommand, type IIMEInputCommandParams } from './commands/commands/ime-input.command';
|
|
31
31
|
export { SetInlineFormatBoldCommand, SetInlineFormatItalicCommand, SetInlineFormatUnderlineCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatFontSizeCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatTextColorCommand, SetInlineFormatTextBackgroundColorCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatCommand, } from './commands/commands/inline-format.command';
|
|
32
32
|
export { ListOperationCommand, BulletListCommand, OrderListCommand } from './commands/commands/list.command';
|
|
@@ -42,3 +42,5 @@ export { MoveCursorOperation, MoveSelectionOperation } from './commands/operatio
|
|
|
42
42
|
export { SelectAllOperation } from './commands/operations/select-all.operation';
|
|
43
43
|
export { SetDocZoomRatioOperation, type ISetDocZoomRatioOperationParams } from './commands/operations/set-doc-zoom-ratio.operation';
|
|
44
44
|
export { SetTextSelectionsOperation, type ISetTextSelectionsOperationParams, } from './commands/operations/text-selection.operation';
|
|
45
|
+
export { getRetainAndDeleteFromReplace } from './basics/retain-delete-params';
|
|
46
|
+
export { getRichTextEditPath } from './commands/util';
|
|
@@ -36,11 +36,13 @@ export declare class TextSelectionManagerService extends RxDisposable {
|
|
|
36
36
|
refreshSelection(): void;
|
|
37
37
|
setCurrentSelection(param: ITextSelectionManagerSearchParam): void;
|
|
38
38
|
setCurrentSelectionNotRefresh(param: ITextSelectionManagerSearchParam): void;
|
|
39
|
-
|
|
39
|
+
getCurrentSelections(): Readonly<Nullable<TextRange[]>>;
|
|
40
40
|
getActiveTextRange(): Nullable<TextRange>;
|
|
41
41
|
getActiveRange(): Nullable<ITextActiveRange>;
|
|
42
42
|
add(textRanges: ISuccinctTextRangeParam[], isEditing?: boolean): void;
|
|
43
|
-
replaceTextRanges(textRanges: ISuccinctTextRangeParam[], isEditing?: boolean
|
|
43
|
+
replaceTextRanges(textRanges: ISuccinctTextRangeParam[], isEditing?: boolean, options?: {
|
|
44
|
+
[key: string]: boolean;
|
|
45
|
+
}): void;
|
|
44
46
|
private _syncSelectionFromRenderService;
|
|
45
47
|
private _replaceTextRangesWithNoRefresh;
|
|
46
48
|
private _getTextRanges;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@wendellhu/redi","rxjs"],t):(m=typeof globalThis<"u"?globalThis:m||self,t(m.UniverDocs={},m.UniverCore,m.UniverEngineRender,m["@wendellhu/redi"],m.rxjs))})(this,function(m,t,E,k,G){"use strict";var Rn=Object.defineProperty;var Mn=(m,t,E)=>t in m?Rn(m,t,{enumerable:!0,configurable:!0,writable:!0,value:E}):m[t]=E;var D=(m,t,E)=>Mn(m,typeof t!="symbol"?t+"":t,E);var ye;function ee(s){return s===t.DataStreamTreeTokenType.CUSTOM_RANGE_END||s===t.DataStreamTreeTokenType.CUSTOM_RANGE_START}function Oe(s,a,e,n){return s<=e&&a>=e||s>=e&&s<=n}function Re(s,a,e,n){const i=n.slice(e.startIndex+1,e.endIndex),o=Math.max(s-(e.startIndex+1),0),r=s+a-1-(e.startIndex+1);if(r<0)return!1;if(o===0&&r>=i.length)return!0;const l=i.slice(0,o)+i.slice(o+a);for(let c=0,d=l.length;c<d;c++){const u=l[c];if(!ee(u))return!1}return!0}function V(s){const{startOffset:a,endOffset:e,collapsed:n}=s,i=Math.min(a,e),o=Math.max(a,e);return{startOffset:i,endOffset:o,collapsed:n}}function Me(s,a){let{startOffset:e,endOffset:n}=V(s);for(;a.dataStream[e-1]===t.DataStreamTreeTokenType.CUSTOM_RANGE_START;)e-=1;for(;a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_END;)n+=1;return{startOffset:e,endOffset:n}}function te(s,a){let{startOffset:e,endOffset:n,collapsed:i}=V(s);if(i){for(;ee(a.dataStream[e-1]);)n-=1,e-=1;return{startOffset:e,endOffset:n,collapsed:i}}else return{...Me(s,a),collapsed:!1}}function J(s,a){let{startOffset:e,endOffset:n,collapsed:i}=V(s);if(i){for(;a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_END;)n+=1,e+=1;for(;a.dataStream[n-1]===t.DataStreamTreeTokenType.CUSTOM_RANGE_START;)n-=1,e-=1;return{startOffset:e,endOffset:n,collapsed:i}}else return{...Me(s,a),collapsed:!1}}function Ot(s,a){if(s.startOffset===s.endOffset)return null;const e=a.customRanges;if(!e)return V(s);let{startOffset:n,endOffset:i}=Me(s,a);for(;ee(a.dataStream[n]);){if(a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_START){const o=e.find(r=>r.startIndex===n);if(!o)throw new Error("No custom-range matched");if(o.endIndex===i-1)return{startOffset:n,endOffset:i,collapsed:!1};if(o.endIndex<i-1)break}n+=1}for(;ee(a.dataStream[i-1]);){if(a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_END){const o=e.find(r=>r.endIndex===i-1);if(!o)throw new Error("No custom-range matched");if(o.startIndex===n)return{startOffset:n,endOffset:i,collapsed:!1};if(o.startIndex>n)break}i-=1}return i<=n?null:{startOffset:n,endOffset:i,collapsed:!1}}const Rt=[t.DataStreamTreeTokenType.PARAGRAPH,t.DataStreamTreeTokenType.SECTION_BREAK,t.DataStreamTreeTokenType.TABLE_START,t.DataStreamTreeTokenType.TABLE_ROW_START,t.DataStreamTreeTokenType.TABLE_CELL_START,t.DataStreamTreeTokenType.TABLE_CELL_END,t.DataStreamTreeTokenType.TABLE_ROW_END,t.DataStreamTreeTokenType.TABLE_END,t.DataStreamTreeTokenType.CUSTOM_RANGE_START,t.DataStreamTreeTokenType.CUSTOM_RANGE_END,t.DataStreamTreeTokenType.COLUMN_BREAK,t.DataStreamTreeTokenType.PAGE_BREAK,t.DataStreamTreeTokenType.DOCS_END,t.DataStreamTreeTokenType.TAB,t.DataStreamTreeTokenType.CUSTOM_BLOCK];function Mt(s,a,e){const n=s.slice(a,e);return Rt.reduce((i,o)=>i.replaceAll(o,""),n)}var W=(s=>(s.MAIN="__Document_Render_Main__",s.BACKGROUND="__Document_Render_Background__",s))(W||{}),Xe=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(Xe||{});const xt=0,Dt=2,Et=4,At=10,Nt="normalTextSelectionPluginName";function Ut(s){const{mainComponent:a,scene:e,engine:n,components:i}=s,o=a,r=i.get(W.BACKGROUND);return{document:o,docBackground:r,scene:e,engine:n}}function Le(s,a){const e=s.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!e)return null;const n=e.getUnitId(),i=a.getRenderById(n);if(i==null)return;const{mainComponent:o,scene:r,engine:l,components:c}=i,d=o,u=c.get(W.BACKGROUND);return{document:d,docBackground:u,scene:r,engine:l}}function bt(s,a){const e=a.getRenderById(s);if(e==null)return;const{mainComponent:n,scene:i,engine:o,components:r}=e,l=n,c=r.get(W.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:o}}const xe={id:"doc.operation.set-selections",type:t.CommandType.OPERATION,handler:(s,a)=>!0};var Pt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,wt=(s,a,e,n)=>{for(var i=n>1?void 0:n?Bt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Pt(a,e,i),i},Fe=(s,a)=>(e,n)=>a(e,n,s);function j(s){const{startOffset:a,endOffset:e,collapsed:n}=s,i={startOffset:a,endOffset:e,collapsed:n};return typeof s.isActive=="function"&&(i.isActive=s.isActive()),i}m.TextSelectionManagerService=class extends t.RxDisposable{constructor(e,n){super();D(this,"_currentSelection",null);D(this,"_textSelectionInfo",new Map);D(this,"_textSelection$",new G.BehaviorSubject(null));D(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=n,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:n}=e;return n.find(i=>i.isActive())}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:n,segmentId:i,style:o,segmentPage:r}=e,l=n.find(h=>h.isActive());if(l==null)return null;const{startOffset:c,endOffset:d,collapsed:u,startNodePosition:S,endNodePosition:g,direction:v}=l;return c==null||d==null?null:{startOffset:c,endOffset:d,collapsed:u,startNodePosition:S,endNodePosition:g,direction:v,segmentId:i,segmentPage:r,style:o}}add(e,n=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",segmentPage:-1,isEditing:n,style:E.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,n=!0){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,n))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(G.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const n={...this._currentSelection,...e};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:o,segmentId:r,style:l,textRanges:c,isEditing:d}=n;this._commandService.executeCommand(xe.id,{unitId:i,subUnitId:o,segmentId:r,style:l,isEditing:d,ranges:c.map(j)})}_getTextRanges(e){var o;if(e==null)return;const{unitId:n,subUnitId:i=""}=e;return(o=this._textSelectionInfo.get(n))==null?void 0:o.get(i)}_refresh(e){const n=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(j))}_replaceByParam(e){const{unitId:n,subUnitId:i,style:o,segmentId:r,textRanges:l,isEditing:c,segmentPage:d}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:l,style:o,segmentId:r,isEditing:c,segmentPage:d})}_addByParam(e){const{unitId:n,subUnitId:i,textRanges:o,style:r,segmentId:l,isEditing:c,segmentPage:d}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const u=this._textSelectionInfo.get(n);u.has(i)?u.get(i).textRanges.push(...o):u.set(i,{textRanges:o,style:r,segmentId:l,isEditing:c,segmentPage:d})}},m.TextSelectionManagerService=wt([Fe(0,E.ITextSelectionRenderManager),Fe(1,t.ICommandService)],m.TextSelectionManagerService);function De(s,a="",e,n){var T;const{startOffset:i,endOffset:o}=s,r=[],l=i-e,c=o-e,d=n.dataStream,u=(T=n.customRanges)==null?void 0:T.filter(f=>Oe(f.startIndex,f.endIndex,i,o)),S=new Set(u==null?void 0:u.filter(f=>Re(i,o-i,f,d))),g=new Set;u==null||u.forEach(f=>{S.has(f)||(f.startIndex-e>=l&&f.startIndex-e<=c&&f.endIndex-e>c&&g.add(f.startIndex),f.endIndex-e>=l&&f.endIndex-e<=c&&f.startIndex<l&&g.add(f.endIndex))}),l>0&&r.push({t:t.TextXActionType.RETAIN,len:l,segmentId:a});const v=[...g].sort((f,p)=>f-p);let h=l;return v.forEach(f=>{const p=f-h;p>0&&r.push({t:t.TextXActionType.DELETE,len:p,line:0,segmentId:a}),r.push({t:t.TextXActionType.RETAIN,len:1,segmentId:a}),h=f+1}),h<c&&(r.push({t:t.TextXActionType.DELETE,len:c-h,line:0,segmentId:a}),h=c+1),{dos:r,cursor:h,retain:g.size}}var Xt=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,Ft=(s,a,e,n)=>{for(var i=n>1?void 0:n?Lt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Xt(a,e,i),i},Ee=(s,a)=>(e,n)=>a(e,n,s);const ke=300;m.DocStateChangeManagerService=class extends t.RxDisposable{constructor(e,n,i){super();D(this,"_docStateChange$",new G.BehaviorSubject(null));D(this,"docStateChange$",this._docStateChange$.asObservable());D(this,"_historyStateCache",new Map);D(this,"_changeStateCache",new Map);D(this,"_historyTimer",null);D(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=n,this._univerInstanceService=i,this._initialize()}setChangeState(e){this._cacheChangeState(e,"history"),this._cacheChangeState(e,"collaboration")}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===t.UndoCommandId||e.id===t.RedoCommandId){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(n==null)return;const i=n.getUnitId();this._pushHistory(i),this._emitChangeState(i)}}))}_cacheChangeState(e,n="history"){const{trigger:i,unitId:o,noHistory:r,debounce:l=!1}=e;if(r||n==="history"&&(i===t.RedoCommandId||i===t.UndoCommandId))return;const c=n==="history"?this._historyStateCache:this._changeStateCache,d=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(c.has(o)){const u=c.get(o);u==null||u.push(e)}else c.set(o,[e]);l?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{d(o)},ke)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{d(o)},ke)):d(o)}_pushHistory(e){const n=this._undoRedoService,i=this._historyStateCache.get(e);if(!Array.isArray(i)||i.length===0)return;const o=i.length,r=i[0].commandId,l=i[0],c=i[o-1],d={unitId:e,actions:i.reduce((S,g)=>t.JSONX.compose(S,g.redoState.actions),null),textRanges:c.redoState.textRanges},u={unitId:e,actions:i.reverse().reduce((S,g)=>t.JSONX.compose(S,g.undoState.actions),null),textRanges:l.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:u}],redoMutations:[{id:r,params:d}]}),i.length=0}_emitChangeState(e){const n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const i=n.length,{commandId:o,trigger:r,segmentId:l,noHistory:c,debounce:d}=n[0],u=n[0],S=n[i-1],g={unitId:e,actions:n.reduce((T,f)=>t.JSONX.compose(T,f.redoState.actions),null),textRanges:S.redoState.textRanges},v={unitId:e,actions:n.reverse().reduce((T,f)=>t.JSONX.compose(T,f.undoState.actions),null),textRanges:u.undoState.textRanges},h={commandId:o,unitId:e,trigger:r,redoState:g,undoState:v,segmentId:l,noHistory:c,debounce:d};n.length=0,this._docStateChange$.next(h)}},m.DocStateChangeManagerService=Ft([Ee(0,k.Inject(t.IUndoRedoService)),Ee(1,t.ICommandService),Ee(2,t.IUniverInstanceService)],m.DocStateChangeManagerService);class Y{constructor(){D(this,"_previousActiveRange",null);D(this,"_undoMutationParamsCache",[]);D(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:a=[],redoCache:e=[]}){this._undoMutationParamsCache=a,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(a){this._previousActiveRange=a}pushUndoRedoMutationParams(a,e){this._undoMutationParamsCache.push(a),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:a}=this._undoMutationParamsCache[0],e={unitId:a,actions:this._undoMutationParamsCache.reverse().reduce((i,o)=>t.JSONX.compose(i,o.actions),null),textRanges:[]};return{redoMutationParams:{unitId:a,actions:this._redoMutationParamsCache.reduce((i,o)=>t.JSONX.compose(i,o.actions),null),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}var kt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,jt=(s,a,e,n)=>{for(var i=n>1?void 0:n?Gt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&kt(a,e,i),i},Ge=(s,a)=>(e,n)=>a(e,n,s);m.DocSkeletonManagerService=class extends t.RxDisposable{constructor(e,n,i){super();D(this,"_skeleton");D(this,"_docViewModel");D(this,"_currentSkeleton$",new G.BehaviorSubject(null));D(this,"currentSkeleton$",this._currentSkeleton$.asObservable());D(this,"_currentSkeletonBefore$",new G.BehaviorSubject(null));D(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());D(this,"_currentViewModel$",new G.BehaviorSubject(null));D(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=n,this._univerInstanceService=i,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe(G.takeUntil(this.dispose$)).subscribe(o=>{(o==null?void 0:o.getUnitId())===this._context.unitId&&this._update(o)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const n=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&n===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const i=this._skeleton;i.calculate(),this._currentSkeletonBefore$.next(i),this._currentSkeleton$.next(i),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return E.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new E.DocumentViewModel(e)}},m.DocSkeletonManagerService=jt([Ge(1,k.Inject(t.LocaleService)),Ge(2,t.IUniverInstanceService)],m.DocSkeletonManagerService);const je="doc.mutation.rich-text-editing",U={id:je,type:t.CommandType.MUTATION,handler:(s,a)=>{var R,A;const{unitId:e,segmentId:n="",actions:i,textRanges:o,prevTextRanges:r,trigger:l,noHistory:c,isCompositionEnd:d,noNeedSetTextRange:u,debounce:S}=a,g=s.get(t.IUniverInstanceService),v=s.get(E.IRenderManagerService),h=g.getUniverDocInstance(e),T=(R=v.getRenderById(e))==null?void 0:R.with(m.DocSkeletonManagerService).getViewModel();if(h==null||T==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const f=s.get(m.TextSelectionManagerService),I=((A=f.getSelections())!=null?A:[]).map(j),_=s.get(m.DocStateChangeManagerService),y=s.get(Y),x=!!h.getSnapshot().disabled;if(t.JSONX.isNoop(i)||i&&i.length===0||x)return{unitId:e,actions:[],textRanges:I};const C=t.JSONX.invertWithDoc(i,h.getSnapshot());h.apply(i),T.reset(h),!u&&o&&l!=null&&queueMicrotask(()=>{f.replaceTextRanges(o)});const M={commandId:je,unitId:e,segmentId:n,trigger:l,noHistory:c,debounce:S,redoState:{actions:i,textRanges:o},undoState:{actions:C,textRanges:r!=null?r:I}};if(d){const O=y.fetchComposedUndoRedoMutationParams();if(O==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:N,redoMutationParams:b,previousActiveRange:P}=O;M.redoState.actions=b.actions,M.undoState.actions=N.actions,M.undoState.textRanges=[P]}return _.setChangeState(M),{unitId:e,actions:C,textRanges:I}}};function $e(s,a){var n;return(n=s.get(E.IRenderManagerService).getRenderById(a))==null?void 0:n.with(m.DocSkeletonManagerService)}function B(s,a=""){if(!a)return["body"];const{headers:e,footers:n}=s.getSnapshot();if(e==null&&n==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[a])!=null)return["headers",a,"body"];if((n==null?void 0:n[a])!=null)return["footers",a,"body"];throw new Error("Segment id not found in headers or footers")}const ze="doc.command.insert-text",K={id:ze,type:t.CommandType.COMMAND,handler:async(s,a)=>{var R;const e=s.get(t.ICommandService),{range:n,segmentId:i,body:o,unitId:r,textRanges:l,cursorOffset:c}=a,d=s.get(m.TextSelectionManagerService),S=s.get(t.IUniverInstanceService).getUnit(r,t.UniverInstanceType.UNIVER_DOC);if(S==null)return!1;const g=d.getActiveRange(),v=S.getSelfOrHeaderFooterModel((R=g==null?void 0:g.segmentId)!=null?R:"").getBody();if(!v)return!1;const h=J(n,v),{startOffset:T,collapsed:f}=h,p=c!=null?c:o.dataStream.length,I=[{startOffset:T+p,endOffset:T+p,style:g==null?void 0:g.style,collapsed:f}],_={id:U.id,params:{unitId:r,actions:[],textRanges:l!=null?l:I,debounce:!0}},y=new t.TextX,x=t.JSONX.getInstance();if(f)T>0&&y.push({t:t.TextXActionType.RETAIN,len:T,segmentId:i});else{const{dos:A,retain:O}=De(h,i,0,v);y.push(...A),l||(_.params.textRanges=[{startOffset:T+p+O,endOffset:T+p+O,collapsed:f}])}y.push({t:t.TextXActionType.INSERT,body:o,len:o.dataStream.length,line:0,segmentId:i});const C=B(S,i);return _.params.actions=x.editOp(y.serialize(),C),!!e.syncExecuteCommand(_.id,_.params)}};var L=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(L||{});const ne={id:"doc.command.delete-text",type:t.CommandType.COMMAND,handler:async(s,a)=>{var A;const e=s.get(t.ICommandService),n=s.get(t.IUniverInstanceService),{range:i,segmentId:o,unitId:r,direction:l,len:c=1}=a,d=n.getUnit(r,t.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(o).getBody();if(d==null||u==null)return!1;const{startOffset:S}=i,g=u.dataStream,v=l===0?S-c:S,h=v+c-1,T=(A=u.customRanges)==null?void 0:A.filter(O=>Oe(O.startIndex,O.endIndex,v,h)),f=T==null?void 0:T.filter(O=>Re(v,c,O,g)),p=[];for(let O=0;O<c;O++)p.push(v+O);f==null||f.forEach(O=>{p.push(O.startIndex,O.endIndex)}),p.sort((O,N)=>O-N);const I=p[0],_={id:U.id,params:{unitId:r,actions:[],textRanges:[{startOffset:I,endOffset:I,collapsed:!0}],debounce:!0}},y=new t.TextX,x=t.JSONX.getInstance();let C=0;for(let O=0;O<p.length;O++){const N=p[O];N-C>0&&y.push({t:t.TextXActionType.RETAIN,len:N-C,segmentId:o}),y.push({t:t.TextXActionType.DELETE,len:1,segmentId:o,line:0}),C=N+1}const M=B(d,o);return _.params.actions=x.editOp(y.serialize(),M),!!e.syncExecuteCommand(_.id,_.params)}},Ae={id:"doc.command.update-text",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{range:e,segmentId:n,updateBody:i,coverType:o,unitId:r,textRanges:l}=a,c=s.get(t.ICommandService),u=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(u==null)return!1;const S={id:U.id,params:{unitId:r,actions:[],textRanges:l}},g=new t.TextX,v=t.JSONX.getInstance(),{startOffset:h,endOffset:T}=e;g.push({t:t.TextXActionType.RETAIN,len:h,segmentId:n}),g.push({t:t.TextXActionType.RETAIN,body:i,len:T-h,segmentId:n,coverType:o});const f=B(u,n);return S.params.actions=v.editOp(g.serialize(),f),!!c.syncExecuteCommand(S.id,S.params)}};function He(s,a){const e=[];for(let n=0,i=s.length;n<i;n++)s[n]===t.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(a)for(const n of e)a.bullet&&(n.bullet=t.Tools.deepClone(a.bullet)),a.paragraphStyle&&(n.paragraphStyle=t.Tools.deepClone(a.paragraphStyle));return e}const Ve={id:"doc.command.break-line",type:t.CommandType.COMMAND,handler:async s=>{var v,h;const a=s.get(m.TextSelectionManagerService),e=s.get(t.IUniverInstanceService),n=s.get(t.ICommandService),i=a.getActiveRange();if(i==null)return!1;const o=e.getCurrentUniverDocInstance(),r=o==null?void 0:o.getBody();if(!o||!r)return!1;const l=o.getUnitId(),{startOffset:c,endOffset:d}=J(i,r),{segmentId:u}=i,g=((h=(v=o.getSelfOrHeaderFooterModel(u).getBody())==null?void 0:v.paragraphs)!=null?h:[]).find(T=>T.startIndex>=c);if(g&&g.startIndex>d){const T=t.normalizeBody(t.getBodySlice(r,d,g.startIndex)),f={startOffset:c,endOffset:g.startIndex,collapsed:!1};return t.updateAttributeByInsert(T,{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:He(t.DataStreamTreeTokenType.PARAGRAPH,g)},1,0),await n.executeCommand(K.id,{unitId:l,body:T,range:f,segmentId:u,cursorOffset:1})}else return await n.executeCommand(K.id,{unitId:l,body:{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:He(t.DataStreamTreeTokenType.PARAGRAPH,g)},range:i,segmentId:u})}},$t={id:"doc.command.inner-paste",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{segmentId:e,textRanges:n}=a,i=a.body,o=s.get(t.ICommandService),r=s.get(m.TextSelectionManagerService),l=s.get(t.IUniverInstanceService),c=r.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const d=l.getCurrentUniverDocInstance(),u=d==null?void 0:d.getSelfOrHeaderFooterModel(e).getBody();if(d==null||u==null)return!1;const S=d.getUnitId(),g={id:U.id,params:{unitId:S,actions:[],textRanges:n}},v=new t.MemoryCursor;v.reset();const h=new t.TextX,T=t.JSONX.getInstance();for(const I of c){const{startOffset:_,endOffset:y,collapsed:x}=I,C=_-v.cursor;if(x)h.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e});else{const{dos:M}=De(I,e,v.cursor,u);h.push(...M)}h.push({t:t.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:e}),v.reset(),v.moveCursor(y)}const f=B(d,e);return g.params.actions=T.editOp(h.serialize(),f),!!o.syncExecuteCommand(g.id,g.params)}},Ne={id:"doc.command.inner-cut",type:t.CommandType.COMMAND,handler:async(s,a)=>{var p;const{segmentId:e,textRanges:n}=a,i=s.get(t.ICommandService),o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),l=o.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const c=(p=r.getCurrentUniverDocInstance())==null?void 0:p.getUnitId();if(!c)return!1;const d=r.getUniverDocInstance(c),u=t.getDocsUpdateBody(d.getSnapshot(),e);if(d==null||u==null)return!1;const S={id:U.id,params:{unitId:c,actions:[],textRanges:n}},g=new t.MemoryCursor;g.reset();const v=new t.TextX,h=t.JSONX.getInstance();for(const I of l){const{startOffset:_,endOffset:y,collapsed:x}=I,C=_-g.cursor;x?v.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e}):v.push(...zt(I,u,e,g.cursor)),g.reset(),g.moveCursor(y)}const T=B(d,e);return S.params.actions=h.editOp(v.serialize(),T),!!i.syncExecuteCommand(S.id,S.params)}};function zt(s,a,e="",n=0){var p;const{startOffset:i,endOffset:o}=te(s,a),r=[],{paragraphs:l=[],dataStream:c}=a,d=i-n,u=o-n,S=l==null?void 0:l.find(I=>I.startIndex-n>=d&&I.startIndex-n<=u),g=(p=a.customRanges)==null?void 0:p.filter(I=>Oe(I.startIndex,I.endIndex,i,o)),v=new Set(g==null?void 0:g.filter(I=>Re(i,o-i,I,c))),h=new Set;if(g==null||g.forEach(I=>{v.has(I)||(I.startIndex-n>=d&&I.startIndex-n<=u&&I.endIndex-n>u&&h.add(I.startIndex),I.endIndex-n>=d&&I.endIndex-n<=u&&I.startIndex<d&&h.add(I.endIndex))}),d>0&&r.push({t:t.TextXActionType.RETAIN,len:d,segmentId:e}),S&&S.startIndex-n>d){const I=S.startIndex-n;h.add(I)}const T=[...h].sort((I,_)=>I-_);let f=d;return T.forEach(I=>{const _=I-f;_>0&&r.push({t:t.TextXActionType.DELETE,len:_,line:0,segmentId:e}),r.push({t:t.TextXActionType.RETAIN,len:1,segmentId:e}),f=I+1}),f<u&&r.push({t:t.TextXActionType.DELETE,len:u-f,line:0,segmentId:e}),r}const ae={id:"doc.command.merge-two-paragraph",type:t.CommandType.COMMAND,handler:async(s,a)=>{var N,b;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{direction:o,range:r}=a,l=e.getActiveRange(),c=e.getSelections();if(l==null||c==null)return!1;const{segmentId:d,style:u}=l,S=n.getCurrentUniverDocInstance(),g=S==null?void 0:S.getSelfOrHeaderFooterModel(d).getBody();if(!S||!g)return!1;const v=te(l,g),{startOffset:h,collapsed:T}=v;if(!T)return!1;const f=o===L.LEFT?h:h+1,p=(b=(N=g.paragraphs)==null?void 0:N.find(P=>P.startIndex>=f))==null?void 0:b.startIndex,I=Ht(g,f,p),_=o===L.LEFT?h-1:h,y=S.getUnitId(),x=[{startOffset:_,endOffset:_,style:u}],C={id:U.id,params:{unitId:y,actions:[],textRanges:x,prevTextRanges:[r]}},M=new t.TextX,R=t.JSONX.getInstance();M.push({t:t.TextXActionType.RETAIN,len:o===L.LEFT?h-1:h,segmentId:d}),I.dataStream.length&&M.push({t:t.TextXActionType.INSERT,body:I,len:I.dataStream.length,line:0,segmentId:d}),M.push({t:t.TextXActionType.RETAIN,len:1,segmentId:d}),M.push({t:t.TextXActionType.DELETE,len:p+1-f,line:0,segmentId:d});const A=B(S,d);return C.params.actions=R.editOp(M.serialize(),A),!!i.syncExecuteCommand(C.id,C.params)}},Je={id:"doc.command.delete-left",type:t.CommandType.COMMAND,handler:async s=>{const a=s.get(m.TextSelectionManagerService),e=s.get(t.IUniverInstanceService),n=s.get(t.ICommandService);let i=!0;const o=e.getCurrentUniverDocInstance();if(!o)return!1;const r=o.getUnitId(),l=$e(s,r),c=a.getActiveRange(),d=a.getSelections(),u=l==null?void 0:l.getSkeleton();if(c==null||u==null||d==null)return!1;const{segmentId:S,style:g,segmentPage:v}=c,h=o.getSelfOrHeaderFooterModel(S).getBody();if(h==null)return!1;const T=te(c,h),{startOffset:f,collapsed:p}=T,I=u.findNodeByCharIndex(f,S,v),_=E.hasListGlyph(I),y=E.isIndentByGlyph(I,h);let x=f;const C=u.findNodeByCharIndex(f-1,S,v);if(E.isFirstGlyph(I)&&C!==I&&(_===!0||y===!0)&&p){const R=E.getParagraphByGlyph(I,h);if(R==null)return!1;const A=R==null?void 0:R.startIndex,O={startIndex:0},N=R.paragraphStyle;if(_===!0){const P=R.paragraphStyle;if(P){O.paragraphStyle=P;const{hanging:Q}=P;Q&&(O.paragraphStyle.indentStart=Q,O.paragraphStyle.hanging=void 0)}}else if(y===!0){const P=R.bullet;P&&(O.bullet=P),N!=null&&(O.paragraphStyle={...N},delete O.paragraphStyle.hanging,delete O.paragraphStyle.indentStart)}const b=[{startOffset:x,endOffset:x,style:g}];i=await n.executeCommand(Ae.id,{unitId:o.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...O}]},range:{startOffset:A,endOffset:A+1},textRanges:b,coverType:t.UpdateDocsAttributeType.REPLACE,segmentId:S})}else if(p===!0){if(C==null)return!0;C.content==="\r"?i=await n.executeCommand(ae.id,{direction:L.LEFT,range:T}):(x-=C.count,i=await n.executeCommand(ne.id,{unitId:o.getUnitId(),range:T,segmentId:S,direction:L.LEFT,len:C.count}))}else{const R=Ye({...c,...T},d);i=await n.executeCommand(Ne.id,{segmentId:S,textRanges:R})}return i}},We={id:"doc.command.delete-right",type:t.CommandType.COMMAND,handler:async s=>{const a=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(!n)return!1;const i=$e(s,n.getUnitId()),o=s.get(t.ICommandService),r=a.getActiveRange(),l=a.getSelections(),c=i==null?void 0:i.getSkeleton();if(r==null||c==null||l==null)return!1;const{segmentId:d,style:u,segmentPage:S}=r,g=n==null?void 0:n.getSelfOrHeaderFooterModel(d).getBody();if(!n||!g)return!1;const v=J(r,g),{startOffset:h,collapsed:T}=v;if(h===g.dataStream.length-2&&T)return!0;let f=!1;if(T===!0){const p=c.findNodeByCharIndex(h,d,S);if(p.content==="\r")f=await o.executeCommand(ae.id,{direction:L.RIGHT,range:r});else{const I=[{startOffset:h,endOffset:h,style:u}];f=await o.executeCommand(ne.id,{unitId:n.getUnitId(),range:{startOffset:h,endOffset:h,collapsed:T},segmentId:d,direction:L.RIGHT,textRanges:I,len:p.count})}}else{const p=Ye(r,l);f=await o.executeCommand(Ne.id,{segmentId:d,textRanges:p})}return f}};function Ht(s,a,e){const{textRuns:n}=s,i=s.dataStream.substring(a,e);if(n==null)return{dataStream:i,customRanges:t.getCustomRangeSlice(s,a,e).customRanges,customDecorations:t.getCustomDecorationSlice(s,a,e)};const o=[];for(const r of n){const{st:l,ed:c}=r;c<=a||l>=e||(l<a?o.push({...r,st:0,ed:c-a}):c>e?o.push({...r,st:l-a,ed:e-a}):o.push({...r,st:l-a,ed:c-a}))}return{dataStream:i,textRuns:o,customRanges:t.getCustomRangeSlice(s,a,e).customRanges,customDecorations:t.getCustomDecorationSlice(s,a,e)}}function Ye(s,a){let e=s.endOffset;for(const i of a){const{startOffset:o,endOffset:r}=i;o==null||r==null||r<=s.endOffset&&(e-=r-o)}return[{startOffset:e,endOffset:e,style:s.style}]}const Ue={id:"doc.command.ime-input",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:o,isCompositionStart:r}=a,l=s.get(t.ICommandService),c=s.get(Y),u=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(u==null)return!1;const S=c.getActiveRange();if(!S)return!1;const{startOffset:g,style:v,segmentId:h}=S,T=u.getSelfOrHeaderFooterModel(h).getBody();if(T==null)return!1;const f=J(S,T);Object.assign(S,f);const p=n.length,I=[{startOffset:g+p,endOffset:g+p,collapsed:!0,style:v}],_={id:U.id,params:{unitId:e,actions:[],textRanges:I}},y=new t.TextX,x=t.JSONX.getInstance();if(!S.collapsed&&r){const{dos:R,retain:A,cursor:O}=De(S,h,0,T);y.push(...R),_.params.textRanges=[{startOffset:g+p+A,endOffset:g+p+A,collapsed:!0}]}else y.push({t:t.TextXActionType.RETAIN,len:g,segmentId:h});i>0&&y.push({t:t.TextXActionType.DELETE,len:i,line:0,segmentId:h}),y.push({t:t.TextXActionType.INSERT,body:{dataStream:n},len:n.length,line:0,segmentId:h});const C=B(u,h);_.params.actions=x.editOp(y.serialize(),C),_.params.noHistory=!o,_.params.isCompositionEnd=o;const M=l.syncExecuteCommand(_.id,_.params);return c.pushUndoRedoMutationParams(M,_.params),!!M}};function w(s,a,e,n){var o;const{segmentId:i}=(o=e.getActiveRange())!=null?o:{};return i==null?!1:n.executeCommand(be.id,{segmentId:i,preCommandId:s,...a!=null?a:{}})}const Ke="doc.command.set-inline-format-bold",ie={id:Ke,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(Ke,a,n,e)}},Ze="doc.command.set-inline-format-italic",se={id:Ze,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(Ze,a,n,e)}},qe="doc.command.set-inline-format-underline",oe={id:qe,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(qe,a,n,e)}},Qe="doc.command.set-inline-format-strikethrough",re={id:Qe,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(Qe,a,n,e)}},et="doc.command.set-inline-format-subscript",z={id:et,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(et,a,n,e)}},tt="doc.command.set-inline-format-superscript",ce={id:tt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(tt,a,n,e)}},nt="doc.command.set-inline-format-fontsize",le={id:nt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(nt,a,n,e)}},at="doc.command.set-inline-format-font-family",de={id:at,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(at,a,n,e)}},it="doc.command.set-inline-format-text-color",ue={id:it,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(it,a,n,e)}},st="doc.command.set-inline-format-text-background-color",me={id:st,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(st,a,n,e)}},ot="doc.command.reset-inline-format-text-background-color",ge={id:ot,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return w(ot,a,n,e)}},rt={[ie.id]:"bl",[se.id]:"it",[oe.id]:"ul",[re.id]:"st",[le.id]:"fs",[de.id]:"ff",[ue.id]:"cl",[me.id]:"bg",[ge.id]:"bg",[z.id]:"va",[ce.id]:"va"},be={id:"doc.command.set-inline-format",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{segmentId:e,value:n,preCommandId:i}=a,o=s.get(t.ICommandService),r=s.get(m.TextSelectionManagerService),l=s.get(t.IUniverInstanceService),c=r.getSelections();if(!Array.isArray(c)||c.length===0)return!1;const d=l.getCurrentUniverDocInstance();if(d==null)return!1;const u=d.getUnitId();let S;switch(i){case ie.id:case se.id:case oe.id:case re.id:case z.id:case ce.id:{S=Jt(d.getSelfOrHeaderFooterModel(e).getBody().textRuns,i,c);break}case le.id:case de.id:{S=n;break}case ue.id:case me.id:{S={rgb:n};break}case ge.id:{S={rgb:null};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const g={id:U.id,params:{unitId:u,actions:[],textRanges:c.map(j)}},v=new t.TextX,h=t.JSONX.getInstance(),T=new t.MemoryCursor;T.reset();for(const I of c){const{startOffset:_,endOffset:y}=I,x={dataStream:"",textRuns:[{st:0,ed:y-_,ts:{[rt[i]]:S}}]},C=_-T.cursor;C!==0&&v.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e}),v.push({t:t.TextXActionType.RETAIN,body:x,len:y-_,segmentId:e}),T.reset(),T.moveCursor(y)}const f=B(d,e);return g.params.actions=h.editOp(v.serialize(),f),!!o.syncExecuteCommand(g.id,g.params)}};function Vt(s){return s!==null&&typeof s=="object"}function Jt(s,a,e){let n=0,i=0;const o=rt[a];for(;n!==s.length&&i!==e.length;){const{startOffset:r,endOffset:l}=e[i],{st:c,ed:d,ts:u}=s[n];if(l<=c)i++;else if(d<=r)n++;else{if(/bl|it/.test(o))return(u==null?void 0:u[o])===t.BooleanNumber.TRUE?t.BooleanNumber.FALSE:t.BooleanNumber.TRUE;if(/ul|st/.test(o))return Vt(u==null?void 0:u[o])&&(u==null?void 0:u[o]).s===t.BooleanNumber.TRUE?{s:t.BooleanNumber.FALSE}:{s:t.BooleanNumber.TRUE};if(/va/.test(o))return a===z.id?(u==null?void 0:u[o])===t.BaselineOffset.SUBSCRIPT?t.BaselineOffset.NORMAL:t.BaselineOffset.SUBSCRIPT:(u==null?void 0:u[o])===t.BaselineOffset.SUPERSCRIPT?t.BaselineOffset.NORMAL:t.BaselineOffset.SUPERSCRIPT;n++}}return/bl|it/.test(o)?t.BooleanNumber.TRUE:/ul|st/.test(o)?{s:t.BooleanNumber.TRUE}:a===z.id?t.BaselineOffset.SUBSCRIPT:t.BaselineOffset.SUPERSCRIPT}const Se={id:"doc.command.list-operation",type:t.CommandType.COMMAND,handler:(s,a)=>{var b,P,Q,_t;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{listType:o}=a,r=n.getCurrentUniverDocInstance(),l=e.getActiveRange();if(r==null||l==null)return!1;const{segmentId:c}=l,d=(b=e.getSelections())!=null?b:[],u=(P=r.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:P.paragraphs,S=d.map(j);if(u==null)return!1;const g=dt(l,u),v=r.getUnitId(),h=g.every($=>{var X;return((X=$.bullet)==null?void 0:X.listType)===o});let f=t.Tools.generateRandomId(6);if(g.length===1){const $=u.indexOf(g[0]),X=u[$-1],F=u[$+1];X&&X.bullet&&X.bullet.listType===o?f=X.bullet.listId:F&&F.bullet&&F.bullet.listType===o&&(f=F.bullet.listId)}const p={id:U.id,params:{unitId:v,actions:[],textRanges:S}},I=new t.MemoryCursor;I.reset();const _=new t.TextX,y=t.JSONX.getInstance(),x=(Q=r.getSnapshot().lists)!=null?Q:{},C={...t.PRESET_LIST_TYPE,...x},{charSpace:M,defaultTabStop:R=36,gridType:A}=r.getSnapshot().documentStyle;for(const $ of g){const{startIndex:X,paragraphStyle:F={}}=$,{indentFirstLine:yn=0,snapToGrid:On,indentStart:Pe=0}=F,{hanging:Be,indentStart:yt}=C[o].nestingLevel[0],we=E.getCharSpaceApply(M,R,A,On);_.push({t:t.TextXActionType.RETAIN,len:X-I.cursor,segmentId:c}),_.push({t:t.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[h?{paragraphStyle:{...F,hanging:void 0,indentStart:Pe?Math.max(0,E.getNumberUnitValue(Pe,we)+Be-yt):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...F,indentFirstLine:void 0,hanging:Be,indentStart:yt-Be+E.getNumberUnitValue(yn,we)+E.getNumberUnitValue(Pe,we)},bullet:{...(_t=$.bullet)!=null?_t:{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:f}}]},segmentId:c,coverType:t.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(X+1)}const O=B(r,c);return p.params.actions=y.editOp(_.serialize(),O),!!i.syncExecuteCommand(p.id,p.params)}},ct={id:"doc.command.bullet-list",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(Se.id,{listType:t.PresetListType.BULLET_LIST})},lt={id:"doc.command.order-list",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(Se.id,{listType:t.PresetListType.ORDER_LIST})};function dt(s,a){const{startOffset:e,endOffset:n}=s,i=[];let o=-1;for(const r of a){const{startIndex:l}=r;(e>o&&e<=l||n>o&&n<=l||l>=e&&l<=n)&&i.push(r),o=l}return i}const ut={id:"doc.command-replace-content",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,body:n,textRanges:i,segmentId:o=""}=a,r=s.get(t.IUniverInstanceService),l=s.get(t.ICommandService),c=s.get(m.TextSelectionManagerService),d=r.getUniverDocInstance(e),u=d==null?void 0:d.getSnapshot().body,S=c.getSelections();if(d==null||u==null||!Array.isArray(S)||S.length===0)return!1;const g=gt(e,o,d,u,n);return g.params.textRanges=i,!!l.syncExecuteCommand(g.id,g.params)}},mt={id:"doc.command-cover-content",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,body:n,segmentId:i=""}=a,o=s.get(t.IUniverInstanceService),r=s.get(t.ICommandService),l=s.get(t.IUndoRedoService),c=o.getUniverDocInstance(e),d=c==null?void 0:c.getSnapshot().body;if(c==null||d==null)return!1;const u=gt(e,i,c,d,n);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,r.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function gt(s,a,e,n,i){const o={id:U.id,params:{unitId:s,actions:[],textRanges:[]}},r=new t.TextX,l=t.JSONX.getInstance(),c=(n==null?void 0:n.dataStream.length)-2;c>0&&r.push({t:t.TextXActionType.DELETE,len:c,line:0,segmentId:a}),i.dataStream.length>0&&r.push({t:t.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:a});const d=B(e,a);return o.params.actions=l.editOp(r.serialize(),d),o}const Wt=(s,a)=>{const e=s.get(t.IUniverInstanceService).getUniverDocInstance(a.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...t.Tools.deepClone(a),zoomRatio:n}},Z={id:"doc.operation.set-zoom-ratio",type:t.CommandType.OPERATION,handler:(s,a)=>{const e=s.get(t.IUniverInstanceService).getUniverDocInstance(a.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:a.zoomRatio}:n.settings.zoomRatio=a.zoomRatio,!0}},St={type:t.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,a)=>{var S,g,v;const e=s.get(t.ICommandService),n=s.get(t.IUndoRedoService),i=s.get(t.IUniverInstanceService);let o=(S=i.getCurrentUniverDocInstance())==null?void 0:S.getUnitId();if(!o)return!1;let r=1;if(a&&(o=(g=a.documentId)!=null?g:o,r=(v=a.zoomRatio)!=null?v:r),!i.getUniverDocInstance(o))return!1;const c={zoomRatio:r,unitId:o},d=Wt(s,c);return e.syncExecuteCommand(Z.id,c)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:Z.id,params:d}],redoMutations:[{id:Z.id,params:c}]}),!0):!1}},fe={id:"doc.operation.move-cursor",type:t.CommandType.OPERATION,handler:(s,a)=>!!a},he={id:"doc.operation.move-selection",type:t.CommandType.OPERATION,handler:(s,a)=>!!a},ft={id:"doc.operation.select-all",type:t.CommandType.COMMAND,handler:async s=>{const a=s.get(t.IUniverInstanceService),e=s.get(m.TextSelectionManagerService),n=a.getCurrentUniverDocInstance(),i=e.getActiveRange();if(n==null||i==null)return!1;const{segmentId:o}=i,r=n.getSelfOrHeaderFooterModel(o).getSnapshot().body;if(r==null)return!1;const l=[{startOffset:0,endOffset:r.dataStream.length-2}];return e.replaceTextRanges(l,!1),!0}};var Yt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,Zt=(s,a,e,n)=>{for(var i=n>1?void 0:n?Kt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Yt(a,e,i),i},q=(s,a)=>(e,n)=>a(e,n,s);let pe=class extends t.Disposable{constructor(a,e,n,i,o){super();D(this,"_previousIMEContent","");D(this,"_isCompositionStart",!0);D(this,"_onStartSubscription");D(this,"_onUpdateSubscription");D(this,"_onEndSubscription");this._univerInstanceService=a,this._renderManagerSrv=e,this._textSelectionRenderManager=n,this._imeInputManagerService=i,this._commandService=o,this._initialize()}dispose(){var a,e,n;(a=this._onStartSubscription)==null||a.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(a=>{if(a==null)return;this._resetIME();const{activeRange:e}=a;e!=null&&this._imeInputManagerService.setActiveRange(t.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async a=>{this._updateContent(a,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(a=>{this._updateContent(a,!1)})}async _updateContent(a,e){var d;if(a==null)return;const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const i=(d=this._renderManagerSrv.getRenderById(n.getUnitId()))==null?void 0:d.with(m.DocSkeletonManagerService).getSkeleton(),{event:o,activeRange:r}=a;if(i==null||r==null)return;const c=o.data;c===this._previousIMEContent&&e||(await this._commandService.executeCommand(Ue.id,{unitId:n.getUnitId(),newText:c,oldTextLen:this._previousIMEContent.length,isCompositionStart:this._isCompositionStart,isCompositionEnd:!e}),e?(this._isCompositionStart&&(this._isCompositionStart=!1),this._previousIMEContent=c):this._resetIME())}_resetIME(){this._previousIMEContent="",this._isCompositionStart=!0,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}};pe=Zt([t.OnLifecycle(t.LifecycleStages.Rendered,pe),q(0,t.IUniverInstanceService),q(1,E.IRenderManagerService),q(2,E.ITextSelectionRenderManager),q(3,k.Inject(Y)),q(4,t.ICommandService)],pe);var qt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(s,a,e,n)=>{for(var i=n>1?void 0:n?Qt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&qt(a,e,i),i},Ie=(s,a)=>(e,n)=>a(e,n,s);let Te=class extends t.Disposable{constructor(a,e,n,i){super();D(this,"_onInputSubscription");this._univerInstanceService=a,this._renderManagerService=e,this._textSelectionManagerService=n,this._commandService=i,this._commandExecutedListener()}dispose(){var a;super.dispose(),(a=this._onInputSubscription)==null||a.unsubscribe()}_commandExecutedListener(){const a=[fe.id,he.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!a.includes(e.id))return;const n=e.params;switch(e.id){case fe.id:return this._handleMoveCursor(n.direction);case he.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(a){var _,y,x;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const o=(_=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:_.with(m.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||o==null||r==null)return;const{startOffset:l,endOffset:c,style:d,collapsed:u,direction:S,segmentId:g,startNodePosition:v,endNodePosition:h,segmentPage:T}=e;if(n.length>1){let C=Number.POSITIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(const R of n)C=Math.min(C,R.startOffset),M=Math.max(M,R.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:a===t.Direction.LEFT||a===t.Direction.UP?M:C,endOffset:a===t.Direction.LEFT||a===t.Direction.UP?C:M,style:d}],!1);return}const f=u||S===E.RANGE_DIRECTION.FORWARD?l:c;let p=u||S===E.RANGE_DIRECTION.FORWARD?c:l;const I=(y=i.getSelfOrHeaderFooterModel(g).getBody().dataStream.length)!=null?y:Number.POSITIVE_INFINITY;if(a===t.Direction.LEFT||a===t.Direction.RIGHT){const C=o.findNodeByCharIndex(p-1,g,T),M=o.findNodeByCharIndex(p,g,T);p=a===t.Direction.RIGHT?p+M.count:p-((x=C==null?void 0:C.count)!=null?x:0),p=Math.min(I-2,Math.max(0,p)),this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:p,style:d}],!1)}else{const C=o.findNodeByCharIndex(p,g,T),M=r.document.getOffsetConfig(),R=u?v:S===E.RANGE_DIRECTION.FORWARD?h:v,A=this._getTopOrBottomPosition(o,C,R,a===t.Direction.DOWN);if(A==null){const N=a===t.Direction.UP?0:I-2;if(N===p)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:N,style:d}],!1);return}const O=new E.NodePositionConvertToCursor(M,o).getRangePointData(A,A).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:O.endOffset,style:d}],!1)}}_handleMoveCursor(a){var f,p,I;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return!1;const o=(f=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:f.with(m.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||o==null||r==null||n==null)return;const{startOffset:l,endOffset:c,style:d,collapsed:u,segmentId:S,startNodePosition:g,endNodePosition:v,segmentPage:h}=e,T=(p=i.getSelfOrHeaderFooterModel(S).getBody().dataStream.length)!=null?p:Number.POSITIVE_INFINITY;if(a===t.Direction.LEFT||a===t.Direction.RIGHT){let _;if(!e.collapsed||n.length>1){let y=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY;for(const C of n)y=Math.min(y,C.startOffset),x=Math.max(x,C.endOffset);_=a===t.Direction.LEFT?y:x}else{const y=o.findNodeByCharIndex(l-1,S,h),x=o.findNodeByCharIndex(l,S,h);a===t.Direction.LEFT?_=Math.max(0,l-((I=y==null?void 0:y.count)!=null?I:0)):_=Math.min(T-2,c+x.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:d}],!1)}else{const _=o.findNodeByCharIndex(l,S,h),y=o.findNodeByCharIndex(c,S,h),x=r.document.getOffsetConfig(),C=this._getTopOrBottomPosition(o,a===t.Direction.UP?_:y,a===t.Direction.UP?g:v,a===t.Direction.DOWN);if(C==null){let R;u?R=a===t.Direction.UP?0:T-2:R=a===t.Direction.UP?l:c,this._textSelectionManagerService.replaceTextRanges([{startOffset:R,endOffset:R,style:d}],!1);return}const M=new E.NodePositionConvertToCursor(x,o).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:d}],!1)}}_getTopOrBottomPosition(a,e,n,i){if(e==null||n==null)return;const o=this._getGlyphLeftOffsetInLine(e),r=this._getNextOrPrevLine(e,i);if(r==null)return;const l=this._matchPositionByLeftOffset(a,r,o,n);if(l!=null)return{...l,isBack:!0}}_getGlyphLeftOffsetInLine(a){const e=a.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:i}=a;return n+i}_matchPositionByLeftOffset(a,e,n,i){const o={distance:Number.POSITIVE_INFINITY};for(const l of e.divides){const c=l.left;for(const d of l.glyphGroup){const{left:u}=d,S=c+u,g=Math.abs(n-S);g<o.distance&&(o.glyph=d,o.distance=g)}}if(o.glyph==null)return;const{segmentPage:r}=i;return a.findPositionByGlyph(o.glyph,r)}_getNextOrPrevLine(a,e){var h,T,f,p,I,_,y,x,C,M,R,A;const n=a.parent;if(n==null)return;const i=n.parent;if(i==null)return;const o=i.parent;if(o==null)return;const r=o.lines.indexOf(i);if(r===-1)return;let l;if(e===!0?l=o.lines[r+1]:l=o.lines[r-1],l!=null)return l;const c=o.parent;if(c==null)return;const d=c.columns.indexOf(o);if(d===-1)return;if(e===!0)l=(h=c.columns[d+1])==null?void 0:h.lines[0];else{const O=(f=(T=c.columns)==null?void 0:T[d-1])==null?void 0:f.lines;l=O==null?void 0:O[O.length-1]}if(l!=null)return l;const u=c.parent;if(u==null)return;const S=u.sections.indexOf(c);if(S===-1)return;if(e===!0)l=(I=(p=u.sections[S-1])==null?void 0:p.columns[0])==null?void 0:I.lines[0];else{const O=(y=(_=u.sections)==null?void 0:_[S-1])==null?void 0:y.columns,N=O==null?void 0:O[O.length-1],b=N==null?void 0:N.lines;l=b==null?void 0:b[b.length-1]}if(l!=null)return l;const g=u.parent;if(g==null)return;const v=g.pages.indexOf(u);if(v!==-1){if(e===!0)l=(M=(C=(x=g.pages[v+1])==null?void 0:x.sections[0])==null?void 0:C.columns[0])==null?void 0:M.lines[0];else{const O=(R=g.pages[v-1])==null?void 0:R.sections;if(O==null)return;const N=(A=O[O.length-1])==null?void 0:A.columns,b=N[N.length-1],P=b==null?void 0:b.lines;l=P[P.length-1]}if(l!=null)return l}}_getDocObject(){return Le(this._univerInstanceService,this._renderManagerService)}};Te=en([t.OnLifecycle(t.LifecycleStages.Rendered,Te),Ie(0,t.IUniverInstanceService),Ie(1,E.IRenderManagerService),Ie(2,k.Inject(m.TextSelectionManagerService)),Ie(3,t.ICommandService)],Te);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,an=(s,a,e,n)=>{for(var i=n>1?void 0:n?nn(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&tn(a,e,i),i},ve=(s,a)=>(e,n)=>a(e,n,s);let Ce=class extends t.Disposable{constructor(a,e,n,i){super();D(this,"_onInputSubscription");this._univerInstanceService=a,this._renderManagerService=e,this._textSelectionRenderManager=n,this._commandService=i,this._init()}dispose(){var a;super.dispose(),(a=this._onInputSubscription)==null||a.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async a=>{var T;if(a==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const n=e.getUnitId(),{event:i,content:o="",activeRange:r}=a,l=i,c=(T=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:T.with(m.DocSkeletonManagerService).getSkeleton();if(l.data==null||c==null||!c||!r)return;const{startOffset:d,segmentId:u,style:S,segmentPage:g}=r,v=o.length,h=[{startOffset:d+v,endOffset:d+v,segmentId:u,segmentPage:g,style:S}];await this._commandService.executeCommand(K.id,{unitId:n,body:{dataStream:o},textRanges:h,range:r,segmentId:u})})}};Ce=an([t.OnLifecycle(t.LifecycleStages.Rendered,Ce),ve(0,t.IUniverInstanceService),ve(1,E.IRenderManagerService),ve(2,E.ITextSelectionRenderManager),ve(3,t.ICommandService)],Ce);const H={id:"doc.command.align-operation",type:t.CommandType.COMMAND,handler:(s,a)=>{var x,C;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{alignType:o}=a,r=n.getCurrentUniverDocInstance(),l=e.getActiveRange();if(r==null||l==null)return!1;const{segmentId:c}=l,d=(x=e.getSelections())!=null?x:[],u=(C=r.getSelfOrHeaderFooterModel(c).getBody())==null?void 0:C.paragraphs,S=d.map(j);if(u==null)return!1;const g=dt(l,u),v=r.getUnitId(),h=g.every(M=>{var R;return((R=M.paragraphStyle)==null?void 0:R.horizontalAlign)===o}),T={id:U.id,params:{unitId:v,actions:[],textRanges:S}},f=new t.MemoryCursor;f.reset();const p=new t.TextX,I=t.JSONX.getInstance();for(const M of g){const{startIndex:R}=M;p.push({t:t.TextXActionType.RETAIN,len:R-f.cursor,segmentId:c});const A={...M.paragraphStyle,horizontalAlign:h?t.HorizontalAlign.UNSPECIFIED:o};p.push({t:t.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...M,paragraphStyle:A,startIndex:0}]},segmentId:c,coverType:t.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(R+1)}const _=B(r,c);return T.params.actions=I.editOp(p.serialize(),_),!!i.syncExecuteCommand(T.id,T.params)}},ht={id:"doc.command.align-left",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(H.id,{alignType:t.HorizontalAlign.LEFT})},pt={id:"doc.command.align-center",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(H.id,{alignType:t.HorizontalAlign.CENTER})},It={id:"doc.command.align-right",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(H.id,{alignType:t.HorizontalAlign.RIGHT})},Tt={id:"doc.command.align-justify",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(H.id,{alignType:t.HorizontalAlign.JUSTIFIED})};class vt{constructor(){D(this,"_customRangeHooks",[])}addClipboardHook(a){return this._customRangeHooks.push(a),t.toDisposable(()=>{const e=this._customRangeHooks.indexOf(a);e>-1&&this._customRangeHooks.splice(e,1)})}copyCustomRange(a){let e={...a};return this._customRangeHooks.forEach(n=>{n.onCopyCustomRange&&(e=n.onCopyCustomRange(e))}),e}}var sn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,rn=(s,a,e,n)=>{for(var i=n>1?void 0:n?on(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&sn(a,e,i),i},cn=(s,a)=>(e,n)=>a(e,n,s);const ln="docs";m.UniverDocsPlugin=(ye=class extends t.Plugin{constructor(a={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[fe,he,Je,We,ie,se,oe,re,z,ce,le,de,ue,ge,me,be,Ve,K,ne,Ae,Ue,ae,U,ut,mt,St,Z,xe,ft,lt,ct,Se,ht,pt,It,H,Tt].forEach(a=>{this._injector.get(t.ICommandService).registerCommand(a)})}_initializeDependencies(a){[[m.DocStateChangeManagerService],[Y],[E.ITextSelectionRenderManager,{useClass:E.TextSelectionRenderManager}],[m.TextSelectionManagerService],[vt],[Ce],[pe],[Te]].forEach(e=>a.add(e))}},D(ye,"pluginName",ln),D(ye,"type",t.UniverInstanceType.UNIVER_DOC),ye),m.UniverDocsPlugin=rn([cn(1,k.Inject(k.Injector))],m.UniverDocsPlugin);function dn(s,a){const{range:e,rangeId:n,rangeType:i,segmentId:o}=s,r=Ot(e,a);if(!r)return null;const{startOffset:l,endOffset:c}=r,d=new t.TextX;return l>0&&d.push({t:t.TextXActionType.RETAIN,len:l,segmentId:o}),d.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0}),d.push({t:t.TextXActionType.RETAIN,body:{dataStream:""},len:c-l,segmentId:o}),d.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:n,rangeType:i,startIndex:-(c-l)-1,endIndex:0}]},len:1,line:0}),d}function un(s,a){const e={id:U.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},n=t.JSONX.getInstance(),i=dn(s,a);return i?(e.params.actions=n.editOp(i.serialize()),e):!1}function mn(s,a){var x;const{segmentId:e,rangeId:n,rangeType:i}=a,o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),l=o.getActiveRange();if(!l)return!1;const c=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!c)return!1;const d=c.getBody(),u=c.getUnitId();if(!d)return!1;const{startOffset:S,endOffset:g}=V(l),v=(x=d.customRanges)!=null?x:[],h=[];for(let C=0,M=v.length;C<M;C++){const R=v[C];if(R.rangeType===i&&Math.max(R.startIndex,S)<=Math.min(R.endIndex,g-1)&&h.push({...R}),R.startIndex>=g)break}const T=h.map(C=>[C.startIndex,C.endIndex]).flat().sort((C,M)=>C-M);let f=0;const p=new t.TextX,I=T.length?{startOffset:Math.min(T[0],S),endOffset:Math.max(T[T.length-1]+1,g)}:l;I.startOffset!==f&&(p.push({t:t.TextXActionType.RETAIN,len:I.startOffset-f,segmentId:e}),f=I.startOffset),p.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0,segmentId:e}),T.forEach((C,M)=>{C!==f&&(p.push({t:t.TextXActionType.RETAIN,len:C-f,segmentId:e}),f=C),p.push({t:t.TextXActionType.DELETE,len:1,line:0,segmentId:e}),f++}),f!==I.endOffset&&(p.push({t:t.TextXActionType.RETAIN,len:I.endOffset-f,segmentId:e}),f=I.endOffset),p.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:n,rangeType:i,startIndex:-(I.endOffset-I.startOffset-T.length+1),endIndex:0}]},len:1,line:0,segmentId:e});const _=t.JSONX.getInstance(),y={id:U.id,params:{unitId:u,actions:[],textRanges:void 0}};return y.params.actions=_.editOp(p.serialize()),y}function gn(s,a){var g,v;const{unitId:e,rangeId:n,segmentId:i}=a,r=s.get(t.IUniverInstanceService).getUnit(e);if(!r)return!1;const l=(v=(g=r.getBody())==null?void 0:g.customRanges)==null?void 0:v.find(h=>h.rangeId===n);if(!l)return!1;const{startIndex:c,endIndex:d}=l,u=new t.TextX,S=d-c+1;return c>0&&u.push({t:t.TextXActionType.RETAIN,len:c,segmentId:i}),u.push({t:t.TextXActionType.DELETE,len:1,segmentId:i,line:0}),S-2>0&&u.push({t:t.TextXActionType.RETAIN,len:S-2,segmentId:i}),u.push({t:t.TextXActionType.DELETE,len:1,segmentId:i,line:0}),u}function Sn(s,a){const e={id:U.id,params:{unitId:a.unitId,actions:[],textRanges:void 0}},n=t.JSONX.getInstance(),i=gn(s,a);return i?(e.params.actions=n.editOp(i.serialize()),e):!1}function Ct(s){const{unitId:a,range:e,id:n,type:i,segmentId:o}=s,{startOffset:r,endOffset:l}=e,c={id:U.id,params:{unitId:a,actions:[],textRanges:void 0}},d=new t.TextX,u=t.JSONX.getInstance();return r>0&&d.push({t:t.TextXActionType.RETAIN,len:r,segmentId:o}),d.push({t:t.TextXActionType.RETAIN,body:{dataStream:"",customDecorations:[{id:n,type:i,startIndex:0,endIndex:l-r-1}]},len:l-r,segmentId:o}),c.params.actions=u.editOp(d.serialize()),c}function fn(s,a){const{segmentId:e,id:n,type:i}=a,o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),l=o.getActiveRange();if(!l)return!1;const c=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!c)return!1;const d=c.getBody(),u=c.getUnitId();return d?Ct({unitId:u,range:{startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0},id:n,type:i,segmentId:e}):!1}function hn(s,a){var T,f;const{unitId:e,id:n,segmentId:i}=a,r=s.get(t.IUniverInstanceService).getUnit(e),l=r==null?void 0:r.getBody();if(!r||!l)return!1;const c=(f=(T=r.getBody())==null?void 0:T.customDecorations)==null?void 0:f.filter(p=>p.id===n);if(!(c!=null&&c.length))return!1;const d=c.map(p=>t.getBodySlice(l,p.startIndex,p.endIndex+1)),u=d.map(p=>{var _;const I=t.Tools.deepClone(p);return I.customDecorations=(_=I.customDecorations)==null?void 0:_.filter(y=>y.id!==n),I}),S={id:U.id,params:{unitId:e,actions:[],textRanges:void 0}},g=new t.TextX,v=t.JSONX.getInstance();let h=0;return c.forEach((p,I)=>{const _=u[I],y=d[I];p.startIndex!==h&&g.push({t:t.TextXActionType.RETAIN,len:p.startIndex-h,segmentId:i}),h=p.startIndex,g.push({t:t.TextXActionType.RETAIN,len:p.endIndex-p.startIndex+1,segmentId:i,body:_,oldBody:y,coverType:t.UpdateDocsAttributeType.REPLACE}),h=h+(p.endIndex-p.startIndex+1)}),S.params.actions=v.editOp(g.serialize()),S}const pn=t.createInterceptorKey("CUSTOM_RANGE"),In=t.createInterceptorKey("CUSTOM_DECORATION"),_e={CUSTOM_RANGE:pn,CUSTOM_DECORATION:In};var Tn=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,Cn=(s,a,e,n)=>{for(var i=n>1?void 0:n?vn(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Tn(a,e,i),i},_n=(s,a)=>(e,n)=>a(e,n,s);m.DocInterceptorService=class extends t.Disposable{constructor(e,n){super();D(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=n,this.disposeWithMe(this._docSkeletonManagerService.currentViewModel$.subscribe(i=>{if(i){const o=i.getDataModel().getUnitId();if(o===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||o===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.interceptDocumentViewModel(i)}})),this.disposeWithMe(this.intercept(_e.CUSTOM_RANGE,{priority:-1,handler:(i,o,r)=>r(i)}))}intercept(e,n){const i=e;this._interceptorsByName.has(i)||this._interceptorsByName.set(i,[]);const o=this._interceptorsByName.get(i);return o.push(n),this._interceptorsByName.set(i,o.sort((r,l)=>{var c,d;return((c=l.priority)!=null?c:0)-((d=r.priority)!=null?d:0)})),this.disposeWithMe(t.toDisposable(()=>t.remove(this._interceptorsByName.get(i),n)))}fetchThroughInterceptors(e){const n=e,i=this._interceptorsByName.get(n);return t.composeInterceptors(i||[])}interceptDocumentViewModel(e){const n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:i=>{var o;return this.fetchThroughInterceptors(_e.CUSTOM_RANGE)(e.getCustomRangeRaw(i),{index:i,unitId:e.getDataModel().getUnitId(),customRanges:(o=e.getDataModel().getCustomRanges())!=null?o:[]})},getCustomDecoration:i=>{var o;return this.fetchThroughInterceptors(_e.CUSTOM_DECORATION)(e.getCustomDecorationRaw(i),{index:i,unitId:e.getDataModel().getUnitId(),customDecorations:(o=e.getDataModel().getCustomDecorations())!=null?o:[]})}})),n}},m.DocInterceptorService=Cn([t.OnLifecycle(t.LifecycleStages.Starting,m.DocInterceptorService),_n(1,k.Inject(m.DocSkeletonManagerService))],m.DocInterceptorService),m.AlignCenterCommand=pt,m.AlignJustifyCommand=Tt,m.AlignLeftCommand=ht,m.AlignOperationCommand=H,m.AlignRightCommand=It,m.BreakLineCommand=Ve,m.BulletListCommand=ct,m.CoverContentCommand=mt,m.CutContentCommand=Ne,m.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=xt,m.DOCS_COMPONENT_DEFAULT_Z_INDEX=At,m.DOCS_COMPONENT_HEADER_LAYER_INDEX=Et,m.DOCS_COMPONENT_MAIN_LAYER_INDEX=Dt,m.DOCS_VIEW_KEY=W,m.DOC_INTERCEPTOR_POINT=_e,m.DeleteCommand=ne,m.DeleteLeftCommand=Je,m.DeleteRightCommand=We,m.DocCustomRangeService=vt,m.EditorInsertTextCommandId=ze,m.IMEInputCommand=Ue,m.IMEInputManagerService=Y,m.InnerPasteCommand=$t,m.InsertCommand=K,m.ListOperationCommand=Se,m.MergeTwoParagraphCommand=ae,m.MoveCursorOperation=fe,m.MoveSelectionOperation=he,m.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Nt,m.OrderListCommand=lt,m.ReplaceContentCommand=ut,m.ResetInlineFormatTextBackgroundColorCommand=ge,m.RichTextEditingMutation=U,m.SelectAllOperation=ft,m.SetDocZoomRatioCommand=St,m.SetDocZoomRatioOperation=Z,m.SetInlineFormatBoldCommand=ie,m.SetInlineFormatCommand=be,m.SetInlineFormatFontFamilyCommand=de,m.SetInlineFormatFontSizeCommand=le,m.SetInlineFormatItalicCommand=se,m.SetInlineFormatStrikethroughCommand=re,m.SetInlineFormatSubscriptCommand=z,m.SetInlineFormatSuperscriptCommand=ce,m.SetInlineFormatTextBackgroundColorCommand=me,m.SetInlineFormatTextColorCommand=ue,m.SetInlineFormatUnderlineCommand=oe,m.SetTextSelectionsOperation=xe,m.UpdateCommand=Ae,m.VIEWPORT_KEY=Xe,m.addCustomDecorationBySelectionFactory=fn,m.addCustomDecorationFactory=Ct,m.addCustomRangeBySelectionFactory=mn,m.addCustomRangeFactory=un,m.deleteCustomDecorationFactory=hn,m.deleteCustomRangeFactory=Sn,m.getDeleteSelection=te,m.getDocObject=Le,m.getDocObjectById=bt,m.getInsertSelection=J,m.getSelectionText=Mt,m.neoGetDocObject=Ut,m.serializeTextRange=j,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(m,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@wendellhu/redi","rxjs"],t):(m=typeof globalThis<"u"?globalThis:m||self,t(m.UniverDocs={},m.UniverCore,m.UniverEngineRender,m["@wendellhu/redi"],m.rxjs))})(this,function(m,t,U,j,$){"use strict";var xn=Object.defineProperty;var Dn=(m,t,U)=>t in m?xn(m,t,{enumerable:!0,configurable:!0,writable:!0,value:U}):m[t]=U;var N=(m,t,U)=>Dn(m,typeof t!="symbol"?t+"":t,U);var Re;function te(s){return s===t.DataStreamTreeTokenType.CUSTOM_RANGE_END||s===t.DataStreamTreeTokenType.CUSTOM_RANGE_START}function xe(s,a,e,n){return s<=e&&a>=e||s>=e&&s<=n}function De(s,a,e,n){const i=n.slice(e.startIndex+1,e.endIndex),o=Math.max(s-(e.startIndex+1),0),r=s+a-1-(e.startIndex+1);if(r<0)return!1;if(o===0&&r>=i.length)return!0;const c=i.slice(0,o)+i.slice(o+a);for(let d=0,u=c.length;d<u;d++){const l=c[d];if(!te(l))return!1}return!0}function W(s){const{startOffset:a,endOffset:e,collapsed:n}=s,i=Math.min(a,e),o=Math.max(a,e);return{startOffset:i,endOffset:o,collapsed:n}}function Ee(s,a){let{startOffset:e,endOffset:n}=W(s);for(;a.dataStream[e-1]===t.DataStreamTreeTokenType.CUSTOM_RANGE_START;)e-=1;for(;a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_END;)n+=1;return{startOffset:e,endOffset:n}}function ne(s,a){let{startOffset:e,endOffset:n,collapsed:i}=W(s);if(i){for(;te(a.dataStream[e-1]);)n-=1,e-=1;return{startOffset:e,endOffset:n,collapsed:i}}else return{...Ee(s,a),collapsed:!1}}function Y(s,a){let{startOffset:e,endOffset:n,collapsed:i}=W(s);if(i){for(;a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_END;)n+=1,e+=1;for(;a.dataStream[n-1]===t.DataStreamTreeTokenType.CUSTOM_RANGE_START;)n-=1,e-=1;return{startOffset:e,endOffset:n,collapsed:i}}else return{...Ee(s,a),collapsed:!1}}function Rt(s,a){if(s.startOffset===s.endOffset)return null;const e=a.customRanges;if(!e)return W(s);let{startOffset:n,endOffset:i}=Ee(s,a);for(;te(a.dataStream[n]);){if(a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_START){const o=e.find(r=>r.startIndex===n);if(!o)throw new Error("No custom-range matched");if(o.endIndex===i-1)return{startOffset:n,endOffset:i,collapsed:!1};if(o.endIndex<i-1)break}n+=1}for(;te(a.dataStream[i-1]);){if(a.dataStream[n]===t.DataStreamTreeTokenType.CUSTOM_RANGE_END){const o=e.find(r=>r.endIndex===i-1);if(!o)throw new Error("No custom-range matched");if(o.startIndex===n)return{startOffset:n,endOffset:i,collapsed:!1};if(o.startIndex>n)break}i-=1}return i<=n?null:{startOffset:n,endOffset:i,collapsed:!1}}const Mt=[t.DataStreamTreeTokenType.PARAGRAPH,t.DataStreamTreeTokenType.SECTION_BREAK,t.DataStreamTreeTokenType.TABLE_START,t.DataStreamTreeTokenType.TABLE_ROW_START,t.DataStreamTreeTokenType.TABLE_CELL_START,t.DataStreamTreeTokenType.TABLE_CELL_END,t.DataStreamTreeTokenType.TABLE_ROW_END,t.DataStreamTreeTokenType.TABLE_END,t.DataStreamTreeTokenType.CUSTOM_RANGE_START,t.DataStreamTreeTokenType.CUSTOM_RANGE_END,t.DataStreamTreeTokenType.COLUMN_BREAK,t.DataStreamTreeTokenType.PAGE_BREAK,t.DataStreamTreeTokenType.DOCS_END,t.DataStreamTreeTokenType.TAB,t.DataStreamTreeTokenType.CUSTOM_BLOCK];function xt(s,a,e){const n=s.slice(a,e);return Mt.reduce((i,o)=>i.replaceAll(o,""),n)}var K=(s=>(s.MAIN="__Document_Render_Main__",s.BACKGROUND="__Document_Render_Background__",s))(K||{}),Fe=(s=>(s.VIEW_MAIN="viewMain",s.VIEW_TOP="viewTop",s.VIEW_LEFT="viewLeft",s.VIEW_LEFT_TOP="viewLeftTop",s))(Fe||{});const Dt=0,Et=2,At=4,Nt=10,Ut="normalTextSelectionPluginName";function bt(s){const{mainComponent:a,scene:e,engine:n,components:i}=s,o=a,r=i.get(K.BACKGROUND);return{document:o,docBackground:r,scene:e,engine:n}}function ke(s,a){const e=s.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!e)return null;const n=e.getUnitId(),i=a.getRenderById(n);if(i==null)return;const{mainComponent:o,scene:r,engine:c,components:d}=i,u=o,l=d.get(K.BACKGROUND);return{document:u,docBackground:l,scene:r,engine:c}}function Pt(s,a){const e=a.getRenderById(s);if(e==null)return;const{mainComponent:n,scene:i,engine:o,components:r}=e,c=n,d=r.get(K.BACKGROUND);return{document:c,docBackground:d,scene:i,engine:o}}const Ae={id:"doc.operation.set-selections",type:t.CommandType.OPERATION,handler:(s,a)=>!0};var wt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Xt=(s,a,e,n)=>{for(var i=n>1?void 0:n?Bt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&wt(a,e,i),i},Ge=(s,a)=>(e,n)=>a(e,n,s);function z(s){const{startOffset:a,endOffset:e,collapsed:n}=s,i={startOffset:a,endOffset:e,collapsed:n};return typeof s.isActive=="function"&&(i.isActive=s.isActive()),i}m.TextSelectionManagerService=class extends t.RxDisposable{constructor(e,n){super();N(this,"_currentSelection",null);N(this,"_textSelectionInfo",new Map);N(this,"_textSelection$",new $.BehaviorSubject(null));N(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=n,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}getCurrentSelections(){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:n}=e;return n.find(i=>i.isActive())}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:n,segmentId:i,style:o,segmentPage:r}=e,c=n.find(S=>S.isActive());if(c==null)return null;const{startOffset:d,endOffset:u,collapsed:l,startNodePosition:f,endNodePosition:g,direction:T}=c;return d==null||u==null?null:{startOffset:d,endOffset:u,collapsed:l,startNodePosition:f,endNodePosition:g,direction:T,segmentId:i,segmentPage:r,style:o}}add(e,n=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",segmentPage:-1,isEditing:n,style:U.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,n=!0,i){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e,n,i))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe($.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const n={...this._currentSelection,...e};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:o,segmentId:r,style:c,textRanges:d,isEditing:u}=n;this._commandService.executeCommand(Ae.id,{unitId:i,subUnitId:o,segmentId:r,style:c,isEditing:u,ranges:d.map(z)})}_getTextRanges(e){var o;if(e==null)return;const{unitId:n,subUnitId:i=""}=e;return(o=this._textSelectionInfo.get(n))==null?void 0:o.get(i)}_refresh(e){const n=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(z))}_replaceByParam(e){const{unitId:n,subUnitId:i,style:o,segmentId:r,textRanges:c,isEditing:d,segmentPage:u}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:c,style:o,segmentId:r,isEditing:d,segmentPage:u})}_addByParam(e){const{unitId:n,subUnitId:i,textRanges:o,style:r,segmentId:c,isEditing:d,segmentPage:u}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(i)?l.get(i).textRanges.push(...o):l.set(i,{textRanges:o,style:r,segmentId:c,isEditing:d,segmentPage:u})}},m.TextSelectionManagerService=Xt([Ge(0,U.ITextSelectionRenderManager),Ge(1,t.ICommandService)],m.TextSelectionManagerService);function ae(s,a="",e,n){var v;const{startOffset:i,endOffset:o}=s,r=[],c=i-e,d=o-e,u=n.dataStream,l=(v=n.customRanges)==null?void 0:v.filter(I=>xe(I.startIndex,I.endIndex,i,o)),f=new Set(l==null?void 0:l.filter(I=>De(i,o-i,I,u))),g=new Set;l==null||l.forEach(I=>{f.has(I)||(I.startIndex-e>=c&&I.startIndex-e<=d&&I.endIndex-e>d&&g.add(I.startIndex),I.endIndex-e>=c&&I.endIndex-e<=d&&I.startIndex<c&&g.add(I.endIndex))}),c>0&&r.push({t:t.TextXActionType.RETAIN,len:c,segmentId:a});const T=[...g].sort((I,h)=>I-h);let S=c;return T.forEach(I=>{const h=I-S;h>0&&r.push({t:t.TextXActionType.DELETE,len:h,line:0,segmentId:a}),r.push({t:t.TextXActionType.RETAIN,len:1,segmentId:a}),S=I+1}),S<d&&(r.push({t:t.TextXActionType.DELETE,len:d-S,line:0,segmentId:a}),S=d+1),{dos:r,cursor:S,retain:g.size}}var Lt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,kt=(s,a,e,n)=>{for(var i=n>1?void 0:n?Ft(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Lt(a,e,i),i},Ne=(s,a)=>(e,n)=>a(e,n,s);const je=300;m.DocStateChangeManagerService=class extends t.RxDisposable{constructor(e,n,i){super();N(this,"_docStateChange$",new $.BehaviorSubject(null));N(this,"docStateChange$",this._docStateChange$.asObservable());N(this,"_historyStateCache",new Map);N(this,"_changeStateCache",new Map);N(this,"_historyTimer",null);N(this,"_changeStateCacheTimer",null);this._undoRedoService=e,this._commandService=n,this._univerInstanceService=i,this._initialize()}setChangeState(e){this._cacheChangeState(e,"history"),this._cacheChangeState(e,"collaboration")}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===t.UndoCommandId||e.id===t.RedoCommandId){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(n==null)return;const i=n.getUnitId();this._pushHistory(i),this._emitChangeState(i)}}))}_cacheChangeState(e,n="history"){const{trigger:i,unitId:o,noHistory:r,debounce:c=!1}=e;if(r||i==null||n==="history"&&(i===t.RedoCommandId||i===t.UndoCommandId))return;const d=n==="history"?this._historyStateCache:this._changeStateCache,u=n==="history"?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(d.has(o)){const l=d.get(o);l==null||l.push(e)}else d.set(o,[e]);c?n==="history"?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{u(o)},je)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{u(o)},je)):u(o)}_pushHistory(e){const n=this._undoRedoService,i=this._historyStateCache.get(e);if(!Array.isArray(i)||i.length===0)return;const o=i.length,r=i[0].commandId,c=i[0],d=i[o-1],u={unitId:e,actions:i.reduce((f,g)=>t.JSONX.compose(f,g.redoState.actions),null),textRanges:d.redoState.textRanges},l={unitId:e,actions:i.reverse().reduce((f,g)=>t.JSONX.compose(f,g.undoState.actions),null),textRanges:c.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:r,params:l}],redoMutations:[{id:r,params:u}]}),i.length=0}_emitChangeState(e){const n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;const i=n.length,{commandId:o,trigger:r,segmentId:c,noHistory:d,debounce:u}=n[0],l=n[0],f=n[i-1],g={unitId:e,actions:n.reduce((v,I)=>t.JSONX.compose(v,I.redoState.actions),null),textRanges:f.redoState.textRanges},T={unitId:e,actions:n.reverse().reduce((v,I)=>t.JSONX.compose(v,I.undoState.actions),null),textRanges:l.undoState.textRanges},S={commandId:o,unitId:e,trigger:r,redoState:g,undoState:T,segmentId:c,noHistory:d,debounce:u};n.length=0,this._docStateChange$.next(S)}},m.DocStateChangeManagerService=kt([Ne(0,j.Inject(t.IUndoRedoService)),Ne(1,t.ICommandService),Ne(2,t.IUniverInstanceService)],m.DocStateChangeManagerService);class Z{constructor(){N(this,"_previousActiveRange",null);N(this,"_undoMutationParamsCache",[]);N(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:a=[],redoCache:e=[]}){this._undoMutationParamsCache=a,this._redoMutationParamsCache=e}getActiveRange(){return this._previousActiveRange}setActiveRange(a){this._previousActiveRange=a}pushUndoRedoMutationParams(a,e){this._undoMutationParamsCache.push(a),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:a}=this._undoMutationParamsCache[0],e={unitId:a,actions:this._undoMutationParamsCache.reverse().reduce((i,o)=>t.JSONX.compose(i,o.actions),null),textRanges:[]};return{redoMutationParams:{unitId:a,actions:this._redoMutationParamsCache.reduce((i,o)=>t.JSONX.compose(i,o.actions),null),textRanges:[]},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}var Gt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,$t=(s,a,e,n)=>{for(var i=n>1?void 0:n?jt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Gt(a,e,i),i},$e=(s,a)=>(e,n)=>a(e,n,s);m.DocSkeletonManagerService=class extends t.RxDisposable{constructor(e,n,i){super();N(this,"_skeleton");N(this,"_docViewModel");N(this,"_currentSkeleton$",new $.BehaviorSubject(null));N(this,"currentSkeleton$",this._currentSkeleton$.asObservable());N(this,"_currentSkeletonBefore$",new $.BehaviorSubject(null));N(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());N(this,"_currentViewModel$",new $.BehaviorSubject(null));N(this,"currentViewModel$",this._currentViewModel$.asObservable());this._context=e,this._localeService=n,this._univerInstanceService=i,this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe($.takeUntil(this.dispose$)).subscribe(o=>{(o==null?void 0:o.getUnitId())===this._context.unitId&&this._update(o)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){const e=this._context.unit;this._update(e)}_update(e){const n=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&n===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));const i=this._skeleton;i.calculate(),this._currentSkeletonBefore$.next(i),this._currentSkeleton$.next(i),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return U.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new U.DocumentViewModel(e)}},m.DocSkeletonManagerService=$t([$e(1,j.Inject(t.LocaleService)),$e(2,t.IUniverInstanceService)],m.DocSkeletonManagerService);const ze="doc.mutation.rich-text-editing",b={id:ze,type:t.CommandType.MUTATION,handler:(s,a)=>{var M,D;const{unitId:e,segmentId:n="",actions:i,textRanges:o,prevTextRanges:r,trigger:c,noHistory:d,isCompositionEnd:u,noNeedSetTextRange:l,debounce:f}=a,g=s.get(t.IUniverInstanceService),T=s.get(U.IRenderManagerService),S=g.getUniverDocInstance(e),v=(M=T.getRenderById(e))==null?void 0:M.with(m.DocSkeletonManagerService).getViewModel();if(S==null||v==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const I=s.get(m.TextSelectionManagerService),p=((D=I.getCurrentSelections())!=null?D:[]).map(z),_=s.get(m.DocStateChangeManagerService),O=s.get(Z),x=!!S.getSnapshot().disabled;if(t.JSONX.isNoop(i)||i&&i.length===0||x)return{unitId:e,actions:[],textRanges:p};const C=t.JSONX.invertWithDoc(i,S.getSnapshot());S.apply(i),v.reset(S),!l&&o&&c!=null&&queueMicrotask(()=>{I.replaceTextRanges(o,!0,a.options)});const R={commandId:ze,unitId:e,segmentId:n,trigger:c,noHistory:d,debounce:f,redoState:{actions:i,textRanges:o},undoState:{actions:C,textRanges:r!=null?r:p}};if(u){const y=O.fetchComposedUndoRedoMutationParams();if(y==null)throw new Error("historyParams is null in RichTextEditingMutation");const{undoMutationParams:A,redoMutationParams:E,previousActiveRange:P}=y;R.redoState.actions=E.actions,R.undoState.actions=A.actions,R.undoState.textRanges=[P]}return _.setChangeState(R),{unitId:e,actions:C,textRanges:p}}};function He(s,a){var n;return(n=s.get(U.IRenderManagerService).getRenderById(a))==null?void 0:n.with(m.DocSkeletonManagerService)}function B(s,a=""){if(!a)return["body"];const{headers:e,footers:n}=s.getSnapshot();if(e==null&&n==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[a])!=null)return["headers",a,"body"];if((n==null?void 0:n[a])!=null)return["footers",a,"body"];throw new Error("Segment id not found in headers or footers")}const Ve="doc.command.insert-text",q={id:Ve,type:t.CommandType.COMMAND,handler:async(s,a)=>{var M;const e=s.get(t.ICommandService),{range:n,segmentId:i,body:o,unitId:r,textRanges:c,cursorOffset:d}=a,u=s.get(m.TextSelectionManagerService),f=s.get(t.IUniverInstanceService).getUnit(r,t.UniverInstanceType.UNIVER_DOC);if(f==null)return!1;const g=u.getActiveRange(),T=f.getSelfOrHeaderFooterModel((M=g==null?void 0:g.segmentId)!=null?M:"").getBody();if(!T)return!1;const S=Y(n,T),{startOffset:v,collapsed:I}=S,h=d!=null?d:o.dataStream.length,p=[{startOffset:v+h,endOffset:v+h,style:g==null?void 0:g.style,collapsed:I}],_={id:b.id,params:{unitId:r,actions:[],textRanges:c!=null?c:p,debounce:!0}},O=new t.TextX,x=t.JSONX.getInstance();if(I)v>0&&O.push({t:t.TextXActionType.RETAIN,len:v,segmentId:i});else{const{dos:D,retain:y}=ae(S,i,0,T);O.push(...D),c||(_.params.textRanges=[{startOffset:v+h+y,endOffset:v+h+y,collapsed:I}])}O.push({t:t.TextXActionType.INSERT,body:o,len:o.dataStream.length,line:0,segmentId:i});const C=B(f,i);return _.params.actions=x.editOp(O.serialize(),C),!!e.syncExecuteCommand(_.id,_.params)}};var w=(s=>(s[s.LEFT=0]="LEFT",s[s.RIGHT=1]="RIGHT",s))(w||{});const H={id:"doc.command.delete-text",type:t.CommandType.COMMAND,handler:async(s,a)=>{var D;const e=s.get(t.ICommandService),n=s.get(t.IUniverInstanceService),{range:i,segmentId:o,unitId:r,direction:c,len:d=1}=a,u=n.getUnit(r,t.UniverInstanceType.UNIVER_DOC),l=u==null?void 0:u.getSelfOrHeaderFooterModel(o).getBody();if(u==null||l==null)return!1;const{startOffset:f}=i,g=l.dataStream,T=c===0?f-d:f,S=T+d-1,v=(D=l.customRanges)==null?void 0:D.filter(y=>xe(y.startIndex,y.endIndex,T,S)),I=v==null?void 0:v.filter(y=>De(T,d,y,g)),h=[];for(let y=0;y<d;y++)h.push(T+y);I==null||I.forEach(y=>{h.push(y.startIndex,y.endIndex)}),h.sort((y,A)=>y-A);const p=h[0],_={id:b.id,params:{unitId:r,actions:[],textRanges:[{startOffset:p,endOffset:p,collapsed:!0}],debounce:!0}},O=new t.TextX,x=t.JSONX.getInstance();let C=0;for(let y=0;y<h.length;y++){const A=h[y];A-C>0&&O.push({t:t.TextXActionType.RETAIN,len:A-C,segmentId:o}),O.push({t:t.TextXActionType.DELETE,len:1,segmentId:o,line:0}),C=A+1}const R=B(u,o);return _.params.actions=x.editOp(O.serialize(),R),!!e.syncExecuteCommand(_.id,_.params)}},Ue={id:"doc.command.update-text",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{range:e,segmentId:n,updateBody:i,coverType:o,unitId:r,textRanges:c}=a,d=s.get(t.ICommandService),l=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(l==null)return!1;const f={id:b.id,params:{unitId:r,actions:[],textRanges:c}},g=new t.TextX,T=t.JSONX.getInstance(),{startOffset:S,endOffset:v}=e;g.push({t:t.TextXActionType.RETAIN,len:S,segmentId:n}),g.push({t:t.TextXActionType.RETAIN,body:i,len:v-S,segmentId:n,coverType:o});const I=B(l,n);return f.params.actions=T.editOp(g.serialize(),I),!!d.syncExecuteCommand(f.id,f.params)}};function Je(s,a){const e=[];for(let n=0,i=s.length;n<i;n++)s[n]===t.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(a)for(const n of e)a.bullet&&(n.bullet=t.Tools.deepClone(a.bullet)),a.paragraphStyle&&(n.paragraphStyle=t.Tools.deepClone(a.paragraphStyle));return e}const We={id:"doc.command.break-line",type:t.CommandType.COMMAND,handler:async s=>{var T;const a=s.get(m.TextSelectionManagerService),e=s.get(t.IUniverInstanceService),n=s.get(t.ICommandService),i=a.getActiveRange();if(i==null)return!1;const{segmentId:o}=i,r=e.getCurrentUniverDocInstance(),c=r==null?void 0:r.getSelfOrHeaderFooterModel(o).getBody();if(!r||!c)return!1;const d=r.getUnitId(),{startOffset:u,endOffset:l}=Y(i,c),g=((T=c.paragraphs)!=null?T:[]).find(S=>S.startIndex>=u);if(g&&g.startIndex>l){const S=t.normalizeBody(t.getBodySlice(c,l,g.startIndex)),v={startOffset:u,endOffset:g.startIndex,collapsed:!1};return t.updateAttributeByInsert(S,{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Je(t.DataStreamTreeTokenType.PARAGRAPH,g)},1,0),await n.executeCommand(q.id,{unitId:d,body:S,range:v,segmentId:o,cursorOffset:1})}else return await n.executeCommand(q.id,{unitId:d,body:{dataStream:t.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Je(t.DataStreamTreeTokenType.PARAGRAPH,g)},range:i,segmentId:o})}},zt={id:"doc.command.inner-paste",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{segmentId:e,textRanges:n}=a,i=a.body,o=s.get(t.ICommandService),r=s.get(m.TextSelectionManagerService),c=s.get(t.IUniverInstanceService),d=r.getCurrentSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=c.getCurrentUniverDocInstance(),l=u==null?void 0:u.getSelfOrHeaderFooterModel(e).getBody();if(u==null||l==null)return!1;const f=u.getUnitId(),g={id:b.id,params:{unitId:f,actions:[],textRanges:n}},T=new t.MemoryCursor;T.reset();const S=new t.TextX,v=t.JSONX.getInstance();for(const p of d){const{startOffset:_,endOffset:O,collapsed:x}=p,C=_-T.cursor;if(x)S.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e});else{const{dos:R}=ae(p,e,T.cursor,l);S.push(...R)}S.push({t:t.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:e}),T.reset(),T.moveCursor(O)}const I=B(u,e);return g.params.actions=v.editOp(S.serialize(),I),!!o.syncExecuteCommand(g.id,g.params)}},be={id:"doc.command.inner-cut",type:t.CommandType.COMMAND,handler:async(s,a)=>{var C,R,M;const{segmentId:e,textRanges:n}=a,i=s.get(t.ICommandService),o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),c=o.getCurrentSelections();if(!Array.isArray(c)||c.length===0)return!1;const d=(C=r.getCurrentUniverDocInstance())==null?void 0:C.getUnitId();if(!d)return!1;const u=r.getUniverDocInstance(d),l=t.getDocsUpdateBody(u.getSnapshot(),e);if(u==null||l==null)return!1;const f={id:b.id,params:{unitId:d,actions:[],textRanges:n}},g=new t.MemoryCursor;g.reset();const T=new t.TextX,S=t.JSONX.getInstance(),v=[];for(const D of c){const{startOffset:y,endOffset:A,collapsed:E}=D;if(y==null||A==null)continue;const P=y-g.cursor;E?T.push({t:t.TextXActionType.RETAIN,len:P,segmentId:e}):T.push(...Vt(D,l,e,g.cursor)),g.reset(),g.moveCursor(A)}const I=B(u,e);v.push(S.editOp(T.serialize(),I));const h=Ht(l,c),p=(R=u.getDrawings())!=null?R:{},_=(M=u.getDrawingsOrder())!=null?M:[],O=h.sort((D,y)=>_.indexOf(D)>_.indexOf(y)?-1:_.indexOf(D)<_.indexOf(y)?1:0);if(O.length>0)for(const D of O){const y=p[D],A=_.indexOf(D);if(y==null||A<0)continue;const E=S.removeOp(["drawings",D],y),P=S.removeOp(["drawingsOrder",A],D);v.push(E),v.push(P)}return f.params.actions=v.reduce((D,y)=>t.JSONX.compose(D,y),null),!!i.syncExecuteCommand(f.id,f.params)}};function Ht(s,a){const e=[],{customBlocks:n=[]}=s;for(const i of a){const{startOffset:o,endOffset:r}=i;if(!(o==null||r==null))for(const c of n){const{startIndex:d}=c;d>=o&&d<r&&e.push(c.blockId)}}return e}function Vt(s,a,e="",n=0){var h;const{startOffset:i,endOffset:o}=ne(s,a),r=[],{paragraphs:c=[],dataStream:d}=a,u=i-n,l=o-n,f=c==null?void 0:c.find(p=>p.startIndex-n>=u&&p.startIndex-n<=l),g=(h=a.customRanges)==null?void 0:h.filter(p=>xe(p.startIndex,p.endIndex,i,o)),T=new Set(g==null?void 0:g.filter(p=>De(i,o-i,p,d))),S=new Set;if(g==null||g.forEach(p=>{T.has(p)||(p.startIndex-n>=u&&p.startIndex-n<=l&&p.endIndex-n>l&&S.add(p.startIndex),p.endIndex-n>=u&&p.endIndex-n<=l&&p.startIndex<u&&S.add(p.endIndex))}),u>0&&r.push({t:t.TextXActionType.RETAIN,len:u,segmentId:e}),f&&f.startIndex-n>u){const p=f.startIndex-n;S.add(p)}const v=[...S].sort((p,_)=>p-_);let I=u;return v.forEach(p=>{const _=p-I;_>0&&r.push({t:t.TextXActionType.DELETE,len:_,line:0,segmentId:e}),r.push({t:t.TextXActionType.RETAIN,len:1,segmentId:e}),I=p+1}),I<l&&r.push({t:t.TextXActionType.DELETE,len:l-I,line:0,segmentId:e}),r}const ie={id:"doc.command.delete-custom-block",type:t.CommandType.COMMAND,handler:async(s,a)=>{var y;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),o=e.getActiveRange(),r=n.getCurrentUniverDocInstance();if(o==null||r==null)return!1;const{direction:c,range:d,unitId:u,drawingId:l}=a,{startOffset:f,segmentId:g,style:T}=o,S=c===w.LEFT?f-1:f,v=[{startOffset:S,endOffset:S,style:T}],I={id:b.id,params:{unitId:u,actions:[],textRanges:v,prevTextRanges:[d]}},h=new t.TextX,p=t.JSONX.getInstance(),_=[];f>0&&h.push({t:t.TextXActionType.RETAIN,len:c===w.LEFT?f-1:f,segmentId:g}),h.push({t:t.TextXActionType.DELETE,len:1,line:0,segmentId:g}),_.push(p.editOp(h.serialize()));const O=((y=r.getDrawings())!=null?y:{})[l],C=r.getDrawingsOrder().indexOf(l),R=p.removeOp(["drawings",l],O),M=p.removeOp(["drawingsOrder",C],l);return _.push(R),_.push(M),I.params.actions=_.reduce((A,E)=>t.JSONX.compose(A,E),null),!!i.syncExecuteCommand(I.id,I.params)}},se={id:"doc.command.merge-two-paragraph",type:t.CommandType.COMMAND,handler:async(s,a)=>{var A,E;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{direction:o,range:r}=a,c=e.getActiveRange(),d=e.getCurrentSelections();if(c==null||d==null)return!1;const{segmentId:u,style:l}=c,f=n.getCurrentUniverDocInstance(),g=f==null?void 0:f.getSelfOrHeaderFooterModel(u).getBody();if(!f||!g)return!1;const T=ne(c,g),{startOffset:S,collapsed:v}=T;if(!v)return!1;const I=o===w.LEFT?S:S+1,h=(E=(A=g.paragraphs)==null?void 0:A.find(P=>P.startIndex>=I))==null?void 0:E.startIndex,p=Jt(g,I,h),_=o===w.LEFT?S-1:S,O=f.getUnitId(),x=[{startOffset:_,endOffset:_,style:l}],C={id:b.id,params:{unitId:O,actions:[],textRanges:x,prevTextRanges:[r]}},R=new t.TextX,M=t.JSONX.getInstance();R.push({t:t.TextXActionType.RETAIN,len:o===w.LEFT?S-1:S,segmentId:u}),p.dataStream.length&&R.push({t:t.TextXActionType.INSERT,body:p,len:p.dataStream.length,line:0,segmentId:u}),R.push({t:t.TextXActionType.RETAIN,len:1,segmentId:u}),R.push({t:t.TextXActionType.DELETE,len:h+1-I,line:0,segmentId:u});const D=B(f,u);return C.params.actions=M.editOp(R.serialize(),D),!!i.syncExecuteCommand(C.id,C.params)}},Ye={id:"doc.command.delete-left",type:t.CommandType.COMMAND,handler:async s=>{var M,D;const a=s.get(m.TextSelectionManagerService),e=s.get(t.IUniverInstanceService),n=s.get(t.ICommandService);let i=!0;const o=e.getCurrentUniverDocInstance();if(!o)return!1;const r=o.getUnitId(),c=He(s,r),d=a.getActiveRange(),u=a.getCurrentSelections(),l=c==null?void 0:c.getSkeleton();if(d==null||l==null||u==null)return!1;const{segmentId:f,style:g,segmentPage:T}=d,S=o.getSelfOrHeaderFooterModel(f).getBody();if(S==null)return!1;const v=ne(d,S),{startOffset:I,collapsed:h}=v,p=l.findNodeByCharIndex(I,f,T),_=U.hasListGlyph(p),O=U.isIndentByGlyph(p,S);let x=I;const C=l.findNodeByCharIndex(I-1,f,T);if(U.isFirstGlyph(p)&&C!==p&&(_===!0||O===!0)&&h){const y=U.getParagraphByGlyph(p,S);if(y==null)return!1;const A=y==null?void 0:y.startIndex,E={startIndex:0},P=y.paragraphStyle;if(_===!0){const k=y.paragraphStyle;if(k){E.paragraphStyle=k;const{hanging:L}=k;L&&(E.paragraphStyle.indentStart=L,E.paragraphStyle.hanging=void 0)}}else if(O===!0){const k=y.bullet;k&&(E.bullet=k),P!=null&&(E.paragraphStyle={...P},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const Me=[{startOffset:x,endOffset:x,style:g}];i=await n.executeCommand(Ue.id,{unitId:o.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:A,endOffset:A+1},textRanges:Me,coverType:t.UpdateDocsAttributeType.REPLACE,segmentId:f})}else if(h===!0){if(C==null)return!0;if(C.content==="\r")i=await n.executeCommand(se.id,{direction:w.LEFT,range:v});else if(C.streamType==="\b"){const y=(D=o.getSnapshot().drawings)==null?void 0:D[(M=C.drawingId)!=null?M:""];if(y==null)return!0;if(y.layoutType===t.PositionedObjectLayoutType.INLINE){const E=o.getUnitId();i=await n.executeCommand(ie.id,{direction:w.LEFT,range:d,unitId:E,drawingId:C.drawingId})}else{const E=l.findNodeByCharIndex(I-2);if(E==null)return!0;x-=C.count,x-=E.count;const P=[{startOffset:x,endOffset:x,style:g}];i=await n.executeCommand(H.id,{unitId:o.getUnitId(),range:{...d,startOffset:d.startOffset-1,endOffset:d.endOffset-1},segmentId:f,direction:w.LEFT,len:E.count,textRanges:P})}}else x-=C.count,i=await n.executeCommand(H.id,{unitId:o.getUnitId(),range:v,segmentId:f,direction:w.LEFT,len:C.count})}else{const y=Ze({...d,...v},u);i=await n.executeCommand(be.id,{segmentId:f,textRanges:y})}return i}},Ke={id:"doc.command.delete-right",type:t.CommandType.COMMAND,handler:async s=>{var p,_;const a=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(!n)return!1;const i=He(s,n.getUnitId()),o=s.get(t.ICommandService),r=a.getActiveRange(),c=a.getCurrentSelections(),d=i==null?void 0:i.getSkeleton();if(r==null||d==null||c==null)return!1;const{segmentId:u,style:l,segmentPage:f}=r,g=n==null?void 0:n.getSelfOrHeaderFooterModel(u).getBody();if(!n||!g)return!1;const T=Y(r,g),{startOffset:S,endOffset:v,collapsed:I}=T;if(S===g.dataStream.length-2&&I)return!0;let h=!1;if(I===!0){const O=d.findNodeByCharIndex(S,u,f),x=d.findNodeByCharIndex(S+1);if(O.content==="\r")h=await o.executeCommand(se.id,{direction:w.RIGHT,range:r});else if(O.streamType==="\b"){const C=(_=n.getSnapshot().drawings)==null?void 0:_[(p=O.drawingId)!=null?p:""];if(C==null)return!0;if(C.layoutType===t.PositionedObjectLayoutType.INLINE){const M=n.getUnitId();h=await o.executeCommand(ie.id,{direction:w.RIGHT,range:r,unitId:M,drawingId:O.drawingId})}else{if(x==null)return!0;const M=[{startOffset:S+1,endOffset:S+1,style:l}];h=await o.executeCommand(H.id,{unitId:n.getUnitId(),range:{...r,startOffset:S+1,endOffset:v+1},segmentId:u,direction:w.RIGHT,textRanges:M,len:x.count})}}else{const C=[{startOffset:S,endOffset:S,style:l}];h=await o.executeCommand(H.id,{unitId:n.getUnitId(),range:T,segmentId:u,direction:w.RIGHT,textRanges:C,len:O.count})}}else{const O=Ze(r,c);h=await o.executeCommand(be.id,{segmentId:u,textRanges:O})}return h}};function Jt(s,a,e){const{textRuns:n=[],customBlocks:i=[]}=s,r={dataStream:s.dataStream.substring(a,e),customRanges:t.getCustomRangeSlice(s,a,e).customRanges,customDecorations:t.getCustomDecorationSlice(s,a,e)},c=[];for(const u of n){const{st:l,ed:f}=u;f<=a||l>=e||(l<a?c.push({...u,st:0,ed:f-a}):f>e?c.push({...u,st:l-a,ed:e-a}):c.push({...u,st:l-a,ed:f-a}))}c.length>0&&(r.textRuns=c);const d=[];for(const u of i){const{startIndex:l}=u;l>=a&&l<=e&&d.push({...u,startIndex:l-a})}return d.length>0&&(r.customBlocks=d),r}function Ze(s,a){let e=s.endOffset;for(const i of a){const{startOffset:o,endOffset:r}=i;o==null||r==null||r<=s.endOffset&&(e-=r-o)}return[{startOffset:e,endOffset:e,style:s.style}]}const Pe={id:"doc.command.ime-input",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:o,isCompositionStart:r}=a,c=s.get(t.ICommandService),d=s.get(Z),l=s.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(l==null)return!1;const f=d.getActiveRange();if(!f)return!1;const{startOffset:g,style:T,segmentId:S}=f,v=l.getSelfOrHeaderFooterModel(S).getBody();if(v==null)return!1;const I=Y(f,v);Object.assign(f,I);const h=n.length,p=[{startOffset:g+h,endOffset:g+h,collapsed:!0,style:T}],_={id:b.id,params:{unitId:e,actions:[],textRanges:p}},O=new t.TextX,x=t.JSONX.getInstance();if(!f.collapsed&&r){const{dos:M,retain:D,cursor:y}=ae(f,S,0,v);O.push(...M),_.params.textRanges=[{startOffset:g+h+D,endOffset:g+h+D,collapsed:!0}]}else O.push({t:t.TextXActionType.RETAIN,len:g,segmentId:S});i>0&&O.push({t:t.TextXActionType.DELETE,len:i,line:0,segmentId:S}),O.push({t:t.TextXActionType.INSERT,body:{dataStream:n},len:n.length,line:0,segmentId:S});const C=B(l,S);_.params.actions=x.editOp(O.serialize(),C),_.params.noHistory=!o,_.params.isCompositionEnd=o;const R=c.syncExecuteCommand(_.id,_.params);return d.pushUndoRedoMutationParams(R,_.params),!!R}};function X(s,a,e,n){var o;const{segmentId:i}=(o=e.getActiveRange())!=null?o:{};return i==null?!1:n.executeCommand(we.id,{segmentId:i,preCommandId:s,...a!=null?a:{}})}const qe="doc.command.set-inline-format-bold",oe={id:qe,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(qe,a,n,e)}},Qe="doc.command.set-inline-format-italic",re={id:Qe,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(Qe,a,n,e)}},et="doc.command.set-inline-format-underline",ce={id:et,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(et,a,n,e)}},tt="doc.command.set-inline-format-strikethrough",de={id:tt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(tt,a,n,e)}},nt="doc.command.set-inline-format-subscript",V={id:nt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(nt,a,n,e)}},at="doc.command.set-inline-format-superscript",le={id:at,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(at,a,n,e)}},it="doc.command.set-inline-format-fontsize",ue={id:it,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(it,a,n,e)}},st="doc.command.set-inline-format-font-family",me={id:st,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(st,a,n,e)}},ot="doc.command.set-inline-format-text-color",ge={id:ot,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(ot,a,n,e)}},rt="doc.command.set-inline-format-text-background-color",fe={id:rt,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(rt,a,n,e)}},ct="doc.command.reset-inline-format-text-background-color",Se={id:ct,type:t.CommandType.COMMAND,handler:async(s,a)=>{const e=s.get(t.ICommandService),n=s.get(m.TextSelectionManagerService);return X(ct,a,n,e)}},dt={[oe.id]:"bl",[re.id]:"it",[ce.id]:"ul",[de.id]:"st",[ue.id]:"fs",[me.id]:"ff",[ge.id]:"cl",[fe.id]:"bg",[Se.id]:"bg",[V.id]:"va",[le.id]:"va"},we={id:"doc.command.set-inline-format",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{segmentId:e,value:n,preCommandId:i}=a,o=s.get(t.ICommandService),r=s.get(m.TextSelectionManagerService),c=s.get(t.IUniverInstanceService),d=r.getCurrentSelections();if(!Array.isArray(d)||d.length===0)return!1;const u=c.getCurrentUniverDocInstance();if(u==null)return!1;const l=u.getUnitId();let f;switch(i){case oe.id:case re.id:case ce.id:case de.id:case V.id:case le.id:{f=Yt(u.getSelfOrHeaderFooterModel(e).getBody().textRuns,i,d);break}case ue.id:case me.id:{f=n;break}case ge.id:case fe.id:{f={rgb:n};break}case Se.id:{f={rgb:null};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const g={id:b.id,params:{unitId:l,actions:[],textRanges:d.map(z)}},T=new t.TextX,S=t.JSONX.getInstance(),v=new t.MemoryCursor;v.reset();for(const p of d){const{startOffset:_,endOffset:O}=p,x={dataStream:"",textRuns:[{st:0,ed:O-_,ts:{[dt[i]]:f}}]},C=_-v.cursor;C!==0&&T.push({t:t.TextXActionType.RETAIN,len:C,segmentId:e}),T.push({t:t.TextXActionType.RETAIN,body:x,len:O-_,segmentId:e}),v.reset(),v.moveCursor(O)}const I=B(u,e);return g.params.actions=S.editOp(T.serialize(),I),!!o.syncExecuteCommand(g.id,g.params)}};function Wt(s){return s!==null&&typeof s=="object"}function Yt(s,a,e){let n=0,i=0;const o=dt[a];for(;n!==s.length&&i!==e.length;){const{startOffset:r,endOffset:c}=e[i],{st:d,ed:u,ts:l}=s[n];if(c<=d)i++;else if(u<=r)n++;else{if(/bl|it/.test(o))return(l==null?void 0:l[o])===t.BooleanNumber.TRUE?t.BooleanNumber.FALSE:t.BooleanNumber.TRUE;if(/ul|st/.test(o))return Wt(l==null?void 0:l[o])&&(l==null?void 0:l[o]).s===t.BooleanNumber.TRUE?{s:t.BooleanNumber.FALSE}:{s:t.BooleanNumber.TRUE};if(/va/.test(o))return a===V.id?(l==null?void 0:l[o])===t.BaselineOffset.SUBSCRIPT?t.BaselineOffset.NORMAL:t.BaselineOffset.SUBSCRIPT:(l==null?void 0:l[o])===t.BaselineOffset.SUPERSCRIPT?t.BaselineOffset.NORMAL:t.BaselineOffset.SUPERSCRIPT;n++}}return/bl|it/.test(o)?t.BooleanNumber.TRUE:/ul|st/.test(o)?{s:t.BooleanNumber.TRUE}:a===V.id?t.BaselineOffset.SUBSCRIPT:t.BaselineOffset.SUPERSCRIPT}const Ie={id:"doc.command.list-operation",type:t.CommandType.COMMAND,handler:(s,a)=>{var E,P,Me,k;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{listType:o}=a,r=n.getCurrentUniverDocInstance(),c=e.getActiveRange();if(r==null||c==null)return!1;const{segmentId:d}=c,u=(E=e.getCurrentSelections())!=null?E:[],l=(P=r.getSelfOrHeaderFooterModel(d).getBody())==null?void 0:P.paragraphs,f=u.map(z);if(l==null)return!1;const g=mt(c,l),T=r.getUnitId(),S=g.every(L=>{var F;return((F=L.bullet)==null?void 0:F.listType)===o});let I=t.Tools.generateRandomId(6);if(g.length===1){const L=l.indexOf(g[0]),F=l[L-1],G=l[L+1];F&&F.bullet&&F.bullet.listType===o?I=F.bullet.listId:G&&G.bullet&&G.bullet.listType===o&&(I=G.bullet.listId)}const h={id:b.id,params:{unitId:T,actions:[],textRanges:f}},p=new t.MemoryCursor;p.reset();const _=new t.TextX,O=t.JSONX.getInstance(),x=(Me=r.getSnapshot().lists)!=null?Me:{},C={...t.PRESET_LIST_TYPE,...x},{charSpace:R,defaultTabStop:M=36,gridType:D}=r.getSnapshot().documentStyle;for(const L of g){const{startIndex:F,paragraphStyle:G={}}=L,{indentFirstLine:Rn=0,snapToGrid:Mn,indentStart:Be=0}=G,{hanging:Xe,indentStart:Ot}=C[o].nestingLevel[0],Le=U.getCharSpaceApply(R,M,D,Mn);_.push({t:t.TextXActionType.RETAIN,len:F-p.cursor,segmentId:d}),_.push({t:t.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[S?{paragraphStyle:{...G,hanging:void 0,indentStart:Be?Math.max(0,U.getNumberUnitValue(Be,Le)+Xe-Ot):void 0},startIndex:0}:{startIndex:0,paragraphStyle:{...G,indentFirstLine:void 0,hanging:Xe,indentStart:Ot-Xe+U.getNumberUnitValue(Rn,Le)+U.getNumberUnitValue(Be,Le)},bullet:{...(k=L.bullet)!=null?k:{nestingLevel:0,textStyle:{fs:20}},listType:o,listId:I}}]},segmentId:d,coverType:t.UpdateDocsAttributeType.REPLACE}),p.moveCursorTo(F+1)}const y=B(r,d);return h.params.actions=O.editOp(_.serialize(),y),!!i.syncExecuteCommand(h.id,h.params)}},lt={id:"doc.command.bullet-list",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(Ie.id,{listType:t.PresetListType.BULLET_LIST})},ut={id:"doc.command.order-list",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(Ie.id,{listType:t.PresetListType.ORDER_LIST})};function mt(s,a){const{startOffset:e,endOffset:n}=s,i=[];let o=-1;for(const r of a){const{startIndex:c}=r;(e>o&&e<=c||n>o&&n<=c||c>=e&&c<=n)&&i.push(r),o=c}return i}const gt={id:"doc.command-replace-content",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,body:n,textRanges:i,segmentId:o="",options:r}=a,c=s.get(t.IUniverInstanceService),d=s.get(t.ICommandService),u=s.get(m.TextSelectionManagerService),l=c.getUniverDocInstance(e),f=l==null?void 0:l.getSnapshot().body,g=u.getCurrentSelections();if(l==null||f==null||!Array.isArray(g)||g.length===0)return!1;const T=St(e,o,l,f,n);return T.params.textRanges=i,r&&(T.params.options=r),!!d.syncExecuteCommand(T.id,T.params)}},ft={id:"doc.command-cover-content",type:t.CommandType.COMMAND,handler:async(s,a)=>{const{unitId:e,body:n,segmentId:i=""}=a,o=s.get(t.IUniverInstanceService),r=s.get(t.ICommandService),c=s.get(t.IUndoRedoService),d=o.getUniverDocInstance(e),u=d==null?void 0:d.getSnapshot().body;if(d==null||u==null)return!1;const l=St(e,i,d,u,n);return l.params.noNeedSetTextRange=!0,l.params.noHistory=!0,r.syncExecuteCommand(l.id,l.params),c.clearUndoRedo(e),!0}};function St(s,a,e,n,i){const o={id:b.id,params:{unitId:s,actions:[],textRanges:[]}},r=new t.TextX,c=t.JSONX.getInstance(),d=(n==null?void 0:n.dataStream.length)-2;d>0&&r.push({t:t.TextXActionType.DELETE,len:d,line:0,segmentId:a}),i.dataStream.length>0&&r.push({t:t.TextXActionType.INSERT,body:i,len:i.dataStream.length,line:0,segmentId:a});const u=B(e,a);return o.params.actions=c.editOp(r.serialize(),u),o}const Kt=(s,a)=>{const e=s.get(t.IUniverInstanceService).getUniverDocInstance(a.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...t.Tools.deepClone(a),zoomRatio:n}},Q={id:"doc.operation.set-zoom-ratio",type:t.CommandType.OPERATION,handler:(s,a)=>{const e=s.get(t.IUniverInstanceService).getUniverDocInstance(a.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:a.zoomRatio}:n.settings.zoomRatio=a.zoomRatio,!0}},It={type:t.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(s,a)=>{var f,g,T;const e=s.get(t.ICommandService),n=s.get(t.IUndoRedoService),i=s.get(t.IUniverInstanceService);let o=(f=i.getCurrentUniverDocInstance())==null?void 0:f.getUnitId();if(!o)return!1;let r=1;if(a&&(o=(g=a.documentId)!=null?g:o,r=(T=a.zoomRatio)!=null?T:r),!i.getUniverDocInstance(o))return!1;const d={zoomRatio:r,unitId:o},u=Kt(s,d);return e.syncExecuteCommand(Q.id,d)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:Q.id,params:u}],redoMutations:[{id:Q.id,params:d}]}),!0):!1}},he={id:"doc.operation.move-cursor",type:t.CommandType.OPERATION,handler:(s,a)=>!!a},pe={id:"doc.operation.move-selection",type:t.CommandType.OPERATION,handler:(s,a)=>!!a},ht={id:"doc.operation.select-all",type:t.CommandType.COMMAND,handler:async s=>{const a=s.get(t.IUniverInstanceService),e=s.get(m.TextSelectionManagerService),n=a.getCurrentUniverDocInstance(),i=e.getActiveRange();if(n==null||i==null)return!1;const{segmentId:o}=i,r=n.getSelfOrHeaderFooterModel(o).getSnapshot().body;if(r==null)return!1;const c=[{startOffset:0,endOffset:r.dataStream.length-2}];return e.replaceTextRanges(c,!1),!0}};var Zt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Qt=(s,a,e,n)=>{for(var i=n>1?void 0:n?qt(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Zt(a,e,i),i},ee=(s,a)=>(e,n)=>a(e,n,s);let Te=class extends t.Disposable{constructor(a,e,n,i,o){super();N(this,"_previousIMEContent","");N(this,"_isCompositionStart",!0);N(this,"_onStartSubscription");N(this,"_onUpdateSubscription");N(this,"_onEndSubscription");this._univerInstanceService=a,this._renderManagerSrv=e,this._textSelectionRenderManager=n,this._imeInputManagerService=i,this._commandService=o,this._initialize()}dispose(){var a,e,n;(a=this._onStartSubscription)==null||a.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(a=>{if(a==null)return;this._resetIME();const{activeRange:e}=a;e!=null&&this._imeInputManagerService.setActiveRange(t.Tools.deepClone(e))})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async a=>{this._updateContent(a,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(a=>{this._updateContent(a,!1)})}async _updateContent(a,e){var u;if(a==null)return;const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const i=(u=this._renderManagerSrv.getRenderById(n.getUnitId()))==null?void 0:u.with(m.DocSkeletonManagerService).getSkeleton(),{event:o,activeRange:r}=a;if(i==null||r==null)return;const d=o.data;d===this._previousIMEContent&&e||(await this._commandService.executeCommand(Pe.id,{unitId:n.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)}};Te=Qt([t.OnLifecycle(t.LifecycleStages.Rendered,Te),ee(0,t.IUniverInstanceService),ee(1,U.IRenderManagerService),ee(2,U.ITextSelectionRenderManager),ee(3,j.Inject(Z)),ee(4,t.ICommandService)],Te);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(s,a,e,n)=>{for(var i=n>1?void 0:n?tn(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&en(a,e,i),i},ve=(s,a)=>(e,n)=>a(e,n,s);let Ce=class extends t.Disposable{constructor(a,e,n,i){super();N(this,"_onInputSubscription");this._univerInstanceService=a,this._renderManagerService=e,this._textSelectionManagerService=n,this._commandService=i,this._commandExecutedListener()}dispose(){var a;super.dispose(),(a=this._onInputSubscription)==null||a.unsubscribe()}_commandExecutedListener(){const a=[he.id,pe.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!a.includes(e.id))return;const n=e.params;switch(e.id){case he.id:return this._handleMoveCursor(n.direction);case pe.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(a){var _,O,x;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getCurrentSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return;const o=(_=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:_.with(m.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||o==null||r==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:l,direction:f,segmentId:g,startNodePosition:T,endNodePosition:S,segmentPage:v}=e;if(n.length>1){let C=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(const M of n)C=Math.min(C,M.startOffset),R=Math.max(R,M.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:a===t.Direction.LEFT||a===t.Direction.UP?R:C,endOffset:a===t.Direction.LEFT||a===t.Direction.UP?C:R,style:u}],!1);return}const I=l||f===U.RANGE_DIRECTION.FORWARD?c:d;let h=l||f===U.RANGE_DIRECTION.FORWARD?d:c;const p=(O=i.getSelfOrHeaderFooterModel(g).getBody().dataStream.length)!=null?O:Number.POSITIVE_INFINITY;if(a===t.Direction.LEFT||a===t.Direction.RIGHT){const C=o.findNodeByCharIndex(h-1,g,v),R=o.findNodeByCharIndex(h,g,v);h=a===t.Direction.RIGHT?h+R.count:h-((x=C==null?void 0:C.count)!=null?x:0),h=Math.min(p-2,Math.max(0,h)),this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:h,style:u}],!1)}else{const C=o.findNodeByCharIndex(h,g,v),R=r.document.getOffsetConfig(),M=l?T:f===U.RANGE_DIRECTION.FORWARD?S:T,D=this._getTopOrBottomPosition(o,C,M,a===t.Direction.DOWN);if(D==null){const A=a===t.Direction.UP?0:p-2;if(A===h)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:A,style:u}],!1);return}const y=new U.NodePositionConvertToCursor(R,o).getRangePointData(D,D).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:y.endOffset,style:u}],!1)}}_handleMoveCursor(a){var I,h,p;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getCurrentSelections(),i=this._univerInstanceService.getCurrentUniverDocInstance();if(!i)return!1;const o=(I=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:I.with(m.DocSkeletonManagerService).getSkeleton(),r=this._getDocObject();if(e==null||o==null||r==null||n==null)return;const{startOffset:c,endOffset:d,style:u,collapsed:l,segmentId:f,startNodePosition:g,endNodePosition:T,segmentPage:S}=e,v=(h=i.getSelfOrHeaderFooterModel(f).getBody().dataStream.length)!=null?h:Number.POSITIVE_INFINITY;if(a===t.Direction.LEFT||a===t.Direction.RIGHT){let _;if(!e.collapsed||n.length>1){let O=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY;for(const C of n)O=Math.min(O,C.startOffset),x=Math.max(x,C.endOffset);_=a===t.Direction.LEFT?O:x}else{const O=o.findNodeByCharIndex(c-1,f,S),x=o.findNodeByCharIndex(c,f,S);a===t.Direction.LEFT?_=Math.max(0,c-((p=O==null?void 0:O.count)!=null?p:0)):_=Math.min(v-2,d+x.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:_,endOffset:_,style:u}],!1)}else{const _=o.findNodeByCharIndex(c,f,S),O=o.findNodeByCharIndex(d,f,S),x=r.document.getOffsetConfig(),C=this._getTopOrBottomPosition(o,a===t.Direction.UP?_:O,a===t.Direction.UP?g:T,a===t.Direction.DOWN);if(C==null){let M;l?M=a===t.Direction.UP?0:v-2:M=a===t.Direction.UP?c:d,this._textSelectionManagerService.replaceTextRanges([{startOffset:M,endOffset:M,style:u}],!1);return}const R=new U.NodePositionConvertToCursor(x,o).getRangePointData(C,C).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...R,style:u}],!1)}}_getTopOrBottomPosition(a,e,n,i){if(e==null||n==null)return;const o=this._getGlyphLeftOffsetInLine(e),r=this._getNextOrPrevLine(e,i);if(r==null)return;const c=this._matchPositionByLeftOffset(a,r,o,n);if(c!=null)return{...c,isBack:!0}}_getGlyphLeftOffsetInLine(a){const e=a.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:i}=a;return n+i}_matchPositionByLeftOffset(a,e,n,i){const o={distance:Number.POSITIVE_INFINITY};for(const c of e.divides){const d=c.left;for(const u of c.glyphGroup){const{left:l}=u,f=d+l,g=Math.abs(n-f);g<o.distance&&(o.glyph=u,o.distance=g)}}if(o.glyph==null)return;const{segmentPage:r}=i;return a.findPositionByGlyph(o.glyph,r)}_getNextOrPrevLine(a,e){var S,v,I,h,p,_,O,x,C,R,M,D;const n=a.parent;if(n==null)return;const i=n.parent;if(i==null)return;const o=i.parent;if(o==null)return;const r=o.lines.indexOf(i);if(r===-1)return;let c;if(e===!0?c=o.lines[r+1]:c=o.lines[r-1],c!=null)return c;const d=o.parent;if(d==null)return;const u=d.columns.indexOf(o);if(u===-1)return;if(e===!0)c=(S=d.columns[u+1])==null?void 0:S.lines[0];else{const y=(I=(v=d.columns)==null?void 0:v[u-1])==null?void 0:I.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const l=d.parent;if(l==null)return;const f=l.sections.indexOf(d);if(f===-1)return;if(e===!0)c=(p=(h=l.sections[f-1])==null?void 0:h.columns[0])==null?void 0:p.lines[0];else{const y=(O=(_=l.sections)==null?void 0:_[f-1])==null?void 0:O.columns,A=y==null?void 0:y[y.length-1],E=A==null?void 0:A.lines;c=E==null?void 0:E[E.length-1]}if(c!=null)return c;const g=l.parent;if(g==null)return;const T=g.pages.indexOf(l);if(T!==-1){if(e===!0)c=(R=(C=(x=g.pages[T+1])==null?void 0:x.sections[0])==null?void 0:C.columns[0])==null?void 0:R.lines[0];else{const y=(M=g.pages[T-1])==null?void 0:M.sections;if(y==null)return;const A=(D=y[y.length-1])==null?void 0:D.columns,E=A[A.length-1],P=E==null?void 0:E.lines;c=P[P.length-1]}if(c!=null)return c}}_getDocObject(){return ke(this._univerInstanceService,this._renderManagerService)}};Ce=nn([t.OnLifecycle(t.LifecycleStages.Rendered,Ce),ve(0,t.IUniverInstanceService),ve(1,U.IRenderManagerService),ve(2,j.Inject(m.TextSelectionManagerService)),ve(3,t.ICommandService)],Ce);var an=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,on=(s,a,e,n)=>{for(var i=n>1?void 0:n?sn(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&an(a,e,i),i},_e=(s,a)=>(e,n)=>a(e,n,s);let ye=class extends t.Disposable{constructor(a,e,n,i){super();N(this,"_onInputSubscription");this._univerInstanceService=a,this._renderManagerService=e,this._textSelectionRenderManager=n,this._commandService=i,this._init()}dispose(){var a;super.dispose(),(a=this._onInputSubscription)==null||a.unsubscribe()}_init(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async a=>{var v;if(a==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const n=e.getUnitId(),{event:i,content:o="",activeRange:r}=a,c=i,d=(v=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:v.with(m.DocSkeletonManagerService).getSkeleton();if(c.data==null||d==null||!d||!r)return;const{startOffset:u,segmentId:l,style:f,segmentPage:g}=r,T=o.length,S=[{startOffset:u+T,endOffset:u+T,segmentId:l,segmentPage:g,style:f}];await this._commandService.executeCommand(q.id,{unitId:n,body:{dataStream:o},textRanges:S,range:r,segmentId:l})})}};ye=on([t.OnLifecycle(t.LifecycleStages.Rendered,ye),_e(0,t.IUniverInstanceService),_e(1,U.IRenderManagerService),_e(2,U.ITextSelectionRenderManager),_e(3,t.ICommandService)],ye);const J={id:"doc.command.align-operation",type:t.CommandType.COMMAND,handler:(s,a)=>{var x,C;const e=s.get(m.TextSelectionManagerService),n=s.get(t.IUniverInstanceService),i=s.get(t.ICommandService),{alignType:o}=a,r=n.getCurrentUniverDocInstance(),c=e.getActiveRange();if(r==null||c==null)return!1;const{segmentId:d}=c,u=(x=e.getCurrentSelections())!=null?x:[],l=(C=r.getSelfOrHeaderFooterModel(d).getBody())==null?void 0:C.paragraphs,f=u.map(z);if(l==null)return!1;const g=mt(c,l),T=r.getUnitId(),S=g.every(R=>{var M;return((M=R.paragraphStyle)==null?void 0:M.horizontalAlign)===o}),v={id:b.id,params:{unitId:T,actions:[],textRanges:f}},I=new t.MemoryCursor;I.reset();const h=new t.TextX,p=t.JSONX.getInstance();for(const R of g){const{startIndex:M}=R;h.push({t:t.TextXActionType.RETAIN,len:M-I.cursor,segmentId:d});const D={...R.paragraphStyle,horizontalAlign:S?t.HorizontalAlign.UNSPECIFIED:o};h.push({t:t.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...R,paragraphStyle:D,startIndex:0}]},segmentId:d,coverType:t.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(M+1)}const _=B(r,d);return v.params.actions=p.editOp(h.serialize(),_),!!i.syncExecuteCommand(v.id,v.params)}},pt={id:"doc.command.align-left",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.CENTER})},vt={id:"doc.command.align-right",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.RIGHT})},Ct={id:"doc.command.align-justify",type:t.CommandType.COMMAND,handler:s=>s.get(t.ICommandService).syncExecuteCommand(J.id,{alignType:t.HorizontalAlign.JUSTIFIED})};class _t{constructor(){N(this,"_customRangeHooks",[])}addClipboardHook(a){return this._customRangeHooks.push(a),t.toDisposable(()=>{const e=this._customRangeHooks.indexOf(a);e>-1&&this._customRangeHooks.splice(e,1)})}copyCustomRange(a){let e={...a};return this._customRangeHooks.forEach(n=>{n.onCopyCustomRange&&(e=n.onCopyCustomRange(e))}),e}}var rn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(s,a,e,n)=>{for(var i=n>1?void 0:n?cn(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&rn(a,e,i),i},ln=(s,a)=>(e,n)=>a(e,n,s);const un="docs";m.UniverDocsPlugin=(Re=class extends t.Plugin{constructor(a={},e){super(),this._injector=e,this._initializeDependencies(e),this._initializeCommands()}_initializeCommands(){[he,pe,Ye,Ke,oe,re,ce,de,V,le,ue,me,ge,Se,fe,we,We,q,H,ie,Ue,Pe,se,b,gt,ft,It,Q,Ae,ht,ut,lt,Ie,pt,Tt,vt,J,Ct].forEach(a=>{this._injector.get(t.ICommandService).registerCommand(a)})}_initializeDependencies(a){[[m.DocStateChangeManagerService],[Z],[U.ITextSelectionRenderManager,{useClass:U.TextSelectionRenderManager}],[m.TextSelectionManagerService],[_t],[ye],[Te],[Ce]].forEach(e=>a.add(e))}},N(Re,"pluginName",un),N(Re,"type",t.UniverInstanceType.UNIVER_DOC),Re),m.UniverDocsPlugin=dn([ln(1,j.Inject(j.Injector))],m.UniverDocsPlugin);function mn(s,a){const{range:e,rangeId:n,rangeType:i,segmentId:o}=s,r=Rt(e,a);if(!r)return null;const{startOffset:c,endOffset:d}=r,u=new t.TextX;return c>0&&u.push({t:t.TextXActionType.RETAIN,len:c,segmentId:o}),u.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0}),u.push({t:t.TextXActionType.RETAIN,body:{dataStream:""},len:d-c,segmentId:o}),u.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:n,rangeType:i,startIndex:-(d-c)-1,endIndex:0}]},len:1,line:0}),u}function gn(s,a){const e={id:b.id,params:{unitId:s.unitId,actions:[],textRanges:void 0}},n=t.JSONX.getInstance(),i=mn(s,a);return i?(e.params.actions=n.editOp(i.serialize()),e):!1}function fn(s,a){var x;const{segmentId:e,rangeId:n,rangeType:i}=a,o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),c=o.getActiveRange();if(!c)return!1;const d=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const u=d.getBody(),l=d.getUnitId();if(!u)return!1;const{startOffset:f,endOffset:g}=W(c),T=(x=u.customRanges)!=null?x:[],S=[];for(let C=0,R=T.length;C<R;C++){const M=T[C];if(M.rangeType===i&&Math.max(M.startIndex,f)<=Math.min(M.endIndex,g-1)&&S.push({...M}),M.startIndex>=g)break}const v=S.map(C=>[C.startIndex,C.endIndex]).flat().sort((C,R)=>C-R);let I=0;const h=new t.TextX,p=v.length?{startOffset:Math.min(v[0],f),endOffset:Math.max(v[v.length-1]+1,g)}:c;p.startOffset!==I&&(h.push({t:t.TextXActionType.RETAIN,len:p.startOffset-I,segmentId:e}),I=p.startOffset),h.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_START},len:1,line:0,segmentId:e}),v.forEach((C,R)=>{C!==I&&(h.push({t:t.TextXActionType.RETAIN,len:C-I,segmentId:e}),I=C),h.push({t:t.TextXActionType.DELETE,len:1,line:0,segmentId:e}),I++}),I!==p.endOffset&&(h.push({t:t.TextXActionType.RETAIN,len:p.endOffset-I,segmentId:e}),I=p.endOffset),h.push({t:t.TextXActionType.INSERT,body:{dataStream:t.DataStreamTreeTokenType.CUSTOM_RANGE_END,customRanges:[{rangeId:n,rangeType:i,startIndex:-(p.endOffset-p.startOffset-v.length+1),endIndex:0}]},len:1,line:0,segmentId:e});const _=t.JSONX.getInstance(),O={id:b.id,params:{unitId:l,actions:[],textRanges:void 0}};return O.params.actions=_.editOp(h.serialize()),O}function Sn(s,a){var g,T;const{unitId:e,rangeId:n,segmentId:i}=a,r=s.get(t.IUniverInstanceService).getUnit(e);if(!r)return!1;const c=(T=(g=r.getBody())==null?void 0:g.customRanges)==null?void 0:T.find(S=>S.rangeId===n);if(!c)return!1;const{startIndex:d,endIndex:u}=c,l=new t.TextX,f=u-d+1;return d>0&&l.push({t:t.TextXActionType.RETAIN,len:d,segmentId:i}),l.push({t:t.TextXActionType.DELETE,len:1,segmentId:i,line:0}),f-2>0&&l.push({t:t.TextXActionType.RETAIN,len:f-2,segmentId:i}),l.push({t:t.TextXActionType.DELETE,len:1,segmentId:i,line:0}),l}function In(s,a){const e={id:b.id,params:{unitId:a.unitId,actions:[],textRanges:void 0}},n=t.JSONX.getInstance(),i=Sn(s,a);return i?(e.params.actions=n.editOp(i.serialize()),e):!1}function yt(s){const{unitId:a,range:e,id:n,type:i,segmentId:o}=s,{startOffset:r,endOffset:c}=e,d={id:b.id,params:{unitId:a,actions:[],textRanges:void 0}},u=new t.TextX,l=t.JSONX.getInstance();return r>0&&u.push({t:t.TextXActionType.RETAIN,len:r,segmentId:o}),u.push({t:t.TextXActionType.RETAIN,body:{dataStream:"",customDecorations:[{id:n,type:i,startIndex:0,endIndex:c-r-1}]},len:c-r,segmentId:o}),d.params.actions=l.editOp(u.serialize()),d}function hn(s,a){const{segmentId:e,id:n,type:i}=a,o=s.get(m.TextSelectionManagerService),r=s.get(t.IUniverInstanceService),c=o.getActiveRange();if(!c)return!1;const d=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const u=d.getBody(),l=d.getUnitId();return u?yt({unitId:l,range:{startOffset:c.startOffset,endOffset:c.endOffset,collapsed:!0},id:n,type:i,segmentId:e}):!1}function pn(s,a){var v,I;const{unitId:e,id:n,segmentId:i}=a,r=s.get(t.IUniverInstanceService).getUnit(e),c=r==null?void 0:r.getBody();if(!r||!c)return!1;const d=(I=(v=r.getBody())==null?void 0:v.customDecorations)==null?void 0:I.filter(h=>h.id===n);if(!(d!=null&&d.length))return!1;const u=d.map(h=>t.getBodySlice(c,h.startIndex,h.endIndex+1)),l=u.map(h=>{var _;const p=t.Tools.deepClone(h);return p.customDecorations=(_=p.customDecorations)==null?void 0:_.filter(O=>O.id!==n),p}),f={id:b.id,params:{unitId:e,actions:[],textRanges:void 0}},g=new t.TextX,T=t.JSONX.getInstance();let S=0;return d.forEach((h,p)=>{const _=l[p],O=u[p];h.startIndex!==S&&g.push({t:t.TextXActionType.RETAIN,len:h.startIndex-S,segmentId:i}),S=h.startIndex,g.push({t:t.TextXActionType.RETAIN,len:h.endIndex-h.startIndex+1,segmentId:i,body:_,oldBody:O,coverType:t.UpdateDocsAttributeType.REPLACE}),S=S+(h.endIndex-h.startIndex+1)}),f.params.actions=T.editOp(g.serialize()),f}const Tn=t.createInterceptorKey("CUSTOM_RANGE"),vn=t.createInterceptorKey("CUSTOM_DECORATION"),Oe={CUSTOM_RANGE:Tn,CUSTOM_DECORATION:vn};var Cn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,yn=(s,a,e,n)=>{for(var i=n>1?void 0:n?_n(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(n?r(a,e,i):r(i))||i);return n&&i&&Cn(a,e,i),i},On=(s,a)=>(e,n)=>a(e,n,s);m.DocInterceptorService=class extends t.Disposable{constructor(e,n){super();N(this,"_interceptorsByName",new Map);this._context=e,this._docSkeletonManagerService=n,this.disposeWithMe(this._docSkeletonManagerService.currentViewModel$.subscribe(i=>{if(i){const o=i.getDataModel().getUnitId();if(o===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||o===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.interceptDocumentViewModel(i)}})),this.disposeWithMe(this.intercept(Oe.CUSTOM_RANGE,{priority:-1,handler:(i,o,r)=>r(i)}))}intercept(e,n){const i=e;this._interceptorsByName.has(i)||this._interceptorsByName.set(i,[]);const o=this._interceptorsByName.get(i);return o.push(n),this._interceptorsByName.set(i,o.sort((r,c)=>{var d,u;return((d=c.priority)!=null?d:0)-((u=r.priority)!=null?u:0)})),this.disposeWithMe(t.toDisposable(()=>t.remove(this._interceptorsByName.get(i),n)))}fetchThroughInterceptors(e){const n=e,i=this._interceptorsByName.get(n);return t.composeInterceptors(i||[])}interceptDocumentViewModel(e){const n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:i=>{var o;return this.fetchThroughInterceptors(Oe.CUSTOM_RANGE)(e.getCustomRangeRaw(i),{index:i,unitId:e.getDataModel().getUnitId(),customRanges:(o=e.getDataModel().getCustomRanges())!=null?o:[]})},getCustomDecoration:i=>{var o;return this.fetchThroughInterceptors(Oe.CUSTOM_DECORATION)(e.getCustomDecorationRaw(i),{index:i,unitId:e.getDataModel().getUnitId(),customDecorations:(o=e.getDataModel().getCustomDecorations())!=null?o:[]})}})),n}},m.DocInterceptorService=yn([t.OnLifecycle(t.LifecycleStages.Starting,m.DocInterceptorService),On(1,j.Inject(m.DocSkeletonManagerService))],m.DocInterceptorService),m.AlignCenterCommand=Tt,m.AlignJustifyCommand=Ct,m.AlignLeftCommand=pt,m.AlignOperationCommand=J,m.AlignRightCommand=vt,m.BreakLineCommand=We,m.BulletListCommand=lt,m.CoverContentCommand=ft,m.CutContentCommand=be,m.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX=Dt,m.DOCS_COMPONENT_DEFAULT_Z_INDEX=Nt,m.DOCS_COMPONENT_HEADER_LAYER_INDEX=At,m.DOCS_COMPONENT_MAIN_LAYER_INDEX=Et,m.DOCS_VIEW_KEY=K,m.DOC_INTERCEPTOR_POINT=Oe,m.DeleteCommand=H,m.DeleteCustomBlockCommand=ie,m.DeleteLeftCommand=Ye,m.DeleteRightCommand=Ke,m.DocCustomRangeService=_t,m.EditorInsertTextCommandId=Ve,m.IMEInputCommand=Pe,m.IMEInputManagerService=Z,m.InnerPasteCommand=zt,m.InsertCommand=q,m.ListOperationCommand=Ie,m.MergeTwoParagraphCommand=se,m.MoveCursorOperation=he,m.MoveSelectionOperation=pe,m.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Ut,m.OrderListCommand=ut,m.ReplaceContentCommand=gt,m.ResetInlineFormatTextBackgroundColorCommand=Se,m.RichTextEditingMutation=b,m.SelectAllOperation=ht,m.SetDocZoomRatioCommand=It,m.SetDocZoomRatioOperation=Q,m.SetInlineFormatBoldCommand=oe,m.SetInlineFormatCommand=we,m.SetInlineFormatFontFamilyCommand=me,m.SetInlineFormatFontSizeCommand=ue,m.SetInlineFormatItalicCommand=re,m.SetInlineFormatStrikethroughCommand=de,m.SetInlineFormatSubscriptCommand=V,m.SetInlineFormatSuperscriptCommand=le,m.SetInlineFormatTextBackgroundColorCommand=fe,m.SetInlineFormatTextColorCommand=ge,m.SetInlineFormatUnderlineCommand=ce,m.SetTextSelectionsOperation=Ae,m.UpdateCommand=Ue,m.VIEWPORT_KEY=Fe,m.addCustomDecorationBySelectionFactory=hn,m.addCustomDecorationFactory=yt,m.addCustomRangeBySelectionFactory=fn,m.addCustomRangeFactory=gn,m.deleteCustomDecorationFactory=pn,m.deleteCustomRangeFactory=In,m.getDeleteSelection=ne,m.getDocObject=ke,m.getDocObjectById=Pt,m.getInsertSelection=Y,m.getRetainAndDeleteFromReplace=ae,m.getRichTextEditPath=B,m.getSelectionText=xt,m.neoGetDocObject=bt,m.serializeTextRange=z,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@wendellhu/redi": "0.15.5",
|
|
50
50
|
"rxjs": ">=7.0.0",
|
|
51
|
-
"@univerjs/
|
|
52
|
-
"@univerjs/
|
|
51
|
+
"@univerjs/engine-render": "0.2.3",
|
|
52
|
+
"@univerjs/core": "0.2.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@wendellhu/redi": "0.15.5",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"typescript": "^5.5.3",
|
|
58
58
|
"vite": "^5.3.3",
|
|
59
59
|
"vitest": "^1.6.0",
|
|
60
|
-
"@univerjs/core": "0.2.
|
|
61
|
-
"@univerjs/engine-render": "0.2.
|
|
62
|
-
"@univerjs/shared": "0.2.
|
|
60
|
+
"@univerjs/core": "0.2.3",
|
|
61
|
+
"@univerjs/engine-render": "0.2.3",
|
|
62
|
+
"@univerjs/shared": "0.2.3"
|
|
63
63
|
},
|
|
64
64
|
"univerSpace": {
|
|
65
65
|
".": {
|